@bastani/atomic 0.9.19-alpha.5 → 0.9.19-alpha.6

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 (109) hide show
  1. package/CHANGELOG.md +26 -0
  2. package/dist/builtin/intercom/CHANGELOG.md +6 -0
  3. package/dist/builtin/intercom/broker/client.ts +19 -1
  4. package/dist/builtin/intercom/index.bundle.mjs +8 -1
  5. package/dist/builtin/intercom/package.json +1 -1
  6. package/dist/builtin/mcp/package.json +1 -1
  7. package/dist/builtin/subagents/CHANGELOG.md +6 -0
  8. package/dist/builtin/subagents/README.md +3 -1
  9. package/dist/builtin/subagents/agents/codebase-online-researcher.md +7 -7
  10. package/dist/builtin/subagents/package.json +1 -1
  11. package/dist/builtin/subagents/skills/subagent/SKILL.md +3 -1
  12. package/dist/builtin/subagents/src/extension/index.bundle.mjs +2 -1
  13. package/dist/builtin/web-access/CHANGELOG.md +7 -0
  14. package/dist/builtin/web-access/README.md +31 -24
  15. package/dist/builtin/web-access/index.bundle.mjs +16099 -77
  16. package/dist/builtin/web-access/package.json +2 -1
  17. package/dist/builtin/workflows/CHANGELOG.md +6 -0
  18. package/dist/builtin/workflows/package.json +1 -1
  19. package/dist/builtin/workflows/src/extension/index.bundle.mjs +31 -2
  20. package/dist/core/agent-session-tool-registry.d.ts.map +1 -1
  21. package/dist/core/agent-session-tool-registry.js +10 -0
  22. package/dist/core/agent-session-tool-registry.js.map +1 -1
  23. package/dist/core/bash-executor.js.map +1 -1
  24. package/dist/core/tools/bash.d.ts +1 -1
  25. package/dist/core/tools/bash.d.ts.map +1 -1
  26. package/dist/core/tools/bash.js +3 -2
  27. package/dist/core/tools/bash.js.map +1 -1
  28. package/dist/core/tools/edit.d.ts +3 -0
  29. package/dist/core/tools/edit.d.ts.map +1 -1
  30. package/dist/core/tools/edit.js +91 -12
  31. package/dist/core/tools/edit.js.map +1 -1
  32. package/dist/core/tools/file-mutation-coordinator.d.ts +255 -0
  33. package/dist/core/tools/file-mutation-coordinator.d.ts.map +1 -0
  34. package/dist/core/tools/file-mutation-coordinator.js +300 -0
  35. package/dist/core/tools/file-mutation-coordinator.js.map +1 -0
  36. package/dist/core/tools/file-mutation-queue.d.ts +14 -1
  37. package/dist/core/tools/file-mutation-queue.d.ts.map +1 -1
  38. package/dist/core/tools/file-mutation-queue.js +15 -3
  39. package/dist/core/tools/file-mutation-queue.js.map +1 -1
  40. package/dist/core/tools/hashline.d.ts +9 -0
  41. package/dist/core/tools/hashline.d.ts.map +1 -1
  42. package/dist/core/tools/hashline.js +12 -1
  43. package/dist/core/tools/hashline.js.map +1 -1
  44. package/dist/core/tools/index.d.ts +9 -1
  45. package/dist/core/tools/index.d.ts.map +1 -1
  46. package/dist/core/tools/index.js +67 -12
  47. package/dist/core/tools/index.js.map +1 -1
  48. package/dist/core/tools/non-minting-snapshot-store.d.ts +49 -0
  49. package/dist/core/tools/non-minting-snapshot-store.d.ts.map +1 -0
  50. package/dist/core/tools/non-minting-snapshot-store.js +64 -0
  51. package/dist/core/tools/non-minting-snapshot-store.js.map +1 -0
  52. package/dist/core/tools/powershell.d.ts +2 -2
  53. package/dist/core/tools/powershell.d.ts.map +1 -1
  54. package/dist/core/tools/powershell.js +2 -5
  55. package/dist/core/tools/powershell.js.map +1 -1
  56. package/dist/core/tools/read-document-extract.js.map +1 -1
  57. package/dist/core/tools/render-utils.js.map +1 -1
  58. package/dist/core/tools/write.d.ts +30 -1
  59. package/dist/core/tools/write.d.ts.map +1 -1
  60. package/dist/core/tools/write.js +97 -8
  61. package/dist/core/tools/write.js.map +1 -1
  62. package/dist/index.d.ts +1 -1
  63. package/dist/index.d.ts.map +1 -1
  64. package/dist/index.js.map +1 -1
  65. package/dist/modes/interactive/components/bash-execution.js.map +1 -1
  66. package/dist/modes/interactive/interactive-mode-base.d.ts +1 -0
  67. package/dist/modes/interactive/interactive-mode-base.d.ts.map +1 -1
  68. package/dist/modes/interactive/interactive-mode-base.js +3 -1
  69. package/dist/modes/interactive/interactive-mode-base.js.map +1 -1
  70. package/dist/modes/interactive/interactive-mode-surface.d.ts +1 -1
  71. package/dist/modes/interactive/interactive-mode-surface.d.ts.map +1 -1
  72. package/dist/modes/interactive/interactive-mode-surface.js.map +1 -1
  73. package/dist/modes/interactive/interactive-render-chat.js +28 -4
  74. package/dist/modes/interactive/interactive-render-chat.js.map +1 -1
  75. package/dist/modes/interactive/interactive-startup.d.ts.map +1 -1
  76. package/dist/modes/interactive/interactive-startup.js +3 -0
  77. package/dist/modes/interactive/interactive-startup.js.map +1 -1
  78. package/dist/modes/interactive-engine/activity-watchdog.d.ts +2 -2
  79. package/dist/modes/interactive-engine/activity-watchdog.d.ts.map +1 -1
  80. package/dist/modes/interactive-engine/activity-watchdog.js.map +1 -1
  81. package/dist/modes/interactive-engine/engine-diagnostic-view.d.ts +3 -1
  82. package/dist/modes/interactive-engine/engine-diagnostic-view.d.ts.map +1 -1
  83. package/dist/modes/interactive-engine/engine-diagnostic-view.js +11 -0
  84. package/dist/modes/interactive-engine/engine-diagnostic-view.js.map +1 -1
  85. package/dist/modes/interactive-engine/isolated-runtime.js +2 -1
  86. package/dist/modes/interactive-engine/isolated-runtime.js.map +1 -1
  87. package/dist/modes/rpc/rpc-client-process.d.ts +2 -0
  88. package/dist/modes/rpc/rpc-client-process.d.ts.map +1 -1
  89. package/dist/modes/rpc/rpc-client-process.js +23 -1
  90. package/dist/modes/rpc/rpc-client-process.js.map +1 -1
  91. package/dist/modes/rpc/rpc-client.d.ts.map +1 -1
  92. package/dist/modes/rpc/rpc-client.js +20 -3
  93. package/dist/modes/rpc/rpc-client.js.map +1 -1
  94. package/dist/utils/markit.d.ts +2 -0
  95. package/dist/utils/markit.d.ts.map +1 -1
  96. package/dist/utils/markit.js +65 -5
  97. package/dist/utils/markit.js.map +1 -1
  98. package/docs/background-tasks.md +14 -10
  99. package/docs/containerization.md +7 -5
  100. package/docs/development.md +11 -0
  101. package/docs/docs.json +1 -0
  102. package/docs/subagents.md +3 -1
  103. package/docs/tools.md +26 -0
  104. package/docs/web-access.md +38 -0
  105. package/examples/extensions/gondolin/index.ts +116 -148
  106. package/examples/extensions/gondolin/package.json +1 -1
  107. package/examples/extensions/ssh.ts +56 -34
  108. package/npm-shrinkwrap.json +33 -33
  109. package/package.json +4 -4
@@ -1 +1 @@
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,IAAI,IAAI,MAAM,EAAE,MAAM,kBAAkB,CAAC;AACtE,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,WAAW,CAAC;AAEnD,OAAO,EAAE,SAAS,EAAE,IAAI,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAC1E,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AACtC,OAAO,EAAe,IAAI,EAAE,MAAM,SAAS,CAAC;AAC5C,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAC3C,OAAO,EAAE,oBAAoB,EAAE,MAAM,wDAAwD,CAAC;AAC9F,OAAO,EAAE,qBAAqB,EAAE,MAAM,uDAAuD,CAAC;AAC9F,OAAO,EAAE,KAAK,EAAE,MAAM,wCAAwC,CAAC;AAC/D,OAAO,EAAE,6BAA6B,EAAE,mBAAmB,EAAE,MAAM,8BAA8B,CAAC;AAClG,OAAO,EACN,cAAc,EACd,WAAW,EACX,eAAe,EACf,qBAAqB,EACrB,uBAAuB,GACvB,MAAM,sBAAsB,CAAC;AAI9B,OAAO,EAEN,+BAA+B,EAC/B,8BAA8B,GAC9B,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,qBAAqB,EAAE,MAAM,sBAAsB,CAAC;AAC7D,OAAO,EACN,gBAAgB,EAChB,wBAAwB,EAGxB,gBAAgB,EAChB,wBAAwB,GACxB,M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Q,EAAE,CAAC;oBACpB,aAAa,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;oBAC9B,KAAK,CAAC,QAAQ,GAAG,SAAS,CAAC;gBAC5B,CAAC;YACF,CAAC;YACD,MAAM,SAAS,GACb,OAAO,CAAC,aAAuD,IAAI,IAAI,yBAAyB,EAAE,CAAC;YACrG,gCAAgC,CAC/B,SAAS,EACT,MAAM,EACN,OAAO,EACP,OAAO,CAAC,UAAU,EAClB,KAAK,CAAC,SAAS,EACf,KAAK,CAAC,OAAO,CACb,CAAC;YACF,SAAS,CAAC,UAAU,EAAE,CAAC;YACvB,OAAO,SAAS,CAAC;QAClB,CAAC;KACD,CAAC;AACH,CAAC;AACD,MAAM,UAAU,cAAc,CAAC,GAAW,EAAE,OAAyB;IACpE,OAAO,kBAAkB,CAAC,wBAAwB,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC,CAAC;AACnE,CAAC","sourcesContent":["import { constants } from \"node:fs\";\nimport { access as fsAccess, stat as fsStat } from \"node:fs/promises\";\nimport { resolve as resolvePath } from \"node:path\";\nimport type { AgentTool } from \"@earendil-works/pi-agent-core\";\nimport { Container, Text, truncateToWidth } from \"@earendil-works/pi-tui\";\nimport { spawn } from \"child_process\";\nimport { type Static, Type } from \"typebox\";\nimport { APP_NAME } from \"../../config.js\";\nimport { parenthesizedKeyHint } from \"../../modes/interactive/components/keybinding-hints.js\";\nimport { truncateToVisualLines } from \"../../modes/interactive/components/visual-truncate.ts\";\nimport { theme } from \"../../modes/interactive/theme/theme.js\";\nimport { createChildProcessEnvironment, waitForChildProcess } from \"../../utils/child-process.ts\";\nimport {\n\tgetShellConfig,\n\tgetShellEnv,\n\tkillProcessTree,\n\ttrackDetachedChildPid,\n\tuntrackDetachedChildPid,\n} from \"../../utils/shell.ts\";\nimport type { BashResult } from \"../bash-executor.ts\";\nimport type { ExtensionContext, ToolDefinition, ToolRenderResultOptions } from \"../extensions/types.ts\";\nimport type { WaitPolicy } from \"../tasks/contracts.js\";\nimport {\n\ttype BashInterceptorRule,\n\tcheckBashInterceptionCandidates,\n\tDEFAULT_BASH_INTERCEPTOR_RULES,\n} from \"./bash-interceptor.ts\";\nimport { stripLeadingCdCommand } from \"./bash-leading-cd.ts\";\nimport {\n\texecuteNativePty,\n\texecuteSupervisedCommand,\n\ttype SupervisedCommandOwner,\n\ttype SupervisedCommandResult,\n\tvalidateBashWait,\n\twaitForSupervisedCommand,\n} from \"./bash-pty-native.js\";\nimport { applyBashSessionEnvironment, snapshotBashSessionEnvironment } from \"./bash-session-environment.ts\";\nimport { OutputAccumulator } from \"./output-accumulator.ts\";\nimport { getTextOutput, invalidArgText, str } from \"./render-utils.ts\";\nimport { expandShellInternalUrls, type InternalResourceContext } from \"./resource-selectors.ts\";\nimport { invalidateNativeSearchCache } from \"./search-native.ts\";\nimport { wrapToolDefinition } from \"./tool-definition-wrapper.ts\";\nimport { DEFAULT_MAX_BYTES, formatSize, type TruncationResult } from \"./truncate.ts\";\n\nconst envSchema = Type.Unsafe<Record<string, string>>({\n\ttype: \"object\",\n\tdescription: \"Environment variables to add or override.\",\n\tadditionalProperties: { type: \"string\" },\n\tpropertyNames: { pattern: \"^[A-Za-z_][A-Za-z0-9_]*$\" },\n});\nconst bashBaseSchema = Type.Object(\n\t{\n\t\tcommand: Type.String({ description: \"Shell command to execute.\" }),\n\t\tenv: Type.Optional(envSchema),\n\t\ttimeout: Type.Optional(Type.Number({ description: \"Timeout in seconds.\" })),\n\t\twait: Type.Optional(\n\t\t\tType.Unsafe<WaitPolicy>({\n\t\t\t\ttype: \"object\",\n\t\t\t\tproperties: {\n\t\t\t\t\tkind: { type: \"string\", enum: [\"background\", \"foreground\"] },\n\t\t\t\t\tbudgetMs: {\n\t\t\t\t\t\ttype: \"number\",\n\t\t\t\t\t\tminimum: 0,\n\t\t\t\t\t\tdescription: \"Foreground observation budget in milliseconds; only valid with foreground.\",\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\trequired: [\"kind\"],\n\t\t\t\tadditionalProperties: false,\n\t\t\t\tdescription:\n\t\t\t\t\t\"Observation policy, independent of execution timeout. Omit for owner-configured automatic yield (default 10s).\",\n\t\t\t}),\n\t\t),\n\t\tcwd: Type.Optional(Type.String({ description: \"Working directory for the command.\" })),\n\t\tpty: Type.Optional(Type.Boolean({ description: \"Run with PTY handling.\" })),\n\t},\n\t{ additionalProperties: false },\n);\ntype ShellCommandInput = Static<typeof bashBaseSchema> & { action?: never; id?: never; budgetMs?: never };\ntype ShellWaitInput = { action: \"wait\"; id: string; budgetMs?: number } & Partial<\n\tRecord<keyof Static<typeof bashBaseSchema>, never>\n>;\nconst bashSchema = Type.Unsafe<ShellCommandInput | ShellWaitInput>({\n\t...bashBaseSchema,\n\tproperties: {\n\t\t...bashBaseSchema.properties,\n\t\taction: {\n\t\t\ttype: \"string\",\n\t\t\tenum: [\"wait\"],\n\t\t\tdescription: \"Observe an existing asynchronous task without executing a command.\",\n\t\t},\n\t\tid: { type: \"string\", description: \"Existing task ID owned by this session.\" },\n\t\tbudgetMs: {\n\t\t\ttype: \"number\",\n\t\t\tminimum: 0,\n\t\t\tdescription: \"Observation budget in milliseconds; omitted uses owner policy.\",\n\t\t},\n\t},\n\trequired: [],\n\tanyOf: [\n\t\t{ required: [\"command\"], not: { anyOf: [\"action\", \"id\", \"budgetMs\"].map((key) => ({ required: [key] })) } },\n\t\t{\n\t\t\trequired: [\"action\", \"id\"],\n\t\t\tnot: { anyOf: Object.keys(bashBaseSchema.properties).map((key) => ({ required: [key] })) },\n\t\t},\n\t],\n});\nexport const bashToolSystemPromptContribution = Object.freeze({\n\tsnippet: \"Execute a shell command.\",\n\tguidelines: Object.freeze([\n\t\t\"You can inspect ATOMIC_* or PI_* environment variables for current model and session details.\",\n\t\t'Use { action: \"wait\", id: taskId, budgetMs: 1000 } to observe an existing shell task. Omit budgetMs for owner policy; zero polls. Never relaunch a yielded command. Waiting does not extend execution timeout or owner lifetime.',\n\t\t\"Choose foreground or background bash observation as needed without asking the user each time. Background yields after admission; foreground waits for its optional budget then the same command continues in background. Omitted wait uses owner-configured automatic background yield (default 10s). Observation never changes the execution timeout, which stops the command. Background requires a supported task owner; unbound foreground waits until completion regardless of budget.\",\n\t] as const),\n} as const);\nexport type BashToolInput = Static<typeof bashSchema>;\nexport interface BashToolDetails {\n\ttruncation?: TruncationResult;\n\tfullOutputPath?: string;\n\texitCode?: number | null;\n\tobservation?: import(\"../tasks/contracts.js\").WaitOutcome;\n\ttimeoutSeconds?: number;\n\trequestedTimeoutSeconds?: number;\n\twallTimeMs?: number;\n}\nconst DEFAULT_TIMEOUT_SECONDS = 300,\n\tMAX_TIMEOUT_SECONDS = 3600;\nexport function validateExplicitTimeoutSeconds(timeout: number): void {\n\tif (!Number.isFinite(timeout) || timeout <= 0 || timeout > MAX_TIMEOUT_SECONDS)\n\t\tthrow new Error(\n\t\t\t`Invalid timeout ${String(timeout)}: timeout must be a finite number greater than 0 and no more than ${MAX_TIMEOUT_SECONDS} seconds`,\n\t\t);\n}\nfunction normalizeTimeoutSeconds(timeout: number | undefined): number {\n\tif (timeout === undefined) return DEFAULT_TIMEOUT_SECONDS;\n\tvalidateExplicitTimeoutSeconds(timeout);\n\treturn Math.max(1, Math.floor(timeout));\n}\nexport type BashOutputChannel = \"stdout\" | \"stderr\";\nexport interface BashOperations {\n\texec: (\n\t\tcommand: string,\n\t\tcwd: string,\n\t\toptions: {\n\t\t\tonData: (data: Buffer, channel?: BashOutputChannel) => void;\n\t\t\tsignal?: AbortSignal;\n\t\t\ttimeout?: number;\n\t\t\twait?: WaitPolicy;\n\t\t\tenv?: NodeJS.ProcessEnv;\n\t\t\tpty?: boolean;\n\t\t},\n\t) => Promise<SupervisedCommandResult>;\n}\nexport function createLocalBashOperations(options?: {\n\tshellPath?: string;\n\ttaskOwner?: SupervisedCommandOwner;\n}): BashOperations {\n\treturn {\n\t\texec: async (command, cwd, { onData, signal, timeout, wait, env, pty }) => {\n\t\t\tvalidateBashWait(wait, !!options?.taskOwner);\n\t\t\tif (timeout !== undefined) validateExplicitTimeoutSeconds(timeout);\n\t\t\tif (pty && process.env.PI_NO_PTY !== \"1\" && process.env.ATOMIC_NO_PTY !== \"1\") {\n\t\t\t\ttry {\n\t\t\t\t\treturn await executeNativePty(command, cwd, {\n\t\t\t\t\t\tonData: (data) => onData(data, \"stdout\"),\n\t\t\t\t\t\tsignal,\n\t\t\t\t\t\ttimeout,\n\t\t\t\t\t\twait,\n\t\t\t\t\t\tenv,\n\t\t\t\t\t\tshellPath: options?.shellPath,\n\t\t\t\t\t\ttaskOwner: options?.taskOwner,\n\t\t\t\t\t});\n\t\t\t\t} catch (error) {\n\t\t\t\t\tif (options?.taskOwner) throw error;\n\t\t\t\t\tconst message = String(error instanceof Error ? error.message : error);\n\t\t\t\t\tif (!message.includes(\"Native PTY\") && !message.includes(\"PtySession\")) throw error;\n\t\t\t\t}\n\t\t\t}\n\t\t\tconst shellConfig = getShellConfig(options?.shellPath);\n\t\t\ttry {\n\t\t\t\tconst cwdStat = await fsStat(cwd);\n\t\t\t\tif (!cwdStat.isDirectory()) throw new Error(`Working directory is not a directory: ${cwd}`);\n\t\t\t\tawait fsAccess(cwd, constants.F_OK);\n\t\t\t} catch (error) {\n\t\t\t\tif (error instanceof Error && error.message.startsWith(\"Working directory is not a directory\")) throw error;\n\t\t\t\tthrow new Error(`Working directory does not exist: ${cwd}\\nCannot execute bash commands.`);\n\t\t\t}\n\t\t\tif (signal?.aborted) throw new Error(\"aborted\");\n\t\t\tif (options?.taskOwner)\n\t\t\t\treturn executeSupervisedCommand(\n\t\t\t\t\tcommand,\n\t\t\t\t\tcwd,\n\t\t\t\t\t{ onData, signal, timeout, wait, env, shellPath: options.shellPath, taskOwner: options.taskOwner },\n\t\t\t\t\tfalse,\n\t\t\t\t);\n\t\t\tconst commandFromStdin = shellConfig.commandTransport === \"stdin\";\n\t\t\tconst child = spawn(shellConfig.shell, commandFromStdin ? shellConfig.args : [...shellConfig.args, command], {\n\t\t\t\tcwd,\n\t\t\t\tdetached: process.platform !== \"win32\",\n\t\t\t\tenv: createChildProcessEnvironment(undefined, env ?? getShellEnv()),\n\t\t\t\tstdio: [commandFromStdin ? \"pipe\" : \"ignore\", \"pipe\", \"pipe\"],\n\t\t\t\twindowsHide: true,\n\t\t\t});\n\t\t\tif (commandFromStdin) {\n\t\t\t\tchild.stdin?.on(\"error\", () => {});\n\t\t\t\tchild.stdin?.end(command);\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\t\t\ttry {\n\t\t\t\tif (timeout !== undefined && timeout > 0) {\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}, timeout * 1000);\n\t\t\t\t}\n\t\t\t\tchild.stdout?.on(\"data\", (data: Buffer) => onData(data, \"stdout\"));\n\t\t\t\tchild.stderr?.on(\"data\", (data: Buffer) => onData(data, \"stderr\"));\n\t\t\t\tif (signal) {\n\t\t\t\t\tif (signal.aborted) onAbort();\n\t\t\t\t\telse signal.addEventListener(\"abort\", onAbort, { once: true });\n\t\t\t\t}\n\t\t\t\tconst exitCode = await waitForChildProcess(child);\n\t\t\t\tif (signal?.aborted) throw new Error(\"aborted\");\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}\nexport interface BashSpawnContext {\n\tcommand: string;\n\tcwd: string;\n\tenv: NodeJS.ProcessEnv;\n}\nexport type BashSpawnHook = (context: BashSpawnContext) => BashSpawnContext;\nfunction resolveSpawnContext(\n\tcommand: string,\n\tcwd: string,\n\tsessionEnvironment: NodeJS.ProcessEnv,\n\tspawnHook?: BashSpawnHook,\n): BashSpawnContext {\n\tconst baseContext: BashSpawnContext = { command, cwd, env: { ...getShellEnv() } };\n\tapplyBashSessionEnvironment(baseContext.env, sessionEnvironment);\n\treturn spawnHook ? spawnHook(baseContext) : baseContext;\n}\nexport interface BashInterceptorResult {\n\toperations?: BashOperations;\n\tresult?: BashResult;\n}\nexport type BashInterceptor = (\n\tcontext: BashSpawnContext,\n) => Promise<BashInterceptorResult | undefined> | BashInterceptorResult | undefined;\nexport interface BashToolOptions {\n\toperations?: BashOperations;\n\t/** Trusted host ownership; never supplied by model arguments. */\n\ttaskOwner?: SupervisedCommandOwner;\n\t/** Expose the execution-time Atomic session snapshot and PI compatibility aliases. Default: true. */\n\texposeSessionEnvironment?: boolean;\n\t/** Prefix prepended to every shell command before execution. */\n\tcommandPrefix?: string;\n\t/** Override shell executable resolution for local bash operations. */\n\tshellPath?: string;\n\t/** Dialect for generated internal-URL path literals. Defaults to POSIX; does not select the executable. */\n\tshellDialect?: \"posix\" | \"powershell\";\n\t/** Last-mile hook for rewriting the command/cwd/env spawn context. */\n\tspawnHook?: BashSpawnHook;\n\t/** Optional command interceptor used by extensions and parity tests. */\n\tinterceptor?: BashInterceptor;\n\tinterceptorEnabled?: boolean | (() => boolean);\n\tavailableTools?: string[];\n\tinterceptorRules?: BashInterceptorRule[];\n\t/**\n\t * Session-scoped directory for overflow logs, resolved per execution so a\n\t * session switch (fork, branch, resume) follows the live transcript session.\n\t */\n\tsessionTempDir?: string | (() => string | undefined);\n}\n/**\n * Presentation identity for a shell-backed built-in tool. Atomic runs PowerShell\n * through the same execution pipeline as bash, so the transcript prompt and the\n * overflow temp-file prefix are the only shell-specific display values.\n */\nexport interface ShellToolPresentation {\n\t/** Transcript prompt prefix: `$` for bash, `PS>` for PowerShell. */\n\tprompt: string;\n\t/** Prefix for the temp file that holds truncated output. */\n\ttempFilePrefix: string;\n}\nexport const BASH_SHELL_PRESENTATION: ShellToolPresentation = {\n\tprompt: \"$\",\n\ttempFilePrefix: `${APP_NAME}-bash`,\n};\nconst BASH_PREVIEW_LINES = 5,\n\tBASH_UPDATE_THROTTLE_MS = 100;\nfunction bashResultToToolResult(result: BashResult): {\n\tcontent: Array<{ type: \"text\"; text: string }>;\n\tdetails: BashToolDetails | undefined;\n} {\n\tconst details: BashToolDetails | undefined = result.truncated\n\t\t? { fullOutputPath: result.fullOutputPath }\n\t\t: undefined;\n\tconst status = result.cancelled\n\t\t? \"Command aborted\"\n\t\t: result.exitCode && result.exitCode !== 0\n\t\t\t? `Command exited with code ${result.exitCode}`\n\t\t\t: undefined;\n\tconst text = `${result.output || \"(no output)\"}${status ? `\\n\\n${status}` : \"\"}`;\n\treturn { content: [{ type: \"text\", text }], details };\n}\ntype BashRenderState = {\n\tstartedAt: number | undefined;\n\tendedAt: number | undefined;\n\tinterval: NodeJS.Timeout | undefined;\n};\ntype BashResultRenderState = {\n\tcachedWidth: number | undefined;\n\tcachedLines: string[] | undefined;\n\tcachedSkipped: number | undefined;\n};\nclass BashResultRenderComponent extends Container {\n\tstate: BashResultRenderState = {\n\t\tcachedWidth: undefined,\n\t\tcachedLines: undefined,\n\t\tcachedSkipped: undefined,\n\t};\n}\nfunction formatDuration(ms: number): string {\n\tconst totalSeconds = Math.floor(Math.max(0, ms) / 1000);\n\tconst hours = Math.floor(totalSeconds / 3600);\n\tconst minutes = Math.floor((totalSeconds % 3600) / 60);\n\tconst seconds = totalSeconds % 60;\n\tif (hours > 0) return minutes > 0 ? `${hours}h ${minutes}m` : `${hours}h`;\n\tif (minutes > 0) return seconds > 0 ? `${minutes}m ${seconds}s` : `${minutes}m`;\n\treturn `${seconds}s`;\n}\nfunction formatBashCall(\n\targs: { command?: string; timeout?: number; action?: string; id?: string } | undefined,\n\tprompt: string,\n): string {\n\tif (args?.action === \"wait\") return theme.fg(\"toolTitle\", theme.bold(`${prompt} wait ${str(args.id) ?? \"...\"}`));\n\tconst command = str(args?.command);\n\tconst timeout = args?.timeout as number | undefined;\n\tconst timeoutSuffix = timeout ? theme.fg(\"muted\", ` (timeout ${timeout}s)`) : \"\";\n\tconst commandDisplay = command === null ? invalidArgText(theme) : command ? command : theme.fg(\"toolOutput\", \"...\");\n\treturn theme.fg(\"toolTitle\", theme.bold(`${prompt} ${commandDisplay}`)) + timeoutSuffix;\n}\nfunction rebuildBashResultRenderComponent(\n\tcomponent: BashResultRenderComponent,\n\tresult: {\n\t\tcontent: Array<{ type: string; text?: string; data?: string; mimeType?: string }>;\n\t\tdetails?: BashToolDetails;\n\t},\n\toptions: ToolRenderResultOptions,\n\tshowImages: boolean,\n\tstartedAt: number | undefined,\n\tendedAt: number | undefined,\n): void {\n\tconst state = component.state;\n\tcomponent.clear();\n\tlet output = getTextOutput(result, showImages).trim();\n\tconst observation = result.details?.observation;\n\tif (observation?.kind === \"yielded\") {\n\t\tconst receipt = `Command is still running (task ${observation.taskId}).`;\n\t\tif (output.endsWith(receipt)) output = output.slice(0, -receipt.length).trimEnd();\n\t\tcomponent.addChild(new Text(theme.fg(\"accent\", \"∀ Continued in background\"), 0, 0));\n\t\tcomponent.addChild(\n\t\t\tnew Text(\n\t\t\t\ttheme.fg(\"dim\", `/tasks to inspect output or stop${options.expanded ? ` · ${observation.taskId}` : \"\"}`),\n\t\t\t\t0,\n\t\t\t\t0,\n\t\t\t),\n\t\t);\n\t}\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\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\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 =\n\t\t\t\t\t\t\ttheme.fg(\"muted\", \"... \") +\n\t\t\t\t\t\t\tparenthesizedKeyHint(\"app.tools.expand\", \"Expand\", `${state.cachedSkipped} earlier lines`);\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\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\tif (startedAt !== undefined) {\n\t\tconst label = options.isPartial ? \"Elapsed\" : observation?.kind === \"yielded\" ? \"Observed for\" : \"Took\";\n\t\tconst endTime = endedAt ?? Date.now();\n\t\tcomponent.addChild(new Text(`\\n${theme.fg(\"muted\", `${label} ${formatDuration(endTime - startedAt)}`)}`, 0, 0));\n\t}\n}\nexport function createBashToolDefinition(\n\tcwd: string,\n\toptions?: BashToolOptions,\n\tpresentation: ShellToolPresentation = BASH_SHELL_PRESENTATION,\n): ToolDefinition<typeof bashSchema, BashToolDetails | undefined, BashRenderState> {\n\tconst defaultOps =\n\t\toptions?.operations ??\n\t\tcreateLocalBashOperations({ shellPath: options?.shellPath, taskOwner: options?.taskOwner });\n\tconst commandPrefix = options?.commandPrefix,\n\t\texposeSessionEnvironment = options?.exposeSessionEnvironment ?? true;\n\tconst spawnHook = options?.spawnHook;\n\tconst interceptor = options?.interceptor;\n\tconst isInterceptorEnabled = (): boolean =>\n\t\ttypeof options?.interceptorEnabled === \"function\"\n\t\t\t? options.interceptorEnabled()\n\t\t\t: (options?.interceptorEnabled ?? !!interceptor);\n\tconst availableTools = options?.availableTools ?? [\"read\", \"search\", \"find\", \"edit\", \"write\"];\n\tconst interceptorRules = options?.interceptorRules ?? DEFAULT_BASH_INTERCEPTOR_RULES;\n\tconst sessionTempDirOption = options?.sessionTempDir;\n\tconst resolveSessionTempDir = (): string | undefined =>\n\t\ttypeof sessionTempDirOption === \"function\" ? sessionTempDirOption() : sessionTempDirOption;\n\treturn {\n\t\tname: \"bash\",\n\t\tlabel: \"bash\",\n\t\tdescription:\n\t\t\t'Execute a shell command with optional PTY handling and foreground/background observation, or observe an existing task with action: \"wait\", id, and optional budgetMs. Omitted command wait uses owner policy (default 10s). Observation never changes execution timeout. Background and existing-task waits require a supported task owner; unbound foreground execution waits until completion.',\n\t\tpromptSnippet: bashToolSystemPromptContribution.snippet,\n\t\tconstrainedSampling: { type: \"json_schema\", strict: \"prefer\" },\n\t\tpromptGuidelines: exposeSessionEnvironment ? [...bashToolSystemPromptContribution.guidelines] : undefined,\n\t\tparameters: bashSchema,\n\t\tmaxResultSizeChars: Infinity,\n\t\tasync execute(_toolCallId, bashCommand: BashToolInput, signal?: AbortSignal, onUpdate?, ctx?: ExtensionContext) {\n\t\t\tif (bashCommand.action !== undefined) {\n\t\t\t\tif (\n\t\t\t\t\tbashCommand.action !== \"wait\" ||\n\t\t\t\t\ttypeof bashCommand.id !== \"string\" ||\n\t\t\t\t\tObject.keys(bashCommand).some((key) => ![\"action\", \"id\", \"budgetMs\"].includes(key)) ||\n\t\t\t\t\t(bashCommand.budgetMs !== undefined &&\n\t\t\t\t\t\t(typeof bashCommand.budgetMs !== \"number\" ||\n\t\t\t\t\t\t\t!Number.isFinite(bashCommand.budgetMs) ||\n\t\t\t\t\t\t\tbashCommand.budgetMs < 0))\n\t\t\t\t)\n\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t\"Invalid shell wait: expected action wait, id, and optional finite non-negative budgetMs\",\n\t\t\t\t\t);\n\t\t\t\treturn waitForSupervisedCommand(options?.taskOwner, bashCommand.id, bashCommand.budgetMs, signal, {\n\t\t\t\t\ttempFilePrefix: presentation.tempFilePrefix,\n\t\t\t\t\ttempDir: resolveSessionTempDir(),\n\t\t\t\t});\n\t\t\t}\n\t\t\tif (\n\t\t\t\tbashCommand.id !== undefined ||\n\t\t\t\tbashCommand.budgetMs !== undefined ||\n\t\t\t\ttypeof bashCommand.command !== \"string\"\n\t\t\t)\n\t\t\t\tthrow new Error(\"Invalid shell command: command is required; id and budgetMs require action wait\");\n\t\t\tconst { command } = bashCommand;\n\t\t\tconst timeout = normalizeTimeoutSeconds(bashCommand.timeout);\n\t\t\tvalidateBashWait(bashCommand.wait, !!options?.operations || !!options?.taskOwner);\n\t\t\tconst sessionEnvironment = snapshotBashSessionEnvironment(ctx, exposeSessionEnvironment);\n\t\t\tconst resourceCtx = ctx as InternalResourceContext | undefined;\n\t\t\tconst executionCwd = ctx?.cwd || cwd;\n\t\t\tconst hasExplicitCwd = typeof bashCommand.cwd === \"string\";\n\t\t\tconst rawStrippedContext = hasExplicitCwd ? undefined : stripLeadingCdCommand(command, executionCwd);\n\t\t\tconst interceptorEnabled = isInterceptorEnabled();\n\t\t\tif (interceptorEnabled)\n\t\t\t\tcheckBashInterceptionCandidates([command, rawStrippedContext?.command], availableTools, interceptorRules);\n\t\t\tconst cwdInput = hasExplicitCwd\n\t\t\t\t\t? await expandShellInternalUrls(bashCommand.cwd!, executionCwd, resourceCtx)\n\t\t\t\t\t: executionCwd,\n\t\t\t\trequestedCwd = resolvePath(executionCwd, cwdInput);\n\t\t\tconst expandedCommand = await expandShellInternalUrls(\n\t\t\t\tcommand,\n\t\t\t\texecutionCwd,\n\t\t\t\tresourceCtx,\n\t\t\t\ttrue,\n\t\t\t\toptions?.shellDialect,\n\t\t\t);\n\t\t\tconst strippedExpandedContext = hasExplicitCwd\n\t\t\t\t? undefined\n\t\t\t\t: stripLeadingCdCommand(expandedCommand, requestedCwd);\n\t\t\tconst resolvedCommand = commandPrefix ? `${commandPrefix}\\n${expandedCommand}` : expandedCommand;\n\t\t\tconst spawnContext = resolveSpawnContext(resolvedCommand, requestedCwd, sessionEnvironment, spawnHook);\n\t\t\tconst strippedCdContext = strippedExpandedContext\n\t\t\t\t? resolveSpawnContext(\n\t\t\t\t\t\tcommandPrefix\n\t\t\t\t\t\t\t? `${commandPrefix}\\n${strippedExpandedContext.command}`\n\t\t\t\t\t\t\t: strippedExpandedContext.command,\n\t\t\t\t\t\tstrippedExpandedContext.cwd,\n\t\t\t\t\t\tsessionEnvironment,\n\t\t\t\t\t\tspawnHook,\n\t\t\t\t\t)\n\t\t\t\t: undefined;\n\t\t\tif (interceptorEnabled)\n\t\t\t\tcheckBashInterceptionCandidates(\n\t\t\t\t\t[\n\t\t\t\t\t\texpandedCommand,\n\t\t\t\t\t\tstrippedExpandedContext?.command,\n\t\t\t\t\t\tresolvedCommand,\n\t\t\t\t\t\tspawnContext.command,\n\t\t\t\t\t\tstrippedCdContext?.command,\n\t\t\t\t\t],\n\t\t\t\t\tavailableTools,\n\t\t\t\t\tinterceptorRules,\n\t\t\t\t);\n\t\t\tlet expandedEnv: NodeJS.ProcessEnv | undefined;\n\t\t\tif (bashCommand.env) {\n\t\t\t\texpandedEnv = {};\n\t\t\t\tfor (const [key, value] of Object.entries(bashCommand.env)) {\n\t\t\t\t\tif (!/^[A-Za-z_][A-Za-z0-9_]*$/.test(key)) throw new Error(`Invalid bash env name: ${key}`);\n\t\t\t\t\texpandedEnv[key] = await expandShellInternalUrls(value, executionCwd, resourceCtx);\n\t\t\t\t}\n\t\t\t\tspawnContext.env = { ...spawnContext.env, ...expandedEnv };\n\t\t\t}\n\t\t\tif (strippedCdContext && expandedEnv) strippedCdContext.env = { ...strippedCdContext.env, ...expandedEnv };\n\t\t\tapplyBashSessionEnvironment(spawnContext.env, sessionEnvironment);\n\t\t\tif (strippedCdContext) applyBashSessionEnvironment(strippedCdContext.env, sessionEnvironment);\n\t\t\tconst primaryInterception = interceptorEnabled && interceptor ? await interceptor(spawnContext) : undefined;\n\t\t\tconst fallbackInterception =\n\t\t\t\t!primaryInterception && strippedCdContext && interceptorEnabled && interceptor\n\t\t\t\t\t? await interceptor(strippedCdContext)\n\t\t\t\t\t: undefined;\n\t\t\tconst intercepted = primaryInterception ?? fallbackInterception;\n\t\t\tif (intercepted?.result) return bashResultToToolResult(intercepted.result);\n\t\t\tconst ops = intercepted?.operations ?? defaultOps;\n\t\t\tconst executionContext = primaryInterception ? spawnContext : (strippedCdContext ?? spawnContext);\n\t\t\tconst output = new OutputAccumulator({\n\t\t\t\ttempFilePrefix: presentation.tempFilePrefix,\n\t\t\t\ttempDir: resolveSessionTempDir(),\n\t\t\t});\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\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\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\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\t\t\tif (onUpdate) {\n\t\t\t\tonUpdate({ content: [], details: undefined });\n\t\t\t}\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\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\ttry {\n\t\t\t\t\tawait output.closeTempFile();\n\t\t\t\t} catch {\n\t\t\t\t\t// The spill file could not be flushed. Keep the truncated result, but\n\t\t\t\t\t// re-read the snapshot so the now-cleared path is not advertised.\n\t\t\t\t\treturn output.snapshot();\n\t\t\t\t}\n\t\t\t\treturn snapshot;\n\t\t\t};\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\t// Persistence can be refused (a temp directory we will not write\n\t\t\t\t\t// through, a full or read-only disk), and then there is no path to\n\t\t\t\t\t// name. Every other renderer already omits the clause; this one must\n\t\t\t\t\t// too, rather than handing the model the string \"undefined\".\n\t\t\t\t\tconst fullOutputNote = snapshot.fullOutputPath ? ` Full output: ${snapshot.fullOutputPath}` : \"\";\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}).${fullOutputNote}]`;\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}.${fullOutputNote}]`;\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).${fullOutputNote}]`;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\treturn { text, details };\n\t\t\t};\n\t\t\tconst startedAt = Date.now();\n\t\t\tconst withTiming = (details: BashToolDetails | undefined): BashToolDetails => ({\n\t\t\t\t...details,\n\t\t\t\ttimeoutSeconds: timeout,\n\t\t\t\t...(bashCommand.timeout !== undefined && bashCommand.timeout !== timeout\n\t\t\t\t\t? { requestedTimeoutSeconds: bashCommand.timeout }\n\t\t\t\t\t: {}),\n\t\t\t\twallTimeMs: Date.now() - startedAt,\n\t\t\t});\n\t\t\tconst appendStatus = (text: string, status: string) => `${text ? `${text}\\n\\n` : \"\"}${status}`;\n\t\t\ttry {\n\t\t\t\tlet exitCode: number | null;\n\t\t\t\tlet observation: SupervisedCommandResult[\"observation\"];\n\t\t\t\ttry {\n\t\t\t\t\tconst result = await ops.exec(executionContext.command, executionContext.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\twait: bashCommand.wait,\n\t\t\t\t\t\tenv: executionContext.env,\n\t\t\t\t\t\tpty: bashCommand.pty,\n\t\t\t\t\t});\n\t\t\t\t\texitCode = result.exitCode;\n\t\t\t\t\tobservation = result.observation;\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\t\t\t\tconst snapshot = await finishOutput();\n\t\t\t\tconst { text: outputText, details } = formatOutput(snapshot);\n\t\t\t\tif (observation?.kind === \"yielded\")\n\t\t\t\t\treturn {\n\t\t\t\t\t\tcontent: [\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\ttype: \"text\",\n\t\t\t\t\t\t\t\ttext: appendStatus(outputText, `Command is still running (task ${observation.taskId}).`),\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t],\n\t\t\t\t\t\tdetails: { ...withTiming(details), observation },\n\t\t\t\t\t};\n\t\t\t\tif (exitCode !== 0 && exitCode !== null) {\n\t\t\t\t\treturn {\n\t\t\t\t\t\tcontent: [{ type: \"text\", text: appendStatus(outputText, `Command exited with code ${exitCode}`) }],\n\t\t\t\t\t\tdetails: { ...withTiming(details), exitCode },\n\t\t\t\t\t\tisError: true,\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t\treturn { content: [{ type: \"text\", text: outputText }], details: withTiming(details) };\n\t\t\t} finally {\n\t\t\t\tinvalidateNativeSearchCache();\n\t\t\t\tclearUpdateTimer();\n\t\t\t}\n\t\t},\n\t\trenderCall(args, _theme, context) {\n\t\t\tconst state = context.state;\n\t\t\tif (context.executionStarted && state.startedAt === undefined) {\n\t\t\t\tstate.startedAt = Date.now();\n\t\t\t\tstate.endedAt = undefined;\n\t\t\t}\n\t\t\tconst text = (context.lastComponent as Text | undefined) ?? new Text(\"\", 0, 0);\n\t\t\ttext.setText(formatBashCall(args, presentation.prompt));\n\t\t\treturn text;\n\t\t},\n\t\trenderResult(result, options, _theme, context) {\n\t\t\tconst state = context.state;\n\t\t\tif (state.startedAt !== undefined && options.isPartial && !state.interval) {\n\t\t\t\tstate.interval = setInterval(() => context.invalidate(), 1000);\n\t\t\t}\n\t\t\tif (!options.isPartial || context.isError) {\n\t\t\t\tstate.endedAt ??= Date.now();\n\t\t\t\tif (state.interval) {\n\t\t\t\t\tclearInterval(state.interval);\n\t\t\t\t\tstate.interval = undefined;\n\t\t\t\t}\n\t\t\t}\n\t\t\tconst component =\n\t\t\t\t(context.lastComponent as BashResultRenderComponent | undefined) ?? new BashResultRenderComponent();\n\t\t\trebuildBashResultRenderComponent(\n\t\t\t\tcomponent,\n\t\t\t\tresult,\n\t\t\t\toptions,\n\t\t\t\tcontext.showImages,\n\t\t\t\tstate.startedAt,\n\t\t\t\tstate.endedAt,\n\t\t\t);\n\t\t\tcomponent.invalidate();\n\t\t\treturn component;\n\t\t},\n\t};\n}\nexport function createBashTool(cwd: string, options?: BashToolOptions): AgentTool<typeof bashSchema> {\n\treturn wrapToolDefinition(createBashToolDefinition(cwd, options));\n}\n"]}
1
+ {"version":3,"file":"bash.js","sourceRoot":"","sources":["../../../src/core/tools/bash.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AACpC,OAAO,EAAE,MAAM,IAAI,QAAQ,EAAE,IAAI,IAAI,MAAM,EAAE,MAAM,kBAAkB,CAAC;AACtE,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,WAAW,CAAC;AAEnD,OAAO,EAAE,SAAS,EAAE,IAAI,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAC1E,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AACtC,OAAO,EAAe,IAAI,EAAE,MAAM,SAAS,CAAC;AAC5C,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAC3C,OAAO,EAAE,oBAAoB,EAAE,MAAM,wDAAwD,CAAC;AAC9F,OAAO,EAAE,qBAAqB,EAAE,MAAM,uDAAuD,CAAC;AAC9F,OAAO,EAAE,KAAK,EAAE,MAAM,wCAAwC,CAAC;AAC/D,OAAO,EAAE,6BAA6B,EAAE,mBAAmB,EAAE,MAAM,8BAA8B,CAAC;AAClG,OAAO,EACN,cAAc,EACd,WAAW,EACX,eAAe,EACf,qBAAqB,EACrB,uBAAuB,GACvB,MAAM,sBAAsB,CAAC;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AAO,CAAC,UAAU,EAAE,EAAE,IAAI,CAAC,CAAC;YAChE,CAAC;YACD,IAAI,CAAC,OAAO,CAAC,SAAS,IAAI,OAAO,CAAC,OAAO,EAAE,CAAC;gBAC3C,KAAK,CAAC,OAAO,KAAK,IAAI,CAAC,GAAG,EAAE,CAAC;gBAC7B,IAAI,KAAK,CAAC,QAAQ,EAAE,CAAC;oBACpB,aAAa,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;oBAC9B,KAAK,CAAC,QAAQ,GAAG,SAAS,CAAC;gBAC5B,CAAC;YACF,CAAC;YACD,MAAM,SAAS,GACb,OAAO,CAAC,aAAuD,IAAI,IAAI,yBAAyB,EAAE,CAAC;YACrG,gCAAgC,CAC/B,SAAS,EACT,MAAM,EACN,OAAO,EACP,OAAO,CAAC,UAAU,EAClB,KAAK,CAAC,SAAS,EACf,KAAK,CAAC,OAAO,CACb,CAAC;YACF,SAAS,CAAC,UAAU,EAAE,CAAC;YACvB,OAAO,SAAS,CAAC;QAClB,CAAC;KACD,CAAC;AACH,CAAC;AACD,MAAM,UAAU,cAAc,CAAC,GAAW,EAAE,OAAyB;IACpE,OAAO,kBAAkB,CAAC,wBAAwB,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC,CAAC;AACnE,CAAC","sourcesContent":["import { constants } from \"node:fs\";\nimport { access as fsAccess, stat as fsStat } from \"node:fs/promises\";\nimport { resolve as resolvePath } from \"node:path\";\nimport type { AgentTool } from \"@earendil-works/pi-agent-core\";\nimport { Container, Text, truncateToWidth } from \"@earendil-works/pi-tui\";\nimport { spawn } from \"child_process\";\nimport { type Static, Type } from \"typebox\";\nimport { APP_NAME } from \"../../config.js\";\nimport { parenthesizedKeyHint } from \"../../modes/interactive/components/keybinding-hints.js\";\nimport { truncateToVisualLines } from \"../../modes/interactive/components/visual-truncate.ts\";\nimport { theme } from \"../../modes/interactive/theme/theme.js\";\nimport { createChildProcessEnvironment, waitForChildProcess } from \"../../utils/child-process.ts\";\nimport {\n\tgetShellConfig,\n\tgetShellEnv,\n\tkillProcessTree,\n\ttrackDetachedChildPid,\n\tuntrackDetachedChildPid,\n} from \"../../utils/shell.ts\";\nimport type { BashResult } from \"../bash-executor.ts\";\nimport type { ExtensionContext, ToolDefinition, ToolRenderResultOptions } from \"../extensions/types.ts\";\nimport type { WaitPolicy } from \"../tasks/contracts.js\";\nimport {\n\ttype BashInterceptorRule,\n\tcheckBashInterceptionCandidates,\n\tDEFAULT_BASH_INTERCEPTOR_RULES,\n} from \"./bash-interceptor.ts\";\nimport { stripLeadingCdCommand } from \"./bash-leading-cd.ts\";\nimport {\n\texecuteNativePty,\n\texecuteSupervisedCommand,\n\ttype SupervisedCommandOwner,\n\ttype SupervisedCommandResult,\n\tvalidateBashWait,\n\twaitForSupervisedCommand,\n} from \"./bash-pty-native.js\";\nimport { applyBashSessionEnvironment, snapshotBashSessionEnvironment } from \"./bash-session-environment.ts\";\nimport { OutputAccumulator } from \"./output-accumulator.ts\";\nimport { getTextOutput, invalidArgText, str } from \"./render-utils.ts\";\nimport { expandShellInternalUrls, type InternalResourceContext } from \"./resource-selectors.ts\";\nimport { invalidateNativeSearchCache } from \"./search-native.ts\";\nimport { wrapToolDefinition } from \"./tool-definition-wrapper.ts\";\nimport { DEFAULT_MAX_BYTES, formatSize, type TruncationResult } from \"./truncate.ts\";\n\nconst envSchema = Type.Unsafe<Record<string, string>>({\n\ttype: \"object\",\n\tdescription: \"Environment variables to add or override.\",\n\tadditionalProperties: { type: \"string\" },\n\tpropertyNames: { pattern: \"^[A-Za-z_][A-Za-z0-9_]*$\" },\n});\nconst bashBaseSchema = Type.Object(\n\t{\n\t\tcommand: Type.String({ description: \"Shell command to execute.\" }),\n\t\tenv: Type.Optional(envSchema),\n\t\ttimeout: Type.Optional(Type.Number({ description: \"Timeout in seconds.\" })),\n\t\twait: Type.Optional(\n\t\t\tType.Unsafe<WaitPolicy>({\n\t\t\t\ttype: \"object\",\n\t\t\t\tproperties: {\n\t\t\t\t\tkind: { type: \"string\", enum: [\"background\", \"foreground\"] },\n\t\t\t\t\tbudgetMs: {\n\t\t\t\t\t\ttype: \"number\",\n\t\t\t\t\t\tminimum: 0,\n\t\t\t\t\t\tdescription: \"Foreground observation budget in milliseconds; only valid with foreground.\",\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\trequired: [\"kind\"],\n\t\t\t\tadditionalProperties: false,\n\t\t\t\tdescription:\n\t\t\t\t\t\"Observation policy, independent of execution timeout. Omit for owner-configured automatic yield (default 10s).\",\n\t\t\t}),\n\t\t),\n\t\tcwd: Type.Optional(Type.String({ description: \"Working directory for the command.\" })),\n\t\tpty: Type.Optional(Type.Boolean({ description: \"Run with PTY handling.\" })),\n\t},\n\t{ additionalProperties: false },\n);\ntype ShellCommandInput = Static<typeof bashBaseSchema> & { action?: never; id?: never; budgetMs?: never };\ntype ShellWaitInput = { action: \"wait\"; id: string; budgetMs?: number } & Partial<\n\tRecord<keyof Static<typeof bashBaseSchema>, never>\n>;\nconst bashSchema = Type.Unsafe<ShellCommandInput | ShellWaitInput>({\n\t...bashBaseSchema,\n\tproperties: {\n\t\t...bashBaseSchema.properties,\n\t\taction: {\n\t\t\ttype: \"string\",\n\t\t\tenum: [\"wait\"],\n\t\t\tdescription: \"Observe an existing asynchronous task without executing a command.\",\n\t\t},\n\t\tid: { type: \"string\", description: \"Existing task ID owned by this session.\" },\n\t\tbudgetMs: {\n\t\t\ttype: \"number\",\n\t\t\tminimum: 0,\n\t\t\tdescription: \"Observation budget in milliseconds; omitted uses owner policy.\",\n\t\t},\n\t},\n\trequired: [],\n\tanyOf: [\n\t\t{ required: [\"command\"], not: { anyOf: [\"action\", \"id\", \"budgetMs\"].map((key) => ({ required: [key] })) } },\n\t\t{\n\t\t\trequired: [\"action\", \"id\"],\n\t\t\tnot: { anyOf: Object.keys(bashBaseSchema.properties).map((key) => ({ required: [key] })) },\n\t\t},\n\t],\n});\nexport const bashToolSystemPromptContribution = Object.freeze({\n\tsnippet: \"Execute a shell command.\",\n\tguidelines: Object.freeze([\n\t\t\"You can inspect ATOMIC_* or PI_* environment variables for current model and session details.\",\n\t\t'Use { action: \"wait\", id: taskId } to observe an existing shell task with the owner policy. Avoid repeated short polls; await completion notifications when no dependent work is blocked. Never relaunch a yielded command. Waiting does not extend execution timeout or owner lifetime.',\n\t\t\"For ordinary commands, omit wait to use the owner's observation policy (normally 10s). Do not routinely request one-second waits: premature yields add tool calls without making the command faster. Use a short budget only for a concrete responsiveness need, or explicit background observation when you have independent work to do. Explicit budgets, including zero for polling, remain available.\",\n\t\t\"Choose foreground or background shell observation as needed without asking the user each time. Background yields after admission; foreground waits for its optional budget then the same command continues in background. Omitted wait uses owner-configured automatic background yield (default 10s). Observation never changes the execution timeout, which stops the command. Background requires a supported task owner; unbound foreground waits until completion regardless of budget.\",\n\t] as const),\n} as const);\nexport type BashToolInput = Static<typeof bashSchema>;\nexport interface BashToolDetails {\n\ttruncation?: TruncationResult;\n\tfullOutputPath?: string;\n\texitCode?: number | null;\n\tobservation?: import(\"../tasks/contracts.js\").WaitOutcome;\n\ttimeoutSeconds?: number;\n\trequestedTimeoutSeconds?: number;\n\twallTimeMs?: number;\n}\nconst DEFAULT_TIMEOUT_SECONDS = 300,\n\tMAX_TIMEOUT_SECONDS = 3600;\nexport function validateExplicitTimeoutSeconds(timeout: number): void {\n\tif (!Number.isFinite(timeout) || timeout <= 0 || timeout > MAX_TIMEOUT_SECONDS)\n\t\tthrow new Error(\n\t\t\t`Invalid timeout ${String(timeout)}: timeout must be a finite number greater than 0 and no more than ${MAX_TIMEOUT_SECONDS} seconds`,\n\t\t);\n}\nfunction normalizeTimeoutSeconds(timeout: number | undefined): number {\n\tif (timeout === undefined) return DEFAULT_TIMEOUT_SECONDS;\n\tvalidateExplicitTimeoutSeconds(timeout);\n\treturn Math.max(1, Math.floor(timeout));\n}\nexport type BashOutputChannel = \"stdout\" | \"stderr\";\nexport interface BashOperations {\n\texec: (\n\t\tcommand: string,\n\t\tcwd: string,\n\t\toptions: {\n\t\t\tonData: (data: Buffer, channel?: BashOutputChannel) => void;\n\t\t\tsignal?: AbortSignal;\n\t\t\ttimeout?: number;\n\t\t\twait?: WaitPolicy;\n\t\t\tenv?: NodeJS.ProcessEnv;\n\t\t\tpty?: boolean;\n\t\t},\n\t) => Promise<SupervisedCommandResult>;\n}\nexport function createLocalBashOperations(options?: {\n\tshellPath?: string;\n\ttaskOwner?: SupervisedCommandOwner;\n}): BashOperations {\n\treturn {\n\t\texec: async (command, cwd, { onData, signal, timeout, wait, env, pty }) => {\n\t\t\tvalidateBashWait(wait, !!options?.taskOwner);\n\t\t\tif (timeout !== undefined) validateExplicitTimeoutSeconds(timeout);\n\t\t\tif (pty && process.env.PI_NO_PTY !== \"1\" && process.env.ATOMIC_NO_PTY !== \"1\") {\n\t\t\t\ttry {\n\t\t\t\t\treturn await executeNativePty(command, cwd, {\n\t\t\t\t\t\tonData: (data) => onData(data, \"stdout\"),\n\t\t\t\t\t\tsignal,\n\t\t\t\t\t\ttimeout,\n\t\t\t\t\t\twait,\n\t\t\t\t\t\tenv,\n\t\t\t\t\t\tshellPath: options?.shellPath,\n\t\t\t\t\t\ttaskOwner: options?.taskOwner,\n\t\t\t\t\t});\n\t\t\t\t} catch (error) {\n\t\t\t\t\tif (options?.taskOwner) throw error;\n\t\t\t\t\tconst message = String(error instanceof Error ? error.message : error);\n\t\t\t\t\tif (!message.includes(\"Native PTY\") && !message.includes(\"PtySession\")) throw error;\n\t\t\t\t}\n\t\t\t}\n\t\t\tconst shellConfig = getShellConfig(options?.shellPath);\n\t\t\ttry {\n\t\t\t\tconst cwdStat = await fsStat(cwd);\n\t\t\t\tif (!cwdStat.isDirectory()) throw new Error(`Working directory is not a directory: ${cwd}`);\n\t\t\t\tawait fsAccess(cwd, constants.F_OK);\n\t\t\t} catch (error) {\n\t\t\t\tif (error instanceof Error && error.message.startsWith(\"Working directory is not a directory\")) throw error;\n\t\t\t\tthrow new Error(`Working directory does not exist: ${cwd}\\nCannot execute bash commands.`);\n\t\t\t}\n\t\t\tif (signal?.aborted) throw new Error(\"aborted\");\n\t\t\tif (options?.taskOwner)\n\t\t\t\treturn executeSupervisedCommand(\n\t\t\t\t\tcommand,\n\t\t\t\t\tcwd,\n\t\t\t\t\t{ onData, signal, timeout, wait, env, shellPath: options.shellPath, taskOwner: options.taskOwner },\n\t\t\t\t\tfalse,\n\t\t\t\t);\n\t\t\tconst commandFromStdin = shellConfig.commandTransport === \"stdin\";\n\t\t\tconst child = spawn(shellConfig.shell, commandFromStdin ? shellConfig.args : [...shellConfig.args, command], {\n\t\t\t\tcwd,\n\t\t\t\tdetached: process.platform !== \"win32\",\n\t\t\t\tenv: createChildProcessEnvironment(undefined, env ?? getShellEnv()),\n\t\t\t\tstdio: [commandFromStdin ? \"pipe\" : \"ignore\", \"pipe\", \"pipe\"],\n\t\t\t\twindowsHide: true,\n\t\t\t});\n\t\t\tif (commandFromStdin) {\n\t\t\t\tchild.stdin?.on(\"error\", () => {});\n\t\t\t\tchild.stdin?.end(command);\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\t\t\ttry {\n\t\t\t\tif (timeout !== undefined && timeout > 0) {\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}, timeout * 1000);\n\t\t\t\t}\n\t\t\t\tchild.stdout?.on(\"data\", (data: Buffer) => onData(data, \"stdout\"));\n\t\t\t\tchild.stderr?.on(\"data\", (data: Buffer) => onData(data, \"stderr\"));\n\t\t\t\tif (signal) {\n\t\t\t\t\tif (signal.aborted) onAbort();\n\t\t\t\t\telse signal.addEventListener(\"abort\", onAbort, { once: true });\n\t\t\t\t}\n\t\t\t\tconst exitCode = await waitForChildProcess(child);\n\t\t\t\tif (signal?.aborted) throw new Error(\"aborted\");\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}\nexport interface BashSpawnContext {\n\tcommand: string;\n\tcwd: string;\n\tenv: NodeJS.ProcessEnv;\n}\nexport type BashSpawnHook = (context: BashSpawnContext) => BashSpawnContext;\nfunction resolveSpawnContext(\n\tcommand: string,\n\tcwd: string,\n\tsessionEnvironment: NodeJS.ProcessEnv,\n\tspawnHook?: BashSpawnHook,\n): BashSpawnContext {\n\tconst baseContext: BashSpawnContext = { command, cwd, env: { ...getShellEnv() } };\n\tapplyBashSessionEnvironment(baseContext.env, sessionEnvironment);\n\treturn spawnHook ? spawnHook(baseContext) : baseContext;\n}\nexport interface BashInterceptorResult {\n\toperations?: BashOperations;\n\tresult?: BashResult;\n}\nexport type BashInterceptor = (\n\tcontext: BashSpawnContext,\n) => Promise<BashInterceptorResult | undefined> | BashInterceptorResult | undefined;\nexport interface BashToolOptions {\n\toperations?: BashOperations;\n\t/** Trusted host ownership; never supplied by model arguments. */\n\ttaskOwner?: SupervisedCommandOwner;\n\t/** Expose the execution-time Atomic session snapshot and PI compatibility aliases. Default: true. */\n\texposeSessionEnvironment?: boolean;\n\t/** Prefix prepended to every shell command before execution. */\n\tcommandPrefix?: string;\n\t/** Override shell executable resolution for local bash operations. */\n\tshellPath?: string;\n\t/** Dialect for generated internal-URL path literals. Defaults to POSIX; does not select the executable. */\n\tshellDialect?: \"posix\" | \"powershell\";\n\t/** Last-mile hook for rewriting the command/cwd/env spawn context. */\n\tspawnHook?: BashSpawnHook;\n\t/** Optional command interceptor used by extensions and parity tests. */\n\tinterceptor?: BashInterceptor;\n\tinterceptorEnabled?: boolean | (() => boolean);\n\tavailableTools?: string[];\n\tinterceptorRules?: BashInterceptorRule[];\n\t/**\n\t * Session-scoped directory for overflow logs, resolved per execution so a\n\t * session switch (fork, branch, resume) follows the live transcript session.\n\t */\n\tsessionTempDir?: string | (() => string | undefined);\n}\n/**\n * Presentation identity for a shell-backed built-in tool. Atomic runs PowerShell\n * through the same execution pipeline as bash, so the transcript prompt and the\n * overflow temp-file prefix are the only shell-specific display values.\n */\nexport interface ShellToolPresentation {\n\t/** Transcript prompt prefix: `$` for bash, `PS>` for PowerShell. */\n\tprompt: string;\n\t/** Prefix for the temp file that holds truncated output. */\n\ttempFilePrefix: string;\n}\nexport const BASH_SHELL_PRESENTATION: ShellToolPresentation = {\n\tprompt: \"$\",\n\ttempFilePrefix: `${APP_NAME}-bash`,\n};\nconst BASH_PREVIEW_LINES = 5,\n\tBASH_UPDATE_THROTTLE_MS = 100;\nfunction bashResultToToolResult(result: BashResult): {\n\tcontent: Array<{ type: \"text\"; text: string }>;\n\tdetails: BashToolDetails | undefined;\n} {\n\tconst details: BashToolDetails | undefined = result.truncated\n\t\t? { fullOutputPath: result.fullOutputPath }\n\t\t: undefined;\n\tconst status = result.cancelled\n\t\t? \"Command aborted\"\n\t\t: result.exitCode && result.exitCode !== 0\n\t\t\t? `Command exited with code ${result.exitCode}`\n\t\t\t: undefined;\n\tconst text = `${result.output || \"(no output)\"}${status ? `\\n\\n${status}` : \"\"}`;\n\treturn { content: [{ type: \"text\", text }], details };\n}\ntype BashRenderState = {\n\tstartedAt: number | undefined;\n\tendedAt: number | undefined;\n\tinterval: NodeJS.Timeout | undefined;\n};\ntype BashResultRenderState = {\n\tcachedWidth: number | undefined;\n\tcachedLines: string[] | undefined;\n\tcachedSkipped: number | undefined;\n};\nclass BashResultRenderComponent extends Container {\n\tstate: BashResultRenderState = {\n\t\tcachedWidth: undefined,\n\t\tcachedLines: undefined,\n\t\tcachedSkipped: undefined,\n\t};\n}\nfunction formatDuration(ms: number): string {\n\tconst totalSeconds = Math.floor(Math.max(0, ms) / 1000);\n\tconst hours = Math.floor(totalSeconds / 3600);\n\tconst minutes = Math.floor((totalSeconds % 3600) / 60);\n\tconst seconds = totalSeconds % 60;\n\tif (hours > 0) return minutes > 0 ? `${hours}h ${minutes}m` : `${hours}h`;\n\tif (minutes > 0) return seconds > 0 ? `${minutes}m ${seconds}s` : `${minutes}m`;\n\treturn `${seconds}s`;\n}\nfunction formatBashCall(\n\targs: { command?: string; timeout?: number; action?: string; id?: string } | undefined,\n\tprompt: string,\n): string {\n\tif (args?.action === \"wait\") return theme.fg(\"toolTitle\", theme.bold(`${prompt} wait ${str(args.id) ?? \"...\"}`));\n\tconst command = str(args?.command);\n\tconst timeout = args?.timeout as number | undefined;\n\tconst timeoutSuffix = timeout ? theme.fg(\"muted\", ` (timeout ${timeout}s)`) : \"\";\n\tconst commandDisplay = command === null ? invalidArgText(theme) : command ? command : theme.fg(\"toolOutput\", \"...\");\n\treturn theme.fg(\"toolTitle\", theme.bold(`${prompt} ${commandDisplay}`)) + timeoutSuffix;\n}\nfunction rebuildBashResultRenderComponent(\n\tcomponent: BashResultRenderComponent,\n\tresult: {\n\t\tcontent: Array<{ type: string; text?: string; data?: string; mimeType?: string }>;\n\t\tdetails?: BashToolDetails;\n\t},\n\toptions: ToolRenderResultOptions,\n\tshowImages: boolean,\n\tstartedAt: number | undefined,\n\tendedAt: number | undefined,\n): void {\n\tconst state = component.state;\n\tcomponent.clear();\n\tlet output = getTextOutput(result, showImages).trim();\n\tconst observation = result.details?.observation;\n\tif (observation?.kind === \"yielded\") {\n\t\tconst receipt = `Command is still running (task ${observation.taskId}).`;\n\t\tif (output.endsWith(receipt)) output = output.slice(0, -receipt.length).trimEnd();\n\t\tcomponent.addChild(new Text(theme.fg(\"accent\", \"∀ Continued in background\"), 0, 0));\n\t\tcomponent.addChild(\n\t\t\tnew Text(\n\t\t\t\ttheme.fg(\"dim\", `/tasks to inspect output or stop${options.expanded ? ` · ${observation.taskId}` : \"\"}`),\n\t\t\t\t0,\n\t\t\t\t0,\n\t\t\t),\n\t\t);\n\t}\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\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\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 =\n\t\t\t\t\t\t\ttheme.fg(\"muted\", \"... \") +\n\t\t\t\t\t\t\tparenthesizedKeyHint(\"app.tools.expand\", \"Expand\", `${state.cachedSkipped} earlier lines`);\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\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\tif (startedAt !== undefined) {\n\t\tconst label = options.isPartial ? \"Elapsed\" : observation?.kind === \"yielded\" ? \"Observed for\" : \"Took\";\n\t\tconst endTime = endedAt ?? Date.now();\n\t\tcomponent.addChild(new Text(`\\n${theme.fg(\"muted\", `${label} ${formatDuration(endTime - startedAt)}`)}`, 0, 0));\n\t}\n}\nexport function createBashToolDefinition(\n\tcwd: string,\n\toptions?: BashToolOptions,\n\tpresentation: ShellToolPresentation = BASH_SHELL_PRESENTATION,\n): ToolDefinition<typeof bashSchema, BashToolDetails | undefined, BashRenderState> {\n\tconst defaultOps =\n\t\toptions?.operations ??\n\t\tcreateLocalBashOperations({ shellPath: options?.shellPath, taskOwner: options?.taskOwner });\n\tconst commandPrefix = options?.commandPrefix,\n\t\texposeSessionEnvironment = options?.exposeSessionEnvironment ?? true;\n\tconst spawnHook = options?.spawnHook;\n\tconst interceptor = options?.interceptor;\n\tconst isInterceptorEnabled = (): boolean =>\n\t\ttypeof options?.interceptorEnabled === \"function\"\n\t\t\t? options.interceptorEnabled()\n\t\t\t: (options?.interceptorEnabled ?? !!interceptor);\n\tconst availableTools = options?.availableTools ?? [\"read\", \"search\", \"find\", \"edit\", \"write\"];\n\tconst interceptorRules = options?.interceptorRules ?? DEFAULT_BASH_INTERCEPTOR_RULES;\n\tconst sessionTempDirOption = options?.sessionTempDir;\n\tconst resolveSessionTempDir = (): string | undefined =>\n\t\ttypeof sessionTempDirOption === \"function\" ? sessionTempDirOption() : sessionTempDirOption;\n\treturn {\n\t\tname: \"bash\",\n\t\tlabel: \"bash\",\n\t\tdescription:\n\t\t\t'Execute a shell command with optional PTY handling and foreground/background observation, or observe an existing task with action: \"wait\", id, and optional budgetMs. Omitted command wait uses owner policy (default 10s). Observation never changes execution timeout. Background and existing-task waits require a supported task owner; unbound foreground execution waits until completion.',\n\t\tpromptSnippet: bashToolSystemPromptContribution.snippet,\n\t\tconstrainedSampling: { type: \"json_schema\", strict: \"prefer\" },\n\t\tpromptGuidelines: exposeSessionEnvironment ? [...bashToolSystemPromptContribution.guidelines] : undefined,\n\t\tparameters: bashSchema,\n\t\tmaxResultSizeChars: Infinity,\n\t\tasync execute(_toolCallId, bashCommand: BashToolInput, signal?: AbortSignal, onUpdate?, ctx?: ExtensionContext) {\n\t\t\tif (bashCommand.action !== undefined) {\n\t\t\t\tif (\n\t\t\t\t\tbashCommand.action !== \"wait\" ||\n\t\t\t\t\ttypeof bashCommand.id !== \"string\" ||\n\t\t\t\t\tObject.keys(bashCommand).some((key) => ![\"action\", \"id\", \"budgetMs\"].includes(key)) ||\n\t\t\t\t\t(bashCommand.budgetMs !== undefined &&\n\t\t\t\t\t\t(typeof bashCommand.budgetMs !== \"number\" ||\n\t\t\t\t\t\t\t!Number.isFinite(bashCommand.budgetMs) ||\n\t\t\t\t\t\t\tbashCommand.budgetMs < 0))\n\t\t\t\t)\n\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t\"Invalid shell wait: expected action wait, id, and optional finite non-negative budgetMs\",\n\t\t\t\t\t);\n\t\t\t\treturn waitForSupervisedCommand(options?.taskOwner, bashCommand.id, bashCommand.budgetMs, signal, {\n\t\t\t\t\ttempFilePrefix: presentation.tempFilePrefix,\n\t\t\t\t\ttempDir: resolveSessionTempDir(),\n\t\t\t\t});\n\t\t\t}\n\t\t\tif (\n\t\t\t\tbashCommand.id !== undefined ||\n\t\t\t\tbashCommand.budgetMs !== undefined ||\n\t\t\t\ttypeof bashCommand.command !== \"string\"\n\t\t\t)\n\t\t\t\tthrow new Error(\"Invalid shell command: command is required; id and budgetMs require action wait\");\n\t\t\tconst { command } = bashCommand;\n\t\t\tconst timeout = normalizeTimeoutSeconds(bashCommand.timeout);\n\t\t\tvalidateBashWait(bashCommand.wait, !!options?.operations || !!options?.taskOwner);\n\t\t\tconst sessionEnvironment = snapshotBashSessionEnvironment(ctx, exposeSessionEnvironment);\n\t\t\tconst resourceCtx = ctx as InternalResourceContext | undefined;\n\t\t\tconst executionCwd = ctx?.cwd || cwd;\n\t\t\tconst hasExplicitCwd = typeof bashCommand.cwd === \"string\";\n\t\t\tconst rawStrippedContext = hasExplicitCwd ? undefined : stripLeadingCdCommand(command, executionCwd);\n\t\t\tconst interceptorEnabled = isInterceptorEnabled();\n\t\t\tif (interceptorEnabled)\n\t\t\t\tcheckBashInterceptionCandidates([command, rawStrippedContext?.command], availableTools, interceptorRules);\n\t\t\tconst cwdInput = hasExplicitCwd\n\t\t\t\t\t? await expandShellInternalUrls(bashCommand.cwd!, executionCwd, resourceCtx)\n\t\t\t\t\t: executionCwd,\n\t\t\t\trequestedCwd = resolvePath(executionCwd, cwdInput);\n\t\t\tconst expandedCommand = await expandShellInternalUrls(\n\t\t\t\tcommand,\n\t\t\t\texecutionCwd,\n\t\t\t\tresourceCtx,\n\t\t\t\ttrue,\n\t\t\t\toptions?.shellDialect,\n\t\t\t);\n\t\t\tconst strippedExpandedContext = hasExplicitCwd\n\t\t\t\t? undefined\n\t\t\t\t: stripLeadingCdCommand(expandedCommand, requestedCwd);\n\t\t\tconst resolvedCommand = commandPrefix ? `${commandPrefix}\\n${expandedCommand}` : expandedCommand;\n\t\t\tconst spawnContext = resolveSpawnContext(resolvedCommand, requestedCwd, sessionEnvironment, spawnHook);\n\t\t\tconst strippedCdContext = strippedExpandedContext\n\t\t\t\t? resolveSpawnContext(\n\t\t\t\t\t\tcommandPrefix\n\t\t\t\t\t\t\t? `${commandPrefix}\\n${strippedExpandedContext.command}`\n\t\t\t\t\t\t\t: strippedExpandedContext.command,\n\t\t\t\t\t\tstrippedExpandedContext.cwd,\n\t\t\t\t\t\tsessionEnvironment,\n\t\t\t\t\t\tspawnHook,\n\t\t\t\t\t)\n\t\t\t\t: undefined;\n\t\t\tif (interceptorEnabled)\n\t\t\t\tcheckBashInterceptionCandidates(\n\t\t\t\t\t[\n\t\t\t\t\t\texpandedCommand,\n\t\t\t\t\t\tstrippedExpandedContext?.command,\n\t\t\t\t\t\tresolvedCommand,\n\t\t\t\t\t\tspawnContext.command,\n\t\t\t\t\t\tstrippedCdContext?.command,\n\t\t\t\t\t],\n\t\t\t\t\tavailableTools,\n\t\t\t\t\tinterceptorRules,\n\t\t\t\t);\n\t\t\tlet expandedEnv: NodeJS.ProcessEnv | undefined;\n\t\t\tif (bashCommand.env) {\n\t\t\t\texpandedEnv = {};\n\t\t\t\tfor (const [key, value] of Object.entries(bashCommand.env)) {\n\t\t\t\t\tif (!/^[A-Za-z_][A-Za-z0-9_]*$/.test(key)) throw new Error(`Invalid bash env name: ${key}`);\n\t\t\t\t\texpandedEnv[key] = await expandShellInternalUrls(value, executionCwd, resourceCtx);\n\t\t\t\t}\n\t\t\t\tspawnContext.env = { ...spawnContext.env, ...expandedEnv };\n\t\t\t}\n\t\t\tif (strippedCdContext && expandedEnv) strippedCdContext.env = { ...strippedCdContext.env, ...expandedEnv };\n\t\t\tapplyBashSessionEnvironment(spawnContext.env, sessionEnvironment);\n\t\t\tif (strippedCdContext) applyBashSessionEnvironment(strippedCdContext.env, sessionEnvironment);\n\t\t\tconst primaryInterception = interceptorEnabled && interceptor ? await interceptor(spawnContext) : undefined;\n\t\t\tconst fallbackInterception =\n\t\t\t\t!primaryInterception && strippedCdContext && interceptorEnabled && interceptor\n\t\t\t\t\t? await interceptor(strippedCdContext)\n\t\t\t\t\t: undefined;\n\t\t\tconst intercepted = primaryInterception ?? fallbackInterception;\n\t\t\tif (intercepted?.result) return bashResultToToolResult(intercepted.result);\n\t\t\tconst ops = intercepted?.operations ?? defaultOps;\n\t\t\tconst executionContext = primaryInterception ? spawnContext : (strippedCdContext ?? spawnContext);\n\t\t\tconst output = new OutputAccumulator({\n\t\t\t\ttempFilePrefix: presentation.tempFilePrefix,\n\t\t\t\ttempDir: resolveSessionTempDir(),\n\t\t\t});\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\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\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\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\t\t\tif (onUpdate) {\n\t\t\t\tonUpdate({ content: [], details: undefined });\n\t\t\t}\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\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\ttry {\n\t\t\t\t\tawait output.closeTempFile();\n\t\t\t\t} catch {\n\t\t\t\t\t// The spill file could not be flushed. Keep the truncated result, but\n\t\t\t\t\t// re-read the snapshot so the now-cleared path is not advertised.\n\t\t\t\t\treturn output.snapshot();\n\t\t\t\t}\n\t\t\t\treturn snapshot;\n\t\t\t};\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\t// Persistence can be refused (a temp directory we will not write\n\t\t\t\t\t// through, a full or read-only disk), and then there is no path to\n\t\t\t\t\t// name. Every other renderer already omits the clause; this one must\n\t\t\t\t\t// too, rather than handing the model the string \"undefined\".\n\t\t\t\t\tconst fullOutputNote = snapshot.fullOutputPath ? ` Full output: ${snapshot.fullOutputPath}` : \"\";\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}).${fullOutputNote}]`;\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}.${fullOutputNote}]`;\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).${fullOutputNote}]`;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\treturn { text, details };\n\t\t\t};\n\t\t\tconst startedAt = Date.now();\n\t\t\tconst withTiming = (details: BashToolDetails | undefined): BashToolDetails => ({\n\t\t\t\t...details,\n\t\t\t\ttimeoutSeconds: timeout,\n\t\t\t\t...(bashCommand.timeout !== undefined && bashCommand.timeout !== timeout\n\t\t\t\t\t? { requestedTimeoutSeconds: bashCommand.timeout }\n\t\t\t\t\t: {}),\n\t\t\t\twallTimeMs: Date.now() - startedAt,\n\t\t\t});\n\t\t\tconst appendStatus = (text: string, status: string) => `${text ? `${text}\\n\\n` : \"\"}${status}`;\n\t\t\ttry {\n\t\t\t\tlet exitCode: number | null;\n\t\t\t\tlet observation: SupervisedCommandResult[\"observation\"];\n\t\t\t\ttry {\n\t\t\t\t\tconst result = await ops.exec(executionContext.command, executionContext.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\twait: bashCommand.wait,\n\t\t\t\t\t\tenv: executionContext.env,\n\t\t\t\t\t\tpty: bashCommand.pty,\n\t\t\t\t\t});\n\t\t\t\t\texitCode = result.exitCode;\n\t\t\t\t\tobservation = result.observation;\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\t\t\t\tconst snapshot = await finishOutput();\n\t\t\t\tconst { text: outputText, details } = formatOutput(snapshot);\n\t\t\t\tif (observation?.kind === \"yielded\")\n\t\t\t\t\treturn {\n\t\t\t\t\t\tcontent: [\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\ttype: \"text\",\n\t\t\t\t\t\t\t\ttext: appendStatus(outputText, `Command is still running (task ${observation.taskId}).`),\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t],\n\t\t\t\t\t\tdetails: { ...withTiming(details), observation },\n\t\t\t\t\t};\n\t\t\t\tif (exitCode !== 0 && exitCode !== null) {\n\t\t\t\t\treturn {\n\t\t\t\t\t\tcontent: [{ type: \"text\", text: appendStatus(outputText, `Command exited with code ${exitCode}`) }],\n\t\t\t\t\t\tdetails: { ...withTiming(details), exitCode },\n\t\t\t\t\t\tisError: true,\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t\treturn { content: [{ type: \"text\", text: outputText }], details: withTiming(details) };\n\t\t\t} finally {\n\t\t\t\tinvalidateNativeSearchCache();\n\t\t\t\tclearUpdateTimer();\n\t\t\t}\n\t\t},\n\t\trenderCall(args, _theme, context) {\n\t\t\tconst state = context.state;\n\t\t\tif (context.executionStarted && state.startedAt === undefined) {\n\t\t\t\tstate.startedAt = Date.now();\n\t\t\t\tstate.endedAt = undefined;\n\t\t\t}\n\t\t\tconst text = (context.lastComponent as Text | undefined) ?? new Text(\"\", 0, 0);\n\t\t\ttext.setText(formatBashCall(args, presentation.prompt));\n\t\t\treturn text;\n\t\t},\n\t\trenderResult(result, options, _theme, context) {\n\t\t\tconst state = context.state;\n\t\t\tif (state.startedAt !== undefined && options.isPartial && !state.interval) {\n\t\t\t\tstate.interval = setInterval(() => context.invalidate(), 1000);\n\t\t\t}\n\t\t\tif (!options.isPartial || context.isError) {\n\t\t\t\tstate.endedAt ??= Date.now();\n\t\t\t\tif (state.interval) {\n\t\t\t\t\tclearInterval(state.interval);\n\t\t\t\t\tstate.interval = undefined;\n\t\t\t\t}\n\t\t\t}\n\t\t\tconst component =\n\t\t\t\t(context.lastComponent as BashResultRenderComponent | undefined) ?? new BashResultRenderComponent();\n\t\t\trebuildBashResultRenderComponent(\n\t\t\t\tcomponent,\n\t\t\t\tresult,\n\t\t\t\toptions,\n\t\t\t\tcontext.showImages,\n\t\t\t\tstate.startedAt,\n\t\t\t\tstate.endedAt,\n\t\t\t);\n\t\t\tcomponent.invalidate();\n\t\t\treturn component;\n\t\t},\n\t};\n}\nexport function createBashTool(cwd: string, options?: BashToolOptions): AgentTool<typeof bashSchema> {\n\treturn wrapToolDefinition(createBashToolDefinition(cwd, options));\n}\n"]}
@@ -1,6 +1,7 @@
1
1
  import type { AgentTool } from "@earendil-works/pi-agent-core";
2
2
  import { type Static, Type } from "typebox";
3
3
  import type { ToolDefinition } from "../extensions/types.ts";
4
+ import { type MutationRequesterResolver } from "./file-mutation-coordinator.ts";
4
5
  import { type HashlineSnapshotStore } from "./hashline.ts";
5
6
  declare const editSchema: Type.TObject<{
6
7
  input: Type.TString;
@@ -23,6 +24,8 @@ export interface EditOperations {
23
24
  export interface EditToolOptions {
24
25
  operations?: EditOperations;
25
26
  hashlineStore?: HashlineSnapshotStore;
27
+ /** Resolves who is being rejected when a mutation conflicts. Diagnostic only. */
28
+ resolveMutationRequester?: MutationRequesterResolver;
26
29
  }
27
30
  export declare function createEditToolDefinition(cwd: string, options?: EditToolOptions): ToolDefinition<typeof editSchema, EditToolDetails | undefined>;
28
31
  export declare function createEditTool(cwd: string, options?: EditToolOptions): AgentTool<typeof editSchema>;
@@ -1 +1 @@
1
- {"version":3,"file":"edit.d.ts","sourceRoot":"","sources":["../../../src/core/tools/edit.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,+BAA+B,CAAC;AAI/D,OAAO,EAAE,KAAK,MAAM,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAG5C,OAAO,KAAK,EAAoB,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAK/E,OAAO,EAGN,KAAK,qBAAqB,EAE1B,MAAM,eAAe,CAAC;AAgBvB,QAAA,MAAM,UAAU;;EAQf,CAAC;AAGF,eAAO,MAAM,gCAAgC;sBACnC,8CAA8C;;EAmI7C,CAAC;AAEZ,MAAM,MAAM,aAAa,GAAG,MAAM,CAAC,OAAO,UAAU,CAAC,CAAC;AAEtD,MAAM,WAAW,eAAe;IAC/B,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,gBAAgB,CAAC,EAAE,MAAM,CAAC;CAC1B;AAED,MAAM,WAAW,cAAc;IAC9B,QAAQ,EAAE,CAAC,YAAY,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,CAAC,CAAC;IACpD,SAAS,EAAE,CAAC,YAAY,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IACpE,MAAM,EAAE,CAAC,YAAY,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;CAChD;AAQD,MAAM,WAAW,eAAe;IAC/B,UAAU,CAAC,EAAE,cAAc,CAAC;IAC5B,aAAa,CAAC,EAAE,qBAAqB,CAAC;CACtC;AAwND,wBAAgB,wBAAwB,CACvC,GAAG,EAAE,MAAM,EACX,OAAO,CAAC,EAAE,eAAe,GACvB,cAAc,CAA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C;IACtC,iFAAiF;IACjF,wBAAwB,CAAC,EAAE,yBAAyB,CAAC;CACrD;AA0SD,wBAAgB,wBAAwB,CACvC,GAAG,EAAE,MAAM,EACX,OAAO,CAAC,EAAE,eAAe,GACvB,cAAc,CAAC,OAAO,UAAU,EAAE,eAAe,GAAG,SAAS,CAAC,CAmFhE;AAED,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,eAAe,GAAG,SAAS,CAAC,OAAO,UAAU,CAAC,CAEnG"}
@@ -6,9 +6,11 @@ import { renderDiff } from "../../modes/interactive/components/diff.js";
6
6
  import { nativeBlockResolver } from "./block-resolver.js";
7
7
  import { EditBatchCoordinator, parallelEditBatchWarning } from "./edit-batch.js";
8
8
  import { generateDiffString, generateUnifiedPatch, normalizeToLF, stripBom } from "./edit-diff.js";
9
- import { withFileMutationQueue } from "./file-mutation-queue.js";
9
+ import { assertLiveMatchesPrepared, computeLiveState, FileMutationConflict, filesystemErrorCode, isMissingTargetError, } from "./file-mutation-coordinator.js";
10
+ import { canonicalMutationKey, withFileMutationQueue } from "./file-mutation-queue.js";
10
11
  import { createHashlineSnapshotStore, formatCompactHashlineEditResult, recordHashlineSnapshot, } from "./hashline.js";
11
- import { Filesystem, missingSnapshotTagMessage, Patch, Patcher, } from "./hashline-engine/index.js";
12
+ import { Filesystem, MismatchError, missingSnapshotTagMessage, Patch, Patcher, } from "./hashline-engine/index.js";
13
+ import { NonMintingSnapshotStore } from "./non-minting-snapshot-store.js";
12
14
  import { isNotebookPath, readEditableNotebookText, serializeEditedNotebookText } from "./notebook.js";
13
15
  import { resolveReadPath } from "./path-utils.js";
14
16
  import { renderToolPath } from "./render-utils.js";
@@ -231,9 +233,15 @@ function formatEditResult(result, theme, isError) {
231
233
  }
232
234
  async function withFileMutationQueues(filePaths, fn) {
233
235
  const sorted = [...new Set(filePaths)].sort();
236
+ const canonicalKeys = new Map();
234
237
  const run = (index) => {
235
238
  const filePath = sorted[index];
236
- return filePath ? withFileMutationQueue(filePath, () => run(index + 1)) : fn();
239
+ return filePath
240
+ ? withFileMutationQueue(filePath, (canonicalKey) => {
241
+ canonicalKeys.set(filePath, canonicalKey);
242
+ return run(index + 1);
243
+ })
244
+ : fn(canonicalKeys);
237
245
  };
238
246
  return run(0);
239
247
  }
@@ -264,17 +272,49 @@ function assertUniquePreparedPaths(prepared) {
264
272
  }
265
273
  function createEditCwdScope(cwd, ops, hashlineStore) {
266
274
  const fs = new EditFilesystem(cwd, ops);
267
- const patcher = new Patcher({ fs, snapshots: hashlineStore.snapshots, blockResolver: nativeBlockResolver });
275
+ // Reads delegate to the session store; records are computed and dropped, so a rejection
276
+ // cannot mint the tag that would validate an identical retry. `recordHashlineSnapshot`
277
+ // below stays the single writer of provenance.
278
+ const patcher = new Patcher({
279
+ fs,
280
+ snapshots: new NonMintingSnapshotStore(hashlineStore.snapshots),
281
+ blockResolver: nativeBlockResolver,
282
+ });
268
283
  const noopCounts = new Map();
269
284
  const batcher = new EditBatchCoordinator();
270
- async function applySiblingEdits(siblings, applySignal) {
285
+ /**
286
+ * `requester` is the identity of the call that reached the lock first. #2496 merges
287
+ * compatible siblings into one planned mutation, and a conflict rejects that mutation as a
288
+ * unit, so naming the batch's holder is accurate. Identity is diagnostic regardless: it
289
+ * never decides whether a sibling is admitted.
290
+ */
291
+ async function applySiblingEdits(siblings, canonicalKeys, applySignal, requester) {
271
292
  const merged = siblings.length === 1
272
293
  ? Patch.parse(siblings[0].input, { cwd })
273
294
  : Patch.parse(siblings.map((sibling) => sibling.input).join("\n"), { cwd });
274
295
  const prepared = [];
275
296
  for (const section of merged.sections) {
276
297
  throwIfAborted(applySignal);
277
- prepared.push(await patcher.prepare(section));
298
+ try {
299
+ prepared.push(await patcher.prepare(section));
300
+ }
301
+ catch (error) {
302
+ // `hashRecognized` is the engine's own answer to "have I ever recorded this tag
303
+ // for this path", so the foreign case is read off a typed field rather than
304
+ // matched out of a message in vendored code. Everything else the engine raises
305
+ // is left alone: recovery successes and the head/tail drift warning never reach
306
+ // here, and a stale-but-known tag keeps the engine's own wording.
307
+ if (!(error instanceof MismatchError) || error.hashRecognized)
308
+ throw error;
309
+ throw new FileMutationConflict({
310
+ reason: "foreign_snapshot",
311
+ path: section.path,
312
+ canonicalKey: await canonicalMutationKey(fs.canonicalPath(section.path)),
313
+ presentedTag: error.expectedFileHash,
314
+ liveState: computeLiveState(error.fileLines.join("\n")),
315
+ ...(requester ? { requester } : {}),
316
+ });
317
+ }
278
318
  }
279
319
  assertUniquePreparedPaths(prepared);
280
320
  const noops = prepared.filter((item) => item.isNoop);
@@ -293,8 +333,43 @@ function createEditCwdScope(cwd, ops, hashlineStore) {
293
333
  }
294
334
  for (const item of prepared) {
295
335
  throwIfAborted(applySignal);
296
- if (normalizeToLF(stripBom(await fs.readText(item.section.path)).text) !== item.normalized)
297
- throw new Error(`Stale hashline tag for ${item.section.path}: file content changed before write. Re-read before editing.`);
336
+ let live;
337
+ try {
338
+ live = normalizeToLF(stripBom(await fs.readText(item.section.path)).text);
339
+ }
340
+ catch (error) {
341
+ // `prepare` already read this file, so a read failing now means the target changed
342
+ // state under the patch: deleted, replaced by a directory, locked, or rewritten as
343
+ // something this reader cannot parse. Those are all race outcomes rather than tool
344
+ // errors, and letting them escape as raw filesystem errors would hide that from
345
+ // every consumer that tells conflicts apart from ordinary tool failures.
346
+ const missing = isMissingTargetError(error);
347
+ const causeCode = filesystemErrorCode(error);
348
+ throw new FileMutationConflict({
349
+ reason: missing ? "target_missing" : "target_unreadable",
350
+ path: item.section.path,
351
+ // Queue registration resolved this before preparation. A new lookup may fail
352
+ // for the same reason as the read and mask the typed conflict.
353
+ canonicalKey: canonicalKeys.get(item.canonicalPath),
354
+ // Only the missing case can describe the target. Once a read fails for any
355
+ // other cause, its size and tag are unknowable and claiming either is invention.
356
+ ...(missing ? { liveState: computeLiveState(undefined) } : {}),
357
+ ...(causeCode ? { causeCode } : {}),
358
+ ...(requester ? { requester } : {}),
359
+ });
360
+ }
361
+ // Compared before calling the guard so the happy path skips the extra `realpath`
362
+ // that naming the target canonically costs. The guard still owns the rejection.
363
+ if (live !== item.normalized) {
364
+ assertLiveMatchesPrepared({
365
+ canonicalKey: await canonicalMutationKey(item.canonicalPath),
366
+ path: item.section.path,
367
+ prepared: item.normalized,
368
+ live,
369
+ ...(requester ? { requester } : {}),
370
+ ...(item.section.fileHash ? { presentedTag: item.section.fileHash } : {}),
371
+ });
372
+ }
298
373
  }
299
374
  const outputs = [];
300
375
  let combinedDiff = "", combinedPatch = "";
@@ -315,9 +390,13 @@ function createEditCwdScope(cwd, ops, hashlineStore) {
315
390
  (written.length > 0 ? ` Sections already written: ${written.join(", ")}.` : "") +
316
391
  (notWritten.length > 0 ? ` Sections not written: ${notWritten.join(", ")}.` : ""), { cause: error });
317
392
  }
318
- throwIfAborted(applySignal);
319
393
  invalidateNativeSearchCache(result.canonicalPath);
394
+ // Recorded before the abort check, not after. `commit` has already written, and since
395
+ // the patcher was made non-minting this call is the only writer of provenance, so
396
+ // aborting first would leave the session's own bytes on disk with nothing recorded
397
+ // for them. The next overwrite would then read as another agent's file.
320
398
  const snapshot = recordHashlineSnapshot(result.canonicalPath, cwd, result.after, hashlineStore);
399
+ throwIfAborted(applySignal);
321
400
  const diffResult = generateDiffString(result.before, result.after);
322
401
  combinedDiff += `${combinedDiff ? "\n" : ""}${diffResult.diff}`;
323
402
  combinedPatch += `${combinedPatch ? "\n" : ""}${generateUnifiedPatch(result.path, result.before, result.after)}`;
@@ -357,7 +436,7 @@ export function createEditToolDefinition(cwd, options) {
357
436
  promptGuidelines: [...editToolSystemPromptContribution.guidelines],
358
437
  constrainedSampling: { type: "json_schema", strict: "prefer" },
359
438
  parameters: editSchema,
360
- async execute(_toolCallId, input, signal, _onUpdate, ctx) {
439
+ async execute(toolCallId, input, signal, _onUpdate, ctx) {
361
440
  if (typeof input.input !== "string" || input.input.trim() === "")
362
441
  throw new Error("edit input must be a non-empty hashline script with [PATH#TAG] sections.");
363
442
  const executionCwd = ctx?.cwd || cwd;
@@ -371,13 +450,13 @@ export function createEditToolDefinition(cwd, options) {
371
450
  }
372
451
  const entry = batcher.announce(input.input, paths, signal);
373
452
  try {
374
- return await withFileMutationQueues([...paths.keys()].map((sectionPath) => fs.canonicalPath(sectionPath)), async () => {
453
+ return await withFileMutationQueues([...paths.keys()].map((sectionPath) => fs.canonicalPath(sectionPath)), async (canonicalKeys) => {
375
454
  if (entry.settled)
376
455
  return await entry.promise;
377
456
  throwIfAborted(signal);
378
457
  const siblings = batcher.takeCompatible(entry);
379
458
  try {
380
- const result = await applySiblingEdits(siblings, signal);
459
+ const result = await applySiblingEdits(siblings, canonicalKeys, signal, options?.resolveMutationRequester?.(toolCallId));
381
460
  for (const sibling of siblings)
382
461
  sibling.resolve(result);
383
462
  return result;