@orion-agents/orion-code 0.1.9 → 0.2.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 +85 -0
- package/README.md +142 -323
- package/README.zh-CN.md +118 -578
- package/dist/cli.js +65 -84
- package/dist/cli.js.map +1 -1
- package/dist/commands/context-commands.d.ts.map +1 -1
- package/dist/commands/context-commands.js +14 -7
- package/dist/commands/context-commands.js.map +1 -1
- package/dist/commands/context-tool-command-handlers.d.ts +4 -5
- package/dist/commands/context-tool-command-handlers.d.ts.map +1 -1
- package/dist/commands/context-tool-command-handlers.js +132 -208
- package/dist/commands/context-tool-command-handlers.js.map +1 -1
- package/dist/commands/core-command-handlers.d.ts +3 -6
- package/dist/commands/core-command-handlers.d.ts.map +1 -1
- package/dist/commands/core-command-handlers.js +66 -664
- package/dist/commands/core-command-handlers.js.map +1 -1
- package/dist/commands/diagnostic-command-handlers.d.ts +1 -2
- package/dist/commands/diagnostic-command-handlers.d.ts.map +1 -1
- package/dist/commands/diagnostic-command-handlers.js +3 -17
- package/dist/commands/diagnostic-command-handlers.js.map +1 -1
- package/dist/commands/diagnostic-commands.d.ts.map +1 -1
- package/dist/commands/diagnostic-commands.js +0 -45
- package/dist/commands/diagnostic-commands.js.map +1 -1
- package/dist/commands/index.d.ts +1 -1
- package/dist/commands/index.d.ts.map +1 -1
- package/dist/commands/index.js +2 -7
- package/dist/commands/index.js.map +1 -1
- package/dist/commands/model-command-handlers.d.ts +1 -1
- package/dist/commands/model-command-handlers.js +2 -2
- package/dist/commands/model-command-handlers.js.map +1 -1
- package/dist/commands/model-commands.d.ts.map +1 -1
- package/dist/commands/model-commands.js +0 -11
- package/dist/commands/model-commands.js.map +1 -1
- package/dist/commands/registry.d.ts.map +1 -1
- package/dist/commands/registry.js +1 -139
- package/dist/commands/registry.js.map +1 -1
- package/dist/commands/session-command-handlers.d.ts +1 -1
- package/dist/commands/session-command-handlers.d.ts.map +1 -1
- package/dist/commands/session-command-handlers.js +52 -214
- package/dist/commands/session-command-handlers.js.map +1 -1
- package/dist/commands/session-commands.d.ts.map +1 -1
- package/dist/commands/session-commands.js +0 -48
- package/dist/commands/session-commands.js.map +1 -1
- package/dist/commands/target-command.d.ts +9 -15
- package/dist/commands/target-command.d.ts.map +1 -1
- package/dist/commands/target-command.js +16 -130
- package/dist/commands/target-command.js.map +1 -1
- package/dist/commands/tool-commands.d.ts.map +1 -1
- package/dist/commands/tool-commands.js +0 -10
- package/dist/commands/tool-commands.js.map +1 -1
- package/dist/commands/types.d.ts +10 -14
- package/dist/commands/types.d.ts.map +1 -1
- package/dist/commands/types.js +1 -1
- package/dist/commands/types.js.map +1 -1
- package/dist/commands/workflow-command-handlers.d.ts.map +1 -1
- package/dist/commands/workflow-command-handlers.js +1 -3
- package/dist/commands/workflow-command-handlers.js.map +1 -1
- package/dist/commands/workflow-commands.d.ts.map +1 -1
- package/dist/commands/workflow-commands.js +2 -24
- package/dist/commands/workflow-commands.js.map +1 -1
- package/dist/framework/agent-mode.d.ts +2 -3
- package/dist/framework/agent-mode.d.ts.map +1 -1
- package/dist/framework/agent-mode.js +8 -31
- package/dist/framework/agent-mode.js.map +1 -1
- package/dist/framework/index.d.ts +3 -3
- package/dist/framework/index.d.ts.map +1 -1
- package/dist/framework/index.js +6 -9
- package/dist/framework/index.js.map +1 -1
- package/dist/framework/loop-budget-contract.d.ts +20 -0
- package/dist/framework/loop-budget-contract.d.ts.map +1 -0
- package/dist/framework/loop-budget-contract.js +13 -0
- package/dist/framework/loop-budget-contract.js.map +1 -0
- package/dist/framework/prompt.d.ts.map +1 -1
- package/dist/framework/prompt.js +5 -4
- package/dist/framework/prompt.js.map +1 -1
- package/dist/framework/query.d.ts +45 -22
- package/dist/framework/query.d.ts.map +1 -1
- package/dist/framework/query.js +64 -52
- package/dist/framework/query.js.map +1 -1
- package/dist/framework/store.d.ts +4 -2
- package/dist/framework/store.d.ts.map +1 -1
- package/dist/framework/store.js +1 -0
- package/dist/framework/store.js.map +1 -1
- package/dist/framework/tool-call-orchestrator.d.ts +80 -0
- package/dist/framework/tool-call-orchestrator.d.ts.map +1 -0
- package/dist/framework/tool-call-orchestrator.js +192 -0
- package/dist/framework/tool-call-orchestrator.js.map +1 -0
- package/dist/framework/tool-state.d.ts +12 -11
- package/dist/framework/tool-state.d.ts.map +1 -1
- package/dist/framework/tool-state.js +36 -28
- package/dist/framework/tool-state.js.map +1 -1
- package/dist/framework/tool.d.ts +0 -9
- package/dist/framework/tool.d.ts.map +1 -1
- package/dist/framework/tool.js.map +1 -1
- package/dist/index.d.ts +70 -26
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +64 -65
- package/dist/index.js.map +1 -1
- package/dist/print-ui/launch.d.ts.map +1 -1
- package/dist/print-ui/launch.js +9 -2
- package/dist/print-ui/launch.js.map +1 -1
- package/dist/product/paths.d.ts +7 -0
- package/dist/product/paths.d.ts.map +1 -1
- package/dist/product/paths.js +19 -0
- package/dist/product/paths.js.map +1 -1
- package/dist/runtime/agent-loop.d.ts +80 -0
- package/dist/runtime/agent-loop.d.ts.map +1 -0
- package/dist/runtime/agent-loop.js +419 -0
- package/dist/runtime/agent-loop.js.map +1 -0
- package/dist/runtime/agent-runtime-controller.d.ts +10 -57
- package/dist/runtime/agent-runtime-controller.d.ts.map +1 -1
- package/dist/runtime/agent-runtime-controller.js +270 -1216
- package/dist/runtime/agent-runtime-controller.js.map +1 -1
- package/dist/runtime/agent-runtime-protocol.d.ts +4 -5
- package/dist/runtime/agent-runtime-protocol.d.ts.map +1 -1
- package/dist/runtime/agent-runtime-protocol.js.map +1 -1
- package/dist/runtime/agent-runtime-runner.d.ts +36 -0
- package/dist/runtime/agent-runtime-runner.d.ts.map +1 -0
- package/dist/runtime/agent-runtime-runner.js +3 -0
- package/dist/runtime/agent-runtime-runner.js.map +1 -0
- package/dist/runtime/batch-read-service.d.ts +29 -0
- package/dist/runtime/batch-read-service.d.ts.map +1 -0
- package/dist/runtime/batch-read-service.js +212 -0
- package/dist/runtime/batch-read-service.js.map +1 -0
- package/dist/runtime/builtin-tool-provider.d.ts +30 -0
- package/dist/runtime/builtin-tool-provider.d.ts.map +1 -0
- package/dist/runtime/builtin-tool-provider.js +233 -0
- package/dist/runtime/builtin-tool-provider.js.map +1 -0
- package/dist/runtime/capabilities/compiler.d.ts +11 -0
- package/dist/runtime/capabilities/compiler.d.ts.map +1 -0
- package/dist/runtime/capabilities/compiler.js +719 -0
- package/dist/runtime/capabilities/compiler.js.map +1 -0
- package/dist/runtime/capabilities/index.d.ts +3 -0
- package/dist/runtime/capabilities/index.d.ts.map +1 -0
- package/dist/runtime/capabilities/index.js +9 -0
- package/dist/runtime/capabilities/index.js.map +1 -0
- package/dist/runtime/capabilities/types.d.ts +175 -0
- package/dist/runtime/capabilities/types.d.ts.map +1 -0
- package/dist/runtime/capabilities/types.js +3 -0
- package/dist/runtime/capabilities/types.js.map +1 -0
- package/dist/runtime/capability-receipt-journal.d.ts +29 -0
- package/dist/runtime/capability-receipt-journal.d.ts.map +1 -0
- package/dist/runtime/capability-receipt-journal.js +264 -0
- package/dist/runtime/capability-receipt-journal.js.map +1 -0
- package/dist/runtime/capability-step-factory.d.ts +73 -0
- package/dist/runtime/capability-step-factory.d.ts.map +1 -0
- package/dist/runtime/capability-step-factory.js +302 -0
- package/dist/runtime/capability-step-factory.js.map +1 -0
- package/dist/runtime/compact-transaction.d.ts +225 -0
- package/dist/runtime/compact-transaction.d.ts.map +1 -0
- package/dist/runtime/compact-transaction.js +622 -0
- package/dist/runtime/compact-transaction.js.map +1 -0
- package/dist/runtime/composer/buffer.d.ts +3 -4
- package/dist/runtime/composer/buffer.d.ts.map +1 -1
- package/dist/runtime/composer/buffer.js +3 -4
- package/dist/runtime/composer/buffer.js.map +1 -1
- package/dist/runtime/composer/grapheme.d.ts +2 -4
- package/dist/runtime/composer/grapheme.d.ts.map +1 -1
- package/dist/runtime/composer/grapheme.js +2 -4
- package/dist/runtime/composer/grapheme.js.map +1 -1
- package/dist/runtime/composer/layout.d.ts +1 -3
- package/dist/runtime/composer/layout.d.ts.map +1 -1
- package/dist/runtime/composer/layout.js +1 -3
- package/dist/runtime/composer/layout.js.map +1 -1
- package/dist/runtime/core-tools/descriptors.d.ts +17 -0
- package/dist/runtime/core-tools/descriptors.d.ts.map +1 -0
- package/dist/runtime/core-tools/descriptors.js +185 -0
- package/dist/runtime/core-tools/descriptors.js.map +1 -0
- package/dist/runtime/first-party-core-provider.d.ts +55 -0
- package/dist/runtime/first-party-core-provider.d.ts.map +1 -0
- package/dist/runtime/first-party-core-provider.js +197 -0
- package/dist/runtime/first-party-core-provider.js.map +1 -0
- package/dist/runtime/first-party-long-tail-provider.d.ts +57 -0
- package/dist/runtime/first-party-long-tail-provider.d.ts.map +1 -0
- package/dist/runtime/first-party-long-tail-provider.js +238 -0
- package/dist/runtime/first-party-long-tail-provider.js.map +1 -0
- package/dist/runtime/first-party-tool-services.d.ts +43 -0
- package/dist/runtime/first-party-tool-services.d.ts.map +1 -0
- package/dist/runtime/first-party-tool-services.js +200 -0
- package/dist/runtime/first-party-tool-services.js.map +1 -0
- package/dist/runtime/first-party-tool-universe.d.ts +14 -0
- package/dist/runtime/first-party-tool-universe.d.ts.map +1 -0
- package/dist/runtime/first-party-tool-universe.js +20 -0
- package/dist/runtime/first-party-tool-universe.js.map +1 -0
- package/dist/runtime/goal-lifecycle-v2.d.ts +63 -0
- package/dist/runtime/goal-lifecycle-v2.d.ts.map +1 -0
- package/dist/runtime/goal-lifecycle-v2.js +253 -0
- package/dist/runtime/goal-lifecycle-v2.js.map +1 -0
- package/dist/runtime/goal-runtime-coordinator.d.ts +111 -0
- package/dist/runtime/goal-runtime-coordinator.d.ts.map +1 -0
- package/dist/runtime/goal-runtime-coordinator.js +511 -0
- package/dist/runtime/goal-runtime-coordinator.js.map +1 -0
- package/dist/runtime/harness-confluence.d.ts +165 -0
- package/dist/runtime/harness-confluence.d.ts.map +1 -0
- package/dist/runtime/harness-confluence.js +807 -0
- package/dist/runtime/harness-confluence.js.map +1 -0
- package/dist/runtime/harness-eval.d.ts +96 -0
- package/dist/runtime/harness-eval.d.ts.map +1 -0
- package/dist/runtime/harness-eval.js +181 -0
- package/dist/runtime/harness-eval.js.map +1 -0
- package/dist/runtime/harness-metrics.d.ts +202 -0
- package/dist/runtime/harness-metrics.d.ts.map +1 -0
- package/dist/runtime/harness-metrics.js +415 -0
- package/dist/runtime/harness-metrics.js.map +1 -0
- package/dist/runtime/legacy-session-importer.d.ts +99 -0
- package/dist/runtime/legacy-session-importer.d.ts.map +1 -0
- package/dist/runtime/legacy-session-importer.js +455 -0
- package/dist/runtime/legacy-session-importer.js.map +1 -0
- package/dist/runtime/legacy-thread-materializer.d.ts +72 -0
- package/dist/runtime/legacy-thread-materializer.d.ts.map +1 -0
- package/dist/runtime/legacy-thread-materializer.js +553 -0
- package/dist/runtime/legacy-thread-materializer.js.map +1 -0
- package/dist/runtime/long-tail-tools/descriptors.d.ts +23 -0
- package/dist/runtime/long-tail-tools/descriptors.d.ts.map +1 -0
- package/dist/runtime/long-tail-tools/descriptors.js +423 -0
- package/dist/runtime/long-tail-tools/descriptors.js.map +1 -0
- package/dist/runtime/loop-budget.d.ts +1 -1
- package/dist/runtime/loop-budget.d.ts.map +1 -1
- package/dist/runtime/loop-budget.js +2 -2
- package/dist/runtime/loop-budget.js.map +1 -1
- package/dist/runtime/mcp/first-party-mcp-adapter.d.ts +75 -0
- package/dist/runtime/mcp/first-party-mcp-adapter.d.ts.map +1 -0
- package/dist/runtime/mcp/first-party-mcp-adapter.js +484 -0
- package/dist/runtime/mcp/first-party-mcp-adapter.js.map +1 -0
- package/dist/runtime/mcp/first-party-mcp-config.d.ts +13 -0
- package/dist/runtime/mcp/first-party-mcp-config.d.ts.map +1 -0
- package/dist/runtime/mcp/first-party-mcp-config.js +139 -0
- package/dist/runtime/mcp/first-party-mcp-config.js.map +1 -0
- package/dist/runtime/mcp/index.d.ts +5 -0
- package/dist/runtime/mcp/index.d.ts.map +1 -0
- package/dist/{skills → runtime/mcp}/index.js +3 -9
- package/dist/runtime/mcp/index.js.map +1 -0
- package/dist/runtime/mcp/lazy-mcp-runtime.d.ts +95 -0
- package/dist/runtime/mcp/lazy-mcp-runtime.d.ts.map +1 -0
- package/dist/runtime/mcp/lazy-mcp-runtime.js +854 -0
- package/dist/runtime/mcp/lazy-mcp-runtime.js.map +1 -0
- package/dist/runtime/mcp/types.d.ts +128 -0
- package/dist/runtime/mcp/types.d.ts.map +1 -0
- package/dist/runtime/mcp/types.js +5 -0
- package/dist/runtime/mcp/types.js.map +1 -0
- package/dist/runtime/orion-runtime-v1.d.ts +322 -0
- package/dist/runtime/orion-runtime-v1.d.ts.map +1 -0
- package/dist/runtime/orion-runtime-v1.js +959 -0
- package/dist/runtime/orion-runtime-v1.js.map +1 -0
- package/dist/runtime/orion-session-runner.d.ts +38 -0
- package/dist/runtime/orion-session-runner.d.ts.map +1 -0
- package/dist/runtime/orion-session-runner.js +168 -0
- package/dist/runtime/orion-session-runner.js.map +1 -0
- package/dist/runtime/product-orion-runtime.d.ts +35 -0
- package/dist/runtime/product-orion-runtime.d.ts.map +1 -0
- package/dist/runtime/product-orion-runtime.js +1047 -0
- package/dist/runtime/product-orion-runtime.js.map +1 -0
- package/dist/runtime/prompts/index.d.ts +3 -0
- package/dist/runtime/prompts/index.d.ts.map +1 -0
- package/dist/{ink-ui/types.js → runtime/prompts/index.js} +3 -2
- package/dist/runtime/prompts/index.js.map +1 -0
- package/dist/runtime/prompts/prompt-registry.d.ts +22 -0
- package/dist/runtime/prompts/prompt-registry.d.ts.map +1 -0
- package/dist/runtime/prompts/prompt-registry.js +356 -0
- package/dist/runtime/prompts/prompt-registry.js.map +1 -0
- package/dist/runtime/prompts/types.d.ts +111 -0
- package/dist/runtime/prompts/types.d.ts.map +1 -0
- package/dist/runtime/prompts/types.js +5 -0
- package/dist/runtime/prompts/types.js.map +1 -0
- package/dist/runtime/protocol/canonical.d.ts +3 -0
- package/dist/runtime/protocol/canonical.d.ts.map +1 -0
- package/dist/runtime/protocol/canonical.js +21 -0
- package/dist/runtime/protocol/canonical.js.map +1 -0
- package/dist/runtime/protocol/index.d.ts +4 -0
- package/dist/runtime/protocol/index.d.ts.map +1 -0
- package/dist/runtime/protocol/index.js +16 -0
- package/dist/runtime/protocol/index.js.map +1 -0
- package/dist/runtime/protocol/runtime-protocol-v1.d.ts +671 -0
- package/dist/runtime/protocol/runtime-protocol-v1.d.ts.map +1 -0
- package/dist/runtime/protocol/runtime-protocol-v1.js +557 -0
- package/dist/runtime/protocol/runtime-protocol-v1.js.map +1 -0
- package/dist/runtime/release-receipts.d.ts +110 -0
- package/dist/runtime/release-receipts.d.ts.map +1 -0
- package/dist/runtime/release-receipts.js +305 -0
- package/dist/runtime/release-receipts.js.map +1 -0
- package/dist/runtime/resource-scope.d.ts +123 -0
- package/dist/runtime/resource-scope.d.ts.map +1 -0
- package/dist/runtime/resource-scope.js +363 -0
- package/dist/runtime/resource-scope.js.map +1 -0
- package/dist/runtime/runtime-event-buffer.d.ts +78 -0
- package/dist/runtime/runtime-event-buffer.d.ts.map +1 -0
- package/dist/runtime/runtime-event-buffer.js +237 -0
- package/dist/runtime/runtime-event-buffer.js.map +1 -0
- package/dist/runtime/runtime-services.d.ts +87 -0
- package/dist/runtime/runtime-services.d.ts.map +1 -0
- package/dist/runtime/runtime-services.js +180 -0
- package/dist/runtime/runtime-services.js.map +1 -0
- package/dist/runtime/session-history-recovery.d.ts +19 -0
- package/dist/runtime/session-history-recovery.d.ts.map +1 -0
- package/dist/runtime/session-history-recovery.js +45 -0
- package/dist/runtime/session-history-recovery.js.map +1 -0
- package/dist/runtime/skills/bounded-lru-cache.d.ts +34 -0
- package/dist/runtime/skills/bounded-lru-cache.d.ts.map +1 -0
- package/dist/runtime/skills/bounded-lru-cache.js +100 -0
- package/dist/runtime/skills/bounded-lru-cache.js.map +1 -0
- package/dist/runtime/skills/filesystem-skill-provider.d.ts +96 -0
- package/dist/runtime/skills/filesystem-skill-provider.d.ts.map +1 -0
- package/dist/runtime/skills/filesystem-skill-provider.js +829 -0
- package/dist/runtime/skills/filesystem-skill-provider.js.map +1 -0
- package/dist/runtime/skills/index.d.ts +5 -0
- package/dist/runtime/skills/index.d.ts.map +1 -0
- package/dist/{ink-ui/controllers/chat-controller.js → runtime/skills/index.js} +5 -2
- package/dist/runtime/skills/index.js.map +1 -0
- package/dist/runtime/skills/lazy-skill-runtime.d.ts +77 -0
- package/dist/runtime/skills/lazy-skill-runtime.d.ts.map +1 -0
- package/dist/runtime/skills/lazy-skill-runtime.js +673 -0
- package/dist/runtime/skills/lazy-skill-runtime.js.map +1 -0
- package/dist/runtime/skills/types.d.ts +137 -0
- package/dist/runtime/skills/types.d.ts.map +1 -0
- package/dist/runtime/skills/types.js +13 -0
- package/dist/runtime/skills/types.js.map +1 -0
- package/dist/runtime/step-snapshot.d.ts +183 -0
- package/dist/runtime/step-snapshot.d.ts.map +1 -0
- package/dist/runtime/step-snapshot.js +286 -0
- package/dist/runtime/step-snapshot.js.map +1 -0
- package/dist/runtime/subagent-thread-runtime.d.ts +239 -0
- package/dist/runtime/subagent-thread-runtime.d.ts.map +1 -0
- package/dist/runtime/subagent-thread-runtime.js +876 -0
- package/dist/runtime/subagent-thread-runtime.js.map +1 -0
- package/dist/runtime/subagents/index.d.ts +4 -1
- package/dist/runtime/subagents/index.d.ts.map +1 -1
- package/dist/runtime/subagents/index.js +10 -2
- package/dist/runtime/subagents/index.js.map +1 -1
- package/dist/runtime/subagents/parent-step-fork.d.ts +36 -0
- package/dist/runtime/subagents/parent-step-fork.d.ts.map +1 -0
- package/dist/runtime/subagents/parent-step-fork.js +83 -0
- package/dist/runtime/subagents/parent-step-fork.js.map +1 -0
- package/dist/runtime/subagents/production.d.ts +65 -46
- package/dist/runtime/subagents/production.d.ts.map +1 -1
- package/dist/runtime/subagents/production.js +494 -170
- package/dist/runtime/subagents/production.js.map +1 -1
- package/dist/runtime/subagents/receipt-journal.d.ts +20 -0
- package/dist/runtime/subagents/receipt-journal.d.ts.map +1 -0
- package/dist/runtime/subagents/receipt-journal.js +74 -0
- package/dist/runtime/subagents/receipt-journal.js.map +1 -0
- package/dist/runtime/subagents/runtime-contract.d.ts +29 -0
- package/dist/runtime/subagents/runtime-contract.d.ts.map +1 -0
- package/dist/runtime/subagents/runtime-contract.js +3 -0
- package/dist/runtime/subagents/runtime-contract.js.map +1 -0
- package/dist/runtime/subagents/runtime-integration.d.ts +41 -56
- package/dist/runtime/subagents/runtime-integration.d.ts.map +1 -1
- package/dist/runtime/subagents/runtime-integration.js +34 -198
- package/dist/runtime/subagents/runtime-integration.js.map +1 -1
- package/dist/runtime/subagents/supervisor.d.ts +19 -7
- package/dist/runtime/subagents/supervisor.d.ts.map +1 -1
- package/dist/runtime/subagents/supervisor.js +83 -40
- package/dist/runtime/subagents/supervisor.js.map +1 -1
- package/dist/runtime/subagents/types.d.ts +1 -1
- package/dist/runtime/subagents/types.js +1 -1
- package/dist/runtime/task-context-service.d.ts +91 -0
- package/dist/runtime/task-context-service.d.ts.map +1 -0
- package/dist/runtime/task-context-service.js +122 -0
- package/dist/runtime/task-context-service.js.map +1 -0
- package/dist/runtime/thread-admission.d.ts +130 -0
- package/dist/runtime/thread-admission.d.ts.map +1 -0
- package/dist/runtime/thread-admission.js +276 -0
- package/dist/runtime/thread-admission.js.map +1 -0
- package/dist/runtime/thread-compact-persistence.d.ts +50 -0
- package/dist/runtime/thread-compact-persistence.d.ts.map +1 -0
- package/dist/runtime/thread-compact-persistence.js +176 -0
- package/dist/runtime/thread-compact-persistence.js.map +1 -0
- package/dist/runtime/thread-event-store.d.ts +98 -0
- package/dist/runtime/thread-event-store.d.ts.map +1 -0
- package/dist/runtime/thread-event-store.js +737 -0
- package/dist/runtime/thread-event-store.js.map +1 -0
- package/dist/runtime/thread-projection.d.ts +91 -0
- package/dist/runtime/thread-projection.d.ts.map +1 -0
- package/dist/runtime/thread-projection.js +407 -0
- package/dist/runtime/thread-projection.js.map +1 -0
- package/dist/runtime/thread-runtime.d.ts +165 -0
- package/dist/runtime/thread-runtime.d.ts.map +1 -0
- package/dist/runtime/thread-runtime.js +704 -0
- package/dist/runtime/thread-runtime.js.map +1 -0
- package/dist/runtime/thread-session-view.d.ts +45 -0
- package/dist/runtime/thread-session-view.d.ts.map +1 -0
- package/dist/runtime/thread-session-view.js +264 -0
- package/dist/runtime/thread-session-view.js.map +1 -0
- package/dist/runtime/thread-tool-journal.d.ts +11 -0
- package/dist/runtime/thread-tool-journal.d.ts.map +1 -0
- package/dist/runtime/thread-tool-journal.js +131 -0
- package/dist/runtime/thread-tool-journal.js.map +1 -0
- package/dist/runtime/thread-ui-adapter.d.ts +87 -0
- package/dist/runtime/thread-ui-adapter.d.ts.map +1 -0
- package/dist/runtime/thread-ui-adapter.js +580 -0
- package/dist/runtime/thread-ui-adapter.js.map +1 -0
- package/dist/runtime/tool-gateway.d.ts +159 -0
- package/dist/runtime/tool-gateway.d.ts.map +1 -0
- package/dist/runtime/tool-gateway.js +311 -0
- package/dist/runtime/tool-gateway.js.map +1 -0
- package/dist/runtime/turn-commit.d.ts +103 -0
- package/dist/runtime/turn-commit.d.ts.map +1 -0
- package/dist/runtime/turn-commit.js +321 -0
- package/dist/runtime/turn-commit.js.map +1 -0
- package/dist/runtime/ui-events.d.ts +15 -5
- package/dist/runtime/ui-events.d.ts.map +1 -1
- package/dist/runtime/ui-events.js +0 -1
- package/dist/runtime/ui-events.js.map +1 -1
- package/dist/runtime/ui-view-model.d.ts +2 -1
- package/dist/runtime/ui-view-model.d.ts.map +1 -1
- package/dist/runtime/ui-view-model.js +6 -5
- package/dist/runtime/ui-view-model.js.map +1 -1
- package/dist/services/config-dir.d.ts +1 -1
- package/dist/services/config-dir.d.ts.map +1 -1
- package/dist/services/config-dir.js +2 -1
- package/dist/services/config-dir.js.map +1 -1
- package/dist/services/config.d.ts +2 -16
- package/dist/services/config.d.ts.map +1 -1
- package/dist/services/config.js +2 -29
- package/dist/services/config.js.map +1 -1
- package/dist/services/doctor.d.ts +0 -2
- package/dist/services/doctor.d.ts.map +1 -1
- package/dist/services/doctor.js +39 -64
- package/dist/services/doctor.js.map +1 -1
- package/dist/services/file-lock.d.ts.map +1 -1
- package/dist/services/file-lock.js +42 -17
- package/dist/services/file-lock.js.map +1 -1
- package/dist/services/global-config.d.ts +2 -2
- package/dist/services/global-config.d.ts.map +1 -1
- package/dist/services/session-storage.d.ts +8 -0
- package/dist/services/session-storage.d.ts.map +1 -1
- package/dist/services/session-storage.js +76 -12
- package/dist/services/session-storage.js.map +1 -1
- package/dist/skills/builtin/code-review/SKILL.md +51 -0
- package/dist/skills/builtin/security-check/SKILL.md +54 -0
- package/dist/skills/builtin/test-gen/SKILL.md +49 -0
- package/dist/terminal-ui/launch.d.ts +3 -1
- package/dist/terminal-ui/launch.d.ts.map +1 -1
- package/dist/terminal-ui/launch.js +21 -3
- package/dist/terminal-ui/launch.js.map +1 -1
- package/dist/tools/core/common.d.ts +34 -0
- package/dist/tools/core/common.d.ts.map +1 -0
- package/dist/tools/core/common.js +164 -0
- package/dist/tools/core/common.js.map +1 -0
- package/dist/tools/core/edit-file.d.ts +10 -0
- package/dist/tools/core/edit-file.d.ts.map +1 -0
- package/dist/tools/core/edit-file.js +301 -0
- package/dist/tools/core/edit-file.js.map +1 -0
- package/dist/tools/core/exec-command.d.ts +2 -0
- package/dist/tools/core/exec-command.d.ts.map +1 -0
- package/dist/tools/core/exec-command.js +347 -0
- package/dist/tools/core/exec-command.js.map +1 -0
- package/dist/tools/core/glob.d.ts +2 -0
- package/dist/tools/core/glob.d.ts.map +1 -0
- package/dist/tools/core/glob.js +133 -0
- package/dist/tools/core/glob.js.map +1 -0
- package/dist/tools/core/grep.d.ts +12 -0
- package/dist/tools/core/grep.d.ts.map +1 -0
- package/dist/tools/core/grep.js +223 -0
- package/dist/tools/core/grep.js.map +1 -0
- package/dist/tools/core/index.d.ts +15 -0
- package/dist/tools/core/index.d.ts.map +1 -0
- package/dist/tools/core/index.js +31 -0
- package/dist/tools/core/index.js.map +1 -0
- package/dist/tools/core/list-files.d.ts +2 -0
- package/dist/tools/core/list-files.d.ts.map +1 -0
- package/dist/tools/core/list-files.js +87 -0
- package/dist/tools/core/list-files.js.map +1 -0
- package/dist/tools/core/read-file.d.ts +2 -0
- package/dist/tools/core/read-file.d.ts.map +1 -0
- package/dist/tools/core/read-file.js +129 -0
- package/dist/tools/core/read-file.js.map +1 -0
- package/dist/tools/core/write-file.d.ts +2 -0
- package/dist/tools/core/write-file.d.ts.map +1 -0
- package/dist/tools/core/write-file.js +65 -0
- package/dist/tools/core/write-file.js.map +1 -0
- package/dist/tools/todo.d.ts +3 -4
- package/dist/tools/todo.d.ts.map +1 -1
- package/dist/tools/todo.js +80 -79
- package/dist/tools/todo.js.map +1 -1
- package/dist/tools/web.js +1 -1
- package/dist/tools/web.js.map +1 -1
- package/dist/tui-ui/chrome-view-model.d.ts.map +1 -1
- package/dist/tui-ui/chrome-view-model.js +22 -8
- package/dist/tui-ui/chrome-view-model.js.map +1 -1
- package/dist/tui-ui/launch.d.ts.map +1 -1
- package/dist/tui-ui/launch.js +13 -0
- package/dist/tui-ui/launch.js.map +1 -1
- package/dist/tui-ui/layout.js +1 -1
- package/dist/tui-ui/layout.js.map +1 -1
- package/dist/tui-ui/state.d.ts.map +1 -1
- package/dist/tui-ui/state.js +2 -0
- package/dist/tui-ui/state.js.map +1 -1
- package/docs/migration/v0.1.9-to-v0.2.0.md +98 -0
- package/docs/orion.example.json +79 -0
- package/docs/plan/v0.2.0-dsh-harness-redesign-plan.md +1234 -0
- package/docs/plan/v0.2.0-release-checklist.md +91 -0
- package/docs/readme.md +8 -8
- package/npm-shrinkwrap.json +45 -450
- package/package.json +17 -13
- package/dist/agents/coder.d.ts +0 -12
- package/dist/agents/coder.d.ts.map +0 -1
- package/dist/agents/coder.js +0 -48
- package/dist/agents/coder.js.map +0 -1
- package/dist/agents/coordinator.d.ts +0 -86
- package/dist/agents/coordinator.d.ts.map +0 -1
- package/dist/agents/coordinator.js +0 -291
- package/dist/agents/coordinator.js.map +0 -1
- package/dist/agents/fork.d.ts +0 -73
- package/dist/agents/fork.d.ts.map +0 -1
- package/dist/agents/fork.js +0 -163
- package/dist/agents/fork.js.map +0 -1
- package/dist/agents/leader.d.ts +0 -12
- package/dist/agents/leader.d.ts.map +0 -1
- package/dist/agents/leader.js +0 -49
- package/dist/agents/leader.js.map +0 -1
- package/dist/agents/router.d.ts +0 -59
- package/dist/agents/router.d.ts.map +0 -1
- package/dist/agents/router.js +0 -193
- package/dist/agents/router.js.map +0 -1
- package/dist/agents/worker-pool.d.ts +0 -72
- package/dist/agents/worker-pool.d.ts.map +0 -1
- package/dist/agents/worker-pool.js +0 -229
- package/dist/agents/worker-pool.js.map +0 -1
- package/dist/commands/legacy-commands.d.ts +0 -4
- package/dist/commands/legacy-commands.d.ts.map +0 -1
- package/dist/commands/legacy-commands.js +0 -44
- package/dist/commands/legacy-commands.js.map +0 -1
- package/dist/core/agent.d.ts +0 -84
- package/dist/core/agent.d.ts.map +0 -1
- package/dist/core/agent.js +0 -58
- package/dist/core/agent.js.map +0 -1
- package/dist/core/brain.d.ts +0 -50
- package/dist/core/brain.d.ts.map +0 -1
- package/dist/core/brain.js +0 -95
- package/dist/core/brain.js.map +0 -1
- package/dist/framework/tool-scheduler.d.ts +0 -191
- package/dist/framework/tool-scheduler.d.ts.map +0 -1
- package/dist/framework/tool-scheduler.js +0 -573
- package/dist/framework/tool-scheduler.js.map +0 -1
- package/dist/harness/harness.d.ts +0 -58
- package/dist/harness/harness.d.ts.map +0 -1
- package/dist/harness/harness.js +0 -195
- package/dist/harness/harness.js.map +0 -1
- package/dist/harness/safety.d.ts +0 -101
- package/dist/harness/safety.d.ts.map +0 -1
- package/dist/harness/safety.js +0 -322
- package/dist/harness/safety.js.map +0 -1
- package/dist/init.d.ts +0 -108
- package/dist/init.d.ts.map +0 -1
- package/dist/init.js +0 -393
- package/dist/init.js.map +0 -1
- package/dist/ink-ui/App.d.ts +0 -9
- package/dist/ink-ui/App.d.ts.map +0 -1
- package/dist/ink-ui/App.js +0 -12
- package/dist/ink-ui/App.js.map +0 -1
- package/dist/ink-ui/components/Markdown.d.ts +0 -10
- package/dist/ink-ui/components/Markdown.d.ts.map +0 -1
- package/dist/ink-ui/components/Markdown.js +0 -210
- package/dist/ink-ui/components/Markdown.js.map +0 -1
- package/dist/ink-ui/components/NativeCursor.d.ts +0 -12
- package/dist/ink-ui/components/NativeCursor.d.ts.map +0 -1
- package/dist/ink-ui/components/NativeCursor.js +0 -35
- package/dist/ink-ui/components/NativeCursor.js.map +0 -1
- package/dist/ink-ui/components/PixelHorseBanner.d.ts +0 -8
- package/dist/ink-ui/components/PixelHorseBanner.d.ts.map +0 -1
- package/dist/ink-ui/components/PixelHorseBanner.js +0 -97
- package/dist/ink-ui/components/PixelHorseBanner.js.map +0 -1
- package/dist/ink-ui/components/PromptInput.d.ts +0 -13
- package/dist/ink-ui/components/PromptInput.d.ts.map +0 -1
- package/dist/ink-ui/components/PromptInput.js +0 -30
- package/dist/ink-ui/components/PromptInput.js.map +0 -1
- package/dist/ink-ui/components/RunningHorseIndicator.d.ts +0 -13
- package/dist/ink-ui/components/RunningHorseIndicator.d.ts.map +0 -1
- package/dist/ink-ui/components/RunningHorseIndicator.js +0 -53
- package/dist/ink-ui/components/RunningHorseIndicator.js.map +0 -1
- package/dist/ink-ui/components/SelectList.d.ts +0 -16
- package/dist/ink-ui/components/SelectList.d.ts.map +0 -1
- package/dist/ink-ui/components/SelectList.js +0 -60
- package/dist/ink-ui/components/SelectList.js.map +0 -1
- package/dist/ink-ui/components/StatusLine.d.ts +0 -11
- package/dist/ink-ui/components/StatusLine.d.ts.map +0 -1
- package/dist/ink-ui/components/StatusLine.js +0 -70
- package/dist/ink-ui/components/StatusLine.js.map +0 -1
- package/dist/ink-ui/components/ToolActivity.d.ts +0 -19
- package/dist/ink-ui/components/ToolActivity.d.ts.map +0 -1
- package/dist/ink-ui/components/ToolActivity.js +0 -134
- package/dist/ink-ui/components/ToolActivity.js.map +0 -1
- package/dist/ink-ui/components/Transcript.d.ts +0 -14
- package/dist/ink-ui/components/Transcript.d.ts.map +0 -1
- package/dist/ink-ui/components/Transcript.js +0 -66
- package/dist/ink-ui/components/Transcript.js.map +0 -1
- package/dist/ink-ui/controllers/chat-controller.d.ts +0 -2
- package/dist/ink-ui/controllers/chat-controller.d.ts.map +0 -1
- package/dist/ink-ui/controllers/chat-controller.js.map +0 -1
- package/dist/ink-ui/hooks/use-raw-input-bridge.d.ts +0 -6
- package/dist/ink-ui/hooks/use-raw-input-bridge.d.ts.map +0 -1
- package/dist/ink-ui/hooks/use-raw-input-bridge.js +0 -27
- package/dist/ink-ui/hooks/use-raw-input-bridge.js.map +0 -1
- package/dist/ink-ui/hooks/use-terminal-size.d.ts +0 -7
- package/dist/ink-ui/hooks/use-terminal-size.d.ts.map +0 -1
- package/dist/ink-ui/hooks/use-terminal-size.js +0 -34
- package/dist/ink-ui/hooks/use-terminal-size.js.map +0 -1
- package/dist/ink-ui/launch.d.ts +0 -9
- package/dist/ink-ui/launch.d.ts.map +0 -1
- package/dist/ink-ui/launch.js +0 -101
- package/dist/ink-ui/launch.js.map +0 -1
- package/dist/ink-ui/runtime/grapheme.d.ts +0 -10
- package/dist/ink-ui/runtime/grapheme.d.ts.map +0 -1
- package/dist/ink-ui/runtime/grapheme.js +0 -17
- package/dist/ink-ui/runtime/grapheme.js.map +0 -1
- package/dist/ink-ui/runtime/input-buffer.d.ts +0 -10
- package/dist/ink-ui/runtime/input-buffer.d.ts.map +0 -1
- package/dist/ink-ui/runtime/input-buffer.js +0 -18
- package/dist/ink-ui/runtime/input-buffer.js.map +0 -1
- package/dist/ink-ui/runtime/layout-budget.d.ts +0 -13
- package/dist/ink-ui/runtime/layout-budget.d.ts.map +0 -1
- package/dist/ink-ui/runtime/layout-budget.js +0 -25
- package/dist/ink-ui/runtime/layout-budget.js.map +0 -1
- package/dist/ink-ui/runtime/native-cursor.d.ts +0 -62
- package/dist/ink-ui/runtime/native-cursor.d.ts.map +0 -1
- package/dist/ink-ui/runtime/native-cursor.js +0 -398
- package/dist/ink-ui/runtime/native-cursor.js.map +0 -1
- package/dist/ink-ui/runtime/prompt-layout.d.ts +0 -10
- package/dist/ink-ui/runtime/prompt-layout.d.ts.map +0 -1
- package/dist/ink-ui/runtime/prompt-layout.js +0 -21
- package/dist/ink-ui/runtime/prompt-layout.js.map +0 -1
- package/dist/ink-ui/runtime/raw-input.d.ts +0 -4
- package/dist/ink-ui/runtime/raw-input.d.ts.map +0 -1
- package/dist/ink-ui/runtime/raw-input.js +0 -15
- package/dist/ink-ui/runtime/raw-input.js.map +0 -1
- package/dist/ink-ui/runtime/transcript-state.d.ts +0 -37
- package/dist/ink-ui/runtime/transcript-state.d.ts.map +0 -1
- package/dist/ink-ui/runtime/transcript-state.js +0 -91
- package/dist/ink-ui/runtime/transcript-state.js.map +0 -1
- package/dist/ink-ui/screens/ReplScreen.d.ts +0 -27
- package/dist/ink-ui/screens/ReplScreen.d.ts.map +0 -1
- package/dist/ink-ui/screens/ReplScreen.js +0 -781
- package/dist/ink-ui/screens/ReplScreen.js.map +0 -1
- package/dist/ink-ui/types.d.ts +0 -2
- package/dist/ink-ui/types.d.ts.map +0 -1
- package/dist/ink-ui/types.js.map +0 -1
- package/dist/runtime/chat-checkpoint.d.ts +0 -17
- package/dist/runtime/chat-checkpoint.d.ts.map +0 -1
- package/dist/runtime/chat-checkpoint.js +0 -105
- package/dist/runtime/chat-checkpoint.js.map +0 -1
- package/dist/runtime/chat-command-scope.d.ts +0 -5
- package/dist/runtime/chat-command-scope.d.ts.map +0 -1
- package/dist/runtime/chat-command-scope.js +0 -22
- package/dist/runtime/chat-command-scope.js.map +0 -1
- package/dist/runtime/chat-compact.d.ts +0 -26
- package/dist/runtime/chat-compact.d.ts.map +0 -1
- package/dist/runtime/chat-compact.js +0 -132
- package/dist/runtime/chat-compact.js.map +0 -1
- package/dist/runtime/chat-controller.d.ts +0 -62
- package/dist/runtime/chat-controller.d.ts.map +0 -1
- package/dist/runtime/chat-controller.js +0 -1620
- package/dist/runtime/chat-controller.js.map +0 -1
- package/dist/runtime/chat-effort.d.ts +0 -5
- package/dist/runtime/chat-effort.d.ts.map +0 -1
- package/dist/runtime/chat-effort.js +0 -47
- package/dist/runtime/chat-effort.js.map +0 -1
- package/dist/runtime/chat-presentation.d.ts +0 -63
- package/dist/runtime/chat-presentation.d.ts.map +0 -1
- package/dist/runtime/chat-presentation.js +0 -561
- package/dist/runtime/chat-presentation.js.map +0 -1
- package/dist/runtime/chat-trace.d.ts +0 -52
- package/dist/runtime/chat-trace.d.ts.map +0 -1
- package/dist/runtime/chat-trace.js +0 -234
- package/dist/runtime/chat-trace.js.map +0 -1
- package/dist/runtime/chat-workspace.d.ts +0 -22
- package/dist/runtime/chat-workspace.d.ts.map +0 -1
- package/dist/runtime/chat-workspace.js +0 -154
- package/dist/runtime/chat-workspace.js.map +0 -1
- package/dist/runtime/goals/accounting.d.ts +0 -45
- package/dist/runtime/goals/accounting.d.ts.map +0 -1
- package/dist/runtime/goals/accounting.js +0 -114
- package/dist/runtime/goals/accounting.js.map +0 -1
- package/dist/runtime/goals/coordinator.d.ts +0 -92
- package/dist/runtime/goals/coordinator.d.ts.map +0 -1
- package/dist/runtime/goals/coordinator.js +0 -1471
- package/dist/runtime/goals/coordinator.js.map +0 -1
- package/dist/runtime/goals/lifecycle.d.ts +0 -13
- package/dist/runtime/goals/lifecycle.d.ts.map +0 -1
- package/dist/runtime/goals/lifecycle.js +0 -46
- package/dist/runtime/goals/lifecycle.js.map +0 -1
- package/dist/runtime/goals/prompt.d.ts +0 -16
- package/dist/runtime/goals/prompt.d.ts.map +0 -1
- package/dist/runtime/goals/prompt.js +0 -88
- package/dist/runtime/goals/prompt.js.map +0 -1
- package/dist/runtime/goals/stop-policy.d.ts +0 -9
- package/dist/runtime/goals/stop-policy.d.ts.map +0 -1
- package/dist/runtime/goals/stop-policy.js +0 -83
- package/dist/runtime/goals/stop-policy.js.map +0 -1
- package/dist/runtime/goals/tools.d.ts +0 -61
- package/dist/runtime/goals/tools.d.ts.map +0 -1
- package/dist/runtime/goals/tools.js +0 -568
- package/dist/runtime/goals/tools.js.map +0 -1
- package/dist/sdk/index.d.ts +0 -10
- package/dist/sdk/index.d.ts.map +0 -1
- package/dist/sdk/index.js +0 -23
- package/dist/sdk/index.js.map +0 -1
- package/dist/sdk/init.d.ts +0 -24
- package/dist/sdk/init.d.ts.map +0 -1
- package/dist/sdk/init.js +0 -48
- package/dist/sdk/init.js.map +0 -1
- package/dist/sdk/query.d.ts +0 -19
- package/dist/sdk/query.d.ts.map +0 -1
- package/dist/sdk/query.js +0 -42
- package/dist/sdk/query.js.map +0 -1
- package/dist/sdk/sessions.d.ts +0 -19
- package/dist/sdk/sessions.d.ts.map +0 -1
- package/dist/sdk/sessions.js +0 -57
- package/dist/sdk/sessions.js.map +0 -1
- package/dist/sdk/types.d.ts +0 -47
- package/dist/sdk/types.d.ts.map +0 -1
- package/dist/sdk/types.js +0 -8
- package/dist/sdk/types.js.map +0 -1
- package/dist/services/agent-runner.d.ts +0 -71
- package/dist/services/agent-runner.d.ts.map +0 -1
- package/dist/services/agent-runner.js +0 -185
- package/dist/services/agent-runner.js.map +0 -1
- package/dist/services/task-manager.d.ts +0 -161
- package/dist/services/task-manager.d.ts.map +0 -1
- package/dist/services/task-manager.js +0 -315
- package/dist/services/task-manager.js.map +0 -1
- package/dist/skills/discovery.d.ts +0 -22
- package/dist/skills/discovery.d.ts.map +0 -1
- package/dist/skills/discovery.js +0 -75
- package/dist/skills/discovery.js.map +0 -1
- package/dist/skills/index.d.ts +0 -11
- package/dist/skills/index.d.ts.map +0 -1
- package/dist/skills/index.js.map +0 -1
- package/dist/skills/loader.d.ts +0 -53
- package/dist/skills/loader.d.ts.map +0 -1
- package/dist/skills/loader.js +0 -421
- package/dist/skills/loader.js.map +0 -1
- package/dist/skills/registry.d.ts +0 -41
- package/dist/skills/registry.d.ts.map +0 -1
- package/dist/skills/registry.js +0 -157
- package/dist/skills/registry.js.map +0 -1
- package/dist/skills/runtime.d.ts +0 -46
- package/dist/skills/runtime.d.ts.map +0 -1
- package/dist/skills/runtime.js +0 -363
- package/dist/skills/runtime.js.map +0 -1
- package/dist/skills/types.d.ts +0 -112
- package/dist/skills/types.d.ts.map +0 -1
- package/dist/skills/types.js +0 -24
- package/dist/skills/types.js.map +0 -1
- package/dist/tools/index.d.ts +0 -52
- package/dist/tools/index.d.ts.map +0 -1
- package/dist/tools/index.js +0 -2268
- package/dist/tools/index.js.map +0 -1
- package/dist/tools/mcp.d.ts +0 -99
- package/dist/tools/mcp.d.ts.map +0 -1
- package/dist/tools/mcp.js +0 -695
- package/dist/tools/mcp.js.map +0 -1
- package/dist/tools/plan.d.ts +0 -17
- package/dist/tools/plan.d.ts.map +0 -1
- package/dist/tools/plan.js +0 -84
- package/dist/tools/plan.js.map +0 -1
- package/docs/migration/v0.1.8-to-v0.1.9.md +0 -60
- package/docs/plan/v0.1.9-release-checklist.md +0 -64
|
@@ -1,1620 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.InkChatController = exports.AgentChatController = exports.sessionMessagesToTranscriptEntries = exports.createToolEventPresenter = exports.createAssistantStreamPresenter = void 0;
|
|
4
|
-
exports.loadSessionIntoRuntime = loadSessionIntoRuntime;
|
|
5
|
-
exports.closeSession = closeSession;
|
|
6
|
-
const commands_1 = require("../commands");
|
|
7
|
-
const crypto_1 = require("crypto");
|
|
8
|
-
const parser_1 = require("../commands/parser");
|
|
9
|
-
const session_storage_1 = require("../services/session-storage");
|
|
10
|
-
const config_1 = require("../services/config");
|
|
11
|
-
const provider_resilience_1 = require("../services/provider-resilience");
|
|
12
|
-
const tool_allowlist_1 = require("../services/tool-allowlist");
|
|
13
|
-
const framework_1 = require("../framework");
|
|
14
|
-
const prompt_1 = require("./goals/prompt");
|
|
15
|
-
const harness_1 = require("../harness");
|
|
16
|
-
const tools_1 = require("../tools");
|
|
17
|
-
const tool_scheduler_1 = require("../framework/tool-scheduler");
|
|
18
|
-
const tool_serializer_1 = require("../framework/tool-serializer");
|
|
19
|
-
const tool_artifacts_1 = require("../core/tool-artifacts");
|
|
20
|
-
const skills_1 = require("../skills");
|
|
21
|
-
const subagents_1 = require("./subagents");
|
|
22
|
-
const file_context_1 = require("../services/file-context");
|
|
23
|
-
const prompt_context_1 = require("../memory/prompt-context");
|
|
24
|
-
const prompt_context_2 = require("../services/prompt-context");
|
|
25
|
-
const workspace_state_1 = require("../services/workspace-state");
|
|
26
|
-
const verification_profile_1 = require("../services/verification-profile");
|
|
27
|
-
const ui_events_1 = require("./ui-events");
|
|
28
|
-
const ui_view_model_1 = require("./ui-view-model");
|
|
29
|
-
const agent_status_1 = require("./agent-status");
|
|
30
|
-
const loop_budget_1 = require("./loop-budget");
|
|
31
|
-
const observability_1 = require("../utils/observability");
|
|
32
|
-
const chat_trace_1 = require("./chat-trace");
|
|
33
|
-
const chat_checkpoint_1 = require("./chat-checkpoint");
|
|
34
|
-
const chat_workspace_1 = require("./chat-workspace");
|
|
35
|
-
const chat_presentation_1 = require("./chat-presentation");
|
|
36
|
-
const chat_effort_1 = require("./chat-effort");
|
|
37
|
-
const chat_compact_1 = require("./chat-compact");
|
|
38
|
-
const agent_mode_1 = require("../framework/agent-mode");
|
|
39
|
-
const chat_command_scope_1 = require("./chat-command-scope");
|
|
40
|
-
var chat_presentation_2 = require("./chat-presentation");
|
|
41
|
-
Object.defineProperty(exports, "createAssistantStreamPresenter", { enumerable: true, get: function () { return chat_presentation_2.createAssistantStreamPresenter; } });
|
|
42
|
-
Object.defineProperty(exports, "createToolEventPresenter", { enumerable: true, get: function () { return chat_presentation_2.createToolEventPresenter; } });
|
|
43
|
-
Object.defineProperty(exports, "sessionMessagesToTranscriptEntries", { enumerable: true, get: function () { return chat_presentation_2.sessionMessagesToTranscriptEntries; } });
|
|
44
|
-
class AgentChatController {
|
|
45
|
-
setGoalCoordinator(coord) {
|
|
46
|
-
this.goalCoordinator = coord;
|
|
47
|
-
}
|
|
48
|
-
resolveToolAllowlist() {
|
|
49
|
-
// Resolve on every evaluation, including execution. A model response can
|
|
50
|
-
// contain several serial calls prepared before the first permission prompt;
|
|
51
|
-
// once the user chooses project/global scope, the next call in that same
|
|
52
|
-
// response must observe the persisted grant instead of prompting again.
|
|
53
|
-
return (toolName, args) => (0, tool_allowlist_1.resolveProjectToolAllowlist)(this.runtime.cwd).evaluator?.(toolName, args);
|
|
54
|
-
}
|
|
55
|
-
constructor(runtime, events, controllerOptions = {}) {
|
|
56
|
-
this.runtime = runtime;
|
|
57
|
-
this.events = events;
|
|
58
|
-
this.controllerOptions = controllerOptions;
|
|
59
|
-
/** v0.2.26: optional goal coordinator for prompt injection and turn finalization. */
|
|
60
|
-
this.goalCoordinator = null;
|
|
61
|
-
}
|
|
62
|
-
setLoopStats(stats) {
|
|
63
|
-
this.runtime.store.setLastLoopStats(stats);
|
|
64
|
-
this.events.loopStatsUpdated?.(stats);
|
|
65
|
-
}
|
|
66
|
-
async runInput(input, options = {}) {
|
|
67
|
-
const text = input.trim();
|
|
68
|
-
if (!text)
|
|
69
|
-
return;
|
|
70
|
-
// Every root input owns a fresh accounting snapshot. Commands and local
|
|
71
|
-
// fast paths are known zero-provider turns; runChat changes tokenUsage to
|
|
72
|
-
// null before networking so missing provider usage remains fail-closed.
|
|
73
|
-
const storeWithState = this.runtime.store;
|
|
74
|
-
storeWithState.setState?.({
|
|
75
|
-
tokenUsage: { promptTokens: 0, completionTokens: 0 },
|
|
76
|
-
lastLoopStats: undefined,
|
|
77
|
-
});
|
|
78
|
-
const parsed = (0, parser_1.parseInput)(text);
|
|
79
|
-
if (!parsed.isCommand) {
|
|
80
|
-
const localFastPath = (0, chat_presentation_1.parseLocalFastPath)(text);
|
|
81
|
-
if (localFastPath) {
|
|
82
|
-
await this.runLocalFastPath(text, localFastPath, options);
|
|
83
|
-
return;
|
|
84
|
-
}
|
|
85
|
-
await this.runChat(text, options);
|
|
86
|
-
return;
|
|
87
|
-
}
|
|
88
|
-
const command = (0, commands_1.findCommand)(parsed.name);
|
|
89
|
-
if (!command) {
|
|
90
|
-
if ((0, skills_1.hasMatchingSkill)(text, this.runtime.cwd)) {
|
|
91
|
-
await this.runChat(text, options);
|
|
92
|
-
return;
|
|
93
|
-
}
|
|
94
|
-
const suggestions = (0, parser_1.buildCommandSuggestions)(parsed.name);
|
|
95
|
-
this.events.append({
|
|
96
|
-
role: 'error',
|
|
97
|
-
title: 'unknown command',
|
|
98
|
-
content: suggestions.length > 0
|
|
99
|
-
? `Unknown command: /${parsed.name}\nDid you mean: ${suggestions.map(item => `/${item}`).join(', ')}?`
|
|
100
|
-
: `Unknown command: /${parsed.name}`,
|
|
101
|
-
errorLayer: 'runtime',
|
|
102
|
-
});
|
|
103
|
-
return;
|
|
104
|
-
}
|
|
105
|
-
const activeRenderer = this.controllerOptions.uiRenderer ?? this.runtime.config.ui?.renderer ?? 'terminal';
|
|
106
|
-
if ((0, chat_command_scope_1.rejectUnsupportedRenderer)(this.events, command, activeRenderer))
|
|
107
|
-
return;
|
|
108
|
-
if (parsed.name === 'clear') {
|
|
109
|
-
if (this.events.clearView) {
|
|
110
|
-
this.events.clearView();
|
|
111
|
-
}
|
|
112
|
-
else {
|
|
113
|
-
this.events.clearTranscript();
|
|
114
|
-
}
|
|
115
|
-
this.events.setStatus('View cleared. Conversation context is preserved.');
|
|
116
|
-
return;
|
|
117
|
-
}
|
|
118
|
-
if (parsed.name === 'exit' || parsed.name === 'quit' || parsed.name === 'q') {
|
|
119
|
-
this.events.shutdownRequested?.('user request');
|
|
120
|
-
await this.runtime.shutdown();
|
|
121
|
-
return;
|
|
122
|
-
}
|
|
123
|
-
const compatibilityAlias = command.compatibilityAliases?.find(alias => alias.name.toLowerCase() === parsed.name.toLowerCase());
|
|
124
|
-
const deprecation = compatibilityAlias?.lifecycle ??
|
|
125
|
-
(command.lifecycle.status === 'deprecated' ? command.lifecycle : undefined);
|
|
126
|
-
if (deprecation) {
|
|
127
|
-
this.events.append({
|
|
128
|
-
role: 'system',
|
|
129
|
-
title: `/${parsed.name} deprecated`,
|
|
130
|
-
content: `/${parsed.name} is deprecated${deprecation.replacement ? `; use ${deprecation.replacement}` : ''}. It will be removed in ${deprecation.removeIn ?? 'a future release'}.`,
|
|
131
|
-
statusTone: 'warning',
|
|
132
|
-
command: {
|
|
133
|
-
id: command.id,
|
|
134
|
-
name: command.name,
|
|
135
|
-
source: command.source,
|
|
136
|
-
success: true,
|
|
137
|
-
},
|
|
138
|
-
});
|
|
139
|
-
}
|
|
140
|
-
const ctx = this.createCommandContext(options.abortSignal, options.turnId);
|
|
141
|
-
let commandProviderAttempts = 0;
|
|
142
|
-
const commandProviderPreflight = async (context) => {
|
|
143
|
-
commandProviderAttempts += 1;
|
|
144
|
-
return this.controllerOptions.beforeProviderRequest
|
|
145
|
-
? this.controllerOptions.beforeProviderRequest(context)
|
|
146
|
-
: { available: true };
|
|
147
|
-
};
|
|
148
|
-
const restoreProviderPreflight = typeof this.runtime.llm?.setProviderRequestPreflight === 'function'
|
|
149
|
-
? this.runtime.llm.setProviderRequestPreflight(commandProviderPreflight)
|
|
150
|
-
: undefined;
|
|
151
|
-
const commandUsage = { promptTokens: 0, completionTokens: 0 };
|
|
152
|
-
let commandUsageEvents = 0;
|
|
153
|
-
const unsubscribeCommandUsage = typeof this.runtime.llm?.subscribeUsage === 'function'
|
|
154
|
-
? this.runtime.llm.subscribeUsage(event => {
|
|
155
|
-
commandUsageEvents += 1;
|
|
156
|
-
commandUsage.promptTokens += event.usage.promptTokens;
|
|
157
|
-
commandUsage.completionTokens += event.usage.completionTokens;
|
|
158
|
-
})
|
|
159
|
-
: undefined;
|
|
160
|
-
let result;
|
|
161
|
-
let output;
|
|
162
|
-
try {
|
|
163
|
-
if (command.audience === 'primary') {
|
|
164
|
-
result = await command.execute(ctx, parsed.args);
|
|
165
|
-
output = '';
|
|
166
|
-
}
|
|
167
|
-
else {
|
|
168
|
-
({ result, output } = await (0, chat_presentation_1.captureConsoleOutput)(() => command.execute(ctx, parsed.args)));
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
finally {
|
|
172
|
-
unsubscribeCommandUsage?.();
|
|
173
|
-
restoreProviderPreflight?.();
|
|
174
|
-
if (commandUsage.promptTokens > 0 || commandUsage.completionTokens > 0) {
|
|
175
|
-
this.runtime.store.setTokenUsage(commandUsage);
|
|
176
|
-
}
|
|
177
|
-
const providerRequests = Math.max(commandProviderAttempts, commandUsageEvents);
|
|
178
|
-
if (providerRequests > 0) {
|
|
179
|
-
const diagnostics = (0, chat_trace_1.getLastRequestDiagnostics)(this.runtime.llm);
|
|
180
|
-
const retryCount = diagnostics?.retryCount ?? 0;
|
|
181
|
-
const fallbackCount = diagnostics?.fallbackTriggered ? 1 : 0;
|
|
182
|
-
this.setLoopStats({
|
|
183
|
-
turnsStarted: 1,
|
|
184
|
-
llmRequests: providerRequests,
|
|
185
|
-
toolCalls: 0,
|
|
186
|
-
readOnlyToolCalls: 0,
|
|
187
|
-
unsafeToolCalls: 0,
|
|
188
|
-
toolResultBytes: 0,
|
|
189
|
-
modelVisibleToolBytes: 0,
|
|
190
|
-
summarizedBytes: 0,
|
|
191
|
-
finishReason: commandUsageEvents > 0 ? 'completed' : 'failed',
|
|
192
|
-
providerRetryCount: retryCount,
|
|
193
|
-
providerRetryDelayMs: diagnostics?.retryDelayMs,
|
|
194
|
-
providerRetryErrorTypes: diagnostics?.retryErrorTypes,
|
|
195
|
-
providerLastRetryErrorType: diagnostics?.lastRetryErrorType,
|
|
196
|
-
providerLastRetryStatus: diagnostics?.lastRetryStatus,
|
|
197
|
-
providerFallbackCount: fallbackCount,
|
|
198
|
-
providerFallbackFromModel: diagnostics?.fallbackFromModel,
|
|
199
|
-
providerFallbackToModel: diagnostics?.fallbackToModel,
|
|
200
|
-
providerFinalModel: diagnostics?.finalModel,
|
|
201
|
-
providerUsingFallback: diagnostics?.usingFallback,
|
|
202
|
-
singleReadOnlyStreak: 0,
|
|
203
|
-
batchReadSuggestionCount: 0,
|
|
204
|
-
localFastPathUsed: false,
|
|
205
|
-
});
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
const commandMeta = {
|
|
209
|
-
id: command.id,
|
|
210
|
-
name: command.name,
|
|
211
|
-
source: command.source,
|
|
212
|
-
success: result.success,
|
|
213
|
-
};
|
|
214
|
-
if (output) {
|
|
215
|
-
this.events.append({
|
|
216
|
-
role: result.success ? 'system' : 'error',
|
|
217
|
-
title: `/${command.name}`,
|
|
218
|
-
content: output,
|
|
219
|
-
command: commandMeta,
|
|
220
|
-
});
|
|
221
|
-
}
|
|
222
|
-
if (result.output) {
|
|
223
|
-
this.events.append({
|
|
224
|
-
role: result.success ? 'system' : 'error',
|
|
225
|
-
title: `/${command.name}`,
|
|
226
|
-
content: result.output,
|
|
227
|
-
command: commandMeta,
|
|
228
|
-
});
|
|
229
|
-
}
|
|
230
|
-
if (result.error) {
|
|
231
|
-
this.events.append({
|
|
232
|
-
role: 'error',
|
|
233
|
-
title: `/${command.name}`,
|
|
234
|
-
content: result.error,
|
|
235
|
-
errorLayer: 'runtime',
|
|
236
|
-
command: commandMeta,
|
|
237
|
-
});
|
|
238
|
-
}
|
|
239
|
-
if (result.sessionPicker) {
|
|
240
|
-
this.events.showSessionPicker(result.sessionPicker);
|
|
241
|
-
return;
|
|
242
|
-
}
|
|
243
|
-
if (result.modelPicker) {
|
|
244
|
-
this.events.showModelPicker?.(result.modelPicker);
|
|
245
|
-
return;
|
|
246
|
-
}
|
|
247
|
-
if (result.editPreview) {
|
|
248
|
-
this.events.showEditPreview(result.editPreview);
|
|
249
|
-
return;
|
|
250
|
-
}
|
|
251
|
-
if (result.effortEvent) {
|
|
252
|
-
this.events.effortEvent?.(result.effortEvent);
|
|
253
|
-
}
|
|
254
|
-
if (result.continueAsChat) {
|
|
255
|
-
await this.runChat(result.chatInput ?? parsed.args, options);
|
|
256
|
-
}
|
|
257
|
-
}
|
|
258
|
-
async runRequest(request, options = {}) {
|
|
259
|
-
const internalInput = request.text?.trim() ||
|
|
260
|
-
'Continue pursuing the active goal from its persisted plan and evidence.';
|
|
261
|
-
const run = () => this.runInput(internalInput, {
|
|
262
|
-
...options,
|
|
263
|
-
persistAsUserMessage: request.persistAsUserMessage,
|
|
264
|
-
inputKind: request.inputKind,
|
|
265
|
-
});
|
|
266
|
-
if (!request.goal) {
|
|
267
|
-
await run();
|
|
268
|
-
return;
|
|
269
|
-
}
|
|
270
|
-
await chat_trace_1.goalTraceContext.run({
|
|
271
|
-
goalId: request.goal.goalId,
|
|
272
|
-
goalRevision: request.goal.revision,
|
|
273
|
-
goalInputKind: request.inputKind,
|
|
274
|
-
getStopReason: () => this.goalCoordinator?.goal?.stopReason?.message,
|
|
275
|
-
}, run);
|
|
276
|
-
}
|
|
277
|
-
async runLocalFastPath(input, action, options = {}) {
|
|
278
|
-
const activeSession = this.runtime.getSession() ??
|
|
279
|
-
this.runtime.ensureSession() ??
|
|
280
|
-
(0, session_storage_1.loadSessionMeta)(this.runtime.getSession()?.id ?? '');
|
|
281
|
-
const sessionId = activeSession?.id;
|
|
282
|
-
const turnId = (0, chat_trace_1.traceTurnId)(options.turnId);
|
|
283
|
-
(0, observability_1.setDiagnosticTraceContext)({
|
|
284
|
-
traceId: `${sessionId ?? 'local'}:${turnId}`,
|
|
285
|
-
...(sessionId ? { sessionId } : {}),
|
|
286
|
-
turnId,
|
|
287
|
-
});
|
|
288
|
-
const localCallId = `local-${turnId}`;
|
|
289
|
-
const start = Date.now();
|
|
290
|
-
const preWorkspace = (0, workspace_state_1.captureWorkspaceSnapshot)(this.runtime.cwd);
|
|
291
|
-
const traceArgs = (0, chat_trace_1.buildTraceArgsDetails)(this.runtime.cwd, action.tool, action.args);
|
|
292
|
-
if (sessionId) {
|
|
293
|
-
(0, session_storage_1.appendSessionMessage)(sessionId, {
|
|
294
|
-
role: 'user',
|
|
295
|
-
content: input,
|
|
296
|
-
timestamp: Date.now(),
|
|
297
|
-
});
|
|
298
|
-
(0, chat_trace_1.recordTraceEvent)(this.events, sessionId, {
|
|
299
|
-
turnId,
|
|
300
|
-
type: 'turn_start',
|
|
301
|
-
inputBytes: (0, chat_trace_1.byteLength)(input),
|
|
302
|
-
localFastPathUsed: true,
|
|
303
|
-
});
|
|
304
|
-
(0, chat_workspace_1.appendWorkspaceSnapshotTrace)(this.events, sessionId, turnId, 'pre_turn', preWorkspace);
|
|
305
|
-
(0, chat_trace_1.recordTraceEvent)(this.events, sessionId, {
|
|
306
|
-
turnId,
|
|
307
|
-
type: 'local_fast_path',
|
|
308
|
-
name: action.tool,
|
|
309
|
-
...traceArgs,
|
|
310
|
-
note: (0, chat_trace_1.compactMiddle)(action.label, 160),
|
|
311
|
-
});
|
|
312
|
-
}
|
|
313
|
-
if (options.persistAsUserMessage !== false) {
|
|
314
|
-
this.runtime.store.addMessage({ role: 'user', content: input });
|
|
315
|
-
}
|
|
316
|
-
this.events.setStatus(`Running local ${action.label}...`);
|
|
317
|
-
try {
|
|
318
|
-
const tool = (0, tools_1.getRuntimeTools)().find(candidate => candidate.name === action.tool);
|
|
319
|
-
if (!tool) {
|
|
320
|
-
throw new chat_presentation_1.LocalFastPathBlockedError(`Local fast path tool ${action.tool} is unavailable.`);
|
|
321
|
-
}
|
|
322
|
-
const effectivePermissionMode = this.runtime.store.getEffectivePermissionMode();
|
|
323
|
-
const toolAllowlist = this.resolveToolAllowlist();
|
|
324
|
-
const toolContext = {
|
|
325
|
-
cwd: this.runtime.cwd,
|
|
326
|
-
config: {
|
|
327
|
-
name: this.runtime.config.name,
|
|
328
|
-
mode: this.runtime.config.mode,
|
|
329
|
-
},
|
|
330
|
-
sessionId,
|
|
331
|
-
turnId,
|
|
332
|
-
permissionMode: effectivePermissionMode,
|
|
333
|
-
toolAllowlist,
|
|
334
|
-
toolConfirmation: this.runtime.config.toolConfirmation,
|
|
335
|
-
confirmToolUse: effectivePermissionMode === 'auto' ? undefined : this.controllerOptions.confirmToolUse,
|
|
336
|
-
};
|
|
337
|
-
let permission;
|
|
338
|
-
try {
|
|
339
|
-
permission = tool.checkPermissions?.(action.args, toolContext);
|
|
340
|
-
}
|
|
341
|
-
catch (error) {
|
|
342
|
-
const detail = error instanceof Error ? error.message : String(error);
|
|
343
|
-
throw new chat_presentation_1.LocalFastPathBlockedError(`Permission check failed closed: ${detail}`);
|
|
344
|
-
}
|
|
345
|
-
const effective = (0, tool_scheduler_1.resolveEffectivePermission)({
|
|
346
|
-
toolName: action.tool,
|
|
347
|
-
tool,
|
|
348
|
-
args: action.args,
|
|
349
|
-
permission,
|
|
350
|
-
permissionMode: effectivePermissionMode,
|
|
351
|
-
allowlist: toolAllowlist?.(action.tool, action.args),
|
|
352
|
-
toolConfirmation: this.runtime.config.toolConfirmation,
|
|
353
|
-
});
|
|
354
|
-
if (effective.outcome === 'deny') {
|
|
355
|
-
throw new chat_presentation_1.LocalFastPathBlockedError(effective.reason ||
|
|
356
|
-
`Local fast path blocked by ${effective.source ?? 'permission policy'}.`);
|
|
357
|
-
}
|
|
358
|
-
if (effective.outcome === 'confirm') {
|
|
359
|
-
if (this.runtime.config.toolConfirmation === 'deny' ||
|
|
360
|
-
!this.controllerOptions.confirmToolUse) {
|
|
361
|
-
throw new chat_presentation_1.LocalFastPathBlockedError(effective.reason || 'Local fast path requires user confirmation.');
|
|
362
|
-
}
|
|
363
|
-
const approved = await this.controllerOptions.confirmToolUse({
|
|
364
|
-
name: action.tool,
|
|
365
|
-
args: action.args,
|
|
366
|
-
reason: effective.reason,
|
|
367
|
-
abortSignal: options.abortSignal,
|
|
368
|
-
});
|
|
369
|
-
if (!approved) {
|
|
370
|
-
throw new chat_presentation_1.LocalFastPathBlockedError(`Local fast path ${action.tool} requires confirmation and was denied by user.`);
|
|
371
|
-
}
|
|
372
|
-
}
|
|
373
|
-
if (options.abortSignal?.aborted) {
|
|
374
|
-
throw new chat_presentation_1.LocalFastPathBlockedError('Local fast path was cancelled before tool execution.');
|
|
375
|
-
}
|
|
376
|
-
if (sessionId) {
|
|
377
|
-
(0, chat_trace_1.recordTraceEvent)(this.events, sessionId, {
|
|
378
|
-
turnId,
|
|
379
|
-
type: 'tool_call',
|
|
380
|
-
name: action.tool,
|
|
381
|
-
callId: localCallId,
|
|
382
|
-
...traceArgs,
|
|
383
|
-
});
|
|
384
|
-
}
|
|
385
|
-
const result = await (0, tools_1.executeTool)(action.tool, action.args, options.abortSignal, {
|
|
386
|
-
...toolContext,
|
|
387
|
-
sessionId,
|
|
388
|
-
turnId,
|
|
389
|
-
});
|
|
390
|
-
const duration = Date.now() - start;
|
|
391
|
-
const envelope = (0, tool_serializer_1.parseToolResultEnvelope)(result);
|
|
392
|
-
const outputBytes = typeof envelope.outputBytes === 'number'
|
|
393
|
-
? envelope.outputBytes
|
|
394
|
-
: Buffer.byteLength(result, 'utf8');
|
|
395
|
-
const formattedLocalResult = (0, chat_presentation_1.formatLocalFastPathAssistantContent)(action, result, this.runtime.cwd);
|
|
396
|
-
const assistantContent = formattedLocalResult.content;
|
|
397
|
-
const stats = (0, framework_1.createLocalFastPathLoopStats)({
|
|
398
|
-
finishReason: envelope.success ? 'completed' : 'failed',
|
|
399
|
-
toolCalls: 1,
|
|
400
|
-
readOnlyToolCalls: action.tool === 'exec_command' ? 0 : 1,
|
|
401
|
-
unsafeToolCalls: action.tool === 'exec_command' ? 1 : 0,
|
|
402
|
-
toolResultBytes: outputBytes,
|
|
403
|
-
modelVisibleToolBytes: 0,
|
|
404
|
-
summarizedBytes: outputBytes,
|
|
405
|
-
});
|
|
406
|
-
const localToolResultEvent = {
|
|
407
|
-
type: 'tool_result',
|
|
408
|
-
name: action.tool,
|
|
409
|
-
args: action.args,
|
|
410
|
-
callId: localCallId,
|
|
411
|
-
result,
|
|
412
|
-
modelVisibleResult: result,
|
|
413
|
-
duration,
|
|
414
|
-
success: envelope.success,
|
|
415
|
-
error: envelope.error,
|
|
416
|
-
summary: envelope.summary,
|
|
417
|
-
outputBytes,
|
|
418
|
-
artifactRef: formattedLocalResult.artifactRef,
|
|
419
|
-
};
|
|
420
|
-
this.events.append({
|
|
421
|
-
role: envelope.success ? 'tool' : 'error',
|
|
422
|
-
title: 'local',
|
|
423
|
-
content: (0, chat_presentation_1.toolFinishContent)(localToolResultEvent),
|
|
424
|
-
toolActivity: (0, chat_presentation_1.structuredToolFinishActivity)(localToolResultEvent, 1, {
|
|
425
|
-
projectPath: this.runtime.cwd,
|
|
426
|
-
turnId,
|
|
427
|
-
}),
|
|
428
|
-
});
|
|
429
|
-
this.runtime.store.addMessage({ role: 'assistant', content: assistantContent });
|
|
430
|
-
this.setLoopStats(stats);
|
|
431
|
-
if (sessionId) {
|
|
432
|
-
(0, chat_trace_1.recordTraceEvent)(this.events, sessionId, {
|
|
433
|
-
turnId,
|
|
434
|
-
type: 'tool_result',
|
|
435
|
-
name: action.tool,
|
|
436
|
-
callId: localCallId,
|
|
437
|
-
argsSummary: traceArgs.argsSummary,
|
|
438
|
-
argsArtifactId: traceArgs.argsArtifactId,
|
|
439
|
-
argsBytes: traceArgs.argsBytes,
|
|
440
|
-
success: envelope.success,
|
|
441
|
-
duration,
|
|
442
|
-
outputBytes,
|
|
443
|
-
modelVisibleBytes: 0,
|
|
444
|
-
artifactId: formattedLocalResult.artifactRef?.id,
|
|
445
|
-
error: envelope.error ? (0, chat_trace_1.compactMiddle)(envelope.error, 240) : undefined,
|
|
446
|
-
});
|
|
447
|
-
(0, chat_workspace_1.appendPostWorkspaceTrace)(this.events, sessionId, turnId, this.runtime.cwd, preWorkspace);
|
|
448
|
-
(0, chat_trace_1.recordTraceEvent)(this.events, sessionId, {
|
|
449
|
-
turnId,
|
|
450
|
-
type: 'complete',
|
|
451
|
-
finishReason: stats.finishReason,
|
|
452
|
-
stopDecision: stats.stopDecision,
|
|
453
|
-
llmRequests: stats.llmRequests,
|
|
454
|
-
toolCalls: stats.toolCalls,
|
|
455
|
-
readOnlyToolCalls: stats.readOnlyToolCalls,
|
|
456
|
-
unsafeToolCalls: stats.unsafeToolCalls,
|
|
457
|
-
localFastPathUsed: true,
|
|
458
|
-
});
|
|
459
|
-
(0, session_storage_1.appendSessionMessage)(sessionId, {
|
|
460
|
-
role: 'assistant',
|
|
461
|
-
content: assistantContent,
|
|
462
|
-
timestamp: Date.now(),
|
|
463
|
-
});
|
|
464
|
-
}
|
|
465
|
-
this.events.setStatus(envelope.success ? `Completed local ${action.label}` : `Failed local ${action.label}`);
|
|
466
|
-
}
|
|
467
|
-
catch (error) {
|
|
468
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
469
|
-
this.events.append({ role: 'error', title: 'local', content: message, errorLayer: 'tool' });
|
|
470
|
-
this.events.setStatus('Local command failed. Ready for the next input.');
|
|
471
|
-
const assistantContent = `Local fast path failed for ${action.label}.\n\n${message}`;
|
|
472
|
-
this.runtime.store.addMessage({ role: 'assistant', content: assistantContent });
|
|
473
|
-
const finishReason = error instanceof chat_presentation_1.LocalFastPathBlockedError ? 'blocked' : 'failed';
|
|
474
|
-
const stats = (0, framework_1.createLocalFastPathLoopStats)({
|
|
475
|
-
finishReason,
|
|
476
|
-
toolCalls: 0,
|
|
477
|
-
});
|
|
478
|
-
this.setLoopStats(stats);
|
|
479
|
-
if (sessionId) {
|
|
480
|
-
(0, chat_trace_1.recordTraceEvent)(this.events, sessionId, {
|
|
481
|
-
turnId,
|
|
482
|
-
type: 'error',
|
|
483
|
-
name: action.tool,
|
|
484
|
-
error: (0, chat_trace_1.compactTraceError)(error),
|
|
485
|
-
});
|
|
486
|
-
(0, chat_workspace_1.appendPostWorkspaceTrace)(this.events, sessionId, turnId, this.runtime.cwd, preWorkspace);
|
|
487
|
-
(0, chat_trace_1.recordTraceEvent)(this.events, sessionId, {
|
|
488
|
-
turnId,
|
|
489
|
-
type: 'complete',
|
|
490
|
-
finishReason: stats.finishReason,
|
|
491
|
-
stopDecision: stats.stopDecision,
|
|
492
|
-
llmRequests: stats.llmRequests,
|
|
493
|
-
toolCalls: stats.toolCalls,
|
|
494
|
-
localFastPathUsed: true,
|
|
495
|
-
note: 'local_fast_path_failed',
|
|
496
|
-
});
|
|
497
|
-
(0, session_storage_1.appendSessionMessage)(sessionId, {
|
|
498
|
-
role: 'assistant',
|
|
499
|
-
content: assistantContent,
|
|
500
|
-
timestamp: Date.now(),
|
|
501
|
-
});
|
|
502
|
-
}
|
|
503
|
-
}
|
|
504
|
-
}
|
|
505
|
-
createCommandContext(abortSignal, turnId) {
|
|
506
|
-
return {
|
|
507
|
-
cwd: this.runtime.cwd,
|
|
508
|
-
config: this.runtime.config,
|
|
509
|
-
store: this.runtime.store,
|
|
510
|
-
llm: this.runtime.llm,
|
|
511
|
-
compactCoordinator: this.runtime.compactCoordinator,
|
|
512
|
-
modelCoordinator: this.runtime.modelCoordinator,
|
|
513
|
-
runtime: this.runtime.runtime,
|
|
514
|
-
sessionId: this.runtime.getSession()?.id,
|
|
515
|
-
turnId,
|
|
516
|
-
ensureSession: this.runtime.ensureSession,
|
|
517
|
-
setSession: session => {
|
|
518
|
-
this.runtime.setSession(session);
|
|
519
|
-
(0, chat_effort_1.applySessionEffort)(this.runtime, this.events, session);
|
|
520
|
-
const renderer = this.controllerOptions.uiRenderer ?? this.runtime.config.ui?.renderer ?? 'terminal';
|
|
521
|
-
this.events.replaceTranscript((0, chat_presentation_1.sessionMessagesToTranscriptEntries)(session.id, {
|
|
522
|
-
includeToolOutputViews: renderer === 'tui',
|
|
523
|
-
}));
|
|
524
|
-
},
|
|
525
|
-
sessionRestored: event => {
|
|
526
|
-
this.events.sessionRestored?.(event);
|
|
527
|
-
},
|
|
528
|
-
getSession: this.runtime.getSession,
|
|
529
|
-
getActiveGoal: () => this.goalCoordinator?.goal ?? null,
|
|
530
|
-
abortSignal,
|
|
531
|
-
writeOutput: text => {
|
|
532
|
-
if (text.trim()) {
|
|
533
|
-
this.events.append({ role: 'system', content: text });
|
|
534
|
-
}
|
|
535
|
-
},
|
|
536
|
-
writeLine: text => {
|
|
537
|
-
if (text?.trim()) {
|
|
538
|
-
this.events.append({ role: 'system', content: text });
|
|
539
|
-
}
|
|
540
|
-
},
|
|
541
|
-
clearView: () => {
|
|
542
|
-
if (this.events.clearView) {
|
|
543
|
-
this.events.clearView();
|
|
544
|
-
}
|
|
545
|
-
else {
|
|
546
|
-
this.events.clearTranscript();
|
|
547
|
-
}
|
|
548
|
-
},
|
|
549
|
-
requestShutdown: reason => {
|
|
550
|
-
this.events.shutdownRequested?.(reason);
|
|
551
|
-
},
|
|
552
|
-
uiRenderer: this.controllerOptions.uiRenderer ?? this.runtime.config.ui?.renderer ?? 'terminal',
|
|
553
|
-
uiCapabilities: (0, ui_events_1.resolveUiRendererCapabilities)(this.controllerOptions.uiCapabilities, this.controllerOptions.uiRenderer ?? this.runtime.config.ui?.renderer),
|
|
554
|
-
agentModeLifecycle: this.controllerOptions.agentModeLifecycle,
|
|
555
|
-
};
|
|
556
|
-
}
|
|
557
|
-
/**
|
|
558
|
-
* Forward a subagent lifecycle event to the runtime event sink and session
|
|
559
|
-
* trace. Renderers consume the same event across terminal/Ink/TUI; this is
|
|
560
|
-
* the only place a subtask event touches the root loop.
|
|
561
|
-
*/
|
|
562
|
-
handleSubtaskEvent(event, sessionId, turnId) {
|
|
563
|
-
// Emit the renderer-independent runtime event first so all renderers
|
|
564
|
-
// (terminal/Ink/TUI) consume the same lifecycle through one protocol.
|
|
565
|
-
this.events.subtaskEvent?.(event);
|
|
566
|
-
const stateToTraceType = {
|
|
567
|
-
queued: 'subtask_requested',
|
|
568
|
-
running: 'subtask_started',
|
|
569
|
-
completed: 'subtask_completed',
|
|
570
|
-
failed: 'subtask_failed',
|
|
571
|
-
cancelled: 'subtask_cancelled',
|
|
572
|
-
rejected: 'subtask_rejected',
|
|
573
|
-
timed_out: 'subtask_timed_out',
|
|
574
|
-
};
|
|
575
|
-
if (sessionId) {
|
|
576
|
-
const traceType = stateToTraceType[event.state];
|
|
577
|
-
if (traceType) {
|
|
578
|
-
(0, chat_trace_1.recordTraceEvent)(this.events, sessionId, {
|
|
579
|
-
turnId: String(turnId),
|
|
580
|
-
type: traceType,
|
|
581
|
-
name: `${event.role}:${event.taskId}`,
|
|
582
|
-
argsSummary: event.objective.slice(0, 160),
|
|
583
|
-
});
|
|
584
|
-
}
|
|
585
|
-
}
|
|
586
|
-
// Surface start/complete/fail/cancel summaries in the transcript so all
|
|
587
|
-
// renderers show subtask progress without renderer-local logic.
|
|
588
|
-
if (event.state === 'running') {
|
|
589
|
-
this.events.append({
|
|
590
|
-
role: 'system',
|
|
591
|
-
content: `▸ subtask ${event.role} started: ${event.objective.slice(0, 120)}`,
|
|
592
|
-
});
|
|
593
|
-
}
|
|
594
|
-
else if (event.state === 'completed' ||
|
|
595
|
-
event.state === 'failed' ||
|
|
596
|
-
event.state === 'cancelled' ||
|
|
597
|
-
event.state === 'timed_out' ||
|
|
598
|
-
event.state === 'rejected') {
|
|
599
|
-
const summary = event.summary ? ` — ${event.summary.slice(0, 200)}` : '';
|
|
600
|
-
this.events.append({
|
|
601
|
-
role: 'system',
|
|
602
|
-
content: `◂ subtask ${event.role} ${event.state}${summary}`,
|
|
603
|
-
});
|
|
604
|
-
}
|
|
605
|
-
}
|
|
606
|
-
/**
|
|
607
|
-
* Fold reconciled child aggregate usage into the root turn's loop stats so
|
|
608
|
-
* `/cost` and loop-budget accounting reflect subagent cost. Child model
|
|
609
|
-
* requests and tool calls are added to the root counters; a note records the
|
|
610
|
-
* subagent contribution so it is distinguishable from root work.
|
|
611
|
-
*/
|
|
612
|
-
foldSubagentUsage(stats, bundle) {
|
|
613
|
-
if (!bundle)
|
|
614
|
-
return stats;
|
|
615
|
-
const usage = bundle.getAggregateUsage();
|
|
616
|
-
if (usage.modelRequests === 0 && usage.toolCalls === 0 && usage.usageComplete === true)
|
|
617
|
-
return stats;
|
|
618
|
-
const subtaskCount = bundle.getSubtaskCount();
|
|
619
|
-
const subagentSuffix = `subagents: ${usage.modelRequests} req/${usage.toolCalls} calls across ${subtaskCount} task(s)`;
|
|
620
|
-
return {
|
|
621
|
-
...stats,
|
|
622
|
-
llmRequests: (stats.llmRequests ?? 0) + usage.modelRequests,
|
|
623
|
-
toolCalls: (stats.toolCalls ?? 0) + usage.toolCalls,
|
|
624
|
-
readOnlyToolCalls: (stats.readOnlyToolCalls ?? 0) + usage.toolCalls,
|
|
625
|
-
subagentPromptTokens: usage.promptTokens,
|
|
626
|
-
subagentCompletionTokens: usage.completionTokens,
|
|
627
|
-
subagentTotalTokens: usage.promptTokens + usage.completionTokens,
|
|
628
|
-
usageAccountingComplete: stats.usageAccountingComplete !== false &&
|
|
629
|
-
usage.usageComplete === true,
|
|
630
|
-
continuationHint: stats.continuationHint
|
|
631
|
-
? `${stats.continuationHint} (${subagentSuffix})`
|
|
632
|
-
: subagentSuffix,
|
|
633
|
-
};
|
|
634
|
-
}
|
|
635
|
-
async runChat(input, options = {}) {
|
|
636
|
-
if (!input) {
|
|
637
|
-
this.events.append({
|
|
638
|
-
role: 'error',
|
|
639
|
-
content: 'Usage: /chat <message>',
|
|
640
|
-
errorLayer: 'runtime',
|
|
641
|
-
});
|
|
642
|
-
return;
|
|
643
|
-
}
|
|
644
|
-
if (!this.runtime.llm || !(0, config_1.isConfigured)(this.runtime.config)) {
|
|
645
|
-
this.events.append({
|
|
646
|
-
role: 'error',
|
|
647
|
-
content: 'LLM is not configured. Set ORION_CODE_API_KEY in ~/.orion-code/orion.json or environment.',
|
|
648
|
-
errorLayer: 'provider',
|
|
649
|
-
});
|
|
650
|
-
return;
|
|
651
|
-
}
|
|
652
|
-
// Usage belongs to a single root turn. Clear the previous snapshot before
|
|
653
|
-
// any provider request so failures without usage cannot inherit stale data.
|
|
654
|
-
this.runtime.store.setState({ tokenUsage: null });
|
|
655
|
-
const abortSignal = options.abortSignal;
|
|
656
|
-
const turnId = (0, chat_trace_1.traceTurnId)(options.turnId);
|
|
657
|
-
const activeSession = this.runtime.getSession() ??
|
|
658
|
-
this.runtime.ensureSession() ??
|
|
659
|
-
(0, session_storage_1.loadSessionMeta)(this.runtime.getSession()?.id ?? '');
|
|
660
|
-
const sessionId = activeSession?.id;
|
|
661
|
-
(0, observability_1.setDiagnosticTraceContext)({
|
|
662
|
-
traceId: `${sessionId ?? 'unsaved'}:${turnId}`,
|
|
663
|
-
...(sessionId ? { sessionId } : {}),
|
|
664
|
-
turnId,
|
|
665
|
-
});
|
|
666
|
-
const preWorkspace = (0, workspace_state_1.captureWorkspaceSnapshot)(this.runtime.cwd);
|
|
667
|
-
const runtimeTools = (0, tools_1.getRuntimeTools)();
|
|
668
|
-
const skillResolution = (0, skills_1.resolveSkillsForTurn)({
|
|
669
|
-
cwd: this.runtime.cwd,
|
|
670
|
-
input,
|
|
671
|
-
tools: runtimeTools,
|
|
672
|
-
projectPath: activeSession?.projectPath,
|
|
673
|
-
sessionId,
|
|
674
|
-
});
|
|
675
|
-
const appliedSkillNames = skillResolution.skills.map(skill => skill.name);
|
|
676
|
-
if (sessionId && options.persistAsUserMessage !== false) {
|
|
677
|
-
(0, session_storage_1.appendSessionMessage)(sessionId, {
|
|
678
|
-
role: 'user',
|
|
679
|
-
content: input,
|
|
680
|
-
timestamp: Date.now(),
|
|
681
|
-
appliedSkills: appliedSkillNames.length > 0 ? appliedSkillNames : undefined,
|
|
682
|
-
});
|
|
683
|
-
(0, chat_trace_1.recordTraceEvent)(this.events, sessionId, {
|
|
684
|
-
turnId,
|
|
685
|
-
type: 'turn_start',
|
|
686
|
-
inputBytes: (0, chat_trace_1.byteLength)(input),
|
|
687
|
-
note: appliedSkillNames.length > 0 ? `skills=${appliedSkillNames.join(',')}` : undefined,
|
|
688
|
-
});
|
|
689
|
-
(0, chat_workspace_1.appendWorkspaceSnapshotTrace)(this.events, sessionId, turnId, 'pre_turn', preWorkspace);
|
|
690
|
-
}
|
|
691
|
-
if (options.persistAsUserMessage !== false) {
|
|
692
|
-
this.runtime.store.addMessage({ role: 'user', content: input });
|
|
693
|
-
}
|
|
694
|
-
(0, prompt_context_2.refreshProjectInstructions)(this.runtime.store, this.runtime.cwd);
|
|
695
|
-
const snapshot = this.runtime.store.getSnapshot();
|
|
696
|
-
const effectivePermissionMode = this.runtime.store.getEffectivePermissionMode();
|
|
697
|
-
const onPlanModeChange = (0, agent_mode_1.createPlanModeChangeHandler)(this.runtime.store, this.controllerOptions.agentModeLifecycle);
|
|
698
|
-
const harness = (0, harness_1.createContextHarness)({
|
|
699
|
-
cwd: this.runtime.cwd,
|
|
700
|
-
modelId: this.runtime.llm.getModel(),
|
|
701
|
-
state: snapshot.harnessState,
|
|
702
|
-
config: {
|
|
703
|
-
enabled: true,
|
|
704
|
-
driftGuard: 'warn',
|
|
705
|
-
completionGate: true,
|
|
706
|
-
},
|
|
707
|
-
});
|
|
708
|
-
const intent = harness.updateContractFromUserInput(options.inputKind === 'goal_continuation'
|
|
709
|
-
? (this.goalCoordinator?.goal?.objective ?? input)
|
|
710
|
-
: input);
|
|
711
|
-
harness.recordAppliedSkills(skillResolution.skills);
|
|
712
|
-
// Reconcile diagnostic: when harness state is present but objective may be incomplete
|
|
713
|
-
if (snapshot.harnessState &&
|
|
714
|
-
!snapshot.harnessState.rootObjective &&
|
|
715
|
-
!snapshot.harnessState.contract?.objective) {
|
|
716
|
-
this.events.setStatus('Resume diagnostic: harness state restored but objective may be incomplete. Run /harness explain to review.');
|
|
717
|
-
}
|
|
718
|
-
const subagentConfig = this.runtime.config.subagents;
|
|
719
|
-
// The subtask capability is a root-level tool. It is exposed on normal
|
|
720
|
-
// turns, but respects an active skill scope: when a skill restricts the
|
|
721
|
-
// tool set, subtask is not appended (the skill owns the scope).
|
|
722
|
-
const projectPath = activeSession?.projectPath;
|
|
723
|
-
const subagentBundle = subagentConfig &&
|
|
724
|
-
subagentConfig.mode !== 'off' &&
|
|
725
|
-
this.runtime.llm &&
|
|
726
|
-
!skillResolution.toolScopeActive
|
|
727
|
-
? (0, subagents_1.createSubagentBundleForTurn)({
|
|
728
|
-
config: subagentConfig,
|
|
729
|
-
cwd: this.runtime.cwd,
|
|
730
|
-
rootLlmConfig: (0, subagents_1.deriveRootLlmConfig)(this.runtime.config),
|
|
731
|
-
modelLabel: this.runtime.llm.getModel(),
|
|
732
|
-
rootObjectiveSummary: harness.toJSON()?.rootObjective ?? input,
|
|
733
|
-
abortSignal,
|
|
734
|
-
resilience: this.runtime.llm.resilience,
|
|
735
|
-
onSubtaskEvent: event => {
|
|
736
|
-
this.handleSubtaskEvent(event, sessionId, turnId);
|
|
737
|
-
},
|
|
738
|
-
onSubtaskResult: (result, _batchId, objective, researchContext) => {
|
|
739
|
-
if (!projectPath)
|
|
740
|
-
return;
|
|
741
|
-
const json = JSON.stringify(result);
|
|
742
|
-
const artifact = (0, tool_artifacts_1.storeArtifact)(projectPath, `subtask_${result.role}`, json, Buffer.byteLength(json, 'utf8'));
|
|
743
|
-
if (artifact) {
|
|
744
|
-
// Record a trace event for artifact discoverability only.
|
|
745
|
-
// The subtask state transition (subtask_completed) is already
|
|
746
|
-
// emitted by handleSubtaskEvent above.
|
|
747
|
-
if (sessionId) {
|
|
748
|
-
(0, chat_trace_1.recordTraceEvent)(this.events, sessionId, {
|
|
749
|
-
turnId: String(turnId),
|
|
750
|
-
type: 'subtask_artifact_stored',
|
|
751
|
-
name: `${result.role}:${result.id}`,
|
|
752
|
-
argsSummary: result.summary.slice(0, 200),
|
|
753
|
-
argsArtifactId: artifact.id,
|
|
754
|
-
argsBytes: artifact.outputBytes,
|
|
755
|
-
});
|
|
756
|
-
}
|
|
757
|
-
}
|
|
758
|
-
// v0.1.4 Research-to-Evidence integration: normalize every
|
|
759
|
-
// terminal research result (including partial/failure states),
|
|
760
|
-
// persist it under a packet-specific CAS scope, and forward the
|
|
761
|
-
// canonical lifecycle stream to every renderer.
|
|
762
|
-
if (result.role !== 'research' || !sessionId)
|
|
763
|
-
return;
|
|
764
|
-
try {
|
|
765
|
-
const goal = this.goalCoordinator?.goal;
|
|
766
|
-
const objectiveRevision = goal?.contract?.objectiveRevision;
|
|
767
|
-
const hasGoalBinding = typeof goal?.goalId === 'string' && typeof objectiveRevision === 'number';
|
|
768
|
-
// Preserve the authoritative request produced from the
|
|
769
|
-
// original subtask capability. Reconstruct local-only only for
|
|
770
|
-
// legacy callers that predate the additive callback context.
|
|
771
|
-
const baseRequest = researchContext?.request ??
|
|
772
|
-
(0, subagents_1.createLocalResearchRequest)(objective?.trim() || result.summary || 'repository research', projectPath);
|
|
773
|
-
const request = {
|
|
774
|
-
...baseRequest,
|
|
775
|
-
scope: { ...baseRequest.scope, projectRoot: projectPath },
|
|
776
|
-
...(hasGoalBinding
|
|
777
|
-
? {
|
|
778
|
-
goalBinding: {
|
|
779
|
-
goalId: goal.goalId,
|
|
780
|
-
objectiveRevision,
|
|
781
|
-
},
|
|
782
|
-
}
|
|
783
|
-
: {}),
|
|
784
|
-
};
|
|
785
|
-
const packet = (0, subagents_1.subtaskResultToPacket)(result, request, {
|
|
786
|
-
projectPath,
|
|
787
|
-
sessionId,
|
|
788
|
-
...(hasGoalBinding ? { goalId: goal.goalId, objectiveRevision } : {}),
|
|
789
|
-
}, {
|
|
790
|
-
externalSources: researchContext?.web?.sources,
|
|
791
|
-
externalNotes: researchContext?.web?.notes,
|
|
792
|
-
externalTimedOut: researchContext?.web?.timedOut,
|
|
793
|
-
externalAborted: researchContext?.web?.aborted,
|
|
794
|
-
});
|
|
795
|
-
// Citation resolution can downgrade claims and mark superseded
|
|
796
|
-
// same-URL sources stale. Resolve before validation/persistence so
|
|
797
|
-
// the CAS token, durable packet and renderer view describe the
|
|
798
|
-
// exact same final state (#105).
|
|
799
|
-
const resolution = (0, subagents_1.resolveCitations)(packet);
|
|
800
|
-
const validation = (0, subagents_1.validatePacket)(packet);
|
|
801
|
-
if (!validation.ok)
|
|
802
|
-
return;
|
|
803
|
-
const saved = (0, subagents_1.saveResearchPacket)((0, subagents_1.createFileArtifactStore)(projectPath), packet, {
|
|
804
|
-
projectPath,
|
|
805
|
-
sessionId,
|
|
806
|
-
packetId: packet.packetId,
|
|
807
|
-
...(packet.goalId ? { goalId: packet.goalId } : {}),
|
|
808
|
-
});
|
|
809
|
-
const view = (0, subagents_1.buildResearchView)(packet, resolution);
|
|
810
|
-
for (const event of (0, subagents_1.toLifecycleEvents)(view, resolution)) {
|
|
811
|
-
this.events.researchEvent?.(event);
|
|
812
|
-
}
|
|
813
|
-
(0, chat_trace_1.recordTraceEvent)(this.events, sessionId, {
|
|
814
|
-
turnId: String(turnId),
|
|
815
|
-
type: 'subtask_artifact_stored',
|
|
816
|
-
name: `research:${packet.packetId}`,
|
|
817
|
-
argsSummary: `${view.stage}/${view.auditStatus}: ${packet.summary}`.slice(0, 200),
|
|
818
|
-
argsArtifactId: `research-${saved.casToken.slice(0, 16)}`,
|
|
819
|
-
argsBytes: Buffer.byteLength(JSON.stringify(packet), 'utf8'),
|
|
820
|
-
});
|
|
821
|
-
}
|
|
822
|
-
catch {
|
|
823
|
-
// Research persistence/rendering is observational. A storage
|
|
824
|
-
// failure must not alter the child result or root turn state.
|
|
825
|
-
}
|
|
826
|
-
},
|
|
827
|
-
// R6: wire live permission state so the subagent policy gate can
|
|
828
|
-
// prevent background delegation while the user is deciding a tool
|
|
829
|
-
// permission. Injected by AgentRuntimeController via chatOptions.
|
|
830
|
-
hasPendingPermission: this.controllerOptions.hasPendingPermission,
|
|
831
|
-
// R6: wire child usage callback so CostTracker records subagent
|
|
832
|
-
// token consumption. Injected by AgentRuntimeController via chatOptions.
|
|
833
|
-
onChildUsage: this.controllerOptions.onChildUsage,
|
|
834
|
-
beforeProviderRequest: this.controllerOptions.beforeProviderRequest,
|
|
835
|
-
})
|
|
836
|
-
: null;
|
|
837
|
-
const subtaskTool = subagentBundle?.tool ?? null;
|
|
838
|
-
const turnTools = subtaskTool ? [...skillResolution.tools, subtaskTool] : skillResolution.tools;
|
|
839
|
-
const memoryPrompt = (0, prompt_context_1.buildMemoryPromptContext)(input, this.runtime.cwd);
|
|
840
|
-
if (sessionId) {
|
|
841
|
-
const selected = memoryPrompt.manifest.selected.map(item => `memory:${item.name}`);
|
|
842
|
-
const omitted = memoryPrompt.manifest.omitted.map(item => `memory:${item.name}`);
|
|
843
|
-
(0, chat_trace_1.recordTraceEvent)(this.events, sessionId, {
|
|
844
|
-
turnId: String(turnId),
|
|
845
|
-
type: 'message',
|
|
846
|
-
name: 'memory_context',
|
|
847
|
-
argsSummary: JSON.stringify({
|
|
848
|
-
budgetChars: memoryPrompt.manifest.budgetChars,
|
|
849
|
-
usedChars: memoryPrompt.manifest.usedChars,
|
|
850
|
-
candidateCount: memoryPrompt.manifest.candidateCount,
|
|
851
|
-
entrypointTruncated: memoryPrompt.manifest.entrypoint.truncated,
|
|
852
|
-
selected: selected.slice(0, 10),
|
|
853
|
-
omitted: omitted.slice(0, 10),
|
|
854
|
-
}),
|
|
855
|
-
contentBytes: Buffer.byteLength(memoryPrompt.content, 'utf8'),
|
|
856
|
-
});
|
|
857
|
-
}
|
|
858
|
-
const promptCtx = {
|
|
859
|
-
cwd: this.runtime.cwd,
|
|
860
|
-
platform: process.platform,
|
|
861
|
-
nodeVersion: process.version,
|
|
862
|
-
tools: turnTools,
|
|
863
|
-
memoryContent: memoryPrompt.content,
|
|
864
|
-
skillsContent: snapshot.skillsContent,
|
|
865
|
-
projectInstructionsContent: snapshot.projectInstructionsContent,
|
|
866
|
-
activeSkillsContent: skillResolution.promptInjection,
|
|
867
|
-
referencedFilesContent: (0, file_context_1.buildReferencedFilesPrompt)(input, this.runtime.cwd),
|
|
868
|
-
planMode: snapshot.planMode || snapshot.agentMode === 'plan',
|
|
869
|
-
agentMode: snapshot.agentMode,
|
|
870
|
-
goalContent: this.goalCoordinator?.goal?.status === 'active'
|
|
871
|
-
? (0, prompt_1.buildGoalContextFragment)(this.goalCoordinator.goal)?.text
|
|
872
|
-
: undefined,
|
|
873
|
-
};
|
|
874
|
-
const systemPrompt = (0, framework_1.buildSystemPrompt)(promptCtx);
|
|
875
|
-
const messages = [
|
|
876
|
-
{ role: 'system', content: systemPrompt.static, cacheControl: { type: 'ephemeral' } },
|
|
877
|
-
...(systemPrompt.dynamic ? [{ role: 'system', content: systemPrompt.dynamic }] : []),
|
|
878
|
-
...snapshot.conversationHistory,
|
|
879
|
-
...(options.persistAsUserMessage === false
|
|
880
|
-
? [{ role: 'user', content: input }]
|
|
881
|
-
: []),
|
|
882
|
-
];
|
|
883
|
-
let finalContent = '';
|
|
884
|
-
let finalUsage;
|
|
885
|
-
let finalModel = '';
|
|
886
|
-
let pendingCompleteTrace = null;
|
|
887
|
-
let pendingCompleteStats;
|
|
888
|
-
let pendingCompact;
|
|
889
|
-
const verificationResults = [];
|
|
890
|
-
const sessionMessagesToRecord = [];
|
|
891
|
-
const assistantStream = (0, chat_presentation_1.createAssistantStreamPresenter)(this.events, abortSignal);
|
|
892
|
-
const toolEvents = (0, chat_presentation_1.createToolEventPresenter)(this.events, {
|
|
893
|
-
projectPath: this.runtime.cwd,
|
|
894
|
-
turnId,
|
|
895
|
-
});
|
|
896
|
-
let checkpointSequence = 0;
|
|
897
|
-
const checkpointIds = [];
|
|
898
|
-
const streamCallbacks = {
|
|
899
|
-
onChunk: chunk => {
|
|
900
|
-
assistantStream.appendChunk(chunk);
|
|
901
|
-
},
|
|
902
|
-
};
|
|
903
|
-
const toolExecutor = async (name, args, signal) => {
|
|
904
|
-
// The runtime-bound `subtask` tool is not in the global TOOLS registry;
|
|
905
|
-
// dispatch it directly so it reaches the Supervisor closure.
|
|
906
|
-
if (name === 'subtask' && subtaskTool) {
|
|
907
|
-
const result = await subtaskTool.execute(args, {
|
|
908
|
-
cwd: this.runtime.cwd,
|
|
909
|
-
config: { name: this.runtime.config.name, mode: this.runtime.config.mode },
|
|
910
|
-
abortSignal: signal,
|
|
911
|
-
sessionId,
|
|
912
|
-
turnId,
|
|
913
|
-
});
|
|
914
|
-
return JSON.stringify(result);
|
|
915
|
-
}
|
|
916
|
-
if (!turnTools.some(tool => tool.name === name)) {
|
|
917
|
-
return JSON.stringify({
|
|
918
|
-
success: false,
|
|
919
|
-
error: skillResolution.toolScopeActive
|
|
920
|
-
? `Tool ${name} is not available for the active skill scope. Available tools: ${skillResolution.tools.map(tool => tool.name).join(', ') || 'none'}`
|
|
921
|
-
: `Tool ${name} is not available.`,
|
|
922
|
-
});
|
|
923
|
-
}
|
|
924
|
-
return (0, tools_1.executeTool)(name, args, signal, {
|
|
925
|
-
cwd: this.runtime.cwd,
|
|
926
|
-
config: {
|
|
927
|
-
name: this.runtime.config.name,
|
|
928
|
-
mode: this.runtime.config.mode,
|
|
929
|
-
},
|
|
930
|
-
sessionId,
|
|
931
|
-
turnId,
|
|
932
|
-
// Tools that fan out to other tools (batch_read) have to re-run the
|
|
933
|
-
// permission gate per sub-step; they need the mode and the allowlist.
|
|
934
|
-
permissionMode: effectivePermissionMode,
|
|
935
|
-
toolAllowlist: this.resolveToolAllowlist(),
|
|
936
|
-
toolConfirmation: this.runtime.config.toolConfirmation,
|
|
937
|
-
confirmToolUse: effectivePermissionMode === 'auto' ? undefined : this.controllerOptions.confirmToolUse,
|
|
938
|
-
onPlanModeChange,
|
|
939
|
-
});
|
|
940
|
-
};
|
|
941
|
-
const loopBudget = options.inputKind === 'goal_continuation'
|
|
942
|
-
? (0, loop_budget_1.resolveAutonomousGoalLoopBudget)(this.runtime.config)
|
|
943
|
-
: (0, loop_budget_1.resolveRuntimeLoopBudget)(input, this.runtime.config, harness.toJSON());
|
|
944
|
-
let observedTurnsStarted = 0;
|
|
945
|
-
let observedLlmRequests = 0;
|
|
946
|
-
let observedToolCalls = 0;
|
|
947
|
-
let observedReadOnlyToolCalls = 0;
|
|
948
|
-
let observedUnsafeToolCalls = 0;
|
|
949
|
-
let observedToolResultBytes = 0;
|
|
950
|
-
let observedModelVisibleToolBytes = 0;
|
|
951
|
-
const restoreProviderPreflight = typeof this.runtime.llm.setProviderRequestPreflight === 'function'
|
|
952
|
-
? this.runtime.llm.setProviderRequestPreflight(this.controllerOptions.beforeProviderRequest)
|
|
953
|
-
: undefined;
|
|
954
|
-
const persistInterruptedAccounting = (rootUsage, stats, usageAccountingComplete) => {
|
|
955
|
-
const accountingStats = {
|
|
956
|
-
...stats,
|
|
957
|
-
finishReason: 'cancelled',
|
|
958
|
-
usageAccountingComplete,
|
|
959
|
-
};
|
|
960
|
-
const interruptedStats = this.foldSubagentUsage(accountingStats, subagentBundle);
|
|
961
|
-
this.setLoopStats(interruptedStats);
|
|
962
|
-
const subagentUsage = subagentBundle?.getAggregateUsage();
|
|
963
|
-
const knownZeroRootUsage = usageAccountingComplete && interruptedStats.llmRequests === 0;
|
|
964
|
-
if (rootUsage || knownZeroRootUsage) {
|
|
965
|
-
this.runtime.store.setTokenUsage({
|
|
966
|
-
promptTokens: (rootUsage?.promptTokens ?? 0) + (subagentUsage?.promptTokens ?? 0),
|
|
967
|
-
completionTokens: (rootUsage?.completionTokens ?? 0) + (subagentUsage?.completionTokens ?? 0),
|
|
968
|
-
});
|
|
969
|
-
}
|
|
970
|
-
};
|
|
971
|
-
try {
|
|
972
|
-
for await (const event of (0, framework_1.query)({
|
|
973
|
-
messages,
|
|
974
|
-
tools: turnTools,
|
|
975
|
-
toolExecutor,
|
|
976
|
-
llm: this.runtime.llm,
|
|
977
|
-
streamCallbacks,
|
|
978
|
-
costTracker: snapshot.costTracker,
|
|
979
|
-
permissionMode: effectivePermissionMode,
|
|
980
|
-
toolConfirmation: this.runtime.config.toolConfirmation,
|
|
981
|
-
toolAllowlist: this.resolveToolAllowlist(),
|
|
982
|
-
confirmToolUse: effectivePermissionMode === 'auto' ? undefined : this.controllerOptions.confirmToolUse,
|
|
983
|
-
toolContext: {
|
|
984
|
-
cwd: this.runtime.cwd,
|
|
985
|
-
config: {
|
|
986
|
-
name: this.runtime.config.name,
|
|
987
|
-
mode: this.runtime.config.mode,
|
|
988
|
-
},
|
|
989
|
-
sessionId,
|
|
990
|
-
turnId,
|
|
991
|
-
permissionMode: effectivePermissionMode,
|
|
992
|
-
toolAllowlist: this.resolveToolAllowlist(),
|
|
993
|
-
toolConfirmation: this.runtime.config.toolConfirmation,
|
|
994
|
-
confirmToolUse: effectivePermissionMode === 'auto' ? undefined : this.controllerOptions.confirmToolUse,
|
|
995
|
-
onPlanModeChange,
|
|
996
|
-
},
|
|
997
|
-
abortSignal,
|
|
998
|
-
harness,
|
|
999
|
-
input,
|
|
1000
|
-
loopBudget,
|
|
1001
|
-
onContextUsage: usage => {
|
|
1002
|
-
this.runtime.store.setContextUsage(usage);
|
|
1003
|
-
},
|
|
1004
|
-
compactCoordinator: this.runtime.compactCoordinator,
|
|
1005
|
-
onCompactPrepare: sessionId
|
|
1006
|
-
? () => (0, session_storage_1.prepareSessionCompactSourceReceipt)(sessionId)
|
|
1007
|
-
: undefined,
|
|
1008
|
-
})) {
|
|
1009
|
-
switch (event.type) {
|
|
1010
|
-
case 'request_start':
|
|
1011
|
-
observedTurnsStarted = Math.max(observedTurnsStarted, event.turn);
|
|
1012
|
-
observedLlmRequests++;
|
|
1013
|
-
assistantStream.discardSegment();
|
|
1014
|
-
this.events.setStatus((0, agent_status_1.agentStepStatus)(event.turn));
|
|
1015
|
-
if (sessionId) {
|
|
1016
|
-
(0, chat_trace_1.recordTraceEvent)(this.events, sessionId, {
|
|
1017
|
-
turnId,
|
|
1018
|
-
type: 'request_start',
|
|
1019
|
-
model: event.model,
|
|
1020
|
-
turn: event.turn,
|
|
1021
|
-
});
|
|
1022
|
-
}
|
|
1023
|
-
break;
|
|
1024
|
-
case 'prompt_assembly':
|
|
1025
|
-
if (sessionId) {
|
|
1026
|
-
(0, chat_trace_1.recordTraceEvent)(this.events, sessionId, {
|
|
1027
|
-
turnId,
|
|
1028
|
-
type: 'prompt_assembly',
|
|
1029
|
-
promptModelId: event.modelId,
|
|
1030
|
-
promptEstimatedTokens: event.estimatedTokens,
|
|
1031
|
-
promptBudgetTokens: event.budgetTokens,
|
|
1032
|
-
promptCoreTokens: event.coreTokens,
|
|
1033
|
-
promptEvidenceBudgetTokens: event.evidenceBudgetTokens,
|
|
1034
|
-
promptRecentTurnBudgetTokens: event.recentTurnBudgetTokens,
|
|
1035
|
-
promptSections: event.sections,
|
|
1036
|
-
promptIncludedEvidence: event.includedEvidence,
|
|
1037
|
-
promptOmittedEvidence: event.omittedEvidence,
|
|
1038
|
-
promptIncludedEvidenceCount: event.includedEvidenceCount,
|
|
1039
|
-
promptOmittedEvidenceCount: event.omittedEvidenceCount,
|
|
1040
|
-
promptSectionManifest: event.sectionManifest,
|
|
1041
|
-
promptOverBudget: event.overBudget,
|
|
1042
|
-
promptCapabilityProfileVersion: event.capabilityProfileVersion,
|
|
1043
|
-
promptCapabilityProfileFingerprint: event.capabilityProfileFingerprint,
|
|
1044
|
-
});
|
|
1045
|
-
}
|
|
1046
|
-
break;
|
|
1047
|
-
case 'assistant_tool_calls':
|
|
1048
|
-
assistantStream.ensureMessage(event.content || '');
|
|
1049
|
-
assistantStream.closeSegment();
|
|
1050
|
-
this.events.setStatus((0, agent_status_1.runningToolsStatus)(event.toolCalls.length));
|
|
1051
|
-
{
|
|
1052
|
-
const batchReadOnlyCount = event.toolCalls.filter(tc => {
|
|
1053
|
-
const def = skillResolution.tools.find(t => t.name === tc.function.name);
|
|
1054
|
-
const args = (0, chat_checkpoint_1.parseToolCallArgsForRuntime)(tc);
|
|
1055
|
-
return args && def?.isReadOnly?.(args) === true;
|
|
1056
|
-
}).length;
|
|
1057
|
-
const suggestion = (0, agent_status_1.batchingSuggestion)(batchReadOnlyCount);
|
|
1058
|
-
if (suggestion) {
|
|
1059
|
-
this.events.append({ role: 'status', content: suggestion });
|
|
1060
|
-
}
|
|
1061
|
-
}
|
|
1062
|
-
const checkpointId = `${turnId}-${checkpointSequence + 1}-${(0, crypto_1.randomUUID)()}`;
|
|
1063
|
-
const checkpointResult = (0, chat_checkpoint_1.createPreToolCheckpoint)(this.events, sessionId, turnId, checkpointId, this.runtime.cwd, event.toolCalls);
|
|
1064
|
-
if (checkpointResult.created) {
|
|
1065
|
-
checkpointIds.push(checkpointId);
|
|
1066
|
-
checkpointSequence++;
|
|
1067
|
-
}
|
|
1068
|
-
if (checkpointResult.created && checkpointResult.risky) {
|
|
1069
|
-
this.events.append({
|
|
1070
|
-
role: 'status',
|
|
1071
|
-
title: 'checkpoint',
|
|
1072
|
-
statusTone: 'warning',
|
|
1073
|
-
content: `Risky edit: ${checkpointResult.targetCount} files in one turn. Checkpoint ${checkpointId} created for rollback (/checkpoints restore ${checkpointId}).`,
|
|
1074
|
-
});
|
|
1075
|
-
}
|
|
1076
|
-
else if (checkpointResult.risky) {
|
|
1077
|
-
this.events.append({
|
|
1078
|
-
role: 'status',
|
|
1079
|
-
title: 'checkpoint',
|
|
1080
|
-
statusTone: 'warning',
|
|
1081
|
-
content: `Risky edit: ${checkpointResult.targetCount} files in one turn, but checkpoint creation failed. Restore any pre-existing checkpoint manually or revert via git.`,
|
|
1082
|
-
});
|
|
1083
|
-
}
|
|
1084
|
-
if (sessionId) {
|
|
1085
|
-
(0, chat_trace_1.recordTraceEvent)(this.events, sessionId, {
|
|
1086
|
-
turnId,
|
|
1087
|
-
type: 'assistant_tool_calls',
|
|
1088
|
-
toolCallCount: event.toolCalls.length,
|
|
1089
|
-
contentBytes: (0, chat_trace_1.byteLength)(event.content || ''),
|
|
1090
|
-
});
|
|
1091
|
-
}
|
|
1092
|
-
sessionMessagesToRecord.push({
|
|
1093
|
-
role: 'assistant',
|
|
1094
|
-
content: event.content || '',
|
|
1095
|
-
timestamp: Date.now(),
|
|
1096
|
-
tool_calls: event.toolCalls,
|
|
1097
|
-
});
|
|
1098
|
-
break;
|
|
1099
|
-
case 'tool_call':
|
|
1100
|
-
observedToolCalls++;
|
|
1101
|
-
{
|
|
1102
|
-
const toolDefinition = skillResolution.tools.find(tool => tool.name === event.name);
|
|
1103
|
-
if (toolDefinition?.isReadOnly?.(event.args) === true) {
|
|
1104
|
-
observedReadOnlyToolCalls++;
|
|
1105
|
-
}
|
|
1106
|
-
else {
|
|
1107
|
-
observedUnsafeToolCalls++;
|
|
1108
|
-
}
|
|
1109
|
-
}
|
|
1110
|
-
assistantStream.closeSegment();
|
|
1111
|
-
toolEvents.start(event);
|
|
1112
|
-
if (sessionId) {
|
|
1113
|
-
const traceArgs = (0, chat_trace_1.buildTraceArgsDetails)(this.runtime.cwd, event.name, event.args);
|
|
1114
|
-
(0, chat_trace_1.recordTraceEvent)(this.events, sessionId, {
|
|
1115
|
-
turnId,
|
|
1116
|
-
type: 'tool_call',
|
|
1117
|
-
name: event.name,
|
|
1118
|
-
callId: event.callId,
|
|
1119
|
-
...traceArgs,
|
|
1120
|
-
batchCount: event.batchCount,
|
|
1121
|
-
batchIndex: event.batchIndex,
|
|
1122
|
-
});
|
|
1123
|
-
}
|
|
1124
|
-
break;
|
|
1125
|
-
case 'permission_decision':
|
|
1126
|
-
toolEvents.permission(event);
|
|
1127
|
-
if (sessionId) {
|
|
1128
|
-
(0, chat_trace_1.recordTraceEvent)(this.events, sessionId, {
|
|
1129
|
-
turnId,
|
|
1130
|
-
type: 'permission_decision',
|
|
1131
|
-
name: event.name,
|
|
1132
|
-
callId: event.callId,
|
|
1133
|
-
argsSummary: (0, chat_trace_1.compactToolArgs)(event.args),
|
|
1134
|
-
permissionBehavior: event.decision.behavior,
|
|
1135
|
-
permissionApproved: event.decision.approved,
|
|
1136
|
-
permissionSource: event.decision.source,
|
|
1137
|
-
permissionReason: event.decision.reason
|
|
1138
|
-
? (0, chat_trace_1.compactMiddle)(event.decision.reason, 240)
|
|
1139
|
-
: undefined,
|
|
1140
|
-
permissionDuration: event.decision.duration,
|
|
1141
|
-
batchCount: event.batchCount,
|
|
1142
|
-
batchIndex: event.batchIndex,
|
|
1143
|
-
});
|
|
1144
|
-
}
|
|
1145
|
-
break;
|
|
1146
|
-
case 'tool_result': {
|
|
1147
|
-
observedToolResultBytes += event.outputBytes ?? (0, chat_trace_1.byteLength)(event.result);
|
|
1148
|
-
observedModelVisibleToolBytes += (0, chat_trace_1.byteLength)(event.modelVisibleResult);
|
|
1149
|
-
toolEvents.finish(event);
|
|
1150
|
-
if (sessionId) {
|
|
1151
|
-
(0, chat_trace_1.recordTraceEvent)(this.events, sessionId, {
|
|
1152
|
-
turnId,
|
|
1153
|
-
type: 'tool_result',
|
|
1154
|
-
name: event.name,
|
|
1155
|
-
callId: event.callId,
|
|
1156
|
-
argsSummary: (0, chat_trace_1.compactToolArgs)(event.args),
|
|
1157
|
-
success: event.success,
|
|
1158
|
-
duration: event.duration,
|
|
1159
|
-
outputBytes: event.outputBytes,
|
|
1160
|
-
modelVisibleBytes: (0, chat_trace_1.byteLength)(event.modelVisibleResult),
|
|
1161
|
-
artifactId: event.artifactRef?.id,
|
|
1162
|
-
error: event.error ? (0, chat_trace_1.compactMiddle)(event.error, 240) : undefined,
|
|
1163
|
-
batchCount: event.batchCount,
|
|
1164
|
-
batchIndex: event.batchIndex,
|
|
1165
|
-
});
|
|
1166
|
-
}
|
|
1167
|
-
const verificationResult = (0, verification_profile_1.collectVerificationCommandResult)({
|
|
1168
|
-
toolName: event.name,
|
|
1169
|
-
args: event.args,
|
|
1170
|
-
success: event.success,
|
|
1171
|
-
outputBytes: event.outputBytes,
|
|
1172
|
-
error: event.error,
|
|
1173
|
-
});
|
|
1174
|
-
if (verificationResult) {
|
|
1175
|
-
verificationResults.push(verificationResult);
|
|
1176
|
-
(0, chat_workspace_1.appendVerificationResultTrace)(this.events, sessionId, turnId, verificationResult);
|
|
1177
|
-
}
|
|
1178
|
-
sessionMessagesToRecord.push({
|
|
1179
|
-
role: 'tool',
|
|
1180
|
-
content: event.result,
|
|
1181
|
-
modelVisibleContent: event.modelVisibleResult,
|
|
1182
|
-
timestamp: Date.now(),
|
|
1183
|
-
toolCallId: event.callId,
|
|
1184
|
-
});
|
|
1185
|
-
break;
|
|
1186
|
-
}
|
|
1187
|
-
case 'strategy_exhausted':
|
|
1188
|
-
this.events.append({ role: 'status', content: event.suggestion });
|
|
1189
|
-
if (sessionId) {
|
|
1190
|
-
(0, chat_trace_1.recordTraceEvent)(this.events, sessionId, {
|
|
1191
|
-
turnId,
|
|
1192
|
-
type: 'strategy_exhausted',
|
|
1193
|
-
note: (0, chat_trace_1.compactMiddle)(event.suggestion, 240),
|
|
1194
|
-
});
|
|
1195
|
-
}
|
|
1196
|
-
break;
|
|
1197
|
-
case 'warning':
|
|
1198
|
-
this.events.append({
|
|
1199
|
-
role: 'status',
|
|
1200
|
-
statusTone: 'warning',
|
|
1201
|
-
title: 'harness',
|
|
1202
|
-
content: event.message,
|
|
1203
|
-
});
|
|
1204
|
-
break;
|
|
1205
|
-
case 'message':
|
|
1206
|
-
finalContent = event.content;
|
|
1207
|
-
assistantStream.ensureMessage(event.content);
|
|
1208
|
-
if (sessionId) {
|
|
1209
|
-
(0, chat_trace_1.recordTraceEvent)(this.events, sessionId, {
|
|
1210
|
-
turnId,
|
|
1211
|
-
type: 'message',
|
|
1212
|
-
contentBytes: (0, chat_trace_1.byteLength)(event.content),
|
|
1213
|
-
});
|
|
1214
|
-
}
|
|
1215
|
-
if (event.content) {
|
|
1216
|
-
sessionMessagesToRecord.push({
|
|
1217
|
-
role: 'assistant',
|
|
1218
|
-
content: event.content,
|
|
1219
|
-
timestamp: Date.now(),
|
|
1220
|
-
});
|
|
1221
|
-
}
|
|
1222
|
-
break;
|
|
1223
|
-
case 'complete':
|
|
1224
|
-
if (event.stats?.finishReason === 'blocked') {
|
|
1225
|
-
toolEvents.finalizePendingAsSkipped('permission denied');
|
|
1226
|
-
}
|
|
1227
|
-
if (event.content && !finalContent) {
|
|
1228
|
-
if (event.stats?.finishReason === 'budget_exceeded') {
|
|
1229
|
-
assistantStream.replaceMessage(event.content);
|
|
1230
|
-
}
|
|
1231
|
-
else {
|
|
1232
|
-
assistantStream.ensureMessage(event.content);
|
|
1233
|
-
}
|
|
1234
|
-
sessionMessagesToRecord.push({
|
|
1235
|
-
role: 'assistant',
|
|
1236
|
-
content: event.content,
|
|
1237
|
-
timestamp: Date.now(),
|
|
1238
|
-
});
|
|
1239
|
-
}
|
|
1240
|
-
finalContent = event.content;
|
|
1241
|
-
finalUsage = event.usage;
|
|
1242
|
-
finalModel = event.model;
|
|
1243
|
-
pendingCompact = event.compact;
|
|
1244
|
-
if (event.stats) {
|
|
1245
|
-
pendingCompleteStats = event.stats;
|
|
1246
|
-
(0, chat_trace_1.recordProviderTraceEvents)(this.events, sessionId, turnId, event.stats);
|
|
1247
|
-
pendingCompleteTrace = {
|
|
1248
|
-
turnId,
|
|
1249
|
-
type: 'complete',
|
|
1250
|
-
model: event.model,
|
|
1251
|
-
contentBytes: (0, chat_trace_1.byteLength)(event.content || ''),
|
|
1252
|
-
finishReason: event.stats.finishReason,
|
|
1253
|
-
stopDecision: event.stats.stopDecision,
|
|
1254
|
-
llmRequests: event.stats.llmRequests,
|
|
1255
|
-
toolCalls: event.stats.toolCalls,
|
|
1256
|
-
readOnlyToolCalls: event.stats.readOnlyToolCalls,
|
|
1257
|
-
unsafeToolCalls: event.stats.unsafeToolCalls,
|
|
1258
|
-
loopBudgetSource: event.stats.loopBudgetSource,
|
|
1259
|
-
loopBudgetBaseProfile: event.stats.loopBudgetBaseProfile,
|
|
1260
|
-
loopBudgetMaxLlmRequests: event.stats.loopBudgetMaxLlmRequests,
|
|
1261
|
-
loopBudgetMaxToolCalls: event.stats.loopBudgetMaxToolCalls,
|
|
1262
|
-
loopBudgetMaxReadOnlyFragmentation: event.stats.loopBudgetMaxReadOnlyFragmentation,
|
|
1263
|
-
loopBudgetMaxModelVisibleBytes: event.stats.loopBudgetMaxModelVisibleBytes,
|
|
1264
|
-
loopBudgetConfigOverride: event.stats.loopBudgetConfigOverride,
|
|
1265
|
-
budgetExceededReason: event.stats.budgetExceededReason,
|
|
1266
|
-
continuationActions: event.stats.continuationActions,
|
|
1267
|
-
continuationHint: event.stats.continuationHint,
|
|
1268
|
-
lastToolName: event.stats.lastToolName,
|
|
1269
|
-
lastToolSummary: event.stats.lastToolSummary,
|
|
1270
|
-
lastToolSuccess: event.stats.lastToolSuccess,
|
|
1271
|
-
localFastPathUsed: event.stats.localFastPathUsed,
|
|
1272
|
-
};
|
|
1273
|
-
}
|
|
1274
|
-
else {
|
|
1275
|
-
pendingCompleteTrace = {
|
|
1276
|
-
turnId,
|
|
1277
|
-
type: 'complete',
|
|
1278
|
-
model: event.model,
|
|
1279
|
-
contentBytes: (0, chat_trace_1.byteLength)(event.content || ''),
|
|
1280
|
-
};
|
|
1281
|
-
}
|
|
1282
|
-
break;
|
|
1283
|
-
}
|
|
1284
|
-
}
|
|
1285
|
-
const wasAborted = abortSignal?.aborted === true;
|
|
1286
|
-
if (wasAborted) {
|
|
1287
|
-
const stats = pendingCompleteStats ??
|
|
1288
|
-
(0, framework_1.createFailedLoopStats)({
|
|
1289
|
-
loopBudget,
|
|
1290
|
-
diagnostics: observedLlmRequests > 0 ? (0, chat_trace_1.getLastRequestDiagnostics)(this.runtime.llm) : undefined,
|
|
1291
|
-
turnsStarted: observedTurnsStarted,
|
|
1292
|
-
llmRequests: observedLlmRequests,
|
|
1293
|
-
toolCalls: observedToolCalls,
|
|
1294
|
-
readOnlyToolCalls: observedReadOnlyToolCalls,
|
|
1295
|
-
unsafeToolCalls: observedUnsafeToolCalls,
|
|
1296
|
-
toolResultBytes: observedToolResultBytes,
|
|
1297
|
-
modelVisibleToolBytes: observedModelVisibleToolBytes,
|
|
1298
|
-
});
|
|
1299
|
-
persistInterruptedAccounting(finalUsage, stats, finalUsage !== undefined || stats.llmRequests === 0);
|
|
1300
|
-
assistantStream.discardSegment();
|
|
1301
|
-
this.events.setStatus('Interrupted.');
|
|
1302
|
-
(0, chat_presentation_1.removeTrailingUserMessage)(this.runtime);
|
|
1303
|
-
if (sessionId) {
|
|
1304
|
-
const { delta } = (0, chat_workspace_1.appendPostWorkspaceTrace)(this.events, sessionId, turnId, this.runtime.cwd, preWorkspace, verificationResults);
|
|
1305
|
-
(0, chat_trace_1.recordTraceEvent)(this.events, sessionId, {
|
|
1306
|
-
turnId,
|
|
1307
|
-
type: 'aborted',
|
|
1308
|
-
note: 'aborted_after_query',
|
|
1309
|
-
});
|
|
1310
|
-
const recoveryNotice = (0, chat_workspace_1.workspaceDeltaHasTurnChanges)(delta)
|
|
1311
|
-
? (0, chat_workspace_1.formatFailureRecoveryNotice)(turnId, delta, checkpointIds)
|
|
1312
|
-
: undefined;
|
|
1313
|
-
if (recoveryNotice) {
|
|
1314
|
-
this.events.append({
|
|
1315
|
-
role: 'status',
|
|
1316
|
-
title: 'recovery',
|
|
1317
|
-
statusTone: 'warning',
|
|
1318
|
-
content: recoveryNotice,
|
|
1319
|
-
});
|
|
1320
|
-
}
|
|
1321
|
-
(0, session_storage_1.removeLastIncompleteAssistantMessage)(sessionId);
|
|
1322
|
-
}
|
|
1323
|
-
// Persist any accumulated session messages before returning,
|
|
1324
|
-
// so tool results from the interrupted turn are not lost.
|
|
1325
|
-
if (sessionId && sessionMessagesToRecord.length > 0) {
|
|
1326
|
-
(0, session_storage_1.appendSessionMessages)(sessionId, sessionMessagesToRecord);
|
|
1327
|
-
}
|
|
1328
|
-
return;
|
|
1329
|
-
}
|
|
1330
|
-
assistantStream.closeSegment();
|
|
1331
|
-
if (sessionId) {
|
|
1332
|
-
const { profile, summary } = (0, chat_workspace_1.appendPostWorkspaceTrace)(this.events, sessionId, turnId, this.runtime.cwd, preWorkspace, verificationResults);
|
|
1333
|
-
if (profile.changedFiles.length > 0 && profile.required) {
|
|
1334
|
-
this.events.setStatus((0, agent_status_1.verifyingStatus)(profile.profile));
|
|
1335
|
-
this.controllerOptions.onVerificationStateChange?.('running');
|
|
1336
|
-
}
|
|
1337
|
-
if ((0, chat_workspace_1.shouldRecordVerificationLoopStats)(profile, summary)) {
|
|
1338
|
-
const stats = pendingCompleteStats ?? this.runtime.store.getSnapshot().lastLoopStats;
|
|
1339
|
-
if (stats) {
|
|
1340
|
-
pendingCompleteStats = (0, chat_workspace_1.withVerificationLoopStats)(stats, summary);
|
|
1341
|
-
}
|
|
1342
|
-
}
|
|
1343
|
-
if ((0, verification_profile_1.shouldGateCompletion)(summary)) {
|
|
1344
|
-
this.events.setStatus((0, agent_status_1.verificationGateStatus)(summary.skippedReason ?? 'verification checks not run'));
|
|
1345
|
-
this.controllerOptions.onVerificationStateChange?.('gated');
|
|
1346
|
-
const notice = (0, verification_profile_1.formatVerificationGateNotice)(summary);
|
|
1347
|
-
this.events.append({
|
|
1348
|
-
role: 'status',
|
|
1349
|
-
title: 'verification',
|
|
1350
|
-
statusTone: 'warning',
|
|
1351
|
-
content: notice,
|
|
1352
|
-
});
|
|
1353
|
-
finalContent = finalContent ? `${finalContent}\n\n${notice}` : notice;
|
|
1354
|
-
(0, chat_trace_1.appendAssistantNotice)(sessionMessagesToRecord, notice);
|
|
1355
|
-
if (pendingCompleteTrace) {
|
|
1356
|
-
pendingCompleteTrace.finishReason = 'completion_gate';
|
|
1357
|
-
pendingCompleteTrace.contentBytes = (0, chat_trace_1.byteLength)(finalContent);
|
|
1358
|
-
pendingCompleteTrace.note = 'verification_incomplete';
|
|
1359
|
-
}
|
|
1360
|
-
const stats = pendingCompleteStats ?? this.runtime.store.getSnapshot().lastLoopStats;
|
|
1361
|
-
if (stats) {
|
|
1362
|
-
pendingCompleteStats = (0, framework_1.withLoopFinishReason)((0, chat_workspace_1.withVerificationLoopStats)(stats, summary), 'completion_gate');
|
|
1363
|
-
if (pendingCompleteTrace) {
|
|
1364
|
-
pendingCompleteTrace.stopDecision = pendingCompleteStats.stopDecision;
|
|
1365
|
-
}
|
|
1366
|
-
}
|
|
1367
|
-
}
|
|
1368
|
-
else if (profile.changedFiles.length > 0 && profile.required) {
|
|
1369
|
-
this.controllerOptions.onVerificationStateChange?.('passed');
|
|
1370
|
-
}
|
|
1371
|
-
}
|
|
1372
|
-
if (pendingCompleteStats?.finishReason === 'budget_exceeded') {
|
|
1373
|
-
const stats = pendingCompleteStats;
|
|
1374
|
-
const budgetStop = (0, ui_view_model_1.createLoopBudgetStopView)(stats);
|
|
1375
|
-
const notice = (0, ui_view_model_1.formatLoopBudgetStopView)(budgetStop, (0, ui_view_model_1.budgetStopLocaleForInput)(input));
|
|
1376
|
-
this.events.append({
|
|
1377
|
-
role: 'status',
|
|
1378
|
-
title: 'budget',
|
|
1379
|
-
statusTone: 'warning',
|
|
1380
|
-
content: notice,
|
|
1381
|
-
budgetStop,
|
|
1382
|
-
});
|
|
1383
|
-
finalContent = finalContent ? `${finalContent}\n\n${notice}` : notice;
|
|
1384
|
-
(0, chat_trace_1.appendAssistantNotice)(sessionMessagesToRecord, notice);
|
|
1385
|
-
if (pendingCompleteTrace) {
|
|
1386
|
-
pendingCompleteTrace.contentBytes = (0, chat_trace_1.byteLength)(finalContent);
|
|
1387
|
-
}
|
|
1388
|
-
}
|
|
1389
|
-
if (pendingCompleteStats) {
|
|
1390
|
-
this.setLoopStats(this.foldSubagentUsage(pendingCompleteStats, subagentBundle));
|
|
1391
|
-
}
|
|
1392
|
-
if (finalContent) {
|
|
1393
|
-
this.runtime.store.addMessage({ role: 'assistant', content: finalContent });
|
|
1394
|
-
}
|
|
1395
|
-
if (sessionId && sessionMessagesToRecord.length > 0) {
|
|
1396
|
-
(0, session_storage_1.appendSessionMessages)(sessionId, sessionMessagesToRecord);
|
|
1397
|
-
}
|
|
1398
|
-
harness.ingestTurn({
|
|
1399
|
-
userInput: input,
|
|
1400
|
-
assistantContent: finalContent,
|
|
1401
|
-
sessionMessages: sessionMessagesToRecord,
|
|
1402
|
-
intent,
|
|
1403
|
-
});
|
|
1404
|
-
const harnessState = harness.toJSON();
|
|
1405
|
-
this.runtime.store.setState({ harnessState });
|
|
1406
|
-
(0, chat_trace_1.emitHarnessDiagnostics)(this.events, harnessState);
|
|
1407
|
-
if (sessionId) {
|
|
1408
|
-
(0, session_storage_1.updateSessionHarnessState)(sessionId, harnessState);
|
|
1409
|
-
}
|
|
1410
|
-
if (pendingCompact) {
|
|
1411
|
-
(0, chat_compact_1.commitChatCompact)({
|
|
1412
|
-
pendingCompact,
|
|
1413
|
-
sessionId,
|
|
1414
|
-
turnId,
|
|
1415
|
-
modelId: finalModel || this.runtime.llm.getModel(),
|
|
1416
|
-
sessionMessages: sessionMessagesToRecord,
|
|
1417
|
-
harnessState,
|
|
1418
|
-
activeGoal: this.goalCoordinator?.goal,
|
|
1419
|
-
store: this.runtime.store,
|
|
1420
|
-
events: this.events,
|
|
1421
|
-
});
|
|
1422
|
-
}
|
|
1423
|
-
if (finalUsage) {
|
|
1424
|
-
// Fold subagent token usage into /cost accounting.
|
|
1425
|
-
if (subagentBundle) {
|
|
1426
|
-
const subUsage = subagentBundle.getAggregateUsage();
|
|
1427
|
-
finalUsage = {
|
|
1428
|
-
promptTokens: finalUsage.promptTokens + subUsage.promptTokens,
|
|
1429
|
-
completionTokens: finalUsage.completionTokens + subUsage.completionTokens,
|
|
1430
|
-
};
|
|
1431
|
-
}
|
|
1432
|
-
this.runtime.store.setTokenUsage(finalUsage);
|
|
1433
|
-
}
|
|
1434
|
-
if (sessionId) {
|
|
1435
|
-
if (pendingCompleteTrace) {
|
|
1436
|
-
(0, chat_trace_1.recordTraceEvent)(this.events, sessionId, pendingCompleteTrace);
|
|
1437
|
-
}
|
|
1438
|
-
(0, session_storage_1.updateSessionSkills)(sessionId, appliedSkillNames);
|
|
1439
|
-
}
|
|
1440
|
-
this.events.setStatus(finalModel ? `Completed with ${finalModel}` : 'Completed');
|
|
1441
|
-
}
|
|
1442
|
-
catch (error) {
|
|
1443
|
-
// v0.2.25: Provider retry exhausted is a recoverable turn failure.
|
|
1444
|
-
if (error instanceof provider_resilience_1.ProviderRetryExhaustedError) {
|
|
1445
|
-
const diag = error.diagnostics;
|
|
1446
|
-
const attempts = diag?.attempts?.length ?? '?';
|
|
1447
|
-
const kind = diag?.attempts?.[diag.attempts.length - 1]?.failureKind ?? 'unknown';
|
|
1448
|
-
this.events.setStatus(`Provider unavailable (${kind}, ${attempts} attempts). Retry exhausted — ready for next input.`);
|
|
1449
|
-
this.events.append({
|
|
1450
|
-
role: 'error',
|
|
1451
|
-
title: 'provider',
|
|
1452
|
-
content: `Provider retry exhausted after ${attempts} attempts (${kind}). The turn was not completed. You can try again or wait for the provider to recover.`,
|
|
1453
|
-
errorLayer: 'provider',
|
|
1454
|
-
});
|
|
1455
|
-
// v0.2.25: If a goal is active, pause it on provider retry exhaustion
|
|
1456
|
-
// so it doesn't auto-continue and burn retries.
|
|
1457
|
-
try {
|
|
1458
|
-
const gc = this.goalCoordinator;
|
|
1459
|
-
if (gc?.goal?.status === 'active') {
|
|
1460
|
-
gc.deferContinuation();
|
|
1461
|
-
}
|
|
1462
|
-
}
|
|
1463
|
-
catch {
|
|
1464
|
-
/* best effort */
|
|
1465
|
-
}
|
|
1466
|
-
return;
|
|
1467
|
-
}
|
|
1468
|
-
if ((0, chat_trace_1.isAbortError)(error, abortSignal)) {
|
|
1469
|
-
const interruptedStats = error instanceof framework_1.QueryLoopError
|
|
1470
|
-
? error.stats
|
|
1471
|
-
: (0, framework_1.createFailedLoopStats)({
|
|
1472
|
-
loopBudget,
|
|
1473
|
-
diagnostics: observedLlmRequests > 0 ? (0, chat_trace_1.getLastRequestDiagnostics)(this.runtime.llm) : undefined,
|
|
1474
|
-
turnsStarted: observedTurnsStarted,
|
|
1475
|
-
llmRequests: observedLlmRequests,
|
|
1476
|
-
toolCalls: observedToolCalls,
|
|
1477
|
-
readOnlyToolCalls: observedReadOnlyToolCalls,
|
|
1478
|
-
unsafeToolCalls: observedUnsafeToolCalls,
|
|
1479
|
-
toolResultBytes: observedToolResultBytes,
|
|
1480
|
-
modelVisibleToolBytes: observedModelVisibleToolBytes,
|
|
1481
|
-
});
|
|
1482
|
-
const interruptedRootUsage = error instanceof framework_1.QueryLoopError ? error.aggregateUsage : undefined;
|
|
1483
|
-
// A thrown abort after a provider request started can only prove a
|
|
1484
|
-
// lower bound: the in-flight request may be billable even when its
|
|
1485
|
-
// final usage chunk never arrived.
|
|
1486
|
-
persistInterruptedAccounting(interruptedRootUsage, interruptedStats, interruptedStats.llmRequests === 0);
|
|
1487
|
-
assistantStream.discardSegment();
|
|
1488
|
-
this.events.setStatus('Interrupted.');
|
|
1489
|
-
(0, chat_presentation_1.removeTrailingUserMessage)(this.runtime);
|
|
1490
|
-
if (sessionId) {
|
|
1491
|
-
const { delta } = (0, chat_workspace_1.appendPostWorkspaceTrace)(this.events, sessionId, turnId, this.runtime.cwd, preWorkspace, verificationResults);
|
|
1492
|
-
(0, chat_trace_1.recordTraceEvent)(this.events, sessionId, {
|
|
1493
|
-
turnId,
|
|
1494
|
-
type: 'aborted',
|
|
1495
|
-
note: 'abort_error',
|
|
1496
|
-
});
|
|
1497
|
-
const recoveryNotice = (0, chat_workspace_1.workspaceDeltaHasTurnChanges)(delta)
|
|
1498
|
-
? (0, chat_workspace_1.formatFailureRecoveryNotice)(turnId, delta, checkpointIds)
|
|
1499
|
-
: undefined;
|
|
1500
|
-
if (recoveryNotice) {
|
|
1501
|
-
this.events.append({
|
|
1502
|
-
role: 'status',
|
|
1503
|
-
title: 'recovery',
|
|
1504
|
-
statusTone: 'warning',
|
|
1505
|
-
content: recoveryNotice,
|
|
1506
|
-
});
|
|
1507
|
-
}
|
|
1508
|
-
(0, session_storage_1.removeLastIncompleteAssistantMessage)(sessionId);
|
|
1509
|
-
}
|
|
1510
|
-
return;
|
|
1511
|
-
}
|
|
1512
|
-
assistantStream.discardSegment();
|
|
1513
|
-
this.events.append({
|
|
1514
|
-
role: 'error',
|
|
1515
|
-
content: (0, chat_trace_1.formatChatError)(error),
|
|
1516
|
-
errorLayer: (0, chat_trace_1.errorLayerForChatError)(error),
|
|
1517
|
-
});
|
|
1518
|
-
this.events.setStatus('Turn failed. Ready for the next input.');
|
|
1519
|
-
const failedStats = this.foldSubagentUsage(error instanceof framework_1.QueryLoopError
|
|
1520
|
-
? error.stats
|
|
1521
|
-
: (0, framework_1.createFailedLoopStats)({
|
|
1522
|
-
loopBudget,
|
|
1523
|
-
diagnostics: observedLlmRequests > 0 ? (0, chat_trace_1.getLastRequestDiagnostics)(this.runtime.llm) : undefined,
|
|
1524
|
-
turnsStarted: observedTurnsStarted,
|
|
1525
|
-
llmRequests: observedLlmRequests,
|
|
1526
|
-
toolCalls: observedToolCalls,
|
|
1527
|
-
readOnlyToolCalls: observedReadOnlyToolCalls,
|
|
1528
|
-
unsafeToolCalls: observedUnsafeToolCalls,
|
|
1529
|
-
toolResultBytes: observedToolResultBytes,
|
|
1530
|
-
modelVisibleToolBytes: observedModelVisibleToolBytes,
|
|
1531
|
-
}), subagentBundle);
|
|
1532
|
-
const rootUsage = error instanceof framework_1.QueryLoopError ? error.aggregateUsage : undefined;
|
|
1533
|
-
const subagentUsage = subagentBundle?.getAggregateUsage();
|
|
1534
|
-
const hasSubagentUsage = (subagentUsage?.promptTokens ?? 0) > 0 || (subagentUsage?.completionTokens ?? 0) > 0;
|
|
1535
|
-
if (rootUsage || hasSubagentUsage) {
|
|
1536
|
-
this.runtime.store.setTokenUsage({
|
|
1537
|
-
promptTokens: (rootUsage?.promptTokens ?? 0) + (subagentUsage?.promptTokens ?? 0),
|
|
1538
|
-
completionTokens: (rootUsage?.completionTokens ?? 0) + (subagentUsage?.completionTokens ?? 0),
|
|
1539
|
-
});
|
|
1540
|
-
}
|
|
1541
|
-
this.setLoopStats(failedStats);
|
|
1542
|
-
if (sessionId) {
|
|
1543
|
-
(0, chat_trace_1.recordProviderTraceEvents)(this.events, sessionId, turnId, failedStats);
|
|
1544
|
-
const { delta } = (0, chat_workspace_1.appendPostWorkspaceTrace)(this.events, sessionId, turnId, this.runtime.cwd, preWorkspace, verificationResults);
|
|
1545
|
-
const recoveryNotice = (0, chat_workspace_1.workspaceDeltaHasTurnChanges)(delta)
|
|
1546
|
-
? (0, chat_workspace_1.formatFailureRecoveryNotice)(turnId, delta, checkpointIds)
|
|
1547
|
-
: undefined;
|
|
1548
|
-
if (recoveryNotice) {
|
|
1549
|
-
this.events.append({
|
|
1550
|
-
role: 'status',
|
|
1551
|
-
title: 'recovery',
|
|
1552
|
-
statusTone: 'warning',
|
|
1553
|
-
content: recoveryNotice,
|
|
1554
|
-
});
|
|
1555
|
-
}
|
|
1556
|
-
(0, chat_trace_1.recordTraceEvent)(this.events, sessionId, {
|
|
1557
|
-
turnId,
|
|
1558
|
-
type: 'error',
|
|
1559
|
-
error: (0, chat_trace_1.compactTraceError)(error),
|
|
1560
|
-
note: recoveryNotice,
|
|
1561
|
-
});
|
|
1562
|
-
(0, chat_trace_1.recordTraceEvent)(this.events, sessionId, {
|
|
1563
|
-
turnId,
|
|
1564
|
-
type: 'complete',
|
|
1565
|
-
model: failedStats.providerFinalModel ?? this.runtime.llm.getModel(),
|
|
1566
|
-
contentBytes: 0,
|
|
1567
|
-
finishReason: failedStats.finishReason,
|
|
1568
|
-
stopDecision: failedStats.stopDecision,
|
|
1569
|
-
llmRequests: failedStats.llmRequests,
|
|
1570
|
-
toolCalls: failedStats.toolCalls,
|
|
1571
|
-
readOnlyToolCalls: failedStats.readOnlyToolCalls,
|
|
1572
|
-
unsafeToolCalls: failedStats.unsafeToolCalls,
|
|
1573
|
-
loopBudgetSource: failedStats.loopBudgetSource,
|
|
1574
|
-
loopBudgetBaseProfile: failedStats.loopBudgetBaseProfile,
|
|
1575
|
-
loopBudgetMaxLlmRequests: failedStats.loopBudgetMaxLlmRequests,
|
|
1576
|
-
loopBudgetMaxToolCalls: failedStats.loopBudgetMaxToolCalls,
|
|
1577
|
-
loopBudgetMaxReadOnlyFragmentation: failedStats.loopBudgetMaxReadOnlyFragmentation,
|
|
1578
|
-
loopBudgetMaxModelVisibleBytes: failedStats.loopBudgetMaxModelVisibleBytes,
|
|
1579
|
-
loopBudgetConfigOverride: failedStats.loopBudgetConfigOverride,
|
|
1580
|
-
localFastPathUsed: failedStats.localFastPathUsed,
|
|
1581
|
-
});
|
|
1582
|
-
(0, session_storage_1.removeLastIncompleteAssistantMessage)(sessionId);
|
|
1583
|
-
// A failed turn must not leave the user's prompt dangling in the
|
|
1584
|
-
// persisted session (it would replay on resume). The in-memory history
|
|
1585
|
-
// is cleaned above (2969-2972); mirror that for the on-disk transcript.
|
|
1586
|
-
if (options.persistAsUserMessage !== false) {
|
|
1587
|
-
(0, session_storage_1.removeTrailingSessionUserMessage)(sessionId);
|
|
1588
|
-
}
|
|
1589
|
-
}
|
|
1590
|
-
const history = this.runtime.store.getSnapshot().conversationHistory;
|
|
1591
|
-
if (history.length > 0) {
|
|
1592
|
-
this.runtime.store.setState({ conversationHistory: history.slice(0, -1) });
|
|
1593
|
-
}
|
|
1594
|
-
}
|
|
1595
|
-
finally {
|
|
1596
|
-
restoreProviderPreflight?.();
|
|
1597
|
-
}
|
|
1598
|
-
}
|
|
1599
|
-
}
|
|
1600
|
-
exports.AgentChatController = AgentChatController;
|
|
1601
|
-
exports.InkChatController = AgentChatController;
|
|
1602
|
-
function loadSessionIntoRuntime(runtime, sessionId) {
|
|
1603
|
-
const history = (0, session_storage_1.loadSessionHistory)(sessionId);
|
|
1604
|
-
runtime.store.setState({ conversationHistory: history });
|
|
1605
|
-
runtime.store.setState({
|
|
1606
|
-
harnessState: (0, session_storage_1.loadSessionHarnessState)(sessionId) ?? (0, session_storage_1.loadSessionMeta)(sessionId)?.harnessState,
|
|
1607
|
-
});
|
|
1608
|
-
return `Restored ${history.length} messages`;
|
|
1609
|
-
}
|
|
1610
|
-
function closeSession(runtime) {
|
|
1611
|
-
const session = runtime.getSession();
|
|
1612
|
-
if (!session)
|
|
1613
|
-
return;
|
|
1614
|
-
const messages = (0, session_storage_1.readSessionMessages)(session.id);
|
|
1615
|
-
if (messages.length > 0) {
|
|
1616
|
-
(0, session_storage_1.updateSessionSummary)(session.id, messages);
|
|
1617
|
-
}
|
|
1618
|
-
(0, session_storage_1.endSession)(session.id);
|
|
1619
|
-
}
|
|
1620
|
-
//# sourceMappingURL=chat-controller.js.map
|