@astralyn/pi 0.84.11 → 0.84.12

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 (181) hide show
  1. package/CHANGELOG.md +21 -0
  2. package/dist/cli/startup-ui.d.ts.map +1 -1
  3. package/dist/cli/startup-ui.js +2 -1
  4. package/dist/cli/startup-ui.js.map +1 -1
  5. package/dist/core/agent-session.d.ts +62 -8
  6. package/dist/core/agent-session.d.ts.map +1 -1
  7. package/dist/core/agent-session.js +395 -78
  8. package/dist/core/agent-session.js.map +1 -1
  9. package/dist/core/compaction/branch-summarization.d.ts.map +1 -1
  10. package/dist/core/compaction/branch-summarization.js +4 -3
  11. package/dist/core/compaction/branch-summarization.js.map +1 -1
  12. package/dist/core/compaction/compaction.d.ts +5 -0
  13. package/dist/core/compaction/compaction.d.ts.map +1 -1
  14. package/dist/core/compaction/compaction.js +19 -5
  15. package/dist/core/compaction/compaction.js.map +1 -1
  16. package/dist/core/extensions/index.d.ts +1 -1
  17. package/dist/core/extensions/index.d.ts.map +1 -1
  18. package/dist/core/extensions/index.js.map +1 -1
  19. package/dist/core/extensions/runner.d.ts +5 -0
  20. package/dist/core/extensions/runner.d.ts.map +1 -1
  21. package/dist/core/extensions/runner.js +44 -1
  22. package/dist/core/extensions/runner.js.map +1 -1
  23. package/dist/core/extensions/types.d.ts +18 -10
  24. package/dist/core/extensions/types.d.ts.map +1 -1
  25. package/dist/core/extensions/types.js.map +1 -1
  26. package/dist/core/session-manager.d.ts.map +1 -1
  27. package/dist/core/session-manager.js +4 -2
  28. package/dist/core/session-manager.js.map +1 -1
  29. package/dist/core/settings-manager.d.ts +8 -1
  30. package/dist/core/settings-manager.d.ts.map +1 -1
  31. package/dist/core/settings-manager.js +17 -0
  32. package/dist/core/settings-manager.js.map +1 -1
  33. package/dist/core/tools/bash.d.ts +5 -0
  34. package/dist/core/tools/bash.d.ts.map +1 -1
  35. package/dist/core/tools/bash.js +5 -1
  36. package/dist/core/tools/bash.js.map +1 -1
  37. package/dist/extensions/background/actions.d.ts +21 -0
  38. package/dist/extensions/background/actions.d.ts.map +1 -0
  39. package/dist/extensions/background/actions.js +264 -0
  40. package/dist/extensions/background/actions.js.map +1 -0
  41. package/dist/extensions/background/constants.d.ts +24 -0
  42. package/dist/extensions/background/constants.d.ts.map +1 -0
  43. package/dist/extensions/background/constants.js +24 -0
  44. package/dist/extensions/background/constants.js.map +1 -0
  45. package/dist/extensions/background/index.d.ts +6 -115
  46. package/dist/extensions/background/index.d.ts.map +1 -1
  47. package/dist/extensions/background/index.js +38 -509
  48. package/dist/extensions/background/index.js.map +1 -1
  49. package/dist/extensions/background/manager.d.ts +2 -1
  50. package/dist/extensions/background/manager.d.ts.map +1 -1
  51. package/dist/extensions/background/manager.js +8 -10
  52. package/dist/extensions/background/manager.js.map +1 -1
  53. package/dist/extensions/background/notify.d.ts +16 -0
  54. package/dist/extensions/background/notify.d.ts.map +1 -0
  55. package/dist/extensions/background/notify.js +114 -0
  56. package/dist/extensions/background/notify.js.map +1 -0
  57. package/dist/extensions/background/output-file.d.ts +58 -0
  58. package/dist/extensions/background/output-file.d.ts.map +1 -0
  59. package/dist/extensions/background/output-file.js +122 -0
  60. package/dist/extensions/background/output-file.js.map +1 -0
  61. package/dist/extensions/background/registry.d.ts +40 -72
  62. package/dist/extensions/background/registry.d.ts.map +1 -1
  63. package/dist/extensions/background/registry.js +71 -184
  64. package/dist/extensions/background/registry.js.map +1 -1
  65. package/dist/extensions/background/render.d.ts +3 -10
  66. package/dist/extensions/background/render.d.ts.map +1 -1
  67. package/dist/extensions/background/render.js +20 -60
  68. package/dist/extensions/background/render.js.map +1 -1
  69. package/dist/extensions/background/schema.d.ts +34 -0
  70. package/dist/extensions/background/schema.d.ts.map +1 -0
  71. package/dist/extensions/background/schema.js +89 -0
  72. package/dist/extensions/background/schema.js.map +1 -0
  73. package/dist/extensions/background/task-view.d.ts +48 -0
  74. package/dist/extensions/background/task-view.d.ts.map +1 -0
  75. package/dist/extensions/background/task-view.js +90 -0
  76. package/dist/extensions/background/task-view.js.map +1 -0
  77. package/dist/extensions/background/text.d.ts +15 -0
  78. package/dist/extensions/background/text.d.ts.map +1 -0
  79. package/dist/extensions/background/text.js +31 -0
  80. package/dist/extensions/background/text.js.map +1 -0
  81. package/dist/extensions/background/types.d.ts +74 -0
  82. package/dist/extensions/background/types.d.ts.map +1 -0
  83. package/dist/extensions/background/types.js +17 -0
  84. package/dist/extensions/background/types.js.map +1 -0
  85. package/dist/extensions/llama/client.d.ts +6 -0
  86. package/dist/extensions/llama/client.d.ts.map +1 -1
  87. package/dist/extensions/llama/client.js +7 -0
  88. package/dist/extensions/llama/client.js.map +1 -1
  89. package/dist/extensions/llama/provider.d.ts +3 -1
  90. package/dist/extensions/llama/provider.d.ts.map +1 -1
  91. package/dist/extensions/llama/provider.js +27 -6
  92. package/dist/extensions/llama/provider.js.map +1 -1
  93. package/dist/extensions/subagent/activity.d.ts +5 -0
  94. package/dist/extensions/subagent/activity.d.ts.map +1 -1
  95. package/dist/extensions/subagent/activity.js +5 -0
  96. package/dist/extensions/subagent/activity.js.map +1 -1
  97. package/dist/extensions/subagent/agents-command.d.ts.map +1 -1
  98. package/dist/extensions/subagent/agents-command.js +6 -391
  99. package/dist/extensions/subagent/agents-command.js.map +1 -1
  100. package/dist/extensions/subagent/constants.d.ts.map +1 -1
  101. package/dist/extensions/subagent/constants.js +1 -0
  102. package/dist/extensions/subagent/constants.js.map +1 -1
  103. package/dist/extensions/subagent/render.d.ts.map +1 -1
  104. package/dist/extensions/subagent/render.js +15 -1
  105. package/dist/extensions/subagent/render.js.map +1 -1
  106. package/dist/extensions/subagent/resolve.d.ts.map +1 -1
  107. package/dist/extensions/subagent/resolve.js +2 -4
  108. package/dist/extensions/subagent/resolve.js.map +1 -1
  109. package/dist/extensions/subagent/runner.d.ts +1 -1
  110. package/dist/extensions/subagent/runner.d.ts.map +1 -1
  111. package/dist/extensions/subagent/runner.js +8 -8
  112. package/dist/extensions/subagent/runner.js.map +1 -1
  113. package/dist/extensions/subagent/sdk-runner.d.ts +11 -0
  114. package/dist/extensions/subagent/sdk-runner.d.ts.map +1 -1
  115. package/dist/extensions/subagent/sdk-runner.js +90 -79
  116. package/dist/extensions/subagent/sdk-runner.js.map +1 -1
  117. package/dist/extensions/subagent/state.d.ts.map +1 -1
  118. package/dist/extensions/subagent/state.js +145 -126
  119. package/dist/extensions/subagent/state.js.map +1 -1
  120. package/dist/extensions/subagent/text.d.ts.map +1 -1
  121. package/dist/extensions/subagent/text.js +4 -0
  122. package/dist/extensions/subagent/text.js.map +1 -1
  123. package/dist/extensions/subagent/ui/agents-dialog.d.ts +4 -0
  124. package/dist/extensions/subagent/ui/agents-dialog.d.ts.map +1 -0
  125. package/dist/extensions/subagent/ui/agents-dialog.js +84 -0
  126. package/dist/extensions/subagent/ui/agents-dialog.js.map +1 -0
  127. package/dist/extensions/subagent/ui/choice-menu.d.ts +39 -0
  128. package/dist/extensions/subagent/ui/choice-menu.d.ts.map +1 -0
  129. package/dist/extensions/subagent/ui/choice-menu.js +93 -0
  130. package/dist/extensions/subagent/ui/choice-menu.js.map +1 -0
  131. package/dist/extensions/subagent/ui/model-picker.d.ts +47 -0
  132. package/dist/extensions/subagent/ui/model-picker.d.ts.map +1 -0
  133. package/dist/extensions/subagent/ui/model-picker.js +142 -0
  134. package/dist/extensions/subagent/ui/model-picker.js.map +1 -0
  135. package/dist/extensions/subagent/ui/profile-settings-menu.d.ts +41 -0
  136. package/dist/extensions/subagent/ui/profile-settings-menu.d.ts.map +1 -0
  137. package/dist/extensions/subagent/ui/profile-settings-menu.js +98 -0
  138. package/dist/extensions/subagent/ui/profile-settings-menu.js.map +1 -0
  139. package/dist/index.d.ts +2 -1
  140. package/dist/index.d.ts.map +1 -1
  141. package/dist/index.js +1 -0
  142. package/dist/index.js.map +1 -1
  143. package/dist/main.d.ts.map +1 -1
  144. package/dist/main.js +2 -0
  145. package/dist/main.js.map +1 -1
  146. package/dist/modes/interactive/components/settings-selector.d.ts +2 -0
  147. package/dist/modes/interactive/components/settings-selector.d.ts.map +1 -1
  148. package/dist/modes/interactive/components/settings-selector.js +10 -0
  149. package/dist/modes/interactive/components/settings-selector.js.map +1 -1
  150. package/dist/modes/interactive/interactive-mode.d.ts +4 -0
  151. package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
  152. package/dist/modes/interactive/interactive-mode.js +71 -58
  153. package/dist/modes/interactive/interactive-mode.js.map +1 -1
  154. package/dist/modes/rpc/rpc-client.d.ts +7 -0
  155. package/dist/modes/rpc/rpc-client.d.ts.map +1 -1
  156. package/dist/modes/rpc/rpc-client.js +7 -0
  157. package/dist/modes/rpc/rpc-client.js.map +1 -1
  158. package/dist/modes/rpc/rpc-mode.d.ts.map +1 -1
  159. package/dist/modes/rpc/rpc-mode.js +3 -0
  160. package/dist/modes/rpc/rpc-mode.js.map +1 -1
  161. package/dist/modes/rpc/rpc-types.d.ts +12 -0
  162. package/dist/modes/rpc/rpc-types.d.ts.map +1 -1
  163. package/dist/modes/rpc/rpc-types.js.map +1 -1
  164. package/dist/utils/shell.d.ts.map +1 -1
  165. package/dist/utils/shell.js +6 -4
  166. package/dist/utils/shell.js.map +1 -1
  167. package/docs/compaction.md +5 -12
  168. package/docs/environment-variables.md +3 -0
  169. package/docs/extensions.md +21 -5
  170. package/docs/keybindings.md +1 -1
  171. package/docs/quickstart.md +1 -1
  172. package/docs/rpc.md +23 -0
  173. package/docs/settings.md +7 -0
  174. package/docs/terminal-setup.md +12 -0
  175. package/docs/usage.md +4 -3
  176. package/npm-shrinkwrap.json +29 -29
  177. package/package.json +6 -6
  178. package/dist/core/compaction-controller.d.ts +0 -90
  179. package/dist/core/compaction-controller.d.ts.map +0 -1
  180. package/dist/core/compaction-controller.js +0 -471
  181. package/dist/core/compaction-controller.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"bash.js","sourceRoot":"","sources":["../../../src/core/tools/bash.ts"],"names":[],"mappings":"AAAA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AAI,CAAC;AACb,CAAC","sourcesContent":["import { constants } from \"node:fs\";\nimport { access as fsAccess } from \"node:fs/promises\";\nimport type { AgentTool } from \"@earendil-works/pi-agent-core\";\nimport { type Component, Container, Text, truncateToWidth, visibleWidth } from \"@earendil-works/pi-tui\";\nimport { spawn } from \"child_process\";\nimport { type Static, Type } from \"typebox\";\nimport { truncateToVisualLines } from \"../../modes/interactive/components/visual-truncate.ts\";\nimport { highlightCode, theme } from \"../../modes/interactive/theme/theme.ts\";\nimport { waitForChildProcess } from \"../../utils/child-process.ts\";\nimport {\n\tgetShellConfig,\n\tgetShellEnv,\n\tkillProcessTree,\n\trewriteCmdNulRedirects,\n\ttype ShellConfig,\n\ttrackDetachedChildPid,\n\tuntrackDetachedChildPid,\n} from \"../../utils/shell.ts\";\nimport { getExperimentalToolSampling } from \"../experimental.ts\";\nimport type { ExtensionContext, ToolDefinition, ToolRenderResultOptions } from \"../extensions/types.ts\";\nimport { OutputAccumulator } from \"./output-accumulator.ts\";\nimport { collapsedLinesHint, getTextOutput, invalidArgText, str } from \"./render-utils.ts\";\nimport { wrapToolDefinition } from \"./tool-definition-wrapper.ts\";\nimport { DEFAULT_MAX_BYTES, DEFAULT_MAX_LINES, formatSize, type TruncationResult } from \"./truncate.ts\";\n\nconst MAX_TIMEOUT_MS = 2_147_483_647;\nexport const MAX_TIMEOUT_SECONDS = MAX_TIMEOUT_MS / 1000;\n\nfunction resolveTimeoutMs(timeout: number | undefined): number | undefined {\n\tif (timeout === undefined) return undefined;\n\tif (!Number.isFinite(timeout) || timeout <= 0) {\n\t\tthrow new Error(\"Invalid timeout: must be a finite number of seconds\");\n\t}\n\n\tconst timeoutMs = timeout * 1000;\n\tif (timeoutMs > MAX_TIMEOUT_MS) {\n\t\tthrow new Error(`Invalid timeout: maximum is ${MAX_TIMEOUT_SECONDS} seconds`);\n\t}\n\treturn timeoutMs;\n}\n\nconst bashSchema = Type.Object({\n\tcommand: Type.String({ description: \"Shell command to execute\" }),\n\ttimeout: Type.Optional(Type.Number({ description: \"Timeout in seconds (optional, no default timeout)\" })),\n});\n\nexport const bashToolSystemPromptContribution = {\n\tsnippet: \"Execute bash commands (ls, grep, find, etc.)\",\n\tguidelines: [\"You can inspect PI_* environment variables for current model and session details.\"],\n} as const;\n\nexport type BashToolInput = Static<typeof bashSchema>;\n\nexport interface BashToolDetails {\n\ttruncation?: TruncationResult;\n\tfullOutputPath?: string;\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\t * Error contract: reject with `new Error(\"aborted\")` when aborted via `signal`,\n\t * and `new Error(\"timeout:<seconds>\")` on timeout expiry — callers (including\n\t * the background extension) classify outcomes from these exact markers.\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\n/** Shared process execution used by the built-in shell tools. */\nexport function createLocalShellOperations(\n\tshellName: string,\n\tresolveShellConfig: () => ShellConfig,\n\tnormalizeCommand: (command: string) => string = (command) => command,\n): BashOperations {\n\treturn {\n\t\texec: async (command, cwd, { onData, signal, timeout, env }) => {\n\t\t\tconst timeoutMs = resolveTimeoutMs(timeout);\n\t\t\tif (signal?.aborted) {\n\t\t\t\tthrow new Error(\"aborted\");\n\t\t\t}\n\t\t\tconst shellConfig = resolveShellConfig();\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\n\t\t\tconst commandFromStdin = shellConfig.commandTransport === \"stdin\";\n\t\t\tconst normalizedCommand = normalizeCommand(command);\n\t\t\tconst child = spawn(\n\t\t\t\tshellConfig.shell,\n\t\t\t\tcommandFromStdin ? shellConfig.args : [...shellConfig.args, normalizedCommand],\n\t\t\t\t{\n\t\t\t\t\tcwd,\n\t\t\t\t\tdetached: process.platform !== \"win32\",\n\t\t\t\t\tenv: env ?? getShellEnv(),\n\t\t\t\t\tstdio: [commandFromStdin ? \"pipe\" : \"ignore\", \"pipe\", \"pipe\"],\n\t\t\t\t\twindowsHide: true,\n\t\t\t\t},\n\t\t\t);\n\t\t\tif (commandFromStdin) {\n\t\t\t\tchild.stdin?.on(\"error\", () => {});\n\t\t\t\tchild.stdin?.end(normalizedCommand);\n\t\t\t}\n\t\t\tif (child.pid) trackDetachedChildPid(child.pid);\n\t\t\tlet timedOut = false;\n\t\t\tlet timeoutHandle: NodeJS.Timeout | undefined;\n\t\t\tconst onAbort = () => {\n\t\t\t\tif (child.pid) killProcessTree(child.pid);\n\t\t\t};\n\n\t\t\ttry {\n\t\t\t\t// Set timeout if provided.\n\t\t\t\tif (timeoutMs !== undefined) {\n\t\t\t\t\ttimeoutHandle = setTimeout(() => {\n\t\t\t\t\t\ttimedOut = true;\n\t\t\t\t\t\tif (child.pid) killProcessTree(child.pid);\n\t\t\t\t\t}, timeoutMs);\n\t\t\t\t}\n\t\t\t\t// Stream stdout and stderr.\n\t\t\t\tchild.stdout?.on(\"data\", onData);\n\t\t\t\tchild.stderr?.on(\"data\", onData);\n\t\t\t\t// Handle abort signal by killing the entire process tree.\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\t// Handle shell spawn errors and wait for the process to terminate without hanging\n\t\t\t\t// on inherited stdio handles held by detached descendants.\n\t\t\t\tconst exitCode = await waitForChildProcess(child);\n\t\t\t\tif (signal?.aborted) {\n\t\t\t\t\tthrow new Error(\"aborted\");\n\t\t\t\t}\n\t\t\t\tif (timedOut) {\n\t\t\t\t\tthrow new Error(`timeout:${timeout}`);\n\t\t\t\t}\n\t\t\t\treturn { exitCode };\n\t\t\t} finally {\n\t\t\t\tif (child.pid) untrackDetachedChildPid(child.pid);\n\t\t\t\tif (timeoutHandle) clearTimeout(timeoutHandle);\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 }): BashOperations {\n\treturn createLocalShellOperations(\"bash\", () => getShellConfig(options?.shellPath), rewriteCmdNulRedirects);\n}\n\nexport interface BashSpawnContext {\n\tcommand: string;\n\tcwd: string;\n\tenv: NodeJS.ProcessEnv;\n}\n\nexport type BashSpawnHook = (context: BashSpawnContext) => BashSpawnContext;\n\nexport function resolveSpawnContext(\n\tcommand: string,\n\tcwd: string,\n\tspawnHook: BashSpawnHook | undefined,\n\texposeSessionEnvironment: boolean,\n\tctx: ExtensionContext | undefined,\n): BashSpawnContext {\n\tconst env = { ...getShellEnv() };\n\tdelete env.PI_SESSION_ID;\n\tdelete env.PI_SESSION_FILE;\n\tdelete env.PI_PROVIDER;\n\tdelete env.PI_MODEL;\n\tdelete env.PI_REASONING_LEVEL;\n\tif (exposeSessionEnvironment && ctx) {\n\t\tconst model = ctx.model;\n\t\tenv.PI_SESSION_ID = ctx.sessionManager.getSessionId();\n\t\tconst sessionFile = ctx.sessionManager.getSessionFile();\n\t\tif (sessionFile) env.PI_SESSION_FILE = sessionFile;\n\t\tif (model) {\n\t\t\tenv.PI_PROVIDER = model.provider;\n\t\t\tenv.PI_MODEL = model.id;\n\t\t}\n\t\tif (ctx.thinkingLevel) env.PI_REASONING_LEVEL = ctx.thinkingLevel;\n\t}\n\tconst baseContext: BashSpawnContext = { command, cwd, env };\n\treturn spawnHook ? spawnHook(baseContext) : baseContext;\n}\n\nexport interface BashToolOptions {\n\t/** Custom operations for command execution. Default: local 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/** Expose current Pi session metadata as PI_* environment variables. Default: true */\n\texposeSessionEnvironment?: boolean;\n\t/** Hook to adjust command, cwd, or env before execution */\n\tspawnHook?: BashSpawnHook;\n}\n\nconst BASH_PREVIEW_LINES = 5;\nconst BASH_UPDATE_THROTTLE_MS = 100;\n\nexport type BashRenderState = {\n\tstartedAt: number | undefined;\n\tendedAt: number | undefined;\n\tinterval: NodeJS.Timeout | undefined;\n};\n\ntype BashCachedRenderState = {\n\tcachedWidth: number | undefined;\n\tcachedLines: string[] | undefined;\n\tcachedSkipped: number | undefined;\n};\n\nclass BashCallRenderComponent implements Component {\n\tprivate command: string | null = \"\";\n\tprivate timeout: number | undefined;\n\tprivate expanded = false;\n\tprivate cachedWidth: number | undefined;\n\tprivate cachedLines: string[] | undefined;\n\tprivate readonly config: ShellToolConfig;\n\n\tconstructor(config: ShellToolConfig) {\n\t\tthis.config = config;\n\t}\n\n\tupdate(args: { command?: string; timeout?: number } | undefined, expanded: boolean): void {\n\t\tconst command = str(args?.command);\n\t\tconst timeout = args?.timeout as number | undefined;\n\t\tif (this.command === command && this.timeout === timeout && this.expanded === expanded) {\n\t\t\treturn;\n\t\t}\n\n\t\tthis.command = command;\n\t\tthis.timeout = timeout;\n\t\tthis.expanded = expanded;\n\t\tthis.invalidate();\n\t}\n\n\trender(width: number): string[] {\n\t\tif (this.cachedLines === undefined || this.cachedWidth !== width) {\n\t\t\tthis.cachedLines = this.renderLines(Math.max(1, width));\n\t\t\tthis.cachedWidth = width;\n\t\t}\n\t\treturn this.cachedLines;\n\t}\n\n\tinvalidate(): void {\n\t\tthis.cachedWidth = undefined;\n\t\tthis.cachedLines = undefined;\n\t}\n\n\tprivate renderLines(width: number): string[] {\n\t\tconst fullCall = formatFullShellCall(this.command, this.timeout, this.config);\n\t\tconst fullLines = new Text(fullCall, 0, 0).render(width);\n\t\tif (this.expanded || fullLines.length <= 1) return fullLines;\n\t\treturn [formatTruncatedShellCall(this.command, this.timeout, width, this.config)];\n\t}\n}\n\nclass BashResultRenderComponent extends Container {\n\tstate: BashCachedRenderState = {\n\t\tcachedWidth: undefined,\n\t\tcachedLines: undefined,\n\t\tcachedSkipped: undefined,\n\t};\n}\n\nfunction formatShellPrompt(prompt: string): string {\n\treturn theme.fg(\"toolTitle\", theme.bold(`${prompt} `));\n}\n\nfunction formatShellTimeout(timeout: number | undefined): string {\n\treturn timeout ? theme.fg(\"muted\", ` (timeout ${timeout}s)`) : \"\";\n}\n\nfunction styleShellCommand(command: string, config: ShellToolConfig): string {\n\tconst language = config.name === \"powershell\" ? \"powershell\" : \"bash\";\n\treturn highlightCode(command, language).join(\"\\n\");\n}\n\nfunction formatFullShellCall(command: string | null, timeout: number | undefined, config: ShellToolConfig): string {\n\tconst commandDisplay =\n\t\tcommand === null\n\t\t\t? invalidArgText(theme)\n\t\t\t: command\n\t\t\t\t? styleShellCommand(command, config)\n\t\t\t\t: theme.fg(\"toolOutput\", \"...\");\n\treturn formatShellPrompt(config.prompt) + commandDisplay + formatShellTimeout(timeout);\n}\n\nfunction fitCollapsedShellCall(\n\tbody: string,\n\ttimeout: number | undefined,\n\twidth: number,\n\tsuffix: string,\n\tconfig: ShellToolConfig,\n): string {\n\tconst prompt = formatShellPrompt(config.prompt);\n\tconst timeoutSuffix = formatShellTimeout(timeout);\n\tconst bodyWidth = Math.max(0, width - visibleWidth(prompt) - visibleWidth(suffix) - visibleWidth(timeoutSuffix));\n\tconst fittedBody = truncateToWidth(body, bodyWidth, \"\");\n\treturn truncateToWidth(prompt + fittedBody + suffix + timeoutSuffix, width, \"…\");\n}\n\nfunction formatTruncatedShellCall(\n\tcommand: string | null,\n\ttimeout: number | undefined,\n\twidth: number,\n\tconfig: ShellToolConfig,\n): string {\n\tif (command === null) return truncateToWidth(formatFullShellCall(command, timeout, config), width, \"…\");\n\tif (!command) return formatFullShellCall(command, timeout, config);\n\tconst physicalLines = command.split(/\\r?\\n/).filter((line) => line.trim());\n\tconst firstNonEmptyLine = physicalLines[0]?.trim() ?? command.trim();\n\tconst hiddenLines = Math.max(0, physicalLines.length - 1);\n\tconst suffix =\n\t\thiddenLines > 0\n\t\t\t? theme.fg(\"muted\", ` (+${hiddenLines} line${hiddenLines === 1 ? \"\" : \"s\"})`)\n\t\t\t: theme.fg(\"muted\", \" …\");\n\treturn fitCollapsedShellCall(styleShellCommand(firstNonEmptyLine, config), timeout, width, suffix, config);\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\tlet output = getTextOutput(result as any, showImages).trim();\n\tconst truncation = result.details?.truncation;\n\tconst fullOutputPath = result.details?.fullOutputPath;\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\tconst styledOutput = output\n\t\t\t.split(\"\\n\")\n\t\t\t.map((line) => theme.fg(\"toolOutput\", line))\n\t\t\t.join(\"\\n\");\n\n\t\tif (options.expanded) {\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(styledOutput, BASH_PREVIEW_LINES, width);\n\t\t\t\t\t\tstate.cachedLines = preview.visualLines;\n\t\t\t\t\t\tstate.cachedSkipped = 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 = collapsedLinesHint(theme, state.cachedSkipped, \"earlier\");\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) {\n\t\tconst warnings: string[] = [];\n\t\tif (fullOutputPath) {\n\t\t\twarnings.push(`Full output: ${fullOutputPath}`);\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\nexport interface ShellToolConfig {\n\tname: string;\n\tlabel: string;\n\tshellName: string;\n\tprompt: string;\n\tpromptSnippet: string;\n\tpromptGuidelines?: readonly string[];\n\ttempFilePrefix: string;\n}\n\nexport function createShellToolDefinition(\n\tcwd: string,\n\tconfig: ShellToolConfig,\n\toptions?: BashToolOptions,\n): ToolDefinition<typeof bashSchema, BashToolDetails | undefined, BashRenderState> {\n\tconst ops = options?.operations ?? createLocalBashOperations({ shellPath: options?.shellPath });\n\tconst commandPrefix = options?.commandPrefix;\n\tconst exposeSessionEnvironment = options?.exposeSessionEnvironment ?? true;\n\tconst spawnHook = options?.spawnHook;\n\treturn {\n\t\tname: config.name,\n\t\tlabel: config.label,\n\t\tdescription: `Execute a ${config.shellName} command in the current working directory. 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 temp file. Optionally provide a timeout in seconds.`,\n\t\tpromptSnippet: config.promptSnippet,\n\t\tpromptGuidelines: exposeSessionEnvironment && config.promptGuidelines ? [...config.promptGuidelines] : undefined,\n\t\tparameters: bashSchema,\n\t\tconstrainedSampling: getExperimentalToolSampling(),\n\t\tasync execute(\n\t\t\t_toolCallId,\n\t\t\t{ command, timeout }: { command: string; timeout?: number },\n\t\t\tsignal?: AbortSignal,\n\t\t\tonUpdate?,\n\t\t\tctx?,\n\t\t) {\n\t\t\tconst resolvedCommand = commandPrefix ? `${commandPrefix}\\n${command}` : command;\n\t\t\tconst spawnContext = resolveSpawnContext(resolvedCommand, cwd, spawnHook, exposeSessionEnvironment, ctx);\n\t\t\tconst output = new OutputAccumulator({ tempFilePrefix: config.tempFilePrefix });\n\t\t\tlet acceptingOutput = true;\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.snapshot({ persistIfTruncated: true });\n\t\t\t\tonUpdate({\n\t\t\t\t\tcontent: [{ type: \"text\", text: snapshot.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},\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\tif (!acceptingOutput) return;\n\t\t\t\toutput.append(data);\n\t\t\t\tscheduleOutputUpdate();\n\t\t\t};\n\n\t\t\tconst finishOutput = async () => {\n\t\t\t\tacceptingOutput = false;\n\t\t\t\toutput.finish();\n\t\t\t\tclearUpdateTimer();\n\t\t\t\temitOutputUpdate();\n\t\t\t\tconst snapshot = output.snapshot({ persistIfTruncated: true });\n\t\t\t\tawait output.closeTempFile();\n\t\t\t\treturn snapshot;\n\t\t\t};\n\n\t\t\tconst formatOutput = (snapshot: Awaited<ReturnType<typeof finishOutput>>, emptyText = \"(no output)\") => {\n\t\t\t\tconst truncation = snapshot.truncation;\n\t\t\t\tlet text = snapshot.content || emptyText;\n\t\t\t\tlet details: BashToolDetails | undefined;\n\t\t\t\tif (truncation.truncated) {\n\t\t\t\t\tdetails = { truncation, fullOutputPath: snapshot.fullOutputPath };\n\t\t\t\t\tconst startLine = truncation.totalLines - truncation.outputLines + 1;\n\t\t\t\t\tconst endLine = truncation.totalLines;\n\t\t\t\t\tif (truncation.lastLinePartial) {\n\t\t\t\t\t\tconst lastLineSize = formatSize(output.getLastLineBytes());\n\t\t\t\t\t\ttext += `\\n\\n[Showing last ${formatSize(truncation.outputBytes)} of line ${endLine} (line is ${lastLineSize}). Full output: ${snapshot.fullOutputPath}]`;\n\t\t\t\t\t} else if (truncation.truncatedBy === \"lines\") {\n\t\t\t\t\t\ttext += `\\n\\n[Showing lines ${startLine}-${endLine} of ${truncation.totalLines}. Full output: ${snapshot.fullOutputPath}]`;\n\t\t\t\t\t} else {\n\t\t\t\t\t\ttext += `\\n\\n[Showing lines ${startLine}-${endLine} of ${truncation.totalLines} (${formatSize(DEFAULT_MAX_BYTES)} limit). Full output: ${snapshot.fullOutputPath}]`;\n\t\t\t\t\t}\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\n\t\t\ttry {\n\t\t\t\tlet exitCode: number | null;\n\t\t\t\ttry {\n\t\t\t\t\tconst result = await ops.exec(spawnContext.command, spawnContext.cwd, {\n\t\t\t\t\t\tonData: handleData,\n\t\t\t\t\t\tsignal,\n\t\t\t\t\t\ttimeout,\n\t\t\t\t\t\tenv: spawnContext.env,\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\tthrow err;\n\t\t\t\t}\n\n\t\t\t\tconst snapshot = await finishOutput();\n\t\t\t\tconst { text: outputText, details } = formatOutput(snapshot);\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}\n\t\t},\n\t\trenderCall(args, _theme, context) {\n\t\t\tconst component =\n\t\t\t\t(context.lastComponent as BashCallRenderComponent | undefined) ?? new BashCallRenderComponent(config);\n\t\t\tcomponent.update(args, context.expanded);\n\t\t\treturn component;\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\nconst bashToolConfig: ShellToolConfig = {\n\tname: \"bash\",\n\tlabel: \"bash\",\n\tshellName: \"bash\",\n\tprompt: \"$\",\n\tpromptSnippet: bashToolSystemPromptContribution.snippet,\n\tpromptGuidelines: bashToolSystemPromptContribution.guidelines,\n\ttempFilePrefix: \"pi-bash\",\n};\n\nexport function createBashToolDefinition(\n\tcwd: string,\n\toptions?: BashToolOptions,\n): ToolDefinition<typeof bashSchema, BashToolDetails | undefined, BashRenderState> {\n\treturn createShellToolDefinition(cwd, bashToolConfig, options);\n}\n\nexport function createBashTool(cwd: string, options?: BashToolOptions): AgentTool<typeof bashSchema> {\n\tconst definition = createBashToolDefinition(cwd, options);\n\tconst tool = wrapToolDefinition(definition);\n\tObject.assign(tool, {\n\t\tpromptSnippet: definition.promptSnippet,\n\t\tpromptGuidelines: definition.promptGuidelines,\n\t});\n\treturn tool;\n}\n"]}
1
+ {"version":3,"file":"bash.js","sourceRoot":"","sources":["../../../src/core/tools/bash.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AACpC,OAAO,EAAE,MAAM,IAAI,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAEtD,OAAO,EAAkB,SAAS,EAAE,IAAI,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AACxG,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AACtC,OAAO,EAAe,IAAI,EAAE,MAAM,SAAS,CAAC;AAC5C,OAAO,EAAE,qBAAqB,EAAE,MAAM,uDAAuD,CAAC;AAC9F,OAAO,EAAE,aAAa,EAAE,KAAK,EAAE,MAAM,wCAAwC,CAAC;AAC9E,OAAO,EAAE,mBAAmB,EAAE,MAAM,8BAA8B,CAAC;AACnE,OAAO,EACN,cAAc,EACd,WAAW,EACX,eAAe,EACf,sBAAsB,EAEtB,qBAAqB,EACrB,uBAAuB,GACvB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,2BAA2B,EAAE,MAAM,oBAAoB,CAAC;AAEjE,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAC5D,OAAO,EAAE,kBAAkB,EAAE,aAAa,EAAE,cAAc,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAC;AAC3F,OAAO,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAC;AAClE,OAAO,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,UAAU,EAAyB,MAAM,eAAe,CAAC;AAExG,MAAM,cAAc,GAAG,aAAa,CAAC;AACrC,MAAM,CAAC,MAAM,mBAAmB,GAAG,cAAc,GAAG,IAAI,CAAC;AAEzD;;;GAGG;AACH,MAAM,UAAU,gBAAgB,CAAC,OAA2B;IAC3D,IAAI,OAAO,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,UAAU,CAAC,CAAC;IAC5C,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE;QACnB,aAAa,EAAE,UAAU,CAAC,aAAa;QACvC,gBAAgB,EAAE,UAAU,CAAC,gBAAgB;KAC7C,CAAC,CAAC;IACH,OAAO,IAAI,CAAC;AACb,CAAC","sourcesContent":["import { constants } from \"node:fs\";\nimport { access as fsAccess } from \"node:fs/promises\";\nimport type { AgentTool } from \"@earendil-works/pi-agent-core\";\nimport { type Component, Container, Text, truncateToWidth, visibleWidth } from \"@earendil-works/pi-tui\";\nimport { spawn } from \"child_process\";\nimport { type Static, Type } from \"typebox\";\nimport { truncateToVisualLines } from \"../../modes/interactive/components/visual-truncate.ts\";\nimport { highlightCode, theme } from \"../../modes/interactive/theme/theme.ts\";\nimport { waitForChildProcess } from \"../../utils/child-process.ts\";\nimport {\n\tgetShellConfig,\n\tgetShellEnv,\n\tkillProcessTree,\n\trewriteCmdNulRedirects,\n\ttype ShellConfig,\n\ttrackDetachedChildPid,\n\tuntrackDetachedChildPid,\n} from \"../../utils/shell.ts\";\nimport { getExperimentalToolSampling } from \"../experimental.ts\";\nimport type { ExtensionContext, ToolDefinition, ToolRenderResultOptions } from \"../extensions/types.ts\";\nimport { OutputAccumulator } from \"./output-accumulator.ts\";\nimport { collapsedLinesHint, getTextOutput, invalidArgText, str } from \"./render-utils.ts\";\nimport { wrapToolDefinition } from \"./tool-definition-wrapper.ts\";\nimport { DEFAULT_MAX_BYTES, DEFAULT_MAX_LINES, formatSize, type TruncationResult } from \"./truncate.ts\";\n\nconst MAX_TIMEOUT_MS = 2_147_483_647;\nexport const MAX_TIMEOUT_SECONDS = MAX_TIMEOUT_MS / 1000;\n\n/**\n * The one timeout rule, shared by this tool and the background extension so a\n * rejected timeout reads the same wherever it is caught.\n */\nexport function resolveTimeoutMs(timeout: number | undefined): number | undefined {\n\tif (timeout === undefined) return undefined;\n\tif (!Number.isFinite(timeout) || timeout <= 0) {\n\t\tthrow new Error(\"Invalid timeout: must be a finite number of seconds\");\n\t}\n\n\tconst timeoutMs = timeout * 1000;\n\tif (timeoutMs > MAX_TIMEOUT_MS) {\n\t\tthrow new Error(`Invalid timeout: maximum is ${MAX_TIMEOUT_SECONDS} seconds`);\n\t}\n\treturn timeoutMs;\n}\n\nconst bashSchema = Type.Object({\n\tcommand: Type.String({ description: \"Shell command to execute\" }),\n\ttimeout: Type.Optional(Type.Number({ description: \"Timeout in seconds (optional, no default timeout)\" })),\n});\n\nexport const bashToolSystemPromptContribution = {\n\tsnippet: \"Execute bash commands (ls, grep, find, etc.)\",\n\tguidelines: [\"You can inspect PI_* environment variables for current model and session details.\"],\n} as const;\n\nexport type BashToolInput = Static<typeof bashSchema>;\n\nexport interface BashToolDetails {\n\ttruncation?: TruncationResult;\n\tfullOutputPath?: string;\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\t * Error contract: reject with `new Error(\"aborted\")` when aborted via `signal`,\n\t * and `new Error(\"timeout:<seconds>\")` on timeout expiry — callers (including\n\t * the background extension) classify outcomes from these exact markers.\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\n/** Shared process execution used by the built-in shell tools. */\nexport function createLocalShellOperations(\n\tshellName: string,\n\tresolveShellConfig: () => ShellConfig,\n\tnormalizeCommand: (command: string) => string = (command) => command,\n): BashOperations {\n\treturn {\n\t\texec: async (command, cwd, { onData, signal, timeout, env }) => {\n\t\t\tconst timeoutMs = resolveTimeoutMs(timeout);\n\t\t\tif (signal?.aborted) {\n\t\t\t\tthrow new Error(\"aborted\");\n\t\t\t}\n\t\t\tconst shellConfig = resolveShellConfig();\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\n\t\t\tconst commandFromStdin = shellConfig.commandTransport === \"stdin\";\n\t\t\tconst normalizedCommand = normalizeCommand(command);\n\t\t\tconst child = spawn(\n\t\t\t\tshellConfig.shell,\n\t\t\t\tcommandFromStdin ? shellConfig.args : [...shellConfig.args, normalizedCommand],\n\t\t\t\t{\n\t\t\t\t\tcwd,\n\t\t\t\t\tdetached: process.platform !== \"win32\",\n\t\t\t\t\tenv: env ?? getShellEnv(),\n\t\t\t\t\tstdio: [commandFromStdin ? \"pipe\" : \"ignore\", \"pipe\", \"pipe\"],\n\t\t\t\t\twindowsHide: true,\n\t\t\t\t},\n\t\t\t);\n\t\t\tif (commandFromStdin) {\n\t\t\t\tchild.stdin?.on(\"error\", () => {});\n\t\t\t\tchild.stdin?.end(normalizedCommand);\n\t\t\t}\n\t\t\tif (child.pid) trackDetachedChildPid(child.pid);\n\t\t\tlet timedOut = false;\n\t\t\tlet timeoutHandle: NodeJS.Timeout | undefined;\n\t\t\tconst onAbort = () => {\n\t\t\t\tif (child.pid) killProcessTree(child.pid);\n\t\t\t};\n\n\t\t\ttry {\n\t\t\t\t// Set timeout if provided.\n\t\t\t\tif (timeoutMs !== undefined) {\n\t\t\t\t\ttimeoutHandle = setTimeout(() => {\n\t\t\t\t\t\ttimedOut = true;\n\t\t\t\t\t\tif (child.pid) killProcessTree(child.pid);\n\t\t\t\t\t}, timeoutMs);\n\t\t\t\t}\n\t\t\t\t// Stream stdout and stderr.\n\t\t\t\tchild.stdout?.on(\"data\", onData);\n\t\t\t\tchild.stderr?.on(\"data\", onData);\n\t\t\t\t// Handle abort signal by killing the entire process tree.\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\t// Handle shell spawn errors and wait for the process to terminate without hanging\n\t\t\t\t// on inherited stdio handles held by detached descendants.\n\t\t\t\tconst exitCode = await waitForChildProcess(child);\n\t\t\t\tif (signal?.aborted) {\n\t\t\t\t\tthrow new Error(\"aborted\");\n\t\t\t\t}\n\t\t\t\tif (timedOut) {\n\t\t\t\t\tthrow new Error(`timeout:${timeout}`);\n\t\t\t\t}\n\t\t\t\treturn { exitCode };\n\t\t\t} finally {\n\t\t\t\tif (child.pid) untrackDetachedChildPid(child.pid);\n\t\t\t\tif (timeoutHandle) clearTimeout(timeoutHandle);\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 }): BashOperations {\n\treturn createLocalShellOperations(\"bash\", () => getShellConfig(options?.shellPath), rewriteCmdNulRedirects);\n}\n\nexport interface BashSpawnContext {\n\tcommand: string;\n\tcwd: string;\n\tenv: NodeJS.ProcessEnv;\n}\n\nexport type BashSpawnHook = (context: BashSpawnContext) => BashSpawnContext;\n\nexport function resolveSpawnContext(\n\tcommand: string,\n\tcwd: string,\n\tspawnHook: BashSpawnHook | undefined,\n\texposeSessionEnvironment: boolean,\n\tctx: ExtensionContext | undefined,\n): BashSpawnContext {\n\tconst env = { ...getShellEnv() };\n\tdelete env.PI_SESSION_ID;\n\tdelete env.PI_SESSION_FILE;\n\tdelete env.PI_PROVIDER;\n\tdelete env.PI_MODEL;\n\tdelete env.PI_REASONING_LEVEL;\n\tif (exposeSessionEnvironment && ctx) {\n\t\tconst model = ctx.model;\n\t\tenv.PI_SESSION_ID = ctx.sessionManager.getSessionId();\n\t\tconst sessionFile = ctx.sessionManager.getSessionFile();\n\t\tif (sessionFile) env.PI_SESSION_FILE = sessionFile;\n\t\tif (model) {\n\t\t\tenv.PI_PROVIDER = model.provider;\n\t\t\tenv.PI_MODEL = model.id;\n\t\t}\n\t\tif (ctx.thinkingLevel) env.PI_REASONING_LEVEL = ctx.thinkingLevel;\n\t}\n\tconst baseContext: BashSpawnContext = { command, cwd, env };\n\treturn spawnHook ? spawnHook(baseContext) : baseContext;\n}\n\nexport interface BashToolOptions {\n\t/** Custom operations for command execution. Default: local 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/** Expose current Pi session metadata as PI_* environment variables. Default: true */\n\texposeSessionEnvironment?: boolean;\n\t/** Hook to adjust command, cwd, or env before execution */\n\tspawnHook?: BashSpawnHook;\n}\n\nconst BASH_PREVIEW_LINES = 5;\nconst BASH_UPDATE_THROTTLE_MS = 100;\n\nexport type BashRenderState = {\n\tstartedAt: number | undefined;\n\tendedAt: number | undefined;\n\tinterval: NodeJS.Timeout | undefined;\n};\n\ntype BashCachedRenderState = {\n\tcachedWidth: number | undefined;\n\tcachedLines: string[] | undefined;\n\tcachedSkipped: number | undefined;\n};\n\nclass BashCallRenderComponent implements Component {\n\tprivate command: string | null = \"\";\n\tprivate timeout: number | undefined;\n\tprivate expanded = false;\n\tprivate cachedWidth: number | undefined;\n\tprivate cachedLines: string[] | undefined;\n\tprivate readonly config: ShellToolConfig;\n\n\tconstructor(config: ShellToolConfig) {\n\t\tthis.config = config;\n\t}\n\n\tupdate(args: { command?: string; timeout?: number } | undefined, expanded: boolean): void {\n\t\tconst command = str(args?.command);\n\t\tconst timeout = args?.timeout as number | undefined;\n\t\tif (this.command === command && this.timeout === timeout && this.expanded === expanded) {\n\t\t\treturn;\n\t\t}\n\n\t\tthis.command = command;\n\t\tthis.timeout = timeout;\n\t\tthis.expanded = expanded;\n\t\tthis.invalidate();\n\t}\n\n\trender(width: number): string[] {\n\t\tif (this.cachedLines === undefined || this.cachedWidth !== width) {\n\t\t\tthis.cachedLines = this.renderLines(Math.max(1, width));\n\t\t\tthis.cachedWidth = width;\n\t\t}\n\t\treturn this.cachedLines;\n\t}\n\n\tinvalidate(): void {\n\t\tthis.cachedWidth = undefined;\n\t\tthis.cachedLines = undefined;\n\t}\n\n\tprivate renderLines(width: number): string[] {\n\t\tconst fullCall = formatFullShellCall(this.command, this.timeout, this.config);\n\t\tconst fullLines = new Text(fullCall, 0, 0).render(width);\n\t\tif (this.expanded || fullLines.length <= 1) return fullLines;\n\t\treturn [formatTruncatedShellCall(this.command, this.timeout, width, this.config)];\n\t}\n}\n\nclass BashResultRenderComponent extends Container {\n\tstate: BashCachedRenderState = {\n\t\tcachedWidth: undefined,\n\t\tcachedLines: undefined,\n\t\tcachedSkipped: undefined,\n\t};\n}\n\nfunction formatShellPrompt(prompt: string): string {\n\treturn theme.fg(\"toolTitle\", theme.bold(`${prompt} `));\n}\n\nfunction formatShellTimeout(timeout: number | undefined): string {\n\treturn timeout ? theme.fg(\"muted\", ` (timeout ${timeout}s)`) : \"\";\n}\n\nfunction styleShellCommand(command: string, config: ShellToolConfig): string {\n\tconst language = config.name === \"powershell\" ? \"powershell\" : \"bash\";\n\treturn highlightCode(command, language).join(\"\\n\");\n}\n\nfunction formatFullShellCall(command: string | null, timeout: number | undefined, config: ShellToolConfig): string {\n\tconst commandDisplay =\n\t\tcommand === null\n\t\t\t? invalidArgText(theme)\n\t\t\t: command\n\t\t\t\t? styleShellCommand(command, config)\n\t\t\t\t: theme.fg(\"toolOutput\", \"...\");\n\treturn formatShellPrompt(config.prompt) + commandDisplay + formatShellTimeout(timeout);\n}\n\nfunction fitCollapsedShellCall(\n\tbody: string,\n\ttimeout: number | undefined,\n\twidth: number,\n\tsuffix: string,\n\tconfig: ShellToolConfig,\n): string {\n\tconst prompt = formatShellPrompt(config.prompt);\n\tconst timeoutSuffix = formatShellTimeout(timeout);\n\tconst bodyWidth = Math.max(0, width - visibleWidth(prompt) - visibleWidth(suffix) - visibleWidth(timeoutSuffix));\n\tconst fittedBody = truncateToWidth(body, bodyWidth, \"\");\n\treturn truncateToWidth(prompt + fittedBody + suffix + timeoutSuffix, width, \"…\");\n}\n\nfunction formatTruncatedShellCall(\n\tcommand: string | null,\n\ttimeout: number | undefined,\n\twidth: number,\n\tconfig: ShellToolConfig,\n): string {\n\tif (command === null) return truncateToWidth(formatFullShellCall(command, timeout, config), width, \"…\");\n\tif (!command) return formatFullShellCall(command, timeout, config);\n\tconst physicalLines = command.split(/\\r?\\n/).filter((line) => line.trim());\n\tconst firstNonEmptyLine = physicalLines[0]?.trim() ?? command.trim();\n\tconst hiddenLines = Math.max(0, physicalLines.length - 1);\n\tconst suffix =\n\t\thiddenLines > 0\n\t\t\t? theme.fg(\"muted\", ` (+${hiddenLines} line${hiddenLines === 1 ? \"\" : \"s\"})`)\n\t\t\t: theme.fg(\"muted\", \" …\");\n\treturn fitCollapsedShellCall(styleShellCommand(firstNonEmptyLine, config), timeout, width, suffix, config);\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\tlet output = getTextOutput(result as any, showImages).trim();\n\tconst truncation = result.details?.truncation;\n\tconst fullOutputPath = result.details?.fullOutputPath;\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\tconst styledOutput = output\n\t\t\t.split(\"\\n\")\n\t\t\t.map((line) => theme.fg(\"toolOutput\", line))\n\t\t\t.join(\"\\n\");\n\n\t\tif (options.expanded) {\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(styledOutput, BASH_PREVIEW_LINES, width);\n\t\t\t\t\t\tstate.cachedLines = preview.visualLines;\n\t\t\t\t\t\tstate.cachedSkipped = 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 = collapsedLinesHint(theme, state.cachedSkipped, \"earlier\");\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) {\n\t\tconst warnings: string[] = [];\n\t\tif (fullOutputPath) {\n\t\t\twarnings.push(`Full output: ${fullOutputPath}`);\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\nexport interface ShellToolConfig {\n\tname: string;\n\tlabel: string;\n\tshellName: string;\n\tprompt: string;\n\tpromptSnippet: string;\n\tpromptGuidelines?: readonly string[];\n\ttempFilePrefix: string;\n}\n\nexport function createShellToolDefinition(\n\tcwd: string,\n\tconfig: ShellToolConfig,\n\toptions?: BashToolOptions,\n): ToolDefinition<typeof bashSchema, BashToolDetails | undefined, BashRenderState> {\n\tconst ops = options?.operations ?? createLocalBashOperations({ shellPath: options?.shellPath });\n\tconst commandPrefix = options?.commandPrefix;\n\tconst exposeSessionEnvironment = options?.exposeSessionEnvironment ?? true;\n\tconst spawnHook = options?.spawnHook;\n\treturn {\n\t\tname: config.name,\n\t\tlabel: config.label,\n\t\tdescription: `Execute a ${config.shellName} command in the current working directory. 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 temp file. Optionally provide a timeout in seconds.`,\n\t\tpromptSnippet: config.promptSnippet,\n\t\tpromptGuidelines: exposeSessionEnvironment && config.promptGuidelines ? [...config.promptGuidelines] : undefined,\n\t\tparameters: bashSchema,\n\t\tconstrainedSampling: getExperimentalToolSampling(),\n\t\tasync execute(\n\t\t\t_toolCallId,\n\t\t\t{ command, timeout }: { command: string; timeout?: number },\n\t\t\tsignal?: AbortSignal,\n\t\t\tonUpdate?,\n\t\t\tctx?,\n\t\t) {\n\t\t\tconst resolvedCommand = commandPrefix ? `${commandPrefix}\\n${command}` : command;\n\t\t\tconst spawnContext = resolveSpawnContext(resolvedCommand, cwd, spawnHook, exposeSessionEnvironment, ctx);\n\t\t\tconst output = new OutputAccumulator({ tempFilePrefix: config.tempFilePrefix });\n\t\t\tlet acceptingOutput = true;\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.snapshot({ persistIfTruncated: true });\n\t\t\t\tonUpdate({\n\t\t\t\t\tcontent: [{ type: \"text\", text: snapshot.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},\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\tif (!acceptingOutput) return;\n\t\t\t\toutput.append(data);\n\t\t\t\tscheduleOutputUpdate();\n\t\t\t};\n\n\t\t\tconst finishOutput = async () => {\n\t\t\t\tacceptingOutput = false;\n\t\t\t\toutput.finish();\n\t\t\t\tclearUpdateTimer();\n\t\t\t\temitOutputUpdate();\n\t\t\t\tconst snapshot = output.snapshot({ persistIfTruncated: true });\n\t\t\t\tawait output.closeTempFile();\n\t\t\t\treturn snapshot;\n\t\t\t};\n\n\t\t\tconst formatOutput = (snapshot: Awaited<ReturnType<typeof finishOutput>>, emptyText = \"(no output)\") => {\n\t\t\t\tconst truncation = snapshot.truncation;\n\t\t\t\tlet text = snapshot.content || emptyText;\n\t\t\t\tlet details: BashToolDetails | undefined;\n\t\t\t\tif (truncation.truncated) {\n\t\t\t\t\tdetails = { truncation, fullOutputPath: snapshot.fullOutputPath };\n\t\t\t\t\tconst startLine = truncation.totalLines - truncation.outputLines + 1;\n\t\t\t\t\tconst endLine = truncation.totalLines;\n\t\t\t\t\tif (truncation.lastLinePartial) {\n\t\t\t\t\t\tconst lastLineSize = formatSize(output.getLastLineBytes());\n\t\t\t\t\t\ttext += `\\n\\n[Showing last ${formatSize(truncation.outputBytes)} of line ${endLine} (line is ${lastLineSize}). Full output: ${snapshot.fullOutputPath}]`;\n\t\t\t\t\t} else if (truncation.truncatedBy === \"lines\") {\n\t\t\t\t\t\ttext += `\\n\\n[Showing lines ${startLine}-${endLine} of ${truncation.totalLines}. Full output: ${snapshot.fullOutputPath}]`;\n\t\t\t\t\t} else {\n\t\t\t\t\t\ttext += `\\n\\n[Showing lines ${startLine}-${endLine} of ${truncation.totalLines} (${formatSize(DEFAULT_MAX_BYTES)} limit). Full output: ${snapshot.fullOutputPath}]`;\n\t\t\t\t\t}\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\n\t\t\ttry {\n\t\t\t\tlet exitCode: number | null;\n\t\t\t\ttry {\n\t\t\t\t\tconst result = await ops.exec(spawnContext.command, spawnContext.cwd, {\n\t\t\t\t\t\tonData: handleData,\n\t\t\t\t\t\tsignal,\n\t\t\t\t\t\ttimeout,\n\t\t\t\t\t\tenv: spawnContext.env,\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\tthrow err;\n\t\t\t\t}\n\n\t\t\t\tconst snapshot = await finishOutput();\n\t\t\t\tconst { text: outputText, details } = formatOutput(snapshot);\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}\n\t\t},\n\t\trenderCall(args, _theme, context) {\n\t\t\tconst component =\n\t\t\t\t(context.lastComponent as BashCallRenderComponent | undefined) ?? new BashCallRenderComponent(config);\n\t\t\tcomponent.update(args, context.expanded);\n\t\t\treturn component;\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\nconst bashToolConfig: ShellToolConfig = {\n\tname: \"bash\",\n\tlabel: \"bash\",\n\tshellName: \"bash\",\n\tprompt: \"$\",\n\tpromptSnippet: bashToolSystemPromptContribution.snippet,\n\tpromptGuidelines: bashToolSystemPromptContribution.guidelines,\n\ttempFilePrefix: \"pi-bash\",\n};\n\nexport function createBashToolDefinition(\n\tcwd: string,\n\toptions?: BashToolOptions,\n): ToolDefinition<typeof bashSchema, BashToolDetails | undefined, BashRenderState> {\n\treturn createShellToolDefinition(cwd, bashToolConfig, options);\n}\n\nexport function createBashTool(cwd: string, options?: BashToolOptions): AgentTool<typeof bashSchema> {\n\tconst definition = createBashToolDefinition(cwd, options);\n\tconst tool = wrapToolDefinition(definition);\n\tObject.assign(tool, {\n\t\tpromptSnippet: definition.promptSnippet,\n\t\tpromptGuidelines: definition.promptGuidelines,\n\t});\n\treturn tool;\n}\n"]}
@@ -0,0 +1,21 @@
1
+ /**
2
+ * background — the five `bg` actions.
3
+ *
4
+ * Free functions over the registry rather than closures over the extension's
5
+ * session state: each action can be read, moved, and tested on its own, and
6
+ * the required fields are narrowed at the top of each one (schema.ts) instead
7
+ * of being asserted with a cast. Every model-facing tool-result string this
8
+ * extension produces is built here.
9
+ */
10
+ import type { AgentToolResult, ExtensionContext } from "../../core/extensions/types.ts";
11
+ import type { BackgroundTaskRegistry, BgTask } from "./registry.ts";
12
+ import { type BgInput } from "./schema.ts";
13
+ import type { BgCreateDetails, BgKillDetails, BgListDetails, BgReadDetails, BgWaitDetails } from "./types.ts";
14
+ /** One row of a bounded task listing: the model-facing list and the /bg fallback summary. */
15
+ export declare function describeTaskLine(task: BgTask, now: number): string;
16
+ export declare function runCreate(registry: BackgroundTaskRegistry, input: BgInput, ctx: ExtensionContext): AgentToolResult<BgCreateDetails>;
17
+ export declare function runRead(registry: BackgroundTaskRegistry, input: BgInput): Promise<AgentToolResult<BgReadDetails>>;
18
+ export declare function runWait(registry: BackgroundTaskRegistry, input: BgInput, signal?: AbortSignal): Promise<AgentToolResult<BgWaitDetails>>;
19
+ export declare function runKill(registry: BackgroundTaskRegistry, input: BgInput): AgentToolResult<BgKillDetails>;
20
+ export declare function runList(registry: BackgroundTaskRegistry): AgentToolResult<BgListDetails>;
21
+ //# sourceMappingURL=actions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"actions.d.ts","sourceRoot":"","sources":["../../../src/extensions/background/actions.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,gCAAgC,CAAC;AAMxF,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,EAAqB,MAAM,eAAe,CAAC;AACvF,OAAO,EACN,KAAK,OAAO,EAOZ,MAAM,aAAa,CAAC;AAGrB,OAAO,KAAK,EAAE,eAAe,EAAE,aAAa,EAAE,aAAa,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAsB9G,6FAA6F;AAC7F,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,CAGlE;AAID,wBAAgB,SAAS,CACxB,QAAQ,EAAE,sBAAsB,EAChC,KAAK,EAAE,OAAO,EACd,GAAG,EAAE,gBAAgB,GACnB,eAAe,CAAC,eAAe,CAAC,CAiClC;AAID,wBAAsB,OAAO,CAC5B,QAAQ,EAAE,sBAAsB,EAChC,KAAK,EAAE,OAAO,GACZ,OAAO,CAAC,eAAe,CAAC,aAAa,CAAC,CAAC,CAuCzC;AA+BD,wBAAsB,OAAO,CAC5B,QAAQ,EAAE,sBAAsB,EAChC,KAAK,EAAE,OAAO,EACd,MAAM,CAAC,EAAE,WAAW,GAClB,OAAO,CAAC,eAAe,CAAC,aAAa,CAAC,CAAC,CAQzC;AAsFD,wBAAgB,OAAO,CAAC,QAAQ,EAAE,sBAAsB,EAAE,KAAK,EAAE,OAAO,GAAG,eAAe,CAAC,aAAa,CAAC,CAcxG;AAID,wBAAgB,OAAO,CAAC,QAAQ,EAAE,sBAAsB,GAAG,eAAe,CAAC,aAAa,CAAC,CA8BxF"}
@@ -0,0 +1,264 @@
1
+ /**
2
+ * background — the five `bg` actions.
3
+ *
4
+ * Free functions over the registry rather than closures over the extension's
5
+ * session state: each action can be read, moved, and tested on its own, and
6
+ * the required fields are narrowed at the top of each one (schema.ts) instead
7
+ * of being asserted with a cast. Every model-facing tool-result string this
8
+ * extension produces is built here.
9
+ */
10
+ import { resolveSpawnContext } from "../../core/tools/bash.js";
11
+ import { formatSize } from "../../core/tools/truncate.js";
12
+ import { sanitizeBinaryOutput } from "../../utils/shell.js";
13
+ import { BG_LIST_FINISHED_SHOWN, BG_WAIT_DELTA_BYTES, BG_WAIT_PEEK_BYTES } from "./constants.js";
14
+ import { readOutputSince, readOutputSlice, readTail } from "./output-file.js";
15
+ import { clampReadBytes, clampSinceBytes, clampWaitMs, parseTimeoutSeconds, requireCommand, requireTaskId, } from "./schema.js";
16
+ import { exitSuffix, hasExitCode, runtimeLabel, taskLabelWithin } from "./task-view.js";
17
+ import { formatDuration, noticeLine } from "./text.js";
18
+ /** Width budget for a task label inside a listing row. */
19
+ const LIST_LABEL_WIDTH = 60;
20
+ function describeResolveFailure(input, result) {
21
+ if (result.reason === "ambiguous") {
22
+ const lines = result.candidates.map((task) => ` ${task.id} (${task.status}) ${taskLabelWithin(task, LIST_LABEL_WIDTH)}`);
23
+ return `Task id "${input}" is ambiguous. Candidates:\n${lines.join("\n")}`;
24
+ }
25
+ return `No background task matches "${input}". Check the id returned by bg (action create), or run action list.`;
26
+ }
27
+ /** Resolve a task by id or unique prefix, or throw a message naming the next step. */
28
+ function resolveTask(registry, taskId) {
29
+ const resolved = registry.resolveTask(taskId);
30
+ if (!resolved.ok)
31
+ throw new Error(describeResolveFailure(taskId, resolved));
32
+ return resolved.task;
33
+ }
34
+ /** One row of a bounded task listing: the model-facing list and the /bg fallback summary. */
35
+ export function describeTaskLine(task, now) {
36
+ const label = taskLabelWithin(task, LIST_LABEL_WIDTH);
37
+ return ` ${task.id} ${task.status}${exitSuffix(task.exitCode, " ")} ${runtimeLabel(task, now)} ${label}`;
38
+ }
39
+ // ── create ────────────────────────────────────────────────────────────────
40
+ export function runCreate(registry, input, ctx) {
41
+ const command = requireCommand(input);
42
+ const timeoutSeconds = parseTimeoutSeconds(input.timeout);
43
+ // Same PI_* session variables as the built-in bash tool, snapshotted at start.
44
+ const spawnContext = resolveSpawnContext(command, ctx.cwd, undefined, true, ctx);
45
+ // Deliberately ignore the turn signal: aborting the current turn must not
46
+ // kill the background task (that is what action kill is for).
47
+ const task = registry.startTask({
48
+ command,
49
+ cwd: ctx.cwd,
50
+ description: input.description,
51
+ timeoutSeconds,
52
+ env: spawnContext.env,
53
+ });
54
+ const label = task.description ? ` (${task.description})` : "";
55
+ const text = [
56
+ `Started background task ${task.id}${label}.`,
57
+ `Output file: ${task.outputPath}`,
58
+ "",
59
+ "A <background-task> notification with the result and output tail arrives automatically when the task " +
60
+ "ends — do NOT poll (no sleep loops, no repeated reads). Use action read for an early peek, " +
61
+ "action wait when the next step depends on the result, action kill to stop it.",
62
+ ].join("\n");
63
+ return {
64
+ content: [{ type: "text", text }],
65
+ details: {
66
+ action: "create",
67
+ taskId: task.id,
68
+ outputPath: task.outputPath,
69
+ command,
70
+ description: input.description,
71
+ },
72
+ };
73
+ }
74
+ // ── read ──────────────────────────────────────────────────────────────────
75
+ export async function runRead(registry, input) {
76
+ const task = resolveTask(registry, requireTaskId(input));
77
+ const mode = input.mode ?? "tail";
78
+ let slice;
79
+ try {
80
+ slice = await readOutputSlice(task.outputPath, { mode, maxBytes: clampReadBytes(input.bytes) });
81
+ }
82
+ catch (error) {
83
+ const message = error instanceof Error ? error.message : String(error);
84
+ throw new Error(`Could not read output for ${task.id} (${task.status}): ${message}\nOutput file: ${task.outputPath}`);
85
+ }
86
+ const running = task.status === "running" && "still running";
87
+ const notice = slice.truncated
88
+ ? noticeLine([
89
+ `${mode} ${formatSize(slice.sliceBytes)} of ${formatSize(slice.totalBytes)}`,
90
+ `task ${task.id} ${task.status}`,
91
+ running,
92
+ slice.startsMidLine && "first line may be partial",
93
+ `full output: ${task.outputPath}`,
94
+ ])
95
+ : noticeLine([
96
+ `task ${task.id} ${task.status}`,
97
+ running,
98
+ `${formatSize(slice.totalBytes)} total`,
99
+ `output: ${task.outputPath}`,
100
+ ]);
101
+ const text = sanitizeBinaryOutput(slice.text);
102
+ return {
103
+ content: [{ type: "text", text: `${notice}\n${text.length > 0 ? text : "(no output yet)"}` }],
104
+ details: {
105
+ action: "read",
106
+ taskId: task.id,
107
+ mode,
108
+ sliceBytes: slice.sliceBytes,
109
+ totalBytes: slice.totalBytes,
110
+ outputPath: task.outputPath,
111
+ },
112
+ };
113
+ }
114
+ // ── wait ──────────────────────────────────────────────────────────────────
115
+ /** The six fields every wait result shares; only the output accounting differs. */
116
+ function waitDetails(task, waitedMs, output) {
117
+ return {
118
+ action: "wait",
119
+ taskId: task.id,
120
+ status: task.status,
121
+ exitCode: task.exitCode,
122
+ outputPath: task.outputPath,
123
+ waitedMs,
124
+ ...output,
125
+ };
126
+ }
127
+ /** Header shared by a settled wait and by a settled wait whose output could not be read. */
128
+ function settledHeaderParts(task, waitedMs) {
129
+ return [
130
+ `${task.id} ${task.status}`,
131
+ hasExitCode(task.exitCode) && `exit ${task.exitCode}`,
132
+ `ran ${runtimeLabel(task)}`,
133
+ `waited ${formatDuration(waitedMs)}`,
134
+ ];
135
+ }
136
+ export async function runWait(registry, input, signal) {
137
+ const task = resolveTask(registry, requireTaskId(input));
138
+ const startedWait = Date.now();
139
+ const result = await registry.waitForResult(task.id, clampWaitMs(input.waitMs), signal);
140
+ const waitedMs = Date.now() - startedWait;
141
+ return result.outcome === "timeout"
142
+ ? waitTimedOut(result.task, waitedMs)
143
+ : waitSettled(result.task, waitedMs, clampSinceBytes(input.sinceBytes));
144
+ }
145
+ /** Window expired, task still running: keep progress visible with a bounded tail peek. */
146
+ async function waitTimedOut(task, waitedMs) {
147
+ const peek = await readTail(task.outputPath, BG_WAIT_PEEK_BYTES);
148
+ const totalBytes = peek.slice?.totalBytes ?? task.outputBytes;
149
+ const lines = [
150
+ noticeLine([`${task.id} still running`, `waited ${formatDuration(waitedMs)}`, `${formatSize(totalBytes)} total`]),
151
+ ];
152
+ const trimmed = sanitizeBinaryOutput(peek.slice?.text ?? "").trimEnd();
153
+ if (trimmed.length > 0) {
154
+ const note = peek.slice?.truncated ? ` (last ${formatSize(peek.slice.sliceBytes)})` : "";
155
+ lines.push(`Last output${note}:\n${trimmed}`);
156
+ }
157
+ lines.push("The task keeps running. Wait again (action wait), peek with action read, or stop it with action kill; " +
158
+ "the <background-task> notification still arrives when it ends. Do not sleep-poll.");
159
+ return {
160
+ content: [{ type: "text", text: lines.join("\n\n") }],
161
+ details: waitDetails(task, waitedMs, { timedOut: true, deltaBytes: 0, totalBytes, deltaTruncated: false }),
162
+ };
163
+ }
164
+ /**
165
+ * Terminal: deliver the bounded delta since the requested offset. The followUp
166
+ * notification was suppressed by the claim protocol — this result is the single
167
+ * delivery of the completion, so it is produced even when the file is unreadable.
168
+ */
169
+ async function waitSettled(task, waitedMs, sinceBytes) {
170
+ let delta;
171
+ try {
172
+ delta = await readOutputSince(task.outputPath, sinceBytes ?? 0, BG_WAIT_DELTA_BYTES);
173
+ }
174
+ catch (error) {
175
+ const message = error instanceof Error ? error.message : String(error);
176
+ const notice = noticeLine(settledHeaderParts(task, waitedMs));
177
+ return {
178
+ content: [{ type: "text", text: `${notice}\nerror reading output: ${message}` }],
179
+ details: waitDetails(task, waitedMs, {
180
+ timedOut: false,
181
+ deltaBytes: 0,
182
+ totalBytes: task.outputBytes,
183
+ deltaTruncated: false,
184
+ }),
185
+ };
186
+ }
187
+ const lines = [
188
+ noticeLine([
189
+ ...settledHeaderParts(task, waitedMs),
190
+ `+${formatSize(delta.sliceBytes)} new output`,
191
+ `total ${formatSize(delta.totalBytes)}`,
192
+ ]),
193
+ ];
194
+ if (delta.offsetPastEof) {
195
+ lines.push(task.outputTruncated
196
+ ? "[the given offset is past EOF — output was truncated at the limit; showing the tail]"
197
+ : "[the given offset is past EOF; showing the tail]");
198
+ }
199
+ if (task.error)
200
+ lines.push(`error: ${task.error}`);
201
+ if (delta.truncated) {
202
+ lines.push(`[showing ${formatSize(delta.sliceBytes)} of ${formatSize(delta.totalBytes)}; full output: ${task.outputPath}]`);
203
+ }
204
+ const body = sanitizeBinaryOutput(delta.text).trimEnd();
205
+ lines.push(body.length > 0 ? body : "(no new output)");
206
+ return {
207
+ content: [{ type: "text", text: lines.join("\n") }],
208
+ details: waitDetails(task, waitedMs, {
209
+ timedOut: false,
210
+ deltaBytes: delta.sliceBytes,
211
+ totalBytes: delta.totalBytes,
212
+ deltaTruncated: delta.truncated,
213
+ }),
214
+ };
215
+ }
216
+ // ── kill ──────────────────────────────────────────────────────────────────
217
+ export function runKill(registry, input) {
218
+ const task = resolveTask(registry, requireTaskId(input));
219
+ if (!registry.killTask(task.id).killed) {
220
+ throw new Error(`Task ${task.id} is not running (status: ${task.status}${exitSuffix(task.exitCode, ", ")}).`);
221
+ }
222
+ return {
223
+ content: [
224
+ {
225
+ type: "text",
226
+ text: `Killed task ${task.id}. If you are waiting on it (action wait) the killed status is delivered there; otherwise a completion notification follows once the process tree is reaped.`,
227
+ },
228
+ ],
229
+ details: { action: "kill", taskId: task.id, command: task.command },
230
+ };
231
+ }
232
+ // ── list ──────────────────────────────────────────────────────────────────
233
+ export function runList(registry) {
234
+ const tasks = registry.listTasks();
235
+ if (tasks.length === 0) {
236
+ return {
237
+ content: [{ type: "text", text: "No background tasks this session. Start one with action create." }],
238
+ details: { action: "list", running: 0, finished: 0, shown: 0, hidden: 0 },
239
+ };
240
+ }
241
+ const now = Date.now();
242
+ const running = tasks.filter((task) => task.status === "running");
243
+ const finished = tasks.filter((task) => task.status !== "running");
244
+ const shownFinished = finished.slice(0, BG_LIST_FINISHED_SHOWN);
245
+ const hidden = finished.length - shownFinished.length;
246
+ const lines = [`${running.length} running · ${finished.length} finished`];
247
+ for (const task of [...running, ...shownFinished]) {
248
+ lines.push(describeTaskLine(task, now));
249
+ }
250
+ if (hidden > 0) {
251
+ lines.push(`(+${hidden} more finished, not shown — action read shows any task's output)`);
252
+ }
253
+ return {
254
+ content: [{ type: "text", text: lines.join("\n") }],
255
+ details: {
256
+ action: "list",
257
+ running: running.length,
258
+ finished: finished.length,
259
+ shown: running.length + shownFinished.length,
260
+ hidden,
261
+ },
262
+ };
263
+ }
264
+ //# sourceMappingURL=actions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"actions.js","sourceRoot":"","sources":["../../../src/extensions/background/actions.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAGH,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAC/D,OAAO,EAAE,UAAU,EAAE,MAAM,8BAA8B,CAAC;AAC1D,OAAO,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AAC5D,OAAO,EAAE,sBAAsB,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AACjG,OAAO,EAAoB,eAAe,EAAE,eAAe,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAEhG,OAAO,EAEN,cAAc,EACd,eAAe,EACf,WAAW,EACX,mBAAmB,EACnB,cAAc,EACd,aAAa,GACb,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AACxF,OAAO,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAGvD,0DAA0D;AAC1D,MAAM,gBAAgB,GAAG,EAAE,CAAC;AAE5B,SAAS,sBAAsB,CAAC,KAAa,EAAE,MAAyC;IACvF,IAAI,MAAM,CAAC,MAAM,KAAK,WAAW,EAAE,CAAC;QACnC,MAAM,KAAK,GAAG,MAAM,CAAC,UAAU,CAAC,GAAG,CAClC,CAAC,IAAI,EAAE,EAAE,CAAC,KAAK,IAAI,CAAC,EAAE,KAAK,IAAI,CAAC,MAAM,MAAM,eAAe,CAAC,IAAI,EAAE,gBAAgB,CAAC,EAAE,CACrF,CAAC;QACF,OAAO,YAAY,KAAK,gCAAgC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;IAC5E,CAAC;I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cAAc,QAAQ,CAAC,MAAM,WAAW,CAAC,CAAC;IAC1E,KAAK,MAAM,IAAI,IAAI,CAAC,GAAG,OAAO,EAAE,GAAG,aAAa,CAAC,EAAE,CAAC;QACnD,KAAK,CAAC,IAAI,CAAC,gBAAgB,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC,CAAC;IACzC,CAAC;IACD,IAAI,MAAM,GAAG,CAAC,EAAE,CAAC;QAChB,KAAK,CAAC,IAAI,CAAC,KAAK,MAAM,kEAAkE,CAAC,CAAC;IAC3F,CAAC;IACD,OAAO;QACN,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;QACnD,OAAO,EAAE;YACR,MAAM,EAAE,MAAM;YACd,OAAO,EAAE,OAAO,CAAC,MAAM;YACvB,QAAQ,EAAE,QAAQ,CAAC,MAAM;YACzB,KAAK,EAAE,OAAO,CAAC,MAAM,GAAG,aAAa,CAAC,MAAM;YAC5C,MAAM;SACN;KACD,CAAC;AACH,CAAC","sourcesContent":["/**\n * background — the five `bg` actions.\n *\n * Free functions over the registry rather than closures over the extension's\n * session state: each action can be read, moved, and tested on its own, and\n * the required fields are narrowed at the top of each one (schema.ts) instead\n * of being asserted with a cast. Every model-facing tool-result string this\n * extension produces is built here.\n */\n\nimport type { AgentToolResult, ExtensionContext } from \"../../core/extensions/types.ts\";\nimport { resolveSpawnContext } from \"../../core/tools/bash.ts\";\nimport { formatSize } from \"../../core/tools/truncate.ts\";\nimport { sanitizeBinaryOutput } from \"../../utils/shell.ts\";\nimport { BG_LIST_FINISHED_SHOWN, BG_WAIT_DELTA_BYTES, BG_WAIT_PEEK_BYTES } from \"./constants.ts\";\nimport { type OutputSlice, readOutputSince, readOutputSlice, readTail } from \"./output-file.ts\";\nimport type { BackgroundTaskRegistry, BgTask, ResolveTaskResult } from \"./registry.ts\";\nimport {\n\ttype BgInput,\n\tclampReadBytes,\n\tclampSinceBytes,\n\tclampWaitMs,\n\tparseTimeoutSeconds,\n\trequireCommand,\n\trequireTaskId,\n} from \"./schema.ts\";\nimport { exitSuffix, hasExitCode, runtimeLabel, taskLabelWithin } from \"./task-view.ts\";\nimport { formatDuration, noticeLine } from \"./text.ts\";\nimport type { BgCreateDetails, BgKillDetails, BgListDetails, BgReadDetails, BgWaitDetails } from \"./types.ts\";\n\n/** Width budget for a task label inside a listing row. */\nconst LIST_LABEL_WIDTH = 60;\n\nfunction describeResolveFailure(input: string, result: ResolveTaskResult & { ok: false }): string {\n\tif (result.reason === \"ambiguous\") {\n\t\tconst lines = result.candidates.map(\n\t\t\t(task) => ` ${task.id} (${task.status}) ${taskLabelWithin(task, LIST_LABEL_WIDTH)}`,\n\t\t);\n\t\treturn `Task id \"${input}\" is ambiguous. Candidates:\\n${lines.join(\"\\n\")}`;\n\t}\n\treturn `No background task matches \"${input}\". Check the id returned by bg (action create), or run action list.`;\n}\n\n/** Resolve a task by id or unique prefix, or throw a message naming the next step. */\nfunction resolveTask(registry: BackgroundTaskRegistry, taskId: string): BgTask {\n\tconst resolved = registry.resolveTask(taskId);\n\tif (!resolved.ok) throw new Error(describeResolveFailure(taskId, resolved));\n\treturn resolved.task;\n}\n\n/** One row of a bounded task listing: the model-facing list and the /bg fallback summary. */\nexport function describeTaskLine(task: BgTask, now: number): string {\n\tconst label = taskLabelWithin(task, LIST_LABEL_WIDTH);\n\treturn ` ${task.id} ${task.status}${exitSuffix(task.exitCode, \" \")} ${runtimeLabel(task, now)} ${label}`;\n}\n\n// ── create ────────────────────────────────────────────────────────────────\n\nexport function runCreate(\n\tregistry: BackgroundTaskRegistry,\n\tinput: BgInput,\n\tctx: ExtensionContext,\n): AgentToolResult<BgCreateDetails> {\n\tconst command = requireCommand(input);\n\tconst timeoutSeconds = parseTimeoutSeconds(input.timeout);\n\t// Same PI_* session variables as the built-in bash tool, snapshotted at start.\n\tconst spawnContext = resolveSpawnContext(command, ctx.cwd, undefined, true, ctx);\n\t// Deliberately ignore the turn signal: aborting the current turn must not\n\t// kill the background task (that is what action kill is for).\n\tconst task = registry.startTask({\n\t\tcommand,\n\t\tcwd: ctx.cwd,\n\t\tdescription: input.description,\n\t\ttimeoutSeconds,\n\t\tenv: spawnContext.env,\n\t});\n\tconst label = task.description ? ` (${task.description})` : \"\";\n\tconst text = [\n\t\t`Started background task ${task.id}${label}.`,\n\t\t`Output file: ${task.outputPath}`,\n\t\t\"\",\n\t\t\"A <background-task> notification with the result and output tail arrives automatically when the task \" +\n\t\t\t\"ends — do NOT poll (no sleep loops, no repeated reads). Use action read for an early peek, \" +\n\t\t\t\"action wait when the next step depends on the result, action kill to stop it.\",\n\t].join(\"\\n\");\n\treturn {\n\t\tcontent: [{ type: \"text\", text }],\n\t\tdetails: {\n\t\t\taction: \"create\",\n\t\t\ttaskId: task.id,\n\t\t\toutputPath: task.outputPath,\n\t\t\tcommand,\n\t\t\tdescription: input.description,\n\t\t},\n\t};\n}\n\n// ── read ──────────────────────────────────────────────────────────────────\n\nexport async function runRead(\n\tregistry: BackgroundTaskRegistry,\n\tinput: BgInput,\n): Promise<AgentToolResult<BgReadDetails>> {\n\tconst task = resolveTask(registry, requireTaskId(input));\n\tconst mode = input.mode ?? \"tail\";\n\tlet slice: OutputSlice;\n\ttry {\n\t\tslice = await readOutputSlice(task.outputPath, { mode, maxBytes: clampReadBytes(input.bytes) });\n\t} catch (error) {\n\t\tconst message = error instanceof Error ? error.message : String(error);\n\t\tthrow new Error(\n\t\t\t`Could not read output for ${task.id} (${task.status}): ${message}\\nOutput file: ${task.outputPath}`,\n\t\t);\n\t}\n\tconst running = task.status === \"running\" && \"still running\";\n\tconst notice = slice.truncated\n\t\t? noticeLine([\n\t\t\t\t`${mode} ${formatSize(slice.sliceBytes)} of ${formatSize(slice.totalBytes)}`,\n\t\t\t\t`task ${task.id} ${task.status}`,\n\t\t\t\trunning,\n\t\t\t\tslice.startsMidLine && \"first line may be partial\",\n\t\t\t\t`full output: ${task.outputPath}`,\n\t\t\t])\n\t\t: noticeLine([\n\t\t\t\t`task ${task.id} ${task.status}`,\n\t\t\t\trunning,\n\t\t\t\t`${formatSize(slice.totalBytes)} total`,\n\t\t\t\t`output: ${task.outputPath}`,\n\t\t\t]);\n\tconst text = sanitizeBinaryOutput(slice.text);\n\treturn {\n\t\tcontent: [{ type: \"text\", text: `${notice}\\n${text.length > 0 ? text : \"(no output yet)\"}` }],\n\t\tdetails: {\n\t\t\taction: \"read\",\n\t\t\ttaskId: task.id,\n\t\t\tmode,\n\t\t\tsliceBytes: slice.sliceBytes,\n\t\t\ttotalBytes: slice.totalBytes,\n\t\t\toutputPath: task.outputPath,\n\t\t},\n\t};\n}\n\n// ── wait ──────────────────────────────────────────────────────────────────\n\n/** The six fields every wait result shares; only the output accounting differs. */\nfunction waitDetails(\n\ttask: BgTask,\n\twaitedMs: number,\n\toutput: { timedOut: boolean; deltaBytes: number; totalBytes: number; deltaTruncated: boolean },\n): BgWaitDetails {\n\treturn {\n\t\taction: \"wait\",\n\t\ttaskId: task.id,\n\t\tstatus: task.status,\n\t\texitCode: task.exitCode,\n\t\toutputPath: task.outputPath,\n\t\twaitedMs,\n\t\t...output,\n\t};\n}\n\n/** Header shared by a settled wait and by a settled wait whose output could not be read. */\nfunction settledHeaderParts(task: BgTask, waitedMs: number): (string | false)[] {\n\treturn [\n\t\t`${task.id} ${task.status}`,\n\t\thasExitCode(task.exitCode) && `exit ${task.exitCode}`,\n\t\t`ran ${runtimeLabel(task)}`,\n\t\t`waited ${formatDuration(waitedMs)}`,\n\t];\n}\n\nexport async function runWait(\n\tregistry: BackgroundTaskRegistry,\n\tinput: BgInput,\n\tsignal?: AbortSignal,\n): Promise<AgentToolResult<BgWaitDetails>> {\n\tconst task = resolveTask(registry, requireTaskId(input));\n\tconst startedWait = Date.now();\n\tconst result = await registry.waitForResult(task.id, clampWaitMs(input.waitMs), signal);\n\tconst waitedMs = Date.now() - startedWait;\n\treturn result.outcome === \"timeout\"\n\t\t? waitTimedOut(result.task, waitedMs)\n\t\t: waitSettled(result.task, waitedMs, clampSinceBytes(input.sinceBytes));\n}\n\n/** Window expired, task still running: keep progress visible with a bounded tail peek. */\nasync function waitTimedOut(task: BgTask, waitedMs: number): Promise<AgentToolResult<BgWaitDetails>> {\n\tconst peek = await readTail(task.outputPath, BG_WAIT_PEEK_BYTES);\n\tconst totalBytes = peek.slice?.totalBytes ?? task.outputBytes;\n\tconst lines = [\n\t\tnoticeLine([`${task.id} still running`, `waited ${formatDuration(waitedMs)}`, `${formatSize(totalBytes)} total`]),\n\t];\n\tconst trimmed = sanitizeBinaryOutput(peek.slice?.text ?? \"\").trimEnd();\n\tif (trimmed.length > 0) {\n\t\tconst note = peek.slice?.truncated ? ` (last ${formatSize(peek.slice.sliceBytes)})` : \"\";\n\t\tlines.push(`Last output${note}:\\n${trimmed}`);\n\t}\n\tlines.push(\n\t\t\"The task keeps running. Wait again (action wait), peek with action read, or stop it with action kill; \" +\n\t\t\t\"the <background-task> notification still arrives when it ends. Do not sleep-poll.\",\n\t);\n\treturn {\n\t\tcontent: [{ type: \"text\", text: lines.join(\"\\n\\n\") }],\n\t\tdetails: waitDetails(task, waitedMs, { timedOut: true, deltaBytes: 0, totalBytes, deltaTruncated: false }),\n\t};\n}\n\n/**\n * Terminal: deliver the bounded delta since the requested offset. The followUp\n * notification was suppressed by the claim protocol — this result is the single\n * delivery of the completion, so it is produced even when the file is unreadable.\n */\nasync function waitSettled(\n\ttask: BgTask,\n\twaitedMs: number,\n\tsinceBytes: number | undefined,\n): Promise<AgentToolResult<BgWaitDetails>> {\n\tlet delta: Awaited<ReturnType<typeof readOutputSince>>;\n\ttry {\n\t\tdelta = await readOutputSince(task.outputPath, sinceBytes ?? 0, BG_WAIT_DELTA_BYTES);\n\t} catch (error) {\n\t\tconst message = error instanceof Error ? error.message : String(error);\n\t\tconst notice = noticeLine(settledHeaderParts(task, waitedMs));\n\t\treturn {\n\t\t\tcontent: [{ type: \"text\", text: `${notice}\\nerror reading output: ${message}` }],\n\t\t\tdetails: waitDetails(task, waitedMs, {\n\t\t\t\ttimedOut: false,\n\t\t\t\tdeltaBytes: 0,\n\t\t\t\ttotalBytes: task.outputBytes,\n\t\t\t\tdeltaTruncated: false,\n\t\t\t}),\n\t\t};\n\t}\n\n\tconst lines = [\n\t\tnoticeLine([\n\t\t\t...settledHeaderParts(task, waitedMs),\n\t\t\t`+${formatSize(delta.sliceBytes)} new output`,\n\t\t\t`total ${formatSize(delta.totalBytes)}`,\n\t\t]),\n\t];\n\tif (delta.offsetPastEof) {\n\t\tlines.push(\n\t\t\ttask.outputTruncated\n\t\t\t\t? \"[the given offset is past EOF — output was truncated at the limit; showing the tail]\"\n\t\t\t\t: \"[the given offset is past EOF; showing the tail]\",\n\t\t);\n\t}\n\tif (task.error) lines.push(`error: ${task.error}`);\n\tif (delta.truncated) {\n\t\tlines.push(\n\t\t\t`[showing ${formatSize(delta.sliceBytes)} of ${formatSize(delta.totalBytes)}; full output: ${task.outputPath}]`,\n\t\t);\n\t}\n\tconst body = sanitizeBinaryOutput(delta.text).trimEnd();\n\tlines.push(body.length > 0 ? body : \"(no new output)\");\n\treturn {\n\t\tcontent: [{ type: \"text\", text: lines.join(\"\\n\") }],\n\t\tdetails: waitDetails(task, waitedMs, {\n\t\t\ttimedOut: false,\n\t\t\tdeltaBytes: delta.sliceBytes,\n\t\t\ttotalBytes: delta.totalBytes,\n\t\t\tdeltaTruncated: delta.truncated,\n\t\t}),\n\t};\n}\n\n// ── kill ──────────────────────────────────────────────────────────────────\n\nexport function runKill(registry: BackgroundTaskRegistry, input: BgInput): AgentToolResult<BgKillDetails> {\n\tconst task = resolveTask(registry, requireTaskId(input));\n\tif (!registry.killTask(task.id).killed) {\n\t\tthrow new Error(`Task ${task.id} is not running (status: ${task.status}${exitSuffix(task.exitCode, \", \")}).`);\n\t}\n\treturn {\n\t\tcontent: [\n\t\t\t{\n\t\t\t\ttype: \"text\",\n\t\t\t\ttext: `Killed task ${task.id}. If you are waiting on it (action wait) the killed status is delivered there; otherwise a completion notification follows once the process tree is reaped.`,\n\t\t\t},\n\t\t],\n\t\tdetails: { action: \"kill\", taskId: task.id, command: task.command },\n\t};\n}\n\n// ── list ──────────────────────────────────────────────────────────────────\n\nexport function runList(registry: BackgroundTaskRegistry): AgentToolResult<BgListDetails> {\n\tconst tasks = registry.listTasks();\n\tif (tasks.length === 0) {\n\t\treturn {\n\t\t\tcontent: [{ type: \"text\", text: \"No background tasks this session. Start one with action create.\" }],\n\t\t\tdetails: { action: \"list\", running: 0, finished: 0, shown: 0, hidden: 0 },\n\t\t};\n\t}\n\tconst now = Date.now();\n\tconst running = tasks.filter((task) => task.status === \"running\");\n\tconst finished = tasks.filter((task) => task.status !== \"running\");\n\tconst shownFinished = finished.slice(0, BG_LIST_FINISHED_SHOWN);\n\tconst hidden = finished.length - shownFinished.length;\n\tconst lines = [`${running.length} running · ${finished.length} finished`];\n\tfor (const task of [...running, ...shownFinished]) {\n\t\tlines.push(describeTaskLine(task, now));\n\t}\n\tif (hidden > 0) {\n\t\tlines.push(`(+${hidden} more finished, not shown — action read shows any task's output)`);\n\t}\n\treturn {\n\t\tcontent: [{ type: \"text\", text: lines.join(\"\\n\") }],\n\t\tdetails: {\n\t\t\taction: \"list\",\n\t\t\trunning: running.length,\n\t\t\tfinished: finished.length,\n\t\t\tshown: running.length + shownFinished.length,\n\t\t\thidden,\n\t\t},\n\t};\n}\n"]}
@@ -0,0 +1,24 @@
1
+ /**
2
+ * background — shared limits and identity.
3
+ *
4
+ * Numbers that more than one module needs live here so a change lands in one
5
+ * place; module-private layout constants stay with their view. Registry option
6
+ * defaults (`DEFAULT_MAX_OUTPUT_BYTES`, the stall watchdog tuning) stay in
7
+ * registry.ts, documented next to the options they tune.
8
+ */
9
+ /** customType of the `<background-task>` message sent to the model. */
10
+ export declare const BG_NOTIFICATION_TYPE = "background-task";
11
+ /** Default and floor for a `read` slice; the ceiling is truncate.ts's DEFAULT_MAX_BYTES. */
12
+ export declare const BG_LOGS_DEFAULT_BYTES: number;
13
+ export declare const BG_LOGS_MIN_BYTES = 256;
14
+ /** Finished tasks shown by `list` before the rest fold into a count. */
15
+ export declare const BG_LIST_FINISHED_SHOWN = 5;
16
+ /** Bounded output delta returned by a successful wait. */
17
+ export declare const BG_WAIT_DELTA_BYTES: number;
18
+ /** Tail peek included in a wait timeout result so progress stays visible. */
19
+ export declare const BG_WAIT_PEEK_BYTES: number;
20
+ /** Wait-window bounds shared by execution and the pending-call renderer. */
21
+ export declare const BG_WAIT_DEFAULT_MS = 20000;
22
+ export declare const BG_WAIT_MIN_MS = 1000;
23
+ export declare const BG_WAIT_MAX_MS = 60000;
24
+ //# sourceMappingURL=constants.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../../src/extensions/background/constants.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,uEAAuE;AACvE,eAAO,MAAM,oBAAoB,oBAAoB,CAAC;AAEtD,4FAA4F;AAC5F,eAAO,MAAM,qBAAqB,QAAW,CAAC;AAC9C,eAAO,MAAM,iBAAiB,MAAM,CAAC;AAErC,wEAAwE;AACxE,eAAO,MAAM,sBAAsB,IAAI,CAAC;AAExC,0DAA0D;AAC1D,eAAO,MAAM,mBAAmB,QAAY,CAAC;AAE7C,6EAA6E;AAC7E,eAAO,MAAM,kBAAkB,QAAW,CAAC;AAE3C,4EAA4E;AAC5E,eAAO,MAAM,kBAAkB,QAAS,CAAC;AACzC,eAAO,MAAM,cAAc,OAAQ,CAAC;AACpC,eAAO,MAAM,cAAc,QAAS,CAAC"}
@@ -0,0 +1,24 @@
1
+ /**
2
+ * background — shared limits and identity.
3
+ *
4
+ * Numbers that more than one module needs live here so a change lands in one
5
+ * place; module-private layout constants stay with their view. Registry option
6
+ * defaults (`DEFAULT_MAX_OUTPUT_BYTES`, the stall watchdog tuning) stay in
7
+ * registry.ts, documented next to the options they tune.
8
+ */
9
+ /** customType of the `<background-task>` message sent to the model. */
10
+ export const BG_NOTIFICATION_TYPE = "background-task";
11
+ /** Default and floor for a `read` slice; the ceiling is truncate.ts's DEFAULT_MAX_BYTES. */
12
+ export const BG_LOGS_DEFAULT_BYTES = 8 * 1024;
13
+ export const BG_LOGS_MIN_BYTES = 256;
14
+ /** Finished tasks shown by `list` before the rest fold into a count. */
15
+ export const BG_LIST_FINISHED_SHOWN = 5;
16
+ /** Bounded output delta returned by a successful wait. */
17
+ export const BG_WAIT_DELTA_BYTES = 32 * 1024;
18
+ /** Tail peek included in a wait timeout result so progress stays visible. */
19
+ export const BG_WAIT_PEEK_BYTES = 2 * 1024;
20
+ /** Wait-window bounds shared by execution and the pending-call renderer. */
21
+ export const BG_WAIT_DEFAULT_MS = 20_000;
22
+ export const BG_WAIT_MIN_MS = 1_000;
23
+ export const BG_WAIT_MAX_MS = 60_000;
24
+ //# sourceMappingURL=constants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../src/extensions/background/constants.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,uEAAuE;AACvE,MAAM,CAAC,MAAM,oBAAoB,GAAG,iBAAiB,CAAC;AAEtD,4FAA4F;AAC5F,MAAM,CAAC,MAAM,qBAAqB,GAAG,CAAC,GAAG,IAAI,CAAC;AAC9C,MAAM,CAAC,MAAM,iBAAiB,GAAG,GAAG,CAAC;AAErC,wEAAwE;AACxE,MAAM,CAAC,MAAM,sBAAsB,GAAG,CAAC,CAAC;AAExC,0DAA0D;AAC1D,MAAM,CAAC,MAAM,mBAAmB,GAAG,EAAE,GAAG,IAAI,CAAC;AAE7C,6EAA6E;AAC7E,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,GAAG,IAAI,CAAC;AAE3C,4EAA4E;AAC5E,MAAM,CAAC,MAAM,kBAAkB,GAAG,MAAM,CAAC;AACzC,MAAM,CAAC,MAAM,cAAc,GAAG,KAAK,CAAC;AACpC,MAAM,CAAC,MAAM,cAAc,GAAG,MAAM,CAAC","sourcesContent":["/**\n * background — shared limits and identity.\n *\n * Numbers that more than one module needs live here so a change lands in one\n * place; module-private layout constants stay with their view. Registry option\n * defaults (`DEFAULT_MAX_OUTPUT_BYTES`, the stall watchdog tuning) stay in\n * registry.ts, documented next to the options they tune.\n */\n\n/** customType of the `<background-task>` message sent to the model. */\nexport const BG_NOTIFICATION_TYPE = \"background-task\";\n\n/** Default and floor for a `read` slice; the ceiling is truncate.ts's DEFAULT_MAX_BYTES. */\nexport const BG_LOGS_DEFAULT_BYTES = 8 * 1024;\nexport const BG_LOGS_MIN_BYTES = 256;\n\n/** Finished tasks shown by `list` before the rest fold into a count. */\nexport const BG_LIST_FINISHED_SHOWN = 5;\n\n/** Bounded output delta returned by a successful wait. */\nexport const BG_WAIT_DELTA_BYTES = 32 * 1024;\n\n/** Tail peek included in a wait timeout result so progress stays visible. */\nexport const BG_WAIT_PEEK_BYTES = 2 * 1024;\n\n/** Wait-window bounds shared by execution and the pending-call renderer. */\nexport const BG_WAIT_DEFAULT_MS = 20_000;\nexport const BG_WAIT_MIN_MS = 1_000;\nexport const BG_WAIT_MAX_MS = 60_000;\n"]}