@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,151 +1,133 @@
1
- /**
2
- * Output Schema — Single Source of Truth
3
- *
4
- * ALL output type definitions live here. Edit ONLY this file to add, rename,
5
- * or relocate output types. Derived constants and generated files (phase-utils.js)
6
- * are automatically updated by: node scripts/generate-refs.js
7
- */
8
-
9
- import { join } from 'path';
10
-
11
- // ============================================================================
12
- // Schema Definition
13
- // ============================================================================
14
-
15
- /**
16
- * Complete schema for all 12 output types produced by morph-spec phases.
17
- *
18
- * Fields:
19
- * filename - The file's basename (e.g. 'spec.md')
20
- * phaseDir - Subdirectory within .morph/features/{feature}/ (e.g. '2-design')
21
- * phase - The morph-spec phase that produces this output
22
- * protected - Whether the file requires an approval gate before editing
23
- * approvalGate - (optional) Which gate protects this file
24
- */
25
- export const OUTPUT_SCHEMA = {
26
- proposal: { filename: 'proposal.md', phaseDir: '0-proposal', phase: 'proposal', protected: false },
27
- schemaAnalysis:{ filename: 'schema-analysis.md', phaseDir: '2-design', phase: 'design', protected: true, approvalGate: 'design' },
28
- spec: { filename: 'spec.md', phaseDir: '2-design', phase: 'design', protected: true, approvalGate: 'design' },
29
- contracts: { filename: 'contracts.cs', phaseDir: '2-design', phase: 'design', protected: true, approvalGate: 'design' },
30
- contractsTs: { filename: 'contracts.ts', phaseDir: '2-design', phase: 'design', protected: true, approvalGate: 'design' },
31
- contractsVsa: { filename: 'contracts-vsa.cs', phaseDir: '2-design', phase: 'design', protected: true, approvalGate: 'design' },
32
- plan: { filename: 'plan.md', phaseDir: '3-plan', phase: 'plan', protected: true, approvalGate: 'plan' },
33
- tasks: { filename: 'tasks.md', phaseDir: '4-tasks', phase: 'tasks', protected: true, approvalGate: 'tasks' },
34
- uiDesignSystem:{ filename: 'design-system.md', phaseDir: '1-ui', phase: 'uiux', protected: true, approvalGate: 'uiux' },
35
- uiMockups: { filename: 'mockups.md', phaseDir: '1-ui', phase: 'uiux', protected: true, approvalGate: 'uiux' },
36
- uiComponents: { filename: 'components.md', phaseDir: '1-ui', phase: 'uiux', protected: true, approvalGate: 'uiux' },
37
- uiFlows: { filename: 'flows.md', phaseDir: '1-ui', phase: 'uiux', protected: true, approvalGate: 'uiux' },
38
- decisions: { filename: 'decisions.md', phaseDir: '2-design', phase: 'design', protected: false },
39
- recap: { filename: 'recap.md', phaseDir: '5-implement', phase: 'implement', protected: false },
40
- };
41
-
42
- // ============================================================================
43
- // Builder Functions (Windows-safe via path.join)
44
- // ============================================================================
45
-
46
- /**
47
- * Get the morph-relative path for a specific output type of a feature.
48
- * Returns forward-slash paths suitable for state.json storage.
49
- *
50
- * @param {string} featureName - The feature name
51
- * @param {string} outputType - camelCase output type key from OUTPUT_SCHEMA
52
- * @returns {string} e.g. ".morph/features/my-feature/2-design/spec.md"
53
- */
54
- export function getOutputPath(featureName, outputType) {
55
- const entry = OUTPUT_SCHEMA[outputType];
56
- if (!entry) {
57
- throw new Error(`Unknown output type: "${outputType}". Valid types: ${Object.keys(OUTPUT_SCHEMA).join(', ')}`);
58
- }
59
- // Use path.join for OS-safe construction, then normalise to forward slashes
60
- return join('.morph', 'features', featureName, entry.phaseDir, entry.filename)
61
- .replace(/\\/g, '/');
62
- }
63
-
64
- /**
65
- * Get the absolute filesystem path for a specific output type.
66
- *
67
- * @param {string} projectRoot - Absolute project root (e.g. process.cwd())
68
- * @param {string} featureName - The feature name
69
- * @param {string} outputType - camelCase output type key from OUTPUT_SCHEMA
70
- * @returns {string} Absolute path using OS path separator
71
- */
72
- export function getAbsoluteOutputPath(projectRoot, featureName, outputType) {
73
- const entry = OUTPUT_SCHEMA[outputType];
74
- if (!entry) {
75
- throw new Error(`Unknown output type: "${outputType}". Valid types: ${Object.keys(OUTPUT_SCHEMA).join(', ')}`);
76
- }
77
- return join(projectRoot, '.morph', 'features', featureName, entry.phaseDir, entry.filename);
78
- }
79
-
80
- /**
81
- * Get the feature base directory (morph-relative, forward slashes).
82
- *
83
- * @param {string} featureName
84
- * @returns {string} e.g. ".morph/features/my-feature"
85
- */
86
- export function getFeatureDir(featureName) {
87
- return join('.morph', 'features', featureName).replace(/\\/g, '/');
88
- }
89
-
90
- /**
91
- * Get all output paths for a feature, ready for use in state.json `outputs` block.
92
- * Returns an object shaped like the state.json outputs for a single feature.
93
- *
94
- * @param {string} featureName
95
- * @returns {Object} e.g. { proposal: { created: false, path: '...' }, ... }
96
- */
97
- export function getAllOutputPaths(featureName) {
98
- const outputs = {};
99
- for (const [key] of Object.entries(OUTPUT_SCHEMA)) {
100
- outputs[key] = {
101
- created: false,
102
- path: getOutputPath(featureName, key),
103
- };
104
- }
105
- return outputs;
106
- }
107
-
108
- // ============================================================================
109
- // Derived Constants (for direct import without calling functions)
110
- // ============================================================================
111
-
112
- /**
113
- * Map filename → output type (camelCase)
114
- * e.g. { 'spec.md': 'spec', 'contracts.cs': 'contracts', ... }
115
- */
116
- export const FILENAME_TO_OUTPUT = Object.fromEntries(
117
- Object.entries(OUTPUT_SCHEMA).map(([key, entry]) => [entry.filename, key])
118
- );
119
-
120
- /**
121
- * Map output type (camelCase) → phase that produces it
122
- * e.g. { spec: 'design', tasks: 'tasks', ... }
123
- */
124
- export const OUTPUT_PHASE_MAP = Object.fromEntries(
125
- Object.entries(OUTPUT_SCHEMA).map(([key, entry]) => [key, entry.phase])
126
- );
127
-
128
- /**
129
- * Protected spec files and the approval gate that locks them.
130
- * Only includes files where protected === true.
131
- * e.g. { 'spec.md': 'design', 'tasks.md': 'tasks', ... }
132
- */
133
- export const PROTECTED_SPEC_FILES = Object.fromEntries(
134
- Object.entries(OUTPUT_SCHEMA)
135
- .filter(([, entry]) => entry.protected && entry.approvalGate)
136
- .map(([, entry]) => [entry.filename, entry.approvalGate])
137
- );
138
-
139
- // ============================================================================
140
- // Stack-aware Helpers
141
- // ============================================================================
142
-
143
- /**
144
- * Resolve the correct contracts output type key for a given stack.
145
- * @param {string|null} stack
146
- * @returns {'contracts'|'contractsTs'}
147
- */
148
- export function resolveContractsOutputType(stack) {
149
- const NEXTJS_STACKS = new Set(['nextjs', 'next', 'next.js']);
150
- return NEXTJS_STACKS.has(stack?.toLowerCase?.()) ? 'contractsTs' : 'contracts';
151
- }
1
+ /**
2
+ * Output Schema — Single Source of Truth (v5)
3
+ *
4
+ * ALL output type definitions live here. Edit ONLY this file to add, rename,
5
+ * or relocate output types.
6
+ */
7
+
8
+ import { join } from 'path';
9
+
10
+ // ============================================================================
11
+ // Schema Definition
12
+ // ============================================================================
13
+
14
+ /**
15
+ * Schema for output types produced by morph-spec NLH phases.
16
+ *
17
+ * Fields:
18
+ * filename - The file's basename (e.g. 'spec.md')
19
+ * phaseDir - Subdirectory within .morph/features/{feature}/
20
+ * phase - The morph-spec phase that produces this output
21
+ * protected - Whether the file requires an approval gate before editing
22
+ * approvalGate - (optional) Which gate protects this file
23
+ */
24
+ export const OUTPUT_SCHEMA = {
25
+ // 0-proposal/
26
+ proposal: { filename: 'proposal.md', phaseDir: '0-proposal', phase: 'proposal', protected: false },
27
+ stackScan: { filename: 'stack-scan.md', phaseDir: '0-proposal', phase: 'proposal', protected: false },
28
+ migrationPlan: { filename: 'migration-plan.md', phaseDir: '0-proposal', phase: 'proposal', protected: false },
29
+
30
+ // 1-ui/ (optional)
31
+ uiDesignSystem: { filename: 'design-system.md', phaseDir: '1-ui', phase: 'uiux', protected: true, approvalGate: 'uiux' },
32
+ uiMockups: { filename: 'mockups.md', phaseDir: '1-ui', phase: 'uiux', protected: true, approvalGate: 'uiux' },
33
+ uiComponents: { filename: 'components.md', phaseDir: '1-ui', phase: 'uiux', protected: true, approvalGate: 'uiux' },
34
+ uiFlows: { filename: 'flows.md', phaseDir: '1-ui', phase: 'uiux', protected: true, approvalGate: 'uiux' },
35
+
36
+ // 2-plan/
37
+ spec: { filename: 'spec.md', phaseDir: '2-plan', phase: 'plan', protected: true, approvalGate: 'plan' },
38
+ mandate: { filename: 'mandate.md', phaseDir: '2-plan', phase: 'plan', protected: true, approvalGate: 'plan' },
39
+ tasks: { filename: 'tasks.md', phaseDir: '2-plan', phase: 'plan', protected: true, approvalGate: 'plan' },
40
+ decisions: { filename: 'decisions.md', phaseDir: '2-plan', phase: 'plan', protected: false },
41
+
42
+ // 3-implement/
43
+ recap: { filename: 'recap.md', phaseDir: '3-implement', phase: 'implement', protected: false },
44
+
45
+ // 4-review/
46
+ reviewReport: { filename: 'review-report.md', phaseDir: '4-review', phase: 'review', protected: false },
47
+ };
48
+
49
+ // ============================================================================
50
+ // Builder Functions (Windows-safe via path.join)
51
+ // ============================================================================
52
+
53
+ /**
54
+ * Get the morph-relative path for a specific output type of a feature.
55
+ *
56
+ * @param {string} featureName
57
+ * @param {string} outputType - camelCase output type key from OUTPUT_SCHEMA
58
+ * @returns {string} e.g. ".morph/features/my-feature/2-plan/spec.md"
59
+ */
60
+ export function getOutputPath(featureName, outputType) {
61
+ const entry = OUTPUT_SCHEMA[outputType];
62
+ if (!entry) {
63
+ throw new Error(`Unknown output type: "${outputType}". Valid types: ${Object.keys(OUTPUT_SCHEMA).join(', ')}`);
64
+ }
65
+ return join('.morph', 'features', featureName, entry.phaseDir, entry.filename)
66
+ .replace(/\\/g, '/');
67
+ }
68
+
69
+ /**
70
+ * Get the absolute filesystem path for a specific output type.
71
+ */
72
+ export function getAbsoluteOutputPath(projectRoot, featureName, outputType) {
73
+ const entry = OUTPUT_SCHEMA[outputType];
74
+ if (!entry) {
75
+ throw new Error(`Unknown output type: "${outputType}". Valid types: ${Object.keys(OUTPUT_SCHEMA).join(', ')}`);
76
+ }
77
+ return join(projectRoot, '.morph', 'features', featureName, entry.phaseDir, entry.filename);
78
+ }
79
+
80
+ /**
81
+ * Get the feature base directory (morph-relative, forward slashes).
82
+ */
83
+ export function getFeatureDir(featureName) {
84
+ return join('.morph', 'features', featureName).replace(/\\/g, '/');
85
+ }
86
+
87
+ /**
88
+ * Get all output paths for a feature, ready for state.json `outputs` block.
89
+ */
90
+ export function getAllOutputPaths(featureName) {
91
+ const outputs = {};
92
+ for (const [key] of Object.entries(OUTPUT_SCHEMA)) {
93
+ outputs[key] = {
94
+ created: false,
95
+ path: getOutputPath(featureName, key),
96
+ };
97
+ }
98
+ return outputs;
99
+ }
100
+
101
+ // ============================================================================
102
+ // Derived Constants
103
+ // ============================================================================
104
+
105
+ export const FILENAME_TO_OUTPUT = Object.fromEntries(
106
+ Object.entries(OUTPUT_SCHEMA).map(([key, entry]) => [entry.filename, key])
107
+ );
108
+
109
+ export const OUTPUT_PHASE_MAP = Object.fromEntries(
110
+ Object.entries(OUTPUT_SCHEMA).map(([key, entry]) => [key, entry.phase])
111
+ );
112
+
113
+ /**
114
+ * Protected spec files and the approval gate that locks them.
115
+ */
116
+ export const PROTECTED_SPEC_FILES = Object.fromEntries(
117
+ Object.entries(OUTPUT_SCHEMA)
118
+ .filter(([, entry]) => entry.protected && entry.approvalGate)
119
+ .map(([, entry]) => [entry.filename, entry.approvalGate])
120
+ );
121
+
122
+ // ============================================================================
123
+ // Backwards-compat shim (will be removed in v5.1)
124
+ // ============================================================================
125
+
126
+ /**
127
+ * v4 had separate contracts.cs / contracts.ts / contracts-vsa.cs output types.
128
+ * In v5 contracts live inside spec.md (or in source files for VSA). This
129
+ * function keeps callers happy until they're updated.
130
+ */
131
+ export function resolveContractsOutputType() {
132
+ return 'spec';
133
+ }
@@ -10,13 +10,11 @@
10
10
  * Each phase can only transition to specific next phases
11
11
  */
12
12
  const VALID_TRANSITIONS = {
13
- 'proposal': ['uiux', 'design'], // Can skip UI/UX if no frontend
14
- 'uiux': ['design'],
15
- 'design': ['plan'],
16
- 'plan': ['tasks'],
17
- 'tasks': ['implement'],
18
- 'implement': ['sync', 'archived'], // Can skip sync
19
- 'sync': ['archived']
13
+ 'proposal': ['uiux', 'plan'],
14
+ 'uiux': ['plan'],
15
+ 'plan': ['implement'],
16
+ 'implement': ['review'],
17
+ 'review': []
20
18
  };
21
19
 
22
20
  /**
@@ -25,18 +23,15 @@ const VALID_TRANSITIONS = {
25
23
  const PHASE_NAMES = {
26
24
  'proposal': 'Proposal (Phase 0)',
27
25
  'uiux': 'UI/UX Design (Phase 1)',
28
- 'design': 'Design (Phase 2)',
29
- 'plan': 'Plan (Phase 3)',
30
- 'tasks': 'Tasks (Phase 4)',
31
- 'implement': 'Implement (Phase 5)',
32
- 'sync': 'Sync (Phase 6)',
33
- 'archived': 'Archived'
26
+ 'plan': 'Plan (Phase 2)',
27
+ 'implement': 'Implement (Phase 3)',
28
+ 'review': 'Quality Review (Phase 4)'
34
29
  };
35
30
 
36
31
  /**
37
32
  * Optional phases that can be skipped
38
33
  */
39
- const OPTIONAL_PHASES = ['uiux', 'sync'];
34
+ const OPTIONAL_PHASES = ['uiux'];
40
35
 
41
36
  /**
42
37
  * Validate if a phase transition is allowed
@@ -116,16 +111,7 @@ export function validateTransition(fromPhase, toPhase) {
116
111
  * @returns {string[]} Ordered list of phases
117
112
  */
118
113
  export function getPhaseSequence() {
119
- return [
120
- 'proposal',
121
- 'uiux', // optional
122
- 'design',
123
- 'plan',
124
- 'tasks',
125
- 'implement',
126
- 'sync', // optional
127
- 'archived'
128
- ];
114
+ return ['proposal', 'uiux', 'plan', 'implement', 'review'];
129
115
  }
130
116
 
131
117
  /**
@@ -27,14 +27,13 @@ export function getStatePath() {
27
27
  * Returns the phase corresponding to the highest-numbered folder present.
28
28
  *
29
29
  * @param {string} featurePath - Absolute path to .morph/features/{feature}/
30
- * @returns {string} Phase name: 'implement' | 'tasks' | 'plan' | 'uiux' | 'design' | 'proposal'
30
+ * @returns {string} Phase name: 'review' | 'implement' | 'plan' | 'uiux' | 'proposal'
31
31
  */
32
32
  export function derivePhase(featurePath) {
33
33
  const phaseMap = [
34
- ['5-implement', 'implement'],
35
- ['4-tasks', 'tasks'],
36
- ['3-plan', 'plan'],
37
- ['2-design', 'design'],
34
+ ['4-review', 'review'],
35
+ ['3-implement', 'implement'],
36
+ ['2-plan', 'plan'],
38
37
  ['1-ui', 'uiux'],
39
38
  ['0-proposal', 'proposal'],
40
39
  ];
@@ -79,7 +78,7 @@ export function loadState(throwOnError = true) {
79
78
 
80
79
  if (!existsSync(statePath)) {
81
80
  if (throwOnError) {
82
- throw new Error(`State file not found: ${statePath}\nRun 'morph-spec state init' first.`);
81
+ throw new Error(`State file not found: ${statePath}\nRun 'morph-spec init' to initialize MORPH in this project.`);
83
82
  }
84
83
  return null;
85
84
  }
@@ -297,6 +296,7 @@ async function ensureFeature(featureName, options = {}) {
297
296
  workflowDetection.matchedKeywords = detection.matchedKeywords;
298
297
  workflowDetection.estimatedComplexity = detection.estimatedComplexity;
299
298
  workflowDetection.reasoning = detection.reasoning;
299
+ workflowDetection.warnings = detection.warnings || [];
300
300
  } catch (err) {
301
301
  // If detection fails, fall back to auto
302
302
  console.warn('Workflow detection failed:', err.message);
@@ -313,8 +313,8 @@ async function ensureFeature(featureName, options = {}) {
313
313
  approvalGates: {
314
314
  proposal: { approved: false, timestamp: null, approvedBy: null },
315
315
  uiux: { approved: false, timestamp: null, approvedBy: null },
316
- design: { approved: false, timestamp: null, approvedBy: null },
317
- tasks: { approved: false, timestamp: null, approvedBy: null }
316
+ plan: { approved: false, timestamp: null, approvedBy: null },
317
+ review: { approved: false, timestamp: null, approvedBy: null }
318
318
  },
319
319
  tasks: {
320
320
  total: 0,
@@ -491,7 +491,7 @@ export function logDispatch(featureName, entry) {
491
491
  /**
492
492
  * Normalize output type from kebab-case to camelCase (BUG-002 fix - Enhanced)
493
493
  * Supports both kebab-case and camelCase input formats for all output types
494
- * @param {string} type - Output type (e.g., 'ui-design-system', 'schema-analysis', or 'uiDesignSystem')
494
+ * @param {string} type - Output type (e.g., 'ui-design-system', 'stack-scan', or 'uiDesignSystem')
495
495
  * @returns {string} Normalized type in camelCase
496
496
  */
497
497
  function normalizeOutputType(type) {
@@ -502,7 +502,7 @@ function normalizeOutputType(type) {
502
502
 
503
503
  // Convert kebab-case to camelCase automatically
504
504
  // Example: 'ui-design-system' → 'uiDesignSystem'
505
- // Example: 'schema-analysis' → 'schemaAnalysis'
505
+ // Example: 'stack-scan' → 'stackScan'
506
506
  const camelCase = type.replace(/-([a-z])/g, (_, letter) => letter.toUpperCase());
507
507
 
508
508
  return camelCase;
@@ -582,7 +582,7 @@ function findClosestMatch(inputType, validTypes) {
582
582
  /**
583
583
  * Mark output as created
584
584
  * @param {string} featureName - Feature name
585
- * @param {string} outputType - Output type (proposal, spec, contracts, etc.)
585
+ * @param {string} outputType - Output type (proposal, spec, mandate, etc.)
586
586
  */
587
587
  export async function markOutput(featureName, outputType) {
588
588
  await ensureFeature(featureName);
@@ -618,7 +618,7 @@ export async function markOutput(featureName, outputType) {
618
618
 
619
619
  errorMsg += `\n\nValid types:\n`;
620
620
  errorMsg += ` ${validCamelCaseTypes.join(', ')}\n`;
621
- errorMsg += `\nNote: UI types also accept kebab-case (e.g., 'ui-design-system', 'schema-analysis')`;
621
+ errorMsg += `\nNote: kebab-case is also accepted (e.g., 'ui-design-system', 'stack-scan')`;
622
622
 
623
623
  throw new Error(errorMsg);
624
624
  }
@@ -769,7 +769,7 @@ export function getSummary() {
769
769
  /**
770
770
  * Set approval gate status
771
771
  * @param {string} featureName - Feature name
772
- * @param {string} gate - Gate name (proposal, uiux, design, tasks)
772
+ * @param {string} gate - Gate name (proposal, uiux, plan, review)
773
773
  * @param {boolean} approved - Approval status
774
774
  * @param {Object} metadata - Additional metadata (approvedBy, reason, etc.)
775
775
  */
@@ -781,8 +781,8 @@ export async function setApprovalGate(featureName, gate, approved, metadata = {}
781
781
  feature.approvalGates = {
782
782
  proposal: { approved: false, timestamp: null, approvedBy: null },
783
783
  uiux: { approved: false, timestamp: null, approvedBy: null },
784
- design: { approved: false, timestamp: null, approvedBy: null },
785
- tasks: { approved: false, timestamp: null, approvedBy: null }
784
+ plan: { approved: false, timestamp: null, approvedBy: null },
785
+ review: { approved: false, timestamp: null, approvedBy: null }
786
786
  };
787
787
  }
788
788
 
@@ -831,8 +831,8 @@ export function isPendingApproval(featureName) {
831
831
 
832
832
  // Check if current phase has an approval gate
833
833
  const phaseGateMap = {
834
- 'design': 'design',
835
- 'tasks': 'tasks',
834
+ 'plan': 'plan',
835
+ 'review': 'review',
836
836
  'uiux': 'uiux'
837
837
  };
838
838