gsd-opencode 1.10.2 → 1.20.1

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 (164) hide show
  1. package/agents/gsd-codebase-mapper.md +29 -3
  2. package/agents/gsd-debugger.md +19 -21
  3. package/agents/gsd-executor.md +213 -528
  4. package/agents/gsd-integration-checker.md +20 -0
  5. package/agents/gsd-phase-researcher.md +189 -267
  6. package/agents/gsd-plan-checker.md +278 -279
  7. package/agents/gsd-planner.md +299 -490
  8. package/agents/gsd-project-researcher.md +103 -345
  9. package/agents/gsd-research-synthesizer.md +5 -22
  10. package/agents/gsd-roadmapper.md +43 -6
  11. package/agents/gsd-verifier.md +158 -377
  12. package/{lib → bin/dm/lib}/constants.js +10 -3
  13. package/{src → bin/dm/src}/commands/install.js +5 -4
  14. package/{src → bin/dm/src}/commands/uninstall.js +3 -1
  15. package/{src → bin/dm/src}/services/backup-manager.js +1 -1
  16. package/{src → bin/dm/src}/services/config.js +1 -1
  17. package/{src → bin/dm/src}/services/file-ops.js +20 -4
  18. package/{src → bin/dm/src}/services/health-checker.js +3 -1
  19. package/{src → bin/dm/src}/services/repair-service.js +3 -1
  20. package/{src → bin/dm/src}/services/settings.js +1 -1
  21. package/{src → bin/dm/src}/services/update-service.js +2 -2
  22. package/bin/gsd-install.js +0 -0
  23. package/bin/gsd.js +9 -9
  24. package/commands/gsd/gsd-add-phase.md +43 -0
  25. package/commands/gsd/gsd-add-todo.md +47 -0
  26. package/commands/gsd/gsd-audit-milestone.md +36 -0
  27. package/commands/gsd/gsd-check-todos.md +45 -0
  28. package/commands/gsd/gsd-cleanup.md +18 -0
  29. package/commands/gsd/{complete-milestone.md → gsd-complete-milestone.md} +1 -1
  30. package/commands/gsd/{debug.md → gsd-debug.md} +16 -21
  31. package/commands/gsd/{discuss-phase.md → gsd-discuss-phase.md} +6 -9
  32. package/commands/gsd/gsd-execute-phase.md +41 -0
  33. package/commands/gsd/gsd-health.md +22 -0
  34. package/commands/gsd/gsd-help.md +22 -0
  35. package/commands/gsd/gsd-insert-phase.md +32 -0
  36. package/commands/gsd/gsd-join-discord.md +18 -0
  37. package/commands/gsd/{list-phase-assumptions.md → gsd-list-phase-assumptions.md} +3 -7
  38. package/commands/gsd/{map-codebase.md → gsd-map-codebase.md} +3 -3
  39. package/commands/gsd/gsd-new-milestone.md +44 -0
  40. package/commands/gsd/gsd-new-project.md +42 -0
  41. package/commands/gsd/gsd-pause-work.md +38 -0
  42. package/commands/gsd/gsd-plan-milestone-gaps.md +34 -0
  43. package/commands/gsd/gsd-plan-phase.md +44 -0
  44. package/commands/gsd/gsd-progress.md +24 -0
  45. package/commands/gsd/gsd-quick.md +41 -0
  46. package/commands/gsd/gsd-reapply-patches.md +119 -0
  47. package/commands/gsd/gsd-remove-phase.md +31 -0
  48. package/commands/gsd/{research-phase.md → gsd-research-phase.md} +38 -49
  49. package/commands/gsd/{resume-work.md → gsd-resume-work.md} +2 -2
  50. package/commands/gsd/gsd-set-profile.md +34 -0
  51. package/commands/gsd/gsd-settings.md +36 -0
  52. package/commands/gsd/gsd-update.md +37 -0
  53. package/commands/gsd/gsd-verify-work.md +38 -0
  54. package/get-shit-done/bin/gsd-tools.cjs +553 -0
  55. package/get-shit-done/bin/gsd-tools.test.cjs +2346 -0
  56. package/get-shit-done/bin/lib/commands.cjs +556 -0
  57. package/get-shit-done/bin/lib/config.cjs +162 -0
  58. package/get-shit-done/bin/lib/core.cjs +377 -0
  59. package/get-shit-done/bin/lib/frontmatter.cjs +299 -0
  60. package/get-shit-done/bin/lib/init.cjs +694 -0
  61. package/get-shit-done/bin/lib/milestone.cjs +215 -0
  62. package/get-shit-done/bin/lib/phase.cjs +877 -0
  63. package/get-shit-done/bin/lib/roadmap.cjs +298 -0
  64. package/get-shit-done/bin/lib/state.cjs +490 -0
  65. package/get-shit-done/bin/lib/template.cjs +222 -0
  66. package/get-shit-done/bin/lib/verify.cjs +772 -0
  67. package/get-shit-done/references/checkpoints.md +62 -364
  68. package/get-shit-done/references/decimal-phase-calculation.md +65 -0
  69. package/get-shit-done/references/git-integration.md +10 -16
  70. package/get-shit-done/references/git-planning-commit.md +38 -0
  71. package/get-shit-done/references/model-profile-resolution.md +34 -0
  72. package/get-shit-done/references/model-profiles.md +54 -66
  73. package/get-shit-done/references/phase-argument-parsing.md +61 -0
  74. package/get-shit-done/references/planning-config.md +112 -10
  75. package/get-shit-done/references/questioning.md +4 -0
  76. package/get-shit-done/references/ui-brand.md +1 -1
  77. package/get-shit-done/templates/UAT.md +1 -1
  78. package/get-shit-done/templates/VALIDATION.md +104 -0
  79. package/get-shit-done/templates/codebase/structure.md +6 -6
  80. package/get-shit-done/templates/config.json +37 -0
  81. package/get-shit-done/templates/context.md +2 -10
  82. package/get-shit-done/templates/continue-here.md +6 -6
  83. package/get-shit-done/templates/debug-subagent-prompt.md +2 -2
  84. package/get-shit-done/templates/discovery.md +6 -6
  85. package/get-shit-done/templates/milestone-archive.md +3 -3
  86. package/get-shit-done/templates/phase-prompt.md +9 -7
  87. package/get-shit-done/templates/planner-subagent-prompt.md +6 -6
  88. package/get-shit-done/templates/research-project/ARCHITECTURE.md +1 -1
  89. package/get-shit-done/templates/research.md +29 -6
  90. package/get-shit-done/templates/roadmap.md +1 -1
  91. package/get-shit-done/templates/state.md +0 -30
  92. package/get-shit-done/templates/summary-complex.md +59 -0
  93. package/get-shit-done/templates/summary-minimal.md +41 -0
  94. package/get-shit-done/templates/summary-standard.md +48 -0
  95. package/get-shit-done/templates/summary.md +16 -37
  96. package/get-shit-done/templates/user-setup.md +1 -13
  97. package/get-shit-done/templates/verification-report.md +5 -5
  98. package/get-shit-done/workflows/add-phase.md +111 -0
  99. package/{commands/gsd → get-shit-done/workflows}/add-todo.md +24 -60
  100. package/{commands/gsd → get-shit-done/workflows}/audit-milestone.md +83 -63
  101. package/{commands/gsd → get-shit-done/workflows}/check-todos.md +21 -73
  102. package/get-shit-done/workflows/cleanup.md +152 -0
  103. package/get-shit-done/workflows/complete-milestone.md +251 -312
  104. package/get-shit-done/workflows/diagnose-issues.md +6 -31
  105. package/get-shit-done/workflows/discovery-phase.md +11 -11
  106. package/get-shit-done/workflows/discuss-phase.md +156 -49
  107. package/get-shit-done/workflows/execute-phase.md +238 -396
  108. package/get-shit-done/workflows/execute-plan.md +180 -1609
  109. package/get-shit-done/workflows/health.md +156 -0
  110. package/{commands/gsd → get-shit-done/workflows}/help.md +33 -35
  111. package/get-shit-done/workflows/insert-phase.md +129 -0
  112. package/get-shit-done/workflows/list-phase-assumptions.md +3 -3
  113. package/get-shit-done/workflows/map-codebase.md +73 -80
  114. package/get-shit-done/workflows/new-milestone.md +382 -0
  115. package/{commands/gsd → get-shit-done/workflows}/new-project.md +281 -234
  116. package/get-shit-done/workflows/oc-set-profile.md +320 -0
  117. package/{commands/gsd → get-shit-done/workflows}/pause-work.md +31 -43
  118. package/{commands/gsd → get-shit-done/workflows}/plan-milestone-gaps.md +29 -50
  119. package/get-shit-done/workflows/plan-phase.md +478 -0
  120. package/{commands/gsd → get-shit-done/workflows}/progress.md +64 -47
  121. package/get-shit-done/workflows/quick.md +453 -0
  122. package/get-shit-done/workflows/remove-phase.md +154 -0
  123. package/get-shit-done/workflows/research-phase.md +73 -0
  124. package/get-shit-done/workflows/resume-project.md +17 -26
  125. package/get-shit-done/workflows/set-profile.md +80 -0
  126. package/get-shit-done/workflows/settings.md +213 -0
  127. package/get-shit-done/workflows/transition.md +84 -104
  128. package/{commands/gsd → get-shit-done/workflows}/update.md +70 -28
  129. package/get-shit-done/workflows/verify-phase.md +106 -492
  130. package/get-shit-done/workflows/verify-work.md +26 -53
  131. package/package.json +7 -4
  132. package/rules/gsd-oc-work-hard.md +36 -0
  133. package/skills/gsd-oc-select-model/SKILL.md +348 -0
  134. package/skills/gsd-oc-select-model/scripts/select-models.cjs +268 -0
  135. package/agents/gsd-set-model.md +0 -287
  136. package/agents/gsd-set-profile.md +0 -239
  137. package/agents/gsd-settings.md +0 -749
  138. package/bin/install.js +0 -323
  139. package/commands/gsd/add-phase.md +0 -207
  140. package/commands/gsd/execute-phase.md +0 -339
  141. package/commands/gsd/insert-phase.md +0 -227
  142. package/commands/gsd/new-milestone.md +0 -721
  143. package/commands/gsd/plan-phase.md +0 -525
  144. package/commands/gsd/quick.md +0 -309
  145. package/commands/gsd/remove-phase.md +0 -349
  146. package/commands/gsd/set-model.md +0 -77
  147. package/commands/gsd/set-profile.md +0 -46
  148. package/commands/gsd/settings.md +0 -33
  149. package/commands/gsd/verify-work.md +0 -219
  150. package/commands/gsd/whats-new.md +0 -124
  151. /package/{src → bin/dm/src}/commands/check.js +0 -0
  152. /package/{src → bin/dm/src}/commands/config.js +0 -0
  153. /package/{src → bin/dm/src}/commands/list.js +0 -0
  154. /package/{src → bin/dm/src}/commands/repair.js +0 -0
  155. /package/{src → bin/dm/src}/commands/update.js +0 -0
  156. /package/{src → bin/dm/src}/services/manifest-manager.js +0 -0
  157. /package/{src → bin/dm/src}/services/migration-service.js +0 -0
  158. /package/{src → bin/dm/src}/services/scope-manager.js +0 -0
  159. /package/{src → bin/dm/src}/services/structure-detector.js +0 -0
  160. /package/{src → bin/dm/src}/utils/hash.js +0 -0
  161. /package/{src → bin/dm/src}/utils/interactive.js +0 -0
  162. /package/{src → bin/dm/src}/utils/logger.js +0 -0
  163. /package/{src → bin/dm/src}/utils/npm-registry.js +0 -0
  164. /package/{src → bin/dm/src}/utils/path-resolver.js +0 -0
@@ -0,0 +1,556 @@
1
+ /**
2
+ * Commands — Standalone utility commands
3
+ */
4
+ const fs = require('fs');
5
+ const path = require('path');
6
+ const { execSync } = require('child_process');
7
+ const { safeReadFile, loadConfig, isGitIgnored, execGit, normalizePhaseName, getArchivedPhaseDirs, generateSlugInternal, getMilestoneInfo, resolveModelInternal, MODEL_PROFILES, output, error, findPhaseInternal } = require('./core.cjs');
8
+ const { extractFrontmatter } = require('./frontmatter.cjs');
9
+
10
+ function cmdGenerateSlug(text, raw) {
11
+ if (!text) {
12
+ error('text required for slug generation');
13
+ }
14
+
15
+ const slug = text
16
+ .toLowerCase()
17
+ .replace(/[^a-z0-9]+/g, '-')
18
+ .replace(/^-+|-+$/g, '');
19
+
20
+ const result = { slug };
21
+ output(result, raw, slug);
22
+ }
23
+
24
+ function cmdCurrentTimestamp(format, raw) {
25
+ const now = new Date();
26
+ let result;
27
+
28
+ switch (format) {
29
+ case 'date':
30
+ result = now.toISOString().split('T')[0];
31
+ break;
32
+ case 'filename':
33
+ result = now.toISOString().replace(/:/g, '-').replace(/\..+/, '');
34
+ break;
35
+ case 'full':
36
+ default:
37
+ result = now.toISOString();
38
+ break;
39
+ }
40
+
41
+ output({ timestamp: result }, raw, result);
42
+ }
43
+
44
+ function cmdListTodos(cwd, area, raw) {
45
+ const pendingDir = path.join(cwd, '.planning', 'todos', 'pending');
46
+
47
+ let count = 0;
48
+ const todos = [];
49
+
50
+ try {
51
+ const files = fs.readdirSync(pendingDir).filter(f => f.endsWith('.md'));
52
+
53
+ for (const file of files) {
54
+ try {
55
+ const content = fs.readFileSync(path.join(pendingDir, file), 'utf-8');
56
+ const createdMatch = content.match(/^created:\s*(.+)$/m);
57
+ const titleMatch = content.match(/^title:\s*(.+)$/m);
58
+ const areaMatch = content.match(/^area:\s*(.+)$/m);
59
+
60
+ const todoArea = areaMatch ? areaMatch[1].trim() : 'general';
61
+
62
+ // Apply area filter if specified
63
+ if (area && todoArea !== area) continue;
64
+
65
+ count++;
66
+ todos.push({
67
+ file,
68
+ created: createdMatch ? createdMatch[1].trim() : 'unknown',
69
+ title: titleMatch ? titleMatch[1].trim() : 'Untitled',
70
+ area: todoArea,
71
+ path: path.join('.planning', 'todos', 'pending', file),
72
+ });
73
+ } catch {}
74
+ }
75
+ } catch {}
76
+
77
+ const result = { count, todos };
78
+ output(result, raw, count.toString());
79
+ }
80
+
81
+ function cmdVerifyPathExists(cwd, targetPath, raw) {
82
+ if (!targetPath) {
83
+ error('path required for verification');
84
+ }
85
+
86
+ const fullPath = path.isAbsolute(targetPath) ? targetPath : path.join(cwd, targetPath);
87
+
88
+ try {
89
+ const stats = fs.statSync(fullPath);
90
+ const type = stats.isDirectory() ? 'directory' : stats.isFile() ? 'file' : 'other';
91
+ const result = { exists: true, type };
92
+ output(result, raw, 'true');
93
+ } catch {
94
+ const result = { exists: false, type: null };
95
+ output(result, raw, 'false');
96
+ }
97
+ }
98
+
99
+ function cmdHistoryDigest(cwd, raw) {
100
+ const phasesDir = path.join(cwd, '.planning', 'phases');
101
+ const digest = { phases: {}, decisions: [], tech_stack: new Set() };
102
+
103
+ // Collect all phase directories: archived + current
104
+ const allPhaseDirs = [];
105
+
106
+ // Add archived phases first (oldest milestones first)
107
+ const archived = getArchivedPhaseDirs(cwd);
108
+ for (const a of archived) {
109
+ allPhaseDirs.push({ name: a.name, fullPath: a.fullPath, milestone: a.milestone });
110
+ }
111
+
112
+ // Add current phases
113
+ if (fs.existsSync(phasesDir)) {
114
+ try {
115
+ const currentDirs = fs.readdirSync(phasesDir, { withFileTypes: true })
116
+ .filter(e => e.isDirectory())
117
+ .map(e => e.name)
118
+ .sort();
119
+ for (const dir of currentDirs) {
120
+ allPhaseDirs.push({ name: dir, fullPath: path.join(phasesDir, dir), milestone: null });
121
+ }
122
+ } catch {}
123
+ }
124
+
125
+ if (allPhaseDirs.length === 0) {
126
+ digest.tech_stack = [];
127
+ output(digest, raw);
128
+ return;
129
+ }
130
+
131
+ try {
132
+ for (const { name: dir, fullPath: dirPath } of allPhaseDirs) {
133
+ const summaries = fs.readdirSync(dirPath).filter(f => f.endsWith('-SUMMARY.md') || f === 'SUMMARY.md');
134
+
135
+ for (const summary of summaries) {
136
+ try {
137
+ const content = fs.readFileSync(path.join(dirPath, summary), 'utf-8');
138
+ const fm = extractFrontmatter(content);
139
+
140
+ const phaseNum = fm.phase || dir.split('-')[0];
141
+
142
+ if (!digest.phases[phaseNum]) {
143
+ digest.phases[phaseNum] = {
144
+ name: fm.name || dir.split('-').slice(1).join(' ') || 'Unknown',
145
+ provides: new Set(),
146
+ affects: new Set(),
147
+ patterns: new Set(),
148
+ };
149
+ }
150
+
151
+ // Merge provides
152
+ if (fm['dependency-graph'] && fm['dependency-graph'].provides) {
153
+ fm['dependency-graph'].provides.forEach(p => digest.phases[phaseNum].provides.add(p));
154
+ } else if (fm.provides) {
155
+ fm.provides.forEach(p => digest.phases[phaseNum].provides.add(p));
156
+ }
157
+
158
+ // Merge affects
159
+ if (fm['dependency-graph'] && fm['dependency-graph'].affects) {
160
+ fm['dependency-graph'].affects.forEach(a => digest.phases[phaseNum].affects.add(a));
161
+ }
162
+
163
+ // Merge patterns
164
+ if (fm['patterns-established']) {
165
+ fm['patterns-established'].forEach(p => digest.phases[phaseNum].patterns.add(p));
166
+ }
167
+
168
+ // Merge decisions
169
+ if (fm['key-decisions']) {
170
+ fm['key-decisions'].forEach(d => {
171
+ digest.decisions.push({ phase: phaseNum, decision: d });
172
+ });
173
+ }
174
+
175
+ // Merge tech stack
176
+ if (fm['tech-stack'] && fm['tech-stack'].added) {
177
+ fm['tech-stack'].added.forEach(t => digest.tech_stack.add(typeof t === 'string' ? t : t.name));
178
+ }
179
+
180
+ } catch (e) {
181
+ // Skip malformed summaries
182
+ }
183
+ }
184
+ }
185
+
186
+ // Convert Sets to Arrays for JSON output
187
+ Object.keys(digest.phases).forEach(p => {
188
+ digest.phases[p].provides = [...digest.phases[p].provides];
189
+ digest.phases[p].affects = [...digest.phases[p].affects];
190
+ digest.phases[p].patterns = [...digest.phases[p].patterns];
191
+ });
192
+ digest.tech_stack = [...digest.tech_stack];
193
+
194
+ output(digest, raw);
195
+ } catch (e) {
196
+ error('Failed to generate history digest: ' + e.message);
197
+ }
198
+ }
199
+
200
+ function cmdResolveModel(cwd, agentType, raw) {
201
+ if (!agentType) {
202
+ error('agent-type required');
203
+ }
204
+
205
+ const config = loadConfig(cwd);
206
+ const profile = config.model_profile || 'balanced';
207
+
208
+ const agentModels = MODEL_PROFILES[agentType];
209
+ if (!agentModels) {
210
+ const result = { model: 'sonnet', profile, unknown_agent: true };
211
+ output(result, raw, 'sonnet');
212
+ return;
213
+ }
214
+
215
+ const resolved = agentModels[profile] || agentModels['balanced'] || 'sonnet';
216
+ const model = resolved === 'opus' ? 'inherit' : resolved;
217
+ const result = { model, profile };
218
+ output(result, raw, model);
219
+ }
220
+
221
+ function cmdCommit(cwd, message, files, raw, amend) {
222
+ if (!message && !amend) {
223
+ error('commit message required');
224
+ }
225
+
226
+ const config = loadConfig(cwd);
227
+
228
+ // Check commit_docs config
229
+ if (!config.commit_docs) {
230
+ const result = { committed: false, hash: null, reason: 'skipped_commit_docs_false' };
231
+ output(result, raw, 'skipped');
232
+ return;
233
+ }
234
+
235
+ // Check if .planning is gitignored
236
+ if (isGitIgnored(cwd, '.planning')) {
237
+ const result = { committed: false, hash: null, reason: 'skipped_gitignored' };
238
+ output(result, raw, 'skipped');
239
+ return;
240
+ }
241
+
242
+ // Stage files
243
+ const filesToStage = files && files.length > 0 ? files : ['.planning/'];
244
+ for (const file of filesToStage) {
245
+ execGit(cwd, ['add', file]);
246
+ }
247
+
248
+ // Commit
249
+ const commitArgs = amend ? ['commit', '--amend', '--no-edit'] : ['commit', '-m', message];
250
+ const commitResult = execGit(cwd, commitArgs);
251
+ if (commitResult.exitCode !== 0) {
252
+ if (commitResult.stdout.includes('nothing to commit') || commitResult.stderr.includes('nothing to commit')) {
253
+ const result = { committed: false, hash: null, reason: 'nothing_to_commit' };
254
+ output(result, raw, 'nothing');
255
+ return;
256
+ }
257
+ const result = { committed: false, hash: null, reason: 'nothing_to_commit', error: commitResult.stderr };
258
+ output(result, raw, 'nothing');
259
+ return;
260
+ }
261
+
262
+ // Get short hash
263
+ const hashResult = execGit(cwd, ['rev-parse', '--short', 'HEAD']);
264
+ const hash = hashResult.exitCode === 0 ? hashResult.stdout : null;
265
+ const result = { committed: true, hash, reason: 'committed' };
266
+ output(result, raw, hash || 'committed');
267
+ }
268
+
269
+ function cmdSummaryExtract(cwd, summaryPath, fields, raw) {
270
+ if (!summaryPath) {
271
+ error('summary-path required for summary-extract');
272
+ }
273
+
274
+ const fullPath = path.join(cwd, summaryPath);
275
+
276
+ if (!fs.existsSync(fullPath)) {
277
+ output({ error: 'File not found', path: summaryPath }, raw);
278
+ return;
279
+ }
280
+
281
+ const content = fs.readFileSync(fullPath, 'utf-8');
282
+ const fm = extractFrontmatter(content);
283
+
284
+ // Parse key-decisions into structured format
285
+ const parseDecisions = (decisionsList) => {
286
+ if (!decisionsList || !Array.isArray(decisionsList)) return [];
287
+ return decisionsList.map(d => {
288
+ const colonIdx = d.indexOf(':');
289
+ if (colonIdx > 0) {
290
+ return {
291
+ summary: d.substring(0, colonIdx).trim(),
292
+ rationale: d.substring(colonIdx + 1).trim(),
293
+ };
294
+ }
295
+ return { summary: d, rationale: null };
296
+ });
297
+ };
298
+
299
+ // Build full result
300
+ const fullResult = {
301
+ path: summaryPath,
302
+ one_liner: fm['one-liner'] || null,
303
+ key_files: fm['key-files'] || [],
304
+ tech_added: (fm['tech-stack'] && fm['tech-stack'].added) || [],
305
+ patterns: fm['patterns-established'] || [],
306
+ decisions: parseDecisions(fm['key-decisions']),
307
+ };
308
+
309
+ // If fields specified, filter to only those fields
310
+ if (fields && fields.length > 0) {
311
+ const filtered = { path: summaryPath };
312
+ for (const field of fields) {
313
+ if (fullResult[field] !== undefined) {
314
+ filtered[field] = fullResult[field];
315
+ }
316
+ }
317
+ output(filtered, raw);
318
+ return;
319
+ }
320
+
321
+ output(fullResult, raw);
322
+ }
323
+
324
+ async function cmdWebsearch(query, options, raw) {
325
+ const apiKey = process.env.BRAVE_API_KEY;
326
+
327
+ if (!apiKey) {
328
+ // No key = silent skip, agent falls back to built-in websearch
329
+ output({ available: false, reason: 'BRAVE_API_KEY not set' }, raw, '');
330
+ return;
331
+ }
332
+
333
+ if (!query) {
334
+ output({ available: false, error: 'Query required' }, raw, '');
335
+ return;
336
+ }
337
+
338
+ const params = new URLSearchParams({
339
+ q: query,
340
+ count: String(options.limit || 10),
341
+ country: 'us',
342
+ search_lang: 'en',
343
+ text_decorations: 'false'
344
+ });
345
+
346
+ if (options.freshness) {
347
+ params.set('freshness', options.freshness);
348
+ }
349
+
350
+ try {
351
+ const response = await fetch(
352
+ `https://api.search.brave.com/res/v1/web/search?${params}`,
353
+ {
354
+ headers: {
355
+ 'Accept': 'application/json',
356
+ 'X-Subscription-Token': apiKey
357
+ }
358
+ }
359
+ );
360
+
361
+ if (!response.ok) {
362
+ output({ available: false, error: `API error: ${response.status}` }, raw, '');
363
+ return;
364
+ }
365
+
366
+ const data = await response.json();
367
+
368
+ const results = (data.web?.results || []).map(r => ({
369
+ title: r.title,
370
+ url: r.url,
371
+ description: r.description,
372
+ age: r.age || null
373
+ }));
374
+
375
+ output({
376
+ available: true,
377
+ query,
378
+ count: results.length,
379
+ results
380
+ }, raw, results.map(r => `${r.title}\n${r.url}\n${r.description}`).join('\n\n'));
381
+ } catch (err) {
382
+ output({ available: false, error: err.message }, raw, '');
383
+ }
384
+ }
385
+
386
+ function cmdProgressRender(cwd, format, raw) {
387
+ const phasesDir = path.join(cwd, '.planning', 'phases');
388
+ const roadmapPath = path.join(cwd, '.planning', 'ROADMAP.md');
389
+ const milestone = getMilestoneInfo(cwd);
390
+
391
+ const phases = [];
392
+ let totalPlans = 0;
393
+ let totalSummaries = 0;
394
+
395
+ try {
396
+ const entries = fs.readdirSync(phasesDir, { withFileTypes: true });
397
+ const dirs = entries.filter(e => e.isDirectory()).map(e => e.name).sort((a, b) => {
398
+ const aNum = parseFloat(a.match(/^(\d+(?:\.\d+)?)/)?.[1] || '0');
399
+ const bNum = parseFloat(b.match(/^(\d+(?:\.\d+)?)/)?.[1] || '0');
400
+ return aNum - bNum;
401
+ });
402
+
403
+ for (const dir of dirs) {
404
+ const dm = dir.match(/^(\d+(?:\.\d+)?)-?(.*)/);
405
+ const phaseNum = dm ? dm[1] : dir;
406
+ const phaseName = dm && dm[2] ? dm[2].replace(/-/g, ' ') : '';
407
+ const phaseFiles = fs.readdirSync(path.join(phasesDir, dir));
408
+ const plans = phaseFiles.filter(f => f.endsWith('-PLAN.md') || f === 'PLAN.md').length;
409
+ const summaries = phaseFiles.filter(f => f.endsWith('-SUMMARY.md') || f === 'SUMMARY.md').length;
410
+
411
+ totalPlans += plans;
412
+ totalSummaries += summaries;
413
+
414
+ let status;
415
+ if (plans === 0) status = 'Pending';
416
+ else if (summaries >= plans) status = 'Complete';
417
+ else if (summaries > 0) status = 'In Progress';
418
+ else status = 'Planned';
419
+
420
+ phases.push({ number: phaseNum, name: phaseName, plans, summaries, status });
421
+ }
422
+ } catch {}
423
+
424
+ const percent = totalPlans > 0 ? Math.round((totalSummaries / totalPlans) * 100) : 0;
425
+
426
+ if (format === 'table') {
427
+ // Render markdown table
428
+ const barWidth = 10;
429
+ const filled = Math.round((percent / 100) * barWidth);
430
+ const bar = '\u2588'.repeat(filled) + '\u2591'.repeat(barWidth - filled);
431
+ let out = `# ${milestone.version} ${milestone.name}\n\n`;
432
+ out += `**Progress:** [${bar}] ${totalSummaries}/${totalPlans} plans (${percent}%)\n\n`;
433
+ out += `| Phase | Name | Plans | Status |\n`;
434
+ out += `|-------|------|-------|--------|\n`;
435
+ for (const p of phases) {
436
+ out += `| ${p.number} | ${p.name} | ${p.summaries}/${p.plans} | ${p.status} |\n`;
437
+ }
438
+ output({ rendered: out }, raw, out);
439
+ } else if (format === 'bar') {
440
+ const barWidth = 20;
441
+ const filled = Math.round((percent / 100) * barWidth);
442
+ const bar = '\u2588'.repeat(filled) + '\u2591'.repeat(barWidth - filled);
443
+ const text = `[${bar}] ${totalSummaries}/${totalPlans} plans (${percent}%)`;
444
+ output({ bar: text, percent, completed: totalSummaries, total: totalPlans }, raw, text);
445
+ } else {
446
+ // JSON format
447
+ output({
448
+ milestone_version: milestone.version,
449
+ milestone_name: milestone.name,
450
+ phases,
451
+ total_plans: totalPlans,
452
+ total_summaries: totalSummaries,
453
+ percent,
454
+ }, raw);
455
+ }
456
+ }
457
+
458
+ function cmdTodoComplete(cwd, filename, raw) {
459
+ if (!filename) {
460
+ error('filename required for todo complete');
461
+ }
462
+
463
+ const pendingDir = path.join(cwd, '.planning', 'todos', 'pending');
464
+ const completedDir = path.join(cwd, '.planning', 'todos', 'completed');
465
+ const sourcePath = path.join(pendingDir, filename);
466
+
467
+ if (!fs.existsSync(sourcePath)) {
468
+ error(`Todo not found: ${filename}`);
469
+ }
470
+
471
+ // Ensure completed directory exists
472
+ fs.mkdirSync(completedDir, { recursive: true });
473
+
474
+ // read, add completion timestamp, move
475
+ let content = fs.readFileSync(sourcePath, 'utf-8');
476
+ const today = new Date().toISOString().split('T')[0];
477
+ content = `completed: ${today}\n` + content;
478
+
479
+ fs.writeFileSync(path.join(completedDir, filename), content, 'utf-8');
480
+ fs.unlinkSync(sourcePath);
481
+
482
+ output({ completed: true, file: filename, date: today }, raw, 'completed');
483
+ }
484
+
485
+ function cmdScaffold(cwd, type, options, raw) {
486
+ const { phase, name } = options;
487
+ const padded = phase ? normalizePhaseName(phase) : '00';
488
+ const today = new Date().toISOString().split('T')[0];
489
+
490
+ // Find phase directory
491
+ const phaseInfo = phase ? findPhaseInternal(cwd, phase) : null;
492
+ const phaseDir = phaseInfo ? path.join(cwd, phaseInfo.directory) : null;
493
+
494
+ if (phase && !phaseDir && type !== 'phase-dir') {
495
+ error(`Phase ${phase} directory not found`);
496
+ }
497
+
498
+ let filePath, content;
499
+
500
+ switch (type) {
501
+ case 'context': {
502
+ filePath = path.join(phaseDir, `${padded}-CONTEXT.md`);
503
+ content = `---\nphase: "${padded}"\nname: "${name || phaseInfo?.phase_name || 'Unnamed'}"\ncreated: ${today}\n---\n\n# Phase ${phase}: ${name || phaseInfo?.phase_name || 'Unnamed'} — Context\n\n## Decisions\n\n_Decisions will be captured during /gsd-discuss-phase ${phase}_\n\n## Discretion Areas\n\n_Areas where the executor can use judgment_\n\n## Deferred Ideas\n\n_Ideas to consider later_\n`;
504
+ break;
505
+ }
506
+ case 'uat': {
507
+ filePath = path.join(phaseDir, `${padded}-UAT.md`);
508
+ content = `---\nphase: "${padded}"\nname: "${name || phaseInfo?.phase_name || 'Unnamed'}"\ncreated: ${today}\nstatus: pending\n---\n\n# Phase ${phase}: ${name || phaseInfo?.phase_name || 'Unnamed'} — User Acceptance Testing\n\n## Test Results\n\n| # | Test | Status | Notes |\n|---|------|--------|-------|\n\n## Summary\n\n_Pending UAT_\n`;
509
+ break;
510
+ }
511
+ case 'verification': {
512
+ filePath = path.join(phaseDir, `${padded}-VERIFICATION.md`);
513
+ content = `---\nphase: "${padded}"\nname: "${name || phaseInfo?.phase_name || 'Unnamed'}"\ncreated: ${today}\nstatus: pending\n---\n\n# Phase ${phase}: ${name || phaseInfo?.phase_name || 'Unnamed'} — Verification\n\n## Goal-Backward Verification\n\n**Phase Goal:** [From ROADMAP.md]\n\n## Checks\n\n| # | Requirement | Status | Evidence |\n|---|------------|--------|----------|\n\n## Result\n\n_Pending verification_\n`;
514
+ break;
515
+ }
516
+ case 'phase-dir': {
517
+ if (!phase || !name) {
518
+ error('phase and name required for phase-dir scaffold');
519
+ }
520
+ const slug = generateSlugInternal(name);
521
+ const dirName = `${padded}-${slug}`;
522
+ const phasesParent = path.join(cwd, '.planning', 'phases');
523
+ fs.mkdirSync(phasesParent, { recursive: true });
524
+ const dirPath = path.join(phasesParent, dirName);
525
+ fs.mkdirSync(dirPath, { recursive: true });
526
+ output({ created: true, directory: `.planning/phases/${dirName}`, path: dirPath }, raw, dirPath);
527
+ return;
528
+ }
529
+ default:
530
+ error(`Unknown scaffold type: ${type}. Available: context, uat, verification, phase-dir`);
531
+ }
532
+
533
+ if (fs.existsSync(filePath)) {
534
+ output({ created: false, reason: 'already_exists', path: filePath }, raw, 'exists');
535
+ return;
536
+ }
537
+
538
+ fs.writeFileSync(filePath, content, 'utf-8');
539
+ const relPath = path.relative(cwd, filePath);
540
+ output({ created: true, path: relPath }, raw, relPath);
541
+ }
542
+
543
+ module.exports = {
544
+ cmdGenerateSlug,
545
+ cmdCurrentTimestamp,
546
+ cmdListTodos,
547
+ cmdVerifyPathExists,
548
+ cmdHistoryDigest,
549
+ cmdResolveModel,
550
+ cmdCommit,
551
+ cmdSummaryExtract,
552
+ cmdWebsearch,
553
+ cmdProgressRender,
554
+ cmdTodoComplete,
555
+ cmdScaffold,
556
+ };