@bastani/atomic 0.9.5-alpha.8 → 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 +122 -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 +38 -0
- package/dist/builtin/mcp/OAUTH.md +1 -0
- package/dist/builtin/mcp/README.md +10 -6
- 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 +40 -255
- package/dist/builtin/mcp/host-html-template.ts +4 -2
- package/dist/builtin/mcp/index.ts +274 -239
- package/dist/builtin/mcp/init.ts +96 -126
- 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 +52 -0
- 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 +106 -23
- package/dist/builtin/mcp/proxy-modes.ts +3 -3
- package/dist/builtin/mcp/session-cleanup-barrier.ts +43 -0
- package/dist/builtin/mcp/startup-warmup.ts +98 -0
- package/dist/builtin/mcp/state-lease.ts +12 -0
- package/dist/builtin/mcp/tool-result-renderer.ts +3 -3
- package/dist/builtin/mcp/ui-server.ts +8 -8
- package/dist/builtin/mcp/ui-session.ts +9 -18
- package/dist/builtin/subagents/CHANGELOG.md +78 -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 +289 -320
- 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/startup-maintenance.ts +89 -0
- 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 +26 -20
- 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 +177 -233
- 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 +29 -15
- 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 +63 -46
- 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 +55 -12
- 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 +157 -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 +86 -0
- package/dist/builtin/workflows/README.md +5 -5
- package/dist/builtin/workflows/builtin/deep-research-codebase-utils.ts +27 -4
- package/dist/builtin/workflows/builtin/goal-runner.ts +86 -27
- 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/skills/impeccable/SKILL.md +16 -13
- package/dist/builtin/workflows/skills/impeccable/reference/adapt.md +1 -0
- package/dist/builtin/workflows/skills/impeccable/reference/adapt.native.md +58 -0
- package/dist/builtin/workflows/skills/impeccable/reference/android.md +40 -0
- package/dist/builtin/workflows/skills/impeccable/reference/animate.md +2 -0
- package/dist/builtin/workflows/skills/impeccable/reference/audit.md +2 -0
- package/dist/builtin/workflows/skills/impeccable/reference/audit.native.md +139 -0
- package/dist/builtin/workflows/skills/impeccable/reference/bolder.md +69 -62
- package/dist/builtin/workflows/skills/impeccable/reference/critique.md +21 -7
- package/dist/builtin/workflows/skills/impeccable/reference/document.md +1 -1
- package/dist/builtin/workflows/skills/impeccable/reference/hooks.md +92 -0
- package/dist/builtin/workflows/skills/impeccable/reference/init.md +29 -7
- package/dist/builtin/workflows/skills/impeccable/reference/ios.md +45 -0
- package/dist/builtin/workflows/skills/impeccable/reference/layout.md +25 -1
- package/dist/builtin/workflows/skills/impeccable/reference/typeset.md +23 -1
- package/dist/builtin/workflows/skills/impeccable/scripts/context-signals.mjs +2 -1
- package/dist/builtin/workflows/skills/impeccable/scripts/context.mjs +75 -14
- package/dist/builtin/workflows/skills/impeccable/scripts/detector/browser/injected/index.mjs +1 -1
- package/dist/builtin/workflows/skills/impeccable/scripts/detector/cli/main.mjs +31 -0
- package/dist/builtin/workflows/skills/impeccable/scripts/detector/design-system.mjs +64 -0
- package/dist/builtin/workflows/skills/impeccable/scripts/detector/detect-antipatterns-browser.js +118 -11
- package/dist/builtin/workflows/skills/impeccable/scripts/detector/engines/regex/detect-text.mjs +16 -11
- package/dist/builtin/workflows/skills/impeccable/scripts/detector/registry/antipatterns.mjs +66 -0
- package/dist/builtin/workflows/skills/impeccable/scripts/detector/rules/checks.mjs +42 -10
- package/dist/builtin/workflows/skills/impeccable/scripts/detector/shared/fonts.mjs +30 -0
- package/dist/builtin/workflows/skills/impeccable/scripts/detector/shared/page.mjs +4 -6
- package/dist/builtin/workflows/skills/impeccable/scripts/hook-admin.mjs +660 -0
- package/dist/builtin/workflows/skills/impeccable/scripts/hook-before-edit.mjs +516 -0
- package/dist/builtin/workflows/skills/impeccable/scripts/hook-lib.mjs +1764 -0
- package/dist/builtin/workflows/skills/impeccable/scripts/hook.mjs +61 -0
- package/dist/builtin/workflows/skills/impeccable/scripts/lib/impeccable-config.mjs +4 -2
- package/dist/builtin/workflows/skills/impeccable/scripts/lib/is-generated.mjs +2 -2
- package/dist/builtin/workflows/skills/impeccable/scripts/live/svelte-component.mjs +13 -16
- package/dist/builtin/workflows/skills/impeccable/scripts/live-accept.mjs +17 -11
- package/dist/builtin/workflows/skills/impeccable/scripts/live-browser.js +104 -37
- package/dist/builtin/workflows/skills/impeccable/scripts/live-wrap.mjs +9 -0
- package/dist/builtin/workflows/src/durable/backend.ts +12 -0
- package/dist/builtin/workflows/src/durable/dbos-backend.ts +17 -1
- package/dist/builtin/workflows/src/durable/resume-catalog.ts +12 -0
- package/dist/builtin/workflows/src/durable/resume-runtime.ts +5 -2
- package/dist/builtin/workflows/src/durable/stage-primitive.ts +2 -1
- package/dist/builtin/workflows/src/durable/types.ts +16 -0
- package/dist/builtin/workflows/src/engine/primitives/task.ts +3 -1
- package/dist/builtin/workflows/src/engine/run-durable-finalize.ts +1 -2
- package/dist/builtin/workflows/src/engine/run-returned-status.ts +50 -16
- package/dist/builtin/workflows/src/engine/run.ts +20 -19
- package/dist/builtin/workflows/src/engine/runtime.ts +5 -0
- package/dist/builtin/workflows/src/extension/extension-factory.ts +3 -0
- package/dist/builtin/workflows/src/extension/extension-lifecycle.ts +9 -2
- package/dist/builtin/workflows/src/extension/extension-runtime-state.ts +137 -27
- package/dist/builtin/workflows/src/extension/lifecycle-notifications.ts +22 -6
- package/dist/builtin/workflows/src/extension/public-types.ts +1 -1
- package/dist/builtin/workflows/src/extension/workflow-command-completions.ts +13 -1
- package/dist/builtin/workflows/src/extension/workflow-command-registration.ts +19 -4
- package/dist/builtin/workflows/src/extension/workflow-command-surfaces.ts +9 -0
- package/dist/builtin/workflows/src/extension/workflow-prompts.ts +17 -22
- package/dist/builtin/workflows/src/extension/workflow-run-control-command.ts +48 -23
- package/dist/builtin/workflows/src/extension/workflow-schema.ts +15 -2
- package/dist/builtin/workflows/src/extension/workflow-tool-control.ts +20 -8
- package/dist/builtin/workflows/src/extension/workflow-tool.ts +24 -8
- package/dist/builtin/workflows/src/runs/background/status.ts +4 -3
- package/dist/builtin/workflows/src/runs/foreground/executor-direct-helpers.ts +29 -8
- package/dist/builtin/workflows/src/runs/foreground/executor-hil.ts +1 -1
- package/dist/builtin/workflows/src/runs/foreground/executor-stage-factory.ts +3 -2
- package/dist/builtin/workflows/src/runs/shared/model-fallback-candidates.ts +1 -1
- package/dist/builtin/workflows/src/runs/shared/worktree-git.ts +155 -20
- package/dist/builtin/workflows/src/runs/shared/worktree-types.ts +6 -0
- package/dist/builtin/workflows/src/runs/shared/worktree.ts +2 -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/shared/returned-run-status.ts +116 -0
- package/dist/builtin/workflows/src/shared/workflow-failures-decisions.ts +2 -0
- package/dist/builtin/workflows/src/tui/graph-view-render-helpers.ts +21 -3
- package/dist/builtin/workflows/src/tui/graph-view-state.ts +3 -0
- package/dist/builtin/workflows/src/tui/graph-view-types.ts +3 -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/builtin/workflows/src/tui/status-list.ts +22 -15
- package/dist/builtin/workflows/src/tui/workflow-attach-pane.ts +4 -4
- 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-auto-compaction.d.ts +23 -3
- package/dist/core/agent-session-auto-compaction.d.ts.map +1 -1
- package/dist/core/agent-session-auto-compaction.js +129 -17
- package/dist/core/agent-session-auto-compaction.js.map +1 -1
- package/dist/core/agent-session-events.d.ts.map +1 -1
- package/dist/core/agent-session-events.js +9 -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-methods.d.ts +6 -3
- package/dist/core/agent-session-methods.d.ts.map +1 -1
- package/dist/core/agent-session-methods.js.map +1 -1
- package/dist/core/agent-session-prompt.d.ts.map +1 -1
- package/dist/core/agent-session-prompt.js +2 -2
- 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/agent-session.d.ts +4 -2
- package/dist/core/agent-session.d.ts.map +1 -1
- package/dist/core/agent-session.js +4 -2
- package/dist/core/agent-session.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/loader-virtual-modules.d.ts +8 -1
- package/dist/core/extensions/loader-virtual-modules.d.ts.map +1 -1
- package/dist/core/extensions/loader-virtual-modules.js +2 -1
- package/dist/core/extensions/loader-virtual-modules.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/footer-data-provider.d.ts +6 -0
- package/dist/core/footer-data-provider.d.ts.map +1 -1
- package/dist/core/footer-data-provider.js +72 -29
- package/dist/core/footer-data-provider.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/openai-responses-payload-sanitizer.d.ts +1 -0
- package/dist/core/openai-responses-payload-sanitizer.d.ts.map +1 -1
- package/dist/core/openai-responses-payload-sanitizer.js +24 -9
- package/dist/core/openai-responses-payload-sanitizer.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/slash-commands.d.ts +2 -0
- package/dist/core/slash-commands.d.ts.map +1 -1
- package/dist/core/slash-commands.js +141 -0
- package/dist/core/slash-commands.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/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/main-deferred-startup.d.ts.map +1 -1
- package/dist/main-deferred-startup.js +2 -2
- package/dist/main-deferred-startup.js.map +1 -1
- package/dist/main-early-input.d.ts.map +1 -1
- package/dist/main-early-input.js +7 -0
- package/dist/main-early-input.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/main.d.ts.map +1 -1
- package/dist/main.js +1 -1
- package/dist/main.js.map +1 -1
- package/dist/modes/interactive/components/chat-session-host-actions.d.ts.map +1 -1
- package/dist/modes/interactive/components/chat-session-host-actions.js +0 -1
- package/dist/modes/interactive/components/chat-session-host-actions.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 +3 -1
- package/dist/modes/interactive/interactive-agent-events.js.map +1 -1
- package/dist/modes/interactive/interactive-autocomplete.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-autocomplete.js +21 -9
- package/dist/modes/interactive/interactive-autocomplete.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 +43 -30
- package/dist/modes/interactive/interactive-deferred-startup.js.map +1 -1
- package/dist/modes/interactive/interactive-hotkeys-debug.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-hotkeys-debug.js +1 -0
- package/dist/modes/interactive/interactive-hotkeys-debug.js.map +1 -1
- package/dist/modes/interactive/interactive-input-handling.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-input-handling.js +41 -6
- package/dist/modes/interactive/interactive-input-handling.js.map +1 -1
- package/dist/modes/interactive/interactive-mode-base.d.ts +3 -0
- package/dist/modes/interactive/interactive-mode-base.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode-base.js +3 -0
- package/dist/modes/interactive/interactive-mode-base.js.map +1 -1
- package/dist/modes/interactive/interactive-mode-deps.d.ts +2 -2
- package/dist/modes/interactive/interactive-mode-deps.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode-deps.js +2 -2
- package/dist/modes/interactive/interactive-mode-deps.js.map +1 -1
- package/dist/modes/interactive/interactive-mode-surface.d.ts +2 -2
- package/dist/modes/interactive/interactive-mode-surface.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode-surface.js.map +1 -1
- package/dist/modes/interactive/interactive-model-routing.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-model-routing.js +11 -4
- package/dist/modes/interactive/interactive-model-routing.js.map +1 -1
- package/dist/modes/interactive/interactive-process-lifecycle.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-process-lifecycle.js +0 -3
- package/dist/modes/interactive/interactive-process-lifecycle.js.map +1 -1
- package/dist/modes/interactive/interactive-render-chat.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-render-chat.js +15 -1
- package/dist/modes/interactive/interactive-render-chat.js.map +1 -1
- package/dist/modes/interactive/interactive-session-routing.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-session-routing.js +5 -1
- package/dist/modes/interactive/interactive-session-routing.js.map +1 -1
- package/dist/modes/interactive/interactive-startup.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-startup.js +20 -21
- package/dist/modes/interactive/interactive-startup.js.map +1 -1
- package/dist/modes/interactive/theme/global-theme.d.ts.map +1 -1
- package/dist/modes/interactive/theme/global-theme.js +26 -2
- package/dist/modes/interactive/theme/global-theme.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/dist/utils/fs-watch.d.ts +24 -1
- package/dist/utils/fs-watch.d.ts.map +1 -1
- package/dist/utils/fs-watch.js +60 -5
- package/dist/utils/fs-watch.js.map +1 -1
- package/docs/changelog.mdx +19 -0
- package/docs/compaction.md +60 -49
- package/docs/custom-provider.md +18 -5
- package/docs/development.md +4 -0
- package/docs/extensions.md +11 -2
- package/docs/json.md +1 -1
- package/docs/models.md +69 -10
- package/docs/providers.md +1 -1
- package/docs/quickstart.md +12 -8
- package/docs/rpc.md +2 -2
- package/docs/sdk.md +1 -1
- package/docs/settings.md +4 -4
- package/docs/subagents.md +40 -5
- package/docs/tools.md +1 -1
- package/docs/usage.md +4 -2
- package/docs/windows.md +4 -0
- package/docs/workflows.md +33 -48
- 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
|
@@ -1,202 +1,71 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { APP_NAME, getEnvValue, type ExtensionAPI, type ExtensionContext, type SessionStartEvent, type ToolDefinition, type ToolExecutionStartEvent } from "@bastani/atomic";
|
|
2
2
|
import { Text } from "@earendil-works/pi-tui";
|
|
3
3
|
import { Type } from "typebox";
|
|
4
4
|
import { renderIntercomToolResult } from "./result-renderers.js";
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
type
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
model_select: ModelSelectEvent;
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
type LazyLifecycleEvent = keyof ForwardedEventMap;
|
|
25
|
-
type ForwardedHandler<K extends LazyLifecycleEvent> = ExtensionHandler<ForwardedEventMap[K]>;
|
|
26
|
-
type ForwardedHandlerMap = { [K in LazyLifecycleEvent]: ForwardedHandler<K>[] };
|
|
27
|
-
type AnyForwardedHandler = { [K in LazyLifecycleEvent]: ForwardedHandler<K> }[LazyLifecycleEvent];
|
|
28
|
-
|
|
29
|
-
type CapturedHeavy = {
|
|
30
|
-
tools: Map<string, ToolDefinition>;
|
|
31
|
-
commands: Map<string, CapturedCommand>;
|
|
32
|
-
handlers: ForwardedHandlerMap;
|
|
33
|
-
shortcuts: Map<string, CapturedShortcut>;
|
|
34
|
-
eventHandlers: Map<string, EventHandler[]>;
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
type LifecycleSnapshot<K extends LazyLifecycleEvent> = {
|
|
5
|
+
import { loadConfig } from "./config.js";
|
|
6
|
+
import { executeHeavyTool, runHeavyCommand, type HeavyHandle } from "./lazy-tool-execution.js";
|
|
7
|
+
import { assertCurrentLifecycleLease, createLifecycleLease, retainSettledLifecycleCleanup, retireLifecycleLease, SerializedLifecycleForwarder, type LifecycleLease } from "./lifecycle-lease.js";
|
|
8
|
+
import { rejectLazyResultRelay } from "./lazy-subagent-ack.js";
|
|
9
|
+
import {
|
|
10
|
+
createForwardedHandlerMap,
|
|
11
|
+
createHeavyProxy,
|
|
12
|
+
dispatchEventHandlers,
|
|
13
|
+
dispatchHandlers,
|
|
14
|
+
type CapturedHeavy,
|
|
15
|
+
type ForwardedEventMap,
|
|
16
|
+
type HeavyRuntimeReadiness,
|
|
17
|
+
type ToolRenderResultArgs,
|
|
18
|
+
} from "./lazy-heavy-proxy.js";
|
|
19
|
+
|
|
20
|
+
type LifecycleSnapshot<K extends keyof ForwardedEventMap> = {
|
|
38
21
|
event: ForwardedEventMap[K];
|
|
39
22
|
ctx: ExtensionContext;
|
|
40
23
|
};
|
|
41
|
-
|
|
42
|
-
type
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
24
|
+
type ShutdownSnapshot = LifecycleSnapshot<"session_shutdown"> & { generation: number };
|
|
25
|
+
type IntercomLease = LifecycleLease<ShutdownSnapshot>;
|
|
26
|
+
type SessionSnapshot = LifecycleSnapshot<"session_start"> & { generation: number; lease: IntercomLease };
|
|
27
|
+
type IntercomHeavyHandle = HeavyHandle<CapturedHeavy>;
|
|
28
|
+
type HeavyAttempt = { lease: IntercomLease; promise: Promise<IntercomHeavyHandle> };
|
|
29
|
+
type ReplayAttempt = { lease: IntercomLease; heavy: CapturedHeavy; promise: Promise<void> };
|
|
46
30
|
type ActiveLifecycleState = {
|
|
47
31
|
turnStart: LifecycleSnapshot<"turn_start"> | null;
|
|
48
32
|
agentStart: LifecycleSnapshot<"agent_start"> | null;
|
|
49
33
|
activeTools: Map<string, LifecycleSnapshot<"tool_execution_start">>;
|
|
50
34
|
modelSelect: LifecycleSnapshot<"model_select"> | null;
|
|
51
35
|
};
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
function hasSubagentIntercomEnv(): boolean {
|
|
56
|
-
return Object.keys(process.env).some((key) => key.endsWith("_SUBAGENT_ORCHESTRATOR_TARGET"));
|
|
36
|
+
interface LightweightIntercomOptions {
|
|
37
|
+
importHeavy?: () => Promise<{ default: (pi: ExtensionAPI) => void | HeavyRuntimeReadiness | Promise<void | HeavyRuntimeReadiness> }>;
|
|
38
|
+
isEnabled?: () => boolean;
|
|
57
39
|
}
|
|
58
40
|
|
|
59
|
-
|
|
60
|
-
return { type: "session_start", reason: "startup" };
|
|
61
|
-
}
|
|
41
|
+
const MANAGEMENT_ONLY_SUBAGENT_ACTIONS = new Set(["list", "get", "create", "update", "delete", "status", "interrupt", "doctor"]);
|
|
62
42
|
|
|
63
|
-
function
|
|
64
|
-
return
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
agent_end: [],
|
|
71
|
-
tool_execution_start: [],
|
|
72
|
-
tool_execution_end: [],
|
|
73
|
-
model_select: [],
|
|
74
|
-
};
|
|
43
|
+
function isInteractiveForegroundSubagentStart(event: ToolExecutionStartEvent, ctx: ExtensionContext): boolean {
|
|
44
|
+
if (!ctx.hasUI || event.toolName !== "subagent") return false;
|
|
45
|
+
if (!event.args || typeof event.args !== "object" || Array.isArray(event.args)) return true;
|
|
46
|
+
const args = event.args as { action?: unknown; async?: unknown };
|
|
47
|
+
const action = typeof args.action === "string" ? args.action.trim() : "";
|
|
48
|
+
if (action && MANAGEMENT_ONLY_SUBAGENT_ACTIONS.has(action)) return false;
|
|
49
|
+
return args.async !== true;
|
|
75
50
|
}
|
|
76
51
|
|
|
77
|
-
function addHandler<K extends LazyLifecycleEvent>(captured: CapturedHeavy, event: K, handler: ForwardedHandler<K>): void {
|
|
78
|
-
captured.handlers[event].push(handler);
|
|
79
|
-
}
|
|
80
52
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
function captureForwardedHandler(captured: CapturedHeavy, event: "turn_start", handler: ForwardedHandler<"turn_start">): void;
|
|
84
|
-
function captureForwardedHandler(captured: CapturedHeavy, event: "turn_end", handler: ForwardedHandler<"turn_end">): void;
|
|
85
|
-
function captureForwardedHandler(captured: CapturedHeavy, event: "agent_start", handler: ForwardedHandler<"agent_start">): void;
|
|
86
|
-
function captureForwardedHandler(captured: CapturedHeavy, event: "agent_end", handler: ForwardedHandler<"agent_end">): void;
|
|
87
|
-
function captureForwardedHandler(captured: CapturedHeavy, event: "tool_execution_start", handler: ForwardedHandler<"tool_execution_start">): void;
|
|
88
|
-
function captureForwardedHandler(captured: CapturedHeavy, event: "tool_execution_end", handler: ForwardedHandler<"tool_execution_end">): void;
|
|
89
|
-
function captureForwardedHandler(captured: CapturedHeavy, event: "model_select", handler: ForwardedHandler<"model_select">): void;
|
|
90
|
-
function captureForwardedHandler(captured: CapturedHeavy, event: LazyLifecycleEvent, handler: AnyForwardedHandler): void;
|
|
91
|
-
function captureForwardedHandler(captured: CapturedHeavy, event: LazyLifecycleEvent, handler: AnyForwardedHandler): void {
|
|
92
|
-
switch (event) {
|
|
93
|
-
case "session_start":
|
|
94
|
-
addHandler(captured, event, handler as ForwardedHandler<"session_start">);
|
|
95
|
-
return;
|
|
96
|
-
case "session_shutdown":
|
|
97
|
-
addHandler(captured, event, handler as ForwardedHandler<"session_shutdown">);
|
|
98
|
-
return;
|
|
99
|
-
case "turn_start":
|
|
100
|
-
addHandler(captured, event, handler as ForwardedHandler<"turn_start">);
|
|
101
|
-
return;
|
|
102
|
-
case "turn_end":
|
|
103
|
-
addHandler(captured, event, handler as ForwardedHandler<"turn_end">);
|
|
104
|
-
return;
|
|
105
|
-
case "agent_start":
|
|
106
|
-
addHandler(captured, event, handler as ForwardedHandler<"agent_start">);
|
|
107
|
-
return;
|
|
108
|
-
case "agent_end":
|
|
109
|
-
addHandler(captured, event, handler as ForwardedHandler<"agent_end">);
|
|
110
|
-
return;
|
|
111
|
-
case "tool_execution_start":
|
|
112
|
-
addHandler(captured, event, handler as ForwardedHandler<"tool_execution_start">);
|
|
113
|
-
return;
|
|
114
|
-
case "tool_execution_end":
|
|
115
|
-
addHandler(captured, event, handler as ForwardedHandler<"tool_execution_end">);
|
|
116
|
-
return;
|
|
117
|
-
case "model_select":
|
|
118
|
-
addHandler(captured, event, handler as ForwardedHandler<"model_select">);
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
function addEventHandler(captured: CapturedHeavy, event: string, handler: EventHandler): void {
|
|
123
|
-
const handlers = captured.eventHandlers.get(event) ?? [];
|
|
124
|
-
handlers.push(handler);
|
|
125
|
-
captured.eventHandlers.set(event, handlers);
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
async function dispatchHandlers<K extends LazyLifecycleEvent>(captured: CapturedHeavy, eventName: K, event: ForwardedEventMap[K], ctx: ExtensionContext): Promise<void> {
|
|
129
|
-
for (const handler of captured.handlers[eventName]) {
|
|
130
|
-
await handler(event, ctx);
|
|
131
|
-
}
|
|
132
|
-
}
|
|
53
|
+
const SUBAGENT_CONTROL_INTERCOM_EVENT = "subagent:control-intercom";
|
|
54
|
+
const SUBAGENT_RESULT_INTERCOM_EVENT = "subagent:result-intercom";
|
|
133
55
|
|
|
134
|
-
|
|
135
|
-
for (const handler of captured.eventHandlers.get(eventName) ?? []) {
|
|
136
|
-
await handler(payload);
|
|
137
|
-
}
|
|
138
|
-
}
|
|
56
|
+
const SUBAGENT_ENV_PREFIX = `${APP_NAME.toUpperCase()}_SUBAGENT_`;
|
|
139
57
|
|
|
140
|
-
function
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
if (prop === "registerTool") {
|
|
144
|
-
return (tool: ToolDefinition) => captured.tools.set(tool.name, tool);
|
|
145
|
-
}
|
|
146
|
-
if (prop === "registerCommand") {
|
|
147
|
-
return (name: string, options: CapturedCommand) => captured.commands.set(name, options);
|
|
148
|
-
}
|
|
149
|
-
if (prop === "on") {
|
|
150
|
-
return (event: LazyLifecycleEvent, handler: AnyForwardedHandler) => {
|
|
151
|
-
captureForwardedHandler(captured, event, handler);
|
|
152
|
-
};
|
|
153
|
-
}
|
|
154
|
-
if (prop === "registerShortcut") {
|
|
155
|
-
return (shortcut: string, options: CapturedShortcut) => {
|
|
156
|
-
captured.shortcuts.set(shortcut, options);
|
|
157
|
-
};
|
|
158
|
-
}
|
|
159
|
-
if (prop === "registerMessageRenderer") {
|
|
160
|
-
return (customType: string, renderer: MessageRenderer) => pi.registerMessageRenderer(customType, renderer);
|
|
161
|
-
}
|
|
162
|
-
if (prop === "events") {
|
|
163
|
-
return new Proxy(pi.events, {
|
|
164
|
-
get(eventTarget, eventProp, eventReceiver) {
|
|
165
|
-
if (eventProp === "on") {
|
|
166
|
-
return (event: string, handler: EventHandler) => {
|
|
167
|
-
addEventHandler(captured, event, handler);
|
|
168
|
-
return () => {
|
|
169
|
-
const handlers = captured.eventHandlers.get(event) ?? [];
|
|
170
|
-
captured.eventHandlers.set(event, handlers.filter((candidate) => candidate !== handler));
|
|
171
|
-
};
|
|
172
|
-
};
|
|
173
|
-
}
|
|
174
|
-
return Reflect.get(eventTarget, eventProp, eventReceiver);
|
|
175
|
-
},
|
|
176
|
-
});
|
|
177
|
-
}
|
|
178
|
-
return Reflect.get(target, prop, receiver);
|
|
179
|
-
},
|
|
180
|
-
}) as ExtensionAPI;
|
|
58
|
+
function readSubagentEnv(name: string): string | undefined {
|
|
59
|
+
const value = getEnvValue(`${SUBAGENT_ENV_PREFIX}${name}`)?.trim();
|
|
60
|
+
return value || undefined;
|
|
181
61
|
}
|
|
182
62
|
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
name: string,
|
|
186
|
-
args: Parameters<NonNullable<ToolDefinition["execute"]>>,
|
|
187
|
-
): Promise<Awaited<ReturnType<NonNullable<ToolDefinition["execute"]>>>> {
|
|
188
|
-
const ctx = args[4];
|
|
189
|
-
const heavy = await loadHeavy(ctx);
|
|
190
|
-
const tool = heavy.tools.get(name);
|
|
191
|
-
if (!tool?.execute) throw new Error(`Intercom tool implementation not found: ${name}`);
|
|
192
|
-
return await tool.execute(...args) as Awaited<ReturnType<NonNullable<ToolDefinition["execute"]>>>;
|
|
63
|
+
function hasSubagentIntercomEnv(): boolean {
|
|
64
|
+
return readSubagentEnv("ORCHESTRATOR_TARGET") !== undefined;
|
|
193
65
|
}
|
|
194
66
|
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
const command = heavy.commands.get("intercom");
|
|
198
|
-
if (!command) throw new Error("Intercom command implementation not found");
|
|
199
|
-
await command.handler(args ?? "", ctx);
|
|
67
|
+
function createSyntheticSessionStartEvent(): SessionStartEvent {
|
|
68
|
+
return { type: "session_start", reason: "startup" };
|
|
200
69
|
}
|
|
201
70
|
|
|
202
71
|
function renderHeavyToolResult(loadedHeavy: CapturedHeavy | null, name: string, args: ToolRenderResultArgs): ReturnType<NonNullable<ToolDefinition["renderResult"]>> {
|
|
@@ -204,159 +73,307 @@ function renderHeavyToolResult(loadedHeavy: CapturedHeavy | null, name: string,
|
|
|
204
73
|
if (renderer) return renderer(...args);
|
|
205
74
|
return renderIntercomToolResult(name, args);
|
|
206
75
|
}
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
76
|
+
export default function intercom(pi: ExtensionAPI, options: LightweightIntercomOptions = {}) {
|
|
77
|
+
const enabled = options.isEnabled?.() ?? loadConfig().enabled;
|
|
78
|
+
const delegatedSession = hasSubagentIntercomEnv();
|
|
79
|
+
const delegatedSessionName = readSubagentEnv("INTERCOM_SESSION_NAME");
|
|
80
|
+
let heavyAttempt: HeavyAttempt | null = null;
|
|
81
|
+
let loadedHeavy: IntercomHeavyHandle | null = null;
|
|
211
82
|
let sessionSnapshot: SessionSnapshot | null = null;
|
|
212
83
|
let lifecycleGeneration = 0;
|
|
84
|
+
let nextLeaseId = 1;
|
|
85
|
+
let activeLease = createLifecycleLease<ShutdownSnapshot>(nextLeaseId++);
|
|
213
86
|
let replayedGeneration = 0;
|
|
87
|
+
let replayAttempt: ReplayAttempt | null = null;
|
|
88
|
+
const lifecycleForward = new SerializedLifecycleForwarder();
|
|
89
|
+
const invalidatedMessage = "Intercom initialization was invalidated by session shutdown";
|
|
214
90
|
const activeLifecycle: ActiveLifecycleState = {
|
|
215
91
|
turnStart: null,
|
|
216
92
|
agentStart: null,
|
|
217
93
|
activeTools: new Map(),
|
|
218
94
|
modelSelect: null,
|
|
219
95
|
};
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
96
|
+
function assertLease(lease: IntercomLease): void {
|
|
97
|
+
assertCurrentLifecycleLease(activeLease, lease, invalidatedMessage);
|
|
98
|
+
}
|
|
99
|
+
function createHandle(heavy: CapturedHeavy, lease: IntercomLease): IntercomHeavyHandle {
|
|
100
|
+
return { heavy, assertCurrent: () => assertLease(lease) };
|
|
101
|
+
}
|
|
102
|
+
async function waitForPriorCleanup(lease: IntercomLease): Promise<void> {
|
|
103
|
+
await lease.priorCleanup;
|
|
104
|
+
assertLease(lease);
|
|
105
|
+
}
|
|
106
|
+
function isReplaySnapshotCurrent(snapshot: SessionSnapshot, lease: IntercomLease): boolean {
|
|
107
|
+
assertLease(lease);
|
|
108
|
+
return sessionSnapshot === snapshot;
|
|
109
|
+
}
|
|
110
|
+
async function replaySessionStart(heavy: CapturedHeavy, lease: IntercomLease, onReplay?: (ctx: ExtensionContext) => void): Promise<void> {
|
|
111
|
+
for (;;) {
|
|
112
|
+
assertLease(lease);
|
|
113
|
+
const snapshot = sessionSnapshot;
|
|
114
|
+
if (!snapshot || snapshot.lease !== lease || replayedGeneration === snapshot.generation) return;
|
|
115
|
+
const active = {
|
|
116
|
+
turnStart: activeLifecycle.turnStart,
|
|
117
|
+
modelSelect: activeLifecycle.modelSelect,
|
|
118
|
+
agentStart: activeLifecycle.agentStart,
|
|
119
|
+
activeTools: [...activeLifecycle.activeTools.values()],
|
|
120
|
+
};
|
|
121
|
+
onReplay?.(snapshot.ctx);
|
|
122
|
+
await dispatchHandlers(heavy, "session_start", snapshot.event, snapshot.ctx);
|
|
123
|
+
if (!isReplaySnapshotCurrent(snapshot, lease)) continue;
|
|
124
|
+
if (active.turnStart) await dispatchHandlers(heavy, "turn_start", active.turnStart.event, active.turnStart.ctx);
|
|
125
|
+
if (!isReplaySnapshotCurrent(snapshot, lease)) continue;
|
|
126
|
+
if (active.modelSelect) await dispatchHandlers(heavy, "model_select", active.modelSelect.event, active.modelSelect.ctx);
|
|
127
|
+
if (!isReplaySnapshotCurrent(snapshot, lease)) continue;
|
|
128
|
+
if (active.agentStart) await dispatchHandlers(heavy, "agent_start", active.agentStart.event, active.agentStart.ctx);
|
|
129
|
+
if (!isReplaySnapshotCurrent(snapshot, lease)) continue;
|
|
130
|
+
for (const activeTool of active.activeTools) {
|
|
131
|
+
await dispatchHandlers(heavy, "tool_execution_start", activeTool.event, activeTool.ctx);
|
|
132
|
+
if (!isReplaySnapshotCurrent(snapshot, lease)) break;
|
|
133
|
+
}
|
|
134
|
+
if (!isReplaySnapshotCurrent(snapshot, lease)) continue;
|
|
135
|
+
replayedGeneration = snapshot.generation;
|
|
136
|
+
return;
|
|
236
137
|
}
|
|
237
138
|
}
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
139
|
+
async function ensureSessionStartReplayed(heavy: CapturedHeavy, lease: IntercomLease, onReplay?: (ctx: ExtensionContext) => void): Promise<void> {
|
|
140
|
+
await waitForPriorCleanup(lease);
|
|
141
|
+
const snapshot = sessionSnapshot;
|
|
142
|
+
if (!snapshot || snapshot.lease !== lease || replayedGeneration === snapshot.generation) return;
|
|
143
|
+
const existing = replayAttempt;
|
|
144
|
+
if (existing?.lease === lease && existing.heavy === heavy) return existing.promise;
|
|
145
|
+
let promise: Promise<void>;
|
|
146
|
+
promise = lifecycleForward.enqueue(() => replaySessionStart(heavy, lease, onReplay)).finally(() => {
|
|
147
|
+
if (replayAttempt?.promise === promise) replayAttempt = null;
|
|
148
|
+
});
|
|
149
|
+
replayAttempt = { lease, heavy, promise };
|
|
150
|
+
await promise;
|
|
151
|
+
}
|
|
152
|
+
async function loadHeavy(ctx?: ExtensionContext): Promise<IntercomHeavyHandle> {
|
|
153
|
+
const lease = activeLease;
|
|
154
|
+
if (lease.retired) throw new Error("Intercom initialization unavailable: no active session");
|
|
155
|
+
await waitForPriorCleanup(lease);
|
|
156
|
+
const existing = heavyAttempt;
|
|
157
|
+
if (existing?.lease === lease) {
|
|
158
|
+
const handle = await existing.promise;
|
|
159
|
+
assertLease(lease);
|
|
160
|
+
if (!sessionSnapshot && ctx) {
|
|
161
|
+
sessionSnapshot = { event: createSyntheticSessionStartEvent(), ctx, generation: ++lifecycleGeneration, lease };
|
|
162
|
+
}
|
|
163
|
+
await ensureSessionStartReplayed(handle.heavy, lease);
|
|
164
|
+
assertLease(lease);
|
|
165
|
+
return handle;
|
|
166
|
+
}
|
|
167
|
+
let promise: Promise<IntercomHeavyHandle>;
|
|
168
|
+
promise = (async (): Promise<IntercomHeavyHandle> => {
|
|
169
|
+
const captured: CapturedHeavy = {
|
|
170
|
+
tools: new Map(), commands: new Map(), handlers: createForwardedHandlerMap(),
|
|
171
|
+
shortcuts: new Map(), eventHandlers: new Map(),
|
|
172
|
+
};
|
|
173
|
+
let replayCtx: ExtensionContext | null = null;
|
|
174
|
+
let cleaned = false;
|
|
175
|
+
const cleanupCandidate = async (): Promise<void> => {
|
|
176
|
+
const shutdown = lease.shutdown;
|
|
177
|
+
const cleanupCtx = shutdown?.ctx ?? replayCtx;
|
|
178
|
+
if (!cleanupCtx || cleaned) return;
|
|
179
|
+
cleaned = true;
|
|
180
|
+
const event = shutdown?.event ?? { type: "session_shutdown", reason: "quit" };
|
|
181
|
+
try {
|
|
182
|
+
await dispatchHandlers(captured, "session_shutdown", event, cleanupCtx);
|
|
183
|
+
} catch (cleanupError) {
|
|
184
|
+
console.error("Intercom failed to clean rejected lazy candidate:", cleanupError);
|
|
185
|
+
}
|
|
186
|
+
};
|
|
187
|
+
try {
|
|
188
|
+
const mod = await (options.importHeavy?.() ?? import("./index-heavy.js"));
|
|
189
|
+
assertLease(lease);
|
|
190
|
+
const runtimeReadiness = await mod.default(createHeavyProxy(pi, captured));
|
|
191
|
+
if (runtimeReadiness) captured.runtimeReadiness = runtimeReadiness;
|
|
192
|
+
assertLease(lease);
|
|
252
193
|
if (!sessionSnapshot && ctx) {
|
|
253
|
-
sessionSnapshot = { event: createSyntheticSessionStartEvent(), ctx, generation: ++lifecycleGeneration };
|
|
194
|
+
sessionSnapshot = { event: createSyntheticSessionStartEvent(), ctx, generation: ++lifecycleGeneration, lease };
|
|
254
195
|
}
|
|
255
|
-
await
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
196
|
+
await ensureSessionStartReplayed(captured, lease, (replayContext) => { replayCtx = replayContext; });
|
|
197
|
+
assertLease(lease);
|
|
198
|
+
const handle = createHandle(captured, lease);
|
|
199
|
+
loadedHeavy = handle;
|
|
200
|
+
return handle;
|
|
201
|
+
} catch (error) {
|
|
202
|
+
await cleanupCandidate();
|
|
203
|
+
throw error;
|
|
204
|
+
}
|
|
205
|
+
})();
|
|
206
|
+
heavyAttempt = { lease, promise };
|
|
207
|
+
void promise.then(
|
|
208
|
+
() => undefined,
|
|
209
|
+
(error: unknown) => {
|
|
210
|
+
if (heavyAttempt?.promise === promise) heavyAttempt = null;
|
|
211
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
212
|
+
console.error(`Intercom heavy initialization failed; a later call will retry: ${message}`, error);
|
|
213
|
+
},
|
|
214
|
+
);
|
|
215
|
+
return promise;
|
|
216
|
+
}
|
|
217
|
+
async function registerAutomatically(ctx: ExtensionContext, phase: string, foreground = false): Promise<boolean> {
|
|
218
|
+
try {
|
|
219
|
+
const handle = await loadHeavy(ctx);
|
|
220
|
+
const readiness = handle.heavy.runtimeReadiness;
|
|
221
|
+
if (!readiness) throw new Error("Intercom heavy runtime did not expose broker readiness");
|
|
222
|
+
if (readiness.enabled) {
|
|
223
|
+
if (foreground) await readiness.awaitForegroundBrokerReady();
|
|
224
|
+
else await readiness.awaitAutomaticBrokerReady();
|
|
225
|
+
}
|
|
226
|
+
handle.assertCurrent();
|
|
227
|
+
return readiness.enabled;
|
|
228
|
+
} catch (error) {
|
|
229
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
230
|
+
console.error(`Intercom ${phase} failed; session will continue and a later call may retry: ${message}`, error);
|
|
231
|
+
return false;
|
|
263
232
|
}
|
|
264
|
-
return heavy;
|
|
265
233
|
}
|
|
266
|
-
|
|
267
234
|
pi.on("session_start", async (event, ctx) => {
|
|
235
|
+
if (delegatedSessionName && typeof pi.setSessionName === "function") pi.setSessionName(delegatedSessionName);
|
|
236
|
+
if (activeLease.retired) activeLease = createLifecycleLease<ShutdownSnapshot>(nextLeaseId++, activeLease.cleanupBarrier);
|
|
237
|
+
const lease = activeLease;
|
|
238
|
+
await waitForPriorCleanup(lease);
|
|
239
|
+
if (sessionSnapshot) {
|
|
240
|
+
activeLifecycle.turnStart = null;
|
|
241
|
+
activeLifecycle.agentStart = null;
|
|
242
|
+
activeLifecycle.activeTools.clear();
|
|
243
|
+
activeLifecycle.modelSelect = null;
|
|
244
|
+
}
|
|
268
245
|
const generation = ++lifecycleGeneration;
|
|
269
|
-
sessionSnapshot = { event, ctx, generation };
|
|
246
|
+
sessionSnapshot = { event, ctx, generation, lease };
|
|
270
247
|
if (loadedHeavy) {
|
|
271
|
-
|
|
272
|
-
|
|
248
|
+
await ensureSessionStartReplayed(loadedHeavy.heavy, lease);
|
|
249
|
+
return;
|
|
273
250
|
}
|
|
251
|
+
if (!enabled || (!ctx.hasUI && !delegatedSession)) return;
|
|
252
|
+
if (delegatedSession) await registerAutomatically(ctx, "bridged child automatic registration");
|
|
274
253
|
});
|
|
275
|
-
|
|
276
254
|
pi.on("session_shutdown", async (event, ctx) => {
|
|
277
|
-
|
|
255
|
+
const lease = activeLease;
|
|
256
|
+
const generation = ++lifecycleGeneration;
|
|
257
|
+
retireLifecycleLease(lease, { event, ctx, generation });
|
|
258
|
+
const retiredHeavy = loadedHeavy?.heavy ?? null;
|
|
259
|
+
const retiredAttempt = heavyAttempt?.lease === lease ? heavyAttempt.promise : null;
|
|
260
|
+
const retiredReplay = replayAttempt?.lease === lease ? replayAttempt.promise : null;
|
|
261
|
+
sessionSnapshot = null;
|
|
262
|
+
heavyAttempt = null;
|
|
263
|
+
loadedHeavy = null;
|
|
264
|
+
replayAttempt = null;
|
|
265
|
+
replayedGeneration = generation;
|
|
278
266
|
activeLifecycle.turnStart = null;
|
|
279
267
|
activeLifecycle.agentStart = null;
|
|
280
268
|
activeLifecycle.activeTools.clear();
|
|
281
269
|
activeLifecycle.modelSelect = null;
|
|
282
|
-
|
|
283
|
-
|
|
270
|
+
const publishedCleanup = retiredHeavy
|
|
271
|
+
? lifecycleForward.enqueue(() => dispatchHandlers(retiredHeavy, "session_shutdown", event, ctx))
|
|
272
|
+
: Promise.resolve();
|
|
273
|
+
const retainedCleanup = retainSettledLifecycleCleanup(lease, [publishedCleanup, retiredAttempt, retiredReplay, lifecycleForward.settled]);
|
|
274
|
+
try {
|
|
275
|
+
await publishedCleanup;
|
|
276
|
+
} finally {
|
|
277
|
+
await retainedCleanup;
|
|
284
278
|
}
|
|
285
|
-
sessionSnapshot = null;
|
|
286
|
-
replayedGeneration = lifecycleGeneration;
|
|
287
279
|
});
|
|
288
|
-
|
|
289
280
|
pi.on("turn_start", async (event, ctx) => {
|
|
281
|
+
if (activeLease.retired) return;
|
|
290
282
|
activeLifecycle.turnStart = { event, ctx };
|
|
291
|
-
|
|
283
|
+
const heavy = loadedHeavy?.heavy;
|
|
284
|
+
if (heavy) await lifecycleForward.enqueue(() => dispatchHandlers(heavy, "turn_start", event, ctx));
|
|
292
285
|
});
|
|
293
|
-
|
|
294
286
|
pi.on("turn_end", async (event, ctx) => {
|
|
287
|
+
if (activeLease.retired) return;
|
|
295
288
|
activeLifecycle.turnStart = null;
|
|
296
289
|
activeLifecycle.agentStart = null;
|
|
297
290
|
activeLifecycle.activeTools.clear();
|
|
298
|
-
|
|
291
|
+
const heavy = loadedHeavy?.heavy;
|
|
292
|
+
if (heavy) await lifecycleForward.enqueue(() => dispatchHandlers(heavy, "turn_end", event, ctx));
|
|
299
293
|
});
|
|
300
|
-
|
|
301
294
|
pi.on("agent_start", async (event, ctx) => {
|
|
295
|
+
if (activeLease.retired) return;
|
|
302
296
|
activeLifecycle.agentStart = { event, ctx };
|
|
303
297
|
activeLifecycle.activeTools.clear();
|
|
304
|
-
|
|
298
|
+
const heavy = loadedHeavy?.heavy;
|
|
299
|
+
if (heavy) await lifecycleForward.enqueue(() => dispatchHandlers(heavy, "agent_start", event, ctx));
|
|
305
300
|
});
|
|
306
|
-
|
|
307
301
|
pi.on("agent_end", async (event, ctx) => {
|
|
302
|
+
if (activeLease.retired) return;
|
|
308
303
|
activeLifecycle.agentStart = null;
|
|
309
304
|
activeLifecycle.activeTools.clear();
|
|
310
|
-
|
|
305
|
+
const heavy = loadedHeavy?.heavy;
|
|
306
|
+
if (heavy) await lifecycleForward.enqueue(() => dispatchHandlers(heavy, "agent_end", event, ctx));
|
|
311
307
|
});
|
|
312
|
-
|
|
313
308
|
pi.on("tool_execution_start", async (event, ctx) => {
|
|
314
|
-
|
|
315
|
-
|
|
309
|
+
if (activeLease.retired) return;
|
|
310
|
+
const lease = activeLease;
|
|
311
|
+
const toolSnapshot: LifecycleSnapshot<"tool_execution_start"> = { event, ctx };
|
|
312
|
+
activeLifecycle.activeTools.set(event.toolCallId, toolSnapshot);
|
|
313
|
+
if (isInteractiveForegroundSubagentStart(event, ctx) && enabled) {
|
|
314
|
+
const session = sessionSnapshot;
|
|
315
|
+
const warmHeavy = loadedHeavy?.heavy ?? null;
|
|
316
|
+
const warmReplayComplete = warmHeavy !== null
|
|
317
|
+
&& session?.lease === lease
|
|
318
|
+
&& replayedGeneration === session.generation;
|
|
319
|
+
// Successful readiness gates launch; optional Intercom failures degrade
|
|
320
|
+
// without preventing the subagent tool itself from executing.
|
|
321
|
+
await registerAutomatically(ctx, "foreground parent warmup", true);
|
|
322
|
+
if (warmReplayComplete
|
|
323
|
+
&& activeLease === lease
|
|
324
|
+
&& !lease.retired
|
|
325
|
+
&& sessionSnapshot === session
|
|
326
|
+
&& activeLifecycle.activeTools.get(event.toolCallId) === toolSnapshot
|
|
327
|
+
&& loadedHeavy?.heavy === warmHeavy) {
|
|
328
|
+
await lifecycleForward.enqueue(() => dispatchHandlers(warmHeavy, "tool_execution_start", event, ctx));
|
|
329
|
+
}
|
|
330
|
+
return; // Cold initialization replay owns this active tool's delivery.
|
|
331
|
+
}
|
|
332
|
+
const heavy = loadedHeavy?.heavy;
|
|
333
|
+
if (heavy) await lifecycleForward.enqueue(() => dispatchHandlers(heavy, "tool_execution_start", event, ctx));
|
|
316
334
|
});
|
|
317
|
-
|
|
318
335
|
pi.on("tool_execution_end", async (event, ctx) => {
|
|
336
|
+
if (activeLease.retired) return;
|
|
319
337
|
activeLifecycle.activeTools.delete(event.toolCallId);
|
|
320
|
-
|
|
338
|
+
const heavy = loadedHeavy?.heavy;
|
|
339
|
+
if (heavy) await lifecycleForward.enqueue(() => dispatchHandlers(heavy, "tool_execution_end", event, ctx));
|
|
321
340
|
});
|
|
322
|
-
|
|
323
341
|
pi.on("model_select", async (event, ctx) => {
|
|
342
|
+
if (activeLease.retired) return;
|
|
324
343
|
activeLifecycle.modelSelect = { event, ctx };
|
|
325
|
-
|
|
344
|
+
const heavy = loadedHeavy?.heavy;
|
|
345
|
+
if (heavy) await lifecycleForward.enqueue(() => dispatchHandlers(heavy, "model_select", event, ctx));
|
|
326
346
|
});
|
|
327
|
-
|
|
328
347
|
pi.registerShortcut("alt+m", {
|
|
329
348
|
description: "Open session intercom overlay",
|
|
330
349
|
handler: async (ctx) => {
|
|
331
|
-
const
|
|
332
|
-
|
|
350
|
+
const handle = await loadHeavy(ctx);
|
|
351
|
+
handle.assertCurrent();
|
|
352
|
+
const handler = handle.heavy.shortcuts.get("alt+m")?.handler;
|
|
333
353
|
if (!handler) throw new Error("Intercom shortcut implementation not found: alt+m");
|
|
334
354
|
await handler(ctx);
|
|
355
|
+
handle.assertCurrent();
|
|
335
356
|
},
|
|
336
357
|
});
|
|
337
|
-
|
|
338
358
|
for (const eventName of [SUBAGENT_CONTROL_INTERCOM_EVENT, SUBAGENT_RESULT_INTERCOM_EVENT] as const) {
|
|
339
359
|
pi.events.on(eventName, (payload) => {
|
|
340
|
-
void loadHeavy().then(
|
|
360
|
+
void loadHeavy().then(async (handle) => {
|
|
361
|
+
handle.assertCurrent();
|
|
362
|
+
await dispatchEventHandlers(handle.heavy, eventName, payload);
|
|
363
|
+
handle.assertCurrent();
|
|
364
|
+
}).catch((error) => {
|
|
365
|
+
rejectLazyResultRelay(pi, eventName, payload, error);
|
|
341
366
|
console.error(`Intercom event relay failed (${eventName}):`, error);
|
|
342
367
|
});
|
|
343
368
|
});
|
|
344
369
|
}
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
pi.on("session_start", (_event, ctx) => {
|
|
348
|
-
void loadHeavy(ctx).catch((error) => {
|
|
349
|
-
console.error("Intercom initialization failed:", error);
|
|
350
|
-
});
|
|
351
|
-
});
|
|
352
|
-
}
|
|
353
|
-
|
|
370
|
+
// Bridged children are registered synchronously by the primary session-start
|
|
371
|
+
// handler, before their first agent turn can send or receive intercom messages.
|
|
354
372
|
pi.registerTool({
|
|
355
373
|
name: "intercom",
|
|
356
374
|
label: "Intercom",
|
|
357
375
|
description: `Send a message to another local agent session running on this machine.
|
|
358
376
|
Use this to communicate findings, request help, or coordinate work with other sessions.
|
|
359
|
-
|
|
360
377
|
Usage:
|
|
361
378
|
intercom({ action: "list" }) → List active sessions
|
|
362
379
|
intercom({ action: "send", to: "session-name", message: "..." }) → Send message
|
|
@@ -378,14 +395,13 @@ Usage:
|
|
|
378
395
|
replyTo: Type.Optional(Type.String({ description: "Message ID to reply to (for threading or responding to an 'ask')" })),
|
|
379
396
|
}),
|
|
380
397
|
execute: (...args) => executeHeavyTool(loadHeavy, "intercom", args),
|
|
381
|
-
renderResult: (...args) => renderHeavyToolResult(loadedHeavy, "intercom", args),
|
|
398
|
+
renderResult: (...args) => renderHeavyToolResult(loadedHeavy?.heavy ?? null, "intercom", args),
|
|
382
399
|
renderCall(args, theme) {
|
|
383
400
|
const input = args as { action?: string; to?: string; message?: string };
|
|
384
401
|
const target = input.to ? ` ${input.to}` : "";
|
|
385
402
|
return new Text(theme.fg("toolTitle", theme.bold(`intercom ${input.action ?? ""}`)) + theme.fg("accent", target), 0, 0);
|
|
386
403
|
},
|
|
387
404
|
});
|
|
388
|
-
|
|
389
405
|
if (hasSubagentIntercomEnv()) {
|
|
390
406
|
pi.registerTool({
|
|
391
407
|
name: "contact_supervisor",
|
|
@@ -419,7 +435,7 @@ Usage:
|
|
|
419
435
|
}, { description: "Structured interview request for reason='interview_request'" })),
|
|
420
436
|
}),
|
|
421
437
|
execute: (...args) => executeHeavyTool(loadHeavy, "contact_supervisor", args),
|
|
422
|
-
renderResult: (...args) => renderHeavyToolResult(loadedHeavy, "contact_supervisor", args),
|
|
438
|
+
renderResult: (...args) => renderHeavyToolResult(loadedHeavy?.heavy ?? null, "contact_supervisor", args),
|
|
423
439
|
renderCall(args, theme) {
|
|
424
440
|
const input = args as { reason?: string; message?: string; interview?: { title?: string } };
|
|
425
441
|
const reason = input.reason ?? "contact";
|