qaa-agent 1.6.2 → 1.6.3

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 (73) hide show
  1. package/.claude/commands/create-test.md +164 -164
  2. package/.claude/commands/qa-audit.md +37 -37
  3. package/.claude/commands/qa-blueprint.md +54 -54
  4. package/.claude/commands/qa-fix.md +36 -36
  5. package/.claude/commands/qa-from-ticket.md +24 -24
  6. package/.claude/commands/qa-gap.md +20 -20
  7. package/.claude/commands/qa-map.md +47 -47
  8. package/.claude/commands/qa-pom.md +36 -36
  9. package/.claude/commands/qa-pr.md +23 -23
  10. package/.claude/commands/qa-pyramid.md +37 -37
  11. package/.claude/commands/qa-report.md +38 -38
  12. package/.claude/commands/qa-research.md +33 -33
  13. package/.claude/commands/qa-start.md +22 -22
  14. package/.claude/commands/qa-testid.md +19 -19
  15. package/.claude/commands/qa-validate.md +42 -42
  16. package/.claude/commands/update-test.md +58 -58
  17. package/.claude/settings.json +20 -20
  18. package/.claude/skills/qa-bug-detective/SKILL.md +122 -122
  19. package/.claude/skills/qa-learner/SKILL.md +150 -150
  20. package/.claude/skills/qa-repo-analyzer/SKILL.md +88 -88
  21. package/.claude/skills/qa-self-validator/SKILL.md +109 -109
  22. package/.claude/skills/qa-template-engine/SKILL.md +113 -113
  23. package/.claude/skills/qa-testid-injector/SKILL.md +93 -93
  24. package/.claude/skills/qa-workflow-documenter/SKILL.md +87 -87
  25. package/.mcp.json +8 -8
  26. package/CHANGELOG.md +71 -71
  27. package/CLAUDE.md +553 -553
  28. package/agents/qa-pipeline-orchestrator.md +1378 -1378
  29. package/agents/qaa-analyzer.md +524 -524
  30. package/agents/qaa-bug-detective.md +446 -446
  31. package/agents/qaa-codebase-mapper.md +935 -935
  32. package/agents/qaa-e2e-runner.md +415 -415
  33. package/agents/qaa-executor.md +651 -651
  34. package/agents/qaa-planner.md +390 -390
  35. package/agents/qaa-project-researcher.md +319 -319
  36. package/agents/qaa-scanner.md +424 -424
  37. package/agents/qaa-testid-injector.md +585 -585
  38. package/agents/qaa-validator.md +452 -452
  39. package/bin/install.cjs +198 -198
  40. package/bin/lib/commands.cjs +709 -709
  41. package/bin/lib/config.cjs +307 -307
  42. package/bin/lib/core.cjs +497 -497
  43. package/bin/lib/frontmatter.cjs +299 -299
  44. package/bin/lib/init.cjs +989 -989
  45. package/bin/lib/milestone.cjs +241 -241
  46. package/bin/lib/model-profiles.cjs +60 -60
  47. package/bin/lib/phase.cjs +911 -911
  48. package/bin/lib/roadmap.cjs +306 -306
  49. package/bin/lib/state.cjs +748 -748
  50. package/bin/lib/template.cjs +222 -222
  51. package/bin/lib/verify.cjs +842 -842
  52. package/bin/qaa-tools.cjs +607 -607
  53. package/docs/COMMANDS.md +341 -341
  54. package/docs/DEMO.md +182 -182
  55. package/docs/TESTING.md +156 -156
  56. package/package.json +41 -41
  57. package/templates/failure-classification.md +391 -391
  58. package/templates/gap-analysis.md +409 -409
  59. package/templates/pr-template.md +48 -48
  60. package/templates/qa-analysis.md +381 -381
  61. package/templates/qa-audit-report.md +465 -465
  62. package/templates/qa-repo-blueprint.md +636 -636
  63. package/templates/scan-manifest.md +312 -312
  64. package/templates/test-inventory.md +582 -582
  65. package/templates/testid-audit-report.md +354 -354
  66. package/templates/validation-report.md +243 -243
  67. package/workflows/qa-analyze.md +296 -296
  68. package/workflows/qa-from-ticket.md +536 -536
  69. package/workflows/qa-gap.md +303 -303
  70. package/workflows/qa-pr.md +389 -389
  71. package/workflows/qa-start.md +1168 -1168
  72. package/workflows/qa-testid.md +356 -356
  73. package/workflows/qa-validate.md +295 -295
@@ -1,306 +1,306 @@
1
- /**
2
- * Roadmap — Roadmap parsing and update operations
3
- */
4
-
5
- const fs = require('fs');
6
- const path = require('path');
7
- const { escapeRegex, normalizePhaseName, output, error, findPhaseInternal, stripShippedMilestones, replaceInCurrentMilestone } = require('./core.cjs');
8
-
9
- function cmdRoadmapGetPhase(cwd, phaseNum, raw) {
10
- const roadmapPath = path.join(cwd, '.planning', 'ROADMAP.md');
11
-
12
- if (!fs.existsSync(roadmapPath)) {
13
- output({ found: false, error: 'ROADMAP.md not found' }, raw, '');
14
- return;
15
- }
16
-
17
- try {
18
- const content = stripShippedMilestones(fs.readFileSync(roadmapPath, 'utf-8'));
19
-
20
- // Escape special regex chars in phase number, handle decimal
21
- const escapedPhase = escapeRegex(phaseNum);
22
-
23
- // Match "## Phase X:", "### Phase X:", or "#### Phase X:" with optional name
24
- const phasePattern = new RegExp(
25
- `#{2,4}\\s*Phase\\s+${escapedPhase}:\\s*([^\\n]+)`,
26
- 'i'
27
- );
28
- const headerMatch = content.match(phasePattern);
29
-
30
- if (!headerMatch) {
31
- // Fallback: check if phase exists in summary list but missing detail section
32
- const checklistPattern = new RegExp(
33
- `-\\s*\\[[ x]\\]\\s*\\*\\*Phase\\s+${escapedPhase}:\\s*([^*]+)\\*\\*`,
34
- 'i'
35
- );
36
- const checklistMatch = content.match(checklistPattern);
37
-
38
- if (checklistMatch) {
39
- // Phase exists in summary but missing detail section - malformed ROADMAP
40
- output({
41
- found: false,
42
- phase_number: phaseNum,
43
- phase_name: checklistMatch[1].trim(),
44
- error: 'malformed_roadmap',
45
- message: `Phase ${phaseNum} exists in summary list but missing "### Phase ${phaseNum}:" detail section. ROADMAP.md needs both formats.`
46
- }, raw, '');
47
- return;
48
- }
49
-
50
- output({ found: false, phase_number: phaseNum }, raw, '');
51
- return;
52
- }
53
-
54
- const phaseName = headerMatch[1].trim();
55
- const headerIndex = headerMatch.index;
56
-
57
- // Find the end of this section (next ## or ### phase header, or end of file)
58
- const restOfContent = content.slice(headerIndex);
59
- const nextHeaderMatch = restOfContent.match(/\n#{2,4}\s+Phase\s+\d/i);
60
- const sectionEnd = nextHeaderMatch
61
- ? headerIndex + nextHeaderMatch.index
62
- : content.length;
63
-
64
- const section = content.slice(headerIndex, sectionEnd).trim();
65
-
66
- // Extract goal if present (supports both **Goal:** and **Goal**: formats)
67
- const goalMatch = section.match(/\*\*Goal(?::\*\*|\*\*:)\s*([^\n]+)/i);
68
- const goal = goalMatch ? goalMatch[1].trim() : null;
69
-
70
- // Extract success criteria as structured array
71
- const criteriaMatch = section.match(/\*\*Success Criteria\*\*[^\n]*:\s*\n((?:\s*\d+\.\s*[^\n]+\n?)+)/i);
72
- const success_criteria = criteriaMatch
73
- ? criteriaMatch[1].trim().split('\n').map(line => line.replace(/^\s*\d+\.\s*/, '').trim()).filter(Boolean)
74
- : [];
75
-
76
- output(
77
- {
78
- found: true,
79
- phase_number: phaseNum,
80
- phase_name: phaseName,
81
- goal,
82
- success_criteria,
83
- section,
84
- },
85
- raw,
86
- section
87
- );
88
- } catch (e) {
89
- error('Failed to read ROADMAP.md: ' + e.message);
90
- }
91
- }
92
-
93
- function cmdRoadmapAnalyze(cwd, raw) {
94
- const roadmapPath = path.join(cwd, '.planning', 'ROADMAP.md');
95
-
96
- if (!fs.existsSync(roadmapPath)) {
97
- output({ error: 'ROADMAP.md not found', milestones: [], phases: [], current_phase: null }, raw);
98
- return;
99
- }
100
-
101
- const rawContent = fs.readFileSync(roadmapPath, 'utf-8');
102
- const content = stripShippedMilestones(rawContent);
103
- const phasesDir = path.join(cwd, '.planning', 'phases');
104
-
105
- // Extract all phase headings: ## Phase N: Name or ### Phase N: Name
106
- const phasePattern = /#{2,4}\s*Phase\s+(\d+[A-Z]?(?:\.\d+)*)\s*:\s*([^\n]+)/gi;
107
- const phases = [];
108
- let match;
109
-
110
- while ((match = phasePattern.exec(content)) !== null) {
111
- const phaseNum = match[1];
112
- const phaseName = match[2].replace(/\(INSERTED\)/i, '').trim();
113
-
114
- // Extract goal from the section
115
- const sectionStart = match.index;
116
- const restOfContent = content.slice(sectionStart);
117
- const nextHeader = restOfContent.match(/\n#{2,4}\s+Phase\s+\d/i);
118
- const sectionEnd = nextHeader ? sectionStart + nextHeader.index : content.length;
119
- const section = content.slice(sectionStart, sectionEnd);
120
-
121
- const goalMatch = section.match(/\*\*Goal(?::\*\*|\*\*:)\s*([^\n]+)/i);
122
- const goal = goalMatch ? goalMatch[1].trim() : null;
123
-
124
- const dependsMatch = section.match(/\*\*Depends on(?::\*\*|\*\*:)\s*([^\n]+)/i);
125
- const depends_on = dependsMatch ? dependsMatch[1].trim() : null;
126
-
127
- // Check completion on disk
128
- const normalized = normalizePhaseName(phaseNum);
129
- let diskStatus = 'no_directory';
130
- let planCount = 0;
131
- let summaryCount = 0;
132
- let hasContext = false;
133
- let hasResearch = false;
134
-
135
- try {
136
- const entries = fs.readdirSync(phasesDir, { withFileTypes: true });
137
- const dirs = entries.filter(e => e.isDirectory()).map(e => e.name);
138
- const dirMatch = dirs.find(d => d.startsWith(normalized + '-') || d === normalized);
139
-
140
- if (dirMatch) {
141
- const phaseFiles = fs.readdirSync(path.join(phasesDir, dirMatch));
142
- planCount = phaseFiles.filter(f => f.endsWith('-PLAN.md') || f === 'PLAN.md').length;
143
- summaryCount = phaseFiles.filter(f => f.endsWith('-SUMMARY.md') || f === 'SUMMARY.md').length;
144
- hasContext = phaseFiles.some(f => f.endsWith('-CONTEXT.md') || f === 'CONTEXT.md');
145
- hasResearch = phaseFiles.some(f => f.endsWith('-RESEARCH.md') || f === 'RESEARCH.md');
146
-
147
- if (summaryCount >= planCount && planCount > 0) diskStatus = 'complete';
148
- else if (summaryCount > 0) diskStatus = 'partial';
149
- else if (planCount > 0) diskStatus = 'planned';
150
- else if (hasResearch) diskStatus = 'researched';
151
- else if (hasContext) diskStatus = 'discussed';
152
- else diskStatus = 'empty';
153
- }
154
- } catch {}
155
-
156
- // Check ROADMAP checkbox status
157
- const checkboxPattern = new RegExp(`-\\s*\\[(x| )\\]\\s*.*Phase\\s+${escapeRegex(phaseNum)}[:\\s]`, 'i');
158
- const checkboxMatch = content.match(checkboxPattern);
159
- const roadmapComplete = checkboxMatch ? checkboxMatch[1] === 'x' : false;
160
-
161
- // If roadmap marks phase complete, trust that over disk file structure.
162
- // Phases completed before GSD tracking (or via external tools) may lack
163
- // the standard PLAN/SUMMARY pairs but are still done.
164
- if (roadmapComplete && diskStatus !== 'complete') {
165
- diskStatus = 'complete';
166
- }
167
-
168
- phases.push({
169
- number: phaseNum,
170
- name: phaseName,
171
- goal,
172
- depends_on,
173
- plan_count: planCount,
174
- summary_count: summaryCount,
175
- has_context: hasContext,
176
- has_research: hasResearch,
177
- disk_status: diskStatus,
178
- roadmap_complete: roadmapComplete,
179
- });
180
- }
181
-
182
- // Extract milestone info
183
- const milestones = [];
184
- const milestonePattern = /##\s*(.*v(\d+\.\d+)[^(\n]*)/gi;
185
- let mMatch;
186
- while ((mMatch = milestonePattern.exec(content)) !== null) {
187
- milestones.push({
188
- heading: mMatch[1].trim(),
189
- version: 'v' + mMatch[2],
190
- });
191
- }
192
-
193
- // Find current and next phase
194
- const currentPhase = phases.find(p => p.disk_status === 'planned' || p.disk_status === 'partial') || null;
195
- const nextPhase = phases.find(p => p.disk_status === 'empty' || p.disk_status === 'no_directory' || p.disk_status === 'discussed' || p.disk_status === 'researched') || null;
196
-
197
- // Aggregated stats
198
- const totalPlans = phases.reduce((sum, p) => sum + p.plan_count, 0);
199
- const totalSummaries = phases.reduce((sum, p) => sum + p.summary_count, 0);
200
- const completedPhases = phases.filter(p => p.disk_status === 'complete').length;
201
-
202
- // Detect phases in summary list without detail sections (malformed ROADMAP)
203
- const checklistPattern = /-\s*\[[ x]\]\s*\*\*Phase\s+(\d+[A-Z]?(?:\.\d+)*)/gi;
204
- const checklistPhases = new Set();
205
- let checklistMatch;
206
- while ((checklistMatch = checklistPattern.exec(content)) !== null) {
207
- checklistPhases.add(checklistMatch[1]);
208
- }
209
- const detailPhases = new Set(phases.map(p => p.number));
210
- const missingDetails = [...checklistPhases].filter(p => !detailPhases.has(p));
211
-
212
- const result = {
213
- milestones,
214
- phases,
215
- phase_count: phases.length,
216
- completed_phases: completedPhases,
217
- total_plans: totalPlans,
218
- total_summaries: totalSummaries,
219
- progress_percent: totalPlans > 0 ? Math.min(100, Math.round((totalSummaries / totalPlans) * 100)) : 0,
220
- current_phase: currentPhase ? currentPhase.number : null,
221
- next_phase: nextPhase ? nextPhase.number : null,
222
- missing_phase_details: missingDetails.length > 0 ? missingDetails : null,
223
- };
224
-
225
- output(result, raw);
226
- }
227
-
228
- function cmdRoadmapUpdatePlanProgress(cwd, phaseNum, raw) {
229
- if (!phaseNum) {
230
- error('phase number required for roadmap update-plan-progress');
231
- }
232
-
233
- const roadmapPath = path.join(cwd, '.planning', 'ROADMAP.md');
234
-
235
- const phaseInfo = findPhaseInternal(cwd, phaseNum);
236
- if (!phaseInfo) {
237
- error(`Phase ${phaseNum} not found`);
238
- }
239
-
240
- const planCount = phaseInfo.plans.length;
241
- const summaryCount = phaseInfo.summaries.length;
242
-
243
- if (planCount === 0) {
244
- output({ updated: false, reason: 'No plans found', plan_count: 0, summary_count: 0 }, raw, 'no plans');
245
- return;
246
- }
247
-
248
- const isComplete = summaryCount >= planCount;
249
- const status = isComplete ? 'Complete' : summaryCount > 0 ? 'In Progress' : 'Planned';
250
- const today = new Date().toISOString().split('T')[0];
251
-
252
- if (!fs.existsSync(roadmapPath)) {
253
- output({ updated: false, reason: 'ROADMAP.md not found', plan_count: planCount, summary_count: summaryCount }, raw, 'no roadmap');
254
- return;
255
- }
256
-
257
- let roadmapContent = fs.readFileSync(roadmapPath, 'utf-8');
258
- const phaseEscaped = escapeRegex(phaseNum);
259
-
260
- // Progress table row: update Plans column (summaries/plans) and Status column
261
- const tablePattern = new RegExp(
262
- `(\\|\\s*${phaseEscaped}\\.?\\s[^|]*\\|)[^|]*(\\|)\\s*[^|]*(\\|)\\s*[^|]*(\\|)`,
263
- 'i'
264
- );
265
- const dateField = isComplete ? ` ${today} ` : ' ';
266
- roadmapContent = replaceInCurrentMilestone(
267
- roadmapContent, tablePattern,
268
- `$1 ${summaryCount}/${planCount} $2 ${status.padEnd(11)}$3${dateField}$4`
269
- );
270
-
271
- // Update plan count in phase detail section
272
- const planCountPattern = new RegExp(
273
- `(#{2,4}\\s*Phase\\s+${phaseEscaped}[\\s\\S]*?\\*\\*Plans:\\*\\*\\s*)[^\\n]+`,
274
- 'i'
275
- );
276
- const planCountText = isComplete
277
- ? `${summaryCount}/${planCount} plans complete`
278
- : `${summaryCount}/${planCount} plans executed`;
279
- roadmapContent = replaceInCurrentMilestone(roadmapContent, planCountPattern, `$1${planCountText}`);
280
-
281
- // If complete: check checkbox
282
- if (isComplete) {
283
- const checkboxPattern = new RegExp(
284
- `(-\\s*\\[)[ ](\\]\\s*.*Phase\\s+${phaseEscaped}[:\\s][^\\n]*)`,
285
- 'i'
286
- );
287
- roadmapContent = replaceInCurrentMilestone(roadmapContent, checkboxPattern, `$1x$2 (completed ${today})`);
288
- }
289
-
290
- fs.writeFileSync(roadmapPath, roadmapContent, 'utf-8');
291
-
292
- output({
293
- updated: true,
294
- phase: phaseNum,
295
- plan_count: planCount,
296
- summary_count: summaryCount,
297
- status,
298
- complete: isComplete,
299
- }, raw, `${summaryCount}/${planCount} ${status}`);
300
- }
301
-
302
- module.exports = {
303
- cmdRoadmapGetPhase,
304
- cmdRoadmapAnalyze,
305
- cmdRoadmapUpdatePlanProgress,
306
- };
1
+ /**
2
+ * Roadmap — Roadmap parsing and update operations
3
+ */
4
+
5
+ const fs = require('fs');
6
+ const path = require('path');
7
+ const { escapeRegex, normalizePhaseName, output, error, findPhaseInternal, stripShippedMilestones, replaceInCurrentMilestone } = require('./core.cjs');
8
+
9
+ function cmdRoadmapGetPhase(cwd, phaseNum, raw) {
10
+ const roadmapPath = path.join(cwd, '.planning', 'ROADMAP.md');
11
+
12
+ if (!fs.existsSync(roadmapPath)) {
13
+ output({ found: false, error: 'ROADMAP.md not found' }, raw, '');
14
+ return;
15
+ }
16
+
17
+ try {
18
+ const content = stripShippedMilestones(fs.readFileSync(roadmapPath, 'utf-8'));
19
+
20
+ // Escape special regex chars in phase number, handle decimal
21
+ const escapedPhase = escapeRegex(phaseNum);
22
+
23
+ // Match "## Phase X:", "### Phase X:", or "#### Phase X:" with optional name
24
+ const phasePattern = new RegExp(
25
+ `#{2,4}\\s*Phase\\s+${escapedPhase}:\\s*([^\\n]+)`,
26
+ 'i'
27
+ );
28
+ const headerMatch = content.match(phasePattern);
29
+
30
+ if (!headerMatch) {
31
+ // Fallback: check if phase exists in summary list but missing detail section
32
+ const checklistPattern = new RegExp(
33
+ `-\\s*\\[[ x]\\]\\s*\\*\\*Phase\\s+${escapedPhase}:\\s*([^*]+)\\*\\*`,
34
+ 'i'
35
+ );
36
+ const checklistMatch = content.match(checklistPattern);
37
+
38
+ if (checklistMatch) {
39
+ // Phase exists in summary but missing detail section - malformed ROADMAP
40
+ output({
41
+ found: false,
42
+ phase_number: phaseNum,
43
+ phase_name: checklistMatch[1].trim(),
44
+ error: 'malformed_roadmap',
45
+ message: `Phase ${phaseNum} exists in summary list but missing "### Phase ${phaseNum}:" detail section. ROADMAP.md needs both formats.`
46
+ }, raw, '');
47
+ return;
48
+ }
49
+
50
+ output({ found: false, phase_number: phaseNum }, raw, '');
51
+ return;
52
+ }
53
+
54
+ const phaseName = headerMatch[1].trim();
55
+ const headerIndex = headerMatch.index;
56
+
57
+ // Find the end of this section (next ## or ### phase header, or end of file)
58
+ const restOfContent = content.slice(headerIndex);
59
+ const nextHeaderMatch = restOfContent.match(/\n#{2,4}\s+Phase\s+\d/i);
60
+ const sectionEnd = nextHeaderMatch
61
+ ? headerIndex + nextHeaderMatch.index
62
+ : content.length;
63
+
64
+ const section = content.slice(headerIndex, sectionEnd).trim();
65
+
66
+ // Extract goal if present (supports both **Goal:** and **Goal**: formats)
67
+ const goalMatch = section.match(/\*\*Goal(?::\*\*|\*\*:)\s*([^\n]+)/i);
68
+ const goal = goalMatch ? goalMatch[1].trim() : null;
69
+
70
+ // Extract success criteria as structured array
71
+ const criteriaMatch = section.match(/\*\*Success Criteria\*\*[^\n]*:\s*\n((?:\s*\d+\.\s*[^\n]+\n?)+)/i);
72
+ const success_criteria = criteriaMatch
73
+ ? criteriaMatch[1].trim().split('\n').map(line => line.replace(/^\s*\d+\.\s*/, '').trim()).filter(Boolean)
74
+ : [];
75
+
76
+ output(
77
+ {
78
+ found: true,
79
+ phase_number: phaseNum,
80
+ phase_name: phaseName,
81
+ goal,
82
+ success_criteria,
83
+ section,
84
+ },
85
+ raw,
86
+ section
87
+ );
88
+ } catch (e) {
89
+ error('Failed to read ROADMAP.md: ' + e.message);
90
+ }
91
+ }
92
+
93
+ function cmdRoadmapAnalyze(cwd, raw) {
94
+ const roadmapPath = path.join(cwd, '.planning', 'ROADMAP.md');
95
+
96
+ if (!fs.existsSync(roadmapPath)) {
97
+ output({ error: 'ROADMAP.md not found', milestones: [], phases: [], current_phase: null }, raw);
98
+ return;
99
+ }
100
+
101
+ const rawContent = fs.readFileSync(roadmapPath, 'utf-8');
102
+ const content = stripShippedMilestones(rawContent);
103
+ const phasesDir = path.join(cwd, '.planning', 'phases');
104
+
105
+ // Extract all phase headings: ## Phase N: Name or ### Phase N: Name
106
+ const phasePattern = /#{2,4}\s*Phase\s+(\d+[A-Z]?(?:\.\d+)*)\s*:\s*([^\n]+)/gi;
107
+ const phases = [];
108
+ let match;
109
+
110
+ while ((match = phasePattern.exec(content)) !== null) {
111
+ const phaseNum = match[1];
112
+ const phaseName = match[2].replace(/\(INSERTED\)/i, '').trim();
113
+
114
+ // Extract goal from the section
115
+ const sectionStart = match.index;
116
+ const restOfContent = content.slice(sectionStart);
117
+ const nextHeader = restOfContent.match(/\n#{2,4}\s+Phase\s+\d/i);
118
+ const sectionEnd = nextHeader ? sectionStart + nextHeader.index : content.length;
119
+ const section = content.slice(sectionStart, sectionEnd);
120
+
121
+ const goalMatch = section.match(/\*\*Goal(?::\*\*|\*\*:)\s*([^\n]+)/i);
122
+ const goal = goalMatch ? goalMatch[1].trim() : null;
123
+
124
+ const dependsMatch = section.match(/\*\*Depends on(?::\*\*|\*\*:)\s*([^\n]+)/i);
125
+ const depends_on = dependsMatch ? dependsMatch[1].trim() : null;
126
+
127
+ // Check completion on disk
128
+ const normalized = normalizePhaseName(phaseNum);
129
+ let diskStatus = 'no_directory';
130
+ let planCount = 0;
131
+ let summaryCount = 0;
132
+ let hasContext = false;
133
+ let hasResearch = false;
134
+
135
+ try {
136
+ const entries = fs.readdirSync(phasesDir, { withFileTypes: true });
137
+ const dirs = entries.filter(e => e.isDirectory()).map(e => e.name);
138
+ const dirMatch = dirs.find(d => d.startsWith(normalized + '-') || d === normalized);
139
+
140
+ if (dirMatch) {
141
+ const phaseFiles = fs.readdirSync(path.join(phasesDir, dirMatch));
142
+ planCount = phaseFiles.filter(f => f.endsWith('-PLAN.md') || f === 'PLAN.md').length;
143
+ summaryCount = phaseFiles.filter(f => f.endsWith('-SUMMARY.md') || f === 'SUMMARY.md').length;
144
+ hasContext = phaseFiles.some(f => f.endsWith('-CONTEXT.md') || f === 'CONTEXT.md');
145
+ hasResearch = phaseFiles.some(f => f.endsWith('-RESEARCH.md') || f === 'RESEARCH.md');
146
+
147
+ if (summaryCount >= planCount && planCount > 0) diskStatus = 'complete';
148
+ else if (summaryCount > 0) diskStatus = 'partial';
149
+ else if (planCount > 0) diskStatus = 'planned';
150
+ else if (hasResearch) diskStatus = 'researched';
151
+ else if (hasContext) diskStatus = 'discussed';
152
+ else diskStatus = 'empty';
153
+ }
154
+ } catch {}
155
+
156
+ // Check ROADMAP checkbox status
157
+ const checkboxPattern = new RegExp(`-\\s*\\[(x| )\\]\\s*.*Phase\\s+${escapeRegex(phaseNum)}[:\\s]`, 'i');
158
+ const checkboxMatch = content.match(checkboxPattern);
159
+ const roadmapComplete = checkboxMatch ? checkboxMatch[1] === 'x' : false;
160
+
161
+ // If roadmap marks phase complete, trust that over disk file structure.
162
+ // Phases completed before GSD tracking (or via external tools) may lack
163
+ // the standard PLAN/SUMMARY pairs but are still done.
164
+ if (roadmapComplete && diskStatus !== 'complete') {
165
+ diskStatus = 'complete';
166
+ }
167
+
168
+ phases.push({
169
+ number: phaseNum,
170
+ name: phaseName,
171
+ goal,
172
+ depends_on,
173
+ plan_count: planCount,
174
+ summary_count: summaryCount,
175
+ has_context: hasContext,
176
+ has_research: hasResearch,
177
+ disk_status: diskStatus,
178
+ roadmap_complete: roadmapComplete,
179
+ });
180
+ }
181
+
182
+ // Extract milestone info
183
+ const milestones = [];
184
+ const milestonePattern = /##\s*(.*v(\d+\.\d+)[^(\n]*)/gi;
185
+ let mMatch;
186
+ while ((mMatch = milestonePattern.exec(content)) !== null) {
187
+ milestones.push({
188
+ heading: mMatch[1].trim(),
189
+ version: 'v' + mMatch[2],
190
+ });
191
+ }
192
+
193
+ // Find current and next phase
194
+ const currentPhase = phases.find(p => p.disk_status === 'planned' || p.disk_status === 'partial') || null;
195
+ const nextPhase = phases.find(p => p.disk_status === 'empty' || p.disk_status === 'no_directory' || p.disk_status === 'discussed' || p.disk_status === 'researched') || null;
196
+
197
+ // Aggregated stats
198
+ const totalPlans = phases.reduce((sum, p) => sum + p.plan_count, 0);
199
+ const totalSummaries = phases.reduce((sum, p) => sum + p.summary_count, 0);
200
+ const completedPhases = phases.filter(p => p.disk_status === 'complete').length;
201
+
202
+ // Detect phases in summary list without detail sections (malformed ROADMAP)
203
+ const checklistPattern = /-\s*\[[ x]\]\s*\*\*Phase\s+(\d+[A-Z]?(?:\.\d+)*)/gi;
204
+ const checklistPhases = new Set();
205
+ let checklistMatch;
206
+ while ((checklistMatch = checklistPattern.exec(content)) !== null) {
207
+ checklistPhases.add(checklistMatch[1]);
208
+ }
209
+ const detailPhases = new Set(phases.map(p => p.number));
210
+ const missingDetails = [...checklistPhases].filter(p => !detailPhases.has(p));
211
+
212
+ const result = {
213
+ milestones,
214
+ phases,
215
+ phase_count: phases.length,
216
+ completed_phases: completedPhases,
217
+ total_plans: totalPlans,
218
+ total_summaries: totalSummaries,
219
+ progress_percent: totalPlans > 0 ? Math.min(100, Math.round((totalSummaries / totalPlans) * 100)) : 0,
220
+ current_phase: currentPhase ? currentPhase.number : null,
221
+ next_phase: nextPhase ? nextPhase.number : null,
222
+ missing_phase_details: missingDetails.length > 0 ? missingDetails : null,
223
+ };
224
+
225
+ output(result, raw);
226
+ }
227
+
228
+ function cmdRoadmapUpdatePlanProgress(cwd, phaseNum, raw) {
229
+ if (!phaseNum) {
230
+ error('phase number required for roadmap update-plan-progress');
231
+ }
232
+
233
+ const roadmapPath = path.join(cwd, '.planning', 'ROADMAP.md');
234
+
235
+ const phaseInfo = findPhaseInternal(cwd, phaseNum);
236
+ if (!phaseInfo) {
237
+ error(`Phase ${phaseNum} not found`);
238
+ }
239
+
240
+ const planCount = phaseInfo.plans.length;
241
+ const summaryCount = phaseInfo.summaries.length;
242
+
243
+ if (planCount === 0) {
244
+ output({ updated: false, reason: 'No plans found', plan_count: 0, summary_count: 0 }, raw, 'no plans');
245
+ return;
246
+ }
247
+
248
+ const isComplete = summaryCount >= planCount;
249
+ const status = isComplete ? 'Complete' : summaryCount > 0 ? 'In Progress' : 'Planned';
250
+ const today = new Date().toISOString().split('T')[0];
251
+
252
+ if (!fs.existsSync(roadmapPath)) {
253
+ output({ updated: false, reason: 'ROADMAP.md not found', plan_count: planCount, summary_count: summaryCount }, raw, 'no roadmap');
254
+ return;
255
+ }
256
+
257
+ let roadmapContent = fs.readFileSync(roadmapPath, 'utf-8');
258
+ const phaseEscaped = escapeRegex(phaseNum);
259
+
260
+ // Progress table row: update Plans column (summaries/plans) and Status column
261
+ const tablePattern = new RegExp(
262
+ `(\\|\\s*${phaseEscaped}\\.?\\s[^|]*\\|)[^|]*(\\|)\\s*[^|]*(\\|)\\s*[^|]*(\\|)`,
263
+ 'i'
264
+ );
265
+ const dateField = isComplete ? ` ${today} ` : ' ';
266
+ roadmapContent = replaceInCurrentMilestone(
267
+ roadmapContent, tablePattern,
268
+ `$1 ${summaryCount}/${planCount} $2 ${status.padEnd(11)}$3${dateField}$4`
269
+ );
270
+
271
+ // Update plan count in phase detail section
272
+ const planCountPattern = new RegExp(
273
+ `(#{2,4}\\s*Phase\\s+${phaseEscaped}[\\s\\S]*?\\*\\*Plans:\\*\\*\\s*)[^\\n]+`,
274
+ 'i'
275
+ );
276
+ const planCountText = isComplete
277
+ ? `${summaryCount}/${planCount} plans complete`
278
+ : `${summaryCount}/${planCount} plans executed`;
279
+ roadmapContent = replaceInCurrentMilestone(roadmapContent, planCountPattern, `$1${planCountText}`);
280
+
281
+ // If complete: check checkbox
282
+ if (isComplete) {
283
+ const checkboxPattern = new RegExp(
284
+ `(-\\s*\\[)[ ](\\]\\s*.*Phase\\s+${phaseEscaped}[:\\s][^\\n]*)`,
285
+ 'i'
286
+ );
287
+ roadmapContent = replaceInCurrentMilestone(roadmapContent, checkboxPattern, `$1x$2 (completed ${today})`);
288
+ }
289
+
290
+ fs.writeFileSync(roadmapPath, roadmapContent, 'utf-8');
291
+
292
+ output({
293
+ updated: true,
294
+ phase: phaseNum,
295
+ plan_count: planCount,
296
+ summary_count: summaryCount,
297
+ status,
298
+ complete: isComplete,
299
+ }, raw, `${summaryCount}/${planCount} ${status}`);
300
+ }
301
+
302
+ module.exports = {
303
+ cmdRoadmapGetPhase,
304
+ cmdRoadmapAnalyze,
305
+ cmdRoadmapUpdatePlanProgress,
306
+ };