@bastani/atomic 0.8.10 → 0.8.12-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 +29 -2
- package/dist/builtin/intercom/package.json +1 -1
- package/dist/builtin/mcp/package.json +1 -1
- package/dist/builtin/subagents/CHANGELOG.md +3 -0
- package/dist/builtin/subagents/package.json +1 -1
- package/dist/builtin/subagents/src/agents/agent-serializer.ts +3 -2
- package/dist/builtin/subagents/src/agents/agents.ts +1 -1
- package/dist/builtin/subagents/src/extension/index.ts +597 -471
- package/dist/builtin/subagents/src/runs/background/async-job-tracker.ts +16 -8
- package/dist/builtin/subagents/src/runs/background/subagent-runner.ts +9 -13
- package/dist/builtin/subagents/src/runs/foreground/execution.ts +7 -3
- package/dist/builtin/subagents/src/shared/formatters.ts +8 -3
- package/dist/builtin/subagents/src/slash/slash-commands.ts +625 -468
- package/dist/builtin/subagents/src/tui/render.ts +342 -158
- package/dist/builtin/web-access/package.json +1 -1
- package/dist/builtin/workflows/package.json +1 -1
- package/dist/builtin/workflows/src/runs/foreground/executor.ts +15 -4
- package/dist/builtin/workflows/src/runs/foreground/stage-control-registry.ts +75 -33
- package/dist/builtin/workflows/src/shared/store-types.ts +3 -4
- package/dist/builtin/workflows/src/shared/store.ts +2 -3
- package/dist/builtin/workflows/src/tui/graph-view.ts +12 -1
- package/dist/builtin/workflows/src/tui/stage-chat-view.ts +1 -2
- package/dist/builtin/workflows/src/tui/status-helpers.ts +1 -1
- package/dist/bun/cli.d.ts.map +1 -1
- package/dist/bun/cli.js.map +1 -1
- package/dist/cli/args.d.ts +1 -1
- package/dist/cli/args.d.ts.map +1 -1
- package/dist/cli/args.js.map +1 -1
- package/dist/cli/config-selector.d.ts +2 -2
- package/dist/cli/config-selector.d.ts.map +1 -1
- package/dist/cli/config-selector.js.map +1 -1
- package/dist/cli/file-processor.d.ts.map +1 -1
- package/dist/cli/file-processor.js.map +1 -1
- package/dist/cli/initial-message.d.ts +1 -1
- package/dist/cli/initial-message.d.ts.map +1 -1
- package/dist/cli/initial-message.js.map +1 -1
- package/dist/cli/list-models.d.ts +1 -1
- package/dist/cli/list-models.d.ts.map +1 -1
- package/dist/cli/list-models.js.map +1 -1
- package/dist/cli/session-picker.d.ts +1 -1
- package/dist/cli/session-picker.d.ts.map +1 -1
- package/dist/cli/session-picker.js.map +1 -1
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +2 -6
- package/dist/cli.js.map +1 -1
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +45 -22
- package/dist/config.js.map +1 -1
- package/dist/core/agent-session-runtime.d.ts +9 -9
- package/dist/core/agent-session-runtime.d.ts.map +1 -1
- package/dist/core/agent-session-runtime.js +2 -3
- package/dist/core/agent-session-runtime.js.map +1 -1
- package/dist/core/agent-session-services.d.ts +7 -7
- package/dist/core/agent-session-services.d.ts.map +1 -1
- package/dist/core/agent-session-services.js.map +1 -1
- package/dist/core/agent-session.d.ts +10 -10
- package/dist/core/agent-session.d.ts.map +1 -1
- package/dist/core/agent-session.js.map +1 -1
- package/dist/core/atomic-guide-command.d.ts.map +1 -1
- package/dist/core/atomic-guide-command.js.map +1 -1
- package/dist/core/auth-guidance.d.ts.map +1 -1
- package/dist/core/auth-guidance.js.map +1 -1
- package/dist/core/auth-storage.d.ts +1 -1
- package/dist/core/auth-storage.d.ts.map +1 -1
- package/dist/core/auth-storage.js +1 -1
- package/dist/core/auth-storage.js.map +1 -1
- package/dist/core/bash-executor.d.ts +1 -1
- package/dist/core/bash-executor.d.ts.map +1 -1
- package/dist/core/bash-executor.js.map +1 -1
- package/dist/core/builtin-packages.d.ts.map +1 -1
- package/dist/core/builtin-packages.js.map +1 -1
- package/dist/core/compaction/branch-summarization.d.ts +3 -3
- package/dist/core/compaction/branch-summarization.d.ts.map +1 -1
- package/dist/core/compaction/branch-summarization.js.map +1 -1
- package/dist/core/compaction/compaction.d.ts +2 -2
- package/dist/core/compaction/compaction.d.ts.map +1 -1
- package/dist/core/compaction/compaction.js.map +1 -1
- package/dist/core/compaction/index.d.ts +3 -3
- package/dist/core/compaction/index.d.ts.map +1 -1
- package/dist/core/compaction/index.js.map +1 -1
- package/dist/core/exec.d.ts.map +1 -1
- package/dist/core/exec.js.map +1 -1
- package/dist/core/export-html/index.d.ts +1 -1
- package/dist/core/export-html/index.d.ts.map +1 -1
- package/dist/core/export-html/index.js.map +1 -1
- package/dist/core/export-html/tool-renderer.d.ts +2 -2
- package/dist/core/export-html/tool-renderer.d.ts.map +1 -1
- package/dist/core/export-html/tool-renderer.js.map +1 -1
- package/dist/core/extensions/index.d.ts +8 -8
- package/dist/core/extensions/index.d.ts.map +1 -1
- package/dist/core/extensions/index.js.map +1 -1
- package/dist/core/extensions/loader.d.ts +3 -3
- package/dist/core/extensions/loader.d.ts.map +1 -1
- package/dist/core/extensions/loader.js.map +1 -1
- package/dist/core/extensions/runner.d.ts +6 -6
- package/dist/core/extensions/runner.d.ts.map +1 -1
- package/dist/core/extensions/runner.js.map +1 -1
- package/dist/core/extensions/types.d.ts +20 -20
- package/dist/core/extensions/types.d.ts.map +1 -1
- package/dist/core/extensions/types.js.map +1 -1
- package/dist/core/extensions/wrapper.d.ts +2 -2
- package/dist/core/extensions/wrapper.d.ts.map +1 -1
- package/dist/core/extensions/wrapper.js.map +1 -1
- package/dist/core/footer-data-provider.d.ts.map +1 -1
- package/dist/core/footer-data-provider.js.map +1 -1
- package/dist/core/http-dispatcher.d.ts +32 -0
- package/dist/core/http-dispatcher.d.ts.map +1 -0
- package/dist/core/http-dispatcher.js +43 -0
- package/dist/core/http-dispatcher.js.map +1 -0
- package/dist/core/index.d.ts +8 -8
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/index.js.map +1 -1
- package/dist/core/keybindings.d.ts.map +1 -1
- package/dist/core/keybindings.js.map +1 -1
- package/dist/core/model-registry.d.ts +4 -4
- package/dist/core/model-registry.d.ts.map +1 -1
- package/dist/core/model-registry.js +2 -2
- package/dist/core/model-registry.js.map +1 -1
- package/dist/core/model-resolver.d.ts +1 -1
- package/dist/core/model-resolver.d.ts.map +1 -1
- package/dist/core/model-resolver.js.map +1 -1
- package/dist/core/package-manager.d.ts +1 -1
- package/dist/core/package-manager.d.ts.map +1 -1
- package/dist/core/package-manager.js +10 -11
- package/dist/core/package-manager.js.map +1 -1
- package/dist/core/prompt-templates.d.ts +1 -1
- package/dist/core/prompt-templates.d.ts.map +1 -1
- package/dist/core/prompt-templates.js.map +1 -1
- package/dist/core/resolve-config-value.d.ts.map +1 -1
- package/dist/core/resolve-config-value.js.map +1 -1
- package/dist/core/resource-loader.d.ts +9 -9
- package/dist/core/resource-loader.d.ts.map +1 -1
- package/dist/core/resource-loader.js.map +1 -1
- package/dist/core/sdk.d.ts +13 -13
- package/dist/core/sdk.d.ts.map +1 -1
- package/dist/core/sdk.js.map +1 -1
- package/dist/core/session-manager.d.ts +1 -1
- package/dist/core/session-manager.d.ts.map +1 -1
- package/dist/core/session-manager.js.map +1 -1
- package/dist/core/settings-manager.d.ts +3 -0
- package/dist/core/settings-manager.d.ts.map +1 -1
- package/dist/core/settings-manager.js +21 -0
- package/dist/core/settings-manager.js.map +1 -1
- package/dist/core/skills.d.ts +2 -2
- package/dist/core/skills.d.ts.map +1 -1
- package/dist/core/skills.js.map +1 -1
- package/dist/core/slash-commands.d.ts +1 -1
- package/dist/core/slash-commands.d.ts.map +1 -1
- package/dist/core/slash-commands.js.map +1 -1
- package/dist/core/source-info.d.ts +1 -1
- package/dist/core/source-info.d.ts.map +1 -1
- package/dist/core/source-info.js.map +1 -1
- package/dist/core/system-prompt.d.ts +1 -1
- package/dist/core/system-prompt.d.ts.map +1 -1
- package/dist/core/system-prompt.js +7 -8
- package/dist/core/system-prompt.js.map +1 -1
- package/dist/core/telemetry.d.ts +1 -1
- package/dist/core/telemetry.d.ts.map +1 -1
- package/dist/core/telemetry.js.map +1 -1
- package/dist/core/timings.d.ts.map +1 -1
- package/dist/core/timings.js.map +1 -1
- package/dist/core/tools/ask-user-question/ask-user-question.d.ts +4 -4
- package/dist/core/tools/ask-user-question/ask-user-question.d.ts.map +1 -1
- package/dist/core/tools/ask-user-question/ask-user-question.js.map +1 -1
- package/dist/core/tools/ask-user-question/index.d.ts +1 -1
- package/dist/core/tools/ask-user-question/index.d.ts.map +1 -1
- package/dist/core/tools/ask-user-question/index.js.map +1 -1
- package/dist/core/tools/ask-user-question/state/build-questionnaire.d.ts +5 -5
- package/dist/core/tools/ask-user-question/state/build-questionnaire.d.ts.map +1 -1
- package/dist/core/tools/ask-user-question/state/build-questionnaire.js.map +1 -1
- package/dist/core/tools/ask-user-question/state/key-router.d.ts +2 -2
- package/dist/core/tools/ask-user-question/state/key-router.d.ts.map +1 -1
- package/dist/core/tools/ask-user-question/state/key-router.js.map +1 -1
- package/dist/core/tools/ask-user-question/state/questionnaire-session.d.ts +3 -3
- package/dist/core/tools/ask-user-question/state/questionnaire-session.d.ts.map +1 -1
- package/dist/core/tools/ask-user-question/state/questionnaire-session.js.map +1 -1
- package/dist/core/tools/ask-user-question/state/row-intent.d.ts +2 -2
- package/dist/core/tools/ask-user-question/state/row-intent.d.ts.map +1 -1
- package/dist/core/tools/ask-user-question/state/row-intent.js.map +1 -1
- package/dist/core/tools/ask-user-question/state/selectors/contract.d.ts +6 -6
- package/dist/core/tools/ask-user-question/state/selectors/contract.d.ts.map +1 -1
- package/dist/core/tools/ask-user-question/state/selectors/contract.js.map +1 -1
- package/dist/core/tools/ask-user-question/state/selectors/derivations.d.ts +2 -2
- package/dist/core/tools/ask-user-question/state/selectors/derivations.d.ts.map +1 -1
- package/dist/core/tools/ask-user-question/state/selectors/derivations.js.map +1 -1
- package/dist/core/tools/ask-user-question/state/selectors/focus.d.ts +1 -1
- package/dist/core/tools/ask-user-question/state/selectors/focus.d.ts.map +1 -1
- package/dist/core/tools/ask-user-question/state/selectors/focus.js.map +1 -1
- package/dist/core/tools/ask-user-question/state/selectors/projections.d.ts +8 -8
- package/dist/core/tools/ask-user-question/state/selectors/projections.d.ts.map +1 -1
- package/dist/core/tools/ask-user-question/state/selectors/projections.js.map +1 -1
- package/dist/core/tools/ask-user-question/state/state-reducer.d.ts +4 -4
- package/dist/core/tools/ask-user-question/state/state-reducer.d.ts.map +1 -1
- package/dist/core/tools/ask-user-question/state/state-reducer.js.map +1 -1
- package/dist/core/tools/ask-user-question/state/state.d.ts +2 -2
- package/dist/core/tools/ask-user-question/state/state.d.ts.map +1 -1
- package/dist/core/tools/ask-user-question/state/state.js.map +1 -1
- package/dist/core/tools/ask-user-question/tool/format-answer.d.ts +1 -1
- package/dist/core/tools/ask-user-question/tool/format-answer.d.ts.map +1 -1
- package/dist/core/tools/ask-user-question/tool/format-answer.js.map +1 -1
- package/dist/core/tools/ask-user-question/tool/response-envelope.d.ts +1 -1
- package/dist/core/tools/ask-user-question/tool/response-envelope.d.ts.map +1 -1
- package/dist/core/tools/ask-user-question/tool/response-envelope.js.map +1 -1
- package/dist/core/tools/ask-user-question/tool/types.d.ts.map +1 -1
- package/dist/core/tools/ask-user-question/tool/types.js.map +1 -1
- package/dist/core/tools/ask-user-question/tool/validate-questionnaire.d.ts +1 -1
- package/dist/core/tools/ask-user-question/tool/validate-questionnaire.d.ts.map +1 -1
- package/dist/core/tools/ask-user-question/tool/validate-questionnaire.js.map +1 -1
- package/dist/core/tools/ask-user-question/view/body-residual-spacer.d.ts.map +1 -1
- package/dist/core/tools/ask-user-question/view/body-residual-spacer.js.map +1 -1
- package/dist/core/tools/ask-user-question/view/component-binding.d.ts +4 -4
- package/dist/core/tools/ask-user-question/view/component-binding.d.ts.map +1 -1
- package/dist/core/tools/ask-user-question/view/component-binding.js.map +1 -1
- package/dist/core/tools/ask-user-question/view/components/chat-row-view.d.ts +2 -2
- package/dist/core/tools/ask-user-question/view/components/chat-row-view.d.ts.map +1 -1
- package/dist/core/tools/ask-user-question/view/components/chat-row-view.js.map +1 -1
- package/dist/core/tools/ask-user-question/view/components/multi-select-view.d.ts +4 -4
- package/dist/core/tools/ask-user-question/view/components/multi-select-view.d.ts.map +1 -1
- package/dist/core/tools/ask-user-question/view/components/multi-select-view.js.map +1 -1
- package/dist/core/tools/ask-user-question/view/components/option-list-view.d.ts +2 -2
- package/dist/core/tools/ask-user-question/view/components/option-list-view.d.ts.map +1 -1
- package/dist/core/tools/ask-user-question/view/components/option-list-view.js.map +1 -1
- package/dist/core/tools/ask-user-question/view/components/preview/markdown-content-cache.d.ts +2 -2
- package/dist/core/tools/ask-user-question/view/components/preview/markdown-content-cache.d.ts.map +1 -1
- package/dist/core/tools/ask-user-question/view/components/preview/markdown-content-cache.js.map +1 -1
- package/dist/core/tools/ask-user-question/view/components/preview/preview-block-renderer.d.ts +3 -3
- package/dist/core/tools/ask-user-question/view/components/preview/preview-block-renderer.d.ts.map +1 -1
- package/dist/core/tools/ask-user-question/view/components/preview/preview-block-renderer.js.map +1 -1
- package/dist/core/tools/ask-user-question/view/components/preview/preview-layout-decider.d.ts +2 -2
- package/dist/core/tools/ask-user-question/view/components/preview/preview-layout-decider.d.ts.map +1 -1
- package/dist/core/tools/ask-user-question/view/components/preview/preview-layout-decider.js.map +1 -1
- package/dist/core/tools/ask-user-question/view/components/preview/preview-pane.d.ts +8 -8
- package/dist/core/tools/ask-user-question/view/components/preview/preview-pane.d.ts.map +1 -1
- package/dist/core/tools/ask-user-question/view/components/preview/preview-pane.js.map +1 -1
- package/dist/core/tools/ask-user-question/view/components/submit-picker.d.ts +3 -3
- package/dist/core/tools/ask-user-question/view/components/submit-picker.d.ts.map +1 -1
- package/dist/core/tools/ask-user-question/view/components/submit-picker.js.map +1 -1
- package/dist/core/tools/ask-user-question/view/components/tab-bar.d.ts +3 -3
- package/dist/core/tools/ask-user-question/view/components/tab-bar.d.ts.map +1 -1
- package/dist/core/tools/ask-user-question/view/components/tab-bar.js.map +1 -1
- package/dist/core/tools/ask-user-question/view/dialog-builder.d.ts +8 -8
- package/dist/core/tools/ask-user-question/view/dialog-builder.d.ts.map +1 -1
- package/dist/core/tools/ask-user-question/view/dialog-builder.js.map +1 -1
- package/dist/core/tools/ask-user-question/view/props-adapter.d.ts +5 -5
- package/dist/core/tools/ask-user-question/view/props-adapter.d.ts.map +1 -1
- package/dist/core/tools/ask-user-question/view/props-adapter.js.map +1 -1
- package/dist/core/tools/ask-user-question/view/tab-components.d.ts +4 -4
- package/dist/core/tools/ask-user-question/view/tab-components.d.ts.map +1 -1
- package/dist/core/tools/ask-user-question/view/tab-components.js.map +1 -1
- package/dist/core/tools/ask-user-question/view/tab-content-strategy.d.ts +9 -9
- package/dist/core/tools/ask-user-question/view/tab-content-strategy.d.ts.map +1 -1
- package/dist/core/tools/ask-user-question/view/tab-content-strategy.js +2 -2
- package/dist/core/tools/ask-user-question/view/tab-content-strategy.js.map +1 -1
- package/dist/core/tools/bash.d.ts +2 -2
- package/dist/core/tools/bash.d.ts.map +1 -1
- package/dist/core/tools/bash.js +9 -1
- package/dist/core/tools/bash.js.map +1 -1
- package/dist/core/tools/edit-diff.d.ts.map +1 -1
- package/dist/core/tools/edit-diff.js.map +1 -1
- package/dist/core/tools/edit.d.ts +2 -2
- package/dist/core/tools/edit.d.ts.map +1 -1
- package/dist/core/tools/edit.js.map +1 -1
- package/dist/core/tools/find.d.ts +2 -2
- package/dist/core/tools/find.d.ts.map +1 -1
- package/dist/core/tools/find.js.map +1 -1
- package/dist/core/tools/grep.d.ts +2 -2
- package/dist/core/tools/grep.d.ts.map +1 -1
- package/dist/core/tools/grep.js.map +1 -1
- package/dist/core/tools/index.d.ts +19 -19
- package/dist/core/tools/index.d.ts.map +1 -1
- package/dist/core/tools/index.js.map +1 -1
- package/dist/core/tools/ls.d.ts +2 -2
- package/dist/core/tools/ls.d.ts.map +1 -1
- package/dist/core/tools/ls.js.map +1 -1
- package/dist/core/tools/output-accumulator.d.ts +1 -1
- package/dist/core/tools/output-accumulator.d.ts.map +1 -1
- package/dist/core/tools/output-accumulator.js.map +1 -1
- package/dist/core/tools/read.d.ts +2 -2
- package/dist/core/tools/read.d.ts.map +1 -1
- package/dist/core/tools/read.js.map +1 -1
- package/dist/core/tools/render-utils.d.ts +1 -1
- package/dist/core/tools/render-utils.d.ts.map +1 -1
- package/dist/core/tools/render-utils.js.map +1 -1
- package/dist/core/tools/todos.d.ts +1 -1
- package/dist/core/tools/todos.d.ts.map +1 -1
- package/dist/core/tools/todos.js.map +1 -1
- package/dist/core/tools/tool-definition-wrapper.d.ts +1 -1
- package/dist/core/tools/tool-definition-wrapper.d.ts.map +1 -1
- package/dist/core/tools/tool-definition-wrapper.js.map +1 -1
- package/dist/core/tools/write.d.ts +1 -1
- package/dist/core/tools/write.d.ts.map +1 -1
- package/dist/core/tools/write.js.map +1 -1
- package/dist/index.d.ts +30 -29
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/main.d.ts +1 -1
- package/dist/main.d.ts.map +1 -1
- package/dist/main.js +2 -0
- package/dist/main.js.map +1 -1
- package/dist/migrations.d.ts.map +1 -1
- package/dist/migrations.js.map +1 -1
- package/dist/modes/index.d.ts +5 -5
- package/dist/modes/index.d.ts.map +1 -1
- package/dist/modes/index.js.map +1 -1
- package/dist/modes/interactive/components/armin.d.ts.map +1 -1
- package/dist/modes/interactive/components/armin.js.map +1 -1
- package/dist/modes/interactive/components/assistant-message.d.ts.map +1 -1
- package/dist/modes/interactive/components/assistant-message.js.map +1 -1
- package/dist/modes/interactive/components/atomic-banner.d.ts +1 -1
- package/dist/modes/interactive/components/atomic-banner.d.ts.map +1 -1
- package/dist/modes/interactive/components/atomic-banner.js.map +1 -1
- package/dist/modes/interactive/components/bash-execution.d.ts +1 -1
- package/dist/modes/interactive/components/bash-execution.d.ts.map +1 -1
- package/dist/modes/interactive/components/bash-execution.js.map +1 -1
- package/dist/modes/interactive/components/bordered-loader.d.ts +1 -1
- package/dist/modes/interactive/components/bordered-loader.d.ts.map +1 -1
- package/dist/modes/interactive/components/bordered-loader.js.map +1 -1
- package/dist/modes/interactive/components/branch-summary-message.d.ts +1 -1
- package/dist/modes/interactive/components/branch-summary-message.d.ts.map +1 -1
- package/dist/modes/interactive/components/branch-summary-message.js.map +1 -1
- package/dist/modes/interactive/components/chat-message-renderer.d.ts +3 -3
- package/dist/modes/interactive/components/chat-message-renderer.d.ts.map +1 -1
- package/dist/modes/interactive/components/chat-message-renderer.js +1 -1
- package/dist/modes/interactive/components/chat-message-renderer.js.map +1 -1
- package/dist/modes/interactive/components/chat-transcript.d.ts.map +1 -1
- package/dist/modes/interactive/components/chat-transcript.js.map +1 -1
- package/dist/modes/interactive/components/compaction-summary-message.d.ts +1 -1
- package/dist/modes/interactive/components/compaction-summary-message.d.ts.map +1 -1
- package/dist/modes/interactive/components/compaction-summary-message.js.map +1 -1
- package/dist/modes/interactive/components/config-selector.d.ts +2 -2
- package/dist/modes/interactive/components/config-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/config-selector.js.map +1 -1
- package/dist/modes/interactive/components/countdown-timer.d.ts +2 -2
- package/dist/modes/interactive/components/countdown-timer.d.ts.map +1 -1
- package/dist/modes/interactive/components/countdown-timer.js.map +1 -1
- package/dist/modes/interactive/components/custom-editor.d.ts +1 -1
- package/dist/modes/interactive/components/custom-editor.d.ts.map +1 -1
- package/dist/modes/interactive/components/custom-editor.js.map +1 -1
- package/dist/modes/interactive/components/custom-message.d.ts +2 -2
- package/dist/modes/interactive/components/custom-message.d.ts.map +1 -1
- package/dist/modes/interactive/components/custom-message.js.map +1 -1
- package/dist/modes/interactive/components/daxnuts.d.ts.map +1 -1
- package/dist/modes/interactive/components/daxnuts.js.map +1 -1
- package/dist/modes/interactive/components/diff.d.ts.map +1 -1
- package/dist/modes/interactive/components/diff.js.map +1 -1
- package/dist/modes/interactive/components/dynamic-border.d.ts.map +1 -1
- package/dist/modes/interactive/components/dynamic-border.js.map +1 -1
- package/dist/modes/interactive/components/earendil-announcement.d.ts.map +1 -1
- package/dist/modes/interactive/components/earendil-announcement.js.map +1 -1
- package/dist/modes/interactive/components/extension-editor.d.ts +1 -1
- package/dist/modes/interactive/components/extension-editor.d.ts.map +1 -1
- package/dist/modes/interactive/components/extension-editor.js.map +1 -1
- package/dist/modes/interactive/components/extension-input.d.ts.map +1 -1
- package/dist/modes/interactive/components/extension-input.js.map +1 -1
- package/dist/modes/interactive/components/extension-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/extension-selector.js.map +1 -1
- package/dist/modes/interactive/components/footer.d.ts +3 -3
- package/dist/modes/interactive/components/footer.d.ts.map +1 -1
- package/dist/modes/interactive/components/footer.js +1 -1
- package/dist/modes/interactive/components/footer.js.map +1 -1
- package/dist/modes/interactive/components/index.d.ts +34 -34
- package/dist/modes/interactive/components/index.d.ts.map +1 -1
- package/dist/modes/interactive/components/index.js.map +1 -1
- package/dist/modes/interactive/components/keybinding-hints.d.ts.map +1 -1
- package/dist/modes/interactive/components/keybinding-hints.js.map +1 -1
- package/dist/modes/interactive/components/login-dialog.d.ts +1 -1
- package/dist/modes/interactive/components/login-dialog.d.ts.map +1 -1
- package/dist/modes/interactive/components/login-dialog.js +1 -1
- package/dist/modes/interactive/components/login-dialog.js.map +1 -1
- package/dist/modes/interactive/components/model-selector.d.ts +2 -2
- package/dist/modes/interactive/components/model-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/model-selector.js.map +1 -1
- package/dist/modes/interactive/components/oauth-selector.d.ts +1 -1
- package/dist/modes/interactive/components/oauth-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/oauth-selector.js.map +1 -1
- package/dist/modes/interactive/components/scoped-models-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/scoped-models-selector.js.map +1 -1
- package/dist/modes/interactive/components/session-selector-search.d.ts +1 -1
- package/dist/modes/interactive/components/session-selector-search.d.ts.map +1 -1
- package/dist/modes/interactive/components/session-selector-search.js.map +1 -1
- package/dist/modes/interactive/components/session-selector.d.ts +3 -3
- package/dist/modes/interactive/components/session-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/session-selector.js.map +1 -1
- package/dist/modes/interactive/components/settings-selector.d.ts +3 -1
- package/dist/modes/interactive/components/settings-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/settings-selector.js +13 -0
- package/dist/modes/interactive/components/settings-selector.js.map +1 -1
- package/dist/modes/interactive/components/show-images-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/show-images-selector.js.map +1 -1
- package/dist/modes/interactive/components/skill-invocation-message.d.ts +1 -1
- package/dist/modes/interactive/components/skill-invocation-message.d.ts.map +1 -1
- package/dist/modes/interactive/components/skill-invocation-message.js.map +1 -1
- package/dist/modes/interactive/components/theme-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/theme-selector.js.map +1 -1
- package/dist/modes/interactive/components/thinking-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/thinking-selector.js.map +1 -1
- package/dist/modes/interactive/components/tool-execution.d.ts +1 -1
- package/dist/modes/interactive/components/tool-execution.d.ts.map +1 -1
- package/dist/modes/interactive/components/tool-execution.js.map +1 -1
- package/dist/modes/interactive/components/tree-selector.d.ts +1 -1
- package/dist/modes/interactive/components/tree-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/tree-selector.js.map +1 -1
- package/dist/modes/interactive/components/user-message-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/user-message-selector.js.map +1 -1
- package/dist/modes/interactive/components/user-message.d.ts.map +1 -1
- package/dist/modes/interactive/components/user-message.js.map +1 -1
- package/dist/modes/interactive/components/working-status.d.ts.map +1 -1
- package/dist/modes/interactive/components/working-status.js.map +1 -1
- package/dist/modes/interactive/interactive-mode.d.ts +2 -2
- package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode.js +7 -1
- package/dist/modes/interactive/interactive-mode.js.map +1 -1
- package/dist/modes/interactive/theme/theme.d.ts +1 -1
- package/dist/modes/interactive/theme/theme.d.ts.map +1 -1
- package/dist/modes/interactive/theme/theme.js.map +1 -1
- package/dist/modes/print-mode.d.ts +1 -1
- package/dist/modes/print-mode.d.ts.map +1 -1
- package/dist/modes/print-mode.js.map +1 -1
- package/dist/modes/rpc/rpc-client.d.ts +5 -5
- package/dist/modes/rpc/rpc-client.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-client.js +1 -1
- package/dist/modes/rpc/rpc-client.js.map +1 -1
- package/dist/modes/rpc/rpc-mode.d.ts +2 -2
- package/dist/modes/rpc/rpc-mode.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-mode.js.map +1 -1
- package/dist/modes/rpc/rpc-types.d.ts +4 -4
- package/dist/modes/rpc/rpc-types.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-types.js.map +1 -1
- package/dist/package-manager-cli.d.ts.map +1 -1
- package/dist/package-manager-cli.js +22 -6
- package/dist/package-manager-cli.js.map +1 -1
- package/dist/utils/changelog.d.ts +1 -1
- package/dist/utils/changelog.d.ts.map +1 -1
- package/dist/utils/changelog.js.map +1 -1
- package/dist/utils/child-process.d.ts +5 -2
- package/dist/utils/child-process.d.ts.map +1 -1
- package/dist/utils/child-process.js +9 -7
- package/dist/utils/child-process.js.map +1 -1
- package/dist/utils/clipboard-image.d.ts.map +1 -1
- package/dist/utils/clipboard-image.js.map +1 -1
- package/dist/utils/clipboard.d.ts.map +1 -1
- package/dist/utils/clipboard.js.map +1 -1
- package/dist/utils/exif-orientation.d.ts +1 -1
- package/dist/utils/exif-orientation.d.ts.map +1 -1
- package/dist/utils/exif-orientation.js.map +1 -1
- package/dist/utils/image-convert.d.ts.map +1 -1
- package/dist/utils/image-convert.js.map +1 -1
- package/dist/utils/image-resize.d.ts.map +1 -1
- package/dist/utils/image-resize.js.map +1 -1
- package/dist/utils/shell.d.ts.map +1 -1
- package/dist/utils/shell.js.map +1 -1
- package/dist/utils/syntax-highlight.d.ts.map +1 -1
- package/dist/utils/syntax-highlight.js.map +1 -1
- package/dist/utils/tools-manager.d.ts.map +1 -1
- package/dist/utils/tools-manager.js.map +1 -1
- package/dist/utils/version-check.d.ts.map +1 -1
- package/dist/utils/version-check.js.map +1 -1
- package/dist/utils/windows-self-update.d.ts +3 -0
- package/dist/utils/windows-self-update.d.ts.map +1 -0
- package/dist/utils/windows-self-update.js +78 -0
- package/dist/utils/windows-self-update.js.map +1 -0
- package/docs/compaction.md +5 -5
- package/docs/custom-provider.md +2 -2
- package/docs/development.md +22 -16
- package/docs/docs.json +6 -2
- package/docs/extensions.md +25 -25
- package/docs/index.md +11 -14
- package/docs/keybindings.md +5 -5
- package/docs/models.md +6 -6
- package/docs/packages.md +55 -48
- package/docs/prompt-templates.md +5 -5
- package/docs/providers.md +10 -10
- package/docs/quickstart.md +32 -30
- package/docs/rpc.md +9 -9
- package/docs/sdk.md +1 -1
- package/docs/session-format.md +3 -3
- package/docs/sessions.md +11 -11
- package/docs/settings.md +18 -15
- package/docs/shell-aliases.md +2 -2
- package/docs/skills.md +11 -11
- package/docs/terminal-setup.md +8 -8
- package/docs/termux.md +6 -6
- package/docs/themes.md +10 -10
- package/docs/tui.md +5 -4
- package/docs/usage.md +50 -50
- package/docs/windows.md +2 -2
- package/docs/workflows.md +695 -0
- package/examples/extensions/custom-provider-gitlab-duo/test.ts +1 -1
- package/examples/extensions/doom-overlay/doom-component.ts +2 -2
- package/examples/extensions/doom-overlay/index.ts +3 -3
- package/examples/extensions/overlay-qa-tests.ts +116 -33
- package/examples/extensions/overlay-test.ts +9 -3
- package/examples/extensions/plan-mode/index.ts +1 -1
- package/examples/extensions/subagent/index.ts +1159 -903
- package/package.json +6 -4
- package/dist/builtin/workflows/skills/workflow/SKILL.md +0 -322
- package/dist/builtin/workflows/skills/workflow/references/context-engineering/advanced-evaluation.md +0 -404
- package/dist/builtin/workflows/skills/workflow/references/context-engineering/bdi-mental-states.md +0 -313
- package/dist/builtin/workflows/skills/workflow/references/context-engineering/context-compression.md +0 -274
- package/dist/builtin/workflows/skills/workflow/references/context-engineering/context-degradation.md +0 -208
- package/dist/builtin/workflows/skills/workflow/references/context-engineering/context-fundamentals.md +0 -203
- package/dist/builtin/workflows/skills/workflow/references/context-engineering/context-optimization.md +0 -197
- package/dist/builtin/workflows/skills/workflow/references/context-engineering/evaluation.md +0 -253
- package/dist/builtin/workflows/skills/workflow/references/context-engineering/filesystem-context.md +0 -289
- package/dist/builtin/workflows/skills/workflow/references/context-engineering/hosted-agents.md +0 -262
- package/dist/builtin/workflows/skills/workflow/references/context-engineering/memory-systems.md +0 -221
- package/dist/builtin/workflows/skills/workflow/references/context-engineering/multi-agent-patterns.md +0 -259
- package/dist/builtin/workflows/skills/workflow/references/context-engineering/project-development.md +0 -293
- package/dist/builtin/workflows/skills/workflow/references/context-engineering/tool-design.md +0 -273
- package/dist/builtin/workflows/skills/workflow/references/context-engineering.md +0 -23
- package/dist/builtin/workflows/skills/workflow/references/design-checklist.md +0 -83
- package/dist/builtin/workflows/skills/workflow/references/running-workflows.md +0 -159
- package/dist/builtin/workflows/skills/workflow/references/sdk-authoring.md +0 -260
|
@@ -19,969 +19,1225 @@ import * as path from "node:path";
|
|
|
19
19
|
import type { AgentToolResult } from "@earendil-works/pi-agent-core";
|
|
20
20
|
import type { Message } from "@earendil-works/pi-ai";
|
|
21
21
|
import { StringEnum } from "@earendil-works/pi-ai";
|
|
22
|
-
import {
|
|
22
|
+
import {
|
|
23
|
+
type ExtensionAPI,
|
|
24
|
+
getMarkdownTheme,
|
|
25
|
+
withFileMutationQueue,
|
|
26
|
+
} from "@bastani/atomic";
|
|
23
27
|
import { Container, Markdown, Spacer, Text } from "@earendil-works/pi-tui";
|
|
24
28
|
import { Type } from "typebox";
|
|
25
|
-
import { type AgentConfig, type AgentScope, discoverAgents } from "./agents.
|
|
29
|
+
import { type AgentConfig, type AgentScope, discoverAgents } from "./agents.ts";
|
|
26
30
|
|
|
27
31
|
const MAX_PARALLEL_TASKS = 8;
|
|
28
32
|
const MAX_CONCURRENCY = 4;
|
|
29
33
|
const COLLAPSED_ITEM_COUNT = 10;
|
|
30
34
|
|
|
31
35
|
function formatTokens(count: number): string {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
+
if (count < 1000) return count.toString();
|
|
37
|
+
if (count < 10000) return `${(count / 1000).toFixed(1)}k`;
|
|
38
|
+
if (count < 1000000) return `${Math.round(count / 1000)}k`;
|
|
39
|
+
return `${(count / 1000000).toFixed(1)}M`;
|
|
36
40
|
}
|
|
37
41
|
|
|
38
42
|
function formatUsageStats(
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
43
|
+
usage: {
|
|
44
|
+
input: number;
|
|
45
|
+
output: number;
|
|
46
|
+
cacheRead: number;
|
|
47
|
+
cacheWrite: number;
|
|
48
|
+
cost: number;
|
|
49
|
+
contextTokens?: number;
|
|
50
|
+
turns?: number;
|
|
51
|
+
},
|
|
52
|
+
model?: string,
|
|
49
53
|
): string {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
54
|
+
const parts: string[] = [];
|
|
55
|
+
if (usage.turns)
|
|
56
|
+
parts.push(`${usage.turns} turn${usage.turns > 1 ? "s" : ""}`);
|
|
57
|
+
if (usage.input) parts.push(`↑${formatTokens(usage.input)}`);
|
|
58
|
+
if (usage.output) parts.push(`↓${formatTokens(usage.output)}`);
|
|
59
|
+
if (usage.cacheRead) parts.push(`R${formatTokens(usage.cacheRead)}`);
|
|
60
|
+
if (usage.cacheWrite) parts.push(`W${formatTokens(usage.cacheWrite)}`);
|
|
61
|
+
if (usage.cost) parts.push(`$${usage.cost.toFixed(4)}`);
|
|
62
|
+
if (usage.contextTokens && usage.contextTokens > 0) {
|
|
63
|
+
parts.push(`ctx:${formatTokens(usage.contextTokens)}`);
|
|
64
|
+
}
|
|
65
|
+
if (model) parts.push(model);
|
|
66
|
+
return parts.join(" ");
|
|
62
67
|
}
|
|
63
68
|
|
|
64
69
|
function formatToolCall(
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
70
|
+
toolName: string,
|
|
71
|
+
args: Record<string, unknown>,
|
|
72
|
+
themeFg: (color: any, text: string) => string,
|
|
68
73
|
): string {
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
74
|
+
const shortenPath = (p: string) => {
|
|
75
|
+
const home = os.homedir();
|
|
76
|
+
return p.startsWith(home) ? `~${p.slice(home.length)}` : p;
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
switch (toolName) {
|
|
80
|
+
case "bash": {
|
|
81
|
+
const command = (args.command as string) || "...";
|
|
82
|
+
const preview =
|
|
83
|
+
command.length > 60 ? `${command.slice(0, 60)}...` : command;
|
|
84
|
+
return themeFg("muted", "$ ") + themeFg("toolOutput", preview);
|
|
85
|
+
}
|
|
86
|
+
case "read": {
|
|
87
|
+
const rawPath = (args.file_path || args.path || "...") as string;
|
|
88
|
+
const filePath = shortenPath(rawPath);
|
|
89
|
+
const offset = args.offset as number | undefined;
|
|
90
|
+
const limit = args.limit as number | undefined;
|
|
91
|
+
let text = themeFg("accent", filePath);
|
|
92
|
+
if (offset !== undefined || limit !== undefined) {
|
|
93
|
+
const startLine = offset ?? 1;
|
|
94
|
+
const endLine = limit !== undefined ? startLine + limit - 1 : "";
|
|
95
|
+
text += themeFg(
|
|
96
|
+
"warning",
|
|
97
|
+
`:${startLine}${endLine ? `-${endLine}` : ""}`,
|
|
98
|
+
);
|
|
99
|
+
}
|
|
100
|
+
return themeFg("muted", "read ") + text;
|
|
101
|
+
}
|
|
102
|
+
case "write": {
|
|
103
|
+
const rawPath = (args.file_path || args.path || "...") as string;
|
|
104
|
+
const filePath = shortenPath(rawPath);
|
|
105
|
+
const content = (args.content || "") as string;
|
|
106
|
+
const lines = content.split("\n").length;
|
|
107
|
+
let text = themeFg("muted", "write ") + themeFg("accent", filePath);
|
|
108
|
+
if (lines > 1) text += themeFg("dim", ` (${lines} lines)`);
|
|
109
|
+
return text;
|
|
110
|
+
}
|
|
111
|
+
case "edit": {
|
|
112
|
+
const rawPath = (args.file_path || args.path || "...") as string;
|
|
113
|
+
return (
|
|
114
|
+
themeFg("muted", "edit ") + themeFg("accent", shortenPath(rawPath))
|
|
115
|
+
);
|
|
116
|
+
}
|
|
117
|
+
case "ls": {
|
|
118
|
+
const rawPath = (args.path || ".") as string;
|
|
119
|
+
return themeFg("muted", "ls ") + themeFg("accent", shortenPath(rawPath));
|
|
120
|
+
}
|
|
121
|
+
case "find": {
|
|
122
|
+
const pattern = (args.pattern || "*") as string;
|
|
123
|
+
const rawPath = (args.path || ".") as string;
|
|
124
|
+
return (
|
|
125
|
+
themeFg("muted", "find ") +
|
|
126
|
+
themeFg("accent", pattern) +
|
|
127
|
+
themeFg("dim", ` in ${shortenPath(rawPath)}`)
|
|
128
|
+
);
|
|
129
|
+
}
|
|
130
|
+
case "grep": {
|
|
131
|
+
const pattern = (args.pattern || "") as string;
|
|
132
|
+
const rawPath = (args.path || ".") as string;
|
|
133
|
+
return (
|
|
134
|
+
themeFg("muted", "grep ") +
|
|
135
|
+
themeFg("accent", `/${pattern}/`) +
|
|
136
|
+
themeFg("dim", ` in ${shortenPath(rawPath)}`)
|
|
137
|
+
);
|
|
138
|
+
}
|
|
139
|
+
default: {
|
|
140
|
+
const argsStr = JSON.stringify(args);
|
|
141
|
+
const preview =
|
|
142
|
+
argsStr.length > 50 ? `${argsStr.slice(0, 50)}...` : argsStr;
|
|
143
|
+
return themeFg("accent", toolName) + themeFg("dim", ` ${preview}`);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
130
146
|
}
|
|
131
147
|
|
|
132
148
|
interface UsageStats {
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
149
|
+
input: number;
|
|
150
|
+
output: number;
|
|
151
|
+
cacheRead: number;
|
|
152
|
+
cacheWrite: number;
|
|
153
|
+
cost: number;
|
|
154
|
+
contextTokens: number;
|
|
155
|
+
turns: number;
|
|
140
156
|
}
|
|
141
157
|
|
|
142
158
|
interface SingleResult {
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
159
|
+
agent: string;
|
|
160
|
+
agentSource: "user" | "project" | "unknown";
|
|
161
|
+
task: string;
|
|
162
|
+
exitCode: number;
|
|
163
|
+
messages: Message[];
|
|
164
|
+
stderr: string;
|
|
165
|
+
usage: UsageStats;
|
|
166
|
+
model?: string;
|
|
167
|
+
stopReason?: string;
|
|
168
|
+
errorMessage?: string;
|
|
169
|
+
step?: number;
|
|
154
170
|
}
|
|
155
171
|
|
|
156
172
|
interface SubagentDetails {
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
173
|
+
mode: "single" | "parallel" | "chain";
|
|
174
|
+
agentScope: AgentScope;
|
|
175
|
+
projectAgentsDir: string | null;
|
|
176
|
+
results: SingleResult[];
|
|
161
177
|
}
|
|
162
178
|
|
|
163
179
|
function getFinalOutput(messages: Message[]): string {
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
180
|
+
for (let i = messages.length - 1; i >= 0; i--) {
|
|
181
|
+
const msg = messages[i];
|
|
182
|
+
if (msg.role === "assistant") {
|
|
183
|
+
for (const part of msg.content) {
|
|
184
|
+
if (part.type === "text") return part.text;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
return "";
|
|
173
189
|
}
|
|
174
190
|
|
|
175
|
-
type DisplayItem =
|
|
191
|
+
type DisplayItem =
|
|
192
|
+
| { type: "text"; text: string }
|
|
193
|
+
| { type: "toolCall"; name: string; args: Record<string, any> };
|
|
176
194
|
|
|
177
195
|
function getDisplayItems(messages: Message[]): DisplayItem[] {
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
196
|
+
const items: DisplayItem[] = [];
|
|
197
|
+
for (const msg of messages) {
|
|
198
|
+
if (msg.role === "assistant") {
|
|
199
|
+
for (const part of msg.content) {
|
|
200
|
+
if (part.type === "text") items.push({ type: "text", text: part.text });
|
|
201
|
+
else if (part.type === "toolCall")
|
|
202
|
+
items.push({
|
|
203
|
+
type: "toolCall",
|
|
204
|
+
name: part.name,
|
|
205
|
+
args: part.arguments,
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
return items;
|
|
188
211
|
}
|
|
189
212
|
|
|
190
213
|
async function mapWithConcurrencyLimit<TIn, TOut>(
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
214
|
+
items: TIn[],
|
|
215
|
+
concurrency: number,
|
|
216
|
+
fn: (item: TIn, index: number) => Promise<TOut>,
|
|
194
217
|
): Promise<TOut[]> {
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
218
|
+
if (items.length === 0) return [];
|
|
219
|
+
const limit = Math.max(1, Math.min(concurrency, items.length));
|
|
220
|
+
const results: TOut[] = new Array(items.length);
|
|
221
|
+
let nextIndex = 0;
|
|
222
|
+
const workers = new Array(limit).fill(null).map(async () => {
|
|
223
|
+
while (true) {
|
|
224
|
+
const current = nextIndex++;
|
|
225
|
+
if (current >= items.length) return;
|
|
226
|
+
results[current] = await fn(items[current], current);
|
|
227
|
+
}
|
|
228
|
+
});
|
|
229
|
+
await Promise.all(workers);
|
|
230
|
+
return results;
|
|
208
231
|
}
|
|
209
232
|
|
|
210
|
-
async function writePromptToTempFile(
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
233
|
+
async function writePromptToTempFile(
|
|
234
|
+
agentName: string,
|
|
235
|
+
prompt: string,
|
|
236
|
+
): Promise<{ dir: string; filePath: string }> {
|
|
237
|
+
const tmpDir = await fs.promises.mkdtemp(
|
|
238
|
+
path.join(os.tmpdir(), "pi-subagent-"),
|
|
239
|
+
);
|
|
240
|
+
const safeName = agentName.replace(/[^\w.-]+/g, "_");
|
|
241
|
+
const filePath = path.join(tmpDir, `prompt-${safeName}.md`);
|
|
242
|
+
await withFileMutationQueue(filePath, async () => {
|
|
243
|
+
await fs.promises.writeFile(filePath, prompt, {
|
|
244
|
+
encoding: "utf-8",
|
|
245
|
+
mode: 0o600,
|
|
246
|
+
});
|
|
247
|
+
});
|
|
248
|
+
return { dir: tmpDir, filePath };
|
|
218
249
|
}
|
|
219
250
|
|
|
220
251
|
function getPiInvocation(args: string[]): { command: string; args: string[] } {
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
252
|
+
const currentScript = process.argv[1];
|
|
253
|
+
const isBunVirtualScript = currentScript?.startsWith("/$bunfs/root/");
|
|
254
|
+
if (currentScript && !isBunVirtualScript && fs.existsSync(currentScript)) {
|
|
255
|
+
return { command: process.execPath, args: [currentScript, ...args] };
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
const execName = path.basename(process.execPath).toLowerCase();
|
|
259
|
+
const isGenericRuntime = /^(node|bun)(\.exe)?$/.test(execName);
|
|
260
|
+
if (!isGenericRuntime) {
|
|
261
|
+
return { command: process.execPath, args };
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
return { command: "pi", args };
|
|
234
265
|
}
|
|
235
266
|
|
|
236
267
|
type OnUpdateCallback = (partial: AgentToolResult<SubagentDetails>) => void;
|
|
237
268
|
|
|
238
269
|
async function runSingleAgent(
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
270
|
+
defaultCwd: string,
|
|
271
|
+
agents: AgentConfig[],
|
|
272
|
+
agentName: string,
|
|
273
|
+
task: string,
|
|
274
|
+
cwd: string | undefined,
|
|
275
|
+
step: number | undefined,
|
|
276
|
+
signal: AbortSignal | undefined,
|
|
277
|
+
onUpdate: OnUpdateCallback | undefined,
|
|
278
|
+
makeDetails: (results: SingleResult[]) => SubagentDetails,
|
|
248
279
|
): Promise<SingleResult> {
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
280
|
+
const agent = agents.find((a) => a.name === agentName);
|
|
281
|
+
|
|
282
|
+
if (!agent) {
|
|
283
|
+
const available = agents.map((a) => `"${a.name}"`).join(", ") || "none";
|
|
284
|
+
return {
|
|
285
|
+
agent: agentName,
|
|
286
|
+
agentSource: "unknown",
|
|
287
|
+
task,
|
|
288
|
+
exitCode: 1,
|
|
289
|
+
messages: [],
|
|
290
|
+
stderr: `Unknown agent: "${agentName}". Available agents: ${available}.`,
|
|
291
|
+
usage: {
|
|
292
|
+
input: 0,
|
|
293
|
+
output: 0,
|
|
294
|
+
cacheRead: 0,
|
|
295
|
+
cacheWrite: 0,
|
|
296
|
+
cost: 0,
|
|
297
|
+
contextTokens: 0,
|
|
298
|
+
turns: 0,
|
|
299
|
+
},
|
|
300
|
+
step,
|
|
301
|
+
};
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
const args: string[] = ["--mode", "json", "-p", "--no-session"];
|
|
305
|
+
if (agent.model) args.push("--model", agent.model);
|
|
306
|
+
if (agent.tools && agent.tools.length > 0)
|
|
307
|
+
args.push("--tools", agent.tools.join(","));
|
|
308
|
+
|
|
309
|
+
let tmpPromptDir: string | null = null;
|
|
310
|
+
let tmpPromptPath: string | null = null;
|
|
311
|
+
|
|
312
|
+
const currentResult: SingleResult = {
|
|
313
|
+
agent: agentName,
|
|
314
|
+
agentSource: agent.source,
|
|
315
|
+
task,
|
|
316
|
+
exitCode: 0,
|
|
317
|
+
messages: [],
|
|
318
|
+
stderr: "",
|
|
319
|
+
usage: {
|
|
320
|
+
input: 0,
|
|
321
|
+
output: 0,
|
|
322
|
+
cacheRead: 0,
|
|
323
|
+
cacheWrite: 0,
|
|
324
|
+
cost: 0,
|
|
325
|
+
contextTokens: 0,
|
|
326
|
+
turns: 0,
|
|
327
|
+
},
|
|
328
|
+
model: agent.model,
|
|
329
|
+
step,
|
|
330
|
+
};
|
|
331
|
+
|
|
332
|
+
const emitUpdate = () => {
|
|
333
|
+
if (onUpdate) {
|
|
334
|
+
onUpdate({
|
|
335
|
+
content: [
|
|
336
|
+
{
|
|
337
|
+
type: "text",
|
|
338
|
+
text: getFinalOutput(currentResult.messages) || "(running...)",
|
|
339
|
+
},
|
|
340
|
+
],
|
|
341
|
+
details: makeDetails([currentResult]),
|
|
342
|
+
});
|
|
343
|
+
}
|
|
344
|
+
};
|
|
345
|
+
|
|
346
|
+
try {
|
|
347
|
+
if (agent.systemPrompt.trim()) {
|
|
348
|
+
const tmp = await writePromptToTempFile(agent.name, agent.systemPrompt);
|
|
349
|
+
tmpPromptDir = tmp.dir;
|
|
350
|
+
tmpPromptPath = tmp.filePath;
|
|
351
|
+
args.push("--append-system-prompt", tmpPromptPath);
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
args.push(`Task: ${task}`);
|
|
355
|
+
let wasAborted = false;
|
|
356
|
+
|
|
357
|
+
const exitCode = await new Promise<number>((resolve) => {
|
|
358
|
+
const invocation = getPiInvocation(args);
|
|
359
|
+
const proc = spawn(invocation.command, invocation.args, {
|
|
360
|
+
cwd: cwd ?? defaultCwd,
|
|
361
|
+
shell: false,
|
|
362
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
363
|
+
});
|
|
364
|
+
let buffer = "";
|
|
365
|
+
|
|
366
|
+
const processLine = (line: string) => {
|
|
367
|
+
if (!line.trim()) return;
|
|
368
|
+
let event: any;
|
|
369
|
+
try {
|
|
370
|
+
event = JSON.parse(line);
|
|
371
|
+
} catch {
|
|
372
|
+
return;
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
if (event.type === "message_end" && event.message) {
|
|
376
|
+
const msg = event.message as Message;
|
|
377
|
+
currentResult.messages.push(msg);
|
|
378
|
+
|
|
379
|
+
if (msg.role === "assistant") {
|
|
380
|
+
currentResult.usage.turns++;
|
|
381
|
+
const usage = msg.usage;
|
|
382
|
+
if (usage) {
|
|
383
|
+
currentResult.usage.input += usage.input || 0;
|
|
384
|
+
currentResult.usage.output += usage.output || 0;
|
|
385
|
+
currentResult.usage.cacheRead += usage.cacheRead || 0;
|
|
386
|
+
currentResult.usage.cacheWrite += usage.cacheWrite || 0;
|
|
387
|
+
currentResult.usage.cost += usage.cost?.total || 0;
|
|
388
|
+
currentResult.usage.contextTokens = usage.totalTokens || 0;
|
|
389
|
+
}
|
|
390
|
+
if (!currentResult.model && msg.model)
|
|
391
|
+
currentResult.model = msg.model;
|
|
392
|
+
if (msg.stopReason) currentResult.stopReason = msg.stopReason;
|
|
393
|
+
if (msg.errorMessage) currentResult.errorMessage = msg.errorMessage;
|
|
394
|
+
}
|
|
395
|
+
emitUpdate();
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
if (event.type === "tool_result_end" && event.message) {
|
|
399
|
+
currentResult.messages.push(event.message as Message);
|
|
400
|
+
emitUpdate();
|
|
401
|
+
}
|
|
402
|
+
};
|
|
403
|
+
|
|
404
|
+
proc.stdout.on("data", (data) => {
|
|
405
|
+
buffer += data.toString();
|
|
406
|
+
const lines = buffer.split("\n");
|
|
407
|
+
buffer = lines.pop() || "";
|
|
408
|
+
for (const line of lines) processLine(line);
|
|
409
|
+
});
|
|
410
|
+
|
|
411
|
+
proc.stderr.on("data", (data) => {
|
|
412
|
+
currentResult.stderr += data.toString();
|
|
413
|
+
});
|
|
414
|
+
|
|
415
|
+
proc.on("close", (code) => {
|
|
416
|
+
if (buffer.trim()) processLine(buffer);
|
|
417
|
+
resolve(code ?? 0);
|
|
418
|
+
});
|
|
419
|
+
|
|
420
|
+
proc.on("error", () => {
|
|
421
|
+
resolve(1);
|
|
422
|
+
});
|
|
423
|
+
|
|
424
|
+
if (signal) {
|
|
425
|
+
const killProc = () => {
|
|
426
|
+
wasAborted = true;
|
|
427
|
+
proc.kill("SIGTERM");
|
|
428
|
+
setTimeout(() => {
|
|
429
|
+
if (!proc.killed) proc.kill("SIGKILL");
|
|
430
|
+
}, 5000);
|
|
431
|
+
};
|
|
432
|
+
if (signal.aborted) killProc();
|
|
433
|
+
else signal.addEventListener("abort", killProc, { once: true });
|
|
434
|
+
}
|
|
435
|
+
});
|
|
436
|
+
|
|
437
|
+
currentResult.exitCode = exitCode;
|
|
438
|
+
if (wasAborted) throw new Error("Subagent was aborted");
|
|
439
|
+
return currentResult;
|
|
440
|
+
} finally {
|
|
441
|
+
if (tmpPromptPath)
|
|
442
|
+
try {
|
|
443
|
+
fs.unlinkSync(tmpPromptPath);
|
|
444
|
+
} catch {
|
|
445
|
+
/* ignore */
|
|
446
|
+
}
|
|
447
|
+
if (tmpPromptDir)
|
|
448
|
+
try {
|
|
449
|
+
fs.rmdirSync(tmpPromptDir);
|
|
450
|
+
} catch {
|
|
451
|
+
/* ignore */
|
|
452
|
+
}
|
|
453
|
+
}
|
|
400
454
|
}
|
|
401
455
|
|
|
402
456
|
const TaskItem = Type.Object({
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
457
|
+
agent: Type.String({ description: "Name of the agent to invoke" }),
|
|
458
|
+
task: Type.String({ description: "Task to delegate to the agent" }),
|
|
459
|
+
cwd: Type.Optional(
|
|
460
|
+
Type.String({ description: "Working directory for the agent process" }),
|
|
461
|
+
),
|
|
406
462
|
});
|
|
407
463
|
|
|
408
464
|
const ChainItem = Type.Object({
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
465
|
+
agent: Type.String({ description: "Name of the agent to invoke" }),
|
|
466
|
+
task: Type.String({
|
|
467
|
+
description: "Task with optional {previous} placeholder for prior output",
|
|
468
|
+
}),
|
|
469
|
+
cwd: Type.Optional(
|
|
470
|
+
Type.String({ description: "Working directory for the agent process" }),
|
|
471
|
+
),
|
|
412
472
|
});
|
|
413
473
|
|
|
414
474
|
const AgentScopeSchema = StringEnum(["user", "project", "both"] as const, {
|
|
415
|
-
|
|
416
|
-
|
|
475
|
+
description:
|
|
476
|
+
'Which agent directories to use. Default: "user". Use "both" to include project-local agents.',
|
|
477
|
+
default: "user",
|
|
417
478
|
});
|
|
418
479
|
|
|
419
480
|
const SubagentParams = Type.Object({
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
481
|
+
agent: Type.Optional(
|
|
482
|
+
Type.String({
|
|
483
|
+
description: "Name of the agent to invoke (for single mode)",
|
|
484
|
+
}),
|
|
485
|
+
),
|
|
486
|
+
task: Type.Optional(
|
|
487
|
+
Type.String({ description: "Task to delegate (for single mode)" }),
|
|
488
|
+
),
|
|
489
|
+
tasks: Type.Optional(
|
|
490
|
+
Type.Array(TaskItem, {
|
|
491
|
+
description: "Array of {agent, task} for parallel execution",
|
|
492
|
+
}),
|
|
493
|
+
),
|
|
494
|
+
chain: Type.Optional(
|
|
495
|
+
Type.Array(ChainItem, {
|
|
496
|
+
description: "Array of {agent, task} for sequential execution",
|
|
497
|
+
}),
|
|
498
|
+
),
|
|
499
|
+
agentScope: Type.Optional(AgentScopeSchema),
|
|
500
|
+
confirmProjectAgents: Type.Optional(
|
|
501
|
+
Type.Boolean({
|
|
502
|
+
description: "Prompt before running project-local agents. Default: true.",
|
|
503
|
+
default: true,
|
|
504
|
+
}),
|
|
505
|
+
),
|
|
506
|
+
cwd: Type.Optional(
|
|
507
|
+
Type.String({
|
|
508
|
+
description: "Working directory for the agent process (single mode)",
|
|
509
|
+
}),
|
|
510
|
+
),
|
|
429
511
|
});
|
|
430
512
|
|
|
431
513
|
export default function (pi: ExtensionAPI) {
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
514
|
+
pi.registerTool({
|
|
515
|
+
name: "subagent",
|
|
516
|
+
label: "Subagent",
|
|
517
|
+
description: [
|
|
518
|
+
"Delegate tasks to specialized subagents with isolated context.",
|
|
519
|
+
"Modes: single (agent + task), parallel (tasks array), chain (sequential with {previous} placeholder).",
|
|
520
|
+
'Default agent scope is "user" (from ~/.pi/agent/agents).',
|
|
521
|
+
'To enable project-local agents in .pi/agents, set agentScope: "both" (or "project").',
|
|
522
|
+
].join(" "),
|
|
523
|
+
parameters: SubagentParams,
|
|
524
|
+
|
|
525
|
+
async execute(_toolCallId, params, signal, onUpdate, ctx) {
|
|
526
|
+
const agentScope: AgentScope = params.agentScope ?? "user";
|
|
527
|
+
const discovery = discoverAgents(ctx.cwd, agentScope);
|
|
528
|
+
const agents = discovery.agents;
|
|
529
|
+
const confirmProjectAgents = params.confirmProjectAgents ?? true;
|
|
530
|
+
|
|
531
|
+
const hasChain = (params.chain?.length ?? 0) > 0;
|
|
532
|
+
const hasTasks = (params.tasks?.length ?? 0) > 0;
|
|
533
|
+
const hasSingle = Boolean(params.agent && params.task);
|
|
534
|
+
const modeCount = Number(hasChain) + Number(hasTasks) + Number(hasSingle);
|
|
535
|
+
|
|
536
|
+
const makeDetails =
|
|
537
|
+
(mode: "single" | "parallel" | "chain") =>
|
|
538
|
+
(results: SingleResult[]): SubagentDetails => ({
|
|
539
|
+
mode,
|
|
540
|
+
agentScope,
|
|
541
|
+
projectAgentsDir: discovery.projectAgentsDir,
|
|
542
|
+
results,
|
|
543
|
+
});
|
|
544
|
+
|
|
545
|
+
if (modeCount !== 1) {
|
|
546
|
+
const available =
|
|
547
|
+
agents.map((a) => `${a.name} (${a.source})`).join(", ") || "none";
|
|
548
|
+
return {
|
|
549
|
+
content: [
|
|
550
|
+
{
|
|
551
|
+
type: "text",
|
|
552
|
+
text: `Invalid parameters. Provide exactly one mode.\nAvailable agents: ${available}`,
|
|
553
|
+
},
|
|
554
|
+
],
|
|
555
|
+
details: makeDetails("single")([]),
|
|
556
|
+
};
|
|
557
|
+
}
|
|
558
|
+
|
|
559
|
+
if (
|
|
560
|
+
(agentScope === "project" || agentScope === "both") &&
|
|
561
|
+
confirmProjectAgents &&
|
|
562
|
+
ctx.hasUI
|
|
563
|
+
) {
|
|
564
|
+
const requestedAgentNames = new Set<string>();
|
|
565
|
+
if (params.chain)
|
|
566
|
+
for (const step of params.chain) requestedAgentNames.add(step.agent);
|
|
567
|
+
if (params.tasks)
|
|
568
|
+
for (const t of params.tasks) requestedAgentNames.add(t.agent);
|
|
569
|
+
if (params.agent) requestedAgentNames.add(params.agent);
|
|
570
|
+
|
|
571
|
+
const projectAgentsRequested = Array.from(requestedAgentNames)
|
|
572
|
+
.map((name) => agents.find((a) => a.name === name))
|
|
573
|
+
.filter((a): a is AgentConfig => a?.source === "project");
|
|
574
|
+
|
|
575
|
+
if (projectAgentsRequested.length > 0) {
|
|
576
|
+
const names = projectAgentsRequested.map((a) => a.name).join(", ");
|
|
577
|
+
const dir = discovery.projectAgentsDir ?? "(unknown)";
|
|
578
|
+
const ok = await ctx.ui.confirm(
|
|
579
|
+
"Run project-local agents?",
|
|
580
|
+
`Agents: ${names}\nSource: ${dir}\n\nProject agents are repo-controlled. Only continue for trusted repositories.`,
|
|
581
|
+
);
|
|
582
|
+
if (!ok)
|
|
583
|
+
return {
|
|
584
|
+
content: [
|
|
585
|
+
{
|
|
586
|
+
type: "text",
|
|
587
|
+
text: "Canceled: project-local agents not approved.",
|
|
588
|
+
},
|
|
589
|
+
],
|
|
590
|
+
details: makeDetails(
|
|
591
|
+
hasChain ? "chain" : hasTasks ? "parallel" : "single",
|
|
592
|
+
)([]),
|
|
593
|
+
};
|
|
594
|
+
}
|
|
595
|
+
}
|
|
596
|
+
|
|
597
|
+
if (params.chain && params.chain.length > 0) {
|
|
598
|
+
const results: SingleResult[] = [];
|
|
599
|
+
let previousOutput = "";
|
|
600
|
+
|
|
601
|
+
for (let i = 0; i < params.chain.length; i++) {
|
|
602
|
+
const step = params.chain[i];
|
|
603
|
+
const taskWithContext = step.task.replace(
|
|
604
|
+
/\{previous\}/g,
|
|
605
|
+
previousOutput,
|
|
606
|
+
);
|
|
607
|
+
|
|
608
|
+
// Create update callback that includes all previous results
|
|
609
|
+
const chainUpdate: OnUpdateCallback | undefined = onUpdate
|
|
610
|
+
? (partial) => {
|
|
611
|
+
// Combine completed results with current streaming result
|
|
612
|
+
const currentResult = partial.details?.results[0];
|
|
613
|
+
if (currentResult) {
|
|
614
|
+
const allResults = [...results, currentResult];
|
|
615
|
+
onUpdate({
|
|
616
|
+
content: partial.content,
|
|
617
|
+
details: makeDetails("chain")(allResults),
|
|
618
|
+
});
|
|
619
|
+
}
|
|
620
|
+
}
|
|
621
|
+
: undefined;
|
|
622
|
+
|
|
623
|
+
const result = await runSingleAgent(
|
|
624
|
+
ctx.cwd,
|
|
625
|
+
agents,
|
|
626
|
+
step.agent,
|
|
627
|
+
taskWithContext,
|
|
628
|
+
step.cwd,
|
|
629
|
+
i + 1,
|
|
630
|
+
signal,
|
|
631
|
+
chainUpdate,
|
|
632
|
+
makeDetails("chain"),
|
|
633
|
+
);
|
|
634
|
+
results.push(result);
|
|
635
|
+
|
|
636
|
+
const isError =
|
|
637
|
+
result.exitCode !== 0 ||
|
|
638
|
+
result.stopReason === "error" ||
|
|
639
|
+
result.stopReason === "aborted";
|
|
640
|
+
if (isError) {
|
|
641
|
+
const errorMsg =
|
|
642
|
+
result.errorMessage ||
|
|
643
|
+
result.stderr ||
|
|
644
|
+
getFinalOutput(result.messages) ||
|
|
645
|
+
"(no output)";
|
|
646
|
+
return {
|
|
647
|
+
content: [
|
|
648
|
+
{
|
|
649
|
+
type: "text",
|
|
650
|
+
text: `Chain stopped at step ${i + 1} (${step.agent}): ${errorMsg}`,
|
|
651
|
+
},
|
|
652
|
+
],
|
|
653
|
+
details: makeDetails("chain")(results),
|
|
654
|
+
isError: true,
|
|
655
|
+
};
|
|
656
|
+
}
|
|
657
|
+
previousOutput = getFinalOutput(result.messages);
|
|
658
|
+
}
|
|
659
|
+
return {
|
|
660
|
+
content: [
|
|
661
|
+
{
|
|
662
|
+
type: "text",
|
|
663
|
+
text:
|
|
664
|
+
getFinalOutput(results[results.length - 1].messages) ||
|
|
665
|
+
"(no output)",
|
|
666
|
+
},
|
|
667
|
+
],
|
|
668
|
+
details: makeDetails("chain")(results),
|
|
669
|
+
};
|
|
670
|
+
}
|
|
671
|
+
|
|
672
|
+
if (params.tasks && params.tasks.length > 0) {
|
|
673
|
+
if (params.tasks.length > MAX_PARALLEL_TASKS)
|
|
674
|
+
return {
|
|
675
|
+
content: [
|
|
676
|
+
{
|
|
677
|
+
type: "text",
|
|
678
|
+
text: `Too many parallel tasks (${params.tasks.length}). Max is ${MAX_PARALLEL_TASKS}.`,
|
|
679
|
+
},
|
|
680
|
+
],
|
|
681
|
+
details: makeDetails("parallel")([]),
|
|
682
|
+
};
|
|
683
|
+
|
|
684
|
+
// Track all results for streaming updates
|
|
685
|
+
const allResults: SingleResult[] = new Array(params.tasks.length);
|
|
686
|
+
|
|
687
|
+
// Initialize placeholder results
|
|
688
|
+
for (let i = 0; i < params.tasks.length; i++) {
|
|
689
|
+
allResults[i] = {
|
|
690
|
+
agent: params.tasks[i].agent,
|
|
691
|
+
agentSource: "unknown",
|
|
692
|
+
task: params.tasks[i].task,
|
|
693
|
+
exitCode: -1, // -1 = still running
|
|
694
|
+
messages: [],
|
|
695
|
+
stderr: "",
|
|
696
|
+
usage: {
|
|
697
|
+
input: 0,
|
|
698
|
+
output: 0,
|
|
699
|
+
cacheRead: 0,
|
|
700
|
+
cacheWrite: 0,
|
|
701
|
+
cost: 0,
|
|
702
|
+
contextTokens: 0,
|
|
703
|
+
turns: 0,
|
|
704
|
+
},
|
|
705
|
+
};
|
|
706
|
+
}
|
|
707
|
+
|
|
708
|
+
const emitParallelUpdate = () => {
|
|
709
|
+
if (onUpdate) {
|
|
710
|
+
const running = allResults.filter((r) => r.exitCode === -1).length;
|
|
711
|
+
const done = allResults.filter((r) => r.exitCode !== -1).length;
|
|
712
|
+
onUpdate({
|
|
713
|
+
content: [
|
|
714
|
+
{
|
|
715
|
+
type: "text",
|
|
716
|
+
text: `Parallel: ${done}/${allResults.length} done, ${running} running...`,
|
|
717
|
+
},
|
|
718
|
+
],
|
|
719
|
+
details: makeDetails("parallel")([...allResults]),
|
|
720
|
+
});
|
|
721
|
+
}
|
|
722
|
+
};
|
|
723
|
+
|
|
724
|
+
const results = await mapWithConcurrencyLimit(
|
|
725
|
+
params.tasks,
|
|
726
|
+
MAX_CONCURRENCY,
|
|
727
|
+
async (t, index) => {
|
|
728
|
+
const result = await runSingleAgent(
|
|
729
|
+
ctx.cwd,
|
|
730
|
+
agents,
|
|
731
|
+
t.agent,
|
|
732
|
+
t.task,
|
|
733
|
+
t.cwd,
|
|
734
|
+
undefined,
|
|
735
|
+
signal,
|
|
736
|
+
// Per-task update callback
|
|
737
|
+
(partial) => {
|
|
738
|
+
if (partial.details?.results[0]) {
|
|
739
|
+
allResults[index] = partial.details.results[0];
|
|
740
|
+
emitParallelUpdate();
|
|
741
|
+
}
|
|
742
|
+
},
|
|
743
|
+
makeDetails("parallel"),
|
|
744
|
+
);
|
|
745
|
+
allResults[index] = result;
|
|
746
|
+
emitParallelUpdate();
|
|
747
|
+
return result;
|
|
748
|
+
},
|
|
749
|
+
);
|
|
750
|
+
|
|
751
|
+
const successCount = results.filter((r) => r.exitCode === 0).length;
|
|
752
|
+
const summaries = results.map((r) => {
|
|
753
|
+
const output = getFinalOutput(r.messages);
|
|
754
|
+
const preview =
|
|
755
|
+
output.slice(0, 100) + (output.length > 100 ? "..." : "");
|
|
756
|
+
return `[${r.agent}] ${r.exitCode === 0 ? "completed" : "failed"}: ${preview || "(no output)"}`;
|
|
757
|
+
});
|
|
758
|
+
return {
|
|
759
|
+
content: [
|
|
760
|
+
{
|
|
761
|
+
type: "text",
|
|
762
|
+
text: `Parallel: ${successCount}/${results.length} succeeded\n\n${summaries.join("\n\n")}`,
|
|
763
|
+
},
|
|
764
|
+
],
|
|
765
|
+
details: makeDetails("parallel")(results),
|
|
766
|
+
};
|
|
767
|
+
}
|
|
768
|
+
|
|
769
|
+
if (params.agent && params.task) {
|
|
770
|
+
const result = await runSingleAgent(
|
|
771
|
+
ctx.cwd,
|
|
772
|
+
agents,
|
|
773
|
+
params.agent,
|
|
774
|
+
params.task,
|
|
775
|
+
params.cwd,
|
|
776
|
+
undefined,
|
|
777
|
+
signal,
|
|
778
|
+
onUpdate,
|
|
779
|
+
makeDetails("single"),
|
|
780
|
+
);
|
|
781
|
+
const isError =
|
|
782
|
+
result.exitCode !== 0 ||
|
|
783
|
+
result.stopReason === "error" ||
|
|
784
|
+
result.stopReason === "aborted";
|
|
785
|
+
if (isError) {
|
|
786
|
+
const errorMsg =
|
|
787
|
+
result.errorMessage ||
|
|
788
|
+
result.stderr ||
|
|
789
|
+
getFinalOutput(result.messages) ||
|
|
790
|
+
"(no output)";
|
|
791
|
+
return {
|
|
792
|
+
content: [
|
|
793
|
+
{
|
|
794
|
+
type: "text",
|
|
795
|
+
text: `Agent ${result.stopReason || "failed"}: ${errorMsg}`,
|
|
796
|
+
},
|
|
797
|
+
],
|
|
798
|
+
details: makeDetails("single")([result]),
|
|
799
|
+
isError: true,
|
|
800
|
+
};
|
|
801
|
+
}
|
|
802
|
+
return {
|
|
803
|
+
content: [
|
|
804
|
+
{
|
|
805
|
+
type: "text",
|
|
806
|
+
text: getFinalOutput(result.messages) || "(no output)",
|
|
807
|
+
},
|
|
808
|
+
],
|
|
809
|
+
details: makeDetails("single")([result]),
|
|
810
|
+
};
|
|
811
|
+
}
|
|
812
|
+
|
|
813
|
+
const available =
|
|
814
|
+
agents.map((a) => `${a.name} (${a.source})`).join(", ") || "none";
|
|
815
|
+
return {
|
|
816
|
+
content: [
|
|
817
|
+
{
|
|
818
|
+
type: "text",
|
|
819
|
+
text: `Invalid parameters. Available agents: ${available}`,
|
|
820
|
+
},
|
|
821
|
+
],
|
|
822
|
+
details: makeDetails("single")([]),
|
|
823
|
+
};
|
|
824
|
+
},
|
|
825
|
+
|
|
826
|
+
renderCall(args, theme, _context) {
|
|
827
|
+
const scope: AgentScope = args.agentScope ?? "user";
|
|
828
|
+
if (args.chain && args.chain.length > 0) {
|
|
829
|
+
let text =
|
|
830
|
+
theme.fg("toolTitle", theme.bold("subagent ")) +
|
|
831
|
+
theme.fg("accent", `chain (${args.chain.length} steps)`) +
|
|
832
|
+
theme.fg("muted", ` [${scope}]`);
|
|
833
|
+
for (let i = 0; i < Math.min(args.chain.length, 3); i++) {
|
|
834
|
+
const step = args.chain[i];
|
|
835
|
+
// Clean up {previous} placeholder for display
|
|
836
|
+
const cleanTask = step.task.replace(/\{previous\}/g, "").trim();
|
|
837
|
+
const preview =
|
|
838
|
+
cleanTask.length > 40 ? `${cleanTask.slice(0, 40)}...` : cleanTask;
|
|
839
|
+
text +=
|
|
840
|
+
"\n " +
|
|
841
|
+
theme.fg("muted", `${i + 1}.`) +
|
|
842
|
+
" " +
|
|
843
|
+
theme.fg("accent", step.agent) +
|
|
844
|
+
theme.fg("dim", ` ${preview}`);
|
|
845
|
+
}
|
|
846
|
+
if (args.chain.length > 3)
|
|
847
|
+
text += `\n ${theme.fg("muted", `... +${args.chain.length - 3} more`)}`;
|
|
848
|
+
return new Text(text, 0, 0);
|
|
849
|
+
}
|
|
850
|
+
if (args.tasks && args.tasks.length > 0) {
|
|
851
|
+
let text =
|
|
852
|
+
theme.fg("toolTitle", theme.bold("subagent ")) +
|
|
853
|
+
theme.fg("accent", `parallel (${args.tasks.length} tasks)`) +
|
|
854
|
+
theme.fg("muted", ` [${scope}]`);
|
|
855
|
+
for (const t of args.tasks.slice(0, 3)) {
|
|
856
|
+
const preview =
|
|
857
|
+
t.task.length > 40 ? `${t.task.slice(0, 40)}...` : t.task;
|
|
858
|
+
text += `\n ${theme.fg("accent", t.agent)}${theme.fg("dim", ` ${preview}`)}`;
|
|
859
|
+
}
|
|
860
|
+
if (args.tasks.length > 3)
|
|
861
|
+
text += `\n ${theme.fg("muted", `... +${args.tasks.length - 3} more`)}`;
|
|
862
|
+
return new Text(text, 0, 0);
|
|
863
|
+
}
|
|
864
|
+
const agentName = args.agent || "...";
|
|
865
|
+
const preview = args.task
|
|
866
|
+
? args.task.length > 60
|
|
867
|
+
? `${args.task.slice(0, 60)}...`
|
|
868
|
+
: args.task
|
|
869
|
+
: "...";
|
|
870
|
+
let text =
|
|
871
|
+
theme.fg("toolTitle", theme.bold("subagent ")) +
|
|
872
|
+
theme.fg("accent", agentName) +
|
|
873
|
+
theme.fg("muted", ` [${scope}]`);
|
|
874
|
+
text += `\n ${theme.fg("dim", preview)}`;
|
|
875
|
+
return new Text(text, 0, 0);
|
|
876
|
+
},
|
|
877
|
+
|
|
878
|
+
renderResult(result, { expanded }, theme, _context) {
|
|
879
|
+
const details = result.details as SubagentDetails | undefined;
|
|
880
|
+
if (!details || details.results.length === 0) {
|
|
881
|
+
const text = result.content[0];
|
|
882
|
+
return new Text(
|
|
883
|
+
text?.type === "text" ? text.text : "(no output)",
|
|
884
|
+
0,
|
|
885
|
+
0,
|
|
886
|
+
);
|
|
887
|
+
}
|
|
888
|
+
|
|
889
|
+
const mdTheme = getMarkdownTheme();
|
|
890
|
+
|
|
891
|
+
const renderDisplayItems = (items: DisplayItem[], limit?: number) => {
|
|
892
|
+
const toShow = limit ? items.slice(-limit) : items;
|
|
893
|
+
const skipped =
|
|
894
|
+
limit && items.length > limit ? items.length - limit : 0;
|
|
895
|
+
let text = "";
|
|
896
|
+
if (skipped > 0)
|
|
897
|
+
text += theme.fg("muted", `... ${skipped} earlier items\n`);
|
|
898
|
+
for (const item of toShow) {
|
|
899
|
+
if (item.type === "text") {
|
|
900
|
+
const preview = expanded
|
|
901
|
+
? item.text
|
|
902
|
+
: item.text.split("\n").slice(0, 3).join("\n");
|
|
903
|
+
text += `${theme.fg("toolOutput", preview)}\n`;
|
|
904
|
+
} else {
|
|
905
|
+
text += `${theme.fg("muted", "→ ") + formatToolCall(item.name, item.args, theme.fg.bind(theme))}\n`;
|
|
906
|
+
}
|
|
907
|
+
}
|
|
908
|
+
return text.trimEnd();
|
|
909
|
+
};
|
|
910
|
+
|
|
911
|
+
if (details.mode === "single" && details.results.length === 1) {
|
|
912
|
+
const r = details.results[0];
|
|
913
|
+
const isError =
|
|
914
|
+
r.exitCode !== 0 ||
|
|
915
|
+
r.stopReason === "error" ||
|
|
916
|
+
r.stopReason === "aborted";
|
|
917
|
+
const icon = isError
|
|
918
|
+
? theme.fg("error", "✗")
|
|
919
|
+
: theme.fg("success", "✓");
|
|
920
|
+
const displayItems = getDisplayItems(r.messages);
|
|
921
|
+
const finalOutput = getFinalOutput(r.messages);
|
|
922
|
+
|
|
923
|
+
if (expanded) {
|
|
924
|
+
const container = new Container();
|
|
925
|
+
let header = `${icon} ${theme.fg("toolTitle", theme.bold(r.agent))}${theme.fg("muted", ` (${r.agentSource})`)}`;
|
|
926
|
+
if (isError && r.stopReason)
|
|
927
|
+
header += ` ${theme.fg("error", `[${r.stopReason}]`)}`;
|
|
928
|
+
container.addChild(new Text(header, 0, 0));
|
|
929
|
+
if (isError && r.errorMessage)
|
|
930
|
+
container.addChild(
|
|
931
|
+
new Text(theme.fg("error", `Error: ${r.errorMessage}`), 0, 0),
|
|
932
|
+
);
|
|
933
|
+
container.addChild(new Spacer(1));
|
|
934
|
+
container.addChild(new Text(theme.fg("muted", "─── Task ───"), 0, 0));
|
|
935
|
+
container.addChild(new Text(theme.fg("dim", r.task), 0, 0));
|
|
936
|
+
container.addChild(new Spacer(1));
|
|
937
|
+
container.addChild(
|
|
938
|
+
new Text(theme.fg("muted", "─── Output ───"), 0, 0),
|
|
939
|
+
);
|
|
940
|
+
if (displayItems.length === 0 && !finalOutput) {
|
|
941
|
+
container.addChild(
|
|
942
|
+
new Text(theme.fg("muted", "(no output)"), 0, 0),
|
|
943
|
+
);
|
|
944
|
+
} else {
|
|
945
|
+
for (const item of displayItems) {
|
|
946
|
+
if (item.type === "toolCall")
|
|
947
|
+
container.addChild(
|
|
948
|
+
new Text(
|
|
949
|
+
theme.fg("muted", "→ ") +
|
|
950
|
+
formatToolCall(
|
|
951
|
+
item.name,
|
|
952
|
+
item.args,
|
|
953
|
+
theme.fg.bind(theme),
|
|
954
|
+
),
|
|
955
|
+
0,
|
|
956
|
+
0,
|
|
957
|
+
),
|
|
958
|
+
);
|
|
959
|
+
}
|
|
960
|
+
if (finalOutput) {
|
|
961
|
+
container.addChild(new Spacer(1));
|
|
962
|
+
container.addChild(
|
|
963
|
+
new Markdown(finalOutput.trim(), 0, 0, mdTheme),
|
|
964
|
+
);
|
|
965
|
+
}
|
|
966
|
+
}
|
|
967
|
+
const usageStr = formatUsageStats(r.usage, r.model);
|
|
968
|
+
if (usageStr) {
|
|
969
|
+
container.addChild(new Spacer(1));
|
|
970
|
+
container.addChild(new Text(theme.fg("dim", usageStr), 0, 0));
|
|
971
|
+
}
|
|
972
|
+
return container;
|
|
973
|
+
}
|
|
974
|
+
|
|
975
|
+
let text = `${icon} ${theme.fg("toolTitle", theme.bold(r.agent))}${theme.fg("muted", ` (${r.agentSource})`)}`;
|
|
976
|
+
if (isError && r.stopReason)
|
|
977
|
+
text += ` ${theme.fg("error", `[${r.stopReason}]`)}`;
|
|
978
|
+
if (isError && r.errorMessage)
|
|
979
|
+
text += `\n${theme.fg("error", `Error: ${r.errorMessage}`)}`;
|
|
980
|
+
else if (displayItems.length === 0)
|
|
981
|
+
text += `\n${theme.fg("muted", "(no output)")}`;
|
|
982
|
+
else {
|
|
983
|
+
text += `\n${renderDisplayItems(displayItems, COLLAPSED_ITEM_COUNT)}`;
|
|
984
|
+
if (displayItems.length > COLLAPSED_ITEM_COUNT)
|
|
985
|
+
text += `\n${theme.fg("muted", "(ctrl+o to expand)")}`;
|
|
986
|
+
}
|
|
987
|
+
const usageStr = formatUsageStats(r.usage, r.model);
|
|
988
|
+
if (usageStr) text += `\n${theme.fg("dim", usageStr)}`;
|
|
989
|
+
return new Text(text, 0, 0);
|
|
990
|
+
}
|
|
991
|
+
|
|
992
|
+
const aggregateUsage = (results: SingleResult[]) => {
|
|
993
|
+
const total = {
|
|
994
|
+
input: 0,
|
|
995
|
+
output: 0,
|
|
996
|
+
cacheRead: 0,
|
|
997
|
+
cacheWrite: 0,
|
|
998
|
+
cost: 0,
|
|
999
|
+
turns: 0,
|
|
1000
|
+
};
|
|
1001
|
+
for (const r of results) {
|
|
1002
|
+
total.input += r.usage.input;
|
|
1003
|
+
total.output += r.usage.output;
|
|
1004
|
+
total.cacheRead += r.usage.cacheRead;
|
|
1005
|
+
total.cacheWrite += r.usage.cacheWrite;
|
|
1006
|
+
total.cost += r.usage.cost;
|
|
1007
|
+
total.turns += r.usage.turns;
|
|
1008
|
+
}
|
|
1009
|
+
return total;
|
|
1010
|
+
};
|
|
1011
|
+
|
|
1012
|
+
if (details.mode === "chain") {
|
|
1013
|
+
const successCount = details.results.filter(
|
|
1014
|
+
(r) => r.exitCode === 0,
|
|
1015
|
+
).length;
|
|
1016
|
+
const icon =
|
|
1017
|
+
successCount === details.results.length
|
|
1018
|
+
? theme.fg("success", "✓")
|
|
1019
|
+
: theme.fg("error", "✗");
|
|
1020
|
+
|
|
1021
|
+
if (expanded) {
|
|
1022
|
+
const container = new Container();
|
|
1023
|
+
container.addChild(
|
|
1024
|
+
new Text(
|
|
1025
|
+
icon +
|
|
1026
|
+
" " +
|
|
1027
|
+
theme.fg("toolTitle", theme.bold("chain ")) +
|
|
1028
|
+
theme.fg(
|
|
1029
|
+
"accent",
|
|
1030
|
+
`${successCount}/${details.results.length} steps`,
|
|
1031
|
+
),
|
|
1032
|
+
0,
|
|
1033
|
+
0,
|
|
1034
|
+
),
|
|
1035
|
+
);
|
|
1036
|
+
|
|
1037
|
+
for (const r of details.results) {
|
|
1038
|
+
const rIcon =
|
|
1039
|
+
r.exitCode === 0
|
|
1040
|
+
? theme.fg("success", "✓")
|
|
1041
|
+
: theme.fg("error", "✗");
|
|
1042
|
+
const displayItems = getDisplayItems(r.messages);
|
|
1043
|
+
const finalOutput = getFinalOutput(r.messages);
|
|
1044
|
+
|
|
1045
|
+
container.addChild(new Spacer(1));
|
|
1046
|
+
container.addChild(
|
|
1047
|
+
new Text(
|
|
1048
|
+
`${theme.fg("muted", `─── Step ${r.step}: `) + theme.fg("accent", r.agent)} ${rIcon}`,
|
|
1049
|
+
0,
|
|
1050
|
+
0,
|
|
1051
|
+
),
|
|
1052
|
+
);
|
|
1053
|
+
container.addChild(
|
|
1054
|
+
new Text(
|
|
1055
|
+
theme.fg("muted", "Task: ") + theme.fg("dim", r.task),
|
|
1056
|
+
0,
|
|
1057
|
+
0,
|
|
1058
|
+
),
|
|
1059
|
+
);
|
|
1060
|
+
|
|
1061
|
+
// Show tool calls
|
|
1062
|
+
for (const item of displayItems) {
|
|
1063
|
+
if (item.type === "toolCall") {
|
|
1064
|
+
container.addChild(
|
|
1065
|
+
new Text(
|
|
1066
|
+
theme.fg("muted", "→ ") +
|
|
1067
|
+
formatToolCall(
|
|
1068
|
+
item.name,
|
|
1069
|
+
item.args,
|
|
1070
|
+
theme.fg.bind(theme),
|
|
1071
|
+
),
|
|
1072
|
+
0,
|
|
1073
|
+
0,
|
|
1074
|
+
),
|
|
1075
|
+
);
|
|
1076
|
+
}
|
|
1077
|
+
}
|
|
1078
|
+
|
|
1079
|
+
// Show final output as markdown
|
|
1080
|
+
if (finalOutput) {
|
|
1081
|
+
container.addChild(new Spacer(1));
|
|
1082
|
+
container.addChild(
|
|
1083
|
+
new Markdown(finalOutput.trim(), 0, 0, mdTheme),
|
|
1084
|
+
);
|
|
1085
|
+
}
|
|
1086
|
+
|
|
1087
|
+
const stepUsage = formatUsageStats(r.usage, r.model);
|
|
1088
|
+
if (stepUsage)
|
|
1089
|
+
container.addChild(new Text(theme.fg("dim", stepUsage), 0, 0));
|
|
1090
|
+
}
|
|
1091
|
+
|
|
1092
|
+
const usageStr = formatUsageStats(aggregateUsage(details.results));
|
|
1093
|
+
if (usageStr) {
|
|
1094
|
+
container.addChild(new Spacer(1));
|
|
1095
|
+
container.addChild(
|
|
1096
|
+
new Text(theme.fg("dim", `Total: ${usageStr}`), 0, 0),
|
|
1097
|
+
);
|
|
1098
|
+
}
|
|
1099
|
+
return container;
|
|
1100
|
+
}
|
|
1101
|
+
|
|
1102
|
+
// Collapsed view
|
|
1103
|
+
let text =
|
|
1104
|
+
icon +
|
|
1105
|
+
" " +
|
|
1106
|
+
theme.fg("toolTitle", theme.bold("chain ")) +
|
|
1107
|
+
theme.fg("accent", `${successCount}/${details.results.length} steps`);
|
|
1108
|
+
for (const r of details.results) {
|
|
1109
|
+
const rIcon =
|
|
1110
|
+
r.exitCode === 0
|
|
1111
|
+
? theme.fg("success", "✓")
|
|
1112
|
+
: theme.fg("error", "✗");
|
|
1113
|
+
const displayItems = getDisplayItems(r.messages);
|
|
1114
|
+
text += `\n\n${theme.fg("muted", `─── Step ${r.step}: `)}${theme.fg("accent", r.agent)} ${rIcon}`;
|
|
1115
|
+
if (displayItems.length === 0)
|
|
1116
|
+
text += `\n${theme.fg("muted", "(no output)")}`;
|
|
1117
|
+
else text += `\n${renderDisplayItems(displayItems, 5)}`;
|
|
1118
|
+
}
|
|
1119
|
+
const usageStr = formatUsageStats(aggregateUsage(details.results));
|
|
1120
|
+
if (usageStr) text += `\n\n${theme.fg("dim", `Total: ${usageStr}`)}`;
|
|
1121
|
+
text += `\n${theme.fg("muted", "(ctrl+o to expand)")}`;
|
|
1122
|
+
return new Text(text, 0, 0);
|
|
1123
|
+
}
|
|
1124
|
+
|
|
1125
|
+
if (details.mode === "parallel") {
|
|
1126
|
+
const running = details.results.filter((r) => r.exitCode === -1).length;
|
|
1127
|
+
const successCount = details.results.filter(
|
|
1128
|
+
(r) => r.exitCode === 0,
|
|
1129
|
+
).length;
|
|
1130
|
+
const failCount = details.results.filter((r) => r.exitCode > 0).length;
|
|
1131
|
+
const isRunning = running > 0;
|
|
1132
|
+
const icon = isRunning
|
|
1133
|
+
? theme.fg("warning", "⏳")
|
|
1134
|
+
: failCount > 0
|
|
1135
|
+
? theme.fg("warning", "◐")
|
|
1136
|
+
: theme.fg("success", "✓");
|
|
1137
|
+
const status = isRunning
|
|
1138
|
+
? `${successCount + failCount}/${details.results.length} done, ${running} running`
|
|
1139
|
+
: `${successCount}/${details.results.length} tasks`;
|
|
1140
|
+
|
|
1141
|
+
if (expanded && !isRunning) {
|
|
1142
|
+
const container = new Container();
|
|
1143
|
+
container.addChild(
|
|
1144
|
+
new Text(
|
|
1145
|
+
`${icon} ${theme.fg("toolTitle", theme.bold("parallel "))}${theme.fg("accent", status)}`,
|
|
1146
|
+
0,
|
|
1147
|
+
0,
|
|
1148
|
+
),
|
|
1149
|
+
);
|
|
1150
|
+
|
|
1151
|
+
for (const r of details.results) {
|
|
1152
|
+
const rIcon =
|
|
1153
|
+
r.exitCode === 0
|
|
1154
|
+
? theme.fg("success", "✓")
|
|
1155
|
+
: theme.fg("error", "✗");
|
|
1156
|
+
const displayItems = getDisplayItems(r.messages);
|
|
1157
|
+
const finalOutput = getFinalOutput(r.messages);
|
|
1158
|
+
|
|
1159
|
+
container.addChild(new Spacer(1));
|
|
1160
|
+
container.addChild(
|
|
1161
|
+
new Text(
|
|
1162
|
+
`${theme.fg("muted", "─── ") + theme.fg("accent", r.agent)} ${rIcon}`,
|
|
1163
|
+
0,
|
|
1164
|
+
0,
|
|
1165
|
+
),
|
|
1166
|
+
);
|
|
1167
|
+
container.addChild(
|
|
1168
|
+
new Text(
|
|
1169
|
+
theme.fg("muted", "Task: ") + theme.fg("dim", r.task),
|
|
1170
|
+
0,
|
|
1171
|
+
0,
|
|
1172
|
+
),
|
|
1173
|
+
);
|
|
1174
|
+
|
|
1175
|
+
// Show tool calls
|
|
1176
|
+
for (const item of displayItems) {
|
|
1177
|
+
if (item.type === "toolCall") {
|
|
1178
|
+
container.addChild(
|
|
1179
|
+
new Text(
|
|
1180
|
+
theme.fg("muted", "→ ") +
|
|
1181
|
+
formatToolCall(
|
|
1182
|
+
item.name,
|
|
1183
|
+
item.args,
|
|
1184
|
+
theme.fg.bind(theme),
|
|
1185
|
+
),
|
|
1186
|
+
0,
|
|
1187
|
+
0,
|
|
1188
|
+
),
|
|
1189
|
+
);
|
|
1190
|
+
}
|
|
1191
|
+
}
|
|
1192
|
+
|
|
1193
|
+
// Show final output as markdown
|
|
1194
|
+
if (finalOutput) {
|
|
1195
|
+
container.addChild(new Spacer(1));
|
|
1196
|
+
container.addChild(
|
|
1197
|
+
new Markdown(finalOutput.trim(), 0, 0, mdTheme),
|
|
1198
|
+
);
|
|
1199
|
+
}
|
|
1200
|
+
|
|
1201
|
+
const taskUsage = formatUsageStats(r.usage, r.model);
|
|
1202
|
+
if (taskUsage)
|
|
1203
|
+
container.addChild(new Text(theme.fg("dim", taskUsage), 0, 0));
|
|
1204
|
+
}
|
|
1205
|
+
|
|
1206
|
+
const usageStr = formatUsageStats(aggregateUsage(details.results));
|
|
1207
|
+
if (usageStr) {
|
|
1208
|
+
container.addChild(new Spacer(1));
|
|
1209
|
+
container.addChild(
|
|
1210
|
+
new Text(theme.fg("dim", `Total: ${usageStr}`), 0, 0),
|
|
1211
|
+
);
|
|
1212
|
+
}
|
|
1213
|
+
return container;
|
|
1214
|
+
}
|
|
1215
|
+
|
|
1216
|
+
// Collapsed view (or still running)
|
|
1217
|
+
let text = `${icon} ${theme.fg("toolTitle", theme.bold("parallel "))}${theme.fg("accent", status)}`;
|
|
1218
|
+
for (const r of details.results) {
|
|
1219
|
+
const rIcon =
|
|
1220
|
+
r.exitCode === -1
|
|
1221
|
+
? theme.fg("warning", "⏳")
|
|
1222
|
+
: r.exitCode === 0
|
|
1223
|
+
? theme.fg("success", "✓")
|
|
1224
|
+
: theme.fg("error", "✗");
|
|
1225
|
+
const displayItems = getDisplayItems(r.messages);
|
|
1226
|
+
text += `\n\n${theme.fg("muted", "─── ")}${theme.fg("accent", r.agent)} ${rIcon}`;
|
|
1227
|
+
if (displayItems.length === 0)
|
|
1228
|
+
text += `\n${theme.fg("muted", r.exitCode === -1 ? "(running...)" : "(no output)")}`;
|
|
1229
|
+
else text += `\n${renderDisplayItems(displayItems, 5)}`;
|
|
1230
|
+
}
|
|
1231
|
+
if (!isRunning) {
|
|
1232
|
+
const usageStr = formatUsageStats(aggregateUsage(details.results));
|
|
1233
|
+
if (usageStr) text += `\n\n${theme.fg("dim", `Total: ${usageStr}`)}`;
|
|
1234
|
+
}
|
|
1235
|
+
if (!expanded) text += `\n${theme.fg("muted", "(ctrl+o to expand)")}`;
|
|
1236
|
+
return new Text(text, 0, 0);
|
|
1237
|
+
}
|
|
1238
|
+
|
|
1239
|
+
const text = result.content[0];
|
|
1240
|
+
return new Text(text?.type === "text" ? text.text : "(no output)", 0, 0);
|
|
1241
|
+
},
|
|
1242
|
+
});
|
|
987
1243
|
}
|