@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 +1 @@
|
|
|
1
|
-
{"version":3,"file":"interactive-model-routing.d.ts","sourceRoot":"","sources":["../../../src/modes/interactive/interactive-model-routing.ts"],"names":[],"mappings":"","sourcesContent":["import { InteractiveModeBase } from \"./interactive-mode-base.ts\";\nimport { type Api, type Model, getAgentDir, findExactModelReferenceMatch, resolveModelScope, ContextWindowSelectorComponent, formatContextWindow, copilotApiBaseUrlFromToken, copilotCatalogCacheHost, copilotCatalogCachePath, fetchCopilotModelCatalog, readCopilotCatalogCache, setActiveCopilotModelCatalog, writeCopilotCatalogCache, ModelSelectorComponent, ScopedModelsSelectorComponent, UserMessageSelectorComponent } from \"./interactive-mode-deps.ts\";\nimport { ANTHROPIC_SUBSCRIPTION_AUTH_WARNING, isAnthropicSubscriptionAuthKey } from \"./interactive-mode-helpers.ts\";\n\nInteractiveModeBase.prototype.handleModelCommand = async function(this: InteractiveModeBase, searchTerm?: string): Promise<void> {\n if (!searchTerm) {\n this.showModelSelector();\n return;\n }\n\n const model = await this.findExactModelMatch(searchTerm);\n if (model) {\n try {\n await this.session.setModel(model);\n this.footer.invalidate();\n this.updateEditorBorderColor();\n this.showStatus(`Model: ${model.id}`);\n void this.maybeWarnAboutAnthropicSubscriptionAuth(model);\n this.checkDaxnutsEasterEgg(model);\n } catch (error) {\n this.showError(error instanceof Error ? error.message : String(error));\n }\n return;\n }\n\n this.showModelSelector(searchTerm);\n };\n\nInteractiveModeBase.prototype.findExactModelMatch = async function(this: InteractiveModeBase, searchTerm: string): Promise<Model<Api> | undefined> {\n const models = await this.getModelCandidates();\n return findExactModelReferenceMatch(searchTerm, models);\n };\n\nInteractiveModeBase.prototype.getModelCandidates = async function(this: InteractiveModeBase): Promise<Model<Api>[]> {\n if (this.session.scopedModels.length > 0) {\n return this.session.scopedModels.map((scoped) => scoped.model);\n }\n\n await this.refreshCopilotModelCatalog();\n this.session.modelRegistry.refresh();\n try {\n return await this.session.modelRegistry.getAvailable();\n } catch {\n return [];\n }\n };\n\nInteractiveModeBase.prototype.refreshCopilotModelCatalog = async function(this: InteractiveModeBase): Promise<void> {\n if (this.copilotCatalogApplied) return;\n if (!this.copilotCatalogInFlight) {\n this.copilotCatalogInFlight = this.loadCopilotModelCatalog();\n }\n try {\n await this.copilotCatalogInFlight;\n } finally {\n this.copilotCatalogInFlight = undefined;\n }\n };\n\nInteractiveModeBase.prototype.loadCopilotModelCatalog = async function(this: InteractiveModeBase): Promise<void> {\n const registry = this.session.modelRegistry;\n // Gate: do nothing unless the user has a Copilot token, including COPILOT_GITHUB_TOKEN env auth.\n try {\n const token = await registry.getApiKeyForProvider(\"github-copilot\");\n if (!token) return;\n const baseUrl = copilotApiBaseUrlFromToken(token);\n const cachePath = copilotCatalogCachePath(getAgentDir());\n let catalog = readCopilotCatalogCache(cachePath, { host: copilotCatalogCacheHost(baseUrl) });\n if (!catalog) {\n catalog = await fetchCopilotModelCatalog({ token, baseUrl });\n writeCopilotCatalogCache(cachePath, baseUrl, catalog);\n }\n setActiveCopilotModelCatalog(catalog);\n registry.refresh();\n this.session.refreshCurrentModelFromRegistry();\n this.copilotCatalogApplied = true;\n } catch {\n // Best-effort: leave the active catalog as-is on any failure (offline, auth, parse).\n }\n };\n\nInteractiveModeBase.prototype.updateAvailableProviderCount = async function(this: InteractiveModeBase): Promise<void> {\n const models = await this.getModelCandidates();\n const uniqueProviders = new Set(models.map((m) => m.provider));\n this.footerDataProvider.setAvailableProviderCount(uniqueProviders.size);\n };\n\nInteractiveModeBase.prototype.maybeWarnAboutAnthropicSubscriptionAuth = async function(this: InteractiveModeBase, model: Model<Api> | undefined = this.session.model, targetContainer = this.chatContainer): Promise<void> {\n if (this.settingsManager.getWarnings().anthropicExtraUsage === false) {\n return;\n }\n if (this.anthropicSubscriptionWarningShown) {\n return;\n }\n if (!model || model.provider !== \"anthropic\") {\n return;\n }\n\n const storedCredential =\n this.session.modelRegistry.authStorage.get(\"anthropic\");\n if (storedCredential?.type === \"oauth\") {\n this.anthropicSubscriptionWarningShown = true;\n this.showWarning(ANTHROPIC_SUBSCRIPTION_AUTH_WARNING, targetContainer);\n return;\n }\n\n try {\n const apiKey = await this.session.modelRegistry.getApiKeyForProvider(\n model.provider,\n );\n if (!isAnthropicSubscriptionAuthKey(apiKey)) {\n return;\n }\n this.anthropicSubscriptionWarningShown = true;\n this.showWarning(ANTHROPIC_SUBSCRIPTION_AUTH_WARNING, targetContainer);\n } catch {\n // Ignore auth lookup failures for warning-only checks.\n }\n };\n\nInteractiveModeBase.prototype.showModelSelector = function(this: InteractiveModeBase, initialSearchInput?: string): void {\n this.showSelector((done) => {\n const selector = new ModelSelectorComponent(\n this.ui,\n this.session.model,\n this.settingsManager,\n this.session.modelRegistry,\n this.session.scopedModels,\n async (model) => {\n try {\n await this.session.setModel(model);\n this.footer.invalidate();\n this.updateEditorBorderColor();\n done();\n void this.maybeWarnAboutAnthropicSubscriptionAuth(model);\n this.checkDaxnutsEasterEgg(model);\n if (this.session.supportsContextWindowSelection()) {\n this.showContextWindowSelector(model);\n } else {\n this.showStatus(`Model: ${model.id}`);\n }\n } catch (error) {\n done();\n this.showError(\n error instanceof Error ? error.message : String(error),\n );\n }\n },\n () => {\n done();\n this.ui.requestRender();\n },\n initialSearchInput,\n );\n return { component: selector, focus: selector };\n });\n };\n\nInteractiveModeBase.prototype.showContextWindowSelector = function(this: InteractiveModeBase, model: Model<Api>): void {\n const availableContextWindows = this.session.getAvailableContextWindows();\n const currentContextWindow =\n this.session.model?.contextWindow ?? availableContextWindows[0] ?? 0;\n this.showSelector((done) => {\n const selector = new ContextWindowSelectorComponent(\n model.name ?? model.id,\n availableContextWindows,\n currentContextWindow,\n async (contextWindow) => {\n try {\n this.session.setContextWindow(contextWindow, {\n persistDefault: true,\n });\n this.footer.invalidate();\n this.usageMeter.invalidate();\n this.updateEditorBorderColor();\n done();\n this.showStatus(\n `Model: ${model.id} \\u00b7 ${formatContextWindow(contextWindow)} context`,\n );\n } catch (error) {\n done();\n this.showError(\n error instanceof Error ? error.message : String(error),\n );\n }\n },\n () => {\n done();\n this.showStatus(`Model: ${model.id}`);\n },\n );\n return { component: selector, focus: selector };\n });\n };\n\nInteractiveModeBase.prototype.showModelsSelector = async function(this: InteractiveModeBase): Promise<void> {\n // Get all available models\n this.session.modelRegistry.refresh();\n const allModels = this.session.modelRegistry.getAvailable();\n\n if (allModels.length === 0) {\n this.showStatus(\"No models available\");\n return;\n }\n\n // Check if session has scoped models (from previous session-only changes or CLI --models)\n const sessionScopedModels = this.session.scopedModels;\n const hasSessionScope = sessionScopedModels.length > 0;\n\n // Build enabled model IDs from session state or settings\n let currentEnabledIds: string[] | null = null;\n\n if (hasSessionScope) {\n // Use current session's scoped models\n currentEnabledIds = sessionScopedModels.map(\n (scoped) => `${scoped.model.provider}/${scoped.model.id}`,\n );\n } else {\n // Fall back to settings\n const patterns = this.settingsManager.getEnabledModels();\n if (patterns !== undefined && patterns.length > 0) {\n const scopedModels = await resolveModelScope(\n patterns,\n this.session.modelRegistry,\n );\n currentEnabledIds = scopedModels.map(\n (scoped) => `${scoped.model.provider}/${scoped.model.id}`,\n );\n }\n }\n\n // Helper to update session's scoped models (session-only, no persist)\n const updateSessionModels = async (enabledIds: string[] | null) => {\n currentEnabledIds = enabledIds === null ? null : [...enabledIds];\n if (\n enabledIds &&\n enabledIds.length > 0 &&\n enabledIds.length < allModels.length\n ) {\n const newScopedModels = await resolveModelScope(\n enabledIds,\n this.session.modelRegistry,\n );\n this.session.setScopedModels(\n newScopedModels.map((sm) => ({\n model: sm.model,\n thinkingLevel: sm.thinkingLevel,\n })),\n );\n } else {\n // All enabled or none enabled = no filter\n this.session.setScopedModels([]);\n }\n await this.updateAvailableProviderCount();\n this.setupAutocompleteProvider();\n this.ui.requestRender();\n };\n\n this.showSelector((done) => {\n const selector = new ScopedModelsSelectorComponent(\n {\n allModels,\n enabledModelIds: currentEnabledIds,\n },\n {\n onChange: async (enabledIds) => {\n await updateSessionModels(enabledIds);\n },\n onPersist: (enabledIds) => {\n // Persist to settings\n const newPatterns =\n enabledIds === null || enabledIds.length === allModels.length\n ? undefined // All enabled = clear filter\n : enabledIds;\n this.settingsManager.setEnabledModels(\n newPatterns ? [...newPatterns] : undefined,\n );\n this.showStatus(\"Model selection saved to settings\");\n },\n onCancel: () => {\n done();\n this.ui.requestRender();\n },\n },\n );\n return { component: selector, focus: selector };\n });\n };\n\nInteractiveModeBase.prototype.showUserMessageSelector = function(this: InteractiveModeBase): void {\n const userMessages = this.session.getUserMessagesForForking();\n\n if (userMessages.length === 0) {\n this.showStatus(\"No messages to fork from\");\n return;\n }\n\n const initialSelectedId = userMessages[userMessages.length - 1]?.entryId;\n\n this.showSelector((done) => {\n const selector = new UserMessageSelectorComponent(\n userMessages.map((m) => ({ id: m.entryId, text: m.text })),\n async (entryId) => {\n try {\n const result = await this.runtimeHost.fork(entryId);\n if (result.cancelled) {\n done();\n this.ui.requestRender();\n return;\n }\n\n this.renderCurrentSessionState();\n this.editor.setText(result.selectedText ?? \"\");\n done();\n this.showStatus(\"Forked to new session\");\n } catch (error: unknown) {\n done();\n this.showError(\n error instanceof Error ? error.message : String(error),\n );\n }\n },\n () => {\n done();\n this.ui.requestRender();\n },\n initialSelectedId,\n );\n return { component: selector, focus: selector.getMessageList() };\n });\n };\n"]}
|
|
1
|
+
{"version":3,"file":"interactive-model-routing.d.ts","sourceRoot":"","sources":["../../../src/modes/interactive/interactive-model-routing.ts"],"names":[],"mappings":"","sourcesContent":["import { InteractiveModeBase } from \"./interactive-mode-base.ts\";\nimport { type Api, type Model, getAgentDir, findExactModelReferenceMatch, resolveModelScope, ContextWindowSelectorComponent, formatContextWindow, copilotApiBaseUrlFromToken, copilotCatalogCacheHost, copilotCatalogCachePath, fetchCopilotModelCatalog, readCopilotCatalogCache, setActiveCopilotModelCatalog, writeCopilotCatalogCache, ModelSelectorComponent, ScopedModelsSelectorComponent, UserMessageSelectorComponent } from \"./interactive-mode-deps.ts\";\nimport { ANTHROPIC_SUBSCRIPTION_AUTH_WARNING, isAnthropicSubscriptionAuthKey } from \"./interactive-mode-helpers.ts\";\n\nInteractiveModeBase.prototype.handleModelCommand = async function(this: InteractiveModeBase, searchTerm?: string): Promise<void> {\n if (!searchTerm) {\n this.showModelSelector();\n return;\n }\n\n const model = await this.findExactModelMatch(searchTerm);\n if (model) {\n try {\n await this.session.setModel(model);\n this.footer.invalidate();\n this.updateEditorBorderColor();\n this.showStatus(`Model: ${model.id}`);\n void this.maybeWarnAboutAnthropicSubscriptionAuth(model);\n this.checkDaxnutsEasterEgg(model);\n } catch (error) {\n this.showError(error instanceof Error ? error.message : String(error));\n }\n return;\n }\n\n this.showModelSelector(searchTerm);\n };\n\nInteractiveModeBase.prototype.findExactModelMatch = async function(this: InteractiveModeBase, searchTerm: string): Promise<Model<Api> | undefined> {\n const models = await this.getModelCandidates();\n return findExactModelReferenceMatch(searchTerm, models);\n };\n\nInteractiveModeBase.prototype.getModelCandidates = async function(this: InteractiveModeBase): Promise<Model<Api>[]> {\n if (this.session.scopedModels.length > 0) {\n return this.session.scopedModels.map((scoped) => scoped.model);\n }\n\n await this.refreshCopilotModelCatalog();\n this.session.modelRegistry.refresh();\n try {\n return await this.session.modelRegistry.getAvailable();\n } catch {\n return [];\n }\n };\n\nInteractiveModeBase.prototype.refreshCopilotModelCatalog = async function(this: InteractiveModeBase): Promise<void> {\n if (this.copilotCatalogApplied) return;\n if (!this.copilotCatalogInFlight) {\n this.copilotCatalogInFlight = this.loadCopilotModelCatalog();\n }\n try {\n await this.copilotCatalogInFlight;\n } finally {\n this.copilotCatalogInFlight = undefined;\n }\n };\n\nInteractiveModeBase.prototype.loadCopilotModelCatalog = async function(this: InteractiveModeBase): Promise<void> {\n const registry = this.session.modelRegistry;\n // Gate: do nothing unless the user has a Copilot token, including COPILOT_GITHUB_TOKEN env auth.\n try {\n const token = await registry.getApiKeyForProvider(\"github-copilot\");\n if (!token) return;\n const baseUrl = copilotApiBaseUrlFromToken(token);\n const cachePath = copilotCatalogCachePath(getAgentDir());\n let catalog = readCopilotCatalogCache(cachePath, { host: copilotCatalogCacheHost(baseUrl) });\n if (!catalog) {\n catalog = await fetchCopilotModelCatalog({ token, baseUrl });\n writeCopilotCatalogCache(cachePath, baseUrl, catalog);\n }\n setActiveCopilotModelCatalog(catalog);\n registry.refresh();\n this.session.refreshCurrentModelFromRegistry();\n this.copilotCatalogApplied = true;\n } catch {\n // Best-effort: leave the active catalog as-is on any failure (offline, auth, parse).\n }\n };\n\nInteractiveModeBase.prototype.updateAvailableProviderCount = async function(this: InteractiveModeBase): Promise<void> {\n const models = await this.getModelCandidates();\n const uniqueProviders = new Set(models.map((m) => m.provider));\n this.footerDataProvider.setAvailableProviderCount(uniqueProviders.size);\n };\n\nInteractiveModeBase.prototype.maybeWarnAboutAnthropicSubscriptionAuth = async function(this: InteractiveModeBase, model: Model<Api> | undefined = this.session.model, targetContainer = this.chatContainer): Promise<void> {\n if (this.settingsManager.getWarnings().anthropicExtraUsage === false) {\n return;\n }\n if (this.anthropicSubscriptionWarningShown) {\n return;\n }\n if (!model || model.provider !== \"anthropic\") {\n return;\n }\n\n const storedCredential =\n this.session.modelRegistry.authStorage.get(\"anthropic\");\n if (storedCredential?.type === \"oauth\") {\n this.anthropicSubscriptionWarningShown = true;\n this.showWarning(ANTHROPIC_SUBSCRIPTION_AUTH_WARNING, targetContainer);\n return;\n }\n\n try {\n const apiKey = await this.session.modelRegistry.getApiKeyForProvider(\n model.provider,\n );\n if (!isAnthropicSubscriptionAuthKey(apiKey)) {\n return;\n }\n this.anthropicSubscriptionWarningShown = true;\n this.showWarning(ANTHROPIC_SUBSCRIPTION_AUTH_WARNING, targetContainer);\n } catch {\n // Ignore auth lookup failures for warning-only checks.\n }\n };\n\nInteractiveModeBase.prototype.showModelSelector = function(this: InteractiveModeBase, initialSearchInput?: string): void {\n this.showSelector((done) => {\n const selector = new ModelSelectorComponent(\n this.ui,\n this.session.model,\n this.settingsManager,\n this.session.modelRegistry,\n this.session.scopedModels,\n async (model) => {\n try {\n await this.session.setModel(model);\n this.footer.invalidate();\n this.updateEditorBorderColor();\n done();\n void this.maybeWarnAboutAnthropicSubscriptionAuth(model);\n this.checkDaxnutsEasterEgg(model);\n if (this.session.supportsContextWindowSelection()) {\n this.showContextWindowSelector(model);\n } else {\n this.showStatus(`Model: ${model.id}`);\n }\n } catch (error) {\n done();\n this.showError(\n error instanceof Error ? error.message : String(error),\n );\n }\n },\n () => {\n done();\n this.ui.requestRender();\n },\n initialSearchInput,\n );\n return { component: selector, focus: selector };\n });\n };\n\nInteractiveModeBase.prototype.showContextWindowSelector = function(this: InteractiveModeBase, model: Model<Api>): void {\n const availableContextWindows = this.session.getAvailableContextWindows();\n const currentContextWindow =\n this.session.model?.contextWindow ?? availableContextWindows[0] ?? 0;\n this.showSelector((done) => {\n const selector = new ContextWindowSelectorComponent(\n model.name ?? model.id,\n availableContextWindows,\n currentContextWindow,\n async (contextWindow) => {\n try {\n this.session.setContextWindow(contextWindow, {\n persistDefault: true,\n });\n this.footer.invalidate();\n this.usageMeter.invalidate();\n this.updateEditorBorderColor();\n done();\n this.showStatus(\n `Model: ${model.id} \\u00b7 ${formatContextWindow(contextWindow)} context`,\n );\n } catch (error) {\n done();\n this.showError(\n error instanceof Error ? error.message : String(error),\n );\n }\n },\n () => {\n done();\n this.showStatus(`Model: ${model.id}`);\n },\n );\n return { component: selector, focus: selector };\n });\n };\n\nInteractiveModeBase.prototype.showModelsSelector = async function(this: InteractiveModeBase): Promise<void> {\n // Get all available models\n this.session.modelRegistry.refresh();\n const allModels = this.session.modelRegistry.getAvailable();\n\n if (allModels.length === 0) {\n this.showStatus(\"No models available\");\n return;\n }\n\n // Check if session has scoped models (from previous session-only changes or CLI --models)\n const sessionScopedModels = this.session.scopedModels;\n const hasSessionScope = sessionScopedModels.length > 0;\n\n // Build enabled model IDs from session state or settings\n let currentEnabledIds: string[] | null = null;\n\n if (hasSessionScope) {\n // Use current session's scoped models\n currentEnabledIds = sessionScopedModels.map(\n (scoped) => `${scoped.model.provider}/${scoped.model.id}`,\n );\n } else {\n // Fall back to settings\n const patterns = this.settingsManager.getEnabledModels();\n if (patterns !== undefined && patterns.length > 0) {\n const scopedModels = await resolveModelScope(\n patterns,\n this.session.modelRegistry,\n );\n currentEnabledIds = scopedModels.map(\n (scoped) => `${scoped.model.provider}/${scoped.model.id}`,\n );\n }\n }\n\n // Helper to update session's scoped models (session-only, no persist)\n const updateSessionModels = async (enabledIds: string[] | null) => {\n currentEnabledIds = enabledIds === null ? null : [...enabledIds];\n if (\n enabledIds &&\n enabledIds.length > 0 &&\n enabledIds.length < allModels.length\n ) {\n const newScopedModels = await resolveModelScope(\n enabledIds,\n this.session.modelRegistry,\n );\n this.session.setScopedModels(\n newScopedModels.map((sm) => ({\n model: sm.model,\n thinkingLevel: sm.thinkingLevel,\n })),\n );\n } else {\n // All enabled or none enabled = no filter\n this.session.setScopedModels([]);\n }\n await this.updateAvailableProviderCount();\n this.setupAutocompleteProvider();\n this.ui.requestRender();\n };\n\n this.showSelector((done) => {\n const selector = new ScopedModelsSelectorComponent(\n {\n allModels,\n enabledModelIds: currentEnabledIds,\n },\n {\n onChange: async (enabledIds) => {\n await updateSessionModels(enabledIds);\n },\n onPersist: (enabledIds) => {\n // Persist to settings\n const newPatterns =\n enabledIds === null || enabledIds.length === allModels.length\n ? undefined // All enabled = clear filter\n : enabledIds;\n this.settingsManager.setEnabledModels(\n newPatterns ? [...newPatterns] : undefined,\n );\n this.showStatus(\"Model selection saved to settings\");\n },\n onCancel: () => {\n done();\n this.ui.requestRender();\n },\n },\n );\n return { component: selector, focus: selector };\n });\n };\n\nInteractiveModeBase.prototype.showUserMessageSelector = async function(this: InteractiveModeBase): Promise<void> {\n await this.ensureDeferredStartupComplete();\n const userMessages = this.session.getUserMessagesForForking();\n\n if (userMessages.length === 0) {\n this.showStatus(\"No messages to fork from\");\n return;\n }\n\n const initialSelectedId = userMessages[userMessages.length - 1]?.entryId;\n\n this.showSelector((done) => {\n let selectionHandled = false;\n const selector = new UserMessageSelectorComponent(\n userMessages.map((m) => ({ id: m.entryId, text: m.text })),\n async (entryId) => {\n if (selectionHandled) return;\n selectionHandled = true;\n done();\n try {\n await this.ensureDeferredStartupComplete();\n const result = await this.runtimeHost.fork(entryId);\n if (result.cancelled) {\n this.ui.requestRender();\n return;\n }\n\n this.renderCurrentSessionState();\n this.editor.setText(result.selectedText ?? \"\");\n this.showStatus(\"Forked to new session\");\n } catch (error: unknown) {\n this.showError(\n error instanceof Error ? error.message : String(error),\n );\n }\n },\n () => {\n if (selectionHandled) return;\n selectionHandled = true;\n done();\n this.ui.requestRender();\n },\n initialSelectedId,\n );\n return { component: selector, focus: selector.getMessageList() };\n });\n };\n"]}
|
|
@@ -232,7 +232,8 @@ InteractiveModeBase.prototype.showModelsSelector = async function () {
|
|
|
232
232
|
return { component: selector, focus: selector };
|
|
233
233
|
});
|
|
234
234
|
};
|
|
235
|
-
InteractiveModeBase.prototype.showUserMessageSelector = function () {
|
|
235
|
+
InteractiveModeBase.prototype.showUserMessageSelector = async function () {
|
|
236
|
+
await this.ensureDeferredStartupComplete();
|
|
236
237
|
const userMessages = this.session.getUserMessagesForForking();
|
|
237
238
|
if (userMessages.length === 0) {
|
|
238
239
|
this.showStatus("No messages to fork from");
|
|
@@ -240,24 +241,30 @@ InteractiveModeBase.prototype.showUserMessageSelector = function () {
|
|
|
240
241
|
}
|
|
241
242
|
const initialSelectedId = userMessages[userMessages.length - 1]?.entryId;
|
|
242
243
|
this.showSelector((done) => {
|
|
244
|
+
let selectionHandled = false;
|
|
243
245
|
const selector = new UserMessageSelectorComponent(userMessages.map((m) => ({ id: m.entryId, text: m.text })), async (entryId) => {
|
|
246
|
+
if (selectionHandled)
|
|
247
|
+
return;
|
|
248
|
+
selectionHandled = true;
|
|
249
|
+
done();
|
|
244
250
|
try {
|
|
251
|
+
await this.ensureDeferredStartupComplete();
|
|
245
252
|
const result = await this.runtimeHost.fork(entryId);
|
|
246
253
|
if (result.cancelled) {
|
|
247
|
-
done();
|
|
248
254
|
this.ui.requestRender();
|
|
249
255
|
return;
|
|
250
256
|
}
|
|
251
257
|
this.renderCurrentSessionState();
|
|
252
258
|
this.editor.setText(result.selectedText ?? "");
|
|
253
|
-
done();
|
|
254
259
|
this.showStatus("Forked to new session");
|
|
255
260
|
}
|
|
256
261
|
catch (error) {
|
|
257
|
-
done();
|
|
258
262
|
this.showError(error instanceof Error ? error.message : String(error));
|
|
259
263
|
}
|
|
260
264
|
}, () => {
|
|
265
|
+
if (selectionHandled)
|
|
266
|
+
return;
|
|
267
|
+
selectionHandled = true;
|
|
261
268
|
done();
|
|
262
269
|
this.ui.requestRender();
|
|
263
270
|
}, initialSelectedId);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"interactive-model-routing.js","sourceRoot":"","sources":["../../../src/modes/interactive/interactive-model-routing.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AACjE,OAAO,EAAwB,WAAW,EAAE,4BAA4B,EAAE,iBAAiB,EAAE,8BAA8B,EAAE,mBAAmB,EAAE,0BAA0B,EAAE,uBAAuB,EAAE,uBAAuB,EAAE,wBAAwB,EAAE,uBAAuB,EAAE,4BAA4B,EAAE,wBAAwB,EAAE,sBAAsB,EAAE,6BAA6B,EAAE,4BAA4B,EAAE,MAAM,4BAA4B,CAAC;AACnc,OAAO,EAAE,mCAAmC,EAAE,8BAA8B,EAAE,MAAM,+BAA+B,CAAC;AAEpH,mBAAmB,CAAC,SAAS,CAAC,kBAAkB,GAAG,KAAK,WAAqC,UAAmB;IAC5G,IAAI,CAAC,UAAU,EAAE,CAAC;QAChB,IAAI,CAAC,iBAAiB,EAAE,CAAC;QACzB,OAAO;IACT,CAAC;IAED,MAAM,KAAK,GAAG,MAAM,IAAI,CAAC,mBAAmB,CAAC,UAAU,CAAC,CAAC;IACzD,IAAI,KAAK,EAAE,CAAC;QACV,IAAI,CAAC;YACH,MAAM,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;YACnC,IAAI,CAAC,MAAM,CAAC,UAAU,EAAE,CAAC;YACzB,IAAI,CAAC,uBAAuB,EAAE,CAAC;YAC/B,IAAI,CAAC,UAAU,CAAC,UAAU,KAAK,CAAC,EAAE,EAAE,CAAC,CAAC;YACtC,KAAK,IAAI,CAAC,uCAAuC,CAAC,KAAK,CAAC,CAAC;YACzD,I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\"./interactive-mode-base.ts\";\nimport { type Api, type Model, getAgentDir, findExactModelReferenceMatch, resolveModelScope, ContextWindowSelectorComponent, formatContextWindow, copilotApiBaseUrlFromToken, copilotCatalogCacheHost, copilotCatalogCachePath, fetchCopilotModelCatalog, readCopilotCatalogCache, setActiveCopilotModelCatalog, writeCopilotCatalogCache, ModelSelectorComponent, ScopedModelsSelectorComponent, UserMessageSelectorComponent } from \"./interactive-mode-deps.ts\";\nimport { ANTHROPIC_SUBSCRIPTION_AUTH_WARNING, isAnthropicSubscriptionAuthKey } from \"./interactive-mode-helpers.ts\";\n\nInteractiveModeBase.prototype.handleModelCommand = async function(this: InteractiveModeBase, searchTerm?: string): Promise<void> {\n if (!searchTerm) {\n this.showModelSelector();\n return;\n }\n\n const model = await this.findExactModelMatch(searchTerm);\n if (model) {\n try {\n await this.session.setModel(model);\n this.footer.invalidate();\n this.updateEditorBorderColor();\n this.showStatus(`Model: ${model.id}`);\n void this.maybeWarnAboutAnthropicSubscriptionAuth(model);\n this.checkDaxnutsEasterEgg(model);\n } catch (error) {\n this.showError(error instanceof Error ? error.message : String(error));\n }\n return;\n }\n\n this.showModelSelector(searchTerm);\n };\n\nInteractiveModeBase.prototype.findExactModelMatch = async function(this: InteractiveModeBase, searchTerm: string): Promise<Model<Api> | undefined> {\n const models = await this.getModelCandidates();\n return findExactModelReferenceMatch(searchTerm, models);\n };\n\nInteractiveModeBase.prototype.getModelCandidates = async function(this: InteractiveModeBase): Promise<Model<Api>[]> {\n if (this.session.scopedModels.length > 0) {\n return this.session.scopedModels.map((scoped) => scoped.model);\n }\n\n await this.refreshCopilotModelCatalog();\n this.session.modelRegistry.refresh();\n try {\n return await this.session.modelRegistry.getAvailable();\n } catch {\n return [];\n }\n };\n\nInteractiveModeBase.prototype.refreshCopilotModelCatalog = async function(this: InteractiveModeBase): Promise<void> {\n if (this.copilotCatalogApplied) return;\n if (!this.copilotCatalogInFlight) {\n this.copilotCatalogInFlight = this.loadCopilotModelCatalog();\n }\n try {\n await this.copilotCatalogInFlight;\n } finally {\n this.copilotCatalogInFlight = undefined;\n }\n };\n\nInteractiveModeBase.prototype.loadCopilotModelCatalog = async function(this: InteractiveModeBase): Promise<void> {\n const registry = this.session.modelRegistry;\n // Gate: do nothing unless the user has a Copilot token, including COPILOT_GITHUB_TOKEN env auth.\n try {\n const token = await registry.getApiKeyForProvider(\"github-copilot\");\n if (!token) return;\n const baseUrl = copilotApiBaseUrlFromToken(token);\n const cachePath = copilotCatalogCachePath(getAgentDir());\n let catalog = readCopilotCatalogCache(cachePath, { host: copilotCatalogCacheHost(baseUrl) });\n if (!catalog) {\n catalog = await fetchCopilotModelCatalog({ token, baseUrl });\n writeCopilotCatalogCache(cachePath, baseUrl, catalog);\n }\n setActiveCopilotModelCatalog(catalog);\n registry.refresh();\n this.session.refreshCurrentModelFromRegistry();\n this.copilotCatalogApplied = true;\n } catch {\n // Best-effort: leave the active catalog as-is on any failure (offline, auth, parse).\n }\n };\n\nInteractiveModeBase.prototype.updateAvailableProviderCount = async function(this: InteractiveModeBase): Promise<void> {\n const models = await this.getModelCandidates();\n const uniqueProviders = new Set(models.map((m) => m.provider));\n this.footerDataProvider.setAvailableProviderCount(uniqueProviders.size);\n };\n\nInteractiveModeBase.prototype.maybeWarnAboutAnthropicSubscriptionAuth = async function(this: InteractiveModeBase, model: Model<Api> | undefined = this.session.model, targetContainer = this.chatContainer): Promise<void> {\n if (this.settingsManager.getWarnings().anthropicExtraUsage === false) {\n return;\n }\n if (this.anthropicSubscriptionWarningShown) {\n return;\n }\n if (!model || model.provider !== \"anthropic\") {\n return;\n }\n\n const storedCredential =\n this.session.modelRegistry.authStorage.get(\"anthropic\");\n if (storedCredential?.type === \"oauth\") {\n this.anthropicSubscriptionWarningShown = true;\n this.showWarning(ANTHROPIC_SUBSCRIPTION_AUTH_WARNING, targetContainer);\n return;\n }\n\n try {\n const apiKey = await this.session.modelRegistry.getApiKeyForProvider(\n model.provider,\n );\n if (!isAnthropicSubscriptionAuthKey(apiKey)) {\n return;\n }\n this.anthropicSubscriptionWarningShown = true;\n this.showWarning(ANTHROPIC_SUBSCRIPTION_AUTH_WARNING, targetContainer);\n } catch {\n // Ignore auth lookup failures for warning-only checks.\n }\n };\n\nInteractiveModeBase.prototype.showModelSelector = function(this: InteractiveModeBase, initialSearchInput?: string): void {\n this.showSelector((done) => {\n const selector = new ModelSelectorComponent(\n this.ui,\n this.session.model,\n this.settingsManager,\n this.session.modelRegistry,\n this.session.scopedModels,\n async (model) => {\n try {\n await this.session.setModel(model);\n this.footer.invalidate();\n this.updateEditorBorderColor();\n done();\n void this.maybeWarnAboutAnthropicSubscriptionAuth(model);\n this.checkDaxnutsEasterEgg(model);\n if (this.session.supportsContextWindowSelection()) {\n this.showContextWindowSelector(model);\n } else {\n this.showStatus(`Model: ${model.id}`);\n }\n } catch (error) {\n done();\n this.showError(\n error instanceof Error ? error.message : String(error),\n );\n }\n },\n () => {\n done();\n this.ui.requestRender();\n },\n initialSearchInput,\n );\n return { component: selector, focus: selector };\n });\n };\n\nInteractiveModeBase.prototype.showContextWindowSelector = function(this: InteractiveModeBase, model: Model<Api>): void {\n const availableContextWindows = this.session.getAvailableContextWindows();\n const currentContextWindow =\n this.session.model?.contextWindow ?? availableContextWindows[0] ?? 0;\n this.showSelector((done) => {\n const selector = new ContextWindowSelectorComponent(\n model.name ?? model.id,\n availableContextWindows,\n currentContextWindow,\n async (contextWindow) => {\n try {\n this.session.setContextWindow(contextWindow, {\n persistDefault: true,\n });\n this.footer.invalidate();\n this.usageMeter.invalidate();\n this.updateEditorBorderColor();\n done();\n this.showStatus(\n `Model: ${model.id} \\u00b7 ${formatContextWindow(contextWindow)} context`,\n );\n } catch (error) {\n done();\n this.showError(\n error instanceof Error ? error.message : String(error),\n );\n }\n },\n () => {\n done();\n this.showStatus(`Model: ${model.id}`);\n },\n );\n return { component: selector, focus: selector };\n });\n };\n\nInteractiveModeBase.prototype.showModelsSelector = async function(this: InteractiveModeBase): Promise<void> {\n // Get all available models\n this.session.modelRegistry.refresh();\n const allModels = this.session.modelRegistry.getAvailable();\n\n if (allModels.length === 0) {\n this.showStatus(\"No models available\");\n return;\n }\n\n // Check if session has scoped models (from previous session-only changes or CLI --models)\n const sessionScopedModels = this.session.scopedModels;\n const hasSessionScope = sessionScopedModels.length > 0;\n\n // Build enabled model IDs from session state or settings\n let currentEnabledIds: string[] | null = null;\n\n if (hasSessionScope) {\n // Use current session's scoped models\n currentEnabledIds = sessionScopedModels.map(\n (scoped) => `${scoped.model.provider}/${scoped.model.id}`,\n );\n } else {\n // Fall back to settings\n const patterns = this.settingsManager.getEnabledModels();\n if (patterns !== undefined && patterns.length > 0) {\n const scopedModels = await resolveModelScope(\n patterns,\n this.session.modelRegistry,\n );\n currentEnabledIds = scopedModels.map(\n (scoped) => `${scoped.model.provider}/${scoped.model.id}`,\n );\n }\n }\n\n // Helper to update session's scoped models (session-only, no persist)\n const updateSessionModels = async (enabledIds: string[] | null) => {\n currentEnabledIds = enabledIds === null ? null : [...enabledIds];\n if (\n enabledIds &&\n enabledIds.length > 0 &&\n enabledIds.length < allModels.length\n ) {\n const newScopedModels = await resolveModelScope(\n enabledIds,\n this.session.modelRegistry,\n );\n this.session.setScopedModels(\n newScopedModels.map((sm) => ({\n model: sm.model,\n thinkingLevel: sm.thinkingLevel,\n })),\n );\n } else {\n // All enabled or none enabled = no filter\n this.session.setScopedModels([]);\n }\n await this.updateAvailableProviderCount();\n this.setupAutocompleteProvider();\n this.ui.requestRender();\n };\n\n this.showSelector((done) => {\n const selector = new ScopedModelsSelectorComponent(\n {\n allModels,\n enabledModelIds: currentEnabledIds,\n },\n {\n onChange: async (enabledIds) => {\n await updateSessionModels(enabledIds);\n },\n onPersist: (enabledIds) => {\n // Persist to settings\n const newPatterns =\n enabledIds === null || enabledIds.length === allModels.length\n ? undefined // All enabled = clear filter\n : enabledIds;\n this.settingsManager.setEnabledModels(\n newPatterns ? [...newPatterns] : undefined,\n );\n this.showStatus(\"Model selection saved to settings\");\n },\n onCancel: () => {\n done();\n this.ui.requestRender();\n },\n },\n );\n return { component: selector, focus: selector };\n });\n };\n\nInteractiveModeBase.prototype.showUserMessageSelector = function(this: InteractiveModeBase): void {\n const userMessages = this.session.getUserMessagesForForking();\n\n if (userMessages.length === 0) {\n this.showStatus(\"No messages to fork from\");\n return;\n }\n\n const initialSelectedId = userMessages[userMessages.length - 1]?.entryId;\n\n this.showSelector((done) => {\n const selector = new UserMessageSelectorComponent(\n userMessages.map((m) => ({ id: m.entryId, text: m.text })),\n async (entryId) => {\n try {\n const result = await this.runtimeHost.fork(entryId);\n if (result.cancelled) {\n done();\n this.ui.requestRender();\n return;\n }\n\n this.renderCurrentSessionState();\n this.editor.setText(result.selectedText ?? \"\");\n done();\n this.showStatus(\"Forked to new session\");\n } catch (error: unknown) {\n done();\n this.showError(\n error instanceof Error ? error.message : String(error),\n );\n }\n },\n () => {\n done();\n this.ui.requestRender();\n },\n initialSelectedId,\n );\n return { component: selector, focus: selector.getMessageList() };\n });\n };\n"]}
|
|
1
|
+
{"version":3,"file":"interactive-model-routing.js","sourceRoot":"","sources":["../../../src/modes/interactive/interactive-model-routing.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AACjE,OAAO,EAAwB,WAAW,EAAE,4BAA4B,EAAE,iBAAiB,EAAE,8BAA8B,EAAE,mBAAmB,EAAE,0BAA0B,EAAE,uBAAuB,EAAE,uBAAuB,EAAE,wBAAwB,EAAE,uBAAuB,EAAE,4BAA4B,EAAE,wBAAwB,EAAE,sBAAsB,EAAE,6BAA6B,EAAE,4BAA4B,EAAE,MAAM,4BAA4B,CAAC;AACnc,OAAO,EAAE,mCAAmC,EAAE,8BAA8B,EAAE,MAAM,+BAA+B,CAAC;AAEpH,mBAAmB,CAAC,SAAS,CAAC,kBAAkB,GAAG,KAAK,WAAqC,UAAmB;IAC5G,IAAI,CAAC,UAAU,EAAE,CAAC;QAChB,IAAI,CAAC,i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,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,YAAY,IAAI,EAAE,CAAC,CAAC;gBAC/C,IAAI,CAAC,UAAU,CAAC,uBAAuB,CAAC,CAAC;YAC3C,CAAC;YAAC,OAAO,KAAc,EAAE,CAAC;gBACxB,IAAI,CAAC,SAAS,CACZ,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CACvD,CAAC;YACJ,CAAC;QACH,CAAC,EACD,GAAG,EAAE;YACH,IAAI,gBAAgB;gBAAE,OAAO;YAC7B,gBAAgB,GAAG,IAAI,CAAC;YACxB,IAAI,EAAE,CAAC;YACP,IAAI,CAAC,EAAE,CAAC,aAAa,EAAE,CAAC;QAC1B,CAAC,EACD,iBAAiB,CAClB,CAAC;QACF,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,KAAK,EAAE,QAAQ,CAAC,cAAc,EAAE,EAAE,CAAC;IACnE,CAAC,CAAC,CAAC;AACL,CAAC,CAAC","sourcesContent":["import { InteractiveModeBase } from \"./interactive-mode-base.ts\";\nimport { type Api, type Model, getAgentDir, findExactModelReferenceMatch, resolveModelScope, ContextWindowSelectorComponent, formatContextWindow, copilotApiBaseUrlFromToken, copilotCatalogCacheHost, copilotCatalogCachePath, fetchCopilotModelCatalog, readCopilotCatalogCache, setActiveCopilotModelCatalog, writeCopilotCatalogCache, ModelSelectorComponent, ScopedModelsSelectorComponent, UserMessageSelectorComponent } from \"./interactive-mode-deps.ts\";\nimport { ANTHROPIC_SUBSCRIPTION_AUTH_WARNING, isAnthropicSubscriptionAuthKey } from \"./interactive-mode-helpers.ts\";\n\nInteractiveModeBase.prototype.handleModelCommand = async function(this: InteractiveModeBase, searchTerm?: string): Promise<void> {\n if (!searchTerm) {\n this.showModelSelector();\n return;\n }\n\n const model = await this.findExactModelMatch(searchTerm);\n if (model) {\n try {\n await this.session.setModel(model);\n this.footer.invalidate();\n this.updateEditorBorderColor();\n this.showStatus(`Model: ${model.id}`);\n void this.maybeWarnAboutAnthropicSubscriptionAuth(model);\n this.checkDaxnutsEasterEgg(model);\n } catch (error) {\n this.showError(error instanceof Error ? error.message : String(error));\n }\n return;\n }\n\n this.showModelSelector(searchTerm);\n };\n\nInteractiveModeBase.prototype.findExactModelMatch = async function(this: InteractiveModeBase, searchTerm: string): Promise<Model<Api> | undefined> {\n const models = await this.getModelCandidates();\n return findExactModelReferenceMatch(searchTerm, models);\n };\n\nInteractiveModeBase.prototype.getModelCandidates = async function(this: InteractiveModeBase): Promise<Model<Api>[]> {\n if (this.session.scopedModels.length > 0) {\n return this.session.scopedModels.map((scoped) => scoped.model);\n }\n\n await this.refreshCopilotModelCatalog();\n this.session.modelRegistry.refresh();\n try {\n return await this.session.modelRegistry.getAvailable();\n } catch {\n return [];\n }\n };\n\nInteractiveModeBase.prototype.refreshCopilotModelCatalog = async function(this: InteractiveModeBase): Promise<void> {\n if (this.copilotCatalogApplied) return;\n if (!this.copilotCatalogInFlight) {\n this.copilotCatalogInFlight = this.loadCopilotModelCatalog();\n }\n try {\n await this.copilotCatalogInFlight;\n } finally {\n this.copilotCatalogInFlight = undefined;\n }\n };\n\nInteractiveModeBase.prototype.loadCopilotModelCatalog = async function(this: InteractiveModeBase): Promise<void> {\n const registry = this.session.modelRegistry;\n // Gate: do nothing unless the user has a Copilot token, including COPILOT_GITHUB_TOKEN env auth.\n try {\n const token = await registry.getApiKeyForProvider(\"github-copilot\");\n if (!token) return;\n const baseUrl = copilotApiBaseUrlFromToken(token);\n const cachePath = copilotCatalogCachePath(getAgentDir());\n let catalog = readCopilotCatalogCache(cachePath, { host: copilotCatalogCacheHost(baseUrl) });\n if (!catalog) {\n catalog = await fetchCopilotModelCatalog({ token, baseUrl });\n writeCopilotCatalogCache(cachePath, baseUrl, catalog);\n }\n setActiveCopilotModelCatalog(catalog);\n registry.refresh();\n this.session.refreshCurrentModelFromRegistry();\n this.copilotCatalogApplied = true;\n } catch {\n // Best-effort: leave the active catalog as-is on any failure (offline, auth, parse).\n }\n };\n\nInteractiveModeBase.prototype.updateAvailableProviderCount = async function(this: InteractiveModeBase): Promise<void> {\n const models = await this.getModelCandidates();\n const uniqueProviders = new Set(models.map((m) => m.provider));\n this.footerDataProvider.setAvailableProviderCount(uniqueProviders.size);\n };\n\nInteractiveModeBase.prototype.maybeWarnAboutAnthropicSubscriptionAuth = async function(this: InteractiveModeBase, model: Model<Api> | undefined = this.session.model, targetContainer = this.chatContainer): Promise<void> {\n if (this.settingsManager.getWarnings().anthropicExtraUsage === false) {\n return;\n }\n if (this.anthropicSubscriptionWarningShown) {\n return;\n }\n if (!model || model.provider !== \"anthropic\") {\n return;\n }\n\n const storedCredential =\n this.session.modelRegistry.authStorage.get(\"anthropic\");\n if (storedCredential?.type === \"oauth\") {\n this.anthropicSubscriptionWarningShown = true;\n this.showWarning(ANTHROPIC_SUBSCRIPTION_AUTH_WARNING, targetContainer);\n return;\n }\n\n try {\n const apiKey = await this.session.modelRegistry.getApiKeyForProvider(\n model.provider,\n );\n if (!isAnthropicSubscriptionAuthKey(apiKey)) {\n return;\n }\n this.anthropicSubscriptionWarningShown = true;\n this.showWarning(ANTHROPIC_SUBSCRIPTION_AUTH_WARNING, targetContainer);\n } catch {\n // Ignore auth lookup failures for warning-only checks.\n }\n };\n\nInteractiveModeBase.prototype.showModelSelector = function(this: InteractiveModeBase, initialSearchInput?: string): void {\n this.showSelector((done) => {\n const selector = new ModelSelectorComponent(\n this.ui,\n this.session.model,\n this.settingsManager,\n this.session.modelRegistry,\n this.session.scopedModels,\n async (model) => {\n try {\n await this.session.setModel(model);\n this.footer.invalidate();\n this.updateEditorBorderColor();\n done();\n void this.maybeWarnAboutAnthropicSubscriptionAuth(model);\n this.checkDaxnutsEasterEgg(model);\n if (this.session.supportsContextWindowSelection()) {\n this.showContextWindowSelector(model);\n } else {\n this.showStatus(`Model: ${model.id}`);\n }\n } catch (error) {\n done();\n this.showError(\n error instanceof Error ? error.message : String(error),\n );\n }\n },\n () => {\n done();\n this.ui.requestRender();\n },\n initialSearchInput,\n );\n return { component: selector, focus: selector };\n });\n };\n\nInteractiveModeBase.prototype.showContextWindowSelector = function(this: InteractiveModeBase, model: Model<Api>): void {\n const availableContextWindows = this.session.getAvailableContextWindows();\n const currentContextWindow =\n this.session.model?.contextWindow ?? availableContextWindows[0] ?? 0;\n this.showSelector((done) => {\n const selector = new ContextWindowSelectorComponent(\n model.name ?? model.id,\n availableContextWindows,\n currentContextWindow,\n async (contextWindow) => {\n try {\n this.session.setContextWindow(contextWindow, {\n persistDefault: true,\n });\n this.footer.invalidate();\n this.usageMeter.invalidate();\n this.updateEditorBorderColor();\n done();\n this.showStatus(\n `Model: ${model.id} \\u00b7 ${formatContextWindow(contextWindow)} context`,\n );\n } catch (error) {\n done();\n this.showError(\n error instanceof Error ? error.message : String(error),\n );\n }\n },\n () => {\n done();\n this.showStatus(`Model: ${model.id}`);\n },\n );\n return { component: selector, focus: selector };\n });\n };\n\nInteractiveModeBase.prototype.showModelsSelector = async function(this: InteractiveModeBase): Promise<void> {\n // Get all available models\n this.session.modelRegistry.refresh();\n const allModels = this.session.modelRegistry.getAvailable();\n\n if (allModels.length === 0) {\n this.showStatus(\"No models available\");\n return;\n }\n\n // Check if session has scoped models (from previous session-only changes or CLI --models)\n const sessionScopedModels = this.session.scopedModels;\n const hasSessionScope = sessionScopedModels.length > 0;\n\n // Build enabled model IDs from session state or settings\n let currentEnabledIds: string[] | null = null;\n\n if (hasSessionScope) {\n // Use current session's scoped models\n currentEnabledIds = sessionScopedModels.map(\n (scoped) => `${scoped.model.provider}/${scoped.model.id}`,\n );\n } else {\n // Fall back to settings\n const patterns = this.settingsManager.getEnabledModels();\n if (patterns !== undefined && patterns.length > 0) {\n const scopedModels = await resolveModelScope(\n patterns,\n this.session.modelRegistry,\n );\n currentEnabledIds = scopedModels.map(\n (scoped) => `${scoped.model.provider}/${scoped.model.id}`,\n );\n }\n }\n\n // Helper to update session's scoped models (session-only, no persist)\n const updateSessionModels = async (enabledIds: string[] | null) => {\n currentEnabledIds = enabledIds === null ? null : [...enabledIds];\n if (\n enabledIds &&\n enabledIds.length > 0 &&\n enabledIds.length < allModels.length\n ) {\n const newScopedModels = await resolveModelScope(\n enabledIds,\n this.session.modelRegistry,\n );\n this.session.setScopedModels(\n newScopedModels.map((sm) => ({\n model: sm.model,\n thinkingLevel: sm.thinkingLevel,\n })),\n );\n } else {\n // All enabled or none enabled = no filter\n this.session.setScopedModels([]);\n }\n await this.updateAvailableProviderCount();\n this.setupAutocompleteProvider();\n this.ui.requestRender();\n };\n\n this.showSelector((done) => {\n const selector = new ScopedModelsSelectorComponent(\n {\n allModels,\n enabledModelIds: currentEnabledIds,\n },\n {\n onChange: async (enabledIds) => {\n await updateSessionModels(enabledIds);\n },\n onPersist: (enabledIds) => {\n // Persist to settings\n const newPatterns =\n enabledIds === null || enabledIds.length === allModels.length\n ? undefined // All enabled = clear filter\n : enabledIds;\n this.settingsManager.setEnabledModels(\n newPatterns ? [...newPatterns] : undefined,\n );\n this.showStatus(\"Model selection saved to settings\");\n },\n onCancel: () => {\n done();\n this.ui.requestRender();\n },\n },\n );\n return { component: selector, focus: selector };\n });\n };\n\nInteractiveModeBase.prototype.showUserMessageSelector = async function(this: InteractiveModeBase): Promise<void> {\n await this.ensureDeferredStartupComplete();\n const userMessages = this.session.getUserMessagesForForking();\n\n if (userMessages.length === 0) {\n this.showStatus(\"No messages to fork from\");\n return;\n }\n\n const initialSelectedId = userMessages[userMessages.length - 1]?.entryId;\n\n this.showSelector((done) => {\n let selectionHandled = false;\n const selector = new UserMessageSelectorComponent(\n userMessages.map((m) => ({ id: m.entryId, text: m.text })),\n async (entryId) => {\n if (selectionHandled) return;\n selectionHandled = true;\n done();\n try {\n await this.ensureDeferredStartupComplete();\n const result = await this.runtimeHost.fork(entryId);\n if (result.cancelled) {\n this.ui.requestRender();\n return;\n }\n\n this.renderCurrentSessionState();\n this.editor.setText(result.selectedText ?? \"\");\n this.showStatus(\"Forked to new session\");\n } catch (error: unknown) {\n this.showError(\n error instanceof Error ? error.message : String(error),\n );\n }\n },\n () => {\n if (selectionHandled) return;\n selectionHandled = true;\n done();\n this.ui.requestRender();\n },\n initialSelectedId,\n );\n return { component: selector, focus: selector.getMessageList() };\n });\n };\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"interactive-process-lifecycle.d.ts","sourceRoot":"","sources":["../../../src/modes/interactive/interactive-process-lifecycle.ts"],"names":[],"mappings":"","sourcesContent":["import { InteractiveModeBase } from \"./interactive-mode-base.ts\";\nimport { chalk, killTrackedDetachedChildren } from \"./interactive-mode-deps.ts\";\nimport { formatResumeCommand, isDeadTerminalError } from \"./interactive-mode-helpers.ts\";\n\nconst SHUTDOWN_INPUT_DRAIN_MAX_MS = 250;\nconst SHUTDOWN_INPUT_DRAIN_IDLE_MS = 50;\n\nInteractiveModeBase.prototype.handleCtrlC = function(this: InteractiveModeBase): void {\n // When the agent is doing work, Ctrl+C interrupts it (matching Escape and\n // common CLI muscle memory) instead of clearing/exiting the editor. Only\n // fall back to the clear / double-press-exit behavior when idle.\n if (this.interruptActiveOperation()) {\n // Reset the double-press window so a follow-up Ctrl+C after the abort\n // does not immediately exit.\n this.lastSigintTime = 0;\n return;\n }\n const now = Date.now();\n if (now - this.lastSigintTime < 500) {\n void this.shutdown();\n } else {\n this.clearEditor();\n this.lastSigintTime = now;\n }\n };\n\nInteractiveModeBase.prototype.interruptActiveOperation = function(this: InteractiveModeBase): boolean {\n // Mirror the Escape interrupt paths so Ctrl+C aborts whichever operation is\n // currently running. Returns true when something was aborted.\n if (this.session.isStreaming) {\n this.restoreQueuedMessagesToEditor({ abort: true });\n return true;\n }\n if (this.session.isBashRunning) {\n this.session.abortBash();\n return true;\n }\n if (this.session.isCompacting) {\n this.session.abortCompaction();\n return true;\n }\n if (this.session.isRetrying) {\n this.session.abortRetry();\n return true;\n }\n return false;\n };\n\nInteractiveModeBase.prototype.handleCtrlD = function(this: InteractiveModeBase): void {\n // Only called when editor is empty (enforced by CustomEditor)\n void this.shutdown();\n };\n\nInteractiveModeBase.prototype.shutdown = async function(this: InteractiveModeBase, options?: { fromSignal?: boolean }): Promise<void> {\n if (this.isShuttingDown) return;\n this.isShuttingDown = true;\n // Keep signal handlers registered until terminal cleanup has completed.\n // `signal-exit` checks the listener list during the same SIGTERM/SIGHUP\n // dispatch and re-sends the signal if only its own listeners remain.\n\n if (options?.fromSignal) {\n await this.runtimeHost.dispose();\n this.themeController.disableAutoSync();\n // Drain any in-flight Kitty key release events briefly before stopping.\n // Keep this bounded so Ctrl+C exits do not feel stalled on Windows.\n await this.ui.terminal.drainInput(SHUTDOWN_INPUT_DRAIN_MAX_MS, SHUTDOWN_INPUT_DRAIN_IDLE_MS);\n this.stop();\n process.exit(0);\n }\n\n // Drain any in-flight Kitty key release events briefly before stopping.\n // Keep this bounded so Ctrl+C exits do not feel stalled on Windows.\n this.themeController.disableAutoSync();\n await this.ui.terminal.drainInput(SHUTDOWN_INPUT_DRAIN_MAX_MS, SHUTDOWN_INPUT_DRAIN_IDLE_MS);\n\n this.stop();\n await this.runtimeHost.dispose();\n const resumeCommand = formatResumeCommand(this.sessionManager);\n if (resumeCommand) {\n process.stdout.write(`${chalk.dim(\"To resume this session:\")} ${resumeCommand}\\n`);\n }\n process.exit(0);\n };\n\nInteractiveModeBase.prototype.emergencyTerminalExit = function(this: InteractiveModeBase): never {\n this.isShuttingDown = true;\n this.unregisterSignalHandlers();\n killTrackedDetachedChildren();\n // The terminal is gone. Do not run normal shutdown because TUI and\n // extension cleanup can write restore sequences and re-trigger EIO.\n process.exit(129);\n };\n\nInteractiveModeBase.prototype.uncaughtCrash = function(this: InteractiveModeBase, error: Error): never {\n if (this.isShuttingDown) {\n process.exit(1);\n }\n this.isShuttingDown = true;\n try {\n this.unregisterSignalHandlers();\n } catch {}\n try {\n killTrackedDetachedChildren();\n } catch {}\n try {\n this.ui.stop();\n } catch {}\n console.error(\"pi exiting due to uncaughtException:\");\n console.error(error);\n process.exit(1);\n };\n\nInteractiveModeBase.prototype.checkShutdownRequested = async function(this: InteractiveModeBase): Promise<void> {\n if (!this.shutdownRequested) return;\n await this.shutdown();\n };\n\nInteractiveModeBase.prototype.registerSignalHandlers = function(this: InteractiveModeBase): void {\n this.unregisterSignalHandlers();\n\n const signals: NodeJS.Signals[] = [\"SIGTERM\"];\n if (process.platform !== \"win32\") {\n signals.push(\"SIGHUP\");\n }\n\n for (const signal of signals) {\n const handler = () => {\n killTrackedDetachedChildren();\n void this.shutdown({ fromSignal: true });\n };\n process.prependListener(signal, handler);\n this.signalCleanupHandlers.push(() => process.off(signal, handler));\n }\n\n const sigintHandler = () => {\n this.handleCtrlC();\n };\n process.prependListener(\"SIGINT\", sigintHandler);\n this.signalCleanupHandlers.push(() => process.off(\"SIGINT\", sigintHandler));\n\n const terminalErrorHandler = (error: Error) => {\n if (isDeadTerminalError(error)) {\n this.emergencyTerminalExit();\n }\n throw error;\n };\n process.stdout.on(\"error\", terminalErrorHandler);\n process.stderr.on(\"error\", terminalErrorHandler);\n this.signalCleanupHandlers.push(() =>\n process.stdout.off(\"error\", terminalErrorHandler),\n );\n this.signalCleanupHandlers.push(() =>\n process.stderr.off(\"error\", terminalErrorHandler),\n );\n\n // Restore the terminal before the process dies on any uncaught throw.\n // Without this, an unhandled exception from extension code (or anywhere\n // in pi) leaves the terminal in raw mode with no cursor.\n const uncaughtExceptionHandler = (error: Error) =>\n this.uncaughtCrash(error);\n process.prependListener(\"uncaughtException\", uncaughtExceptionHandler);\n this.signalCleanupHandlers.push(() =>\n process.off(\"uncaughtException\", uncaughtExceptionHandler),\n );\n };\n\nInteractiveModeBase.prototype.unregisterSignalHandlers = function(this: InteractiveModeBase): void {\n for (const cleanup of this.signalCleanupHandlers) {\n cleanup();\n }\n this.signalCleanupHandlers = [];\n };\n\nInteractiveModeBase.prototype.handleCtrlZ = function(this: InteractiveModeBase): void {\n if (process.platform === \"win32\") {\n this.showStatus(\"Suspend to background is not supported on Windows\");\n return;\n }\n\n // Keep the event loop alive while suspended. Without this, stopping the TUI\n // can leave Node with no ref'ed handles, causing the process to exit on fg\n // before the SIGCONT handler gets a chance to restore the terminal.\n const suspendKeepAlive = setInterval(() => {}, 2 ** 30);\n\n // Ignore SIGINT while suspended so Ctrl+C in the terminal does not\n // kill the backgrounded process. The handler is removed on resume.\n const ignoreSigint = () => {};\n process.on(\"SIGINT\", ignoreSigint);\n\n // Set up handler to restore TUI when resumed\n process.once(\"SIGCONT\", () => {\n clearInterval(suspendKeepAlive);\n process.removeListener(\"SIGINT\", ignoreSigint);\n this.ui.start();\n this.ui.requestRender(true);\n });\n\n try {\n // Stop the TUI (restore terminal to normal mode)\n this.ui.stop();\n\n // Send SIGTSTP to process group (pid=0 means all processes in group)\n process.kill(0, \"SIGTSTP\");\n } catch (error) {\n clearInterval(suspendKeepAlive);\n process.removeListener(\"SIGINT\", ignoreSigint);\n throw error;\n }\n };\n\nInteractiveModeBase.prototype.handleFollowUp = async function(this: InteractiveModeBase): Promise<void> {\n const text = (\n this.editor.getExpandedText?.() ?? this.editor.getText()\n ).trim();\n if (!text) return;\n\n // Queue input during compaction (extension commands execute immediately)\n if (this.session.isCompacting) {\n if (this.isExtensionCommand(text)) {\n this.editor.addToHistory?.(text);\n this.editor.setText(\"\");\n await this.session.prompt(text);\n } else {\n this.queueCompactionMessage(text, \"followUp\");\n }\n return;\n }\n\n // Alt+Enter queues a follow-up message (waits until agent finishes)\n // This handles extension commands (execute immediately), prompt template expansion, and queueing\n if (this.session.isStreaming) {\n this.editor.addToHistory?.(text);\n this.editor.setText(\"\");\n await this.session.prompt(text, { streamingBehavior: \"followUp\" });\n this.updatePendingMessagesDisplay();\n this.ui.requestRender();\n }\n // If not streaming, Alt+Enter acts like regular Enter (trigger onSubmit)\n else if (this.editor.onSubmit) {\n this.editor.setText(\"\");\n this.editor.onSubmit(text);\n }\n };\n\nInteractiveModeBase.prototype.handleDequeue = function(this: InteractiveModeBase): void {\n const restored = this.restoreQueuedMessagesToEditor();\n if (restored === 0) {\n this.showStatus(\"No queued messages to restore\");\n }
|
|
1
|
+
{"version":3,"file":"interactive-process-lifecycle.d.ts","sourceRoot":"","sources":["../../../src/modes/interactive/interactive-process-lifecycle.ts"],"names":[],"mappings":"","sourcesContent":["import { InteractiveModeBase } from \"./interactive-mode-base.ts\";\nimport { chalk, killTrackedDetachedChildren } from \"./interactive-mode-deps.ts\";\nimport { formatResumeCommand, isDeadTerminalError } from \"./interactive-mode-helpers.ts\";\n\nconst SHUTDOWN_INPUT_DRAIN_MAX_MS = 250;\nconst SHUTDOWN_INPUT_DRAIN_IDLE_MS = 50;\n\nInteractiveModeBase.prototype.handleCtrlC = function(this: InteractiveModeBase): void {\n // When the agent is doing work, Ctrl+C interrupts it (matching Escape and\n // common CLI muscle memory) instead of clearing/exiting the editor. Only\n // fall back to the clear / double-press-exit behavior when idle.\n if (this.interruptActiveOperation()) {\n // Reset the double-press window so a follow-up Ctrl+C after the abort\n // does not immediately exit.\n this.lastSigintTime = 0;\n return;\n }\n const now = Date.now();\n if (now - this.lastSigintTime < 500) {\n void this.shutdown();\n } else {\n this.clearEditor();\n this.lastSigintTime = now;\n }\n };\n\nInteractiveModeBase.prototype.interruptActiveOperation = function(this: InteractiveModeBase): boolean {\n // Mirror the Escape interrupt paths so Ctrl+C aborts whichever operation is\n // currently running. Returns true when something was aborted.\n if (this.session.isStreaming) {\n this.restoreQueuedMessagesToEditor({ abort: true });\n return true;\n }\n if (this.session.isBashRunning) {\n this.session.abortBash();\n return true;\n }\n if (this.session.isCompacting) {\n this.session.abortCompaction();\n return true;\n }\n if (this.session.isRetrying) {\n this.session.abortRetry();\n return true;\n }\n return false;\n };\n\nInteractiveModeBase.prototype.handleCtrlD = function(this: InteractiveModeBase): void {\n // Only called when editor is empty (enforced by CustomEditor)\n void this.shutdown();\n };\n\nInteractiveModeBase.prototype.shutdown = async function(this: InteractiveModeBase, options?: { fromSignal?: boolean }): Promise<void> {\n if (this.isShuttingDown) return;\n this.isShuttingDown = true;\n // Keep signal handlers registered until terminal cleanup has completed.\n // `signal-exit` checks the listener list during the same SIGTERM/SIGHUP\n // dispatch and re-sends the signal if only its own listeners remain.\n\n if (options?.fromSignal) {\n await this.runtimeHost.dispose();\n this.themeController.disableAutoSync();\n // Drain any in-flight Kitty key release events briefly before stopping.\n // Keep this bounded so Ctrl+C exits do not feel stalled on Windows.\n await this.ui.terminal.drainInput(SHUTDOWN_INPUT_DRAIN_MAX_MS, SHUTDOWN_INPUT_DRAIN_IDLE_MS);\n this.stop();\n process.exit(0);\n }\n\n // Drain any in-flight Kitty key release events briefly before stopping.\n // Keep this bounded so Ctrl+C exits do not feel stalled on Windows.\n this.themeController.disableAutoSync();\n await this.ui.terminal.drainInput(SHUTDOWN_INPUT_DRAIN_MAX_MS, SHUTDOWN_INPUT_DRAIN_IDLE_MS);\n\n this.stop();\n await this.runtimeHost.dispose();\n const resumeCommand = formatResumeCommand(this.sessionManager);\n if (resumeCommand) {\n process.stdout.write(`${chalk.dim(\"To resume this session:\")} ${resumeCommand}\\n`);\n }\n process.exit(0);\n };\n\nInteractiveModeBase.prototype.emergencyTerminalExit = function(this: InteractiveModeBase): never {\n this.isShuttingDown = true;\n this.unregisterSignalHandlers();\n killTrackedDetachedChildren();\n // The terminal is gone. Do not run normal shutdown because TUI and\n // extension cleanup can write restore sequences and re-trigger EIO.\n process.exit(129);\n };\n\nInteractiveModeBase.prototype.uncaughtCrash = function(this: InteractiveModeBase, error: Error): never {\n if (this.isShuttingDown) {\n process.exit(1);\n }\n this.isShuttingDown = true;\n try {\n this.unregisterSignalHandlers();\n } catch {}\n try {\n killTrackedDetachedChildren();\n } catch {}\n try {\n this.ui.stop();\n } catch {}\n console.error(\"pi exiting due to uncaughtException:\");\n console.error(error);\n process.exit(1);\n };\n\nInteractiveModeBase.prototype.checkShutdownRequested = async function(this: InteractiveModeBase): Promise<void> {\n if (!this.shutdownRequested) return;\n await this.shutdown();\n };\n\nInteractiveModeBase.prototype.registerSignalHandlers = function(this: InteractiveModeBase): void {\n this.unregisterSignalHandlers();\n\n const signals: NodeJS.Signals[] = [\"SIGTERM\"];\n if (process.platform !== \"win32\") {\n signals.push(\"SIGHUP\");\n }\n\n for (const signal of signals) {\n const handler = () => {\n killTrackedDetachedChildren();\n void this.shutdown({ fromSignal: true });\n };\n process.prependListener(signal, handler);\n this.signalCleanupHandlers.push(() => process.off(signal, handler));\n }\n\n const sigintHandler = () => {\n this.handleCtrlC();\n };\n process.prependListener(\"SIGINT\", sigintHandler);\n this.signalCleanupHandlers.push(() => process.off(\"SIGINT\", sigintHandler));\n\n const terminalErrorHandler = (error: Error) => {\n if (isDeadTerminalError(error)) {\n this.emergencyTerminalExit();\n }\n throw error;\n };\n process.stdout.on(\"error\", terminalErrorHandler);\n process.stderr.on(\"error\", terminalErrorHandler);\n this.signalCleanupHandlers.push(() =>\n process.stdout.off(\"error\", terminalErrorHandler),\n );\n this.signalCleanupHandlers.push(() =>\n process.stderr.off(\"error\", terminalErrorHandler),\n );\n\n // Restore the terminal before the process dies on any uncaught throw.\n // Without this, an unhandled exception from extension code (or anywhere\n // in pi) leaves the terminal in raw mode with no cursor.\n const uncaughtExceptionHandler = (error: Error) =>\n this.uncaughtCrash(error);\n process.prependListener(\"uncaughtException\", uncaughtExceptionHandler);\n this.signalCleanupHandlers.push(() =>\n process.off(\"uncaughtException\", uncaughtExceptionHandler),\n );\n };\n\nInteractiveModeBase.prototype.unregisterSignalHandlers = function(this: InteractiveModeBase): void {\n for (const cleanup of this.signalCleanupHandlers) {\n cleanup();\n }\n this.signalCleanupHandlers = [];\n };\n\nInteractiveModeBase.prototype.handleCtrlZ = function(this: InteractiveModeBase): void {\n if (process.platform === \"win32\") {\n this.showStatus(\"Suspend to background is not supported on Windows\");\n return;\n }\n\n // Keep the event loop alive while suspended. Without this, stopping the TUI\n // can leave Node with no ref'ed handles, causing the process to exit on fg\n // before the SIGCONT handler gets a chance to restore the terminal.\n const suspendKeepAlive = setInterval(() => {}, 2 ** 30);\n\n // Ignore SIGINT while suspended so Ctrl+C in the terminal does not\n // kill the backgrounded process. The handler is removed on resume.\n const ignoreSigint = () => {};\n process.on(\"SIGINT\", ignoreSigint);\n\n // Set up handler to restore TUI when resumed\n process.once(\"SIGCONT\", () => {\n clearInterval(suspendKeepAlive);\n process.removeListener(\"SIGINT\", ignoreSigint);\n this.ui.start();\n this.ui.requestRender(true);\n });\n\n try {\n // Stop the TUI (restore terminal to normal mode)\n this.ui.stop();\n\n // Send SIGTSTP to process group (pid=0 means all processes in group)\n process.kill(0, \"SIGTSTP\");\n } catch (error) {\n clearInterval(suspendKeepAlive);\n process.removeListener(\"SIGINT\", ignoreSigint);\n throw error;\n }\n };\n\nInteractiveModeBase.prototype.handleFollowUp = async function(this: InteractiveModeBase): Promise<void> {\n const text = (\n this.editor.getExpandedText?.() ?? this.editor.getText()\n ).trim();\n if (!text) return;\n\n // Queue input during compaction (extension commands execute immediately)\n if (this.session.isCompacting) {\n if (this.isExtensionCommand(text)) {\n this.editor.addToHistory?.(text);\n this.editor.setText(\"\");\n await this.session.prompt(text);\n } else {\n this.queueCompactionMessage(text, \"followUp\");\n }\n return;\n }\n\n // Alt+Enter queues a follow-up message (waits until agent finishes)\n // This handles extension commands (execute immediately), prompt template expansion, and queueing\n if (this.session.isStreaming) {\n this.editor.addToHistory?.(text);\n this.editor.setText(\"\");\n await this.session.prompt(text, { streamingBehavior: \"followUp\" });\n this.updatePendingMessagesDisplay();\n this.ui.requestRender();\n }\n // If not streaming, Alt+Enter acts like regular Enter (trigger onSubmit)\n else if (this.editor.onSubmit) {\n this.editor.setText(\"\");\n this.editor.onSubmit(text);\n }\n };\n\nInteractiveModeBase.prototype.handleDequeue = function(this: InteractiveModeBase): void {\n const restored = this.restoreQueuedMessagesToEditor();\n if (restored === 0) {\n this.showStatus(\"No queued messages to restore\");\n }\n };\n"]}
|
|
@@ -219,8 +219,5 @@ InteractiveModeBase.prototype.handleDequeue = function () {
|
|
|
219
219
|
if (restored === 0) {
|
|
220
220
|
this.showStatus("No queued messages to restore");
|
|
221
221
|
}
|
|
222
|
-
else {
|
|
223
|
-
this.showStatus(`Restored ${restored} queued message${restored > 1 ? "s" : ""} to editor`);
|
|
224
|
-
}
|
|
225
222
|
};
|
|
226
223
|
//# sourceMappingURL=interactive-process-lifecycle.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"interactive-process-lifecycle.js","sourceRoot":"","sources":["../../../src/modes/interactive/interactive-process-lifecycle.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AACjE,OAAO,EAAE,KAAK,EAAE,2BAA2B,EAAE,MAAM,4BAA4B,CAAC;AAChF,OAAO,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,MAAM,+BAA+B,CAAC;AAEzF,MAAM,2BAA2B,GAAG,GAAG,CAAC;AACxC,MAAM,4BAA4B,GAAG,EAAE,CAAC;AAExC,mBAAmB,CAAC,SAAS,CAAC,WAAW,GAAG;IACxC,0EAA0E;IAC1E,yEAAyE;IACzE,iEAAiE;IACjE,IAAI,IAAI,CAAC,wBAAwB,EAAE,EAAE,CAAC;QACpC,sEAAsE;QACtE,6BAA6B;QAC7B,IAAI,CAAC,cAAc,GAAG,CAAC,CAAC;QACxB,OAAO;IACT,CAAC;IACD,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;IACvB,IAAI,GAAG,GAAG,IAAI,CAAC,cAAc,GAAG,GAAG,EAAE,CAAC;QACpC,KAAK,IAAI,CAAC,QAAQ,EAAE,CAAC;IACvB,CAAC;SAAM,CAAC;QACN,IAAI,CAAC,WAAW,EAAE,CAAC;QACnB,IAAI,CAAC,cAAc,GAAG,GAAG,CAAC;IAC5B,CAAC;AACH,CAAC,CAAC;AAEJ,mBAAmB,CAAC,SAAS,CAAC,wBAAwB,GAAG;IACrD,4EAA4E;IAC5E,8DAA8D;I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AAI,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;IAC7B,CAAC;AACH,CAAC,CAAC;AAEJ,mBAAmB,CAAC,SAAS,CAAC,aAAa,GAAG;IAC1C,MAAM,QAAQ,GAAG,IAAI,CAAC,6BAA6B,EAAE,CAAC;IACtD,IAAI,QAAQ,KAAK,CAAC,EAAE,CAAC;QACnB,IAAI,CAAC,UAAU,CAAC,+BAA+B,CAAC,CAAC;IACnD,CAAC;SAAM,CAAC;QACN,IAAI,CAAC,UAAU,CACb,YAAY,QAAQ,kBAAkB,QAAQ,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,YAAY,CAC1E,CAAC;IACJ,CAAC;AACH,CAAC,CAAC","sourcesContent":["import { InteractiveModeBase } from \"./interactive-mode-base.ts\";\nimport { chalk, killTrackedDetachedChildren } from \"./interactive-mode-deps.ts\";\nimport { formatResumeCommand, isDeadTerminalError } from \"./interactive-mode-helpers.ts\";\n\nconst SHUTDOWN_INPUT_DRAIN_MAX_MS = 250;\nconst SHUTDOWN_INPUT_DRAIN_IDLE_MS = 50;\n\nInteractiveModeBase.prototype.handleCtrlC = function(this: InteractiveModeBase): void {\n // When the agent is doing work, Ctrl+C interrupts it (matching Escape and\n // common CLI muscle memory) instead of clearing/exiting the editor. Only\n // fall back to the clear / double-press-exit behavior when idle.\n if (this.interruptActiveOperation()) {\n // Reset the double-press window so a follow-up Ctrl+C after the abort\n // does not immediately exit.\n this.lastSigintTime = 0;\n return;\n }\n const now = Date.now();\n if (now - this.lastSigintTime < 500) {\n void this.shutdown();\n } else {\n this.clearEditor();\n this.lastSigintTime = now;\n }\n };\n\nInteractiveModeBase.prototype.interruptActiveOperation = function(this: InteractiveModeBase): boolean {\n // Mirror the Escape interrupt paths so Ctrl+C aborts whichever operation is\n // currently running. Returns true when something was aborted.\n if (this.session.isStreaming) {\n this.restoreQueuedMessagesToEditor({ abort: true });\n return true;\n }\n if (this.session.isBashRunning) {\n this.session.abortBash();\n return true;\n }\n if (this.session.isCompacting) {\n this.session.abortCompaction();\n return true;\n }\n if (this.session.isRetrying) {\n this.session.abortRetry();\n return true;\n }\n return false;\n };\n\nInteractiveModeBase.prototype.handleCtrlD = function(this: InteractiveModeBase): void {\n // Only called when editor is empty (enforced by CustomEditor)\n void this.shutdown();\n };\n\nInteractiveModeBase.prototype.shutdown = async function(this: InteractiveModeBase, options?: { fromSignal?: boolean }): Promise<void> {\n if (this.isShuttingDown) return;\n this.isShuttingDown = true;\n // Keep signal handlers registered until terminal cleanup has completed.\n // `signal-exit` checks the listener list during the same SIGTERM/SIGHUP\n // dispatch and re-sends the signal if only its own listeners remain.\n\n if (options?.fromSignal) {\n await this.runtimeHost.dispose();\n this.themeController.disableAutoSync();\n // Drain any in-flight Kitty key release events briefly before stopping.\n // Keep this bounded so Ctrl+C exits do not feel stalled on Windows.\n await this.ui.terminal.drainInput(SHUTDOWN_INPUT_DRAIN_MAX_MS, SHUTDOWN_INPUT_DRAIN_IDLE_MS);\n this.stop();\n process.exit(0);\n }\n\n // Drain any in-flight Kitty key release events briefly before stopping.\n // Keep this bounded so Ctrl+C exits do not feel stalled on Windows.\n this.themeController.disableAutoSync();\n await this.ui.terminal.drainInput(SHUTDOWN_INPUT_DRAIN_MAX_MS, SHUTDOWN_INPUT_DRAIN_IDLE_MS);\n\n this.stop();\n await this.runtimeHost.dispose();\n const resumeCommand = formatResumeCommand(this.sessionManager);\n if (resumeCommand) {\n process.stdout.write(`${chalk.dim(\"To resume this session:\")} ${resumeCommand}\\n`);\n }\n process.exit(0);\n };\n\nInteractiveModeBase.prototype.emergencyTerminalExit = function(this: InteractiveModeBase): never {\n this.isShuttingDown = true;\n this.unregisterSignalHandlers();\n killTrackedDetachedChildren();\n // The terminal is gone. Do not run normal shutdown because TUI and\n // extension cleanup can write restore sequences and re-trigger EIO.\n process.exit(129);\n };\n\nInteractiveModeBase.prototype.uncaughtCrash = function(this: InteractiveModeBase, error: Error): never {\n if (this.isShuttingDown) {\n process.exit(1);\n }\n this.isShuttingDown = true;\n try {\n this.unregisterSignalHandlers();\n } catch {}\n try {\n killTrackedDetachedChildren();\n } catch {}\n try {\n this.ui.stop();\n } catch {}\n console.error(\"pi exiting due to uncaughtException:\");\n console.error(error);\n process.exit(1);\n };\n\nInteractiveModeBase.prototype.checkShutdownRequested = async function(this: InteractiveModeBase): Promise<void> {\n if (!this.shutdownRequested) return;\n await this.shutdown();\n };\n\nInteractiveModeBase.prototype.registerSignalHandlers = function(this: InteractiveModeBase): void {\n this.unregisterSignalHandlers();\n\n const signals: NodeJS.Signals[] = [\"SIGTERM\"];\n if (process.platform !== \"win32\") {\n signals.push(\"SIGHUP\");\n }\n\n for (const signal of signals) {\n const handler = () => {\n killTrackedDetachedChildren();\n void this.shutdown({ fromSignal: true });\n };\n process.prependListener(signal, handler);\n this.signalCleanupHandlers.push(() => process.off(signal, handler));\n }\n\n const sigintHandler = () => {\n this.handleCtrlC();\n };\n process.prependListener(\"SIGINT\", sigintHandler);\n this.signalCleanupHandlers.push(() => process.off(\"SIGINT\", sigintHandler));\n\n const terminalErrorHandler = (error: Error) => {\n if (isDeadTerminalError(error)) {\n this.emergencyTerminalExit();\n }\n throw error;\n };\n process.stdout.on(\"error\", terminalErrorHandler);\n process.stderr.on(\"error\", terminalErrorHandler);\n this.signalCleanupHandlers.push(() =>\n process.stdout.off(\"error\", terminalErrorHandler),\n );\n this.signalCleanupHandlers.push(() =>\n process.stderr.off(\"error\", terminalErrorHandler),\n );\n\n // Restore the terminal before the process dies on any uncaught throw.\n // Without this, an unhandled exception from extension code (or anywhere\n // in pi) leaves the terminal in raw mode with no cursor.\n const uncaughtExceptionHandler = (error: Error) =>\n this.uncaughtCrash(error);\n process.prependListener(\"uncaughtException\", uncaughtExceptionHandler);\n this.signalCleanupHandlers.push(() =>\n process.off(\"uncaughtException\", uncaughtExceptionHandler),\n );\n };\n\nInteractiveModeBase.prototype.unregisterSignalHandlers = function(this: InteractiveModeBase): void {\n for (const cleanup of this.signalCleanupHandlers) {\n cleanup();\n }\n this.signalCleanupHandlers = [];\n };\n\nInteractiveModeBase.prototype.handleCtrlZ = function(this: InteractiveModeBase): void {\n if (process.platform === \"win32\") {\n this.showStatus(\"Suspend to background is not supported on Windows\");\n return;\n }\n\n // Keep the event loop alive while suspended. Without this, stopping the TUI\n // can leave Node with no ref'ed handles, causing the process to exit on fg\n // before the SIGCONT handler gets a chance to restore the terminal.\n const suspendKeepAlive = setInterval(() => {}, 2 ** 30);\n\n // Ignore SIGINT while suspended so Ctrl+C in the terminal does not\n // kill the backgrounded process. The handler is removed on resume.\n const ignoreSigint = () => {};\n process.on(\"SIGINT\", ignoreSigint);\n\n // Set up handler to restore TUI when resumed\n process.once(\"SIGCONT\", () => {\n clearInterval(suspendKeepAlive);\n process.removeListener(\"SIGINT\", ignoreSigint);\n this.ui.start();\n this.ui.requestRender(true);\n });\n\n try {\n // Stop the TUI (restore terminal to normal mode)\n this.ui.stop();\n\n // Send SIGTSTP to process group (pid=0 means all processes in group)\n process.kill(0, \"SIGTSTP\");\n } catch (error) {\n clearInterval(suspendKeepAlive);\n process.removeListener(\"SIGINT\", ignoreSigint);\n throw error;\n }\n };\n\nInteractiveModeBase.prototype.handleFollowUp = async function(this: InteractiveModeBase): Promise<void> {\n const text = (\n this.editor.getExpandedText?.() ?? this.editor.getText()\n ).trim();\n if (!text) return;\n\n // Queue input during compaction (extension commands execute immediately)\n if (this.session.isCompacting) {\n if (this.isExtensionCommand(text)) {\n this.editor.addToHistory?.(text);\n this.editor.setText(\"\");\n await this.session.prompt(text);\n } else {\n this.queueCompactionMessage(text, \"followUp\");\n }\n return;\n }\n\n // Alt+Enter queues a follow-up message (waits until agent finishes)\n // This handles extension commands (execute immediately), prompt template expansion, and queueing\n if (this.session.isStreaming) {\n this.editor.addToHistory?.(text);\n this.editor.setText(\"\");\n await this.session.prompt(text, { streamingBehavior: \"followUp\" });\n this.updatePendingMessagesDisplay();\n this.ui.requestRender();\n }\n // If not streaming, Alt+Enter acts like regular Enter (trigger onSubmit)\n else if (this.editor.onSubmit) {\n this.editor.setText(\"\");\n this.editor.onSubmit(text);\n }\n };\n\nInteractiveModeBase.prototype.handleDequeue = function(this: InteractiveModeBase): void {\n const restored = this.restoreQueuedMessagesToEditor();\n if (restored === 0) {\n this.showStatus(\"No queued messages to restore\");\n } else {\n this.showStatus(\n `Restored ${restored} queued message${restored > 1 ? \"s\" : \"\"} to editor`,\n );\n }\n };\n"]}
|
|
1
|
+
{"version":3,"file":"interactive-process-lifecycle.js","sourceRoot":"","sources":["../../../src/modes/interactive/interactive-process-lifecycle.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AACjE,OAAO,EAAE,KAAK,EAAE,2BAA2B,EAAE,MAAM,4BAA4B,CAAC;AAChF,OAAO,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,MAAM,+BAA+B,CAAC;AAEzF,MAAM,2BAA2B,GAAG,GAAG,CAAC;AACxC,MAAM,4BAA4B,GAAG,EAAE,CAAC;AAExC,mBAAmB,CAAC,SAAS,CAAC,WAAW,GAAG;IACxC,0EAA0E;IAC1E,yEAAyE;IACzE,iEAAiE;IACjE,IAAI,IAAI,CAAC,wBAAwB,EAAE,EAAE,CAAC;QACpC,sEAAsE;QACtE,6BAA6B;QAC7B,IAAI,CAAC,cAAc,GAAG,CAAC,CAAC;QACxB,OAAO;IACT,CAAC;IACD,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;IACvB,IAAI,GAAG,GAAG,IAAI,CAAC,cAAc,GAAG,GAAG,EAAE,CAAC;QACpC,KAAK,IAAI,CAAC,QAAQ,EAAE,CAAC;IACvB,CAAC;SAAM,CAAC;QACN,IAAI,CAAC,WAAW,EAAE,CAAC;QACnB,IAAI,CAAC,cAAc,GAAG,GAAG,CAAC;IAC5B,CAAC;AACH,CAAC,CAAC;AAEJ,mBAAmB,CAAC,SAAS,CAA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AAM,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;QACxB,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;IAC7B,CAAC;AACH,CAAC,CAAC;AAEJ,mBAAmB,CAAC,SAAS,CAAC,aAAa,GAAG;IAC1C,MAAM,QAAQ,GAAG,IAAI,CAAC,6BAA6B,EAAE,CAAC;IACtD,IAAI,QAAQ,KAAK,CAAC,EAAE,CAAC;QACnB,IAAI,CAAC,UAAU,CAAC,+BAA+B,CAAC,CAAC;IACnD,CAAC;AACH,CAAC,CAAC","sourcesContent":["import { InteractiveModeBase } from \"./interactive-mode-base.ts\";\nimport { chalk, killTrackedDetachedChildren } from \"./interactive-mode-deps.ts\";\nimport { formatResumeCommand, isDeadTerminalError } from \"./interactive-mode-helpers.ts\";\n\nconst SHUTDOWN_INPUT_DRAIN_MAX_MS = 250;\nconst SHUTDOWN_INPUT_DRAIN_IDLE_MS = 50;\n\nInteractiveModeBase.prototype.handleCtrlC = function(this: InteractiveModeBase): void {\n // When the agent is doing work, Ctrl+C interrupts it (matching Escape and\n // common CLI muscle memory) instead of clearing/exiting the editor. Only\n // fall back to the clear / double-press-exit behavior when idle.\n if (this.interruptActiveOperation()) {\n // Reset the double-press window so a follow-up Ctrl+C after the abort\n // does not immediately exit.\n this.lastSigintTime = 0;\n return;\n }\n const now = Date.now();\n if (now - this.lastSigintTime < 500) {\n void this.shutdown();\n } else {\n this.clearEditor();\n this.lastSigintTime = now;\n }\n };\n\nInteractiveModeBase.prototype.interruptActiveOperation = function(this: InteractiveModeBase): boolean {\n // Mirror the Escape interrupt paths so Ctrl+C aborts whichever operation is\n // currently running. Returns true when something was aborted.\n if (this.session.isStreaming) {\n this.restoreQueuedMessagesToEditor({ abort: true });\n return true;\n }\n if (this.session.isBashRunning) {\n this.session.abortBash();\n return true;\n }\n if (this.session.isCompacting) {\n this.session.abortCompaction();\n return true;\n }\n if (this.session.isRetrying) {\n this.session.abortRetry();\n return true;\n }\n return false;\n };\n\nInteractiveModeBase.prototype.handleCtrlD = function(this: InteractiveModeBase): void {\n // Only called when editor is empty (enforced by CustomEditor)\n void this.shutdown();\n };\n\nInteractiveModeBase.prototype.shutdown = async function(this: InteractiveModeBase, options?: { fromSignal?: boolean }): Promise<void> {\n if (this.isShuttingDown) return;\n this.isShuttingDown = true;\n // Keep signal handlers registered until terminal cleanup has completed.\n // `signal-exit` checks the listener list during the same SIGTERM/SIGHUP\n // dispatch and re-sends the signal if only its own listeners remain.\n\n if (options?.fromSignal) {\n await this.runtimeHost.dispose();\n this.themeController.disableAutoSync();\n // Drain any in-flight Kitty key release events briefly before stopping.\n // Keep this bounded so Ctrl+C exits do not feel stalled on Windows.\n await this.ui.terminal.drainInput(SHUTDOWN_INPUT_DRAIN_MAX_MS, SHUTDOWN_INPUT_DRAIN_IDLE_MS);\n this.stop();\n process.exit(0);\n }\n\n // Drain any in-flight Kitty key release events briefly before stopping.\n // Keep this bounded so Ctrl+C exits do not feel stalled on Windows.\n this.themeController.disableAutoSync();\n await this.ui.terminal.drainInput(SHUTDOWN_INPUT_DRAIN_MAX_MS, SHUTDOWN_INPUT_DRAIN_IDLE_MS);\n\n this.stop();\n await this.runtimeHost.dispose();\n const resumeCommand = formatResumeCommand(this.sessionManager);\n if (resumeCommand) {\n process.stdout.write(`${chalk.dim(\"To resume this session:\")} ${resumeCommand}\\n`);\n }\n process.exit(0);\n };\n\nInteractiveModeBase.prototype.emergencyTerminalExit = function(this: InteractiveModeBase): never {\n this.isShuttingDown = true;\n this.unregisterSignalHandlers();\n killTrackedDetachedChildren();\n // The terminal is gone. Do not run normal shutdown because TUI and\n // extension cleanup can write restore sequences and re-trigger EIO.\n process.exit(129);\n };\n\nInteractiveModeBase.prototype.uncaughtCrash = function(this: InteractiveModeBase, error: Error): never {\n if (this.isShuttingDown) {\n process.exit(1);\n }\n this.isShuttingDown = true;\n try {\n this.unregisterSignalHandlers();\n } catch {}\n try {\n killTrackedDetachedChildren();\n } catch {}\n try {\n this.ui.stop();\n } catch {}\n console.error(\"pi exiting due to uncaughtException:\");\n console.error(error);\n process.exit(1);\n };\n\nInteractiveModeBase.prototype.checkShutdownRequested = async function(this: InteractiveModeBase): Promise<void> {\n if (!this.shutdownRequested) return;\n await this.shutdown();\n };\n\nInteractiveModeBase.prototype.registerSignalHandlers = function(this: InteractiveModeBase): void {\n this.unregisterSignalHandlers();\n\n const signals: NodeJS.Signals[] = [\"SIGTERM\"];\n if (process.platform !== \"win32\") {\n signals.push(\"SIGHUP\");\n }\n\n for (const signal of signals) {\n const handler = () => {\n killTrackedDetachedChildren();\n void this.shutdown({ fromSignal: true });\n };\n process.prependListener(signal, handler);\n this.signalCleanupHandlers.push(() => process.off(signal, handler));\n }\n\n const sigintHandler = () => {\n this.handleCtrlC();\n };\n process.prependListener(\"SIGINT\", sigintHandler);\n this.signalCleanupHandlers.push(() => process.off(\"SIGINT\", sigintHandler));\n\n const terminalErrorHandler = (error: Error) => {\n if (isDeadTerminalError(error)) {\n this.emergencyTerminalExit();\n }\n throw error;\n };\n process.stdout.on(\"error\", terminalErrorHandler);\n process.stderr.on(\"error\", terminalErrorHandler);\n this.signalCleanupHandlers.push(() =>\n process.stdout.off(\"error\", terminalErrorHandler),\n );\n this.signalCleanupHandlers.push(() =>\n process.stderr.off(\"error\", terminalErrorHandler),\n );\n\n // Restore the terminal before the process dies on any uncaught throw.\n // Without this, an unhandled exception from extension code (or anywhere\n // in pi) leaves the terminal in raw mode with no cursor.\n const uncaughtExceptionHandler = (error: Error) =>\n this.uncaughtCrash(error);\n process.prependListener(\"uncaughtException\", uncaughtExceptionHandler);\n this.signalCleanupHandlers.push(() =>\n process.off(\"uncaughtException\", uncaughtExceptionHandler),\n );\n };\n\nInteractiveModeBase.prototype.unregisterSignalHandlers = function(this: InteractiveModeBase): void {\n for (const cleanup of this.signalCleanupHandlers) {\n cleanup();\n }\n this.signalCleanupHandlers = [];\n };\n\nInteractiveModeBase.prototype.handleCtrlZ = function(this: InteractiveModeBase): void {\n if (process.platform === \"win32\") {\n this.showStatus(\"Suspend to background is not supported on Windows\");\n return;\n }\n\n // Keep the event loop alive while suspended. Without this, stopping the TUI\n // can leave Node with no ref'ed handles, causing the process to exit on fg\n // before the SIGCONT handler gets a chance to restore the terminal.\n const suspendKeepAlive = setInterval(() => {}, 2 ** 30);\n\n // Ignore SIGINT while suspended so Ctrl+C in the terminal does not\n // kill the backgrounded process. The handler is removed on resume.\n const ignoreSigint = () => {};\n process.on(\"SIGINT\", ignoreSigint);\n\n // Set up handler to restore TUI when resumed\n process.once(\"SIGCONT\", () => {\n clearInterval(suspendKeepAlive);\n process.removeListener(\"SIGINT\", ignoreSigint);\n this.ui.start();\n this.ui.requestRender(true);\n });\n\n try {\n // Stop the TUI (restore terminal to normal mode)\n this.ui.stop();\n\n // Send SIGTSTP to process group (pid=0 means all processes in group)\n process.kill(0, \"SIGTSTP\");\n } catch (error) {\n clearInterval(suspendKeepAlive);\n process.removeListener(\"SIGINT\", ignoreSigint);\n throw error;\n }\n };\n\nInteractiveModeBase.prototype.handleFollowUp = async function(this: InteractiveModeBase): Promise<void> {\n const text = (\n this.editor.getExpandedText?.() ?? this.editor.getText()\n ).trim();\n if (!text) return;\n\n // Queue input during compaction (extension commands execute immediately)\n if (this.session.isCompacting) {\n if (this.isExtensionCommand(text)) {\n this.editor.addToHistory?.(text);\n this.editor.setText(\"\");\n await this.session.prompt(text);\n } else {\n this.queueCompactionMessage(text, \"followUp\");\n }\n return;\n }\n\n // Alt+Enter queues a follow-up message (waits until agent finishes)\n // This handles extension commands (execute immediately), prompt template expansion, and queueing\n if (this.session.isStreaming) {\n this.editor.addToHistory?.(text);\n this.editor.setText(\"\");\n await this.session.prompt(text, { streamingBehavior: \"followUp\" });\n this.updatePendingMessagesDisplay();\n this.ui.requestRender();\n }\n // If not streaming, Alt+Enter acts like regular Enter (trigger onSubmit)\n else if (this.editor.onSubmit) {\n this.editor.setText(\"\");\n this.editor.onSubmit(text);\n }\n };\n\nInteractiveModeBase.prototype.handleDequeue = function(this: InteractiveModeBase): void {\n const restored = this.restoreQueuedMessagesToEditor();\n if (restored === 0) {\n this.showStatus(\"No queued messages to restore\");\n }\n };\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"interactive-render-chat.d.ts","sourceRoot":"","sources":["../../../src/modes/interactive/interactive-render-chat.ts"],"names":[],"mappings":"","sourcesContent":["import { InteractiveModeBase } from \"./interactive-mode-base.ts\";\nimport { type AgentMessage, type Component, type ContextCompactionResult, type SessionContext, type TruncationResult, type ChatMessageEntry, type ChatMessageRenderOptions, Spacer, Text, parseSkillBlock, AssistantMessageComponent, BashExecutionComponent, BranchSummaryMessageComponent, chatEntriesFromAgentMessages, renderChatMessageEntry, addChatTranscriptEntry, ContextCompactionSummaryMessageComponent, CustomMessageComponent, SkillInvocationMessageComponent, ToolExecutionComponent, UserMessageComponent, theme } from \"./interactive-mode-deps.ts\";\nimport { yieldToEventLoop } from \"../../utils/event-loop.ts\";\n\nInteractiveModeBase.prototype.showStatus = function(this: InteractiveModeBase, message: string): void {\n const children = this.chatContainer.children;\n const last =\n children.length > 0 ? children[children.length - 1] : undefined;\n const secondLast =\n children.length > 1 ? children[children.length - 2] : undefined;\n\n if (\n last &&\n secondLast &&\n last === this.lastStatusText &&\n secondLast === this.lastStatusSpacer\n ) {\n this.lastStatusText.setText(theme.fg(\"dim\", message));\n this.ui.requestRender();\n return;\n }\n\n const spacer = new Spacer(1);\n const text = new Text(theme.fg(\"dim\", message), 1, 0);\n this.chatContainer.addChild(spacer);\n this.chatContainer.addChild(text);\n this.lastStatusSpacer = spacer;\n this.lastStatusText = text;\n this.ui.requestRender();\n };\n\nInteractiveModeBase.prototype.renderDeferredUserInput = function(this: InteractiveModeBase, text: string): void {\n this.deferredRenderedUserInputs.push(text);\n const startIndex = this.chatContainer.children.length;\n this.addMessageToChat({ role: \"user\", content: text } as AgentMessage);\n const renderedComponents = this.chatContainer.children.slice(startIndex);\n const trackedComponents = this.deferredRenderedUserInputComponents.get(text) ?? [];\n trackedComponents.push(renderedComponents);\n this.deferredRenderedUserInputComponents.set(text, trackedComponents);\n this.updatePendingMessagesDisplay();\n this.ui.requestRender();\n };\n\nInteractiveModeBase.prototype.consumeDeferredRenderedUserInput = function(this: InteractiveModeBase, text: string): boolean {\n const index = this.deferredRenderedUserInputs.indexOf(text);\n if (index === -1) return false;\n this.deferredRenderedUserInputs.splice(index, 1);\n const trackedComponents = this.deferredRenderedUserInputComponents.get(text);\n trackedComponents?.shift();\n if (trackedComponents && trackedComponents.length === 0) {\n this.deferredRenderedUserInputComponents.delete(text);\n }\n return true;\n };\n\nInteractiveModeBase.prototype.discardDeferredRenderedUserInput = function(this: InteractiveModeBase, text: string): void {\n const index = this.deferredRenderedUserInputs.indexOf(text);\n if (index !== -1) this.deferredRenderedUserInputs.splice(index, 1);\n const trackedComponents = this.deferredRenderedUserInputComponents.get(text);\n const componentsToRemove = trackedComponents?.shift();\n if (trackedComponents && trackedComponents.length === 0) {\n this.deferredRenderedUserInputComponents.delete(text);\n }\n if (!componentsToRemove) return;\n for (const component of componentsToRemove) {\n this.chatContainer.removeChild(component);\n }\n this.updatePendingMessagesDisplay();\n this.ui.requestRender();\n };\n\nInteractiveModeBase.prototype.chatMessageRenderOptions = function(this: InteractiveModeBase): ChatMessageRenderOptions {\n return {\n ui: this.ui,\n cwd: this.sessionManager.getCwd(),\n markdownTheme: this.getMarkdownThemeWithSettings(),\n hideThinkingBlock: this.hideThinkingBlock,\n hiddenThinkingLabel: this.hiddenThinkingLabel,\n toolOutputExpanded: this.toolOutputExpanded,\n showImages: this.settingsManager.getShowImages(),\n imageWidthCells: this.settingsManager.getImageWidthCells(),\n outputPad: this.outputPad,\n getToolDefinition: (toolName) => this.getRegisteredToolDefinition(toolName),\n getCustomMessageRenderer: (customType) =>\n this.session.extensionRunner.getMessageRenderer(customType),\n };\n };\n\nInteractiveModeBase.prototype.addRenderedChatEntry = function(this: InteractiveModeBase, entry: ChatMessageEntry): Component {\n const component = renderChatMessageEntry(entry, this.chatMessageRenderOptions());\n addChatTranscriptEntry(this.chatContainer, component, entry.role);\n return component;\n };\n\nInteractiveModeBase.prototype.addContextCompactionSummaryToChat = function(this: InteractiveModeBase, result: ContextCompactionResult): void {\n this.chatContainer.addChild(new Spacer(1));\n const component = new ContextCompactionSummaryMessageComponent(\n result,\n this.getMarkdownThemeWithSettings(),\n );\n component.setExpanded(this.toolOutputExpanded);\n this.chatContainer.addChild(component);\n };\n\nInteractiveModeBase.prototype.addMessageToChat = function(this: InteractiveModeBase, message: AgentMessage, options?: { populateHistory?: boolean }): void {\n switch (message.role) {\n case \"bashExecution\": {\n const component = new BashExecutionComponent(\n message.command,\n this.ui,\n message.excludeFromContext,\n );\n if (message.output) {\n component.appendOutput(message.output);\n }\n component.setComplete(\n message.exitCode,\n message.cancelled,\n message.truncated\n ? ({ truncated: true } as TruncationResult)\n : undefined,\n message.fullOutputPath,\n );\n this.chatContainer.addChild(component);\n break;\n }\n case \"custom\": {\n if (message.display) {\n const renderer = this.session.extensionRunner.getMessageRenderer(\n message.customType,\n );\n const component = new CustomMessageComponent(\n message,\n renderer,\n this.getMarkdownThemeWithSettings(),\n );\n component.setExpanded(this.toolOutputExpanded);\n this.chatContainer.addChild(component);\n }\n break;\n }\n case \"branchSummary\": {\n this.chatContainer.addChild(new Spacer(1));\n const component = new BranchSummaryMessageComponent(\n message,\n this.getMarkdownThemeWithSettings(),\n );\n component.setExpanded(this.toolOutputExpanded);\n this.chatContainer.addChild(component);\n break;\n }\n case \"user\": {\n const textContent = this.getUserMessageText(message);\n if (textContent) {\n if (this.chatContainer.children.length > 0) {\n this.chatContainer.addChild(new Spacer(1));\n }\n const skillBlock = parseSkillBlock(textContent);\n if (skillBlock) {\n // Render skill block (collapsible)\n const component = new SkillInvocationMessageComponent(\n skillBlock,\n this.getMarkdownThemeWithSettings(),\n );\n component.setExpanded(this.toolOutputExpanded);\n this.chatContainer.addChild(component);\n // Render user message separately if present\n if (skillBlock.userMessage) {\n const userComponent = new UserMessageComponent(\n skillBlock.userMessage,\n this.getMarkdownThemeWithSettings(),\n this.outputPad,\n );\n this.chatContainer.addChild(userComponent);\n }\n } else {\n const userComponent = new UserMessageComponent(\n textContent,\n this.getMarkdownThemeWithSettings(),\n this.outputPad,\n );\n this.chatContainer.addChild(userComponent);\n }\n if (options?.populateHistory) {\n this.editor.addToHistory?.(textContent);\n }\n }\n break;\n }\n case \"assistant\": {\n const assistantComponent = new AssistantMessageComponent(\n message,\n this.hideThinkingBlock,\n this.getMarkdownThemeWithSettings(),\n this.hiddenThinkingLabel,\n this.outputPad,\n );\n this.chatContainer.addChild(assistantComponent);\n break;\n }\n case \"toolResult\": {\n // Tool results are rendered inline with tool calls, handled separately\n break;\n }\n default:\n break;\n }\n };\n\nInteractiveModeBase.prototype.renderSessionContext = function(this: InteractiveModeBase, sessionContext: SessionContext, options: { updateFooter?: boolean; populateHistory?: boolean } = {}): void {\n this.pendingTools.clear();\n const pendingDeferredInputs = [...this.deferredRenderedUserInputs];\n this.deferredRenderedUserInputs = [];\n this.deferredRenderedUserInputComponents.clear();\n\n if (options.updateFooter) {\n this.footer.invalidate();\n this.updateEditorBorderColor();\n }\n\n const entries = chatEntriesFromAgentMessages(sessionContext.messages);\n for (const entry of entries) {\n const component = this.addRenderedChatEntry(entry);\n if (\n entry.kind === \"tool\" &&\n entry.isPartial !== false &&\n component instanceof ToolExecutionComponent\n ) {\n this.pendingTools.set(entry.toolCallId, component);\n }\n if (options.populateHistory && entry.kind === \"user\") {\n this.editor.addToHistory?.(entry.text);\n }\n }\n\n for (const input of pendingDeferredInputs) {\n this.renderDeferredUserInput(input);\n }\n\n this.ui.requestRender();\n };\n\nInteractiveModeBase.prototype.attachStartupNoticesContainer = function(this: InteractiveModeBase, options: { resetDetached?: boolean } = {}): void {\n const isAttached = this.chatContainer.children.includes(this.startupNoticesContainer);\n if (isAttached) return;\n if (options.resetDetached) {\n this.startupNoticesContainer.clear();\n }\n this.chatContainer.addChild(this.startupNoticesContainer);\n };\n\nInteractiveModeBase.prototype.renderInitialMessages = function(this: InteractiveModeBase): void {\n this.attachStartupNoticesContainer({ resetDetached: true });\n // Get aligned messages and entries from session context\n const context = this.sessionManager.buildSessionContext();\n this.renderSessionContext(context, {\n updateFooter: true,\n populateHistory: true,\n });\n\n // Show compaction info if session was compacted\n const allEntries = this.sessionManager.getEntries();\n const compactionCount = allEntries.filter(\n (e) => e.type === \"compaction\",\n ).length;\n if (compactionCount > 0) {\n const times =\n compactionCount === 1 ? \"1 time\" : `${compactionCount} times`;\n this.showStatus(`Session compacted ${times}`);\n }\n };\n\nInteractiveModeBase.prototype.getUserInput = async function(this: InteractiveModeBase): Promise<string> {\n for (let attempt = 0; !this.startupCookedInputRecovered && attempt < 10; attempt += 1) {\n await yieldToEventLoop();\n if (this.recoverCookedStartupInput?.()) break;\n }\n while (true) {\n const queuedInput = this.pendingUserInputs.shift();\n if (queuedInput !== undefined) {\n return queuedInput;\n }\n\n if (this.startupReplayActiveInput) {\n await this.drainStartupReplayCommands();\n continue;\n }\n\n return new Promise((resolve) => {\n this.onInputCallback = (text: string) => {\n this.onInputCallback = undefined;\n resolve(text);\n };\n });\n }\n };\n\nInteractiveModeBase.prototype.rebuildChatFromMessages = function(this: InteractiveModeBase): void {\n this.chatContainer.clear();\n this.attachStartupNoticesContainer();\n const context = this.sessionManager.buildSessionContext();\n this.renderSessionContext(context);\n };\n"]}
|
|
1
|
+
{"version":3,"file":"interactive-render-chat.d.ts","sourceRoot":"","sources":["../../../src/modes/interactive/interactive-render-chat.ts"],"names":[],"mappings":"","sourcesContent":["import { InteractiveModeBase } from \"./interactive-mode-base.ts\";\nimport { type AgentMessage, type Component, type ContextCompactionResult, type SessionContext, type TruncationResult, type ChatMessageEntry, type ChatMessageRenderOptions, Spacer, Text, parseSkillBlock, AssistantMessageComponent, BashExecutionComponent, BranchSummaryMessageComponent, chatEntriesFromAgentMessages, renderChatMessageEntry, addChatTranscriptEntry, ContextCompactionSummaryMessageComponent, CustomMessageComponent, SkillInvocationMessageComponent, ToolExecutionComponent, UserMessageComponent, recordTimeSinceReset, theme } from \"./interactive-mode-deps.ts\";\nimport { yieldToEventLoop } from \"../../utils/event-loop.ts\";\n\nInteractiveModeBase.prototype.showStatus = function(this: InteractiveModeBase, message: string): void {\n const children = this.chatContainer.children;\n const last =\n children.length > 0 ? children[children.length - 1] : undefined;\n const secondLast =\n children.length > 1 ? children[children.length - 2] : undefined;\n\n if (\n last &&\n secondLast &&\n last === this.lastStatusText &&\n secondLast === this.lastStatusSpacer\n ) {\n this.lastStatusText.setText(theme.fg(\"dim\", message));\n this.ui.requestRender();\n return;\n }\n\n const spacer = new Spacer(1);\n const text = new Text(theme.fg(\"dim\", message), 1, 0);\n this.chatContainer.addChild(spacer);\n this.chatContainer.addChild(text);\n this.lastStatusSpacer = spacer;\n this.lastStatusText = text;\n this.ui.requestRender();\n };\n\nInteractiveModeBase.prototype.renderDeferredUserInput = function(this: InteractiveModeBase, text: string): void {\n this.deferredRenderedUserInputs.push(text);\n const startIndex = this.chatContainer.children.length;\n this.addMessageToChat({ role: \"user\", content: text } as AgentMessage);\n const renderedComponents = this.chatContainer.children.slice(startIndex);\n const trackedComponents = this.deferredRenderedUserInputComponents.get(text) ?? [];\n trackedComponents.push(renderedComponents);\n this.deferredRenderedUserInputComponents.set(text, trackedComponents);\n this.updatePendingMessagesDisplay();\n this.ui.requestRender();\n };\n\nInteractiveModeBase.prototype.consumeDeferredRenderedUserInput = function(this: InteractiveModeBase, text: string): boolean {\n const index = this.deferredRenderedUserInputs.indexOf(text);\n if (index === -1) return false;\n this.deferredRenderedUserInputs.splice(index, 1);\n const trackedComponents = this.deferredRenderedUserInputComponents.get(text);\n trackedComponents?.shift();\n if (trackedComponents && trackedComponents.length === 0) {\n this.deferredRenderedUserInputComponents.delete(text);\n }\n return true;\n };\n\nInteractiveModeBase.prototype.discardDeferredRenderedUserInput = function(this: InteractiveModeBase, text: string): void {\n const index = this.deferredRenderedUserInputs.indexOf(text);\n if (index !== -1) this.deferredRenderedUserInputs.splice(index, 1);\n const trackedComponents = this.deferredRenderedUserInputComponents.get(text);\n const componentsToRemove = trackedComponents?.shift();\n if (trackedComponents && trackedComponents.length === 0) {\n this.deferredRenderedUserInputComponents.delete(text);\n }\n if (!componentsToRemove) return;\n for (const component of componentsToRemove) {\n this.chatContainer.removeChild(component);\n }\n this.updatePendingMessagesDisplay();\n this.ui.requestRender();\n };\n\nInteractiveModeBase.prototype.chatMessageRenderOptions = function(this: InteractiveModeBase): ChatMessageRenderOptions {\n return {\n ui: this.ui,\n cwd: this.sessionManager.getCwd(),\n markdownTheme: this.getMarkdownThemeWithSettings(),\n hideThinkingBlock: this.hideThinkingBlock,\n hiddenThinkingLabel: this.hiddenThinkingLabel,\n toolOutputExpanded: this.toolOutputExpanded,\n showImages: this.settingsManager.getShowImages(),\n imageWidthCells: this.settingsManager.getImageWidthCells(),\n outputPad: this.outputPad,\n getToolDefinition: (toolName) => this.getRegisteredToolDefinition(toolName),\n getCustomMessageRenderer: (customType) =>\n this.session.extensionRunner.getMessageRenderer(customType),\n };\n };\n\nInteractiveModeBase.prototype.addRenderedChatEntry = function(this: InteractiveModeBase, entry: ChatMessageEntry): Component {\n const component = renderChatMessageEntry(entry, this.chatMessageRenderOptions());\n addChatTranscriptEntry(this.chatContainer, component, entry.role);\n return component;\n };\n\nInteractiveModeBase.prototype.addContextCompactionSummaryToChat = function(this: InteractiveModeBase, result: ContextCompactionResult): void {\n this.chatContainer.addChild(new Spacer(1));\n const component = new ContextCompactionSummaryMessageComponent(\n result,\n this.getMarkdownThemeWithSettings(),\n );\n component.setExpanded(this.toolOutputExpanded);\n this.chatContainer.addChild(component);\n };\n\nInteractiveModeBase.prototype.addMessageToChat = function(this: InteractiveModeBase, message: AgentMessage, options?: { populateHistory?: boolean }): void {\n switch (message.role) {\n case \"bashExecution\": {\n const component = new BashExecutionComponent(\n message.command,\n this.ui,\n message.excludeFromContext,\n );\n if (message.output) {\n component.appendOutput(message.output);\n }\n component.setComplete(\n message.exitCode,\n message.cancelled,\n message.truncated\n ? ({ truncated: true } as TruncationResult)\n : undefined,\n message.fullOutputPath,\n );\n this.chatContainer.addChild(component);\n break;\n }\n case \"custom\": {\n if (message.display) {\n const renderer = this.session.extensionRunner.getMessageRenderer(\n message.customType,\n );\n const component = new CustomMessageComponent(\n message,\n renderer,\n this.getMarkdownThemeWithSettings(),\n );\n component.setExpanded(this.toolOutputExpanded);\n this.chatContainer.addChild(component);\n }\n break;\n }\n case \"branchSummary\": {\n this.chatContainer.addChild(new Spacer(1));\n const component = new BranchSummaryMessageComponent(\n message,\n this.getMarkdownThemeWithSettings(),\n );\n component.setExpanded(this.toolOutputExpanded);\n this.chatContainer.addChild(component);\n break;\n }\n case \"user\": {\n const textContent = this.getUserMessageText(message);\n if (textContent) {\n if (this.chatContainer.children.length > 0) {\n this.chatContainer.addChild(new Spacer(1));\n }\n const skillBlock = parseSkillBlock(textContent);\n if (skillBlock) {\n // Render skill block (collapsible)\n const component = new SkillInvocationMessageComponent(\n skillBlock,\n this.getMarkdownThemeWithSettings(),\n );\n component.setExpanded(this.toolOutputExpanded);\n this.chatContainer.addChild(component);\n // Render user message separately if present\n if (skillBlock.userMessage) {\n const userComponent = new UserMessageComponent(\n skillBlock.userMessage,\n this.getMarkdownThemeWithSettings(),\n this.outputPad,\n );\n this.chatContainer.addChild(userComponent);\n }\n } else {\n const userComponent = new UserMessageComponent(\n textContent,\n this.getMarkdownThemeWithSettings(),\n this.outputPad,\n );\n this.chatContainer.addChild(userComponent);\n }\n if (options?.populateHistory) {\n this.editor.addToHistory?.(textContent);\n }\n }\n break;\n }\n case \"assistant\": {\n const assistantComponent = new AssistantMessageComponent(\n message,\n this.hideThinkingBlock,\n this.getMarkdownThemeWithSettings(),\n this.hiddenThinkingLabel,\n this.outputPad,\n );\n this.chatContainer.addChild(assistantComponent);\n break;\n }\n case \"toolResult\": {\n // Tool results are rendered inline with tool calls, handled separately\n break;\n }\n default:\n break;\n }\n };\n\nInteractiveModeBase.prototype.renderSessionContext = function(this: InteractiveModeBase, sessionContext: SessionContext, options: { updateFooter?: boolean; populateHistory?: boolean } = {}): void {\n this.pendingTools.clear();\n const pendingDeferredInputs = [...this.deferredRenderedUserInputs];\n this.deferredRenderedUserInputs = [];\n this.deferredRenderedUserInputComponents.clear();\n\n if (options.updateFooter) {\n this.footer.invalidate();\n this.updateEditorBorderColor();\n }\n\n const entries = chatEntriesFromAgentMessages(sessionContext.messages);\n for (const entry of entries) {\n const component = this.addRenderedChatEntry(entry);\n if (\n entry.kind === \"tool\" &&\n entry.isPartial !== false &&\n component instanceof ToolExecutionComponent\n ) {\n this.pendingTools.set(entry.toolCallId, component);\n }\n if (options.populateHistory && entry.kind === \"user\") {\n this.editor.addToHistory?.(entry.text);\n }\n }\n\n for (const input of pendingDeferredInputs) {\n this.renderDeferredUserInput(input);\n }\n\n this.ui.requestRender();\n };\n\nInteractiveModeBase.prototype.attachStartupNoticesContainer = function(this: InteractiveModeBase, options: { resetDetached?: boolean } = {}): void {\n const isAttached = this.chatContainer.children.includes(this.startupNoticesContainer);\n if (isAttached) return;\n if (options.resetDetached) {\n this.startupNoticesContainer.clear();\n }\n this.chatContainer.addChild(this.startupNoticesContainer);\n };\n\nInteractiveModeBase.prototype.renderInitialMessages = function(this: InteractiveModeBase): void {\n this.attachStartupNoticesContainer({ resetDetached: true });\n // Get aligned messages and entries from session context\n const context = this.sessionManager.buildSessionContext();\n this.renderSessionContext(context, {\n updateFooter: true,\n populateHistory: true,\n });\n\n // Show compaction info if session was compacted\n const allEntries = this.sessionManager.getEntries();\n const compactionCount = allEntries.filter(\n (e) => e.type === \"compaction\",\n ).length;\n if (compactionCount > 0) {\n const times =\n compactionCount === 1 ? \"1 time\" : `${compactionCount} times`;\n this.showStatus(`Session compacted ${times}`);\n }\n };\n\nInteractiveModeBase.prototype.getUserInput = async function(this: InteractiveModeBase): Promise<string> {\n for (let attempt = 0; !this.startupCookedInputRecovered && attempt < 10; attempt += 1) {\n await yieldToEventLoop();\n if (this.recoverCookedStartupInput?.()) break;\n }\n while (true) {\n const queuedInput = this.pendingUserInputs.shift();\n if (queuedInput !== undefined) {\n return queuedInput;\n }\n\n if (this.startupReplayActiveInput) {\n await this.drainStartupReplayCommands();\n continue;\n }\n\n return new Promise((resolve) => {\n this.onInputCallback = (text: string) => {\n this.onInputCallback = undefined;\n resolve(text);\n };\n if (!this.inputHandlerReadyRecorded) {\n this.inputHandlerReadyRecorded = true;\n recordTimeSinceReset(\"interactive-input-handler-ready\");\n void (async () => {\n await yieldToEventLoop();\n this.footerDataProvider.startGitWatcher();\n if (this.deferredStartupPending) {\n await this.ensureDeferredStartupComplete();\n }\n })().catch((error) => {\n const message = error instanceof Error ? error.message : String(error);\n console.error(`Deferred input-readiness startup task failed: ${message}`);\n });\n }\n });\n }\n };\n\nInteractiveModeBase.prototype.rebuildChatFromMessages = function(this: InteractiveModeBase): void {\n this.chatContainer.clear();\n this.attachStartupNoticesContainer();\n const context = this.sessionManager.buildSessionContext();\n this.renderSessionContext(context);\n };\n"]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { InteractiveModeBase } from "./interactive-mode-base.js";
|
|
2
|
-
import { Spacer, Text, parseSkillBlock, AssistantMessageComponent, BashExecutionComponent, BranchSummaryMessageComponent, chatEntriesFromAgentMessages, renderChatMessageEntry, addChatTranscriptEntry, ContextCompactionSummaryMessageComponent, CustomMessageComponent, SkillInvocationMessageComponent, ToolExecutionComponent, UserMessageComponent, theme } from "./interactive-mode-deps.js";
|
|
2
|
+
import { Spacer, Text, parseSkillBlock, AssistantMessageComponent, BashExecutionComponent, BranchSummaryMessageComponent, chatEntriesFromAgentMessages, renderChatMessageEntry, addChatTranscriptEntry, ContextCompactionSummaryMessageComponent, CustomMessageComponent, SkillInvocationMessageComponent, ToolExecutionComponent, UserMessageComponent, recordTimeSinceReset, theme } from "./interactive-mode-deps.js";
|
|
3
3
|
import { yieldToEventLoop } from "../../utils/event-loop.js";
|
|
4
4
|
InteractiveModeBase.prototype.showStatus = function (message) {
|
|
5
5
|
const children = this.chatContainer.children;
|
|
@@ -228,6 +228,20 @@ InteractiveModeBase.prototype.getUserInput = async function () {
|
|
|
228
228
|
this.onInputCallback = undefined;
|
|
229
229
|
resolve(text);
|
|
230
230
|
};
|
|
231
|
+
if (!this.inputHandlerReadyRecorded) {
|
|
232
|
+
this.inputHandlerReadyRecorded = true;
|
|
233
|
+
recordTimeSinceReset("interactive-input-handler-ready");
|
|
234
|
+
void (async () => {
|
|
235
|
+
await yieldToEventLoop();
|
|
236
|
+
this.footerDataProvider.startGitWatcher();
|
|
237
|
+
if (this.deferredStartupPending) {
|
|
238
|
+
await this.ensureDeferredStartupComplete();
|
|
239
|
+
}
|
|
240
|
+
})().catch((error) => {
|
|
241
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
242
|
+
console.error(`Deferred input-readiness startup task failed: ${message}`);
|
|
243
|
+
});
|
|
244
|
+
}
|
|
231
245
|
});
|
|
232
246
|
}
|
|
233
247
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"interactive-render-chat.js","sourceRoot":"","sources":["../../../src/modes/interactive/interactive-render-chat.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AACjE,OAAO,EAAqK,MAAM,EAAE,IAAI,EAAE,eAAe,EAAE,yBAAyB,EAAE,sBAAsB,EAAE,6BAA6B,EAAE,4BAA4B,EAAE,sBAAsB,EAAE,sBAAsB,EAAE,wCAAwC,EAAE,sBAAsB,EAAE,+BAA+B,EAAE,sBAAsB,EAAE,oBAAoB,EAAE,KAAK,EAAE,MAAM,4BAA4B,CAAC;AACtiB,OAAO,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAE7D,mBAAmB,CAAC,SAAS,CAAC,UAAU,GAAG,UAAoC,OAAe;IAC1F,MAAM,QAAQ,GAAG,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EAAE,CAAC;IACrC,MAAM,OAAO,GAAG,IAAI,CAAC,cAAc,CAAC,mBAAmB,EAAE,CAAC;IAC1D,IAAI,CAAC,oBAAoB,CAAC,OAAO,CAAC,CAAC;AACrC,CAAC,CAAC","sourcesContent":["import { InteractiveModeBase } from \"./interactive-mode-base.ts\";\nimport { type AgentMessage, type Component, type ContextCompactionResult, type SessionContext, type TruncationResult, type ChatMessageEntry, type ChatMessageRenderOptions, Spacer, Text, parseSkillBlock, AssistantMessageComponent, BashExecutionComponent, BranchSummaryMessageComponent, chatEntriesFromAgentMessages, renderChatMessageEntry, addChatTranscriptEntry, ContextCompactionSummaryMessageComponent, CustomMessageComponent, SkillInvocationMessageComponent, ToolExecutionComponent, UserMessageComponent, theme } from \"./interactive-mode-deps.ts\";\nimport { yieldToEventLoop } from \"../../utils/event-loop.ts\";\n\nInteractiveModeBase.prototype.showStatus = function(this: InteractiveModeBase, message: string): void {\n const children = this.chatContainer.children;\n const last =\n children.length > 0 ? children[children.length - 1] : undefined;\n const secondLast =\n children.length > 1 ? children[children.length - 2] : undefined;\n\n if (\n last &&\n secondLast &&\n last === this.lastStatusText &&\n secondLast === this.lastStatusSpacer\n ) {\n this.lastStatusText.setText(theme.fg(\"dim\", message));\n this.ui.requestRender();\n return;\n }\n\n const spacer = new Spacer(1);\n const text = new Text(theme.fg(\"dim\", message), 1, 0);\n this.chatContainer.addChild(spacer);\n this.chatContainer.addChild(text);\n this.lastStatusSpacer = spacer;\n this.lastStatusText = text;\n this.ui.requestRender();\n };\n\nInteractiveModeBase.prototype.renderDeferredUserInput = function(this: InteractiveModeBase, text: string): void {\n this.deferredRenderedUserInputs.push(text);\n const startIndex = this.chatContainer.children.length;\n this.addMessageToChat({ role: \"user\", content: text } as AgentMessage);\n const renderedComponents = this.chatContainer.children.slice(startIndex);\n const trackedComponents = this.deferredRenderedUserInputComponents.get(text) ?? [];\n trackedComponents.push(renderedComponents);\n this.deferredRenderedUserInputComponents.set(text, trackedComponents);\n this.updatePendingMessagesDisplay();\n this.ui.requestRender();\n };\n\nInteractiveModeBase.prototype.consumeDeferredRenderedUserInput = function(this: InteractiveModeBase, text: string): boolean {\n const index = this.deferredRenderedUserInputs.indexOf(text);\n if (index === -1) return false;\n this.deferredRenderedUserInputs.splice(index, 1);\n const trackedComponents = this.deferredRenderedUserInputComponents.get(text);\n trackedComponents?.shift();\n if (trackedComponents && trackedComponents.length === 0) {\n this.deferredRenderedUserInputComponents.delete(text);\n }\n return true;\n };\n\nInteractiveModeBase.prototype.discardDeferredRenderedUserInput = function(this: InteractiveModeBase, text: string): void {\n const index = this.deferredRenderedUserInputs.indexOf(text);\n if (index !== -1) this.deferredRenderedUserInputs.splice(index, 1);\n const trackedComponents = this.deferredRenderedUserInputComponents.get(text);\n const componentsToRemove = trackedComponents?.shift();\n if (trackedComponents && trackedComponents.length === 0) {\n this.deferredRenderedUserInputComponents.delete(text);\n }\n if (!componentsToRemove) return;\n for (const component of componentsToRemove) {\n this.chatContainer.removeChild(component);\n }\n this.updatePendingMessagesDisplay();\n this.ui.requestRender();\n };\n\nInteractiveModeBase.prototype.chatMessageRenderOptions = function(this: InteractiveModeBase): ChatMessageRenderOptions {\n return {\n ui: this.ui,\n cwd: this.sessionManager.getCwd(),\n markdownTheme: this.getMarkdownThemeWithSettings(),\n hideThinkingBlock: this.hideThinkingBlock,\n hiddenThinkingLabel: this.hiddenThinkingLabel,\n toolOutputExpanded: this.toolOutputExpanded,\n showImages: this.settingsManager.getShowImages(),\n imageWidthCells: this.settingsManager.getImageWidthCells(),\n outputPad: this.outputPad,\n getToolDefinition: (toolName) => this.getRegisteredToolDefinition(toolName),\n getCustomMessageRenderer: (customType) =>\n this.session.extensionRunner.getMessageRenderer(customType),\n };\n };\n\nInteractiveModeBase.prototype.addRenderedChatEntry = function(this: InteractiveModeBase, entry: ChatMessageEntry): Component {\n const component = renderChatMessageEntry(entry, this.chatMessageRenderOptions());\n addChatTranscriptEntry(this.chatContainer, component, entry.role);\n return component;\n };\n\nInteractiveModeBase.prototype.addContextCompactionSummaryToChat = function(this: InteractiveModeBase, result: ContextCompactionResult): void {\n this.chatContainer.addChild(new Spacer(1));\n const component = new ContextCompactionSummaryMessageComponent(\n result,\n this.getMarkdownThemeWithSettings(),\n );\n component.setExpanded(this.toolOutputExpanded);\n this.chatContainer.addChild(component);\n };\n\nInteractiveModeBase.prototype.addMessageToChat = function(this: InteractiveModeBase, message: AgentMessage, options?: { populateHistory?: boolean }): void {\n switch (message.role) {\n case \"bashExecution\": {\n const component = new BashExecutionComponent(\n message.command,\n this.ui,\n message.excludeFromContext,\n );\n if (message.output) {\n component.appendOutput(message.output);\n }\n component.setComplete(\n message.exitCode,\n message.cancelled,\n message.truncated\n ? ({ truncated: true } as TruncationResult)\n : undefined,\n message.fullOutputPath,\n );\n this.chatContainer.addChild(component);\n break;\n }\n case \"custom\": {\n if (message.display) {\n const renderer = this.session.extensionRunner.getMessageRenderer(\n message.customType,\n );\n const component = new CustomMessageComponent(\n message,\n renderer,\n this.getMarkdownThemeWithSettings(),\n );\n component.setExpanded(this.toolOutputExpanded);\n this.chatContainer.addChild(component);\n }\n break;\n }\n case \"branchSummary\": {\n this.chatContainer.addChild(new Spacer(1));\n const component = new BranchSummaryMessageComponent(\n message,\n this.getMarkdownThemeWithSettings(),\n );\n component.setExpanded(this.toolOutputExpanded);\n this.chatContainer.addChild(component);\n break;\n }\n case \"user\": {\n const textContent = this.getUserMessageText(message);\n if (textContent) {\n if (this.chatContainer.children.length > 0) {\n this.chatContainer.addChild(new Spacer(1));\n }\n const skillBlock = parseSkillBlock(textContent);\n if (skillBlock) {\n // Render skill block (collapsible)\n const component = new SkillInvocationMessageComponent(\n skillBlock,\n this.getMarkdownThemeWithSettings(),\n );\n component.setExpanded(this.toolOutputExpanded);\n this.chatContainer.addChild(component);\n // Render user message separately if present\n if (skillBlock.userMessage) {\n const userComponent = new UserMessageComponent(\n skillBlock.userMessage,\n this.getMarkdownThemeWithSettings(),\n this.outputPad,\n );\n this.chatContainer.addChild(userComponent);\n }\n } else {\n const userComponent = new UserMessageComponent(\n textContent,\n this.getMarkdownThemeWithSettings(),\n this.outputPad,\n );\n this.chatContainer.addChild(userComponent);\n }\n if (options?.populateHistory) {\n this.editor.addToHistory?.(textContent);\n }\n }\n break;\n }\n case \"assistant\": {\n const assistantComponent = new AssistantMessageComponent(\n message,\n this.hideThinkingBlock,\n this.getMarkdownThemeWithSettings(),\n this.hiddenThinkingLabel,\n this.outputPad,\n );\n this.chatContainer.addChild(assistantComponent);\n break;\n }\n case \"toolResult\": {\n // Tool results are rendered inline with tool calls, handled separately\n break;\n }\n default:\n break;\n }\n };\n\nInteractiveModeBase.prototype.renderSessionContext = function(this: InteractiveModeBase, sessionContext: SessionContext, options: { updateFooter?: boolean; populateHistory?: boolean } = {}): void {\n this.pendingTools.clear();\n const pendingDeferredInputs = [...this.deferredRenderedUserInputs];\n this.deferredRenderedUserInputs = [];\n this.deferredRenderedUserInputComponents.clear();\n\n if (options.updateFooter) {\n this.footer.invalidate();\n this.updateEditorBorderColor();\n }\n\n const entries = chatEntriesFromAgentMessages(sessionContext.messages);\n for (const entry of entries) {\n const component = this.addRenderedChatEntry(entry);\n if (\n entry.kind === \"tool\" &&\n entry.isPartial !== false &&\n component instanceof ToolExecutionComponent\n ) {\n this.pendingTools.set(entry.toolCallId, component);\n }\n if (options.populateHistory && entry.kind === \"user\") {\n this.editor.addToHistory?.(entry.text);\n }\n }\n\n for (const input of pendingDeferredInputs) {\n this.renderDeferredUserInput(input);\n }\n\n this.ui.requestRender();\n };\n\nInteractiveModeBase.prototype.attachStartupNoticesContainer = function(this: InteractiveModeBase, options: { resetDetached?: boolean } = {}): void {\n const isAttached = this.chatContainer.children.includes(this.startupNoticesContainer);\n if (isAttached) return;\n if (options.resetDetached) {\n this.startupNoticesContainer.clear();\n }\n this.chatContainer.addChild(this.startupNoticesContainer);\n };\n\nInteractiveModeBase.prototype.renderInitialMessages = function(this: InteractiveModeBase): void {\n this.attachStartupNoticesContainer({ resetDetached: true });\n // Get aligned messages and entries from session context\n const context = this.sessionManager.buildSessionContext();\n this.renderSessionContext(context, {\n updateFooter: true,\n populateHistory: true,\n });\n\n // Show compaction info if session was compacted\n const allEntries = this.sessionManager.getEntries();\n const compactionCount = allEntries.filter(\n (e) => e.type === \"compaction\",\n ).length;\n if (compactionCount > 0) {\n const times =\n compactionCount === 1 ? \"1 time\" : `${compactionCount} times`;\n this.showStatus(`Session compacted ${times}`);\n }\n };\n\nInteractiveModeBase.prototype.getUserInput = async function(this: InteractiveModeBase): Promise<string> {\n for (let attempt = 0; !this.startupCookedInputRecovered && attempt < 10; attempt += 1) {\n await yieldToEventLoop();\n if (this.recoverCookedStartupInput?.()) break;\n }\n while (true) {\n const queuedInput = this.pendingUserInputs.shift();\n if (queuedInput !== undefined) {\n return queuedInput;\n }\n\n if (this.startupReplayActiveInput) {\n await this.drainStartupReplayCommands();\n continue;\n }\n\n return new Promise((resolve) => {\n this.onInputCallback = (text: string) => {\n this.onInputCallback = undefined;\n resolve(text);\n };\n });\n }\n };\n\nInteractiveModeBase.prototype.rebuildChatFromMessages = function(this: InteractiveModeBase): void {\n this.chatContainer.clear();\n this.attachStartupNoticesContainer();\n const context = this.sessionManager.buildSessionContext();\n this.renderSessionContext(context);\n };\n"]}
|
|
1
|
+
{"version":3,"file":"interactive-render-chat.js","sourceRoot":"","sources":["../../../src/modes/interactive/interactive-render-chat.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AACjE,OAAO,EAAqK,MAAM,EAAE,IAAI,EAAE,eAAe,EAAE,yBAAyB,EAAE,sBAAsB,EAAE,6BAA6B,EAAE,4BAA4B,EAAE,sBAAsB,EAAE,sBAAsB,EAAE,wCAAwC,EAAE,sBAAsB,EAAE,+BAA+B,EAAE,sBAAsB,EAAE,oBAAoB,EAAE,oBAAoB,EAAE,KAAK,EAAE,MAAM,4BAA4B,CAAC;AAC5jB,OAAO,EAAE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C,IAAI,CAAC,yBAAyB,GAAG,IAAI,CAAC;gBACtC,oBAAoB,CAAC,iCAAiC,CAAC,CAAC;gBACxD,KAAK,CAAC,KAAK,IAAI,EAAE;oBACf,MAAM,gBAAgB,EAAE,CAAC;oBACzB,IAAI,CAAC,kBAAkB,CAAC,eAAe,EAAE,CAAC;oBAC1C,IAAI,IAAI,CAAC,sBAAsB,EAAE,CAAC;wBAChC,MAAM,IAAI,CAAC,6BAA6B,EAAE,CAAC;oBAC7C,CAAC;gBACH,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE;oBACnB,MAAM,OAAO,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;oBACvE,OAAO,CAAC,KAAK,CAAC,iDAAiD,OAAO,EAAE,CAAC,CAAC;gBAC5E,CAAC,CAAC,CAAC;YACL,CAAC;QACH,CAAC,CAAC,CAAC;IACL,CAAC;AACH,CAAC,CAAC;AAEJ,mBAAmB,CAAC,SAAS,CAAC,uBAAuB,GAAG;IACpD,IAAI,CAAC,aAAa,CAAC,KAAK,EAAE,CAAC;IAC3B,IAAI,CAAC,6BAA6B,EAAE,CAAC;IACrC,MAAM,OAAO,GAAG,IAAI,CAAC,cAAc,CAAC,mBAAmB,EAAE,CAAC;IAC1D,IAAI,CAAC,oBAAoB,CAAC,OAAO,CAAC,CAAC;AACrC,CAAC,CAAC","sourcesContent":["import { InteractiveModeBase } from \"./interactive-mode-base.ts\";\nimport { type AgentMessage, type Component, type ContextCompactionResult, type SessionContext, type TruncationResult, type ChatMessageEntry, type ChatMessageRenderOptions, Spacer, Text, parseSkillBlock, AssistantMessageComponent, BashExecutionComponent, BranchSummaryMessageComponent, chatEntriesFromAgentMessages, renderChatMessageEntry, addChatTranscriptEntry, ContextCompactionSummaryMessageComponent, CustomMessageComponent, SkillInvocationMessageComponent, ToolExecutionComponent, UserMessageComponent, recordTimeSinceReset, theme } from \"./interactive-mode-deps.ts\";\nimport { yieldToEventLoop } from \"../../utils/event-loop.ts\";\n\nInteractiveModeBase.prototype.showStatus = function(this: InteractiveModeBase, message: string): void {\n const children = this.chatContainer.children;\n const last =\n children.length > 0 ? children[children.length - 1] : undefined;\n const secondLast =\n children.length > 1 ? children[children.length - 2] : undefined;\n\n if (\n last &&\n secondLast &&\n last === this.lastStatusText &&\n secondLast === this.lastStatusSpacer\n ) {\n this.lastStatusText.setText(theme.fg(\"dim\", message));\n this.ui.requestRender();\n return;\n }\n\n const spacer = new Spacer(1);\n const text = new Text(theme.fg(\"dim\", message), 1, 0);\n this.chatContainer.addChild(spacer);\n this.chatContainer.addChild(text);\n this.lastStatusSpacer = spacer;\n this.lastStatusText = text;\n this.ui.requestRender();\n };\n\nInteractiveModeBase.prototype.renderDeferredUserInput = function(this: InteractiveModeBase, text: string): void {\n this.deferredRenderedUserInputs.push(text);\n const startIndex = this.chatContainer.children.length;\n this.addMessageToChat({ role: \"user\", content: text } as AgentMessage);\n const renderedComponents = this.chatContainer.children.slice(startIndex);\n const trackedComponents = this.deferredRenderedUserInputComponents.get(text) ?? [];\n trackedComponents.push(renderedComponents);\n this.deferredRenderedUserInputComponents.set(text, trackedComponents);\n this.updatePendingMessagesDisplay();\n this.ui.requestRender();\n };\n\nInteractiveModeBase.prototype.consumeDeferredRenderedUserInput = function(this: InteractiveModeBase, text: string): boolean {\n const index = this.deferredRenderedUserInputs.indexOf(text);\n if (index === -1) return false;\n this.deferredRenderedUserInputs.splice(index, 1);\n const trackedComponents = this.deferredRenderedUserInputComponents.get(text);\n trackedComponents?.shift();\n if (trackedComponents && trackedComponents.length === 0) {\n this.deferredRenderedUserInputComponents.delete(text);\n }\n return true;\n };\n\nInteractiveModeBase.prototype.discardDeferredRenderedUserInput = function(this: InteractiveModeBase, text: string): void {\n const index = this.deferredRenderedUserInputs.indexOf(text);\n if (index !== -1) this.deferredRenderedUserInputs.splice(index, 1);\n const trackedComponents = this.deferredRenderedUserInputComponents.get(text);\n const componentsToRemove = trackedComponents?.shift();\n if (trackedComponents && trackedComponents.length === 0) {\n this.deferredRenderedUserInputComponents.delete(text);\n }\n if (!componentsToRemove) return;\n for (const component of componentsToRemove) {\n this.chatContainer.removeChild(component);\n }\n this.updatePendingMessagesDisplay();\n this.ui.requestRender();\n };\n\nInteractiveModeBase.prototype.chatMessageRenderOptions = function(this: InteractiveModeBase): ChatMessageRenderOptions {\n return {\n ui: this.ui,\n cwd: this.sessionManager.getCwd(),\n markdownTheme: this.getMarkdownThemeWithSettings(),\n hideThinkingBlock: this.hideThinkingBlock,\n hiddenThinkingLabel: this.hiddenThinkingLabel,\n toolOutputExpanded: this.toolOutputExpanded,\n showImages: this.settingsManager.getShowImages(),\n imageWidthCells: this.settingsManager.getImageWidthCells(),\n outputPad: this.outputPad,\n getToolDefinition: (toolName) => this.getRegisteredToolDefinition(toolName),\n getCustomMessageRenderer: (customType) =>\n this.session.extensionRunner.getMessageRenderer(customType),\n };\n };\n\nInteractiveModeBase.prototype.addRenderedChatEntry = function(this: InteractiveModeBase, entry: ChatMessageEntry): Component {\n const component = renderChatMessageEntry(entry, this.chatMessageRenderOptions());\n addChatTranscriptEntry(this.chatContainer, component, entry.role);\n return component;\n };\n\nInteractiveModeBase.prototype.addContextCompactionSummaryToChat = function(this: InteractiveModeBase, result: ContextCompactionResult): void {\n this.chatContainer.addChild(new Spacer(1));\n const component = new ContextCompactionSummaryMessageComponent(\n result,\n this.getMarkdownThemeWithSettings(),\n );\n component.setExpanded(this.toolOutputExpanded);\n this.chatContainer.addChild(component);\n };\n\nInteractiveModeBase.prototype.addMessageToChat = function(this: InteractiveModeBase, message: AgentMessage, options?: { populateHistory?: boolean }): void {\n switch (message.role) {\n case \"bashExecution\": {\n const component = new BashExecutionComponent(\n message.command,\n this.ui,\n message.excludeFromContext,\n );\n if (message.output) {\n component.appendOutput(message.output);\n }\n component.setComplete(\n message.exitCode,\n message.cancelled,\n message.truncated\n ? ({ truncated: true } as TruncationResult)\n : undefined,\n message.fullOutputPath,\n );\n this.chatContainer.addChild(component);\n break;\n }\n case \"custom\": {\n if (message.display) {\n const renderer = this.session.extensionRunner.getMessageRenderer(\n message.customType,\n );\n const component = new CustomMessageComponent(\n message,\n renderer,\n this.getMarkdownThemeWithSettings(),\n );\n component.setExpanded(this.toolOutputExpanded);\n this.chatContainer.addChild(component);\n }\n break;\n }\n case \"branchSummary\": {\n this.chatContainer.addChild(new Spacer(1));\n const component = new BranchSummaryMessageComponent(\n message,\n this.getMarkdownThemeWithSettings(),\n );\n component.setExpanded(this.toolOutputExpanded);\n this.chatContainer.addChild(component);\n break;\n }\n case \"user\": {\n const textContent = this.getUserMessageText(message);\n if (textContent) {\n if (this.chatContainer.children.length > 0) {\n this.chatContainer.addChild(new Spacer(1));\n }\n const skillBlock = parseSkillBlock(textContent);\n if (skillBlock) {\n // Render skill block (collapsible)\n const component = new SkillInvocationMessageComponent(\n skillBlock,\n this.getMarkdownThemeWithSettings(),\n );\n component.setExpanded(this.toolOutputExpanded);\n this.chatContainer.addChild(component);\n // Render user message separately if present\n if (skillBlock.userMessage) {\n const userComponent = new UserMessageComponent(\n skillBlock.userMessage,\n this.getMarkdownThemeWithSettings(),\n this.outputPad,\n );\n this.chatContainer.addChild(userComponent);\n }\n } else {\n const userComponent = new UserMessageComponent(\n textContent,\n this.getMarkdownThemeWithSettings(),\n this.outputPad,\n );\n this.chatContainer.addChild(userComponent);\n }\n if (options?.populateHistory) {\n this.editor.addToHistory?.(textContent);\n }\n }\n break;\n }\n case \"assistant\": {\n const assistantComponent = new AssistantMessageComponent(\n message,\n this.hideThinkingBlock,\n this.getMarkdownThemeWithSettings(),\n this.hiddenThinkingLabel,\n this.outputPad,\n );\n this.chatContainer.addChild(assistantComponent);\n break;\n }\n case \"toolResult\": {\n // Tool results are rendered inline with tool calls, handled separately\n break;\n }\n default:\n break;\n }\n };\n\nInteractiveModeBase.prototype.renderSessionContext = function(this: InteractiveModeBase, sessionContext: SessionContext, options: { updateFooter?: boolean; populateHistory?: boolean } = {}): void {\n this.pendingTools.clear();\n const pendingDeferredInputs = [...this.deferredRenderedUserInputs];\n this.deferredRenderedUserInputs = [];\n this.deferredRenderedUserInputComponents.clear();\n\n if (options.updateFooter) {\n this.footer.invalidate();\n this.updateEditorBorderColor();\n }\n\n const entries = chatEntriesFromAgentMessages(sessionContext.messages);\n for (const entry of entries) {\n const component = this.addRenderedChatEntry(entry);\n if (\n entry.kind === \"tool\" &&\n entry.isPartial !== false &&\n component instanceof ToolExecutionComponent\n ) {\n this.pendingTools.set(entry.toolCallId, component);\n }\n if (options.populateHistory && entry.kind === \"user\") {\n this.editor.addToHistory?.(entry.text);\n }\n }\n\n for (const input of pendingDeferredInputs) {\n this.renderDeferredUserInput(input);\n }\n\n this.ui.requestRender();\n };\n\nInteractiveModeBase.prototype.attachStartupNoticesContainer = function(this: InteractiveModeBase, options: { resetDetached?: boolean } = {}): void {\n const isAttached = this.chatContainer.children.includes(this.startupNoticesContainer);\n if (isAttached) return;\n if (options.resetDetached) {\n this.startupNoticesContainer.clear();\n }\n this.chatContainer.addChild(this.startupNoticesContainer);\n };\n\nInteractiveModeBase.prototype.renderInitialMessages = function(this: InteractiveModeBase): void {\n this.attachStartupNoticesContainer({ resetDetached: true });\n // Get aligned messages and entries from session context\n const context = this.sessionManager.buildSessionContext();\n this.renderSessionContext(context, {\n updateFooter: true,\n populateHistory: true,\n });\n\n // Show compaction info if session was compacted\n const allEntries = this.sessionManager.getEntries();\n const compactionCount = allEntries.filter(\n (e) => e.type === \"compaction\",\n ).length;\n if (compactionCount > 0) {\n const times =\n compactionCount === 1 ? \"1 time\" : `${compactionCount} times`;\n this.showStatus(`Session compacted ${times}`);\n }\n };\n\nInteractiveModeBase.prototype.getUserInput = async function(this: InteractiveModeBase): Promise<string> {\n for (let attempt = 0; !this.startupCookedInputRecovered && attempt < 10; attempt += 1) {\n await yieldToEventLoop();\n if (this.recoverCookedStartupInput?.()) break;\n }\n while (true) {\n const queuedInput = this.pendingUserInputs.shift();\n if (queuedInput !== undefined) {\n return queuedInput;\n }\n\n if (this.startupReplayActiveInput) {\n await this.drainStartupReplayCommands();\n continue;\n }\n\n return new Promise((resolve) => {\n this.onInputCallback = (text: string) => {\n this.onInputCallback = undefined;\n resolve(text);\n };\n if (!this.inputHandlerReadyRecorded) {\n this.inputHandlerReadyRecorded = true;\n recordTimeSinceReset(\"interactive-input-handler-ready\");\n void (async () => {\n await yieldToEventLoop();\n this.footerDataProvider.startGitWatcher();\n if (this.deferredStartupPending) {\n await this.ensureDeferredStartupComplete();\n }\n })().catch((error) => {\n const message = error instanceof Error ? error.message : String(error);\n console.error(`Deferred input-readiness startup task failed: ${message}`);\n });\n }\n });\n }\n };\n\nInteractiveModeBase.prototype.rebuildChatFromMessages = function(this: InteractiveModeBase): void {\n this.chatContainer.clear();\n this.attachStartupNoticesContainer();\n const context = this.sessionManager.buildSessionContext();\n this.renderSessionContext(context);\n };\n"]}
|