@polymorphism-tech/morph-spec 3.0.0 → 3.1.0

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 (240) hide show
  1. package/CLAUDE.md +68 -400
  2. package/README.md +198 -76
  3. package/bin/detect-agents.js +227 -225
  4. package/bin/morph-spec.js +10 -0
  5. package/bin/render-template.js +303 -302
  6. package/bin/semantic-detect-agents.js +247 -246
  7. package/bin/{task-manager.js → task-manager.cjs} +12 -1
  8. package/bin/validate-agents-skills.js +257 -251
  9. package/bin/validate-agents.js +70 -69
  10. package/bin/validate-phase.js +263 -263
  11. package/docs/getting-started.md +3 -3
  12. package/package.json +3 -4
  13. package/scripts/reorganize-skills.cjs +175 -0
  14. package/scripts/validate-agents-structure.cjs +52 -0
  15. package/scripts/validate-skills.cjs +180 -0
  16. package/src/commands/create-story.js +354 -351
  17. package/src/commands/detect-agents.js +13 -2
  18. package/src/commands/detect.js +104 -104
  19. package/src/commands/state.js +334 -333
  20. package/src/commands/sync.js +167 -167
  21. package/src/commands/task.js +1 -1
  22. package/src/commands/update.js +13 -1
  23. package/src/lib/context-generator.js +7 -4
  24. package/{detectors → src/lib/detectors}/config-detector.js +223 -223
  25. package/{detectors → src/lib/detectors}/conversation-analyzer.js +163 -163
  26. package/{detectors → src/lib/detectors}/index.js +84 -84
  27. package/{detectors → src/lib/detectors}/standards-generator.js +275 -275
  28. package/src/lib/hook-executor.js +2 -1
  29. package/src/lib/stack-resolver.js +148 -0
  30. package/src/lib/standards-context-injector.js +4 -3
  31. package/src/lib/state-manager.js +21 -4
  32. package/src/lib/team-orchestrator.js +2 -1
  33. package/src/lib/troubleshoot-grep.js +13 -3
  34. package/src/lib/validation-runner.js +2 -1
  35. package/src/utils/file-copier.js +3 -1
  36. package/{content → stacks/blazor-azure}/.azure/README.md +293 -293
  37. package/{content → stacks/blazor-azure}/.azure/docs/azure-devops-setup.md +454 -454
  38. package/{content → stacks/blazor-azure}/.azure/docs/branch-strategy.md +398 -398
  39. package/{content → stacks/blazor-azure}/.azure/docs/local-development.md +515 -515
  40. package/{content → stacks/blazor-azure}/.azure/pipelines/pipeline-variables.yml +34 -34
  41. package/{content → stacks/blazor-azure}/.azure/pipelines/prod-pipeline.yml +319 -319
  42. package/{content → stacks/blazor-azure}/.azure/pipelines/staging-pipeline.yml +234 -234
  43. package/{content → stacks/blazor-azure}/.azure/pipelines/templates/build-dotnet.yml +75 -75
  44. package/{content → stacks/blazor-azure}/.azure/pipelines/templates/deploy-app-service.yml +94 -94
  45. package/{content → stacks/blazor-azure}/.azure/pipelines/templates/deploy-container-app.yml +120 -120
  46. package/{content → stacks/blazor-azure}/.azure/pipelines/templates/infra-deploy.yml +90 -90
  47. package/{content → stacks/blazor-azure}/.claude/commands/morph-archive.md +79 -79
  48. package/{content → stacks/blazor-azure}/.claude/commands/morph-deploy.md +529 -529
  49. package/{content → stacks/blazor-azure}/.claude/commands/morph-infra.md +209 -209
  50. package/{content → stacks/blazor-azure}/.claude/commands/morph-troubleshoot.md +1 -1
  51. package/{content → stacks/blazor-azure}/.claude/settings.local.json +15 -15
  52. package/{content → stacks/blazor-azure}/.claude/skills/level-1-workflows/phase-setup.md +1 -1
  53. package/{content/.claude/skills/specialists → stacks/blazor-azure/.claude/skills/level-2-domains/architecture}/prompt-engineer.md +189 -189
  54. package/{content/.claude/skills/specialists → stacks/blazor-azure/.claude/skills/level-2-domains/architecture}/seo-growth-hacker.md +320 -320
  55. package/{content/.claude/skills/infra → stacks/blazor-azure/.claude/skills/level-2-domains/infrastructure}/azure-deploy-specialist.md +699 -699
  56. package/{content → stacks/blazor-azure}/.morph/.morphversion +5 -5
  57. package/{content → stacks/blazor-azure}/.morph/archive/.gitkeep +25 -25
  58. package/{content → stacks/blazor-azure}/.morph/config/agents.json +7 -5
  59. package/{content → stacks/blazor-azure}/.morph/docs/STORY-DRIVEN-DEVELOPMENT.md +392 -392
  60. package/{content → stacks/blazor-azure}/.morph/docs/workflows/enforcement-pipeline.md +3 -3
  61. package/{content → stacks/blazor-azure}/.morph/examples/api-nextjs/README.md +241 -241
  62. package/{content → stacks/blazor-azure}/.morph/examples/api-nextjs/contracts.ts +307 -307
  63. package/{content → stacks/blazor-azure}/.morph/examples/api-nextjs/spec.md +399 -399
  64. package/{content → stacks/blazor-azure}/.morph/examples/api-nextjs/tasks.md +168 -168
  65. package/{content → stacks/blazor-azure}/.morph/examples/micro-saas/README.md +125 -125
  66. package/{content → stacks/blazor-azure}/.morph/examples/micro-saas/contracts.cs +358 -358
  67. package/{content → stacks/blazor-azure}/.morph/examples/micro-saas/decisions.md +246 -246
  68. package/{content → stacks/blazor-azure}/.morph/examples/micro-saas/spec.md +236 -236
  69. package/{content → stacks/blazor-azure}/.morph/examples/micro-saas/tasks.md +150 -150
  70. package/{content → stacks/blazor-azure}/.morph/examples/multi-agent/README.md +309 -309
  71. package/{content → stacks/blazor-azure}/.morph/examples/multi-agent/contracts.cs +433 -433
  72. package/{content → stacks/blazor-azure}/.morph/examples/multi-agent/spec.md +479 -479
  73. package/{content → stacks/blazor-azure}/.morph/examples/multi-agent/tasks.md +185 -185
  74. package/{content → stacks/blazor-azure}/.morph/examples/state-v3.json +188 -188
  75. package/{content → stacks/blazor-azure}/.morph/features/.gitkeep +25 -25
  76. package/{content → stacks/blazor-azure}/.morph/hooks/README.md +12 -12
  77. package/{content → stacks/blazor-azure}/.morph/hooks/pre-commit-all.sh +48 -48
  78. package/{content → stacks/blazor-azure}/.morph/hooks/pre-commit-specs.sh +49 -49
  79. package/{content → stacks/blazor-azure}/.morph/hooks/pre-commit-tests.sh +60 -60
  80. package/{content → stacks/blazor-azure}/.morph/project.md +160 -160
  81. package/{content → stacks/blazor-azure}/.morph/schemas/agent.schema.json +296 -296
  82. package/{content → stacks/blazor-azure}/.morph/specs/.gitkeep +20 -20
  83. package/{content → stacks/blazor-azure}/.morph/standards/agent-teams-workflow.md +2 -2
  84. package/{content → stacks/blazor-azure}/.morph/standards/coding.md +377 -377
  85. package/{content → stacks/blazor-azure}/.morph/standards/fluent-ui-setup.md +590 -590
  86. package/{content → stacks/blazor-azure}/.morph/standards/migration-guide.md +514 -514
  87. package/{content → stacks/blazor-azure}/.morph/standards/passkeys-auth.md +423 -423
  88. package/{content → stacks/blazor-azure}/.morph/standards/vector-search-rag.md +536 -536
  89. package/{content → stacks/blazor-azure}/.morph/state.json +17 -17
  90. package/{content → stacks/blazor-azure}/.morph/templates/FluentDesignTheme.cs +149 -149
  91. package/{content → stacks/blazor-azure}/.morph/templates/MudTheme.cs +281 -281
  92. package/{content → stacks/blazor-azure}/.morph/templates/component.razor +239 -239
  93. package/{content → stacks/blazor-azure}/.morph/templates/contracts.cs +217 -217
  94. package/{content → stacks/blazor-azure}/.morph/templates/design-system.css +226 -226
  95. package/{content → stacks/blazor-azure}/.morph/templates/infra/.dockerignore.example +89 -89
  96. package/{content → stacks/blazor-azure}/.morph/templates/infra/Dockerfile.example +82 -82
  97. package/{content → stacks/blazor-azure}/.morph/templates/infra/README.md +286 -286
  98. package/{content → stacks/blazor-azure}/.morph/templates/infra/app-insights.bicep +63 -63
  99. package/{content → stacks/blazor-azure}/.morph/templates/infra/app-service.bicep +164 -164
  100. package/{content → stacks/blazor-azure}/.morph/templates/infra/azure-pipelines-deploy.yml +480 -480
  101. package/{content → stacks/blazor-azure}/.morph/templates/infra/container-app-env.bicep +49 -49
  102. package/{content → stacks/blazor-azure}/.morph/templates/infra/container-app.bicep +156 -156
  103. package/{content → stacks/blazor-azure}/.morph/templates/infra/deploy.ps1 +229 -229
  104. package/{content → stacks/blazor-azure}/.morph/templates/infra/deploy.sh +208 -208
  105. package/{content → stacks/blazor-azure}/.morph/templates/infra/key-vault.bicep +91 -91
  106. package/{content → stacks/blazor-azure}/.morph/templates/infra/main.bicep +189 -189
  107. package/{content → stacks/blazor-azure}/.morph/templates/infra/parameters.dev.json +29 -29
  108. package/{content → stacks/blazor-azure}/.morph/templates/infra/parameters.prod.json +29 -29
  109. package/{content → stacks/blazor-azure}/.morph/templates/infra/parameters.staging.json +29 -29
  110. package/{content → stacks/blazor-azure}/.morph/templates/infra/sql-database.bicep +103 -103
  111. package/{content → stacks/blazor-azure}/.morph/templates/infra/storage.bicep +106 -106
  112. package/{content → stacks/blazor-azure}/.morph/templates/integrations/asaas-client.cs +387 -387
  113. package/{content → stacks/blazor-azure}/.morph/templates/integrations/asaas-webhook.cs +351 -351
  114. package/{content → stacks/blazor-azure}/.morph/templates/integrations/azure-identity-config.cs +288 -288
  115. package/{content → stacks/blazor-azure}/.morph/templates/integrations/clerk-config.cs +258 -258
  116. package/{content → stacks/blazor-azure}/.morph/templates/job.cs +171 -171
  117. package/{content → stacks/blazor-azure}/.morph/templates/migration.cs +83 -83
  118. package/{content → stacks/blazor-azure}/.morph/templates/repository.cs +141 -141
  119. package/{content → stacks/blazor-azure}/.morph/templates/saas/subscription.cs +347 -347
  120. package/{content → stacks/blazor-azure}/.morph/templates/saas/tenant.cs +338 -338
  121. package/{content → stacks/blazor-azure}/.morph/templates/service.cs +139 -139
  122. package/{content → stacks/blazor-azure}/.morph/templates/sprint-status.yaml +68 -68
  123. package/{content → stacks/blazor-azure}/.morph/templates/story.md +143 -143
  124. package/{content → stacks/blazor-azure}/.morph/templates/test.cs +239 -239
  125. package/{content → stacks/blazor-azure}/.morph/templates/ui-design-system.md +286 -286
  126. package/{content → stacks/blazor-azure}/.morph/templates/ui-flows.md +336 -336
  127. package/{content → stacks/blazor-azure}/.morph/templates/ui-mockups.md +133 -133
  128. package/{content → stacks/blazor-azure}/.morph/test-infra/example.bicep +59 -59
  129. package/{content → stacks/blazor-azure}/README.md +79 -79
  130. package/stacks/nextjs-supabase/.claude/skills/level-2-domains/backend/dotnet-supabase.md +244 -0
  131. package/stacks/nextjs-supabase/.claude/skills/level-2-domains/frontend/nextjs-supabase.md +335 -0
  132. package/stacks/nextjs-supabase/.claude/skills/level-2-domains/infrastructure/easypanel-deployer.md +189 -0
  133. package/stacks/nextjs-supabase/.claude/skills/level-2-domains/integrations/supabase-expert.md +170 -0
  134. package/stacks/nextjs-supabase/.morph/config/agents.json +345 -0
  135. package/stacks/nextjs-supabase/.morph/config/config.template.json +92 -0
  136. package/stacks/nextjs-supabase/.morph/docs/easypanel-setup.md +169 -0
  137. package/stacks/nextjs-supabase/.morph/docs/supabase-mcp-setup.md +247 -0
  138. package/stacks/nextjs-supabase/.morph/examples/crud-nextjs-supabase/README.md +697 -0
  139. package/stacks/nextjs-supabase/.morph/examples/crud-nextjs-supabase/spec.md +85 -0
  140. package/stacks/nextjs-supabase/.morph/examples/crud-nextjs-supabase/tasks.md +86 -0
  141. package/stacks/nextjs-supabase/.morph/examples/saas-nextjs-supabase/README.md +498 -0
  142. package/stacks/nextjs-supabase/.morph/examples/saas-nextjs-supabase/decisions.md +121 -0
  143. package/stacks/nextjs-supabase/.morph/examples/saas-nextjs-supabase/spec.md +138 -0
  144. package/stacks/nextjs-supabase/.morph/examples/saas-nextjs-supabase/tasks.md +162 -0
  145. package/stacks/nextjs-supabase/.morph/project.md +168 -0
  146. package/stacks/nextjs-supabase/.morph/standards/easypanel-deploy.md +191 -0
  147. package/stacks/nextjs-supabase/.morph/standards/nextjs-patterns.md +193 -0
  148. package/stacks/nextjs-supabase/.morph/standards/supabase-auth.md +171 -0
  149. package/stacks/nextjs-supabase/.morph/standards/supabase-pgvector.md +164 -0
  150. package/stacks/nextjs-supabase/.morph/standards/supabase-rls.md +179 -0
  151. package/stacks/nextjs-supabase/.morph/standards/supabase-storage.md +148 -0
  152. package/stacks/nextjs-supabase/.morph/templates/contracts.cs +173 -0
  153. package/stacks/nextjs-supabase/.morph/templates/contracts.ts +168 -0
  154. package/stacks/nextjs-supabase/.morph/templates/decisions.md +115 -0
  155. package/stacks/nextjs-supabase/.morph/templates/dockerfile-api.dockerfile +38 -0
  156. package/stacks/nextjs-supabase/.morph/templates/dockerfile-web.dockerfile +48 -0
  157. package/stacks/nextjs-supabase/.morph/templates/proposal.md +145 -0
  158. package/stacks/nextjs-supabase/.morph/templates/recap.md +134 -0
  159. package/stacks/nextjs-supabase/.morph/templates/rls-policy.sql +57 -0
  160. package/stacks/nextjs-supabase/.morph/templates/spec.md +231 -0
  161. package/stacks/nextjs-supabase/.morph/templates/supabase-migration.sql +100 -0
  162. package/stacks/nextjs-supabase/.morph/templates/tasks.md +257 -0
  163. package/stacks/nextjs-supabase/CLAUDE.md +149 -0
  164. package/stacks/nextjs-supabase/README.md +112 -0
  165. /package/{detectors → src/lib/detectors}/structure-detector.js +0 -0
  166. /package/{content → stacks/blazor-azure}/.claude/commands/morph-apply.md +0 -0
  167. /package/{content → stacks/blazor-azure}/.claude/commands/morph-preflight.md +0 -0
  168. /package/{content → stacks/blazor-azure}/.claude/commands/morph-proposal.md +0 -0
  169. /package/{content → stacks/blazor-azure}/.claude/commands/morph-status.md +0 -0
  170. /package/{content → stacks/blazor-azure}/.claude/skills/level-0-meta/README.md +0 -0
  171. /package/{content → stacks/blazor-azure}/.claude/skills/level-0-meta/code-review.md +0 -0
  172. /package/{content → stacks/blazor-azure}/.claude/skills/level-0-meta/morph-checklist.md +0 -0
  173. /package/{content → stacks/blazor-azure}/.claude/skills/level-0-meta/simulation-checklist.md +0 -0
  174. /package/{content → stacks/blazor-azure}/.claude/skills/level-1-workflows/README.md +0 -0
  175. /package/{content → stacks/blazor-azure}/.claude/skills/level-1-workflows/morph-replicate.md +0 -0
  176. /package/{content → stacks/blazor-azure}/.claude/skills/level-1-workflows/phase-clarify.md +0 -0
  177. /package/{content → stacks/blazor-azure}/.claude/skills/level-1-workflows/phase-design.md +0 -0
  178. /package/{content → stacks/blazor-azure}/.claude/skills/level-1-workflows/phase-tasks.md +0 -0
  179. /package/{content → stacks/blazor-azure}/.claude/skills/level-1-workflows/phase-uiux.md +0 -0
  180. /package/{content → stacks/blazor-azure}/.claude/skills/level-2-domains/README.md +0 -0
  181. /package/{content → stacks/blazor-azure}/.claude/skills/level-2-domains/ai-agents/ai-system-architect.md +0 -0
  182. /package/{content → stacks/blazor-azure}/.claude/skills/level-2-domains/architecture/po-pm-advisor.md +0 -0
  183. /package/{content → stacks/blazor-azure}/.claude/skills/level-2-domains/architecture/standards-architect.md +0 -0
  184. /package/{content → stacks/blazor-azure}/.claude/skills/level-2-domains/backend/dotnet-senior.md +0 -0
  185. /package/{content → stacks/blazor-azure}/.claude/skills/level-2-domains/backend/ef-modeler.md +0 -0
  186. /package/{content → stacks/blazor-azure}/.claude/skills/level-2-domains/backend/hangfire-orchestrator.md +0 -0
  187. /package/{content → stacks/blazor-azure}/.claude/skills/level-2-domains/backend/ms-agent-expert.md +0 -0
  188. /package/{content → stacks/blazor-azure}/.claude/skills/level-2-domains/frontend/blazor-builder.md +0 -0
  189. /package/{content → stacks/blazor-azure}/.claude/skills/level-2-domains/frontend/nextjs-expert.md +0 -0
  190. /package/{content → stacks/blazor-azure}/.claude/skills/level-2-domains/frontend/ui-ux-designer.md +0 -0
  191. /package/{content → stacks/blazor-azure}/.claude/skills/level-2-domains/infrastructure/azure-architect.md +0 -0
  192. /package/{content → stacks/blazor-azure}/.claude/skills/level-2-domains/infrastructure/bicep-architect.md +0 -0
  193. /package/{content → stacks/blazor-azure}/.claude/skills/level-2-domains/infrastructure/container-specialist.md +0 -0
  194. /package/{content → stacks/blazor-azure}/.claude/skills/level-2-domains/infrastructure/devops-engineer.md +0 -0
  195. /package/{content → stacks/blazor-azure}/.claude/skills/level-2-domains/integrations/asaas-financial.md +0 -0
  196. /package/{content → stacks/blazor-azure}/.claude/skills/level-2-domains/integrations/azure-identity.md +0 -0
  197. /package/{content → stacks/blazor-azure}/.claude/skills/level-2-domains/integrations/clerk-auth.md +0 -0
  198. /package/{content → stacks/blazor-azure}/.claude/skills/level-2-domains/integrations/resend-email.md +0 -0
  199. /package/{content → stacks/blazor-azure}/.claude/skills/level-2-domains/quality/code-analyzer.md +0 -0
  200. /package/{content → stacks/blazor-azure}/.claude/skills/level-2-domains/quality/testing-specialist.md +0 -0
  201. /package/{content → stacks/blazor-azure}/.claude/skills/level-3-technologies/README.md +0 -0
  202. /package/{content → stacks/blazor-azure}/.claude/skills/level-4-patterns/README.md +0 -0
  203. /package/{content → stacks/blazor-azure}/.morph/config/config.template.json +0 -0
  204. /package/{content → stacks/blazor-azure}/.morph/docs/workflows/design-impl.md +0 -0
  205. /package/{content → stacks/blazor-azure}/.morph/docs/workflows/fast-track.md +0 -0
  206. /package/{content → stacks/blazor-azure}/.morph/docs/workflows/full-morph.md +0 -0
  207. /package/{content → stacks/blazor-azure}/.morph/docs/workflows/standard.md +0 -0
  208. /package/{content → stacks/blazor-azure}/.morph/docs/workflows/ui-refresh.md +0 -0
  209. /package/{content → stacks/blazor-azure}/.morph/examples/scheduled-reports/decisions.md +0 -0
  210. /package/{content → stacks/blazor-azure}/.morph/examples/scheduled-reports/proposal.md +0 -0
  211. /package/{content → stacks/blazor-azure}/.morph/examples/scheduled-reports/spec.md +0 -0
  212. /package/{content → stacks/blazor-azure}/.morph/hooks/pre-commit-agents.sh +0 -0
  213. /package/{content → stacks/blazor-azure}/.morph/hooks/task-completed.js +0 -0
  214. /package/{content → stacks/blazor-azure}/.morph/hooks/teammate-idle.js +0 -0
  215. /package/{content → stacks/blazor-azure}/.morph/schemas/tasks.schema.json +0 -0
  216. /package/{content → stacks/blazor-azure}/.morph/standards/agent-framework-blazor-ui.md +0 -0
  217. /package/{content → stacks/blazor-azure}/.morph/standards/agent-framework-production.md +0 -0
  218. /package/{content → stacks/blazor-azure}/.morph/standards/agent-framework-setup.md +0 -0
  219. /package/{content → stacks/blazor-azure}/.morph/standards/agent-framework-workflows.md +0 -0
  220. /package/{content → stacks/blazor-azure}/.morph/standards/architecture.md +0 -0
  221. /package/{content → stacks/blazor-azure}/.morph/standards/azure.md +0 -0
  222. /package/{content → stacks/blazor-azure}/.morph/standards/dotnet10-migration.md +0 -0
  223. /package/{content → stacks/blazor-azure}/.morph/templates/CONTEXT-FEATURE.md +0 -0
  224. /package/{content → stacks/blazor-azure}/.morph/templates/CONTEXT.md +0 -0
  225. /package/{content → stacks/blazor-azure}/.morph/templates/agent.cs +0 -0
  226. /package/{content → stacks/blazor-azure}/.morph/templates/clarify-questions.md +0 -0
  227. /package/{content → stacks/blazor-azure}/.morph/templates/contracts/Commands.cs +0 -0
  228. /package/{content → stacks/blazor-azure}/.morph/templates/contracts/Entities.cs +0 -0
  229. /package/{content → stacks/blazor-azure}/.morph/templates/contracts/Queries.cs +0 -0
  230. /package/{content → stacks/blazor-azure}/.morph/templates/contracts/README.md +0 -0
  231. /package/{content → stacks/blazor-azure}/.morph/templates/decisions.md +0 -0
  232. /package/{content → stacks/blazor-azure}/.morph/templates/infra/deploy-checklist.md +0 -0
  233. /package/{content → stacks/blazor-azure}/.morph/templates/proposal.md +0 -0
  234. /package/{content → stacks/blazor-azure}/.morph/templates/recap.md +0 -0
  235. /package/{content → stacks/blazor-azure}/.morph/templates/simulation.md +0 -0
  236. /package/{content → stacks/blazor-azure}/.morph/templates/spec.md +0 -0
  237. /package/{content → stacks/blazor-azure}/.morph/templates/state.template.json +0 -0
  238. /package/{content → stacks/blazor-azure}/.morph/templates/tasks.md +0 -0
  239. /package/{content → stacks/blazor-azure}/.morph/templates/ui-components.md +0 -0
  240. /package/{content → stacks/blazor-azure}/CLAUDE.md +0 -0
@@ -1,351 +1,354 @@
1
- /**
2
- * MORPH-SPEC Story Creator
3
- * Creates self-contained story files with auto-injected Dev Notes
4
- * Inspired by BMAD Method story-driven development
5
- */
6
-
7
- import fs from 'fs';
8
- import path from 'path';
9
- import yaml from 'yaml';
10
- import ora from 'ora';
11
- import chalk from 'chalk';
12
- import { logger } from '../utils/logger.js';
13
- import { ensureDir, writeFile } from '../utils/file-copier.js';
14
-
15
- // ============================================================================
16
- // Helper Functions
17
- // ============================================================================
18
-
19
- function readTemplate(templateName) {
20
- const templatePath = path.join(process.cwd(), 'node_modules/@polymorphism-tech/morph-spec/content/.morph/templates', templateName);
21
-
22
- // Fallback to local if in development
23
- if (!fs.existsSync(templatePath)) {
24
- const localPath = path.join(process.cwd(), `content/.morph/templates/${templateName}`);
25
- if (fs.existsSync(localPath)) {
26
- return fs.readFileSync(localPath, 'utf-8');
27
- }
28
- throw new Error(`Template not found: ${templateName}`);
29
- }
30
-
31
- return fs.readFileSync(templatePath, 'utf-8');
32
- }
33
-
34
- function readSpec(featureName) {
35
- const specPath = path.join(process.cwd(), `.morph/project/outputs/${featureName}/spec.md`);
36
- const shardedIndexPath = path.join(process.cwd(), `.morph/project/outputs/${featureName}/spec/index.md`);
37
-
38
- // Try sharded spec first (BMAD pattern)
39
- if (fs.existsSync(shardedIndexPath)) {
40
- return { isSharded: true, indexPath: shardedIndexPath };
41
- }
42
-
43
- // Fallback to monolithic spec
44
- if (fs.existsSync(specPath)) {
45
- return { isSharded: false, content: fs.readFileSync(specPath, 'utf-8') };
46
- }
47
-
48
- throw new Error(`Spec not found for feature: ${featureName}`);
49
- }
50
-
51
- function extractContextFromSpec(specContent, sectionHeading) {
52
- // Extract section content between ## heading and next ##
53
- const regex = new RegExp(`## ${sectionHeading}\\s*([\\s\\S]*?)(?=\\n## |$)`, 'i');
54
- const match = specContent.match(regex);
55
- return match ? match[1].trim() : 'See spec.md for complete context';
56
- }
57
-
58
- function detectPatterns(tasks, specContent) {
59
- const patterns = {
60
- hasEntity: tasks.some(t => /entity|model|domain/i.test(t)),
61
- hasService: tasks.some(t => /service|business|logic/i.test(t)),
62
- hasComponent: tasks.some(t => /component|razor|blazor|ui/i.test(t)),
63
- hasRepository: tasks.some(t => /repository|data|persistence/i.test(t)),
64
- hasJob: tasks.some(t => /job|background|hangfire|scheduled/i.test(t)),
65
- hasAI: tasks.some(t => /agent|ai|llm|semantic|rag/i.test(t)),
66
- hasAzure: tasks.some(t => /bicep|azure|infra|deploy/i.test(t)),
67
- };
68
-
69
- return patterns;
70
- }
71
-
72
- function injectDevNotes(patterns, storyData) {
73
- const notes = [];
74
-
75
- // Entity pattern
76
- if (patterns.hasEntity) {
77
- notes.push('Use Primary Constructor (.NET 10 feature)');
78
- notes.push('Follow entity pattern: .morph/project/standards/coding.md#entity-pattern');
79
- notes.push('Navigation properties: configure in DbContext with Fluent API');
80
- }
81
-
82
- // Service pattern
83
- if (patterns.hasService) {
84
- notes.push('Service layer: implement interface-first (IXService → XService)');
85
- notes.push('Dependency injection: register in Program.cs as Scoped');
86
- notes.push('Error handling: use Result<T> pattern from standards/architecture.md');
87
- }
88
-
89
- // Blazor component
90
- if (patterns.hasComponent) {
91
- notes.push('UI Library: Fluent UI Blazor (see .morph/project/standards/ui.md)');
92
- notes.push('Design System: use CSS variables from wwwroot/css/design-system.css');
93
- notes.push('State management: @inject for services, [Parameter] for props');
94
- }
95
-
96
- // Repository pattern
97
- if (patterns.hasRepository) {
98
- notes.push('Repository pattern: IRepository<T> generic base');
99
- notes.push('EF Core: use AsNoTracking() for read-only queries');
100
- notes.push('Transactions: wrap in DbContext.Database.BeginTransactionAsync()');
101
- }
102
-
103
- // Background job
104
- if (patterns.hasJob) {
105
- notes.push('Hangfire: implement IJob interface, register in HangfireConfig.cs');
106
- notes.push('Retry policy: use [AutomaticRetry(Attempts = 3)]');
107
- notes.push('Logging: inject ILogger<TJob> for monitoring');
108
- }
109
-
110
- // AI/Agent
111
- if (patterns.hasAI) {
112
- notes.push('Microsoft Agent Framework: use AgentBuilder (not Semantic Kernel)');
113
- notes.push('Prompts: store in /prompts/{agent-name}.md');
114
- notes.push('Vector search: use EF Core 10 Vector Search (see standards/vector-search-rag.md)');
115
- }
116
-
117
- // Azure/IaC
118
- if (patterns.hasAzure) {
119
- notes.push('Infrastructure as Code: ALWAYS use Bicep (never portal)');
120
- notes.push('Cost validation: run morph-spec cost before commit');
121
- notes.push('Deployment: Azure Container Apps (not App Service)');
122
- }
123
-
124
- // Add spec reference
125
- if (storyData.specShard) {
126
- notes.push(`Spec reference: .morph/project/outputs/${storyData.featureName}/spec/${storyData.specShard}.md`);
127
- } else {
128
- notes.push(`Spec reference: .morph/project/outputs/${storyData.featureName}/spec.md`);
129
- }
130
-
131
- return notes;
132
- }
133
-
134
- function renderStory(template, data) {
135
- let rendered = template;
136
-
137
- // Simple placeholder replacement (non-Mustache for simplicity)
138
- const replacements = {
139
- '{{STORY_ID}}': data.storyId || 'STORY-XXX',
140
- '{{STORY_TITLE}}': data.storyTitle || 'Story Title',
141
- '{{FEATURE_NAME}}': data.featureName || 'feature-name',
142
- '{{FEATURE_NAME_TITLE}}': data.featureNameTitle || 'Feature Name',
143
- '{{EPIC_NAME}}': data.epicName || 'Epic Name',
144
- '{{DATE}}': new Date().toISOString().split('T')[0],
145
- '{{STORY_CONTEXT}}': data.context || 'Context not provided',
146
- '{{SPEC_SHARD}}': data.specShard || 'spec',
147
- '{{EFFORT}}': data.effort || '1 day',
148
- '{{CODING_PATTERN}}': data.codingPattern || 'general',
149
- '{{ARCH_PATTERN}}': data.archPattern || 'clean-architecture',
150
- '{{STATUS}}': 'Ready',
151
- '{{CREATED_DATE}}': new Date().toISOString().split('T')[0],
152
- '{{ADDITIONAL_NOTES}}': data.additionalNotes || '',
153
- };
154
-
155
- for (const [placeholder, value] of Object.entries(replacements)) {
156
- rendered = rendered.replaceAll(placeholder, value);
157
- }
158
-
159
- // Handle arrays (tasks, dev notes, acceptance criteria)
160
- if (data.tasks && data.tasks.length > 0) {
161
- const tasksSection = data.tasks.map(t => `- [ ] ${t}`).join('\n');
162
- rendered = rendered.replace(/{{#TASKS}}[\s\S]*?{{\/TASKS}}/g, tasksSection);
163
- } else {
164
- rendered = rendered.replace(/{{#TASKS}}[\s\S]*?{{\/TASKS}}/g, '- [ ] Task 1\n- [ ] Task 2');
165
- }
166
-
167
- if (data.devNotes && data.devNotes.length > 0) {
168
- const devNotesSection = data.devNotes.map(n => `- ${n}`).join('\n');
169
- rendered = rendered.replace(/{{#DEV_NOTES}}[\s\S]*?{{\/DEV_NOTES}}/g, devNotesSection);
170
- } else {
171
- rendered = rendered.replace(/{{#DEV_NOTES}}[\s\S]*?{{\/DEV_NOTES}}/g, '- Follow standards in .morph/project/standards/');
172
- }
173
-
174
- if (data.acceptanceCriteria && data.acceptanceCriteria.length > 0) {
175
- const acSection = data.acceptanceCriteria.map(ac =>
176
- `- [ ] **GIVEN** ${ac.given} **WHEN** ${ac.when} **THEN** ${ac.then}`
177
- ).join('\n');
178
- rendered = rendered.replace(/{{#ACCEPTANCE_CRITERIA}}[\s\S]*?{{\/ACCEPTANCE_CRITERIA}}/g, acSection);
179
- } else {
180
- rendered = rendered.replace(/{{#ACCEPTANCE_CRITERIA}}[\s\S]*?{{\/ACCEPTANCE_CRITERIA}}/g,
181
- '- [ ] **GIVEN** [condition] **WHEN** [action] **THEN** [result]');
182
- }
183
-
184
- // Clean up remaining Mustache sections (empty arrays)
185
- rendered = rendered.replace(/{{#\w+}}[\s\S]*?{{\/\w+}}/g, '');
186
-
187
- return rendered;
188
- }
189
-
190
- function toTitleCase(str) {
191
- return str
192
- .split('-')
193
- .map(word => word.charAt(0).toUpperCase() + word.slice(1))
194
- .join(' ');
195
- }
196
-
197
- // ============================================================================
198
- // Command Function
199
- // ============================================================================
200
-
201
- export async function createStoryCommand(feature, storyId, options) {
202
- logger.header('MORPH-SPEC Story Creator');
203
- logger.dim(`Feature: ${feature}`);
204
- logger.dim(`Story ID: ${storyId}`);
205
- logger.blank();
206
-
207
- const spinner = ora('Creating story...').start();
208
-
209
- try {
210
- // Read template
211
- const template = readTemplate('story.md');
212
-
213
- // Read spec (detect if sharded)
214
- const spec = readSpec(feature);
215
-
216
- // Build story data
217
- const storyData = {
218
- featureName: feature,
219
- featureNameTitle: toTitleCase(feature),
220
- storyId,
221
- storyTitle: options.title || 'Story Title',
222
- epicName: options.epic || toTitleCase(feature),
223
- context: options.context || (spec.isSharded
224
- ? 'See sharded spec for complete context'
225
- : extractContextFromSpec(spec.content, 'Overview')),
226
- specShard: spec.isSharded ? 'index' : null,
227
- tasks: options.tasks ? options.tasks.split(',').map(t => t.trim()) : ['Task 1', 'Task 2'],
228
- effort: '1 day',
229
- additionalNotes: '',
230
- };
231
-
232
- // Detect patterns and inject Dev Notes
233
- const patterns = detectPatterns(storyData.tasks, spec.content || '');
234
- storyData.devNotes = injectDevNotes(patterns, storyData);
235
-
236
- // Default acceptance criteria
237
- storyData.acceptanceCriteria = [
238
- { given: '[condition]', when: '[action]', then: '[expected result]' },
239
- ];
240
-
241
- // Render story
242
- const renderedStory = renderStory(template, storyData);
243
-
244
- // Output
245
- const outputDir = path.join(process.cwd(), `.morph/project/outputs/${feature}/stories`);
246
- const outputPath = path.join(outputDir, `${storyId}.md`);
247
-
248
- if (options.dryRun) {
249
- spinner.info('Dry run - preview only');
250
- logger.blank();
251
- console.log(renderedStory);
252
- logger.blank();
253
- logger.dim(`Would be written to: ${outputPath}`);
254
- } else {
255
- // Ensure directory exists
256
- await ensureDir(outputDir);
257
-
258
- // Write file
259
- await writeFile(outputPath, renderedStory);
260
-
261
- // ============================================================================
262
- // Update sprint-status.yaml (create if doesn't exist)
263
- // ============================================================================
264
- const sprintStatusPath = path.join(process.cwd(), `.morph/project/outputs/${feature}/sprint-status.yaml`);
265
- let sprintStatus;
266
-
267
- if (fs.existsSync(sprintStatusPath)) {
268
- // Load existing
269
- const content = fs.readFileSync(sprintStatusPath, 'utf-8');
270
- sprintStatus = yaml.parse(content);
271
- } else {
272
- // Create new
273
- sprintStatus = {
274
- feature: feature,
275
- epic: options.epic || toTitleCase(feature),
276
- created: new Date().toISOString().split('T')[0],
277
- updated: new Date().toISOString().split('T')[0],
278
- stories: [],
279
- metrics: {
280
- total_stories: 0,
281
- ready: 0,
282
- in_progress: 0,
283
- ready_for_qa: 0,
284
- done: 0,
285
- completion_percent: 0
286
- },
287
- current: null,
288
- next: null
289
- };
290
- }
291
-
292
- // Add new story to sprint-status
293
- sprintStatus.stories.push({
294
- id: storyId,
295
- title: storyData.storyTitle,
296
- file: `stories/${storyId}.md`,
297
- status: 'ready',
298
- created: new Date().toISOString().split('T')[0],
299
- assigned: null,
300
- started: null,
301
- completed: null
302
- });
303
-
304
- // Update metrics
305
- sprintStatus.metrics.total_stories = sprintStatus.stories.length;
306
- sprintStatus.metrics.ready = sprintStatus.stories.filter(s => s.status === 'ready').length;
307
- sprintStatus.metrics.in_progress = sprintStatus.stories.filter(s => s.status === 'in_progress').length;
308
- sprintStatus.metrics.ready_for_qa = sprintStatus.stories.filter(s => s.status === 'ready_for_qa').length;
309
- sprintStatus.metrics.done = sprintStatus.stories.filter(s => s.status === 'done').length;
310
- sprintStatus.metrics.completion_percent = sprintStatus.stories.length > 0
311
- ? Math.round((sprintStatus.metrics.done / sprintStatus.stories.length) * 100)
312
- : 0;
313
- sprintStatus.updated = new Date().toISOString().split('T')[0];
314
-
315
- // Set next story if null
316
- if (!sprintStatus.next) {
317
- sprintStatus.next = {
318
- story_id: storyId,
319
- recommendation: `Story ${storyId} is ready for development`
320
- };
321
- }
322
-
323
- // Write sprint-status.yaml
324
- const yamlContent = yaml.stringify(sprintStatus);
325
- fs.writeFileSync(sprintStatusPath, yamlContent);
326
-
327
- spinner.succeed('Story created!');
328
- logger.blank();
329
-
330
- logger.success(`Story file: ${chalk.cyan(outputPath)}`);
331
- logger.success(`Updated: ${chalk.cyan('sprint-status.yaml')}`);
332
- logger.blank();
333
-
334
- logger.header('Dev Notes Auto-Injected:');
335
- storyData.devNotes.forEach(note => logger.dim(` - ${note}`));
336
- logger.blank();
337
-
338
- logger.header('Next Steps:');
339
- logger.dim(' 1. Review and customize story file');
340
- logger.dim(' 2. Run in fresh Claude session: /dev → implement story');
341
- logger.dim(' 3. Dev adds implementation notes');
342
- logger.dim(' 4. QA reviews and adds QA notes');
343
- logger.blank();
344
- }
345
-
346
- } catch (error) {
347
- spinner.fail('Failed to create story');
348
- logger.error(error.message);
349
- process.exit(1);
350
- }
351
- }
1
+ /**
2
+ * MORPH-SPEC Story Creator
3
+ * Creates self-contained story files with auto-injected Dev Notes
4
+ * Inspired by BMAD Method story-driven development
5
+ */
6
+
7
+ import fs from 'fs';
8
+ import path from 'path';
9
+ import yaml from 'yaml';
10
+ import ora from 'ora';
11
+ import chalk from 'chalk';
12
+ import { logger } from '../utils/logger.js';
13
+ import { ensureDir, writeFile } from '../utils/file-copier.js';
14
+ import { resolveTemplatesDir } from '../lib/stack-resolver.js';
15
+
16
+ // ============================================================================
17
+ // Helper Functions
18
+ // ============================================================================
19
+
20
+ function readTemplate(templateName) {
21
+ // Try npm-installed package path first
22
+ const pkgTemplatesDir = resolveTemplatesDir(path.join(process.cwd(), 'node_modules/@polymorphism-tech/morph-spec'));
23
+ const templatePath = path.join(pkgTemplatesDir, templateName);
24
+
25
+ // Fallback to local if in development
26
+ if (!fs.existsSync(templatePath)) {
27
+ const localPath = path.join(resolveTemplatesDir(process.cwd()), templateName);
28
+ if (fs.existsSync(localPath)) {
29
+ return fs.readFileSync(localPath, 'utf-8');
30
+ }
31
+ throw new Error(`Template not found: ${templateName}`);
32
+ }
33
+
34
+ return fs.readFileSync(templatePath, 'utf-8');
35
+ }
36
+
37
+ function readSpec(featureName) {
38
+ const specPath = path.join(process.cwd(), `.morph/project/outputs/${featureName}/spec.md`);
39
+ const shardedIndexPath = path.join(process.cwd(), `.morph/project/outputs/${featureName}/spec/index.md`);
40
+
41
+ // Try sharded spec first (BMAD pattern)
42
+ if (fs.existsSync(shardedIndexPath)) {
43
+ return { isSharded: true, indexPath: shardedIndexPath };
44
+ }
45
+
46
+ // Fallback to monolithic spec
47
+ if (fs.existsSync(specPath)) {
48
+ return { isSharded: false, content: fs.readFileSync(specPath, 'utf-8') };
49
+ }
50
+
51
+ throw new Error(`Spec not found for feature: ${featureName}`);
52
+ }
53
+
54
+ function extractContextFromSpec(specContent, sectionHeading) {
55
+ // Extract section content between ## heading and next ##
56
+ const regex = new RegExp(`## ${sectionHeading}\\s*([\\s\\S]*?)(?=\\n## |$)`, 'i');
57
+ const match = specContent.match(regex);
58
+ return match ? match[1].trim() : 'See spec.md for complete context';
59
+ }
60
+
61
+ function detectPatterns(tasks, specContent) {
62
+ const patterns = {
63
+ hasEntity: tasks.some(t => /entity|model|domain/i.test(t)),
64
+ hasService: tasks.some(t => /service|business|logic/i.test(t)),
65
+ hasComponent: tasks.some(t => /component|razor|blazor|ui/i.test(t)),
66
+ hasRepository: tasks.some(t => /repository|data|persistence/i.test(t)),
67
+ hasJob: tasks.some(t => /job|background|hangfire|scheduled/i.test(t)),
68
+ hasAI: tasks.some(t => /agent|ai|llm|semantic|rag/i.test(t)),
69
+ hasAzure: tasks.some(t => /bicep|azure|infra|deploy/i.test(t)),
70
+ };
71
+
72
+ return patterns;
73
+ }
74
+
75
+ function injectDevNotes(patterns, storyData) {
76
+ const notes = [];
77
+
78
+ // Entity pattern
79
+ if (patterns.hasEntity) {
80
+ notes.push('Use Primary Constructor (.NET 10 feature)');
81
+ notes.push('Follow entity pattern: .morph/project/standards/coding.md#entity-pattern');
82
+ notes.push('Navigation properties: configure in DbContext with Fluent API');
83
+ }
84
+
85
+ // Service pattern
86
+ if (patterns.hasService) {
87
+ notes.push('Service layer: implement interface-first (IXService → XService)');
88
+ notes.push('Dependency injection: register in Program.cs as Scoped');
89
+ notes.push('Error handling: use Result<T> pattern from standards/architecture.md');
90
+ }
91
+
92
+ // Blazor component
93
+ if (patterns.hasComponent) {
94
+ notes.push('UI Library: Fluent UI Blazor (see .morph/project/standards/ui.md)');
95
+ notes.push('Design System: use CSS variables from wwwroot/css/design-system.css');
96
+ notes.push('State management: @inject for services, [Parameter] for props');
97
+ }
98
+
99
+ // Repository pattern
100
+ if (patterns.hasRepository) {
101
+ notes.push('Repository pattern: IRepository<T> generic base');
102
+ notes.push('EF Core: use AsNoTracking() for read-only queries');
103
+ notes.push('Transactions: wrap in DbContext.Database.BeginTransactionAsync()');
104
+ }
105
+
106
+ // Background job
107
+ if (patterns.hasJob) {
108
+ notes.push('Hangfire: implement IJob interface, register in HangfireConfig.cs');
109
+ notes.push('Retry policy: use [AutomaticRetry(Attempts = 3)]');
110
+ notes.push('Logging: inject ILogger<TJob> for monitoring');
111
+ }
112
+
113
+ // AI/Agent
114
+ if (patterns.hasAI) {
115
+ notes.push('Microsoft Agent Framework: use AgentBuilder (not Semantic Kernel)');
116
+ notes.push('Prompts: store in /prompts/{agent-name}.md');
117
+ notes.push('Vector search: use EF Core 10 Vector Search (see standards/vector-search-rag.md)');
118
+ }
119
+
120
+ // Azure/IaC
121
+ if (patterns.hasAzure) {
122
+ notes.push('Infrastructure as Code: ALWAYS use Bicep (never portal)');
123
+ notes.push('Cost validation: run morph-spec cost before commit');
124
+ notes.push('Deployment: Azure Container Apps (not App Service)');
125
+ }
126
+
127
+ // Add spec reference
128
+ if (storyData.specShard) {
129
+ notes.push(`Spec reference: .morph/project/outputs/${storyData.featureName}/spec/${storyData.specShard}.md`);
130
+ } else {
131
+ notes.push(`Spec reference: .morph/project/outputs/${storyData.featureName}/spec.md`);
132
+ }
133
+
134
+ return notes;
135
+ }
136
+
137
+ function renderStory(template, data) {
138
+ let rendered = template;
139
+
140
+ // Simple placeholder replacement (non-Mustache for simplicity)
141
+ const replacements = {
142
+ '{{STORY_ID}}': data.storyId || 'STORY-XXX',
143
+ '{{STORY_TITLE}}': data.storyTitle || 'Story Title',
144
+ '{{FEATURE_NAME}}': data.featureName || 'feature-name',
145
+ '{{FEATURE_NAME_TITLE}}': data.featureNameTitle || 'Feature Name',
146
+ '{{EPIC_NAME}}': data.epicName || 'Epic Name',
147
+ '{{DATE}}': new Date().toISOString().split('T')[0],
148
+ '{{STORY_CONTEXT}}': data.context || 'Context not provided',
149
+ '{{SPEC_SHARD}}': data.specShard || 'spec',
150
+ '{{EFFORT}}': data.effort || '1 day',
151
+ '{{CODING_PATTERN}}': data.codingPattern || 'general',
152
+ '{{ARCH_PATTERN}}': data.archPattern || 'clean-architecture',
153
+ '{{STATUS}}': 'Ready',
154
+ '{{CREATED_DATE}}': new Date().toISOString().split('T')[0],
155
+ '{{ADDITIONAL_NOTES}}': data.additionalNotes || '',
156
+ };
157
+
158
+ for (const [placeholder, value] of Object.entries(replacements)) {
159
+ rendered = rendered.replaceAll(placeholder, value);
160
+ }
161
+
162
+ // Handle arrays (tasks, dev notes, acceptance criteria)
163
+ if (data.tasks && data.tasks.length > 0) {
164
+ const tasksSection = data.tasks.map(t => `- [ ] ${t}`).join('\n');
165
+ rendered = rendered.replace(/{{#TASKS}}[\s\S]*?{{\/TASKS}}/g, tasksSection);
166
+ } else {
167
+ rendered = rendered.replace(/{{#TASKS}}[\s\S]*?{{\/TASKS}}/g, '- [ ] Task 1\n- [ ] Task 2');
168
+ }
169
+
170
+ if (data.devNotes && data.devNotes.length > 0) {
171
+ const devNotesSection = data.devNotes.map(n => `- ${n}`).join('\n');
172
+ rendered = rendered.replace(/{{#DEV_NOTES}}[\s\S]*?{{\/DEV_NOTES}}/g, devNotesSection);
173
+ } else {
174
+ rendered = rendered.replace(/{{#DEV_NOTES}}[\s\S]*?{{\/DEV_NOTES}}/g, '- Follow standards in .morph/project/standards/');
175
+ }
176
+
177
+ if (data.acceptanceCriteria && data.acceptanceCriteria.length > 0) {
178
+ const acSection = data.acceptanceCriteria.map(ac =>
179
+ `- [ ] **GIVEN** ${ac.given} **WHEN** ${ac.when} **THEN** ${ac.then}`
180
+ ).join('\n');
181
+ rendered = rendered.replace(/{{#ACCEPTANCE_CRITERIA}}[\s\S]*?{{\/ACCEPTANCE_CRITERIA}}/g, acSection);
182
+ } else {
183
+ rendered = rendered.replace(/{{#ACCEPTANCE_CRITERIA}}[\s\S]*?{{\/ACCEPTANCE_CRITERIA}}/g,
184
+ '- [ ] **GIVEN** [condition] **WHEN** [action] **THEN** [result]');
185
+ }
186
+
187
+ // Clean up remaining Mustache sections (empty arrays)
188
+ rendered = rendered.replace(/{{#\w+}}[\s\S]*?{{\/\w+}}/g, '');
189
+
190
+ return rendered;
191
+ }
192
+
193
+ function toTitleCase(str) {
194
+ return str
195
+ .split('-')
196
+ .map(word => word.charAt(0).toUpperCase() + word.slice(1))
197
+ .join(' ');
198
+ }
199
+
200
+ // ============================================================================
201
+ // Command Function
202
+ // ============================================================================
203
+
204
+ export async function createStoryCommand(feature, storyId, options) {
205
+ logger.header('MORPH-SPEC Story Creator');
206
+ logger.dim(`Feature: ${feature}`);
207
+ logger.dim(`Story ID: ${storyId}`);
208
+ logger.blank();
209
+
210
+ const spinner = ora('Creating story...').start();
211
+
212
+ try {
213
+ // Read template
214
+ const template = readTemplate('story.md');
215
+
216
+ // Read spec (detect if sharded)
217
+ const spec = readSpec(feature);
218
+
219
+ // Build story data
220
+ const storyData = {
221
+ featureName: feature,
222
+ featureNameTitle: toTitleCase(feature),
223
+ storyId,
224
+ storyTitle: options.title || 'Story Title',
225
+ epicName: options.epic || toTitleCase(feature),
226
+ context: options.context || (spec.isSharded
227
+ ? 'See sharded spec for complete context'
228
+ : extractContextFromSpec(spec.content, 'Overview')),
229
+ specShard: spec.isSharded ? 'index' : null,
230
+ tasks: options.tasks ? options.tasks.split(',').map(t => t.trim()) : ['Task 1', 'Task 2'],
231
+ effort: '1 day',
232
+ additionalNotes: '',
233
+ };
234
+
235
+ // Detect patterns and inject Dev Notes
236
+ const patterns = detectPatterns(storyData.tasks, spec.content || '');
237
+ storyData.devNotes = injectDevNotes(patterns, storyData);
238
+
239
+ // Default acceptance criteria
240
+ storyData.acceptanceCriteria = [
241
+ { given: '[condition]', when: '[action]', then: '[expected result]' },
242
+ ];
243
+
244
+ // Render story
245
+ const renderedStory = renderStory(template, storyData);
246
+
247
+ // Output
248
+ const outputDir = path.join(process.cwd(), `.morph/project/outputs/${feature}/stories`);
249
+ const outputPath = path.join(outputDir, `${storyId}.md`);
250
+
251
+ if (options.dryRun) {
252
+ spinner.info('Dry run - preview only');
253
+ logger.blank();
254
+ console.log(renderedStory);
255
+ logger.blank();
256
+ logger.dim(`Would be written to: ${outputPath}`);
257
+ } else {
258
+ // Ensure directory exists
259
+ await ensureDir(outputDir);
260
+
261
+ // Write file
262
+ await writeFile(outputPath, renderedStory);
263
+
264
+ // ============================================================================
265
+ // Update sprint-status.yaml (create if doesn't exist)
266
+ // ============================================================================
267
+ const sprintStatusPath = path.join(process.cwd(), `.morph/project/outputs/${feature}/sprint-status.yaml`);
268
+ let sprintStatus;
269
+
270
+ if (fs.existsSync(sprintStatusPath)) {
271
+ // Load existing
272
+ const content = fs.readFileSync(sprintStatusPath, 'utf-8');
273
+ sprintStatus = yaml.parse(content);
274
+ } else {
275
+ // Create new
276
+ sprintStatus = {
277
+ feature: feature,
278
+ epic: options.epic || toTitleCase(feature),
279
+ created: new Date().toISOString().split('T')[0],
280
+ updated: new Date().toISOString().split('T')[0],
281
+ stories: [],
282
+ metrics: {
283
+ total_stories: 0,
284
+ ready: 0,
285
+ in_progress: 0,
286
+ ready_for_qa: 0,
287
+ done: 0,
288
+ completion_percent: 0
289
+ },
290
+ current: null,
291
+ next: null
292
+ };
293
+ }
294
+
295
+ // Add new story to sprint-status
296
+ sprintStatus.stories.push({
297
+ id: storyId,
298
+ title: storyData.storyTitle,
299
+ file: `stories/${storyId}.md`,
300
+ status: 'ready',
301
+ created: new Date().toISOString().split('T')[0],
302
+ assigned: null,
303
+ started: null,
304
+ completed: null
305
+ });
306
+
307
+ // Update metrics
308
+ sprintStatus.metrics.total_stories = sprintStatus.stories.length;
309
+ sprintStatus.metrics.ready = sprintStatus.stories.filter(s => s.status === 'ready').length;
310
+ sprintStatus.metrics.in_progress = sprintStatus.stories.filter(s => s.status === 'in_progress').length;
311
+ sprintStatus.metrics.ready_for_qa = sprintStatus.stories.filter(s => s.status === 'ready_for_qa').length;
312
+ sprintStatus.metrics.done = sprintStatus.stories.filter(s => s.status === 'done').length;
313
+ sprintStatus.metrics.completion_percent = sprintStatus.stories.length > 0
314
+ ? Math.round((sprintStatus.metrics.done / sprintStatus.stories.length) * 100)
315
+ : 0;
316
+ sprintStatus.updated = new Date().toISOString().split('T')[0];
317
+
318
+ // Set next story if null
319
+ if (!sprintStatus.next) {
320
+ sprintStatus.next = {
321
+ story_id: storyId,
322
+ recommendation: `Story ${storyId} is ready for development`
323
+ };
324
+ }
325
+
326
+ // Write sprint-status.yaml
327
+ const yamlContent = yaml.stringify(sprintStatus);
328
+ fs.writeFileSync(sprintStatusPath, yamlContent);
329
+
330
+ spinner.succeed('Story created!');
331
+ logger.blank();
332
+
333
+ logger.success(`Story file: ${chalk.cyan(outputPath)}`);
334
+ logger.success(`Updated: ${chalk.cyan('sprint-status.yaml')}`);
335
+ logger.blank();
336
+
337
+ logger.header('Dev Notes Auto-Injected:');
338
+ storyData.devNotes.forEach(note => logger.dim(` - ${note}`));
339
+ logger.blank();
340
+
341
+ logger.header('Next Steps:');
342
+ logger.dim(' 1. Review and customize story file');
343
+ logger.dim(' 2. Run in fresh Claude session: /dev → implement story');
344
+ logger.dim(' 3. Dev adds implementation notes');
345
+ logger.dim(' 4. QA reviews and adds QA notes');
346
+ logger.blank();
347
+ }
348
+
349
+ } catch (error) {
350
+ spinner.fail('Failed to create story');
351
+ logger.error(error.message);
352
+ process.exit(1);
353
+ }
354
+ }