@polymorphism-tech/morph-spec 4.10.6 → 4.10.8

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 (149) hide show
  1. package/CLAUDE.md +3 -0
  2. package/LICENSE +71 -71
  3. package/README.md +379 -379
  4. package/bin/morph-spec.js +89 -0
  5. package/bin/task-manager.js +59 -6
  6. package/claude-plugin.json +14 -14
  7. package/docs/CHEATSHEET.md +1 -1
  8. package/docs/QUICKSTART.md +206 -206
  9. package/framework/agents/README.md +14 -14
  10. package/framework/agents/architecture/standards-architect.md +159 -159
  11. package/framework/agents/frontend/blazor-builder.md +13 -0
  12. package/framework/agents/frontend/css-specialist.md +87 -0
  13. package/framework/agents/frontend/nextjs-expert.md +13 -0
  14. package/framework/agents/frontend/nextjs-ui-specialist.md +218 -0
  15. package/framework/agents/frontend/ui-ux-designer.md +80 -10
  16. package/framework/agents/infrastructure/azure-architect.md +149 -149
  17. package/framework/agents/infrastructure/infra-architect.md +48 -48
  18. package/framework/agents.json +2268 -2567
  19. package/framework/hooks/README.md +204 -204
  20. package/framework/hooks/claude-code/post-tool-use/dispatch.js +10 -5
  21. package/framework/hooks/claude-code/session-start/inject-morph-context.js +10 -24
  22. package/framework/hooks/shared/phase-utils.js +139 -139
  23. package/framework/hooks/shared/worktree-helpers.js +30 -8
  24. package/framework/rules/csharp-standards.md +13 -13
  25. package/framework/rules/frontend-standards.md +13 -13
  26. package/framework/rules/infrastructure-standards.md +16 -16
  27. package/framework/rules/testing-standards.md +14 -14
  28. package/framework/skills/README.md +0 -1
  29. package/framework/skills/level-0-meta/morph-brainstorming/SKILL.md +12 -0
  30. package/framework/skills/level-0-meta/morph-code-review-nextjs/references/review-example-nextjs.md +254 -254
  31. package/framework/skills/level-0-meta/morph-init/SKILL.md +88 -3
  32. package/framework/skills/level-1-workflows/morph-phase-clarify/SKILL.md +247 -247
  33. package/framework/skills/level-1-workflows/morph-phase-codebase-analysis/SKILL.md +270 -270
  34. package/framework/skills/level-1-workflows/morph-phase-design/SKILL.md +515 -499
  35. package/framework/skills/level-1-workflows/morph-phase-implement/SKILL.md +508 -471
  36. package/framework/skills/level-1-workflows/morph-phase-plan/SKILL.md +12 -1
  37. package/framework/skills/level-1-workflows/morph-phase-setup/SKILL.md +272 -258
  38. package/framework/skills/level-1-workflows/morph-phase-tasks/SKILL.md +317 -311
  39. package/framework/skills/level-1-workflows/morph-phase-uiux/SKILL.md +424 -323
  40. package/framework/skills/level-1-workflows/morph-scope-escalation/SKILL.md +1 -1
  41. package/framework/standards/STANDARDS.json +2040 -2040
  42. package/framework/standards/frontend/nextjs/motion-patterns.md +321 -0
  43. package/framework/standards/frontend/nextjs/nextjs-patterns.md +17 -17
  44. package/framework/templates/README.md +814 -814
  45. package/framework/templates/code/dotnet/contracts/Commands.cs +74 -74
  46. package/framework/templates/code/dotnet/contracts/Entities.cs +25 -25
  47. package/framework/templates/code/dotnet/contracts/Queries.cs +74 -74
  48. package/framework/templates/code/dotnet/contracts/README.md +74 -74
  49. package/framework/templates/code/dotnet/contracts/api-contracts.cs +173 -173
  50. package/framework/templates/code/dotnet/frontend/component.razor +239 -239
  51. package/framework/templates/code/dotnet/jobs/agent.cs +163 -163
  52. package/framework/templates/code/dotnet/jobs/job.cs +171 -171
  53. package/framework/templates/code/dotnet/test.cs +239 -239
  54. package/framework/templates/code/sql/rls-policy.sql +57 -57
  55. package/framework/templates/code/sql/supabase-migration.sql +100 -100
  56. package/framework/templates/code/sql/supabase-migration.template.sql +113 -113
  57. package/framework/templates/code/typescript/contracts.ts +168 -168
  58. package/framework/templates/context/CONTEXT.md +181 -181
  59. package/framework/templates/context/design-system.md +211 -0
  60. package/framework/templates/docs/proposal.md +182 -182
  61. package/framework/templates/docs/user-stories.md +34 -34
  62. package/framework/templates/examples/design-system-examples.md +357 -357
  63. package/framework/templates/examples/spec-examples.md +90 -90
  64. package/framework/templates/feature/decisions.md +187 -187
  65. package/framework/templates/feature/recap.md +146 -146
  66. package/framework/templates/feature/tasks.md +199 -199
  67. package/framework/templates/infrastructure/azure/README.md +286 -286
  68. package/framework/templates/infrastructure/azure/deploy-checklist.md +426 -426
  69. package/framework/templates/infrastructure/azure/parameters.dev.json +29 -29
  70. package/framework/templates/infrastructure/azure/parameters.prod.json +29 -29
  71. package/framework/templates/infrastructure/azure/parameters.staging.json +29 -29
  72. package/framework/templates/infrastructure/docker/docker-compose.template.yml +67 -67
  73. package/framework/templates/infrastructure/docker/dockerfile-api.dockerfile +38 -38
  74. package/framework/templates/infrastructure/docker/dockerfile-web.dockerfile +48 -48
  75. package/framework/templates/infrastructure/docker/easypanel.template.json +54 -54
  76. package/package.json +82 -82
  77. package/src/commands/agents/agent-metrics.js +174 -0
  78. package/src/commands/agents/audit-dispatch.js +82 -0
  79. package/src/commands/agents/detect-agents.js +275 -0
  80. package/src/commands/agents/dispatch-agents.js +41 -135
  81. package/src/commands/agents/index.js +13 -4
  82. package/src/commands/agents/manage-agents.js +352 -0
  83. package/src/commands/project/doctor.js +59 -0
  84. package/src/commands/project/install-plugin-cmd.js +28 -28
  85. package/src/commands/project/setup-infra-cmd.js +12 -12
  86. package/src/commands/project/update.js +1 -17
  87. package/src/commands/project/worktree.js +58 -2
  88. package/src/commands/state/advance-phase.js +11 -3
  89. package/src/commands/tasks/index.js +4 -4
  90. package/src/commands/templates/index.js +5 -5
  91. package/src/commands/utils/index.js +3 -3
  92. package/src/commands/validation/index.js +4 -4
  93. package/src/core/state/phase-state-machine.js +217 -217
  94. package/src/core/state/state-manager.js +81 -0
  95. package/src/lib/agents/agents-manager.js +349 -0
  96. package/src/lib/agents/metrics-calculator.js +125 -0
  97. package/src/lib/agents/output-collector.js +75 -0
  98. package/src/lib/generators/context-generator.js +8 -7
  99. package/src/lib/generators/design-system-generator.js +298 -298
  100. package/src/lib/generators/index.js +10 -10
  101. package/src/lib/generators/metadata-extractor.js +387 -387
  102. package/src/lib/stack-filter.js +65 -65
  103. package/src/lib/standards/index.js +7 -7
  104. package/src/lib/standards/standards-context-injector.js +302 -302
  105. package/src/lib/tasks/task-parser.js +94 -3
  106. package/src/lib/validators/architecture/architecture-validator.js +387 -387
  107. package/src/lib/validators/architecture/index.js +7 -7
  108. package/src/lib/validators/blazor/blazor-concurrency-analyzer.js +316 -316
  109. package/src/lib/validators/blazor/blazor-state-validator.js +279 -279
  110. package/src/lib/validators/blazor/blazor-validator.js +369 -369
  111. package/src/lib/validators/blazor/index.js +9 -9
  112. package/src/lib/validators/checkpoint-persistence.js +39 -0
  113. package/src/lib/validators/content/content-validator.js +287 -279
  114. package/src/lib/validators/content/index.js +7 -7
  115. package/src/lib/validators/contracts/index.js +7 -7
  116. package/src/lib/validators/css/css-validator.js +352 -352
  117. package/src/lib/validators/css/index.js +7 -7
  118. package/src/lib/validators/design-system/design-system-validator.js +231 -231
  119. package/src/lib/validators/design-system/index.js +7 -7
  120. package/src/lib/validators/nextjs/index.js +6 -6
  121. package/src/lib/validators/nextjs/next-component-validator.js +183 -183
  122. package/src/lib/validators/packages/index.js +7 -7
  123. package/src/lib/validators/packages/package-validator.js +360 -360
  124. package/src/lib/validators/shared/index.js +12 -12
  125. package/src/lib/validators/shared/issue-counter.js +18 -18
  126. package/src/lib/validators/shared/result-formatter.js +124 -124
  127. package/src/lib/validators/spec-validator.js +2 -2
  128. package/src/lib/validators/ui/index.js +7 -7
  129. package/src/lib/validators/ui/ui-contrast-validator.js +422 -422
  130. package/src/lib/validators/validation-runner.js +20 -0
  131. package/src/scripts/global-install.js +58 -58
  132. package/src/scripts/install-plugin.js +126 -126
  133. package/src/scripts/setup-infra.js +1 -17
  134. package/src/utils/agent-id-mapper.js +11 -0
  135. package/src/utils/agents-installer.js +40 -8
  136. package/src/utils/claude-md-injector.js +90 -90
  137. package/src/utils/claude-settings-manager.js +1 -1
  138. package/src/utils/file-copier.js +200 -196
  139. package/src/utils/hooks-installer.js +556 -739
  140. package/src/utils/logger.js +32 -32
  141. package/src/utils/skills-installer.js +178 -178
  142. package/src/utils/tier-helpers.js +24 -0
  143. package/src/utils/version-checker.js +175 -175
  144. package/framework/agents/architecture/po-pm-advisor.md +0 -203
  145. package/framework/hooks/claude-code/user-prompt/set-terminal-title.js +0 -68
  146. package/framework/skills/level-1-workflows/morph-phase-implement/.morph/logs/activity.json +0 -38
  147. package/framework/skills/level-1-workflows/morph-phase-tasks/.morph/logs/activity.json +0 -14
  148. package/framework/templates/.idea/morph-templates.xml +0 -92
  149. package/framework/templates/.vscode/morph-templates.code-snippets +0 -186
@@ -1,9 +1,9 @@
1
- /**
2
- * Blazor Validators
3
- *
4
- * Validators specific to Blazor Server and Fluent UI Blazor patterns.
5
- */
6
-
7
- export * from './blazor-validator.js';
8
- export * from './blazor-state-validator.js';
9
- export * from './blazor-concurrency-analyzer.js';
1
+ /**
2
+ * Blazor Validators
3
+ *
4
+ * Validators specific to Blazor Server and Fluent UI Blazor patterns.
5
+ */
6
+
7
+ export * from './blazor-validator.js';
8
+ export * from './blazor-state-validator.js';
9
+ export * from './blazor-concurrency-analyzer.js';
@@ -0,0 +1,39 @@
1
+ /**
2
+ * Checkpoint Validation Persistence
3
+ *
4
+ * Persists checkpoint validation results to disk for traceability.
5
+ * Each checkpoint writes a JSON file to:
6
+ * .morph/features/{feature}/5-implement/validations/checkpoint-{N}.json
7
+ */
8
+
9
+ import { mkdirSync, writeFileSync } from 'fs';
10
+ import { join } from 'path';
11
+
12
+ /**
13
+ * Persist a checkpoint validation result to disk.
14
+ *
15
+ * @param {string} projectPath - Project root
16
+ * @param {string} featureName - Feature name
17
+ * @param {{ checkpointNum: number, timestamp: string, passed: boolean, validators: Object, summary: string, feature?: string, phase?: string }} result - Validation result
18
+ * @returns {string} Path to the saved JSON file
19
+ */
20
+ export function persistCheckpointValidation(projectPath, featureName, result) {
21
+ const dir = join(projectPath, `.morph/features/${featureName}/5-implement/validations`);
22
+ mkdirSync(dir, { recursive: true });
23
+
24
+ const filename = `checkpoint-${result.checkpointNum}.json`;
25
+ const filePath = join(dir, filename);
26
+
27
+ const output = {
28
+ checkpointNum: result.checkpointNum,
29
+ timestamp: result.timestamp || new Date().toISOString(),
30
+ passed: result.passed,
31
+ validators: result.validators || {},
32
+ summary: result.summary || '',
33
+ feature: result.feature || featureName,
34
+ phase: result.phase || 'implement',
35
+ };
36
+
37
+ writeFileSync(filePath, JSON.stringify(output, null, 2), 'utf8');
38
+ return filePath;
39
+ }
@@ -1,279 +1,287 @@
1
- import { readFileSync, existsSync } from 'fs';
2
-
3
- /**
4
- * Content Validator - Validates structure and content of output files
5
- *
6
- * Ensures spec.md, tasks.json, and other outputs have required sections
7
- * and proper structure before allowing phase transitions.
8
- */
9
-
10
- /**
11
- * Validate spec.md structure
12
- * @param {string} specPath - Path to spec.md file
13
- * @returns {Object} Validation result
14
- */
15
- export function validateSpecContent(specPath) {
16
- if (!existsSync(specPath)) {
17
- return {
18
- valid: false,
19
- missing: ['File does not exist'],
20
- errors: ['Spec file not found at: ' + specPath]
21
- };
22
- }
23
-
24
- const content = readFileSync(specPath, 'utf8');
25
-
26
- // Required sections for a complete spec (prefix-match to handle variants like
27
- // "## Functional Requirements" and "## Technical Architecture")
28
- const requiredSections = [
29
- '## Overview',
30
- '## Functional Requirements',
31
- '## Technical',
32
- '## Data Model',
33
- ];
34
-
35
- const lines = content.split('\n');
36
- const missing = requiredSections.filter(section =>
37
- !lines.some(line => line.startsWith(section))
38
- );
39
-
40
- // Additional quality checks
41
- const errors = [];
42
- const warnings = [];
43
-
44
- // Check minimum content length
45
- if (content.length < 500) {
46
- warnings.push('Spec seems very short (< 500 characters). Consider adding more detail.');
47
- }
48
-
49
- // Check for placeholder text that should be replaced
50
- const placeholders = ['TODO', 'TBD', 'PLACEHOLDER', '{{'];
51
- placeholders.forEach(placeholder => {
52
- if (content.includes(placeholder)) {
53
- warnings.push(`Spec contains "${placeholder}" - ensure all placeholders are replaced`);
54
- }
55
- });
56
-
57
- // Check for anti-patterns mentioned in the plan
58
- if (content.toLowerCase().includes('manual azure portal')) {
59
- errors.push(
60
- 'Spec mentions manual Azure portal creation. ' +
61
- 'All infrastructure must be defined in Bicep (Infrastructure as Code).'
62
- );
63
- }
64
-
65
- if (content.toLowerCase().includes('create resource manually')) {
66
- errors.push(
67
- 'Spec mentions manual resource creation. ' +
68
- 'Use IaC (Bicep) for all infrastructure resources.'
69
- );
70
- }
71
-
72
- return {
73
- valid: missing.length === 0 && errors.length === 0,
74
- missing,
75
- errors,
76
- warnings,
77
- sections: {
78
- required: requiredSections.length,
79
- found: requiredSections.length - missing.length
80
- }
81
- };
82
- }
83
-
84
- /**
85
- * Validate tasks.md structure
86
- * @param {string} tasksPath - Path to tasks.md file
87
- * @returns {Object} Validation result
88
- */
89
- export function validateTasksContent(tasksPath) {
90
- if (!existsSync(tasksPath)) {
91
- return {
92
- valid: false,
93
- errors: ['Tasks file not found at: ' + tasksPath]
94
- };
95
- }
96
-
97
- const content = readFileSync(tasksPath, 'utf8');
98
- const errors = [];
99
- const warnings = [];
100
-
101
- // Extract task IDs from headings: ### T001 — title OR ### T001: title
102
- const taskRe = /^###\s+(T\d{3})\s*[—–:\-]\s*(.+)$/gm;
103
- const checkpointRe = /^###\s+(CHECKPOINT[_-]\d+)\s*[—–:\-]\s*(.+)$/gm;
104
-
105
- const tasks = [...content.matchAll(taskRe)];
106
- const checkpoints = [...content.matchAll(checkpointRe)];
107
-
108
- if (tasks.length === 0) {
109
- errors.push('No tasks found in tasks.md — expected headings like "### T001 — Title" or "### T001: Title"');
110
- return { valid: false, errors, warnings };
111
- }
112
-
113
- // Validate no duplicate IDs
114
- const ids = tasks.map(m => m[1]);
115
- const dupes = ids.filter((id, i) => ids.indexOf(id) !== i);
116
- dupes.forEach(id => errors.push(`Duplicate task ID: ${id}`));
117
-
118
- // Check for dependency references (look for "Dependencies: T###")
119
- const depRe = /\*\*Dependenc(?:y|ies):\*\*\s*([T\d, ]+)/gi;
120
- const allDepRefs = [...content.matchAll(depRe)]
121
- .flatMap(m => m[1].split(/[,\s]+/).filter(s => /^T\d{3}$/.test(s)));
122
-
123
- const idSet = new Set(ids);
124
- allDepRefs.forEach(depId => {
125
- if (!idSet.has(depId)) {
126
- warnings.push(`Dependency reference "${depId}" not found in task list`);
127
- }
128
- });
129
-
130
- return {
131
- valid: errors.length === 0,
132
- errors,
133
- warnings,
134
- stats: {
135
- totalTasks: tasks.length + checkpoints.length,
136
- regularTasks: tasks.length,
137
- checkpoints: checkpoints.length,
138
- },
139
- };
140
- }
141
-
142
- /**
143
- * Validate contracts file structure (C# contracts)
144
- * @param {string} contractsPath - Path to contracts file
145
- * @returns {Object} Validation result
146
- */
147
- export function validateContractsContent(contractsPath) {
148
- if (!existsSync(contractsPath)) {
149
- return {
150
- valid: false,
151
- errors: ['Contracts file not found at: ' + contractsPath]
152
- };
153
- }
154
-
155
- const content = readFileSync(contractsPath, 'utf8');
156
- const errors = [];
157
- const warnings = [];
158
-
159
- // Check for basic C# structure
160
- if (!content.includes('namespace')) {
161
- errors.push('Contracts file missing namespace declaration');
162
- }
163
-
164
- // Check for at least one interface or record
165
- const hasInterface = /interface\s+\w+/.test(content);
166
- const hasRecord = /record\s+\w+/.test(content);
167
- const hasClass = /class\s+\w+/.test(content);
168
-
169
- if (!hasInterface && !hasRecord && !hasClass) {
170
- errors.push('Contracts file should define at least one interface, record, or class');
171
- }
172
-
173
- // Check for common anti-patterns
174
- if (content.includes('// TODO') || content.includes('// PLACEHOLDER')) {
175
- warnings.push('Contracts contain TODO/PLACEHOLDER comments - ensure they are completed');
176
- }
177
-
178
- return {
179
- valid: errors.length === 0,
180
- errors,
181
- warnings,
182
- found: {
183
- hasNamespace: content.includes('namespace'),
184
- hasInterfaces: hasInterface,
185
- hasRecords: hasRecord,
186
- hasClasses: hasClass
187
- }
188
- };
189
- }
190
-
191
- /**
192
- * Validate proposal.md structure
193
- * @param {string} proposalPath - Path to proposal.md file
194
- * @returns {Object} Validation result
195
- */
196
- export function validateProposalContent(proposalPath) {
197
- if (!existsSync(proposalPath)) {
198
- return {
199
- valid: false,
200
- errors: ['Proposal file not found at: ' + proposalPath]
201
- };
202
- }
203
-
204
- const content = readFileSync(proposalPath, 'utf8');
205
- const errors = [];
206
- const warnings = [];
207
-
208
- // Required sections
209
- const requiredSections = [
210
- '## Problem Statement',
211
- '## Proposed Solution'
212
- ];
213
-
214
- const missing = requiredSections.filter(section => !content.includes(section));
215
- missing.forEach(section => errors.push(`Missing required section: ${section}`));
216
-
217
- // Check for minimum content
218
- if (content.length < 300) {
219
- warnings.push('Proposal seems very brief (< 300 characters)');
220
- }
221
-
222
- return {
223
- valid: errors.length === 0,
224
- errors,
225
- warnings,
226
- sections: {
227
- required: requiredSections.length,
228
- found: requiredSections.length - missing.length
229
- }
230
- };
231
- }
232
-
233
- /**
234
- * Validate all outputs for a feature comprehensively
235
- * @param {Object} featureState - Feature state object
236
- * @param {string} targetPhase - Target phase for validation
237
- * @returns {Object} Comprehensive validation result
238
- */
239
- export function validateFeatureOutputs(featureState, targetPhase) {
240
- const results = {
241
- valid: true,
242
- validations: []
243
- };
244
-
245
- // Validate based on target phase
246
- if (targetPhase === 'clarify' || targetPhase === 'tasks' || targetPhase === 'implement') {
247
- // Spec is required
248
- if (featureState.outputs?.spec?.created) {
249
- const specResult = validateSpecContent(featureState.outputs.spec.path);
250
- results.validations.push({ type: 'spec', ...specResult });
251
- if (!specResult.valid) results.valid = false;
252
- } else {
253
- results.valid = false;
254
- results.validations.push({
255
- type: 'spec',
256
- valid: false,
257
- errors: ['Spec file not created']
258
- });
259
- }
260
- }
261
-
262
- if (targetPhase === 'implement') {
263
- // Tasks are required
264
- if (featureState.outputs?.tasks?.created) {
265
- const tasksResult = validateTasksContent(featureState.outputs.tasks.path);
266
- results.validations.push({ type: 'tasks', ...tasksResult });
267
- if (!tasksResult.valid) results.valid = false;
268
- } else {
269
- results.valid = false;
270
- results.validations.push({
271
- type: 'tasks',
272
- valid: false,
273
- errors: ['Tasks file not created']
274
- });
275
- }
276
- }
277
-
278
- return results;
279
- }
1
+ import { readFileSync, existsSync } from 'fs';
2
+
3
+ /**
4
+ * Content Validator - Validates structure and content of output files
5
+ *
6
+ * Ensures spec.md, tasks.json, and other outputs have required sections
7
+ * and proper structure before allowing phase transitions.
8
+ */
9
+
10
+ /**
11
+ * Validate spec.md structure
12
+ * @param {string} specPath - Path to spec.md file
13
+ * @returns {Object} Validation result
14
+ */
15
+ export function validateSpecContent(specPath) {
16
+ if (!existsSync(specPath)) {
17
+ return {
18
+ valid: false,
19
+ missing: ['File does not exist'],
20
+ errors: ['Spec file not found at: ' + specPath]
21
+ };
22
+ }
23
+
24
+ const content = readFileSync(specPath, 'utf8');
25
+
26
+ // Required sections for a complete spec (prefix-match to handle variants like
27
+ // "## Functional Requirements" and "## Technical Architecture")
28
+ const requiredSections = [
29
+ '## Overview',
30
+ '## Functional Requirements',
31
+ '## Technical',
32
+ '## Data Model',
33
+ ];
34
+
35
+ const lines = content.split('\n');
36
+ const missing = requiredSections.filter(section =>
37
+ !lines.some(line => line.startsWith(section))
38
+ );
39
+
40
+ // Additional quality checks
41
+ const errors = [];
42
+ const warnings = [];
43
+
44
+ // Missing sections are warnings, not errors — not every spec needs all sections
45
+ // (e.g., frontend-only features may not have Data Model, CLI tools may not have Technical Architecture)
46
+ if (missing.length > 0) {
47
+ missing.forEach(section => {
48
+ warnings.push(`Missing recommended section: ${section}`);
49
+ });
50
+ }
51
+
52
+ // Check minimum content length
53
+ if (content.length < 500) {
54
+ warnings.push('Spec seems very short (< 500 characters). Consider adding more detail.');
55
+ }
56
+
57
+ // Check for placeholder text that should be replaced
58
+ const placeholders = ['TODO', 'TBD', 'PLACEHOLDER', '{{'];
59
+ placeholders.forEach(placeholder => {
60
+ if (content.includes(placeholder)) {
61
+ warnings.push(`Spec contains "${placeholder}" - ensure all placeholders are replaced`);
62
+ }
63
+ });
64
+
65
+ // Check for anti-patterns mentioned in the plan
66
+ if (content.toLowerCase().includes('manual azure portal')) {
67
+ errors.push(
68
+ 'Spec mentions manual Azure portal creation. ' +
69
+ 'All infrastructure must be defined in Bicep (Infrastructure as Code).'
70
+ );
71
+ }
72
+
73
+ if (content.toLowerCase().includes('create resource manually')) {
74
+ errors.push(
75
+ 'Spec mentions manual resource creation. ' +
76
+ 'Use IaC (Bicep) for all infrastructure resources.'
77
+ );
78
+ }
79
+
80
+ return {
81
+ valid: errors.length === 0,
82
+ missing,
83
+ errors,
84
+ warnings,
85
+ sections: {
86
+ required: requiredSections.length,
87
+ found: requiredSections.length - missing.length
88
+ }
89
+ };
90
+ }
91
+
92
+ /**
93
+ * Validate tasks.md structure
94
+ * @param {string} tasksPath - Path to tasks.md file
95
+ * @returns {Object} Validation result
96
+ */
97
+ export function validateTasksContent(tasksPath) {
98
+ if (!existsSync(tasksPath)) {
99
+ return {
100
+ valid: false,
101
+ errors: ['Tasks file not found at: ' + tasksPath]
102
+ };
103
+ }
104
+
105
+ const content = readFileSync(tasksPath, 'utf8');
106
+ const errors = [];
107
+ const warnings = [];
108
+
109
+ // Extract task IDs from headings: ### T001 — title OR ### T001: title
110
+ const taskRe = /^###\s+(T\d{3})\s*[—–:\-]\s*(.+)$/gm;
111
+ const checkpointRe = /^###\s+(CHECKPOINT[_-]\d+)\s*[—–:\-]\s*(.+)$/gm;
112
+
113
+ const tasks = [...content.matchAll(taskRe)];
114
+ const checkpoints = [...content.matchAll(checkpointRe)];
115
+
116
+ if (tasks.length === 0) {
117
+ errors.push('No tasks found in tasks.md — expected headings like "### T001 — Title" or "### T001: Title"');
118
+ return { valid: false, errors, warnings };
119
+ }
120
+
121
+ // Validate no duplicate IDs
122
+ const ids = tasks.map(m => m[1]);
123
+ const dupes = ids.filter((id, i) => ids.indexOf(id) !== i);
124
+ dupes.forEach(id => errors.push(`Duplicate task ID: ${id}`));
125
+
126
+ // Check for dependency references (look for "Dependencies: T###")
127
+ const depRe = /\*\*Dependenc(?:y|ies):\*\*\s*([T\d, ]+)/gi;
128
+ const allDepRefs = [...content.matchAll(depRe)]
129
+ .flatMap(m => m[1].split(/[,\s]+/).filter(s => /^T\d{3}$/.test(s)));
130
+
131
+ const idSet = new Set(ids);
132
+ allDepRefs.forEach(depId => {
133
+ if (!idSet.has(depId)) {
134
+ warnings.push(`Dependency reference "${depId}" not found in task list`);
135
+ }
136
+ });
137
+
138
+ return {
139
+ valid: errors.length === 0,
140
+ errors,
141
+ warnings,
142
+ stats: {
143
+ totalTasks: tasks.length + checkpoints.length,
144
+ regularTasks: tasks.length,
145
+ checkpoints: checkpoints.length,
146
+ },
147
+ };
148
+ }
149
+
150
+ /**
151
+ * Validate contracts file structure (C# contracts)
152
+ * @param {string} contractsPath - Path to contracts file
153
+ * @returns {Object} Validation result
154
+ */
155
+ export function validateContractsContent(contractsPath) {
156
+ if (!existsSync(contractsPath)) {
157
+ return {
158
+ valid: false,
159
+ errors: ['Contracts file not found at: ' + contractsPath]
160
+ };
161
+ }
162
+
163
+ const content = readFileSync(contractsPath, 'utf8');
164
+ const errors = [];
165
+ const warnings = [];
166
+
167
+ // Check for basic C# structure
168
+ if (!content.includes('namespace')) {
169
+ errors.push('Contracts file missing namespace declaration');
170
+ }
171
+
172
+ // Check for at least one interface or record
173
+ const hasInterface = /interface\s+\w+/.test(content);
174
+ const hasRecord = /record\s+\w+/.test(content);
175
+ const hasClass = /class\s+\w+/.test(content);
176
+
177
+ if (!hasInterface && !hasRecord && !hasClass) {
178
+ errors.push('Contracts file should define at least one interface, record, or class');
179
+ }
180
+
181
+ // Check for common anti-patterns
182
+ if (content.includes('// TODO') || content.includes('// PLACEHOLDER')) {
183
+ warnings.push('Contracts contain TODO/PLACEHOLDER comments - ensure they are completed');
184
+ }
185
+
186
+ return {
187
+ valid: errors.length === 0,
188
+ errors,
189
+ warnings,
190
+ found: {
191
+ hasNamespace: content.includes('namespace'),
192
+ hasInterfaces: hasInterface,
193
+ hasRecords: hasRecord,
194
+ hasClasses: hasClass
195
+ }
196
+ };
197
+ }
198
+
199
+ /**
200
+ * Validate proposal.md structure
201
+ * @param {string} proposalPath - Path to proposal.md file
202
+ * @returns {Object} Validation result
203
+ */
204
+ export function validateProposalContent(proposalPath) {
205
+ if (!existsSync(proposalPath)) {
206
+ return {
207
+ valid: false,
208
+ errors: ['Proposal file not found at: ' + proposalPath]
209
+ };
210
+ }
211
+
212
+ const content = readFileSync(proposalPath, 'utf8');
213
+ const errors = [];
214
+ const warnings = [];
215
+
216
+ // Required sections
217
+ const requiredSections = [
218
+ '## Problem Statement',
219
+ '## Proposed Solution'
220
+ ];
221
+
222
+ const missing = requiredSections.filter(section => !content.includes(section));
223
+ missing.forEach(section => errors.push(`Missing required section: ${section}`));
224
+
225
+ // Check for minimum content
226
+ if (content.length < 300) {
227
+ warnings.push('Proposal seems very brief (< 300 characters)');
228
+ }
229
+
230
+ return {
231
+ valid: errors.length === 0,
232
+ errors,
233
+ warnings,
234
+ sections: {
235
+ required: requiredSections.length,
236
+ found: requiredSections.length - missing.length
237
+ }
238
+ };
239
+ }
240
+
241
+ /**
242
+ * Validate all outputs for a feature comprehensively
243
+ * @param {Object} featureState - Feature state object
244
+ * @param {string} targetPhase - Target phase for validation
245
+ * @returns {Object} Comprehensive validation result
246
+ */
247
+ export function validateFeatureOutputs(featureState, targetPhase) {
248
+ const results = {
249
+ valid: true,
250
+ validations: []
251
+ };
252
+
253
+ // Validate based on target phase
254
+ if (targetPhase === 'clarify' || targetPhase === 'tasks' || targetPhase === 'implement') {
255
+ // Spec is required
256
+ if (featureState.outputs?.spec?.created) {
257
+ const specResult = validateSpecContent(featureState.outputs.spec.path);
258
+ results.validations.push({ type: 'spec', ...specResult });
259
+ if (!specResult.valid) results.valid = false;
260
+ } else {
261
+ results.valid = false;
262
+ results.validations.push({
263
+ type: 'spec',
264
+ valid: false,
265
+ errors: ['Spec file not created']
266
+ });
267
+ }
268
+ }
269
+
270
+ if (targetPhase === 'implement') {
271
+ // Tasks are required
272
+ if (featureState.outputs?.tasks?.created) {
273
+ const tasksResult = validateTasksContent(featureState.outputs.tasks.path);
274
+ results.validations.push({ type: 'tasks', ...tasksResult });
275
+ if (!tasksResult.valid) results.valid = false;
276
+ } else {
277
+ results.valid = false;
278
+ results.validations.push({
279
+ type: 'tasks',
280
+ valid: false,
281
+ errors: ['Tasks file not created']
282
+ });
283
+ }
284
+ }
285
+
286
+ return results;
287
+ }
@@ -1,7 +1,7 @@
1
- /**
2
- * Content Validators
3
- *
4
- * Content and spec validation.
5
- */
6
-
7
- export * from './content-validator.js';
1
+ /**
2
+ * Content Validators
3
+ *
4
+ * Content and spec validation.
5
+ */
6
+
7
+ export * from './content-validator.js';