@astralyn/pi 1.4.1 → 1.4.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +14 -0
- package/dist/bundle/chunks/{chunk-N77PYEXG.js → chunk-ISXCH6TG.js} +1 -1
- package/dist/bundle/chunks/{chunk-KSKBY3VV.js → chunk-Z2YN4E74.js} +117 -111
- package/dist/bundle/chunks/{virtual-modules-XNEYDLXF.js → virtual-modules-QX6D3D7X.js} +1 -1
- package/dist/bundle/cli.js +1 -1
- package/dist/bundle/index.js +1 -1
- package/dist/bundle/rpc-entry.js +1 -1
- package/dist/core/agent-session.d.ts +15 -1
- package/dist/core/agent-session.d.ts.map +1 -1
- package/dist/core/agent-session.js +1 -8
- package/dist/core/agent-session.js.map +1 -1
- package/dist/core/extensions/distribution-api.d.ts +1 -1
- package/dist/core/extensions/distribution-api.d.ts.map +1 -1
- package/dist/core/extensions/distribution-api.js.map +1 -1
- package/dist/core/extensions/index.d.ts +2 -2
- package/dist/core/extensions/index.d.ts.map +1 -1
- package/dist/core/extensions/index.js.map +1 -1
- package/dist/core/extensions/runner.d.ts.map +1 -1
- package/dist/core/extensions/runner.js +3 -2
- package/dist/core/extensions/runner.js.map +1 -1
- package/dist/core/extensions/types.d.ts +29 -2
- package/dist/core/extensions/types.d.ts.map +1 -1
- package/dist/core/extensions/types.js.map +1 -1
- package/dist/core/keybinding-registry.d.ts +16 -1
- package/dist/core/keybinding-registry.d.ts.map +1 -1
- package/dist/core/keybinding-registry.js +20 -0
- package/dist/core/keybinding-registry.js.map +1 -1
- package/dist/core/keybindings-schema.d.ts.map +1 -1
- package/dist/core/keybindings-schema.js +2 -1
- package/dist/core/keybindings-schema.js.map +1 -1
- package/dist/core/keybindings.d.ts +4 -106
- package/dist/core/keybindings.d.ts.map +1 -1
- package/dist/core/keybindings.js +0 -13
- package/dist/core/keybindings.js.map +1 -1
- package/dist/core/slash-commands.d.ts.map +1 -1
- package/dist/core/slash-commands.js +0 -1
- package/dist/core/slash-commands.js.map +1 -1
- package/dist/core/tasks/format.d.ts.map +1 -1
- package/dist/core/tasks/format.js +10 -4
- package/dist/core/tasks/format.js.map +1 -1
- package/dist/core/tasks/limits.d.ts +5 -0
- package/dist/core/tasks/limits.d.ts.map +1 -0
- package/dist/core/tasks/limits.js +5 -0
- package/dist/core/tasks/limits.js.map +1 -0
- package/dist/core/tasks/runtime.d.ts +1 -0
- package/dist/core/tasks/runtime.d.ts.map +1 -1
- package/dist/core/tasks/runtime.js +7 -3
- package/dist/core/tasks/runtime.js.map +1 -1
- package/dist/core/tasks/session.d.ts +1 -1
- package/dist/core/tasks/session.d.ts.map +1 -1
- package/dist/core/tasks/session.js +10 -2
- package/dist/core/tasks/session.js.map +1 -1
- package/dist/core/tasks/types.d.ts +13 -0
- package/dist/core/tasks/types.d.ts.map +1 -1
- package/dist/core/tasks/types.js.map +1 -1
- package/dist/core/tools/bash.d.ts +98 -9
- package/dist/core/tools/bash.d.ts.map +1 -1
- package/dist/core/tools/bash.js +308 -11
- package/dist/core/tools/bash.js.map +1 -1
- package/dist/core/tools/index.d.ts +5 -4
- package/dist/core/tools/index.d.ts.map +1 -1
- package/dist/core/tools/index.js +3 -11
- package/dist/core/tools/index.js.map +1 -1
- package/dist/core/tools/powershell.d.ts +2 -1
- package/dist/core/tools/powershell.d.ts.map +1 -1
- package/dist/core/tools/powershell.js +2 -1
- package/dist/core/tools/powershell.js.map +1 -1
- package/dist/core/tools/renderers/bash.d.ts +1 -1
- package/dist/core/tools/renderers/bash.d.ts.map +1 -1
- package/dist/core/tools/renderers/bash.js.map +1 -1
- package/dist/core/tools/renderers/index.d.ts.map +1 -1
- package/dist/core/tools/renderers/index.js +7 -5
- package/dist/core/tools/renderers/index.js.map +1 -1
- package/dist/core/tools/shell-execution.d.ts +2 -2
- package/dist/core/tools/shell-execution.d.ts.map +1 -1
- package/dist/core/tools/shell-execution.js +0 -21
- package/dist/core/tools/shell-execution.js.map +1 -1
- package/dist/core/tools/shell-operations.d.ts +12 -0
- package/dist/core/tools/shell-operations.d.ts.map +1 -0
- package/dist/core/tools/shell-operations.js +38 -0
- package/dist/core/tools/shell-operations.js.map +1 -0
- package/dist/core/tools/shell-tool.d.ts +8 -64
- package/dist/core/tools/shell-tool.d.ts.map +1 -1
- package/dist/core/tools/shell-tool.js +27 -125
- package/dist/core/tools/shell-tool.js.map +1 -1
- package/dist/extensions/index.d.ts +1 -0
- package/dist/extensions/index.d.ts.map +1 -1
- package/dist/extensions/index.js +5 -0
- package/dist/extensions/index.js.map +1 -1
- package/dist/extensions/keybindings.d.ts +6 -0
- package/dist/extensions/keybindings.d.ts.map +1 -0
- package/dist/extensions/keybindings.js +6 -0
- package/dist/extensions/keybindings.js.map +1 -0
- package/dist/extensions/tasks/index.d.ts +5 -0
- package/dist/extensions/tasks/index.d.ts.map +1 -0
- package/dist/extensions/tasks/index.js +42 -0
- package/dist/extensions/tasks/index.js.map +1 -0
- package/dist/extensions/tasks/keybindings.d.ts +19 -0
- package/dist/extensions/tasks/keybindings.d.ts.map +1 -0
- package/dist/extensions/tasks/keybindings.js +30 -0
- package/dist/extensions/tasks/keybindings.js.map +1 -0
- package/dist/{core/tools/tasks → extensions/tasks/tool}/actions.d.ts +2 -2
- package/dist/extensions/tasks/tool/actions.d.ts.map +1 -0
- package/dist/{core/tools/tasks → extensions/tasks/tool}/actions.js +4 -4
- package/dist/extensions/tasks/tool/actions.js.map +1 -0
- package/dist/{core/tools/tasks → extensions/tasks/tool}/constants.d.ts +1 -3
- package/dist/extensions/tasks/tool/constants.d.ts.map +1 -0
- package/dist/{core/tools/tasks → extensions/tasks/tool}/constants.js +1 -3
- package/dist/extensions/tasks/tool/constants.js.map +1 -0
- package/dist/extensions/tasks/tool/schema.d.ts.map +1 -0
- package/dist/{core/tools/tasks → extensions/tasks/tool}/schema.js +5 -4
- package/dist/extensions/tasks/tool/schema.js.map +1 -0
- package/dist/{core/tools/tasks → extensions/tasks/tool}/types.d.ts +1 -1
- package/dist/extensions/tasks/tool/types.d.ts.map +1 -0
- package/dist/extensions/tasks/tool/types.js.map +1 -0
- package/dist/extensions/tasks/tool.d.ts +6 -0
- package/dist/extensions/tasks/tool.d.ts.map +1 -0
- package/dist/{core/tools/tasks.js → extensions/tasks/tool.js} +6 -10
- package/dist/extensions/tasks/tool.js.map +1 -0
- package/dist/{modes/interactive/tasks → extensions/tasks/ui}/completion-render.d.ts +1 -1
- package/dist/extensions/tasks/ui/completion-render.d.ts.map +1 -0
- package/dist/{modes/interactive/tasks → extensions/tasks/ui}/completion-render.js +2 -2
- package/dist/extensions/tasks/ui/completion-render.js.map +1 -0
- package/dist/{modes/interactive/tasks → extensions/tasks/ui}/index.d.ts +1 -1
- package/dist/extensions/tasks/ui/index.d.ts.map +1 -0
- package/dist/{modes/interactive/tasks → extensions/tasks/ui}/index.js +4 -4
- package/dist/extensions/tasks/ui/index.js.map +1 -0
- package/dist/{modes/interactive/tasks → extensions/tasks/ui}/inspector.d.ts +1 -1
- package/dist/extensions/tasks/ui/inspector.d.ts.map +1 -0
- package/dist/extensions/tasks/ui/inspector.js.map +1 -0
- package/dist/{modes/interactive/tasks → extensions/tasks/ui}/layout.d.ts +1 -1
- package/dist/extensions/tasks/ui/layout.d.ts.map +1 -0
- package/dist/{modes/interactive/tasks → extensions/tasks/ui}/layout.js +1 -1
- package/dist/extensions/tasks/ui/layout.js.map +1 -0
- package/dist/{modes/interactive/tasks → extensions/tasks/ui}/list.d.ts +1 -1
- package/dist/extensions/tasks/ui/list.d.ts.map +1 -0
- package/dist/{modes/interactive/tasks → extensions/tasks/ui}/list.js +1 -1
- package/dist/extensions/tasks/ui/list.js.map +1 -0
- package/dist/{modes/interactive/tasks → extensions/tasks/ui}/manager.d.ts +2 -1
- package/dist/extensions/tasks/ui/manager.d.ts.map +1 -0
- package/dist/{modes/interactive/tasks → extensions/tasks/ui}/manager.js +2 -1
- package/dist/extensions/tasks/ui/manager.js.map +1 -0
- package/dist/extensions/tasks/ui/model.d.ts.map +1 -0
- package/dist/extensions/tasks/ui/model.js.map +1 -0
- package/dist/{modes/interactive/tasks → extensions/tasks/ui}/render.d.ts +3 -3
- package/dist/extensions/tasks/ui/render.d.ts.map +1 -0
- package/dist/{modes/interactive/tasks → extensions/tasks/ui}/render.js +2 -2
- package/dist/extensions/tasks/ui/render.js.map +1 -0
- package/dist/{modes/interactive/tasks → extensions/tasks/ui}/task-view.d.ts +1 -1
- package/dist/extensions/tasks/ui/task-view.d.ts.map +1 -0
- package/dist/{modes/interactive/tasks → extensions/tasks/ui}/task-view.js +1 -1
- package/dist/extensions/tasks/ui/task-view.js.map +1 -0
- package/dist/extensions/tasks/ui/text.d.ts.map +1 -0
- package/dist/extensions/tasks/ui/text.js.map +1 -0
- package/dist/extensions/tasks/ui/tree.d.ts +7 -0
- package/dist/extensions/tasks/ui/tree.d.ts.map +1 -0
- package/dist/{modes/interactive/tasks/host-hooks.js → extensions/tasks/ui/tree.js} +1 -18
- package/dist/extensions/tasks/ui/tree.js.map +1 -0
- package/dist/extensions/tasks/ui/viewport.d.ts.map +1 -0
- package/dist/extensions/tasks/ui/viewport.js.map +1 -0
- package/dist/{modes/interactive/tasks → extensions/tasks/ui}/views.d.ts +1 -1
- package/dist/extensions/tasks/ui/views.d.ts.map +1 -0
- package/dist/{modes/interactive/tasks → extensions/tasks/ui}/views.js +1 -1
- package/dist/extensions/tasks/ui/views.js.map +1 -0
- package/dist/extensions/tool-presentation/index.d.ts +7 -0
- package/dist/extensions/tool-presentation/index.d.ts.map +1 -0
- package/dist/extensions/tool-presentation/index.js +9 -0
- package/dist/extensions/tool-presentation/index.js.map +1 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/modes/interactive/components/assistant-message.d.ts +3 -2
- package/dist/modes/interactive/components/assistant-message.d.ts.map +1 -1
- package/dist/modes/interactive/components/assistant-message.js +65 -18
- package/dist/modes/interactive/components/assistant-message.js.map +1 -1
- package/dist/modes/interactive/components/custom-message.d.ts.map +1 -1
- package/dist/modes/interactive/components/custom-message.js +1 -3
- package/dist/modes/interactive/components/custom-message.js.map +1 -1
- package/dist/modes/interactive/components/index.d.ts +1 -1
- package/dist/modes/interactive/components/index.d.ts.map +1 -1
- package/dist/modes/interactive/components/index.js +1 -1
- package/dist/modes/interactive/components/index.js.map +1 -1
- package/dist/modes/interactive/components/tool-execution.d.ts +85 -0
- package/dist/modes/interactive/components/tool-execution.d.ts.map +1 -0
- package/dist/modes/interactive/components/tool-execution.js +362 -0
- package/dist/modes/interactive/components/tool-execution.js.map +1 -0
- package/dist/modes/interactive/interactive-mode.d.ts +5 -3
- package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode.js +14 -29
- package/dist/modes/interactive/interactive-mode.js.map +1 -1
- package/dist/modes/interactive/tool-view/chat.d.ts +1 -1
- package/dist/modes/interactive/tool-view/chat.d.ts.map +1 -1
- package/dist/modes/interactive/tool-view/chat.js +2 -3
- package/dist/modes/interactive/tool-view/chat.js.map +1 -1
- package/dist/modes/interactive/tool-view/shell.d.ts +15 -0
- package/dist/modes/interactive/tool-view/shell.d.ts.map +1 -0
- package/dist/modes/interactive/tool-view/shell.js +51 -0
- package/dist/modes/interactive/tool-view/shell.js.map +1 -0
- package/dist/modes/interactive/tool-view/tool-execution.d.ts +10 -79
- package/dist/modes/interactive/tool-view/tool-execution.d.ts.map +1 -1
- package/dist/modes/interactive/tool-view/tool-execution.js +7 -298
- package/dist/modes/interactive/tool-view/tool-execution.js.map +1 -1
- package/docs/bundled/README.md +1 -4
- package/docs/bundled/tasks.md +3 -3
- package/docs/bundled/tool-presentation.md +9 -7
- package/docs/extensions.md +9 -4
- package/docs/settings.md +1 -1
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
- package/schemas/keybindings.schema.json +84 -52
- package/dist/core/tools/tasks/actions.d.ts.map +0 -1
- package/dist/core/tools/tasks/actions.js.map +0 -1
- package/dist/core/tools/tasks/constants.d.ts.map +0 -1
- package/dist/core/tools/tasks/constants.js.map +0 -1
- package/dist/core/tools/tasks/schema.d.ts.map +0 -1
- package/dist/core/tools/tasks/schema.js.map +0 -1
- package/dist/core/tools/tasks/types.d.ts.map +0 -1
- package/dist/core/tools/tasks/types.js.map +0 -1
- package/dist/core/tools/tasks.d.ts +0 -14
- package/dist/core/tools/tasks.d.ts.map +0 -1
- package/dist/core/tools/tasks.js.map +0 -1
- package/dist/modes/interactive/tasks/completion-render.d.ts.map +0 -1
- package/dist/modes/interactive/tasks/completion-render.js.map +0 -1
- package/dist/modes/interactive/tasks/host-hooks.d.ts +0 -14
- package/dist/modes/interactive/tasks/host-hooks.d.ts.map +0 -1
- package/dist/modes/interactive/tasks/host-hooks.js.map +0 -1
- package/dist/modes/interactive/tasks/index.d.ts.map +0 -1
- package/dist/modes/interactive/tasks/index.js.map +0 -1
- package/dist/modes/interactive/tasks/inspector.d.ts.map +0 -1
- package/dist/modes/interactive/tasks/inspector.js.map +0 -1
- package/dist/modes/interactive/tasks/layout.d.ts.map +0 -1
- package/dist/modes/interactive/tasks/layout.js.map +0 -1
- package/dist/modes/interactive/tasks/list.d.ts.map +0 -1
- package/dist/modes/interactive/tasks/list.js.map +0 -1
- package/dist/modes/interactive/tasks/manager.d.ts.map +0 -1
- package/dist/modes/interactive/tasks/manager.js.map +0 -1
- package/dist/modes/interactive/tasks/model.d.ts.map +0 -1
- package/dist/modes/interactive/tasks/model.js.map +0 -1
- package/dist/modes/interactive/tasks/render.d.ts.map +0 -1
- package/dist/modes/interactive/tasks/render.js.map +0 -1
- package/dist/modes/interactive/tasks/task-view.d.ts.map +0 -1
- package/dist/modes/interactive/tasks/task-view.js.map +0 -1
- package/dist/modes/interactive/tasks/text.d.ts.map +0 -1
- package/dist/modes/interactive/tasks/text.js.map +0 -1
- package/dist/modes/interactive/tasks/viewport.d.ts.map +0 -1
- package/dist/modes/interactive/tasks/viewport.js.map +0 -1
- package/dist/modes/interactive/tasks/views.d.ts.map +0 -1
- package/dist/modes/interactive/tasks/views.js.map +0 -1
- /package/dist/{core/tools/tasks → extensions/tasks/tool}/schema.d.ts +0 -0
- /package/dist/{core/tools/tasks → extensions/tasks/tool}/types.js +0 -0
- /package/dist/{modes/interactive/tasks → extensions/tasks/ui}/inspector.js +0 -0
- /package/dist/{modes/interactive/tasks → extensions/tasks/ui}/model.d.ts +0 -0
- /package/dist/{modes/interactive/tasks → extensions/tasks/ui}/model.js +0 -0
- /package/dist/{modes/interactive/tasks → extensions/tasks/ui}/text.d.ts +0 -0
- /package/dist/{modes/interactive/tasks → extensions/tasks/ui}/text.js +0 -0
- /package/dist/{modes/interactive/tasks → extensions/tasks/ui}/viewport.d.ts +0 -0
- /package/dist/{modes/interactive/tasks → extensions/tasks/ui}/viewport.js +0 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"powershell.js","sourceRoot":"","sources":["../../../src/core/tools/powershell.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAC3D,OAAO,
|
|
1
|
+
{"version":3,"file":"powershell.js","sourceRoot":"","sources":["../../../src/core/tools/powershell.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAC3D,OAAO,EAKN,0BAA0B,GAE1B,MAAM,WAAW,CAAC;AACnB,OAAO,EAA4C,yBAAyB,EAAE,MAAM,iBAAiB,CAAC;AACtG,OAAO,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAC;AAElE,MAAM,kBAAkB,GAAG,2EAA2E,CAAC;AAEvG,MAAM,CAAC,MAAM,sCAAsC,GAAG;IACrD,OAAO,EAAE,uDAAuD;IAChE,UAAU,EAAE,CAAC,mFAAmF,CAAC;CACxF,CAAC;AAWX,MAAM,UAAU,+BAA+B;IAC9C,MAAM,UAAU,GAAG,0BAA0B,CAAC,YAAY,EAAE,mBAAmB,CAAC,CAAC;IACjF,OAAO;QACN,IAAI,EAAE,CAAC,OAAO,EAAE,GAAG,EAAE,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,GAAG,kBAAkB,GAAG,OAAO,EAAE,EAAE,GAAG,EAAE,OAAO,CAAC;KACjG,CAAC;AACH,CAAC;AAED,MAAM,oBAAoB,GAAoB;IAC7C,IAAI,EAAE,YAAY;IAClB,KAAK,EAAE,YAAY;IACnB,SAAS,EAAE,YAAY;IACvB,MAAM,EAAE,KAAK;IACb,aAAa,EAAE,sCAAsC,CAAC,OAAO;IAC7D,gBAAgB,EAAE,sCAAsC,CAAC,UAAU;IACnE,cAAc,EAAE,eAAe;CAC/B,CAAC;AAEF,MAAM,UAAU,8BAA8B,CAC7C,GAAW,EACX,OAA+B;IAE/B,OAAO,yBAAyB,CAAC,GAAG,EAAE,oBAAoB,EAAE;QAC3D,GAAG,OAAO;QACV,UAAU,EAAE,OAAO,EAAE,UAAU,IAAI,+BAA+B,EAAE;KACpE,CAAC,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,oBAAoB,CAAC,GAAW,EAAE,OAA+B;IAChF,MAAM,UAAU,GAAG,8BAA8B,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;IAChE,MAAM,IAAI,GAAG,kBAAkB,CAAC,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 { getPowerShellConfig } from \"../../utils/shell.ts\";\nimport {\n\ttype BashOperations,\n\ttype BashSpawnContext,\n\ttype BashSpawnHook,\n\ttype BashToolOptions,\n\tcreateLocalShellOperations,\n\ttype ShellToolConfig,\n} from \"./bash.ts\";\nimport { type BashToolDetails, type BashToolInput, createShellToolDefinition } from \"./shell-tool.ts\";\nimport { wrapToolDefinition } from \"./tool-definition-wrapper.ts\";\n\nconst UTF8_OUTPUT_PREFIX = \"try { [Console]::OutputEncoding=[System.Text.Encoding]::UTF8 } catch {}\\n\";\n\nexport const powershellToolSystemPromptContribution = {\n\tsnippet: \"Execute PowerShell commands, foreground or background\",\n\tguidelines: [\"You can inspect PI_* environment variables for current model and session details.\"],\n} as const;\n\nexport type PowerShellOperations = BashOperations;\nexport type PowerShellSpawnContext = BashSpawnContext;\nexport type PowerShellSpawnHook = BashSpawnHook;\nexport type PowerShellToolDetails = BashToolDetails;\nexport type PowerShellToolInput = BashToolInput;\n\nexport interface PowerShellToolOptions\n\textends Pick<BashToolOptions, \"operations\" | \"exposeSessionEnvironment\" | \"spawnHook\"> {}\n\nexport function createLocalPowerShellOperations(): PowerShellOperations {\n\tconst operations = createLocalShellOperations(\"PowerShell\", getPowerShellConfig);\n\treturn {\n\t\texec: (command, cwd, options) => operations.exec(`${UTF8_OUTPUT_PREFIX}${command}`, cwd, options),\n\t};\n}\n\nconst powershellToolConfig: ShellToolConfig = {\n\tname: \"powershell\",\n\tlabel: \"powershell\",\n\tshellName: \"PowerShell\",\n\tprompt: \"PS>\",\n\tpromptSnippet: powershellToolSystemPromptContribution.snippet,\n\tpromptGuidelines: powershellToolSystemPromptContribution.guidelines,\n\ttempFilePrefix: \"pi-powershell\",\n};\n\nexport function createPowerShellToolDefinition(\n\tcwd: string,\n\toptions?: PowerShellToolOptions,\n): ReturnType<typeof createShellToolDefinition> {\n\treturn createShellToolDefinition(cwd, powershellToolConfig, {\n\t\t...options,\n\t\toperations: options?.operations ?? createLocalPowerShellOperations(),\n\t});\n}\n\nexport function createPowerShellTool(cwd: string, options?: PowerShellToolOptions) {\n\tconst definition = createPowerShellToolDefinition(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"]}
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* tool definition, so the tool's public shape is unchanged.
|
|
7
7
|
*/
|
|
8
8
|
import type { ToolDefinition } from "../../extensions/types.ts";
|
|
9
|
-
import type { ShellToolConfig } from "../
|
|
9
|
+
import type { ShellToolConfig } from "../bash.ts";
|
|
10
10
|
export declare const BASH_UPDATE_THROTTLE_MS = 100;
|
|
11
11
|
/** Shell renderers are shared by bash and powershell, which differ in the prompt and highlight language. */
|
|
12
12
|
export declare function createShellRenderers(config: Pick<ShellToolConfig, "name" | "prompt">): Pick<ToolDefinition<any, any>, "renderCall" | "renderResult">;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bash.d.ts","sourceRoot":"","sources":["../../../../src/core/tools/renderers/bash.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAMH,OAAO,KAAK,EAAE,cAAc,EAA8C,MAAM,2BAA2B,CAAC;
|
|
1
|
+
{"version":3,"file":"bash.d.ts","sourceRoot":"","sources":["../../../../src/core/tools/renderers/bash.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAMH,OAAO,KAAK,EAAE,cAAc,EAA8C,MAAM,2BAA2B,CAAC;AAC5G,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAMlD,eAAO,MAAM,uBAAuB,MAAM,CAAC;AAqM3C,4GAA4G;AAC5G,wBAAgB,oBAAoB,CACnC,MAAM,EAAE,IAAI,CAAC,eAAe,EAAE,MAAM,GAAG,QAAQ,CAAC,GAC9C,IAAI,CAAC,cAAc,CAAC,GAAG,EAAE,GAAG,CAAC,EAAE,YAAY,GAAG,cAAc,CAAC,CAmB/D"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bash.js","sourceRoot":"","sources":["../../../../src/core/tools/renderers/bash.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAkB,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,eAAe,EAAE,YAAY,EAAE,M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C5D,MAAM,SAAS,GAAI,OAAO,CAAC,aAAuC,IAAI,IAAI,SAAS,EAAE,CAAC;YACtF,MAAM,SAAS,GAAI,OAAO,CAAC,IAA6C,EAAE,UAAU,KAAK,IAAI,CAAC;YAC9F,gCAAgC,CAAC,SAAS,EAAE,MAAa,EAAE,OAAO,EAAE,OAAO,CAAC,UAAU,EAAE,SAAS,EAAE,SAAS,CAAC,CAAC;YAC9G,SAAS,CAAC,UAAU,EAAE,CAAC;YACvB,OAAO,SAAS,CAAC;QAClB,CAAC;KACD,CAAC;AACH,CAAC","sourcesContent":["/**\n * Presentation for the shell tools.\n *\n * Renderers live apart from the implementation so a process that only displays tool output does not\n * load the execution path or its typebox parameter schema. `bash.ts` spreads these into the shell\n * tool definition, so the tool's public shape is unchanged.\n */\n\nimport { type Component, Container, Spacer, Text, truncateToWidth, visibleWidth } from \"@earendil-works/pi-tui\";\nimport { keyHint } from \"../../../modes/interactive/components/keybinding-hints.ts\";\nimport { VisualLinePreview } from \"../../../modes/interactive/components/visual-truncate.ts\";\nimport { highlightCode, theme } from \"../../../modes/interactive/theme/theme.ts\";\nimport type { ToolDefinition, ToolRenderContext, ToolRenderResultOptions } from \"../../extensions/types.ts\";\nimport { getTextOutput, invalidArgText, startToolTimer, str, toolTimerText } from \"../render-utils.ts\";\nimport type { BashRenderState, BashToolDetails, ShellToolConfig } from \"../shell-tool.ts\";\nimport { DEFAULT_MAX_BYTES, formatSize } from \"../truncate.ts\";\n\nconst BASH_PREVIEW_LINES = 5;\nexport const BASH_UPDATE_THROTTLE_MS = 100;\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: Pick<ShellToolConfig, \"name\" | \"prompt\">;\n\n\tconstructor(config: Pick<ShellToolConfig, \"name\" | \"prompt\">) {\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\nconst shellTimerHooked = Symbol(\"shellTimerHooked\");\ntype ShellTimerState = BashRenderState & {\n\tinterval?: ReturnType<typeof setInterval>;\n\t[shellTimerHooked]?: true;\n};\n\n/**\n * Start the row's clock and hook disposal once. Either slot can initialize timing, since\n * extensions may replace the other slot; upstream's timer state outlives a replaced slot, but\n * its refresh interval must still end when the row is disposed mid-run.\n */\nfunction ensureShellTimer(context: ToolRenderContext<ShellTimerState>): void {\n\tstartToolTimer(context);\n\tconst state = context.state;\n\tif (state[shellTimerHooked]) return;\n\tstate[shellTimerHooked] = true;\n\tconst previousDispose = state.dispose;\n\tstate.dispose = () => {\n\t\ttry {\n\t\t\tpreviousDispose?.call(state);\n\t\t} finally {\n\t\t\tclearInterval(state.interval);\n\t\t\tstate.interval = undefined;\n\t\t}\n\t};\n}\n\nfunction formatShellPrompt(prompt: string): string {\n\treturn theme.fg(\"toolTitle\", theme.bold(`${prompt} `));\n}\nfunction formatShellTimeout(timeout: number | undefined): string {\n\treturn timeout ? theme.fg(\"muted\", ` (timeout ${timeout}s)`) : \"\";\n}\nfunction styleShellCommand(command: string, config: Pick<ShellToolConfig, \"name\" | \"prompt\">): string {\n\tconst language = config.name === \"powershell\" ? \"powershell\" : \"bash\";\n\treturn highlightCode(command, language).join(\"\\n\");\n}\nfunction formatFullShellCall(\n\tcommand: string | null,\n\ttimeout: number | undefined,\n\tconfig: Pick<ShellToolConfig, \"name\" | \"prompt\">,\n): 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}\nfunction fitCollapsedShellCall(\n\tbody: string,\n\ttimeout: number | undefined,\n\twidth: number,\n\tsuffix: string,\n\tconfig: Pick<ShellToolConfig, \"name\" | \"prompt\">,\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}\nfunction formatTruncatedShellCall(\n\tcommand: string | null,\n\ttimeout: number | undefined,\n\twidth: number,\n\tconfig: Pick<ShellToolConfig, \"name\" | \"prompt\">,\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}\nfunction rebuildBashResultRenderComponent(\n\tcomponent: Container,\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\ttimerText: string | undefined,\n\tsubmittedAsBackground: boolean,\n): void {\n\tcomponent.clear();\n\n\tconst background = result.details?.background;\n\tlet output =\n\t\tbackground?.kind === \"background\"\n\t\t\t? `${submittedAsBackground ? \"Running in the background\" : \"Moved to background\"} · ${background.taskId}`\n\t\t\t: 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(new Spacer(1));\n\t\t\tcomponent.addChild(\n\t\t\t\tnew VisualLinePreview({\n\t\t\t\t\ttext: styledOutput,\n\t\t\t\t\tmaxVisualLines: BASH_PREVIEW_LINES,\n\t\t\t\t\tkeep: \"end\",\n\t\t\t\t\tformatHint: (hidden) =>\n\t\t\t\t\t\ttheme.fg(\"muted\", `... (${hidden} earlier lines,`) +\n\t\t\t\t\t\t` ${keyHint(\"app.tools.expand\", \"to expand\")}${theme.fg(\"muted\", \")\")}`,\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\tif (timerText) component.addChild(new Text(`\\n${theme.fg(\"muted\", timerText)}`, 0, 0));\n}\n\n/** Shell renderers are shared by bash and powershell, which differ in the prompt and highlight language. */\nexport function createShellRenderers(\n\tconfig: Pick<ShellToolConfig, \"name\" | \"prompt\">,\n): Pick<ToolDefinition<any, any>, \"renderCall\" | \"renderResult\"> {\n\treturn {\n\t\trenderCall(args, _theme, context) {\n\t\t\tensureShellTimer(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 as { command?: string; timeout?: number } | undefined, context.expanded);\n\t\t\treturn component;\n\t\t},\n\t\trenderResult(result, options, _theme, context) {\n\t\t\tensureShellTimer(context);\n\t\t\tconst timerText = toolTimerText(context, options.isPartial);\n\t\t\tconst component = (context.lastComponent as Container | undefined) ?? new Container();\n\t\t\tconst submitted = (context.args as { background?: boolean } | undefined)?.background === true;\n\t\t\trebuildBashResultRenderComponent(component, result as any, options, context.showImages, timerText, submitted);\n\t\t\tcomponent.invalidate();\n\t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;YAC/F,OAAO,SAAS,CAAC;QAClB,CAAC;QACD,YAAY,CAAC,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO;YAC5C,gBAAgB,CAAC,OAAO,CAAC,CAAC;YAC1B,MAAM,SAAS,GAAG,aAAa,CAAC,OAAO,EAAE,OAAO,CAAC,SAAS,CAAC,CAAC;YAC5D,MAAM,SAAS,GAAI,OAAO,CAAC,aAAuC,IAAI,IAAI,SAAS,EAAE,CAAC;YACtF,MAAM,SAAS,GAAI,OAAO,CAAC,IAA6C,EAAE,UAAU,KAAK,IAAI,CAAC;YAC9F,gCAAgC,CAAC,SAAS,EAAE,MAAa,EAAE,OAAO,EAAE,OAAO,CAAC,UAAU,EAAE,SAAS,EAAE,SAAS,CAAC,CAAC;YAC9G,SAAS,CAAC,UAAU,EAAE,CAAC;YACvB,OAAO,SAAS,CAAC;QAClB,CAAC;KACD,CAAC;AACH,CAAC","sourcesContent":["/**\n * Presentation for the shell tools.\n *\n * Renderers live apart from the implementation so a process that only displays tool output does not\n * load the execution path or its typebox parameter schema. `bash.ts` spreads these into the shell\n * tool definition, so the tool's public shape is unchanged.\n */\n\nimport { type Component, Container, Spacer, Text, truncateToWidth, visibleWidth } from \"@earendil-works/pi-tui\";\nimport { keyHint } from \"../../../modes/interactive/components/keybinding-hints.ts\";\nimport { VisualLinePreview } from \"../../../modes/interactive/components/visual-truncate.ts\";\nimport { highlightCode, theme } from \"../../../modes/interactive/theme/theme.ts\";\nimport type { ToolDefinition, ToolRenderContext, ToolRenderResultOptions } from \"../../extensions/types.ts\";\nimport type { ShellToolConfig } from \"../bash.ts\";\nimport { getTextOutput, invalidArgText, startToolTimer, str, toolTimerText } from \"../render-utils.ts\";\nimport type { BashRenderState, BashToolDetails } from \"../shell-tool.ts\";\nimport { DEFAULT_MAX_BYTES, formatSize } from \"../truncate.ts\";\n\nconst BASH_PREVIEW_LINES = 5;\nexport const BASH_UPDATE_THROTTLE_MS = 100;\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: Pick<ShellToolConfig, \"name\" | \"prompt\">;\n\n\tconstructor(config: Pick<ShellToolConfig, \"name\" | \"prompt\">) {\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\nconst shellTimerHooked = Symbol(\"shellTimerHooked\");\ntype ShellTimerState = BashRenderState & {\n\tinterval?: ReturnType<typeof setInterval>;\n\t[shellTimerHooked]?: true;\n};\n\n/**\n * Start the row's clock and hook disposal once. Either slot can initialize timing, since\n * extensions may replace the other slot; upstream's timer state outlives a replaced slot, but\n * its refresh interval must still end when the row is disposed mid-run.\n */\nfunction ensureShellTimer(context: ToolRenderContext<ShellTimerState>): void {\n\tstartToolTimer(context);\n\tconst state = context.state;\n\tif (state[shellTimerHooked]) return;\n\tstate[shellTimerHooked] = true;\n\tconst previousDispose = state.dispose;\n\tstate.dispose = () => {\n\t\ttry {\n\t\t\tpreviousDispose?.call(state);\n\t\t} finally {\n\t\t\tclearInterval(state.interval);\n\t\t\tstate.interval = undefined;\n\t\t}\n\t};\n}\n\nfunction formatShellPrompt(prompt: string): string {\n\treturn theme.fg(\"toolTitle\", theme.bold(`${prompt} `));\n}\nfunction formatShellTimeout(timeout: number | undefined): string {\n\treturn timeout ? theme.fg(\"muted\", ` (timeout ${timeout}s)`) : \"\";\n}\nfunction styleShellCommand(command: string, config: Pick<ShellToolConfig, \"name\" | \"prompt\">): string {\n\tconst language = config.name === \"powershell\" ? \"powershell\" : \"bash\";\n\treturn highlightCode(command, language).join(\"\\n\");\n}\nfunction formatFullShellCall(\n\tcommand: string | null,\n\ttimeout: number | undefined,\n\tconfig: Pick<ShellToolConfig, \"name\" | \"prompt\">,\n): 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}\nfunction fitCollapsedShellCall(\n\tbody: string,\n\ttimeout: number | undefined,\n\twidth: number,\n\tsuffix: string,\n\tconfig: Pick<ShellToolConfig, \"name\" | \"prompt\">,\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}\nfunction formatTruncatedShellCall(\n\tcommand: string | null,\n\ttimeout: number | undefined,\n\twidth: number,\n\tconfig: Pick<ShellToolConfig, \"name\" | \"prompt\">,\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}\nfunction rebuildBashResultRenderComponent(\n\tcomponent: Container,\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\ttimerText: string | undefined,\n\tsubmittedAsBackground: boolean,\n): void {\n\tcomponent.clear();\n\n\tconst background = result.details?.background;\n\tlet output =\n\t\tbackground?.kind === \"background\"\n\t\t\t? `${submittedAsBackground ? \"Running in the background\" : \"Moved to background\"} · ${background.taskId}`\n\t\t\t: 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(new Spacer(1));\n\t\t\tcomponent.addChild(\n\t\t\t\tnew VisualLinePreview({\n\t\t\t\t\ttext: styledOutput,\n\t\t\t\t\tmaxVisualLines: BASH_PREVIEW_LINES,\n\t\t\t\t\tkeep: \"end\",\n\t\t\t\t\tformatHint: (hidden) =>\n\t\t\t\t\t\ttheme.fg(\"muted\", `... (${hidden} earlier lines,`) +\n\t\t\t\t\t\t` ${keyHint(\"app.tools.expand\", \"to expand\")}${theme.fg(\"muted\", \")\")}`,\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\tif (timerText) component.addChild(new Text(`\\n${theme.fg(\"muted\", timerText)}`, 0, 0));\n}\n\n/** Shell renderers are shared by bash and powershell, which differ in the prompt and highlight language. */\nexport function createShellRenderers(\n\tconfig: Pick<ShellToolConfig, \"name\" | \"prompt\">,\n): Pick<ToolDefinition<any, any>, \"renderCall\" | \"renderResult\"> {\n\treturn {\n\t\trenderCall(args, _theme, context) {\n\t\t\tensureShellTimer(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 as { command?: string; timeout?: number } | undefined, context.expanded);\n\t\t\treturn component;\n\t\t},\n\t\trenderResult(result, options, _theme, context) {\n\t\t\tensureShellTimer(context);\n\t\t\tconst timerText = toolTimerText(context, options.isPartial);\n\t\t\tconst component = (context.lastComponent as Container | undefined) ?? new Container();\n\t\t\tconst submitted = (context.args as { background?: boolean } | undefined)?.background === true;\n\t\t\trebuildBashResultRenderComponent(component, result as any, options, context.showImages, timerText, submitted);\n\t\t\tcomponent.invalidate();\n\t\t\treturn component;\n\t\t},\n\t};\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/core/tools/renderers/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/core/tools/renderers/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAC/D,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,oBAAoB,EAAE,MAAM,WAAW,CAAC;AACjD,OAAO,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AACtC,OAAO,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAE5C,YAAY,EAAE,aAAa,EAAE,CAAC;AAE9B,OAAO,EACN,oBAAoB,EACpB,aAAa,EACb,aAAa,EACb,aAAa,EACb,WAAW,EACX,aAAa,EACb,cAAc,GACd,CAAC;AAEF,6DAA6D;AAC7D,wBAAgB,sBAAsB,IAAI,MAAM,CAAC,QAAQ,EAAE,aAAa,CAAC,CAWxE;AAED;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAAC,WAAW,SAAS,aAAa,EACrE,QAAQ,EAAE,MAAM,EAChB,UAAU,EAAE,WAAW,GAAG,SAAS,GACjC,WAAW,GAAG,aAAa,GAAG,SAAS,CASzC"}
|
|
@@ -1,4 +1,10 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Built-in tool renderers, without the tools themselves.
|
|
3
|
+
*
|
|
4
|
+
* A presentation displays tool calls and results; it does not execute them and does not need their
|
|
5
|
+
* typebox parameter schemas. Importing this instead of `core/tools/index.ts` keeps ~17 MB of module
|
|
6
|
+
* graph out of a process that only renders.
|
|
7
|
+
*/
|
|
2
8
|
import { createShellRenderers } from "./bash.js";
|
|
3
9
|
import { editRenderers } from "./edit.js";
|
|
4
10
|
import { findRenderers } from "./find.js";
|
|
@@ -10,10 +16,6 @@ export { createShellRenderers, editRenderers, findRenderers, grepRenderers, lsRe
|
|
|
10
16
|
/** Renderers for every built-in tool, keyed by tool name. */
|
|
11
17
|
export function createAllToolRenderers() {
|
|
12
18
|
return {
|
|
13
|
-
tasks: {
|
|
14
|
-
renderCall: (args, theme, context) => renderTasksCall(args, theme, context),
|
|
15
|
-
renderResult: renderTasksResult,
|
|
16
|
-
},
|
|
17
19
|
read: readRenderers,
|
|
18
20
|
bash: createShellRenderers({ name: "bash", prompt: "$" }),
|
|
19
21
|
powershell: createShellRenderers({ name: "powershell", prompt: "PS>" }),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/core/tools/renderers/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/core/tools/renderers/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAIH,OAAO,EAAE,oBAAoB,EAAE,MAAM,WAAW,CAAC;AACjD,OAAO,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AACtC,OAAO,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAI5C,OAAO,EACN,oBAAoB,EACpB,aAAa,EACb,aAAa,EACb,aAAa,EACb,WAAW,EACX,aAAa,EACb,cAAc,GACd,CAAC;AAEF,6DAA6D;AAC7D,MAAM,UAAU,sBAAsB;IACrC,OAAO;QACN,IAAI,EAAE,aAAa;QACnB,IAAI,EAAE,oBAAoB,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC;QACzD,UAAU,EAAE,oBAAoB,CAAC,EAAE,IAAI,EAAE,YAAY,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC;QACvE,IAAI,EAAE,aAAa;QACnB,KAAK,EAAE,cAAc;QACrB,IAAI,EAAE,aAAa;QACnB,IAAI,EAAE,aAAa;QACnB,EAAE,EAAE,WAAW;KACf,CAAC;AACH,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,oBAAoB,CACnC,QAAgB,EAChB,UAAmC;IAEnC,MAAM,OAAO,GAAG,sBAAsB,EAAE,CAAC,QAAoB,CAAC,CAAC;IAC/D,IAAI,CAAC,UAAU;QAAE,OAAO,OAAO,CAAC;IAChC,IAAI,CAAC,OAAO;QAAE,OAAO,UAAU,CAAC;IAChC,OAAO;QACN,GAAG,UAAU;QACb,UAAU,EAAE,UAAU,CAAC,UAAU,IAAI,OAAO,CAAC,UAAU;QACvD,YAAY,EAAE,UAAU,CAAC,YAAY,IAAI,OAAO,CAAC,YAAY;KAC7D,CAAC;AACH,CAAC","sourcesContent":["/**\n * Built-in tool renderers, without the tools themselves.\n *\n * A presentation displays tool calls and results; it does not execute them and does not need their\n * typebox parameter schemas. Importing this instead of `core/tools/index.ts` keeps ~17 MB of module\n * graph out of a process that only renders.\n */\n\nimport type { ToolRenderers } from \"../../extensions/types.ts\";\nimport type { ToolName } from \"../index.ts\";\nimport { createShellRenderers } from \"./bash.ts\";\nimport { editRenderers } from \"./edit.ts\";\nimport { findRenderers } from \"./find.ts\";\nimport { grepRenderers } from \"./grep.ts\";\nimport { lsRenderers } from \"./ls.ts\";\nimport { readRenderers } from \"./read.ts\";\nimport { writeRenderers } from \"./write.ts\";\n\nexport type { ToolRenderers };\n\nexport {\n\tcreateShellRenderers,\n\teditRenderers,\n\tfindRenderers,\n\tgrepRenderers,\n\tlsRenderers,\n\treadRenderers,\n\twriteRenderers,\n};\n\n/** Renderers for every built-in tool, keyed by tool name. */\nexport function createAllToolRenderers(): Record<ToolName, ToolRenderers> {\n\treturn {\n\t\tread: readRenderers,\n\t\tbash: createShellRenderers({ name: \"bash\", prompt: \"$\" }),\n\t\tpowershell: createShellRenderers({ name: \"powershell\", prompt: \"PS>\" }),\n\t\tedit: editRenderers,\n\t\twrite: writeRenderers,\n\t\tgrep: grepRenderers,\n\t\tfind: findRenderers,\n\t\tls: lsRenderers,\n\t};\n}\n\n/**\n * Merge built-in renderers into a tool definition that does not supply its own.\n *\n * `ToolExecutionComponent` used to do this lookup itself, which forced every presentation to import\n * the tool implementations. Callers do it now, so a process that renders can import renderers alone.\n */\nexport function withBuiltInRenderers<TDefinition extends ToolRenderers>(\n\ttoolName: string,\n\tdefinition: TDefinition | undefined,\n): TDefinition | ToolRenderers | undefined {\n\tconst builtIn = createAllToolRenderers()[toolName as ToolName];\n\tif (!definition) return builtIn;\n\tif (!builtIn) return definition;\n\treturn {\n\t\t...definition,\n\t\trenderCall: definition.renderCall ?? builtIn.renderCall,\n\t\trenderResult: definition.renderResult ?? builtIn.renderResult,\n\t};\n}\n"]}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { AgentToolResult } from "@earendil-works/pi-agent-core";
|
|
2
2
|
import type { TaskCompletion, TaskControl } from "../tasks/types.ts";
|
|
3
|
-
import type { BashOperations, BashSpawnContext
|
|
4
|
-
|
|
3
|
+
import type { BashOperations, BashSpawnContext } from "./bash.ts";
|
|
4
|
+
import type { BashToolDetails } from "./shell-tool.ts";
|
|
5
5
|
export declare const MAX_BACKGROUND_OUTPUT_BYTES: number;
|
|
6
6
|
export interface ManagedShellExecution {
|
|
7
7
|
control: TaskControl<BashToolDetails | undefined>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shell-execution.d.ts","sourceRoot":"","sources":["../../../src/core/tools/shell-execution.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AAErE,OAAO,KAAK,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"shell-execution.d.ts","sourceRoot":"","sources":["../../../src/core/tools/shell-execution.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AAErE,OAAO,KAAK,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AACrE,OAAO,KAAK,EAAE,cAAc,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAGlE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAGvD,eAAO,MAAM,2BAA2B,QAAmB,CAAC;AAE5D,MAAM,WAAW,qBAAqB;IACrC,OAAO,EAAE,WAAW,CAAC,eAAe,GAAG,SAAS,CAAC,CAAC;CAClD;AAED,UAAU,qBAAqB;IAC9B,UAAU,EAAE,cAAc,CAAC;IAC3B,OAAO,EAAE,gBAAgB,CAAC;IAC1B,cAAc,EAAE,MAAM,CAAC;IACvB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB,QAAQ,CAAC,EAAE,CAAC,MAAM,EAAE,eAAe,CAAC,eAAe,GAAG,SAAS,CAAC,KAAK,IAAI,CAAC;IAC1E,OAAO,CAAC,EAAE,qBAAqB,CAAC;CAChC;AAwCD,6EAA6E;AAC7E,wBAAsB,eAAe,CACpC,OAAO,EAAE,qBAAqB,GAC5B,OAAO,CAAC,cAAc,CAAC,eAAe,GAAG,SAAS,CAAC,CAAC,CAsKtD"}
|
|
@@ -3,27 +3,6 @@ import { boundText } from "../tasks/output.js";
|
|
|
3
3
|
import { OutputAccumulator } from "./output-accumulator.js";
|
|
4
4
|
import { BASH_UPDATE_THROTTLE_MS } from "./renderers/bash.js";
|
|
5
5
|
import { formatSize } from "./truncate.js";
|
|
6
|
-
/**
|
|
7
|
-
* Rewrite Windows CMD-style `nul` redirects to POSIX `/dev/null`.
|
|
8
|
-
*
|
|
9
|
-
* Models occasionally emit CMD syntax such as `command 2>nul` even though the
|
|
10
|
-
* shell resolved by `getShellConfig` is always POSIX. A POSIX shell treats
|
|
11
|
-
* `nul` as an ordinary file name, so the redirect creates a literal `nul`
|
|
12
|
-
* file. On Windows that name is a reserved device name: Explorer and most
|
|
13
|
-
* tools cannot delete the file, and it breaks `git add .` and `git clone`
|
|
14
|
-
* for the affected directory.
|
|
15
|
-
*
|
|
16
|
-
* Matches `>nul`, `> NUL`, `2>nul`, `&>nul`, and `>>nul` case-insensitively
|
|
17
|
-
* while leaving longer tokens such as `>null` or `>nul.txt` untouched. The
|
|
18
|
-
* regex does not parse shell quoting, so a quoted literal such as
|
|
19
|
-
* `echo "2>nul crashes"` is also rewritten when `nul` is followed by
|
|
20
|
-
* whitespace; that is accepted because the pattern is rare and the rewritten
|
|
21
|
-
* string stays harmless.
|
|
22
|
-
*/
|
|
23
|
-
const CMD_NUL_REDIRECT_REGEX = /(\d?&?>+\s*)[Nn][Uu][Ll](?=\s|$|[|&;)\n])/g;
|
|
24
|
-
export function rewriteCmdNulRedirects(command) {
|
|
25
|
-
return command.replace(CMD_NUL_REDIRECT_REGEX, "$1/dev/null");
|
|
26
|
-
}
|
|
27
6
|
export const MAX_BACKGROUND_OUTPUT_BYTES = 20 * 1024 * 1024;
|
|
28
7
|
/** Interpret the documented BashOperations error markers once, before formatting output. */
|
|
29
8
|
function shellFailure(error) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shell-execution.js","sourceRoot":"","sources":["../../../src/core/tools/shell-execution.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAE1C,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAE/C,OAAO,EAAE,iBAAiB,EAAuB,MAAM,yBAAyB,CAAC;AACjF,OAAO,EAAE,uBAAuB,EAAE,MAAM,qBAAqB,CAAC;AAE9D,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAE3C;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,sBAAsB,GAAG,4CAA4C,CAAC;AAE5E,MAAM,UAAU,sBAAsB,CAAC,OAAe;IACrD,OAAO,OAAO,CAAC,OAAO,CAAC,sBAAsB,EAAE,aAAa,CAAC,CAAC;AAC/D,CAAC;AAED,MAAM,CAAC,MAAM,2BAA2B,GAAG,EAAE,GAAG,IAAI,GAAG,IAAI,CAAC;AAqB5D,4FAA4F;AAC5F,SAAS,YAAY,CAAC,KAAc;IACnC,IAAI,KAAK,YAAY,KAAK,IAAI,KAAK,CAAC,OAAO,KAAK,SAAS;QAAE,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,KAAK,EAAE,iBAAiB,EAAE,CAAC;IACpH,IAAI,KAAK,YAAY,KAAK,IAAI,KAAK,CAAC,OAAO,CAAC,UAAU,CAAC,UAAU,CAAC;QACjE,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,KAAK,EAAE,2BAA2B,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,UAAU,EAAE,CAAC;IACvG,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,KAAK,EAAE,SAAS,CAAC,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAA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,aAAa,EAAE,CAAC;IAC9B,CAAC;AACF,CAAC","sourcesContent":["import { unlink } from \"node:fs/promises\";\nimport type { AgentToolResult } from \"@earendil-works/pi-agent-core\";\nimport { boundText } from \"../tasks/output.ts\";\nimport type { TaskCompletion, TaskControl } from \"../tasks/types.ts\";\nimport { OutputAccumulator, type OutputSnapshot } from \"./output-accumulator.ts\";\nimport { BASH_UPDATE_THROTTLE_MS } from \"./renderers/bash.ts\";\nimport type { BashOperations, BashSpawnContext, BashToolDetails } from \"./shell-tool.ts\";\nimport { formatSize } from \"./truncate.ts\";\n\n/**\n * Rewrite Windows CMD-style `nul` redirects to POSIX `/dev/null`.\n *\n * Models occasionally emit CMD syntax such as `command 2>nul` even though the\n * shell resolved by `getShellConfig` is always POSIX. A POSIX shell treats\n * `nul` as an ordinary file name, so the redirect creates a literal `nul`\n * file. On Windows that name is a reserved device name: Explorer and most\n * tools cannot delete the file, and it breaks `git add .` and `git clone`\n * for the affected directory.\n *\n * Matches `>nul`, `> NUL`, `2>nul`, `&>nul`, and `>>nul` case-insensitively\n * while leaving longer tokens such as `>null` or `>nul.txt` untouched. The\n * regex does not parse shell quoting, so a quoted literal such as\n * `echo \"2>nul crashes\"` is also rewritten when `nul` is followed by\n * whitespace; that is accepted because the pattern is rare and the rewritten\n * string stays harmless.\n */\nconst CMD_NUL_REDIRECT_REGEX = /(\\d?&?>+\\s*)[Nn][Uu][Ll](?=\\s|$|[|&;)\\n])/g;\n\nexport function rewriteCmdNulRedirects(command: string): string {\n\treturn command.replace(CMD_NUL_REDIRECT_REGEX, \"$1/dev/null\");\n}\n\nexport const MAX_BACKGROUND_OUTPUT_BYTES = 20 * 1024 * 1024;\n\nexport interface ManagedShellExecution {\n\tcontrol: TaskControl<BashToolDetails | undefined>;\n}\n\ninterface ShellExecutionOptions {\n\toperations: BashOperations;\n\tcontext: BashSpawnContext;\n\ttempFilePrefix: string;\n\ttimeout?: number;\n\tsignal?: AbortSignal;\n\tonUpdate?: (result: AgentToolResult<BashToolDetails | undefined>) => void;\n\tmanaged?: ManagedShellExecution;\n}\n\ninterface ShellFailure {\n\tstatus: \"failed\" | \"cancelled\" | \"timeout\";\n\terror: string;\n}\n\n/** Interpret the documented BashOperations error markers once, before formatting output. */\nfunction shellFailure(error: unknown): ShellFailure {\n\tif (error instanceof Error && error.message === \"aborted\") return { status: \"cancelled\", error: \"Command aborted\" };\n\tif (error instanceof Error && error.message.startsWith(\"timeout:\"))\n\t\treturn { status: \"timeout\", error: `Command timed out after ${error.message.split(\":\")[1]} seconds` };\n\treturn { status: \"failed\", error: boundText(error instanceof Error ? error.message : String(error), 4096) };\n}\n\nfunction formatOutput(\n\toutput: OutputAccumulator,\n\tsnapshot: OutputSnapshot,\n\tmanaged: boolean,\n\temptyText: string,\n): { text: string; details: BashToolDetails | undefined } {\n\tconst truncation = snapshot.truncation;\n\tlet text = snapshot.content || emptyText;\n\tlet details: BashToolDetails | undefined = managed ? { fullOutputPath: snapshot.fullOutputPath } : undefined;\n\tif (truncation.truncated) {\n\t\tdetails = { truncation, fullOutputPath: snapshot.fullOutputPath };\n\t\tconst startLine = truncation.totalLines - truncation.outputLines + 1;\n\t\tconst endLine = truncation.totalLines;\n\t\tif (truncation.lastLinePartial) {\n\t\t\tconst lastLineSize = formatSize(output.getLastLineBytes());\n\t\t\ttext += `\\n\\n[Showing last ${formatSize(truncation.outputBytes)} of line ${endLine} (line is ${lastLineSize}). Full output: ${snapshot.fullOutputPath}]`;\n\t\t} else if (truncation.truncatedBy === \"lines\") {\n\t\t\ttext += `\\n\\n[Showing lines ${startLine}-${endLine} of ${truncation.totalLines}. Full output: ${snapshot.fullOutputPath}]`;\n\t\t} else {\n\t\t\ttext += `\\n\\n[Showing lines ${startLine}-${endLine} of ${truncation.totalLines} (${formatSize(truncation.maxBytes)} limit). Full output: ${snapshot.fullOutputPath}]`;\n\t\t}\n\t}\n\treturn { text, details };\n}\n\n/** One process and one output owner across foreground/background handoff. */\nexport async function runShellCommand(\n\toptions: ShellExecutionOptions,\n): Promise<TaskCompletion<BashToolDetails | undefined>> {\n\tconst { operations, context, managed, signal, timeout } = options;\n\tconst output = new OutputAccumulator({ tempFilePrefix: options.tempFilePrefix, persistFromStart: !!managed });\n\tconst startedAt = performance.now();\n\tlet outputError: Error | undefined;\n\tlet acceptingOutput = true;\n\tlet unsubscribe: (() => void) | undefined;\n\tlet updateTimer: NodeJS.Timeout | undefined;\n\tlet updateDirty = false;\n\tlet lastUpdateAt = 0;\n\n\tconst failOutput = (error: unknown) => {\n\t\tif (outputError) return;\n\t\toutputError = error instanceof Error ? error : new Error(String(error));\n\t\ttry {\n\t\t\tif (managed) managed.control.requestCancel();\n\t\t} catch {\n\t\t\t// Late data must not throw through a process observer.\n\t\t}\n\t};\n\tconst checkOutputLimit = () => {\n\t\tif (managed?.control.mode === \"background\" && output.getTotalBytes() > MAX_BACKGROUND_OUTPUT_BYTES) {\n\t\t\tfailOutput(new Error(\"Background command exceeded the 20 MiB output limit\"));\n\t\t}\n\t};\n\tconst snapshot = () =>\n\t\toutput.snapshot({\n\t\t\tpersistIfTruncated: true,\n\t\t\tmaxBytes: managed?.control.mode === \"background\" ? 40 * 1024 : undefined,\n\t\t});\n\tconst publish = (snapshot?: OutputSnapshot) => {\n\t\tconst result: AgentToolResult<BashToolDetails | undefined> = {\n\t\t\tcontent: snapshot ? [{ type: \"text\", text: snapshot.content }] : [],\n\t\t\tdetails: snapshot\n\t\t\t\t? {\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: undefined,\n\t\t};\n\t\tif (managed) managed.control.publish(result);\n\t\telse options.onUpdate?.(result);\n\t};\n\tconst emitOutputUpdate = () => {\n\t\tif ((!managed && !options.onUpdate) || !updateDirty) return;\n\t\tupdateDirty = false;\n\t\tlastUpdateAt = Date.now();\n\t\tpublish(snapshot());\n\t};\n\tconst clearUpdateTimer = () => {\n\t\tif (updateTimer) clearTimeout(updateTimer);\n\t\tupdateTimer = undefined;\n\t};\n\tconst scheduleOutputUpdate = () => {\n\t\tif (!managed && !options.onUpdate) return;\n\t\tupdateDirty = true;\n\t\tconst delay = BASH_UPDATE_THROTTLE_MS - (Date.now() - lastUpdateAt);\n\t\tif (delay <= 0) {\n\t\t\tclearUpdateTimer();\n\t\t\temitOutputUpdate();\n\t\t} else {\n\t\t\tupdateTimer ??= setTimeout(() => {\n\t\t\t\tupdateTimer = undefined;\n\t\t\t\temitOutputUpdate();\n\t\t\t}, delay);\n\t\t}\n\t};\n\tconst handleData = (data: Buffer) => {\n\t\tif (!acceptingOutput || outputError) return;\n\t\ttry {\n\t\t\tif (\n\t\t\t\tmanaged?.control.mode === \"background\" &&\n\t\t\t\toutput.getTotalBytes() + data.length > MAX_BACKGROUND_OUTPUT_BYTES\n\t\t\t) {\n\t\t\t\tconst remaining = Math.max(0, MAX_BACKGROUND_OUTPUT_BYTES - output.getTotalBytes());\n\t\t\t\toutput.append(data.subarray(0, remaining));\n\t\t\t\tfailOutput(new Error(\"Background command exceeded the 20 MiB output limit\"));\n\t\t\t} else output.append(data);\n\t\t\tscheduleOutputUpdate();\n\t\t} catch (error) {\n\t\t\tif (!managed) throw error;\n\t\t\tfailOutput(error);\n\t\t}\n\t};\n\n\ttry {\n\t\tif (managed) {\n\t\t\tconst path = output.snapshot().fullOutputPath!;\n\t\t\tconst cleanup = async () => {\n\t\t\t\tawait output.closeTempFile();\n\t\t\t\tawait unlink(path).catch((error: NodeJS.ErrnoException) => {\n\t\t\t\t\tif (error.code !== \"ENOENT\") throw error;\n\t\t\t\t});\n\t\t\t};\n\t\t\ttry {\n\t\t\t\tmanaged.control.setOutputPath(path, cleanup);\n\t\t\t} catch (error) {\n\t\t\t\tawait cleanup();\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t\t// Detach must check a silent foreground log too, preserving bytes already written.\n\t\t\tunsubscribe = managed.control.onModeChange(checkOutputLimit);\n\t\t}\n\t\tpublish();\n\t\tlet failure: ShellFailure | undefined;\n\t\tlet exitCode: number | null | undefined;\n\t\ttry {\n\t\t\tif (signal?.aborted) throw new Error(\"aborted\");\n\t\t\tconst execution = operations.exec(context.command, context.cwd, {\n\t\t\t\tonData: handleData,\n\t\t\t\tsignal,\n\t\t\t\ttimeout,\n\t\t\t\tenv: context.env,\n\t\t\t});\n\t\t\tmanaged?.control.accept();\n\t\t\t({ exitCode } = await execution);\n\t\t\tif (exitCode === null) {\n\t\t\t\tfailure = { status: \"failed\", error: \"Command terminated without an exit code\" };\n\t\t\t} else if (exitCode !== 0) {\n\t\t\t\tfailure = { status: \"failed\", error: `Command exited with code ${exitCode}` };\n\t\t\t}\n\t\t} catch (error) {\n\t\t\tfailure = shellFailure(error);\n\t\t}\n\t\tacceptingOutput = false;\n\t\toutput.finish();\n\t\tclearUpdateTimer();\n\t\tif (managed) publish(snapshot());\n\t\telse emitOutputUpdate();\n\t\tconst final = snapshot();\n\t\tawait output.closeTempFile();\n\t\t// Final progress/cleanup can re-enter handoff. Classify policy cancellation\n\t\t// after those callbacks, independently of the process's abort marker.\n\t\tif (outputError) failure = { status: \"failed\", error: boundText(outputError.message, 4096) };\n\t\tconst { text, details } = formatOutput(output, final, !!managed, failure ? \"\" : \"(no output)\");\n\t\tconst fullOutput =\n\t\t\ttypeof exitCode === \"number\" && !outputError ? await output.readFullOutput(1024 * 1024) : undefined;\n\t\treturn {\n\t\t\tstatus: failure?.status,\n\t\t\terror: failure?.error,\n\t\t\t...(exitCode !== undefined ? { exitCode } : {}),\n\t\t\tresult: {\n\t\t\t\t...(fullOutput && typeof exitCode === \"number\"\n\t\t\t\t\t? {\n\t\t\t\t\t\t\tstructuredContent: {\n\t\t\t\t\t\t\t\toutput: fullOutput.content,\n\t\t\t\t\t\t\t\ttruncated: fullOutput.truncated,\n\t\t\t\t\t\t\t\t...(fullOutput.truncated && final.fullOutputPath\n\t\t\t\t\t\t\t\t\t? { full_output_path: final.fullOutputPath }\n\t\t\t\t\t\t\t\t\t: {}),\n\t\t\t\t\t\t\t\texit_code: exitCode,\n\t\t\t\t\t\t\t\twall_time_seconds: Math.round((performance.now() - startedAt) / 100) / 10,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t...(failure ? { isError: true } : {}),\n\t\t\t\t\t\t}\n\t\t\t\t\t: {}),\n\t\t\t\tcontent: [{ type: \"text\", text: failure ? `${text ? `${text}\\n\\n` : \"\"}${failure.error}` : text }],\n\t\t\t\tdetails,\n\t\t\t},\n\t\t};\n\t} finally {\n\t\tacceptingOutput = false;\n\t\tunsubscribe?.();\n\t\tclearUpdateTimer();\n\t\tawait output.closeTempFile();\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"shell-execution.js","sourceRoot":"","sources":["../../../src/core/tools/shell-execution.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAE1C,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAG/C,OAAO,EAAE,iBAAiB,EAAuB,MAAM,yBAAyB,CAAC;AACjF,OAAO,EAAE,uBAAuB,EAAE,MAAM,qBAAqB,CAAC;AAE9D,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAE3C,MAAM,CAAC,MAAM,2BAA2B,GAAG,EAAE,GAAG,IAAI,GAAG,IAAI,CAAC;AAqB5D,4FAA4F;AAC5F,SAAS,YAAY,CAAC,KAAc;IACnC,IAAI,KAAK,YAAY,KAAK,IAAI,KAAK,CAAC,OAAO,KAAK,SAAS;QAAE,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,KAAK,EAAE,iBAAiB,EAAE,CAAC;IACpH,IAAI,KAAK,YAAY,KAAK,IAAI,KAAK,CAAC,OAAO,CAAC,UAAU,CAAC,UAAU,CAAC;QACjE,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,KAAK,EAAE,2BAA2B,KAAK,CAAC,OAAO,CAAC,KAAK,CAA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AClG,OAAO;aACP;SACD,CAAC;IACH,CAAC;YAAS,CAAC;QACV,eAAe,GAAG,KAAK,CAAC;QACxB,WAAW,EAAE,EAAE,CAAC;QAChB,gBAAgB,EAAE,CAAC;QACnB,MAAM,MAAM,CAAC,aAAa,EAAE,CAAC;IAC9B,CAAC;AACF,CAAC","sourcesContent":["import { unlink } from \"node:fs/promises\";\nimport type { AgentToolResult } from \"@earendil-works/pi-agent-core\";\nimport { boundText } from \"../tasks/output.ts\";\nimport type { TaskCompletion, TaskControl } from \"../tasks/types.ts\";\nimport type { BashOperations, BashSpawnContext } from \"./bash.ts\";\nimport { OutputAccumulator, type OutputSnapshot } from \"./output-accumulator.ts\";\nimport { BASH_UPDATE_THROTTLE_MS } from \"./renderers/bash.ts\";\nimport type { BashToolDetails } from \"./shell-tool.ts\";\nimport { formatSize } from \"./truncate.ts\";\n\nexport const MAX_BACKGROUND_OUTPUT_BYTES = 20 * 1024 * 1024;\n\nexport interface ManagedShellExecution {\n\tcontrol: TaskControl<BashToolDetails | undefined>;\n}\n\ninterface ShellExecutionOptions {\n\toperations: BashOperations;\n\tcontext: BashSpawnContext;\n\ttempFilePrefix: string;\n\ttimeout?: number;\n\tsignal?: AbortSignal;\n\tonUpdate?: (result: AgentToolResult<BashToolDetails | undefined>) => void;\n\tmanaged?: ManagedShellExecution;\n}\n\ninterface ShellFailure {\n\tstatus: \"failed\" | \"cancelled\" | \"timeout\";\n\terror: string;\n}\n\n/** Interpret the documented BashOperations error markers once, before formatting output. */\nfunction shellFailure(error: unknown): ShellFailure {\n\tif (error instanceof Error && error.message === \"aborted\") return { status: \"cancelled\", error: \"Command aborted\" };\n\tif (error instanceof Error && error.message.startsWith(\"timeout:\"))\n\t\treturn { status: \"timeout\", error: `Command timed out after ${error.message.split(\":\")[1]} seconds` };\n\treturn { status: \"failed\", error: boundText(error instanceof Error ? error.message : String(error), 4096) };\n}\n\nfunction formatOutput(\n\toutput: OutputAccumulator,\n\tsnapshot: OutputSnapshot,\n\tmanaged: boolean,\n\temptyText: string,\n): { text: string; details: BashToolDetails | undefined } {\n\tconst truncation = snapshot.truncation;\n\tlet text = snapshot.content || emptyText;\n\tlet details: BashToolDetails | undefined = managed ? { fullOutputPath: snapshot.fullOutputPath } : undefined;\n\tif (truncation.truncated) {\n\t\tdetails = { truncation, fullOutputPath: snapshot.fullOutputPath };\n\t\tconst startLine = truncation.totalLines - truncation.outputLines + 1;\n\t\tconst endLine = truncation.totalLines;\n\t\tif (truncation.lastLinePartial) {\n\t\t\tconst lastLineSize = formatSize(output.getLastLineBytes());\n\t\t\ttext += `\\n\\n[Showing last ${formatSize(truncation.outputBytes)} of line ${endLine} (line is ${lastLineSize}). Full output: ${snapshot.fullOutputPath}]`;\n\t\t} else if (truncation.truncatedBy === \"lines\") {\n\t\t\ttext += `\\n\\n[Showing lines ${startLine}-${endLine} of ${truncation.totalLines}. Full output: ${snapshot.fullOutputPath}]`;\n\t\t} else {\n\t\t\ttext += `\\n\\n[Showing lines ${startLine}-${endLine} of ${truncation.totalLines} (${formatSize(truncation.maxBytes)} limit). Full output: ${snapshot.fullOutputPath}]`;\n\t\t}\n\t}\n\treturn { text, details };\n}\n\n/** One process and one output owner across foreground/background handoff. */\nexport async function runShellCommand(\n\toptions: ShellExecutionOptions,\n): Promise<TaskCompletion<BashToolDetails | undefined>> {\n\tconst { operations, context, managed, signal, timeout } = options;\n\tconst output = new OutputAccumulator({ tempFilePrefix: options.tempFilePrefix, persistFromStart: !!managed });\n\tconst startedAt = performance.now();\n\tlet outputError: Error | undefined;\n\tlet acceptingOutput = true;\n\tlet unsubscribe: (() => void) | undefined;\n\tlet updateTimer: NodeJS.Timeout | undefined;\n\tlet updateDirty = false;\n\tlet lastUpdateAt = 0;\n\n\tconst failOutput = (error: unknown) => {\n\t\tif (outputError) return;\n\t\toutputError = error instanceof Error ? error : new Error(String(error));\n\t\ttry {\n\t\t\tif (managed) managed.control.requestCancel();\n\t\t} catch {\n\t\t\t// Late data must not throw through a process observer.\n\t\t}\n\t};\n\tconst checkOutputLimit = () => {\n\t\tif (managed?.control.mode === \"background\" && output.getTotalBytes() > MAX_BACKGROUND_OUTPUT_BYTES) {\n\t\t\tfailOutput(new Error(\"Background command exceeded the 20 MiB output limit\"));\n\t\t}\n\t};\n\tconst snapshot = () =>\n\t\toutput.snapshot({\n\t\t\tpersistIfTruncated: true,\n\t\t\tmaxBytes: managed?.control.mode === \"background\" ? 40 * 1024 : undefined,\n\t\t});\n\tconst publish = (snapshot?: OutputSnapshot) => {\n\t\tconst result: AgentToolResult<BashToolDetails | undefined> = {\n\t\t\tcontent: snapshot ? [{ type: \"text\", text: snapshot.content }] : [],\n\t\t\tdetails: snapshot\n\t\t\t\t? {\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: undefined,\n\t\t};\n\t\tif (managed) managed.control.publish(result);\n\t\telse options.onUpdate?.(result);\n\t};\n\tconst emitOutputUpdate = () => {\n\t\tif ((!managed && !options.onUpdate) || !updateDirty) return;\n\t\tupdateDirty = false;\n\t\tlastUpdateAt = Date.now();\n\t\tpublish(snapshot());\n\t};\n\tconst clearUpdateTimer = () => {\n\t\tif (updateTimer) clearTimeout(updateTimer);\n\t\tupdateTimer = undefined;\n\t};\n\tconst scheduleOutputUpdate = () => {\n\t\tif (!managed && !options.onUpdate) return;\n\t\tupdateDirty = true;\n\t\tconst delay = BASH_UPDATE_THROTTLE_MS - (Date.now() - lastUpdateAt);\n\t\tif (delay <= 0) {\n\t\t\tclearUpdateTimer();\n\t\t\temitOutputUpdate();\n\t\t} else {\n\t\t\tupdateTimer ??= setTimeout(() => {\n\t\t\t\tupdateTimer = undefined;\n\t\t\t\temitOutputUpdate();\n\t\t\t}, delay);\n\t\t}\n\t};\n\tconst handleData = (data: Buffer) => {\n\t\tif (!acceptingOutput || outputError) return;\n\t\ttry {\n\t\t\tif (\n\t\t\t\tmanaged?.control.mode === \"background\" &&\n\t\t\t\toutput.getTotalBytes() + data.length > MAX_BACKGROUND_OUTPUT_BYTES\n\t\t\t) {\n\t\t\t\tconst remaining = Math.max(0, MAX_BACKGROUND_OUTPUT_BYTES - output.getTotalBytes());\n\t\t\t\toutput.append(data.subarray(0, remaining));\n\t\t\t\tfailOutput(new Error(\"Background command exceeded the 20 MiB output limit\"));\n\t\t\t} else output.append(data);\n\t\t\tscheduleOutputUpdate();\n\t\t} catch (error) {\n\t\t\tif (!managed) throw error;\n\t\t\tfailOutput(error);\n\t\t}\n\t};\n\n\ttry {\n\t\tif (managed) {\n\t\t\tconst path = output.snapshot().fullOutputPath!;\n\t\t\tconst cleanup = async () => {\n\t\t\t\tawait output.closeTempFile();\n\t\t\t\tawait unlink(path).catch((error: NodeJS.ErrnoException) => {\n\t\t\t\t\tif (error.code !== \"ENOENT\") throw error;\n\t\t\t\t});\n\t\t\t};\n\t\t\ttry {\n\t\t\t\tmanaged.control.setOutputPath(path, cleanup);\n\t\t\t} catch (error) {\n\t\t\t\tawait cleanup();\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t\t// Detach must check a silent foreground log too, preserving bytes already written.\n\t\t\tunsubscribe = managed.control.onModeChange(checkOutputLimit);\n\t\t}\n\t\tpublish();\n\t\tlet failure: ShellFailure | undefined;\n\t\tlet exitCode: number | null | undefined;\n\t\ttry {\n\t\t\tif (signal?.aborted) throw new Error(\"aborted\");\n\t\t\tconst execution = operations.exec(context.command, context.cwd, {\n\t\t\t\tonData: handleData,\n\t\t\t\tsignal,\n\t\t\t\ttimeout,\n\t\t\t\tenv: context.env,\n\t\t\t});\n\t\t\tmanaged?.control.accept();\n\t\t\t({ exitCode } = await execution);\n\t\t\tif (exitCode === null) {\n\t\t\t\tfailure = { status: \"failed\", error: \"Command terminated without an exit code\" };\n\t\t\t} else if (exitCode !== 0) {\n\t\t\t\tfailure = { status: \"failed\", error: `Command exited with code ${exitCode}` };\n\t\t\t}\n\t\t} catch (error) {\n\t\t\tfailure = shellFailure(error);\n\t\t}\n\t\tacceptingOutput = false;\n\t\toutput.finish();\n\t\tclearUpdateTimer();\n\t\tif (managed) publish(snapshot());\n\t\telse emitOutputUpdate();\n\t\tconst final = snapshot();\n\t\tawait output.closeTempFile();\n\t\t// Final progress/cleanup can re-enter handoff. Classify policy cancellation\n\t\t// after those callbacks, independently of the process's abort marker.\n\t\tif (outputError) failure = { status: \"failed\", error: boundText(outputError.message, 4096) };\n\t\tconst { text, details } = formatOutput(output, final, !!managed, failure ? \"\" : \"(no output)\");\n\t\tconst fullOutput =\n\t\t\ttypeof exitCode === \"number\" && !outputError ? await output.readFullOutput(1024 * 1024) : undefined;\n\t\treturn {\n\t\t\tstatus: failure?.status,\n\t\t\terror: failure?.error,\n\t\t\t...(exitCode !== undefined ? { exitCode } : {}),\n\t\t\tresult: {\n\t\t\t\t...(fullOutput && typeof exitCode === \"number\"\n\t\t\t\t\t? {\n\t\t\t\t\t\t\tstructuredContent: {\n\t\t\t\t\t\t\t\toutput: fullOutput.content,\n\t\t\t\t\t\t\t\ttruncated: fullOutput.truncated,\n\t\t\t\t\t\t\t\t...(fullOutput.truncated && final.fullOutputPath\n\t\t\t\t\t\t\t\t\t? { full_output_path: final.fullOutputPath }\n\t\t\t\t\t\t\t\t\t: {}),\n\t\t\t\t\t\t\t\texit_code: exitCode,\n\t\t\t\t\t\t\t\twall_time_seconds: Math.round((performance.now() - startedAt) / 100) / 10,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t...(failure ? { isError: true } : {}),\n\t\t\t\t\t\t}\n\t\t\t\t\t: {}),\n\t\t\t\tcontent: [{ type: \"text\", text: failure ? `${text ? `${text}\\n\\n` : \"\"}${failure.error}` : text }],\n\t\t\t\tdetails,\n\t\t\t},\n\t\t};\n\t} finally {\n\t\tacceptingOutput = false;\n\t\tunsubscribe?.();\n\t\tclearUpdateTimer();\n\t\tawait output.closeTempFile();\n\t}\n}\n"]}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { type BashOperations } from "./bash.ts";
|
|
2
|
+
export declare function rewriteCmdNulRedirects(command: string): string;
|
|
3
|
+
export declare function normalizeLocalBashCommand(command: string, platform?: NodeJS.Platform): string;
|
|
4
|
+
/**
|
|
5
|
+
* Local bash operations for every bash entry point: the managed shell tool,
|
|
6
|
+
* extension `user_bash` handlers, and SDK callers. The process loop stays
|
|
7
|
+
* upstream; only the command normalization is distribution-owned.
|
|
8
|
+
*/
|
|
9
|
+
export declare function createLocalBashOperations(options?: {
|
|
10
|
+
shellPath?: string;
|
|
11
|
+
}): BashOperations;
|
|
12
|
+
//# sourceMappingURL=shell-operations.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shell-operations.d.ts","sourceRoot":"","sources":["../../../src/core/tools/shell-operations.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,cAAc,EAA8B,MAAM,WAAW,CAAC;AAqB5E,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAE9D;AAED,wBAAgB,yBAAyB,CAAC,OAAO,EAAE,MAAM,EAAE,QAAQ,GAAE,MAAM,CAAC,QAA2B,GAAG,MAAM,CAE/G;AAED;;;;GAIG;AACH,wBAAgB,yBAAyB,CAAC,OAAO,CAAC,EAAE;IAAE,SAAS,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG,cAAc,CAK1F"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { getShellConfig } from "../../utils/shell.js";
|
|
2
|
+
import { createLocalShellOperations } from "./bash.js";
|
|
3
|
+
/**
|
|
4
|
+
* Rewrite Windows CMD-style `nul` redirects to POSIX `/dev/null`.
|
|
5
|
+
*
|
|
6
|
+
* Models occasionally emit CMD syntax such as `command 2>nul` even though the
|
|
7
|
+
* shell resolved by `getShellConfig` is always POSIX. A POSIX shell treats
|
|
8
|
+
* `nul` as an ordinary file name, so the redirect creates a literal `nul`
|
|
9
|
+
* file. On Windows that name is a reserved device name: Explorer and most
|
|
10
|
+
* tools cannot delete the file, and it breaks `git add .` and `git clone`
|
|
11
|
+
* for the affected directory.
|
|
12
|
+
*
|
|
13
|
+
* Matches `>nul`, `> NUL`, `2>nul`, `&>nul`, and `>>nul` case-insensitively
|
|
14
|
+
* while leaving longer tokens such as `>null` or `>nul.txt` untouched. The
|
|
15
|
+
* regex does not parse shell quoting, so a quoted literal such as
|
|
16
|
+
* `echo "2>nul crashes"` is also rewritten when `nul` is followed by
|
|
17
|
+
* whitespace; that is accepted because the pattern is rare and the rewritten
|
|
18
|
+
* string stays harmless.
|
|
19
|
+
*/
|
|
20
|
+
const CMD_NUL_REDIRECT_REGEX = /(\d?&?>+\s*)[Nn][Uu][Ll](?=\s|$|[|&;)\n])/g;
|
|
21
|
+
export function rewriteCmdNulRedirects(command) {
|
|
22
|
+
return command.replace(CMD_NUL_REDIRECT_REGEX, "$1/dev/null");
|
|
23
|
+
}
|
|
24
|
+
export function normalizeLocalBashCommand(command, platform = process.platform) {
|
|
25
|
+
return platform === "win32" ? rewriteCmdNulRedirects(command) : command;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Local bash operations for every bash entry point: the managed shell tool,
|
|
29
|
+
* extension `user_bash` handlers, and SDK callers. The process loop stays
|
|
30
|
+
* upstream; only the command normalization is distribution-owned.
|
|
31
|
+
*/
|
|
32
|
+
export function createLocalBashOperations(options) {
|
|
33
|
+
const operations = createLocalShellOperations("bash", () => getShellConfig(options?.shellPath));
|
|
34
|
+
return {
|
|
35
|
+
exec: (command, cwd, execOptions) => operations.exec(normalizeLocalBashCommand(command), cwd, execOptions),
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
//# sourceMappingURL=shell-operations.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shell-operations.js","sourceRoot":"","sources":["../../../src/core/tools/shell-operations.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAAuB,0BAA0B,EAAE,MAAM,WAAW,CAAC;AAE5E;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,sBAAsB,GAAG,4CAA4C,CAAC;AAE5E,MAAM,UAAU,sBAAsB,CAAC,OAAe;IACrD,OAAO,OAAO,CAAC,OAAO,CAAC,sBAAsB,EAAE,aAAa,CAAC,CAAC;AAC/D,CAAC;AAED,MAAM,UAAU,yBAAyB,CAAC,OAAe,EAAE,WAA4B,OAAO,CAAC,QAAQ;IACtG,OAAO,QAAQ,KAAK,OAAO,CAAC,CAAC,CAAC,sBAAsB,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC;AACzE,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,yBAAyB,CAAC,OAAgC;IACzE,MAAM,UAAU,GAAG,0BAA0B,CAAC,MAAM,EAAE,GAAG,EAAE,CAAC,cAAc,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC,CAAC;IAChG,OAAO;QACN,IAAI,EAAE,CAAC,OAAO,EAAE,GAAG,EAAE,WAAW,EAAE,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,yBAAyB,CAAC,OAAO,CAAC,EAAE,GAAG,EAAE,WAAW,CAAC;KAC1G,CAAC;AACH,CAAC","sourcesContent":["import { getShellConfig } from \"../../utils/shell.ts\";\nimport { type BashOperations, createLocalShellOperations } from \"./bash.ts\";\n\n/**\n * Rewrite Windows CMD-style `nul` redirects to POSIX `/dev/null`.\n *\n * Models occasionally emit CMD syntax such as `command 2>nul` even though the\n * shell resolved by `getShellConfig` is always POSIX. A POSIX shell treats\n * `nul` as an ordinary file name, so the redirect creates a literal `nul`\n * file. On Windows that name is a reserved device name: Explorer and most\n * tools cannot delete the file, and it breaks `git add .` and `git clone`\n * for the affected directory.\n *\n * Matches `>nul`, `> NUL`, `2>nul`, `&>nul`, and `>>nul` case-insensitively\n * while leaving longer tokens such as `>null` or `>nul.txt` untouched. The\n * regex does not parse shell quoting, so a quoted literal such as\n * `echo \"2>nul crashes\"` is also rewritten when `nul` is followed by\n * whitespace; that is accepted because the pattern is rare and the rewritten\n * string stays harmless.\n */\nconst CMD_NUL_REDIRECT_REGEX = /(\\d?&?>+\\s*)[Nn][Uu][Ll](?=\\s|$|[|&;)\\n])/g;\n\nexport function rewriteCmdNulRedirects(command: string): string {\n\treturn command.replace(CMD_NUL_REDIRECT_REGEX, \"$1/dev/null\");\n}\n\nexport function normalizeLocalBashCommand(command: string, platform: NodeJS.Platform = process.platform): string {\n\treturn platform === \"win32\" ? rewriteCmdNulRedirects(command) : command;\n}\n\n/**\n * Local bash operations for every bash entry point: the managed shell tool,\n * extension `user_bash` handlers, and SDK callers. The process loop stays\n * upstream; only the command normalization is distribution-owned.\n */\nexport function createLocalBashOperations(options?: { shellPath?: string }): BashOperations {\n\tconst operations = createLocalShellOperations(\"bash\", () => getShellConfig(options?.shellPath));\n\treturn {\n\t\texec: (command, cwd, execOptions) => operations.exec(normalizeLocalBashCommand(command), cwd, execOptions),\n\t};\n}\n"]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type Static, Type } from "typebox";
|
|
2
|
-
import {
|
|
3
|
-
import type
|
|
2
|
+
import type { ToolDefinition } from "../extensions/types.ts";
|
|
3
|
+
import { type BashOperations, type BashToolOptions, type ShellToolConfig } from "./bash.ts";
|
|
4
4
|
import { type TruncationResult } from "./truncate.ts";
|
|
5
5
|
declare const bashSchema: Type.TObject<{
|
|
6
6
|
command: Type.TString;
|
|
@@ -21,73 +21,17 @@ export interface BashToolDetails {
|
|
|
21
21
|
taskId: string;
|
|
22
22
|
};
|
|
23
23
|
}
|
|
24
|
-
/**
|
|
25
|
-
* Pluggable operations for the bash tool.
|
|
26
|
-
* Override these to delegate command execution to remote systems (for example SSH).
|
|
27
|
-
*/
|
|
28
|
-
export interface BashOperations {
|
|
29
|
-
/**
|
|
30
|
-
* Execute a command and stream output.
|
|
31
|
-
* @param command The command to execute
|
|
32
|
-
* @param cwd Working directory
|
|
33
|
-
* @param options Execution options
|
|
34
|
-
* @returns Promise resolving to the exit code. Report signal terminations as 128 + signal number;
|
|
35
|
-
* a null exit code is treated as a failed command.
|
|
36
|
-
*
|
|
37
|
-
* Error contract: reject with `new Error("aborted")` when aborted via `signal`,
|
|
38
|
-
* and `new Error("timeout:<seconds>")` on timeout expiry. The shared shell
|
|
39
|
-
* execution pipeline classifies outcomes from these exact markers.
|
|
40
|
-
*/
|
|
41
|
-
exec: (command: string, cwd: string, options: {
|
|
42
|
-
onData: (data: Buffer) => void;
|
|
43
|
-
signal?: AbortSignal;
|
|
44
|
-
timeout?: number;
|
|
45
|
-
env?: NodeJS.ProcessEnv;
|
|
46
|
-
}) => Promise<{
|
|
47
|
-
exitCode: number | null;
|
|
48
|
-
}>;
|
|
49
|
-
}
|
|
50
|
-
/** Shared process execution used by the built-in shell tools. */
|
|
51
|
-
export declare function createLocalShellOperations(shellName: string, resolveShellConfig: () => ShellConfig, normalizeCommand?: (command: string) => string): BashOperations;
|
|
52
|
-
/**
|
|
53
|
-
* Create bash operations using pi's built-in local shell execution backend.
|
|
54
|
-
*
|
|
55
|
-
* This is useful for extensions that intercept user_bash and still want pi's
|
|
56
|
-
* standard local shell behavior while wrapping or rewriting commands.
|
|
57
|
-
*/
|
|
58
|
-
export interface BashSpawnContext {
|
|
59
|
-
command: string;
|
|
60
|
-
cwd: string;
|
|
61
|
-
env: NodeJS.ProcessEnv;
|
|
62
|
-
}
|
|
63
|
-
export type BashSpawnHook = (context: BashSpawnContext) => BashSpawnContext;
|
|
64
|
-
export declare function resolveSpawnContext(command: string, cwd: string, spawnHook: BashSpawnHook | undefined, exposeSessionEnvironment: boolean, ctx: ExtensionContext | undefined): BashSpawnContext;
|
|
65
|
-
export interface BashToolOptions {
|
|
66
|
-
/** Custom operations for command execution. Default: local shell */
|
|
67
|
-
operations?: BashOperations;
|
|
68
|
-
/** Command prefix prepended to every command (for example shell setup commands) */
|
|
69
|
-
commandPrefix?: string;
|
|
70
|
-
/** Optional explicit shell path from settings */
|
|
71
|
-
shellPath?: string;
|
|
72
|
-
/** Expose current Pi session metadata as PI_* environment variables. Default: true */
|
|
73
|
-
exposeSessionEnvironment?: boolean;
|
|
74
|
-
/** Hook to adjust command, cwd, or env before execution */
|
|
75
|
-
spawnHook?: BashSpawnHook;
|
|
76
|
-
}
|
|
77
24
|
export type BashRenderState = {
|
|
78
25
|
dispose?: () => void;
|
|
79
26
|
};
|
|
80
|
-
export interface ShellToolConfig {
|
|
81
|
-
name: string;
|
|
82
|
-
label: string;
|
|
83
|
-
shellName: string;
|
|
84
|
-
prompt: string;
|
|
85
|
-
promptSnippet: string;
|
|
86
|
-
promptGuidelines?: readonly string[];
|
|
87
|
-
tempFilePrefix: string;
|
|
88
|
-
}
|
|
89
27
|
export declare function createShellToolDefinition(cwd: string, config: ShellToolConfig, options: BashToolOptions & {
|
|
90
28
|
operations: BashOperations;
|
|
91
29
|
}): ToolDefinition<typeof bashSchema, BashToolDetails | undefined, BashRenderState>;
|
|
30
|
+
export declare function createBashToolDefinition(cwd: string, options?: BashToolOptions): ReturnType<typeof createShellToolDefinition>;
|
|
31
|
+
export declare function createBashTool(cwd: string, options?: BashToolOptions): import("@earendil-works/pi-agent-core").AgentTool<Type.TObject<{
|
|
32
|
+
command: Type.TString;
|
|
33
|
+
timeout: Type.TOptional<Type.TNumber>;
|
|
34
|
+
background: Type.TOptional<Type.TBoolean>;
|
|
35
|
+
}>, BashToolDetails | undefined>;
|
|
92
36
|
export {};
|
|
93
37
|
//# sourceMappingURL=shell-tool.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shell-tool.d.ts","sourceRoot":"","sources":["../../../src/core/tools/shell-tool.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"shell-tool.d.ts","sourceRoot":"","sources":["../../../src/core/tools/shell-tool.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,MAAM,EAAE,I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