@polymorphism-tech/morph-spec 4.21.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 (213) 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 -1183
  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 -28
  33. package/framework/hooks/shared/state-reader.js +4 -5
  34. package/framework/{skills/level-0-meta/mcp-registry.json → mcp/registry.json} +254 -210
  35. package/framework/phases.json +40 -114
  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/standards/STANDARDS.json +32 -0
  47. package/framework/standards/frontend/design-system/ai-image-generation.md +244 -0
  48. package/framework/standards/integration/mcp/mcp-tools.md +48 -0
  49. package/framework/templates/CLAUDE.md.core.guide.md +29 -0
  50. package/framework/templates/CLAUDE.md.core.template +22 -0
  51. package/framework/templates/REGISTRY.json +4 -4
  52. package/framework/workflows/configs/fast-track.json +5 -10
  53. package/framework/workflows/configs/full.json +4 -8
  54. package/framework/workflows/configs/quick.json +32 -0
  55. package/framework/workflows/configs/standard.json +57 -64
  56. package/package.json +7 -6
  57. package/src/commands/mcp/mcp-setup.js +58 -31
  58. package/src/commands/project/doctor.js +69 -70
  59. package/src/commands/project/init.js +26 -5
  60. package/src/commands/project/status.js +18 -19
  61. package/src/commands/state/approve.js +1 -1
  62. package/src/commands/validation/validate-feature.js +18 -112
  63. package/src/core/paths/output-schema.js +133 -151
  64. package/src/core/state/phase-state-machine.js +10 -24
  65. package/src/core/state/state-manager.js +17 -17
  66. package/src/core/workflows/workflow-detector.js +214 -31
  67. package/src/core/workflows/workflow-router.js +204 -0
  68. package/src/dashboard/app/pages/AgentMap.jsx +32 -33
  69. package/src/dashboard/app/pages/LiveState.jsx +1 -1
  70. package/src/dashboard/app/pages/PhasePipeline.jsx +2 -4
  71. package/src/dashboard/app/pages/SkillsLibrary.jsx +2 -3
  72. package/src/dashboard/app/pages/Workflows.jsx +2 -2
  73. package/src/dashboard/scanner/agents-scanner.js +30 -35
  74. package/src/lib/agents/metrics-aggregator.js +1 -1
  75. package/src/lib/agents/output-collector.js +7 -8
  76. package/src/lib/context/context-builder.js +289 -0
  77. package/src/lib/detectors/claude-config-detector.js +19 -3
  78. package/src/lib/generators/context-generator.js +20 -42
  79. package/src/lib/generators/index.js +1 -0
  80. package/src/lib/generators/mandate-generator.js +512 -0
  81. package/src/lib/generators/metadata-extractor.js +1 -1
  82. package/src/lib/generators/recap-generator.js +3 -4
  83. package/src/lib/installers/mcp-installer.js +300 -92
  84. package/src/lib/phase-chain/phase-validator.js +36 -40
  85. package/src/lib/stack/stack-profile.js +74 -91
  86. package/src/lib/tasks/task-parser.js +1 -1
  87. package/src/lib/tasks/wave-resolver.js +353 -0
  88. package/src/lib/validators/checkpoint-persistence.js +2 -2
  89. package/src/lib/validators/content/cross-phase-validator.js +281 -0
  90. package/src/lib/validators/content/index.js +1 -0
  91. package/src/lib/validators/shared/emit-validator-dispatch.js +6 -56
  92. package/src/scripts/global-install.js +2 -27
  93. package/src/utils/agents-installer.js +224 -447
  94. package/src/utils/claude-settings-manager.js +57 -15
  95. package/src/utils/file-copier.js +1 -0
  96. package/src/utils/hooks-installer.js +15 -117
  97. package/src/utils/skills-installer.js +12 -18
  98. package/bin/detect-agents.js +0 -226
  99. package/bin/task-manager.js +0 -1036
  100. package/framework/agents/README.md +0 -13
  101. package/framework/agents/ai-agents/ai-system-architect.md +0 -194
  102. package/framework/agents/ai-agents/vector-search-expert.md +0 -247
  103. package/framework/agents/architecture/architecture-expert.md +0 -98
  104. package/framework/agents/architecture/morph-spec-architect.md +0 -66
  105. package/framework/agents/architecture/packages-validator.md +0 -89
  106. package/framework/agents/architecture/security-expert.md +0 -79
  107. package/framework/agents/architecture/seo-growth-hacker.md +0 -168
  108. package/framework/agents/architecture/standards-architect.md +0 -153
  109. package/framework/agents/backend/dotnet-senior.md +0 -163
  110. package/framework/agents/backend/ef-modeler.md +0 -119
  111. package/framework/agents/backend/hangfire-orchestrator.md +0 -133
  112. package/framework/agents/backend/ms-agent-expert.md +0 -55
  113. package/framework/agents/backend/neon-expert.md +0 -379
  114. package/framework/agents/frontend/css-specialist.md +0 -89
  115. package/framework/agents/frontend/design-system-validator.md +0 -100
  116. package/framework/agents/frontend/gsap-animator.md +0 -131
  117. package/framework/agents/frontend/nextjs-component-validator.md +0 -97
  118. package/framework/agents/frontend/nextjs-expert.md +0 -201
  119. package/framework/agents/frontend/ui-designer.md +0 -259
  120. package/framework/agents/infrastructure/infra-architect.md +0 -215
  121. package/framework/agents/integrations/asaas-financial.md +0 -138
  122. package/framework/agents/integrations/neon-auth.md +0 -151
  123. package/framework/agents/integrations/resend-email.md +0 -127
  124. package/framework/hooks/claude-code/post-tool-use/agent-complete.js +0 -122
  125. package/framework/hooks/claude-code/post-tool-use/dispatch.js +0 -363
  126. package/framework/hooks/claude-code/post-tool-use/handle-tool-failure.js +0 -78
  127. package/framework/hooks/claude-code/post-tool-use/validator-feedback.js +0 -194
  128. package/framework/hooks/claude-code/pre-compact/save-morph-context.js +0 -199
  129. package/framework/hooks/claude-code/pre-tool-use/task-tracking-guard.js +0 -55
  130. package/framework/hooks/claude-code/session-start/inject-morph-context.js +0 -323
  131. package/framework/hooks/claude-code/session-start/post-compact-restore.js +0 -41
  132. package/framework/hooks/claude-code/session-start/resume-context.js +0 -77
  133. package/framework/hooks/claude-code/teammate-idle/teammate-idle.js +0 -90
  134. package/framework/hooks/claude-code/user-prompt/enrich-prompt.js +0 -114
  135. package/framework/hooks/shared/compact-restore.js +0 -123
  136. package/framework/hooks/shared/dispatch-helpers.js +0 -147
  137. package/framework/hooks/shared/skill-reminder-helpers.js +0 -79
  138. package/framework/hooks/shared/stale-task-reset.js +0 -57
  139. package/framework/hooks/shared/worktree-helpers.js +0 -75
  140. package/framework/skills/level-0-meta/README.md +0 -7
  141. package/framework/skills/level-0-meta/morph-agent-teams/SKILL.md +0 -472
  142. package/framework/skills/level-0-meta/morph-brainstorming/SKILL.md +0 -174
  143. package/framework/skills/level-0-meta/morph-brainstorming/references/proposal-example.md +0 -138
  144. package/framework/skills/level-0-meta/morph-checklist/SKILL.md +0 -145
  145. package/framework/skills/level-0-meta/morph-code-review/SKILL.md +0 -250
  146. package/framework/skills/level-0-meta/morph-code-review/references/review-example.md +0 -164
  147. package/framework/skills/level-0-meta/morph-code-review/references/review-guidelines.md +0 -100
  148. package/framework/skills/level-0-meta/morph-code-review/scripts/scan-csharp.mjs +0 -151
  149. package/framework/skills/level-0-meta/morph-code-review-nextjs/SKILL.md +0 -165
  150. package/framework/skills/level-0-meta/morph-code-review-nextjs/references/review-example-nextjs.md +0 -254
  151. package/framework/skills/level-0-meta/morph-code-review-nextjs/scripts/scan-nextjs.mjs +0 -189
  152. package/framework/skills/level-0-meta/morph-frontend-review/SKILL.md +0 -344
  153. package/framework/skills/level-0-meta/morph-frontend-review/scripts/scan-accessibility.mjs +0 -376
  154. package/framework/skills/level-0-meta/morph-init/SKILL.md +0 -537
  155. package/framework/skills/level-0-meta/morph-parallel-dispatch/SKILL.md +0 -225
  156. package/framework/skills/level-0-meta/morph-post-implementation/SKILL.md +0 -382
  157. package/framework/skills/level-0-meta/morph-post-implementation/scripts/detect-dev-server.mjs +0 -153
  158. package/framework/skills/level-0-meta/morph-post-implementation/scripts/detect-stack.mjs +0 -234
  159. package/framework/skills/level-0-meta/morph-simulation-checklist/SKILL.md +0 -106
  160. package/framework/skills/level-0-meta/morph-tool-usage-guide/SKILL.md +0 -243
  161. package/framework/skills/level-0-meta/morph-tool-usage-guide/references/tools-per-phase.md +0 -169
  162. package/framework/skills/level-0-meta/morph-verification-before-completion/SKILL.md +0 -148
  163. package/framework/skills/level-0-meta/morph-verification-before-completion/scripts/check-phase-outputs.mjs +0 -110
  164. package/framework/skills/level-1-workflows/README.md +0 -7
  165. package/framework/skills/level-1-workflows/morph-phase-codebase-analysis/SKILL.md +0 -269
  166. package/framework/skills/level-1-workflows/morph-phase-design/SKILL.md +0 -453
  167. package/framework/skills/level-1-workflows/morph-phase-design/references/architecture-analysis-guide.md +0 -44
  168. package/framework/skills/level-1-workflows/morph-phase-design/references/spec-authoring-guide.md +0 -55
  169. package/framework/skills/level-1-workflows/morph-phase-design/references/spec-example.md +0 -253
  170. package/framework/skills/level-1-workflows/morph-phase-implement/.morph/logs/activity.json +0 -38
  171. package/framework/skills/level-1-workflows/morph-phase-implement/SKILL.md +0 -493
  172. package/framework/skills/level-1-workflows/morph-phase-implement/prompts/code-quality-reviewer-prompt.md +0 -50
  173. package/framework/skills/level-1-workflows/morph-phase-implement/prompts/implementer-prompt.md +0 -46
  174. package/framework/skills/level-1-workflows/morph-phase-implement/prompts/spec-reviewer-prompt.md +0 -47
  175. package/framework/skills/level-1-workflows/morph-phase-implement/references/recap-example.md +0 -132
  176. package/framework/skills/level-1-workflows/morph-phase-implement/references/vsa-implementation-guide.md +0 -92
  177. package/framework/skills/level-1-workflows/morph-phase-plan/SKILL.md +0 -257
  178. package/framework/skills/level-1-workflows/morph-phase-tasks/.morph/logs/activity.json +0 -14
  179. package/framework/skills/level-1-workflows/morph-phase-tasks/SKILL.md +0 -291
  180. package/framework/skills/level-1-workflows/morph-phase-tasks/references/task-planning-patterns.md +0 -143
  181. package/framework/skills/level-1-workflows/morph-phase-tasks/references/tasks-example.md +0 -404
  182. package/framework/skills/level-1-workflows/morph-phase-tasks/scripts/validate-tasks.mjs +0 -112
  183. package/framework/skills/level-1-workflows/morph-phase-uiux/SKILL.md +0 -788
  184. package/framework/skills/level-1-workflows/morph-scope-escalation/SKILL.md +0 -147
  185. package/framework/squad-templates/backend-only.json +0 -47
  186. package/framework/squad-templates/frontend-only.json +0 -56
  187. package/framework/squad-templates/full-stack.json +0 -74
  188. package/src/commands/agents/agent-metrics.js +0 -174
  189. package/src/commands/agents/audit-dispatch.js +0 -82
  190. package/src/commands/agents/detect-agents.js +0 -275
  191. package/src/commands/agents/dispatch-agents.js +0 -461
  192. package/src/commands/agents/index.js +0 -13
  193. package/src/commands/agents/manage-agents.js +0 -352
  194. package/src/commands/agents/project-metrics.js +0 -74
  195. package/src/commands/phase/phase-reset.js +0 -74
  196. package/src/commands/scope/escalate.js +0 -217
  197. package/src/commands/state/advance-phase.js +0 -600
  198. package/src/commands/state/phase-runner.js +0 -215
  199. package/src/commands/state/state.js +0 -444
  200. package/src/commands/task/expand.js +0 -100
  201. package/src/commands/tasks/index.js +0 -4
  202. package/src/commands/tasks/task.js +0 -105
  203. package/src/commands/templates/index.js +0 -5
  204. package/src/commands/templates/template-render.js +0 -93
  205. package/src/commands/trust/trust.js +0 -118
  206. package/src/lib/agents/agents-manager.js +0 -349
  207. package/src/lib/build/build-runner.js +0 -99
  208. package/src/lib/checkpoints/checkpoint-hooks.js +0 -111
  209. package/src/lib/contracts/sprint-contract-generator.js +0 -137
  210. package/src/lib/scope/impact-analyzer.js +0 -106
  211. package/src/lib/trust/trust-manager.js +0 -157
  212. package/src/utils/tier-helpers.js +0 -24
  213. /package/framework/hooks/claude-code/{post-tool-use → core}/loop-detect.js +0 -0
@@ -1,269 +0,0 @@
1
- ---
2
- name: morph-phase-codebase-analysis
3
- description: MORPH-SPEC Design sub-phase that analyzes existing codebase and database schema, producing schema-analysis.md with real column names, types, relationships, and field mismatches. Use at the start of Design phase before generating contracts.cs to prevent incorrect field names or types.
4
- user-invocable: false
5
- allowed-tools: Read, Write, Edit, Bash, Glob, Grep, AskUserQuestion
6
- cliVersion: "4.21.0"
7
- ---
8
-
9
- # MORPH Codebase Analysis - Design Sub-phase
10
-
11
- > INTERNAL: Automation skill for schema analysis step within Phase 2 (Design).
12
- > Called by `phase-design.md` Step 2. Not a standalone user command.
13
-
14
- Automates existing code analysis to generate `schema-analysis.md` with real database/code data.
15
-
16
- ## Prerequisites
17
-
18
- - [ ] Proposal phase completed
19
- - [ ] Feature has approved `proposal.md`
20
- - [ ] Project context loaded (stack, agents)
21
-
22
- ## Recommended Tools
23
-
24
- > **Ref:** `framework/skills/level-0-meta/morph-tool-usage-guide/SKILL.md` for complete guide.
25
- > **Ref:** `framework/standards/integration/mcp/mcp-tools.md` for MCP reference.
26
-
27
- | Action | Tool | Alternative |
28
- |------|------------|-------------|
29
- | List database tables | **Bash** `pg_dump $(neonctl connection-string)` or `psql <DB_URL>` | **Grep** `.from(` in code |
30
- | Get table schema | **Bash** `psql <DB_URL> -c "SELECT ... FROM information_schema.columns"` | **Read** type definitions |
31
- | Get FK relationships | **Bash** `psql <DB_URL> -c "SELECT ... FROM information_schema.table_constraints"` | **Grep** JOIN/FK patterns |
32
- | Get RLS policies | **Bash** `psql <DB_URL> -c "SELECT ... FROM pg_policies"` | **Read** policy files |
33
- | Find queries in code | **Grep** `\.from\(` in `*.ts,*.tsx,*.js,*.cs` | — |
34
- | Find type definitions | **Glob** `src/**/types/**/*.ts` or `**/Entities/**/*.cs` | — |
35
- | Read found files | **Read** each file | — |
36
- | Complex multi-file analysis | **Task** (subagent Explore) | Read individual |
37
- | Generate schema-analysis.md | **Write** using template | **Bash** template render |
38
-
39
- **Tools for this phase:** Neon CLI (`neonctl`) / psql (schema — **PRIORITY**), Generic database CLIs.
40
-
41
- ---
42
-
43
- ## Automated Workflow
44
-
45
- ### Step 1: Detect Analysis Method
46
-
47
- **IMPORTANT:** Do not assume the MCP is available and accessible.
48
- Verify first with a test call before attempting to use it.
49
-
50
- ```
51
- 0. **Database connectivity check:** Run `neonctl connection-string` to verify Neon CLI is configured.
52
- → IF Neon CLI is not configured → warn user: "Neon CLI not configured — run `neonctl auth`."
53
- → Ask user via AskUserQuestion: configure Neon or fall back to Method B.
54
-
55
- 1. IF Neon/PostgreSQL database detected (DATABASE_URL env var exists OR config.json stack includes database):
56
- → Run `neonctl connection-string` to get the DB URL
57
- → IF running (exit 0): extract DB URL from output → Use Method A (direct CLI/psql)
58
- → IF not running (exit non-zero):
59
- → Log: "Neon database not accessible — run `neonctl auth`"
60
- → Ask user via AskUserQuestion: configure it or fall back to Method B
61
-
62
- 2. IF no Neon/PostgreSQL database detected:
63
- → Use Method B (static code analysis)
64
- ```
65
-
66
- **Signs of unavailable Neon database:**
67
- - `neonctl connection-string` exits with non-zero code
68
- - Neon CLI not authenticated or project not configured
69
- - Project uses database other than Neon (CloudSQL, RDS, Azure SQL, etc.)
70
-
71
- ### Step 2A: CLI Method (Preferred — Neon CLI)
72
-
73
- **Tools:** Bash (Neon CLI + psql)
74
-
75
- ```bash
76
- # 0. Get DB URL
77
- neonctl connection-string
78
- # → Returns connection string, e.g.: postgresql://user:pass@ep-xxx.us-east-2.aws.neon.tech/neondb
79
-
80
- # 1. List all tables
81
- pg_dump $(neonctl connection-string) --schema public 2>/dev/null | grep "CREATE TABLE"
82
-
83
- # 2. For each feature-relevant table:
84
-
85
- # 2a. Complete schema
86
- psql $DB_URL -c "SELECT column_name, data_type, is_nullable, column_default \
87
- FROM information_schema.columns WHERE table_name = 'TABLE_NAME' ORDER BY ordinal_position"
88
-
89
- # 2b. Relationships (FK)
90
- psql $DB_URL -c "SELECT tc.table_name, kcu.column_name, ccu.table_name AS foreign_table, \
91
- ccu.column_name AS foreign_column FROM information_schema.table_constraints tc \
92
- JOIN information_schema.key_column_usage kcu ON tc.constraint_name = kcu.constraint_name \
93
- JOIN information_schema.constraint_column_usage ccu ON tc.constraint_name = ccu.constraint_name \
94
- WHERE tc.constraint_type = 'FOREIGN KEY' AND tc.table_name = 'TABLE_NAME'"
95
-
96
- # 2c. Indexes
97
- psql $DB_URL -c "SELECT indexname, indexdef FROM pg_indexes WHERE tablename = 'TABLE_NAME'"
98
-
99
- # 2d. RLS policies (security)
100
- psql $DB_URL -c "SELECT policyname, cmd, qual FROM pg_policies WHERE tablename = 'TABLE_NAME'"
101
- ```
102
-
103
- ### Step 2B: Static Analysis Method (Fallback)
104
-
105
- **Tools:** Grep, Glob, Read, Task (subagent for large projects)
106
-
107
- **Phase B1: Find Queries**
108
-
109
- ```
110
- Grep: "\.from\(|\.select\(|SELECT |context\.|dbContext\.|DbSet<"
111
- Type: ts,tsx,js,jsx,cs
112
- Output: files_with_matches
113
- ```
114
-
115
- **Phase B2: Read Query Files**
116
-
117
- For each found file, use **Read** to extract:
118
- - Table names: `from('leads')`, `DbSet<Lead>`, `FROM leads`
119
- - Column names: `.select('fullname, phonenumber')`, `l.FullName`
120
- - Data types: TypeScript interfaces, C# DTOs
121
- - Relationships: JOIN clauses, navigation properties
122
-
123
- **Phase B3: Find Type Definitions**
124
-
125
- ```
126
- # TypeScript/JavaScript:
127
- Glob: "src/**/types/**/*.ts"
128
- Glob: "src/**/*.d.ts"
129
- Glob: "src/**/interfaces/*.ts"
130
-
131
- # .NET:
132
- Glob: "**/*Dto.cs"
133
- Glob: "**/Entities/**/*.cs"
134
- Glob: "**/Models/**/*.cs"
135
- ```
136
-
137
- **Phase B4: When to use Task (subagent)**
138
-
139
- Use Task subagent **ONLY** when:
140
- - Project has 20+ query files
141
- - Multiple data access patterns (Neon + EF Core + raw SQL)
142
- - Precise cross-context analysis across many files
143
-
144
- Do not use Task subagent when:
145
- - Project has < 10 query files (direct Read is faster)
146
- - Data access pattern is uniform (only Neon OR only EF Core)
147
-
148
- ### Step 2B-Format: Standardized Format for Static Analysis
149
-
150
- **IMPORTANT:** When using Method B (static analysis), **always use the official template**.
151
- This ensures `contracts.cs` can be generated mechanically, without manual interpretation.
152
-
153
- The template is at `framework/templates/docs/schema-analysis.md`. Use it via:
154
-
155
- ```bash
156
- morph-spec template render docs/schema-analysis \
157
- .morph/features/{feature}/2-design/schema-analysis.md \
158
- '{
159
- "FEATURE_NAME": "{feature}",
160
- "FEATURE_NAME_TITLE": "{Feature Display Name}",
161
- "DATE": "YYYY-MM-DD",
162
- "AUTHOR": "Claude Code (Sonnet 4.6)",
163
- "method": "Static Code Analysis",
164
- "mcpUsed": "No",
165
- "tableCount": N,
166
- "fileCount": N,
167
- "tables": [
168
- {
169
- "name": "table_name",
170
- "codeSource": "path/to/file.ts",
171
- "columns": [
172
- { "name": "column_name", "type": "string", "nullable": false, "notes": "from SELECT query" }
173
- ],
174
- "relationships": [{ "description": "belongs to users via user_id" }],
175
- "indexes": [{ "description": "idx_leads_created_at (created_at DESC)" }]
176
- }
177
- ],
178
- "fieldMismatches": [
179
- { "description": "Code uses user.name but DB column is users.fullname" }
180
- ],
181
- "typeMismatches": [],
182
- "relationshipIssues": [],
183
- "dtoRecommendations": [
184
- {
185
- "tableName": "leads",
186
- "dtoName": "LeadDto",
187
- "fields": [
188
- { "type": "Guid", "name": "Id", "nullable": false, "comment": "PK" },
189
- { "type": "string", "name": "FullName", "nullable": false, "comment": "leads.fullname" }
190
- ]
191
- }
192
- ]
193
- }'
194
- ```
195
-
196
- **If template render is not available**, use **Write** tool to create the file directly
197
- following the structure above. The table and mismatch format is MANDATORY — without standard format
198
- it's not possible to generate contracts.cs mechanically.
199
-
200
- ### Step 3: Map Inconsistencies
201
-
202
- Create a map of:
203
-
204
- | Frontend/Code | Database | Type | Problem |
205
- |----------------|----------------|------|----------|
206
- | user.name | users.fullname | string | MISMATCH |
207
- | lead.phone | leads.phonenumber | string | MISMATCH |
208
- | order.metadata | orders.metadata | JSONB | Type complex |
209
-
210
- ### Step 4: Generate `schema-analysis.md`
211
-
212
- Use the template at `framework/templates/docs/schema-analysis.md`:
213
-
214
- ```bash
215
- morph-spec template render docs/schema-analysis \
216
- .morph/features/{feature-name}/2-design/schema-analysis.md \
217
- '{ "FEATURE_NAME": "{feature-name}", "DATE": "..." }'
218
- ```
219
-
220
- OR use **Write** tool to create directly with collected data.
221
-
222
- ### Step 5: Update State
223
-
224
- ```bash
225
- morph-spec state mark-output {feature-name} schema-analysis
226
- ```
227
-
228
- ---
229
-
230
- ## Outputs
231
-
232
- - `.morph/features/{feature}/2-design/schema-analysis.md`
233
- - State updated with `schemaAnalysis` output
234
-
235
- ## CHECKPOINT
236
-
237
- Before proceeding to contracts.cs, present results and ask for confirmation using `AskUserQuestion`:
238
-
239
- ```json
240
- {
241
- "questions": [
242
- {
243
- "header": "Schema Review",
244
- "question": "Schema analysis complete: {N} tables, {N} field mismatches, {N} type mismatches, {N} relationships. Is the analysis correct?",
245
- "multiSelect": false,
246
- "options": [
247
- { "label": "Correct", "description": "Schema analysis matches the real database" },
248
- { "label": "Has issues", "description": "I see problems — let me explain" }
249
- ]
250
- },
251
- {
252
- "header": "Contracts",
253
- "question": "May I generate contracts.cs based on this real schema?",
254
- "multiSelect": false,
255
- "options": [
256
- { "label": "Generate contracts", "description": "Proceed to contracts.cs using the analyzed schema" },
257
- { "label": "Wait", "description": "I want to review schema-analysis.md first" }
258
- ]
259
- }
260
- ]
261
- }
262
- ```
263
-
264
- **If "Has issues"** → ask what's wrong, fix schema-analysis.md, re-present checkpoint.
265
- **If "Correct" + "Generate contracts"** → proceed to contracts generation.
266
-
267
- ---
268
-
269
- *MORPH-SPEC by Polymorphism Tech*