@polymorphism-tech/morph-spec 4.22.0 → 5.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (211) hide show
  1. package/CLAUDE.md +57 -71
  2. package/README.md +2 -2
  3. package/bin/morph-spec.js +224 -491
  4. package/claude-plugin.json +1 -1
  5. package/docs/CHEATSHEET.md +1 -1
  6. package/docs/QUICKSTART.md +1 -1
  7. package/framework/CLAUDE.md +55 -38
  8. package/framework/MORPH.md +244 -0
  9. package/framework/agents.json +127 -1198
  10. package/framework/commands/morph-apply.md +56 -240
  11. package/framework/commands/morph-archive.md +48 -85
  12. package/framework/commands/morph-preflight.md +7 -7
  13. package/framework/commands/morph-proposal.md +35 -191
  14. package/framework/commands/morph-status.md +19 -50
  15. package/framework/commands/morph-troubleshoot.md +2 -2
  16. package/framework/evals/rubrics/README.md +44 -0
  17. package/framework/evals/rubrics/architecture.md +46 -0
  18. package/framework/evals/rubrics/code-quality.md +50 -0
  19. package/framework/evals/rubrics/contracts.md +47 -0
  20. package/framework/evals/rubrics/test-coverage.md +50 -0
  21. package/framework/evals/scenarios/dotnet-crud.yaml +42 -0
  22. package/framework/evals/scenarios/nextjs-auth.yaml +38 -0
  23. package/framework/evals/suites/standard.yaml +5 -0
  24. package/framework/evals/trace-schema.md +67 -0
  25. package/framework/hooks/claude-code/core/README.md +3 -0
  26. package/framework/hooks/claude-code/core/denylist.json +14 -0
  27. package/framework/hooks/claude-code/{pre-tool-use → core}/enforce-phase-writes.js +5 -5
  28. package/framework/hooks/claude-code/core/post-edit-typecheck.js +69 -0
  29. package/framework/hooks/claude-code/core/pre-bash-denylist.js +29 -0
  30. package/framework/hooks/claude-code/{pre-tool-use → core}/protect-spec-files.js +4 -6
  31. package/framework/hooks/claude-code/{stop → core}/validate-completion.js +13 -82
  32. package/framework/hooks/shared/phase-utils.js +20 -31
  33. package/framework/hooks/shared/state-reader.js +4 -5
  34. package/framework/{skills/level-0-meta/mcp-registry.json → mcp/registry.json} +254 -243
  35. package/framework/phases.json +41 -115
  36. package/framework/rubrics/eval-rubric.json +66 -0
  37. package/framework/skills/README.md +39 -64
  38. package/framework/skills/core/README.md +3 -0
  39. package/framework/skills/core/morph-brainstorming/SKILL.md +102 -0
  40. package/framework/skills/core/morph-eval/SKILL.md +57 -0
  41. package/framework/skills/core/morph-implement/SKILL.md +83 -0
  42. package/framework/skills/core/morph-plan/SKILL.md +64 -0
  43. package/framework/skills/core/morph-review/SKILL.md +62 -0
  44. package/framework/skills/core/morph-stack-scan/SKILL.md +109 -0
  45. package/framework/skills/core/morph-standards/SKILL.md +49 -0
  46. package/framework/templates/CLAUDE.md.core.guide.md +29 -0
  47. package/framework/templates/CLAUDE.md.core.template +22 -0
  48. package/framework/templates/REGISTRY.json +4 -4
  49. package/framework/workflows/configs/fast-track.json +5 -10
  50. package/framework/workflows/configs/full.json +4 -8
  51. package/framework/workflows/configs/quick.json +32 -0
  52. package/framework/workflows/configs/standard.json +57 -64
  53. package/package.json +7 -6
  54. package/src/commands/mcp/mcp-setup.js +58 -31
  55. package/src/commands/project/doctor.js +69 -70
  56. package/src/commands/project/init.js +26 -5
  57. package/src/commands/project/status.js +18 -19
  58. package/src/commands/state/approve.js +1 -1
  59. package/src/commands/validation/validate-feature.js +18 -112
  60. package/src/core/paths/output-schema.js +133 -152
  61. package/src/core/state/phase-state-machine.js +10 -24
  62. package/src/core/state/state-manager.js +17 -17
  63. package/src/core/workflows/workflow-detector.js +214 -31
  64. package/src/core/workflows/workflow-router.js +204 -0
  65. package/src/dashboard/app/pages/AgentMap.jsx +32 -33
  66. package/src/dashboard/app/pages/LiveState.jsx +1 -1
  67. package/src/dashboard/app/pages/PhasePipeline.jsx +2 -4
  68. package/src/dashboard/app/pages/SkillsLibrary.jsx +2 -3
  69. package/src/dashboard/app/pages/Workflows.jsx +2 -2
  70. package/src/dashboard/scanner/agents-scanner.js +30 -35
  71. package/src/lib/agents/metrics-aggregator.js +1 -1
  72. package/src/lib/agents/output-collector.js +7 -9
  73. package/src/lib/context/context-builder.js +289 -0
  74. package/src/lib/detectors/claude-config-detector.js +19 -3
  75. package/src/lib/generators/context-generator.js +20 -42
  76. package/src/lib/generators/index.js +1 -0
  77. package/src/lib/generators/mandate-generator.js +512 -0
  78. package/src/lib/generators/metadata-extractor.js +1 -1
  79. package/src/lib/generators/recap-generator.js +3 -4
  80. package/src/lib/installers/mcp-installer.js +300 -92
  81. package/src/lib/phase-chain/phase-validator.js +36 -40
  82. package/src/lib/stack/stack-profile.js +74 -91
  83. package/src/lib/tasks/task-parser.js +1 -1
  84. package/src/lib/tasks/wave-resolver.js +353 -0
  85. package/src/lib/validators/checkpoint-persistence.js +2 -2
  86. package/src/lib/validators/content/cross-phase-validator.js +281 -0
  87. package/src/lib/validators/content/index.js +1 -0
  88. package/src/lib/validators/shared/emit-validator-dispatch.js +6 -56
  89. package/src/scripts/global-install.js +2 -27
  90. package/src/utils/agents-installer.js +224 -447
  91. package/src/utils/claude-settings-manager.js +57 -15
  92. package/src/utils/file-copier.js +1 -0
  93. package/src/utils/hooks-installer.js +15 -117
  94. package/src/utils/skills-installer.js +12 -18
  95. package/bin/detect-agents.js +0 -226
  96. package/bin/task-manager.js +0 -1036
  97. package/framework/agents/README.md +0 -13
  98. package/framework/agents/ai-agents/ai-system-architect.md +0 -194
  99. package/framework/agents/ai-agents/vector-search-expert.md +0 -247
  100. package/framework/agents/architecture/architecture-expert.md +0 -98
  101. package/framework/agents/architecture/morph-spec-architect.md +0 -66
  102. package/framework/agents/architecture/packages-validator.md +0 -89
  103. package/framework/agents/architecture/security-expert.md +0 -79
  104. package/framework/agents/architecture/seo-growth-hacker.md +0 -168
  105. package/framework/agents/architecture/standards-architect.md +0 -153
  106. package/framework/agents/backend/dotnet-senior.md +0 -163
  107. package/framework/agents/backend/ef-modeler.md +0 -119
  108. package/framework/agents/backend/hangfire-orchestrator.md +0 -133
  109. package/framework/agents/backend/ms-agent-expert.md +0 -55
  110. package/framework/agents/backend/neon-expert.md +0 -379
  111. package/framework/agents/frontend/css-specialist.md +0 -89
  112. package/framework/agents/frontend/design-system-validator.md +0 -100
  113. package/framework/agents/frontend/gsap-animator.md +0 -131
  114. package/framework/agents/frontend/nextjs-component-validator.md +0 -97
  115. package/framework/agents/frontend/nextjs-expert.md +0 -201
  116. package/framework/agents/frontend/ui-designer.md +0 -259
  117. package/framework/agents/infrastructure/infra-architect.md +0 -215
  118. package/framework/agents/integrations/asaas-financial.md +0 -138
  119. package/framework/agents/integrations/neon-auth.md +0 -151
  120. package/framework/agents/integrations/resend-email.md +0 -127
  121. package/framework/hooks/claude-code/post-tool-use/agent-complete.js +0 -122
  122. package/framework/hooks/claude-code/post-tool-use/dispatch.js +0 -363
  123. package/framework/hooks/claude-code/post-tool-use/handle-tool-failure.js +0 -78
  124. package/framework/hooks/claude-code/post-tool-use/validator-feedback.js +0 -194
  125. package/framework/hooks/claude-code/pre-compact/save-morph-context.js +0 -199
  126. package/framework/hooks/claude-code/pre-tool-use/task-tracking-guard.js +0 -55
  127. package/framework/hooks/claude-code/session-start/inject-morph-context.js +0 -323
  128. package/framework/hooks/claude-code/session-start/post-compact-restore.js +0 -41
  129. package/framework/hooks/claude-code/session-start/resume-context.js +0 -77
  130. package/framework/hooks/claude-code/teammate-idle/teammate-idle.js +0 -90
  131. package/framework/hooks/claude-code/user-prompt/enrich-prompt.js +0 -114
  132. package/framework/hooks/shared/compact-restore.js +0 -123
  133. package/framework/hooks/shared/dispatch-helpers.js +0 -147
  134. package/framework/hooks/shared/skill-reminder-helpers.js +0 -79
  135. package/framework/hooks/shared/stale-task-reset.js +0 -57
  136. package/framework/hooks/shared/worktree-helpers.js +0 -75
  137. package/framework/skills/level-0-meta/README.md +0 -7
  138. package/framework/skills/level-0-meta/morph-agent-teams/SKILL.md +0 -472
  139. package/framework/skills/level-0-meta/morph-brainstorming/SKILL.md +0 -174
  140. package/framework/skills/level-0-meta/morph-brainstorming/references/proposal-example.md +0 -138
  141. package/framework/skills/level-0-meta/morph-checklist/SKILL.md +0 -145
  142. package/framework/skills/level-0-meta/morph-code-review/SKILL.md +0 -250
  143. package/framework/skills/level-0-meta/morph-code-review/references/review-example.md +0 -164
  144. package/framework/skills/level-0-meta/morph-code-review/references/review-guidelines.md +0 -100
  145. package/framework/skills/level-0-meta/morph-code-review/scripts/scan-csharp.mjs +0 -151
  146. package/framework/skills/level-0-meta/morph-code-review-nextjs/SKILL.md +0 -165
  147. package/framework/skills/level-0-meta/morph-code-review-nextjs/references/review-example-nextjs.md +0 -254
  148. package/framework/skills/level-0-meta/morph-code-review-nextjs/scripts/scan-nextjs.mjs +0 -189
  149. package/framework/skills/level-0-meta/morph-frontend-review/SKILL.md +0 -344
  150. package/framework/skills/level-0-meta/morph-frontend-review/scripts/scan-accessibility.mjs +0 -376
  151. package/framework/skills/level-0-meta/morph-gemini-image/SKILL.md +0 -290
  152. package/framework/skills/level-0-meta/morph-init/SKILL.md +0 -537
  153. package/framework/skills/level-0-meta/morph-parallel-dispatch/SKILL.md +0 -225
  154. package/framework/skills/level-0-meta/morph-post-implementation/SKILL.md +0 -401
  155. package/framework/skills/level-0-meta/morph-post-implementation/scripts/detect-dev-server.mjs +0 -153
  156. package/framework/skills/level-0-meta/morph-post-implementation/scripts/detect-stack.mjs +0 -234
  157. package/framework/skills/level-0-meta/morph-simulation-checklist/SKILL.md +0 -106
  158. package/framework/skills/level-0-meta/morph-tool-usage-guide/SKILL.md +0 -243
  159. package/framework/skills/level-0-meta/morph-tool-usage-guide/references/tools-per-phase.md +0 -169
  160. package/framework/skills/level-0-meta/morph-verification-before-completion/SKILL.md +0 -148
  161. package/framework/skills/level-0-meta/morph-verification-before-completion/scripts/check-phase-outputs.mjs +0 -110
  162. package/framework/skills/level-1-workflows/README.md +0 -7
  163. package/framework/skills/level-1-workflows/morph-phase-codebase-analysis/SKILL.md +0 -269
  164. package/framework/skills/level-1-workflows/morph-phase-design/SKILL.md +0 -453
  165. package/framework/skills/level-1-workflows/morph-phase-design/references/architecture-analysis-guide.md +0 -44
  166. package/framework/skills/level-1-workflows/morph-phase-design/references/spec-authoring-guide.md +0 -55
  167. package/framework/skills/level-1-workflows/morph-phase-design/references/spec-example.md +0 -253
  168. package/framework/skills/level-1-workflows/morph-phase-implement/.morph/logs/activity.json +0 -38
  169. package/framework/skills/level-1-workflows/morph-phase-implement/SKILL.md +0 -634
  170. package/framework/skills/level-1-workflows/morph-phase-implement/prompts/code-quality-reviewer-prompt.md +0 -50
  171. package/framework/skills/level-1-workflows/morph-phase-implement/prompts/implementer-prompt.md +0 -54
  172. package/framework/skills/level-1-workflows/morph-phase-implement/prompts/spec-reviewer-prompt.md +0 -47
  173. package/framework/skills/level-1-workflows/morph-phase-implement/references/recap-example.md +0 -132
  174. package/framework/skills/level-1-workflows/morph-phase-implement/references/vsa-implementation-guide.md +0 -92
  175. package/framework/skills/level-1-workflows/morph-phase-plan/SKILL.md +0 -257
  176. package/framework/skills/level-1-workflows/morph-phase-tasks/.morph/logs/activity.json +0 -14
  177. package/framework/skills/level-1-workflows/morph-phase-tasks/SKILL.md +0 -291
  178. package/framework/skills/level-1-workflows/morph-phase-tasks/references/task-planning-patterns.md +0 -143
  179. package/framework/skills/level-1-workflows/morph-phase-tasks/references/tasks-example.md +0 -404
  180. package/framework/skills/level-1-workflows/morph-phase-tasks/scripts/validate-tasks.mjs +0 -112
  181. package/framework/skills/level-1-workflows/morph-phase-uiux/SKILL.md +0 -995
  182. package/framework/skills/level-1-workflows/morph-scope-escalation/SKILL.md +0 -147
  183. package/framework/squad-templates/backend-only.json +0 -47
  184. package/framework/squad-templates/frontend-only.json +0 -56
  185. package/framework/squad-templates/full-stack.json +0 -74
  186. package/src/commands/agents/agent-metrics.js +0 -174
  187. package/src/commands/agents/audit-dispatch.js +0 -82
  188. package/src/commands/agents/detect-agents.js +0 -275
  189. package/src/commands/agents/dispatch-agents.js +0 -461
  190. package/src/commands/agents/index.js +0 -13
  191. package/src/commands/agents/manage-agents.js +0 -352
  192. package/src/commands/agents/project-metrics.js +0 -74
  193. package/src/commands/phase/phase-reset.js +0 -74
  194. package/src/commands/scope/escalate.js +0 -217
  195. package/src/commands/state/advance-phase.js +0 -600
  196. package/src/commands/state/phase-runner.js +0 -215
  197. package/src/commands/state/state.js +0 -444
  198. package/src/commands/task/expand.js +0 -100
  199. package/src/commands/tasks/index.js +0 -4
  200. package/src/commands/tasks/task.js +0 -105
  201. package/src/commands/templates/index.js +0 -5
  202. package/src/commands/templates/template-render.js +0 -93
  203. package/src/commands/trust/trust.js +0 -118
  204. package/src/lib/agents/agents-manager.js +0 -349
  205. package/src/lib/build/build-runner.js +0 -99
  206. package/src/lib/checkpoints/checkpoint-hooks.js +0 -111
  207. package/src/lib/contracts/sprint-contract-generator.js +0 -137
  208. package/src/lib/scope/impact-analyzer.js +0 -106
  209. package/src/lib/trust/trust-manager.js +0 -157
  210. package/src/utils/tier-helpers.js +0 -24
  211. /package/framework/hooks/claude-code/{post-tool-use → core}/loop-detect.js +0 -0
@@ -1,165 +0,0 @@
1
- ---
2
- name: morph-code-review-nextjs
3
- description: Next.js code review checklist covering naming conventions, component architecture (Server vs Client), data fetching patterns, form implementation, state management, TypeScript/Zod discipline, feature boundaries, and testing. Use after implementing Next.js code, before creating PRs, or when reviewing TSX/TS code for compliance with MORPH-SPEC Next.js standards.
4
- user-invocable: true
5
- allowed-tools: Read, Write, Edit, Bash, Glob, Grep
6
- stacks:
7
- - nextjs
8
- ---
9
-
10
- # Next.js Code Review Checklist
11
-
12
- > Comprehensive checklist for Next.js code review: naming, component architecture, data fetching, forms, state, TypeScript, structure, and testing.
13
- > **Ref:** `framework/standards/frontend/nextjs/naming-conventions.md`
14
- > **Ref:** `framework/standards/frontend/nextjs/app-router.md`
15
- > **Ref:** `framework/standards/frontend/nextjs/components.md`
16
- > **Ref:** `framework/standards/frontend/nextjs/data-fetching.md`
17
- > **Ref:** `framework/standards/frontend/nextjs/forms.md`
18
- > **Ref:** `framework/standards/frontend/nextjs/state-management.md`
19
- > **Ref:** `framework/standards/frontend/nextjs/testing.md`
20
- > **Example:** `references/review-example-nextjs.md` — filled-in review showing expected finding format.
21
- > **Script:** `scripts/scan-nextjs.mjs` — automated scan for CRITICAL/HIGH violations before manual review.
22
- > **Ref:** `.claude/skills/morph-code-review/references/review-guidelines.md` — false-positive rubric, confidence scoring, evidence format.
23
-
24
- ---
25
-
26
- ## Step 0 — Eligibility Check
27
-
28
- ```bash
29
- git diff --name-only main...HEAD -- "*.tsx" "*.ts" | wc -l
30
- ```
31
-
32
- **Skip review if:**
33
- - 0 `.tsx`/`.ts` files changed → no frontend code to review
34
- - Only changes in `*.json`, `*.md`, config files → infrastructure scope
35
- - `.morph/features/$ARGUMENTS/5-implement/code-review-nextjs.md` already exists from today → already reviewed
36
-
37
- If skipping: output `"Skipping code-review-nextjs: [reason]"` and stop.
38
-
39
- ---
40
-
41
- ## Step 1 — Run automated scan first
42
-
43
- ```bash
44
- node scripts/scan-nextjs.mjs src/
45
- ```
46
-
47
- Review and address CRITICAL findings before proceeding with the manual checklist below. Warnings can be addressed during review.
48
-
49
- ---
50
-
51
- ## Naming & Style (ref: naming-conventions.md)
52
-
53
- - [ ] `[CRITICAL]` File names use kebab-case (`user-card.tsx`, NOT `UserCard.tsx`)
54
- - [ ] `[HIGH]` Components exported as named exports (`export function UserCard`, NOT `export default function UserCard`)
55
- - [ ] `[HIGH]` Hook files named `use-{action}.ts` and export `use{Action}()`
56
- - [ ] `[HIGH]` Schema files named `{feature}.schemas.ts` with Zod exports
57
- - [ ] `[HIGH]` Type files named `{feature}.types.ts` with `z.infer<>` derived types
58
- - [ ] `[MEDIUM]` No abbreviations in public API names (`repository` not `repo`)
59
- - [ ] `[MEDIUM]` Feature folder uses kebab-case (`features/user-management/`, NOT `features/userManagement/`)
60
-
61
- ---
62
-
63
- ## Component Architecture (ref: app-router.md, components.md)
64
-
65
- ### Server vs Client Discipline
66
- - [ ] `[CRITICAL]` `'use client'` only on components that use hooks or event handlers
67
- - [ ] `[CRITICAL]` No `useEffect(() => { fetch(...) }, [])` for data fetching — use Server Components or TanStack Query
68
- - [ ] `[HIGH]` Server Components used for initial page data (no `'use client'` on page files)
69
- - [ ] `[HIGH]` `loading.tsx`, `error.tsx` co-located with every `page.tsx`
70
- - [ ] `[HIGH]` No business logic in `app/` route files — import from `features/`
71
-
72
- ### Three-Tier Hierarchy
73
- - [ ] `[CRITICAL]` No edits to `components/ui/` files — shadcn primitives are never modified
74
- - [ ] `[HIGH]` `components/` (Tier 2) has no imports from `features/` — no domain knowledge
75
- - [ ] `[HIGH]` Feature components (`features/*/components/`) do not import from other features
76
- - [ ] `[MEDIUM]` Feature cross-dependencies extracted to `components/` or `lib/`
77
-
78
- ---
79
-
80
- ## Data Fetching (ref: data-fetching.md)
81
-
82
- - [ ] `[CRITICAL]` No `useEffect` + `useState` pattern for API data — use `useQuery`
83
- - [ ] `[HIGH]` TanStack Query v5 syntax: `useQuery({ queryKey: [...], queryFn: async () => {} })`
84
- - [ ] `[HIGH]` Query key factory pattern used (`userKeys.lists()`, NOT hardcoded `['users']`)
85
- - [ ] `[HIGH]` `useMutation` used for POST/PUT/DELETE — not inline `fetch` in handlers
86
- - [ ] `[HIGH]` API responses validated with Zod before use
87
- - [ ] `[MEDIUM]` `onSuccess` in `useMutation` invalidates relevant query keys
88
- - [ ] `[MEDIUM]` `QueryClientProvider` wraps app in `app/layout.tsx`, not per-component
89
-
90
- ---
91
-
92
- ## Forms (ref: forms.md)
93
-
94
- - [ ] `[CRITICAL]` Zod schema defined BEFORE TypeScript type — type derived with `z.infer<>`
95
- - [ ] `[HIGH]` `useForm` uses `zodResolver(schema)` — NOT manual validation
96
- - [ ] `[HIGH]` shadcn `<Form>`, `<FormField>`, `<FormItem>`, `<FormLabel>`, `<FormControl>`, `<FormMessage>` used
97
- - [ ] `[HIGH]` Form submission uses `useMutation` — NOT direct `fetch` in `onSubmit`
98
- - [ ] `[MEDIUM]` `isPending` used for loading state — NOT `isLoading` (v5 renamed)
99
- - [ ] `[MEDIUM]` Root-level errors displayed: `form.formState.errors.root`
100
- - [ ] `[MEDIUM]` No `useState` for individual form fields — react-hook-form handles this
101
-
102
- ---
103
-
104
- ## State Management (ref: state-management.md)
105
-
106
- - [ ] `[HIGH]` No Zustand/Redux installed without documented justification
107
- - [ ] `[HIGH]` No React Context used for server state (API data) — use TanStack Query
108
- - [ ] `[MEDIUM]` Local UI state (open/closed, selected) in `useState` — not global store
109
- - [ ] `[MEDIUM]` Context only for truly global UI: theme, auth user, locale
110
- - [ ] `[LOW]` No prop drilling beyond 3 levels — consider Context or co-location
111
-
112
- ---
113
-
114
- ## TypeScript Discipline
115
-
116
- - [ ] `[CRITICAL]` No `any` type — use `unknown` and narrow, or fix the actual type
117
- - [ ] `[HIGH]` Types derived from Zod schemas (`type User = z.infer<typeof userSchema>`)
118
- - [ ] `[HIGH]` No duplicate type definitions — if the server returns it, define it once with Zod
119
- - [ ] `[MEDIUM]` API response types come from the shared schema, not manually written
120
- - [ ] `[MEDIUM]` `noUncheckedIndexedAccess` respected — array accesses use optional chaining
121
- - [ ] `[LOW]` No type assertions (`as User`) without validation
122
-
123
- ---
124
-
125
- ## Feature Structure (ref: project-structure.md)
126
-
127
- - [ ] `[HIGH]` Feature exposes public API via `features/{name}/index.ts` — no deep path imports
128
- - [ ] `[HIGH]` Consumers import from index: `from '@/features/users'` NOT `from '@/features/users/components/user-list'`
129
- - [ ] `[MEDIUM]` New features create: `components/`, `hooks/`, `types/` subdirectories
130
- - [ ] `[MEDIUM]` TanStack Query hooks in `features/{name}/hooks/` — NOT co-located with components
131
- - [ ] `[MEDIUM]` Zod schemas in `features/{name}/types/{name}.schemas.ts`
132
- - [ ] `[LOW]` Feature index only exports what external consumers actually need (no over-exposure)
133
-
134
- ---
135
-
136
- ## Testing (ref: testing.md)
137
-
138
- - [ ] `[HIGH]` Test files co-located with source (`user-card.test.tsx` next to `user-card.tsx`)
139
- - [ ] `[HIGH]` `@testing-library/user-event` used — NOT `fireEvent`
140
- - [ ] `[HIGH]` API calls mocked with MSW — NOT `jest.mock('fetch')` or `global.fetch = jest.fn()`
141
- - [ ] `[MEDIUM]` Hook tests use `QueryClientWrapper` helper with `retry: false`
142
- - [ ] `[MEDIUM]` Tests cover happy path + one error path per component
143
- - [ ] `[LOW]` No snapshot tests — use `expect(screen.getByText(...))`
144
-
145
- ---
146
-
147
- ## Quick Pre-Merge Checklist
148
-
149
- ```
150
- [ ] node scripts/scan-nextjs.mjs src/ — 0 CRITICAL findings
151
- [ ] File names are kebab-case (UserCard.tsx → user-card.tsx)
152
- [ ] 'use client' only on interactive components (hooks or event handlers)
153
- [ ] No useEffect for data fetching — Server Component or useQuery
154
- [ ] Zod schema defined first, type derived with z.infer<>
155
- [ ] zodResolver connected to useForm, useMutation for submit
156
- [ ] Query key factory used (userKeys.lists() not ['users'])
157
- [ ] Feature public API via features/{name}/index.ts
158
- [ ] components/ui/ files untouched (shadcn CLI only)
159
- [ ] Tests: userEvent not fireEvent, MSW not mock fetch
160
- ```
161
-
162
- ---
163
-
164
- *Covers: naming-conventions.md + app-router.md + components.md + data-fetching.md + forms.md + state-management.md + testing.md + project-structure.md*
165
- *MORPH-SPEC by Polymorphism Tech*
@@ -1,254 +0,0 @@
1
- # Code Review Report — User Management Feature
2
-
3
- > Example of a well-structured Next.js code review output. Filled-in reference — not a template.
4
-
5
- **Scope:** `src/features/users/` + `src/app/(dashboard)/users/page.tsx`
6
- **Date:** 2026-02-23
7
- **Reviewer:** code-review-nextjs skill
8
-
9
- ---
10
-
11
- ## Automated Scan Results
12
-
13
- ```bash
14
- $ node scripts/scan-nextjs.mjs src/features/users/
15
-
16
- CRITICAL (1)
17
- features/users/components/UserList.tsx:1 — React hooks used (useState) without 'use client'
18
-
19
- HIGH/MEDIUM (2)
20
- features/users/components/UserList.tsx — PascalCase filename (should be user-list.tsx)
21
- features/users/components/user-form.tsx — 'use client' directive present but no interactivity detected
22
-
23
- Summary: 8 files scanned | 3 issues (1 critical, 2 high/medium)
24
- ```
25
-
26
- ---
27
-
28
- ## Findings by Severity
29
-
30
- | Severity | Count |
31
- |----------|-------|
32
- | CRITICAL | 2 |
33
- | HIGH | 3 |
34
- | MEDIUM | 2 |
35
- | LOW | 1 |
36
-
37
- ---
38
-
39
- ### [CRITICAL] Missing 'use client' on interactive component
40
-
41
- **File:** `src/features/users/components/UserList.tsx:1`
42
-
43
- **Current code:**
44
- ```tsx
45
- import { useState } from 'react';
46
-
47
- export function UserList() {
48
- const [selected, setSelected] = useState<string | null>(null);
49
- return <div onClick={() => setSelected('test')}>...</div>;
50
- }
51
- ```
52
-
53
- **Suggested fix:**
54
- ```tsx
55
- 'use client';
56
-
57
- import { useState } from 'react';
58
- // ... rest unchanged
59
- ```
60
-
61
- **Why:** React hooks (`useState`) require `'use client'`. Without it, Next.js treats this as a Server Component and the `useState` call fails at runtime.
62
-
63
- ---
64
-
65
- ### [CRITICAL] useEffect for data fetching
66
-
67
- **File:** `src/features/users/components/user-list.tsx:8`
68
-
69
- **Current code:**
70
- ```tsx
71
- 'use client';
72
- import { useEffect, useState } from 'react';
73
-
74
- export function UserList() {
75
- const [users, setUsers] = useState([]);
76
- useEffect(() => {
77
- fetch('/api/users').then(r => r.json()).then(setUsers);
78
- }, []);
79
- return <ul>{users.map(u => <li key={u.id}>{u.name}</li>)}</ul>;
80
- }
81
- ```
82
-
83
- **Suggested fix:**
84
- ```tsx
85
- // Option A — Server Component (no 'use client' needed)
86
- // app/(dashboard)/users/page.tsx
87
- async function getUsers() {
88
- const res = await fetch(`${process.env.API_URL}/api/users`, { next: { revalidate: 30 } });
89
- return res.json();
90
- }
91
- export default async function UsersPage() {
92
- const users = await getUsers();
93
- return <UserList initialData={users} />;
94
- }
95
-
96
- // Option B — TanStack Query (when client interactivity needed)
97
- 'use client';
98
- import { useUsers } from '@/features/users/hooks/use-users';
99
- export function UserList() {
100
- const { data: users = [], isLoading } = useUsers();
101
- if (isLoading) return <div>Loading...</div>;
102
- return <ul>{users.map(u => <li key={u.id}>{u.name}</li>)}</ul>;
103
- }
104
- ```
105
-
106
- **Why:** `useEffect` + `useState` for fetching: (1) doubles renders, (2) no caching, (3) no SSR, (4) no error/loading states, (5) can't be cancelled. TanStack Query or Server Components solve all five.
107
-
108
- ---
109
-
110
- ### [HIGH] PascalCase file name
111
-
112
- **File:** `src/features/users/components/UserList.tsx`
113
-
114
- **Suggested fix:** Rename to `user-list.tsx`
115
-
116
- **Why:** Linux servers are case-sensitive. `UserList.tsx` and `user-list.tsx` are different files on the server but the same on macOS/Windows, causing import failures in production.
117
-
118
- ---
119
-
120
- ### [HIGH] Default export on non-page component
121
-
122
- **File:** `src/features/users/components/user-card.tsx:3`
123
-
124
- **Current code:**
125
- ```tsx
126
- export default function UserCard({ user }: { user: User }) {
127
- ```
128
-
129
- **Suggested fix:**
130
- ```tsx
131
- export function UserCard({ user }: { user: User }) {
132
- ```
133
-
134
- **Why:** Named exports are refactor-safe — IDEs track renames automatically. Default exports are anonymous in imports (`import X from './user-card'` allows `X` to be anything).
135
-
136
- ---
137
-
138
- ### [HIGH] Type defined manually instead of deriving from Zod schema
139
-
140
- **File:** `src/features/users/types/user.types.ts:1`
141
-
142
- **Current code:**
143
- ```ts
144
- export type User = {
145
- id: string;
146
- name: string;
147
- email: string;
148
- role: 'admin' | 'user';
149
- };
150
- ```
151
-
152
- **Suggested fix:**
153
- ```ts
154
- // user.schemas.ts — single source of truth
155
- export const userSchema = z.object({
156
- id: z.string(),
157
- name: z.string(),
158
- email: z.string().email(),
159
- role: z.enum(['admin', 'user']),
160
- });
161
-
162
- // user.types.ts — derived, never written manually
163
- export type User = z.infer<typeof userSchema>;
164
- ```
165
-
166
- **Why:** Manually written types drift from API responses. `z.infer<>` ensures the TypeScript type is always in sync with the runtime validation.
167
-
168
- ---
169
-
170
- ### [MEDIUM] Deep path import instead of feature index
171
-
172
- **File:** `src/app/(dashboard)/users/page.tsx:2`
173
-
174
- **Current code:**
175
- ```tsx
176
- import { UserList } from '@/features/users/components/user-list';
177
- ```
178
-
179
- **Suggested fix:**
180
- ```tsx
181
- import { UserList } from '@/features/users';
182
- ```
183
-
184
- **Why:** Deep path imports expose internal structure. When `user-list.tsx` moves or is renamed, every consumer breaks. The feature index is the stable public API.
185
-
186
- ---
187
-
188
- ### [MEDIUM] Query key not using factory pattern
189
-
190
- **File:** `src/features/users/hooks/use-users.ts:8`
191
-
192
- **Current code:**
193
- ```ts
194
- return useQuery({
195
- queryKey: ['users'],
196
- ```
197
-
198
- **Suggested fix:**
199
- ```ts
200
- // query-keys.ts
201
- export const userKeys = {
202
- all: ['users'] as const,
203
- lists: () => [...userKeys.all, 'list'] as const,
204
- };
205
-
206
- // use-users.ts
207
- return useQuery({
208
- queryKey: userKeys.lists(),
209
- ```
210
-
211
- **Why:** Hardcoded `['users']` cannot be selectively invalidated. `queryClient.invalidateQueries({ queryKey: userKeys.lists() })` correctly invalidates only list queries, not detail queries with the same prefix.
212
-
213
- ---
214
-
215
- ### [LOW] Test uses fireEvent instead of userEvent
216
-
217
- **File:** `src/features/users/components/user-card.test.tsx:14`
218
-
219
- **Current code:**
220
- ```tsx
221
- fireEvent.click(screen.getByRole('button', { name: /edit/i }));
222
- ```
223
-
224
- **Suggested fix:**
225
- ```tsx
226
- await userEvent.click(screen.getByRole('button', { name: /edit/i }));
227
- ```
228
-
229
- **Why:** `fireEvent.click` dispatches a synthetic event. `userEvent.click` simulates the full browser interaction sequence (pointerdown, mousedown, focus, click, etc.) — closer to real user behaviour.
230
-
231
- ---
232
-
233
- ## Top Priorities
234
-
235
- 1. `UserList.tsx:1` — CRITICAL missing `'use client'` (2 min fix)
236
- 2. `user-list.tsx:8` — CRITICAL useEffect fetch → useQuery (15 min)
237
- 3. `UserList.tsx` — HIGH rename to `user-list.tsx` (2 min)
238
- 4. `user-card.tsx:3` — HIGH named export (2 min)
239
- 5. `user.types.ts:1` — HIGH derive from Zod (10 min)
240
-
241
- ---
242
-
243
- ## Passed Checks ✅
244
-
245
- - `components/ui/` files untouched
246
- - `zodResolver` correctly wired in `user-form.tsx`
247
- - `isPending` used (v5 correct — not `isLoading`)
248
- - `loading.tsx` and `error.tsx` present in `app/(dashboard)/users/`
249
- - Feature has `index.ts` re-exporting public API
250
- - Test file co-located with component
251
-
252
- ---
253
-
254
- *MORPH-SPEC by Polymorphism Tech*
@@ -1,189 +0,0 @@
1
- #!/usr/bin/env node
2
- /**
3
- * scan-nextjs.mjs
4
- *
5
- * Scans .tsx/.ts files for MORPH-SPEC Next.js coding standard violations.
6
- * Executed locally by Claude via Bash — output returned to Claude.
7
- *
8
- * Usage:
9
- * node scan-nextjs.mjs [path] # scan directory or file
10
- * node scan-nextjs.mjs src/ # scan src/ recursively
11
- * node scan-nextjs.mjs --summary # counts only, no details
12
- * node scan-nextjs.mjs --diff # scan only changed files (git diff main...HEAD)
13
- * node scan-nextjs.mjs --diff --base=develop # use different base branch
14
- *
15
- * Checks (ref: framework/standards/frontend/nextjs/):
16
- * - Non-PascalCase component files → MyComponent.tsx, not myComponent.tsx
17
- * - Explicit `any` type annotations → avoid untyped code
18
- * - useEffect with fetch inside → use TanStack Query instead
19
- * - Importing from components/ui/ → use shadcn/ui without modification
20
- * - useMutation calling fetch directly → use api client utilities
21
- */
22
-
23
- import { readdirSync, readFileSync, statSync, existsSync } from 'fs';
24
- import { join, extname, basename, relative } from 'path';
25
- import { execSync } from 'child_process';
26
-
27
- const args = process.argv.slice(2);
28
- const diffMode = args.includes('--diff');
29
- const summaryOnly = args.includes('--summary');
30
- const baseBranch = args.find(a => a.startsWith('--base='))?.split('=')[1] ?? 'main';
31
- const targetPath = args.find(a => !a.startsWith('--')) ?? '.';
32
-
33
- const CHECKS = [
34
- {
35
- id: 'NON_PASCAL_CASE_COMPONENT',
36
- severity: 'CRITICAL',
37
- fileLevel: true,
38
- check: (filePath) => {
39
- const name = basename(filePath, extname(filePath));
40
- // Only check files that look like components (exclude lowercase utils/hooks/types)
41
- if (!filePath.endsWith('.tsx')) return null;
42
- // Skip files starting with lowercase (could be utils)
43
- if (/^[a-z]/.test(name) && !name.includes('-') && !name.includes('.')) return null;
44
- // Flag kebab-case or non-PascalCase component files
45
- if (name.includes('-') || /^[a-z]/.test(name)) {
46
- return `Component file '${name}.tsx' is not PascalCase → rename to '${toPascalCase(name)}.tsx'`;
47
- }
48
- return null;
49
- },
50
- },
51
- {
52
- id: 'EXPLICIT_ANY_TYPE',
53
- severity: 'CRITICAL',
54
- pattern: /:\s*any\b(?!\s*\[)/g,
55
- message: (m, line) => `Explicit 'any' type annotation on line ${line} → use proper TypeScript type`,
56
- },
57
- {
58
- id: 'USE_EFFECT_FETCH',
59
- severity: 'CRITICAL',
60
- pattern: /useEffect\s*\(\s*\(\s*\)\s*=>\s*\{[^}]*fetch\s*\(/gs,
61
- message: () => 'useEffect with fetch() inside → use TanStack Query (useQuery/useMutation) instead',
62
- },
63
- {
64
- id: 'COMPONENTS_UI_IMPORT_MODIFIED',
65
- severity: 'CRITICAL',
66
- pattern: /from\s+['"](?:@\/|\.\.\/)*components\/ui\/(\w+)['"]/g,
67
- message: (m) => `Import from 'components/ui/${m[1]}' — do not modify shadcn/ui components directly; extend via composition instead`,
68
- },
69
- {
70
- id: 'USE_MUTATION_FETCH',
71
- severity: 'HIGH',
72
- pattern: /useMutation\s*\(\s*\{[^}]*mutationFn[^}]*fetch\s*\(/gs,
73
- message: () => 'useMutation with direct fetch() call → use a typed API client utility function instead',
74
- },
75
- ];
76
-
77
- function toPascalCase(str) {
78
- return str
79
- .replace(/-([a-z])/g, (_, c) => c.toUpperCase())
80
- .replace(/^[a-z]/, (c) => c.toUpperCase());
81
- }
82
-
83
- function collectTsFiles(dir) {
84
- if (!existsSync(dir)) return [];
85
- const stat = statSync(dir);
86
- if (stat.isFile()) {
87
- const ext = extname(dir);
88
- return ext === '.tsx' || ext === '.ts' ? [dir] : [];
89
- }
90
- const results = [];
91
- const ignored = ['node_modules', '.git', '.next', 'dist', 'build', '.turbo'];
92
- for (const entry of readdirSync(dir, { withFileTypes: true })) {
93
- if (entry.isDirectory() && !ignored.includes(entry.name)) {
94
- results.push(...collectTsFiles(join(dir, entry.name)));
95
- } else if (entry.isFile()) {
96
- const ext = extname(entry.name);
97
- if (ext === '.tsx' || ext === '.ts') {
98
- results.push(join(dir, entry.name));
99
- }
100
- }
101
- }
102
- return results;
103
- }
104
-
105
- function getChangedFiles(base) {
106
- try {
107
- const raw = execSync(`git diff --name-only ${base}...HEAD`, { encoding: 'utf-8', stdio: ['pipe', 'pipe', 'pipe'] });
108
- return raw.split('\n')
109
- .map(f => f.trim())
110
- .filter(f => (f.endsWith('.ts') || f.endsWith('.tsx')) && existsSync(f));
111
- } catch {
112
- return null;
113
- }
114
- }
115
-
116
- let mode = 'full';
117
- let files;
118
- if (diffMode) {
119
- const changed = getChangedFiles(baseBranch);
120
- if (changed !== null) {
121
- files = changed;
122
- mode = 'diff';
123
- } else {
124
- files = collectTsFiles(targetPath);
125
- }
126
- } else {
127
- files = collectTsFiles(targetPath);
128
- }
129
-
130
- const findings = [];
131
-
132
- for (const file of files) {
133
- const content = readFileSync(file, 'utf-8');
134
- const lines = content.split('\n');
135
- const relFile = relative(process.cwd(), file).replace(/\\/g, '/');
136
-
137
- for (const check of CHECKS) {
138
- if (check.fileLevel) {
139
- const msg = check.check(file);
140
- if (msg) {
141
- findings.push({
142
- severity: check.severity,
143
- id: check.id,
144
- file: relFile,
145
- line: 1,
146
- message: msg,
147
- snippet: '',
148
- });
149
- }
150
- continue;
151
- }
152
-
153
- const regex = new RegExp(check.pattern.source, check.pattern.flags);
154
- let match;
155
- while ((match = regex.exec(content)) !== null) {
156
- const lineNum = content.slice(0, match.index).split('\n').length;
157
- const msg = check.message(match, lineNum);
158
- if (!msg) continue;
159
- findings.push({
160
- severity: check.severity,
161
- id: check.id,
162
- file: relFile,
163
- line: lineNum,
164
- message: msg,
165
- snippet: lines[lineNum - 1]?.trim().slice(0, 100),
166
- });
167
- }
168
- }
169
- }
170
-
171
- const bySeverity = { CRITICAL: 0, HIGH: 0, MEDIUM: 0, LOW: 0 };
172
- for (const f of findings) bySeverity[f.severity] = (bySeverity[f.severity] ?? 0) + 1;
173
-
174
- const summary = {
175
- scanned: files.length,
176
- findings: findings.length,
177
- bySeverity,
178
- clean: findings.length === 0,
179
- mode,
180
- ...(mode === 'diff' && { baseBranch, changedFilesCount: files.length }),
181
- };
182
-
183
- if (summaryOnly) {
184
- console.log(JSON.stringify(summary, null, 2));
185
- } else {
186
- console.log(JSON.stringify({ summary, findings }, null, 2));
187
- }
188
-
189
- process.exit(findings.some(f => f.severity === 'CRITICAL') ? 1 : 0);