@draht/coding-agent 2026.5.12 → 2026.7.7
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 +41 -0
- package/README.md +1 -4
- package/bin/draht-tools.cjs +3756 -1
- package/dist/bun/cli.d.ts.map +1 -1
- package/dist/bun/cli.js +4 -2
- package/dist/bun/cli.js.map +1 -1
- package/dist/bun/register-bedrock.d.ts.map +1 -1
- package/dist/bun/register-bedrock.js +1 -1
- package/dist/bun/register-bedrock.js.map +1 -1
- package/dist/bun/restore-sandbox-env.d.ts +17 -0
- package/dist/bun/restore-sandbox-env.d.ts.map +1 -0
- package/dist/bun/restore-sandbox-env.js +36 -0
- package/dist/bun/restore-sandbox-env.js.map +1 -0
- package/dist/cli/args.d.ts +9 -4
- package/dist/cli/args.d.ts.map +1 -1
- package/dist/cli/args.js +91 -38
- package/dist/cli/args.js.map +1 -1
- package/dist/cli/config-selector.d.ts +5 -3
- package/dist/cli/config-selector.d.ts.map +1 -1
- package/dist/cli/config-selector.js +1 -1
- package/dist/cli/config-selector.js.map +1 -1
- package/dist/cli/file-processor.d.ts.map +1 -1
- package/dist/cli/file-processor.js +13 -26
- package/dist/cli/file-processor.js.map +1 -1
- package/dist/cli/initial-message.d.ts +1 -1
- package/dist/cli/initial-message.d.ts.map +1 -1
- package/dist/cli/initial-message.js.map +1 -1
- package/dist/cli/list-models.d.ts +1 -1
- package/dist/cli/list-models.d.ts.map +1 -1
- package/dist/cli/list-models.js +7 -1
- package/dist/cli/list-models.js.map +1 -1
- package/dist/cli/project-trust.d.ts +10 -0
- package/dist/cli/project-trust.d.ts.map +1 -0
- package/dist/cli/project-trust.js +48 -0
- package/dist/cli/project-trust.js.map +1 -0
- package/dist/cli/session-picker.d.ts +3 -2
- package/dist/cli/session-picker.d.ts.map +1 -1
- package/dist/cli/session-picker.js +5 -4
- package/dist/cli/session-picker.js.map +1 -1
- package/dist/cli/startup-ui.d.ts +20 -0
- package/dist/cli/startup-ui.d.ts.map +1 -0
- package/dist/cli/startup-ui.js +184 -0
- package/dist/cli/startup-ui.js.map +1 -0
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +7 -4
- package/dist/cli.js.map +1 -1
- package/dist/config.d.ts +27 -13
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +284 -63
- package/dist/config.js.map +1 -1
- package/dist/core/agent-session-runtime.d.ts +45 -9
- package/dist/core/agent-session-runtime.d.ts.map +1 -1
- package/dist/core/agent-session-runtime.js +100 -33
- package/dist/core/agent-session-runtime.js.map +1 -1
- package/dist/core/agent-session-services.d.ts +6 -4
- package/dist/core/agent-session-services.d.ts.map +1 -1
- package/dist/core/agent-session-services.js +7 -4
- package/dist/core/agent-session-services.js.map +1 -1
- package/dist/core/agent-session.d.ts +55 -33
- package/dist/core/agent-session.d.ts.map +1 -1
- package/dist/core/agent-session.js +560 -492
- package/dist/core/agent-session.js.map +1 -1
- package/dist/core/auth-guidance.d.ts +5 -0
- package/dist/core/auth-guidance.d.ts.map +1 -0
- package/dist/core/auth-guidance.js +21 -0
- package/dist/core/auth-guidance.js.map +1 -0
- package/dist/core/auth-storage.d.ts +21 -13
- package/dist/core/auth-storage.d.ts.map +1 -1
- package/dist/core/auth-storage.js +48 -28
- package/dist/core/auth-storage.js.map +1 -1
- package/dist/core/bash-executor.d.ts +1 -15
- package/dist/core/bash-executor.d.ts.map +1 -1
- package/dist/core/bash-executor.js +10 -24
- package/dist/core/bash-executor.js.map +1 -1
- package/dist/core/builtins/subagent.d.ts.map +1 -1
- package/dist/core/builtins/subagent.js +1 -2
- package/dist/core/builtins/subagent.js.map +1 -1
- package/dist/core/compaction/branch-summarization.d.ts +9 -5
- package/dist/core/compaction/branch-summarization.d.ts.map +1 -1
- package/dist/core/compaction/branch-summarization.js +10 -4
- package/dist/core/compaction/branch-summarization.js.map +1 -1
- package/dist/core/compaction/compaction.d.ts +8 -7
- package/dist/core/compaction/compaction.d.ts.map +1 -1
- package/dist/core/compaction/compaction.js +56 -47
- package/dist/core/compaction/compaction.js.map +1 -1
- package/dist/core/compaction/index.d.ts +3 -3
- package/dist/core/compaction/index.d.ts.map +1 -1
- package/dist/core/compaction/index.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 +1 -1
- package/dist/core/compaction/utils.js.map +1 -1
- package/dist/core/exec.d.ts.map +1 -1
- package/dist/core/exec.js.map +1 -1
- package/dist/core/experimental.d.ts +2 -0
- package/dist/core/experimental.d.ts.map +1 -0
- package/dist/core/experimental.js +4 -0
- package/dist/core/experimental.js.map +1 -0
- package/dist/core/export-html/ansi-to-html.d.ts.map +1 -1
- package/dist/core/export-html/ansi-to-html.js +1 -1
- package/dist/core/export-html/ansi-to-html.js.map +1 -1
- package/dist/core/export-html/index.d.ts +1 -1
- package/dist/core/export-html/index.d.ts.map +1 -1
- package/dist/core/export-html/index.js +13 -11
- package/dist/core/export-html/index.js.map +1 -1
- package/dist/core/export-html/template.css +69 -4
- package/dist/core/export-html/template.js +231 -57
- package/dist/core/export-html/tool-renderer.d.ts +0 -6
- package/dist/core/export-html/tool-renderer.d.ts.map +1 -1
- package/dist/core/export-html/tool-renderer.js +15 -2
- package/dist/core/export-html/tool-renderer.js.map +1 -1
- package/dist/core/export-html/vendor/marked.min.js +75 -3
- package/dist/core/extensions/index.d.ts +8 -8
- 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 +5 -6
- package/dist/core/extensions/loader.d.ts.map +1 -1
- package/dist/core/extensions/loader.js +98 -43
- package/dist/core/extensions/loader.js.map +1 -1
- package/dist/core/extensions/runner.d.ts +31 -12
- package/dist/core/extensions/runner.d.ts.map +1 -1
- package/dist/core/extensions/runner.js +248 -33
- package/dist/core/extensions/runner.js.map +1 -1
- package/dist/core/extensions/types.d.ts +191 -36
- 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 +2 -2
- package/dist/core/extensions/wrapper.js.map +1 -1
- package/dist/core/footer-data-provider.d.ts +7 -1
- package/dist/core/footer-data-provider.d.ts.map +1 -1
- package/dist/core/footer-data-provider.js +78 -54
- package/dist/core/footer-data-provider.js.map +1 -1
- package/dist/core/http-dispatcher.d.ts +22 -0
- package/dist/core/http-dispatcher.d.ts.map +1 -0
- package/dist/core/http-dispatcher.js +91 -0
- package/dist/core/http-dispatcher.js.map +1 -0
- package/dist/core/index.d.ts +9 -8
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/index.js +2 -1
- package/dist/core/index.js.map +1 -1
- package/dist/core/keybindings.d.ts +67 -2
- package/dist/core/keybindings.d.ts.map +1 -1
- package/dist/core/keybindings.js +59 -7
- package/dist/core/keybindings.js.map +1 -1
- package/dist/core/model-registry.d.ts +24 -5
- package/dist/core/model-registry.d.ts.map +1 -1
- package/dist/core/model-registry.js +188 -51
- package/dist/core/model-registry.js.map +1 -1
- package/dist/core/model-resolver.d.ts +12 -1
- package/dist/core/model-resolver.d.ts.map +1 -1
- package/dist/core/model-resolver.js +84 -39
- package/dist/core/model-resolver.js.map +1 -1
- package/dist/core/output-guard.d.ts +1 -0
- package/dist/core/output-guard.d.ts.map +1 -1
- package/dist/core/output-guard.js +52 -22
- package/dist/core/output-guard.js.map +1 -1
- package/dist/core/package-manager.d.ts +22 -4
- package/dist/core/package-manager.d.ts.map +1 -1
- package/dist/core/package-manager.js +455 -157
- package/dist/core/package-manager.js.map +1 -1
- package/dist/core/project-trust.d.ts +15 -0
- package/dist/core/project-trust.d.ts.map +1 -0
- package/dist/core/project-trust.js +59 -0
- package/dist/core/project-trust.js.map +1 -0
- package/dist/core/prompt-templates.d.ts +13 -11
- package/dist/core/prompt-templates.d.ts.map +1 -1
- package/dist/core/prompt-templates.js +67 -76
- package/dist/core/prompt-templates.js.map +1 -1
- package/dist/core/provider-attribution.d.ts +4 -0
- package/dist/core/provider-attribution.d.ts.map +1 -0
- package/dist/core/provider-attribution.js +72 -0
- package/dist/core/provider-attribution.js.map +1 -0
- package/dist/core/provider-display-names.d.ts +2 -0
- package/dist/core/provider-display-names.d.ts.map +1 -0
- package/dist/core/provider-display-names.js +36 -0
- package/dist/core/provider-display-names.js.map +1 -0
- package/dist/core/resolve-config-value.d.ts +13 -6
- package/dist/core/resolve-config-value.d.ts.map +1 -1
- package/dist/core/resolve-config-value.js +143 -22
- package/dist/core/resolve-config-value.js.map +1 -1
- package/dist/core/resource-loader.d.ts +36 -15
- package/dist/core/resource-loader.d.ts.map +1 -1
- package/dist/core/resource-loader.js +178 -79
- package/dist/core/resource-loader.js.map +1 -1
- package/dist/core/sdk.d.ts +34 -18
- package/dist/core/sdk.d.ts.map +1 -1
- package/dist/core/sdk.js +47 -16
- package/dist/core/sdk.js.map +1 -1
- package/dist/core/session-manager.d.ts +32 -14
- package/dist/core/session-manager.d.ts.map +1 -1
- package/dist/core/session-manager.js +366 -209
- package/dist/core/session-manager.js.map +1 -1
- package/dist/core/settings-manager.d.ts +62 -6
- package/dist/core/settings-manager.d.ts.map +1 -1
- package/dist/core/settings-manager.js +230 -40
- package/dist/core/settings-manager.js.map +1 -1
- package/dist/core/skills.d.ts +10 -10
- package/dist/core/skills.d.ts.map +1 -1
- package/dist/core/skills.js +13 -35
- package/dist/core/skills.js.map +1 -1
- package/dist/core/slash-commands.d.ts +1 -1
- package/dist/core/slash-commands.d.ts.map +1 -1
- package/dist/core/slash-commands.js +7 -4
- package/dist/core/slash-commands.js.map +1 -1
- package/dist/core/source-info.d.ts +1 -1
- package/dist/core/source-info.d.ts.map +1 -1
- package/dist/core/source-info.js.map +1 -1
- package/dist/core/system-prompt.d.ts +4 -4
- package/dist/core/system-prompt.d.ts.map +1 -1
- package/dist/core/system-prompt.js +20 -16
- package/dist/core/system-prompt.js.map +1 -1
- package/dist/core/telemetry.d.ts +3 -0
- package/dist/core/telemetry.d.ts.map +1 -0
- package/dist/core/telemetry.js +9 -0
- package/dist/core/telemetry.js.map +1 -0
- package/dist/core/timings.d.ts +4 -2
- package/dist/core/timings.d.ts.map +1 -1
- package/dist/core/timings.js +24 -14
- package/dist/core/timings.js.map +1 -1
- package/dist/core/tools/bash.d.ts +11 -16
- package/dist/core/tools/bash.d.ts.map +1 -1
- package/dist/core/tools/bash.js +187 -178
- package/dist/core/tools/bash.js.map +1 -1
- package/dist/core/tools/edit-diff.d.ts +26 -5
- package/dist/core/tools/edit-diff.d.ts.map +1 -1
- package/dist/core/tools/edit-diff.js +110 -23
- package/dist/core/tools/edit-diff.js.map +1 -1
- package/dist/core/tools/edit.d.ts +22 -24
- package/dist/core/tools/edit.d.ts.map +1 -1
- package/dist/core/tools/edit.js +201 -113
- package/dist/core/tools/edit.js.map +1 -1
- package/dist/core/tools/file-mutation-queue.d.ts.map +1 -1
- package/dist/core/tools/file-mutation-queue.js +27 -12
- package/dist/core/tools/file-mutation-queue.js.map +1 -1
- package/dist/core/tools/find.d.ts +7 -18
- package/dist/core/tools/find.d.ts.map +1 -1
- package/dist/core/tools/find.js +148 -101
- package/dist/core/tools/find.js.map +1 -1
- package/dist/core/tools/grep.d.ts +11 -30
- package/dist/core/tools/grep.d.ts.map +1 -1
- package/dist/core/tools/grep.js +23 -12
- package/dist/core/tools/grep.js.map +1 -1
- package/dist/core/tools/index.d.ts +26 -101
- package/dist/core/tools/index.d.ts.map +1 -1
- package/dist/core/tools/index.js +78 -52
- package/dist/core/tools/index.js.map +1 -1
- package/dist/core/tools/ls.d.ts +6 -15
- package/dist/core/tools/ls.d.ts.map +1 -1
- package/dist/core/tools/ls.js +12 -17
- package/dist/core/tools/ls.js.map +1 -1
- package/dist/core/tools/output-accumulator.d.ts +52 -0
- package/dist/core/tools/output-accumulator.d.ts.map +1 -0
- package/dist/core/tools/output-accumulator.js +184 -0
- package/dist/core/tools/output-accumulator.js.map +1 -0
- package/dist/core/tools/path-utils.d.ts +2 -0
- package/dist/core/tools/path-utils.d.ts.map +1 -1
- package/dist/core/tools/path-utils.js +40 -22
- package/dist/core/tools/path-utils.js.map +1 -1
- package/dist/core/tools/read.d.ts +7 -18
- package/dist/core/tools/read.d.ts.map +1 -1
- package/dist/core/tools/read.js +103 -52
- package/dist/core/tools/read.js.map +1 -1
- package/dist/core/tools/render-utils.d.ts +5 -2
- package/dist/core/tools/render-utils.d.ts.map +1 -1
- package/dist/core/tools/render-utils.js +18 -2
- package/dist/core/tools/render-utils.js.map +1 -1
- package/dist/core/tools/tool-definition-wrapper.d.ts.map +1 -1
- package/dist/core/tools/tool-definition-wrapper.js +2 -0
- package/dist/core/tools/tool-definition-wrapper.js.map +1 -1
- package/dist/core/tools/truncate.d.ts.map +1 -1
- package/dist/core/tools/truncate.js +12 -2
- package/dist/core/tools/truncate.js.map +1 -1
- package/dist/core/tools/write.d.ts +5 -14
- package/dist/core/tools/write.d.ts.map +1 -1
- package/dist/core/tools/write.js +27 -46
- package/dist/core/tools/write.js.map +1 -1
- package/dist/core/trust-manager.d.ts +36 -0
- package/dist/core/trust-manager.d.ts.map +1 -0
- package/dist/core/trust-manager.js +202 -0
- package/dist/core/trust-manager.js.map +1 -0
- package/dist/index.d.ts +33 -29
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +12 -9
- package/dist/index.js.map +1 -1
- package/dist/main.d.ts +5 -1
- package/dist/main.d.ts.map +1 -1
- package/dist/main.js +208 -93
- package/dist/main.js.map +1 -1
- package/dist/migrations.d.ts +2 -2
- package/dist/migrations.d.ts.map +1 -1
- package/dist/migrations.js +4 -4
- package/dist/migrations.js.map +1 -1
- package/dist/modes/index.d.ts +5 -5
- package/dist/modes/index.d.ts.map +1 -1
- package/dist/modes/index.js.map +1 -1
- package/dist/modes/interactive/assets/clankolas.png +0 -0
- package/dist/modes/interactive/components/assistant-message.d.ts +5 -1
- package/dist/modes/interactive/components/assistant-message.d.ts.map +1 -1
- package/dist/modes/interactive/components/assistant-message.js +37 -15
- package/dist/modes/interactive/components/assistant-message.js.map +1 -1
- package/dist/modes/interactive/components/bash-execution.d.ts +1 -1
- package/dist/modes/interactive/components/bash-execution.d.ts.map +1 -1
- package/dist/modes/interactive/components/bash-execution.js +3 -3
- package/dist/modes/interactive/components/bash-execution.js.map +1 -1
- package/dist/modes/interactive/components/bordered-loader.d.ts.map +1 -1
- package/dist/modes/interactive/components/bordered-loader.js +3 -0
- package/dist/modes/interactive/components/bordered-loader.js.map +1 -1
- package/dist/modes/interactive/components/config-selector.d.ts +36 -5
- package/dist/modes/interactive/components/config-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/config-selector.js +318 -36
- package/dist/modes/interactive/components/config-selector.js.map +1 -1
- package/dist/modes/interactive/components/countdown-timer.d.ts +2 -2
- package/dist/modes/interactive/components/countdown-timer.d.ts.map +1 -1
- package/dist/modes/interactive/components/countdown-timer.js +2 -2
- package/dist/modes/interactive/components/countdown-timer.js.map +1 -1
- package/dist/modes/interactive/components/custom-editor.d.ts +1 -1
- package/dist/modes/interactive/components/custom-editor.d.ts.map +1 -1
- package/dist/modes/interactive/components/custom-editor.js.map +1 -1
- package/dist/modes/interactive/components/custom-entry.d.ts +19 -0
- package/dist/modes/interactive/components/custom-entry.d.ts.map +1 -0
- package/dist/modes/interactive/components/custom-entry.js +52 -0
- package/dist/modes/interactive/components/custom-entry.js.map +1 -0
- package/dist/modes/interactive/components/custom-message.d.ts +2 -2
- package/dist/modes/interactive/components/custom-message.d.ts.map +1 -1
- package/dist/modes/interactive/components/custom-message.js.map +1 -1
- package/dist/modes/interactive/components/diff.d.ts.map +1 -1
- package/dist/modes/interactive/components/diff.js.map +1 -1
- package/dist/modes/interactive/components/earendil-announcement.d.ts.map +1 -1
- package/dist/modes/interactive/components/earendil-announcement.js.map +1 -1
- package/dist/modes/interactive/components/extension-editor.d.ts +3 -1
- package/dist/modes/interactive/components/extension-editor.d.ts.map +1 -1
- package/dist/modes/interactive/components/extension-editor.js +26 -9
- package/dist/modes/interactive/components/extension-editor.js.map +1 -1
- package/dist/modes/interactive/components/extension-input.d.ts.map +1 -1
- package/dist/modes/interactive/components/extension-input.js.map +1 -1
- package/dist/modes/interactive/components/extension-selector.d.ts +2 -0
- package/dist/modes/interactive/components/extension-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/extension-selector.js +8 -3
- package/dist/modes/interactive/components/extension-selector.js.map +1 -1
- package/dist/modes/interactive/components/first-time-setup.d.ts +25 -0
- package/dist/modes/interactive/components/first-time-setup.d.ts.map +1 -0
- package/dist/modes/interactive/components/first-time-setup.js +103 -0
- package/dist/modes/interactive/components/first-time-setup.js.map +1 -0
- package/dist/modes/interactive/components/footer.d.ts +4 -3
- package/dist/modes/interactive/components/footer.d.ts.map +1 -1
- package/dist/modes/interactive/components/footer.js +27 -7
- package/dist/modes/interactive/components/footer.js.map +1 -1
- package/dist/modes/interactive/components/index.d.ts +33 -31
- package/dist/modes/interactive/components/index.d.ts.map +1 -1
- package/dist/modes/interactive/components/index.js +2 -0
- package/dist/modes/interactive/components/index.js.map +1 -1
- package/dist/modes/interactive/components/keybinding-hints.d.ts +5 -0
- package/dist/modes/interactive/components/keybinding-hints.d.ts.map +1 -1
- package/dist/modes/interactive/components/keybinding-hints.js +19 -5
- package/dist/modes/interactive/components/keybinding-hints.js.map +1 -1
- package/dist/modes/interactive/components/login-dialog.d.ts +12 -2
- package/dist/modes/interactive/components/login-dialog.d.ts.map +1 -1
- package/dist/modes/interactive/components/login-dialog.js +45 -11
- package/dist/modes/interactive/components/login-dialog.js.map +1 -1
- package/dist/modes/interactive/components/model-selector.d.ts +2 -2
- package/dist/modes/interactive/components/model-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/model-selector.js +10 -6
- package/dist/modes/interactive/components/model-selector.js.map +1 -1
- package/dist/modes/interactive/components/oauth-selector.d.ts +18 -6
- package/dist/modes/interactive/components/oauth-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/oauth-selector.js +93 -25
- package/dist/modes/interactive/components/oauth-selector.js.map +1 -1
- package/dist/modes/interactive/components/scoped-models-selector.d.ts +5 -12
- package/dist/modes/interactive/components/scoped-models-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/scoped-models-selector.js +49 -31
- package/dist/modes/interactive/components/scoped-models-selector.js.map +1 -1
- package/dist/modes/interactive/components/session-selector.d.ts +2 -2
- package/dist/modes/interactive/components/session-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/session-selector.js +33 -14
- package/dist/modes/interactive/components/session-selector.js.map +1 -1
- package/dist/modes/interactive/components/settings-selector.d.ts +17 -0
- package/dist/modes/interactive/components/settings-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/settings-selector.js +301 -20
- package/dist/modes/interactive/components/settings-selector.js.map +1 -1
- package/dist/modes/interactive/components/skill-invocation-message.d.ts +1 -1
- package/dist/modes/interactive/components/skill-invocation-message.d.ts.map +1 -1
- package/dist/modes/interactive/components/skill-invocation-message.js.map +1 -1
- package/dist/modes/interactive/components/status-indicator.d.ts +28 -0
- package/dist/modes/interactive/components/status-indicator.d.ts.map +1 -0
- package/dist/modes/interactive/components/status-indicator.js +60 -0
- package/dist/modes/interactive/components/status-indicator.js.map +1 -0
- package/dist/modes/interactive/components/thinking-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/thinking-selector.js +1 -1
- package/dist/modes/interactive/components/thinking-selector.js.map +1 -1
- package/dist/modes/interactive/components/tool-execution.d.ts +6 -1
- package/dist/modes/interactive/components/tool-execution.d.ts.map +1 -1
- package/dist/modes/interactive/components/tool-execution.js +57 -14
- package/dist/modes/interactive/components/tool-execution.js.map +1 -1
- package/dist/modes/interactive/components/tree-selector.d.ts +1 -1
- package/dist/modes/interactive/components/tree-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/tree-selector.js +137 -13
- package/dist/modes/interactive/components/tree-selector.js.map +1 -1
- package/dist/modes/interactive/components/trust-selector.d.ts +23 -0
- package/dist/modes/interactive/components/trust-selector.d.ts.map +1 -0
- package/dist/modes/interactive/components/trust-selector.js +91 -0
- package/dist/modes/interactive/components/trust-selector.js.map +1 -0
- package/dist/modes/interactive/components/user-message-selector.d.ts +2 -2
- package/dist/modes/interactive/components/user-message-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/user-message-selector.js +8 -7
- package/dist/modes/interactive/components/user-message-selector.js.map +1 -1
- package/dist/modes/interactive/components/user-message.d.ts +6 -1
- package/dist/modes/interactive/components/user-message.d.ts.map +1 -1
- package/dist/modes/interactive/components/user-message.js +22 -8
- package/dist/modes/interactive/components/user-message.js.map +1 -1
- package/dist/modes/interactive/interactive-mode.d.ts +76 -19
- package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode.js +1294 -494
- package/dist/modes/interactive/interactive-mode.js.map +1 -1
- package/dist/modes/interactive/model-search.d.ts +12 -0
- package/dist/modes/interactive/model-search.d.ts.map +1 -0
- package/dist/modes/interactive/model-search.js +15 -0
- package/dist/modes/interactive/model-search.js.map +1 -0
- package/dist/modes/interactive/theme/dark.json +5 -4
- package/dist/modes/interactive/theme/light.json +5 -4
- package/dist/modes/interactive/theme/theme-controller.d.ts +29 -0
- package/dist/modes/interactive/theme/theme-controller.d.ts.map +1 -0
- package/dist/modes/interactive/theme/theme-controller.js +102 -0
- package/dist/modes/interactive/theme/theme-controller.js.map +1 -0
- package/dist/modes/interactive/theme/theme-schema.json +2 -1
- package/dist/modes/interactive/theme/theme.d.ts +41 -3
- package/dist/modes/interactive/theme/theme.d.ts.map +1 -1
- package/dist/modes/interactive/theme/theme.js +183 -106
- package/dist/modes/interactive/theme/theme.js.map +1 -1
- package/dist/modes/print-mode.d.ts.map +1 -1
- package/dist/modes/print-mode.js +40 -20
- package/dist/modes/print-mode.js.map +1 -1
- package/dist/modes/rpc/rpc-client.d.ts +30 -5
- package/dist/modes/rpc/rpc-client.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-client.js +87 -8
- package/dist/modes/rpc/rpc-client.js.map +1 -1
- package/dist/modes/rpc/rpc-mode.d.ts +2 -2
- package/dist/modes/rpc/rpc-mode.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-mode.js +113 -31
- package/dist/modes/rpc/rpc-mode.js.map +1 -1
- package/dist/modes/rpc/rpc-types.d.ts +42 -4
- 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 +6 -2
- package/dist/package-manager-cli.d.ts.map +1 -1
- package/dist/package-manager-cli.js +504 -25
- package/dist/package-manager-cli.js.map +1 -1
- package/dist/prompts/commands/brainstorm.md +148 -0
- package/dist/prompts/commands/map-codebase.md +14 -0
- package/dist/rpc-entry.d.ts +3 -0
- package/dist/rpc-entry.d.ts.map +1 -0
- package/dist/rpc-entry.js +10 -0
- package/dist/rpc-entry.js.map +1 -0
- package/dist/utils/ansi.d.ts +2 -0
- package/dist/utils/ansi.d.ts.map +1 -0
- package/dist/utils/ansi.js +52 -0
- package/dist/utils/ansi.js.map +1 -0
- package/dist/utils/changelog.d.ts +2 -1
- package/dist/utils/changelog.d.ts.map +1 -1
- package/dist/utils/changelog.js +78 -0
- package/dist/utils/changelog.js.map +1 -1
- package/dist/utils/child-process.d.ts +12 -5
- package/dist/utils/child-process.d.ts.map +1 -1
- package/dist/utils/child-process.js +33 -5
- package/dist/utils/child-process.js.map +1 -1
- package/dist/utils/clipboard-image.d.ts.map +1 -1
- package/dist/utils/clipboard-image.js +2 -2
- package/dist/utils/clipboard-image.js.map +1 -1
- package/dist/utils/clipboard-native.d.ts +3 -1
- package/dist/utils/clipboard-native.d.ts.map +1 -1
- package/dist/utils/clipboard-native.js +14 -8
- package/dist/utils/clipboard-native.js.map +1 -1
- package/dist/utils/clipboard.d.ts.map +1 -1
- package/dist/utils/clipboard.js +84 -45
- package/dist/utils/clipboard.js.map +1 -1
- package/dist/utils/deprecation.d.ts +4 -0
- package/dist/utils/deprecation.d.ts.map +1 -0
- package/dist/utils/deprecation.js +13 -0
- package/dist/utils/deprecation.js.map +1 -0
- package/dist/utils/exif-orientation.d.ts +1 -1
- package/dist/utils/exif-orientation.d.ts.map +1 -1
- package/dist/utils/exif-orientation.js.map +1 -1
- package/dist/utils/fs-watch.d.ts +5 -0
- package/dist/utils/fs-watch.d.ts.map +1 -0
- package/dist/utils/fs-watch.js +25 -0
- package/dist/utils/fs-watch.js.map +1 -0
- package/dist/utils/git.d.ts.map +1 -1
- package/dist/utils/git.js +54 -22
- package/dist/utils/git.js.map +1 -1
- package/dist/utils/html.d.ts +7 -0
- package/dist/utils/html.d.ts.map +1 -0
- package/dist/utils/html.js +40 -0
- package/dist/utils/html.js.map +1 -0
- package/dist/utils/image-convert.d.ts +1 -0
- package/dist/utils/image-convert.d.ts.map +1 -1
- package/dist/utils/image-convert.js +21 -15
- package/dist/utils/image-convert.js.map +1 -1
- package/dist/utils/image-process.d.ts +18 -0
- package/dist/utils/image-process.d.ts.map +1 -0
- package/dist/utils/image-process.js +83 -0
- package/dist/utils/image-process.js.map +1 -0
- package/dist/utils/image-resize-core.d.ts +30 -0
- package/dist/utils/image-resize-core.d.ts.map +1 -0
- package/dist/utils/image-resize-core.js +124 -0
- package/dist/utils/image-resize-core.js.map +1 -0
- package/dist/utils/image-resize-worker.d.ts +2 -0
- package/dist/utils/image-resize-worker.d.ts.map +1 -0
- package/dist/utils/image-resize-worker.js +31 -0
- package/dist/utils/image-resize-worker.js.map +1 -0
- package/dist/utils/image-resize.d.ts +7 -27
- package/dist/utils/image-resize.d.ts.map +1 -1
- package/dist/utils/image-resize.js +75 -115
- package/dist/utils/image-resize.js.map +1 -1
- package/dist/utils/json.d.ts +3 -0
- package/dist/utils/json.d.ts.map +1 -0
- package/dist/utils/json.js +7 -0
- package/dist/utils/json.js.map +1 -0
- package/dist/utils/mime.d.ts +1 -0
- package/dist/utils/mime.d.ts.map +1 -1
- package/dist/utils/mime.js +100 -16
- package/dist/utils/mime.js.map +1 -1
- package/dist/utils/open-browser.d.ts +9 -0
- package/dist/utils/open-browser.d.ts.map +1 -0
- package/dist/utils/open-browser.js +22 -0
- package/dist/utils/open-browser.js.map +1 -0
- package/dist/utils/paths.d.ts +25 -1
- package/dist/utils/paths.d.ts.map +1 -1
- package/dist/utils/paths.js +75 -2
- package/dist/utils/paths.js.map +1 -1
- package/dist/utils/pi-user-agent.d.ts +2 -0
- package/dist/utils/pi-user-agent.d.ts.map +1 -0
- package/dist/utils/pi-user-agent.js +5 -0
- package/dist/utils/pi-user-agent.js.map +1 -0
- package/dist/utils/shell.d.ts +11 -6
- package/dist/utils/shell.d.ts.map +1 -1
- package/dist/utils/shell.js +42 -26
- package/dist/utils/shell.js.map +1 -1
- package/dist/utils/syntax-highlight.d.ts +12 -0
- package/dist/utils/syntax-highlight.d.ts.map +1 -0
- package/dist/utils/syntax-highlight.js +118 -0
- package/dist/utils/syntax-highlight.js.map +1 -0
- package/dist/utils/tools-manager.d.ts.map +1 -1
- package/dist/utils/tools-manager.js +86 -10
- package/dist/utils/tools-manager.js.map +1 -1
- package/dist/utils/version-check.d.ts +15 -0
- package/dist/utils/version-check.d.ts.map +1 -0
- package/dist/utils/version-check.js +59 -0
- package/dist/utils/version-check.js.map +1 -0
- package/dist/utils/windows-self-update.d.ts +3 -0
- package/dist/utils/windows-self-update.d.ts.map +1 -0
- package/dist/utils/windows-self-update.js +77 -0
- package/dist/utils/windows-self-update.js.map +1 -0
- package/docs/compaction.md +12 -12
- package/docs/containerization.md +111 -0
- package/docs/custom-provider.md +187 -47
- package/docs/development.md +5 -5
- package/docs/docs.json +156 -0
- package/docs/extensions.md +520 -79
- package/docs/index.md +82 -0
- package/docs/json.md +4 -4
- package/docs/keybindings.md +24 -2
- package/docs/models.md +119 -17
- package/docs/packages.md +19 -11
- package/docs/prompt-templates.md +30 -2
- package/docs/providers.md +85 -23
- package/docs/quickstart.md +165 -0
- package/docs/rpc.md +99 -10
- package/docs/sdk.md +118 -50
- package/docs/security.md +55 -0
- package/docs/{session.md → session-format.md} +29 -19
- package/docs/sessions.md +145 -0
- package/docs/settings.md +71 -11
- package/docs/skills.md +16 -17
- package/docs/terminal-setup.md +44 -2
- package/docs/termux.md +4 -4
- package/docs/themes.md +3 -3
- package/docs/tmux.md +4 -2
- package/docs/tui.md +44 -4
- package/docs/usage.md +305 -0
- package/examples/extensions/README.md +1 -0
- package/examples/extensions/border-status-editor.ts +145 -0
- package/examples/extensions/built-in-tool-renderer.ts +3 -0
- package/examples/extensions/custom-compaction.ts +2 -1
- package/examples/extensions/custom-header.ts +1 -1
- package/examples/extensions/custom-provider-anthropic/index.ts +2 -2
- package/examples/extensions/custom-provider-anthropic/package-lock.json +2 -2
- package/examples/extensions/custom-provider-anthropic/package.json +2 -2
- package/examples/extensions/custom-provider-gitlab-duo/index.ts +63 -8
- package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
- package/examples/extensions/custom-provider-gitlab-duo/test.ts +2 -2
- package/examples/extensions/doom-overlay/doom-component.ts +2 -2
- package/examples/extensions/doom-overlay/index.ts +1 -1
- package/examples/extensions/dynamic-resources/dynamic.json +1 -1
- package/examples/extensions/dynamic-tools.ts +2 -2
- package/examples/extensions/entry-renderer.ts +41 -0
- package/examples/extensions/git-merge-and-resolve.ts +115 -0
- package/examples/extensions/github-issue-autocomplete.ts +185 -0
- package/examples/extensions/gondolin/index.ts +531 -0
- package/examples/extensions/gondolin/package-lock.json +185 -0
- package/examples/extensions/gondolin/package.json +19 -0
- package/examples/extensions/handoff.ts +52 -14
- package/examples/extensions/input-transform-streaming.ts +39 -0
- package/examples/extensions/interactive-shell.ts +1 -1
- package/examples/extensions/notify.ts +2 -9
- package/examples/extensions/overlay-qa-tests.ts +240 -138
- package/examples/extensions/overlay-test.ts +7 -4
- package/examples/extensions/plan-mode/index.ts +87 -37
- package/examples/extensions/plan-mode/utils.ts +1 -1
- package/examples/extensions/preset.ts +46 -7
- package/examples/extensions/project-trust.ts +64 -0
- package/examples/extensions/prompt-customizer.ts +97 -0
- package/examples/extensions/provider-payload.ts +8 -4
- package/examples/extensions/qna.ts +3 -3
- package/examples/extensions/question.ts +34 -20
- package/examples/extensions/questionnaire.ts +43 -30
- package/examples/extensions/reload-runtime.ts +1 -1
- package/examples/extensions/sandbox/index.ts +6 -6
- package/examples/extensions/sandbox/package-lock.json +5 -5
- package/examples/extensions/sandbox/package.json +2 -2
- package/examples/extensions/shutdown-command.ts +1 -1
- package/examples/extensions/snake.ts +1 -1
- package/examples/extensions/space-invaders.ts +1 -1
- package/examples/extensions/structured-output.ts +65 -0
- package/examples/extensions/subagent/agents.ts +2 -2
- package/examples/extensions/subagent/index.ts +58 -29
- package/examples/extensions/summarize.ts +3 -2
- package/examples/extensions/tic-tac-toe.ts +1008 -0
- package/examples/extensions/titlebar-spinner.ts +2 -2
- package/examples/extensions/todo.ts +2 -2
- package/examples/extensions/tool-override.ts +1 -1
- package/examples/extensions/tools.ts +5 -0
- package/examples/extensions/truncated-tool.ts +1 -1
- package/examples/extensions/with-deps/index.ts +1 -1
- package/examples/extensions/with-deps/package-lock.json +2 -2
- package/examples/extensions/with-deps/package.json +3 -3
- package/examples/extensions/working-indicator.ts +123 -0
- package/examples/extensions/working-message-test.ts +25 -0
- package/examples/sdk/01-minimal.ts +14 -10
- package/examples/sdk/02-custom-model.ts +13 -9
- package/examples/sdk/03-custom-prompt.ts +32 -17
- package/examples/sdk/04-skills.ts +5 -2
- package/examples/sdk/05-tools.ts +23 -31
- package/examples/sdk/06-extensions.ts +14 -8
- package/examples/sdk/07-context-files.ts +5 -3
- package/examples/sdk/08-prompt-templates.ts +5 -2
- package/examples/sdk/09-api-keys-and-oauth.ts +8 -4
- package/examples/sdk/10-settings.ts +8 -6
- package/examples/sdk/11-sessions.ts +4 -0
- package/examples/sdk/12-full-control.ts +15 -19
- package/package.json +22 -16
- package/prompts/commands/brainstorm.md +148 -0
- package/prompts/commands/map-codebase.md +14 -0
|
@@ -6,23 +6,34 @@ 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 {
|
|
9
|
+
import { getProviders, } from "@draht/ai/compat";
|
|
10
|
+
import { CombinedAutocompleteProvider, Container, fuzzyFilter, getCapabilities, hyperlink, Markdown, matchesKey, ProcessTerminal, Spacer, setKeybindings, Text, TruncatedText, TUI, visibleWidth, } from "@draht/tui";
|
|
11
|
+
import chalk from "chalk";
|
|
10
12
|
import { spawn, spawnSync } from "child_process";
|
|
11
|
-
import { APP_NAME, getAgentDir, getAuthPath, getDebugLogPath,
|
|
13
|
+
import { APP_NAME, APP_TITLE, CONFIG_DIR_NAME, DISPLAY_VERSION, getAgentDir, getAuthPath, getDebugLogPath, getDocsPath, getShareViewerUrl, VERSION, } from "../../config.js";
|
|
12
14
|
import { parseSkillBlock } from "../../core/agent-session.js";
|
|
15
|
+
import { SessionImportFileNotFoundError } from "../../core/agent-session-runtime.js";
|
|
13
16
|
import { FooterDataProvider } from "../../core/footer-data-provider.js";
|
|
17
|
+
import { configureHttpDispatcher, formatHttpIdleTimeoutMs } from "../../core/http-dispatcher.js";
|
|
14
18
|
import { KeybindingsManager } from "../../core/keybindings.js";
|
|
15
19
|
import { createCompactionSummaryMessage } from "../../core/messages.js";
|
|
16
|
-
import { findExactModelReferenceMatch, resolveModelScope } from "../../core/model-resolver.js";
|
|
20
|
+
import { defaultModelPerProvider, findExactModelReferenceMatch, resolveModelScope } from "../../core/model-resolver.js";
|
|
17
21
|
import { DefaultPackageManager } from "../../core/package-manager.js";
|
|
22
|
+
import { BUILT_IN_PROVIDER_DISPLAY_NAMES } from "../../core/provider-display-names.js";
|
|
18
23
|
import { formatMissingSessionCwdPrompt, MissingSessionCwdError } from "../../core/session-cwd.js";
|
|
19
|
-
import { SessionManager } from "../../core/session-manager.js";
|
|
24
|
+
import { SessionManager, sessionEntryToContextMessages } from "../../core/session-manager.js";
|
|
20
25
|
import { BUILTIN_SLASH_COMMANDS } from "../../core/slash-commands.js";
|
|
21
|
-
import {
|
|
26
|
+
import { isInstallTelemetryEnabled } from "../../core/telemetry.js";
|
|
27
|
+
import { hasTrustRequiringProjectResources, ProjectTrustStore } from "../../core/trust-manager.js";
|
|
28
|
+
import { getChangelogPath, getNewEntries, normalizeChangelogLinks, parseChangelog } from "../../utils/changelog.js";
|
|
22
29
|
import { copyToClipboard } from "../../utils/clipboard.js";
|
|
23
30
|
import { extensionForImageMimeType, readClipboardImage } from "../../utils/clipboard-image.js";
|
|
24
31
|
import { parseGitUrl } from "../../utils/git.js";
|
|
32
|
+
import { getCwdRelativePath } from "../../utils/paths.js";
|
|
33
|
+
import { getPiUserAgent } from "../../utils/pi-user-agent.js";
|
|
34
|
+
import { killTrackedDetachedChildren } from "../../utils/shell.js";
|
|
25
35
|
import { ensureTool } from "../../utils/tools-manager.js";
|
|
36
|
+
import { checkForNewPiVersion } from "../../utils/version-check.js";
|
|
26
37
|
import { ArminComponent } from "./components/armin.js";
|
|
27
38
|
import { AssistantMessageComponent } from "./components/assistant-message.js";
|
|
28
39
|
import { BashExecutionComponent } from "./components/bash-execution.js";
|
|
@@ -30,6 +41,7 @@ import { BorderedLoader } from "./components/bordered-loader.js";
|
|
|
30
41
|
import { BranchSummaryMessageComponent } from "./components/branch-summary-message.js";
|
|
31
42
|
import { CompactionSummaryMessageComponent } from "./components/compaction-summary-message.js";
|
|
32
43
|
import { CustomEditor } from "./components/custom-editor.js";
|
|
44
|
+
import { CustomEntryComponent } from "./components/custom-entry.js";
|
|
33
45
|
import { CustomMessageComponent } from "./components/custom-message.js";
|
|
34
46
|
import { DaxnutsComponent } from "./components/daxnuts.js";
|
|
35
47
|
import { DynamicBorder } from "./components/dynamic-border.js";
|
|
@@ -38,7 +50,7 @@ import { ExtensionEditorComponent } from "./components/extension-editor.js";
|
|
|
38
50
|
import { ExtensionInputComponent } from "./components/extension-input.js";
|
|
39
51
|
import { ExtensionSelectorComponent } from "./components/extension-selector.js";
|
|
40
52
|
import { FooterComponent } from "./components/footer.js";
|
|
41
|
-
import { keyHint, keyText, rawKeyHint } from "./components/keybinding-hints.js";
|
|
53
|
+
import { formatKeyText, keyDisplayText, keyHint, keyText, rawKeyHint } from "./components/keybinding-hints.js";
|
|
42
54
|
import { LoginDialogComponent } from "./components/login-dialog.js";
|
|
43
55
|
import { ModelSelectorComponent } from "./components/model-selector.js";
|
|
44
56
|
import { OAuthSelectorComponent } from "./components/oauth-selector.js";
|
|
@@ -46,28 +58,95 @@ import { ScopedModelsSelectorComponent } from "./components/scoped-models-select
|
|
|
46
58
|
import { SessionSelectorComponent } from "./components/session-selector.js";
|
|
47
59
|
import { SettingsSelectorComponent } from "./components/settings-selector.js";
|
|
48
60
|
import { SkillInvocationMessageComponent } from "./components/skill-invocation-message.js";
|
|
61
|
+
import { BranchSummaryStatusIndicator, CompactionStatusIndicator, IdleStatus, RetryStatusIndicator, WorkingStatusIndicator, } from "./components/status-indicator.js";
|
|
49
62
|
import { ToolExecutionComponent } from "./components/tool-execution.js";
|
|
50
63
|
import { TreeSelectorComponent } from "./components/tree-selector.js";
|
|
64
|
+
import { TrustSelectorComponent } from "./components/trust-selector.js";
|
|
51
65
|
import { UserMessageComponent } from "./components/user-message.js";
|
|
52
66
|
import { UserMessageSelectorComponent } from "./components/user-message-selector.js";
|
|
53
|
-
import {
|
|
67
|
+
import { getModelSearchText } from "./model-search.js";
|
|
68
|
+
import { getAvailableThemes, getAvailableThemesWithPaths, getEditorTheme, getMarkdownTheme, getThemeByName, onThemeChange, setRegisteredThemes, stopThemeWatcher, Theme, theme, } from "./theme/theme.js";
|
|
69
|
+
import { InteractiveThemeController } from "./theme/theme-controller.js";
|
|
54
70
|
function isExpandable(obj) {
|
|
55
71
|
return typeof obj === "object" && obj !== null && "setExpanded" in obj && typeof obj.setExpanded === "function";
|
|
56
72
|
}
|
|
57
|
-
|
|
73
|
+
class ExpandableText extends Text {
|
|
74
|
+
getCollapsedText;
|
|
75
|
+
getExpandedText;
|
|
76
|
+
constructor(getCollapsedText, getExpandedText, expanded = false, paddingX = 0, paddingY = 0) {
|
|
77
|
+
super(expanded ? getExpandedText() : getCollapsedText(), paddingX, paddingY);
|
|
78
|
+
this.getCollapsedText = getCollapsedText;
|
|
79
|
+
this.getExpandedText = getExpandedText;
|
|
80
|
+
}
|
|
81
|
+
setExpanded(expanded) {
|
|
82
|
+
this.setText(expanded ? this.getExpandedText() : this.getCollapsedText());
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
function isCustomSessionEntry(item) {
|
|
86
|
+
return "type" in item && item.type === "custom";
|
|
87
|
+
}
|
|
88
|
+
const DEAD_TERMINAL_ERROR_CODES = new Set(["EIO", "EPIPE", "ENOTCONN"]);
|
|
89
|
+
function isDeadTerminalError(error) {
|
|
90
|
+
if (!error || typeof error !== "object" || !("code" in error)) {
|
|
91
|
+
return false;
|
|
92
|
+
}
|
|
93
|
+
const code = error.code;
|
|
94
|
+
return code !== undefined && DEAD_TERMINAL_ERROR_CODES.has(code);
|
|
95
|
+
}
|
|
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.";
|
|
58
97
|
function isAnthropicSubscriptionAuthKey(apiKey) {
|
|
59
98
|
return typeof apiKey === "string" && apiKey.startsWith("sk-ant-oat");
|
|
60
99
|
}
|
|
100
|
+
function isUnknownModel(model) {
|
|
101
|
+
return !!model && model.provider === "unknown" && model.id === "unknown" && model.api === "unknown";
|
|
102
|
+
}
|
|
103
|
+
function quoteIfNeeded(value) {
|
|
104
|
+
if (value.length > 0 && !/[^a-zA-Z0-9_\-./~:@]/.test(value)) {
|
|
105
|
+
return value;
|
|
106
|
+
}
|
|
107
|
+
return `'${value.replace(/'/g, `'\\''`)}'`;
|
|
108
|
+
}
|
|
109
|
+
export function formatResumeCommand(sessionManager) {
|
|
110
|
+
if (!process.stdout.isTTY)
|
|
111
|
+
return undefined;
|
|
112
|
+
if (!sessionManager.isPersisted())
|
|
113
|
+
return undefined;
|
|
114
|
+
const sessionFile = sessionManager.getSessionFile();
|
|
115
|
+
if (!sessionFile || !fs.existsSync(sessionFile))
|
|
116
|
+
return undefined;
|
|
117
|
+
const args = [APP_NAME];
|
|
118
|
+
if (!sessionManager.usesDefaultSessionDir()) {
|
|
119
|
+
args.push("--session-dir", quoteIfNeeded(sessionManager.getSessionDir()));
|
|
120
|
+
}
|
|
121
|
+
args.push("--session", sessionManager.getSessionId());
|
|
122
|
+
return args.join(" ");
|
|
123
|
+
}
|
|
124
|
+
function hasDefaultModelProvider(providerId) {
|
|
125
|
+
return providerId in defaultModelPerProvider;
|
|
126
|
+
}
|
|
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
|
+
}
|
|
61
138
|
export class InteractiveMode {
|
|
62
|
-
options;
|
|
63
139
|
runtimeHost;
|
|
64
140
|
ui;
|
|
141
|
+
loadedResourcesContainer;
|
|
65
142
|
chatContainer;
|
|
66
143
|
pendingMessagesContainer;
|
|
67
144
|
statusContainer;
|
|
68
145
|
defaultEditor;
|
|
69
146
|
editor;
|
|
147
|
+
editorComponentFactory;
|
|
70
148
|
autocompleteProvider;
|
|
149
|
+
autocompleteProviderWrappers = [];
|
|
71
150
|
fdPath;
|
|
72
151
|
editorContainer;
|
|
73
152
|
footer;
|
|
@@ -77,8 +156,12 @@ export class InteractiveMode {
|
|
|
77
156
|
version;
|
|
78
157
|
isInitialized = false;
|
|
79
158
|
onInputCallback;
|
|
80
|
-
|
|
81
|
-
|
|
159
|
+
pendingUserInputs = [];
|
|
160
|
+
activeStatusIndicator = undefined;
|
|
161
|
+
idleStatus = new IdleStatus();
|
|
162
|
+
workingMessage = undefined;
|
|
163
|
+
workingVisible = true;
|
|
164
|
+
workingIndicatorOptions = undefined;
|
|
82
165
|
defaultWorkingMessage = "Working...";
|
|
83
166
|
defaultHiddenThinkingLabel = "Thinking...";
|
|
84
167
|
hiddenThinkingLabel = this.defaultHiddenThinkingLabel;
|
|
@@ -99,10 +182,12 @@ export class InteractiveMode {
|
|
|
99
182
|
toolOutputExpanded = false;
|
|
100
183
|
// Thinking block visibility state
|
|
101
184
|
hideThinkingBlock = false;
|
|
185
|
+
outputPad = 1;
|
|
102
186
|
// Skill commands: command name -> skill file path
|
|
103
187
|
skillCommands = new Map();
|
|
104
188
|
// Agent subscription unsubscribe function
|
|
105
189
|
unsubscribe;
|
|
190
|
+
signalCleanupHandlers = [];
|
|
106
191
|
// Track if editor is in bash mode (text starts with !)
|
|
107
192
|
isBashMode = false;
|
|
108
193
|
// Track current bash execution component
|
|
@@ -110,10 +195,8 @@ export class InteractiveMode {
|
|
|
110
195
|
// Track pending bash components (shown in pending area, moved to chat on submit)
|
|
111
196
|
pendingBashComponents = [];
|
|
112
197
|
// Auto-compaction state
|
|
113
|
-
autoCompactionLoader = undefined;
|
|
114
198
|
autoCompactionEscapeHandler;
|
|
115
199
|
// Auto-retry state
|
|
116
|
-
retryLoader = undefined;
|
|
117
200
|
retryEscapeHandler;
|
|
118
201
|
// Messages queued while compaction is running
|
|
119
202
|
compactionQueuedMessages = [];
|
|
@@ -137,6 +220,9 @@ export class InteractiveMode {
|
|
|
137
220
|
builtInHeader = undefined;
|
|
138
221
|
// Custom header from extension (undefined = use built-in header)
|
|
139
222
|
customHeader = undefined;
|
|
223
|
+
options;
|
|
224
|
+
autoTrustOnReloadCwd;
|
|
225
|
+
themeController;
|
|
140
226
|
// Convenience accessors
|
|
141
227
|
get session() {
|
|
142
228
|
return this.runtimeHost.session;
|
|
@@ -151,12 +237,20 @@ export class InteractiveMode {
|
|
|
151
237
|
return this.session.settingsManager;
|
|
152
238
|
}
|
|
153
239
|
constructor(runtimeHost, options = {}) {
|
|
154
|
-
this.options = options;
|
|
155
240
|
this.runtimeHost = runtimeHost;
|
|
241
|
+
this.options = options;
|
|
242
|
+
this.autoTrustOnReloadCwd = options.autoTrustOnReloadCwd;
|
|
243
|
+
this.runtimeHost.setBeforeSessionInvalidate(() => {
|
|
244
|
+
this.resetExtensionUI();
|
|
245
|
+
});
|
|
246
|
+
this.runtimeHost.setRebindSession(async () => {
|
|
247
|
+
await this.rebindCurrentSession({ renderBeforeBind: true });
|
|
248
|
+
});
|
|
156
249
|
this.version = VERSION;
|
|
157
250
|
this.ui = new TUI(new ProcessTerminal(), this.settingsManager.getShowHardwareCursor());
|
|
158
251
|
this.ui.setClearOnShrink(this.settingsManager.getClearOnShrink());
|
|
159
252
|
this.headerContainer = new Container();
|
|
253
|
+
this.loadedResourcesContainer = new Container();
|
|
160
254
|
this.chatContainer = new Container();
|
|
161
255
|
this.pendingMessagesContainer = new Container();
|
|
162
256
|
this.statusContainer = new Container();
|
|
@@ -178,9 +272,10 @@ export class InteractiveMode {
|
|
|
178
272
|
this.footer.setAutoCompactEnabled(this.session.autoCompactionEnabled);
|
|
179
273
|
// Load hide thinking block setting
|
|
180
274
|
this.hideThinkingBlock = this.settingsManager.getHideThinkingBlock();
|
|
275
|
+
this.outputPad = this.settingsManager.getOutputPad();
|
|
181
276
|
// Register themes from resource loader and initialize
|
|
182
277
|
setRegisteredThemes(this.session.resourceLoader.getThemes().themes);
|
|
183
|
-
|
|
278
|
+
this.themeController = new InteractiveThemeController(this.ui, this.settingsManager, (message) => this.showError(message), () => this.updateEditorBorderColor());
|
|
184
279
|
}
|
|
185
280
|
getAutocompleteSourceTag(sourceInfo) {
|
|
186
281
|
if (!sourceInfo) {
|
|
@@ -209,9 +304,6 @@ export class InteractiveMode {
|
|
|
209
304
|
return description ? `[${sourceTag}] ${description}` : `[${sourceTag}]`;
|
|
210
305
|
}
|
|
211
306
|
getBuiltInCommandConflictDiagnostics(extensionRunner) {
|
|
212
|
-
if (!extensionRunner) {
|
|
213
|
-
return [];
|
|
214
|
-
}
|
|
215
307
|
const builtinNames = new Set(BUILTIN_SLASH_COMMANDS.map((command) => command.name));
|
|
216
308
|
return extensionRunner
|
|
217
309
|
.getRegisteredCommands()
|
|
@@ -224,7 +316,7 @@ export class InteractiveMode {
|
|
|
224
316
|
path: command.sourceInfo.path,
|
|
225
317
|
}));
|
|
226
318
|
}
|
|
227
|
-
|
|
319
|
+
createBaseAutocompleteProvider() {
|
|
228
320
|
// Define commands for autocomplete
|
|
229
321
|
const slashCommands = BUILTIN_SLASH_COMMANDS.map((command) => ({
|
|
230
322
|
name: command.name,
|
|
@@ -243,10 +335,11 @@ export class InteractiveMode {
|
|
|
243
335
|
const items = models.map((m) => ({
|
|
244
336
|
id: m.id,
|
|
245
337
|
provider: m.provider,
|
|
338
|
+
name: m.name,
|
|
246
339
|
label: `${m.provider}/${m.id}`,
|
|
247
340
|
}));
|
|
248
|
-
// Fuzzy filter by model ID + provider
|
|
249
|
-
const filtered = fuzzyFilter(items, prefix,
|
|
341
|
+
// Fuzzy filter by model ID + provider in either order.
|
|
342
|
+
const filtered = fuzzyFilter(items, prefix, getModelSearchText);
|
|
250
343
|
if (filtered.length === 0)
|
|
251
344
|
return null;
|
|
252
345
|
return filtered.map((item) => ({
|
|
@@ -260,10 +353,14 @@ export class InteractiveMode {
|
|
|
260
353
|
const templateCommands = this.session.promptTemplates.map((cmd) => ({
|
|
261
354
|
name: cmd.name,
|
|
262
355
|
description: this.prefixAutocompleteDescription(cmd.description, cmd.sourceInfo),
|
|
356
|
+
...(cmd.argumentHint && { argumentHint: cmd.argumentHint }),
|
|
263
357
|
}));
|
|
264
358
|
// Convert extension commands to SlashCommand format
|
|
265
359
|
const builtinCommandNames = new Set(slashCommands.map((c) => c.name));
|
|
266
|
-
const extensionCommands =
|
|
360
|
+
const extensionCommands = this.session.extensionRunner
|
|
361
|
+
.getRegisteredCommands()
|
|
362
|
+
.filter((cmd) => !builtinCommandNames.has(cmd.name))
|
|
363
|
+
.map((cmd) => ({
|
|
267
364
|
name: cmd.invocationName,
|
|
268
365
|
description: this.prefixAutocompleteDescription(cmd.description, cmd.sourceInfo),
|
|
269
366
|
getArgumentCompletions: cmd.getArgumentCompletions,
|
|
@@ -281,11 +378,22 @@ export class InteractiveMode {
|
|
|
281
378
|
});
|
|
282
379
|
}
|
|
283
380
|
}
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
381
|
+
return new CombinedAutocompleteProvider([...slashCommands, ...templateCommands, ...extensionCommands, ...skillCommandList], this.sessionManager.getCwd(), this.fdPath);
|
|
382
|
+
}
|
|
383
|
+
setupAutocompleteProvider() {
|
|
384
|
+
let provider = this.createBaseAutocompleteProvider();
|
|
385
|
+
const triggerCharacters = [];
|
|
386
|
+
for (const wrapProvider of this.autocompleteProviderWrappers) {
|
|
387
|
+
provider = wrapProvider(provider);
|
|
388
|
+
triggerCharacters.push(...(provider.triggerCharacters ?? []));
|
|
389
|
+
}
|
|
390
|
+
if (triggerCharacters.length > 0) {
|
|
391
|
+
provider.triggerCharacters = [...new Set(triggerCharacters)];
|
|
392
|
+
}
|
|
393
|
+
this.autocompleteProvider = provider;
|
|
394
|
+
this.defaultEditor.setAutocompleteProvider(provider);
|
|
287
395
|
if (this.editor !== this.defaultEditor) {
|
|
288
|
-
this.editor.setAutocompleteProvider?.(
|
|
396
|
+
this.editor.setAutocompleteProvider?.(provider);
|
|
289
397
|
}
|
|
290
398
|
}
|
|
291
399
|
showStartupNoticesIfNeeded() {
|
|
@@ -317,14 +425,45 @@ export class InteractiveMode {
|
|
|
317
425
|
async init() {
|
|
318
426
|
if (this.isInitialized)
|
|
319
427
|
return;
|
|
428
|
+
this.registerSignalHandlers();
|
|
320
429
|
// Load changelog (only show new entries, skip for resumed sessions)
|
|
321
430
|
this.changelogMarkdown = this.getChangelogForDisplay();
|
|
322
431
|
// Ensure fd and rg are available (downloads if missing, adds to PATH via getBinDir)
|
|
323
432
|
// Both are needed: fd for autocomplete, rg for grep tool and bash commands
|
|
324
433
|
const [fdPath] = await Promise.all([ensureTool("fd"), ensureTool("rg")]);
|
|
325
434
|
this.fdPath = fdPath;
|
|
326
|
-
|
|
435
|
+
if (this.session.scopedModels.length > 0 && (this.options.verbose || !this.settingsManager.getQuietStartup())) {
|
|
436
|
+
const modelList = this.session.scopedModels
|
|
437
|
+
.map((sm) => {
|
|
438
|
+
const thinkingStr = sm.thinkingLevel ? `:${sm.thinkingLevel}` : "";
|
|
439
|
+
return `${sm.model.id}${thinkingStr}`;
|
|
440
|
+
})
|
|
441
|
+
.join(", ");
|
|
442
|
+
const cycleKeys = this.keybindings.getKeys("app.model.cycleForward");
|
|
443
|
+
const cycleHint = cycleKeys.length > 0
|
|
444
|
+
? theme.fg("muted", ` (${formatKeyText(cycleKeys.join("/"), { capitalize: true })} to cycle)`)
|
|
445
|
+
: "";
|
|
446
|
+
console.log(theme.fg("dim", `Model scope: ${modelList}${cycleHint}`));
|
|
447
|
+
}
|
|
448
|
+
// Add header container as first child. Populate it after applying theme settings.
|
|
449
|
+
// Keep loaded resources before chat so restored session messages never precede them.
|
|
327
450
|
this.ui.addChild(this.headerContainer);
|
|
451
|
+
this.ui.addChild(this.loadedResourcesContainer);
|
|
452
|
+
this.ui.addChild(this.chatContainer);
|
|
453
|
+
this.ui.addChild(this.pendingMessagesContainer);
|
|
454
|
+
this.ui.addChild(this.statusContainer);
|
|
455
|
+
this.renderWidgets(); // Initialize with default spacer
|
|
456
|
+
this.ui.addChild(this.widgetContainerAbove);
|
|
457
|
+
this.ui.addChild(this.editorContainer);
|
|
458
|
+
this.ui.addChild(this.widgetContainerBelow);
|
|
459
|
+
this.ui.addChild(this.footer);
|
|
460
|
+
this.ui.setFocus(this.editor);
|
|
461
|
+
this.setupKeyHandlers();
|
|
462
|
+
this.setupEditorSubmitHandler();
|
|
463
|
+
// Start the UI before initializing extensions so session_start handlers can use interactive dialogs
|
|
464
|
+
this.ui.start();
|
|
465
|
+
this.isInitialized = true;
|
|
466
|
+
await this.themeController.applyFromSettings();
|
|
328
467
|
// Add header with keybindings from config (unless silenced)
|
|
329
468
|
if (this.options.verbose || !this.settingsManager.getQuietStartup()) {
|
|
330
469
|
const asciiArt = [
|
|
@@ -338,11 +477,11 @@ export class InteractiveMode {
|
|
|
338
477
|
]
|
|
339
478
|
.map((line) => theme.fg("border", line))
|
|
340
479
|
.join("\n");
|
|
341
|
-
const wordmark = theme.bold(theme.fg("accent", APP_NAME)) + theme.fg("dim", ` v${
|
|
480
|
+
const wordmark = theme.bold(theme.fg("accent", APP_NAME)) + theme.fg("dim", ` v${DISPLAY_VERSION} · /dʁaːt/`);
|
|
342
481
|
const logo = `${asciiArt}\n${wordmark}`;
|
|
343
482
|
// Build startup instructions using keybinding hint helpers
|
|
344
483
|
const hint = (keybinding, description) => keyHint(keybinding, description);
|
|
345
|
-
const
|
|
484
|
+
const expandedInstructions = [
|
|
346
485
|
hint("app.interrupt", "to interrupt"),
|
|
347
486
|
hint("app.clear", "to clear"),
|
|
348
487
|
rawKeyHint(`${keyText("app.clear")} twice`, "to exit"),
|
|
@@ -363,8 +502,16 @@ export class InteractiveMode {
|
|
|
363
502
|
hint("app.clipboard.pasteImage", "to paste image"),
|
|
364
503
|
rawKeyHint("drop files", "to attach"),
|
|
365
504
|
].join("\n");
|
|
366
|
-
const
|
|
367
|
-
|
|
505
|
+
const compactInstructions = [
|
|
506
|
+
hint("app.interrupt", "interrupt"),
|
|
507
|
+
rawKeyHint(`${keyText("app.clear")}/${keyText("app.exit")}`, "clear/exit"),
|
|
508
|
+
rawKeyHint("/", "commands"),
|
|
509
|
+
rawKeyHint("!", "bash"),
|
|
510
|
+
hint("app.tools.expand", "more"),
|
|
511
|
+
].join(theme.fg("muted", " · "));
|
|
512
|
+
const compactOnboarding = theme.fg("dim", `Press ${keyText("app.tools.expand")} to show full startup help and loaded resources.`);
|
|
513
|
+
const onboarding = theme.fg("dim", `${APP_NAME} can explain its own features and look up its docs. Ask it how to use or extend ${APP_NAME}.`);
|
|
514
|
+
this.builtInHeader = new ExpandableText(() => `${logo}\n${compactInstructions}\n${compactOnboarding}\n\n${onboarding}`, () => `${logo}\n${expandedInstructions}\n\n${onboarding}`, this.getStartupExpansionState(), 1, 0);
|
|
368
515
|
// Setup UI layout
|
|
369
516
|
this.headerContainer.addChild(new Spacer(1));
|
|
370
517
|
this.headerContainer.addChild(this.builtInHeader);
|
|
@@ -375,28 +522,11 @@ export class InteractiveMode {
|
|
|
375
522
|
this.builtInHeader = new Text("", 0, 0);
|
|
376
523
|
this.headerContainer.addChild(this.builtInHeader);
|
|
377
524
|
}
|
|
378
|
-
this.ui.
|
|
379
|
-
this.ui.addChild(this.pendingMessagesContainer);
|
|
380
|
-
this.ui.addChild(this.statusContainer);
|
|
381
|
-
this.renderWidgets(); // Initialize with default spacer
|
|
382
|
-
this.ui.addChild(this.widgetContainerAbove);
|
|
383
|
-
this.ui.addChild(this.editorContainer);
|
|
384
|
-
this.ui.addChild(this.widgetContainerBelow);
|
|
385
|
-
this.ui.addChild(this.footer);
|
|
386
|
-
this.ui.setFocus(this.editor);
|
|
387
|
-
this.setupKeyHandlers();
|
|
388
|
-
this.setupEditorSubmitHandler();
|
|
389
|
-
// Start the UI before initializing extensions so session_start handlers can use interactive dialogs
|
|
390
|
-
this.ui.start();
|
|
391
|
-
this.isInitialized = true;
|
|
525
|
+
this.ui.requestRender();
|
|
392
526
|
// Initialize extensions first so resources are shown before messages
|
|
393
|
-
await this.
|
|
527
|
+
await this.rebindCurrentSession();
|
|
394
528
|
// Render initial messages AFTER showing loaded resources
|
|
395
529
|
this.renderInitialMessages();
|
|
396
|
-
// Set terminal title
|
|
397
|
-
this.updateTerminalTitle();
|
|
398
|
-
// Subscribe to agent events
|
|
399
|
-
this.subscribeToAgent();
|
|
400
530
|
// Set up theme file watcher
|
|
401
531
|
onThemeChange(() => {
|
|
402
532
|
this.ui.invalidate();
|
|
@@ -417,10 +547,10 @@ export class InteractiveMode {
|
|
|
417
547
|
const cwdBasename = path.basename(this.sessionManager.getCwd());
|
|
418
548
|
const sessionName = this.sessionManager.getSessionName();
|
|
419
549
|
if (sessionName) {
|
|
420
|
-
this.ui.terminal.setTitle(
|
|
550
|
+
this.ui.terminal.setTitle(`${APP_TITLE} - ${sessionName} - ${cwdBasename}`);
|
|
421
551
|
}
|
|
422
552
|
else {
|
|
423
|
-
this.ui.terminal.setTitle(
|
|
553
|
+
this.ui.terminal.setTitle(`${APP_TITLE} - ${cwdBasename}`);
|
|
424
554
|
}
|
|
425
555
|
}
|
|
426
556
|
/**
|
|
@@ -430,9 +560,9 @@ export class InteractiveMode {
|
|
|
430
560
|
async run() {
|
|
431
561
|
await this.init();
|
|
432
562
|
// Start version check asynchronously
|
|
433
|
-
this.
|
|
434
|
-
if (
|
|
435
|
-
this.showNewVersionNotification(
|
|
563
|
+
checkForNewPiVersion(this.version).then((newRelease) => {
|
|
564
|
+
if (newRelease) {
|
|
565
|
+
this.showNewVersionNotification(newRelease);
|
|
436
566
|
}
|
|
437
567
|
});
|
|
438
568
|
// Start package update check asynchronously
|
|
@@ -493,31 +623,8 @@ export class InteractiveMode {
|
|
|
493
623
|
}
|
|
494
624
|
}
|
|
495
625
|
}
|
|
496
|
-
/**
|
|
497
|
-
* Check npm registry for a newer version.
|
|
498
|
-
*/
|
|
499
|
-
async checkForNewVersion() {
|
|
500
|
-
if (process.env.PI_SKIP_VERSION_CHECK || process.env.PI_OFFLINE)
|
|
501
|
-
return undefined;
|
|
502
|
-
try {
|
|
503
|
-
const response = await fetch("https://registry.npmjs.org/@draht/coding-agent/latest", {
|
|
504
|
-
signal: AbortSignal.timeout(10000),
|
|
505
|
-
});
|
|
506
|
-
if (!response.ok)
|
|
507
|
-
return undefined;
|
|
508
|
-
const data = (await response.json());
|
|
509
|
-
const latestVersion = data.version;
|
|
510
|
-
if (latestVersion && latestVersion !== this.version) {
|
|
511
|
-
return latestVersion;
|
|
512
|
-
}
|
|
513
|
-
return undefined;
|
|
514
|
-
}
|
|
515
|
-
catch {
|
|
516
|
-
return undefined;
|
|
517
|
-
}
|
|
518
|
-
}
|
|
519
626
|
async checkForPackageUpdates() {
|
|
520
|
-
if (process.env.
|
|
627
|
+
if (process.env.DRAHT_OFFLINE) {
|
|
521
628
|
return [];
|
|
522
629
|
}
|
|
523
630
|
try {
|
|
@@ -583,27 +690,39 @@ export class InteractiveMode {
|
|
|
583
690
|
if (this.session.state.messages.length > 0) {
|
|
584
691
|
return undefined;
|
|
585
692
|
}
|
|
586
|
-
// Skip changelog in dev mode — "dev" parses as 0.0.0 and would surface every entry.
|
|
587
|
-
if (VERSION === "dev") {
|
|
588
|
-
return undefined;
|
|
589
|
-
}
|
|
590
693
|
const lastVersion = this.settingsManager.getLastChangelogVersion();
|
|
591
694
|
const changelogPath = getChangelogPath();
|
|
592
695
|
const entries = parseChangelog(changelogPath);
|
|
593
696
|
if (!lastVersion) {
|
|
594
|
-
// Fresh install -
|
|
697
|
+
// Fresh install - record the version, send telemetry, don't show changelog
|
|
595
698
|
this.settingsManager.setLastChangelogVersion(VERSION);
|
|
699
|
+
this.reportInstallTelemetry(VERSION);
|
|
596
700
|
return undefined;
|
|
597
701
|
}
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
}
|
|
702
|
+
const newEntries = getNewEntries(entries, lastVersion);
|
|
703
|
+
if (newEntries.length > 0) {
|
|
704
|
+
this.settingsManager.setLastChangelogVersion(VERSION);
|
|
705
|
+
this.reportInstallTelemetry(VERSION);
|
|
706
|
+
return newEntries.map((e) => normalizeChangelogLinks(e.content, e)).join("\n\n");
|
|
604
707
|
}
|
|
605
708
|
return undefined;
|
|
606
709
|
}
|
|
710
|
+
reportInstallTelemetry(version) {
|
|
711
|
+
if (process.env.DRAHT_OFFLINE) {
|
|
712
|
+
return;
|
|
713
|
+
}
|
|
714
|
+
if (!isInstallTelemetryEnabled(this.settingsManager)) {
|
|
715
|
+
return;
|
|
716
|
+
}
|
|
717
|
+
void fetch(`https://pi.dev/api/report-install?version=${encodeURIComponent(version)}`, {
|
|
718
|
+
headers: {
|
|
719
|
+
"User-Agent": getPiUserAgent(version),
|
|
720
|
+
},
|
|
721
|
+
signal: AbortSignal.timeout(5000),
|
|
722
|
+
})
|
|
723
|
+
.then(() => undefined)
|
|
724
|
+
.catch(() => undefined);
|
|
725
|
+
}
|
|
607
726
|
getMarkdownThemeWithSettings() {
|
|
608
727
|
return {
|
|
609
728
|
...getMarkdownTheme(),
|
|
@@ -622,10 +741,38 @@ export class InteractiveMode {
|
|
|
622
741
|
}
|
|
623
742
|
return result;
|
|
624
743
|
}
|
|
744
|
+
formatExtensionDisplayPath(path) {
|
|
745
|
+
let result = this.formatDisplayPath(path);
|
|
746
|
+
result = result.replace(/\/index\.ts$/, "").replace(/\/index\.js$/, "");
|
|
747
|
+
return result;
|
|
748
|
+
}
|
|
749
|
+
formatContextPath(p) {
|
|
750
|
+
const cwd = path.resolve(this.sessionManager.getCwd());
|
|
751
|
+
const absolutePath = path.isAbsolute(p) ? path.resolve(p) : path.resolve(cwd, p);
|
|
752
|
+
const relativePath = getCwdRelativePath(absolutePath, cwd);
|
|
753
|
+
if (relativePath !== undefined) {
|
|
754
|
+
return relativePath;
|
|
755
|
+
}
|
|
756
|
+
return this.formatDisplayPath(absolutePath);
|
|
757
|
+
}
|
|
758
|
+
getStartupExpansionState() {
|
|
759
|
+
return this.options.verbose || this.toolOutputExpanded;
|
|
760
|
+
}
|
|
625
761
|
/**
|
|
626
762
|
* Get a short path relative to the package root for display.
|
|
627
763
|
*/
|
|
628
764
|
getShortPath(fullPath, sourceInfo) {
|
|
765
|
+
const baseDir = sourceInfo?.baseDir;
|
|
766
|
+
if (baseDir && this.isPackageSource(sourceInfo)) {
|
|
767
|
+
const relativePath = path.relative(path.resolve(baseDir), path.resolve(fullPath));
|
|
768
|
+
if (relativePath &&
|
|
769
|
+
relativePath !== "." &&
|
|
770
|
+
!relativePath.startsWith("..") &&
|
|
771
|
+
!relativePath.startsWith(`..${path.sep}`) &&
|
|
772
|
+
!path.isAbsolute(relativePath)) {
|
|
773
|
+
return relativePath.replace(/\\/g, "/");
|
|
774
|
+
}
|
|
775
|
+
}
|
|
629
776
|
const source = sourceInfo?.source ?? "";
|
|
630
777
|
const npmMatch = fullPath.match(/node_modules\/(@?[^/]+(?:\/[^/]+)?)\/(.*)/);
|
|
631
778
|
if (npmMatch && source.startsWith("npm:")) {
|
|
@@ -637,6 +784,93 @@ export class InteractiveMode {
|
|
|
637
784
|
}
|
|
638
785
|
return this.formatDisplayPath(fullPath);
|
|
639
786
|
}
|
|
787
|
+
getCompactPathLabel(resourcePath, sourceInfo) {
|
|
788
|
+
const shortPath = this.getShortPath(resourcePath, sourceInfo);
|
|
789
|
+
const normalizedPath = shortPath.replace(/\\/g, "/");
|
|
790
|
+
const segments = normalizedPath.split("/").filter((segment) => segment.length > 0 && segment !== "~");
|
|
791
|
+
if (segments.length > 0) {
|
|
792
|
+
return segments[segments.length - 1];
|
|
793
|
+
}
|
|
794
|
+
return shortPath;
|
|
795
|
+
}
|
|
796
|
+
getCompactPackageSourceLabel(sourceInfo) {
|
|
797
|
+
const source = sourceInfo?.source ?? "";
|
|
798
|
+
if (source.startsWith("npm:")) {
|
|
799
|
+
return source.slice("npm:".length) || source;
|
|
800
|
+
}
|
|
801
|
+
const gitSource = parseGitUrl(source);
|
|
802
|
+
if (gitSource) {
|
|
803
|
+
return gitSource.path || source;
|
|
804
|
+
}
|
|
805
|
+
return source;
|
|
806
|
+
}
|
|
807
|
+
getCompactExtensionLabel(resourcePath, sourceInfo) {
|
|
808
|
+
if (!this.isPackageSource(sourceInfo)) {
|
|
809
|
+
return this.getCompactPathLabel(resourcePath, sourceInfo);
|
|
810
|
+
}
|
|
811
|
+
const sourceLabel = this.getCompactPackageSourceLabel(sourceInfo);
|
|
812
|
+
if (!sourceLabel) {
|
|
813
|
+
return this.getCompactPathLabel(resourcePath, sourceInfo);
|
|
814
|
+
}
|
|
815
|
+
const shortPath = this.getShortPath(resourcePath, sourceInfo).replace(/\\/g, "/");
|
|
816
|
+
const packagePath = shortPath.startsWith("extensions/") ? shortPath.slice("extensions/".length) : shortPath;
|
|
817
|
+
const parsedPath = path.posix.parse(packagePath);
|
|
818
|
+
if (parsedPath.name === "index") {
|
|
819
|
+
return !parsedPath.dir || parsedPath.dir === "." ? sourceLabel : `${sourceLabel}:${parsedPath.dir}`;
|
|
820
|
+
}
|
|
821
|
+
return `${sourceLabel}:${packagePath}`;
|
|
822
|
+
}
|
|
823
|
+
getCompactDisplayPathSegments(resourcePath) {
|
|
824
|
+
return this.formatDisplayPath(resourcePath)
|
|
825
|
+
.replace(/\\/g, "/")
|
|
826
|
+
.split("/")
|
|
827
|
+
.filter((segment) => segment.length > 0 && segment !== "~");
|
|
828
|
+
}
|
|
829
|
+
getCompactNonPackageExtensionLabel(resourcePath, index, allPaths) {
|
|
830
|
+
const segments = allPaths[index]?.segments;
|
|
831
|
+
if (!segments || segments.length === 0) {
|
|
832
|
+
return this.getCompactPathLabel(resourcePath);
|
|
833
|
+
}
|
|
834
|
+
for (let segmentCount = 1; segmentCount <= segments.length; segmentCount += 1) {
|
|
835
|
+
const candidate = segments.slice(-segmentCount).join("/");
|
|
836
|
+
const isUnique = allPaths.every((item, itemIndex) => {
|
|
837
|
+
if (itemIndex === index) {
|
|
838
|
+
return true;
|
|
839
|
+
}
|
|
840
|
+
return item.segments.slice(-segmentCount).join("/") !== candidate;
|
|
841
|
+
});
|
|
842
|
+
if (isUnique) {
|
|
843
|
+
return candidate;
|
|
844
|
+
}
|
|
845
|
+
}
|
|
846
|
+
return segments.join("/");
|
|
847
|
+
}
|
|
848
|
+
getCompactExtensionLabels(extensions) {
|
|
849
|
+
const nonPackageExtensions = extensions
|
|
850
|
+
.map((extension) => {
|
|
851
|
+
const segments = this.getCompactDisplayPathSegments(extension.path);
|
|
852
|
+
const lastSegment = segments[segments.length - 1];
|
|
853
|
+
if (segments.length > 1 && (lastSegment === "index.ts" || lastSegment === "index.js")) {
|
|
854
|
+
segments.pop();
|
|
855
|
+
}
|
|
856
|
+
return {
|
|
857
|
+
path: extension.path,
|
|
858
|
+
sourceInfo: extension.sourceInfo,
|
|
859
|
+
segments,
|
|
860
|
+
};
|
|
861
|
+
})
|
|
862
|
+
.filter((extension) => !this.isPackageSource(extension.sourceInfo));
|
|
863
|
+
return extensions.map((extension) => {
|
|
864
|
+
if (this.isPackageSource(extension.sourceInfo)) {
|
|
865
|
+
return this.getCompactExtensionLabel(extension.path, extension.sourceInfo);
|
|
866
|
+
}
|
|
867
|
+
const nonPackageIndex = nonPackageExtensions.findIndex((item) => item.path === extension.path);
|
|
868
|
+
if (nonPackageIndex === -1) {
|
|
869
|
+
return this.getCompactPathLabel(extension.path, extension.sourceInfo);
|
|
870
|
+
}
|
|
871
|
+
return this.getCompactNonPackageExtensionLabel(extension.path, nonPackageIndex, nonPackageExtensions);
|
|
872
|
+
});
|
|
873
|
+
}
|
|
640
874
|
getDisplaySourceInfo(sourceInfo) {
|
|
641
875
|
const source = sourceInfo?.source ?? "local";
|
|
642
876
|
const scope = sourceInfo?.scope ?? "project";
|
|
@@ -776,12 +1010,26 @@ export class InteractiveMode {
|
|
|
776
1010
|
return lines.join("\n");
|
|
777
1011
|
}
|
|
778
1012
|
showLoadedResources(options) {
|
|
1013
|
+
// Resource rendering is idempotent; chat clears no longer clear this separate container.
|
|
1014
|
+
this.loadedResourcesContainer.clear();
|
|
779
1015
|
const showListing = options?.force || this.options.verbose || !this.settingsManager.getQuietStartup();
|
|
780
1016
|
const showDiagnostics = showListing || options?.showDiagnosticsWhenQuiet === true;
|
|
781
1017
|
if (!showListing && !showDiagnostics) {
|
|
782
1018
|
return;
|
|
783
1019
|
}
|
|
784
1020
|
const sectionHeader = (name, color = "mdHeading") => theme.fg(color, `[${name}]`);
|
|
1021
|
+
const formatCompactList = (items, options) => {
|
|
1022
|
+
const labels = items.map((item) => item.trim()).filter((item) => item.length > 0);
|
|
1023
|
+
if (options?.sort !== false) {
|
|
1024
|
+
labels.sort((a, b) => a.localeCompare(b));
|
|
1025
|
+
}
|
|
1026
|
+
return theme.fg("dim", ` ${labels.join(", ")}`);
|
|
1027
|
+
};
|
|
1028
|
+
const addLoadedSection = (name, collapsedBody, expandedBody = collapsedBody, color = "mdHeading") => {
|
|
1029
|
+
const section = new ExpandableText(() => `${sectionHeader(name, color)}\n${collapsedBody}`, () => `${sectionHeader(name, color)}\n${expandedBody}`, this.getStartupExpansionState(), 0, 0);
|
|
1030
|
+
this.loadedResourcesContainer.addChild(section);
|
|
1031
|
+
this.loadedResourcesContainer.addChild(new Spacer(1));
|
|
1032
|
+
};
|
|
785
1033
|
const skillsResult = this.session.resourceLoader.getSkills();
|
|
786
1034
|
const promptsResult = this.session.resourceLoader.getPrompts();
|
|
787
1035
|
const themesResult = this.session.resourceLoader.getThemes();
|
|
@@ -814,12 +1062,12 @@ export class InteractiveMode {
|
|
|
814
1062
|
if (showListing) {
|
|
815
1063
|
const contextFiles = this.session.resourceLoader.getAgentsFiles().agentsFiles;
|
|
816
1064
|
if (contextFiles.length > 0) {
|
|
817
|
-
this.
|
|
1065
|
+
this.loadedResourcesContainer.addChild(new Spacer(1));
|
|
818
1066
|
const contextList = contextFiles
|
|
819
1067
|
.map((f) => theme.fg("dim", ` ${this.formatDisplayPath(f.path)}`))
|
|
820
1068
|
.join("\n");
|
|
821
|
-
|
|
822
|
-
|
|
1069
|
+
const contextCompactList = formatCompactList(contextFiles.map((contextFile) => this.formatContextPath(contextFile.path)), { sort: false });
|
|
1070
|
+
addLoadedSection("Context", contextCompactList, contextList);
|
|
823
1071
|
}
|
|
824
1072
|
const skills = skillsResult.skills;
|
|
825
1073
|
if (skills.length > 0) {
|
|
@@ -828,8 +1076,8 @@ export class InteractiveMode {
|
|
|
828
1076
|
formatPath: (item) => this.formatDisplayPath(item.path),
|
|
829
1077
|
formatPackagePath: (item) => this.getShortPath(item.path, item.sourceInfo),
|
|
830
1078
|
});
|
|
831
|
-
|
|
832
|
-
|
|
1079
|
+
const skillCompactList = formatCompactList(skills.map((skill) => skill.name));
|
|
1080
|
+
addLoadedSection("Skills", skillCompactList, skillList);
|
|
833
1081
|
}
|
|
834
1082
|
const templates = this.session.promptTemplates;
|
|
835
1083
|
if (templates.length > 0) {
|
|
@@ -845,17 +1093,17 @@ export class InteractiveMode {
|
|
|
845
1093
|
return template ? `/${template.name}` : this.formatDisplayPath(item.path);
|
|
846
1094
|
},
|
|
847
1095
|
});
|
|
848
|
-
|
|
849
|
-
|
|
1096
|
+
const promptCompactList = formatCompactList(templates.map((template) => `/${template.name}`));
|
|
1097
|
+
addLoadedSection("Prompts", promptCompactList, templateList);
|
|
850
1098
|
}
|
|
851
1099
|
if (extensions.length > 0) {
|
|
852
1100
|
const groups = this.buildScopeGroups(extensions);
|
|
853
1101
|
const extList = this.formatScopeGroups(groups, {
|
|
854
|
-
formatPath: (item) => this.
|
|
855
|
-
formatPackagePath: (item) => this.getShortPath(item.path, item.sourceInfo),
|
|
1102
|
+
formatPath: (item) => this.formatExtensionDisplayPath(item.path),
|
|
1103
|
+
formatPackagePath: (item) => this.formatExtensionDisplayPath(this.getShortPath(item.path, item.sourceInfo)),
|
|
856
1104
|
});
|
|
857
|
-
this.
|
|
858
|
-
|
|
1105
|
+
const extensionCompactList = formatCompactList(this.getCompactExtensionLabels(extensions));
|
|
1106
|
+
addLoadedSection("Extensions", extensionCompactList, extList, "mdHeading");
|
|
859
1107
|
}
|
|
860
1108
|
// Show loaded themes (excluding built-in)
|
|
861
1109
|
const loadedThemes = themesResult.themes;
|
|
@@ -869,22 +1117,22 @@ export class InteractiveMode {
|
|
|
869
1117
|
formatPath: (item) => this.formatDisplayPath(item.path),
|
|
870
1118
|
formatPackagePath: (item) => this.getShortPath(item.path, item.sourceInfo),
|
|
871
1119
|
});
|
|
872
|
-
|
|
873
|
-
|
|
1120
|
+
const themeCompactList = formatCompactList(customThemes.map((loadedTheme) => loadedTheme.name ?? this.getCompactPathLabel(loadedTheme.sourcePath, loadedTheme.sourceInfo)));
|
|
1121
|
+
addLoadedSection("Themes", themeCompactList, themeList);
|
|
874
1122
|
}
|
|
875
1123
|
}
|
|
876
1124
|
if (showDiagnostics) {
|
|
877
1125
|
const skillDiagnostics = skillsResult.diagnostics;
|
|
878
1126
|
if (skillDiagnostics.length > 0) {
|
|
879
1127
|
const warningLines = this.formatDiagnostics(skillDiagnostics, sourceInfos);
|
|
880
|
-
this.
|
|
881
|
-
this.
|
|
1128
|
+
this.loadedResourcesContainer.addChild(new Text(`${theme.fg("warning", "[Skill conflicts]")}\n${warningLines}`, 0, 0));
|
|
1129
|
+
this.loadedResourcesContainer.addChild(new Spacer(1));
|
|
882
1130
|
}
|
|
883
1131
|
const promptDiagnostics = promptsResult.diagnostics;
|
|
884
1132
|
if (promptDiagnostics.length > 0) {
|
|
885
1133
|
const warningLines = this.formatDiagnostics(promptDiagnostics, sourceInfos);
|
|
886
|
-
this.
|
|
887
|
-
this.
|
|
1134
|
+
this.loadedResourcesContainer.addChild(new Text(`${theme.fg("warning", "[Prompt conflicts]")}\n${warningLines}`, 0, 0));
|
|
1135
|
+
this.loadedResourcesContainer.addChild(new Spacer(1));
|
|
888
1136
|
}
|
|
889
1137
|
const extensionDiagnostics = [];
|
|
890
1138
|
const extensionErrors = this.session.resourceLoader.getExtensions().errors;
|
|
@@ -893,21 +1141,21 @@ export class InteractiveMode {
|
|
|
893
1141
|
extensionDiagnostics.push({ type: "error", message: error.error, path: error.path });
|
|
894
1142
|
}
|
|
895
1143
|
}
|
|
896
|
-
const commandDiagnostics = this.session.extensionRunner
|
|
1144
|
+
const commandDiagnostics = this.session.extensionRunner.getCommandDiagnostics();
|
|
897
1145
|
extensionDiagnostics.push(...commandDiagnostics);
|
|
898
1146
|
extensionDiagnostics.push(...this.getBuiltInCommandConflictDiagnostics(this.session.extensionRunner));
|
|
899
|
-
const shortcutDiagnostics = this.session.extensionRunner
|
|
1147
|
+
const shortcutDiagnostics = this.session.extensionRunner.getShortcutDiagnostics();
|
|
900
1148
|
extensionDiagnostics.push(...shortcutDiagnostics);
|
|
901
1149
|
if (extensionDiagnostics.length > 0) {
|
|
902
1150
|
const warningLines = this.formatDiagnostics(extensionDiagnostics, sourceInfos);
|
|
903
|
-
this.
|
|
904
|
-
this.
|
|
1151
|
+
this.loadedResourcesContainer.addChild(new Text(`${theme.fg("warning", "[Extension issues]")}\n${warningLines}`, 0, 0));
|
|
1152
|
+
this.loadedResourcesContainer.addChild(new Spacer(1));
|
|
905
1153
|
}
|
|
906
1154
|
const themeDiagnostics = themesResult.diagnostics;
|
|
907
1155
|
if (themeDiagnostics.length > 0) {
|
|
908
1156
|
const warningLines = this.formatDiagnostics(themeDiagnostics, sourceInfos);
|
|
909
|
-
this.
|
|
910
|
-
this.
|
|
1157
|
+
this.loadedResourcesContainer.addChild(new Text(`${theme.fg("warning", "[Theme conflicts]")}\n${warningLines}`, 0, 0));
|
|
1158
|
+
this.loadedResourcesContainer.addChild(new Spacer(1));
|
|
911
1159
|
}
|
|
912
1160
|
}
|
|
913
1161
|
}
|
|
@@ -918,33 +1166,25 @@ export class InteractiveMode {
|
|
|
918
1166
|
const uiContext = this.createExtensionUIContext();
|
|
919
1167
|
await this.session.bindExtensions({
|
|
920
1168
|
uiContext,
|
|
1169
|
+
mode: "tui",
|
|
1170
|
+
abortHandler: () => {
|
|
1171
|
+
this.restoreQueuedMessagesToEditor({ abort: true });
|
|
1172
|
+
},
|
|
921
1173
|
commandContextActions: {
|
|
922
1174
|
waitForIdle: () => this.session.agent.waitForIdle(),
|
|
923
1175
|
newSession: async (options) => {
|
|
924
|
-
|
|
925
|
-
this.loadingAnimation.stop();
|
|
926
|
-
this.loadingAnimation = undefined;
|
|
927
|
-
}
|
|
928
|
-
this.statusContainer.clear();
|
|
1176
|
+
this.clearStatusIndicator();
|
|
929
1177
|
try {
|
|
930
|
-
|
|
931
|
-
if (!result.cancelled) {
|
|
932
|
-
await this.handleRuntimeSessionChange();
|
|
933
|
-
this.renderCurrentSessionState();
|
|
934
|
-
this.ui.requestRender();
|
|
935
|
-
}
|
|
936
|
-
return result;
|
|
1178
|
+
return await this.runtimeHost.newSession(options);
|
|
937
1179
|
}
|
|
938
1180
|
catch (error) {
|
|
939
1181
|
return this.handleFatalRuntimeError("Failed to create session", error);
|
|
940
1182
|
}
|
|
941
1183
|
},
|
|
942
|
-
fork: async (entryId) => {
|
|
1184
|
+
fork: async (entryId, options) => {
|
|
943
1185
|
try {
|
|
944
|
-
const result = await this.runtimeHost.fork(entryId);
|
|
1186
|
+
const result = await this.runtimeHost.fork(entryId, options);
|
|
945
1187
|
if (!result.cancelled) {
|
|
946
|
-
await this.handleRuntimeSessionChange();
|
|
947
|
-
this.renderCurrentSessionState();
|
|
948
1188
|
this.editor.setText(result.selectedText ?? "");
|
|
949
1189
|
this.showStatus("Forked to new session");
|
|
950
1190
|
}
|
|
@@ -970,11 +1210,11 @@ export class InteractiveMode {
|
|
|
970
1210
|
this.editor.setText(result.editorText);
|
|
971
1211
|
}
|
|
972
1212
|
this.showStatus("Navigated to selected point");
|
|
1213
|
+
void this.flushCompactionQueue({ willRetry: false });
|
|
973
1214
|
return { cancelled: false };
|
|
974
1215
|
},
|
|
975
|
-
switchSession: async (sessionPath) => {
|
|
976
|
-
|
|
977
|
-
return { cancelled: false };
|
|
1216
|
+
switchSession: async (sessionPath, options) => {
|
|
1217
|
+
return this.handleResumeSession(sessionPath, options);
|
|
978
1218
|
},
|
|
979
1219
|
reload: async () => {
|
|
980
1220
|
await this.handleReloadCommand();
|
|
@@ -991,24 +1231,25 @@ export class InteractiveMode {
|
|
|
991
1231
|
},
|
|
992
1232
|
});
|
|
993
1233
|
setRegisteredThemes(this.session.resourceLoader.getThemes().themes);
|
|
994
|
-
this.
|
|
1234
|
+
this.setupAutocompleteProvider();
|
|
995
1235
|
const extensionRunner = this.session.extensionRunner;
|
|
996
|
-
if (!extensionRunner) {
|
|
997
|
-
this.showLoadedResources({ extensions: [], force: false });
|
|
998
|
-
this.showStartupNoticesIfNeeded();
|
|
999
|
-
return;
|
|
1000
|
-
}
|
|
1001
1236
|
this.setupExtensionShortcuts(extensionRunner);
|
|
1002
|
-
this.showLoadedResources({ force: false });
|
|
1237
|
+
this.showLoadedResources({ force: false, showDiagnosticsWhenQuiet: true });
|
|
1003
1238
|
this.showStartupNoticesIfNeeded();
|
|
1004
1239
|
}
|
|
1005
1240
|
applyRuntimeSettings() {
|
|
1241
|
+
configureHttpDispatcher(this.settingsManager.getHttpIdleTimeoutMs());
|
|
1006
1242
|
this.footer.setSession(this.session);
|
|
1007
1243
|
this.footer.setAutoCompactEnabled(this.session.autoCompactionEnabled);
|
|
1008
1244
|
this.footerDataProvider.setCwd(this.sessionManager.getCwd());
|
|
1009
1245
|
this.hideThinkingBlock = this.settingsManager.getHideThinkingBlock();
|
|
1246
|
+
this.outputPad = this.settingsManager.getOutputPad();
|
|
1010
1247
|
this.ui.setShowHardwareCursor(this.settingsManager.getShowHardwareCursor());
|
|
1011
|
-
this.
|
|
1248
|
+
const clearOnShrink = this.settingsManager.getClearOnShrink();
|
|
1249
|
+
this.ui.setClearOnShrink(clearOnShrink);
|
|
1250
|
+
if (!clearOnShrink && !this.activeStatusIndicator) {
|
|
1251
|
+
this.statusContainer.clear();
|
|
1252
|
+
}
|
|
1012
1253
|
const editorPaddingX = this.settingsManager.getEditorPaddingX();
|
|
1013
1254
|
const autocompleteMaxVisible = this.settingsManager.getAutocompleteMaxVisible();
|
|
1014
1255
|
this.defaultEditor.setPaddingX(editorPaddingX);
|
|
@@ -1018,13 +1259,19 @@ export class InteractiveMode {
|
|
|
1018
1259
|
this.editor.setAutocompleteMaxVisible?.(autocompleteMaxVisible);
|
|
1019
1260
|
}
|
|
1020
1261
|
}
|
|
1021
|
-
async
|
|
1022
|
-
this.resetExtensionUI();
|
|
1262
|
+
async rebindCurrentSession(options = {}) {
|
|
1023
1263
|
this.unsubscribe?.();
|
|
1024
1264
|
this.unsubscribe = undefined;
|
|
1025
1265
|
this.applyRuntimeSettings();
|
|
1026
|
-
|
|
1027
|
-
|
|
1266
|
+
if (options.renderBeforeBind) {
|
|
1267
|
+
this.renderCurrentSessionState();
|
|
1268
|
+
this.subscribeToAgent();
|
|
1269
|
+
await this.bindCurrentSessionExtensions();
|
|
1270
|
+
}
|
|
1271
|
+
else {
|
|
1272
|
+
await this.bindCurrentSessionExtensions();
|
|
1273
|
+
this.subscribeToAgent();
|
|
1274
|
+
}
|
|
1028
1275
|
await this.updateAvailableProviderCount();
|
|
1029
1276
|
this.updateEditorBorderColor();
|
|
1030
1277
|
this.updateTerminalTitle();
|
|
@@ -1037,6 +1284,7 @@ export class InteractiveMode {
|
|
|
1037
1284
|
process.exit(1);
|
|
1038
1285
|
}
|
|
1039
1286
|
renderCurrentSessionState() {
|
|
1287
|
+
this.loadedResourcesContainer.clear();
|
|
1040
1288
|
this.chatContainer.clear();
|
|
1041
1289
|
this.pendingMessagesContainer.clear();
|
|
1042
1290
|
this.compactionQueuedMessages = [];
|
|
@@ -1061,14 +1309,18 @@ export class InteractiveMode {
|
|
|
1061
1309
|
// Create a context for shortcut handlers
|
|
1062
1310
|
const createContext = () => ({
|
|
1063
1311
|
ui: this.createExtensionUIContext(),
|
|
1312
|
+
mode: "tui",
|
|
1064
1313
|
hasUI: true,
|
|
1065
1314
|
cwd: this.sessionManager.getCwd(),
|
|
1066
1315
|
sessionManager: this.sessionManager,
|
|
1067
1316
|
modelRegistry: this.session.modelRegistry,
|
|
1068
1317
|
model: this.session.model,
|
|
1069
1318
|
isIdle: () => !this.session.isStreaming,
|
|
1319
|
+
isProjectTrusted: () => this.settingsManager.isProjectTrusted(),
|
|
1070
1320
|
signal: this.session.agent.signal,
|
|
1071
|
-
abort: () =>
|
|
1321
|
+
abort: () => {
|
|
1322
|
+
this.restoreQueuedMessagesToEditor({ abort: true });
|
|
1323
|
+
},
|
|
1072
1324
|
hasPendingMessages: () => this.session.pendingMessageCount > 0,
|
|
1073
1325
|
shutdown: () => {
|
|
1074
1326
|
this.shutdownRequested = true;
|
|
@@ -1110,6 +1362,43 @@ export class InteractiveMode {
|
|
|
1110
1362
|
this.footerDataProvider.setExtensionStatus(key, text);
|
|
1111
1363
|
this.ui.requestRender();
|
|
1112
1364
|
}
|
|
1365
|
+
showStatusIndicator(indicator) {
|
|
1366
|
+
this.activeStatusIndicator?.dispose();
|
|
1367
|
+
this.activeStatusIndicator = indicator;
|
|
1368
|
+
this.statusContainer.clear();
|
|
1369
|
+
this.statusContainer.addChild(indicator);
|
|
1370
|
+
}
|
|
1371
|
+
clearStatusIndicator(kind) {
|
|
1372
|
+
if (kind && this.activeStatusIndicator?.kind !== kind) {
|
|
1373
|
+
return;
|
|
1374
|
+
}
|
|
1375
|
+
const hadActiveStatusIndicator = this.activeStatusIndicator !== undefined;
|
|
1376
|
+
this.activeStatusIndicator?.dispose();
|
|
1377
|
+
this.activeStatusIndicator = undefined;
|
|
1378
|
+
this.statusContainer.clear();
|
|
1379
|
+
if (hadActiveStatusIndicator && this.ui.getClearOnShrink()) {
|
|
1380
|
+
this.statusContainer.addChild(this.idleStatus);
|
|
1381
|
+
}
|
|
1382
|
+
}
|
|
1383
|
+
setWorkingVisible(visible) {
|
|
1384
|
+
this.workingVisible = visible;
|
|
1385
|
+
if (!visible) {
|
|
1386
|
+
this.clearStatusIndicator("working");
|
|
1387
|
+
this.ui.requestRender();
|
|
1388
|
+
return;
|
|
1389
|
+
}
|
|
1390
|
+
if (this.session.isStreaming && this.activeStatusIndicator?.kind !== "working") {
|
|
1391
|
+
this.showStatusIndicator(new WorkingStatusIndicator(this.ui, this.workingMessage ?? this.defaultWorkingMessage, this.workingIndicatorOptions));
|
|
1392
|
+
}
|
|
1393
|
+
this.ui.requestRender();
|
|
1394
|
+
}
|
|
1395
|
+
setWorkingIndicator(options) {
|
|
1396
|
+
this.workingIndicatorOptions = options;
|
|
1397
|
+
if (this.activeStatusIndicator?.kind === "working") {
|
|
1398
|
+
this.activeStatusIndicator.setIndicator(options);
|
|
1399
|
+
}
|
|
1400
|
+
this.ui.requestRender();
|
|
1401
|
+
}
|
|
1113
1402
|
setHiddenThinkingLabel(label) {
|
|
1114
1403
|
this.hiddenThinkingLabel = label ?? this.defaultHiddenThinkingLabel;
|
|
1115
1404
|
for (const child of this.chatContainer.children) {
|
|
@@ -1187,11 +1476,16 @@ export class InteractiveMode {
|
|
|
1187
1476
|
this.clearExtensionWidgets();
|
|
1188
1477
|
this.footerDataProvider.clearExtensionStatuses();
|
|
1189
1478
|
this.footer.invalidate();
|
|
1479
|
+
this.autocompleteProviderWrappers = [];
|
|
1190
1480
|
this.setCustomEditorComponent(undefined);
|
|
1481
|
+
this.setupAutocompleteProvider();
|
|
1191
1482
|
this.defaultEditor.onExtensionShortcut = undefined;
|
|
1192
1483
|
this.updateTerminalTitle();
|
|
1193
|
-
|
|
1194
|
-
|
|
1484
|
+
this.workingMessage = undefined;
|
|
1485
|
+
this.workingVisible = true;
|
|
1486
|
+
this.setWorkingIndicator();
|
|
1487
|
+
if (this.activeStatusIndicator?.kind === "working") {
|
|
1488
|
+
this.activeStatusIndicator.setMessage(`${this.defaultWorkingMessage} (${keyText("app.interrupt")} to interrupt)`);
|
|
1195
1489
|
}
|
|
1196
1490
|
this.setHiddenThinkingLabel();
|
|
1197
1491
|
}
|
|
@@ -1267,6 +1561,9 @@ export class InteractiveMode {
|
|
|
1267
1561
|
if (factory) {
|
|
1268
1562
|
// Create and add custom header
|
|
1269
1563
|
this.customHeader = factory(this.ui, theme);
|
|
1564
|
+
if (isExpandable(this.customHeader)) {
|
|
1565
|
+
this.customHeader.setExpanded(this.toolOutputExpanded);
|
|
1566
|
+
}
|
|
1270
1567
|
if (index !== -1) {
|
|
1271
1568
|
this.headerContainer.children[index] = this.customHeader;
|
|
1272
1569
|
}
|
|
@@ -1278,6 +1575,9 @@ export class InteractiveMode {
|
|
|
1278
1575
|
else {
|
|
1279
1576
|
// Restore built-in header
|
|
1280
1577
|
this.customHeader = undefined;
|
|
1578
|
+
if (isExpandable(this.builtInHeader)) {
|
|
1579
|
+
this.builtInHeader.setExpanded(this.toolOutputExpanded);
|
|
1580
|
+
}
|
|
1281
1581
|
if (index !== -1) {
|
|
1282
1582
|
this.headerContainer.children[index] = this.builtInHeader;
|
|
1283
1583
|
}
|
|
@@ -1301,6 +1601,20 @@ export class InteractiveMode {
|
|
|
1301
1601
|
/**
|
|
1302
1602
|
* Create the ExtensionUIContext for extensions.
|
|
1303
1603
|
*/
|
|
1604
|
+
createProjectTrustContext(cwd) {
|
|
1605
|
+
const ui = this.createExtensionUIContext();
|
|
1606
|
+
return {
|
|
1607
|
+
cwd,
|
|
1608
|
+
mode: "tui",
|
|
1609
|
+
hasUI: true,
|
|
1610
|
+
ui: {
|
|
1611
|
+
select: ui.select,
|
|
1612
|
+
confirm: ui.confirm,
|
|
1613
|
+
input: ui.input,
|
|
1614
|
+
notify: ui.notify,
|
|
1615
|
+
},
|
|
1616
|
+
};
|
|
1617
|
+
}
|
|
1304
1618
|
createExtensionUIContext() {
|
|
1305
1619
|
return {
|
|
1306
1620
|
select: (title, options, opts) => this.showExtensionSelector(title, options, opts),
|
|
@@ -1310,19 +1624,13 @@ export class InteractiveMode {
|
|
|
1310
1624
|
onTerminalInput: (handler) => this.addExtensionTerminalInputListener(handler),
|
|
1311
1625
|
setStatus: (key, text) => this.setExtensionStatus(key, text),
|
|
1312
1626
|
setWorkingMessage: (message) => {
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
}
|
|
1317
|
-
else {
|
|
1318
|
-
this.loadingAnimation.setMessage(`${this.defaultWorkingMessage} (${keyText("app.interrupt")} to interrupt)`);
|
|
1319
|
-
}
|
|
1320
|
-
}
|
|
1321
|
-
else {
|
|
1322
|
-
// Queue message for when loadingAnimation is created (handles agent_start race)
|
|
1323
|
-
this.pendingWorkingMessage = message;
|
|
1627
|
+
this.workingMessage = message;
|
|
1628
|
+
if (this.activeStatusIndicator?.kind === "working") {
|
|
1629
|
+
this.activeStatusIndicator.setMessage(message ?? this.defaultWorkingMessage);
|
|
1324
1630
|
}
|
|
1325
1631
|
},
|
|
1632
|
+
setWorkingVisible: (visible) => this.setWorkingVisible(visible),
|
|
1633
|
+
setWorkingIndicator: (options) => this.setWorkingIndicator(options),
|
|
1326
1634
|
setHiddenThinkingLabel: (label) => this.setHiddenThinkingLabel(label),
|
|
1327
1635
|
setWidget: (key, content, options) => this.setExtensionWidget(key, content, options),
|
|
1328
1636
|
setFooter: (factory) => this.setExtensionFooter(factory),
|
|
@@ -1333,7 +1641,12 @@ export class InteractiveMode {
|
|
|
1333
1641
|
setEditorText: (text) => this.editor.setText(text),
|
|
1334
1642
|
getEditorText: () => this.editor.getExpandedText?.() ?? this.editor.getText(),
|
|
1335
1643
|
editor: (title, prefill) => this.showExtensionEditor(title, prefill),
|
|
1644
|
+
addAutocompleteProvider: (factory) => {
|
|
1645
|
+
this.autocompleteProviderWrappers.push(factory);
|
|
1646
|
+
this.setupAutocompleteProvider();
|
|
1647
|
+
},
|
|
1336
1648
|
setEditorComponent: (factory) => this.setCustomEditorComponent(factory),
|
|
1649
|
+
getEditorComponent: () => this.editorComponentFactory,
|
|
1337
1650
|
get theme() {
|
|
1338
1651
|
return theme;
|
|
1339
1652
|
},
|
|
@@ -1341,16 +1654,13 @@ export class InteractiveMode {
|
|
|
1341
1654
|
getTheme: (name) => getThemeByName(name),
|
|
1342
1655
|
setTheme: (themeOrName) => {
|
|
1343
1656
|
if (themeOrName instanceof Theme) {
|
|
1344
|
-
setThemeInstance(themeOrName);
|
|
1345
|
-
this.ui.requestRender();
|
|
1346
|
-
return { success: true };
|
|
1657
|
+
return this.themeController.setThemeInstance(themeOrName);
|
|
1347
1658
|
}
|
|
1348
|
-
const result =
|
|
1659
|
+
const result = this.themeController.setThemeName(themeOrName);
|
|
1349
1660
|
if (result.success) {
|
|
1350
1661
|
if (this.settingsManager.getTheme() !== themeOrName) {
|
|
1351
1662
|
this.settingsManager.setTheme(themeOrName);
|
|
1352
1663
|
}
|
|
1353
|
-
this.ui.requestRender();
|
|
1354
1664
|
}
|
|
1355
1665
|
return result;
|
|
1356
1666
|
},
|
|
@@ -1380,7 +1690,7 @@ export class InteractiveMode {
|
|
|
1380
1690
|
opts?.signal?.removeEventListener("abort", onAbort);
|
|
1381
1691
|
this.hideExtensionSelector();
|
|
1382
1692
|
resolve(undefined);
|
|
1383
|
-
}, { tui: this.ui, timeout: opts?.timeout });
|
|
1693
|
+
}, { tui: this.ui, timeout: opts?.timeout, onToggleToolsExpanded: () => this.toggleToolOutputExpansion() });
|
|
1384
1694
|
this.editorContainer.clear();
|
|
1385
1695
|
this.editorContainer.addChild(this.extensionSelector);
|
|
1386
1696
|
this.ui.setFocus(this.extensionSelector);
|
|
@@ -1460,7 +1770,7 @@ export class InteractiveMode {
|
|
|
1460
1770
|
}, () => {
|
|
1461
1771
|
this.hideExtensionEditor();
|
|
1462
1772
|
resolve(undefined);
|
|
1463
|
-
});
|
|
1773
|
+
}, undefined, this.settingsManager.getExternalEditorCommand());
|
|
1464
1774
|
this.editorContainer.clear();
|
|
1465
1775
|
this.editorContainer.addChild(this.extensionEditor);
|
|
1466
1776
|
this.ui.setFocus(this.extensionEditor);
|
|
@@ -1482,6 +1792,7 @@ export class InteractiveMode {
|
|
|
1482
1792
|
* Pass undefined to restore the default editor.
|
|
1483
1793
|
*/
|
|
1484
1794
|
setCustomEditorComponent(factory) {
|
|
1795
|
+
this.editorComponentFactory = factory;
|
|
1485
1796
|
// Save text from current editor before switching
|
|
1486
1797
|
const currentText = this.editor.getText();
|
|
1487
1798
|
this.editorContainer.clear();
|
|
@@ -1646,7 +1957,7 @@ export class InteractiveMode {
|
|
|
1646
1957
|
// Set up handlers on defaultEditor - they use this.editor for text access
|
|
1647
1958
|
// so they work correctly regardless of which editor is active
|
|
1648
1959
|
this.defaultEditor.onEscape = () => {
|
|
1649
|
-
if (this.
|
|
1960
|
+
if (this.session.isStreaming) {
|
|
1650
1961
|
this.restoreQueuedMessagesToEditor({ abort: true });
|
|
1651
1962
|
}
|
|
1652
1963
|
else if (this.session.isBashRunning) {
|
|
@@ -1750,12 +2061,12 @@ export class InteractiveMode {
|
|
|
1750
2061
|
await this.handleModelCommand(searchTerm);
|
|
1751
2062
|
return;
|
|
1752
2063
|
}
|
|
1753
|
-
if (text.startsWith("/export")) {
|
|
2064
|
+
if (text === "/export" || text.startsWith("/export ")) {
|
|
1754
2065
|
await this.handleExportCommand(text);
|
|
1755
2066
|
this.editor.setText("");
|
|
1756
2067
|
return;
|
|
1757
2068
|
}
|
|
1758
|
-
if (text.startsWith("/import")) {
|
|
2069
|
+
if (text === "/import" || text.startsWith("/import ")) {
|
|
1759
2070
|
await this.handleImportCommand(text);
|
|
1760
2071
|
this.editor.setText("");
|
|
1761
2072
|
return;
|
|
@@ -1795,11 +2106,21 @@ export class InteractiveMode {
|
|
|
1795
2106
|
this.editor.setText("");
|
|
1796
2107
|
return;
|
|
1797
2108
|
}
|
|
2109
|
+
if (text === "/clone") {
|
|
2110
|
+
this.editor.setText("");
|
|
2111
|
+
await this.handleCloneCommand();
|
|
2112
|
+
return;
|
|
2113
|
+
}
|
|
1798
2114
|
if (text === "/tree") {
|
|
1799
2115
|
this.showTreeSelector();
|
|
1800
2116
|
this.editor.setText("");
|
|
1801
2117
|
return;
|
|
1802
2118
|
}
|
|
2119
|
+
if (text === "/trust") {
|
|
2120
|
+
this.showTrustSelector();
|
|
2121
|
+
this.editor.setText("");
|
|
2122
|
+
return;
|
|
2123
|
+
}
|
|
1803
2124
|
if (text === "/login") {
|
|
1804
2125
|
this.showOAuthSelector("login");
|
|
1805
2126
|
this.editor.setText("");
|
|
@@ -1896,6 +2217,9 @@ export class InteractiveMode {
|
|
|
1896
2217
|
if (this.onInputCallback) {
|
|
1897
2218
|
this.onInputCallback(text);
|
|
1898
2219
|
}
|
|
2220
|
+
else {
|
|
2221
|
+
this.pendingUserInputs.push(text);
|
|
2222
|
+
}
|
|
1899
2223
|
this.editor.addToHistory?.(text);
|
|
1900
2224
|
};
|
|
1901
2225
|
}
|
|
@@ -1911,28 +2235,21 @@ export class InteractiveMode {
|
|
|
1911
2235
|
this.footer.invalidate();
|
|
1912
2236
|
switch (event.type) {
|
|
1913
2237
|
case "agent_start":
|
|
2238
|
+
this.pendingTools.clear();
|
|
2239
|
+
if (this.settingsManager.getShowTerminalProgress()) {
|
|
2240
|
+
this.ui.terminal.setProgress(true);
|
|
2241
|
+
}
|
|
1914
2242
|
// Restore main escape handler if retry handler is still active
|
|
1915
2243
|
// (retry success event fires later, but we need main handler now)
|
|
1916
2244
|
if (this.retryEscapeHandler) {
|
|
1917
2245
|
this.defaultEditor.onEscape = this.retryEscapeHandler;
|
|
1918
2246
|
this.retryEscapeHandler = undefined;
|
|
1919
2247
|
}
|
|
1920
|
-
if (this.
|
|
1921
|
-
this.
|
|
1922
|
-
this.retryLoader = undefined;
|
|
1923
|
-
}
|
|
1924
|
-
if (this.loadingAnimation) {
|
|
1925
|
-
this.loadingAnimation.stop();
|
|
2248
|
+
if (this.workingVisible) {
|
|
2249
|
+
this.showStatusIndicator(new WorkingStatusIndicator(this.ui, this.workingMessage ?? this.defaultWorkingMessage, this.workingIndicatorOptions));
|
|
1926
2250
|
}
|
|
1927
|
-
|
|
1928
|
-
|
|
1929
|
-
this.statusContainer.addChild(this.loadingAnimation);
|
|
1930
|
-
// Apply any pending working message queued before loader existed
|
|
1931
|
-
if (this.pendingWorkingMessage !== undefined) {
|
|
1932
|
-
if (this.pendingWorkingMessage) {
|
|
1933
|
-
this.loadingAnimation.setMessage(this.pendingWorkingMessage);
|
|
1934
|
-
}
|
|
1935
|
-
this.pendingWorkingMessage = undefined;
|
|
2251
|
+
else {
|
|
2252
|
+
this.clearStatusIndicator();
|
|
1936
2253
|
}
|
|
1937
2254
|
this.ui.requestRender();
|
|
1938
2255
|
break;
|
|
@@ -1940,6 +2257,21 @@ export class InteractiveMode {
|
|
|
1940
2257
|
this.updatePendingMessagesDisplay();
|
|
1941
2258
|
this.ui.requestRender();
|
|
1942
2259
|
break;
|
|
2260
|
+
case "entry_appended":
|
|
2261
|
+
if (event.entry.type === "custom") {
|
|
2262
|
+
this.addCustomEntryToChat(event.entry);
|
|
2263
|
+
this.ui.requestRender();
|
|
2264
|
+
}
|
|
2265
|
+
break;
|
|
2266
|
+
case "session_info_changed":
|
|
2267
|
+
this.updateTerminalTitle();
|
|
2268
|
+
this.footer.invalidate();
|
|
2269
|
+
this.ui.requestRender();
|
|
2270
|
+
break;
|
|
2271
|
+
case "thinking_level_changed":
|
|
2272
|
+
this.footer.invalidate();
|
|
2273
|
+
this.updateEditorBorderColor();
|
|
2274
|
+
break;
|
|
1943
2275
|
case "message_start":
|
|
1944
2276
|
if (event.message.role === "custom") {
|
|
1945
2277
|
this.addMessageToChat(event.message);
|
|
@@ -1951,7 +2283,7 @@ export class InteractiveMode {
|
|
|
1951
2283
|
this.ui.requestRender();
|
|
1952
2284
|
}
|
|
1953
2285
|
else if (event.message.role === "assistant") {
|
|
1954
|
-
this.streamingComponent = new AssistantMessageComponent(undefined, this.hideThinkingBlock, this.getMarkdownThemeWithSettings(), this.hiddenThinkingLabel);
|
|
2286
|
+
this.streamingComponent = new AssistantMessageComponent(undefined, this.hideThinkingBlock, this.getMarkdownThemeWithSettings(), this.hiddenThinkingLabel, this.outputPad);
|
|
1955
2287
|
this.streamingMessage = event.message;
|
|
1956
2288
|
this.chatContainer.addChild(this.streamingComponent);
|
|
1957
2289
|
this.streamingComponent.updateContent(this.streamingMessage);
|
|
@@ -1967,6 +2299,7 @@ export class InteractiveMode {
|
|
|
1967
2299
|
if (!this.pendingTools.has(content.id)) {
|
|
1968
2300
|
const component = new ToolExecutionComponent(content.name, content.id, content.arguments, {
|
|
1969
2301
|
showImages: this.settingsManager.getShowImages(),
|
|
2302
|
+
imageWidthCells: this.settingsManager.getImageWidthCells(),
|
|
1970
2303
|
}, this.getRegisteredToolDefinition(content.name), this.ui, this.sessionManager.getCwd());
|
|
1971
2304
|
component.setExpanded(this.toolOutputExpanded);
|
|
1972
2305
|
this.chatContainer.addChild(component);
|
|
@@ -2027,6 +2360,7 @@ export class InteractiveMode {
|
|
|
2027
2360
|
if (!component) {
|
|
2028
2361
|
component = new ToolExecutionComponent(event.toolName, event.toolCallId, event.args, {
|
|
2029
2362
|
showImages: this.settingsManager.getShowImages(),
|
|
2363
|
+
imageWidthCells: this.settingsManager.getImageWidthCells(),
|
|
2030
2364
|
}, this.getRegisteredToolDefinition(event.toolName), this.ui, this.sessionManager.getCwd());
|
|
2031
2365
|
component.setExpanded(this.toolOutputExpanded);
|
|
2032
2366
|
this.chatContainer.addChild(component);
|
|
@@ -2054,11 +2388,10 @@ export class InteractiveMode {
|
|
|
2054
2388
|
break;
|
|
2055
2389
|
}
|
|
2056
2390
|
case "agent_end":
|
|
2057
|
-
if (this.
|
|
2058
|
-
this.
|
|
2059
|
-
this.loadingAnimation = undefined;
|
|
2060
|
-
this.statusContainer.clear();
|
|
2391
|
+
if (this.settingsManager.getShowTerminalProgress()) {
|
|
2392
|
+
this.ui.terminal.setProgress(false);
|
|
2061
2393
|
}
|
|
2394
|
+
this.clearStatusIndicator("working");
|
|
2062
2395
|
if (this.streamingComponent) {
|
|
2063
2396
|
this.chatContainer.removeChild(this.streamingComponent);
|
|
2064
2397
|
this.streamingComponent = undefined;
|
|
@@ -2069,31 +2402,27 @@ export class InteractiveMode {
|
|
|
2069
2402
|
this.ui.requestRender();
|
|
2070
2403
|
break;
|
|
2071
2404
|
case "compaction_start": {
|
|
2405
|
+
if (this.settingsManager.getShowTerminalProgress()) {
|
|
2406
|
+
this.ui.terminal.setProgress(true);
|
|
2407
|
+
}
|
|
2072
2408
|
// Keep editor active; submissions are queued during compaction.
|
|
2073
2409
|
this.autoCompactionEscapeHandler = this.defaultEditor.onEscape;
|
|
2074
2410
|
this.defaultEditor.onEscape = () => {
|
|
2075
2411
|
this.session.abortCompaction();
|
|
2076
2412
|
};
|
|
2077
|
-
this.
|
|
2078
|
-
const cancelHint = `(${keyText("app.interrupt")} to cancel)`;
|
|
2079
|
-
const label = event.reason === "manual"
|
|
2080
|
-
? `Compacting context... ${cancelHint}`
|
|
2081
|
-
: `${event.reason === "overflow" ? "Context overflow detected, " : ""}Auto-compacting... ${cancelHint}`;
|
|
2082
|
-
this.autoCompactionLoader = new Loader(this.ui, (spinner) => theme.fg("accent", spinner), (text) => theme.fg("muted", text), label);
|
|
2083
|
-
this.statusContainer.addChild(this.autoCompactionLoader);
|
|
2413
|
+
this.showStatusIndicator(new CompactionStatusIndicator(this.ui, event.reason));
|
|
2084
2414
|
this.ui.requestRender();
|
|
2085
2415
|
break;
|
|
2086
2416
|
}
|
|
2087
2417
|
case "compaction_end": {
|
|
2418
|
+
if (this.settingsManager.getShowTerminalProgress()) {
|
|
2419
|
+
this.ui.terminal.setProgress(false);
|
|
2420
|
+
}
|
|
2088
2421
|
if (this.autoCompactionEscapeHandler) {
|
|
2089
2422
|
this.defaultEditor.onEscape = this.autoCompactionEscapeHandler;
|
|
2090
2423
|
this.autoCompactionEscapeHandler = undefined;
|
|
2091
2424
|
}
|
|
2092
|
-
|
|
2093
|
-
this.autoCompactionLoader.stop();
|
|
2094
|
-
this.autoCompactionLoader = undefined;
|
|
2095
|
-
this.statusContainer.clear();
|
|
2096
|
-
}
|
|
2425
|
+
this.clearStatusIndicator("compaction");
|
|
2097
2426
|
if (event.aborted) {
|
|
2098
2427
|
if (event.reason === "manual") {
|
|
2099
2428
|
this.showError("Compaction cancelled");
|
|
@@ -2127,11 +2456,7 @@ export class InteractiveMode {
|
|
|
2127
2456
|
this.defaultEditor.onEscape = () => {
|
|
2128
2457
|
this.session.abortRetry();
|
|
2129
2458
|
};
|
|
2130
|
-
|
|
2131
|
-
this.statusContainer.clear();
|
|
2132
|
-
const delaySeconds = Math.round(event.delayMs / 1000);
|
|
2133
|
-
this.retryLoader = new Loader(this.ui, (spinner) => theme.fg("warning", spinner), (text) => theme.fg("muted", text), `Retrying (${event.attempt}/${event.maxAttempts}) in ${delaySeconds}s... (${keyText("app.interrupt")} to cancel)`);
|
|
2134
|
-
this.statusContainer.addChild(this.retryLoader);
|
|
2459
|
+
this.showStatusIndicator(new RetryStatusIndicator(this.ui, event.attempt, event.maxAttempts, event.delayMs));
|
|
2135
2460
|
this.ui.requestRender();
|
|
2136
2461
|
break;
|
|
2137
2462
|
}
|
|
@@ -2141,12 +2466,7 @@ export class InteractiveMode {
|
|
|
2141
2466
|
this.defaultEditor.onEscape = this.retryEscapeHandler;
|
|
2142
2467
|
this.retryEscapeHandler = undefined;
|
|
2143
2468
|
}
|
|
2144
|
-
|
|
2145
|
-
if (this.retryLoader) {
|
|
2146
|
-
this.retryLoader.stop();
|
|
2147
|
-
this.retryLoader = undefined;
|
|
2148
|
-
this.statusContainer.clear();
|
|
2149
|
-
}
|
|
2469
|
+
this.clearStatusIndicator("retry");
|
|
2150
2470
|
// Show error only on final failure (success shows normal response)
|
|
2151
2471
|
if (!event.success) {
|
|
2152
2472
|
this.showError(`Retry failed after ${event.attempt} attempts: ${event.finalError || "Unknown error"}`);
|
|
@@ -2188,6 +2508,25 @@ export class InteractiveMode {
|
|
|
2188
2508
|
this.lastStatusText = text;
|
|
2189
2509
|
this.ui.requestRender();
|
|
2190
2510
|
}
|
|
2511
|
+
addCustomEntryToChat(entry) {
|
|
2512
|
+
const renderer = this.session.extensionRunner.getEntryRenderer(entry.customType);
|
|
2513
|
+
if (!renderer) {
|
|
2514
|
+
return;
|
|
2515
|
+
}
|
|
2516
|
+
const component = new CustomEntryComponent(entry, renderer);
|
|
2517
|
+
component.setExpanded(this.toolOutputExpanded);
|
|
2518
|
+
if (!component.hasContent()) {
|
|
2519
|
+
return;
|
|
2520
|
+
}
|
|
2521
|
+
if (this.streamingComponent) {
|
|
2522
|
+
const streamingIndex = this.chatContainer.children.indexOf(this.streamingComponent);
|
|
2523
|
+
if (streamingIndex >= 0) {
|
|
2524
|
+
this.chatContainer.children.splice(streamingIndex, 0, component);
|
|
2525
|
+
return;
|
|
2526
|
+
}
|
|
2527
|
+
}
|
|
2528
|
+
this.chatContainer.addChild(component);
|
|
2529
|
+
}
|
|
2191
2530
|
addMessageToChat(message, options) {
|
|
2192
2531
|
switch (message.role) {
|
|
2193
2532
|
case "bashExecution": {
|
|
@@ -2201,7 +2540,7 @@ export class InteractiveMode {
|
|
|
2201
2540
|
}
|
|
2202
2541
|
case "custom": {
|
|
2203
2542
|
if (message.display) {
|
|
2204
|
-
const renderer = this.session.extensionRunner
|
|
2543
|
+
const renderer = this.session.extensionRunner.getMessageRenderer(message.customType);
|
|
2205
2544
|
const component = new CustomMessageComponent(message, renderer, this.getMarkdownThemeWithSettings());
|
|
2206
2545
|
component.setExpanded(this.toolOutputExpanded);
|
|
2207
2546
|
this.chatContainer.addChild(component);
|
|
@@ -2225,21 +2564,24 @@ export class InteractiveMode {
|
|
|
2225
2564
|
case "user": {
|
|
2226
2565
|
const textContent = this.getUserMessageText(message);
|
|
2227
2566
|
if (textContent) {
|
|
2567
|
+
if (this.chatContainer.children.length > 0) {
|
|
2568
|
+
this.chatContainer.addChild(new Spacer(1));
|
|
2569
|
+
}
|
|
2228
2570
|
const skillBlock = parseSkillBlock(textContent);
|
|
2229
2571
|
if (skillBlock) {
|
|
2230
2572
|
// Render skill block (collapsible)
|
|
2231
|
-
this.chatContainer.addChild(new Spacer(1));
|
|
2232
2573
|
const component = new SkillInvocationMessageComponent(skillBlock, this.getMarkdownThemeWithSettings());
|
|
2233
2574
|
component.setExpanded(this.toolOutputExpanded);
|
|
2234
2575
|
this.chatContainer.addChild(component);
|
|
2235
2576
|
// Render user message separately if present
|
|
2236
2577
|
if (skillBlock.userMessage) {
|
|
2237
|
-
|
|
2578
|
+
this.chatContainer.addChild(new Spacer(1));
|
|
2579
|
+
const userComponent = new UserMessageComponent(skillBlock.userMessage, this.getMarkdownThemeWithSettings(), this.outputPad);
|
|
2238
2580
|
this.chatContainer.addChild(userComponent);
|
|
2239
2581
|
}
|
|
2240
2582
|
}
|
|
2241
2583
|
else {
|
|
2242
|
-
const userComponent = new UserMessageComponent(textContent, this.getMarkdownThemeWithSettings());
|
|
2584
|
+
const userComponent = new UserMessageComponent(textContent, this.getMarkdownThemeWithSettings(), this.outputPad);
|
|
2243
2585
|
this.chatContainer.addChild(userComponent);
|
|
2244
2586
|
}
|
|
2245
2587
|
if (options?.populateHistory) {
|
|
@@ -2249,7 +2591,7 @@ export class InteractiveMode {
|
|
|
2249
2591
|
break;
|
|
2250
2592
|
}
|
|
2251
2593
|
case "assistant": {
|
|
2252
|
-
const assistantComponent = new AssistantMessageComponent(message, this.hideThinkingBlock, this.getMarkdownThemeWithSettings(), this.hiddenThinkingLabel);
|
|
2594
|
+
const assistantComponent = new AssistantMessageComponent(message, this.hideThinkingBlock, this.getMarkdownThemeWithSettings(), this.hiddenThinkingLabel, this.outputPad);
|
|
2253
2595
|
this.chatContainer.addChild(assistantComponent);
|
|
2254
2596
|
break;
|
|
2255
2597
|
}
|
|
@@ -2262,26 +2604,29 @@ export class InteractiveMode {
|
|
|
2262
2604
|
}
|
|
2263
2605
|
}
|
|
2264
2606
|
}
|
|
2265
|
-
|
|
2266
|
-
* Render session context to chat. Used for initial load and rebuild after compaction.
|
|
2267
|
-
* @param sessionContext Session context to render
|
|
2268
|
-
* @param options.updateFooter Update footer state
|
|
2269
|
-
* @param options.populateHistory Add user messages to editor history
|
|
2270
|
-
*/
|
|
2271
|
-
renderSessionContext(sessionContext, options = {}) {
|
|
2607
|
+
renderSessionItems(items, options = {}) {
|
|
2272
2608
|
this.pendingTools.clear();
|
|
2609
|
+
const renderedPendingTools = new Map();
|
|
2273
2610
|
if (options.updateFooter) {
|
|
2274
2611
|
this.footer.invalidate();
|
|
2275
2612
|
this.updateEditorBorderColor();
|
|
2276
2613
|
}
|
|
2277
|
-
for (const
|
|
2614
|
+
for (const item of items) {
|
|
2615
|
+
if (isCustomSessionEntry(item)) {
|
|
2616
|
+
this.addCustomEntryToChat(item);
|
|
2617
|
+
continue;
|
|
2618
|
+
}
|
|
2619
|
+
const message = item;
|
|
2278
2620
|
// Assistant messages need special handling for tool calls
|
|
2279
2621
|
if (message.role === "assistant") {
|
|
2280
2622
|
this.addMessageToChat(message);
|
|
2281
2623
|
// Render tool call components
|
|
2282
2624
|
for (const content of message.content) {
|
|
2283
2625
|
if (content.type === "toolCall") {
|
|
2284
|
-
const component = new ToolExecutionComponent(content.name, content.id, content.arguments, {
|
|
2626
|
+
const component = new ToolExecutionComponent(content.name, content.id, content.arguments, {
|
|
2627
|
+
showImages: this.settingsManager.getShowImages(),
|
|
2628
|
+
imageWidthCells: this.settingsManager.getImageWidthCells(),
|
|
2629
|
+
}, this.getRegisteredToolDefinition(content.name), this.ui, this.sessionManager.getCwd());
|
|
2285
2630
|
component.setExpanded(this.toolOutputExpanded);
|
|
2286
2631
|
this.chatContainer.addChild(component);
|
|
2287
2632
|
if (message.stopReason === "aborted" || message.stopReason === "error") {
|
|
@@ -2299,17 +2644,17 @@ export class InteractiveMode {
|
|
|
2299
2644
|
component.updateResult({ content: [{ type: "text", text: errorMessage }], isError: true });
|
|
2300
2645
|
}
|
|
2301
2646
|
else {
|
|
2302
|
-
|
|
2647
|
+
renderedPendingTools.set(content.id, component);
|
|
2303
2648
|
}
|
|
2304
2649
|
}
|
|
2305
2650
|
}
|
|
2306
2651
|
}
|
|
2307
2652
|
else if (message.role === "toolResult") {
|
|
2308
2653
|
// Match tool results to pending tool components
|
|
2309
|
-
const component =
|
|
2654
|
+
const component = renderedPendingTools.get(message.toolCallId);
|
|
2310
2655
|
if (component) {
|
|
2311
2656
|
component.updateResult(message);
|
|
2312
|
-
|
|
2657
|
+
renderedPendingTools.delete(message.toolCallId);
|
|
2313
2658
|
}
|
|
2314
2659
|
}
|
|
2315
2660
|
else {
|
|
@@ -2317,16 +2662,33 @@ export class InteractiveMode {
|
|
|
2317
2662
|
this.addMessageToChat(message, options);
|
|
2318
2663
|
}
|
|
2319
2664
|
}
|
|
2320
|
-
|
|
2665
|
+
for (const [toolCallId, component] of renderedPendingTools) {
|
|
2666
|
+
this.pendingTools.set(toolCallId, component);
|
|
2667
|
+
}
|
|
2321
2668
|
this.ui.requestRender();
|
|
2322
2669
|
}
|
|
2670
|
+
/**
|
|
2671
|
+
* Render session entries to chat. Used for initial load and rebuild after compaction.
|
|
2672
|
+
* @param entries Compaction-aware session entries to render
|
|
2673
|
+
* @param options.updateFooter Update footer state
|
|
2674
|
+
* @param options.populateHistory Add user messages to editor history
|
|
2675
|
+
*/
|
|
2676
|
+
renderSessionEntries(entries, options = {}) {
|
|
2677
|
+
const items = entries.flatMap((entry) => {
|
|
2678
|
+
if (entry.type === "custom") {
|
|
2679
|
+
return [entry];
|
|
2680
|
+
}
|
|
2681
|
+
return sessionEntryToContextMessages(entry);
|
|
2682
|
+
});
|
|
2683
|
+
this.renderSessionItems(items, options);
|
|
2684
|
+
}
|
|
2323
2685
|
renderInitialMessages() {
|
|
2324
|
-
|
|
2325
|
-
|
|
2326
|
-
this.renderSessionContext(context, {
|
|
2686
|
+
const entries = this.sessionManager.buildContextEntries();
|
|
2687
|
+
this.renderSessionEntries(entries, {
|
|
2327
2688
|
updateFooter: true,
|
|
2328
2689
|
populateHistory: true,
|
|
2329
2690
|
});
|
|
2691
|
+
this.renderProjectTrustWarningIfNeeded();
|
|
2330
2692
|
// Show compaction info if session was compacted
|
|
2331
2693
|
const allEntries = this.sessionManager.getEntries();
|
|
2332
2694
|
const compactionCount = allEntries.filter((e) => e.type === "compaction").length;
|
|
@@ -2335,7 +2697,20 @@ export class InteractiveMode {
|
|
|
2335
2697
|
this.showStatus(`Session compacted ${times}`);
|
|
2336
2698
|
}
|
|
2337
2699
|
}
|
|
2700
|
+
renderProjectTrustWarningIfNeeded() {
|
|
2701
|
+
if (this.settingsManager.isProjectTrusted() || !hasTrustRequiringProjectResources(this.sessionManager.getCwd())) {
|
|
2702
|
+
return;
|
|
2703
|
+
}
|
|
2704
|
+
if (this.chatContainer.children.length > 0) {
|
|
2705
|
+
this.chatContainer.addChild(new Spacer(1));
|
|
2706
|
+
}
|
|
2707
|
+
this.chatContainer.addChild(new Text(theme.fg("warning", `This project is not trusted. Project ${CONFIG_DIR_NAME} resources and packages are ignored. Use /trust to save a trust decision, then restart pi.`), 1, 0));
|
|
2708
|
+
}
|
|
2338
2709
|
async getUserInput() {
|
|
2710
|
+
const queuedInput = this.pendingUserInputs.shift();
|
|
2711
|
+
if (queuedInput !== undefined) {
|
|
2712
|
+
return queuedInput;
|
|
2713
|
+
}
|
|
2339
2714
|
return new Promise((resolve) => {
|
|
2340
2715
|
this.onInputCallback = (text) => {
|
|
2341
2716
|
this.onInputCallback = undefined;
|
|
@@ -2345,8 +2720,7 @@ export class InteractiveMode {
|
|
|
2345
2720
|
}
|
|
2346
2721
|
rebuildChatFromMessages() {
|
|
2347
2722
|
this.chatContainer.clear();
|
|
2348
|
-
|
|
2349
|
-
this.renderSessionContext(context);
|
|
2723
|
+
this.renderSessionEntries(this.sessionManager.buildContextEntries());
|
|
2350
2724
|
}
|
|
2351
2725
|
// =========================================================================
|
|
2352
2726
|
// Key handlers
|
|
@@ -2367,22 +2741,85 @@ export class InteractiveMode {
|
|
|
2367
2741
|
}
|
|
2368
2742
|
/**
|
|
2369
2743
|
* Gracefully shutdown the agent.
|
|
2370
|
-
*
|
|
2744
|
+
* Stops the TUI before emitting shutdown events so extension UI cleanup cannot
|
|
2745
|
+
* repaint the final frame while the process is exiting.
|
|
2371
2746
|
*/
|
|
2372
2747
|
isShuttingDown = false;
|
|
2373
|
-
async shutdown() {
|
|
2748
|
+
async shutdown(options) {
|
|
2374
2749
|
if (this.isShuttingDown)
|
|
2375
2750
|
return;
|
|
2376
2751
|
this.isShuttingDown = true;
|
|
2377
|
-
|
|
2378
|
-
//
|
|
2379
|
-
//
|
|
2380
|
-
|
|
2752
|
+
// Keep signal handlers registered until terminal cleanup has completed.
|
|
2753
|
+
// `signal-exit` checks the listener list during the same SIGTERM/SIGHUP
|
|
2754
|
+
// dispatch and re-sends the signal if only its own listeners remain.
|
|
2755
|
+
if (options?.fromSignal) {
|
|
2756
|
+
// Signal-triggered shutdown (SIGTERM/SIGHUP). Emit extension cleanup
|
|
2757
|
+
// (session_shutdown) BEFORE touching the terminal. Extension teardown
|
|
2758
|
+
// such as removing sockets does not write to the tty, so it must not be
|
|
2759
|
+
// skipped if a later terminal-restore write fails on a dead or stalled
|
|
2760
|
+
// terminal. If the terminal is gone, the restore writes below emit EIO,
|
|
2761
|
+
// which the stdout/stderr error handler turns into emergencyTerminalExit;
|
|
2762
|
+
// the render loop is already idle, so this cannot hot-spin (see #4144).
|
|
2763
|
+
await this.runtimeHost.dispose();
|
|
2764
|
+
this.themeController.disableAutoSync();
|
|
2765
|
+
await this.ui.terminal.drainInput(1000);
|
|
2766
|
+
this.stop();
|
|
2767
|
+
process.exit(0);
|
|
2768
|
+
}
|
|
2769
|
+
// Interactive quit (Ctrl+D, Ctrl+C, /quit, extension shutdown()). Stop the
|
|
2770
|
+
// TUI before emitting shutdown events so extension UI cleanup cannot repaint
|
|
2771
|
+
// the final frame while the process is exiting.
|
|
2381
2772
|
// Drain any in-flight Kitty key release events before stopping.
|
|
2382
2773
|
// This prevents escape sequences from leaking to the parent shell over slow SSH.
|
|
2774
|
+
this.themeController.disableAutoSync();
|
|
2383
2775
|
await this.ui.terminal.drainInput(1000);
|
|
2384
2776
|
this.stop();
|
|
2385
|
-
|
|
2777
|
+
await this.runtimeHost.dispose();
|
|
2778
|
+
const resumeCommand = formatResumeCommand(this.sessionManager);
|
|
2779
|
+
if (resumeCommand) {
|
|
2780
|
+
process.stdout.write(`${chalk.dim("To resume this session:")} ${resumeCommand}\n`);
|
|
2781
|
+
}
|
|
2782
|
+
process.exit(0);
|
|
2783
|
+
}
|
|
2784
|
+
emergencyTerminalExit() {
|
|
2785
|
+
this.isShuttingDown = true;
|
|
2786
|
+
this.unregisterSignalHandlers();
|
|
2787
|
+
killTrackedDetachedChildren();
|
|
2788
|
+
// The terminal is gone. Do not run normal shutdown because TUI and
|
|
2789
|
+
// extension cleanup can write restore sequences and re-trigger EIO.
|
|
2790
|
+
process.exit(129);
|
|
2791
|
+
}
|
|
2792
|
+
/**
|
|
2793
|
+
* Last-resort handler for uncaught exceptions. The TUI puts stdin into raw
|
|
2794
|
+
* mode and hides the cursor; without this handler, an uncaught throw from
|
|
2795
|
+
* anywhere (e.g. an extension's async `ChildProcess.on("exit")` callback)
|
|
2796
|
+
* tears down the process while leaving the terminal in raw mode with no
|
|
2797
|
+
* cursor, requiring `stty sane && reset` to recover.
|
|
2798
|
+
*
|
|
2799
|
+
* Unlike emergencyTerminalExit, the terminal is still alive here, so we
|
|
2800
|
+
* call ui.stop() to restore cooked mode, the cursor, and disable bracketed
|
|
2801
|
+
* paste / Kitty / modifyOtherKeys sequences.
|
|
2802
|
+
*/
|
|
2803
|
+
uncaughtCrash(error) {
|
|
2804
|
+
if (this.isShuttingDown) {
|
|
2805
|
+
process.exit(1);
|
|
2806
|
+
}
|
|
2807
|
+
this.isShuttingDown = true;
|
|
2808
|
+
try {
|
|
2809
|
+
this.unregisterSignalHandlers();
|
|
2810
|
+
}
|
|
2811
|
+
catch { }
|
|
2812
|
+
try {
|
|
2813
|
+
killTrackedDetachedChildren();
|
|
2814
|
+
}
|
|
2815
|
+
catch { }
|
|
2816
|
+
try {
|
|
2817
|
+
this.ui.stop();
|
|
2818
|
+
}
|
|
2819
|
+
catch { }
|
|
2820
|
+
console.error("pi exiting due to uncaughtException:");
|
|
2821
|
+
console.error(error);
|
|
2822
|
+
process.exit(1);
|
|
2386
2823
|
}
|
|
2387
2824
|
/**
|
|
2388
2825
|
* Check if shutdown was requested and perform shutdown if so.
|
|
@@ -2392,7 +2829,52 @@ export class InteractiveMode {
|
|
|
2392
2829
|
return;
|
|
2393
2830
|
await this.shutdown();
|
|
2394
2831
|
}
|
|
2832
|
+
registerSignalHandlers() {
|
|
2833
|
+
this.unregisterSignalHandlers();
|
|
2834
|
+
const signals = ["SIGTERM"];
|
|
2835
|
+
if (process.platform !== "win32") {
|
|
2836
|
+
signals.push("SIGHUP");
|
|
2837
|
+
}
|
|
2838
|
+
for (const signal of signals) {
|
|
2839
|
+
const handler = () => {
|
|
2840
|
+
// SIGHUP no longer hard-exits: graceful shutdown emits session_shutdown
|
|
2841
|
+
// first, then attempts terminal restore. A genuinely dead terminal
|
|
2842
|
+
// surfaces as an EIO on the restore writes, which the stdout/stderr
|
|
2843
|
+
// error handler converts into emergencyTerminalExit (see #4144, #5080).
|
|
2844
|
+
killTrackedDetachedChildren();
|
|
2845
|
+
void this.shutdown({ fromSignal: true });
|
|
2846
|
+
};
|
|
2847
|
+
process.prependListener(signal, handler);
|
|
2848
|
+
this.signalCleanupHandlers.push(() => process.off(signal, handler));
|
|
2849
|
+
}
|
|
2850
|
+
const terminalErrorHandler = (error) => {
|
|
2851
|
+
if (isDeadTerminalError(error)) {
|
|
2852
|
+
this.emergencyTerminalExit();
|
|
2853
|
+
}
|
|
2854
|
+
throw error;
|
|
2855
|
+
};
|
|
2856
|
+
process.stdout.on("error", terminalErrorHandler);
|
|
2857
|
+
process.stderr.on("error", terminalErrorHandler);
|
|
2858
|
+
this.signalCleanupHandlers.push(() => process.stdout.off("error", terminalErrorHandler));
|
|
2859
|
+
this.signalCleanupHandlers.push(() => process.stderr.off("error", terminalErrorHandler));
|
|
2860
|
+
// Restore the terminal before the process dies on any uncaught throw.
|
|
2861
|
+
// Without this, an unhandled exception from extension code (or anywhere
|
|
2862
|
+
// in pi) leaves the terminal in raw mode with no cursor.
|
|
2863
|
+
const uncaughtExceptionHandler = (error) => this.uncaughtCrash(error);
|
|
2864
|
+
process.prependListener("uncaughtException", uncaughtExceptionHandler);
|
|
2865
|
+
this.signalCleanupHandlers.push(() => process.off("uncaughtException", uncaughtExceptionHandler));
|
|
2866
|
+
}
|
|
2867
|
+
unregisterSignalHandlers() {
|
|
2868
|
+
for (const cleanup of this.signalCleanupHandlers) {
|
|
2869
|
+
cleanup();
|
|
2870
|
+
}
|
|
2871
|
+
this.signalCleanupHandlers = [];
|
|
2872
|
+
}
|
|
2395
2873
|
handleCtrlZ() {
|
|
2874
|
+
if (process.platform === "win32") {
|
|
2875
|
+
this.showStatus("Suspend to background is not supported on Windows");
|
|
2876
|
+
return;
|
|
2877
|
+
}
|
|
2396
2878
|
// Keep the event loop alive while suspended. Without this, stopping the TUI
|
|
2397
2879
|
// can leave Node with no ref'ed handles, causing the process to exit on fg
|
|
2398
2880
|
// before the SIGCONT handler gets a chance to restore the terminal.
|
|
@@ -2447,6 +2929,7 @@ export class InteractiveMode {
|
|
|
2447
2929
|
}
|
|
2448
2930
|
// If not streaming, Alt+Enter acts like regular Enter (trigger onSubmit)
|
|
2449
2931
|
else if (this.editor.onSubmit) {
|
|
2932
|
+
this.editor.setText("");
|
|
2450
2933
|
this.editor.onSubmit(text);
|
|
2451
2934
|
}
|
|
2452
2935
|
}
|
|
@@ -2504,9 +2987,15 @@ export class InteractiveMode {
|
|
|
2504
2987
|
}
|
|
2505
2988
|
setToolsExpanded(expanded) {
|
|
2506
2989
|
this.toolOutputExpanded = expanded;
|
|
2507
|
-
|
|
2508
|
-
|
|
2509
|
-
|
|
2990
|
+
const activeHeader = this.customHeader ?? this.builtInHeader;
|
|
2991
|
+
if (isExpandable(activeHeader)) {
|
|
2992
|
+
activeHeader.setExpanded(expanded);
|
|
2993
|
+
}
|
|
2994
|
+
for (const container of [this.loadedResourcesContainer, this.chatContainer]) {
|
|
2995
|
+
for (const child of container.children) {
|
|
2996
|
+
if (isExpandable(child)) {
|
|
2997
|
+
child.setExpanded(expanded);
|
|
2998
|
+
}
|
|
2510
2999
|
}
|
|
2511
3000
|
}
|
|
2512
3001
|
this.ui.requestRender();
|
|
@@ -2525,11 +3014,10 @@ export class InteractiveMode {
|
|
|
2525
3014
|
}
|
|
2526
3015
|
this.showStatus(`Thinking blocks: ${this.hideThinkingBlock ? "hidden" : "visible"}`);
|
|
2527
3016
|
}
|
|
2528
|
-
openExternalEditor() {
|
|
2529
|
-
|
|
2530
|
-
const editorCmd = process.env.VISUAL || process.env.EDITOR;
|
|
3017
|
+
async openExternalEditor() {
|
|
3018
|
+
const editorCmd = this.settingsManager.getExternalEditorCommand();
|
|
2531
3019
|
if (!editorCmd) {
|
|
2532
|
-
this.showWarning("No editor configured. Set
|
|
3020
|
+
this.showWarning("No editor configured. Set externalEditor in settings.json or $VISUAL/$EDITOR.");
|
|
2533
3021
|
return;
|
|
2534
3022
|
}
|
|
2535
3023
|
const currentText = this.editor.getExpandedText?.() ?? this.editor.getText();
|
|
@@ -2541,13 +3029,20 @@ export class InteractiveMode {
|
|
|
2541
3029
|
this.ui.stop();
|
|
2542
3030
|
// Split by space to support editor arguments (e.g., "code --wait")
|
|
2543
3031
|
const [editor, ...editorArgs] = editorCmd.split(" ");
|
|
2544
|
-
|
|
2545
|
-
|
|
2546
|
-
|
|
2547
|
-
|
|
3032
|
+
process.stdout.write(`Launching external editor: ${editorCmd}\nPi will resume when the editor exits.\n`);
|
|
3033
|
+
// Do not use spawnSync here. On Windows, synchronous child_process calls can keep
|
|
3034
|
+
// Node/libuv's console input read active after ui.stop() pauses stdin, racing
|
|
3035
|
+
// vim/nvim for the console input buffer until Ctrl+C cancels the pending read.
|
|
3036
|
+
const status = await new Promise((resolve) => {
|
|
3037
|
+
const child = spawn(editor, [...editorArgs, tmpFile], {
|
|
3038
|
+
stdio: "inherit",
|
|
3039
|
+
shell: process.platform === "win32",
|
|
3040
|
+
});
|
|
3041
|
+
child.on("error", () => resolve(null));
|
|
3042
|
+
child.on("close", (code) => resolve(code));
|
|
2548
3043
|
});
|
|
2549
3044
|
// On successful exit (status 0), replace editor content
|
|
2550
|
-
if (
|
|
3045
|
+
if (status === 0) {
|
|
2551
3046
|
const newContent = fs.readFileSync(tmpFile, "utf-8").replace(/\n$/, "");
|
|
2552
3047
|
this.editor.setText(newContent);
|
|
2553
3048
|
}
|
|
@@ -2584,19 +3079,31 @@ export class InteractiveMode {
|
|
|
2584
3079
|
this.chatContainer.addChild(new Text(theme.fg("warning", `Warning: ${warningMessage}`), 1, 0));
|
|
2585
3080
|
this.ui.requestRender();
|
|
2586
3081
|
}
|
|
2587
|
-
showNewVersionNotification(
|
|
2588
|
-
const action = theme.fg("accent",
|
|
2589
|
-
const updateInstruction = theme.fg("muted", `New version ${
|
|
2590
|
-
const changelogUrl =
|
|
2591
|
-
const
|
|
3082
|
+
showNewVersionNotification(release) {
|
|
3083
|
+
const action = theme.fg("accent", `${APP_NAME} update`);
|
|
3084
|
+
const updateInstruction = theme.fg("muted", `New version ${release.version} is available. Run `) + action;
|
|
3085
|
+
const changelogUrl = "https://pi.dev/changelog";
|
|
3086
|
+
const changelogLink = getCapabilities().hyperlinks
|
|
3087
|
+
? hyperlink(theme.fg("accent", changelogUrl), changelogUrl)
|
|
3088
|
+
: theme.fg("accent", changelogUrl);
|
|
3089
|
+
const changelogLine = theme.fg("muted", "Changelog: ") + changelogLink;
|
|
3090
|
+
const note = release.note?.trim();
|
|
2592
3091
|
this.chatContainer.addChild(new Spacer(1));
|
|
2593
3092
|
this.chatContainer.addChild(new DynamicBorder((text) => theme.fg("warning", text)));
|
|
2594
|
-
this.chatContainer.addChild(new Text(`${theme.bold(theme.fg("warning", "Update Available"))}\n${updateInstruction}
|
|
3093
|
+
this.chatContainer.addChild(new Text(`${theme.bold(theme.fg("warning", "Update Available"))}\n${updateInstruction}`, 1, 0));
|
|
3094
|
+
if (note) {
|
|
3095
|
+
this.chatContainer.addChild(new Spacer(1));
|
|
3096
|
+
this.chatContainer.addChild(new Markdown(note, 1, 0, this.getMarkdownThemeWithSettings(), {
|
|
3097
|
+
color: (text) => theme.fg("muted", text),
|
|
3098
|
+
}));
|
|
3099
|
+
this.chatContainer.addChild(new Spacer(1));
|
|
3100
|
+
}
|
|
3101
|
+
this.chatContainer.addChild(new Text(changelogLine, 1, 0));
|
|
2595
3102
|
this.chatContainer.addChild(new DynamicBorder((text) => theme.fg("warning", text)));
|
|
2596
3103
|
this.ui.requestRender();
|
|
2597
3104
|
}
|
|
2598
3105
|
showPackageUpdateNotification(packages) {
|
|
2599
|
-
const action = theme.fg("accent", `${APP_NAME} update`);
|
|
3106
|
+
const action = theme.fg("accent", `${APP_NAME} update --extensions`);
|
|
2600
3107
|
const updateInstruction = theme.fg("muted", "Package updates are available. Run ") + action;
|
|
2601
3108
|
const packageLines = packages.map((pkg) => `- ${pkg}`).join("\n");
|
|
2602
3109
|
this.chatContainer.addChild(new Spacer(1));
|
|
@@ -2688,8 +3195,6 @@ export class InteractiveMode {
|
|
|
2688
3195
|
if (!text.startsWith("/"))
|
|
2689
3196
|
return false;
|
|
2690
3197
|
const extensionRunner = this.session.extensionRunner;
|
|
2691
|
-
if (!extensionRunner)
|
|
2692
|
-
return false;
|
|
2693
3198
|
const spaceIndex = text.indexOf(" ");
|
|
2694
3199
|
const commandName = spaceIndex === -1 ? text.slice(1) : text.slice(1, spaceIndex);
|
|
2695
3200
|
return !!extensionRunner.getCommand(commandName);
|
|
@@ -2795,25 +3300,33 @@ export class InteractiveMode {
|
|
|
2795
3300
|
const selector = new SettingsSelectorComponent({
|
|
2796
3301
|
autoCompact: this.session.autoCompactionEnabled,
|
|
2797
3302
|
showImages: this.settingsManager.getShowImages(),
|
|
3303
|
+
imageWidthCells: this.settingsManager.getImageWidthCells(),
|
|
2798
3304
|
autoResizeImages: this.settingsManager.getImageAutoResize(),
|
|
2799
3305
|
blockImages: this.settingsManager.getBlockImages(),
|
|
2800
3306
|
enableSkillCommands: this.settingsManager.getEnableSkillCommands(),
|
|
2801
3307
|
steeringMode: this.session.steeringMode,
|
|
2802
3308
|
followUpMode: this.session.followUpMode,
|
|
2803
3309
|
transport: this.settingsManager.getTransport(),
|
|
3310
|
+
httpIdleTimeoutMs: this.settingsManager.getHttpIdleTimeoutMs(),
|
|
2804
3311
|
thinkingLevel: this.session.thinkingLevel,
|
|
2805
3312
|
availableThinkingLevels: this.session.getAvailableThinkingLevels(),
|
|
2806
|
-
currentTheme: this.settingsManager.
|
|
3313
|
+
currentTheme: this.settingsManager.getThemeSetting() || "dark",
|
|
3314
|
+
terminalTheme: this.themeController.getTerminalTheme(),
|
|
2807
3315
|
availableThemes: getAvailableThemes(),
|
|
2808
3316
|
hideThinkingBlock: this.hideThinkingBlock,
|
|
2809
3317
|
collapseChangelog: this.settingsManager.getCollapseChangelog(),
|
|
3318
|
+
enableInstallTelemetry: this.settingsManager.getEnableInstallTelemetry(),
|
|
2810
3319
|
doubleEscapeAction: this.settingsManager.getDoubleEscapeAction(),
|
|
2811
3320
|
treeFilterMode: this.settingsManager.getTreeFilterMode(),
|
|
2812
3321
|
showHardwareCursor: this.settingsManager.getShowHardwareCursor(),
|
|
3322
|
+
defaultProjectTrust: this.settingsManager.getDefaultProjectTrust(),
|
|
2813
3323
|
editorPaddingX: this.settingsManager.getEditorPaddingX(),
|
|
3324
|
+
outputPad: this.settingsManager.getOutputPad(),
|
|
2814
3325
|
autocompleteMaxVisible: this.settingsManager.getAutocompleteMaxVisible(),
|
|
2815
3326
|
quietStartup: this.settingsManager.getQuietStartup(),
|
|
2816
3327
|
clearOnShrink: this.settingsManager.getClearOnShrink(),
|
|
3328
|
+
showTerminalProgress: this.settingsManager.getShowTerminalProgress(),
|
|
3329
|
+
warnings: this.settingsManager.getWarnings(),
|
|
2817
3330
|
}, {
|
|
2818
3331
|
onAutoCompactChange: (enabled) => {
|
|
2819
3332
|
this.session.setAutoCompactionEnabled(enabled);
|
|
@@ -2827,6 +3340,14 @@ export class InteractiveMode {
|
|
|
2827
3340
|
}
|
|
2828
3341
|
}
|
|
2829
3342
|
},
|
|
3343
|
+
onImageWidthCellsChange: (width) => {
|
|
3344
|
+
this.settingsManager.setImageWidthCells(width);
|
|
3345
|
+
for (const child of this.chatContainer.children) {
|
|
3346
|
+
if (child instanceof ToolExecutionComponent) {
|
|
3347
|
+
child.setImageWidthCells(width);
|
|
3348
|
+
}
|
|
3349
|
+
}
|
|
3350
|
+
},
|
|
2830
3351
|
onAutoResizeImagesChange: (enabled) => {
|
|
2831
3352
|
this.settingsManager.setImageAutoResize(enabled);
|
|
2832
3353
|
},
|
|
@@ -2835,7 +3356,7 @@ export class InteractiveMode {
|
|
|
2835
3356
|
},
|
|
2836
3357
|
onEnableSkillCommandsChange: (enabled) => {
|
|
2837
3358
|
this.settingsManager.setEnableSkillCommands(enabled);
|
|
2838
|
-
this.
|
|
3359
|
+
this.setupAutocompleteProvider();
|
|
2839
3360
|
},
|
|
2840
3361
|
onSteeringModeChange: (mode) => {
|
|
2841
3362
|
this.session.setSteeringMode(mode);
|
|
@@ -2847,26 +3368,21 @@ export class InteractiveMode {
|
|
|
2847
3368
|
this.settingsManager.setTransport(transport);
|
|
2848
3369
|
this.session.agent.transport = transport;
|
|
2849
3370
|
},
|
|
3371
|
+
onHttpIdleTimeoutMsChange: (timeoutMs) => {
|
|
3372
|
+
this.settingsManager.setHttpIdleTimeoutMs(timeoutMs);
|
|
3373
|
+
configureHttpDispatcher(timeoutMs);
|
|
3374
|
+
this.showStatus(`HTTP idle timeout: ${formatHttpIdleTimeoutMs(timeoutMs)}`);
|
|
3375
|
+
},
|
|
2850
3376
|
onThinkingLevelChange: (level) => {
|
|
2851
3377
|
this.session.setThinkingLevel(level);
|
|
2852
3378
|
this.footer.invalidate();
|
|
2853
3379
|
this.updateEditorBorderColor();
|
|
2854
3380
|
},
|
|
2855
|
-
onThemeChange: (
|
|
2856
|
-
|
|
2857
|
-
this.
|
|
2858
|
-
this.ui.invalidate();
|
|
2859
|
-
if (!result.success) {
|
|
2860
|
-
this.showError(`Failed to load theme "${themeName}": ${result.error}\nFell back to dark theme.`);
|
|
2861
|
-
}
|
|
2862
|
-
},
|
|
2863
|
-
onThemePreview: (themeName) => {
|
|
2864
|
-
const result = setTheme(themeName, true);
|
|
2865
|
-
if (result.success) {
|
|
2866
|
-
this.ui.invalidate();
|
|
2867
|
-
this.ui.requestRender();
|
|
2868
|
-
}
|
|
3381
|
+
onThemeChange: (themeSetting) => {
|
|
3382
|
+
this.settingsManager.setTheme(themeSetting);
|
|
3383
|
+
void this.themeController.applyFromSettings();
|
|
2869
3384
|
},
|
|
3385
|
+
onThemePreview: (themeName) => this.themeController.preview(themeName),
|
|
2870
3386
|
onHideThinkingBlockChange: (hidden) => {
|
|
2871
3387
|
this.hideThinkingBlock = hidden;
|
|
2872
3388
|
this.settingsManager.setHideThinkingBlock(hidden);
|
|
@@ -2881,9 +3397,15 @@ export class InteractiveMode {
|
|
|
2881
3397
|
onCollapseChangelogChange: (collapsed) => {
|
|
2882
3398
|
this.settingsManager.setCollapseChangelog(collapsed);
|
|
2883
3399
|
},
|
|
3400
|
+
onEnableInstallTelemetryChange: (enabled) => {
|
|
3401
|
+
this.settingsManager.setEnableInstallTelemetry(enabled);
|
|
3402
|
+
},
|
|
2884
3403
|
onQuietStartupChange: (enabled) => {
|
|
2885
3404
|
this.settingsManager.setQuietStartup(enabled);
|
|
2886
3405
|
},
|
|
3406
|
+
onDefaultProjectTrustChange: (defaultProjectTrust) => {
|
|
3407
|
+
this.settingsManager.setDefaultProjectTrust(defaultProjectTrust);
|
|
3408
|
+
},
|
|
2887
3409
|
onDoubleEscapeActionChange: (action) => {
|
|
2888
3410
|
this.settingsManager.setDoubleEscapeAction(action);
|
|
2889
3411
|
},
|
|
@@ -2901,6 +3423,23 @@ export class InteractiveMode {
|
|
|
2901
3423
|
this.editor.setPaddingX(padding);
|
|
2902
3424
|
}
|
|
2903
3425
|
},
|
|
3426
|
+
onOutputPadChange: (padding) => {
|
|
3427
|
+
this.settingsManager.setOutputPad(padding);
|
|
3428
|
+
this.outputPad = padding;
|
|
3429
|
+
if (this.streamingComponent || this.session.isStreaming) {
|
|
3430
|
+
for (const child of this.chatContainer.children) {
|
|
3431
|
+
if (child instanceof AssistantMessageComponent || child instanceof UserMessageComponent) {
|
|
3432
|
+
child.setOutputPad(padding);
|
|
3433
|
+
}
|
|
3434
|
+
}
|
|
3435
|
+
if (this.streamingComponent) {
|
|
3436
|
+
this.streamingComponent.setOutputPad(padding);
|
|
3437
|
+
}
|
|
3438
|
+
this.ui.requestRender();
|
|
3439
|
+
return;
|
|
3440
|
+
}
|
|
3441
|
+
this.rebuildChatFromMessages();
|
|
3442
|
+
},
|
|
2904
3443
|
onAutocompleteMaxVisibleChange: (maxVisible) => {
|
|
2905
3444
|
this.settingsManager.setAutocompleteMaxVisible(maxVisible);
|
|
2906
3445
|
this.defaultEditor.setAutocompleteMaxVisible(maxVisible);
|
|
@@ -2911,6 +3450,15 @@ export class InteractiveMode {
|
|
|
2911
3450
|
onClearOnShrinkChange: (enabled) => {
|
|
2912
3451
|
this.settingsManager.setClearOnShrink(enabled);
|
|
2913
3452
|
this.ui.setClearOnShrink(enabled);
|
|
3453
|
+
if (!enabled && !this.activeStatusIndicator) {
|
|
3454
|
+
this.statusContainer.clear();
|
|
3455
|
+
}
|
|
3456
|
+
},
|
|
3457
|
+
onShowTerminalProgressChange: (enabled) => {
|
|
3458
|
+
this.settingsManager.setShowTerminalProgress(enabled);
|
|
3459
|
+
},
|
|
3460
|
+
onWarningsChange: (warnings) => {
|
|
3461
|
+
this.settingsManager.setWarnings(warnings);
|
|
2914
3462
|
},
|
|
2915
3463
|
onCancel: () => {
|
|
2916
3464
|
done();
|
|
@@ -2965,6 +3513,9 @@ export class InteractiveMode {
|
|
|
2965
3513
|
this.footerDataProvider.setAvailableProviderCount(uniqueProviders.size);
|
|
2966
3514
|
}
|
|
2967
3515
|
async maybeWarnAboutAnthropicSubscriptionAuth(model = this.session.model) {
|
|
3516
|
+
if (this.settingsManager.getWarnings().anthropicExtraUsage === false) {
|
|
3517
|
+
return;
|
|
3518
|
+
}
|
|
2968
3519
|
if (this.anthropicSubscriptionWarningShown) {
|
|
2969
3520
|
return;
|
|
2970
3521
|
}
|
|
@@ -2989,6 +3540,51 @@ export class InteractiveMode {
|
|
|
2989
3540
|
// Ignore auth lookup failures for warning-only checks.
|
|
2990
3541
|
}
|
|
2991
3542
|
}
|
|
3543
|
+
maybeSaveImplicitProjectTrustAfterReload() {
|
|
3544
|
+
const cwd = this.sessionManager.getCwd();
|
|
3545
|
+
if (this.autoTrustOnReloadCwd !== cwd) {
|
|
3546
|
+
return false;
|
|
3547
|
+
}
|
|
3548
|
+
if (!this.settingsManager.isProjectTrusted() || !hasTrustRequiringProjectResources(cwd)) {
|
|
3549
|
+
return false;
|
|
3550
|
+
}
|
|
3551
|
+
const trustStore = new ProjectTrustStore(this.runtimeHost.services.agentDir);
|
|
3552
|
+
try {
|
|
3553
|
+
if (trustStore.get(cwd) !== null) {
|
|
3554
|
+
this.autoTrustOnReloadCwd = undefined;
|
|
3555
|
+
return false;
|
|
3556
|
+
}
|
|
3557
|
+
trustStore.set(cwd, true);
|
|
3558
|
+
this.autoTrustOnReloadCwd = undefined;
|
|
3559
|
+
return true;
|
|
3560
|
+
}
|
|
3561
|
+
catch (error) {
|
|
3562
|
+
this.showWarning(`Could not save project trust after reload: ${error instanceof Error ? error.message : String(error)}`);
|
|
3563
|
+
return false;
|
|
3564
|
+
}
|
|
3565
|
+
}
|
|
3566
|
+
showTrustSelector() {
|
|
3567
|
+
const cwd = this.sessionManager.getCwd();
|
|
3568
|
+
const trustStore = new ProjectTrustStore(this.runtimeHost.services.agentDir);
|
|
3569
|
+
const savedDecision = trustStore.getEntry(cwd);
|
|
3570
|
+
this.showSelector((done) => {
|
|
3571
|
+
const selector = new TrustSelectorComponent({
|
|
3572
|
+
cwd,
|
|
3573
|
+
savedDecision,
|
|
3574
|
+
projectTrusted: this.settingsManager.isProjectTrusted(),
|
|
3575
|
+
onSelect: (selection) => {
|
|
3576
|
+
trustStore.setMany(selection.updates);
|
|
3577
|
+
done();
|
|
3578
|
+
this.showStatus(`Saved trust decision: ${selection.trusted ? "trusted" : "untrusted"}. Restart pi for this to take effect.`);
|
|
3579
|
+
},
|
|
3580
|
+
onCancel: () => {
|
|
3581
|
+
done();
|
|
3582
|
+
this.ui.requestRender();
|
|
3583
|
+
},
|
|
3584
|
+
});
|
|
3585
|
+
return { component: selector, focus: selector };
|
|
3586
|
+
});
|
|
3587
|
+
}
|
|
2992
3588
|
showModelSelector(initialSearchInput) {
|
|
2993
3589
|
this.showSelector((done) => {
|
|
2994
3590
|
const selector = new ModelSelectorComponent(this.ui, this.session.model, this.settingsManager, this.session.modelRegistry, this.session.scopedModels, async (model) => {
|
|
@@ -3024,33 +3620,24 @@ export class InteractiveMode {
|
|
|
3024
3620
|
const sessionScopedModels = this.session.scopedModels;
|
|
3025
3621
|
const hasSessionScope = sessionScopedModels.length > 0;
|
|
3026
3622
|
// Build enabled model IDs from session state or settings
|
|
3027
|
-
|
|
3028
|
-
let hasFilter = false;
|
|
3623
|
+
let currentEnabledIds = null;
|
|
3029
3624
|
if (hasSessionScope) {
|
|
3030
3625
|
// Use current session's scoped models
|
|
3031
|
-
|
|
3032
|
-
enabledModelIds.add(`${sm.model.provider}/${sm.model.id}`);
|
|
3033
|
-
}
|
|
3034
|
-
hasFilter = true;
|
|
3626
|
+
currentEnabledIds = sessionScopedModels.map((scoped) => `${scoped.model.provider}/${scoped.model.id}`);
|
|
3035
3627
|
}
|
|
3036
3628
|
else {
|
|
3037
3629
|
// Fall back to settings
|
|
3038
3630
|
const patterns = this.settingsManager.getEnabledModels();
|
|
3039
3631
|
if (patterns !== undefined && patterns.length > 0) {
|
|
3040
|
-
hasFilter = true;
|
|
3041
3632
|
const scopedModels = await resolveModelScope(patterns, this.session.modelRegistry);
|
|
3042
|
-
|
|
3043
|
-
enabledModelIds.add(`${sm.model.provider}/${sm.model.id}`);
|
|
3044
|
-
}
|
|
3633
|
+
currentEnabledIds = scopedModels.map((scoped) => `${scoped.model.provider}/${scoped.model.id}`);
|
|
3045
3634
|
}
|
|
3046
3635
|
}
|
|
3047
|
-
// Track current enabled state (session-only until persisted)
|
|
3048
|
-
const currentEnabledIds = new Set(enabledModelIds);
|
|
3049
|
-
let currentHasFilter = hasFilter;
|
|
3050
3636
|
// Helper to update session's scoped models (session-only, no persist)
|
|
3051
3637
|
const updateSessionModels = async (enabledIds) => {
|
|
3052
|
-
|
|
3053
|
-
|
|
3638
|
+
currentEnabledIds = enabledIds === null ? null : [...enabledIds];
|
|
3639
|
+
if (enabledIds && enabledIds.length > 0 && enabledIds.length < allModels.length) {
|
|
3640
|
+
const newScopedModels = await resolveModelScope(enabledIds, this.session.modelRegistry);
|
|
3054
3641
|
this.session.setScopedModels(newScopedModels.map((sm) => ({
|
|
3055
3642
|
model: sm.model,
|
|
3056
3643
|
thinkingLevel: sm.thinkingLevel,
|
|
@@ -3067,49 +3654,16 @@ export class InteractiveMode {
|
|
|
3067
3654
|
const selector = new ScopedModelsSelectorComponent({
|
|
3068
3655
|
allModels,
|
|
3069
3656
|
enabledModelIds: currentEnabledIds,
|
|
3070
|
-
hasEnabledModelsFilter: currentHasFilter,
|
|
3071
3657
|
}, {
|
|
3072
|
-
|
|
3073
|
-
|
|
3074
|
-
currentEnabledIds.add(modelId);
|
|
3075
|
-
}
|
|
3076
|
-
else {
|
|
3077
|
-
currentEnabledIds.delete(modelId);
|
|
3078
|
-
}
|
|
3079
|
-
currentHasFilter = true;
|
|
3080
|
-
await updateSessionModels(currentEnabledIds);
|
|
3081
|
-
},
|
|
3082
|
-
onEnableAll: async (allModelIds) => {
|
|
3083
|
-
currentEnabledIds.clear();
|
|
3084
|
-
for (const id of allModelIds) {
|
|
3085
|
-
currentEnabledIds.add(id);
|
|
3086
|
-
}
|
|
3087
|
-
currentHasFilter = false;
|
|
3088
|
-
await updateSessionModels(currentEnabledIds);
|
|
3089
|
-
},
|
|
3090
|
-
onClearAll: async () => {
|
|
3091
|
-
currentEnabledIds.clear();
|
|
3092
|
-
currentHasFilter = true;
|
|
3093
|
-
await updateSessionModels(currentEnabledIds);
|
|
3094
|
-
},
|
|
3095
|
-
onToggleProvider: async (_provider, modelIds, enabled) => {
|
|
3096
|
-
for (const id of modelIds) {
|
|
3097
|
-
if (enabled) {
|
|
3098
|
-
currentEnabledIds.add(id);
|
|
3099
|
-
}
|
|
3100
|
-
else {
|
|
3101
|
-
currentEnabledIds.delete(id);
|
|
3102
|
-
}
|
|
3103
|
-
}
|
|
3104
|
-
currentHasFilter = true;
|
|
3105
|
-
await updateSessionModels(currentEnabledIds);
|
|
3658
|
+
onChange: async (enabledIds) => {
|
|
3659
|
+
await updateSessionModels(enabledIds);
|
|
3106
3660
|
},
|
|
3107
3661
|
onPersist: (enabledIds) => {
|
|
3108
3662
|
// Persist to settings
|
|
3109
|
-
const newPatterns = enabledIds.length === allModels.length
|
|
3663
|
+
const newPatterns = enabledIds === null || enabledIds.length === allModels.length
|
|
3110
3664
|
? undefined // All enabled = clear filter
|
|
3111
3665
|
: enabledIds;
|
|
3112
|
-
this.settingsManager.setEnabledModels(newPatterns);
|
|
3666
|
+
this.settingsManager.setEnabledModels(newPatterns ? [...newPatterns] : undefined);
|
|
3113
3667
|
this.showStatus("Model selection saved to settings");
|
|
3114
3668
|
},
|
|
3115
3669
|
onCancel: () => {
|
|
@@ -3126,26 +3680,50 @@ export class InteractiveMode {
|
|
|
3126
3680
|
this.showStatus("No messages to fork from");
|
|
3127
3681
|
return;
|
|
3128
3682
|
}
|
|
3683
|
+
const initialSelectedId = userMessages[userMessages.length - 1]?.entryId;
|
|
3129
3684
|
this.showSelector((done) => {
|
|
3130
3685
|
const selector = new UserMessageSelectorComponent(userMessages.map((m) => ({ id: m.entryId, text: m.text })), async (entryId) => {
|
|
3131
|
-
|
|
3132
|
-
|
|
3686
|
+
try {
|
|
3687
|
+
const result = await this.runtimeHost.fork(entryId);
|
|
3688
|
+
if (result.cancelled) {
|
|
3689
|
+
done();
|
|
3690
|
+
this.ui.requestRender();
|
|
3691
|
+
return;
|
|
3692
|
+
}
|
|
3693
|
+
this.editor.setText(result.selectedText ?? "");
|
|
3133
3694
|
done();
|
|
3134
|
-
this.
|
|
3135
|
-
|
|
3695
|
+
this.showStatus("Forked to new session");
|
|
3696
|
+
}
|
|
3697
|
+
catch (error) {
|
|
3698
|
+
done();
|
|
3699
|
+
this.showError(error instanceof Error ? error.message : String(error));
|
|
3136
3700
|
}
|
|
3137
|
-
await this.handleRuntimeSessionChange();
|
|
3138
|
-
this.renderCurrentSessionState();
|
|
3139
|
-
this.editor.setText(result.selectedText ?? "");
|
|
3140
|
-
done();
|
|
3141
|
-
this.showStatus("Branched to new session");
|
|
3142
3701
|
}, () => {
|
|
3143
3702
|
done();
|
|
3144
3703
|
this.ui.requestRender();
|
|
3145
|
-
});
|
|
3704
|
+
}, initialSelectedId);
|
|
3146
3705
|
return { component: selector, focus: selector.getMessageList() };
|
|
3147
3706
|
});
|
|
3148
3707
|
}
|
|
3708
|
+
async handleCloneCommand() {
|
|
3709
|
+
const leafId = this.sessionManager.getLeafId();
|
|
3710
|
+
if (!leafId) {
|
|
3711
|
+
this.showStatus("Nothing to clone yet");
|
|
3712
|
+
return;
|
|
3713
|
+
}
|
|
3714
|
+
try {
|
|
3715
|
+
const result = await this.runtimeHost.fork(leafId, { position: "at" });
|
|
3716
|
+
if (result.cancelled) {
|
|
3717
|
+
this.ui.requestRender();
|
|
3718
|
+
return;
|
|
3719
|
+
}
|
|
3720
|
+
this.editor.setText("");
|
|
3721
|
+
this.showStatus("Cloned to new session");
|
|
3722
|
+
}
|
|
3723
|
+
catch (error) {
|
|
3724
|
+
this.showError(error instanceof Error ? error.message : String(error));
|
|
3725
|
+
}
|
|
3726
|
+
}
|
|
3149
3727
|
showTreeSelector(initialSelectedId) {
|
|
3150
3728
|
const tree = this.sessionManager.getTree();
|
|
3151
3729
|
const realLeafId = this.sessionManager.getLeafId();
|
|
@@ -3192,16 +3770,16 @@ export class InteractiveMode {
|
|
|
3192
3770
|
break;
|
|
3193
3771
|
}
|
|
3194
3772
|
}
|
|
3195
|
-
// Set up escape handler and
|
|
3196
|
-
let
|
|
3773
|
+
// Set up escape handler and status indicator if summarizing
|
|
3774
|
+
let showingSummaryIndicator = false;
|
|
3197
3775
|
const originalOnEscape = this.defaultEditor.onEscape;
|
|
3198
3776
|
if (wantsSummary) {
|
|
3199
3777
|
this.defaultEditor.onEscape = () => {
|
|
3200
3778
|
this.session.abortBranchSummary();
|
|
3201
3779
|
};
|
|
3202
3780
|
this.chatContainer.addChild(new Spacer(1));
|
|
3203
|
-
|
|
3204
|
-
|
|
3781
|
+
this.showStatusIndicator(new BranchSummaryStatusIndicator(this.ui));
|
|
3782
|
+
showingSummaryIndicator = true;
|
|
3205
3783
|
this.ui.requestRender();
|
|
3206
3784
|
}
|
|
3207
3785
|
try {
|
|
@@ -3226,14 +3804,14 @@ export class InteractiveMode {
|
|
|
3226
3804
|
this.editor.setText(result.editorText);
|
|
3227
3805
|
}
|
|
3228
3806
|
this.showStatus("Navigated to selected point");
|
|
3807
|
+
void this.flushCompactionQueue({ willRetry: false });
|
|
3229
3808
|
}
|
|
3230
3809
|
catch (error) {
|
|
3231
3810
|
this.showError(error instanceof Error ? error.message : String(error));
|
|
3232
3811
|
}
|
|
3233
3812
|
finally {
|
|
3234
|
-
if (
|
|
3235
|
-
|
|
3236
|
-
this.statusContainer.clear();
|
|
3813
|
+
if (showingSummaryIndicator) {
|
|
3814
|
+
this.clearStatusIndicator("branchSummary");
|
|
3237
3815
|
}
|
|
3238
3816
|
this.defaultEditor.onEscape = originalOnEscape;
|
|
3239
3817
|
}
|
|
@@ -3249,7 +3827,9 @@ export class InteractiveMode {
|
|
|
3249
3827
|
}
|
|
3250
3828
|
showSessionSelector() {
|
|
3251
3829
|
this.showSelector((done) => {
|
|
3252
|
-
const selector = new SessionSelectorComponent((onProgress) => SessionManager.list(this.sessionManager.getCwd(), this.sessionManager.getSessionDir(), onProgress),
|
|
3830
|
+
const selector = new SessionSelectorComponent((onProgress) => SessionManager.list(this.sessionManager.getCwd(), this.sessionManager.getSessionDir(), onProgress), (onProgress) => this.sessionManager.usesDefaultSessionDir()
|
|
3831
|
+
? SessionManager.listAll(onProgress)
|
|
3832
|
+
: SessionManager.listAll(this.sessionManager.getSessionDir(), onProgress), async (sessionPath) => {
|
|
3253
3833
|
done();
|
|
3254
3834
|
await this.handleResumeSession(sessionPath);
|
|
3255
3835
|
}, () => {
|
|
@@ -3271,87 +3851,293 @@ export class InteractiveMode {
|
|
|
3271
3851
|
return { component: selector, focus: selector };
|
|
3272
3852
|
});
|
|
3273
3853
|
}
|
|
3274
|
-
async handleResumeSession(sessionPath) {
|
|
3275
|
-
|
|
3276
|
-
this.loadingAnimation.stop();
|
|
3277
|
-
this.loadingAnimation = undefined;
|
|
3278
|
-
}
|
|
3279
|
-
this.statusContainer.clear();
|
|
3854
|
+
async handleResumeSession(sessionPath, options) {
|
|
3855
|
+
this.clearStatusIndicator();
|
|
3280
3856
|
try {
|
|
3281
|
-
const result = await this.runtimeHost.switchSession(sessionPath
|
|
3857
|
+
const result = await this.runtimeHost.switchSession(sessionPath, {
|
|
3858
|
+
withSession: options?.withSession,
|
|
3859
|
+
projectTrustContextFactory: (cwd) => this.createProjectTrustContext(cwd),
|
|
3860
|
+
});
|
|
3282
3861
|
if (result.cancelled) {
|
|
3283
|
-
return;
|
|
3862
|
+
return result;
|
|
3284
3863
|
}
|
|
3285
|
-
await this.handleRuntimeSessionChange();
|
|
3286
|
-
this.renderCurrentSessionState();
|
|
3287
3864
|
this.showStatus("Resumed session");
|
|
3865
|
+
return result;
|
|
3288
3866
|
}
|
|
3289
3867
|
catch (error) {
|
|
3290
3868
|
if (error instanceof MissingSessionCwdError) {
|
|
3291
3869
|
const selectedCwd = await this.promptForMissingSessionCwd(error);
|
|
3292
3870
|
if (!selectedCwd) {
|
|
3293
3871
|
this.showStatus("Resume cancelled");
|
|
3294
|
-
return;
|
|
3872
|
+
return { cancelled: true };
|
|
3295
3873
|
}
|
|
3296
|
-
const result = await this.runtimeHost.switchSession(sessionPath,
|
|
3874
|
+
const result = await this.runtimeHost.switchSession(sessionPath, {
|
|
3875
|
+
cwdOverride: selectedCwd,
|
|
3876
|
+
withSession: options?.withSession,
|
|
3877
|
+
projectTrustContextFactory: (cwd) => this.createProjectTrustContext(cwd),
|
|
3878
|
+
});
|
|
3297
3879
|
if (result.cancelled) {
|
|
3298
|
-
return;
|
|
3880
|
+
return result;
|
|
3299
3881
|
}
|
|
3300
|
-
await this.handleRuntimeSessionChange();
|
|
3301
|
-
this.renderCurrentSessionState();
|
|
3302
3882
|
this.showStatus("Resumed session in current cwd");
|
|
3303
|
-
return;
|
|
3883
|
+
return result;
|
|
3304
3884
|
}
|
|
3305
|
-
|
|
3885
|
+
return this.handleFatalRuntimeError("Failed to resume session", error);
|
|
3306
3886
|
}
|
|
3307
3887
|
}
|
|
3308
|
-
|
|
3309
|
-
|
|
3310
|
-
|
|
3311
|
-
|
|
3312
|
-
|
|
3313
|
-
|
|
3314
|
-
|
|
3888
|
+
getLoginProviderOptions(authType) {
|
|
3889
|
+
const authStorage = this.session.modelRegistry.authStorage;
|
|
3890
|
+
const oauthProviders = authStorage.getOAuthProviders();
|
|
3891
|
+
const oauthProviderIds = new Set(oauthProviders.map((provider) => provider.id));
|
|
3892
|
+
const options = oauthProviders.map((provider) => ({
|
|
3893
|
+
id: provider.id,
|
|
3894
|
+
name: provider.name,
|
|
3895
|
+
authType: "oauth",
|
|
3896
|
+
}));
|
|
3897
|
+
const modelProviders = new Set(this.session.modelRegistry.getAll().map((model) => model.provider));
|
|
3898
|
+
for (const providerId of modelProviders) {
|
|
3899
|
+
if (!isApiKeyLoginProvider(providerId, oauthProviderIds)) {
|
|
3900
|
+
continue;
|
|
3315
3901
|
}
|
|
3902
|
+
options.push({
|
|
3903
|
+
id: providerId,
|
|
3904
|
+
name: this.session.modelRegistry.getProviderDisplayName(providerId),
|
|
3905
|
+
authType: "api_key",
|
|
3906
|
+
});
|
|
3316
3907
|
}
|
|
3908
|
+
const filteredOptions = authType ? options.filter((option) => option.authType === authType) : options;
|
|
3909
|
+
return filteredOptions.sort((a, b) => a.name.localeCompare(b.name));
|
|
3910
|
+
}
|
|
3911
|
+
getLogoutProviderOptions() {
|
|
3912
|
+
const authStorage = this.session.modelRegistry.authStorage;
|
|
3913
|
+
const options = [];
|
|
3914
|
+
for (const providerId of authStorage.list()) {
|
|
3915
|
+
const credential = authStorage.get(providerId);
|
|
3916
|
+
if (!credential) {
|
|
3917
|
+
continue;
|
|
3918
|
+
}
|
|
3919
|
+
options.push({
|
|
3920
|
+
id: providerId,
|
|
3921
|
+
name: this.session.modelRegistry.getProviderDisplayName(providerId),
|
|
3922
|
+
authType: credential.type,
|
|
3923
|
+
});
|
|
3924
|
+
}
|
|
3925
|
+
return options.sort((a, b) => a.name.localeCompare(b.name));
|
|
3926
|
+
}
|
|
3927
|
+
showLoginAuthTypeSelector() {
|
|
3928
|
+
const subscriptionLabel = "Use a subscription";
|
|
3929
|
+
const apiKeyLabel = "Use an API key";
|
|
3317
3930
|
this.showSelector((done) => {
|
|
3318
|
-
const selector = new
|
|
3931
|
+
const selector = new ExtensionSelectorComponent("Select authentication method:", [subscriptionLabel, apiKeyLabel], (option) => {
|
|
3932
|
+
done();
|
|
3933
|
+
const authType = option === subscriptionLabel ? "oauth" : "api_key";
|
|
3934
|
+
this.showLoginProviderSelector(authType);
|
|
3935
|
+
}, () => {
|
|
3319
3936
|
done();
|
|
3320
|
-
|
|
3321
|
-
|
|
3937
|
+
this.ui.requestRender();
|
|
3938
|
+
});
|
|
3939
|
+
return { component: selector, focus: selector };
|
|
3940
|
+
});
|
|
3941
|
+
}
|
|
3942
|
+
showLoginProviderSelector(authType) {
|
|
3943
|
+
const providerOptions = this.getLoginProviderOptions(authType);
|
|
3944
|
+
if (providerOptions.length === 0) {
|
|
3945
|
+
this.showStatus(authType === "oauth" ? "No subscription providers available." : "No API key providers available.");
|
|
3946
|
+
return;
|
|
3947
|
+
}
|
|
3948
|
+
this.showSelector((done) => {
|
|
3949
|
+
const selector = new OAuthSelectorComponent("login", this.session.modelRegistry.authStorage, providerOptions, async (providerId) => {
|
|
3950
|
+
done();
|
|
3951
|
+
const providerOption = providerOptions.find((provider) => provider.id === providerId);
|
|
3952
|
+
if (!providerOption) {
|
|
3953
|
+
return;
|
|
3954
|
+
}
|
|
3955
|
+
if (providerOption.authType === "oauth") {
|
|
3956
|
+
await this.showLoginDialog(providerOption.id, providerOption.name);
|
|
3957
|
+
}
|
|
3958
|
+
else if (providerOption.id === BEDROCK_PROVIDER_ID) {
|
|
3959
|
+
this.showBedrockSetupDialog(providerOption.id, providerOption.name);
|
|
3960
|
+
}
|
|
3961
|
+
else {
|
|
3962
|
+
await this.showApiKeyLoginDialog(providerOption.id, providerOption.name);
|
|
3963
|
+
}
|
|
3964
|
+
}, () => {
|
|
3965
|
+
done();
|
|
3966
|
+
this.showLoginAuthTypeSelector();
|
|
3967
|
+
}, (providerId) => this.session.modelRegistry.getProviderAuthStatus(providerId));
|
|
3968
|
+
return { component: selector, focus: selector };
|
|
3969
|
+
});
|
|
3970
|
+
}
|
|
3971
|
+
async showOAuthSelector(mode) {
|
|
3972
|
+
if (mode === "login") {
|
|
3973
|
+
this.showLoginAuthTypeSelector();
|
|
3974
|
+
return;
|
|
3975
|
+
}
|
|
3976
|
+
const providerOptions = this.getLogoutProviderOptions();
|
|
3977
|
+
if (providerOptions.length === 0) {
|
|
3978
|
+
this.showStatus("No stored credentials to remove. /logout only removes credentials saved by /login; environment variables and models.json config are unchanged.");
|
|
3979
|
+
return;
|
|
3980
|
+
}
|
|
3981
|
+
this.showSelector((done) => {
|
|
3982
|
+
const selector = new OAuthSelectorComponent(mode, this.session.modelRegistry.authStorage, providerOptions, async (providerId) => {
|
|
3983
|
+
done();
|
|
3984
|
+
const providerOption = providerOptions.find((provider) => provider.id === providerId);
|
|
3985
|
+
if (!providerOption) {
|
|
3986
|
+
return;
|
|
3987
|
+
}
|
|
3988
|
+
try {
|
|
3989
|
+
this.session.modelRegistry.authStorage.logout(providerOption.id);
|
|
3990
|
+
this.session.modelRegistry.refresh();
|
|
3991
|
+
await this.updateAvailableProviderCount();
|
|
3992
|
+
const message = providerOption.authType === "oauth"
|
|
3993
|
+
? `Logged out of ${providerOption.name}`
|
|
3994
|
+
: `Removed stored API key for ${providerOption.name}. Environment variables and models.json config are unchanged.`;
|
|
3995
|
+
this.showStatus(message);
|
|
3996
|
+
}
|
|
3997
|
+
catch (error) {
|
|
3998
|
+
this.showError(`Logout failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
3999
|
+
}
|
|
4000
|
+
}, () => {
|
|
4001
|
+
done();
|
|
4002
|
+
this.ui.requestRender();
|
|
4003
|
+
});
|
|
4004
|
+
return { component: selector, focus: selector };
|
|
4005
|
+
});
|
|
4006
|
+
}
|
|
4007
|
+
async completeProviderAuthentication(providerId, providerName, authType, previousModel) {
|
|
4008
|
+
this.session.modelRegistry.refresh();
|
|
4009
|
+
const actionLabel = authType === "oauth" ? `Logged in to ${providerName}` : `Saved API key for ${providerName}`;
|
|
4010
|
+
let selectedModel;
|
|
4011
|
+
let selectionError;
|
|
4012
|
+
if (isUnknownModel(previousModel)) {
|
|
4013
|
+
const availableModels = this.session.modelRegistry.getAvailable();
|
|
4014
|
+
const providerModels = availableModels.filter((model) => model.provider === providerId);
|
|
4015
|
+
if (!hasDefaultModelProvider(providerId)) {
|
|
4016
|
+
selectionError = `${actionLabel}, but no default model is configured for provider "${providerId}". Use /model to select a model.`;
|
|
4017
|
+
}
|
|
4018
|
+
else if (providerModels.length === 0) {
|
|
4019
|
+
selectionError = `${actionLabel}, but no models are available for that provider. Use /model to select a model.`;
|
|
4020
|
+
}
|
|
4021
|
+
else {
|
|
4022
|
+
const defaultModelId = defaultModelPerProvider[providerId];
|
|
4023
|
+
selectedModel = providerModels.find((model) => model.id === defaultModelId);
|
|
4024
|
+
if (!selectedModel) {
|
|
4025
|
+
selectionError = `${actionLabel}, but its default model "${defaultModelId}" is not available. Use /model to select a model.`;
|
|
3322
4026
|
}
|
|
3323
4027
|
else {
|
|
3324
|
-
// Logout flow
|
|
3325
|
-
const providerInfo = this.session.modelRegistry.authStorage
|
|
3326
|
-
.getOAuthProviders()
|
|
3327
|
-
.find((p) => p.id === providerId);
|
|
3328
|
-
const providerName = providerInfo?.name || providerId;
|
|
3329
4028
|
try {
|
|
3330
|
-
this.session.
|
|
3331
|
-
this.session.modelRegistry.refresh();
|
|
3332
|
-
await this.updateAvailableProviderCount();
|
|
3333
|
-
this.showStatus(`Logged out of ${providerName}`);
|
|
4029
|
+
await this.session.setModel(selectedModel);
|
|
3334
4030
|
}
|
|
3335
4031
|
catch (error) {
|
|
3336
|
-
|
|
4032
|
+
selectedModel = undefined;
|
|
4033
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
4034
|
+
selectionError = `${actionLabel}, but selecting its default model failed: ${errorMessage}. Use /model to select a model.`;
|
|
3337
4035
|
}
|
|
3338
4036
|
}
|
|
3339
|
-
}
|
|
3340
|
-
|
|
4037
|
+
}
|
|
4038
|
+
}
|
|
4039
|
+
await this.updateAvailableProviderCount();
|
|
4040
|
+
this.footer.invalidate();
|
|
4041
|
+
this.updateEditorBorderColor();
|
|
4042
|
+
if (selectedModel) {
|
|
4043
|
+
this.showStatus(`${actionLabel}. Selected ${selectedModel.id}. Credentials saved to ${getAuthPath()}`);
|
|
4044
|
+
void this.maybeWarnAboutAnthropicSubscriptionAuth(selectedModel);
|
|
4045
|
+
this.checkDaxnutsEasterEgg(selectedModel);
|
|
4046
|
+
}
|
|
4047
|
+
else {
|
|
4048
|
+
this.showStatus(`${actionLabel}. Credentials saved to ${getAuthPath()}`);
|
|
4049
|
+
if (selectionError) {
|
|
4050
|
+
this.showError(selectionError);
|
|
4051
|
+
}
|
|
4052
|
+
else {
|
|
4053
|
+
void this.maybeWarnAboutAnthropicSubscriptionAuth();
|
|
4054
|
+
}
|
|
4055
|
+
}
|
|
4056
|
+
}
|
|
4057
|
+
showBedrockSetupDialog(providerId, providerName) {
|
|
4058
|
+
const restoreEditor = () => {
|
|
4059
|
+
this.editorContainer.clear();
|
|
4060
|
+
this.editorContainer.addChild(this.editor);
|
|
4061
|
+
this.ui.setFocus(this.editor);
|
|
4062
|
+
this.ui.requestRender();
|
|
4063
|
+
};
|
|
4064
|
+
const dialog = new LoginDialogComponent(this.ui, providerId, () => restoreEditor(), providerName, "Amazon Bedrock setup");
|
|
4065
|
+
dialog.showInfo([
|
|
4066
|
+
theme.fg("text", "Amazon Bedrock uses AWS credentials instead of a single API key."),
|
|
4067
|
+
theme.fg("text", "Configure an AWS profile, IAM keys, bearer token, or role-based credentials."),
|
|
4068
|
+
theme.fg("muted", "See:"),
|
|
4069
|
+
theme.fg("accent", ` ${path.join(getDocsPath(), "providers.md")}`),
|
|
4070
|
+
]);
|
|
4071
|
+
this.editorContainer.clear();
|
|
4072
|
+
this.editorContainer.addChild(dialog);
|
|
4073
|
+
this.ui.setFocus(dialog);
|
|
4074
|
+
this.ui.requestRender();
|
|
4075
|
+
}
|
|
4076
|
+
async showApiKeyLoginDialog(providerId, providerName) {
|
|
4077
|
+
const previousModel = this.session.model;
|
|
4078
|
+
const dialog = new LoginDialogComponent(this.ui, providerId, (_success, _message) => {
|
|
4079
|
+
// Completion handled below
|
|
4080
|
+
}, providerName);
|
|
4081
|
+
this.editorContainer.clear();
|
|
4082
|
+
this.editorContainer.addChild(dialog);
|
|
4083
|
+
this.ui.setFocus(dialog);
|
|
4084
|
+
this.ui.requestRender();
|
|
4085
|
+
const restoreEditor = () => {
|
|
4086
|
+
this.editorContainer.clear();
|
|
4087
|
+
this.editorContainer.addChild(this.editor);
|
|
4088
|
+
this.ui.setFocus(this.editor);
|
|
4089
|
+
this.ui.requestRender();
|
|
4090
|
+
};
|
|
4091
|
+
try {
|
|
4092
|
+
const apiKey = (await dialog.showPrompt("Enter API key:")).trim();
|
|
4093
|
+
if (!apiKey) {
|
|
4094
|
+
throw new Error("API key cannot be empty.");
|
|
4095
|
+
}
|
|
4096
|
+
this.session.modelRegistry.authStorage.set(providerId, { type: "api_key", key: apiKey });
|
|
4097
|
+
restoreEditor();
|
|
4098
|
+
await this.completeProviderAuthentication(providerId, providerName, "api_key", previousModel);
|
|
4099
|
+
}
|
|
4100
|
+
catch (error) {
|
|
4101
|
+
restoreEditor();
|
|
4102
|
+
const errorMsg = error instanceof Error ? error.message : String(error);
|
|
4103
|
+
if (errorMsg !== "Login cancelled") {
|
|
4104
|
+
this.showError(`Failed to save API key for ${providerName}: ${errorMsg}`);
|
|
4105
|
+
}
|
|
4106
|
+
}
|
|
4107
|
+
}
|
|
4108
|
+
showOAuthLoginSelect(dialog, prompt) {
|
|
4109
|
+
return new Promise((resolve) => {
|
|
4110
|
+
const restoreDialog = () => {
|
|
4111
|
+
this.editorContainer.clear();
|
|
4112
|
+
this.editorContainer.addChild(dialog);
|
|
4113
|
+
this.ui.setFocus(dialog);
|
|
3341
4114
|
this.ui.requestRender();
|
|
4115
|
+
};
|
|
4116
|
+
const labels = prompt.options.map((option) => option.label);
|
|
4117
|
+
const selector = new ExtensionSelectorComponent(prompt.message, labels, (optionLabel) => {
|
|
4118
|
+
restoreDialog();
|
|
4119
|
+
resolve(prompt.options.find((option) => option.label === optionLabel)?.id);
|
|
4120
|
+
}, () => {
|
|
4121
|
+
restoreDialog();
|
|
4122
|
+
resolve(undefined);
|
|
3342
4123
|
});
|
|
3343
|
-
|
|
4124
|
+
this.editorContainer.clear();
|
|
4125
|
+
this.editorContainer.addChild(selector);
|
|
4126
|
+
this.ui.setFocus(selector);
|
|
4127
|
+
this.ui.requestRender();
|
|
3344
4128
|
});
|
|
3345
4129
|
}
|
|
3346
|
-
async showLoginDialog(providerId) {
|
|
3347
|
-
const providerInfo = this.session.modelRegistry.authStorage
|
|
3348
|
-
|
|
4130
|
+
async showLoginDialog(providerId, providerName) {
|
|
4131
|
+
const providerInfo = this.session.modelRegistry.authStorage
|
|
4132
|
+
.getOAuthProviders()
|
|
4133
|
+
.find((provider) => provider.id === providerId);
|
|
4134
|
+
const previousModel = this.session.model;
|
|
3349
4135
|
// Providers that use callback servers (can paste redirect URL)
|
|
3350
4136
|
const usesCallbackServer = providerInfo?.usesCallbackServer ?? false;
|
|
3351
4137
|
// Create login dialog component
|
|
3352
4138
|
const dialog = new LoginDialogComponent(this.ui, providerId, (_success, _message) => {
|
|
3353
4139
|
// Completion handled below
|
|
3354
|
-
});
|
|
4140
|
+
}, providerName);
|
|
3355
4141
|
// Show dialog in editor container
|
|
3356
4142
|
this.editorContainer.clear();
|
|
3357
4143
|
this.editorContainer.addChild(dialog);
|
|
@@ -3392,26 +4178,25 @@ export class InteractiveMode {
|
|
|
3392
4178
|
}
|
|
3393
4179
|
});
|
|
3394
4180
|
}
|
|
3395
|
-
else if (providerId === "github-copilot") {
|
|
3396
|
-
// GitHub Copilot polls after onAuth
|
|
3397
|
-
dialog.showWaiting("Waiting for browser authentication...");
|
|
3398
|
-
}
|
|
3399
4181
|
// For Anthropic: onPrompt is called immediately after
|
|
3400
4182
|
},
|
|
4183
|
+
onDeviceCode: (info) => {
|
|
4184
|
+
dialog.showDeviceCode(info);
|
|
4185
|
+
dialog.showWaiting("Waiting for authentication...");
|
|
4186
|
+
},
|
|
3401
4187
|
onPrompt: async (prompt) => {
|
|
3402
4188
|
return dialog.showPrompt(prompt.message, prompt.placeholder);
|
|
3403
4189
|
},
|
|
3404
4190
|
onProgress: (message) => {
|
|
3405
4191
|
dialog.showProgress(message);
|
|
3406
4192
|
},
|
|
4193
|
+
onSelect: (prompt) => this.showOAuthLoginSelect(dialog, prompt),
|
|
3407
4194
|
onManualCodeInput: () => manualCodePromise,
|
|
3408
4195
|
signal: dialog.signal,
|
|
3409
4196
|
});
|
|
3410
4197
|
// Success
|
|
3411
4198
|
restoreEditor();
|
|
3412
|
-
this.
|
|
3413
|
-
await this.updateAvailableProviderCount();
|
|
3414
|
-
this.showStatus(`Logged in to ${providerName}. Credentials saved to ${getAuthPath()}`);
|
|
4199
|
+
await this.completeProviderAuthentication(providerId, providerName, "oauth", previousModel);
|
|
3415
4200
|
}
|
|
3416
4201
|
catch (error) {
|
|
3417
4202
|
restoreEditor();
|
|
@@ -3434,31 +4219,47 @@ export class InteractiveMode {
|
|
|
3434
4219
|
return;
|
|
3435
4220
|
}
|
|
3436
4221
|
this.resetExtensionUI();
|
|
3437
|
-
const
|
|
3438
|
-
|
|
3439
|
-
|
|
4222
|
+
const reloadBox = new Container();
|
|
4223
|
+
const borderColor = (s) => theme.fg("border", s);
|
|
4224
|
+
reloadBox.addChild(new DynamicBorder(borderColor));
|
|
4225
|
+
reloadBox.addChild(new Spacer(1));
|
|
4226
|
+
reloadBox.addChild(new Text(theme.fg("muted", "Reloading keybindings, extensions, skills, prompts, themes..."), 1, 0));
|
|
4227
|
+
reloadBox.addChild(new Spacer(1));
|
|
4228
|
+
reloadBox.addChild(new DynamicBorder(borderColor));
|
|
3440
4229
|
const previousEditor = this.editor;
|
|
3441
4230
|
this.editorContainer.clear();
|
|
3442
|
-
this.editorContainer.addChild(
|
|
3443
|
-
this.ui.setFocus(
|
|
3444
|
-
this.ui.requestRender();
|
|
3445
|
-
|
|
3446
|
-
|
|
4231
|
+
this.editorContainer.addChild(reloadBox);
|
|
4232
|
+
this.ui.setFocus(reloadBox);
|
|
4233
|
+
this.ui.requestRender(true);
|
|
4234
|
+
await new Promise((resolve) => process.nextTick(resolve));
|
|
4235
|
+
const dismissReloadBox = (editor) => {
|
|
3447
4236
|
this.editorContainer.clear();
|
|
3448
4237
|
this.editorContainer.addChild(editor);
|
|
3449
4238
|
this.ui.setFocus(editor);
|
|
3450
4239
|
this.ui.requestRender();
|
|
3451
4240
|
};
|
|
4241
|
+
let chatRestoredBeforeSessionStart = false;
|
|
4242
|
+
let reloadBoxDismissed = false;
|
|
4243
|
+
const restoreChatBeforeSessionStart = () => {
|
|
4244
|
+
if (chatRestoredBeforeSessionStart) {
|
|
4245
|
+
return;
|
|
4246
|
+
}
|
|
4247
|
+
this.hideThinkingBlock = this.settingsManager.getHideThinkingBlock();
|
|
4248
|
+
this.outputPad = this.settingsManager.getOutputPad();
|
|
4249
|
+
this.rebuildChatFromMessages();
|
|
4250
|
+
chatRestoredBeforeSessionStart = true;
|
|
4251
|
+
};
|
|
3452
4252
|
try {
|
|
3453
|
-
await this.session.reload();
|
|
4253
|
+
await this.session.reload({ beforeSessionStart: restoreChatBeforeSessionStart });
|
|
4254
|
+
restoreChatBeforeSessionStart();
|
|
4255
|
+
configureHttpDispatcher(this.settingsManager.getHttpIdleTimeoutMs());
|
|
3454
4256
|
this.keybindings.reload();
|
|
3455
|
-
|
|
3456
|
-
|
|
3457
|
-
|
|
3458
|
-
const themeResult = themeName ? setTheme(themeName, true) : { success: true };
|
|
3459
|
-
if (!themeResult.success) {
|
|
3460
|
-
this.showError(`Failed to load theme "${themeName}": ${themeResult.error}\nFell back to dark theme.`);
|
|
4257
|
+
const activeHeader = this.customHeader ?? this.builtInHeader;
|
|
4258
|
+
if (isExpandable(activeHeader)) {
|
|
4259
|
+
activeHeader.setExpanded(this.toolOutputExpanded);
|
|
3461
4260
|
}
|
|
4261
|
+
setRegisteredThemes(this.session.resourceLoader.getThemes().themes);
|
|
4262
|
+
await this.themeController.applyFromSettings();
|
|
3462
4263
|
const editorPaddingX = this.settingsManager.getEditorPaddingX();
|
|
3463
4264
|
const autocompleteMaxVisible = this.settingsManager.getAutocompleteMaxVisible();
|
|
3464
4265
|
this.defaultEditor.setPaddingX(editorPaddingX);
|
|
@@ -3468,32 +4269,38 @@ export class InteractiveMode {
|
|
|
3468
4269
|
this.editor.setAutocompleteMaxVisible?.(autocompleteMaxVisible);
|
|
3469
4270
|
}
|
|
3470
4271
|
this.ui.setShowHardwareCursor(this.settingsManager.getShowHardwareCursor());
|
|
3471
|
-
this.
|
|
3472
|
-
this.
|
|
3473
|
-
|
|
3474
|
-
|
|
3475
|
-
this.setupExtensionShortcuts(runner);
|
|
4272
|
+
const clearOnShrink = this.settingsManager.getClearOnShrink();
|
|
4273
|
+
this.ui.setClearOnShrink(clearOnShrink);
|
|
4274
|
+
if (!clearOnShrink && !this.activeStatusIndicator) {
|
|
4275
|
+
this.statusContainer.clear();
|
|
3476
4276
|
}
|
|
3477
|
-
this.
|
|
3478
|
-
|
|
4277
|
+
this.setupAutocompleteProvider();
|
|
4278
|
+
const runner = this.session.extensionRunner;
|
|
4279
|
+
this.setupExtensionShortcuts(runner);
|
|
3479
4280
|
this.showLoadedResources({
|
|
3480
4281
|
force: false,
|
|
3481
4282
|
showDiagnosticsWhenQuiet: true,
|
|
3482
4283
|
});
|
|
4284
|
+
const savedImplicitProjectTrust = this.maybeSaveImplicitProjectTrustAfterReload();
|
|
3483
4285
|
const modelsJsonError = this.session.modelRegistry.getError();
|
|
3484
4286
|
if (modelsJsonError) {
|
|
3485
4287
|
this.showError(`models.json error: ${modelsJsonError}`);
|
|
3486
4288
|
}
|
|
3487
|
-
this.showStatus(
|
|
4289
|
+
this.showStatus(savedImplicitProjectTrust
|
|
4290
|
+
? "Reloaded keybindings, extensions, skills, prompts, themes; saved project trust"
|
|
4291
|
+
: "Reloaded keybindings, extensions, skills, prompts, themes");
|
|
4292
|
+
dismissReloadBox(this.editor);
|
|
4293
|
+
reloadBoxDismissed = true;
|
|
3488
4294
|
}
|
|
3489
4295
|
catch (error) {
|
|
3490
|
-
|
|
4296
|
+
if (!reloadBoxDismissed) {
|
|
4297
|
+
dismissReloadBox(previousEditor);
|
|
4298
|
+
}
|
|
3491
4299
|
this.showError(`Reload failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
3492
4300
|
}
|
|
3493
4301
|
}
|
|
3494
4302
|
async handleExportCommand(text) {
|
|
3495
|
-
const
|
|
3496
|
-
const outputPath = parts.length > 1 ? parts[1] : undefined;
|
|
4303
|
+
const outputPath = this.getPathCommandArgument(text, "/export");
|
|
3497
4304
|
try {
|
|
3498
4305
|
if (outputPath?.endsWith(".jsonl")) {
|
|
3499
4306
|
const filePath = this.session.exportToJsonl(outputPath);
|
|
@@ -3508,31 +4315,49 @@ export class InteractiveMode {
|
|
|
3508
4315
|
this.showError(`Failed to export session: ${error instanceof Error ? error.message : "Unknown error"}`);
|
|
3509
4316
|
}
|
|
3510
4317
|
}
|
|
4318
|
+
getPathCommandArgument(text, command) {
|
|
4319
|
+
if (text === command) {
|
|
4320
|
+
return undefined;
|
|
4321
|
+
}
|
|
4322
|
+
if (!text.startsWith(`${command} `)) {
|
|
4323
|
+
return undefined;
|
|
4324
|
+
}
|
|
4325
|
+
const argsString = text.slice(command.length + 1).trimStart();
|
|
4326
|
+
if (!argsString) {
|
|
4327
|
+
return undefined;
|
|
4328
|
+
}
|
|
4329
|
+
const firstChar = argsString[0];
|
|
4330
|
+
if (firstChar === '"' || firstChar === "'") {
|
|
4331
|
+
const closingQuoteIndex = argsString.indexOf(firstChar, 1);
|
|
4332
|
+
if (closingQuoteIndex < 0) {
|
|
4333
|
+
return undefined;
|
|
4334
|
+
}
|
|
4335
|
+
return argsString.slice(1, closingQuoteIndex);
|
|
4336
|
+
}
|
|
4337
|
+
const firstWhitespaceIndex = argsString.search(/\s/);
|
|
4338
|
+
if (firstWhitespaceIndex < 0) {
|
|
4339
|
+
return argsString;
|
|
4340
|
+
}
|
|
4341
|
+
return argsString.slice(0, firstWhitespaceIndex);
|
|
4342
|
+
}
|
|
3511
4343
|
async handleImportCommand(text) {
|
|
3512
|
-
const
|
|
3513
|
-
if (
|
|
4344
|
+
const inputPath = this.getPathCommandArgument(text, "/import");
|
|
4345
|
+
if (!inputPath) {
|
|
3514
4346
|
this.showError("Usage: /import <path.jsonl>");
|
|
3515
4347
|
return;
|
|
3516
4348
|
}
|
|
3517
|
-
const inputPath = parts[1];
|
|
3518
4349
|
const confirmed = await this.showExtensionConfirm("Import session", `Replace current session with ${inputPath}?`);
|
|
3519
4350
|
if (!confirmed) {
|
|
3520
4351
|
this.showStatus("Import cancelled");
|
|
3521
4352
|
return;
|
|
3522
4353
|
}
|
|
3523
4354
|
try {
|
|
3524
|
-
|
|
3525
|
-
this.loadingAnimation.stop();
|
|
3526
|
-
this.loadingAnimation = undefined;
|
|
3527
|
-
}
|
|
3528
|
-
this.statusContainer.clear();
|
|
4355
|
+
this.clearStatusIndicator();
|
|
3529
4356
|
const result = await this.runtimeHost.importFromJsonl(inputPath);
|
|
3530
4357
|
if (result.cancelled) {
|
|
3531
4358
|
this.showStatus("Import cancelled");
|
|
3532
4359
|
return;
|
|
3533
4360
|
}
|
|
3534
|
-
await this.handleRuntimeSessionChange();
|
|
3535
|
-
this.renderCurrentSessionState();
|
|
3536
4361
|
this.showStatus(`Session imported from: ${inputPath}`);
|
|
3537
4362
|
}
|
|
3538
4363
|
catch (error) {
|
|
@@ -3547,11 +4372,13 @@ export class InteractiveMode {
|
|
|
3547
4372
|
this.showStatus("Import cancelled");
|
|
3548
4373
|
return;
|
|
3549
4374
|
}
|
|
3550
|
-
await this.handleRuntimeSessionChange();
|
|
3551
|
-
this.renderCurrentSessionState();
|
|
3552
4375
|
this.showStatus(`Session imported from: ${inputPath}`);
|
|
3553
4376
|
return;
|
|
3554
4377
|
}
|
|
4378
|
+
if (error instanceof SessionImportFileNotFoundError) {
|
|
4379
|
+
this.showError(`Failed to import session: ${error.message}`);
|
|
4380
|
+
return;
|
|
4381
|
+
}
|
|
3555
4382
|
await this.handleFatalRuntimeError("Failed to import session", error);
|
|
3556
4383
|
}
|
|
3557
4384
|
}
|
|
@@ -3670,10 +4497,13 @@ export class InteractiveMode {
|
|
|
3670
4497
|
this.ui.requestRender();
|
|
3671
4498
|
return;
|
|
3672
4499
|
}
|
|
3673
|
-
this.
|
|
3674
|
-
this.
|
|
4500
|
+
this.session.setSessionName(name);
|
|
4501
|
+
const sessionName = this.sessionManager.getSessionName();
|
|
4502
|
+
if (sessionName !== name) {
|
|
4503
|
+
this.showWarning(`Session name was normalized from ${JSON.stringify(name)} to ${JSON.stringify(sessionName)}`);
|
|
4504
|
+
}
|
|
3675
4505
|
this.chatContainer.addChild(new Spacer(1));
|
|
3676
|
-
this.chatContainer.addChild(new Text(theme.fg("dim", `Session name set: ${name}`), 1, 0));
|
|
4506
|
+
this.chatContainer.addChild(new Text(theme.fg("dim", `Session name set: ${sessionName ?? name}`), 1, 0));
|
|
3677
4507
|
this.ui.requestRender();
|
|
3678
4508
|
}
|
|
3679
4509
|
handleSessionCommand() {
|
|
@@ -3715,7 +4545,7 @@ export class InteractiveMode {
|
|
|
3715
4545
|
const changelogMarkdown = allEntries.length > 0
|
|
3716
4546
|
? allEntries
|
|
3717
4547
|
.reverse()
|
|
3718
|
-
.map((e) => e.content)
|
|
4548
|
+
.map((e) => normalizeChangelogLinks(e.content, e))
|
|
3719
4549
|
.join("\n\n")
|
|
3720
4550
|
: "No changelog entries found.";
|
|
3721
4551
|
this.chatContainer.addChild(new Spacer(1));
|
|
@@ -3726,29 +4556,17 @@ export class InteractiveMode {
|
|
|
3726
4556
|
this.chatContainer.addChild(new DynamicBorder());
|
|
3727
4557
|
this.ui.requestRender();
|
|
3728
4558
|
}
|
|
3729
|
-
/**
|
|
3730
|
-
* Capitalize keybinding for display (e.g., "ctrl+c" -> "Ctrl+C").
|
|
3731
|
-
*/
|
|
3732
|
-
capitalizeKey(key) {
|
|
3733
|
-
return key
|
|
3734
|
-
.split("/")
|
|
3735
|
-
.map((k) => k
|
|
3736
|
-
.split("+")
|
|
3737
|
-
.map((part) => part.charAt(0).toUpperCase() + part.slice(1))
|
|
3738
|
-
.join("+"))
|
|
3739
|
-
.join("/");
|
|
3740
|
-
}
|
|
3741
4559
|
/**
|
|
3742
4560
|
* Get capitalized display string for an app keybinding action.
|
|
3743
4561
|
*/
|
|
3744
4562
|
getAppKeyDisplay(action) {
|
|
3745
|
-
return
|
|
4563
|
+
return keyDisplayText(action);
|
|
3746
4564
|
}
|
|
3747
4565
|
/**
|
|
3748
4566
|
* Get capitalized display string for an editor keybinding action.
|
|
3749
4567
|
*/
|
|
3750
4568
|
getEditorKeyDisplay(action) {
|
|
3751
|
-
return
|
|
4569
|
+
return keyDisplayText(action);
|
|
3752
4570
|
}
|
|
3753
4571
|
handleHotkeysCommand() {
|
|
3754
4572
|
// Navigation keybindings
|
|
@@ -3794,7 +4612,7 @@ export class InteractiveMode {
|
|
|
3794
4612
|
**Navigation**
|
|
3795
4613
|
| Key | Action |
|
|
3796
4614
|
|-----|--------|
|
|
3797
|
-
| \`${cursorUp}\` / \`${cursorDown}\` / \`${cursorLeft}\` / \`${cursorRight}\` | Move cursor / browse history
|
|
4615
|
+
| \`${cursorUp}\` / \`${cursorDown}\` / \`${cursorLeft}\` / \`${cursorRight}\` | Move cursor / browse history |
|
|
3798
4616
|
| \`${cursorWordLeft}\` / \`${cursorWordRight}\` | Move by word |
|
|
3799
4617
|
| \`${cursorLineStart}\` | Start of line |
|
|
3800
4618
|
| \`${cursorLineEnd}\` | End of line |
|
|
@@ -3838,19 +4656,17 @@ export class InteractiveMode {
|
|
|
3838
4656
|
`;
|
|
3839
4657
|
// Add extension-registered shortcuts
|
|
3840
4658
|
const extensionRunner = this.session.extensionRunner;
|
|
3841
|
-
|
|
3842
|
-
|
|
3843
|
-
|
|
3844
|
-
hotkeys += `
|
|
4659
|
+
const shortcuts = extensionRunner.getShortcuts(this.keybindings.getEffectiveConfig());
|
|
4660
|
+
if (shortcuts.size > 0) {
|
|
4661
|
+
hotkeys += `
|
|
3845
4662
|
**Extensions**
|
|
3846
4663
|
| Key | Action |
|
|
3847
4664
|
|-----|--------|
|
|
3848
4665
|
`;
|
|
3849
|
-
|
|
3850
|
-
|
|
3851
|
-
|
|
3852
|
-
|
|
3853
|
-
}
|
|
4666
|
+
for (const [key, shortcut] of shortcuts) {
|
|
4667
|
+
const description = shortcut.description ?? shortcut.extensionPath;
|
|
4668
|
+
const keyDisplay = formatKeyText(key, { capitalize: true });
|
|
4669
|
+
hotkeys += `| \`${keyDisplay}\` | ${description} |\n`;
|
|
3854
4670
|
}
|
|
3855
4671
|
}
|
|
3856
4672
|
this.chatContainer.addChild(new Spacer(1));
|
|
@@ -3862,18 +4678,12 @@ export class InteractiveMode {
|
|
|
3862
4678
|
this.ui.requestRender();
|
|
3863
4679
|
}
|
|
3864
4680
|
async handleClearCommand() {
|
|
3865
|
-
|
|
3866
|
-
this.loadingAnimation.stop();
|
|
3867
|
-
this.loadingAnimation = undefined;
|
|
3868
|
-
}
|
|
3869
|
-
this.statusContainer.clear();
|
|
4681
|
+
this.clearStatusIndicator();
|
|
3870
4682
|
try {
|
|
3871
4683
|
const result = await this.runtimeHost.newSession();
|
|
3872
4684
|
if (result.cancelled) {
|
|
3873
4685
|
return;
|
|
3874
4686
|
}
|
|
3875
|
-
await this.handleRuntimeSessionChange();
|
|
3876
|
-
this.renderCurrentSessionState();
|
|
3877
4687
|
this.chatContainer.addChild(new Spacer(1));
|
|
3878
4688
|
this.chatContainer.addChild(new Text(`${theme.fg("accent", "✓ New session started")}`, 1, 1));
|
|
3879
4689
|
this.ui.requestRender();
|
|
@@ -3932,14 +4742,12 @@ export class InteractiveMode {
|
|
|
3932
4742
|
async handleBashCommand(command, excludeFromContext = false) {
|
|
3933
4743
|
const extensionRunner = this.session.extensionRunner;
|
|
3934
4744
|
// Emit user_bash event to let extensions intercept
|
|
3935
|
-
const eventResult = extensionRunner
|
|
3936
|
-
|
|
3937
|
-
|
|
3938
|
-
|
|
3939
|
-
|
|
3940
|
-
|
|
3941
|
-
})
|
|
3942
|
-
: undefined;
|
|
4745
|
+
const eventResult = await extensionRunner.emitUserBash({
|
|
4746
|
+
type: "user_bash",
|
|
4747
|
+
command,
|
|
4748
|
+
excludeFromContext,
|
|
4749
|
+
cwd: this.sessionManager.getCwd(),
|
|
4750
|
+
});
|
|
3943
4751
|
// If extension returned a full result, use it directly
|
|
3944
4752
|
if (eventResult?.result) {
|
|
3945
4753
|
const result = eventResult.result;
|
|
@@ -3997,17 +4805,7 @@ export class InteractiveMode {
|
|
|
3997
4805
|
this.ui.requestRender();
|
|
3998
4806
|
}
|
|
3999
4807
|
async handleCompactCommand(customInstructions) {
|
|
4000
|
-
|
|
4001
|
-
const messageCount = entries.filter((e) => e.type === "message").length;
|
|
4002
|
-
if (messageCount < 2) {
|
|
4003
|
-
this.showWarning("Nothing to compact (no messages yet)");
|
|
4004
|
-
return;
|
|
4005
|
-
}
|
|
4006
|
-
if (this.loadingAnimation) {
|
|
4007
|
-
this.loadingAnimation.stop();
|
|
4008
|
-
this.loadingAnimation = undefined;
|
|
4009
|
-
}
|
|
4010
|
-
this.statusContainer.clear();
|
|
4808
|
+
this.clearStatusIndicator();
|
|
4011
4809
|
try {
|
|
4012
4810
|
await this.session.compact(customInstructions);
|
|
4013
4811
|
}
|
|
@@ -4016,10 +4814,11 @@ export class InteractiveMode {
|
|
|
4016
4814
|
}
|
|
4017
4815
|
}
|
|
4018
4816
|
stop() {
|
|
4019
|
-
if (this.
|
|
4020
|
-
this.
|
|
4021
|
-
this.loadingAnimation = undefined;
|
|
4817
|
+
if (this.settingsManager.getShowTerminalProgress()) {
|
|
4818
|
+
this.ui.terminal.setProgress(false);
|
|
4022
4819
|
}
|
|
4820
|
+
this.clearStatusIndicator();
|
|
4821
|
+
this.themeController.disableAutoSync();
|
|
4023
4822
|
this.clearExtensionTerminalInputListeners();
|
|
4024
4823
|
this.footer.dispose();
|
|
4025
4824
|
this.footerDataProvider.dispose();
|
|
@@ -4030,6 +4829,7 @@ export class InteractiveMode {
|
|
|
4030
4829
|
this.ui.stop();
|
|
4031
4830
|
this.isInitialized = false;
|
|
4032
4831
|
}
|
|
4832
|
+
this.unregisterSignalHandlers();
|
|
4033
4833
|
}
|
|
4034
4834
|
}
|
|
4035
4835
|
//# sourceMappingURL=interactive-mode.js.map
|