@polymorphism-tech/morph-spec 4.9.0 → 4.10.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 (164) hide show
  1. package/README.md +2 -2
  2. package/bin/morph-spec.js +30 -0
  3. package/bin/task-manager.js +34 -22
  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 +35 -98
  8. package/framework/agents/backend/api-designer.md +3 -0
  9. package/framework/agents/backend/dotnet-senior.md +3 -0
  10. package/framework/agents/backend/ef-modeler.md +2 -0
  11. package/framework/agents/backend/hangfire-orchestrator.md +2 -0
  12. package/framework/agents/backend/ms-agent-expert.md +2 -0
  13. package/framework/agents/frontend/blazor-builder.md +2 -0
  14. package/framework/agents/frontend/nextjs-expert.md +2 -0
  15. package/framework/agents/infrastructure/azure-architect.md +2 -0
  16. package/framework/agents/infrastructure/azure-deploy-specialist.md +2 -0
  17. package/framework/agents/infrastructure/bicep-architect.md +2 -0
  18. package/framework/agents/infrastructure/container-specialist.md +2 -0
  19. package/framework/agents/infrastructure/devops-engineer.md +3 -0
  20. package/framework/agents/infrastructure/infra-architect.md +3 -0
  21. package/framework/agents/integrations/asaas-financial.md +2 -0
  22. package/framework/agents/integrations/azure-identity.md +2 -0
  23. package/framework/agents/integrations/clerk-auth.md +3 -0
  24. package/framework/agents/integrations/hangfire-integration.md +2 -0
  25. package/framework/agents/integrations/resend-email.md +2 -0
  26. package/framework/agents.json +37 -7
  27. package/framework/commands/commit.md +166 -0
  28. package/framework/commands/morph-apply.md +156 -155
  29. package/framework/commands/morph-archive.md +33 -27
  30. package/framework/commands/morph-infra.md +83 -77
  31. package/framework/commands/morph-preflight.md +97 -55
  32. package/framework/commands/morph-proposal.md +131 -58
  33. package/framework/commands/morph-status.md +36 -30
  34. package/framework/commands/morph-troubleshoot.md +68 -59
  35. package/framework/hooks/claude-code/notification/approval-reminder.js +3 -2
  36. package/framework/hooks/claude-code/post-tool-use/dispatch.js +154 -31
  37. package/framework/hooks/claude-code/post-tool-use/skill-reminder.js +7 -84
  38. package/framework/hooks/claude-code/post-tool-use/validator-feedback.js +8 -17
  39. package/framework/hooks/claude-code/pre-compact/save-morph-context.js +16 -3
  40. package/framework/hooks/claude-code/pre-tool-use/enforce-phase-writes.js +4 -3
  41. package/framework/hooks/claude-code/pre-tool-use/protect-spec-files.js +3 -2
  42. package/framework/hooks/claude-code/pre-tool-use/task-tracking-guard.js +60 -0
  43. package/framework/hooks/claude-code/session-start/inject-morph-context.js +55 -2
  44. package/framework/hooks/claude-code/session-start/post-compact-restore.js +41 -0
  45. package/framework/hooks/claude-code/stop/validate-completion.js +2 -15
  46. package/framework/hooks/claude-code/user-prompt/enrich-prompt.js +23 -5
  47. package/framework/hooks/shared/compact-restore.js +100 -0
  48. package/framework/hooks/shared/dispatch-helpers.js +116 -0
  49. package/framework/hooks/shared/phase-utils.js +9 -5
  50. package/framework/hooks/shared/state-reader.js +27 -3
  51. package/framework/phases.json +30 -7
  52. package/framework/rules/csharp-standards.md +3 -0
  53. package/framework/rules/frontend-standards.md +2 -0
  54. package/framework/rules/infrastructure-standards.md +3 -0
  55. package/framework/rules/morph-workflow.md +143 -86
  56. package/framework/rules/nextjs-standards.md +2 -0
  57. package/framework/rules/testing-standards.md +3 -0
  58. package/framework/skills/level-0-meta/mcp-registry.json +86 -51
  59. package/framework/skills/level-0-meta/morph-brainstorming/SKILL.md +139 -0
  60. package/framework/skills/level-0-meta/morph-checklist/SKILL.md +42 -19
  61. package/framework/skills/level-0-meta/{code-review → morph-code-review}/SKILL.md +8 -5
  62. package/framework/skills/level-0-meta/{code-review-nextjs → morph-code-review-nextjs}/SKILL.md +8 -6
  63. package/framework/skills/level-0-meta/morph-frontend-review/SKILL.md +362 -0
  64. package/framework/skills/level-0-meta/morph-init/SKILL.md +114 -20
  65. package/framework/skills/level-0-meta/morph-post-implementation/SKILL.md +362 -0
  66. package/framework/skills/level-0-meta/morph-replicate/SKILL.md +95 -87
  67. package/framework/skills/level-0-meta/{simulation-checklist → morph-simulation-checklist}/SKILL.md +24 -0
  68. package/framework/skills/level-0-meta/{tool-usage-guide → morph-tool-usage-guide}/SKILL.md +43 -43
  69. package/framework/skills/level-0-meta/{tool-usage-guide → morph-tool-usage-guide}/references/tools-per-phase.md +1 -2
  70. package/framework/skills/level-0-meta/{verification-before-completion → morph-verification-before-completion}/SKILL.md +23 -12
  71. package/framework/skills/level-0-meta/{verification-before-completion → morph-verification-before-completion}/scripts/check-phase-outputs.mjs +2 -2
  72. package/framework/skills/level-1-workflows/morph-phase-clarify/SKILL.md +247 -0
  73. package/framework/skills/level-1-workflows/morph-phase-codebase-analysis/SKILL.md +270 -0
  74. package/framework/skills/level-1-workflows/morph-phase-design/SKILL.md +499 -0
  75. package/framework/skills/level-1-workflows/morph-phase-implement/.morph/logs/activity.json +38 -0
  76. package/framework/skills/level-1-workflows/morph-phase-implement/SKILL.md +472 -0
  77. package/framework/skills/level-1-workflows/morph-phase-implement/prompts/code-quality-reviewer-prompt.md +50 -0
  78. package/framework/skills/level-1-workflows/morph-phase-implement/prompts/implementer-prompt.md +45 -0
  79. package/framework/skills/level-1-workflows/morph-phase-implement/prompts/spec-reviewer-prompt.md +47 -0
  80. package/framework/skills/level-1-workflows/morph-phase-plan/SKILL.md +246 -0
  81. package/framework/skills/level-1-workflows/morph-phase-setup/SKILL.md +238 -0
  82. package/framework/skills/level-1-workflows/morph-phase-tasks/.morph/logs/activity.json +14 -0
  83. package/framework/skills/level-1-workflows/morph-phase-tasks/SKILL.md +312 -0
  84. package/framework/skills/level-1-workflows/{phase-tasks → morph-phase-tasks}/scripts/validate-tasks.mjs +3 -3
  85. package/framework/skills/level-1-workflows/morph-phase-uiux/SKILL.md +324 -0
  86. package/framework/skills/level-1-workflows/morph-scope-escalation/SKILL.md +146 -0
  87. package/framework/standards/integration/mcp/mcp-tools.md +25 -7
  88. package/framework/templates/docs/onboarding.md +2 -2
  89. package/package.json +3 -4
  90. package/src/commands/agents/dispatch-agents.js +50 -3
  91. package/src/commands/mcp/mcp-setup.js +39 -2
  92. package/src/commands/phase/phase-reset.js +74 -0
  93. package/src/commands/project/doctor.js +26 -7
  94. package/src/commands/project/update.js +4 -4
  95. package/src/commands/scope/escalate.js +215 -0
  96. package/src/commands/state/advance-phase.js +27 -53
  97. package/src/commands/state/state.js +1 -1
  98. package/src/commands/task/expand.js +100 -0
  99. package/src/core/paths/output-schema.js +4 -3
  100. package/src/core/state/phase-state-machine.js +7 -4
  101. package/src/core/state/state-manager.js +4 -3
  102. package/src/lib/detectors/claude-config-detector.js +93 -347
  103. package/src/lib/detectors/design-system-detector.js +189 -189
  104. package/src/lib/detectors/index.js +155 -57
  105. package/src/lib/generators/context-generator.js +2 -2
  106. package/src/lib/installers/mcp-installer.js +37 -5
  107. package/src/lib/phase-chain/phase-validator.js +22 -16
  108. package/src/lib/scope/impact-analyzer.js +106 -0
  109. package/src/lib/stack-filter.js +58 -0
  110. package/src/lib/tasks/task-parser.js +1 -1
  111. package/src/lib/validators/shared/emit-validator-dispatch.js +64 -0
  112. package/src/scripts/setup-infra.js +68 -18
  113. package/src/utils/agents-installer.js +51 -17
  114. package/src/utils/claude-md-injector.js +90 -0
  115. package/src/utils/file-copier.js +0 -1
  116. package/src/utils/hooks-installer.js +16 -5
  117. package/src/utils/skills-installer.js +67 -7
  118. package/CLAUDE.md +0 -98
  119. package/framework/memory/patterns-learned.md +0 -766
  120. package/framework/skills/level-0-meta/brainstorming/SKILL.md +0 -137
  121. package/framework/skills/level-0-meta/frontend-review/SKILL.md +0 -359
  122. package/framework/skills/level-0-meta/post-implementation/SKILL.md +0 -362
  123. package/framework/skills/level-0-meta/terminal-title/SKILL.md +0 -61
  124. package/framework/skills/level-0-meta/terminal-title/scripts/set_title.sh +0 -65
  125. package/framework/skills/level-1-workflows/phase-clarify/SKILL.md +0 -216
  126. package/framework/skills/level-1-workflows/phase-codebase-analysis/SKILL.md +0 -252
  127. package/framework/skills/level-1-workflows/phase-design/SKILL.md +0 -383
  128. package/framework/skills/level-1-workflows/phase-implement/SKILL.md +0 -492
  129. package/framework/skills/level-1-workflows/phase-setup/SKILL.md +0 -195
  130. package/framework/skills/level-1-workflows/phase-tasks/SKILL.md +0 -271
  131. package/framework/skills/level-1-workflows/phase-uiux/SKILL.md +0 -286
  132. package/src/commands/project/index.js +0 -8
  133. package/src/core/index.js +0 -10
  134. package/src/core/state/index.js +0 -8
  135. package/src/core/templates/index.js +0 -9
  136. package/src/core/templates/template-data-sources.js +0 -325
  137. package/src/core/workflows/index.js +0 -7
  138. package/src/lib/detectors/config-detector.js +0 -223
  139. package/src/lib/detectors/standards-generator.js +0 -335
  140. package/src/lib/detectors/structure-detector.js +0 -275
  141. package/src/lib/monitor/agent-resolver.js +0 -144
  142. package/src/lib/monitor/renderer.js +0 -230
  143. package/src/lib/orchestration/index.js +0 -7
  144. package/src/lib/orchestration/team-orchestrator.js +0 -404
  145. package/src/sanitizer/context-sanitizer.js +0 -221
  146. package/src/sanitizer/patterns.js +0 -163
  147. package/src/writer/file-writer.js +0 -86
  148. /package/framework/skills/level-0-meta/{brainstorming → morph-brainstorming}/references/proposal-example.md +0 -0
  149. /package/framework/skills/level-0-meta/{code-review → morph-code-review}/references/review-example.md +0 -0
  150. /package/framework/skills/level-0-meta/{code-review → morph-code-review}/references/review-guidelines.md +0 -0
  151. /package/framework/skills/level-0-meta/{code-review → morph-code-review}/scripts/scan-csharp.mjs +0 -0
  152. /package/framework/skills/level-0-meta/{code-review-nextjs → morph-code-review-nextjs}/references/review-example-nextjs.md +0 -0
  153. /package/framework/skills/level-0-meta/{code-review-nextjs → morph-code-review-nextjs}/scripts/scan-nextjs.mjs +0 -0
  154. /package/framework/skills/level-0-meta/{frontend-review → morph-frontend-review}/scripts/scan-accessibility.mjs +0 -0
  155. /package/framework/skills/level-0-meta/{post-implementation → morph-post-implementation}/scripts/detect-dev-server.mjs +0 -0
  156. /package/framework/skills/level-0-meta/{post-implementation → morph-post-implementation}/scripts/detect-stack.mjs +0 -0
  157. /package/framework/skills/level-1-workflows/{phase-clarify → morph-phase-clarify}/references/clarifications-example.md +0 -0
  158. /package/framework/skills/level-1-workflows/{phase-design → morph-phase-design}/references/architecture-analysis-guide.md +0 -0
  159. /package/framework/skills/level-1-workflows/{phase-design → morph-phase-design}/references/spec-authoring-guide.md +0 -0
  160. /package/framework/skills/level-1-workflows/{phase-design → morph-phase-design}/references/spec-example.md +0 -0
  161. /package/framework/skills/level-1-workflows/{phase-implement → morph-phase-implement}/references/recap-example.md +0 -0
  162. /package/framework/skills/level-1-workflows/{phase-implement → morph-phase-implement}/references/vsa-implementation-guide.md +0 -0
  163. /package/framework/skills/level-1-workflows/{phase-tasks → morph-phase-tasks}/references/task-planning-patterns.md +0 -0
  164. /package/framework/skills/level-1-workflows/{phase-tasks → morph-phase-tasks}/references/tasks-example.md +0 -0
@@ -0,0 +1,499 @@
1
+ ---
2
+ name: morph:phase-design
3
+ description: MORPH-SPEC Phase 2 (Design). Schema-first interactive design: reads EF models/Supabase/DB, validates findings with user, then routes to VSA Blueprint or DDD Architecture Blueprint based on config.architecture.style, producing spec.md, contracts.cs, schema-analysis.md, and decisions.md through a quality loop (score 0-100). Use after setup phase to create technical specifications grounded in the real database schema.
4
+ argument-hint: "[feature-name]"
5
+ user-invocable: false
6
+ allowed-tools: Read, Write, Edit, Bash, Glob, Grep, AskUserQuestion, Agent
7
+ cliVersion: "4.10.1"
8
+ ---
9
+
10
+ # MORPH Design — Phase 2
11
+
12
+ > INTERNAL: Workflow skill used by /morph-proposal during automated phase orchestration. Not a user command.
13
+
14
+ Schema-first interactive design: read the real schema, validate with user, generate blueprint, produce artifacts through a quality loop.
15
+
16
+ ## Prerequisites
17
+
18
+ - [ ] Phase 1 (Setup) completed
19
+ - [ ] Phase 1.5 (UI/UX) completed OR skipped
20
+ - [ ] Proposal approved by the user
21
+
22
+ ## Recommended Tools
23
+
24
+ > **Ref:** `framework/skills/level-0-meta/morph-tool-usage-guide/SKILL.md` for full guide.
25
+ > **Ref:** `references/spec-example.md` — filled-in spec.md showing expected output quality.
26
+ > **Ref:** `references/spec-authoring-guide.md` — section structure for spec.md.
27
+
28
+ | Action | Tool | Alternative |
29
+ |--------|------|-------------|
30
+ | Read proposal + UI specs | **Read** output files | — |
31
+ | **Detect architecture** | **Read** `.morph/config/config.json` → check `architecture.style` | **Bash** `grep` |
32
+ | **Schema: Supabase** | **Supabase MCP** `list_tables()`, `get_table_schema()`, `get_relationships()` | — |
33
+ | **Schema: EF Core** | **Glob** `**/Entities/**/*.cs` + **Glob** `**/*Context.cs` → **Read** | **Grep** `DbSet<` |
34
+ | **Schema: Next.js/TS** | **Glob** `src/**/types/**/*.ts` + **Grep** `interface\|type.*=` | — |
35
+ | Schema: RLS policies | **Supabase MCP** `query()` with `pg_policies` | **Read** policy files |
36
+ | Dispatch vsa-architect | **Agent** `subagent_type=vsa-architect` + `prompt=agent.taskPrompt` | — |
37
+ | Dispatch domain-architect | **Agent** `subagent_type=domain-architect` + `prompt=agent.taskPrompt` | — |
38
+ | Dispatch tech leads | **Agent** for each active agent from dispatch config | — |
39
+ | Research library | **Context7 MCP** `query_docs()` | **WebSearch** + **WebFetch** |
40
+ | Render contracts VSA | **Bash** `npx morph-spec template render dotnet-contracts-vsa ...` | — |
41
+ | Render contracts DDD | **Bash** `npx morph-spec template render dotnet-contracts-level{N} ...` | — |
42
+ | Render spec.md | **Bash** `npx morph-spec template render docs/spec ...` | — |
43
+ | Render decisions.md | **Bash** `npx morph-spec template render docs/decisions ...` | — |
44
+ | Update state | **Bash** `npx morph-spec state mark-output $ARGUMENTS <type>` | — |
45
+
46
+ **Anti-patterns:**
47
+ - Do not generate contracts before reading the real schema — guessed field names corrupt the entire design
48
+ - Do not present a Blueprint without validating with the user first
49
+ - Do not ask questions as plain text — always use `AskUserQuestion`
50
+ - Do not ignore `config.architecture.style` — always detect it before CHECKPOINT 2
51
+
52
+ ---
53
+
54
+ ## PRE-FLIGHT
55
+
56
+ **STEP 0 (BEFORE any reads or writes) — Ensure phase is design:**
57
+
58
+ ```bash
59
+ npx morph-spec state get $ARGUMENTS
60
+ ```
61
+
62
+ Check the `"phase"` field in the output:
63
+
64
+ **If `"phase": "design"`** → phase is correct, proceed.
65
+
66
+ **If `"phase": "proposal"`** → execute in sequence:
67
+ 1. `npx morph-spec state mark-output $ARGUMENTS proposal`
68
+ 2. `npx morph-spec phase advance $ARGUMENTS` (→ setup)
69
+ 3. `npx morph-spec phase advance $ARGUMENTS` (→ design)
70
+
71
+ **If `"phase": "setup"`** → execute:
72
+ 1. `npx morph-spec phase advance $ARGUMENTS` (→ design)
73
+
74
+ **Any other value** → do not proceed — inconsistent state, report to user.
75
+
76
+ > **Rule:** Never write to `1-design/` while the phase is not `design`. The hook will block and the sequence will be corrupted.
77
+
78
+ ---
79
+
80
+ Read in parallel:
81
+ ```
82
+ Read: .morph/features/$ARGUMENTS/0-proposal/proposal.md
83
+ + Read: .morph/config/config.json ← detect architecture.style
84
+ + Read: .morph/context/README.md
85
+ ```
86
+
87
+ **Detect architecture style:**
88
+
89
+ | Value of `config.architecture.style` | Path |
90
+ |--------------------------------------|------|
91
+ | `"vertical-slice"` | → **VSA** (CHECKPOINT 2-VSA + VSA contracts) |
92
+ | any other value or absent | → **DDD** (CHECKPOINT 2-DDD + DDD contracts) |
93
+
94
+ If scope ≥ 20 tasks or refactor touches ≥ 5 domain files → **EnterPlanMode** before continuing.
95
+
96
+ ---
97
+
98
+ ## CHECKPOINT 1 — Real Schema (MANDATORY before any generation)
99
+
100
+ > **Rule:** Never assume field names. Every generated DTO must have a traceable origin in the schema.
101
+
102
+ ### 1.1 Read real schema
103
+
104
+ Execute in parallel according to the stack detected in `config.json`:
105
+
106
+ **Supabase (preferred if available):**
107
+ ```
108
+ Supabase MCP: list_tables() → get_table_schema(table) for each relevant table
109
+ + get_relationships() → RLS policies if applicable
110
+ ```
111
+
112
+ **EF Core (.NET):**
113
+ ```
114
+ Glob: **/Entities/**/*.cs → Read each entity file
115
+ Glob: **/*DbContext.cs → Read to see DbSet<> and relations
116
+ Grep: "DbSet<" → confirm mapped entities
117
+ ```
118
+
119
+ **TypeScript/Next.js:**
120
+ ```
121
+ Glob: src/**/types/**/*.ts, src/**/models/**/*.ts
122
+ Grep: "export interface|export type" → Read found files
123
+ ```
124
+
125
+ ### 1.2 Generate schema-analysis.md
126
+
127
+ Write `.morph/features/$ARGUMENTS/1-design/schema-analysis.md` with:
128
+
129
+ ```markdown
130
+ # Schema Analysis — {Feature}
131
+
132
+ ## Relevant Entities
133
+
134
+ ### {EntityName}
135
+ | Field | DB Type | C#/TS Type | Nullable | Notes |
136
+ |-------|---------|-----------|----------|-------|
137
+ | id | uuid | Guid | No | PK |
138
+ | ... | ... | ... | ... | ... |
139
+
140
+ ## Relationships
141
+ - {Entity A} 1—N {Entity B} via {FK field}
142
+
143
+ ## JSONB / Complex Fields
144
+ - {field}: internal structure {known keys}
145
+
146
+ ## Fields Not Referenced in Proposal
147
+ - {field}: present in schema but no reference in the proposal
148
+ ```
149
+
150
+ ### 1.3 Validate with user
151
+
152
+ Use `AskUserQuestion`:
153
+
154
+ ```json
155
+ {
156
+ "questions": [{
157
+ "header": "Schema OK?",
158
+ "question": "Found these entities and fields in the schema. Are they correct before generating contracts?",
159
+ "multiSelect": false,
160
+ "options": [
161
+ { "label": "Confirm and continue", "description": "Schema mapped correctly" },
162
+ { "label": "I have corrections", "description": "Use Other to describe what's wrong" }
163
+ ]
164
+ }]
165
+ }
166
+ ```
167
+
168
+ - **"Confirm"** → proceed to Checkpoint 2
169
+ - **"I have corrections" / Other** → apply corrections to schema-analysis.md and repeat 1.3
170
+
171
+ ---
172
+
173
+ ## CHECKPOINT 2 — Architecture Blueprint (MANDATORY before generating contracts)
174
+
175
+ > Use the path corresponding to the style detected in PRE-FLIGHT.
176
+
177
+ ---
178
+
179
+ ### CHECKPOINT 2-VSA — Vertical Slice Architecture
180
+
181
+ #### 2-VSA.1 Dispatch vsa-architect
182
+
183
+ ```bash
184
+ npx morph-spec dispatch-agents $ARGUMENTS design
185
+ ```
186
+
187
+ Use the `taskPrompt` from the `vsa-architect` agent in the result. Call:
188
+
189
+ ```
190
+ Agent(subagent_type=vsa-architect, prompt=<taskPrompt + contents of proposal.md + schema-analysis.md>)
191
+ ```
192
+
193
+ The agent produces a VSA Blueprint with:
194
+ - Entity fields (based on the schema validated in Checkpoint 1)
195
+ - Operations (GetAll, GetById, Create, Update, Delete + custom)
196
+ - Routes (`GET /api/{feature}s`, `POST /api/{feature}s`, etc.)
197
+ - Error types (`{Entity}Errors.NotFound`, `{Entity}Errors.AlreadyExists`, etc.)
198
+ - Validation rules per field
199
+
200
+ **Parallelize** with other active agents from the dispatch config.
201
+
202
+ #### 2-VSA.2 Validate Blueprint with user
203
+
204
+ Present the generated blueprint in a readable format and use `AskUserQuestion`:
205
+
206
+ ```json
207
+ {
208
+ "questions": [{
209
+ "header": "Blueprint OK?",
210
+ "question": "Planned these slices and operations for the feature. Confirm before generating spec and contracts?",
211
+ "multiSelect": false,
212
+ "options": [
213
+ { "label": "Confirm blueprint", "description": "Generate spec.md and contracts with this blueprint" },
214
+ { "label": "Need adjustments", "description": "Use Other to describe what to change" }
215
+ ]
216
+ }]
217
+ }
218
+ ```
219
+
220
+ - **"Confirm"** → proceed to VSA generation
221
+ - **"Need adjustments" / Other** → update blueprint and repeat 2-VSA.2
222
+
223
+ ---
224
+
225
+ ### CHECKPOINT 2-DDD — Domain-Driven Design
226
+
227
+ #### 2-DDD.1 Determine Complexity Level
228
+
229
+ Read the proposal and evaluate using the 5 detection questions in `framework/standards/architecture/ddd/complexity-levels.md`:
230
+
231
+ | Level | When to use |
232
+ |-------|-------------|
233
+ | **Level 1 (CRUD)** | Simple entities, no complex business rules, basic CRUD |
234
+ | **Level 2 (Business Logic)** | Domain invariants, business workflows, multiple related entities |
235
+ | **Level 3 (Bounded Context)** | Context isolation, integration events, distributed systems |
236
+
237
+ > If uncertain, assume Level 1 and use `AskUserQuestion` to confirm.
238
+
239
+ #### 2-DDD.2 Dispatch domain-architect
240
+
241
+ ```bash
242
+ npx morph-spec dispatch-agents $ARGUMENTS design
243
+ ```
244
+
245
+ Use the `taskPrompt` from the `domain-architect` agent in the result. Call:
246
+
247
+ ```
248
+ Agent(subagent_type=domain-architect, prompt=<taskPrompt + contents of proposal.md + schema-analysis.md + detected level>)
249
+ ```
250
+
251
+ The agent produces an Architecture Blueprint with:
252
+ - **Level 1:** Entities, repositories, services, DTOs
253
+ - **Level 2:** AggregateRoot, Value Objects, Domain Events, CQRS handlers
254
+ - **Level 3:** BC setup, Integration Events, Anti-corruption layer
255
+
256
+ **Parallelize** with other active agents from the dispatch config.
257
+
258
+ #### 2-DDD.3 Validate Blueprint with user
259
+
260
+ Present the generated blueprint in a readable format and use `AskUserQuestion`:
261
+
262
+ ```json
263
+ {
264
+ "questions": [{
265
+ "header": "Blueprint OK?",
266
+ "question": "Planned this domain architecture for the feature. Confirm before generating spec and contracts?",
267
+ "multiSelect": false,
268
+ "options": [
269
+ { "label": "Confirm blueprint", "description": "Generate spec.md and contracts with this blueprint" },
270
+ { "label": "Need adjustments", "description": "Use Other to describe what to change" }
271
+ ]
272
+ }]
273
+ }
274
+ ```
275
+
276
+ - **"Confirm"** → proceed to DDD generation
277
+ - **"Need adjustments" / Other** → update blueprint and repeat 2-DDD.3
278
+
279
+ ---
280
+
281
+ ## Artifact Generation
282
+
283
+ With schema validated (Checkpoint 1) and blueprint confirmed (Checkpoint 2):
284
+
285
+ ### Generate spec.md
286
+
287
+ > Detailed structure: `references/spec-authoring-guide.md`
288
+
289
+ Read the spec-authoring-guide first, then create `.morph/features/$ARGUMENTS/1-design/spec.md` with:
290
+ - Overview, Functional Requirements (FR001...) with measurable acceptance criteria
291
+ - Non-Functional Requirements, Data Model
292
+ - **VSA:** section `## Architecture Style: Vertical Slice` with slices and operations
293
+ - **DDD:** section `## Domain Complexity` with level (1/2/3) and justification
294
+ - Infrastructure Requirements (if applicable)
295
+
296
+ ### Generate contracts — VSA
297
+
298
+ **Mandatory source:** fields from `schema-analysis.md` + operations from the VSA Blueprint.
299
+
300
+ ```bash
301
+ npx morph-spec template render \
302
+ dotnet-contracts-vsa \
303
+ .morph/features/$ARGUMENTS/1-design/contracts.cs \
304
+ '{
305
+ "FEATURE_NAME": "$ARGUMENTS",
306
+ "NAMESPACE": "{ProjectNamespace}",
307
+ "ROUTE": "/api/{kebabCase FEATURE_NAME}s",
308
+ "DATE": "{{TODAY}}"
309
+ }'
310
+ ```
311
+
312
+ After rendering, fill in the `// placeholder:` sections with real fields from schema-analysis.md.
313
+
314
+ **Mandatory VSA patterns:**
315
+ - `sealed` on handlers, endpoints, validators, records
316
+ - `Guid.CreateVersion7()` for IDs
317
+ - `result.Match()` in endpoints
318
+ - `{Entity}Errors` static shared across all slices
319
+ - CancellationToken in all async methods
320
+
321
+ ### Generate contracts — DDD
322
+
323
+ **Mandatory source:** fields from `schema-analysis.md` + components from the DDD Blueprint.
324
+
325
+ ```bash
326
+ # Replace {N} with the detected level (1, 2, or 3):
327
+ npx morph-spec template render \
328
+ dotnet-contracts-level{N} \
329
+ .morph/features/$ARGUMENTS/1-design/contracts.cs \
330
+ '{
331
+ "FEATURE_NAME": "$ARGUMENTS",
332
+ "NAMESPACE": "{ProjectNamespace}",
333
+ "DATE": "{{TODAY}}"
334
+ }'
335
+ ```
336
+
337
+ After rendering, fill in the `// placeholder:` sections with real fields from schema-analysis.md.
338
+
339
+ **Mandatory DDD patterns:**
340
+ - Level 1: repository interfaces + service with mapped methods
341
+ - Level 2: AggregateRoot with invariants + immutable Value Objects + Domain Events
342
+ - Level 3: adds Integration Events + Bounded Context boundary
343
+
344
+ ### Stack adaptation for contracts
345
+
346
+ For TypeScript/Next.js projects, generate `contracts.ts` instead of `contracts.cs`. Use TypeScript interfaces with the same DDD/VSA patterns adapted to the language (e.g., `readonly` fields for Value Objects, union types for status enums, typed event interfaces for Domain Events).
347
+
348
+ ### Generate decisions.md
349
+
350
+ ```bash
351
+ npx morph-spec template render docs/decisions \
352
+ .morph/features/$ARGUMENTS/1-design/decisions.md \
353
+ '{"FEATURE_NAME": "$ARGUMENTS", "DATE": "{{TODAY}}", "decisions": []}'
354
+ ```
355
+
356
+ Mandatory ADRs: architecture choice (VSA vs DDD + justification), UI library (if UI/UX phase ran), external integrations, Azure resources with cost estimates.
357
+
358
+ ---
359
+
360
+ ## Quality Scoring System
361
+
362
+ After generating artifacts, evaluate the design with the **Quality Score (0–100)**:
363
+
364
+ | Dimension | Pts | Maximum score criteria |
365
+ |-----------|-----|----------------------|
366
+ | **Schema fidelity** | 25 | All fields in contracts have traceable origin in schema-analysis.md — zero guessed |
367
+ | **Functional coverage** | 20 | All FRs from the proposal are in spec with measurable acceptance criteria |
368
+ | **Blueprint complete** | 20 | **VSA:** all slices have handler, validator (except GetAll), endpoint and errors \| **DDD:** all entities/aggregates/services have components for the detected level |
369
+ | **External integrations** | 20 | APIs/services with payload, error format and retry policy documented |
370
+ | **Infra / costs** | 15 | Azure resources estimated with cost, or "N/A" explicitly documented |
371
+
372
+ **Thresholds:**
373
+
374
+ | Score | Action |
375
+ |-------|--------|
376
+ | ≥ 85 | Design satisfactory. Offer to close or optionally refine |
377
+ | 70–84 | Continue. Focus on the weakest dimensions |
378
+ | < 70 | Continue. Open technical questions block implementation |
379
+
380
+ ---
381
+
382
+ ## Quality Loop
383
+
384
+ **Repeat until: score ≥ 85 OR user approves.**
385
+
386
+ ### A. Calculate score
387
+
388
+ Score each dimension based on the generated artifacts. Identify the most impactful gaps.
389
+
390
+ ### B. Identify open questions
391
+
392
+ Typical questions by dimension:
393
+
394
+ | Weak dimension | Example questions |
395
+ |----------------|-------------------|
396
+ | Schema fidelity | "The `metadata` field (JSONB) — what is its structure? Which keys?" |
397
+ | Functional coverage | "FR003 says 'notify user' — by email, push, or both?" |
398
+ | Blueprint VSA | "Should the CreateOrder slice trigger an email job or is it synchronous?" |
399
+ | Blueprint DDD | "Should `Place()` on OrderAggregate emit `OrderPlacedEvent`?" |
400
+ | Integrations | "Does the payment API use webhook or polling to confirm?" |
401
+ | Infra/costs | "Does this feature need Azure storage? Which tier?" |
402
+
403
+ ### C. Ask via AskUserQuestion
404
+
405
+ Maximum 3 technical questions per call. In the last call of each round, always include:
406
+
407
+ ```json
408
+ {
409
+ "header": "Continue?",
410
+ "question": "Continue refining or finalize the design?",
411
+ "multiSelect": false,
412
+ "options": [
413
+ { "label": "Continue refining", "description": "More open questions identified" },
414
+ { "label": "Finalize design", "description": "Proceed to Clarify with current design" }
415
+ ]
416
+ }
417
+ ```
418
+
419
+ > If score ≥ 85, adjust: `"Continue (optional)"` with description `"Score {N}/100 — design is satisfactory"`
420
+
421
+ ### D. Incorporate answers
422
+
423
+ Update spec.md, contracts, and decisions.md with the answers received. Recalculate the score.
424
+
425
+ ### E. Exit condition
426
+
427
+ - User chose **"Finalize design"** → exit loop
428
+ - Score ≥ 85 AND no new questions → exit loop
429
+
430
+ ---
431
+
432
+ ## Post-Loop: Update State
433
+
434
+ ```bash
435
+ npx morph-spec state mark-output $ARGUMENTS schema-analysis
436
+ npx morph-spec state mark-output $ARGUMENTS spec
437
+ npx morph-spec state mark-output $ARGUMENTS contracts
438
+ npx morph-spec state mark-output $ARGUMENTS decisions
439
+ ```
440
+
441
+ If Azure costs were estimated:
442
+ ```bash
443
+ npx morph-spec state set $ARGUMENTS costs.estimated {X.XX}
444
+ ```
445
+
446
+ ## MANDATORY PAUSE
447
+
448
+ ```json
449
+ {
450
+ "questions": [{
451
+ "header": "Approval",
452
+ "question": "Design generated. Approve to continue to Clarify?",
453
+ "multiSelect": false,
454
+ "options": [
455
+ { "label": "Approve and continue", "description": "Advance to Clarify phase" },
456
+ { "label": "I have feedback", "description": "Describe what to change (Other)" }
457
+ ]
458
+ }]
459
+ }
460
+ ```
461
+
462
+ - **"Approve and continue"** →
463
+ ```bash
464
+ npx morph-spec approve $ARGUMENTS design
465
+ npx morph-spec phase advance $ARGUMENTS
466
+ ```
467
+ - **"I have feedback" / Other** → apply feedback and repeat PAUSE
468
+
469
+ ## Generated Outputs
470
+
471
+ - `.morph/features/$ARGUMENTS/1-design/schema-analysis.md` — Real schema mapped and validated
472
+ - `.morph/features/$ARGUMENTS/1-design/spec.md` — Complete technical specification
473
+ - `.morph/features/$ARGUMENTS/1-design/contracts.cs` (or `.ts` for TypeScript projects) — Contracts based on real schema (VSA or DDD)
474
+ - `.morph/features/$ARGUMENTS/1-design/decisions.md` — Documented ADRs
475
+
476
+ ## Advancement Criteria
477
+
478
+ - [x] Architecture style detected from `config.architecture.style`
479
+ - [x] Schema validated by user (Checkpoint 1)
480
+ - [x] Blueprint confirmed by user (Checkpoint 2-VSA or 2-DDD)
481
+ - [x] Quality score ≥ 85 OR user finalized
482
+ - [x] All field names in contracts traceable to schema-analysis.md
483
+ - [x] State updated
484
+ - [x] User approved at MANDATORY PAUSE
485
+
486
+ ---
487
+
488
+ <!-- morph:outputs:design -->
489
+ | Output | Path |
490
+ |--------|------|
491
+ | `schemaAnalysis` | `.morph/features/{feature}/1-design/schema-analysis.md` |
492
+ | `spec` | `.morph/features/{feature}/1-design/spec.md` |
493
+ | `contracts` | `.morph/features/{feature}/1-design/contracts.cs` |
494
+ | `contractsTs` | `.morph/features/{feature}/1-design/contracts.ts` |
495
+ | `contractsVsa` | `.morph/features/{feature}/1-design/contracts-vsa.cs` |
496
+ | `decisions` | `.morph/features/{feature}/1-design/decisions.md` |
497
+ <!-- /morph:outputs -->
498
+
499
+ Continue automatically to Phase 3 (Clarify) after approval.
@@ -0,0 +1,38 @@
1
+ {
2
+ "sessionId": "",
3
+ "feature": "",
4
+ "phase": "",
5
+ "hooks": [
6
+ {
7
+ "name": "set-terminal-title",
8
+ "event": "UserPromptSubmit",
9
+ "result": "failed",
10
+ "ts": "16:06:20"
11
+ },
12
+ {
13
+ "name": "set-terminal-title",
14
+ "event": "UserPromptSubmit",
15
+ "result": "failed",
16
+ "ts": "16:12:07"
17
+ },
18
+ {
19
+ "name": "set-terminal-title",
20
+ "event": "UserPromptSubmit",
21
+ "result": "failed",
22
+ "ts": "16:12:15"
23
+ },
24
+ {
25
+ "name": "set-terminal-title",
26
+ "event": "UserPromptSubmit",
27
+ "result": "failed",
28
+ "ts": "16:12:15"
29
+ },
30
+ {
31
+ "name": "set-terminal-title",
32
+ "event": "UserPromptSubmit",
33
+ "result": "failed",
34
+ "ts": "16:12:40"
35
+ }
36
+ ],
37
+ "skills": []
38
+ }