@bastani/atomic 0.8.11 → 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 +21 -0
- 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
|
@@ -17,44 +17,78 @@ import * as os from "node:os";
|
|
|
17
17
|
import * as path from "node:path";
|
|
18
18
|
import { getAgentConfigPaths, getEnvValue } from "@bastani/atomic";
|
|
19
19
|
import type { AgentToolResult } from "@earendil-works/pi-agent-core";
|
|
20
|
-
import {
|
|
21
|
-
|
|
20
|
+
import {
|
|
21
|
+
type ExtensionAPI,
|
|
22
|
+
type ExtensionContext,
|
|
23
|
+
type ToolDefinition,
|
|
24
|
+
} from "@bastani/atomic";
|
|
25
|
+
import {
|
|
26
|
+
Box,
|
|
27
|
+
Container,
|
|
28
|
+
Spacer,
|
|
29
|
+
Text,
|
|
30
|
+
truncateToWidth,
|
|
31
|
+
visibleWidth,
|
|
32
|
+
wrapTextWithAnsi,
|
|
33
|
+
type Component,
|
|
34
|
+
} from "@earendil-works/pi-tui";
|
|
22
35
|
import { discoverAgents } from "../agents/agents.ts";
|
|
23
|
-
import {
|
|
36
|
+
import {
|
|
37
|
+
cleanupAllArtifactDirs,
|
|
38
|
+
cleanupOldArtifacts,
|
|
39
|
+
getArtifactsDir,
|
|
40
|
+
} from "../shared/artifacts.ts";
|
|
24
41
|
import { resolveCurrentSessionId } from "../shared/session-identity.ts";
|
|
25
42
|
import { cleanupOldChainDirs } from "../shared/settings.ts";
|
|
26
|
-
import {
|
|
43
|
+
import {
|
|
44
|
+
renderWidget,
|
|
45
|
+
renderSubagentResult,
|
|
46
|
+
stopResultAnimations,
|
|
47
|
+
stopWidgetAnimation,
|
|
48
|
+
syncResultAnimation,
|
|
49
|
+
} from "../tui/render.ts";
|
|
27
50
|
import { SubagentParams } from "./schemas.ts";
|
|
28
|
-
import {
|
|
51
|
+
import {
|
|
52
|
+
createSubagentExecutor,
|
|
53
|
+
type SubagentParamsLike,
|
|
54
|
+
} from "../runs/foreground/subagent-executor.ts";
|
|
29
55
|
import { createAsyncJobTracker } from "../runs/background/async-job-tracker.ts";
|
|
30
56
|
import { createResultWatcher } from "../runs/background/result-watcher.ts";
|
|
31
57
|
import { registerSlashCommands } from "../slash/slash-commands.ts";
|
|
32
58
|
import { registerPromptTemplateDelegationBridge } from "../slash/prompt-template-bridge.ts";
|
|
33
59
|
import { registerSlashSubagentBridge } from "../slash/slash-bridge.ts";
|
|
34
|
-
import {
|
|
60
|
+
import {
|
|
61
|
+
clearSlashSnapshots,
|
|
62
|
+
getSlashRenderableSnapshot,
|
|
63
|
+
resolveSlashMessageDetails,
|
|
64
|
+
restoreSlashFinalSnapshots,
|
|
65
|
+
type SlashMessageDetails,
|
|
66
|
+
} from "../slash/slash-live-state.ts";
|
|
35
67
|
import { inspectSubagentStatus } from "../runs/background/run-status.ts";
|
|
36
|
-
import registerSubagentNotify, {
|
|
68
|
+
import registerSubagentNotify, {
|
|
69
|
+
type SubagentNotifyDetails,
|
|
70
|
+
} from "../runs/background/notify.ts";
|
|
37
71
|
import { SUBAGENT_CHILD_ENV } from "../runs/shared/pi-args.ts";
|
|
38
72
|
import { formatDuration, shortenPath } from "../shared/formatters.ts";
|
|
39
73
|
import {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
74
|
+
type Details,
|
|
75
|
+
type ExtensionConfig,
|
|
76
|
+
type SubagentState,
|
|
77
|
+
ASYNC_DIR,
|
|
78
|
+
DEFAULT_ARTIFACT_CONFIG,
|
|
79
|
+
RESULTS_DIR,
|
|
80
|
+
SLASH_RESULT_TYPE,
|
|
81
|
+
SUBAGENT_ASYNC_COMPLETE_EVENT,
|
|
82
|
+
SUBAGENT_ASYNC_STARTED_EVENT,
|
|
83
|
+
SUBAGENT_CONTROL_EVENT,
|
|
84
|
+
WIDGET_KEY,
|
|
51
85
|
} from "../shared/types.ts";
|
|
52
86
|
import {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
87
|
+
clearPendingForegroundControlNotices,
|
|
88
|
+
formatSubagentControlNotice,
|
|
89
|
+
handleSubagentControlNotice,
|
|
90
|
+
SUBAGENT_CONTROL_MESSAGE_TYPE,
|
|
91
|
+
type SubagentControlMessageDetails,
|
|
58
92
|
} from "./control-notices.ts";
|
|
59
93
|
|
|
60
94
|
/**
|
|
@@ -65,29 +99,38 @@ import {
|
|
|
65
99
|
* Falls back to a unique temp directory if no parent session.
|
|
66
100
|
*/
|
|
67
101
|
function getSubagentSessionRoot(parentSessionFile: string | null): string {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
102
|
+
if (parentSessionFile) {
|
|
103
|
+
const baseName = path.basename(parentSessionFile, ".jsonl");
|
|
104
|
+
const sessionsDir = path.dirname(parentSessionFile);
|
|
105
|
+
return path.join(sessionsDir, baseName);
|
|
106
|
+
}
|
|
107
|
+
return fs.mkdtempSync(path.join(os.tmpdir(), "pi-subagent-session-"));
|
|
74
108
|
}
|
|
75
109
|
|
|
76
110
|
function loadConfig(): ExtensionConfig {
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
111
|
+
for (const configPath of getAgentConfigPaths(
|
|
112
|
+
"extensions",
|
|
113
|
+
"subagent",
|
|
114
|
+
"config.json",
|
|
115
|
+
)) {
|
|
116
|
+
try {
|
|
117
|
+
if (fs.existsSync(configPath)) {
|
|
118
|
+
return JSON.parse(
|
|
119
|
+
fs.readFileSync(configPath, "utf-8"),
|
|
120
|
+
) as ExtensionConfig;
|
|
121
|
+
}
|
|
122
|
+
} catch (error) {
|
|
123
|
+
console.error(
|
|
124
|
+
`Failed to load subagent config from '${configPath}':`,
|
|
125
|
+
error,
|
|
126
|
+
);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
return {};
|
|
87
130
|
}
|
|
88
131
|
|
|
89
132
|
function expandTilde(p: string): string {
|
|
90
|
-
|
|
133
|
+
return p.startsWith("~/") ? path.join(os.homedir(), p.slice(2)) : p;
|
|
91
134
|
}
|
|
92
135
|
|
|
93
136
|
/**
|
|
@@ -98,309 +141,380 @@ function expandTilde(p: string): string {
|
|
|
98
141
|
* the directory completely inaccessible to the creating user.
|
|
99
142
|
*/
|
|
100
143
|
function ensureAccessibleDir(dirPath: string): void {
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
144
|
+
fs.mkdirSync(dirPath, { recursive: true });
|
|
145
|
+
try {
|
|
146
|
+
fs.accessSync(dirPath, fs.constants.R_OK | fs.constants.W_OK);
|
|
147
|
+
} catch {
|
|
148
|
+
try {
|
|
149
|
+
fs.rmSync(dirPath, { recursive: true, force: true });
|
|
150
|
+
} catch {
|
|
151
|
+
// Best effort: retry mkdir/access even if cleanup fails.
|
|
152
|
+
}
|
|
153
|
+
fs.mkdirSync(dirPath, { recursive: true });
|
|
154
|
+
fs.accessSync(dirPath, fs.constants.R_OK | fs.constants.W_OK);
|
|
155
|
+
}
|
|
113
156
|
}
|
|
114
157
|
|
|
115
158
|
function isSlashResultRunning(result: { details?: Details }): boolean {
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
159
|
+
return (
|
|
160
|
+
result.details?.progress?.some((entry) => entry.status === "running") ||
|
|
161
|
+
result.details?.results.some(
|
|
162
|
+
(entry) => entry.progress?.status === "running",
|
|
163
|
+
) ||
|
|
164
|
+
false
|
|
165
|
+
);
|
|
119
166
|
}
|
|
120
167
|
|
|
121
168
|
function isSlashResultError(result: { details?: Details }): boolean {
|
|
122
|
-
|
|
169
|
+
return (
|
|
170
|
+
result.details?.results.some(
|
|
171
|
+
(entry) => entry.exitCode !== 0 && entry.progress?.status !== "running",
|
|
172
|
+
) || false
|
|
173
|
+
);
|
|
123
174
|
}
|
|
124
175
|
|
|
125
176
|
function isStaleExtensionContextError(error: unknown): boolean {
|
|
126
|
-
|
|
177
|
+
return (
|
|
178
|
+
error instanceof Error &&
|
|
179
|
+
error.message.includes("Extension context no longer active")
|
|
180
|
+
);
|
|
127
181
|
}
|
|
128
182
|
|
|
129
183
|
function rebuildSlashResultContainer(
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
184
|
+
container: Container,
|
|
185
|
+
result: AgentToolResult<Details>,
|
|
186
|
+
options: { expanded: boolean },
|
|
187
|
+
theme: ExtensionContext["ui"]["theme"],
|
|
134
188
|
): void {
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
189
|
+
container.clear();
|
|
190
|
+
container.addChild(new Spacer(1));
|
|
191
|
+
const boxTheme = isSlashResultRunning(result)
|
|
192
|
+
? "toolPendingBg"
|
|
193
|
+
: isSlashResultError(result)
|
|
194
|
+
? "toolErrorBg"
|
|
195
|
+
: "toolSuccessBg";
|
|
196
|
+
const box = new Box(1, 1, (text: string) => theme.bg(boxTheme, text));
|
|
197
|
+
box.addChild(renderSubagentResult(result, options, theme));
|
|
198
|
+
container.addChild(box);
|
|
141
199
|
}
|
|
142
200
|
|
|
143
201
|
function createSlashResultComponent(
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
202
|
+
details: SlashMessageDetails,
|
|
203
|
+
options: { expanded: boolean },
|
|
204
|
+
theme: ExtensionContext["ui"]["theme"],
|
|
205
|
+
requestRender: () => void,
|
|
148
206
|
): Container {
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
207
|
+
const container = new Container();
|
|
208
|
+
const animationState: { subagentResultAnimationTimer?: ReturnType<typeof setInterval> } = {};
|
|
209
|
+
let lastVersion = -1;
|
|
210
|
+
container.render = (width: number): string[] => {
|
|
211
|
+
const snapshot = getSlashRenderableSnapshot(details);
|
|
212
|
+
syncResultAnimation(snapshot.result, { state: animationState, invalidate: requestRender });
|
|
213
|
+
if (
|
|
214
|
+
snapshot.version !== lastVersion ||
|
|
215
|
+
isSlashResultRunning(snapshot.result)
|
|
216
|
+
) {
|
|
217
|
+
lastVersion = snapshot.version;
|
|
218
|
+
rebuildSlashResultContainer(container, snapshot.result, options, theme);
|
|
219
|
+
}
|
|
220
|
+
return Container.prototype.render.call(container, width);
|
|
221
|
+
};
|
|
222
|
+
return container;
|
|
162
223
|
}
|
|
163
224
|
|
|
164
|
-
function parseSubagentNotifyContent(
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
225
|
+
function parseSubagentNotifyContent(
|
|
226
|
+
content: string,
|
|
227
|
+
): SubagentNotifyDetails | undefined {
|
|
228
|
+
const lines = content.split("\n");
|
|
229
|
+
const header = lines[0] ?? "";
|
|
230
|
+
const match = header.match(
|
|
231
|
+
/^Background task (completed|failed|paused): \*\*(.+?)\*\*(?:\s+(\([^)]*\)))?$/,
|
|
232
|
+
);
|
|
233
|
+
if (!match) return undefined;
|
|
234
|
+
const body = lines.slice(2);
|
|
235
|
+
let sessionIndex = -1;
|
|
236
|
+
for (let i = body.length - 1; i >= 1; i--) {
|
|
237
|
+
if (
|
|
238
|
+
body[i - 1]?.trim() === "" &&
|
|
239
|
+
/^(Session|Session file|Session share error):\s+/.test(body[i]!)
|
|
240
|
+
) {
|
|
241
|
+
sessionIndex = i;
|
|
242
|
+
break;
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
const sessionLine = sessionIndex >= 0 ? body[sessionIndex] : undefined;
|
|
246
|
+
const resultLines = sessionIndex >= 0 ? body.slice(0, sessionIndex) : body;
|
|
247
|
+
const resultPreview = resultLines.join("\n").trim() || "(no output)";
|
|
248
|
+
let sessionLabel: string | undefined;
|
|
249
|
+
let sessionValue: string | undefined;
|
|
250
|
+
if (sessionLine) {
|
|
251
|
+
const separator = sessionLine.indexOf(":");
|
|
252
|
+
sessionLabel = sessionLine.slice(0, separator).toLowerCase();
|
|
253
|
+
sessionValue = sessionLine.slice(separator + 1).trim();
|
|
254
|
+
}
|
|
255
|
+
return {
|
|
256
|
+
agent: match[2]!,
|
|
257
|
+
status: match[1] as SubagentNotifyDetails["status"],
|
|
258
|
+
...(match[3] ? { taskInfo: match[3] } : {}),
|
|
259
|
+
resultPreview,
|
|
260
|
+
...(sessionLabel && sessionValue ? { sessionLabel, sessionValue } : {}),
|
|
261
|
+
};
|
|
194
262
|
}
|
|
195
263
|
|
|
196
264
|
class SubagentControlNoticeComponent implements Component {
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
265
|
+
constructor(
|
|
266
|
+
private readonly details: SubagentControlMessageDetails,
|
|
267
|
+
private readonly theme: ExtensionContext["ui"]["theme"],
|
|
268
|
+
) {}
|
|
269
|
+
|
|
270
|
+
invalidate(): void {}
|
|
271
|
+
|
|
272
|
+
render(width: number): string[] {
|
|
273
|
+
const eventLabel = this.details.event.type.replaceAll("_", " ");
|
|
274
|
+
if (width < 3) return [truncateToWidth(`Subagent ${eventLabel}`, width)];
|
|
275
|
+
const bodyWidth = Math.max(1, width - 2);
|
|
276
|
+
const borderChar = "─";
|
|
277
|
+
const header = ` ⚠ Subagent ${eventLabel}: ${this.details.event.agent} `;
|
|
278
|
+
const headerText = truncateToWidth(header, bodyWidth, "");
|
|
279
|
+
const headerPadding = Math.max(0, bodyWidth - visibleWidth(headerText));
|
|
280
|
+
const lines = [
|
|
281
|
+
this.theme.fg(
|
|
282
|
+
"accent",
|
|
283
|
+
`╭${headerText}${borderChar.repeat(headerPadding)}╮`,
|
|
284
|
+
),
|
|
285
|
+
];
|
|
286
|
+
|
|
287
|
+
for (const line of wrapTextWithAnsi(
|
|
288
|
+
formatSubagentControlNotice(this.details),
|
|
289
|
+
bodyWidth,
|
|
290
|
+
)) {
|
|
291
|
+
const text = truncateToWidth(line, bodyWidth, "");
|
|
292
|
+
const padding = Math.max(0, bodyWidth - visibleWidth(text));
|
|
293
|
+
lines.push(this.theme.fg("accent", `│${text}${" ".repeat(padding)}│`));
|
|
294
|
+
}
|
|
295
|
+
lines.push(this.theme.fg("accent", `╰${borderChar.repeat(bodyWidth)}╯`));
|
|
296
|
+
return lines;
|
|
297
|
+
}
|
|
222
298
|
}
|
|
223
299
|
|
|
224
300
|
export default function registerSubagentExtension(pi: ExtensionAPI): void {
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
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
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
301
|
+
if (getEnvValue(SUBAGENT_CHILD_ENV) === "1") return;
|
|
302
|
+
const globalStore = globalThis as Record<string, unknown>;
|
|
303
|
+
const runtimeCleanupStoreKey = "__piSubagentRuntimeCleanup";
|
|
304
|
+
const previousRuntimeCleanup = globalStore[runtimeCleanupStoreKey];
|
|
305
|
+
if (typeof previousRuntimeCleanup === "function") {
|
|
306
|
+
try {
|
|
307
|
+
previousRuntimeCleanup();
|
|
308
|
+
} catch {
|
|
309
|
+
// Best effort cleanup for stale timers from an older reload.
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
ensureAccessibleDir(RESULTS_DIR);
|
|
314
|
+
ensureAccessibleDir(ASYNC_DIR);
|
|
315
|
+
cleanupOldChainDirs();
|
|
316
|
+
|
|
317
|
+
const config = loadConfig();
|
|
318
|
+
const asyncByDefault = config.asyncByDefault === true;
|
|
319
|
+
const tempArtifactsDir = getArtifactsDir(null);
|
|
320
|
+
cleanupAllArtifactDirs(DEFAULT_ARTIFACT_CONFIG.cleanupDays);
|
|
321
|
+
|
|
322
|
+
const state: SubagentState = {
|
|
323
|
+
baseCwd: "",
|
|
324
|
+
currentSessionId: null,
|
|
325
|
+
asyncJobs: new Map(),
|
|
326
|
+
foregroundRuns: new Map(),
|
|
327
|
+
foregroundControls: new Map(),
|
|
328
|
+
lastForegroundControlId: null,
|
|
329
|
+
pendingForegroundControlNotices: new Map(),
|
|
330
|
+
cleanupTimers: new Map(),
|
|
331
|
+
lastUiContext: null,
|
|
332
|
+
poller: null,
|
|
333
|
+
completionSeen: new Map(),
|
|
334
|
+
watcher: null,
|
|
335
|
+
watcherRestartTimer: null,
|
|
336
|
+
resultFileCoalescer: {
|
|
337
|
+
schedule: () => false,
|
|
338
|
+
clear: () => {},
|
|
339
|
+
},
|
|
340
|
+
};
|
|
341
|
+
|
|
342
|
+
const { startResultWatcher, primeExistingResults, stopResultWatcher } =
|
|
343
|
+
createResultWatcher(pi, state, RESULTS_DIR, 10 * 60 * 1000);
|
|
344
|
+
startResultWatcher();
|
|
345
|
+
primeExistingResults();
|
|
346
|
+
|
|
347
|
+
const runtimeCleanup = () => {
|
|
348
|
+
stopWidgetAnimation();
|
|
349
|
+
stopResultAnimations();
|
|
350
|
+
stopResultWatcher();
|
|
351
|
+
clearPendingForegroundControlNotices(state);
|
|
352
|
+
if (state.poller) {
|
|
353
|
+
clearInterval(state.poller);
|
|
354
|
+
state.poller = null;
|
|
355
|
+
}
|
|
356
|
+
};
|
|
357
|
+
globalStore[runtimeCleanupStoreKey] = runtimeCleanup;
|
|
358
|
+
|
|
359
|
+
const { ensurePoller, handleStarted, handleComplete, resetJobs } =
|
|
360
|
+
createAsyncJobTracker(pi, state, ASYNC_DIR);
|
|
361
|
+
const executor = createSubagentExecutor({
|
|
362
|
+
pi,
|
|
363
|
+
state,
|
|
364
|
+
config,
|
|
365
|
+
asyncByDefault,
|
|
366
|
+
tempArtifactsDir,
|
|
367
|
+
getSubagentSessionRoot,
|
|
368
|
+
expandTilde,
|
|
369
|
+
discoverAgents,
|
|
370
|
+
});
|
|
371
|
+
|
|
372
|
+
pi.registerMessageRenderer<SlashMessageDetails>(
|
|
373
|
+
SLASH_RESULT_TYPE,
|
|
374
|
+
(message, options, theme) => {
|
|
375
|
+
const details = resolveSlashMessageDetails(message.details);
|
|
376
|
+
if (!details) return undefined;
|
|
377
|
+
return createSlashResultComponent(details, options, theme, () => state.lastUiContext?.ui.requestRender?.());
|
|
378
|
+
},
|
|
379
|
+
);
|
|
380
|
+
|
|
381
|
+
pi.registerMessageRenderer<SubagentNotifyDetails>(
|
|
382
|
+
"subagent-notify",
|
|
383
|
+
(message, options, theme) => {
|
|
384
|
+
const content =
|
|
385
|
+
typeof message.content === "string" ? message.content : "";
|
|
386
|
+
const details =
|
|
387
|
+
(message.details as SubagentNotifyDetails | undefined) ??
|
|
388
|
+
parseSubagentNotifyContent(content);
|
|
389
|
+
if (!details) return new Text(content, 0, 0);
|
|
390
|
+
const icon =
|
|
391
|
+
details.status === "completed"
|
|
392
|
+
? theme.fg("success", "✓")
|
|
393
|
+
: details.status === "paused"
|
|
394
|
+
? theme.fg("warning", "■")
|
|
395
|
+
: theme.fg("error", "✗");
|
|
396
|
+
const parts: string[] = [];
|
|
397
|
+
if (details.taskInfo) parts.push(details.taskInfo);
|
|
398
|
+
if (details.durationMs !== undefined)
|
|
399
|
+
parts.push(formatDuration(details.durationMs));
|
|
400
|
+
let text = `${icon} ${theme.bold(details.agent)} ${theme.fg("dim", details.status)}`;
|
|
401
|
+
if (parts.length > 0)
|
|
402
|
+
text += ` ${theme.fg("dim", "·")} ${parts.map((part) => theme.fg("dim", part)).join(` ${theme.fg("dim", "·")} `)}`;
|
|
403
|
+
const trimmedPreview = details.resultPreview.trim();
|
|
404
|
+
const previewLines = options.expanded
|
|
405
|
+
? trimmedPreview.split("\n").filter((line) => line.trim())
|
|
406
|
+
: [trimmedPreview.split("\n", 1)[0] ?? ""].filter((line) =>
|
|
407
|
+
line.trim(),
|
|
408
|
+
);
|
|
409
|
+
for (const line of previewLines.length > 0
|
|
410
|
+
? previewLines
|
|
411
|
+
: ["(no output)"]) {
|
|
412
|
+
text += `\n ${theme.fg("dim", `⎿ ${line}`)}`;
|
|
413
|
+
}
|
|
414
|
+
if (!options.expanded && trimmedPreview.includes("\n")) {
|
|
415
|
+
text += `\n ${theme.fg("dim", "ctrl+o full notification")}`;
|
|
416
|
+
}
|
|
417
|
+
if (details.sessionLabel && details.sessionValue) {
|
|
418
|
+
text += `\n ${theme.fg("muted", `${details.sessionLabel}: ${shortenPath(details.sessionValue)}`)}`;
|
|
419
|
+
}
|
|
420
|
+
return new Text(text, 0, 0);
|
|
421
|
+
},
|
|
422
|
+
);
|
|
423
|
+
|
|
424
|
+
pi.registerMessageRenderer<SubagentControlMessageDetails>(
|
|
425
|
+
SUBAGENT_CONTROL_MESSAGE_TYPE,
|
|
426
|
+
(message, _options, theme) => {
|
|
427
|
+
const details = message.details as
|
|
428
|
+
| SubagentControlMessageDetails
|
|
429
|
+
| undefined;
|
|
430
|
+
if (!details?.event) return undefined;
|
|
431
|
+
const content =
|
|
432
|
+
typeof message.content === "string" ? message.content : undefined;
|
|
433
|
+
return new SubagentControlNoticeComponent(
|
|
434
|
+
{
|
|
435
|
+
...details,
|
|
436
|
+
noticeText: formatSubagentControlNotice(details, content),
|
|
437
|
+
},
|
|
438
|
+
theme,
|
|
439
|
+
);
|
|
440
|
+
},
|
|
441
|
+
);
|
|
442
|
+
|
|
443
|
+
const executeSubagentCollapsed = (
|
|
444
|
+
id: string,
|
|
445
|
+
params: SubagentParamsLike,
|
|
446
|
+
signal: AbortSignal,
|
|
447
|
+
onUpdate: ((result: AgentToolResult<Details>) => void) | undefined,
|
|
448
|
+
ctx: ExtensionContext,
|
|
449
|
+
) => {
|
|
450
|
+
if (ctx.hasUI) ctx.ui.setToolsExpanded(false);
|
|
451
|
+
return executor.execute(id, params, signal, onUpdate, ctx);
|
|
452
|
+
};
|
|
453
|
+
|
|
454
|
+
const slashBridge = registerSlashSubagentBridge({
|
|
455
|
+
events: pi.events,
|
|
456
|
+
getContext: () => state.lastUiContext,
|
|
457
|
+
execute: (id, params, signal, onUpdate, ctx) =>
|
|
458
|
+
executeSubagentCollapsed(id, params, signal, onUpdate, ctx),
|
|
459
|
+
});
|
|
460
|
+
|
|
461
|
+
const promptTemplateBridge = registerPromptTemplateDelegationBridge({
|
|
462
|
+
events: pi.events,
|
|
463
|
+
getContext: () => state.lastUiContext,
|
|
464
|
+
execute: async (requestId, request, signal, ctx, onUpdate) => {
|
|
465
|
+
if (request.tasks && request.tasks.length > 0) {
|
|
466
|
+
return executeSubagentCollapsed(
|
|
467
|
+
requestId,
|
|
468
|
+
{
|
|
469
|
+
tasks: request.tasks,
|
|
470
|
+
context: request.context,
|
|
471
|
+
cwd: request.cwd,
|
|
472
|
+
worktree: request.worktree,
|
|
473
|
+
async: false,
|
|
474
|
+
clarify: false,
|
|
475
|
+
},
|
|
476
|
+
signal,
|
|
477
|
+
onUpdate,
|
|
478
|
+
ctx,
|
|
479
|
+
);
|
|
480
|
+
}
|
|
481
|
+
return executeSubagentCollapsed(
|
|
482
|
+
requestId,
|
|
483
|
+
{
|
|
484
|
+
agent: request.agent,
|
|
485
|
+
task: request.task,
|
|
486
|
+
context: request.context,
|
|
487
|
+
cwd: request.cwd,
|
|
488
|
+
model: request.model,
|
|
489
|
+
async: false,
|
|
490
|
+
clarify: false,
|
|
491
|
+
},
|
|
492
|
+
signal,
|
|
493
|
+
onUpdate,
|
|
494
|
+
ctx,
|
|
495
|
+
);
|
|
496
|
+
},
|
|
497
|
+
});
|
|
498
|
+
|
|
499
|
+
function effectiveParallelTaskCount(
|
|
500
|
+
tasks: Array<{ count?: unknown }> | undefined,
|
|
501
|
+
): number {
|
|
502
|
+
if (!tasks || tasks.length === 0) return 0;
|
|
503
|
+
return tasks.reduce((total, task) => {
|
|
504
|
+
const count =
|
|
505
|
+
typeof task.count === "number" &&
|
|
506
|
+
Number.isInteger(task.count) &&
|
|
507
|
+
task.count >= 1
|
|
508
|
+
? task.count
|
|
509
|
+
: 1;
|
|
510
|
+
return total + count;
|
|
511
|
+
}, 0);
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
const tool: ToolDefinition<typeof SubagentParams, Details> = {
|
|
515
|
+
name: "subagent",
|
|
516
|
+
label: "Subagent",
|
|
517
|
+
description: `Delegate to subagents or manage agent definitions.
|
|
404
518
|
|
|
405
519
|
EXECUTION (use exactly ONE mode):
|
|
406
520
|
• Before executing, use { action: "list" } to inspect configured agents/chains. Only execute agents listed as executable/non-disabled.
|
|
@@ -431,157 +545,169 @@ CONTROL:
|
|
|
431
545
|
|
|
432
546
|
DIAGNOSTICS:
|
|
433
547
|
• { action: "doctor" } - read-only report for runtime paths, discovery, sessions, and intercom`,
|
|
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
|
-
|
|
548
|
+
parameters: SubagentParams,
|
|
549
|
+
|
|
550
|
+
execute(id, params, signal, onUpdate, ctx) {
|
|
551
|
+
return executeSubagentCollapsed(id, params, signal, onUpdate, ctx);
|
|
552
|
+
},
|
|
553
|
+
|
|
554
|
+
renderCall(args, theme) {
|
|
555
|
+
if (args.action) {
|
|
556
|
+
const target = args.agent || args.chainName || "";
|
|
557
|
+
return new Text(
|
|
558
|
+
`${theme.fg("toolTitle", theme.bold("subagent "))}${args.action}${target ? ` ${theme.fg("accent", target)}` : ""}`,
|
|
559
|
+
0,
|
|
560
|
+
0,
|
|
561
|
+
);
|
|
562
|
+
}
|
|
563
|
+
const isParallel = (args.tasks?.length ?? 0) > 0;
|
|
564
|
+
const parallelCount = effectiveParallelTaskCount(
|
|
565
|
+
args.tasks as Array<{ count?: unknown }> | undefined,
|
|
566
|
+
);
|
|
567
|
+
const asyncLabel =
|
|
568
|
+
args.async === true && args.clarify !== true && !isParallel
|
|
569
|
+
? theme.fg("warning", " [async]")
|
|
570
|
+
: "";
|
|
571
|
+
if (args.chain?.length)
|
|
572
|
+
return new Text(
|
|
573
|
+
`${theme.fg("toolTitle", theme.bold("subagent "))}chain (${args.chain.length})${asyncLabel}`,
|
|
574
|
+
0,
|
|
575
|
+
0,
|
|
576
|
+
);
|
|
577
|
+
if (isParallel)
|
|
578
|
+
return new Text(
|
|
579
|
+
`${theme.fg("toolTitle", theme.bold("subagent "))}parallel (${parallelCount})`,
|
|
580
|
+
0,
|
|
581
|
+
0,
|
|
582
|
+
);
|
|
583
|
+
return new Text(
|
|
584
|
+
`${theme.fg("toolTitle", theme.bold("subagent "))}${theme.fg("accent", args.agent || "?")}${asyncLabel}`,
|
|
585
|
+
0,
|
|
586
|
+
0,
|
|
587
|
+
);
|
|
588
|
+
},
|
|
589
|
+
|
|
590
|
+
renderResult(result, options, theme, context) {
|
|
591
|
+
syncResultAnimation(result, context);
|
|
592
|
+
return renderSubagentResult(result, options, theme);
|
|
593
|
+
},
|
|
594
|
+
};
|
|
595
|
+
|
|
596
|
+
pi.registerTool(tool);
|
|
597
|
+
registerSlashCommands(pi, state);
|
|
598
|
+
|
|
599
|
+
const eventUnsubscribeStoreKey = "__piSubagentEventUnsubscribes";
|
|
600
|
+
const controlNoticeSeenStoreKey = "__piSubagentVisibleControlNotices";
|
|
601
|
+
const previousEventUnsubscribes = globalStore[eventUnsubscribeStoreKey];
|
|
602
|
+
if (Array.isArray(previousEventUnsubscribes)) {
|
|
603
|
+
for (const unsubscribe of previousEventUnsubscribes) {
|
|
604
|
+
if (typeof unsubscribe !== "function") continue;
|
|
605
|
+
try {
|
|
606
|
+
unsubscribe();
|
|
607
|
+
} catch {
|
|
608
|
+
// Best effort cleanup for stale handlers from an older reload.
|
|
609
|
+
}
|
|
610
|
+
}
|
|
611
|
+
}
|
|
612
|
+
registerSubagentNotify(pi);
|
|
613
|
+
|
|
614
|
+
const existingVisibleControlNotices = globalStore[controlNoticeSeenStoreKey];
|
|
615
|
+
const visibleControlNotices =
|
|
616
|
+
existingVisibleControlNotices instanceof Set
|
|
617
|
+
? (existingVisibleControlNotices as Set<string>)
|
|
618
|
+
: new Set<string>();
|
|
619
|
+
globalStore[controlNoticeSeenStoreKey] = visibleControlNotices;
|
|
620
|
+
const controlEventHandler = (payload: unknown) => {
|
|
621
|
+
handleSubagentControlNotice({
|
|
622
|
+
pi,
|
|
623
|
+
state,
|
|
624
|
+
visibleControlNotices,
|
|
625
|
+
details: payload as SubagentControlMessageDetails,
|
|
626
|
+
});
|
|
627
|
+
};
|
|
628
|
+
const eventUnsubscribes = [
|
|
629
|
+
pi.events.on(SUBAGENT_ASYNC_STARTED_EVENT, handleStarted),
|
|
630
|
+
pi.events.on(SUBAGENT_ASYNC_COMPLETE_EVENT, handleComplete),
|
|
631
|
+
pi.events.on(SUBAGENT_CONTROL_EVENT, controlEventHandler),
|
|
632
|
+
];
|
|
633
|
+
globalStore[eventUnsubscribeStoreKey] = eventUnsubscribes;
|
|
634
|
+
|
|
635
|
+
pi.on("tool_result", (event, ctx) => {
|
|
636
|
+
if (event.toolName !== "subagent") return;
|
|
637
|
+
if (!ctx.hasUI) return;
|
|
638
|
+
state.lastUiContext = ctx;
|
|
639
|
+
if (state.asyncJobs.size > 0) {
|
|
640
|
+
renderWidget(ctx, Array.from(state.asyncJobs.values()));
|
|
641
|
+
ctx.ui.requestRender?.();
|
|
642
|
+
ensurePoller();
|
|
643
|
+
}
|
|
644
|
+
});
|
|
645
|
+
|
|
646
|
+
const cleanupSessionArtifacts = (ctx: ExtensionContext) => {
|
|
647
|
+
try {
|
|
648
|
+
const sessionFile = ctx.sessionManager.getSessionFile();
|
|
649
|
+
if (sessionFile) {
|
|
650
|
+
cleanupOldArtifacts(
|
|
651
|
+
getArtifactsDir(sessionFile),
|
|
652
|
+
DEFAULT_ARTIFACT_CONFIG.cleanupDays,
|
|
653
|
+
);
|
|
654
|
+
}
|
|
655
|
+
} catch {
|
|
656
|
+
// Cleanup failures should not block session lifecycle events.
|
|
657
|
+
}
|
|
658
|
+
};
|
|
659
|
+
|
|
660
|
+
const resetSessionState = (ctx: ExtensionContext) => {
|
|
661
|
+
state.baseCwd = ctx.cwd;
|
|
662
|
+
state.currentSessionId = resolveCurrentSessionId(ctx.sessionManager);
|
|
663
|
+
state.lastUiContext = ctx;
|
|
664
|
+
cleanupSessionArtifacts(ctx);
|
|
665
|
+
clearPendingForegroundControlNotices(state);
|
|
666
|
+
resetJobs(ctx);
|
|
667
|
+
restoreSlashFinalSnapshots(ctx.sessionManager.getEntries());
|
|
668
|
+
primeExistingResults();
|
|
669
|
+
};
|
|
670
|
+
|
|
671
|
+
pi.on("session_start", (_event, ctx) => {
|
|
672
|
+
resetSessionState(ctx);
|
|
673
|
+
});
|
|
674
|
+
|
|
675
|
+
pi.on("session_shutdown", () => {
|
|
676
|
+
for (const unsubscribe of eventUnsubscribes) {
|
|
677
|
+
try {
|
|
678
|
+
unsubscribe();
|
|
679
|
+
} catch {
|
|
680
|
+
// Best effort cleanup during shutdown.
|
|
681
|
+
}
|
|
682
|
+
}
|
|
683
|
+
if (globalStore[eventUnsubscribeStoreKey] === eventUnsubscribes) {
|
|
684
|
+
delete globalStore[eventUnsubscribeStoreKey];
|
|
685
|
+
}
|
|
686
|
+
stopResultWatcher();
|
|
687
|
+
if (state.poller) clearInterval(state.poller);
|
|
688
|
+
state.poller = null;
|
|
689
|
+
clearPendingForegroundControlNotices(state);
|
|
690
|
+
for (const timer of state.cleanupTimers.values()) {
|
|
691
|
+
clearTimeout(timer);
|
|
692
|
+
}
|
|
693
|
+
state.cleanupTimers.clear();
|
|
694
|
+
state.asyncJobs.clear();
|
|
695
|
+
clearSlashSnapshots();
|
|
696
|
+
slashBridge.cancelAll();
|
|
697
|
+
slashBridge.dispose();
|
|
698
|
+
promptTemplateBridge.cancelAll();
|
|
699
|
+
promptTemplateBridge.dispose();
|
|
700
|
+
stopWidgetAnimation();
|
|
701
|
+
stopResultAnimations();
|
|
702
|
+
if (globalStore[runtimeCleanupStoreKey] === runtimeCleanup) {
|
|
703
|
+
delete globalStore[runtimeCleanupStoreKey];
|
|
704
|
+
}
|
|
705
|
+
try {
|
|
706
|
+
if (state.lastUiContext?.hasUI) {
|
|
707
|
+
state.lastUiContext.ui.setWidget(WIDGET_KEY, undefined);
|
|
708
|
+
}
|
|
709
|
+
} catch (error) {
|
|
710
|
+
if (!isStaleExtensionContextError(error)) throw error;
|
|
711
|
+
}
|
|
712
|
+
});
|
|
587
713
|
}
|