gsd-opencode 1.10.2 → 1.20.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.
- package/agents/gsd-codebase-mapper.md +29 -3
- package/agents/gsd-debugger.md +19 -21
- package/agents/gsd-executor.md +213 -528
- package/agents/gsd-integration-checker.md +20 -0
- package/agents/gsd-phase-researcher.md +189 -267
- package/agents/gsd-plan-checker.md +278 -279
- package/agents/gsd-planner.md +299 -490
- package/agents/gsd-project-researcher.md +103 -345
- package/agents/gsd-research-synthesizer.md +5 -22
- package/agents/gsd-roadmapper.md +43 -6
- package/agents/gsd-verifier.md +158 -377
- package/{lib → bin/dm/lib}/constants.js +10 -3
- package/{src → bin/dm/src}/commands/install.js +5 -4
- package/{src → bin/dm/src}/commands/uninstall.js +3 -1
- package/{src → bin/dm/src}/services/backup-manager.js +1 -1
- package/{src → bin/dm/src}/services/config.js +1 -1
- package/{src → bin/dm/src}/services/file-ops.js +20 -4
- package/{src → bin/dm/src}/services/health-checker.js +3 -1
- package/{src → bin/dm/src}/services/repair-service.js +3 -1
- package/{src → bin/dm/src}/services/settings.js +1 -1
- package/{src → bin/dm/src}/services/update-service.js +2 -2
- package/bin/gsd-install.js +0 -0
- package/bin/gsd.js +9 -9
- package/commands/gsd/gsd-add-phase.md +43 -0
- package/commands/gsd/gsd-add-todo.md +47 -0
- package/commands/gsd/gsd-audit-milestone.md +36 -0
- package/commands/gsd/gsd-check-todos.md +45 -0
- package/commands/gsd/gsd-cleanup.md +18 -0
- package/commands/gsd/{complete-milestone.md → gsd-complete-milestone.md} +1 -1
- package/commands/gsd/{debug.md → gsd-debug.md} +16 -21
- package/commands/gsd/{discuss-phase.md → gsd-discuss-phase.md} +6 -9
- package/commands/gsd/gsd-execute-phase.md +41 -0
- package/commands/gsd/gsd-health.md +22 -0
- package/commands/gsd/gsd-help.md +22 -0
- package/commands/gsd/gsd-insert-phase.md +32 -0
- package/commands/gsd/gsd-join-discord.md +18 -0
- package/commands/gsd/{list-phase-assumptions.md → gsd-list-phase-assumptions.md} +3 -7
- package/commands/gsd/{map-codebase.md → gsd-map-codebase.md} +3 -3
- package/commands/gsd/gsd-new-milestone.md +44 -0
- package/commands/gsd/gsd-new-project.md +42 -0
- package/commands/gsd/gsd-pause-work.md +38 -0
- package/commands/gsd/gsd-plan-milestone-gaps.md +34 -0
- package/commands/gsd/gsd-plan-phase.md +44 -0
- package/commands/gsd/gsd-progress.md +24 -0
- package/commands/gsd/gsd-quick.md +41 -0
- package/commands/gsd/gsd-reapply-patches.md +119 -0
- package/commands/gsd/gsd-remove-phase.md +31 -0
- package/commands/gsd/{research-phase.md → gsd-research-phase.md} +38 -49
- package/commands/gsd/{resume-work.md → gsd-resume-work.md} +2 -2
- package/commands/gsd/gsd-set-profile.md +34 -0
- package/commands/gsd/gsd-settings.md +36 -0
- package/commands/gsd/gsd-update.md +37 -0
- package/commands/gsd/gsd-verify-work.md +38 -0
- package/get-shit-done/bin/gsd-tools.cjs +553 -0
- package/get-shit-done/bin/gsd-tools.test.cjs +2346 -0
- package/get-shit-done/bin/lib/commands.cjs +556 -0
- package/get-shit-done/bin/lib/config.cjs +162 -0
- package/get-shit-done/bin/lib/core.cjs +377 -0
- package/get-shit-done/bin/lib/frontmatter.cjs +299 -0
- package/get-shit-done/bin/lib/init.cjs +694 -0
- package/get-shit-done/bin/lib/milestone.cjs +215 -0
- package/get-shit-done/bin/lib/phase.cjs +877 -0
- package/get-shit-done/bin/lib/roadmap.cjs +298 -0
- package/get-shit-done/bin/lib/state.cjs +490 -0
- package/get-shit-done/bin/lib/template.cjs +222 -0
- package/get-shit-done/bin/lib/verify.cjs +772 -0
- package/get-shit-done/references/checkpoints.md +62 -364
- package/get-shit-done/references/decimal-phase-calculation.md +65 -0
- package/get-shit-done/references/git-integration.md +10 -16
- package/get-shit-done/references/git-planning-commit.md +38 -0
- package/get-shit-done/references/model-profile-resolution.md +34 -0
- package/get-shit-done/references/model-profiles.md +54 -66
- package/get-shit-done/references/phase-argument-parsing.md +61 -0
- package/get-shit-done/references/planning-config.md +112 -10
- package/get-shit-done/references/questioning.md +4 -0
- package/get-shit-done/references/ui-brand.md +1 -1
- package/get-shit-done/templates/UAT.md +1 -1
- package/get-shit-done/templates/VALIDATION.md +104 -0
- package/get-shit-done/templates/codebase/structure.md +6 -6
- package/get-shit-done/templates/config.json +37 -0
- package/get-shit-done/templates/context.md +2 -10
- package/get-shit-done/templates/continue-here.md +6 -6
- package/get-shit-done/templates/debug-subagent-prompt.md +2 -2
- package/get-shit-done/templates/discovery.md +6 -6
- package/get-shit-done/templates/milestone-archive.md +3 -3
- package/get-shit-done/templates/phase-prompt.md +9 -7
- package/get-shit-done/templates/planner-subagent-prompt.md +6 -6
- package/get-shit-done/templates/research-project/ARCHITECTURE.md +1 -1
- package/get-shit-done/templates/research.md +29 -6
- package/get-shit-done/templates/roadmap.md +1 -1
- package/get-shit-done/templates/state.md +0 -30
- package/get-shit-done/templates/summary-complex.md +59 -0
- package/get-shit-done/templates/summary-minimal.md +41 -0
- package/get-shit-done/templates/summary-standard.md +48 -0
- package/get-shit-done/templates/summary.md +16 -37
- package/get-shit-done/templates/user-setup.md +1 -13
- package/get-shit-done/templates/verification-report.md +5 -5
- package/get-shit-done/workflows/add-phase.md +111 -0
- package/{commands/gsd → get-shit-done/workflows}/add-todo.md +24 -60
- package/{commands/gsd → get-shit-done/workflows}/audit-milestone.md +83 -63
- package/{commands/gsd → get-shit-done/workflows}/check-todos.md +21 -73
- package/get-shit-done/workflows/cleanup.md +152 -0
- package/get-shit-done/workflows/complete-milestone.md +251 -312
- package/get-shit-done/workflows/diagnose-issues.md +6 -31
- package/get-shit-done/workflows/discovery-phase.md +11 -11
- package/get-shit-done/workflows/discuss-phase.md +156 -49
- package/get-shit-done/workflows/execute-phase.md +238 -396
- package/get-shit-done/workflows/execute-plan.md +180 -1609
- package/get-shit-done/workflows/health.md +156 -0
- package/{commands/gsd → get-shit-done/workflows}/help.md +33 -35
- package/get-shit-done/workflows/insert-phase.md +129 -0
- package/get-shit-done/workflows/list-phase-assumptions.md +3 -3
- package/get-shit-done/workflows/map-codebase.md +73 -80
- package/get-shit-done/workflows/new-milestone.md +382 -0
- package/{commands/gsd → get-shit-done/workflows}/new-project.md +281 -234
- package/get-shit-done/workflows/oc-set-profile.md +320 -0
- package/{commands/gsd → get-shit-done/workflows}/pause-work.md +31 -43
- package/{commands/gsd → get-shit-done/workflows}/plan-milestone-gaps.md +29 -50
- package/get-shit-done/workflows/plan-phase.md +478 -0
- package/{commands/gsd → get-shit-done/workflows}/progress.md +64 -47
- package/get-shit-done/workflows/quick.md +453 -0
- package/get-shit-done/workflows/remove-phase.md +154 -0
- package/get-shit-done/workflows/research-phase.md +73 -0
- package/get-shit-done/workflows/resume-project.md +17 -26
- package/get-shit-done/workflows/set-profile.md +80 -0
- package/get-shit-done/workflows/settings.md +213 -0
- package/get-shit-done/workflows/transition.md +84 -104
- package/{commands/gsd → get-shit-done/workflows}/update.md +70 -28
- package/get-shit-done/workflows/verify-phase.md +106 -492
- package/get-shit-done/workflows/verify-work.md +26 -53
- package/package.json +7 -4
- package/rules/gsd-oc-work-hard.md +36 -0
- package/skills/gsd-oc-select-model/SKILL.md +348 -0
- package/skills/gsd-oc-select-model/scripts/select-models.cjs +268 -0
- package/agents/gsd-set-model.md +0 -287
- package/agents/gsd-set-profile.md +0 -239
- package/agents/gsd-settings.md +0 -749
- package/bin/install.js +0 -323
- package/commands/gsd/add-phase.md +0 -207
- package/commands/gsd/execute-phase.md +0 -339
- package/commands/gsd/insert-phase.md +0 -227
- package/commands/gsd/new-milestone.md +0 -721
- package/commands/gsd/plan-phase.md +0 -525
- package/commands/gsd/quick.md +0 -309
- package/commands/gsd/remove-phase.md +0 -349
- package/commands/gsd/set-model.md +0 -77
- package/commands/gsd/set-profile.md +0 -46
- package/commands/gsd/settings.md +0 -33
- package/commands/gsd/verify-work.md +0 -219
- package/commands/gsd/whats-new.md +0 -124
- /package/{src → bin/dm/src}/commands/check.js +0 -0
- /package/{src → bin/dm/src}/commands/config.js +0 -0
- /package/{src → bin/dm/src}/commands/list.js +0 -0
- /package/{src → bin/dm/src}/commands/repair.js +0 -0
- /package/{src → bin/dm/src}/commands/update.js +0 -0
- /package/{src → bin/dm/src}/services/manifest-manager.js +0 -0
- /package/{src → bin/dm/src}/services/migration-service.js +0 -0
- /package/{src → bin/dm/src}/services/scope-manager.js +0 -0
- /package/{src → bin/dm/src}/services/structure-detector.js +0 -0
- /package/{src → bin/dm/src}/utils/hash.js +0 -0
- /package/{src → bin/dm/src}/utils/interactive.js +0 -0
- /package/{src → bin/dm/src}/utils/logger.js +0 -0
- /package/{src → bin/dm/src}/utils/npm-registry.js +0 -0
- /package/{src → bin/dm/src}/utils/path-resolver.js +0 -0
|
@@ -0,0 +1,877 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Phase — Phase CRUD, query, and lifecycle operations
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
const fs = require('fs');
|
|
6
|
+
const path = require('path');
|
|
7
|
+
const { normalizePhaseName, findPhaseInternal, getArchivedPhaseDirs, generateSlugInternal, output, error } = require('./core.cjs');
|
|
8
|
+
const { extractFrontmatter } = require('./frontmatter.cjs');
|
|
9
|
+
|
|
10
|
+
function cmdPhasesList(cwd, options, raw) {
|
|
11
|
+
const phasesDir = path.join(cwd, '.planning', 'phases');
|
|
12
|
+
const { type, phase, includeArchived } = options;
|
|
13
|
+
|
|
14
|
+
// If no phases directory, return empty
|
|
15
|
+
if (!fs.existsSync(phasesDir)) {
|
|
16
|
+
if (type) {
|
|
17
|
+
output({ files: [], count: 0 }, raw, '');
|
|
18
|
+
} else {
|
|
19
|
+
output({ directories: [], count: 0 }, raw, '');
|
|
20
|
+
}
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
try {
|
|
25
|
+
// Get all phase directories
|
|
26
|
+
const entries = fs.readdirSync(phasesDir, { withFileTypes: true });
|
|
27
|
+
let dirs = entries.filter(e => e.isDirectory()).map(e => e.name);
|
|
28
|
+
|
|
29
|
+
// Include archived phases if requested
|
|
30
|
+
if (includeArchived) {
|
|
31
|
+
const archived = getArchivedPhaseDirs(cwd);
|
|
32
|
+
for (const a of archived) {
|
|
33
|
+
dirs.push(`${a.name} [${a.milestone}]`);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// Sort numerically (handles decimals: 01, 02, 02.1, 02.2, 03)
|
|
38
|
+
dirs.sort((a, b) => {
|
|
39
|
+
const aNum = parseFloat(a.match(/^(\d+(?:\.\d+)?)/)?.[1] || '0');
|
|
40
|
+
const bNum = parseFloat(b.match(/^(\d+(?:\.\d+)?)/)?.[1] || '0');
|
|
41
|
+
return aNum - bNum;
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
// If filtering by phase number
|
|
45
|
+
if (phase) {
|
|
46
|
+
const normalized = normalizePhaseName(phase);
|
|
47
|
+
const match = dirs.find(d => d.startsWith(normalized));
|
|
48
|
+
if (!match) {
|
|
49
|
+
output({ files: [], count: 0, phase_dir: null, error: 'Phase not found' }, raw, '');
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
dirs = [match];
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// If listing files of a specific type
|
|
56
|
+
if (type) {
|
|
57
|
+
const files = [];
|
|
58
|
+
for (const dir of dirs) {
|
|
59
|
+
const dirPath = path.join(phasesDir, dir);
|
|
60
|
+
const dirFiles = fs.readdirSync(dirPath);
|
|
61
|
+
|
|
62
|
+
let filtered;
|
|
63
|
+
if (type === 'plans') {
|
|
64
|
+
filtered = dirFiles.filter(f => f.endsWith('-PLAN.md') || f === 'PLAN.md');
|
|
65
|
+
} else if (type === 'summaries') {
|
|
66
|
+
filtered = dirFiles.filter(f => f.endsWith('-SUMMARY.md') || f === 'SUMMARY.md');
|
|
67
|
+
} else {
|
|
68
|
+
filtered = dirFiles;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
files.push(...filtered.sort());
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
const result = {
|
|
75
|
+
files,
|
|
76
|
+
count: files.length,
|
|
77
|
+
phase_dir: phase ? dirs[0].replace(/^\d+(?:\.\d+)?-?/, '') : null,
|
|
78
|
+
};
|
|
79
|
+
output(result, raw, files.join('\n'));
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// Default: list directories
|
|
84
|
+
output({ directories: dirs, count: dirs.length }, raw, dirs.join('\n'));
|
|
85
|
+
} catch (e) {
|
|
86
|
+
error('Failed to list phases: ' + e.message);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
function cmdPhaseNextDecimal(cwd, basePhase, raw) {
|
|
91
|
+
const phasesDir = path.join(cwd, '.planning', 'phases');
|
|
92
|
+
const normalized = normalizePhaseName(basePhase);
|
|
93
|
+
|
|
94
|
+
// Check if phases directory exists
|
|
95
|
+
if (!fs.existsSync(phasesDir)) {
|
|
96
|
+
output(
|
|
97
|
+
{
|
|
98
|
+
found: false,
|
|
99
|
+
base_phase: normalized,
|
|
100
|
+
next: `${normalized}.1`,
|
|
101
|
+
existing: [],
|
|
102
|
+
},
|
|
103
|
+
raw,
|
|
104
|
+
`${normalized}.1`
|
|
105
|
+
);
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
try {
|
|
110
|
+
const entries = fs.readdirSync(phasesDir, { withFileTypes: true });
|
|
111
|
+
const dirs = entries.filter(e => e.isDirectory()).map(e => e.name);
|
|
112
|
+
|
|
113
|
+
// Check if base phase exists
|
|
114
|
+
const baseExists = dirs.some(d => d.startsWith(normalized + '-') || d === normalized);
|
|
115
|
+
|
|
116
|
+
// Find existing decimal phases for this base
|
|
117
|
+
const decimalPattern = new RegExp(`^${normalized}\\.(\\d+)`);
|
|
118
|
+
const existingDecimals = [];
|
|
119
|
+
|
|
120
|
+
for (const dir of dirs) {
|
|
121
|
+
const match = dir.match(decimalPattern);
|
|
122
|
+
if (match) {
|
|
123
|
+
existingDecimals.push(`${normalized}.${match[1]}`);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
// Sort numerically
|
|
128
|
+
existingDecimals.sort((a, b) => {
|
|
129
|
+
const aNum = parseFloat(a);
|
|
130
|
+
const bNum = parseFloat(b);
|
|
131
|
+
return aNum - bNum;
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
// Calculate next decimal
|
|
135
|
+
let nextDecimal;
|
|
136
|
+
if (existingDecimals.length === 0) {
|
|
137
|
+
nextDecimal = `${normalized}.1`;
|
|
138
|
+
} else {
|
|
139
|
+
const lastDecimal = existingDecimals[existingDecimals.length - 1];
|
|
140
|
+
const lastNum = parseInt(lastDecimal.split('.')[1], 10);
|
|
141
|
+
nextDecimal = `${normalized}.${lastNum + 1}`;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
output(
|
|
145
|
+
{
|
|
146
|
+
found: baseExists,
|
|
147
|
+
base_phase: normalized,
|
|
148
|
+
next: nextDecimal,
|
|
149
|
+
existing: existingDecimals,
|
|
150
|
+
},
|
|
151
|
+
raw,
|
|
152
|
+
nextDecimal
|
|
153
|
+
);
|
|
154
|
+
} catch (e) {
|
|
155
|
+
error('Failed to calculate next decimal phase: ' + e.message);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
function cmdFindPhase(cwd, phase, raw) {
|
|
160
|
+
if (!phase) {
|
|
161
|
+
error('phase identifier required');
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
const phasesDir = path.join(cwd, '.planning', 'phases');
|
|
165
|
+
const normalized = normalizePhaseName(phase);
|
|
166
|
+
|
|
167
|
+
const notFound = { found: false, directory: null, phase_number: null, phase_name: null, plans: [], summaries: [] };
|
|
168
|
+
|
|
169
|
+
try {
|
|
170
|
+
const entries = fs.readdirSync(phasesDir, { withFileTypes: true });
|
|
171
|
+
const dirs = entries.filter(e => e.isDirectory()).map(e => e.name).sort();
|
|
172
|
+
|
|
173
|
+
const match = dirs.find(d => d.startsWith(normalized));
|
|
174
|
+
if (!match) {
|
|
175
|
+
output(notFound, raw, '');
|
|
176
|
+
return;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
const dirMatch = match.match(/^(\d+(?:\.\d+)?)-?(.*)/);
|
|
180
|
+
const phaseNumber = dirMatch ? dirMatch[1] : normalized;
|
|
181
|
+
const phaseName = dirMatch && dirMatch[2] ? dirMatch[2] : null;
|
|
182
|
+
|
|
183
|
+
const phaseDir = path.join(phasesDir, match);
|
|
184
|
+
const phaseFiles = fs.readdirSync(phaseDir);
|
|
185
|
+
const plans = phaseFiles.filter(f => f.endsWith('-PLAN.md') || f === 'PLAN.md').sort();
|
|
186
|
+
const summaries = phaseFiles.filter(f => f.endsWith('-SUMMARY.md') || f === 'SUMMARY.md').sort();
|
|
187
|
+
|
|
188
|
+
const result = {
|
|
189
|
+
found: true,
|
|
190
|
+
directory: path.join('.planning', 'phases', match),
|
|
191
|
+
phase_number: phaseNumber,
|
|
192
|
+
phase_name: phaseName,
|
|
193
|
+
plans,
|
|
194
|
+
summaries,
|
|
195
|
+
};
|
|
196
|
+
|
|
197
|
+
output(result, raw, result.directory);
|
|
198
|
+
} catch {
|
|
199
|
+
output(notFound, raw, '');
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
function cmdPhasePlanIndex(cwd, phase, raw) {
|
|
204
|
+
if (!phase) {
|
|
205
|
+
error('phase required for phase-plan-index');
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
const phasesDir = path.join(cwd, '.planning', 'phases');
|
|
209
|
+
const normalized = normalizePhaseName(phase);
|
|
210
|
+
|
|
211
|
+
// Find phase directory
|
|
212
|
+
let phaseDir = null;
|
|
213
|
+
let phaseDirName = null;
|
|
214
|
+
try {
|
|
215
|
+
const entries = fs.readdirSync(phasesDir, { withFileTypes: true });
|
|
216
|
+
const dirs = entries.filter(e => e.isDirectory()).map(e => e.name).sort();
|
|
217
|
+
const match = dirs.find(d => d.startsWith(normalized));
|
|
218
|
+
if (match) {
|
|
219
|
+
phaseDir = path.join(phasesDir, match);
|
|
220
|
+
phaseDirName = match;
|
|
221
|
+
}
|
|
222
|
+
} catch {
|
|
223
|
+
// phases dir doesn't exist
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
if (!phaseDir) {
|
|
227
|
+
output({ phase: normalized, error: 'Phase not found', plans: [], waves: {}, incomplete: [], has_checkpoints: false }, raw);
|
|
228
|
+
return;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
// Get all files in phase directory
|
|
232
|
+
const phaseFiles = fs.readdirSync(phaseDir);
|
|
233
|
+
const planFiles = phaseFiles.filter(f => f.endsWith('-PLAN.md') || f === 'PLAN.md').sort();
|
|
234
|
+
const summaryFiles = phaseFiles.filter(f => f.endsWith('-SUMMARY.md') || f === 'SUMMARY.md');
|
|
235
|
+
|
|
236
|
+
// Build set of plan IDs with summaries
|
|
237
|
+
const completedPlanIds = new Set(
|
|
238
|
+
summaryFiles.map(s => s.replace('-SUMMARY.md', '').replace('SUMMARY.md', ''))
|
|
239
|
+
);
|
|
240
|
+
|
|
241
|
+
const plans = [];
|
|
242
|
+
const waves = {};
|
|
243
|
+
const incomplete = [];
|
|
244
|
+
let hasCheckpoints = false;
|
|
245
|
+
|
|
246
|
+
for (const planFile of planFiles) {
|
|
247
|
+
const planId = planFile.replace('-PLAN.md', '').replace('PLAN.md', '');
|
|
248
|
+
const planPath = path.join(phaseDir, planFile);
|
|
249
|
+
const content = fs.readFileSync(planPath, 'utf-8');
|
|
250
|
+
const fm = extractFrontmatter(content);
|
|
251
|
+
|
|
252
|
+
// Count tasks (## task N patterns)
|
|
253
|
+
const taskMatches = content.match(/##\s*task\s*\d+/gi) || [];
|
|
254
|
+
const taskCount = taskMatches.length;
|
|
255
|
+
|
|
256
|
+
// Parse wave as integer
|
|
257
|
+
const wave = parseInt(fm.wave, 10) || 1;
|
|
258
|
+
|
|
259
|
+
// Parse autonomous (default true if not specified)
|
|
260
|
+
let autonomous = true;
|
|
261
|
+
if (fm.autonomous !== undefined) {
|
|
262
|
+
autonomous = fm.autonomous === 'true' || fm.autonomous === true;
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
if (!autonomous) {
|
|
266
|
+
hasCheckpoints = true;
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
// Parse files-modified
|
|
270
|
+
let filesModified = [];
|
|
271
|
+
if (fm['files-modified']) {
|
|
272
|
+
filesModified = Array.isArray(fm['files-modified']) ? fm['files-modified'] : [fm['files-modified']];
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
const hasSummary = completedPlanIds.has(planId);
|
|
276
|
+
if (!hasSummary) {
|
|
277
|
+
incomplete.push(planId);
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
const plan = {
|
|
281
|
+
id: planId,
|
|
282
|
+
wave,
|
|
283
|
+
autonomous,
|
|
284
|
+
objective: fm.objective || null,
|
|
285
|
+
files_modified: filesModified,
|
|
286
|
+
task_count: taskCount,
|
|
287
|
+
has_summary: hasSummary,
|
|
288
|
+
};
|
|
289
|
+
|
|
290
|
+
plans.push(plan);
|
|
291
|
+
|
|
292
|
+
// Group by wave
|
|
293
|
+
const waveKey = String(wave);
|
|
294
|
+
if (!waves[waveKey]) {
|
|
295
|
+
waves[waveKey] = [];
|
|
296
|
+
}
|
|
297
|
+
waves[waveKey].push(planId);
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
const result = {
|
|
301
|
+
phase: normalized,
|
|
302
|
+
plans,
|
|
303
|
+
waves,
|
|
304
|
+
incomplete,
|
|
305
|
+
has_checkpoints: hasCheckpoints,
|
|
306
|
+
};
|
|
307
|
+
|
|
308
|
+
output(result, raw);
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
function cmdPhaseAdd(cwd, description, raw) {
|
|
312
|
+
if (!description) {
|
|
313
|
+
error('description required for phase add');
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
const roadmapPath = path.join(cwd, '.planning', 'ROADMAP.md');
|
|
317
|
+
if (!fs.existsSync(roadmapPath)) {
|
|
318
|
+
error('ROADMAP.md not found');
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
const content = fs.readFileSync(roadmapPath, 'utf-8');
|
|
322
|
+
const slug = generateSlugInternal(description);
|
|
323
|
+
|
|
324
|
+
// Find highest integer phase number
|
|
325
|
+
const phasePattern = /#{2,4}\s*Phase\s+(\d+)(?:\.\d+)?:/gi;
|
|
326
|
+
let maxPhase = 0;
|
|
327
|
+
let m;
|
|
328
|
+
while ((m = phasePattern.exec(content)) !== null) {
|
|
329
|
+
const num = parseInt(m[1], 10);
|
|
330
|
+
if (num > maxPhase) maxPhase = num;
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
const newPhaseNum = maxPhase + 1;
|
|
334
|
+
const paddedNum = String(newPhaseNum).padStart(2, '0');
|
|
335
|
+
const dirName = `${paddedNum}-${slug}`;
|
|
336
|
+
const dirPath = path.join(cwd, '.planning', 'phases', dirName);
|
|
337
|
+
|
|
338
|
+
// Create directory with .gitkeep so git tracks empty folders
|
|
339
|
+
fs.mkdirSync(dirPath, { recursive: true });
|
|
340
|
+
fs.writeFileSync(path.join(dirPath, '.gitkeep'), '');
|
|
341
|
+
|
|
342
|
+
// Build phase entry
|
|
343
|
+
const phaseEntry = `\n### Phase ${newPhaseNum}: ${description}\n\n**Goal:** [To be planned]\n**Depends on:** Phase ${maxPhase}\n**Plans:** 0 plans\n\nPlans:\n- [ ] TBD (run /gsd-plan-phase ${newPhaseNum} to break down)\n`;
|
|
344
|
+
|
|
345
|
+
// Find insertion point: before last "---" or at end
|
|
346
|
+
let updatedContent;
|
|
347
|
+
const lastSeparator = content.lastIndexOf('\n---');
|
|
348
|
+
if (lastSeparator > 0) {
|
|
349
|
+
updatedContent = content.slice(0, lastSeparator) + phaseEntry + content.slice(lastSeparator);
|
|
350
|
+
} else {
|
|
351
|
+
updatedContent = content + phaseEntry;
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
fs.writeFileSync(roadmapPath, updatedContent, 'utf-8');
|
|
355
|
+
|
|
356
|
+
const result = {
|
|
357
|
+
phase_number: newPhaseNum,
|
|
358
|
+
padded: paddedNum,
|
|
359
|
+
name: description,
|
|
360
|
+
slug,
|
|
361
|
+
directory: `.planning/phases/${dirName}`,
|
|
362
|
+
};
|
|
363
|
+
|
|
364
|
+
output(result, raw, paddedNum);
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
function cmdPhaseInsert(cwd, afterPhase, description, raw) {
|
|
368
|
+
if (!afterPhase || !description) {
|
|
369
|
+
error('after-phase and description required for phase insert');
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
const roadmapPath = path.join(cwd, '.planning', 'ROADMAP.md');
|
|
373
|
+
if (!fs.existsSync(roadmapPath)) {
|
|
374
|
+
error('ROADMAP.md not found');
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
const content = fs.readFileSync(roadmapPath, 'utf-8');
|
|
378
|
+
const slug = generateSlugInternal(description);
|
|
379
|
+
|
|
380
|
+
// Normalize input then strip leading zeros for flexible matching
|
|
381
|
+
const normalizedAfter = normalizePhaseName(afterPhase);
|
|
382
|
+
const unpadded = normalizedAfter.replace(/^0+/, '');
|
|
383
|
+
const afterPhaseEscaped = unpadded.replace(/\./g, '\\.');
|
|
384
|
+
const targetPattern = new RegExp(`#{2,4}\\s*Phase\\s+0*${afterPhaseEscaped}:`, 'i');
|
|
385
|
+
if (!targetPattern.test(content)) {
|
|
386
|
+
error(`Phase ${afterPhase} not found in ROADMAP.md`);
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
// Calculate next decimal using existing logic
|
|
390
|
+
const phasesDir = path.join(cwd, '.planning', 'phases');
|
|
391
|
+
const normalizedBase = normalizePhaseName(afterPhase);
|
|
392
|
+
let existingDecimals = [];
|
|
393
|
+
|
|
394
|
+
try {
|
|
395
|
+
const entries = fs.readdirSync(phasesDir, { withFileTypes: true });
|
|
396
|
+
const dirs = entries.filter(e => e.isDirectory()).map(e => e.name);
|
|
397
|
+
const decimalPattern = new RegExp(`^${normalizedBase}\\.(\\d+)`);
|
|
398
|
+
for (const dir of dirs) {
|
|
399
|
+
const dm = dir.match(decimalPattern);
|
|
400
|
+
if (dm) existingDecimals.push(parseInt(dm[1], 10));
|
|
401
|
+
}
|
|
402
|
+
} catch {}
|
|
403
|
+
|
|
404
|
+
const nextDecimal = existingDecimals.length === 0 ? 1 : Math.max(...existingDecimals) + 1;
|
|
405
|
+
const decimalPhase = `${normalizedBase}.${nextDecimal}`;
|
|
406
|
+
const dirName = `${decimalPhase}-${slug}`;
|
|
407
|
+
const dirPath = path.join(cwd, '.planning', 'phases', dirName);
|
|
408
|
+
|
|
409
|
+
// Create directory with .gitkeep so git tracks empty folders
|
|
410
|
+
fs.mkdirSync(dirPath, { recursive: true });
|
|
411
|
+
fs.writeFileSync(path.join(dirPath, '.gitkeep'), '');
|
|
412
|
+
|
|
413
|
+
// Build phase entry
|
|
414
|
+
const phaseEntry = `\n### Phase ${decimalPhase}: ${description} (INSERTED)\n\n**Goal:** [Urgent work - to be planned]\n**Depends on:** Phase ${afterPhase}\n**Plans:** 0 plans\n\nPlans:\n- [ ] TBD (run /gsd-plan-phase ${decimalPhase} to break down)\n`;
|
|
415
|
+
|
|
416
|
+
// Insert after the target phase section
|
|
417
|
+
const headerPattern = new RegExp(`(#{2,4}\\s*Phase\\s+0*${afterPhaseEscaped}:[^\\n]*\\n)`, 'i');
|
|
418
|
+
const headerMatch = content.match(headerPattern);
|
|
419
|
+
if (!headerMatch) {
|
|
420
|
+
error(`Could not find Phase ${afterPhase} header`);
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
const headerIdx = content.indexOf(headerMatch[0]);
|
|
424
|
+
const afterHeader = content.slice(headerIdx + headerMatch[0].length);
|
|
425
|
+
const nextPhaseMatch = afterHeader.match(/\n#{2,4}\s+Phase\s+\d/i);
|
|
426
|
+
|
|
427
|
+
let insertIdx;
|
|
428
|
+
if (nextPhaseMatch) {
|
|
429
|
+
insertIdx = headerIdx + headerMatch[0].length + nextPhaseMatch.index;
|
|
430
|
+
} else {
|
|
431
|
+
insertIdx = content.length;
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
const updatedContent = content.slice(0, insertIdx) + phaseEntry + content.slice(insertIdx);
|
|
435
|
+
fs.writeFileSync(roadmapPath, updatedContent, 'utf-8');
|
|
436
|
+
|
|
437
|
+
const result = {
|
|
438
|
+
phase_number: decimalPhase,
|
|
439
|
+
after_phase: afterPhase,
|
|
440
|
+
name: description,
|
|
441
|
+
slug,
|
|
442
|
+
directory: `.planning/phases/${dirName}`,
|
|
443
|
+
};
|
|
444
|
+
|
|
445
|
+
output(result, raw, decimalPhase);
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
function cmdPhaseRemove(cwd, targetPhase, options, raw) {
|
|
449
|
+
if (!targetPhase) {
|
|
450
|
+
error('phase number required for phase remove');
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
const roadmapPath = path.join(cwd, '.planning', 'ROADMAP.md');
|
|
454
|
+
const phasesDir = path.join(cwd, '.planning', 'phases');
|
|
455
|
+
const force = options.force || false;
|
|
456
|
+
|
|
457
|
+
if (!fs.existsSync(roadmapPath)) {
|
|
458
|
+
error('ROADMAP.md not found');
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
// Normalize the target
|
|
462
|
+
const normalized = normalizePhaseName(targetPhase);
|
|
463
|
+
const isDecimal = targetPhase.includes('.');
|
|
464
|
+
|
|
465
|
+
// Find and validate target directory
|
|
466
|
+
let targetDir = null;
|
|
467
|
+
try {
|
|
468
|
+
const entries = fs.readdirSync(phasesDir, { withFileTypes: true });
|
|
469
|
+
const dirs = entries.filter(e => e.isDirectory()).map(e => e.name).sort();
|
|
470
|
+
targetDir = dirs.find(d => d.startsWith(normalized + '-') || d === normalized);
|
|
471
|
+
} catch {}
|
|
472
|
+
|
|
473
|
+
// Check for executed work (SUMMARY.md files)
|
|
474
|
+
if (targetDir && !force) {
|
|
475
|
+
const targetPath = path.join(phasesDir, targetDir);
|
|
476
|
+
const files = fs.readdirSync(targetPath);
|
|
477
|
+
const summaries = files.filter(f => f.endsWith('-SUMMARY.md') || f === 'SUMMARY.md');
|
|
478
|
+
if (summaries.length > 0) {
|
|
479
|
+
error(`Phase ${targetPhase} has ${summaries.length} executed plan(s). Use --force to remove anyway.`);
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
// Delete target directory
|
|
484
|
+
if (targetDir) {
|
|
485
|
+
fs.rmSync(path.join(phasesDir, targetDir), { recursive: true, force: true });
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
// Renumber subsequent phases
|
|
489
|
+
const renamedDirs = [];
|
|
490
|
+
const renamedFiles = [];
|
|
491
|
+
|
|
492
|
+
if (isDecimal) {
|
|
493
|
+
// Decimal removal: renumber sibling decimals (e.g., removing 06.2 → 06.3 becomes 06.2)
|
|
494
|
+
const baseParts = normalized.split('.');
|
|
495
|
+
const baseInt = baseParts[0];
|
|
496
|
+
const removedDecimal = parseInt(baseParts[1], 10);
|
|
497
|
+
|
|
498
|
+
try {
|
|
499
|
+
const entries = fs.readdirSync(phasesDir, { withFileTypes: true });
|
|
500
|
+
const dirs = entries.filter(e => e.isDirectory()).map(e => e.name).sort();
|
|
501
|
+
|
|
502
|
+
// Find sibling decimals with higher numbers
|
|
503
|
+
const decPattern = new RegExp(`^${baseInt}\\.(\\d+)-(.+)$`);
|
|
504
|
+
const toRename = [];
|
|
505
|
+
for (const dir of dirs) {
|
|
506
|
+
const dm = dir.match(decPattern);
|
|
507
|
+
if (dm && parseInt(dm[1], 10) > removedDecimal) {
|
|
508
|
+
toRename.push({ dir, oldDecimal: parseInt(dm[1], 10), slug: dm[2] });
|
|
509
|
+
}
|
|
510
|
+
}
|
|
511
|
+
|
|
512
|
+
// Sort descending to avoid conflicts
|
|
513
|
+
toRename.sort((a, b) => b.oldDecimal - a.oldDecimal);
|
|
514
|
+
|
|
515
|
+
for (const item of toRename) {
|
|
516
|
+
const newDecimal = item.oldDecimal - 1;
|
|
517
|
+
const oldPhaseId = `${baseInt}.${item.oldDecimal}`;
|
|
518
|
+
const newPhaseId = `${baseInt}.${newDecimal}`;
|
|
519
|
+
const newDirName = `${baseInt}.${newDecimal}-${item.slug}`;
|
|
520
|
+
|
|
521
|
+
// Rename directory
|
|
522
|
+
fs.renameSync(path.join(phasesDir, item.dir), path.join(phasesDir, newDirName));
|
|
523
|
+
renamedDirs.push({ from: item.dir, to: newDirName });
|
|
524
|
+
|
|
525
|
+
// Rename files inside
|
|
526
|
+
const dirFiles = fs.readdirSync(path.join(phasesDir, newDirName));
|
|
527
|
+
for (const f of dirFiles) {
|
|
528
|
+
// Files may have phase prefix like "06.2-01-PLAN.md"
|
|
529
|
+
if (f.includes(oldPhaseId)) {
|
|
530
|
+
const newFileName = f.replace(oldPhaseId, newPhaseId);
|
|
531
|
+
fs.renameSync(
|
|
532
|
+
path.join(phasesDir, newDirName, f),
|
|
533
|
+
path.join(phasesDir, newDirName, newFileName)
|
|
534
|
+
);
|
|
535
|
+
renamedFiles.push({ from: f, to: newFileName });
|
|
536
|
+
}
|
|
537
|
+
}
|
|
538
|
+
}
|
|
539
|
+
} catch {}
|
|
540
|
+
|
|
541
|
+
} else {
|
|
542
|
+
// Integer removal: renumber all subsequent integer phases
|
|
543
|
+
const removedInt = parseInt(normalized, 10);
|
|
544
|
+
|
|
545
|
+
try {
|
|
546
|
+
const entries = fs.readdirSync(phasesDir, { withFileTypes: true });
|
|
547
|
+
const dirs = entries.filter(e => e.isDirectory()).map(e => e.name).sort();
|
|
548
|
+
|
|
549
|
+
// Collect directories that need renumbering (integer phases > removed, and their decimals)
|
|
550
|
+
const toRename = [];
|
|
551
|
+
for (const dir of dirs) {
|
|
552
|
+
const dm = dir.match(/^(\d+)(?:\.(\d+))?-(.+)$/);
|
|
553
|
+
if (!dm) continue;
|
|
554
|
+
const dirInt = parseInt(dm[1], 10);
|
|
555
|
+
if (dirInt > removedInt) {
|
|
556
|
+
toRename.push({
|
|
557
|
+
dir,
|
|
558
|
+
oldInt: dirInt,
|
|
559
|
+
decimal: dm[2] ? parseInt(dm[2], 10) : null,
|
|
560
|
+
slug: dm[3],
|
|
561
|
+
});
|
|
562
|
+
}
|
|
563
|
+
}
|
|
564
|
+
|
|
565
|
+
// Sort descending to avoid conflicts
|
|
566
|
+
toRename.sort((a, b) => {
|
|
567
|
+
if (a.oldInt !== b.oldInt) return b.oldInt - a.oldInt;
|
|
568
|
+
return (b.decimal || 0) - (a.decimal || 0);
|
|
569
|
+
});
|
|
570
|
+
|
|
571
|
+
for (const item of toRename) {
|
|
572
|
+
const newInt = item.oldInt - 1;
|
|
573
|
+
const newPadded = String(newInt).padStart(2, '0');
|
|
574
|
+
const oldPadded = String(item.oldInt).padStart(2, '0');
|
|
575
|
+
const decimalSuffix = item.decimal !== null ? `.${item.decimal}` : '';
|
|
576
|
+
const oldPrefix = `${oldPadded}${decimalSuffix}`;
|
|
577
|
+
const newPrefix = `${newPadded}${decimalSuffix}`;
|
|
578
|
+
const newDirName = `${newPrefix}-${item.slug}`;
|
|
579
|
+
|
|
580
|
+
// Rename directory
|
|
581
|
+
fs.renameSync(path.join(phasesDir, item.dir), path.join(phasesDir, newDirName));
|
|
582
|
+
renamedDirs.push({ from: item.dir, to: newDirName });
|
|
583
|
+
|
|
584
|
+
// Rename files inside
|
|
585
|
+
const dirFiles = fs.readdirSync(path.join(phasesDir, newDirName));
|
|
586
|
+
for (const f of dirFiles) {
|
|
587
|
+
if (f.startsWith(oldPrefix)) {
|
|
588
|
+
const newFileName = newPrefix + f.slice(oldPrefix.length);
|
|
589
|
+
fs.renameSync(
|
|
590
|
+
path.join(phasesDir, newDirName, f),
|
|
591
|
+
path.join(phasesDir, newDirName, newFileName)
|
|
592
|
+
);
|
|
593
|
+
renamedFiles.push({ from: f, to: newFileName });
|
|
594
|
+
}
|
|
595
|
+
}
|
|
596
|
+
}
|
|
597
|
+
} catch {}
|
|
598
|
+
}
|
|
599
|
+
|
|
600
|
+
// Update ROADMAP.md
|
|
601
|
+
let roadmapContent = fs.readFileSync(roadmapPath, 'utf-8');
|
|
602
|
+
|
|
603
|
+
// Remove the target phase section
|
|
604
|
+
const targetEscaped = targetPhase.replace(/\./g, '\\.');
|
|
605
|
+
const sectionPattern = new RegExp(
|
|
606
|
+
`\\n?#{2,4}\\s*Phase\\s+${targetEscaped}\\s*:[\\s\\S]*?(?=\\n#{2,4}\\s+Phase\\s+\\d|$)`,
|
|
607
|
+
'i'
|
|
608
|
+
);
|
|
609
|
+
roadmapContent = roadmapContent.replace(sectionPattern, '');
|
|
610
|
+
|
|
611
|
+
// Remove from phase list (checkbox)
|
|
612
|
+
const checkboxPattern = new RegExp(`\\n?-\\s*\\[[ x]\\]\\s*.*Phase\\s+${targetEscaped}[:\\s][^\\n]*`, 'gi');
|
|
613
|
+
roadmapContent = roadmapContent.replace(checkboxPattern, '');
|
|
614
|
+
|
|
615
|
+
// Remove from progress table
|
|
616
|
+
const tableRowPattern = new RegExp(`\\n?\\|\\s*${targetEscaped}\\.?\\s[^|]*\\|[^\\n]*`, 'gi');
|
|
617
|
+
roadmapContent = roadmapContent.replace(tableRowPattern, '');
|
|
618
|
+
|
|
619
|
+
// Renumber references in ROADMAP for subsequent phases
|
|
620
|
+
if (!isDecimal) {
|
|
621
|
+
const removedInt = parseInt(normalized, 10);
|
|
622
|
+
|
|
623
|
+
// Collect all integer phases > removedInt
|
|
624
|
+
const maxPhase = 99; // reasonable upper bound
|
|
625
|
+
for (let oldNum = maxPhase; oldNum > removedInt; oldNum--) {
|
|
626
|
+
const newNum = oldNum - 1;
|
|
627
|
+
const oldStr = String(oldNum);
|
|
628
|
+
const newStr = String(newNum);
|
|
629
|
+
const oldPad = oldStr.padStart(2, '0');
|
|
630
|
+
const newPad = newStr.padStart(2, '0');
|
|
631
|
+
|
|
632
|
+
// Phase headings: ## Phase 18: or ### Phase 18: → ## Phase 17: or ### Phase 17:
|
|
633
|
+
roadmapContent = roadmapContent.replace(
|
|
634
|
+
new RegExp(`(#{2,4}\\s*Phase\\s+)${oldStr}(\\s*:)`, 'gi'),
|
|
635
|
+
`$1${newStr}$2`
|
|
636
|
+
);
|
|
637
|
+
|
|
638
|
+
// Checkbox items: - [ ] **Phase 18:** → - [ ] **Phase 17:**
|
|
639
|
+
roadmapContent = roadmapContent.replace(
|
|
640
|
+
new RegExp(`(Phase\\s+)${oldStr}([:\\s])`, 'g'),
|
|
641
|
+
`$1${newStr}$2`
|
|
642
|
+
);
|
|
643
|
+
|
|
644
|
+
// Plan references: 18-01 → 17-01
|
|
645
|
+
roadmapContent = roadmapContent.replace(
|
|
646
|
+
new RegExp(`${oldPad}-(\\d{2})`, 'g'),
|
|
647
|
+
`${newPad}-$1`
|
|
648
|
+
);
|
|
649
|
+
|
|
650
|
+
// Table rows: | 18. → | 17.
|
|
651
|
+
roadmapContent = roadmapContent.replace(
|
|
652
|
+
new RegExp(`(\\|\\s*)${oldStr}\\.\\s`, 'g'),
|
|
653
|
+
`$1${newStr}. `
|
|
654
|
+
);
|
|
655
|
+
|
|
656
|
+
// Depends on references
|
|
657
|
+
roadmapContent = roadmapContent.replace(
|
|
658
|
+
new RegExp(`(Depends on:\\*\\*\\s*Phase\\s+)${oldStr}\\b`, 'gi'),
|
|
659
|
+
`$1${newStr}`
|
|
660
|
+
);
|
|
661
|
+
}
|
|
662
|
+
}
|
|
663
|
+
|
|
664
|
+
fs.writeFileSync(roadmapPath, roadmapContent, 'utf-8');
|
|
665
|
+
|
|
666
|
+
// Update STATE.md phase count
|
|
667
|
+
const statePath = path.join(cwd, '.planning', 'STATE.md');
|
|
668
|
+
if (fs.existsSync(statePath)) {
|
|
669
|
+
let stateContent = fs.readFileSync(statePath, 'utf-8');
|
|
670
|
+
// Update "Total Phases" field
|
|
671
|
+
const totalPattern = /(\*\*Total Phases:\*\*\s*)(\d+)/;
|
|
672
|
+
const totalMatch = stateContent.match(totalPattern);
|
|
673
|
+
if (totalMatch) {
|
|
674
|
+
const oldTotal = parseInt(totalMatch[2], 10);
|
|
675
|
+
stateContent = stateContent.replace(totalPattern, `$1${oldTotal - 1}`);
|
|
676
|
+
}
|
|
677
|
+
// Update "Phase: X of Y" pattern
|
|
678
|
+
const ofPattern = /(\bof\s+)(\d+)(\s*(?:\(|phases?))/i;
|
|
679
|
+
const ofMatch = stateContent.match(ofPattern);
|
|
680
|
+
if (ofMatch) {
|
|
681
|
+
const oldTotal = parseInt(ofMatch[2], 10);
|
|
682
|
+
stateContent = stateContent.replace(ofPattern, `$1${oldTotal - 1}$3`);
|
|
683
|
+
}
|
|
684
|
+
fs.writeFileSync(statePath, stateContent, 'utf-8');
|
|
685
|
+
}
|
|
686
|
+
|
|
687
|
+
const result = {
|
|
688
|
+
removed: targetPhase,
|
|
689
|
+
directory_deleted: targetDir || null,
|
|
690
|
+
renamed_directories: renamedDirs,
|
|
691
|
+
renamed_files: renamedFiles,
|
|
692
|
+
roadmap_updated: true,
|
|
693
|
+
state_updated: fs.existsSync(statePath),
|
|
694
|
+
};
|
|
695
|
+
|
|
696
|
+
output(result, raw);
|
|
697
|
+
}
|
|
698
|
+
|
|
699
|
+
function cmdPhaseComplete(cwd, phaseNum, raw) {
|
|
700
|
+
if (!phaseNum) {
|
|
701
|
+
error('phase number required for phase complete');
|
|
702
|
+
}
|
|
703
|
+
|
|
704
|
+
const roadmapPath = path.join(cwd, '.planning', 'ROADMAP.md');
|
|
705
|
+
const statePath = path.join(cwd, '.planning', 'STATE.md');
|
|
706
|
+
const phasesDir = path.join(cwd, '.planning', 'phases');
|
|
707
|
+
const normalized = normalizePhaseName(phaseNum);
|
|
708
|
+
const today = new Date().toISOString().split('T')[0];
|
|
709
|
+
|
|
710
|
+
// Verify phase info
|
|
711
|
+
const phaseInfo = findPhaseInternal(cwd, phaseNum);
|
|
712
|
+
if (!phaseInfo) {
|
|
713
|
+
error(`Phase ${phaseNum} not found`);
|
|
714
|
+
}
|
|
715
|
+
|
|
716
|
+
const planCount = phaseInfo.plans.length;
|
|
717
|
+
const summaryCount = phaseInfo.summaries.length;
|
|
718
|
+
|
|
719
|
+
// Update ROADMAP.md: mark phase complete
|
|
720
|
+
if (fs.existsSync(roadmapPath)) {
|
|
721
|
+
let roadmapContent = fs.readFileSync(roadmapPath, 'utf-8');
|
|
722
|
+
|
|
723
|
+
// Checkbox: - [ ] Phase N: → - [x] Phase N: (...completed DATE)
|
|
724
|
+
const checkboxPattern = new RegExp(
|
|
725
|
+
`(-\\s*\\[)[ ](\\]\\s*.*Phase\\s+${phaseNum.replace('.', '\\.')}[:\\s][^\\n]*)`,
|
|
726
|
+
'i'
|
|
727
|
+
);
|
|
728
|
+
roadmapContent = roadmapContent.replace(checkboxPattern, `$1x$2 (completed ${today})`);
|
|
729
|
+
|
|
730
|
+
// Progress table: update Status to Complete, add date
|
|
731
|
+
const phaseEscaped = phaseNum.replace('.', '\\.');
|
|
732
|
+
const tablePattern = new RegExp(
|
|
733
|
+
`(\\|\\s*${phaseEscaped}\\.?\\s[^|]*\\|[^|]*\\|)\\s*[^|]*(\\|)\\s*[^|]*(\\|)`,
|
|
734
|
+
'i'
|
|
735
|
+
);
|
|
736
|
+
roadmapContent = roadmapContent.replace(
|
|
737
|
+
tablePattern,
|
|
738
|
+
`$1 Complete $2 ${today} $3`
|
|
739
|
+
);
|
|
740
|
+
|
|
741
|
+
// Update plan count in phase section
|
|
742
|
+
const planCountPattern = new RegExp(
|
|
743
|
+
`(#{2,4}\\s*Phase\\s+${phaseEscaped}[\\s\\S]*?\\*\\*Plans:\\*\\*\\s*)[^\\n]+`,
|
|
744
|
+
'i'
|
|
745
|
+
);
|
|
746
|
+
roadmapContent = roadmapContent.replace(
|
|
747
|
+
planCountPattern,
|
|
748
|
+
`$1${summaryCount}/${planCount} plans complete`
|
|
749
|
+
);
|
|
750
|
+
|
|
751
|
+
fs.writeFileSync(roadmapPath, roadmapContent, 'utf-8');
|
|
752
|
+
|
|
753
|
+
// Update REQUIREMENTS.md traceability for this phase's requirements
|
|
754
|
+
const reqPath = path.join(cwd, '.planning', 'REQUIREMENTS.md');
|
|
755
|
+
if (fs.existsSync(reqPath)) {
|
|
756
|
+
// Extract Requirements line from roadmap for this phase
|
|
757
|
+
const reqMatch = roadmapContent.match(
|
|
758
|
+
new RegExp(`Phase\\s+${phaseNum.replace('.', '\\.')}[\\s\\S]*?\\*\\*Requirements:\\*\\*\\s*([^\\n]+)`, 'i')
|
|
759
|
+
);
|
|
760
|
+
|
|
761
|
+
if (reqMatch) {
|
|
762
|
+
const reqIds = reqMatch[1].replace(/[\[\]]/g, '').split(/[,\s]+/).map(r => r.trim()).filter(Boolean);
|
|
763
|
+
let reqContent = fs.readFileSync(reqPath, 'utf-8');
|
|
764
|
+
|
|
765
|
+
for (const reqId of reqIds) {
|
|
766
|
+
// Update checkbox: - [ ] **REQ-ID** → - [x] **REQ-ID**
|
|
767
|
+
reqContent = reqContent.replace(
|
|
768
|
+
new RegExp(`(-\\s*\\[)[ ](\\]\\s*\\*\\*${reqId}\\*\\*)`, 'gi'),
|
|
769
|
+
'$1x$2'
|
|
770
|
+
);
|
|
771
|
+
// Update traceability table: | REQ-ID | Phase N | Pending | → | REQ-ID | Phase N | Complete |
|
|
772
|
+
reqContent = reqContent.replace(
|
|
773
|
+
new RegExp(`(\\|\\s*${reqId}\\s*\\|[^|]+\\|)\\s*Pending\\s*(\\|)`, 'gi'),
|
|
774
|
+
'$1 Complete $2'
|
|
775
|
+
);
|
|
776
|
+
}
|
|
777
|
+
|
|
778
|
+
fs.writeFileSync(reqPath, reqContent, 'utf-8');
|
|
779
|
+
}
|
|
780
|
+
}
|
|
781
|
+
}
|
|
782
|
+
|
|
783
|
+
// Find next phase
|
|
784
|
+
let nextPhaseNum = null;
|
|
785
|
+
let nextPhaseName = null;
|
|
786
|
+
let isLastPhase = true;
|
|
787
|
+
|
|
788
|
+
try {
|
|
789
|
+
const entries = fs.readdirSync(phasesDir, { withFileTypes: true });
|
|
790
|
+
const dirs = entries.filter(e => e.isDirectory()).map(e => e.name).sort();
|
|
791
|
+
const currentFloat = parseFloat(phaseNum);
|
|
792
|
+
|
|
793
|
+
// Find the next phase directory after current
|
|
794
|
+
for (const dir of dirs) {
|
|
795
|
+
const dm = dir.match(/^(\d+(?:\.\d+)?)-?(.*)/);
|
|
796
|
+
if (dm) {
|
|
797
|
+
const dirFloat = parseFloat(dm[1]);
|
|
798
|
+
if (dirFloat > currentFloat) {
|
|
799
|
+
nextPhaseNum = dm[1];
|
|
800
|
+
nextPhaseName = dm[2] || null;
|
|
801
|
+
isLastPhase = false;
|
|
802
|
+
break;
|
|
803
|
+
}
|
|
804
|
+
}
|
|
805
|
+
}
|
|
806
|
+
} catch {}
|
|
807
|
+
|
|
808
|
+
// Update STATE.md
|
|
809
|
+
if (fs.existsSync(statePath)) {
|
|
810
|
+
let stateContent = fs.readFileSync(statePath, 'utf-8');
|
|
811
|
+
|
|
812
|
+
// Update Current Phase
|
|
813
|
+
stateContent = stateContent.replace(
|
|
814
|
+
/(\*\*Current Phase:\*\*\s*).*/,
|
|
815
|
+
`$1${nextPhaseNum || phaseNum}`
|
|
816
|
+
);
|
|
817
|
+
|
|
818
|
+
// Update Current Phase Name
|
|
819
|
+
if (nextPhaseName) {
|
|
820
|
+
stateContent = stateContent.replace(
|
|
821
|
+
/(\*\*Current Phase Name:\*\*\s*).*/,
|
|
822
|
+
`$1${nextPhaseName.replace(/-/g, ' ')}`
|
|
823
|
+
);
|
|
824
|
+
}
|
|
825
|
+
|
|
826
|
+
// Update Status
|
|
827
|
+
stateContent = stateContent.replace(
|
|
828
|
+
/(\*\*Status:\*\*\s*).*/,
|
|
829
|
+
`$1${isLastPhase ? 'Milestone complete' : 'Ready to plan'}`
|
|
830
|
+
);
|
|
831
|
+
|
|
832
|
+
// Update Current Plan
|
|
833
|
+
stateContent = stateContent.replace(
|
|
834
|
+
/(\*\*Current Plan:\*\*\s*).*/,
|
|
835
|
+
`$1Not started`
|
|
836
|
+
);
|
|
837
|
+
|
|
838
|
+
// Update Last Activity
|
|
839
|
+
stateContent = stateContent.replace(
|
|
840
|
+
/(\*\*Last Activity:\*\*\s*).*/,
|
|
841
|
+
`$1${today}`
|
|
842
|
+
);
|
|
843
|
+
|
|
844
|
+
// Update Last Activity Description
|
|
845
|
+
stateContent = stateContent.replace(
|
|
846
|
+
/(\*\*Last Activity Description:\*\*\s*).*/,
|
|
847
|
+
`$1Phase ${phaseNum} complete${nextPhaseNum ? `, transitioned to Phase ${nextPhaseNum}` : ''}`
|
|
848
|
+
);
|
|
849
|
+
|
|
850
|
+
fs.writeFileSync(statePath, stateContent, 'utf-8');
|
|
851
|
+
}
|
|
852
|
+
|
|
853
|
+
const result = {
|
|
854
|
+
completed_phase: phaseNum,
|
|
855
|
+
phase_name: phaseInfo.phase_name,
|
|
856
|
+
plans_executed: `${summaryCount}/${planCount}`,
|
|
857
|
+
next_phase: nextPhaseNum,
|
|
858
|
+
next_phase_name: nextPhaseName,
|
|
859
|
+
is_last_phase: isLastPhase,
|
|
860
|
+
date: today,
|
|
861
|
+
roadmap_updated: fs.existsSync(roadmapPath),
|
|
862
|
+
state_updated: fs.existsSync(statePath),
|
|
863
|
+
};
|
|
864
|
+
|
|
865
|
+
output(result, raw);
|
|
866
|
+
}
|
|
867
|
+
|
|
868
|
+
module.exports = {
|
|
869
|
+
cmdPhasesList,
|
|
870
|
+
cmdPhaseNextDecimal,
|
|
871
|
+
cmdFindPhase,
|
|
872
|
+
cmdPhasePlanIndex,
|
|
873
|
+
cmdPhaseAdd,
|
|
874
|
+
cmdPhaseInsert,
|
|
875
|
+
cmdPhaseRemove,
|
|
876
|
+
cmdPhaseComplete,
|
|
877
|
+
};
|