@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
@@ -0,0 +1,291 @@
1
+ /**
2
+ * MORPH-SPEC Session Summary Command
3
+ *
4
+ * Shows a comprehensive summary of the current session including:
5
+ * - Phases completed
6
+ * - Decisions taken
7
+ * - Progress on tasks
8
+ * - Next steps
9
+ *
10
+ * Usage:
11
+ * morph-spec session-summary <feature-name>
12
+ * morph-spec summary <feature-name>
13
+ */
14
+
15
+ import fs from 'fs';
16
+ import path from 'path';
17
+ import chalk from 'chalk';
18
+ import { loadState, getFeature } from '../lib/state-manager.js';
19
+
20
+ // Phase order for display
21
+ const PHASE_ORDER = [
22
+ { key: 'proposal', name: 'FASE 0: PROPOSAL', emoji: '📝' },
23
+ { key: 'setup', name: 'FASE 1: SETUP', emoji: '⚙️' },
24
+ { key: 'uiux', name: 'FASE 1.5: UI/UX', emoji: '🎨', optional: true },
25
+ { key: 'design', name: 'FASE 2: DESIGN', emoji: '📐' },
26
+ { key: 'clarify', name: 'FASE 3: CLARIFY', emoji: '❓' },
27
+ { key: 'tasks', name: 'FASE 4: TASKS', emoji: '📋' },
28
+ { key: 'implement', name: 'FASE 5: IMPLEMENT', emoji: '🔨' },
29
+ { key: 'sync', name: 'FASE 6: SYNC', emoji: '🔄', optional: true }
30
+ ];
31
+
32
+ /**
33
+ * Get phase index for comparison
34
+ */
35
+ function getPhaseIndex(phaseKey) {
36
+ return PHASE_ORDER.findIndex(p => p.key === phaseKey);
37
+ }
38
+
39
+ /**
40
+ * Read decisions from decisions.md
41
+ */
42
+ function readDecisions(featurePath) {
43
+ const decisionsPath = path.join(featurePath, 'decisions.md');
44
+ if (!fs.existsSync(decisionsPath)) return [];
45
+
46
+ try {
47
+ const content = fs.readFileSync(decisionsPath, 'utf-8');
48
+ const decisions = [];
49
+
50
+ // Parse ADR sections
51
+ const adrMatches = content.matchAll(/##\s+ADR[- ]?\d*:?\s*(.+?)(?=\n##|\n$|$)/gis);
52
+ for (const match of adrMatches) {
53
+ const title = match[1].split('\n')[0].trim();
54
+ decisions.push(title);
55
+ }
56
+
57
+ // Also parse simple decisions format
58
+ const simpleMatches = content.matchAll(/[-*]\s+\*\*(.+?)\*\*:\s*(.+)/g);
59
+ for (const match of simpleMatches) {
60
+ decisions.push(`${match[1]}: ${match[2]}`);
61
+ }
62
+
63
+ return decisions.slice(0, 10); // Limit to 10
64
+ } catch {
65
+ return [];
66
+ }
67
+ }
68
+
69
+ /**
70
+ * Check which outputs exist
71
+ */
72
+ function checkOutputs(featurePath) {
73
+ const outputs = [
74
+ { file: 'proposal.md', name: 'Proposal' },
75
+ { file: 'spec.md', name: 'Spec' },
76
+ { file: 'contracts.cs', name: 'Contracts' },
77
+ { file: 'ui-design-system.md', name: 'UI Design System' },
78
+ { file: 'ui-mockups.md', name: 'UI Mockups' },
79
+ { file: 'ui-components.md', name: 'UI Components' },
80
+ { file: 'ui-flows.md', name: 'UI Flows' },
81
+ { file: 'decisions.md', name: 'Decisions' },
82
+ { file: 'recap.md', name: 'Recap' }
83
+ ];
84
+
85
+ return outputs.map(o => ({
86
+ ...o,
87
+ exists: fs.existsSync(path.join(featurePath, o.file))
88
+ }));
89
+ }
90
+
91
+ /**
92
+ * Generate progress bar
93
+ */
94
+ function progressBar(completed, total, width = 30) {
95
+ if (total === 0) return chalk.gray('[' + '░'.repeat(width) + '] 0%');
96
+
97
+ const percentage = Math.round((completed / total) * 100);
98
+ const filled = Math.round((completed / total) * width);
99
+ const empty = width - filled;
100
+
101
+ const bar = '█'.repeat(filled) + '░'.repeat(empty);
102
+ const color = percentage === 100 ? chalk.green : percentage > 50 ? chalk.yellow : chalk.cyan;
103
+
104
+ return color(`[${bar}] ${percentage}%`);
105
+ }
106
+
107
+ /**
108
+ * Get next steps suggestions
109
+ */
110
+ function getNextSteps(feature, currentPhaseIndex) {
111
+ const steps = [];
112
+
113
+ if (!feature) {
114
+ steps.push('Run: morph-spec state set <feature> phase proposal');
115
+ return steps;
116
+ }
117
+
118
+ const nextPhase = PHASE_ORDER[currentPhaseIndex + 1];
119
+
120
+ if (feature.tasks?.total > 0 && feature.tasks?.completed < feature.tasks?.total) {
121
+ steps.push(`Continue implementing tasks (${feature.tasks.completed}/${feature.tasks.total} done)`);
122
+ }
123
+
124
+ if (nextPhase) {
125
+ steps.push(`Advance to ${nextPhase.name}`);
126
+ }
127
+
128
+ if (feature.phase === 'implement' && feature.tasks?.completed === feature.tasks?.total) {
129
+ steps.push('Generate recap.md');
130
+ steps.push('Consider running FASE 6: SYNC to promote decisions');
131
+ }
132
+
133
+ return steps;
134
+ }
135
+
136
+ /**
137
+ * Main command handler
138
+ */
139
+ export async function sessionSummaryCommand(featureName, options = {}) {
140
+ const featurePath = path.join(process.cwd(), '.morph/project/outputs', featureName);
141
+
142
+ // Header
143
+ console.log(chalk.cyan('\n╔════════════════════════════════════════════════════════════╗'));
144
+ console.log(chalk.cyan(`║ 📊 SESSION SUMMARY: ${featureName.padEnd(35)}║`));
145
+ console.log(chalk.cyan('╚════════════════════════════════════════════════════════════╝\n'));
146
+
147
+ // Get feature from state
148
+ let feature = null;
149
+ try {
150
+ feature = getFeature(featureName);
151
+ } catch {
152
+ // State may not exist
153
+ }
154
+
155
+ // JSON output mode
156
+ if (options.json) {
157
+ const outputs = checkOutputs(featurePath);
158
+ const decisions = readDecisions(featurePath);
159
+ const summary = {
160
+ feature: featureName,
161
+ status: feature?.status || 'unknown',
162
+ phase: feature?.phase || 'unknown',
163
+ workflow: feature?.workflow || 'auto',
164
+ agents: feature?.activeAgents || [],
165
+ tasks: feature?.tasks || { total: 0, completed: 0 },
166
+ checkpoints: feature?.checkpoints || [],
167
+ outputs: outputs.filter(o => o.exists).map(o => o.name),
168
+ decisions,
169
+ skippedPhases: feature?.skippedPhases || []
170
+ };
171
+ console.log(JSON.stringify(summary, null, 2));
172
+ return;
173
+ }
174
+
175
+ // Check if feature directory exists
176
+ if (!fs.existsSync(featurePath)) {
177
+ console.log(chalk.yellow(' ⚠️ Feature directory not found'));
178
+ console.log(chalk.gray(` Expected: ${featurePath}\n`));
179
+
180
+ if (feature) {
181
+ console.log(chalk.gray(' State exists but no outputs directory.'));
182
+ console.log(chalk.gray(` Phase: ${feature.phase}`));
183
+ }
184
+ return;
185
+ }
186
+
187
+ // Current Status
188
+ const currentPhaseIndex = feature ? getPhaseIndex(feature.phase) : -1;
189
+
190
+ console.log(chalk.bold('📌 Current Status'));
191
+ console.log(chalk.gray('─'.repeat(50)));
192
+ console.log(` Phase: ${chalk.cyan(feature?.phase || 'unknown')}`);
193
+ console.log(` Status: ${chalk.cyan(feature?.status || 'unknown')}`);
194
+ console.log(` Workflow: ${chalk.cyan(feature?.workflow || 'auto')}`);
195
+ console.log('');
196
+
197
+ // Phases Progress
198
+ console.log(chalk.bold('🔄 Phases Progress'));
199
+ console.log(chalk.gray('─'.repeat(50)));
200
+
201
+ for (let i = 0; i < PHASE_ORDER.length; i++) {
202
+ const phase = PHASE_ORDER[i];
203
+ let status;
204
+ let color;
205
+
206
+ const isSkipped = feature?.skippedPhases?.includes(phase.key);
207
+
208
+ if (isSkipped) {
209
+ status = 'SKIP';
210
+ color = chalk.gray;
211
+ } else if (i < currentPhaseIndex) {
212
+ status = '✓';
213
+ color = chalk.green;
214
+ } else if (i === currentPhaseIndex) {
215
+ status = '▸';
216
+ color = chalk.cyan;
217
+ } else {
218
+ status = ' ';
219
+ color = chalk.gray;
220
+ }
221
+
222
+ const optionalTag = phase.optional ? chalk.gray(' (optional)') : '';
223
+ console.log(` ${color(status)} ${phase.emoji} ${color(phase.name)}${optionalTag}`);
224
+ }
225
+ console.log('');
226
+
227
+ // Tasks Progress
228
+ if (feature?.tasks && feature.tasks.total > 0) {
229
+ console.log(chalk.bold('📋 Tasks Progress'));
230
+ console.log(chalk.gray('─'.repeat(50)));
231
+ console.log(` ${progressBar(feature.tasks.completed, feature.tasks.total)}`);
232
+ console.log(` ${chalk.gray(`${feature.tasks.completed}/${feature.tasks.total} tasks completed`)}`);
233
+ console.log('');
234
+ }
235
+
236
+ // Active Agents
237
+ if (feature?.activeAgents && feature.activeAgents.length > 0) {
238
+ console.log(chalk.bold('🤖 Active Agents'));
239
+ console.log(chalk.gray('─'.repeat(50)));
240
+ feature.activeAgents.forEach(agent => {
241
+ console.log(` • ${chalk.cyan(agent)}`);
242
+ });
243
+ console.log('');
244
+ }
245
+
246
+ // Outputs
247
+ const outputs = checkOutputs(featurePath);
248
+ const createdOutputs = outputs.filter(o => o.exists);
249
+
250
+ if (createdOutputs.length > 0) {
251
+ console.log(chalk.bold('📄 Outputs Created'));
252
+ console.log(chalk.gray('─'.repeat(50)));
253
+ createdOutputs.forEach(o => {
254
+ console.log(` ${chalk.green('✓')} ${o.name}`);
255
+ });
256
+ console.log('');
257
+ }
258
+
259
+ // Decisions Taken
260
+ const decisions = readDecisions(featurePath);
261
+ if (decisions.length > 0) {
262
+ console.log(chalk.bold('🎯 Decisions Taken'));
263
+ console.log(chalk.gray('─'.repeat(50)));
264
+ decisions.forEach(d => {
265
+ console.log(` • ${chalk.white(d)}`);
266
+ });
267
+ console.log('');
268
+ }
269
+
270
+ // Checkpoints
271
+ if (feature?.checkpoints && feature.checkpoints.length > 0) {
272
+ console.log(chalk.bold('🏁 Checkpoints'));
273
+ console.log(chalk.gray('─'.repeat(50)));
274
+ feature.checkpoints.slice(-5).forEach(cp => {
275
+ const date = new Date(cp.timestamp).toLocaleString();
276
+ console.log(` ${chalk.gray(date)} - ${cp.note}`);
277
+ });
278
+ console.log('');
279
+ }
280
+
281
+ // Next Steps
282
+ const nextSteps = getNextSteps(feature, currentPhaseIndex);
283
+ if (nextSteps.length > 0) {
284
+ console.log(chalk.bold('➡️ Next Steps'));
285
+ console.log(chalk.gray('─'.repeat(50)));
286
+ nextSteps.forEach((step, i) => {
287
+ console.log(` ${i + 1}. ${chalk.yellow(step)}`);
288
+ });
289
+ console.log('');
290
+ }
291
+ }
@@ -1,75 +1,78 @@
1
- /**
2
- * Task management commands
3
- * Wrapper for bin/task-manager.js (CommonJS) to ESM
4
- */
5
-
6
- import { spawn } from 'child_process';
7
- import { fileURLToPath } from 'url';
8
- import { dirname, join } from 'path';
9
- import chalk from 'chalk';
10
-
11
- const __dirname = dirname(fileURLToPath(import.meta.url));
12
- const taskManagerPath = join(__dirname, '..', '..', 'bin', 'task-manager.js');
13
-
14
- /**
15
- * Execute task-manager.js with given arguments
16
- */
17
- function executeTaskManager(args) {
18
- return new Promise((resolve, reject) => {
19
- const child = spawn('node', [taskManagerPath, ...args], {
20
- stdio: 'inherit',
21
- shell: true
22
- });
23
-
24
- child.on('close', (code) => {
25
- if (code === 0) {
26
- resolve();
27
- } else {
28
- reject(new Error(`Task manager exited with code ${code}`));
29
- }
30
- });
31
-
32
- child.on('error', (error) => {
33
- reject(error);
34
- });
35
- });
36
- }
37
-
38
- /**
39
- * Complete tasks command
40
- */
41
- export async function taskDoneCommand(featureName, taskIds, options) {
42
- try {
43
- const args = ['done', featureName, ...taskIds];
44
- await executeTaskManager(args);
45
- } catch (error) {
46
- console.error(chalk.red(`Error: ${error.message}`));
47
- process.exit(1);
48
- }
49
- }
50
-
51
- /**
52
- * Start task command
53
- */
54
- export async function taskStartCommand(featureName, taskId, options) {
55
- try {
56
- const args = ['start', featureName, taskId];
57
- await executeTaskManager(args);
58
- } catch (error) {
59
- console.error(chalk.red(`Error: ${error.message}`));
60
- process.exit(1);
61
- }
62
- }
63
-
64
- /**
65
- * Get next task command
66
- */
67
- export async function taskNextCommand(featureName, options) {
68
- try {
69
- const args = ['next', featureName];
70
- await executeTaskManager(args);
71
- } catch (error) {
72
- console.error(chalk.red(`Error: ${error.message}`));
73
- process.exit(1);
74
- }
75
- }
1
+ /**
2
+ * Task management commands
3
+ * Wrapper for bin/task-manager.js (CommonJS) to ESM
4
+ */
5
+
6
+ import { spawn } from 'child_process';
7
+ import { fileURLToPath } from 'url';
8
+ import { dirname, join } from 'path';
9
+ import chalk from 'chalk';
10
+
11
+ const __dirname = dirname(fileURLToPath(import.meta.url));
12
+ const taskManagerPath = join(__dirname, '..', '..', 'bin', 'task-manager.js');
13
+
14
+ /**
15
+ * Execute task-manager.js with given arguments
16
+ */
17
+ function executeTaskManager(args) {
18
+ return new Promise((resolve, reject) => {
19
+ const child = spawn('node', [taskManagerPath, ...args], {
20
+ stdio: 'inherit',
21
+ shell: true
22
+ });
23
+
24
+ child.on('close', (code) => {
25
+ if (code === 0) {
26
+ resolve();
27
+ } else {
28
+ reject(new Error(`Task manager exited with code ${code}`));
29
+ }
30
+ });
31
+
32
+ child.on('error', (error) => {
33
+ reject(error);
34
+ });
35
+ });
36
+ }
37
+
38
+ /**
39
+ * Complete tasks command
40
+ */
41
+ export async function taskDoneCommand(featureName, taskIds, options) {
42
+ try {
43
+ const args = ['done', featureName, ...taskIds];
44
+ if (options.skipValidation) {
45
+ args.push('--skip-validation');
46
+ }
47
+ await executeTaskManager(args);
48
+ } catch (error) {
49
+ console.error(chalk.red(`Error: ${error.message}`));
50
+ process.exit(1);
51
+ }
52
+ }
53
+
54
+ /**
55
+ * Start task command
56
+ */
57
+ export async function taskStartCommand(featureName, taskId, options) {
58
+ try {
59
+ const args = ['start', featureName, taskId];
60
+ await executeTaskManager(args);
61
+ } catch (error) {
62
+ console.error(chalk.red(`Error: ${error.message}`));
63
+ process.exit(1);
64
+ }
65
+ }
66
+
67
+ /**
68
+ * Get next task command
69
+ */
70
+ export async function taskNextCommand(featureName, options) {
71
+ try {
72
+ const args = ['next', featureName];
73
+ await executeTaskManager(args);
74
+ } catch (error) {
75
+ console.error(chalk.red(`Error: ${error.message}`));
76
+ process.exit(1);
77
+ }
78
+ }
@@ -0,0 +1,222 @@
1
+ /**
2
+ * Troubleshoot Command
3
+ * Search for solutions to common problems
4
+ *
5
+ * Usage: morph-spec troubleshoot <keywords...>
6
+ */
7
+
8
+ import { searchIndex, getCategories } from '../lib/troubleshoot-index.js';
9
+ import { searchGrep } from '../lib/troubleshoot-grep.js';
10
+ import chalk from 'chalk';
11
+
12
+ // Severity colors and icons
13
+ const SEVERITY_CONFIG = {
14
+ critical: { color: chalk.red, icon: '🔴', label: 'CRITICAL' },
15
+ high: { color: chalk.yellow, icon: '🟠', label: 'HIGH' },
16
+ medium: { color: chalk.blue, icon: '🔵', label: 'MEDIUM' },
17
+ low: { color: chalk.gray, icon: '⚪', label: 'LOW' }
18
+ };
19
+
20
+ /**
21
+ * Format a single result for display
22
+ * @param {Object} result - Result object
23
+ * @param {boolean} verbose - Show full content
24
+ * @returns {string} Formatted output
25
+ */
26
+ function formatResult(result, verbose = false) {
27
+ const severity = SEVERITY_CONFIG[result.severity] || SEVERITY_CONFIG.medium;
28
+ const lines = [];
29
+
30
+ lines.push(chalk.gray('━'.repeat(50)));
31
+ lines.push('');
32
+ lines.push(`${severity.icon} ${severity.color.bold(severity.label)}: ${chalk.white.bold(result.title)}`);
33
+ lines.push('');
34
+
35
+ // File and section
36
+ lines.push(`${chalk.gray('📁 Arquivo:')} ${chalk.cyan(result.file)}`);
37
+ if (result.section) {
38
+ lines.push(`${chalk.gray('📂 Seção:')} ${result.section}`);
39
+ }
40
+ lines.push('');
41
+
42
+ // Cause
43
+ if (result.cause) {
44
+ lines.push(`${chalk.red('💡 Causa:')}`);
45
+ lines.push(` ${result.cause}`);
46
+ lines.push('');
47
+ }
48
+
49
+ // Solution
50
+ if (result.solution) {
51
+ lines.push(`${chalk.green('✅ Solução:')}`);
52
+ lines.push(` ${chalk.white(result.solution)}`);
53
+ lines.push('');
54
+ }
55
+
56
+ // Content preview (for grep results or verbose mode)
57
+ if (verbose && result.content) {
58
+ lines.push(`${chalk.gray('📝 Conteúdo:')}`);
59
+ const contentLines = result.content.split('\n').slice(0, 15);
60
+ contentLines.forEach(line => {
61
+ lines.push(` ${chalk.gray(line)}`);
62
+ });
63
+ lines.push('');
64
+ }
65
+
66
+ // Keywords matched
67
+ if (result.keywords && result.keywords.length > 0) {
68
+ const keywords = Array.isArray(result.keywords)
69
+ ? result.keywords.slice(0, 5).join(', ')
70
+ : result.keywords;
71
+ lines.push(`${chalk.gray('🏷️ Keywords:')} ${chalk.dim(keywords)}`);
72
+ }
73
+
74
+ // Source (index or grep)
75
+ if (result.source === 'grep') {
76
+ lines.push(`${chalk.gray('🔍 Fonte:')} ${chalk.dim('Busca em arquivos (grep)')}`);
77
+ }
78
+
79
+ lines.push('');
80
+
81
+ return lines.join('\n');
82
+ }
83
+
84
+ /**
85
+ * Format the summary footer
86
+ * @param {Object} stats - Search statistics
87
+ * @returns {string} Formatted summary
88
+ */
89
+ function formatSummary(stats) {
90
+ const lines = [];
91
+
92
+ lines.push(chalk.gray('━'.repeat(50)));
93
+ lines.push('');
94
+
95
+ if (stats.total === 0) {
96
+ lines.push(chalk.yellow('⚠️ Nenhum resultado encontrado no índice ou arquivos.'));
97
+ lines.push('');
98
+ lines.push(chalk.dim('💡 Dicas:'));
99
+ lines.push(chalk.dim(' • Tente termos mais específicos (ex: "NU1605" em vez de "error")'));
100
+ lines.push(chalk.dim(' • Use parte da mensagem de erro exata'));
101
+ lines.push(chalk.dim(' • Consulte a documentação: morph-spec read blazor-pitfalls.md'));
102
+ } else {
103
+ lines.push(`${chalk.green('✅')} Encontrado ${chalk.bold(stats.total)} resultado(s)`);
104
+
105
+ if (stats.fromIndex > 0) {
106
+ lines.push(` ${chalk.dim(`• ${stats.fromIndex} do índice de problemas conhecidos`)}`);
107
+ }
108
+ if (stats.fromGrep > 0) {
109
+ lines.push(` ${chalk.dim(`• ${stats.fromGrep} da busca em arquivos`)}`);
110
+ }
111
+ }
112
+
113
+ lines.push('');
114
+
115
+ return lines.join('\n');
116
+ }
117
+
118
+ /**
119
+ * List all categories
120
+ */
121
+ function listCategories() {
122
+ const categories = getCategories();
123
+
124
+ console.log('');
125
+ console.log(chalk.bold('📂 Categorias disponíveis:'));
126
+ console.log('');
127
+
128
+ for (const [id, category] of Object.entries(categories)) {
129
+ const name = typeof category === 'object' ? category.name : category;
130
+ const desc = typeof category === 'object' ? category.description : '';
131
+ console.log(` ${chalk.cyan(id.padEnd(12))} ${name}`);
132
+ if (desc) {
133
+ console.log(` ${' '.repeat(12)} ${chalk.dim(desc)}`);
134
+ }
135
+ }
136
+
137
+ console.log('');
138
+ console.log(chalk.dim('Uso: morph-spec troubleshoot --category efcore "sua busca"'));
139
+ console.log('');
140
+ }
141
+
142
+ /**
143
+ * Main troubleshoot command
144
+ * @param {string[]} keywords - Search keywords
145
+ * @param {Object} options - Command options
146
+ */
147
+ export async function troubleshootCommand(keywords, options = {}) {
148
+ // Handle --list-categories flag
149
+ if (options.listCategories) {
150
+ listCategories();
151
+ return;
152
+ }
153
+
154
+ // Validate keywords
155
+ if (!keywords || keywords.length === 0) {
156
+ console.log('');
157
+ console.log(chalk.yellow('⚠️ Por favor, forneça termos de busca.'));
158
+ console.log('');
159
+ console.log(chalk.dim('Exemplos:'));
160
+ console.log(chalk.dim(' morph-spec troubleshoot "blazor.web.js 404"'));
161
+ console.log(chalk.dim(' morph-spec troubleshoot DbContext concurrent'));
162
+ console.log(chalk.dim(' morph-spec troubleshoot NU1605 Azure.Identity'));
163
+ console.log('');
164
+ console.log(chalk.dim('Opções:'));
165
+ console.log(chalk.dim(' --category <cat> Filtrar por categoria (blazor, efcore, azure)'));
166
+ console.log(chalk.dim(' --verbose, -v Mostrar conteúdo completo'));
167
+ console.log(chalk.dim(' --list-categories Listar categorias disponíveis'));
168
+ console.log('');
169
+ return;
170
+ }
171
+
172
+ const searchTerms = Array.isArray(keywords) ? keywords : [keywords];
173
+
174
+ console.log('');
175
+ console.log(`${chalk.cyan('🔍')} Buscando soluções para: ${chalk.bold(`"${searchTerms.join(' ')}"`)}`);
176
+ console.log('');
177
+
178
+ // Search options
179
+ const searchOptions = {};
180
+ if (options.category) {
181
+ searchOptions.category = options.category;
182
+ console.log(chalk.dim(` Filtrando por categoria: ${options.category}`));
183
+ console.log('');
184
+ }
185
+
186
+ // Level 1: Search index
187
+ let indexResults = searchIndex(searchTerms, searchOptions);
188
+ indexResults = indexResults.map(r => ({ ...r, source: 'index' }));
189
+
190
+ // Level 2: Grep fallback (if few results)
191
+ let grepResults = [];
192
+ if (indexResults.length < 3) {
193
+ grepResults = searchGrep(searchTerms, searchOptions);
194
+ // Filter out duplicates (same file + section)
195
+ const indexKeys = new Set(indexResults.map(r => `${r.file}:${r.section}`));
196
+ grepResults = grepResults.filter(r => !indexKeys.has(`${r.file}:${r.section}`));
197
+ }
198
+
199
+ // Combine and limit results
200
+ const allResults = [...indexResults, ...grepResults].slice(0, 10);
201
+
202
+ // Display results
203
+ for (const result of allResults) {
204
+ console.log(formatResult(result, options.verbose));
205
+ }
206
+
207
+ // Display summary
208
+ console.log(formatSummary({
209
+ total: allResults.length,
210
+ fromIndex: indexResults.length,
211
+ fromGrep: grepResults.slice(0, 10 - indexResults.length).length
212
+ }));
213
+
214
+ // Hint for web search (handled by Claude Code slash command)
215
+ if (allResults.length === 0) {
216
+ console.log(chalk.dim('💡 Use /morph-troubleshoot no Claude Code para busca web em'));
217
+ console.log(chalk.dim(' GitHub Issues, Stack Overflow e Microsoft Learn.'));
218
+ console.log('');
219
+ }
220
+ }
221
+
222
+ export default troubleshootCommand;