Type Safety Fix Loop
Run validation and fix every failing layer bottom-up until pnpm validate:all exits 0. Follow the six-layer type safety architecture documented in _docs/type/.
Reference
Read these docs before starting (they define the chain, naming rules, generators, and fix protocol):
_docs/type/TYPE_SAFETY.md — full chain overview, error fixing protocol, commands
_docs/type/layers/01-drizzle-schema.md through 06-ui-components.md — per-layer validation rules and generators
_docs/type/AI_LAB_AND_OTHER_SURFACES.md — surfaces outside the chain (skip these)
_docs/type/PROBLEMATIC_PAGES_TYPE_CHAIN.md — known runtime issues (context only)
Protocol
Phase 1 — Initial assessment
- Run
pnpm validate:all to see which layers fail. Capture the full JSON output.
- If all layers pass (exit 0), report success and stop.
- If a layer fails, note the first failing layer (the chain stops at first failure).
Phase 2 — Fix loop (bottom-up, one layer at a time)
For the first failing layer, apply the fix:
| Layer |
Fix command |
What it does |
| 1 — Drizzle Schema |
npx tsx scripts/generate-schema.ts |
Regenerate schema.ts from live DB (requires DATABASE_URL). If DB is unavailable, report and stop. |
| 2 — Zod Schemas |
pnpm generate:schemas |
Regenerate src/lib/schemas/index.ts from schema.ts |
| 3 — Services |
pnpm generate:services |
Regenerate all service files + index.ts |
| 4 — API Routes |
pnpm generate:routes |
Regenerate all route files |
| 5 — React Hooks |
pnpm generate:hooks |
Regenerate all hook files + index.ts |
| 6 — UI Components |
pnpm generate:ui |
Regenerate all component files + index.ts |
After running the generator:
- Re-run that layer's check command (e.g.
pnpm contracts:check for Layer 2).
- If it still fails, read the JSON output carefully and fix manually (missing exports, wrong naming, structural issues).
- Once that layer passes, move to the next layer up.
Phase 3 — Full re-validation
After all individual layers pass:
- Run
pnpm validate:all to confirm the full chain is green.
- If any layer regressed, go back to Phase 2 for that layer.
- Repeat until
pnpm validate:all exits 0.
Phase 4 — TypeScript check (optional but recommended)
Run pnpm build:check (or NODE_OPTIONS=--max-old-space-size=8192 pnpm typecheck) to catch any TypeScript type errors introduced by regeneration. If there are TS errors:
- Trace each error to the lowest affected layer.
- Fix at that layer (edit the generated file or the generator input).
- Re-run
pnpm validate:all to ensure layer validation still passes.
- Re-run typecheck until clean.
Rules
- Lock-before-proceed: Never work on Layer N until all layers < N pass.
- Fix bottom-up: Always fix the lowest failing layer first.
- Never fix upstream: Do not change a lower layer to satisfy a higher layer.
- Generators overwrite: Running a generator replaces all entity files. Custom logic lives in
custom/ directories and is not affected.
- Layer 1 needs DB: Layer 1 regeneration requires a live database connection. If unavailable, report the mismatch and stop — do not guess at schema changes.
- 148 vs 149: Layer 1 validates 149 tables (includes type-annotated
contentCategories). Layers 2–6 validate 148 entities (regex excludes type-annotated exports). This is expected.
Output
After each loop iteration, report:
- Which layer was fixed and how
- Current status of all layers checked so far
At completion, report:
- Final
pnpm validate:all output
- Any TypeScript errors remaining (if Phase 4 was run)
1---2name: type-fix3description: Run type safety checks across all 6 layers, regenerate any failing layers, and loop until all layers pass with zero errors. Follows the lock-before-proceed protocol from _docs/type/.4user-invocable: true5allowed-tools: Bash, Read, Write, Edit, Grep, Glob, Agent6metadata:7 source: https://skillmd.com/skills/joshuashepherd/type-fix8---910# Type Safety Fix Loop1112Run validation and fix every failing layer bottom-up until `pnpm validate:all` exits 0. Follow the six-layer type safety architecture documented in `_docs/type/`.1314## Reference1516Read these docs before starting (they define the chain, naming rules, generators, and fix protocol):1718- `_docs/type/TYPE_SAFETY.md` — full chain overview, error fixing protocol, commands19- `_docs/type/layers/01-drizzle-schema.md` through `06-ui-components.md` — per-layer validation rules and generators20- `_docs/type/AI_LAB_AND_OTHER_SURFACES.md` — surfaces outside the chain (skip these)21- `_docs/type/PROBLEMATIC_PAGES_TYPE_CHAIN.md` — known runtime issues (context only)2223## Protocol2425### Phase 1 — Initial assessment26271. Run `pnpm validate:all` to see which layers fail. Capture the full JSON output.282. If all layers pass (exit 0), report success and stop.293. If a layer fails, note the **first failing layer** (the chain stops at first failure).3031### Phase 2 — Fix loop (bottom-up, one layer at a time)3233For the first failing layer, apply the fix:3435| Layer | Fix command | What it does |36|-------|------------|--------------|37| 1 — Drizzle Schema | `npx tsx scripts/generate-schema.ts` | Regenerate schema.ts from live DB (requires DATABASE_URL). If DB is unavailable, report and stop. |38| 2 — Zod Schemas | `pnpm generate:schemas` | Regenerate `src/lib/schemas/index.ts` from schema.ts |39| 3 — Services | `pnpm generate:services` | Regenerate all service files + index.ts |40| 4 — API Routes | `pnpm generate:routes` | Regenerate all route files |41| 5 — React Hooks | `pnpm generate:hooks` | Regenerate all hook files + index.ts |42| 6 — UI Components | `pnpm generate:ui` | Regenerate all component files + index.ts |4344After running the generator:451. Re-run that layer's check command (e.g. `pnpm contracts:check` for Layer 2).462. If it still fails, read the JSON output carefully and fix manually (missing exports, wrong naming, structural issues).473. Once that layer passes, move to the next layer up.4849### Phase 3 — Full re-validation5051After all individual layers pass:521. Run `pnpm validate:all` to confirm the full chain is green.532. If any layer regressed, go back to Phase 2 for that layer.543. Repeat until `pnpm validate:all` exits 0.5556### Phase 4 — TypeScript check (optional but recommended)5758Run `pnpm build:check` (or `NODE_OPTIONS=--max-old-space-size=8192 pnpm typecheck`) to catch any TypeScript type errors introduced by regeneration. If there are TS errors:591. Trace each error to the lowest affected layer.602. Fix at that layer (edit the generated file or the generator input).613. Re-run `pnpm validate:all` to ensure layer validation still passes.624. Re-run typecheck until clean.6364## Rules6566- **Lock-before-proceed:** Never work on Layer N until all layers < N pass.67- **Fix bottom-up:** Always fix the lowest failing layer first.68- **Never fix upstream:** Do not change a lower layer to satisfy a higher layer.69- **Generators overwrite:** Running a generator replaces all entity files. Custom logic lives in `custom/` directories and is not affected.70- **Layer 1 needs DB:** Layer 1 regeneration requires a live database connection. If unavailable, report the mismatch and stop — do not guess at schema changes.71- **148 vs 149:** Layer 1 validates 149 tables (includes type-annotated `contentCategories`). Layers 2–6 validate 148 entities (regex excludes type-annotated exports). This is expected.7273## Output7475After each loop iteration, report:76- Which layer was fixed and how77- Current status of all layers checked so far7879At completion, report:80- Final `pnpm validate:all` output81- Any TypeScript errors remaining (if Phase 4 was run)