@opengsd/gsd-pi 1.1.1-dev.3ea310e → 1.1.1-dev.74e8dd1

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 (177) hide show
  1. package/dist/resources/.managed-resources-content-hash +1 -1
  2. package/dist/resources/extensions/gsd/auto/phases.js +4 -3
  3. package/dist/resources/extensions/gsd/auto-dashboard.js +15 -4
  4. package/dist/resources/extensions/gsd/auto-post-unit.js +111 -5
  5. package/dist/resources/extensions/gsd/auto-prompts.js +9 -0
  6. package/dist/resources/extensions/gsd/auto-start.js +41 -12
  7. package/dist/resources/extensions/gsd/auto-unit-tool-scope.js +2 -1
  8. package/dist/resources/extensions/gsd/auto.js +3 -3
  9. package/dist/resources/extensions/gsd/bootstrap/db-tools.js +79 -0
  10. package/dist/resources/extensions/gsd/bootstrap/exec-tools.js +43 -0
  11. package/dist/resources/extensions/gsd/bootstrap/register-hooks.js +30 -9
  12. package/dist/resources/extensions/gsd/bootstrap/write-gate.js +16 -10
  13. package/dist/resources/extensions/gsd/commands/handlers/core.js +1 -1
  14. package/dist/resources/extensions/gsd/commands-prefs-wizard.js +3 -1
  15. package/dist/resources/extensions/gsd/commands-verdict.js +1 -1
  16. package/dist/resources/extensions/gsd/config-overlay.js +2 -1
  17. package/dist/resources/extensions/gsd/error-classifier.js +2 -1
  18. package/dist/resources/extensions/gsd/exec-sandbox.js +2 -0
  19. package/dist/resources/extensions/gsd/prompts/run-uat.md +10 -4
  20. package/dist/resources/extensions/gsd/prompts/system.md +3 -1
  21. package/dist/resources/extensions/gsd/safety/destructive-guard.js +3 -0
  22. package/dist/resources/extensions/gsd/skill-activation.js +20 -3
  23. package/dist/resources/extensions/gsd/state-reconciliation/drift/roadmap.js +18 -1
  24. package/dist/resources/extensions/gsd/state-reconciliation/index.js +6 -0
  25. package/dist/resources/extensions/gsd/state.js +1 -1
  26. package/dist/resources/extensions/gsd/tools/exec-tool.js +109 -0
  27. package/dist/resources/extensions/gsd/tools/workflow-tool-executors.js +366 -3
  28. package/dist/resources/extensions/gsd/unit-context-manifest.js +8 -3
  29. package/dist/resources/extensions/gsd/validation-block-guard.js +2 -0
  30. package/dist/resources/extensions/gsd/workflow-mcp-auto-prep.js +1 -1
  31. package/dist/resources/extensions/gsd/workflow-mcp.js +5 -1
  32. package/dist/web/standalone/.next/BUILD_ID +1 -1
  33. package/dist/web/standalone/.next/app-path-routes-manifest.json +6 -6
  34. package/dist/web/standalone/.next/build-manifest.json +2 -2
  35. package/dist/web/standalone/.next/prerender-manifest.json +3 -3
  36. package/dist/web/standalone/.next/server/app/_global-error.html +1 -1
  37. package/dist/web/standalone/.next/server/app/_global-error.rsc +1 -1
  38. package/dist/web/standalone/.next/server/app/_global-error.segments/_full.segment.rsc +1 -1
  39. package/dist/web/standalone/.next/server/app/_global-error.segments/_global-error/__PAGE__.segment.rsc +1 -1
  40. package/dist/web/standalone/.next/server/app/_global-error.segments/_global-error.segment.rsc +1 -1
  41. package/dist/web/standalone/.next/server/app/_global-error.segments/_head.segment.rsc +1 -1
  42. package/dist/web/standalone/.next/server/app/_global-error.segments/_index.segment.rsc +1 -1
  43. package/dist/web/standalone/.next/server/app/_global-error.segments/_tree.segment.rsc +1 -1
  44. package/dist/web/standalone/.next/server/app/_not-found.html +1 -1
  45. package/dist/web/standalone/.next/server/app/_not-found.rsc +1 -1
  46. package/dist/web/standalone/.next/server/app/_not-found.segments/_full.segment.rsc +1 -1
  47. package/dist/web/standalone/.next/server/app/_not-found.segments/_head.segment.rsc +1 -1
  48. package/dist/web/standalone/.next/server/app/_not-found.segments/_index.segment.rsc +1 -1
  49. package/dist/web/standalone/.next/server/app/_not-found.segments/_not-found/__PAGE__.segment.rsc +1 -1
  50. package/dist/web/standalone/.next/server/app/_not-found.segments/_not-found.segment.rsc +1 -1
  51. package/dist/web/standalone/.next/server/app/_not-found.segments/_tree.segment.rsc +1 -1
  52. package/dist/web/standalone/.next/server/app/index.html +1 -1
  53. package/dist/web/standalone/.next/server/app/index.rsc +1 -1
  54. package/dist/web/standalone/.next/server/app/index.segments/__PAGE__.segment.rsc +1 -1
  55. package/dist/web/standalone/.next/server/app/index.segments/_full.segment.rsc +1 -1
  56. package/dist/web/standalone/.next/server/app/index.segments/_head.segment.rsc +1 -1
  57. package/dist/web/standalone/.next/server/app/index.segments/_index.segment.rsc +1 -1
  58. package/dist/web/standalone/.next/server/app/index.segments/_tree.segment.rsc +1 -1
  59. package/dist/web/standalone/.next/server/app-paths-manifest.json +6 -6
  60. package/dist/web/standalone/.next/server/chunks/8357.js +1 -1
  61. package/dist/web/standalone/.next/server/middleware-build-manifest.js +1 -1
  62. package/dist/web/standalone/.next/server/pages/404.html +1 -1
  63. package/dist/web/standalone/.next/server/pages/500.html +1 -1
  64. package/dist/web/standalone/.next/server/server-reference-manifest.json +1 -1
  65. package/package.json +2 -2
  66. package/packages/cloud-mcp-gateway/package.json +2 -2
  67. package/packages/contracts/dist/workflow.d.ts +14 -0
  68. package/packages/contracts/dist/workflow.d.ts.map +1 -1
  69. package/packages/contracts/dist/workflow.js +16 -0
  70. package/packages/contracts/dist/workflow.js.map +1 -1
  71. package/packages/contracts/package.json +1 -1
  72. package/packages/daemon/package.json +4 -4
  73. package/packages/gsd-agent-core/package.json +5 -5
  74. package/packages/gsd-agent-modes/dist/modes/interactive/components/settings-selector.d.ts +2 -0
  75. package/packages/gsd-agent-modes/dist/modes/interactive/components/settings-selector.d.ts.map +1 -1
  76. package/packages/gsd-agent-modes/dist/modes/interactive/components/settings-selector.js +10 -0
  77. package/packages/gsd-agent-modes/dist/modes/interactive/components/settings-selector.js.map +1 -1
  78. package/packages/gsd-agent-modes/dist/modes/interactive/controllers/chat-controller.d.ts +1 -0
  79. package/packages/gsd-agent-modes/dist/modes/interactive/controllers/chat-controller.d.ts.map +1 -1
  80. package/packages/gsd-agent-modes/dist/modes/interactive/controllers/chat-controller.js +69 -31
  81. package/packages/gsd-agent-modes/dist/modes/interactive/controllers/chat-controller.js.map +1 -1
  82. package/packages/gsd-agent-modes/dist/modes/interactive/interactive-mode-class-constants.d.ts +1 -1
  83. package/packages/gsd-agent-modes/dist/modes/interactive/interactive-mode-class-constants.d.ts.map +1 -1
  84. package/packages/gsd-agent-modes/dist/modes/interactive/interactive-mode-class-constants.js +1 -1
  85. package/packages/gsd-agent-modes/dist/modes/interactive/interactive-mode-class-constants.js.map +1 -1
  86. package/packages/gsd-agent-modes/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
  87. package/packages/gsd-agent-modes/dist/modes/interactive/interactive-mode.js +1 -0
  88. package/packages/gsd-agent-modes/dist/modes/interactive/interactive-mode.js.map +1 -1
  89. package/packages/gsd-agent-modes/dist/modes/interactive/interactive-selectors-settings.d.ts.map +1 -1
  90. package/packages/gsd-agent-modes/dist/modes/interactive/interactive-selectors-settings.js +5 -0
  91. package/packages/gsd-agent-modes/dist/modes/interactive/interactive-selectors-settings.js.map +1 -1
  92. package/packages/gsd-agent-modes/package.json +7 -7
  93. package/packages/mcp-server/dist/workflow-tools.d.ts.map +1 -1
  94. package/packages/mcp-server/dist/workflow-tools.js +82 -0
  95. package/packages/mcp-server/dist/workflow-tools.js.map +1 -1
  96. package/packages/mcp-server/package.json +3 -3
  97. package/packages/native/package.json +1 -1
  98. package/packages/pi-agent-core/package.json +1 -1
  99. package/packages/pi-ai/dist/image-models.generated.d.ts +15 -0
  100. package/packages/pi-ai/dist/image-models.generated.d.ts.map +1 -1
  101. package/packages/pi-ai/dist/image-models.generated.js +15 -0
  102. package/packages/pi-ai/dist/image-models.generated.js.map +1 -1
  103. package/packages/pi-ai/dist/models.generated.d.ts +35 -1
  104. package/packages/pi-ai/dist/models.generated.d.ts.map +1 -1
  105. package/packages/pi-ai/dist/models.generated.js +53 -19
  106. package/packages/pi-ai/dist/models.generated.js.map +1 -1
  107. package/packages/pi-ai/package.json +1 -1
  108. package/packages/pi-coding-agent/dist/core/settings-manager.d.ts +3 -0
  109. package/packages/pi-coding-agent/dist/core/settings-manager.d.ts.map +1 -1
  110. package/packages/pi-coding-agent/dist/core/settings-manager.js +11 -0
  111. package/packages/pi-coding-agent/dist/core/settings-manager.js.map +1 -1
  112. package/packages/pi-coding-agent/package.json +7 -7
  113. package/packages/pi-tui/dist/terminal.d.ts +1 -0
  114. package/packages/pi-tui/dist/terminal.d.ts.map +1 -1
  115. package/packages/pi-tui/dist/terminal.js +8 -4
  116. package/packages/pi-tui/dist/terminal.js.map +1 -1
  117. package/packages/pi-tui/package.json +1 -1
  118. package/packages/rpc-client/package.json +2 -2
  119. package/pkg/package.json +1 -1
  120. package/src/resources/extensions/gsd/auto/phases.ts +5 -3
  121. package/src/resources/extensions/gsd/auto-dashboard.ts +16 -4
  122. package/src/resources/extensions/gsd/auto-post-unit.ts +136 -5
  123. package/src/resources/extensions/gsd/auto-prompts.ts +9 -0
  124. package/src/resources/extensions/gsd/auto-start.ts +54 -14
  125. package/src/resources/extensions/gsd/auto-unit-tool-scope.ts +2 -1
  126. package/src/resources/extensions/gsd/auto.ts +3 -2
  127. package/src/resources/extensions/gsd/bootstrap/db-tools.ts +86 -0
  128. package/src/resources/extensions/gsd/bootstrap/exec-tools.ts +51 -0
  129. package/src/resources/extensions/gsd/bootstrap/register-hooks.ts +51 -14
  130. package/src/resources/extensions/gsd/bootstrap/write-gate.ts +21 -10
  131. package/src/resources/extensions/gsd/commands/handlers/core.ts +1 -1
  132. package/src/resources/extensions/gsd/commands-prefs-wizard.ts +4 -1
  133. package/src/resources/extensions/gsd/commands-verdict.ts +1 -1
  134. package/src/resources/extensions/gsd/config-overlay.ts +3 -1
  135. package/src/resources/extensions/gsd/error-classifier.ts +2 -1
  136. package/src/resources/extensions/gsd/exec-sandbox.ts +4 -0
  137. package/src/resources/extensions/gsd/preferences-types.ts +1 -1
  138. package/src/resources/extensions/gsd/prompts/run-uat.md +10 -4
  139. package/src/resources/extensions/gsd/prompts/system.md +3 -1
  140. package/src/resources/extensions/gsd/safety/destructive-guard.ts +3 -0
  141. package/src/resources/extensions/gsd/skill-activation.ts +20 -2
  142. package/src/resources/extensions/gsd/state-reconciliation/drift/roadmap.ts +20 -0
  143. package/src/resources/extensions/gsd/state-reconciliation/index.ts +6 -0
  144. package/src/resources/extensions/gsd/state-reconciliation/types.ts +1 -0
  145. package/src/resources/extensions/gsd/state.ts +1 -1
  146. package/src/resources/extensions/gsd/tests/auto-dashboard.test.ts +51 -0
  147. package/src/resources/extensions/gsd/tests/auto-start-orphan-bootstrap.test.ts +16 -3
  148. package/src/resources/extensions/gsd/tests/commands-dispatcher-validation-block.test.ts +38 -3
  149. package/src/resources/extensions/gsd/tests/commands-verdict.test.ts +6 -2
  150. package/src/resources/extensions/gsd/tests/derive-state-db.test.ts +8 -0
  151. package/src/resources/extensions/gsd/tests/derive-state-helpers.test.ts +8 -0
  152. package/src/resources/extensions/gsd/tests/exec-sandbox.test.ts +18 -0
  153. package/src/resources/extensions/gsd/tests/exec-tool.test.ts +69 -0
  154. package/src/resources/extensions/gsd/tests/parallel-skill-prompt-integration.test.ts +54 -7
  155. package/src/resources/extensions/gsd/tests/prompt-contracts.test.ts +10 -0
  156. package/src/resources/extensions/gsd/tests/provider-errors.test.ts +18 -1
  157. package/src/resources/extensions/gsd/tests/reactive-executor.test.ts +36 -0
  158. package/src/resources/extensions/gsd/tests/register-hooks-depth-verification.test.ts +35 -0
  159. package/src/resources/extensions/gsd/tests/restore-tools-after-discuss.test.ts +1 -1
  160. package/src/resources/extensions/gsd/tests/skill-activation.test.ts +55 -0
  161. package/src/resources/extensions/gsd/tests/state-reconciliation-drift.test.ts +52 -0
  162. package/src/resources/extensions/gsd/tests/token-tool-gating.test.ts +84 -10
  163. package/src/resources/extensions/gsd/tests/tool-naming.test.ts +12 -2
  164. package/src/resources/extensions/gsd/tests/tui-header-lifecycle.test.ts +29 -6
  165. package/src/resources/extensions/gsd/tests/unit-context-manifest.test.ts +29 -6
  166. package/src/resources/extensions/gsd/tests/validation-block-guard.test.ts +21 -0
  167. package/src/resources/extensions/gsd/tests/workflow-mcp-auto-prep.test.ts +2 -2
  168. package/src/resources/extensions/gsd/tests/workflow-tool-executors.test.ts +83 -0
  169. package/src/resources/extensions/gsd/tests/write-gate-planning-unit.test.ts +25 -0
  170. package/src/resources/extensions/gsd/tools/exec-tool.ts +130 -0
  171. package/src/resources/extensions/gsd/tools/workflow-tool-executors.ts +440 -2
  172. package/src/resources/extensions/gsd/unit-context-manifest.ts +14 -5
  173. package/src/resources/extensions/gsd/validation-block-guard.ts +2 -0
  174. package/src/resources/extensions/gsd/workflow-mcp-auto-prep.ts +1 -1
  175. package/src/resources/extensions/gsd/workflow-mcp.ts +5 -1
  176. /package/dist/web/standalone/.next/static/{xACmObbrDjwLriepRgaa9 → eRWf-RI9bzbrwEurm_3uI}/_buildManifest.js +0 -0
  177. /package/dist/web/standalone/.next/static/{xACmObbrDjwLriepRgaa9 → eRWf-RI9bzbrwEurm_3uI}/_ssgManifest.js +0 -0
@@ -1 +1 @@
1
- {"version":3,"file":"terminal.js","sourceRoot":"","sources":["../src/terminal.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAC9B,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAClC,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,sBAAsB,EAAE,MAAM,WAAW,CAAC;AACnD,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AACzD,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAEhD,MAAM,UAAU,GAAG,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAElD,MAAM,8BAA8B,GAAG,IAAI,CAAC;AAC5C,MAAM,iCAAiC,GAAG,gBAAgB,CAAC;AAC3D,MAAM,gCAAgC,GAAG,iBAAiB,CAAC;AAoD3D;;GAEG;AACH,MAAM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I,CAAC,gBAAgB,GAAG,WAAW,CAAC,GAAG,EAAE;oBACxC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,iCAAiC,CAAC,CAAC;gBACzD,CAAC,EAAE,8BAA8B,CAAC,CAAC;YACpC,CAAC;QACF,CAAC;aAAM,CAAC;YACP,IAAI,CAAC,qBAAqB,EAAE,CAAC;YAC7B,6BAA6B;YAC7B,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,gCAAgC,CAAC,CAAC;QACxD,CAAC;IACF,CAAC;IAEO,qBAAqB;QAC5B,IAAI,CAAC,IAAI,CAAC,gBAAgB;YAAE,OAAO,KAAK,CAAC;QACzC,aAAa,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAAC;QACrC,IAAI,CAAC,gBAAgB,GAAG,SAAS,CAAC;QAClC,OAAO,IAAI,CAAC;IACb,CAAC;CACD","sourcesContent":["import * as fs from \"node:fs\";\nimport { createRequire } from \"node:module\";\nimport * as path from \"node:path\";\nimport { fileURLToPath } from \"node:url\";\nimport { setKittyProtocolActive } from \"./keys.js\";\nimport { DISABLE_MOUSE, ENABLE_MOUSE } from \"./mouse.js\";\nimport { StdinBuffer } from \"./stdin-buffer.js\";\n\nconst cjsRequire = createRequire(import.meta.url);\n\nconst TERMINAL_PROGRESS_KEEPALIVE_MS = 1000;\nconst TERMINAL_PROGRESS_ACTIVE_SEQUENCE = \"\\x1b]9;4;3\\x07\";\nconst TERMINAL_PROGRESS_CLEAR_SEQUENCE = \"\\x1b]9;4;0;\\x07\";\n\n/**\n * Minimal terminal interface for TUI\n */\nexport interface Terminal {\n\t// Whether the terminal is interactive\n\treadonly isTTY: boolean;\n\n\t// Start the terminal with input and resize handlers\n\tstart(onInput: (data: string) => void, onResize: () => void): void;\n\n\t// Stop the terminal and restore state\n\tstop(): void;\n\n\t/**\n\t * Drain stdin before exiting to prevent Kitty key release events from\n\t * leaking to the parent shell over slow SSH connections.\n\t * @param maxMs - Maximum time to drain (default: 1000ms)\n\t * @param idleMs - Exit early if no input arrives within this time (default: 50ms)\n\t */\n\tdrainInput(maxMs?: number, idleMs?: number): Promise<void>;\n\n\t// Write output to terminal\n\twrite(data: string): void;\n\n\t// Get terminal dimensions\n\tget columns(): number;\n\tget rows(): number;\n\n\t// Whether Kitty keyboard protocol is active\n\tget kittyProtocolActive(): boolean;\n\n\t// Cursor positioning (relative to current position)\n\tmoveBy(lines: number): void; // Move cursor up (negative) or down (positive) by N lines\n\n\t// Cursor visibility\n\thideCursor(): void; // Hide the cursor\n\tshowCursor(): void; // Show the cursor\n\n\t// Clear operations\n\tclearLine(): void; // Clear current line\n\tclearFromCursor(): void; // Clear from cursor to end of screen\n\tclearScreen(): void; // Clear entire screen and move cursor to (0,0)\n\n\t// Title operations\n\tsetTitle(title: string): void; // Set terminal window title\n\n\t// Progress indicator (OSC 9;4)\n\tsetProgress(active: boolean): void;\n}\n\n/**\n * Real terminal using process.stdin/stdout\n */\nexport class ProcessTerminal implements Terminal {\n\tprivate wasRaw = false;\n\tprivate inputHandler?: (data: string) => void;\n\tprivate resizeHandler?: () => void;\n\tprivate _kittyProtocolActive = false;\n\tprivate _modifyOtherKeysActive = false;\n\tprivate _mouseActive = false;\n\tprivate stdinBuffer?: StdinBuffer;\n\tprivate stdinDataHandler?: (data: string) => void;\n\tprivate progressInterval?: ReturnType<typeof setInterval>;\n\tprivate writeLogPath = (() => {\n\t\tconst env = process.env.PI_TUI_WRITE_LOG || \"\";\n\t\tif (!env) return \"\";\n\t\ttry {\n\t\t\tif (fs.statSync(env).isDirectory()) {\n\t\t\t\tconst now = new Date();\n\t\t\t\tconst ts = `${now.getFullYear()}-${String(now.getMonth() + 1).padStart(2, \"0\")}-${String(now.getDate()).padStart(2, \"0\")}_${String(now.getHours()).padStart(2, \"0\")}-${String(now.getMinutes()).padStart(2, \"0\")}-${String(now.getSeconds()).padStart(2, \"0\")}`;\n\t\t\t\treturn path.join(env, `tui-${ts}-${process.pid}.log`);\n\t\t\t}\n\t\t} catch {\n\t\t\t// Not an existing directory - use as-is (file path)\n\t\t}\n\t\treturn env;\n\t})();\n\n\tget kittyProtocolActive(): boolean {\n\t\treturn this._kittyProtocolActive;\n\t}\n\n\tget isTTY(): boolean {\n\t\treturn Boolean(process.stdout.isTTY);\n\t}\n\n\tstart(onInput: (data: string) => void, onResize: () => void): void {\n\t\t// Idempotency guard: if start() is called again without an intervening\n\t\t// stop() (e.g. a mis-paired suspend/resume cycle), detach any stale\n\t\t// listeners first so they don't accumulate on the long-lived\n\t\t// process.stdin/stdout and trip MaxListenersExceededWarning. No-op on a\n\t\t// fresh start since all handles are undefined.\n\t\tif (this.stdinDataHandler) {\n\t\t\tprocess.stdin.removeListener(\"data\", this.stdinDataHandler);\n\t\t\tthis.stdinDataHandler = undefined;\n\t\t}\n\t\tif (this.resizeHandler) {\n\t\t\tprocess.stdout.removeListener(\"resize\", this.resizeHandler);\n\t\t\tthis.resizeHandler = undefined;\n\t\t}\n\t\tif (this.stdinBuffer) {\n\t\t\tthis.stdinBuffer.destroy();\n\t\t\tthis.stdinBuffer = undefined;\n\t\t}\n\n\t\tif (!this.isTTY) {\n\t\t\tthis.inputHandler = onInput;\n\t\t\tthis.resizeHandler = onResize;\n\t\t\treturn;\n\t\t}\n\n\t\tthis.inputHandler = onInput;\n\t\tthis.resizeHandler = onResize;\n\n\t\t// Save previous state and enable raw mode\n\t\tthis.wasRaw = process.stdin.isRaw || false;\n\t\tif (process.stdin.setRawMode) {\n\t\t\tprocess.stdin.setRawMode(true);\n\t\t}\n\t\tprocess.stdin.setEncoding(\"utf8\");\n\t\tprocess.stdin.resume();\n\n\t\t// Enable bracketed paste mode - terminal will wrap pastes in \\x1b[200~ ... \\x1b[201~\n\t\tprocess.stdout.write(\"\\x1b[?2004h\");\n\n\t\t// Enable mouse reporting so clicks and the wheel reach the TUI. On by\n\t\t// default; set PI_TUI_MOUSE=0 to opt out (preserves native click-drag\n\t\t// text selection without holding Shift).\n\t\tif (process.env.PI_TUI_MOUSE !== \"0\") {\n\t\t\tprocess.stdout.write(ENABLE_MOUSE);\n\t\t\tthis._mouseActive = true;\n\t\t}\n\n\t\t// Set up resize handler immediately\n\t\tprocess.stdout.on(\"resize\", this.resizeHandler);\n\n\t\t// Refresh terminal dimensions - they may be stale after suspend/resume\n\t\t// (SIGWINCH is lost while process is stopped). Unix only.\n\t\tif (process.platform !== \"win32\") {\n\t\t\tprocess.kill(process.pid, \"SIGWINCH\");\n\t\t}\n\n\t\t// On Windows, enable ENABLE_VIRTUAL_TERMINAL_INPUT so the console sends\n\t\t// VT escape sequences (e.g. \\x1b[Z for Shift+Tab) instead of raw console\n\t\t// events that lose modifier information. Must run AFTER setRawMode(true)\n\t\t// since that resets console mode flags.\n\t\tthis.enableWindowsVTInput();\n\n\t\t// Query and enable Kitty keyboard protocol\n\t\t// The query handler intercepts input temporarily, then installs the user's handler\n\t\t// See: https://sw.kovidgoyal.net/kitty/keyboard-protocol/\n\t\tthis.queryAndEnableKittyProtocol();\n\t}\n\n\t/**\n\t * Set up StdinBuffer to split batched input into individual sequences.\n\t * This ensures components receive single events, making matchesKey/isKeyRelease work correctly.\n\t *\n\t * Also watches for Kitty protocol response and enables it when detected.\n\t * This is done here (after stdinBuffer parsing) rather than on raw stdin\n\t * to handle the case where the response arrives split across multiple events.\n\t */\n\tprivate setupStdinBuffer(): void {\n\t\tthis.stdinBuffer = new StdinBuffer({ timeout: 10 });\n\n\t\t// Kitty protocol response pattern: \\x1b[?<flags>u\n\t\tconst kittyResponsePattern = /^\\x1b\\[\\?(\\d+)u$/;\n\n\t\t// Forward individual sequences to the input handler\n\t\tthis.stdinBuffer.on(\"data\", (sequence) => {\n\t\t\t// Check for Kitty protocol response (only if not already enabled)\n\t\t\tif (!this._kittyProtocolActive) {\n\t\t\t\tconst match = sequence.match(kittyResponsePattern);\n\t\t\t\tif (match) {\n\t\t\t\t\tthis._kittyProtocolActive = true;\n\t\t\t\t\tsetKittyProtocolActive(true);\n\n\t\t\t\t\t// Enable Kitty keyboard protocol (push flags)\n\t\t\t\t\t// Flag 1 = disambiguate escape codes\n\t\t\t\t\t// Flag 2 = report event types (press/repeat/release)\n\t\t\t\t\t// Flag 4 = report alternate keys (shifted key, base layout key)\n\t\t\t\t\t// Base layout key enables shortcuts to work with non-Latin keyboard layouts\n\t\t\t\t\tprocess.stdout.write(\"\\x1b[>7u\");\n\t\t\t\t\treturn; // Don't forward protocol response to TUI\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (this.inputHandler) {\n\t\t\t\tthis.inputHandler(sequence);\n\t\t\t}\n\t\t});\n\n\t\t// Re-wrap paste content with bracketed paste markers for existing editor handling\n\t\tthis.stdinBuffer.on(\"paste\", (content) => {\n\t\t\tif (this.inputHandler) {\n\t\t\t\tthis.inputHandler(`\\x1b[200~${content}\\x1b[201~`);\n\t\t\t}\n\t\t});\n\n\t\t// Handler that pipes stdin data through the buffer\n\t\tthis.stdinDataHandler = (data: string) => {\n\t\t\tthis.stdinBuffer!.process(data);\n\t\t};\n\t}\n\n\t/**\n\t * Query terminal for Kitty keyboard protocol support and enable if available.\n\t *\n\t * Sends CSI ? u to query current flags. If terminal responds with CSI ? <flags> u,\n\t * it supports the protocol and we enable it with CSI > 1 u.\n\t *\n\t * If no Kitty response arrives shortly after startup, fall back to enabling\n\t * xterm modifyOtherKeys mode 2. This is needed for tmux, which can forward\n\t * modified enter keys as CSI-u when extended-keys is enabled, but may not\n\t * answer the Kitty protocol query.\n\t *\n\t * The response is detected in setupStdinBuffer's data handler, which properly\n\t * handles the case where the response arrives split across multiple stdin events.\n\t */\n\tprivate queryAndEnableKittyProtocol(): void {\n\t\tthis.setupStdinBuffer();\n\t\tprocess.stdin.on(\"data\", this.stdinDataHandler!);\n\t\tprocess.stdout.write(\"\\x1b[?u\");\n\t\tsetTimeout(() => {\n\t\t\tif (!this._kittyProtocolActive && !this._modifyOtherKeysActive) {\n\t\t\t\tprocess.stdout.write(\"\\x1b[>4;2m\");\n\t\t\t\tthis._modifyOtherKeysActive = true;\n\t\t\t}\n\t\t}, 150);\n\t}\n\n\t/**\n\t * On Windows, add ENABLE_VIRTUAL_TERMINAL_INPUT (0x0200) to the stdin\n\t * console handle so the terminal sends VT sequences for modified keys\n\t * (e.g. \\x1b[Z for Shift+Tab). Without this, libuv's ReadConsoleInputW\n\t * discards modifier state and Shift+Tab arrives as plain \\t.\n\t */\n\tprivate enableWindowsVTInput(): void {\n\t\tif (process.platform !== \"win32\") return;\n\t\ttry {\n\t\t\tconst arch = process.arch;\n\t\t\tif (arch !== \"x64\" && arch !== \"arm64\") return;\n\n\t\t\t// Dynamic require so non-Windows and bundled/browser paths never load the\n\t\t\t// native helper. In the npm package native/ is next to dist/; in compiled\n\t\t\t// binary archives native/ is copied next to the executable.\n\t\t\tconst moduleDir = path.dirname(fileURLToPath(import.meta.url));\n\t\t\tconst nativePath = path.join(\"native\", \"win32\", \"prebuilds\", `win32-${arch}`, \"win32-console-mode.node\");\n\t\t\tconst candidates = [\n\t\t\t\tpath.join(moduleDir, \"..\", nativePath),\n\t\t\t\tpath.join(moduleDir, nativePath),\n\t\t\t\tpath.join(path.dirname(process.execPath), nativePath),\n\t\t\t];\n\t\t\tfor (const modulePath of candidates) {\n\t\t\t\ttry {\n\t\t\t\t\tconst helper = cjsRequire(modulePath) as { enableVirtualTerminalInput?: () => boolean };\n\t\t\t\t\thelper.enableVirtualTerminalInput?.();\n\t\t\t\t\treturn;\n\t\t\t\t} catch {\n\t\t\t\t\t// Try the next possible packaging location.\n\t\t\t\t}\n\t\t\t}\n\t\t} catch {\n\t\t\t// Native helper not available — Shift+Tab won't be distinguishable from Tab.\n\t\t}\n\t}\n\n\tasync drainInput(maxMs = 1000, idleMs = 50): Promise<void> {\n\t\tif (this._kittyProtocolActive) {\n\t\t\t// Disable Kitty keyboard protocol first so any late key releases\n\t\t\t// do not generate new Kitty escape sequences.\n\t\t\tprocess.stdout.write(\"\\x1b[<u\");\n\t\t\tthis._kittyProtocolActive = false;\n\t\t\tsetKittyProtocolActive(false);\n\t\t}\n\t\tif (this._modifyOtherKeysActive) {\n\t\t\tprocess.stdout.write(\"\\x1b[>4;0m\");\n\t\t\tthis._modifyOtherKeysActive = false;\n\t\t}\n\t\tif (this._mouseActive) {\n\t\t\tprocess.stdout.write(DISABLE_MOUSE);\n\t\t\tthis._mouseActive = false;\n\t\t}\n\n\t\tconst previousHandler = this.inputHandler;\n\t\tthis.inputHandler = undefined;\n\n\t\tlet lastDataTime = Date.now();\n\t\tconst onData = () => {\n\t\t\tlastDataTime = Date.now();\n\t\t};\n\n\t\tprocess.stdin.on(\"data\", onData);\n\t\tconst endTime = Date.now() + maxMs;\n\n\t\ttry {\n\t\t\twhile (true) {\n\t\t\t\tconst now = Date.now();\n\t\t\t\tconst timeLeft = endTime - now;\n\t\t\t\tif (timeLeft <= 0) break;\n\t\t\t\tif (now - lastDataTime >= idleMs) break;\n\t\t\t\tawait new Promise((resolve) => setTimeout(resolve, Math.min(idleMs, timeLeft)));\n\t\t\t}\n\t\t} finally {\n\t\t\tprocess.stdin.removeListener(\"data\", onData);\n\t\t\tthis.inputHandler = previousHandler;\n\t\t}\n\t}\n\n\tstop(): void {\n\t\tif (this.clearProgressInterval()) {\n\t\t\tprocess.stdout.write(TERMINAL_PROGRESS_CLEAR_SEQUENCE);\n\t\t}\n\n\t\t// Disable bracketed paste mode\n\t\tprocess.stdout.write(\"\\x1b[?2004l\");\n\n\t\t// Disable mouse reporting if not already done by drainInput()\n\t\tif (this._mouseActive) {\n\t\t\tprocess.stdout.write(DISABLE_MOUSE);\n\t\t\tthis._mouseActive = false;\n\t\t}\n\n\t\t// Disable Kitty keyboard protocol if not already done by drainInput()\n\t\tif (this._kittyProtocolActive) {\n\t\t\tprocess.stdout.write(\"\\x1b[<u\");\n\t\t\tthis._kittyProtocolActive = false;\n\t\t\tsetKittyProtocolActive(false);\n\t\t}\n\t\tif (this._modifyOtherKeysActive) {\n\t\t\tprocess.stdout.write(\"\\x1b[>4;0m\");\n\t\t\tthis._modifyOtherKeysActive = false;\n\t\t}\n\n\t\t// Clean up StdinBuffer\n\t\tif (this.stdinBuffer) {\n\t\t\tthis.stdinBuffer.destroy();\n\t\t\tthis.stdinBuffer = undefined;\n\t\t}\n\n\t\t// Remove event handlers\n\t\tif (this.stdinDataHandler) {\n\t\t\tprocess.stdin.removeListener(\"data\", this.stdinDataHandler);\n\t\t\tthis.stdinDataHandler = undefined;\n\t\t}\n\t\tthis.inputHandler = undefined;\n\t\tif (this.resizeHandler) {\n\t\t\tprocess.stdout.removeListener(\"resize\", this.resizeHandler);\n\t\t\tthis.resizeHandler = undefined;\n\t\t}\n\n\t\t// Pause stdin to prevent any buffered input (e.g., Ctrl+D) from being\n\t\t// re-interpreted after raw mode is disabled. This fixes a race condition\n\t\t// where Ctrl+D could close the parent shell over SSH.\n\t\tprocess.stdin.pause();\n\n\t\t// Restore raw mode state\n\t\tif (process.stdin.setRawMode) {\n\t\t\tprocess.stdin.setRawMode(this.wasRaw);\n\t\t}\n\t}\n\n\twrite(data: string): void {\n\t\tprocess.stdout.write(data);\n\t\tif (this.writeLogPath) {\n\t\t\ttry {\n\t\t\t\tfs.appendFileSync(this.writeLogPath, data, { encoding: \"utf8\" });\n\t\t\t} catch {\n\t\t\t\t// Ignore logging errors\n\t\t\t}\n\t\t}\n\t}\n\n\tget columns(): number {\n\t\treturn process.stdout.columns || Number(process.env.COLUMNS) || 80;\n\t}\n\n\tget rows(): number {\n\t\treturn process.stdout.rows || Number(process.env.LINES) || 24;\n\t}\n\n\tmoveBy(lines: number): void {\n\t\tif (lines > 0) {\n\t\t\t// Move down\n\t\t\tprocess.stdout.write(`\\x1b[${lines}B`);\n\t\t} else if (lines < 0) {\n\t\t\t// Move up\n\t\t\tprocess.stdout.write(`\\x1b[${-lines}A`);\n\t\t}\n\t\t// lines === 0: no movement\n\t}\n\n\thideCursor(): void {\n\t\tprocess.stdout.write(\"\\x1b[?25l\");\n\t}\n\n\tshowCursor(): void {\n\t\tprocess.stdout.write(\"\\x1b[?25h\");\n\t}\n\n\tclearLine(): void {\n\t\tprocess.stdout.write(\"\\x1b[K\");\n\t}\n\n\tclearFromCursor(): void {\n\t\tprocess.stdout.write(\"\\x1b[J\");\n\t}\n\n\tclearScreen(): void {\n\t\tprocess.stdout.write(\"\\x1b[2J\\x1b[H\"); // Clear screen and move to home (1,1)\n\t}\n\n\tsetTitle(title: string): void {\n\t\t// OSC 0;title BEL - set terminal window title\n\t\tprocess.stdout.write(`\\x1b]0;${title}\\x07`);\n\t}\n\n\tsetProgress(active: boolean): void {\n\t\tif (active) {\n\t\t\t// OSC 9;4;3 - indeterminate progress\n\t\t\tprocess.stdout.write(TERMINAL_PROGRESS_ACTIVE_SEQUENCE);\n\t\t\tif (!this.progressInterval) {\n\t\t\t\tthis.progressInterval = setInterval(() => {\n\t\t\t\t\tprocess.stdout.write(TERMINAL_PROGRESS_ACTIVE_SEQUENCE);\n\t\t\t\t}, TERMINAL_PROGRESS_KEEPALIVE_MS);\n\t\t\t}\n\t\t} else {\n\t\t\tthis.clearProgressInterval();\n\t\t\t// OSC 9;4;0 - clear progress\n\t\t\tprocess.stdout.write(TERMINAL_PROGRESS_CLEAR_SEQUENCE);\n\t\t}\n\t}\n\n\tprivate clearProgressInterval(): boolean {\n\t\tif (!this.progressInterval) return false;\n\t\tclearInterval(this.progressInterval);\n\t\tthis.progressInterval = undefined;\n\t\treturn true;\n\t}\n}\n"]}
1
+ {"version":3,"file":"terminal.js","sourceRoot":"","sources":["../src/terminal.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAC9B,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAClC,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,sBAAsB,EAAE,MAAM,WAAW,CAAC;AACnD,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AACz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AAC,KAAK,CAAC,eAAe,CAAC,CAAC,CAAC,sCAAsC;IAC9E,CAAC;IAED,QAAQ,CAAC,KAAa;QACrB,8CAA8C;QAC9C,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,UAAU,KAAK,MAAM,CAAC,CAAC;IAC7C,CAAC;IAED,WAAW,CAAC,MAAe;QAC1B,IAAI,MAAM,EAAE,CAAC;YACZ,qCAAqC;YACrC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,iCAAiC,CAAC,CAAC;YACxD,IAAI,CAAC,IAAI,CAAC,gBAAgB,EAAE,CAAC;gBAC5B,IAAI,CAAC,gBAAgB,GAAG,WAAW,CAAC,GAAG,EAAE;oBACxC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,iCAAiC,CAAC,CAAC;gBACzD,CAAC,EAAE,8BAA8B,CAAC,CAAC;YACpC,CAAC;QACF,CAAC;aAAM,CAAC;YACP,IAAI,CAAC,qBAAqB,EAAE,CAAC;YAC7B,6BAA6B;YAC7B,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,gCAAgC,CAAC,CAAC;QACxD,CAAC;IACF,CAAC;IAEO,qBAAqB;QAC5B,IAAI,CAAC,IAAI,CAAC,gBAAgB;YAAE,OAAO,KAAK,CAAC;QACzC,aAAa,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAAC;QACrC,IAAI,CAAC,gBAAgB,GAAG,SAAS,CAAC;QAClC,OAAO,IAAI,CAAC;IACb,CAAC;CACD","sourcesContent":["import * as fs from \"node:fs\";\nimport { createRequire } from \"node:module\";\nimport * as path from \"node:path\";\nimport { fileURLToPath } from \"node:url\";\nimport { setKittyProtocolActive } from \"./keys.js\";\nimport { DISABLE_MOUSE, ENABLE_MOUSE } from \"./mouse.js\";\nimport { StdinBuffer } from \"./stdin-buffer.js\";\n\nconst cjsRequire = createRequire(import.meta.url);\n\nconst TERMINAL_PROGRESS_KEEPALIVE_MS = 1000;\nconst TERMINAL_PROGRESS_ACTIVE_SEQUENCE = \"\\x1b]9;4;3\\x07\";\nconst TERMINAL_PROGRESS_CLEAR_SEQUENCE = \"\\x1b]9;4;0;\\x07\";\n\nexport function shouldEnableMouseReporting(env: NodeJS.ProcessEnv = process.env): boolean {\n\treturn env.PI_TUI_MOUSE === \"1\";\n}\n\n/**\n * Minimal terminal interface for TUI\n */\nexport interface Terminal {\n\t// Whether the terminal is interactive\n\treadonly isTTY: boolean;\n\n\t// Start the terminal with input and resize handlers\n\tstart(onInput: (data: string) => void, onResize: () => void): void;\n\n\t// Stop the terminal and restore state\n\tstop(): void;\n\n\t/**\n\t * Drain stdin before exiting to prevent Kitty key release events from\n\t * leaking to the parent shell over slow SSH connections.\n\t * @param maxMs - Maximum time to drain (default: 1000ms)\n\t * @param idleMs - Exit early if no input arrives within this time (default: 50ms)\n\t */\n\tdrainInput(maxMs?: number, idleMs?: number): Promise<void>;\n\n\t// Write output to terminal\n\twrite(data: string): void;\n\n\t// Get terminal dimensions\n\tget columns(): number;\n\tget rows(): number;\n\n\t// Whether Kitty keyboard protocol is active\n\tget kittyProtocolActive(): boolean;\n\n\t// Cursor positioning (relative to current position)\n\tmoveBy(lines: number): void; // Move cursor up (negative) or down (positive) by N lines\n\n\t// Cursor visibility\n\thideCursor(): void; // Hide the cursor\n\tshowCursor(): void; // Show the cursor\n\n\t// Clear operations\n\tclearLine(): void; // Clear current line\n\tclearFromCursor(): void; // Clear from cursor to end of screen\n\tclearScreen(): void; // Clear entire screen and move cursor to (0,0)\n\n\t// Title operations\n\tsetTitle(title: string): void; // Set terminal window title\n\n\t// Progress indicator (OSC 9;4)\n\tsetProgress(active: boolean): void;\n}\n\n/**\n * Real terminal using process.stdin/stdout\n */\nexport class ProcessTerminal implements Terminal {\n\tprivate wasRaw = false;\n\tprivate inputHandler?: (data: string) => void;\n\tprivate resizeHandler?: () => void;\n\tprivate _kittyProtocolActive = false;\n\tprivate _modifyOtherKeysActive = false;\n\tprivate _mouseActive = false;\n\tprivate stdinBuffer?: StdinBuffer;\n\tprivate stdinDataHandler?: (data: string) => void;\n\tprivate progressInterval?: ReturnType<typeof setInterval>;\n\tprivate writeLogPath = (() => {\n\t\tconst env = process.env.PI_TUI_WRITE_LOG || \"\";\n\t\tif (!env) return \"\";\n\t\ttry {\n\t\t\tif (fs.statSync(env).isDirectory()) {\n\t\t\t\tconst now = new Date();\n\t\t\t\tconst ts = `${now.getFullYear()}-${String(now.getMonth() + 1).padStart(2, \"0\")}-${String(now.getDate()).padStart(2, \"0\")}_${String(now.getHours()).padStart(2, \"0\")}-${String(now.getMinutes()).padStart(2, \"0\")}-${String(now.getSeconds()).padStart(2, \"0\")}`;\n\t\t\t\treturn path.join(env, `tui-${ts}-${process.pid}.log`);\n\t\t\t}\n\t\t} catch {\n\t\t\t// Not an existing directory - use as-is (file path)\n\t\t}\n\t\treturn env;\n\t})();\n\n\tget kittyProtocolActive(): boolean {\n\t\treturn this._kittyProtocolActive;\n\t}\n\n\tget isTTY(): boolean {\n\t\treturn Boolean(process.stdout.isTTY);\n\t}\n\n\tstart(onInput: (data: string) => void, onResize: () => void): void {\n\t\t// Idempotency guard: if start() is called again without an intervening\n\t\t// stop() (e.g. a mis-paired suspend/resume cycle), detach any stale\n\t\t// listeners first so they don't accumulate on the long-lived\n\t\t// process.stdin/stdout and trip MaxListenersExceededWarning. No-op on a\n\t\t// fresh start since all handles are undefined.\n\t\tif (this.stdinDataHandler) {\n\t\t\tprocess.stdin.removeListener(\"data\", this.stdinDataHandler);\n\t\t\tthis.stdinDataHandler = undefined;\n\t\t}\n\t\tif (this.resizeHandler) {\n\t\t\tprocess.stdout.removeListener(\"resize\", this.resizeHandler);\n\t\t\tthis.resizeHandler = undefined;\n\t\t}\n\t\tif (this.stdinBuffer) {\n\t\t\tthis.stdinBuffer.destroy();\n\t\t\tthis.stdinBuffer = undefined;\n\t\t}\n\n\t\tif (!this.isTTY) {\n\t\t\tthis.inputHandler = onInput;\n\t\t\tthis.resizeHandler = onResize;\n\t\t\treturn;\n\t\t}\n\n\t\tthis.inputHandler = onInput;\n\t\tthis.resizeHandler = onResize;\n\n\t\t// Save previous state and enable raw mode\n\t\tthis.wasRaw = process.stdin.isRaw || false;\n\t\tif (process.stdin.setRawMode) {\n\t\t\tprocess.stdin.setRawMode(true);\n\t\t}\n\t\tprocess.stdin.setEncoding(\"utf8\");\n\t\tprocess.stdin.resume();\n\n\t\t// Enable bracketed paste mode - terminal will wrap pastes in \\x1b[200~ ... \\x1b[201~\n\t\tprocess.stdout.write(\"\\x1b[?2004h\");\n\n\t\t// Mouse reporting lets clicks and the wheel reach the TUI, but terminal\n\t\t// mouse capture prevents native click-drag text selection in most\n\t\t// emulators. Keep native selection as the default; set PI_TUI_MOUSE=1 to\n\t\t// opt into mouse reporting.\n\t\tif (shouldEnableMouseReporting()) {\n\t\t\tprocess.stdout.write(ENABLE_MOUSE);\n\t\t\tthis._mouseActive = true;\n\t\t}\n\n\t\t// Set up resize handler immediately\n\t\tprocess.stdout.on(\"resize\", this.resizeHandler);\n\n\t\t// Refresh terminal dimensions - they may be stale after suspend/resume\n\t\t// (SIGWINCH is lost while process is stopped). Unix only.\n\t\tif (process.platform !== \"win32\") {\n\t\t\tprocess.kill(process.pid, \"SIGWINCH\");\n\t\t}\n\n\t\t// On Windows, enable ENABLE_VIRTUAL_TERMINAL_INPUT so the console sends\n\t\t// VT escape sequences (e.g. \\x1b[Z for Shift+Tab) instead of raw console\n\t\t// events that lose modifier information. Must run AFTER setRawMode(true)\n\t\t// since that resets console mode flags.\n\t\tthis.enableWindowsVTInput();\n\n\t\t// Query and enable Kitty keyboard protocol\n\t\t// The query handler intercepts input temporarily, then installs the user's handler\n\t\t// See: https://sw.kovidgoyal.net/kitty/keyboard-protocol/\n\t\tthis.queryAndEnableKittyProtocol();\n\t}\n\n\t/**\n\t * Set up StdinBuffer to split batched input into individual sequences.\n\t * This ensures components receive single events, making matchesKey/isKeyRelease work correctly.\n\t *\n\t * Also watches for Kitty protocol response and enables it when detected.\n\t * This is done here (after stdinBuffer parsing) rather than on raw stdin\n\t * to handle the case where the response arrives split across multiple events.\n\t */\n\tprivate setupStdinBuffer(): void {\n\t\tthis.stdinBuffer = new StdinBuffer({ timeout: 10 });\n\n\t\t// Kitty protocol response pattern: \\x1b[?<flags>u\n\t\tconst kittyResponsePattern = /^\\x1b\\[\\?(\\d+)u$/;\n\n\t\t// Forward individual sequences to the input handler\n\t\tthis.stdinBuffer.on(\"data\", (sequence) => {\n\t\t\t// Check for Kitty protocol response (only if not already enabled)\n\t\t\tif (!this._kittyProtocolActive) {\n\t\t\t\tconst match = sequence.match(kittyResponsePattern);\n\t\t\t\tif (match) {\n\t\t\t\t\tthis._kittyProtocolActive = true;\n\t\t\t\t\tsetKittyProtocolActive(true);\n\n\t\t\t\t\t// Enable Kitty keyboard protocol (push flags)\n\t\t\t\t\t// Flag 1 = disambiguate escape codes\n\t\t\t\t\t// Flag 2 = report event types (press/repeat/release)\n\t\t\t\t\t// Flag 4 = report alternate keys (shifted key, base layout key)\n\t\t\t\t\t// Base layout key enables shortcuts to work with non-Latin keyboard layouts\n\t\t\t\t\tprocess.stdout.write(\"\\x1b[>7u\");\n\t\t\t\t\treturn; // Don't forward protocol response to TUI\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (this.inputHandler) {\n\t\t\t\tthis.inputHandler(sequence);\n\t\t\t}\n\t\t});\n\n\t\t// Re-wrap paste content with bracketed paste markers for existing editor handling\n\t\tthis.stdinBuffer.on(\"paste\", (content) => {\n\t\t\tif (this.inputHandler) {\n\t\t\t\tthis.inputHandler(`\\x1b[200~${content}\\x1b[201~`);\n\t\t\t}\n\t\t});\n\n\t\t// Handler that pipes stdin data through the buffer\n\t\tthis.stdinDataHandler = (data: string) => {\n\t\t\tthis.stdinBuffer!.process(data);\n\t\t};\n\t}\n\n\t/**\n\t * Query terminal for Kitty keyboard protocol support and enable if available.\n\t *\n\t * Sends CSI ? u to query current flags. If terminal responds with CSI ? <flags> u,\n\t * it supports the protocol and we enable it with CSI > 1 u.\n\t *\n\t * If no Kitty response arrives shortly after startup, fall back to enabling\n\t * xterm modifyOtherKeys mode 2. This is needed for tmux, which can forward\n\t * modified enter keys as CSI-u when extended-keys is enabled, but may not\n\t * answer the Kitty protocol query.\n\t *\n\t * The response is detected in setupStdinBuffer's data handler, which properly\n\t * handles the case where the response arrives split across multiple stdin events.\n\t */\n\tprivate queryAndEnableKittyProtocol(): void {\n\t\tthis.setupStdinBuffer();\n\t\tprocess.stdin.on(\"data\", this.stdinDataHandler!);\n\t\tprocess.stdout.write(\"\\x1b[?u\");\n\t\tsetTimeout(() => {\n\t\t\tif (!this._kittyProtocolActive && !this._modifyOtherKeysActive) {\n\t\t\t\tprocess.stdout.write(\"\\x1b[>4;2m\");\n\t\t\t\tthis._modifyOtherKeysActive = true;\n\t\t\t}\n\t\t}, 150);\n\t}\n\n\t/**\n\t * On Windows, add ENABLE_VIRTUAL_TERMINAL_INPUT (0x0200) to the stdin\n\t * console handle so the terminal sends VT sequences for modified keys\n\t * (e.g. \\x1b[Z for Shift+Tab). Without this, libuv's ReadConsoleInputW\n\t * discards modifier state and Shift+Tab arrives as plain \\t.\n\t */\n\tprivate enableWindowsVTInput(): void {\n\t\tif (process.platform !== \"win32\") return;\n\t\ttry {\n\t\t\tconst arch = process.arch;\n\t\t\tif (arch !== \"x64\" && arch !== \"arm64\") return;\n\n\t\t\t// Dynamic require so non-Windows and bundled/browser paths never load the\n\t\t\t// native helper. In the npm package native/ is next to dist/; in compiled\n\t\t\t// binary archives native/ is copied next to the executable.\n\t\t\tconst moduleDir = path.dirname(fileURLToPath(import.meta.url));\n\t\t\tconst nativePath = path.join(\"native\", \"win32\", \"prebuilds\", `win32-${arch}`, \"win32-console-mode.node\");\n\t\t\tconst candidates = [\n\t\t\t\tpath.join(moduleDir, \"..\", nativePath),\n\t\t\t\tpath.join(moduleDir, nativePath),\n\t\t\t\tpath.join(path.dirname(process.execPath), nativePath),\n\t\t\t];\n\t\t\tfor (const modulePath of candidates) {\n\t\t\t\ttry {\n\t\t\t\t\tconst helper = cjsRequire(modulePath) as { enableVirtualTerminalInput?: () => boolean };\n\t\t\t\t\thelper.enableVirtualTerminalInput?.();\n\t\t\t\t\treturn;\n\t\t\t\t} catch {\n\t\t\t\t\t// Try the next possible packaging location.\n\t\t\t\t}\n\t\t\t}\n\t\t} catch {\n\t\t\t// Native helper not available — Shift+Tab won't be distinguishable from Tab.\n\t\t}\n\t}\n\n\tasync drainInput(maxMs = 1000, idleMs = 50): Promise<void> {\n\t\tif (this._kittyProtocolActive) {\n\t\t\t// Disable Kitty keyboard protocol first so any late key releases\n\t\t\t// do not generate new Kitty escape sequences.\n\t\t\tprocess.stdout.write(\"\\x1b[<u\");\n\t\t\tthis._kittyProtocolActive = false;\n\t\t\tsetKittyProtocolActive(false);\n\t\t}\n\t\tif (this._modifyOtherKeysActive) {\n\t\t\tprocess.stdout.write(\"\\x1b[>4;0m\");\n\t\t\tthis._modifyOtherKeysActive = false;\n\t\t}\n\t\tif (this._mouseActive) {\n\t\t\tprocess.stdout.write(DISABLE_MOUSE);\n\t\t\tthis._mouseActive = false;\n\t\t}\n\n\t\tconst previousHandler = this.inputHandler;\n\t\tthis.inputHandler = undefined;\n\n\t\tlet lastDataTime = Date.now();\n\t\tconst onData = () => {\n\t\t\tlastDataTime = Date.now();\n\t\t};\n\n\t\tprocess.stdin.on(\"data\", onData);\n\t\tconst endTime = Date.now() + maxMs;\n\n\t\ttry {\n\t\t\twhile (true) {\n\t\t\t\tconst now = Date.now();\n\t\t\t\tconst timeLeft = endTime - now;\n\t\t\t\tif (timeLeft <= 0) break;\n\t\t\t\tif (now - lastDataTime >= idleMs) break;\n\t\t\t\tawait new Promise((resolve) => setTimeout(resolve, Math.min(idleMs, timeLeft)));\n\t\t\t}\n\t\t} finally {\n\t\t\tprocess.stdin.removeListener(\"data\", onData);\n\t\t\tthis.inputHandler = previousHandler;\n\t\t}\n\t}\n\n\tstop(): void {\n\t\tif (this.clearProgressInterval()) {\n\t\t\tprocess.stdout.write(TERMINAL_PROGRESS_CLEAR_SEQUENCE);\n\t\t}\n\n\t\t// Disable bracketed paste mode\n\t\tprocess.stdout.write(\"\\x1b[?2004l\");\n\n\t\t// Disable mouse reporting if not already done by drainInput()\n\t\tif (this._mouseActive) {\n\t\t\tprocess.stdout.write(DISABLE_MOUSE);\n\t\t\tthis._mouseActive = false;\n\t\t}\n\n\t\t// Disable Kitty keyboard protocol if not already done by drainInput()\n\t\tif (this._kittyProtocolActive) {\n\t\t\tprocess.stdout.write(\"\\x1b[<u\");\n\t\t\tthis._kittyProtocolActive = false;\n\t\t\tsetKittyProtocolActive(false);\n\t\t}\n\t\tif (this._modifyOtherKeysActive) {\n\t\t\tprocess.stdout.write(\"\\x1b[>4;0m\");\n\t\t\tthis._modifyOtherKeysActive = false;\n\t\t}\n\n\t\t// Clean up StdinBuffer\n\t\tif (this.stdinBuffer) {\n\t\t\tthis.stdinBuffer.destroy();\n\t\t\tthis.stdinBuffer = undefined;\n\t\t}\n\n\t\t// Remove event handlers\n\t\tif (this.stdinDataHandler) {\n\t\t\tprocess.stdin.removeListener(\"data\", this.stdinDataHandler);\n\t\t\tthis.stdinDataHandler = undefined;\n\t\t}\n\t\tthis.inputHandler = undefined;\n\t\tif (this.resizeHandler) {\n\t\t\tprocess.stdout.removeListener(\"resize\", this.resizeHandler);\n\t\t\tthis.resizeHandler = undefined;\n\t\t}\n\n\t\t// Pause stdin to prevent any buffered input (e.g., Ctrl+D) from being\n\t\t// re-interpreted after raw mode is disabled. This fixes a race condition\n\t\t// where Ctrl+D could close the parent shell over SSH.\n\t\tprocess.stdin.pause();\n\n\t\t// Restore raw mode state\n\t\tif (process.stdin.setRawMode) {\n\t\t\tprocess.stdin.setRawMode(this.wasRaw);\n\t\t}\n\t}\n\n\twrite(data: string): void {\n\t\tprocess.stdout.write(data);\n\t\tif (this.writeLogPath) {\n\t\t\ttry {\n\t\t\t\tfs.appendFileSync(this.writeLogPath, data, { encoding: \"utf8\" });\n\t\t\t} catch {\n\t\t\t\t// Ignore logging errors\n\t\t\t}\n\t\t}\n\t}\n\n\tget columns(): number {\n\t\treturn process.stdout.columns || Number(process.env.COLUMNS) || 80;\n\t}\n\n\tget rows(): number {\n\t\treturn process.stdout.rows || Number(process.env.LINES) || 24;\n\t}\n\n\tmoveBy(lines: number): void {\n\t\tif (lines > 0) {\n\t\t\t// Move down\n\t\t\tprocess.stdout.write(`\\x1b[${lines}B`);\n\t\t} else if (lines < 0) {\n\t\t\t// Move up\n\t\t\tprocess.stdout.write(`\\x1b[${-lines}A`);\n\t\t}\n\t\t// lines === 0: no movement\n\t}\n\n\thideCursor(): void {\n\t\tprocess.stdout.write(\"\\x1b[?25l\");\n\t}\n\n\tshowCursor(): void {\n\t\tprocess.stdout.write(\"\\x1b[?25h\");\n\t}\n\n\tclearLine(): void {\n\t\tprocess.stdout.write(\"\\x1b[K\");\n\t}\n\n\tclearFromCursor(): void {\n\t\tprocess.stdout.write(\"\\x1b[J\");\n\t}\n\n\tclearScreen(): void {\n\t\tprocess.stdout.write(\"\\x1b[2J\\x1b[H\"); // Clear screen and move to home (1,1)\n\t}\n\n\tsetTitle(title: string): void {\n\t\t// OSC 0;title BEL - set terminal window title\n\t\tprocess.stdout.write(`\\x1b]0;${title}\\x07`);\n\t}\n\n\tsetProgress(active: boolean): void {\n\t\tif (active) {\n\t\t\t// OSC 9;4;3 - indeterminate progress\n\t\t\tprocess.stdout.write(TERMINAL_PROGRESS_ACTIVE_SEQUENCE);\n\t\t\tif (!this.progressInterval) {\n\t\t\t\tthis.progressInterval = setInterval(() => {\n\t\t\t\t\tprocess.stdout.write(TERMINAL_PROGRESS_ACTIVE_SEQUENCE);\n\t\t\t\t}, TERMINAL_PROGRESS_KEEPALIVE_MS);\n\t\t\t}\n\t\t} else {\n\t\t\tthis.clearProgressInterval();\n\t\t\t// OSC 9;4;0 - clear progress\n\t\t\tprocess.stdout.write(TERMINAL_PROGRESS_CLEAR_SEQUENCE);\n\t\t}\n\t}\n\n\tprivate clearProgressInterval(): boolean {\n\t\tif (!this.progressInterval) return false;\n\t\tclearInterval(this.progressInterval);\n\t\tthis.progressInterval = undefined;\n\t\treturn true;\n\t}\n}\n"]}
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gsd/pi-tui",
3
- "version": "1.1.1-dev.3ea310e",
3
+ "version": "1.1.1-dev.74e8dd1",
4
4
  "description": "Terminal UI library (vendored from earendil-works/pi)",
5
5
  "type": "module",
6
6
  "gsd": {
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opengsd/rpc-client",
3
- "version": "1.1.1-dev.3ea310e",
3
+ "version": "1.1.1-dev.74e8dd1",
4
4
  "description": "Standalone RPC client SDK for GSD — zero internal dependencies",
5
5
  "license": "MIT",
6
6
  "gsd": {
@@ -34,7 +34,7 @@
34
34
  "test": "node --test dist/rpc-client.test.js"
35
35
  },
36
36
  "dependencies": {
37
- "@opengsd/contracts": "^1.1.1-dev.3ea310e"
37
+ "@opengsd/contracts": "^1.1.1-dev.74e8dd1"
38
38
  },
39
39
  "engines": {
40
40
  "node": ">=22.0.0"
package/pkg/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@glittercowboy/gsd",
3
- "version": "1.1.1-dev.3ea310e",
3
+ "version": "1.1.1-dev.74e8dd1",
4
4
  "piConfig": {
5
5
  "name": "gsd",
6
6
  "configDir": ".gsd"
@@ -88,7 +88,7 @@ import { resolveManifest } from "../unit-context-manifest.js";
88
88
  import { createWorktreeSafetyModule, type WorktreeSafetyResult } from "../worktree-safety.js";
89
89
  import { isSuspiciousGhostCompletion } from "../auto-unit-closeout.js";
90
90
  import { decideVerificationRetry, verificationRetryKey } from "./verification-retry-policy.js";
91
- import { buildPhaseHandoffOutcome, setAutoOutcomeWidget } from "../auto-dashboard.js";
91
+ import { buildPhaseHandoffOutcome, setAutoActiveStatus, setAutoOutcomeWidget } from "../auto-dashboard.js";
92
92
  import { getConsecutiveDispatchBlocker } from "../dispatch-guard.js";
93
93
  import {
94
94
  captureRootDirtySnapshot,
@@ -100,7 +100,7 @@ import { classifyError, isTransient } from "../error-classifier.js";
100
100
  export const STUCK_WINDOW_SIZE = 6;
101
101
  const STUCK_RECOVERY_ATTEMPTS_KEY = "stuck_recovery_attempts";
102
102
  const ZERO_TOOL_PROVIDER_ERROR_PREFIX_RE =
103
- /^(?:api error(?::|$|\s*\()|provider error(?::|$|\s*\()|request failed\b|(?:http\s*)?(?:429|500|502|503)\b|\b(?:econnreset|etimedout|econnrefused|epipe)\b|socket hang up\b|fetch failed\b|(?:network|connection|server) error(?::|$)|connection (?:reset|refused)(?::|$|\s+by\b)|dns\b.*(?:fail|error|timeout)|unexpected eof\b|stream idle timeout\b|partial response received\b|stream_exhausted\b|terminated(?::|$)|(?:connection|stream|request)\b.{0,40}\bterminated\b|other side closed\b|rate.?limit(?:ed| exceeded| reached| error)|too many requests\b|you(?:'ve| have) hit your limit\b|usage limit\b|out of extra usage\b|service.?unavailable\b|internal(?: server)? error(?::|$)|internal(?:[_-]server)?[_-]error\b|server[_-]error\b|(?:provider|server|api|model|codex|claude|openai|anthropic|gemini)\b.{0,80}\boverloaded\b|overloaded\b.{0,80}\b(?:provider|server|api|model)\b|context (?:window|length) exceed|context window exceed)/i;
103
+ /^(?:api error(?::|$|\s*\()|provider error(?::|$|\s*\()|request failed\b|(?:http\s*)?(?:429|500|502|503)\b|\b(?:econnreset|etimedout|econnrefused|epipe)\b|socket hang up\b|fetch failed\b|(?:network|connection|server) error(?::|$)|connection (?:reset|refused)(?::|$|\s+by\b)|dns\b.*(?:fail|error|timeout)|unexpected eof\b|stream idle timeout\b|partial response received\b|stream_exhausted\b|terminated(?::|$)|(?:connection|stream|request)\b.{0,40}\bterminated\b|other side closed\b|rate.?limit(?:ed| exceeded| reached| error)|too many requests\b|you(?:'ve| have) (?:hit|reached) your (?:\w+ )?limit\b|.*\b(?:usage|session|weekly|daily|monthly|quota) limit\b|limit\b.{0,40}\bresets?\b|out of extra usage\b|service.?unavailable\b|internal(?: server)? error(?::|$)|internal(?:[_-]server)?[_-]error\b|server[_-]error\b|(?:provider|server|api|model|codex|claude|openai|anthropic|gemini)\b.{0,80}\boverloaded\b|overloaded\b.{0,80}\b(?:provider|server|api|model)\b|context (?:window|length) exceed|context window exceed)/i;
104
104
  const ZERO_TOOL_PROVIDER_ERROR_SIGNAL_RE =
105
105
  /(?:\b(?:http|status(?: code)?|code|error:)\s*(?:429|500|502|503)\b|\b(?:api|provider) error\s*[:(]?\s*(?:429|500|502|503)\b|\b(?:typeerror|error):\s*(?:fetch failed\b|socket hang up\b|terminated(?::|$)|connection (?:reset|refused)(?::|$|\s+by\b)|(?:network|connection|server) error(?::|$)|stream idle timeout\b|partial response received\b|unexpected eof\b)|\b(?:server_error|api_error|stream_exhausted(?:_without_result)?)\b|\b(?:econnreset|etimedout|econnrefused|epipe)\b|context (?:window|length) exceed|context window exceed)/i;
106
106
 
@@ -114,6 +114,8 @@ function classifyZeroToolProviderMessage(message: string): ReturnType<typeof cla
114
114
  return classifyError(firstLine);
115
115
  }
116
116
 
117
+ export const _classifyZeroToolProviderMessageForTest = classifyZeroToolProviderMessage;
118
+
117
119
  export function resolveDispatchRecoveryAttempts(
118
120
  unitRecoveryCount: Map<string, number>,
119
121
  unitType: string,
@@ -2092,7 +2094,7 @@ export async function runUnitPhase(
2092
2094
  const nextDispatchCount = (s.unitDispatchCount.get(dispatchKey) ?? 0) + 1;
2093
2095
 
2094
2096
  // Status bar (widget + preconditions deferred until after model selection — see #2899)
2095
- ctx.ui.setStatus("gsd-auto", s.stepMode ? "next" : "auto");
2097
+ setAutoActiveStatus(ctx, s.stepMode ? "next" : "auto");
2096
2098
  if (mid)
2097
2099
  deps.updateSliceProgressCache(s.basePath, mid, state.activeSlice?.id);
2098
2100
 
@@ -516,8 +516,9 @@ export const hideFooter = (_tui: unknown, theme: Theme, footerData: ReadonlyFoot
516
516
 
517
517
  /** Widget display modes: full → small → min → off → full */
518
518
  export type WidgetMode = "full" | "small" | "min" | "off";
519
+ export const DEFAULT_WIDGET_MODE: WidgetMode = "small";
519
520
  const WIDGET_MODES: WidgetMode[] = ["full", "small", "min", "off"];
520
- let widgetMode: WidgetMode = "full";
521
+ let widgetMode: WidgetMode = DEFAULT_WIDGET_MODE;
521
522
  let widgetModeInitialized = false;
522
523
  let widgetModePreferencePath: string | null = null;
523
524
 
@@ -628,7 +629,7 @@ export function getWidgetMode(projectPath?: string, globalPath?: string): Widget
628
629
 
629
630
  /** Test-only reset for widget mode caching. */
630
631
  export function _resetWidgetModeForTests(): void {
631
- widgetMode = "full";
632
+ widgetMode = DEFAULT_WIDGET_MODE;
632
633
  widgetModeInitialized = false;
633
634
  widgetModePreferencePath = null;
634
635
  }
@@ -648,6 +649,16 @@ export interface WidgetStateAccessors {
648
649
  getCurrentDispatchedModelId(): string | null;
649
650
  }
650
651
 
652
+ function clearAutoOutcomeWidget(ctx: ExtensionContext): void {
653
+ if (!ctx.hasUI) return;
654
+ ctx.ui.setWidget("gsd-outcome", undefined);
655
+ }
656
+
657
+ export function setAutoActiveStatus(ctx: ExtensionContext, status: "auto" | "next"): void {
658
+ ctx.ui.setStatus("gsd-auto", status);
659
+ clearAutoOutcomeWidget(ctx);
660
+ }
661
+
651
662
  export function updateProgressWidget(
652
663
  ctx: ExtensionContext,
653
664
  unitType: string,
@@ -673,7 +684,7 @@ export function updateProgressWidget(
673
684
  ctx.ui.setStatus("gsd-step", undefined);
674
685
  }
675
686
  if (!accessors.isSessionSwitching()) {
676
- ctx.ui.setWidget("gsd-outcome", undefined);
687
+ clearAutoOutcomeWidget(ctx);
677
688
  }
678
689
 
679
690
  const verb = unitVerb(unitType);
@@ -732,6 +743,7 @@ export function updateProgressWidget(
732
743
  logWarning("dashboard", `DB status update failed: ${err instanceof Error ? err.message : String(err)}`);
733
744
  }
734
745
  }, 15_000);
746
+ progressRefreshTimer.unref?.();
735
747
 
736
748
  return {
737
749
  render(width: number): string[] {
@@ -1003,7 +1015,7 @@ export function setCompletionProgressWidget(
1003
1015
  ): void {
1004
1016
  if (!ctx.hasUI) return;
1005
1017
  const widgetKey = "gsd-progress";
1006
- ctx.ui.setWidget("gsd-outcome", undefined);
1018
+ clearAutoOutcomeWidget(ctx);
1007
1019
 
1008
1020
  if (typeof ctx.ui?.setHeader === "function") {
1009
1021
  ctx.ui.setHeader(() => ({
@@ -394,6 +394,50 @@ function stripKnownIdPrefix(value: string | undefined | null, id: string): strin
394
394
  return raw;
395
395
  }
396
396
 
397
+ function parseReactiveBatchTaskIds(unitId: string): string[] {
398
+ const { task: batchPart } = parseUnitId(unitId);
399
+ if (!batchPart?.startsWith("reactive+")) return [];
400
+
401
+ const rawIds = batchPart
402
+ .slice("reactive+".length)
403
+ .split(",")
404
+ .map((taskId) => taskId.trim().toUpperCase())
405
+ .filter(Boolean);
406
+
407
+ const unique = new Set<string>();
408
+ for (const taskId of rawIds) {
409
+ unique.add(taskId);
410
+ }
411
+ return [...unique];
412
+ }
413
+
414
+ function dedupePaths(values: string[]): string[] {
415
+ const seen = new Set<string>();
416
+ const result: string[] = [];
417
+ for (const value of values) {
418
+ if (!seen.has(value)) {
419
+ seen.add(value);
420
+ result.push(value);
421
+ }
422
+ }
423
+ return result;
424
+ }
425
+
426
+ function getPlannedKeyFiles(tasks: Array<
427
+ { expected_output?: string[]; files?: string[]; key_files?: string[] }
428
+ >): string[] {
429
+ return dedupePaths(
430
+ tasks.flatMap((taskRow) => [
431
+ ...(taskRow.expected_output ?? []),
432
+ ...(taskRow.files ?? []),
433
+ ...(taskRow.key_files ?? []),
434
+ ]),
435
+ );
436
+ }
437
+
438
+ export const _parseReactiveBatchTaskIdsForTest = parseReactiveBatchTaskIds;
439
+ export const _getPlannedKeyFilesForTest = getPlannedKeyFiles;
440
+
397
441
  function resolveVerificationFailureMarkerPath(
398
442
  unitType: string,
399
443
  unitId: string,
@@ -481,6 +525,40 @@ async function buildTaskCommitContextForUnit(
481
525
  };
482
526
  }
483
527
 
528
+ async function buildReactiveTaskCommitContext(
529
+ _basePath: string,
530
+ unitId: string,
531
+ ): Promise<TaskCommitContext | undefined> {
532
+ const { milestone: mid, slice: sid } = parseUnitId(unitId);
533
+ if (!mid || !sid || !isDbAvailable()) return undefined;
534
+
535
+ const batchTaskIds = parseReactiveBatchTaskIds(unitId);
536
+ if (batchTaskIds.length === 0) return undefined;
537
+
538
+ const milestone = getMilestone(mid);
539
+ const slice = getSlice(mid, sid);
540
+ const taskRows = batchTaskIds
541
+ .map((tid) => getTask(mid, sid, tid))
542
+ .filter((taskRow): taskRow is NonNullable<ReturnType<typeof getTask>> => taskRow !== null);
543
+
544
+ const keyFiles = getPlannedKeyFiles(taskRows);
545
+ if (taskRows.length === 0 || keyFiles.length === 0) return undefined;
546
+
547
+ const taskLabel = taskRows.map((row) => row.id).join(",");
548
+
549
+ return {
550
+ taskId: `${sid}/${taskLabel}`,
551
+ taskDisplayId: "reactive-batch",
552
+ taskTitle: `Reactive batch: ${taskLabel}`,
553
+ milestoneId: mid,
554
+ milestoneTitle: stripKnownIdPrefix(milestone?.title, mid),
555
+ sliceId: sid,
556
+ sliceTitle: stripKnownIdPrefix(slice?.title, sid),
557
+ oneLiner: `Reactive execute for ${taskLabel}`,
558
+ keyFiles,
559
+ };
560
+ }
561
+
484
562
  async function runPostUnitGitHubSyncIfNeeded(
485
563
  basePath: string,
486
564
  unit: NonNullable<AutoSession["currentUnit"]>,
@@ -943,6 +1021,8 @@ export async function autoCommitUnit(
943
1021
 
944
1022
  if (unitType === "execute-task") {
945
1023
  taskContext = await buildTaskCommitContextForUnit(basePath, unitId);
1024
+ } else if (unitType === "reactive-execute") {
1025
+ taskContext = await buildReactiveTaskCommitContext(basePath, unitId);
946
1026
  }
947
1027
 
948
1028
  _resetHasChangesCache();
@@ -1005,6 +1085,21 @@ async function runCloseoutGitAction(
1005
1085
  if (mid && sid && tid && isDbAvailable()) {
1006
1086
  targetRepositories = getTask(mid, sid, tid)?.target_repositories;
1007
1087
  }
1088
+ } else if (turnAction === "commit" && unit.type === "reactive-execute") {
1089
+ taskContext = await buildReactiveTaskCommitContext(s.basePath, unit.id);
1090
+ const { milestone: mid, slice: sid } = parseUnitId(unit.id);
1091
+ if (mid && sid && isDbAvailable()) {
1092
+ const repositories = new Set<string>();
1093
+ for (const tid of parseReactiveBatchTaskIds(unit.id)) {
1094
+ const taskRow = getTask(mid, sid, tid);
1095
+ for (const repoId of taskRow?.target_repositories ?? []) {
1096
+ repositories.add(repoId);
1097
+ }
1098
+ }
1099
+ if (repositories.size > 0) {
1100
+ targetRepositories = [...repositories];
1101
+ }
1102
+ }
1008
1103
  }
1009
1104
 
1010
1105
  // Invalidate the nativeHasChanges cache before auto-commit (#1853).
@@ -1436,12 +1531,24 @@ export async function postUnitPreVerification(pctx: PostUnitContext, opts?: PreV
1436
1531
  const { milestone: sMid, slice: sSid, task: sTid } = parseUnitId(s.currentUnit.id);
1437
1532
 
1438
1533
  // File change validation (execute-task only, after unit execution)
1439
- if (safetyConfig.file_change_validation && s.currentUnit.type === "execute-task" && sMid && sSid && sTid && isDbAvailable()) {
1534
+ if (safetyConfig.file_change_validation && s.currentUnit.type === "execute-task" && sMid && sSid && sTid) {
1440
1535
  try {
1441
- const taskRow = getTask(sMid, sSid, sTid);
1442
- if (taskRow) {
1443
- const expectedOutput = taskRow.expected_output ?? [];
1444
- const plannedFiles = taskRow.files ?? [];
1536
+ const sliceTaskRows = isDbAvailable()
1537
+ ? getSliceTasks(sMid, sSid).filter((t) => isClosedStatus(t.status) || t.id === sTid)
1538
+ : [];
1539
+
1540
+ if (sliceTaskRows.length > 0) {
1541
+ const expectedOutput = getPlannedKeyFiles(
1542
+ sliceTaskRows.map((taskRow) => ({
1543
+ expected_output: taskRow.expected_output,
1544
+ files: taskRow.files,
1545
+ })),
1546
+ );
1547
+ const plannedFiles = getPlannedKeyFiles(
1548
+ sliceTaskRows.map((taskRow) => ({
1549
+ files: taskRow.files,
1550
+ })),
1551
+ );
1445
1552
  const audit = validateFileChanges(s.basePath, expectedOutput, plannedFiles, safetyConfig.file_change_allowlist);
1446
1553
  if (audit && audit.violations.length > 0) {
1447
1554
  const warnings = audit.violations.filter(v => v.severity === "warning");
@@ -1455,6 +1562,30 @@ export async function postUnitPreVerification(pctx: PostUnitContext, opts?: PreV
1455
1562
  );
1456
1563
  }
1457
1564
  }
1565
+ } else {
1566
+ const taskRow = getTask(sMid, sSid, sTid);
1567
+ if (taskRow) {
1568
+ const expectedOutput = taskRow.expected_output ?? [];
1569
+ const plannedFiles = taskRow.files ?? [];
1570
+ const audit = validateFileChanges(
1571
+ s.basePath,
1572
+ expectedOutput,
1573
+ plannedFiles,
1574
+ safetyConfig.file_change_allowlist,
1575
+ );
1576
+ if (audit && audit.violations.length > 0) {
1577
+ const warnings = audit.violations.filter(v => v.severity === "warning");
1578
+ for (const v of warnings) {
1579
+ logWarning("safety", `file-change: ${v.file} — ${v.reason}`);
1580
+ }
1581
+ if (warnings.length > 0) {
1582
+ ctx.ui.notify(
1583
+ `Safety: ${warnings.length} unexpected file change(s) outside task plan`,
1584
+ "warning",
1585
+ );
1586
+ }
1587
+ }
1588
+ }
1458
1589
  }
1459
1590
  } catch (e) {
1460
1591
  debugLog("postUnit", { phase: "safety-file-change", error: String(e) });
@@ -2711,6 +2711,15 @@ export async function buildCompleteSlicePrompt(
2711
2711
  sliceSummaryPath,
2712
2712
  sliceUatPath,
2713
2713
  gatesToClose,
2714
+ skillActivation: buildSkillActivationBlock({
2715
+ base,
2716
+ milestoneId: mid,
2717
+ milestoneTitle: midTitle,
2718
+ sliceId: sid,
2719
+ sliceTitle: sTitle,
2720
+ extraContext: [inlinedContext],
2721
+ unitType: "complete-slice",
2722
+ }),
2714
2723
  });
2715
2724
  }
2716
2725
 
@@ -101,6 +101,7 @@ import {
101
101
  } from "./preferences-models.js";
102
102
  import type { WorktreeLifecycle } from "./worktree-lifecycle.js";
103
103
  import { getSessionModelOverride } from "./session-model-override.js";
104
+ import { setAutoActiveStatus } from "./auto-dashboard.js";
104
105
 
105
106
  export interface BootstrapDeps {
106
107
  shouldUseWorktreeIsolation: (basePath?: string) => boolean;
@@ -293,6 +294,7 @@ export interface OrphanAuditAction {
293
294
  message: string;
294
295
  severity: "info" | "warning";
295
296
  branch?: string;
297
+ mainBranch?: string;
296
298
  commitsAhead?: number;
297
299
  dirtyWorktree?: boolean;
298
300
  worktreeDirExists?: boolean;
@@ -311,6 +313,27 @@ function isBlockingStrandedWorkAction(action: OrphanAuditAction): boolean {
311
313
  return action.kind === "in-progress-stranded-work" && action.blocksAuto;
312
314
  }
313
315
 
316
+ function strandedWorkEvidence(args: {
317
+ branch?: string;
318
+ commitsAhead: number;
319
+ mainBranch: string;
320
+ dirtyWorktree: boolean;
321
+ }): string[] {
322
+ const evidence: string[] = [];
323
+ if (args.branch && args.commitsAhead > 0) {
324
+ evidence.push(
325
+ `branch ${args.branch} has ${args.commitsAhead} commit(s) ahead of ${args.mainBranch}`,
326
+ );
327
+ }
328
+ if (args.dirtyWorktree) {
329
+ evidence.push("the worktree has uncommitted changes");
330
+ }
331
+ if (evidence.length === 0) {
332
+ evidence.push("physical git evidence exists");
333
+ }
334
+ return evidence;
335
+ }
336
+
314
337
  function detectWorktreeEvidence(
315
338
  basePath: string,
316
339
  milestoneId: string,
@@ -342,18 +365,7 @@ function strandedWorkMessage(args: {
342
365
  worktreeDirExists: boolean;
343
366
  recoveryMode: StrandedWorkRecoveryMode;
344
367
  }): string {
345
- const evidence: string[] = [];
346
- if (args.branch && args.commitsAhead > 0) {
347
- evidence.push(
348
- `branch ${args.branch} has ${args.commitsAhead} commit(s) ahead of ${args.mainBranch}`,
349
- );
350
- }
351
- if (args.dirtyWorktree) {
352
- evidence.push("the worktree has uncommitted changes");
353
- }
354
- if (evidence.length === 0) {
355
- evidence.push("physical git evidence exists");
356
- }
368
+ const evidence = strandedWorkEvidence(args);
357
369
 
358
370
  const wtSuffix = args.worktreeDirExists
359
371
  ? ` Worktree directory at .gsd/worktrees/${args.milestoneId}/ holds live work.`
@@ -369,6 +381,26 @@ function strandedWorkMessage(args: {
369
381
  );
370
382
  }
371
383
 
384
+ function formatStrandedWorkRecoveryMessage(action: OrphanAuditAction): string {
385
+ const recoveryMode = action.recoveryMode === "worktree"
386
+ ? "existing worktree"
387
+ : "milestone branch";
388
+ const evidence = strandedWorkEvidence({
389
+ branch: action.branch,
390
+ commitsAhead: action.commitsAhead ?? 0,
391
+ mainBranch: action.mainBranch ?? "main",
392
+ dirtyWorktree: action.dirtyWorktree ?? false,
393
+ });
394
+ const wtSuffix = action.worktreeDirExists
395
+ ? ` Worktree directory at .gsd/worktrees/${action.milestoneId}/ holds live work.`
396
+ : "";
397
+ return (
398
+ `Resuming saved milestone work for ${action.milestoneId}: ${evidence.join("; ")}.` +
399
+ wtSuffix +
400
+ ` Adopting the ${recoveryMode} before dispatching new units. Park or discard explicitly if abandoning.`
401
+ );
402
+ }
403
+
372
404
  function formatStrandedWorkBlockerMessage(
373
405
  action: OrphanAuditAction,
374
406
  activeMilestoneId: string | null,
@@ -489,6 +521,7 @@ export function auditOrphanedMilestoneBranches(
489
521
  kind: "in-progress-stranded-work",
490
522
  milestoneId,
491
523
  branch,
524
+ mainBranch,
492
525
  commitsAhead,
493
526
  dirtyWorktree: worktreeEvidence.dirty,
494
527
  worktreeDirExists: worktreeEvidence.dirExists,
@@ -643,6 +676,7 @@ export function auditOrphanedMilestoneBranches(
643
676
  pushAction({
644
677
  kind: "in-progress-stranded-work",
645
678
  milestoneId: m.id,
679
+ mainBranch,
646
680
  commitsAhead: 0,
647
681
  dirtyWorktree: true,
648
682
  worktreeDirExists: worktreeEvidence.dirExists,
@@ -1158,7 +1192,13 @@ export async function bootstrapAutoSession(
1158
1192
  for (const msg of auditResult.recovered) {
1159
1193
  ctx.ui.notify(`Orphan audit: ${msg}`, "info");
1160
1194
  }
1195
+ const deferredStrandedMessages = new Set(
1196
+ auditResult.actions
1197
+ .filter(isBlockingStrandedWorkAction)
1198
+ .map((action) => action.message),
1199
+ );
1161
1200
  for (const msg of auditResult.warnings) {
1201
+ if (deferredStrandedMessages.has(msg)) continue;
1162
1202
  const prefix = msg.startsWith("Stranded work") ? "" : "Orphan audit: ";
1163
1203
  ctx.ui.notify(`${prefix}${msg}`, "warning");
1164
1204
  }
@@ -1246,7 +1286,7 @@ export async function bootstrapAutoSession(
1246
1286
  }
1247
1287
  strandedRecoveryAction = blockingStrandedRecoveryAction;
1248
1288
  ctx.ui.notify(
1249
- `Recovering stranded work for ${strandedRecoveryAction.milestoneId} before dispatching new units.`,
1289
+ formatStrandedWorkRecoveryMessage(strandedRecoveryAction),
1250
1290
  "info",
1251
1291
  );
1252
1292
  }
@@ -1718,7 +1758,7 @@ export async function bootstrapAutoSession(
1718
1758
  snapshotSkills();
1719
1759
  }
1720
1760
 
1721
- ctx.ui.setStatus("gsd-auto", s.stepMode ? "next" : "auto");
1761
+ setAutoActiveStatus(ctx, s.stepMode ? "next" : "auto");
1722
1762
  ctx.ui.setWidget("gsd-health", undefined);
1723
1763
  const modeLabel = s.stepMode ? "Step-mode" : "Auto-mode";
1724
1764
  const pendingCount = (state.registry ?? []).filter(
@@ -1,4 +1,5 @@
1
1
  import { parseUnitId } from "./unit-id.js";
2
+ import { RUN_UAT_WORKFLOW_TOOL_NAMES } from "./tool-presentation-plan.js";
2
3
 
3
4
  export const RUN_UAT_BROWSER_TOOL_NAMES = [
4
5
  "browser_navigate",
@@ -44,7 +45,7 @@ export const AUTO_UNIT_SCOPED_TOOLS: Record<string, readonly string[]> = {
44
45
  "execute-task": ["gsd_task_complete", "gsd_decision_save"],
45
46
  "execute-task-simple": ["gsd_task_complete", "gsd_decision_save"],
46
47
  "reactive-execute": ["gsd_task_complete", "gsd_decision_save"],
47
- "run-uat": ["gsd_summary_save", ...RUN_UAT_BROWSER_TOOL_NAMES],
48
+ "run-uat": [...RUN_UAT_WORKFLOW_TOOL_NAMES, "subagent", ...RUN_UAT_BROWSER_TOOL_NAMES],
48
49
  "gate-evaluate": ["gsd_save_gate_result"],
49
50
  "rewrite-docs": ["gsd_summary_save", "gsd_decision_save"],
50
51
  "workflow-preferences": ["gsd_summary_save"],
@@ -205,6 +205,7 @@ import {
205
205
  updateProgressWidget as _updateProgressWidget,
206
206
  setCompletionProgressWidget,
207
207
  setAutoOutcomeWidget,
208
+ setAutoActiveStatus,
208
209
  updateSliceProgressCache,
209
210
  clearSliceProgressCache,
210
211
  describeNextUnit as _describeNextUnit,
@@ -3022,7 +3023,7 @@ export async function startAuto(
3022
3023
  ensureOrchestrationModule(ctx, pi, s.basePath || base);
3023
3024
  registerSigtermHandler(lockBase());
3024
3025
 
3025
- ctx.ui.setStatus("gsd-auto", s.stepMode ? "next" : "auto");
3026
+ setAutoActiveStatus(ctx, s.stepMode ? "next" : "auto");
3026
3027
  ctx.ui.setWidget("gsd-health", undefined);
3027
3028
  ctx.ui.notify(
3028
3029
  s.stepMode ? "Step-mode resumed." : "Auto-mode resumed.",
@@ -3351,7 +3352,7 @@ export async function dispatchHookUnit(
3351
3352
  await pauseAuto(ctx, pi);
3352
3353
  }, hookHardTimeoutMs);
3353
3354
 
3354
- ctx.ui.setStatus("gsd-auto", s.stepMode ? "next" : "auto");
3355
+ setAutoActiveStatus(ctx, s.stepMode ? "next" : "auto");
3355
3356
  ctx.ui.notify(`Running post-unit hook: ${hookName}`, "info");
3356
3357
 
3357
3358
  debugLog("dispatchHookUnit", {