@bastani/atomic 0.9.5-alpha.9 → 0.9.5
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 +106 -0
- package/README.md +2 -2
- package/dist/builtin/cursor/CHANGELOG.md +12 -0
- package/dist/builtin/cursor/package.json +3 -3
- package/dist/builtin/cursor/src/model-mapper.ts +6 -3
- package/dist/builtin/intercom/CHANGELOG.md +37 -0
- package/dist/builtin/intercom/README.md +4 -2
- package/dist/builtin/intercom/broker/broker.ts +6 -114
- package/dist/builtin/intercom/broker/client.ts +29 -54
- package/dist/builtin/intercom/broker/delivered-message-cache.ts +44 -0
- package/dist/builtin/intercom/broker/pending-send-registry.ts +142 -0
- package/dist/builtin/intercom/broker/send-handler.ts +106 -0
- package/dist/builtin/intercom/broker/send-signature.ts +37 -0
- package/dist/builtin/intercom/foreground-detach-handoff.ts +136 -0
- package/dist/builtin/intercom/index-heavy.ts +49 -53
- package/dist/builtin/intercom/index.ts +278 -262
- package/dist/builtin/intercom/lazy-heavy-proxy.ts +114 -0
- package/dist/builtin/intercom/lazy-subagent-ack.ts +20 -0
- package/dist/builtin/intercom/lazy-tool-execution.ts +39 -0
- package/dist/builtin/intercom/lifecycle-lease.ts +51 -0
- package/dist/builtin/intercom/lifecycle.ts +37 -20
- package/dist/builtin/intercom/package.json +3 -6
- package/dist/builtin/intercom/reply-routing.ts +17 -0
- package/dist/builtin/intercom/subagent-relay.ts +58 -12
- package/dist/builtin/intercom/types.ts +3 -3
- package/dist/builtin/mcp/CHANGELOG.md +27 -0
- package/dist/builtin/mcp/OAUTH.md +1 -0
- package/dist/builtin/mcp/README.md +4 -0
- package/dist/builtin/mcp/apps-cancellation.ts +32 -0
- package/dist/builtin/mcp/call-tool-result.ts +9 -0
- package/dist/builtin/mcp/caller-wait.ts +50 -0
- package/dist/builtin/mcp/command-registration.ts +82 -0
- package/dist/builtin/mcp/direct-tool-executor.ts +279 -0
- package/dist/builtin/mcp/direct-tools.ts +6 -239
- package/dist/builtin/mcp/host-html-template.ts +4 -2
- package/dist/builtin/mcp/index.ts +258 -250
- package/dist/builtin/mcp/init.ts +96 -87
- package/dist/builtin/mcp/mcp-auth-flow.ts +247 -237
- package/dist/builtin/mcp/mcp-callback-server.ts +89 -68
- package/dist/builtin/mcp/mcp-oauth-provider.ts +23 -1
- package/dist/builtin/mcp/metadata-hydration.ts +21 -6
- package/dist/builtin/mcp/package.json +3 -3
- package/dist/builtin/mcp/proxy-auth.ts +4 -4
- package/dist/builtin/mcp/proxy-call.ts +111 -40
- package/dist/builtin/mcp/proxy-connect.ts +35 -15
- package/dist/builtin/mcp/proxy-info-modes.ts +49 -19
- package/dist/builtin/mcp/proxy-modes.ts +3 -3
- package/dist/builtin/mcp/session-cleanup-barrier.ts +43 -0
- package/dist/builtin/mcp/state-lease.ts +12 -0
- package/dist/builtin/mcp/ui-server.ts +8 -8
- package/dist/builtin/mcp/ui-session.ts +9 -18
- package/dist/builtin/subagents/CHANGELOG.md +66 -0
- package/dist/builtin/subagents/README.md +30 -29
- package/dist/builtin/subagents/agents/code-simplifier.md +2 -2
- package/dist/builtin/subagents/agents/codebase-analyzer.md +2 -2
- package/dist/builtin/subagents/agents/codebase-locator.md +2 -2
- package/dist/builtin/subagents/agents/codebase-online-researcher.md +2 -2
- package/dist/builtin/subagents/agents/codebase-pattern-finder.md +2 -2
- package/dist/builtin/subagents/agents/codebase-research-analyzer.md +2 -2
- package/dist/builtin/subagents/agents/codebase-research-locator.md +2 -2
- package/dist/builtin/subagents/agents/debugger.md +2 -2
- package/dist/builtin/subagents/agents/worker.md +2 -2
- package/dist/builtin/subagents/package.json +5 -5
- package/dist/builtin/subagents/prompts/review-loop.md +1 -1
- package/dist/builtin/subagents/skills/subagent/SKILL.md +37 -36
- package/dist/builtin/subagents/src/extension/api-lifecycle.ts +64 -0
- package/dist/builtin/subagents/src/extension/fanout-child.ts +44 -51
- package/dist/builtin/subagents/src/extension/index.ts +287 -307
- package/dist/builtin/subagents/src/extension/prompt-guidance.ts +7 -10
- package/dist/builtin/subagents/src/extension/schemas.ts +22 -5
- package/dist/builtin/subagents/src/extension/tool-description.ts +29 -0
- package/dist/builtin/subagents/src/intercom/intercom-bridge.ts +13 -2
- package/dist/builtin/subagents/src/intercom/result-intercom.ts +4 -4
- package/dist/builtin/subagents/src/runs/background/async-event-journal.ts +106 -0
- package/dist/builtin/subagents/src/runs/background/async-execution-common.ts +3 -2
- package/dist/builtin/subagents/src/runs/background/async-execution-single.ts +13 -2
- package/dist/builtin/subagents/src/runs/background/async-execution-types.ts +3 -0
- package/dist/builtin/subagents/src/runs/background/async-job-tracker.ts +1 -1
- package/dist/builtin/subagents/src/runs/background/completion-claims.ts +189 -0
- package/dist/builtin/subagents/src/runs/background/completion-dedupe.ts +44 -7
- package/dist/builtin/subagents/src/runs/background/completion-notification.ts +34 -0
- package/dist/builtin/subagents/src/runs/background/notify.ts +72 -22
- package/dist/builtin/subagents/src/runs/background/result-delivery-processor.ts +232 -0
- package/dist/builtin/subagents/src/runs/background/result-file-claims.ts +151 -0
- package/dist/builtin/subagents/src/runs/background/result-quarantine.ts +72 -0
- package/dist/builtin/subagents/src/runs/background/result-retry-scheduler.ts +48 -0
- package/dist/builtin/subagents/src/runs/background/result-status.ts +81 -0
- package/dist/builtin/subagents/src/runs/background/result-watcher-data.ts +59 -0
- package/dist/builtin/subagents/src/runs/background/result-watcher.ts +172 -238
- package/dist/builtin/subagents/src/runs/background/run-id-resolver.ts +3 -2
- package/dist/builtin/subagents/src/runs/background/stale-run-reconciler.ts +73 -14
- package/dist/builtin/subagents/src/runs/background/subagent-runner-streaming.ts +17 -13
- package/dist/builtin/subagents/src/runs/background/top-level-async.ts +1 -2
- package/dist/builtin/subagents/src/runs/foreground/chain-execution-dynamic-step.ts +1 -0
- package/dist/builtin/subagents/src/runs/foreground/chain-execution-parallel-runner.ts +1 -0
- package/dist/builtin/subagents/src/runs/foreground/chain-execution-parallel-step.ts +1 -0
- package/dist/builtin/subagents/src/runs/foreground/chain-execution-sequential-step.ts +7 -9
- package/dist/builtin/subagents/src/runs/foreground/chain-execution-types.ts +3 -13
- package/dist/builtin/subagents/src/runs/foreground/chain-execution.ts +2 -15
- package/dist/builtin/subagents/src/runs/foreground/execution-attempt-finalize.ts +2 -2
- package/dist/builtin/subagents/src/runs/foreground/execution-attempt.ts +53 -44
- package/dist/builtin/subagents/src/runs/foreground/execution-detach-reservations.ts +48 -0
- package/dist/builtin/subagents/src/runs/foreground/execution-detach-route.ts +17 -0
- package/dist/builtin/subagents/src/runs/foreground/execution-run-sync.ts +39 -26
- package/dist/builtin/subagents/src/runs/foreground/subagent-executor-async.ts +3 -1
- package/dist/builtin/subagents/src/runs/foreground/subagent-executor-chain.ts +3 -51
- package/dist/builtin/subagents/src/runs/foreground/subagent-executor-context.ts +6 -11
- package/dist/builtin/subagents/src/runs/foreground/subagent-executor-input.ts +11 -2
- package/dist/builtin/subagents/src/runs/foreground/subagent-executor-parallel-task.ts +2 -0
- package/dist/builtin/subagents/src/runs/foreground/subagent-executor-parallel.ts +5 -112
- package/dist/builtin/subagents/src/runs/foreground/subagent-executor-resume.ts +2 -0
- package/dist/builtin/subagents/src/runs/foreground/subagent-executor-single.ts +68 -118
- package/dist/builtin/subagents/src/runs/foreground/subagent-executor-status.ts +79 -7
- package/dist/builtin/subagents/src/runs/foreground/subagent-executor-types.ts +2 -2
- package/dist/builtin/subagents/src/runs/foreground/subagent-executor.ts +3 -0
- package/dist/builtin/subagents/src/runs/shared/pi-args.ts +2 -2
- package/dist/builtin/subagents/src/runs/shared/pi-spawn.ts +27 -11
- package/dist/builtin/subagents/src/shared/artifacts.ts +22 -11
- package/dist/builtin/subagents/src/shared/event-jsonl-writer.ts +294 -0
- package/dist/builtin/subagents/src/shared/exclusive-file-publication.ts +44 -0
- package/dist/builtin/subagents/src/shared/jsonl-writer.ts +1 -0
- package/dist/builtin/subagents/src/shared/model-info.ts +2 -2
- package/dist/builtin/subagents/src/shared/settings.ts +20 -10
- package/dist/builtin/subagents/src/shared/types-async.ts +3 -1
- package/dist/builtin/subagents/src/shared/types-config.ts +2 -0
- package/dist/builtin/subagents/src/shared/types-runtime.ts +3 -2
- package/dist/builtin/subagents/src/slash/slash-commands.ts +9 -12
- package/dist/builtin/subagents/src/slash/slash-live-state.ts +63 -32
- package/dist/builtin/subagents/src/tui/render-result.ts +7 -0
- package/dist/builtin/subagents/src/tui/render-stable-output.ts +1 -0
- package/dist/builtin/subagents/src/tui/render-widget.ts +128 -89
- package/dist/builtin/web-access/CHANGELOG.md +28 -0
- package/dist/builtin/web-access/README.md +4 -0
- package/dist/builtin/web-access/content-tools.ts +8 -3
- package/dist/builtin/web-access/index-heavy.ts +1 -1
- package/dist/builtin/web-access/index.ts +190 -46
- package/dist/builtin/web-access/lifecycle-lease.ts +38 -0
- package/dist/builtin/web-access/package.json +2 -2
- package/dist/builtin/web-access/result-renderers.ts +1 -1
- package/dist/builtin/web-access/summary-review.ts +1 -1
- package/dist/builtin/web-access/web-search-activity.ts +1 -1
- package/dist/builtin/web-access/web-search-return.ts +7 -0
- package/dist/builtin/web-access/web-search-summary.ts +1 -1
- package/dist/builtin/web-access/web-search-tool.ts +4 -2
- package/dist/builtin/workflows/CHANGELOG.md +68 -0
- package/dist/builtin/workflows/README.md +4 -4
- package/dist/builtin/workflows/builtin/deep-research-codebase-utils.ts +27 -4
- package/dist/builtin/workflows/builtin/goal-runner.ts +47 -26
- package/dist/builtin/workflows/builtin/open-claude-design-runner.ts +10 -0
- package/dist/builtin/workflows/builtin/ralph-core.ts +9 -9
- package/dist/builtin/workflows/builtin/ralph-models.ts +71 -36
- package/dist/builtin/workflows/builtin/ralph-runner.ts +20 -31
- package/dist/builtin/workflows/package.json +2 -2
- package/dist/builtin/workflows/src/durable/stage-primitive.ts +2 -1
- package/dist/builtin/workflows/src/engine/primitives/task.ts +2 -1
- package/dist/builtin/workflows/src/extension/workflow-prompts.ts +17 -22
- package/dist/builtin/workflows/src/extension/workflow-schema.ts +15 -2
- package/dist/builtin/workflows/src/runs/foreground/executor-hil.ts +1 -2
- package/dist/builtin/workflows/src/runs/shared/model-fallback-candidates.ts +1 -1
- package/dist/builtin/workflows/src/shared/authoring-contract-stage.d.ts +2 -2
- package/dist/builtin/workflows/src/shared/authoring-contract-stage.ts +2 -2
- package/dist/builtin/workflows/src/shared/resume-continuation.ts +2 -0
- package/dist/builtin/workflows/src/tui/stage-chat-view-archive-history.ts +1 -23
- package/dist/builtin/workflows/src/tui/stage-chat-view-footer-status.ts +54 -9
- package/dist/builtin/workflows/src/tui/stage-chat-view.ts +5 -2
- package/dist/cli/args.d.ts.map +1 -1
- package/dist/cli/args.js +2 -2
- package/dist/cli/args.js.map +1 -1
- package/dist/core/agent-session-events.d.ts.map +1 -1
- package/dist/core/agent-session-events.js +2 -1
- package/dist/core/agent-session-events.js.map +1 -1
- package/dist/core/agent-session-message-queue.d.ts.map +1 -1
- package/dist/core/agent-session-message-queue.js +1 -1
- package/dist/core/agent-session-message-queue.js.map +1 -1
- package/dist/core/agent-session-prompt.d.ts.map +1 -1
- package/dist/core/agent-session-prompt.js +1 -1
- package/dist/core/agent-session-prompt.js.map +1 -1
- package/dist/core/agent-session-retry.d.ts.map +1 -1
- package/dist/core/agent-session-retry.js +1 -1
- package/dist/core/agent-session-retry.js.map +1 -1
- package/dist/core/agent-session-services.d.ts.map +1 -1
- package/dist/core/agent-session-services.js +3 -2
- package/dist/core/agent-session-services.js.map +1 -1
- package/dist/core/agent-session-types.d.ts.map +1 -1
- package/dist/core/agent-session-types.js +1 -1
- package/dist/core/agent-session-types.js.map +1 -1
- package/dist/core/anthropic-thinking-guard.d.ts +5 -5
- package/dist/core/anthropic-thinking-guard.d.ts.map +1 -1
- package/dist/core/anthropic-thinking-guard.js +42 -32
- package/dist/core/anthropic-thinking-guard.js.map +1 -1
- package/dist/core/atomic-guide-command.d.ts.map +1 -1
- package/dist/core/atomic-guide-command.js +15 -15
- package/dist/core/atomic-guide-command.js.map +1 -1
- package/dist/core/auth-storage.d.ts.map +1 -1
- package/dist/core/auth-storage.js +14 -9
- package/dist/core/auth-storage.js.map +1 -1
- package/dist/core/compaction/compaction.d.ts +2 -0
- package/dist/core/compaction/compaction.d.ts.map +1 -1
- package/dist/core/compaction/compaction.js +79 -46
- package/dist/core/compaction/compaction.js.map +1 -1
- package/dist/core/compaction/context-assistant-turns.d.ts +42 -0
- package/dist/core/compaction/context-assistant-turns.d.ts.map +1 -0
- package/dist/core/compaction/context-assistant-turns.js +87 -0
- package/dist/core/compaction/context-assistant-turns.js.map +1 -0
- package/dist/core/compaction/context-compaction-critical.d.ts +1 -1
- package/dist/core/compaction/context-compaction-critical.d.ts.map +1 -1
- package/dist/core/compaction/context-compaction-critical.js +2 -2
- package/dist/core/compaction/context-compaction-critical.js.map +1 -1
- package/dist/core/compaction/context-compaction-eviction-alternates.d.ts +18 -0
- package/dist/core/compaction/context-compaction-eviction-alternates.d.ts.map +1 -0
- package/dist/core/compaction/context-compaction-eviction-alternates.js +186 -0
- package/dist/core/compaction/context-compaction-eviction-alternates.js.map +1 -0
- package/dist/core/compaction/context-compaction-eviction.d.ts +10 -2
- package/dist/core/compaction/context-compaction-eviction.d.ts.map +1 -1
- package/dist/core/compaction/context-compaction-eviction.js +196 -146
- package/dist/core/compaction/context-compaction-eviction.js.map +1 -1
- package/dist/core/compaction/context-compaction-prompt.d.ts.map +1 -1
- package/dist/core/compaction/context-compaction-prompt.js +1 -1
- package/dist/core/compaction/context-compaction-prompt.js.map +1 -1
- package/dist/core/compaction/context-compaction-types.d.ts +2 -0
- package/dist/core/compaction/context-compaction-types.d.ts.map +1 -1
- package/dist/core/compaction/context-compaction-types.js.map +1 -1
- package/dist/core/compaction/context-deletion-application.d.ts +5 -4
- package/dist/core/compaction/context-deletion-application.d.ts.map +1 -1
- package/dist/core/compaction/context-deletion-application.js +17 -15
- package/dist/core/compaction/context-deletion-application.js.map +1 -1
- package/dist/core/compaction/context-deletion-store.d.ts.map +1 -1
- package/dist/core/compaction/context-deletion-store.js +1 -1
- package/dist/core/compaction/context-deletion-store.js.map +1 -1
- package/dist/core/compaction/context-deletion-targets.d.ts +2 -1
- package/dist/core/compaction/context-deletion-targets.d.ts.map +1 -1
- package/dist/core/compaction/context-deletion-targets.js +36 -31
- package/dist/core/compaction/context-deletion-targets.js.map +1 -1
- package/dist/core/compaction/context-deletion-tool-helpers.d.ts.map +1 -1
- package/dist/core/compaction/context-deletion-tool-helpers.js +116 -43
- package/dist/core/compaction/context-deletion-tool-helpers.js.map +1 -1
- package/dist/core/compaction/context-transcript-analysis.d.ts +1 -2
- package/dist/core/compaction/context-transcript-analysis.d.ts.map +1 -1
- package/dist/core/compaction/context-transcript-analysis.js +33 -37
- package/dist/core/compaction/context-transcript-analysis.js.map +1 -1
- package/dist/core/copilot-model-synthesis.d.ts.map +1 -1
- package/dist/core/copilot-model-synthesis.js +3 -1
- package/dist/core/copilot-model-synthesis.js.map +1 -1
- package/dist/core/extensions/provider-types.d.ts +2 -7
- package/dist/core/extensions/provider-types.d.ts.map +1 -1
- package/dist/core/extensions/provider-types.js.map +1 -1
- package/dist/core/messages.d.ts +9 -0
- package/dist/core/messages.d.ts.map +1 -1
- package/dist/core/messages.js +100 -18
- package/dist/core/messages.js.map +1 -1
- package/dist/core/model-registry-builtins.d.ts.map +1 -1
- package/dist/core/model-registry-builtins.js +5 -0
- package/dist/core/model-registry-builtins.js.map +1 -1
- package/dist/core/model-registry-custom-loader.d.ts.map +1 -1
- package/dist/core/model-registry-custom-loader.js +49 -8
- package/dist/core/model-registry-custom-loader.js.map +1 -1
- package/dist/core/model-registry-dynamic.d.ts.map +1 -1
- package/dist/core/model-registry-dynamic.js +11 -5
- package/dist/core/model-registry-dynamic.js.map +1 -1
- package/dist/core/model-registry-loader.d.ts.map +1 -1
- package/dist/core/model-registry-loader.js +8 -0
- package/dist/core/model-registry-loader.js.map +1 -1
- package/dist/core/model-registry-schemas.d.ts +93 -8
- package/dist/core/model-registry-schemas.d.ts.map +1 -1
- package/dist/core/model-registry-schemas.js +24 -12
- package/dist/core/model-registry-schemas.js.map +1 -1
- package/dist/core/model-registry-types.d.ts +7 -6
- package/dist/core/model-registry-types.d.ts.map +1 -1
- package/dist/core/model-registry-types.js.map +1 -1
- package/dist/core/model-registry.d.ts +5 -0
- package/dist/core/model-registry.d.ts.map +1 -1
- package/dist/core/model-registry.js +23 -0
- package/dist/core/model-registry.js.map +1 -1
- package/dist/core/model-resolver-cli.d.ts.map +1 -1
- package/dist/core/model-resolver-cli.js +33 -5
- package/dist/core/model-resolver-cli.js.map +1 -1
- package/dist/core/model-resolver-initial.d.ts +6 -1
- package/dist/core/model-resolver-initial.d.ts.map +1 -1
- package/dist/core/model-resolver-initial.js +12 -7
- package/dist/core/model-resolver-initial.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 +1 -1
- package/dist/core/model-resolver.js.map +1 -1
- package/dist/core/resource-loader-context-files.d.ts +1 -0
- package/dist/core/resource-loader-context-files.d.ts.map +1 -1
- package/dist/core/resource-loader-context-files.js +13 -10
- package/dist/core/resource-loader-context-files.js.map +1 -1
- package/dist/core/sdk.d.ts.map +1 -1
- package/dist/core/sdk.js +2 -2
- package/dist/core/sdk.js.map +1 -1
- package/dist/core/session-entry-normalization.d.ts +7 -0
- package/dist/core/session-entry-normalization.d.ts.map +1 -0
- package/dist/core/session-entry-normalization.js +14 -0
- package/dist/core/session-entry-normalization.js.map +1 -0
- package/dist/core/session-manager-core.d.ts.map +1 -1
- package/dist/core/session-manager-core.js +1 -0
- package/dist/core/session-manager-core.js.map +1 -1
- package/dist/core/session-manager-history.d.ts +2 -2
- package/dist/core/session-manager-history.d.ts.map +1 -1
- package/dist/core/session-manager-history.js +127 -108
- package/dist/core/session-manager-history.js.map +1 -1
- package/dist/core/settings-manager-basic-accessors.d.ts +2 -2
- package/dist/core/settings-manager-basic-accessors.d.ts.map +1 -1
- package/dist/core/settings-manager-basic-accessors.js.map +1 -1
- package/dist/core/settings-types.d.ts +1 -1
- package/dist/core/settings-types.d.ts.map +1 -1
- package/dist/core/settings-types.js.map +1 -1
- package/dist/core/tools/bash.d.ts.map +1 -1
- package/dist/core/tools/bash.js +11 -8
- package/dist/core/tools/bash.js.map +1 -1
- package/dist/main-session.d.ts.map +1 -1
- package/dist/main-session.js +1 -0
- package/dist/main-session.js.map +1 -1
- package/dist/modes/interactive/components/settings-selector-options.d.ts.map +1 -1
- package/dist/modes/interactive/components/settings-selector-options.js +3 -1
- package/dist/modes/interactive/components/settings-selector-options.js.map +1 -1
- package/dist/modes/interactive/components/thinking-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/thinking-selector.js +2 -1
- package/dist/modes/interactive/components/thinking-selector.js.map +1 -1
- package/dist/modes/interactive/interactive-agent-events.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-agent-events.js +2 -1
- package/dist/modes/interactive/interactive-agent-events.js.map +1 -1
- package/dist/modes/interactive/interactive-child-ordering.d.ts +7 -0
- package/dist/modes/interactive/interactive-child-ordering.d.ts.map +1 -0
- package/dist/modes/interactive/interactive-child-ordering.js +26 -0
- package/dist/modes/interactive/interactive-child-ordering.js.map +1 -0
- package/dist/modes/interactive/interactive-deferred-startup.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-deferred-startup.js +2 -2
- package/dist/modes/interactive/interactive-deferred-startup.js.map +1 -1
- package/dist/modes/interactive/interactive-mode-deps.d.ts +1 -1
- package/dist/modes/interactive/interactive-mode-deps.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode-deps.js +1 -1
- package/dist/modes/interactive/interactive-mode-deps.js.map +1 -1
- package/dist/modes/interactive/interactive-model-routing.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-model-routing.js +8 -3
- package/dist/modes/interactive/interactive-model-routing.js.map +1 -1
- package/dist/modes/interactive/theme/theme-class.d.ts +1 -1
- package/dist/modes/interactive/theme/theme-class.d.ts.map +1 -1
- package/dist/modes/interactive/theme/theme-class.js +2 -0
- package/dist/modes/interactive/theme/theme-class.js.map +1 -1
- package/dist/utils/clipboard-image.d.ts.map +1 -1
- package/dist/utils/clipboard-image.js +3 -0
- package/dist/utils/clipboard-image.js.map +1 -1
- package/docs/changelog.mdx +19 -0
- package/docs/compaction.md +55 -48
- package/docs/custom-provider.md +18 -5
- package/docs/extensions.md +7 -3
- package/docs/models.md +69 -10
- package/docs/providers.md +1 -1
- package/docs/quickstart.md +11 -7
- package/docs/rpc.md +2 -2
- package/docs/sdk.md +1 -1
- package/docs/settings.md +3 -3
- package/docs/subagents.md +36 -5
- package/docs/tools.md +1 -1
- package/docs/usage.md +4 -2
- package/docs/workflows.md +26 -43
- package/examples/extensions/preset.ts +2 -2
- package/examples/extensions/subagent/README.md +2 -2
- package/examples/extensions/subagent/index.ts +1 -2
- package/examples/extensions/subagent/schemas.ts +4 -1
- package/examples/sdk/12-full-control.ts +1 -1
- package/npm-shrinkwrap.json +48 -51
- package/package.json +7 -7
- package/dist/builtin/subagents/src/runs/foreground/chain-clarify-behavior.ts +0 -75
- package/dist/builtin/subagents/src/runs/foreground/chain-clarify-component.ts +0 -202
- package/dist/builtin/subagents/src/runs/foreground/chain-clarify-edit.ts +0 -97
- package/dist/builtin/subagents/src/runs/foreground/chain-clarify-editor.ts +0 -160
- package/dist/builtin/subagents/src/runs/foreground/chain-clarify-frame.ts +0 -72
- package/dist/builtin/subagents/src/runs/foreground/chain-clarify-render-modes.ts +0 -161
- package/dist/builtin/subagents/src/runs/foreground/chain-clarify-render-selectors.ts +0 -203
- package/dist/builtin/subagents/src/runs/foreground/chain-clarify-selectors.ts +0 -234
- package/dist/builtin/subagents/src/runs/foreground/chain-clarify-state.ts +0 -103
- package/dist/builtin/subagents/src/runs/foreground/chain-clarify-types.ts +0 -29
- package/dist/builtin/subagents/src/runs/foreground/chain-clarify.ts +0 -9
- package/dist/builtin/subagents/src/runs/foreground/chain-execution-clarify.ts +0 -117
|
@@ -17,16 +17,18 @@ import { registerSlashCommands } from "../slash/slash-commands.ts";
|
|
|
17
17
|
import { registerPromptTemplateDelegationBridge } from "../slash/prompt-template-bridge.ts";
|
|
18
18
|
import { registerSlashSubagentBridge } from "../slash/slash-bridge.ts";
|
|
19
19
|
import { clearSlashSnapshots, getSlashRenderableSnapshot, resolveSlashMessageDetails, restoreSlashFinalSnapshots, type SlashMessageDetails } from "../slash/slash-live-state.ts";
|
|
20
|
-
import { inspectSubagentStatus } from "../runs/background/run-status.ts";
|
|
21
20
|
import registerSubagentNotify, { type SubagentNotifyDetails } from "../runs/background/notify.ts";
|
|
22
21
|
import { SUBAGENT_CHILD_ENV, SUBAGENT_FANOUT_CHILD_ENV } from "../runs/shared/pi-args.ts";
|
|
23
22
|
import registerFanoutChildSubagentExtension from "./fanout-child.ts";
|
|
24
23
|
import { formatDuration, shortenPath } from "../shared/formatters.ts";
|
|
25
24
|
import { loadConfig } from "./config.ts";
|
|
26
25
|
import { DEFAULT_PROMPT_GUIDANCE } from "./prompt-guidance.ts";
|
|
27
|
-
import {
|
|
26
|
+
import { SUBAGENT_TOOL_DESCRIPTION } from "./tool-description.ts";
|
|
27
|
+
export { SUBAGENT_TOOL_DESCRIPTION } from "./tool-description.ts";
|
|
28
|
+
import { type Details, type SubagentState, ASYNC_DIR, DEFAULT_ARTIFACT_CONFIG, RESULTS_DIR, SLASH_RESULT_TYPE, SUBAGENT_ASYNC_COMPLETE_EVENT, SUBAGENT_ASYNC_STARTED_EVENT, SUBAGENT_CONTROL_EVENT } from "../shared/types.ts";
|
|
28
29
|
import { clearPendingForegroundControlNotices, formatSubagentControlNotice, handleSubagentControlNotice, SUBAGENT_CONTROL_MESSAGE_TYPE, type SubagentControlMessageDetails } from "./control-notices.ts";
|
|
29
30
|
import { createSubagentStartupMaintenance } from "./startup-maintenance.ts";
|
|
31
|
+
import { beginApiLifecycle, getApiScopedSet } from "./api-lifecycle.ts";
|
|
30
32
|
export { loadConfig } from "./config.ts";
|
|
31
33
|
function getSubagentSessionRoot(parentSessionFile: string | null): string {
|
|
32
34
|
if (parentSessionFile) {
|
|
@@ -60,9 +62,6 @@ function isSlashResultRunning(result: { details?: Details }): boolean {
|
|
|
60
62
|
function isSlashResultError(result: { details?: Details }): boolean {
|
|
61
63
|
return result.details?.results.some((entry) => entry.exitCode !== 0 && entry.progress?.status !== "running") || false;
|
|
62
64
|
}
|
|
63
|
-
function isStaleExtensionContextError(error: unknown): boolean {
|
|
64
|
-
return error instanceof Error && error.message.includes("Extension context no longer active");
|
|
65
|
-
}
|
|
66
65
|
type SubagentToolRenderState = SubagentResultRenderState;
|
|
67
66
|
function rebuildSlashResultContainer(
|
|
68
67
|
container: Container,
|
|
@@ -81,13 +80,14 @@ function createSlashResultComponent(
|
|
|
81
80
|
details: SlashMessageDetails,
|
|
82
81
|
options: { expanded: boolean },
|
|
83
82
|
theme: ExtensionContext["ui"]["theme"],
|
|
83
|
+
owner: ExtensionAPI,
|
|
84
84
|
): Container {
|
|
85
85
|
const container = new Container();
|
|
86
86
|
let lastVersion = -1;
|
|
87
87
|
let lastSnapshotNow = 0;
|
|
88
88
|
let pulseFrame = 0;
|
|
89
89
|
container.render = (width: number): string[] => {
|
|
90
|
-
const snapshot = getSlashRenderableSnapshot(details);
|
|
90
|
+
const snapshot = getSlashRenderableSnapshot(details, owner);
|
|
91
91
|
if (snapshot.version !== lastVersion) {
|
|
92
92
|
lastVersion = snapshot.version;
|
|
93
93
|
lastSnapshotNow = Date.now();
|
|
@@ -153,329 +153,309 @@ class SubagentControlNoticeComponent implements Component {
|
|
|
153
153
|
return lines;
|
|
154
154
|
}
|
|
155
155
|
}
|
|
156
|
+
|
|
156
157
|
export default function registerSubagentExtension(pi: ExtensionAPI): void {
|
|
157
158
|
if (getEnvValue(SUBAGENT_CHILD_ENV) === "1") {
|
|
158
159
|
if (getEnvValue(SUBAGENT_FANOUT_CHILD_ENV) === "1") registerFanoutChildSubagentExtension(pi);
|
|
159
160
|
return;
|
|
160
161
|
}
|
|
161
|
-
const
|
|
162
|
-
const
|
|
163
|
-
|
|
164
|
-
|
|
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
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
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
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
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
|
-
|
|
162
|
+
const lifecycle = beginApiLifecycle(pi);
|
|
163
|
+
const registrationFailureCleanups: Array<() => void> = [];
|
|
164
|
+
let runtimeCleanupInstalled = false;
|
|
165
|
+
try {
|
|
166
|
+
ensureAccessibleDir(RESULTS_DIR);
|
|
167
|
+
ensureAccessibleDir(ASYNC_DIR);
|
|
168
|
+
const config = loadConfig();
|
|
169
|
+
const asyncByDefault = config.asyncByDefault === true;
|
|
170
|
+
const tempArtifactsDir = getArtifactsDir(null);
|
|
171
|
+
const state: SubagentState = {
|
|
172
|
+
baseCwd: "",
|
|
173
|
+
currentSessionId: null,
|
|
174
|
+
asyncJobs: new Map(),
|
|
175
|
+
subagentInProgress: false,
|
|
176
|
+
foregroundRuns: new Map(),
|
|
177
|
+
foregroundControls: new Map(),
|
|
178
|
+
lastForegroundControlId: null,
|
|
179
|
+
pendingForegroundControlNotices: new Map(),
|
|
180
|
+
cleanupTimers: new Map(),
|
|
181
|
+
lastUiContext: null,
|
|
182
|
+
poller: null,
|
|
183
|
+
completionSeen: new Map(),
|
|
184
|
+
watcher: null,
|
|
185
|
+
watcherRestartTimer: null,
|
|
186
|
+
resultFileCoalescer: {
|
|
187
|
+
schedule: () => false,
|
|
188
|
+
clear: () => {},
|
|
189
|
+
},
|
|
190
|
+
};
|
|
191
|
+
const maintenance = createSubagentStartupMaintenance(pi, state, {
|
|
192
|
+
resultsDir: RESULTS_DIR,
|
|
193
|
+
artifactCleanupDays: DEFAULT_ARTIFACT_CONFIG.cleanupDays,
|
|
194
|
+
resultTtlMs: 10 * 60 * 1000,
|
|
195
|
+
});
|
|
196
|
+
maintenance.scheduleStartupCleanup();
|
|
197
|
+
registrationFailureCleanups.push(() => maintenance.stop());
|
|
198
|
+
maintenance.startResultWatcherDeferred();
|
|
199
|
+
maintenance.primeExistingResultsDeferred();
|
|
200
|
+
const { ensurePoller, handleStarted, handleComplete, resetJobs, hydrateActiveJobs } = createAsyncJobTracker(pi, state, ASYNC_DIR);
|
|
201
|
+
const executor = createSubagentExecutor({
|
|
202
|
+
pi,
|
|
203
|
+
state,
|
|
204
|
+
config,
|
|
205
|
+
asyncByDefault,
|
|
206
|
+
tempArtifactsDir,
|
|
207
|
+
getSubagentSessionRoot,
|
|
208
|
+
expandTilde,
|
|
209
|
+
discoverAgents,
|
|
210
|
+
});
|
|
211
|
+
pi.registerMessageRenderer<SlashMessageDetails>(SLASH_RESULT_TYPE, (message, options, theme) => {
|
|
212
|
+
const details = resolveSlashMessageDetails(message.details);
|
|
213
|
+
if (!details) return undefined;
|
|
214
|
+
return createSlashResultComponent(details, options, theme, pi);
|
|
215
|
+
});
|
|
216
|
+
pi.registerMessageRenderer<SubagentNotifyDetails>("subagent-notify", (message, options, theme) => {
|
|
217
|
+
const content = typeof message.content === "string" ? message.content : "";
|
|
218
|
+
const details = (message.details as SubagentNotifyDetails | undefined) ?? parseSubagentNotifyContent(content);
|
|
219
|
+
if (!details) return new Text(content, 0, 0);
|
|
220
|
+
const icon = details.status === "completed"
|
|
221
|
+
? theme.fg("success", "✓")
|
|
222
|
+
: details.status === "paused"
|
|
223
|
+
? theme.fg("warning", "■")
|
|
224
|
+
: theme.fg("error", "✗");
|
|
225
|
+
const parts: string[] = [];
|
|
226
|
+
if (details.taskInfo) parts.push(details.taskInfo);
|
|
227
|
+
if (details.durationMs !== undefined) parts.push(formatDuration(details.durationMs));
|
|
228
|
+
let text = `${icon} ${theme.bold(details.agent)} ${theme.fg("dim", details.status)}`;
|
|
229
|
+
if (parts.length > 0) text += ` ${theme.fg("dim", "·")} ${parts.map((part) => theme.fg("dim", part)).join(` ${theme.fg("dim", "·")} `)}`;
|
|
230
|
+
const trimmedPreview = details.resultPreview.trim();
|
|
231
|
+
const previewLines = options.expanded
|
|
232
|
+
? trimmedPreview.split("\n").filter((line) => line.trim())
|
|
233
|
+
: [trimmedPreview.split("\n", 1)[0] ?? ""].filter((line) => line.trim());
|
|
234
|
+
for (const line of previewLines.length > 0 ? previewLines : ["(no output)"]) {
|
|
235
|
+
text += `\n ${theme.fg("dim", `⎿ ${line}`)}`;
|
|
236
|
+
}
|
|
237
|
+
if (!options.expanded && trimmedPreview.includes("\n")) {
|
|
238
|
+
text += `\n ${theme.fg("dim", "ctrl+o full notification")}`;
|
|
239
|
+
}
|
|
240
|
+
if (details.sessionLabel && details.sessionValue) {
|
|
241
|
+
text += `\n ${theme.fg("muted", `${details.sessionLabel}: ${shortenPath(details.sessionValue)}`)}`;
|
|
242
|
+
}
|
|
243
|
+
return new Text(text, 0, 0);
|
|
244
|
+
});
|
|
245
|
+
pi.registerMessageRenderer<SubagentControlMessageDetails>(SUBAGENT_CONTROL_MESSAGE_TYPE, (message, _options, theme) => {
|
|
246
|
+
const details = message.details as SubagentControlMessageDetails | undefined;
|
|
247
|
+
if (!details?.event) return undefined;
|
|
248
|
+
const content = typeof message.content === "string" ? message.content : undefined;
|
|
249
|
+
return new SubagentControlNoticeComponent({ ...details, noticeText: formatSubagentControlNotice(details, content) }, theme);
|
|
250
|
+
});
|
|
251
|
+
const executeSubagentCollapsed = (id: string, params: SubagentParamsLike, signal: AbortSignal, onUpdate: ((result: AgentToolResult<Details>) => void) | undefined, ctx: ExtensionContext) => {
|
|
252
|
+
if (ctx.hasUI) {
|
|
253
|
+
state.lastUiContext = ctx;
|
|
254
|
+
ctx.ui.setToolsExpanded(false);
|
|
255
|
+
}
|
|
256
|
+
return executor.execute(id, params, signal, onUpdate, ctx);
|
|
257
|
+
};
|
|
258
|
+
const slashBridge = registerSlashSubagentBridge({
|
|
259
|
+
events: pi.events,
|
|
260
|
+
getContext: () => state.lastUiContext,
|
|
261
|
+
execute: (id, params, signal, onUpdate, ctx) =>
|
|
262
|
+
executeSubagentCollapsed(id, params, signal, onUpdate, ctx),
|
|
263
|
+
});
|
|
264
|
+
registrationFailureCleanups.push(() => {
|
|
265
|
+
slashBridge.cancelAll();
|
|
266
|
+
slashBridge.dispose();
|
|
267
|
+
});
|
|
268
|
+
const promptTemplateBridge = registerPromptTemplateDelegationBridge({
|
|
269
|
+
events: pi.events,
|
|
270
|
+
getContext: () => state.lastUiContext,
|
|
271
|
+
execute: async (requestId, request, signal, ctx, onUpdate) => {
|
|
272
|
+
if (request.tasks && request.tasks.length > 0) {
|
|
273
|
+
return executeSubagentCollapsed(
|
|
274
|
+
requestId,
|
|
275
|
+
{
|
|
276
|
+
tasks: request.tasks,
|
|
277
|
+
context: request.context,
|
|
278
|
+
cwd: request.cwd,
|
|
279
|
+
worktree: request.worktree,
|
|
280
|
+
async: false,
|
|
281
|
+
},
|
|
282
|
+
signal,
|
|
283
|
+
onUpdate,
|
|
284
|
+
ctx,
|
|
285
|
+
);
|
|
286
|
+
}
|
|
283
287
|
return executeSubagentCollapsed(
|
|
284
288
|
requestId,
|
|
285
289
|
{
|
|
286
|
-
|
|
290
|
+
agent: request.agent,
|
|
291
|
+
task: request.task,
|
|
287
292
|
context: request.context,
|
|
288
293
|
cwd: request.cwd,
|
|
289
|
-
|
|
294
|
+
model: request.model,
|
|
290
295
|
async: false,
|
|
291
|
-
clarify: false,
|
|
292
296
|
},
|
|
293
297
|
signal,
|
|
294
298
|
onUpdate,
|
|
295
299
|
ctx,
|
|
296
300
|
);
|
|
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
|
-
• Use chainName for chain operations; packaged chains also use dotted runtime names
|
|
344
|
-
CONTROL:
|
|
345
|
-
• { action: "status", id: "..." } - inspect an async/background run by id or prefix
|
|
346
|
-
• { action: "interrupt", id?: "..." } - soft-interrupt the current child turn and leave the run paused
|
|
347
|
-
• { action: "resume", id: "...", message: "...", index?: 0 } - follow up with a live async child or revive a completed async/foreground child from its session
|
|
348
|
-
DIAGNOSTICS:
|
|
349
|
-
• { action: "doctor" } - read-only report for runtime paths, discovery, sessions, and intercom`,
|
|
350
|
-
parameters: SubagentParams,
|
|
351
|
-
promptGuidelines: DEFAULT_PROMPT_GUIDANCE,
|
|
352
|
-
execute(id, params, signal, onUpdate, ctx) {
|
|
353
|
-
return executeSubagentCollapsed(id, params, signal, onUpdate, ctx);
|
|
354
|
-
},
|
|
355
|
-
renderCall(args, theme) {
|
|
356
|
-
if (args.action) {
|
|
357
|
-
const target = args.agent || args.chainName || "";
|
|
358
|
-
return new Text(
|
|
359
|
-
`${theme.fg("toolTitle", theme.bold("subagent "))}${args.action}${target ? ` ${theme.fg("accent", target)}` : ""}`,
|
|
360
|
-
0, 0,
|
|
361
|
-
);
|
|
362
|
-
}
|
|
363
|
-
const isParallel = (args.tasks?.length ?? 0) > 0;
|
|
364
|
-
const parallelCount = effectiveParallelTaskCount(args.tasks as Array<{ count?: unknown }> | undefined);
|
|
365
|
-
const asyncLabel = args.async === true && args.clarify !== true && !isParallel ? theme.fg("warning", " [async]") : "";
|
|
366
|
-
if (args.chain?.length)
|
|
367
|
-
return new Text(
|
|
368
|
-
`${theme.fg("toolTitle", theme.bold("subagent "))}chain (${args.chain.length})${asyncLabel}`,
|
|
369
|
-
0,
|
|
370
|
-
0,
|
|
371
|
-
);
|
|
372
|
-
if (isParallel)
|
|
301
|
+
},
|
|
302
|
+
});
|
|
303
|
+
registrationFailureCleanups.push(() => {
|
|
304
|
+
promptTemplateBridge.cancelAll();
|
|
305
|
+
promptTemplateBridge.dispose();
|
|
306
|
+
});
|
|
307
|
+
function effectiveParallelTaskCount(tasks: Array<{ count?: unknown }> | undefined): number {
|
|
308
|
+
if (!tasks || tasks.length === 0) return 0;
|
|
309
|
+
return tasks.reduce((total, task) => {
|
|
310
|
+
const count = typeof task.count === "number" && Number.isInteger(task.count) && task.count >= 1 ? task.count : 1;
|
|
311
|
+
return total + count;
|
|
312
|
+
}, 0);
|
|
313
|
+
}
|
|
314
|
+
const tool: ToolDefinition<typeof SubagentParams, Details, SubagentToolRenderState> = {
|
|
315
|
+
name: "subagent",
|
|
316
|
+
label: "Subagent",
|
|
317
|
+
description: SUBAGENT_TOOL_DESCRIPTION,
|
|
318
|
+
parameters: SubagentParams,
|
|
319
|
+
promptGuidelines: DEFAULT_PROMPT_GUIDANCE,
|
|
320
|
+
execute(id, params, signal, onUpdate, ctx) {
|
|
321
|
+
const executionSignal = signal ?? ctx.signal ?? new AbortController().signal;
|
|
322
|
+
return executeSubagentCollapsed(id, params as SubagentParamsLike, executionSignal, onUpdate, ctx);
|
|
323
|
+
},
|
|
324
|
+
renderCall(args, theme) {
|
|
325
|
+
if (args.action) {
|
|
326
|
+
const target = args.agent || args.chainName || "";
|
|
327
|
+
return new Text(
|
|
328
|
+
`${theme.fg("toolTitle", theme.bold("subagent "))}${args.action}${target ? ` ${theme.fg("accent", target)}` : ""}`,
|
|
329
|
+
0, 0,
|
|
330
|
+
);
|
|
331
|
+
}
|
|
332
|
+
const isParallel = (args.tasks?.length ?? 0) > 0;
|
|
333
|
+
const parallelCount = effectiveParallelTaskCount(args.tasks as Array<{ count?: unknown }> | undefined);
|
|
334
|
+
const asyncLabel = args.async === true ? theme.fg("warning", " [async]") : "";
|
|
335
|
+
if (args.chain?.length)
|
|
336
|
+
return new Text(
|
|
337
|
+
`${theme.fg("toolTitle", theme.bold("subagent "))}chain (${args.chain.length})${asyncLabel}`,
|
|
338
|
+
0,
|
|
339
|
+
0,
|
|
340
|
+
);
|
|
341
|
+
if (isParallel)
|
|
342
|
+
return new Text(
|
|
343
|
+
`${theme.fg("toolTitle", theme.bold("subagent "))}parallel (${parallelCount})${asyncLabel}`,
|
|
344
|
+
0,
|
|
345
|
+
0,
|
|
346
|
+
);
|
|
373
347
|
return new Text(
|
|
374
|
-
`${theme.fg("toolTitle", theme.bold("subagent "))}
|
|
348
|
+
`${theme.fg("toolTitle", theme.bold("subagent "))}${theme.fg("accent", args.agent || "?")}${asyncLabel}`,
|
|
375
349
|
0,
|
|
376
350
|
0,
|
|
377
351
|
);
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
if (
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
352
|
+
},
|
|
353
|
+
renderResult(result, options, theme, context) {
|
|
354
|
+
return renderLiveSubagentResult(result, options, theme, context);
|
|
355
|
+
},
|
|
356
|
+
};
|
|
357
|
+
pi.registerTool(tool);
|
|
358
|
+
registerSlashCommands(pi, state);
|
|
359
|
+
const notifyCleanup = registerSubagentNotify(pi);
|
|
360
|
+
registrationFailureCleanups.push(notifyCleanup);
|
|
361
|
+
const visibleControlNotices = getApiScopedSet(pi, "__piSubagentVisibleControlNoticesByApi");
|
|
362
|
+
const startedEventHandler = (payload: unknown) => {
|
|
363
|
+
if (lifecycle.isCurrent()) handleStarted(payload);
|
|
364
|
+
};
|
|
365
|
+
const completeEventHandler = (payload: unknown) => {
|
|
366
|
+
if (lifecycle.isCurrent()) handleComplete(payload);
|
|
367
|
+
};
|
|
368
|
+
const controlEventHandler = (payload: unknown) => {
|
|
369
|
+
if (!lifecycle.isCurrent()) return;
|
|
370
|
+
handleSubagentControlNotice({
|
|
371
|
+
pi,
|
|
372
|
+
state,
|
|
373
|
+
visibleControlNotices,
|
|
374
|
+
details: payload as SubagentControlMessageDetails,
|
|
375
|
+
});
|
|
376
|
+
};
|
|
377
|
+
const eventUnsubscribes: Array<() => void> = [];
|
|
378
|
+
for (const [event, handler] of [
|
|
379
|
+
[SUBAGENT_ASYNC_STARTED_EVENT, startedEventHandler],
|
|
380
|
+
[SUBAGENT_ASYNC_COMPLETE_EVENT, completeEventHandler],
|
|
381
|
+
[SUBAGENT_CONTROL_EVENT, controlEventHandler],
|
|
382
|
+
] as const) {
|
|
383
|
+
const unsubscribe = pi.events.on(event, handler);
|
|
384
|
+
eventUnsubscribes.push(unsubscribe);
|
|
385
|
+
registrationFailureCleanups.push(unsubscribe);
|
|
400
386
|
}
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
state.baseCwd = ctx.cwd;
|
|
432
|
-
state.currentSessionId = resolveCurrentSessionId(ctx.sessionManager);
|
|
433
|
-
state.lastUiContext = ctx;
|
|
434
|
-
cleanupSessionArtifacts(ctx);
|
|
435
|
-
clearPendingForegroundControlNotices(state);
|
|
436
|
-
resetJobs(ctx);
|
|
437
|
-
hydrateActiveJobs(ctx);
|
|
438
|
-
restoreSlashFinalSnapshots(ctx.sessionManager.getEntries());
|
|
439
|
-
maintenance.primeExistingResultsDeferred();
|
|
440
|
-
};
|
|
441
|
-
pi.on("session_start", (_event, ctx) => {
|
|
442
|
-
resetSessionState(ctx);
|
|
443
|
-
});
|
|
444
|
-
pi.on("session_shutdown", () => {
|
|
445
|
-
for (const unsubscribe of eventUnsubscribes) {
|
|
446
|
-
try {
|
|
447
|
-
unsubscribe();
|
|
448
|
-
} catch {
|
|
387
|
+
let cleaned = false;
|
|
388
|
+
const runtimeCleanup = () => {
|
|
389
|
+
if (cleaned) return;
|
|
390
|
+
cleaned = true;
|
|
391
|
+
const cleanupSteps: Array<() => void> = [
|
|
392
|
+
...eventUnsubscribes,
|
|
393
|
+
notifyCleanup,
|
|
394
|
+
() => maintenance.stop(),
|
|
395
|
+
() => stopWidgetAnimation(undefined, pi),
|
|
396
|
+
() => stopResultAnimations(),
|
|
397
|
+
() => {
|
|
398
|
+
if (state.poller) clearInterval(state.poller);
|
|
399
|
+
state.poller = null;
|
|
400
|
+
},
|
|
401
|
+
() => clearPendingForegroundControlNotices(state),
|
|
402
|
+
...Array.from(state.cleanupTimers.values(), (timer) => () => clearTimeout(timer)),
|
|
403
|
+
() => state.cleanupTimers.clear(),
|
|
404
|
+
() => state.asyncJobs.clear(),
|
|
405
|
+
() => clearSlashSnapshots(pi),
|
|
406
|
+
() => slashBridge.cancelAll(),
|
|
407
|
+
() => slashBridge.dispose(),
|
|
408
|
+
() => promptTemplateBridge.cancelAll(),
|
|
409
|
+
() => promptTemplateBridge.dispose(),
|
|
410
|
+
];
|
|
411
|
+
for (const cleanup of cleanupSteps) {
|
|
412
|
+
try {
|
|
413
|
+
cleanup();
|
|
414
|
+
} catch {
|
|
415
|
+
// Cleanup is exhaustive and best effort so later owned resources release.
|
|
416
|
+
}
|
|
449
417
|
}
|
|
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
|
-
|
|
418
|
+
};
|
|
419
|
+
lifecycle.setCleanup(runtimeCleanup);
|
|
420
|
+
runtimeCleanupInstalled = true;
|
|
421
|
+
pi.on("tool_result", (event, ctx) => {
|
|
422
|
+
if (!lifecycle.isCurrent() || event.toolName !== "subagent") return;
|
|
423
|
+
if (!ctx.hasUI) return;
|
|
424
|
+
state.lastUiContext = ctx;
|
|
425
|
+
hydrateActiveJobs(ctx);
|
|
426
|
+
if (state.asyncJobs.size > 0) ensurePoller();
|
|
427
|
+
});
|
|
428
|
+
const cleanupSessionArtifacts = (ctx: ExtensionContext) => {
|
|
429
|
+
maintenance.cleanupSessionArtifactsDeferred(ctx);
|
|
430
|
+
};
|
|
431
|
+
const resetSessionState = (ctx: ExtensionContext) => {
|
|
432
|
+
state.baseCwd = ctx.cwd;
|
|
433
|
+
state.currentSessionId = resolveCurrentSessionId(ctx.sessionManager);
|
|
434
|
+
state.lastUiContext = ctx;
|
|
435
|
+
cleanupSessionArtifacts(ctx);
|
|
436
|
+
clearPendingForegroundControlNotices(state);
|
|
437
|
+
resetJobs(ctx);
|
|
438
|
+
hydrateActiveJobs(ctx);
|
|
439
|
+
restoreSlashFinalSnapshots(ctx.sessionManager.getEntries(), pi);
|
|
440
|
+
maintenance.primeExistingResultsDeferred();
|
|
441
|
+
};
|
|
442
|
+
pi.on("session_start", (_event, ctx) => {
|
|
443
|
+
if (lifecycle.isCurrent()) resetSessionState(ctx);
|
|
444
|
+
});
|
|
445
|
+
pi.on("session_shutdown", () => {
|
|
446
|
+
lifecycle.dispose();
|
|
447
|
+
});
|
|
448
|
+
} catch (error) {
|
|
449
|
+
if (!runtimeCleanupInstalled) {
|
|
450
|
+
for (const cleanup of registrationFailureCleanups.reverse()) {
|
|
451
|
+
try {
|
|
452
|
+
cleanup();
|
|
453
|
+
} catch {
|
|
454
|
+
// Continue releasing partial-registration resources.
|
|
455
|
+
}
|
|
476
456
|
}
|
|
477
|
-
} catch (error) {
|
|
478
|
-
if (!isStaleExtensionContextError(error)) throw error;
|
|
479
457
|
}
|
|
480
|
-
|
|
458
|
+
lifecycle.dispose();
|
|
459
|
+
throw error;
|
|
460
|
+
}
|
|
481
461
|
}
|