@draht/coding-agent 2026.7.13 → 2026.9.5-1
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 +241 -0
- package/README.md +47 -2
- package/agents/debugger.md +12 -1
- package/agents/git-committer.md +1 -0
- package/agents/implementer.md +20 -0
- package/agents/investigator.md +75 -0
- package/agents/reviewer.md +7 -0
- package/agents/spec-reviewer.md +66 -0
- package/agents/verifier.md +4 -3
- package/bin/draht-tools.cjs +472 -41
- package/dist/agents/debugger.md +12 -1
- package/dist/agents/git-committer.md +1 -0
- package/dist/agents/implementer.md +20 -0
- package/dist/agents/investigator.md +75 -0
- package/dist/agents/reviewer.md +7 -0
- package/dist/agents/spec-reviewer.md +66 -0
- package/dist/agents/verifier.md +4 -3
- package/dist/bun/cli.js +2 -0
- package/dist/bun/cli.js.map +1 -1
- package/dist/cli/args.d.ts +10 -0
- package/dist/cli/args.d.ts.map +1 -1
- package/dist/cli/args.js +80 -3
- package/dist/cli/args.js.map +1 -1
- package/dist/cli/attach-mode.d.ts +61 -0
- package/dist/cli/attach-mode.d.ts.map +1 -1
- package/dist/cli/attach-mode.js +243 -5
- package/dist/cli/attach-mode.js.map +1 -1
- package/dist/cli/config-selector.js +1 -1
- package/dist/cli/config-selector.js.map +1 -1
- package/dist/cli/credential-print.d.ts +23 -0
- package/dist/cli/credential-print.d.ts.map +1 -0
- package/dist/cli/credential-print.js +117 -0
- package/dist/cli/credential-print.js.map +1 -0
- package/dist/cli/list-models.d.ts +2 -2
- package/dist/cli/list-models.d.ts.map +1 -1
- package/dist/cli/list-models.js +3 -3
- package/dist/cli/list-models.js.map +1 -1
- package/dist/cli/startup-ui.js +1 -1
- package/dist/cli/startup-ui.js.map +1 -1
- package/dist/config.d.ts +9 -0
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +31 -4
- package/dist/config.js.map +1 -1
- package/dist/core/agent-session-runtime.d.ts +17 -1
- package/dist/core/agent-session-runtime.d.ts.map +1 -1
- package/dist/core/agent-session-runtime.js +90 -30
- package/dist/core/agent-session-runtime.js.map +1 -1
- package/dist/core/agent-session-services.d.ts +4 -7
- package/dist/core/agent-session-services.d.ts.map +1 -1
- package/dist/core/agent-session-services.js +24 -9
- package/dist/core/agent-session-services.js.map +1 -1
- package/dist/core/agent-session.d.ts +87 -27
- package/dist/core/agent-session.d.ts.map +1 -1
- package/dist/core/agent-session.js +337 -154
- package/dist/core/agent-session.js.map +1 -1
- package/dist/core/auth-storage.d.ts +20 -104
- package/dist/core/auth-storage.d.ts.map +1 -1
- package/dist/core/auth-storage.js +104 -260
- package/dist/core/auth-storage.js.map +1 -1
- package/dist/core/builtins/checkpoints.d.ts +20 -0
- package/dist/core/builtins/checkpoints.d.ts.map +1 -0
- package/dist/core/builtins/checkpoints.js +161 -0
- package/dist/core/builtins/checkpoints.js.map +1 -0
- package/dist/core/builtins/duet.d.ts +26 -0
- package/dist/core/builtins/duet.d.ts.map +1 -0
- package/dist/core/builtins/duet.js +660 -0
- package/dist/core/builtins/duet.js.map +1 -0
- package/dist/core/builtins/index.d.ts.map +1 -1
- package/dist/core/builtins/index.js +7 -1
- package/dist/core/builtins/index.js.map +1 -1
- package/dist/core/builtins/subagent.d.ts +24 -4
- package/dist/core/builtins/subagent.d.ts.map +1 -1
- package/dist/core/builtins/subagent.js +278 -35
- package/dist/core/builtins/subagent.js.map +1 -1
- package/dist/core/cache-stats.d.ts +2 -2
- package/dist/core/cache-stats.d.ts.map +1 -1
- package/dist/core/cache-stats.js +1 -1
- package/dist/core/cache-stats.js.map +1 -1
- package/dist/core/checkpoints/checkpoint-cli.d.ts +17 -0
- package/dist/core/checkpoints/checkpoint-cli.d.ts.map +1 -0
- package/dist/core/checkpoints/checkpoint-cli.js +78 -0
- package/dist/core/checkpoints/checkpoint-cli.js.map +1 -0
- package/dist/core/checkpoints/checkpoint-manager.d.ts +294 -0
- package/dist/core/checkpoints/checkpoint-manager.d.ts.map +1 -0
- package/dist/core/checkpoints/checkpoint-manager.js +865 -0
- package/dist/core/checkpoints/checkpoint-manager.js.map +1 -0
- package/dist/core/checkpoints/rewind.d.ts +141 -0
- package/dist/core/checkpoints/rewind.d.ts.map +1 -0
- package/dist/core/checkpoints/rewind.js +246 -0
- package/dist/core/checkpoints/rewind.js.map +1 -0
- package/dist/core/compaction/branch-summarization.d.ts +9 -3
- package/dist/core/compaction/branch-summarization.d.ts.map +1 -1
- package/dist/core/compaction/branch-summarization.js +16 -14
- package/dist/core/compaction/branch-summarization.js.map +1 -1
- package/dist/core/compaction/compaction.d.ts +24 -3
- package/dist/core/compaction/compaction.d.ts.map +1 -1
- package/dist/core/compaction/compaction.js +96 -30
- package/dist/core/compaction/compaction.js.map +1 -1
- package/dist/core/compaction/utils.d.ts +1 -1
- package/dist/core/compaction/utils.d.ts.map +1 -1
- package/dist/core/compaction/utils.js +6 -17
- package/dist/core/compaction/utils.js.map +1 -1
- package/dist/core/context-windows.d.ts +7 -0
- package/dist/core/context-windows.d.ts.map +1 -0
- package/dist/core/context-windows.js +35 -0
- package/dist/core/context-windows.js.map +1 -0
- package/dist/core/extensions/index.d.ts +1 -1
- package/dist/core/extensions/index.d.ts.map +1 -1
- package/dist/core/extensions/index.js.map +1 -1
- package/dist/core/extensions/loader.d.ts.map +1 -1
- package/dist/core/extensions/loader.js +101 -23
- package/dist/core/extensions/loader.js.map +1 -1
- package/dist/core/extensions/runner.d.ts +19 -3
- package/dist/core/extensions/runner.d.ts.map +1 -1
- package/dist/core/extensions/runner.js +117 -2
- package/dist/core/extensions/runner.js.map +1 -1
- package/dist/core/extensions/types.d.ts +236 -9
- package/dist/core/extensions/types.d.ts.map +1 -1
- package/dist/core/extensions/types.js.map +1 -1
- package/dist/core/extensions/wrapper.d.ts.map +1 -1
- package/dist/core/extensions/wrapper.js +22 -3
- package/dist/core/extensions/wrapper.js.map +1 -1
- package/dist/core/footer-data-provider.d.ts +10 -0
- package/dist/core/footer-data-provider.d.ts.map +1 -1
- package/dist/core/footer-data-provider.js +1 -1
- package/dist/core/footer-data-provider.js.map +1 -1
- package/dist/core/http-dispatcher.d.ts.map +1 -1
- package/dist/core/http-dispatcher.js +7 -0
- package/dist/core/http-dispatcher.js.map +1 -1
- package/dist/core/index.d.ts +1 -1
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/index.js.map +1 -1
- package/dist/core/keybindings.d.ts +18 -3
- package/dist/core/keybindings.d.ts.map +1 -1
- package/dist/core/keybindings.js +12 -3
- package/dist/core/keybindings.js.map +1 -1
- package/dist/core/model-config.d.ts +542 -0
- package/dist/core/model-config.d.ts.map +1 -0
- package/dist/core/model-config.js +247 -0
- package/dist/core/model-config.js.map +1 -0
- package/dist/core/model-registry.d.ts +19 -124
- package/dist/core/model-registry.d.ts.map +1 -1
- package/dist/core/model-registry.js +56 -727
- package/dist/core/model-registry.js.map +1 -1
- package/dist/core/model-resolver.d.ts +7 -6
- package/dist/core/model-resolver.d.ts.map +1 -1
- package/dist/core/model-resolver.js +74 -27
- package/dist/core/model-resolver.js.map +1 -1
- package/dist/core/model-runtime.d.ts +89 -0
- package/dist/core/model-runtime.d.ts.map +1 -0
- package/dist/core/model-runtime.js +451 -0
- package/dist/core/model-runtime.js.map +1 -0
- package/dist/core/models-store.d.ts +17 -0
- package/dist/core/models-store.d.ts.map +1 -0
- package/dist/core/models-store.js +46 -0
- package/dist/core/models-store.js.map +1 -0
- package/dist/core/multi-agent/permission-gate.d.ts.map +1 -1
- package/dist/core/multi-agent/permission-gate.js +4 -3
- package/dist/core/multi-agent/permission-gate.js.map +1 -1
- package/dist/core/multi-agent/worktree.d.ts +2 -0
- package/dist/core/multi-agent/worktree.d.ts.map +1 -1
- package/dist/core/multi-agent/worktree.js +2 -2
- package/dist/core/multi-agent/worktree.js.map +1 -1
- package/dist/core/package-manager.d.ts +7 -1
- package/dist/core/package-manager.d.ts.map +1 -1
- package/dist/core/package-manager.js +41 -45
- package/dist/core/package-manager.js.map +1 -1
- package/dist/core/permission-relay/index.d.ts +19 -0
- package/dist/core/permission-relay/index.d.ts.map +1 -0
- package/dist/core/permission-relay/index.js +49 -0
- package/dist/core/permission-relay/index.js.map +1 -0
- package/dist/core/permission-relay/relay-ui-context.d.ts +39 -0
- package/dist/core/permission-relay/relay-ui-context.d.ts.map +1 -0
- package/dist/core/permission-relay/relay-ui-context.js +788 -0
- package/dist/core/permission-relay/relay-ui-context.js.map +1 -0
- package/dist/core/permission-relay/types.d.ts +222 -0
- package/dist/core/permission-relay/types.d.ts.map +1 -0
- package/dist/core/permission-relay/types.js +15 -0
- package/dist/core/permission-relay/types.js.map +1 -0
- package/dist/core/pi-manifest.d.ts +14 -0
- package/dist/core/pi-manifest.d.ts.map +1 -0
- package/dist/core/pi-manifest.js +35 -0
- package/dist/core/pi-manifest.js.map +1 -0
- package/dist/core/project-trust.js +2 -2
- package/dist/core/project-trust.js.map +1 -1
- package/dist/core/prompt-templates.d.ts +1 -0
- package/dist/core/prompt-templates.d.ts.map +1 -1
- package/dist/core/prompt-templates.js +4 -4
- package/dist/core/prompt-templates.js.map +1 -1
- package/dist/core/provider-composer.d.ts +55 -0
- package/dist/core/provider-composer.d.ts.map +1 -0
- package/dist/core/provider-composer.js +375 -0
- package/dist/core/provider-composer.js.map +1 -0
- package/dist/core/radius.d.ts +2 -0
- package/dist/core/radius.d.ts.map +1 -0
- package/dist/core/radius.js +2 -0
- package/dist/core/radius.js.map +1 -0
- package/dist/core/remote-catalog-provider.d.ts +5 -0
- package/dist/core/remote-catalog-provider.d.ts.map +1 -0
- package/dist/core/remote-catalog-provider.js +115 -0
- package/dist/core/remote-catalog-provider.js.map +1 -0
- package/dist/core/resource-loader.d.ts +36 -0
- package/dist/core/resource-loader.d.ts.map +1 -1
- package/dist/core/resource-loader.js +159 -27
- package/dist/core/resource-loader.js.map +1 -1
- package/dist/core/runtime-credentials.d.ts +15 -0
- package/dist/core/runtime-credentials.d.ts.map +1 -0
- package/dist/core/runtime-credentials.js +35 -0
- package/dist/core/runtime-credentials.js.map +1 -0
- package/dist/core/sandbox/bash-operations.d.ts +149 -0
- package/dist/core/sandbox/bash-operations.d.ts.map +1 -0
- package/dist/core/sandbox/bash-operations.js +163 -0
- package/dist/core/sandbox/bash-operations.js.map +1 -0
- package/dist/core/sandbox/env.d.ts +83 -0
- package/dist/core/sandbox/env.d.ts.map +1 -0
- package/dist/core/sandbox/env.js +123 -0
- package/dist/core/sandbox/env.js.map +1 -0
- package/dist/core/sandbox/executor.d.ts +104 -0
- package/dist/core/sandbox/executor.d.ts.map +1 -0
- package/dist/core/sandbox/executor.js +92 -0
- package/dist/core/sandbox/executor.js.map +1 -0
- package/dist/core/sandbox/index.d.ts +36 -0
- package/dist/core/sandbox/index.d.ts.map +1 -0
- package/dist/core/sandbox/index.js +36 -0
- package/dist/core/sandbox/index.js.map +1 -0
- package/dist/core/sandbox/linux.d.ts +121 -0
- package/dist/core/sandbox/linux.d.ts.map +1 -0
- package/dist/core/sandbox/linux.js +260 -0
- package/dist/core/sandbox/linux.js.map +1 -0
- package/dist/core/sandbox/policy.d.ts +142 -0
- package/dist/core/sandbox/policy.d.ts.map +1 -0
- package/dist/core/sandbox/policy.js +297 -0
- package/dist/core/sandbox/policy.js.map +1 -0
- package/dist/core/sandbox/real-path.d.ts +112 -0
- package/dist/core/sandbox/real-path.d.ts.map +1 -0
- package/dist/core/sandbox/real-path.js +158 -0
- package/dist/core/sandbox/real-path.js.map +1 -0
- package/dist/core/sandbox/seatbelt-profile.d.ts +95 -0
- package/dist/core/sandbox/seatbelt-profile.d.ts.map +1 -0
- package/dist/core/sandbox/seatbelt-profile.js +239 -0
- package/dist/core/sandbox/seatbelt-profile.js.map +1 -0
- package/dist/core/sandbox/seatbelt.d.ts +95 -0
- package/dist/core/sandbox/seatbelt.d.ts.map +1 -0
- package/dist/core/sandbox/seatbelt.js +154 -0
- package/dist/core/sandbox/seatbelt.js.map +1 -0
- package/dist/core/sandbox/self-test.d.ts +109 -0
- package/dist/core/sandbox/self-test.d.ts.map +1 -0
- package/dist/core/sandbox/self-test.js +369 -0
- package/dist/core/sandbox/self-test.js.map +1 -0
- package/dist/core/sandbox/spawn.d.ts +33 -0
- package/dist/core/sandbox/spawn.d.ts.map +1 -0
- package/dist/core/sandbox/spawn.js +87 -0
- package/dist/core/sandbox/spawn.js.map +1 -0
- package/dist/core/sdk.d.ts +3 -6
- package/dist/core/sdk.d.ts.map +1 -1
- package/dist/core/sdk.js +25 -22
- package/dist/core/sdk.js.map +1 -1
- package/dist/core/session-manager.d.ts +74 -7
- package/dist/core/session-manager.d.ts.map +1 -1
- package/dist/core/session-manager.js +169 -34
- package/dist/core/session-manager.js.map +1 -1
- package/dist/core/settings-manager.d.ts +22 -1
- package/dist/core/settings-manager.d.ts.map +1 -1
- package/dist/core/settings-manager.js +36 -16
- package/dist/core/settings-manager.js.map +1 -1
- package/dist/core/skills.d.ts +3 -1
- package/dist/core/skills.d.ts.map +1 -1
- package/dist/core/skills.js +19 -6
- package/dist/core/skills.js.map +1 -1
- package/dist/core/slash-commands.d.ts.map +1 -1
- package/dist/core/slash-commands.js +1 -0
- package/dist/core/slash-commands.js.map +1 -1
- package/dist/core/soak/soak-log.d.ts +298 -0
- package/dist/core/soak/soak-log.d.ts.map +1 -0
- package/dist/core/soak/soak-log.js +660 -0
- package/dist/core/soak/soak-log.js.map +1 -0
- package/dist/core/soak/soak-reader.d.ts +60 -0
- package/dist/core/soak/soak-reader.d.ts.map +1 -0
- package/dist/core/soak/soak-reader.js +106 -0
- package/dist/core/soak/soak-reader.js.map +1 -0
- package/dist/core/socket-server/discovery.d.ts +78 -1
- package/dist/core/socket-server/discovery.d.ts.map +1 -1
- package/dist/core/socket-server/discovery.js +356 -37
- package/dist/core/socket-server/discovery.js.map +1 -1
- package/dist/core/socket-server/index.d.ts +10 -4
- package/dist/core/socket-server/index.d.ts.map +1 -1
- package/dist/core/socket-server/index.js +6 -3
- package/dist/core/socket-server/index.js.map +1 -1
- package/dist/core/socket-server/permission-delivery.d.ts +125 -0
- package/dist/core/socket-server/permission-delivery.d.ts.map +1 -0
- package/dist/core/socket-server/permission-delivery.js +152 -0
- package/dist/core/socket-server/permission-delivery.js.map +1 -0
- package/dist/core/socket-server/permission-registry.d.ts +301 -0
- package/dist/core/socket-server/permission-registry.d.ts.map +1 -0
- package/dist/core/socket-server/permission-registry.js +410 -0
- package/dist/core/socket-server/permission-registry.js.map +1 -0
- package/dist/core/socket-server/permission-relay.d.ts +81 -0
- package/dist/core/socket-server/permission-relay.d.ts.map +1 -0
- package/dist/core/socket-server/permission-relay.js +528 -0
- package/dist/core/socket-server/permission-relay.js.map +1 -0
- package/dist/core/socket-server/safe-text.d.ts +83 -0
- package/dist/core/socket-server/safe-text.d.ts.map +1 -0
- package/dist/core/socket-server/safe-text.js +277 -0
- package/dist/core/socket-server/safe-text.js.map +1 -0
- package/dist/core/socket-server/session-integration.d.ts +65 -2
- package/dist/core/socket-server/session-integration.d.ts.map +1 -1
- package/dist/core/socket-server/session-integration.js +434 -32
- package/dist/core/socket-server/session-integration.js.map +1 -1
- package/dist/core/socket-server/socket-client.d.ts +21 -2
- package/dist/core/socket-server/socket-client.d.ts.map +1 -1
- package/dist/core/socket-server/socket-client.js +52 -1
- package/dist/core/socket-server/socket-client.js.map +1 -1
- package/dist/core/socket-server/socket-server.d.ts +152 -1
- package/dist/core/socket-server/socket-server.d.ts.map +1 -1
- package/dist/core/socket-server/socket-server.js +775 -26
- package/dist/core/socket-server/socket-server.js.map +1 -1
- package/dist/core/socket-server/types.d.ts +106 -2
- package/dist/core/socket-server/types.d.ts.map +1 -1
- package/dist/core/socket-server/types.js +13 -1
- package/dist/core/socket-server/types.js.map +1 -1
- package/dist/core/system-prompt.d.ts.map +1 -1
- package/dist/core/system-prompt.js +10 -21
- package/dist/core/system-prompt.js.map +1 -1
- package/dist/core/tools/bash.d.ts +3 -1
- package/dist/core/tools/bash.d.ts.map +1 -1
- package/dist/core/tools/bash.js +39 -7
- package/dist/core/tools/bash.js.map +1 -1
- package/dist/core/tools/edit.d.ts.map +1 -1
- package/dist/core/tools/edit.js +17 -2
- package/dist/core/tools/edit.js.map +1 -1
- package/dist/core/tools/find.d.ts +3 -0
- package/dist/core/tools/find.d.ts.map +1 -1
- package/dist/core/tools/find.js +11 -18
- package/dist/core/tools/find.js.map +1 -1
- package/dist/core/tools/read.js +1 -1
- package/dist/core/tools/read.js.map +1 -1
- package/dist/core/tools/tool-definition-wrapper.d.ts.map +1 -1
- package/dist/core/tools/tool-definition-wrapper.js +3 -1
- package/dist/core/tools/tool-definition-wrapper.js.map +1 -1
- package/dist/core/trust-manager.d.ts +6 -4
- package/dist/core/trust-manager.d.ts.map +1 -1
- package/dist/core/trust-manager.js +55 -21
- package/dist/core/trust-manager.js.map +1 -1
- package/dist/core/usage-totals.d.ts +19 -0
- package/dist/core/usage-totals.d.ts.map +1 -0
- package/dist/core/usage-totals.js +52 -0
- package/dist/core/usage-totals.js.map +1 -0
- package/dist/extensions/index.d.ts +3 -0
- package/dist/extensions/index.d.ts.map +1 -0
- package/dist/extensions/index.js +7 -0
- package/dist/extensions/index.js.map +1 -0
- package/dist/extensions/llama/client.d.ts +61 -0
- package/dist/extensions/llama/client.d.ts.map +1 -0
- package/dist/extensions/llama/client.js +300 -0
- package/dist/extensions/llama/client.js.map +1 -0
- package/dist/extensions/llama/huggingface.d.ts +23 -0
- package/dist/extensions/llama/huggingface.d.ts.map +1 -0
- package/dist/extensions/llama/huggingface.js +139 -0
- package/dist/extensions/llama/huggingface.js.map +1 -0
- package/dist/extensions/llama/index.d.ts +3 -0
- package/dist/extensions/llama/index.d.ts.map +1 -0
- package/dist/extensions/llama/index.js +208 -0
- package/dist/extensions/llama/index.js.map +1 -0
- package/dist/extensions/llama/provider.d.ts +10 -0
- package/dist/extensions/llama/provider.d.ts.map +1 -0
- package/dist/extensions/llama/provider.js +111 -0
- package/dist/extensions/llama/provider.js.map +1 -0
- package/dist/extensions/llama/ui.d.ts +42 -0
- package/dist/extensions/llama/ui.d.ts.map +1 -0
- package/dist/extensions/llama/ui.js +400 -0
- package/dist/extensions/llama/ui.js.map +1 -0
- package/dist/extensions/stub-provider/index.d.ts +9 -0
- package/dist/extensions/stub-provider/index.d.ts.map +1 -0
- package/dist/extensions/stub-provider/index.js +13 -0
- package/dist/extensions/stub-provider/index.js.map +1 -0
- package/dist/extensions/stub-provider/provider.d.ts +77 -0
- package/dist/extensions/stub-provider/provider.d.ts.map +1 -0
- package/dist/extensions/stub-provider/provider.js +193 -0
- package/dist/extensions/stub-provider/provider.js.map +1 -0
- package/dist/hooks/gsd/draht-quality-gate.js +3 -3
- package/dist/index.d.ts +4 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -3
- package/dist/index.js.map +1 -1
- package/dist/main.d.ts.map +1 -1
- package/dist/main.js +305 -61
- package/dist/main.js.map +1 -1
- package/dist/modes/interactive/components/assistant-message.d.ts.map +1 -1
- package/dist/modes/interactive/components/assistant-message.js +22 -10
- package/dist/modes/interactive/components/assistant-message.js.map +1 -1
- package/dist/modes/interactive/components/config-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/config-selector.js +3 -2
- package/dist/modes/interactive/components/config-selector.js.map +1 -1
- package/dist/modes/interactive/components/custom-editor.js +1 -1
- package/dist/modes/interactive/components/custom-editor.js.map +1 -1
- package/dist/modes/interactive/components/custom-message.d.ts +3 -1
- package/dist/modes/interactive/components/custom-message.d.ts.map +1 -1
- package/dist/modes/interactive/components/custom-message.js +9 -2
- package/dist/modes/interactive/components/custom-message.js.map +1 -1
- package/dist/modes/interactive/components/extension-editor.d.ts +1 -2
- package/dist/modes/interactive/components/extension-editor.d.ts.map +1 -1
- package/dist/modes/interactive/components/extension-editor.js +16 -46
- package/dist/modes/interactive/components/extension-editor.js.map +1 -1
- package/dist/modes/interactive/components/extension-selector.d.ts +49 -0
- package/dist/modes/interactive/components/extension-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/extension-selector.js +202 -5
- package/dist/modes/interactive/components/extension-selector.js.map +1 -1
- package/dist/modes/interactive/components/footer.d.ts.map +1 -1
- package/dist/modes/interactive/components/footer.js +24 -23
- package/dist/modes/interactive/components/footer.js.map +1 -1
- package/dist/modes/interactive/components/login-dialog.d.ts +5 -5
- package/dist/modes/interactive/components/login-dialog.d.ts.map +1 -1
- package/dist/modes/interactive/components/login-dialog.js +17 -8
- package/dist/modes/interactive/components/login-dialog.js.map +1 -1
- package/dist/modes/interactive/components/model-selector.d.ts +11 -4
- package/dist/modes/interactive/components/model-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/model-selector.js +74 -41
- package/dist/modes/interactive/components/model-selector.js.map +1 -1
- package/dist/modes/interactive/components/oauth-selector.d.ts +4 -4
- package/dist/modes/interactive/components/oauth-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/oauth-selector.js +14 -25
- package/dist/modes/interactive/components/oauth-selector.js.map +1 -1
- package/dist/modes/interactive/components/scoped-models-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/scoped-models-selector.js +22 -13
- package/dist/modes/interactive/components/scoped-models-selector.js.map +1 -1
- package/dist/modes/interactive/components/session-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/session-selector.js +10 -2
- package/dist/modes/interactive/components/session-selector.js.map +1 -1
- package/dist/modes/interactive/components/settings-selector.d.ts +2 -0
- package/dist/modes/interactive/components/settings-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/settings-selector.js +10 -0
- package/dist/modes/interactive/components/settings-selector.js.map +1 -1
- package/dist/modes/interactive/components/tool-execution.d.ts.map +1 -1
- package/dist/modes/interactive/components/tool-execution.js +10 -1
- package/dist/modes/interactive/components/tool-execution.js.map +1 -1
- package/dist/modes/interactive/components/tree-selector.d.ts +25 -2
- package/dist/modes/interactive/components/tree-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/tree-selector.js +68 -17
- package/dist/modes/interactive/components/tree-selector.js.map +1 -1
- package/dist/modes/interactive/external-editor.d.ts +12 -0
- package/dist/modes/interactive/external-editor.d.ts.map +1 -0
- package/dist/modes/interactive/external-editor.js +37 -0
- package/dist/modes/interactive/external-editor.js.map +1 -0
- package/dist/modes/interactive/interactive-mode.d.ts +107 -10
- package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode.js +763 -285
- package/dist/modes/interactive/interactive-mode.js.map +1 -1
- package/dist/modes/rpc/rpc-client.d.ts +4 -0
- package/dist/modes/rpc/rpc-client.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-client.js +7 -0
- package/dist/modes/rpc/rpc-client.js.map +1 -1
- package/dist/modes/rpc/rpc-mode.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-mode.js +185 -9
- package/dist/modes/rpc/rpc-mode.js.map +1 -1
- package/dist/modes/rpc/rpc-types.d.ts +79 -1
- package/dist/modes/rpc/rpc-types.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-types.js.map +1 -1
- package/dist/package-manager-cli.d.ts.map +1 -1
- package/dist/package-manager-cli.js +67 -5
- package/dist/package-manager-cli.js.map +1 -1
- package/dist/prompts/commands/atomic-commit.md +1 -12
- package/dist/prompts/commands/brainstorm.md +12 -15
- package/dist/prompts/commands/create-verification-skill.md +108 -0
- package/dist/prompts/commands/discuss-phase.md +3 -14
- package/dist/prompts/commands/execute-phase.md +3 -11
- package/dist/prompts/commands/fix.md +41 -18
- package/dist/prompts/commands/grill.md +66 -0
- package/dist/prompts/commands/init-project.md +5 -15
- package/dist/prompts/commands/map-codebase.md +1 -13
- package/dist/prompts/commands/new-project.md +5 -15
- package/dist/prompts/commands/next-milestone.md +1 -13
- package/dist/prompts/commands/orchestrate.md +1 -1
- package/dist/prompts/commands/pause-work.md +1 -13
- package/dist/prompts/commands/plan-phase.md +2 -11
- package/dist/prompts/commands/progress.md +0 -13
- package/dist/prompts/commands/quick.md +3 -11
- package/dist/prompts/commands/resolve-conflicts.md +71 -0
- package/dist/prompts/commands/resume-work.md +0 -13
- package/dist/prompts/commands/review.md +4 -13
- package/dist/prompts/commands/triage.md +159 -0
- package/dist/prompts/commands/verify-work.md +4 -14
- package/dist/prompts/commands/why.md +135 -0
- package/dist/skills/atomic-reasoning/SKILL.md +115 -0
- package/dist/skills/blast-radius/SKILL.md +55 -0
- package/dist/skills/epistemics/SKILL.md +99 -0
- package/dist/skills/hexagon-animation/SKILL.md +49 -0
- package/dist/skills/hexagon-animation/generate.mjs +81 -0
- package/dist/skills/hexagon-animation/template.html +361 -0
- package/dist/skills/typescript-discipline/SKILL.md +50 -0
- package/dist/skills/typescript-discipline/references/patterns.md +294 -0
- package/dist/skills/unslop/SKILL.md +101 -0
- package/dist/utils/canonical-path.d.ts +28 -0
- package/dist/utils/canonical-path.d.ts.map +1 -0
- package/dist/utils/canonical-path.js +90 -0
- package/dist/utils/canonical-path.js.map +1 -0
- package/dist/utils/child-process.d.ts +12 -1
- package/dist/utils/child-process.d.ts.map +1 -1
- package/dist/utils/child-process.js +25 -8
- package/dist/utils/child-process.js.map +1 -1
- package/dist/utils/clipboard-native.d.ts +1 -0
- package/dist/utils/clipboard-native.d.ts.map +1 -1
- package/dist/utils/clipboard-native.js.map +1 -1
- package/dist/utils/clipboard.d.ts +2 -0
- package/dist/utils/clipboard.d.ts.map +1 -1
- package/dist/utils/clipboard.js +53 -9
- package/dist/utils/clipboard.js.map +1 -1
- package/dist/utils/exif-orientation.d.ts.map +1 -1
- package/dist/utils/exif-orientation.js +2 -3
- package/dist/utils/exif-orientation.js.map +1 -1
- package/dist/utils/paths.d.ts +2 -7
- package/dist/utils/paths.d.ts.map +1 -1
- package/dist/utils/paths.js +13 -15
- package/dist/utils/paths.js.map +1 -1
- package/dist/utils/shell.d.ts.map +1 -1
- package/dist/utils/shell.js +6 -4
- package/dist/utils/shell.js.map +1 -1
- package/dist/utils/tools-manager.d.ts.map +1 -1
- package/dist/utils/tools-manager.js +3 -5
- package/dist/utils/tools-manager.js.map +1 -1
- package/dist/utils/version-check.d.ts.map +1 -1
- package/dist/utils/version-check.js +3 -1
- package/dist/utils/version-check.js.map +1 -1
- package/docs/attachable-sessions.md +79 -0
- package/docs/compaction.md +29 -24
- package/docs/containerization.md +23 -23
- package/docs/custom-provider.md +66 -32
- package/docs/development.md +9 -9
- package/docs/docs.json +6 -2
- package/docs/duet.md +42 -0
- package/docs/environment-variables.md +88 -0
- package/docs/extensions.md +278 -65
- package/docs/index.md +12 -10
- package/docs/json.md +12 -8
- package/docs/keybindings.md +8 -5
- package/docs/llama-cpp.md +99 -0
- package/docs/models.md +19 -8
- package/docs/packages.md +43 -42
- package/docs/prompt-templates.md +5 -4
- package/docs/providers.md +45 -11
- package/docs/quickstart.md +33 -33
- package/docs/rpc.md +190 -19
- package/docs/sdk.md +18 -15
- package/docs/security.md +18 -18
- package/docs/session-format.md +53 -15
- package/docs/sessions.md +17 -14
- package/docs/settings.md +26 -19
- package/docs/shell-aliases.md +2 -2
- package/docs/skills.md +12 -11
- package/docs/terminal-setup.md +12 -12
- package/docs/termux.md +6 -6
- package/docs/themes.md +11 -11
- package/docs/tmux.md +4 -4
- package/docs/tui.md +46 -31
- package/docs/usage.md +53 -63
- package/docs/windows.md +2 -2
- package/examples/extensions/custom-compaction.ts +4 -0
- package/examples/extensions/custom-provider-anthropic/index.ts +9 -3
- package/examples/extensions/custom-provider-anthropic/package.json +1 -1
- package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
- package/examples/extensions/custom-provider-qwen-cli/package.json +1 -1
- package/examples/extensions/gondolin/package.json +2 -2
- package/examples/extensions/handoff.ts +9 -1
- package/examples/extensions/kimi-deferred-tools.ts +61 -0
- package/examples/extensions/message-renderer.ts +2 -2
- package/examples/extensions/overlay-qa-tests.ts +3 -3
- package/examples/extensions/sandbox/package.json +1 -1
- package/examples/extensions/summarize.ts +3 -0
- package/examples/extensions/with-deps/package.json +1 -1
- package/examples/sdk/02-custom-model.ts +5 -8
- package/examples/sdk/09-api-keys-and-oauth.ts +15 -31
- package/examples/sdk/12-full-control.ts +9 -12
- package/hooks/gsd/draht-quality-gate.js +3 -3
- package/package.json +14 -11
- package/prompts/commands/atomic-commit.md +1 -12
- package/prompts/commands/brainstorm.md +12 -15
- package/prompts/commands/create-verification-skill.md +108 -0
- package/prompts/commands/discuss-phase.md +3 -14
- package/prompts/commands/execute-phase.md +3 -11
- package/prompts/commands/fix.md +41 -18
- package/prompts/commands/grill.md +66 -0
- package/prompts/commands/init-project.md +5 -15
- package/prompts/commands/map-codebase.md +1 -13
- package/prompts/commands/new-project.md +5 -15
- package/prompts/commands/next-milestone.md +1 -13
- package/prompts/commands/orchestrate.md +1 -1
- package/prompts/commands/pause-work.md +1 -13
- package/prompts/commands/plan-phase.md +2 -11
- package/prompts/commands/progress.md +0 -13
- package/prompts/commands/quick.md +3 -11
- package/prompts/commands/resolve-conflicts.md +71 -0
- package/prompts/commands/resume-work.md +0 -13
- package/prompts/commands/review.md +4 -13
- package/prompts/commands/triage.md +159 -0
- package/prompts/commands/verify-work.md +4 -14
- package/prompts/commands/why.md +135 -0
- package/skills/atomic-reasoning/SKILL.md +115 -0
- package/skills/blast-radius/SKILL.md +55 -0
- package/skills/epistemics/SKILL.md +99 -0
- package/skills/hexagon-animation/SKILL.md +49 -0
- package/skills/hexagon-animation/generate.mjs +81 -0
- package/skills/hexagon-animation/template.html +361 -0
- package/skills/typescript-discipline/SKILL.md +50 -0
- package/skills/typescript-discipline/references/patterns.md +294 -0
- package/skills/unslop/SKILL.md +101 -0
- package/dist/core/provider-display-names.d.ts +0 -2
- package/dist/core/provider-display-names.d.ts.map +0 -1
- package/dist/core/provider-display-names.js +0 -36
- package/dist/core/provider-display-names.js.map +0 -1
- package/dist/prompts/agents/build.md +0 -86
- package/dist/prompts/agents/plan.md +0 -79
- package/dist/prompts/agents/verify.md +0 -69
- package/prompts/agents/build.md +0 -86
- package/prompts/agents/plan.md +0 -79
- package/prompts/agents/verify.md +0 -69
|
@@ -6,7 +6,6 @@ import * as crypto from "node:crypto";
|
|
|
6
6
|
import * as fs from "node:fs";
|
|
7
7
|
import * as os from "node:os";
|
|
8
8
|
import * as path from "node:path";
|
|
9
|
-
import { getProviders, } from "@draht/ai/compat";
|
|
10
9
|
import { CombinedAutocompleteProvider, Container, fuzzyFilter, getCapabilities, hyperlink, Markdown, matchesKey, ProcessTerminal, Spacer, setKeybindings, Text, TruncatedText, TUI, visibleWidth, } from "@draht/tui";
|
|
11
10
|
import chalk from "chalk";
|
|
12
11
|
import { spawn, spawnSync } from "child_process";
|
|
@@ -14,20 +13,24 @@ import { APP_NAME, APP_TITLE, CONFIG_DIR_NAME, DISPLAY_VERSION, getAgentDir, get
|
|
|
14
13
|
import { parseSkillBlock } from "../../core/agent-session.js";
|
|
15
14
|
import { SessionImportFileNotFoundError } from "../../core/agent-session-runtime.js";
|
|
16
15
|
import { CACHE_TTL_MS, collectCacheMisses, computeCacheWaste, detectCacheMiss, } from "../../core/cache-stats.js";
|
|
16
|
+
import { CheckpointManager } from "../../core/checkpoints/checkpoint-manager.js";
|
|
17
|
+
import { DEFAULT_REWIND_SCOPE, listRewindTargets, performRewind, REWIND_SCOPE_CHOICES, rewindScopeForLabel, } from "../../core/checkpoints/rewind.js";
|
|
18
|
+
import { formatContextWindow } from "../../core/context-windows.js";
|
|
17
19
|
import { FooterDataProvider } from "../../core/footer-data-provider.js";
|
|
18
20
|
import { configureHttpDispatcher, formatHttpIdleTimeoutMs } from "../../core/http-dispatcher.js";
|
|
19
21
|
import { KeybindingsManager } from "../../core/keybindings.js";
|
|
20
22
|
import { createCompactionSummaryMessage } from "../../core/messages.js";
|
|
21
|
-
import { defaultModelPerProvider, findExactModelReferenceMatch, resolveModelScope } from "../../core/model-resolver.js";
|
|
23
|
+
import { defaultModelPerProvider, findExactModelReferenceMatch, resolveModelScope, resolveModelScopeWithDiagnostics, } from "../../core/model-resolver.js";
|
|
22
24
|
import { DefaultPackageManager } from "../../core/package-manager.js";
|
|
23
|
-
import { BUILT_IN_PROVIDER_DISPLAY_NAMES } from "../../core/provider-display-names.js";
|
|
24
25
|
import { formatMissingSessionCwdPrompt, MissingSessionCwdError } from "../../core/session-cwd.js";
|
|
25
26
|
import { SessionManager, sessionEntryToContextMessages } from "../../core/session-manager.js";
|
|
26
27
|
import { BUILTIN_SLASH_COMMANDS } from "../../core/slash-commands.js";
|
|
28
|
+
import { boundedSafeText } from "../../core/socket-server/safe-text.js";
|
|
27
29
|
import { isInstallTelemetryEnabled } from "../../core/telemetry.js";
|
|
28
30
|
import { hasTrustRequiringProjectResources, ProjectTrustStore } from "../../core/trust-manager.js";
|
|
31
|
+
import { getUsageCostBreakdown } from "../../core/usage-totals.js";
|
|
29
32
|
import { getChangelogPath, getNewEntries, normalizeChangelogLinks, parseChangelog } from "../../utils/changelog.js";
|
|
30
|
-
import { copyToClipboard } from "../../utils/clipboard.js";
|
|
33
|
+
import { copyToClipboard, readClipboardText } from "../../utils/clipboard.js";
|
|
31
34
|
import { extensionForImageMimeType, readClipboardImage } from "../../utils/clipboard-image.js";
|
|
32
35
|
import { parseGitUrl } from "../../utils/git.js";
|
|
33
36
|
import { sendTerminalNotification } from "../../utils/notify.js";
|
|
@@ -50,7 +53,7 @@ import { DynamicBorder } from "./components/dynamic-border.js";
|
|
|
50
53
|
import { EarendilAnnouncementComponent } from "./components/earendil-announcement.js";
|
|
51
54
|
import { ExtensionEditorComponent } from "./components/extension-editor.js";
|
|
52
55
|
import { ExtensionInputComponent } from "./components/extension-input.js";
|
|
53
|
-
import { ExtensionSelectorComponent } from "./components/extension-selector.js";
|
|
56
|
+
import { boundDialogText, ExtensionSelectorComponent, MAX_DETAIL_ROWS } from "./components/extension-selector.js";
|
|
54
57
|
import { FooterComponent, formatTokens } from "./components/footer.js";
|
|
55
58
|
import { formatKeyText, keyDisplayText, keyHint, keyText, rawKeyHint } from "./components/keybinding-hints.js";
|
|
56
59
|
import { LoginDialogComponent } from "./components/login-dialog.js";
|
|
@@ -66,6 +69,7 @@ import { TreeSelectorComponent } from "./components/tree-selector.js";
|
|
|
66
69
|
import { TrustSelectorComponent } from "./components/trust-selector.js";
|
|
67
70
|
import { UserMessageComponent } from "./components/user-message.js";
|
|
68
71
|
import { UserMessageSelectorComponent } from "./components/user-message-selector.js";
|
|
72
|
+
import { editInExternalEditor } from "./external-editor.js";
|
|
69
73
|
import { getModelSearchText } from "./model-search.js";
|
|
70
74
|
import { getAvailableThemes, getAvailableThemesWithPaths, getEditorTheme, getMarkdownTheme, getThemeByName, onThemeChange, setRegisteredThemes, stopThemeWatcher, Theme, theme, } from "./theme/theme.js";
|
|
71
75
|
import { InteractiveThemeController } from "./theme/theme-controller.js";
|
|
@@ -93,7 +97,7 @@ function isDeadTerminalError(error) {
|
|
|
93
97
|
const code = error.code;
|
|
94
98
|
return code !== undefined && DEAD_TERMINAL_ERROR_CODES.has(code);
|
|
95
99
|
}
|
|
96
|
-
const ANTHROPIC_SUBSCRIPTION_AUTH_WARNING = "Anthropic subscription auth is active. Third-party harness usage draws from extra usage and is billed per token, not your Claude plan limits. Manage extra usage at https://claude.ai/settings/usage.";
|
|
100
|
+
const ANTHROPIC_SUBSCRIPTION_AUTH_WARNING = "Anthropic subscription auth is active. Third-party harness usage draws from extra usage and is billed per token, not your Claude plan limits. Manage extra usage at https://claude.ai/settings/usage. Disable this warning in /settings.";
|
|
97
101
|
function isAnthropicSubscriptionAuthKey(apiKey) {
|
|
98
102
|
return typeof apiKey === "string" && apiKey.startsWith("sk-ant-oat");
|
|
99
103
|
}
|
|
@@ -124,17 +128,6 @@ export function formatResumeCommand(sessionManager) {
|
|
|
124
128
|
function hasDefaultModelProvider(providerId) {
|
|
125
129
|
return providerId in defaultModelPerProvider;
|
|
126
130
|
}
|
|
127
|
-
const BEDROCK_PROVIDER_ID = "amazon-bedrock";
|
|
128
|
-
const BUILT_IN_MODEL_PROVIDERS = new Set(getProviders());
|
|
129
|
-
export function isApiKeyLoginProvider(providerId, oauthProviderIds, builtInProviderIds = BUILT_IN_MODEL_PROVIDERS) {
|
|
130
|
-
if (BUILT_IN_PROVIDER_DISPLAY_NAMES[providerId]) {
|
|
131
|
-
return true;
|
|
132
|
-
}
|
|
133
|
-
if (builtInProviderIds.has(providerId)) {
|
|
134
|
-
return false;
|
|
135
|
-
}
|
|
136
|
-
return !oauthProviderIds.has(providerId);
|
|
137
|
-
}
|
|
138
131
|
const AUTH_TYPE_ORDER = { oauth: 0, api_key: 1 };
|
|
139
132
|
function createFuzzyAutocompleteItems(items, prefix, getSearchText, toAutocompleteItem) {
|
|
140
133
|
const filtered = fuzzyFilter(items, prefix, getSearchText);
|
|
@@ -220,6 +213,10 @@ export class InteractiveMode {
|
|
|
220
213
|
this.signalCleanupHandlers = [];
|
|
221
214
|
// Track if editor is in bash mode (text starts with !)
|
|
222
215
|
this.isBashMode = false;
|
|
216
|
+
// True while `/rewind` is rewriting the working tree. The selector hands
|
|
217
|
+
// focus back to the editor before the restore finishes, so submissions have
|
|
218
|
+
// to be gated here or a new prompt runs against a half-restored tree.
|
|
219
|
+
this.isRewindRunning = false;
|
|
223
220
|
// Track current bash execution component
|
|
224
221
|
this.bashComponent = undefined;
|
|
225
222
|
// Track pending bash components (shown in pending area, moved to chat on submit)
|
|
@@ -230,8 +227,22 @@ export class InteractiveMode {
|
|
|
230
227
|
this.shutdownRequested = false;
|
|
231
228
|
// Extension UI state
|
|
232
229
|
this.extensionSelector = undefined;
|
|
230
|
+
/**
|
|
231
|
+
* Settles the promise of the dialog currently occupying {@link extensionSelector}.
|
|
232
|
+
*
|
|
233
|
+
* The slot holds at most one dialog, so opening a second one used to overwrite the first without
|
|
234
|
+
* settling it — stranding a promise that `beforeToolCall` is awaiting, which wedges the agent
|
|
235
|
+
* loop forever. Keeping the settle function beside the component makes the slot non-clobbering.
|
|
236
|
+
*/
|
|
237
|
+
this.extensionSelectorSettle = undefined;
|
|
238
|
+
/** Label of the surface that decided the open ask elsewhere, pending a one-line notice. */
|
|
239
|
+
this.extensionDialogDecidedBy = undefined;
|
|
233
240
|
this.extensionInput = undefined;
|
|
241
|
+
/** Settles the promise `showExtensionInput` returned. See {@link hideExtensionInput}. */
|
|
242
|
+
this.extensionInputSettle = undefined;
|
|
234
243
|
this.extensionEditor = undefined;
|
|
244
|
+
/** Settles the promise `showExtensionEditor` returned. See {@link hideExtensionEditor}. */
|
|
245
|
+
this.extensionEditorSettle = undefined;
|
|
235
246
|
this.extensionTerminalInputUnsubscribers = new Set();
|
|
236
247
|
// Extension widgets (components rendered above/below the editor)
|
|
237
248
|
this.extensionWidgetsAbove = new Map();
|
|
@@ -258,7 +269,7 @@ export class InteractiveMode {
|
|
|
258
269
|
await this.rebindCurrentSession({ renderBeforeBind: true });
|
|
259
270
|
});
|
|
260
271
|
this.version = VERSION;
|
|
261
|
-
this.ui = new TUI(new ProcessTerminal(), this.settingsManager.getShowHardwareCursor());
|
|
272
|
+
this.ui = new TUI(new ProcessTerminal(), this.settingsManager.getShowHardwareCursor(), getAgentDir());
|
|
262
273
|
this.ui.setClearOnShrink(this.settingsManager.getClearOnShrink());
|
|
263
274
|
this.headerContainer = new Container();
|
|
264
275
|
this.loadedResourcesContainer = new Container();
|
|
@@ -336,11 +347,11 @@ export class InteractiveMode {
|
|
|
336
347
|
}));
|
|
337
348
|
const modelCommand = slashCommands.find((command) => command.name === "model");
|
|
338
349
|
if (modelCommand) {
|
|
339
|
-
modelCommand.getArgumentCompletions = (prefix) => {
|
|
350
|
+
modelCommand.getArgumentCompletions = async (prefix) => {
|
|
340
351
|
// Get available models (scoped or from registry)
|
|
341
352
|
const models = this.session.scopedModels.length > 0
|
|
342
353
|
? this.session.scopedModels.map((s) => s.model)
|
|
343
|
-
: this.session.
|
|
354
|
+
: await this.session.modelRuntime.getAvailable();
|
|
344
355
|
if (models.length === 0)
|
|
345
356
|
return null;
|
|
346
357
|
// Create items with provider/id format
|
|
@@ -508,6 +519,9 @@ export class InteractiveMode {
|
|
|
508
519
|
hint("app.suspend", "to suspend"),
|
|
509
520
|
keyHint("tui.editor.deleteToLineEnd", "to delete to end"),
|
|
510
521
|
hint("app.thinking.cycle", "to cycle thinking level"),
|
|
522
|
+
...(this.keybindings.getKeys("app.context.cycle").length > 0
|
|
523
|
+
? [hint("app.context.cycle", "to cycle context window")]
|
|
524
|
+
: []),
|
|
511
525
|
rawKeyHint(`${keyText("app.model.cycleForward")}/${keyText("app.model.cycleBackward")}`, "to cycle models"),
|
|
512
526
|
hint("app.model.select", "to select model"),
|
|
513
527
|
hint("app.tools.expand", "to expand tools"),
|
|
@@ -518,7 +532,7 @@ export class InteractiveMode {
|
|
|
518
532
|
rawKeyHint("!!", "to run bash (no context)"),
|
|
519
533
|
hint("app.message.followUp", "to queue follow-up"),
|
|
520
534
|
hint("app.message.dequeue", "to edit all queued messages"),
|
|
521
|
-
hint("app.clipboard.pasteImage", "to paste image"),
|
|
535
|
+
hint("app.clipboard.pasteImage", "to paste image (with text fallback)"),
|
|
522
536
|
rawKeyHint("drop files", "to attach"),
|
|
523
537
|
].join("\n");
|
|
524
538
|
const compactInstructions = [
|
|
@@ -578,6 +592,12 @@ export class InteractiveMode {
|
|
|
578
592
|
*/
|
|
579
593
|
async run() {
|
|
580
594
|
await this.init();
|
|
595
|
+
if (!process.env.DRAHT_OFFLINE) {
|
|
596
|
+
void this.session.modelRuntime
|
|
597
|
+
.refresh()
|
|
598
|
+
.then(() => this.updateAvailableProviderCount())
|
|
599
|
+
.catch(() => { });
|
|
600
|
+
}
|
|
581
601
|
// Start version check asynchronously
|
|
582
602
|
checkForNewPiVersion(this.version).then((newRelease) => {
|
|
583
603
|
if (newRelease) {
|
|
@@ -585,10 +605,18 @@ export class InteractiveMode {
|
|
|
585
605
|
}
|
|
586
606
|
});
|
|
587
607
|
// Start package update check asynchronously
|
|
588
|
-
this.checkForPackageUpdates()
|
|
608
|
+
this.checkForPackageUpdates()
|
|
609
|
+
.then((updates) => {
|
|
589
610
|
if (updates.length > 0) {
|
|
590
611
|
this.showPackageUpdateNotification(updates);
|
|
591
612
|
}
|
|
613
|
+
})
|
|
614
|
+
.finally(() => {
|
|
615
|
+
// On Windows, npm can overwrite the shared console title while checking
|
|
616
|
+
// extension package versions. Restore Pi's title after the startup check.
|
|
617
|
+
if (process.platform === "win32" && this.isInitialized) {
|
|
618
|
+
this.updateTerminalTitle();
|
|
619
|
+
}
|
|
592
620
|
});
|
|
593
621
|
// Check tmux keyboard setup asynchronously
|
|
594
622
|
this.checkTmuxKeyboardSetup().then((warning) => {
|
|
@@ -601,7 +629,7 @@ export class InteractiveMode {
|
|
|
601
629
|
if (migratedProviders && migratedProviders.length > 0) {
|
|
602
630
|
this.showWarning(`Migrated credentials to auth.json: ${migratedProviders.join(", ")}`);
|
|
603
631
|
}
|
|
604
|
-
const modelsJsonError = this.session.
|
|
632
|
+
const modelsJsonError = this.session.modelRuntime.getError();
|
|
605
633
|
if (modelsJsonError) {
|
|
606
634
|
this.showError(`models.json error: ${modelsJsonError}`);
|
|
607
635
|
}
|
|
@@ -781,8 +809,15 @@ export class InteractiveMode {
|
|
|
781
809
|
* Get a short path relative to the package root for display.
|
|
782
810
|
*/
|
|
783
811
|
getShortPath(fullPath, sourceInfo) {
|
|
812
|
+
const normalizedFullPath = fullPath.replace(/\\/g, "/");
|
|
784
813
|
const baseDir = sourceInfo?.baseDir;
|
|
785
814
|
if (baseDir && this.isPackageSource(sourceInfo)) {
|
|
815
|
+
const normalizedBaseDir = baseDir.replace(/\\/g, "/");
|
|
816
|
+
const npmRootMatch = normalizedBaseDir.match(/^(.*\/node_modules)\/(@?[^/]+(?:\/[^/]+)?)$/);
|
|
817
|
+
// If fullPath is under the same node_modules root as baseDir, preserve that relative topology.
|
|
818
|
+
if (npmRootMatch?.[1] && normalizedFullPath.startsWith(`${npmRootMatch[1]}/`)) {
|
|
819
|
+
return path.posix.relative(normalizedBaseDir, normalizedFullPath);
|
|
820
|
+
}
|
|
786
821
|
const relativePath = path.relative(path.resolve(baseDir), path.resolve(fullPath));
|
|
787
822
|
if (relativePath &&
|
|
788
823
|
relativePath !== "." &&
|
|
@@ -793,11 +828,11 @@ export class InteractiveMode {
|
|
|
793
828
|
}
|
|
794
829
|
}
|
|
795
830
|
const source = sourceInfo?.source ?? "";
|
|
796
|
-
const npmMatch =
|
|
831
|
+
const npmMatch = normalizedFullPath.match(/node_modules\/(@?[^/]+(?:\/[^/]+)?)\/(.*)/);
|
|
797
832
|
if (npmMatch && source.startsWith("npm:")) {
|
|
798
833
|
return npmMatch[2];
|
|
799
834
|
}
|
|
800
|
-
const gitMatch =
|
|
835
|
+
const gitMatch = normalizedFullPath.match(/git\/[^/]+\/[^/]+\/(.*)/);
|
|
801
836
|
if (gitMatch && source.startsWith("git:")) {
|
|
802
837
|
return gitMatch[1];
|
|
803
838
|
}
|
|
@@ -1053,7 +1088,10 @@ export class InteractiveMode {
|
|
|
1053
1088
|
const promptsResult = this.session.resourceLoader.getPrompts();
|
|
1054
1089
|
const themesResult = this.session.resourceLoader.getThemes();
|
|
1055
1090
|
const extensions = options?.extensions ??
|
|
1056
|
-
this.session.resourceLoader
|
|
1091
|
+
this.session.resourceLoader
|
|
1092
|
+
.getExtensions()
|
|
1093
|
+
.extensions.filter((extension) => !extension.hidden)
|
|
1094
|
+
.map((extension) => ({
|
|
1057
1095
|
path: extension.path,
|
|
1058
1096
|
sourceInfo: extension.sourceInfo,
|
|
1059
1097
|
}));
|
|
@@ -1079,7 +1117,12 @@ export class InteractiveMode {
|
|
|
1079
1117
|
}
|
|
1080
1118
|
}
|
|
1081
1119
|
if (showListing) {
|
|
1082
|
-
const
|
|
1120
|
+
const systemPromptSource = this.session.resourceLoader.getSystemPromptSource();
|
|
1121
|
+
const contextFiles = [
|
|
1122
|
+
...(systemPromptSource ? [systemPromptSource] : []),
|
|
1123
|
+
...this.session.resourceLoader.getAppendSystemPromptSources(),
|
|
1124
|
+
...this.session.resourceLoader.getAgentsFiles().agentsFiles,
|
|
1125
|
+
];
|
|
1083
1126
|
if (contextFiles.length > 0) {
|
|
1084
1127
|
this.loadedResourcesContainer.addChild(new Spacer(1));
|
|
1085
1128
|
const contextList = contextFiles
|
|
@@ -1279,16 +1322,19 @@ export class InteractiveMode {
|
|
|
1279
1322
|
}
|
|
1280
1323
|
}
|
|
1281
1324
|
async rebindCurrentSession(options = {}) {
|
|
1325
|
+
const session = this.session;
|
|
1282
1326
|
this.unsubscribe?.();
|
|
1283
1327
|
this.unsubscribe = undefined;
|
|
1284
1328
|
this.applyRuntimeSettings();
|
|
1285
1329
|
if (options.renderBeforeBind) {
|
|
1286
1330
|
this.renderCurrentSessionState();
|
|
1287
1331
|
this.subscribeToAgent();
|
|
1288
|
-
await this.bindCurrentSessionExtensions();
|
|
1289
1332
|
}
|
|
1290
|
-
|
|
1291
|
-
|
|
1333
|
+
await this.bindCurrentSessionExtensions();
|
|
1334
|
+
if (this.session !== session) {
|
|
1335
|
+
return;
|
|
1336
|
+
}
|
|
1337
|
+
if (!options.renderBeforeBind) {
|
|
1292
1338
|
this.subscribeToAgent();
|
|
1293
1339
|
}
|
|
1294
1340
|
await this.updateAvailableProviderCount();
|
|
@@ -1332,8 +1378,10 @@ export class InteractiveMode {
|
|
|
1332
1378
|
hasUI: true,
|
|
1333
1379
|
cwd: this.sessionManager.getCwd(),
|
|
1334
1380
|
sessionManager: this.sessionManager,
|
|
1335
|
-
modelRegistry:
|
|
1381
|
+
modelRegistry: extensionRunner.getModelRegistry(),
|
|
1336
1382
|
model: this.session.model,
|
|
1383
|
+
scopedModels: this.session.scopedModels,
|
|
1384
|
+
thinkingLevel: this.session.thinkingLevel,
|
|
1337
1385
|
isIdle: () => this.session.isIdle,
|
|
1338
1386
|
isProjectTrusted: () => this.settingsManager.isProjectTrusted(),
|
|
1339
1387
|
signal: this.session.agent.signal,
|
|
@@ -1690,50 +1738,190 @@ export class InteractiveMode {
|
|
|
1690
1738
|
/**
|
|
1691
1739
|
* Show a selector for extensions.
|
|
1692
1740
|
*/
|
|
1693
|
-
showExtensionSelector(title, options, opts) {
|
|
1741
|
+
showExtensionSelector(title, options, opts, detailRows) {
|
|
1694
1742
|
return new Promise((resolve) => {
|
|
1695
1743
|
if (opts?.signal?.aborted) {
|
|
1696
1744
|
resolve(undefined);
|
|
1697
1745
|
return;
|
|
1698
1746
|
}
|
|
1747
|
+
let settled = false;
|
|
1748
|
+
const settle = (value) => {
|
|
1749
|
+
if (settled)
|
|
1750
|
+
return;
|
|
1751
|
+
settled = true;
|
|
1752
|
+
opts?.signal?.removeEventListener("abort", onAbort);
|
|
1753
|
+
if (this.extensionSelectorSettle === settle)
|
|
1754
|
+
this.extensionSelectorSettle = undefined;
|
|
1755
|
+
// A deciding-surface label that nothing flushed belongs to THIS ask and dies with it.
|
|
1756
|
+
// Left standing it is sticky: the next, unrelated dialog's teardown would emit
|
|
1757
|
+
// "Permission resolved by <whoever>" about an ask that surface never saw.
|
|
1758
|
+
this.extensionDialogDecidedBy = undefined;
|
|
1759
|
+
resolve(value);
|
|
1760
|
+
};
|
|
1699
1761
|
const onAbort = () => {
|
|
1700
|
-
|
|
1701
|
-
|
|
1762
|
+
// A dialog that was already displaced by a newer one must not tear the newer one down.
|
|
1763
|
+
if (!settled) {
|
|
1764
|
+
// Flush BEFORE settling: `settle` drops the pending label, and `hideExtensionSelector`
|
|
1765
|
+
// now settles this dialog fail-closed on its way out.
|
|
1766
|
+
this.flushExtensionDialogDecidedNotice();
|
|
1767
|
+
this.hideExtensionSelector();
|
|
1768
|
+
}
|
|
1769
|
+
settle(undefined);
|
|
1702
1770
|
};
|
|
1703
1771
|
opts?.signal?.addEventListener("abort", onAbort, { once: true });
|
|
1704
|
-
|
|
1705
|
-
|
|
1772
|
+
// Non-clobbering slot. Whatever is already in it is disposed and its promise settled as
|
|
1773
|
+
// cancelled BEFORE the replacement takes over; the previous code overwrote the field and
|
|
1774
|
+
// left the earlier caller awaiting a promise nothing could ever resolve.
|
|
1775
|
+
const displaced = this.extensionSelectorSettle;
|
|
1776
|
+
this.extensionSelector?.dispose();
|
|
1777
|
+
this.extensionSelector = undefined;
|
|
1778
|
+
this.extensionSelectorSettle = undefined;
|
|
1779
|
+
this.extensionSelector = new ExtensionSelectorComponent(title, options,
|
|
1780
|
+
// Settle BEFORE hiding: `hideExtensionSelector` settles whatever is still in the slot
|
|
1781
|
+
// fail-closed, so hiding first would resolve the ask as `undefined` (a denial) and the
|
|
1782
|
+
// human's actual choice would be swallowed by the `settled` guard.
|
|
1783
|
+
(option) => {
|
|
1784
|
+
settle(option);
|
|
1706
1785
|
this.hideExtensionSelector();
|
|
1707
|
-
resolve(option);
|
|
1708
1786
|
}, () => {
|
|
1709
|
-
|
|
1787
|
+
settle(undefined);
|
|
1710
1788
|
this.hideExtensionSelector();
|
|
1711
|
-
|
|
1712
|
-
|
|
1789
|
+
}, {
|
|
1790
|
+
tui: this.ui,
|
|
1791
|
+
timeout: opts?.timeout,
|
|
1792
|
+
detailRows,
|
|
1793
|
+
onToggleToolsExpanded: () => this.toggleToolOutputExpansion(),
|
|
1794
|
+
});
|
|
1795
|
+
this.extensionSelectorSettle = settle;
|
|
1713
1796
|
this.editorContainer.clear();
|
|
1714
1797
|
this.editorContainer.addChild(this.extensionSelector);
|
|
1715
1798
|
this.ui.setFocus(this.extensionSelector);
|
|
1716
1799
|
this.ui.requestRender();
|
|
1800
|
+
// Settle the displaced caller only once the replacement is installed, so its continuation
|
|
1801
|
+
// cannot observe an empty dialog slot.
|
|
1802
|
+
displaced?.(undefined);
|
|
1717
1803
|
});
|
|
1718
1804
|
}
|
|
1719
1805
|
/**
|
|
1720
|
-
*
|
|
1806
|
+
* Record that the open ask was decided by another surface (an attached client, the RPC caller).
|
|
1807
|
+
*
|
|
1808
|
+
* This does NOT dismiss the dialog: `opts.signal` already does that, and the relay aborts it
|
|
1809
|
+
* right after calling this. All that is added here is the RENDERING — the operator otherwise
|
|
1810
|
+
* watches a permission dialog vanish with no account of who answered it.
|
|
1811
|
+
*/
|
|
1812
|
+
noteExtensionDialogResolvedElsewhere(label) {
|
|
1813
|
+
this.extensionDialogDecidedBy = label;
|
|
1814
|
+
// Nothing is open to abort, so no teardown will flush the notice — emit it now.
|
|
1815
|
+
if (!this.extensionSelector)
|
|
1816
|
+
this.flushExtensionDialogDecidedNotice();
|
|
1817
|
+
}
|
|
1818
|
+
/** Emit the pending deciding-surface notice at most once, then forget it. */
|
|
1819
|
+
flushExtensionDialogDecidedNotice() {
|
|
1820
|
+
const label = this.extensionDialogDecidedBy;
|
|
1821
|
+
if (label === undefined)
|
|
1822
|
+
return;
|
|
1823
|
+
this.extensionDialogDecidedBy = undefined;
|
|
1824
|
+
this.showExtensionNotify(`Permission resolved by ${label}`, "info");
|
|
1825
|
+
}
|
|
1826
|
+
/**
|
|
1827
|
+
* Hide the extension selector, settling its promise FAIL-CLOSED if nothing else has.
|
|
1828
|
+
*
|
|
1829
|
+
* Every teardown path FOR THE SELECTOR funnels through here — {@link hideExtensionInput} and
|
|
1830
|
+
* {@link hideExtensionEditor} are the matching, separate ones for the other two dialog types, and
|
|
1831
|
+
* they need the same treatment for the same reason. This one used to drop the component on the
|
|
1832
|
+
* floor without touching {@link extensionSelectorSettle} when `resetExtensionUI` (reached from
|
|
1833
|
+
* `setBeforeSessionInvalidate` and from `/reload`) called it. A session invalidate while a permission ask
|
|
1834
|
+
* was open therefore stranded the promise `beforeToolCall` awaits and wedged the agent loop
|
|
1835
|
+
* forever: no dialog on screen, no tool call, no way out.
|
|
1836
|
+
*
|
|
1837
|
+
* `undefined` is the fail-closed answer — `showExtensionConfirm` maps it to `false`, i.e. denial.
|
|
1838
|
+
* Callers that carry a real answer must `settle(...)` it BEFORE calling this.
|
|
1721
1839
|
*/
|
|
1722
1840
|
hideExtensionSelector() {
|
|
1841
|
+
const settle = this.extensionSelectorSettle;
|
|
1842
|
+
this.extensionSelectorSettle = undefined;
|
|
1723
1843
|
this.extensionSelector?.dispose();
|
|
1724
1844
|
this.editorContainer.clear();
|
|
1725
1845
|
this.editorContainer.addChild(this.editor);
|
|
1726
1846
|
this.extensionSelector = undefined;
|
|
1727
1847
|
this.ui.setFocus(this.editor);
|
|
1728
1848
|
this.ui.requestRender();
|
|
1849
|
+
// Last, so the caller's continuation cannot observe a half-torn-down dialog slot.
|
|
1850
|
+
settle?.(undefined);
|
|
1729
1851
|
}
|
|
1730
1852
|
/**
|
|
1731
1853
|
* Show a confirmation dialog for extensions.
|
|
1854
|
+
*
|
|
1855
|
+
* `ui.confirm(title, message, opts)` is a PUBLIC extension surface and the attach relay forwards
|
|
1856
|
+
* the caller's title through unchanged, so `title` is attacker-influenced even when the built-in
|
|
1857
|
+
* permission gate passes a constant. Untreated it carried every defect the detail rows were
|
|
1858
|
+
* hardened against: `ESC[2J` in a title cleared the operator's screen, U+202E survived verbatim,
|
|
1859
|
+
* and `"Approve\nYes\nNo"` rendered four option-looking rows above two real ones.
|
|
1860
|
+
*
|
|
1861
|
+
* TITLE and MESSAGE are bounded DIFFERENTLY, because they are different things:
|
|
1862
|
+
*
|
|
1863
|
+
* - a TITLE is a header, so it stays exactly ONE row on every path and its newlines are
|
|
1864
|
+
* neutralized. That is what stops `"Approve\nYes\nNo"` from drawing option-looking rows above
|
|
1865
|
+
* the real ones, and it costs nothing HERE: no caller of `showExtensionConfirm` writes a
|
|
1866
|
+
* multi-line title. (Two callers elsewhere do — `showStartupSelector` gets the five-line
|
|
1867
|
+
* `formatMissingSessionCwdPrompt` from `main.ts`, and `project-trust.ts` passes
|
|
1868
|
+
* `${title}\n${message}` — but they reach `ExtensionSelectorComponent` directly, where
|
|
1869
|
+
* `TitleRowsComponent` draws one row per line. The reasoning below depends only on the
|
|
1870
|
+
* `showExtensionConfirm` path.)
|
|
1871
|
+
* - a MESSAGE is prose, so it gets a ROW BUDGET and its own newlines are row breaks. Bounding it
|
|
1872
|
+
* to a single row's width instead gutted the `/rewind --fork` consent dialog (215 of its 273
|
|
1873
|
+
* characters elided at 80 columns) and collapsed the deliberately 5-line
|
|
1874
|
+
* `formatMissingSessionCwdPrompt` into one. See {@link boundDialogText}.
|
|
1732
1875
|
*/
|
|
1733
1876
|
async showExtensionConfirm(title, message, opts) {
|
|
1734
|
-
|
|
1877
|
+
// Grapheme budget for one row of dialog text: the terminal width less the row's `paddingX: 1`
|
|
1878
|
+
// on each side. The floor keeps a very narrow terminal from producing a useless budget.
|
|
1879
|
+
const columns = this.ui?.terminal?.columns ?? 80;
|
|
1880
|
+
const safeTitle = boundedSafeText(title, Math.max(16, columns - 2)).value;
|
|
1881
|
+
const detail = opts?.detail;
|
|
1882
|
+
if (detail !== undefined) {
|
|
1883
|
+
// A permission ask arrives with typed fields, so it is rendered as typed rows. Flattening
|
|
1884
|
+
// it back into `${title}\n${message}` would hand the attacker-influenced command a way to
|
|
1885
|
+
// forge rows, and the human would be deciding about a string rather than about a call.
|
|
1886
|
+
const rows = this.buildPermissionDetailRows(detail);
|
|
1887
|
+
const result = await this.showExtensionSelector(safeTitle, ["Yes", "No"], opts, rows);
|
|
1888
|
+
return result === "Yes";
|
|
1889
|
+
}
|
|
1890
|
+
// Two rows of the header budget are already spoken for: the single-row title above, and the
|
|
1891
|
+
// spacer `ExtensionSelectorComponent` draws between the header and the option list when there
|
|
1892
|
+
// are no detail rows. Both sit above `Yes`, so both have to come out of the same budget.
|
|
1893
|
+
const safeMessage = boundDialogText(message, columns, MAX_DETAIL_ROWS - 2);
|
|
1894
|
+
const result = await this.showExtensionSelector(`${safeTitle}\n${safeMessage}`, ["Yes", "No"], opts);
|
|
1735
1895
|
return result === "Yes";
|
|
1736
1896
|
}
|
|
1897
|
+
/**
|
|
1898
|
+
* Turn a {@link PermissionAskDetail} into one bounded, neutralized row per fact.
|
|
1899
|
+
*
|
|
1900
|
+
* The protocol layer neutralizes what arrives from a remote surface, but a LOCALLY raised ask
|
|
1901
|
+
* never crosses the wire — so the rule is applied here too. Note the ORDER: neutralize, then
|
|
1902
|
+
* measure. `visibleWidth` strips ANSI for measurement only and reports zero width for bidi
|
|
1903
|
+
* controls and DEL, so any width budget computed over raw text is a fiction.
|
|
1904
|
+
*/
|
|
1905
|
+
buildPermissionDetailRows(detail) {
|
|
1906
|
+
const labels = [
|
|
1907
|
+
["Tool", detail.toolName],
|
|
1908
|
+
["Directory", detail.cwd],
|
|
1909
|
+
["Command", detail.command],
|
|
1910
|
+
["Path", detail.path],
|
|
1911
|
+
["Operation", detail.operation],
|
|
1912
|
+
["Reason", detail.reason],
|
|
1913
|
+
];
|
|
1914
|
+
const present = labels.filter((entry) => {
|
|
1915
|
+
const value = entry[1];
|
|
1916
|
+
return value !== undefined && value.length > 0;
|
|
1917
|
+
});
|
|
1918
|
+
const labelWidth = present.reduce((max, [label]) => Math.max(max, label.length), 0);
|
|
1919
|
+
// Terminal width minus the row margins, the label column and its ": " separator. The floor
|
|
1920
|
+
// keeps a narrow terminal from producing a zero or negative budget.
|
|
1921
|
+
const columns = this.ui?.terminal?.columns ?? 80;
|
|
1922
|
+
const budget = Math.max(16, columns - 2 - labelWidth - 2);
|
|
1923
|
+
return present.map(([label, value]) => `${label.padEnd(labelWidth)}: ${boundedSafeText(value, budget).value}`);
|
|
1924
|
+
}
|
|
1737
1925
|
async promptForMissingSessionCwd(error) {
|
|
1738
1926
|
const confirmed = await this.showExtensionConfirm("Session cwd not found", formatMissingSessionCwdPrompt(error.issue));
|
|
1739
1927
|
return confirmed ? error.issue.fallbackCwd : undefined;
|
|
@@ -1747,64 +1935,125 @@ export class InteractiveMode {
|
|
|
1747
1935
|
resolve(undefined);
|
|
1748
1936
|
return;
|
|
1749
1937
|
}
|
|
1938
|
+
let settled = false;
|
|
1939
|
+
const settle = (value) => {
|
|
1940
|
+
if (settled)
|
|
1941
|
+
return;
|
|
1942
|
+
settled = true;
|
|
1943
|
+
opts?.signal?.removeEventListener("abort", onAbort);
|
|
1944
|
+
if (this.extensionInputSettle === settle)
|
|
1945
|
+
this.extensionInputSettle = undefined;
|
|
1946
|
+
resolve(value);
|
|
1947
|
+
};
|
|
1750
1948
|
const onAbort = () => {
|
|
1751
|
-
|
|
1752
|
-
|
|
1949
|
+
// A dialog already displaced by a newer one must not tear the newer one down.
|
|
1950
|
+
if (!settled)
|
|
1951
|
+
this.hideExtensionInput();
|
|
1952
|
+
settle(undefined);
|
|
1753
1953
|
};
|
|
1754
1954
|
opts?.signal?.addEventListener("abort", onAbort, { once: true });
|
|
1755
|
-
|
|
1756
|
-
|
|
1955
|
+
const displaced = this.extensionInputSettle;
|
|
1956
|
+
this.extensionInput?.dispose();
|
|
1957
|
+
this.extensionInput = undefined;
|
|
1958
|
+
this.extensionInputSettle = undefined;
|
|
1959
|
+
this.extensionInput = new ExtensionInputComponent(title, placeholder,
|
|
1960
|
+
// Settle BEFORE hiding, for the same reason the selector does: `hideExtensionInput`
|
|
1961
|
+
// settles whatever is still in the slot fail-closed, so hiding first would resolve the
|
|
1962
|
+
// ask as `undefined` and the human's actual answer would hit the `settled` guard.
|
|
1963
|
+
(value) => {
|
|
1964
|
+
settle(value);
|
|
1757
1965
|
this.hideExtensionInput();
|
|
1758
|
-
resolve(value);
|
|
1759
1966
|
}, () => {
|
|
1760
|
-
|
|
1967
|
+
settle(undefined);
|
|
1761
1968
|
this.hideExtensionInput();
|
|
1762
|
-
resolve(undefined);
|
|
1763
1969
|
}, { tui: this.ui, timeout: opts?.timeout });
|
|
1970
|
+
this.extensionInputSettle = settle;
|
|
1764
1971
|
this.editorContainer.clear();
|
|
1765
1972
|
this.editorContainer.addChild(this.extensionInput);
|
|
1766
1973
|
this.ui.setFocus(this.extensionInput);
|
|
1767
1974
|
this.ui.requestRender();
|
|
1975
|
+
// Only once the replacement is installed, so the displaced caller's continuation cannot
|
|
1976
|
+
// observe an empty dialog slot.
|
|
1977
|
+
displaced?.(undefined);
|
|
1768
1978
|
});
|
|
1769
1979
|
}
|
|
1770
1980
|
/**
|
|
1771
|
-
* Hide the extension input.
|
|
1981
|
+
* Hide the extension input, settling its promise FAIL-CLOSED if nothing else has.
|
|
1982
|
+
*
|
|
1983
|
+
* Same defect the selector had: this used to dispose and re-focus without touching the `resolve`
|
|
1984
|
+
* captured in {@link showExtensionInput}'s closure, so `resetExtensionUI` — a session invalidate
|
|
1985
|
+
* or `/reload` — left the extension awaiting `ui.input(...)` hanging forever.
|
|
1986
|
+
*
|
|
1987
|
+
* Callers that carry a real answer must `settle(...)` it BEFORE calling this.
|
|
1772
1988
|
*/
|
|
1773
1989
|
hideExtensionInput() {
|
|
1990
|
+
const settle = this.extensionInputSettle;
|
|
1991
|
+
this.extensionInputSettle = undefined;
|
|
1774
1992
|
this.extensionInput?.dispose();
|
|
1775
1993
|
this.editorContainer.clear();
|
|
1776
1994
|
this.editorContainer.addChild(this.editor);
|
|
1777
1995
|
this.extensionInput = undefined;
|
|
1778
1996
|
this.ui.setFocus(this.editor);
|
|
1779
1997
|
this.ui.requestRender();
|
|
1998
|
+
// Last, so the caller's continuation cannot observe a half-torn-down dialog slot.
|
|
1999
|
+
settle?.(undefined);
|
|
1780
2000
|
}
|
|
1781
2001
|
/**
|
|
1782
2002
|
* Show a multi-line editor for extensions (with Ctrl+G support).
|
|
1783
2003
|
*/
|
|
1784
2004
|
showExtensionEditor(title, prefill) {
|
|
1785
2005
|
return new Promise((resolve) => {
|
|
1786
|
-
|
|
1787
|
-
|
|
2006
|
+
let settled = false;
|
|
2007
|
+
const settle = (value) => {
|
|
2008
|
+
if (settled)
|
|
2009
|
+
return;
|
|
2010
|
+
settled = true;
|
|
2011
|
+
if (this.extensionEditorSettle === settle)
|
|
2012
|
+
this.extensionEditorSettle = undefined;
|
|
1788
2013
|
resolve(value);
|
|
2014
|
+
};
|
|
2015
|
+
const displaced = this.extensionEditorSettle;
|
|
2016
|
+
this.extensionEditor = undefined;
|
|
2017
|
+
this.extensionEditorSettle = undefined;
|
|
2018
|
+
this.extensionEditor = new ExtensionEditorComponent(this.ui, this.keybindings, title, prefill,
|
|
2019
|
+
// Settle BEFORE hiding: `hideExtensionEditor` settles the slot fail-closed.
|
|
2020
|
+
(value) => {
|
|
2021
|
+
settle(value);
|
|
2022
|
+
this.hideExtensionEditor();
|
|
1789
2023
|
}, () => {
|
|
2024
|
+
settle(undefined);
|
|
1790
2025
|
this.hideExtensionEditor();
|
|
1791
|
-
resolve(undefined);
|
|
1792
2026
|
}, undefined, this.settingsManager.getExternalEditorCommand());
|
|
2027
|
+
this.extensionEditorSettle = settle;
|
|
1793
2028
|
this.editorContainer.clear();
|
|
1794
2029
|
this.editorContainer.addChild(this.extensionEditor);
|
|
1795
2030
|
this.ui.setFocus(this.extensionEditor);
|
|
1796
2031
|
this.ui.requestRender();
|
|
2032
|
+
// Only once the replacement is installed, so the displaced caller's continuation cannot
|
|
2033
|
+
// observe an empty dialog slot.
|
|
2034
|
+
displaced?.(undefined);
|
|
1797
2035
|
});
|
|
1798
2036
|
}
|
|
1799
2037
|
/**
|
|
1800
|
-
* Hide the extension editor.
|
|
2038
|
+
* Hide the extension editor, settling its promise FAIL-CLOSED if nothing else has.
|
|
2039
|
+
*
|
|
2040
|
+
* Same defect the selector had: this used to clear the container and re-focus without touching
|
|
2041
|
+
* the `resolve` captured in {@link showExtensionEditor}'s closure, so `resetExtensionUI` — a
|
|
2042
|
+
* session invalidate or `/reload` — stranded whoever was awaiting the editor forever. `/compact`
|
|
2043
|
+
* with custom instructions is one such caller.
|
|
2044
|
+
*
|
|
2045
|
+
* Callers that carry a real answer must `settle(...)` it BEFORE calling this.
|
|
1801
2046
|
*/
|
|
1802
2047
|
hideExtensionEditor() {
|
|
2048
|
+
const settle = this.extensionEditorSettle;
|
|
2049
|
+
this.extensionEditorSettle = undefined;
|
|
1803
2050
|
this.editorContainer.clear();
|
|
1804
2051
|
this.editorContainer.addChild(this.editor);
|
|
1805
2052
|
this.extensionEditor = undefined;
|
|
1806
2053
|
this.ui.setFocus(this.editor);
|
|
1807
2054
|
this.ui.requestRender();
|
|
2055
|
+
// Last, so the caller's continuation cannot observe a half-torn-down dialog slot.
|
|
2056
|
+
settle?.(undefined);
|
|
1808
2057
|
}
|
|
1809
2058
|
/**
|
|
1810
2059
|
* Set a custom editor component from an extension.
|
|
@@ -1830,6 +2079,9 @@ export class InteractiveMode {
|
|
|
1830
2079
|
if (newEditor.setPaddingX !== undefined) {
|
|
1831
2080
|
newEditor.setPaddingX(this.defaultEditor.getPaddingX());
|
|
1832
2081
|
}
|
|
2082
|
+
if (newEditor.setAutocompleteMaxVisible !== undefined) {
|
|
2083
|
+
newEditor.setAutocompleteMaxVisible(this.defaultEditor.getAutocompleteMaxVisible());
|
|
2084
|
+
}
|
|
1833
2085
|
// Set autocomplete if supported
|
|
1834
2086
|
if (newEditor.setAutocompleteProvider && this.autocompleteProvider) {
|
|
1835
2087
|
newEditor.setAutocompleteProvider(this.autocompleteProvider);
|
|
@@ -2012,6 +2264,7 @@ export class InteractiveMode {
|
|
|
2012
2264
|
this.defaultEditor.onCtrlD = () => this.handleCtrlD();
|
|
2013
2265
|
this.defaultEditor.onAction("app.suspend", () => this.handleCtrlZ());
|
|
2014
2266
|
this.defaultEditor.onAction("app.thinking.cycle", () => this.cycleThinkingLevel());
|
|
2267
|
+
this.defaultEditor.onAction("app.context.cycle", () => void this.cycleContextWindow());
|
|
2015
2268
|
this.defaultEditor.onAction("app.model.cycleForward", () => this.cycleModel("forward"));
|
|
2016
2269
|
this.defaultEditor.onAction("app.model.cycleBackward", () => this.cycleModel("backward"));
|
|
2017
2270
|
// Global debug handler on TUI (works regardless of focus)
|
|
@@ -2019,11 +2272,13 @@ export class InteractiveMode {
|
|
|
2019
2272
|
this.defaultEditor.onAction("app.model.select", () => this.showModelSelector());
|
|
2020
2273
|
this.defaultEditor.onAction("app.tools.expand", () => this.toggleToolOutputExpansion());
|
|
2021
2274
|
this.defaultEditor.onAction("app.thinking.toggle", () => this.toggleThinkingBlockVisibility());
|
|
2022
|
-
this.defaultEditor.onAction("app.editor.external", () => this.
|
|
2275
|
+
this.defaultEditor.onAction("app.editor.external", () => void this.handleOpenExternalEditor());
|
|
2276
|
+
this.defaultEditor.onAction("app.message.copy", () => void this.handleCopyCommand());
|
|
2023
2277
|
this.defaultEditor.onAction("app.message.followUp", () => this.handleFollowUp());
|
|
2024
2278
|
this.defaultEditor.onAction("app.message.dequeue", () => this.handleDequeue());
|
|
2025
2279
|
this.defaultEditor.onAction("app.session.new", () => this.handleClearCommand());
|
|
2026
2280
|
this.defaultEditor.onAction("app.session.tree", () => this.showTreeSelector());
|
|
2281
|
+
this.defaultEditor.onAction("app.session.rewind", () => this.showRewindSelector());
|
|
2027
2282
|
this.defaultEditor.onAction("app.session.fork", () => this.showUserMessageSelector());
|
|
2028
2283
|
this.defaultEditor.onAction("app.session.resume", () => this.showSessionSelector());
|
|
2029
2284
|
this.defaultEditor.onChange = (text) => {
|
|
@@ -2033,26 +2288,30 @@ export class InteractiveMode {
|
|
|
2033
2288
|
this.updateEditorBorderColor();
|
|
2034
2289
|
}
|
|
2035
2290
|
};
|
|
2036
|
-
// Handle clipboard
|
|
2291
|
+
// Handle clipboard paste (triggered on Ctrl+V). Images are attached by path;
|
|
2292
|
+
// otherwise, paste plain text from the system clipboard.
|
|
2037
2293
|
this.defaultEditor.onPasteImage = () => {
|
|
2038
|
-
this.
|
|
2294
|
+
void this.handleClipboardPaste();
|
|
2039
2295
|
};
|
|
2040
2296
|
}
|
|
2041
|
-
async
|
|
2297
|
+
async handleClipboardPaste() {
|
|
2042
2298
|
try {
|
|
2043
2299
|
const image = await readClipboardImage();
|
|
2044
|
-
if (
|
|
2300
|
+
if (image) {
|
|
2301
|
+
const tmpDir = os.tmpdir();
|
|
2302
|
+
const ext = extensionForImageMimeType(image.mimeType) ?? "png";
|
|
2303
|
+
const fileName = `pi-clipboard-${crypto.randomUUID()}.${ext}`;
|
|
2304
|
+
const filePath = path.join(tmpDir, fileName);
|
|
2305
|
+
fs.writeFileSync(filePath, Buffer.from(image.bytes));
|
|
2306
|
+
this.editor.insertTextAtCursor?.(filePath);
|
|
2307
|
+
this.ui.requestRender();
|
|
2045
2308
|
return;
|
|
2046
2309
|
}
|
|
2047
|
-
|
|
2048
|
-
|
|
2049
|
-
|
|
2050
|
-
|
|
2051
|
-
|
|
2052
|
-
fs.writeFileSync(filePath, Buffer.from(image.bytes));
|
|
2053
|
-
// Insert file path directly
|
|
2054
|
-
this.editor.insertTextAtCursor?.(filePath);
|
|
2055
|
-
this.ui.requestRender();
|
|
2310
|
+
const text = await readClipboardText();
|
|
2311
|
+
if (text) {
|
|
2312
|
+
this.editor.insertTextAtCursor?.(text);
|
|
2313
|
+
this.ui.requestRender();
|
|
2314
|
+
}
|
|
2056
2315
|
}
|
|
2057
2316
|
catch {
|
|
2058
2317
|
// Silently ignore clipboard errors (may not have permission, etc.)
|
|
@@ -2063,6 +2322,14 @@ export class InteractiveMode {
|
|
|
2063
2322
|
text = text.trim();
|
|
2064
2323
|
if (!text)
|
|
2065
2324
|
return;
|
|
2325
|
+
// A `/rewind` is rewriting the working tree right now. Anything
|
|
2326
|
+
// submitted here would run against a tree that is mid-restore, so
|
|
2327
|
+
// hold the text in the editor the way the bash guard below does.
|
|
2328
|
+
if (this.isRewindRunning) {
|
|
2329
|
+
this.showWarning("A rewind is restoring your files. Wait for it to finish.");
|
|
2330
|
+
this.editor.setText(text);
|
|
2331
|
+
return;
|
|
2332
|
+
}
|
|
2066
2333
|
// Handle commands
|
|
2067
2334
|
if (text === "/settings") {
|
|
2068
2335
|
this.showSettingsSelector();
|
|
@@ -2135,6 +2402,11 @@ export class InteractiveMode {
|
|
|
2135
2402
|
this.editor.setText("");
|
|
2136
2403
|
return;
|
|
2137
2404
|
}
|
|
2405
|
+
if (text === "/rewind") {
|
|
2406
|
+
this.showRewindSelector();
|
|
2407
|
+
this.editor.setText("");
|
|
2408
|
+
return;
|
|
2409
|
+
}
|
|
2138
2410
|
if (text === "/trust") {
|
|
2139
2411
|
this.showTrustSelector();
|
|
2140
2412
|
this.editor.setText("");
|
|
@@ -2292,6 +2564,10 @@ export class InteractiveMode {
|
|
|
2292
2564
|
this.footer.invalidate();
|
|
2293
2565
|
this.updateEditorBorderColor();
|
|
2294
2566
|
break;
|
|
2567
|
+
case "context_window_changed":
|
|
2568
|
+
this.footer.invalidate();
|
|
2569
|
+
this.ui.requestRender();
|
|
2570
|
+
break;
|
|
2295
2571
|
case "message_start":
|
|
2296
2572
|
if (event.message.role === "custom") {
|
|
2297
2573
|
this.addMessageToChat(event.message);
|
|
@@ -2376,6 +2652,9 @@ export class InteractiveMode {
|
|
|
2376
2652
|
}
|
|
2377
2653
|
this.ui.requestRender();
|
|
2378
2654
|
break;
|
|
2655
|
+
case "bash_execution_update":
|
|
2656
|
+
// The bash execution callback handles TUI output rendering.
|
|
2657
|
+
break;
|
|
2379
2658
|
case "tool_execution_start": {
|
|
2380
2659
|
let component = this.pendingTools.get(event.toolCallId);
|
|
2381
2660
|
if (!component) {
|
|
@@ -2498,6 +2777,28 @@ export class InteractiveMode {
|
|
|
2498
2777
|
this.ui.requestRender();
|
|
2499
2778
|
break;
|
|
2500
2779
|
}
|
|
2780
|
+
case "summarization_retry_scheduled": {
|
|
2781
|
+
this.showError(event.errorMessage);
|
|
2782
|
+
this.showStatusIndicator(new RetryStatusIndicator(this.ui, event.attempt, event.maxAttempts, event.delayMs));
|
|
2783
|
+
this.ui.requestRender();
|
|
2784
|
+
break;
|
|
2785
|
+
}
|
|
2786
|
+
case "summarization_retry_attempt_start": {
|
|
2787
|
+
this.clearStatusIndicator("retry");
|
|
2788
|
+
if (event.source === "branchSummary") {
|
|
2789
|
+
this.showStatusIndicator(new BranchSummaryStatusIndicator(this.ui));
|
|
2790
|
+
}
|
|
2791
|
+
else {
|
|
2792
|
+
this.showStatusIndicator(new CompactionStatusIndicator(this.ui, event.reason));
|
|
2793
|
+
}
|
|
2794
|
+
this.ui.requestRender();
|
|
2795
|
+
break;
|
|
2796
|
+
}
|
|
2797
|
+
case "summarization_retry_finished": {
|
|
2798
|
+
this.clearStatusIndicator("retry");
|
|
2799
|
+
this.ui.requestRender();
|
|
2800
|
+
break;
|
|
2801
|
+
}
|
|
2501
2802
|
}
|
|
2502
2803
|
}
|
|
2503
2804
|
/** Extract text content from a user message */
|
|
@@ -2565,7 +2866,7 @@ export class InteractiveMode {
|
|
|
2565
2866
|
case "custom": {
|
|
2566
2867
|
if (message.display) {
|
|
2567
2868
|
const renderer = this.session.extensionRunner.getMessageRenderer(message.customType);
|
|
2568
|
-
const component = new CustomMessageComponent(message, renderer, this.getMarkdownThemeWithSettings());
|
|
2869
|
+
const component = new CustomMessageComponent(message, renderer, this.getMarkdownThemeWithSettings(), this.outputPad);
|
|
2569
2870
|
component.setExpanded(this.toolOutputExpanded);
|
|
2570
2871
|
this.chatContainer.addChild(component);
|
|
2571
2872
|
}
|
|
@@ -2634,7 +2935,7 @@ export class InteractiveMode {
|
|
|
2634
2935
|
// Cache-miss notices are not persisted; re-derive them from the full entry
|
|
2635
2936
|
// list and re-inject them after the assistant messages that paid for them.
|
|
2636
2937
|
const cacheMisses = this.settingsManager.getShowCacheMissNotices()
|
|
2637
|
-
? collectCacheMisses(this.sessionManager.getEntries(), this.session.
|
|
2938
|
+
? collectCacheMisses(this.sessionManager.getEntries(), this.session.modelRuntime)
|
|
2638
2939
|
: new Map();
|
|
2639
2940
|
if (options.updateFooter) {
|
|
2640
2941
|
this.footer.invalidate();
|
|
@@ -2725,7 +3026,7 @@ export class InteractiveMode {
|
|
|
2725
3026
|
if (!this.settingsManager.getShowCacheMissNotices())
|
|
2726
3027
|
return;
|
|
2727
3028
|
// Entries don't contain `message` yet: message_end fires before persistence.
|
|
2728
|
-
const miss = detectCacheMiss(this.sessionManager.getEntries(), message, this.session.
|
|
3029
|
+
const miss = detectCacheMiss(this.sessionManager.getEntries(), message, this.session.modelRuntime);
|
|
2729
3030
|
if (miss)
|
|
2730
3031
|
this.addCacheMissNotice(miss);
|
|
2731
3032
|
}
|
|
@@ -3020,6 +3321,56 @@ export class InteractiveMode {
|
|
|
3020
3321
|
this.showStatus(`Thinking level: ${newLevel}`);
|
|
3021
3322
|
}
|
|
3022
3323
|
}
|
|
3324
|
+
async cycleContextWindow() {
|
|
3325
|
+
const model = this.session.model;
|
|
3326
|
+
const nextContextWindow = this.session.getNextContextWindow();
|
|
3327
|
+
if (!model || nextContextWindow === undefined) {
|
|
3328
|
+
this.showStatus("Current model has only one context window");
|
|
3329
|
+
return;
|
|
3330
|
+
}
|
|
3331
|
+
if (this.session.isStreaming || this.session.isCompacting) {
|
|
3332
|
+
this.showWarning("Wait for the current response or compaction to finish before changing the context window.");
|
|
3333
|
+
return;
|
|
3334
|
+
}
|
|
3335
|
+
const reserveTokens = this.settingsManager.getCompactionSettings().reserveTokens;
|
|
3336
|
+
const usableContextWindow = nextContextWindow - reserveTokens;
|
|
3337
|
+
const contextUsage = this.session.getContextUsage();
|
|
3338
|
+
if (nextContextWindow < model.contextWindow &&
|
|
3339
|
+
contextUsage?.tokens !== null &&
|
|
3340
|
+
contextUsage?.tokens !== undefined &&
|
|
3341
|
+
contextUsage.tokens > usableContextWindow) {
|
|
3342
|
+
const confirmed = await this.showExtensionConfirm("Compact context?", `The current context (${formatContextWindow(contextUsage.tokens)}) does not fit the ${formatContextWindow(nextContextWindow)} window with ${formatContextWindow(reserveTokens)} reserved for the response. Compact before switching?`);
|
|
3343
|
+
if (!confirmed) {
|
|
3344
|
+
this.showStatus("Context window unchanged");
|
|
3345
|
+
return;
|
|
3346
|
+
}
|
|
3347
|
+
try {
|
|
3348
|
+
const result = await this.session.compact();
|
|
3349
|
+
if (result.estimatedTokensAfter !== undefined && result.estimatedTokensAfter > usableContextWindow) {
|
|
3350
|
+
this.showWarning(`Compacted context is still too large for the ${formatContextWindow(nextContextWindow)} window.`);
|
|
3351
|
+
return;
|
|
3352
|
+
}
|
|
3353
|
+
}
|
|
3354
|
+
catch {
|
|
3355
|
+
return;
|
|
3356
|
+
}
|
|
3357
|
+
}
|
|
3358
|
+
try {
|
|
3359
|
+
const previousContextWindow = model.contextWindow;
|
|
3360
|
+
this.session.setContextWindow(nextContextWindow);
|
|
3361
|
+
const pricingThreshold = model.cost.tiers
|
|
3362
|
+
?.map((tier) => tier.inputTokensAbove)
|
|
3363
|
+
.filter((threshold) => threshold >= previousContextWindow && threshold < nextContextWindow)
|
|
3364
|
+
.sort((a, b) => a - b)[0];
|
|
3365
|
+
const pricingNotice = pricingThreshold === undefined
|
|
3366
|
+
? ""
|
|
3367
|
+
: `; higher pricing above ${formatContextWindow(pricingThreshold)} input`;
|
|
3368
|
+
this.showStatus(`Context window: ${formatContextWindow(nextContextWindow)}${pricingNotice}`);
|
|
3369
|
+
}
|
|
3370
|
+
catch (error) {
|
|
3371
|
+
this.showError(error instanceof Error ? error.message : String(error));
|
|
3372
|
+
}
|
|
3373
|
+
}
|
|
3023
3374
|
async cycleModel(direction) {
|
|
3024
3375
|
try {
|
|
3025
3376
|
const result = await this.session.cycleModel(direction);
|
|
@@ -3055,7 +3406,7 @@ export class InteractiveMode {
|
|
|
3055
3406
|
}
|
|
3056
3407
|
}
|
|
3057
3408
|
}
|
|
3058
|
-
this.
|
|
3409
|
+
this.showStatus(`Tool output: ${expanded ? "expanded" : "collapsed"}`);
|
|
3059
3410
|
}
|
|
3060
3411
|
toggleThinkingBlockVisibility() {
|
|
3061
3412
|
this.hideThinkingBlock = !this.hideThinkingBlock;
|
|
@@ -3071,51 +3422,21 @@ export class InteractiveMode {
|
|
|
3071
3422
|
}
|
|
3072
3423
|
this.showStatus(`Thinking blocks: ${this.hideThinkingBlock ? "hidden" : "visible"}`);
|
|
3073
3424
|
}
|
|
3074
|
-
async
|
|
3425
|
+
async handleOpenExternalEditor() {
|
|
3075
3426
|
const editorCmd = this.settingsManager.getExternalEditorCommand();
|
|
3076
|
-
|
|
3077
|
-
|
|
3078
|
-
return;
|
|
3079
|
-
}
|
|
3080
|
-
const currentText = this.editor.getExpandedText?.() ?? this.editor.getText();
|
|
3081
|
-
const tmpFile = path.join(os.tmpdir(), `pi-editor-${Date.now()}.pi.md`);
|
|
3427
|
+
const content = this.editor.getExpandedText?.() ?? this.editor.getText();
|
|
3428
|
+
this.ui.stop();
|
|
3082
3429
|
try {
|
|
3083
|
-
|
|
3084
|
-
|
|
3085
|
-
|
|
3086
|
-
this.ui.stop();
|
|
3087
|
-
// Split by space to support editor arguments (e.g., "code --wait")
|
|
3088
|
-
const [editor, ...editorArgs] = editorCmd.split(" ");
|
|
3089
|
-
process.stdout.write(`Launching external editor: ${editorCmd}\nPi will resume when the editor exits.\n`);
|
|
3090
|
-
// Do not use spawnSync here. On Windows, synchronous child_process calls can keep
|
|
3091
|
-
// Node/libuv's console input read active after ui.stop() pauses stdin, racing
|
|
3092
|
-
// vim/nvim for the console input buffer until Ctrl+C cancels the pending read.
|
|
3093
|
-
const status = await new Promise((resolve) => {
|
|
3094
|
-
const child = spawn(editor, [...editorArgs, tmpFile], {
|
|
3095
|
-
stdio: "inherit",
|
|
3096
|
-
shell: process.platform === "win32",
|
|
3097
|
-
});
|
|
3098
|
-
child.on("error", () => resolve(null));
|
|
3099
|
-
child.on("close", (code) => resolve(code));
|
|
3430
|
+
const result = await editInExternalEditor({
|
|
3431
|
+
command: editorCmd,
|
|
3432
|
+
content,
|
|
3100
3433
|
});
|
|
3101
|
-
|
|
3102
|
-
|
|
3103
|
-
const newContent = fs.readFileSync(tmpFile, "utf-8").replace(/\n$/, "");
|
|
3104
|
-
this.editor.setText(newContent);
|
|
3434
|
+
if (result.status === "complete") {
|
|
3435
|
+
this.editor.setText(result.content);
|
|
3105
3436
|
}
|
|
3106
|
-
// On non-zero exit, keep original text (no action needed)
|
|
3107
3437
|
}
|
|
3108
3438
|
finally {
|
|
3109
|
-
// Clean up temp file
|
|
3110
|
-
try {
|
|
3111
|
-
fs.unlinkSync(tmpFile);
|
|
3112
|
-
}
|
|
3113
|
-
catch {
|
|
3114
|
-
// Ignore cleanup errors
|
|
3115
|
-
}
|
|
3116
|
-
// Restart TUI
|
|
3117
3439
|
this.ui.start();
|
|
3118
|
-
// Force full re-render since external editor uses alternate screen
|
|
3119
3440
|
this.ui.requestRender(true);
|
|
3120
3441
|
}
|
|
3121
3442
|
}
|
|
@@ -3302,8 +3623,10 @@ export class InteractiveMode {
|
|
|
3302
3623
|
for (const message of preCommands) {
|
|
3303
3624
|
await this.session.prompt(message.text);
|
|
3304
3625
|
}
|
|
3305
|
-
//
|
|
3306
|
-
const promptPromise = this.session
|
|
3626
|
+
// Start a prompt when idle, or queue it into a run still finishing compaction.
|
|
3627
|
+
const promptPromise = this.session
|
|
3628
|
+
.prompt(firstPrompt.text, { streamingBehavior: firstPrompt.mode })
|
|
3629
|
+
.catch((error) => {
|
|
3307
3630
|
restoreQueue(error);
|
|
3308
3631
|
});
|
|
3309
3632
|
// Queue remaining messages
|
|
@@ -3382,6 +3705,7 @@ export class InteractiveMode {
|
|
|
3382
3705
|
outputPad: this.settingsManager.getOutputPad(),
|
|
3383
3706
|
autocompleteMaxVisible: this.settingsManager.getAutocompleteMaxVisible(),
|
|
3384
3707
|
quietStartup: this.settingsManager.getQuietStartup(),
|
|
3708
|
+
attachableSessions: this.settingsManager.getAttachableSessions(),
|
|
3385
3709
|
clearOnShrink: this.settingsManager.getClearOnShrink(),
|
|
3386
3710
|
showTerminalProgress: this.settingsManager.getShowTerminalProgress(),
|
|
3387
3711
|
warnings: this.settingsManager.getWarnings(),
|
|
@@ -3465,6 +3789,10 @@ export class InteractiveMode {
|
|
|
3465
3789
|
onQuietStartupChange: (enabled) => {
|
|
3466
3790
|
this.settingsManager.setQuietStartup(enabled);
|
|
3467
3791
|
},
|
|
3792
|
+
onAttachableSessionsChange: (enabled) => {
|
|
3793
|
+
// Takes effect on the next session start: this one already bound (or did not).
|
|
3794
|
+
this.settingsManager.setAttachableSessions(enabled);
|
|
3795
|
+
},
|
|
3468
3796
|
onDefaultProjectTrustChange: (defaultProjectTrust) => {
|
|
3469
3797
|
this.settingsManager.setDefaultProjectTrust(defaultProjectTrust);
|
|
3470
3798
|
},
|
|
@@ -3490,7 +3818,9 @@ export class InteractiveMode {
|
|
|
3490
3818
|
this.outputPad = padding;
|
|
3491
3819
|
if (this.streamingComponent || this.session.isStreaming) {
|
|
3492
3820
|
for (const child of this.chatContainer.children) {
|
|
3493
|
-
if (child instanceof AssistantMessageComponent ||
|
|
3821
|
+
if (child instanceof AssistantMessageComponent ||
|
|
3822
|
+
child instanceof CustomMessageComponent ||
|
|
3823
|
+
child instanceof UserMessageComponent) {
|
|
3494
3824
|
child.setOutputPad(padding);
|
|
3495
3825
|
}
|
|
3496
3826
|
}
|
|
@@ -3560,18 +3890,20 @@ export class InteractiveMode {
|
|
|
3560
3890
|
if (this.session.scopedModels.length > 0) {
|
|
3561
3891
|
return this.session.scopedModels.map((scoped) => scoped.model);
|
|
3562
3892
|
}
|
|
3563
|
-
this.session.modelRegistry.refresh();
|
|
3564
3893
|
try {
|
|
3565
|
-
|
|
3894
|
+
await this.session.modelRuntime.refresh();
|
|
3895
|
+
return [...(await this.session.modelRuntime.getAvailable())];
|
|
3566
3896
|
}
|
|
3567
3897
|
catch {
|
|
3568
3898
|
return [];
|
|
3569
3899
|
}
|
|
3570
3900
|
}
|
|
3571
|
-
/** Update the footer's available provider count from current
|
|
3572
|
-
|
|
3573
|
-
const models =
|
|
3574
|
-
|
|
3901
|
+
/** Update the footer's available provider count from the current snapshot without refreshing catalogs. */
|
|
3902
|
+
updateAvailableProviderCount() {
|
|
3903
|
+
const models = this.session.scopedModels.length > 0
|
|
3904
|
+
? this.session.scopedModels.map((scoped) => scoped.model)
|
|
3905
|
+
: this.session.modelRuntime.getAvailableSnapshot();
|
|
3906
|
+
const uniqueProviders = new Set(models.map((model) => model.provider));
|
|
3575
3907
|
this.footerDataProvider.setAvailableProviderCount(uniqueProviders.size);
|
|
3576
3908
|
}
|
|
3577
3909
|
async maybeWarnAboutAnthropicSubscriptionAuth(model = this.session.model) {
|
|
@@ -3584,14 +3916,13 @@ export class InteractiveMode {
|
|
|
3584
3916
|
if (!model || model.provider !== "anthropic") {
|
|
3585
3917
|
return;
|
|
3586
3918
|
}
|
|
3587
|
-
const storedCredential = this.session.modelRegistry.authStorage.get("anthropic");
|
|
3588
|
-
if (storedCredential?.type === "oauth") {
|
|
3589
|
-
this.anthropicSubscriptionWarningShown = true;
|
|
3590
|
-
this.showWarning(ANTHROPIC_SUBSCRIPTION_AUTH_WARNING);
|
|
3591
|
-
return;
|
|
3592
|
-
}
|
|
3593
3919
|
try {
|
|
3594
|
-
|
|
3920
|
+
if ((await this.session.modelRuntime.checkAuth("anthropic"))?.type === "oauth") {
|
|
3921
|
+
this.anthropicSubscriptionWarningShown = true;
|
|
3922
|
+
this.showWarning(ANTHROPIC_SUBSCRIPTION_AUTH_WARNING);
|
|
3923
|
+
return;
|
|
3924
|
+
}
|
|
3925
|
+
const apiKey = (await this.session.modelRuntime.getAuth(model.provider))?.auth.apiKey;
|
|
3595
3926
|
if (!isAnthropicSubscriptionAuthKey(apiKey)) {
|
|
3596
3927
|
return;
|
|
3597
3928
|
}
|
|
@@ -3649,7 +3980,7 @@ export class InteractiveMode {
|
|
|
3649
3980
|
}
|
|
3650
3981
|
showModelSelector(initialSearchInput) {
|
|
3651
3982
|
this.showSelector((done) => {
|
|
3652
|
-
const selector = new ModelSelectorComponent(this.ui, this.session.model, this.settingsManager, this.session.
|
|
3983
|
+
const selector = new ModelSelectorComponent(this.ui, this.session.model, this.settingsManager, this.session.modelRuntime, this.session.scopedModels, async (model) => {
|
|
3653
3984
|
try {
|
|
3654
3985
|
await this.session.setModel(model);
|
|
3655
3986
|
this.footer.invalidate();
|
|
@@ -3672,14 +4003,19 @@ export class InteractiveMode {
|
|
|
3672
4003
|
}
|
|
3673
4004
|
async showModelsSelector() {
|
|
3674
4005
|
// Get all available models
|
|
3675
|
-
this.session.
|
|
3676
|
-
const allModels = this.session.
|
|
3677
|
-
|
|
4006
|
+
await this.session.modelRuntime.refresh();
|
|
4007
|
+
const allModels = [...(await this.session.modelRuntime.getAvailable())];
|
|
4008
|
+
const allModelIds = new Set(allModels.map((model) => `${model.provider}/${model.id}`));
|
|
4009
|
+
const configuredPatterns = this.settingsManager.getEnabledModels();
|
|
4010
|
+
const sessionScopedModels = this.session.scopedModels;
|
|
4011
|
+
if (allModels.length === 0 && !configuredPatterns?.length && sessionScopedModels.length === 0) {
|
|
3678
4012
|
this.showStatus("No models available");
|
|
3679
4013
|
return;
|
|
3680
4014
|
}
|
|
4015
|
+
const configuredScope = configuredPatterns?.length
|
|
4016
|
+
? await resolveModelScopeWithDiagnostics(configuredPatterns, this.session.modelRuntime)
|
|
4017
|
+
: undefined;
|
|
3681
4018
|
// Check if session has scoped models (from previous session-only changes or CLI --models)
|
|
3682
|
-
const sessionScopedModels = this.session.scopedModels;
|
|
3683
4019
|
const hasSessionScope = sessionScopedModels.length > 0;
|
|
3684
4020
|
// Build enabled model IDs from session state or settings
|
|
3685
4021
|
let currentEnabledIds = null;
|
|
@@ -3687,19 +4023,23 @@ export class InteractiveMode {
|
|
|
3687
4023
|
// Use current session's scoped models
|
|
3688
4024
|
currentEnabledIds = sessionScopedModels.map((scoped) => `${scoped.model.provider}/${scoped.model.id}`);
|
|
3689
4025
|
}
|
|
3690
|
-
else {
|
|
3691
|
-
|
|
3692
|
-
|
|
3693
|
-
|
|
3694
|
-
|
|
3695
|
-
|
|
3696
|
-
|
|
4026
|
+
else if (configuredScope) {
|
|
4027
|
+
currentEnabledIds = configuredScope.scopedModels.map((scoped) => `${scoped.model.provider}/${scoped.model.id}`);
|
|
4028
|
+
}
|
|
4029
|
+
for (const diagnostic of configuredScope?.diagnostics ?? []) {
|
|
4030
|
+
if (diagnostic.code !== "no-match")
|
|
4031
|
+
continue;
|
|
4032
|
+
currentEnabledIds ??= [];
|
|
4033
|
+
if (!currentEnabledIds.includes(diagnostic.pattern))
|
|
4034
|
+
currentEnabledIds.push(diagnostic.pattern);
|
|
3697
4035
|
}
|
|
3698
4036
|
// Helper to update session's scoped models (session-only, no persist)
|
|
3699
4037
|
const updateSessionModels = async (enabledIds) => {
|
|
3700
4038
|
currentEnabledIds = enabledIds === null ? null : [...enabledIds];
|
|
3701
|
-
|
|
3702
|
-
|
|
4039
|
+
const hasEnabledAvailableModel = enabledIds?.some((id) => allModelIds.has(id)) ?? false;
|
|
4040
|
+
const allAvailableModelsEnabled = enabledIds !== null && [...allModelIds].every((id) => enabledIds.includes(id));
|
|
4041
|
+
if (enabledIds && hasEnabledAvailableModel && !allAvailableModelsEnabled) {
|
|
4042
|
+
const newScopedModels = await resolveModelScope(enabledIds, this.session.modelRuntime);
|
|
3703
4043
|
this.session.setScopedModels(newScopedModels.map((sm) => ({
|
|
3704
4044
|
model: sm.model,
|
|
3705
4045
|
thinkingLevel: sm.thinkingLevel,
|
|
@@ -3722,9 +4062,10 @@ export class InteractiveMode {
|
|
|
3722
4062
|
},
|
|
3723
4063
|
onPersist: (enabledIds) => {
|
|
3724
4064
|
// Persist to settings
|
|
3725
|
-
const
|
|
3726
|
-
|
|
3727
|
-
|
|
4065
|
+
const allEnabled = enabledIds !== null &&
|
|
4066
|
+
enabledIds.length === allModels.length &&
|
|
4067
|
+
enabledIds.every((id) => allModelIds.has(id));
|
|
4068
|
+
const newPatterns = enabledIds === null || allEnabled ? undefined : enabledIds;
|
|
3728
4069
|
this.settingsManager.setEnabledModels(newPatterns ? [...newPatterns] : undefined);
|
|
3729
4070
|
this.showStatus("Model selection saved to settings");
|
|
3730
4071
|
},
|
|
@@ -3746,6 +4087,14 @@ export class InteractiveMode {
|
|
|
3746
4087
|
this.showSelector((done) => {
|
|
3747
4088
|
const selector = new UserMessageSelectorComponent(userMessages.map((m) => ({ id: m.entryId, text: m.text })), async (entryId) => {
|
|
3748
4089
|
done();
|
|
4090
|
+
// The user committed to forking: stop the active response first,
|
|
4091
|
+
// the same way /tree and /rewind do. The fork fires the
|
|
4092
|
+
// checkpoint restore offer, and that must never rewrite the
|
|
4093
|
+
// working tree while the agent is still writing to it.
|
|
4094
|
+
if (this.session.isStreaming) {
|
|
4095
|
+
this.restoreQueuedMessagesToEditor();
|
|
4096
|
+
await this.session.abort();
|
|
4097
|
+
}
|
|
3749
4098
|
try {
|
|
3750
4099
|
const result = await this.runtimeHost.fork(entryId);
|
|
3751
4100
|
if (result.cancelled) {
|
|
@@ -3795,7 +4144,7 @@ export class InteractiveMode {
|
|
|
3795
4144
|
this.showSelector((done) => {
|
|
3796
4145
|
const selector = new TreeSelectorComponent(tree, realLeafId, this.ui.terminal.rows, async (entryId) => {
|
|
3797
4146
|
// Selecting the current leaf is a no-op (already there)
|
|
3798
|
-
if (entryId ===
|
|
4147
|
+
if (entryId === this.sessionManager.getLeafId()) {
|
|
3799
4148
|
done();
|
|
3800
4149
|
this.showStatus("Already at this point");
|
|
3801
4150
|
return;
|
|
@@ -3830,6 +4179,11 @@ export class InteractiveMode {
|
|
|
3830
4179
|
break;
|
|
3831
4180
|
}
|
|
3832
4181
|
}
|
|
4182
|
+
// The user committed to navigating: stop the active response first.
|
|
4183
|
+
if (this.session.isStreaming) {
|
|
4184
|
+
this.restoreQueuedMessagesToEditor();
|
|
4185
|
+
await this.session.abort();
|
|
4186
|
+
}
|
|
3833
4187
|
// Set up escape handler and status indicator if summarizing
|
|
3834
4188
|
let showingSummaryIndicator = false;
|
|
3835
4189
|
const originalOnEscape = this.defaultEditor.onEscape;
|
|
@@ -3882,9 +4236,140 @@ export class InteractiveMode {
|
|
|
3882
4236
|
this.sessionManager.appendLabelChange(entryId, label);
|
|
3883
4237
|
this.ui.requestRender();
|
|
3884
4238
|
}, initialSelectedId, initialFilterMode);
|
|
4239
|
+
selector.onCopy = async (text) => {
|
|
4240
|
+
if (!text) {
|
|
4241
|
+
this.showError("Selected entry has no text to copy");
|
|
4242
|
+
return;
|
|
4243
|
+
}
|
|
4244
|
+
try {
|
|
4245
|
+
await copyToClipboard(text);
|
|
4246
|
+
this.showStatus("Copied selected message to clipboard");
|
|
4247
|
+
}
|
|
4248
|
+
catch (error) {
|
|
4249
|
+
this.showError(error instanceof Error ? error.message : String(error));
|
|
4250
|
+
}
|
|
4251
|
+
};
|
|
4252
|
+
return { component: selector, focus: selector };
|
|
4253
|
+
});
|
|
4254
|
+
}
|
|
4255
|
+
/** Checkpoint manager for the live session; undefined before a session file exists. */
|
|
4256
|
+
createCheckpointManager() {
|
|
4257
|
+
const sessionFile = this.sessionManager.getSessionFile();
|
|
4258
|
+
if (!sessionFile)
|
|
4259
|
+
return undefined;
|
|
4260
|
+
return new CheckpointManager({
|
|
4261
|
+
cwd: this.sessionManager.getCwd(),
|
|
4262
|
+
sessionId: this.sessionManager.getSessionId(),
|
|
4263
|
+
sessionFile,
|
|
4264
|
+
});
|
|
4265
|
+
}
|
|
4266
|
+
/**
|
|
4267
|
+
* `/rewind` (R42-RWD.1): the tree selector, restricted to entries that have a
|
|
4268
|
+
* checkpoint and annotated with its time and dirty-file count, followed by the
|
|
4269
|
+
* restore-scope menu (R42-RWD.2). Entries on abandoned branches keep their
|
|
4270
|
+
* checkpoints, so rewinding forward to one is just another selection (R42-RWD.6).
|
|
4271
|
+
*/
|
|
4272
|
+
showRewindSelector(initialSelectedId) {
|
|
4273
|
+
const tree = this.sessionManager.getTree();
|
|
4274
|
+
if (tree.length === 0) {
|
|
4275
|
+
this.showStatus("No entries in session");
|
|
4276
|
+
return;
|
|
4277
|
+
}
|
|
4278
|
+
const manager = this.createCheckpointManager();
|
|
4279
|
+
const targets = manager ? listRewindTargets(manager.list()) : [];
|
|
4280
|
+
const checkpoints = targets.length > 0
|
|
4281
|
+
? new Map(targets.map((target) => [
|
|
4282
|
+
target.entryId,
|
|
4283
|
+
{ timestamp: target.timestamp, dirtyFileCount: target.dirtyFileCount },
|
|
4284
|
+
]))
|
|
4285
|
+
: undefined;
|
|
4286
|
+
if (!checkpoints) {
|
|
4287
|
+
// No snapshots (e.g. a non-git cwd): still rewind the conversation.
|
|
4288
|
+
this.showStatus("No checkpoints recorded - /rewind will restore the conversation only");
|
|
4289
|
+
}
|
|
4290
|
+
this.showSelector((done) => {
|
|
4291
|
+
const selector = new TreeSelectorComponent(tree, this.sessionManager.getLeafId(), this.ui.terminal.rows, async (entryId) => {
|
|
4292
|
+
done();
|
|
4293
|
+
if (!checkpoints) {
|
|
4294
|
+
await this.runRewind(entryId, "conversation-only", undefined);
|
|
4295
|
+
return;
|
|
4296
|
+
}
|
|
4297
|
+
const label = await this.showExtensionSelector("Restore scope?", REWIND_SCOPE_CHOICES.map((choice) => choice.label));
|
|
4298
|
+
if (label === undefined) {
|
|
4299
|
+
// Escape returns to the selector with the same entry focused.
|
|
4300
|
+
this.showRewindSelector(entryId);
|
|
4301
|
+
return;
|
|
4302
|
+
}
|
|
4303
|
+
await this.runRewind(entryId, rewindScopeForLabel(label) ?? DEFAULT_REWIND_SCOPE, manager);
|
|
4304
|
+
}, () => {
|
|
4305
|
+
done();
|
|
4306
|
+
this.ui.requestRender();
|
|
4307
|
+
}, undefined, initialSelectedId, undefined, { title: "Rewind", checkpoints });
|
|
3885
4308
|
return { component: selector, focus: selector };
|
|
3886
4309
|
});
|
|
3887
4310
|
}
|
|
4311
|
+
/**
|
|
4312
|
+
* Run the rewind under the chosen scope. The conversation leaf is moved by
|
|
4313
|
+
* `performRewind` through this navigate callback, which it only invokes once
|
|
4314
|
+
* the file restore has succeeded (R42-RWD.5).
|
|
4315
|
+
*/
|
|
4316
|
+
async runRewind(targetEntryId, scope, manager) {
|
|
4317
|
+
const currentEntryId = this.sessionManager.getLeafId();
|
|
4318
|
+
if (!currentEntryId) {
|
|
4319
|
+
this.showStatus("Nothing to rewind yet");
|
|
4320
|
+
return;
|
|
4321
|
+
}
|
|
4322
|
+
if (targetEntryId === currentEntryId && scope === "conversation-only") {
|
|
4323
|
+
this.showStatus("Already at this point");
|
|
4324
|
+
return;
|
|
4325
|
+
}
|
|
4326
|
+
// The user committed to rewinding: stop the active response first.
|
|
4327
|
+
if (this.session.isStreaming) {
|
|
4328
|
+
this.restoreQueuedMessagesToEditor();
|
|
4329
|
+
await this.session.abort();
|
|
4330
|
+
}
|
|
4331
|
+
// The selector already called `done()`, so the editor has focus again
|
|
4332
|
+
// while this runs. Block submissions until the restore is finished
|
|
4333
|
+
// rather than let a new prompt race the file writes.
|
|
4334
|
+
this.isRewindRunning = true;
|
|
4335
|
+
let result;
|
|
4336
|
+
try {
|
|
4337
|
+
result = await performRewind({
|
|
4338
|
+
manager,
|
|
4339
|
+
scope,
|
|
4340
|
+
// Scopes the in-progress gate to this session (R35-ALWAYS.5).
|
|
4341
|
+
// Read at call time so it follows a session replacement.
|
|
4342
|
+
sessionId: this.sessionManager.getSessionId(),
|
|
4343
|
+
targetEntryId,
|
|
4344
|
+
currentEntryId,
|
|
4345
|
+
// Gives extensions the `session_before_rewind` veto (R42-RWD.8).
|
|
4346
|
+
runner: this.session.extensionRunner,
|
|
4347
|
+
navigate: async () => {
|
|
4348
|
+
if (targetEntryId === currentEntryId)
|
|
4349
|
+
return;
|
|
4350
|
+
const navigation = await this.session.navigateTree(targetEntryId, { summarize: false });
|
|
4351
|
+
if (navigation.cancelled)
|
|
4352
|
+
throw new Error("navigation cancelled");
|
|
4353
|
+
this.chatContainer.clear();
|
|
4354
|
+
this.renderInitialMessages();
|
|
4355
|
+
if (navigation.editorText && !this.editor.getText().trim()) {
|
|
4356
|
+
this.editor.setText(navigation.editorText);
|
|
4357
|
+
}
|
|
4358
|
+
void this.flushCompactionQueue({ willRetry: false });
|
|
4359
|
+
},
|
|
4360
|
+
});
|
|
4361
|
+
}
|
|
4362
|
+
finally {
|
|
4363
|
+
this.isRewindRunning = false;
|
|
4364
|
+
}
|
|
4365
|
+
if (result.ok) {
|
|
4366
|
+
this.showStatus(result.message);
|
|
4367
|
+
}
|
|
4368
|
+
else {
|
|
4369
|
+
this.showError(result.message);
|
|
4370
|
+
}
|
|
4371
|
+
this.ui.requestRender();
|
|
4372
|
+
}
|
|
3888
4373
|
showSessionSelector() {
|
|
3889
4374
|
this.showSelector((done) => {
|
|
3890
4375
|
const selector = new SessionSelectorComponent((onProgress) => SessionManager.list(this.sessionManager.getCwd(), this.sessionManager.getSessionDir(), onProgress), (onProgress) => this.sessionManager.usesDefaultSessionDir()
|
|
@@ -3946,44 +4431,46 @@ export class InteractiveMode {
|
|
|
3946
4431
|
}
|
|
3947
4432
|
}
|
|
3948
4433
|
getLoginProviderOptions(authType) {
|
|
3949
|
-
const authStorage = this.session.modelRegistry.authStorage;
|
|
3950
|
-
const oauthProviders = authStorage.getOAuthProviders();
|
|
3951
|
-
const oauthProviderIds = new Set(oauthProviders.map((provider) => provider.id));
|
|
3952
|
-
const options = oauthProviders.map((provider) => ({
|
|
3953
|
-
id: provider.id,
|
|
3954
|
-
name: provider.name,
|
|
3955
|
-
authType: "oauth",
|
|
3956
|
-
}));
|
|
3957
|
-
const modelProviders = new Set(this.session.modelRegistry.getAll().map((model) => model.provider));
|
|
3958
|
-
for (const providerId of modelProviders) {
|
|
3959
|
-
if (!isApiKeyLoginProvider(providerId, oauthProviderIds)) {
|
|
3960
|
-
continue;
|
|
3961
|
-
}
|
|
3962
|
-
options.push({
|
|
3963
|
-
id: providerId,
|
|
3964
|
-
name: this.session.modelRegistry.getProviderDisplayName(providerId),
|
|
3965
|
-
authType: "api_key",
|
|
3966
|
-
});
|
|
3967
|
-
}
|
|
3968
|
-
const filteredOptions = authType ? options.filter((option) => option.authType === authType) : options;
|
|
3969
|
-
return filteredOptions.sort((a, b) => a.name.localeCompare(b.name));
|
|
3970
|
-
}
|
|
3971
|
-
getLogoutProviderOptions() {
|
|
3972
|
-
const authStorage = this.session.modelRegistry.authStorage;
|
|
3973
4434
|
const options = [];
|
|
3974
|
-
for (const
|
|
3975
|
-
const
|
|
3976
|
-
|
|
3977
|
-
|
|
4435
|
+
for (const provider of this.session.modelRuntime.getProviders()) {
|
|
4436
|
+
const authStatus = this.session.modelRuntime.getProviderAuthStatus(provider.id);
|
|
4437
|
+
const status = authStatus.configured
|
|
4438
|
+
? {
|
|
4439
|
+
type: this.session.modelRuntime.isUsingOAuth(provider.id) ? "oauth" : "api_key",
|
|
4440
|
+
source: authStatus.label ?? authStatus.source,
|
|
4441
|
+
}
|
|
4442
|
+
: undefined;
|
|
4443
|
+
if ((!authType || authType === "oauth") && provider.auth.oauth) {
|
|
4444
|
+
options.push({
|
|
4445
|
+
id: provider.id,
|
|
4446
|
+
name: provider.name,
|
|
4447
|
+
authType: "oauth",
|
|
4448
|
+
method: provider.auth.oauth,
|
|
4449
|
+
status,
|
|
4450
|
+
});
|
|
4451
|
+
}
|
|
4452
|
+
if ((!authType || authType === "api_key") && provider.auth.apiKey) {
|
|
4453
|
+
options.push({
|
|
4454
|
+
id: provider.id,
|
|
4455
|
+
name: provider.name,
|
|
4456
|
+
authType: "api_key",
|
|
4457
|
+
method: provider.auth.apiKey,
|
|
4458
|
+
status,
|
|
4459
|
+
});
|
|
3978
4460
|
}
|
|
3979
|
-
options.push({
|
|
3980
|
-
id: providerId,
|
|
3981
|
-
name: this.session.modelRegistry.getProviderDisplayName(providerId),
|
|
3982
|
-
authType: credential.type,
|
|
3983
|
-
});
|
|
3984
4461
|
}
|
|
3985
4462
|
return options.sort((a, b) => a.name.localeCompare(b.name));
|
|
3986
4463
|
}
|
|
4464
|
+
async getLogoutProviderOptions() {
|
|
4465
|
+
return (await this.session.modelRuntime.listCredentials())
|
|
4466
|
+
.map(({ providerId, type }) => ({
|
|
4467
|
+
id: providerId,
|
|
4468
|
+
name: this.session.modelRuntime.getProvider(providerId)?.name ?? providerId,
|
|
4469
|
+
authType: type,
|
|
4470
|
+
status: { type, source: "stored credential" },
|
|
4471
|
+
}))
|
|
4472
|
+
.sort((a, b) => a.name.localeCompare(b.name));
|
|
4473
|
+
}
|
|
3987
4474
|
findLoginProviderOptions(providerRef) {
|
|
3988
4475
|
const normalizedProviderRef = providerRef.trim().toLowerCase();
|
|
3989
4476
|
if (!normalizedProviderRef) {
|
|
@@ -3993,6 +4480,7 @@ export class InteractiveMode {
|
|
|
3993
4480
|
provider.name.toLowerCase() === normalizedProviderRef);
|
|
3994
4481
|
}
|
|
3995
4482
|
async handleLoginCommand(providerRef) {
|
|
4483
|
+
await this.session.modelRuntime.getAvailable();
|
|
3996
4484
|
if (!providerRef) {
|
|
3997
4485
|
this.showLoginAuthTypeSelector();
|
|
3998
4486
|
return;
|
|
@@ -4015,16 +4503,18 @@ export class InteractiveMode {
|
|
|
4015
4503
|
if (providerOption.authType === "oauth") {
|
|
4016
4504
|
await this.showLoginDialog(providerOption.id, providerOption.name);
|
|
4017
4505
|
}
|
|
4018
|
-
else if (providerOption.
|
|
4019
|
-
this.
|
|
4506
|
+
else if (providerOption.method?.login) {
|
|
4507
|
+
await this.showApiKeyLoginDialog(providerOption.id, providerOption.name);
|
|
4020
4508
|
}
|
|
4021
4509
|
else {
|
|
4022
|
-
|
|
4510
|
+
this.showAmbientAuthDialog(providerOption);
|
|
4023
4511
|
}
|
|
4024
4512
|
}
|
|
4025
4513
|
showLoginAuthTypeSelector(providerOptions) {
|
|
4026
|
-
const
|
|
4027
|
-
const
|
|
4514
|
+
const oauthProvider = providerOptions?.find((provider) => provider.authType === "oauth");
|
|
4515
|
+
const oauthLoginLabel = oauthProvider?.method && "loginLabel" in oauthProvider.method ? oauthProvider.method.loginLabel : undefined;
|
|
4516
|
+
const subscriptionLabel = oauthLoginLabel ?? "Sign in with an account";
|
|
4517
|
+
const apiKeyLabel = "Sign in with an API key";
|
|
4028
4518
|
const availableAuthTypes = providerOptions
|
|
4029
4519
|
? new Set(providerOptions.map((provider) => provider.authType))
|
|
4030
4520
|
: new Set(["oauth", "api_key"]);
|
|
@@ -4080,7 +4570,7 @@ export class InteractiveMode {
|
|
|
4080
4570
|
return;
|
|
4081
4571
|
}
|
|
4082
4572
|
this.showSelector((done) => {
|
|
4083
|
-
const selector = new OAuthSelectorComponent("login",
|
|
4573
|
+
const selector = new OAuthSelectorComponent("login", providerOptions, async (providerId, selectedAuthType) => {
|
|
4084
4574
|
done();
|
|
4085
4575
|
const providerOption = providerOptions.find((provider) => provider.id === providerId && provider.authType === selectedAuthType);
|
|
4086
4576
|
if (!providerOption) {
|
|
@@ -4095,7 +4585,7 @@ export class InteractiveMode {
|
|
|
4095
4585
|
else {
|
|
4096
4586
|
this.ui.requestRender();
|
|
4097
4587
|
}
|
|
4098
|
-
},
|
|
4588
|
+
}, initialSearchInput);
|
|
4099
4589
|
return { component: selector, focus: selector };
|
|
4100
4590
|
});
|
|
4101
4591
|
}
|
|
@@ -4104,21 +4594,20 @@ export class InteractiveMode {
|
|
|
4104
4594
|
this.showLoginAuthTypeSelector();
|
|
4105
4595
|
return;
|
|
4106
4596
|
}
|
|
4107
|
-
const providerOptions = this.getLogoutProviderOptions();
|
|
4597
|
+
const providerOptions = await this.getLogoutProviderOptions();
|
|
4108
4598
|
if (providerOptions.length === 0) {
|
|
4109
4599
|
this.showStatus("No stored credentials to remove. /logout only removes credentials saved by /login; environment variables and models.json config are unchanged.");
|
|
4110
4600
|
return;
|
|
4111
4601
|
}
|
|
4112
4602
|
this.showSelector((done) => {
|
|
4113
|
-
const selector = new OAuthSelectorComponent(mode,
|
|
4603
|
+
const selector = new OAuthSelectorComponent(mode, providerOptions, async (providerId) => {
|
|
4114
4604
|
done();
|
|
4115
4605
|
const providerOption = providerOptions.find((provider) => provider.id === providerId);
|
|
4116
4606
|
if (!providerOption) {
|
|
4117
4607
|
return;
|
|
4118
4608
|
}
|
|
4119
4609
|
try {
|
|
4120
|
-
this.session.
|
|
4121
|
-
this.session.modelRegistry.refresh();
|
|
4610
|
+
await this.session.modelRuntime.logout(providerOption.id);
|
|
4122
4611
|
await this.updateAvailableProviderCount();
|
|
4123
4612
|
const message = providerOption.authType === "oauth"
|
|
4124
4613
|
? `Logged out of ${providerOption.name}`
|
|
@@ -4136,12 +4625,12 @@ export class InteractiveMode {
|
|
|
4136
4625
|
});
|
|
4137
4626
|
}
|
|
4138
4627
|
async completeProviderAuthentication(providerId, providerName, authType, previousModel) {
|
|
4139
|
-
this.session.
|
|
4628
|
+
await this.session.modelRuntime.getAvailable();
|
|
4140
4629
|
const actionLabel = authType === "oauth" ? `Logged in to ${providerName}` : `Saved API key for ${providerName}`;
|
|
4141
4630
|
let selectedModel;
|
|
4142
4631
|
let selectionError;
|
|
4143
4632
|
if (isUnknownModel(previousModel)) {
|
|
4144
|
-
const availableModels = this.session.
|
|
4633
|
+
const availableModels = await this.session.modelRuntime.getAvailable();
|
|
4145
4634
|
const providerModels = availableModels.filter((model) => model.provider === providerId);
|
|
4146
4635
|
if (!hasDefaultModelProvider(providerId)) {
|
|
4147
4636
|
selectionError = `${actionLabel}, but no default model is configured for provider "${providerId}". Use /model to select a model.`;
|
|
@@ -4185,20 +4674,15 @@ export class InteractiveMode {
|
|
|
4185
4674
|
}
|
|
4186
4675
|
}
|
|
4187
4676
|
}
|
|
4188
|
-
|
|
4677
|
+
showAmbientAuthDialog(providerOption) {
|
|
4189
4678
|
const restoreEditor = () => {
|
|
4190
4679
|
this.editorContainer.clear();
|
|
4191
4680
|
this.editorContainer.addChild(this.editor);
|
|
4192
4681
|
this.ui.setFocus(this.editor);
|
|
4193
4682
|
this.ui.requestRender();
|
|
4194
4683
|
};
|
|
4195
|
-
const dialog = new LoginDialogComponent(this.ui,
|
|
4196
|
-
dialog.showInfo([
|
|
4197
|
-
theme.fg("text", "Amazon Bedrock uses AWS credentials instead of a single API key."),
|
|
4198
|
-
theme.fg("text", "Configure an AWS profile, IAM keys, bearer token, or role-based credentials."),
|
|
4199
|
-
theme.fg("muted", "See:"),
|
|
4200
|
-
theme.fg("accent", ` ${path.join(getDocsPath(), "providers.md")}`),
|
|
4201
|
-
]);
|
|
4684
|
+
const dialog = new LoginDialogComponent(this.ui, providerOption.id, () => restoreEditor(), providerOption.name, `${providerOption.name} setup`);
|
|
4685
|
+
dialog.showInfo(`${providerOption.method?.name ?? "Authentication"} is configured outside pi.`, [], true);
|
|
4202
4686
|
this.editorContainer.clear();
|
|
4203
4687
|
this.editorContainer.addChild(dialog);
|
|
4204
4688
|
this.ui.setFocus(dialog);
|
|
@@ -4209,6 +4693,13 @@ export class InteractiveMode {
|
|
|
4209
4693
|
const dialog = new LoginDialogComponent(this.ui, providerId, (_success, _message) => {
|
|
4210
4694
|
// Completion handled below
|
|
4211
4695
|
}, providerName);
|
|
4696
|
+
if (providerId === "amazon-bedrock") {
|
|
4697
|
+
dialog.showDetails([
|
|
4698
|
+
theme.fg("text", "You can also use an AWS profile, IAM keys, or role-based credentials."),
|
|
4699
|
+
theme.fg("muted", "See:"),
|
|
4700
|
+
theme.fg("accent", ` ${path.join(getDocsPath(), "providers.md")}`),
|
|
4701
|
+
]);
|
|
4702
|
+
}
|
|
4212
4703
|
this.editorContainer.clear();
|
|
4213
4704
|
this.editorContainer.addChild(dialog);
|
|
4214
4705
|
this.ui.setFocus(dialog);
|
|
@@ -4220,11 +4711,7 @@ export class InteractiveMode {
|
|
|
4220
4711
|
this.ui.requestRender();
|
|
4221
4712
|
};
|
|
4222
4713
|
try {
|
|
4223
|
-
|
|
4224
|
-
if (!apiKey) {
|
|
4225
|
-
throw new Error("API key cannot be empty.");
|
|
4226
|
-
}
|
|
4227
|
-
this.session.modelRegistry.authStorage.set(providerId, { type: "api_key", key: apiKey });
|
|
4714
|
+
await this.loginProvider(dialog, providerId, "api_key");
|
|
4228
4715
|
restoreEditor();
|
|
4229
4716
|
await this.completeProviderAuthentication(providerId, providerName, "api_key", previousModel);
|
|
4230
4717
|
}
|
|
@@ -4236,8 +4723,8 @@ export class InteractiveMode {
|
|
|
4236
4723
|
}
|
|
4237
4724
|
}
|
|
4238
4725
|
}
|
|
4239
|
-
|
|
4240
|
-
return new Promise((resolve) => {
|
|
4726
|
+
showAuthSelect(dialog, prompt) {
|
|
4727
|
+
return new Promise((resolve, reject) => {
|
|
4241
4728
|
const restoreDialog = () => {
|
|
4242
4729
|
this.editorContainer.clear();
|
|
4243
4730
|
this.editorContainer.addChild(dialog);
|
|
@@ -4247,10 +4734,14 @@ export class InteractiveMode {
|
|
|
4247
4734
|
const labels = prompt.options.map((option) => option.label);
|
|
4248
4735
|
const selector = new ExtensionSelectorComponent(prompt.message, labels, (optionLabel) => {
|
|
4249
4736
|
restoreDialog();
|
|
4250
|
-
|
|
4737
|
+
const id = prompt.options.find((option) => option.label === optionLabel)?.id;
|
|
4738
|
+
if (id)
|
|
4739
|
+
resolve(id);
|
|
4740
|
+
else
|
|
4741
|
+
reject(new Error("Login cancelled"));
|
|
4251
4742
|
}, () => {
|
|
4252
4743
|
restoreDialog();
|
|
4253
|
-
|
|
4744
|
+
reject(new Error("Login cancelled"));
|
|
4254
4745
|
});
|
|
4255
4746
|
this.editorContainer.clear();
|
|
4256
4747
|
this.editorContainer.addChild(selector);
|
|
@@ -4258,30 +4749,64 @@ export class InteractiveMode {
|
|
|
4258
4749
|
this.ui.requestRender();
|
|
4259
4750
|
});
|
|
4260
4751
|
}
|
|
4752
|
+
async showAuthPrompt(dialog, prompt) {
|
|
4753
|
+
let response;
|
|
4754
|
+
if (prompt.type === "select") {
|
|
4755
|
+
response = this.showAuthSelect(dialog, prompt);
|
|
4756
|
+
}
|
|
4757
|
+
else if (prompt.type === "manual_code") {
|
|
4758
|
+
response = dialog.showManualInput(prompt.message);
|
|
4759
|
+
}
|
|
4760
|
+
else {
|
|
4761
|
+
response = dialog.showPrompt(prompt.message, prompt.placeholder);
|
|
4762
|
+
}
|
|
4763
|
+
if (!prompt.signal)
|
|
4764
|
+
return response;
|
|
4765
|
+
if (prompt.signal.aborted)
|
|
4766
|
+
throw new Error("Login cancelled");
|
|
4767
|
+
const signal = prompt.signal;
|
|
4768
|
+
let onAbort;
|
|
4769
|
+
const aborted = new Promise((_resolve, reject) => {
|
|
4770
|
+
onAbort = () => reject(new Error("Login cancelled"));
|
|
4771
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
4772
|
+
});
|
|
4773
|
+
try {
|
|
4774
|
+
return await Promise.race([response, aborted]);
|
|
4775
|
+
}
|
|
4776
|
+
finally {
|
|
4777
|
+
if (onAbort)
|
|
4778
|
+
signal.removeEventListener("abort", onAbort);
|
|
4779
|
+
}
|
|
4780
|
+
}
|
|
4781
|
+
notifyAuthDialog(dialog, event) {
|
|
4782
|
+
if (event.type === "auth_url") {
|
|
4783
|
+
dialog.showAuth(event.url, event.instructions);
|
|
4784
|
+
}
|
|
4785
|
+
else if (event.type === "device_code") {
|
|
4786
|
+
dialog.showDeviceCode(event);
|
|
4787
|
+
dialog.showWaiting("Waiting for authentication...");
|
|
4788
|
+
}
|
|
4789
|
+
else if (event.type === "info") {
|
|
4790
|
+
dialog.showInfo(event.message, event.links);
|
|
4791
|
+
}
|
|
4792
|
+
else {
|
|
4793
|
+
dialog.showProgress(event.message);
|
|
4794
|
+
}
|
|
4795
|
+
}
|
|
4796
|
+
async loginProvider(dialog, providerId, method) {
|
|
4797
|
+
await this.session.modelRuntime.login(providerId, method, {
|
|
4798
|
+
signal: dialog.signal,
|
|
4799
|
+
prompt: (prompt) => this.showAuthPrompt(dialog, prompt),
|
|
4800
|
+
notify: (event) => this.notifyAuthDialog(dialog, event),
|
|
4801
|
+
});
|
|
4802
|
+
}
|
|
4261
4803
|
async showLoginDialog(providerId, providerName) {
|
|
4262
|
-
const providerInfo = this.session.modelRegistry.authStorage
|
|
4263
|
-
.getOAuthProviders()
|
|
4264
|
-
.find((provider) => provider.id === providerId);
|
|
4265
4804
|
const previousModel = this.session.model;
|
|
4266
|
-
|
|
4267
|
-
const usesCallbackServer = providerInfo?.usesCallbackServer ?? false;
|
|
4268
|
-
// Create login dialog component
|
|
4269
|
-
const dialog = new LoginDialogComponent(this.ui, providerId, (_success, _message) => {
|
|
4270
|
-
// Completion handled below
|
|
4271
|
-
}, providerName);
|
|
4272
|
-
// Show dialog in editor container
|
|
4805
|
+
const dialog = new LoginDialogComponent(this.ui, providerId, (_success, _message) => { }, providerName);
|
|
4273
4806
|
this.editorContainer.clear();
|
|
4274
4807
|
this.editorContainer.addChild(dialog);
|
|
4275
4808
|
this.ui.setFocus(dialog);
|
|
4276
4809
|
this.ui.requestRender();
|
|
4277
|
-
// Promise for manual code input (racing with callback server)
|
|
4278
|
-
let manualCodeResolve;
|
|
4279
|
-
let manualCodeReject;
|
|
4280
|
-
const manualCodePromise = new Promise((resolve, reject) => {
|
|
4281
|
-
manualCodeResolve = resolve;
|
|
4282
|
-
manualCodeReject = reject;
|
|
4283
|
-
});
|
|
4284
|
-
// Restore editor helper
|
|
4285
4810
|
const restoreEditor = () => {
|
|
4286
4811
|
this.editorContainer.clear();
|
|
4287
4812
|
this.editorContainer.addChild(this.editor);
|
|
@@ -4289,43 +4814,7 @@ export class InteractiveMode {
|
|
|
4289
4814
|
this.ui.requestRender();
|
|
4290
4815
|
};
|
|
4291
4816
|
try {
|
|
4292
|
-
await this.
|
|
4293
|
-
onAuth: (info) => {
|
|
4294
|
-
dialog.showAuth(info.url, info.instructions);
|
|
4295
|
-
if (usesCallbackServer) {
|
|
4296
|
-
// Show input for manual paste, racing with callback
|
|
4297
|
-
dialog
|
|
4298
|
-
.showManualInput("Paste redirect URL below, or complete login in browser:")
|
|
4299
|
-
.then((value) => {
|
|
4300
|
-
if (value && manualCodeResolve) {
|
|
4301
|
-
manualCodeResolve(value);
|
|
4302
|
-
manualCodeResolve = undefined;
|
|
4303
|
-
}
|
|
4304
|
-
})
|
|
4305
|
-
.catch(() => {
|
|
4306
|
-
if (manualCodeReject) {
|
|
4307
|
-
manualCodeReject(new Error("Login cancelled"));
|
|
4308
|
-
manualCodeReject = undefined;
|
|
4309
|
-
}
|
|
4310
|
-
});
|
|
4311
|
-
}
|
|
4312
|
-
// For Anthropic: onPrompt is called immediately after
|
|
4313
|
-
},
|
|
4314
|
-
onDeviceCode: (info) => {
|
|
4315
|
-
dialog.showDeviceCode(info);
|
|
4316
|
-
dialog.showWaiting("Waiting for authentication...");
|
|
4317
|
-
},
|
|
4318
|
-
onPrompt: async (prompt) => {
|
|
4319
|
-
return dialog.showPrompt(prompt.message, prompt.placeholder);
|
|
4320
|
-
},
|
|
4321
|
-
onProgress: (message) => {
|
|
4322
|
-
dialog.showProgress(message);
|
|
4323
|
-
},
|
|
4324
|
-
onSelect: (prompt) => this.showOAuthLoginSelect(dialog, prompt),
|
|
4325
|
-
onManualCodeInput: () => manualCodePromise,
|
|
4326
|
-
signal: dialog.signal,
|
|
4327
|
-
});
|
|
4328
|
-
// Success
|
|
4817
|
+
await this.loginProvider(dialog, providerId, "oauth");
|
|
4329
4818
|
restoreEditor();
|
|
4330
4819
|
await this.completeProviderAuthentication(providerId, providerName, "oauth", previousModel);
|
|
4331
4820
|
}
|
|
@@ -4413,7 +4902,7 @@ export class InteractiveMode {
|
|
|
4413
4902
|
showDiagnosticsWhenQuiet: true,
|
|
4414
4903
|
});
|
|
4415
4904
|
const savedImplicitProjectTrust = this.maybeSaveImplicitProjectTrustAfterReload();
|
|
4416
|
-
const modelsJsonError = this.session.
|
|
4905
|
+
const modelsJsonError = this.session.modelRuntime.getError();
|
|
4417
4906
|
if (modelsJsonError) {
|
|
4418
4907
|
this.showError(`models.json error: ${modelsJsonError}`);
|
|
4419
4908
|
}
|
|
@@ -4641,25 +5130,11 @@ export class InteractiveMode {
|
|
|
4641
5130
|
const stats = this.session.getSessionStats();
|
|
4642
5131
|
const sessionName = this.sessionManager.getSessionName();
|
|
4643
5132
|
const entries = this.sessionManager.getEntries();
|
|
4644
|
-
const cacheWaste = computeCacheWaste(entries, this.session.
|
|
5133
|
+
const cacheWaste = computeCacheWaste(entries, this.session.modelRuntime);
|
|
4645
5134
|
// Cost/token totals per provider/model actually used (e.g. OpenRouter `auto`
|
|
4646
|
-
// resolves to a concrete responseModel)
|
|
4647
|
-
|
|
4648
|
-
|
|
4649
|
-
if (entry.type !== "message" || entry.message.role !== "assistant")
|
|
4650
|
-
continue;
|
|
4651
|
-
const message = entry.message;
|
|
4652
|
-
const usage = message.usage;
|
|
4653
|
-
const key = `${message.provider}/${message.responseModel ?? message.model}`;
|
|
4654
|
-
let bucket = perModelMap.get(key);
|
|
4655
|
-
if (!bucket) {
|
|
4656
|
-
bucket = { key, cost: 0, tokens: 0 };
|
|
4657
|
-
perModelMap.set(key, bucket);
|
|
4658
|
-
}
|
|
4659
|
-
bucket.cost += usage.cost.total;
|
|
4660
|
-
bucket.tokens += usage.input + usage.output + usage.cacheRead + usage.cacheWrite;
|
|
4661
|
-
}
|
|
4662
|
-
const perModel = Array.from(perModelMap.values()).sort((a, b) => b.cost - a.cost);
|
|
5135
|
+
// resolves to a concrete responseModel). Usage without model attribution is
|
|
5136
|
+
// grouped separately so the breakdown reconciles with the session total.
|
|
5137
|
+
const usageBreakdown = getUsageCostBreakdown(entries);
|
|
4663
5138
|
let info = `${theme.bold("Session Info")}\n\n`;
|
|
4664
5139
|
if (sessionName) {
|
|
4665
5140
|
info += `${theme.fg("dim", "Name:")} ${sessionName}\n`;
|
|
@@ -4690,8 +5165,8 @@ export class InteractiveMode {
|
|
|
4690
5165
|
if (stats.cost > 0 || cacheWaste.missedTokens > 0) {
|
|
4691
5166
|
info += `\n${theme.bold("Cost")}\n`;
|
|
4692
5167
|
info += `${theme.fg("dim", "Total:")} $${stats.cost.toFixed(3)}`;
|
|
4693
|
-
if (
|
|
4694
|
-
for (const entry of
|
|
5168
|
+
if (usageBreakdown.length > 1) {
|
|
5169
|
+
for (const entry of usageBreakdown) {
|
|
4695
5170
|
info += `\n ${theme.fg("dim", `${entry.key}:`)} $${entry.cost.toFixed(3)} ${theme.fg("dim", `(${formatTokens(entry.tokens)} tokens)`)}`;
|
|
4696
5171
|
}
|
|
4697
5172
|
}
|
|
@@ -4768,12 +5243,14 @@ export class InteractiveMode {
|
|
|
4768
5243
|
const exit = this.getAppKeyDisplay("app.exit");
|
|
4769
5244
|
const suspend = this.getAppKeyDisplay("app.suspend");
|
|
4770
5245
|
const cycleThinkingLevel = this.getAppKeyDisplay("app.thinking.cycle");
|
|
5246
|
+
const cycleContextWindow = this.getAppKeyDisplay("app.context.cycle");
|
|
4771
5247
|
const cycleModelForward = this.getAppKeyDisplay("app.model.cycleForward");
|
|
4772
5248
|
const selectModel = this.getAppKeyDisplay("app.model.select");
|
|
4773
5249
|
const expandTools = this.getAppKeyDisplay("app.tools.expand");
|
|
4774
5250
|
const toggleThinking = this.getAppKeyDisplay("app.thinking.toggle");
|
|
4775
5251
|
const externalEditor = this.getAppKeyDisplay("app.editor.external");
|
|
4776
5252
|
const cycleModelBackward = this.getAppKeyDisplay("app.model.cycleBackward");
|
|
5253
|
+
const copyMessage = this.getAppKeyDisplay("app.message.copy");
|
|
4777
5254
|
const followUp = this.getAppKeyDisplay("app.message.followUp");
|
|
4778
5255
|
const dequeue = this.getAppKeyDisplay("app.message.dequeue");
|
|
4779
5256
|
const pasteImage = this.getAppKeyDisplay("app.clipboard.pasteImage");
|
|
@@ -4811,14 +5288,15 @@ export class InteractiveMode {
|
|
|
4811
5288
|
| \`${exit}\` | Exit (when editor is empty) |
|
|
4812
5289
|
| \`${suspend}\` | Suspend to background |
|
|
4813
5290
|
| \`${cycleThinkingLevel}\` | Cycle thinking level |
|
|
4814
|
-
| \`${cycleModelForward}\` / \`${cycleModelBackward}\` | Cycle models |
|
|
5291
|
+
${cycleContextWindow ? `| \`${cycleContextWindow}\` | Cycle context window |\n` : ""}| \`${cycleModelForward}\` / \`${cycleModelBackward}\` | Cycle models |
|
|
4815
5292
|
| \`${selectModel}\` | Open model selector |
|
|
4816
5293
|
| \`${expandTools}\` | Toggle tool output expansion |
|
|
4817
5294
|
| \`${toggleThinking}\` | Toggle thinking block visibility |
|
|
4818
5295
|
| \`${externalEditor}\` | Edit message in external editor |
|
|
5296
|
+
| \`${copyMessage}\` | Copy last assistant message |
|
|
4819
5297
|
| \`${followUp}\` | Queue follow-up message |
|
|
4820
5298
|
| \`${dequeue}\` | Restore queued messages |
|
|
4821
|
-
| \`${pasteImage}\` | Paste image from clipboard |
|
|
5299
|
+
| \`${pasteImage}\` | Paste image or text from clipboard |
|
|
4822
5300
|
| \`/\` | Slash commands |
|
|
4823
5301
|
| \`!\` | Run bash command |
|
|
4824
5302
|
| \`!!\` | Run bash command (excluded from context) |
|