@polymorphism-tech/morph-spec 2.3.0 → 3.0.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 (166) hide show
  1. package/CLAUDE.md +446 -1730
  2. package/README.md +515 -516
  3. package/bin/morph-spec.js +366 -294
  4. package/bin/task-manager.js +429 -368
  5. package/bin/validate.js +369 -268
  6. package/content/.claude/commands/morph-apply.md +221 -158
  7. package/content/.claude/commands/morph-deploy.md +529 -0
  8. package/content/.claude/commands/morph-preflight.md +227 -0
  9. package/content/.claude/commands/morph-proposal.md +122 -101
  10. package/content/.claude/commands/morph-status.md +86 -86
  11. package/content/.claude/commands/morph-troubleshoot.md +122 -0
  12. package/content/.claude/skills/infra/azure-deploy-specialist.md +699 -0
  13. package/content/.claude/skills/level-0-meta/README.md +7 -0
  14. package/content/.claude/skills/level-0-meta/code-review.md +226 -0
  15. package/content/.claude/skills/level-0-meta/morph-checklist.md +117 -0
  16. package/content/.claude/skills/level-0-meta/simulation-checklist.md +77 -0
  17. package/content/.claude/skills/level-1-workflows/README.md +7 -0
  18. package/content/.claude/skills/level-1-workflows/morph-replicate.md +213 -0
  19. package/content/.claude/{commands/morph-clarify.md → skills/level-1-workflows/phase-clarify.md} +131 -184
  20. package/content/.claude/{commands/morph-design.md → skills/level-1-workflows/phase-design.md} +213 -275
  21. package/content/.claude/skills/level-1-workflows/phase-setup.md +106 -0
  22. package/content/.claude/skills/level-1-workflows/phase-tasks.md +164 -0
  23. package/content/.claude/{commands/morph-uiux.md → skills/level-1-workflows/phase-uiux.md} +169 -211
  24. package/content/.claude/skills/level-2-domains/README.md +14 -0
  25. package/content/.claude/skills/level-2-domains/ai-agents/ai-system-architect.md +192 -0
  26. package/content/.claude/skills/{specialists → level-2-domains/architecture}/po-pm-advisor.md +197 -197
  27. package/content/.claude/skills/level-2-domains/architecture/standards-architect.md +156 -0
  28. package/content/.claude/skills/level-2-domains/backend/dotnet-senior.md +287 -0
  29. package/content/.claude/skills/level-2-domains/backend/ef-modeler.md +113 -0
  30. package/content/.claude/skills/level-2-domains/backend/hangfire-orchestrator.md +126 -0
  31. package/content/.claude/skills/level-2-domains/backend/ms-agent-expert.md +109 -0
  32. package/content/.claude/skills/level-2-domains/frontend/blazor-builder.md +210 -0
  33. package/content/.claude/skills/level-2-domains/frontend/nextjs-expert.md +154 -0
  34. package/content/.claude/skills/level-2-domains/frontend/ui-ux-designer.md +191 -0
  35. package/content/.claude/skills/{specialists → level-2-domains/infrastructure}/azure-architect.md +142 -142
  36. package/content/.claude/skills/level-2-domains/infrastructure/bicep-architect.md +126 -0
  37. package/content/.claude/skills/level-2-domains/infrastructure/container-specialist.md +131 -0
  38. package/content/.claude/skills/level-2-domains/infrastructure/devops-engineer.md +119 -0
  39. package/content/.claude/skills/level-2-domains/integrations/asaas-financial.md +130 -0
  40. package/content/.claude/skills/level-2-domains/integrations/azure-identity.md +142 -0
  41. package/content/.claude/skills/level-2-domains/integrations/clerk-auth.md +108 -0
  42. package/content/.claude/skills/level-2-domains/integrations/resend-email.md +119 -0
  43. package/content/.claude/skills/level-2-domains/quality/code-analyzer.md +235 -0
  44. package/content/.claude/skills/level-2-domains/quality/testing-specialist.md +126 -0
  45. package/content/.claude/skills/level-3-technologies/README.md +7 -0
  46. package/content/.claude/skills/level-4-patterns/README.md +7 -0
  47. package/content/.claude/skills/specialists/prompt-engineer.md +189 -0
  48. package/content/.claude/skills/specialists/seo-growth-hacker.md +320 -0
  49. package/content/.morph/config/agents.json +762 -242
  50. package/content/.morph/config/config.template.json +122 -108
  51. package/content/.morph/docs/workflows/design-impl.md +37 -0
  52. package/content/.morph/docs/workflows/enforcement-pipeline.md +668 -0
  53. package/content/.morph/docs/workflows/fast-track.md +29 -0
  54. package/content/.morph/docs/workflows/full-morph.md +76 -0
  55. package/content/.morph/docs/workflows/standard.md +44 -0
  56. package/content/.morph/docs/workflows/ui-refresh.md +39 -0
  57. package/content/.morph/examples/scheduled-reports/decisions.md +158 -0
  58. package/content/.morph/examples/scheduled-reports/proposal.md +95 -0
  59. package/content/.morph/examples/scheduled-reports/spec.md +267 -0
  60. package/content/.morph/hooks/README.md +348 -239
  61. package/content/.morph/hooks/pre-commit-agents.sh +24 -24
  62. package/content/.morph/hooks/task-completed.js +73 -0
  63. package/content/.morph/hooks/teammate-idle.js +68 -0
  64. package/content/.morph/schemas/tasks.schema.json +220 -0
  65. package/content/.morph/standards/agent-framework-blazor-ui.md +359 -0
  66. package/content/.morph/standards/agent-framework-production.md +410 -0
  67. package/content/.morph/standards/agent-framework-setup.md +413 -453
  68. package/content/.morph/standards/agent-framework-workflows.md +349 -0
  69. package/content/.morph/standards/agent-teams-workflow.md +474 -0
  70. package/content/.morph/standards/architecture.md +325 -325
  71. package/content/.morph/standards/azure.md +605 -379
  72. package/content/.morph/standards/dotnet10-migration.md +520 -494
  73. package/content/.morph/templates/CONTEXT-FEATURE.md +276 -0
  74. package/content/.morph/templates/CONTEXT.md +170 -0
  75. package/content/.morph/templates/agent.cs +163 -172
  76. package/content/.morph/templates/clarify-questions.md +159 -0
  77. package/content/.morph/templates/contracts/Commands.cs +74 -0
  78. package/content/.morph/templates/contracts/Entities.cs +25 -0
  79. package/content/.morph/templates/contracts/Queries.cs +74 -0
  80. package/content/.morph/templates/contracts/README.md +74 -0
  81. package/content/.morph/templates/decisions.md +123 -106
  82. package/content/.morph/templates/infra/azure-pipelines-deploy.yml +480 -0
  83. package/content/.morph/templates/infra/deploy-checklist.md +426 -0
  84. package/content/.morph/templates/proposal.md +141 -155
  85. package/content/.morph/templates/recap.md +94 -105
  86. package/content/.morph/templates/simulation.md +353 -0
  87. package/content/.morph/templates/spec.md +149 -148
  88. package/content/.morph/templates/state.template.json +222 -222
  89. package/content/.morph/templates/tasks.md +257 -235
  90. package/content/.morph/templates/ui-components.md +362 -276
  91. package/content/CLAUDE.md +150 -442
  92. package/detectors/structure-detector.js +245 -250
  93. package/docs/README.md +144 -149
  94. package/docs/getting-started.md +301 -302
  95. package/docs/installation.md +361 -361
  96. package/docs/validation-checklist.md +265 -266
  97. package/package.json +80 -80
  98. package/src/commands/advance-phase.js +266 -0
  99. package/src/commands/analyze-blazor-concurrency.js +193 -0
  100. package/src/commands/deploy.js +780 -0
  101. package/src/commands/detect-agents.js +167 -0
  102. package/src/commands/doctor.js +356 -280
  103. package/src/commands/generate-context.js +40 -0
  104. package/src/commands/init.js +258 -245
  105. package/src/commands/lint-fluent.js +352 -0
  106. package/src/commands/rollback-phase.js +185 -0
  107. package/src/commands/session-summary.js +291 -0
  108. package/src/commands/task.js +78 -75
  109. package/src/commands/troubleshoot.js +222 -0
  110. package/src/commands/update.js +192 -159
  111. package/src/commands/validate-blazor-state.js +210 -0
  112. package/src/commands/validate-blazor.js +156 -0
  113. package/src/commands/validate-css.js +84 -0
  114. package/src/commands/validate-phase.js +221 -0
  115. package/src/lib/blazor-concurrency-analyzer.js +288 -0
  116. package/src/lib/blazor-state-validator.js +291 -0
  117. package/src/lib/blazor-validator.js +374 -0
  118. package/src/lib/complexity-analyzer.js +441 -292
  119. package/src/lib/context-generator.js +513 -0
  120. package/src/lib/continuous-validator.js +421 -440
  121. package/src/lib/css-validator.js +352 -0
  122. package/src/lib/decision-constraint-loader.js +109 -0
  123. package/src/lib/design-system-detector.js +187 -0
  124. package/src/lib/design-system-scaffolder.js +299 -0
  125. package/src/lib/hook-executor.js +256 -0
  126. package/src/lib/recap-generator.js +205 -0
  127. package/src/lib/spec-validator.js +258 -0
  128. package/src/lib/standards-context-injector.js +287 -0
  129. package/src/lib/state-manager.js +397 -340
  130. package/src/lib/team-orchestrator.js +322 -0
  131. package/src/lib/troubleshoot-grep.js +194 -0
  132. package/src/lib/troubleshoot-index.js +144 -0
  133. package/src/lib/validation-runner.js +283 -0
  134. package/src/lib/validators/contract-compliance-validator.js +273 -0
  135. package/src/lib/validators/design-system-validator.js +231 -0
  136. package/src/utils/file-copier.js +187 -139
  137. package/content/.claude/commands/morph-costs.md +0 -206
  138. package/content/.claude/commands/morph-setup.md +0 -100
  139. package/content/.claude/commands/morph-tasks.md +0 -319
  140. package/content/.claude/skills/infra/bicep-architect.md +0 -419
  141. package/content/.claude/skills/infra/container-specialist.md +0 -437
  142. package/content/.claude/skills/infra/devops-engineer.md +0 -405
  143. package/content/.claude/skills/integrations/asaas-financial.md +0 -333
  144. package/content/.claude/skills/integrations/azure-identity.md +0 -309
  145. package/content/.claude/skills/integrations/clerk-auth.md +0 -290
  146. package/content/.claude/skills/specialists/ai-system-architect.md +0 -604
  147. package/content/.claude/skills/specialists/cost-guardian.md +0 -110
  148. package/content/.claude/skills/specialists/ef-modeler.md +0 -211
  149. package/content/.claude/skills/specialists/hangfire-orchestrator.md +0 -255
  150. package/content/.claude/skills/specialists/ms-agent-expert.md +0 -263
  151. package/content/.claude/skills/specialists/standards-architect.md +0 -78
  152. package/content/.claude/skills/specialists/ui-ux-designer.md +0 -1100
  153. package/content/.claude/skills/stacks/dotnet-blazor.md +0 -606
  154. package/content/.claude/skills/stacks/dotnet-nextjs.md +0 -402
  155. package/content/.claude/skills/stacks/shopify.md +0 -445
  156. package/content/.morph/config/azure-pricing.json +0 -70
  157. package/content/.morph/config/azure-pricing.schema.json +0 -50
  158. package/content/.morph/hooks/pre-commit-costs.sh +0 -91
  159. package/docs/api/cost-calculator.js.html +0 -513
  160. package/docs/api/design-system-generator.js.html +0 -382
  161. package/docs/api/global.html +0 -5263
  162. package/docs/api/index.html +0 -96
  163. package/docs/api/state-manager.js.html +0 -423
  164. package/src/commands/cost.js +0 -181
  165. package/src/commands/update-pricing.js +0 -206
  166. package/src/lib/cost-calculator.js +0 -429
package/bin/morph-spec.js CHANGED
@@ -1,294 +1,366 @@
1
- #!/usr/bin/env node
2
-
3
- import { program } from 'commander';
4
- import chalk from 'chalk';
5
- import { fileURLToPath } from 'url';
6
- import { dirname, join } from 'path';
7
- import { readFileSync } from 'fs';
8
-
9
- import { initCommand } from '../src/commands/init.js';
10
- import { updateCommand } from '../src/commands/update.js';
11
- import { doctorCommand } from '../src/commands/doctor.js';
12
- import { detectCommand } from '../src/commands/detect.js';
13
- import { syncCommand } from '../src/commands/sync.js';
14
- import { createStoryCommand } from '../src/commands/create-story.js';
15
- import { shardSpecCommand } from '../src/commands/shard-spec.js';
16
- import { sprintStatusCommand } from '../src/commands/sprint-status.js';
17
- import { stateCommand } from '../src/commands/state.js';
18
- import { taskDoneCommand, taskStartCommand, taskNextCommand } from '../src/commands/task.js';
19
- import { costCommand } from '../src/commands/cost.js';
20
- import { generateDesignSystemCommand } from '../src/commands/generate.js';
21
- import { updateResourcePricing, showPricing, validatePricing } from '../src/commands/update-pricing.js';
22
- import { validateCommand } from './validate.js';
23
- import { LearningSystem } from '../src/lib/learning-system.js';
24
-
25
- const __dirname = dirname(fileURLToPath(import.meta.url));
26
- const pkg = JSON.parse(readFileSync(join(__dirname, '..', 'package.json'), 'utf8'));
27
-
28
- const banner = chalk.cyan(`
29
- ███╗ ███╗ ██████╗ ██████╗ ██████╗ ██╗ ██╗
30
- ████╗ ████║██╔═══██╗██╔══██╗██╔══██╗██║ ██║
31
- ██╔████╔██║██║ ██║██████╔╝██████╔╝███████║
32
- ██║╚██╔╝██║██║ ██║██╔══██╗██╔═══╝ ██╔══██║
33
- ██║ ╚═╝ ██║╚██████╔╝██║ ██║██║ ██║ ██║
34
- ╚═╝ ╚═╝ ╚═════╝ ╚═╝ ╚═╝╚═╝ ╚═╝ ╚═╝
35
-
36
- Methodical Orchestration for Reliable Production-ready SPEC-driven development
37
- by Polymorphism Tech | v${pkg.version}
38
- `);
39
-
40
- program
41
- .name('morph-spec')
42
- .description('MORPH-SPEC Framework CLI')
43
- .version(pkg.version)
44
- .addHelpText('beforeAll', banner);
45
-
46
- program
47
- .command('init')
48
- .description('Initialize MORPH-SPEC in current directory')
49
- .option('-f, --force', 'Overwrite existing MORPH installation')
50
- .option('-p, --path <path>', 'Target path (default: current directory)')
51
- .action(initCommand);
52
-
53
- program
54
- .command('update')
55
- .description('Update MORPH templates and standards to latest version')
56
- .option('--templates', 'Update only templates')
57
- .option('--standards', 'Update only standards')
58
- .action(updateCommand);
59
-
60
- program
61
- .command('doctor')
62
- .description('Check MORPH installation health')
63
- .action(doctorCommand);
64
-
65
- program
66
- .command('detect')
67
- .description('Detect project stack, architecture, and patterns')
68
- .option('-p, --path <path>', 'Project path (default: current directory)')
69
- .option('-v, --verbose', 'Show detailed detection results')
70
- .option('--no-save', 'Do not save results to .morph/project/')
71
- .action(detectCommand);
72
-
73
- program
74
- .command('sync')
75
- .description('Sync standards from feature decisions')
76
- .option('-p, --path <path>', 'Project path (default: current directory)')
77
- .option('--dry-run', 'Show what would be synced without updating files')
78
- .action(syncCommand);
79
-
80
- // Story-driven development commands
81
- const storyCommand = program
82
- .command('story')
83
- .description('Story-driven development commands');
84
-
85
- storyCommand
86
- .command('create <feature> <story-id>')
87
- .description('Create a new story with auto-injected Dev Notes')
88
- .option('--title <title>', 'Story title')
89
- .option('--epic <epic>', 'Epic name')
90
- .option('--context <context>', 'Story context')
91
- .option('--tasks <tasks>', 'Comma-separated tasks')
92
- .option('--dry-run', 'Preview without writing file')
93
- .action(createStoryCommand);
94
-
95
- storyCommand
96
- .command('shard <feature>')
97
- .description('Shard spec.md into manageable chunks (90% token savings)')
98
- .option('--dry-run', 'Preview shards without writing files')
99
- .option('--verbose', 'Show detailed shard info')
100
- .action(shardSpecCommand);
101
-
102
- storyCommand
103
- .command('status <feature> [action] [story-id]')
104
- .description('Manage sprint status (show | start | qa | done | next)')
105
- .action(sprintStatusCommand);
106
-
107
- // State management commands
108
- program
109
- .command('state <action> [args...]')
110
- .description('Manage state.json (init | get | set | checkpoint | list | add-agent | remove-agent | mark-output)')
111
- .option('--force', 'Force overwrite (init command)')
112
- .option('--project <name>', 'Project name (init command)')
113
- .option('--type <type>', 'Project type (init command)')
114
- .option('--json', 'Output as JSON (get command)')
115
- .action((action, args, options) => stateCommand(action, args, options));
116
-
117
- // Task management commands (MORPH-SPEC 3.0)
118
- const taskCommand = program
119
- .command('task')
120
- .description('Manage feature tasks (done | start | next)');
121
-
122
- taskCommand
123
- .command('done <feature> <task-ids...>')
124
- .description('Mark tasks as completed')
125
- .action((feature, taskIds, options) => taskDoneCommand(feature, taskIds, options));
126
-
127
- taskCommand
128
- .command('start <feature> <task-id>')
129
- .description('Start a task (mark as in_progress)')
130
- .action((feature, taskId, options) => taskStartCommand(feature, taskId, options));
131
-
132
- taskCommand
133
- .command('next <feature>')
134
- .description('Show next suggested task')
135
- .action((feature, options) => taskNextCommand(feature, options));
136
-
137
- // Cost calculation command
138
- program
139
- .command('cost <bicep-files>')
140
- .description('Calculate Azure infrastructure costs from Bicep files')
141
- .option('--config <path>', 'Custom config path')
142
- .option('--verbose', 'Show detailed breakdown')
143
- .option('--json', 'Output as JSON')
144
- .option('--strict', 'Exit with error if cost exceeds ADR threshold')
145
- .action(costCommand);
146
-
147
- // Pricing management commands
148
- const pricingCommand = program
149
- .command('pricing')
150
- .description('Manage Azure pricing table');
151
-
152
- pricingCommand
153
- .command('show [resource-type]')
154
- .description('Show current pricing (all or specific resource type)')
155
- .option('--json', 'Output as JSON')
156
- .action((resourceType, options) => showPricing({ resourceType, format: options.json ? 'json' : 'table' }));
157
-
158
- pricingCommand
159
- .command('update <resource-type> <sku> <price>')
160
- .description('Update pricing for a specific SKU')
161
- .option('--dry-run', 'Preview without saving')
162
- .option('--no-validate', 'Skip validation')
163
- .action((resourceType, sku, price, options) =>
164
- updateResourcePricing({
165
- resourceType,
166
- sku,
167
- price: parseFloat(price),
168
- dryRun: options.dryRun,
169
- validate: options.validate !== false
170
- })
171
- );
172
-
173
- pricingCommand
174
- .command('validate')
175
- .description('Validate pricing file against JSON schema')
176
- .action(validatePricing);
177
-
178
- // Generation commands
179
- const generateCommand = program
180
- .command('generate')
181
- .description('Generate code from templates');
182
-
183
- generateCommand
184
- .command('design-system <ui-design-system-md>')
185
- .description('Generate CSS + theme files from ui-design-system.md')
186
- .option('--fluent', 'Generate only Fluent UI theme')
187
- .option('--mud', 'Generate only MudBlazor theme')
188
- .option('--both', 'Generate both themes (default)')
189
- .option('--namespace <ns>', 'C# namespace (default: YourProject.Themes)')
190
- .option('--css-output <path>', 'CSS output path (default: wwwroot/css/design-system.css)')
191
- .option('--fluent-output <path>', 'Fluent theme output path (default: Themes/FluentDesignTheme.cs)')
192
- .option('--mud-output <path>', 'MudBlazor theme output path (default: Themes/MudDesignTheme.cs)')
193
- .option('--dry-run', 'Preview without writing files')
194
- .action(generateDesignSystemCommand);
195
-
196
- // Validation commands (Sprint 4: Continuous Validation)
197
- program
198
- .command('validate [validator]')
199
- .description('Run project validations (all | packages | architecture | contrast)')
200
- .option('-v, --verbose', 'Show detailed output')
201
- .option('--auto-fix, --fix', 'Auto-fix issues where possible')
202
- .option('--no-fail', 'Don\'t exit with error code')
203
- .option('-i, --insights', 'Show learning insights')
204
- .option('--wcag-aaa', 'Use WCAG AAA standard (stricter)')
205
- .action((validator, options) => {
206
- const args = validator ? [validator] : ['all'];
207
- if (options.verbose) args.push('--verbose');
208
- if (options.autoFix) args.push('--auto-fix');
209
- if (options.noFail) args.push('--no-fail');
210
- if (options.insights) args.push('--insights');
211
- if (options.wcagAaa) args.push('--wcag-aaa');
212
- validateCommand(args);
213
- });
214
-
215
- // Learning commands (Sprint 4: Learning System)
216
- const learnCommand = program
217
- .command('learn')
218
- .description('AI learning system commands');
219
-
220
- learnCommand
221
- .command('analyze')
222
- .description('Learn from project history (decisions.md files)')
223
- .option('-v, --verbose', 'Show detailed learning progress')
224
- .action(async (options) => {
225
- const learner = new LearningSystem('.');
226
- await learner.learnFromProject();
227
-
228
- if (options.verbose) {
229
- learner.formatInsights();
230
- }
231
- });
232
-
233
- learnCommand
234
- .command('insights')
235
- .description('Show AI insights and patterns')
236
- .option('--json', 'Output as JSON')
237
- .action((options) => {
238
- const learner = new LearningSystem('.');
239
-
240
- if (options.json) {
241
- console.log(JSON.stringify(learner.getInsightsSummary(), null, 2));
242
- } else {
243
- learner.formatInsights();
244
- }
245
- });
246
-
247
- learnCommand
248
- .command('suggest [category]')
249
- .description('Get AI suggestions for a category (uiLibrary | architecture | infrastructure | authentication | stateManagement | testing)')
250
- .option('--json', 'Output as JSON')
251
- .action((category, options) => {
252
- const learner = new LearningSystem('.');
253
-
254
- if (category) {
255
- const suggestion = learner.getSuggestion(category);
256
- if (options.json) {
257
- console.log(JSON.stringify(suggestion, null, 2));
258
- } else {
259
- console.log(chalk.cyan(`\n💡 Suggestion for ${category}:\n`));
260
- if (suggestion.confidence === 'none') {
261
- console.log(chalk.yellow(` ${suggestion.reason}`));
262
- } else {
263
- console.log(chalk.white(` → ${suggestion.suggestion} (${suggestion.percentage}% confidence)`));
264
- console.log(chalk.gray(` ${suggestion.reason}`));
265
- }
266
- console.log('');
267
- }
268
- } else {
269
- const suggestions = learner.getAllSuggestions();
270
- if (options.json) {
271
- console.log(JSON.stringify(suggestions, null, 2));
272
- } else {
273
- learner.formatSuggestions(suggestions);
274
- }
275
- }
276
- });
277
-
278
- learnCommand
279
- .command('reset')
280
- .description('Reset knowledge base (clear all learned patterns)')
281
- .option('--force', 'Skip confirmation')
282
- .action((options) => {
283
- if (!options.force) {
284
- console.log(chalk.yellow('\n⚠️ This will delete all learned patterns and preferences.'));
285
- console.log(chalk.gray(' Run with --force to confirm.\n'));
286
- process.exit(1);
287
- }
288
-
289
- const learner = new LearningSystem('.');
290
- learner.reset();
291
- console.log(chalk.green('\n✅ Knowledge base reset\n'));
292
- });
293
-
294
- program.parse();
1
+ #!/usr/bin/env node
2
+
3
+ import { program } from 'commander';
4
+ import chalk from 'chalk';
5
+ import { fileURLToPath } from 'url';
6
+ import { dirname, join } from 'path';
7
+ import { readFileSync } from 'fs';
8
+
9
+ import { initCommand } from '../src/commands/init.js';
10
+ import { updateCommand } from '../src/commands/update.js';
11
+ import { doctorCommand } from '../src/commands/doctor.js';
12
+ import { detectCommand } from '../src/commands/detect.js';
13
+ import { detectAgentsCommand } from '../src/commands/detect-agents.js';
14
+ import { syncCommand } from '../src/commands/sync.js';
15
+ import { createStoryCommand } from '../src/commands/create-story.js';
16
+ import { shardSpecCommand } from '../src/commands/shard-spec.js';
17
+ import { sprintStatusCommand } from '../src/commands/sprint-status.js';
18
+ import { stateCommand } from '../src/commands/state.js';
19
+ import { taskDoneCommand, taskStartCommand, taskNextCommand } from '../src/commands/task.js';
20
+ import { generateDesignSystemCommand } from '../src/commands/generate.js';
21
+ import { generateContextCommand } from '../src/commands/generate-context.js';
22
+ import { validateCommand } from './validate.js';
23
+ import { validateBlazorCommand } from '../src/commands/validate-blazor.js';
24
+ import { lintFluentCommand } from '../src/commands/lint-fluent.js';
25
+ import { analyzeBlazorConcurrencyCommand } from '../src/commands/analyze-blazor-concurrency.js';
26
+ import { validateBlazorStateCommand } from '../src/commands/validate-blazor-state.js';
27
+ import { validateCssCommand } from '../src/commands/validate-css.js';
28
+ import { LearningSystem } from '../src/lib/learning-system.js';
29
+ import troubleshootCommand from '../src/commands/troubleshoot.js';
30
+ import { validatePhaseCommand } from '../src/commands/validate-phase.js';
31
+ import { sessionSummaryCommand } from '../src/commands/session-summary.js';
32
+ import { rollbackPhaseCommand } from '../src/commands/rollback-phase.js';
33
+ import { advancePhaseCommand } from '../src/commands/advance-phase.js';
34
+
35
+ const __dirname = dirname(fileURLToPath(import.meta.url));
36
+ const pkg = JSON.parse(readFileSync(join(__dirname, '..', 'package.json'), 'utf8'));
37
+
38
+ const banner = chalk.cyan(`
39
+ ███╗ ███╗ ██████╗ ██████╗ ██████╗ ██╗ ██╗
40
+ ████╗ ████║██╔═══██╗██╔══██╗██╔══██╗██║ ██║
41
+ ██╔████╔██║██║ ██║██████╔╝██████╔╝███████║
42
+ ██║╚██╔╝██║██║ ██║██╔══██╗██╔═══╝ ██╔══██║
43
+ ██║ ╚═╝ ██║╚██████╔╝██║ ██║██║ ██║ ██║
44
+ ╚═╝ ╚═╝ ╚═════╝ ╚═╝ ╚═╝╚═╝ ╚═╝ ╚═╝
45
+
46
+ Methodical Orchestration for Reliable Production-ready SPEC-driven development
47
+ by Polymorphism Tech | v${pkg.version}
48
+ `);
49
+
50
+ program
51
+ .name('morph-spec')
52
+ .description('MORPH-SPEC Framework CLI')
53
+ .version(pkg.version)
54
+ .addHelpText('beforeAll', banner);
55
+
56
+ program
57
+ .command('init')
58
+ .description('Initialize MORPH-SPEC in current directory')
59
+ .option('-f, --force', 'Overwrite existing MORPH installation')
60
+ .option('-p, --path <path>', 'Target path (default: current directory)')
61
+ .action(initCommand);
62
+
63
+ program
64
+ .command('update')
65
+ .description('Update MORPH templates and standards to latest version')
66
+ .option('--templates', 'Update only templates')
67
+ .option('--standards', 'Update only standards')
68
+ .action(updateCommand);
69
+
70
+ program
71
+ .command('doctor')
72
+ .description('Check MORPH installation health')
73
+ .action(doctorCommand);
74
+
75
+ program
76
+ .command('detect')
77
+ .description('Detect project stack, architecture, and patterns')
78
+ .option('-p, --path <path>', 'Project path (default: current directory)')
79
+ .option('-v, --verbose', 'Show detailed detection results')
80
+ .option('--no-save', 'Do not save results to .morph/project/')
81
+ .action(detectCommand);
82
+
83
+ program
84
+ .command('detect-agents <input...>')
85
+ .description('Detect which agents to activate based on keywords in user input')
86
+ .option('-v, --verbose', 'Show detailed detection results')
87
+ .option('-j, --json', 'Output full result as JSON')
88
+ .option('-i, --ids-only', 'Output only agent IDs (one per line)')
89
+ .action(detectAgentsCommand);
90
+
91
+ program
92
+ .command('sync')
93
+ .description('Sync standards from feature decisions')
94
+ .option('-p, --path <path>', 'Project path (default: current directory)')
95
+ .option('--dry-run', 'Show what would be synced without updating files')
96
+ .action(syncCommand);
97
+
98
+ // Story-driven development commands
99
+ const storyCommand = program
100
+ .command('story')
101
+ .description('Story-driven development commands');
102
+
103
+ storyCommand
104
+ .command('create <feature> <story-id>')
105
+ .description('Create a new story with auto-injected Dev Notes')
106
+ .option('--title <title>', 'Story title')
107
+ .option('--epic <epic>', 'Epic name')
108
+ .option('--context <context>', 'Story context')
109
+ .option('--tasks <tasks>', 'Comma-separated tasks')
110
+ .option('--dry-run', 'Preview without writing file')
111
+ .action(createStoryCommand);
112
+
113
+ storyCommand
114
+ .command('shard <feature>')
115
+ .description('Shard spec.md into manageable chunks (90% token savings)')
116
+ .option('--dry-run', 'Preview shards without writing files')
117
+ .option('--verbose', 'Show detailed shard info')
118
+ .action(shardSpecCommand);
119
+
120
+ storyCommand
121
+ .command('status <feature> [action] [story-id]')
122
+ .description('Manage sprint status (show | start | qa | done | next)')
123
+ .action(sprintStatusCommand);
124
+
125
+ // State management commands
126
+ program
127
+ .command('state <action> [args...]')
128
+ .description('Manage state.json (init | get | set | checkpoint | list | add-agent | remove-agent | mark-output)')
129
+ .option('--force', 'Force overwrite (init command)')
130
+ .option('--project <name>', 'Project name (init command)')
131
+ .option('--type <type>', 'Project type (init command)')
132
+ .option('--json', 'Output as JSON (get command)')
133
+ .action((action, args, options) => stateCommand(action, args, options));
134
+
135
+ // Task management commands (MORPH-SPEC 3.0)
136
+ const taskCommand = program
137
+ .command('task')
138
+ .description('Manage feature tasks (done | start | next)');
139
+
140
+ taskCommand
141
+ .command('done <feature> <task-ids...>')
142
+ .description('Mark tasks as completed (runs validation first)')
143
+ .option('--skip-validation', 'Skip code validation (not recommended)')
144
+ .action((feature, taskIds, options) => taskDoneCommand(feature, taskIds, options));
145
+
146
+ taskCommand
147
+ .command('start <feature> <task-id>')
148
+ .description('Start a task (mark as in_progress)')
149
+ .action((feature, taskId, options) => taskStartCommand(feature, taskId, options));
150
+
151
+ taskCommand
152
+ .command('next <feature>')
153
+ .description('Show next suggested task')
154
+ .action((feature, options) => taskNextCommand(feature, options));
155
+
156
+ // Generation commands
157
+ const generateCommand = program
158
+ .command('generate')
159
+ .description('Generate code from templates');
160
+
161
+ generateCommand
162
+ .command('design-system <ui-design-system-md>')
163
+ .description('Generate CSS + theme files from ui-design-system.md')
164
+ .option('--fluent', 'Generate only Fluent UI theme')
165
+ .option('--mud', 'Generate only MudBlazor theme')
166
+ .option('--both', 'Generate both themes (default)')
167
+ .option('--namespace <ns>', 'C# namespace (default: YourProject.Themes)')
168
+ .option('--css-output <path>', 'CSS output path (default: wwwroot/css/design-system.css)')
169
+ .option('--fluent-output <path>', 'Fluent theme output path (default: Themes/FluentDesignTheme.cs)')
170
+ .option('--mud-output <path>', 'MudBlazor theme output path (default: Themes/MudDesignTheme.cs)')
171
+ .option('--dry-run', 'Preview without writing files')
172
+ .action(generateDesignSystemCommand);
173
+
174
+ generateCommand
175
+ .command('recap <feature>')
176
+ .description('Auto-generate recap.md from project data (state, validation, contracts)')
177
+ .option('--quiet', 'Suppress output')
178
+ .action(async (feature, options) => {
179
+ const { generateRecap } = await import('../src/lib/recap-generator.js');
180
+ await generateRecap('.', feature, options);
181
+ });
182
+
183
+ generateCommand
184
+ .command('context [feature]')
185
+ .description('Generate CONTEXT.md with full project data for Claude Code')
186
+ .action(async (feature) => {
187
+ await generateContextCommand('.', feature);
188
+ });
189
+
190
+ // Validation commands (Sprint 4: Continuous Validation)
191
+ program
192
+ .command('validate [validator]')
193
+ .description('Run project validations (all | packages | architecture | contrast)')
194
+ .option('-v, --verbose', 'Show detailed output')
195
+ .option('--auto-fix, --fix', 'Auto-fix issues where possible')
196
+ .option('--no-fail', 'Don\'t exit with error code')
197
+ .option('-i, --insights', 'Show learning insights')
198
+ .option('--wcag-aaa', 'Use WCAG AAA standard (stricter)')
199
+ .action((validator, options) => {
200
+ const args = validator ? [validator] : ['all'];
201
+ if (options.verbose) args.push('--verbose');
202
+ if (options.autoFix) args.push('--auto-fix');
203
+ if (options.noFail) args.push('--no-fail');
204
+ if (options.insights) args.push('--insights');
205
+ if (options.wcagAaa) args.push('--wcag-aaa');
206
+ validateCommand(args);
207
+ });
208
+
209
+ // Fluent UI Blazor validation commands
210
+ program
211
+ .command('validate-blazor [path]')
212
+ .description('Validate Fluent UI Blazor patterns and icons')
213
+ .option('-v, --verbose', 'Show detailed output')
214
+ .option('--fix', 'Auto-fix issues where possible')
215
+ .action(validateBlazorCommand);
216
+
217
+ program
218
+ .command('lint-fluent [path]')
219
+ .description('Lint Fluent UI patterns for common issues')
220
+ .option('-v, --verbose', 'Show detailed output')
221
+ .action(lintFluentCommand);
222
+
223
+ program
224
+ .command('analyze-blazor-concurrency [path]')
225
+ .description('Analyze Blazor Server code for DbContext concurrency issues')
226
+ .option('-v, --verbose', 'Show detailed output')
227
+ .action(analyzeBlazorConcurrencyCommand);
228
+
229
+ program
230
+ .command('validate-blazor-state [path]')
231
+ .description('Validate Blazor Server session state patterns')
232
+ .option('-v, --verbose', 'Show detailed output')
233
+ .action(validateBlazorStateCommand);
234
+
235
+ program
236
+ .command('validate-css [path]')
237
+ .description('Validate CSS classes used in Razor files exist in CSS files')
238
+ .option('-v, --verbose', 'Show detailed output')
239
+ .option('--generate-stub', 'Generate a CSS stub file with missing classes')
240
+ .option('--include-utilities', 'Include utility classes (Tailwind, Bootstrap) in validation')
241
+ .action(validateCssCommand);
242
+
243
+ // Learning commands (Sprint 4: Learning System)
244
+ const learnCommand = program
245
+ .command('learn')
246
+ .description('AI learning system commands');
247
+
248
+ learnCommand
249
+ .command('analyze')
250
+ .description('Learn from project history (decisions.md files)')
251
+ .option('-v, --verbose', 'Show detailed learning progress')
252
+ .action(async (options) => {
253
+ const learner = new LearningSystem('.');
254
+ await learner.learnFromProject();
255
+
256
+ if (options.verbose) {
257
+ learner.formatInsights();
258
+ }
259
+ });
260
+
261
+ learnCommand
262
+ .command('insights')
263
+ .description('Show AI insights and patterns')
264
+ .option('--json', 'Output as JSON')
265
+ .action((options) => {
266
+ const learner = new LearningSystem('.');
267
+
268
+ if (options.json) {
269
+ console.log(JSON.stringify(learner.getInsightsSummary(), null, 2));
270
+ } else {
271
+ learner.formatInsights();
272
+ }
273
+ });
274
+
275
+ learnCommand
276
+ .command('suggest [category]')
277
+ .description('Get AI suggestions for a category (uiLibrary | architecture | infrastructure | authentication | stateManagement | testing)')
278
+ .option('--json', 'Output as JSON')
279
+ .action((category, options) => {
280
+ const learner = new LearningSystem('.');
281
+
282
+ if (category) {
283
+ const suggestion = learner.getSuggestion(category);
284
+ if (options.json) {
285
+ console.log(JSON.stringify(suggestion, null, 2));
286
+ } else {
287
+ console.log(chalk.cyan(`\n💡 Suggestion for ${category}:\n`));
288
+ if (suggestion.confidence === 'none') {
289
+ console.log(chalk.yellow(` ${suggestion.reason}`));
290
+ } else {
291
+ console.log(chalk.white(` → ${suggestion.suggestion} (${suggestion.percentage}% confidence)`));
292
+ console.log(chalk.gray(` ${suggestion.reason}`));
293
+ }
294
+ console.log('');
295
+ }
296
+ } else {
297
+ const suggestions = learner.getAllSuggestions();
298
+ if (options.json) {
299
+ console.log(JSON.stringify(suggestions, null, 2));
300
+ } else {
301
+ learner.formatSuggestions(suggestions);
302
+ }
303
+ }
304
+ });
305
+
306
+ learnCommand
307
+ .command('reset')
308
+ .description('Reset knowledge base (clear all learned patterns)')
309
+ .option('--force', 'Skip confirmation')
310
+ .action((options) => {
311
+ if (!options.force) {
312
+ console.log(chalk.yellow('\n⚠️ This will delete all learned patterns and preferences.'));
313
+ console.log(chalk.gray(' Run with --force to confirm.\n'));
314
+ process.exit(1);
315
+ }
316
+
317
+ const learner = new LearningSystem('.');
318
+ learner.reset();
319
+ console.log(chalk.green('\n✅ Knowledge base reset\n'));
320
+ });
321
+
322
+ // Troubleshooting command
323
+ program
324
+ .command('troubleshoot <keywords...>')
325
+ .alias('ts')
326
+ .description('Search troubleshooting solutions for common errors')
327
+ .option('--category <cat>', 'Filter by category (blazor, efcore, azure, auth, deploy)')
328
+ .option('-v, --verbose', 'Show full solution content')
329
+ .option('--list-categories', 'List available categories')
330
+ .action(troubleshootCommand);
331
+
332
+ // Phase management commands
333
+ const phaseCommand = program
334
+ .command('phase')
335
+ .description('Phase management (advance | validate)');
336
+
337
+ phaseCommand
338
+ .command('advance <feature>')
339
+ .description('Validate current phase and advance to next')
340
+ .option('--skip-optional', 'Skip optional phases (uiux, sync)')
341
+ .action((feature, options) => advancePhaseCommand(feature, options));
342
+
343
+ // Phase validation command (also available as standalone)
344
+ program
345
+ .command('validate-phase <feature> <phase>')
346
+ .description('Validate prerequisites before advancing to a phase')
347
+ .option('-v, --verbose', 'Show detailed output')
348
+ .action(validatePhaseCommand);
349
+
350
+ // Session summary command
351
+ program
352
+ .command('session-summary <feature>')
353
+ .alias('summary')
354
+ .description('Show summary of current session (phases, decisions, progress)')
355
+ .option('--json', 'Output as JSON')
356
+ .action(sessionSummaryCommand);
357
+
358
+ // Rollback phase command
359
+ program
360
+ .command('rollback <feature> <phase>')
361
+ .description('Rollback feature to a previous phase (marks outputs as draft)')
362
+ .option('--force', 'Skip confirmation')
363
+ .option('-v, --verbose', 'Show detailed output')
364
+ .action(rollbackPhaseCommand);
365
+
366
+ program.parse();