@relay-harness/coding-agent 0.0.0-stage → 1.0.2
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 +6111 -0
- package/README.md +80 -2
- package/dist/bun/cli.d.ts +5 -0
- package/dist/bun/cli.d.ts.map +1 -0
- package/dist/bun/cli.js +5 -0
- package/dist/bun/cli.js.map +1 -0
- package/dist/bun/restore-sandbox-env.d.ts +17 -0
- package/dist/bun/restore-sandbox-env.d.ts.map +1 -0
- package/dist/bun/restore-sandbox-env.js +36 -0
- package/dist/bun/restore-sandbox-env.js.map +1 -0
- package/dist/bun/runtime-setup.d.ts +2 -0
- package/dist/bun/runtime-setup.d.ts.map +1 -0
- package/dist/bun/runtime-setup.js +12 -0
- package/dist/bun/runtime-setup.js.map +1 -0
- package/dist/bun/sandbox-env-setup.d.ts +2 -0
- package/dist/bun/sandbox-env-setup.d.ts.map +1 -0
- package/dist/bun/sandbox-env-setup.js +4 -0
- package/dist/bun/sandbox-env-setup.js.map +1 -0
- package/dist/bundle/chunks/anthropic-messages-TXWUAW5N.js +6 -0
- package/dist/bundle/chunks/anthropic.js +75 -0
- package/dist/bundle/chunks/azure-openai-responses-EJG46ESA.js +2 -0
- package/dist/bundle/chunks/bedrock-converse-stream.js +83 -0
- package/dist/bundle/chunks/chunk-3QND5D7W.js +82 -0
- package/dist/bundle/chunks/chunk-3XNI2SB6.js +15 -0
- package/dist/bundle/chunks/chunk-4L3WN2XY.js +2 -0
- package/dist/bundle/chunks/chunk-6CYCI3EJ.js +12 -0
- package/dist/bundle/chunks/chunk-7ZC4UXSL.js +2 -0
- package/dist/bundle/chunks/chunk-A3JYRWB6.js +2 -0
- package/dist/bundle/chunks/chunk-C47CLQZK.js +2 -0
- package/dist/bundle/chunks/chunk-DRQDKNXA.js +2 -0
- package/dist/bundle/chunks/chunk-EQ2HXQGJ.js +2 -0
- package/dist/bundle/chunks/chunk-F5ZABL6Z.js +20 -0
- package/dist/bundle/chunks/chunk-H3QXYIF7.js +31 -0
- package/dist/bundle/chunks/chunk-H6S6DQTM.js +2 -0
- package/dist/bundle/chunks/chunk-ISNO4JTR.js +127 -0
- package/dist/bundle/chunks/chunk-KJUDFE6Y.js +11 -0
- package/dist/bundle/chunks/chunk-L2ZPNLYD.js +2 -0
- package/dist/bundle/chunks/chunk-LD2P6SFZ.js +2 -0
- package/dist/bundle/chunks/chunk-MP5FU7MG.js +20 -0
- package/dist/bundle/chunks/chunk-O7R77OAK.js +2 -0
- package/dist/bundle/chunks/chunk-PGXDEOVV.js +2 -0
- package/dist/bundle/chunks/chunk-PJACZCIR.js +2 -0
- package/dist/bundle/chunks/chunk-PRRNXB7S.js +2 -0
- package/dist/bundle/chunks/chunk-PTRF7IZB.js +2 -0
- package/dist/bundle/chunks/chunk-RZ4KG4BP.js +44 -0
- package/dist/bundle/chunks/chunk-S3GGRYIO.js +6 -0
- package/dist/bundle/chunks/chunk-TEPMHNKQ.js +2 -0
- package/dist/bundle/chunks/chunk-TRDNDS6A.js +4 -0
- package/dist/bundle/chunks/chunk-USJZMAIR.js +2 -0
- package/dist/bundle/chunks/chunk-UTB4DTYQ.js +2 -0
- package/dist/bundle/chunks/chunk-WMTXXI7H.js +4 -0
- package/dist/bundle/chunks/chunk-XDAWU2J5.js +132 -0
- package/dist/bundle/chunks/chunk-XSLAMYCK.js +1297 -0
- package/dist/bundle/chunks/chunk-Z2G7KLPH.js +11 -0
- package/dist/bundle/chunks/cli-K4CNHWOI.js +51 -0
- package/dist/bundle/chunks/cloudflare-workers-ai-system-one-NM3JRRWQ.js +2 -0
- package/dist/bundle/chunks/codemode-worker.js +374 -0
- package/dist/bundle/chunks/easter-egg-3d-TGRCIHA4.js +2 -0
- package/dist/bundle/chunks/execute-6E5DA2QI.js +388 -0
- package/dist/bundle/chunks/github-copilot.js +2 -0
- package/dist/bundle/chunks/google-generative-ai-HYUNEOCJ.js +2 -0
- package/dist/bundle/chunks/google-vertex-J7MDGTNM.js +2 -0
- package/dist/bundle/chunks/https-proxy-agent-2VXB7436.js +13 -0
- package/dist/bundle/chunks/image-resize-worker.js +2 -0
- package/dist/bundle/chunks/jiti-loader-C3NU2SDH.js +21 -0
- package/dist/bundle/chunks/jiti-static-loader-E6ANQD5T.js +2 -0
- package/dist/bundle/chunks/kimi-coding.js +2 -0
- package/dist/bundle/chunks/lib-TEDK3E5I.js +9 -0
- package/dist/bundle/chunks/llama-cpp-classify-XT44PI3C.js +22 -0
- package/dist/bundle/chunks/meta.js +2 -0
- package/dist/bundle/chunks/mistral-conversations-UD2HHXKZ.js +5 -0
- package/dist/bundle/chunks/multipart-parser-SQ6GDJL7.js +3 -0
- package/dist/bundle/chunks/node-N5BSDOA5.js +16 -0
- package/dist/bundle/chunks/node-TWVVAGPO.js +2 -0
- package/dist/bundle/chunks/openai-chatgpt.js +75 -0
- package/dist/bundle/chunks/openai-codex-responses-EMHXEJR4.js +10 -0
- package/dist/bundle/chunks/openai-codex.js +75 -0
- package/dist/bundle/chunks/openai-completions-LPKRZYMC.js +7 -0
- package/dist/bundle/chunks/openai-responses-TOOBRHUV.js +3 -0
- package/dist/bundle/chunks/openrouter-images-ZVXWCSIM.js +2 -0
- package/dist/bundle/chunks/openrouter.js +75 -0
- package/dist/bundle/chunks/relay-messages-QRFJXG5X.js +8 -0
- package/dist/bundle/chunks/runtime-O5HLCH3V.js +2 -0
- package/dist/bundle/chunks/src-UK77SYZE.js +4 -0
- package/dist/bundle/chunks/typesafe-system-one-PRR5K6CI.js +2 -0
- package/dist/bundle/chunks/virtual-modules-FNVEVB65.js +2 -0
- package/dist/bundle/chunks/xai.js +2 -0
- package/dist/bundle/cli-runtime.js +3 -0
- package/dist/bundle/cli.js +5 -0
- package/dist/bundle/index.js +2 -0
- package/dist/bundle/rpc-entry.js +3 -0
- package/dist/cli/args.d.ts +61 -0
- package/dist/cli/args.d.ts.map +1 -0
- package/dist/cli/args.js +454 -0
- package/dist/cli/args.js.map +1 -0
- package/dist/cli/auth-check.d.ts +19 -0
- package/dist/cli/auth-check.d.ts.map +1 -0
- package/dist/cli/auth-check.js +50 -0
- package/dist/cli/auth-check.js.map +1 -0
- package/dist/cli/auth-command.d.ts +24 -0
- package/dist/cli/auth-command.d.ts.map +1 -0
- package/dist/cli/auth-command.js +103 -0
- package/dist/cli/auth-command.js.map +1 -0
- package/dist/cli/config-selector.d.ts +16 -0
- package/dist/cli/config-selector.d.ts.map +1 -0
- package/dist/cli/config-selector.js +32 -0
- package/dist/cli/config-selector.js.map +1 -0
- package/dist/cli/credential-print.d.ts +13 -0
- package/dist/cli/credential-print.d.ts.map +1 -0
- package/dist/cli/credential-print.js +76 -0
- package/dist/cli/credential-print.js.map +1 -0
- package/dist/cli/file-processor.d.ts +15 -0
- package/dist/cli/file-processor.d.ts.map +1 -0
- package/dist/cli/file-processor.js +71 -0
- package/dist/cli/file-processor.js.map +1 -0
- package/dist/cli/initial-message.d.ts +18 -0
- package/dist/cli/initial-message.d.ts.map +1 -0
- package/dist/cli/initial-message.js +22 -0
- package/dist/cli/initial-message.js.map +1 -0
- package/dist/cli/list-models.d.ts +9 -0
- package/dist/cli/list-models.d.ts.map +1 -0
- package/dist/cli/list-models.js +98 -0
- package/dist/cli/list-models.js.map +1 -0
- 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 +10 -0
- package/dist/cli/session-picker.d.ts.map +1 -0
- package/dist/cli/session-picker.js +36 -0
- package/dist/cli/session-picker.js.map +1 -0
- package/dist/cli/setup.d.ts +2 -0
- package/dist/cli/setup.d.ts.map +1 -0
- package/dist/cli/setup.js +12 -0
- package/dist/cli/setup.js.map +1 -0
- package/dist/cli/startup-ui.d.ts +20 -0
- package/dist/cli/startup-ui.d.ts.map +1 -0
- package/dist/cli/startup-ui.js +193 -0
- package/dist/cli/startup-ui.js.map +1 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +6 -0
- package/dist/cli.js.map +1 -0
- package/dist/config.d.ts +108 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +264 -0
- package/dist/config.js.map +1 -0
- package/dist/core/agent-session-runtime.d.ts +119 -0
- package/dist/core/agent-session-runtime.d.ts.map +1 -0
- package/dist/core/agent-session-runtime.js +317 -0
- package/dist/core/agent-session-runtime.js.map +1 -0
- package/dist/core/agent-session-services.d.ts +86 -0
- package/dist/core/agent-session-services.d.ts.map +1 -0
- package/dist/core/agent-session-services.js +147 -0
- package/dist/core/agent-session-services.js.map +1 -0
- package/dist/core/agent-session.d.ts +891 -0
- package/dist/core/agent-session.d.ts.map +1 -0
- package/dist/core/agent-session.js +3553 -0
- package/dist/core/agent-session.js.map +1 -0
- 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 +72 -0
- package/dist/core/auth-storage.d.ts.map +1 -0
- package/dist/core/auth-storage.js +426 -0
- package/dist/core/auth-storage.js.map +1 -0
- package/dist/core/bash-executor.d.ts +32 -0
- package/dist/core/bash-executor.d.ts.map +1 -0
- package/dist/core/bash-executor.js +106 -0
- package/dist/core/bash-executor.js.map +1 -0
- package/dist/core/bug-report.d.ts +176 -0
- package/dist/core/bug-report.d.ts.map +1 -0
- package/dist/core/bug-report.js +292 -0
- package/dist/core/bug-report.js.map +1 -0
- package/dist/core/cache-stats.d.ts +49 -0
- package/dist/core/cache-stats.d.ts.map +1 -0
- package/dist/core/cache-stats.js +112 -0
- package/dist/core/cache-stats.js.map +1 -0
- package/dist/core/cache-warmer.d.ts +103 -0
- package/dist/core/cache-warmer.d.ts.map +1 -0
- package/dist/core/cache-warmer.js +356 -0
- package/dist/core/cache-warmer.js.map +1 -0
- package/dist/core/compaction/branch-summarization.d.ts +98 -0
- package/dist/core/compaction/branch-summarization.d.ts.map +1 -0
- package/dist/core/compaction/branch-summarization.js +251 -0
- package/dist/core/compaction/branch-summarization.js.map +1 -0
- package/dist/core/compaction/compaction.d.ts +145 -0
- package/dist/core/compaction/compaction.d.ts.map +1 -0
- package/dist/core/compaction/compaction.js +744 -0
- package/dist/core/compaction/compaction.js.map +1 -0
- package/dist/core/compaction/index.d.ts +7 -0
- package/dist/core/compaction/index.d.ts.map +1 -0
- package/dist/core/compaction/index.js +7 -0
- package/dist/core/compaction/index.js.map +1 -0
- package/dist/core/compaction/utils.d.ts +39 -0
- package/dist/core/compaction/utils.d.ts.map +1 -0
- package/dist/core/compaction/utils.js +149 -0
- package/dist/core/compaction/utils.js.map +1 -0
- package/dist/core/crash-log.d.ts +27 -0
- package/dist/core/crash-log.d.ts.map +1 -0
- package/dist/core/crash-log.js +140 -0
- package/dist/core/crash-log.js.map +1 -0
- package/dist/core/defaults.d.ts +4 -0
- package/dist/core/defaults.d.ts.map +1 -0
- package/dist/core/defaults.js +11 -0
- package/dist/core/defaults.js.map +1 -0
- package/dist/core/diagnostics.d.ts +15 -0
- package/dist/core/diagnostics.d.ts.map +1 -0
- package/dist/core/diagnostics.js +2 -0
- package/dist/core/diagnostics.js.map +1 -0
- package/dist/core/event-bus.d.ts +9 -0
- package/dist/core/event-bus.d.ts.map +1 -0
- package/dist/core/event-bus.js +25 -0
- package/dist/core/event-bus.js.map +1 -0
- package/dist/core/exec.d.ts +29 -0
- package/dist/core/exec.d.ts.map +1 -0
- package/dist/core/exec.js +75 -0
- package/dist/core/exec.js.map +1 -0
- 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 +22 -0
- package/dist/core/export-html/ansi-to-html.d.ts.map +1 -0
- package/dist/core/export-html/ansi-to-html.js +249 -0
- package/dist/core/export-html/ansi-to-html.js.map +1 -0
- package/dist/core/export-html/index.d.ts +37 -0
- package/dist/core/export-html/index.d.ts.map +1 -0
- package/dist/core/export-html/index.js +226 -0
- package/dist/core/export-html/index.js.map +1 -0
- package/dist/core/export-html/template.css +1076 -0
- package/dist/core/export-html/template.html +55 -0
- package/dist/core/export-html/template.js +1918 -0
- package/dist/core/export-html/tool-renderer.d.ts +34 -0
- package/dist/core/export-html/tool-renderer.d.ts.map +1 -0
- package/dist/core/export-html/tool-renderer.js +108 -0
- package/dist/core/export-html/tool-renderer.js.map +1 -0
- package/dist/core/export-html/vendor/highlight.min.js +1213 -0
- package/dist/core/export-html/vendor/marked.min.js +78 -0
- package/dist/core/extensions/index.d.ts +12 -0
- package/dist/core/extensions/index.d.ts.map +1 -0
- package/dist/core/extensions/index.js +9 -0
- package/dist/core/extensions/index.js.map +1 -0
- package/dist/core/extensions/jiti-loader.d.ts +2 -0
- package/dist/core/extensions/jiti-loader.d.ts.map +1 -0
- package/dist/core/extensions/jiti-loader.js +4 -0
- package/dist/core/extensions/jiti-loader.js.map +1 -0
- package/dist/core/extensions/jiti-static-loader.d.ts +2 -0
- package/dist/core/extensions/jiti-static-loader.d.ts.map +1 -0
- package/dist/core/extensions/jiti-static-loader.js +4 -0
- package/dist/core/extensions/jiti-static-loader.js.map +1 -0
- package/dist/core/extensions/loader.d.ts +23 -0
- package/dist/core/extensions/loader.d.ts.map +1 -0
- package/dist/core/extensions/loader.js +701 -0
- package/dist/core/extensions/loader.js.map +1 -0
- package/dist/core/extensions/runner.d.ts +213 -0
- package/dist/core/extensions/runner.d.ts.map +1 -0
- package/dist/core/extensions/runner.js +1239 -0
- package/dist/core/extensions/runner.js.map +1 -0
- package/dist/core/extensions/types.d.ts +1720 -0
- package/dist/core/extensions/types.d.ts.map +1 -0
- package/dist/core/extensions/types.js +48 -0
- package/dist/core/extensions/types.js.map +1 -0
- package/dist/core/extensions/virtual-modules.d.ts +3 -0
- package/dist/core/extensions/virtual-modules.d.ts.map +1 -0
- package/dist/core/extensions/virtual-modules.js +38 -0
- package/dist/core/extensions/virtual-modules.js.map +1 -0
- package/dist/core/extensions/wrapper.d.ts +20 -0
- package/dist/core/extensions/wrapper.d.ts.map +1 -0
- package/dist/core/extensions/wrapper.js +22 -0
- package/dist/core/extensions/wrapper.js.map +1 -0
- package/dist/core/footer-data-provider.d.ts +64 -0
- package/dist/core/footer-data-provider.d.ts.map +1 -0
- package/dist/core/footer-data-provider.js +338 -0
- package/dist/core/footer-data-provider.js.map +1 -0
- package/dist/core/harness-core.d.ts +50 -0
- package/dist/core/harness-core.d.ts.map +1 -0
- package/dist/core/harness-core.js +240 -0
- package/dist/core/harness-core.js.map +1 -0
- package/dist/core/http-dispatcher.d.ts +22 -0
- package/dist/core/http-dispatcher.d.ts.map +1 -0
- package/dist/core/http-dispatcher.js +98 -0
- package/dist/core/http-dispatcher.js.map +1 -0
- package/dist/core/index.d.ts +14 -0
- package/dist/core/index.d.ts.map +1 -0
- package/dist/core/index.js +13 -0
- package/dist/core/index.js.map +1 -0
- package/dist/core/keybindings.d.ts +428 -0
- package/dist/core/keybindings.d.ts.map +1 -0
- package/dist/core/keybindings.js +321 -0
- package/dist/core/keybindings.js.map +1 -0
- package/dist/core/mcp-servers.d.ts +125 -0
- package/dist/core/mcp-servers.d.ts.map +1 -0
- package/dist/core/mcp-servers.js +198 -0
- package/dist/core/mcp-servers.js.map +1 -0
- package/dist/core/messages.d.ts +77 -0
- package/dist/core/messages.d.ts.map +1 -0
- package/dist/core/messages.js +124 -0
- package/dist/core/messages.js.map +1 -0
- package/dist/core/model-config.d.ts +759 -0
- package/dist/core/model-config.d.ts.map +1 -0
- package/dist/core/model-config.js +293 -0
- package/dist/core/model-config.js.map +1 -0
- package/dist/core/model-registry.d.ts +63 -0
- package/dist/core/model-registry.d.ts.map +1 -0
- package/dist/core/model-registry.js +144 -0
- package/dist/core/model-registry.js.map +1 -0
- package/dist/core/model-resolver.d.ts +124 -0
- package/dist/core/model-resolver.d.ts.map +1 -0
- package/dist/core/model-resolver.js +589 -0
- package/dist/core/model-resolver.js.map +1 -0
- package/dist/core/model-runtime.d.ts +142 -0
- package/dist/core/model-runtime.d.ts.map +1 -0
- package/dist/core/model-runtime.js +732 -0
- package/dist/core/model-runtime.js.map +1 -0
- package/dist/core/models-store.d.ts +22 -0
- package/dist/core/models-store.d.ts.map +1 -0
- package/dist/core/models-store.js +115 -0
- package/dist/core/models-store.js.map +1 -0
- package/dist/core/nested-tool-calls.d.ts +102 -0
- package/dist/core/nested-tool-calls.d.ts.map +1 -0
- package/dist/core/nested-tool-calls.js +178 -0
- package/dist/core/nested-tool-calls.js.map +1 -0
- package/dist/core/output-guard.d.ts +7 -0
- package/dist/core/output-guard.d.ts.map +1 -0
- package/dist/core/output-guard.js +89 -0
- package/dist/core/output-guard.js.map +1 -0
- package/dist/core/package-manager.d.ts +217 -0
- package/dist/core/package-manager.d.ts.map +1 -0
- package/dist/core/package-manager.js +2224 -0
- package/dist/core/package-manager.js.map +1 -0
- package/dist/core/project-trust.d.ts +15 -0
- package/dist/core/project-trust.d.ts.map +1 -0
- package/dist/core/project-trust.js +59 -0
- package/dist/core/project-trust.js.map +1 -0
- package/dist/core/prompt-templates.d.ts +59 -0
- package/dist/core/prompt-templates.d.ts.map +1 -0
- package/dist/core/prompt-templates.js +262 -0
- package/dist/core/prompt-templates.js.map +1 -0
- 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-composer.d.ts +80 -0
- package/dist/core/provider-composer.d.ts.map +1 -0
- package/dist/core/provider-composer.js +484 -0
- package/dist/core/provider-composer.js.map +1 -0
- package/dist/core/relay-manifest.d.ts +8 -0
- package/dist/core/relay-manifest.d.ts.map +1 -0
- package/dist/core/relay-manifest.js +26 -0
- package/dist/core/relay-manifest.js.map +1 -0
- package/dist/core/resolve-config-value.d.ts +30 -0
- package/dist/core/resolve-config-value.d.ts.map +1 -0
- package/dist/core/resolve-config-value.js +247 -0
- package/dist/core/resolve-config-value.js.map +1 -0
- package/dist/core/resource-loader.d.ts +227 -0
- package/dist/core/resource-loader.d.ts.map +1 -0
- package/dist/core/resource-loader.js +1005 -0
- package/dist/core/resource-loader.js.map +1 -0
- package/dist/core/runtime-credentials.d.ts +15 -0
- package/dist/core/runtime-credentials.d.ts.map +1 -0
- package/dist/core/runtime-credentials.js +39 -0
- package/dist/core/runtime-credentials.js.map +1 -0
- package/dist/core/sdk.d.ts +108 -0
- package/dist/core/sdk.d.ts.map +1 -0
- package/dist/core/sdk.js +315 -0
- package/dist/core/sdk.js.map +1 -0
- package/dist/core/session-cwd.d.ts +19 -0
- package/dist/core/session-cwd.d.ts.map +1 -0
- package/dist/core/session-cwd.js +38 -0
- package/dist/core/session-cwd.js.map +1 -0
- package/dist/core/session-export.d.ts +8 -0
- package/dist/core/session-export.d.ts.map +1 -0
- package/dist/core/session-export.js +33 -0
- package/dist/core/session-export.js.map +1 -0
- package/dist/core/session-manager.d.ts +416 -0
- package/dist/core/session-manager.d.ts.map +1 -0
- package/dist/core/session-manager.js +1523 -0
- package/dist/core/session-manager.js.map +1 -0
- package/dist/core/settings-diagnostics.d.ts +9 -0
- package/dist/core/settings-diagnostics.d.ts.map +1 -0
- package/dist/core/settings-diagnostics.js +21 -0
- package/dist/core/settings-diagnostics.js.map +1 -0
- package/dist/core/settings-manager.d.ts +421 -0
- package/dist/core/settings-manager.d.ts.map +1 -0
- package/dist/core/settings-manager.js +1120 -0
- package/dist/core/settings-manager.js.map +1 -0
- package/dist/core/skills.d.ts +60 -0
- package/dist/core/skills.d.ts.map +1 -0
- package/dist/core/skills.js +408 -0
- package/dist/core/skills.js.map +1 -0
- package/dist/core/slash-commands.d.ts +15 -0
- package/dist/core/slash-commands.d.ts.map +1 -0
- package/dist/core/slash-commands.js +29 -0
- package/dist/core/slash-commands.js.map +1 -0
- package/dist/core/source-info.d.ts +26 -0
- package/dist/core/source-info.d.ts.map +1 -0
- package/dist/core/source-info.js +35 -0
- package/dist/core/source-info.js.map +1 -0
- package/dist/core/system-prompt.d.ts +71 -0
- package/dist/core/system-prompt.d.ts.map +1 -0
- package/dist/core/system-prompt.js +147 -0
- package/dist/core/system-prompt.js.map +1 -0
- package/dist/core/telemetry.d.ts +3 -0
- package/dist/core/telemetry.d.ts.map +1 -0
- package/dist/core/telemetry.js +9 -0
- package/dist/core/telemetry.js.map +1 -0
- package/dist/core/timings.d.ts +10 -0
- package/dist/core/timings.d.ts.map +1 -0
- package/dist/core/timings.js +41 -0
- package/dist/core/timings.js.map +1 -0
- package/dist/core/tools/bash.d.ts +100 -0
- package/dist/core/tools/bash.d.ts.map +1 -0
- package/dist/core/tools/bash.js +333 -0
- package/dist/core/tools/bash.js.map +1 -0
- package/dist/core/tools/edit-diff.d.ts +101 -0
- package/dist/core/tools/edit-diff.d.ts.map +1 -0
- package/dist/core/tools/edit-diff.js +421 -0
- package/dist/core/tools/edit-diff.js.map +1 -0
- package/dist/core/tools/edit.d.ts +44 -0
- package/dist/core/tools/edit.d.ts.map +1 -0
- package/dist/core/tools/edit.js +147 -0
- package/dist/core/tools/edit.js.map +1 -0
- package/dist/core/tools/file-mutation-queue.d.ts +6 -0
- package/dist/core/tools/file-mutation-queue.d.ts.map +1 -0
- package/dist/core/tools/file-mutation-queue.js +52 -0
- package/dist/core/tools/file-mutation-queue.js.map +1 -0
- package/dist/core/tools/find.d.ts +42 -0
- package/dist/core/tools/find.d.ts.map +1 -0
- package/dist/core/tools/find.js +251 -0
- package/dist/core/tools/find.js.map +1 -0
- package/dist/core/tools/grep.d.ts +41 -0
- package/dist/core/tools/grep.d.ts.map +1 -0
- package/dist/core/tools/grep.js +252 -0
- package/dist/core/tools/grep.js.map +1 -0
- package/dist/core/tools/index.d.ts +43 -0
- package/dist/core/tools/index.d.ts.map +1 -0
- package/dist/core/tools/index.js +129 -0
- package/dist/core/tools/index.js.map +1 -0
- package/dist/core/tools/ls.d.ts +41 -0
- package/dist/core/tools/ls.d.ts.map +1 -0
- package/dist/core/tools/ls.js +126 -0
- package/dist/core/tools/ls.js.map +1 -0
- package/dist/core/tools/output-accumulator.d.ts +63 -0
- package/dist/core/tools/output-accumulator.d.ts.map +1 -0
- package/dist/core/tools/output-accumulator.js +214 -0
- package/dist/core/tools/output-accumulator.js.map +1 -0
- package/dist/core/tools/path-utils.d.ts +10 -0
- package/dist/core/tools/path-utils.d.ts.map +1 -0
- package/dist/core/tools/path-utils.js +99 -0
- package/dist/core/tools/path-utils.js.map +1 -0
- package/dist/core/tools/powershell.d.ts +16 -0
- package/dist/core/tools/powershell.d.ts.map +1 -0
- package/dist/core/tools/powershell.js +39 -0
- package/dist/core/tools/powershell.js.map +1 -0
- package/dist/core/tools/read.d.ts +42 -0
- package/dist/core/tools/read.d.ts.map +1 -0
- package/dist/core/tools/read.js +169 -0
- package/dist/core/tools/read.js.map +1 -0
- package/dist/core/tools/render-utils.d.ts +30 -0
- package/dist/core/tools/render-utils.d.ts.map +1 -0
- package/dist/core/tools/render-utils.js +91 -0
- package/dist/core/tools/render-utils.js.map +1 -0
- package/dist/core/tools/renderers/bash.d.ts +12 -0
- package/dist/core/tools/renderers/bash.d.ts.map +1 -0
- package/dist/core/tools/renderers/bash.js +117 -0
- package/dist/core/tools/renderers/bash.js.map +1 -0
- package/dist/core/tools/renderers/edit.d.ts +23 -0
- package/dist/core/tools/renderers/edit.d.ts.map +1 -0
- package/dist/core/tools/renderers/edit.js +167 -0
- package/dist/core/tools/renderers/edit.js.map +1 -0
- package/dist/core/tools/renderers/find.d.ts +10 -0
- package/dist/core/tools/renderers/find.d.ts.map +1 -0
- package/dist/core/tools/renderers/find.js +64 -0
- package/dist/core/tools/renderers/find.js.map +1 -0
- package/dist/core/tools/renderers/grep.d.ts +10 -0
- package/dist/core/tools/renderers/grep.d.ts.map +1 -0
- package/dist/core/tools/renderers/grep.js +69 -0
- package/dist/core/tools/renderers/grep.js.map +1 -0
- package/dist/core/tools/renderers/index.d.ts +28 -0
- package/dist/core/tools/renderers/index.d.ts.map +1 -0
- package/dist/core/tools/renderers/index.js +47 -0
- package/dist/core/tools/renderers/index.js.map +1 -0
- package/dist/core/tools/renderers/ls.d.ts +10 -0
- package/dist/core/tools/renderers/ls.d.ts.map +1 -0
- package/dist/core/tools/renderers/ls.js +58 -0
- package/dist/core/tools/renderers/ls.js.map +1 -0
- package/dist/core/tools/renderers/read.d.ts +11 -0
- package/dist/core/tools/renderers/read.d.ts.map +1 -0
- package/dist/core/tools/renderers/read.js +130 -0
- package/dist/core/tools/renderers/read.js.map +1 -0
- package/dist/core/tools/renderers/write.d.ts +10 -0
- package/dist/core/tools/renderers/write.d.ts.map +1 -0
- package/dist/core/tools/renderers/write.js +153 -0
- package/dist/core/tools/renderers/write.js.map +1 -0
- package/dist/core/tools/tool-definition-wrapper.d.ts +16 -0
- package/dist/core/tools/tool-definition-wrapper.d.ts.map +1 -0
- package/dist/core/tools/tool-definition-wrapper.js +38 -0
- package/dist/core/tools/tool-definition-wrapper.js.map +1 -0
- package/dist/core/tools/truncate.d.ts +84 -0
- package/dist/core/tools/truncate.d.ts.map +1 -0
- package/dist/core/tools/truncate.js +244 -0
- package/dist/core/tools/truncate.js.map +1 -0
- package/dist/core/tools/write.d.ts +30 -0
- package/dist/core/tools/write.d.ts.map +1 -0
- package/dist/core/tools/write.js +61 -0
- package/dist/core/tools/write.js.map +1 -0
- package/dist/core/trust-manager.d.ts +36 -0
- package/dist/core/trust-manager.d.ts.map +1 -0
- package/dist/core/trust-manager.js +204 -0
- package/dist/core/trust-manager.js.map +1 -0
- package/dist/core/usage-totals.d.ts +21 -0
- package/dist/core/usage-totals.d.ts.map +1 -0
- package/dist/core/usage-totals.js +79 -0
- package/dist/core/usage-totals.js.map +1 -0
- package/dist/core/virtual-models.d.ts +117 -0
- package/dist/core/virtual-models.d.ts.map +1 -0
- package/dist/core/virtual-models.js +124 -0
- package/dist/core/virtual-models.js.map +1 -0
- package/dist/core/workspace-probe.d.ts +8 -0
- package/dist/core/workspace-probe.d.ts.map +1 -0
- package/dist/core/workspace-probe.js +65 -0
- package/dist/core/workspace-probe.js.map +1 -0
- package/dist/extensions/codemode/execute.d.ts +16 -0
- package/dist/extensions/codemode/execute.d.ts.map +1 -0
- package/dist/extensions/codemode/execute.js +577 -0
- package/dist/extensions/codemode/execute.js.map +1 -0
- package/dist/extensions/codemode/execute.lazy.d.ts +3 -0
- package/dist/extensions/codemode/execute.lazy.d.ts.map +1 -0
- package/dist/extensions/codemode/execute.lazy.js +3 -0
- package/dist/extensions/codemode/execute.lazy.js.map +1 -0
- package/dist/extensions/codemode/index.d.ts +21 -0
- package/dist/extensions/codemode/index.d.ts.map +1 -0
- package/dist/extensions/codemode/index.js +31 -0
- package/dist/extensions/codemode/index.js.map +1 -0
- package/dist/extensions/codemode/renderer.d.ts +12 -0
- package/dist/extensions/codemode/renderer.d.ts.map +1 -0
- package/dist/extensions/codemode/renderer.js +137 -0
- package/dist/extensions/codemode/renderer.js.map +1 -0
- package/dist/extensions/codemode/tool.d.ts +123 -0
- package/dist/extensions/codemode/tool.d.ts.map +1 -0
- package/dist/extensions/codemode/tool.js +268 -0
- package/dist/extensions/codemode/tool.js.map +1 -0
- package/dist/extensions/codemode/worker.d.ts +7 -0
- package/dist/extensions/codemode/worker.d.ts.map +1 -0
- package/dist/extensions/codemode/worker.js +7 -0
- package/dist/extensions/codemode/worker.js.map +1 -0
- package/dist/extensions/index.d.ts +3 -0
- package/dist/extensions/index.d.ts.map +1 -0
- package/dist/extensions/index.js +19 -0
- package/dist/extensions/index.js.map +1 -0
- package/dist/extensions/intake/docx.d.ts +42 -0
- package/dist/extensions/intake/docx.d.ts.map +1 -0
- package/dist/extensions/intake/docx.js +148 -0
- package/dist/extensions/intake/docx.js.map +1 -0
- package/dist/extensions/intake/index.d.ts +17 -0
- package/dist/extensions/intake/index.d.ts.map +1 -0
- package/dist/extensions/intake/index.js +88 -0
- package/dist/extensions/intake/index.js.map +1 -0
- package/dist/extensions/intake/prompt.d.ts +6 -0
- package/dist/extensions/intake/prompt.d.ts.map +1 -0
- package/dist/extensions/intake/prompt.js +41 -0
- package/dist/extensions/intake/prompt.js.map +1 -0
- package/dist/extensions/intake/questionnaire.d.ts +84 -0
- package/dist/extensions/intake/questionnaire.d.ts.map +1 -0
- package/dist/extensions/intake/questionnaire.js +472 -0
- package/dist/extensions/intake/questionnaire.js.map +1 -0
- package/dist/extensions/laya/assessment.d.ts +34 -0
- package/dist/extensions/laya/assessment.d.ts.map +1 -0
- package/dist/extensions/laya/assessment.js +171 -0
- package/dist/extensions/laya/assessment.js.map +1 -0
- package/dist/extensions/laya/index.d.ts +34 -0
- package/dist/extensions/laya/index.d.ts.map +1 -0
- package/dist/extensions/laya/index.js +516 -0
- package/dist/extensions/laya/index.js.map +1 -0
- package/dist/extensions/laya/model-manifest.d.ts +7 -0
- package/dist/extensions/laya/model-manifest.d.ts.map +1 -0
- package/dist/extensions/laya/model-manifest.js +48 -0
- package/dist/extensions/laya/model-manifest.js.map +1 -0
- package/dist/extensions/laya/policy.d.ts +130 -0
- package/dist/extensions/laya/policy.d.ts.map +1 -0
- package/dist/extensions/laya/policy.js +222 -0
- package/dist/extensions/laya/policy.js.map +1 -0
- package/dist/extensions/laya/questions.d.ts +60 -0
- package/dist/extensions/laya/questions.d.ts.map +1 -0
- package/dist/extensions/laya/questions.js +189 -0
- package/dist/extensions/laya/questions.js.map +1 -0
- package/dist/extensions/laya/routers.d.ts +17 -0
- package/dist/extensions/laya/routers.d.ts.map +1 -0
- package/dist/extensions/laya/routers.js +119 -0
- package/dist/extensions/laya/routers.js.map +1 -0
- package/dist/extensions/laya/runtime.d.ts +68 -0
- package/dist/extensions/laya/runtime.d.ts.map +1 -0
- package/dist/extensions/laya/runtime.js +179 -0
- package/dist/extensions/laya/runtime.js.map +1 -0
- package/dist/extensions/laya/seed.d.ts +39 -0
- package/dist/extensions/laya/seed.d.ts.map +1 -0
- package/dist/extensions/laya/seed.js +358 -0
- package/dist/extensions/laya/seed.js.map +1 -0
- package/dist/extensions/laya/server.d.ts +26 -0
- package/dist/extensions/laya/server.d.ts.map +1 -0
- package/dist/extensions/laya/server.js +117 -0
- package/dist/extensions/laya/server.js.map +1 -0
- package/dist/extensions/laya/telemetry.d.ts +94 -0
- package/dist/extensions/laya/telemetry.d.ts.map +1 -0
- package/dist/extensions/laya/telemetry.js +107 -0
- package/dist/extensions/laya/telemetry.js.map +1 -0
- package/dist/extensions/llama/client.d.ts +69 -0
- package/dist/extensions/llama/client.d.ts.map +1 -0
- package/dist/extensions/llama/client.js +313 -0
- package/dist/extensions/llama/client.js.map +1 -0
- package/dist/extensions/llama/huggingface.d.ts +23 -0
- package/dist/extensions/llama/huggingface.d.ts.map +1 -0
- package/dist/extensions/llama/huggingface.js +141 -0
- package/dist/extensions/llama/huggingface.js.map +1 -0
- package/dist/extensions/llama/index.d.ts +3 -0
- package/dist/extensions/llama/index.d.ts.map +1 -0
- package/dist/extensions/llama/index.js +219 -0
- package/dist/extensions/llama/index.js.map +1 -0
- package/dist/extensions/llama/provider.d.ts +12 -0
- package/dist/extensions/llama/provider.d.ts.map +1 -0
- package/dist/extensions/llama/provider.js +213 -0
- package/dist/extensions/llama/provider.js.map +1 -0
- package/dist/extensions/llama/ui.d.ts +42 -0
- package/dist/extensions/llama/ui.d.ts.map +1 -0
- package/dist/extensions/llama/ui.js +416 -0
- package/dist/extensions/llama/ui.js.map +1 -0
- package/dist/extensions/mcp/cli.d.ts +21 -0
- package/dist/extensions/mcp/cli.d.ts.map +1 -0
- package/dist/extensions/mcp/cli.js +503 -0
- package/dist/extensions/mcp/cli.js.map +1 -0
- package/dist/extensions/mcp/cli.lazy.d.ts +3 -0
- package/dist/extensions/mcp/cli.lazy.d.ts.map +1 -0
- package/dist/extensions/mcp/cli.lazy.js +3 -0
- package/dist/extensions/mcp/cli.lazy.js.map +1 -0
- package/dist/extensions/mcp/config.d.ts +84 -0
- package/dist/extensions/mcp/config.d.ts.map +1 -0
- package/dist/extensions/mcp/config.js +194 -0
- package/dist/extensions/mcp/config.js.map +1 -0
- package/dist/extensions/mcp/index.d.ts +79 -0
- package/dist/extensions/mcp/index.d.ts.map +1 -0
- package/dist/extensions/mcp/index.js +1101 -0
- package/dist/extensions/mcp/index.js.map +1 -0
- package/dist/extensions/mcp/log.d.ts +16 -0
- package/dist/extensions/mcp/log.d.ts.map +1 -0
- package/dist/extensions/mcp/log.js +66 -0
- package/dist/extensions/mcp/log.js.map +1 -0
- package/dist/extensions/mcp/oauth.d.ts +98 -0
- package/dist/extensions/mcp/oauth.d.ts.map +1 -0
- package/dist/extensions/mcp/oauth.js +366 -0
- package/dist/extensions/mcp/oauth.js.map +1 -0
- package/dist/extensions/mcp/resources.d.ts +43 -0
- package/dist/extensions/mcp/resources.d.ts.map +1 -0
- package/dist/extensions/mcp/resources.js +262 -0
- package/dist/extensions/mcp/resources.js.map +1 -0
- package/dist/extensions/mcp/runtime.d.ts +98 -0
- package/dist/extensions/mcp/runtime.d.ts.map +1 -0
- package/dist/extensions/mcp/runtime.js +395 -0
- package/dist/extensions/mcp/runtime.js.map +1 -0
- package/dist/extensions/mcp/runtime.lazy.d.ts +3 -0
- package/dist/extensions/mcp/runtime.lazy.d.ts.map +1 -0
- package/dist/extensions/mcp/runtime.lazy.js +3 -0
- package/dist/extensions/mcp/runtime.lazy.js.map +1 -0
- package/dist/extensions/mcp/tools.d.ts +86 -0
- package/dist/extensions/mcp/tools.d.ts.map +1 -0
- package/dist/extensions/mcp/tools.js +252 -0
- package/dist/extensions/mcp/tools.js.map +1 -0
- package/dist/extensions/mcp/ui.d.ts +60 -0
- package/dist/extensions/mcp/ui.d.ts.map +1 -0
- package/dist/extensions/mcp/ui.js +178 -0
- package/dist/extensions/mcp/ui.js.map +1 -0
- package/dist/extensions/tool-search/index.d.ts +12 -0
- package/dist/extensions/tool-search/index.d.ts.map +1 -0
- package/dist/extensions/tool-search/index.js +15 -0
- package/dist/extensions/tool-search/index.js.map +1 -0
- package/dist/extensions/tool-search/tool.d.ts +73 -0
- package/dist/extensions/tool-search/tool.d.ts.map +1 -0
- package/dist/extensions/tool-search/tool.js +189 -0
- package/dist/extensions/tool-search/tool.js.map +1 -0
- package/dist/index.d.ts +44 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +53 -0
- package/dist/index.js.map +1 -0
- package/dist/main.d.ts +16 -0
- package/dist/main.d.ts.map +1 -0
- package/dist/main.js +820 -0
- package/dist/main.js.map +1 -0
- package/dist/migrations.d.ts +33 -0
- package/dist/migrations.d.ts.map +1 -0
- package/dist/migrations.js +282 -0
- package/dist/migrations.js.map +1 -0
- package/dist/modes/index.d.ts +10 -0
- package/dist/modes/index.d.ts.map +1 -0
- package/dist/modes/index.js +8 -0
- package/dist/modes/index.js.map +1 -0
- package/dist/modes/interactive/assets/clankolas.png +0 -0
- package/dist/modes/interactive/bug-report.d.ts +16 -0
- package/dist/modes/interactive/bug-report.d.ts.map +1 -0
- package/dist/modes/interactive/bug-report.js +171 -0
- package/dist/modes/interactive/bug-report.js.map +1 -0
- package/dist/modes/interactive/chat-viewport.d.ts +20 -0
- package/dist/modes/interactive/chat-viewport.d.ts.map +1 -0
- package/dist/modes/interactive/chat-viewport.js +28 -0
- package/dist/modes/interactive/chat-viewport.js.map +1 -0
- package/dist/modes/interactive/components/armin.d.ts +37 -0
- package/dist/modes/interactive/components/armin.d.ts.map +1 -0
- package/dist/modes/interactive/components/armin.js +335 -0
- package/dist/modes/interactive/components/armin.js.map +1 -0
- package/dist/modes/interactive/components/assistant-message.d.ts +26 -0
- package/dist/modes/interactive/components/assistant-message.d.ts.map +1 -0
- package/dist/modes/interactive/components/assistant-message.js +158 -0
- package/dist/modes/interactive/components/assistant-message.js.map +1 -0
- package/dist/modes/interactive/components/auth-url.d.ts +14 -0
- package/dist/modes/interactive/components/auth-url.d.ts.map +1 -0
- package/dist/modes/interactive/components/auth-url.js +37 -0
- package/dist/modes/interactive/components/auth-url.js.map +1 -0
- package/dist/modes/interactive/components/bash-execution.d.ts +34 -0
- package/dist/modes/interactive/components/bash-execution.d.ts.map +1 -0
- package/dist/modes/interactive/components/bash-execution.js +175 -0
- package/dist/modes/interactive/components/bash-execution.js.map +1 -0
- package/dist/modes/interactive/components/bordered-loader.d.ts +16 -0
- package/dist/modes/interactive/components/bordered-loader.d.ts.map +1 -0
- package/dist/modes/interactive/components/bordered-loader.js +54 -0
- package/dist/modes/interactive/components/bordered-loader.js.map +1 -0
- package/dist/modes/interactive/components/branch-summary-message.d.ts +16 -0
- package/dist/modes/interactive/components/branch-summary-message.d.ts.map +1 -0
- package/dist/modes/interactive/components/branch-summary-message.js +51 -0
- package/dist/modes/interactive/components/branch-summary-message.js.map +1 -0
- package/dist/modes/interactive/components/compaction-summary-message.d.ts +16 -0
- package/dist/modes/interactive/components/compaction-summary-message.d.ts.map +1 -0
- package/dist/modes/interactive/components/compaction-summary-message.js +52 -0
- package/dist/modes/interactive/components/compaction-summary-message.js.map +1 -0
- package/dist/modes/interactive/components/config-selector.d.ts +102 -0
- package/dist/modes/interactive/components/config-selector.d.ts.map +1 -0
- package/dist/modes/interactive/components/config-selector.js +771 -0
- package/dist/modes/interactive/components/config-selector.js.map +1 -0
- package/dist/modes/interactive/components/countdown-timer.d.ts +14 -0
- package/dist/modes/interactive/components/countdown-timer.d.ts.map +1 -0
- package/dist/modes/interactive/components/countdown-timer.js +33 -0
- package/dist/modes/interactive/components/countdown-timer.js.map +1 -0
- package/dist/modes/interactive/components/custom-editor.d.ts +30 -0
- package/dist/modes/interactive/components/custom-editor.d.ts.map +1 -0
- package/dist/modes/interactive/components/custom-editor.js +115 -0
- package/dist/modes/interactive/components/custom-editor.js.map +1 -0
- package/dist/modes/interactive/components/custom-entry.d.ts +19 -0
- package/dist/modes/interactive/components/custom-entry.d.ts.map +1 -0
- package/dist/modes/interactive/components/custom-entry.js +52 -0
- package/dist/modes/interactive/components/custom-entry.js.map +1 -0
- package/dist/modes/interactive/components/custom-message.d.ts +22 -0
- package/dist/modes/interactive/components/custom-message.d.ts.map +1 -0
- package/dist/modes/interactive/components/custom-message.js +87 -0
- package/dist/modes/interactive/components/custom-message.js.map +1 -0
- package/dist/modes/interactive/components/diff.d.ts +12 -0
- package/dist/modes/interactive/components/diff.d.ts.map +1 -0
- package/dist/modes/interactive/components/diff.js +133 -0
- package/dist/modes/interactive/components/diff.js.map +1 -0
- package/dist/modes/interactive/components/dynamic-border.d.ts +15 -0
- package/dist/modes/interactive/components/dynamic-border.d.ts.map +1 -0
- package/dist/modes/interactive/components/dynamic-border.js +21 -0
- package/dist/modes/interactive/components/dynamic-border.js.map +1 -0
- package/dist/modes/interactive/components/earendil-announcement.d.ts +5 -0
- package/dist/modes/interactive/components/earendil-announcement.d.ts.map +1 -0
- package/dist/modes/interactive/components/earendil-announcement.js +40 -0
- package/dist/modes/interactive/components/earendil-announcement.js.map +1 -0
- package/dist/modes/interactive/components/easter-egg-3d.d.ts +104 -0
- package/dist/modes/interactive/components/easter-egg-3d.d.ts.map +1 -0
- package/dist/modes/interactive/components/easter-egg-3d.js +1141 -0
- package/dist/modes/interactive/components/easter-egg-3d.js.map +1 -0
- package/dist/modes/interactive/components/easter-egg-3d.lazy.d.ts +6 -0
- package/dist/modes/interactive/components/easter-egg-3d.lazy.d.ts.map +1 -0
- package/dist/modes/interactive/components/easter-egg-3d.lazy.js +23 -0
- package/dist/modes/interactive/components/easter-egg-3d.lazy.js.map +1 -0
- package/dist/modes/interactive/components/extension-editor.d.ts +24 -0
- package/dist/modes/interactive/components/extension-editor.d.ts.map +1 -0
- package/dist/modes/interactive/components/extension-editor.js +103 -0
- package/dist/modes/interactive/components/extension-editor.js.map +1 -0
- package/dist/modes/interactive/components/extension-input.d.ts +25 -0
- package/dist/modes/interactive/components/extension-input.d.ts.map +1 -0
- package/dist/modes/interactive/components/extension-input.js +67 -0
- package/dist/modes/interactive/components/extension-input.js.map +1 -0
- package/dist/modes/interactive/components/extension-selector.d.ts +27 -0
- package/dist/modes/interactive/components/extension-selector.d.ts.map +1 -0
- package/dist/modes/interactive/components/extension-selector.js +87 -0
- package/dist/modes/interactive/components/extension-selector.js.map +1 -0
- 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 +109 -0
- package/dist/modes/interactive/components/first-time-setup.js.map +1 -0
- package/dist/modes/interactive/components/footer.d.ts +39 -0
- package/dist/modes/interactive/components/footer.d.ts.map +1 -0
- package/dist/modes/interactive/components/footer.js +265 -0
- package/dist/modes/interactive/components/footer.js.map +1 -0
- package/dist/modes/interactive/components/index.d.ts +33 -0
- package/dist/modes/interactive/components/index.d.ts.map +1 -0
- package/dist/modes/interactive/components/index.js +34 -0
- package/dist/modes/interactive/components/index.js.map +1 -0
- package/dist/modes/interactive/components/keybinding-hints.d.ts +13 -0
- package/dist/modes/interactive/components/keybinding-hints.d.ts.map +1 -0
- package/dist/modes/interactive/components/keybinding-hints.js +36 -0
- package/dist/modes/interactive/components/keybinding-hints.js.map +1 -0
- package/dist/modes/interactive/components/login-dialog.d.ts +54 -0
- package/dist/modes/interactive/components/login-dialog.d.ts.map +1 -0
- package/dist/modes/interactive/components/login-dialog.js +194 -0
- package/dist/modes/interactive/components/login-dialog.js.map +1 -0
- package/dist/modes/interactive/components/markdown-transform.d.ts +3 -0
- package/dist/modes/interactive/components/markdown-transform.d.ts.map +1 -0
- package/dist/modes/interactive/components/markdown-transform.js +19 -0
- package/dist/modes/interactive/components/markdown-transform.js.map +1 -0
- package/dist/modes/interactive/components/mermaid.d.ts +11 -0
- package/dist/modes/interactive/components/mermaid.d.ts.map +1 -0
- package/dist/modes/interactive/components/mermaid.js +75 -0
- package/dist/modes/interactive/components/mermaid.js.map +1 -0
- package/dist/modes/interactive/components/model-selector.d.ts +60 -0
- package/dist/modes/interactive/components/model-selector.d.ts.map +1 -0
- package/dist/modes/interactive/components/model-selector.js +361 -0
- package/dist/modes/interactive/components/model-selector.js.map +1 -0
- package/dist/modes/interactive/components/oauth-selector.d.ts +39 -0
- package/dist/modes/interactive/components/oauth-selector.d.ts.map +1 -0
- package/dist/modes/interactive/components/oauth-selector.js +166 -0
- package/dist/modes/interactive/components/oauth-selector.js.map +1 -0
- package/dist/modes/interactive/components/relay-logo.d.ts +22 -0
- package/dist/modes/interactive/components/relay-logo.d.ts.map +1 -0
- package/dist/modes/interactive/components/relay-logo.js +63 -0
- package/dist/modes/interactive/components/relay-logo.js.map +1 -0
- package/dist/modes/interactive/components/scoped-models-selector.d.ts +46 -0
- package/dist/modes/interactive/components/scoped-models-selector.d.ts.map +1 -0
- package/dist/modes/interactive/components/scoped-models-selector.js +326 -0
- package/dist/modes/interactive/components/scoped-models-selector.js.map +1 -0
- package/dist/modes/interactive/components/session-selector-search.d.ts +23 -0
- package/dist/modes/interactive/components/session-selector-search.d.ts.map +1 -0
- package/dist/modes/interactive/components/session-selector-search.js +155 -0
- package/dist/modes/interactive/components/session-selector-search.js.map +1 -0
- package/dist/modes/interactive/components/session-selector.d.ts +95 -0
- package/dist/modes/interactive/components/session-selector.d.ts.map +1 -0
- package/dist/modes/interactive/components/session-selector.js +893 -0
- package/dist/modes/interactive/components/session-selector.js.map +1 -0
- package/dist/modes/interactive/components/settings-selector.d.ts +96 -0
- package/dist/modes/interactive/components/settings-selector.d.ts.map +1 -0
- package/dist/modes/interactive/components/settings-selector.js +742 -0
- package/dist/modes/interactive/components/settings-selector.js.map +1 -0
- package/dist/modes/interactive/components/settings-submenu.d.ts +72 -0
- package/dist/modes/interactive/components/settings-submenu.d.ts.map +1 -0
- package/dist/modes/interactive/components/settings-submenu.js +165 -0
- package/dist/modes/interactive/components/settings-submenu.js.map +1 -0
- package/dist/modes/interactive/components/show-images-selector.d.ts +10 -0
- package/dist/modes/interactive/components/show-images-selector.d.ts.map +1 -0
- package/dist/modes/interactive/components/show-images-selector.js +39 -0
- package/dist/modes/interactive/components/show-images-selector.js.map +1 -0
- package/dist/modes/interactive/components/skill-invocation-message.d.ts +17 -0
- package/dist/modes/interactive/components/skill-invocation-message.d.ts.map +1 -0
- package/dist/modes/interactive/components/skill-invocation-message.js +54 -0
- package/dist/modes/interactive/components/skill-invocation-message.js.map +1 -0
- package/dist/modes/interactive/components/status-indicator.d.ts +30 -0
- package/dist/modes/interactive/components/status-indicator.d.ts.map +1 -0
- package/dist/modes/interactive/components/status-indicator.js +67 -0
- package/dist/modes/interactive/components/status-indicator.js.map +1 -0
- package/dist/modes/interactive/components/theme-selector.d.ts +11 -0
- package/dist/modes/interactive/components/theme-selector.d.ts.map +1 -0
- package/dist/modes/interactive/components/theme-selector.js +50 -0
- package/dist/modes/interactive/components/theme-selector.js.map +1 -0
- package/dist/modes/interactive/components/themed-text.d.ts +17 -0
- package/dist/modes/interactive/components/themed-text.d.ts.map +1 -0
- package/dist/modes/interactive/components/themed-text.js +29 -0
- package/dist/modes/interactive/components/themed-text.js.map +1 -0
- package/dist/modes/interactive/components/thinking-selector.d.ts +23 -0
- package/dist/modes/interactive/components/thinking-selector.d.ts.map +1 -0
- package/dist/modes/interactive/components/thinking-selector.js +109 -0
- package/dist/modes/interactive/components/thinking-selector.js.map +1 -0
- package/dist/modes/interactive/components/tool-execution.d.ts +68 -0
- package/dist/modes/interactive/components/tool-execution.d.ts.map +1 -0
- package/dist/modes/interactive/components/tool-execution.js +314 -0
- package/dist/modes/interactive/components/tool-execution.js.map +1 -0
- package/dist/modes/interactive/components/tree-selector.d.ts +94 -0
- package/dist/modes/interactive/components/tree-selector.d.ts.map +1 -0
- package/dist/modes/interactive/components/tree-selector.js +1254 -0
- package/dist/modes/interactive/components/tree-selector.js.map +1 -0
- 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 +30 -0
- package/dist/modes/interactive/components/user-message-selector.d.ts.map +1 -0
- package/dist/modes/interactive/components/user-message-selector.js +114 -0
- package/dist/modes/interactive/components/user-message-selector.js.map +1 -0
- package/dist/modes/interactive/components/user-message.d.ts +16 -0
- package/dist/modes/interactive/components/user-message.d.ts.map +1 -0
- package/dist/modes/interactive/components/user-message.js +50 -0
- package/dist/modes/interactive/components/user-message.js.map +1 -0
- package/dist/modes/interactive/components/visual-truncate.d.ts +48 -0
- package/dist/modes/interactive/components/visual-truncate.d.ts.map +1 -0
- package/dist/modes/interactive/components/visual-truncate.js +66 -0
- package/dist/modes/interactive/components/visual-truncate.js.map +1 -0
- package/dist/modes/interactive/external-editor.d.ts +12 -0
- package/dist/modes/interactive/external-editor.d.ts.map +1 -0
- package/dist/modes/interactive/external-editor.js +38 -0
- package/dist/modes/interactive/external-editor.js.map +1 -0
- package/dist/modes/interactive/interactive-mode.d.ts +482 -0
- package/dist/modes/interactive/interactive-mode.d.ts.map +1 -0
- package/dist/modes/interactive/interactive-mode.js +5861 -0
- package/dist/modes/interactive/interactive-mode.js.map +1 -0
- package/dist/modes/interactive/model-catalog-refresh.d.ts +7 -0
- package/dist/modes/interactive/model-catalog-refresh.d.ts.map +1 -0
- package/dist/modes/interactive/model-catalog-refresh.js +34 -0
- package/dist/modes/interactive/model-catalog-refresh.js.map +1 -0
- package/dist/modes/interactive/model-search.d.ts +12 -0
- package/dist/modes/interactive/model-search.d.ts.map +1 -0
- package/dist/modes/interactive/model-search.js +15 -0
- package/dist/modes/interactive/model-search.js.map +1 -0
- package/dist/modes/interactive/session-share.d.ts +16 -0
- package/dist/modes/interactive/session-share.d.ts.map +1 -0
- package/dist/modes/interactive/session-share.js +119 -0
- package/dist/modes/interactive/session-share.js.map +1 -0
- package/dist/modes/interactive/theme/dark.json +78 -0
- package/dist/modes/interactive/theme/light.json +78 -0
- package/dist/modes/interactive/theme/system-theme.d.ts +55 -0
- package/dist/modes/interactive/theme/system-theme.d.ts.map +1 -0
- package/dist/modes/interactive/theme/system-theme.js +546 -0
- package/dist/modes/interactive/theme/system-theme.js.map +1 -0
- package/dist/modes/interactive/theme/theme-controller.d.ts +81 -0
- package/dist/modes/interactive/theme/theme-controller.d.ts.map +1 -0
- package/dist/modes/interactive/theme/theme-controller.js +210 -0
- package/dist/modes/interactive/theme/theme-controller.js.map +1 -0
- package/dist/modes/interactive/theme/theme-json.d.ts +85 -0
- package/dist/modes/interactive/theme/theme-json.d.ts.map +1 -0
- package/dist/modes/interactive/theme/theme-json.js +132 -0
- package/dist/modes/interactive/theme/theme-json.js.map +1 -0
- package/dist/modes/interactive/theme/theme-schema.json +361 -0
- package/dist/modes/interactive/theme/theme.d.ts +158 -0
- package/dist/modes/interactive/theme/theme.d.ts.map +1 -0
- package/dist/modes/interactive/theme/theme.js +912 -0
- package/dist/modes/interactive/theme/theme.js.map +1 -0
- package/dist/modes/interactive/tui-renderer.d.ts +22 -0
- package/dist/modes/interactive/tui-renderer.d.ts.map +1 -0
- package/dist/modes/interactive/tui-renderer.js +67 -0
- package/dist/modes/interactive/tui-renderer.js.map +1 -0
- package/dist/modes/json-event.d.ts +34 -0
- package/dist/modes/json-event.d.ts.map +1 -0
- package/dist/modes/json-event.js +29 -0
- package/dist/modes/json-event.js.map +1 -0
- package/dist/modes/print-mode.d.ts +28 -0
- package/dist/modes/print-mode.d.ts.map +1 -0
- package/dist/modes/print-mode.js +142 -0
- package/dist/modes/print-mode.js.map +1 -0
- package/dist/modes/rpc/jsonl.d.ts +17 -0
- package/dist/modes/rpc/jsonl.d.ts.map +1 -0
- package/dist/modes/rpc/jsonl.js +49 -0
- package/dist/modes/rpc/jsonl.js.map +1 -0
- package/dist/modes/rpc/rpc-client.d.ts +254 -0
- package/dist/modes/rpc/rpc-client.d.ts.map +1 -0
- package/dist/modes/rpc/rpc-client.js +499 -0
- package/dist/modes/rpc/rpc-client.js.map +1 -0
- package/dist/modes/rpc/rpc-mode.d.ts +20 -0
- package/dist/modes/rpc/rpc-mode.d.ts.map +1 -0
- package/dist/modes/rpc/rpc-mode.js +655 -0
- package/dist/modes/rpc/rpc-mode.js.map +1 -0
- package/dist/modes/rpc/rpc-types.d.ts +478 -0
- package/dist/modes/rpc/rpc-types.d.ts.map +1 -0
- package/dist/modes/rpc/rpc-types.js +8 -0
- package/dist/modes/rpc/rpc-types.js.map +1 -0
- package/dist/package-manager-cli.d.ts +8 -0
- package/dist/package-manager-cli.d.ts.map +1 -0
- package/dist/package-manager-cli.js +524 -0
- package/dist/package-manager-cli.js.map +1 -0
- package/dist/rpc-entry.d.ts +3 -0
- package/dist/rpc-entry.d.ts.map +1 -0
- package/dist/rpc-entry.js +11 -0
- package/dist/rpc-entry.js.map +1 -0
- package/dist/utils/abort.d.ts +5 -0
- package/dist/utils/abort.d.ts.map +1 -0
- package/dist/utils/abort.js +48 -0
- package/dist/utils/abort.js.map +1 -0
- package/dist/utils/ansi.d.ts +2 -0
- package/dist/utils/ansi.d.ts.map +1 -0
- package/dist/utils/ansi.js +52 -0
- package/dist/utils/ansi.js.map +1 -0
- package/dist/utils/changelog.d.ts +22 -0
- package/dist/utils/changelog.d.ts.map +1 -0
- package/dist/utils/changelog.js +176 -0
- package/dist/utils/changelog.js.map +1 -0
- package/dist/utils/child-process.d.ts +18 -0
- package/dist/utils/child-process.d.ts.map +1 -0
- package/dist/utils/child-process.js +106 -0
- package/dist/utils/child-process.js.map +1 -0
- package/dist/utils/clipboard-command.d.ts +7 -0
- package/dist/utils/clipboard-command.d.ts.map +1 -0
- package/dist/utils/clipboard-command.js +45 -0
- package/dist/utils/clipboard-command.js.map +1 -0
- package/dist/utils/clipboard-image.d.ts +11 -0
- package/dist/utils/clipboard-image.d.ts.map +1 -0
- package/dist/utils/clipboard-image.js +214 -0
- package/dist/utils/clipboard-image.js.map +1 -0
- package/dist/utils/clipboard.d.ts +6 -0
- package/dist/utils/clipboard.d.ts.map +1 -0
- package/dist/utils/clipboard.js +156 -0
- package/dist/utils/clipboard.js.map +1 -0
- 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 +5 -0
- package/dist/utils/exif-orientation.d.ts.map +1 -0
- package/dist/utils/exif-orientation.js +157 -0
- package/dist/utils/exif-orientation.js.map +1 -0
- package/dist/utils/frontmatter.d.ts +8 -0
- package/dist/utils/frontmatter.d.ts.map +1 -0
- package/dist/utils/frontmatter.js +27 -0
- package/dist/utils/frontmatter.js.map +1 -0
- 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 +26 -0
- package/dist/utils/git.d.ts.map +1 -0
- package/dist/utils/git.js +195 -0
- package/dist/utils/git.js.map +1 -0
- 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 +22 -0
- package/dist/utils/image-convert.d.ts.map +1 -0
- package/dist/utils/image-convert.js +84 -0
- package/dist/utils/image-convert.js.map +1 -0
- package/dist/utils/image-process.d.ts +18 -0
- package/dist/utils/image-process.d.ts.map +1 -0
- package/dist/utils/image-process.js +83 -0
- package/dist/utils/image-process.js.map +1 -0
- package/dist/utils/image-resize-core.d.ts +30 -0
- package/dist/utils/image-resize-core.d.ts.map +1 -0
- package/dist/utils/image-resize-core.js +124 -0
- package/dist/utils/image-resize-core.js.map +1 -0
- package/dist/utils/image-resize-worker.d.ts +2 -0
- package/dist/utils/image-resize-worker.d.ts.map +1 -0
- package/dist/utils/image-resize-worker.js +31 -0
- package/dist/utils/image-resize-worker.js.map +1 -0
- package/dist/utils/image-resize.d.ts +16 -0
- package/dist/utils/image-resize.d.ts.map +1 -0
- package/dist/utils/image-resize.js +97 -0
- package/dist/utils/image-resize.js.map +1 -0
- 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/management-http.d.ts +25 -0
- package/dist/utils/management-http.d.ts.map +1 -0
- package/dist/utils/management-http.js +54 -0
- package/dist/utils/management-http.js.map +1 -0
- package/dist/utils/mime.d.ts +3 -0
- package/dist/utils/mime.d.ts.map +1 -0
- package/dist/utils/mime.js +110 -0
- package/dist/utils/mime.js.map +1 -0
- 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/output-files.d.ts +15 -0
- package/dist/utils/output-files.d.ts.map +1 -0
- package/dist/utils/output-files.js +30 -0
- package/dist/utils/output-files.js.map +1 -0
- package/dist/utils/paths.d.ts +34 -0
- package/dist/utils/paths.d.ts.map +1 -0
- package/dist/utils/paths.js +115 -0
- package/dist/utils/paths.js.map +1 -0
- package/dist/utils/photon.d.ts +21 -0
- package/dist/utils/photon.d.ts.map +1 -0
- package/dist/utils/photon.js +121 -0
- package/dist/utils/photon.js.map +1 -0
- package/dist/utils/relay-user-agent.d.ts +2 -0
- package/dist/utils/relay-user-agent.d.ts.map +1 -0
- package/dist/utils/relay-user-agent.js +5 -0
- package/dist/utils/relay-user-agent.js.map +1 -0
- package/dist/utils/shell.d.ts +32 -0
- package/dist/utils/shell.d.ts.map +1 -0
- package/dist/utils/shell.js +189 -0
- package/dist/utils/shell.js.map +1 -0
- package/dist/utils/sleep.d.ts +5 -0
- package/dist/utils/sleep.d.ts.map +1 -0
- package/dist/utils/sleep.js +17 -0
- package/dist/utils/sleep.js.map +1 -0
- package/dist/utils/syntax-highlight.d.ts +13 -0
- package/dist/utils/syntax-highlight.d.ts.map +1 -0
- package/dist/utils/syntax-highlight.js +179 -0
- package/dist/utils/syntax-highlight.js.map +1 -0
- package/dist/utils/text.d.ts +8 -0
- package/dist/utils/text.d.ts.map +1 -0
- package/dist/utils/text.js +9 -0
- package/dist/utils/text.js.map +1 -0
- package/dist/utils/tool-result-images.d.ts +21 -0
- package/dist/utils/tool-result-images.d.ts.map +1 -0
- package/dist/utils/tool-result-images.js +48 -0
- package/dist/utils/tool-result-images.js.map +1 -0
- package/dist/utils/tools-manager.d.ts +13 -0
- package/dist/utils/tools-manager.d.ts.map +1 -0
- package/dist/utils/tools-manager.js +343 -0
- package/dist/utils/tools-manager.js.map +1 -0
- package/dist/utils/version-check.d.ts +17 -0
- package/dist/utils/version-check.d.ts.map +1 -0
- package/dist/utils/version-check.js +74 -0
- package/dist/utils/version-check.js.map +1 -0
- package/dist/utils/wsl.d.ts +3 -0
- package/dist/utils/wsl.d.ts.map +1 -0
- package/dist/utils/wsl.js +15 -0
- package/dist/utils/wsl.js.map +1 -0
- package/dist/utils/zip.d.ts +7 -0
- package/dist/utils/zip.d.ts.map +1 -0
- package/dist/utils/zip.js +60 -0
- package/dist/utils/zip.js.map +1 -0
- package/docs/cli-integration.md +106 -0
- package/docs/cli.md +316 -0
- package/docs/codemode.md +207 -0
- package/docs/compaction.md +463 -0
- package/docs/configuration.md +47 -0
- package/docs/containerization.md +154 -0
- package/docs/custom-provider.md +173 -0
- package/docs/docs.json +224 -0
- package/docs/environment-variables.md +97 -0
- package/docs/extensions.md +274 -0
- package/docs/harness-core.md +99 -0
- package/docs/how-relay-works.md +49 -0
- package/docs/images/doom-extension.png +0 -0
- package/docs/images/exy.png +0 -0
- package/docs/images/interactive-mode.png +0 -0
- package/docs/images/tree-view.png +0 -0
- package/docs/index.md +39 -0
- package/docs/intake.md +40 -0
- package/docs/json.md +226 -0
- package/docs/keybindings.md +194 -0
- package/docs/laya.md +112 -0
- package/docs/llama-cpp.md +114 -0
- package/docs/mcp.md +258 -0
- package/docs/message-types.md +261 -0
- package/docs/models.md +205 -0
- package/docs/packages.md +129 -0
- package/docs/prompt-templates.md +59 -0
- package/docs/providers.md +187 -0
- package/docs/quickstart.md +126 -0
- package/docs/rpc-commands.md +860 -0
- package/docs/rpc-extension-ui.md +200 -0
- package/docs/rpc.md +193 -0
- package/docs/sdk.md +147 -0
- package/docs/security.md +99 -0
- package/docs/session-format.md +293 -0
- package/docs/sessions.md +66 -0
- package/docs/settings.md +205 -0
- package/docs/shell-aliases.md +93 -0
- package/docs/skills.md +93 -0
- package/docs/slash-commands.md +61 -0
- package/docs/terminal-setup.md +219 -0
- package/docs/termux.md +121 -0
- package/docs/themes.md +136 -0
- package/docs/tmux.md +55 -0
- package/docs/tui.md +125 -0
- package/docs/usage.md +94 -0
- package/docs/virtual-models.md +114 -0
- package/docs/windows.md +67 -0
- package/examples/README.md +39 -0
- package/examples/extensions/README.md +213 -0
- package/examples/extensions/auto-commit-on-exit.ts +49 -0
- package/examples/extensions/bash-spawn-hook.ts +30 -0
- package/examples/extensions/bookmark.ts +50 -0
- package/examples/extensions/border-status-editor.ts +150 -0
- package/examples/extensions/built-in-tool-renderer.ts +225 -0
- package/examples/extensions/claude-rules.ts +86 -0
- package/examples/extensions/commands.ts +72 -0
- package/examples/extensions/confirm-destructive.ts +59 -0
- package/examples/extensions/custom-compaction.ts +117 -0
- package/examples/extensions/custom-footer.ts +64 -0
- package/examples/extensions/custom-header.ts +73 -0
- package/examples/extensions/custom-provider-anthropic/index.ts +617 -0
- package/examples/extensions/custom-provider-anthropic/package-lock.json +24 -0
- package/examples/extensions/custom-provider-anthropic/package.json +19 -0
- package/examples/extensions/custom-provider-gitlab-duo/index.ts +405 -0
- package/examples/extensions/custom-provider-gitlab-duo/package.json +16 -0
- package/examples/extensions/custom-provider-gitlab-duo/test.ts +82 -0
- package/examples/extensions/debug-provider.ts +90 -0
- package/examples/extensions/dirty-repo-guard.ts +56 -0
- package/examples/extensions/doom-overlay/README.md +46 -0
- package/examples/extensions/doom-overlay/doom/build/doom.js +21 -0
- package/examples/extensions/doom-overlay/doom/build/doom.wasm +0 -0
- package/examples/extensions/doom-overlay/doom/build.sh +152 -0
- package/examples/extensions/doom-overlay/doom/doomgeneric_relay.c +72 -0
- package/examples/extensions/doom-overlay/doom-component.ts +132 -0
- package/examples/extensions/doom-overlay/doom-engine.ts +173 -0
- package/examples/extensions/doom-overlay/doom-keys.ts +104 -0
- package/examples/extensions/doom-overlay/index.ts +74 -0
- package/examples/extensions/doom-overlay/wad-finder.ts +55 -0
- package/examples/extensions/dynamic-resources/SKILL.md +8 -0
- package/examples/extensions/dynamic-resources/dynamic.json +81 -0
- package/examples/extensions/dynamic-resources/dynamic.md +5 -0
- package/examples/extensions/dynamic-resources/index.ts +15 -0
- package/examples/extensions/dynamic-tools.ts +74 -0
- package/examples/extensions/entry-renderer.ts +41 -0
- package/examples/extensions/event-bus.ts +43 -0
- package/examples/extensions/file-trigger.ts +41 -0
- package/examples/extensions/git-checkpoint.ts +53 -0
- package/examples/extensions/git-merge-and-resolve.ts +115 -0
- package/examples/extensions/github-issue-autocomplete.ts +185 -0
- package/examples/extensions/handoff.ts +190 -0
- package/examples/extensions/hello.ts +26 -0
- package/examples/extensions/hidden-thinking-label.ts +53 -0
- package/examples/extensions/inline-bash.ts +94 -0
- package/examples/extensions/input-transform-streaming.ts +39 -0
- package/examples/extensions/input-transform.ts +43 -0
- package/examples/extensions/interactive-shell.ts +196 -0
- package/examples/extensions/jev-router.ts +113 -0
- package/examples/extensions/mac-system-theme.ts +47 -0
- package/examples/extensions/message-renderer.ts +59 -0
- package/examples/extensions/minimal-mode.ts +354 -0
- package/examples/extensions/modal-editor.ts +85 -0
- package/examples/extensions/model-status.ts +31 -0
- package/examples/extensions/notify.ts +57 -0
- package/examples/extensions/overlay-qa-tests.ts +1450 -0
- package/examples/extensions/overlay-test.ts +153 -0
- package/examples/extensions/permission-gate.ts +34 -0
- package/examples/extensions/pirate.ts +47 -0
- package/examples/extensions/plan-mode/README.md +66 -0
- package/examples/extensions/plan-mode/index.ts +390 -0
- package/examples/extensions/plan-mode/utils.ts +168 -0
- package/examples/extensions/preset.ts +436 -0
- package/examples/extensions/project-trust.ts +64 -0
- package/examples/extensions/prompt-customizer.ts +49 -0
- package/examples/extensions/protected-paths.ts +30 -0
- package/examples/extensions/provider-payload.ts +18 -0
- package/examples/extensions/qna.ts +118 -0
- package/examples/extensions/question.ts +278 -0
- package/examples/extensions/questionnaire.ts +440 -0
- package/examples/extensions/rainbow-editor.ts +88 -0
- package/examples/extensions/reload-runtime.ts +37 -0
- package/examples/extensions/rpc-demo.ts +118 -0
- package/examples/extensions/sandbox/index.ts +321 -0
- package/examples/extensions/sandbox/package-lock.json +92 -0
- package/examples/extensions/sandbox/package.json +19 -0
- package/examples/extensions/send-user-message.ts +97 -0
- package/examples/extensions/session-name.ts +27 -0
- package/examples/extensions/shutdown-command.ts +63 -0
- package/examples/extensions/snake.ts +343 -0
- package/examples/extensions/space-invaders.ts +560 -0
- package/examples/extensions/ssh.ts +220 -0
- package/examples/extensions/status-line.ts +32 -0
- package/examples/extensions/structured-output.ts +65 -0
- package/examples/extensions/subagent/README.md +196 -0
- package/examples/extensions/subagent/agents/planner.md +37 -0
- package/examples/extensions/subagent/agents/reviewer.md +35 -0
- package/examples/extensions/subagent/agents/scout.md +50 -0
- package/examples/extensions/subagent/agents/security-auditor.md +20 -0
- package/examples/extensions/subagent/agents/verifier.md +31 -0
- package/examples/extensions/subagent/agents/worker.md +24 -0
- package/examples/extensions/subagent/agents.ts +157 -0
- package/examples/extensions/subagent/index.ts +1038 -0
- package/examples/extensions/subagent/prompts/implement-and-review.md +10 -0
- package/examples/extensions/subagent/prompts/implement-and-verify.md +10 -0
- package/examples/extensions/subagent/prompts/implement.md +10 -0
- package/examples/extensions/subagent/prompts/scout-and-plan.md +9 -0
- package/examples/extensions/subagent/skills/delegate/SKILL.md +48 -0
- package/examples/extensions/subagent/skills/security-audit/SKILL.md +108 -0
- package/examples/extensions/subagent/skills/security-audit/references/categories.md +130 -0
- package/examples/extensions/subagent/skills/security-audit/references/report.md +38 -0
- package/examples/extensions/summarize.ts +199 -0
- package/examples/extensions/system-prompt-header.ts +17 -0
- package/examples/extensions/tic-tac-toe.ts +1008 -0
- package/examples/extensions/timed-confirm.ts +70 -0
- package/examples/extensions/titlebar-spinner.ts +58 -0
- package/examples/extensions/todo.ts +297 -0
- package/examples/extensions/tool-override.ts +144 -0
- package/examples/extensions/tools.ts +146 -0
- package/examples/extensions/trigger-compact.ts +50 -0
- package/examples/extensions/truncated-tool.ts +195 -0
- package/examples/extensions/widget-placement.ts +9 -0
- package/examples/extensions/with-deps/index.ts +32 -0
- package/examples/extensions/with-deps/package-lock.json +31 -0
- package/examples/extensions/with-deps/package.json +22 -0
- package/examples/extensions/working-indicator.ts +123 -0
- package/examples/extensions/working-message-test.ts +25 -0
- package/examples/plugins/relay-example-plugin/README.md +38 -0
- package/examples/plugins/relay-example-plugin/package.json +10 -0
- package/examples/plugins/relay-example-plugin/src/contract.ts +13 -0
- package/examples/plugins/relay-example-plugin/src/session.ts +24 -0
- package/examples/plugins/relay-example-plugin/src/tui.ts +31 -0
- package/examples/rpc-client.ts +35 -0
- package/examples/rpc-extension-ui.ts +661 -0
- package/examples/sdk/01-minimal.ts +26 -0
- package/examples/sdk/02-custom-model.ts +49 -0
- package/examples/sdk/03-custom-prompt.ts +70 -0
- package/examples/sdk/04-skills.ts +55 -0
- package/examples/sdk/05-tools.ts +48 -0
- package/examples/sdk/06-extensions.ts +94 -0
- package/examples/sdk/07-context-files.ts +42 -0
- package/examples/sdk/08-prompt-templates.ts +51 -0
- package/examples/sdk/09-api-keys-and-oauth.ts +34 -0
- package/examples/sdk/10-settings.ts +53 -0
- package/examples/sdk/11-sessions.ts +52 -0
- package/examples/sdk/12-full-control.ts +74 -0
- package/examples/sdk/13-session-runtime.ts +67 -0
- package/examples/sdk/14-codemode-mcp.ts +61 -0
- package/examples/sdk/README.md +141 -0
- package/package.json +107 -5
|
@@ -0,0 +1,3553 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AgentSession - Core abstraction for agent lifecycle and session management.
|
|
3
|
+
*
|
|
4
|
+
* This class is shared between all run modes (interactive, print, rpc).
|
|
5
|
+
* It encapsulates:
|
|
6
|
+
* - Agent state access
|
|
7
|
+
* - Event subscription with automatic session persistence
|
|
8
|
+
* - Model and thinking level management
|
|
9
|
+
* - Compaction (manual and auto)
|
|
10
|
+
* - Bash execution
|
|
11
|
+
* - Session switching and branching
|
|
12
|
+
*
|
|
13
|
+
* Modes use this class and add their own I/O layer on top.
|
|
14
|
+
*/
|
|
15
|
+
import { readFileSync } from "node:fs";
|
|
16
|
+
import { basename, dirname } from "node:path";
|
|
17
|
+
import { runToolCall, } from "@relay-harness/agent-core";
|
|
18
|
+
import { contentText, getCurrentSystemMessage, retryDelayMs } from "@relay-harness/ai";
|
|
19
|
+
import { clampThinkingLevel, cleanupSessionResources, getSupportedThinkingLevels, isContextOverflow, isRecoverableLength, isRetryableAssistantError, modelsAreEqual, resetApiProviders, streamSimple, } from "@relay-harness/ai/compat";
|
|
20
|
+
import { getThemeByName, theme } from "../modes/interactive/theme/theme.js";
|
|
21
|
+
import { stripFrontmatter } from "../utils/frontmatter.js";
|
|
22
|
+
import { processImage } from "../utils/image-process.js";
|
|
23
|
+
import { sleep } from "../utils/sleep.js";
|
|
24
|
+
import { normalizeToolResultImages } from "../utils/tool-result-images.js";
|
|
25
|
+
import { formatNoApiKeyFoundMessage, formatNoModelSelectedMessage } from "./auth-guidance.js";
|
|
26
|
+
import { executeBashWithOperations } from "./bash-executor.js";
|
|
27
|
+
import { generateBugReportSummary } from "./bug-report.js";
|
|
28
|
+
import { calculateContextTokens, collectEntriesForBranchSummary, compact, estimateContextTokens, estimateProjectedContextTokens, estimateTokens, generateBranchSummary, prepareCompaction, shouldCompact, } from "./compaction/index.js";
|
|
29
|
+
import { DEFAULT_THINKING_LEVEL, THINKING_LEVEL_OPTIONS } from "./defaults.js";
|
|
30
|
+
import { exportSessionToHtml } from "./export-html/index.js";
|
|
31
|
+
import { createToolHtmlRenderer } from "./export-html/tool-renderer.js";
|
|
32
|
+
import { ExtensionRunner, wrapRegisteredTools, } from "./extensions/index.js";
|
|
33
|
+
import { emitSessionShutdownEvent } from "./extensions/runner.js";
|
|
34
|
+
import { CodingHarnessCore } from "./harness-core.js";
|
|
35
|
+
import { convertToLlm } from "./messages.js";
|
|
36
|
+
import { ModelRegistry } from "./model-registry.js";
|
|
37
|
+
import { NestedToolCallRunner } from "./nested-tool-calls.js";
|
|
38
|
+
import { expandPromptTemplate } from "./prompt-templates.js";
|
|
39
|
+
import { exportSessionToJsonl } from "./session-export.js";
|
|
40
|
+
import { getLatestCompactionEntry, SessionManager, } from "./session-manager.js";
|
|
41
|
+
import { DEFAULT_TOOL_NAMES } from "./settings-manager.js";
|
|
42
|
+
import { BUILTIN_PATH_PREFIX, createSyntheticSourceInfo, isSyntheticPath } from "./source-info.js";
|
|
43
|
+
import { buildSystemPrompt, buildSystemPromptSections, diffSystemPromptSections, normalizeBuildSystemPromptOptions, } from "./system-prompt.js";
|
|
44
|
+
import { createLocalBashOperations } from "./tools/bash.js";
|
|
45
|
+
import { createAllToolDefinitions } from "./tools/index.js";
|
|
46
|
+
import { createToolDefinitionFromAgentTool } from "./tools/tool-definition-wrapper.js";
|
|
47
|
+
import { addUsageToTotals, combineUsage, createUsageTotals } from "./usage-totals.js";
|
|
48
|
+
import { findLatestResponse, getBranchSelection, getVirtualModelState, isVirtualModel, VIRTUAL_MODEL_STATE_ENTRY, } from "./virtual-models.js";
|
|
49
|
+
/**
|
|
50
|
+
* Parse a skill block from message text.
|
|
51
|
+
* Returns null if the text doesn't contain a skill block.
|
|
52
|
+
*/
|
|
53
|
+
export function parseSkillBlock(text) {
|
|
54
|
+
const match = text.match(/^<skill name="([^"]+)" location="([^"]+)">\n([\s\S]*?)\n<\/skill>(?:\n\n([\s\S]+))?$/);
|
|
55
|
+
if (!match)
|
|
56
|
+
return null;
|
|
57
|
+
return {
|
|
58
|
+
name: match[1],
|
|
59
|
+
location: match[2],
|
|
60
|
+
content: match[3],
|
|
61
|
+
userMessage: match[4]?.trim() || undefined,
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
// ============================================================================
|
|
65
|
+
// Types
|
|
66
|
+
// ============================================================================
|
|
67
|
+
function withoutDeletedHeaders(headers) {
|
|
68
|
+
return headers
|
|
69
|
+
? Object.fromEntries(Object.entries(headers).filter((entry) => entry[1] !== null))
|
|
70
|
+
: undefined;
|
|
71
|
+
}
|
|
72
|
+
function estimateMessagesTokens(messages) {
|
|
73
|
+
let tokens = 0;
|
|
74
|
+
for (const message of messages) {
|
|
75
|
+
tokens += estimateTokens(message);
|
|
76
|
+
}
|
|
77
|
+
return tokens;
|
|
78
|
+
}
|
|
79
|
+
// ============================================================================
|
|
80
|
+
// AgentSession Class
|
|
81
|
+
// ============================================================================
|
|
82
|
+
export class AgentSession {
|
|
83
|
+
agent;
|
|
84
|
+
sessionManager;
|
|
85
|
+
settingsManager;
|
|
86
|
+
_scopedModels;
|
|
87
|
+
// Event subscription state
|
|
88
|
+
_unsubscribeAgent;
|
|
89
|
+
_eventListeners = [];
|
|
90
|
+
_isAgentRunActive = false;
|
|
91
|
+
_agentRunAbortRequested = false;
|
|
92
|
+
_idleWaitPromise;
|
|
93
|
+
_resolveIdleWait;
|
|
94
|
+
/** Tracks pending steering messages for UI display. Removed when delivered. */
|
|
95
|
+
_steeringMessages = [];
|
|
96
|
+
/** Tracks pending follow-up messages for UI display. Removed when delivered. */
|
|
97
|
+
_followUpMessages = [];
|
|
98
|
+
/** Messages queued to be included with the next user prompt as context ("asides"). */
|
|
99
|
+
_pendingNextTurnMessages = [];
|
|
100
|
+
/** Context-only custom messages queued during a run, flushed once the current turn's tool results are in. */
|
|
101
|
+
_pendingCustomMessages = [];
|
|
102
|
+
// Compaction state
|
|
103
|
+
_compactionAbortController = undefined;
|
|
104
|
+
_autoCompactionAbortController = undefined;
|
|
105
|
+
_overflowRecoveryAttempted = false;
|
|
106
|
+
// Branch summarization state
|
|
107
|
+
_branchSummaryAbortController = undefined;
|
|
108
|
+
// Retry state
|
|
109
|
+
_retryAbortController = undefined;
|
|
110
|
+
_retryAttempt = 0;
|
|
111
|
+
/**
|
|
112
|
+
* Failed response that the next request repeats, set by auto-retry and overflow recovery. The
|
|
113
|
+
* retry is routed with it as `failed`, since the context no longer contains it.
|
|
114
|
+
*/
|
|
115
|
+
_failedResponse;
|
|
116
|
+
// Bash execution state
|
|
117
|
+
_bashAbortControllers = new Set();
|
|
118
|
+
_pendingBashMessages = [];
|
|
119
|
+
// Extension system
|
|
120
|
+
_extensionRunner;
|
|
121
|
+
_turnIndex = 0;
|
|
122
|
+
_entryIdsByMessage = new WeakMap();
|
|
123
|
+
_boundaryDispatchedMessages = new WeakSet();
|
|
124
|
+
_lastAssistantMessage;
|
|
125
|
+
_lastAssistantToolResults = [];
|
|
126
|
+
_lastActivityOutcome = "completed";
|
|
127
|
+
_isBeforeSettle = false;
|
|
128
|
+
_abortDuringBeforeSettle = false;
|
|
129
|
+
_isEmittingAgentSettled = false;
|
|
130
|
+
_deferredSettledActions = [];
|
|
131
|
+
_resourceLoader;
|
|
132
|
+
_customTools;
|
|
133
|
+
_baseToolDefinitions = new Map();
|
|
134
|
+
_cwd;
|
|
135
|
+
_extensionRunnerRef;
|
|
136
|
+
_initialActiveToolNames;
|
|
137
|
+
/**
|
|
138
|
+
* Tools of the restored or reloaded loadout that are not registered yet, such as tools of MCP
|
|
139
|
+
* servers that are still connecting. They are activated when they are registered, and dropped when
|
|
140
|
+
* `setActiveToolsByName()` deactivates a tool or the next agent run starts.
|
|
141
|
+
*/
|
|
142
|
+
_pendingToolNames = new Set();
|
|
143
|
+
_usesDefaultTools;
|
|
144
|
+
_allowedToolNames;
|
|
145
|
+
_excludedToolNames;
|
|
146
|
+
_baseToolsOverride;
|
|
147
|
+
_sessionStartEvent;
|
|
148
|
+
_extensionUIContext;
|
|
149
|
+
_extensionMode = "print";
|
|
150
|
+
_extensionCommandContextActions;
|
|
151
|
+
_extensionAbortHandler;
|
|
152
|
+
_extensionShutdownHandler;
|
|
153
|
+
_extensionErrorListener;
|
|
154
|
+
_extensionErrorUnsubscriber;
|
|
155
|
+
_modelRuntime;
|
|
156
|
+
_harnessCore;
|
|
157
|
+
_cacheWarmer;
|
|
158
|
+
// Tool registry for extension getTools/setTools
|
|
159
|
+
_toolRegistry = new Map();
|
|
160
|
+
/** Created on the first `ctx.executeTool()` call. */
|
|
161
|
+
_nestedToolCalls;
|
|
162
|
+
/** Declared tools whose declarations requests leave out, from `prepareLoadout` hooks. */
|
|
163
|
+
_hiddenDeclarations = new Set();
|
|
164
|
+
_toolDefinitions = new Map();
|
|
165
|
+
_toolPromptSnippets = new Map();
|
|
166
|
+
_toolPromptGuidelines = new Map();
|
|
167
|
+
_baseSystemPromptOptions;
|
|
168
|
+
/** Prompt options after before_agent_start mutations for the active run. */
|
|
169
|
+
_runSystemPromptOptions;
|
|
170
|
+
constructor(config) {
|
|
171
|
+
this.agent = config.agent;
|
|
172
|
+
this.sessionManager = config.sessionManager;
|
|
173
|
+
this.settingsManager = config.settingsManager;
|
|
174
|
+
this._scopedModels = config.scopedModels ?? [];
|
|
175
|
+
this._resourceLoader = config.resourceLoader;
|
|
176
|
+
this._customTools = config.customTools ?? [];
|
|
177
|
+
this._cwd = config.cwd;
|
|
178
|
+
this._modelRuntime = config.modelRuntime;
|
|
179
|
+
this._cacheWarmer = config.cacheWarmer;
|
|
180
|
+
if (this._cacheWarmer) {
|
|
181
|
+
this._cacheWarmer.onWarmed = (entry) => this._emit({ type: "entry_appended", entry });
|
|
182
|
+
}
|
|
183
|
+
this._extensionRunnerRef = config.extensionRunnerRef;
|
|
184
|
+
this._initialActiveToolNames = config.initialActiveToolNames;
|
|
185
|
+
this._usesDefaultTools = config.usesDefaultTools ?? false;
|
|
186
|
+
this._allowedToolNames = config.allowedToolNames ? new Set(config.allowedToolNames) : undefined;
|
|
187
|
+
this._excludedToolNames = config.excludedToolNames ? new Set(config.excludedToolNames) : undefined;
|
|
188
|
+
this._baseToolsOverride = config.baseToolsOverride;
|
|
189
|
+
this._sessionStartEvent = config.sessionStartEvent ?? { type: "session_start", reason: "startup" };
|
|
190
|
+
// Always subscribe to agent events for internal handling
|
|
191
|
+
// (session persistence, extensions, auto-compaction, retry logic)
|
|
192
|
+
this._unsubscribeAgent = this.agent.subscribe(this._handleAgentEvent);
|
|
193
|
+
this._installAgentToolHooks();
|
|
194
|
+
this._installAgentNextTurnRefresh();
|
|
195
|
+
this._installAgentRequestProjection();
|
|
196
|
+
this._installAgentBoundaryHooks();
|
|
197
|
+
this._installHiddenDeclarationsProjection();
|
|
198
|
+
this._installAgentForcedPromptProjection();
|
|
199
|
+
// Installed last so the pillars wrap every session and extension hook.
|
|
200
|
+
this._harnessCore = new CodingHarnessCore({
|
|
201
|
+
agent: this.agent,
|
|
202
|
+
settingsManager: this.settingsManager,
|
|
203
|
+
sessionManager: this.sessionManager,
|
|
204
|
+
cwd: this._cwd,
|
|
205
|
+
getSkills: () => this._resourceLoader.getSkills().skills,
|
|
206
|
+
getUI: () => ({ ui: this._extensionUIContext, mode: this._extensionMode }),
|
|
207
|
+
});
|
|
208
|
+
this._buildRuntime({
|
|
209
|
+
activeToolNames: this._initialActiveToolNames,
|
|
210
|
+
includeAllExtensionTools: true,
|
|
211
|
+
});
|
|
212
|
+
if (this._initialActiveToolNames === undefined)
|
|
213
|
+
this._restoreToolsFromTranscript();
|
|
214
|
+
}
|
|
215
|
+
get modelRuntime() {
|
|
216
|
+
return this._modelRuntime;
|
|
217
|
+
}
|
|
218
|
+
/** The harness pillars installed on this session: alignment, evidence, context, and skills. */
|
|
219
|
+
get harnessCore() {
|
|
220
|
+
return this._harnessCore;
|
|
221
|
+
}
|
|
222
|
+
async _getRequiredRequestAuth(model, signal) {
|
|
223
|
+
let result;
|
|
224
|
+
try {
|
|
225
|
+
result = await this._modelRuntime.getAuth(model, { signal });
|
|
226
|
+
}
|
|
227
|
+
catch (error) {
|
|
228
|
+
const cause = error instanceof Error ? error.cause : undefined;
|
|
229
|
+
if (cause instanceof Error && cause.message === "authHeader requires a resolved API key") {
|
|
230
|
+
throw new Error(formatNoApiKeyFoundMessage(model.provider));
|
|
231
|
+
}
|
|
232
|
+
throw error;
|
|
233
|
+
}
|
|
234
|
+
if (result && (result.auth.apiKey || result.auth.headers)) {
|
|
235
|
+
const requestModel = result.auth.baseUrl ? { ...model, baseUrl: result.auth.baseUrl } : model;
|
|
236
|
+
return {
|
|
237
|
+
model: requestModel,
|
|
238
|
+
apiKey: result.auth.apiKey,
|
|
239
|
+
headers: withoutDeletedHeaders(result.auth.headers),
|
|
240
|
+
env: result.env,
|
|
241
|
+
};
|
|
242
|
+
}
|
|
243
|
+
const isOAuth = this._modelRuntime.isUsingOAuth(model.provider);
|
|
244
|
+
if (isOAuth) {
|
|
245
|
+
throw new Error(`Authentication failed for "${model.provider}". ` +
|
|
246
|
+
`Credentials may have expired or network is unavailable. ` +
|
|
247
|
+
`Run '/login ${model.provider}' to re-authenticate.`);
|
|
248
|
+
}
|
|
249
|
+
throw new Error(formatNoApiKeyFoundMessage(model.provider));
|
|
250
|
+
}
|
|
251
|
+
async _getSummarizationRequestAuth(selectedModel, signal) {
|
|
252
|
+
// Route a virtual model first: summaries size their input and output from the model they get.
|
|
253
|
+
const { model, thinkingLevel } = isVirtualModel(selectedModel)
|
|
254
|
+
? await this._modelRuntime.resolveModel(selectedModel, convertToLlm(this.messages), {
|
|
255
|
+
reason: "direct",
|
|
256
|
+
thinkingLevel: this.thinkingLevel,
|
|
257
|
+
signal,
|
|
258
|
+
})
|
|
259
|
+
: { model: selectedModel, thinkingLevel: this.thinkingLevel };
|
|
260
|
+
if (this.agent.streamFunction === streamSimple) {
|
|
261
|
+
return { ...(await this._getRequiredRequestAuth(model, signal)), thinkingLevel };
|
|
262
|
+
}
|
|
263
|
+
try {
|
|
264
|
+
const result = await this._modelRuntime.getAuth(model, { signal });
|
|
265
|
+
if (!result)
|
|
266
|
+
return { model, thinkingLevel };
|
|
267
|
+
const requestModel = result.auth.baseUrl ? { ...model, baseUrl: result.auth.baseUrl } : model;
|
|
268
|
+
return {
|
|
269
|
+
model: requestModel,
|
|
270
|
+
apiKey: result.auth.apiKey,
|
|
271
|
+
headers: withoutDeletedHeaders(result.auth.headers),
|
|
272
|
+
env: result.env,
|
|
273
|
+
thinkingLevel,
|
|
274
|
+
};
|
|
275
|
+
}
|
|
276
|
+
catch (error) {
|
|
277
|
+
if (signal?.aborted)
|
|
278
|
+
throw error;
|
|
279
|
+
return { model, thinkingLevel };
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
/**
|
|
283
|
+
* The model whose limits apply to `message`, or undefined when the message came from another
|
|
284
|
+
* model. Under a virtual selection, that is the physical model that produced it.
|
|
285
|
+
*/
|
|
286
|
+
_modelForMessage(message) {
|
|
287
|
+
const model = this.model;
|
|
288
|
+
if (model && isVirtualModel(model))
|
|
289
|
+
return this._modelRuntime.getPhysicalModel(message.provider, message.model);
|
|
290
|
+
return model?.provider === message.provider && model.id === message.model ? model : undefined;
|
|
291
|
+
}
|
|
292
|
+
/**
|
|
293
|
+
* Record the selection on the current branch when the branch implies another one, so a resume
|
|
294
|
+
* restores it. Tree navigation can leave the latest `model_change` on another branch; responses
|
|
295
|
+
* cannot record a virtual selection because they name physical models. Responses do record a
|
|
296
|
+
* physical selection unless the branch holds a virtual one; checking a physical selection against
|
|
297
|
+
* responses would record it on every prompt while `prepareRequest` redirects to another model.
|
|
298
|
+
*/
|
|
299
|
+
_recordSelection() {
|
|
300
|
+
const model = this.model;
|
|
301
|
+
if (!model)
|
|
302
|
+
return;
|
|
303
|
+
const getModel = (provider, modelId) => this._modelRuntime.getModel(provider, modelId);
|
|
304
|
+
const recorded = getBranchSelection(this.sessionManager.getBranch(), getModel);
|
|
305
|
+
if (!recorded || (recorded.provider === model.provider && recorded.modelId === model.id))
|
|
306
|
+
return;
|
|
307
|
+
const recordedModel = getModel(recorded.provider, recorded.modelId);
|
|
308
|
+
if (!isVirtualModel(model) && !(recordedModel && isVirtualModel(recordedModel)))
|
|
309
|
+
return;
|
|
310
|
+
this.sessionManager.appendModelChange(model.provider, model.id);
|
|
311
|
+
}
|
|
312
|
+
/** The model whose limits apply to the conversation. */
|
|
313
|
+
_limitsModel() {
|
|
314
|
+
return this.routedModel?.model ?? this.model;
|
|
315
|
+
}
|
|
316
|
+
/**
|
|
317
|
+
* Install tool hooks once on the Agent instance.
|
|
318
|
+
*
|
|
319
|
+
* The callbacks read `this._extensionRunner` at execution time, so extension reload swaps in the
|
|
320
|
+
* new runner without reinstalling hooks. Extension-specific tool wrappers are still used to adapt
|
|
321
|
+
* registered tool execution to the extension context. Tool call and tool result interception now
|
|
322
|
+
* happens here instead of in wrappers.
|
|
323
|
+
*/
|
|
324
|
+
_installAgentToolHooks() {
|
|
325
|
+
this.agent.beforeToolCall = (context) => this._beforeToolCall(context);
|
|
326
|
+
this.agent.afterToolCall = (context) => this._afterToolCall(context);
|
|
327
|
+
}
|
|
328
|
+
/** `tool_call` handlers. `parentToolCallId` is set for calls another tool made. */
|
|
329
|
+
async _beforeToolCall({ toolCall, args }, parentToolCallId) {
|
|
330
|
+
const runner = this._extensionRunner;
|
|
331
|
+
if (!runner.hasHandlers("tool_call")) {
|
|
332
|
+
return undefined;
|
|
333
|
+
}
|
|
334
|
+
try {
|
|
335
|
+
return await runner.emitToolCall({
|
|
336
|
+
type: "tool_call",
|
|
337
|
+
toolName: toolCall.name,
|
|
338
|
+
toolCallId: toolCall.id,
|
|
339
|
+
...(parentToolCallId ? { parentToolCallId } : {}),
|
|
340
|
+
input: args,
|
|
341
|
+
});
|
|
342
|
+
}
|
|
343
|
+
catch (err) {
|
|
344
|
+
if (err instanceof Error) {
|
|
345
|
+
throw err;
|
|
346
|
+
}
|
|
347
|
+
throw new Error(`Extension failed, blocking execution: ${String(err)}`);
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
/** `tool_result` handlers and image normalization. `parentToolCallId` is set for calls another tool made. */
|
|
351
|
+
async _afterToolCall({ toolCall, args, result, isError }, parentToolCallId) {
|
|
352
|
+
const runner = this._extensionRunner;
|
|
353
|
+
const hookResult = runner.hasHandlers("tool_result")
|
|
354
|
+
? await runner.emitToolResult({
|
|
355
|
+
type: "tool_result",
|
|
356
|
+
toolName: toolCall.name,
|
|
357
|
+
toolCallId: toolCall.id,
|
|
358
|
+
...(parentToolCallId ? { parentToolCallId } : {}),
|
|
359
|
+
input: args,
|
|
360
|
+
content: result.content,
|
|
361
|
+
details: result.details,
|
|
362
|
+
...(result.structuredContent === undefined ? {} : { structuredContent: result.structuredContent }),
|
|
363
|
+
isError,
|
|
364
|
+
usage: result.usage,
|
|
365
|
+
})
|
|
366
|
+
: undefined;
|
|
367
|
+
const content = hookResult?.content ?? result.content ?? [];
|
|
368
|
+
// Runs after the extension hook so images injected or replaced by extensions are normalized too.
|
|
369
|
+
const resizeOptions = this._limitsModel()?.inputLimits?.images?.resize;
|
|
370
|
+
const normalizedContent = await normalizeToolResultImages(content, {
|
|
371
|
+
autoResizeImages: this.settingsManager.getImageAutoResize(),
|
|
372
|
+
...(resizeOptions ? { resizeOptions } : {}),
|
|
373
|
+
});
|
|
374
|
+
if (!hookResult && normalizedContent === content) {
|
|
375
|
+
return undefined;
|
|
376
|
+
}
|
|
377
|
+
// The hook result already dropped structured content that replaced content no longer matches.
|
|
378
|
+
return {
|
|
379
|
+
content: normalizedContent,
|
|
380
|
+
details: hookResult?.details,
|
|
381
|
+
structuredContent: hookResult ? hookResult.structuredContent : result.structuredContent,
|
|
382
|
+
isError: hookResult?.isError ?? isError,
|
|
383
|
+
usage: hookResult?.usage,
|
|
384
|
+
};
|
|
385
|
+
}
|
|
386
|
+
/**
|
|
387
|
+
* Run a call that the tool call `parentToolCallId` made through `ctx.executeTool()`. It goes
|
|
388
|
+
* through the agent's tool pipeline with the session's hooks, against the callable tools.
|
|
389
|
+
*/
|
|
390
|
+
async _executeNestedToolCall(parentToolCallId, name, args, options) {
|
|
391
|
+
this._nestedToolCalls ??= new NestedToolCallRunner({
|
|
392
|
+
getTools: () => this._getCallableTools(),
|
|
393
|
+
isSequential: () => this.agent.toolExecution === "sequential",
|
|
394
|
+
runToolCall: (toolCall, parentId, signal, onUpdate) => {
|
|
395
|
+
const assistantMessage = this._findLastAssistantMessage();
|
|
396
|
+
if (!assistantMessage) {
|
|
397
|
+
return Promise.resolve({
|
|
398
|
+
toolCall,
|
|
399
|
+
result: { content: [{ type: "text", text: "No assistant message issued this call" }], details: {} },
|
|
400
|
+
isError: true,
|
|
401
|
+
});
|
|
402
|
+
}
|
|
403
|
+
return runToolCall(toolCall, {
|
|
404
|
+
tools: this._getCallableTools(),
|
|
405
|
+
assistantMessage,
|
|
406
|
+
context: { messages: this.agent.state.messages, tools: this.agent.state.tools },
|
|
407
|
+
beforeToolCall: (context) => this._beforeToolCall(context, parentId),
|
|
408
|
+
afterToolCall: (context) => this._afterToolCall(context, parentId),
|
|
409
|
+
signal,
|
|
410
|
+
onUpdate,
|
|
411
|
+
});
|
|
412
|
+
},
|
|
413
|
+
emit: async (event) => {
|
|
414
|
+
await this._extensionRunner.emit(event);
|
|
415
|
+
this._emit(event);
|
|
416
|
+
},
|
|
417
|
+
});
|
|
418
|
+
return this._nestedToolCalls.execute(parentToolCallId, name, args, options);
|
|
419
|
+
}
|
|
420
|
+
/** Whether `projection`, the current session projection, exceeds the compaction threshold of `model`. */
|
|
421
|
+
_exceedsCompactionThreshold(model, projection) {
|
|
422
|
+
if (model.contextWindow <= 0)
|
|
423
|
+
return false;
|
|
424
|
+
return shouldCompact(estimateProjectedContextTokens(projection, this.sessionManager.getBranch()).tokens, model.contextWindow, this.settingsManager.getCompactionSettings(this.model));
|
|
425
|
+
}
|
|
426
|
+
async _compactBeforeNextAssistantResponse(context) {
|
|
427
|
+
const projection = this.sessionManager.buildSessionProjection();
|
|
428
|
+
// A virtual selection is checked in prepareRequest, against the model the request is routed to.
|
|
429
|
+
const model = this.model;
|
|
430
|
+
if (!model || isVirtualModel(model) || !this._exceedsCompactionThreshold(model, projection)) {
|
|
431
|
+
return { ...context, messages: projection.messages };
|
|
432
|
+
}
|
|
433
|
+
await this._runAutoCompaction("threshold", false);
|
|
434
|
+
return { ...context, messages: this.sessionManager.buildSessionProjection().messages };
|
|
435
|
+
}
|
|
436
|
+
_installAgentRequestProjection() {
|
|
437
|
+
const previousPrepareRequest = this.agent.prepareRequest;
|
|
438
|
+
this.agent.prepareRequest = async (request, signal) => {
|
|
439
|
+
const failed = this._failedResponse;
|
|
440
|
+
this._failedResponse = undefined;
|
|
441
|
+
const prepare = async () => {
|
|
442
|
+
const projection = this.sessionManager.buildSessionProjection();
|
|
443
|
+
const canonicalContext = {
|
|
444
|
+
...request.context,
|
|
445
|
+
messages: projection.messages,
|
|
446
|
+
// Messages declare the provider-visible loadout; context.tools keeps executable implementations.
|
|
447
|
+
tools: this.agent.state.tools.slice(),
|
|
448
|
+
};
|
|
449
|
+
const previous = await previousPrepareRequest?.({
|
|
450
|
+
...request,
|
|
451
|
+
context: canonicalContext,
|
|
452
|
+
model: this.agent.state.model,
|
|
453
|
+
thinkingLevel: this.agent.state.thinkingLevel,
|
|
454
|
+
}, signal);
|
|
455
|
+
return { previous, context: previous?.context ?? canonicalContext, projection };
|
|
456
|
+
};
|
|
457
|
+
let { previous, context, projection } = await prepare();
|
|
458
|
+
const model = previous?.model ?? this.agent.state.model;
|
|
459
|
+
const thinkingLevel = previous?.thinkingLevel ?? this.agent.state.thinkingLevel;
|
|
460
|
+
if (!isVirtualModel(model))
|
|
461
|
+
return { ...previous, context, model, thinkingLevel };
|
|
462
|
+
// The selection stays in agent state; only this request uses the routed model. A routing
|
|
463
|
+
// failure rejects, which ends the run with an error response. Only messages the user wrote
|
|
464
|
+
// start a turn; extension messages can follow them, e.g. from before_agent_start.
|
|
465
|
+
const lastResponse = context.messages.findLastIndex((message) => message.role === "assistant");
|
|
466
|
+
const userTurn = context.messages.slice(lastResponse + 1).some((message) => message.role === "user");
|
|
467
|
+
const state = getVirtualModelState(this.sessionManager.getBranch(), model.provider, model.id);
|
|
468
|
+
const route = await this._modelRuntime.resolveModel(model, convertToLlm(context.messages), {
|
|
469
|
+
reason: failed ? "retry" : userTurn ? "user" : "continuation",
|
|
470
|
+
thinkingLevel,
|
|
471
|
+
signal,
|
|
472
|
+
failed,
|
|
473
|
+
state,
|
|
474
|
+
});
|
|
475
|
+
if (route.state !== undefined && route.state !== state) {
|
|
476
|
+
const data = { provider: model.provider, modelId: model.id, state: route.state };
|
|
477
|
+
const entry = this.sessionManager.getEntry(this.sessionManager.appendCustomEntry(VIRTUAL_MODEL_STATE_ENTRY, data));
|
|
478
|
+
if (entry)
|
|
479
|
+
this._emit({ type: "entry_appended", entry });
|
|
480
|
+
}
|
|
481
|
+
// The route stands: the router already decided this request. The state entry does not change
|
|
482
|
+
// the projection.
|
|
483
|
+
if (this._exceedsCompactionThreshold(route.model, projection)) {
|
|
484
|
+
await this._runAutoCompaction("threshold", false);
|
|
485
|
+
({ previous, context } = await prepare());
|
|
486
|
+
}
|
|
487
|
+
return { ...previous, context, model: route.model, thinkingLevel: route.thinkingLevel };
|
|
488
|
+
};
|
|
489
|
+
}
|
|
490
|
+
async _dispatchTurnEndBoundary(message, toolResults) {
|
|
491
|
+
this._lastActivityOutcome =
|
|
492
|
+
message.stopReason === "aborted" ? "aborted" : message.stopReason === "error" ? "error" : "completed";
|
|
493
|
+
const messageEntryId = this._findPersistedMessageEntryId(message);
|
|
494
|
+
if (!this._extensionRunner.hasHandlers("turn_end"))
|
|
495
|
+
return false;
|
|
496
|
+
if (!messageEntryId) {
|
|
497
|
+
this._extensionRunner.emitError({
|
|
498
|
+
extensionPath: "<boundary>",
|
|
499
|
+
event: "turn_end",
|
|
500
|
+
error: "turn_end could not resolve the persisted assistant entry ID",
|
|
501
|
+
});
|
|
502
|
+
return false;
|
|
503
|
+
}
|
|
504
|
+
const toolResultEntryIds = toolResults.flatMap((result) => {
|
|
505
|
+
const entryId = this._findPersistedMessageEntryId(result);
|
|
506
|
+
return entryId ? [entryId] : [];
|
|
507
|
+
});
|
|
508
|
+
const boundary = await this._extensionRunner.emitBoundary({
|
|
509
|
+
type: "turn_end",
|
|
510
|
+
turnIndex: this._turnIndex,
|
|
511
|
+
message,
|
|
512
|
+
toolResults,
|
|
513
|
+
messageEntryId,
|
|
514
|
+
toolResultEntryIds,
|
|
515
|
+
outcome: this._lastActivityOutcome,
|
|
516
|
+
}, (entries) => this._buildBoundaryContext(entries, "turn_end"));
|
|
517
|
+
this._commitBoundaryDrafts(boundary.entries);
|
|
518
|
+
if (boundary.continue && !this._buildBoundaryContext([], "turn_end").canContinue) {
|
|
519
|
+
this._reportInvalidBoundaryContinuation("turn_end");
|
|
520
|
+
return false;
|
|
521
|
+
}
|
|
522
|
+
return boundary.continue;
|
|
523
|
+
}
|
|
524
|
+
_installAgentBoundaryHooks() {
|
|
525
|
+
const previousFinishTurn = this.agent.finishTurn;
|
|
526
|
+
this.agent.finishTurn = async (turn, signal) => {
|
|
527
|
+
this._boundaryDispatchedMessages.add(turn.message);
|
|
528
|
+
const extensionContinue = await this._dispatchTurnEndBoundary(turn.message, turn.toolResults);
|
|
529
|
+
const previousDecision = await previousFinishTurn?.(turn, signal);
|
|
530
|
+
if (previousDecision?.action === "end")
|
|
531
|
+
return previousDecision;
|
|
532
|
+
if (extensionContinue || previousDecision?.action === "continue")
|
|
533
|
+
return { action: "continue" };
|
|
534
|
+
return undefined;
|
|
535
|
+
};
|
|
536
|
+
}
|
|
537
|
+
_installAgentNextTurnRefresh() {
|
|
538
|
+
const previousPrepareNextTurnWithContext = this.agent.prepareNextTurnWithContext ??
|
|
539
|
+
(this.agent.prepareNextTurn
|
|
540
|
+
? async (_turn, signal) => await this.agent.prepareNextTurn?.(signal)
|
|
541
|
+
: undefined);
|
|
542
|
+
this.agent.prepareNextTurnWithContext = async (turn, signal) => {
|
|
543
|
+
const context = await this._compactBeforeNextAssistantResponse(turn.context);
|
|
544
|
+
const previousSnapshot = await previousPrepareNextTurnWithContext?.({ ...turn, context }, signal);
|
|
545
|
+
const nextContext = previousSnapshot?.context ?? context;
|
|
546
|
+
const runOptions = this._runSystemPromptOptions ?? this._baseSystemPromptOptions;
|
|
547
|
+
const options = normalizeBuildSystemPromptOptions({
|
|
548
|
+
...runOptions,
|
|
549
|
+
selectedTools: this.getActiveToolNames(),
|
|
550
|
+
toolSnippets: { ...this._baseSystemPromptOptions.toolSnippets, ...runOptions.toolSnippets },
|
|
551
|
+
toolGuidelines: { ...this._baseSystemPromptOptions.toolGuidelines, ...runOptions.toolGuidelines },
|
|
552
|
+
});
|
|
553
|
+
const updateMessage = this._preparePromptAndToolLoadout(options, nextContext.messages);
|
|
554
|
+
// Keep session.systemPrompt and ctx.getSystemPrompt() in step with what the provider sees.
|
|
555
|
+
this._runSystemPromptOptions = options;
|
|
556
|
+
return {
|
|
557
|
+
...previousSnapshot,
|
|
558
|
+
context: {
|
|
559
|
+
...nextContext,
|
|
560
|
+
tools: this.agent.state.tools.slice(),
|
|
561
|
+
},
|
|
562
|
+
messages: updateMessage
|
|
563
|
+
? [...(previousSnapshot?.messages ?? []), updateMessage]
|
|
564
|
+
: previousSnapshot?.messages,
|
|
565
|
+
model: this.agent.state.model,
|
|
566
|
+
thinkingLevel: this.agent.state.thinkingLevel,
|
|
567
|
+
};
|
|
568
|
+
};
|
|
569
|
+
}
|
|
570
|
+
// =========================================================================
|
|
571
|
+
// Event Subscription
|
|
572
|
+
// =========================================================================
|
|
573
|
+
_refreshFinalizedContext() {
|
|
574
|
+
const projection = this.sessionManager.buildSessionProjection();
|
|
575
|
+
for (const entry of projection.entries) {
|
|
576
|
+
for (const message of entry.messages)
|
|
577
|
+
this._entryIdsByMessage.set(message, entry.sourceEntry.id);
|
|
578
|
+
}
|
|
579
|
+
this.agent.state.messages = projection.messages;
|
|
580
|
+
}
|
|
581
|
+
_applyBoundaryDrafts(manager, drafts) {
|
|
582
|
+
const appended = [];
|
|
583
|
+
for (const draft of drafts) {
|
|
584
|
+
let entryId;
|
|
585
|
+
switch (draft.type) {
|
|
586
|
+
case "custom":
|
|
587
|
+
entryId = manager.appendCustomEntry(draft.customType, draft.data);
|
|
588
|
+
break;
|
|
589
|
+
case "custom_message":
|
|
590
|
+
entryId = manager.appendCustomMessageEntry(draft.customType, draft.content, draft.display, draft.details);
|
|
591
|
+
break;
|
|
592
|
+
case "context_edit":
|
|
593
|
+
entryId = manager.appendContextEdit(draft.targetId, draft.replacement);
|
|
594
|
+
break;
|
|
595
|
+
case "compaction": {
|
|
596
|
+
const tokensBefore = estimateProjectedContextTokens(manager.buildSessionProjection(), manager.getBranch()).tokens;
|
|
597
|
+
entryId = manager.appendCompaction(draft.summary, draft.firstKeptEntryId, tokensBefore, draft.details, true, draft.usage);
|
|
598
|
+
break;
|
|
599
|
+
}
|
|
600
|
+
}
|
|
601
|
+
const entry = manager.getEntry(entryId);
|
|
602
|
+
if (entry)
|
|
603
|
+
appended.push(entry);
|
|
604
|
+
}
|
|
605
|
+
return appended;
|
|
606
|
+
}
|
|
607
|
+
_createBoundaryPreviewManager(drafts) {
|
|
608
|
+
const header = this.sessionManager.getHeader();
|
|
609
|
+
if (!header)
|
|
610
|
+
throw new Error("Session header is missing");
|
|
611
|
+
const manager = SessionManager.inMemory(this._cwd, undefined, [header, ...this.sessionManager.getBranch()]);
|
|
612
|
+
this._applyBoundaryDrafts(manager, drafts);
|
|
613
|
+
return manager;
|
|
614
|
+
}
|
|
615
|
+
_getPendingBoundaryMessages() {
|
|
616
|
+
return [...this.agent.peekQueuedMessages(), ...this._pendingCustomMessages];
|
|
617
|
+
}
|
|
618
|
+
_buildBoundaryContext(drafts, boundary) {
|
|
619
|
+
const projection = this._createBoundaryPreviewManager(drafts).buildSessionProjection();
|
|
620
|
+
const pendingMessages = this._getPendingBoundaryMessages();
|
|
621
|
+
const llmMessages = convertToLlm(projection.messages);
|
|
622
|
+
const finalRole = llmMessages[llmMessages.length - 1]?.role;
|
|
623
|
+
const hasNonSystemContext = llmMessages.some((message) => message.role !== "system");
|
|
624
|
+
const contextCanContinue = hasNonSystemContext && finalRole !== "assistant";
|
|
625
|
+
const pendingCustomContext = this._pendingCustomMessages.length > 0;
|
|
626
|
+
return {
|
|
627
|
+
contextEntries: projection.entries,
|
|
628
|
+
contextMessages: projection.messages,
|
|
629
|
+
llmMessages,
|
|
630
|
+
pendingMessages,
|
|
631
|
+
canContinue: contextCanContinue ||
|
|
632
|
+
pendingCustomContext ||
|
|
633
|
+
(boundary === "turn_end"
|
|
634
|
+
? this.agent.hasQueuedMessages()
|
|
635
|
+
: finalRole === "assistant" && this.agent.hasQueuedMessages()),
|
|
636
|
+
};
|
|
637
|
+
}
|
|
638
|
+
_commitBoundaryDrafts(drafts) {
|
|
639
|
+
const appended = this._applyBoundaryDrafts(this.sessionManager, drafts);
|
|
640
|
+
this._refreshFinalizedContext();
|
|
641
|
+
for (const entry of appended)
|
|
642
|
+
this._emit({ type: "entry_appended", entry });
|
|
643
|
+
}
|
|
644
|
+
_reportInvalidBoundaryContinuation(event) {
|
|
645
|
+
this._extensionRunner.emitError({
|
|
646
|
+
extensionPath: "<boundary>",
|
|
647
|
+
event,
|
|
648
|
+
error: `${event} requested continuation without runnable model context`,
|
|
649
|
+
});
|
|
650
|
+
}
|
|
651
|
+
/** Emit an event to all listeners */
|
|
652
|
+
_emit(event) {
|
|
653
|
+
for (const l of this._eventListeners) {
|
|
654
|
+
l(event);
|
|
655
|
+
}
|
|
656
|
+
}
|
|
657
|
+
_emitQueueUpdate() {
|
|
658
|
+
this._emit({
|
|
659
|
+
type: "queue_update",
|
|
660
|
+
steering: [...this._steeringMessages],
|
|
661
|
+
followUp: [...this._followUpMessages],
|
|
662
|
+
});
|
|
663
|
+
}
|
|
664
|
+
async _emitSessionCompactFailed(event) {
|
|
665
|
+
if (this._extensionRunner.hasHandlers("session_compact_failed")) {
|
|
666
|
+
await this._extensionRunner.emit({ type: "session_compact_failed", ...event });
|
|
667
|
+
}
|
|
668
|
+
}
|
|
669
|
+
_getIdleWaitPromise() {
|
|
670
|
+
if (!this._idleWaitPromise) {
|
|
671
|
+
this._idleWaitPromise = new Promise((resolve) => {
|
|
672
|
+
this._resolveIdleWait = resolve;
|
|
673
|
+
});
|
|
674
|
+
}
|
|
675
|
+
return this._idleWaitPromise;
|
|
676
|
+
}
|
|
677
|
+
_resolveIdleWaitIfIdle() {
|
|
678
|
+
if (!this.isIdle || !this._resolveIdleWait) {
|
|
679
|
+
return;
|
|
680
|
+
}
|
|
681
|
+
const resolve = this._resolveIdleWait;
|
|
682
|
+
this._idleWaitPromise = undefined;
|
|
683
|
+
this._resolveIdleWait = undefined;
|
|
684
|
+
resolve();
|
|
685
|
+
}
|
|
686
|
+
async _emitAgentSettled() {
|
|
687
|
+
this._cacheWarmer?.onAgentSettled();
|
|
688
|
+
this._isAgentRunActive = false;
|
|
689
|
+
this._isEmittingAgentSettled = true;
|
|
690
|
+
try {
|
|
691
|
+
await this._extensionRunner.emit({ type: "agent_settled" });
|
|
692
|
+
this._emit({ type: "agent_settled" });
|
|
693
|
+
}
|
|
694
|
+
finally {
|
|
695
|
+
this._isEmittingAgentSettled = false;
|
|
696
|
+
}
|
|
697
|
+
const deferred = this._deferredSettledActions.splice(0);
|
|
698
|
+
if (deferred.length > 0) {
|
|
699
|
+
try {
|
|
700
|
+
for (const action of deferred)
|
|
701
|
+
await action();
|
|
702
|
+
}
|
|
703
|
+
finally {
|
|
704
|
+
this._resolveIdleWaitIfIdle();
|
|
705
|
+
}
|
|
706
|
+
return;
|
|
707
|
+
}
|
|
708
|
+
this._resolveIdleWaitIfIdle();
|
|
709
|
+
}
|
|
710
|
+
/** Internal handler for agent events - shared by subscribe and reconnect */
|
|
711
|
+
_handleAgentEvent = async (event) => {
|
|
712
|
+
// Record the calls a tool made through ctx.executeTool() and their usage on its result message.
|
|
713
|
+
if (this._nestedToolCalls) {
|
|
714
|
+
if (event.type === "message_start" && event.message.role === "toolResult") {
|
|
715
|
+
const message = event.message;
|
|
716
|
+
const summary = this._nestedToolCalls.takeRecord(message.toolCallId);
|
|
717
|
+
if (summary?.calls)
|
|
718
|
+
message.nestedCalls = summary.calls;
|
|
719
|
+
if (summary?.usage) {
|
|
720
|
+
message.usage = message.usage ? combineUsage(message.usage, summary.usage) : summary.usage;
|
|
721
|
+
}
|
|
722
|
+
}
|
|
723
|
+
else if (event.type === "agent_end") {
|
|
724
|
+
this._nestedToolCalls.clear();
|
|
725
|
+
}
|
|
726
|
+
}
|
|
727
|
+
// When a user message starts, check if it's from either queue and remove it BEFORE emitting
|
|
728
|
+
// This ensures the UI sees the updated queue state
|
|
729
|
+
if (event.type === "message_start" && event.message.role === "user") {
|
|
730
|
+
this._overflowRecoveryAttempted = false;
|
|
731
|
+
const messageText = contentText(event.message.content, "");
|
|
732
|
+
if (messageText) {
|
|
733
|
+
// Check steering queue first
|
|
734
|
+
const steeringIndex = this._steeringMessages.indexOf(messageText);
|
|
735
|
+
if (steeringIndex !== -1) {
|
|
736
|
+
this._steeringMessages.splice(steeringIndex, 1);
|
|
737
|
+
this._emitQueueUpdate();
|
|
738
|
+
}
|
|
739
|
+
else {
|
|
740
|
+
// Check follow-up queue
|
|
741
|
+
const followUpIndex = this._followUpMessages.indexOf(messageText);
|
|
742
|
+
if (followUpIndex !== -1) {
|
|
743
|
+
this._followUpMessages.splice(followUpIndex, 1);
|
|
744
|
+
this._emitQueueUpdate();
|
|
745
|
+
}
|
|
746
|
+
}
|
|
747
|
+
}
|
|
748
|
+
}
|
|
749
|
+
// Emit to extensions first, then notify public listeners.
|
|
750
|
+
await this._emitExtensionEvent(event);
|
|
751
|
+
this._emit(event.type === "agent_end" ? { ...event, willRetry: this._willRetryAfterAgentEnd(event) } : event);
|
|
752
|
+
// Handle session persistence
|
|
753
|
+
if (event.type === "message_end") {
|
|
754
|
+
let entryId;
|
|
755
|
+
// Check if this is a custom message from extensions
|
|
756
|
+
if (event.message.role === "custom") {
|
|
757
|
+
// Persist as CustomMessageEntry
|
|
758
|
+
entryId = this.sessionManager.appendCustomMessageEntry(event.message.customType, event.message.content, event.message.display, event.message.details);
|
|
759
|
+
}
|
|
760
|
+
else if (event.message.role === "system" ||
|
|
761
|
+
event.message.role === "user" ||
|
|
762
|
+
event.message.role === "assistant" ||
|
|
763
|
+
event.message.role === "toolResult") {
|
|
764
|
+
// Regular LLM message - persist as SessionMessageEntry
|
|
765
|
+
entryId = this.sessionManager.appendMessage(event.message);
|
|
766
|
+
}
|
|
767
|
+
if (entryId)
|
|
768
|
+
this._entryIdsByMessage.set(event.message, entryId);
|
|
769
|
+
// Other message types (bashExecution, compactionSummary, branchSummary) are persisted elsewhere
|
|
770
|
+
if (event.message.role === "assistant") {
|
|
771
|
+
const assistantMsg = event.message;
|
|
772
|
+
this._lastAssistantMessage = assistantMsg;
|
|
773
|
+
if (assistantMsg.stopReason !== "error" && assistantMsg.stopReason !== "length") {
|
|
774
|
+
this._overflowRecoveryAttempted = false;
|
|
775
|
+
}
|
|
776
|
+
// Reset retry counter immediately on successful assistant response
|
|
777
|
+
// This prevents accumulation across multiple LLM calls within a turn
|
|
778
|
+
if (assistantMsg.stopReason !== "error" && this._retryAttempt > 0) {
|
|
779
|
+
this._emit({
|
|
780
|
+
type: "auto_retry_end",
|
|
781
|
+
success: true,
|
|
782
|
+
attempt: this._retryAttempt,
|
|
783
|
+
});
|
|
784
|
+
this._retryAttempt = 0;
|
|
785
|
+
}
|
|
786
|
+
}
|
|
787
|
+
}
|
|
788
|
+
// A turn ends after its assistant message and every tool result has been appended,
|
|
789
|
+
// so this is the first point in the run where a context-only custom message can be
|
|
790
|
+
// inserted without landing between a tool call and its result. Flushing after the
|
|
791
|
+
// extension and listener dispatch above also picks up messages that turn_end
|
|
792
|
+
// handlers queued.
|
|
793
|
+
if (event.type === "turn_end") {
|
|
794
|
+
this._lastAssistantToolResults = event.toolResults;
|
|
795
|
+
this._flushPendingCustomMessages();
|
|
796
|
+
}
|
|
797
|
+
};
|
|
798
|
+
_willRetryAfterAgentEnd(event) {
|
|
799
|
+
if (this._agentRunAbortRequested)
|
|
800
|
+
return false;
|
|
801
|
+
const settings = this.settingsManager.getRetrySettings();
|
|
802
|
+
if (!settings.enabled || this._retryAttempt >= settings.maxRetries) {
|
|
803
|
+
return false;
|
|
804
|
+
}
|
|
805
|
+
for (let i = event.messages.length - 1; i >= 0; i--) {
|
|
806
|
+
const message = event.messages[i];
|
|
807
|
+
if (message.role === "assistant") {
|
|
808
|
+
return this._isRetryableError(message);
|
|
809
|
+
}
|
|
810
|
+
}
|
|
811
|
+
return false;
|
|
812
|
+
}
|
|
813
|
+
_findPersistedMessageEntryId(message) {
|
|
814
|
+
const mapped = this._entryIdsByMessage.get(message);
|
|
815
|
+
if (mapped)
|
|
816
|
+
return mapped;
|
|
817
|
+
for (const entry of [...this.sessionManager.getBranch()].reverse()) {
|
|
818
|
+
if (entry.type === "message" && entry.message === message)
|
|
819
|
+
return entry.id;
|
|
820
|
+
}
|
|
821
|
+
const messageIndex = this.agent.state.messages.indexOf(message);
|
|
822
|
+
if (messageIndex < 0)
|
|
823
|
+
return undefined;
|
|
824
|
+
const projection = this.sessionManager.buildSessionProjection();
|
|
825
|
+
let projectedIndex = 0;
|
|
826
|
+
for (const entry of projection.entries) {
|
|
827
|
+
for (let i = 0; i < entry.messages.length; i++) {
|
|
828
|
+
if (projectedIndex === messageIndex) {
|
|
829
|
+
this._entryIdsByMessage.set(message, entry.sourceEntry.id);
|
|
830
|
+
return entry.sourceEntry.id;
|
|
831
|
+
}
|
|
832
|
+
projectedIndex++;
|
|
833
|
+
}
|
|
834
|
+
}
|
|
835
|
+
return undefined;
|
|
836
|
+
}
|
|
837
|
+
_omitRecoveryAttempt(message, toolResults = []) {
|
|
838
|
+
const targets = [message, ...toolResults];
|
|
839
|
+
const targetIds = targets.map((target) => this._findPersistedMessageEntryId(target));
|
|
840
|
+
const unresolvedProjectedTarget = targets.some((target, index) => targetIds[index] === undefined && this.agent.state.messages.includes(target));
|
|
841
|
+
if (unresolvedProjectedTarget) {
|
|
842
|
+
throw new Error("Cannot persist recovery omission because a projected message has no source entry");
|
|
843
|
+
}
|
|
844
|
+
for (const targetId of targetIds) {
|
|
845
|
+
if (!targetId)
|
|
846
|
+
continue;
|
|
847
|
+
const editId = this.sessionManager.appendContextEdit(targetId, null);
|
|
848
|
+
const entry = this.sessionManager.getEntry(editId);
|
|
849
|
+
if (entry)
|
|
850
|
+
this._emit({ type: "entry_appended", entry });
|
|
851
|
+
}
|
|
852
|
+
this._refreshFinalizedContext();
|
|
853
|
+
}
|
|
854
|
+
/** Find the last assistant message in agent state (including aborted ones) */
|
|
855
|
+
_findLastAssistantMessage() {
|
|
856
|
+
const messages = this.agent.state.messages;
|
|
857
|
+
for (let i = messages.length - 1; i >= 0; i--) {
|
|
858
|
+
const msg = messages[i];
|
|
859
|
+
if (msg.role === "assistant") {
|
|
860
|
+
return msg;
|
|
861
|
+
}
|
|
862
|
+
}
|
|
863
|
+
return undefined;
|
|
864
|
+
}
|
|
865
|
+
_replaceMessageInPlace(target, replacement) {
|
|
866
|
+
// Agent-core stores the finalized message object in its state before emitting message_end.
|
|
867
|
+
// SessionManager persistence happens later in _handleAgentEvent() with event.message.
|
|
868
|
+
// Mutating this object in place keeps agent state, later turn/agent events, listeners,
|
|
869
|
+
// and the eventual SessionManager.appendMessage(event.message) persistence in sync.
|
|
870
|
+
if (target === replacement) {
|
|
871
|
+
return;
|
|
872
|
+
}
|
|
873
|
+
const targetRecord = target;
|
|
874
|
+
for (const key of Object.keys(targetRecord)) {
|
|
875
|
+
delete targetRecord[key];
|
|
876
|
+
}
|
|
877
|
+
Object.assign(targetRecord, replacement);
|
|
878
|
+
}
|
|
879
|
+
/** Emit extension events based on agent events */
|
|
880
|
+
async _emitExtensionEvent(event) {
|
|
881
|
+
if (event.type === "agent_start") {
|
|
882
|
+
this._turnIndex = 0;
|
|
883
|
+
await this._extensionRunner.emit({ type: "agent_start" });
|
|
884
|
+
}
|
|
885
|
+
else if (event.type === "agent_end") {
|
|
886
|
+
await this._extensionRunner.emit({ type: "agent_end", messages: event.messages });
|
|
887
|
+
}
|
|
888
|
+
else if (event.type === "turn_start") {
|
|
889
|
+
const extensionEvent = {
|
|
890
|
+
type: "turn_start",
|
|
891
|
+
turnIndex: this._turnIndex,
|
|
892
|
+
timestamp: Date.now(),
|
|
893
|
+
};
|
|
894
|
+
await this._extensionRunner.emit(extensionEvent);
|
|
895
|
+
}
|
|
896
|
+
else if (event.type === "turn_end") {
|
|
897
|
+
if (event.message.role === "assistant" && !this._boundaryDispatchedMessages.delete(event.message)) {
|
|
898
|
+
await this._dispatchTurnEndBoundary(event.message, event.toolResults);
|
|
899
|
+
}
|
|
900
|
+
this._turnIndex++;
|
|
901
|
+
}
|
|
902
|
+
else if (event.type === "message_start") {
|
|
903
|
+
const extensionEvent = {
|
|
904
|
+
type: "message_start",
|
|
905
|
+
message: event.message,
|
|
906
|
+
};
|
|
907
|
+
await this._extensionRunner.emit(extensionEvent);
|
|
908
|
+
}
|
|
909
|
+
else if (event.type === "message_update") {
|
|
910
|
+
const extensionEvent = {
|
|
911
|
+
type: "message_update",
|
|
912
|
+
message: event.message,
|
|
913
|
+
assistantMessageEvent: event.assistantMessageEvent,
|
|
914
|
+
};
|
|
915
|
+
await this._extensionRunner.emit(extensionEvent);
|
|
916
|
+
}
|
|
917
|
+
else if (event.type === "message_end") {
|
|
918
|
+
const extensionEvent = {
|
|
919
|
+
type: "message_end",
|
|
920
|
+
message: event.message,
|
|
921
|
+
};
|
|
922
|
+
const replacement = await this._extensionRunner.emitMessageEnd(extensionEvent);
|
|
923
|
+
if (replacement) {
|
|
924
|
+
// Untyped extension handlers can return messages with null/missing content;
|
|
925
|
+
// normalize so it never enters agent state or session history.
|
|
926
|
+
const normalized = (replacement.role === "user" ||
|
|
927
|
+
replacement.role === "assistant" ||
|
|
928
|
+
replacement.role === "toolResult" ||
|
|
929
|
+
replacement.role === "custom") &&
|
|
930
|
+
replacement.content == null
|
|
931
|
+
? { ...replacement, content: [] }
|
|
932
|
+
: replacement;
|
|
933
|
+
this._replaceMessageInPlace(event.message, normalized);
|
|
934
|
+
}
|
|
935
|
+
}
|
|
936
|
+
else if (event.type === "tool_execution_start") {
|
|
937
|
+
const extensionEvent = {
|
|
938
|
+
type: "tool_execution_start",
|
|
939
|
+
toolCallId: event.toolCallId,
|
|
940
|
+
toolName: event.toolName,
|
|
941
|
+
args: event.args,
|
|
942
|
+
};
|
|
943
|
+
await this._extensionRunner.emit(extensionEvent);
|
|
944
|
+
}
|
|
945
|
+
else if (event.type === "tool_execution_update") {
|
|
946
|
+
const extensionEvent = {
|
|
947
|
+
type: "tool_execution_update",
|
|
948
|
+
toolCallId: event.toolCallId,
|
|
949
|
+
toolName: event.toolName,
|
|
950
|
+
args: event.args,
|
|
951
|
+
partialResult: event.partialResult,
|
|
952
|
+
};
|
|
953
|
+
await this._extensionRunner.emit(extensionEvent);
|
|
954
|
+
}
|
|
955
|
+
else if (event.type === "tool_execution_end") {
|
|
956
|
+
const extensionEvent = {
|
|
957
|
+
type: "tool_execution_end",
|
|
958
|
+
toolCallId: event.toolCallId,
|
|
959
|
+
toolName: event.toolName,
|
|
960
|
+
result: event.result,
|
|
961
|
+
isError: event.isError,
|
|
962
|
+
};
|
|
963
|
+
await this._extensionRunner.emit(extensionEvent);
|
|
964
|
+
}
|
|
965
|
+
}
|
|
966
|
+
/**
|
|
967
|
+
* Subscribe to agent events.
|
|
968
|
+
* Session persistence is handled internally (saves messages on message_end).
|
|
969
|
+
* Multiple listeners can be added. Returns unsubscribe function for this listener.
|
|
970
|
+
*/
|
|
971
|
+
subscribe(listener) {
|
|
972
|
+
this._eventListeners.push(listener);
|
|
973
|
+
// Return unsubscribe function for this specific listener
|
|
974
|
+
return () => {
|
|
975
|
+
const index = this._eventListeners.indexOf(listener);
|
|
976
|
+
if (index !== -1) {
|
|
977
|
+
this._eventListeners.splice(index, 1);
|
|
978
|
+
}
|
|
979
|
+
};
|
|
980
|
+
}
|
|
981
|
+
/** Disconnect from agent events during disposal. */
|
|
982
|
+
_disconnectFromAgent() {
|
|
983
|
+
if (this._unsubscribeAgent) {
|
|
984
|
+
this._unsubscribeAgent();
|
|
985
|
+
this._unsubscribeAgent = undefined;
|
|
986
|
+
}
|
|
987
|
+
}
|
|
988
|
+
/**
|
|
989
|
+
* Remove all listeners and disconnect from agent.
|
|
990
|
+
* Call this when completely done with the session.
|
|
991
|
+
*/
|
|
992
|
+
dispose() {
|
|
993
|
+
try {
|
|
994
|
+
this.abortRetry();
|
|
995
|
+
this.abortCompaction();
|
|
996
|
+
this.abortBranchSummary();
|
|
997
|
+
this.abortBash();
|
|
998
|
+
this.agent.abort();
|
|
999
|
+
}
|
|
1000
|
+
catch {
|
|
1001
|
+
// Dispose must succeed even if an abort hook throws.
|
|
1002
|
+
}
|
|
1003
|
+
this._extensionRunner.invalidate("This extension ctx is stale after session replacement or reload. Do not use a captured relay 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().");
|
|
1004
|
+
this._disconnectFromAgent();
|
|
1005
|
+
this._harnessCore.dispose();
|
|
1006
|
+
this._eventListeners = [];
|
|
1007
|
+
if (this._cacheWarmer) {
|
|
1008
|
+
this._cacheWarmer.onWarmed = undefined;
|
|
1009
|
+
this._cacheWarmer.cancel();
|
|
1010
|
+
}
|
|
1011
|
+
cleanupSessionResources(this.sessionId);
|
|
1012
|
+
}
|
|
1013
|
+
// =========================================================================
|
|
1014
|
+
// Read-only State Access
|
|
1015
|
+
// =========================================================================
|
|
1016
|
+
/** Refresh the public finalized transcript from the canonical session projection. */
|
|
1017
|
+
refreshContext() {
|
|
1018
|
+
this._refreshFinalizedContext();
|
|
1019
|
+
}
|
|
1020
|
+
/** Full agent state */
|
|
1021
|
+
get state() {
|
|
1022
|
+
return this.agent.state;
|
|
1023
|
+
}
|
|
1024
|
+
/** Current cache-warming state and the policy inputs that produced it. */
|
|
1025
|
+
get cacheWarmingStatus() {
|
|
1026
|
+
return this._cacheWarmer?.status;
|
|
1027
|
+
}
|
|
1028
|
+
/** Persist the cache-warming mode and immediately reconcile active warming. */
|
|
1029
|
+
setCacheWarmingMode(mode) {
|
|
1030
|
+
this.settingsManager.setCacheWarmingMode(mode);
|
|
1031
|
+
this._cacheWarmer?.onModeChanged();
|
|
1032
|
+
}
|
|
1033
|
+
/** Current model (may be undefined if not yet selected) */
|
|
1034
|
+
get model() {
|
|
1035
|
+
return this.agent.state.model;
|
|
1036
|
+
}
|
|
1037
|
+
/** Current thinking level */
|
|
1038
|
+
get thinkingLevel() {
|
|
1039
|
+
return this.agent.state.thinkingLevel;
|
|
1040
|
+
}
|
|
1041
|
+
/** Under a virtual selection, the physical model and thinking level of the latest successful response. */
|
|
1042
|
+
get routedModel() {
|
|
1043
|
+
if (!this.model || !isVirtualModel(this.model))
|
|
1044
|
+
return undefined;
|
|
1045
|
+
const latest = findLatestResponse(this.agent.state.messages);
|
|
1046
|
+
const model = latest && this._modelRuntime.getPhysicalModel(latest.provider, latest.model);
|
|
1047
|
+
return model && { model, thinkingLevel: latest?.thinkingLevel };
|
|
1048
|
+
}
|
|
1049
|
+
/** Whether the session is currently processing an agent run or post-run continuation. */
|
|
1050
|
+
get isStreaming() {
|
|
1051
|
+
return this._isAgentRunActive;
|
|
1052
|
+
}
|
|
1053
|
+
/** Whether the session has no active agent run, compaction, branch summary, retry, or queued continuation. */
|
|
1054
|
+
get isIdle() {
|
|
1055
|
+
return !this._isAgentRunActive && !this.isCompacting;
|
|
1056
|
+
}
|
|
1057
|
+
/** Current effective system prompt, including changes not yet sent to the model. */
|
|
1058
|
+
get systemPrompt() {
|
|
1059
|
+
return buildSystemPrompt(this._runSystemPromptOptions ?? this._baseSystemPromptOptions);
|
|
1060
|
+
}
|
|
1061
|
+
/** Current retry attempt (0 if not retrying) */
|
|
1062
|
+
get retryAttempt() {
|
|
1063
|
+
return this._retryAttempt;
|
|
1064
|
+
}
|
|
1065
|
+
/**
|
|
1066
|
+
* Get the names of currently active tools, which are the tools declared to the model.
|
|
1067
|
+
* Tools with `codemode` or `deferred` exposure are callable from other tools without being active.
|
|
1068
|
+
*/
|
|
1069
|
+
getActiveToolNames() {
|
|
1070
|
+
return this.agent.state.tools.map((t) => t.name);
|
|
1071
|
+
}
|
|
1072
|
+
/** Get the names of the tools that tools can call through `ctx.executeTool()`. */
|
|
1073
|
+
getCallableToolNames() {
|
|
1074
|
+
return this._getCallableTools().map((t) => t.name);
|
|
1075
|
+
}
|
|
1076
|
+
/**
|
|
1077
|
+
* Get all configured tools with name, description, parameter schema, prompt guidelines, and source metadata.
|
|
1078
|
+
*/
|
|
1079
|
+
getAllTools() {
|
|
1080
|
+
return Array.from(this._toolDefinitions.values()).map(({ definition, sourceInfo }) => ({
|
|
1081
|
+
name: definition.name,
|
|
1082
|
+
description: definition.description,
|
|
1083
|
+
parameters: definition.parameters,
|
|
1084
|
+
promptGuidelines: definition.promptGuidelines,
|
|
1085
|
+
exposure: this._getToolExposure(definition.name),
|
|
1086
|
+
...(definition.namespace ? { namespace: definition.namespace } : {}),
|
|
1087
|
+
...(definition.annotations ? { annotations: { ...definition.annotations } } : {}),
|
|
1088
|
+
sourceInfo,
|
|
1089
|
+
}));
|
|
1090
|
+
}
|
|
1091
|
+
getToolDefinition(name) {
|
|
1092
|
+
return this._toolDefinitions.get(name)?.definition;
|
|
1093
|
+
}
|
|
1094
|
+
/**
|
|
1095
|
+
* Set active tools by name.
|
|
1096
|
+
* Only tools in the registry can be enabled. Unknown and hidden tool names are ignored.
|
|
1097
|
+
* Also rebuilds the system prompt to reflect the new tool set.
|
|
1098
|
+
* Changes take effect on the next agent turn.
|
|
1099
|
+
*/
|
|
1100
|
+
setActiveToolsByName(toolNames) {
|
|
1101
|
+
const previous = this.getActiveToolNames();
|
|
1102
|
+
this._setActiveTools(toolNames);
|
|
1103
|
+
// A loadout that deactivates a tool replaces the restored one, whose pending tools are dropped.
|
|
1104
|
+
// One that only adds tools, like activating tool_search, keeps them.
|
|
1105
|
+
const active = new Set(this.getActiveToolNames());
|
|
1106
|
+
if (previous.some((name) => !active.has(name)))
|
|
1107
|
+
this._pendingToolNames.clear();
|
|
1108
|
+
}
|
|
1109
|
+
_setActiveTools(toolNames) {
|
|
1110
|
+
const tools = this._applyToolLoadout(toolNames);
|
|
1111
|
+
for (const tool of tools)
|
|
1112
|
+
this._pendingToolNames.delete(tool.name);
|
|
1113
|
+
this._rebuildSystemPrompt(tools.map((tool) => tool.name));
|
|
1114
|
+
}
|
|
1115
|
+
_isAllowedTool(name) {
|
|
1116
|
+
return (!this._allowedToolNames || this._allowedToolNames.has(name)) && !this._excludedToolNames?.has(name);
|
|
1117
|
+
}
|
|
1118
|
+
_getToolExposure(name) {
|
|
1119
|
+
return this._toolDefinitions.get(name)?.definition.exposure ?? "direct";
|
|
1120
|
+
}
|
|
1121
|
+
/**
|
|
1122
|
+
* Tools callable through `ctx.executeTool()`: the active `direct` tools and every registered
|
|
1123
|
+
* `codemode` or `deferred` tool.
|
|
1124
|
+
*/
|
|
1125
|
+
_getCallableTools(active = new Set(this.getActiveToolNames())) {
|
|
1126
|
+
return [...this._toolRegistry.values()].filter((tool) => {
|
|
1127
|
+
const exposure = this._getToolExposure(tool.name);
|
|
1128
|
+
return exposure === "codemode" || exposure === "deferred" || (exposure === "direct" && active.has(tool.name));
|
|
1129
|
+
});
|
|
1130
|
+
}
|
|
1131
|
+
/**
|
|
1132
|
+
* Set the agent's tools for the given active tool names and return them. The active tools are
|
|
1133
|
+
* the registered, non-hidden ones; they are declared to the model. Active tools with a
|
|
1134
|
+
* `prepareLoadout` hook can change the declared descriptions and hide declarations from
|
|
1135
|
+
* requests (see {@link _installHiddenDeclarationsProjection}).
|
|
1136
|
+
*/
|
|
1137
|
+
_applyToolLoadout(toolNames) {
|
|
1138
|
+
const tools = [...new Set(toolNames)].flatMap((name) => {
|
|
1139
|
+
const tool = this._toolRegistry.get(name);
|
|
1140
|
+
return tool && this._getToolExposure(name) !== "hidden" ? [tool] : [];
|
|
1141
|
+
});
|
|
1142
|
+
const hooks = tools.flatMap((tool) => {
|
|
1143
|
+
const entry = this._toolDefinitions.get(tool.name);
|
|
1144
|
+
return entry?.definition.prepareLoadout ? [entry] : [];
|
|
1145
|
+
});
|
|
1146
|
+
const hidden = new Set();
|
|
1147
|
+
let declared = tools;
|
|
1148
|
+
if (hooks.length > 0) {
|
|
1149
|
+
const loadout = {
|
|
1150
|
+
declared: tools,
|
|
1151
|
+
callable: this._getCallableTools(new Set(tools.map((tool) => tool.name))),
|
|
1152
|
+
registered: [...this._toolRegistry.values()],
|
|
1153
|
+
getExposure: (name) => this._getToolExposure(name),
|
|
1154
|
+
getNamespace: (name) => this._toolDefinitions.get(name)?.definition.namespace,
|
|
1155
|
+
};
|
|
1156
|
+
const descriptions = new Map();
|
|
1157
|
+
for (const { definition, sourceInfo } of hooks) {
|
|
1158
|
+
try {
|
|
1159
|
+
const changes = definition.prepareLoadout?.(loadout);
|
|
1160
|
+
for (const [name, description] of Object.entries(changes?.descriptions ?? {})) {
|
|
1161
|
+
descriptions.set(name, description);
|
|
1162
|
+
}
|
|
1163
|
+
for (const name of changes?.hiddenDeclarations ?? [])
|
|
1164
|
+
hidden.add(name);
|
|
1165
|
+
}
|
|
1166
|
+
catch (error) {
|
|
1167
|
+
this._extensionRunner.emitError({
|
|
1168
|
+
extensionPath: sourceInfo.path,
|
|
1169
|
+
event: "prepare_loadout",
|
|
1170
|
+
error: error instanceof Error ? error.message : String(error),
|
|
1171
|
+
stack: error instanceof Error ? error.stack : undefined,
|
|
1172
|
+
});
|
|
1173
|
+
}
|
|
1174
|
+
}
|
|
1175
|
+
declared = tools.map((tool) => {
|
|
1176
|
+
const description = descriptions.get(tool.name);
|
|
1177
|
+
return description === undefined ? tool : { ...tool, description };
|
|
1178
|
+
});
|
|
1179
|
+
}
|
|
1180
|
+
this._hiddenDeclarations = hidden;
|
|
1181
|
+
this.agent.state.tools = declared;
|
|
1182
|
+
return declared;
|
|
1183
|
+
}
|
|
1184
|
+
/** Whether compaction or branch summarization is currently running */
|
|
1185
|
+
get isCompacting() {
|
|
1186
|
+
return (this._autoCompactionAbortController !== undefined ||
|
|
1187
|
+
this._compactionAbortController !== undefined ||
|
|
1188
|
+
this._branchSummaryAbortController !== undefined);
|
|
1189
|
+
}
|
|
1190
|
+
/** All messages including custom types like BashExecutionMessage */
|
|
1191
|
+
get messages() {
|
|
1192
|
+
return this.agent.state.messages;
|
|
1193
|
+
}
|
|
1194
|
+
/** Current steering mode */
|
|
1195
|
+
get steeringMode() {
|
|
1196
|
+
return this.agent.steeringMode;
|
|
1197
|
+
}
|
|
1198
|
+
/** Current follow-up mode */
|
|
1199
|
+
get followUpMode() {
|
|
1200
|
+
return this.agent.followUpMode;
|
|
1201
|
+
}
|
|
1202
|
+
/** Current session file path, or undefined if sessions are disabled */
|
|
1203
|
+
get sessionFile() {
|
|
1204
|
+
return this.sessionManager.getSessionFile();
|
|
1205
|
+
}
|
|
1206
|
+
/** Current session ID */
|
|
1207
|
+
get sessionId() {
|
|
1208
|
+
return this.sessionManager.getSessionId();
|
|
1209
|
+
}
|
|
1210
|
+
/** Current session display name, if set */
|
|
1211
|
+
get sessionName() {
|
|
1212
|
+
return this.sessionManager.getSessionName();
|
|
1213
|
+
}
|
|
1214
|
+
/** Scoped models for cycling (from --models flag) */
|
|
1215
|
+
get scopedModels() {
|
|
1216
|
+
return this._scopedModels;
|
|
1217
|
+
}
|
|
1218
|
+
/** Update scoped models for cycling */
|
|
1219
|
+
setScopedModels(scopedModels) {
|
|
1220
|
+
this._scopedModels = scopedModels;
|
|
1221
|
+
}
|
|
1222
|
+
/** File-based prompt templates */
|
|
1223
|
+
get promptTemplates() {
|
|
1224
|
+
return this._resourceLoader.getPrompts().prompts;
|
|
1225
|
+
}
|
|
1226
|
+
_normalizePromptSnippet(text) {
|
|
1227
|
+
if (!text)
|
|
1228
|
+
return undefined;
|
|
1229
|
+
const oneLine = text
|
|
1230
|
+
.replace(/[\r\n]+/g, " ")
|
|
1231
|
+
.replace(/\s+/g, " ")
|
|
1232
|
+
.trim();
|
|
1233
|
+
return oneLine.length > 0 ? oneLine : undefined;
|
|
1234
|
+
}
|
|
1235
|
+
_normalizePromptGuidelines(guidelines) {
|
|
1236
|
+
if (!guidelines || guidelines.length === 0) {
|
|
1237
|
+
return [];
|
|
1238
|
+
}
|
|
1239
|
+
const unique = new Set();
|
|
1240
|
+
for (const guideline of guidelines) {
|
|
1241
|
+
const normalized = guideline.trim();
|
|
1242
|
+
if (normalized.length > 0) {
|
|
1243
|
+
unique.add(normalized);
|
|
1244
|
+
}
|
|
1245
|
+
}
|
|
1246
|
+
return Array.from(unique);
|
|
1247
|
+
}
|
|
1248
|
+
_rebuildSystemPrompt(toolNames) {
|
|
1249
|
+
const validToolNames = toolNames.filter((name) => this._toolRegistry.has(name));
|
|
1250
|
+
const toolSnippets = {};
|
|
1251
|
+
for (const name of this._toolRegistry.keys()) {
|
|
1252
|
+
const snippet = this._toolPromptSnippets.get(name);
|
|
1253
|
+
// Tools without a snippet are not listed. Hidden tools are only callable through another tool.
|
|
1254
|
+
if (snippet && !this._hiddenDeclarations.has(name))
|
|
1255
|
+
toolSnippets[name] = snippet;
|
|
1256
|
+
}
|
|
1257
|
+
const loaderSystemPrompt = this._resourceLoader.getSystemPrompt();
|
|
1258
|
+
const loaderAppendSystemPrompt = this._resourceLoader.getAppendSystemPrompt();
|
|
1259
|
+
const appendSystemPrompt = loaderAppendSystemPrompt.length > 0 ? loaderAppendSystemPrompt.join("\n\n") : "";
|
|
1260
|
+
const loadedSkills = this._resourceLoader.getSkills().skills;
|
|
1261
|
+
const loadedContextFiles = this._resourceLoader.getAgentsFiles().agentsFiles;
|
|
1262
|
+
this._baseSystemPromptOptions = normalizeBuildSystemPromptOptions({
|
|
1263
|
+
cwd: this._cwd,
|
|
1264
|
+
skills: loadedSkills,
|
|
1265
|
+
contextFiles: loadedContextFiles,
|
|
1266
|
+
customPrompt: loaderSystemPrompt,
|
|
1267
|
+
appendSystemPrompt,
|
|
1268
|
+
selectedTools: validToolNames,
|
|
1269
|
+
toolSnippets,
|
|
1270
|
+
toolGuidelines: Object.fromEntries(this._toolPromptGuidelines),
|
|
1271
|
+
promptGuidelines: this._harnessCore.promptGuidelines(),
|
|
1272
|
+
});
|
|
1273
|
+
}
|
|
1274
|
+
/**
|
|
1275
|
+
* Apply a prompt and tool loadout for the next request. Sets the executable tools and
|
|
1276
|
+
* returns a system message patching the prompt sections the model currently has (replayed
|
|
1277
|
+
* from `messages`), or undefined when the prompt is unchanged. Tool changes are declared by
|
|
1278
|
+
* the agent loop before the request.
|
|
1279
|
+
*
|
|
1280
|
+
* A forced prompt does not affect the transcript: the structured sections are still diffed
|
|
1281
|
+
* and persisted, and the forced text is projected onto the request by
|
|
1282
|
+
* {@link _installAgentForcedPromptProjection}.
|
|
1283
|
+
*/
|
|
1284
|
+
_preparePromptAndToolLoadout(options, messages = this.agent.state.messages) {
|
|
1285
|
+
options.selectedTools = this._applyToolLoadout(options.selectedTools).map((tool) => tool.name);
|
|
1286
|
+
// The tool list must match the declarations the request carries, so hidden tools are not listed.
|
|
1287
|
+
options.toolSnippets = Object.fromEntries(Object.entries(options.toolSnippets).filter(([name]) => !this._hiddenDeclarations.has(name)));
|
|
1288
|
+
const sections = diffSystemPromptSections(getCurrentSystemMessage(messages)?.sections ?? {}, buildSystemPromptSections(options));
|
|
1289
|
+
return sections ? { role: "system", content: "", sections, timestamp: Date.now() } : undefined;
|
|
1290
|
+
}
|
|
1291
|
+
/**
|
|
1292
|
+
* Send a forced prompt as the provider's leading system prompt without recording it.
|
|
1293
|
+
*
|
|
1294
|
+
* A `before_agent_start` handler that returns `systemPrompt` needs that exact text at the
|
|
1295
|
+
* head of the request; a mid-conversation system message would leave the original prompt
|
|
1296
|
+
* in place. The forced text is a rendering of the current prompt, so the transcript keeps
|
|
1297
|
+
* its structured sections and the request is projected instead: the system messages
|
|
1298
|
+
* collapse into one head holding the forced text and the current tools. Runs after the
|
|
1299
|
+
* `context` extension handlers.
|
|
1300
|
+
*/
|
|
1301
|
+
/**
|
|
1302
|
+
* Remove the declarations that `prepareLoadout` hooks hide from every request. The whole
|
|
1303
|
+
* transcript is filtered with the current set, so the projected declarations stay consistent
|
|
1304
|
+
* across requests and only change when the loadout does.
|
|
1305
|
+
*/
|
|
1306
|
+
_installHiddenDeclarationsProjection() {
|
|
1307
|
+
const previousTransformContext = this.agent.transformContext;
|
|
1308
|
+
this.agent.transformContext = async (messages, signal) => {
|
|
1309
|
+
const transformed = previousTransformContext ? await previousTransformContext(messages, signal) : messages;
|
|
1310
|
+
const hidden = this._hiddenDeclarations;
|
|
1311
|
+
if (hidden.size === 0)
|
|
1312
|
+
return transformed;
|
|
1313
|
+
return transformed.map((message) => {
|
|
1314
|
+
if (message.role !== "system" || (!message.toolsAdded && !message.toolsRemoved))
|
|
1315
|
+
return message;
|
|
1316
|
+
const { toolsAdded, toolsRemoved, ...rest } = message;
|
|
1317
|
+
const added = toolsAdded?.filter((tool) => !hidden.has(tool.name)) ?? [];
|
|
1318
|
+
const removed = toolsRemoved?.filter((tool) => !hidden.has(tool.name)) ?? [];
|
|
1319
|
+
return {
|
|
1320
|
+
...rest,
|
|
1321
|
+
...(added.length > 0 ? { toolsAdded: added } : {}),
|
|
1322
|
+
...(removed.length > 0 ? { toolsRemoved: removed } : {}),
|
|
1323
|
+
};
|
|
1324
|
+
});
|
|
1325
|
+
};
|
|
1326
|
+
}
|
|
1327
|
+
_installAgentForcedPromptProjection() {
|
|
1328
|
+
const previousTransformContext = this.agent.transformContext;
|
|
1329
|
+
this.agent.transformContext = async (messages, signal) => {
|
|
1330
|
+
const transformed = previousTransformContext ? await previousTransformContext(messages, signal) : messages;
|
|
1331
|
+
const forced = this._runSystemPromptOptions?.forceSystemPrompt;
|
|
1332
|
+
if (forced === undefined)
|
|
1333
|
+
return transformed;
|
|
1334
|
+
const current = getCurrentSystemMessage(transformed);
|
|
1335
|
+
const head = {
|
|
1336
|
+
role: "system",
|
|
1337
|
+
content: forced,
|
|
1338
|
+
...(current?.toolsAdded ? { toolsAdded: current.toolsAdded } : {}),
|
|
1339
|
+
timestamp: current?.timestamp ?? Date.now(),
|
|
1340
|
+
};
|
|
1341
|
+
return [head, ...transformed.filter((message) => message.role !== "system")];
|
|
1342
|
+
};
|
|
1343
|
+
}
|
|
1344
|
+
/**
|
|
1345
|
+
* Restore the active tool loadout declared by the session transcript, if it declares one.
|
|
1346
|
+
* Tools reachable only from other tools are never declared, but they do not depend on the active
|
|
1347
|
+
* set, so the transcript's declarations are the whole loadout.
|
|
1348
|
+
*/
|
|
1349
|
+
_restoreToolsFromTranscript() {
|
|
1350
|
+
this._pendingToolNames.clear();
|
|
1351
|
+
const current = getCurrentSystemMessage(this.sessionManager.buildSessionContext().messages);
|
|
1352
|
+
if (!current)
|
|
1353
|
+
return;
|
|
1354
|
+
const names = (current.toolsAdded ?? []).map((tool) => tool.name);
|
|
1355
|
+
this._pendingToolNames = new Set(names.filter((name) => this._isAllowedTool(name)));
|
|
1356
|
+
this._setActiveTools(names);
|
|
1357
|
+
}
|
|
1358
|
+
// =========================================================================
|
|
1359
|
+
// Prompting
|
|
1360
|
+
// =========================================================================
|
|
1361
|
+
async _runAgentPrompt(messages) {
|
|
1362
|
+
this._agentRunAbortRequested = false;
|
|
1363
|
+
// Compaction before the prompt may have scheduled a retry; the new prompt replaces it.
|
|
1364
|
+
this._failedResponse = undefined;
|
|
1365
|
+
this._recordSelection();
|
|
1366
|
+
// The run records the loadout in the transcript; restored tools that did not register by now
|
|
1367
|
+
// are dropped, so a tool that never registers does not stay pending.
|
|
1368
|
+
this._pendingToolNames.clear();
|
|
1369
|
+
this._isAgentRunActive = true;
|
|
1370
|
+
try {
|
|
1371
|
+
await this.agent.prompt(messages);
|
|
1372
|
+
while (!this._agentRunAbortRequested) {
|
|
1373
|
+
if (await this._handlePostAgentRun()) {
|
|
1374
|
+
if (this._agentRunAbortRequested)
|
|
1375
|
+
break;
|
|
1376
|
+
await this.agent.continue();
|
|
1377
|
+
continue;
|
|
1378
|
+
}
|
|
1379
|
+
if (this._agentRunAbortRequested || !(await this._runBeforeSettleBoundary()))
|
|
1380
|
+
break;
|
|
1381
|
+
if (this._agentRunAbortRequested)
|
|
1382
|
+
break;
|
|
1383
|
+
await this.agent.continue();
|
|
1384
|
+
}
|
|
1385
|
+
}
|
|
1386
|
+
finally {
|
|
1387
|
+
if (this._agentRunAbortRequested)
|
|
1388
|
+
this._finishCancelledRetry();
|
|
1389
|
+
this._failedResponse = undefined;
|
|
1390
|
+
this._runSystemPromptOptions = undefined;
|
|
1391
|
+
this._flushPendingBashMessages();
|
|
1392
|
+
this._flushPendingCustomMessages();
|
|
1393
|
+
await this._emitAgentSettled();
|
|
1394
|
+
}
|
|
1395
|
+
}
|
|
1396
|
+
async _handlePostAgentRun() {
|
|
1397
|
+
const message = this._lastAssistantMessage;
|
|
1398
|
+
const toolResults = this._lastAssistantToolResults;
|
|
1399
|
+
this._lastAssistantMessage = undefined;
|
|
1400
|
+
this._lastAssistantToolResults = [];
|
|
1401
|
+
if (this._agentRunAbortRequested) {
|
|
1402
|
+
this._finishCancelledRetry();
|
|
1403
|
+
return false;
|
|
1404
|
+
}
|
|
1405
|
+
if (!message)
|
|
1406
|
+
return this.agent.hasQueuedMessages();
|
|
1407
|
+
if (this._isRetryableError(message) && (await this._prepareRetry(message))) {
|
|
1408
|
+
if (this._agentRunAbortRequested)
|
|
1409
|
+
this._finishCancelledRetry();
|
|
1410
|
+
this._failedResponse = message;
|
|
1411
|
+
return !this._agentRunAbortRequested;
|
|
1412
|
+
}
|
|
1413
|
+
if (this._agentRunAbortRequested) {
|
|
1414
|
+
this._finishCancelledRetry();
|
|
1415
|
+
return false;
|
|
1416
|
+
}
|
|
1417
|
+
if (message.stopReason === "error" && this._retryAttempt > 0) {
|
|
1418
|
+
this._emit({
|
|
1419
|
+
type: "auto_retry_end",
|
|
1420
|
+
success: false,
|
|
1421
|
+
attempt: this._retryAttempt,
|
|
1422
|
+
finalError: message.errorMessage,
|
|
1423
|
+
});
|
|
1424
|
+
this._retryAttempt = 0;
|
|
1425
|
+
}
|
|
1426
|
+
if (await this._checkCompaction(message, true, toolResults)) {
|
|
1427
|
+
return !this._agentRunAbortRequested;
|
|
1428
|
+
}
|
|
1429
|
+
// The low-level loop drains both queues before agent_end. Messages queued by
|
|
1430
|
+
// agent_end handlers require a fresh run before pre-settlement handlers fire.
|
|
1431
|
+
return !this._agentRunAbortRequested && this.agent.hasQueuedMessages();
|
|
1432
|
+
}
|
|
1433
|
+
async _runBeforeSettleBoundary() {
|
|
1434
|
+
if (!this._extensionRunner.hasHandlers("agent_before_settle"))
|
|
1435
|
+
return this.agent.hasQueuedMessages();
|
|
1436
|
+
this._isBeforeSettle = true;
|
|
1437
|
+
this._abortDuringBeforeSettle = false;
|
|
1438
|
+
try {
|
|
1439
|
+
const result = await this._extensionRunner.emitBoundary({ type: "agent_before_settle", outcome: this._lastActivityOutcome }, (entries) => this._buildBoundaryContext(entries, "agent_before_settle"));
|
|
1440
|
+
this._commitBoundaryDrafts(result.entries);
|
|
1441
|
+
this._flushPendingCustomMessages();
|
|
1442
|
+
const finalContext = this._buildBoundaryContext([], "agent_before_settle");
|
|
1443
|
+
if (this._abortDuringBeforeSettle)
|
|
1444
|
+
return false;
|
|
1445
|
+
const shouldContinue = result.continue || this.agent.hasQueuedMessages();
|
|
1446
|
+
if (shouldContinue && !finalContext.canContinue) {
|
|
1447
|
+
if (result.continue)
|
|
1448
|
+
this._reportInvalidBoundaryContinuation("agent_before_settle");
|
|
1449
|
+
return false;
|
|
1450
|
+
}
|
|
1451
|
+
return shouldContinue;
|
|
1452
|
+
}
|
|
1453
|
+
finally {
|
|
1454
|
+
this._isBeforeSettle = false;
|
|
1455
|
+
}
|
|
1456
|
+
}
|
|
1457
|
+
async _runInputHandlers(text, images, source, streamingBehavior) {
|
|
1458
|
+
if (!this._extensionRunner.hasHandlers("input")) {
|
|
1459
|
+
return { text, images };
|
|
1460
|
+
}
|
|
1461
|
+
const inputResult = await this._extensionRunner.emitInput(text, images, source, streamingBehavior);
|
|
1462
|
+
if (inputResult.action === "handled") {
|
|
1463
|
+
return undefined;
|
|
1464
|
+
}
|
|
1465
|
+
if (inputResult.action === "transform") {
|
|
1466
|
+
return { text: inputResult.text, images: inputResult.images ?? images };
|
|
1467
|
+
}
|
|
1468
|
+
return { text, images };
|
|
1469
|
+
}
|
|
1470
|
+
async _normalizePromptImages(images) {
|
|
1471
|
+
if (!images)
|
|
1472
|
+
return { images: [], hints: [] };
|
|
1473
|
+
const normalizedImages = [];
|
|
1474
|
+
const hints = [];
|
|
1475
|
+
for (const image of images) {
|
|
1476
|
+
const processed = await processImage(Buffer.from(image.data, "base64"), image.mimeType, {
|
|
1477
|
+
autoResizeImages: this.settingsManager.getImageAutoResize(),
|
|
1478
|
+
resizeOptions: this._limitsModel()?.inputLimits?.images?.resize,
|
|
1479
|
+
});
|
|
1480
|
+
if (!processed.ok) {
|
|
1481
|
+
hints.push(processed.message);
|
|
1482
|
+
continue;
|
|
1483
|
+
}
|
|
1484
|
+
normalizedImages.push({ type: "image", data: processed.data, mimeType: processed.mimeType });
|
|
1485
|
+
hints.push(...processed.hints);
|
|
1486
|
+
}
|
|
1487
|
+
return { images: normalizedImages, hints };
|
|
1488
|
+
}
|
|
1489
|
+
/**
|
|
1490
|
+
* Send a prompt to the agent.
|
|
1491
|
+
* - Handles extension commands (registered via relay.registerCommand) immediately, even during streaming
|
|
1492
|
+
* - Expands file-based prompt templates by default
|
|
1493
|
+
* - During streaming, queues via steer() or followUp() based on streamingBehavior option
|
|
1494
|
+
* - Validates model and API key before sending (when not streaming)
|
|
1495
|
+
* @throws Error if streaming and no streamingBehavior specified
|
|
1496
|
+
* @throws Error if no model selected or no API key available (when not streaming)
|
|
1497
|
+
*/
|
|
1498
|
+
async prompt(text, options) {
|
|
1499
|
+
if (this._isEmittingAgentSettled) {
|
|
1500
|
+
this._deferredSettledActions.push(async () => await this.prompt(text, options));
|
|
1501
|
+
return;
|
|
1502
|
+
}
|
|
1503
|
+
const expandPromptTemplates = options?.expandPromptTemplates ?? true;
|
|
1504
|
+
const preflightResult = options?.preflightResult;
|
|
1505
|
+
// Handle extension commands first (execute immediately, even during streaming)
|
|
1506
|
+
// Extension commands manage their own LLM interaction via relay.sendMessage()
|
|
1507
|
+
if (expandPromptTemplates && text.startsWith("/")) {
|
|
1508
|
+
const handled = await this._tryExecuteExtensionCommand(text);
|
|
1509
|
+
if (handled) {
|
|
1510
|
+
// Extension command executed, no prompt to send
|
|
1511
|
+
preflightResult?.("handled");
|
|
1512
|
+
return;
|
|
1513
|
+
}
|
|
1514
|
+
}
|
|
1515
|
+
if (this._compactionAbortController !== undefined) {
|
|
1516
|
+
throw new Error("Cannot submit a prompt while compaction is in progress. Wait for compaction to finish and retry.");
|
|
1517
|
+
}
|
|
1518
|
+
// Emit input event for extension interception (before skill/template expansion)
|
|
1519
|
+
const processedInput = await this._runInputHandlers(text, options?.images, options?.source ?? "interactive", this.isStreaming ? options?.streamingBehavior : undefined);
|
|
1520
|
+
if (!processedInput) {
|
|
1521
|
+
preflightResult?.("handled");
|
|
1522
|
+
return;
|
|
1523
|
+
}
|
|
1524
|
+
const { text: currentText, images: currentImages } = processedInput;
|
|
1525
|
+
// Expand skill commands (/skill:name args) and prompt templates (/template args)
|
|
1526
|
+
let expandedText = currentText;
|
|
1527
|
+
if (expandPromptTemplates) {
|
|
1528
|
+
expandedText = this._expandSkillCommand(expandedText);
|
|
1529
|
+
expandedText = expandPromptTemplate(expandedText, [...this.promptTemplates]);
|
|
1530
|
+
}
|
|
1531
|
+
// If streaming, queue via steer() or followUp() based on option
|
|
1532
|
+
if (this.isStreaming) {
|
|
1533
|
+
if (!options?.streamingBehavior) {
|
|
1534
|
+
throw new Error("Agent is already processing. Specify streamingBehavior ('steer' or 'followUp') to queue the message.");
|
|
1535
|
+
}
|
|
1536
|
+
if (options.streamingBehavior === "followUp") {
|
|
1537
|
+
await this._queueFollowUp(expandedText, currentImages);
|
|
1538
|
+
}
|
|
1539
|
+
else {
|
|
1540
|
+
await this._queueSteer(expandedText, currentImages);
|
|
1541
|
+
}
|
|
1542
|
+
preflightResult?.("queued");
|
|
1543
|
+
return;
|
|
1544
|
+
}
|
|
1545
|
+
// Flush any pending bash and custom messages before the new prompt
|
|
1546
|
+
this._flushPendingBashMessages();
|
|
1547
|
+
this._flushPendingCustomMessages();
|
|
1548
|
+
// Validate model
|
|
1549
|
+
if (!this.model) {
|
|
1550
|
+
throw new Error(formatNoModelSelectedMessage());
|
|
1551
|
+
}
|
|
1552
|
+
const hasConfiguredAuth = this._modelRuntime.hasConfiguredAuth(this.model.provider) ||
|
|
1553
|
+
(await this._modelRuntime.checkAuth(this.model.provider)) !== undefined;
|
|
1554
|
+
if (!hasConfiguredAuth) {
|
|
1555
|
+
const isOAuth = this._modelRuntime.isUsingOAuth(this.model.provider);
|
|
1556
|
+
if (isOAuth) {
|
|
1557
|
+
throw new Error(`Authentication failed for "${this.model.provider}". ` +
|
|
1558
|
+
`Credentials may have expired or network is unavailable. ` +
|
|
1559
|
+
`Run '/login ${this.model.provider}' to re-authenticate.`);
|
|
1560
|
+
}
|
|
1561
|
+
throw new Error(formatNoApiKeyFoundMessage(this.model.provider));
|
|
1562
|
+
}
|
|
1563
|
+
// Check if we need to compact before sending (catches aborted responses).
|
|
1564
|
+
// The user's new prompt is sent below, so do not call agent.continue() here.
|
|
1565
|
+
const lastAssistant = this._findLastAssistantMessage();
|
|
1566
|
+
if (lastAssistant) {
|
|
1567
|
+
await this._checkCompaction(lastAssistant, false);
|
|
1568
|
+
}
|
|
1569
|
+
// Emit before_agent_start before normalizing images so extension-driven model
|
|
1570
|
+
// selection determines the resize profile used for the request and history.
|
|
1571
|
+
const selectedToolsBefore = this._baseSystemPromptOptions.selectedTools;
|
|
1572
|
+
const result = await this._extensionRunner.emitBeforeAgentStart(expandedText, currentImages, this._baseSystemPromptOptions);
|
|
1573
|
+
// Handlers may edit event.systemPromptOptions.selectedTools or call setActiveTools(),
|
|
1574
|
+
// which updates the live loadout instead. An explicit edit wins; otherwise the live
|
|
1575
|
+
// loadout is authoritative, so a setActiveTools() call is not undone here.
|
|
1576
|
+
const handlerEditedTools = result.systemPromptOptions.selectedTools.length !== selectedToolsBefore.length ||
|
|
1577
|
+
result.systemPromptOptions.selectedTools.some((name, index) => name !== selectedToolsBefore[index]);
|
|
1578
|
+
if (!handlerEditedTools)
|
|
1579
|
+
result.systemPromptOptions.selectedTools = this.getActiveToolNames();
|
|
1580
|
+
const normalized = await this._normalizePromptImages(currentImages);
|
|
1581
|
+
const userText = normalized.hints.length > 0 ? `${expandedText}\n\n${normalized.hints.join("\n")}` : expandedText;
|
|
1582
|
+
// Build messages only after hooks and image normalization have completed.
|
|
1583
|
+
const messages = [];
|
|
1584
|
+
const userContent = [{ type: "text", text: userText }];
|
|
1585
|
+
userContent.push(...normalized.images);
|
|
1586
|
+
messages.push({
|
|
1587
|
+
role: "user",
|
|
1588
|
+
content: userContent,
|
|
1589
|
+
timestamp: Date.now(),
|
|
1590
|
+
});
|
|
1591
|
+
// Inject any pending "nextTurn" messages as context alongside the user message
|
|
1592
|
+
for (const msg of this._pendingNextTurnMessages) {
|
|
1593
|
+
messages.push(msg);
|
|
1594
|
+
}
|
|
1595
|
+
this._pendingNextTurnMessages = [];
|
|
1596
|
+
for (const msg of result.messages) {
|
|
1597
|
+
messages.push({
|
|
1598
|
+
role: "custom",
|
|
1599
|
+
customType: msg.customType,
|
|
1600
|
+
// Untyped extensions can pass null/missing content; normalize at ingestion.
|
|
1601
|
+
content: msg.content ?? [],
|
|
1602
|
+
display: msg.display,
|
|
1603
|
+
details: msg.details,
|
|
1604
|
+
timestamp: Date.now(),
|
|
1605
|
+
});
|
|
1606
|
+
}
|
|
1607
|
+
const updateMessage = this._preparePromptAndToolLoadout(result.systemPromptOptions);
|
|
1608
|
+
this._runSystemPromptOptions = result.systemPromptOptions;
|
|
1609
|
+
if (updateMessage)
|
|
1610
|
+
messages.unshift(updateMessage);
|
|
1611
|
+
preflightResult?.("started");
|
|
1612
|
+
await this._runAgentPrompt(messages);
|
|
1613
|
+
}
|
|
1614
|
+
/**
|
|
1615
|
+
* Try to execute an extension command. Returns true if command was found and executed.
|
|
1616
|
+
*/
|
|
1617
|
+
async _tryExecuteExtensionCommand(text) {
|
|
1618
|
+
// Parse command name and args
|
|
1619
|
+
const spaceIndex = text.indexOf(" ");
|
|
1620
|
+
const commandName = spaceIndex === -1 ? text.slice(1) : text.slice(1, spaceIndex);
|
|
1621
|
+
const args = spaceIndex === -1 ? "" : text.slice(spaceIndex + 1);
|
|
1622
|
+
const command = this._extensionRunner.getCommand(commandName);
|
|
1623
|
+
if (!command)
|
|
1624
|
+
return false;
|
|
1625
|
+
// Get command context from extension runner (includes session control methods)
|
|
1626
|
+
const ctx = this._extensionRunner.createCommandContext();
|
|
1627
|
+
try {
|
|
1628
|
+
await command.handler(args, ctx);
|
|
1629
|
+
return true;
|
|
1630
|
+
}
|
|
1631
|
+
catch (err) {
|
|
1632
|
+
// Emit error via extension runner
|
|
1633
|
+
this._extensionRunner.emitError({
|
|
1634
|
+
extensionPath: `command:${commandName}`,
|
|
1635
|
+
event: "command",
|
|
1636
|
+
error: err instanceof Error ? err.message : String(err),
|
|
1637
|
+
});
|
|
1638
|
+
return true;
|
|
1639
|
+
}
|
|
1640
|
+
}
|
|
1641
|
+
/**
|
|
1642
|
+
* Expand skill commands (/skill:name args) to their full content.
|
|
1643
|
+
* Returns the expanded text, or the original text if not a skill command or skill not found.
|
|
1644
|
+
* Emits errors via extension runner if file read fails.
|
|
1645
|
+
*/
|
|
1646
|
+
_expandSkillCommand(text) {
|
|
1647
|
+
if (!text.startsWith("/skill:"))
|
|
1648
|
+
return text;
|
|
1649
|
+
const spaceIndex = text.indexOf(" ");
|
|
1650
|
+
const skillName = spaceIndex === -1 ? text.slice(7) : text.slice(7, spaceIndex);
|
|
1651
|
+
const args = spaceIndex === -1 ? "" : text.slice(spaceIndex + 1).trim();
|
|
1652
|
+
const skill = this.resourceLoader.getSkills().skills.find((s) => s.name === skillName);
|
|
1653
|
+
if (!skill)
|
|
1654
|
+
return text; // Unknown skill, pass through
|
|
1655
|
+
try {
|
|
1656
|
+
const content = readFileSync(skill.filePath, "utf-8");
|
|
1657
|
+
const body = stripFrontmatter(content).trim();
|
|
1658
|
+
const skillBlock = `<skill name="${skill.name}" location="${skill.filePath}">\nReferences are relative to ${skill.baseDir}.\n\n${body}\n</skill>`;
|
|
1659
|
+
return args ? `${skillBlock}\n\n${args}` : skillBlock;
|
|
1660
|
+
}
|
|
1661
|
+
catch (err) {
|
|
1662
|
+
// Emit error like extension commands do
|
|
1663
|
+
this._extensionRunner.emitError({
|
|
1664
|
+
extensionPath: skill.filePath,
|
|
1665
|
+
event: "skill_expansion",
|
|
1666
|
+
error: err instanceof Error ? err.message : String(err),
|
|
1667
|
+
});
|
|
1668
|
+
return text; // Return original on error
|
|
1669
|
+
}
|
|
1670
|
+
}
|
|
1671
|
+
async _queueUserInput(text, images, behavior, source) {
|
|
1672
|
+
if (text.startsWith("/")) {
|
|
1673
|
+
this._throwIfExtensionCommand(text);
|
|
1674
|
+
}
|
|
1675
|
+
const processedInput = await this._runInputHandlers(text, images, source, this.isStreaming ? behavior : undefined);
|
|
1676
|
+
if (!processedInput)
|
|
1677
|
+
return "handled";
|
|
1678
|
+
let expandedText = this._expandSkillCommand(processedInput.text);
|
|
1679
|
+
expandedText = expandPromptTemplate(expandedText, [...this.promptTemplates]);
|
|
1680
|
+
if (behavior === "steer") {
|
|
1681
|
+
await this._queueSteer(expandedText, processedInput.images);
|
|
1682
|
+
}
|
|
1683
|
+
else {
|
|
1684
|
+
await this._queueFollowUp(expandedText, processedInput.images);
|
|
1685
|
+
}
|
|
1686
|
+
return "queued";
|
|
1687
|
+
}
|
|
1688
|
+
/**
|
|
1689
|
+
* Queue a steering message while the agent is running.
|
|
1690
|
+
* Delivered after the current assistant turn finishes executing its tool calls,
|
|
1691
|
+
* before the next LLM call.
|
|
1692
|
+
* Expands skill commands and prompt templates. Errors on extension commands.
|
|
1693
|
+
* @param images Optional image attachments to include with the message
|
|
1694
|
+
* @param options Input source; defaults to interactive
|
|
1695
|
+
* @throws Error if text is an extension command
|
|
1696
|
+
*/
|
|
1697
|
+
async steer(text, images, options) {
|
|
1698
|
+
return this._queueUserInput(text, images, "steer", options?.source ?? "interactive");
|
|
1699
|
+
}
|
|
1700
|
+
/**
|
|
1701
|
+
* Queue a follow-up message to be processed after the agent finishes.
|
|
1702
|
+
* Delivered only when agent has no more tool calls or steering messages.
|
|
1703
|
+
* Expands skill commands and prompt templates. Errors on extension commands.
|
|
1704
|
+
* @param images Optional image attachments to include with the message
|
|
1705
|
+
* @param options Input source; defaults to interactive
|
|
1706
|
+
* @throws Error if text is an extension command
|
|
1707
|
+
*/
|
|
1708
|
+
async followUp(text, images, options) {
|
|
1709
|
+
return this._queueUserInput(text, images, "followUp", options?.source ?? "interactive");
|
|
1710
|
+
}
|
|
1711
|
+
/**
|
|
1712
|
+
* Internal: Queue a steering message (already expanded, no extension command check).
|
|
1713
|
+
*/
|
|
1714
|
+
async _queueSteer(text, images) {
|
|
1715
|
+
this._steeringMessages.push(text);
|
|
1716
|
+
this._emitQueueUpdate();
|
|
1717
|
+
const content = [{ type: "text", text }];
|
|
1718
|
+
if (images) {
|
|
1719
|
+
content.push(...images);
|
|
1720
|
+
}
|
|
1721
|
+
this.agent.steer({
|
|
1722
|
+
role: "user",
|
|
1723
|
+
content,
|
|
1724
|
+
timestamp: Date.now(),
|
|
1725
|
+
});
|
|
1726
|
+
}
|
|
1727
|
+
/**
|
|
1728
|
+
* Internal: Queue a follow-up message (already expanded, no extension command check).
|
|
1729
|
+
*/
|
|
1730
|
+
async _queueFollowUp(text, images) {
|
|
1731
|
+
this._followUpMessages.push(text);
|
|
1732
|
+
this._emitQueueUpdate();
|
|
1733
|
+
const content = [{ type: "text", text }];
|
|
1734
|
+
if (images) {
|
|
1735
|
+
content.push(...images);
|
|
1736
|
+
}
|
|
1737
|
+
this.agent.followUp({ role: "user", content, timestamp: Date.now() });
|
|
1738
|
+
}
|
|
1739
|
+
/**
|
|
1740
|
+
* Throw an error if the text is an extension command.
|
|
1741
|
+
*/
|
|
1742
|
+
_throwIfExtensionCommand(text) {
|
|
1743
|
+
const spaceIndex = text.indexOf(" ");
|
|
1744
|
+
const commandName = spaceIndex === -1 ? text.slice(1) : text.slice(1, spaceIndex);
|
|
1745
|
+
const command = this._extensionRunner.getCommand(commandName);
|
|
1746
|
+
if (command) {
|
|
1747
|
+
throw new Error(`Extension command "/${commandName}" cannot be queued. Use prompt() or execute the command when not streaming.`);
|
|
1748
|
+
}
|
|
1749
|
+
}
|
|
1750
|
+
/**
|
|
1751
|
+
* Send a custom message to the session. Creates a CustomMessageEntry.
|
|
1752
|
+
*
|
|
1753
|
+
* Handles four cases:
|
|
1754
|
+
* - Streaming: queues message, processed when loop pulls from queue
|
|
1755
|
+
* - Streaming + triggerTurn false: appended to state/session once the current turn ends
|
|
1756
|
+
* - Not streaming + triggerTurn: appends to state/session, starts new turn
|
|
1757
|
+
* - Not streaming + no trigger: appends to state/session, no turn
|
|
1758
|
+
*
|
|
1759
|
+
* @param message Custom message with customType, content, display, details
|
|
1760
|
+
* @param options.triggerTurn If true and not streaming, triggers a new LLM turn
|
|
1761
|
+
* @param options.deliverAs Delivery mode: "steer", "followUp", or "nextTurn"
|
|
1762
|
+
*/
|
|
1763
|
+
async sendCustomMessage(message, options) {
|
|
1764
|
+
const appMessage = {
|
|
1765
|
+
role: "custom",
|
|
1766
|
+
customType: message.customType,
|
|
1767
|
+
// Untyped extensions can pass null/missing content; normalize at ingestion.
|
|
1768
|
+
content: message.content ?? [],
|
|
1769
|
+
display: message.display,
|
|
1770
|
+
details: message.details,
|
|
1771
|
+
timestamp: Date.now(),
|
|
1772
|
+
};
|
|
1773
|
+
if (options?.deliverAs === "nextTurn") {
|
|
1774
|
+
this._pendingNextTurnMessages.push(appMessage);
|
|
1775
|
+
}
|
|
1776
|
+
else if (this.isStreaming && options?.triggerTurn !== false) {
|
|
1777
|
+
if (options?.deliverAs === "followUp") {
|
|
1778
|
+
this.agent.followUp(appMessage);
|
|
1779
|
+
}
|
|
1780
|
+
else {
|
|
1781
|
+
this.agent.steer(appMessage);
|
|
1782
|
+
}
|
|
1783
|
+
}
|
|
1784
|
+
else if (options?.triggerTurn) {
|
|
1785
|
+
if (this._isEmittingAgentSettled) {
|
|
1786
|
+
this._deferredSettledActions.push(async () => await this._runAgentPrompt(appMessage));
|
|
1787
|
+
return;
|
|
1788
|
+
}
|
|
1789
|
+
await this._runAgentPrompt(appMessage);
|
|
1790
|
+
}
|
|
1791
|
+
else if (this.isStreaming) {
|
|
1792
|
+
// Appending now would put the message between an assistant tool call and its
|
|
1793
|
+
// result, which providers that validate message order reject on replay. Defer
|
|
1794
|
+
// to the end of the turn. Nothing is emitted yet: message events must not
|
|
1795
|
+
// describe messages the session tree does not contain.
|
|
1796
|
+
this._pendingCustomMessages.push(appMessage);
|
|
1797
|
+
}
|
|
1798
|
+
else {
|
|
1799
|
+
this._appendCustomMessage(appMessage);
|
|
1800
|
+
}
|
|
1801
|
+
}
|
|
1802
|
+
_appendCustomMessage(appMessage) {
|
|
1803
|
+
this.sessionManager.appendCustomMessageEntry(appMessage.customType, appMessage.content, appMessage.display, appMessage.details);
|
|
1804
|
+
this._refreshFinalizedContext();
|
|
1805
|
+
this._emit({ type: "message_start", message: appMessage });
|
|
1806
|
+
this._emit({ type: "message_end", message: appMessage });
|
|
1807
|
+
}
|
|
1808
|
+
/**
|
|
1809
|
+
* Append custom messages queued while the agent was running.
|
|
1810
|
+
* Called once the current turn's tool results are in agent state and session history.
|
|
1811
|
+
*/
|
|
1812
|
+
_flushPendingCustomMessages() {
|
|
1813
|
+
if (this._pendingCustomMessages.length === 0)
|
|
1814
|
+
return;
|
|
1815
|
+
const pending = this._pendingCustomMessages;
|
|
1816
|
+
this._pendingCustomMessages = [];
|
|
1817
|
+
for (const appMessage of pending) {
|
|
1818
|
+
this._appendCustomMessage(appMessage);
|
|
1819
|
+
}
|
|
1820
|
+
}
|
|
1821
|
+
/**
|
|
1822
|
+
* Send a user message to the agent. Always triggers a turn.
|
|
1823
|
+
* When the agent is streaming, use deliverAs to specify how to queue the message.
|
|
1824
|
+
*
|
|
1825
|
+
* @param content User message content (string or content array)
|
|
1826
|
+
* @param options.deliverAs Delivery mode when streaming: "steer" or "followUp"
|
|
1827
|
+
* @param options.expandPromptTemplates Whether to dispatch extension commands and expand skill commands and prompt templates. Default: false.
|
|
1828
|
+
*/
|
|
1829
|
+
async sendUserMessage(content, options) {
|
|
1830
|
+
// Normalize content to text string + optional images
|
|
1831
|
+
let text;
|
|
1832
|
+
let images;
|
|
1833
|
+
if (typeof content === "string") {
|
|
1834
|
+
text = content;
|
|
1835
|
+
}
|
|
1836
|
+
else {
|
|
1837
|
+
const textParts = [];
|
|
1838
|
+
images = [];
|
|
1839
|
+
for (const part of content) {
|
|
1840
|
+
if (part.type === "text") {
|
|
1841
|
+
textParts.push(part.text);
|
|
1842
|
+
}
|
|
1843
|
+
else {
|
|
1844
|
+
images.push(part);
|
|
1845
|
+
}
|
|
1846
|
+
}
|
|
1847
|
+
text = textParts.join("\n");
|
|
1848
|
+
if (images.length === 0)
|
|
1849
|
+
images = undefined;
|
|
1850
|
+
}
|
|
1851
|
+
await this.prompt(text, {
|
|
1852
|
+
expandPromptTemplates: options?.expandPromptTemplates ?? false,
|
|
1853
|
+
streamingBehavior: options?.deliverAs,
|
|
1854
|
+
images,
|
|
1855
|
+
source: "extension",
|
|
1856
|
+
});
|
|
1857
|
+
}
|
|
1858
|
+
/**
|
|
1859
|
+
* Clear all queued messages and return them.
|
|
1860
|
+
* Useful for restoring to editor when user aborts.
|
|
1861
|
+
* @returns Object with steering and followUp arrays
|
|
1862
|
+
*/
|
|
1863
|
+
clearQueue() {
|
|
1864
|
+
const steering = [...this._steeringMessages];
|
|
1865
|
+
const followUp = [...this._followUpMessages];
|
|
1866
|
+
this._steeringMessages = [];
|
|
1867
|
+
this._followUpMessages = [];
|
|
1868
|
+
this.agent.clearAllQueues();
|
|
1869
|
+
this._emitQueueUpdate();
|
|
1870
|
+
return { steering, followUp };
|
|
1871
|
+
}
|
|
1872
|
+
/** Number of pending messages (includes both steering and follow-up) */
|
|
1873
|
+
get pendingMessageCount() {
|
|
1874
|
+
return this._steeringMessages.length + this._followUpMessages.length;
|
|
1875
|
+
}
|
|
1876
|
+
/** Get pending steering messages (read-only) */
|
|
1877
|
+
getSteeringMessages() {
|
|
1878
|
+
return this._steeringMessages;
|
|
1879
|
+
}
|
|
1880
|
+
/** Get pending follow-up messages (read-only) */
|
|
1881
|
+
getFollowUpMessages() {
|
|
1882
|
+
return this._followUpMessages;
|
|
1883
|
+
}
|
|
1884
|
+
get resourceLoader() {
|
|
1885
|
+
return this._resourceLoader;
|
|
1886
|
+
}
|
|
1887
|
+
/**
|
|
1888
|
+
* Abort current operation and wait for agent to become idle.
|
|
1889
|
+
*/
|
|
1890
|
+
async abort() {
|
|
1891
|
+
if (this._isAgentRunActive) {
|
|
1892
|
+
this._agentRunAbortRequested = true;
|
|
1893
|
+
}
|
|
1894
|
+
this.abortRetry();
|
|
1895
|
+
this.abortCompaction();
|
|
1896
|
+
this.abortBranchSummary();
|
|
1897
|
+
if (this._isBeforeSettle)
|
|
1898
|
+
this._abortDuringBeforeSettle = true;
|
|
1899
|
+
this.agent.abort();
|
|
1900
|
+
await this.waitForIdle();
|
|
1901
|
+
}
|
|
1902
|
+
async waitForIdle() {
|
|
1903
|
+
if (this.isIdle) {
|
|
1904
|
+
return;
|
|
1905
|
+
}
|
|
1906
|
+
await this._getIdleWaitPromise();
|
|
1907
|
+
}
|
|
1908
|
+
// =========================================================================
|
|
1909
|
+
// Model Management
|
|
1910
|
+
// =========================================================================
|
|
1911
|
+
async _emitModelSelect(nextModel, previousModel, source) {
|
|
1912
|
+
if (modelsAreEqual(previousModel, nextModel))
|
|
1913
|
+
return;
|
|
1914
|
+
await this._extensionRunner.emit({
|
|
1915
|
+
type: "model_select",
|
|
1916
|
+
model: nextModel,
|
|
1917
|
+
previousModel,
|
|
1918
|
+
source,
|
|
1919
|
+
});
|
|
1920
|
+
}
|
|
1921
|
+
/**
|
|
1922
|
+
* Set model directly.
|
|
1923
|
+
* Validates that auth is configured and saves to the session transcript.
|
|
1924
|
+
* Persists to global defaults only when options.persist is true.
|
|
1925
|
+
* @throws Error if no auth is configured for the model
|
|
1926
|
+
*/
|
|
1927
|
+
async setModel(model, options = {}) {
|
|
1928
|
+
if (!(await this._modelRuntime.checkAuth(model.provider))) {
|
|
1929
|
+
throw new Error(`No API key for ${model.provider}/${model.id}`);
|
|
1930
|
+
}
|
|
1931
|
+
const previousModel = this.model;
|
|
1932
|
+
const thinkingLevel = this._getThinkingLevelForModelSwitch(model);
|
|
1933
|
+
this.agent.state.model = model;
|
|
1934
|
+
this.sessionManager.appendModelChange(model.provider, model.id);
|
|
1935
|
+
if (options.persist) {
|
|
1936
|
+
this.settingsManager.setDefaultModelAndProvider(model.provider, model.id);
|
|
1937
|
+
this._addPersistedDefaultToNonEmptyScope(model);
|
|
1938
|
+
}
|
|
1939
|
+
// Apply thinking level for the new model.
|
|
1940
|
+
// Per-model thinking level overrides take priority over the global default.
|
|
1941
|
+
// Model persistence does not implicitly rewrite the global thinking default.
|
|
1942
|
+
this.setThinkingLevel(thinkingLevel);
|
|
1943
|
+
await this._emitModelSelect(model, previousModel, "set");
|
|
1944
|
+
}
|
|
1945
|
+
_addPersistedDefaultToNonEmptyScope(model) {
|
|
1946
|
+
if (this._scopedModels.length === 0)
|
|
1947
|
+
return;
|
|
1948
|
+
if (this._scopedModels.some((scoped) => modelsAreEqual(scoped.model, model)))
|
|
1949
|
+
return;
|
|
1950
|
+
this._scopedModels = [...this._scopedModels, { model }];
|
|
1951
|
+
const enabledModels = this.settingsManager.getEnabledModels();
|
|
1952
|
+
if (!enabledModels?.length)
|
|
1953
|
+
return;
|
|
1954
|
+
const modelReference = `${model.provider}/${model.id}`;
|
|
1955
|
+
if (enabledModels.some((pattern) => pattern.toLowerCase() === modelReference.toLowerCase()))
|
|
1956
|
+
return;
|
|
1957
|
+
this.settingsManager.setEnabledModels([...enabledModels, modelReference]);
|
|
1958
|
+
}
|
|
1959
|
+
/**
|
|
1960
|
+
* Cycle to next/previous model.
|
|
1961
|
+
* Uses scoped models (from --models flag) if available, otherwise all available models.
|
|
1962
|
+
* @param direction - "forward" (default) or "backward"
|
|
1963
|
+
* @returns The new model info, or undefined if only one model available
|
|
1964
|
+
*/
|
|
1965
|
+
async cycleModel(direction = "forward", options = {}) {
|
|
1966
|
+
if (this._scopedModels.length > 0) {
|
|
1967
|
+
return this._cycleScopedModel(direction, options);
|
|
1968
|
+
}
|
|
1969
|
+
return this._cycleAvailableModel(direction, options);
|
|
1970
|
+
}
|
|
1971
|
+
async _cycleScopedModel(direction, options) {
|
|
1972
|
+
const availableIds = new Set(this._modelRuntime.getAvailableSnapshot().map((model) => `${model.provider}\0${model.id}`));
|
|
1973
|
+
const scopedModels = this._scopedModels.filter((scoped) => availableIds.has(`${scoped.model.provider}\0${scoped.model.id}`));
|
|
1974
|
+
if (scopedModels.length <= 1)
|
|
1975
|
+
return undefined;
|
|
1976
|
+
const currentModel = this.model;
|
|
1977
|
+
let currentIndex = scopedModels.findIndex((sm) => modelsAreEqual(sm.model, currentModel));
|
|
1978
|
+
if (currentIndex === -1)
|
|
1979
|
+
currentIndex = 0;
|
|
1980
|
+
const len = scopedModels.length;
|
|
1981
|
+
const nextIndex = direction === "forward" ? (currentIndex + 1) % len : (currentIndex - 1 + len) % len;
|
|
1982
|
+
const next = scopedModels[nextIndex];
|
|
1983
|
+
const thinkingLevel = this._getThinkingLevelForModelSwitch(next.model, next.thinkingLevel);
|
|
1984
|
+
// Apply model
|
|
1985
|
+
this.agent.state.model = next.model;
|
|
1986
|
+
this.sessionManager.appendModelChange(next.model.provider, next.model.id);
|
|
1987
|
+
if (options.persist) {
|
|
1988
|
+
this.settingsManager.setDefaultModelAndProvider(next.model.provider, next.model.id);
|
|
1989
|
+
this._addPersistedDefaultToNonEmptyScope(next.model);
|
|
1990
|
+
}
|
|
1991
|
+
// Apply thinking level for the new model.
|
|
1992
|
+
// - Explicit scoped model thinking level overrides defaults
|
|
1993
|
+
// - Per-model thinking level overrides take priority over the global default
|
|
1994
|
+
// setThinkingLevel clamps to model capabilities.
|
|
1995
|
+
// Model persistence does not implicitly rewrite the global thinking default.
|
|
1996
|
+
this.setThinkingLevel(thinkingLevel);
|
|
1997
|
+
await this._emitModelSelect(next.model, currentModel, "cycle");
|
|
1998
|
+
return { model: next.model, thinkingLevel: this.thinkingLevel, isScoped: true };
|
|
1999
|
+
}
|
|
2000
|
+
async _cycleAvailableModel(direction, options) {
|
|
2001
|
+
const availableModels = this._modelRuntime.getAvailableSnapshot();
|
|
2002
|
+
if (availableModels.length <= 1)
|
|
2003
|
+
return undefined;
|
|
2004
|
+
const currentModel = this.model;
|
|
2005
|
+
let currentIndex = availableModels.findIndex((m) => modelsAreEqual(m, currentModel));
|
|
2006
|
+
if (currentIndex === -1)
|
|
2007
|
+
currentIndex = 0;
|
|
2008
|
+
const len = availableModels.length;
|
|
2009
|
+
const nextIndex = direction === "forward" ? (currentIndex + 1) % len : (currentIndex - 1 + len) % len;
|
|
2010
|
+
const nextModel = availableModels[nextIndex];
|
|
2011
|
+
const thinkingLevel = this._getThinkingLevelForModelSwitch(nextModel);
|
|
2012
|
+
this.agent.state.model = nextModel;
|
|
2013
|
+
this.sessionManager.appendModelChange(nextModel.provider, nextModel.id);
|
|
2014
|
+
if (options.persist) {
|
|
2015
|
+
this.settingsManager.setDefaultModelAndProvider(nextModel.provider, nextModel.id);
|
|
2016
|
+
this._addPersistedDefaultToNonEmptyScope(nextModel);
|
|
2017
|
+
}
|
|
2018
|
+
// Apply thinking level for the new model.
|
|
2019
|
+
// Model persistence does not implicitly rewrite the global thinking default.
|
|
2020
|
+
this.setThinkingLevel(thinkingLevel);
|
|
2021
|
+
await this._emitModelSelect(nextModel, currentModel, "cycle");
|
|
2022
|
+
return { model: nextModel, thinkingLevel: this.thinkingLevel, isScoped: false };
|
|
2023
|
+
}
|
|
2024
|
+
// =========================================================================
|
|
2025
|
+
// Thinking Level Management
|
|
2026
|
+
// =========================================================================
|
|
2027
|
+
/**
|
|
2028
|
+
* Set thinking level.
|
|
2029
|
+
* Clamps to model capabilities based on available thinking levels.
|
|
2030
|
+
* Saves the clamped level to the session transcript only if the level actually changes.
|
|
2031
|
+
* Persists the requested level to global defaults only when options.persist is true.
|
|
2032
|
+
*/
|
|
2033
|
+
setThinkingLevel(level, options = {}) {
|
|
2034
|
+
const availableLevels = this.getAvailableThinkingLevels();
|
|
2035
|
+
const effectiveLevel = availableLevels.includes(level) ? level : this._clampThinkingLevel(level, availableLevels);
|
|
2036
|
+
// Only persist if actually changing
|
|
2037
|
+
const previousLevel = this.agent.state.thinkingLevel;
|
|
2038
|
+
const isChanging = effectiveLevel !== previousLevel;
|
|
2039
|
+
this.agent.state.thinkingLevel = effectiveLevel;
|
|
2040
|
+
if (options.persist) {
|
|
2041
|
+
this.settingsManager.setDefaultThinkingLevel(level);
|
|
2042
|
+
}
|
|
2043
|
+
if (isChanging) {
|
|
2044
|
+
this.sessionManager.appendThinkingLevelChange(effectiveLevel);
|
|
2045
|
+
this._emit({ type: "thinking_level_changed", level: effectiveLevel });
|
|
2046
|
+
void this._extensionRunner.emit({
|
|
2047
|
+
type: "thinking_level_select",
|
|
2048
|
+
level: effectiveLevel,
|
|
2049
|
+
previousLevel,
|
|
2050
|
+
});
|
|
2051
|
+
}
|
|
2052
|
+
}
|
|
2053
|
+
/**
|
|
2054
|
+
* Cycle to next thinking level.
|
|
2055
|
+
* @returns New level, or undefined if model doesn't support thinking
|
|
2056
|
+
*/
|
|
2057
|
+
cycleThinkingLevel(options = {}) {
|
|
2058
|
+
if (!this.supportsThinking())
|
|
2059
|
+
return undefined;
|
|
2060
|
+
const levels = this.getAvailableThinkingLevels();
|
|
2061
|
+
const currentIndex = levels.indexOf(this.thinkingLevel);
|
|
2062
|
+
const nextIndex = (currentIndex + 1) % levels.length;
|
|
2063
|
+
const nextLevel = levels[nextIndex];
|
|
2064
|
+
this.setThinkingLevel(nextLevel, options);
|
|
2065
|
+
return nextLevel;
|
|
2066
|
+
}
|
|
2067
|
+
/**
|
|
2068
|
+
* Get available thinking levels for current model.
|
|
2069
|
+
* The provider will clamp to what the specific model supports internally.
|
|
2070
|
+
*/
|
|
2071
|
+
getAvailableThinkingLevels() {
|
|
2072
|
+
if (!this.model)
|
|
2073
|
+
return [...THINKING_LEVEL_OPTIONS];
|
|
2074
|
+
return getSupportedThinkingLevels(this.model);
|
|
2075
|
+
}
|
|
2076
|
+
/**
|
|
2077
|
+
* Check if current model supports thinking/reasoning.
|
|
2078
|
+
*/
|
|
2079
|
+
supportsThinking() {
|
|
2080
|
+
return !!this.model?.reasoning;
|
|
2081
|
+
}
|
|
2082
|
+
_getThinkingLevelForModelSwitch(targetModel, explicitLevel) {
|
|
2083
|
+
if (explicitLevel !== undefined) {
|
|
2084
|
+
return explicitLevel;
|
|
2085
|
+
}
|
|
2086
|
+
// Per-model default takes priority when switching to a model that has one
|
|
2087
|
+
if (targetModel) {
|
|
2088
|
+
const perModel = this.settingsManager.getModelThinkingLevel(targetModel.provider, targetModel.id);
|
|
2089
|
+
if (perModel !== undefined) {
|
|
2090
|
+
return perModel;
|
|
2091
|
+
}
|
|
2092
|
+
}
|
|
2093
|
+
return this.settingsManager.getDefaultThinkingLevel() ?? this.thinkingLevel ?? DEFAULT_THINKING_LEVEL;
|
|
2094
|
+
}
|
|
2095
|
+
_clampThinkingLevel(level, _availableLevels) {
|
|
2096
|
+
return this.model ? clampThinkingLevel(this.model, level) : "off";
|
|
2097
|
+
}
|
|
2098
|
+
// =========================================================================
|
|
2099
|
+
// Queue Mode Management
|
|
2100
|
+
// =========================================================================
|
|
2101
|
+
syncQueueModesFromSettings() {
|
|
2102
|
+
this.agent.steeringMode = this.settingsManager.getSteeringMode();
|
|
2103
|
+
this.agent.followUpMode = this.settingsManager.getFollowUpMode();
|
|
2104
|
+
}
|
|
2105
|
+
/**
|
|
2106
|
+
* Set steering message mode.
|
|
2107
|
+
* Saves to settings.
|
|
2108
|
+
*/
|
|
2109
|
+
setSteeringMode(mode) {
|
|
2110
|
+
this.agent.steeringMode = mode;
|
|
2111
|
+
this.settingsManager.setSteeringMode(mode);
|
|
2112
|
+
}
|
|
2113
|
+
/**
|
|
2114
|
+
* Set follow-up message mode.
|
|
2115
|
+
* Saves to settings.
|
|
2116
|
+
*/
|
|
2117
|
+
setFollowUpMode(mode) {
|
|
2118
|
+
this.agent.followUpMode = mode;
|
|
2119
|
+
this.settingsManager.setFollowUpMode(mode);
|
|
2120
|
+
}
|
|
2121
|
+
// =========================================================================
|
|
2122
|
+
// Compaction
|
|
2123
|
+
// =========================================================================
|
|
2124
|
+
/** Generate Relay's built-in compaction summary for manual and automatic compaction. */
|
|
2125
|
+
async _runDefaultCompaction(preparation, model, customInstructions, signal, reason) {
|
|
2126
|
+
// Resolve the request only when Relay summarizes itself: routing may call models or fail.
|
|
2127
|
+
const request = await this._getSummarizationRequestAuth(model, signal);
|
|
2128
|
+
return compact(preparation, request.model, request.apiKey, request.headers, customInstructions, signal, request.thinkingLevel, this.agent.streamFunction, request.env, this.settingsManager.getRetrySettings(), this._summarizationRetryCallbacks({ source: "compaction", reason }), undefined);
|
|
2129
|
+
}
|
|
2130
|
+
_clearManualCompactionState() {
|
|
2131
|
+
this._compactionAbortController = undefined;
|
|
2132
|
+
this._resolveIdleWaitIfIdle();
|
|
2133
|
+
}
|
|
2134
|
+
/**
|
|
2135
|
+
* Manually compact the session context.
|
|
2136
|
+
*
|
|
2137
|
+
* This is the manual entry point used by `/compact`, RPC, and extensions. It is
|
|
2138
|
+
* separate from automatic threshold/overflow compaction, which enters through
|
|
2139
|
+
* `_checkCompaction()` and `_runAutoCompaction()`. After preparation and the
|
|
2140
|
+
* `session_before_compact` hook, both paths call the lower-level `compact()`
|
|
2141
|
+
* function imported from `./compaction/index.ts`, unless the hook cancels or
|
|
2142
|
+
* supplies a custom result.
|
|
2143
|
+
*
|
|
2144
|
+
* Aborts the current agent operation first. Manual compaction never retries or
|
|
2145
|
+
* continues the interrupted agent turn.
|
|
2146
|
+
*
|
|
2147
|
+
* @param customInstructions Optional instructions for the compaction summary
|
|
2148
|
+
*/
|
|
2149
|
+
async compact(customInstructions) {
|
|
2150
|
+
await this.abort();
|
|
2151
|
+
this._compactionAbortController = new AbortController();
|
|
2152
|
+
this._emit({ type: "compaction_start", reason: "manual" });
|
|
2153
|
+
let fromExtension = false;
|
|
2154
|
+
let cancelledByExtension = false;
|
|
2155
|
+
try {
|
|
2156
|
+
const model = this.model;
|
|
2157
|
+
if (!model) {
|
|
2158
|
+
throw new Error(formatNoModelSelectedMessage());
|
|
2159
|
+
}
|
|
2160
|
+
const settings = this.settingsManager.getCompactionSettings(model);
|
|
2161
|
+
const pathEntries = this.sessionManager.getBranch();
|
|
2162
|
+
const preparation = prepareCompaction(pathEntries, settings);
|
|
2163
|
+
if (!preparation) {
|
|
2164
|
+
// Check why we can't compact
|
|
2165
|
+
const lastEntry = pathEntries[pathEntries.length - 1];
|
|
2166
|
+
if (lastEntry?.type === "compaction") {
|
|
2167
|
+
throw new Error("Already compacted");
|
|
2168
|
+
}
|
|
2169
|
+
throw new Error("Nothing to compact (session too small)");
|
|
2170
|
+
}
|
|
2171
|
+
let extensionCompaction;
|
|
2172
|
+
if (this._extensionRunner.hasHandlers("session_before_compact")) {
|
|
2173
|
+
const result = (await this._extensionRunner.emit({
|
|
2174
|
+
type: "session_before_compact",
|
|
2175
|
+
preparation,
|
|
2176
|
+
branchEntries: pathEntries,
|
|
2177
|
+
customInstructions,
|
|
2178
|
+
reason: "manual",
|
|
2179
|
+
willRetry: false,
|
|
2180
|
+
signal: this._compactionAbortController.signal,
|
|
2181
|
+
}));
|
|
2182
|
+
if (result?.cancel) {
|
|
2183
|
+
cancelledByExtension = true;
|
|
2184
|
+
throw new Error("Compaction cancelled");
|
|
2185
|
+
}
|
|
2186
|
+
if (result?.compaction) {
|
|
2187
|
+
extensionCompaction = result.compaction;
|
|
2188
|
+
fromExtension = true;
|
|
2189
|
+
}
|
|
2190
|
+
}
|
|
2191
|
+
let summary;
|
|
2192
|
+
let firstKeptEntryId;
|
|
2193
|
+
let tokensBefore;
|
|
2194
|
+
let usage;
|
|
2195
|
+
let details;
|
|
2196
|
+
if (extensionCompaction) {
|
|
2197
|
+
// Extension provided compaction content
|
|
2198
|
+
summary = extensionCompaction.summary;
|
|
2199
|
+
firstKeptEntryId = extensionCompaction.firstKeptEntryId;
|
|
2200
|
+
tokensBefore = extensionCompaction.tokensBefore;
|
|
2201
|
+
usage = extensionCompaction.usage;
|
|
2202
|
+
details = extensionCompaction.details;
|
|
2203
|
+
}
|
|
2204
|
+
else {
|
|
2205
|
+
// Shared default summary generator, also used by automatic compaction.
|
|
2206
|
+
const result = await this._runDefaultCompaction(preparation, model, customInstructions, this._compactionAbortController.signal, "manual");
|
|
2207
|
+
summary = result.summary;
|
|
2208
|
+
firstKeptEntryId = result.firstKeptEntryId;
|
|
2209
|
+
tokensBefore = result.tokensBefore;
|
|
2210
|
+
usage = result.usage;
|
|
2211
|
+
details = result.details;
|
|
2212
|
+
}
|
|
2213
|
+
if (this._compactionAbortController.signal.aborted) {
|
|
2214
|
+
throw new Error("Compaction cancelled");
|
|
2215
|
+
}
|
|
2216
|
+
this.sessionManager.appendCompaction(summary, firstKeptEntryId, tokensBefore, details, fromExtension, usage);
|
|
2217
|
+
const newEntries = this.sessionManager.getEntries();
|
|
2218
|
+
this._refreshFinalizedContext();
|
|
2219
|
+
const estimatedTokensAfter = estimateMessagesTokens(this.sessionManager.buildSessionProjection().messages);
|
|
2220
|
+
// Get the saved compaction entry for the extension event
|
|
2221
|
+
const savedCompactionEntry = newEntries.find((e) => e.type === "compaction" && e.summary === summary);
|
|
2222
|
+
if (this._extensionRunner && savedCompactionEntry) {
|
|
2223
|
+
await this._extensionRunner.emit({
|
|
2224
|
+
type: "session_compact",
|
|
2225
|
+
compactionEntry: savedCompactionEntry,
|
|
2226
|
+
fromExtension,
|
|
2227
|
+
reason: "manual",
|
|
2228
|
+
willRetry: false,
|
|
2229
|
+
});
|
|
2230
|
+
}
|
|
2231
|
+
const compactionResult = {
|
|
2232
|
+
summary,
|
|
2233
|
+
firstKeptEntryId,
|
|
2234
|
+
tokensBefore,
|
|
2235
|
+
estimatedTokensAfter,
|
|
2236
|
+
usage,
|
|
2237
|
+
details,
|
|
2238
|
+
};
|
|
2239
|
+
// compaction_end listeners may submit queued prompts, so expose idle state before notifying them.
|
|
2240
|
+
this._clearManualCompactionState();
|
|
2241
|
+
this._emit({
|
|
2242
|
+
type: "compaction_end",
|
|
2243
|
+
reason: "manual",
|
|
2244
|
+
result: compactionResult,
|
|
2245
|
+
aborted: false,
|
|
2246
|
+
willRetry: false,
|
|
2247
|
+
});
|
|
2248
|
+
return compactionResult;
|
|
2249
|
+
}
|
|
2250
|
+
catch (error) {
|
|
2251
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
2252
|
+
const aborted = this._compactionAbortController.signal.aborted || cancelledByExtension;
|
|
2253
|
+
const errorMessage = aborted ? undefined : `Compaction failed: ${message}`;
|
|
2254
|
+
this._clearManualCompactionState();
|
|
2255
|
+
this._emit({
|
|
2256
|
+
type: "compaction_end",
|
|
2257
|
+
reason: "manual",
|
|
2258
|
+
result: undefined,
|
|
2259
|
+
aborted,
|
|
2260
|
+
willRetry: false,
|
|
2261
|
+
errorMessage,
|
|
2262
|
+
});
|
|
2263
|
+
await this._emitSessionCompactFailed({
|
|
2264
|
+
reason: "manual",
|
|
2265
|
+
errorMessage,
|
|
2266
|
+
aborted,
|
|
2267
|
+
willRetry: false,
|
|
2268
|
+
fromExtension,
|
|
2269
|
+
});
|
|
2270
|
+
throw error;
|
|
2271
|
+
}
|
|
2272
|
+
finally {
|
|
2273
|
+
this._clearManualCompactionState();
|
|
2274
|
+
}
|
|
2275
|
+
}
|
|
2276
|
+
/**
|
|
2277
|
+
* Cancel in-progress compaction (manual or auto).
|
|
2278
|
+
*/
|
|
2279
|
+
abortCompaction() {
|
|
2280
|
+
this._compactionAbortController?.abort();
|
|
2281
|
+
this._autoCompactionAbortController?.abort();
|
|
2282
|
+
}
|
|
2283
|
+
/**
|
|
2284
|
+
* Cancel in-progress branch summarization.
|
|
2285
|
+
*/
|
|
2286
|
+
abortBranchSummary() {
|
|
2287
|
+
this._branchSummaryAbortController?.abort();
|
|
2288
|
+
}
|
|
2289
|
+
/**
|
|
2290
|
+
* Dispatch automatic compaction after `agent_end` or before prompt submission.
|
|
2291
|
+
* Manual compaction does not call this method; it enters through `compact()`.
|
|
2292
|
+
*
|
|
2293
|
+
* Automatic cases:
|
|
2294
|
+
* 1. Overflow with retry: a context-overflow error or recoverable length stop;
|
|
2295
|
+
* remove the failed assistant message, compact, and retry the turn once.
|
|
2296
|
+
* 2. Overflow without retry: a successful response exceeded the configured
|
|
2297
|
+
* context window; compact but preserve the completed response.
|
|
2298
|
+
* 3. Threshold without retry: valid or estimated context usage crossed the
|
|
2299
|
+
* configured threshold; compact without retrying the completed response.
|
|
2300
|
+
*
|
|
2301
|
+
* Each case calls `_runAutoCompaction()`. After preparation and the
|
|
2302
|
+
* `session_before_compact` hook, that method calls the lower-level `compact()`
|
|
2303
|
+
* function imported from `./compaction/index.ts`, unless the hook cancels or
|
|
2304
|
+
* supplies a custom result.
|
|
2305
|
+
*
|
|
2306
|
+
* @param assistantMessage The assistant message to check
|
|
2307
|
+
* @param skipAbortedCheck If false, include aborted messages (for pre-prompt check). Default: true
|
|
2308
|
+
* @returns Whether the post-run loop should call `agent.continue()` for overflow recovery or queued messages
|
|
2309
|
+
*/
|
|
2310
|
+
async _checkCompaction(assistantMessage, skipAbortedCheck = true, toolResults = []) {
|
|
2311
|
+
const settings = this.settingsManager.getCompactionSettings(this.model);
|
|
2312
|
+
if (!settings.enabled)
|
|
2313
|
+
return false;
|
|
2314
|
+
// Skip if message was aborted (user cancelled) - unless skipAbortedCheck is false
|
|
2315
|
+
if (skipAbortedCheck && assistantMessage.stopReason === "aborted")
|
|
2316
|
+
return false;
|
|
2317
|
+
// Skip overflow check if the message came from a different model.
|
|
2318
|
+
// This handles the case where user switched from a smaller-context model (e.g. opus)
|
|
2319
|
+
// to a larger-context model (e.g. codex) - the overflow error from the old model
|
|
2320
|
+
// shouldn't trigger compaction for the new model. Under a virtual selection, the
|
|
2321
|
+
// physical model that produced the message supplies the limits.
|
|
2322
|
+
const messageModel = this._modelForMessage(assistantMessage);
|
|
2323
|
+
const sameModel = messageModel !== undefined;
|
|
2324
|
+
const contextWindow = (messageModel ?? this.model)?.contextWindow ?? 0;
|
|
2325
|
+
// Skip compaction checks if this assistant message is older than the latest
|
|
2326
|
+
// compaction boundary. This prevents a stale pre-compaction usage/error
|
|
2327
|
+
// from retriggering compaction on the first prompt after compaction.
|
|
2328
|
+
const compactionEntry = getLatestCompactionEntry(this.sessionManager.getBranch());
|
|
2329
|
+
const assistantIsFromBeforeCompaction = compactionEntry !== null && assistantMessage.timestamp <= new Date(compactionEntry.timestamp).getTime();
|
|
2330
|
+
if (assistantIsFromBeforeCompaction) {
|
|
2331
|
+
return false;
|
|
2332
|
+
}
|
|
2333
|
+
// Automatic cases 1 and 2: context overflow.
|
|
2334
|
+
// A length stop is recoverable when output ended below the model's original desired limit,
|
|
2335
|
+
// independent of the configured context size or any context-clamped provider request limit.
|
|
2336
|
+
const currentProjection = this.sessionManager.buildSessionProjection();
|
|
2337
|
+
const assistantEntryId = this._findPersistedMessageEntryId(assistantMessage);
|
|
2338
|
+
const assistantIsProjected = assistantEntryId === undefined ||
|
|
2339
|
+
currentProjection.entries.some((entry) => entry.sourceEntry.id === assistantEntryId &&
|
|
2340
|
+
entry.messages.some((message) => message.role === "assistant"));
|
|
2341
|
+
const branch = this.sessionManager.getBranch();
|
|
2342
|
+
const assistantIndex = assistantEntryId ? branch.findIndex((entry) => entry.id === assistantEntryId) : -1;
|
|
2343
|
+
const entriesAfterAssistant = assistantIndex >= 0 ? branch.slice(assistantIndex + 1) : [];
|
|
2344
|
+
const hasPostAssistantContextEdit = entriesAfterAssistant.some((entry) => entry.type === "context_edit");
|
|
2345
|
+
const latestAssistantEdit = entriesAfterAssistant
|
|
2346
|
+
.filter((entry) => entry.type === "context_edit" && entry.targetId === assistantEntryId)
|
|
2347
|
+
.at(-1);
|
|
2348
|
+
const assistantRetainedForExplicitRecovery = assistantEntryId === undefined ||
|
|
2349
|
+
(!entriesAfterAssistant.some((entry) => entry.type === "compaction") &&
|
|
2350
|
+
latestAssistantEdit?.replacement !== null);
|
|
2351
|
+
const assistantUsageMatchesProjection = assistantIsProjected && !hasPostAssistantContextEdit;
|
|
2352
|
+
const explicitOverflow = assistantMessage.stopReason === "error" && isContextOverflow(assistantMessage);
|
|
2353
|
+
const contextOverflow = sameModel &&
|
|
2354
|
+
((explicitOverflow && assistantRetainedForExplicitRecovery) ||
|
|
2355
|
+
(assistantUsageMatchesProjection && isContextOverflow(assistantMessage, contextWindow)));
|
|
2356
|
+
const recoverableLength = sameModel && assistantIsProjected && isRecoverableLength(assistantMessage, messageModel.maxTokens);
|
|
2357
|
+
if (contextOverflow || recoverableLength) {
|
|
2358
|
+
const willRetry = assistantMessage.stopReason !== "stop";
|
|
2359
|
+
// Case 2: the response completed successfully. Compact, but do not retry because
|
|
2360
|
+
// agent.continue() cannot continue from a completed assistant response.
|
|
2361
|
+
if (!willRetry) {
|
|
2362
|
+
return await this._runAutoCompaction("overflow", false);
|
|
2363
|
+
}
|
|
2364
|
+
if (this._overflowRecoveryAttempted) {
|
|
2365
|
+
const errorMessage = contextOverflow
|
|
2366
|
+
? "Context overflow recovery failed after one compact-and-retry attempt. Try reducing context or switching to a larger-context model."
|
|
2367
|
+
: "Truncated response recovery failed after one compact-and-retry attempt.";
|
|
2368
|
+
this._emit({
|
|
2369
|
+
type: "compaction_end",
|
|
2370
|
+
reason: "overflow",
|
|
2371
|
+
result: undefined,
|
|
2372
|
+
aborted: false,
|
|
2373
|
+
willRetry: false,
|
|
2374
|
+
errorMessage,
|
|
2375
|
+
});
|
|
2376
|
+
await this._emitSessionCompactFailed({
|
|
2377
|
+
reason: "overflow",
|
|
2378
|
+
errorMessage,
|
|
2379
|
+
aborted: false,
|
|
2380
|
+
willRetry: false,
|
|
2381
|
+
fromExtension: false,
|
|
2382
|
+
});
|
|
2383
|
+
return false;
|
|
2384
|
+
}
|
|
2385
|
+
// Persistently omit the selected final attempt before post-run recovery compaction.
|
|
2386
|
+
this._overflowRecoveryAttempted = true;
|
|
2387
|
+
this._omitRecoveryAttempt(assistantMessage, toolResults);
|
|
2388
|
+
const retry = await this._runAutoCompaction("overflow", willRetry);
|
|
2389
|
+
if (retry)
|
|
2390
|
+
this._failedResponse = assistantMessage;
|
|
2391
|
+
return retry;
|
|
2392
|
+
}
|
|
2393
|
+
// Case 3: threshold compaction without retry.
|
|
2394
|
+
// For error messages or all-zero usage messages, estimate from the last valid response.
|
|
2395
|
+
// This ensures sessions that hit persistent API errors (e.g. 529) or malformed zero-usage
|
|
2396
|
+
// responses can still compact and do not reset context accounting.
|
|
2397
|
+
let contextTokens;
|
|
2398
|
+
const projection = currentProjection;
|
|
2399
|
+
const hasContextEdits = projection.entries.some((entry) => entry.sourceEntry.type === "context_edit");
|
|
2400
|
+
const directContextTokens = assistantMessage.usage ? calculateContextTokens(assistantMessage.usage) : 0;
|
|
2401
|
+
if (hasContextEdits) {
|
|
2402
|
+
contextTokens = estimateProjectedContextTokens(projection, branch).tokens;
|
|
2403
|
+
}
|
|
2404
|
+
else if (assistantMessage.stopReason === "error" || directContextTokens === 0) {
|
|
2405
|
+
const messages = this.agent.state.messages;
|
|
2406
|
+
const estimate = estimateContextTokens(messages);
|
|
2407
|
+
// Without provider usage, estimate.tokens is the pure message-size estimate.
|
|
2408
|
+
// Only usage-backed estimates need the stale pre-compaction check.
|
|
2409
|
+
if (estimate.lastUsageIndex !== null) {
|
|
2410
|
+
// Verify the usage source is post-compaction. Kept pre-compaction messages
|
|
2411
|
+
// have stale usage reflecting the old (larger) context and would falsely
|
|
2412
|
+
// trigger compaction right after one just finished.
|
|
2413
|
+
const usageMsg = messages[estimate.lastUsageIndex];
|
|
2414
|
+
if (compactionEntry &&
|
|
2415
|
+
usageMsg.role === "assistant" &&
|
|
2416
|
+
usageMsg.timestamp <= new Date(compactionEntry.timestamp).getTime()) {
|
|
2417
|
+
return false;
|
|
2418
|
+
}
|
|
2419
|
+
}
|
|
2420
|
+
contextTokens = estimate.tokens;
|
|
2421
|
+
}
|
|
2422
|
+
else {
|
|
2423
|
+
contextTokens = directContextTokens;
|
|
2424
|
+
}
|
|
2425
|
+
if (shouldCompact(contextTokens, contextWindow, settings)) {
|
|
2426
|
+
return await this._runAutoCompaction("threshold", false);
|
|
2427
|
+
}
|
|
2428
|
+
return false;
|
|
2429
|
+
}
|
|
2430
|
+
/**
|
|
2431
|
+
* Execute threshold or overflow compaction. Manual compaction uses
|
|
2432
|
+
* `AgentSession.compact()` instead. Both paths call the lower-level `compact()`
|
|
2433
|
+
* function imported from `./compaction/index.ts` after preparation and extension
|
|
2434
|
+
* interception.
|
|
2435
|
+
*
|
|
2436
|
+
* @param reason Automatic trigger selected by `_checkCompaction()`
|
|
2437
|
+
* @param willRetry Whether to continue the interrupted turn after overflow compaction
|
|
2438
|
+
* @returns Whether the post-run loop should call `agent.continue()`
|
|
2439
|
+
*/
|
|
2440
|
+
async _runAutoCompaction(reason, willRetry) {
|
|
2441
|
+
const model = this.model;
|
|
2442
|
+
const settings = this.settingsManager.getCompactionSettings(model);
|
|
2443
|
+
let abortController;
|
|
2444
|
+
let started = false;
|
|
2445
|
+
let fromExtension = false;
|
|
2446
|
+
let cancelledByExtension = false;
|
|
2447
|
+
try {
|
|
2448
|
+
if (!model) {
|
|
2449
|
+
return false;
|
|
2450
|
+
}
|
|
2451
|
+
const pathEntries = this.sessionManager.getBranch();
|
|
2452
|
+
const preparation = prepareCompaction(pathEntries, settings);
|
|
2453
|
+
if (!preparation) {
|
|
2454
|
+
return false;
|
|
2455
|
+
}
|
|
2456
|
+
abortController = new AbortController();
|
|
2457
|
+
this._autoCompactionAbortController = abortController;
|
|
2458
|
+
started = true;
|
|
2459
|
+
this._emit({ type: "compaction_start", reason });
|
|
2460
|
+
abortController.signal.throwIfAborted();
|
|
2461
|
+
let extensionCompaction;
|
|
2462
|
+
if (this._extensionRunner.hasHandlers("session_before_compact")) {
|
|
2463
|
+
const extensionResult = (await this._extensionRunner.emit({
|
|
2464
|
+
type: "session_before_compact",
|
|
2465
|
+
preparation,
|
|
2466
|
+
branchEntries: pathEntries,
|
|
2467
|
+
customInstructions: undefined,
|
|
2468
|
+
reason,
|
|
2469
|
+
willRetry,
|
|
2470
|
+
signal: abortController.signal,
|
|
2471
|
+
}));
|
|
2472
|
+
if (extensionResult?.cancel) {
|
|
2473
|
+
cancelledByExtension = true;
|
|
2474
|
+
throw new Error("Compaction cancelled");
|
|
2475
|
+
}
|
|
2476
|
+
if (extensionResult?.compaction) {
|
|
2477
|
+
extensionCompaction = extensionResult.compaction;
|
|
2478
|
+
fromExtension = true;
|
|
2479
|
+
}
|
|
2480
|
+
}
|
|
2481
|
+
abortController.signal.throwIfAborted();
|
|
2482
|
+
let summary;
|
|
2483
|
+
let firstKeptEntryId;
|
|
2484
|
+
let tokensBefore;
|
|
2485
|
+
let usage;
|
|
2486
|
+
let details;
|
|
2487
|
+
if (extensionCompaction) {
|
|
2488
|
+
// Extension provided compaction content
|
|
2489
|
+
summary = extensionCompaction.summary;
|
|
2490
|
+
firstKeptEntryId = extensionCompaction.firstKeptEntryId;
|
|
2491
|
+
tokensBefore = extensionCompaction.tokensBefore;
|
|
2492
|
+
usage = extensionCompaction.usage;
|
|
2493
|
+
details = extensionCompaction.details;
|
|
2494
|
+
}
|
|
2495
|
+
else {
|
|
2496
|
+
// Shared default summary generator, also used by manual compaction.
|
|
2497
|
+
const compactResult = await this._runDefaultCompaction(preparation, model, undefined, abortController.signal, reason);
|
|
2498
|
+
summary = compactResult.summary;
|
|
2499
|
+
firstKeptEntryId = compactResult.firstKeptEntryId;
|
|
2500
|
+
tokensBefore = compactResult.tokensBefore;
|
|
2501
|
+
usage = compactResult.usage;
|
|
2502
|
+
details = compactResult.details;
|
|
2503
|
+
}
|
|
2504
|
+
abortController.signal.throwIfAborted();
|
|
2505
|
+
this.sessionManager.appendCompaction(summary, firstKeptEntryId, tokensBefore, details, fromExtension, usage);
|
|
2506
|
+
const newEntries = this.sessionManager.getEntries();
|
|
2507
|
+
this._refreshFinalizedContext();
|
|
2508
|
+
const estimatedTokensAfter = estimateMessagesTokens(this.sessionManager.buildSessionProjection().messages);
|
|
2509
|
+
// Get the saved compaction entry for the extension event
|
|
2510
|
+
const savedCompactionEntry = newEntries.find((e) => e.type === "compaction" && e.summary === summary);
|
|
2511
|
+
if (this._extensionRunner && savedCompactionEntry) {
|
|
2512
|
+
await this._extensionRunner.emit({
|
|
2513
|
+
type: "session_compact",
|
|
2514
|
+
compactionEntry: savedCompactionEntry,
|
|
2515
|
+
fromExtension,
|
|
2516
|
+
reason,
|
|
2517
|
+
willRetry,
|
|
2518
|
+
});
|
|
2519
|
+
}
|
|
2520
|
+
const result = {
|
|
2521
|
+
summary,
|
|
2522
|
+
firstKeptEntryId,
|
|
2523
|
+
tokensBefore,
|
|
2524
|
+
estimatedTokensAfter,
|
|
2525
|
+
usage,
|
|
2526
|
+
details,
|
|
2527
|
+
};
|
|
2528
|
+
this._emit({ type: "compaction_end", reason, result, aborted: false, willRetry });
|
|
2529
|
+
if (willRetry)
|
|
2530
|
+
return true;
|
|
2531
|
+
// Auto-compaction can complete while follow-up/steering/custom messages are waiting.
|
|
2532
|
+
// Continue once so queued messages are delivered.
|
|
2533
|
+
return this.agent.hasQueuedMessages();
|
|
2534
|
+
}
|
|
2535
|
+
catch (error) {
|
|
2536
|
+
const message = error instanceof Error ? error.message : "compaction failed";
|
|
2537
|
+
const aborted = abortController?.signal.aborted === true || cancelledByExtension;
|
|
2538
|
+
if (started) {
|
|
2539
|
+
const errorMessage = aborted
|
|
2540
|
+
? undefined
|
|
2541
|
+
: reason === "overflow"
|
|
2542
|
+
? `Context overflow recovery failed: ${message}`
|
|
2543
|
+
: `Auto-compaction failed: ${message}`;
|
|
2544
|
+
this._emit({
|
|
2545
|
+
type: "compaction_end",
|
|
2546
|
+
reason,
|
|
2547
|
+
result: undefined,
|
|
2548
|
+
aborted,
|
|
2549
|
+
willRetry: false,
|
|
2550
|
+
errorMessage,
|
|
2551
|
+
});
|
|
2552
|
+
await this._emitSessionCompactFailed({
|
|
2553
|
+
reason,
|
|
2554
|
+
errorMessage,
|
|
2555
|
+
aborted,
|
|
2556
|
+
willRetry: false,
|
|
2557
|
+
fromExtension,
|
|
2558
|
+
});
|
|
2559
|
+
}
|
|
2560
|
+
return false;
|
|
2561
|
+
}
|
|
2562
|
+
finally {
|
|
2563
|
+
if (this._autoCompactionAbortController === abortController) {
|
|
2564
|
+
this._autoCompactionAbortController = undefined;
|
|
2565
|
+
}
|
|
2566
|
+
this._resolveIdleWaitIfIdle();
|
|
2567
|
+
}
|
|
2568
|
+
}
|
|
2569
|
+
/**
|
|
2570
|
+
* Toggle auto-compaction setting.
|
|
2571
|
+
*/
|
|
2572
|
+
setAutoCompactionEnabled(enabled) {
|
|
2573
|
+
this.settingsManager.setCompactionEnabled(enabled);
|
|
2574
|
+
}
|
|
2575
|
+
/** Whether auto-compaction is enabled */
|
|
2576
|
+
get autoCompactionEnabled() {
|
|
2577
|
+
return this.settingsManager.getCompactionEnabled();
|
|
2578
|
+
}
|
|
2579
|
+
async bindExtensions(bindings) {
|
|
2580
|
+
if (bindings.uiContext !== undefined) {
|
|
2581
|
+
this._extensionUIContext = bindings.uiContext;
|
|
2582
|
+
}
|
|
2583
|
+
if (bindings.mode !== undefined) {
|
|
2584
|
+
this._extensionMode = bindings.mode;
|
|
2585
|
+
}
|
|
2586
|
+
if (bindings.commandContextActions !== undefined) {
|
|
2587
|
+
this._extensionCommandContextActions = bindings.commandContextActions;
|
|
2588
|
+
}
|
|
2589
|
+
if (bindings.abortHandler !== undefined) {
|
|
2590
|
+
this._extensionAbortHandler = bindings.abortHandler;
|
|
2591
|
+
}
|
|
2592
|
+
if (bindings.shutdownHandler !== undefined) {
|
|
2593
|
+
this._extensionShutdownHandler = bindings.shutdownHandler;
|
|
2594
|
+
}
|
|
2595
|
+
if (bindings.onError !== undefined) {
|
|
2596
|
+
this._extensionErrorListener = bindings.onError;
|
|
2597
|
+
}
|
|
2598
|
+
this._applyExtensionBindings(this._extensionRunner);
|
|
2599
|
+
await this._extensionRunner.emit(this._sessionStartEvent);
|
|
2600
|
+
this._extensionRunner.reportUnhandledMcpServers();
|
|
2601
|
+
await this.extendResourcesFromExtensions(this._sessionStartEvent.reason === "reload" ? "reload" : "startup");
|
|
2602
|
+
}
|
|
2603
|
+
async extendResourcesFromExtensions(reason) {
|
|
2604
|
+
if (!this._extensionRunner.hasHandlers("resources_discover")) {
|
|
2605
|
+
return;
|
|
2606
|
+
}
|
|
2607
|
+
const { skillPaths, promptPaths, themePaths } = await this._extensionRunner.emitResourcesDiscover(this._cwd, reason);
|
|
2608
|
+
if (skillPaths.length === 0 && promptPaths.length === 0 && themePaths.length === 0) {
|
|
2609
|
+
return;
|
|
2610
|
+
}
|
|
2611
|
+
const extensionPaths = {
|
|
2612
|
+
skillPaths: this.buildExtensionResourcePaths(skillPaths),
|
|
2613
|
+
promptPaths: this.buildExtensionResourcePaths(promptPaths),
|
|
2614
|
+
themePaths: this.buildExtensionResourcePaths(themePaths),
|
|
2615
|
+
};
|
|
2616
|
+
this._resourceLoader.extendResources(extensionPaths);
|
|
2617
|
+
this._rebuildSystemPrompt(this.getActiveToolNames());
|
|
2618
|
+
}
|
|
2619
|
+
buildExtensionResourcePaths(entries) {
|
|
2620
|
+
return entries.map((entry) => {
|
|
2621
|
+
const source = this.getExtensionSourceLabel(entry.extensionPath);
|
|
2622
|
+
const baseDir = isSyntheticPath(entry.extensionPath) ? undefined : dirname(entry.extensionPath);
|
|
2623
|
+
return {
|
|
2624
|
+
path: entry.path,
|
|
2625
|
+
metadata: {
|
|
2626
|
+
source,
|
|
2627
|
+
scope: "temporary",
|
|
2628
|
+
origin: "top-level",
|
|
2629
|
+
baseDir,
|
|
2630
|
+
},
|
|
2631
|
+
};
|
|
2632
|
+
});
|
|
2633
|
+
}
|
|
2634
|
+
getExtensionSourceLabel(extensionPath) {
|
|
2635
|
+
if (isSyntheticPath(extensionPath)) {
|
|
2636
|
+
return `extension:${extensionPath.replace(/[<>]/g, "")}`;
|
|
2637
|
+
}
|
|
2638
|
+
const base = basename(extensionPath);
|
|
2639
|
+
const name = base.replace(/\.(ts|js)$/, "");
|
|
2640
|
+
return `extension:${name}`;
|
|
2641
|
+
}
|
|
2642
|
+
_applyExtensionBindings(runner) {
|
|
2643
|
+
runner.setUIContext(this._extensionUIContext, this._extensionMode);
|
|
2644
|
+
runner.bindCommandContext(this._extensionCommandContextActions);
|
|
2645
|
+
this._extensionErrorUnsubscriber?.();
|
|
2646
|
+
this._extensionErrorUnsubscriber = this._extensionErrorListener
|
|
2647
|
+
? runner.onError(this._extensionErrorListener)
|
|
2648
|
+
: undefined;
|
|
2649
|
+
}
|
|
2650
|
+
_refreshCurrentModelFromRegistry() {
|
|
2651
|
+
const currentModel = this.model;
|
|
2652
|
+
if (!currentModel) {
|
|
2653
|
+
return;
|
|
2654
|
+
}
|
|
2655
|
+
const refreshedModel = this._modelRuntime.getModel(currentModel.provider, currentModel.id);
|
|
2656
|
+
if (!refreshedModel || refreshedModel === currentModel) {
|
|
2657
|
+
return;
|
|
2658
|
+
}
|
|
2659
|
+
this.agent.state.model = refreshedModel;
|
|
2660
|
+
}
|
|
2661
|
+
_bindExtensionCore(runner) {
|
|
2662
|
+
const getCommands = () => {
|
|
2663
|
+
const extensionCommands = runner.getRegisteredCommands().map((command) => ({
|
|
2664
|
+
name: command.invocationName,
|
|
2665
|
+
description: command.description,
|
|
2666
|
+
source: "extension",
|
|
2667
|
+
sourceInfo: command.sourceInfo,
|
|
2668
|
+
}));
|
|
2669
|
+
const templates = this.promptTemplates.map((template) => ({
|
|
2670
|
+
name: template.name,
|
|
2671
|
+
description: template.description,
|
|
2672
|
+
source: "prompt",
|
|
2673
|
+
sourceInfo: template.sourceInfo,
|
|
2674
|
+
}));
|
|
2675
|
+
const skills = this._resourceLoader.getSkills().skills.map((skill) => ({
|
|
2676
|
+
name: `skill:${skill.name}`,
|
|
2677
|
+
description: skill.description,
|
|
2678
|
+
source: "skill",
|
|
2679
|
+
sourceInfo: skill.sourceInfo,
|
|
2680
|
+
}));
|
|
2681
|
+
return [...extensionCommands, ...templates, ...skills];
|
|
2682
|
+
};
|
|
2683
|
+
runner.bindCore({
|
|
2684
|
+
sendMessage: (message, options) => {
|
|
2685
|
+
this.sendCustomMessage(message, options).catch((err) => {
|
|
2686
|
+
runner.emitError({
|
|
2687
|
+
extensionPath: "<runtime>",
|
|
2688
|
+
event: "send_message",
|
|
2689
|
+
error: err instanceof Error ? err.message : String(err),
|
|
2690
|
+
});
|
|
2691
|
+
});
|
|
2692
|
+
},
|
|
2693
|
+
sendUserMessage: (content, options) => {
|
|
2694
|
+
this.sendUserMessage(content, options).catch((err) => {
|
|
2695
|
+
runner.emitError({
|
|
2696
|
+
extensionPath: "<runtime>",
|
|
2697
|
+
event: "send_user_message",
|
|
2698
|
+
error: err instanceof Error ? err.message : String(err),
|
|
2699
|
+
});
|
|
2700
|
+
});
|
|
2701
|
+
},
|
|
2702
|
+
appendEntry: (customType, data) => {
|
|
2703
|
+
const entryId = this.sessionManager.appendCustomEntry(customType, data);
|
|
2704
|
+
const entry = this.sessionManager.getEntry(entryId);
|
|
2705
|
+
if (entry) {
|
|
2706
|
+
this._emit({ type: "entry_appended", entry });
|
|
2707
|
+
}
|
|
2708
|
+
},
|
|
2709
|
+
setSessionName: (name) => {
|
|
2710
|
+
this.setSessionName(name);
|
|
2711
|
+
},
|
|
2712
|
+
getSessionName: () => {
|
|
2713
|
+
return this.sessionManager.getSessionName();
|
|
2714
|
+
},
|
|
2715
|
+
setLabel: (entryId, label) => {
|
|
2716
|
+
this.sessionManager.appendLabelChange(entryId, label);
|
|
2717
|
+
},
|
|
2718
|
+
getActiveTools: () => this.getActiveToolNames(),
|
|
2719
|
+
getAllTools: () => this.getAllTools(),
|
|
2720
|
+
getSettings: () => this.settingsManager.getSettings(),
|
|
2721
|
+
setActiveTools: (toolNames) => this.setActiveToolsByName(toolNames),
|
|
2722
|
+
refreshTools: () => this._refreshToolRegistry(),
|
|
2723
|
+
getCommands,
|
|
2724
|
+
setModel: async (model) => {
|
|
2725
|
+
if (!this._modelRuntime.hasConfiguredAuth(model.provider))
|
|
2726
|
+
return false;
|
|
2727
|
+
await this.setModel(model);
|
|
2728
|
+
return true;
|
|
2729
|
+
},
|
|
2730
|
+
getThinkingLevel: () => this.thinkingLevel,
|
|
2731
|
+
setThinkingLevel: (level) => this.setThinkingLevel(level),
|
|
2732
|
+
}, {
|
|
2733
|
+
getModel: () => this.model,
|
|
2734
|
+
getScopedModels: () => this._scopedModels,
|
|
2735
|
+
isIdle: () => this.isIdle,
|
|
2736
|
+
isProjectTrusted: () => this.settingsManager.isProjectTrusted(),
|
|
2737
|
+
getSignal: () => this.agent.signal,
|
|
2738
|
+
abort: () => {
|
|
2739
|
+
if (this._extensionAbortHandler) {
|
|
2740
|
+
this._extensionAbortHandler();
|
|
2741
|
+
return;
|
|
2742
|
+
}
|
|
2743
|
+
void this.abort();
|
|
2744
|
+
},
|
|
2745
|
+
hasPendingMessages: () => this.pendingMessageCount > 0,
|
|
2746
|
+
shutdown: () => {
|
|
2747
|
+
this._extensionShutdownHandler?.();
|
|
2748
|
+
},
|
|
2749
|
+
getContextUsage: () => this.getContextUsage(),
|
|
2750
|
+
compact: (options) => {
|
|
2751
|
+
void (async () => {
|
|
2752
|
+
try {
|
|
2753
|
+
const result = await this.compact(options?.customInstructions);
|
|
2754
|
+
options?.onComplete?.(result);
|
|
2755
|
+
}
|
|
2756
|
+
catch (error) {
|
|
2757
|
+
const err = error instanceof Error ? error : new Error(String(error));
|
|
2758
|
+
options?.onError?.(err);
|
|
2759
|
+
}
|
|
2760
|
+
})();
|
|
2761
|
+
},
|
|
2762
|
+
getSystemPrompt: () => this.systemPrompt,
|
|
2763
|
+
getSystemPromptOptions: () => this._baseSystemPromptOptions,
|
|
2764
|
+
executeTool: (callerId, name, args, options) => this._executeNestedToolCall(callerId, name, args, options),
|
|
2765
|
+
getCallableTools: () => this._getCallableTools(),
|
|
2766
|
+
}, {
|
|
2767
|
+
registerProvider: (name, config) => {
|
|
2768
|
+
this._modelRuntime.registerProvider(name, config);
|
|
2769
|
+
this._refreshCurrentModelFromRegistry();
|
|
2770
|
+
},
|
|
2771
|
+
registerNativeProvider: (provider) => {
|
|
2772
|
+
this._modelRuntime.registerNativeProvider(provider);
|
|
2773
|
+
this._refreshCurrentModelFromRegistry();
|
|
2774
|
+
},
|
|
2775
|
+
unregisterProvider: (name) => {
|
|
2776
|
+
this._modelRuntime.unregisterProvider(name);
|
|
2777
|
+
this._refreshCurrentModelFromRegistry();
|
|
2778
|
+
},
|
|
2779
|
+
registerVirtualModel: (definition) => {
|
|
2780
|
+
this._modelRuntime.registerVirtualModel(definition);
|
|
2781
|
+
this._refreshCurrentModelFromRegistry();
|
|
2782
|
+
},
|
|
2783
|
+
unregisterVirtualModel: (provider, id) => {
|
|
2784
|
+
this._modelRuntime.unregisterVirtualModel(provider, id);
|
|
2785
|
+
this._refreshCurrentModelFromRegistry();
|
|
2786
|
+
},
|
|
2787
|
+
});
|
|
2788
|
+
}
|
|
2789
|
+
_refreshToolRegistry(options) {
|
|
2790
|
+
// Tools that were already activated on registration. A tool whose exposure changes to
|
|
2791
|
+
// `direct` or `model-only` (for example from `hidden`) is activated like a new tool.
|
|
2792
|
+
const previousActivatedOnRegistration = new Set([...this._toolRegistry.keys()].filter((name) => this._isActivatedOnRegistration(name)));
|
|
2793
|
+
const previousActiveToolNames = this.getActiveToolNames();
|
|
2794
|
+
const allowedToolNames = this._allowedToolNames;
|
|
2795
|
+
const registeredTools = this._extensionRunner.getAllRegisteredTools();
|
|
2796
|
+
const allCustomTools = [
|
|
2797
|
+
...registeredTools,
|
|
2798
|
+
...this._customTools.map((definition) => ({
|
|
2799
|
+
definition,
|
|
2800
|
+
sourceInfo: createSyntheticSourceInfo(`<sdk:${definition.name}>`, { source: "sdk" }),
|
|
2801
|
+
})),
|
|
2802
|
+
].filter((tool) => this._isAllowedTool(tool.definition.name));
|
|
2803
|
+
const definitionRegistry = new Map(Array.from(this._baseToolDefinitions.entries())
|
|
2804
|
+
.filter(([name]) => this._isAllowedTool(name))
|
|
2805
|
+
.map(([name, definition]) => [
|
|
2806
|
+
name,
|
|
2807
|
+
{
|
|
2808
|
+
definition,
|
|
2809
|
+
sourceInfo: createSyntheticSourceInfo(`${BUILTIN_PATH_PREFIX}${name}`, { source: "builtin" }),
|
|
2810
|
+
},
|
|
2811
|
+
]));
|
|
2812
|
+
for (const tool of allCustomTools) {
|
|
2813
|
+
definitionRegistry.set(tool.definition.name, {
|
|
2814
|
+
definition: tool.definition,
|
|
2815
|
+
sourceInfo: tool.sourceInfo,
|
|
2816
|
+
});
|
|
2817
|
+
}
|
|
2818
|
+
this._toolDefinitions = definitionRegistry;
|
|
2819
|
+
this._toolPromptSnippets = new Map(Array.from(definitionRegistry.values())
|
|
2820
|
+
.map(({ definition }) => {
|
|
2821
|
+
const snippet = this._normalizePromptSnippet(definition.promptSnippet);
|
|
2822
|
+
return snippet ? [definition.name, snippet] : undefined;
|
|
2823
|
+
})
|
|
2824
|
+
.filter((entry) => entry !== undefined));
|
|
2825
|
+
this._toolPromptGuidelines = new Map(Array.from(definitionRegistry.values())
|
|
2826
|
+
.map(({ definition }) => {
|
|
2827
|
+
const guidelines = this._normalizePromptGuidelines(definition.promptGuidelines);
|
|
2828
|
+
return guidelines.length > 0 ? [definition.name, guidelines] : undefined;
|
|
2829
|
+
})
|
|
2830
|
+
.filter((entry) => entry !== undefined));
|
|
2831
|
+
const runner = this._extensionRunner;
|
|
2832
|
+
const wrappedExtensionTools = wrapRegisteredTools(allCustomTools, runner);
|
|
2833
|
+
const wrappedBuiltInTools = wrapRegisteredTools(Array.from(this._baseToolDefinitions.values())
|
|
2834
|
+
.filter((definition) => this._isAllowedTool(definition.name))
|
|
2835
|
+
.map((definition) => ({
|
|
2836
|
+
definition,
|
|
2837
|
+
sourceInfo: createSyntheticSourceInfo(`${BUILTIN_PATH_PREFIX}${definition.name}`, {
|
|
2838
|
+
source: "builtin",
|
|
2839
|
+
}),
|
|
2840
|
+
})), runner);
|
|
2841
|
+
const toolRegistry = new Map(wrappedBuiltInTools.map((tool) => [tool.name, tool]));
|
|
2842
|
+
for (const tool of wrappedExtensionTools) {
|
|
2843
|
+
toolRegistry.set(tool.name, tool);
|
|
2844
|
+
}
|
|
2845
|
+
this._toolRegistry = toolRegistry;
|
|
2846
|
+
const nextActiveToolNames = (options?.activeToolNames ? [...options.activeToolNames] : [...previousActiveToolNames]).filter((name) => this._isAllowedTool(name));
|
|
2847
|
+
if (allowedToolNames) {
|
|
2848
|
+
for (const toolName of this._toolRegistry.keys()) {
|
|
2849
|
+
// Naming a tool activates it even when it is not active by default.
|
|
2850
|
+
if (allowedToolNames.has(toolName) && this._isDeclarable(toolName)) {
|
|
2851
|
+
nextActiveToolNames.push(toolName);
|
|
2852
|
+
}
|
|
2853
|
+
}
|
|
2854
|
+
}
|
|
2855
|
+
else if (options?.includeAllExtensionTools) {
|
|
2856
|
+
for (const tool of wrappedExtensionTools) {
|
|
2857
|
+
if (this._isActivatedOnRegistration(tool.name))
|
|
2858
|
+
nextActiveToolNames.push(tool.name);
|
|
2859
|
+
}
|
|
2860
|
+
}
|
|
2861
|
+
else if (!options?.activeToolNames) {
|
|
2862
|
+
for (const toolName of this._toolRegistry.keys()) {
|
|
2863
|
+
if (!previousActivatedOnRegistration.has(toolName) && this._isActivatedOnRegistration(toolName)) {
|
|
2864
|
+
nextActiveToolNames.push(toolName);
|
|
2865
|
+
}
|
|
2866
|
+
}
|
|
2867
|
+
}
|
|
2868
|
+
// Pending tools that are registered now become active.
|
|
2869
|
+
nextActiveToolNames.push(...this._pendingToolNames);
|
|
2870
|
+
this._setActiveTools([...new Set(nextActiveToolNames)]);
|
|
2871
|
+
}
|
|
2872
|
+
/** Whether activating the tool declares it to the model. */
|
|
2873
|
+
_isDeclarable(name) {
|
|
2874
|
+
const exposure = this._getToolExposure(name);
|
|
2875
|
+
return exposure === "direct" || exposure === "model-only";
|
|
2876
|
+
}
|
|
2877
|
+
/** Whether registering the tool activates it, which declares it to the model. */
|
|
2878
|
+
_isActivatedOnRegistration(name) {
|
|
2879
|
+
return this._isDeclarable(name) && this._toolDefinitions.get(name)?.definition.defaultActive !== false;
|
|
2880
|
+
}
|
|
2881
|
+
_buildRuntime(options) {
|
|
2882
|
+
const autoResizeImages = this.settingsManager.getImageAutoResize();
|
|
2883
|
+
const shellCommandPrefix = this.settingsManager.getShellCommandPrefix();
|
|
2884
|
+
const shellPath = this.settingsManager.getShellPath();
|
|
2885
|
+
const baseToolDefinitions = this._baseToolsOverride
|
|
2886
|
+
? Object.fromEntries(Object.entries(this._baseToolsOverride).map(([name, tool]) => [
|
|
2887
|
+
name,
|
|
2888
|
+
createToolDefinitionFromAgentTool(tool),
|
|
2889
|
+
]))
|
|
2890
|
+
: createAllToolDefinitions(this._cwd, {
|
|
2891
|
+
read: { autoResizeImages },
|
|
2892
|
+
bash: { commandPrefix: shellCommandPrefix, shellPath },
|
|
2893
|
+
});
|
|
2894
|
+
this._baseToolDefinitions = new Map(Object.entries(baseToolDefinitions).map(([name, tool]) => [name, tool]));
|
|
2895
|
+
const extensionsResult = this._resourceLoader.getExtensions();
|
|
2896
|
+
if (options.flagValues) {
|
|
2897
|
+
for (const [name, value] of options.flagValues) {
|
|
2898
|
+
extensionsResult.runtime.flagValues.set(name, value);
|
|
2899
|
+
}
|
|
2900
|
+
}
|
|
2901
|
+
this._extensionRunner = new ExtensionRunner(extensionsResult.extensions, extensionsResult.runtime, this._cwd, this.sessionManager, new ModelRegistry(this._modelRuntime));
|
|
2902
|
+
if (this._extensionRunnerRef) {
|
|
2903
|
+
this._extensionRunnerRef.current = this._extensionRunner;
|
|
2904
|
+
}
|
|
2905
|
+
this._bindExtensionCore(this._extensionRunner);
|
|
2906
|
+
this._applyExtensionBindings(this._extensionRunner);
|
|
2907
|
+
const defaultActiveToolNames = this._baseToolsOverride
|
|
2908
|
+
? Object.keys(this._baseToolsOverride)
|
|
2909
|
+
: ["read", "bash", "edit", "write"];
|
|
2910
|
+
const baseActiveToolNames = options.activeToolNames ?? defaultActiveToolNames;
|
|
2911
|
+
this._refreshToolRegistry({
|
|
2912
|
+
activeToolNames: baseActiveToolNames,
|
|
2913
|
+
includeAllExtensionTools: options.includeAllExtensionTools,
|
|
2914
|
+
});
|
|
2915
|
+
}
|
|
2916
|
+
async reload(options) {
|
|
2917
|
+
const oldRunner = this._extensionRunner;
|
|
2918
|
+
const previousFlagValues = oldRunner.getFlagValues();
|
|
2919
|
+
await emitSessionShutdownEvent(oldRunner, { type: "session_shutdown", reason: "reload" });
|
|
2920
|
+
oldRunner.invalidate();
|
|
2921
|
+
const previousDefaultTools = new Set(this._usesDefaultTools ? (this.settingsManager.getDefaultTools() ?? DEFAULT_TOOL_NAMES) : []);
|
|
2922
|
+
await this.settingsManager.reload();
|
|
2923
|
+
this.syncQueueModesFromSettings();
|
|
2924
|
+
resetApiProviders();
|
|
2925
|
+
await this._resourceLoader.reload();
|
|
2926
|
+
// Activate tools newly added to defaultTools. Removed ones stay active, and tools disabled
|
|
2927
|
+
// during the session stay disabled unless the setting newly adds them.
|
|
2928
|
+
const addedDefaultTools = this._usesDefaultTools
|
|
2929
|
+
? (this.settingsManager.getDefaultTools() ?? DEFAULT_TOOL_NAMES).filter((name) => !previousDefaultTools.has(name))
|
|
2930
|
+
: [];
|
|
2931
|
+
// Tools the new extensions register later, such as MCP tools, are pending until then.
|
|
2932
|
+
for (const name of this.getActiveToolNames())
|
|
2933
|
+
this._pendingToolNames.add(name);
|
|
2934
|
+
this._buildRuntime({
|
|
2935
|
+
activeToolNames: [...this.getActiveToolNames(), ...addedDefaultTools],
|
|
2936
|
+
flagValues: previousFlagValues,
|
|
2937
|
+
includeAllExtensionTools: true,
|
|
2938
|
+
});
|
|
2939
|
+
const hasBindings = this._extensionUIContext ||
|
|
2940
|
+
this._extensionCommandContextActions ||
|
|
2941
|
+
this._extensionShutdownHandler ||
|
|
2942
|
+
this._extensionErrorListener;
|
|
2943
|
+
if (hasBindings) {
|
|
2944
|
+
await options?.beforeSessionStart?.();
|
|
2945
|
+
await this._extensionRunner.emit({ type: "session_start", reason: "reload" });
|
|
2946
|
+
this._extensionRunner.reportUnhandledMcpServers();
|
|
2947
|
+
await this.extendResourcesFromExtensions("reload");
|
|
2948
|
+
}
|
|
2949
|
+
}
|
|
2950
|
+
// =========================================================================
|
|
2951
|
+
// Auto-Retry
|
|
2952
|
+
// =========================================================================
|
|
2953
|
+
/**
|
|
2954
|
+
* Check if an error is retryable (overloaded, rate limit, server errors).
|
|
2955
|
+
* Context overflow errors are NOT retryable (handled by compaction instead).
|
|
2956
|
+
*/
|
|
2957
|
+
_isRetryableError(message) {
|
|
2958
|
+
// Context overflow is handled by compaction, not retry.
|
|
2959
|
+
if (isContextOverflow(message, (this._modelForMessage(message) ?? this.model)?.contextWindow ?? 0))
|
|
2960
|
+
return false;
|
|
2961
|
+
return isRetryableAssistantError(message);
|
|
2962
|
+
}
|
|
2963
|
+
/**
|
|
2964
|
+
* Retry policy + callbacks shared by compaction and branch-summary summarization calls.
|
|
2965
|
+
* Uses the same `settings.retry` budget/backoff as agent-turn retries so a single transient
|
|
2966
|
+
* stream drop no longer fails the whole operation. `source` carries the context
|
|
2967
|
+
* the TUI needs to render the retry and recreate the underlying indicator.
|
|
2968
|
+
*/
|
|
2969
|
+
_summarizationRetryCallbacks(source) {
|
|
2970
|
+
return {
|
|
2971
|
+
onRetryScheduled: (attempt, maxAttempts, delayMs, errorMessage) => {
|
|
2972
|
+
this._emit({
|
|
2973
|
+
type: "summarization_retry_scheduled",
|
|
2974
|
+
attempt,
|
|
2975
|
+
maxAttempts,
|
|
2976
|
+
delayMs,
|
|
2977
|
+
errorMessage,
|
|
2978
|
+
});
|
|
2979
|
+
},
|
|
2980
|
+
onRetryAttemptStart: () => {
|
|
2981
|
+
this._emit({
|
|
2982
|
+
type: "summarization_retry_attempt_start",
|
|
2983
|
+
...source,
|
|
2984
|
+
});
|
|
2985
|
+
},
|
|
2986
|
+
onRetryFinished: () => {
|
|
2987
|
+
this._emit({ type: "summarization_retry_finished" });
|
|
2988
|
+
},
|
|
2989
|
+
};
|
|
2990
|
+
}
|
|
2991
|
+
_finishCancelledRetry() {
|
|
2992
|
+
if (this._retryAttempt === 0)
|
|
2993
|
+
return;
|
|
2994
|
+
const attempt = this._retryAttempt;
|
|
2995
|
+
this._retryAttempt = 0;
|
|
2996
|
+
this._emit({
|
|
2997
|
+
type: "auto_retry_end",
|
|
2998
|
+
success: false,
|
|
2999
|
+
attempt,
|
|
3000
|
+
finalError: "Retry cancelled",
|
|
3001
|
+
});
|
|
3002
|
+
}
|
|
3003
|
+
/**
|
|
3004
|
+
* Prepare a retryable error for continuation with exponential backoff.
|
|
3005
|
+
* @returns true if the caller should continue the agent, false otherwise
|
|
3006
|
+
*/
|
|
3007
|
+
async _prepareRetry(message) {
|
|
3008
|
+
const settings = this.settingsManager.getRetrySettings();
|
|
3009
|
+
if (!settings.enabled) {
|
|
3010
|
+
return false;
|
|
3011
|
+
}
|
|
3012
|
+
this._retryAttempt++;
|
|
3013
|
+
if (this._retryAttempt > settings.maxRetries) {
|
|
3014
|
+
// Preserve the completed attempt count so post-run handling can emit the final failure.
|
|
3015
|
+
this._retryAttempt--;
|
|
3016
|
+
return false;
|
|
3017
|
+
}
|
|
3018
|
+
const delayMs = retryDelayMs(settings, this._retryAttempt);
|
|
3019
|
+
this._emit({
|
|
3020
|
+
type: "auto_retry_start",
|
|
3021
|
+
attempt: this._retryAttempt,
|
|
3022
|
+
maxAttempts: settings.maxRetries,
|
|
3023
|
+
delayMs,
|
|
3024
|
+
errorMessage: message.errorMessage || "Unknown error",
|
|
3025
|
+
});
|
|
3026
|
+
// Keep the failed attempt in raw history while durably omitting it from model projection.
|
|
3027
|
+
this._omitRecoveryAttempt(message);
|
|
3028
|
+
// Wait with exponential backoff (abortable)
|
|
3029
|
+
this._retryAbortController = new AbortController();
|
|
3030
|
+
try {
|
|
3031
|
+
await sleep(delayMs, this._retryAbortController.signal);
|
|
3032
|
+
}
|
|
3033
|
+
catch {
|
|
3034
|
+
// Aborted during sleep - emit end event so UI can clean up
|
|
3035
|
+
this._finishCancelledRetry();
|
|
3036
|
+
return false;
|
|
3037
|
+
}
|
|
3038
|
+
finally {
|
|
3039
|
+
this._retryAbortController = undefined;
|
|
3040
|
+
}
|
|
3041
|
+
return true;
|
|
3042
|
+
}
|
|
3043
|
+
/**
|
|
3044
|
+
* Cancel in-progress retry.
|
|
3045
|
+
*/
|
|
3046
|
+
abortRetry() {
|
|
3047
|
+
this._retryAbortController?.abort();
|
|
3048
|
+
}
|
|
3049
|
+
/** Whether auto-retry is currently in progress */
|
|
3050
|
+
get isRetrying() {
|
|
3051
|
+
return this._retryAbortController !== undefined;
|
|
3052
|
+
}
|
|
3053
|
+
/** Whether auto-retry is enabled */
|
|
3054
|
+
get autoRetryEnabled() {
|
|
3055
|
+
return this.settingsManager.getRetryEnabled();
|
|
3056
|
+
}
|
|
3057
|
+
/**
|
|
3058
|
+
* Toggle auto-retry setting.
|
|
3059
|
+
*/
|
|
3060
|
+
setAutoRetryEnabled(enabled) {
|
|
3061
|
+
this.settingsManager.setRetryEnabled(enabled);
|
|
3062
|
+
}
|
|
3063
|
+
// =========================================================================
|
|
3064
|
+
// Bash Execution
|
|
3065
|
+
// =========================================================================
|
|
3066
|
+
/**
|
|
3067
|
+
* Execute a bash command.
|
|
3068
|
+
* Adds result to agent context and session.
|
|
3069
|
+
* @param command The bash command to execute
|
|
3070
|
+
* @param onChunk Optional streaming callback for output
|
|
3071
|
+
* @param options.excludeFromContext If true, command output won't be sent to LLM (!! prefix)
|
|
3072
|
+
* @param options.id Optional identifier included in bash execution update events
|
|
3073
|
+
* @param options.operations Custom BashOperations for remote execution
|
|
3074
|
+
*/
|
|
3075
|
+
async executeBash(command, onChunk, options) {
|
|
3076
|
+
const abortController = new AbortController();
|
|
3077
|
+
this._bashAbortControllers.add(abortController);
|
|
3078
|
+
// Apply command prefix if configured (e.g., "shopt -s expand_aliases" for alias support)
|
|
3079
|
+
const prefix = this.settingsManager.getShellCommandPrefix();
|
|
3080
|
+
const shellPath = this.settingsManager.getShellPath();
|
|
3081
|
+
const resolvedCommand = prefix ? `${prefix}\n${command}` : command;
|
|
3082
|
+
try {
|
|
3083
|
+
const result = await executeBashWithOperations(resolvedCommand, this.sessionManager.getCwd(), options?.operations ?? createLocalBashOperations({ shellPath }), {
|
|
3084
|
+
onChunk: (delta) => {
|
|
3085
|
+
onChunk?.(delta);
|
|
3086
|
+
this._emit({ type: "bash_execution_update", id: options?.id, delta });
|
|
3087
|
+
},
|
|
3088
|
+
signal: abortController.signal,
|
|
3089
|
+
});
|
|
3090
|
+
this.recordBashResult(command, result, options);
|
|
3091
|
+
return result;
|
|
3092
|
+
}
|
|
3093
|
+
finally {
|
|
3094
|
+
this._bashAbortControllers.delete(abortController);
|
|
3095
|
+
}
|
|
3096
|
+
}
|
|
3097
|
+
/**
|
|
3098
|
+
* Record a bash execution result in session history.
|
|
3099
|
+
* Used by executeBash and by extensions that handle bash execution themselves.
|
|
3100
|
+
*/
|
|
3101
|
+
recordBashResult(command, result, options) {
|
|
3102
|
+
const bashMessage = {
|
|
3103
|
+
role: "bashExecution",
|
|
3104
|
+
command,
|
|
3105
|
+
output: result.output,
|
|
3106
|
+
exitCode: result.exitCode,
|
|
3107
|
+
cancelled: result.cancelled,
|
|
3108
|
+
truncated: result.truncated,
|
|
3109
|
+
fullOutputPath: result.fullOutputPath,
|
|
3110
|
+
timestamp: Date.now(),
|
|
3111
|
+
excludeFromContext: options?.excludeFromContext,
|
|
3112
|
+
};
|
|
3113
|
+
// If agent is streaming, defer adding to avoid breaking tool_use/tool_result ordering
|
|
3114
|
+
if (this.isStreaming) {
|
|
3115
|
+
// Queue for later - will be flushed on agent_end
|
|
3116
|
+
this._pendingBashMessages.push(bashMessage);
|
|
3117
|
+
}
|
|
3118
|
+
else {
|
|
3119
|
+
this.sessionManager.appendMessage(bashMessage);
|
|
3120
|
+
this._refreshFinalizedContext();
|
|
3121
|
+
}
|
|
3122
|
+
}
|
|
3123
|
+
/**
|
|
3124
|
+
* Cancel running bash command.
|
|
3125
|
+
*/
|
|
3126
|
+
abortBash() {
|
|
3127
|
+
for (const abortController of [...this._bashAbortControllers]) {
|
|
3128
|
+
abortController.abort();
|
|
3129
|
+
}
|
|
3130
|
+
}
|
|
3131
|
+
/** Whether a bash command is currently running */
|
|
3132
|
+
get isBashRunning() {
|
|
3133
|
+
return this._bashAbortControllers.size > 0;
|
|
3134
|
+
}
|
|
3135
|
+
/** Whether there are pending bash messages waiting to be flushed */
|
|
3136
|
+
get hasPendingBashMessages() {
|
|
3137
|
+
return this._pendingBashMessages.length > 0;
|
|
3138
|
+
}
|
|
3139
|
+
/**
|
|
3140
|
+
* Flush pending bash messages to agent state and session.
|
|
3141
|
+
* Called after agent turn completes to maintain proper message ordering.
|
|
3142
|
+
*/
|
|
3143
|
+
_flushPendingBashMessages() {
|
|
3144
|
+
if (this._pendingBashMessages.length === 0)
|
|
3145
|
+
return;
|
|
3146
|
+
for (const bashMessage of this._pendingBashMessages) {
|
|
3147
|
+
this.sessionManager.appendMessage(bashMessage);
|
|
3148
|
+
}
|
|
3149
|
+
this._pendingBashMessages = [];
|
|
3150
|
+
this._refreshFinalizedContext();
|
|
3151
|
+
}
|
|
3152
|
+
// =========================================================================
|
|
3153
|
+
// Session Management
|
|
3154
|
+
// =========================================================================
|
|
3155
|
+
/**
|
|
3156
|
+
* Set a display name for the current session.
|
|
3157
|
+
*/
|
|
3158
|
+
setSessionName(name) {
|
|
3159
|
+
this.sessionManager.appendSessionInfo(name);
|
|
3160
|
+
const event = { type: "session_info_changed", name: this.sessionManager.getSessionName() };
|
|
3161
|
+
this._emit(event);
|
|
3162
|
+
void this._extensionRunner.emit(event);
|
|
3163
|
+
}
|
|
3164
|
+
// =========================================================================
|
|
3165
|
+
// Tree Navigation
|
|
3166
|
+
// =========================================================================
|
|
3167
|
+
/**
|
|
3168
|
+
* Navigate to a different node in the session tree.
|
|
3169
|
+
* Unlike fork() which creates a new session file, this stays in the same file.
|
|
3170
|
+
*
|
|
3171
|
+
* @param targetId The entry ID to navigate to
|
|
3172
|
+
* @param options.summarize Whether user wants to summarize abandoned branch
|
|
3173
|
+
* @param options.customInstructions Custom instructions for summarizer
|
|
3174
|
+
* @param options.replaceInstructions If true, customInstructions replaces the default prompt
|
|
3175
|
+
* @param options.label Label to attach to the branch summary entry
|
|
3176
|
+
* @returns Result with editorText (if user message) and cancelled status
|
|
3177
|
+
*/
|
|
3178
|
+
async navigateTree(targetId, options = {}) {
|
|
3179
|
+
if (this.isStreaming) {
|
|
3180
|
+
throw new Error("Wait for the current response to finish before navigating the session tree.");
|
|
3181
|
+
}
|
|
3182
|
+
if (this.isCompacting) {
|
|
3183
|
+
throw new Error("Wait for the current compaction or tree navigation to finish before navigating the session tree.");
|
|
3184
|
+
}
|
|
3185
|
+
const oldLeafId = this.sessionManager.getLeafId();
|
|
3186
|
+
// No-op if already at target
|
|
3187
|
+
if (targetId === oldLeafId) {
|
|
3188
|
+
return { cancelled: false };
|
|
3189
|
+
}
|
|
3190
|
+
// Model required for summarization
|
|
3191
|
+
if (options.summarize && !this.model) {
|
|
3192
|
+
throw new Error("No model available for summarization");
|
|
3193
|
+
}
|
|
3194
|
+
const targetEntry = this.sessionManager.getEntry(targetId);
|
|
3195
|
+
if (!targetEntry) {
|
|
3196
|
+
throw new Error(`Entry ${targetId} not found`);
|
|
3197
|
+
}
|
|
3198
|
+
// Collect entries to summarize (from old leaf to common ancestor)
|
|
3199
|
+
const { entries: entriesToSummarize, commonAncestorId } = collectEntriesForBranchSummary(this.sessionManager, oldLeafId, targetId);
|
|
3200
|
+
// Prepare event data - mutable so extensions can override
|
|
3201
|
+
let customInstructions = options.customInstructions;
|
|
3202
|
+
let replaceInstructions = options.replaceInstructions;
|
|
3203
|
+
let label = options.label;
|
|
3204
|
+
const preparation = {
|
|
3205
|
+
targetId,
|
|
3206
|
+
oldLeafId,
|
|
3207
|
+
commonAncestorId,
|
|
3208
|
+
entriesToSummarize,
|
|
3209
|
+
userWantsSummary: options.summarize ?? false,
|
|
3210
|
+
customInstructions,
|
|
3211
|
+
replaceInstructions,
|
|
3212
|
+
label,
|
|
3213
|
+
};
|
|
3214
|
+
// Set up abort controller for summarization
|
|
3215
|
+
this._branchSummaryAbortController = new AbortController();
|
|
3216
|
+
try {
|
|
3217
|
+
let extensionSummary;
|
|
3218
|
+
let fromExtension = false;
|
|
3219
|
+
// Emit session_before_tree event
|
|
3220
|
+
if (this._extensionRunner.hasHandlers("session_before_tree")) {
|
|
3221
|
+
const result = (await this._extensionRunner.emit({
|
|
3222
|
+
type: "session_before_tree",
|
|
3223
|
+
preparation,
|
|
3224
|
+
signal: this._branchSummaryAbortController.signal,
|
|
3225
|
+
}));
|
|
3226
|
+
if (result?.cancel) {
|
|
3227
|
+
return { cancelled: true };
|
|
3228
|
+
}
|
|
3229
|
+
if (result?.summary && options.summarize) {
|
|
3230
|
+
extensionSummary = result.summary;
|
|
3231
|
+
fromExtension = true;
|
|
3232
|
+
}
|
|
3233
|
+
// Allow extensions to override instructions and label
|
|
3234
|
+
if (result?.customInstructions !== undefined) {
|
|
3235
|
+
customInstructions = result.customInstructions;
|
|
3236
|
+
}
|
|
3237
|
+
if (result?.replaceInstructions !== undefined) {
|
|
3238
|
+
replaceInstructions = result.replaceInstructions;
|
|
3239
|
+
}
|
|
3240
|
+
if (result?.label !== undefined) {
|
|
3241
|
+
label = result.label;
|
|
3242
|
+
}
|
|
3243
|
+
}
|
|
3244
|
+
// Run default summarizer if needed
|
|
3245
|
+
let summaryText;
|
|
3246
|
+
let summaryDetails;
|
|
3247
|
+
let summaryUsage;
|
|
3248
|
+
if (options.summarize && entriesToSummarize.length > 0 && !extensionSummary) {
|
|
3249
|
+
const signal = this._branchSummaryAbortController.signal;
|
|
3250
|
+
const branchSummarySettings = this.settingsManager.getBranchSummarySettings();
|
|
3251
|
+
const result = await generateBranchSummary(entriesToSummarize, {
|
|
3252
|
+
...(await this._getSummarizationRequestAuth(this.model, signal)),
|
|
3253
|
+
signal,
|
|
3254
|
+
customInstructions,
|
|
3255
|
+
replaceInstructions,
|
|
3256
|
+
reserveTokens: branchSummarySettings.reserveTokens,
|
|
3257
|
+
streamFn: this.agent.streamFunction,
|
|
3258
|
+
retry: this.settingsManager.getRetrySettings(),
|
|
3259
|
+
callbacks: this._summarizationRetryCallbacks({ source: "branchSummary" }),
|
|
3260
|
+
});
|
|
3261
|
+
if (result.aborted) {
|
|
3262
|
+
return { cancelled: true, aborted: true };
|
|
3263
|
+
}
|
|
3264
|
+
if (result.error) {
|
|
3265
|
+
throw new Error(result.error);
|
|
3266
|
+
}
|
|
3267
|
+
summaryText = result.summary;
|
|
3268
|
+
summaryUsage = result.usage;
|
|
3269
|
+
summaryDetails = {
|
|
3270
|
+
readFiles: result.readFiles || [],
|
|
3271
|
+
modifiedFiles: result.modifiedFiles || [],
|
|
3272
|
+
};
|
|
3273
|
+
}
|
|
3274
|
+
else if (extensionSummary) {
|
|
3275
|
+
summaryText = extensionSummary.summary;
|
|
3276
|
+
summaryDetails = extensionSummary.details;
|
|
3277
|
+
summaryUsage = extensionSummary.usage;
|
|
3278
|
+
}
|
|
3279
|
+
// Determine the new leaf position based on target type
|
|
3280
|
+
let newLeafId;
|
|
3281
|
+
let editorText;
|
|
3282
|
+
if (targetEntry.type === "message" && targetEntry.message.role === "user") {
|
|
3283
|
+
// User message: leaf = parent (null if root), text goes to editor
|
|
3284
|
+
newLeafId = targetEntry.parentId;
|
|
3285
|
+
editorText = contentText(targetEntry.message.content, "");
|
|
3286
|
+
}
|
|
3287
|
+
else if (targetEntry.type === "custom_message") {
|
|
3288
|
+
// Custom message: leaf = parent (null if root), text goes to editor
|
|
3289
|
+
newLeafId = targetEntry.parentId;
|
|
3290
|
+
editorText = contentText(targetEntry.content, "");
|
|
3291
|
+
}
|
|
3292
|
+
else {
|
|
3293
|
+
// Non-user message: leaf = selected node
|
|
3294
|
+
newLeafId = targetId;
|
|
3295
|
+
}
|
|
3296
|
+
// Switch leaf (with or without summary)
|
|
3297
|
+
// Summary is attached at the navigation target position (newLeafId), not the old branch
|
|
3298
|
+
let summaryEntry;
|
|
3299
|
+
if (summaryText) {
|
|
3300
|
+
// Create summary at target position (can be null for root)
|
|
3301
|
+
const summaryId = this.sessionManager.branchWithSummary(newLeafId, summaryText, summaryDetails, fromExtension, summaryUsage);
|
|
3302
|
+
summaryEntry = this.sessionManager.getEntry(summaryId);
|
|
3303
|
+
// Attach label to the summary entry
|
|
3304
|
+
if (label) {
|
|
3305
|
+
this.sessionManager.appendLabelChange(summaryId, label);
|
|
3306
|
+
}
|
|
3307
|
+
}
|
|
3308
|
+
else if (newLeafId === null) {
|
|
3309
|
+
// No summary, navigating to root - reset leaf
|
|
3310
|
+
this.sessionManager.resetLeaf();
|
|
3311
|
+
}
|
|
3312
|
+
else {
|
|
3313
|
+
// No summary, navigating to non-root
|
|
3314
|
+
this.sessionManager.branch(newLeafId);
|
|
3315
|
+
}
|
|
3316
|
+
// Attach label to target entry when not summarizing (no summary entry to label)
|
|
3317
|
+
if (label && !summaryText) {
|
|
3318
|
+
this.sessionManager.appendLabelChange(targetId, label);
|
|
3319
|
+
}
|
|
3320
|
+
// Update finalized context from the canonical session projection.
|
|
3321
|
+
this._refreshFinalizedContext();
|
|
3322
|
+
this._restoreToolsFromTranscript();
|
|
3323
|
+
// Emit session_tree event
|
|
3324
|
+
await this._extensionRunner.emit({
|
|
3325
|
+
type: "session_tree",
|
|
3326
|
+
newLeafId: this.sessionManager.getLeafId(),
|
|
3327
|
+
oldLeafId,
|
|
3328
|
+
summaryEntry,
|
|
3329
|
+
fromExtension: summaryText ? fromExtension : undefined,
|
|
3330
|
+
});
|
|
3331
|
+
// Emit to custom tools
|
|
3332
|
+
return { editorText, cancelled: false, summaryEntry };
|
|
3333
|
+
}
|
|
3334
|
+
finally {
|
|
3335
|
+
this._branchSummaryAbortController = undefined;
|
|
3336
|
+
this._resolveIdleWaitIfIdle();
|
|
3337
|
+
}
|
|
3338
|
+
}
|
|
3339
|
+
/**
|
|
3340
|
+
* Get all user messages from session for fork selector.
|
|
3341
|
+
*/
|
|
3342
|
+
getUserMessagesForForking() {
|
|
3343
|
+
const entries = this.sessionManager.getEntries();
|
|
3344
|
+
const result = [];
|
|
3345
|
+
for (const entry of entries) {
|
|
3346
|
+
if (entry.type !== "message")
|
|
3347
|
+
continue;
|
|
3348
|
+
if (entry.message.role !== "user")
|
|
3349
|
+
continue;
|
|
3350
|
+
const text = contentText(entry.message.content, "");
|
|
3351
|
+
if (text) {
|
|
3352
|
+
result.push({ entryId: entry.id, text });
|
|
3353
|
+
}
|
|
3354
|
+
}
|
|
3355
|
+
return result;
|
|
3356
|
+
}
|
|
3357
|
+
/**
|
|
3358
|
+
* Get session statistics. Aggregates over ALL session entries (including
|
|
3359
|
+
* history that was compacted away), so token/cost totals reflect what was
|
|
3360
|
+
* actually billed across the session.
|
|
3361
|
+
*/
|
|
3362
|
+
getSessionStats() {
|
|
3363
|
+
let userMessages = 0;
|
|
3364
|
+
let assistantMessages = 0;
|
|
3365
|
+
let toolResults = 0;
|
|
3366
|
+
let totalMessages = 0;
|
|
3367
|
+
let toolCalls = 0;
|
|
3368
|
+
const usageTotals = createUsageTotals();
|
|
3369
|
+
for (const entry of this.sessionManager.getEntries()) {
|
|
3370
|
+
if (entry.type === "usage") {
|
|
3371
|
+
addUsageToTotals(usageTotals, entry.usage);
|
|
3372
|
+
}
|
|
3373
|
+
else if ((entry.type === "branch_summary" || entry.type === "compaction") && entry.usage) {
|
|
3374
|
+
addUsageToTotals(usageTotals, entry.usage);
|
|
3375
|
+
}
|
|
3376
|
+
if (entry.type !== "message")
|
|
3377
|
+
continue;
|
|
3378
|
+
totalMessages++;
|
|
3379
|
+
const message = entry.message;
|
|
3380
|
+
if (message.role === "user") {
|
|
3381
|
+
userMessages++;
|
|
3382
|
+
}
|
|
3383
|
+
else if (message.role === "toolResult") {
|
|
3384
|
+
toolResults++;
|
|
3385
|
+
if (message.usage) {
|
|
3386
|
+
addUsageToTotals(usageTotals, message.usage);
|
|
3387
|
+
}
|
|
3388
|
+
}
|
|
3389
|
+
else if (message.role === "assistant") {
|
|
3390
|
+
assistantMessages++;
|
|
3391
|
+
const assistantMsg = message;
|
|
3392
|
+
if (Array.isArray(assistantMsg.content)) {
|
|
3393
|
+
toolCalls += assistantMsg.content.filter((c) => c.type === "toolCall").length;
|
|
3394
|
+
}
|
|
3395
|
+
addUsageToTotals(usageTotals, assistantMsg.usage);
|
|
3396
|
+
}
|
|
3397
|
+
}
|
|
3398
|
+
return {
|
|
3399
|
+
sessionFile: this.sessionFile,
|
|
3400
|
+
sessionId: this.sessionId,
|
|
3401
|
+
userMessages,
|
|
3402
|
+
assistantMessages,
|
|
3403
|
+
toolCalls,
|
|
3404
|
+
toolResults,
|
|
3405
|
+
totalMessages,
|
|
3406
|
+
tokens: {
|
|
3407
|
+
input: usageTotals.input,
|
|
3408
|
+
output: usageTotals.output,
|
|
3409
|
+
cacheRead: usageTotals.cacheRead,
|
|
3410
|
+
cacheWrite: usageTotals.cacheWrite,
|
|
3411
|
+
total: usageTotals.input + usageTotals.output + usageTotals.cacheRead + usageTotals.cacheWrite,
|
|
3412
|
+
},
|
|
3413
|
+
cost: usageTotals.cost,
|
|
3414
|
+
contextUsage: this.getContextUsage(),
|
|
3415
|
+
};
|
|
3416
|
+
}
|
|
3417
|
+
getContextUsage() {
|
|
3418
|
+
const model = this._limitsModel();
|
|
3419
|
+
if (!model)
|
|
3420
|
+
return undefined;
|
|
3421
|
+
const contextWindow = model.contextWindow ?? 0;
|
|
3422
|
+
if (contextWindow <= 0)
|
|
3423
|
+
return undefined;
|
|
3424
|
+
// After compaction, the last assistant usage reflects pre-compaction context size.
|
|
3425
|
+
// We can only trust usage from an assistant that responded after the latest compaction.
|
|
3426
|
+
// If no such assistant exists, context token count is unknown until the next LLM response.
|
|
3427
|
+
const projection = this.sessionManager.buildSessionProjection();
|
|
3428
|
+
const branch = this.sessionManager.getBranch();
|
|
3429
|
+
const latestCompaction = getLatestCompactionEntry(branch);
|
|
3430
|
+
if (latestCompaction) {
|
|
3431
|
+
const projectedAssistants = new Set(projection.entries.flatMap((entry) => entry.messages.some((message) => message.role === "assistant" &&
|
|
3432
|
+
message.stopReason !== "aborted" &&
|
|
3433
|
+
message.stopReason !== "error" &&
|
|
3434
|
+
calculateContextTokens(message.usage) > 0)
|
|
3435
|
+
? [entry.sourceEntry.id]
|
|
3436
|
+
: []));
|
|
3437
|
+
const compactionIndex = branch.findIndex((entry) => entry.id === latestCompaction.id);
|
|
3438
|
+
const hasPostCompactionUsage = branch
|
|
3439
|
+
.slice(compactionIndex + 1)
|
|
3440
|
+
.some((entry) => projectedAssistants.has(entry.id));
|
|
3441
|
+
if (!hasPostCompactionUsage)
|
|
3442
|
+
return { tokens: null, contextWindow, percent: null };
|
|
3443
|
+
}
|
|
3444
|
+
const estimate = estimateProjectedContextTokens(projection, branch);
|
|
3445
|
+
const percent = (estimate.tokens / contextWindow) * 100;
|
|
3446
|
+
return {
|
|
3447
|
+
tokens: estimate.tokens,
|
|
3448
|
+
contextWindow,
|
|
3449
|
+
percent,
|
|
3450
|
+
};
|
|
3451
|
+
}
|
|
3452
|
+
/**
|
|
3453
|
+
* Export session to HTML.
|
|
3454
|
+
* @param outputPath Optional output path (defaults to session directory)
|
|
3455
|
+
* @param options Optional export presentation settings
|
|
3456
|
+
* @returns Path to exported file
|
|
3457
|
+
*/
|
|
3458
|
+
async exportToHtml(outputPath, options = {}) {
|
|
3459
|
+
const themeName = [options.themeName, this.settingsManager.getTheme()].find((candidate) => candidate !== undefined && getThemeByName(candidate) !== undefined);
|
|
3460
|
+
// Create tool renderer if we have an extension runner (for custom tool HTML rendering)
|
|
3461
|
+
const toolRenderer = createToolHtmlRenderer({
|
|
3462
|
+
getToolRenderers: (name) => this._extensionRunner.resolveToolRenderers(name, () => this.getToolDefinition(name)),
|
|
3463
|
+
theme,
|
|
3464
|
+
cwd: this.sessionManager.getCwd(),
|
|
3465
|
+
});
|
|
3466
|
+
return await exportSessionToHtml(this.sessionManager, this.state, {
|
|
3467
|
+
outputPath,
|
|
3468
|
+
themeName,
|
|
3469
|
+
toolRenderer,
|
|
3470
|
+
});
|
|
3471
|
+
}
|
|
3472
|
+
/**
|
|
3473
|
+
* Export the current session branch to a JSONL file.
|
|
3474
|
+
* Writes the session header followed by all entries on the current branch path.
|
|
3475
|
+
* @param outputPath Target file path. If omitted, generates a timestamped file in cwd.
|
|
3476
|
+
* @returns The resolved output file path.
|
|
3477
|
+
*/
|
|
3478
|
+
exportToJsonl(outputPath) {
|
|
3479
|
+
return exportSessionToJsonl(this.sessionManager, outputPath);
|
|
3480
|
+
}
|
|
3481
|
+
/**
|
|
3482
|
+
* Ask the current model to describe what went wrong in this session for a bug report.
|
|
3483
|
+
* Used when the user declines to share the transcript itself.
|
|
3484
|
+
*/
|
|
3485
|
+
async summarizeForBugReport(options) {
|
|
3486
|
+
const model = this.model;
|
|
3487
|
+
if (!model) {
|
|
3488
|
+
throw new Error("No model selected");
|
|
3489
|
+
}
|
|
3490
|
+
return generateBugReportSummary({
|
|
3491
|
+
...(await this._getSummarizationRequestAuth(model, options.signal)),
|
|
3492
|
+
messages: this.messages,
|
|
3493
|
+
hint: options.hint,
|
|
3494
|
+
signal: options.signal,
|
|
3495
|
+
streamFn: this.agent.streamFunction,
|
|
3496
|
+
retry: this.settingsManager.getRetrySettings(),
|
|
3497
|
+
sessionId: this.sessionId,
|
|
3498
|
+
});
|
|
3499
|
+
}
|
|
3500
|
+
// =========================================================================
|
|
3501
|
+
// Utilities
|
|
3502
|
+
// =========================================================================
|
|
3503
|
+
/**
|
|
3504
|
+
* Get text content of last assistant message.
|
|
3505
|
+
* Useful for /copy command.
|
|
3506
|
+
* @returns Text content, or undefined if no assistant message exists
|
|
3507
|
+
*/
|
|
3508
|
+
getLastAssistantText() {
|
|
3509
|
+
const lastAssistant = this.messages
|
|
3510
|
+
.slice()
|
|
3511
|
+
.reverse()
|
|
3512
|
+
.find((m) => {
|
|
3513
|
+
if (m.role !== "assistant")
|
|
3514
|
+
return false;
|
|
3515
|
+
const msg = m;
|
|
3516
|
+
// Skip aborted messages with no content
|
|
3517
|
+
if (msg.stopReason === "aborted" && msg.content.length === 0)
|
|
3518
|
+
return false;
|
|
3519
|
+
return true;
|
|
3520
|
+
});
|
|
3521
|
+
if (!lastAssistant)
|
|
3522
|
+
return undefined;
|
|
3523
|
+
let text = "";
|
|
3524
|
+
for (const content of lastAssistant.content) {
|
|
3525
|
+
if (content.type === "text") {
|
|
3526
|
+
text += content.text;
|
|
3527
|
+
}
|
|
3528
|
+
}
|
|
3529
|
+
return text.trim() || undefined;
|
|
3530
|
+
}
|
|
3531
|
+
// =========================================================================
|
|
3532
|
+
// Extension System
|
|
3533
|
+
// =========================================================================
|
|
3534
|
+
createReplacedSessionContext() {
|
|
3535
|
+
const context = Object.defineProperties({}, Object.getOwnPropertyDescriptors(this._extensionRunner.createCommandContext()));
|
|
3536
|
+
context.sendMessage = (message, options) => this.sendCustomMessage(message, options);
|
|
3537
|
+
context.sendUserMessage = (content, options) => this.sendUserMessage(content, options);
|
|
3538
|
+
return context;
|
|
3539
|
+
}
|
|
3540
|
+
/**
|
|
3541
|
+
* Check if extensions have handlers for a specific event type.
|
|
3542
|
+
*/
|
|
3543
|
+
hasExtensionHandlers(eventType) {
|
|
3544
|
+
return this._extensionRunner.hasHandlers(eventType);
|
|
3545
|
+
}
|
|
3546
|
+
/**
|
|
3547
|
+
* Get the extension runner (for setting UI context and error handlers).
|
|
3548
|
+
*/
|
|
3549
|
+
get extensionRunner() {
|
|
3550
|
+
return this._extensionRunner;
|
|
3551
|
+
}
|
|
3552
|
+
}
|
|
3553
|
+
//# sourceMappingURL=agent-session.js.map
|