@caupulican/pi-adaptative 0.84.1 → 0.85.3

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 (214) hide show
  1. package/CHANGELOG.md +53 -0
  2. package/dist/bundled-resources/extensions/tmux-agent-manager/index.d.ts.map +1 -1
  3. package/dist/bundled-resources/extensions/tmux-agent-manager/index.js +14 -8
  4. package/dist/bundled-resources/extensions/tmux-agent-manager/index.js.map +1 -1
  5. package/dist/bundled-resources/extensions/tmux-agent-manager/index.ts +14 -8
  6. package/dist/bundled-resources/runtimes/pi-shell-engine/arithmetic.py +364 -0
  7. package/dist/bundled-resources/runtimes/pi-shell-engine/context.py +2 -1
  8. package/dist/bundled-resources/runtimes/pi-shell-engine/errors.py +16 -0
  9. package/dist/bundled-resources/runtimes/pi-shell-engine/exec.py +137 -14
  10. package/dist/bundled-resources/runtimes/pi-shell-engine/nodes.py +23 -2
  11. package/dist/bundled-resources/runtimes/pi-shell-engine/parser.py +134 -6
  12. package/dist/bundled-resources/runtimes/pi-shell-engine/tokens.py +25 -2
  13. package/dist/bundled-resources/skills/deduplicate-by-evidence/SKILL.md +7 -5
  14. package/dist/bundled-resources/skills/worker-profile-writer/SKILL.md +63 -0
  15. package/dist/core/agent-session.d.ts.map +1 -1
  16. package/dist/core/agent-session.js +8 -0
  17. package/dist/core/agent-session.js.map +1 -1
  18. package/dist/core/autonomy/lane-tool-surface.d.ts.map +1 -1
  19. package/dist/core/autonomy/lane-tool-surface.js +4 -2
  20. package/dist/core/autonomy/lane-tool-surface.js.map +1 -1
  21. package/dist/core/background-lane-controller.d.ts +3 -0
  22. package/dist/core/background-lane-controller.d.ts.map +1 -1
  23. package/dist/core/background-lane-controller.js +6 -0
  24. package/dist/core/background-lane-controller.js.map +1 -1
  25. package/dist/core/compaction-controller.d.ts +2 -0
  26. package/dist/core/compaction-controller.d.ts.map +1 -1
  27. package/dist/core/compaction-controller.js +35 -13
  28. package/dist/core/compaction-controller.js.map +1 -1
  29. package/dist/core/default-tool-surface.d.ts.map +1 -1
  30. package/dist/core/default-tool-surface.js +1 -0
  31. package/dist/core/default-tool-surface.js.map +1 -1
  32. package/dist/core/delegation/worker-delegation-controller.d.ts +7 -0
  33. package/dist/core/delegation/worker-delegation-controller.d.ts.map +1 -1
  34. package/dist/core/delegation/worker-delegation-controller.js +28 -0
  35. package/dist/core/delegation/worker-delegation-controller.js.map +1 -1
  36. package/dist/core/delegation/worker-profile-resolver.d.ts +2 -0
  37. package/dist/core/delegation/worker-profile-resolver.d.ts.map +1 -1
  38. package/dist/core/delegation/worker-profile-resolver.js +46 -11
  39. package/dist/core/delegation/worker-profile-resolver.js.map +1 -1
  40. package/dist/core/doctor.d.ts +1 -1
  41. package/dist/core/doctor.d.ts.map +1 -1
  42. package/dist/core/doctor.js +5 -4
  43. package/dist/core/doctor.js.map +1 -1
  44. package/dist/core/failure-corpus.d.ts +26 -1
  45. package/dist/core/failure-corpus.d.ts.map +1 -1
  46. package/dist/core/failure-corpus.js +17 -0
  47. package/dist/core/failure-corpus.js.map +1 -1
  48. package/dist/core/model-capability.d.ts.map +1 -1
  49. package/dist/core/model-capability.js +1 -0
  50. package/dist/core/model-capability.js.map +1 -1
  51. package/dist/core/model-tool-protocol.d.ts +3 -2
  52. package/dist/core/model-tool-protocol.d.ts.map +1 -1
  53. package/dist/core/model-tool-protocol.js +5 -1
  54. package/dist/core/model-tool-protocol.js.map +1 -1
  55. package/dist/core/models/runtime-process.d.ts +7 -1
  56. package/dist/core/models/runtime-process.d.ts.map +1 -1
  57. package/dist/core/models/runtime-process.js +4 -2
  58. package/dist/core/models/runtime-process.js.map +1 -1
  59. package/dist/core/orchestration/lane-tool-manifests.d.ts +1 -1
  60. package/dist/core/orchestration/lane-tool-manifests.d.ts.map +1 -1
  61. package/dist/core/orchestration/lane-tool-manifests.js +6 -1
  62. package/dist/core/orchestration/lane-tool-manifests.js.map +1 -1
  63. package/dist/core/orchestration/session-task-profile-store.d.ts +31 -0
  64. package/dist/core/orchestration/session-task-profile-store.d.ts.map +1 -0
  65. package/dist/core/orchestration/session-task-profile-store.js +138 -0
  66. package/dist/core/orchestration/session-task-profile-store.js.map +1 -0
  67. package/dist/core/orchestration/task-profile-writer.d.ts +58 -0
  68. package/dist/core/orchestration/task-profile-writer.d.ts.map +1 -0
  69. package/dist/core/orchestration/task-profile-writer.js +165 -0
  70. package/dist/core/orchestration/task-profile-writer.js.map +1 -0
  71. package/dist/core/process-matrix/runtime.js +43 -11
  72. package/dist/core/process-matrix/runtime.js.map +1 -1
  73. package/dist/core/resource-loader.d.ts +2 -0
  74. package/dist/core/resource-loader.d.ts.map +1 -1
  75. package/dist/core/resource-loader.js +18 -6
  76. package/dist/core/resource-loader.js.map +1 -1
  77. package/dist/core/runtime-builder.d.ts +3 -1
  78. package/dist/core/runtime-builder.d.ts.map +1 -1
  79. package/dist/core/runtime-builder.js +14 -0
  80. package/dist/core/runtime-builder.js.map +1 -1
  81. package/dist/core/security/untrusted-boundary.d.ts.map +1 -1
  82. package/dist/core/security/untrusted-boundary.js +4 -6
  83. package/dist/core/security/untrusted-boundary.js.map +1 -1
  84. package/dist/core/session-role.d.ts.map +1 -1
  85. package/dist/core/session-role.js +1 -0
  86. package/dist/core/session-role.js.map +1 -1
  87. package/dist/core/system-prompt.d.ts.map +1 -1
  88. package/dist/core/system-prompt.js +21 -23
  89. package/dist/core/system-prompt.js.map +1 -1
  90. package/dist/core/tool-capability-policy.js +1 -1
  91. package/dist/core/tool-capability-policy.js.map +1 -1
  92. package/dist/core/tool-recovery-log-records.d.ts +33 -1
  93. package/dist/core/tool-recovery-log-records.d.ts.map +1 -1
  94. package/dist/core/tool-recovery-log-records.js +59 -12
  95. package/dist/core/tool-recovery-log-records.js.map +1 -1
  96. package/dist/core/tool-recovery-logger.d.ts +12 -1
  97. package/dist/core/tool-recovery-logger.d.ts.map +1 -1
  98. package/dist/core/tool-recovery-logger.js +24 -1
  99. package/dist/core/tool-recovery-logger.js.map +1 -1
  100. package/dist/core/tool-repair-health.d.ts.map +1 -1
  101. package/dist/core/tool-repair-health.js +6 -0
  102. package/dist/core/tool-repair-health.js.map +1 -1
  103. package/dist/core/tools/bash.d.ts +3 -8
  104. package/dist/core/tools/bash.d.ts.map +1 -1
  105. package/dist/core/tools/bash.js +4 -28
  106. package/dist/core/tools/bash.js.map +1 -1
  107. package/dist/core/tools/delegate.js +4 -4
  108. package/dist/core/tools/delegate.js.map +1 -1
  109. package/dist/core/tools/edit-diff.d.ts +32 -5
  110. package/dist/core/tools/edit-diff.d.ts.map +1 -1
  111. package/dist/core/tools/edit-diff.js +137 -69
  112. package/dist/core/tools/edit-diff.js.map +1 -1
  113. package/dist/core/tools/edit.d.ts +22 -7
  114. package/dist/core/tools/edit.d.ts.map +1 -1
  115. package/dist/core/tools/edit.js +128 -55
  116. package/dist/core/tools/edit.js.map +1 -1
  117. package/dist/core/tools/file-mutation-intent.d.ts +70 -0
  118. package/dist/core/tools/file-mutation-intent.d.ts.map +1 -0
  119. package/dist/core/tools/file-mutation-intent.js +325 -0
  120. package/dist/core/tools/file-mutation-intent.js.map +1 -0
  121. package/dist/core/tools/find.d.ts +2 -1
  122. package/dist/core/tools/find.d.ts.map +1 -1
  123. package/dist/core/tools/find.js +2 -6
  124. package/dist/core/tools/find.js.map +1 -1
  125. package/dist/core/tools/goal.d.ts.map +1 -1
  126. package/dist/core/tools/goal.js +41 -18
  127. package/dist/core/tools/goal.js.map +1 -1
  128. package/dist/core/tools/grep.d.ts +2 -1
  129. package/dist/core/tools/grep.d.ts.map +1 -1
  130. package/dist/core/tools/grep.js +2 -6
  131. package/dist/core/tools/grep.js.map +1 -1
  132. package/dist/core/tools/index.d.ts +3 -1
  133. package/dist/core/tools/index.d.ts.map +1 -1
  134. package/dist/core/tools/index.js +31 -8
  135. package/dist/core/tools/index.js.map +1 -1
  136. package/dist/core/tools/managed-search-tool.d.ts +8 -0
  137. package/dist/core/tools/managed-search-tool.d.ts.map +1 -0
  138. package/dist/core/tools/managed-search-tool.js +10 -0
  139. package/dist/core/tools/managed-search-tool.js.map +1 -0
  140. package/dist/core/tools/profile-writer.d.ts +33 -0
  141. package/dist/core/tools/profile-writer.d.ts.map +1 -0
  142. package/dist/core/tools/profile-writer.js +67 -0
  143. package/dist/core/tools/profile-writer.js.map +1 -0
  144. package/dist/core/tools/shell-command-parser.d.ts +4 -3
  145. package/dist/core/tools/shell-command-parser.d.ts.map +1 -1
  146. package/dist/core/tools/shell-command-parser.js +32 -7
  147. package/dist/core/tools/shell-command-parser.js.map +1 -1
  148. package/dist/core/tools/shell-contract-router.d.ts.map +1 -1
  149. package/dist/core/tools/shell-contract-router.js +23 -1
  150. package/dist/core/tools/shell-contract-router.js.map +1 -1
  151. package/dist/core/tools/task-steps.d.ts.map +1 -1
  152. package/dist/core/tools/task-steps.js +6 -11
  153. package/dist/core/tools/task-steps.js.map +1 -1
  154. package/dist/core/tools/tmux-dispatch.d.ts +2 -0
  155. package/dist/core/tools/tmux-dispatch.d.ts.map +1 -1
  156. package/dist/core/tools/tmux-dispatch.js +16 -2
  157. package/dist/core/tools/tmux-dispatch.js.map +1 -1
  158. package/dist/core/tools/windows-shell-engine.js +1 -1
  159. package/dist/core/tools/windows-shell-engine.js.map +1 -1
  160. package/dist/core/tools/write.d.ts +24 -7
  161. package/dist/core/tools/write.d.ts.map +1 -1
  162. package/dist/core/tools/write.js +182 -107
  163. package/dist/core/tools/write.js.map +1 -1
  164. package/dist/index.d.ts +1 -1
  165. package/dist/index.d.ts.map +1 -1
  166. package/dist/index.js +1 -1
  167. package/dist/index.js.map +1 -1
  168. package/dist/jscpd-cli.d.ts +3 -0
  169. package/dist/jscpd-cli.d.ts.map +1 -0
  170. package/dist/jscpd-cli.js +22 -0
  171. package/dist/jscpd-cli.js.map +1 -0
  172. package/dist/modes/interactive/components/profile-resource-editor.js +2 -2
  173. package/dist/modes/interactive/components/profile-resource-editor.js.map +1 -1
  174. package/dist/modes/interactive/components/tool-execution.d.ts +1 -0
  175. package/dist/modes/interactive/components/tool-execution.d.ts.map +1 -1
  176. package/dist/modes/interactive/components/tool-execution.js +85 -3
  177. package/dist/modes/interactive/components/tool-execution.js.map +1 -1
  178. package/dist/modes/interactive/interactive-mode.js +1 -1
  179. package/dist/modes/interactive/interactive-mode.js.map +1 -1
  180. package/dist/utils/bundled-jscpd.d.ts +20 -0
  181. package/dist/utils/bundled-jscpd.d.ts.map +1 -0
  182. package/dist/utils/bundled-jscpd.js +154 -0
  183. package/dist/utils/bundled-jscpd.js.map +1 -0
  184. package/dist/utils/paths.js +1 -1
  185. package/dist/utils/paths.js.map +1 -1
  186. package/dist/utils/shell.d.ts.map +1 -1
  187. package/dist/utils/shell.js +11 -0
  188. package/dist/utils/shell.js.map +1 -1
  189. package/dist/utils/tools-manager.d.ts +19 -2
  190. package/dist/utils/tools-manager.d.ts.map +1 -1
  191. package/dist/utils/tools-manager.js +92 -40
  192. package/dist/utils/tools-manager.js.map +1 -1
  193. package/docs/index.md +3 -0
  194. package/docs/managed-data-tools.md +15 -0
  195. package/docs/models.md +1 -1
  196. package/docs/quickstart.md +2 -2
  197. package/docs/settings.md +1 -1
  198. package/docs/tool-boundary-performance-roadmap-2026-08-02.md +166 -0
  199. package/docs/tool-repair.md +4 -4
  200. package/docs/windows.md +7 -5
  201. package/docs/worker-profiles.md +16 -0
  202. package/examples/extensions/built-in-tool-renderer.ts +12 -5
  203. package/examples/extensions/custom-provider-anthropic/package-lock.json +2 -2
  204. package/examples/extensions/custom-provider-anthropic/package.json +1 -1
  205. package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
  206. package/examples/extensions/minimal-mode.ts +8 -7
  207. package/examples/extensions/prompt-customizer.ts +4 -2
  208. package/examples/extensions/sandbox/package-lock.json +2 -2
  209. package/examples/extensions/sandbox/package.json +1 -1
  210. package/examples/extensions/ssh.ts +113 -24
  211. package/examples/extensions/with-deps/package-lock.json +2 -2
  212. package/examples/extensions/with-deps/package.json +1 -1
  213. package/npm-shrinkwrap.json +112 -12
  214. package/package.json +7 -5
@@ -1 +1 @@
1
- {"version":3,"file":"bash.js","sourceRoot":"","sources":["../../../src/core/tools/bash.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AACpC,OAAO,EAAE,MAAM,IAAI,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AACtD,OAAO,EAAkB,qBAAqB,EAAE,MAAM,2BAA2B,CAAC;AAClF,OAAO,EACN,iBAAiB,EACjB,iBAAiB,EACjB,UAAU,GAEV,MAAM,gCAAgC,CAAC;AACxC,OAAO,EAAE,SAAS,EAAE,IAAI,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACtE,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AACtC,OAAO,EAAe,IAAI,EAAE,MAAM,SAAS,CAAC;AAC5C,OAAO,EAAE,OAAO,EAAE,MAAM,wDAAwD,CAAC;AACjF,OAAO,EAAE,qBAAqB,EAAE,MAAM,uDAAuD,CAAC;AAC9F,OAAO,EAAE,KAAK,EAAE,MAAM,wCAAwC,CAAC;AAC/D,OAAO,EAAE,kCAAkC,EAAE,MAAM,8BAA8B,CAAC;AAClF,OAAO,EACN,wBAAwB,EACxB,cAAc,EACd,WAAW,EAEX,uBAAuB,EACvB,qBAAqB,EACrB,uBAAuB,GACvB,MAAM,sBAAsB,CAAC;AAE9B,OAAO,EAAE,4BAA4B,EAAE,MAAM,0BAA0B,CAAC;AACxE,OAAO,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AACzE,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAC5D,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAC;AACvE,OAAO,EAAE,sBAAsB,EAAE,yBAAyB,EAAE,MAAM,2BAA2B,CAAC;AAC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AAC;gBAC7B,IAAI,KAAK,CAAC,QAAQ,EAAE,CAAC;oBACpB,aAAa,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;oBAC9B,KAAK,CAAC,QAAQ,GAAG,SAAS,CAAC;gBAC5B,CAAC;YACF,CAAC;YACD,MAAM,SAAS,GACb,OAAO,CAAC,aAAuD,IAAI,IAAI,yBAAyB,EAAE,CAAC;YACrG,gCAAgC,CAC/B,SAAS,EACT,MAAa,EACb,OAAO,EACP,OAAO,CAAC,UAAU,EAClB,KAAK,CAAC,SAAS,EACf,KAAK,CAAC,OAAO,CACb,CAAC;YACF,SAAS,CAAC,UAAU,EAAE,CAAC;YACvB,OAAO,SAAS,CAAC;QAClB,CAAC;KACD,CAAC;AACH,CAAC;AAED,MAAM,UAAU,wBAAwB,CACvC,GAAW,EACX,OAAyB;IAEzB,MAAM,QAAQ,GAAG,OAAO,EAAE,QAAQ,IAAI,OAAO,CAAC,QAAQ,CAAC;IACvD,OAAO,yBAAyB,CAAC,GAAG,EAAE,wBAAwB,CAAC,QAAQ,CAAC,EAAE,QAAQ,EAAE,OAAO,CAAC,CAAC;AAC9F,CAAC;AAED,MAAM,UAAU,cAAc,CAAC,GAAW,EAAE,OAAyB;IACpE,OAAO,kBAAkB,CAAC,wBAAwB,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC,CAAC;AACnE,CAAC","sourcesContent":["import { randomUUID } from \"node:crypto\";\nimport { constants } from \"node:fs\";\nimport { access as fsAccess } from \"node:fs/promises\";\nimport { type AgentTool, createSilenceWatchdog } from \"@caupulican/pi-agent-core\";\nimport {\n\tDEFAULT_MAX_BYTES,\n\tDEFAULT_MAX_LINES,\n\tformatSize,\n\ttype TruncationResult,\n} from \"@caupulican/pi-agent-core/node\";\nimport { Container, Text, truncateToWidth } from \"@caupulican/pi-tui\";\nimport { spawn } from \"child_process\";\nimport { type Static, Type } from \"typebox\";\nimport { keyHint } from \"../../modes/interactive/components/keybinding-hints.ts\";\nimport { truncateToVisualLines } from \"../../modes/interactive/components/visual-truncate.ts\";\nimport { theme } from \"../../modes/interactive/theme/theme.ts\";\nimport { waitForChildProcessWithTermination } from \"../../utils/child-process.ts\";\nimport {\n\tgetPlatformShellToolName,\n\tgetShellConfig,\n\tgetShellEnv,\n\ttype PlatformShellToolName,\n\tprefixPowerShellCommand,\n\ttrackDetachedChildPid,\n\tuntrackDetachedChildPid,\n} from \"../../utils/shell.ts\";\nimport type { ToolDefinition, ToolRenderResultOptions } from \"../extensions/types.ts\";\nimport { withExclusiveMutationBarrier } from \"./file-mutation-queue.ts\";\nimport { classifyGitCommand, executeFilteredGit } from \"./git-filter.ts\";\nimport { OutputAccumulator } from \"./output-accumulator.ts\";\nimport { getTextOutput, invalidArgText, str } from \"./render-utils.ts\";\nimport { assessShellSearchScope, BROAD_SEARCH_OUTPUT_ROUTE } from \"./search-command-guard.ts\";\nimport { routeShellContract } from \"./shell-contract-router.ts\";\nimport {\n\tcreateShellOutputProjector,\n\ttype ShellOutputProjection,\n\ttype ShellOutputProjectionDetails,\n} from \"./shell-output-projection.ts\";\nimport { acquirePersistentShellSession } from \"./shell-session.ts\";\nimport { wrapToolDefinition } from \"./tool-definition-wrapper.ts\";\nimport { createWindowsShellEngineOperations, type WindowsShellEngineOptions } from \"./windows-shell-engine.ts\";\nimport { getOrCreateWindowsShellState, mergeEffectiveEnv, resolveEffectiveCwd } from \"./windows-shell-state.ts\";\n\n/** Low-level silence bound retained for direct shell-operation consumers. Agent tool calls always pass a wall-clock bound. */\nconst DEFAULT_COMMAND_SILENCE_MS = 600_000;\n/** Agent-facing wall-clock bound: continuously producing output must not make a command immortal. */\nexport const DEFAULT_COMMAND_TIMEOUT_SECONDS = 120;\nexport const MAX_COMMAND_TIMEOUT_SECONDS = 3600;\nconst MIN_COMMAND_TIMEOUT_SECONDS = 0.1;\nlet commandSilenceMsOverride: number | undefined;\nlet commandTimeoutMsOverride: number | undefined;\n\n/** Test hook: override the low-level silence threshold. Pass undefined to restore the default. */\nexport function setCommandSilenceMsForTests(ms: number | undefined): void {\n\tcommandSilenceMsOverride = ms;\n}\n\n/** Test hook: override the agent tool's default wall-clock bound. Pass undefined to restore it. */\nexport function setCommandTimeoutMsForTests(ms: number | undefined): void {\n\tcommandTimeoutMsOverride = ms;\n}\n\nexport function resolveCommandTimeoutSeconds(timeout: number | undefined): number {\n\tif (typeof timeout !== \"number\" || !Number.isFinite(timeout) || timeout <= 0) {\n\t\treturn DEFAULT_COMMAND_TIMEOUT_SECONDS;\n\t}\n\treturn Math.max(MIN_COMMAND_TIMEOUT_SECONDS, Math.min(timeout, MAX_COMMAND_TIMEOUT_SECONDS));\n}\n\nconst bashSchema = Type.Object({\n\tcommand: Type.String({ description: \"Shell command to execute\" }),\n\ttimeout: Type.Optional(\n\t\tType.Number({\n\t\t\tdescription: `Wall-clock timeout in seconds. Defaults to ${DEFAULT_COMMAND_TIMEOUT_SECONDS}; positive overrides are capped at ${MAX_COMMAND_TIMEOUT_SECONDS}. Zero or negative values use the default.`,\n\t\t}),\n\t),\n\tbroadSearch: Type.Optional(\n\t\tType.Literal(BROAD_SEARCH_OUTPUT_ROUTE, {\n\t\t\tdescription:\n\t\t\t\t\"Explicit override for a broad rg/grep/find/fd scan that cannot be narrowed. The command runs, but its complete output is routed to a file and excluded from model context.\",\n\t\t}),\n\t),\n});\n\nexport type BashToolInput = Static<typeof bashSchema>;\n\nexport interface BashToolDetails {\n\ttruncation?: TruncationResult;\n\tfullOutputPath?: string;\n\tfullOutputError?: string;\n\tpersistedOutputTruncated?: boolean;\n\tpersistedOutputBytes?: number;\n\tpreview?: {\n\t\tcontent: string;\n\t\tskippedLines: number;\n\t};\n\toutputProjection?: ShellOutputProjectionDetails;\n}\n\n/**\n * Pluggable operations for the bash tool.\n * Override these to delegate command execution to remote systems (for example SSH).\n */\nexport interface BashOperations {\n\t/**\n\t * Execute a command and stream output.\n\t * @param command The command to execute\n\t * @param cwd Working directory\n\t * @param options Execution options\n\t * @returns Promise resolving to exit code (null if killed)\n\t */\n\texec: (\n\t\tcommand: string,\n\t\tcwd: string,\n\t\toptions: {\n\t\t\tonData: (data: Buffer) => void;\n\t\t\tsignal?: AbortSignal;\n\t\t\ttimeout?: number;\n\t\t\tenv?: NodeJS.ProcessEnv;\n\t\t},\n\t) => Promise<{ exitCode: number | null }>;\n}\n\nfunction createLocalShellOperations(\n\tshellName: PlatformShellToolName,\n\toptions?: { shellPath?: string; sessionKey?: string },\n): BashOperations {\n\t// A session key selects the persistent per-agent backend. An explicit custom shell path keeps\n\t// per-command spawning: persistent sessions assume the resolved platform shell's flag set.\n\tconst sessionKey = options?.sessionKey;\n\tif (sessionKey !== undefined && !options?.shellPath) {\n\t\treturn {\n\t\t\texec: async (command, cwd, { onData, signal, timeout, env }) => {\n\t\t\t\ttry {\n\t\t\t\t\tawait fsAccess(cwd, constants.F_OK);\n\t\t\t\t} catch {\n\t\t\t\t\tthrow new Error(`Working directory does not exist: ${cwd}\\nCannot execute ${shellName} commands.`);\n\t\t\t\t}\n\t\t\t\tif (signal?.aborted) throw new Error(\"aborted\");\n\t\t\t\tconst session = acquirePersistentShellSession(sessionKey, shellName);\n\t\t\t\tconst silenceMs = commandSilenceMsOverride ?? DEFAULT_COMMAND_SILENCE_MS;\n\t\t\t\tconst hasWallClock = timeout !== undefined && timeout > 0;\n\t\t\t\treturn session.exec(command, cwd, {\n\t\t\t\t\tonData,\n\t\t\t\t\tsignal,\n\t\t\t\t\tenv,\n\t\t\t\t\ttimeoutSeconds: hasWallClock ? timeout : undefined,\n\t\t\t\t\tsilenceMs: !hasWallClock && silenceMs > 0 ? silenceMs : undefined,\n\t\t\t\t});\n\t\t\t},\n\t\t};\n\t}\n\treturn {\n\t\texec: async (command, cwd, { onData, signal, timeout, env }) => {\n\t\t\tconst { shell, args } = getShellConfig(options?.shellPath, shellName);\n\t\t\ttry {\n\t\t\t\tawait fsAccess(cwd, constants.F_OK);\n\t\t\t} catch {\n\t\t\t\tthrow new Error(`Working directory does not exist: ${cwd}\\nCannot execute ${shellName} commands.`);\n\t\t\t}\n\t\t\tif (signal?.aborted) throw new Error(\"aborted\");\n\n\t\t\tconst child = spawn(shell, [...args, command], {\n\t\t\t\tcwd,\n\t\t\t\tdetached: process.platform !== \"win32\",\n\t\t\t\tenv: env ?? getShellEnv(),\n\t\t\t\tstdio: [\"ignore\", \"pipe\", \"pipe\"],\n\t\t\t\twindowsHide: true,\n\t\t\t});\n\t\t\tif (child.pid) trackDetachedChildPid(child.pid);\n\t\t\tconst terminationController = new AbortController();\n\t\t\tconst onAbort = () => terminationController.abort();\n\t\t\tlet silenceKilled = false;\n\t\t\tconst silenceMs = commandSilenceMsOverride ?? DEFAULT_COMMAND_SILENCE_MS;\n\t\t\tconst silenceWatchdog =\n\t\t\t\t(timeout === undefined || timeout <= 0) && silenceMs > 0\n\t\t\t\t\t? createSilenceWatchdog({\n\t\t\t\t\t\t\tsilenceMs,\n\t\t\t\t\t\t\tonSilence: () => {\n\t\t\t\t\t\t\t\tsilenceKilled = true;\n\t\t\t\t\t\t\t\tterminationController.abort();\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t})\n\t\t\t\t\t: undefined;\n\t\t\tconst onChunk = (data: Buffer) => {\n\t\t\t\tsilenceWatchdog?.touch();\n\t\t\t\tonData(data);\n\t\t\t};\n\n\t\t\ttry {\n\t\t\t\tchild.stdout?.on(\"data\", onChunk);\n\t\t\t\tchild.stderr?.on(\"data\", onChunk);\n\t\t\t\tif (signal) {\n\t\t\t\t\tif (signal.aborted) onAbort();\n\t\t\t\t\telse signal.addEventListener(\"abort\", onAbort, { once: true });\n\t\t\t\t}\n\t\t\t\tconst terminal = await waitForChildProcessWithTermination(child, {\n\t\t\t\t\tsignal: terminationController.signal,\n\t\t\t\t\ttimeoutMs: timeout !== undefined && timeout > 0 ? timeout * 1000 : undefined,\n\t\t\t\t\tkillGraceMs: 2_000,\n\t\t\t\t});\n\t\t\t\tif (signal?.aborted) throw new Error(\"aborted\");\n\t\t\t\tif (terminal.reason === \"timeout\") throw new Error(`timeout:${timeout}`);\n\t\t\t\tif (silenceKilled) throw new Error(`silence:${silenceMs / 1000}`);\n\t\t\t\treturn { exitCode: terminal.code };\n\t\t\t} finally {\n\t\t\t\tsilenceWatchdog?.disarm();\n\t\t\t\tif (child.pid) untrackDetachedChildPid(child.pid);\n\t\t\t\tif (signal) signal.removeEventListener(\"abort\", onAbort);\n\t\t\t}\n\t\t},\n\t};\n}\n\n/**\n * Create bash operations using pi's built-in local shell execution backend.\n *\n * This is useful for extensions that intercept user_bash and still want pi's\n * standard local shell behavior while wrapping or rewriting commands.\n */\nexport function createLocalBashOperations(options?: { shellPath?: string; sessionKey?: string }): BashOperations {\n\treturn createLocalShellOperations(\"bash\", options);\n}\n\n/** Create PowerShell operations using pi's built-in local execution backend. */\nexport function createLocalPowerShellOperations(options?: { shellPath?: string; sessionKey?: string }): BashOperations {\n\treturn createLocalShellOperations(\"powershell\", options);\n}\n\n/** Create the platform shell backend without requiring callers or the model to choose a shell. */\nexport function createLocalPlatformShellOperations(\n\toptions: {\n\t\tshellPath?: string;\n\t\tcommandPrefix?: string;\n\t\toperations?: BashOperations;\n\t\tsessionKey?: string;\n\t\t/** Route complex/state-mutating Bash constructs to the Python engine on Windows. Default: true. */\n\t\tpythonEngine?: boolean;\n\t\t/** Test/embedding hook: overrides the engine tier's runtime/spawn/state resolution. */\n\t\tengineOptions?: WindowsShellEngineOptions;\n\t} = {},\n\tplatform: NodeJS.Platform = process.platform,\n): BashOperations {\n\tconst operations =\n\t\toptions.operations ??\n\t\tcreateLocalShellOperations(getPlatformShellToolName(platform), {\n\t\t\tshellPath: options.shellPath,\n\t\t\tsessionKey: options.sessionKey,\n\t\t});\n\tconst pythonEngineEnabled = options.pythonEngine !== false;\n\t// One factory instance is one fallback tenant. Production agent sessions always pass their\n\t// stable key; standalone callers that omit it must never collapse into a process-global engine.\n\tconst engineSessionKey = options.sessionKey ?? `platform-shell-operations:${randomUUID()}`;\n\tconst engineOperations = createWindowsShellEngineOperations(engineSessionKey, options.engineOptions);\n\treturn {\n\t\tasync exec(command, cwd, execOptions) {\n\t\t\tlet resolvedCommand = command;\n\t\t\tlet resolvedCwd = cwd;\n\t\t\tlet resolvedExecOptions = execOptions;\n\t\t\tif (platform === \"win32\") {\n\t\t\t\tconst route = routeShellContract(command, platform, { pythonEngine: pythonEngineEnabled });\n\t\t\t\tif (route.kind === \"unsupported\") throw new Error(route.error);\n\t\t\t\t// The engine is the sole state mutator (D4); every Windows call — engine or PS\n\t\t\t\t// tier — reads the SAME session state so a `cd`/`export` in one call is observed\n\t\t\t\t// by the very next call regardless of which tier runs it.\n\t\t\t\tconst state = getOrCreateWindowsShellState(engineSessionKey);\n\t\t\t\tresolvedCwd = resolveEffectiveCwd(state, cwd);\n\t\t\t\tresolvedExecOptions = { ...execOptions, env: mergeEffectiveEnv(state, execOptions.env ?? getShellEnv()) };\n\t\t\t\tif (route.kind === \"python-engine\") {\n\t\t\t\t\t// The engine owns the state transition and resolves the original host cwd\n\t\t\t\t\t// exactly once. Passing the already state-adjusted cwd here would make the\n\t\t\t\t\t// engine mistake its own `cd` result for a host cwd change on the next call.\n\t\t\t\t\treturn engineOperations.exec(route.command, cwd, execOptions);\n\t\t\t\t}\n\t\t\t\tif (route.kind === \"powershell\") resolvedCommand = route.command;\n\t\t\t}\n\t\t\tif (options.commandPrefix) resolvedCommand = `${options.commandPrefix}\\n${resolvedCommand}`;\n\t\t\tif (platform === \"win32\") resolvedCommand = prefixPowerShellCommand(resolvedCommand);\n\t\t\treturn operations.exec(resolvedCommand, resolvedCwd, resolvedExecOptions);\n\t\t},\n\t};\n}\n\nexport interface BashSpawnContext {\n\tcommand: string;\n\tcwd: string;\n\tenv: NodeJS.ProcessEnv;\n}\n\nexport type BashSpawnHook = (context: BashSpawnContext) => BashSpawnContext;\n\nfunction resolveSpawnContext(command: string, cwd: string, spawnHook?: BashSpawnHook): BashSpawnContext {\n\tconst baseContext: BashSpawnContext = { command, cwd, env: { ...getShellEnv() } };\n\treturn spawnHook ? spawnHook(baseContext) : baseContext;\n}\n\nexport interface BashToolOptions {\n\t/** Platform used to choose the default backend and contract router. Defaults to process.platform. */\n\tplatform?: NodeJS.Platform;\n\t/** Custom operations for command execution. Default: local platform shell */\n\toperations?: BashOperations;\n\t/** Command prefix prepended to every command (for example shell setup commands) */\n\tcommandPrefix?: string;\n\t/** Optional explicit shell path from settings */\n\tshellPath?: string;\n\t/** Hook to adjust command, cwd, or env before execution */\n\tspawnHook?: BashSpawnHook;\n\t/**\n\t * Stable key for this agent's persistent shell session. The host passes its per-agent key so\n\t * the session survives runtime reloads and user `!` commands share it; separately created\n\t * tool instances (subagents) auto-generate their own key and stay isolated.\n\t */\n\tsessionKey?: string;\n\t/** Route complex/state-mutating Bash constructs to the Python engine on Windows. Default: true. */\n\twindowsShellPythonEngine?: boolean;\n\t/** Test/embedding hook: overrides the engine tier's runtime/spawn/state resolution. */\n\twindowsShellEngineOptions?: WindowsShellEngineOptions;\n\t/** Test/embedding hook: override the managed directory used for complete command output. */\n\toutputDirectory?: string;\n}\n\nconst BASH_PREVIEW_LINES = 5;\nconst BASH_PREVIEW_BYTES = 8 * 1024;\nconst BASH_UPDATE_THROTTLE_MS = 100;\nconst BROAD_SEARCH_MAX_PERSISTED_BYTES = 8 * 1024 * 1024;\n\ntype BashRenderState = {\n\tstartedAt: number | undefined;\n\tendedAt: number | undefined;\n\tinterval: NodeJS.Timeout | undefined;\n};\n\ntype BashResultRenderState = {\n\tcachedWidth: number | undefined;\n\tcachedLines: string[] | undefined;\n\tcachedSkipped: number | undefined;\n};\n\nclass BashResultRenderComponent extends Container {\n\tstate: BashResultRenderState = {\n\t\tcachedWidth: undefined,\n\t\tcachedLines: undefined,\n\t\tcachedSkipped: undefined,\n\t};\n}\n\nfunction formatDuration(ms: number): string {\n\treturn `${(ms / 1000).toFixed(1)}s`;\n}\n\nfunction formatBashCall(\n\targs: { command?: string; timeout?: number } | undefined,\n\tshellName: PlatformShellToolName,\n): string {\n\tconst command = str(args?.command);\n\tconst timeout = args?.timeout as number | undefined;\n\tconst timeoutSuffix = timeout ? theme.fg(\"muted\", ` (timeout ${timeout}s)`) : \"\";\n\tconst commandDisplay = command === null ? invalidArgText(theme) : command ? command : theme.fg(\"toolOutput\", \"...\");\n\tconst prompt = shellName === \"powershell\" ? \"PS>\" : \"$\";\n\treturn theme.fg(\"toolTitle\", theme.bold(`${prompt} ${commandDisplay}`)) + timeoutSuffix;\n}\n\nfunction rebuildBashResultRenderComponent(\n\tcomponent: BashResultRenderComponent,\n\tresult: {\n\t\tcontent: Array<{ type: string; text?: string; data?: string; mimeType?: string }>;\n\t\tdetails?: BashToolDetails;\n\t},\n\toptions: ToolRenderResultOptions,\n\tshowImages: boolean,\n\tstartedAt: number | undefined,\n\tendedAt: number | undefined,\n): void {\n\tconst state = component.state;\n\tcomponent.clear();\n\n\tconst renderPreview = !options.expanded ? result.details?.preview : undefined;\n\tlet output = (renderPreview ? renderPreview.content : getTextOutput(result as any, showImages)).trim();\n\tconst truncation = result.details?.truncation;\n\tconst fullOutputPath = result.details?.fullOutputPath;\n\tconst fullOutputError = result.details?.fullOutputError;\n\tif (!options.isPartial && truncation?.truncated && fullOutputPath && output.endsWith(\"]\")) {\n\t\tconst footerStart = output.lastIndexOf(\"\\n\\n[\");\n\t\tif (footerStart !== -1 && output.slice(footerStart).includes(fullOutputPath)) {\n\t\t\toutput = output.slice(0, footerStart).trimEnd();\n\t\t}\n\t}\n\n\tif (output) {\n\t\tif (options.expanded) {\n\t\t\tconst styledOutput = output\n\t\t\t\t.split(\"\\n\")\n\t\t\t\t.map((line) => theme.fg(\"toolOutput\", line))\n\t\t\t\t.join(\"\\n\");\n\t\t\tcomponent.addChild(new Text(`\\n${styledOutput}`, 0, 0));\n\t\t} else {\n\t\t\tcomponent.addChild({\n\t\t\t\trender: (width: number) => {\n\t\t\t\t\tif (state.cachedLines === undefined || state.cachedWidth !== width) {\n\t\t\t\t\t\tconst preview = truncateToVisualLines(output, BASH_PREVIEW_LINES, width);\n\t\t\t\t\t\tstate.cachedLines = preview.visualLines.map((line) => theme.fg(\"toolOutput\", line));\n\t\t\t\t\t\tstate.cachedSkipped = (result.details?.preview?.skippedLines ?? 0) + preview.skippedCount;\n\t\t\t\t\t\tstate.cachedWidth = width;\n\t\t\t\t\t}\n\t\t\t\t\tif (state.cachedSkipped && state.cachedSkipped > 0) {\n\t\t\t\t\t\tconst hint =\n\t\t\t\t\t\t\ttheme.fg(\"muted\", `... (${state.cachedSkipped} earlier lines,`) +\n\t\t\t\t\t\t\t` ${keyHint(\"app.tools.expand\", \"to expand\")})`;\n\t\t\t\t\t\treturn [\"\", truncateToWidth(hint, width, \"...\"), ...(state.cachedLines ?? [])];\n\t\t\t\t\t}\n\t\t\t\t\treturn [\"\", ...(state.cachedLines ?? [])];\n\t\t\t\t},\n\t\t\t\tinvalidate: () => {\n\t\t\t\t\tstate.cachedWidth = undefined;\n\t\t\t\t\tstate.cachedLines = undefined;\n\t\t\t\t\tstate.cachedSkipped = undefined;\n\t\t\t\t},\n\t\t\t});\n\t\t}\n\t}\n\n\tif (truncation?.truncated || fullOutputPath || fullOutputError) {\n\t\tconst warnings: string[] = [];\n\t\tif (fullOutputPath) {\n\t\t\twarnings.push(`Full output: ${fullOutputPath}`);\n\t\t} else if (fullOutputError) {\n\t\t\twarnings.push(`Full output unavailable: ${fullOutputError}`);\n\t\t}\n\t\tif (truncation?.truncated) {\n\t\t\tif (truncation.truncatedBy === \"lines\") {\n\t\t\t\twarnings.push(`Truncated: showing ${truncation.outputLines} of ${truncation.totalLines} lines`);\n\t\t\t} else {\n\t\t\t\twarnings.push(\n\t\t\t\t\t`Truncated: ${truncation.outputLines} lines shown (${formatSize(truncation.maxBytes ?? DEFAULT_MAX_BYTES)} limit)`,\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t\tcomponent.addChild(new Text(`\\n${theme.fg(\"warning\", `[${warnings.join(\". \")}]`)}`, 0, 0));\n\t}\n\n\tif (startedAt !== undefined) {\n\t\tconst label = options.isPartial ? \"Elapsed\" : \"Took\";\n\t\tconst endTime = endedAt ?? Date.now();\n\t\tcomponent.addChild(new Text(`\\n${theme.fg(\"muted\", `${label} ${formatDuration(endTime - startedAt)}`)}`, 0, 0));\n\t}\n}\n\nfunction createShellToolDefinition(\n\tcwd: string,\n\tbackendShell: PlatformShellToolName,\n\tcontractPlatform: NodeJS.Platform,\n\toptions?: BashToolOptions,\n): ToolDefinition<typeof bashSchema, BashToolDetails | undefined, BashRenderState> {\n\tconst toolName = \"bash\";\n\tconst sessionKey = options?.sessionKey ?? `bash-tool:${randomUUID()}`;\n\tconst ops =\n\t\toptions?.operations ??\n\t\t(backendShell === \"powershell\"\n\t\t\t? createLocalPowerShellOperations({ shellPath: options?.shellPath, sessionKey })\n\t\t\t: createLocalBashOperations({ shellPath: options?.shellPath, sessionKey }));\n\tconst commandPrefix = options?.commandPrefix;\n\tconst spawnHook = options?.spawnHook;\n\tconst hasExecutionOverrides = Boolean(options?.operations || options?.shellPath || commandPrefix || spawnHook);\n\tconst canFilterCommand = !hasExecutionOverrides;\n\tconst routesWindowsContract = contractPlatform === \"win32\";\n\tconst pythonEngineEnabled = options?.windowsShellPythonEngine !== false;\n\tconst engineOperations = routesWindowsContract\n\t\t? createWindowsShellEngineOperations(sessionKey, options?.windowsShellEngineOptions)\n\t\t: undefined;\n\tconst contractDescription = routesWindowsContract\n\t\t? \"Execute Pi's stable Bash-like command contract in a persistent per-agent shell session (current directory and environment variables persist across calls, including across the PowerShell and Python engine tiers). On Windows, a deterministic router converts simple commands directly to PowerShell and routes pipelines, redirection, expansion, chaining, and state-mutating commands (cd/export/unset) through a bundled Python engine that implements the supported Bash grammar; named unsupported constructs (job control, process substitution, heredocs, nested shells, and similar) fail closed instead of being guessed.\"\n\t\t: \"Execute a Bash command in a persistent per-agent shell session: the current directory and environment variables persist across calls, and a timed-out or aborted command resets the session.\";\n\treturn {\n\t\tname: toolName,\n\t\tlabel: toolName,\n\t\tdescription: `${contractDescription} Returns stdout and stderr. Output is truncated to last ${DEFAULT_MAX_LINES} lines or ${DEFAULT_MAX_BYTES / 1024}KB (whichever is hit first). If truncated, full output is saved to a managed file. Recognized test runners return a bounded failure/summary projection when it is materially smaller, with exact output saved to a managed file. Broad rg/grep/find/fd scans are rejected before execution; when an exhaustive scan is unavoidable, set broadSearch=\"${BROAD_SEARCH_OUTPUT_ROUTE}\" to route all output to a managed file instead of model context. Commands have a ${DEFAULT_COMMAND_TIMEOUT_SECONDS}-second wall-clock default, including commands that keep producing output; use a positive timeout only when a scoped operation justifies a larger bound (maximum ${MAX_COMMAND_TIMEOUT_SECONDS} seconds).`,\n\t\tpromptSnippet: routesWindowsContract\n\t\t\t? \"Execute Bash-like commands; Pi routes them deterministically to PowerShell or a bundled Python engine on Windows\"\n\t\t\t: \"Execute Bash commands (ls, grep, find, etc.)\",\n\t\tpromptGuidelines: routesWindowsContract\n\t\t\t? [\n\t\t\t\t\t\"Use ordinary Bash-like commands on Windows; do not write PowerShell or ask the user to choose a shell.\",\n\t\t\t\t\t\"Pipelines, redirection, expansion (variables, command substitution, globs), chaining (&&/||/;), and cd/export/unset are supported and routed to a bundled Python engine; a fixed set of named constructs (job control, process substitution, heredocs, arithmetic expansion, nested shells, and similar) fail closed with an actionable message instead of being guessed.\",\n\t\t\t\t\t\"Working directory and environment changes from cd/export/unset persist across subsequent bash calls, including calls that route to the PowerShell tier.\",\n\t\t\t\t\t\"Supported Bash-like file commands are converted with literal-path operations; verify targets before recursive rm, cp, or mv calls.\",\n\t\t\t\t\t`Keep searches scoped and purpose-driven: discover paths first, pass an explicit root and filters, and prefer the bounded grep/find tools. Broad shell searches are rejected; use broadSearch=\"${BROAD_SEARCH_OUTPUT_ROUTE}\" only for an unavoidable exhaustive scan, then inspect the returned file with bounded reads or narrower searches.`,\n\t\t\t\t]\n\t\t\t: [\n\t\t\t\t\t`Keep searches scoped and purpose-driven: discover paths first, pass an explicit root and filters, and prefer the bounded grep/find tools. Broad shell searches are rejected; use broadSearch=\"${BROAD_SEARCH_OUTPUT_ROUTE}\" only for an unavoidable exhaustive scan, then inspect the returned file with bounded reads or narrower searches.`,\n\t\t\t\t],\n\t\tparameters: bashSchema,\n\t\tasync execute(\n\t\t\t_toolCallId,\n\t\t\t{\n\t\t\t\tcommand,\n\t\t\t\ttimeout,\n\t\t\t\tbroadSearch,\n\t\t\t}: { command: string; timeout?: number; broadSearch?: typeof BROAD_SEARCH_OUTPUT_ROUTE },\n\t\t\tsignal?: AbortSignal,\n\t\t\tonUpdate?,\n\t\t\t_ctx?,\n\t\t) {\n\t\t\tconst searchScope = assessShellSearchScope(command, cwd);\n\t\t\tif (searchScope.kind === \"broad\" && broadSearch !== BROAD_SEARCH_OUTPUT_ROUTE) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`Broad search blocked before execution: ${searchScope.reason}. Narrow the path, glob, type, or pattern; prefer the grep/find tool with explicit path/glob/limit. If an exhaustive scan is required, retry with broadSearch=\"${BROAD_SEARCH_OUTPUT_ROUTE}\"; Pi will keep its output out of context and return a managed file path for bounded read or search follow-up.`,\n\t\t\t\t);\n\t\t\t}\n\t\t\tconst routeBroadSearchOutput = searchScope.kind === \"broad\";\n\t\t\tlet outputProjector =\n\t\t\t\trouteBroadSearchOutput || commandPrefix || spawnHook ? undefined : createShellOutputProjector(command);\n\t\t\tconst output = new OutputAccumulator({\n\t\t\t\ttempFilePrefix: `pi-${toolName}`,\n\t\t\t\ttempDirectory: options?.outputDirectory,\n\t\t\t\tpersistAllOutput: routeBroadSearchOutput,\n\t\t\t\tmaxPersistedBytes: routeBroadSearchOutput ? BROAD_SEARCH_MAX_PERSISTED_BYTES : undefined,\n\t\t\t});\n\t\t\tlet updateTimer: NodeJS.Timeout | undefined;\n\t\t\tlet updateDirty = false;\n\t\t\tlet lastUpdateAt = 0;\n\n\t\t\tconst emitOutputUpdate = () => {\n\t\t\t\tif (!onUpdate || !updateDirty) return;\n\t\t\t\tupdateDirty = false;\n\t\t\t\tlastUpdateAt = Date.now();\n\t\t\t\tconst snapshot = output.previewSnapshot(BASH_PREVIEW_LINES, BASH_PREVIEW_BYTES, {\n\t\t\t\t\tpersistIfFullTruncated: true,\n\t\t\t\t});\n\t\t\t\tif (routeBroadSearchOutput) {\n\t\t\t\t\tconst notice = snapshot.fullOutputPath\n\t\t\t\t\t\t? `Broad search running. Output is being routed to ${snapshot.fullOutputPath}`\n\t\t\t\t\t\t: \"Broad search running. Output is being routed to a managed file\";\n\t\t\t\t\tonUpdate({\n\t\t\t\t\t\tcontent: [{ type: \"text\", text: notice }],\n\t\t\t\t\t\tdetails: {\n\t\t\t\t\t\t\tfullOutputPath: snapshot.fullOutputPath,\n\t\t\t\t\t\t\tfullOutputError: snapshot.fullOutputError,\n\t\t\t\t\t\t\tpersistedOutputTruncated: snapshot.persistedOutputTruncated,\n\t\t\t\t\t\t\tpersistedOutputBytes: snapshot.persistedOutputBytes,\n\t\t\t\t\t\t},\n\t\t\t\t\t});\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tconst preview = {\n\t\t\t\t\tcontent: snapshot.content.replace(/\\r/g, \"\"),\n\t\t\t\t\tskippedLines: Math.max(0, snapshot.truncation.totalLines - snapshot.truncation.outputLines),\n\t\t\t\t};\n\t\t\t\tonUpdate({\n\t\t\t\t\tcontent: [{ type: \"text\", text: preview.content || \"\" }],\n\t\t\t\t\tdetails: {\n\t\t\t\t\t\ttruncation: snapshot.truncation.truncated ? snapshot.truncation : undefined,\n\t\t\t\t\t\tfullOutputPath: snapshot.fullOutputPath,\n\t\t\t\t\t\tfullOutputError: snapshot.fullOutputError,\n\t\t\t\t\t\tpreview,\n\t\t\t\t\t},\n\t\t\t\t});\n\t\t\t};\n\n\t\t\tconst clearUpdateTimer = () => {\n\t\t\t\tif (updateTimer) {\n\t\t\t\t\tclearTimeout(updateTimer);\n\t\t\t\t\tupdateTimer = undefined;\n\t\t\t\t}\n\t\t\t};\n\n\t\t\tconst scheduleOutputUpdate = () => {\n\t\t\t\tif (!onUpdate) return;\n\t\t\t\tupdateDirty = true;\n\t\t\t\tconst delay = BASH_UPDATE_THROTTLE_MS - (Date.now() - lastUpdateAt);\n\t\t\t\tif (delay <= 0) {\n\t\t\t\t\tclearUpdateTimer();\n\t\t\t\t\temitOutputUpdate();\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tupdateTimer ??= setTimeout(() => {\n\t\t\t\t\tupdateTimer = undefined;\n\t\t\t\t\temitOutputUpdate();\n\t\t\t\t}, delay);\n\t\t\t};\n\n\t\t\tif (onUpdate) {\n\t\t\t\tonUpdate({ content: [], details: undefined });\n\t\t\t}\n\n\t\t\tconst handleData = (data: Buffer) => {\n\t\t\t\toutput.append(data);\n\t\t\t\tif (outputProjector) {\n\t\t\t\t\ttry {\n\t\t\t\t\t\toutputProjector.append(data);\n\t\t\t\t\t} catch {\n\t\t\t\t\t\t// Projection is opportunistic. Raw output remains authoritative.\n\t\t\t\t\t\toutputProjector = undefined;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tscheduleOutputUpdate();\n\t\t\t};\n\n\t\t\tconst finishOutput = async (persistAlways = false) => {\n\t\t\t\toutput.finish();\n\t\t\t\tclearUpdateTimer();\n\t\t\t\temitOutputUpdate();\n\t\t\t\treturn output.snapshot({ persistIfTruncated: true, persistAlways });\n\t\t\t};\n\n\t\t\tconst finishProjection = (exitCode: number | null): ShellOutputProjection | undefined => {\n\t\t\t\tif (!outputProjector) return undefined;\n\t\t\t\ttry {\n\t\t\t\t\treturn outputProjector.finish(exitCode);\n\t\t\t\t} catch {\n\t\t\t\t\toutputProjector = undefined;\n\t\t\t\t\treturn undefined;\n\t\t\t\t}\n\t\t\t};\n\n\t\t\tconst formatOutput = (\n\t\t\t\tsnapshot: Awaited<ReturnType<typeof finishOutput>>,\n\t\t\t\temptyText = \"(no output)\",\n\t\t\t\tprojection?: ShellOutputProjection,\n\t\t\t) => {\n\t\t\t\tconst truncation = snapshot.truncation;\n\t\t\t\tif (routeBroadSearchOutput) {\n\t\t\t\t\tif (snapshot.fullOutputPath) {\n\t\t\t\t\t\tconst persistenceNotice = snapshot.persistedOutputTruncated\n\t\t\t\t\t\t\t? `The managed ${formatSize(BROAD_SEARCH_MAX_PERSISTED_BYTES)} file limit was reached; later output was discarded.`\n\t\t\t\t\t\t\t: \"\";\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\ttext: `Broad search output routed to ${snapshot.fullOutputPath}. ${persistenceNotice} Inspect it with bounded read offsets or a narrower search.`,\n\t\t\t\t\t\t\tdetails: {\n\t\t\t\t\t\t\t\t...(truncation.truncated ? { truncation } : {}),\n\t\t\t\t\t\t\t\tfullOutputPath: snapshot.fullOutputPath,\n\t\t\t\t\t\t\t\tpersistedOutputTruncated: snapshot.persistedOutputTruncated,\n\t\t\t\t\t\t\t\tpersistedOutputBytes: snapshot.persistedOutputBytes,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\t\t\t\t\tconst boundedTail = snapshot.content.replace(/\\r/g, \"\") || emptyText;\n\t\t\t\t\treturn {\n\t\t\t\t\t\ttext: `Broad search output could not be routed to a managed file${snapshot.fullOutputError ? `: ${snapshot.fullOutputError}` : \"\"}. Bounded tail:\\n${boundedTail}`,\n\t\t\t\t\t\tdetails: {\n\t\t\t\t\t\t\t...(truncation.truncated ? { truncation } : {}),\n\t\t\t\t\t\t\tfullOutputError: snapshot.fullOutputError ?? \"managed output file unavailable\",\n\t\t\t\t\t\t},\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t\tlet text = (projection?.content ?? snapshot.content).replace(/\\r/g, \"\") || emptyText;\n\t\t\t\tlet details: BashToolDetails | undefined;\n\t\t\t\tconst preview = projection\n\t\t\t\t\t? (() => {\n\t\t\t\t\t\t\tconst lines = projection.content.split(\"\\n\");\n\t\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t\tcontent: lines.slice(-BASH_PREVIEW_LINES).join(\"\\n\"),\n\t\t\t\t\t\t\t\tskippedLines: Math.max(0, lines.length - BASH_PREVIEW_LINES),\n\t\t\t\t\t\t\t};\n\t\t\t\t\t\t})()\n\t\t\t\t\t: output.preview(BASH_PREVIEW_LINES, BASH_PREVIEW_BYTES);\n\t\t\t\tconst fullOutputNotice = snapshot.fullOutputPath\n\t\t\t\t\t? `Full output: ${snapshot.fullOutputPath}`\n\t\t\t\t\t: snapshot.fullOutputError\n\t\t\t\t\t\t? `Full output unavailable: ${snapshot.fullOutputError}`\n\t\t\t\t\t\t: \"Full output unavailable\";\n\t\t\t\tif (truncation.truncated || preview.skippedLines > 0 || projection) {\n\t\t\t\t\tdetails = { preview };\n\t\t\t\t}\n\t\t\t\tif (snapshot.fullOutputPath || snapshot.fullOutputError) {\n\t\t\t\t\tdetails = {\n\t\t\t\t\t\t...(details ?? {}),\n\t\t\t\t\t\tfullOutputPath: snapshot.fullOutputPath,\n\t\t\t\t\t\tfullOutputError: snapshot.fullOutputError,\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t\tif (truncation.truncated) {\n\t\t\t\t\tdetails = {\n\t\t\t\t\t\t...(details ?? {}),\n\t\t\t\t\t\ttruncation,\n\t\t\t\t\t\tfullOutputPath: snapshot.fullOutputPath,\n\t\t\t\t\t\tfullOutputError: snapshot.fullOutputError,\n\t\t\t\t\t};\n\t\t\t\t\tif (!projection) {\n\t\t\t\t\t\tconst startLine = truncation.totalLines - truncation.outputLines + 1;\n\t\t\t\t\t\tconst endLine = truncation.totalLines;\n\t\t\t\t\t\tif (truncation.lastLinePartial) {\n\t\t\t\t\t\t\tconst lastLineSize = formatSize(output.getLastLineBytes());\n\t\t\t\t\t\t\ttext += `\\n\\n[Showing last ${formatSize(truncation.outputBytes)} of line ${endLine} (line is ${lastLineSize}). ${fullOutputNotice}]`;\n\t\t\t\t\t\t} else if (truncation.truncatedBy === \"lines\") {\n\t\t\t\t\t\t\ttext += `\\n\\n[Showing lines ${startLine}-${endLine} of ${truncation.totalLines}. ${fullOutputNotice}]`;\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\ttext += `\\n\\n[Showing lines ${startLine}-${endLine} of ${truncation.totalLines} (${formatSize(DEFAULT_MAX_BYTES)} limit). ${fullOutputNotice}]`;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif (projection) {\n\t\t\t\t\tdetails = {\n\t\t\t\t\t\t...(details ?? {}),\n\t\t\t\t\t\toutputProjection: {\n\t\t\t\t\t\t\tkind: projection.kind,\n\t\t\t\t\t\t\tinputLines: projection.inputLines,\n\t\t\t\t\t\t\tinputBytes: projection.inputBytes,\n\t\t\t\t\t\t\toutputLines: projection.outputLines,\n\t\t\t\t\t\t\toutputBytes: projection.outputBytes,\n\t\t\t\t\t\t\tomittedLines: projection.omittedLines,\n\t\t\t\t\t\t\tcollapsedPassingLines: projection.collapsedPassingLines,\n\t\t\t\t\t\t},\n\t\t\t\t\t};\n\t\t\t\t\tconst passingNotice =\n\t\t\t\t\t\tprojection.collapsedPassingLines > 0\n\t\t\t\t\t\t\t? ` ${projection.collapsedPassingLines} passing/progress lines collapsed.`\n\t\t\t\t\t\t\t: \"\";\n\t\t\t\t\ttext += `\\n\\n[Test output filtered: retained ${projection.inputLines - projection.omittedLines} of ${projection.inputLines} lines.${passingNotice} ${fullOutputNotice}]`;\n\t\t\t\t}\n\t\t\t\treturn { text, details };\n\t\t\t};\n\n\t\t\tconst appendStatus = (text: string, status: string) => `${text ? `${text}\\n\\n` : \"\"}${status}`;\n\t\t\tconst effectiveTimeoutSeconds =\n\t\t\t\ttypeof timeout === \"number\" && Number.isFinite(timeout) && timeout > 0\n\t\t\t\t\t? resolveCommandTimeoutSeconds(timeout)\n\t\t\t\t\t: (commandTimeoutMsOverride ?? DEFAULT_COMMAND_TIMEOUT_SECONDS * 1000) / 1000;\n\n\t\t\ttry {\n\t\t\t\tif (canFilterCommand) {\n\t\t\t\t\tconst classification = classifyGitCommand(command, getShellEnv());\n\t\t\t\t\tif (classification.eligible && classification.subcommand) {\n\t\t\t\t\t\tconst res = await executeFilteredGit(\n\t\t\t\t\t\t\tcwd,\n\t\t\t\t\t\t\tclassification.subcommand,\n\t\t\t\t\t\t\tclassification.globalOptions || [],\n\t\t\t\t\t\t\tclassification.subcommandArgs || [],\n\t\t\t\t\t\t\t{ signal, timeout: effectiveTimeoutSeconds },\n\t\t\t\t\t\t);\n\t\t\t\t\t\tif (res.exitCode !== -100) {\n\t\t\t\t\t\t\toutput.append(res.rawBytes ?? Buffer.from(res.rawOut, \"utf-8\"));\n\t\t\t\t\t\t\tconst snapshot = await finishOutput();\n\t\t\t\t\t\t\tif (res.exitCode !== 0) {\n\t\t\t\t\t\t\t\tconst { text: rawOutputText } = formatOutput(snapshot);\n\t\t\t\t\t\t\t\tthrow new Error(appendStatus(rawOutputText, `Command exited with code ${res.exitCode}`));\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tconst details = snapshot.truncation.truncated\n\t\t\t\t\t\t\t\t? {\n\t\t\t\t\t\t\t\t\t\ttruncation: snapshot.truncation,\n\t\t\t\t\t\t\t\t\t\tfullOutputPath: snapshot.fullOutputPath,\n\t\t\t\t\t\t\t\t\t\tfullOutputError: snapshot.fullOutputError,\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t: snapshot.fullOutputPath || snapshot.fullOutputError\n\t\t\t\t\t\t\t\t\t? { fullOutputPath: snapshot.fullOutputPath, fullOutputError: snapshot.fullOutputError }\n\t\t\t\t\t\t\t\t\t: undefined;\n\t\t\t\t\t\t\treturn { content: [{ type: \"text\", text: res.output }], details };\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tlet backendCommand = command;\n\t\t\t\tlet engineRoute = false;\n\t\t\t\tlet effectiveCwd = cwd;\n\t\t\t\tif (routesWindowsContract) {\n\t\t\t\t\tconst route = routeShellContract(command, contractPlatform, { pythonEngine: pythonEngineEnabled });\n\t\t\t\t\tif (route.kind === \"unsupported\") throw new Error(route.error);\n\t\t\t\t\tif (route.kind === \"python-engine\") engineRoute = true;\n\t\t\t\t\tbackendCommand = route.command;\n\t\t\t\t\t// The engine is the sole state mutator (D4); every Windows call — engine or PS\n\t\t\t\t\t// tier — reads the SAME session state so a `cd`/`export` in one call is observed\n\t\t\t\t\t// by the very next call regardless of which tier runs it.\n\t\t\t\t\teffectiveCwd = resolveEffectiveCwd(getOrCreateWindowsShellState(sessionKey), cwd);\n\t\t\t\t}\n\t\t\t\t// The engine executes the RAW Bash source unchanged: no commandPrefix (arbitrary\n\t\t\t\t// PowerShell setup would not parse as Bash grammar) and no PowerShell UTF-8 prefix.\n\t\t\t\tconst resolvedCommand = engineRoute\n\t\t\t\t\t? backendCommand\n\t\t\t\t\t: backendShell === \"powershell\"\n\t\t\t\t\t\t? prefixPowerShellCommand(commandPrefix ? `${commandPrefix}\\n${backendCommand}` : backendCommand)\n\t\t\t\t\t\t: commandPrefix\n\t\t\t\t\t\t\t? `${commandPrefix}\\n${backendCommand}`\n\t\t\t\t\t\t\t: backendCommand;\n\t\t\t\tconst spawnContext = resolveSpawnContext(resolvedCommand, effectiveCwd, spawnHook);\n\t\t\t\tif (routesWindowsContract) {\n\t\t\t\t\tspawnContext.env = mergeEffectiveEnv(getOrCreateWindowsShellState(sessionKey), spawnContext.env);\n\t\t\t\t}\n\n\t\t\t\tlet exitCode: number | null;\n\t\t\t\ttry {\n\t\t\t\t\t// Shell commands cannot statically declare which files they mutate, so the\n\t\t\t\t\t// actual execution takes the coarse exclusive barrier: it waits for\n\t\t\t\t\t// in-flight edit/write mutations to drain and blocks new ones meanwhile.\n\t\t\t\t\tconst result = await withExclusiveMutationBarrier(() =>\n\t\t\t\t\t\t(engineRoute && engineOperations ? engineOperations : ops).exec(\n\t\t\t\t\t\t\tspawnContext.command,\n\t\t\t\t\t\t\tspawnContext.cwd,\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tonData: handleData,\n\t\t\t\t\t\t\t\tsignal,\n\t\t\t\t\t\t\t\ttimeout: effectiveTimeoutSeconds,\n\t\t\t\t\t\t\t\tenv: spawnContext.env,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t),\n\t\t\t\t\t);\n\t\t\t\t\texitCode = result.exitCode;\n\t\t\t\t} catch (err) {\n\t\t\t\t\tconst snapshot = await finishOutput();\n\t\t\t\t\tconst { text } = formatOutput(snapshot, \"\");\n\t\t\t\t\tif (err instanceof Error && err.message === \"aborted\") {\n\t\t\t\t\t\tthrow new Error(appendStatus(text, \"Command aborted\"));\n\t\t\t\t\t}\n\t\t\t\t\tif (err instanceof Error && err.message.startsWith(\"timeout:\")) {\n\t\t\t\t\t\tconst timeoutSecs = err.message.split(\":\")[1];\n\t\t\t\t\t\tthrow new Error(appendStatus(text, `Command timed out after ${timeoutSecs} seconds`));\n\t\t\t\t\t}\n\t\t\t\t\tif (err instanceof Error && err.message.startsWith(\"silence:\")) {\n\t\t\t\t\t\tconst secs = err.message.split(\":\")[1];\n\t\t\t\t\t\tconst recovery =\n\t\t\t\t\t\t\tbackendShell === \"bash\"\n\t\t\t\t\t\t\t\t? \"re-run it with an explicit timeout, or run it in the background with '&'.\"\n\t\t\t\t\t\t\t\t: \"re-run it with an explicit timeout.\";\n\t\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t\tappendStatus(\n\t\t\t\t\t\t\t\ttext,\n\t\t\t\t\t\t\t\t`Command killed after ${secs}s of silence (no output). If the command is legitimately quiet for long stretches, ${recovery}`,\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t\tthrow err;\n\t\t\t\t}\n\n\t\t\t\tconst candidateProjection = finishProjection(exitCode);\n\t\t\t\tconst snapshot = await finishOutput(candidateProjection !== undefined);\n\t\t\t\tconst projection = candidateProjection && snapshot.fullOutputPath ? candidateProjection : undefined;\n\t\t\t\tconst { text: outputText, details } = formatOutput(snapshot, \"(no output)\", projection);\n\t\t\t\tif (exitCode !== 0 && exitCode !== null) {\n\t\t\t\t\tthrow new Error(appendStatus(outputText, `Command exited with code ${exitCode}`));\n\t\t\t\t}\n\t\t\t\treturn { content: [{ type: \"text\", text: outputText }], details };\n\t\t\t} finally {\n\t\t\t\tclearUpdateTimer();\n\t\t\t\tawait output.closeTempFile();\n\t\t\t}\n\t\t},\n\t\trenderCall(args, _theme, context) {\n\t\t\tconst state = context.state;\n\t\t\tif (context.executionStarted && state.startedAt === undefined) {\n\t\t\t\tstate.startedAt = Date.now();\n\t\t\t\tstate.endedAt = undefined;\n\t\t\t}\n\t\t\tconst text = (context.lastComponent as Text | undefined) ?? new Text(\"\", 0, 0);\n\t\t\ttext.setText(formatBashCall(args, toolName));\n\t\t\treturn text;\n\t\t},\n\t\trenderResult(result, options, _theme, context) {\n\t\t\tconst state = context.state;\n\t\t\tif (state.startedAt !== undefined && options.isPartial && !state.interval) {\n\t\t\t\tstate.interval = setInterval(() => context.invalidate(), 1000);\n\t\t\t}\n\t\t\tif (!options.isPartial || context.isError) {\n\t\t\t\tstate.endedAt ??= Date.now();\n\t\t\t\tif (state.interval) {\n\t\t\t\t\tclearInterval(state.interval);\n\t\t\t\t\tstate.interval = undefined;\n\t\t\t\t}\n\t\t\t}\n\t\t\tconst component =\n\t\t\t\t(context.lastComponent as BashResultRenderComponent | undefined) ?? new BashResultRenderComponent();\n\t\t\trebuildBashResultRenderComponent(\n\t\t\t\tcomponent,\n\t\t\t\tresult as any,\n\t\t\t\toptions,\n\t\t\t\tcontext.showImages,\n\t\t\t\tstate.startedAt,\n\t\t\t\tstate.endedAt,\n\t\t\t);\n\t\t\tcomponent.invalidate();\n\t\t\treturn component;\n\t\t},\n\t};\n}\n\nexport function createBashToolDefinition(\n\tcwd: string,\n\toptions?: BashToolOptions,\n): ToolDefinition<typeof bashSchema, BashToolDetails | undefined, BashRenderState> {\n\tconst platform = options?.platform ?? process.platform;\n\treturn createShellToolDefinition(cwd, getPlatformShellToolName(platform), platform, options);\n}\n\nexport function createBashTool(cwd: string, options?: BashToolOptions): AgentTool<typeof bashSchema> {\n\treturn wrapToolDefinition(createBashToolDefinition(cwd, options));\n}\n"]}
1
+ {"version":3,"file":"bash.js","sourceRoot":"","sources":["../../../src/core/tools/bash.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AACpC,OAAO,EAAE,MAAM,IAAI,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AACtD,OAAO,EAAkB,qBAAqB,EAAE,MAAM,2BAA2B,CAAC;AAClF,OAAO,EACN,iBAAiB,EACjB,iBAAiB,EACjB,UAAU,GAEV,MAAM,gCAAgC,CAAC;AACxC,OAAO,EAAE,SAAS,EAAE,IAAI,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACtE,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AACtC,OAAO,EAAe,IAAI,EAAE,MAAM,SAAS,CAAC;AAC5C,OAAO,EAAE,OAAO,EAAE,MAAM,wDAAwD,CAAC;AACjF,OAAO,EAAE,qBAAqB,EAAE,MAAM,uDAAuD,CAAC;AAC9F,OAAO,EAAE,KAAK,EAAE,MAAM,wCAAwC,CAAC;AAC/D,OAAO,EAAE,kCAAkC,EAAE,MAAM,8BAA8B,CAAC;AAClF,OAAO,EACN,wBAAwB,EACxB,cAAc,EACd,WAAW,EAEX,uBAAuB,EACvB,qBAAqB,EACrB,uBAAuB,GACvB,MAAM,sBAAsB,CAAC;AAE9B,OAAO,EAAE,4BAA4B,EAAE,MAAM,0BAA0B,CAAC;AACxE,OAAO,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AACzE,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAC5D,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAC;AACvE,OAAO,EAAE,sBAAsB,EAAE,yB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OAAO,EAAE,MAAM,EAAE,OAAO;YAC5C,MAAM,SAAS,GACb,OAAO,CAAC,aAAuD,IAAI,IAAI,yBAAyB,EAAE,CAAC;YACrG,gCAAgC,CAAC,SAAS,EAAE,MAAa,EAAE,OAAO,EAAE,OAAO,CAAC,UAAU,CAAC,CAAC;YACxF,SAAS,CAAC,UAAU,EAAE,CAAC;YACvB,OAAO,SAAS,CAAC;QAClB,CAAC;KACD,CAAC;AACH,CAAC;AAED,MAAM,UAAU,wBAAwB,CACvC,GAAW,EACX,OAAyB;IAEzB,MAAM,QAAQ,GAAG,OAAO,EAAE,QAAQ,IAAI,OAAO,CAAC,QAAQ,CAAC;IACvD,OAAO,yBAAyB,CAAC,GAAG,EAAE,wBAAwB,CAAC,QAAQ,CAAC,EAAE,QAAQ,EAAE,OAAO,CAAC,CAAC;AAC9F,CAAC;AAED,MAAM,UAAU,cAAc,CAAC,GAAW,EAAE,OAAyB;IACpE,OAAO,kBAAkB,CAAC,wBAAwB,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC,CAAC;AACnE,CAAC","sourcesContent":["import { randomUUID } from \"node:crypto\";\nimport { constants } from \"node:fs\";\nimport { access as fsAccess } from \"node:fs/promises\";\nimport { type AgentTool, createSilenceWatchdog } from \"@caupulican/pi-agent-core\";\nimport {\n\tDEFAULT_MAX_BYTES,\n\tDEFAULT_MAX_LINES,\n\tformatSize,\n\ttype TruncationResult,\n} from \"@caupulican/pi-agent-core/node\";\nimport { Container, Text, truncateToWidth } from \"@caupulican/pi-tui\";\nimport { spawn } from \"child_process\";\nimport { type Static, Type } from \"typebox\";\nimport { keyHint } from \"../../modes/interactive/components/keybinding-hints.ts\";\nimport { truncateToVisualLines } from \"../../modes/interactive/components/visual-truncate.ts\";\nimport { theme } from \"../../modes/interactive/theme/theme.ts\";\nimport { waitForChildProcessWithTermination } from \"../../utils/child-process.ts\";\nimport {\n\tgetPlatformShellToolName,\n\tgetShellConfig,\n\tgetShellEnv,\n\ttype PlatformShellToolName,\n\tprefixPowerShellCommand,\n\ttrackDetachedChildPid,\n\tuntrackDetachedChildPid,\n} from \"../../utils/shell.ts\";\nimport type { ToolDefinition, ToolRenderResultOptions } from \"../extensions/types.ts\";\nimport { withExclusiveMutationBarrier } from \"./file-mutation-queue.ts\";\nimport { classifyGitCommand, executeFilteredGit } from \"./git-filter.ts\";\nimport { OutputAccumulator } from \"./output-accumulator.ts\";\nimport { getTextOutput, invalidArgText, str } from \"./render-utils.ts\";\nimport { assessShellSearchScope, BROAD_SEARCH_OUTPUT_ROUTE } from \"./search-command-guard.ts\";\nimport { routeShellContract } from \"./shell-contract-router.ts\";\nimport {\n\tcreateShellOutputProjector,\n\ttype ShellOutputProjection,\n\ttype ShellOutputProjectionDetails,\n} from \"./shell-output-projection.ts\";\nimport { acquirePersistentShellSession } from \"./shell-session.ts\";\nimport { wrapToolDefinition } from \"./tool-definition-wrapper.ts\";\nimport { createWindowsShellEngineOperations, type WindowsShellEngineOptions } from \"./windows-shell-engine.ts\";\nimport { getOrCreateWindowsShellState, mergeEffectiveEnv, resolveEffectiveCwd } from \"./windows-shell-state.ts\";\n\n/** Low-level silence bound retained for direct shell-operation consumers. Agent tool calls always pass a wall-clock bound. */\nconst DEFAULT_COMMAND_SILENCE_MS = 600_000;\n/** Agent-facing wall-clock bound: continuously producing output must not make a command immortal. */\nexport const DEFAULT_COMMAND_TIMEOUT_SECONDS = 120;\nexport const MAX_COMMAND_TIMEOUT_SECONDS = 3600;\nconst MIN_COMMAND_TIMEOUT_SECONDS = 0.1;\nlet commandSilenceMsOverride: number | undefined;\nlet commandTimeoutMsOverride: number | undefined;\n\n/** Test hook: override the low-level silence threshold. Pass undefined to restore the default. */\nexport function setCommandSilenceMsForTests(ms: number | undefined): void {\n\tcommandSilenceMsOverride = ms;\n}\n\n/** Test hook: override the agent tool's default wall-clock bound. Pass undefined to restore it. */\nexport function setCommandTimeoutMsForTests(ms: number | undefined): void {\n\tcommandTimeoutMsOverride = ms;\n}\n\nexport function resolveCommandTimeoutSeconds(timeout: number | undefined): number {\n\tif (typeof timeout !== \"number\" || !Number.isFinite(timeout) || timeout <= 0) {\n\t\treturn DEFAULT_COMMAND_TIMEOUT_SECONDS;\n\t}\n\treturn Math.max(MIN_COMMAND_TIMEOUT_SECONDS, Math.min(timeout, MAX_COMMAND_TIMEOUT_SECONDS));\n}\n\nconst bashSchema = Type.Object({\n\tcommand: Type.String({ description: \"Shell command to execute\" }),\n\ttimeout: Type.Optional(\n\t\tType.Number({\n\t\t\tdescription: `Wall-clock timeout in seconds. Defaults to ${DEFAULT_COMMAND_TIMEOUT_SECONDS}; positive overrides are capped at ${MAX_COMMAND_TIMEOUT_SECONDS}. Zero or negative values use the default.`,\n\t\t}),\n\t),\n\tbroadSearch: Type.Optional(\n\t\tType.Literal(BROAD_SEARCH_OUTPUT_ROUTE, {\n\t\t\tdescription:\n\t\t\t\t\"Explicit override for a broad rg/grep/find/fd scan that cannot be narrowed. The command runs, but its complete output is routed to a file and excluded from model context.\",\n\t\t}),\n\t),\n});\n\nexport type BashToolInput = Static<typeof bashSchema>;\n\nexport interface BashToolDetails {\n\ttruncation?: TruncationResult;\n\tfullOutputPath?: string;\n\tfullOutputError?: string;\n\tpersistedOutputTruncated?: boolean;\n\tpersistedOutputBytes?: number;\n\tpreview?: {\n\t\tcontent: string;\n\t\tskippedLines: number;\n\t};\n\toutputProjection?: ShellOutputProjectionDetails;\n}\n\n/**\n * Pluggable operations for the bash tool.\n * Override these to delegate command execution to remote systems (for example SSH).\n */\nexport interface BashOperations {\n\t/**\n\t * Execute a command and stream output.\n\t * @param command The command to execute\n\t * @param cwd Working directory\n\t * @param options Execution options\n\t * @returns Promise resolving to exit code (null if killed)\n\t */\n\texec: (\n\t\tcommand: string,\n\t\tcwd: string,\n\t\toptions: {\n\t\t\tonData: (data: Buffer) => void;\n\t\t\tsignal?: AbortSignal;\n\t\t\ttimeout?: number;\n\t\t\tenv?: NodeJS.ProcessEnv;\n\t\t},\n\t) => Promise<{ exitCode: number | null }>;\n}\n\nfunction createLocalShellOperations(\n\tshellName: PlatformShellToolName,\n\toptions?: { shellPath?: string; sessionKey?: string },\n): BashOperations {\n\t// A session key selects the persistent per-agent backend. An explicit custom shell path keeps\n\t// per-command spawning: persistent sessions assume the resolved platform shell's flag set.\n\tconst sessionKey = options?.sessionKey;\n\tif (sessionKey !== undefined && !options?.shellPath) {\n\t\treturn {\n\t\t\texec: async (command, cwd, { onData, signal, timeout, env }) => {\n\t\t\t\ttry {\n\t\t\t\t\tawait fsAccess(cwd, constants.F_OK);\n\t\t\t\t} catch {\n\t\t\t\t\tthrow new Error(`Working directory does not exist: ${cwd}\\nCannot execute ${shellName} commands.`);\n\t\t\t\t}\n\t\t\t\tif (signal?.aborted) throw new Error(\"aborted\");\n\t\t\t\tconst session = acquirePersistentShellSession(sessionKey, shellName);\n\t\t\t\tconst silenceMs = commandSilenceMsOverride ?? DEFAULT_COMMAND_SILENCE_MS;\n\t\t\t\tconst hasWallClock = timeout !== undefined && timeout > 0;\n\t\t\t\treturn session.exec(command, cwd, {\n\t\t\t\t\tonData,\n\t\t\t\t\tsignal,\n\t\t\t\t\tenv,\n\t\t\t\t\ttimeoutSeconds: hasWallClock ? timeout : undefined,\n\t\t\t\t\tsilenceMs: !hasWallClock && silenceMs > 0 ? silenceMs : undefined,\n\t\t\t\t});\n\t\t\t},\n\t\t};\n\t}\n\treturn {\n\t\texec: async (command, cwd, { onData, signal, timeout, env }) => {\n\t\t\tconst { shell, args } = getShellConfig(options?.shellPath, shellName);\n\t\t\ttry {\n\t\t\t\tawait fsAccess(cwd, constants.F_OK);\n\t\t\t} catch {\n\t\t\t\tthrow new Error(`Working directory does not exist: ${cwd}\\nCannot execute ${shellName} commands.`);\n\t\t\t}\n\t\t\tif (signal?.aborted) throw new Error(\"aborted\");\n\n\t\t\tconst child = spawn(shell, [...args, command], {\n\t\t\t\tcwd,\n\t\t\t\tdetached: process.platform !== \"win32\",\n\t\t\t\tenv: env ?? getShellEnv(),\n\t\t\t\tstdio: [\"ignore\", \"pipe\", \"pipe\"],\n\t\t\t\twindowsHide: true,\n\t\t\t});\n\t\t\tif (child.pid) trackDetachedChildPid(child.pid);\n\t\t\tconst terminationController = new AbortController();\n\t\t\tconst onAbort = () => terminationController.abort();\n\t\t\tlet silenceKilled = false;\n\t\t\tconst silenceMs = commandSilenceMsOverride ?? DEFAULT_COMMAND_SILENCE_MS;\n\t\t\tconst silenceWatchdog =\n\t\t\t\t(timeout === undefined || timeout <= 0) && silenceMs > 0\n\t\t\t\t\t? createSilenceWatchdog({\n\t\t\t\t\t\t\tsilenceMs,\n\t\t\t\t\t\t\tonSilence: () => {\n\t\t\t\t\t\t\t\tsilenceKilled = true;\n\t\t\t\t\t\t\t\tterminationController.abort();\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t})\n\t\t\t\t\t: undefined;\n\t\t\tconst onChunk = (data: Buffer) => {\n\t\t\t\tsilenceWatchdog?.touch();\n\t\t\t\tonData(data);\n\t\t\t};\n\n\t\t\ttry {\n\t\t\t\tchild.stdout?.on(\"data\", onChunk);\n\t\t\t\tchild.stderr?.on(\"data\", onChunk);\n\t\t\t\tif (signal) {\n\t\t\t\t\tif (signal.aborted) onAbort();\n\t\t\t\t\telse signal.addEventListener(\"abort\", onAbort, { once: true });\n\t\t\t\t}\n\t\t\t\tconst terminal = await waitForChildProcessWithTermination(child, {\n\t\t\t\t\tsignal: terminationController.signal,\n\t\t\t\t\ttimeoutMs: timeout !== undefined && timeout > 0 ? timeout * 1000 : undefined,\n\t\t\t\t\tkillGraceMs: 2_000,\n\t\t\t\t});\n\t\t\t\tif (signal?.aborted) throw new Error(\"aborted\");\n\t\t\t\tif (terminal.reason === \"timeout\") throw new Error(`timeout:${timeout}`);\n\t\t\t\tif (silenceKilled) throw new Error(`silence:${silenceMs / 1000}`);\n\t\t\t\treturn { exitCode: terminal.code };\n\t\t\t} finally {\n\t\t\t\tsilenceWatchdog?.disarm();\n\t\t\t\tif (child.pid) untrackDetachedChildPid(child.pid);\n\t\t\t\tif (signal) signal.removeEventListener(\"abort\", onAbort);\n\t\t\t}\n\t\t},\n\t};\n}\n\n/**\n * Create bash operations using pi's built-in local shell execution backend.\n *\n * This is useful for extensions that intercept user_bash and still want pi's\n * standard local shell behavior while wrapping or rewriting commands.\n */\nexport function createLocalBashOperations(options?: { shellPath?: string; sessionKey?: string }): BashOperations {\n\treturn createLocalShellOperations(\"bash\", options);\n}\n\n/** Create PowerShell operations using pi's built-in local execution backend. */\nexport function createLocalPowerShellOperations(options?: { shellPath?: string; sessionKey?: string }): BashOperations {\n\treturn createLocalShellOperations(\"powershell\", options);\n}\n\n/** Create the platform shell backend without requiring callers or the model to choose a shell. */\nexport function createLocalPlatformShellOperations(\n\toptions: {\n\t\tshellPath?: string;\n\t\tcommandPrefix?: string;\n\t\toperations?: BashOperations;\n\t\tsessionKey?: string;\n\t\t/** Route complex/state-mutating Bash constructs and portable builtins to the Python engine on Windows. Default: true. */\n\t\tpythonEngine?: boolean;\n\t\t/** Test/embedding hook: overrides the engine tier's runtime/spawn/state resolution. */\n\t\tengineOptions?: WindowsShellEngineOptions;\n\t} = {},\n\tplatform: NodeJS.Platform = process.platform,\n): BashOperations {\n\tconst operations =\n\t\toptions.operations ??\n\t\tcreateLocalShellOperations(getPlatformShellToolName(platform), {\n\t\t\tshellPath: options.shellPath,\n\t\t\tsessionKey: options.sessionKey,\n\t\t});\n\tconst pythonEngineEnabled = options.pythonEngine !== false;\n\t// One factory instance is one fallback tenant. Production agent sessions always pass their\n\t// stable key; standalone callers that omit it must never collapse into a process-global engine.\n\tconst engineSessionKey = options.sessionKey ?? `platform-shell-operations:${randomUUID()}`;\n\tconst engineOperations = createWindowsShellEngineOperations(engineSessionKey, options.engineOptions);\n\treturn {\n\t\tasync exec(command, cwd, execOptions) {\n\t\t\tlet resolvedCommand = command;\n\t\t\tlet resolvedCwd = cwd;\n\t\t\tlet resolvedExecOptions = execOptions;\n\t\t\tif (platform === \"win32\") {\n\t\t\t\tconst route = routeShellContract(command, platform, { pythonEngine: pythonEngineEnabled });\n\t\t\t\tif (route.kind === \"unsupported\") throw new Error(route.error);\n\t\t\t\t// The engine is the sole state mutator (D4); every Windows call — engine or PS\n\t\t\t\t// tier — reads the SAME session state so a `cd`/`export` in one call is observed\n\t\t\t\t// by the very next call regardless of which tier runs it.\n\t\t\t\tconst state = getOrCreateWindowsShellState(engineSessionKey);\n\t\t\t\tresolvedCwd = resolveEffectiveCwd(state, cwd);\n\t\t\t\tresolvedExecOptions = { ...execOptions, env: mergeEffectiveEnv(state, execOptions.env ?? getShellEnv()) };\n\t\t\t\tif (route.kind === \"python-engine\") {\n\t\t\t\t\t// The engine owns the state transition and resolves the original host cwd\n\t\t\t\t\t// exactly once. Passing the already state-adjusted cwd here would make the\n\t\t\t\t\t// engine mistake its own `cd` result for a host cwd change on the next call.\n\t\t\t\t\treturn engineOperations.exec(route.command, cwd, execOptions);\n\t\t\t\t}\n\t\t\t\tif (route.kind === \"powershell\") resolvedCommand = route.command;\n\t\t\t}\n\t\t\tif (options.commandPrefix) resolvedCommand = `${options.commandPrefix}\\n${resolvedCommand}`;\n\t\t\tif (platform === \"win32\") resolvedCommand = prefixPowerShellCommand(resolvedCommand);\n\t\t\treturn operations.exec(resolvedCommand, resolvedCwd, resolvedExecOptions);\n\t\t},\n\t};\n}\n\nexport interface BashSpawnContext {\n\tcommand: string;\n\tcwd: string;\n\tenv: NodeJS.ProcessEnv;\n}\n\nexport type BashSpawnHook = (context: BashSpawnContext) => BashSpawnContext;\n\nfunction resolveSpawnContext(command: string, cwd: string, spawnHook?: BashSpawnHook): BashSpawnContext {\n\tconst baseContext: BashSpawnContext = { command, cwd, env: { ...getShellEnv() } };\n\treturn spawnHook ? spawnHook(baseContext) : baseContext;\n}\n\nexport interface BashToolOptions {\n\t/** Platform used to choose the default backend and contract router. Defaults to process.platform. */\n\tplatform?: NodeJS.Platform;\n\t/** Custom operations for command execution. Default: local platform shell */\n\toperations?: BashOperations;\n\t/** Command prefix prepended to every command (for example shell setup commands) */\n\tcommandPrefix?: string;\n\t/** Optional explicit shell path from settings */\n\tshellPath?: string;\n\t/** Hook to adjust command, cwd, or env before execution */\n\tspawnHook?: BashSpawnHook;\n\t/**\n\t * Stable key for this agent's persistent shell session. The host passes its per-agent key so\n\t * the session survives runtime reloads and user `!` commands share it; separately created\n\t * tool instances (subagents) auto-generate their own key and stay isolated.\n\t */\n\tsessionKey?: string;\n\t/** Route complex/state-mutating Bash constructs and portable builtins to the Python engine on Windows. Default: true. */\n\twindowsShellPythonEngine?: boolean;\n\t/** Test/embedding hook: overrides the engine tier's runtime/spawn/state resolution. */\n\twindowsShellEngineOptions?: WindowsShellEngineOptions;\n\t/** Test/embedding hook: override the managed directory used for complete command output. */\n\toutputDirectory?: string;\n}\n\nconst BASH_PREVIEW_LINES = 5;\nconst BASH_PREVIEW_BYTES = 8 * 1024;\nconst BASH_UPDATE_THROTTLE_MS = 100;\nconst BROAD_SEARCH_MAX_PERSISTED_BYTES = 8 * 1024 * 1024;\n\ntype BashResultRenderState = {\n\tcachedWidth: number | undefined;\n\tcachedLines: string[] | undefined;\n\tcachedSkipped: number | undefined;\n};\n\nclass BashResultRenderComponent extends Container {\n\tstate: BashResultRenderState = {\n\t\tcachedWidth: undefined,\n\t\tcachedLines: undefined,\n\t\tcachedSkipped: undefined,\n\t};\n}\n\nfunction formatBashCall(\n\targs: { command?: string; timeout?: number } | undefined,\n\tshellName: PlatformShellToolName,\n): string {\n\tconst command = str(args?.command);\n\tconst timeout = args?.timeout as number | undefined;\n\tconst timeoutSuffix = timeout ? theme.fg(\"muted\", ` (timeout ${timeout}s)`) : \"\";\n\tconst commandDisplay = command === null ? invalidArgText(theme) : command ? command : theme.fg(\"toolOutput\", \"...\");\n\tconst prompt = shellName === \"powershell\" ? \"PS>\" : \"$\";\n\treturn theme.fg(\"toolTitle\", theme.bold(`${prompt} ${commandDisplay}`)) + timeoutSuffix;\n}\n\nfunction rebuildBashResultRenderComponent(\n\tcomponent: BashResultRenderComponent,\n\tresult: {\n\t\tcontent: Array<{ type: string; text?: string; data?: string; mimeType?: string }>;\n\t\tdetails?: BashToolDetails;\n\t},\n\toptions: ToolRenderResultOptions,\n\tshowImages: boolean,\n): void {\n\tconst state = component.state;\n\tcomponent.clear();\n\n\tconst renderPreview = !options.expanded ? result.details?.preview : undefined;\n\tlet output = (renderPreview ? renderPreview.content : getTextOutput(result as any, showImages)).trim();\n\tconst truncation = result.details?.truncation;\n\tconst fullOutputPath = result.details?.fullOutputPath;\n\tconst fullOutputError = result.details?.fullOutputError;\n\tif (!options.isPartial && truncation?.truncated && fullOutputPath && output.endsWith(\"]\")) {\n\t\tconst footerStart = output.lastIndexOf(\"\\n\\n[\");\n\t\tif (footerStart !== -1 && output.slice(footerStart).includes(fullOutputPath)) {\n\t\t\toutput = output.slice(0, footerStart).trimEnd();\n\t\t}\n\t}\n\n\tif (output) {\n\t\tif (options.expanded) {\n\t\t\tconst styledOutput = output\n\t\t\t\t.split(\"\\n\")\n\t\t\t\t.map((line) => theme.fg(\"toolOutput\", line))\n\t\t\t\t.join(\"\\n\");\n\t\t\tcomponent.addChild(new Text(`\\n${styledOutput}`, 0, 0));\n\t\t} else {\n\t\t\tcomponent.addChild({\n\t\t\t\trender: (width: number) => {\n\t\t\t\t\tif (state.cachedLines === undefined || state.cachedWidth !== width) {\n\t\t\t\t\t\tconst preview = truncateToVisualLines(output, BASH_PREVIEW_LINES, width);\n\t\t\t\t\t\tstate.cachedLines = preview.visualLines.map((line) => theme.fg(\"toolOutput\", line));\n\t\t\t\t\t\tstate.cachedSkipped = (result.details?.preview?.skippedLines ?? 0) + preview.skippedCount;\n\t\t\t\t\t\tstate.cachedWidth = width;\n\t\t\t\t\t}\n\t\t\t\t\tif (state.cachedSkipped && state.cachedSkipped > 0) {\n\t\t\t\t\t\tconst hint =\n\t\t\t\t\t\t\ttheme.fg(\"muted\", `... (${state.cachedSkipped} earlier lines,`) +\n\t\t\t\t\t\t\t` ${keyHint(\"app.tools.expand\", \"to expand\")})`;\n\t\t\t\t\t\treturn [\"\", truncateToWidth(hint, width, \"...\"), ...(state.cachedLines ?? [])];\n\t\t\t\t\t}\n\t\t\t\t\treturn [\"\", ...(state.cachedLines ?? [])];\n\t\t\t\t},\n\t\t\t\tinvalidate: () => {\n\t\t\t\t\tstate.cachedWidth = undefined;\n\t\t\t\t\tstate.cachedLines = undefined;\n\t\t\t\t\tstate.cachedSkipped = undefined;\n\t\t\t\t},\n\t\t\t});\n\t\t}\n\t}\n\n\tif (truncation?.truncated || fullOutputPath || fullOutputError) {\n\t\tconst warnings: string[] = [];\n\t\tif (fullOutputPath) {\n\t\t\twarnings.push(`Full output: ${fullOutputPath}`);\n\t\t} else if (fullOutputError) {\n\t\t\twarnings.push(`Full output unavailable: ${fullOutputError}`);\n\t\t}\n\t\tif (truncation?.truncated) {\n\t\t\tif (truncation.truncatedBy === \"lines\") {\n\t\t\t\twarnings.push(`Truncated: showing ${truncation.outputLines} of ${truncation.totalLines} lines`);\n\t\t\t} else {\n\t\t\t\twarnings.push(\n\t\t\t\t\t`Truncated: ${truncation.outputLines} lines shown (${formatSize(truncation.maxBytes ?? DEFAULT_MAX_BYTES)} limit)`,\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t\tcomponent.addChild(new Text(`\\n${theme.fg(\"warning\", `[${warnings.join(\". \")}]`)}`, 0, 0));\n\t}\n}\n\nfunction createShellToolDefinition(\n\tcwd: string,\n\tbackendShell: PlatformShellToolName,\n\tcontractPlatform: NodeJS.Platform,\n\toptions?: BashToolOptions,\n): ToolDefinition<typeof bashSchema, BashToolDetails | undefined> {\n\tconst toolName = \"bash\";\n\tconst sessionKey = options?.sessionKey ?? `bash-tool:${randomUUID()}`;\n\tconst ops =\n\t\toptions?.operations ??\n\t\t(backendShell === \"powershell\"\n\t\t\t? createLocalPowerShellOperations({ shellPath: options?.shellPath, sessionKey })\n\t\t\t: createLocalBashOperations({ shellPath: options?.shellPath, sessionKey }));\n\tconst commandPrefix = options?.commandPrefix;\n\tconst spawnHook = options?.spawnHook;\n\tconst hasExecutionOverrides = Boolean(options?.operations || options?.shellPath || commandPrefix || spawnHook);\n\tconst canFilterCommand = !hasExecutionOverrides;\n\tconst routesWindowsContract = contractPlatform === \"win32\";\n\tconst pythonEngineEnabled = options?.windowsShellPythonEngine !== false;\n\tconst engineOperations = routesWindowsContract\n\t\t? createWindowsShellEngineOperations(sessionKey, options?.windowsShellEngineOptions)\n\t\t: undefined;\n\tconst contractDescription = routesWindowsContract\n\t\t? \"Execute Pi's stable Bash-like command contract in a persistent per-agent shell session (current directory and environment variables persist across calls, including across the PowerShell and Python engine tiers). On Windows, a deterministic router converts simple commands directly to PowerShell and routes word-list and arithmetic for loops, break/continue, portable builtins such as printf, pipelines, redirection, expansion, chaining, and state-mutating commands (cd/export/unset) through a bundled Python engine that implements the supported Bash grammar; named unsupported constructs (job control, process substitution, heredocs, nested shells, and similar) fail closed instead of being guessed.\"\n\t\t: \"Execute a Bash command in a persistent per-agent shell session: the current directory and environment variables persist across calls, and a timed-out or aborted command resets the session.\";\n\treturn {\n\t\tname: toolName,\n\t\tlabel: toolName,\n\t\tdescription: `${contractDescription} Returns stdout and stderr. Output is truncated to last ${DEFAULT_MAX_LINES} lines or ${DEFAULT_MAX_BYTES / 1024}KB (whichever is hit first). If truncated, full output is saved to a managed file. Recognized test runners return a bounded failure/summary projection when it is materially smaller, with exact output saved to a managed file. Broad rg/grep/find/fd scans are rejected before execution; when an exhaustive scan is unavoidable, set broadSearch=\"${BROAD_SEARCH_OUTPUT_ROUTE}\" to route all output to a managed file instead of model context. Commands have a ${DEFAULT_COMMAND_TIMEOUT_SECONDS}-second wall-clock default, including commands that keep producing output; use a positive timeout only when a scoped operation justifies a larger bound (maximum ${MAX_COMMAND_TIMEOUT_SECONDS} seconds).`,\n\t\tpromptSnippet: routesWindowsContract\n\t\t\t? \"Execute Bash-like commands; Pi routes them deterministically to PowerShell or a bundled Python engine on Windows\"\n\t\t\t: \"Execute Bash commands (ls, grep, find, etc.)\",\n\t\tpromptGuidelines: routesWindowsContract\n\t\t\t? [\n\t\t\t\t\t\"Use ordinary Bash-like commands on Windows; do not write PowerShell or ask the user to choose a shell.\",\n\t\t\t\t\t\"Word-list and arithmetic for loops, nested break/continue, printf and the documented portable builtins, pipelines, redirection, expansion (variables, command substitution, globs), chaining (&&/||/;), and cd/export/unset are supported and routed to a bundled Python engine; shell arithmetic expansion outside a for header, job control, process substitution, heredocs, nested shells, and other named constructs fail closed with an actionable message instead of being guessed.\",\n\t\t\t\t\t\"Working directory and environment changes from cd/export/unset persist across subsequent bash calls, including calls that route to the PowerShell tier.\",\n\t\t\t\t\t\"Supported Bash-like file commands are converted with literal-path operations; verify targets before recursive rm, cp, or mv calls.\",\n\t\t\t\t\t`Keep searches scoped and purpose-driven: discover paths first, pass an explicit root and filters, and prefer the bounded grep/find tools. Broad shell searches are rejected; use broadSearch=\"${BROAD_SEARCH_OUTPUT_ROUTE}\" only for an unavoidable exhaustive scan, then inspect the returned file with bounded reads or narrower searches.`,\n\t\t\t\t]\n\t\t\t: [\n\t\t\t\t\t`Keep searches scoped and purpose-driven: discover paths first, pass an explicit root and filters, and prefer the bounded grep/find tools. Broad shell searches are rejected; use broadSearch=\"${BROAD_SEARCH_OUTPUT_ROUTE}\" only for an unavoidable exhaustive scan, then inspect the returned file with bounded reads or narrower searches.`,\n\t\t\t\t],\n\t\tparameters: bashSchema,\n\t\tasync execute(\n\t\t\t_toolCallId,\n\t\t\t{\n\t\t\t\tcommand,\n\t\t\t\ttimeout,\n\t\t\t\tbroadSearch,\n\t\t\t}: { command: string; timeout?: number; broadSearch?: typeof BROAD_SEARCH_OUTPUT_ROUTE },\n\t\t\tsignal?: AbortSignal,\n\t\t\tonUpdate?,\n\t\t\t_ctx?,\n\t\t) {\n\t\t\tconst searchScope = assessShellSearchScope(command, cwd);\n\t\t\tif (searchScope.kind === \"broad\" && broadSearch !== BROAD_SEARCH_OUTPUT_ROUTE) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`Broad search blocked before execution: ${searchScope.reason}. Narrow the path, glob, type, or pattern; prefer the grep/find tool with explicit path/glob/limit. If an exhaustive scan is required, retry with broadSearch=\"${BROAD_SEARCH_OUTPUT_ROUTE}\"; Pi will keep its output out of context and return a managed file path for bounded read or search follow-up.`,\n\t\t\t\t);\n\t\t\t}\n\t\t\tconst routeBroadSearchOutput = searchScope.kind === \"broad\";\n\t\t\tlet outputProjector =\n\t\t\t\trouteBroadSearchOutput || commandPrefix || spawnHook ? undefined : createShellOutputProjector(command);\n\t\t\tconst output = new OutputAccumulator({\n\t\t\t\ttempFilePrefix: `pi-${toolName}`,\n\t\t\t\ttempDirectory: options?.outputDirectory,\n\t\t\t\tpersistAllOutput: routeBroadSearchOutput,\n\t\t\t\tmaxPersistedBytes: routeBroadSearchOutput ? BROAD_SEARCH_MAX_PERSISTED_BYTES : undefined,\n\t\t\t});\n\t\t\tlet updateTimer: NodeJS.Timeout | undefined;\n\t\t\tlet updateDirty = false;\n\t\t\tlet lastUpdateAt = 0;\n\n\t\t\tconst emitOutputUpdate = () => {\n\t\t\t\tif (!onUpdate || !updateDirty) return;\n\t\t\t\tupdateDirty = false;\n\t\t\t\tlastUpdateAt = Date.now();\n\t\t\t\tconst snapshot = output.previewSnapshot(BASH_PREVIEW_LINES, BASH_PREVIEW_BYTES, {\n\t\t\t\t\tpersistIfFullTruncated: true,\n\t\t\t\t});\n\t\t\t\tif (routeBroadSearchOutput) {\n\t\t\t\t\tconst notice = snapshot.fullOutputPath\n\t\t\t\t\t\t? `Broad search running. Output is being routed to ${snapshot.fullOutputPath}`\n\t\t\t\t\t\t: \"Broad search running. Output is being routed to a managed file\";\n\t\t\t\t\tonUpdate({\n\t\t\t\t\t\tcontent: [{ type: \"text\", text: notice }],\n\t\t\t\t\t\tdetails: {\n\t\t\t\t\t\t\tfullOutputPath: snapshot.fullOutputPath,\n\t\t\t\t\t\t\tfullOutputError: snapshot.fullOutputError,\n\t\t\t\t\t\t\tpersistedOutputTruncated: snapshot.persistedOutputTruncated,\n\t\t\t\t\t\t\tpersistedOutputBytes: snapshot.persistedOutputBytes,\n\t\t\t\t\t\t},\n\t\t\t\t\t});\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tconst preview = {\n\t\t\t\t\tcontent: snapshot.content.replace(/\\r/g, \"\"),\n\t\t\t\t\tskippedLines: Math.max(0, snapshot.truncation.totalLines - snapshot.truncation.outputLines),\n\t\t\t\t};\n\t\t\t\tonUpdate({\n\t\t\t\t\tcontent: [{ type: \"text\", text: preview.content || \"\" }],\n\t\t\t\t\tdetails: {\n\t\t\t\t\t\ttruncation: snapshot.truncation.truncated ? snapshot.truncation : undefined,\n\t\t\t\t\t\tfullOutputPath: snapshot.fullOutputPath,\n\t\t\t\t\t\tfullOutputError: snapshot.fullOutputError,\n\t\t\t\t\t\tpreview,\n\t\t\t\t\t},\n\t\t\t\t});\n\t\t\t};\n\n\t\t\tconst clearUpdateTimer = () => {\n\t\t\t\tif (updateTimer) {\n\t\t\t\t\tclearTimeout(updateTimer);\n\t\t\t\t\tupdateTimer = undefined;\n\t\t\t\t}\n\t\t\t};\n\n\t\t\tconst scheduleOutputUpdate = () => {\n\t\t\t\tif (!onUpdate) return;\n\t\t\t\tupdateDirty = true;\n\t\t\t\tconst delay = BASH_UPDATE_THROTTLE_MS - (Date.now() - lastUpdateAt);\n\t\t\t\tif (delay <= 0) {\n\t\t\t\t\tclearUpdateTimer();\n\t\t\t\t\temitOutputUpdate();\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tupdateTimer ??= setTimeout(() => {\n\t\t\t\t\tupdateTimer = undefined;\n\t\t\t\t\temitOutputUpdate();\n\t\t\t\t}, delay);\n\t\t\t};\n\n\t\t\tif (onUpdate) {\n\t\t\t\tonUpdate({ content: [], details: undefined });\n\t\t\t}\n\n\t\t\tconst handleData = (data: Buffer) => {\n\t\t\t\toutput.append(data);\n\t\t\t\tif (outputProjector) {\n\t\t\t\t\ttry {\n\t\t\t\t\t\toutputProjector.append(data);\n\t\t\t\t\t} catch {\n\t\t\t\t\t\t// Projection is opportunistic. Raw output remains authoritative.\n\t\t\t\t\t\toutputProjector = undefined;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tscheduleOutputUpdate();\n\t\t\t};\n\n\t\t\tconst finishOutput = async (persistAlways = false) => {\n\t\t\t\toutput.finish();\n\t\t\t\tclearUpdateTimer();\n\t\t\t\temitOutputUpdate();\n\t\t\t\treturn output.snapshot({ persistIfTruncated: true, persistAlways });\n\t\t\t};\n\n\t\t\tconst finishProjection = (exitCode: number | null): ShellOutputProjection | undefined => {\n\t\t\t\tif (!outputProjector) return undefined;\n\t\t\t\ttry {\n\t\t\t\t\treturn outputProjector.finish(exitCode);\n\t\t\t\t} catch {\n\t\t\t\t\toutputProjector = undefined;\n\t\t\t\t\treturn undefined;\n\t\t\t\t}\n\t\t\t};\n\n\t\t\tconst formatOutput = (\n\t\t\t\tsnapshot: Awaited<ReturnType<typeof finishOutput>>,\n\t\t\t\temptyText = \"(no output)\",\n\t\t\t\tprojection?: ShellOutputProjection,\n\t\t\t) => {\n\t\t\t\tconst truncation = snapshot.truncation;\n\t\t\t\tif (routeBroadSearchOutput) {\n\t\t\t\t\tif (snapshot.fullOutputPath) {\n\t\t\t\t\t\tconst persistenceNotice = snapshot.persistedOutputTruncated\n\t\t\t\t\t\t\t? `The managed ${formatSize(BROAD_SEARCH_MAX_PERSISTED_BYTES)} file limit was reached; later output was discarded.`\n\t\t\t\t\t\t\t: \"\";\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\ttext: `Broad search output routed to ${snapshot.fullOutputPath}. ${persistenceNotice} Inspect it with bounded read offsets or a narrower search.`,\n\t\t\t\t\t\t\tdetails: {\n\t\t\t\t\t\t\t\t...(truncation.truncated ? { truncation } : {}),\n\t\t\t\t\t\t\t\tfullOutputPath: snapshot.fullOutputPath,\n\t\t\t\t\t\t\t\tpersistedOutputTruncated: snapshot.persistedOutputTruncated,\n\t\t\t\t\t\t\t\tpersistedOutputBytes: snapshot.persistedOutputBytes,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\t\t\t\t\tconst boundedTail = snapshot.content.replace(/\\r/g, \"\") || emptyText;\n\t\t\t\t\treturn {\n\t\t\t\t\t\ttext: `Broad search output could not be routed to a managed file${snapshot.fullOutputError ? `: ${snapshot.fullOutputError}` : \"\"}. Bounded tail:\\n${boundedTail}`,\n\t\t\t\t\t\tdetails: {\n\t\t\t\t\t\t\t...(truncation.truncated ? { truncation } : {}),\n\t\t\t\t\t\t\tfullOutputError: snapshot.fullOutputError ?? \"managed output file unavailable\",\n\t\t\t\t\t\t},\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t\tlet text = (projection?.content ?? snapshot.content).replace(/\\r/g, \"\") || emptyText;\n\t\t\t\tlet details: BashToolDetails | undefined;\n\t\t\t\tconst preview = projection\n\t\t\t\t\t? (() => {\n\t\t\t\t\t\t\tconst lines = projection.content.split(\"\\n\");\n\t\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t\tcontent: lines.slice(-BASH_PREVIEW_LINES).join(\"\\n\"),\n\t\t\t\t\t\t\t\tskippedLines: Math.max(0, lines.length - BASH_PREVIEW_LINES),\n\t\t\t\t\t\t\t};\n\t\t\t\t\t\t})()\n\t\t\t\t\t: output.preview(BASH_PREVIEW_LINES, BASH_PREVIEW_BYTES);\n\t\t\t\tconst fullOutputNotice = snapshot.fullOutputPath\n\t\t\t\t\t? `Full output: ${snapshot.fullOutputPath}`\n\t\t\t\t\t: snapshot.fullOutputError\n\t\t\t\t\t\t? `Full output unavailable: ${snapshot.fullOutputError}`\n\t\t\t\t\t\t: \"Full output unavailable\";\n\t\t\t\tif (truncation.truncated || preview.skippedLines > 0 || projection) {\n\t\t\t\t\tdetails = { preview };\n\t\t\t\t}\n\t\t\t\tif (snapshot.fullOutputPath || snapshot.fullOutputError) {\n\t\t\t\t\tdetails = {\n\t\t\t\t\t\t...(details ?? {}),\n\t\t\t\t\t\tfullOutputPath: snapshot.fullOutputPath,\n\t\t\t\t\t\tfullOutputError: snapshot.fullOutputError,\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t\tif (truncation.truncated) {\n\t\t\t\t\tdetails = {\n\t\t\t\t\t\t...(details ?? {}),\n\t\t\t\t\t\ttruncation,\n\t\t\t\t\t\tfullOutputPath: snapshot.fullOutputPath,\n\t\t\t\t\t\tfullOutputError: snapshot.fullOutputError,\n\t\t\t\t\t};\n\t\t\t\t\tif (!projection) {\n\t\t\t\t\t\tconst startLine = truncation.totalLines - truncation.outputLines + 1;\n\t\t\t\t\t\tconst endLine = truncation.totalLines;\n\t\t\t\t\t\tif (truncation.lastLinePartial) {\n\t\t\t\t\t\t\tconst lastLineSize = formatSize(output.getLastLineBytes());\n\t\t\t\t\t\t\ttext += `\\n\\n[Showing last ${formatSize(truncation.outputBytes)} of line ${endLine} (line is ${lastLineSize}). ${fullOutputNotice}]`;\n\t\t\t\t\t\t} else if (truncation.truncatedBy === \"lines\") {\n\t\t\t\t\t\t\ttext += `\\n\\n[Showing lines ${startLine}-${endLine} of ${truncation.totalLines}. ${fullOutputNotice}]`;\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\ttext += `\\n\\n[Showing lines ${startLine}-${endLine} of ${truncation.totalLines} (${formatSize(DEFAULT_MAX_BYTES)} limit). ${fullOutputNotice}]`;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif (projection) {\n\t\t\t\t\tdetails = {\n\t\t\t\t\t\t...(details ?? {}),\n\t\t\t\t\t\toutputProjection: {\n\t\t\t\t\t\t\tkind: projection.kind,\n\t\t\t\t\t\t\tinputLines: projection.inputLines,\n\t\t\t\t\t\t\tinputBytes: projection.inputBytes,\n\t\t\t\t\t\t\toutputLines: projection.outputLines,\n\t\t\t\t\t\t\toutputBytes: projection.outputBytes,\n\t\t\t\t\t\t\tomittedLines: projection.omittedLines,\n\t\t\t\t\t\t\tcollapsedPassingLines: projection.collapsedPassingLines,\n\t\t\t\t\t\t},\n\t\t\t\t\t};\n\t\t\t\t\tconst passingNotice =\n\t\t\t\t\t\tprojection.collapsedPassingLines > 0\n\t\t\t\t\t\t\t? ` ${projection.collapsedPassingLines} passing/progress lines collapsed.`\n\t\t\t\t\t\t\t: \"\";\n\t\t\t\t\ttext += `\\n\\n[Test output filtered: retained ${projection.inputLines - projection.omittedLines} of ${projection.inputLines} lines.${passingNotice} ${fullOutputNotice}]`;\n\t\t\t\t}\n\t\t\t\treturn { text, details };\n\t\t\t};\n\n\t\t\tconst appendStatus = (text: string, status: string) => `${text ? `${text}\\n\\n` : \"\"}${status}`;\n\t\t\tconst effectiveTimeoutSeconds =\n\t\t\t\ttypeof timeout === \"number\" && Number.isFinite(timeout) && timeout > 0\n\t\t\t\t\t? resolveCommandTimeoutSeconds(timeout)\n\t\t\t\t\t: (commandTimeoutMsOverride ?? DEFAULT_COMMAND_TIMEOUT_SECONDS * 1000) / 1000;\n\n\t\t\ttry {\n\t\t\t\tif (canFilterCommand) {\n\t\t\t\t\tconst classification = classifyGitCommand(command, getShellEnv());\n\t\t\t\t\tif (classification.eligible && classification.subcommand) {\n\t\t\t\t\t\tconst res = await executeFilteredGit(\n\t\t\t\t\t\t\tcwd,\n\t\t\t\t\t\t\tclassification.subcommand,\n\t\t\t\t\t\t\tclassification.globalOptions || [],\n\t\t\t\t\t\t\tclassification.subcommandArgs || [],\n\t\t\t\t\t\t\t{ signal, timeout: effectiveTimeoutSeconds },\n\t\t\t\t\t\t);\n\t\t\t\t\t\tif (res.exitCode !== -100) {\n\t\t\t\t\t\t\toutput.append(res.rawBytes ?? Buffer.from(res.rawOut, \"utf-8\"));\n\t\t\t\t\t\t\tconst snapshot = await finishOutput();\n\t\t\t\t\t\t\tif (res.exitCode !== 0) {\n\t\t\t\t\t\t\t\tconst { text: rawOutputText } = formatOutput(snapshot);\n\t\t\t\t\t\t\t\tthrow new Error(appendStatus(rawOutputText, `Command exited with code ${res.exitCode}`));\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tconst details = snapshot.truncation.truncated\n\t\t\t\t\t\t\t\t? {\n\t\t\t\t\t\t\t\t\t\ttruncation: snapshot.truncation,\n\t\t\t\t\t\t\t\t\t\tfullOutputPath: snapshot.fullOutputPath,\n\t\t\t\t\t\t\t\t\t\tfullOutputError: snapshot.fullOutputError,\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t: snapshot.fullOutputPath || snapshot.fullOutputError\n\t\t\t\t\t\t\t\t\t? { fullOutputPath: snapshot.fullOutputPath, fullOutputError: snapshot.fullOutputError }\n\t\t\t\t\t\t\t\t\t: undefined;\n\t\t\t\t\t\t\treturn { content: [{ type: \"text\", text: res.output }], details };\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tlet backendCommand = command;\n\t\t\t\tlet engineRoute = false;\n\t\t\t\tlet effectiveCwd = cwd;\n\t\t\t\tif (routesWindowsContract) {\n\t\t\t\t\tconst route = routeShellContract(command, contractPlatform, { pythonEngine: pythonEngineEnabled });\n\t\t\t\t\tif (route.kind === \"unsupported\") throw new Error(route.error);\n\t\t\t\t\tif (route.kind === \"python-engine\") engineRoute = true;\n\t\t\t\t\tbackendCommand = route.command;\n\t\t\t\t\t// The engine is the sole state mutator (D4); every Windows call — engine or PS\n\t\t\t\t\t// tier — reads the SAME session state so a `cd`/`export` in one call is observed\n\t\t\t\t\t// by the very next call regardless of which tier runs it.\n\t\t\t\t\teffectiveCwd = resolveEffectiveCwd(getOrCreateWindowsShellState(sessionKey), cwd);\n\t\t\t\t}\n\t\t\t\t// The engine executes the RAW Bash source unchanged: no commandPrefix (arbitrary\n\t\t\t\t// PowerShell setup would not parse as Bash grammar) and no PowerShell UTF-8 prefix.\n\t\t\t\tconst resolvedCommand = engineRoute\n\t\t\t\t\t? backendCommand\n\t\t\t\t\t: backendShell === \"powershell\"\n\t\t\t\t\t\t? prefixPowerShellCommand(commandPrefix ? `${commandPrefix}\\n${backendCommand}` : backendCommand)\n\t\t\t\t\t\t: commandPrefix\n\t\t\t\t\t\t\t? `${commandPrefix}\\n${backendCommand}`\n\t\t\t\t\t\t\t: backendCommand;\n\t\t\t\tconst spawnContext = resolveSpawnContext(resolvedCommand, effectiveCwd, spawnHook);\n\t\t\t\tif (routesWindowsContract) {\n\t\t\t\t\tspawnContext.env = mergeEffectiveEnv(getOrCreateWindowsShellState(sessionKey), spawnContext.env);\n\t\t\t\t}\n\n\t\t\t\tlet exitCode: number | null;\n\t\t\t\ttry {\n\t\t\t\t\t// Shell commands cannot statically declare which files they mutate, so the\n\t\t\t\t\t// actual execution takes the coarse exclusive barrier: it waits for\n\t\t\t\t\t// in-flight edit/write mutations to drain and blocks new ones meanwhile.\n\t\t\t\t\tconst result = await withExclusiveMutationBarrier(() =>\n\t\t\t\t\t\t(engineRoute && engineOperations ? engineOperations : ops).exec(\n\t\t\t\t\t\t\tspawnContext.command,\n\t\t\t\t\t\t\tspawnContext.cwd,\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tonData: handleData,\n\t\t\t\t\t\t\t\tsignal,\n\t\t\t\t\t\t\t\ttimeout: effectiveTimeoutSeconds,\n\t\t\t\t\t\t\t\tenv: spawnContext.env,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t),\n\t\t\t\t\t);\n\t\t\t\t\texitCode = result.exitCode;\n\t\t\t\t} catch (err) {\n\t\t\t\t\tconst snapshot = await finishOutput();\n\t\t\t\t\tconst { text } = formatOutput(snapshot, \"\");\n\t\t\t\t\tif (err instanceof Error && err.message === \"aborted\") {\n\t\t\t\t\t\tthrow new Error(appendStatus(text, \"Command aborted\"));\n\t\t\t\t\t}\n\t\t\t\t\tif (err instanceof Error && err.message.startsWith(\"timeout:\")) {\n\t\t\t\t\t\tconst timeoutSecs = err.message.split(\":\")[1];\n\t\t\t\t\t\tthrow new Error(appendStatus(text, `Command timed out after ${timeoutSecs} seconds`));\n\t\t\t\t\t}\n\t\t\t\t\tif (err instanceof Error && err.message.startsWith(\"silence:\")) {\n\t\t\t\t\t\tconst secs = err.message.split(\":\")[1];\n\t\t\t\t\t\tconst recovery =\n\t\t\t\t\t\t\tbackendShell === \"bash\"\n\t\t\t\t\t\t\t\t? \"re-run it with an explicit timeout, or run it in the background with '&'.\"\n\t\t\t\t\t\t\t\t: \"re-run it with an explicit timeout.\";\n\t\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t\tappendStatus(\n\t\t\t\t\t\t\t\ttext,\n\t\t\t\t\t\t\t\t`Command killed after ${secs}s of silence (no output). If the command is legitimately quiet for long stretches, ${recovery}`,\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t\tthrow err;\n\t\t\t\t}\n\n\t\t\t\tconst candidateProjection = finishProjection(exitCode);\n\t\t\t\tconst snapshot = await finishOutput(candidateProjection !== undefined);\n\t\t\t\tconst projection = candidateProjection && snapshot.fullOutputPath ? candidateProjection : undefined;\n\t\t\t\tconst { text: outputText, details } = formatOutput(snapshot, \"(no output)\", projection);\n\t\t\t\tif (exitCode !== 0 && exitCode !== null) {\n\t\t\t\t\tthrow new Error(appendStatus(outputText, `Command exited with code ${exitCode}`));\n\t\t\t\t}\n\t\t\t\treturn { content: [{ type: \"text\", text: outputText }], details };\n\t\t\t} finally {\n\t\t\t\tclearUpdateTimer();\n\t\t\t\tawait output.closeTempFile();\n\t\t\t}\n\t\t},\n\t\trenderCall(args, _theme, context) {\n\t\t\tconst text = (context.lastComponent as Text | undefined) ?? new Text(\"\", 0, 0);\n\t\t\ttext.setText(formatBashCall(args, toolName));\n\t\t\treturn text;\n\t\t},\n\t\trenderResult(result, options, _theme, context) {\n\t\t\tconst component =\n\t\t\t\t(context.lastComponent as BashResultRenderComponent | undefined) ?? new BashResultRenderComponent();\n\t\t\trebuildBashResultRenderComponent(component, result as any, options, context.showImages);\n\t\t\tcomponent.invalidate();\n\t\t\treturn component;\n\t\t},\n\t};\n}\n\nexport function createBashToolDefinition(\n\tcwd: string,\n\toptions?: BashToolOptions,\n): ToolDefinition<typeof bashSchema, BashToolDetails | undefined> {\n\tconst platform = options?.platform ?? process.platform;\n\treturn createShellToolDefinition(cwd, getPlatformShellToolName(platform), platform, options);\n}\n\nexport function createBashTool(cwd: string, options?: BashToolOptions): AgentTool<typeof bashSchema> {\n\treturn wrapToolDefinition(createBashToolDefinition(cwd, options));\n}\n"]}
@@ -9,7 +9,7 @@ function createDelegateSchema() {
9
9
  })),
10
10
  profileId: Type.Optional(Type.String({
11
11
  maxLength: 512,
12
- description: "Owner-authored orchestration profile to use. The profile fixes role, model, thinking, tools, resources, budget, and concurrency. Omit only when the owner configured a default workerDelegation.orchestrationProfile.",
12
+ description: "Owner-authored orchestration profile to use. The profile fixes role, model, thinking, tools, resources, budget, and concurrency. Regular sessions must omit this field and use the owner's configured default; only an active owner-authored orchestrator may select an allowlisted profile.",
13
13
  })),
14
14
  instructions: Type.Optional(Type.String({
15
15
  maxLength: 16 * 1024,
@@ -43,7 +43,7 @@ function isDelegateAction(value) {
43
43
  value === "resume" ||
44
44
  value === "cancel");
45
45
  }
46
- const DELEGATE_DESCRIPTION_CORE = "Delegate one bounded, self-contained task to an isolated worker lane with classified workspace tools. Workers are read-only by default. The owner-authored profile fixes memory, process, model, thinking, and tool authority; writes additionally require that workerDelegation.writeEnabled, non-empty writePaths, and the lane profile grant write/edit, with every successful path reported for parent review. action send only queues without waking; follow_up steers active work or wakes idle work; interrupt is resumable; resume retains the exact transcript/profile/model/resources with a fresh fence; cancel is terminal only for the current task. Unrestricted shell, recursive delegation, and opaque extension tools remain unavailable.";
46
+ const DELEGATE_DESCRIPTION_CORE = "Delegate one bounded, self-contained task to an isolated worker lane with classified workspace tools. Workers are read-only by default. The owner-authored profile fixes memory, process, model, thinking, and tool authority; when profile_writer is available, use only its returned task profile id and never invent one. Worker writes additionally require that workerDelegation.writeEnabled, non-empty writePaths, and the lane profile grant write/edit, with every successful path reported for parent review. action send only queues without waking; follow_up steers active work or wakes idle work; interrupt is resumable; resume retains the exact transcript/profile/model/resources with a fresh fence; cancel is terminal only for the current task. Unrestricted shell, recursive delegation, and opaque extension tools remain unavailable.";
47
47
  // Synchronous wiring: no `deps.startWorkerDelegation`, so `execute` awaits `runWorkerDelegation`
48
48
  // and the result comes back in this same tool call's response.
49
49
  const SYNCHRONOUS_DELEGATE_DESCRIPTION = DELEGATE_DESCRIPTION_CORE;
@@ -122,7 +122,7 @@ function delegatePanelModel(details) {
122
122
  }
123
123
  function orchestrationProfileGuideline(profiles) {
124
124
  if (!profiles || profiles.length === 0) {
125
- return "Delegation requires an owner-authored orchestration profile. Select its profileId, or rely on the owner's configured default; model and thinking overrides do not exist.";
125
+ return "Delegation requires an owner-authored orchestration profile. Regular sessions must rely on the owner's configured default; only an active owner-authored orchestrator may select a profileId. Never invent, create, or edit profiles during delegation.";
126
126
  }
127
127
  const visibleProfiles = profiles.slice(0, MAX_VISIBLE_ORCHESTRATION_PROFILES);
128
128
  const entries = visibleProfiles.map((profile) => {
@@ -135,7 +135,7 @@ function orchestrationProfileGuideline(profiles) {
135
135
  return [
136
136
  `Available owner-authored orchestration profiles: ${profiles.length} configured; ${entries.join("; ")}`,
137
137
  ...(omitted > 0 ? [`${omitted} omitted from this prompt; use the owner profile catalog to select them.`] : []),
138
- "Select by profileId; never infer or request a model/thinking override.",
138
+ "Only an active owner-authored orchestrator may select an allowlisted profileId; regular sessions must omit it and use the owner's configured default. Never invent, create, or edit profiles during delegation, and never infer or request a model/thinking override.",
139
139
  ]
140
140
  .join(" ")
141
141
  .slice(0, MAX_PROFILE_GUIDELINE_CHARS);
@@ -1 +1 @@
1
- {"version":3,"file":"delegate.js","sourceRoot":"","sources":["../../../src/core/tools/delegate.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,IAAI,EAAE,MAAM,SAAS,CAAC;AAM5C,OAAO,EACN,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MAAM,EAAE,UAAU;wBAClC,QAAQ,EAAE,OAAO,EAAE,QAAQ;wBAC3B,OAAO,EAAE,OAAO,EAAE,OAAO;wBACzB,OAAO,EAAE,OAAO,EAAE,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC;wBAC/C,QAAQ,EAAE,OAAO,EAAE,KAAK,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC;qBAC/C;iBACD,CAAC;YACH,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBAChB,MAAM,MAAM,GAAG,CAAC,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,wBAAwB,CAAC,CAAC;gBAC3G,OAAO,OAAO,CAAC,YAAY,MAAM,YAAY,MAAM,EAAE,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC,EAAE;oBACtE,OAAO,EAAE,KAAK;oBACd,MAAM;oBACN,GAAG,CAAC,KAAK,CAAC,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,KAAK,CAAC,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;oBACnE,UAAU,EAAE,4BAA4B;iBACxC,CAAC,CAAC;YACJ,CAAC;QACF,CAAC;KACD,CAAC;AACH,CAAC","sourcesContent":["import { type Static, Type } from \"typebox\";\nimport type { LaneRecord } from \"../autonomy/lane-tracker.ts\";\nimport type { WorkerAgentControlPort } from \"../delegation/worker-agent-control.ts\";\nimport type { WorkerDelegationRequest } from \"../delegation/worker-delegation-request.ts\";\nimport type { WorkerRunOutcome } from \"../delegation/worker-runner.ts\";\nimport type { ToolDefinition } from \"../extensions/types.ts\";\nimport {\n\temptyOrchestrationCall,\n\ttype OrchestrationPanelModel,\n\ttype OrchestrationRowStatus,\n\trenderOrchestrationToolResult,\n} from \"./orchestration-panel.ts\";\n\nfunction createDelegateSchema() {\n\treturn Type.Object(\n\t\t{\n\t\t\taction: Type.Optional(\n\t\t\t\tType.String({\n\t\t\t\t\tmaxLength: 16,\n\t\t\t\t\tenum: [\"start\", \"send\", \"follow_up\", \"interrupt\", \"resume\", \"cancel\"],\n\t\t\t\t\tdescription:\n\t\t\t\t\t\t\"Optional logical-agent action. Omit or use start to create a worker; send queues without waking; follow_up steers an active worker or wakes an idle one; interrupt is resumable; resume restores the exact admitted transcript/profile/model/resources under a fresh fence; cancel is terminal for the current task only.\",\n\t\t\t\t}),\n\t\t\t),\n\t\t\tprofileId: Type.Optional(\n\t\t\t\tType.String({\n\t\t\t\t\tmaxLength: 512,\n\t\t\t\t\tdescription:\n\t\t\t\t\t\t\"Owner-authored orchestration profile to use. The profile fixes role, model, thinking, tools, resources, budget, and concurrency. Omit only when the owner configured a default workerDelegation.orchestrationProfile.\",\n\t\t\t\t}),\n\t\t\t),\n\t\t\tinstructions: Type.Optional(\n\t\t\t\tType.String({\n\t\t\t\t\tmaxLength: 16 * 1024,\n\t\t\t\t\tdescription:\n\t\t\t\t\t\t\"The self-contained task for a bounded worker with classified workspace tools. It is read-only unless workerDelegation.writeEnabled, non-empty writePaths, and its lane profile all grant write/edit; any write is path-scoped and parent-reviewed. Include all context it needs; it cannot see this conversation.\",\n\t\t\t\t}),\n\t\t\t),\n\t\t\tagentId: Type.Optional(\n\t\t\t\tType.String({\n\t\t\t\t\tmaxLength: 512,\n\t\t\t\t\tdescription: \"Stable logical worker id returned by start; never substitute a transient task lane.\",\n\t\t\t\t}),\n\t\t\t),\n\t\t\tmessage: Type.Optional(\n\t\t\t\tType.String({\n\t\t\t\t\tmaxLength: 4_096,\n\t\t\t\t\tdescription: \"Bounded message for send or follow_up. Send only queues it; follow_up may wake idle work.\",\n\t\t\t\t}),\n\t\t\t),\n\t\t},\n\t\t{ additionalProperties: false },\n\t);\n}\n\nconst delegateSchema = createDelegateSchema();\nconst MAX_DELEGATE_RESULT_CHARS = 16 * 1024;\nconst MAX_DELEGATE_ERROR_CHARS = 1_900;\nconst MAX_DELEGATE_INSTRUCTIONS_CHARS = 16 * 1024;\nconst MAX_DELEGATE_PROFILE_ID_CHARS = 512;\nconst MAX_DELEGATE_AGENT_ID_CHARS = 512;\nconst MAX_DELEGATE_MESSAGE_CHARS = 4_096;\nconst MAX_PROFILE_GUIDELINE_CHARS = 4_096;\nconst MAX_VISIBLE_ORCHESTRATION_PROFILES = 16;\nconst MAX_PROFILE_GUIDELINE_FIELD_CHARS = 64;\n\ntype DelegateAction = NonNullable<DelegateToolDetails[\"action\"]>;\n\nfunction isDelegateAction(value: string): value is DelegateAction {\n\treturn (\n\t\tvalue === \"start\" ||\n\t\tvalue === \"send\" ||\n\t\tvalue === \"follow_up\" ||\n\t\tvalue === \"interrupt\" ||\n\t\tvalue === \"resume\" ||\n\t\tvalue === \"cancel\"\n\t);\n}\n\nexport type DelegateToolInput = Static<typeof delegateSchema>;\n\nexport interface DelegateRunOutcome {\n\tstarted: boolean;\n\tskipReason?: string;\n\trecord?: LaneRecord;\n\toutcome?: WorkerRunOutcome;\n}\n\nexport interface DelegateToolDetails {\n\tstarted: boolean;\n\taction?: \"start\" | \"send\" | \"follow_up\" | \"interrupt\" | \"resume\" | \"cancel\";\n\tagentId?: string;\n\tskipReason?: string;\n\tprofileId?: string;\n\tlaneId?: string;\n\tlabel?: string;\n\tstatus?: LaneRecord[\"status\"];\n\treasonCode?: string;\n\taccepted?: boolean;\n\tcostUsd?: number;\n\tsummary?: string;\n\tblockers?: readonly string[];\n\tqueued?: boolean;\n}\n\nexport interface DelegateToolDependencies {\n\tstartWorkerDelegation?: (\n\t\targs: WorkerDelegationRequest,\n\t) => { started: false; skipReason: string } | { started: true; record: LaneRecord };\n\trunWorkerDelegation: (args: WorkerDelegationRequest) => Promise<DelegateRunOutcome>;\n\torchestrationProfiles?: readonly { profileId: string; role: string; description: string }[];\n\tworkerAgentControl?: WorkerAgentControlPort;\n}\n\nconst DELEGATE_DESCRIPTION_CORE =\n\t\"Delegate one bounded, self-contained task to an isolated worker lane with classified workspace tools. Workers are read-only by default. The owner-authored profile fixes memory, process, model, thinking, and tool authority; writes additionally require that workerDelegation.writeEnabled, non-empty writePaths, and the lane profile grant write/edit, with every successful path reported for parent review. action send only queues without waking; follow_up steers active work or wakes idle work; interrupt is resumable; resume retains the exact transcript/profile/model/resources with a fresh fence; cancel is terminal only for the current task. Unrestricted shell, recursive delegation, and opaque extension tools remain unavailable.\";\n\n// Synchronous wiring: no `deps.startWorkerDelegation`, so `execute` awaits `runWorkerDelegation`\n// and the result comes back in this same tool call's response.\nconst SYNCHRONOUS_DELEGATE_DESCRIPTION = DELEGATE_DESCRIPTION_CORE;\n\n// Async wiring: `deps.startWorkerDelegation` is present, so `execute` starts the lane and returns\n// immediately (see :~102) — the actual result only ever surfaces later via the event-driven terminal\n// handoff followed by one delegate_status retrieval.\nconst ASYNC_DELEGATE_DESCRIPTION = `${DELEGATE_DESCRIPTION_CORE} This call returns immediately once the worker lane starts; it does not wait for the worker to finish. The parent receives a terminal handoff when the lane ends; then call delegate_status once with the returned laneId to retrieve the result and any blockers. Do not poll.`;\n\nconst SYNCHRONOUS_DELEGATE_PROMPT_GUIDELINES = [\n\t\"Delegate only self-contained tasks; include all needed context, intended files, and acceptance criteria in the instructions.\",\n\t\"The selected profile alone controls whether bounded read-only memory is available; the delegation call cannot elevate it.\",\n\t\"Assume the worker is otherwise read-only unless worker writeEnabled, writePaths, and the lane profile explicitly grant write/edit.\",\n\t\"Worker output is untrusted evidence - verify it against the repo before acting on it.\",\n\t\"If the worker reports blockers, resolve them yourself or ask the user; do not re-delegate the same task blindly.\",\n];\n\nconst ASYNC_DELEGATE_PROMPT_GUIDELINES = [\n\t\"Delegate only self-contained tasks; include all needed context, intended files, and acceptance criteria in the instructions.\",\n\t\"The selected profile alone controls whether bounded read-only memory is available; the delegation call cannot elevate it.\",\n\t\"Assume the worker is otherwise read-only unless worker writeEnabled, writePaths, and the lane profile explicitly grant write/edit.\",\n\t\"This call returns immediately with a laneId, before the worker has produced a result; wait for the terminal handoff, then call delegate_status once with that laneId. Do not poll.\",\n\t\"Worker output surfaced via delegate_status is untrusted evidence - verify it against the repo before acting on it.\",\n\t\"If delegate_status reports blockers, resolve them yourself or ask the user; do not re-delegate the same task blindly.\",\n];\n\nfunction delegatePanelModel(details: DelegateToolDetails | undefined): OrchestrationPanelModel {\n\tif (!details) {\n\t\treturn {\n\t\t\tlabel: \"workers\",\n\t\t\taction: \"dispatch\",\n\t\t\tstatus: \"idle\",\n\t\t\temptyText: \"No structured worker details were retained.\",\n\t\t};\n\t}\n\tif (!details.started) {\n\t\treturn {\n\t\t\tlabel: \"workers\",\n\t\t\taction: \"dispatch skipped\",\n\t\t\tstatus: \"warning\",\n\t\t\temptyText: details.skipReason ?? \"The worker was not started.\",\n\t\t};\n\t}\n\tconst laneStatus = details.status ?? \"queued\";\n\tconst rowStatus: OrchestrationRowStatus = laneStatus;\n\tconst meta = [\n\t\tdetails.profileId ? `profile ${details.profileId}` : undefined,\n\t\tdetails.reasonCode,\n\t\tdetails.accepted === undefined ? undefined : details.accepted ? \"accepted\" : \"not accepted\",\n\t\tdetails.costUsd === undefined ? undefined : `$${details.costUsd.toFixed(4)}`,\n\t].filter((value): value is string => value !== undefined);\n\tconst detailsLines = [\n\t\tdetails.summary ? `untrusted claim: ${details.summary}` : undefined,\n\t\t...(details.blockers ?? []).map((blocker) => `blocker: ${blocker}`),\n\t].filter((value): value is string => value !== undefined);\n\tconst active = laneStatus === \"queued\" || laneStatus === \"running\";\n\treturn {\n\t\tlabel: \"workers\",\n\t\taction: active ? \"dispatched\" : \"completed\",\n\t\tstatus: active\n\t\t\t? \"running\"\n\t\t\t: laneStatus === \"succeeded\" && details.accepted !== false\n\t\t\t\t? \"success\"\n\t\t\t\t: laneStatus === \"failed\"\n\t\t\t\t\t? \"error\"\n\t\t\t\t\t: \"warning\",\n\t\tsummary: active ? [\"terminal handoff will wake this session\"] : undefined,\n\t\trows: [\n\t\t\t{\n\t\t\t\tstatus: rowStatus,\n\t\t\t\tlabel: details.label ?? details.laneId ?? \"worker lane\",\n\t\t\t\tmeta: [details.label ? details.laneId : undefined, ...meta].filter(\n\t\t\t\t\t(value): value is string => value !== undefined,\n\t\t\t\t),\n\t\t\t\tdetails: detailsLines,\n\t\t\t},\n\t\t],\n\t\tnotices:\n\t\t\tdetails.accepted === false\n\t\t\t\t? [{ status: \"warning\", text: \"Worker output was not accepted; inspect and verify before use.\" }]\n\t\t\t\t: undefined,\n\t};\n}\n\nfunction orchestrationProfileGuideline(\n\tprofiles: readonly { profileId: string; role: string; description: string }[] | undefined,\n): string {\n\tif (!profiles || profiles.length === 0) {\n\t\treturn \"Delegation requires an owner-authored orchestration profile. Select its profileId, or rely on the owner's configured default; model and thinking overrides do not exist.\";\n\t}\n\tconst visibleProfiles = profiles.slice(0, MAX_VISIBLE_ORCHESTRATION_PROFILES);\n\tconst entries = visibleProfiles.map((profile) => {\n\t\tconst profileId = profile.profileId.slice(0, MAX_PROFILE_GUIDELINE_FIELD_CHARS);\n\t\tconst role = profile.role.slice(0, MAX_PROFILE_GUIDELINE_FIELD_CHARS);\n\t\tconst description = profile.description.slice(0, MAX_PROFILE_GUIDELINE_FIELD_CHARS);\n\t\treturn `${profileId} (${role}: ${description})`;\n\t});\n\tconst omitted = profiles.length - visibleProfiles.length;\n\treturn [\n\t\t`Available owner-authored orchestration profiles: ${profiles.length} configured; ${entries.join(\"; \")}`,\n\t\t...(omitted > 0 ? [`${omitted} omitted from this prompt; use the owner profile catalog to select them.`] : []),\n\t\t\"Select by profileId; never infer or request a model/thinking override.\",\n\t]\n\t\t.join(\" \")\n\t\t.slice(0, MAX_PROFILE_GUIDELINE_CHARS);\n}\n\nexport function createDelegateToolDefinition(deps: DelegateToolDependencies): ToolDefinition {\n\tconst isAsyncWiring = deps.startWorkerDelegation !== undefined;\n\tconst profileGuideline = orchestrationProfileGuideline(deps.orchestrationProfiles);\n\treturn {\n\t\tname: \"delegate\",\n\t\tlabel: \"delegate\",\n\t\tdescription: isAsyncWiring ? ASYNC_DELEGATE_DESCRIPTION : SYNCHRONOUS_DELEGATE_DESCRIPTION,\n\t\tpromptSnippet: \"Delegate a bounded task to an isolated, least-privilege worker lane.\",\n\t\tpromptGuidelines: [\n\t\t\tprofileGuideline,\n\t\t\t...(isAsyncWiring ? ASYNC_DELEGATE_PROMPT_GUIDELINES : SYNCHRONOUS_DELEGATE_PROMPT_GUIDELINES),\n\t\t],\n\t\tparameters: delegateSchema,\n\t\trenderShell: \"self\",\n\t\trenderCall() {\n\t\t\treturn emptyOrchestrationCall();\n\t\t},\n\t\trenderResult(result, { expanded, isPartial }, theme) {\n\t\t\tconst details = result.details as DelegateToolDetails | undefined;\n\t\t\treturn renderOrchestrationToolResult(theme, delegatePanelModel(details), {\n\t\t\t\tisPartial,\n\t\t\t\tcollapse: !expanded && details?.started === true,\n\t\t\t\texpanded,\n\t\t\t});\n\t\t},\n\t\tasync execute(\n\t\t\t_toolCallId,\n\t\t\tinput: DelegateToolInput,\n\t\t): Promise<{\n\t\t\tcontent: Array<{ type: \"text\"; text: string }>;\n\t\t\tdetails: DelegateToolDetails;\n\t\t}> {\n\t\t\tconst requestedAction = input.action ?? \"start\";\n\t\t\tconst invalid = (message: string, actionDetails: DelegateToolDetails) => ({\n\t\t\t\tcontent: [{ type: \"text\" as const, text: message }],\n\t\t\t\tdetails: actionDetails,\n\t\t\t});\n\t\t\tif (!isDelegateAction(requestedAction)) {\n\t\t\t\treturn invalid(`delegate action is invalid: ${requestedAction}`, {\n\t\t\t\t\tstarted: false,\n\t\t\t\t\tskipReason: \"invalid_action\",\n\t\t\t\t});\n\t\t\t}\n\t\t\tconst action = requestedAction;\n\t\t\tif (input.instructions !== undefined && input.instructions.length > MAX_DELEGATE_INSTRUCTIONS_CHARS) {\n\t\t\t\treturn invalid(`delegate instructions may not exceed ${MAX_DELEGATE_INSTRUCTIONS_CHARS} characters`, {\n\t\t\t\t\tstarted: false,\n\t\t\t\t\taction,\n\t\t\t\t\tskipReason: \"instructions_too_long\",\n\t\t\t\t});\n\t\t\t}\n\t\t\tif (input.profileId !== undefined && input.profileId.length > MAX_DELEGATE_PROFILE_ID_CHARS) {\n\t\t\t\treturn invalid(`delegate profileId may not exceed ${MAX_DELEGATE_PROFILE_ID_CHARS} characters`, {\n\t\t\t\t\tstarted: false,\n\t\t\t\t\taction,\n\t\t\t\t\tskipReason: \"profile_id_too_long\",\n\t\t\t\t});\n\t\t\t}\n\t\t\tif (input.agentId !== undefined && input.agentId.length > MAX_DELEGATE_AGENT_ID_CHARS) {\n\t\t\t\treturn invalid(`delegate agentId may not exceed ${MAX_DELEGATE_AGENT_ID_CHARS} characters`, {\n\t\t\t\t\tstarted: false,\n\t\t\t\t\taction,\n\t\t\t\t\tskipReason: \"agent_id_too_long\",\n\t\t\t\t});\n\t\t\t}\n\t\t\tif (input.message !== undefined && input.message.length > MAX_DELEGATE_MESSAGE_CHARS) {\n\t\t\t\treturn invalid(`delegate message may not exceed ${MAX_DELEGATE_MESSAGE_CHARS} characters`, {\n\t\t\t\t\tstarted: false,\n\t\t\t\t\taction,\n\t\t\t\t\tskipReason: \"message_too_long\",\n\t\t\t\t});\n\t\t\t}\n\t\t\tconst requireAgentId = (): string | undefined => {\n\t\t\t\tconst agentId = input.agentId?.trim();\n\t\t\t\tif (agentId) return agentId;\n\t\t\t\treturn undefined;\n\t\t\t};\n\t\t\ttry {\n\t\t\t\tif (action !== \"start\") {\n\t\t\t\t\tconst agentId = requireAgentId();\n\t\t\t\t\tif (!agentId)\n\t\t\t\t\t\treturn invalid(`delegate ${action} requires agentId`, {\n\t\t\t\t\t\t\tstarted: false,\n\t\t\t\t\t\t\taction,\n\t\t\t\t\t\t\tskipReason: \"missing_agent_id\",\n\t\t\t\t\t\t});\n\t\t\t\t\tif (action === \"send\" || action === \"follow_up\") {\n\t\t\t\t\t\tconst message = input.message?.trim();\n\t\t\t\t\t\tif (!message)\n\t\t\t\t\t\t\treturn invalid(`delegate ${action} requires message`, {\n\t\t\t\t\t\t\t\tstarted: false,\n\t\t\t\t\t\t\t\taction,\n\t\t\t\t\t\t\t\tagentId,\n\t\t\t\t\t\t\t\tskipReason: \"missing_message\",\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\tif (action === \"send\") {\n\t\t\t\t\t\t\tif (!deps.workerAgentControl)\n\t\t\t\t\t\t\t\treturn invalid(\"delegate send is unavailable\", {\n\t\t\t\t\t\t\t\t\tstarted: false,\n\t\t\t\t\t\t\t\t\taction,\n\t\t\t\t\t\t\t\t\tagentId,\n\t\t\t\t\t\t\t\t\tskipReason: \"worker_agent_control_unavailable\",\n\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\tconst outcome = deps.workerAgentControl.sendWorkerAgentMessage(agentId, message);\n\t\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t\tcontent: [\n\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\ttype: \"text\" as const,\n\t\t\t\t\t\t\t\t\t\ttext: `message queued for ${agentId}; it will not wake the worker`,\n\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t\tdetails: { started: true, action, agentId, queued: outcome.queued },\n\t\t\t\t\t\t\t};\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (!deps.workerAgentControl)\n\t\t\t\t\t\t\treturn invalid(\"delegate follow_up is unavailable\", {\n\t\t\t\t\t\t\t\tstarted: false,\n\t\t\t\t\t\t\t\taction,\n\t\t\t\t\t\t\t\tagentId,\n\t\t\t\t\t\t\t\tskipReason: \"worker_agent_control_unavailable\",\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\tconst outcome = deps.workerAgentControl.followUpWorkerAgent(agentId, message);\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\tcontent: [\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\ttype: \"text\" as const,\n\t\t\t\t\t\t\t\t\ttext: `follow_up ${outcome.started ? \"started\" : \"queued\"} for ${agentId}`,\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\tdetails: {\n\t\t\t\t\t\t\t\tstarted: outcome.started,\n\t\t\t\t\t\t\t\taction,\n\t\t\t\t\t\t\t\tagentId,\n\t\t\t\t\t\t\t\tlaneId: outcome.record?.laneId,\n\t\t\t\t\t\t\t\tstatus: outcome.record?.status,\n\t\t\t\t\t\t\t\tskipReason: outcome.skipReason,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\t\t\t\t\tif (action === \"interrupt\") {\n\t\t\t\t\t\tif (!deps.workerAgentControl)\n\t\t\t\t\t\t\treturn invalid(\"delegate interrupt is unavailable\", {\n\t\t\t\t\t\t\t\tstarted: false,\n\t\t\t\t\t\t\t\taction,\n\t\t\t\t\t\t\t\tagentId,\n\t\t\t\t\t\t\t\tskipReason: \"worker_agent_control_unavailable\",\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\tconst outcome = deps.workerAgentControl.interruptWorkerAgent(agentId);\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\tcontent: [\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\ttype: \"text\" as const,\n\t\t\t\t\t\t\t\t\ttext: outcome.interrupted\n\t\t\t\t\t\t\t\t\t\t? `worker ${agentId} interrupted; resume preserves its admitted state`\n\t\t\t\t\t\t\t\t\t\t: `worker ${agentId} was not interrupted (${outcome.reason ?? \"unknown\"})`,\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\tdetails: { started: outcome.interrupted, action, agentId, skipReason: outcome.reason },\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\t\t\t\t\tif (action === \"resume\") {\n\t\t\t\t\t\tif (!deps.workerAgentControl)\n\t\t\t\t\t\t\treturn invalid(\"delegate resume is unavailable\", {\n\t\t\t\t\t\t\t\tstarted: false,\n\t\t\t\t\t\t\t\taction,\n\t\t\t\t\t\t\t\tagentId,\n\t\t\t\t\t\t\t\tskipReason: \"worker_agent_control_unavailable\",\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\tconst outcome = deps.workerAgentControl.resumeWorkerAgent(agentId);\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\tcontent: [\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\ttype: \"text\" as const,\n\t\t\t\t\t\t\t\t\ttext: outcome.started\n\t\t\t\t\t\t\t\t\t\t? `worker ${agentId} resumed with its admitted transcript and authority`\n\t\t\t\t\t\t\t\t\t\t: `worker ${agentId} was not resumed (${outcome.skipReason ?? \"unknown\"})`,\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\tdetails: {\n\t\t\t\t\t\t\t\tstarted: outcome.started,\n\t\t\t\t\t\t\t\taction,\n\t\t\t\t\t\t\t\tagentId,\n\t\t\t\t\t\t\t\tlaneId: outcome.record?.laneId,\n\t\t\t\t\t\t\t\tstatus: outcome.record?.status,\n\t\t\t\t\t\t\t\tskipReason: outcome.skipReason,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\t\t\t\t\tif (!deps.workerAgentControl)\n\t\t\t\t\t\treturn invalid(\"delegate cancel is unavailable\", {\n\t\t\t\t\t\t\tstarted: false,\n\t\t\t\t\t\t\taction,\n\t\t\t\t\t\t\tagentId,\n\t\t\t\t\t\t\tskipReason: \"worker_agent_control_unavailable\",\n\t\t\t\t\t\t});\n\t\t\t\t\tconst cancelled = deps.workerAgentControl.cancelWorkerAgent(agentId);\n\t\t\t\t\treturn {\n\t\t\t\t\t\tcontent: [\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\ttype: \"text\" as const,\n\t\t\t\t\t\t\t\ttext: cancelled\n\t\t\t\t\t\t\t\t\t? `worker ${agentId} cancelled for its current task`\n\t\t\t\t\t\t\t\t\t: `worker ${agentId} was not cancelled`,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t],\n\t\t\t\t\t\tdetails: {\n\t\t\t\t\t\t\tstarted: Boolean(cancelled),\n\t\t\t\t\t\t\taction,\n\t\t\t\t\t\t\tagentId,\n\t\t\t\t\t\t\tlaneId: cancelled?.laneId,\n\t\t\t\t\t\t\tstatus: cancelled?.status,\n\t\t\t\t\t\t\treasonCode: cancelled?.reasonCode,\n\t\t\t\t\t\t},\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t\tconst instructions = input.instructions?.trim();\n\t\t\t\tif (!instructions)\n\t\t\t\t\treturn invalid(\"delegate start requires instructions\", {\n\t\t\t\t\t\tstarted: false,\n\t\t\t\t\t\taction,\n\t\t\t\t\t\tskipReason: \"missing_instructions\",\n\t\t\t\t\t});\n\t\t\t\tconst profileId = input.profileId?.trim();\n\t\t\t\tconst request = { instructions, ...(profileId ? { profileId } : {}) };\n\t\t\t\tif (deps.startWorkerDelegation) {\n\t\t\t\t\tconst started = deps.startWorkerDelegation(request);\n\t\t\t\t\tif (!started.started) {\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\tcontent: [{ type: \"text\" as const, text: `delegate skipped: ${started.skipReason}` }],\n\t\t\t\t\t\t\tdetails: {\n\t\t\t\t\t\t\t\tstarted: false,\n\t\t\t\t\t\t\t\tskipReason: started.skipReason,\n\t\t\t\t\t\t\t\t...(profileId ? { profileId } : {}),\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\t\t\t\t\treturn {\n\t\t\t\t\t\tcontent: [\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\ttype: \"text\" as const,\n\t\t\t\t\t\t\t\ttext: `delegate started (${started.record.status}) — stable agentId ${started.record.laneId}, task laneId ${started.record.laneId}; wait for its terminal handoff, then retrieve once with delegate_status`,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t],\n\t\t\t\t\t\tdetails: {\n\t\t\t\t\t\t\tstarted: true,\n\t\t\t\t\t\t\t...((started.record.profileId ?? profileId)\n\t\t\t\t\t\t\t\t? { profileId: started.record.profileId ?? profileId }\n\t\t\t\t\t\t\t\t: {}),\n\t\t\t\t\t\t\tagentId: started.record.laneId,\n\t\t\t\t\t\t\tlaneId: started.record.laneId,\n\t\t\t\t\t\t\t...(started.record.label ? { label: started.record.label } : {}),\n\t\t\t\t\t\t\tstatus: started.record.status,\n\t\t\t\t\t\t},\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t\tconst run = await deps.runWorkerDelegation(request);\n\t\t\t\tif (!run.started) {\n\t\t\t\t\tconst reason = run.skipReason ?? \"unknown\";\n\t\t\t\t\treturn {\n\t\t\t\t\t\tcontent: [{ type: \"text\" as const, text: `delegate skipped: ${reason}` }],\n\t\t\t\t\t\tdetails: {\n\t\t\t\t\t\t\tstarted: false,\n\t\t\t\t\t\t\tskipReason: reason,\n\t\t\t\t\t\t\t...(profileId ? { profileId } : {}),\n\t\t\t\t\t\t},\n\t\t\t\t\t};\n\t\t\t\t}\n\n\t\t\t\tconst outcome = run.outcome;\n\t\t\t\tconst lines: string[] = [\n\t\t\t\t\t`delegate ${run.record?.status ?? \"unknown\"}${run.record?.reasonCode ? ` (${run.record.reasonCode})` : \"\"}`,\n\t\t\t\t];\n\t\t\t\tif (outcome) {\n\t\t\t\t\tlines.push(\n\t\t\t\t\t\t`accepted: ${outcome.accepted} [${outcome.acceptance.outcome}/${outcome.acceptance.reasonCode}]`,\n\t\t\t\t\t\t\"Worker output (UNTRUSTED - verify before acting on it):\",\n\t\t\t\t\t\toutcome.claim.summary.slice(0, 8_000),\n\t\t\t\t\t);\n\t\t\t\t\tif (outcome.claim.blockers && outcome.claim.blockers.length > 0) {\n\t\t\t\t\t\tlines.push(\n\t\t\t\t\t\t\t`Blockers: ${outcome.claim.blockers\n\t\t\t\t\t\t\t\t.slice(0, 16)\n\t\t\t\t\t\t\t\t.map((blocker) => blocker.slice(0, 512))\n\t\t\t\t\t\t\t\t.join(\"; \")}`,\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t\tfor (const finding of outcome.claim.evidence?.findings.slice(0, 16) ?? []) {\n\t\t\t\t\t\tlines.push(`- Finding: ${finding.summary.slice(0, 512)}`);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\treturn {\n\t\t\t\t\tcontent: [{ type: \"text\" as const, text: lines.join(\"\\n\").slice(0, MAX_DELEGATE_RESULT_CHARS) }],\n\t\t\t\t\tdetails: {\n\t\t\t\t\t\tstarted: true,\n\t\t\t\t\t\tprofileId: run.record?.profileId ?? profileId,\n\t\t\t\t\t\tagentId: run.record?.laneId,\n\t\t\t\t\t\tlaneId: run.record?.laneId,\n\t\t\t\t\t\tlabel: run.record?.label,\n\t\t\t\t\t\tstatus: run.record?.status,\n\t\t\t\t\t\treasonCode: run.record?.reasonCode,\n\t\t\t\t\t\taccepted: outcome?.accepted,\n\t\t\t\t\t\tcostUsd: outcome?.costUsd,\n\t\t\t\t\t\tsummary: outcome?.claim.summary.slice(0, 8_000),\n\t\t\t\t\t\tblockers: outcome?.claim.blockers?.slice(0, 16),\n\t\t\t\t\t},\n\t\t\t\t};\n\t\t\t} catch (error) {\n\t\t\t\tconst reason = (error instanceof Error ? error.message : String(error)).slice(0, MAX_DELEGATE_ERROR_CHARS);\n\t\t\t\treturn invalid(`delegate ${action} failed: ${reason}`.slice(0, 2_048), {\n\t\t\t\t\tstarted: false,\n\t\t\t\t\taction,\n\t\t\t\t\t...(input.agentId?.trim() ? { agentId: input.agentId.trim() } : {}),\n\t\t\t\t\tskipReason: \"worker_agent_control_error\",\n\t\t\t\t});\n\t\t\t}\n\t\t},\n\t};\n}\n"]}
1
+ {"version":3,"file":"delegate.js","sourceRoot":"","sources":["../../../src/core/tools/delegate.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,IAAI,EAAE,MAAM,SAAS,CAAC;AAM5C,OAAO,EACN,sBAAsB,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M,EAAE,UAAU;wBAClC,QAAQ,EAAE,OAAO,EAAE,QAAQ;wBAC3B,OAAO,EAAE,OAAO,EAAE,OAAO;wBACzB,OAAO,EAAE,OAAO,EAAE,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC;wBAC/C,QAAQ,EAAE,OAAO,EAAE,KAAK,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC;qBAC/C;iBACD,CAAC;YACH,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBAChB,MAAM,MAAM,GAAG,CAAC,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,wBAAwB,CAAC,CAAC;gBAC3G,OAAO,OAAO,CAAC,YAAY,MAAM,YAAY,MAAM,EAAE,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC,EAAE;oBACtE,OAAO,EAAE,KAAK;oBACd,MAAM;oBACN,GAAG,CAAC,KAAK,CAAC,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,KAAK,CAAC,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;oBACnE,UAAU,EAAE,4BAA4B;iBACxC,CAAC,CAAC;YACJ,CAAC;QACF,CAAC;KACD,CAAC;AACH,CAAC","sourcesContent":["import { type Static, Type } from \"typebox\";\nimport type { LaneRecord } from \"../autonomy/lane-tracker.ts\";\nimport type { WorkerAgentControlPort } from \"../delegation/worker-agent-control.ts\";\nimport type { WorkerDelegationRequest } from \"../delegation/worker-delegation-request.ts\";\nimport type { WorkerRunOutcome } from \"../delegation/worker-runner.ts\";\nimport type { ToolDefinition } from \"../extensions/types.ts\";\nimport {\n\temptyOrchestrationCall,\n\ttype OrchestrationPanelModel,\n\ttype OrchestrationRowStatus,\n\trenderOrchestrationToolResult,\n} from \"./orchestration-panel.ts\";\n\nfunction createDelegateSchema() {\n\treturn Type.Object(\n\t\t{\n\t\t\taction: Type.Optional(\n\t\t\t\tType.String({\n\t\t\t\t\tmaxLength: 16,\n\t\t\t\t\tenum: [\"start\", \"send\", \"follow_up\", \"interrupt\", \"resume\", \"cancel\"],\n\t\t\t\t\tdescription:\n\t\t\t\t\t\t\"Optional logical-agent action. Omit or use start to create a worker; send queues without waking; follow_up steers an active worker or wakes an idle one; interrupt is resumable; resume restores the exact admitted transcript/profile/model/resources under a fresh fence; cancel is terminal for the current task only.\",\n\t\t\t\t}),\n\t\t\t),\n\t\t\tprofileId: Type.Optional(\n\t\t\t\tType.String({\n\t\t\t\t\tmaxLength: 512,\n\t\t\t\t\tdescription:\n\t\t\t\t\t\t\"Owner-authored orchestration profile to use. The profile fixes role, model, thinking, tools, resources, budget, and concurrency. Regular sessions must omit this field and use the owner's configured default; only an active owner-authored orchestrator may select an allowlisted profile.\",\n\t\t\t\t}),\n\t\t\t),\n\t\t\tinstructions: Type.Optional(\n\t\t\t\tType.String({\n\t\t\t\t\tmaxLength: 16 * 1024,\n\t\t\t\t\tdescription:\n\t\t\t\t\t\t\"The self-contained task for a bounded worker with classified workspace tools. It is read-only unless workerDelegation.writeEnabled, non-empty writePaths, and its lane profile all grant write/edit; any write is path-scoped and parent-reviewed. Include all context it needs; it cannot see this conversation.\",\n\t\t\t\t}),\n\t\t\t),\n\t\t\tagentId: Type.Optional(\n\t\t\t\tType.String({\n\t\t\t\t\tmaxLength: 512,\n\t\t\t\t\tdescription: \"Stable logical worker id returned by start; never substitute a transient task lane.\",\n\t\t\t\t}),\n\t\t\t),\n\t\t\tmessage: Type.Optional(\n\t\t\t\tType.String({\n\t\t\t\t\tmaxLength: 4_096,\n\t\t\t\t\tdescription: \"Bounded message for send or follow_up. Send only queues it; follow_up may wake idle work.\",\n\t\t\t\t}),\n\t\t\t),\n\t\t},\n\t\t{ additionalProperties: false },\n\t);\n}\n\nconst delegateSchema = createDelegateSchema();\nconst MAX_DELEGATE_RESULT_CHARS = 16 * 1024;\nconst MAX_DELEGATE_ERROR_CHARS = 1_900;\nconst MAX_DELEGATE_INSTRUCTIONS_CHARS = 16 * 1024;\nconst MAX_DELEGATE_PROFILE_ID_CHARS = 512;\nconst MAX_DELEGATE_AGENT_ID_CHARS = 512;\nconst MAX_DELEGATE_MESSAGE_CHARS = 4_096;\nconst MAX_PROFILE_GUIDELINE_CHARS = 4_096;\nconst MAX_VISIBLE_ORCHESTRATION_PROFILES = 16;\nconst MAX_PROFILE_GUIDELINE_FIELD_CHARS = 64;\n\ntype DelegateAction = NonNullable<DelegateToolDetails[\"action\"]>;\n\nfunction isDelegateAction(value: string): value is DelegateAction {\n\treturn (\n\t\tvalue === \"start\" ||\n\t\tvalue === \"send\" ||\n\t\tvalue === \"follow_up\" ||\n\t\tvalue === \"interrupt\" ||\n\t\tvalue === \"resume\" ||\n\t\tvalue === \"cancel\"\n\t);\n}\n\nexport type DelegateToolInput = Static<typeof delegateSchema>;\n\nexport interface DelegateRunOutcome {\n\tstarted: boolean;\n\tskipReason?: string;\n\trecord?: LaneRecord;\n\toutcome?: WorkerRunOutcome;\n}\n\nexport interface DelegateToolDetails {\n\tstarted: boolean;\n\taction?: \"start\" | \"send\" | \"follow_up\" | \"interrupt\" | \"resume\" | \"cancel\";\n\tagentId?: string;\n\tskipReason?: string;\n\tprofileId?: string;\n\tlaneId?: string;\n\tlabel?: string;\n\tstatus?: LaneRecord[\"status\"];\n\treasonCode?: string;\n\taccepted?: boolean;\n\tcostUsd?: number;\n\tsummary?: string;\n\tblockers?: readonly string[];\n\tqueued?: boolean;\n}\n\nexport interface DelegateToolDependencies {\n\tstartWorkerDelegation?: (\n\t\targs: WorkerDelegationRequest,\n\t) => { started: false; skipReason: string } | { started: true; record: LaneRecord };\n\trunWorkerDelegation: (args: WorkerDelegationRequest) => Promise<DelegateRunOutcome>;\n\torchestrationProfiles?: readonly { profileId: string; role: string; description: string }[];\n\tworkerAgentControl?: WorkerAgentControlPort;\n}\n\nconst DELEGATE_DESCRIPTION_CORE =\n\t\"Delegate one bounded, self-contained task to an isolated worker lane with classified workspace tools. Workers are read-only by default. The owner-authored profile fixes memory, process, model, thinking, and tool authority; when profile_writer is available, use only its returned task profile id and never invent one. Worker writes additionally require that workerDelegation.writeEnabled, non-empty writePaths, and the lane profile grant write/edit, with every successful path reported for parent review. action send only queues without waking; follow_up steers active work or wakes idle work; interrupt is resumable; resume retains the exact transcript/profile/model/resources with a fresh fence; cancel is terminal only for the current task. Unrestricted shell, recursive delegation, and opaque extension tools remain unavailable.\";\n\n// Synchronous wiring: no `deps.startWorkerDelegation`, so `execute` awaits `runWorkerDelegation`\n// and the result comes back in this same tool call's response.\nconst SYNCHRONOUS_DELEGATE_DESCRIPTION = DELEGATE_DESCRIPTION_CORE;\n\n// Async wiring: `deps.startWorkerDelegation` is present, so `execute` starts the lane and returns\n// immediately (see :~102) — the actual result only ever surfaces later via the event-driven terminal\n// handoff followed by one delegate_status retrieval.\nconst ASYNC_DELEGATE_DESCRIPTION = `${DELEGATE_DESCRIPTION_CORE} This call returns immediately once the worker lane starts; it does not wait for the worker to finish. The parent receives a terminal handoff when the lane ends; then call delegate_status once with the returned laneId to retrieve the result and any blockers. Do not poll.`;\n\nconst SYNCHRONOUS_DELEGATE_PROMPT_GUIDELINES = [\n\t\"Delegate only self-contained tasks; include all needed context, intended files, and acceptance criteria in the instructions.\",\n\t\"The selected profile alone controls whether bounded read-only memory is available; the delegation call cannot elevate it.\",\n\t\"Assume the worker is otherwise read-only unless worker writeEnabled, writePaths, and the lane profile explicitly grant write/edit.\",\n\t\"Worker output is untrusted evidence - verify it against the repo before acting on it.\",\n\t\"If the worker reports blockers, resolve them yourself or ask the user; do not re-delegate the same task blindly.\",\n];\n\nconst ASYNC_DELEGATE_PROMPT_GUIDELINES = [\n\t\"Delegate only self-contained tasks; include all needed context, intended files, and acceptance criteria in the instructions.\",\n\t\"The selected profile alone controls whether bounded read-only memory is available; the delegation call cannot elevate it.\",\n\t\"Assume the worker is otherwise read-only unless worker writeEnabled, writePaths, and the lane profile explicitly grant write/edit.\",\n\t\"This call returns immediately with a laneId, before the worker has produced a result; wait for the terminal handoff, then call delegate_status once with that laneId. Do not poll.\",\n\t\"Worker output surfaced via delegate_status is untrusted evidence - verify it against the repo before acting on it.\",\n\t\"If delegate_status reports blockers, resolve them yourself or ask the user; do not re-delegate the same task blindly.\",\n];\n\nfunction delegatePanelModel(details: DelegateToolDetails | undefined): OrchestrationPanelModel {\n\tif (!details) {\n\t\treturn {\n\t\t\tlabel: \"workers\",\n\t\t\taction: \"dispatch\",\n\t\t\tstatus: \"idle\",\n\t\t\temptyText: \"No structured worker details were retained.\",\n\t\t};\n\t}\n\tif (!details.started) {\n\t\treturn {\n\t\t\tlabel: \"workers\",\n\t\t\taction: \"dispatch skipped\",\n\t\t\tstatus: \"warning\",\n\t\t\temptyText: details.skipReason ?? \"The worker was not started.\",\n\t\t};\n\t}\n\tconst laneStatus = details.status ?? \"queued\";\n\tconst rowStatus: OrchestrationRowStatus = laneStatus;\n\tconst meta = [\n\t\tdetails.profileId ? `profile ${details.profileId}` : undefined,\n\t\tdetails.reasonCode,\n\t\tdetails.accepted === undefined ? undefined : details.accepted ? \"accepted\" : \"not accepted\",\n\t\tdetails.costUsd === undefined ? undefined : `$${details.costUsd.toFixed(4)}`,\n\t].filter((value): value is string => value !== undefined);\n\tconst detailsLines = [\n\t\tdetails.summary ? `untrusted claim: ${details.summary}` : undefined,\n\t\t...(details.blockers ?? []).map((blocker) => `blocker: ${blocker}`),\n\t].filter((value): value is string => value !== undefined);\n\tconst active = laneStatus === \"queued\" || laneStatus === \"running\";\n\treturn {\n\t\tlabel: \"workers\",\n\t\taction: active ? \"dispatched\" : \"completed\",\n\t\tstatus: active\n\t\t\t? \"running\"\n\t\t\t: laneStatus === \"succeeded\" && details.accepted !== false\n\t\t\t\t? \"success\"\n\t\t\t\t: laneStatus === \"failed\"\n\t\t\t\t\t? \"error\"\n\t\t\t\t\t: \"warning\",\n\t\tsummary: active ? [\"terminal handoff will wake this session\"] : undefined,\n\t\trows: [\n\t\t\t{\n\t\t\t\tstatus: rowStatus,\n\t\t\t\tlabel: details.label ?? details.laneId ?? \"worker lane\",\n\t\t\t\tmeta: [details.label ? details.laneId : undefined, ...meta].filter(\n\t\t\t\t\t(value): value is string => value !== undefined,\n\t\t\t\t),\n\t\t\t\tdetails: detailsLines,\n\t\t\t},\n\t\t],\n\t\tnotices:\n\t\t\tdetails.accepted === false\n\t\t\t\t? [{ status: \"warning\", text: \"Worker output was not accepted; inspect and verify before use.\" }]\n\t\t\t\t: undefined,\n\t};\n}\n\nfunction orchestrationProfileGuideline(\n\tprofiles: readonly { profileId: string; role: string; description: string }[] | undefined,\n): string {\n\tif (!profiles || profiles.length === 0) {\n\t\treturn \"Delegation requires an owner-authored orchestration profile. Regular sessions must rely on the owner's configured default; only an active owner-authored orchestrator may select a profileId. Never invent, create, or edit profiles during delegation.\";\n\t}\n\tconst visibleProfiles = profiles.slice(0, MAX_VISIBLE_ORCHESTRATION_PROFILES);\n\tconst entries = visibleProfiles.map((profile) => {\n\t\tconst profileId = profile.profileId.slice(0, MAX_PROFILE_GUIDELINE_FIELD_CHARS);\n\t\tconst role = profile.role.slice(0, MAX_PROFILE_GUIDELINE_FIELD_CHARS);\n\t\tconst description = profile.description.slice(0, MAX_PROFILE_GUIDELINE_FIELD_CHARS);\n\t\treturn `${profileId} (${role}: ${description})`;\n\t});\n\tconst omitted = profiles.length - visibleProfiles.length;\n\treturn [\n\t\t`Available owner-authored orchestration profiles: ${profiles.length} configured; ${entries.join(\"; \")}`,\n\t\t...(omitted > 0 ? [`${omitted} omitted from this prompt; use the owner profile catalog to select them.`] : []),\n\t\t\"Only an active owner-authored orchestrator may select an allowlisted profileId; regular sessions must omit it and use the owner's configured default. Never invent, create, or edit profiles during delegation, and never infer or request a model/thinking override.\",\n\t]\n\t\t.join(\" \")\n\t\t.slice(0, MAX_PROFILE_GUIDELINE_CHARS);\n}\n\nexport function createDelegateToolDefinition(deps: DelegateToolDependencies): ToolDefinition {\n\tconst isAsyncWiring = deps.startWorkerDelegation !== undefined;\n\tconst profileGuideline = orchestrationProfileGuideline(deps.orchestrationProfiles);\n\treturn {\n\t\tname: \"delegate\",\n\t\tlabel: \"delegate\",\n\t\tdescription: isAsyncWiring ? ASYNC_DELEGATE_DESCRIPTION : SYNCHRONOUS_DELEGATE_DESCRIPTION,\n\t\tpromptSnippet: \"Delegate a bounded task to an isolated, least-privilege worker lane.\",\n\t\tpromptGuidelines: [\n\t\t\tprofileGuideline,\n\t\t\t...(isAsyncWiring ? ASYNC_DELEGATE_PROMPT_GUIDELINES : SYNCHRONOUS_DELEGATE_PROMPT_GUIDELINES),\n\t\t],\n\t\tparameters: delegateSchema,\n\t\trenderShell: \"self\",\n\t\trenderCall() {\n\t\t\treturn emptyOrchestrationCall();\n\t\t},\n\t\trenderResult(result, { expanded, isPartial }, theme) {\n\t\t\tconst details = result.details as DelegateToolDetails | undefined;\n\t\t\treturn renderOrchestrationToolResult(theme, delegatePanelModel(details), {\n\t\t\t\tisPartial,\n\t\t\t\tcollapse: !expanded && details?.started === true,\n\t\t\t\texpanded,\n\t\t\t});\n\t\t},\n\t\tasync execute(\n\t\t\t_toolCallId,\n\t\t\tinput: DelegateToolInput,\n\t\t): Promise<{\n\t\t\tcontent: Array<{ type: \"text\"; text: string }>;\n\t\t\tdetails: DelegateToolDetails;\n\t\t}> {\n\t\t\tconst requestedAction = input.action ?? \"start\";\n\t\t\tconst invalid = (message: string, actionDetails: DelegateToolDetails) => ({\n\t\t\t\tcontent: [{ type: \"text\" as const, text: message }],\n\t\t\t\tdetails: actionDetails,\n\t\t\t});\n\t\t\tif (!isDelegateAction(requestedAction)) {\n\t\t\t\treturn invalid(`delegate action is invalid: ${requestedAction}`, {\n\t\t\t\t\tstarted: false,\n\t\t\t\t\tskipReason: \"invalid_action\",\n\t\t\t\t});\n\t\t\t}\n\t\t\tconst action = requestedAction;\n\t\t\tif (input.instructions !== undefined && input.instructions.length > MAX_DELEGATE_INSTRUCTIONS_CHARS) {\n\t\t\t\treturn invalid(`delegate instructions may not exceed ${MAX_DELEGATE_INSTRUCTIONS_CHARS} characters`, {\n\t\t\t\t\tstarted: false,\n\t\t\t\t\taction,\n\t\t\t\t\tskipReason: \"instructions_too_long\",\n\t\t\t\t});\n\t\t\t}\n\t\t\tif (input.profileId !== undefined && input.profileId.length > MAX_DELEGATE_PROFILE_ID_CHARS) {\n\t\t\t\treturn invalid(`delegate profileId may not exceed ${MAX_DELEGATE_PROFILE_ID_CHARS} characters`, {\n\t\t\t\t\tstarted: false,\n\t\t\t\t\taction,\n\t\t\t\t\tskipReason: \"profile_id_too_long\",\n\t\t\t\t});\n\t\t\t}\n\t\t\tif (input.agentId !== undefined && input.agentId.length > MAX_DELEGATE_AGENT_ID_CHARS) {\n\t\t\t\treturn invalid(`delegate agentId may not exceed ${MAX_DELEGATE_AGENT_ID_CHARS} characters`, {\n\t\t\t\t\tstarted: false,\n\t\t\t\t\taction,\n\t\t\t\t\tskipReason: \"agent_id_too_long\",\n\t\t\t\t});\n\t\t\t}\n\t\t\tif (input.message !== undefined && input.message.length > MAX_DELEGATE_MESSAGE_CHARS) {\n\t\t\t\treturn invalid(`delegate message may not exceed ${MAX_DELEGATE_MESSAGE_CHARS} characters`, {\n\t\t\t\t\tstarted: false,\n\t\t\t\t\taction,\n\t\t\t\t\tskipReason: \"message_too_long\",\n\t\t\t\t});\n\t\t\t}\n\t\t\tconst requireAgentId = (): string | undefined => {\n\t\t\t\tconst agentId = input.agentId?.trim();\n\t\t\t\tif (agentId) return agentId;\n\t\t\t\treturn undefined;\n\t\t\t};\n\t\t\ttry {\n\t\t\t\tif (action !== \"start\") {\n\t\t\t\t\tconst agentId = requireAgentId();\n\t\t\t\t\tif (!agentId)\n\t\t\t\t\t\treturn invalid(`delegate ${action} requires agentId`, {\n\t\t\t\t\t\t\tstarted: false,\n\t\t\t\t\t\t\taction,\n\t\t\t\t\t\t\tskipReason: \"missing_agent_id\",\n\t\t\t\t\t\t});\n\t\t\t\t\tif (action === \"send\" || action === \"follow_up\") {\n\t\t\t\t\t\tconst message = input.message?.trim();\n\t\t\t\t\t\tif (!message)\n\t\t\t\t\t\t\treturn invalid(`delegate ${action} requires message`, {\n\t\t\t\t\t\t\t\tstarted: false,\n\t\t\t\t\t\t\t\taction,\n\t\t\t\t\t\t\t\tagentId,\n\t\t\t\t\t\t\t\tskipReason: \"missing_message\",\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\tif (action === \"send\") {\n\t\t\t\t\t\t\tif (!deps.workerAgentControl)\n\t\t\t\t\t\t\t\treturn invalid(\"delegate send is unavailable\", {\n\t\t\t\t\t\t\t\t\tstarted: false,\n\t\t\t\t\t\t\t\t\taction,\n\t\t\t\t\t\t\t\t\tagentId,\n\t\t\t\t\t\t\t\t\tskipReason: \"worker_agent_control_unavailable\",\n\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\tconst outcome = deps.workerAgentControl.sendWorkerAgentMessage(agentId, message);\n\t\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t\tcontent: [\n\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\ttype: \"text\" as const,\n\t\t\t\t\t\t\t\t\t\ttext: `message queued for ${agentId}; it will not wake the worker`,\n\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t\tdetails: { started: true, action, agentId, queued: outcome.queued },\n\t\t\t\t\t\t\t};\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (!deps.workerAgentControl)\n\t\t\t\t\t\t\treturn invalid(\"delegate follow_up is unavailable\", {\n\t\t\t\t\t\t\t\tstarted: false,\n\t\t\t\t\t\t\t\taction,\n\t\t\t\t\t\t\t\tagentId,\n\t\t\t\t\t\t\t\tskipReason: \"worker_agent_control_unavailable\",\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\tconst outcome = deps.workerAgentControl.followUpWorkerAgent(agentId, message);\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\tcontent: [\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\ttype: \"text\" as const,\n\t\t\t\t\t\t\t\t\ttext: `follow_up ${outcome.started ? \"started\" : \"queued\"} for ${agentId}`,\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\tdetails: {\n\t\t\t\t\t\t\t\tstarted: outcome.started,\n\t\t\t\t\t\t\t\taction,\n\t\t\t\t\t\t\t\tagentId,\n\t\t\t\t\t\t\t\tlaneId: outcome.record?.laneId,\n\t\t\t\t\t\t\t\tstatus: outcome.record?.status,\n\t\t\t\t\t\t\t\tskipReason: outcome.skipReason,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\t\t\t\t\tif (action === \"interrupt\") {\n\t\t\t\t\t\tif (!deps.workerAgentControl)\n\t\t\t\t\t\t\treturn invalid(\"delegate interrupt is unavailable\", {\n\t\t\t\t\t\t\t\tstarted: false,\n\t\t\t\t\t\t\t\taction,\n\t\t\t\t\t\t\t\tagentId,\n\t\t\t\t\t\t\t\tskipReason: \"worker_agent_control_unavailable\",\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\tconst outcome = deps.workerAgentControl.interruptWorkerAgent(agentId);\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\tcontent: [\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\ttype: \"text\" as const,\n\t\t\t\t\t\t\t\t\ttext: outcome.interrupted\n\t\t\t\t\t\t\t\t\t\t? `worker ${agentId} interrupted; resume preserves its admitted state`\n\t\t\t\t\t\t\t\t\t\t: `worker ${agentId} was not interrupted (${outcome.reason ?? \"unknown\"})`,\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\tdetails: { started: outcome.interrupted, action, agentId, skipReason: outcome.reason },\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\t\t\t\t\tif (action === \"resume\") {\n\t\t\t\t\t\tif (!deps.workerAgentControl)\n\t\t\t\t\t\t\treturn invalid(\"delegate resume is unavailable\", {\n\t\t\t\t\t\t\t\tstarted: false,\n\t\t\t\t\t\t\t\taction,\n\t\t\t\t\t\t\t\tagentId,\n\t\t\t\t\t\t\t\tskipReason: \"worker_agent_control_unavailable\",\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\tconst outcome = deps.workerAgentControl.resumeWorkerAgent(agentId);\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\tcontent: [\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\ttype: \"text\" as const,\n\t\t\t\t\t\t\t\t\ttext: outcome.started\n\t\t\t\t\t\t\t\t\t\t? `worker ${agentId} resumed with its admitted transcript and authority`\n\t\t\t\t\t\t\t\t\t\t: `worker ${agentId} was not resumed (${outcome.skipReason ?? \"unknown\"})`,\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\tdetails: {\n\t\t\t\t\t\t\t\tstarted: outcome.started,\n\t\t\t\t\t\t\t\taction,\n\t\t\t\t\t\t\t\tagentId,\n\t\t\t\t\t\t\t\tlaneId: outcome.record?.laneId,\n\t\t\t\t\t\t\t\tstatus: outcome.record?.status,\n\t\t\t\t\t\t\t\tskipReason: outcome.skipReason,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\t\t\t\t\tif (!deps.workerAgentControl)\n\t\t\t\t\t\treturn invalid(\"delegate cancel is unavailable\", {\n\t\t\t\t\t\t\tstarted: false,\n\t\t\t\t\t\t\taction,\n\t\t\t\t\t\t\tagentId,\n\t\t\t\t\t\t\tskipReason: \"worker_agent_control_unavailable\",\n\t\t\t\t\t\t});\n\t\t\t\t\tconst cancelled = deps.workerAgentControl.cancelWorkerAgent(agentId);\n\t\t\t\t\treturn {\n\t\t\t\t\t\tcontent: [\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\ttype: \"text\" as const,\n\t\t\t\t\t\t\t\ttext: cancelled\n\t\t\t\t\t\t\t\t\t? `worker ${agentId} cancelled for its current task`\n\t\t\t\t\t\t\t\t\t: `worker ${agentId} was not cancelled`,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t],\n\t\t\t\t\t\tdetails: {\n\t\t\t\t\t\t\tstarted: Boolean(cancelled),\n\t\t\t\t\t\t\taction,\n\t\t\t\t\t\t\tagentId,\n\t\t\t\t\t\t\tlaneId: cancelled?.laneId,\n\t\t\t\t\t\t\tstatus: cancelled?.status,\n\t\t\t\t\t\t\treasonCode: cancelled?.reasonCode,\n\t\t\t\t\t\t},\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t\tconst instructions = input.instructions?.trim();\n\t\t\t\tif (!instructions)\n\t\t\t\t\treturn invalid(\"delegate start requires instructions\", {\n\t\t\t\t\t\tstarted: false,\n\t\t\t\t\t\taction,\n\t\t\t\t\t\tskipReason: \"missing_instructions\",\n\t\t\t\t\t});\n\t\t\t\tconst profileId = input.profileId?.trim();\n\t\t\t\tconst request = { instructions, ...(profileId ? { profileId } : {}) };\n\t\t\t\tif (deps.startWorkerDelegation) {\n\t\t\t\t\tconst started = deps.startWorkerDelegation(request);\n\t\t\t\t\tif (!started.started) {\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\tcontent: [{ type: \"text\" as const, text: `delegate skipped: ${started.skipReason}` }],\n\t\t\t\t\t\t\tdetails: {\n\t\t\t\t\t\t\t\tstarted: false,\n\t\t\t\t\t\t\t\tskipReason: started.skipReason,\n\t\t\t\t\t\t\t\t...(profileId ? { profileId } : {}),\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\t\t\t\t\treturn {\n\t\t\t\t\t\tcontent: [\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\ttype: \"text\" as const,\n\t\t\t\t\t\t\t\ttext: `delegate started (${started.record.status}) — stable agentId ${started.record.laneId}, task laneId ${started.record.laneId}; wait for its terminal handoff, then retrieve once with delegate_status`,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t],\n\t\t\t\t\t\tdetails: {\n\t\t\t\t\t\t\tstarted: true,\n\t\t\t\t\t\t\t...((started.record.profileId ?? profileId)\n\t\t\t\t\t\t\t\t? { profileId: started.record.profileId ?? profileId }\n\t\t\t\t\t\t\t\t: {}),\n\t\t\t\t\t\t\tagentId: started.record.laneId,\n\t\t\t\t\t\t\tlaneId: started.record.laneId,\n\t\t\t\t\t\t\t...(started.record.label ? { label: started.record.label } : {}),\n\t\t\t\t\t\t\tstatus: started.record.status,\n\t\t\t\t\t\t},\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t\tconst run = await deps.runWorkerDelegation(request);\n\t\t\t\tif (!run.started) {\n\t\t\t\t\tconst reason = run.skipReason ?? \"unknown\";\n\t\t\t\t\treturn {\n\t\t\t\t\t\tcontent: [{ type: \"text\" as const, text: `delegate skipped: ${reason}` }],\n\t\t\t\t\t\tdetails: {\n\t\t\t\t\t\t\tstarted: false,\n\t\t\t\t\t\t\tskipReason: reason,\n\t\t\t\t\t\t\t...(profileId ? { profileId } : {}),\n\t\t\t\t\t\t},\n\t\t\t\t\t};\n\t\t\t\t}\n\n\t\t\t\tconst outcome = run.outcome;\n\t\t\t\tconst lines: string[] = [\n\t\t\t\t\t`delegate ${run.record?.status ?? \"unknown\"}${run.record?.reasonCode ? ` (${run.record.reasonCode})` : \"\"}`,\n\t\t\t\t];\n\t\t\t\tif (outcome) {\n\t\t\t\t\tlines.push(\n\t\t\t\t\t\t`accepted: ${outcome.accepted} [${outcome.acceptance.outcome}/${outcome.acceptance.reasonCode}]`,\n\t\t\t\t\t\t\"Worker output (UNTRUSTED - verify before acting on it):\",\n\t\t\t\t\t\toutcome.claim.summary.slice(0, 8_000),\n\t\t\t\t\t);\n\t\t\t\t\tif (outcome.claim.blockers && outcome.claim.blockers.length > 0) {\n\t\t\t\t\t\tlines.push(\n\t\t\t\t\t\t\t`Blockers: ${outcome.claim.blockers\n\t\t\t\t\t\t\t\t.slice(0, 16)\n\t\t\t\t\t\t\t\t.map((blocker) => blocker.slice(0, 512))\n\t\t\t\t\t\t\t\t.join(\"; \")}`,\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t\tfor (const finding of outcome.claim.evidence?.findings.slice(0, 16) ?? []) {\n\t\t\t\t\t\tlines.push(`- Finding: ${finding.summary.slice(0, 512)}`);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\treturn {\n\t\t\t\t\tcontent: [{ type: \"text\" as const, text: lines.join(\"\\n\").slice(0, MAX_DELEGATE_RESULT_CHARS) }],\n\t\t\t\t\tdetails: {\n\t\t\t\t\t\tstarted: true,\n\t\t\t\t\t\tprofileId: run.record?.profileId ?? profileId,\n\t\t\t\t\t\tagentId: run.record?.laneId,\n\t\t\t\t\t\tlaneId: run.record?.laneId,\n\t\t\t\t\t\tlabel: run.record?.label,\n\t\t\t\t\t\tstatus: run.record?.status,\n\t\t\t\t\t\treasonCode: run.record?.reasonCode,\n\t\t\t\t\t\taccepted: outcome?.accepted,\n\t\t\t\t\t\tcostUsd: outcome?.costUsd,\n\t\t\t\t\t\tsummary: outcome?.claim.summary.slice(0, 8_000),\n\t\t\t\t\t\tblockers: outcome?.claim.blockers?.slice(0, 16),\n\t\t\t\t\t},\n\t\t\t\t};\n\t\t\t} catch (error) {\n\t\t\t\tconst reason = (error instanceof Error ? error.message : String(error)).slice(0, MAX_DELEGATE_ERROR_CHARS);\n\t\t\t\treturn invalid(`delegate ${action} failed: ${reason}`.slice(0, 2_048), {\n\t\t\t\t\tstarted: false,\n\t\t\t\t\taction,\n\t\t\t\t\t...(input.agentId?.trim() ? { agentId: input.agentId.trim() } : {}),\n\t\t\t\t\tskipReason: \"worker_agent_control_error\",\n\t\t\t\t});\n\t\t\t}\n\t\t},\n\t};\n}\n"]}