gsd-pi 2.38.0-dev.bc2e21e → 2.38.0-dev.d533afb

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 (99) hide show
  1. package/dist/resource-loader.js +34 -1
  2. package/dist/resources/extensions/github-sync/cli.js +284 -0
  3. package/dist/resources/extensions/github-sync/index.js +73 -0
  4. package/dist/resources/extensions/github-sync/mapping.js +67 -0
  5. package/dist/resources/extensions/github-sync/sync.js +424 -0
  6. package/dist/resources/extensions/github-sync/templates.js +118 -0
  7. package/dist/resources/extensions/github-sync/types.js +7 -0
  8. package/dist/resources/extensions/gsd/auto/session.js +3 -23
  9. package/dist/resources/extensions/gsd/auto-dispatch.js +1 -1
  10. package/dist/resources/extensions/gsd/auto-loop.js +292 -263
  11. package/dist/resources/extensions/gsd/auto-post-unit.js +28 -3
  12. package/dist/resources/extensions/gsd/auto-prompts.js +23 -43
  13. package/dist/resources/extensions/gsd/auto-start.js +7 -1
  14. package/dist/resources/extensions/gsd/auto-worktree.js +3 -3
  15. package/dist/resources/extensions/gsd/auto.js +143 -80
  16. package/dist/resources/extensions/gsd/commands-prefs-wizard.js +1 -1
  17. package/dist/resources/extensions/gsd/commands.js +2 -1
  18. package/dist/resources/extensions/gsd/context-budget.js +2 -10
  19. package/dist/resources/extensions/gsd/docs/preferences-reference.md +0 -2
  20. package/dist/resources/extensions/gsd/doctor-providers.js +27 -11
  21. package/dist/resources/extensions/gsd/doctor.js +20 -1
  22. package/dist/resources/extensions/gsd/exit-command.js +2 -1
  23. package/dist/resources/extensions/gsd/files.js +4 -0
  24. package/dist/resources/extensions/gsd/git-service.js +15 -12
  25. package/dist/resources/extensions/gsd/guided-flow.js +82 -32
  26. package/dist/resources/extensions/gsd/index.js +22 -19
  27. package/dist/resources/extensions/gsd/native-git-bridge.js +37 -0
  28. package/dist/resources/extensions/gsd/preferences-models.js +0 -12
  29. package/dist/resources/extensions/gsd/preferences-types.js +1 -1
  30. package/dist/resources/extensions/gsd/preferences-validation.js +58 -10
  31. package/dist/resources/extensions/gsd/preferences.js +4 -2
  32. package/dist/resources/extensions/gsd/prompts/run-uat.md +2 -0
  33. package/dist/resources/extensions/gsd/repo-identity.js +19 -3
  34. package/dist/resources/extensions/gsd/roadmap-mutations.js +24 -0
  35. package/dist/resources/extensions/mcp-client/index.js +14 -1
  36. package/package.json +1 -1
  37. package/packages/pi-ai/dist/utils/oauth/anthropic.js +2 -2
  38. package/packages/pi-ai/dist/utils/oauth/anthropic.js.map +1 -1
  39. package/packages/pi-ai/src/utils/oauth/anthropic.ts +2 -2
  40. package/packages/pi-coding-agent/dist/core/extensions/loader.d.ts.map +1 -1
  41. package/packages/pi-coding-agent/dist/core/extensions/loader.js +205 -7
  42. package/packages/pi-coding-agent/dist/core/extensions/loader.js.map +1 -1
  43. package/packages/pi-coding-agent/src/core/extensions/loader.ts +223 -7
  44. package/src/resources/extensions/github-sync/cli.ts +364 -0
  45. package/src/resources/extensions/github-sync/index.ts +93 -0
  46. package/src/resources/extensions/github-sync/mapping.ts +81 -0
  47. package/src/resources/extensions/github-sync/sync.ts +556 -0
  48. package/src/resources/extensions/github-sync/templates.ts +183 -0
  49. package/src/resources/extensions/github-sync/tests/cli.test.ts +20 -0
  50. package/src/resources/extensions/github-sync/tests/commit-linking.test.ts +39 -0
  51. package/src/resources/extensions/github-sync/tests/mapping.test.ts +104 -0
  52. package/src/resources/extensions/github-sync/tests/templates.test.ts +110 -0
  53. package/src/resources/extensions/github-sync/types.ts +47 -0
  54. package/src/resources/extensions/gsd/auto/session.ts +3 -25
  55. package/src/resources/extensions/gsd/auto-dispatch.ts +1 -1
  56. package/src/resources/extensions/gsd/auto-loop.ts +382 -360
  57. package/src/resources/extensions/gsd/auto-post-unit.ts +29 -3
  58. package/src/resources/extensions/gsd/auto-prompts.ts +25 -45
  59. package/src/resources/extensions/gsd/auto-start.ts +11 -1
  60. package/src/resources/extensions/gsd/auto-worktree.ts +3 -3
  61. package/src/resources/extensions/gsd/auto.ts +139 -86
  62. package/src/resources/extensions/gsd/commands-prefs-wizard.ts +1 -1
  63. package/src/resources/extensions/gsd/commands.ts +2 -2
  64. package/src/resources/extensions/gsd/context-budget.ts +2 -12
  65. package/src/resources/extensions/gsd/docs/preferences-reference.md +0 -2
  66. package/src/resources/extensions/gsd/doctor-providers.ts +26 -9
  67. package/src/resources/extensions/gsd/doctor.ts +22 -1
  68. package/src/resources/extensions/gsd/exit-command.ts +2 -2
  69. package/src/resources/extensions/gsd/files.ts +3 -1
  70. package/src/resources/extensions/gsd/git-service.ts +20 -10
  71. package/src/resources/extensions/gsd/guided-flow.ts +110 -38
  72. package/src/resources/extensions/gsd/index.ts +21 -16
  73. package/src/resources/extensions/gsd/native-git-bridge.ts +37 -0
  74. package/src/resources/extensions/gsd/preferences-models.ts +0 -12
  75. package/src/resources/extensions/gsd/preferences-types.ts +4 -4
  76. package/src/resources/extensions/gsd/preferences-validation.ts +50 -10
  77. package/src/resources/extensions/gsd/preferences.ts +3 -2
  78. package/src/resources/extensions/gsd/prompts/run-uat.md +2 -0
  79. package/src/resources/extensions/gsd/repo-identity.ts +20 -3
  80. package/src/resources/extensions/gsd/roadmap-mutations.ts +29 -0
  81. package/src/resources/extensions/gsd/tests/agent-end-retry.test.ts +21 -18
  82. package/src/resources/extensions/gsd/tests/auto-loop.test.ts +122 -68
  83. package/src/resources/extensions/gsd/tests/doctor-providers.test.ts +86 -3
  84. package/src/resources/extensions/gsd/tests/preferences.test.ts +2 -7
  85. package/src/resources/extensions/gsd/tests/repo-identity-worktree.test.ts +21 -1
  86. package/src/resources/extensions/gsd/types.ts +0 -1
  87. package/src/resources/extensions/mcp-client/index.ts +17 -1
  88. package/dist/resources/extensions/gsd/prompt-compressor.js +0 -393
  89. package/dist/resources/extensions/gsd/semantic-chunker.js +0 -254
  90. package/dist/resources/extensions/gsd/summary-distiller.js +0 -212
  91. package/src/resources/extensions/gsd/prompt-compressor.ts +0 -508
  92. package/src/resources/extensions/gsd/semantic-chunker.ts +0 -336
  93. package/src/resources/extensions/gsd/summary-distiller.ts +0 -258
  94. package/src/resources/extensions/gsd/tests/context-compression.test.ts +0 -193
  95. package/src/resources/extensions/gsd/tests/prompt-compressor.test.ts +0 -529
  96. package/src/resources/extensions/gsd/tests/semantic-chunker.test.ts +0 -426
  97. package/src/resources/extensions/gsd/tests/summary-distiller.test.ts +0 -323
  98. package/src/resources/extensions/gsd/tests/token-optimization-benchmark.test.ts +0 -1272
  99. package/src/resources/extensions/gsd/tests/token-optimization-prefs.test.ts +0 -164
@@ -28,10 +28,12 @@ function modelToProviderId(model) {
28
28
  const prefix = model.split("/")[0].toLowerCase();
29
29
  // Map known prefixes to registry IDs
30
30
  const prefixMap = {
31
+ "anthropic-vertex": "anthropic-vertex",
31
32
  openrouter: "openrouter",
32
33
  groq: "groq",
33
34
  mistral: "mistral",
34
35
  google: "google",
36
+ "google-vertex": "google-vertex",
35
37
  anthropic: "anthropic",
36
38
  openai: "openai",
37
39
  "github-copilot": "github-copilot",
@@ -67,11 +69,19 @@ function collectConfiguredModelProviders() {
67
69
  }
68
70
  const modelEntries = typeof models === "object" ? Object.values(models) : [];
69
71
  for (const entry of modelEntries) {
70
- const modelId = typeof entry === "string" ? entry
71
- : typeof entry === "object" && entry !== null && "model" in entry
72
- ? String(entry.model)
73
- : null;
74
- if (modelId) {
72
+ if (typeof entry === "string") {
73
+ const pid = modelToProviderId(entry);
74
+ if (pid)
75
+ providers.add(pid);
76
+ continue;
77
+ }
78
+ if (typeof entry === "object" && entry !== null && "model" in entry) {
79
+ const configuredProvider = "provider" in entry ? entry.provider : undefined;
80
+ if (typeof configuredProvider === "string" && configuredProvider.trim().length > 0) {
81
+ providers.add(configuredProvider);
82
+ continue;
83
+ }
84
+ const modelId = String(entry.model);
75
85
  const pid = modelToProviderId(modelId);
76
86
  if (pid)
77
87
  providers.add(pid);
@@ -138,7 +148,9 @@ function checkLlmProviders() {
138
148
  const results = [];
139
149
  for (const providerId of required) {
140
150
  const info = PROVIDER_REGISTRY.find(p => p.id === providerId);
141
- const label = info?.label ?? providerId;
151
+ const label = providerId === "anthropic-vertex"
152
+ ? "Anthropic Vertex"
153
+ : info?.label ?? providerId;
142
154
  const lookup = resolveKey(providerId);
143
155
  if (!lookup.found) {
144
156
  // Check if a cross-provider can serve this provider's models
@@ -157,16 +169,20 @@ function checkLlmProviders() {
157
169
  });
158
170
  continue;
159
171
  }
160
- const envVar = info?.envVar ?? `${providerId.toUpperCase()}_API_KEY`;
172
+ const envVar = providerId === "anthropic-vertex"
173
+ ? "ANTHROPIC_VERTEX_PROJECT_ID"
174
+ : info?.envVar ?? `${providerId.toUpperCase()}_API_KEY`;
161
175
  results.push({
162
176
  name: providerId,
163
177
  label,
164
178
  category: "llm",
165
179
  status: "error",
166
- message: `${label} — no API key found`,
167
- detail: info?.hasOAuth
168
- ? `Run /gsd keys to authenticate`
169
- : `Set ${envVar} or run /gsd keys`,
180
+ message: `${label} — not configured`,
181
+ detail: providerId === "anthropic-vertex"
182
+ ? "Set ANTHROPIC_VERTEX_PROJECT_ID and authenticate with Google ADC"
183
+ : info?.hasOAuth
184
+ ? `Run /gsd keys to authenticate`
185
+ : `Set ${envVar} or run /gsd keys`,
170
186
  required: true,
171
187
  });
172
188
  }
@@ -257,10 +257,23 @@ async function markSliceDoneInRoadmap(basePath, milestoneId, sliceId, fixesAppli
257
257
  fixesApplied.push(`marked ${sliceId} done in ${roadmapPath}`);
258
258
  }
259
259
  }
260
+ async function markSliceUndoneInRoadmap(basePath, milestoneId, sliceId, fixesApplied) {
261
+ const roadmapPath = resolveMilestoneFile(basePath, milestoneId, "ROADMAP");
262
+ if (!roadmapPath)
263
+ return;
264
+ const content = await loadFile(roadmapPath);
265
+ if (!content)
266
+ return;
267
+ const updated = content.replace(new RegExp(`^(\\s*-\\s+)\\[x\\]\\s+\\*\\*${sliceId}:`, "m"), `$1[ ] **${sliceId}:`);
268
+ if (updated !== content) {
269
+ await saveFile(roadmapPath, updated);
270
+ fixesApplied.push(`unmarked ${sliceId} in ${roadmapPath} (premature completion)`);
271
+ }
272
+ }
260
273
  function matchesScope(unitId, scope) {
261
274
  if (!scope)
262
275
  return true;
263
- return unitId === scope || unitId.startsWith(`${scope}/`) || unitId.startsWith(`${scope}`);
276
+ return unitId === scope || unitId.startsWith(`${scope}/`);
264
277
  }
265
278
  function auditRequirements(content) {
266
279
  if (!content)
@@ -828,6 +841,12 @@ export async function runGSDDoctor(basePath, options) {
828
841
  file: relSliceFile(basePath, milestoneId, slice.id, "SUMMARY"),
829
842
  fixable: true,
830
843
  });
844
+ if (!allTasksDone) {
845
+ dryRunCanFix("slice_checked_missing_summary", `uncheck ${slice.id} in roadmap (tasks incomplete)`);
846
+ if (shouldFix("slice_checked_missing_summary")) {
847
+ await markSliceUndoneInRoadmap(basePath, milestoneId, slice.id, fixesApplied);
848
+ }
849
+ }
831
850
  }
832
851
  if (slice.done && !hasSliceUat) {
833
852
  issues.push({
@@ -1,9 +1,10 @@
1
+ import { importExtensionModule } from "@gsd/pi-coding-agent";
1
2
  export function registerExitCommand(pi, deps = {}) {
2
3
  pi.registerCommand("exit", {
3
4
  description: "Exit GSD gracefully",
4
5
  handler: async (_args, ctx) => {
5
6
  // Stop auto-mode first so locks and activity state are cleaned up before shutdown.
6
- const stopAuto = deps.stopAuto ?? (await import("./auto.js")).stopAuto;
7
+ const stopAuto = deps.stopAuto ?? (await importExtensionModule(import.meta.url, "./auto.js")).stopAuto;
7
8
  await stopAuto(ctx, pi, "Graceful exit");
8
9
  ctx.shutdown();
9
10
  },
@@ -692,6 +692,10 @@ export function extractUatType(content) {
692
692
  const rawValue = modeBullet.slice('UAT mode:'.length).trim().toLowerCase();
693
693
  if (rawValue.startsWith('artifact-driven'))
694
694
  return 'artifact-driven';
695
+ if (rawValue.startsWith('browser-executable'))
696
+ return 'browser-executable';
697
+ if (rawValue.startsWith('runtime-executable'))
698
+ return 'runtime-executable';
695
699
  if (rawValue.startsWith('live-runtime'))
696
700
  return 'live-runtime';
697
701
  if (rawValue.startsWith('human-experience'))
@@ -14,7 +14,7 @@ import { gsdRoot } from "./paths.js";
14
14
  import { GIT_NO_PROMPT_ENV } from "./git-constants.js";
15
15
  import { loadEffectiveGSDPreferences } from "./preferences.js";
16
16
  import { detectWorktreeName, SLICE_BRANCH_RE, } from "./worktree.js";
17
- import { nativeGetCurrentBranch, nativeDetectMainBranch, nativeBranchExists, nativeHasChanges, nativeAddAll, nativeResetPaths, nativeHasStagedChanges, nativeCommit, nativeRmCached, nativeUpdateRef, } from "./native-git-bridge.js";
17
+ import { nativeGetCurrentBranch, nativeDetectMainBranch, nativeBranchExists, nativeHasChanges, nativeAddAllWithExclusions, nativeHasStagedChanges, nativeCommit, nativeRmCached, nativeUpdateRef, } from "./native-git-bridge.js";
18
18
  import { GSDError, GSD_MERGE_CONFLICT, GSD_GIT_ERROR } from "./errors.js";
19
19
  import { getErrorMessage } from "./error-utils.js";
20
20
  export const VALID_BRANCH_NAME = /^[a-zA-Z0-9_\-\/.]+$/;
@@ -36,12 +36,19 @@ export function buildTaskCommitMessage(ctx) {
36
36
  : description;
37
37
  const subject = `${type}(${scope}): ${truncated}`;
38
38
  // Build body with key files if available
39
+ const bodyParts = [];
39
40
  if (ctx.keyFiles && ctx.keyFiles.length > 0) {
40
41
  const fileLines = ctx.keyFiles
41
42
  .slice(0, 8) // cap at 8 files to keep commit concise
42
43
  .map(f => `- ${f}`)
43
44
  .join("\n");
44
- return `${subject}\n\n${fileLines}`;
45
+ bodyParts.push(fileLines);
46
+ }
47
+ if (ctx.issueNumber) {
48
+ bodyParts.push(`Resolves #${ctx.issueNumber}`);
49
+ }
50
+ if (bodyParts.length > 0) {
51
+ return `${subject}\n\n${bodyParts.join("\n\n")}`;
45
52
  }
46
53
  return subject;
47
54
  }
@@ -254,7 +261,9 @@ export class GitServiceImpl {
254
261
  }
255
262
  this._runtimeFilesCleanedUp = true;
256
263
  }
257
- // Stage everything, then unstage excluded paths.
264
+ // Stage everything using pathspec exclusions so excluded paths are never
265
+ // hashed by git. The old approach of `git add -A` followed by unstaging
266
+ // hangs indefinitely on repos with large untracked artifact trees (#1605).
258
267
  //
259
268
  // Exclude only RUNTIME paths from staging — not the entire .gsd/ directory.
260
269
  // When .gsd/milestones/ files are already tracked in the index (projects
@@ -264,15 +273,9 @@ export class GitServiceImpl {
264
273
  // the second half of a milestone's artifacts are never committed (#1326).
265
274
  //
266
275
  // If .gsd/ IS in .gitignore (the default for external state projects),
267
- // git add -A already skips it and the reset is a harmless no-op.
268
- nativeAddAll(this.basePath);
269
- const runtimeExclusions = [...RUNTIME_EXCLUSION_PATHS, ...extraExclusions];
270
- for (const exclusion of runtimeExclusions) {
271
- try {
272
- nativeResetPaths(this.basePath, [exclusion]);
273
- }
274
- catch { /* path not staged — ignore */ }
275
- }
276
+ // git add -A already skips it and the exclusions are harmless no-ops.
277
+ const allExclusions = [...RUNTIME_EXCLUSION_PATHS, ...extraExclusions];
278
+ nativeAddAllWithExclusions(this.basePath, allExclusions);
276
279
  }
277
280
  /** Tracks whether runtime file cleanup has run this session. */
278
281
  _runtimeFilesCleanedUp = false;
@@ -28,6 +28,7 @@ import { showConfirm } from "../shared/mod.js";
28
28
  import { debugLog } from "./debug-logger.js";
29
29
  import { findMilestoneIds, nextMilestoneId } from "./milestone-ids.js";
30
30
  import { parkMilestone, discardMilestone } from "./milestone-actions.js";
31
+ import { resolveModelWithFallbacksForUnit } from "./preferences-models.js";
31
32
  // ─── Re-exports (preserve public API for existing importers) ────────────────
32
33
  export { MILESTONE_ID_RE, generateMilestoneSuffix, nextMilestoneId, extractMilestoneSeq, parseMilestoneId, milestoneIdSort, maxMilestoneNum, findMilestoneIds, } from "./milestone-ids.js";
33
34
  export { showQueue, handleQueueReorder, showQueueAdd, buildExistingMilestonesContext, } from "./guided-flow-queue.js";
@@ -153,8 +154,32 @@ function parseMilestoneSequenceFromProject(content) {
153
154
  /**
154
155
  * Read GSD-WORKFLOW.md and dispatch it to the LLM with a contextual note.
155
156
  * This is the only way the wizard triggers work — everything else is the LLM's job.
157
+ *
158
+ * When a unitType is provided, resolves the user's model preference for that
159
+ * phase (e.g., models.planning → "plan-milestone") and applies it before
160
+ * dispatching. This ensures guided-flow dispatches respect the same
161
+ * per-phase model preferences that auto-mode uses.
156
162
  */
157
- function dispatchWorkflow(pi, note, customType = "gsd-run") {
163
+ async function dispatchWorkflow(pi, note, customType = "gsd-run", ctx, unitType) {
164
+ // Apply model preference for this unit type (if configured)
165
+ if (ctx && unitType) {
166
+ const modelConfig = resolveModelWithFallbacksForUnit(unitType);
167
+ if (modelConfig) {
168
+ const availableModels = ctx.modelRegistry.getAvailable();
169
+ const modelsToTry = [modelConfig.primary, ...modelConfig.fallbacks];
170
+ for (const modelId of modelsToTry) {
171
+ // Resolve model from available models (same logic as auto-model-selection)
172
+ const model = resolveAvailableModel(modelId, availableModels, ctx.model?.provider);
173
+ if (!model)
174
+ continue;
175
+ const ok = await pi.setModel(model, { persist: false });
176
+ if (ok) {
177
+ debugLog("guided-flow-model-applied", { unitType, model: `${model.provider}/${model.id}` });
178
+ break;
179
+ }
180
+ }
181
+ }
182
+ }
158
183
  const workflowPath = process.env.GSD_WORKFLOW_PATH ?? join(process.env.HOME ?? "~", ".gsd", "agent", "GSD-WORKFLOW.md");
159
184
  const workflow = readFileSync(workflowPath, "utf-8");
160
185
  pi.sendMessage({
@@ -163,6 +188,31 @@ function dispatchWorkflow(pi, note, customType = "gsd-run") {
163
188
  display: false,
164
189
  }, { triggerTurn: true });
165
190
  }
191
+ /**
192
+ * Resolve a model ID string to a model object from available models.
193
+ * Handles "provider/model" and bare ID formats.
194
+ */
195
+ function resolveAvailableModel(modelId, availableModels, currentProvider) {
196
+ const slashIdx = modelId.indexOf("/");
197
+ if (slashIdx !== -1) {
198
+ const maybeProvider = modelId.substring(0, slashIdx);
199
+ const id = modelId.substring(slashIdx + 1);
200
+ const knownProviders = new Set(availableModels.map(m => m.provider.toLowerCase()));
201
+ if (knownProviders.has(maybeProvider.toLowerCase())) {
202
+ const match = availableModels.find(m => m.provider.toLowerCase() === maybeProvider.toLowerCase()
203
+ && m.id.toLowerCase() === id.toLowerCase());
204
+ if (match)
205
+ return match;
206
+ }
207
+ // Try matching the full string as a model ID (OpenRouter-style)
208
+ const lower = modelId.toLowerCase();
209
+ return availableModels.find(m => m.id.toLowerCase() === lower
210
+ || `${m.provider}/${m.id}`.toLowerCase() === lower);
211
+ }
212
+ // Bare ID — prefer current provider, then first available
213
+ const exactProviderMatch = availableModels.find(m => m.id === modelId && m.provider === currentProvider);
214
+ return exactProviderMatch ?? availableModels.find(m => m.id === modelId);
215
+ }
166
216
  /**
167
217
  * Build the discuss-and-plan prompt for a new milestone.
168
218
  * Used by all three "new milestone" paths (first ever, no active, all complete).
@@ -244,8 +294,8 @@ export async function showHeadlessMilestoneCreation(ctx, pi, basePath, seedConte
244
294
  const prompt = buildHeadlessDiscussPrompt(nextId, seedContext, basePath);
245
295
  // Set pending auto start (auto-mode triggers on "Milestone X ready." via checkAutoStartAfterDiscuss)
246
296
  pendingAutoStart = { ctx, pi, basePath, milestoneId: nextId };
247
- // Dispatch
248
- dispatchWorkflow(pi, prompt);
297
+ // Dispatch — headless milestone creation is a planning activity
298
+ await dispatchWorkflow(pi, prompt, "gsd-run", ctx, "plan-milestone");
249
299
  }
250
300
  // ─── Discuss Flow ─────────────────────────────────────────────────────────────
251
301
  /**
@@ -381,23 +431,23 @@ export async function showDiscuss(ctx, pi, basePath) {
381
431
  ? `${basePrompt}\n\n## Prior Discussion (Draft Seed)\n\n${draftContent}`
382
432
  : basePrompt;
383
433
  pendingAutoStart = { ctx, pi, basePath, milestoneId: mid, step: false };
384
- dispatchWorkflow(pi, seed, "gsd-discuss");
434
+ await dispatchWorkflow(pi, seed, "gsd-discuss", ctx, "plan-milestone");
385
435
  }
386
436
  else if (choice === "discuss_fresh") {
387
437
  const discussMilestoneTemplates = inlineTemplate("context", "Context");
388
438
  const structuredQuestionsAvailable = pi.getActiveTools().includes("ask_user_questions") ? "true" : "false";
389
439
  pendingAutoStart = { ctx, pi, basePath, milestoneId: mid, step: false };
390
- dispatchWorkflow(pi, loadPrompt("guided-discuss-milestone", {
440
+ await dispatchWorkflow(pi, loadPrompt("guided-discuss-milestone", {
391
441
  milestoneId: mid, milestoneTitle, inlinedTemplates: discussMilestoneTemplates, structuredQuestionsAvailable,
392
442
  commitInstruction: buildDocsCommitInstruction(`docs(${mid}): milestone context from discuss`),
393
- }), "gsd-discuss");
443
+ }), "gsd-discuss", ctx, "plan-milestone");
394
444
  }
395
445
  else if (choice === "skip_milestone") {
396
446
  const milestoneIds = findMilestoneIds(basePath);
397
447
  const uniqueMilestoneIds = !!loadEffectiveGSDPreferences()?.preferences?.unique_milestone_ids;
398
448
  const nextId = nextMilestoneId(milestoneIds, uniqueMilestoneIds);
399
449
  pendingAutoStart = { ctx, pi, basePath, milestoneId: nextId, step: false };
400
- dispatchWorkflow(pi, buildDiscussPrompt(nextId, `New milestone ${nextId}.`, basePath));
450
+ await dispatchWorkflow(pi, buildDiscussPrompt(nextId, `New milestone ${nextId}.`, basePath), "gsd-run", ctx, "plan-milestone");
401
451
  }
402
452
  return;
403
453
  }
@@ -484,7 +534,7 @@ export async function showDiscuss(ctx, pi, basePath) {
484
534
  continue;
485
535
  }
486
536
  const prompt = await buildDiscussSlicePrompt(mid, chosen.id, chosen.title, basePath, { rediscuss: isRediscuss });
487
- dispatchWorkflow(pi, prompt, "gsd-discuss");
537
+ await dispatchWorkflow(pi, prompt, "gsd-discuss", ctx, "plan-slice");
488
538
  // Wait for the discuss session to finish, then loop back to the picker
489
539
  await ctx.waitForIdle();
490
540
  invalidateAllCaches();
@@ -611,7 +661,7 @@ async function handleMilestoneActions(ctx, pi, basePath, milestoneId, milestoneT
611
661
  const uniqueMilestoneIds = !!loadEffectiveGSDPreferences()?.preferences?.unique_milestone_ids;
612
662
  const nextId = nextMilestoneId(milestoneIds, uniqueMilestoneIds);
613
663
  pendingAutoStart = { ctx, pi, basePath, milestoneId: nextId, step: stepMode };
614
- dispatchWorkflow(pi, buildDiscussPrompt(nextId, `New milestone ${nextId}.`, basePath));
664
+ await dispatchWorkflow(pi, buildDiscussPrompt(nextId, `New milestone ${nextId}.`, basePath), "gsd-run", ctx, "plan-milestone");
615
665
  return true;
616
666
  }
617
667
  // "back" or null
@@ -729,7 +779,7 @@ export async function showSmartEntry(ctx, pi, basePath, options) {
729
779
  if (isFirst) {
730
780
  // First ever — skip wizard, just ask directly
731
781
  pendingAutoStart = { ctx, pi, basePath, milestoneId: nextId, step: stepMode };
732
- dispatchWorkflow(pi, buildDiscussPrompt(nextId, `New project, milestone ${nextId}. Do NOT read or explore .gsd/ — it's empty scaffolding.`, basePath));
782
+ await dispatchWorkflow(pi, buildDiscussPrompt(nextId, `New project, milestone ${nextId}. Do NOT read or explore .gsd/ — it's empty scaffolding.`, basePath), "gsd-run", ctx, "plan-milestone");
733
783
  }
734
784
  else {
735
785
  const choice = await showNextAction(ctx, {
@@ -747,7 +797,7 @@ export async function showSmartEntry(ctx, pi, basePath, options) {
747
797
  });
748
798
  if (choice === "new_milestone") {
749
799
  pendingAutoStart = { ctx, pi, basePath, milestoneId: nextId, step: stepMode };
750
- dispatchWorkflow(pi, buildDiscussPrompt(nextId, `New milestone ${nextId}.`, basePath));
800
+ await dispatchWorkflow(pi, buildDiscussPrompt(nextId, `New milestone ${nextId}.`, basePath), "gsd-run", ctx, "plan-milestone");
751
801
  }
752
802
  }
753
803
  return;
@@ -779,7 +829,7 @@ export async function showSmartEntry(ctx, pi, basePath, options) {
779
829
  const uniqueMilestoneIds = !!loadEffectiveGSDPreferences()?.preferences?.unique_milestone_ids;
780
830
  const nextId = nextMilestoneId(milestoneIds, uniqueMilestoneIds);
781
831
  pendingAutoStart = { ctx, pi, basePath, milestoneId: nextId, step: stepMode };
782
- dispatchWorkflow(pi, buildDiscussPrompt(nextId, `New milestone ${nextId}.`, basePath));
832
+ await dispatchWorkflow(pi, buildDiscussPrompt(nextId, `New milestone ${nextId}.`, basePath), "gsd-run", ctx, "plan-milestone");
783
833
  }
784
834
  else if (choice === "status") {
785
835
  const { fireStatusViaCommand } = await import("./commands.js");
@@ -825,23 +875,23 @@ export async function showSmartEntry(ctx, pi, basePath, options) {
825
875
  ? `${basePrompt}\n\n## Prior Discussion (Draft Seed)\n\n${draftContent}`
826
876
  : basePrompt;
827
877
  pendingAutoStart = { ctx, pi, basePath, milestoneId, step: stepMode };
828
- dispatchWorkflow(pi, seed, "gsd-discuss");
878
+ await dispatchWorkflow(pi, seed, "gsd-discuss", ctx, "plan-milestone");
829
879
  }
830
880
  else if (choice === "discuss_fresh") {
831
881
  const discussMilestoneTemplates = inlineTemplate("context", "Context");
832
882
  const structuredQuestionsAvailable = pi.getActiveTools().includes("ask_user_questions") ? "true" : "false";
833
883
  pendingAutoStart = { ctx, pi, basePath, milestoneId, step: stepMode };
834
- dispatchWorkflow(pi, loadPrompt("guided-discuss-milestone", {
884
+ await dispatchWorkflow(pi, loadPrompt("guided-discuss-milestone", {
835
885
  milestoneId, milestoneTitle, inlinedTemplates: discussMilestoneTemplates, structuredQuestionsAvailable,
836
886
  commitInstruction: buildDocsCommitInstruction(`docs(${milestoneId}): milestone context from discuss`),
837
- }), "gsd-discuss");
887
+ }), "gsd-discuss", ctx, "plan-milestone");
838
888
  }
839
889
  else if (choice === "skip_milestone") {
840
890
  const milestoneIds = findMilestoneIds(basePath);
841
891
  const uniqueMilestoneIds = !!loadEffectiveGSDPreferences()?.preferences?.unique_milestone_ids;
842
892
  const nextId = nextMilestoneId(milestoneIds, uniqueMilestoneIds);
843
893
  pendingAutoStart = { ctx, pi, basePath, milestoneId: nextId, step: stepMode };
844
- dispatchWorkflow(pi, buildDiscussPrompt(nextId, `New milestone ${nextId}.`, basePath));
894
+ await dispatchWorkflow(pi, buildDiscussPrompt(nextId, `New milestone ${nextId}.`, basePath), "gsd-run", ctx, "plan-milestone");
845
895
  }
846
896
  return;
847
897
  }
@@ -893,24 +943,24 @@ export async function showSmartEntry(ctx, pi, basePath, options) {
893
943
  inlineTemplate("secrets-manifest", "Secrets Manifest"),
894
944
  ].join("\n\n---\n\n");
895
945
  const secretsOutputPath = relMilestoneFile(basePath, milestoneId, "SECRETS");
896
- dispatchWorkflow(pi, loadPrompt("guided-plan-milestone", {
946
+ await dispatchWorkflow(pi, loadPrompt("guided-plan-milestone", {
897
947
  milestoneId, milestoneTitle, secretsOutputPath, inlinedTemplates: planMilestoneTemplates,
898
- }));
948
+ }), "gsd-run", ctx, "plan-milestone");
899
949
  }
900
950
  else if (choice === "discuss") {
901
951
  const discussMilestoneTemplates = inlineTemplate("context", "Context");
902
952
  const structuredQuestionsAvailable = pi.getActiveTools().includes("ask_user_questions") ? "true" : "false";
903
- dispatchWorkflow(pi, loadPrompt("guided-discuss-milestone", {
953
+ await dispatchWorkflow(pi, loadPrompt("guided-discuss-milestone", {
904
954
  milestoneId, milestoneTitle, inlinedTemplates: discussMilestoneTemplates, structuredQuestionsAvailable,
905
955
  commitInstruction: buildDocsCommitInstruction(`docs(${milestoneId}): milestone context from discuss`),
906
- }));
956
+ }), "gsd-run", ctx, "plan-milestone");
907
957
  }
908
958
  else if (choice === "skip_milestone") {
909
959
  const milestoneIds = findMilestoneIds(basePath);
910
960
  const uniqueMilestoneIds = !!loadEffectiveGSDPreferences()?.preferences?.unique_milestone_ids;
911
961
  const nextId = nextMilestoneId(milestoneIds, uniqueMilestoneIds);
912
962
  pendingAutoStart = { ctx, pi, basePath, milestoneId: nextId, step: stepMode };
913
- dispatchWorkflow(pi, buildDiscussPrompt(nextId, `New milestone ${nextId}.`, basePath));
963
+ await dispatchWorkflow(pi, buildDiscussPrompt(nextId, `New milestone ${nextId}.`, basePath), "gsd-run", ctx, "plan-milestone");
914
964
  }
915
965
  else if (choice === "discard_milestone") {
916
966
  const confirmed = await showConfirm(ctx, {
@@ -1021,18 +1071,18 @@ export async function showSmartEntry(ctx, pi, basePath, options) {
1021
1071
  inlineTemplate("plan", "Slice Plan"),
1022
1072
  inlineTemplate("task-plan", "Task Plan"),
1023
1073
  ].join("\n\n---\n\n");
1024
- dispatchWorkflow(pi, loadPrompt("guided-plan-slice", {
1074
+ await dispatchWorkflow(pi, loadPrompt("guided-plan-slice", {
1025
1075
  milestoneId, sliceId, sliceTitle, inlinedTemplates: planSliceTemplates,
1026
- }));
1076
+ }), "gsd-run", ctx, "plan-slice");
1027
1077
  }
1028
1078
  else if (choice === "discuss") {
1029
- dispatchWorkflow(pi, await buildDiscussSlicePrompt(milestoneId, sliceId, sliceTitle, basePath, { rediscuss: hasContext }));
1079
+ await dispatchWorkflow(pi, await buildDiscussSlicePrompt(milestoneId, sliceId, sliceTitle, basePath, { rediscuss: hasContext }), "gsd-run", ctx, "plan-slice");
1030
1080
  }
1031
1081
  else if (choice === "research") {
1032
1082
  const researchTemplates = inlineTemplate("research", "Research");
1033
- dispatchWorkflow(pi, loadPrompt("guided-research-slice", {
1083
+ await dispatchWorkflow(pi, loadPrompt("guided-research-slice", {
1034
1084
  milestoneId, sliceId, sliceTitle, inlinedTemplates: researchTemplates,
1035
- }));
1085
+ }), "gsd-run", ctx, "research-slice");
1036
1086
  }
1037
1087
  else if (choice === "status") {
1038
1088
  const { fireStatusViaCommand } = await import("./commands.js");
@@ -1075,9 +1125,9 @@ export async function showSmartEntry(ctx, pi, basePath, options) {
1075
1125
  inlineTemplate("slice-summary", "Slice Summary"),
1076
1126
  inlineTemplate("uat", "UAT"),
1077
1127
  ].join("\n\n---\n\n");
1078
- dispatchWorkflow(pi, loadPrompt("guided-complete-slice", {
1128
+ await dispatchWorkflow(pi, loadPrompt("guided-complete-slice", {
1079
1129
  workingDirectory: basePath, milestoneId, sliceId, sliceTitle, inlinedTemplates: completeSliceTemplates,
1080
- }));
1130
+ }), "gsd-run", ctx, "complete-slice");
1081
1131
  }
1082
1132
  else if (choice === "status") {
1083
1133
  const { fireStatusViaCommand } = await import("./commands.js");
@@ -1138,15 +1188,15 @@ export async function showSmartEntry(ctx, pi, basePath, options) {
1138
1188
  }
1139
1189
  if (choice === "execute") {
1140
1190
  if (hasInterrupted) {
1141
- dispatchWorkflow(pi, loadPrompt("guided-resume-task", {
1191
+ await dispatchWorkflow(pi, loadPrompt("guided-resume-task", {
1142
1192
  milestoneId, sliceId,
1143
- }));
1193
+ }), "gsd-run", ctx, "execute-task");
1144
1194
  }
1145
1195
  else {
1146
1196
  const executeTaskTemplates = inlineTemplate("task-summary", "Task Summary");
1147
- dispatchWorkflow(pi, loadPrompt("guided-execute-task", {
1197
+ await dispatchWorkflow(pi, loadPrompt("guided-execute-task", {
1148
1198
  milestoneId, sliceId, taskId, taskTitle, inlinedTemplates: executeTaskTemplates,
1149
- }));
1199
+ }), "gsd-run", ctx, "execute-task");
1150
1200
  }
1151
1201
  }
1152
1202
  else if (choice === "status") {
@@ -66,6 +66,24 @@ function warnDeprecatedAgentInstructions() {
66
66
  }
67
67
  // ── Depth verification state ──────────────────────────────────────────────
68
68
  let depthVerificationDone = false;
69
+ // ── DB lazy-open helper ───────────────────────────────────────────────────
70
+ // In manual sessions (no auto-mode), the DB is never opened by bootstrapAutoSession.
71
+ // This helper ensures the DB is lazily opened on first tool call that needs it.
72
+ async function ensureDbOpen() {
73
+ try {
74
+ const db = await import("./gsd-db.js");
75
+ if (db.isDbAvailable())
76
+ return true;
77
+ const dbPath = join(process.cwd(), ".gsd", "gsd.db");
78
+ if (existsSync(dbPath)) {
79
+ return db.openDatabase(dbPath);
80
+ }
81
+ return false;
82
+ }
83
+ catch {
84
+ return false;
85
+ }
86
+ }
69
87
  // ── Queue phase tracking ──────────────────────────────────────────────────
70
88
  // When true, the LLM is in a queue flow writing CONTEXT.md files.
71
89
  // The write-gate applies during queue flows just like discussion flows.
@@ -228,13 +246,8 @@ export default function (pi) {
228
246
  when_context: Type.Optional(Type.String({ description: "When/context for the decision (e.g. milestone ID)" })),
229
247
  }),
230
248
  async execute(_toolCallId, params, _signal, _onUpdate, _ctx) {
231
- // Check DB availability
232
- let dbAvailable = false;
233
- try {
234
- const db = await import("./gsd-db.js");
235
- dbAvailable = db.isDbAvailable();
236
- }
237
- catch { /* dynamic import failed */ }
249
+ // Ensure DB is open (lazy-open on first tool call in manual sessions)
250
+ const dbAvailable = await ensureDbOpen();
238
251
  if (!dbAvailable) {
239
252
  return {
240
253
  content: [{ type: "text", text: "Error: GSD database is not available. Cannot save decision." }],
@@ -290,12 +303,7 @@ export default function (pi) {
290
303
  supporting_slices: Type.Optional(Type.String({ description: "Supporting slices" })),
291
304
  }),
292
305
  async execute(_toolCallId, params, _signal, _onUpdate, _ctx) {
293
- let dbAvailable = false;
294
- try {
295
- const db = await import("./gsd-db.js");
296
- dbAvailable = db.isDbAvailable();
297
- }
298
- catch { /* dynamic import failed */ }
306
+ const dbAvailable = await ensureDbOpen();
299
307
  if (!dbAvailable) {
300
308
  return {
301
309
  content: [{ type: "text", text: "Error: GSD database is not available. Cannot update requirement." }],
@@ -365,12 +373,7 @@ export default function (pi) {
365
373
  content: Type.String({ description: "The full markdown content of the artifact" }),
366
374
  }),
367
375
  async execute(_toolCallId, params, _signal, _onUpdate, _ctx) {
368
- let dbAvailable = false;
369
- try {
370
- const db = await import("./gsd-db.js");
371
- dbAvailable = db.isDbAvailable();
372
- }
373
- catch { /* dynamic import failed */ }
376
+ const dbAvailable = await ensureDbOpen();
374
377
  if (!dbAvailable) {
375
378
  return {
376
379
  content: [{ type: "text", text: "Error: GSD database is not available. Cannot save artifact." }],
@@ -518,6 +518,43 @@ export function nativeAddAll(basePath) {
518
518
  }
519
519
  gitFileExec(basePath, ["add", "-A"]);
520
520
  }
521
+ /**
522
+ * Stage all files with pathspec exclusions (git add -A -- ':!pattern' ...).
523
+ * Excluded paths are never hashed by git, preventing hangs on large
524
+ * untracked artifact trees (57GB+, 11K+ files). See #1605.
525
+ *
526
+ * Falls back to plain `git add -A` when no exclusions are provided.
527
+ * Always uses the CLI path (not libgit2) because libgit2's add_all
528
+ * does not support pathspec exclusion syntax.
529
+ *
530
+ * When excluded paths are already covered by .gitignore, git may exit
531
+ * with code 1 and an "ignored by .gitignore" warning. This is harmless
532
+ * (the staging succeeds for all non-ignored files) and is suppressed.
533
+ */
534
+ export function nativeAddAllWithExclusions(basePath, exclusions) {
535
+ if (exclusions.length === 0) {
536
+ nativeAddAll(basePath);
537
+ return;
538
+ }
539
+ const pathspecs = exclusions.map(e => `:!${e}`);
540
+ try {
541
+ execFileSync("git", ["add", "-A", "--", ...pathspecs], {
542
+ cwd: basePath,
543
+ stdio: ["ignore", "pipe", "pipe"],
544
+ encoding: "utf-8",
545
+ env: GIT_NO_PROMPT_ENV,
546
+ });
547
+ }
548
+ catch (err) {
549
+ // git exits 1 when pathspec exclusions reference paths already covered
550
+ // by .gitignore. The staging itself succeeds — only suppress that case.
551
+ const stderr = err?.stderr ?? "";
552
+ if (stderr.includes("ignored by one of your .gitignore files")) {
553
+ return;
554
+ }
555
+ throw new GSDError(GSD_GIT_ERROR, `git add -A with exclusions failed in ${basePath}: ${getErrorMessage(err)}`);
556
+ }
557
+ }
521
558
  /**
522
559
  * Stage specific files.
523
560
  * Native: libgit2 index add.
@@ -260,18 +260,6 @@ export function resolveInlineLevel() {
260
260
  case "quality": return "full";
261
261
  }
262
262
  }
263
- /**
264
- * Resolve the compression strategy from the active token profile.
265
- * budget/balanced -> "compress", quality -> "truncate".
266
- * Explicit preference always wins.
267
- */
268
- export function resolveCompressionStrategy() {
269
- const prefs = loadEffectiveGSDPreferences();
270
- if (prefs?.preferences.compression_strategy)
271
- return prefs.preferences.compression_strategy;
272
- const profile = resolveEffectiveProfile();
273
- return profile === "quality" ? "truncate" : "compress";
274
- }
275
263
  /**
276
264
  * Resolve the context selection mode from the active token profile.
277
265
  * budget -> "smart", balanced/quality -> "full".
@@ -62,10 +62,10 @@ export const KNOWN_PREFERENCE_KEYS = new Set([
62
62
  "verification_auto_fix",
63
63
  "verification_max_retries",
64
64
  "search_provider",
65
- "compression_strategy",
66
65
  "context_selection",
67
66
  "widget_mode",
68
67
  "reactive_execution",
68
+ "github",
69
69
  ]);
70
70
  /** Canonical list of all dispatch unit types. */
71
71
  export const KNOWN_UNIT_TYPES = [