gsdd-cli 0.18.4 → 0.19.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/LICENSE +21 -21
- package/README.md +625 -607
- package/agents/DISTILLATION.md +421 -421
- package/agents/README.md +62 -62
- package/agents/approach-explorer.md +361 -361
- package/agents/debugger.md +82 -82
- package/agents/executor.md +394 -394
- package/agents/integration-checker.md +318 -318
- package/agents/mapper.md +103 -103
- package/agents/planner.md +313 -313
- package/agents/researcher.md +84 -84
- package/agents/roadmapper.md +296 -296
- package/agents/synthesizer.md +236 -236
- package/agents/verifier.md +337 -337
- package/bin/adapters/agents.mjs +34 -34
- package/bin/adapters/claude.mjs +191 -191
- package/bin/adapters/codex.mjs +85 -85
- package/bin/adapters/index.mjs +20 -20
- package/bin/adapters/opencode.mjs +278 -278
- package/bin/gsdd.mjs +123 -116
- package/bin/lib/cli-utils.mjs +28 -28
- package/bin/lib/evidence-contract.mjs +112 -112
- package/bin/lib/file-ops.mjs +209 -161
- package/bin/lib/health-truth.mjs +181 -178
- package/bin/lib/health.mjs +265 -235
- package/bin/lib/init-flow.mjs +252 -236
- package/bin/lib/init-prompts.mjs +248 -247
- package/bin/lib/init-runtime.mjs +225 -212
- package/bin/lib/init.mjs +17 -17
- package/bin/lib/lifecycle-preflight.mjs +360 -333
- package/bin/lib/lifecycle-state.mjs +351 -267
- package/bin/lib/manifest.mjs +116 -114
- package/bin/lib/models.mjs +411 -411
- package/bin/lib/phase.mjs +397 -378
- package/bin/lib/plan-constants.mjs +30 -30
- package/bin/lib/provenance.mjs +109 -106
- package/bin/lib/rendering.mjs +178 -130
- package/bin/lib/runtime-freshness.mjs +221 -219
- package/bin/lib/templates.mjs +225 -224
- package/bin/lib/workspace-root.mjs +132 -0
- package/distilled/DESIGN.md +2347 -2327
- package/distilled/EVIDENCE-INDEX.md +397 -394
- package/distilled/README.md +196 -193
- package/distilled/SKILL.md +86 -85
- package/distilled/templates/agents.block.md +21 -21
- package/distilled/templates/agents.md +6 -6
- package/distilled/templates/approach.md +232 -232
- package/distilled/templates/auth-matrix.md +78 -78
- package/distilled/templates/brownfield-change/CHANGE.md +99 -0
- package/distilled/templates/brownfield-change/HANDOFF.md +38 -0
- package/distilled/templates/brownfield-change/VERIFICATION.md +56 -0
- package/distilled/templates/codebase/architecture.md +110 -110
- package/distilled/templates/codebase/concerns.md +95 -95
- package/distilled/templates/codebase/conventions.md +193 -193
- package/distilled/templates/codebase/stack.md +96 -96
- package/distilled/templates/delegates/approach-explorer.md +25 -25
- package/distilled/templates/delegates/mapper-arch.md +26 -26
- package/distilled/templates/delegates/mapper-concerns.md +27 -27
- package/distilled/templates/delegates/mapper-quality.md +28 -28
- package/distilled/templates/delegates/mapper-tech.md +25 -25
- package/distilled/templates/delegates/plan-checker.md +68 -68
- package/distilled/templates/delegates/researcher-architecture.md +30 -30
- package/distilled/templates/delegates/researcher-features.md +30 -30
- package/distilled/templates/delegates/researcher-pitfalls.md +30 -30
- package/distilled/templates/delegates/researcher-stack.md +30 -30
- package/distilled/templates/delegates/researcher-synthesizer.md +31 -31
- package/distilled/templates/research/architecture.md +57 -57
- package/distilled/templates/research/features.md +23 -23
- package/distilled/templates/research/pitfalls.md +46 -46
- package/distilled/templates/research/stack.md +45 -45
- package/distilled/templates/research/summary.md +67 -67
- package/distilled/templates/roadmap.md +74 -62
- package/distilled/templates/spec.md +110 -110
- package/distilled/workflows/audit-milestone.md +275 -271
- package/distilled/workflows/complete-milestone.md +336 -332
- package/distilled/workflows/execute.md +454 -449
- package/distilled/workflows/map-codebase.md +253 -253
- package/distilled/workflows/new-milestone.md +242 -238
- package/distilled/workflows/new-project.md +398 -398
- package/distilled/workflows/pause.md +160 -156
- package/distilled/workflows/plan-milestone-gaps.md +183 -183
- package/distilled/workflows/plan.md +451 -447
- package/distilled/workflows/progress.md +227 -223
- package/distilled/workflows/quick.md +351 -347
- package/distilled/workflows/resume.md +220 -212
- package/distilled/workflows/verify-work.md +260 -260
- package/distilled/workflows/verify.md +431 -429
- package/docs/BROWNFIELD-PROOF.md +95 -95
- package/docs/RUNTIME-SUPPORT.md +93 -75
- package/docs/USER-GUIDE.md +440 -399
- package/docs/VERIFICATION-DISCIPLINE.md +59 -59
- package/docs/claude/context-monitor.md +98 -98
- package/docs/proof/consumer-node-cli/README.md +37 -37
- package/docs/proof/consumer-node-cli/ROADMAP.md +14 -14
- package/docs/proof/consumer-node-cli/SPEC.md +17 -17
- package/docs/proof/consumer-node-cli/brief.md +9 -9
- package/docs/proof/consumer-node-cli/phases/01-foundation/01-01-PLAN.md +34 -34
- package/docs/proof/consumer-node-cli/phases/01-foundation/01-01-SUMMARY.md +10 -10
- package/docs/proof/consumer-node-cli/phases/01-foundation/01-VERIFICATION.md +30 -30
- package/package.json +62 -61
package/bin/lib/phase.mjs
CHANGED
|
@@ -1,378 +1,397 @@
|
|
|
1
|
-
// phase.mjs — Phase discovery, verification, and scaffolding
|
|
2
|
-
//
|
|
3
|
-
// IMPORTANT: No module-scope process.cwd() — ESM caching means sub-modules
|
|
4
|
-
// evaluate once, so CWD must be computed inside function bodies.
|
|
5
|
-
|
|
6
|
-
import { existsSync, mkdirSync, readFileSync, writeFileSync, readdirSync } from 'fs';
|
|
7
|
-
import { join, basename } from 'path';
|
|
8
|
-
import { output } from './cli-utils.mjs';
|
|
9
|
-
import { writeFingerprint } from './session-fingerprint.mjs';
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
const
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
const
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
const
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
const
|
|
133
|
-
.
|
|
134
|
-
|
|
135
|
-
const
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
const
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
1
|
+
// phase.mjs — Phase discovery, verification, and scaffolding
|
|
2
|
+
//
|
|
3
|
+
// IMPORTANT: No module-scope process.cwd() — ESM caching means sub-modules
|
|
4
|
+
// evaluate once, so CWD must be computed inside function bodies.
|
|
5
|
+
|
|
6
|
+
import { existsSync, mkdirSync, readFileSync, writeFileSync, readdirSync } from 'fs';
|
|
7
|
+
import { join, basename } from 'path';
|
|
8
|
+
import { output } from './cli-utils.mjs';
|
|
9
|
+
import { writeFingerprint } from './session-fingerprint.mjs';
|
|
10
|
+
import { resolveWorkspaceContext } from './workspace-root.mjs';
|
|
11
|
+
|
|
12
|
+
const PHASE_STATUS_MARKERS = {
|
|
13
|
+
not_started: '[ ]',
|
|
14
|
+
todo: '[ ]',
|
|
15
|
+
in_progress: '[-]',
|
|
16
|
+
done: '[x]',
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
const PHASE_MARKER_RE = '(\\[[ x]\\]|\\[-\\]|⬜|ðŸ"„|✅|⬜|🔄|✅)';
|
|
20
|
+
const PHASE_TOKEN_RE = '(\\d+(?:\\.\\d+)*[a-z]?)';
|
|
21
|
+
const PHASE_LINE_RE = new RegExp(
|
|
22
|
+
`^[-*]\\s*${PHASE_MARKER_RE}\\s*\\*\\*Phase\\s+${PHASE_TOKEN_RE}:\\s*(.+?)\\*\\*`,
|
|
23
|
+
'i'
|
|
24
|
+
);
|
|
25
|
+
const ROADMAP_PHASE_STATUS_RE = new RegExp(
|
|
26
|
+
`^(\\s*[-*]\\s*)${PHASE_MARKER_RE}(\\s*\\*\\*Phase\\s+${PHASE_TOKEN_RE}:.*)$`,
|
|
27
|
+
'i'
|
|
28
|
+
);
|
|
29
|
+
const PHASE_DETAIL_HEADING_RE = new RegExp(`^#{3,}\\s+Phase\\s+${PHASE_TOKEN_RE}(?::|\\b)`, 'i');
|
|
30
|
+
const PHASE_DETAIL_STATUS_RE = new RegExp(`^(\\s*\\*\\*Status\\*\\*:\\s*)${PHASE_MARKER_RE}(.*)$`, 'i');
|
|
31
|
+
const DETAILS_OPEN_RE = /<details\b/i;
|
|
32
|
+
const DETAILS_CLOSE_RE = /<\/details>/i;
|
|
33
|
+
|
|
34
|
+
function findFiles(dir, prefix) {
|
|
35
|
+
if (!existsSync(dir)) return [];
|
|
36
|
+
|
|
37
|
+
const phaseArtifactPrefix = String(prefix).match(/^(\d+(?:\.\d+)*[a-z]?)-(PLAN|SUMMARY)$/i);
|
|
38
|
+
if (!phaseArtifactPrefix) {
|
|
39
|
+
return readdirSync(dir).filter((f) => f.startsWith(prefix) || f.startsWith(prefix.replace(/^0+/, '')));
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const targetPhase = normalizePhaseToken(phaseArtifactPrefix[1]);
|
|
43
|
+
const targetKind = phaseArtifactPrefix[2].toUpperCase();
|
|
44
|
+
|
|
45
|
+
return listPhaseArtifacts(dir)
|
|
46
|
+
.filter((artifact) => artifact.phaseToken === targetPhase && artifact.kind === targetKind)
|
|
47
|
+
.map((artifact) => artifact.displayPath);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function listPhaseArtifacts(dir) {
|
|
51
|
+
if (!existsSync(dir)) return [];
|
|
52
|
+
|
|
53
|
+
const artifacts = [];
|
|
54
|
+
for (const entry of readdirSync(dir, { withFileTypes: true })) {
|
|
55
|
+
if (entry.isFile()) {
|
|
56
|
+
const artifact = classifyPhaseArtifact('', entry.name);
|
|
57
|
+
if (artifact) artifacts.push(artifact);
|
|
58
|
+
continue;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
if (!entry.isDirectory()) continue;
|
|
62
|
+
|
|
63
|
+
const entryPath = join(dir, entry.name);
|
|
64
|
+
for (const child of readdirSync(entryPath, { withFileTypes: true })) {
|
|
65
|
+
if (!child.isFile()) continue;
|
|
66
|
+
const artifact = classifyPhaseArtifact(entry.name, child.name);
|
|
67
|
+
if (artifact) artifacts.push(artifact);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
return artifacts;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function classifyPhaseArtifact(dir, name) {
|
|
75
|
+
const dirMatch = dir ? dir.match(/^(\d+(?:\.\d+)*[a-z]?)-/i) : null;
|
|
76
|
+
const nameMatch = name.match(/^(\d+(?:\.\d+)*[a-z]?)/i);
|
|
77
|
+
const phaseToken = normalizePhaseToken((dirMatch || nameMatch)?.[1] || '');
|
|
78
|
+
|
|
79
|
+
let kind = 'OTHER';
|
|
80
|
+
if (name.includes('PLAN')) kind = 'PLAN';
|
|
81
|
+
else if (name.includes('SUMMARY')) kind = 'SUMMARY';
|
|
82
|
+
|
|
83
|
+
return {
|
|
84
|
+
dir,
|
|
85
|
+
name,
|
|
86
|
+
displayPath: dir ? `${dir}/${name}` : name,
|
|
87
|
+
phaseToken,
|
|
88
|
+
kind,
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function padPhase(n) {
|
|
93
|
+
return String(n).padStart(2, '0');
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
function parsePhaseStatuses(roadmap) {
|
|
97
|
+
const phases = [];
|
|
98
|
+
const lines = roadmap.split('\n');
|
|
99
|
+
for (const line of lines) {
|
|
100
|
+
const match = line.match(PHASE_LINE_RE);
|
|
101
|
+
if (match) {
|
|
102
|
+
const rawStatus = match[1].toLowerCase();
|
|
103
|
+
let status = 'not_started';
|
|
104
|
+
if (rawStatus === '[x]' || rawStatus === '✅' || rawStatus === '✅') status = 'done';
|
|
105
|
+
else if (rawStatus === '[-]') status = 'in_progress';
|
|
106
|
+
else if (rawStatus === 'ðÿ"„' || rawStatus === '🔄') status = 'in_progress';
|
|
107
|
+
phases.push({
|
|
108
|
+
number: match[2],
|
|
109
|
+
name: match[3].replace(/\*\*/g, '').split('-')[0].trim(),
|
|
110
|
+
status,
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
return phases;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
function normalizePhaseToken(value) {
|
|
118
|
+
const raw = String(value).trim().toLowerCase();
|
|
119
|
+
const match = raw.match(/^(\d+(?:\.\d+)*)([a-z]?)$/i);
|
|
120
|
+
if (!match) return raw;
|
|
121
|
+
|
|
122
|
+
const numericSegments = match[1]
|
|
123
|
+
.split('.')
|
|
124
|
+
.map((segment) => String(parseInt(segment, 10)));
|
|
125
|
+
return `${numericSegments.join('.')}${match[2] || ''}`;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
function extractPlanFileArtifacts(planContent, workspaceRoot) {
|
|
129
|
+
const artifacts = [];
|
|
130
|
+
const seen = new Set();
|
|
131
|
+
|
|
132
|
+
for (const line of planContent.split('\n')) {
|
|
133
|
+
const moveMatch = line.match(/^\s*-\s*(RENAME|MOVE):\s*(.+?)\s*->\s*(.+?)\s*$/i);
|
|
134
|
+
if (moveMatch) {
|
|
135
|
+
const operation = moveMatch[1].toLowerCase();
|
|
136
|
+
const from = moveMatch[2].replace(/^`|`$/g, '').trim();
|
|
137
|
+
const to = moveMatch[3].replace(/^`|`$/g, '').trim();
|
|
138
|
+
if (!from || !to || seen.has(`${operation}:${from}->${to}`)) continue;
|
|
139
|
+
seen.add(`${operation}:${from}->${to}`);
|
|
140
|
+
artifacts.push({
|
|
141
|
+
operation,
|
|
142
|
+
from,
|
|
143
|
+
to,
|
|
144
|
+
file: to,
|
|
145
|
+
exists: existsSync(join(workspaceRoot, to)),
|
|
146
|
+
});
|
|
147
|
+
continue;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
const match = line.match(/^\s*-\s*(CREATE|MODIFY|DELETE|READ|TOUCH):\s*(.+?)\s*$/i);
|
|
151
|
+
if (!match) continue;
|
|
152
|
+
|
|
153
|
+
const operation = match[1].toLowerCase();
|
|
154
|
+
const file = match[2].replace(/^`|`$/g, '').trim();
|
|
155
|
+
if (!file || seen.has(`${operation}:${file}`)) continue;
|
|
156
|
+
seen.add(`${operation}:${file}`);
|
|
157
|
+
artifacts.push({
|
|
158
|
+
operation,
|
|
159
|
+
file,
|
|
160
|
+
exists: existsSync(join(workspaceRoot, file)),
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
return artifacts;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
export function updateRoadmapPhaseStatus(roadmap, phaseNumber, status) {
|
|
168
|
+
const marker = PHASE_STATUS_MARKERS[status];
|
|
169
|
+
if (!marker) {
|
|
170
|
+
throw new Error(`Unsupported phase status: ${status}`);
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
const normalizedTarget = normalizePhaseToken(phaseNumber);
|
|
174
|
+
const lines = roadmap.split('\n');
|
|
175
|
+
const overviewIndexes = [];
|
|
176
|
+
const detailSections = [];
|
|
177
|
+
let inArchivedDetails = false;
|
|
178
|
+
|
|
179
|
+
for (let index = 0; index < lines.length; index += 1) {
|
|
180
|
+
if (DETAILS_OPEN_RE.test(lines[index]) && !DETAILS_CLOSE_RE.test(lines[index])) {
|
|
181
|
+
inArchivedDetails = true;
|
|
182
|
+
continue;
|
|
183
|
+
}
|
|
184
|
+
if (DETAILS_CLOSE_RE.test(lines[index])) {
|
|
185
|
+
inArchivedDetails = false;
|
|
186
|
+
continue;
|
|
187
|
+
}
|
|
188
|
+
if (inArchivedDetails) continue;
|
|
189
|
+
|
|
190
|
+
const overviewMatch = lines[index].match(ROADMAP_PHASE_STATUS_RE);
|
|
191
|
+
if (overviewMatch && normalizePhaseToken(overviewMatch[4]) === normalizedTarget) {
|
|
192
|
+
overviewIndexes.push({ index, match: overviewMatch });
|
|
193
|
+
continue;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
const headingMatch = lines[index].match(PHASE_DETAIL_HEADING_RE);
|
|
197
|
+
if (headingMatch && normalizePhaseToken(headingMatch[1]) === normalizedTarget) {
|
|
198
|
+
let statusIndex = -1;
|
|
199
|
+
let statusMatch = null;
|
|
200
|
+
for (let detailIndex = index + 1; detailIndex < lines.length; detailIndex += 1) {
|
|
201
|
+
if (/^#+\s+/.test(lines[detailIndex])) break;
|
|
202
|
+
const candidate = lines[detailIndex].match(PHASE_DETAIL_STATUS_RE);
|
|
203
|
+
if (candidate) {
|
|
204
|
+
statusIndex = detailIndex;
|
|
205
|
+
statusMatch = candidate;
|
|
206
|
+
break;
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
detailSections.push({ headingIndex: index, statusIndex, statusMatch });
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
if (overviewIndexes.length === 0) {
|
|
214
|
+
throw new Error(`Phase ${phaseNumber} was not found in ROADMAP.md`);
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
if (overviewIndexes.length > 1) {
|
|
218
|
+
throw new Error(`Phase ${phaseNumber} matched multiple ROADMAP.md entries`);
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
if (detailSections.length > 1) {
|
|
222
|
+
throw new Error(`Phase ${phaseNumber} matched multiple Phase Details sections in ROADMAP.md`);
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
if (detailSections.length === 1 && detailSections[0].statusIndex === -1) {
|
|
226
|
+
throw new Error(`Phase ${phaseNumber} has a Phase Details section but no **Status** line in ROADMAP.md`);
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
const updatedLines = [...lines];
|
|
230
|
+
const overview = overviewIndexes[0];
|
|
231
|
+
updatedLines[overview.index] = `${overview.match[1]}${marker}${overview.match[3]}`;
|
|
232
|
+
|
|
233
|
+
if (detailSections.length === 1) {
|
|
234
|
+
const detail = detailSections[0];
|
|
235
|
+
updatedLines[detail.statusIndex] = `${detail.statusMatch[1]}${marker}${detail.statusMatch[3]}`;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
return updatedLines.join('\n');
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
export function cmdPhaseStatus(...args) {
|
|
242
|
+
const { args: normalizedArgs, planningDir, invalid, error } = resolveWorkspaceContext(args);
|
|
243
|
+
if (invalid) {
|
|
244
|
+
console.error(error);
|
|
245
|
+
process.exitCode = 1;
|
|
246
|
+
return;
|
|
247
|
+
}
|
|
248
|
+
const roadmapPath = join(planningDir, 'ROADMAP.md');
|
|
249
|
+
const [phaseNumber, status] = normalizedArgs;
|
|
250
|
+
|
|
251
|
+
if (!phaseNumber || !status) {
|
|
252
|
+
console.error('Usage: gsdd phase-status <phase-number> <not_started|todo|in_progress|done>');
|
|
253
|
+
process.exitCode = 1;
|
|
254
|
+
return;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
if (!existsSync(roadmapPath)) {
|
|
258
|
+
console.error('No ROADMAP.md found. Run the new-project workflow first.');
|
|
259
|
+
process.exitCode = 1;
|
|
260
|
+
return;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
try {
|
|
264
|
+
const roadmap = readFileSync(roadmapPath, 'utf-8');
|
|
265
|
+
const updated = updateRoadmapPhaseStatus(roadmap, phaseNumber, status);
|
|
266
|
+
const changed = updated !== roadmap;
|
|
267
|
+
if (changed) {
|
|
268
|
+
writeFileSync(roadmapPath, updated);
|
|
269
|
+
try { writeFingerprint(planningDir); } catch { /* best-effort */ }
|
|
270
|
+
}
|
|
271
|
+
output({ phase: phaseNumber, status, roadmap: '.planning/ROADMAP.md', changed });
|
|
272
|
+
} catch (error) {
|
|
273
|
+
console.error(error.message);
|
|
274
|
+
process.exitCode = 1;
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
export function cmdFindPhase(...args) {
|
|
279
|
+
const { args: normalizedArgs, planningDir, invalid, error } = resolveWorkspaceContext(args);
|
|
280
|
+
if (invalid) {
|
|
281
|
+
output({ error });
|
|
282
|
+
process.exitCode = 1;
|
|
283
|
+
return;
|
|
284
|
+
}
|
|
285
|
+
const phaseNum = normalizedArgs[0];
|
|
286
|
+
|
|
287
|
+
if (!existsSync(planningDir)) {
|
|
288
|
+
output({ error: 'No .planning/ directory found. Run `npx -y gsdd-cli init` then the new-project workflow first.' });
|
|
289
|
+
return;
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
const roadmapPath = join(planningDir, 'ROADMAP.md');
|
|
293
|
+
if (!existsSync(roadmapPath)) {
|
|
294
|
+
output({ error: 'No ROADMAP.md found. Run the new-project workflow first.' });
|
|
295
|
+
return;
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
const phasesDir = join(planningDir, 'phases');
|
|
299
|
+
const researchDir = join(planningDir, 'research');
|
|
300
|
+
|
|
301
|
+
if (phaseNum) {
|
|
302
|
+
const plans = findFiles(phasesDir, `${padPhase(phaseNum)}-PLAN`);
|
|
303
|
+
const summaries = findFiles(phasesDir, `${padPhase(phaseNum)}-SUMMARY`);
|
|
304
|
+
|
|
305
|
+
output({
|
|
306
|
+
phase: normalizePhaseToken(phaseNum),
|
|
307
|
+
directory: phasesDir,
|
|
308
|
+
plans,
|
|
309
|
+
summaries,
|
|
310
|
+
hasResearch: existsSync(researchDir) && readdirSync(researchDir).length > 0,
|
|
311
|
+
incomplete: plans.filter((p) => !summaries.some((s) => s.replace('SUMMARY', '') === p.replace('PLAN', ''))),
|
|
312
|
+
});
|
|
313
|
+
return;
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
const allArtifacts = listPhaseArtifacts(phasesDir);
|
|
317
|
+
const plans = allArtifacts.filter((artifact) => artifact.kind === 'PLAN');
|
|
318
|
+
const summaries = allArtifacts.filter((artifact) => artifact.kind === 'SUMMARY');
|
|
319
|
+
|
|
320
|
+
const roadmap = readFileSync(roadmapPath, 'utf-8');
|
|
321
|
+
const phases = parsePhaseStatuses(roadmap);
|
|
322
|
+
|
|
323
|
+
output({
|
|
324
|
+
phases,
|
|
325
|
+
planCount: plans.length,
|
|
326
|
+
summaryCount: summaries.length,
|
|
327
|
+
currentPhase: phases.find((p) => p.status === 'in_progress') || phases.find((p) => p.status === 'not_started') || null,
|
|
328
|
+
hasResearch: existsSync(researchDir) && readdirSync(researchDir).length > 0,
|
|
329
|
+
});
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
export function cmdVerify(...args) {
|
|
333
|
+
const { args: normalizedArgs, workspaceRoot, planningDir, invalid, error } = resolveWorkspaceContext(args);
|
|
334
|
+
if (invalid) {
|
|
335
|
+
console.error(error);
|
|
336
|
+
process.exitCode = 1;
|
|
337
|
+
return;
|
|
338
|
+
}
|
|
339
|
+
const phaseNum = normalizedArgs[0];
|
|
340
|
+
if (!phaseNum) {
|
|
341
|
+
console.error('Usage: gsdd verify <phase-number>');
|
|
342
|
+
process.exitCode = 1; return;
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
if (!existsSync(planningDir)) {
|
|
346
|
+
console.error('No .planning/ directory found.');
|
|
347
|
+
process.exitCode = 1; return;
|
|
348
|
+
}
|
|
349
|
+
const phasesDir = join(planningDir, 'phases');
|
|
350
|
+
const matchingPlans = findFiles(phasesDir, `${padPhase(phaseNum)}-PLAN`);
|
|
351
|
+
const matchingSummaries = findFiles(phasesDir, `${padPhase(phaseNum)}-SUMMARY`);
|
|
352
|
+
const artifacts = matchingPlans.flatMap((planPath) => {
|
|
353
|
+
const fullPath = join(phasesDir, planPath);
|
|
354
|
+
return existsSync(fullPath)
|
|
355
|
+
? extractPlanFileArtifacts(readFileSync(fullPath, 'utf-8'), workspaceRoot)
|
|
356
|
+
: [];
|
|
357
|
+
});
|
|
358
|
+
|
|
359
|
+
const result = {
|
|
360
|
+
phase: normalizePhaseToken(phaseNum),
|
|
361
|
+
exists: matchingPlans.length > 0,
|
|
362
|
+
plans: matchingPlans,
|
|
363
|
+
summaries: matchingSummaries,
|
|
364
|
+
artifacts,
|
|
365
|
+
allExist: artifacts.every((artifact) => artifact.exists),
|
|
366
|
+
verified: matchingPlans.length > 0 && matchingSummaries.length > 0,
|
|
367
|
+
};
|
|
368
|
+
output(result);
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
export function cmdScaffold(...args) {
|
|
372
|
+
const { args: normalizedArgs, planningDir, invalid, error } = resolveWorkspaceContext(args);
|
|
373
|
+
if (invalid) {
|
|
374
|
+
console.error(error);
|
|
375
|
+
process.exitCode = 1;
|
|
376
|
+
return;
|
|
377
|
+
}
|
|
378
|
+
const kind = normalizedArgs[0];
|
|
379
|
+
const phaseNum = normalizedArgs[1];
|
|
380
|
+
const phaseName = normalizedArgs[2] || 'phase';
|
|
381
|
+
if (kind !== 'phase' || !phaseNum) {
|
|
382
|
+
console.error('Usage: gsdd scaffold phase <phase-number> [phase-name]');
|
|
383
|
+
process.exitCode = 1; return;
|
|
384
|
+
}
|
|
385
|
+
mkdirSync(planningDir, { recursive: true });
|
|
386
|
+
const phasesDir = join(planningDir, 'phases');
|
|
387
|
+
mkdirSync(phasesDir, { recursive: true });
|
|
388
|
+
const dirName = `${padPhase(phaseNum)}-${phaseName.replace(/\s+/g, '-').toLowerCase()}`;
|
|
389
|
+
const phaseDir = join(phasesDir, dirName);
|
|
390
|
+
mkdirSync(phaseDir, { recursive: true });
|
|
391
|
+
const planPath = join(phaseDir, `${padPhase(phaseNum)}-PLAN.md`);
|
|
392
|
+
const created = !existsSync(planPath);
|
|
393
|
+
if (created) {
|
|
394
|
+
writeFileSync(planPath, `# Phase ${phaseNum} Plan\n\n## Goal\n- \n\n## Tasks\n- [ ] \n`);
|
|
395
|
+
}
|
|
396
|
+
output({ created, path: planPath.replace(/\\/g, '/'), phase: normalizePhaseToken(phaseNum) });
|
|
397
|
+
}
|