@lenylvt/pi-coding-agent 0.64.0
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 +3331 -0
- package/README.md +48 -0
- package/dist/bun/cli.d.ts +3 -0
- package/dist/bun/cli.d.ts.map +1 -0
- package/dist/bun/cli.js +5 -0
- package/dist/bun/cli.js.map +1 -0
- package/dist/cli/args.d.ts +49 -0
- package/dist/cli/args.d.ts.map +1 -0
- package/dist/cli/args.js +292 -0
- package/dist/cli/args.js.map +1 -0
- package/dist/cli/config-selector.d.ts +14 -0
- package/dist/cli/config-selector.d.ts.map +1 -0
- package/dist/cli/config-selector.js +31 -0
- package/dist/cli/config-selector.js.map +1 -0
- package/dist/cli/file-processor.d.ts +15 -0
- package/dist/cli/file-processor.d.ts.map +1 -0
- package/dist/cli/file-processor.js +83 -0
- package/dist/cli/file-processor.js.map +1 -0
- 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 +9 -0
- package/dist/cli/list-models.d.ts.map +1 -0
- package/dist/cli/list-models.js +92 -0
- package/dist/cli/list-models.js.map +1 -0
- package/dist/cli/session-picker.d.ts +9 -0
- package/dist/cli/session-picker.d.ts.map +1 -0
- package/dist/cli/session-picker.js +35 -0
- package/dist/cli/session-picker.js.map +1 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +14 -0
- package/dist/cli.js.map +1 -0
- package/dist/config.d.ts +69 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +178 -0
- package/dist/config.js.map +1 -0
- package/dist/core/agent-session.d.ts +622 -0
- package/dist/core/agent-session.d.ts.map +1 -0
- package/dist/core/agent-session.js +2688 -0
- package/dist/core/agent-session.js.map +1 -0
- package/dist/core/auth-storage.d.ts +132 -0
- package/dist/core/auth-storage.d.ts.map +1 -0
- package/dist/core/auth-storage.js +422 -0
- package/dist/core/auth-storage.js.map +1 -0
- package/dist/core/bash-executor.d.ts +46 -0
- package/dist/core/bash-executor.d.ts.map +1 -0
- package/dist/core/bash-executor.js +113 -0
- package/dist/core/bash-executor.js.map +1 -0
- package/dist/core/compaction/branch-summarization.d.ts +88 -0
- package/dist/core/compaction/branch-summarization.d.ts.map +1 -0
- package/dist/core/compaction/branch-summarization.js +243 -0
- package/dist/core/compaction/branch-summarization.js.map +1 -0
- package/dist/core/compaction/compaction.d.ts +121 -0
- package/dist/core/compaction/compaction.d.ts.map +1 -0
- package/dist/core/compaction/compaction.js +613 -0
- package/dist/core/compaction/compaction.js.map +1 -0
- package/dist/core/compaction/index.d.ts +7 -0
- package/dist/core/compaction/index.d.ts.map +1 -0
- package/dist/core/compaction/index.js +7 -0
- package/dist/core/compaction/index.js.map +1 -0
- package/dist/core/compaction/utils.d.ts +38 -0
- package/dist/core/compaction/utils.d.ts.map +1 -0
- package/dist/core/compaction/utils.js +153 -0
- package/dist/core/compaction/utils.js.map +1 -0
- package/dist/core/defaults.d.ts +3 -0
- package/dist/core/defaults.d.ts.map +1 -0
- package/dist/core/defaults.js +2 -0
- package/dist/core/defaults.js.map +1 -0
- package/dist/core/diagnostics.d.ts +15 -0
- package/dist/core/diagnostics.d.ts.map +1 -0
- package/dist/core/diagnostics.js +2 -0
- package/dist/core/diagnostics.js.map +1 -0
- package/dist/core/event-bus.d.ts +9 -0
- package/dist/core/event-bus.d.ts.map +1 -0
- package/dist/core/event-bus.js +25 -0
- package/dist/core/event-bus.js.map +1 -0
- package/dist/core/exec.d.ts +29 -0
- package/dist/core/exec.d.ts.map +1 -0
- package/dist/core/exec.js +75 -0
- package/dist/core/exec.js.map +1 -0
- package/dist/core/export-html/ansi-to-html.d.ts +22 -0
- package/dist/core/export-html/ansi-to-html.d.ts.map +1 -0
- package/dist/core/export-html/ansi-to-html.js +249 -0
- package/dist/core/export-html/ansi-to-html.js.map +1 -0
- package/dist/core/export-html/index.d.ts +37 -0
- package/dist/core/export-html/index.d.ts.map +1 -0
- package/dist/core/export-html/index.js +224 -0
- package/dist/core/export-html/index.js.map +1 -0
- package/dist/core/export-html/template.css +1001 -0
- package/dist/core/export-html/template.html +55 -0
- package/dist/core/export-html/template.js +1690 -0
- package/dist/core/export-html/tool-renderer.d.ts +38 -0
- package/dist/core/export-html/tool-renderer.d.ts.map +1 -0
- package/dist/core/export-html/tool-renderer.js +95 -0
- package/dist/core/export-html/tool-renderer.js.map +1 -0
- package/dist/core/export-html/vendor/highlight.min.js +1213 -0
- package/dist/core/export-html/vendor/marked.min.js +6 -0
- package/dist/core/extensions/index.d.ts +12 -0
- package/dist/core/extensions/index.d.ts.map +1 -0
- package/dist/core/extensions/index.js +9 -0
- package/dist/core/extensions/index.js.map +1 -0
- package/dist/core/extensions/loader.d.ts +25 -0
- package/dist/core/extensions/loader.d.ts.map +1 -0
- package/dist/core/extensions/loader.js +436 -0
- package/dist/core/extensions/loader.js.map +1 -0
- package/dist/core/extensions/runner.d.ts +148 -0
- package/dist/core/extensions/runner.d.ts.map +1 -0
- package/dist/core/extensions/runner.js +700 -0
- package/dist/core/extensions/runner.js.map +1 -0
- package/dist/core/extensions/types.d.ts +1085 -0
- package/dist/core/extensions/types.d.ts.map +1 -0
- package/dist/core/extensions/types.js +35 -0
- package/dist/core/extensions/types.js.map +1 -0
- package/dist/core/extensions/wrapper.d.ts +20 -0
- package/dist/core/extensions/wrapper.d.ts.map +1 -0
- package/dist/core/extensions/wrapper.js +22 -0
- package/dist/core/extensions/wrapper.js.map +1 -0
- package/dist/core/footer-data-provider.d.ts +44 -0
- package/dist/core/footer-data-provider.d.ts.map +1 -0
- package/dist/core/footer-data-provider.js +252 -0
- package/dist/core/footer-data-provider.js.map +1 -0
- package/dist/core/index.d.ts +10 -0
- package/dist/core/index.d.ts.map +1 -0
- package/dist/core/index.js +10 -0
- package/dist/core/index.js.map +1 -0
- package/dist/core/keybindings.d.ts +275 -0
- package/dist/core/keybindings.d.ts.map +1 -0
- package/dist/core/keybindings.js +241 -0
- package/dist/core/keybindings.js.map +1 -0
- package/dist/core/messages.d.ts +77 -0
- package/dist/core/messages.d.ts.map +1 -0
- package/dist/core/messages.js +123 -0
- package/dist/core/messages.js.map +1 -0
- package/dist/core/model-registry.d.ts +132 -0
- package/dist/core/model-registry.d.ts.map +1 -0
- package/dist/core/model-registry.js +565 -0
- package/dist/core/model-registry.js.map +1 -0
- package/dist/core/model-resolver.d.ts +110 -0
- package/dist/core/model-resolver.d.ts.map +1 -0
- package/dist/core/model-resolver.js +464 -0
- package/dist/core/model-resolver.js.map +1 -0
- 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 +172 -0
- package/dist/core/package-manager.d.ts.map +1 -0
- package/dist/core/package-manager.js +1801 -0
- package/dist/core/package-manager.js.map +1 -0
- package/dist/core/prompt-templates.d.ts +51 -0
- package/dist/core/prompt-templates.d.ts.map +1 -0
- package/dist/core/prompt-templates.js +249 -0
- package/dist/core/prompt-templates.js.map +1 -0
- package/dist/core/resolve-config-value.d.ts +23 -0
- package/dist/core/resolve-config-value.d.ts.map +1 -0
- package/dist/core/resolve-config-value.js +126 -0
- package/dist/core/resolve-config-value.js.map +1 -0
- package/dist/core/resource-loader.d.ts +185 -0
- package/dist/core/resource-loader.d.ts.map +1 -0
- package/dist/core/resource-loader.js +698 -0
- package/dist/core/resource-loader.js.map +1 -0
- package/dist/core/sdk.d.ts +90 -0
- package/dist/core/sdk.d.ts.map +1 -0
- package/dist/core/sdk.js +233 -0
- package/dist/core/sdk.js.map +1 -0
- package/dist/core/self-update.d.ts +3 -0
- package/dist/core/self-update.d.ts.map +1 -0
- package/dist/core/self-update.js +46 -0
- package/dist/core/self-update.js.map +1 -0
- package/dist/core/session-manager.d.ts +329 -0
- package/dist/core/session-manager.d.ts.map +1 -0
- package/dist/core/session-manager.js +1097 -0
- package/dist/core/session-manager.js.map +1 -0
- package/dist/core/settings-manager.d.ts +237 -0
- package/dist/core/settings-manager.d.ts.map +1 -0
- package/dist/core/settings-manager.js +708 -0
- package/dist/core/settings-manager.js.map +1 -0
- package/dist/core/skills.d.ts +60 -0
- package/dist/core/skills.d.ts.map +1 -0
- package/dist/core/skills.js +409 -0
- package/dist/core/skills.js.map +1 -0
- package/dist/core/slash-commands.d.ts +14 -0
- package/dist/core/slash-commands.d.ts.map +1 -0
- package/dist/core/slash-commands.js +22 -0
- package/dist/core/slash-commands.js.map +1 -0
- 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 +28 -0
- package/dist/core/system-prompt.d.ts.map +1 -0
- package/dist/core/system-prompt.js +116 -0
- package/dist/core/system-prompt.js.map +1 -0
- package/dist/core/timings.d.ts +8 -0
- package/dist/core/timings.d.ts.map +1 -0
- package/dist/core/timings.js +31 -0
- package/dist/core/timings.js.map +1 -0
- package/dist/core/tools/bash.d.ts +73 -0
- package/dist/core/tools/bash.d.ts.map +1 -0
- package/dist/core/tools/bash.js +342 -0
- package/dist/core/tools/bash.js.map +1 -0
- package/dist/core/tools/edit-diff.d.ts +85 -0
- package/dist/core/tools/edit-diff.d.ts.map +1 -0
- package/dist/core/tools/edit-diff.js +337 -0
- package/dist/core/tools/edit-diff.js.map +1 -0
- package/dist/core/tools/edit.d.ts +53 -0
- package/dist/core/tools/edit.d.ts.map +1 -0
- package/dist/core/tools/edit.js +196 -0
- package/dist/core/tools/edit.js.map +1 -0
- 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 +46 -0
- package/dist/core/tools/find.d.ts.map +1 -0
- package/dist/core/tools/find.js +258 -0
- package/dist/core/tools/find.js.map +1 -0
- package/dist/core/tools/grep.d.ts +56 -0
- package/dist/core/tools/grep.d.ts.map +1 -0
- package/dist/core/tools/grep.js +293 -0
- package/dist/core/tools/grep.js.map +1 -0
- package/dist/core/tools/index.d.ts +115 -0
- package/dist/core/tools/index.d.ts.map +1 -0
- package/dist/core/tools/index.js +86 -0
- package/dist/core/tools/index.js.map +1 -0
- package/dist/core/tools/ls.d.ts +46 -0
- package/dist/core/tools/ls.d.ts.map +1 -0
- package/dist/core/tools/ls.js +172 -0
- package/dist/core/tools/ls.js.map +1 -0
- package/dist/core/tools/path-utils.d.ts +8 -0
- package/dist/core/tools/path-utils.d.ts.map +1 -0
- package/dist/core/tools/path-utils.js +81 -0
- package/dist/core/tools/path-utils.js.map +1 -0
- package/dist/core/tools/read.d.ts +46 -0
- package/dist/core/tools/read.d.ts.map +1 -0
- package/dist/core/tools/read.js +225 -0
- package/dist/core/tools/read.js.map +1 -0
- 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 +32 -0
- package/dist/core/tools/tool-definition-wrapper.js.map +1 -0
- package/dist/core/tools/truncate.d.ts +70 -0
- package/dist/core/tools/truncate.d.ts.map +1 -0
- package/dist/core/tools/truncate.js +205 -0
- package/dist/core/tools/truncate.js.map +1 -0
- package/dist/core/tools/write.d.ts +35 -0
- package/dist/core/tools/write.d.ts.map +1 -0
- package/dist/core/tools/write.js +216 -0
- package/dist/core/tools/write.js.map +1 -0
- package/dist/core/version-check.d.ts +2 -0
- package/dist/core/version-check.d.ts.map +1 -0
- package/dist/core/version-check.js +73 -0
- package/dist/core/version-check.js.map +1 -0
- package/dist/index.d.ts +28 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +43 -0
- package/dist/index.js.map +1 -0
- package/dist/main.d.ts +8 -0
- package/dist/main.d.ts.map +1 -0
- package/dist/main.js +811 -0
- package/dist/main.js.map +1 -0
- package/dist/migrations.d.ts +32 -0
- package/dist/migrations.d.ts.map +1 -0
- package/dist/migrations.js +258 -0
- package/dist/migrations.js.map +1 -0
- package/dist/modes/index.d.ts +9 -0
- package/dist/modes/index.d.ts.map +1 -0
- package/dist/modes/index.js +8 -0
- package/dist/modes/index.js.map +1 -0
- package/dist/modes/interactive/components/armin.d.ts +34 -0
- package/dist/modes/interactive/components/armin.d.ts.map +1 -0
- package/dist/modes/interactive/components/armin.js +333 -0
- package/dist/modes/interactive/components/armin.js.map +1 -0
- package/dist/modes/interactive/components/assistant-message.d.ts +18 -0
- package/dist/modes/interactive/components/assistant-message.d.ts.map +1 -0
- package/dist/modes/interactive/components/assistant-message.js +107 -0
- package/dist/modes/interactive/components/assistant-message.js.map +1 -0
- package/dist/modes/interactive/components/bash-execution.d.ts +34 -0
- package/dist/modes/interactive/components/bash-execution.d.ts.map +1 -0
- package/dist/modes/interactive/components/bash-execution.js +175 -0
- package/dist/modes/interactive/components/bash-execution.js.map +1 -0
- package/dist/modes/interactive/components/bordered-loader.d.ts +16 -0
- package/dist/modes/interactive/components/bordered-loader.d.ts.map +1 -0
- package/dist/modes/interactive/components/bordered-loader.js +51 -0
- package/dist/modes/interactive/components/bordered-loader.js.map +1 -0
- package/dist/modes/interactive/components/branch-summary-message.d.ts +16 -0
- package/dist/modes/interactive/components/branch-summary-message.d.ts.map +1 -0
- package/dist/modes/interactive/components/branch-summary-message.js +44 -0
- package/dist/modes/interactive/components/branch-summary-message.js.map +1 -0
- package/dist/modes/interactive/components/compaction-summary-message.d.ts +16 -0
- package/dist/modes/interactive/components/compaction-summary-message.d.ts.map +1 -0
- package/dist/modes/interactive/components/compaction-summary-message.js +45 -0
- package/dist/modes/interactive/components/compaction-summary-message.js.map +1 -0
- package/dist/modes/interactive/components/config-selector.d.ts +71 -0
- package/dist/modes/interactive/components/config-selector.d.ts.map +1 -0
- package/dist/modes/interactive/components/config-selector.js +479 -0
- package/dist/modes/interactive/components/config-selector.js.map +1 -0
- package/dist/modes/interactive/components/countdown-timer.d.ts +14 -0
- package/dist/modes/interactive/components/countdown-timer.d.ts.map +1 -0
- package/dist/modes/interactive/components/countdown-timer.js +33 -0
- package/dist/modes/interactive/components/countdown-timer.js.map +1 -0
- package/dist/modes/interactive/components/custom-editor.d.ts +21 -0
- package/dist/modes/interactive/components/custom-editor.d.ts.map +1 -0
- package/dist/modes/interactive/components/custom-editor.js +70 -0
- package/dist/modes/interactive/components/custom-editor.js.map +1 -0
- package/dist/modes/interactive/components/custom-message.d.ts +20 -0
- package/dist/modes/interactive/components/custom-message.d.ts.map +1 -0
- package/dist/modes/interactive/components/custom-message.js +79 -0
- package/dist/modes/interactive/components/custom-message.js.map +1 -0
- package/dist/modes/interactive/components/diff.d.ts +12 -0
- package/dist/modes/interactive/components/diff.d.ts.map +1 -0
- package/dist/modes/interactive/components/diff.js +133 -0
- package/dist/modes/interactive/components/diff.js.map +1 -0
- package/dist/modes/interactive/components/dynamic-border.d.ts +15 -0
- package/dist/modes/interactive/components/dynamic-border.d.ts.map +1 -0
- package/dist/modes/interactive/components/dynamic-border.js +21 -0
- package/dist/modes/interactive/components/dynamic-border.js.map +1 -0
- package/dist/modes/interactive/components/extension-editor.d.ts +20 -0
- package/dist/modes/interactive/components/extension-editor.d.ts.map +1 -0
- package/dist/modes/interactive/components/extension-editor.js +111 -0
- package/dist/modes/interactive/components/extension-editor.js.map +1 -0
- package/dist/modes/interactive/components/extension-input.d.ts +23 -0
- package/dist/modes/interactive/components/extension-input.d.ts.map +1 -0
- package/dist/modes/interactive/components/extension-input.js +61 -0
- package/dist/modes/interactive/components/extension-input.js.map +1 -0
- package/dist/modes/interactive/components/extension-selector.d.ts +24 -0
- package/dist/modes/interactive/components/extension-selector.d.ts.map +1 -0
- package/dist/modes/interactive/components/extension-selector.js +78 -0
- package/dist/modes/interactive/components/extension-selector.js.map +1 -0
- package/dist/modes/interactive/components/footer.d.ts +26 -0
- package/dist/modes/interactive/components/footer.d.ts.map +1 -0
- package/dist/modes/interactive/components/footer.js +198 -0
- package/dist/modes/interactive/components/footer.js.map +1 -0
- package/dist/modes/interactive/components/index.d.ts +31 -0
- package/dist/modes/interactive/components/index.d.ts.map +1 -0
- package/dist/modes/interactive/components/index.js +32 -0
- package/dist/modes/interactive/components/index.js.map +1 -0
- package/dist/modes/interactive/components/keybinding-hints.d.ts +8 -0
- package/dist/modes/interactive/components/keybinding-hints.d.ts.map +1 -0
- package/dist/modes/interactive/components/keybinding-hints.js +22 -0
- package/dist/modes/interactive/components/keybinding-hints.js.map +1 -0
- package/dist/modes/interactive/components/login-dialog.d.ts +42 -0
- package/dist/modes/interactive/components/login-dialog.d.ts.map +1 -0
- package/dist/modes/interactive/components/login-dialog.js +145 -0
- package/dist/modes/interactive/components/login-dialog.js.map +1 -0
- package/dist/modes/interactive/components/model-selector.d.ts +47 -0
- package/dist/modes/interactive/components/model-selector.d.ts.map +1 -0
- package/dist/modes/interactive/components/model-selector.js +275 -0
- package/dist/modes/interactive/components/model-selector.js.map +1 -0
- package/dist/modes/interactive/components/oauth-selector.d.ts +19 -0
- package/dist/modes/interactive/components/oauth-selector.d.ts.map +1 -0
- package/dist/modes/interactive/components/oauth-selector.js +97 -0
- package/dist/modes/interactive/components/oauth-selector.js.map +1 -0
- package/dist/modes/interactive/components/scoped-models-selector.d.ts +49 -0
- package/dist/modes/interactive/components/scoped-models-selector.d.ts.map +1 -0
- package/dist/modes/interactive/components/scoped-models-selector.js +275 -0
- package/dist/modes/interactive/components/scoped-models-selector.js.map +1 -0
- package/dist/modes/interactive/components/session-selector-search.d.ts +23 -0
- package/dist/modes/interactive/components/session-selector-search.d.ts.map +1 -0
- package/dist/modes/interactive/components/session-selector-search.js +155 -0
- package/dist/modes/interactive/components/session-selector-search.js.map +1 -0
- package/dist/modes/interactive/components/session-selector.d.ts +95 -0
- package/dist/modes/interactive/components/session-selector.d.ts.map +1 -0
- package/dist/modes/interactive/components/session-selector.js +848 -0
- package/dist/modes/interactive/components/session-selector.js.map +1 -0
- package/dist/modes/interactive/components/settings-selector.d.ts +58 -0
- package/dist/modes/interactive/components/settings-selector.d.ts.map +1 -0
- package/dist/modes/interactive/components/settings-selector.js +301 -0
- package/dist/modes/interactive/components/settings-selector.js.map +1 -0
- package/dist/modes/interactive/components/show-images-selector.d.ts +10 -0
- package/dist/modes/interactive/components/show-images-selector.d.ts.map +1 -0
- package/dist/modes/interactive/components/show-images-selector.js +39 -0
- package/dist/modes/interactive/components/show-images-selector.js.map +1 -0
- package/dist/modes/interactive/components/skill-invocation-message.d.ts +17 -0
- package/dist/modes/interactive/components/skill-invocation-message.d.ts.map +1 -0
- package/dist/modes/interactive/components/skill-invocation-message.js +47 -0
- package/dist/modes/interactive/components/skill-invocation-message.js.map +1 -0
- package/dist/modes/interactive/components/theme-selector.d.ts +11 -0
- package/dist/modes/interactive/components/theme-selector.d.ts.map +1 -0
- package/dist/modes/interactive/components/theme-selector.js +50 -0
- package/dist/modes/interactive/components/theme-selector.js.map +1 -0
- package/dist/modes/interactive/components/thinking-selector.d.ts +11 -0
- package/dist/modes/interactive/components/thinking-selector.d.ts.map +1 -0
- package/dist/modes/interactive/components/thinking-selector.js +51 -0
- package/dist/modes/interactive/components/thinking-selector.js.map +1 -0
- package/dist/modes/interactive/components/tool-execution.d.ts +58 -0
- package/dist/modes/interactive/components/tool-execution.d.ts.map +1 -0
- package/dist/modes/interactive/components/tool-execution.js +274 -0
- package/dist/modes/interactive/components/tool-execution.js.map +1 -0
- package/dist/modes/interactive/components/tree-selector.d.ts +87 -0
- package/dist/modes/interactive/components/tree-selector.d.ts.map +1 -0
- package/dist/modes/interactive/components/tree-selector.js +1051 -0
- package/dist/modes/interactive/components/tree-selector.js.map +1 -0
- package/dist/modes/interactive/components/user-message-selector.d.ts +30 -0
- package/dist/modes/interactive/components/user-message-selector.d.ts.map +1 -0
- package/dist/modes/interactive/components/user-message-selector.js +113 -0
- package/dist/modes/interactive/components/user-message-selector.js.map +1 -0
- package/dist/modes/interactive/components/user-message.d.ts +9 -0
- package/dist/modes/interactive/components/user-message.d.ts.map +1 -0
- package/dist/modes/interactive/components/user-message.js +28 -0
- package/dist/modes/interactive/components/user-message.js.map +1 -0
- package/dist/modes/interactive/components/visual-truncate.d.ts +24 -0
- package/dist/modes/interactive/components/visual-truncate.d.ts.map +1 -0
- package/dist/modes/interactive/components/visual-truncate.js +33 -0
- package/dist/modes/interactive/components/visual-truncate.js.map +1 -0
- package/dist/modes/interactive/interactive-mode.d.ts +311 -0
- package/dist/modes/interactive/interactive-mode.d.ts.map +1 -0
- package/dist/modes/interactive/interactive-mode.js +3798 -0
- package/dist/modes/interactive/interactive-mode.js.map +1 -0
- package/dist/modes/interactive/theme/dark.json +85 -0
- package/dist/modes/interactive/theme/light.json +84 -0
- package/dist/modes/interactive/theme/theme-schema.json +335 -0
- package/dist/modes/interactive/theme/theme.d.ts +81 -0
- package/dist/modes/interactive/theme/theme.d.ts.map +1 -0
- package/dist/modes/interactive/theme/theme.js +975 -0
- package/dist/modes/interactive/theme/theme.js.map +1 -0
- package/dist/modes/print-mode.d.ts +28 -0
- package/dist/modes/print-mode.d.ts.map +1 -0
- package/dist/modes/print-mode.js +107 -0
- package/dist/modes/print-mode.js.map +1 -0
- 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 +217 -0
- package/dist/modes/rpc/rpc-client.d.ts.map +1 -0
- package/dist/modes/rpc/rpc-client.js +401 -0
- package/dist/modes/rpc/rpc-client.js.map +1 -0
- package/dist/modes/rpc/rpc-mode.d.ts +20 -0
- package/dist/modes/rpc/rpc-mode.d.ts.map +1 -0
- package/dist/modes/rpc/rpc-mode.js +522 -0
- package/dist/modes/rpc/rpc-mode.js.map +1 -0
- package/dist/modes/rpc/rpc-types.d.ts +408 -0
- package/dist/modes/rpc/rpc-types.d.ts.map +1 -0
- package/dist/modes/rpc/rpc-types.js +8 -0
- package/dist/modes/rpc/rpc-types.js.map +1 -0
- package/dist/utils/changelog.d.ts +21 -0
- package/dist/utils/changelog.d.ts.map +1 -0
- package/dist/utils/changelog.js +87 -0
- package/dist/utils/changelog.js.map +1 -0
- package/dist/utils/child-process.d.ts +11 -0
- package/dist/utils/child-process.d.ts.map +1 -0
- package/dist/utils/child-process.js +78 -0
- package/dist/utils/child-process.js.map +1 -0
- package/dist/utils/clipboard-image.d.ts +11 -0
- package/dist/utils/clipboard-image.d.ts.map +1 -0
- package/dist/utils/clipboard-image.js +245 -0
- package/dist/utils/clipboard-image.js.map +1 -0
- package/dist/utils/clipboard-native.d.ts +8 -0
- package/dist/utils/clipboard-native.d.ts.map +1 -0
- package/dist/utils/clipboard-native.js +14 -0
- package/dist/utils/clipboard-native.js.map +1 -0
- package/dist/utils/clipboard.d.ts +2 -0
- package/dist/utils/clipboard.d.ts.map +1 -0
- package/dist/utils/clipboard.js +78 -0
- package/dist/utils/clipboard.js.map +1 -0
- 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 +8 -0
- package/dist/utils/frontmatter.d.ts.map +1 -0
- package/dist/utils/frontmatter.js +26 -0
- package/dist/utils/frontmatter.js.map +1 -0
- package/dist/utils/git.d.ts +26 -0
- package/dist/utils/git.d.ts.map +1 -0
- package/dist/utils/git.js +163 -0
- package/dist/utils/git.js.map +1 -0
- package/dist/utils/image-convert.d.ts +9 -0
- package/dist/utils/image-convert.d.ts.map +1 -0
- package/dist/utils/image-convert.js +39 -0
- package/dist/utils/image-convert.js.map +1 -0
- package/dist/utils/image-resize.d.ts +36 -0
- package/dist/utils/image-resize.d.ts.map +1 -0
- package/dist/utils/image-resize.js +137 -0
- package/dist/utils/image-resize.js.map +1 -0
- package/dist/utils/mime.d.ts +2 -0
- package/dist/utils/mime.d.ts.map +1 -0
- package/dist/utils/mime.js +26 -0
- package/dist/utils/mime.js.map +1 -0
- package/dist/utils/photon.d.ts +21 -0
- package/dist/utils/photon.d.ts.map +1 -0
- package/dist/utils/photon.js +121 -0
- package/dist/utils/photon.js.map +1 -0
- package/dist/utils/shell.d.ts +26 -0
- package/dist/utils/shell.d.ts.map +1 -0
- package/dist/utils/shell.js +186 -0
- package/dist/utils/shell.js.map +1 -0
- package/dist/utils/sleep.d.ts +5 -0
- package/dist/utils/sleep.d.ts.map +1 -0
- package/dist/utils/sleep.js +17 -0
- package/dist/utils/sleep.js.map +1 -0
- package/dist/utils/tools-manager.d.ts +3 -0
- package/dist/utils/tools-manager.d.ts.map +1 -0
- package/dist/utils/tools-manager.js +252 -0
- package/dist/utils/tools-manager.js.map +1 -0
- package/docs/compaction.md +394 -0
- package/docs/custom-provider.md +327 -0
- package/docs/extensions.md +2229 -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/json.md +82 -0
- package/docs/keybindings.md +173 -0
- package/docs/models.md +197 -0
- package/docs/packages.md +218 -0
- package/docs/prompt-templates.md +67 -0
- package/docs/providers.md +98 -0
- package/docs/release.md +40 -0
- package/docs/rpc.md +1377 -0
- package/docs/sdk.md +971 -0
- package/docs/session.md +412 -0
- package/docs/settings.md +149 -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/tree.md +228 -0
- package/docs/tui.md +887 -0
- package/docs/windows.md +17 -0
- package/examples/README.md +25 -0
- package/examples/extensions/README.md +204 -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/built-in-tool-renderer.ts +246 -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.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/handoff.ts +153 -0
- package/examples/extensions/hello.ts +25 -0
- package/examples/extensions/hidden-thinking-label.ts +57 -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 +166 -0
- package/examples/extensions/preset.ts +397 -0
- package/examples/extensions/protected-paths.ts +30 -0
- package/examples/extensions/provider-payload.ts +14 -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 +124 -0
- package/examples/extensions/sandbox/index.ts +321 -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 +40 -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 +986 -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/timed-confirm.ts +70 -0
- package/examples/extensions/titlebar-spinner.ts +58 -0
- package/examples/extensions/todo.ts +299 -0
- package/examples/extensions/tool-override.ts +144 -0
- package/examples/extensions/tools.ts +146 -0
- package/examples/extensions/trigger-compact.ts +50 -0
- package/examples/extensions/truncated-tool.ts +195 -0
- package/examples/extensions/widget-placement.ts +17 -0
- package/examples/extensions/with-deps/index.ts +32 -0
- package/examples/extensions/with-deps/package.json +22 -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 +55 -0
- package/examples/sdk/04-skills.ts +52 -0
- package/examples/sdk/05-tools.ts +56 -0
- package/examples/sdk/06-extensions.ts +88 -0
- package/examples/sdk/07-context-files.ts +40 -0
- package/examples/sdk/08-prompt-templates.ts +48 -0
- package/examples/sdk/09-api-keys-and-oauth.ts +48 -0
- package/examples/sdk/10-settings.ts +51 -0
- package/examples/sdk/11-sessions.ts +48 -0
- package/examples/sdk/12-full-control.ts +81 -0
- package/examples/sdk/README.md +144 -0
- package/package.json +95 -0
- package/src/bun/cli.ts +5 -0
- package/src/cli/args.ts +309 -0
- package/src/cli/config-selector.ts +52 -0
- package/src/cli/file-processor.ts +100 -0
- package/src/cli/initial-message.ts +43 -0
- package/src/cli/list-models.ts +104 -0
- package/src/cli/session-picker.ts +52 -0
- package/src/cli.ts +16 -0
- package/src/config.ts +214 -0
- package/src/core/agent-session.ts +3279 -0
- package/src/core/auth-storage.ts +488 -0
- package/src/core/bash-executor.ts +158 -0
- package/src/core/compaction/branch-summarization.ts +355 -0
- package/src/core/compaction/compaction.ts +823 -0
- package/src/core/compaction/index.ts +7 -0
- package/src/core/compaction/utils.ts +170 -0
- package/src/core/defaults.ts +3 -0
- package/src/core/diagnostics.ts +15 -0
- package/src/core/event-bus.ts +33 -0
- package/src/core/exec.ts +107 -0
- package/src/core/export-html/ansi-to-html.ts +258 -0
- package/src/core/export-html/index.ts +314 -0
- package/src/core/export-html/template.css +1001 -0
- package/src/core/export-html/template.html +55 -0
- package/src/core/export-html/template.js +1690 -0
- package/src/core/export-html/tool-renderer.ts +156 -0
- package/src/core/export-html/vendor/highlight.min.js +1213 -0
- package/src/core/export-html/vendor/marked.min.js +6 -0
- package/src/core/extensions/index.ts +168 -0
- package/src/core/extensions/loader.ts +557 -0
- package/src/core/extensions/runner.ts +915 -0
- package/src/core/extensions/types.ts +1461 -0
- package/src/core/extensions/wrapper.ts +27 -0
- package/src/core/footer-data-provider.ts +273 -0
- package/src/core/index.ts +61 -0
- package/src/core/keybindings.ts +302 -0
- package/src/core/messages.ts +195 -0
- package/src/core/model-registry.ts +766 -0
- package/src/core/model-resolver.ts +606 -0
- package/src/core/output-guard.ts +74 -0
- package/src/core/package-manager.ts +2222 -0
- package/src/core/prompt-templates.ts +294 -0
- package/src/core/resolve-config-value.ts +142 -0
- package/src/core/resource-loader.ts +886 -0
- package/src/core/sdk.ts +360 -0
- package/src/core/self-update.ts +57 -0
- package/src/core/session-manager.ts +1410 -0
- package/src/core/settings-manager.ts +973 -0
- package/src/core/skills.ts +508 -0
- package/src/core/slash-commands.ts +37 -0
- package/src/core/source-info.ts +40 -0
- package/src/core/system-prompt.ts +168 -0
- package/src/core/timings.ts +31 -0
- package/src/core/tools/bash.ts +431 -0
- package/src/core/tools/edit-diff.ts +445 -0
- package/src/core/tools/edit.ts +307 -0
- package/src/core/tools/file-mutation-queue.ts +39 -0
- package/src/core/tools/find.ts +314 -0
- package/src/core/tools/grep.ts +375 -0
- package/src/core/tools/index.ts +193 -0
- package/src/core/tools/ls.ts +233 -0
- package/src/core/tools/path-utils.ts +94 -0
- package/src/core/tools/read.ts +269 -0
- package/src/core/tools/render-utils.ts +64 -0
- package/src/core/tools/tool-definition-wrapper.ts +43 -0
- package/src/core/tools/truncate.ts +265 -0
- package/src/core/tools/write.ts +285 -0
- package/src/core/version-check.ts +85 -0
- package/src/index.ts +348 -0
- package/src/main.ts +958 -0
- package/src/migrations.ts +290 -0
- package/src/modes/index.ts +9 -0
- package/src/modes/interactive/components/armin.ts +382 -0
- package/src/modes/interactive/components/assistant-message.ts +130 -0
- package/src/modes/interactive/components/bash-execution.ts +218 -0
- package/src/modes/interactive/components/bordered-loader.ts +66 -0
- package/src/modes/interactive/components/branch-summary-message.ts +58 -0
- package/src/modes/interactive/components/compaction-summary-message.ts +59 -0
- package/src/modes/interactive/components/config-selector.ts +592 -0
- package/src/modes/interactive/components/countdown-timer.ts +38 -0
- package/src/modes/interactive/components/custom-editor.ts +80 -0
- package/src/modes/interactive/components/custom-message.ts +99 -0
- package/src/modes/interactive/components/diff.ts +147 -0
- package/src/modes/interactive/components/dynamic-border.ts +25 -0
- package/src/modes/interactive/components/extension-editor.ts +147 -0
- package/src/modes/interactive/components/extension-input.ts +87 -0
- package/src/modes/interactive/components/extension-selector.ts +107 -0
- package/src/modes/interactive/components/footer.ts +216 -0
- package/src/modes/interactive/components/index.ts +31 -0
- package/src/modes/interactive/components/keybinding-hints.ts +24 -0
- package/src/modes/interactive/components/login-dialog.ts +178 -0
- package/src/modes/interactive/components/model-selector.ts +328 -0
- package/src/modes/interactive/components/oauth-selector.ts +121 -0
- package/src/modes/interactive/components/scoped-models-selector.ts +346 -0
- package/src/modes/interactive/components/session-selector-search.ts +194 -0
- package/src/modes/interactive/components/session-selector.ts +1010 -0
- package/src/modes/interactive/components/settings-selector.ts +432 -0
- package/src/modes/interactive/components/show-images-selector.ts +50 -0
- package/src/modes/interactive/components/skill-invocation-message.ts +55 -0
- package/src/modes/interactive/components/theme-selector.ts +67 -0
- package/src/modes/interactive/components/thinking-selector.ts +74 -0
- package/src/modes/interactive/components/tool-execution.ts +328 -0
- package/src/modes/interactive/components/tree-selector.ts +1197 -0
- package/src/modes/interactive/components/user-message-selector.ts +143 -0
- package/src/modes/interactive/components/user-message.ts +33 -0
- package/src/modes/interactive/components/visual-truncate.ts +50 -0
- package/src/modes/interactive/interactive-mode.ts +4501 -0
- package/src/modes/interactive/theme/dark.json +85 -0
- package/src/modes/interactive/theme/light.json +84 -0
- package/src/modes/interactive/theme/theme-schema.json +335 -0
- package/src/modes/interactive/theme/theme.ts +1137 -0
- package/src/modes/print-mode.ts +131 -0
- package/src/modes/rpc/jsonl.ts +58 -0
- package/src/modes/rpc/rpc-client.ts +505 -0
- package/src/modes/rpc/rpc-mode.ts +654 -0
- package/src/modes/rpc/rpc-types.ts +262 -0
- package/src/utils/changelog.ts +99 -0
- package/src/utils/child-process.ts +86 -0
- package/src/utils/clipboard-image.ts +300 -0
- package/src/utils/clipboard-native.ts +22 -0
- package/src/utils/clipboard.ts +81 -0
- package/src/utils/exif-orientation.ts +183 -0
- package/src/utils/frontmatter.ts +39 -0
- package/src/utils/git.ts +192 -0
- package/src/utils/image-convert.ts +41 -0
- package/src/utils/image-resize.ts +176 -0
- package/src/utils/mime.ts +30 -0
- package/src/utils/photon.ts +139 -0
- package/src/utils/shell.ts +202 -0
- package/src/utils/sleep.ts +18 -0
- package/src/utils/tools-manager.ts +287 -0
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* System prompt construction and project context loading
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { getDocsPath, getExamplesPath, getReadmePath } from "../config.js";
|
|
6
|
+
import { formatSkillsForPrompt, type Skill } from "./skills.js";
|
|
7
|
+
|
|
8
|
+
export interface BuildSystemPromptOptions {
|
|
9
|
+
/** Custom system prompt (replaces default). */
|
|
10
|
+
customPrompt?: string;
|
|
11
|
+
/** Tools to include in prompt. Default: [read, bash, edit, write] */
|
|
12
|
+
selectedTools?: string[];
|
|
13
|
+
/** Optional one-line tool snippets keyed by tool name. */
|
|
14
|
+
toolSnippets?: Record<string, string>;
|
|
15
|
+
/** Additional guideline bullets appended to the default system prompt guidelines. */
|
|
16
|
+
promptGuidelines?: string[];
|
|
17
|
+
/** Text to append to system prompt. */
|
|
18
|
+
appendSystemPrompt?: string;
|
|
19
|
+
/** Working directory. Default: process.cwd() */
|
|
20
|
+
cwd?: string;
|
|
21
|
+
/** Pre-loaded context files. */
|
|
22
|
+
contextFiles?: Array<{ path: string; content: string }>;
|
|
23
|
+
/** Pre-loaded skills. */
|
|
24
|
+
skills?: Skill[];
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** Build the system prompt with tools, guidelines, and context */
|
|
28
|
+
export function buildSystemPrompt(options: BuildSystemPromptOptions = {}): string {
|
|
29
|
+
const {
|
|
30
|
+
customPrompt,
|
|
31
|
+
selectedTools,
|
|
32
|
+
toolSnippets,
|
|
33
|
+
promptGuidelines,
|
|
34
|
+
appendSystemPrompt,
|
|
35
|
+
cwd,
|
|
36
|
+
contextFiles: providedContextFiles,
|
|
37
|
+
skills: providedSkills,
|
|
38
|
+
} = options;
|
|
39
|
+
const resolvedCwd = cwd ?? process.cwd();
|
|
40
|
+
const promptCwd = resolvedCwd.replace(/\\/g, "/");
|
|
41
|
+
|
|
42
|
+
const date = new Date().toISOString().slice(0, 10);
|
|
43
|
+
|
|
44
|
+
const appendSection = appendSystemPrompt ? `\n\n${appendSystemPrompt}` : "";
|
|
45
|
+
|
|
46
|
+
const contextFiles = providedContextFiles ?? [];
|
|
47
|
+
const skills = providedSkills ?? [];
|
|
48
|
+
|
|
49
|
+
if (customPrompt) {
|
|
50
|
+
let prompt = customPrompt;
|
|
51
|
+
|
|
52
|
+
if (appendSection) {
|
|
53
|
+
prompt += appendSection;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// Append project context files
|
|
57
|
+
if (contextFiles.length > 0) {
|
|
58
|
+
prompt += "\n\n# Project Context\n\n";
|
|
59
|
+
prompt += "Project-specific instructions and guidelines:\n\n";
|
|
60
|
+
for (const { path: filePath, content } of contextFiles) {
|
|
61
|
+
prompt += `## ${filePath}\n\n${content}\n\n`;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// Append skills section (only if read tool is available)
|
|
66
|
+
const customPromptHasRead = !selectedTools || selectedTools.includes("read");
|
|
67
|
+
if (customPromptHasRead && skills.length > 0) {
|
|
68
|
+
prompt += formatSkillsForPrompt(skills);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// Add date and working directory last
|
|
72
|
+
prompt += `\nCurrent date: ${date}`;
|
|
73
|
+
prompt += `\nCurrent working directory: ${promptCwd}`;
|
|
74
|
+
|
|
75
|
+
return prompt;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// Get absolute paths to documentation and examples
|
|
79
|
+
const readmePath = getReadmePath();
|
|
80
|
+
const docsPath = getDocsPath();
|
|
81
|
+
const examplesPath = getExamplesPath();
|
|
82
|
+
|
|
83
|
+
// Build tools list based on selected tools.
|
|
84
|
+
// A tool appears in Available tools only when the caller provides a one-line snippet.
|
|
85
|
+
const tools = selectedTools || ["read", "bash", "edit", "write"];
|
|
86
|
+
const visibleTools = tools.filter((name) => !!toolSnippets?.[name]);
|
|
87
|
+
const toolsList =
|
|
88
|
+
visibleTools.length > 0 ? visibleTools.map((name) => `- ${name}: ${toolSnippets![name]}`).join("\n") : "(none)";
|
|
89
|
+
|
|
90
|
+
// Build guidelines based on which tools are actually available
|
|
91
|
+
const guidelinesList: string[] = [];
|
|
92
|
+
const guidelinesSet = new Set<string>();
|
|
93
|
+
const addGuideline = (guideline: string): void => {
|
|
94
|
+
if (guidelinesSet.has(guideline)) {
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
guidelinesSet.add(guideline);
|
|
98
|
+
guidelinesList.push(guideline);
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
const hasBash = tools.includes("bash");
|
|
102
|
+
const hasGrep = tools.includes("grep");
|
|
103
|
+
const hasFind = tools.includes("find");
|
|
104
|
+
const hasLs = tools.includes("ls");
|
|
105
|
+
const hasRead = tools.includes("read");
|
|
106
|
+
|
|
107
|
+
// File exploration guidelines
|
|
108
|
+
if (hasBash && !hasGrep && !hasFind && !hasLs) {
|
|
109
|
+
addGuideline("Use bash for file operations like ls, rg, find");
|
|
110
|
+
} else if (hasBash && (hasGrep || hasFind || hasLs)) {
|
|
111
|
+
addGuideline("Prefer grep/find/ls tools over bash for file exploration (faster, respects .gitignore)");
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
for (const guideline of promptGuidelines ?? []) {
|
|
115
|
+
const normalized = guideline.trim();
|
|
116
|
+
if (normalized.length > 0) {
|
|
117
|
+
addGuideline(normalized);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
// Always include these
|
|
122
|
+
addGuideline("Be concise in your responses");
|
|
123
|
+
addGuideline("Show file paths clearly when working with files");
|
|
124
|
+
|
|
125
|
+
const guidelines = guidelinesList.map((g) => `- ${g}`).join("\n");
|
|
126
|
+
|
|
127
|
+
let prompt = `You are an expert coding assistant operating inside pi, a coding agent harness. You help users by reading files, executing commands, editing code, and writing new files.
|
|
128
|
+
|
|
129
|
+
Available tools:
|
|
130
|
+
${toolsList}
|
|
131
|
+
|
|
132
|
+
In addition to the tools above, you may have access to other custom tools depending on the project.
|
|
133
|
+
|
|
134
|
+
Guidelines:
|
|
135
|
+
${guidelines}
|
|
136
|
+
|
|
137
|
+
Pi documentation (read only when the user asks about pi itself, its SDK, extensions, themes, skills, or TUI):
|
|
138
|
+
- Main documentation: ${readmePath}
|
|
139
|
+
- Additional docs: ${docsPath}
|
|
140
|
+
- Examples: ${examplesPath} (extensions, custom tools, SDK)
|
|
141
|
+
- When asked about: extensions (docs/extensions.md, examples/extensions/), themes (docs/themes.md), skills (docs/skills.md), prompt templates (docs/prompt-templates.md), TUI components (docs/tui.md), keybindings (docs/keybindings.md), SDK integrations (docs/sdk.md), custom providers (docs/custom-provider.md), adding models (docs/models.md), pi packages (docs/packages.md)
|
|
142
|
+
- When working on pi topics, read the docs and examples, and follow .md cross-references before implementing
|
|
143
|
+
- Always read pi .md files completely and follow links to related docs (e.g., tui.md for TUI API details)`;
|
|
144
|
+
|
|
145
|
+
if (appendSection) {
|
|
146
|
+
prompt += appendSection;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
// Append project context files
|
|
150
|
+
if (contextFiles.length > 0) {
|
|
151
|
+
prompt += "\n\n# Project Context\n\n";
|
|
152
|
+
prompt += "Project-specific instructions and guidelines:\n\n";
|
|
153
|
+
for (const { path: filePath, content } of contextFiles) {
|
|
154
|
+
prompt += `## ${filePath}\n\n${content}\n\n`;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
// Append skills section (only if read tool is available)
|
|
159
|
+
if (hasRead && skills.length > 0) {
|
|
160
|
+
prompt += formatSkillsForPrompt(skills);
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
// Add date and working directory last
|
|
164
|
+
prompt += `\nCurrent date: ${date}`;
|
|
165
|
+
prompt += `\nCurrent working directory: ${promptCwd}`;
|
|
166
|
+
|
|
167
|
+
return prompt;
|
|
168
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Central timing instrumentation for startup profiling.
|
|
3
|
+
* Enable with PI_TIMING=1 environment variable.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
const ENABLED = process.env.PI_TIMING === "1";
|
|
7
|
+
const timings: Array<{ label: string; ms: number }> = [];
|
|
8
|
+
let lastTime = Date.now();
|
|
9
|
+
|
|
10
|
+
export function resetTimings(): void {
|
|
11
|
+
if (!ENABLED) return;
|
|
12
|
+
timings.length = 0;
|
|
13
|
+
lastTime = Date.now();
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function time(label: string): void {
|
|
17
|
+
if (!ENABLED) return;
|
|
18
|
+
const now = Date.now();
|
|
19
|
+
timings.push({ label, ms: now - lastTime });
|
|
20
|
+
lastTime = now;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function printTimings(): void {
|
|
24
|
+
if (!ENABLED || timings.length === 0) return;
|
|
25
|
+
console.error("\n--- Startup Timings ---");
|
|
26
|
+
for (const t of timings) {
|
|
27
|
+
console.error(` ${t.label}: ${t.ms}ms`);
|
|
28
|
+
}
|
|
29
|
+
console.error(` TOTAL: ${timings.reduce((a, b) => a + b.ms, 0)}ms`);
|
|
30
|
+
console.error("------------------------\n");
|
|
31
|
+
}
|
|
@@ -0,0 +1,431 @@
|
|
|
1
|
+
import { randomBytes } from "node:crypto";
|
|
2
|
+
import { createWriteStream, existsSync } from "node:fs";
|
|
3
|
+
import { tmpdir } from "node:os";
|
|
4
|
+
import { join } from "node:path";
|
|
5
|
+
import type { AgentTool } from "@lenylvt/pi-agent-core";
|
|
6
|
+
import { Container, Text, truncateToWidth } from "@lenylvt/pi-tui";
|
|
7
|
+
import { type Static, Type } from "@sinclair/typebox";
|
|
8
|
+
import { spawn } from "child_process";
|
|
9
|
+
import { keyHint } from "../../modes/interactive/components/keybinding-hints.js";
|
|
10
|
+
import { truncateToVisualLines } from "../../modes/interactive/components/visual-truncate.js";
|
|
11
|
+
import { theme } from "../../modes/interactive/theme/theme.js";
|
|
12
|
+
import { waitForChildProcess } from "../../utils/child-process.js";
|
|
13
|
+
import { getShellConfig, getShellEnv, killProcessTree } from "../../utils/shell.js";
|
|
14
|
+
import type { ToolDefinition, ToolRenderResultOptions } from "../extensions/types.js";
|
|
15
|
+
import { getTextOutput, invalidArgText, str } from "./render-utils.js";
|
|
16
|
+
import { wrapToolDefinition } from "./tool-definition-wrapper.js";
|
|
17
|
+
import { DEFAULT_MAX_BYTES, DEFAULT_MAX_LINES, formatSize, type TruncationResult, truncateTail } from "./truncate.js";
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Generate a unique temp file path for bash output.
|
|
21
|
+
*/
|
|
22
|
+
function getTempFilePath(): string {
|
|
23
|
+
const id = randomBytes(8).toString("hex");
|
|
24
|
+
return join(tmpdir(), `pi-bash-${id}.log`);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const bashSchema = Type.Object({
|
|
28
|
+
command: Type.String({ description: "Bash command to execute" }),
|
|
29
|
+
timeout: Type.Optional(Type.Number({ description: "Timeout in seconds (optional, no default timeout)" })),
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
export type BashToolInput = Static<typeof bashSchema>;
|
|
33
|
+
|
|
34
|
+
export interface BashToolDetails {
|
|
35
|
+
truncation?: TruncationResult;
|
|
36
|
+
fullOutputPath?: string;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Pluggable operations for the bash tool.
|
|
41
|
+
* Override these to delegate command execution to remote systems (for example SSH).
|
|
42
|
+
*/
|
|
43
|
+
export interface BashOperations {
|
|
44
|
+
/**
|
|
45
|
+
* Execute a command and stream output.
|
|
46
|
+
* @param command The command to execute
|
|
47
|
+
* @param cwd Working directory
|
|
48
|
+
* @param options Execution options
|
|
49
|
+
* @returns Promise resolving to exit code (null if killed)
|
|
50
|
+
*/
|
|
51
|
+
exec: (
|
|
52
|
+
command: string,
|
|
53
|
+
cwd: string,
|
|
54
|
+
options: {
|
|
55
|
+
onData: (data: Buffer) => void;
|
|
56
|
+
signal?: AbortSignal;
|
|
57
|
+
timeout?: number;
|
|
58
|
+
env?: NodeJS.ProcessEnv;
|
|
59
|
+
},
|
|
60
|
+
) => Promise<{ exitCode: number | null }>;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Create bash operations using pi's built-in local shell execution backend.
|
|
65
|
+
*
|
|
66
|
+
* This is useful for extensions that intercept user_bash and still want pi's
|
|
67
|
+
* standard local shell behavior while wrapping or rewriting commands.
|
|
68
|
+
*/
|
|
69
|
+
export function createLocalBashOperations(): BashOperations {
|
|
70
|
+
return {
|
|
71
|
+
exec: (command, cwd, { onData, signal, timeout, env }) => {
|
|
72
|
+
return new Promise((resolve, reject) => {
|
|
73
|
+
const { shell, args } = getShellConfig();
|
|
74
|
+
if (!existsSync(cwd)) {
|
|
75
|
+
reject(new Error(`Working directory does not exist: ${cwd}\nCannot execute bash commands.`));
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
const child = spawn(shell, [...args, command], {
|
|
79
|
+
cwd,
|
|
80
|
+
detached: true,
|
|
81
|
+
env: env ?? getShellEnv(),
|
|
82
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
83
|
+
});
|
|
84
|
+
let timedOut = false;
|
|
85
|
+
let timeoutHandle: NodeJS.Timeout | undefined;
|
|
86
|
+
// Set timeout if provided.
|
|
87
|
+
if (timeout !== undefined && timeout > 0) {
|
|
88
|
+
timeoutHandle = setTimeout(() => {
|
|
89
|
+
timedOut = true;
|
|
90
|
+
if (child.pid) killProcessTree(child.pid);
|
|
91
|
+
}, timeout * 1000);
|
|
92
|
+
}
|
|
93
|
+
// Stream stdout and stderr.
|
|
94
|
+
child.stdout?.on("data", onData);
|
|
95
|
+
child.stderr?.on("data", onData);
|
|
96
|
+
// Handle abort signal by killing the entire process tree.
|
|
97
|
+
const onAbort = () => {
|
|
98
|
+
if (child.pid) killProcessTree(child.pid);
|
|
99
|
+
};
|
|
100
|
+
if (signal) {
|
|
101
|
+
if (signal.aborted) onAbort();
|
|
102
|
+
else signal.addEventListener("abort", onAbort, { once: true });
|
|
103
|
+
}
|
|
104
|
+
// Handle shell spawn errors and wait for the process to terminate without hanging
|
|
105
|
+
// on inherited stdio handles held by detached descendants.
|
|
106
|
+
waitForChildProcess(child)
|
|
107
|
+
.then((code) => {
|
|
108
|
+
if (timeoutHandle) clearTimeout(timeoutHandle);
|
|
109
|
+
if (signal) signal.removeEventListener("abort", onAbort);
|
|
110
|
+
if (signal?.aborted) {
|
|
111
|
+
reject(new Error("aborted"));
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
if (timedOut) {
|
|
115
|
+
reject(new Error(`timeout:${timeout}`));
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
resolve({ exitCode: code });
|
|
119
|
+
})
|
|
120
|
+
.catch((err) => {
|
|
121
|
+
if (timeoutHandle) clearTimeout(timeoutHandle);
|
|
122
|
+
if (signal) signal.removeEventListener("abort", onAbort);
|
|
123
|
+
reject(err);
|
|
124
|
+
});
|
|
125
|
+
});
|
|
126
|
+
},
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
export interface BashSpawnContext {
|
|
131
|
+
command: string;
|
|
132
|
+
cwd: string;
|
|
133
|
+
env: NodeJS.ProcessEnv;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
export type BashSpawnHook = (context: BashSpawnContext) => BashSpawnContext;
|
|
137
|
+
|
|
138
|
+
function resolveSpawnContext(command: string, cwd: string, spawnHook?: BashSpawnHook): BashSpawnContext {
|
|
139
|
+
const baseContext: BashSpawnContext = { command, cwd, env: { ...getShellEnv() } };
|
|
140
|
+
return spawnHook ? spawnHook(baseContext) : baseContext;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
export interface BashToolOptions {
|
|
144
|
+
/** Custom operations for command execution. Default: local shell */
|
|
145
|
+
operations?: BashOperations;
|
|
146
|
+
/** Command prefix prepended to every command (for example shell setup commands) */
|
|
147
|
+
commandPrefix?: string;
|
|
148
|
+
/** Hook to adjust command, cwd, or env before execution */
|
|
149
|
+
spawnHook?: BashSpawnHook;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
const BASH_PREVIEW_LINES = 5;
|
|
153
|
+
|
|
154
|
+
type BashRenderState = {
|
|
155
|
+
startedAt: number | undefined;
|
|
156
|
+
endedAt: number | undefined;
|
|
157
|
+
interval: NodeJS.Timeout | undefined;
|
|
158
|
+
};
|
|
159
|
+
|
|
160
|
+
type BashResultRenderState = {
|
|
161
|
+
cachedWidth: number | undefined;
|
|
162
|
+
cachedLines: string[] | undefined;
|
|
163
|
+
cachedSkipped: number | undefined;
|
|
164
|
+
};
|
|
165
|
+
|
|
166
|
+
class BashResultRenderComponent extends Container {
|
|
167
|
+
state: BashResultRenderState = {
|
|
168
|
+
cachedWidth: undefined,
|
|
169
|
+
cachedLines: undefined,
|
|
170
|
+
cachedSkipped: undefined,
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
function formatDuration(ms: number): string {
|
|
175
|
+
return `${(ms / 1000).toFixed(1)}s`;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
function formatBashCall(args: { command?: string; timeout?: number } | undefined): string {
|
|
179
|
+
const command = str(args?.command);
|
|
180
|
+
const timeout = args?.timeout as number | undefined;
|
|
181
|
+
const timeoutSuffix = timeout ? theme.fg("muted", ` (timeout ${timeout}s)`) : "";
|
|
182
|
+
const commandDisplay = command === null ? invalidArgText(theme) : command ? command : theme.fg("toolOutput", "...");
|
|
183
|
+
return theme.fg("toolTitle", theme.bold(`$ ${commandDisplay}`)) + timeoutSuffix;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
function rebuildBashResultRenderComponent(
|
|
187
|
+
component: BashResultRenderComponent,
|
|
188
|
+
result: {
|
|
189
|
+
content: Array<{ type: string; text?: string; data?: string; mimeType?: string }>;
|
|
190
|
+
details?: BashToolDetails;
|
|
191
|
+
},
|
|
192
|
+
options: ToolRenderResultOptions,
|
|
193
|
+
showImages: boolean,
|
|
194
|
+
startedAt: number | undefined,
|
|
195
|
+
endedAt: number | undefined,
|
|
196
|
+
): void {
|
|
197
|
+
const state = component.state;
|
|
198
|
+
component.clear();
|
|
199
|
+
|
|
200
|
+
const output = getTextOutput(result as any, showImages).trim();
|
|
201
|
+
|
|
202
|
+
if (output) {
|
|
203
|
+
const styledOutput = output
|
|
204
|
+
.split("\n")
|
|
205
|
+
.map((line) => theme.fg("toolOutput", line))
|
|
206
|
+
.join("\n");
|
|
207
|
+
|
|
208
|
+
if (options.expanded) {
|
|
209
|
+
component.addChild(new Text(`\n${styledOutput}`, 0, 0));
|
|
210
|
+
} else {
|
|
211
|
+
component.addChild({
|
|
212
|
+
render: (width: number) => {
|
|
213
|
+
if (state.cachedLines === undefined || state.cachedWidth !== width) {
|
|
214
|
+
const preview = truncateToVisualLines(styledOutput, BASH_PREVIEW_LINES, width);
|
|
215
|
+
state.cachedLines = preview.visualLines;
|
|
216
|
+
state.cachedSkipped = preview.skippedCount;
|
|
217
|
+
state.cachedWidth = width;
|
|
218
|
+
}
|
|
219
|
+
if (state.cachedSkipped && state.cachedSkipped > 0) {
|
|
220
|
+
const hint =
|
|
221
|
+
theme.fg("muted", `... (${state.cachedSkipped} earlier lines,`) +
|
|
222
|
+
` ${keyHint("app.tools.expand", "to expand")})`;
|
|
223
|
+
return ["", truncateToWidth(hint, width, "..."), ...(state.cachedLines ?? [])];
|
|
224
|
+
}
|
|
225
|
+
return ["", ...(state.cachedLines ?? [])];
|
|
226
|
+
},
|
|
227
|
+
invalidate: () => {
|
|
228
|
+
state.cachedWidth = undefined;
|
|
229
|
+
state.cachedLines = undefined;
|
|
230
|
+
state.cachedSkipped = undefined;
|
|
231
|
+
},
|
|
232
|
+
});
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
const truncation = result.details?.truncation;
|
|
237
|
+
const fullOutputPath = result.details?.fullOutputPath;
|
|
238
|
+
if (truncation?.truncated || fullOutputPath) {
|
|
239
|
+
const warnings: string[] = [];
|
|
240
|
+
if (fullOutputPath) {
|
|
241
|
+
warnings.push(`Full output: ${fullOutputPath}`);
|
|
242
|
+
}
|
|
243
|
+
if (truncation?.truncated) {
|
|
244
|
+
if (truncation.truncatedBy === "lines") {
|
|
245
|
+
warnings.push(`Truncated: showing ${truncation.outputLines} of ${truncation.totalLines} lines`);
|
|
246
|
+
} else {
|
|
247
|
+
warnings.push(
|
|
248
|
+
`Truncated: ${truncation.outputLines} lines shown (${formatSize(truncation.maxBytes ?? DEFAULT_MAX_BYTES)} limit)`,
|
|
249
|
+
);
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
component.addChild(new Text(`\n${theme.fg("warning", `[${warnings.join(". ")}]`)}`, 0, 0));
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
if (startedAt !== undefined) {
|
|
256
|
+
const label = options.isPartial ? "Elapsed" : "Took";
|
|
257
|
+
const endTime = endedAt ?? Date.now();
|
|
258
|
+
component.addChild(new Text(`\n${theme.fg("muted", `${label} ${formatDuration(endTime - startedAt)}`)}`, 0, 0));
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
export function createBashToolDefinition(
|
|
263
|
+
cwd: string,
|
|
264
|
+
options?: BashToolOptions,
|
|
265
|
+
): ToolDefinition<typeof bashSchema, BashToolDetails | undefined, BashRenderState> {
|
|
266
|
+
const ops = options?.operations ?? createLocalBashOperations();
|
|
267
|
+
const commandPrefix = options?.commandPrefix;
|
|
268
|
+
const spawnHook = options?.spawnHook;
|
|
269
|
+
return {
|
|
270
|
+
name: "bash",
|
|
271
|
+
label: "bash",
|
|
272
|
+
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.`,
|
|
273
|
+
promptSnippet: "Execute bash commands (ls, grep, find, etc.)",
|
|
274
|
+
parameters: bashSchema,
|
|
275
|
+
async execute(
|
|
276
|
+
_toolCallId,
|
|
277
|
+
{ command, timeout }: { command: string; timeout?: number },
|
|
278
|
+
signal?: AbortSignal,
|
|
279
|
+
onUpdate?,
|
|
280
|
+
_ctx?,
|
|
281
|
+
) {
|
|
282
|
+
const resolvedCommand = commandPrefix ? `${commandPrefix}\n${command}` : command;
|
|
283
|
+
const spawnContext = resolveSpawnContext(resolvedCommand, cwd, spawnHook);
|
|
284
|
+
if (onUpdate) {
|
|
285
|
+
onUpdate({ content: [], details: undefined });
|
|
286
|
+
}
|
|
287
|
+
return new Promise((resolve, reject) => {
|
|
288
|
+
let tempFilePath: string | undefined;
|
|
289
|
+
let tempFileStream: ReturnType<typeof createWriteStream> | undefined;
|
|
290
|
+
let totalBytes = 0;
|
|
291
|
+
const chunks: Buffer[] = [];
|
|
292
|
+
let chunksBytes = 0;
|
|
293
|
+
const maxChunksBytes = DEFAULT_MAX_BYTES * 2;
|
|
294
|
+
|
|
295
|
+
const handleData = (data: Buffer) => {
|
|
296
|
+
totalBytes += data.length;
|
|
297
|
+
// Start writing to a temp file once output exceeds the in-memory threshold.
|
|
298
|
+
if (totalBytes > DEFAULT_MAX_BYTES && !tempFilePath) {
|
|
299
|
+
tempFilePath = getTempFilePath();
|
|
300
|
+
tempFileStream = createWriteStream(tempFilePath);
|
|
301
|
+
// Write all buffered chunks to the file.
|
|
302
|
+
for (const chunk of chunks) tempFileStream.write(chunk);
|
|
303
|
+
}
|
|
304
|
+
// Write to temp file if we have one.
|
|
305
|
+
if (tempFileStream) tempFileStream.write(data);
|
|
306
|
+
// Keep a rolling buffer of recent output for tail truncation.
|
|
307
|
+
chunks.push(data);
|
|
308
|
+
chunksBytes += data.length;
|
|
309
|
+
// Trim old chunks if the rolling buffer grows too large.
|
|
310
|
+
while (chunksBytes > maxChunksBytes && chunks.length > 1) {
|
|
311
|
+
const removed = chunks.shift()!;
|
|
312
|
+
chunksBytes -= removed.length;
|
|
313
|
+
}
|
|
314
|
+
// Stream partial output using the rolling tail buffer.
|
|
315
|
+
if (onUpdate) {
|
|
316
|
+
const fullBuffer = Buffer.concat(chunks);
|
|
317
|
+
const fullText = fullBuffer.toString("utf-8");
|
|
318
|
+
const truncation = truncateTail(fullText);
|
|
319
|
+
onUpdate({
|
|
320
|
+
content: [{ type: "text", text: truncation.content || "" }],
|
|
321
|
+
details: {
|
|
322
|
+
truncation: truncation.truncated ? truncation : undefined,
|
|
323
|
+
fullOutputPath: tempFilePath,
|
|
324
|
+
},
|
|
325
|
+
});
|
|
326
|
+
}
|
|
327
|
+
};
|
|
328
|
+
|
|
329
|
+
ops.exec(spawnContext.command, spawnContext.cwd, {
|
|
330
|
+
onData: handleData,
|
|
331
|
+
signal,
|
|
332
|
+
timeout,
|
|
333
|
+
env: spawnContext.env,
|
|
334
|
+
})
|
|
335
|
+
.then(({ exitCode }) => {
|
|
336
|
+
// Close temp file stream before building the final result.
|
|
337
|
+
if (tempFileStream) tempFileStream.end();
|
|
338
|
+
// Combine the rolling buffer chunks.
|
|
339
|
+
const fullBuffer = Buffer.concat(chunks);
|
|
340
|
+
const fullOutput = fullBuffer.toString("utf-8");
|
|
341
|
+
// Apply tail truncation for the final display payload.
|
|
342
|
+
const truncation = truncateTail(fullOutput);
|
|
343
|
+
let outputText = truncation.content || "(no output)";
|
|
344
|
+
let details: BashToolDetails | undefined;
|
|
345
|
+
if (truncation.truncated) {
|
|
346
|
+
// Build truncation details and an actionable notice.
|
|
347
|
+
details = { truncation, fullOutputPath: tempFilePath };
|
|
348
|
+
const startLine = truncation.totalLines - truncation.outputLines + 1;
|
|
349
|
+
const endLine = truncation.totalLines;
|
|
350
|
+
if (truncation.lastLinePartial) {
|
|
351
|
+
// Edge case: the last line alone is larger than the byte limit.
|
|
352
|
+
const lastLineSize = formatSize(Buffer.byteLength(fullOutput.split("\n").pop() || "", "utf-8"));
|
|
353
|
+
outputText += `\n\n[Showing last ${formatSize(truncation.outputBytes)} of line ${endLine} (line is ${lastLineSize}). Full output: ${tempFilePath}]`;
|
|
354
|
+
} else if (truncation.truncatedBy === "lines") {
|
|
355
|
+
outputText += `\n\n[Showing lines ${startLine}-${endLine} of ${truncation.totalLines}. Full output: ${tempFilePath}]`;
|
|
356
|
+
} else {
|
|
357
|
+
outputText += `\n\n[Showing lines ${startLine}-${endLine} of ${truncation.totalLines} (${formatSize(DEFAULT_MAX_BYTES)} limit). Full output: ${tempFilePath}]`;
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
if (exitCode !== 0 && exitCode !== null) {
|
|
361
|
+
outputText += `\n\nCommand exited with code ${exitCode}`;
|
|
362
|
+
reject(new Error(outputText));
|
|
363
|
+
} else {
|
|
364
|
+
resolve({ content: [{ type: "text", text: outputText }], details });
|
|
365
|
+
}
|
|
366
|
+
})
|
|
367
|
+
.catch((err: Error) => {
|
|
368
|
+
// Close temp file stream and include buffered output in the error message.
|
|
369
|
+
if (tempFileStream) tempFileStream.end();
|
|
370
|
+
const fullBuffer = Buffer.concat(chunks);
|
|
371
|
+
let output = fullBuffer.toString("utf-8");
|
|
372
|
+
if (err.message === "aborted") {
|
|
373
|
+
if (output) output += "\n\n";
|
|
374
|
+
output += "Command aborted";
|
|
375
|
+
reject(new Error(output));
|
|
376
|
+
} else if (err.message.startsWith("timeout:")) {
|
|
377
|
+
const timeoutSecs = err.message.split(":")[1];
|
|
378
|
+
if (output) output += "\n\n";
|
|
379
|
+
output += `Command timed out after ${timeoutSecs} seconds`;
|
|
380
|
+
reject(new Error(output));
|
|
381
|
+
} else {
|
|
382
|
+
reject(err);
|
|
383
|
+
}
|
|
384
|
+
});
|
|
385
|
+
});
|
|
386
|
+
},
|
|
387
|
+
renderCall(args, _theme, context) {
|
|
388
|
+
const state = context.state;
|
|
389
|
+
if (context.executionStarted && state.startedAt === undefined) {
|
|
390
|
+
state.startedAt = Date.now();
|
|
391
|
+
state.endedAt = undefined;
|
|
392
|
+
}
|
|
393
|
+
const text = (context.lastComponent as Text | undefined) ?? new Text("", 0, 0);
|
|
394
|
+
text.setText(formatBashCall(args));
|
|
395
|
+
return text;
|
|
396
|
+
},
|
|
397
|
+
renderResult(result, options, _theme, context) {
|
|
398
|
+
const state = context.state;
|
|
399
|
+
if (state.startedAt !== undefined && options.isPartial && !state.interval) {
|
|
400
|
+
state.interval = setInterval(() => context.invalidate(), 1000);
|
|
401
|
+
}
|
|
402
|
+
if (!options.isPartial || context.isError) {
|
|
403
|
+
state.endedAt ??= Date.now();
|
|
404
|
+
if (state.interval) {
|
|
405
|
+
clearInterval(state.interval);
|
|
406
|
+
state.interval = undefined;
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
const component =
|
|
410
|
+
(context.lastComponent as BashResultRenderComponent | undefined) ?? new BashResultRenderComponent();
|
|
411
|
+
rebuildBashResultRenderComponent(
|
|
412
|
+
component,
|
|
413
|
+
result as any,
|
|
414
|
+
options,
|
|
415
|
+
context.showImages,
|
|
416
|
+
state.startedAt,
|
|
417
|
+
state.endedAt,
|
|
418
|
+
);
|
|
419
|
+
component.invalidate();
|
|
420
|
+
return component;
|
|
421
|
+
},
|
|
422
|
+
};
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
export function createBashTool(cwd: string, options?: BashToolOptions): AgentTool<typeof bashSchema> {
|
|
426
|
+
return wrapToolDefinition(createBashToolDefinition(cwd, options));
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
/** Default bash tool using process.cwd() for backwards compatibility. */
|
|
430
|
+
export const bashToolDefinition = createBashToolDefinition(process.cwd());
|
|
431
|
+
export const bashTool = createBashTool(process.cwd());
|