@m3hti/commit-genie 3.2.0 → 3.3.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 (160) hide show
  1. package/.claude/agents/gsd-codebase-mapper.md +764 -0
  2. package/.claude/agents/gsd-debugger.md +1246 -0
  3. package/.claude/agents/gsd-executor.md +469 -0
  4. package/.claude/agents/gsd-integration-checker.md +443 -0
  5. package/.claude/agents/gsd-phase-researcher.md +546 -0
  6. package/.claude/agents/gsd-plan-checker.md +690 -0
  7. package/.claude/agents/gsd-planner.md +1275 -0
  8. package/.claude/agents/gsd-project-researcher.md +621 -0
  9. package/.claude/agents/gsd-research-synthesizer.md +239 -0
  10. package/.claude/agents/gsd-roadmapper.md +642 -0
  11. package/.claude/agents/gsd-verifier.md +573 -0
  12. package/.claude/commands/gsd/add-phase.md +43 -0
  13. package/.claude/commands/gsd/add-tests.md +41 -0
  14. package/.claude/commands/gsd/add-todo.md +47 -0
  15. package/.claude/commands/gsd/audit-milestone.md +36 -0
  16. package/.claude/commands/gsd/check-todos.md +45 -0
  17. package/.claude/commands/gsd/cleanup.md +18 -0
  18. package/.claude/commands/gsd/complete-milestone.md +136 -0
  19. package/.claude/commands/gsd/debug.md +167 -0
  20. package/.claude/commands/gsd/discuss-phase.md +83 -0
  21. package/.claude/commands/gsd/execute-phase.md +41 -0
  22. package/.claude/commands/gsd/health.md +22 -0
  23. package/.claude/commands/gsd/help.md +22 -0
  24. package/.claude/commands/gsd/insert-phase.md +32 -0
  25. package/.claude/commands/gsd/join-discord.md +18 -0
  26. package/.claude/commands/gsd/list-phase-assumptions.md +46 -0
  27. package/.claude/commands/gsd/map-codebase.md +71 -0
  28. package/.claude/commands/gsd/new-milestone.md +44 -0
  29. package/.claude/commands/gsd/new-project.md +42 -0
  30. package/.claude/commands/gsd/new-project.md.bak +1041 -0
  31. package/.claude/commands/gsd/pause-work.md +38 -0
  32. package/.claude/commands/gsd/plan-milestone-gaps.md +34 -0
  33. package/.claude/commands/gsd/plan-phase.md +45 -0
  34. package/.claude/commands/gsd/progress.md +24 -0
  35. package/.claude/commands/gsd/quick.md +41 -0
  36. package/.claude/commands/gsd/reapply-patches.md +110 -0
  37. package/.claude/commands/gsd/remove-phase.md +31 -0
  38. package/.claude/commands/gsd/research-phase.md +189 -0
  39. package/.claude/commands/gsd/resume-work.md +40 -0
  40. package/.claude/commands/gsd/set-profile.md +34 -0
  41. package/.claude/commands/gsd/settings.md +36 -0
  42. package/.claude/commands/gsd/update.md +37 -0
  43. package/.claude/commands/gsd/verify-work.md +38 -0
  44. package/.claude/get-shit-done/VERSION +1 -0
  45. package/.claude/get-shit-done/bin/gsd-tools.cjs +588 -0
  46. package/.claude/get-shit-done/bin/lib/commands.cjs +553 -0
  47. package/.claude/get-shit-done/bin/lib/config.cjs +162 -0
  48. package/.claude/get-shit-done/bin/lib/core.cjs +411 -0
  49. package/.claude/get-shit-done/bin/lib/frontmatter.cjs +299 -0
  50. package/.claude/get-shit-done/bin/lib/init.cjs +710 -0
  51. package/.claude/get-shit-done/bin/lib/milestone.cjs +216 -0
  52. package/.claude/get-shit-done/bin/lib/phase.cjs +871 -0
  53. package/.claude/get-shit-done/bin/lib/roadmap.cjs +298 -0
  54. package/.claude/get-shit-done/bin/lib/state.cjs +679 -0
  55. package/.claude/get-shit-done/bin/lib/template.cjs +222 -0
  56. package/.claude/get-shit-done/bin/lib/verify.cjs +773 -0
  57. package/.claude/get-shit-done/references/checkpoints.md +776 -0
  58. package/.claude/get-shit-done/references/continuation-format.md +249 -0
  59. package/.claude/get-shit-done/references/decimal-phase-calculation.md +65 -0
  60. package/.claude/get-shit-done/references/git-integration.md +248 -0
  61. package/.claude/get-shit-done/references/git-planning-commit.md +38 -0
  62. package/.claude/get-shit-done/references/model-profile-resolution.md +34 -0
  63. package/.claude/get-shit-done/references/model-profiles.md +92 -0
  64. package/.claude/get-shit-done/references/phase-argument-parsing.md +61 -0
  65. package/.claude/get-shit-done/references/planning-config.md +196 -0
  66. package/.claude/get-shit-done/references/questioning.md +145 -0
  67. package/.claude/get-shit-done/references/tdd.md +263 -0
  68. package/.claude/get-shit-done/references/ui-brand.md +160 -0
  69. package/.claude/get-shit-done/references/verification-patterns.md +612 -0
  70. package/.claude/get-shit-done/templates/DEBUG.md +164 -0
  71. package/.claude/get-shit-done/templates/UAT.md +247 -0
  72. package/.claude/get-shit-done/templates/VALIDATION.md +76 -0
  73. package/.claude/get-shit-done/templates/codebase/architecture.md +255 -0
  74. package/.claude/get-shit-done/templates/codebase/concerns.md +310 -0
  75. package/.claude/get-shit-done/templates/codebase/conventions.md +307 -0
  76. package/.claude/get-shit-done/templates/codebase/integrations.md +280 -0
  77. package/.claude/get-shit-done/templates/codebase/stack.md +186 -0
  78. package/.claude/get-shit-done/templates/codebase/structure.md +285 -0
  79. package/.claude/get-shit-done/templates/codebase/testing.md +480 -0
  80. package/.claude/get-shit-done/templates/config.json +37 -0
  81. package/.claude/get-shit-done/templates/context.md +283 -0
  82. package/.claude/get-shit-done/templates/continue-here.md +78 -0
  83. package/.claude/get-shit-done/templates/debug-subagent-prompt.md +91 -0
  84. package/.claude/get-shit-done/templates/discovery.md +146 -0
  85. package/.claude/get-shit-done/templates/milestone-archive.md +123 -0
  86. package/.claude/get-shit-done/templates/milestone.md +115 -0
  87. package/.claude/get-shit-done/templates/phase-prompt.md +569 -0
  88. package/.claude/get-shit-done/templates/planner-subagent-prompt.md +117 -0
  89. package/.claude/get-shit-done/templates/project.md +184 -0
  90. package/.claude/get-shit-done/templates/requirements.md +231 -0
  91. package/.claude/get-shit-done/templates/research-project/ARCHITECTURE.md +204 -0
  92. package/.claude/get-shit-done/templates/research-project/FEATURES.md +147 -0
  93. package/.claude/get-shit-done/templates/research-project/PITFALLS.md +200 -0
  94. package/.claude/get-shit-done/templates/research-project/STACK.md +120 -0
  95. package/.claude/get-shit-done/templates/research-project/SUMMARY.md +170 -0
  96. package/.claude/get-shit-done/templates/research.md +552 -0
  97. package/.claude/get-shit-done/templates/retrospective.md +54 -0
  98. package/.claude/get-shit-done/templates/roadmap.md +202 -0
  99. package/.claude/get-shit-done/templates/state.md +176 -0
  100. package/.claude/get-shit-done/templates/summary-complex.md +59 -0
  101. package/.claude/get-shit-done/templates/summary-minimal.md +41 -0
  102. package/.claude/get-shit-done/templates/summary-standard.md +48 -0
  103. package/.claude/get-shit-done/templates/summary.md +248 -0
  104. package/.claude/get-shit-done/templates/user-setup.md +311 -0
  105. package/.claude/get-shit-done/templates/verification-report.md +322 -0
  106. package/.claude/get-shit-done/workflows/add-phase.md +111 -0
  107. package/.claude/get-shit-done/workflows/add-tests.md +350 -0
  108. package/.claude/get-shit-done/workflows/add-todo.md +157 -0
  109. package/.claude/get-shit-done/workflows/audit-milestone.md +297 -0
  110. package/.claude/get-shit-done/workflows/check-todos.md +176 -0
  111. package/.claude/get-shit-done/workflows/cleanup.md +152 -0
  112. package/.claude/get-shit-done/workflows/complete-milestone.md +763 -0
  113. package/.claude/get-shit-done/workflows/diagnose-issues.md +219 -0
  114. package/.claude/get-shit-done/workflows/discovery-phase.md +289 -0
  115. package/.claude/get-shit-done/workflows/discuss-phase.md +542 -0
  116. package/.claude/get-shit-done/workflows/execute-phase.md +449 -0
  117. package/.claude/get-shit-done/workflows/execute-plan.md +448 -0
  118. package/.claude/get-shit-done/workflows/health.md +156 -0
  119. package/.claude/get-shit-done/workflows/help.md +489 -0
  120. package/.claude/get-shit-done/workflows/insert-phase.md +129 -0
  121. package/.claude/get-shit-done/workflows/list-phase-assumptions.md +178 -0
  122. package/.claude/get-shit-done/workflows/map-codebase.md +315 -0
  123. package/.claude/get-shit-done/workflows/new-milestone.md +382 -0
  124. package/.claude/get-shit-done/workflows/new-project.md +1116 -0
  125. package/.claude/get-shit-done/workflows/pause-work.md +122 -0
  126. package/.claude/get-shit-done/workflows/plan-milestone-gaps.md +274 -0
  127. package/.claude/get-shit-done/workflows/plan-phase.md +569 -0
  128. package/.claude/get-shit-done/workflows/progress.md +381 -0
  129. package/.claude/get-shit-done/workflows/quick.md +453 -0
  130. package/.claude/get-shit-done/workflows/remove-phase.md +154 -0
  131. package/.claude/get-shit-done/workflows/research-phase.md +73 -0
  132. package/.claude/get-shit-done/workflows/resume-project.md +306 -0
  133. package/.claude/get-shit-done/workflows/set-profile.md +80 -0
  134. package/.claude/get-shit-done/workflows/settings.md +213 -0
  135. package/.claude/get-shit-done/workflows/transition.md +544 -0
  136. package/.claude/get-shit-done/workflows/update.md +219 -0
  137. package/.claude/get-shit-done/workflows/verify-phase.md +242 -0
  138. package/.claude/get-shit-done/workflows/verify-work.md +569 -0
  139. package/.claude/gsd-file-manifest.json +144 -0
  140. package/.claude/hooks/gsd-check-update.js +62 -0
  141. package/.claude/hooks/gsd-context-monitor.js +122 -0
  142. package/.claude/hooks/gsd-statusline.js +108 -0
  143. package/.claude/package.json +1 -0
  144. package/.claude/settings.json +49 -0
  145. package/dist/commands/generate.d.ts.map +1 -1
  146. package/dist/commands/generate.js +18 -8
  147. package/dist/commands/generate.js.map +1 -1
  148. package/dist/services/analyzerService.d.ts.map +1 -1
  149. package/dist/services/analyzerService.js +10 -0
  150. package/dist/services/analyzerService.js.map +1 -1
  151. package/dist/services/descriptionGenerator.d.ts.map +1 -1
  152. package/dist/services/descriptionGenerator.js +56 -14
  153. package/dist/services/descriptionGenerator.js.map +1 -1
  154. package/dist/services/fileContentAnalyzer.js +136 -17
  155. package/dist/services/fileContentAnalyzer.js.map +1 -1
  156. package/dist/services/fileContentAnalyzer.test.js +64 -0
  157. package/dist/services/fileContentAnalyzer.test.js.map +1 -1
  158. package/dist/services/semanticAnalyzer.js +20 -0
  159. package/dist/services/semanticAnalyzer.js.map +1 -1
  160. package/package.json +1 -1
@@ -0,0 +1,553 @@
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, comparePhaseNum, 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
+ requirements_completed: fm['requirements-completed'] || [],
308
+ };
309
+
310
+ // If fields specified, filter to only those fields
311
+ if (fields && fields.length > 0) {
312
+ const filtered = { path: summaryPath };
313
+ for (const field of fields) {
314
+ if (fullResult[field] !== undefined) {
315
+ filtered[field] = fullResult[field];
316
+ }
317
+ }
318
+ output(filtered, raw);
319
+ return;
320
+ }
321
+
322
+ output(fullResult, raw);
323
+ }
324
+
325
+ async function cmdWebsearch(query, options, raw) {
326
+ const apiKey = process.env.BRAVE_API_KEY;
327
+
328
+ if (!apiKey) {
329
+ // No key = silent skip, agent falls back to built-in WebSearch
330
+ output({ available: false, reason: 'BRAVE_API_KEY not set' }, raw, '');
331
+ return;
332
+ }
333
+
334
+ if (!query) {
335
+ output({ available: false, error: 'Query required' }, raw, '');
336
+ return;
337
+ }
338
+
339
+ const params = new URLSearchParams({
340
+ q: query,
341
+ count: String(options.limit || 10),
342
+ country: 'us',
343
+ search_lang: 'en',
344
+ text_decorations: 'false'
345
+ });
346
+
347
+ if (options.freshness) {
348
+ params.set('freshness', options.freshness);
349
+ }
350
+
351
+ try {
352
+ const response = await fetch(
353
+ `https://api.search.brave.com/res/v1/web/search?${params}`,
354
+ {
355
+ headers: {
356
+ 'Accept': 'application/json',
357
+ 'X-Subscription-Token': apiKey
358
+ }
359
+ }
360
+ );
361
+
362
+ if (!response.ok) {
363
+ output({ available: false, error: `API error: ${response.status}` }, raw, '');
364
+ return;
365
+ }
366
+
367
+ const data = await response.json();
368
+
369
+ const results = (data.web?.results || []).map(r => ({
370
+ title: r.title,
371
+ url: r.url,
372
+ description: r.description,
373
+ age: r.age || null
374
+ }));
375
+
376
+ output({
377
+ available: true,
378
+ query,
379
+ count: results.length,
380
+ results
381
+ }, raw, results.map(r => `${r.title}\n${r.url}\n${r.description}`).join('\n\n'));
382
+ } catch (err) {
383
+ output({ available: false, error: err.message }, raw, '');
384
+ }
385
+ }
386
+
387
+ function cmdProgressRender(cwd, format, raw) {
388
+ const phasesDir = path.join(cwd, '.planning', 'phases');
389
+ const roadmapPath = path.join(cwd, '.planning', 'ROADMAP.md');
390
+ const milestone = getMilestoneInfo(cwd);
391
+
392
+ const phases = [];
393
+ let totalPlans = 0;
394
+ let totalSummaries = 0;
395
+
396
+ try {
397
+ const entries = fs.readdirSync(phasesDir, { withFileTypes: true });
398
+ const dirs = entries.filter(e => e.isDirectory()).map(e => e.name).sort((a, b) => comparePhaseNum(a, b));
399
+
400
+ for (const dir of dirs) {
401
+ const dm = dir.match(/^(\d+(?:\.\d+)*)-?(.*)/);
402
+ const phaseNum = dm ? dm[1] : dir;
403
+ const phaseName = dm && dm[2] ? dm[2].replace(/-/g, ' ') : '';
404
+ const phaseFiles = fs.readdirSync(path.join(phasesDir, dir));
405
+ const plans = phaseFiles.filter(f => f.endsWith('-PLAN.md') || f === 'PLAN.md').length;
406
+ const summaries = phaseFiles.filter(f => f.endsWith('-SUMMARY.md') || f === 'SUMMARY.md').length;
407
+
408
+ totalPlans += plans;
409
+ totalSummaries += summaries;
410
+
411
+ let status;
412
+ if (plans === 0) status = 'Pending';
413
+ else if (summaries >= plans) status = 'Complete';
414
+ else if (summaries > 0) status = 'In Progress';
415
+ else status = 'Planned';
416
+
417
+ phases.push({ number: phaseNum, name: phaseName, plans, summaries, status });
418
+ }
419
+ } catch {}
420
+
421
+ const percent = totalPlans > 0 ? Math.min(100, Math.round((totalSummaries / totalPlans) * 100)) : 0;
422
+
423
+ if (format === 'table') {
424
+ // Render markdown table
425
+ const barWidth = 10;
426
+ const filled = Math.round((percent / 100) * barWidth);
427
+ const bar = '\u2588'.repeat(filled) + '\u2591'.repeat(barWidth - filled);
428
+ let out = `# ${milestone.version} ${milestone.name}\n\n`;
429
+ out += `**Progress:** [${bar}] ${totalSummaries}/${totalPlans} plans (${percent}%)\n\n`;
430
+ out += `| Phase | Name | Plans | Status |\n`;
431
+ out += `|-------|------|-------|--------|\n`;
432
+ for (const p of phases) {
433
+ out += `| ${p.number} | ${p.name} | ${p.summaries}/${p.plans} | ${p.status} |\n`;
434
+ }
435
+ output({ rendered: out }, raw, out);
436
+ } else if (format === 'bar') {
437
+ const barWidth = 20;
438
+ const filled = Math.round((percent / 100) * barWidth);
439
+ const bar = '\u2588'.repeat(filled) + '\u2591'.repeat(barWidth - filled);
440
+ const text = `[${bar}] ${totalSummaries}/${totalPlans} plans (${percent}%)`;
441
+ output({ bar: text, percent, completed: totalSummaries, total: totalPlans }, raw, text);
442
+ } else {
443
+ // JSON format
444
+ output({
445
+ milestone_version: milestone.version,
446
+ milestone_name: milestone.name,
447
+ phases,
448
+ total_plans: totalPlans,
449
+ total_summaries: totalSummaries,
450
+ percent,
451
+ }, raw);
452
+ }
453
+ }
454
+
455
+ function cmdTodoComplete(cwd, filename, raw) {
456
+ if (!filename) {
457
+ error('filename required for todo complete');
458
+ }
459
+
460
+ const pendingDir = path.join(cwd, '.planning', 'todos', 'pending');
461
+ const completedDir = path.join(cwd, '.planning', 'todos', 'completed');
462
+ const sourcePath = path.join(pendingDir, filename);
463
+
464
+ if (!fs.existsSync(sourcePath)) {
465
+ error(`Todo not found: ${filename}`);
466
+ }
467
+
468
+ // Ensure completed directory exists
469
+ fs.mkdirSync(completedDir, { recursive: true });
470
+
471
+ // Read, add completion timestamp, move
472
+ let content = fs.readFileSync(sourcePath, 'utf-8');
473
+ const today = new Date().toISOString().split('T')[0];
474
+ content = `completed: ${today}\n` + content;
475
+
476
+ fs.writeFileSync(path.join(completedDir, filename), content, 'utf-8');
477
+ fs.unlinkSync(sourcePath);
478
+
479
+ output({ completed: true, file: filename, date: today }, raw, 'completed');
480
+ }
481
+
482
+ function cmdScaffold(cwd, type, options, raw) {
483
+ const { phase, name } = options;
484
+ const padded = phase ? normalizePhaseName(phase) : '00';
485
+ const today = new Date().toISOString().split('T')[0];
486
+
487
+ // Find phase directory
488
+ const phaseInfo = phase ? findPhaseInternal(cwd, phase) : null;
489
+ const phaseDir = phaseInfo ? path.join(cwd, phaseInfo.directory) : null;
490
+
491
+ if (phase && !phaseDir && type !== 'phase-dir') {
492
+ error(`Phase ${phase} directory not found`);
493
+ }
494
+
495
+ let filePath, content;
496
+
497
+ switch (type) {
498
+ case 'context': {
499
+ filePath = path.join(phaseDir, `${padded}-CONTEXT.md`);
500
+ 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`;
501
+ break;
502
+ }
503
+ case 'uat': {
504
+ filePath = path.join(phaseDir, `${padded}-UAT.md`);
505
+ 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`;
506
+ break;
507
+ }
508
+ case 'verification': {
509
+ filePath = path.join(phaseDir, `${padded}-VERIFICATION.md`);
510
+ 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`;
511
+ break;
512
+ }
513
+ case 'phase-dir': {
514
+ if (!phase || !name) {
515
+ error('phase and name required for phase-dir scaffold');
516
+ }
517
+ const slug = generateSlugInternal(name);
518
+ const dirName = `${padded}-${slug}`;
519
+ const phasesParent = path.join(cwd, '.planning', 'phases');
520
+ fs.mkdirSync(phasesParent, { recursive: true });
521
+ const dirPath = path.join(phasesParent, dirName);
522
+ fs.mkdirSync(dirPath, { recursive: true });
523
+ output({ created: true, directory: `.planning/phases/${dirName}`, path: dirPath }, raw, dirPath);
524
+ return;
525
+ }
526
+ default:
527
+ error(`Unknown scaffold type: ${type}. Available: context, uat, verification, phase-dir`);
528
+ }
529
+
530
+ if (fs.existsSync(filePath)) {
531
+ output({ created: false, reason: 'already_exists', path: filePath }, raw, 'exists');
532
+ return;
533
+ }
534
+
535
+ fs.writeFileSync(filePath, content, 'utf-8');
536
+ const relPath = path.relative(cwd, filePath);
537
+ output({ created: true, path: relPath }, raw, relPath);
538
+ }
539
+
540
+ module.exports = {
541
+ cmdGenerateSlug,
542
+ cmdCurrentTimestamp,
543
+ cmdListTodos,
544
+ cmdVerifyPathExists,
545
+ cmdHistoryDigest,
546
+ cmdResolveModel,
547
+ cmdCommit,
548
+ cmdSummaryExtract,
549
+ cmdWebsearch,
550
+ cmdProgressRender,
551
+ cmdTodoComplete,
552
+ cmdScaffold,
553
+ };