← ClaudeAtlas

codegen-drift-watchdoglisted

Detect when generated output (Prisma client, tRPC router types, OpenAPI clients) is stale versus its source schema, then auto-regenerate or fail CI with a precise list.
RMAzrim/opencode-artes · ★ 2 · AI & Automation · score 76
Install: claude install-skill RMAzrim/opencode-artes
# Codegen Drift Watchdog ## 1. System Architecture & Prerequisites Codegen output silently goes stale: a `schema.prisma` changes but the checked-in client doesn't, tRPC router types drift from generated API clients, an OpenAPI spec evolves while its generated SDK lags. Drift breaks `next build` at the worst moment. The Watchdog hashes each generated file, stores the manifest, and on every run re-generates into a scratch dir and diffs — flagging stale files with byte-level confidence. Node 18+ stdlib + whatever codegen CLIs your project uses. Managed pairs (`watchdog.json`): ```json { "regenerators": [ { "source": "schema.prisma", "generated": "client/**", "cmd": "npx prisma generate" } ] } ``` ## 2. Input/Output Data Contracts `watchdog.json` (repo root) defines `regenerators`, each: - `source`: glob(s) of the schema/source inputs - `generated`: glob(s) of the checked-in generated outputs - `cmd`: shell command that (re)generates the outputs - `fix: true|false` — `true` auto-fixes and exits non-zero anyway to force a commit; `false` (default) only reports Output `codegen-drift-report.json` + `CODEGEN_DRIFT.md`: ```json { "check": "hash", "ok": 14, "stale": [ { "file": "client/schema.ts", "sourceHash": "abc…", "generatedHash": "def…" } ] } ``` Exit: `0` = all fresh, `1` = stale found, `2` = watchdog.json invalid. ## 3. Production Reference Implementation ```js // codegen-drift-watchdog.js const fs = require('fs'); const path = require('path'); const crypto = requ