@vandeepunk/pi-coding-agent 0.0.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 +2564 -0
- package/README.md +555 -0
- package/dist/cli/args.d.ts +47 -0
- package/dist/cli/args.d.ts.map +1 -0
- package/dist/cli/args.js +286 -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 +79 -0
- package/dist/cli/file-processor.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 +34 -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 +11 -0
- package/dist/cli.js.map +1 -0
- package/dist/config.d.ts +68 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +203 -0
- package/dist/config.js.map +1 -0
- package/dist/core/agent-session.d.ts +574 -0
- package/dist/core/agent-session.d.ts.map +1 -0
- package/dist/core/agent-session.js +2260 -0
- package/dist/core/agent-session.js.map +1 -0
- package/dist/core/auth-storage.d.ts +102 -0
- package/dist/core/auth-storage.d.ts.map +1 -0
- package/dist/core/auth-storage.js +282 -0
- package/dist/core/auth-storage.js.map +1 -0
- package/dist/core/bash-executor.d.ts +47 -0
- package/dist/core/bash-executor.d.ts.map +1 -0
- package/dist/core/bash-executor.js +212 -0
- package/dist/core/bash-executor.js.map +1 -0
- package/dist/core/compaction/branch-summarization.d.ts +86 -0
- package/dist/core/compaction/branch-summarization.d.ts.map +1 -0
- package/dist/core/compaction/branch-summarization.js +242 -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 +607 -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 +35 -0
- package/dist/core/compaction/utils.d.ts.map +1 -0
- package/dist/core/compaction/utils.js +138 -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 +71 -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 +34 -0
- package/dist/core/export-html/index.d.ts.map +1 -0
- package/dist/core/export-html/index.js +222 -0
- package/dist/core/export-html/index.js.map +1 -0
- package/dist/core/export-html/template.css +909 -0
- package/dist/core/export-html/template.html +54 -0
- package/dist/core/export-html/template.js +1549 -0
- package/dist/core/export-html/tool-renderer.d.ts +35 -0
- package/dist/core/export-html/tool-renderer.d.ts.map +1 -0
- package/dist/core/export-html/tool-renderer.js +57 -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 +11 -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 +400 -0
- package/dist/core/extensions/loader.js.map +1 -0
- package/dist/core/extensions/runner.d.ts +129 -0
- package/dist/core/extensions/runner.d.ts.map +1 -0
- package/dist/core/extensions/runner.js +576 -0
- package/dist/core/extensions/runner.js.map +1 -0
- package/dist/core/extensions/types.d.ts +928 -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 +27 -0
- package/dist/core/extensions/wrapper.d.ts.map +1 -0
- package/dist/core/extensions/wrapper.js +102 -0
- package/dist/core/extensions/wrapper.js.map +1 -0
- package/dist/core/footer-data-provider.d.ts +32 -0
- package/dist/core/footer-data-provider.d.ts.map +1 -0
- package/dist/core/footer-data-provider.js +134 -0
- package/dist/core/footer-data-provider.js.map +1 -0
- package/dist/core/index.d.ts +9 -0
- package/dist/core/index.d.ts.map +1 -0
- package/dist/core/index.js +9 -0
- package/dist/core/index.js.map +1 -0
- package/dist/core/keybindings.d.ts +55 -0
- package/dist/core/keybindings.d.ts.map +1 -0
- package/dist/core/keybindings.js +153 -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 +100 -0
- package/dist/core/model-registry.d.ts.map +1 -0
- package/dist/core/model-registry.js +419 -0
- package/dist/core/model-registry.js.map +1 -0
- package/dist/core/model-resolver.d.ts +76 -0
- package/dist/core/model-resolver.d.ts.map +1 -0
- package/dist/core/model-resolver.js +313 -0
- package/dist/core/model-resolver.js.map +1 -0
- package/dist/core/package-manager.d.ts +131 -0
- package/dist/core/package-manager.d.ts.map +1 -0
- package/dist/core/package-manager.js +1290 -0
- package/dist/core/package-manager.js.map +1 -0
- package/dist/core/prompt-templates.d.ts +50 -0
- package/dist/core/prompt-templates.d.ts.map +1 -0
- package/dist/core/prompt-templates.js +251 -0
- package/dist/core/prompt-templates.js.map +1 -0
- package/dist/core/resolve-config-value.d.ts +17 -0
- package/dist/core/resolve-config-value.d.ts.map +1 -0
- package/dist/core/resolve-config-value.js +59 -0
- package/dist/core/resolve-config-value.js.map +1 -0
- package/dist/core/resource-loader.d.ts +184 -0
- package/dist/core/resource-loader.d.ts.map +1 -0
- package/dist/core/resource-loader.js +673 -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 +234 -0
- package/dist/core/sdk.js.map +1 -0
- package/dist/core/session-manager.d.ts +323 -0
- package/dist/core/session-manager.d.ts.map +1 -0
- package/dist/core/session-manager.js +1091 -0
- package/dist/core/session-manager.js.map +1 -0
- package/dist/core/settings-manager.d.ts +187 -0
- package/dist/core/settings-manager.d.ts.map +1 -0
- package/dist/core/settings-manager.js +552 -0
- package/dist/core/settings-manager.js.map +1 -0
- package/dist/core/skills.d.ts +58 -0
- package/dist/core/skills.d.ts.map +1 -0
- package/dist/core/skills.js +310 -0
- package/dist/core/skills.js.map +1 -0
- package/dist/core/slash-commands.d.ts +15 -0
- package/dist/core/slash-commands.d.ts.map +1 -0
- package/dist/core/slash-commands.js +21 -0
- package/dist/core/slash-commands.js.map +1 -0
- package/dist/core/system-prompt.d.ts +24 -0
- package/dist/core/system-prompt.d.ts.map +1 -0
- package/dist/core/system-prompt.js +137 -0
- package/dist/core/system-prompt.js.map +1 -0
- package/dist/core/timings.d.ts +7 -0
- package/dist/core/timings.d.ts.map +1 -0
- package/dist/core/timings.js +25 -0
- package/dist/core/timings.js.map +1 -0
- package/dist/core/tools/bash.d.ts +55 -0
- package/dist/core/tools/bash.d.ts.map +1 -0
- package/dist/core/tools/bash.js +242 -0
- package/dist/core/tools/bash.js.map +1 -0
- package/dist/core/tools/edit-diff.d.ts +63 -0
- package/dist/core/tools/edit-diff.d.ts.map +1 -0
- package/dist/core/tools/edit-diff.js +243 -0
- package/dist/core/tools/edit-diff.js.map +1 -0
- package/dist/core/tools/edit.d.ts +39 -0
- package/dist/core/tools/edit.d.ts.map +1 -0
- package/dist/core/tools/edit.js +146 -0
- package/dist/core/tools/edit.js.map +1 -0
- package/dist/core/tools/find.d.ts +39 -0
- package/dist/core/tools/find.d.ts.map +1 -0
- package/dist/core/tools/find.js +206 -0
- package/dist/core/tools/find.js.map +1 -0
- package/dist/core/tools/grep.d.ts +45 -0
- package/dist/core/tools/grep.d.ts.map +1 -0
- package/dist/core/tools/grep.js +239 -0
- package/dist/core/tools/grep.js.map +1 -0
- package/dist/core/tools/index.d.ts +73 -0
- package/dist/core/tools/index.d.ts.map +1 -0
- package/dist/core/tools/index.js +61 -0
- package/dist/core/tools/index.js.map +1 -0
- package/dist/core/tools/ls.d.ts +40 -0
- package/dist/core/tools/ls.d.ts.map +1 -0
- package/dist/core/tools/ls.js +118 -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 +39 -0
- package/dist/core/tools/read.d.ts.map +1 -0
- package/dist/core/tools/read.js +166 -0
- package/dist/core/tools/read.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 +29 -0
- package/dist/core/tools/write.d.ts.map +1 -0
- package/dist/core/tools/write.js +78 -0
- package/dist/core/tools/write.js.map +1 -0
- package/dist/index.d.ts +27 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +42 -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 +623 -0
- package/dist/main.js.map +1 -0
- package/dist/migrations.d.ts +33 -0
- package/dist/migrations.d.ts.map +1 -0
- package/dist/migrations.js +261 -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 +16 -0
- package/dist/modes/interactive/components/assistant-message.d.ts.map +1 -0
- package/dist/modes/interactive/components/assistant-message.js +91 -0
- package/dist/modes/interactive/components/assistant-message.js.map +1 -0
- package/dist/modes/interactive/components/bash-execution.d.ts +35 -0
- package/dist/modes/interactive/components/bash-execution.d.ts.map +1 -0
- package/dist/modes/interactive/components/bash-execution.js +162 -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/daxnuts.d.ts +23 -0
- package/dist/modes/interactive/components/daxnuts.d.ts.map +1 -0
- package/dist/modes/interactive/components/daxnuts.js +140 -0
- package/dist/modes/interactive/components/daxnuts.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 +17 -0
- package/dist/modes/interactive/components/extension-editor.d.ts.map +1 -0
- package/dist/modes/interactive/components/extension-editor.js +102 -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 +220 -0
- package/dist/modes/interactive/components/footer.js.map +1 -0
- package/dist/modes/interactive/components/index.d.ts +32 -0
- package/dist/modes/interactive/components/index.d.ts.map +1 -0
- package/dist/modes/interactive/components/index.js +33 -0
- package/dist/modes/interactive/components/index.js.map +1 -0
- package/dist/modes/interactive/components/keybinding-hints.d.ts +41 -0
- package/dist/modes/interactive/components/keybinding-hints.d.ts.map +1 -0
- package/dist/modes/interactive/components/keybinding-hints.js +61 -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 +266 -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 +270 -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 +851 -0
- package/dist/modes/interactive/components/session-selector.js.map +1 -0
- package/dist/modes/interactive/components/settings-selector.d.ts +53 -0
- package/dist/modes/interactive/components/settings-selector.d.ts.map +1 -0
- package/dist/modes/interactive/components/settings-selector.js +277 -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 +35 -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 +46 -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 +47 -0
- package/dist/modes/interactive/components/thinking-selector.js.map +1 -0
- package/dist/modes/interactive/components/tool-execution.d.ts +70 -0
- package/dist/modes/interactive/components/tool-execution.d.ts.map +1 -0
- package/dist/modes/interactive/components/tool-execution.js +621 -0
- package/dist/modes/interactive/components/tool-execution.js.map +1 -0
- package/dist/modes/interactive/components/tree-selector.d.ts +68 -0
- package/dist/modes/interactive/components/tree-selector.d.ts.map +1 -0
- package/dist/modes/interactive/components/tree-selector.js +934 -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 +8 -0
- package/dist/modes/interactive/components/user-message.d.ts.map +1 -0
- package/dist/modes/interactive/components/user-message.js +16 -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 +313 -0
- package/dist/modes/interactive/interactive-mode.d.ts.map +1 -0
- package/dist/modes/interactive/interactive-mode.js +3664 -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 +78 -0
- package/dist/modes/interactive/theme/theme.d.ts.map +1 -0
- package/dist/modes/interactive/theme/theme.js +944 -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 +98 -0
- package/dist/modes/print-mode.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 +405 -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 +500 -0
- package/dist/modes/rpc/rpc-mode.js.map +1 -0
- package/dist/modes/rpc/rpc-types.d.ts +409 -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/clipboard-image.d.ts +11 -0
- package/dist/utils/clipboard-image.d.ts.map +1 -0
- package/dist/utils/clipboard-image.js +162 -0
- package/dist/utils/clipboard-image.js.map +1 -0
- package/dist/utils/clipboard-native.d.ts +7 -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 +67 -0
- package/dist/utils/clipboard.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 +2 -0
- package/dist/utils/git.d.ts.map +1 -0
- package/dist/utils/git.js +6 -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 +35 -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 +181 -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 +201 -0
- package/dist/utils/tools-manager.js.map +1 -0
- package/docs/compaction.md +390 -0
- package/docs/custom-provider.md +539 -0
- package/docs/development.md +69 -0
- package/docs/extensions.md +1827 -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 +79 -0
- package/docs/keybindings.md +174 -0
- package/docs/models.md +254 -0
- package/docs/packages.md +191 -0
- package/docs/prompt-templates.md +67 -0
- package/docs/providers.md +168 -0
- package/docs/rpc.md +1311 -0
- package/docs/sdk.md +957 -0
- package/docs/session.md +412 -0
- package/docs/settings.md +221 -0
- package/docs/shell-aliases.md +13 -0
- package/docs/skills.md +227 -0
- package/docs/terminal-setup.md +70 -0
- package/docs/termux.md +127 -0
- package/docs/themes.md +295 -0
- package/docs/tree.md +219 -0
- package/docs/tui.md +887 -0
- package/docs/windows.md +17 -0
- package/examples/README.md +25 -0
- package/examples/extensions/README.md +202 -0
- package/examples/extensions/antigravity-image-gen.ts +413 -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/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 +114 -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/custom-provider-qwen-cli/index.ts +345 -0
- package/examples/extensions/custom-provider-qwen-cli/package.json +16 -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/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 +150 -0
- package/examples/extensions/hello.ts +25 -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 +881 -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 +398 -0
- package/examples/extensions/protected-paths.ts +30 -0
- package/examples/extensions/qna.ts +119 -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/rpc-demo.ts +124 -0
- package/examples/extensions/sandbox/index.ts +318 -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 +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 +127 -0
- package/examples/extensions/subagent/index.ts +963 -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 +195 -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 +143 -0
- package/examples/extensions/tools.ts +146 -0
- package/examples/extensions/trigger-compact.ts +40 -0
- package/examples/extensions/truncated-tool.ts +192 -0
- package/examples/extensions/widget-placement.ts +17 -0
- package/examples/extensions/with-deps/index.ts +36 -0
- package/examples/extensions/with-deps/package-lock.json +31 -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 +46 -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 +47 -0
- package/examples/sdk/09-api-keys-and-oauth.ts +48 -0
- package/examples/sdk/10-settings.ts +38 -0
- package/examples/sdk/11-sessions.ts +48 -0
- package/examples/sdk/12-full-control.ts +82 -0
- package/examples/sdk/README.md +144 -0
- package/package.json +97 -0
|
@@ -0,0 +1,963 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Subagent Tool - Delegate tasks to specialized agents
|
|
3
|
+
*
|
|
4
|
+
* Spawns a separate `pi` process for each subagent invocation,
|
|
5
|
+
* giving it an isolated context window.
|
|
6
|
+
*
|
|
7
|
+
* Supports three modes:
|
|
8
|
+
* - Single: { agent: "name", task: "..." }
|
|
9
|
+
* - Parallel: { tasks: [{ agent: "name", task: "..." }, ...] }
|
|
10
|
+
* - Chain: { chain: [{ agent: "name", task: "... {previous} ..." }, ...] }
|
|
11
|
+
*
|
|
12
|
+
* Uses JSON mode to capture structured output from subagents.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import { spawn } from "node:child_process";
|
|
16
|
+
import * as fs from "node:fs";
|
|
17
|
+
import * as os from "node:os";
|
|
18
|
+
import * as path from "node:path";
|
|
19
|
+
import type { AgentToolResult } from "@mariozechner/pi-agent-core";
|
|
20
|
+
import type { Message } from "@mariozechner/pi-ai";
|
|
21
|
+
import { StringEnum } from "@mariozechner/pi-ai";
|
|
22
|
+
import { type ExtensionAPI, getMarkdownTheme } from "@mariozechner/pi-coding-agent";
|
|
23
|
+
import { Container, Markdown, Spacer, Text } from "@mariozechner/pi-tui";
|
|
24
|
+
import { Type } from "@sinclair/typebox";
|
|
25
|
+
import { type AgentConfig, type AgentScope, discoverAgents } from "./agents.js";
|
|
26
|
+
|
|
27
|
+
const MAX_PARALLEL_TASKS = 8;
|
|
28
|
+
const MAX_CONCURRENCY = 4;
|
|
29
|
+
const COLLAPSED_ITEM_COUNT = 10;
|
|
30
|
+
|
|
31
|
+
function formatTokens(count: number): string {
|
|
32
|
+
if (count < 1000) return count.toString();
|
|
33
|
+
if (count < 10000) return `${(count / 1000).toFixed(1)}k`;
|
|
34
|
+
if (count < 1000000) return `${Math.round(count / 1000)}k`;
|
|
35
|
+
return `${(count / 1000000).toFixed(1)}M`;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function formatUsageStats(
|
|
39
|
+
usage: {
|
|
40
|
+
input: number;
|
|
41
|
+
output: number;
|
|
42
|
+
cacheRead: number;
|
|
43
|
+
cacheWrite: number;
|
|
44
|
+
cost: number;
|
|
45
|
+
contextTokens?: number;
|
|
46
|
+
turns?: number;
|
|
47
|
+
},
|
|
48
|
+
model?: string,
|
|
49
|
+
): string {
|
|
50
|
+
const parts: string[] = [];
|
|
51
|
+
if (usage.turns) parts.push(`${usage.turns} turn${usage.turns > 1 ? "s" : ""}`);
|
|
52
|
+
if (usage.input) parts.push(`↑${formatTokens(usage.input)}`);
|
|
53
|
+
if (usage.output) parts.push(`↓${formatTokens(usage.output)}`);
|
|
54
|
+
if (usage.cacheRead) parts.push(`R${formatTokens(usage.cacheRead)}`);
|
|
55
|
+
if (usage.cacheWrite) parts.push(`W${formatTokens(usage.cacheWrite)}`);
|
|
56
|
+
if (usage.cost) parts.push(`$${usage.cost.toFixed(4)}`);
|
|
57
|
+
if (usage.contextTokens && usage.contextTokens > 0) {
|
|
58
|
+
parts.push(`ctx:${formatTokens(usage.contextTokens)}`);
|
|
59
|
+
}
|
|
60
|
+
if (model) parts.push(model);
|
|
61
|
+
return parts.join(" ");
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function formatToolCall(
|
|
65
|
+
toolName: string,
|
|
66
|
+
args: Record<string, unknown>,
|
|
67
|
+
themeFg: (color: any, text: string) => string,
|
|
68
|
+
): string {
|
|
69
|
+
const shortenPath = (p: string) => {
|
|
70
|
+
const home = os.homedir();
|
|
71
|
+
return p.startsWith(home) ? `~${p.slice(home.length)}` : p;
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
switch (toolName) {
|
|
75
|
+
case "bash": {
|
|
76
|
+
const command = (args.command as string) || "...";
|
|
77
|
+
const preview = command.length > 60 ? `${command.slice(0, 60)}...` : command;
|
|
78
|
+
return themeFg("muted", "$ ") + themeFg("toolOutput", preview);
|
|
79
|
+
}
|
|
80
|
+
case "read": {
|
|
81
|
+
const rawPath = (args.file_path || args.path || "...") as string;
|
|
82
|
+
const filePath = shortenPath(rawPath);
|
|
83
|
+
const offset = args.offset as number | undefined;
|
|
84
|
+
const limit = args.limit as number | undefined;
|
|
85
|
+
let text = themeFg("accent", filePath);
|
|
86
|
+
if (offset !== undefined || limit !== undefined) {
|
|
87
|
+
const startLine = offset ?? 1;
|
|
88
|
+
const endLine = limit !== undefined ? startLine + limit - 1 : "";
|
|
89
|
+
text += themeFg("warning", `:${startLine}${endLine ? `-${endLine}` : ""}`);
|
|
90
|
+
}
|
|
91
|
+
return themeFg("muted", "read ") + text;
|
|
92
|
+
}
|
|
93
|
+
case "write": {
|
|
94
|
+
const rawPath = (args.file_path || args.path || "...") as string;
|
|
95
|
+
const filePath = shortenPath(rawPath);
|
|
96
|
+
const content = (args.content || "") as string;
|
|
97
|
+
const lines = content.split("\n").length;
|
|
98
|
+
let text = themeFg("muted", "write ") + themeFg("accent", filePath);
|
|
99
|
+
if (lines > 1) text += themeFg("dim", ` (${lines} lines)`);
|
|
100
|
+
return text;
|
|
101
|
+
}
|
|
102
|
+
case "edit": {
|
|
103
|
+
const rawPath = (args.file_path || args.path || "...") as string;
|
|
104
|
+
return themeFg("muted", "edit ") + themeFg("accent", shortenPath(rawPath));
|
|
105
|
+
}
|
|
106
|
+
case "ls": {
|
|
107
|
+
const rawPath = (args.path || ".") as string;
|
|
108
|
+
return themeFg("muted", "ls ") + themeFg("accent", shortenPath(rawPath));
|
|
109
|
+
}
|
|
110
|
+
case "find": {
|
|
111
|
+
const pattern = (args.pattern || "*") as string;
|
|
112
|
+
const rawPath = (args.path || ".") as string;
|
|
113
|
+
return themeFg("muted", "find ") + themeFg("accent", pattern) + themeFg("dim", ` in ${shortenPath(rawPath)}`);
|
|
114
|
+
}
|
|
115
|
+
case "grep": {
|
|
116
|
+
const pattern = (args.pattern || "") as string;
|
|
117
|
+
const rawPath = (args.path || ".") as string;
|
|
118
|
+
return (
|
|
119
|
+
themeFg("muted", "grep ") +
|
|
120
|
+
themeFg("accent", `/${pattern}/`) +
|
|
121
|
+
themeFg("dim", ` in ${shortenPath(rawPath)}`)
|
|
122
|
+
);
|
|
123
|
+
}
|
|
124
|
+
default: {
|
|
125
|
+
const argsStr = JSON.stringify(args);
|
|
126
|
+
const preview = argsStr.length > 50 ? `${argsStr.slice(0, 50)}...` : argsStr;
|
|
127
|
+
return themeFg("accent", toolName) + themeFg("dim", ` ${preview}`);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
interface UsageStats {
|
|
133
|
+
input: number;
|
|
134
|
+
output: number;
|
|
135
|
+
cacheRead: number;
|
|
136
|
+
cacheWrite: number;
|
|
137
|
+
cost: number;
|
|
138
|
+
contextTokens: number;
|
|
139
|
+
turns: number;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
interface SingleResult {
|
|
143
|
+
agent: string;
|
|
144
|
+
agentSource: "user" | "project" | "unknown";
|
|
145
|
+
task: string;
|
|
146
|
+
exitCode: number;
|
|
147
|
+
messages: Message[];
|
|
148
|
+
stderr: string;
|
|
149
|
+
usage: UsageStats;
|
|
150
|
+
model?: string;
|
|
151
|
+
stopReason?: string;
|
|
152
|
+
errorMessage?: string;
|
|
153
|
+
step?: number;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
interface SubagentDetails {
|
|
157
|
+
mode: "single" | "parallel" | "chain";
|
|
158
|
+
agentScope: AgentScope;
|
|
159
|
+
projectAgentsDir: string | null;
|
|
160
|
+
results: SingleResult[];
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
function getFinalOutput(messages: Message[]): string {
|
|
164
|
+
for (let i = messages.length - 1; i >= 0; i--) {
|
|
165
|
+
const msg = messages[i];
|
|
166
|
+
if (msg.role === "assistant") {
|
|
167
|
+
for (const part of msg.content) {
|
|
168
|
+
if (part.type === "text") return part.text;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
return "";
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
type DisplayItem = { type: "text"; text: string } | { type: "toolCall"; name: string; args: Record<string, any> };
|
|
176
|
+
|
|
177
|
+
function getDisplayItems(messages: Message[]): DisplayItem[] {
|
|
178
|
+
const items: DisplayItem[] = [];
|
|
179
|
+
for (const msg of messages) {
|
|
180
|
+
if (msg.role === "assistant") {
|
|
181
|
+
for (const part of msg.content) {
|
|
182
|
+
if (part.type === "text") items.push({ type: "text", text: part.text });
|
|
183
|
+
else if (part.type === "toolCall") items.push({ type: "toolCall", name: part.name, args: part.arguments });
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
return items;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
async function mapWithConcurrencyLimit<TIn, TOut>(
|
|
191
|
+
items: TIn[],
|
|
192
|
+
concurrency: number,
|
|
193
|
+
fn: (item: TIn, index: number) => Promise<TOut>,
|
|
194
|
+
): Promise<TOut[]> {
|
|
195
|
+
if (items.length === 0) return [];
|
|
196
|
+
const limit = Math.max(1, Math.min(concurrency, items.length));
|
|
197
|
+
const results: TOut[] = new Array(items.length);
|
|
198
|
+
let nextIndex = 0;
|
|
199
|
+
const workers = new Array(limit).fill(null).map(async () => {
|
|
200
|
+
while (true) {
|
|
201
|
+
const current = nextIndex++;
|
|
202
|
+
if (current >= items.length) return;
|
|
203
|
+
results[current] = await fn(items[current], current);
|
|
204
|
+
}
|
|
205
|
+
});
|
|
206
|
+
await Promise.all(workers);
|
|
207
|
+
return results;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
function writePromptToTempFile(agentName: string, prompt: string): { dir: string; filePath: string } {
|
|
211
|
+
const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), "pi-subagent-"));
|
|
212
|
+
const safeName = agentName.replace(/[^\w.-]+/g, "_");
|
|
213
|
+
const filePath = path.join(tmpDir, `prompt-${safeName}.md`);
|
|
214
|
+
fs.writeFileSync(filePath, prompt, { encoding: "utf-8", mode: 0o600 });
|
|
215
|
+
return { dir: tmpDir, filePath };
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
type OnUpdateCallback = (partial: AgentToolResult<SubagentDetails>) => void;
|
|
219
|
+
|
|
220
|
+
async function runSingleAgent(
|
|
221
|
+
defaultCwd: string,
|
|
222
|
+
agents: AgentConfig[],
|
|
223
|
+
agentName: string,
|
|
224
|
+
task: string,
|
|
225
|
+
cwd: string | undefined,
|
|
226
|
+
step: number | undefined,
|
|
227
|
+
signal: AbortSignal | undefined,
|
|
228
|
+
onUpdate: OnUpdateCallback | undefined,
|
|
229
|
+
makeDetails: (results: SingleResult[]) => SubagentDetails,
|
|
230
|
+
): Promise<SingleResult> {
|
|
231
|
+
const agent = agents.find((a) => a.name === agentName);
|
|
232
|
+
|
|
233
|
+
if (!agent) {
|
|
234
|
+
return {
|
|
235
|
+
agent: agentName,
|
|
236
|
+
agentSource: "unknown",
|
|
237
|
+
task,
|
|
238
|
+
exitCode: 1,
|
|
239
|
+
messages: [],
|
|
240
|
+
stderr: `Unknown agent: ${agentName}`,
|
|
241
|
+
usage: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, cost: 0, contextTokens: 0, turns: 0 },
|
|
242
|
+
step,
|
|
243
|
+
};
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
const args: string[] = ["--mode", "json", "-p", "--no-session"];
|
|
247
|
+
if (agent.model) args.push("--model", agent.model);
|
|
248
|
+
if (agent.tools && agent.tools.length > 0) args.push("--tools", agent.tools.join(","));
|
|
249
|
+
|
|
250
|
+
let tmpPromptDir: string | null = null;
|
|
251
|
+
let tmpPromptPath: string | null = null;
|
|
252
|
+
|
|
253
|
+
const currentResult: SingleResult = {
|
|
254
|
+
agent: agentName,
|
|
255
|
+
agentSource: agent.source,
|
|
256
|
+
task,
|
|
257
|
+
exitCode: 0,
|
|
258
|
+
messages: [],
|
|
259
|
+
stderr: "",
|
|
260
|
+
usage: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, cost: 0, contextTokens: 0, turns: 0 },
|
|
261
|
+
model: agent.model,
|
|
262
|
+
step,
|
|
263
|
+
};
|
|
264
|
+
|
|
265
|
+
const emitUpdate = () => {
|
|
266
|
+
if (onUpdate) {
|
|
267
|
+
onUpdate({
|
|
268
|
+
content: [{ type: "text", text: getFinalOutput(currentResult.messages) || "(running...)" }],
|
|
269
|
+
details: makeDetails([currentResult]),
|
|
270
|
+
});
|
|
271
|
+
}
|
|
272
|
+
};
|
|
273
|
+
|
|
274
|
+
try {
|
|
275
|
+
if (agent.systemPrompt.trim()) {
|
|
276
|
+
const tmp = writePromptToTempFile(agent.name, agent.systemPrompt);
|
|
277
|
+
tmpPromptDir = tmp.dir;
|
|
278
|
+
tmpPromptPath = tmp.filePath;
|
|
279
|
+
args.push("--append-system-prompt", tmpPromptPath);
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
args.push(`Task: ${task}`);
|
|
283
|
+
let wasAborted = false;
|
|
284
|
+
|
|
285
|
+
const exitCode = await new Promise<number>((resolve) => {
|
|
286
|
+
const proc = spawn("pi", args, { cwd: cwd ?? defaultCwd, shell: false, stdio: ["ignore", "pipe", "pipe"] });
|
|
287
|
+
let buffer = "";
|
|
288
|
+
|
|
289
|
+
const processLine = (line: string) => {
|
|
290
|
+
if (!line.trim()) return;
|
|
291
|
+
let event: any;
|
|
292
|
+
try {
|
|
293
|
+
event = JSON.parse(line);
|
|
294
|
+
} catch {
|
|
295
|
+
return;
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
if (event.type === "message_end" && event.message) {
|
|
299
|
+
const msg = event.message as Message;
|
|
300
|
+
currentResult.messages.push(msg);
|
|
301
|
+
|
|
302
|
+
if (msg.role === "assistant") {
|
|
303
|
+
currentResult.usage.turns++;
|
|
304
|
+
const usage = msg.usage;
|
|
305
|
+
if (usage) {
|
|
306
|
+
currentResult.usage.input += usage.input || 0;
|
|
307
|
+
currentResult.usage.output += usage.output || 0;
|
|
308
|
+
currentResult.usage.cacheRead += usage.cacheRead || 0;
|
|
309
|
+
currentResult.usage.cacheWrite += usage.cacheWrite || 0;
|
|
310
|
+
currentResult.usage.cost += usage.cost?.total || 0;
|
|
311
|
+
currentResult.usage.contextTokens = usage.totalTokens || 0;
|
|
312
|
+
}
|
|
313
|
+
if (!currentResult.model && msg.model) currentResult.model = msg.model;
|
|
314
|
+
if (msg.stopReason) currentResult.stopReason = msg.stopReason;
|
|
315
|
+
if (msg.errorMessage) currentResult.errorMessage = msg.errorMessage;
|
|
316
|
+
}
|
|
317
|
+
emitUpdate();
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
if (event.type === "tool_result_end" && event.message) {
|
|
321
|
+
currentResult.messages.push(event.message as Message);
|
|
322
|
+
emitUpdate();
|
|
323
|
+
}
|
|
324
|
+
};
|
|
325
|
+
|
|
326
|
+
proc.stdout.on("data", (data) => {
|
|
327
|
+
buffer += data.toString();
|
|
328
|
+
const lines = buffer.split("\n");
|
|
329
|
+
buffer = lines.pop() || "";
|
|
330
|
+
for (const line of lines) processLine(line);
|
|
331
|
+
});
|
|
332
|
+
|
|
333
|
+
proc.stderr.on("data", (data) => {
|
|
334
|
+
currentResult.stderr += data.toString();
|
|
335
|
+
});
|
|
336
|
+
|
|
337
|
+
proc.on("close", (code) => {
|
|
338
|
+
if (buffer.trim()) processLine(buffer);
|
|
339
|
+
resolve(code ?? 0);
|
|
340
|
+
});
|
|
341
|
+
|
|
342
|
+
proc.on("error", () => {
|
|
343
|
+
resolve(1);
|
|
344
|
+
});
|
|
345
|
+
|
|
346
|
+
if (signal) {
|
|
347
|
+
const killProc = () => {
|
|
348
|
+
wasAborted = true;
|
|
349
|
+
proc.kill("SIGTERM");
|
|
350
|
+
setTimeout(() => {
|
|
351
|
+
if (!proc.killed) proc.kill("SIGKILL");
|
|
352
|
+
}, 5000);
|
|
353
|
+
};
|
|
354
|
+
if (signal.aborted) killProc();
|
|
355
|
+
else signal.addEventListener("abort", killProc, { once: true });
|
|
356
|
+
}
|
|
357
|
+
});
|
|
358
|
+
|
|
359
|
+
currentResult.exitCode = exitCode;
|
|
360
|
+
if (wasAborted) throw new Error("Subagent was aborted");
|
|
361
|
+
return currentResult;
|
|
362
|
+
} finally {
|
|
363
|
+
if (tmpPromptPath)
|
|
364
|
+
try {
|
|
365
|
+
fs.unlinkSync(tmpPromptPath);
|
|
366
|
+
} catch {
|
|
367
|
+
/* ignore */
|
|
368
|
+
}
|
|
369
|
+
if (tmpPromptDir)
|
|
370
|
+
try {
|
|
371
|
+
fs.rmdirSync(tmpPromptDir);
|
|
372
|
+
} catch {
|
|
373
|
+
/* ignore */
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
const TaskItem = Type.Object({
|
|
379
|
+
agent: Type.String({ description: "Name of the agent to invoke" }),
|
|
380
|
+
task: Type.String({ description: "Task to delegate to the agent" }),
|
|
381
|
+
cwd: Type.Optional(Type.String({ description: "Working directory for the agent process" })),
|
|
382
|
+
});
|
|
383
|
+
|
|
384
|
+
const ChainItem = Type.Object({
|
|
385
|
+
agent: Type.String({ description: "Name of the agent to invoke" }),
|
|
386
|
+
task: Type.String({ description: "Task with optional {previous} placeholder for prior output" }),
|
|
387
|
+
cwd: Type.Optional(Type.String({ description: "Working directory for the agent process" })),
|
|
388
|
+
});
|
|
389
|
+
|
|
390
|
+
const AgentScopeSchema = StringEnum(["user", "project", "both"] as const, {
|
|
391
|
+
description: 'Which agent directories to use. Default: "user". Use "both" to include project-local agents.',
|
|
392
|
+
default: "user",
|
|
393
|
+
});
|
|
394
|
+
|
|
395
|
+
const SubagentParams = Type.Object({
|
|
396
|
+
agent: Type.Optional(Type.String({ description: "Name of the agent to invoke (for single mode)" })),
|
|
397
|
+
task: Type.Optional(Type.String({ description: "Task to delegate (for single mode)" })),
|
|
398
|
+
tasks: Type.Optional(Type.Array(TaskItem, { description: "Array of {agent, task} for parallel execution" })),
|
|
399
|
+
chain: Type.Optional(Type.Array(ChainItem, { description: "Array of {agent, task} for sequential execution" })),
|
|
400
|
+
agentScope: Type.Optional(AgentScopeSchema),
|
|
401
|
+
confirmProjectAgents: Type.Optional(
|
|
402
|
+
Type.Boolean({ description: "Prompt before running project-local agents. Default: true.", default: true }),
|
|
403
|
+
),
|
|
404
|
+
cwd: Type.Optional(Type.String({ description: "Working directory for the agent process (single mode)" })),
|
|
405
|
+
});
|
|
406
|
+
|
|
407
|
+
export default function (pi: ExtensionAPI) {
|
|
408
|
+
pi.registerTool({
|
|
409
|
+
name: "subagent",
|
|
410
|
+
label: "Subagent",
|
|
411
|
+
description: [
|
|
412
|
+
"Delegate tasks to specialized subagents with isolated context.",
|
|
413
|
+
"Modes: single (agent + task), parallel (tasks array), chain (sequential with {previous} placeholder).",
|
|
414
|
+
'Default agent scope is "user" (from ~/.pi/agent/agents).',
|
|
415
|
+
'To enable project-local agents in .pi/agents, set agentScope: "both" (or "project").',
|
|
416
|
+
].join(" "),
|
|
417
|
+
parameters: SubagentParams,
|
|
418
|
+
|
|
419
|
+
async execute(_toolCallId, params, signal, onUpdate, ctx) {
|
|
420
|
+
const agentScope: AgentScope = params.agentScope ?? "user";
|
|
421
|
+
const discovery = discoverAgents(ctx.cwd, agentScope);
|
|
422
|
+
const agents = discovery.agents;
|
|
423
|
+
const confirmProjectAgents = params.confirmProjectAgents ?? true;
|
|
424
|
+
|
|
425
|
+
const hasChain = (params.chain?.length ?? 0) > 0;
|
|
426
|
+
const hasTasks = (params.tasks?.length ?? 0) > 0;
|
|
427
|
+
const hasSingle = Boolean(params.agent && params.task);
|
|
428
|
+
const modeCount = Number(hasChain) + Number(hasTasks) + Number(hasSingle);
|
|
429
|
+
|
|
430
|
+
const makeDetails =
|
|
431
|
+
(mode: "single" | "parallel" | "chain") =>
|
|
432
|
+
(results: SingleResult[]): SubagentDetails => ({
|
|
433
|
+
mode,
|
|
434
|
+
agentScope,
|
|
435
|
+
projectAgentsDir: discovery.projectAgentsDir,
|
|
436
|
+
results,
|
|
437
|
+
});
|
|
438
|
+
|
|
439
|
+
if (modeCount !== 1) {
|
|
440
|
+
const available = agents.map((a) => `${a.name} (${a.source})`).join(", ") || "none";
|
|
441
|
+
return {
|
|
442
|
+
content: [
|
|
443
|
+
{
|
|
444
|
+
type: "text",
|
|
445
|
+
text: `Invalid parameters. Provide exactly one mode.\nAvailable agents: ${available}`,
|
|
446
|
+
},
|
|
447
|
+
],
|
|
448
|
+
details: makeDetails("single")([]),
|
|
449
|
+
};
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
if ((agentScope === "project" || agentScope === "both") && confirmProjectAgents && ctx.hasUI) {
|
|
453
|
+
const requestedAgentNames = new Set<string>();
|
|
454
|
+
if (params.chain) for (const step of params.chain) requestedAgentNames.add(step.agent);
|
|
455
|
+
if (params.tasks) for (const t of params.tasks) requestedAgentNames.add(t.agent);
|
|
456
|
+
if (params.agent) requestedAgentNames.add(params.agent);
|
|
457
|
+
|
|
458
|
+
const projectAgentsRequested = Array.from(requestedAgentNames)
|
|
459
|
+
.map((name) => agents.find((a) => a.name === name))
|
|
460
|
+
.filter((a): a is AgentConfig => a?.source === "project");
|
|
461
|
+
|
|
462
|
+
if (projectAgentsRequested.length > 0) {
|
|
463
|
+
const names = projectAgentsRequested.map((a) => a.name).join(", ");
|
|
464
|
+
const dir = discovery.projectAgentsDir ?? "(unknown)";
|
|
465
|
+
const ok = await ctx.ui.confirm(
|
|
466
|
+
"Run project-local agents?",
|
|
467
|
+
`Agents: ${names}\nSource: ${dir}\n\nProject agents are repo-controlled. Only continue for trusted repositories.`,
|
|
468
|
+
);
|
|
469
|
+
if (!ok)
|
|
470
|
+
return {
|
|
471
|
+
content: [{ type: "text", text: "Canceled: project-local agents not approved." }],
|
|
472
|
+
details: makeDetails(hasChain ? "chain" : hasTasks ? "parallel" : "single")([]),
|
|
473
|
+
};
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
if (params.chain && params.chain.length > 0) {
|
|
478
|
+
const results: SingleResult[] = [];
|
|
479
|
+
let previousOutput = "";
|
|
480
|
+
|
|
481
|
+
for (let i = 0; i < params.chain.length; i++) {
|
|
482
|
+
const step = params.chain[i];
|
|
483
|
+
const taskWithContext = step.task.replace(/\{previous\}/g, previousOutput);
|
|
484
|
+
|
|
485
|
+
// Create update callback that includes all previous results
|
|
486
|
+
const chainUpdate: OnUpdateCallback | undefined = onUpdate
|
|
487
|
+
? (partial) => {
|
|
488
|
+
// Combine completed results with current streaming result
|
|
489
|
+
const currentResult = partial.details?.results[0];
|
|
490
|
+
if (currentResult) {
|
|
491
|
+
const allResults = [...results, currentResult];
|
|
492
|
+
onUpdate({
|
|
493
|
+
content: partial.content,
|
|
494
|
+
details: makeDetails("chain")(allResults),
|
|
495
|
+
});
|
|
496
|
+
}
|
|
497
|
+
}
|
|
498
|
+
: undefined;
|
|
499
|
+
|
|
500
|
+
const result = await runSingleAgent(
|
|
501
|
+
ctx.cwd,
|
|
502
|
+
agents,
|
|
503
|
+
step.agent,
|
|
504
|
+
taskWithContext,
|
|
505
|
+
step.cwd,
|
|
506
|
+
i + 1,
|
|
507
|
+
signal,
|
|
508
|
+
chainUpdate,
|
|
509
|
+
makeDetails("chain"),
|
|
510
|
+
);
|
|
511
|
+
results.push(result);
|
|
512
|
+
|
|
513
|
+
const isError =
|
|
514
|
+
result.exitCode !== 0 || result.stopReason === "error" || result.stopReason === "aborted";
|
|
515
|
+
if (isError) {
|
|
516
|
+
const errorMsg =
|
|
517
|
+
result.errorMessage || result.stderr || getFinalOutput(result.messages) || "(no output)";
|
|
518
|
+
return {
|
|
519
|
+
content: [{ type: "text", text: `Chain stopped at step ${i + 1} (${step.agent}): ${errorMsg}` }],
|
|
520
|
+
details: makeDetails("chain")(results),
|
|
521
|
+
isError: true,
|
|
522
|
+
};
|
|
523
|
+
}
|
|
524
|
+
previousOutput = getFinalOutput(result.messages);
|
|
525
|
+
}
|
|
526
|
+
return {
|
|
527
|
+
content: [{ type: "text", text: getFinalOutput(results[results.length - 1].messages) || "(no output)" }],
|
|
528
|
+
details: makeDetails("chain")(results),
|
|
529
|
+
};
|
|
530
|
+
}
|
|
531
|
+
|
|
532
|
+
if (params.tasks && params.tasks.length > 0) {
|
|
533
|
+
if (params.tasks.length > MAX_PARALLEL_TASKS)
|
|
534
|
+
return {
|
|
535
|
+
content: [
|
|
536
|
+
{
|
|
537
|
+
type: "text",
|
|
538
|
+
text: `Too many parallel tasks (${params.tasks.length}). Max is ${MAX_PARALLEL_TASKS}.`,
|
|
539
|
+
},
|
|
540
|
+
],
|
|
541
|
+
details: makeDetails("parallel")([]),
|
|
542
|
+
};
|
|
543
|
+
|
|
544
|
+
// Track all results for streaming updates
|
|
545
|
+
const allResults: SingleResult[] = new Array(params.tasks.length);
|
|
546
|
+
|
|
547
|
+
// Initialize placeholder results
|
|
548
|
+
for (let i = 0; i < params.tasks.length; i++) {
|
|
549
|
+
allResults[i] = {
|
|
550
|
+
agent: params.tasks[i].agent,
|
|
551
|
+
agentSource: "unknown",
|
|
552
|
+
task: params.tasks[i].task,
|
|
553
|
+
exitCode: -1, // -1 = still running
|
|
554
|
+
messages: [],
|
|
555
|
+
stderr: "",
|
|
556
|
+
usage: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, cost: 0, contextTokens: 0, turns: 0 },
|
|
557
|
+
};
|
|
558
|
+
}
|
|
559
|
+
|
|
560
|
+
const emitParallelUpdate = () => {
|
|
561
|
+
if (onUpdate) {
|
|
562
|
+
const running = allResults.filter((r) => r.exitCode === -1).length;
|
|
563
|
+
const done = allResults.filter((r) => r.exitCode !== -1).length;
|
|
564
|
+
onUpdate({
|
|
565
|
+
content: [
|
|
566
|
+
{ type: "text", text: `Parallel: ${done}/${allResults.length} done, ${running} running...` },
|
|
567
|
+
],
|
|
568
|
+
details: makeDetails("parallel")([...allResults]),
|
|
569
|
+
});
|
|
570
|
+
}
|
|
571
|
+
};
|
|
572
|
+
|
|
573
|
+
const results = await mapWithConcurrencyLimit(params.tasks, MAX_CONCURRENCY, async (t, index) => {
|
|
574
|
+
const result = await runSingleAgent(
|
|
575
|
+
ctx.cwd,
|
|
576
|
+
agents,
|
|
577
|
+
t.agent,
|
|
578
|
+
t.task,
|
|
579
|
+
t.cwd,
|
|
580
|
+
undefined,
|
|
581
|
+
signal,
|
|
582
|
+
// Per-task update callback
|
|
583
|
+
(partial) => {
|
|
584
|
+
if (partial.details?.results[0]) {
|
|
585
|
+
allResults[index] = partial.details.results[0];
|
|
586
|
+
emitParallelUpdate();
|
|
587
|
+
}
|
|
588
|
+
},
|
|
589
|
+
makeDetails("parallel"),
|
|
590
|
+
);
|
|
591
|
+
allResults[index] = result;
|
|
592
|
+
emitParallelUpdate();
|
|
593
|
+
return result;
|
|
594
|
+
});
|
|
595
|
+
|
|
596
|
+
const successCount = results.filter((r) => r.exitCode === 0).length;
|
|
597
|
+
const summaries = results.map((r) => {
|
|
598
|
+
const output = getFinalOutput(r.messages);
|
|
599
|
+
const preview = output.slice(0, 100) + (output.length > 100 ? "..." : "");
|
|
600
|
+
return `[${r.agent}] ${r.exitCode === 0 ? "completed" : "failed"}: ${preview || "(no output)"}`;
|
|
601
|
+
});
|
|
602
|
+
return {
|
|
603
|
+
content: [
|
|
604
|
+
{
|
|
605
|
+
type: "text",
|
|
606
|
+
text: `Parallel: ${successCount}/${results.length} succeeded\n\n${summaries.join("\n\n")}`,
|
|
607
|
+
},
|
|
608
|
+
],
|
|
609
|
+
details: makeDetails("parallel")(results),
|
|
610
|
+
};
|
|
611
|
+
}
|
|
612
|
+
|
|
613
|
+
if (params.agent && params.task) {
|
|
614
|
+
const result = await runSingleAgent(
|
|
615
|
+
ctx.cwd,
|
|
616
|
+
agents,
|
|
617
|
+
params.agent,
|
|
618
|
+
params.task,
|
|
619
|
+
params.cwd,
|
|
620
|
+
undefined,
|
|
621
|
+
signal,
|
|
622
|
+
onUpdate,
|
|
623
|
+
makeDetails("single"),
|
|
624
|
+
);
|
|
625
|
+
const isError = result.exitCode !== 0 || result.stopReason === "error" || result.stopReason === "aborted";
|
|
626
|
+
if (isError) {
|
|
627
|
+
const errorMsg =
|
|
628
|
+
result.errorMessage || result.stderr || getFinalOutput(result.messages) || "(no output)";
|
|
629
|
+
return {
|
|
630
|
+
content: [{ type: "text", text: `Agent ${result.stopReason || "failed"}: ${errorMsg}` }],
|
|
631
|
+
details: makeDetails("single")([result]),
|
|
632
|
+
isError: true,
|
|
633
|
+
};
|
|
634
|
+
}
|
|
635
|
+
return {
|
|
636
|
+
content: [{ type: "text", text: getFinalOutput(result.messages) || "(no output)" }],
|
|
637
|
+
details: makeDetails("single")([result]),
|
|
638
|
+
};
|
|
639
|
+
}
|
|
640
|
+
|
|
641
|
+
const available = agents.map((a) => `${a.name} (${a.source})`).join(", ") || "none";
|
|
642
|
+
return {
|
|
643
|
+
content: [{ type: "text", text: `Invalid parameters. Available agents: ${available}` }],
|
|
644
|
+
details: makeDetails("single")([]),
|
|
645
|
+
};
|
|
646
|
+
},
|
|
647
|
+
|
|
648
|
+
renderCall(args, theme) {
|
|
649
|
+
const scope: AgentScope = args.agentScope ?? "user";
|
|
650
|
+
if (args.chain && args.chain.length > 0) {
|
|
651
|
+
let text =
|
|
652
|
+
theme.fg("toolTitle", theme.bold("subagent ")) +
|
|
653
|
+
theme.fg("accent", `chain (${args.chain.length} steps)`) +
|
|
654
|
+
theme.fg("muted", ` [${scope}]`);
|
|
655
|
+
for (let i = 0; i < Math.min(args.chain.length, 3); i++) {
|
|
656
|
+
const step = args.chain[i];
|
|
657
|
+
// Clean up {previous} placeholder for display
|
|
658
|
+
const cleanTask = step.task.replace(/\{previous\}/g, "").trim();
|
|
659
|
+
const preview = cleanTask.length > 40 ? `${cleanTask.slice(0, 40)}...` : cleanTask;
|
|
660
|
+
text +=
|
|
661
|
+
"\n " +
|
|
662
|
+
theme.fg("muted", `${i + 1}.`) +
|
|
663
|
+
" " +
|
|
664
|
+
theme.fg("accent", step.agent) +
|
|
665
|
+
theme.fg("dim", ` ${preview}`);
|
|
666
|
+
}
|
|
667
|
+
if (args.chain.length > 3) text += `\n ${theme.fg("muted", `... +${args.chain.length - 3} more`)}`;
|
|
668
|
+
return new Text(text, 0, 0);
|
|
669
|
+
}
|
|
670
|
+
if (args.tasks && args.tasks.length > 0) {
|
|
671
|
+
let text =
|
|
672
|
+
theme.fg("toolTitle", theme.bold("subagent ")) +
|
|
673
|
+
theme.fg("accent", `parallel (${args.tasks.length} tasks)`) +
|
|
674
|
+
theme.fg("muted", ` [${scope}]`);
|
|
675
|
+
for (const t of args.tasks.slice(0, 3)) {
|
|
676
|
+
const preview = t.task.length > 40 ? `${t.task.slice(0, 40)}...` : t.task;
|
|
677
|
+
text += `\n ${theme.fg("accent", t.agent)}${theme.fg("dim", ` ${preview}`)}`;
|
|
678
|
+
}
|
|
679
|
+
if (args.tasks.length > 3) text += `\n ${theme.fg("muted", `... +${args.tasks.length - 3} more`)}`;
|
|
680
|
+
return new Text(text, 0, 0);
|
|
681
|
+
}
|
|
682
|
+
const agentName = args.agent || "...";
|
|
683
|
+
const preview = args.task ? (args.task.length > 60 ? `${args.task.slice(0, 60)}...` : args.task) : "...";
|
|
684
|
+
let text =
|
|
685
|
+
theme.fg("toolTitle", theme.bold("subagent ")) +
|
|
686
|
+
theme.fg("accent", agentName) +
|
|
687
|
+
theme.fg("muted", ` [${scope}]`);
|
|
688
|
+
text += `\n ${theme.fg("dim", preview)}`;
|
|
689
|
+
return new Text(text, 0, 0);
|
|
690
|
+
},
|
|
691
|
+
|
|
692
|
+
renderResult(result, { expanded }, theme) {
|
|
693
|
+
const details = result.details as SubagentDetails | undefined;
|
|
694
|
+
if (!details || details.results.length === 0) {
|
|
695
|
+
const text = result.content[0];
|
|
696
|
+
return new Text(text?.type === "text" ? text.text : "(no output)", 0, 0);
|
|
697
|
+
}
|
|
698
|
+
|
|
699
|
+
const mdTheme = getMarkdownTheme();
|
|
700
|
+
|
|
701
|
+
const renderDisplayItems = (items: DisplayItem[], limit?: number) => {
|
|
702
|
+
const toShow = limit ? items.slice(-limit) : items;
|
|
703
|
+
const skipped = limit && items.length > limit ? items.length - limit : 0;
|
|
704
|
+
let text = "";
|
|
705
|
+
if (skipped > 0) text += theme.fg("muted", `... ${skipped} earlier items\n`);
|
|
706
|
+
for (const item of toShow) {
|
|
707
|
+
if (item.type === "text") {
|
|
708
|
+
const preview = expanded ? item.text : item.text.split("\n").slice(0, 3).join("\n");
|
|
709
|
+
text += `${theme.fg("toolOutput", preview)}\n`;
|
|
710
|
+
} else {
|
|
711
|
+
text += `${theme.fg("muted", "→ ") + formatToolCall(item.name, item.args, theme.fg.bind(theme))}\n`;
|
|
712
|
+
}
|
|
713
|
+
}
|
|
714
|
+
return text.trimEnd();
|
|
715
|
+
};
|
|
716
|
+
|
|
717
|
+
if (details.mode === "single" && details.results.length === 1) {
|
|
718
|
+
const r = details.results[0];
|
|
719
|
+
const isError = r.exitCode !== 0 || r.stopReason === "error" || r.stopReason === "aborted";
|
|
720
|
+
const icon = isError ? theme.fg("error", "✗") : theme.fg("success", "✓");
|
|
721
|
+
const displayItems = getDisplayItems(r.messages);
|
|
722
|
+
const finalOutput = getFinalOutput(r.messages);
|
|
723
|
+
|
|
724
|
+
if (expanded) {
|
|
725
|
+
const container = new Container();
|
|
726
|
+
let header = `${icon} ${theme.fg("toolTitle", theme.bold(r.agent))}${theme.fg("muted", ` (${r.agentSource})`)}`;
|
|
727
|
+
if (isError && r.stopReason) header += ` ${theme.fg("error", `[${r.stopReason}]`)}`;
|
|
728
|
+
container.addChild(new Text(header, 0, 0));
|
|
729
|
+
if (isError && r.errorMessage)
|
|
730
|
+
container.addChild(new Text(theme.fg("error", `Error: ${r.errorMessage}`), 0, 0));
|
|
731
|
+
container.addChild(new Spacer(1));
|
|
732
|
+
container.addChild(new Text(theme.fg("muted", "─── Task ───"), 0, 0));
|
|
733
|
+
container.addChild(new Text(theme.fg("dim", r.task), 0, 0));
|
|
734
|
+
container.addChild(new Spacer(1));
|
|
735
|
+
container.addChild(new Text(theme.fg("muted", "─── Output ───"), 0, 0));
|
|
736
|
+
if (displayItems.length === 0 && !finalOutput) {
|
|
737
|
+
container.addChild(new Text(theme.fg("muted", "(no output)"), 0, 0));
|
|
738
|
+
} else {
|
|
739
|
+
for (const item of displayItems) {
|
|
740
|
+
if (item.type === "toolCall")
|
|
741
|
+
container.addChild(
|
|
742
|
+
new Text(
|
|
743
|
+
theme.fg("muted", "→ ") + formatToolCall(item.name, item.args, theme.fg.bind(theme)),
|
|
744
|
+
0,
|
|
745
|
+
0,
|
|
746
|
+
),
|
|
747
|
+
);
|
|
748
|
+
}
|
|
749
|
+
if (finalOutput) {
|
|
750
|
+
container.addChild(new Spacer(1));
|
|
751
|
+
container.addChild(new Markdown(finalOutput.trim(), 0, 0, mdTheme));
|
|
752
|
+
}
|
|
753
|
+
}
|
|
754
|
+
const usageStr = formatUsageStats(r.usage, r.model);
|
|
755
|
+
if (usageStr) {
|
|
756
|
+
container.addChild(new Spacer(1));
|
|
757
|
+
container.addChild(new Text(theme.fg("dim", usageStr), 0, 0));
|
|
758
|
+
}
|
|
759
|
+
return container;
|
|
760
|
+
}
|
|
761
|
+
|
|
762
|
+
let text = `${icon} ${theme.fg("toolTitle", theme.bold(r.agent))}${theme.fg("muted", ` (${r.agentSource})`)}`;
|
|
763
|
+
if (isError && r.stopReason) text += ` ${theme.fg("error", `[${r.stopReason}]`)}`;
|
|
764
|
+
if (isError && r.errorMessage) text += `\n${theme.fg("error", `Error: ${r.errorMessage}`)}`;
|
|
765
|
+
else if (displayItems.length === 0) text += `\n${theme.fg("muted", "(no output)")}`;
|
|
766
|
+
else {
|
|
767
|
+
text += `\n${renderDisplayItems(displayItems, COLLAPSED_ITEM_COUNT)}`;
|
|
768
|
+
if (displayItems.length > COLLAPSED_ITEM_COUNT) text += `\n${theme.fg("muted", "(Ctrl+O to expand)")}`;
|
|
769
|
+
}
|
|
770
|
+
const usageStr = formatUsageStats(r.usage, r.model);
|
|
771
|
+
if (usageStr) text += `\n${theme.fg("dim", usageStr)}`;
|
|
772
|
+
return new Text(text, 0, 0);
|
|
773
|
+
}
|
|
774
|
+
|
|
775
|
+
const aggregateUsage = (results: SingleResult[]) => {
|
|
776
|
+
const total = { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, cost: 0, turns: 0 };
|
|
777
|
+
for (const r of results) {
|
|
778
|
+
total.input += r.usage.input;
|
|
779
|
+
total.output += r.usage.output;
|
|
780
|
+
total.cacheRead += r.usage.cacheRead;
|
|
781
|
+
total.cacheWrite += r.usage.cacheWrite;
|
|
782
|
+
total.cost += r.usage.cost;
|
|
783
|
+
total.turns += r.usage.turns;
|
|
784
|
+
}
|
|
785
|
+
return total;
|
|
786
|
+
};
|
|
787
|
+
|
|
788
|
+
if (details.mode === "chain") {
|
|
789
|
+
const successCount = details.results.filter((r) => r.exitCode === 0).length;
|
|
790
|
+
const icon = successCount === details.results.length ? theme.fg("success", "✓") : theme.fg("error", "✗");
|
|
791
|
+
|
|
792
|
+
if (expanded) {
|
|
793
|
+
const container = new Container();
|
|
794
|
+
container.addChild(
|
|
795
|
+
new Text(
|
|
796
|
+
icon +
|
|
797
|
+
" " +
|
|
798
|
+
theme.fg("toolTitle", theme.bold("chain ")) +
|
|
799
|
+
theme.fg("accent", `${successCount}/${details.results.length} steps`),
|
|
800
|
+
0,
|
|
801
|
+
0,
|
|
802
|
+
),
|
|
803
|
+
);
|
|
804
|
+
|
|
805
|
+
for (const r of details.results) {
|
|
806
|
+
const rIcon = r.exitCode === 0 ? theme.fg("success", "✓") : theme.fg("error", "✗");
|
|
807
|
+
const displayItems = getDisplayItems(r.messages);
|
|
808
|
+
const finalOutput = getFinalOutput(r.messages);
|
|
809
|
+
|
|
810
|
+
container.addChild(new Spacer(1));
|
|
811
|
+
container.addChild(
|
|
812
|
+
new Text(
|
|
813
|
+
`${theme.fg("muted", `─── Step ${r.step}: `) + theme.fg("accent", r.agent)} ${rIcon}`,
|
|
814
|
+
0,
|
|
815
|
+
0,
|
|
816
|
+
),
|
|
817
|
+
);
|
|
818
|
+
container.addChild(new Text(theme.fg("muted", "Task: ") + theme.fg("dim", r.task), 0, 0));
|
|
819
|
+
|
|
820
|
+
// Show tool calls
|
|
821
|
+
for (const item of displayItems) {
|
|
822
|
+
if (item.type === "toolCall") {
|
|
823
|
+
container.addChild(
|
|
824
|
+
new Text(
|
|
825
|
+
theme.fg("muted", "→ ") + formatToolCall(item.name, item.args, theme.fg.bind(theme)),
|
|
826
|
+
0,
|
|
827
|
+
0,
|
|
828
|
+
),
|
|
829
|
+
);
|
|
830
|
+
}
|
|
831
|
+
}
|
|
832
|
+
|
|
833
|
+
// Show final output as markdown
|
|
834
|
+
if (finalOutput) {
|
|
835
|
+
container.addChild(new Spacer(1));
|
|
836
|
+
container.addChild(new Markdown(finalOutput.trim(), 0, 0, mdTheme));
|
|
837
|
+
}
|
|
838
|
+
|
|
839
|
+
const stepUsage = formatUsageStats(r.usage, r.model);
|
|
840
|
+
if (stepUsage) container.addChild(new Text(theme.fg("dim", stepUsage), 0, 0));
|
|
841
|
+
}
|
|
842
|
+
|
|
843
|
+
const usageStr = formatUsageStats(aggregateUsage(details.results));
|
|
844
|
+
if (usageStr) {
|
|
845
|
+
container.addChild(new Spacer(1));
|
|
846
|
+
container.addChild(new Text(theme.fg("dim", `Total: ${usageStr}`), 0, 0));
|
|
847
|
+
}
|
|
848
|
+
return container;
|
|
849
|
+
}
|
|
850
|
+
|
|
851
|
+
// Collapsed view
|
|
852
|
+
let text =
|
|
853
|
+
icon +
|
|
854
|
+
" " +
|
|
855
|
+
theme.fg("toolTitle", theme.bold("chain ")) +
|
|
856
|
+
theme.fg("accent", `${successCount}/${details.results.length} steps`);
|
|
857
|
+
for (const r of details.results) {
|
|
858
|
+
const rIcon = r.exitCode === 0 ? theme.fg("success", "✓") : theme.fg("error", "✗");
|
|
859
|
+
const displayItems = getDisplayItems(r.messages);
|
|
860
|
+
text += `\n\n${theme.fg("muted", `─── Step ${r.step}: `)}${theme.fg("accent", r.agent)} ${rIcon}`;
|
|
861
|
+
if (displayItems.length === 0) text += `\n${theme.fg("muted", "(no output)")}`;
|
|
862
|
+
else text += `\n${renderDisplayItems(displayItems, 5)}`;
|
|
863
|
+
}
|
|
864
|
+
const usageStr = formatUsageStats(aggregateUsage(details.results));
|
|
865
|
+
if (usageStr) text += `\n\n${theme.fg("dim", `Total: ${usageStr}`)}`;
|
|
866
|
+
text += `\n${theme.fg("muted", "(Ctrl+O to expand)")}`;
|
|
867
|
+
return new Text(text, 0, 0);
|
|
868
|
+
}
|
|
869
|
+
|
|
870
|
+
if (details.mode === "parallel") {
|
|
871
|
+
const running = details.results.filter((r) => r.exitCode === -1).length;
|
|
872
|
+
const successCount = details.results.filter((r) => r.exitCode === 0).length;
|
|
873
|
+
const failCount = details.results.filter((r) => r.exitCode > 0).length;
|
|
874
|
+
const isRunning = running > 0;
|
|
875
|
+
const icon = isRunning
|
|
876
|
+
? theme.fg("warning", "⏳")
|
|
877
|
+
: failCount > 0
|
|
878
|
+
? theme.fg("warning", "◐")
|
|
879
|
+
: theme.fg("success", "✓");
|
|
880
|
+
const status = isRunning
|
|
881
|
+
? `${successCount + failCount}/${details.results.length} done, ${running} running`
|
|
882
|
+
: `${successCount}/${details.results.length} tasks`;
|
|
883
|
+
|
|
884
|
+
if (expanded && !isRunning) {
|
|
885
|
+
const container = new Container();
|
|
886
|
+
container.addChild(
|
|
887
|
+
new Text(
|
|
888
|
+
`${icon} ${theme.fg("toolTitle", theme.bold("parallel "))}${theme.fg("accent", status)}`,
|
|
889
|
+
0,
|
|
890
|
+
0,
|
|
891
|
+
),
|
|
892
|
+
);
|
|
893
|
+
|
|
894
|
+
for (const r of details.results) {
|
|
895
|
+
const rIcon = r.exitCode === 0 ? theme.fg("success", "✓") : theme.fg("error", "✗");
|
|
896
|
+
const displayItems = getDisplayItems(r.messages);
|
|
897
|
+
const finalOutput = getFinalOutput(r.messages);
|
|
898
|
+
|
|
899
|
+
container.addChild(new Spacer(1));
|
|
900
|
+
container.addChild(
|
|
901
|
+
new Text(`${theme.fg("muted", "─── ") + theme.fg("accent", r.agent)} ${rIcon}`, 0, 0),
|
|
902
|
+
);
|
|
903
|
+
container.addChild(new Text(theme.fg("muted", "Task: ") + theme.fg("dim", r.task), 0, 0));
|
|
904
|
+
|
|
905
|
+
// Show tool calls
|
|
906
|
+
for (const item of displayItems) {
|
|
907
|
+
if (item.type === "toolCall") {
|
|
908
|
+
container.addChild(
|
|
909
|
+
new Text(
|
|
910
|
+
theme.fg("muted", "→ ") + formatToolCall(item.name, item.args, theme.fg.bind(theme)),
|
|
911
|
+
0,
|
|
912
|
+
0,
|
|
913
|
+
),
|
|
914
|
+
);
|
|
915
|
+
}
|
|
916
|
+
}
|
|
917
|
+
|
|
918
|
+
// Show final output as markdown
|
|
919
|
+
if (finalOutput) {
|
|
920
|
+
container.addChild(new Spacer(1));
|
|
921
|
+
container.addChild(new Markdown(finalOutput.trim(), 0, 0, mdTheme));
|
|
922
|
+
}
|
|
923
|
+
|
|
924
|
+
const taskUsage = formatUsageStats(r.usage, r.model);
|
|
925
|
+
if (taskUsage) container.addChild(new Text(theme.fg("dim", taskUsage), 0, 0));
|
|
926
|
+
}
|
|
927
|
+
|
|
928
|
+
const usageStr = formatUsageStats(aggregateUsage(details.results));
|
|
929
|
+
if (usageStr) {
|
|
930
|
+
container.addChild(new Spacer(1));
|
|
931
|
+
container.addChild(new Text(theme.fg("dim", `Total: ${usageStr}`), 0, 0));
|
|
932
|
+
}
|
|
933
|
+
return container;
|
|
934
|
+
}
|
|
935
|
+
|
|
936
|
+
// Collapsed view (or still running)
|
|
937
|
+
let text = `${icon} ${theme.fg("toolTitle", theme.bold("parallel "))}${theme.fg("accent", status)}`;
|
|
938
|
+
for (const r of details.results) {
|
|
939
|
+
const rIcon =
|
|
940
|
+
r.exitCode === -1
|
|
941
|
+
? theme.fg("warning", "⏳")
|
|
942
|
+
: r.exitCode === 0
|
|
943
|
+
? theme.fg("success", "✓")
|
|
944
|
+
: theme.fg("error", "✗");
|
|
945
|
+
const displayItems = getDisplayItems(r.messages);
|
|
946
|
+
text += `\n\n${theme.fg("muted", "─── ")}${theme.fg("accent", r.agent)} ${rIcon}`;
|
|
947
|
+
if (displayItems.length === 0)
|
|
948
|
+
text += `\n${theme.fg("muted", r.exitCode === -1 ? "(running...)" : "(no output)")}`;
|
|
949
|
+
else text += `\n${renderDisplayItems(displayItems, 5)}`;
|
|
950
|
+
}
|
|
951
|
+
if (!isRunning) {
|
|
952
|
+
const usageStr = formatUsageStats(aggregateUsage(details.results));
|
|
953
|
+
if (usageStr) text += `\n\n${theme.fg("dim", `Total: ${usageStr}`)}`;
|
|
954
|
+
}
|
|
955
|
+
if (!expanded) text += `\n${theme.fg("muted", "(Ctrl+O to expand)")}`;
|
|
956
|
+
return new Text(text, 0, 0);
|
|
957
|
+
}
|
|
958
|
+
|
|
959
|
+
const text = result.content[0];
|
|
960
|
+
return new Text(text?.type === "text" ? text.text : "(no output)", 0, 0);
|
|
961
|
+
},
|
|
962
|
+
});
|
|
963
|
+
}
|