gsd-pi 2.74.0-dev.703eabc → 2.74.0-dev.b2838e6

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 (113) hide show
  1. package/dist/resources/extensions/gsd/auto/phases.js +51 -6
  2. package/dist/resources/extensions/gsd/auto-model-selection.js +3 -3
  3. package/dist/resources/extensions/gsd/auto-recovery.js +24 -10
  4. package/dist/resources/extensions/gsd/auto-worktree.js +2 -0
  5. package/dist/resources/extensions/gsd/bootstrap/provider-error-resume.js +5 -3
  6. package/dist/resources/extensions/gsd/bootstrap/register-hooks.js +16 -5
  7. package/dist/resources/extensions/gsd/cache.js +16 -5
  8. package/dist/resources/extensions/gsd/commands/catalog.js +6 -1
  9. package/dist/resources/extensions/gsd/commands/handlers/core.js +5 -1
  10. package/dist/resources/extensions/gsd/commands-prefs-wizard.js +50 -3
  11. package/dist/resources/extensions/gsd/docs/preferences-reference.md +2 -0
  12. package/dist/resources/extensions/gsd/guided-flow.js +8 -6
  13. package/dist/resources/extensions/gsd/preferences-types.js +1 -0
  14. package/dist/resources/extensions/gsd/preferences-validation.js +10 -0
  15. package/dist/resources/extensions/gsd/preferences.js +5 -0
  16. package/dist/resources/extensions/gsd/safety/evidence-collector.js +15 -30
  17. package/dist/resources/extensions/gsd/templates/PREFERENCES.md +1 -0
  18. package/dist/tsconfig.extensions.tsbuildinfo +1 -1
  19. package/dist/web/standalone/.next/BUILD_ID +1 -1
  20. package/dist/web/standalone/.next/app-path-routes-manifest.json +13 -13
  21. package/dist/web/standalone/.next/build-manifest.json +2 -2
  22. package/dist/web/standalone/.next/prerender-manifest.json +3 -3
  23. package/dist/web/standalone/.next/server/app/_global-error.html +1 -1
  24. package/dist/web/standalone/.next/server/app/_global-error.rsc +1 -1
  25. package/dist/web/standalone/.next/server/app/_global-error.segments/_full.segment.rsc +1 -1
  26. package/dist/web/standalone/.next/server/app/_global-error.segments/_global-error/__PAGE__.segment.rsc +1 -1
  27. package/dist/web/standalone/.next/server/app/_global-error.segments/_global-error.segment.rsc +1 -1
  28. package/dist/web/standalone/.next/server/app/_global-error.segments/_head.segment.rsc +1 -1
  29. package/dist/web/standalone/.next/server/app/_global-error.segments/_index.segment.rsc +1 -1
  30. package/dist/web/standalone/.next/server/app/_global-error.segments/_tree.segment.rsc +1 -1
  31. package/dist/web/standalone/.next/server/app/_not-found.html +1 -1
  32. package/dist/web/standalone/.next/server/app/_not-found.rsc +1 -1
  33. package/dist/web/standalone/.next/server/app/_not-found.segments/_full.segment.rsc +1 -1
  34. package/dist/web/standalone/.next/server/app/_not-found.segments/_head.segment.rsc +1 -1
  35. package/dist/web/standalone/.next/server/app/_not-found.segments/_index.segment.rsc +1 -1
  36. package/dist/web/standalone/.next/server/app/_not-found.segments/_not-found/__PAGE__.segment.rsc +1 -1
  37. package/dist/web/standalone/.next/server/app/_not-found.segments/_not-found.segment.rsc +1 -1
  38. package/dist/web/standalone/.next/server/app/_not-found.segments/_tree.segment.rsc +1 -1
  39. package/dist/web/standalone/.next/server/app/index.html +1 -1
  40. package/dist/web/standalone/.next/server/app/index.rsc +1 -1
  41. package/dist/web/standalone/.next/server/app/index.segments/__PAGE__.segment.rsc +1 -1
  42. package/dist/web/standalone/.next/server/app/index.segments/_full.segment.rsc +1 -1
  43. package/dist/web/standalone/.next/server/app/index.segments/_head.segment.rsc +1 -1
  44. package/dist/web/standalone/.next/server/app/index.segments/_index.segment.rsc +1 -1
  45. package/dist/web/standalone/.next/server/app/index.segments/_tree.segment.rsc +1 -1
  46. package/dist/web/standalone/.next/server/app-paths-manifest.json +13 -13
  47. package/dist/web/standalone/.next/server/middleware-build-manifest.js +1 -1
  48. package/dist/web/standalone/.next/server/middleware-manifest.json +5 -5
  49. package/dist/web/standalone/.next/server/pages/404.html +1 -1
  50. package/dist/web/standalone/.next/server/pages/500.html +1 -1
  51. package/dist/web/standalone/.next/server/server-reference-manifest.json +1 -1
  52. package/package.json +1 -1
  53. package/packages/mcp-server/dist/workflow-tools.d.ts.map +1 -1
  54. package/packages/mcp-server/dist/workflow-tools.js +88 -6
  55. package/packages/mcp-server/dist/workflow-tools.js.map +1 -1
  56. package/packages/mcp-server/src/workflow-tools.ts +95 -10
  57. package/packages/mcp-server/tsconfig.tsbuildinfo +1 -1
  58. package/packages/pi-coding-agent/dist/modes/interactive/components/__tests__/chat-frame-compaction-tone.test.d.ts +2 -0
  59. package/packages/pi-coding-agent/dist/modes/interactive/components/__tests__/chat-frame-compaction-tone.test.d.ts.map +1 -0
  60. package/packages/pi-coding-agent/dist/modes/interactive/components/__tests__/chat-frame-compaction-tone.test.js +61 -0
  61. package/packages/pi-coding-agent/dist/modes/interactive/components/__tests__/chat-frame-compaction-tone.test.js.map +1 -0
  62. package/packages/pi-coding-agent/dist/modes/interactive/components/chat-frame.d.ts +1 -1
  63. package/packages/pi-coding-agent/dist/modes/interactive/components/chat-frame.d.ts.map +1 -1
  64. package/packages/pi-coding-agent/dist/modes/interactive/components/chat-frame.js +9 -3
  65. package/packages/pi-coding-agent/dist/modes/interactive/components/chat-frame.js.map +1 -1
  66. package/packages/pi-coding-agent/dist/modes/interactive/components/compaction-summary-message.d.ts +8 -5
  67. package/packages/pi-coding-agent/dist/modes/interactive/components/compaction-summary-message.d.ts.map +1 -1
  68. package/packages/pi-coding-agent/dist/modes/interactive/components/compaction-summary-message.js +27 -13
  69. package/packages/pi-coding-agent/dist/modes/interactive/components/compaction-summary-message.js.map +1 -1
  70. package/packages/pi-coding-agent/dist/modes/interactive/components/tool-execution.d.ts +8 -0
  71. package/packages/pi-coding-agent/dist/modes/interactive/components/tool-execution.d.ts.map +1 -1
  72. package/packages/pi-coding-agent/dist/modes/interactive/components/tool-execution.js +17 -0
  73. package/packages/pi-coding-agent/dist/modes/interactive/components/tool-execution.js.map +1 -1
  74. package/packages/pi-coding-agent/dist/modes/interactive/interactive-mode.d.ts +1 -0
  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 +17 -0
  77. package/packages/pi-coding-agent/dist/modes/interactive/interactive-mode.js.map +1 -1
  78. package/packages/pi-coding-agent/src/modes/interactive/components/__tests__/chat-frame-compaction-tone.test.ts +92 -0
  79. package/packages/pi-coding-agent/src/modes/interactive/components/chat-frame.ts +12 -4
  80. package/packages/pi-coding-agent/src/modes/interactive/components/compaction-summary-message.ts +36 -15
  81. package/packages/pi-coding-agent/src/modes/interactive/components/tool-execution.ts +17 -0
  82. package/packages/pi-coding-agent/src/modes/interactive/interactive-mode.ts +19 -0
  83. package/packages/pi-coding-agent/tsconfig.tsbuildinfo +1 -1
  84. package/packages/pi-tui/dist/tui.d.ts.map +1 -1
  85. package/packages/pi-tui/dist/tui.js +9 -2
  86. package/packages/pi-tui/dist/tui.js.map +1 -1
  87. package/packages/pi-tui/src/tui.ts +9 -1
  88. package/packages/pi-tui/tsconfig.tsbuildinfo +1 -1
  89. package/src/resources/extensions/gsd/auto/phases.ts +70 -6
  90. package/src/resources/extensions/gsd/auto-model-selection.ts +3 -3
  91. package/src/resources/extensions/gsd/auto-recovery.ts +29 -9
  92. package/src/resources/extensions/gsd/auto-worktree.ts +1 -0
  93. package/src/resources/extensions/gsd/bootstrap/provider-error-resume.ts +5 -3
  94. package/src/resources/extensions/gsd/bootstrap/register-hooks.ts +16 -5
  95. package/src/resources/extensions/gsd/cache.ts +16 -5
  96. package/src/resources/extensions/gsd/commands/catalog.ts +6 -1
  97. package/src/resources/extensions/gsd/commands/handlers/core.ts +5 -1
  98. package/src/resources/extensions/gsd/commands-prefs-wizard.ts +57 -3
  99. package/src/resources/extensions/gsd/docs/preferences-reference.md +2 -0
  100. package/src/resources/extensions/gsd/guided-flow.ts +4 -2
  101. package/src/resources/extensions/gsd/preferences-types.ts +6 -0
  102. package/src/resources/extensions/gsd/preferences-validation.ts +10 -0
  103. package/src/resources/extensions/gsd/preferences.ts +6 -0
  104. package/src/resources/extensions/gsd/safety/evidence-collector.ts +15 -31
  105. package/src/resources/extensions/gsd/templates/PREFERENCES.md +1 -0
  106. package/src/resources/extensions/gsd/tests/artifacts-table-preserved-on-cache-invalidate.test.ts +177 -0
  107. package/src/resources/extensions/gsd/tests/auto-retry-mcp-churn-fixes.test.ts +272 -0
  108. package/src/resources/extensions/gsd/tests/auto-warning-noise-regression.test.ts +117 -0
  109. package/src/resources/extensions/gsd/tests/journal-integration.test.ts +3 -3
  110. package/src/resources/extensions/gsd/tests/preferences.test.ts +145 -0
  111. package/src/resources/extensions/gsd/tests/provider-errors.test.ts +57 -2
  112. /package/dist/web/standalone/.next/static/{3U-oZ5FT59BM7sm2GInic → wuiYdNtJdo9ISED55DAkz}/_buildManifest.js +0 -0
  113. /package/dist/web/standalone/.next/static/{3U-oZ5FT59BM7sm2GInic → wuiYdNtJdo9ISED55DAkz}/_ssgManifest.js +0 -0
@@ -14,6 +14,8 @@ import { debugLog } from "../debug-logger.js";
14
14
  import { PROJECT_FILES } from "../detection.js";
15
15
  import { MergeConflictError } from "../git-service.js";
16
16
  import { setCurrentPhase, clearCurrentPhase } from "../../shared/gsd-phase-state.js";
17
+ import { pauseAutoForProviderError } from "../provider-error-pause.js";
18
+ import { resumeAutoAfterProviderDelay } from "../bootstrap/provider-error-resume.js";
17
19
  import { join, basename, dirname, parse as parsePath } from "node:path";
18
20
  import { existsSync, cpSync, readdirSync } from "node:fs";
19
21
  import { logWarning, logError, _resetLogs, drainLogs, drainAndSummarize, formatForNotification, hasAnyIssues, } from "../workflow-logger.js";
@@ -32,6 +34,12 @@ import { resetEvidence } from "../safety/evidence-collector.js";
32
34
  import { createCheckpoint, cleanupCheckpoint, rollbackToCheckpoint } from "../safety/git-checkpoint.js";
33
35
  import { resolveSafetyHarnessConfig } from "../safety/safety-harness.js";
34
36
  import { getWorkflowTransportSupportError, getRequiredWorkflowToolsForAutoUnit, } from "../workflow-mcp.js";
37
+ // ─── Session timeout auto-resume state ────────────────────────────────────────
38
+ let consecutiveSessionTimeouts = 0;
39
+ const MAX_SESSION_TIMEOUT_AUTO_RESUMES = 3;
40
+ export function resetSessionTimeoutState() {
41
+ consecutiveSessionTimeouts = 0;
42
+ }
35
43
  // ─── generateMilestoneReport ──────────────────────────────────────────────────
36
44
  /**
37
45
  * Resolve the base path for milestone reports.
@@ -1105,19 +1113,54 @@ export async function runUnitPhase(ic, iterData, loopState, sidecarItem) {
1105
1113
  debugLog("autoLoop", { phase: "exit", reason: "provider-pause", isTransient: unitResult.errorContext.isTransient });
1106
1114
  return { action: "break", reason: "provider-pause" };
1107
1115
  }
1108
- // Session creation timeout (not a structural error): pause auto-mode
1109
- // and let the provider-error-resume timer handle recovery (#3767). This
1110
- // matches the provider-pause pathbreak out cleanly, don't hard-stop.
1116
+ // Timeout category covers two distinct scenarios:
1117
+ // 1. Session creation timeout (120s) transient, auto-resume with backoff
1118
+ // 2. Unit hard timeout (30min+)stuck agent, pause for manual review
1111
1119
  // Structural errors (TypeError, is not a function) are NOT transient
1112
1120
  // and must hard-stop to avoid infinite retry loops.
1113
1121
  if (unitResult.errorContext?.isTransient &&
1114
1122
  unitResult.errorContext?.category === "timeout") {
1115
- ctx.ui.notify(`Session creation timed out for ${unitType} ${unitId}. Pausing auto-mode (recoverable).`, "warning");
1116
- debugLog("autoLoop", { phase: "session-timeout-pause", unitType, unitId });
1123
+ const isSessionCreationTimeout = unitResult.errorContext.message?.includes("Session creation timed out");
1124
+ if (isSessionCreationTimeout) {
1125
+ consecutiveSessionTimeouts += 1;
1126
+ const baseRetryAfterMs = 30_000;
1127
+ const retryAfterMs = baseRetryAfterMs * 2 ** Math.max(0, consecutiveSessionTimeouts - 1);
1128
+ const allowAutoResume = consecutiveSessionTimeouts <= MAX_SESSION_TIMEOUT_AUTO_RESUMES;
1129
+ if (!allowAutoResume) {
1130
+ ctx.ui.notify(`Session creation timed out ${consecutiveSessionTimeouts} consecutive times for ${unitType} ${unitId}. Pausing for manual review.`, "warning");
1131
+ }
1132
+ debugLog("autoLoop", {
1133
+ phase: "session-timeout-pause",
1134
+ unitType, unitId,
1135
+ consecutiveSessionTimeouts,
1136
+ retryAfterMs,
1137
+ allowAutoResume,
1138
+ });
1139
+ const errorDetail = ` for ${unitType} ${unitId}`;
1140
+ await pauseAutoForProviderError(ctx.ui, errorDetail, () => deps.pauseAuto(ctx, pi), {
1141
+ isRateLimit: false,
1142
+ isTransient: allowAutoResume,
1143
+ retryAfterMs,
1144
+ resume: allowAutoResume
1145
+ ? () => {
1146
+ void resumeAutoAfterProviderDelay(pi, ctx).catch((err) => {
1147
+ const message = err instanceof Error ? err.message : String(err);
1148
+ ctx.ui.notify(`Session timeout recovery failed: ${message}`, "error");
1149
+ });
1150
+ }
1151
+ : undefined,
1152
+ });
1153
+ await deps.autoCommitUnit?.(s.basePath, unitType, unitId, ctx);
1154
+ await emitCancelledUnitEnd(ic, unitType, unitId, unitStartSeq, unitResult.errorContext);
1155
+ return { action: "break", reason: "session-timeout" };
1156
+ }
1157
+ // Unit hard timeout (30min+): pause without auto-resume — stuck agent
1158
+ ctx.ui.notify(`Unit timed out for ${unitType} ${unitId} (supervision may have failed). Pausing auto-mode.`, "warning");
1159
+ debugLog("autoLoop", { phase: "unit-hard-timeout-pause", unitType, unitId });
1117
1160
  await deps.pauseAuto(ctx, pi);
1118
1161
  await deps.autoCommitUnit?.(s.basePath, unitType, unitId, ctx);
1119
1162
  await emitCancelledUnitEnd(ic, unitType, unitId, unitStartSeq, unitResult.errorContext);
1120
- return { action: "break", reason: "session-timeout" };
1163
+ return { action: "break", reason: "unit-hard-timeout" };
1121
1164
  }
1122
1165
  // All other cancelled states (structural errors, non-transient failures): hard stop
1123
1166
  if (s.currentUnit) {
@@ -1136,6 +1179,8 @@ export async function runUnitPhase(ic, iterData, loopState, sidecarItem) {
1136
1179
  // Guard: stopAuto() may have nulled s.currentUnit via s.reset() while
1137
1180
  // this coroutine was suspended at `await runUnit(...)` (#2939).
1138
1181
  if (s.currentUnit) {
1182
+ // Reset session timeout counter — any successful unit clears the slate
1183
+ consecutiveSessionTimeouts = 0;
1139
1184
  await deps.closeoutUnit(ctx, s.basePath, unitType, unitId, s.currentUnit.startedAt, deps.buildSnapshotOpts(unitType, unitId));
1140
1185
  }
1141
1186
  // ── Zero tool-call guard (#1833, #2653) ──────────────────────────
@@ -405,10 +405,10 @@ export function isFlatRateProvider(provider, opts) {
405
405
  */
406
406
  export function buildFlatRateContext(provider, ctx, prefs) {
407
407
  let authMode;
408
- const getAuthMode = ctx?.modelRegistry?.getProviderAuthMode;
409
- if (typeof getAuthMode === "function") {
408
+ const registry = ctx?.modelRegistry;
409
+ if (registry && typeof registry.getProviderAuthMode === "function") {
410
410
  try {
411
- const mode = getAuthMode(provider);
411
+ const mode = registry.getProviderAuthMode(provider);
412
412
  if (mode === "apiKey" || mode === "oauth" || mode === "externalCli" || mode === "none") {
413
413
  authMode = mode;
414
414
  }
@@ -215,20 +215,28 @@ export function verifyExpectedArtifact(unitType, unitId, base) {
215
215
  const absPath = resolveExpectedArtifactPath(unitType, unitId, base);
216
216
  // For unit types with no verifiable artifact (null path), the parent directory
217
217
  // is missing on disk — treat as stale completion state so the key gets evicted (#313).
218
- if (!absPath)
218
+ if (!absPath) {
219
+ logWarning("recovery", `verify-fail ${unitType} ${unitId}: resolveExpectedArtifactPath returned null (parent dir missing)`);
219
220
  return false;
220
- if (!existsSync(absPath))
221
+ }
222
+ if (!existsSync(absPath)) {
223
+ logWarning("recovery", `verify-fail ${unitType} ${unitId}: existsSync false for ${absPath}`);
221
224
  return false;
225
+ }
222
226
  if (unitType === "validate-milestone") {
223
227
  const validationContent = readFileSync(absPath, "utf-8");
224
- if (!isValidationTerminal(validationContent))
228
+ if (!isValidationTerminal(validationContent)) {
229
+ logWarning("recovery", `verify-fail ${unitType} ${unitId}: validation not terminal (len=${validationContent.length}) at ${absPath}`);
225
230
  return false;
231
+ }
226
232
  }
227
233
  if (unitType === "plan-milestone") {
228
234
  try {
229
235
  const roadmap = parseLegacyRoadmap(readFileSync(absPath, "utf-8"));
230
- if (roadmap.slices.length === 0)
236
+ if (roadmap.slices.length === 0) {
237
+ logWarning("recovery", `verify-fail ${unitType} ${unitId}: roadmap has zero slices at ${absPath}`);
231
238
  return false;
239
+ }
232
240
  }
233
241
  catch (err) {
234
242
  logWarning("recovery", `plan-milestone roadmap verification failed: ${err instanceof Error ? err.message : String(err)}`);
@@ -245,8 +253,10 @@ export function verifyExpectedArtifact(unitType, unitId, base) {
245
253
  // Accept checkbox-style (- [x] **T01: ...) or heading-style (### T01 -- / ### T01: / ### T01 —)
246
254
  const hasCheckboxTask = /^- \[[xX ]\] \*\*T\d+:/m.test(planContent);
247
255
  const hasHeadingTask = /^#{2,4}\s+T\d+\s*(?:--|—|:)/m.test(planContent);
248
- if (!hasCheckboxTask && !hasHeadingTask)
256
+ if (!hasCheckboxTask && !hasHeadingTask) {
257
+ logWarning("recovery", `verify-fail ${unitType} ${unitId}: plan has no task checkbox/heading (len=${planContent.length}) at ${absPath}`);
249
258
  return false;
259
+ }
250
260
  }
251
261
  // execute-task: DB status is authoritative. Fall back to checked-checkbox
252
262
  // detection when the DB is unavailable (unmigrated projects).
@@ -306,11 +316,15 @@ export function verifyExpectedArtifact(unitType, unitId, base) {
306
316
  }
307
317
  if (taskIds && taskIds.length > 0) {
308
318
  const tasksDir = resolveTasksDir(base, mid, sid);
309
- if (tasksDir) {
310
- for (const tid of taskIds) {
311
- const taskPlanFile = join(tasksDir, `${tid}-PLAN.md`);
312
- if (!existsSync(taskPlanFile))
313
- return false;
319
+ if (!tasksDir) {
320
+ logWarning("recovery", `verify-fail ${unitType} ${unitId}: resolveTasksDir returned null for ${mid}/${sid}`);
321
+ return false;
322
+ }
323
+ for (const tid of taskIds) {
324
+ const taskPlanFile = join(tasksDir, `${tid}-PLAN.md`);
325
+ if (!existsSync(taskPlanFile)) {
326
+ logWarning("recovery", `verify-fail ${unitType} ${unitId}: task plan missing ${taskPlanFile}`);
327
+ return false;
314
328
  }
315
329
  }
316
330
  }
@@ -54,6 +54,8 @@ function isSamePath(a, b) {
54
54
  return realpathSync(a) === realpathSync(b);
55
55
  }
56
56
  catch (e) {
57
+ if (e.code === "ENOENT")
58
+ return false;
57
59
  logWarning("worktree", `isSamePath failed: ${e.message}`);
58
60
  return false;
59
61
  }
@@ -1,5 +1,6 @@
1
1
  import { getAutoDashboardData, startAuto } from "../auto.js";
2
2
  import { resetTransientRetryState } from "./agent-end-recovery.js";
3
+ import { resetSessionTimeoutState } from "../auto/phases.js";
3
4
  const defaultDeps = {
4
5
  getSnapshot: () => getAutoDashboardData(),
5
6
  startAuto,
@@ -14,10 +15,11 @@ export async function resumeAutoAfterProviderDelay(pi, ctx, deps = defaultDeps)
14
15
  ctx.ui.notify("Provider error recovery delay elapsed, but no paused auto-mode base path was available. Leaving auto-mode paused.", "warning");
15
16
  return "missing-base";
16
17
  }
17
- // Reset the transient retry counter before restarting — without this,
18
- // consecutiveTransientCount accumulates across pause/resume cycles and
19
- // permanently locks out auto-resume after MAX_TRANSIENT_AUTO_RESUMES errors.
18
+ // Reset retry counters before restarting — without this, counters
19
+ // accumulate across pause/resume cycles and permanently lock out
20
+ // auto-resume after their respective MAX thresholds.
20
21
  resetTransientRetryState();
22
+ resetSessionTimeoutState();
21
23
  await deps.startAuto(ctx, pi, snapshot.basePath, false, { step: snapshot.stepMode });
22
24
  return "resumed";
23
25
  }
@@ -41,8 +41,12 @@ export function registerHooks(pi, ecosystemHandlers) {
41
41
  resetToolCallLoopGuard();
42
42
  resetAskUserQuestionsCache();
43
43
  await syncServiceTierStatus(ctx);
44
- const { prepareWorkflowMcpForProject } = await import("../workflow-mcp-auto-prep.js");
45
- prepareWorkflowMcpForProject(ctx, process.cwd());
44
+ // Skip MCP auto-prep when running inside an auto-worktree (see session_switch below).
45
+ const { isInAutoWorktree } = await import("../auto-worktree.js");
46
+ if (!isInAutoWorktree(process.cwd())) {
47
+ const { prepareWorkflowMcpForProject } = await import("../workflow-mcp-auto-prep.js");
48
+ prepareWorkflowMcpForProject(ctx, process.cwd());
49
+ }
46
50
  // Apply show_token_cost preference (#1515)
47
51
  try {
48
52
  const { loadEffectiveGSDPreferences } = await import("../preferences.js");
@@ -82,8 +86,15 @@ export function registerHooks(pi, ecosystemHandlers) {
82
86
  resetAskUserQuestionsCache();
83
87
  clearDiscussionFlowState();
84
88
  await syncServiceTierStatus(ctx);
85
- const { prepareWorkflowMcpForProject } = await import("../workflow-mcp-auto-prep.js");
86
- prepareWorkflowMcpForProject(ctx, process.cwd());
89
+ // Skip MCP auto-prep when running inside an auto-worktree. The worktree
90
+ // already has .mcp.json from createAutoWorktree, and re-running the writer
91
+ // post-chdir rewrites the file mid-run (non-idempotent due to cwd-relative
92
+ // CLI path resolution), dirtying the tree and breaking the milestone merge.
93
+ const { isInAutoWorktree } = await import("../auto-worktree.js");
94
+ if (!isInAutoWorktree(process.cwd())) {
95
+ const { prepareWorkflowMcpForProject } = await import("../workflow-mcp-auto-prep.js");
96
+ prepareWorkflowMcpForProject(ctx, process.cwd());
97
+ }
87
98
  loadToolApiKeys();
88
99
  });
89
100
  pi.on("before_agent_start", async (event, ctx) => {
@@ -281,7 +292,7 @@ export function registerHooks(pi, ecosystemHandlers) {
281
292
  pi.on("tool_call", async (event, ctx) => {
282
293
  if (!isAutoActive())
283
294
  return;
284
- safetyRecordToolCall(event.toolName, event.input);
295
+ safetyRecordToolCall(event.toolCallId, event.toolName, event.input);
285
296
  // Destructive command classification (warn only, never block)
286
297
  if (isToolCallEventType("bash", event)) {
287
298
  const classification = classifyCommand(event.input.command);
@@ -1,6 +1,6 @@
1
1
  // GSD Extension — Unified Cache Invalidation
2
2
  //
3
- // Three module-scoped caches exist across the GSD extension:
3
+ // Three module-scoped read caches exist across the GSD extension:
4
4
  // 1. State cache (state.ts) — memoized deriveState() result
5
5
  // 2. Path cache (paths.ts) — directory listing results (readdirSync)
6
6
  // 3. Parse cache (files.ts) — parsed markdown file results
@@ -8,20 +8,31 @@
8
8
  // After any file write that changes .gsd/ contents, all three must be
9
9
  // invalidated together to prevent stale reads. This module provides a
10
10
  // single function that clears all three atomically.
11
+ //
12
+ // NOTE: The DB `artifacts` table is NOT included here. Earlier versions
13
+ // called clearArtifacts() as part of this bundle (#793), intending to
14
+ // force deriveState() to re-parse from disk when files were edited
15
+ // out-of-band. But invalidateAllCaches() fires on every post-unit pass,
16
+ // so bundling a DESTRUCTIVE `DELETE FROM artifacts` with routine cache
17
+ // invalidation meant every row written by saveArtifactToDb / writeAndStore
18
+ // was wiped within seconds — leaving the milestone completed on disk but
19
+ // the `artifacts` table empty and the agent looping on "file exists but
20
+ // DB record missing" recovery calls. If a call site genuinely needs the
21
+ // artifact table cleared after an out-of-band file mutation, it should
22
+ // invoke clearArtifacts() from gsd-db.js explicitly — do not add it back
23
+ // here.
11
24
  import { invalidateStateCache } from './state.js';
12
25
  import { clearPathCache } from './paths.js';
13
26
  import { clearParseCache } from './files.js';
14
- import { clearArtifacts } from './gsd-db.js';
15
27
  /**
16
- * Invalidate all GSD runtime caches in one call.
28
+ * Invalidate all GSD runtime read caches in one call.
17
29
  *
18
30
  * Call this after file writes, milestone transitions, merge reconciliation,
19
31
  * or any operation that changes .gsd/ contents on disk. Forgetting to clear
20
- * any single cache causes stale reads (see #431, #793).
32
+ * any single cache causes stale reads (see #431).
21
33
  */
22
34
  export function invalidateAllCaches() {
23
35
  invalidateStateCache();
24
36
  clearPathCache();
25
37
  clearParseCache();
26
- clearArtifacts();
27
38
  }
@@ -4,7 +4,7 @@ import { join } from "node:path";
4
4
  import { loadRegistry } from "../workflow-templates.js";
5
5
  import { resolveProjectRoot } from "../worktree.js";
6
6
  const gsdHome = process.env.GSD_HOME || join(homedir(), ".gsd");
7
- export const GSD_COMMAND_DESCRIPTION = "GSD — Get Shit Done: /gsd help|start|templates|next|auto|stop|pause|status|widget|visualize|queue|quick|discuss|capture|triage|dispatch|history|undo|undo-task|reset-slice|rate|skip|export|cleanup|model|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|fast|mcp|rethink|codebase|notifications|ship|do|session-report|backlog|pr-branch|add-tests";
7
+ export const GSD_COMMAND_DESCRIPTION = "GSD — Get Shit Done: /gsd help|start|templates|next|auto|stop|pause|status|widget|visualize|queue|quick|discuss|capture|triage|dispatch|history|undo|undo-task|reset-slice|rate|skip|export|cleanup|model|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|fast|mcp|rethink|codebase|notifications|ship|do|session-report|backlog|pr-branch|add-tests|language";
8
8
  export const TOP_LEVEL_SUBCOMMANDS = [
9
9
  { cmd: "help", desc: "Categorized command reference with descriptions" },
10
10
  { cmd: "next", desc: "Explicit step mode (same as /gsd)" },
@@ -68,6 +68,7 @@ export const TOP_LEVEL_SUBCOMMANDS = [
68
68
  { cmd: "backlog", desc: "Manage backlog items (add, promote, remove, list)" },
69
69
  { cmd: "pr-branch", desc: "Create clean PR branch filtering .gsd/ commits" },
70
70
  { cmd: "add-tests", desc: "Generate tests for completed slices" },
71
+ { cmd: "language", desc: "Set or clear the global response language (e.g. /gsd language Chinese)" },
71
72
  ];
72
73
  const NESTED_COMPLETIONS = {
73
74
  auto: [
@@ -256,6 +257,10 @@ const NESTED_COMPLETIONS = {
256
257
  { cmd: "--dry-run", desc: "Preview what would be filtered" },
257
258
  { cmd: "--name", desc: "Custom branch name" },
258
259
  ],
260
+ language: [
261
+ { cmd: "off", desc: "Clear the language preference (revert to default)" },
262
+ { cmd: "clear", desc: "Alias for off — clear the language preference" },
263
+ ],
259
264
  };
260
265
  function filterOptions(partial, options, prefix = "") {
261
266
  const normalizedPrefix = prefix ? `${prefix} ` : "";
@@ -1,6 +1,6 @@
1
1
  import { computeProgressScore, formatProgressLine } from "../../progress-score.js";
2
2
  import { getGlobalGSDPreferencesPath, getProjectGSDPreferencesPath } from "../../preferences.js";
3
- import { ensurePreferencesFile, handlePrefs, handlePrefsMode, handlePrefsWizard } from "../../commands-prefs-wizard.js";
3
+ import { ensurePreferencesFile, handlePrefs, handlePrefsMode, handlePrefsWizard, handleLanguage } from "../../commands-prefs-wizard.js";
4
4
  import { runEnvironmentChecks } from "../../doctor-environment.js";
5
5
  import { deriveState } from "../../state.js";
6
6
  import { handleCmux } from "../../commands-cmux.js";
@@ -339,6 +339,10 @@ export async function handleCoreCommand(trimmed, ctx, pi) {
339
339
  await handlePrefs(trimmed.replace(/^prefs\s*/, "").trim(), ctx);
340
340
  return true;
341
341
  }
342
+ if (trimmed === "language" || trimmed.startsWith("language ")) {
343
+ await handleLanguage(trimmed.replace(/^language\s*/, "").trim(), ctx);
344
+ return true;
345
+ }
342
346
  if (trimmed === "cmux" || trimmed.startsWith("cmux ")) {
343
347
  await handleCmux(trimmed.replace(/^cmux\s*/, "").trim(), ctx);
344
348
  return true;
@@ -642,8 +642,8 @@ export async function handlePrefsWizard(ctx, scope) {
642
642
  export function yamlSafeString(val) {
643
643
  if (typeof val !== "string")
644
644
  return String(val);
645
- if (/[:#{\[\]'"`,|>&*!?@%]/.test(val) || val.trim() !== val || val === "") {
646
- return `"${val.replace(/\\/g, "\\\\").replace(/"/g, '\\"')}"`;
645
+ if (/[:#{\[\]'"`,|>&*!?@%\r\n]/.test(val) || val.trim() !== val || val === "") {
646
+ return `"${val.replace(/\\/g, "\\\\").replace(/"/g, '\\"').replace(/\r/g, "\\r").replace(/\n/g, "\\n")}"`;
647
647
  }
648
648
  return val;
649
649
  }
@@ -708,7 +708,7 @@ export function serializePreferencesToFrontmatter(prefs) {
708
708
  "dynamic_routing", "uok", "token_profile", "phases", "parallel",
709
709
  "auto_visualize", "auto_report",
710
710
  "verification_commands", "verification_auto_fix", "verification_max_retries",
711
- "search_provider", "context_selection",
711
+ "search_provider", "context_selection", "language",
712
712
  ];
713
713
  const seen = new Set();
714
714
  for (const key of orderedKeys) {
@@ -739,3 +739,50 @@ export async function ensurePreferencesFile(path, ctx, scope) {
739
739
  ctx.ui.notify(`Using existing ${scope} GSD skill preferences at ${path}`, "info");
740
740
  }
741
741
  }
742
+ /**
743
+ * Handle `/gsd language [code]` — set or clear the global language preference.
744
+ * Without an argument, shows the current setting.
745
+ * Project-level override can be set by editing `.gsd/preferences.md` directly
746
+ * (project language overrides global when both are set).
747
+ */
748
+ export async function handleLanguage(args, ctx) {
749
+ const path = getGlobalGSDPreferencesPath();
750
+ const lang = args.trim();
751
+ // Show current setting when called without argument
752
+ if (!lang) {
753
+ const loaded = loadGlobalGSDPreferences();
754
+ const current = loaded?.preferences.language;
755
+ if (current) {
756
+ ctx.ui.notify(`Current language preference: ${current}\nUse /gsd language <name> to change, or /gsd language off to clear.`, "info");
757
+ }
758
+ else {
759
+ ctx.ui.notify("No language preference set. Use /gsd language <name> to set one (e.g. /gsd language Chinese).", "info");
760
+ }
761
+ return;
762
+ }
763
+ // Ensure preferences file exists with the canonical template
764
+ await ensurePreferencesFile(path, ctx, "global");
765
+ // Read via the same validated path as other handlers
766
+ const existing = loadGlobalGSDPreferences();
767
+ const prefs = existing?.preferences ? { ...existing.preferences } : { version: 1 };
768
+ if (lang === "off" || lang === "none" || lang === "clear") {
769
+ delete prefs.language;
770
+ ctx.ui.notify("Language preference cleared. GSD will use the default language.", "info");
771
+ }
772
+ else {
773
+ // Validate before writing — reject values that would fail on next load
774
+ if (lang.length > 50 || /[\r\n]/.test(lang)) {
775
+ ctx.ui.notify("Language value must be 50 characters or fewer with no newlines (e.g. /gsd language Chinese).", "warning");
776
+ return;
777
+ }
778
+ prefs.language = lang;
779
+ ctx.ui.notify(`Language preference set to: ${lang}\nGSD will now respond in ${lang} across all sessions.`, "info");
780
+ }
781
+ const rawContent = existsSync(path) ? readFileSync(path, "utf-8") : `---\nversion: 1\n---\n`;
782
+ const frontmatter = serializePreferencesToFrontmatter(prefs);
783
+ const body = extractBodyAfterFrontmatter(rawContent)
784
+ ?? "\n# GSD Skill Preferences\n\nSee `~/.gsd/agent/extensions/gsd/docs/preferences-reference.md` for full field documentation and examples.\n";
785
+ await saveFile(path, `---\n${frontmatter}---${body}`);
786
+ await ctx.waitForIdle();
787
+ await ctx.reload();
788
+ }
@@ -102,6 +102,8 @@ Setting `prefer_skills: []` does **not** disable skill discovery — it just mea
102
102
 
103
103
  - `custom_instructions`: extra durable instructions related to skill use. For operational project knowledge (recurring rules, gotchas, patterns), use `.gsd/KNOWLEDGE.md` instead — it's injected into every agent prompt automatically and agents can append to it during execution.
104
104
 
105
+ - `language`: preferred response language for all GSD interactions. Accepts any language name or code — `"Chinese"`, `"zh"`, `"German"`, `"de"`, `"日本語"`, etc. When set, GSD injects "Always respond in \<language\>" into every agent's system prompt, including after `/clear`. Quickest way to set it: `/gsd language <name>`. To clear: `/gsd language off`.
106
+
105
107
  - `models`: per-stage model selection (applies to both auto-mode and guided-flow dispatches). Keys: `research`, `planning`, `discuss`, `execution`, `execution_simple`, `completion`, `validation`, `subagent`. Values can be:
106
108
  - Simple string: `"claude-sonnet-4-6"` — single model, no fallbacks
107
109
  - Provider-qualified string: `"bedrock/claude-sonnet-4-6"` — targets a specific provider when the same model ID exists across multiple providers
@@ -212,14 +212,16 @@ export function checkAutoStartAfterDiscuss() {
212
212
  logWarning("guided", `CONTEXT-DRAFT.md unlink failed: ${e.message}`);
213
213
  }
214
214
  // Cleanup: remove discussion manifest after auto-start (only needed during discussion)
215
- try {
216
- unlinkSync(manifestPath);
217
- }
218
- catch (e) {
219
- logWarning("guided", `manifest unlink failed: ${e.message}`);
215
+ if (existsSync(manifestPath)) {
216
+ try {
217
+ unlinkSync(manifestPath);
218
+ }
219
+ catch (e) {
220
+ logWarning("guided", `manifest unlink failed: ${e.message}`);
221
+ }
220
222
  }
221
223
  pendingAutoStartMap.delete(basePath);
222
- ctx.ui.notify(`Milestone ${milestoneId} ready.`, "info");
224
+ ctx.ui.notify(`Milestone ${milestoneId} ready.`, "success");
223
225
  startAutoDetached(ctx, pi, basePath, false, { step });
224
226
  return true;
225
227
  }
@@ -85,6 +85,7 @@ export const KNOWN_PREFERENCE_KEYS = new Set([
85
85
  "discuss_web_research",
86
86
  "discuss_depth",
87
87
  "flat_rate_providers",
88
+ "language",
88
89
  ]);
89
90
  /** Canonical list of all dispatch unit types. */
90
91
  export const KNOWN_UNIT_TYPES = [
@@ -1144,5 +1144,15 @@ export function validatePreferences(preferences) {
1144
1144
  errors.push(`discuss_depth must be one of: quick, standard, thorough`);
1145
1145
  }
1146
1146
  }
1147
+ // ─── Language ────────────────────────────────────────────────────────
1148
+ if (preferences.language !== undefined) {
1149
+ const trimmed = typeof preferences.language === "string" ? preferences.language.trim() : undefined;
1150
+ if (trimmed && trimmed.length <= 50 && !/[\r\n]/.test(trimmed)) {
1151
+ validated.language = trimmed;
1152
+ }
1153
+ else {
1154
+ errors.push(`language must be a non-empty string up to 50 characters with no newlines (e.g. "Chinese", "de", "日本語")`);
1155
+ }
1156
+ }
1147
1157
  return { preferences: validated, errors, warnings };
1148
1158
  }
@@ -360,6 +360,7 @@ function mergePreferences(base, override) {
360
360
  slice_parallel: (base.slice_parallel || override.slice_parallel)
361
361
  ? { ...(base.slice_parallel ?? {}), ...(override.slice_parallel ?? {}) }
362
362
  : undefined,
363
+ language: override.language ?? base.language,
363
364
  };
364
365
  }
365
366
  function mergeStringLists(base, override) {
@@ -454,6 +455,10 @@ export function renderPreferencesForSystemPrompt(preferences, resolutions) {
454
455
  lines.push(` - ${instruction}`);
455
456
  }
456
457
  }
458
+ if (preferences.language) {
459
+ const safeLang = preferences.language.replace(/[\r\n]/g, " ").slice(0, 50);
460
+ lines.push(`- Language: Always respond in ${safeLang}.`);
461
+ }
457
462
  return lines.join("\n");
458
463
  }
459
464
  // ─── Hook Resolution ──────────────────────────────────────────────────────────
@@ -32,11 +32,11 @@ export function getFilePaths() {
32
32
  * Record a tool call at dispatch time (before execution).
33
33
  * Exit codes and output are filled in by recordToolResult after execution.
34
34
  */
35
- export function recordToolCall(toolName, input) {
35
+ export function recordToolCall(toolCallId, toolName, input) {
36
36
  if (toolName === "bash" || toolName === "Bash") {
37
37
  unitEvidence.push({
38
38
  kind: "bash",
39
- toolCallId: "",
39
+ toolCallId,
40
40
  command: String(input.command ?? ""),
41
41
  exitCode: -1,
42
42
  outputSnippet: "",
@@ -46,7 +46,7 @@ export function recordToolCall(toolName, input) {
46
46
  else if (toolName === "write" || toolName === "Write") {
47
47
  unitEvidence.push({
48
48
  kind: "write",
49
- toolCallId: "",
49
+ toolCallId,
50
50
  path: String(input.file_path ?? input.path ?? ""),
51
51
  timestamp: Date.now(),
52
52
  });
@@ -54,44 +54,29 @@ export function recordToolCall(toolName, input) {
54
54
  else if (toolName === "edit" || toolName === "Edit") {
55
55
  unitEvidence.push({
56
56
  kind: "edit",
57
- toolCallId: "",
57
+ toolCallId,
58
58
  path: String(input.file_path ?? input.path ?? ""),
59
59
  timestamp: Date.now(),
60
60
  });
61
61
  }
62
62
  }
63
63
  /**
64
- * Record a tool execution result. Matches the most recent unresolved entry
65
- * of the same kind and fills in the toolCallId, exit code, and output.
64
+ * Record a tool execution result. Matches the entry by toolCallId (assigned
65
+ * at dispatch time) and fills in exit code + output. Prior versions matched
66
+ * by `kind + empty-string` which corrupted parallel tool calls.
66
67
  */
67
68
  export function recordToolResult(toolCallId, toolName, result, isError) {
68
- const normalizedName = toolName.toLowerCase();
69
- if (normalizedName === "bash") {
70
- const entry = findLastUnresolved("bash");
71
- if (entry) {
72
- entry.toolCallId = toolCallId;
73
- const text = extractResultText(result);
74
- entry.outputSnippet = text.slice(0, 500);
75
- const exitMatch = text.match(/Command exited with code (\d+)/);
76
- entry.exitCode = exitMatch ? Number(exitMatch[1]) : (isError ? 1 : 0);
77
- }
78
- }
79
- else if (normalizedName === "write" || normalizedName === "edit") {
80
- const entry = findLastUnresolved(normalizedName);
81
- if (entry) {
82
- entry.toolCallId = toolCallId;
83
- }
69
+ const entry = unitEvidence.find(e => e.toolCallId === toolCallId);
70
+ if (!entry)
71
+ return;
72
+ if (entry.kind === "bash") {
73
+ const text = extractResultText(result);
74
+ entry.outputSnippet = text.slice(0, 500);
75
+ const exitMatch = text.match(/Command exited with code (\d+)/);
76
+ entry.exitCode = exitMatch ? Number(exitMatch[1]) : (isError ? 1 : 0);
84
77
  }
85
78
  }
86
79
  // ─── Internals ──────────────────────────────────────────────────────────────
87
- function findLastUnresolved(kind) {
88
- for (let i = unitEvidence.length - 1; i >= 0; i--) {
89
- if (unitEvidence[i].kind === kind && unitEvidence[i].toolCallId === "") {
90
- return unitEvidence[i];
91
- }
92
- }
93
- return undefined;
94
- }
95
80
  function extractResultText(result) {
96
81
  if (typeof result === "string")
97
82
  return result;
@@ -89,6 +89,7 @@ remote_questions:
89
89
  uat_dispatch:
90
90
  post_unit_hooks: []
91
91
  pre_dispatch_hooks: []
92
+ # language:
92
93
  # experimental:
93
94
  # rtk: false
94
95
  ---