gsd-pi 2.39.0 → 2.40.0-dev.4a93031

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 (133) hide show
  1. package/dist/resource-loader.js +66 -2
  2. package/dist/resources/extensions/async-jobs/index.js +10 -0
  3. package/dist/resources/extensions/get-secrets-from-user.js +1 -1
  4. package/dist/resources/extensions/gsd/auto-dashboard.js +7 -0
  5. package/dist/resources/extensions/gsd/auto-loop.js +761 -673
  6. package/dist/resources/extensions/gsd/auto-post-unit.js +10 -2
  7. package/dist/resources/extensions/gsd/auto-prompts.js +3 -3
  8. package/dist/resources/extensions/gsd/auto-start.js +6 -1
  9. package/dist/resources/extensions/gsd/auto.js +6 -4
  10. package/dist/resources/extensions/gsd/bootstrap/agent-end-recovery.js +126 -0
  11. package/dist/resources/extensions/gsd/bootstrap/db-tools.js +233 -0
  12. package/dist/resources/extensions/gsd/bootstrap/dynamic-tools.js +59 -0
  13. package/dist/resources/extensions/gsd/bootstrap/register-extension.js +38 -0
  14. package/dist/resources/extensions/gsd/bootstrap/register-hooks.js +156 -0
  15. package/dist/resources/extensions/gsd/bootstrap/register-shortcuts.js +46 -0
  16. package/dist/resources/extensions/gsd/bootstrap/system-context.js +300 -0
  17. package/dist/resources/extensions/gsd/bootstrap/write-gate.js +38 -0
  18. package/dist/resources/extensions/gsd/commands/catalog.js +278 -0
  19. package/dist/resources/extensions/gsd/commands/context.js +84 -0
  20. package/dist/resources/extensions/gsd/commands/dispatcher.js +21 -0
  21. package/dist/resources/extensions/gsd/commands/handlers/auto.js +72 -0
  22. package/dist/resources/extensions/gsd/commands/handlers/core.js +246 -0
  23. package/dist/resources/extensions/gsd/commands/handlers/ops.js +166 -0
  24. package/dist/resources/extensions/gsd/commands/handlers/parallel.js +94 -0
  25. package/dist/resources/extensions/gsd/commands/handlers/workflow.js +102 -0
  26. package/dist/resources/extensions/gsd/commands/index.js +11 -0
  27. package/dist/resources/extensions/gsd/commands-handlers.js +1 -1
  28. package/dist/resources/extensions/gsd/commands.js +8 -1190
  29. package/dist/resources/extensions/gsd/dashboard-overlay.js +9 -0
  30. package/dist/resources/extensions/gsd/doctor-proactive.js +80 -10
  31. package/dist/resources/extensions/gsd/doctor.js +32 -2
  32. package/dist/resources/extensions/gsd/export-html.js +46 -0
  33. package/dist/resources/extensions/gsd/files.js +1 -1
  34. package/dist/resources/extensions/gsd/health-widget.js +1 -1
  35. package/dist/resources/extensions/gsd/index.js +4 -1115
  36. package/dist/resources/extensions/gsd/progress-score.js +20 -1
  37. package/dist/resources/extensions/gsd/prompts/forensics.md +121 -46
  38. package/dist/resources/extensions/gsd/visualizer-data.js +26 -1
  39. package/dist/resources/extensions/gsd/visualizer-views.js +52 -0
  40. package/dist/welcome-screen.d.ts +3 -2
  41. package/dist/welcome-screen.js +66 -22
  42. package/package.json +1 -1
  43. package/packages/pi-coding-agent/dist/core/agent-session.d.ts +12 -0
  44. package/packages/pi-coding-agent/dist/core/agent-session.d.ts.map +1 -1
  45. package/packages/pi-coding-agent/dist/core/agent-session.js +107 -24
  46. package/packages/pi-coding-agent/dist/core/agent-session.js.map +1 -1
  47. package/packages/pi-coding-agent/dist/core/skill-tool.test.d.ts +2 -0
  48. package/packages/pi-coding-agent/dist/core/skill-tool.test.d.ts.map +1 -0
  49. package/packages/pi-coding-agent/dist/core/skill-tool.test.js +70 -0
  50. package/packages/pi-coding-agent/dist/core/skill-tool.test.js.map +1 -0
  51. package/packages/pi-coding-agent/dist/core/skills.d.ts.map +1 -1
  52. package/packages/pi-coding-agent/dist/core/skills.js +2 -1
  53. package/packages/pi-coding-agent/dist/core/skills.js.map +1 -1
  54. package/packages/pi-coding-agent/dist/modes/interactive/controllers/chat-controller.d.ts +17 -0
  55. package/packages/pi-coding-agent/dist/modes/interactive/controllers/chat-controller.d.ts.map +1 -0
  56. package/packages/pi-coding-agent/dist/modes/interactive/controllers/chat-controller.js +244 -0
  57. package/packages/pi-coding-agent/dist/modes/interactive/controllers/chat-controller.js.map +1 -0
  58. package/packages/pi-coding-agent/dist/modes/interactive/controllers/extension-ui-controller.d.ts +3 -0
  59. package/packages/pi-coding-agent/dist/modes/interactive/controllers/extension-ui-controller.d.ts.map +1 -0
  60. package/packages/pi-coding-agent/dist/modes/interactive/controllers/extension-ui-controller.js +58 -0
  61. package/packages/pi-coding-agent/dist/modes/interactive/controllers/extension-ui-controller.js.map +1 -0
  62. package/packages/pi-coding-agent/dist/modes/interactive/controllers/input-controller.d.ts +12 -0
  63. package/packages/pi-coding-agent/dist/modes/interactive/controllers/input-controller.d.ts.map +1 -0
  64. package/packages/pi-coding-agent/dist/modes/interactive/controllers/input-controller.js +54 -0
  65. package/packages/pi-coding-agent/dist/modes/interactive/controllers/input-controller.js.map +1 -0
  66. package/packages/pi-coding-agent/dist/modes/interactive/controllers/model-controller.d.ts +6 -0
  67. package/packages/pi-coding-agent/dist/modes/interactive/controllers/model-controller.d.ts.map +1 -0
  68. package/packages/pi-coding-agent/dist/modes/interactive/controllers/model-controller.js +63 -0
  69. package/packages/pi-coding-agent/dist/modes/interactive/controllers/model-controller.js.map +1 -0
  70. package/packages/pi-coding-agent/dist/modes/interactive/interactive-mode-state.d.ts +38 -0
  71. package/packages/pi-coding-agent/dist/modes/interactive/interactive-mode-state.d.ts.map +1 -0
  72. package/packages/pi-coding-agent/dist/modes/interactive/interactive-mode-state.js +2 -0
  73. package/packages/pi-coding-agent/dist/modes/interactive/interactive-mode-state.js.map +1 -0
  74. package/packages/pi-coding-agent/dist/modes/interactive/interactive-mode.d.ts +1 -1
  75. package/packages/pi-coding-agent/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
  76. package/packages/pi-coding-agent/dist/modes/interactive/interactive-mode.js +15 -457
  77. package/packages/pi-coding-agent/dist/modes/interactive/interactive-mode.js.map +1 -1
  78. package/packages/pi-coding-agent/package.json +1 -1
  79. package/packages/pi-coding-agent/src/core/agent-session.ts +122 -23
  80. package/packages/pi-coding-agent/src/core/skill-tool.test.ts +89 -0
  81. package/packages/pi-coding-agent/src/core/skills.ts +2 -1
  82. package/packages/pi-coding-agent/src/modes/interactive/controllers/chat-controller.ts +302 -0
  83. package/packages/pi-coding-agent/src/modes/interactive/controllers/extension-ui-controller.ts +59 -0
  84. package/packages/pi-coding-agent/src/modes/interactive/controllers/input-controller.ts +68 -0
  85. package/packages/pi-coding-agent/src/modes/interactive/controllers/model-controller.ts +71 -0
  86. package/packages/pi-coding-agent/src/modes/interactive/interactive-mode-state.ts +37 -0
  87. package/packages/pi-coding-agent/src/modes/interactive/interactive-mode.ts +18 -510
  88. package/pkg/package.json +1 -1
  89. package/src/resources/extensions/async-jobs/index.ts +11 -0
  90. package/src/resources/extensions/get-secrets-from-user.ts +1 -1
  91. package/src/resources/extensions/gsd/auto-dashboard.ts +10 -0
  92. package/src/resources/extensions/gsd/auto-loop.ts +1075 -921
  93. package/src/resources/extensions/gsd/auto-post-unit.ts +10 -2
  94. package/src/resources/extensions/gsd/auto-prompts.ts +3 -3
  95. package/src/resources/extensions/gsd/auto-start.ts +6 -1
  96. package/src/resources/extensions/gsd/auto.ts +13 -10
  97. package/src/resources/extensions/gsd/bootstrap/agent-end-recovery.ts +142 -0
  98. package/src/resources/extensions/gsd/bootstrap/db-tools.ts +238 -0
  99. package/src/resources/extensions/gsd/bootstrap/dynamic-tools.ts +90 -0
  100. package/src/resources/extensions/gsd/bootstrap/register-extension.ts +46 -0
  101. package/src/resources/extensions/gsd/bootstrap/register-hooks.ts +167 -0
  102. package/src/resources/extensions/gsd/bootstrap/register-shortcuts.ts +55 -0
  103. package/src/resources/extensions/gsd/bootstrap/system-context.ts +340 -0
  104. package/src/resources/extensions/gsd/bootstrap/write-gate.ts +51 -0
  105. package/src/resources/extensions/gsd/commands/catalog.ts +301 -0
  106. package/src/resources/extensions/gsd/commands/context.ts +101 -0
  107. package/src/resources/extensions/gsd/commands/dispatcher.ts +32 -0
  108. package/src/resources/extensions/gsd/commands/handlers/auto.ts +74 -0
  109. package/src/resources/extensions/gsd/commands/handlers/core.ts +274 -0
  110. package/src/resources/extensions/gsd/commands/handlers/ops.ts +169 -0
  111. package/src/resources/extensions/gsd/commands/handlers/parallel.ts +118 -0
  112. package/src/resources/extensions/gsd/commands/handlers/workflow.ts +109 -0
  113. package/src/resources/extensions/gsd/commands/index.ts +14 -0
  114. package/src/resources/extensions/gsd/commands-handlers.ts +1 -1
  115. package/src/resources/extensions/gsd/commands.ts +10 -1329
  116. package/src/resources/extensions/gsd/dashboard-overlay.ts +10 -0
  117. package/src/resources/extensions/gsd/doctor-proactive.ts +106 -10
  118. package/src/resources/extensions/gsd/doctor.ts +47 -3
  119. package/src/resources/extensions/gsd/export-html.ts +51 -0
  120. package/src/resources/extensions/gsd/files.ts +1 -1
  121. package/src/resources/extensions/gsd/health-widget.ts +2 -1
  122. package/src/resources/extensions/gsd/index.ts +12 -1314
  123. package/src/resources/extensions/gsd/progress-score.ts +23 -0
  124. package/src/resources/extensions/gsd/prompts/forensics.md +121 -46
  125. package/src/resources/extensions/gsd/tests/auto-loop.test.ts +13 -9
  126. package/src/resources/extensions/gsd/tests/doctor-proactive.test.ts +3 -3
  127. package/src/resources/extensions/gsd/tests/provider-errors.test.ts +16 -16
  128. package/src/resources/extensions/gsd/tests/skill-activation.test.ts +4 -4
  129. package/src/resources/extensions/gsd/tests/visualizer-data.test.ts +10 -10
  130. package/src/resources/extensions/gsd/visualizer-data.ts +51 -1
  131. package/src/resources/extensions/gsd/visualizer-views.ts +58 -0
  132. /package/dist/resources/extensions/{env-utils.js → gsd/env-utils.js} +0 -0
  133. /package/src/resources/extensions/{env-utils.ts → gsd/env-utils.ts} +0 -0
@@ -1,1191 +1,9 @@
1
- /**
2
- * GSD Command — /gsd
3
- *
4
- * One command, one wizard. Routes to smart entry or status.
5
- */
6
- import { importExtensionModule } from "@gsd/pi-coding-agent";
7
- import { existsSync, readFileSync, readdirSync, unlinkSync } from "node:fs";
8
- import { homedir } from "node:os";
9
- import { join } from "node:path";
10
- import { gsdRoot } from "./paths.js";
11
- const gsdHome = process.env.GSD_HOME || join(homedir(), ".gsd");
12
- import { enableDebug } from "./debug-logger.js";
13
- import { deriveState } from "./state.js";
14
- import { GSDDashboardOverlay } from "./dashboard-overlay.js";
15
- import { GSDVisualizerOverlay } from "./visualizer-overlay.js";
16
- import { showQueue, showDiscuss, showHeadlessMilestoneCreation } from "./guided-flow.js";
17
- import { startAuto, stopAuto, pauseAuto, isAutoActive, isAutoPaused, stopAutoRemote, checkRemoteAutoSession } from "./auto.js";
18
- import { dispatchDirectPhase } from "./auto-direct-dispatch.js";
19
- import { resolveProjectRoot } from "./worktree.js";
20
- import { assertSafeDirectory } from "./validate-directory.js";
21
- import { getGlobalGSDPreferencesPath, getProjectGSDPreferencesPath, loadEffectiveGSDPreferences, } from "./preferences.js";
22
- import { handleRemote } from "../remote-questions/mod.js";
23
- import { handleQuick } from "./quick.js";
24
- import { handleHistory } from "./history.js";
25
- import { handleUndo } from "./undo.js";
26
- import { handleExport } from "./export.js";
27
- import { isParallelActive, getOrchestratorState, getWorkerStatuses, prepareParallelStart, startParallel, stopParallel, pauseWorker, resumeWorker, } from "./parallel-orchestrator.js";
28
- import { formatEligibilityReport } from "./parallel-eligibility.js";
29
- import { mergeAllCompleted, mergeCompletedMilestone, formatMergeResults } from "./parallel-merge.js";
30
- import { resolveParallelConfig } from "./preferences.js";
31
- // ─── Imports from extracted modules ──────────────────────────────────────────
32
- import { handlePrefs, handlePrefsMode, handlePrefsWizard, ensurePreferencesFile } from "./commands-prefs-wizard.js";
33
- import { handleConfig } from "./commands-config.js";
34
- import { handleInspect } from "./commands-inspect.js";
35
- import { handleCleanupBranches, handleCleanupSnapshots, handleSkip, handleDryRun } from "./commands-maintenance.js";
36
- import { handleDoctor, handleSteer, handleCapture, handleTriage, handleKnowledge, handleRunHook, handleUpdate, handleSkillHealth } from "./commands-handlers.js";
37
- import { computeProgressScore, formatProgressLine } from "./progress-score.js";
38
- import { runEnvironmentChecks } from "./doctor-environment.js";
39
- import { handleLogs } from "./commands-logs.js";
40
- import { handleStart, handleTemplates, getTemplateCompletions } from "./commands-workflow-templates.js";
41
- import { handleCmux } from "./commands-cmux.js";
42
- import { showNextAction } from "../shared/mod.js";
43
- /** Resolve the effective project root, accounting for worktree paths. */
44
- export function projectRoot() {
45
- const cwd = process.cwd();
46
- const root = resolveProjectRoot(cwd);
47
- // When running inside a GSD worktree, the resolved root may be a "dangerous"
48
- // directory (e.g., $HOME used as a git repo root — #1317). The safety check
49
- // should validate the actual working directory, not the upstream root,
50
- // because the worktree itself is a safe project subdirectory.
51
- // Only skip the root check when we can confirm we're in a valid worktree.
52
- if (root !== cwd) {
53
- // We're in a worktree — validate the worktree path instead of the root
54
- assertSafeDirectory(cwd);
55
- }
56
- else {
57
- assertSafeDirectory(root);
58
- }
59
- return root;
60
- }
61
- /**
62
- * Guard against starting auto-mode when a remote session is already running.
63
- * Returns true if the caller should proceed with startAuto, false if handled.
64
- */
65
- async function guardRemoteSession(ctx, pi) {
66
- // Local session already active — proceed (startAuto handles re-entrant calls)
67
- if (isAutoActive() || isAutoPaused())
68
- return true;
69
- const remote = checkRemoteAutoSession(projectRoot());
70
- if (!remote.running || !remote.pid)
71
- return true;
72
- const unitLabel = remote.unitType && remote.unitId
73
- ? `${remote.unitType} (${remote.unitId})`
74
- : "unknown unit";
75
- const unitsMsg = remote.completedUnits != null
76
- ? `${remote.completedUnits} units completed`
77
- : "";
78
- const choice = await showNextAction(ctx, {
79
- title: `Auto-mode is running in another terminal (PID ${remote.pid})`,
80
- summary: [
81
- `Currently executing: ${unitLabel}`,
82
- ...(unitsMsg ? [unitsMsg] : []),
83
- ...(remote.startedAt ? [`Started: ${remote.startedAt}`] : []),
84
- ],
85
- actions: [
86
- {
87
- id: "status",
88
- label: "View status",
89
- description: "Show the current GSD progress dashboard.",
90
- recommended: true,
91
- },
92
- {
93
- id: "steer",
94
- label: "Steer the session",
95
- description: "Use /gsd steer <instruction> to redirect the running session.",
96
- },
97
- {
98
- id: "stop",
99
- label: "Stop remote session",
100
- description: `Send SIGTERM to PID ${remote.pid} to stop it gracefully.`,
101
- },
102
- {
103
- id: "force",
104
- label: "Force start (steal lock)",
105
- description: "Start a new session, terminating the existing one.",
106
- },
107
- ],
108
- notYetMessage: "Run /gsd when ready.",
109
- });
110
- if (choice === "status") {
111
- await handleStatus(ctx);
112
- return false;
113
- }
114
- if (choice === "steer") {
115
- ctx.ui.notify("Use /gsd steer <instruction> to redirect the running auto-mode session.\n" +
116
- "Example: /gsd steer Use Postgres instead of SQLite", "info");
117
- return false;
118
- }
119
- if (choice === "stop") {
120
- const result = stopAutoRemote(projectRoot());
121
- if (result.found) {
122
- ctx.ui.notify(`Sent stop signal to auto-mode session (PID ${result.pid}). It will shut down gracefully.`, "info");
123
- }
124
- else if (result.error) {
125
- ctx.ui.notify(`Failed to stop remote auto-mode: ${result.error}`, "error");
126
- }
127
- else {
128
- ctx.ui.notify("Remote session is no longer running.", "info");
129
- }
130
- return false;
131
- }
132
- if (choice === "force") {
133
- return true; // Proceed — startAuto will steal the lock
134
- }
135
- // "not_yet" or escape
136
- return false;
137
- }
138
- export function registerGSDCommand(pi) {
139
- pi.registerCommand("gsd", {
140
- description: "GSD — Get Shit Done: /gsd help|start|templates|next|auto|stop|pause|status|widget|visualize|queue|quick|capture|triage|dispatch|history|undo|rate|skip|export|cleanup|mode|prefs|config|keys|hooks|run-hook|skill-health|doctor|logs|forensics|changelog|migrate|remote|steer|knowledge|new-milestone|parallel|cmux|park|unpark|init|setup|inspect|extensions|update",
141
- getArgumentCompletions: (prefix) => {
142
- const subcommands = [
143
- { cmd: "help", desc: "Categorized command reference with descriptions" },
144
- { cmd: "next", desc: "Explicit step mode (same as /gsd)" },
145
- { cmd: "auto", desc: "Autonomous mode — research, plan, execute, commit, repeat" },
146
- { cmd: "stop", desc: "Stop auto mode gracefully" },
147
- { cmd: "pause", desc: "Pause auto-mode (preserves state, /gsd auto to resume)" },
148
- { cmd: "status", desc: "Progress dashboard" },
149
- { cmd: "widget", desc: "Cycle widget: full → small → min → off" },
150
- { cmd: "visualize", desc: "Open 10-tab workflow visualizer (progress, timeline, deps, metrics, health, agent, changes, knowledge, captures, export)" },
151
- { cmd: "queue", desc: "Queue and reorder future milestones" },
152
- { cmd: "quick", desc: "Execute a quick task without full planning overhead" },
153
- { cmd: "discuss", desc: "Discuss architecture and decisions" },
154
- { cmd: "capture", desc: "Fire-and-forget thought capture" },
155
- { cmd: "changelog", desc: "Show categorized release notes" },
156
- { cmd: "triage", desc: "Manually trigger triage of pending captures" },
157
- { cmd: "dispatch", desc: "Dispatch a specific phase directly" },
158
- { cmd: "history", desc: "View execution history" },
159
- { cmd: "rate", desc: "Rate last unit's model tier (over/ok/under) — improves adaptive routing" },
160
- { cmd: "undo", desc: "Revert last completed unit" },
161
- { cmd: "skip", desc: "Prevent a unit from auto-mode dispatch" },
162
- { cmd: "export", desc: "Export milestone/slice results" },
163
- { cmd: "cleanup", desc: "Remove merged branches or snapshots" },
164
- { cmd: "mode", desc: "Switch workflow mode (solo/team)" },
165
- { cmd: "prefs", desc: "Manage preferences (model selection, timeouts, etc.)" },
166
- { cmd: "config", desc: "Set API keys for external tools" },
167
- { cmd: "keys", desc: "API key manager — list, add, remove, test, rotate, doctor" },
168
- { cmd: "hooks", desc: "Show configured post-unit and pre-dispatch hooks" },
169
- { cmd: "run-hook", desc: "Manually trigger a specific hook" },
170
- { cmd: "skill-health", desc: "Skill lifecycle dashboard" },
171
- { cmd: "doctor", desc: "Runtime health checks with auto-fix" },
172
- { cmd: "logs", desc: "Browse activity logs, debug logs, and metrics" },
173
- { cmd: "forensics", desc: "Examine execution logs" },
174
- { cmd: "init", desc: "Project init wizard — detect, configure, bootstrap .gsd/" },
175
- { cmd: "setup", desc: "Global setup status and configuration" },
176
- { cmd: "migrate", desc: "Migrate a v1 .planning directory to .gsd format" },
177
- { cmd: "remote", desc: "Control remote auto-mode" },
178
- { cmd: "steer", desc: "Hard-steer plan documents during execution" },
179
- { cmd: "inspect", desc: "Show SQLite DB diagnostics" },
180
- { cmd: "knowledge", desc: "Add persistent project knowledge (rule, pattern, or lesson)" },
181
- { cmd: "new-milestone", desc: "Create a milestone from a specification document (headless)" },
182
- { cmd: "parallel", desc: "Parallel milestone orchestration (start, status, stop, merge)" },
183
- { cmd: "cmux", desc: "Manage cmux integration (status, sidebar, notifications, splits)" },
184
- { cmd: "park", desc: "Park a milestone — skip without deleting" },
185
- { cmd: "unpark", desc: "Reactivate a parked milestone" },
186
- { cmd: "update", desc: "Update GSD to the latest version" },
187
- { cmd: "start", desc: "Start a workflow template (bugfix, spike, feature, etc.)" },
188
- { cmd: "templates", desc: "List available workflow templates" },
189
- { cmd: "extensions", desc: "Manage extensions (list, enable, disable, info)" },
190
- ];
191
- const hasTrailingSpace = prefix.endsWith(" ");
192
- const parts = prefix.trim().split(/\s+/);
193
- if (hasTrailingSpace && parts.length >= 1) {
194
- parts.push("");
195
- }
196
- if (parts.length <= 1) {
197
- return subcommands
198
- .filter((item) => item.cmd.startsWith(parts[0] ?? ""))
199
- .map((item) => ({
200
- value: item.cmd,
201
- label: item.cmd,
202
- description: item.desc
203
- }));
204
- }
205
- if (parts[0] === "auto" && parts.length <= 2) {
206
- const flagPrefix = parts[1] ?? "";
207
- const flags = [
208
- { flag: "--verbose", desc: "Show detailed execution output" },
209
- { flag: "--debug", desc: "Enable debug logging" },
210
- ];
211
- return flags
212
- .filter((f) => f.flag.startsWith(flagPrefix))
213
- .map((f) => ({ value: `auto ${f.flag}`, label: f.flag, description: f.desc }));
214
- }
215
- if (parts[0] === "mode" && parts.length <= 2) {
216
- const subPrefix = parts[1] ?? "";
217
- const modes = [
218
- { cmd: "global", desc: "Edit global workflow mode" },
219
- { cmd: "project", desc: "Edit project-specific workflow mode" },
220
- ];
221
- return modes
222
- .filter((m) => m.cmd.startsWith(subPrefix))
223
- .map((m) => ({ value: `mode ${m.cmd}`, label: m.cmd, description: m.desc }));
224
- }
225
- if (parts[0] === "parallel" && parts.length <= 2) {
226
- const subPrefix = parts[1] ?? "";
227
- const subs = [
228
- { cmd: "start", desc: "Start parallel milestone orchestration" },
229
- { cmd: "status", desc: "Show parallel worker statuses" },
230
- { cmd: "stop", desc: "Stop all parallel workers" },
231
- { cmd: "pause", desc: "Pause a specific worker" },
232
- { cmd: "resume", desc: "Resume a paused worker" },
233
- { cmd: "merge", desc: "Merge completed milestone branches" },
234
- ];
235
- return subs
236
- .filter((s) => s.cmd.startsWith(subPrefix))
237
- .map((s) => ({ value: `parallel ${s.cmd}`, label: s.cmd, description: s.desc }));
238
- }
239
- if (parts[0] === "cmux") {
240
- if (parts.length <= 2) {
241
- const subPrefix = parts[1] ?? "";
242
- const subs = [
243
- { cmd: "status", desc: "Show cmux detection, prefs, and capabilities" },
244
- { cmd: "on", desc: "Enable cmux integration" },
245
- { cmd: "off", desc: "Disable cmux integration" },
246
- { cmd: "notifications", desc: "Toggle cmux desktop notifications" },
247
- { cmd: "sidebar", desc: "Toggle cmux sidebar metadata" },
248
- { cmd: "splits", desc: "Toggle cmux visual subagent splits" },
249
- { cmd: "browser", desc: "Toggle future browser integration flag" },
250
- ];
251
- return subs
252
- .filter((s) => s.cmd.startsWith(subPrefix))
253
- .map((s) => ({ value: `cmux ${s.cmd}`, label: s.cmd, description: s.desc }));
254
- }
255
- if (parts.length <= 3 && ["notifications", "sidebar", "splits", "browser"].includes(parts[1])) {
256
- const togglePrefix = parts[2] ?? "";
257
- return [
258
- { cmd: "on", desc: "Enable this cmux area" },
259
- { cmd: "off", desc: "Disable this cmux area" },
260
- ]
261
- .filter((item) => item.cmd.startsWith(togglePrefix))
262
- .map((item) => ({
263
- value: `cmux ${parts[1]} ${item.cmd}`,
264
- label: item.cmd,
265
- description: item.desc,
266
- }));
267
- }
268
- }
269
- if (parts[0] === "setup" && parts.length <= 2) {
270
- const subPrefix = parts[1] ?? "";
271
- const subs = [
272
- { cmd: "llm", desc: "Configure LLM provider settings" },
273
- { cmd: "search", desc: "Configure web search provider" },
274
- { cmd: "remote", desc: "Configure remote integrations" },
275
- { cmd: "keys", desc: "Manage API keys" },
276
- { cmd: "prefs", desc: "Configure global preferences" },
277
- ];
278
- return subs
279
- .filter((s) => s.cmd.startsWith(subPrefix))
280
- .map((s) => ({ value: `setup ${s.cmd}`, label: s.cmd, description: s.desc }));
281
- }
282
- if (parts[0] === "logs" && parts.length <= 2) {
283
- const subPrefix = parts[1] ?? "";
284
- const subs = [
285
- { cmd: "debug", desc: "List or view debug log files" },
286
- { cmd: "tail", desc: "Show last N activity log summaries" },
287
- { cmd: "clear", desc: "Remove old activity and debug logs" },
288
- ];
289
- return subs
290
- .filter((s) => s.cmd.startsWith(subPrefix))
291
- .map((s) => ({ value: `logs ${s.cmd}`, label: s.cmd, description: s.desc }));
292
- }
293
- if (parts[0] === "keys" && parts.length <= 2) {
294
- const subPrefix = parts[1] ?? "";
295
- const subs = [
296
- { cmd: "list", desc: "Show key status dashboard" },
297
- { cmd: "add", desc: "Add a key for a provider" },
298
- { cmd: "remove", desc: "Remove a key" },
299
- { cmd: "test", desc: "Validate key(s) with API call" },
300
- { cmd: "rotate", desc: "Replace an existing key" },
301
- { cmd: "doctor", desc: "Health check all keys" },
302
- ];
303
- return subs
304
- .filter((s) => s.cmd.startsWith(subPrefix))
305
- .map((s) => ({ value: `keys ${s.cmd}`, label: s.cmd, description: s.desc }));
306
- }
307
- if (parts[0] === "prefs" && parts.length <= 2) {
308
- const subPrefix = parts[1] ?? "";
309
- const subs = [
310
- { cmd: "global", desc: "Edit global preferences file" },
311
- { cmd: "project", desc: "Edit project preferences file" },
312
- { cmd: "status", desc: "Show effective preferences" },
313
- { cmd: "wizard", desc: "Interactive preferences wizard" },
314
- { cmd: "setup", desc: "First-time preferences setup" },
315
- { cmd: "import-claude", desc: "Import settings from Claude Code" },
316
- ];
317
- return subs
318
- .filter((s) => s.cmd.startsWith(subPrefix))
319
- .map((s) => ({ value: `prefs ${s.cmd}`, label: s.cmd, description: s.desc }));
320
- }
321
- if (parts[0] === "remote" && parts.length <= 2) {
322
- const subPrefix = parts[1] ?? "";
323
- const subs = [
324
- { cmd: "slack", desc: "Configure Slack integration" },
325
- { cmd: "discord", desc: "Configure Discord integration" },
326
- { cmd: "status", desc: "Show remote connection status" },
327
- { cmd: "disconnect", desc: "Disconnect remote integrations" },
328
- ];
329
- return subs
330
- .filter((s) => s.cmd.startsWith(subPrefix))
331
- .map((s) => ({ value: `remote ${s.cmd}`, label: s.cmd, description: s.desc }));
332
- }
333
- if (parts[0] === "next" && parts.length <= 2) {
334
- const flagPrefix = parts[1] ?? "";
335
- const flags = [
336
- { flag: "--verbose", desc: "Show detailed step output" },
337
- { flag: "--dry-run", desc: "Preview next step without executing" },
338
- ];
339
- return flags
340
- .filter((f) => f.flag.startsWith(flagPrefix))
341
- .map((f) => ({ value: `next ${f.flag}`, label: f.flag, description: f.desc }));
342
- }
343
- if (parts[0] === "history" && parts.length <= 2) {
344
- const flagPrefix = parts[1] ?? "";
345
- const flags = [
346
- { flag: "--cost", desc: "Show cost breakdown per entry" },
347
- { flag: "--phase", desc: "Filter by phase type" },
348
- { flag: "--model", desc: "Filter by model used" },
349
- { flag: "10", desc: "Show last 10 entries" },
350
- { flag: "20", desc: "Show last 20 entries" },
351
- { flag: "50", desc: "Show last 50 entries" },
352
- ];
353
- return flags
354
- .filter((f) => f.flag.startsWith(flagPrefix))
355
- .map((f) => ({ value: `history ${f.flag}`, label: f.flag, description: f.desc }));
356
- }
357
- if (parts[0] === "undo" && parts.length <= 2) {
358
- return [{ value: "undo --force", label: "--force", description: "Skip confirmation prompt" }];
359
- }
360
- if (parts[0] === "export" && parts.length <= 2) {
361
- const flagPrefix = parts[1] ?? "";
362
- const flags = [
363
- { flag: "--json", desc: "Export as JSON" },
364
- { flag: "--markdown", desc: "Export as Markdown" },
365
- { flag: "--html", desc: "Export as HTML" },
366
- { flag: "--html --all", desc: "Export all milestones as HTML" },
367
- ];
368
- return flags
369
- .filter((f) => f.flag.startsWith(flagPrefix))
370
- .map((f) => ({ value: `export ${f.flag}`, label: f.flag, description: f.desc }));
371
- }
372
- if (parts[0] === "cleanup" && parts.length <= 2) {
373
- const subPrefix = parts[1] ?? "";
374
- const subs = [
375
- { cmd: "branches", desc: "Remove merged milestone branches" },
376
- { cmd: "snapshots", desc: "Remove old execution snapshots" },
377
- ];
378
- return subs
379
- .filter((s) => s.cmd.startsWith(subPrefix))
380
- .map((s) => ({ value: `cleanup ${s.cmd}`, label: s.cmd, description: s.desc }));
381
- }
382
- if (parts[0] === "knowledge" && parts.length <= 2) {
383
- const subPrefix = parts[1] ?? "";
384
- const subs = [
385
- { cmd: "rule", desc: "Add a project rule (always/never do X)" },
386
- { cmd: "pattern", desc: "Add a code pattern to follow" },
387
- { cmd: "lesson", desc: "Record a lesson learned" },
388
- ];
389
- return subs
390
- .filter((s) => s.cmd.startsWith(subPrefix))
391
- .map((s) => ({ value: `knowledge ${s.cmd}`, label: s.cmd, description: s.desc }));
392
- }
393
- if (parts[0] === "start" && parts.length <= 2) {
394
- const subPrefix = parts[1] ?? "";
395
- const subs = [
396
- { cmd: "bugfix", desc: "Triage, fix, test, and ship a bug fix" },
397
- { cmd: "small-feature", desc: "Lightweight feature with optional discussion" },
398
- { cmd: "spike", desc: "Research, prototype, and document findings" },
399
- { cmd: "hotfix", desc: "Minimal: fix it, test it, ship it" },
400
- { cmd: "refactor", desc: "Inventory, plan waves, migrate, verify" },
401
- { cmd: "security-audit", desc: "Scan, triage, remediate, re-scan" },
402
- { cmd: "dep-upgrade", desc: "Assess, upgrade, fix breaks, verify" },
403
- { cmd: "full-project", desc: "Complete GSD workflow with full ceremony" },
404
- { cmd: "resume", desc: "Resume an in-progress workflow" },
405
- { cmd: "--list", desc: "List all available templates" },
406
- { cmd: "--dry-run", desc: "Preview workflow without executing" },
407
- ];
408
- return subs
409
- .filter((s) => s.cmd.startsWith(subPrefix))
410
- .map((s) => ({ value: `start ${s.cmd}`, label: s.cmd, description: s.desc }));
411
- }
412
- if (parts[0] === "templates" && parts.length <= 2) {
413
- const subPrefix = parts[1] ?? "";
414
- const subs = [
415
- { cmd: "info", desc: "Show detailed template info" },
416
- ];
417
- return subs
418
- .filter((s) => s.cmd.startsWith(subPrefix))
419
- .map((s) => ({ value: `templates ${s.cmd}`, label: s.cmd, description: s.desc }));
420
- }
421
- if (parts[0] === "templates" && parts[1] === "info" && parts.length <= 3) {
422
- const namePrefix = parts[2] ?? "";
423
- return getTemplateCompletions(namePrefix)
424
- .map((c) => ({ value: `templates ${c.value}`, label: c.label, description: c.description }));
425
- }
426
- if (parts[0] === "extensions") {
427
- if (parts.length <= 2) {
428
- const subPrefix = parts[1] ?? "";
429
- const subs = [
430
- { cmd: "list", desc: "List all extensions and their status" },
431
- { cmd: "enable", desc: "Enable a disabled extension" },
432
- { cmd: "disable", desc: "Disable an extension" },
433
- { cmd: "info", desc: "Show extension details" },
434
- ];
435
- return subs
436
- .filter((s) => s.cmd.startsWith(subPrefix))
437
- .map((s) => ({ value: `extensions ${s.cmd}`, label: s.cmd, description: s.desc }));
438
- }
439
- if (parts.length === 3 && ["enable", "disable", "info"].includes(parts[1])) {
440
- const idPrefix = parts[2] ?? "";
441
- try {
442
- const extDir = join(gsdHome, "agent", "extensions");
443
- const ids = [];
444
- for (const entry of readdirSync(extDir, { withFileTypes: true })) {
445
- if (!entry.isDirectory())
446
- continue;
447
- const mPath = join(extDir, entry.name, "extension-manifest.json");
448
- if (!existsSync(mPath))
449
- continue;
450
- try {
451
- const m = JSON.parse(readFileSync(mPath, "utf-8"));
452
- if (typeof m?.id === "string")
453
- ids.push({ id: m.id, name: m.name ?? m.id });
454
- }
455
- catch { /* skip malformed */ }
456
- }
457
- return ids
458
- .filter((e) => e.id.startsWith(idPrefix))
459
- .map((e) => ({
460
- value: `extensions ${parts[1]} ${e.id}`,
461
- label: e.id,
462
- description: e.name,
463
- }));
464
- }
465
- catch {
466
- return [];
467
- }
468
- }
469
- return [];
470
- }
471
- if (parts[0] === "doctor") {
472
- const modePrefix = parts[1] ?? "";
473
- const modes = [
474
- { cmd: "fix", desc: "Auto-fix detected issues" },
475
- { cmd: "heal", desc: "AI-driven deep healing" },
476
- { cmd: "audit", desc: "Run health audit without fixing" },
477
- { cmd: "--dry-run", desc: "Show what --fix would change without applying" },
478
- { cmd: "--json", desc: "Output report as JSON (CI/tooling friendly)" },
479
- { cmd: "--build", desc: "Include slow build health check (npm run build)" },
480
- { cmd: "--test", desc: "Include slow test health check (npm test)" },
481
- ];
482
- if (parts.length <= 2) {
483
- return modes
484
- .filter((m) => m.cmd.startsWith(modePrefix))
485
- .map((m) => ({ value: `doctor ${m.cmd}`, label: m.cmd, description: m.desc }));
486
- }
487
- return [];
488
- }
489
- if (parts[0] === "dispatch" && parts.length <= 2) {
490
- const phasePrefix = parts[1] ?? "";
491
- const phases = [
492
- { cmd: "research", desc: "Run research phase" },
493
- { cmd: "plan", desc: "Run planning phase" },
494
- { cmd: "execute", desc: "Run execution phase" },
495
- { cmd: "complete", desc: "Run completion phase" },
496
- { cmd: "reassess", desc: "Reassess current progress" },
497
- { cmd: "uat", desc: "Run user acceptance testing" },
498
- { cmd: "replan", desc: "Replan the current slice" },
499
- ];
500
- return phases
501
- .filter((p) => p.cmd.startsWith(phasePrefix))
502
- .map((p) => ({ value: `dispatch ${p.cmd}`, label: p.cmd, description: p.desc }));
503
- }
504
- if (parts[0] === "rate" && parts.length <= 2) {
505
- const tierPrefix = parts[1] ?? "";
506
- const tiers = [
507
- { cmd: "over", desc: "Model was overqualified for this task" },
508
- { cmd: "ok", desc: "Model was appropriate for this task" },
509
- { cmd: "under", desc: "Model was underqualified for this task" },
510
- ];
511
- return tiers
512
- .filter((t) => t.cmd.startsWith(tierPrefix))
513
- .map((t) => ({ value: `rate ${t.cmd}`, label: t.cmd, description: t.desc }));
514
- }
515
- return [];
516
- },
517
- async handler(args, ctx) {
518
- await handleGSDCommand(args, ctx, pi);
519
- },
520
- });
521
- }
522
- export async function handleGSDCommand(args, ctx, pi) {
523
- const trimmed = (typeof args === "string" ? args : "").trim();
524
- if (trimmed === "help" || trimmed === "h" || trimmed === "?") {
525
- showHelp(ctx);
526
- return;
527
- }
528
- if (trimmed === "status") {
529
- await handleStatus(ctx);
530
- return;
531
- }
532
- if (trimmed === "widget" || trimmed.startsWith("widget ")) {
533
- const { cycleWidgetMode, setWidgetMode, getWidgetMode } = await importExtensionModule(import.meta.url, "./auto-dashboard.js");
534
- const arg = trimmed.replace(/^widget\s*/, "").trim();
535
- if (arg === "full" || arg === "small" || arg === "min" || arg === "off") {
536
- setWidgetMode(arg);
537
- }
538
- else {
539
- cycleWidgetMode();
540
- }
541
- ctx.ui.notify(`Widget: ${getWidgetMode()}`, "info");
542
- return;
543
- }
544
- if (trimmed === "visualize") {
545
- await handleVisualize(ctx);
546
- return;
547
- }
548
- if (trimmed === "mode" || trimmed.startsWith("mode ")) {
549
- const modeArgs = trimmed.replace(/^mode\s*/, "").trim();
550
- const scope = modeArgs === "project" ? "project" : "global";
551
- const path = scope === "project" ? getProjectGSDPreferencesPath() : getGlobalGSDPreferencesPath();
552
- await ensurePreferencesFile(path, ctx, scope);
553
- await handlePrefsMode(ctx, scope);
554
- return;
555
- }
556
- if (trimmed === "prefs" || trimmed.startsWith("prefs ")) {
557
- await handlePrefs(trimmed.replace(/^prefs\s*/, "").trim(), ctx);
558
- return;
559
- }
560
- if (trimmed === "cmux" || trimmed.startsWith("cmux ")) {
561
- await handleCmux(trimmed.replace(/^cmux\s*/, "").trim(), ctx);
562
- return;
563
- }
564
- if (trimmed === "init") {
565
- const { detectProjectState } = await import("./detection.js");
566
- const { showProjectInit, handleReinit } = await import("./init-wizard.js");
567
- const basePath = projectRoot();
568
- const detection = detectProjectState(basePath);
569
- if (detection.state === "v2-gsd" || detection.state === "v2-gsd-empty") {
570
- await handleReinit(ctx, detection);
571
- }
572
- else {
573
- await showProjectInit(ctx, pi, basePath, detection);
574
- }
575
- return;
576
- }
577
- if (trimmed === "keys" || trimmed.startsWith("keys ")) {
578
- const { handleKeys } = await import("./key-manager.js");
579
- const keysArgs = trimmed.replace(/^keys\s*/, "").trim();
580
- await handleKeys(keysArgs, ctx);
581
- return;
582
- }
583
- if (trimmed === "setup" || trimmed.startsWith("setup ")) {
584
- const setupArgs = trimmed.replace(/^setup\s*/, "").trim();
585
- await handleSetup(setupArgs, ctx);
586
- return;
587
- }
588
- if (trimmed === "doctor" || trimmed.startsWith("doctor ")) {
589
- await handleDoctor(trimmed.replace(/^doctor\s*/, "").trim(), ctx, pi);
590
- return;
591
- }
592
- if (trimmed === "logs" || trimmed.startsWith("logs ")) {
593
- await handleLogs(trimmed.replace(/^logs\s*/, "").trim(), ctx);
594
- return;
595
- }
596
- if (trimmed === "forensics" || trimmed.startsWith("forensics ")) {
597
- const { handleForensics } = await import("./forensics.js");
598
- await handleForensics(trimmed.replace(/^forensics\s*/, "").trim(), ctx, pi);
599
- return;
600
- }
601
- if (trimmed === "changelog" || trimmed.startsWith("changelog ")) {
602
- const { handleChangelog } = await import("./changelog.js");
603
- await handleChangelog(trimmed.replace(/^changelog\s*/, "").trim(), ctx, pi);
604
- return;
605
- }
606
- if (trimmed === "next" || trimmed.startsWith("next ")) {
607
- if (trimmed.includes("--dry-run")) {
608
- await handleDryRun(ctx, projectRoot());
609
- return;
610
- }
611
- const verboseMode = trimmed.includes("--verbose");
612
- const debugMode = trimmed.includes("--debug");
613
- if (debugMode)
614
- enableDebug(projectRoot());
615
- if (!(await guardRemoteSession(ctx, pi)))
616
- return;
617
- await startAuto(ctx, pi, projectRoot(), verboseMode, { step: true });
618
- return;
619
- }
620
- if (trimmed === "auto" || trimmed.startsWith("auto ")) {
621
- const verboseMode = trimmed.includes("--verbose");
622
- const debugMode = trimmed.includes("--debug");
623
- if (debugMode)
624
- enableDebug(projectRoot());
625
- if (!(await guardRemoteSession(ctx, pi)))
626
- return;
627
- await startAuto(ctx, pi, projectRoot(), verboseMode);
628
- return;
629
- }
630
- if (trimmed === "stop") {
631
- if (!isAutoActive() && !isAutoPaused()) {
632
- // Not running in this process — check for a remote auto-mode session
633
- const result = stopAutoRemote(projectRoot());
634
- if (result.found) {
635
- ctx.ui.notify(`Sent stop signal to auto-mode session (PID ${result.pid}). It will shut down gracefully.`, "info");
636
- }
637
- else if (result.error) {
638
- ctx.ui.notify(`Failed to stop remote auto-mode: ${result.error}`, "error");
639
- }
640
- else {
641
- ctx.ui.notify("Auto-mode is not running.", "info");
642
- }
643
- return;
644
- }
645
- await stopAuto(ctx, pi, "User requested stop");
646
- return;
647
- }
648
- if (trimmed === "pause") {
649
- if (!isAutoActive()) {
650
- if (isAutoPaused()) {
651
- ctx.ui.notify("Auto-mode is already paused. /gsd auto to resume.", "info");
652
- }
653
- else {
654
- ctx.ui.notify("Auto-mode is not running.", "info");
655
- }
656
- return;
657
- }
658
- await pauseAuto(ctx, pi);
659
- return;
660
- }
661
- if (trimmed === "history" || trimmed.startsWith("history ")) {
662
- await handleHistory(trimmed.replace(/^history\s*/, "").trim(), ctx, projectRoot());
663
- return;
664
- }
665
- if (trimmed === "undo" || trimmed.startsWith("undo ")) {
666
- await handleUndo(trimmed.replace(/^undo\s*/, "").trim(), ctx, pi, projectRoot());
667
- return;
668
- }
669
- if (trimmed === "rate" || trimmed.startsWith("rate ")) {
670
- const { handleRate } = await import("./commands-rate.js");
671
- await handleRate(trimmed.replace(/^rate\s*/, "").trim(), ctx, projectRoot());
672
- return;
673
- }
674
- if (trimmed.startsWith("skip ")) {
675
- await handleSkip(trimmed.replace(/^skip\s*/, "").trim(), ctx, projectRoot());
676
- return;
677
- }
678
- if (trimmed === "export" || trimmed.startsWith("export ")) {
679
- await handleExport(trimmed.replace(/^export\s*/, "").trim(), ctx, projectRoot());
680
- return;
681
- }
682
- // ─── Parallel Orchestration ────────────────────────────────────────
683
- if (trimmed.startsWith("parallel")) {
684
- const parallelArgs = trimmed.slice("parallel".length).trim();
685
- const [subCmd = "", ...restParts] = parallelArgs.split(/\s+/);
686
- const rest = restParts.join(" ");
687
- if (subCmd === "start" || subCmd === "") {
688
- const loaded = loadEffectiveGSDPreferences();
689
- const config = resolveParallelConfig(loaded?.preferences);
690
- if (!config.enabled) {
691
- pi.sendMessage({
692
- customType: "gsd-parallel",
693
- content: "Parallel mode is not enabled. Set `parallel.enabled: true` in your preferences.",
694
- display: false,
695
- });
696
- return;
697
- }
698
- const candidates = await prepareParallelStart(projectRoot(), loaded?.preferences);
699
- const report = formatEligibilityReport(candidates);
700
- if (candidates.eligible.length === 0) {
701
- pi.sendMessage({ customType: "gsd-parallel", content: report + "\n\nNo milestones are eligible for parallel execution.", display: false });
702
- return;
703
- }
704
- const result = await startParallel(projectRoot(), candidates.eligible.map(e => e.milestoneId), loaded?.preferences);
705
- const lines = [`Parallel orchestration started.`, `Workers: ${result.started.join(", ")}`];
706
- if (result.errors.length > 0) {
707
- lines.push(`Errors: ${result.errors.map(e => `${e.mid}: ${e.error}`).join("; ")}`);
708
- }
709
- pi.sendMessage({ customType: "gsd-parallel", content: report + "\n\n" + lines.join("\n"), display: false });
710
- return;
711
- }
712
- if (subCmd === "status") {
713
- if (!isParallelActive()) {
714
- pi.sendMessage({ customType: "gsd-parallel", content: "No parallel orchestration is currently active.", display: false });
715
- return;
716
- }
717
- const workers = getWorkerStatuses();
718
- const lines = ["# Parallel Workers\n"];
719
- for (const w of workers) {
720
- lines.push(`- **${w.milestoneId}** (${w.title}) — ${w.state} — ${w.completedUnits} units — $${w.cost.toFixed(2)}`);
721
- }
722
- const orchState = getOrchestratorState();
723
- if (orchState) {
724
- lines.push(`\nTotal cost: $${orchState.totalCost.toFixed(2)}`);
725
- }
726
- pi.sendMessage({ customType: "gsd-parallel", content: lines.join("\n"), display: false });
727
- return;
728
- }
729
- if (subCmd === "stop") {
730
- const mid = rest.trim() || undefined;
731
- await stopParallel(projectRoot(), mid);
732
- pi.sendMessage({ customType: "gsd-parallel", content: mid ? `Stopped worker for ${mid}.` : "All parallel workers stopped.", display: false });
733
- return;
734
- }
735
- if (subCmd === "pause") {
736
- const mid = rest.trim() || undefined;
737
- pauseWorker(projectRoot(), mid);
738
- pi.sendMessage({ customType: "gsd-parallel", content: mid ? `Paused worker for ${mid}.` : "All parallel workers paused.", display: false });
739
- return;
740
- }
741
- if (subCmd === "resume") {
742
- const mid = rest.trim() || undefined;
743
- resumeWorker(projectRoot(), mid);
744
- pi.sendMessage({ customType: "gsd-parallel", content: mid ? `Resumed worker for ${mid}.` : "All parallel workers resumed.", display: false });
745
- return;
746
- }
747
- if (subCmd === "merge") {
748
- const mid = rest.trim() || undefined;
749
- if (mid) {
750
- // Merge a specific milestone
751
- const result = await mergeCompletedMilestone(projectRoot(), mid);
752
- pi.sendMessage({ customType: "gsd-parallel", content: formatMergeResults([result]), display: false });
753
- return;
754
- }
755
- // Merge all completed milestones
756
- const workers = getWorkerStatuses();
757
- if (workers.length === 0) {
758
- pi.sendMessage({ customType: "gsd-parallel", content: "No parallel workers to merge.", display: false });
759
- return;
760
- }
761
- const results = await mergeAllCompleted(projectRoot(), workers);
762
- pi.sendMessage({ customType: "gsd-parallel", content: formatMergeResults(results), display: false });
763
- return;
764
- }
765
- pi.sendMessage({
766
- customType: "gsd-parallel",
767
- content: `Unknown parallel subcommand "${subCmd}". Usage: /gsd parallel [start|status|stop|pause|resume|merge]`,
768
- display: false,
769
- });
770
- return;
771
- }
772
- if (trimmed === "cleanup") {
773
- await handleCleanupBranches(ctx, projectRoot());
774
- await handleCleanupSnapshots(ctx, projectRoot());
775
- return;
776
- }
777
- if (trimmed === "cleanup branches") {
778
- await handleCleanupBranches(ctx, projectRoot());
779
- return;
780
- }
781
- if (trimmed === "cleanup snapshots") {
782
- await handleCleanupSnapshots(ctx, projectRoot());
783
- return;
784
- }
785
- if (trimmed === "queue") {
786
- await showQueue(ctx, pi, projectRoot());
787
- return;
788
- }
789
- if (trimmed === "discuss") {
790
- await showDiscuss(ctx, pi, projectRoot());
791
- return;
792
- }
793
- if (trimmed === "park" || trimmed.startsWith("park ")) {
794
- const basePath = projectRoot();
795
- const arg = trimmed.replace(/^park\s*/, "").trim();
796
- const { parkMilestone, isParked } = await import("./milestone-actions.js");
797
- const { deriveState } = await import("./state.js");
798
- let targetId = arg;
799
- if (!targetId) {
800
- // Park the current active milestone
801
- const state = await deriveState(basePath);
802
- if (!state.activeMilestone) {
803
- ctx.ui.notify("No active milestone to park.", "warning");
804
- return;
805
- }
806
- targetId = state.activeMilestone.id;
807
- }
808
- if (isParked(basePath, targetId)) {
809
- ctx.ui.notify(`${targetId} is already parked. Use /gsd unpark ${targetId} to reactivate.`, "info");
810
- return;
811
- }
812
- // Extract reason from remaining args (e.g., /gsd park M002 "reason here")
813
- const reasonParts = arg.replace(targetId, "").trim().replace(/^["']|["']$/g, "");
814
- const reason = reasonParts || "Parked via /gsd park";
815
- const success = parkMilestone(basePath, targetId, reason);
816
- if (success) {
817
- ctx.ui.notify(`Parked ${targetId}. Run /gsd unpark ${targetId} to reactivate.`, "info");
818
- }
819
- else {
820
- ctx.ui.notify(`Could not park ${targetId} — milestone not found.`, "warning");
821
- }
822
- return;
823
- }
824
- if (trimmed === "unpark" || trimmed.startsWith("unpark ")) {
825
- const basePath = projectRoot();
826
- const arg = trimmed.replace(/^unpark\s*/, "").trim();
827
- const { unparkMilestone } = await import("./milestone-actions.js");
828
- const { deriveState } = await import("./state.js");
829
- let targetId = arg;
830
- if (!targetId) {
831
- // List parked milestones and let user pick
832
- const state = await deriveState(basePath);
833
- const parkedEntries = state.registry.filter(e => e.status === "parked");
834
- if (parkedEntries.length === 0) {
835
- ctx.ui.notify("No parked milestones.", "info");
836
- return;
837
- }
838
- if (parkedEntries.length === 1) {
839
- targetId = parkedEntries[0].id;
840
- }
841
- else {
842
- ctx.ui.notify(`Parked milestones: ${parkedEntries.map(e => e.id).join(", ")}. Specify which to unpark: /gsd unpark <id>`, "info");
843
- return;
844
- }
845
- }
846
- const success = unparkMilestone(basePath, targetId);
847
- if (success) {
848
- ctx.ui.notify(`Unparked ${targetId}. It will resume its normal position in the queue.`, "info");
849
- }
850
- else {
851
- ctx.ui.notify(`Could not unpark ${targetId} — milestone not found or not parked.`, "warning");
852
- }
853
- return;
854
- }
855
- if (trimmed === "new-milestone") {
856
- const basePath = projectRoot();
857
- const headlessContextPath = join(gsdRoot(basePath), "runtime", "headless-context.md");
858
- if (existsSync(headlessContextPath)) {
859
- const seedContext = readFileSync(headlessContextPath, "utf-8");
860
- try {
861
- unlinkSync(headlessContextPath);
862
- }
863
- catch { /* non-fatal */ }
864
- await showHeadlessMilestoneCreation(ctx, pi, basePath, seedContext);
865
- }
866
- else {
867
- // No headless context — fall back to interactive smart entry
868
- const { showSmartEntry } = await import("./guided-flow.js");
869
- await showSmartEntry(ctx, pi, basePath);
870
- }
871
- return;
872
- }
873
- if (trimmed.startsWith("capture ") || trimmed === "capture") {
874
- await handleCapture(trimmed.replace(/^capture\s*/, "").trim(), ctx);
875
- return;
876
- }
877
- if (trimmed === "triage") {
878
- await handleTriage(ctx, pi, process.cwd());
879
- return;
880
- }
881
- if (trimmed === "quick" || trimmed.startsWith("quick ")) {
882
- await handleQuick(trimmed.replace(/^quick\s*/, "").trim(), ctx, pi);
883
- return;
884
- }
885
- if (trimmed === "config") {
886
- await handleConfig(ctx);
887
- return;
888
- }
889
- if (trimmed === "hooks") {
890
- const { formatHookStatus } = await import("./post-unit-hooks.js");
891
- ctx.ui.notify(formatHookStatus(), "info");
892
- return;
893
- }
894
- // ─── Skill Health ────────────────────────────────────────────
895
- if (trimmed === "skill-health" || trimmed.startsWith("skill-health ")) {
896
- await handleSkillHealth(trimmed.replace(/^skill-health\s*/, "").trim(), ctx);
897
- return;
898
- }
899
- if (trimmed.startsWith("run-hook ")) {
900
- await handleRunHook(trimmed.replace(/^run-hook\s*/, "").trim(), ctx, pi);
901
- return;
902
- }
903
- if (trimmed === "run-hook") {
904
- ctx.ui.notify(`Usage: /gsd run-hook <hook-name> <unit-type> <unit-id>
905
-
906
- Unit types:
907
- execute-task - Task execution (unit-id: M001/S01/T01)
908
- plan-slice - Slice planning (unit-id: M001/S01)
909
- research-milestone - Milestone research (unit-id: M001)
910
- complete-slice - Slice completion (unit-id: M001/S01)
911
- complete-milestone - Milestone completion (unit-id: M001)
912
-
913
- Examples:
914
- /gsd run-hook code-review execute-task M001/S01/T01
915
- /gsd run-hook lint-check plan-slice M001/S01`, "warning");
916
- return;
917
- }
918
- if (trimmed.startsWith("steer ")) {
919
- await handleSteer(trimmed.replace(/^steer\s+/, "").trim(), ctx, pi);
920
- return;
921
- }
922
- if (trimmed === "steer") {
923
- ctx.ui.notify("Usage: /gsd steer <description of change>. Example: /gsd steer Use Postgres instead of SQLite", "warning");
924
- return;
925
- }
926
- if (trimmed.startsWith("knowledge ")) {
927
- await handleKnowledge(trimmed.replace(/^knowledge\s+/, "").trim(), ctx);
928
- return;
929
- }
930
- if (trimmed === "knowledge") {
931
- ctx.ui.notify("Usage: /gsd knowledge <rule|pattern|lesson> <description>. Example: /gsd knowledge rule Use real DB for integration tests", "warning");
932
- return;
933
- }
934
- if (trimmed === "migrate" || trimmed.startsWith("migrate ")) {
935
- const { handleMigrate } = await import("./migrate/command.js");
936
- await handleMigrate(trimmed.replace(/^migrate\s*/, "").trim(), ctx, pi);
937
- return;
938
- }
939
- if (trimmed === "remote" || trimmed.startsWith("remote ")) {
940
- await handleRemote(trimmed.replace(/^remote\s*/, "").trim(), ctx, pi);
941
- return;
942
- }
943
- if (trimmed === "dispatch" || trimmed.startsWith("dispatch ")) {
944
- const phase = trimmed.replace(/^dispatch\s*/, "").trim();
945
- if (!phase) {
946
- ctx.ui.notify("Usage: /gsd dispatch <phase> (research|plan|execute|complete|reassess|uat|replan)", "warning");
947
- return;
948
- }
949
- await dispatchDirectPhase(ctx, pi, phase, projectRoot());
950
- return;
951
- }
952
- if (trimmed === "inspect") {
953
- await handleInspect(ctx);
954
- return;
955
- }
956
- if (trimmed === "update") {
957
- await handleUpdate(ctx);
958
- return;
959
- }
960
- // ─── Workflow Templates ────────────────────────────────────────
961
- if (trimmed === "start" || trimmed.startsWith("start ")) {
962
- await handleStart(trimmed.replace(/^start\s*/, "").trim(), ctx, pi);
963
- return;
964
- }
965
- if (trimmed === "templates" || trimmed.startsWith("templates ")) {
966
- await handleTemplates(trimmed.replace(/^templates\s*/, "").trim(), ctx);
967
- return;
968
- }
969
- if (trimmed === "") {
970
- if (!(await guardRemoteSession(ctx, pi)))
971
- return;
972
- await startAuto(ctx, pi, projectRoot(), false, { step: true });
973
- return;
974
- }
975
- if (trimmed === "extensions" || trimmed.startsWith("extensions ")) {
976
- const { handleExtensions } = await import("./commands-extensions.js");
977
- await handleExtensions(trimmed.replace(/^extensions\s*/, "").trim(), ctx);
978
- return;
979
- }
980
- ctx.ui.notify(`Unknown: /gsd ${trimmed}. Run /gsd help for available commands.`, "warning");
981
- }
982
- function showHelp(ctx) {
983
- const lines = [
984
- "GSD — Get Shit Done\n",
985
- "WORKFLOW",
986
- " /gsd start <tpl> Start a workflow template (bugfix, spike, feature, hotfix, etc.)",
987
- " /gsd templates List available workflow templates [info <name>]",
988
- " /gsd Run next unit in step mode (same as /gsd next)",
989
- " /gsd next Execute next task, then pause [--dry-run] [--verbose]",
990
- " /gsd auto Run all queued units continuously [--verbose]",
991
- " /gsd stop Stop auto-mode gracefully",
992
- " /gsd pause Pause auto-mode (preserves state, /gsd auto to resume)",
993
- " /gsd discuss Start guided milestone/slice discussion",
994
- " /gsd new-milestone Create milestone from headless context (used by gsd headless)",
995
- "",
996
- "VISIBILITY",
997
- " /gsd status Show progress dashboard (Ctrl+Alt+G)",
998
- " /gsd visualize Interactive 10-tab TUI (progress, timeline, deps, metrics, health, agent, changes, knowledge, captures, export)",
999
- " /gsd queue Show queued/dispatched units and execution order",
1000
- " /gsd history View execution history [--cost] [--phase] [--model] [N]",
1001
- " /gsd changelog Show categorized release notes [version]",
1002
- "",
1003
- "COURSE CORRECTION",
1004
- " /gsd steer <desc> Apply user override to active work",
1005
- " /gsd capture <text> Quick-capture a thought to CAPTURES.md",
1006
- " /gsd triage Classify and route pending captures",
1007
- " /gsd skip <unit> Prevent a unit from auto-mode dispatch",
1008
- " /gsd undo Revert last completed unit [--force]",
1009
- " /gsd park [id] Park a milestone — skip without deleting [reason]",
1010
- " /gsd unpark [id] Reactivate a parked milestone",
1011
- "",
1012
- "PROJECT KNOWLEDGE",
1013
- " /gsd knowledge <type> <text> Add rule, pattern, or lesson to KNOWLEDGE.md",
1014
- "",
1015
- "SETUP & CONFIGURATION",
1016
- " /gsd init Project init wizard — detect, configure, bootstrap .gsd/",
1017
- " /gsd setup Global setup status [llm|search|remote|keys|prefs]",
1018
- " /gsd mode Set workflow mode (solo/team) [global|project]",
1019
- " /gsd prefs Manage preferences [global|project|status|wizard|setup|import-claude]",
1020
- " /gsd cmux Manage cmux integration [status|on|off|notifications|sidebar|splits|browser]",
1021
- " /gsd config Set API keys for external tools",
1022
- " /gsd keys API key manager [list|add|remove|test|rotate|doctor]",
1023
- " /gsd hooks Show post-unit hook configuration",
1024
- " /gsd extensions Manage extensions [list|enable|disable|info]",
1025
- "",
1026
- "MAINTENANCE",
1027
- " /gsd doctor Diagnose and repair .gsd/ state [audit|fix|heal] [scope]",
1028
- " /gsd export Export milestone/slice results [--json|--markdown|--html] [--all]",
1029
- " /gsd cleanup Remove merged branches or snapshots [branches|snapshots]",
1030
- " /gsd migrate Migrate .planning/ (v1) to .gsd/ (v2) format",
1031
- " /gsd remote Control remote auto-mode [slack|discord|status|disconnect]",
1032
- " /gsd inspect Show SQLite DB diagnostics (schema, row counts, recent entries)",
1033
- " /gsd update Update GSD to the latest version via npm",
1034
- ];
1035
- ctx.ui.notify(lines.join("\n"), "info");
1036
- }
1037
- async function handleStatus(ctx) {
1038
- const basePath = projectRoot();
1039
- const state = await deriveState(basePath);
1040
- if (state.registry.length === 0) {
1041
- ctx.ui.notify("No GSD milestones found. Run /gsd to start.", "info");
1042
- return;
1043
- }
1044
- const result = await ctx.ui.custom((tui, theme, _kb, done) => {
1045
- return new GSDDashboardOverlay(tui, theme, () => done());
1046
- }, {
1047
- overlay: true,
1048
- overlayOptions: {
1049
- width: "70%",
1050
- minWidth: 60,
1051
- maxHeight: "90%",
1052
- anchor: "center",
1053
- },
1054
- });
1055
- // Fallback for RPC mode where ctx.ui.custom() returns undefined.
1056
- // Produce a text-based status summary so the turn is not empty.
1057
- if (result === undefined) {
1058
- ctx.ui.notify(formatTextStatus(state), "info");
1059
- }
1060
- }
1061
- export async function fireStatusViaCommand(ctx) {
1062
- await handleStatus(ctx);
1063
- }
1064
- async function handleVisualize(ctx) {
1065
- if (!ctx.hasUI) {
1066
- ctx.ui.notify("Visualizer requires an interactive terminal.", "warning");
1067
- return;
1068
- }
1069
- const result = await ctx.ui.custom((tui, theme, _kb, done) => {
1070
- return new GSDVisualizerOverlay(tui, theme, () => done());
1071
- }, {
1072
- overlay: true,
1073
- overlayOptions: {
1074
- width: "80%",
1075
- minWidth: 80,
1076
- maxHeight: "90%",
1077
- anchor: "center",
1078
- },
1079
- });
1080
- // Fallback for RPC mode where ctx.ui.custom() returns undefined.
1081
- if (result === undefined) {
1082
- ctx.ui.notify("Visualizer requires an interactive terminal. Use /gsd status for a text-based overview.", "warning");
1083
- }
1084
- }
1085
- async function handleSetup(args, ctx) {
1086
- const { detectProjectState, hasGlobalSetup } = await import("./detection.js");
1087
- // Show current global setup status
1088
- const globalConfigured = hasGlobalSetup();
1089
- const detection = detectProjectState(projectRoot());
1090
- const statusLines = ["GSD Setup Status\n"];
1091
- statusLines.push(` Global preferences: ${globalConfigured ? "configured" : "not set"}`);
1092
- statusLines.push(` Project state: ${detection.state}`);
1093
- if (detection.projectSignals.primaryLanguage) {
1094
- statusLines.push(` Detected: ${detection.projectSignals.primaryLanguage}`);
1095
- }
1096
- if (args === "llm" || args === "auth") {
1097
- ctx.ui.notify("Use /login to configure LLM authentication.", "info");
1098
- return;
1099
- }
1100
- if (args === "search") {
1101
- ctx.ui.notify("Use /search-provider to configure web search.", "info");
1102
- return;
1103
- }
1104
- if (args === "remote") {
1105
- ctx.ui.notify("Use /gsd remote to configure remote questions.", "info");
1106
- return;
1107
- }
1108
- if (args === "keys") {
1109
- const { handleKeys } = await import("./key-manager.js");
1110
- await handleKeys("", ctx);
1111
- return;
1112
- }
1113
- if (args === "prefs") {
1114
- await ensurePreferencesFile(getGlobalGSDPreferencesPath(), ctx, "global");
1115
- await handlePrefsWizard(ctx, "global");
1116
- return;
1117
- }
1118
- // Full setup summary
1119
- ctx.ui.notify(statusLines.join("\n"), "info");
1120
- ctx.ui.notify("Available setup commands:\n" +
1121
- " /gsd setup llm — LLM authentication\n" +
1122
- " /gsd setup search — Web search provider\n" +
1123
- " /gsd setup remote — Remote questions (Discord/Slack/Telegram)\n" +
1124
- " /gsd setup keys — Tool API keys\n" +
1125
- " /gsd setup prefs — Global preferences wizard", "info");
1126
- }
1127
- // ─── Text-based status for RPC mode ────────────────────────────────────────
1128
- /**
1129
- * Generate a text-based status summary for non-TUI environments (RPC mode).
1130
- * Used as a fallback when the interactive dashboard overlay is unavailable.
1131
- */
1132
- function formatTextStatus(state) {
1133
- const lines = ["GSD Status\n"];
1134
- // Progress score — traffic light (#1221)
1135
- const progressScore = computeProgressScore();
1136
- lines.push(formatProgressLine(progressScore));
1137
- lines.push("");
1138
- // Phase
1139
- lines.push(`Phase: ${state.phase}`);
1140
- // Active milestone
1141
- if (state.activeMilestone) {
1142
- lines.push(`Active milestone: ${state.activeMilestone.id} — ${state.activeMilestone.title}`);
1143
- }
1144
- // Active slice / task
1145
- if (state.activeSlice) {
1146
- lines.push(`Active slice: ${state.activeSlice.id} — ${state.activeSlice.title}`);
1147
- }
1148
- if (state.activeTask) {
1149
- lines.push(`Active task: ${state.activeTask.id} — ${state.activeTask.title}`);
1150
- }
1151
- // Progress
1152
- if (state.progress) {
1153
- const { milestones, slices, tasks } = state.progress;
1154
- const parts = [];
1155
- parts.push(`milestones ${milestones.done}/${milestones.total}`);
1156
- if (slices)
1157
- parts.push(`slices ${slices.done}/${slices.total}`);
1158
- if (tasks)
1159
- parts.push(`tasks ${tasks.done}/${tasks.total}`);
1160
- lines.push(`Progress: ${parts.join(", ")}`);
1161
- }
1162
- // Next action
1163
- if (state.nextAction) {
1164
- lines.push(`Next: ${state.nextAction}`);
1165
- }
1166
- // Blockers
1167
- if (state.blockers.length > 0) {
1168
- lines.push(`Blockers: ${state.blockers.join("; ")}`);
1169
- }
1170
- // Milestone registry summary
1171
- if (state.registry.length > 0) {
1172
- lines.push("");
1173
- lines.push("Milestones:");
1174
- for (const m of state.registry) {
1175
- const statusIcon = m.status === "complete" ? "✓" : m.status === "active" ? "▶" : m.status === "parked" ? "⏸" : "○";
1176
- lines.push(` ${statusIcon} ${m.id}: ${m.title} (${m.status})`);
1177
- }
1178
- }
1179
- // Environment health (#1221)
1180
- const envResults = runEnvironmentChecks(projectRoot());
1181
- const envIssues = envResults.filter(r => r.status !== "ok");
1182
- if (envIssues.length > 0) {
1183
- lines.push("");
1184
- lines.push("Environment:");
1185
- for (const r of envIssues) {
1186
- const icon = r.status === "error" ? "✗" : "⚠";
1187
- lines.push(` ${icon} ${r.message}`);
1188
- }
1189
- }
1190
- return lines.join("\n");
1
+ export { registerGSDCommand } from "./commands/index.js";
2
+ export async function handleGSDCommand(...args) {
3
+ const { handleGSDCommand: dispatch } = await import("./commands/dispatcher.js");
4
+ return dispatch(...args);
5
+ }
6
+ export async function fireStatusViaCommand(...args) {
7
+ const { fireStatusViaCommand: fireStatus } = await import("./commands/handlers/core.js");
8
+ return fireStatus(...args);
1191
9
  }