@draht/coding-agent 2026.7.13 → 2026.9.5-1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +241 -0
- package/README.md +47 -2
- package/agents/debugger.md +12 -1
- package/agents/git-committer.md +1 -0
- package/agents/implementer.md +20 -0
- package/agents/investigator.md +75 -0
- package/agents/reviewer.md +7 -0
- package/agents/spec-reviewer.md +66 -0
- package/agents/verifier.md +4 -3
- package/bin/draht-tools.cjs +472 -41
- package/dist/agents/debugger.md +12 -1
- package/dist/agents/git-committer.md +1 -0
- package/dist/agents/implementer.md +20 -0
- package/dist/agents/investigator.md +75 -0
- package/dist/agents/reviewer.md +7 -0
- package/dist/agents/spec-reviewer.md +66 -0
- package/dist/agents/verifier.md +4 -3
- package/dist/bun/cli.js +2 -0
- package/dist/bun/cli.js.map +1 -1
- package/dist/cli/args.d.ts +10 -0
- package/dist/cli/args.d.ts.map +1 -1
- package/dist/cli/args.js +80 -3
- package/dist/cli/args.js.map +1 -1
- package/dist/cli/attach-mode.d.ts +61 -0
- package/dist/cli/attach-mode.d.ts.map +1 -1
- package/dist/cli/attach-mode.js +243 -5
- package/dist/cli/attach-mode.js.map +1 -1
- package/dist/cli/config-selector.js +1 -1
- package/dist/cli/config-selector.js.map +1 -1
- package/dist/cli/credential-print.d.ts +23 -0
- package/dist/cli/credential-print.d.ts.map +1 -0
- package/dist/cli/credential-print.js +117 -0
- package/dist/cli/credential-print.js.map +1 -0
- package/dist/cli/list-models.d.ts +2 -2
- package/dist/cli/list-models.d.ts.map +1 -1
- package/dist/cli/list-models.js +3 -3
- package/dist/cli/list-models.js.map +1 -1
- package/dist/cli/startup-ui.js +1 -1
- package/dist/cli/startup-ui.js.map +1 -1
- package/dist/config.d.ts +9 -0
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +31 -4
- package/dist/config.js.map +1 -1
- package/dist/core/agent-session-runtime.d.ts +17 -1
- package/dist/core/agent-session-runtime.d.ts.map +1 -1
- package/dist/core/agent-session-runtime.js +90 -30
- package/dist/core/agent-session-runtime.js.map +1 -1
- package/dist/core/agent-session-services.d.ts +4 -7
- package/dist/core/agent-session-services.d.ts.map +1 -1
- package/dist/core/agent-session-services.js +24 -9
- package/dist/core/agent-session-services.js.map +1 -1
- package/dist/core/agent-session.d.ts +87 -27
- package/dist/core/agent-session.d.ts.map +1 -1
- package/dist/core/agent-session.js +337 -154
- package/dist/core/agent-session.js.map +1 -1
- package/dist/core/auth-storage.d.ts +20 -104
- package/dist/core/auth-storage.d.ts.map +1 -1
- package/dist/core/auth-storage.js +104 -260
- package/dist/core/auth-storage.js.map +1 -1
- package/dist/core/builtins/checkpoints.d.ts +20 -0
- package/dist/core/builtins/checkpoints.d.ts.map +1 -0
- package/dist/core/builtins/checkpoints.js +161 -0
- package/dist/core/builtins/checkpoints.js.map +1 -0
- package/dist/core/builtins/duet.d.ts +26 -0
- package/dist/core/builtins/duet.d.ts.map +1 -0
- package/dist/core/builtins/duet.js +660 -0
- package/dist/core/builtins/duet.js.map +1 -0
- package/dist/core/builtins/index.d.ts.map +1 -1
- package/dist/core/builtins/index.js +7 -1
- package/dist/core/builtins/index.js.map +1 -1
- package/dist/core/builtins/subagent.d.ts +24 -4
- package/dist/core/builtins/subagent.d.ts.map +1 -1
- package/dist/core/builtins/subagent.js +278 -35
- package/dist/core/builtins/subagent.js.map +1 -1
- package/dist/core/cache-stats.d.ts +2 -2
- package/dist/core/cache-stats.d.ts.map +1 -1
- package/dist/core/cache-stats.js +1 -1
- package/dist/core/cache-stats.js.map +1 -1
- package/dist/core/checkpoints/checkpoint-cli.d.ts +17 -0
- package/dist/core/checkpoints/checkpoint-cli.d.ts.map +1 -0
- package/dist/core/checkpoints/checkpoint-cli.js +78 -0
- package/dist/core/checkpoints/checkpoint-cli.js.map +1 -0
- package/dist/core/checkpoints/checkpoint-manager.d.ts +294 -0
- package/dist/core/checkpoints/checkpoint-manager.d.ts.map +1 -0
- package/dist/core/checkpoints/checkpoint-manager.js +865 -0
- package/dist/core/checkpoints/checkpoint-manager.js.map +1 -0
- package/dist/core/checkpoints/rewind.d.ts +141 -0
- package/dist/core/checkpoints/rewind.d.ts.map +1 -0
- package/dist/core/checkpoints/rewind.js +246 -0
- package/dist/core/checkpoints/rewind.js.map +1 -0
- package/dist/core/compaction/branch-summarization.d.ts +9 -3
- package/dist/core/compaction/branch-summarization.d.ts.map +1 -1
- package/dist/core/compaction/branch-summarization.js +16 -14
- package/dist/core/compaction/branch-summarization.js.map +1 -1
- package/dist/core/compaction/compaction.d.ts +24 -3
- package/dist/core/compaction/compaction.d.ts.map +1 -1
- package/dist/core/compaction/compaction.js +96 -30
- package/dist/core/compaction/compaction.js.map +1 -1
- package/dist/core/compaction/utils.d.ts +1 -1
- package/dist/core/compaction/utils.d.ts.map +1 -1
- package/dist/core/compaction/utils.js +6 -17
- package/dist/core/compaction/utils.js.map +1 -1
- package/dist/core/context-windows.d.ts +7 -0
- package/dist/core/context-windows.d.ts.map +1 -0
- package/dist/core/context-windows.js +35 -0
- package/dist/core/context-windows.js.map +1 -0
- package/dist/core/extensions/index.d.ts +1 -1
- package/dist/core/extensions/index.d.ts.map +1 -1
- package/dist/core/extensions/index.js.map +1 -1
- package/dist/core/extensions/loader.d.ts.map +1 -1
- package/dist/core/extensions/loader.js +101 -23
- package/dist/core/extensions/loader.js.map +1 -1
- package/dist/core/extensions/runner.d.ts +19 -3
- package/dist/core/extensions/runner.d.ts.map +1 -1
- package/dist/core/extensions/runner.js +117 -2
- package/dist/core/extensions/runner.js.map +1 -1
- package/dist/core/extensions/types.d.ts +236 -9
- package/dist/core/extensions/types.d.ts.map +1 -1
- package/dist/core/extensions/types.js.map +1 -1
- package/dist/core/extensions/wrapper.d.ts.map +1 -1
- package/dist/core/extensions/wrapper.js +22 -3
- package/dist/core/extensions/wrapper.js.map +1 -1
- package/dist/core/footer-data-provider.d.ts +10 -0
- package/dist/core/footer-data-provider.d.ts.map +1 -1
- package/dist/core/footer-data-provider.js +1 -1
- package/dist/core/footer-data-provider.js.map +1 -1
- package/dist/core/http-dispatcher.d.ts.map +1 -1
- package/dist/core/http-dispatcher.js +7 -0
- package/dist/core/http-dispatcher.js.map +1 -1
- package/dist/core/index.d.ts +1 -1
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/index.js.map +1 -1
- package/dist/core/keybindings.d.ts +18 -3
- package/dist/core/keybindings.d.ts.map +1 -1
- package/dist/core/keybindings.js +12 -3
- package/dist/core/keybindings.js.map +1 -1
- package/dist/core/model-config.d.ts +542 -0
- package/dist/core/model-config.d.ts.map +1 -0
- package/dist/core/model-config.js +247 -0
- package/dist/core/model-config.js.map +1 -0
- package/dist/core/model-registry.d.ts +19 -124
- package/dist/core/model-registry.d.ts.map +1 -1
- package/dist/core/model-registry.js +56 -727
- package/dist/core/model-registry.js.map +1 -1
- package/dist/core/model-resolver.d.ts +7 -6
- package/dist/core/model-resolver.d.ts.map +1 -1
- package/dist/core/model-resolver.js +74 -27
- package/dist/core/model-resolver.js.map +1 -1
- package/dist/core/model-runtime.d.ts +89 -0
- package/dist/core/model-runtime.d.ts.map +1 -0
- package/dist/core/model-runtime.js +451 -0
- package/dist/core/model-runtime.js.map +1 -0
- package/dist/core/models-store.d.ts +17 -0
- package/dist/core/models-store.d.ts.map +1 -0
- package/dist/core/models-store.js +46 -0
- package/dist/core/models-store.js.map +1 -0
- package/dist/core/multi-agent/permission-gate.d.ts.map +1 -1
- package/dist/core/multi-agent/permission-gate.js +4 -3
- package/dist/core/multi-agent/permission-gate.js.map +1 -1
- package/dist/core/multi-agent/worktree.d.ts +2 -0
- package/dist/core/multi-agent/worktree.d.ts.map +1 -1
- package/dist/core/multi-agent/worktree.js +2 -2
- package/dist/core/multi-agent/worktree.js.map +1 -1
- package/dist/core/package-manager.d.ts +7 -1
- package/dist/core/package-manager.d.ts.map +1 -1
- package/dist/core/package-manager.js +41 -45
- package/dist/core/package-manager.js.map +1 -1
- package/dist/core/permission-relay/index.d.ts +19 -0
- package/dist/core/permission-relay/index.d.ts.map +1 -0
- package/dist/core/permission-relay/index.js +49 -0
- package/dist/core/permission-relay/index.js.map +1 -0
- package/dist/core/permission-relay/relay-ui-context.d.ts +39 -0
- package/dist/core/permission-relay/relay-ui-context.d.ts.map +1 -0
- package/dist/core/permission-relay/relay-ui-context.js +788 -0
- package/dist/core/permission-relay/relay-ui-context.js.map +1 -0
- package/dist/core/permission-relay/types.d.ts +222 -0
- package/dist/core/permission-relay/types.d.ts.map +1 -0
- package/dist/core/permission-relay/types.js +15 -0
- package/dist/core/permission-relay/types.js.map +1 -0
- package/dist/core/pi-manifest.d.ts +14 -0
- package/dist/core/pi-manifest.d.ts.map +1 -0
- package/dist/core/pi-manifest.js +35 -0
- package/dist/core/pi-manifest.js.map +1 -0
- package/dist/core/project-trust.js +2 -2
- package/dist/core/project-trust.js.map +1 -1
- package/dist/core/prompt-templates.d.ts +1 -0
- package/dist/core/prompt-templates.d.ts.map +1 -1
- package/dist/core/prompt-templates.js +4 -4
- package/dist/core/prompt-templates.js.map +1 -1
- package/dist/core/provider-composer.d.ts +55 -0
- package/dist/core/provider-composer.d.ts.map +1 -0
- package/dist/core/provider-composer.js +375 -0
- package/dist/core/provider-composer.js.map +1 -0
- package/dist/core/radius.d.ts +2 -0
- package/dist/core/radius.d.ts.map +1 -0
- package/dist/core/radius.js +2 -0
- package/dist/core/radius.js.map +1 -0
- package/dist/core/remote-catalog-provider.d.ts +5 -0
- package/dist/core/remote-catalog-provider.d.ts.map +1 -0
- package/dist/core/remote-catalog-provider.js +115 -0
- package/dist/core/remote-catalog-provider.js.map +1 -0
- package/dist/core/resource-loader.d.ts +36 -0
- package/dist/core/resource-loader.d.ts.map +1 -1
- package/dist/core/resource-loader.js +159 -27
- package/dist/core/resource-loader.js.map +1 -1
- package/dist/core/runtime-credentials.d.ts +15 -0
- package/dist/core/runtime-credentials.d.ts.map +1 -0
- package/dist/core/runtime-credentials.js +35 -0
- package/dist/core/runtime-credentials.js.map +1 -0
- package/dist/core/sandbox/bash-operations.d.ts +149 -0
- package/dist/core/sandbox/bash-operations.d.ts.map +1 -0
- package/dist/core/sandbox/bash-operations.js +163 -0
- package/dist/core/sandbox/bash-operations.js.map +1 -0
- package/dist/core/sandbox/env.d.ts +83 -0
- package/dist/core/sandbox/env.d.ts.map +1 -0
- package/dist/core/sandbox/env.js +123 -0
- package/dist/core/sandbox/env.js.map +1 -0
- package/dist/core/sandbox/executor.d.ts +104 -0
- package/dist/core/sandbox/executor.d.ts.map +1 -0
- package/dist/core/sandbox/executor.js +92 -0
- package/dist/core/sandbox/executor.js.map +1 -0
- package/dist/core/sandbox/index.d.ts +36 -0
- package/dist/core/sandbox/index.d.ts.map +1 -0
- package/dist/core/sandbox/index.js +36 -0
- package/dist/core/sandbox/index.js.map +1 -0
- package/dist/core/sandbox/linux.d.ts +121 -0
- package/dist/core/sandbox/linux.d.ts.map +1 -0
- package/dist/core/sandbox/linux.js +260 -0
- package/dist/core/sandbox/linux.js.map +1 -0
- package/dist/core/sandbox/policy.d.ts +142 -0
- package/dist/core/sandbox/policy.d.ts.map +1 -0
- package/dist/core/sandbox/policy.js +297 -0
- package/dist/core/sandbox/policy.js.map +1 -0
- package/dist/core/sandbox/real-path.d.ts +112 -0
- package/dist/core/sandbox/real-path.d.ts.map +1 -0
- package/dist/core/sandbox/real-path.js +158 -0
- package/dist/core/sandbox/real-path.js.map +1 -0
- package/dist/core/sandbox/seatbelt-profile.d.ts +95 -0
- package/dist/core/sandbox/seatbelt-profile.d.ts.map +1 -0
- package/dist/core/sandbox/seatbelt-profile.js +239 -0
- package/dist/core/sandbox/seatbelt-profile.js.map +1 -0
- package/dist/core/sandbox/seatbelt.d.ts +95 -0
- package/dist/core/sandbox/seatbelt.d.ts.map +1 -0
- package/dist/core/sandbox/seatbelt.js +154 -0
- package/dist/core/sandbox/seatbelt.js.map +1 -0
- package/dist/core/sandbox/self-test.d.ts +109 -0
- package/dist/core/sandbox/self-test.d.ts.map +1 -0
- package/dist/core/sandbox/self-test.js +369 -0
- package/dist/core/sandbox/self-test.js.map +1 -0
- package/dist/core/sandbox/spawn.d.ts +33 -0
- package/dist/core/sandbox/spawn.d.ts.map +1 -0
- package/dist/core/sandbox/spawn.js +87 -0
- package/dist/core/sandbox/spawn.js.map +1 -0
- package/dist/core/sdk.d.ts +3 -6
- package/dist/core/sdk.d.ts.map +1 -1
- package/dist/core/sdk.js +25 -22
- package/dist/core/sdk.js.map +1 -1
- package/dist/core/session-manager.d.ts +74 -7
- package/dist/core/session-manager.d.ts.map +1 -1
- package/dist/core/session-manager.js +169 -34
- package/dist/core/session-manager.js.map +1 -1
- package/dist/core/settings-manager.d.ts +22 -1
- package/dist/core/settings-manager.d.ts.map +1 -1
- package/dist/core/settings-manager.js +36 -16
- package/dist/core/settings-manager.js.map +1 -1
- package/dist/core/skills.d.ts +3 -1
- package/dist/core/skills.d.ts.map +1 -1
- package/dist/core/skills.js +19 -6
- package/dist/core/skills.js.map +1 -1
- package/dist/core/slash-commands.d.ts.map +1 -1
- package/dist/core/slash-commands.js +1 -0
- package/dist/core/slash-commands.js.map +1 -1
- package/dist/core/soak/soak-log.d.ts +298 -0
- package/dist/core/soak/soak-log.d.ts.map +1 -0
- package/dist/core/soak/soak-log.js +660 -0
- package/dist/core/soak/soak-log.js.map +1 -0
- package/dist/core/soak/soak-reader.d.ts +60 -0
- package/dist/core/soak/soak-reader.d.ts.map +1 -0
- package/dist/core/soak/soak-reader.js +106 -0
- package/dist/core/soak/soak-reader.js.map +1 -0
- package/dist/core/socket-server/discovery.d.ts +78 -1
- package/dist/core/socket-server/discovery.d.ts.map +1 -1
- package/dist/core/socket-server/discovery.js +356 -37
- package/dist/core/socket-server/discovery.js.map +1 -1
- package/dist/core/socket-server/index.d.ts +10 -4
- package/dist/core/socket-server/index.d.ts.map +1 -1
- package/dist/core/socket-server/index.js +6 -3
- package/dist/core/socket-server/index.js.map +1 -1
- package/dist/core/socket-server/permission-delivery.d.ts +125 -0
- package/dist/core/socket-server/permission-delivery.d.ts.map +1 -0
- package/dist/core/socket-server/permission-delivery.js +152 -0
- package/dist/core/socket-server/permission-delivery.js.map +1 -0
- package/dist/core/socket-server/permission-registry.d.ts +301 -0
- package/dist/core/socket-server/permission-registry.d.ts.map +1 -0
- package/dist/core/socket-server/permission-registry.js +410 -0
- package/dist/core/socket-server/permission-registry.js.map +1 -0
- package/dist/core/socket-server/permission-relay.d.ts +81 -0
- package/dist/core/socket-server/permission-relay.d.ts.map +1 -0
- package/dist/core/socket-server/permission-relay.js +528 -0
- package/dist/core/socket-server/permission-relay.js.map +1 -0
- package/dist/core/socket-server/safe-text.d.ts +83 -0
- package/dist/core/socket-server/safe-text.d.ts.map +1 -0
- package/dist/core/socket-server/safe-text.js +277 -0
- package/dist/core/socket-server/safe-text.js.map +1 -0
- package/dist/core/socket-server/session-integration.d.ts +65 -2
- package/dist/core/socket-server/session-integration.d.ts.map +1 -1
- package/dist/core/socket-server/session-integration.js +434 -32
- package/dist/core/socket-server/session-integration.js.map +1 -1
- package/dist/core/socket-server/socket-client.d.ts +21 -2
- package/dist/core/socket-server/socket-client.d.ts.map +1 -1
- package/dist/core/socket-server/socket-client.js +52 -1
- package/dist/core/socket-server/socket-client.js.map +1 -1
- package/dist/core/socket-server/socket-server.d.ts +152 -1
- package/dist/core/socket-server/socket-server.d.ts.map +1 -1
- package/dist/core/socket-server/socket-server.js +775 -26
- package/dist/core/socket-server/socket-server.js.map +1 -1
- package/dist/core/socket-server/types.d.ts +106 -2
- package/dist/core/socket-server/types.d.ts.map +1 -1
- package/dist/core/socket-server/types.js +13 -1
- package/dist/core/socket-server/types.js.map +1 -1
- package/dist/core/system-prompt.d.ts.map +1 -1
- package/dist/core/system-prompt.js +10 -21
- package/dist/core/system-prompt.js.map +1 -1
- package/dist/core/tools/bash.d.ts +3 -1
- package/dist/core/tools/bash.d.ts.map +1 -1
- package/dist/core/tools/bash.js +39 -7
- package/dist/core/tools/bash.js.map +1 -1
- package/dist/core/tools/edit.d.ts.map +1 -1
- package/dist/core/tools/edit.js +17 -2
- package/dist/core/tools/edit.js.map +1 -1
- package/dist/core/tools/find.d.ts +3 -0
- package/dist/core/tools/find.d.ts.map +1 -1
- package/dist/core/tools/find.js +11 -18
- package/dist/core/tools/find.js.map +1 -1
- package/dist/core/tools/read.js +1 -1
- package/dist/core/tools/read.js.map +1 -1
- package/dist/core/tools/tool-definition-wrapper.d.ts.map +1 -1
- package/dist/core/tools/tool-definition-wrapper.js +3 -1
- package/dist/core/tools/tool-definition-wrapper.js.map +1 -1
- package/dist/core/trust-manager.d.ts +6 -4
- package/dist/core/trust-manager.d.ts.map +1 -1
- package/dist/core/trust-manager.js +55 -21
- package/dist/core/trust-manager.js.map +1 -1
- package/dist/core/usage-totals.d.ts +19 -0
- package/dist/core/usage-totals.d.ts.map +1 -0
- package/dist/core/usage-totals.js +52 -0
- package/dist/core/usage-totals.js.map +1 -0
- package/dist/extensions/index.d.ts +3 -0
- package/dist/extensions/index.d.ts.map +1 -0
- package/dist/extensions/index.js +7 -0
- package/dist/extensions/index.js.map +1 -0
- package/dist/extensions/llama/client.d.ts +61 -0
- package/dist/extensions/llama/client.d.ts.map +1 -0
- package/dist/extensions/llama/client.js +300 -0
- package/dist/extensions/llama/client.js.map +1 -0
- package/dist/extensions/llama/huggingface.d.ts +23 -0
- package/dist/extensions/llama/huggingface.d.ts.map +1 -0
- package/dist/extensions/llama/huggingface.js +139 -0
- package/dist/extensions/llama/huggingface.js.map +1 -0
- package/dist/extensions/llama/index.d.ts +3 -0
- package/dist/extensions/llama/index.d.ts.map +1 -0
- package/dist/extensions/llama/index.js +208 -0
- package/dist/extensions/llama/index.js.map +1 -0
- package/dist/extensions/llama/provider.d.ts +10 -0
- package/dist/extensions/llama/provider.d.ts.map +1 -0
- package/dist/extensions/llama/provider.js +111 -0
- package/dist/extensions/llama/provider.js.map +1 -0
- package/dist/extensions/llama/ui.d.ts +42 -0
- package/dist/extensions/llama/ui.d.ts.map +1 -0
- package/dist/extensions/llama/ui.js +400 -0
- package/dist/extensions/llama/ui.js.map +1 -0
- package/dist/extensions/stub-provider/index.d.ts +9 -0
- package/dist/extensions/stub-provider/index.d.ts.map +1 -0
- package/dist/extensions/stub-provider/index.js +13 -0
- package/dist/extensions/stub-provider/index.js.map +1 -0
- package/dist/extensions/stub-provider/provider.d.ts +77 -0
- package/dist/extensions/stub-provider/provider.d.ts.map +1 -0
- package/dist/extensions/stub-provider/provider.js +193 -0
- package/dist/extensions/stub-provider/provider.js.map +1 -0
- package/dist/hooks/gsd/draht-quality-gate.js +3 -3
- package/dist/index.d.ts +4 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -3
- package/dist/index.js.map +1 -1
- package/dist/main.d.ts.map +1 -1
- package/dist/main.js +305 -61
- package/dist/main.js.map +1 -1
- package/dist/modes/interactive/components/assistant-message.d.ts.map +1 -1
- package/dist/modes/interactive/components/assistant-message.js +22 -10
- package/dist/modes/interactive/components/assistant-message.js.map +1 -1
- package/dist/modes/interactive/components/config-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/config-selector.js +3 -2
- package/dist/modes/interactive/components/config-selector.js.map +1 -1
- package/dist/modes/interactive/components/custom-editor.js +1 -1
- package/dist/modes/interactive/components/custom-editor.js.map +1 -1
- package/dist/modes/interactive/components/custom-message.d.ts +3 -1
- package/dist/modes/interactive/components/custom-message.d.ts.map +1 -1
- package/dist/modes/interactive/components/custom-message.js +9 -2
- package/dist/modes/interactive/components/custom-message.js.map +1 -1
- package/dist/modes/interactive/components/extension-editor.d.ts +1 -2
- package/dist/modes/interactive/components/extension-editor.d.ts.map +1 -1
- package/dist/modes/interactive/components/extension-editor.js +16 -46
- package/dist/modes/interactive/components/extension-editor.js.map +1 -1
- package/dist/modes/interactive/components/extension-selector.d.ts +49 -0
- package/dist/modes/interactive/components/extension-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/extension-selector.js +202 -5
- package/dist/modes/interactive/components/extension-selector.js.map +1 -1
- package/dist/modes/interactive/components/footer.d.ts.map +1 -1
- package/dist/modes/interactive/components/footer.js +24 -23
- package/dist/modes/interactive/components/footer.js.map +1 -1
- package/dist/modes/interactive/components/login-dialog.d.ts +5 -5
- package/dist/modes/interactive/components/login-dialog.d.ts.map +1 -1
- package/dist/modes/interactive/components/login-dialog.js +17 -8
- package/dist/modes/interactive/components/login-dialog.js.map +1 -1
- package/dist/modes/interactive/components/model-selector.d.ts +11 -4
- package/dist/modes/interactive/components/model-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/model-selector.js +74 -41
- package/dist/modes/interactive/components/model-selector.js.map +1 -1
- package/dist/modes/interactive/components/oauth-selector.d.ts +4 -4
- package/dist/modes/interactive/components/oauth-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/oauth-selector.js +14 -25
- package/dist/modes/interactive/components/oauth-selector.js.map +1 -1
- package/dist/modes/interactive/components/scoped-models-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/scoped-models-selector.js +22 -13
- package/dist/modes/interactive/components/scoped-models-selector.js.map +1 -1
- package/dist/modes/interactive/components/session-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/session-selector.js +10 -2
- package/dist/modes/interactive/components/session-selector.js.map +1 -1
- package/dist/modes/interactive/components/settings-selector.d.ts +2 -0
- package/dist/modes/interactive/components/settings-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/settings-selector.js +10 -0
- package/dist/modes/interactive/components/settings-selector.js.map +1 -1
- package/dist/modes/interactive/components/tool-execution.d.ts.map +1 -1
- package/dist/modes/interactive/components/tool-execution.js +10 -1
- package/dist/modes/interactive/components/tool-execution.js.map +1 -1
- package/dist/modes/interactive/components/tree-selector.d.ts +25 -2
- package/dist/modes/interactive/components/tree-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/tree-selector.js +68 -17
- package/dist/modes/interactive/components/tree-selector.js.map +1 -1
- package/dist/modes/interactive/external-editor.d.ts +12 -0
- package/dist/modes/interactive/external-editor.d.ts.map +1 -0
- package/dist/modes/interactive/external-editor.js +37 -0
- package/dist/modes/interactive/external-editor.js.map +1 -0
- package/dist/modes/interactive/interactive-mode.d.ts +107 -10
- package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode.js +763 -285
- package/dist/modes/interactive/interactive-mode.js.map +1 -1
- package/dist/modes/rpc/rpc-client.d.ts +4 -0
- package/dist/modes/rpc/rpc-client.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-client.js +7 -0
- package/dist/modes/rpc/rpc-client.js.map +1 -1
- package/dist/modes/rpc/rpc-mode.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-mode.js +185 -9
- package/dist/modes/rpc/rpc-mode.js.map +1 -1
- package/dist/modes/rpc/rpc-types.d.ts +79 -1
- package/dist/modes/rpc/rpc-types.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-types.js.map +1 -1
- package/dist/package-manager-cli.d.ts.map +1 -1
- package/dist/package-manager-cli.js +67 -5
- package/dist/package-manager-cli.js.map +1 -1
- package/dist/prompts/commands/atomic-commit.md +1 -12
- package/dist/prompts/commands/brainstorm.md +12 -15
- package/dist/prompts/commands/create-verification-skill.md +108 -0
- package/dist/prompts/commands/discuss-phase.md +3 -14
- package/dist/prompts/commands/execute-phase.md +3 -11
- package/dist/prompts/commands/fix.md +41 -18
- package/dist/prompts/commands/grill.md +66 -0
- package/dist/prompts/commands/init-project.md +5 -15
- package/dist/prompts/commands/map-codebase.md +1 -13
- package/dist/prompts/commands/new-project.md +5 -15
- package/dist/prompts/commands/next-milestone.md +1 -13
- package/dist/prompts/commands/orchestrate.md +1 -1
- package/dist/prompts/commands/pause-work.md +1 -13
- package/dist/prompts/commands/plan-phase.md +2 -11
- package/dist/prompts/commands/progress.md +0 -13
- package/dist/prompts/commands/quick.md +3 -11
- package/dist/prompts/commands/resolve-conflicts.md +71 -0
- package/dist/prompts/commands/resume-work.md +0 -13
- package/dist/prompts/commands/review.md +4 -13
- package/dist/prompts/commands/triage.md +159 -0
- package/dist/prompts/commands/verify-work.md +4 -14
- package/dist/prompts/commands/why.md +135 -0
- package/dist/skills/atomic-reasoning/SKILL.md +115 -0
- package/dist/skills/blast-radius/SKILL.md +55 -0
- package/dist/skills/epistemics/SKILL.md +99 -0
- package/dist/skills/hexagon-animation/SKILL.md +49 -0
- package/dist/skills/hexagon-animation/generate.mjs +81 -0
- package/dist/skills/hexagon-animation/template.html +361 -0
- package/dist/skills/typescript-discipline/SKILL.md +50 -0
- package/dist/skills/typescript-discipline/references/patterns.md +294 -0
- package/dist/skills/unslop/SKILL.md +101 -0
- package/dist/utils/canonical-path.d.ts +28 -0
- package/dist/utils/canonical-path.d.ts.map +1 -0
- package/dist/utils/canonical-path.js +90 -0
- package/dist/utils/canonical-path.js.map +1 -0
- package/dist/utils/child-process.d.ts +12 -1
- package/dist/utils/child-process.d.ts.map +1 -1
- package/dist/utils/child-process.js +25 -8
- package/dist/utils/child-process.js.map +1 -1
- package/dist/utils/clipboard-native.d.ts +1 -0
- package/dist/utils/clipboard-native.d.ts.map +1 -1
- package/dist/utils/clipboard-native.js.map +1 -1
- package/dist/utils/clipboard.d.ts +2 -0
- package/dist/utils/clipboard.d.ts.map +1 -1
- package/dist/utils/clipboard.js +53 -9
- package/dist/utils/clipboard.js.map +1 -1
- package/dist/utils/exif-orientation.d.ts.map +1 -1
- package/dist/utils/exif-orientation.js +2 -3
- package/dist/utils/exif-orientation.js.map +1 -1
- package/dist/utils/paths.d.ts +2 -7
- package/dist/utils/paths.d.ts.map +1 -1
- package/dist/utils/paths.js +13 -15
- package/dist/utils/paths.js.map +1 -1
- package/dist/utils/shell.d.ts.map +1 -1
- package/dist/utils/shell.js +6 -4
- package/dist/utils/shell.js.map +1 -1
- package/dist/utils/tools-manager.d.ts.map +1 -1
- package/dist/utils/tools-manager.js +3 -5
- package/dist/utils/tools-manager.js.map +1 -1
- package/dist/utils/version-check.d.ts.map +1 -1
- package/dist/utils/version-check.js +3 -1
- package/dist/utils/version-check.js.map +1 -1
- package/docs/attachable-sessions.md +79 -0
- package/docs/compaction.md +29 -24
- package/docs/containerization.md +23 -23
- package/docs/custom-provider.md +66 -32
- package/docs/development.md +9 -9
- package/docs/docs.json +6 -2
- package/docs/duet.md +42 -0
- package/docs/environment-variables.md +88 -0
- package/docs/extensions.md +278 -65
- package/docs/index.md +12 -10
- package/docs/json.md +12 -8
- package/docs/keybindings.md +8 -5
- package/docs/llama-cpp.md +99 -0
- package/docs/models.md +19 -8
- package/docs/packages.md +43 -42
- package/docs/prompt-templates.md +5 -4
- package/docs/providers.md +45 -11
- package/docs/quickstart.md +33 -33
- package/docs/rpc.md +190 -19
- package/docs/sdk.md +18 -15
- package/docs/security.md +18 -18
- package/docs/session-format.md +53 -15
- package/docs/sessions.md +17 -14
- package/docs/settings.md +26 -19
- package/docs/shell-aliases.md +2 -2
- package/docs/skills.md +12 -11
- package/docs/terminal-setup.md +12 -12
- package/docs/termux.md +6 -6
- package/docs/themes.md +11 -11
- package/docs/tmux.md +4 -4
- package/docs/tui.md +46 -31
- package/docs/usage.md +53 -63
- package/docs/windows.md +2 -2
- package/examples/extensions/custom-compaction.ts +4 -0
- package/examples/extensions/custom-provider-anthropic/index.ts +9 -3
- package/examples/extensions/custom-provider-anthropic/package.json +1 -1
- package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
- package/examples/extensions/custom-provider-qwen-cli/package.json +1 -1
- package/examples/extensions/gondolin/package.json +2 -2
- package/examples/extensions/handoff.ts +9 -1
- package/examples/extensions/kimi-deferred-tools.ts +61 -0
- package/examples/extensions/message-renderer.ts +2 -2
- package/examples/extensions/overlay-qa-tests.ts +3 -3
- package/examples/extensions/sandbox/package.json +1 -1
- package/examples/extensions/summarize.ts +3 -0
- package/examples/extensions/with-deps/package.json +1 -1
- package/examples/sdk/02-custom-model.ts +5 -8
- package/examples/sdk/09-api-keys-and-oauth.ts +15 -31
- package/examples/sdk/12-full-control.ts +9 -12
- package/hooks/gsd/draht-quality-gate.js +3 -3
- package/package.json +14 -11
- package/prompts/commands/atomic-commit.md +1 -12
- package/prompts/commands/brainstorm.md +12 -15
- package/prompts/commands/create-verification-skill.md +108 -0
- package/prompts/commands/discuss-phase.md +3 -14
- package/prompts/commands/execute-phase.md +3 -11
- package/prompts/commands/fix.md +41 -18
- package/prompts/commands/grill.md +66 -0
- package/prompts/commands/init-project.md +5 -15
- package/prompts/commands/map-codebase.md +1 -13
- package/prompts/commands/new-project.md +5 -15
- package/prompts/commands/next-milestone.md +1 -13
- package/prompts/commands/orchestrate.md +1 -1
- package/prompts/commands/pause-work.md +1 -13
- package/prompts/commands/plan-phase.md +2 -11
- package/prompts/commands/progress.md +0 -13
- package/prompts/commands/quick.md +3 -11
- package/prompts/commands/resolve-conflicts.md +71 -0
- package/prompts/commands/resume-work.md +0 -13
- package/prompts/commands/review.md +4 -13
- package/prompts/commands/triage.md +159 -0
- package/prompts/commands/verify-work.md +4 -14
- package/prompts/commands/why.md +135 -0
- package/skills/atomic-reasoning/SKILL.md +115 -0
- package/skills/blast-radius/SKILL.md +55 -0
- package/skills/epistemics/SKILL.md +99 -0
- package/skills/hexagon-animation/SKILL.md +49 -0
- package/skills/hexagon-animation/generate.mjs +81 -0
- package/skills/hexagon-animation/template.html +361 -0
- package/skills/typescript-discipline/SKILL.md +50 -0
- package/skills/typescript-discipline/references/patterns.md +294 -0
- package/skills/unslop/SKILL.md +101 -0
- package/dist/core/provider-display-names.d.ts +0 -2
- package/dist/core/provider-display-names.d.ts.map +0 -1
- package/dist/core/provider-display-names.js +0 -36
- package/dist/core/provider-display-names.js.map +0 -1
- package/dist/prompts/agents/build.md +0 -86
- package/dist/prompts/agents/plan.md +0 -79
- package/dist/prompts/agents/verify.md +0 -69
- package/prompts/agents/build.md +0 -86
- package/prompts/agents/plan.md +0 -79
- package/prompts/agents/verify.md +0 -69
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
*/
|
|
15
15
|
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
16
16
|
import { basename, dirname } from "node:path";
|
|
17
|
+
import { contentText } from "@draht/ai";
|
|
17
18
|
import { clampThinkingLevel, cleanupSessionResources, getSupportedThinkingLevels, isContextOverflow, isRetryableAssistantError, modelsAreEqual, resetApiProviders, streamSimple, } from "@draht/ai/compat";
|
|
18
19
|
import { getThemeByName, theme } from "../modes/interactive/theme/theme.js";
|
|
19
20
|
import { stripFrontmatter } from "../utils/frontmatter.js";
|
|
@@ -22,11 +23,14 @@ import { sleep } from "../utils/sleep.js";
|
|
|
22
23
|
import { formatNoApiKeyFoundMessage, formatNoModelSelectedMessage } from "./auth-guidance.js";
|
|
23
24
|
import { executeBashWithOperations } from "./bash-executor.js";
|
|
24
25
|
import { calculateContextTokens, collectEntriesForBranchSummary, compact, estimateContextTokens, estimateTokens, generateBranchSummary, prepareCompaction, shouldCompact, } from "./compaction/index.js";
|
|
26
|
+
import { applyContextWindow, getAvailableContextWindows } from "./context-windows.js";
|
|
25
27
|
import { DEFAULT_THINKING_LEVEL } from "./defaults.js";
|
|
26
28
|
import { exportSessionToHtml } from "./export-html/index.js";
|
|
27
29
|
import { createToolHtmlRenderer } from "./export-html/tool-renderer.js";
|
|
28
30
|
import { ExtensionRunner, wrapRegisteredTools, } from "./extensions/index.js";
|
|
29
31
|
import { emitSessionShutdownEvent } from "./extensions/runner.js";
|
|
32
|
+
import { ModelRegistry } from "./model-registry.js";
|
|
33
|
+
import { createRelayUIContext, noOpRelayBaseUIContext, } from "./permission-relay/index.js";
|
|
30
34
|
import { expandPromptTemplate } from "./prompt-templates.js";
|
|
31
35
|
import { CURRENT_SESSION_VERSION, getLatestCompactionEntry } from "./session-manager.js";
|
|
32
36
|
import { createSyntheticSourceInfo } from "./source-info.js";
|
|
@@ -34,6 +38,7 @@ import { buildSystemPrompt } from "./system-prompt.js";
|
|
|
34
38
|
import { createLocalBashOperations } from "./tools/bash.js";
|
|
35
39
|
import { createAllToolDefinitions } from "./tools/index.js";
|
|
36
40
|
import { createToolDefinitionFromAgentTool } from "./tools/tool-definition-wrapper.js";
|
|
41
|
+
import { addUsageToTotals, createUsageTotals } from "./usage-totals.js";
|
|
37
42
|
/**
|
|
38
43
|
* Parse a skill block from message text.
|
|
39
44
|
* Returns null if the text doesn't contain a skill block.
|
|
@@ -49,6 +54,14 @@ export function parseSkillBlock(text) {
|
|
|
49
54
|
userMessage: match[4]?.trim() || undefined,
|
|
50
55
|
};
|
|
51
56
|
}
|
|
57
|
+
// ============================================================================
|
|
58
|
+
// Types
|
|
59
|
+
// ============================================================================
|
|
60
|
+
function withoutDeletedHeaders(headers) {
|
|
61
|
+
return headers
|
|
62
|
+
? Object.fromEntries(Object.entries(headers).filter((entry) => entry[1] !== null))
|
|
63
|
+
: undefined;
|
|
64
|
+
}
|
|
52
65
|
function estimateMessagesTokens(messages) {
|
|
53
66
|
let tokens = 0;
|
|
54
67
|
for (const message of messages) {
|
|
@@ -61,6 +74,25 @@ function estimateMessagesTokens(messages) {
|
|
|
61
74
|
// ============================================================================
|
|
62
75
|
/** Standard thinking levels */
|
|
63
76
|
const THINKING_LEVELS = ["off", "minimal", "low", "medium", "high"];
|
|
77
|
+
/**
|
|
78
|
+
* Which SURFACE a dialog answered locally belongs to, per binding mode.
|
|
79
|
+
*
|
|
80
|
+
* Total over {@link ExtensionMode} on purpose — a `Record`, not a lookup with a fallback — because
|
|
81
|
+
* the fallback is what the defect was: the relay decorator hardcoded `tui`, so an answer typed into
|
|
82
|
+
* the RPC surface, and a SIGTERM that cancelled a pending dialog, were both recorded in the
|
|
83
|
+
* session's durable log as a human sitting at a terminal that does not exist.
|
|
84
|
+
*
|
|
85
|
+
* `json` and `print` bind no UI context at all (see `runPrintMode`), so the decorator wraps the
|
|
86
|
+
* barrel's no-op with `baseIsLive: false` and nothing is ever answered locally in them. `system` is
|
|
87
|
+
* therefore both unreachable and the truthful value: if such a mode somehow ended an ask, no person
|
|
88
|
+
* acted. It is deliberately not `tui`.
|
|
89
|
+
*/
|
|
90
|
+
const LOCAL_SURFACE_BY_MODE = Object.freeze({
|
|
91
|
+
tui: "tui",
|
|
92
|
+
rpc: "rpc",
|
|
93
|
+
json: "system",
|
|
94
|
+
print: "system",
|
|
95
|
+
});
|
|
64
96
|
// ============================================================================
|
|
65
97
|
// AgentSession Class
|
|
66
98
|
// ============================================================================
|
|
@@ -74,6 +106,8 @@ export class AgentSession {
|
|
|
74
106
|
this._followUpMessages = [];
|
|
75
107
|
/** Messages queued to be included with the next user prompt as context ("asides"). */
|
|
76
108
|
this._pendingNextTurnMessages = [];
|
|
109
|
+
/** Context-only custom messages queued during a run, flushed once the current turn's tool results are in. */
|
|
110
|
+
this._pendingCustomMessages = [];
|
|
77
111
|
// Compaction state
|
|
78
112
|
this._compactionAbortController = undefined;
|
|
79
113
|
this._autoCompactionAbortController = undefined;
|
|
@@ -84,7 +118,7 @@ export class AgentSession {
|
|
|
84
118
|
this._retryAbortController = undefined;
|
|
85
119
|
this._retryAttempt = 0;
|
|
86
120
|
// Bash execution state
|
|
87
|
-
this.
|
|
121
|
+
this._bashAbortControllers = new Set();
|
|
88
122
|
this._pendingBashMessages = [];
|
|
89
123
|
this._turnIndex = 0;
|
|
90
124
|
this._baseToolDefinitions = new Map();
|
|
@@ -104,7 +138,7 @@ export class AgentSession {
|
|
|
104
138
|
// This ensures the UI sees the updated queue state
|
|
105
139
|
if (event.type === "message_start" && event.message.role === "user") {
|
|
106
140
|
this._overflowRecoveryAttempted = false;
|
|
107
|
-
const messageText =
|
|
141
|
+
const messageText = contentText(event.message.content, "");
|
|
108
142
|
if (messageText) {
|
|
109
143
|
// Check steering queue first
|
|
110
144
|
const steeringIndex = this._steeringMessages.indexOf(messageText);
|
|
@@ -159,6 +193,14 @@ export class AgentSession {
|
|
|
159
193
|
}
|
|
160
194
|
}
|
|
161
195
|
}
|
|
196
|
+
// A turn ends after its assistant message and every tool result has been appended,
|
|
197
|
+
// so this is the first point in the run where a context-only custom message can be
|
|
198
|
+
// inserted without landing between a tool call and its result. Flushing after the
|
|
199
|
+
// extension and listener dispatch above also picks up messages that turn_end
|
|
200
|
+
// handlers queued.
|
|
201
|
+
if (event.type === "turn_end") {
|
|
202
|
+
this._flushPendingCustomMessages();
|
|
203
|
+
}
|
|
162
204
|
};
|
|
163
205
|
this.agent = config.agent;
|
|
164
206
|
this.sessionManager = config.sessionManager;
|
|
@@ -167,7 +209,7 @@ export class AgentSession {
|
|
|
167
209
|
this._resourceLoader = config.resourceLoader;
|
|
168
210
|
this._customTools = config.customTools ?? [];
|
|
169
211
|
this._cwd = config.cwd;
|
|
170
|
-
this.
|
|
212
|
+
this._modelRuntime = config.modelRuntime;
|
|
171
213
|
this._extensionRunnerRef = config.extensionRunnerRef;
|
|
172
214
|
this._initialActiveToolNames = config.initialActiveToolNames;
|
|
173
215
|
this._allowedToolNames = config.allowedToolNames ? new Set(config.allowedToolNames) : undefined;
|
|
@@ -184,22 +226,31 @@ export class AgentSession {
|
|
|
184
226
|
includeAllExtensionTools: true,
|
|
185
227
|
});
|
|
186
228
|
}
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
return this._modelRegistry;
|
|
229
|
+
get modelRuntime() {
|
|
230
|
+
return this._modelRuntime;
|
|
190
231
|
}
|
|
191
232
|
async _getRequiredRequestAuth(model) {
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
233
|
+
let result;
|
|
234
|
+
try {
|
|
235
|
+
result = await this._modelRuntime.getAuth(model);
|
|
236
|
+
}
|
|
237
|
+
catch (error) {
|
|
238
|
+
const cause = error instanceof Error ? error.cause : undefined;
|
|
239
|
+
if (cause instanceof Error && cause.message === "authHeader requires a resolved API key") {
|
|
195
240
|
throw new Error(formatNoApiKeyFoundMessage(model.provider));
|
|
196
241
|
}
|
|
197
|
-
throw
|
|
242
|
+
throw error;
|
|
198
243
|
}
|
|
199
|
-
if (result.apiKey) {
|
|
200
|
-
|
|
244
|
+
if (result && (result.auth.apiKey || result.auth.headers)) {
|
|
245
|
+
const requestModel = result.auth.baseUrl ? { ...model, baseUrl: result.auth.baseUrl } : model;
|
|
246
|
+
return {
|
|
247
|
+
model: requestModel,
|
|
248
|
+
apiKey: result.auth.apiKey,
|
|
249
|
+
headers: withoutDeletedHeaders(result.auth.headers),
|
|
250
|
+
env: result.env,
|
|
251
|
+
};
|
|
201
252
|
}
|
|
202
|
-
const isOAuth = this.
|
|
253
|
+
const isOAuth = this._modelRuntime.isUsingOAuth(model.provider);
|
|
203
254
|
if (isOAuth) {
|
|
204
255
|
throw new Error(`Authentication failed for "${model.provider}". ` +
|
|
205
256
|
`Credentials may have expired or network is unavailable. ` +
|
|
@@ -207,12 +258,25 @@ export class AgentSession {
|
|
|
207
258
|
}
|
|
208
259
|
throw new Error(formatNoApiKeyFoundMessage(model.provider));
|
|
209
260
|
}
|
|
210
|
-
async
|
|
211
|
-
if (this.agent.
|
|
261
|
+
async _getSummarizationRequestAuth(model) {
|
|
262
|
+
if (this.agent.streamFunction === streamSimple) {
|
|
212
263
|
return this._getRequiredRequestAuth(model);
|
|
213
264
|
}
|
|
214
|
-
|
|
215
|
-
|
|
265
|
+
try {
|
|
266
|
+
const result = await this._modelRuntime.getAuth(model);
|
|
267
|
+
if (!result)
|
|
268
|
+
return { model };
|
|
269
|
+
const requestModel = result.auth.baseUrl ? { ...model, baseUrl: result.auth.baseUrl } : model;
|
|
270
|
+
return {
|
|
271
|
+
model: requestModel,
|
|
272
|
+
apiKey: result.auth.apiKey,
|
|
273
|
+
headers: withoutDeletedHeaders(result.auth.headers),
|
|
274
|
+
env: result.env,
|
|
275
|
+
};
|
|
276
|
+
}
|
|
277
|
+
catch {
|
|
278
|
+
return { model };
|
|
279
|
+
}
|
|
216
280
|
}
|
|
217
281
|
/**
|
|
218
282
|
* Install tool hooks once on the Agent instance.
|
|
@@ -256,6 +320,7 @@ export class AgentSession {
|
|
|
256
320
|
content: result.content,
|
|
257
321
|
details: result.details,
|
|
258
322
|
isError,
|
|
323
|
+
usage: result.usage,
|
|
259
324
|
});
|
|
260
325
|
if (!hookResult) {
|
|
261
326
|
return undefined;
|
|
@@ -264,6 +329,7 @@ export class AgentSession {
|
|
|
264
329
|
content: hookResult.content,
|
|
265
330
|
details: hookResult.details,
|
|
266
331
|
isError: hookResult.isError ?? isError,
|
|
332
|
+
usage: hookResult.usage,
|
|
267
333
|
};
|
|
268
334
|
};
|
|
269
335
|
}
|
|
@@ -343,16 +409,6 @@ export class AgentSession {
|
|
|
343
409
|
}
|
|
344
410
|
return false;
|
|
345
411
|
}
|
|
346
|
-
/** Extract text content from a message */
|
|
347
|
-
_getUserMessageText(message) {
|
|
348
|
-
if (message.role !== "user")
|
|
349
|
-
return "";
|
|
350
|
-
const content = message.content;
|
|
351
|
-
if (typeof content === "string")
|
|
352
|
-
return content;
|
|
353
|
-
const textBlocks = content.filter((c) => c.type === "text");
|
|
354
|
-
return textBlocks.map((c) => c.text).join("");
|
|
355
|
-
}
|
|
356
412
|
/** Find the last assistant message in agent state (including aborted ones) */
|
|
357
413
|
_findLastAssistantMessage() {
|
|
358
414
|
const messages = this.agent.state.messages;
|
|
@@ -484,26 +540,13 @@ export class AgentSession {
|
|
|
484
540
|
}
|
|
485
541
|
};
|
|
486
542
|
}
|
|
487
|
-
/**
|
|
488
|
-
* Temporarily disconnect from agent events.
|
|
489
|
-
* User listeners are preserved and will receive events again after resubscribe().
|
|
490
|
-
* Used internally during operations that need to pause event processing.
|
|
491
|
-
*/
|
|
543
|
+
/** Disconnect from agent events during disposal. */
|
|
492
544
|
_disconnectFromAgent() {
|
|
493
545
|
if (this._unsubscribeAgent) {
|
|
494
546
|
this._unsubscribeAgent();
|
|
495
547
|
this._unsubscribeAgent = undefined;
|
|
496
548
|
}
|
|
497
549
|
}
|
|
498
|
-
/**
|
|
499
|
-
* Reconnect to agent events after _disconnectFromAgent().
|
|
500
|
-
* Preserves all existing listeners.
|
|
501
|
-
*/
|
|
502
|
-
_reconnectToAgent() {
|
|
503
|
-
if (this._unsubscribeAgent)
|
|
504
|
-
return; // Already connected
|
|
505
|
-
this._unsubscribeAgent = this.agent.subscribe(this._handleAgentEvent);
|
|
506
|
-
}
|
|
507
550
|
/**
|
|
508
551
|
* Remove all listeners and disconnect from agent.
|
|
509
552
|
* Call this when completely done with the session.
|
|
@@ -707,6 +750,7 @@ export class AgentSession {
|
|
|
707
750
|
finally {
|
|
708
751
|
this._systemPromptOverride = undefined;
|
|
709
752
|
this._flushPendingBashMessages();
|
|
753
|
+
this._flushPendingCustomMessages();
|
|
710
754
|
await this._emitAgentSettled();
|
|
711
755
|
}
|
|
712
756
|
}
|
|
@@ -759,6 +803,9 @@ export class AgentSession {
|
|
|
759
803
|
return;
|
|
760
804
|
}
|
|
761
805
|
}
|
|
806
|
+
if (this._compactionAbortController !== undefined) {
|
|
807
|
+
throw new Error("Cannot submit a prompt while compaction is in progress. Wait for compaction to finish and retry.");
|
|
808
|
+
}
|
|
762
809
|
// Emit input event for extension interception (before skill/template expansion)
|
|
763
810
|
let currentText = text;
|
|
764
811
|
let currentImages = options?.images;
|
|
@@ -793,14 +840,17 @@ export class AgentSession {
|
|
|
793
840
|
preflightResult?.(true);
|
|
794
841
|
return;
|
|
795
842
|
}
|
|
796
|
-
// Flush any pending bash messages before the new prompt
|
|
843
|
+
// Flush any pending bash and custom messages before the new prompt
|
|
797
844
|
this._flushPendingBashMessages();
|
|
845
|
+
this._flushPendingCustomMessages();
|
|
798
846
|
// Validate model
|
|
799
847
|
if (!this.model) {
|
|
800
848
|
throw new Error(formatNoModelSelectedMessage());
|
|
801
849
|
}
|
|
802
|
-
|
|
803
|
-
|
|
850
|
+
const hasConfiguredAuth = this._modelRuntime.hasConfiguredAuth(this.model.provider) ||
|
|
851
|
+
(await this._modelRuntime.checkAuth(this.model.provider)) !== undefined;
|
|
852
|
+
if (!hasConfiguredAuth) {
|
|
853
|
+
const isOAuth = this._modelRuntime.isUsingOAuth(this.model.provider);
|
|
804
854
|
if (isOAuth) {
|
|
805
855
|
throw new Error(`Authentication failed for "${this.model.provider}". ` +
|
|
806
856
|
`Credentials may have expired or network is unavailable. ` +
|
|
@@ -1006,8 +1056,9 @@ export class AgentSession {
|
|
|
1006
1056
|
/**
|
|
1007
1057
|
* Send a custom message to the session. Creates a CustomMessageEntry.
|
|
1008
1058
|
*
|
|
1009
|
-
* Handles
|
|
1059
|
+
* Handles four cases:
|
|
1010
1060
|
* - Streaming: queues message, processed when loop pulls from queue
|
|
1061
|
+
* - Streaming + triggerTurn false: appended to state/session once the current turn ends
|
|
1011
1062
|
* - Not streaming + triggerTurn: appends to state/session, starts new turn
|
|
1012
1063
|
* - Not streaming + no trigger: appends to state/session, no turn
|
|
1013
1064
|
*
|
|
@@ -1028,7 +1079,7 @@ export class AgentSession {
|
|
|
1028
1079
|
if (options?.deliverAs === "nextTurn") {
|
|
1029
1080
|
this._pendingNextTurnMessages.push(appMessage);
|
|
1030
1081
|
}
|
|
1031
|
-
else if (this.isStreaming) {
|
|
1082
|
+
else if (this.isStreaming && options?.triggerTurn !== false) {
|
|
1032
1083
|
if (options?.deliverAs === "followUp") {
|
|
1033
1084
|
this.agent.followUp(appMessage);
|
|
1034
1085
|
}
|
|
@@ -1039,11 +1090,34 @@ export class AgentSession {
|
|
|
1039
1090
|
else if (options?.triggerTurn) {
|
|
1040
1091
|
await this._runAgentPrompt(appMessage);
|
|
1041
1092
|
}
|
|
1093
|
+
else if (this.isStreaming) {
|
|
1094
|
+
// Appending now would put the message between an assistant tool call and its
|
|
1095
|
+
// result, which providers that validate message order reject on replay. Defer
|
|
1096
|
+
// to the end of the turn. Nothing is emitted yet: message events must not
|
|
1097
|
+
// describe messages the session tree does not contain.
|
|
1098
|
+
this._pendingCustomMessages.push(appMessage);
|
|
1099
|
+
}
|
|
1042
1100
|
else {
|
|
1043
|
-
this.
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1101
|
+
this._appendCustomMessage(appMessage);
|
|
1102
|
+
}
|
|
1103
|
+
}
|
|
1104
|
+
_appendCustomMessage(appMessage) {
|
|
1105
|
+
this.agent.state.messages.push(appMessage);
|
|
1106
|
+
this.sessionManager.appendCustomMessageEntry(appMessage.customType, appMessage.content, appMessage.display, appMessage.details);
|
|
1107
|
+
this._emit({ type: "message_start", message: appMessage });
|
|
1108
|
+
this._emit({ type: "message_end", message: appMessage });
|
|
1109
|
+
}
|
|
1110
|
+
/**
|
|
1111
|
+
* Append custom messages queued while the agent was running.
|
|
1112
|
+
* Called once the current turn's tool results are in agent state and session history.
|
|
1113
|
+
*/
|
|
1114
|
+
_flushPendingCustomMessages() {
|
|
1115
|
+
if (this._pendingCustomMessages.length === 0)
|
|
1116
|
+
return;
|
|
1117
|
+
const pending = this._pendingCustomMessages;
|
|
1118
|
+
this._pendingCustomMessages = [];
|
|
1119
|
+
for (const appMessage of pending) {
|
|
1120
|
+
this._appendCustomMessage(appMessage);
|
|
1047
1121
|
}
|
|
1048
1122
|
}
|
|
1049
1123
|
/**
|
|
@@ -1141,20 +1215,22 @@ export class AgentSession {
|
|
|
1141
1215
|
}
|
|
1142
1216
|
/**
|
|
1143
1217
|
* Set model directly.
|
|
1144
|
-
* Validates that auth is configured
|
|
1218
|
+
* Validates that auth is configured and saves to the session. Updates settings unless `persistDefault` is false.
|
|
1145
1219
|
* @throws Error if no auth is configured for the model
|
|
1146
1220
|
*/
|
|
1147
|
-
async setModel(model) {
|
|
1148
|
-
if (!this.
|
|
1221
|
+
async setModel(model, options = {}) {
|
|
1222
|
+
if (!(await this._modelRuntime.checkAuth(model.provider))) {
|
|
1149
1223
|
throw new Error(`No API key for ${model.provider}/${model.id}`);
|
|
1150
1224
|
}
|
|
1151
1225
|
const previousModel = this.model;
|
|
1152
1226
|
const thinkingLevel = this._getThinkingLevelForModelSwitch();
|
|
1153
1227
|
this.agent.state.model = model;
|
|
1154
|
-
this.sessionManager.appendModelChange(model.provider, model.id);
|
|
1155
|
-
|
|
1228
|
+
this.sessionManager.appendModelChange(model.provider, model.id, model.contextWindow);
|
|
1229
|
+
if (options.persistDefault !== false) {
|
|
1230
|
+
this.settingsManager.setDefaultModelAndProvider(model.provider, model.id);
|
|
1231
|
+
}
|
|
1156
1232
|
// Re-clamp thinking level for new model's capabilities
|
|
1157
|
-
this.setThinkingLevel(thinkingLevel);
|
|
1233
|
+
this.setThinkingLevel(thinkingLevel, options);
|
|
1158
1234
|
await this._emitModelSelect(model, previousModel, "set");
|
|
1159
1235
|
}
|
|
1160
1236
|
/**
|
|
@@ -1170,7 +1246,11 @@ export class AgentSession {
|
|
|
1170
1246
|
return this._cycleAvailableModel(direction);
|
|
1171
1247
|
}
|
|
1172
1248
|
async _cycleScopedModel(direction) {
|
|
1173
|
-
const
|
|
1249
|
+
const checks = await Promise.all(this._scopedModels.map(async (scoped) => ({
|
|
1250
|
+
scoped,
|
|
1251
|
+
auth: await this._modelRuntime.checkAuth(scoped.model.provider),
|
|
1252
|
+
})));
|
|
1253
|
+
const scopedModels = checks.filter(({ auth }) => auth !== undefined).map(({ scoped }) => scoped);
|
|
1174
1254
|
if (scopedModels.length <= 1)
|
|
1175
1255
|
return undefined;
|
|
1176
1256
|
const currentModel = this.model;
|
|
@@ -1183,7 +1263,7 @@ export class AgentSession {
|
|
|
1183
1263
|
const thinkingLevel = this._getThinkingLevelForModelSwitch(next.thinkingLevel);
|
|
1184
1264
|
// Apply model
|
|
1185
1265
|
this.agent.state.model = next.model;
|
|
1186
|
-
this.sessionManager.appendModelChange(next.model.provider, next.model.id);
|
|
1266
|
+
this.sessionManager.appendModelChange(next.model.provider, next.model.id, next.model.contextWindow);
|
|
1187
1267
|
this.settingsManager.setDefaultModelAndProvider(next.model.provider, next.model.id);
|
|
1188
1268
|
// Apply thinking level.
|
|
1189
1269
|
// - Explicit scoped model thinking level overrides current session level
|
|
@@ -1194,7 +1274,7 @@ export class AgentSession {
|
|
|
1194
1274
|
return { model: next.model, thinkingLevel: this.thinkingLevel, isScoped: true };
|
|
1195
1275
|
}
|
|
1196
1276
|
async _cycleAvailableModel(direction) {
|
|
1197
|
-
const availableModels = await this.
|
|
1277
|
+
const availableModels = await this._modelRuntime.getAvailable();
|
|
1198
1278
|
if (availableModels.length <= 1)
|
|
1199
1279
|
return undefined;
|
|
1200
1280
|
const currentModel = this.model;
|
|
@@ -1206,7 +1286,7 @@ export class AgentSession {
|
|
|
1206
1286
|
const nextModel = availableModels[nextIndex];
|
|
1207
1287
|
const thinkingLevel = this._getThinkingLevelForModelSwitch();
|
|
1208
1288
|
this.agent.state.model = nextModel;
|
|
1209
|
-
this.sessionManager.appendModelChange(nextModel.provider, nextModel.id);
|
|
1289
|
+
this.sessionManager.appendModelChange(nextModel.provider, nextModel.id, nextModel.contextWindow);
|
|
1210
1290
|
this.settingsManager.setDefaultModelAndProvider(nextModel.provider, nextModel.id);
|
|
1211
1291
|
// Re-clamp thinking level for new model's capabilities
|
|
1212
1292
|
this.setThinkingLevel(thinkingLevel);
|
|
@@ -1214,14 +1294,58 @@ export class AgentSession {
|
|
|
1214
1294
|
return { model: nextModel, thinkingLevel: this.thinkingLevel, isScoped: false };
|
|
1215
1295
|
}
|
|
1216
1296
|
// =========================================================================
|
|
1297
|
+
// Context Window Management
|
|
1298
|
+
// =========================================================================
|
|
1299
|
+
/** Get the selectable context windows for the current model. */
|
|
1300
|
+
getAvailableContextWindows() {
|
|
1301
|
+
return this.model ? getAvailableContextWindows(this.model) : [];
|
|
1302
|
+
}
|
|
1303
|
+
/** Get the context window that would be selected by the next cycle. */
|
|
1304
|
+
getNextContextWindow() {
|
|
1305
|
+
const model = this.model;
|
|
1306
|
+
if (!model)
|
|
1307
|
+
return undefined;
|
|
1308
|
+
const windows = getAvailableContextWindows(model);
|
|
1309
|
+
if (windows.length <= 1)
|
|
1310
|
+
return undefined;
|
|
1311
|
+
const currentIndex = windows.indexOf(model.contextWindow);
|
|
1312
|
+
return windows[(currentIndex + 1) % windows.length];
|
|
1313
|
+
}
|
|
1314
|
+
/** Set the active context window for the current session and persist it on the session branch. */
|
|
1315
|
+
setContextWindow(contextWindow) {
|
|
1316
|
+
const model = this.model;
|
|
1317
|
+
if (!model)
|
|
1318
|
+
throw new Error(formatNoModelSelectedMessage());
|
|
1319
|
+
if (!this.isIdle || this.isCompacting) {
|
|
1320
|
+
throw new Error("Wait for the current response or compaction to finish before changing the context window");
|
|
1321
|
+
}
|
|
1322
|
+
if (!getAvailableContextWindows(model).includes(contextWindow)) {
|
|
1323
|
+
throw new Error(`${model.provider}/${model.id} does not support a ${contextWindow}-token context window`);
|
|
1324
|
+
}
|
|
1325
|
+
const previousContextWindow = model.contextWindow;
|
|
1326
|
+
if (contextWindow === previousContextWindow)
|
|
1327
|
+
return;
|
|
1328
|
+
this.agent.state.model = { ...model, contextWindow };
|
|
1329
|
+
this.sessionManager.appendModelChange(model.provider, model.id, contextWindow);
|
|
1330
|
+
this._emit({ type: "context_window_changed", contextWindow, previousContextWindow });
|
|
1331
|
+
}
|
|
1332
|
+
/** Cycle to the next context window, or return undefined when the model has only one. */
|
|
1333
|
+
cycleContextWindow() {
|
|
1334
|
+
const nextContextWindow = this.getNextContextWindow();
|
|
1335
|
+
if (nextContextWindow === undefined)
|
|
1336
|
+
return undefined;
|
|
1337
|
+
this.setContextWindow(nextContextWindow);
|
|
1338
|
+
return nextContextWindow;
|
|
1339
|
+
}
|
|
1340
|
+
// =========================================================================
|
|
1217
1341
|
// Thinking Level Management
|
|
1218
1342
|
// =========================================================================
|
|
1219
1343
|
/**
|
|
1220
1344
|
* Set thinking level.
|
|
1221
1345
|
* Clamps to model capabilities based on available thinking levels.
|
|
1222
|
-
* Saves to session and settings
|
|
1346
|
+
* Saves changes to the session and updates settings unless `persistDefault` is false.
|
|
1223
1347
|
*/
|
|
1224
|
-
setThinkingLevel(level) {
|
|
1348
|
+
setThinkingLevel(level, options = {}) {
|
|
1225
1349
|
const availableLevels = this.getAvailableThinkingLevels();
|
|
1226
1350
|
const effectiveLevel = availableLevels.includes(level) ? level : this._clampThinkingLevel(level, availableLevels);
|
|
1227
1351
|
// Only persist if actually changing
|
|
@@ -1230,7 +1354,7 @@ export class AgentSession {
|
|
|
1230
1354
|
this.agent.state.thinkingLevel = effectiveLevel;
|
|
1231
1355
|
if (isChanging) {
|
|
1232
1356
|
this.sessionManager.appendThinkingLevelChange(effectiveLevel);
|
|
1233
|
-
if (this.supportsThinking() || effectiveLevel !== "off") {
|
|
1357
|
+
if (options.persistDefault !== false && (this.supportsThinking() || effectiveLevel !== "off")) {
|
|
1234
1358
|
this.settingsManager.setDefaultThinkingLevel(effectiveLevel);
|
|
1235
1359
|
}
|
|
1236
1360
|
this._emit({ type: "thinking_level_changed", level: effectiveLevel });
|
|
@@ -1314,7 +1438,6 @@ export class AgentSession {
|
|
|
1314
1438
|
* @param customInstructions Optional instructions for the compaction summary
|
|
1315
1439
|
*/
|
|
1316
1440
|
async compact(customInstructions) {
|
|
1317
|
-
this._disconnectFromAgent();
|
|
1318
1441
|
await this.abort();
|
|
1319
1442
|
this._compactionAbortController = new AbortController();
|
|
1320
1443
|
this._emit({ type: "compaction_start", reason: "manual" });
|
|
@@ -1322,7 +1445,7 @@ export class AgentSession {
|
|
|
1322
1445
|
if (!this.model) {
|
|
1323
1446
|
throw new Error(formatNoModelSelectedMessage());
|
|
1324
1447
|
}
|
|
1325
|
-
const { apiKey, headers, env } = await this.
|
|
1448
|
+
const { model: requestModel, apiKey, headers, env } = await this._getSummarizationRequestAuth(this.model);
|
|
1326
1449
|
const pathEntries = this.sessionManager.getBranch();
|
|
1327
1450
|
const settings = this.settingsManager.getCompactionSettings();
|
|
1328
1451
|
const preparation = prepareCompaction(pathEntries, settings);
|
|
@@ -1357,26 +1480,29 @@ export class AgentSession {
|
|
|
1357
1480
|
let summary;
|
|
1358
1481
|
let firstKeptEntryId;
|
|
1359
1482
|
let tokensBefore;
|
|
1483
|
+
let usage;
|
|
1360
1484
|
let details;
|
|
1361
1485
|
if (extensionCompaction) {
|
|
1362
1486
|
// Extension provided compaction content
|
|
1363
1487
|
summary = extensionCompaction.summary;
|
|
1364
1488
|
firstKeptEntryId = extensionCompaction.firstKeptEntryId;
|
|
1365
1489
|
tokensBefore = extensionCompaction.tokensBefore;
|
|
1490
|
+
usage = extensionCompaction.usage;
|
|
1366
1491
|
details = extensionCompaction.details;
|
|
1367
1492
|
}
|
|
1368
1493
|
else {
|
|
1369
1494
|
// Generate compaction result
|
|
1370
|
-
const result = await compact(preparation,
|
|
1495
|
+
const result = await compact(preparation, requestModel, apiKey, headers, customInstructions, this._compactionAbortController.signal, this.thinkingLevel, this.agent.streamFunction, env, this.settingsManager.getRetrySettings(), this._summarizationRetryCallbacks({ source: "compaction", reason: "manual" }));
|
|
1371
1496
|
summary = result.summary;
|
|
1372
1497
|
firstKeptEntryId = result.firstKeptEntryId;
|
|
1373
1498
|
tokensBefore = result.tokensBefore;
|
|
1499
|
+
usage = result.usage;
|
|
1374
1500
|
details = result.details;
|
|
1375
1501
|
}
|
|
1376
1502
|
if (this._compactionAbortController.signal.aborted) {
|
|
1377
1503
|
throw new Error("Compaction cancelled");
|
|
1378
1504
|
}
|
|
1379
|
-
this.sessionManager.appendCompaction(summary, firstKeptEntryId, tokensBefore, details, fromExtension);
|
|
1505
|
+
this.sessionManager.appendCompaction(summary, firstKeptEntryId, tokensBefore, details, fromExtension, usage);
|
|
1380
1506
|
const newEntries = this.sessionManager.getEntries();
|
|
1381
1507
|
const sessionContext = this.sessionManager.buildSessionContext();
|
|
1382
1508
|
this.agent.state.messages = sessionContext.messages;
|
|
@@ -1397,8 +1523,11 @@ export class AgentSession {
|
|
|
1397
1523
|
firstKeptEntryId,
|
|
1398
1524
|
tokensBefore,
|
|
1399
1525
|
estimatedTokensAfter,
|
|
1526
|
+
usage,
|
|
1400
1527
|
details,
|
|
1401
1528
|
};
|
|
1529
|
+
// compaction_end listeners may submit queued prompts, so expose idle state before notifying them.
|
|
1530
|
+
this._compactionAbortController = undefined;
|
|
1402
1531
|
this._emit({
|
|
1403
1532
|
type: "compaction_end",
|
|
1404
1533
|
reason: "manual",
|
|
@@ -1411,6 +1540,7 @@ export class AgentSession {
|
|
|
1411
1540
|
catch (error) {
|
|
1412
1541
|
const message = error instanceof Error ? error.message : String(error);
|
|
1413
1542
|
const aborted = message === "Compaction cancelled" || (error instanceof Error && error.name === "AbortError");
|
|
1543
|
+
this._compactionAbortController = undefined;
|
|
1414
1544
|
this._emit({
|
|
1415
1545
|
type: "compaction_end",
|
|
1416
1546
|
reason: "manual",
|
|
@@ -1423,7 +1553,6 @@ export class AgentSession {
|
|
|
1423
1553
|
}
|
|
1424
1554
|
finally {
|
|
1425
1555
|
this._compactionAbortController = undefined;
|
|
1426
|
-
this._reconnectToAgent();
|
|
1427
1556
|
}
|
|
1428
1557
|
}
|
|
1429
1558
|
/**
|
|
@@ -1509,16 +1638,18 @@ export class AgentSession {
|
|
|
1509
1638
|
if (assistantMessage.stopReason === "error" || directContextTokens === 0) {
|
|
1510
1639
|
const messages = this.agent.state.messages;
|
|
1511
1640
|
const estimate = estimateContextTokens(messages);
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1641
|
+
// Without provider usage, estimate.tokens is the pure message-size estimate.
|
|
1642
|
+
// Only usage-backed estimates need the stale pre-compaction check.
|
|
1643
|
+
if (estimate.lastUsageIndex !== null) {
|
|
1644
|
+
// Verify the usage source is post-compaction. Kept pre-compaction messages
|
|
1645
|
+
// have stale usage reflecting the old (larger) context and would falsely
|
|
1646
|
+
// trigger compaction right after one just finished.
|
|
1647
|
+
const usageMsg = messages[estimate.lastUsageIndex];
|
|
1648
|
+
if (compactionEntry &&
|
|
1649
|
+
usageMsg.role === "assistant" &&
|
|
1650
|
+
usageMsg.timestamp <= new Date(compactionEntry.timestamp).getTime()) {
|
|
1651
|
+
return false;
|
|
1652
|
+
}
|
|
1522
1653
|
}
|
|
1523
1654
|
contextTokens = estimate.tokens;
|
|
1524
1655
|
}
|
|
@@ -1540,21 +1671,7 @@ export class AgentSession {
|
|
|
1540
1671
|
if (!this.model) {
|
|
1541
1672
|
return false;
|
|
1542
1673
|
}
|
|
1543
|
-
|
|
1544
|
-
let headers;
|
|
1545
|
-
let env;
|
|
1546
|
-
if (this.agent.streamFn === streamSimple) {
|
|
1547
|
-
const authResult = await this._modelRegistry.getApiKeyAndHeaders(this.model);
|
|
1548
|
-
if (!authResult.ok || !authResult.apiKey) {
|
|
1549
|
-
return false;
|
|
1550
|
-
}
|
|
1551
|
-
apiKey = authResult.apiKey;
|
|
1552
|
-
headers = authResult.headers;
|
|
1553
|
-
env = authResult.env;
|
|
1554
|
-
}
|
|
1555
|
-
else {
|
|
1556
|
-
({ apiKey, headers, env } = await this._getCompactionRequestAuth(this.model));
|
|
1557
|
-
}
|
|
1674
|
+
const { model: requestModel, apiKey, headers, env } = await this._getSummarizationRequestAuth(this.model);
|
|
1558
1675
|
const pathEntries = this.sessionManager.getBranch();
|
|
1559
1676
|
const preparation = prepareCompaction(pathEntries, settings);
|
|
1560
1677
|
if (!preparation) {
|
|
@@ -1593,20 +1710,23 @@ export class AgentSession {
|
|
|
1593
1710
|
let summary;
|
|
1594
1711
|
let firstKeptEntryId;
|
|
1595
1712
|
let tokensBefore;
|
|
1713
|
+
let usage;
|
|
1596
1714
|
let details;
|
|
1597
1715
|
if (extensionCompaction) {
|
|
1598
1716
|
// Extension provided compaction content
|
|
1599
1717
|
summary = extensionCompaction.summary;
|
|
1600
1718
|
firstKeptEntryId = extensionCompaction.firstKeptEntryId;
|
|
1601
1719
|
tokensBefore = extensionCompaction.tokensBefore;
|
|
1720
|
+
usage = extensionCompaction.usage;
|
|
1602
1721
|
details = extensionCompaction.details;
|
|
1603
1722
|
}
|
|
1604
1723
|
else {
|
|
1605
1724
|
// Generate compaction result
|
|
1606
|
-
const compactResult = await compact(preparation,
|
|
1725
|
+
const compactResult = await compact(preparation, requestModel, apiKey, headers, undefined, this._autoCompactionAbortController.signal, this.thinkingLevel, this.agent.streamFunction, env, this.settingsManager.getRetrySettings(), this._summarizationRetryCallbacks({ source: "compaction", reason }));
|
|
1607
1726
|
summary = compactResult.summary;
|
|
1608
1727
|
firstKeptEntryId = compactResult.firstKeptEntryId;
|
|
1609
1728
|
tokensBefore = compactResult.tokensBefore;
|
|
1729
|
+
usage = compactResult.usage;
|
|
1610
1730
|
details = compactResult.details;
|
|
1611
1731
|
}
|
|
1612
1732
|
if (this._autoCompactionAbortController.signal.aborted) {
|
|
@@ -1619,7 +1739,7 @@ export class AgentSession {
|
|
|
1619
1739
|
});
|
|
1620
1740
|
return false;
|
|
1621
1741
|
}
|
|
1622
|
-
this.sessionManager.appendCompaction(summary, firstKeptEntryId, tokensBefore, details, fromExtension);
|
|
1742
|
+
this.sessionManager.appendCompaction(summary, firstKeptEntryId, tokensBefore, details, fromExtension, usage);
|
|
1623
1743
|
const newEntries = this.sessionManager.getEntries();
|
|
1624
1744
|
const sessionContext = this.sessionManager.buildSessionContext();
|
|
1625
1745
|
this.agent.state.messages = sessionContext.messages;
|
|
@@ -1640,6 +1760,7 @@ export class AgentSession {
|
|
|
1640
1760
|
firstKeptEntryId,
|
|
1641
1761
|
tokensBefore,
|
|
1642
1762
|
estimatedTokensAfter,
|
|
1763
|
+
usage,
|
|
1643
1764
|
details,
|
|
1644
1765
|
};
|
|
1645
1766
|
this._emit({ type: "compaction_end", reason, result, aborted: false, willRetry });
|
|
@@ -1685,6 +1806,17 @@ export class AgentSession {
|
|
|
1685
1806
|
get autoCompactionEnabled() {
|
|
1686
1807
|
return this.settingsManager.getCompactionEnabled();
|
|
1687
1808
|
}
|
|
1809
|
+
/**
|
|
1810
|
+
* Install (or remove) the permission relay this session's dialogs are mirrored onto.
|
|
1811
|
+
*
|
|
1812
|
+
* Re-applies the extension bindings immediately: the constructor's own apply has already run
|
|
1813
|
+
* by the time any caller can hand a relay over, so without the re-apply the runner would keep
|
|
1814
|
+
* an undecorated context until the next reload.
|
|
1815
|
+
*/
|
|
1816
|
+
setPermissionRelay(relay) {
|
|
1817
|
+
this._permissionRelay = relay;
|
|
1818
|
+
this._applyExtensionBindings(this._extensionRunner);
|
|
1819
|
+
}
|
|
1688
1820
|
async bindExtensions(bindings) {
|
|
1689
1821
|
if (bindings.uiContext !== undefined) {
|
|
1690
1822
|
this._extensionUIContext = bindings.uiContext;
|
|
@@ -1748,8 +1880,29 @@ export class AgentSession {
|
|
|
1748
1880
|
const name = base.replace(/\.(ts|js)$/, "");
|
|
1749
1881
|
return `extension:${name}`;
|
|
1750
1882
|
}
|
|
1883
|
+
/**
|
|
1884
|
+
* Wrap the mode's UI context so an attached remote surface can answer the same dialogs.
|
|
1885
|
+
*
|
|
1886
|
+
* Returns the base untouched when no relay is installed. When one is, the decorator is built
|
|
1887
|
+
* here and NOWHERE else: this is the only mode-agnostic seam every session passes through
|
|
1888
|
+
* (bindExtensions for interactive/rpc/print, _buildRuntime for the constructor and reload),
|
|
1889
|
+
* so a wrap installed anywhere else is silently overwritten when a mode binds its own context.
|
|
1890
|
+
*/
|
|
1891
|
+
_wrapUIContext(base) {
|
|
1892
|
+
if (this._permissionRelay === undefined) {
|
|
1893
|
+
return base;
|
|
1894
|
+
}
|
|
1895
|
+
return createRelayUIContext(base ?? noOpRelayBaseUIContext, this._permissionRelay, base !== undefined,
|
|
1896
|
+
// The TRUTH about which surface a locally answered dialog came from, and the reason this
|
|
1897
|
+
// seam is the only place the decorator may be built: `_extensionMode` is set by
|
|
1898
|
+
// `bindExtensions` immediately before `_applyExtensionBindings` calls this, so the mode
|
|
1899
|
+
// and the context it wraps are always the same binding. A literal `tui` inside the
|
|
1900
|
+
// decorator recorded an answer typed into the RPC surface as a human at a terminal that
|
|
1901
|
+
// does not exist.
|
|
1902
|
+
LOCAL_SURFACE_BY_MODE[this._extensionMode]);
|
|
1903
|
+
}
|
|
1751
1904
|
_applyExtensionBindings(runner) {
|
|
1752
|
-
runner.setUIContext(this._extensionUIContext, this._extensionMode);
|
|
1905
|
+
runner.setUIContext(this._wrapUIContext(this._extensionUIContext), this._extensionMode);
|
|
1753
1906
|
runner.bindCommandContext(this._extensionCommandContextActions);
|
|
1754
1907
|
this._extensionErrorUnsubscriber?.();
|
|
1755
1908
|
this._extensionErrorUnsubscriber = this._extensionErrorListener
|
|
@@ -1761,11 +1914,11 @@ export class AgentSession {
|
|
|
1761
1914
|
if (!currentModel) {
|
|
1762
1915
|
return;
|
|
1763
1916
|
}
|
|
1764
|
-
const refreshedModel = this.
|
|
1917
|
+
const refreshedModel = this._modelRuntime.getModel(currentModel.provider, currentModel.id);
|
|
1765
1918
|
if (!refreshedModel || refreshedModel === currentModel) {
|
|
1766
1919
|
return;
|
|
1767
1920
|
}
|
|
1768
|
-
this.agent.state.model = refreshedModel;
|
|
1921
|
+
this.agent.state.model = applyContextWindow(refreshedModel, currentModel.contextWindow);
|
|
1769
1922
|
}
|
|
1770
1923
|
_bindExtensionCore(runner) {
|
|
1771
1924
|
const getCommands = () => {
|
|
@@ -1829,16 +1982,17 @@ export class AgentSession {
|
|
|
1829
1982
|
setActiveTools: (toolNames) => this.setActiveToolsByName(toolNames),
|
|
1830
1983
|
refreshTools: () => this._refreshToolRegistry(),
|
|
1831
1984
|
getCommands,
|
|
1832
|
-
setModel: async (model) => {
|
|
1833
|
-
if (!this.
|
|
1985
|
+
setModel: async (model, options) => {
|
|
1986
|
+
if (!this._modelRuntime.hasConfiguredAuth(model.provider))
|
|
1834
1987
|
return false;
|
|
1835
|
-
await this.setModel(model);
|
|
1988
|
+
await this.setModel(model, options);
|
|
1836
1989
|
return true;
|
|
1837
1990
|
},
|
|
1838
1991
|
getThinkingLevel: () => this.thinkingLevel,
|
|
1839
|
-
setThinkingLevel: (level) => this.setThinkingLevel(level),
|
|
1992
|
+
setThinkingLevel: (level, options) => this.setThinkingLevel(level, options),
|
|
1840
1993
|
}, {
|
|
1841
1994
|
getModel: () => this.model,
|
|
1995
|
+
getScopedModels: () => this._scopedModels,
|
|
1842
1996
|
isIdle: () => this.isIdle,
|
|
1843
1997
|
isProjectTrusted: () => this.settingsManager.isProjectTrusted(),
|
|
1844
1998
|
getSignal: () => this.agent.signal,
|
|
@@ -1870,11 +2024,15 @@ export class AgentSession {
|
|
|
1870
2024
|
getSystemPromptOptions: () => this._baseSystemPromptOptions,
|
|
1871
2025
|
}, {
|
|
1872
2026
|
registerProvider: (name, config) => {
|
|
1873
|
-
this.
|
|
2027
|
+
this._modelRuntime.registerProvider(name, config);
|
|
2028
|
+
this._refreshCurrentModelFromRegistry();
|
|
2029
|
+
},
|
|
2030
|
+
registerNativeProvider: (provider) => {
|
|
2031
|
+
this._modelRuntime.registerNativeProvider(provider);
|
|
1874
2032
|
this._refreshCurrentModelFromRegistry();
|
|
1875
2033
|
},
|
|
1876
2034
|
unregisterProvider: (name) => {
|
|
1877
|
-
this.
|
|
2035
|
+
this._modelRuntime.unregisterProvider(name);
|
|
1878
2036
|
this._refreshCurrentModelFromRegistry();
|
|
1879
2037
|
},
|
|
1880
2038
|
});
|
|
@@ -1976,7 +2134,7 @@ export class AgentSession {
|
|
|
1976
2134
|
extensionsResult.runtime.flagValues.set(name, value);
|
|
1977
2135
|
}
|
|
1978
2136
|
}
|
|
1979
|
-
this._extensionRunner = new ExtensionRunner(extensionsResult.extensions, extensionsResult.runtime, this._cwd, this.sessionManager, this.
|
|
2137
|
+
this._extensionRunner = new ExtensionRunner(extensionsResult.extensions, extensionsResult.runtime, this._cwd, this.sessionManager, new ModelRegistry(this._modelRuntime));
|
|
1980
2138
|
if (this._extensionRunnerRef) {
|
|
1981
2139
|
this._extensionRunnerRef.current = this._extensionRunner;
|
|
1982
2140
|
}
|
|
@@ -1992,8 +2150,10 @@ export class AgentSession {
|
|
|
1992
2150
|
});
|
|
1993
2151
|
}
|
|
1994
2152
|
async reload(options) {
|
|
1995
|
-
const
|
|
1996
|
-
|
|
2153
|
+
const oldRunner = this._extensionRunner;
|
|
2154
|
+
const previousFlagValues = oldRunner.getFlagValues();
|
|
2155
|
+
await emitSessionShutdownEvent(oldRunner, { type: "session_shutdown", reason: "reload" });
|
|
2156
|
+
oldRunner.invalidate();
|
|
1997
2157
|
await this.settingsManager.reload();
|
|
1998
2158
|
this.syncQueueModesFromSettings();
|
|
1999
2159
|
resetApiProviders();
|
|
@@ -2026,6 +2186,34 @@ export class AgentSession {
|
|
|
2026
2186
|
return false;
|
|
2027
2187
|
return isRetryableAssistantError(message);
|
|
2028
2188
|
}
|
|
2189
|
+
/**
|
|
2190
|
+
* Retry policy + callbacks shared by compaction and branch-summary summarization calls.
|
|
2191
|
+
* Uses the same `settings.retry` budget/backoff as agent-turn retries so a single transient
|
|
2192
|
+
* stream drop no longer fails the whole operation. `source` carries the context
|
|
2193
|
+
* the TUI needs to render the retry and recreate the underlying indicator.
|
|
2194
|
+
*/
|
|
2195
|
+
_summarizationRetryCallbacks(source) {
|
|
2196
|
+
return {
|
|
2197
|
+
onRetryScheduled: (attempt, maxAttempts, delayMs, errorMessage) => {
|
|
2198
|
+
this._emit({
|
|
2199
|
+
type: "summarization_retry_scheduled",
|
|
2200
|
+
attempt,
|
|
2201
|
+
maxAttempts,
|
|
2202
|
+
delayMs,
|
|
2203
|
+
errorMessage,
|
|
2204
|
+
});
|
|
2205
|
+
},
|
|
2206
|
+
onRetryAttemptStart: () => {
|
|
2207
|
+
this._emit({
|
|
2208
|
+
type: "summarization_retry_attempt_start",
|
|
2209
|
+
...source,
|
|
2210
|
+
});
|
|
2211
|
+
},
|
|
2212
|
+
onRetryFinished: () => {
|
|
2213
|
+
this._emit({ type: "summarization_retry_finished" });
|
|
2214
|
+
},
|
|
2215
|
+
};
|
|
2216
|
+
}
|
|
2029
2217
|
/**
|
|
2030
2218
|
* Prepare a retryable error for continuation with exponential backoff.
|
|
2031
2219
|
* @returns true if the caller should continue the agent, false otherwise
|
|
@@ -2105,24 +2293,29 @@ export class AgentSession {
|
|
|
2105
2293
|
* @param command The bash command to execute
|
|
2106
2294
|
* @param onChunk Optional streaming callback for output
|
|
2107
2295
|
* @param options.excludeFromContext If true, command output won't be sent to LLM (!! prefix)
|
|
2296
|
+
* @param options.id Optional identifier included in bash execution update events
|
|
2108
2297
|
* @param options.operations Custom BashOperations for remote execution
|
|
2109
2298
|
*/
|
|
2110
2299
|
async executeBash(command, onChunk, options) {
|
|
2111
|
-
|
|
2300
|
+
const abortController = new AbortController();
|
|
2301
|
+
this._bashAbortControllers.add(abortController);
|
|
2112
2302
|
// Apply command prefix if configured (e.g., "shopt -s expand_aliases" for alias support)
|
|
2113
2303
|
const prefix = this.settingsManager.getShellCommandPrefix();
|
|
2114
2304
|
const shellPath = this.settingsManager.getShellPath();
|
|
2115
2305
|
const resolvedCommand = prefix ? `${prefix}\n${command}` : command;
|
|
2116
2306
|
try {
|
|
2117
2307
|
const result = await executeBashWithOperations(resolvedCommand, this.sessionManager.getCwd(), options?.operations ?? createLocalBashOperations({ shellPath }), {
|
|
2118
|
-
onChunk
|
|
2119
|
-
|
|
2308
|
+
onChunk: (delta) => {
|
|
2309
|
+
onChunk?.(delta);
|
|
2310
|
+
this._emit({ type: "bash_execution_update", id: options?.id, delta });
|
|
2311
|
+
},
|
|
2312
|
+
signal: abortController.signal,
|
|
2120
2313
|
});
|
|
2121
2314
|
this.recordBashResult(command, result, options);
|
|
2122
2315
|
return result;
|
|
2123
2316
|
}
|
|
2124
2317
|
finally {
|
|
2125
|
-
this.
|
|
2318
|
+
this._bashAbortControllers.delete(abortController);
|
|
2126
2319
|
}
|
|
2127
2320
|
}
|
|
2128
2321
|
/**
|
|
@@ -2157,11 +2350,13 @@ export class AgentSession {
|
|
|
2157
2350
|
* Cancel running bash command.
|
|
2158
2351
|
*/
|
|
2159
2352
|
abortBash() {
|
|
2160
|
-
this.
|
|
2353
|
+
for (const abortController of [...this._bashAbortControllers]) {
|
|
2354
|
+
abortController.abort();
|
|
2355
|
+
}
|
|
2161
2356
|
}
|
|
2162
2357
|
/** Whether a bash command is currently running */
|
|
2163
2358
|
get isBashRunning() {
|
|
2164
|
-
return this.
|
|
2359
|
+
return this._bashAbortControllers.size > 0;
|
|
2165
2360
|
}
|
|
2166
2361
|
/** Whether there are pending bash messages waiting to be flushed */
|
|
2167
2362
|
get hasPendingBashMessages() {
|
|
@@ -2209,6 +2404,9 @@ export class AgentSession {
|
|
|
2209
2404
|
* @returns Result with editorText (if user message) and cancelled status
|
|
2210
2405
|
*/
|
|
2211
2406
|
async navigateTree(targetId, options = {}) {
|
|
2407
|
+
if (this.isStreaming) {
|
|
2408
|
+
throw new Error("Wait for the current response to finish before navigating the session tree.");
|
|
2409
|
+
}
|
|
2212
2410
|
const oldLeafId = this.sessionManager.getLeafId();
|
|
2213
2411
|
// No-op if already at target
|
|
2214
2412
|
if (targetId === oldLeafId) {
|
|
@@ -2271,12 +2469,13 @@ export class AgentSession {
|
|
|
2271
2469
|
// Run default summarizer if needed
|
|
2272
2470
|
let summaryText;
|
|
2273
2471
|
let summaryDetails;
|
|
2472
|
+
let summaryUsage;
|
|
2274
2473
|
if (options.summarize && entriesToSummarize.length > 0 && !extensionSummary) {
|
|
2275
2474
|
const model = this.model;
|
|
2276
|
-
const { apiKey, headers, env } = await this.
|
|
2475
|
+
const { model: requestModel, apiKey, headers, env } = await this._getSummarizationRequestAuth(model);
|
|
2277
2476
|
const branchSummarySettings = this.settingsManager.getBranchSummarySettings();
|
|
2278
2477
|
const result = await generateBranchSummary(entriesToSummarize, {
|
|
2279
|
-
model,
|
|
2478
|
+
model: requestModel,
|
|
2280
2479
|
apiKey,
|
|
2281
2480
|
headers,
|
|
2282
2481
|
env,
|
|
@@ -2284,7 +2483,9 @@ export class AgentSession {
|
|
|
2284
2483
|
customInstructions,
|
|
2285
2484
|
replaceInstructions,
|
|
2286
2485
|
reserveTokens: branchSummarySettings.reserveTokens,
|
|
2287
|
-
streamFn: this.agent.
|
|
2486
|
+
streamFn: this.agent.streamFunction,
|
|
2487
|
+
retry: this.settingsManager.getRetrySettings(),
|
|
2488
|
+
callbacks: this._summarizationRetryCallbacks({ source: "branchSummary" }),
|
|
2288
2489
|
});
|
|
2289
2490
|
if (result.aborted) {
|
|
2290
2491
|
return { cancelled: true, aborted: true };
|
|
@@ -2293,6 +2494,7 @@ export class AgentSession {
|
|
|
2293
2494
|
throw new Error(result.error);
|
|
2294
2495
|
}
|
|
2295
2496
|
summaryText = result.summary;
|
|
2497
|
+
summaryUsage = result.usage;
|
|
2296
2498
|
summaryDetails = {
|
|
2297
2499
|
readFiles: result.readFiles || [],
|
|
2298
2500
|
modifiedFiles: result.modifiedFiles || [],
|
|
@@ -2301,6 +2503,7 @@ export class AgentSession {
|
|
|
2301
2503
|
else if (extensionSummary) {
|
|
2302
2504
|
summaryText = extensionSummary.summary;
|
|
2303
2505
|
summaryDetails = extensionSummary.details;
|
|
2506
|
+
summaryUsage = extensionSummary.usage;
|
|
2304
2507
|
}
|
|
2305
2508
|
// Determine the new leaf position based on target type
|
|
2306
2509
|
let newLeafId;
|
|
@@ -2308,18 +2511,12 @@ export class AgentSession {
|
|
|
2308
2511
|
if (targetEntry.type === "message" && targetEntry.message.role === "user") {
|
|
2309
2512
|
// User message: leaf = parent (null if root), text goes to editor
|
|
2310
2513
|
newLeafId = targetEntry.parentId;
|
|
2311
|
-
editorText =
|
|
2514
|
+
editorText = contentText(targetEntry.message.content, "");
|
|
2312
2515
|
}
|
|
2313
2516
|
else if (targetEntry.type === "custom_message") {
|
|
2314
2517
|
// Custom message: leaf = parent (null if root), text goes to editor
|
|
2315
2518
|
newLeafId = targetEntry.parentId;
|
|
2316
|
-
editorText =
|
|
2317
|
-
typeof targetEntry.content === "string"
|
|
2318
|
-
? targetEntry.content
|
|
2319
|
-
: targetEntry.content
|
|
2320
|
-
.filter((c) => c.type === "text")
|
|
2321
|
-
.map((c) => c.text)
|
|
2322
|
-
.join("");
|
|
2519
|
+
editorText = contentText(targetEntry.content, "");
|
|
2323
2520
|
}
|
|
2324
2521
|
else {
|
|
2325
2522
|
// Non-user message: leaf = selected node
|
|
@@ -2330,7 +2527,7 @@ export class AgentSession {
|
|
|
2330
2527
|
let summaryEntry;
|
|
2331
2528
|
if (summaryText) {
|
|
2332
2529
|
// Create summary at target position (can be null for root)
|
|
2333
|
-
const summaryId = this.sessionManager.branchWithSummary(newLeafId, summaryText, summaryDetails, fromExtension);
|
|
2530
|
+
const summaryId = this.sessionManager.branchWithSummary(newLeafId, summaryText, summaryDetails, fromExtension, summaryUsage);
|
|
2334
2531
|
summaryEntry = this.sessionManager.getEntry(summaryId);
|
|
2335
2532
|
// Attach label to the summary entry
|
|
2336
2533
|
if (label) {
|
|
@@ -2378,24 +2575,13 @@ export class AgentSession {
|
|
|
2378
2575
|
continue;
|
|
2379
2576
|
if (entry.message.role !== "user")
|
|
2380
2577
|
continue;
|
|
2381
|
-
const text =
|
|
2578
|
+
const text = contentText(entry.message.content, "");
|
|
2382
2579
|
if (text) {
|
|
2383
2580
|
result.push({ entryId: entry.id, text });
|
|
2384
2581
|
}
|
|
2385
2582
|
}
|
|
2386
2583
|
return result;
|
|
2387
2584
|
}
|
|
2388
|
-
_extractUserMessageText(content) {
|
|
2389
|
-
if (typeof content === "string")
|
|
2390
|
-
return content;
|
|
2391
|
-
if (Array.isArray(content)) {
|
|
2392
|
-
return content
|
|
2393
|
-
.filter((c) => c.type === "text")
|
|
2394
|
-
.map((c) => c.text)
|
|
2395
|
-
.join("");
|
|
2396
|
-
}
|
|
2397
|
-
return "";
|
|
2398
|
-
}
|
|
2399
2585
|
/**
|
|
2400
2586
|
* Get session statistics. Aggregates over ALL session entries (including
|
|
2401
2587
|
* history that was compacted away), so token/cost totals reflect what was
|
|
@@ -2407,12 +2593,11 @@ export class AgentSession {
|
|
|
2407
2593
|
let toolResults = 0;
|
|
2408
2594
|
let totalMessages = 0;
|
|
2409
2595
|
let toolCalls = 0;
|
|
2410
|
-
|
|
2411
|
-
let totalOutput = 0;
|
|
2412
|
-
let totalCacheRead = 0;
|
|
2413
|
-
let totalCacheWrite = 0;
|
|
2414
|
-
let totalCost = 0;
|
|
2596
|
+
const usageTotals = createUsageTotals();
|
|
2415
2597
|
for (const entry of this.sessionManager.getEntries()) {
|
|
2598
|
+
if ((entry.type === "branch_summary" || entry.type === "compaction") && entry.usage) {
|
|
2599
|
+
addUsageToTotals(usageTotals, entry.usage);
|
|
2600
|
+
}
|
|
2416
2601
|
if (entry.type !== "message")
|
|
2417
2602
|
continue;
|
|
2418
2603
|
totalMessages++;
|
|
@@ -2422,6 +2607,9 @@ export class AgentSession {
|
|
|
2422
2607
|
}
|
|
2423
2608
|
else if (message.role === "toolResult") {
|
|
2424
2609
|
toolResults++;
|
|
2610
|
+
if (message.usage) {
|
|
2611
|
+
addUsageToTotals(usageTotals, message.usage);
|
|
2612
|
+
}
|
|
2425
2613
|
}
|
|
2426
2614
|
else if (message.role === "assistant") {
|
|
2427
2615
|
assistantMessages++;
|
|
@@ -2429,12 +2617,7 @@ export class AgentSession {
|
|
|
2429
2617
|
if (Array.isArray(assistantMsg.content)) {
|
|
2430
2618
|
toolCalls += assistantMsg.content.filter((c) => c.type === "toolCall").length;
|
|
2431
2619
|
}
|
|
2432
|
-
|
|
2433
|
-
totalInput += usage.input;
|
|
2434
|
-
totalOutput += usage.output;
|
|
2435
|
-
totalCacheRead += usage.cacheRead;
|
|
2436
|
-
totalCacheWrite += usage.cacheWrite;
|
|
2437
|
-
totalCost += usage.cost.total;
|
|
2620
|
+
addUsageToTotals(usageTotals, assistantMsg.usage);
|
|
2438
2621
|
}
|
|
2439
2622
|
}
|
|
2440
2623
|
return {
|
|
@@ -2446,13 +2629,13 @@ export class AgentSession {
|
|
|
2446
2629
|
toolResults,
|
|
2447
2630
|
totalMessages,
|
|
2448
2631
|
tokens: {
|
|
2449
|
-
input:
|
|
2450
|
-
output:
|
|
2451
|
-
cacheRead:
|
|
2452
|
-
cacheWrite:
|
|
2453
|
-
total:
|
|
2632
|
+
input: usageTotals.input,
|
|
2633
|
+
output: usageTotals.output,
|
|
2634
|
+
cacheRead: usageTotals.cacheRead,
|
|
2635
|
+
cacheWrite: usageTotals.cacheWrite,
|
|
2636
|
+
total: usageTotals.input + usageTotals.output + usageTotals.cacheRead + usageTotals.cacheWrite,
|
|
2454
2637
|
},
|
|
2455
|
-
cost:
|
|
2638
|
+
cost: usageTotals.cost,
|
|
2456
2639
|
contextUsage: this.getContextUsage(),
|
|
2457
2640
|
};
|
|
2458
2641
|
}
|