@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
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Race one caller's cancellation against a shared producer without forwarding
|
|
3
|
+
* cancellation to, or otherwise taking ownership of, that producer.
|
|
4
|
+
*/
|
|
5
|
+
export function waitForCaller<T>(
|
|
6
|
+
getSharedPromise: () => Promise<T>,
|
|
7
|
+
signal?: AbortSignal,
|
|
8
|
+
): Promise<T> {
|
|
9
|
+
signal?.throwIfAborted();
|
|
10
|
+
const sharedPromise = getSharedPromise();
|
|
11
|
+
if (!signal) return sharedPromise;
|
|
12
|
+
|
|
13
|
+
return new Promise<T>((resolve, reject) => {
|
|
14
|
+
let callerSettled = false;
|
|
15
|
+
const finishCaller = (settle: () => void): void => {
|
|
16
|
+
if (callerSettled) return;
|
|
17
|
+
callerSettled = true;
|
|
18
|
+
signal.removeEventListener("abort", onAbort);
|
|
19
|
+
settle();
|
|
20
|
+
};
|
|
21
|
+
const onAbort = (): void => finishCaller(() => reject(signal.reason));
|
|
22
|
+
|
|
23
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
24
|
+
void sharedPromise.then(
|
|
25
|
+
(value) => finishCaller(() => resolve(value)),
|
|
26
|
+
(error) => finishCaller(() => reject(error)),
|
|
27
|
+
);
|
|
28
|
+
if (signal.aborted) onAbort();
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Race caller cancellation while retaining responsibility for a value that may
|
|
34
|
+
* be produced after the caller has gone away.
|
|
35
|
+
*/
|
|
36
|
+
export async function waitForCallerWithLateCleanup<T>(
|
|
37
|
+
getSharedPromise: () => Promise<T>,
|
|
38
|
+
signal: AbortSignal | undefined,
|
|
39
|
+
cleanupLate: (value: T) => void | Promise<void>,
|
|
40
|
+
): Promise<T> {
|
|
41
|
+
const sharedPromise = getSharedPromise();
|
|
42
|
+
try {
|
|
43
|
+
return await waitForCaller(() => sharedPromise, signal);
|
|
44
|
+
} catch (error) {
|
|
45
|
+
if (signal?.aborted) {
|
|
46
|
+
void sharedPromise.then(cleanupLate, () => undefined);
|
|
47
|
+
}
|
|
48
|
+
throw error;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import type { ExtensionAPI } from "@bastani/atomic";
|
|
2
|
+
import type { McpExtensionState } from "./state.js";
|
|
3
|
+
|
|
4
|
+
interface CommandStateLease {
|
|
5
|
+
readonly state: McpExtensionState;
|
|
6
|
+
readonly assertActive: () => void;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export function registerMcpCommands(
|
|
10
|
+
pi: ExtensionAPI,
|
|
11
|
+
earlyConfigPath: string | undefined,
|
|
12
|
+
acquireState: () => Promise<CommandStateLease>,
|
|
13
|
+
): void {
|
|
14
|
+
pi.registerCommand("mcp", {
|
|
15
|
+
description: "Show MCP server status",
|
|
16
|
+
handler: async (args, ctx) => {
|
|
17
|
+
let lease: CommandStateLease;
|
|
18
|
+
try {
|
|
19
|
+
lease = await acquireState();
|
|
20
|
+
} catch (error) {
|
|
21
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
22
|
+
if (ctx.hasUI) ctx.ui.notify(`MCP initialization failed: ${message}`, "error");
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
const { showStatus, showTools, reconnectServers, logoutServer, openMcpPanel, openMcpSetup } = await import("./commands.js");
|
|
26
|
+
try { lease.assertActive(); } catch { return; }
|
|
27
|
+
const parts = args?.trim()?.split(/\s+/) ?? [];
|
|
28
|
+
const subcommand = parts[0] ?? "";
|
|
29
|
+
const targetServer = parts[1];
|
|
30
|
+
const rest = parts.slice(1).join(" ");
|
|
31
|
+
switch (subcommand) {
|
|
32
|
+
case "reconnect": await reconnectServers(lease.state, ctx, targetServer); break;
|
|
33
|
+
case "tools": await showTools(lease.state, ctx); break;
|
|
34
|
+
case "setup": {
|
|
35
|
+
const result = await openMcpSetup(lease.state, pi, ctx, earlyConfigPath, "setup");
|
|
36
|
+
if (result?.configChanged) await ctx.reload();
|
|
37
|
+
break;
|
|
38
|
+
}
|
|
39
|
+
case "logout": {
|
|
40
|
+
if (!rest) {
|
|
41
|
+
if (ctx.hasUI) ctx.ui.notify("Usage: /mcp logout <server>", "error");
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
await logoutServer(rest, lease.state, ctx);
|
|
45
|
+
break;
|
|
46
|
+
}
|
|
47
|
+
case "status":
|
|
48
|
+
case "":
|
|
49
|
+
default:
|
|
50
|
+
if (ctx.hasUI) {
|
|
51
|
+
const result = await openMcpPanel(lease.state, pi, ctx, earlyConfigPath);
|
|
52
|
+
if (result?.configChanged) await ctx.reload();
|
|
53
|
+
} else {
|
|
54
|
+
await showStatus(lease.state, ctx);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
},
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
pi.registerCommand("mcp-auth", {
|
|
61
|
+
description: "Authenticate with an MCP server (OAuth)",
|
|
62
|
+
handler: async (args, ctx) => {
|
|
63
|
+
const serverName = args?.trim();
|
|
64
|
+
if (!serverName && !ctx.hasUI) return;
|
|
65
|
+
let lease: CommandStateLease;
|
|
66
|
+
try {
|
|
67
|
+
lease = await acquireState();
|
|
68
|
+
} catch (error) {
|
|
69
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
70
|
+
if (ctx.hasUI) ctx.ui.notify(`MCP initialization failed: ${message}`, "error");
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
const { authenticateServer, openMcpAuthPanel } = await import("./commands.js");
|
|
74
|
+
try { lease.assertActive(); } catch { return; }
|
|
75
|
+
if (!serverName) {
|
|
76
|
+
await openMcpAuthPanel(lease.state, pi, ctx, earlyConfigPath);
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
await authenticateServer(serverName, lease.state.config, ctx);
|
|
80
|
+
},
|
|
81
|
+
});
|
|
82
|
+
}
|
|
@@ -0,0 +1,279 @@
|
|
|
1
|
+
import type { AgentToolResult, AgentToolUpdateCallback, ExtensionContext } from "@bastani/atomic";
|
|
2
|
+
import { CallToolResultSchema } from "@modelcontextprotocol/sdk/types.js";
|
|
3
|
+
import type { McpExtensionState } from "./state.js";
|
|
4
|
+
import type { DirectToolSpec, McpContent } from "./types.js";
|
|
5
|
+
import { getFailureAgeSeconds, lazyConnect } from "./init.js";
|
|
6
|
+
import { formatSchema } from "./tool-metadata.js";
|
|
7
|
+
import { transformMcpContent } from "./tool-registrar.js";
|
|
8
|
+
import { maybeStartUiSession, type UiSessionRuntime } from "./ui-session.js";
|
|
9
|
+
import { authenticate, supportsOAuth } from "./mcp-auth-flow.js";
|
|
10
|
+
import { formatAuthRequiredMessage, unflattenToolArguments } from "./utils.js";
|
|
11
|
+
import { waitForCaller, waitForCallerWithLateCleanup } from "./caller-wait.js";
|
|
12
|
+
import { notifyUiCancellation, rethrowHostAbortAfterUiCancellation } from "./apps-cancellation.js";
|
|
13
|
+
import { asCallToolResult } from "./call-tool-result.js";
|
|
14
|
+
|
|
15
|
+
interface DirectToolStateChangedDetails extends Record<string, unknown> {
|
|
16
|
+
error: "state_changed";
|
|
17
|
+
message: string;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
type DirectToolExecute = (
|
|
21
|
+
toolCallId: string,
|
|
22
|
+
params: Record<string, unknown>,
|
|
23
|
+
signal: AbortSignal | undefined,
|
|
24
|
+
onUpdate: AgentToolUpdateCallback<Record<string, unknown>> | undefined,
|
|
25
|
+
ctx: ExtensionContext,
|
|
26
|
+
) => Promise<AgentToolResult<Record<string, unknown>>>;
|
|
27
|
+
|
|
28
|
+
type IsActiveStateOwner = (candidate: McpExtensionState) => boolean;
|
|
29
|
+
type StartUiSession = typeof maybeStartUiSession;
|
|
30
|
+
|
|
31
|
+
export interface DirectToolExecutorOptions {
|
|
32
|
+
readonly startUiSession?: StartUiSession;
|
|
33
|
+
readonly startAutoAuth?: (state: McpExtensionState, serverName: string) => Promise<DirectAutoAuthResult>;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export type DirectAutoAuthResult =
|
|
37
|
+
| { status: "skipped" }
|
|
38
|
+
| { status: "success" }
|
|
39
|
+
| { status: "failed"; message: string };
|
|
40
|
+
|
|
41
|
+
function getDirectAuthRequiredMessage(
|
|
42
|
+
state: McpExtensionState,
|
|
43
|
+
serverName: string,
|
|
44
|
+
defaultMessage = `MCP server "${serverName}" requires OAuth authentication. Run /mcp-auth ${serverName} first.`,
|
|
45
|
+
): string {
|
|
46
|
+
return formatAuthRequiredMessage(state.config, serverName, defaultMessage);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function getDirectAuthFailedMessage(state: McpExtensionState, serverName: string, message: string): string {
|
|
50
|
+
const customGuidance = state.config.settings?.authRequiredMessage;
|
|
51
|
+
if (customGuidance) {
|
|
52
|
+
return `OAuth authentication failed for "${serverName}": ${message}. ${getDirectAuthRequiredMessage(state, serverName)}`;
|
|
53
|
+
}
|
|
54
|
+
return `OAuth authentication failed for "${serverName}": ${message}. Run /mcp-auth ${serverName} first.`;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
async function attemptDirectAutoAuth(
|
|
58
|
+
state: McpExtensionState,
|
|
59
|
+
serverName: string,
|
|
60
|
+
): Promise<DirectAutoAuthResult> {
|
|
61
|
+
if (state.config.settings?.autoAuth !== true) return { status: "skipped" };
|
|
62
|
+
|
|
63
|
+
const definition = state.config.mcpServers[serverName];
|
|
64
|
+
if (!definition || !supportsOAuth(definition) || !definition.url) return { status: "skipped" };
|
|
65
|
+
|
|
66
|
+
const grantType = definition.oauth ? definition.oauth.grantType ?? "authorization_code" : "authorization_code";
|
|
67
|
+
if (!state.ui && grantType !== "client_credentials") {
|
|
68
|
+
return {
|
|
69
|
+
status: "failed",
|
|
70
|
+
message: getDirectAuthRequiredMessage(
|
|
71
|
+
state,
|
|
72
|
+
serverName,
|
|
73
|
+
`MCP server "${serverName}" requires OAuth authentication. Run /mcp-auth ${serverName} in an interactive session.`,
|
|
74
|
+
),
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
try {
|
|
79
|
+
await authenticate(serverName, definition.url, definition);
|
|
80
|
+
return { status: "success" };
|
|
81
|
+
} catch (error) {
|
|
82
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
83
|
+
return { status: "failed", message: getDirectAuthFailedMessage(state, serverName, message) };
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function stateChangedResult(): AgentToolResult<DirectToolStateChangedDetails> {
|
|
88
|
+
const message = "MCP session changed before direct tool execution completed";
|
|
89
|
+
return {
|
|
90
|
+
content: [{ type: "text" as const, text: message }],
|
|
91
|
+
details: { error: "state_changed", message },
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export function createDirectToolExecutor(
|
|
96
|
+
ensureInitialized: () => Promise<McpExtensionState>,
|
|
97
|
+
isActiveStateOwner: IsActiveStateOwner,
|
|
98
|
+
spec: DirectToolSpec,
|
|
99
|
+
options: DirectToolExecutorOptions = {},
|
|
100
|
+
): DirectToolExecute {
|
|
101
|
+
const startUiSession = options.startUiSession ?? maybeStartUiSession;
|
|
102
|
+
const startAutoAuth = options.startAutoAuth ?? attemptDirectAutoAuth;
|
|
103
|
+
return async function execute(_toolCallId, params, signal) {
|
|
104
|
+
signal?.throwIfAborted();
|
|
105
|
+
let state: McpExtensionState;
|
|
106
|
+
try {
|
|
107
|
+
state = await waitForCaller(ensureInitialized, signal);
|
|
108
|
+
} catch (error) {
|
|
109
|
+
signal?.throwIfAborted();
|
|
110
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
111
|
+
return {
|
|
112
|
+
content: [{ type: "text" as const, text: `MCP initialization failed: ${message}` }],
|
|
113
|
+
details: { error: "init_failed", message },
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
signal?.throwIfAborted();
|
|
117
|
+
if (!isActiveStateOwner(state)) return stateChangedResult();
|
|
118
|
+
|
|
119
|
+
let connected = await waitForCaller(() => lazyConnect(state, spec.serverName), signal);
|
|
120
|
+
signal?.throwIfAborted();
|
|
121
|
+
if (!isActiveStateOwner(state)) return stateChangedResult();
|
|
122
|
+
let autoAuthAttempted = false;
|
|
123
|
+
|
|
124
|
+
if (!connected && state.manager.getConnection(spec.serverName)?.status === "needs-auth") {
|
|
125
|
+
autoAuthAttempted = true;
|
|
126
|
+
const autoAuth = await waitForCaller(() => startAutoAuth(state, spec.serverName), signal);
|
|
127
|
+
signal?.throwIfAborted();
|
|
128
|
+
if (!isActiveStateOwner(state)) return stateChangedResult();
|
|
129
|
+
if (autoAuth.status === "failed") {
|
|
130
|
+
return {
|
|
131
|
+
content: [{ type: "text" as const, text: autoAuth.message }],
|
|
132
|
+
details: { error: "auth_required", server: spec.serverName, message: autoAuth.message },
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
if (autoAuth.status === "success") {
|
|
136
|
+
await waitForCaller(() => state.manager.close(spec.serverName), signal);
|
|
137
|
+
signal?.throwIfAborted();
|
|
138
|
+
if (!isActiveStateOwner(state)) return stateChangedResult();
|
|
139
|
+
state.failureTracker.delete(spec.serverName);
|
|
140
|
+
connected = await waitForCaller(() => lazyConnect(state, spec.serverName), signal);
|
|
141
|
+
signal?.throwIfAborted();
|
|
142
|
+
if (!isActiveStateOwner(state)) return stateChangedResult();
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
if (!connected) {
|
|
147
|
+
const authConnection = state.manager.getConnection(spec.serverName);
|
|
148
|
+
if (authConnection?.status === "needs-auth") {
|
|
149
|
+
const message = getDirectAuthRequiredMessage(state, spec.serverName);
|
|
150
|
+
return {
|
|
151
|
+
content: [{ type: "text" as const, text: message }],
|
|
152
|
+
details: { error: "auth_required", server: spec.serverName, message, autoAuthAttempted },
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
const failedAgo = getFailureAgeSeconds(state, spec.serverName);
|
|
156
|
+
return {
|
|
157
|
+
content: [{ type: "text" as const, text: `MCP server "${spec.serverName}" not available${failedAgo !== null ? ` (failed ${failedAgo}s ago)` : ""}` }],
|
|
158
|
+
details: { error: "server_unavailable", server: spec.serverName },
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
const connection = state.manager.getConnection(spec.serverName);
|
|
163
|
+
if (!connection || connection.status !== "connected") {
|
|
164
|
+
return {
|
|
165
|
+
content: [{ type: "text" as const, text: `MCP server "${spec.serverName}" not connected` }],
|
|
166
|
+
details: { error: "not_connected", server: spec.serverName },
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
let uiSession: UiSessionRuntime | null = null;
|
|
171
|
+
let closeUiForStaleState = false;
|
|
172
|
+
let inFlightStarted = false;
|
|
173
|
+
const staleStateResult = (): AgentToolResult<DirectToolStateChangedDetails> => {
|
|
174
|
+
if (uiSession && !uiSession.reused) closeUiForStaleState = true;
|
|
175
|
+
return stateChangedResult();
|
|
176
|
+
};
|
|
177
|
+
const cancelStaleUi = async (): Promise<AgentToolResult<DirectToolStateChangedDetails>> => {
|
|
178
|
+
await notifyUiCancellation(uiSession, "MCP session changed during direct tool execution");
|
|
179
|
+
signal?.throwIfAborted();
|
|
180
|
+
return staleStateResult();
|
|
181
|
+
};
|
|
182
|
+
|
|
183
|
+
try {
|
|
184
|
+
if (!isActiveStateOwner(state)) return staleStateResult();
|
|
185
|
+
state.manager.touch(spec.serverName);
|
|
186
|
+
state.manager.incrementInFlight(spec.serverName);
|
|
187
|
+
inFlightStarted = true;
|
|
188
|
+
|
|
189
|
+
if (spec.resourceUri) {
|
|
190
|
+
const result = await connection.client.readResource({ uri: spec.resourceUri }, { signal });
|
|
191
|
+
signal?.throwIfAborted();
|
|
192
|
+
if (!isActiveStateOwner(state)) return stateChangedResult();
|
|
193
|
+
const content = (result.contents ?? []).map((item) => ({
|
|
194
|
+
type: "text" as const,
|
|
195
|
+
text: "text" in item
|
|
196
|
+
? item.text
|
|
197
|
+
: ("blob" in item ? `[Binary data: ${item.mimeType ?? "unknown"}]` : JSON.stringify(item)),
|
|
198
|
+
}));
|
|
199
|
+
return {
|
|
200
|
+
content: content.length > 0 ? content : [{ type: "text" as const, text: "(empty resource)" }],
|
|
201
|
+
details: { server: spec.serverName, resourceUri: spec.resourceUri },
|
|
202
|
+
};
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
const hasUi = !!spec.uiResourceUri;
|
|
206
|
+
uiSession = hasUi
|
|
207
|
+
? await waitForCallerWithLateCleanup(
|
|
208
|
+
() => startUiSession(state, {
|
|
209
|
+
serverName: spec.serverName,
|
|
210
|
+
toolName: spec.originalName,
|
|
211
|
+
toolArgs: params,
|
|
212
|
+
uiResourceUri: spec.uiResourceUri!,
|
|
213
|
+
streamMode: spec.uiStreamMode,
|
|
214
|
+
}),
|
|
215
|
+
signal,
|
|
216
|
+
(lateSession) => {
|
|
217
|
+
if (lateSession && !lateSession.reused) lateSession.close("caller cancelled during UI startup");
|
|
218
|
+
},
|
|
219
|
+
)
|
|
220
|
+
: null;
|
|
221
|
+
signal?.throwIfAborted();
|
|
222
|
+
if (!isActiveStateOwner(state)) return cancelStaleUi();
|
|
223
|
+
|
|
224
|
+
const sdkResult = await connection.client.callTool({
|
|
225
|
+
name: spec.originalName,
|
|
226
|
+
arguments: unflattenToolArguments(params, spec.inputSchema),
|
|
227
|
+
_meta: uiSession?.requestMeta,
|
|
228
|
+
}, CallToolResultSchema, { signal });
|
|
229
|
+
signal?.throwIfAborted();
|
|
230
|
+
if (!isActiveStateOwner(state)) return cancelStaleUi();
|
|
231
|
+
const result = asCallToolResult(sdkResult);
|
|
232
|
+
uiSession?.sendToolResult(result);
|
|
233
|
+
|
|
234
|
+
const content = transformMcpContent((result.content ?? []) as McpContent[]);
|
|
235
|
+
if (result.isError) {
|
|
236
|
+
let errorText = content.filter((item) => item.type === "text").map((item) => item.text).join("\n") || "Tool execution failed";
|
|
237
|
+
if (spec.inputSchema) errorText += `\n\nExpected parameters:\n${formatSchema(spec.inputSchema)}`;
|
|
238
|
+
return {
|
|
239
|
+
content: [{ type: "text" as const, text: `Error: ${errorText}` }],
|
|
240
|
+
details: { error: "tool_error", server: spec.serverName },
|
|
241
|
+
};
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
const resultText = content.filter((item) => item.type === "text").map((item) => item.text).join("\n") || "(empty result)";
|
|
245
|
+
if (hasUi) {
|
|
246
|
+
const uiMessage = uiSession?.reused
|
|
247
|
+
? "Updated the open UI."
|
|
248
|
+
: "📺 Interactive UI is now open in your browser. I'll respond to your prompts and intents as you interact with it.";
|
|
249
|
+
return {
|
|
250
|
+
content: [{ type: "text" as const, text: `${resultText}\n\n${uiMessage}` }],
|
|
251
|
+
details: { server: spec.serverName, tool: spec.originalName, uiOpen: true },
|
|
252
|
+
};
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
return {
|
|
256
|
+
content: content.length > 0 ? content : [{ type: "text" as const, text: "(empty result)" }],
|
|
257
|
+
details: { server: spec.serverName, tool: spec.originalName },
|
|
258
|
+
};
|
|
259
|
+
} catch (error) {
|
|
260
|
+
await rethrowHostAbortAfterUiCancellation(signal, uiSession);
|
|
261
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
262
|
+
await notifyUiCancellation(uiSession, message);
|
|
263
|
+
signal?.throwIfAborted();
|
|
264
|
+
if (!isActiveStateOwner(state)) return staleStateResult();
|
|
265
|
+
let errorText = `Failed to call tool: ${message}`;
|
|
266
|
+
if (spec.inputSchema) errorText += `\n\nExpected parameters:\n${formatSchema(spec.inputSchema)}`;
|
|
267
|
+
return {
|
|
268
|
+
content: [{ type: "text" as const, text: errorText }],
|
|
269
|
+
details: { error: "call_failed", server: spec.serverName },
|
|
270
|
+
};
|
|
271
|
+
} finally {
|
|
272
|
+
if (uiSession && (uiSession.reused || closeUiForStaleState)) uiSession.close(closeUiForStaleState ? "stale MCP session" : undefined);
|
|
273
|
+
if (inFlightStarted) {
|
|
274
|
+
state.manager.decrementInFlight(spec.serverName);
|
|
275
|
+
if (isActiveStateOwner(state)) state.manager.touch(spec.serverName);
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
};
|
|
279
|
+
}
|