@phi-code-admin/phi-code 0.74.3 → 0.75.1
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 +1186 -4
- package/README.md +478 -379
- package/dist/bun/cli.d.ts +3 -0
- package/dist/bun/cli.d.ts.map +1 -0
- package/dist/bun/cli.js +9 -0
- package/dist/bun/cli.js.map +1 -0
- package/dist/bun/register-bedrock.d.ts +2 -0
- package/dist/bun/register-bedrock.d.ts.map +1 -0
- package/dist/bun/register-bedrock.js +4 -0
- package/dist/bun/register-bedrock.js.map +1 -0
- package/dist/bun/restore-sandbox-env.d.ts +13 -0
- package/dist/bun/restore-sandbox-env.d.ts.map +1 -0
- package/dist/bun/restore-sandbox-env.js +32 -0
- package/dist/bun/restore-sandbox-env.js.map +1 -0
- package/dist/cli/args.d.ts +12 -7
- package/dist/cli/args.d.ts.map +1 -1
- package/dist/cli/args.js +87 -45
- package/dist/cli/args.js.map +1 -1
- package/dist/cli/config-selector.d.ts.map +1 -1
- package/dist/cli/config-selector.js.map +1 -1
- package/dist/cli/file-processor.d.ts.map +1 -1
- package/dist/cli/file-processor.js +4 -0
- package/dist/cli/file-processor.js.map +1 -1
- package/dist/cli/initial-message.d.ts +18 -0
- package/dist/cli/initial-message.d.ts.map +1 -0
- package/dist/cli/initial-message.js +22 -0
- package/dist/cli/initial-message.js.map +1 -0
- package/dist/cli/list-models.d.ts.map +1 -1
- package/dist/cli/list-models.js +7 -1
- package/dist/cli/list-models.js.map +1 -1
- package/dist/cli/session-picker.d.ts.map +1 -1
- package/dist/cli/session-picker.js +2 -1
- package/dist/cli/session-picker.js.map +1 -1
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +9 -5
- package/dist/cli.js.map +1 -1
- package/dist/config.d.ts +24 -0
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +226 -30
- package/dist/config.js.map +1 -1
- package/dist/core/agent-session-runtime.d.ts +117 -0
- package/dist/core/agent-session-runtime.d.ts.map +1 -0
- package/dist/core/agent-session-runtime.js +300 -0
- package/dist/core/agent-session-runtime.js.map +1 -0
- package/dist/core/agent-session-services.d.ts +86 -0
- package/dist/core/agent-session-services.d.ts.map +1 -0
- package/dist/core/agent-session-services.js +117 -0
- package/dist/core/agent-session-services.js.map +1 -0
- package/dist/core/agent-session.d.ts +63 -82
- package/dist/core/agent-session.d.ts.map +1 -1
- package/dist/core/agent-session.js +674 -628
- package/dist/core/agent-session.js.map +1 -1
- package/dist/core/api-key-store.d.ts +87 -0
- package/dist/core/api-key-store.d.ts.map +1 -0
- package/dist/core/api-key-store.js +168 -0
- package/dist/core/api-key-store.js.map +1 -0
- package/dist/core/auth-guidance.d.ts +5 -0
- package/dist/core/auth-guidance.d.ts.map +1 -0
- package/dist/core/auth-guidance.js +21 -0
- package/dist/core/auth-guidance.js.map +1 -0
- package/dist/core/auth-storage.d.ts +12 -5
- package/dist/core/auth-storage.d.ts.map +1 -1
- package/dist/core/auth-storage.js +34 -8
- package/dist/core/auth-storage.js.map +1 -1
- package/dist/core/bash-executor.d.ts +0 -15
- package/dist/core/bash-executor.d.ts.map +1 -1
- package/dist/core/bash-executor.js +28 -129
- package/dist/core/bash-executor.js.map +1 -1
- package/dist/core/compaction/branch-summarization.d.ts +2 -0
- package/dist/core/compaction/branch-summarization.d.ts.map +1 -1
- package/dist/core/compaction/branch-summarization.js +3 -2
- package/dist/core/compaction/branch-summarization.js.map +1 -1
- package/dist/core/compaction/compaction.d.ts +4 -4
- package/dist/core/compaction/compaction.d.ts.map +1 -1
- package/dist/core/compaction/compaction.js +32 -27
- package/dist/core/compaction/compaction.js.map +1 -1
- package/dist/core/compaction/index.d.ts.map +1 -1
- package/dist/core/compaction/utils.d.ts.map +1 -1
- package/dist/core/compaction/utils.js.map +1 -1
- package/dist/core/config-watcher.d.ts +47 -0
- package/dist/core/config-watcher.d.ts.map +1 -0
- package/dist/core/config-watcher.js +135 -0
- package/dist/core/config-watcher.js.map +1 -0
- package/dist/core/default-models.json +80 -0
- package/dist/core/defaults.d.ts.map +1 -1
- package/dist/core/diagnostics.d.ts.map +1 -1
- package/dist/core/event-bus.d.ts.map +1 -1
- package/dist/core/event-bus.js.map +1 -1
- package/dist/core/exec.d.ts.map +1 -1
- package/dist/core/exec.js +7 -3
- package/dist/core/exec.js.map +1 -1
- package/dist/core/export-html/ansi-to-html.d.ts.map +1 -1
- package/dist/core/export-html/ansi-to-html.js +1 -1
- package/dist/core/export-html/ansi-to-html.js.map +1 -1
- package/dist/core/export-html/index.d.ts +7 -4
- package/dist/core/export-html/index.d.ts.map +1 -1
- package/dist/core/export-html/index.js +15 -13
- package/dist/core/export-html/index.js.map +1 -1
- package/dist/core/export-html/template.css +112 -17
- package/dist/core/export-html/template.html +1 -0
- package/dist/core/export-html/template.js +312 -64
- package/dist/core/export-html/tool-renderer.d.ts +9 -10
- package/dist/core/export-html/tool-renderer.d.ts.map +1 -1
- package/dist/core/export-html/tool-renderer.js +61 -16
- package/dist/core/export-html/tool-renderer.js.map +1 -1
- package/dist/core/extensions/index.d.ts +5 -4
- package/dist/core/extensions/index.d.ts.map +1 -1
- package/dist/core/extensions/index.js +2 -2
- package/dist/core/extensions/index.js.map +1 -1
- package/dist/core/extensions/loader.d.ts +0 -1
- package/dist/core/extensions/loader.d.ts.map +1 -1
- package/dist/core/extensions/loader.js +98 -18
- package/dist/core/extensions/loader.js.map +1 -1
- package/dist/core/extensions/runner.d.ts +27 -14
- package/dist/core/extensions/runner.d.ts.map +1 -1
- package/dist/core/extensions/runner.js +299 -115
- package/dist/core/extensions/runner.js.map +1 -1
- package/dist/core/extensions/types.d.ts +200 -44
- package/dist/core/extensions/types.d.ts.map +1 -1
- package/dist/core/extensions/types.js +10 -0
- package/dist/core/extensions/types.js.map +1 -1
- package/dist/core/extensions/wrapper.d.ts +4 -11
- package/dist/core/extensions/wrapper.d.ts.map +1 -1
- package/dist/core/extensions/wrapper.js +7 -87
- package/dist/core/extensions/wrapper.js.map +1 -1
- package/dist/core/footer-data-provider.d.ts +22 -2
- package/dist/core/footer-data-provider.d.ts.map +1 -1
- package/dist/core/footer-data-provider.js +225 -49
- package/dist/core/footer-data-provider.js.map +1 -1
- package/dist/core/index.d.ts +5 -2
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/index.js +5 -2
- package/dist/core/index.js.map +1 -1
- package/dist/core/keybindings.d.ts +348 -50
- package/dist/core/keybindings.d.ts.map +1 -1
- package/dist/core/keybindings.js +276 -132
- package/dist/core/keybindings.js.map +1 -1
- package/dist/core/messages.d.ts.map +1 -1
- package/dist/core/messages.js.map +1 -1
- package/dist/core/model-registry.d.ts +41 -5
- package/dist/core/model-registry.d.ts.map +1 -1
- package/dist/core/model-registry.js +316 -136
- package/dist/core/model-registry.js.map +1 -1
- package/dist/core/model-resolver.d.ts +6 -0
- package/dist/core/model-resolver.d.ts.map +1 -1
- package/dist/core/model-resolver.js +70 -37
- package/dist/core/model-resolver.js.map +1 -1
- package/dist/core/output-guard.d.ts +6 -0
- package/dist/core/output-guard.d.ts.map +1 -0
- package/dist/core/output-guard.js +59 -0
- package/dist/core/output-guard.js.map +1 -0
- package/dist/core/package-manager.d.ts +49 -7
- package/dist/core/package-manager.d.ts.map +1 -1
- package/dist/core/package-manager.js +655 -122
- package/dist/core/package-manager.js.map +1 -1
- package/dist/core/prompt-templates.d.ts +12 -10
- package/dist/core/prompt-templates.d.ts.map +1 -1
- package/dist/core/prompt-templates.js +37 -38
- package/dist/core/prompt-templates.js.map +1 -1
- package/dist/core/provider-display-names.d.ts +2 -0
- package/dist/core/provider-display-names.d.ts.map +1 -0
- package/dist/core/provider-display-names.js +33 -0
- package/dist/core/provider-display-names.js.map +1 -0
- package/dist/core/resolve-config-value.d.ts +6 -0
- package/dist/core/resolve-config-value.d.ts.map +1 -1
- package/dist/core/resolve-config-value.js +75 -8
- package/dist/core/resolve-config-value.js.map +1 -1
- package/dist/core/resource-loader.d.ts +18 -8
- package/dist/core/resource-loader.d.ts.map +1 -1
- package/dist/core/resource-loader.js +217 -123
- package/dist/core/resource-loader.js.map +1 -1
- package/dist/core/sdk.d.ts +25 -8
- package/dist/core/sdk.d.ts.map +1 -1
- package/dist/core/sdk.js +84 -37
- package/dist/core/sdk.js.map +1 -1
- package/dist/core/session-cwd.d.ts +19 -0
- package/dist/core/session-cwd.d.ts.map +1 -0
- package/dist/core/session-cwd.js +38 -0
- package/dist/core/session-cwd.js.map +1 -0
- package/dist/core/session-manager.d.ts +11 -1
- package/dist/core/session-manager.d.ts.map +1 -1
- package/dist/core/session-manager.js +42 -27
- package/dist/core/session-manager.js.map +1 -1
- package/dist/core/settings-manager.d.ts +34 -5
- package/dist/core/settings-manager.d.ts.map +1 -1
- package/dist/core/settings-manager.js +113 -13
- package/dist/core/settings-manager.js.map +1 -1
- package/dist/core/skills.d.ts +13 -11
- package/dist/core/skills.d.ts.map +1 -1
- package/dist/core/skills.js +59 -19
- package/dist/core/skills.js.map +1 -1
- package/dist/core/slash-commands.d.ts +2 -3
- package/dist/core/slash-commands.d.ts.map +1 -1
- package/dist/core/slash-commands.js +9 -6
- package/dist/core/slash-commands.js.map +1 -1
- package/dist/core/source-info.d.ts +18 -0
- package/dist/core/source-info.d.ts.map +1 -0
- package/dist/core/source-info.js +19 -0
- package/dist/core/source-info.js.map +1 -0
- package/dist/core/system-prompt.d.ts +3 -3
- package/dist/core/system-prompt.d.ts.map +1 -1
- package/dist/core/system-prompt.js +16 -55
- package/dist/core/system-prompt.js.map +1 -1
- package/dist/core/telemetry.d.ts +3 -0
- package/dist/core/telemetry.d.ts.map +1 -0
- package/dist/core/telemetry.js +9 -0
- package/dist/core/telemetry.js.map +1 -0
- package/dist/core/timings.d.ts +1 -0
- package/dist/core/timings.d.ts.map +1 -1
- package/dist/core/timings.js +6 -0
- package/dist/core/timings.js.map +1 -1
- package/dist/core/tools/bash.d.ts +27 -14
- package/dist/core/tools/bash.d.ts.map +1 -1
- package/dist/core/tools/bash.js +301 -208
- package/dist/core/tools/bash.js.map +1 -1
- package/dist/core/tools/edit-diff.d.ts +23 -1
- package/dist/core/tools/edit-diff.d.ts.map +1 -1
- package/dist/core/tools/edit-diff.js +154 -59
- package/dist/core/tools/edit-diff.js.map +1 -1
- package/dist/core/tools/edit.d.ts +22 -12
- package/dist/core/tools/edit.d.ts.map +1 -1
- package/dist/core/tools/edit.js +243 -65
- package/dist/core/tools/edit.js.map +1 -1
- package/dist/core/tools/file-mutation-queue.d.ts +6 -0
- package/dist/core/tools/file-mutation-queue.d.ts.map +1 -0
- package/dist/core/tools/file-mutation-queue.js +37 -0
- package/dist/core/tools/file-mutation-queue.js.map +1 -0
- package/dist/core/tools/find.d.ts +10 -14
- package/dist/core/tools/find.d.ts.map +1 -1
- package/dist/core/tools/find.js +202 -110
- package/dist/core/tools/find.js.map +1 -1
- package/dist/core/tools/grep.d.ts +14 -22
- package/dist/core/tools/grep.d.ts.map +1 -1
- package/dist/core/tools/grep.js +100 -35
- package/dist/core/tools/grep.js.map +1 -1
- package/dist/core/tools/index.d.ts +27 -60
- package/dist/core/tools/index.d.ts.map +1 -1
- package/dist/core/tools/index.js +96 -45
- package/dist/core/tools/index.js.map +1 -1
- package/dist/core/tools/ls.d.ts +8 -11
- package/dist/core/tools/ls.d.ts.map +1 -1
- package/dist/core/tools/ls.js +66 -15
- package/dist/core/tools/ls.js.map +1 -1
- package/dist/core/tools/output-accumulator.d.ts +50 -0
- package/dist/core/tools/output-accumulator.d.ts.map +1 -0
- package/dist/core/tools/output-accumulator.js +178 -0
- package/dist/core/tools/output-accumulator.js.map +1 -0
- package/dist/core/tools/path-utils.d.ts.map +1 -1
- package/dist/core/tools/path-utils.js +1 -1
- package/dist/core/tools/path-utils.js.map +1 -1
- package/dist/core/tools/read.d.ts +9 -13
- package/dist/core/tools/read.d.ts.map +1 -1
- package/dist/core/tools/read.js +175 -52
- package/dist/core/tools/read.js.map +1 -1
- package/dist/core/tools/render-utils.d.ts +21 -0
- package/dist/core/tools/render-utils.d.ts.map +1 -0
- package/dist/core/tools/render-utils.js +49 -0
- package/dist/core/tools/render-utils.js.map +1 -0
- package/dist/core/tools/tool-definition-wrapper.d.ts +14 -0
- package/dist/core/tools/tool-definition-wrapper.d.ts.map +1 -0
- package/dist/core/tools/tool-definition-wrapper.js +34 -0
- package/dist/core/tools/tool-definition-wrapper.js.map +1 -0
- package/dist/core/tools/truncate.d.ts.map +1 -1
- package/dist/core/tools/truncate.js.map +1 -1
- package/dist/core/tools/write.d.ts +8 -11
- package/dist/core/tools/write.d.ts.map +1 -1
- package/dist/core/tools/write.js +167 -32
- package/dist/core/tools/write.js.map +1 -1
- package/dist/index.d.ts +12 -9
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +12 -10
- package/dist/index.js.map +1 -1
- package/dist/main.d.ts +5 -1
- package/dist/main.d.ts.map +1 -1
- package/dist/main.js +326 -404
- package/dist/main.js.map +1 -1
- package/dist/migrations.d.ts +2 -2
- package/dist/migrations.d.ts.map +1 -1
- package/dist/migrations.js +24 -4
- package/dist/migrations.js.map +1 -1
- package/dist/modes/index.d.ts.map +1 -1
- package/dist/modes/interactive/components/armin.d.ts.map +1 -1
- package/dist/modes/interactive/components/armin.js +10 -6
- package/dist/modes/interactive/components/armin.js.map +1 -1
- package/dist/modes/interactive/components/assistant-message.d.ts +5 -1
- package/dist/modes/interactive/components/assistant-message.d.ts.map +1 -1
- package/dist/modes/interactive/components/assistant-message.js +32 -3
- package/dist/modes/interactive/components/assistant-message.js.map +1 -1
- package/dist/modes/interactive/components/bash-execution.d.ts +0 -1
- package/dist/modes/interactive/components/bash-execution.d.ts.map +1 -1
- package/dist/modes/interactive/components/bash-execution.js +31 -12
- package/dist/modes/interactive/components/bash-execution.js.map +1 -1
- package/dist/modes/interactive/components/bordered-loader.d.ts.map +1 -1
- package/dist/modes/interactive/components/bordered-loader.js +7 -1
- package/dist/modes/interactive/components/bordered-loader.js.map +1 -1
- package/dist/modes/interactive/components/branch-summary-message.d.ts.map +1 -1
- package/dist/modes/interactive/components/branch-summary-message.js +5 -3
- package/dist/modes/interactive/components/branch-summary-message.js.map +1 -1
- package/dist/modes/interactive/components/compaction-summary-message.d.ts.map +1 -1
- package/dist/modes/interactive/components/compaction-summary-message.js +5 -3
- package/dist/modes/interactive/components/compaction-summary-message.js.map +1 -1
- package/dist/modes/interactive/components/config-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/config-selector.js +49 -16
- package/dist/modes/interactive/components/config-selector.js.map +1 -1
- package/dist/modes/interactive/components/countdown-timer.d.ts.map +1 -1
- package/dist/modes/interactive/components/countdown-timer.js +5 -0
- package/dist/modes/interactive/components/countdown-timer.js.map +1 -1
- package/dist/modes/interactive/components/custom-editor.d.ts +3 -3
- package/dist/modes/interactive/components/custom-editor.d.ts.map +1 -1
- package/dist/modes/interactive/components/custom-editor.js +14 -7
- package/dist/modes/interactive/components/custom-editor.js.map +1 -1
- package/dist/modes/interactive/components/custom-message.d.ts.map +1 -1
- package/dist/modes/interactive/components/custom-message.js +6 -1
- package/dist/modes/interactive/components/custom-message.js.map +1 -1
- package/dist/modes/interactive/components/daxnuts.d.ts.map +1 -1
- package/dist/modes/interactive/components/daxnuts.js +8 -6
- package/dist/modes/interactive/components/daxnuts.js.map +1 -1
- package/dist/modes/interactive/components/diff.d.ts.map +1 -1
- package/dist/modes/interactive/components/diff.js.map +1 -1
- package/dist/modes/interactive/components/dynamic-border.d.ts.map +1 -1
- package/dist/modes/interactive/components/dynamic-border.js +1 -0
- package/dist/modes/interactive/components/dynamic-border.js.map +1 -1
- package/dist/modes/interactive/components/earendil-announcement.d.ts +5 -0
- package/dist/modes/interactive/components/earendil-announcement.d.ts.map +1 -0
- package/dist/modes/interactive/components/earendil-announcement.js +40 -0
- package/dist/modes/interactive/components/earendil-announcement.js.map +1 -0
- package/dist/modes/interactive/components/extension-editor.d.ts.map +1 -1
- package/dist/modes/interactive/components/extension-editor.js +16 -10
- package/dist/modes/interactive/components/extension-editor.js.map +1 -1
- package/dist/modes/interactive/components/extension-input.d.ts.map +1 -1
- package/dist/modes/interactive/components/extension-input.js +13 -7
- package/dist/modes/interactive/components/extension-input.js.map +1 -1
- package/dist/modes/interactive/components/extension-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/extension-selector.js +18 -11
- package/dist/modes/interactive/components/extension-selector.js.map +1 -1
- package/dist/modes/interactive/components/footer.d.ts +1 -0
- package/dist/modes/interactive/components/footer.d.ts.map +1 -1
- package/dist/modes/interactive/components/footer.js +7 -2
- package/dist/modes/interactive/components/footer.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/keybinding-hints.d.ts +8 -36
- package/dist/modes/interactive/components/keybinding-hints.d.ts.map +1 -1
- package/dist/modes/interactive/components/keybinding-hints.js +23 -48
- package/dist/modes/interactive/components/keybinding-hints.js.map +1 -1
- package/dist/modes/interactive/components/login-dialog.d.ts +5 -1
- package/dist/modes/interactive/components/login-dialog.d.ts.map +1 -1
- package/dist/modes/interactive/components/login-dialog.js +35 -14
- package/dist/modes/interactive/components/login-dialog.js.map +1 -1
- package/dist/modes/interactive/components/model-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/model-selector.js +41 -22
- package/dist/modes/interactive/components/model-selector.js.map +1 -1
- package/dist/modes/interactive/components/oauth-selector.d.ts +18 -6
- package/dist/modes/interactive/components/oauth-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/oauth-selector.js +104 -31
- package/dist/modes/interactive/components/oauth-selector.js.map +1 -1
- package/dist/modes/interactive/components/scoped-models-selector.d.ts +5 -12
- package/dist/modes/interactive/components/scoped-models-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/scoped-models-selector.js +61 -42
- package/dist/modes/interactive/components/scoped-models-selector.js.map +1 -1
- package/dist/modes/interactive/components/session-selector-search.d.ts.map +1 -1
- package/dist/modes/interactive/components/session-selector-search.js.map +1 -1
- package/dist/modes/interactive/components/session-selector.d.ts +2 -1
- package/dist/modes/interactive/components/session-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/session-selector.js +109 -73
- package/dist/modes/interactive/components/session-selector.js.map +1 -1
- package/dist/modes/interactive/components/settings-selector.d.ts +9 -0
- package/dist/modes/interactive/components/settings-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/settings-selector.js +84 -4
- package/dist/modes/interactive/components/settings-selector.js.map +1 -1
- package/dist/modes/interactive/components/show-images-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/show-images-selector.js +6 -1
- package/dist/modes/interactive/components/show-images-selector.js.map +1 -1
- package/dist/modes/interactive/components/skill-invocation-message.d.ts.map +1 -1
- package/dist/modes/interactive/components/skill-invocation-message.js +5 -3
- package/dist/modes/interactive/components/skill-invocation-message.js.map +1 -1
- package/dist/modes/interactive/components/theme-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/theme-selector.js +7 -1
- package/dist/modes/interactive/components/theme-selector.js.map +1 -1
- package/dist/modes/interactive/components/thinking-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/thinking-selector.js +6 -1
- package/dist/modes/interactive/components/thinking-selector.js.map +1 -1
- package/dist/modes/interactive/components/tool-execution.d.ts +20 -34
- package/dist/modes/interactive/components/tool-execution.d.ts.map +1 -1
- package/dist/modes/interactive/components/tool-execution.js +158 -636
- package/dist/modes/interactive/components/tool-execution.js.map +1 -1
- package/dist/modes/interactive/components/tree-selector.d.ts +21 -2
- package/dist/modes/interactive/components/tree-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/tree-selector.js +224 -52
- package/dist/modes/interactive/components/tree-selector.js.map +1 -1
- package/dist/modes/interactive/components/user-message-selector.d.ts +2 -2
- package/dist/modes/interactive/components/user-message-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/user-message-selector.js +20 -16
- package/dist/modes/interactive/components/user-message-selector.js.map +1 -1
- package/dist/modes/interactive/components/user-message.d.ts +1 -0
- package/dist/modes/interactive/components/user-message.d.ts.map +1 -1
- package/dist/modes/interactive/components/user-message.js +8 -6
- package/dist/modes/interactive/components/user-message.js.map +1 -1
- package/dist/modes/interactive/components/visual-truncate.d.ts.map +1 -1
- package/dist/modes/interactive/components/visual-truncate.js.map +1 -1
- package/dist/modes/interactive/interactive-mode.d.ts +67 -39
- package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode.js +1587 -710
- package/dist/modes/interactive/interactive-mode.js.map +1 -1
- package/dist/modes/interactive/theme/dark.json +1 -1
- package/dist/modes/interactive/theme/light.json +1 -1
- package/dist/modes/interactive/theme/theme.d.ts +3 -0
- package/dist/modes/interactive/theme/theme.d.ts.map +1 -1
- package/dist/modes/interactive/theme/theme.js +101 -72
- package/dist/modes/interactive/theme/theme.js.map +1 -1
- package/dist/modes/print-mode.d.ts +2 -2
- package/dist/modes/print-mode.d.ts.map +1 -1
- package/dist/modes/print-mode.js +107 -77
- package/dist/modes/print-mode.js.map +1 -1
- package/dist/modes/rpc/jsonl.d.ts +17 -0
- package/dist/modes/rpc/jsonl.d.ts.map +1 -0
- package/dist/modes/rpc/jsonl.js +49 -0
- package/dist/modes/rpc/jsonl.js.map +1 -0
- package/dist/modes/rpc/rpc-client.d.ts +8 -1
- package/dist/modes/rpc/rpc-client.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-client.js +22 -16
- package/dist/modes/rpc/rpc-client.js.map +1 -1
- package/dist/modes/rpc/rpc-mode.d.ts +2 -2
- package/dist/modes/rpc/rpc-mode.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-mode.js +184 -94
- package/dist/modes/rpc/rpc-mode.js.map +1 -1
- package/dist/modes/rpc/rpc-types.d.ts +14 -4
- package/dist/modes/rpc/rpc-types.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-types.js.map +1 -1
- package/dist/package-manager-cli.d.ts +4 -0
- package/dist/package-manager-cli.d.ts.map +1 -0
- package/dist/package-manager-cli.js +460 -0
- package/dist/package-manager-cli.js.map +1 -0
- package/dist/utils/changelog.d.ts.map +1 -1
- package/dist/utils/changelog.js.map +1 -1
- package/dist/utils/child-process.d.ts +12 -0
- package/dist/utils/child-process.d.ts.map +1 -0
- package/dist/utils/child-process.js +86 -0
- package/dist/utils/child-process.js.map +1 -0
- package/dist/utils/clipboard-image.d.ts.map +1 -1
- package/dist/utils/clipboard-image.js +94 -11
- package/dist/utils/clipboard-image.js.map +1 -1
- package/dist/utils/clipboard-native.d.ts +1 -0
- package/dist/utils/clipboard-native.d.ts.map +1 -1
- package/dist/utils/clipboard-native.js.map +1 -1
- package/dist/utils/clipboard.d.ts +1 -1
- package/dist/utils/clipboard.d.ts.map +1 -1
- package/dist/utils/clipboard.js +96 -46
- package/dist/utils/clipboard.js.map +1 -1
- package/dist/utils/exif-orientation.d.ts +5 -0
- package/dist/utils/exif-orientation.d.ts.map +1 -0
- package/dist/utils/exif-orientation.js +158 -0
- package/dist/utils/exif-orientation.js.map +1 -0
- package/dist/utils/frontmatter.d.ts.map +1 -1
- package/dist/utils/frontmatter.js.map +1 -1
- package/dist/utils/fs-watch.d.ts +5 -0
- package/dist/utils/fs-watch.d.ts.map +1 -0
- package/dist/utils/fs-watch.js +25 -0
- package/dist/utils/fs-watch.js.map +1 -0
- package/dist/utils/git.d.ts.map +1 -1
- package/dist/utils/git.js.map +1 -1
- package/dist/utils/image-convert.d.ts.map +1 -1
- package/dist/utils/image-convert.js +5 -1
- package/dist/utils/image-convert.js.map +1 -1
- package/dist/utils/image-resize.d.ts +5 -5
- package/dist/utils/image-resize.d.ts.map +1 -1
- package/dist/utils/image-resize.js +51 -95
- package/dist/utils/image-resize.js.map +1 -1
- package/dist/utils/mime.d.ts.map +1 -1
- package/dist/utils/mime.js.map +1 -1
- package/dist/utils/paths.d.ts +16 -0
- package/dist/utils/paths.d.ts.map +1 -0
- package/dist/utils/paths.js +50 -0
- package/dist/utils/paths.js.map +1 -0
- package/dist/utils/photon.d.ts.map +1 -1
- package/dist/utils/photon.js.map +1 -1
- package/dist/utils/pi-user-agent.d.ts +2 -0
- package/dist/utils/pi-user-agent.d.ts.map +1 -0
- package/dist/utils/pi-user-agent.js +5 -0
- package/dist/utils/pi-user-agent.js.map +1 -0
- package/dist/utils/shell.d.ts +10 -6
- package/dist/utils/shell.d.ts.map +1 -1
- package/dist/utils/shell.js +29 -25
- package/dist/utils/shell.js.map +1 -1
- package/dist/utils/sleep.d.ts.map +1 -1
- package/dist/utils/sleep.js.map +1 -1
- package/dist/utils/tools-manager.d.ts.map +1 -1
- package/dist/utils/tools-manager.js +11 -6
- package/dist/utils/tools-manager.js.map +1 -1
- package/dist/utils/version-check.d.ts +14 -0
- package/dist/utils/version-check.d.ts.map +1 -0
- package/dist/utils/version-check.js +77 -0
- package/dist/utils/version-check.js.map +1 -0
- package/docs/compaction.md +394 -0
- package/docs/custom-provider.md +646 -0
- package/docs/development.md +71 -0
- package/docs/docs.json +148 -0
- package/docs/extensions.md +2596 -0
- package/docs/images/doom-extension.png +0 -0
- package/docs/images/exy.png +0 -0
- package/docs/images/interactive-mode.png +0 -0
- package/docs/images/tree-view.png +0 -0
- package/docs/index.md +70 -0
- package/docs/json.md +82 -0
- package/docs/keybindings.md +197 -0
- package/docs/models.md +474 -0
- package/docs/packages.md +223 -0
- package/docs/prompt-templates.md +88 -0
- package/docs/providers.md +243 -0
- package/docs/quickstart.md +142 -0
- package/docs/rpc.md +1407 -0
- package/docs/sdk.md +1149 -0
- package/docs/session-format.md +412 -0
- package/docs/sessions.md +137 -0
- package/docs/settings.md +279 -0
- package/docs/shell-aliases.md +13 -0
- package/docs/skills.md +232 -0
- package/docs/terminal-setup.md +106 -0
- package/docs/termux.md +127 -0
- package/docs/themes.md +295 -0
- package/docs/tmux.md +61 -0
- package/docs/tui.md +918 -0
- package/docs/usage.md +277 -0
- package/docs/windows.md +17 -0
- package/examples/README.md +25 -0
- package/examples/extensions/README.md +208 -0
- package/examples/extensions/auto-commit-on-exit.ts +49 -0
- package/examples/extensions/bash-spawn-hook.ts +30 -0
- package/examples/extensions/bookmark.ts +50 -0
- package/examples/extensions/border-status-editor.ts +150 -0
- package/examples/extensions/built-in-tool-renderer.ts +249 -0
- package/examples/extensions/claude-rules.ts +86 -0
- package/examples/extensions/commands.ts +72 -0
- package/examples/extensions/confirm-destructive.ts +59 -0
- package/examples/extensions/custom-compaction.ts +127 -0
- package/examples/extensions/custom-footer.ts +64 -0
- package/examples/extensions/custom-header.ts +73 -0
- package/examples/extensions/custom-provider-anthropic/index.ts +604 -0
- package/examples/extensions/custom-provider-anthropic/package-lock.json +24 -0
- package/examples/extensions/custom-provider-anthropic/package.json +19 -0
- package/examples/extensions/custom-provider-gitlab-duo/index.ts +349 -0
- package/examples/extensions/custom-provider-gitlab-duo/package.json +16 -0
- package/examples/extensions/custom-provider-gitlab-duo/test.ts +82 -0
- package/examples/extensions/dirty-repo-guard.ts +56 -0
- package/examples/extensions/doom-overlay/README.md +46 -0
- package/examples/extensions/doom-overlay/doom/build/doom.js +21 -0
- package/examples/extensions/doom-overlay/doom/build/doom.wasm +0 -0
- package/examples/extensions/doom-overlay/doom/build.sh +152 -0
- package/examples/extensions/doom-overlay/doom/doomgeneric_pi.c +72 -0
- package/examples/extensions/doom-overlay/doom-component.ts +132 -0
- package/examples/extensions/doom-overlay/doom-engine.ts +173 -0
- package/examples/extensions/doom-overlay/doom-keys.ts +104 -0
- package/examples/extensions/doom-overlay/index.ts +74 -0
- package/examples/extensions/doom-overlay/wad-finder.ts +51 -0
- package/examples/extensions/dynamic-resources/SKILL.md +8 -0
- package/examples/extensions/dynamic-resources/dynamic.json +79 -0
- package/examples/extensions/dynamic-resources/dynamic.md +5 -0
- package/examples/extensions/dynamic-resources/index.ts +15 -0
- package/examples/extensions/dynamic-tools.ts +74 -0
- package/examples/extensions/event-bus.ts +43 -0
- package/examples/extensions/file-trigger.ts +41 -0
- package/examples/extensions/git-checkpoint.ts +53 -0
- package/examples/extensions/github-issue-autocomplete.ts +185 -0
- package/examples/extensions/handoff.ts +191 -0
- package/examples/extensions/hello.ts +26 -0
- package/examples/extensions/hidden-thinking-label.ts +53 -0
- package/examples/extensions/inline-bash.ts +94 -0
- package/examples/extensions/input-transform.ts +43 -0
- package/examples/extensions/interactive-shell.ts +196 -0
- package/examples/extensions/mac-system-theme.ts +47 -0
- package/examples/extensions/message-renderer.ts +59 -0
- package/examples/extensions/minimal-mode.ts +426 -0
- package/examples/extensions/modal-editor.ts +85 -0
- package/examples/extensions/model-status.ts +31 -0
- package/examples/extensions/notify.ts +55 -0
- package/examples/extensions/overlay-qa-tests.ts +1348 -0
- package/examples/extensions/overlay-test.ts +150 -0
- package/examples/extensions/permission-gate.ts +34 -0
- package/examples/extensions/pirate.ts +47 -0
- package/examples/extensions/plan-mode/README.md +65 -0
- package/examples/extensions/plan-mode/index.ts +340 -0
- package/examples/extensions/plan-mode/utils.ts +168 -0
- package/examples/extensions/preset.ts +430 -0
- package/examples/extensions/prompt-customizer.ts +97 -0
- package/examples/extensions/protected-paths.ts +30 -0
- package/examples/extensions/provider-payload.ts +18 -0
- package/examples/extensions/qna.ts +122 -0
- package/examples/extensions/question.ts +264 -0
- package/examples/extensions/questionnaire.ts +427 -0
- package/examples/extensions/rainbow-editor.ts +88 -0
- package/examples/extensions/reload-runtime.ts +37 -0
- package/examples/extensions/rpc-demo.ts +118 -0
- package/examples/extensions/sandbox/index.ts +321 -0
- package/examples/extensions/sandbox/package-lock.json +92 -0
- package/examples/extensions/sandbox/package.json +19 -0
- package/examples/extensions/send-user-message.ts +97 -0
- package/examples/extensions/session-name.ts +27 -0
- package/examples/extensions/shutdown-command.ts +63 -0
- package/examples/extensions/snake.ts +343 -0
- package/examples/extensions/space-invaders.ts +560 -0
- package/examples/extensions/ssh.ts +220 -0
- package/examples/extensions/status-line.ts +32 -0
- package/examples/extensions/structured-output.ts +65 -0
- package/examples/extensions/subagent/README.md +172 -0
- package/examples/extensions/subagent/agents/planner.md +37 -0
- package/examples/extensions/subagent/agents/reviewer.md +35 -0
- package/examples/extensions/subagent/agents/scout.md +50 -0
- package/examples/extensions/subagent/agents/worker.md +24 -0
- package/examples/extensions/subagent/agents.ts +126 -0
- package/examples/extensions/subagent/index.ts +987 -0
- package/examples/extensions/subagent/prompts/implement-and-review.md +10 -0
- package/examples/extensions/subagent/prompts/implement.md +10 -0
- package/examples/extensions/subagent/prompts/scout-and-plan.md +9 -0
- package/examples/extensions/summarize.ts +206 -0
- package/examples/extensions/system-prompt-header.ts +17 -0
- package/examples/extensions/tic-tac-toe.ts +1008 -0
- package/examples/extensions/timed-confirm.ts +70 -0
- package/examples/extensions/titlebar-spinner.ts +58 -0
- package/examples/extensions/todo.ts +297 -0
- package/examples/extensions/tool-override.ts +144 -0
- package/examples/extensions/tools.ts +141 -0
- package/examples/extensions/trigger-compact.ts +50 -0
- package/examples/extensions/truncated-tool.ts +195 -0
- package/examples/extensions/widget-placement.ts +9 -0
- package/examples/extensions/with-deps/index.ts +32 -0
- package/examples/extensions/with-deps/package-lock.json +31 -0
- package/examples/extensions/with-deps/package.json +22 -0
- package/examples/extensions/working-indicator.ts +123 -0
- package/examples/extensions/working-message-test.ts +25 -0
- package/examples/rpc-extension-ui.ts +632 -0
- package/examples/sdk/01-minimal.ts +22 -0
- package/examples/sdk/02-custom-model.ts +49 -0
- package/examples/sdk/03-custom-prompt.ts +62 -0
- package/examples/sdk/04-skills.ts +55 -0
- package/examples/sdk/05-tools.ts +44 -0
- package/examples/sdk/06-extensions.ts +90 -0
- package/examples/sdk/07-context-files.ts +42 -0
- package/examples/sdk/08-prompt-templates.ts +51 -0
- package/examples/sdk/09-api-keys-and-oauth.ts +48 -0
- package/examples/sdk/10-settings.ts +53 -0
- package/examples/sdk/11-sessions.ts +48 -0
- package/examples/sdk/12-full-control.ts +73 -0
- package/examples/sdk/13-session-runtime.ts +67 -0
- package/examples/sdk/README.md +147 -0
- package/extensions/phi/init.ts +15 -1
- package/extensions/phi/keys.ts +186 -0
- package/extensions/phi/providers/alibaba.ts +126 -0
- package/extensions/phi/providers/opencode-go.ts +204 -0
- package/extensions/phi/setup.ts +692 -0
- package/extensions/phi/smart-router.ts +8 -0
- package/package.json +17 -12
- package/scripts/copy-assets.sh +0 -0
- package/scripts/migrate-sessions.sh +0 -0
package/dist/core/tools/bash.js
CHANGED
|
@@ -1,242 +1,335 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { createWriteStream, existsSync } from "node:fs";
|
|
3
|
-
import { tmpdir } from "node:os";
|
|
4
|
-
import { join } from "node:path";
|
|
5
|
-
import { Type } from "@sinclair/typebox";
|
|
1
|
+
import { existsSync } from "node:fs";
|
|
6
2
|
import { spawn } from "child_process";
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
}
|
|
3
|
+
import { Container, Text, truncateToWidth } from "phi-code-tui";
|
|
4
|
+
import { Type } from "typebox";
|
|
5
|
+
import { keyHint } from "../../modes/interactive/components/keybinding-hints.js";
|
|
6
|
+
import { truncateToVisualLines } from "../../modes/interactive/components/visual-truncate.js";
|
|
7
|
+
import { theme } from "../../modes/interactive/theme/theme.js";
|
|
8
|
+
import { waitForChildProcess } from "../../utils/child-process.js";
|
|
9
|
+
import { getShellConfig, getShellEnv, killProcessTree, trackDetachedChildPid, untrackDetachedChildPid, } from "../../utils/shell.js";
|
|
10
|
+
import { OutputAccumulator } from "./output-accumulator.js";
|
|
11
|
+
import { getTextOutput, invalidArgText, str } from "./render-utils.js";
|
|
12
|
+
import { wrapToolDefinition } from "./tool-definition-wrapper.js";
|
|
13
|
+
import { DEFAULT_MAX_BYTES, DEFAULT_MAX_LINES, formatSize } from "./truncate.js";
|
|
16
14
|
const bashSchema = Type.Object({
|
|
17
15
|
command: Type.String({ description: "Bash command to execute" }),
|
|
18
16
|
timeout: Type.Optional(Type.Number({ description: "Timeout in seconds (optional, no default timeout)" })),
|
|
19
17
|
});
|
|
20
18
|
/**
|
|
21
|
-
*
|
|
19
|
+
* Create bash operations using pi's built-in local shell execution backend.
|
|
20
|
+
*
|
|
21
|
+
* This is useful for extensions that intercept user_bash and still want pi's
|
|
22
|
+
* standard local shell behavior while wrapping or rewriting commands.
|
|
22
23
|
*/
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
}
|
|
31
|
-
const child = spawn(shell, [...args, command], {
|
|
32
|
-
cwd,
|
|
33
|
-
detached: true,
|
|
34
|
-
env: env ?? getShellEnv(),
|
|
35
|
-
stdio: ["ignore", "pipe", "pipe"],
|
|
36
|
-
});
|
|
37
|
-
let timedOut = false;
|
|
38
|
-
// Set timeout if provided
|
|
39
|
-
let timeoutHandle;
|
|
40
|
-
if (timeout !== undefined && timeout > 0) {
|
|
41
|
-
timeoutHandle = setTimeout(() => {
|
|
42
|
-
timedOut = true;
|
|
43
|
-
if (child.pid) {
|
|
44
|
-
killProcessTree(child.pid);
|
|
45
|
-
}
|
|
46
|
-
}, timeout * 1000);
|
|
47
|
-
}
|
|
48
|
-
// Stream stdout and stderr
|
|
49
|
-
if (child.stdout) {
|
|
50
|
-
child.stdout.on("data", onData);
|
|
51
|
-
}
|
|
52
|
-
if (child.stderr) {
|
|
53
|
-
child.stderr.on("data", onData);
|
|
54
|
-
}
|
|
55
|
-
// Handle shell spawn errors
|
|
56
|
-
child.on("error", (err) => {
|
|
57
|
-
if (timeoutHandle)
|
|
58
|
-
clearTimeout(timeoutHandle);
|
|
59
|
-
if (signal)
|
|
60
|
-
signal.removeEventListener("abort", onAbort);
|
|
61
|
-
reject(err);
|
|
62
|
-
});
|
|
63
|
-
// Handle abort signal - kill entire process tree
|
|
64
|
-
const onAbort = () => {
|
|
65
|
-
if (child.pid) {
|
|
66
|
-
killProcessTree(child.pid);
|
|
67
|
-
}
|
|
68
|
-
};
|
|
69
|
-
if (signal) {
|
|
70
|
-
if (signal.aborted) {
|
|
71
|
-
onAbort();
|
|
72
|
-
}
|
|
73
|
-
else {
|
|
74
|
-
signal.addEventListener("abort", onAbort, { once: true });
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
// Handle process exit
|
|
78
|
-
child.on("close", (code) => {
|
|
79
|
-
if (timeoutHandle)
|
|
80
|
-
clearTimeout(timeoutHandle);
|
|
81
|
-
if (signal)
|
|
82
|
-
signal.removeEventListener("abort", onAbort);
|
|
83
|
-
if (signal?.aborted) {
|
|
84
|
-
reject(new Error("aborted"));
|
|
24
|
+
export function createLocalBashOperations(options) {
|
|
25
|
+
return {
|
|
26
|
+
exec: (command, cwd, { onData, signal, timeout, env }) => {
|
|
27
|
+
return new Promise((resolve, reject) => {
|
|
28
|
+
const { shell, args } = getShellConfig(options?.shellPath);
|
|
29
|
+
if (!existsSync(cwd)) {
|
|
30
|
+
reject(new Error(`Working directory does not exist: ${cwd}\nCannot execute bash commands.`));
|
|
85
31
|
return;
|
|
86
32
|
}
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
33
|
+
const child = spawn(shell, [...args, command], {
|
|
34
|
+
cwd,
|
|
35
|
+
detached: process.platform !== "win32",
|
|
36
|
+
env: env ?? getShellEnv(),
|
|
37
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
38
|
+
});
|
|
39
|
+
if (child.pid)
|
|
40
|
+
trackDetachedChildPid(child.pid);
|
|
41
|
+
let timedOut = false;
|
|
42
|
+
let timeoutHandle;
|
|
43
|
+
// Set timeout if provided.
|
|
44
|
+
if (timeout !== undefined && timeout > 0) {
|
|
45
|
+
timeoutHandle = setTimeout(() => {
|
|
46
|
+
timedOut = true;
|
|
47
|
+
if (child.pid)
|
|
48
|
+
killProcessTree(child.pid);
|
|
49
|
+
}, timeout * 1000);
|
|
90
50
|
}
|
|
91
|
-
|
|
51
|
+
// Stream stdout and stderr.
|
|
52
|
+
child.stdout?.on("data", onData);
|
|
53
|
+
child.stderr?.on("data", onData);
|
|
54
|
+
// Handle abort signal by killing the entire process tree.
|
|
55
|
+
const onAbort = () => {
|
|
56
|
+
if (child.pid)
|
|
57
|
+
killProcessTree(child.pid);
|
|
58
|
+
};
|
|
59
|
+
if (signal) {
|
|
60
|
+
if (signal.aborted)
|
|
61
|
+
onAbort();
|
|
62
|
+
else
|
|
63
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
64
|
+
}
|
|
65
|
+
// Handle shell spawn errors and wait for the process to terminate without hanging
|
|
66
|
+
// on inherited stdio handles held by detached descendants.
|
|
67
|
+
waitForChildProcess(child)
|
|
68
|
+
.then((code) => {
|
|
69
|
+
if (child.pid)
|
|
70
|
+
untrackDetachedChildPid(child.pid);
|
|
71
|
+
if (timeoutHandle)
|
|
72
|
+
clearTimeout(timeoutHandle);
|
|
73
|
+
if (signal)
|
|
74
|
+
signal.removeEventListener("abort", onAbort);
|
|
75
|
+
if (signal?.aborted) {
|
|
76
|
+
reject(new Error("aborted"));
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
if (timedOut) {
|
|
80
|
+
reject(new Error(`timeout:${timeout}`));
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
resolve({ exitCode: code });
|
|
84
|
+
})
|
|
85
|
+
.catch((err) => {
|
|
86
|
+
if (child.pid)
|
|
87
|
+
untrackDetachedChildPid(child.pid);
|
|
88
|
+
if (timeoutHandle)
|
|
89
|
+
clearTimeout(timeoutHandle);
|
|
90
|
+
if (signal)
|
|
91
|
+
signal.removeEventListener("abort", onAbort);
|
|
92
|
+
reject(err);
|
|
93
|
+
});
|
|
92
94
|
});
|
|
93
|
-
}
|
|
94
|
-
},
|
|
95
|
-
};
|
|
96
|
-
function resolveSpawnContext(command, cwd, spawnHook) {
|
|
97
|
-
const baseContext = {
|
|
98
|
-
command,
|
|
99
|
-
cwd,
|
|
100
|
-
env: { ...getShellEnv() },
|
|
95
|
+
},
|
|
101
96
|
};
|
|
97
|
+
}
|
|
98
|
+
function resolveSpawnContext(command, cwd, spawnHook) {
|
|
99
|
+
const baseContext = { command, cwd, env: { ...getShellEnv() } };
|
|
102
100
|
return spawnHook ? spawnHook(baseContext) : baseContext;
|
|
103
101
|
}
|
|
104
|
-
|
|
105
|
-
|
|
102
|
+
const BASH_PREVIEW_LINES = 5;
|
|
103
|
+
const BASH_UPDATE_THROTTLE_MS = 100;
|
|
104
|
+
class BashResultRenderComponent extends Container {
|
|
105
|
+
state = {
|
|
106
|
+
cachedWidth: undefined,
|
|
107
|
+
cachedLines: undefined,
|
|
108
|
+
cachedSkipped: undefined,
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
function formatDuration(ms) {
|
|
112
|
+
return `${(ms / 1000).toFixed(1)}s`;
|
|
113
|
+
}
|
|
114
|
+
function formatBashCall(args) {
|
|
115
|
+
const command = str(args?.command);
|
|
116
|
+
const timeout = args?.timeout;
|
|
117
|
+
const timeoutSuffix = timeout ? theme.fg("muted", ` (timeout ${timeout}s)`) : "";
|
|
118
|
+
const commandDisplay = command === null ? invalidArgText(theme) : command ? command : theme.fg("toolOutput", "...");
|
|
119
|
+
return theme.fg("toolTitle", theme.bold(`$ ${commandDisplay}`)) + timeoutSuffix;
|
|
120
|
+
}
|
|
121
|
+
function rebuildBashResultRenderComponent(component, result, options, showImages, startedAt, endedAt) {
|
|
122
|
+
const state = component.state;
|
|
123
|
+
component.clear();
|
|
124
|
+
const output = getTextOutput(result, showImages).trim();
|
|
125
|
+
if (output) {
|
|
126
|
+
const styledOutput = output
|
|
127
|
+
.split("\n")
|
|
128
|
+
.map((line) => theme.fg("toolOutput", line))
|
|
129
|
+
.join("\n");
|
|
130
|
+
if (options.expanded) {
|
|
131
|
+
component.addChild(new Text(`\n${styledOutput}`, 0, 0));
|
|
132
|
+
}
|
|
133
|
+
else {
|
|
134
|
+
component.addChild({
|
|
135
|
+
render: (width) => {
|
|
136
|
+
if (state.cachedLines === undefined || state.cachedWidth !== width) {
|
|
137
|
+
const preview = truncateToVisualLines(styledOutput, BASH_PREVIEW_LINES, width);
|
|
138
|
+
state.cachedLines = preview.visualLines;
|
|
139
|
+
state.cachedSkipped = preview.skippedCount;
|
|
140
|
+
state.cachedWidth = width;
|
|
141
|
+
}
|
|
142
|
+
if (state.cachedSkipped && state.cachedSkipped > 0) {
|
|
143
|
+
const hint = theme.fg("muted", `... (${state.cachedSkipped} earlier lines,`) +
|
|
144
|
+
` ${keyHint("app.tools.expand", "to expand")})`;
|
|
145
|
+
return ["", truncateToWidth(hint, width, "..."), ...(state.cachedLines ?? [])];
|
|
146
|
+
}
|
|
147
|
+
return ["", ...(state.cachedLines ?? [])];
|
|
148
|
+
},
|
|
149
|
+
invalidate: () => {
|
|
150
|
+
state.cachedWidth = undefined;
|
|
151
|
+
state.cachedLines = undefined;
|
|
152
|
+
state.cachedSkipped = undefined;
|
|
153
|
+
},
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
const truncation = result.details?.truncation;
|
|
158
|
+
const fullOutputPath = result.details?.fullOutputPath;
|
|
159
|
+
if (truncation?.truncated || fullOutputPath) {
|
|
160
|
+
const warnings = [];
|
|
161
|
+
if (fullOutputPath) {
|
|
162
|
+
warnings.push(`Full output: ${fullOutputPath}`);
|
|
163
|
+
}
|
|
164
|
+
if (truncation?.truncated) {
|
|
165
|
+
if (truncation.truncatedBy === "lines") {
|
|
166
|
+
warnings.push(`Truncated: showing ${truncation.outputLines} of ${truncation.totalLines} lines`);
|
|
167
|
+
}
|
|
168
|
+
else {
|
|
169
|
+
warnings.push(`Truncated: ${truncation.outputLines} lines shown (${formatSize(truncation.maxBytes ?? DEFAULT_MAX_BYTES)} limit)`);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
component.addChild(new Text(`\n${theme.fg("warning", `[${warnings.join(". ")}]`)}`, 0, 0));
|
|
173
|
+
}
|
|
174
|
+
if (startedAt !== undefined) {
|
|
175
|
+
const label = options.isPartial ? "Elapsed" : "Took";
|
|
176
|
+
const endTime = endedAt ?? Date.now();
|
|
177
|
+
component.addChild(new Text(`\n${theme.fg("muted", `${label} ${formatDuration(endTime - startedAt)}`)}`, 0, 0));
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
export function createBashToolDefinition(cwd, options) {
|
|
181
|
+
const ops = options?.operations ?? createLocalBashOperations({ shellPath: options?.shellPath });
|
|
106
182
|
const commandPrefix = options?.commandPrefix;
|
|
107
183
|
const spawnHook = options?.spawnHook;
|
|
108
184
|
return {
|
|
109
185
|
name: "bash",
|
|
110
186
|
label: "bash",
|
|
111
187
|
description: `Execute a bash command in the current working directory. Returns stdout and stderr. Output is truncated to last ${DEFAULT_MAX_LINES} lines or ${DEFAULT_MAX_BYTES / 1024}KB (whichever is hit first). If truncated, full output is saved to a temp file. Optionally provide a timeout in seconds.`,
|
|
188
|
+
promptSnippet: "Execute bash commands (ls, grep, find, etc.)",
|
|
112
189
|
parameters: bashSchema,
|
|
113
|
-
|
|
114
|
-
// Apply command prefix if configured (e.g., "shopt -s expand_aliases" for alias support)
|
|
190
|
+
async execute(_toolCallId, { command, timeout }, signal, onUpdate, _ctx) {
|
|
115
191
|
const resolvedCommand = commandPrefix ? `${commandPrefix}\n${command}` : command;
|
|
116
192
|
const spawnContext = resolveSpawnContext(resolvedCommand, cwd, spawnHook);
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
const
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
const
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
let details;
|
|
183
|
-
if (truncation.truncated) {
|
|
184
|
-
details = {
|
|
185
|
-
truncation,
|
|
186
|
-
fullOutputPath: tempFilePath,
|
|
187
|
-
};
|
|
188
|
-
// Build actionable notice
|
|
189
|
-
const startLine = truncation.totalLines - truncation.outputLines + 1;
|
|
190
|
-
const endLine = truncation.totalLines;
|
|
191
|
-
if (truncation.lastLinePartial) {
|
|
192
|
-
// Edge case: last line alone > 30KB
|
|
193
|
-
const lastLineSize = formatSize(Buffer.byteLength(fullOutput.split("\n").pop() || "", "utf-8"));
|
|
194
|
-
outputText += `\n\n[Showing last ${formatSize(truncation.outputBytes)} of line ${endLine} (line is ${lastLineSize}). Full output: ${tempFilePath}]`;
|
|
195
|
-
}
|
|
196
|
-
else if (truncation.truncatedBy === "lines") {
|
|
197
|
-
outputText += `\n\n[Showing lines ${startLine}-${endLine} of ${truncation.totalLines}. Full output: ${tempFilePath}]`;
|
|
198
|
-
}
|
|
199
|
-
else {
|
|
200
|
-
outputText += `\n\n[Showing lines ${startLine}-${endLine} of ${truncation.totalLines} (${formatSize(DEFAULT_MAX_BYTES)} limit). Full output: ${tempFilePath}]`;
|
|
201
|
-
}
|
|
193
|
+
const output = new OutputAccumulator({ tempFilePrefix: "pi-bash" });
|
|
194
|
+
let updateTimer;
|
|
195
|
+
let updateDirty = false;
|
|
196
|
+
let lastUpdateAt = 0;
|
|
197
|
+
const emitOutputUpdate = () => {
|
|
198
|
+
if (!onUpdate || !updateDirty)
|
|
199
|
+
return;
|
|
200
|
+
updateDirty = false;
|
|
201
|
+
lastUpdateAt = Date.now();
|
|
202
|
+
const snapshot = output.snapshot({ persistIfTruncated: true });
|
|
203
|
+
onUpdate({
|
|
204
|
+
content: [{ type: "text", text: snapshot.content || "" }],
|
|
205
|
+
details: {
|
|
206
|
+
truncation: snapshot.truncation.truncated ? snapshot.truncation : undefined,
|
|
207
|
+
fullOutputPath: snapshot.fullOutputPath,
|
|
208
|
+
},
|
|
209
|
+
});
|
|
210
|
+
};
|
|
211
|
+
const clearUpdateTimer = () => {
|
|
212
|
+
if (updateTimer) {
|
|
213
|
+
clearTimeout(updateTimer);
|
|
214
|
+
updateTimer = undefined;
|
|
215
|
+
}
|
|
216
|
+
};
|
|
217
|
+
const scheduleOutputUpdate = () => {
|
|
218
|
+
if (!onUpdate)
|
|
219
|
+
return;
|
|
220
|
+
updateDirty = true;
|
|
221
|
+
const delay = BASH_UPDATE_THROTTLE_MS - (Date.now() - lastUpdateAt);
|
|
222
|
+
if (delay <= 0) {
|
|
223
|
+
clearUpdateTimer();
|
|
224
|
+
emitOutputUpdate();
|
|
225
|
+
return;
|
|
226
|
+
}
|
|
227
|
+
updateTimer ??= setTimeout(() => {
|
|
228
|
+
updateTimer = undefined;
|
|
229
|
+
emitOutputUpdate();
|
|
230
|
+
}, delay);
|
|
231
|
+
};
|
|
232
|
+
if (onUpdate) {
|
|
233
|
+
onUpdate({ content: [], details: undefined });
|
|
234
|
+
}
|
|
235
|
+
const handleData = (data) => {
|
|
236
|
+
output.append(data);
|
|
237
|
+
scheduleOutputUpdate();
|
|
238
|
+
};
|
|
239
|
+
const finishOutput = async () => {
|
|
240
|
+
output.finish();
|
|
241
|
+
clearUpdateTimer();
|
|
242
|
+
emitOutputUpdate();
|
|
243
|
+
const snapshot = output.snapshot({ persistIfTruncated: true });
|
|
244
|
+
await output.closeTempFile();
|
|
245
|
+
return snapshot;
|
|
246
|
+
};
|
|
247
|
+
const formatOutput = (snapshot, emptyText = "(no output)") => {
|
|
248
|
+
const truncation = snapshot.truncation;
|
|
249
|
+
let text = snapshot.content || emptyText;
|
|
250
|
+
let details;
|
|
251
|
+
if (truncation.truncated) {
|
|
252
|
+
details = { truncation, fullOutputPath: snapshot.fullOutputPath };
|
|
253
|
+
const startLine = truncation.totalLines - truncation.outputLines + 1;
|
|
254
|
+
const endLine = truncation.totalLines;
|
|
255
|
+
if (truncation.lastLinePartial) {
|
|
256
|
+
const lastLineSize = formatSize(output.getLastLineBytes());
|
|
257
|
+
text += `\n\n[Showing last ${formatSize(truncation.outputBytes)} of line ${endLine} (line is ${lastLineSize}). Full output: ${snapshot.fullOutputPath}]`;
|
|
202
258
|
}
|
|
203
|
-
if (
|
|
204
|
-
|
|
205
|
-
reject(new Error(outputText));
|
|
259
|
+
else if (truncation.truncatedBy === "lines") {
|
|
260
|
+
text += `\n\n[Showing lines ${startLine}-${endLine} of ${truncation.totalLines}. Full output: ${snapshot.fullOutputPath}]`;
|
|
206
261
|
}
|
|
207
262
|
else {
|
|
208
|
-
|
|
209
|
-
}
|
|
210
|
-
})
|
|
211
|
-
.catch((err) => {
|
|
212
|
-
// Close temp file stream
|
|
213
|
-
if (tempFileStream) {
|
|
214
|
-
tempFileStream.end();
|
|
263
|
+
text += `\n\n[Showing lines ${startLine}-${endLine} of ${truncation.totalLines} (${formatSize(DEFAULT_MAX_BYTES)} limit). Full output: ${snapshot.fullOutputPath}]`;
|
|
215
264
|
}
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
265
|
+
}
|
|
266
|
+
return { text, details };
|
|
267
|
+
};
|
|
268
|
+
const appendStatus = (text, status) => `${text ? `${text}\n\n` : ""}${status}`;
|
|
269
|
+
try {
|
|
270
|
+
let exitCode;
|
|
271
|
+
try {
|
|
272
|
+
const result = await ops.exec(spawnContext.command, spawnContext.cwd, {
|
|
273
|
+
onData: handleData,
|
|
274
|
+
signal,
|
|
275
|
+
timeout,
|
|
276
|
+
env: spawnContext.env,
|
|
277
|
+
});
|
|
278
|
+
exitCode = result.exitCode;
|
|
279
|
+
}
|
|
280
|
+
catch (err) {
|
|
281
|
+
const snapshot = await finishOutput();
|
|
282
|
+
const { text } = formatOutput(snapshot, "");
|
|
283
|
+
if (err instanceof Error && err.message === "aborted") {
|
|
284
|
+
throw new Error(appendStatus(text, "Command aborted"));
|
|
224
285
|
}
|
|
225
|
-
|
|
286
|
+
if (err instanceof Error && err.message.startsWith("timeout:")) {
|
|
226
287
|
const timeoutSecs = err.message.split(":")[1];
|
|
227
|
-
|
|
228
|
-
output += "\n\n";
|
|
229
|
-
output += `Command timed out after ${timeoutSecs} seconds`;
|
|
230
|
-
reject(new Error(output));
|
|
288
|
+
throw new Error(appendStatus(text, `Command timed out after ${timeoutSecs} seconds`));
|
|
231
289
|
}
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
});
|
|
236
|
-
|
|
290
|
+
throw err;
|
|
291
|
+
}
|
|
292
|
+
const snapshot = await finishOutput();
|
|
293
|
+
const { text: outputText, details } = formatOutput(snapshot);
|
|
294
|
+
if (exitCode !== 0 && exitCode !== null) {
|
|
295
|
+
throw new Error(appendStatus(outputText, `Command exited with code ${exitCode}`));
|
|
296
|
+
}
|
|
297
|
+
return { content: [{ type: "text", text: outputText }], details };
|
|
298
|
+
}
|
|
299
|
+
finally {
|
|
300
|
+
clearUpdateTimer();
|
|
301
|
+
}
|
|
302
|
+
},
|
|
303
|
+
renderCall(args, _theme, context) {
|
|
304
|
+
const state = context.state;
|
|
305
|
+
if (context.executionStarted && state.startedAt === undefined) {
|
|
306
|
+
state.startedAt = Date.now();
|
|
307
|
+
state.endedAt = undefined;
|
|
308
|
+
}
|
|
309
|
+
const text = context.lastComponent ?? new Text("", 0, 0);
|
|
310
|
+
text.setText(formatBashCall(args));
|
|
311
|
+
return text;
|
|
312
|
+
},
|
|
313
|
+
renderResult(result, options, _theme, context) {
|
|
314
|
+
const state = context.state;
|
|
315
|
+
if (state.startedAt !== undefined && options.isPartial && !state.interval) {
|
|
316
|
+
state.interval = setInterval(() => context.invalidate(), 1000);
|
|
317
|
+
}
|
|
318
|
+
if (!options.isPartial || context.isError) {
|
|
319
|
+
state.endedAt ??= Date.now();
|
|
320
|
+
if (state.interval) {
|
|
321
|
+
clearInterval(state.interval);
|
|
322
|
+
state.interval = undefined;
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
const component = context.lastComponent ?? new BashResultRenderComponent();
|
|
326
|
+
rebuildBashResultRenderComponent(component, result, options, context.showImages, state.startedAt, state.endedAt);
|
|
327
|
+
component.invalidate();
|
|
328
|
+
return component;
|
|
237
329
|
},
|
|
238
330
|
};
|
|
239
331
|
}
|
|
240
|
-
|
|
241
|
-
|
|
332
|
+
export function createBashTool(cwd, options) {
|
|
333
|
+
return wrapToolDefinition(createBashToolDefinition(cwd, options));
|
|
334
|
+
}
|
|
242
335
|
//# sourceMappingURL=bash.js.map
|