@draht/coding-agent 2026.4.26 → 2026.6.11
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 +43 -0
- package/bin/draht-tools.cjs +3809 -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/restore-sandbox-env.d.ts +13 -0
- package/dist/bun/restore-sandbox-env.d.ts.map +1 -0
- package/dist/bun/restore-sandbox-env.js +32 -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 +88 -35
- package/dist/cli/args.js.map +1 -1
- package/dist/cli/config-selector.d.ts +2 -2
- 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 +2 -3
- 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 +1 -1
- package/dist/cli/session-picker.d.ts.map +1 -1
- package/dist/cli/session-picker.js.map +1 -1
- package/dist/cli/startup-ui.d.ts +16 -0
- package/dist/cli/startup-ui.d.ts.map +1 -0
- package/dist/cli/startup-ui.js +112 -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 +23 -13
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +264 -62
- 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 +47 -31
- package/dist/core/agent-session.d.ts.map +1 -1
- package/dist/core/agent-session.js +470 -443
- 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 +10 -1
- package/dist/core/auth-storage.d.ts.map +1 -1
- package/dist/core/auth-storage.js +27 -6
- 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 +6 -4
- package/dist/core/compaction/branch-summarization.d.ts.map +1 -1
- package/dist/core/compaction/branch-summarization.js +9 -3
- package/dist/core/compaction/branch-summarization.js.map +1 -1
- package/dist/core/compaction/compaction.d.ts +5 -5
- package/dist/core/compaction/compaction.d.ts.map +1 -1
- package/dist/core/compaction/compaction.js +43 -37
- 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/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 +3 -3
- package/dist/core/extensions/loader.d.ts.map +1 -1
- package/dist/core/extensions/loader.js +27 -35
- package/dist/core/extensions/loader.js.map +1 -1
- package/dist/core/extensions/runner.d.ts +30 -12
- package/dist/core/extensions/runner.d.ts.map +1 -1
- package/dist/core/extensions/runner.js +215 -32
- package/dist/core/extensions/runner.js.map +1 -1
- package/dist/core/extensions/types.d.ts +163 -35
- 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 +21 -0
- package/dist/core/http-dispatcher.d.ts.map +1 -0
- package/dist/core/http-dispatcher.js +48 -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 +66 -1
- package/dist/core/keybindings.d.ts.map +1 -1
- package/dist/core/keybindings.js +56 -1
- package/dist/core/keybindings.js.map +1 -1
- package/dist/core/model-registry.d.ts +22 -4
- package/dist/core/model-registry.d.ts.map +1 -1
- package/dist/core/model-registry.js +216 -44
- package/dist/core/model-registry.js.map +1 -1
- package/dist/core/model-resolver.d.ts +2 -1
- package/dist/core/model-resolver.d.ts.map +1 -1
- package/dist/core/model-resolver.js +48 -21
- 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 +17 -2
- package/dist/core/package-manager.d.ts.map +1 -1
- package/dist/core/package-manager.js +363 -121
- 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 +58 -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 +9 -1
- package/dist/core/resolve-config-value.d.ts.map +1 -1
- package/dist/core/resolve-config-value.js +134 -11
- package/dist/core/resolve-config-value.js.map +1 -1
- package/dist/core/resource-loader.d.ts +34 -14
- package/dist/core/resource-loader.d.ts.map +1 -1
- package/dist/core/resource-loader.js +165 -76
- package/dist/core/resource-loader.js.map +1 -1
- package/dist/core/sdk.d.ts +26 -10
- package/dist/core/sdk.d.ts.map +1 -1
- package/dist/core/sdk.js +45 -16
- package/dist/core/sdk.js.map +1 -1
- package/dist/core/session-manager.d.ts +11 -12
- package/dist/core/session-manager.d.ts.map +1 -1
- package/dist/core/session-manager.js +245 -132
- package/dist/core/session-manager.js.map +1 -1
- package/dist/core/settings-manager.d.ts +52 -5
- package/dist/core/settings-manager.d.ts.map +1 -1
- package/dist/core/settings-manager.js +202 -38
- 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 +14 -10
- 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/tools/bash.d.ts +11 -16
- package/dist/core/tools/bash.d.ts.map +1 -1
- package/dist/core/tools/bash.js +162 -177
- package/dist/core/tools/bash.js.map +1 -1
- package/dist/core/tools/edit-diff.d.ts +3 -1
- package/dist/core/tools/edit-diff.d.ts.map +1 -1
- package/dist/core/tools/edit-diff.js +11 -3
- 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 +199 -111
- 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 +134 -95
- 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 +100 -36
- 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 +31 -0
- package/dist/core/trust-manager.d.ts.map +1 -0
- package/dist/core/trust-manager.js +187 -0
- package/dist/core/trust-manager.js.map +1 -0
- package/dist/index.d.ts +31 -29
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9 -8
- 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 +170 -87
- 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 +127 -5
- 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/components/assistant-message.d.ts +2 -0
- package/dist/modes/interactive/components/assistant-message.d.ts.map +1 -1
- package/dist/modes/interactive/components/assistant-message.js +14 -0
- 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 +4 -4
- package/dist/modes/interactive/components/config-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/config-selector.js +38 -11
- 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-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.map +1 -1
- package/dist/modes/interactive/components/extension-editor.js +14 -6
- 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 +2 -1
- package/dist/modes/interactive/components/footer.d.ts.map +1 -1
- package/dist/modes/interactive/components/footer.js +23 -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 +46 -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 +8 -5
- 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 +45 -30
- package/dist/modes/interactive/components/scoped-models-selector.js.map +1 -1
- package/dist/modes/interactive/components/session-selector.d.ts +2 -1
- package/dist/modes/interactive/components/session-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/session-selector.js +20 -7
- package/dist/modes/interactive/components/session-selector.js.map +1 -1
- package/dist/modes/interactive/components/settings-selector.d.ts +13 -0
- package/dist/modes/interactive/components/settings-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/settings-selector.js +113 -4
- 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/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.map +1 -1
- package/dist/modes/interactive/components/tree-selector.js +18 -9
- 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 +1 -0
- package/dist/modes/interactive/components/user-message.d.ts.map +1 -1
- package/dist/modes/interactive/components/user-message.js +8 -7
- package/dist/modes/interactive/components/user-message.js.map +1 -1
- package/dist/modes/interactive/interactive-mode.d.ts +68 -13
- package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode.js +1100 -319
- package/dist/modes/interactive/interactive-mode.js.map +1 -1
- package/dist/modes/interactive/theme/dark.json +5 -4
- package/dist/modes/interactive/theme/light.json +5 -4
- package/dist/modes/interactive/theme/theme.d.ts +22 -3
- package/dist/modes/interactive/theme/theme.d.ts.map +1 -1
- package/dist/modes/interactive/theme/theme.js +160 -105
- 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 +11 -1
- package/dist/modes/rpc/rpc-client.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-client.js +73 -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 +96 -30
- package/dist/modes/rpc/rpc-mode.js.map +1 -1
- package/dist/modes/rpc/rpc-types.d.ts +16 -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 +396 -21
- package/dist/package-manager-cli.js.map +1 -1
- package/dist/prompts/commands/atomic-commit.md +12 -0
- package/dist/prompts/commands/execute-phase.md +48 -17
- package/dist/prompts/commands/fix.md +86 -23
- package/dist/prompts/commands/map-codebase.md +17 -3
- package/dist/prompts/commands/orchestrate.md +31 -6
- package/dist/prompts/commands/plan-phase.md +39 -6
- package/dist/prompts/commands/quick.md +36 -6
- package/dist/prompts/commands/review.md +28 -11
- package/dist/prompts/commands/verify-work.md +34 -17
- 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 +5 -1
- package/dist/utils/child-process.d.ts.map +1 -1
- package/dist/utils/child-process.js +10 -0
- 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.map +1 -1
- package/dist/utils/image-convert.js.map +1 -1
- 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 +59 -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 +10 -6
- package/dist/utils/shell.d.ts.map +1 -1
- package/dist/utils/shell.js +35 -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 +82 -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 +465 -71
- package/docs/index.md +82 -0
- package/docs/json.md +4 -4
- package/docs/keybindings.md +23 -1
- package/docs/models.md +119 -17
- package/docs/packages.md +17 -9
- package/docs/prompt-templates.md +30 -2
- package/docs/providers.md +83 -22
- package/docs/quickstart.md +165 -0
- package/docs/rpc.md +41 -10
- package/docs/sdk.md +68 -50
- package/docs/security.md +55 -0
- package/docs/{session.md → session-format.md} +11 -11
- package/docs/sessions.md +145 -0
- package/docs/settings.md +61 -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/border-status-editor.ts +145 -0
- package/examples/extensions/built-in-tool-renderer.ts +3 -0
- package/examples/extensions/custom-header.ts +1 -1
- package/examples/extensions/custom-provider-anthropic/index.ts +1 -1
- 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 +55 -4
- package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
- package/examples/extensions/custom-provider-gitlab-duo/test.ts +1 -1
- 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/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 +50 -12
- 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/utils.ts +1 -1
- package/examples/extensions/preset.ts +36 -3
- package/examples/extensions/project-trust.ts +64 -0
- package/examples/extensions/prompt-customizer.ts +97 -0
- package/examples/extensions/provider-payload.ts +4 -0
- package/examples/extensions/qna.ts +1 -1
- package/examples/extensions/question.ts +2 -2
- package/examples/extensions/questionnaire.ts +2 -2
- package/examples/extensions/reload-runtime.ts +1 -1
- package/examples/extensions/sandbox/index.ts +4 -4
- 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/index.ts +51 -28
- package/examples/extensions/summarize.ts +1 -1
- 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 +12 -8
- 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 +13 -17
- package/package.json +15 -7
- package/prompts/commands/atomic-commit.md +12 -0
- package/prompts/commands/execute-phase.md +48 -17
- package/prompts/commands/fix.md +86 -23
- package/prompts/commands/map-codebase.md +17 -3
- package/prompts/commands/orchestrate.md +31 -6
- package/prompts/commands/plan-phase.md +39 -6
- package/prompts/commands/quick.md +36 -6
- package/prompts/commands/review.md +28 -11
- package/prompts/commands/verify-work.md +34 -17
|
@@ -13,25 +13,27 @@
|
|
|
13
13
|
* Modes use this class and add their own I/O layer on top.
|
|
14
14
|
*/
|
|
15
15
|
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
16
|
-
import { basename, dirname
|
|
17
|
-
import { isContextOverflow, modelsAreEqual, resetApiProviders,
|
|
18
|
-
import { getDocsPath } from "../config.js";
|
|
16
|
+
import { basename, dirname } from "node:path";
|
|
17
|
+
import { clampThinkingLevel, cleanupSessionResources, getSupportedThinkingLevels, isContextOverflow, modelsAreEqual, resetApiProviders, streamSimple, } from "@draht/ai";
|
|
19
18
|
import { theme } from "../modes/interactive/theme/theme.js";
|
|
20
19
|
import { stripFrontmatter } from "../utils/frontmatter.js";
|
|
20
|
+
import { resolvePath } from "../utils/paths.js";
|
|
21
21
|
import { sleep } from "../utils/sleep.js";
|
|
22
|
+
import { formatNoApiKeyFoundMessage, formatNoModelSelectedMessage } from "./auth-guidance.js";
|
|
22
23
|
import { executeBashWithOperations } from "./bash-executor.js";
|
|
23
24
|
import { calculateContextTokens, collectEntriesForBranchSummary, compact, estimateContextTokens, generateBranchSummary, prepareCompaction, shouldCompact, } from "./compaction/index.js";
|
|
24
25
|
import { DEFAULT_THINKING_LEVEL } from "./defaults.js";
|
|
25
26
|
import { exportSessionToHtml } from "./export-html/index.js";
|
|
26
27
|
import { createToolHtmlRenderer } from "./export-html/tool-renderer.js";
|
|
27
28
|
import { ExtensionRunner, wrapRegisteredTools, } from "./extensions/index.js";
|
|
29
|
+
import { emitSessionShutdownEvent } from "./extensions/runner.js";
|
|
28
30
|
import { expandPromptTemplate } from "./prompt-templates.js";
|
|
29
31
|
import { CURRENT_SESSION_VERSION, getLatestCompactionEntry } from "./session-manager.js";
|
|
30
32
|
import { createSyntheticSourceInfo } from "./source-info.js";
|
|
31
33
|
import { buildSystemPrompt } from "./system-prompt.js";
|
|
32
34
|
import { createLocalBashOperations } from "./tools/bash.js";
|
|
33
35
|
import { createAllToolDefinitions } from "./tools/index.js";
|
|
34
|
-
import { createToolDefinitionFromAgentTool
|
|
36
|
+
import { createToolDefinitionFromAgentTool } from "./tools/tool-definition-wrapper.js";
|
|
35
37
|
/**
|
|
36
38
|
* Parse a skill block from message text.
|
|
37
39
|
* Returns null if the text doesn't contain a skill block.
|
|
@@ -52,10 +54,6 @@ export function parseSkillBlock(text) {
|
|
|
52
54
|
// ============================================================================
|
|
53
55
|
/** Standard thinking levels */
|
|
54
56
|
const THINKING_LEVELS = ["off", "minimal", "low", "medium", "high"];
|
|
55
|
-
/** Thinking levels including xhigh (for supported models) */
|
|
56
|
-
const THINKING_LEVELS_WITH_XHIGH = ["off", "minimal", "low", "medium", "high", "xhigh"];
|
|
57
|
-
/** Thinking levels including xhigh and max (Anthropic Opus only) */
|
|
58
|
-
const THINKING_LEVELS_WITH_MAX = ["off", "minimal", "low", "medium", "high", "xhigh", "max"];
|
|
59
57
|
// ============================================================================
|
|
60
58
|
// AgentSession Class
|
|
61
59
|
// ============================================================================
|
|
@@ -67,7 +65,6 @@ export class AgentSession {
|
|
|
67
65
|
// Event subscription state
|
|
68
66
|
_unsubscribeAgent;
|
|
69
67
|
_eventListeners = [];
|
|
70
|
-
_agentEventQueue = Promise.resolve();
|
|
71
68
|
/** Tracks pending steering messages for UI display. Removed when delivered. */
|
|
72
69
|
_steeringMessages = [];
|
|
73
70
|
/** Tracks pending follow-up messages for UI display. Removed when delivered. */
|
|
@@ -83,13 +80,11 @@ export class AgentSession {
|
|
|
83
80
|
// Retry state
|
|
84
81
|
_retryAbortController = undefined;
|
|
85
82
|
_retryAttempt = 0;
|
|
86
|
-
_retryPromise = undefined;
|
|
87
|
-
_retryResolve = undefined;
|
|
88
83
|
// Bash execution state
|
|
89
84
|
_bashAbortController = undefined;
|
|
90
85
|
_pendingBashMessages = [];
|
|
91
86
|
// Extension system
|
|
92
|
-
_extensionRunner
|
|
87
|
+
_extensionRunner;
|
|
93
88
|
_turnIndex = 0;
|
|
94
89
|
_resourceLoader;
|
|
95
90
|
_customTools;
|
|
@@ -97,10 +92,14 @@ export class AgentSession {
|
|
|
97
92
|
_cwd;
|
|
98
93
|
_extensionRunnerRef;
|
|
99
94
|
_initialActiveToolNames;
|
|
95
|
+
_allowedToolNames;
|
|
96
|
+
_excludedToolNames;
|
|
100
97
|
_baseToolsOverride;
|
|
101
98
|
_sessionStartEvent;
|
|
102
99
|
_extensionUIContext;
|
|
100
|
+
_extensionMode = "print";
|
|
103
101
|
_extensionCommandContextActions;
|
|
102
|
+
_extensionAbortHandler;
|
|
104
103
|
_extensionShutdownHandler;
|
|
105
104
|
_extensionErrorListener;
|
|
106
105
|
_extensionErrorUnsubscriber;
|
|
@@ -113,6 +112,7 @@ export class AgentSession {
|
|
|
113
112
|
_toolPromptGuidelines = new Map();
|
|
114
113
|
// Base system prompt (without extension appends) - used to apply fresh appends each turn
|
|
115
114
|
_baseSystemPrompt = "";
|
|
115
|
+
_baseSystemPromptOptions;
|
|
116
116
|
constructor(config) {
|
|
117
117
|
this.agent = config.agent;
|
|
118
118
|
this.sessionManager = config.sessionManager;
|
|
@@ -124,6 +124,8 @@ export class AgentSession {
|
|
|
124
124
|
this._modelRegistry = config.modelRegistry;
|
|
125
125
|
this._extensionRunnerRef = config.extensionRunnerRef;
|
|
126
126
|
this._initialActiveToolNames = config.initialActiveToolNames;
|
|
127
|
+
this._allowedToolNames = config.allowedToolNames ? new Set(config.allowedToolNames) : undefined;
|
|
128
|
+
this._excludedToolNames = config.excludedToolNames ? new Set(config.excludedToolNames) : undefined;
|
|
127
129
|
this._baseToolsOverride = config.baseToolsOverride;
|
|
128
130
|
this._sessionStartEvent = config.sessionStartEvent ?? { type: "session_start", reason: "startup" };
|
|
129
131
|
// Always subscribe to agent events for internal handling
|
|
@@ -142,6 +144,9 @@ export class AgentSession {
|
|
|
142
144
|
async _getRequiredRequestAuth(model) {
|
|
143
145
|
const result = await this._modelRegistry.getApiKeyAndHeaders(model);
|
|
144
146
|
if (!result.ok) {
|
|
147
|
+
if (result.error.startsWith("No API key found")) {
|
|
148
|
+
throw new Error(formatNoApiKeyFoundMessage(model.provider));
|
|
149
|
+
}
|
|
145
150
|
throw new Error(result.error);
|
|
146
151
|
}
|
|
147
152
|
if (result.apiKey) {
|
|
@@ -153,8 +158,14 @@ export class AgentSession {
|
|
|
153
158
|
`Credentials may have expired or network is unavailable. ` +
|
|
154
159
|
`Run '/login ${model.provider}' to re-authenticate.`);
|
|
155
160
|
}
|
|
156
|
-
throw new Error(
|
|
157
|
-
|
|
161
|
+
throw new Error(formatNoApiKeyFoundMessage(model.provider));
|
|
162
|
+
}
|
|
163
|
+
async _getCompactionRequestAuth(model) {
|
|
164
|
+
if (this.agent.streamFn === streamSimple) {
|
|
165
|
+
return this._getRequiredRequestAuth(model);
|
|
166
|
+
}
|
|
167
|
+
const result = await this._modelRegistry.getApiKeyAndHeaders(model);
|
|
168
|
+
return result.ok ? { apiKey: result.apiKey, headers: result.headers } : {};
|
|
158
169
|
}
|
|
159
170
|
/**
|
|
160
171
|
* Install tool hooks once on the Agent instance.
|
|
@@ -167,10 +178,9 @@ export class AgentSession {
|
|
|
167
178
|
_installAgentToolHooks() {
|
|
168
179
|
this.agent.beforeToolCall = async ({ toolCall, args }) => {
|
|
169
180
|
const runner = this._extensionRunner;
|
|
170
|
-
if (!runner
|
|
181
|
+
if (!runner.hasHandlers("tool_call")) {
|
|
171
182
|
return undefined;
|
|
172
183
|
}
|
|
173
|
-
await this._agentEventQueue;
|
|
174
184
|
try {
|
|
175
185
|
return await runner.emitToolCall({
|
|
176
186
|
type: "tool_call",
|
|
@@ -188,7 +198,7 @@ export class AgentSession {
|
|
|
188
198
|
};
|
|
189
199
|
this.agent.afterToolCall = async ({ toolCall, args, result, isError }) => {
|
|
190
200
|
const runner = this._extensionRunner;
|
|
191
|
-
if (!runner
|
|
201
|
+
if (!runner.hasHandlers("tool_result")) {
|
|
192
202
|
return undefined;
|
|
193
203
|
}
|
|
194
204
|
const hookResult = await runner.emitToolResult({
|
|
@@ -197,15 +207,16 @@ export class AgentSession {
|
|
|
197
207
|
toolCallId: toolCall.id,
|
|
198
208
|
input: args,
|
|
199
209
|
content: result.content,
|
|
200
|
-
details:
|
|
210
|
+
details: result.details,
|
|
201
211
|
isError,
|
|
202
212
|
});
|
|
203
|
-
if (!hookResult
|
|
213
|
+
if (!hookResult) {
|
|
204
214
|
return undefined;
|
|
205
215
|
}
|
|
206
216
|
return {
|
|
207
217
|
content: hookResult.content,
|
|
208
218
|
details: hookResult.details,
|
|
219
|
+
isError: hookResult.isError ?? isError,
|
|
209
220
|
};
|
|
210
221
|
};
|
|
211
222
|
}
|
|
@@ -228,43 +239,7 @@ export class AgentSession {
|
|
|
228
239
|
// Track last assistant message for auto-compaction check
|
|
229
240
|
_lastAssistantMessage = undefined;
|
|
230
241
|
/** Internal handler for agent events - shared by subscribe and reconnect */
|
|
231
|
-
_handleAgentEvent = (event) => {
|
|
232
|
-
// Create retry promise synchronously before queueing async processing.
|
|
233
|
-
// Agent.emit() calls this handler synchronously, and prompt() calls waitForRetry()
|
|
234
|
-
// as soon as agent.prompt() resolves. If _retryPromise is created only inside
|
|
235
|
-
// _processAgentEvent, slow earlier queued events can delay agent_end processing
|
|
236
|
-
// and waitForRetry() can miss the in-flight retry.
|
|
237
|
-
this._createRetryPromiseForAgentEnd(event);
|
|
238
|
-
this._agentEventQueue = this._agentEventQueue.then(() => this._processAgentEvent(event), () => this._processAgentEvent(event));
|
|
239
|
-
// Keep queue alive if an event handler fails
|
|
240
|
-
this._agentEventQueue.catch(() => { });
|
|
241
|
-
};
|
|
242
|
-
_createRetryPromiseForAgentEnd(event) {
|
|
243
|
-
if (event.type !== "agent_end" || this._retryPromise) {
|
|
244
|
-
return;
|
|
245
|
-
}
|
|
246
|
-
const settings = this.settingsManager.getRetrySettings();
|
|
247
|
-
if (!settings.enabled) {
|
|
248
|
-
return;
|
|
249
|
-
}
|
|
250
|
-
const lastAssistant = this._findLastAssistantInMessages(event.messages);
|
|
251
|
-
if (!lastAssistant || !this._isRetryableError(lastAssistant)) {
|
|
252
|
-
return;
|
|
253
|
-
}
|
|
254
|
-
this._retryPromise = new Promise((resolve) => {
|
|
255
|
-
this._retryResolve = resolve;
|
|
256
|
-
});
|
|
257
|
-
}
|
|
258
|
-
_findLastAssistantInMessages(messages) {
|
|
259
|
-
for (let i = messages.length - 1; i >= 0; i--) {
|
|
260
|
-
const message = messages[i];
|
|
261
|
-
if (message.role === "assistant") {
|
|
262
|
-
return message;
|
|
263
|
-
}
|
|
264
|
-
}
|
|
265
|
-
return undefined;
|
|
266
|
-
}
|
|
267
|
-
async _processAgentEvent(event) {
|
|
242
|
+
_handleAgentEvent = async (event) => {
|
|
268
243
|
// When a user message starts, check if it's from either queue and remove it BEFORE emitting
|
|
269
244
|
// This ensures the UI sees the updated queue state
|
|
270
245
|
if (event.type === "message_start" && event.message.role === "user") {
|
|
@@ -290,7 +265,7 @@ export class AgentSession {
|
|
|
290
265
|
// Emit to extensions first
|
|
291
266
|
await this._emitExtensionEvent(event);
|
|
292
267
|
// Notify all listeners
|
|
293
|
-
this._emit(event);
|
|
268
|
+
this._emit(event.type === "agent_end" ? { ...event, willRetry: this._willRetryAfterAgentEnd(event) } : event);
|
|
294
269
|
// Handle session persistence
|
|
295
270
|
if (event.type === "message_end") {
|
|
296
271
|
// Check if this is a custom message from extensions
|
|
@@ -324,27 +299,19 @@ export class AgentSession {
|
|
|
324
299
|
}
|
|
325
300
|
}
|
|
326
301
|
}
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
if (this._isRetryableError(msg)) {
|
|
333
|
-
const didRetry = await this._handleRetryableError(msg);
|
|
334
|
-
if (didRetry)
|
|
335
|
-
return; // Retry was initiated, don't proceed to compaction
|
|
336
|
-
}
|
|
337
|
-
this._resolveRetry();
|
|
338
|
-
await this._checkCompaction(msg);
|
|
302
|
+
};
|
|
303
|
+
_willRetryAfterAgentEnd(event) {
|
|
304
|
+
const settings = this.settingsManager.getRetrySettings();
|
|
305
|
+
if (!settings.enabled || this._retryAttempt >= settings.maxRetries) {
|
|
306
|
+
return false;
|
|
339
307
|
}
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
this._retryResolve = undefined;
|
|
346
|
-
this._retryPromise = undefined;
|
|
308
|
+
for (let i = event.messages.length - 1; i >= 0; i--) {
|
|
309
|
+
const message = event.messages[i];
|
|
310
|
+
if (message.role === "assistant") {
|
|
311
|
+
return this._isRetryableError(message);
|
|
312
|
+
}
|
|
347
313
|
}
|
|
314
|
+
return false;
|
|
348
315
|
}
|
|
349
316
|
/** Extract text content from a message */
|
|
350
317
|
_getUserMessageText(message) {
|
|
@@ -367,10 +334,22 @@ export class AgentSession {
|
|
|
367
334
|
}
|
|
368
335
|
return undefined;
|
|
369
336
|
}
|
|
337
|
+
_replaceMessageInPlace(target, replacement) {
|
|
338
|
+
// Agent-core stores the finalized message object in its state before emitting message_end.
|
|
339
|
+
// SessionManager persistence happens later in _handleAgentEvent() with event.message.
|
|
340
|
+
// Mutating this object in place keeps agent state, later turn/agent events, listeners,
|
|
341
|
+
// and the eventual SessionManager.appendMessage(event.message) persistence in sync.
|
|
342
|
+
if (target === replacement) {
|
|
343
|
+
return;
|
|
344
|
+
}
|
|
345
|
+
const targetRecord = target;
|
|
346
|
+
for (const key of Object.keys(targetRecord)) {
|
|
347
|
+
delete targetRecord[key];
|
|
348
|
+
}
|
|
349
|
+
Object.assign(targetRecord, replacement);
|
|
350
|
+
}
|
|
370
351
|
/** Emit extension events based on agent events */
|
|
371
352
|
async _emitExtensionEvent(event) {
|
|
372
|
-
if (!this._extensionRunner)
|
|
373
|
-
return;
|
|
374
353
|
if (event.type === "agent_start") {
|
|
375
354
|
this._turnIndex = 0;
|
|
376
355
|
await this._extensionRunner.emit({ type: "agent_start" });
|
|
@@ -416,7 +395,10 @@ export class AgentSession {
|
|
|
416
395
|
type: "message_end",
|
|
417
396
|
message: event.message,
|
|
418
397
|
};
|
|
419
|
-
await this._extensionRunner.
|
|
398
|
+
const replacement = await this._extensionRunner.emitMessageEnd(extensionEvent);
|
|
399
|
+
if (replacement) {
|
|
400
|
+
this._replaceMessageInPlace(event.message, replacement);
|
|
401
|
+
}
|
|
420
402
|
}
|
|
421
403
|
else if (event.type === "tool_execution_start") {
|
|
422
404
|
const extensionEvent = {
|
|
@@ -488,8 +470,20 @@ export class AgentSession {
|
|
|
488
470
|
* Call this when completely done with the session.
|
|
489
471
|
*/
|
|
490
472
|
dispose() {
|
|
473
|
+
try {
|
|
474
|
+
this.abortRetry();
|
|
475
|
+
this.abortCompaction();
|
|
476
|
+
this.abortBranchSummary();
|
|
477
|
+
this.abortBash();
|
|
478
|
+
this.agent.abort();
|
|
479
|
+
}
|
|
480
|
+
catch {
|
|
481
|
+
// Dispose must succeed even if an abort hook throws.
|
|
482
|
+
}
|
|
483
|
+
this._extensionRunner.invalidate("This extension ctx is stale after session replacement or reload. Do not use a captured pi or command ctx after ctx.newSession(), ctx.fork(), ctx.switchSession(), or ctx.reload(). For newSession, fork, and switchSession, move post-replacement work into withSession and use the ctx passed to withSession. For reload, do not use the old ctx after await ctx.reload().");
|
|
491
484
|
this._disconnectFromAgent();
|
|
492
485
|
this._eventListeners = [];
|
|
486
|
+
cleanupSessionResources(this.sessionId);
|
|
493
487
|
}
|
|
494
488
|
// =========================================================================
|
|
495
489
|
// Read-only State Access
|
|
@@ -526,13 +520,14 @@ export class AgentSession {
|
|
|
526
520
|
return this.agent.state.tools.map((t) => t.name);
|
|
527
521
|
}
|
|
528
522
|
/**
|
|
529
|
-
* Get all configured tools with name, description, parameter schema, and source metadata.
|
|
523
|
+
* Get all configured tools with name, description, parameter schema, prompt guidelines, and source metadata.
|
|
530
524
|
*/
|
|
531
525
|
getAllTools() {
|
|
532
526
|
return Array.from(this._toolDefinitions.values()).map(({ definition, sourceInfo }) => ({
|
|
533
527
|
name: definition.name,
|
|
534
528
|
description: definition.description,
|
|
535
529
|
parameters: definition.parameters,
|
|
530
|
+
promptGuidelines: definition.promptGuidelines,
|
|
536
531
|
sourceInfo,
|
|
537
532
|
}));
|
|
538
533
|
}
|
|
@@ -643,7 +638,7 @@ export class AgentSession {
|
|
|
643
638
|
const appendSystemPrompt = loaderAppendSystemPrompt.length > 0 ? loaderAppendSystemPrompt.join("\n\n") : undefined;
|
|
644
639
|
const loadedSkills = this._resourceLoader.getSkills().skills;
|
|
645
640
|
const loadedContextFiles = this._resourceLoader.getAgentsFiles().agentsFiles;
|
|
646
|
-
|
|
641
|
+
this._baseSystemPromptOptions = {
|
|
647
642
|
cwd: this._cwd,
|
|
648
643
|
skills: loadedSkills,
|
|
649
644
|
contextFiles: loadedContextFiles,
|
|
@@ -652,11 +647,48 @@ export class AgentSession {
|
|
|
652
647
|
selectedTools: validToolNames,
|
|
653
648
|
toolSnippets,
|
|
654
649
|
promptGuidelines,
|
|
655
|
-
}
|
|
650
|
+
};
|
|
651
|
+
return buildSystemPrompt(this._baseSystemPromptOptions);
|
|
656
652
|
}
|
|
657
653
|
// =========================================================================
|
|
658
654
|
// Prompting
|
|
659
655
|
// =========================================================================
|
|
656
|
+
async _runAgentPrompt(messages) {
|
|
657
|
+
try {
|
|
658
|
+
await this.agent.prompt(messages);
|
|
659
|
+
while (await this._handlePostAgentRun()) {
|
|
660
|
+
await this.agent.continue();
|
|
661
|
+
}
|
|
662
|
+
}
|
|
663
|
+
finally {
|
|
664
|
+
this._flushPendingBashMessages();
|
|
665
|
+
}
|
|
666
|
+
}
|
|
667
|
+
async _handlePostAgentRun() {
|
|
668
|
+
const msg = this._lastAssistantMessage;
|
|
669
|
+
this._lastAssistantMessage = undefined;
|
|
670
|
+
if (!msg) {
|
|
671
|
+
return false;
|
|
672
|
+
}
|
|
673
|
+
if (this._isRetryableError(msg) && (await this._prepareRetry(msg))) {
|
|
674
|
+
return true;
|
|
675
|
+
}
|
|
676
|
+
if (msg.stopReason === "error" && this._retryAttempt > 0) {
|
|
677
|
+
this._emit({
|
|
678
|
+
type: "auto_retry_end",
|
|
679
|
+
success: false,
|
|
680
|
+
attempt: this._retryAttempt,
|
|
681
|
+
finalError: msg.errorMessage,
|
|
682
|
+
});
|
|
683
|
+
this._retryAttempt = 0;
|
|
684
|
+
}
|
|
685
|
+
if (await this._checkCompaction(msg)) {
|
|
686
|
+
return true;
|
|
687
|
+
}
|
|
688
|
+
// The agent loop drains both queues before emitting agent_end. Any messages
|
|
689
|
+
// here were queued by agent_end extension handlers and need a continuation.
|
|
690
|
+
return this.agent.hasQueuedMessages();
|
|
691
|
+
}
|
|
660
692
|
/**
|
|
661
693
|
* Send a prompt to the agent.
|
|
662
694
|
* - Handles extension commands (registered via pi.registerCommand) immediately, even during streaming
|
|
@@ -668,90 +700,100 @@ export class AgentSession {
|
|
|
668
700
|
*/
|
|
669
701
|
async prompt(text, options) {
|
|
670
702
|
const expandPromptTemplates = options?.expandPromptTemplates ?? true;
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
703
|
+
const preflightResult = options?.preflightResult;
|
|
704
|
+
let messages;
|
|
705
|
+
try {
|
|
706
|
+
// Handle extension commands first (execute immediately, even during streaming)
|
|
707
|
+
// Extension commands manage their own LLM interaction via pi.sendMessage()
|
|
708
|
+
if (expandPromptTemplates && text.startsWith("/")) {
|
|
709
|
+
const handled = await this._tryExecuteExtensionCommand(text);
|
|
710
|
+
if (handled) {
|
|
711
|
+
// Extension command executed, no prompt to send
|
|
712
|
+
preflightResult?.(true);
|
|
713
|
+
return;
|
|
714
|
+
}
|
|
678
715
|
}
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
716
|
+
// Emit input event for extension interception (before skill/template expansion)
|
|
717
|
+
let currentText = text;
|
|
718
|
+
let currentImages = options?.images;
|
|
719
|
+
if (this._extensionRunner.hasHandlers("input")) {
|
|
720
|
+
const inputResult = await this._extensionRunner.emitInput(currentText, currentImages, options?.source ?? "interactive", this.isStreaming ? options?.streamingBehavior : undefined);
|
|
721
|
+
if (inputResult.action === "handled") {
|
|
722
|
+
preflightResult?.(true);
|
|
723
|
+
return;
|
|
724
|
+
}
|
|
725
|
+
if (inputResult.action === "transform") {
|
|
726
|
+
currentText = inputResult.text;
|
|
727
|
+
currentImages = inputResult.images ?? currentImages;
|
|
728
|
+
}
|
|
687
729
|
}
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
730
|
+
// Expand skill commands (/skill:name args) and prompt templates (/template args)
|
|
731
|
+
let expandedText = currentText;
|
|
732
|
+
if (expandPromptTemplates) {
|
|
733
|
+
expandedText = this._expandSkillCommand(expandedText);
|
|
734
|
+
expandedText = expandPromptTemplate(expandedText, [...this.promptTemplates]);
|
|
691
735
|
}
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
736
|
+
// If streaming, queue via steer() or followUp() based on option
|
|
737
|
+
if (this.isStreaming) {
|
|
738
|
+
if (!options?.streamingBehavior) {
|
|
739
|
+
throw new Error("Agent is already processing. Specify streamingBehavior ('steer' or 'followUp') to queue the message.");
|
|
740
|
+
}
|
|
741
|
+
if (options.streamingBehavior === "followUp") {
|
|
742
|
+
await this._queueFollowUp(expandedText, currentImages);
|
|
743
|
+
}
|
|
744
|
+
else {
|
|
745
|
+
await this._queueSteer(expandedText, currentImages);
|
|
746
|
+
}
|
|
747
|
+
preflightResult?.(true);
|
|
748
|
+
return;
|
|
703
749
|
}
|
|
704
|
-
|
|
705
|
-
|
|
750
|
+
// Flush any pending bash messages before the new prompt
|
|
751
|
+
this._flushPendingBashMessages();
|
|
752
|
+
// Validate model
|
|
753
|
+
if (!this.model) {
|
|
754
|
+
throw new Error(formatNoModelSelectedMessage());
|
|
755
|
+
}
|
|
756
|
+
if (!this._modelRegistry.hasConfiguredAuth(this.model)) {
|
|
757
|
+
const isOAuth = this._modelRegistry.isUsingOAuth(this.model);
|
|
758
|
+
if (isOAuth) {
|
|
759
|
+
throw new Error(`Authentication failed for "${this.model.provider}". ` +
|
|
760
|
+
`Credentials may have expired or network is unavailable. ` +
|
|
761
|
+
`Run '/login ${this.model.provider}' to re-authenticate.`);
|
|
762
|
+
}
|
|
763
|
+
throw new Error(formatNoApiKeyFoundMessage(this.model.provider));
|
|
764
|
+
}
|
|
765
|
+
// Check if we need to compact before sending (catches aborted responses)
|
|
766
|
+
const lastAssistant = this._findLastAssistantMessage();
|
|
767
|
+
if (lastAssistant && (await this._checkCompaction(lastAssistant, false))) {
|
|
768
|
+
try {
|
|
769
|
+
await this.agent.continue();
|
|
770
|
+
while (await this._handlePostAgentRun()) {
|
|
771
|
+
await this.agent.continue();
|
|
772
|
+
}
|
|
773
|
+
}
|
|
774
|
+
finally {
|
|
775
|
+
this._flushPendingBashMessages();
|
|
776
|
+
}
|
|
706
777
|
}
|
|
707
|
-
|
|
708
|
-
|
|
778
|
+
// Build messages array (custom message if any, then user message)
|
|
779
|
+
messages = [];
|
|
780
|
+
// Add user message
|
|
781
|
+
const userContent = [{ type: "text", text: expandedText }];
|
|
782
|
+
if (currentImages) {
|
|
783
|
+
userContent.push(...currentImages);
|
|
709
784
|
}
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
const
|
|
722
|
-
if (isOAuth) {
|
|
723
|
-
throw new Error(`Authentication failed for "${this.model.provider}". ` +
|
|
724
|
-
`Credentials may have expired or network is unavailable. ` +
|
|
725
|
-
`Run '/login ${this.model.provider}' to re-authenticate.`);
|
|
726
|
-
}
|
|
727
|
-
throw new Error(`No API key found for ${this.model.provider}.\n\n` +
|
|
728
|
-
`Use /login or set an API key environment variable. See ${join(getDocsPath(), "providers.md")}`);
|
|
729
|
-
}
|
|
730
|
-
// Check if we need to compact before sending (catches aborted responses)
|
|
731
|
-
const lastAssistant = this._findLastAssistantMessage();
|
|
732
|
-
if (lastAssistant) {
|
|
733
|
-
await this._checkCompaction(lastAssistant, false);
|
|
734
|
-
}
|
|
735
|
-
// Build messages array (custom message if any, then user message)
|
|
736
|
-
const messages = [];
|
|
737
|
-
// Add user message
|
|
738
|
-
const userContent = [{ type: "text", text: expandedText }];
|
|
739
|
-
if (currentImages) {
|
|
740
|
-
userContent.push(...currentImages);
|
|
741
|
-
}
|
|
742
|
-
messages.push({
|
|
743
|
-
role: "user",
|
|
744
|
-
content: userContent,
|
|
745
|
-
timestamp: Date.now(),
|
|
746
|
-
});
|
|
747
|
-
// Inject any pending "nextTurn" messages as context alongside the user message
|
|
748
|
-
for (const msg of this._pendingNextTurnMessages) {
|
|
749
|
-
messages.push(msg);
|
|
750
|
-
}
|
|
751
|
-
this._pendingNextTurnMessages = [];
|
|
752
|
-
// Emit before_agent_start extension event
|
|
753
|
-
if (this._extensionRunner) {
|
|
754
|
-
const result = await this._extensionRunner.emitBeforeAgentStart(expandedText, currentImages, this._baseSystemPrompt);
|
|
785
|
+
messages.push({
|
|
786
|
+
role: "user",
|
|
787
|
+
content: userContent,
|
|
788
|
+
timestamp: Date.now(),
|
|
789
|
+
});
|
|
790
|
+
// Inject any pending "nextTurn" messages as context alongside the user message
|
|
791
|
+
for (const msg of this._pendingNextTurnMessages) {
|
|
792
|
+
messages.push(msg);
|
|
793
|
+
}
|
|
794
|
+
this._pendingNextTurnMessages = [];
|
|
795
|
+
// Emit before_agent_start extension event
|
|
796
|
+
const result = await this._extensionRunner.emitBeforeAgentStart(expandedText, currentImages, this._baseSystemPrompt, this._baseSystemPromptOptions);
|
|
755
797
|
// Add all custom messages from extensions
|
|
756
798
|
if (result?.messages) {
|
|
757
799
|
for (const msg of result.messages) {
|
|
@@ -774,15 +816,20 @@ export class AgentSession {
|
|
|
774
816
|
this.agent.state.systemPrompt = this._baseSystemPrompt;
|
|
775
817
|
}
|
|
776
818
|
}
|
|
777
|
-
|
|
778
|
-
|
|
819
|
+
catch (error) {
|
|
820
|
+
preflightResult?.(false);
|
|
821
|
+
throw error;
|
|
822
|
+
}
|
|
823
|
+
if (!messages) {
|
|
824
|
+
return;
|
|
825
|
+
}
|
|
826
|
+
preflightResult?.(true);
|
|
827
|
+
await this._runAgentPrompt(messages);
|
|
779
828
|
}
|
|
780
829
|
/**
|
|
781
830
|
* Try to execute an extension command. Returns true if command was found and executed.
|
|
782
831
|
*/
|
|
783
832
|
async _tryExecuteExtensionCommand(text) {
|
|
784
|
-
if (!this._extensionRunner)
|
|
785
|
-
return false;
|
|
786
833
|
// Parse command name and args
|
|
787
834
|
const spaceIndex = text.indexOf(" ");
|
|
788
835
|
const commandName = spaceIndex === -1 ? text.slice(1) : text.slice(1, spaceIndex);
|
|
@@ -828,7 +875,7 @@ export class AgentSession {
|
|
|
828
875
|
}
|
|
829
876
|
catch (err) {
|
|
830
877
|
// Emit error like extension commands do
|
|
831
|
-
this._extensionRunner
|
|
878
|
+
this._extensionRunner.emitError({
|
|
832
879
|
extensionPath: skill.filePath,
|
|
833
880
|
event: "skill_expansion",
|
|
834
881
|
error: err instanceof Error ? err.message : String(err),
|
|
@@ -907,8 +954,6 @@ export class AgentSession {
|
|
|
907
954
|
* Throw an error if the text is an extension command.
|
|
908
955
|
*/
|
|
909
956
|
_throwIfExtensionCommand(text) {
|
|
910
|
-
if (!this._extensionRunner)
|
|
911
|
-
return;
|
|
912
957
|
const spaceIndex = text.indexOf(" ");
|
|
913
958
|
const commandName = spaceIndex === -1 ? text.slice(1) : text.slice(1, spaceIndex);
|
|
914
959
|
const command = this._extensionRunner.getCommand(commandName);
|
|
@@ -949,7 +994,7 @@ export class AgentSession {
|
|
|
949
994
|
}
|
|
950
995
|
}
|
|
951
996
|
else if (options?.triggerTurn) {
|
|
952
|
-
await this.
|
|
997
|
+
await this._runAgentPrompt(appMessage);
|
|
953
998
|
}
|
|
954
999
|
else {
|
|
955
1000
|
this.agent.state.messages.push(appMessage);
|
|
@@ -1036,8 +1081,6 @@ export class AgentSession {
|
|
|
1036
1081
|
// Model Management
|
|
1037
1082
|
// =========================================================================
|
|
1038
1083
|
async _emitModelSelect(nextModel, previousModel, source) {
|
|
1039
|
-
if (!this._extensionRunner)
|
|
1040
|
-
return;
|
|
1041
1084
|
if (modelsAreEqual(previousModel, nextModel))
|
|
1042
1085
|
return;
|
|
1043
1086
|
await this._extensionRunner.emit({
|
|
@@ -1133,13 +1176,20 @@ export class AgentSession {
|
|
|
1133
1176
|
const availableLevels = this.getAvailableThinkingLevels();
|
|
1134
1177
|
const effectiveLevel = availableLevels.includes(level) ? level : this._clampThinkingLevel(level, availableLevels);
|
|
1135
1178
|
// Only persist if actually changing
|
|
1136
|
-
const
|
|
1179
|
+
const previousLevel = this.agent.state.thinkingLevel;
|
|
1180
|
+
const isChanging = effectiveLevel !== previousLevel;
|
|
1137
1181
|
this.agent.state.thinkingLevel = effectiveLevel;
|
|
1138
1182
|
if (isChanging) {
|
|
1139
1183
|
this.sessionManager.appendThinkingLevelChange(effectiveLevel);
|
|
1140
1184
|
if (this.supportsThinking() || effectiveLevel !== "off") {
|
|
1141
1185
|
this.settingsManager.setDefaultThinkingLevel(effectiveLevel);
|
|
1142
1186
|
}
|
|
1187
|
+
this._emit({ type: "thinking_level_changed", level: effectiveLevel });
|
|
1188
|
+
void this._extensionRunner.emit({
|
|
1189
|
+
type: "thinking_level_select",
|
|
1190
|
+
level: effectiveLevel,
|
|
1191
|
+
previousLevel,
|
|
1192
|
+
});
|
|
1143
1193
|
}
|
|
1144
1194
|
}
|
|
1145
1195
|
/**
|
|
@@ -1161,23 +1211,9 @@ export class AgentSession {
|
|
|
1161
1211
|
* The provider will clamp to what the specific model supports internally.
|
|
1162
1212
|
*/
|
|
1163
1213
|
getAvailableThinkingLevels() {
|
|
1164
|
-
if (!this.
|
|
1165
|
-
return
|
|
1166
|
-
|
|
1167
|
-
return THINKING_LEVELS_WITH_MAX;
|
|
1168
|
-
return this.supportsXhighThinking() ? THINKING_LEVELS_WITH_XHIGH : THINKING_LEVELS;
|
|
1169
|
-
}
|
|
1170
|
-
/**
|
|
1171
|
-
* Check if current model supports xhigh thinking level.
|
|
1172
|
-
*/
|
|
1173
|
-
supportsXhighThinking() {
|
|
1174
|
-
return this.model ? supportsXhigh(this.model) : false;
|
|
1175
|
-
}
|
|
1176
|
-
/**
|
|
1177
|
-
* Check if current model supports the `max` thinking level (Anthropic Opus 4.6/4.7 only).
|
|
1178
|
-
*/
|
|
1179
|
-
supportsMaxThinking() {
|
|
1180
|
-
return this.model ? supportsMax(this.model) : false;
|
|
1214
|
+
if (!this.model)
|
|
1215
|
+
return THINKING_LEVELS;
|
|
1216
|
+
return getSupportedThinkingLevels(this.model);
|
|
1181
1217
|
}
|
|
1182
1218
|
/**
|
|
1183
1219
|
* Check if current model supports thinking/reasoning.
|
|
@@ -1194,28 +1230,16 @@ export class AgentSession {
|
|
|
1194
1230
|
}
|
|
1195
1231
|
return this.thinkingLevel;
|
|
1196
1232
|
}
|
|
1197
|
-
_clampThinkingLevel(level,
|
|
1198
|
-
|
|
1199
|
-
const available = new Set(availableLevels);
|
|
1200
|
-
const requestedIndex = ordered.indexOf(level);
|
|
1201
|
-
if (requestedIndex === -1) {
|
|
1202
|
-
return availableLevels[0] ?? "off";
|
|
1203
|
-
}
|
|
1204
|
-
for (let i = requestedIndex; i < ordered.length; i++) {
|
|
1205
|
-
const candidate = ordered[i];
|
|
1206
|
-
if (available.has(candidate))
|
|
1207
|
-
return candidate;
|
|
1208
|
-
}
|
|
1209
|
-
for (let i = requestedIndex - 1; i >= 0; i--) {
|
|
1210
|
-
const candidate = ordered[i];
|
|
1211
|
-
if (available.has(candidate))
|
|
1212
|
-
return candidate;
|
|
1213
|
-
}
|
|
1214
|
-
return availableLevels[0] ?? "off";
|
|
1233
|
+
_clampThinkingLevel(level, _availableLevels) {
|
|
1234
|
+
return this.model ? clampThinkingLevel(this.model, level) : "off";
|
|
1215
1235
|
}
|
|
1216
1236
|
// =========================================================================
|
|
1217
1237
|
// Queue Mode Management
|
|
1218
1238
|
// =========================================================================
|
|
1239
|
+
syncQueueModesFromSettings() {
|
|
1240
|
+
this.agent.steeringMode = this.settingsManager.getSteeringMode();
|
|
1241
|
+
this.agent.followUpMode = this.settingsManager.getFollowUpMode();
|
|
1242
|
+
}
|
|
1219
1243
|
/**
|
|
1220
1244
|
* Set steering message mode.
|
|
1221
1245
|
* Saves to settings.
|
|
@@ -1247,9 +1271,9 @@ export class AgentSession {
|
|
|
1247
1271
|
this._emit({ type: "compaction_start", reason: "manual" });
|
|
1248
1272
|
try {
|
|
1249
1273
|
if (!this.model) {
|
|
1250
|
-
throw new Error(
|
|
1274
|
+
throw new Error(formatNoModelSelectedMessage());
|
|
1251
1275
|
}
|
|
1252
|
-
const { apiKey, headers } = await this.
|
|
1276
|
+
const { apiKey, headers } = await this._getCompactionRequestAuth(this.model);
|
|
1253
1277
|
const pathEntries = this.sessionManager.getBranch();
|
|
1254
1278
|
const settings = this.settingsManager.getCompactionSettings();
|
|
1255
1279
|
const preparation = prepareCompaction(pathEntries, settings);
|
|
@@ -1263,7 +1287,7 @@ export class AgentSession {
|
|
|
1263
1287
|
}
|
|
1264
1288
|
let extensionCompaction;
|
|
1265
1289
|
let fromExtension = false;
|
|
1266
|
-
if (this._extensionRunner
|
|
1290
|
+
if (this._extensionRunner.hasHandlers("session_before_compact")) {
|
|
1267
1291
|
const result = (await this._extensionRunner.emit({
|
|
1268
1292
|
type: "session_before_compact",
|
|
1269
1293
|
preparation,
|
|
@@ -1292,7 +1316,7 @@ export class AgentSession {
|
|
|
1292
1316
|
}
|
|
1293
1317
|
else {
|
|
1294
1318
|
// Generate compaction result
|
|
1295
|
-
const result = await compact(preparation, this.model, apiKey, headers, customInstructions, this._compactionAbortController.signal);
|
|
1319
|
+
const result = await compact(preparation, this.model, apiKey, headers, customInstructions, this._compactionAbortController.signal, this.thinkingLevel, this.agent.streamFn);
|
|
1296
1320
|
summary = result.summary;
|
|
1297
1321
|
firstKeptEntryId = result.firstKeptEntryId;
|
|
1298
1322
|
tokensBefore = result.tokensBefore;
|
|
@@ -1374,10 +1398,10 @@ export class AgentSession {
|
|
|
1374
1398
|
async _checkCompaction(assistantMessage, skipAbortedCheck = true) {
|
|
1375
1399
|
const settings = this.settingsManager.getCompactionSettings();
|
|
1376
1400
|
if (!settings.enabled)
|
|
1377
|
-
return;
|
|
1401
|
+
return false;
|
|
1378
1402
|
// Skip if message was aborted (user cancelled) - unless skipAbortedCheck is false
|
|
1379
1403
|
if (skipAbortedCheck && assistantMessage.stopReason === "aborted")
|
|
1380
|
-
return;
|
|
1404
|
+
return false;
|
|
1381
1405
|
const contextWindow = this.model?.contextWindow ?? 0;
|
|
1382
1406
|
// Skip overflow check if the message came from a different model.
|
|
1383
1407
|
// This handles the case where user switched from a smaller-context model (e.g. opus)
|
|
@@ -1390,7 +1414,7 @@ export class AgentSession {
|
|
|
1390
1414
|
const compactionEntry = getLatestCompactionEntry(this.sessionManager.getBranch());
|
|
1391
1415
|
const assistantIsFromBeforeCompaction = compactionEntry !== null && assistantMessage.timestamp <= new Date(compactionEntry.timestamp).getTime();
|
|
1392
1416
|
if (assistantIsFromBeforeCompaction) {
|
|
1393
|
-
return;
|
|
1417
|
+
return false;
|
|
1394
1418
|
}
|
|
1395
1419
|
// Case 1: Overflow - LLM returned context overflow error
|
|
1396
1420
|
if (sameModel && isContextOverflow(assistantMessage, contextWindow)) {
|
|
@@ -1403,7 +1427,7 @@ export class AgentSession {
|
|
|
1403
1427
|
willRetry: false,
|
|
1404
1428
|
errorMessage: "Context overflow recovery failed after one compact-and-retry attempt. Try reducing context or switching to a larger-context model.",
|
|
1405
1429
|
});
|
|
1406
|
-
return;
|
|
1430
|
+
return false;
|
|
1407
1431
|
}
|
|
1408
1432
|
this._overflowRecoveryAttempted = true;
|
|
1409
1433
|
// Remove the error message from agent state (it IS saved to session for history,
|
|
@@ -1412,8 +1436,7 @@ export class AgentSession {
|
|
|
1412
1436
|
if (messages.length > 0 && messages[messages.length - 1].role === "assistant") {
|
|
1413
1437
|
this.agent.state.messages = messages.slice(0, -1);
|
|
1414
1438
|
}
|
|
1415
|
-
await this._runAutoCompaction("overflow", true);
|
|
1416
|
-
return;
|
|
1439
|
+
return await this._runAutoCompaction("overflow", true);
|
|
1417
1440
|
}
|
|
1418
1441
|
// Case 2: Threshold - context is getting large
|
|
1419
1442
|
// For error messages (no usage data), estimate from last successful response.
|
|
@@ -1423,7 +1446,7 @@ export class AgentSession {
|
|
|
1423
1446
|
const messages = this.agent.state.messages;
|
|
1424
1447
|
const estimate = estimateContextTokens(messages);
|
|
1425
1448
|
if (estimate.lastUsageIndex === null)
|
|
1426
|
-
return; // No usage data at all
|
|
1449
|
+
return false; // No usage data at all
|
|
1427
1450
|
// Verify the usage source is post-compaction. Kept pre-compaction messages
|
|
1428
1451
|
// have stale usage reflecting the old (larger) context and would falsely
|
|
1429
1452
|
// trigger compaction right after one just finished.
|
|
@@ -1431,7 +1454,7 @@ export class AgentSession {
|
|
|
1431
1454
|
if (compactionEntry &&
|
|
1432
1455
|
usageMsg.role === "assistant" &&
|
|
1433
1456
|
usageMsg.timestamp <= new Date(compactionEntry.timestamp).getTime()) {
|
|
1434
|
-
return;
|
|
1457
|
+
return false;
|
|
1435
1458
|
}
|
|
1436
1459
|
contextTokens = estimate.tokens;
|
|
1437
1460
|
}
|
|
@@ -1439,8 +1462,9 @@ export class AgentSession {
|
|
|
1439
1462
|
contextTokens = calculateContextTokens(assistantMessage.usage);
|
|
1440
1463
|
}
|
|
1441
1464
|
if (shouldCompact(contextTokens, contextWindow, settings)) {
|
|
1442
|
-
await this._runAutoCompaction("threshold", false);
|
|
1465
|
+
return await this._runAutoCompaction("threshold", false);
|
|
1443
1466
|
}
|
|
1467
|
+
return false;
|
|
1444
1468
|
}
|
|
1445
1469
|
/**
|
|
1446
1470
|
* Internal: Run auto-compaction with events.
|
|
@@ -1458,20 +1482,28 @@ export class AgentSession {
|
|
|
1458
1482
|
aborted: false,
|
|
1459
1483
|
willRetry: false,
|
|
1460
1484
|
});
|
|
1461
|
-
return;
|
|
1485
|
+
return false;
|
|
1462
1486
|
}
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1487
|
+
let apiKey;
|
|
1488
|
+
let headers;
|
|
1489
|
+
if (this.agent.streamFn === streamSimple) {
|
|
1490
|
+
const authResult = await this._modelRegistry.getApiKeyAndHeaders(this.model);
|
|
1491
|
+
if (!authResult.ok || !authResult.apiKey) {
|
|
1492
|
+
this._emit({
|
|
1493
|
+
type: "compaction_end",
|
|
1494
|
+
reason,
|
|
1495
|
+
result: undefined,
|
|
1496
|
+
aborted: false,
|
|
1497
|
+
willRetry: false,
|
|
1498
|
+
});
|
|
1499
|
+
return false;
|
|
1500
|
+
}
|
|
1501
|
+
apiKey = authResult.apiKey;
|
|
1502
|
+
headers = authResult.headers;
|
|
1503
|
+
}
|
|
1504
|
+
else {
|
|
1505
|
+
({ apiKey, headers } = await this._getCompactionRequestAuth(this.model));
|
|
1473
1506
|
}
|
|
1474
|
-
const { apiKey, headers } = authResult;
|
|
1475
1507
|
const pathEntries = this.sessionManager.getBranch();
|
|
1476
1508
|
const preparation = prepareCompaction(pathEntries, settings);
|
|
1477
1509
|
if (!preparation) {
|
|
@@ -1482,11 +1514,11 @@ export class AgentSession {
|
|
|
1482
1514
|
aborted: false,
|
|
1483
1515
|
willRetry: false,
|
|
1484
1516
|
});
|
|
1485
|
-
return;
|
|
1517
|
+
return false;
|
|
1486
1518
|
}
|
|
1487
1519
|
let extensionCompaction;
|
|
1488
1520
|
let fromExtension = false;
|
|
1489
|
-
if (this._extensionRunner
|
|
1521
|
+
if (this._extensionRunner.hasHandlers("session_before_compact")) {
|
|
1490
1522
|
const extensionResult = (await this._extensionRunner.emit({
|
|
1491
1523
|
type: "session_before_compact",
|
|
1492
1524
|
preparation,
|
|
@@ -1502,7 +1534,7 @@ export class AgentSession {
|
|
|
1502
1534
|
aborted: true,
|
|
1503
1535
|
willRetry: false,
|
|
1504
1536
|
});
|
|
1505
|
-
return;
|
|
1537
|
+
return false;
|
|
1506
1538
|
}
|
|
1507
1539
|
if (extensionResult?.compaction) {
|
|
1508
1540
|
extensionCompaction = extensionResult.compaction;
|
|
@@ -1522,7 +1554,7 @@ export class AgentSession {
|
|
|
1522
1554
|
}
|
|
1523
1555
|
else {
|
|
1524
1556
|
// Generate compaction result
|
|
1525
|
-
const compactResult = await compact(preparation, this.model, apiKey, headers, undefined, this._autoCompactionAbortController.signal);
|
|
1557
|
+
const compactResult = await compact(preparation, this.model, apiKey, headers, undefined, this._autoCompactionAbortController.signal, this.thinkingLevel, this.agent.streamFn);
|
|
1526
1558
|
summary = compactResult.summary;
|
|
1527
1559
|
firstKeptEntryId = compactResult.firstKeptEntryId;
|
|
1528
1560
|
tokensBefore = compactResult.tokensBefore;
|
|
@@ -1536,7 +1568,7 @@ export class AgentSession {
|
|
|
1536
1568
|
aborted: true,
|
|
1537
1569
|
willRetry: false,
|
|
1538
1570
|
});
|
|
1539
|
-
return;
|
|
1571
|
+
return false;
|
|
1540
1572
|
}
|
|
1541
1573
|
this.sessionManager.appendCompaction(summary, firstKeptEntryId, tokensBefore, details, fromExtension);
|
|
1542
1574
|
const newEntries = this.sessionManager.getEntries();
|
|
@@ -1564,17 +1596,11 @@ export class AgentSession {
|
|
|
1564
1596
|
if (lastMsg?.role === "assistant" && lastMsg.stopReason === "error") {
|
|
1565
1597
|
this.agent.state.messages = messages.slice(0, -1);
|
|
1566
1598
|
}
|
|
1567
|
-
|
|
1568
|
-
this.agent.continue().catch(() => { });
|
|
1569
|
-
}, 100);
|
|
1570
|
-
}
|
|
1571
|
-
else if (this.agent.hasQueuedMessages()) {
|
|
1572
|
-
// Auto-compaction can complete while follow-up/steering/custom messages are waiting.
|
|
1573
|
-
// Kick the loop so queued messages are actually delivered.
|
|
1574
|
-
setTimeout(() => {
|
|
1575
|
-
this.agent.continue().catch(() => { });
|
|
1576
|
-
}, 100);
|
|
1599
|
+
return true;
|
|
1577
1600
|
}
|
|
1601
|
+
// Auto-compaction can complete while follow-up/steering/custom messages are waiting.
|
|
1602
|
+
// Continue once so queued messages are delivered.
|
|
1603
|
+
return this.agent.hasQueuedMessages();
|
|
1578
1604
|
}
|
|
1579
1605
|
catch (error) {
|
|
1580
1606
|
const errorMessage = error instanceof Error ? error.message : "compaction failed";
|
|
@@ -1588,6 +1614,7 @@ export class AgentSession {
|
|
|
1588
1614
|
? `Context overflow recovery failed: ${errorMessage}`
|
|
1589
1615
|
: `Auto-compaction failed: ${errorMessage}`,
|
|
1590
1616
|
});
|
|
1617
|
+
return false;
|
|
1591
1618
|
}
|
|
1592
1619
|
finally {
|
|
1593
1620
|
this._autoCompactionAbortController = undefined;
|
|
@@ -1607,23 +1634,27 @@ export class AgentSession {
|
|
|
1607
1634
|
if (bindings.uiContext !== undefined) {
|
|
1608
1635
|
this._extensionUIContext = bindings.uiContext;
|
|
1609
1636
|
}
|
|
1637
|
+
if (bindings.mode !== undefined) {
|
|
1638
|
+
this._extensionMode = bindings.mode;
|
|
1639
|
+
}
|
|
1610
1640
|
if (bindings.commandContextActions !== undefined) {
|
|
1611
1641
|
this._extensionCommandContextActions = bindings.commandContextActions;
|
|
1612
1642
|
}
|
|
1643
|
+
if (bindings.abortHandler !== undefined) {
|
|
1644
|
+
this._extensionAbortHandler = bindings.abortHandler;
|
|
1645
|
+
}
|
|
1613
1646
|
if (bindings.shutdownHandler !== undefined) {
|
|
1614
1647
|
this._extensionShutdownHandler = bindings.shutdownHandler;
|
|
1615
1648
|
}
|
|
1616
1649
|
if (bindings.onError !== undefined) {
|
|
1617
1650
|
this._extensionErrorListener = bindings.onError;
|
|
1618
1651
|
}
|
|
1619
|
-
|
|
1620
|
-
|
|
1621
|
-
|
|
1622
|
-
await this.extendResourcesFromExtensions(this._sessionStartEvent.reason === "reload" ? "reload" : "startup");
|
|
1623
|
-
}
|
|
1652
|
+
this._applyExtensionBindings(this._extensionRunner);
|
|
1653
|
+
await this._extensionRunner.emit(this._sessionStartEvent);
|
|
1654
|
+
await this.extendResourcesFromExtensions(this._sessionStartEvent.reason === "reload" ? "reload" : "startup");
|
|
1624
1655
|
}
|
|
1625
1656
|
async extendResourcesFromExtensions(reason) {
|
|
1626
|
-
if (!this._extensionRunner
|
|
1657
|
+
if (!this._extensionRunner.hasHandlers("resources_discover")) {
|
|
1627
1658
|
return;
|
|
1628
1659
|
}
|
|
1629
1660
|
const { skillPaths, promptPaths, themePaths } = await this._extensionRunner.emitResourcesDiscover(this._cwd, reason);
|
|
@@ -1663,7 +1694,7 @@ export class AgentSession {
|
|
|
1663
1694
|
return `extension:${name}`;
|
|
1664
1695
|
}
|
|
1665
1696
|
_applyExtensionBindings(runner) {
|
|
1666
|
-
runner.setUIContext(this._extensionUIContext);
|
|
1697
|
+
runner.setUIContext(this._extensionUIContext, this._extensionMode);
|
|
1667
1698
|
runner.bindCommandContext(this._extensionCommandContextActions);
|
|
1668
1699
|
this._extensionErrorUnsubscriber?.();
|
|
1669
1700
|
this._extensionErrorUnsubscriber = this._extensionErrorListener
|
|
@@ -1726,7 +1757,7 @@ export class AgentSession {
|
|
|
1726
1757
|
this.sessionManager.appendCustomEntry(customType, data);
|
|
1727
1758
|
},
|
|
1728
1759
|
setSessionName: (name) => {
|
|
1729
|
-
this.
|
|
1760
|
+
this.setSessionName(name);
|
|
1730
1761
|
},
|
|
1731
1762
|
getSessionName: () => {
|
|
1732
1763
|
return this.sessionManager.getSessionName();
|
|
@@ -1750,8 +1781,15 @@ export class AgentSession {
|
|
|
1750
1781
|
}, {
|
|
1751
1782
|
getModel: () => this.model,
|
|
1752
1783
|
isIdle: () => !this.isStreaming,
|
|
1784
|
+
isProjectTrusted: () => this.settingsManager.isProjectTrusted(),
|
|
1753
1785
|
getSignal: () => this.agent.signal,
|
|
1754
|
-
abort: () =>
|
|
1786
|
+
abort: () => {
|
|
1787
|
+
if (this._extensionAbortHandler) {
|
|
1788
|
+
this._extensionAbortHandler();
|
|
1789
|
+
return;
|
|
1790
|
+
}
|
|
1791
|
+
void this.abort();
|
|
1792
|
+
},
|
|
1755
1793
|
hasPendingMessages: () => this.pendingMessageCount > 0,
|
|
1756
1794
|
shutdown: () => {
|
|
1757
1795
|
this._extensionShutdownHandler?.();
|
|
@@ -1770,6 +1808,7 @@ export class AgentSession {
|
|
|
1770
1808
|
})();
|
|
1771
1809
|
},
|
|
1772
1810
|
getSystemPrompt: () => this.systemPrompt,
|
|
1811
|
+
getSystemPromptOptions: () => this._baseSystemPromptOptions,
|
|
1773
1812
|
}, {
|
|
1774
1813
|
registerProvider: (name, config) => {
|
|
1775
1814
|
this._modelRegistry.registerProvider(name, config);
|
|
@@ -1784,15 +1823,20 @@ export class AgentSession {
|
|
|
1784
1823
|
_refreshToolRegistry(options) {
|
|
1785
1824
|
const previousRegistryNames = new Set(this._toolRegistry.keys());
|
|
1786
1825
|
const previousActiveToolNames = this.getActiveToolNames();
|
|
1787
|
-
const
|
|
1826
|
+
const allowedToolNames = this._allowedToolNames;
|
|
1827
|
+
const excludedToolNames = this._excludedToolNames;
|
|
1828
|
+
const isAllowedTool = (name) => (!allowedToolNames || allowedToolNames.has(name)) && !excludedToolNames?.has(name);
|
|
1829
|
+
const registeredTools = this._extensionRunner.getAllRegisteredTools();
|
|
1788
1830
|
const allCustomTools = [
|
|
1789
1831
|
...registeredTools,
|
|
1790
1832
|
...this._customTools.map((definition) => ({
|
|
1791
1833
|
definition,
|
|
1792
1834
|
sourceInfo: createSyntheticSourceInfo(`<sdk:${definition.name}>`, { source: "sdk" }),
|
|
1793
1835
|
})),
|
|
1794
|
-
];
|
|
1795
|
-
const definitionRegistry = new Map(Array.from(this._baseToolDefinitions.entries())
|
|
1836
|
+
].filter((tool) => isAllowedTool(tool.definition.name));
|
|
1837
|
+
const definitionRegistry = new Map(Array.from(this._baseToolDefinitions.entries())
|
|
1838
|
+
.filter(([name]) => isAllowedTool(name))
|
|
1839
|
+
.map(([name, definition]) => [
|
|
1796
1840
|
name,
|
|
1797
1841
|
{
|
|
1798
1842
|
definition,
|
|
@@ -1818,21 +1862,28 @@ export class AgentSession {
|
|
|
1818
1862
|
return guidelines.length > 0 ? [definition.name, guidelines] : undefined;
|
|
1819
1863
|
})
|
|
1820
1864
|
.filter((entry) => entry !== undefined));
|
|
1821
|
-
const
|
|
1822
|
-
|
|
1823
|
-
|
|
1824
|
-
|
|
1825
|
-
definition
|
|
1826
|
-
|
|
1827
|
-
|
|
1865
|
+
const runner = this._extensionRunner;
|
|
1866
|
+
const wrappedExtensionTools = wrapRegisteredTools(allCustomTools, runner);
|
|
1867
|
+
const wrappedBuiltInTools = wrapRegisteredTools(Array.from(this._baseToolDefinitions.values())
|
|
1868
|
+
.filter((definition) => isAllowedTool(definition.name))
|
|
1869
|
+
.map((definition) => ({
|
|
1870
|
+
definition,
|
|
1871
|
+
sourceInfo: createSyntheticSourceInfo(`<builtin:${definition.name}>`, { source: "builtin" }),
|
|
1872
|
+
})), runner);
|
|
1873
|
+
const toolRegistry = new Map(wrappedBuiltInTools.map((tool) => [tool.name, tool]));
|
|
1828
1874
|
for (const tool of wrappedExtensionTools) {
|
|
1829
1875
|
toolRegistry.set(tool.name, tool);
|
|
1830
1876
|
}
|
|
1831
1877
|
this._toolRegistry = toolRegistry;
|
|
1832
|
-
const nextActiveToolNames = options?.activeToolNames
|
|
1833
|
-
|
|
1834
|
-
|
|
1835
|
-
|
|
1878
|
+
const nextActiveToolNames = (options?.activeToolNames ? [...options.activeToolNames] : [...previousActiveToolNames]).filter((name) => isAllowedTool(name));
|
|
1879
|
+
if (allowedToolNames) {
|
|
1880
|
+
for (const toolName of this._toolRegistry.keys()) {
|
|
1881
|
+
if (allowedToolNames.has(toolName)) {
|
|
1882
|
+
nextActiveToolNames.push(toolName);
|
|
1883
|
+
}
|
|
1884
|
+
}
|
|
1885
|
+
}
|
|
1886
|
+
else if (options?.includeAllExtensionTools) {
|
|
1836
1887
|
for (const tool of wrappedExtensionTools) {
|
|
1837
1888
|
nextActiveToolNames.push(tool.name);
|
|
1838
1889
|
}
|
|
@@ -1849,6 +1900,7 @@ export class AgentSession {
|
|
|
1849
1900
|
_buildRuntime(options) {
|
|
1850
1901
|
const autoResizeImages = this.settingsManager.getImageAutoResize();
|
|
1851
1902
|
const shellCommandPrefix = this.settingsManager.getShellCommandPrefix();
|
|
1903
|
+
const shellPath = this.settingsManager.getShellPath();
|
|
1852
1904
|
const baseToolDefinitions = this._baseToolsOverride
|
|
1853
1905
|
? Object.fromEntries(Object.entries(this._baseToolsOverride).map(([name, tool]) => [
|
|
1854
1906
|
name,
|
|
@@ -1856,7 +1908,7 @@ export class AgentSession {
|
|
|
1856
1908
|
]))
|
|
1857
1909
|
: createAllToolDefinitions(this._cwd, {
|
|
1858
1910
|
read: { autoResizeImages },
|
|
1859
|
-
bash: { commandPrefix: shellCommandPrefix },
|
|
1911
|
+
bash: { commandPrefix: shellCommandPrefix, shellPath },
|
|
1860
1912
|
});
|
|
1861
1913
|
this._baseToolDefinitions = new Map(Object.entries(baseToolDefinitions).map(([name, tool]) => [name, tool]));
|
|
1862
1914
|
const extensionsResult = this._resourceLoader.getExtensions();
|
|
@@ -1865,19 +1917,12 @@ export class AgentSession {
|
|
|
1865
1917
|
extensionsResult.runtime.flagValues.set(name, value);
|
|
1866
1918
|
}
|
|
1867
1919
|
}
|
|
1868
|
-
|
|
1869
|
-
const hasCustomTools = this._customTools.length > 0;
|
|
1870
|
-
this._extensionRunner =
|
|
1871
|
-
hasExtensions || hasCustomTools
|
|
1872
|
-
? new ExtensionRunner(extensionsResult.extensions, extensionsResult.runtime, this._cwd, this.sessionManager, this._modelRegistry)
|
|
1873
|
-
: undefined;
|
|
1920
|
+
this._extensionRunner = new ExtensionRunner(extensionsResult.extensions, extensionsResult.runtime, this._cwd, this.sessionManager, this._modelRegistry);
|
|
1874
1921
|
if (this._extensionRunnerRef) {
|
|
1875
1922
|
this._extensionRunnerRef.current = this._extensionRunner;
|
|
1876
1923
|
}
|
|
1877
|
-
|
|
1878
|
-
|
|
1879
|
-
this._applyExtensionBindings(this._extensionRunner);
|
|
1880
|
-
}
|
|
1924
|
+
this._bindExtensionCore(this._extensionRunner);
|
|
1925
|
+
this._applyExtensionBindings(this._extensionRunner);
|
|
1881
1926
|
const defaultActiveToolNames = this._baseToolsOverride
|
|
1882
1927
|
? Object.keys(this._baseToolsOverride)
|
|
1883
1928
|
: ["read", "bash", "edit", "write"];
|
|
@@ -1888,9 +1933,10 @@ export class AgentSession {
|
|
|
1888
1933
|
});
|
|
1889
1934
|
}
|
|
1890
1935
|
async reload() {
|
|
1891
|
-
const previousFlagValues = this._extensionRunner
|
|
1892
|
-
await this._extensionRunner
|
|
1936
|
+
const previousFlagValues = this._extensionRunner.getFlagValues();
|
|
1937
|
+
await emitSessionShutdownEvent(this._extensionRunner, { type: "session_shutdown", reason: "reload" });
|
|
1893
1938
|
await this.settingsManager.reload();
|
|
1939
|
+
this.syncQueueModesFromSettings();
|
|
1894
1940
|
resetApiProviders();
|
|
1895
1941
|
await this._resourceLoader.reload();
|
|
1896
1942
|
this._buildRuntime({
|
|
@@ -1902,7 +1948,7 @@ export class AgentSession {
|
|
|
1902
1948
|
this._extensionCommandContextActions ||
|
|
1903
1949
|
this._extensionShutdownHandler ||
|
|
1904
1950
|
this._extensionErrorListener;
|
|
1905
|
-
if (
|
|
1951
|
+
if (hasBindings) {
|
|
1906
1952
|
await this._extensionRunner.emit({ type: "session_start", reason: "reload" });
|
|
1907
1953
|
await this.extendResourcesFromExtensions("reload");
|
|
1908
1954
|
}
|
|
@@ -1910,6 +1956,9 @@ export class AgentSession {
|
|
|
1910
1956
|
// =========================================================================
|
|
1911
1957
|
// Auto-Retry
|
|
1912
1958
|
// =========================================================================
|
|
1959
|
+
_isNonRetryableProviderLimitError(errorMessage) {
|
|
1960
|
+
return /GoUsageLimitError|FreeUsageLimitError|Monthly usage limit reached|available balance|insufficient_quota|out of budget|quota exceeded|billing/i.test(errorMessage);
|
|
1961
|
+
}
|
|
1913
1962
|
/**
|
|
1914
1963
|
* Check if an error is retryable (overloaded, rate limit, server errors).
|
|
1915
1964
|
* Context overflow errors are NOT retryable (handled by compaction instead).
|
|
@@ -1922,37 +1971,24 @@ export class AgentSession {
|
|
|
1922
1971
|
if (isContextOverflow(message, contextWindow))
|
|
1923
1972
|
return false;
|
|
1924
1973
|
const err = message.errorMessage;
|
|
1925
|
-
|
|
1926
|
-
|
|
1974
|
+
if (this._isNonRetryableProviderLimitError(err))
|
|
1975
|
+
return false;
|
|
1976
|
+
// Match: overloaded_error, provider returned error, rate limit, 429, 500, 502, 503, 504, service unavailable, network/connection errors (including connection lost), WebSocket transport closes/errors, fetch failed, premature stream endings, HTTP/2 closed before response, terminated, retry delay exceeded
|
|
1977
|
+
return /overloaded|provider.?returned.?error|rate.?limit|too many requests|429|500|502|503|504|service.?unavailable|server.?error|internal.?error|network.?error|connection.?error|connection.?refused|connection.?lost|websocket.?closed|websocket.?error|other side closed|fetch failed|upstream.?connect|reset before headers|socket hang up|ended without|stream ended before message_stop|http2 request did not get a response|timed? out|timeout|terminated|retry delay/i.test(err);
|
|
1927
1978
|
}
|
|
1928
1979
|
/**
|
|
1929
|
-
*
|
|
1930
|
-
* @returns true if
|
|
1980
|
+
* Prepare a retryable error for continuation with exponential backoff.
|
|
1981
|
+
* @returns true if the caller should continue the agent, false otherwise
|
|
1931
1982
|
*/
|
|
1932
|
-
async
|
|
1983
|
+
async _prepareRetry(message) {
|
|
1933
1984
|
const settings = this.settingsManager.getRetrySettings();
|
|
1934
1985
|
if (!settings.enabled) {
|
|
1935
|
-
this._resolveRetry();
|
|
1936
1986
|
return false;
|
|
1937
1987
|
}
|
|
1938
|
-
// Retry promise is created synchronously in _handleAgentEvent for agent_end.
|
|
1939
|
-
// Keep a defensive fallback here in case a future refactor bypasses that path.
|
|
1940
|
-
if (!this._retryPromise) {
|
|
1941
|
-
this._retryPromise = new Promise((resolve) => {
|
|
1942
|
-
this._retryResolve = resolve;
|
|
1943
|
-
});
|
|
1944
|
-
}
|
|
1945
1988
|
this._retryAttempt++;
|
|
1946
1989
|
if (this._retryAttempt > settings.maxRetries) {
|
|
1947
|
-
//
|
|
1948
|
-
this.
|
|
1949
|
-
type: "auto_retry_end",
|
|
1950
|
-
success: false,
|
|
1951
|
-
attempt: this._retryAttempt - 1,
|
|
1952
|
-
finalError: message.errorMessage,
|
|
1953
|
-
});
|
|
1954
|
-
this._retryAttempt = 0;
|
|
1955
|
-
this._resolveRetry(); // Resolve so waitForRetry() completes
|
|
1990
|
+
// Preserve the completed attempt count so post-run handling can emit the final failure.
|
|
1991
|
+
this._retryAttempt--;
|
|
1956
1992
|
return false;
|
|
1957
1993
|
}
|
|
1958
1994
|
const delayMs = settings.baseDelayMs * 2 ** (this._retryAttempt - 1);
|
|
@@ -1977,23 +2013,17 @@ export class AgentSession {
|
|
|
1977
2013
|
// Aborted during sleep - emit end event so UI can clean up
|
|
1978
2014
|
const attempt = this._retryAttempt;
|
|
1979
2015
|
this._retryAttempt = 0;
|
|
1980
|
-
this._retryAbortController = undefined;
|
|
1981
2016
|
this._emit({
|
|
1982
2017
|
type: "auto_retry_end",
|
|
1983
2018
|
success: false,
|
|
1984
2019
|
attempt,
|
|
1985
2020
|
finalError: "Retry cancelled",
|
|
1986
2021
|
});
|
|
1987
|
-
this._resolveRetry();
|
|
1988
2022
|
return false;
|
|
1989
2023
|
}
|
|
1990
|
-
|
|
1991
|
-
|
|
1992
|
-
|
|
1993
|
-
this.agent.continue().catch(() => {
|
|
1994
|
-
// Retry failed - will be caught by next agent_end
|
|
1995
|
-
});
|
|
1996
|
-
}, 0);
|
|
2024
|
+
finally {
|
|
2025
|
+
this._retryAbortController = undefined;
|
|
2026
|
+
}
|
|
1997
2027
|
return true;
|
|
1998
2028
|
}
|
|
1999
2029
|
/**
|
|
@@ -2001,23 +2031,10 @@ export class AgentSession {
|
|
|
2001
2031
|
*/
|
|
2002
2032
|
abortRetry() {
|
|
2003
2033
|
this._retryAbortController?.abort();
|
|
2004
|
-
// Note: _retryAttempt is reset in the catch block of _autoRetry
|
|
2005
|
-
this._resolveRetry();
|
|
2006
|
-
}
|
|
2007
|
-
/**
|
|
2008
|
-
* Wait for any in-progress retry to complete.
|
|
2009
|
-
* Returns immediately if no retry is in progress.
|
|
2010
|
-
*/
|
|
2011
|
-
async waitForRetry() {
|
|
2012
|
-
if (!this._retryPromise) {
|
|
2013
|
-
return;
|
|
2014
|
-
}
|
|
2015
|
-
await this._retryPromise;
|
|
2016
|
-
await this.agent.waitForIdle();
|
|
2017
2034
|
}
|
|
2018
2035
|
/** Whether auto-retry is currently in progress */
|
|
2019
2036
|
get isRetrying() {
|
|
2020
|
-
return this.
|
|
2037
|
+
return this._retryAbortController !== undefined;
|
|
2021
2038
|
}
|
|
2022
2039
|
/** Whether auto-retry is enabled */
|
|
2023
2040
|
get autoRetryEnabled() {
|
|
@@ -2044,9 +2061,10 @@ export class AgentSession {
|
|
|
2044
2061
|
this._bashAbortController = new AbortController();
|
|
2045
2062
|
// Apply command prefix if configured (e.g., "shopt -s expand_aliases" for alias support)
|
|
2046
2063
|
const prefix = this.settingsManager.getShellCommandPrefix();
|
|
2064
|
+
const shellPath = this.settingsManager.getShellPath();
|
|
2047
2065
|
const resolvedCommand = prefix ? `${prefix}\n${command}` : command;
|
|
2048
2066
|
try {
|
|
2049
|
-
const result = await executeBashWithOperations(resolvedCommand, this.sessionManager.getCwd(), options?.operations ?? createLocalBashOperations(), {
|
|
2067
|
+
const result = await executeBashWithOperations(resolvedCommand, this.sessionManager.getCwd(), options?.operations ?? createLocalBashOperations({ shellPath }), {
|
|
2050
2068
|
onChunk,
|
|
2051
2069
|
signal: this._bashAbortController.signal,
|
|
2052
2070
|
});
|
|
@@ -2122,6 +2140,7 @@ export class AgentSession {
|
|
|
2122
2140
|
*/
|
|
2123
2141
|
setSessionName(name) {
|
|
2124
2142
|
this.sessionManager.appendSessionInfo(name);
|
|
2143
|
+
this._emit({ type: "session_info_changed", name: this.sessionManager.getSessionName() });
|
|
2125
2144
|
}
|
|
2126
2145
|
// =========================================================================
|
|
2127
2146
|
// Tree Navigation
|
|
@@ -2169,118 +2188,118 @@ export class AgentSession {
|
|
|
2169
2188
|
};
|
|
2170
2189
|
// Set up abort controller for summarization
|
|
2171
2190
|
this._branchSummaryAbortController = new AbortController();
|
|
2172
|
-
|
|
2173
|
-
|
|
2174
|
-
|
|
2175
|
-
|
|
2176
|
-
|
|
2177
|
-
|
|
2178
|
-
|
|
2179
|
-
|
|
2180
|
-
|
|
2181
|
-
|
|
2182
|
-
|
|
2183
|
-
|
|
2184
|
-
|
|
2185
|
-
|
|
2186
|
-
|
|
2187
|
-
|
|
2188
|
-
|
|
2189
|
-
|
|
2190
|
-
customInstructions
|
|
2191
|
-
|
|
2192
|
-
|
|
2193
|
-
replaceInstructions
|
|
2194
|
-
|
|
2195
|
-
|
|
2196
|
-
label
|
|
2197
|
-
|
|
2198
|
-
|
|
2199
|
-
// Run default summarizer if needed
|
|
2200
|
-
let summaryText;
|
|
2201
|
-
let summaryDetails;
|
|
2202
|
-
if (options.summarize && entriesToSummarize.length > 0 && !extensionSummary) {
|
|
2203
|
-
const model = this.model;
|
|
2204
|
-
const { apiKey, headers } = await this._getRequiredRequestAuth(model);
|
|
2205
|
-
const branchSummarySettings = this.settingsManager.getBranchSummarySettings();
|
|
2206
|
-
const result = await generateBranchSummary(entriesToSummarize, {
|
|
2207
|
-
model,
|
|
2208
|
-
apiKey,
|
|
2209
|
-
headers,
|
|
2210
|
-
signal: this._branchSummaryAbortController.signal,
|
|
2211
|
-
customInstructions,
|
|
2212
|
-
replaceInstructions,
|
|
2213
|
-
reserveTokens: branchSummarySettings.reserveTokens,
|
|
2214
|
-
});
|
|
2215
|
-
this._branchSummaryAbortController = undefined;
|
|
2216
|
-
if (result.aborted) {
|
|
2217
|
-
return { cancelled: true, aborted: true };
|
|
2191
|
+
try {
|
|
2192
|
+
let extensionSummary;
|
|
2193
|
+
let fromExtension = false;
|
|
2194
|
+
// Emit session_before_tree event
|
|
2195
|
+
if (this._extensionRunner.hasHandlers("session_before_tree")) {
|
|
2196
|
+
const result = (await this._extensionRunner.emit({
|
|
2197
|
+
type: "session_before_tree",
|
|
2198
|
+
preparation,
|
|
2199
|
+
signal: this._branchSummaryAbortController.signal,
|
|
2200
|
+
}));
|
|
2201
|
+
if (result?.cancel) {
|
|
2202
|
+
return { cancelled: true };
|
|
2203
|
+
}
|
|
2204
|
+
if (result?.summary && options.summarize) {
|
|
2205
|
+
extensionSummary = result.summary;
|
|
2206
|
+
fromExtension = true;
|
|
2207
|
+
}
|
|
2208
|
+
// Allow extensions to override instructions and label
|
|
2209
|
+
if (result?.customInstructions !== undefined) {
|
|
2210
|
+
customInstructions = result.customInstructions;
|
|
2211
|
+
}
|
|
2212
|
+
if (result?.replaceInstructions !== undefined) {
|
|
2213
|
+
replaceInstructions = result.replaceInstructions;
|
|
2214
|
+
}
|
|
2215
|
+
if (result?.label !== undefined) {
|
|
2216
|
+
label = result.label;
|
|
2217
|
+
}
|
|
2218
2218
|
}
|
|
2219
|
-
if
|
|
2220
|
-
|
|
2219
|
+
// Run default summarizer if needed
|
|
2220
|
+
let summaryText;
|
|
2221
|
+
let summaryDetails;
|
|
2222
|
+
if (options.summarize && entriesToSummarize.length > 0 && !extensionSummary) {
|
|
2223
|
+
const model = this.model;
|
|
2224
|
+
const { apiKey, headers } = await this._getRequiredRequestAuth(model);
|
|
2225
|
+
const branchSummarySettings = this.settingsManager.getBranchSummarySettings();
|
|
2226
|
+
const result = await generateBranchSummary(entriesToSummarize, {
|
|
2227
|
+
model,
|
|
2228
|
+
apiKey,
|
|
2229
|
+
headers,
|
|
2230
|
+
signal: this._branchSummaryAbortController.signal,
|
|
2231
|
+
customInstructions,
|
|
2232
|
+
replaceInstructions,
|
|
2233
|
+
reserveTokens: branchSummarySettings.reserveTokens,
|
|
2234
|
+
streamFn: this.agent.streamFn,
|
|
2235
|
+
});
|
|
2236
|
+
if (result.aborted) {
|
|
2237
|
+
return { cancelled: true, aborted: true };
|
|
2238
|
+
}
|
|
2239
|
+
if (result.error) {
|
|
2240
|
+
throw new Error(result.error);
|
|
2241
|
+
}
|
|
2242
|
+
summaryText = result.summary;
|
|
2243
|
+
summaryDetails = {
|
|
2244
|
+
readFiles: result.readFiles || [],
|
|
2245
|
+
modifiedFiles: result.modifiedFiles || [],
|
|
2246
|
+
};
|
|
2247
|
+
}
|
|
2248
|
+
else if (extensionSummary) {
|
|
2249
|
+
summaryText = extensionSummary.summary;
|
|
2250
|
+
summaryDetails = extensionSummary.details;
|
|
2251
|
+
}
|
|
2252
|
+
// Determine the new leaf position based on target type
|
|
2253
|
+
let newLeafId;
|
|
2254
|
+
let editorText;
|
|
2255
|
+
if (targetEntry.type === "message" && targetEntry.message.role === "user") {
|
|
2256
|
+
// User message: leaf = parent (null if root), text goes to editor
|
|
2257
|
+
newLeafId = targetEntry.parentId;
|
|
2258
|
+
editorText = this._extractUserMessageText(targetEntry.message.content);
|
|
2259
|
+
}
|
|
2260
|
+
else if (targetEntry.type === "custom_message") {
|
|
2261
|
+
// Custom message: leaf = parent (null if root), text goes to editor
|
|
2262
|
+
newLeafId = targetEntry.parentId;
|
|
2263
|
+
editorText =
|
|
2264
|
+
typeof targetEntry.content === "string"
|
|
2265
|
+
? targetEntry.content
|
|
2266
|
+
: targetEntry.content
|
|
2267
|
+
.filter((c) => c.type === "text")
|
|
2268
|
+
.map((c) => c.text)
|
|
2269
|
+
.join("");
|
|
2221
2270
|
}
|
|
2222
|
-
|
|
2223
|
-
|
|
2224
|
-
|
|
2225
|
-
|
|
2226
|
-
|
|
2227
|
-
|
|
2228
|
-
|
|
2229
|
-
summaryText
|
|
2230
|
-
|
|
2231
|
-
|
|
2232
|
-
|
|
2233
|
-
|
|
2234
|
-
|
|
2235
|
-
|
|
2236
|
-
|
|
2237
|
-
newLeafId = targetEntry.parentId;
|
|
2238
|
-
editorText = this._extractUserMessageText(targetEntry.message.content);
|
|
2239
|
-
}
|
|
2240
|
-
else if (targetEntry.type === "custom_message") {
|
|
2241
|
-
// Custom message: leaf = parent (null if root), text goes to editor
|
|
2242
|
-
newLeafId = targetEntry.parentId;
|
|
2243
|
-
editorText =
|
|
2244
|
-
typeof targetEntry.content === "string"
|
|
2245
|
-
? targetEntry.content
|
|
2246
|
-
: targetEntry.content
|
|
2247
|
-
.filter((c) => c.type === "text")
|
|
2248
|
-
.map((c) => c.text)
|
|
2249
|
-
.join("");
|
|
2250
|
-
}
|
|
2251
|
-
else {
|
|
2252
|
-
// Non-user message: leaf = selected node
|
|
2253
|
-
newLeafId = targetId;
|
|
2254
|
-
}
|
|
2255
|
-
// Switch leaf (with or without summary)
|
|
2256
|
-
// Summary is attached at the navigation target position (newLeafId), not the old branch
|
|
2257
|
-
let summaryEntry;
|
|
2258
|
-
if (summaryText) {
|
|
2259
|
-
// Create summary at target position (can be null for root)
|
|
2260
|
-
const summaryId = this.sessionManager.branchWithSummary(newLeafId, summaryText, summaryDetails, fromExtension);
|
|
2261
|
-
summaryEntry = this.sessionManager.getEntry(summaryId);
|
|
2262
|
-
// Attach label to the summary entry
|
|
2263
|
-
if (label) {
|
|
2264
|
-
this.sessionManager.appendLabelChange(summaryId, label);
|
|
2271
|
+
else {
|
|
2272
|
+
// Non-user message: leaf = selected node
|
|
2273
|
+
newLeafId = targetId;
|
|
2274
|
+
}
|
|
2275
|
+
// Switch leaf (with or without summary)
|
|
2276
|
+
// Summary is attached at the navigation target position (newLeafId), not the old branch
|
|
2277
|
+
let summaryEntry;
|
|
2278
|
+
if (summaryText) {
|
|
2279
|
+
// Create summary at target position (can be null for root)
|
|
2280
|
+
const summaryId = this.sessionManager.branchWithSummary(newLeafId, summaryText, summaryDetails, fromExtension);
|
|
2281
|
+
summaryEntry = this.sessionManager.getEntry(summaryId);
|
|
2282
|
+
// Attach label to the summary entry
|
|
2283
|
+
if (label) {
|
|
2284
|
+
this.sessionManager.appendLabelChange(summaryId, label);
|
|
2285
|
+
}
|
|
2265
2286
|
}
|
|
2266
|
-
|
|
2267
|
-
|
|
2268
|
-
|
|
2269
|
-
|
|
2270
|
-
|
|
2271
|
-
|
|
2272
|
-
|
|
2273
|
-
|
|
2274
|
-
|
|
2275
|
-
|
|
2276
|
-
|
|
2277
|
-
|
|
2278
|
-
|
|
2279
|
-
|
|
2280
|
-
|
|
2281
|
-
|
|
2282
|
-
// Emit session_tree event
|
|
2283
|
-
if (this._extensionRunner) {
|
|
2287
|
+
else if (newLeafId === null) {
|
|
2288
|
+
// No summary, navigating to root - reset leaf
|
|
2289
|
+
this.sessionManager.resetLeaf();
|
|
2290
|
+
}
|
|
2291
|
+
else {
|
|
2292
|
+
// No summary, navigating to non-root
|
|
2293
|
+
this.sessionManager.branch(newLeafId);
|
|
2294
|
+
}
|
|
2295
|
+
// Attach label to target entry when not summarizing (no summary entry to label)
|
|
2296
|
+
if (label && !summaryText) {
|
|
2297
|
+
this.sessionManager.appendLabelChange(targetId, label);
|
|
2298
|
+
}
|
|
2299
|
+
// Update agent state
|
|
2300
|
+
const sessionContext = this.sessionManager.buildSessionContext();
|
|
2301
|
+
this.agent.state.messages = sessionContext.messages;
|
|
2302
|
+
// Emit session_tree event
|
|
2284
2303
|
await this._extensionRunner.emit({
|
|
2285
2304
|
type: "session_tree",
|
|
2286
2305
|
newLeafId: this.sessionManager.getLeafId(),
|
|
@@ -2288,10 +2307,12 @@ export class AgentSession {
|
|
|
2288
2307
|
summaryEntry,
|
|
2289
2308
|
fromExtension: summaryText ? fromExtension : undefined,
|
|
2290
2309
|
});
|
|
2310
|
+
// Emit to custom tools
|
|
2311
|
+
return { editorText, cancelled: false, summaryEntry };
|
|
2312
|
+
}
|
|
2313
|
+
finally {
|
|
2314
|
+
this._branchSummaryAbortController = undefined;
|
|
2291
2315
|
}
|
|
2292
|
-
// Emit to custom tools
|
|
2293
|
-
this._branchSummaryAbortController = undefined;
|
|
2294
|
-
return { editorText, cancelled: false, summaryEntry };
|
|
2295
2316
|
}
|
|
2296
2317
|
/**
|
|
2297
2318
|
* Get all user messages from session for fork selector.
|
|
@@ -2433,7 +2454,7 @@ export class AgentSession {
|
|
|
2433
2454
|
* @returns The resolved output file path.
|
|
2434
2455
|
*/
|
|
2435
2456
|
exportToJsonl(outputPath) {
|
|
2436
|
-
const filePath =
|
|
2457
|
+
const filePath = resolvePath(outputPath ?? `session-${new Date().toISOString().replace(/[:.]/g, "-")}.jsonl`, process.cwd());
|
|
2437
2458
|
const dir = dirname(filePath);
|
|
2438
2459
|
if (!existsSync(dir)) {
|
|
2439
2460
|
mkdirSync(dir, { recursive: true });
|
|
@@ -2491,11 +2512,17 @@ export class AgentSession {
|
|
|
2491
2512
|
// =========================================================================
|
|
2492
2513
|
// Extension System
|
|
2493
2514
|
// =========================================================================
|
|
2515
|
+
createReplacedSessionContext() {
|
|
2516
|
+
const context = Object.defineProperties({}, Object.getOwnPropertyDescriptors(this._extensionRunner.createCommandContext()));
|
|
2517
|
+
context.sendMessage = (message, options) => this.sendCustomMessage(message, options);
|
|
2518
|
+
context.sendUserMessage = (content, options) => this.sendUserMessage(content, options);
|
|
2519
|
+
return context;
|
|
2520
|
+
}
|
|
2494
2521
|
/**
|
|
2495
2522
|
* Check if extensions have handlers for a specific event type.
|
|
2496
2523
|
*/
|
|
2497
2524
|
hasExtensionHandlers(eventType) {
|
|
2498
|
-
return this._extensionRunner
|
|
2525
|
+
return this._extensionRunner.hasHandlers(eventType);
|
|
2499
2526
|
}
|
|
2500
2527
|
/**
|
|
2501
2528
|
* Get the extension runner (for setting UI context and error handlers).
|