@orion-agents/orion-code 0.1.3 → 0.1.4-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/README.md +26 -4
- package/README.zh-CN.md +41 -5
- package/dist/agents/coder.d.ts.map +1 -1
- package/dist/agents/coder.js.map +1 -1
- package/dist/agents/fork.d.ts +12 -4
- package/dist/agents/fork.d.ts.map +1 -1
- package/dist/agents/fork.js +28 -32
- package/dist/agents/fork.js.map +1 -1
- package/dist/agents/leader.d.ts.map +1 -1
- package/dist/agents/leader.js.map +1 -1
- package/dist/agents/worker-pool.d.ts.map +1 -1
- package/dist/agents/worker-pool.js +38 -29
- package/dist/agents/worker-pool.js.map +1 -1
- package/dist/cli.d.ts +1 -1
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +0 -1
- package/dist/cli.js.map +1 -1
- package/dist/commands/context-commands.d.ts +4 -0
- package/dist/commands/context-commands.d.ts.map +1 -0
- package/dist/commands/context-commands.js +52 -0
- package/dist/commands/context-commands.js.map +1 -0
- package/dist/commands/context-tool-command-handlers.d.ts +13 -0
- package/dist/commands/context-tool-command-handlers.d.ts.map +1 -0
- package/dist/commands/context-tool-command-handlers.js +573 -0
- package/dist/commands/context-tool-command-handlers.js.map +1 -0
- package/dist/commands/core-command-handlers.d.ts +12 -0
- package/dist/commands/core-command-handlers.d.ts.map +1 -0
- package/dist/commands/core-command-handlers.js +798 -0
- package/dist/commands/core-command-handlers.js.map +1 -0
- package/dist/commands/diagnostic-command-handlers.d.ts +14 -0
- package/dist/commands/diagnostic-command-handlers.d.ts.map +1 -0
- package/dist/commands/diagnostic-command-handlers.js +1043 -0
- package/dist/commands/diagnostic-command-handlers.js.map +1 -0
- package/dist/commands/diagnostic-commands.d.ts +4 -0
- package/dist/commands/diagnostic-commands.d.ts.map +1 -0
- package/dist/commands/diagnostic-commands.js +132 -0
- package/dist/commands/diagnostic-commands.js.map +1 -0
- package/dist/commands/index.d.ts +7 -8
- package/dist/commands/index.d.ts.map +1 -1
- package/dist/commands/index.js +34 -3562
- package/dist/commands/index.js.map +1 -1
- package/dist/commands/legacy-commands.d.ts +4 -0
- package/dist/commands/legacy-commands.d.ts.map +1 -0
- package/dist/commands/legacy-commands.js +44 -0
- package/dist/commands/legacy-commands.js.map +1 -0
- package/dist/commands/model-command-handlers.d.ts +13 -0
- package/dist/commands/model-command-handlers.d.ts.map +1 -0
- package/dist/commands/model-command-handlers.js +314 -0
- package/dist/commands/model-command-handlers.js.map +1 -0
- package/dist/commands/model-commands.d.ts +4 -0
- package/dist/commands/model-commands.d.ts.map +1 -0
- package/dist/commands/model-commands.js +52 -0
- package/dist/commands/model-commands.js.map +1 -0
- package/dist/commands/session-command-handlers.d.ts +9 -0
- package/dist/commands/session-command-handlers.d.ts.map +1 -0
- package/dist/commands/session-command-handlers.js +566 -0
- package/dist/commands/session-command-handlers.js.map +1 -0
- package/dist/commands/session-commands.d.ts +4 -0
- package/dist/commands/session-commands.d.ts.map +1 -0
- package/dist/commands/session-commands.js +78 -0
- package/dist/commands/session-commands.js.map +1 -0
- package/dist/commands/system-commands.d.ts +4 -0
- package/dist/commands/system-commands.d.ts.map +1 -0
- package/dist/commands/system-commands.js +92 -0
- package/dist/commands/system-commands.js.map +1 -0
- package/dist/commands/target-command.d.ts.map +1 -1
- package/dist/commands/target-command.js +29 -2
- package/dist/commands/target-command.js.map +1 -1
- package/dist/commands/tool-commands.d.ts +4 -0
- package/dist/commands/tool-commands.d.ts.map +1 -0
- package/dist/commands/tool-commands.js +49 -0
- package/dist/commands/tool-commands.js.map +1 -0
- package/dist/commands/types.d.ts +4 -4
- package/dist/commands/workflow-command-handlers.d.ts +7 -0
- package/dist/commands/workflow-command-handlers.d.ts.map +1 -0
- package/dist/commands/workflow-command-handlers.js +35 -0
- package/dist/commands/workflow-command-handlers.js.map +1 -0
- package/dist/commands/workflow-commands.d.ts +4 -0
- package/dist/commands/workflow-commands.d.ts.map +1 -0
- package/dist/commands/workflow-commands.js +92 -0
- package/dist/commands/workflow-commands.js.map +1 -0
- package/dist/core/checkpoint.d.ts +12 -4
- package/dist/core/checkpoint.d.ts.map +1 -1
- package/dist/core/checkpoint.js +114 -28
- package/dist/core/checkpoint.js.map +1 -1
- package/dist/core/cost-tracker.d.ts +5 -1
- package/dist/core/cost-tracker.d.ts.map +1 -1
- package/dist/core/cost-tracker.js +12 -2
- package/dist/core/cost-tracker.js.map +1 -1
- package/dist/core/warn-dedup.d.ts +3 -0
- package/dist/core/warn-dedup.d.ts.map +1 -1
- package/dist/core/warn-dedup.js +6 -6
- package/dist/core/warn-dedup.js.map +1 -1
- package/dist/framework/index.d.ts +1 -1
- package/dist/framework/index.d.ts.map +1 -1
- package/dist/framework/index.js.map +1 -1
- package/dist/framework/prompt.d.ts +2 -2
- package/dist/framework/query.d.ts +2 -2
- package/dist/framework/query.d.ts.map +1 -1
- package/dist/framework/query.js +57 -10
- package/dist/framework/query.js.map +1 -1
- package/dist/framework/store.d.ts +4 -4
- package/dist/framework/tool-scheduler.d.ts +16 -13
- package/dist/framework/tool-scheduler.d.ts.map +1 -1
- package/dist/framework/tool-scheduler.js +135 -32
- package/dist/framework/tool-scheduler.js.map +1 -1
- package/dist/framework/tool.d.ts +30 -2
- package/dist/framework/tool.d.ts.map +1 -1
- package/dist/framework/tool.js +27 -1
- package/dist/framework/tool.js.map +1 -1
- package/dist/harness/assembler.d.ts.map +1 -1
- package/dist/harness/assembler.js +4 -2
- package/dist/harness/assembler.js.map +1 -1
- package/dist/harness/evidence.d.ts.map +1 -1
- package/dist/harness/evidence.js +3 -2
- package/dist/harness/evidence.js.map +1 -1
- package/dist/harness/safety.d.ts +11 -1
- package/dist/harness/safety.d.ts.map +1 -1
- package/dist/harness/safety.js +112 -16
- package/dist/harness/safety.js.map +1 -1
- package/dist/index.d.ts +1 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/init.d.ts +4 -8
- package/dist/init.d.ts.map +1 -1
- package/dist/init.js +4 -4
- package/dist/init.js.map +1 -1
- package/dist/ink-ui/App.d.ts +2 -2
- package/dist/ink-ui/components/Markdown.d.ts.map +1 -1
- package/dist/ink-ui/components/Markdown.js.map +1 -1
- package/dist/ink-ui/components/PixelHorseBanner.d.ts +2 -2
- package/dist/ink-ui/components/StatusLine.d.ts +2 -2
- package/dist/ink-ui/launch.d.ts +2 -2
- package/dist/ink-ui/screens/ReplScreen.d.ts +2 -2
- package/dist/ink-ui/screens/ReplScreen.js.map +1 -1
- package/dist/memory/embeddings.d.ts.map +1 -1
- package/dist/memory/embeddings.js +3 -2
- package/dist/memory/embeddings.js.map +1 -1
- package/dist/memory/relevant-finder.d.ts +2 -1
- package/dist/memory/relevant-finder.d.ts.map +1 -1
- package/dist/memory/relevant-finder.js +17 -8
- package/dist/memory/relevant-finder.js.map +1 -1
- package/dist/memory/semantic-config.d.ts +9 -0
- package/dist/memory/semantic-config.d.ts.map +1 -0
- package/dist/memory/semantic-config.js +16 -0
- package/dist/memory/semantic-config.js.map +1 -0
- package/dist/memory/semantic-search.d.ts +1 -6
- package/dist/memory/semantic-search.d.ts.map +1 -1
- package/dist/memory/semantic-search.js +5 -16
- package/dist/memory/semantic-search.js.map +1 -1
- package/dist/memory/storage.d.ts +23 -0
- package/dist/memory/storage.d.ts.map +1 -1
- package/dist/memory/storage.js +109 -8
- package/dist/memory/storage.js.map +1 -1
- package/dist/memory/vector-store.d.ts +12 -0
- package/dist/memory/vector-store.d.ts.map +1 -1
- package/dist/memory/vector-store.js +139 -18
- package/dist/memory/vector-store.js.map +1 -1
- package/dist/migration/command.d.ts.map +1 -1
- package/dist/migration/command.js +0 -1
- package/dist/migration/command.js.map +1 -1
- package/dist/migration/migrate.d.ts.map +1 -1
- package/dist/migration/migrate.js +43 -109
- package/dist/migration/migrate.js.map +1 -1
- package/dist/migration/types.d.ts +0 -1
- package/dist/migration/types.d.ts.map +1 -1
- package/dist/print-ui/launch.d.ts +10 -3
- package/dist/print-ui/launch.d.ts.map +1 -1
- package/dist/print-ui/launch.js +18 -0
- package/dist/print-ui/launch.js.map +1 -1
- package/dist/product/environment.d.ts +3 -5
- package/dist/product/environment.d.ts.map +1 -1
- package/dist/product/environment.js +4 -32
- package/dist/product/environment.js.map +1 -1
- package/dist/product/index.d.ts +1 -1
- package/dist/product/index.d.ts.map +1 -1
- package/dist/product/index.js +1 -3
- package/dist/product/index.js.map +1 -1
- package/dist/product/paths.d.ts.map +1 -1
- package/dist/product/paths.js +12 -0
- package/dist/product/paths.js.map +1 -1
- package/dist/runtime/agent-runtime-controller.d.ts +2 -2
- package/dist/runtime/agent-runtime-protocol.d.ts +4 -1
- package/dist/runtime/agent-runtime-protocol.d.ts.map +1 -1
- package/dist/runtime/agent-runtime-protocol.js +6 -0
- package/dist/runtime/agent-runtime-protocol.js.map +1 -1
- package/dist/runtime/chat-checkpoint.d.ts +17 -0
- package/dist/runtime/chat-checkpoint.d.ts.map +1 -0
- package/dist/runtime/chat-checkpoint.js +108 -0
- package/dist/runtime/chat-checkpoint.js.map +1 -0
- package/dist/runtime/chat-controller.d.ts +10 -46
- package/dist/runtime/chat-controller.d.ts.map +1 -1
- package/dist/runtime/chat-controller.js +199 -1051
- package/dist/runtime/chat-controller.js.map +1 -1
- package/dist/runtime/chat-presentation.d.ts +60 -0
- package/dist/runtime/chat-presentation.d.ts.map +1 -0
- package/dist/runtime/chat-presentation.js +537 -0
- package/dist/runtime/chat-presentation.js.map +1 -0
- package/dist/runtime/chat-trace.d.ts +52 -0
- package/dist/runtime/chat-trace.d.ts.map +1 -0
- package/dist/runtime/chat-trace.js +234 -0
- package/dist/runtime/chat-trace.js.map +1 -0
- package/dist/runtime/chat-workspace.d.ts +22 -0
- package/dist/runtime/chat-workspace.d.ts.map +1 -0
- package/dist/runtime/chat-workspace.js +154 -0
- package/dist/runtime/chat-workspace.js.map +1 -0
- package/dist/runtime/goals/accounting.js +1 -1
- package/dist/runtime/goals/accounting.js.map +1 -1
- package/dist/runtime/goals/completion-audit.d.ts.map +1 -1
- package/dist/runtime/goals/completion-audit.js +5 -4
- package/dist/runtime/goals/completion-audit.js.map +1 -1
- package/dist/runtime/goals/coordinator.d.ts +3 -0
- package/dist/runtime/goals/coordinator.d.ts.map +1 -1
- package/dist/runtime/goals/coordinator.js +30 -2
- package/dist/runtime/goals/coordinator.js.map +1 -1
- package/dist/runtime/goals/prompt.d.ts +1 -1
- package/dist/runtime/goals/prompt.d.ts.map +1 -1
- package/dist/runtime/goals/prompt.js +3 -2
- package/dist/runtime/goals/prompt.js.map +1 -1
- package/dist/runtime/goals/tools.d.ts +21 -8
- package/dist/runtime/goals/tools.d.ts.map +1 -1
- package/dist/runtime/goals/tools.js +141 -10
- package/dist/runtime/goals/tools.js.map +1 -1
- package/dist/runtime/loop-budget.d.ts +2 -2
- package/dist/runtime/model-coordinator.d.ts.map +1 -1
- package/dist/runtime/model-coordinator.js.map +1 -1
- package/dist/runtime/subagents/child-executor-guard.d.ts.map +1 -1
- package/dist/runtime/subagents/child-executor-guard.js +4 -0
- package/dist/runtime/subagents/child-executor-guard.js.map +1 -1
- package/dist/runtime/subagents/index.d.ts +10 -3
- package/dist/runtime/subagents/index.d.ts.map +1 -1
- package/dist/runtime/subagents/index.js +25 -1
- package/dist/runtime/subagents/index.js.map +1 -1
- package/dist/runtime/subagents/policy.d.ts +1 -1
- package/dist/runtime/subagents/policy.d.ts.map +1 -1
- package/dist/runtime/subagents/policy.js.map +1 -1
- package/dist/runtime/subagents/presets.d.ts +2 -2
- package/dist/runtime/subagents/provider-gate.d.ts.map +1 -1
- package/dist/runtime/subagents/provider-gate.js +0 -1
- package/dist/runtime/subagents/provider-gate.js.map +1 -1
- package/dist/runtime/subagents/research-artifact.d.ts +101 -0
- package/dist/runtime/subagents/research-artifact.d.ts.map +1 -0
- package/dist/runtime/subagents/research-artifact.js +210 -0
- package/dist/runtime/subagents/research-artifact.js.map +1 -0
- package/dist/runtime/subagents/research-citation.d.ts +66 -0
- package/dist/runtime/subagents/research-citation.d.ts.map +1 -0
- package/dist/runtime/subagents/research-citation.js +185 -0
- package/dist/runtime/subagents/research-citation.js.map +1 -0
- package/dist/runtime/subagents/research-contract.d.ts +83 -0
- package/dist/runtime/subagents/research-contract.d.ts.map +1 -0
- package/dist/runtime/subagents/research-contract.js +337 -0
- package/dist/runtime/subagents/research-contract.js.map +1 -0
- package/dist/runtime/subagents/research-quality.d.ts +47 -0
- package/dist/runtime/subagents/research-quality.d.ts.map +1 -0
- package/dist/runtime/subagents/research-quality.js +125 -0
- package/dist/runtime/subagents/research-quality.js.map +1 -0
- package/dist/runtime/subagents/research-renderer.d.ts +95 -0
- package/dist/runtime/subagents/research-renderer.d.ts.map +1 -0
- package/dist/runtime/subagents/research-renderer.js +186 -0
- package/dist/runtime/subagents/research-renderer.js.map +1 -0
- package/dist/runtime/subagents/research-types.d.ts +105 -0
- package/dist/runtime/subagents/research-types.d.ts.map +1 -0
- package/dist/runtime/subagents/research-types.js +16 -0
- package/dist/runtime/subagents/research-types.js.map +1 -0
- package/dist/runtime/subagents/result-parser.d.ts +1 -5
- package/dist/runtime/subagents/result-parser.d.ts.map +1 -1
- package/dist/runtime/subagents/result-parser.js +5 -72
- package/dist/runtime/subagents/result-parser.js.map +1 -1
- package/dist/runtime/subagents/runtime-integration.d.ts +13 -7
- package/dist/runtime/subagents/runtime-integration.d.ts.map +1 -1
- package/dist/runtime/subagents/runtime-integration.js +112 -2
- package/dist/runtime/subagents/runtime-integration.js.map +1 -1
- package/dist/runtime/subagents/supervisor.d.ts +15 -1
- package/dist/runtime/subagents/supervisor.d.ts.map +1 -1
- package/dist/runtime/subagents/supervisor.js +58 -3
- package/dist/runtime/subagents/supervisor.js.map +1 -1
- package/dist/runtime/subagents/tool.d.ts +2 -2
- package/dist/runtime/subagents/tool.d.ts.map +1 -1
- package/dist/runtime/subagents/tool.js +129 -9
- package/dist/runtime/subagents/tool.js.map +1 -1
- package/dist/runtime/subagents/types.d.ts +20 -0
- package/dist/runtime/subagents/types.d.ts.map +1 -1
- package/dist/runtime/subagents/types.js.map +1 -1
- package/dist/runtime/subagents/web-research-adapter.d.ts +85 -0
- package/dist/runtime/subagents/web-research-adapter.d.ts.map +1 -0
- package/dist/runtime/subagents/web-research-adapter.js +328 -0
- package/dist/runtime/subagents/web-research-adapter.js.map +1 -0
- package/dist/runtime/ui-events.d.ts +8 -8
- package/dist/runtime/ui-events.d.ts.map +1 -1
- package/dist/runtime/ui-events.js.map +1 -1
- package/dist/runtime/ui-view-model.d.ts +40 -0
- package/dist/runtime/ui-view-model.d.ts.map +1 -1
- package/dist/runtime/ui-view-model.js +126 -0
- package/dist/runtime/ui-view-model.js.map +1 -1
- package/dist/services/agent-runner.d.ts +5 -2
- package/dist/services/agent-runner.d.ts.map +1 -1
- package/dist/services/agent-runner.js +18 -18
- package/dist/services/agent-runner.js.map +1 -1
- package/dist/services/atomic-write.d.ts +9 -1
- package/dist/services/atomic-write.d.ts.map +1 -1
- package/dist/services/atomic-write.js +55 -2
- package/dist/services/atomic-write.js.map +1 -1
- package/dist/services/auth/auth.d.ts +11 -7
- package/dist/services/auth/auth.d.ts.map +1 -1
- package/dist/services/auth/auth.js +133 -34
- package/dist/services/auth/auth.js.map +1 -1
- package/dist/services/auth/aws.d.ts +2 -0
- package/dist/services/auth/aws.d.ts.map +1 -1
- package/dist/services/auth/aws.js +126 -12
- package/dist/services/auth/aws.js.map +1 -1
- package/dist/services/auth/index.d.ts +1 -1
- package/dist/services/auth/index.d.ts.map +1 -1
- package/dist/services/auth/index.js +2 -1
- package/dist/services/auth/index.js.map +1 -1
- package/dist/services/auto-fix/autoFixConfig.d.ts +0 -3
- package/dist/services/auto-fix/autoFixConfig.d.ts.map +1 -1
- package/dist/services/auto-fix/autoFixConfig.js +25 -8
- package/dist/services/auto-fix/autoFixConfig.js.map +1 -1
- package/dist/services/auto-fix/autoFixHook.d.ts +7 -0
- package/dist/services/auto-fix/autoFixHook.d.ts.map +1 -1
- package/dist/services/auto-fix/autoFixHook.js +10 -1
- package/dist/services/auto-fix/autoFixHook.js.map +1 -1
- package/dist/services/compact/auto-compact.d.ts +2 -0
- package/dist/services/compact/auto-compact.d.ts.map +1 -1
- package/dist/services/compact/auto-compact.js +15 -1
- package/dist/services/compact/auto-compact.js.map +1 -1
- package/dist/services/compact/compact.d.ts.map +1 -1
- package/dist/services/compact/compact.js +9 -11
- package/dist/services/compact/compact.js.map +1 -1
- package/dist/services/compact/summary-generator.d.ts.map +1 -1
- package/dist/services/compact/summary-generator.js +28 -4
- package/dist/services/compact/summary-generator.js.map +1 -1
- package/dist/services/compact/tool-call-groups.d.ts +19 -0
- package/dist/services/compact/tool-call-groups.d.ts.map +1 -0
- package/dist/services/compact/tool-call-groups.js +105 -0
- package/dist/services/compact/tool-call-groups.js.map +1 -0
- package/dist/services/concurrent-sessions.d.ts +4 -0
- package/dist/services/concurrent-sessions.d.ts.map +1 -1
- package/dist/services/concurrent-sessions.js +76 -21
- package/dist/services/concurrent-sessions.js.map +1 -1
- package/dist/services/config-dir.d.ts.map +1 -1
- package/dist/services/config-dir.js +19 -5
- package/dist/services/config-dir.js.map +1 -1
- package/dist/services/config.d.ts +6 -4
- package/dist/services/config.d.ts.map +1 -1
- package/dist/services/config.js +14 -71
- package/dist/services/config.js.map +1 -1
- package/dist/services/doctor.d.ts +2 -2
- package/dist/services/doctor.js.map +1 -1
- package/dist/services/file-glob.d.ts.map +1 -1
- package/dist/services/file-glob.js +22 -2
- package/dist/services/file-glob.js.map +1 -1
- package/dist/services/file-lock.d.ts +7 -0
- package/dist/services/file-lock.d.ts.map +1 -0
- package/dist/services/file-lock.js +139 -0
- package/dist/services/file-lock.js.map +1 -0
- package/dist/services/global-config.d.ts +2 -0
- package/dist/services/global-config.d.ts.map +1 -1
- package/dist/services/global-config.js +67 -4
- package/dist/services/global-config.js.map +1 -1
- package/dist/services/goal-storage.d.ts.map +1 -1
- package/dist/services/goal-storage.js +52 -19
- package/dist/services/goal-storage.js.map +1 -1
- package/dist/services/llm.d.ts +12 -0
- package/dist/services/llm.d.ts.map +1 -1
- package/dist/services/llm.js +166 -69
- package/dist/services/llm.js.map +1 -1
- package/dist/services/mcp/transports.d.ts +0 -1
- package/dist/services/mcp/transports.d.ts.map +1 -1
- package/dist/services/mcp/transports.js +12 -13
- package/dist/services/mcp/transports.js.map +1 -1
- package/dist/services/model-context.d.ts +8 -0
- package/dist/services/model-context.d.ts.map +1 -1
- package/dist/services/model-context.js +111 -7
- package/dist/services/model-context.js.map +1 -1
- package/dist/services/provider-resilience/coordinator.d.ts +9 -4
- package/dist/services/provider-resilience/coordinator.d.ts.map +1 -1
- package/dist/services/provider-resilience/coordinator.js +88 -21
- package/dist/services/provider-resilience/coordinator.js.map +1 -1
- package/dist/services/provider-resilience/error-classifier.d.ts +1 -0
- package/dist/services/provider-resilience/error-classifier.d.ts.map +1 -1
- package/dist/services/provider-resilience/error-classifier.js +50 -29
- package/dist/services/provider-resilience/error-classifier.js.map +1 -1
- package/dist/services/provider-resilience/index.d.ts +3 -3
- package/dist/services/provider-resilience/index.d.ts.map +1 -1
- package/dist/services/provider-resilience/index.js +3 -1
- package/dist/services/provider-resilience/index.js.map +1 -1
- package/dist/services/provider-resilience/request-gate.d.ts +6 -0
- package/dist/services/provider-resilience/request-gate.d.ts.map +1 -1
- package/dist/services/provider-resilience/request-gate.js +24 -9
- package/dist/services/provider-resilience/request-gate.js.map +1 -1
- package/dist/services/provider-resilience/stream-recovery.d.ts +1 -1
- package/dist/services/provider-resilience/stream-recovery.d.ts.map +1 -1
- package/dist/services/provider-resilience/stream-recovery.js +1 -1
- package/dist/services/provider-resilience/stream-recovery.js.map +1 -1
- package/dist/services/provider-resilience/types.d.ts +9 -0
- package/dist/services/provider-resilience/types.d.ts.map +1 -1
- package/dist/services/provider-resilience/types.js.map +1 -1
- package/dist/services/redaction.d.ts.map +1 -1
- package/dist/services/redaction.js +29 -1
- package/dist/services/redaction.js.map +1 -1
- package/dist/services/session-index.d.ts.map +1 -1
- package/dist/services/session-index.js +75 -44
- package/dist/services/session-index.js.map +1 -1
- package/dist/services/session-memory/sessionMemory.d.ts.map +1 -1
- package/dist/services/session-memory/sessionMemory.js +6 -3
- package/dist/services/session-memory/sessionMemory.js.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 +105 -27
- package/dist/services/session-storage.js.map +1 -1
- package/dist/services/storage-maintenance.d.ts.map +1 -1
- package/dist/services/storage-maintenance.js +62 -9
- package/dist/services/storage-maintenance.js.map +1 -1
- package/dist/services/task-manager.d.ts +9 -4
- package/dist/services/task-manager.d.ts.map +1 -1
- package/dist/services/task-manager.js +18 -4
- package/dist/services/task-manager.js.map +1 -1
- package/dist/services/usage-state.d.ts +1 -0
- package/dist/services/usage-state.d.ts.map +1 -1
- package/dist/services/usage-state.js +81 -45
- package/dist/services/usage-state.js.map +1 -1
- package/dist/services/verification-profile.d.ts.map +1 -1
- package/dist/services/verification-profile.js +23 -3
- package/dist/services/verification-profile.js.map +1 -1
- package/dist/services/web-search-adapters.d.ts.map +1 -1
- package/dist/services/web-search-adapters.js +48 -18
- package/dist/services/web-search-adapters.js.map +1 -1
- package/dist/services/web-search-mcp.d.ts.map +1 -1
- package/dist/services/web-search-mcp.js +27 -11
- package/dist/services/web-search-mcp.js.map +1 -1
- package/dist/services/workspace-diff.d.ts +14 -0
- package/dist/services/workspace-diff.d.ts.map +1 -1
- package/dist/services/workspace-diff.js +60 -11
- package/dist/services/workspace-diff.js.map +1 -1
- package/dist/services/yaml-config.d.ts.map +1 -1
- package/dist/services/yaml-config.js +2 -1
- package/dist/services/yaml-config.js.map +1 -1
- package/dist/skills/loader.d.ts.map +1 -1
- package/dist/skills/loader.js +26 -11
- package/dist/skills/loader.js.map +1 -1
- package/dist/skills/runtime.d.ts +3 -3
- package/dist/skills/runtime.d.ts.map +1 -1
- package/dist/skills/runtime.js +37 -4
- package/dist/skills/runtime.js.map +1 -1
- package/dist/skills/types.d.ts +1 -1
- package/dist/skills/types.d.ts.map +1 -1
- package/dist/terminal-ui/launch.d.ts +16 -8
- package/dist/terminal-ui/launch.d.ts.map +1 -1
- package/dist/terminal-ui/launch.js +26 -0
- package/dist/terminal-ui/launch.js.map +1 -1
- package/dist/terminal-ui/raw-editor.js.map +1 -1
- package/dist/tools/bash_security.d.ts +58 -18
- package/dist/tools/bash_security.d.ts.map +1 -1
- package/dist/tools/bash_security.js +587 -80
- package/dist/tools/bash_security.js.map +1 -1
- package/dist/tools/git.d.ts +8 -8
- package/dist/tools/git.d.ts.map +1 -1
- package/dist/tools/git.js +248 -55
- package/dist/tools/git.js.map +1 -1
- package/dist/tools/index.d.ts +14 -4
- package/dist/tools/index.d.ts.map +1 -1
- package/dist/tools/index.js +236 -42
- package/dist/tools/index.js.map +1 -1
- package/dist/tools/lsp.d.ts +74 -6
- package/dist/tools/lsp.d.ts.map +1 -1
- package/dist/tools/lsp.js +24 -5
- package/dist/tools/lsp.js.map +1 -1
- package/dist/tools/mcp.d.ts +19 -6
- package/dist/tools/mcp.d.ts.map +1 -1
- package/dist/tools/mcp.js +143 -26
- package/dist/tools/mcp.js.map +1 -1
- package/dist/tools/plan.d.ts +4 -4
- package/dist/tools/sandbox.d.ts +3 -1
- package/dist/tools/sandbox.d.ts.map +1 -1
- package/dist/tools/sandbox.js +28 -13
- package/dist/tools/sandbox.js.map +1 -1
- package/dist/tools/todo.d.ts +3 -3
- package/dist/tools/web.d.ts +15 -4
- package/dist/tools/web.d.ts.map +1 -1
- package/dist/tools/web.js +240 -26
- package/dist/tools/web.js.map +1 -1
- package/dist/tui-core/frame.js.map +1 -1
- package/dist/tui-ui/launch.d.ts +3 -3
- package/dist/tui-ui/layout.d.ts.map +1 -1
- package/dist/tui-ui/layout.js +2 -0
- package/dist/tui-ui/layout.js.map +1 -1
- package/dist/tui-ui/runner.d.ts.map +1 -1
- package/dist/tui-ui/runner.js +1 -0
- package/dist/tui-ui/runner.js.map +1 -1
- package/dist/tui-ui/state.d.ts +9 -1
- package/dist/tui-ui/state.d.ts.map +1 -1
- package/dist/tui-ui/state.js +13 -0
- package/dist/tui-ui/state.js.map +1 -1
- package/dist/ui/markdown.js.map +1 -1
- package/dist/utils/debug-log.d.ts +52 -0
- package/dist/utils/debug-log.d.ts.map +1 -0
- package/dist/utils/debug-log.js +94 -0
- package/dist/utils/debug-log.js.map +1 -0
- package/dist/utils/errors.d.ts +25 -0
- package/dist/utils/errors.d.ts.map +1 -0
- package/dist/utils/errors.js +47 -0
- package/dist/utils/errors.js.map +1 -0
- package/dist/utils/json.d.ts +6 -0
- package/dist/utils/json.d.ts.map +1 -0
- package/dist/utils/json.js +66 -0
- package/dist/utils/json.js.map +1 -0
- package/dist/utils/mask.d.ts +8 -1
- package/dist/utils/mask.d.ts.map +1 -1
- package/dist/utils/mask.js +10 -12
- package/dist/utils/mask.js.map +1 -1
- package/dist/utils/observability.d.ts +22 -0
- package/dist/utils/observability.d.ts.map +1 -0
- package/dist/utils/observability.js +80 -0
- package/dist/utils/observability.js.map +1 -0
- package/dist/utils/token-estimate.d.ts +8 -0
- package/dist/utils/token-estimate.d.ts.map +1 -1
- package/dist/utils/token-estimate.js +30 -17
- package/dist/utils/token-estimate.js.map +1 -1
- package/package.json +8 -7
|
@@ -1,50 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.InkChatController = exports.AgentChatController = void 0;
|
|
37
|
-
exports.sessionMessagesToTranscriptEntries = sessionMessagesToTranscriptEntries;
|
|
38
|
-
exports.createAssistantStreamPresenter = createAssistantStreamPresenter;
|
|
39
|
-
exports.createToolEventPresenter = createToolEventPresenter;
|
|
3
|
+
exports.InkChatController = exports.AgentChatController = exports.sessionMessagesToTranscriptEntries = exports.createToolEventPresenter = exports.createAssistantStreamPresenter = void 0;
|
|
40
4
|
exports.loadSessionIntoRuntime = loadSessionIntoRuntime;
|
|
41
5
|
exports.closeSession = closeSession;
|
|
42
6
|
const commands_1 = require("../commands");
|
|
43
|
-
const
|
|
7
|
+
const crypto_1 = require("crypto");
|
|
44
8
|
const parser_1 = require("../commands/parser");
|
|
45
|
-
const path = __importStar(require("path"));
|
|
46
9
|
const session_storage_1 = require("../services/session-storage");
|
|
47
10
|
const config_1 = require("../services/config");
|
|
11
|
+
const provider_resilience_1 = require("../services/provider-resilience");
|
|
48
12
|
const tool_allowlist_1 = require("../services/tool-allowlist");
|
|
49
13
|
const framework_1 = require("../framework");
|
|
50
14
|
const prompt_1 = require("./goals/prompt");
|
|
@@ -52,928 +16,24 @@ const harness_1 = require("../harness");
|
|
|
52
16
|
const tools_1 = require("../tools");
|
|
53
17
|
const tool_serializer_1 = require("../framework/tool-serializer");
|
|
54
18
|
const tool_artifacts_1 = require("../core/tool-artifacts");
|
|
55
|
-
const checkpoint_1 = require("../core/checkpoint");
|
|
56
19
|
const skills_1 = require("../skills");
|
|
57
20
|
const subagents_1 = require("./subagents");
|
|
58
21
|
const file_context_1 = require("../services/file-context");
|
|
59
22
|
const prompt_context_1 = require("../services/prompt-context");
|
|
60
|
-
const format_1 = require("../services/format");
|
|
61
23
|
const workspace_state_1 = require("../services/workspace-state");
|
|
62
24
|
const verification_profile_1 = require("../services/verification-profile");
|
|
63
25
|
const ui_events_1 = require("./ui-events");
|
|
64
|
-
const ui_view_model_1 = require("./ui-view-model");
|
|
65
26
|
const agent_status_1 = require("./agent-status");
|
|
66
27
|
const loop_budget_1 = require("./loop-budget");
|
|
67
|
-
const
|
|
68
|
-
const
|
|
69
|
-
const
|
|
70
|
-
const
|
|
71
|
-
const
|
|
72
|
-
|
|
73
|
-
function
|
|
74
|
-
|
|
75
|
-
}
|
|
76
|
-
function isAbortError(error, abortSignal) {
|
|
77
|
-
if (abortSignal?.aborted)
|
|
78
|
-
return true;
|
|
79
|
-
if (error instanceof Error) {
|
|
80
|
-
return error.name === 'AbortError' || error.message.toLowerCase().includes('aborted');
|
|
81
|
-
}
|
|
82
|
-
return false;
|
|
83
|
-
}
|
|
84
|
-
function errorLayerForChatError(error) {
|
|
85
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
86
|
-
const lower = message.toLowerCase();
|
|
87
|
-
if (/NotEnoughCvError|code:\s*11210|provider|quota|rate.?limit|timeout|connection/i.test(message)) {
|
|
88
|
-
return 'provider';
|
|
89
|
-
}
|
|
90
|
-
if (/tool|command|exec_command|write_file|edit_file/i.test(message)) {
|
|
91
|
-
return 'tool';
|
|
92
|
-
}
|
|
93
|
-
if (/\bmcp\b/i.test(message))
|
|
94
|
-
return 'mcp';
|
|
95
|
-
if (/\b(session|resume|compact|harness)\b/i.test(message))
|
|
96
|
-
return 'session';
|
|
97
|
-
if (/\b(skill|skills)\b/i.test(message))
|
|
98
|
-
return 'skills';
|
|
99
|
-
if (/\b(memory|vector store|recall|forget)\b/i.test(message))
|
|
100
|
-
return 'memory';
|
|
101
|
-
if (/\b(renderer|terminal|tty|prompt|resize|scrollback)\b/i.test(message))
|
|
102
|
-
return 'renderer';
|
|
103
|
-
if (lower.includes('abort') || lower.includes('interrupted'))
|
|
104
|
-
return 'runtime';
|
|
105
|
-
return 'unknown';
|
|
106
|
-
}
|
|
107
|
-
function formatChatError(error) {
|
|
108
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
109
|
-
if (/NotEnoughCvError|code:\s*11210/i.test(message)) {
|
|
110
|
-
return [
|
|
111
|
-
message,
|
|
112
|
-
'',
|
|
113
|
-
'Provider quota or credit appears insufficient. The Orion Code session is still active; switch model/provider or recharge the provider account, then continue.',
|
|
114
|
-
].join('\n');
|
|
115
|
-
}
|
|
116
|
-
return message;
|
|
117
|
-
}
|
|
118
|
-
function compactMiddle(text, maxLength) {
|
|
119
|
-
const compact = text.replace(/\s+/g, ' ').trim();
|
|
120
|
-
if (compact.length <= maxLength)
|
|
121
|
-
return compact;
|
|
122
|
-
if (maxLength <= 3)
|
|
123
|
-
return compact.slice(0, maxLength);
|
|
124
|
-
const headLength = Math.ceil((maxLength - 3) * 0.55);
|
|
125
|
-
const tailLength = Math.floor((maxLength - 3) * 0.45);
|
|
126
|
-
return `${compact.slice(0, headLength)}...${compact.slice(-tailLength)}`;
|
|
127
|
-
}
|
|
128
|
-
function compactToolArgs(args, maxLength = 160) {
|
|
129
|
-
for (const key of [
|
|
130
|
-
'path',
|
|
131
|
-
'file_path',
|
|
132
|
-
'file',
|
|
133
|
-
'cwd',
|
|
134
|
-
'command',
|
|
135
|
-
'pattern',
|
|
136
|
-
'query',
|
|
137
|
-
'url',
|
|
138
|
-
'target',
|
|
139
|
-
'sessionId',
|
|
140
|
-
]) {
|
|
141
|
-
const value = args[key];
|
|
142
|
-
if (typeof value === 'string') {
|
|
143
|
-
return compactMiddle(value, maxLength);
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
const firstString = Object.values(args).find(value => typeof value === 'string');
|
|
147
|
-
if (typeof firstString === 'string') {
|
|
148
|
-
return compactMiddle(firstString, maxLength);
|
|
149
|
-
}
|
|
150
|
-
return '';
|
|
151
|
-
}
|
|
152
|
-
function fullToolArgsForTrace(name, args) {
|
|
153
|
-
if (name === 'exec_command' && typeof args.command === 'string') {
|
|
154
|
-
return `$ ${args.command}`;
|
|
155
|
-
}
|
|
156
|
-
try {
|
|
157
|
-
return JSON.stringify(args, null, 2);
|
|
158
|
-
}
|
|
159
|
-
catch {
|
|
160
|
-
return compactToolArgs(args, 2048);
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
function buildTraceArgsDetails(projectPath, name, args) {
|
|
164
|
-
const argsSummary = compactToolArgs(args);
|
|
165
|
-
const fullArgs = (0, session_storage_1.redactTraceText)(fullToolArgsForTrace(name, args)).trim();
|
|
166
|
-
const argsBytes = byteLength(fullArgs);
|
|
167
|
-
if (!projectPath ||
|
|
168
|
-
!fullArgs ||
|
|
169
|
-
fullArgs === (0, session_storage_1.redactTraceText)(argsSummary) ||
|
|
170
|
-
argsBytes <= TRACE_ARGS_ARTIFACT_THRESHOLD_BYTES) {
|
|
171
|
-
return { argsSummary };
|
|
172
|
-
}
|
|
173
|
-
const artifact = (0, tool_artifacts_1.storeArtifact)(projectPath, `${name}-args`, fullArgs, argsBytes);
|
|
174
|
-
return artifact ? { argsSummary, argsArtifactId: artifact.id, argsBytes } : { argsSummary };
|
|
175
|
-
}
|
|
176
|
-
function parseToolCallArgsForRuntime(toolCall) {
|
|
177
|
-
try {
|
|
178
|
-
const parsed = JSON.parse(toolCall.function.arguments || '{}');
|
|
179
|
-
return typeof parsed === 'object' && parsed !== null && !Array.isArray(parsed)
|
|
180
|
-
? parsed
|
|
181
|
-
: null;
|
|
182
|
-
}
|
|
183
|
-
catch {
|
|
184
|
-
return null;
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
function resolveProjectScopedPath(cwd, filePath) {
|
|
188
|
-
const absolute = path.resolve(cwd, filePath);
|
|
189
|
-
const relative = path.relative(cwd, absolute);
|
|
190
|
-
if (relative.startsWith('..') || path.isAbsolute(relative))
|
|
191
|
-
return null;
|
|
192
|
-
return absolute;
|
|
193
|
-
}
|
|
194
|
-
function checkpointTargetsFromToolCalls(cwd, toolCalls) {
|
|
195
|
-
const targets = new Set();
|
|
196
|
-
for (const toolCall of toolCalls) {
|
|
197
|
-
const name = toolCall.function.name;
|
|
198
|
-
if (name !== 'write_file' && name !== 'edit_file')
|
|
199
|
-
continue;
|
|
200
|
-
const args = parseToolCallArgsForRuntime(toolCall);
|
|
201
|
-
if (!args || typeof args.path !== 'string')
|
|
202
|
-
continue;
|
|
203
|
-
if (name === 'edit_file' && args.preview === true)
|
|
204
|
-
continue;
|
|
205
|
-
const target = resolveProjectScopedPath(cwd, args.path);
|
|
206
|
-
if (target)
|
|
207
|
-
targets.add(target);
|
|
208
|
-
}
|
|
209
|
-
return Array.from(targets);
|
|
210
|
-
}
|
|
211
|
-
function createPreToolCheckpoint(events, sessionId, turnId, checkpointId, cwd, toolCalls) {
|
|
212
|
-
const targets = checkpointTargetsFromToolCalls(cwd, toolCalls);
|
|
213
|
-
if (targets.length === 0)
|
|
214
|
-
return { created: false, targetCount: 0, risky: false };
|
|
215
|
-
const risky = (0, checkpoint_1.shouldCreateMultiFileCheckpoint)(targets.length);
|
|
216
|
-
const checkpoint = (0, checkpoint_1.createCheckpoint)(cwd, checkpointId, targets);
|
|
217
|
-
if (!sessionId)
|
|
218
|
-
return { created: true, targetCount: targets.length, risky };
|
|
219
|
-
const relativeTargets = targets.map(target => path.relative(cwd, target));
|
|
220
|
-
recordTraceEvent(events, sessionId, {
|
|
221
|
-
turnId,
|
|
222
|
-
type: 'checkpoint',
|
|
223
|
-
checkpointId,
|
|
224
|
-
checkpointFileCount: checkpoint?.files.length ?? 0,
|
|
225
|
-
checkpointFiles: checkpoint?.files.map(file => file.path) ?? [],
|
|
226
|
-
workspaceFiles: relativeTargets,
|
|
227
|
-
note: checkpoint
|
|
228
|
-
? risky
|
|
229
|
-
? 'risky_multi_file_checkpoint'
|
|
230
|
-
: 'pre_edit_checkpoint'
|
|
231
|
-
: 'pre_edit_checkpoint_skipped',
|
|
232
|
-
});
|
|
233
|
-
return { created: true, targetCount: targets.length, risky };
|
|
234
|
-
}
|
|
235
|
-
function byteLength(text) {
|
|
236
|
-
return Buffer.byteLength(text, 'utf8');
|
|
237
|
-
}
|
|
238
|
-
function traceTurnId(turnId) {
|
|
239
|
-
return turnId == null ? `turn-${Date.now()}` : String(turnId);
|
|
240
|
-
}
|
|
241
|
-
function compactTraceError(error) {
|
|
242
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
243
|
-
return compactMiddle(message, 240);
|
|
244
|
-
}
|
|
245
|
-
function getLastRequestDiagnostics(llm) {
|
|
246
|
-
if (!llm)
|
|
247
|
-
return undefined;
|
|
248
|
-
const reader = llm.getLastRequestDiagnostics;
|
|
249
|
-
return typeof reader === 'function' ? reader.call(llm) : undefined;
|
|
250
|
-
}
|
|
251
|
-
function compactPathList(paths, maxItems = 40) {
|
|
252
|
-
return paths.slice(0, maxItems);
|
|
253
|
-
}
|
|
254
|
-
function formatWorkspaceFileForTrace(file) {
|
|
255
|
-
const metadata = [
|
|
256
|
-
typeof file.sizeBytes === 'number' ? `${file.sizeBytes}B` : '',
|
|
257
|
-
typeof file.mtimeMs === 'number' ? `mtime=${file.mtimeMs}` : '',
|
|
258
|
-
]
|
|
259
|
-
.filter(Boolean)
|
|
260
|
-
.join(' ');
|
|
261
|
-
return `${file.status} ${file.path}${metadata ? ` (${metadata})` : ''}`;
|
|
262
|
-
}
|
|
263
|
-
function appendWorkspaceSnapshotTrace(events, sessionId, turnId, phase, snapshot) {
|
|
264
|
-
if (!sessionId)
|
|
265
|
-
return;
|
|
266
|
-
recordTraceEvent(events, sessionId, {
|
|
267
|
-
turnId,
|
|
268
|
-
type: 'workspace_snapshot',
|
|
269
|
-
workspacePhase: phase,
|
|
270
|
-
workspaceGitAvailable: snapshot.gitAvailable,
|
|
271
|
-
workspaceDirty: snapshot.dirty,
|
|
272
|
-
workspaceBranch: snapshot.branch,
|
|
273
|
-
workspaceFileCount: snapshot.fileCount,
|
|
274
|
-
workspaceFiles: compactPathList(snapshot.files.map(formatWorkspaceFileForTrace)),
|
|
275
|
-
error: snapshot.error ? compactMiddle(snapshot.error, 240) : undefined,
|
|
276
|
-
});
|
|
277
|
-
}
|
|
278
|
-
function appendWorkspaceDeltaTrace(events, sessionId, turnId, before, after) {
|
|
279
|
-
const delta = (0, workspace_state_1.diffWorkspaceSnapshots)(before, after);
|
|
280
|
-
if (sessionId) {
|
|
281
|
-
recordTraceEvent(events, sessionId, {
|
|
282
|
-
turnId,
|
|
283
|
-
type: 'workspace_delta',
|
|
284
|
-
workspaceFileCount: delta.filesAfterTurn.length,
|
|
285
|
-
workspaceFiles: compactPathList(delta.filesAfterTurn),
|
|
286
|
-
workspaceNewByTurn: compactPathList(delta.newFilesByTurn),
|
|
287
|
-
workspaceChangedByTurn: compactPathList(delta.changedByTurn),
|
|
288
|
-
workspaceModifiedPreExistingByTurn: compactPathList(delta.modifiedPreExistingByTurn),
|
|
289
|
-
workspaceResolvedByTurn: compactPathList(delta.resolvedByTurn),
|
|
290
|
-
note: `pre_existing=${delta.preExistingFiles.length}`,
|
|
291
|
-
});
|
|
292
|
-
}
|
|
293
|
-
return delta;
|
|
294
|
-
}
|
|
295
|
-
function workspaceDeltaHasTurnChanges(delta) {
|
|
296
|
-
return (delta.newFilesByTurn.length > 0 ||
|
|
297
|
-
delta.changedByTurn.length > 0 ||
|
|
298
|
-
delta.resolvedByTurn.length > 0);
|
|
299
|
-
}
|
|
300
|
-
function formatFailureRecoveryNotice(turnId, delta, checkpointIds) {
|
|
301
|
-
const files = compactPathList([...delta.newFilesByTurn, ...delta.changedByTurn, ...delta.resolvedByTurn], 8);
|
|
302
|
-
const fileText = files.length > 0 ? files.join(', ') : 'workspace changes recorded';
|
|
303
|
-
const checkpointText = checkpointIds.length > 0
|
|
304
|
-
? ` Checkpoints: ${checkpointIds.join(', ')}. Preview rollback with /checkpoint restore <id>; restore each listed checkpoint if multiple.`
|
|
305
|
-
: '';
|
|
306
|
-
return `Turn failed after modifying files: ${fileText}. Inspect /trace ${turnId}.${checkpointText}`;
|
|
307
|
-
}
|
|
308
|
-
function appendVerificationProfileTrace(events, sessionId, turnId, profile) {
|
|
309
|
-
if (!sessionId || profile.changedFiles.length === 0)
|
|
310
|
-
return;
|
|
311
|
-
recordTraceEvent(events, sessionId, {
|
|
312
|
-
turnId,
|
|
313
|
-
type: 'verification_profile',
|
|
314
|
-
verificationProfile: profile.profile,
|
|
315
|
-
verificationRequired: profile.required,
|
|
316
|
-
verificationRisky: (0, verification_profile_1.isRiskyEdit)(profile.changedFiles),
|
|
317
|
-
verificationCommands: compactPathList(profile.commands, 8),
|
|
318
|
-
verificationChangedFiles: compactPathList(profile.changedFiles),
|
|
319
|
-
note: profile.reason,
|
|
320
|
-
});
|
|
321
|
-
}
|
|
322
|
-
function appendVerificationResultTrace(events, sessionId, turnId, result) {
|
|
323
|
-
if (!sessionId)
|
|
324
|
-
return;
|
|
325
|
-
recordTraceEvent(events, sessionId, {
|
|
326
|
-
turnId,
|
|
327
|
-
type: 'verification_result',
|
|
328
|
-
verificationCommand: result.command,
|
|
329
|
-
verificationPassed: result.success,
|
|
330
|
-
outputBytes: result.outputBytes,
|
|
331
|
-
error: result.error ? compactMiddle(result.error, 240) : undefined,
|
|
332
|
-
});
|
|
333
|
-
}
|
|
334
|
-
function appendVerificationSummaryTrace(events, sessionId, turnId, summary, changedFiles) {
|
|
335
|
-
if (!sessionId || changedFiles.length === 0)
|
|
336
|
-
return;
|
|
337
|
-
recordTraceEvent(events, sessionId, {
|
|
338
|
-
turnId,
|
|
339
|
-
type: 'verification_summary',
|
|
340
|
-
verificationProfile: summary.profile,
|
|
341
|
-
verificationRequired: summary.required,
|
|
342
|
-
verificationCommands: compactPathList(summary.commandsRun, 12),
|
|
343
|
-
verificationPassedCommands: compactPathList(summary.passedCommands, 12),
|
|
344
|
-
verificationFailedCommands: compactPathList(summary.failedCommands, 12),
|
|
345
|
-
verificationMissingCommands: compactPathList(summary.missingCommands, 12),
|
|
346
|
-
verificationChangedFiles: compactPathList(changedFiles),
|
|
347
|
-
verificationClaimAllowed: summary.claimAllowed,
|
|
348
|
-
note: summary.skippedReason,
|
|
349
|
-
});
|
|
350
|
-
}
|
|
351
|
-
function compactVerificationCommands(commands, maxItems = 12) {
|
|
352
|
-
return commands.slice(0, maxItems).map(session_storage_1.redactTraceText);
|
|
353
|
-
}
|
|
354
|
-
function withVerificationLoopStats(stats, summary) {
|
|
355
|
-
return {
|
|
356
|
-
...stats,
|
|
357
|
-
verificationProfile: summary.profile,
|
|
358
|
-
verificationRequired: summary.required,
|
|
359
|
-
verificationClaimAllowed: summary.claimAllowed,
|
|
360
|
-
verificationPassedCommands: compactVerificationCommands(summary.passedCommands),
|
|
361
|
-
verificationFailedCommands: compactVerificationCommands(summary.failedCommands),
|
|
362
|
-
verificationMissingCommands: compactVerificationCommands(summary.missingCommands),
|
|
363
|
-
verificationSkippedReason: summary.skippedReason
|
|
364
|
-
? (0, session_storage_1.redactTraceText)(summary.skippedReason)
|
|
365
|
-
: undefined,
|
|
366
|
-
};
|
|
367
|
-
}
|
|
368
|
-
function shouldRecordVerificationLoopStats(profile, summary) {
|
|
369
|
-
return (profile.changedFiles.length > 0 ||
|
|
370
|
-
summary.commandsRun.length > 0 ||
|
|
371
|
-
summary.passedCommands.length > 0 ||
|
|
372
|
-
summary.failedCommands.length > 0 ||
|
|
373
|
-
summary.missingCommands.length > 0);
|
|
374
|
-
}
|
|
375
|
-
function appendPostWorkspaceTrace(events, sessionId, turnId, cwd, before, verificationResults = []) {
|
|
376
|
-
const postWorkspace = (0, workspace_state_1.captureWorkspaceSnapshot)(cwd);
|
|
377
|
-
appendWorkspaceSnapshotTrace(events, sessionId, turnId, 'post_turn', postWorkspace);
|
|
378
|
-
const delta = appendWorkspaceDeltaTrace(events, sessionId, turnId, before, postWorkspace);
|
|
379
|
-
const profile = (0, verification_profile_1.selectVerificationProfile)(cwd, delta.changedByTurn);
|
|
380
|
-
const summary = (0, verification_profile_1.summarizeVerificationState)(profile, verificationResults);
|
|
381
|
-
appendVerificationProfileTrace(events, sessionId, turnId, profile);
|
|
382
|
-
appendVerificationSummaryTrace(events, sessionId, turnId, summary, profile.changedFiles);
|
|
383
|
-
return { delta, profile, summary };
|
|
384
|
-
}
|
|
385
|
-
function appendAssistantNotice(messages, notice) {
|
|
386
|
-
for (let index = messages.length - 1; index >= 0; index--) {
|
|
387
|
-
const message = messages[index];
|
|
388
|
-
if (message.role === 'assistant' && !message.tool_calls) {
|
|
389
|
-
message.content = message.content ? `${message.content}\n\n${notice}` : notice;
|
|
390
|
-
return;
|
|
391
|
-
}
|
|
392
|
-
}
|
|
393
|
-
messages.push({
|
|
394
|
-
role: 'assistant',
|
|
395
|
-
content: notice,
|
|
396
|
-
timestamp: Date.now(),
|
|
397
|
-
});
|
|
398
|
-
}
|
|
399
|
-
function recordTraceEvent(events, sessionId, event) {
|
|
400
|
-
if (!sessionId)
|
|
401
|
-
return null;
|
|
402
|
-
const goal = goalTraceContext.getStore();
|
|
403
|
-
const traceEvent = (0, session_storage_1.appendSessionTraceEvent)(sessionId, {
|
|
404
|
-
...event,
|
|
405
|
-
goalId: goal?.goalId,
|
|
406
|
-
goalRevision: goal?.goalRevision,
|
|
407
|
-
goalInputKind: goal?.goalInputKind,
|
|
408
|
-
goalStopReason: goal?.getStopReason(),
|
|
409
|
-
});
|
|
410
|
-
if (traceEvent) {
|
|
411
|
-
events.traceEventRecorded?.(traceEvent);
|
|
412
|
-
}
|
|
413
|
-
return traceEvent;
|
|
414
|
-
}
|
|
415
|
-
function recordProviderTraceEvents(events, sessionId, turnId, stats) {
|
|
416
|
-
if ((stats.providerRetryCount ?? 0) > 0) {
|
|
417
|
-
recordTraceEvent(events, sessionId, {
|
|
418
|
-
turnId,
|
|
419
|
-
type: 'provider_retry',
|
|
420
|
-
providerRetryCount: stats.providerRetryCount,
|
|
421
|
-
providerRetryDelayMs: stats.providerRetryDelayMs,
|
|
422
|
-
providerRetryErrorTypes: stats.providerRetryErrorTypes,
|
|
423
|
-
providerLastRetryErrorType: stats.providerLastRetryErrorType,
|
|
424
|
-
providerLastRetryStatus: stats.providerLastRetryStatus,
|
|
425
|
-
providerFinalModel: stats.providerFinalModel,
|
|
426
|
-
providerUsingFallback: stats.providerUsingFallback,
|
|
427
|
-
});
|
|
428
|
-
}
|
|
429
|
-
if ((stats.providerFallbackCount ?? 0) > 0 || stats.providerUsingFallback) {
|
|
430
|
-
recordTraceEvent(events, sessionId, {
|
|
431
|
-
turnId,
|
|
432
|
-
type: 'provider_fallback',
|
|
433
|
-
providerFallbackCount: stats.providerFallbackCount,
|
|
434
|
-
providerFallbackFromModel: stats.providerFallbackFromModel,
|
|
435
|
-
providerFallbackToModel: stats.providerFallbackToModel,
|
|
436
|
-
providerFinalModel: stats.providerFinalModel,
|
|
437
|
-
providerUsingFallback: stats.providerUsingFallback,
|
|
438
|
-
});
|
|
439
|
-
}
|
|
440
|
-
}
|
|
441
|
-
function toHarnessDiagnostics(state) {
|
|
442
|
-
const stats = state.promptAssemblyStats;
|
|
443
|
-
const redactOptional = (value) => typeof value === 'string' ? (0, session_storage_1.redactTraceText)(value) : undefined;
|
|
444
|
-
const redactList = (values) => values?.slice(0, 6).map(session_storage_1.redactTraceText);
|
|
445
|
-
return {
|
|
446
|
-
taskEpoch: state.taskEpoch,
|
|
447
|
-
rootObjective: redactOptional(state.rootObjective ?? state.contract?.objective),
|
|
448
|
-
activeInstruction: redactOptional(state.activeInstruction ?? state.contract?.userIntent),
|
|
449
|
-
openQuestions: redactList(state.openQuestions),
|
|
450
|
-
diagnostics: redactList(state.diagnostics?.slice(-6)),
|
|
451
|
-
ledgerSize: state.ledger?.length ?? 0,
|
|
452
|
-
evidenceSize: state.evidenceIndex?.length ?? 0,
|
|
453
|
-
turnSummaryCount: state.turnSummaries?.length ?? 0,
|
|
454
|
-
promptAssembly: stats
|
|
455
|
-
? {
|
|
456
|
-
modelId: stats.modelId,
|
|
457
|
-
estimatedTokens: stats.estimatedTokens,
|
|
458
|
-
budgetTokens: stats.budgetTokens,
|
|
459
|
-
sections: stats.sections.slice(0, 12),
|
|
460
|
-
includedEvidence: stats.includedEvidence.length,
|
|
461
|
-
omittedEvidence: stats.omittedEvidence.length,
|
|
462
|
-
}
|
|
463
|
-
: undefined,
|
|
464
|
-
};
|
|
465
|
-
}
|
|
466
|
-
function emitHarnessDiagnostics(events, state) {
|
|
467
|
-
events.harnessDiagnosticsUpdated?.(toHarnessDiagnostics(state));
|
|
468
|
-
}
|
|
469
|
-
function toolStartContent(event) {
|
|
470
|
-
return (0, ui_view_model_1.formatToolActivityTranscript)((0, ui_view_model_1.toolActivityFromStarted)(event, compactToolArgs(event.args, TOOL_TRANSCRIPT_ARG_BUDGET)));
|
|
471
|
-
}
|
|
472
|
-
function toolFinishContent(event) {
|
|
473
|
-
return (0, ui_view_model_1.formatToolActivityTranscript)((0, ui_view_model_1.toolActivityFromFinished)(event, compactToolArgs(event.args, TOOL_TRANSCRIPT_ARG_BUDGET)));
|
|
474
|
-
}
|
|
475
|
-
function structuredToolStartActivity(event, seq) {
|
|
476
|
-
const command = event.name === 'exec_command' && typeof event.args.command === 'string'
|
|
477
|
-
? event.args.command
|
|
478
|
-
: undefined;
|
|
479
|
-
const safeCommand = command ? (0, session_storage_1.redactTraceText)(command) : undefined;
|
|
480
|
-
return {
|
|
481
|
-
state: 'running',
|
|
482
|
-
name: event.name,
|
|
483
|
-
detail: command ? '' : (0, session_storage_1.redactTraceText)(compactToolArgs(event.args, TOOL_TRANSCRIPT_ARG_BUDGET)),
|
|
484
|
-
command: safeCommand,
|
|
485
|
-
body: '',
|
|
486
|
-
seq,
|
|
487
|
-
};
|
|
488
|
-
}
|
|
489
|
-
function structuredToolFinishActivity(event, seq, options = {}) {
|
|
490
|
-
const modelVisible = (0, tool_serializer_1.parseToolResultEnvelope)(event.modelVisibleResult);
|
|
491
|
-
const durable = (0, tool_serializer_1.parseToolResultEnvelope)(event.result);
|
|
492
|
-
const durableOutput = typeof durable.output === 'string' ? durable.output : '';
|
|
493
|
-
const displayOutput = typeof modelVisible.output === 'string' ? modelVisible.output : durableOutput;
|
|
494
|
-
const outputBytes = event.outputBytes ?? Buffer.byteLength(durableOutput, 'utf8');
|
|
495
|
-
const aggregatePresentation = (0, aggregate_tool_presenter_1.presentAggregateToolResult)(event.name, durableOutput, outputBytes);
|
|
496
|
-
const aggregate = aggregatePresentation?.view;
|
|
497
|
-
const storedArtifact = event.artifactRef ??
|
|
498
|
-
(options.projectPath &&
|
|
499
|
-
durableOutput &&
|
|
500
|
-
(outputBytes > tool_output_presentation_1.DEFAULT_TOOL_OUTPUT_POLICY.inlineMaxBytes || aggregate)
|
|
501
|
-
? ((0, tool_artifacts_1.storeArtifact)(options.projectPath, event.name, durableOutput, outputBytes) ?? undefined)
|
|
502
|
-
: undefined);
|
|
503
|
-
const artifactRef = storedArtifact
|
|
504
|
-
? { id: storedArtifact.id, outputBytes: storedArtifact.outputBytes }
|
|
505
|
-
: undefined;
|
|
506
|
-
const outputView = (0, tool_output_presentation_1.createToolOutputView)({
|
|
507
|
-
toolName: event.name,
|
|
508
|
-
success: event.success,
|
|
509
|
-
summary: event.summary,
|
|
510
|
-
rawOutput: durableOutput.length <= 64 * 1024 ? durableOutput : displayOutput,
|
|
511
|
-
outputBytes,
|
|
512
|
-
artifactRef,
|
|
513
|
-
callId: event.callId,
|
|
514
|
-
sequence: seq,
|
|
515
|
-
turnId: options.turnId,
|
|
516
|
-
policy: tool_output_presentation_1.DEFAULT_TOOL_OUTPUT_POLICY,
|
|
517
|
-
});
|
|
518
|
-
if (aggregate) {
|
|
519
|
-
outputView.aggregate = {
|
|
520
|
-
...aggregate,
|
|
521
|
-
steps: aggregate.steps.map(step => ({ ...step, detailRef: outputView.detailRef })),
|
|
522
|
-
};
|
|
523
|
-
}
|
|
524
|
-
const command = event.name === 'exec_command' && typeof event.args.command === 'string'
|
|
525
|
-
? event.args.command
|
|
526
|
-
: undefined;
|
|
527
|
-
const safeCommand = command ? (0, session_storage_1.redactTraceText)(command) : undefined;
|
|
528
|
-
return {
|
|
529
|
-
state: event.success ? 'success' : 'error',
|
|
530
|
-
name: event.name,
|
|
531
|
-
detail: command ? '' : (0, session_storage_1.redactTraceText)(compactToolArgs(event.args, TOOL_TRANSCRIPT_ARG_BUDGET)),
|
|
532
|
-
command: safeCommand,
|
|
533
|
-
duration: `${event.duration}ms`,
|
|
534
|
-
summary: event.summary ? (0, session_storage_1.redactTraceText)(event.summary.split(/\r?\n/u, 1)[0]) : undefined,
|
|
535
|
-
outputBytes,
|
|
536
|
-
body: (0, session_storage_1.redactTraceText)(modelVisible.output),
|
|
537
|
-
error: event.error ? (0, session_storage_1.redactTraceText)(event.error) : undefined,
|
|
538
|
-
seq,
|
|
539
|
-
artifactHint: artifactRef ? `/artifacts show ${artifactRef.id} --full` : undefined,
|
|
540
|
-
callId: event.callId,
|
|
541
|
-
turnId: options.turnId,
|
|
542
|
-
outputView,
|
|
543
|
-
};
|
|
544
|
-
}
|
|
545
|
-
function isSyntheticCompactContext(content) {
|
|
546
|
-
return (content.startsWith('[Orion Code Context State v2]') ||
|
|
547
|
-
content.startsWith('[Context Summary]') ||
|
|
548
|
-
content.startsWith('I will continue from this Orion Code Context State') ||
|
|
549
|
-
content.startsWith('I understand the context. I will continue the conversation with this background information.'));
|
|
550
|
-
}
|
|
551
|
-
function sessionToolCallSummaries(message) {
|
|
552
|
-
return (message.tool_calls ?? []).map(call => {
|
|
553
|
-
const args = parseToolCallArgs(call.function.arguments);
|
|
554
|
-
const detail = compactToolArgs(args);
|
|
555
|
-
return {
|
|
556
|
-
id: call.id,
|
|
557
|
-
content: `Requested ${call.function.name}${detail ? ` ${detail}` : ''}`,
|
|
558
|
-
};
|
|
559
|
-
});
|
|
560
|
-
}
|
|
561
|
-
function parseToolCallArgs(rawArgs) {
|
|
562
|
-
try {
|
|
563
|
-
return rawArgs ? JSON.parse(rawArgs) : {};
|
|
564
|
-
}
|
|
565
|
-
catch {
|
|
566
|
-
return rawArgs ? { arguments: rawArgs } : {};
|
|
567
|
-
}
|
|
568
|
-
}
|
|
569
|
-
function parseSessionToolResult(content) {
|
|
570
|
-
try {
|
|
571
|
-
const parsed = JSON.parse(content);
|
|
572
|
-
return {
|
|
573
|
-
success: parsed.success === true,
|
|
574
|
-
error: typeof parsed.error === 'string' ? parsed.error : undefined,
|
|
575
|
-
summary: typeof parsed.summary === 'string' ? parsed.summary : undefined,
|
|
576
|
-
};
|
|
577
|
-
}
|
|
578
|
-
catch {
|
|
579
|
-
return { success: false, error: 'Invalid JSON result' };
|
|
580
|
-
}
|
|
581
|
-
}
|
|
582
|
-
function removeTrailingUserMessage(runtime) {
|
|
583
|
-
const history = runtime.store.getSnapshot().conversationHistory;
|
|
584
|
-
if (history.length === 0)
|
|
585
|
-
return;
|
|
586
|
-
const lastMsg = history[history.length - 1];
|
|
587
|
-
if (lastMsg?.role === 'user') {
|
|
588
|
-
runtime.store.setState({ conversationHistory: history.slice(0, -1) });
|
|
589
|
-
}
|
|
590
|
-
}
|
|
591
|
-
function sessionToolResultSummary(message, toolCallsById) {
|
|
592
|
-
if (!message.toolCallId)
|
|
593
|
-
return null;
|
|
594
|
-
const call = toolCallsById.get(message.toolCallId);
|
|
595
|
-
if (!call)
|
|
596
|
-
return null;
|
|
597
|
-
const args = parseToolCallArgs(call.function.arguments);
|
|
598
|
-
const detail = compactToolArgs(args);
|
|
599
|
-
const parsed = parseSessionToolResult(message.content);
|
|
600
|
-
const firstLine = parsed.summary ||
|
|
601
|
-
`${parsed.success ? '✓' : '✗'} ${call.function.name}${detail ? ` ${detail}` : ''}`;
|
|
602
|
-
return parsed.error ? `${firstLine}\nError: ${parsed.error}` : firstLine;
|
|
603
|
-
}
|
|
604
|
-
function sessionMessagesToTranscriptEntries(sessionId, options = {}) {
|
|
605
|
-
const messages = (0, session_storage_1.loadSessionTranscriptMessages)(sessionId);
|
|
606
|
-
const resultTraces = options.includeToolOutputViews
|
|
607
|
-
? (0, session_storage_1.readSessionTraceEvents)(sessionId).filter(trace => trace.type === 'tool_result' && trace.callId)
|
|
608
|
-
: [];
|
|
609
|
-
const resultTraceByCallId = new Map(resultTraces.map(trace => [trace.callId, trace]));
|
|
610
|
-
const sequenceByCallId = new Map();
|
|
611
|
-
resultTraces.forEach((trace, index) => {
|
|
612
|
-
if (!sequenceByCallId.has(trace.callId))
|
|
613
|
-
sequenceByCallId.set(trace.callId, index + 1);
|
|
614
|
-
});
|
|
615
|
-
const entries = [];
|
|
616
|
-
const toolCallsById = new Map();
|
|
617
|
-
const completedToolCallIds = new Set();
|
|
618
|
-
let fallbackToolSequence = 0;
|
|
619
|
-
for (const message of messages) {
|
|
620
|
-
for (const call of message.tool_calls ?? []) {
|
|
621
|
-
toolCallsById.set(call.id, call);
|
|
622
|
-
}
|
|
623
|
-
if (message.role === 'tool' && message.toolCallId) {
|
|
624
|
-
completedToolCallIds.add(message.toolCallId);
|
|
625
|
-
}
|
|
626
|
-
}
|
|
627
|
-
messages.forEach((message, index) => {
|
|
628
|
-
if (isSyntheticCompactContext(message.content))
|
|
629
|
-
return;
|
|
630
|
-
const idBase = `session-${sessionId.slice(0, 8)}-${index}`;
|
|
631
|
-
if (message.role === 'user') {
|
|
632
|
-
entries.push({ id: `${idBase}-user`, role: 'user', content: message.content });
|
|
633
|
-
return;
|
|
634
|
-
}
|
|
635
|
-
if (message.role === 'assistant') {
|
|
636
|
-
if (message.content?.trim()) {
|
|
637
|
-
entries.push({ id: `${idBase}-assistant`, role: 'assistant', content: message.content });
|
|
638
|
-
}
|
|
639
|
-
for (const summary of sessionToolCallSummaries(message)) {
|
|
640
|
-
if (!completedToolCallIds.has(summary.id)) {
|
|
641
|
-
entries.push({
|
|
642
|
-
id: `${idBase}-tool-call-${entries.length}`,
|
|
643
|
-
role: 'tool',
|
|
644
|
-
content: summary.content,
|
|
645
|
-
});
|
|
646
|
-
}
|
|
647
|
-
}
|
|
648
|
-
return;
|
|
649
|
-
}
|
|
650
|
-
if (message.role === 'tool') {
|
|
651
|
-
const summary = sessionToolResultSummary(message, toolCallsById);
|
|
652
|
-
const call = message.toolCallId ? toolCallsById.get(message.toolCallId) : undefined;
|
|
653
|
-
const trace = message.toolCallId ? resultTraceByCallId.get(message.toolCallId) : undefined;
|
|
654
|
-
const durable = (0, tool_serializer_1.parseToolResultEnvelope)(message.content);
|
|
655
|
-
const modelVisible = message.modelVisibleContent
|
|
656
|
-
? (0, tool_serializer_1.parseToolResultEnvelope)(message.modelVisibleContent)
|
|
657
|
-
: durable;
|
|
658
|
-
const durableOutput = typeof durable.output === 'string' ? durable.output : '';
|
|
659
|
-
const displayOutput = typeof modelVisible.output === 'string' ? modelVisible.output : durableOutput;
|
|
660
|
-
const outputBytes = trace?.outputBytes ??
|
|
661
|
-
(durable.schemaVersion === 1 ? durable.outputBytes : undefined) ??
|
|
662
|
-
Buffer.byteLength(durableOutput, 'utf8');
|
|
663
|
-
const artifactId = durable.artifactRef?.id ?? trace?.artifactId;
|
|
664
|
-
fallbackToolSequence += 1;
|
|
665
|
-
const sequence = message.toolCallId
|
|
666
|
-
? (sequenceByCallId.get(message.toolCallId) ?? fallbackToolSequence)
|
|
667
|
-
: fallbackToolSequence;
|
|
668
|
-
const outputView = options.includeToolOutputViews && call && message.toolCallId
|
|
669
|
-
? (0, tool_output_presentation_1.createToolOutputView)({
|
|
670
|
-
toolName: call.function.name,
|
|
671
|
-
success: durable.success,
|
|
672
|
-
summary: durable.summary,
|
|
673
|
-
rawOutput: durableOutput.length <= 64 * 1024 ? durableOutput : displayOutput,
|
|
674
|
-
outputBytes,
|
|
675
|
-
artifactRef: artifactId ? { id: artifactId, outputBytes } : undefined,
|
|
676
|
-
callId: message.toolCallId,
|
|
677
|
-
sequence,
|
|
678
|
-
turnId: trace?.turnId,
|
|
679
|
-
policy: tool_output_presentation_1.DEFAULT_TOOL_OUTPUT_POLICY,
|
|
680
|
-
})
|
|
681
|
-
: undefined;
|
|
682
|
-
entries.push({
|
|
683
|
-
id: `${idBase}-tool`,
|
|
684
|
-
role: 'tool',
|
|
685
|
-
content: summary ??
|
|
686
|
-
(message.toolCallId
|
|
687
|
-
? `Tool result ${message.toolCallId}\n${message.content}`
|
|
688
|
-
: message.content),
|
|
689
|
-
toolActivity: call && message.toolCallId && outputView
|
|
690
|
-
? {
|
|
691
|
-
state: durable.success ? 'success' : 'error',
|
|
692
|
-
name: call.function.name,
|
|
693
|
-
detail: (0, session_storage_1.redactTraceText)(compactToolArgs(parseToolCallArgs(call.function.arguments))),
|
|
694
|
-
summary: durable.summary
|
|
695
|
-
? (0, session_storage_1.redactTraceText)(durable.summary.split(/\r?\n/u, 1)[0])
|
|
696
|
-
: undefined,
|
|
697
|
-
outputBytes,
|
|
698
|
-
body: (0, session_storage_1.redactTraceText)(durableOutput.length <= 64 * 1024 ? durableOutput : displayOutput),
|
|
699
|
-
error: durable.error ? (0, session_storage_1.redactTraceText)(durable.error) : undefined,
|
|
700
|
-
duration: typeof trace?.duration === 'number' ? `${trace.duration}ms` : undefined,
|
|
701
|
-
seq: sequence,
|
|
702
|
-
artifactHint: artifactId ? `/artifacts show ${artifactId} --full` : undefined,
|
|
703
|
-
callId: message.toolCallId,
|
|
704
|
-
turnId: trace?.turnId,
|
|
705
|
-
outputView,
|
|
706
|
-
}
|
|
707
|
-
: undefined,
|
|
708
|
-
});
|
|
709
|
-
return;
|
|
710
|
-
}
|
|
711
|
-
if (message.role === 'system') {
|
|
712
|
-
entries.push({ id: `${idBase}-system`, role: 'system', content: message.content });
|
|
713
|
-
}
|
|
714
|
-
});
|
|
715
|
-
return entries;
|
|
716
|
-
}
|
|
717
|
-
function createAssistantStreamPresenter(events, abortSignal) {
|
|
718
|
-
let activeSegmentText = '';
|
|
719
|
-
let activeEntryId = null;
|
|
720
|
-
const ensureLiveEntry = () => {
|
|
721
|
-
if (abortSignal?.aborted || !activeSegmentText)
|
|
722
|
-
return null;
|
|
723
|
-
if (activeEntryId) {
|
|
724
|
-
events.update(activeEntryId, { content: activeSegmentText });
|
|
725
|
-
return activeEntryId;
|
|
726
|
-
}
|
|
727
|
-
activeEntryId = events.append({
|
|
728
|
-
role: 'assistant',
|
|
729
|
-
content: activeSegmentText,
|
|
730
|
-
live: true,
|
|
731
|
-
});
|
|
732
|
-
return activeEntryId;
|
|
733
|
-
};
|
|
734
|
-
const flushSegment = () => {
|
|
735
|
-
if (abortSignal?.aborted) {
|
|
736
|
-
if (activeEntryId)
|
|
737
|
-
events.remove(activeEntryId);
|
|
738
|
-
activeEntryId = null;
|
|
739
|
-
activeSegmentText = '';
|
|
740
|
-
return;
|
|
741
|
-
}
|
|
742
|
-
const entryId = ensureLiveEntry();
|
|
743
|
-
if (!entryId)
|
|
744
|
-
return;
|
|
745
|
-
events.finalize(entryId);
|
|
746
|
-
activeEntryId = null;
|
|
747
|
-
activeSegmentText = '';
|
|
748
|
-
};
|
|
749
|
-
return {
|
|
750
|
-
appendChunk(chunk) {
|
|
751
|
-
if (abortSignal?.aborted || !chunk)
|
|
752
|
-
return;
|
|
753
|
-
activeSegmentText += chunk;
|
|
754
|
-
ensureLiveEntry();
|
|
755
|
-
},
|
|
756
|
-
closeSegment() {
|
|
757
|
-
flushSegment();
|
|
758
|
-
},
|
|
759
|
-
discardSegment() {
|
|
760
|
-
if (activeEntryId)
|
|
761
|
-
events.remove(activeEntryId);
|
|
762
|
-
activeEntryId = null;
|
|
763
|
-
activeSegmentText = '';
|
|
764
|
-
},
|
|
765
|
-
ensureMessage(content) {
|
|
766
|
-
if (abortSignal?.aborted || !content || activeSegmentText.length > 0)
|
|
767
|
-
return;
|
|
768
|
-
activeSegmentText = content;
|
|
769
|
-
ensureLiveEntry();
|
|
770
|
-
},
|
|
771
|
-
replaceMessage(content) {
|
|
772
|
-
if (abortSignal?.aborted || !content)
|
|
773
|
-
return;
|
|
774
|
-
activeSegmentText = content;
|
|
775
|
-
ensureLiveEntry();
|
|
776
|
-
},
|
|
777
|
-
};
|
|
778
|
-
}
|
|
779
|
-
const goalTraceContext = new async_hooks_1.AsyncLocalStorage();
|
|
780
|
-
class LocalFastPathBlockedError extends Error {
|
|
781
|
-
constructor(message) {
|
|
782
|
-
super(message);
|
|
783
|
-
this.name = 'LocalFastPathBlockedError';
|
|
784
|
-
}
|
|
785
|
-
}
|
|
786
|
-
function parseLocalFastPath(input) {
|
|
787
|
-
const text = input.trim();
|
|
788
|
-
if (/^git\s+status$/i.test(text)) {
|
|
789
|
-
return { tool: 'git_status', args: {}, label: 'git status' };
|
|
790
|
-
}
|
|
791
|
-
const readMatch = /^(?:read|读取)\s+(.+)$/i.exec(text);
|
|
792
|
-
const readTarget = readMatch?.[1]?.trim();
|
|
793
|
-
const looksLikePath = Boolean(readTarget) &&
|
|
794
|
-
!/\s/.test(readTarget) &&
|
|
795
|
-
(/[/\\.]/.test(readTarget) || readTarget.startsWith('~'));
|
|
796
|
-
if (readTarget && looksLikePath) {
|
|
797
|
-
return { tool: 'read_file', args: { path: readTarget }, label: `read ${readTarget}` };
|
|
798
|
-
}
|
|
799
|
-
const grepMatch = /^(?:grep|搜索)\s+(.+)$/i.exec(text);
|
|
800
|
-
if (grepMatch?.[1]?.trim()) {
|
|
801
|
-
return {
|
|
802
|
-
tool: 'grep',
|
|
803
|
-
args: { pattern: grepMatch[1].trim() },
|
|
804
|
-
label: `grep ${grepMatch[1].trim()}`,
|
|
805
|
-
};
|
|
806
|
-
}
|
|
807
|
-
const runTestMatch = /^(?:run\s+test|运行测试)\s*[::]\s*(.+)$/i.exec(text);
|
|
808
|
-
if (runTestMatch?.[1]?.trim()) {
|
|
809
|
-
return {
|
|
810
|
-
tool: 'exec_command',
|
|
811
|
-
args: { command: runTestMatch[1].trim() },
|
|
812
|
-
label: `run test: ${runTestMatch[1].trim()}`,
|
|
813
|
-
};
|
|
814
|
-
}
|
|
815
|
-
return null;
|
|
816
|
-
}
|
|
817
|
-
function formatLocalFastPathAssistantContent(action, rawResult, projectPath) {
|
|
818
|
-
const envelope = (0, tool_serializer_1.parseToolResultEnvelope)(rawResult);
|
|
819
|
-
const rawOutput = typeof envelope.output === 'string' ? envelope.output : '';
|
|
820
|
-
const output = rawOutput.trim();
|
|
821
|
-
const summary = envelope.summary || `${action.tool} ${envelope.success ? 'completed' : 'failed'}`;
|
|
822
|
-
const lines = [
|
|
823
|
-
envelope.success
|
|
824
|
-
? `Local fast path completed ${action.label}.`
|
|
825
|
-
: `Local fast path failed ${action.label}.`,
|
|
826
|
-
'',
|
|
827
|
-
summary,
|
|
828
|
-
];
|
|
829
|
-
if (!envelope.success && envelope.error) {
|
|
830
|
-
lines.push(`Error: ${envelope.error}`);
|
|
831
|
-
}
|
|
832
|
-
if (!output) {
|
|
833
|
-
return { content: lines.join('\n'), artifactRef: envelope.artifactRef };
|
|
834
|
-
}
|
|
835
|
-
let artifactRef = envelope.artifactRef;
|
|
836
|
-
let preview = output;
|
|
837
|
-
const outputBytes = envelope.outputBytes ?? byteLength(rawOutput);
|
|
838
|
-
if (byteLength(rawOutput) > LOCAL_FAST_PATH_INLINE_OUTPUT_BYTES) {
|
|
839
|
-
if (!artifactRef) {
|
|
840
|
-
const artifact = (0, tool_artifacts_1.storeArtifact)(projectPath, action.tool, rawOutput, outputBytes);
|
|
841
|
-
artifactRef = artifact ? { id: artifact.id, outputBytes: artifact.outputBytes } : undefined;
|
|
842
|
-
}
|
|
843
|
-
preview = (0, tool_artifacts_1.truncateForContext)(output, LOCAL_FAST_PATH_INLINE_OUTPUT_BYTES);
|
|
844
|
-
}
|
|
845
|
-
if (artifactRef) {
|
|
846
|
-
lines.push('', `Full output: /artifacts show ${artifactRef.id} --full (${(0, format_1.formatBytes)(artifactRef.outputBytes)})`);
|
|
847
|
-
}
|
|
848
|
-
lines.push('', 'Preview:', preview);
|
|
849
|
-
return { content: lines.join('\n'), artifactRef };
|
|
850
|
-
}
|
|
851
|
-
function createToolEventPresenter(events, options = {}) {
|
|
852
|
-
const runningToolEntries = new Map();
|
|
853
|
-
let toolSequenceCounter = 0;
|
|
854
|
-
return {
|
|
855
|
-
start(event) {
|
|
856
|
-
const seq = ++toolSequenceCounter;
|
|
857
|
-
const entryId = events.append({
|
|
858
|
-
role: 'tool',
|
|
859
|
-
title: 'tool',
|
|
860
|
-
content: toolStartContent(event),
|
|
861
|
-
toolActivity: structuredToolStartActivity(event, seq),
|
|
862
|
-
});
|
|
863
|
-
runningToolEntries.set(event.callId, {
|
|
864
|
-
entryId,
|
|
865
|
-
name: event.name,
|
|
866
|
-
args: event.args,
|
|
867
|
-
sequence: seq,
|
|
868
|
-
batchCount: event.batchCount,
|
|
869
|
-
batchIndex: event.batchIndex,
|
|
870
|
-
});
|
|
871
|
-
events.toolStarted?.({
|
|
872
|
-
callId: event.callId,
|
|
873
|
-
name: event.name,
|
|
874
|
-
args: event.args,
|
|
875
|
-
sequence: seq,
|
|
876
|
-
batchCount: event.batchCount,
|
|
877
|
-
batchIndex: event.batchIndex,
|
|
878
|
-
});
|
|
879
|
-
},
|
|
880
|
-
finish(event) {
|
|
881
|
-
const content = toolFinishContent(event);
|
|
882
|
-
const stored = runningToolEntries.get(event.callId);
|
|
883
|
-
const seq = stored?.sequence ?? ++toolSequenceCounter;
|
|
884
|
-
const toolActivity = structuredToolFinishActivity(event, seq, options);
|
|
885
|
-
if (stored) {
|
|
886
|
-
events.finalize(stored.entryId, {
|
|
887
|
-
role: event.success ? 'tool' : 'error',
|
|
888
|
-
title: 'tool',
|
|
889
|
-
content,
|
|
890
|
-
toolActivity,
|
|
891
|
-
});
|
|
892
|
-
runningToolEntries.delete(event.callId);
|
|
893
|
-
}
|
|
894
|
-
else {
|
|
895
|
-
const entryId = events.append({
|
|
896
|
-
role: event.success ? 'tool' : 'error',
|
|
897
|
-
title: 'tool',
|
|
898
|
-
content,
|
|
899
|
-
toolActivity,
|
|
900
|
-
});
|
|
901
|
-
events.finalize(entryId);
|
|
902
|
-
}
|
|
903
|
-
events.toolFinished?.({
|
|
904
|
-
callId: event.callId,
|
|
905
|
-
name: event.name,
|
|
906
|
-
args: event.args,
|
|
907
|
-
success: event.success,
|
|
908
|
-
duration: event.duration,
|
|
909
|
-
summary: event.summary,
|
|
910
|
-
error: event.error,
|
|
911
|
-
outputBytes: event.outputBytes,
|
|
912
|
-
artifactRef: toolActivity.outputView?.detailRef?.artifactId
|
|
913
|
-
? {
|
|
914
|
-
id: toolActivity.outputView.detailRef.artifactId,
|
|
915
|
-
outputBytes: toolActivity.outputView.detailRef.outputBytes,
|
|
916
|
-
}
|
|
917
|
-
: event.artifactRef,
|
|
918
|
-
externalAssertion: event.externalAssertion,
|
|
919
|
-
sequence: seq,
|
|
920
|
-
batchCount: event.batchCount,
|
|
921
|
-
batchIndex: event.batchIndex,
|
|
922
|
-
});
|
|
923
|
-
},
|
|
924
|
-
finalizePendingAsSkipped(reason = 'permission denied') {
|
|
925
|
-
for (const [callId, entry] of runningToolEntries) {
|
|
926
|
-
events.finalize(entry.entryId, {
|
|
927
|
-
role: 'tool',
|
|
928
|
-
title: 'tool',
|
|
929
|
-
content: `Skipped · ${reason}`,
|
|
930
|
-
toolActivity: {
|
|
931
|
-
state: 'skipped',
|
|
932
|
-
name: entry.name,
|
|
933
|
-
detail: '',
|
|
934
|
-
body: '',
|
|
935
|
-
error: reason,
|
|
936
|
-
seq: entry.sequence,
|
|
937
|
-
},
|
|
938
|
-
});
|
|
939
|
-
events.toolFinished?.({
|
|
940
|
-
callId,
|
|
941
|
-
name: entry.name,
|
|
942
|
-
args: entry.args,
|
|
943
|
-
success: false,
|
|
944
|
-
skipped: true,
|
|
945
|
-
duration: 0,
|
|
946
|
-
error: reason,
|
|
947
|
-
sequence: entry.sequence,
|
|
948
|
-
batchCount: entry.batchCount,
|
|
949
|
-
batchIndex: entry.batchIndex,
|
|
950
|
-
});
|
|
951
|
-
}
|
|
952
|
-
runningToolEntries.clear();
|
|
953
|
-
},
|
|
954
|
-
};
|
|
955
|
-
}
|
|
956
|
-
async function captureConsoleOutput(fn) {
|
|
957
|
-
const lines = [];
|
|
958
|
-
const originalLog = console.log;
|
|
959
|
-
const originalError = console.error;
|
|
960
|
-
const originalWarn = console.warn;
|
|
961
|
-
const capture = (...args) => {
|
|
962
|
-
lines.push(stripAnsi(args.map(arg => (typeof arg === 'string' ? arg : JSON.stringify(arg))).join(' ')));
|
|
963
|
-
};
|
|
964
|
-
console.log = capture;
|
|
965
|
-
console.error = capture;
|
|
966
|
-
console.warn = capture;
|
|
967
|
-
try {
|
|
968
|
-
const result = await fn();
|
|
969
|
-
return { result, output: lines.join('\n').trim() };
|
|
970
|
-
}
|
|
971
|
-
finally {
|
|
972
|
-
console.log = originalLog;
|
|
973
|
-
console.error = originalError;
|
|
974
|
-
console.warn = originalWarn;
|
|
975
|
-
}
|
|
976
|
-
}
|
|
28
|
+
const observability_1 = require("../utils/observability");
|
|
29
|
+
const chat_trace_1 = require("./chat-trace");
|
|
30
|
+
const chat_checkpoint_1 = require("./chat-checkpoint");
|
|
31
|
+
const chat_workspace_1 = require("./chat-workspace");
|
|
32
|
+
const chat_presentation_1 = require("./chat-presentation");
|
|
33
|
+
var chat_presentation_2 = require("./chat-presentation");
|
|
34
|
+
Object.defineProperty(exports, "createAssistantStreamPresenter", { enumerable: true, get: function () { return chat_presentation_2.createAssistantStreamPresenter; } });
|
|
35
|
+
Object.defineProperty(exports, "createToolEventPresenter", { enumerable: true, get: function () { return chat_presentation_2.createToolEventPresenter; } });
|
|
36
|
+
Object.defineProperty(exports, "sessionMessagesToTranscriptEntries", { enumerable: true, get: function () { return chat_presentation_2.sessionMessagesToTranscriptEntries; } });
|
|
977
37
|
class AgentChatController {
|
|
978
38
|
setGoalCoordinator(coord) {
|
|
979
39
|
this.goalCoordinator = coord;
|
|
@@ -1010,7 +70,7 @@ class AgentChatController {
|
|
|
1010
70
|
});
|
|
1011
71
|
const parsed = (0, parser_1.parseInput)(text);
|
|
1012
72
|
if (!parsed.isCommand) {
|
|
1013
|
-
const localFastPath = parseLocalFastPath(text);
|
|
73
|
+
const localFastPath = (0, chat_presentation_1.parseLocalFastPath)(text);
|
|
1014
74
|
if (localFastPath) {
|
|
1015
75
|
await this.runLocalFastPath(text, localFastPath, options);
|
|
1016
76
|
return;
|
|
@@ -1073,7 +133,7 @@ class AgentChatController {
|
|
|
1073
133
|
let result;
|
|
1074
134
|
let output;
|
|
1075
135
|
try {
|
|
1076
|
-
({ result, output } = await captureConsoleOutput(() => command.execute(ctx, parsed.args)));
|
|
136
|
+
({ result, output } = await (0, chat_presentation_1.captureConsoleOutput)(() => command.execute(ctx, parsed.args)));
|
|
1077
137
|
}
|
|
1078
138
|
finally {
|
|
1079
139
|
unsubscribeCommandUsage?.();
|
|
@@ -1083,7 +143,7 @@ class AgentChatController {
|
|
|
1083
143
|
}
|
|
1084
144
|
const providerRequests = Math.max(commandProviderAttempts, commandUsageEvents);
|
|
1085
145
|
if (providerRequests > 0) {
|
|
1086
|
-
const diagnostics = getLastRequestDiagnostics(this.runtime.llm);
|
|
146
|
+
const diagnostics = (0, chat_trace_1.getLastRequestDiagnostics)(this.runtime.llm);
|
|
1087
147
|
const retryCount = diagnostics?.retryCount ?? 0;
|
|
1088
148
|
const fallbackCount = diagnostics?.fallbackTriggered ? 1 : 0;
|
|
1089
149
|
this.setLoopStats({
|
|
@@ -1162,7 +222,7 @@ class AgentChatController {
|
|
|
1162
222
|
await run();
|
|
1163
223
|
return;
|
|
1164
224
|
}
|
|
1165
|
-
await goalTraceContext.run({
|
|
225
|
+
await chat_trace_1.goalTraceContext.run({
|
|
1166
226
|
goalId: request.goal.goalId,
|
|
1167
227
|
goalRevision: request.goal.revision,
|
|
1168
228
|
goalInputKind: request.inputKind,
|
|
@@ -1174,30 +234,35 @@ class AgentChatController {
|
|
|
1174
234
|
this.runtime.ensureSession() ??
|
|
1175
235
|
(0, session_storage_1.loadSessionMeta)(this.runtime.getSession()?.id ?? '');
|
|
1176
236
|
const sessionId = activeSession?.id;
|
|
1177
|
-
const turnId = traceTurnId(options.turnId);
|
|
237
|
+
const turnId = (0, chat_trace_1.traceTurnId)(options.turnId);
|
|
238
|
+
(0, observability_1.setDiagnosticTraceContext)({
|
|
239
|
+
traceId: `${sessionId ?? 'local'}:${turnId}`,
|
|
240
|
+
...(sessionId ? { sessionId } : {}),
|
|
241
|
+
turnId,
|
|
242
|
+
});
|
|
1178
243
|
const localCallId = `local-${turnId}`;
|
|
1179
244
|
const start = Date.now();
|
|
1180
245
|
const preWorkspace = (0, workspace_state_1.captureWorkspaceSnapshot)(this.runtime.cwd);
|
|
1181
|
-
const traceArgs = buildTraceArgsDetails(this.runtime.cwd, action.tool, action.args);
|
|
246
|
+
const traceArgs = (0, chat_trace_1.buildTraceArgsDetails)(this.runtime.cwd, action.tool, action.args);
|
|
1182
247
|
if (sessionId) {
|
|
1183
248
|
(0, session_storage_1.appendSessionMessage)(sessionId, {
|
|
1184
249
|
role: 'user',
|
|
1185
250
|
content: input,
|
|
1186
251
|
timestamp: Date.now(),
|
|
1187
252
|
});
|
|
1188
|
-
recordTraceEvent(this.events, sessionId, {
|
|
253
|
+
(0, chat_trace_1.recordTraceEvent)(this.events, sessionId, {
|
|
1189
254
|
turnId,
|
|
1190
255
|
type: 'turn_start',
|
|
1191
|
-
inputBytes: byteLength(input),
|
|
256
|
+
inputBytes: (0, chat_trace_1.byteLength)(input),
|
|
1192
257
|
localFastPathUsed: true,
|
|
1193
258
|
});
|
|
1194
|
-
appendWorkspaceSnapshotTrace(this.events, sessionId, turnId, 'pre_turn', preWorkspace);
|
|
1195
|
-
recordTraceEvent(this.events, sessionId, {
|
|
259
|
+
(0, chat_workspace_1.appendWorkspaceSnapshotTrace)(this.events, sessionId, turnId, 'pre_turn', preWorkspace);
|
|
260
|
+
(0, chat_trace_1.recordTraceEvent)(this.events, sessionId, {
|
|
1196
261
|
turnId,
|
|
1197
262
|
type: 'local_fast_path',
|
|
1198
263
|
name: action.tool,
|
|
1199
264
|
...traceArgs,
|
|
1200
|
-
note: compactMiddle(action.label, 160),
|
|
265
|
+
note: (0, chat_trace_1.compactMiddle)(action.label, 160),
|
|
1201
266
|
});
|
|
1202
267
|
}
|
|
1203
268
|
if (options.persistAsUserMessage !== false) {
|
|
@@ -1218,13 +283,13 @@ class AgentChatController {
|
|
|
1218
283
|
const permission = tool?.checkPermissions?.(action.args, toolContext);
|
|
1219
284
|
if (permission?.behavior === 'deny' || tool?.isDestructive?.(action.args) === true) {
|
|
1220
285
|
const reason = permission?.reason || 'Local fast path blocked a destructive tool request.';
|
|
1221
|
-
throw new LocalFastPathBlockedError(reason);
|
|
286
|
+
throw new chat_presentation_1.LocalFastPathBlockedError(reason);
|
|
1222
287
|
}
|
|
1223
288
|
if (permission?.behavior === 'ask') {
|
|
1224
|
-
throw new LocalFastPathBlockedError(permission.reason || 'Local fast path requires an allow-safe command.');
|
|
289
|
+
throw new chat_presentation_1.LocalFastPathBlockedError(permission.reason || 'Local fast path requires an allow-safe command.');
|
|
1225
290
|
}
|
|
1226
291
|
if (sessionId) {
|
|
1227
|
-
recordTraceEvent(this.events, sessionId, {
|
|
292
|
+
(0, chat_trace_1.recordTraceEvent)(this.events, sessionId, {
|
|
1228
293
|
turnId,
|
|
1229
294
|
type: 'tool_call',
|
|
1230
295
|
name: action.tool,
|
|
@@ -1242,7 +307,7 @@ class AgentChatController {
|
|
|
1242
307
|
const outputBytes = typeof envelope.outputBytes === 'number'
|
|
1243
308
|
? envelope.outputBytes
|
|
1244
309
|
: Buffer.byteLength(result, 'utf8');
|
|
1245
|
-
const formattedLocalResult = formatLocalFastPathAssistantContent(action, result, this.runtime.cwd);
|
|
310
|
+
const formattedLocalResult = (0, chat_presentation_1.formatLocalFastPathAssistantContent)(action, result, this.runtime.cwd);
|
|
1246
311
|
const assistantContent = formattedLocalResult.content;
|
|
1247
312
|
const stats = (0, framework_1.createLocalFastPathLoopStats)({
|
|
1248
313
|
finishReason: envelope.success ? 'completed' : 'failed',
|
|
@@ -1270,8 +335,8 @@ class AgentChatController {
|
|
|
1270
335
|
this.events.append({
|
|
1271
336
|
role: envelope.success ? 'tool' : 'error',
|
|
1272
337
|
title: 'local',
|
|
1273
|
-
content: toolFinishContent(localToolResultEvent),
|
|
1274
|
-
toolActivity: structuredToolFinishActivity(localToolResultEvent, 1, {
|
|
338
|
+
content: (0, chat_presentation_1.toolFinishContent)(localToolResultEvent),
|
|
339
|
+
toolActivity: (0, chat_presentation_1.structuredToolFinishActivity)(localToolResultEvent, 1, {
|
|
1275
340
|
projectPath: this.runtime.cwd,
|
|
1276
341
|
turnId,
|
|
1277
342
|
}),
|
|
@@ -1279,7 +344,7 @@ class AgentChatController {
|
|
|
1279
344
|
this.runtime.store.addMessage({ role: 'assistant', content: assistantContent });
|
|
1280
345
|
this.setLoopStats(stats);
|
|
1281
346
|
if (sessionId) {
|
|
1282
|
-
recordTraceEvent(this.events, sessionId, {
|
|
347
|
+
(0, chat_trace_1.recordTraceEvent)(this.events, sessionId, {
|
|
1283
348
|
turnId,
|
|
1284
349
|
type: 'tool_result',
|
|
1285
350
|
name: action.tool,
|
|
@@ -1292,10 +357,10 @@ class AgentChatController {
|
|
|
1292
357
|
outputBytes,
|
|
1293
358
|
modelVisibleBytes: 0,
|
|
1294
359
|
artifactId: formattedLocalResult.artifactRef?.id,
|
|
1295
|
-
error: envelope.error ? compactMiddle(envelope.error, 240) : undefined,
|
|
360
|
+
error: envelope.error ? (0, chat_trace_1.compactMiddle)(envelope.error, 240) : undefined,
|
|
1296
361
|
});
|
|
1297
|
-
appendPostWorkspaceTrace(this.events, sessionId, turnId, this.runtime.cwd, preWorkspace);
|
|
1298
|
-
recordTraceEvent(this.events, sessionId, {
|
|
362
|
+
(0, chat_workspace_1.appendPostWorkspaceTrace)(this.events, sessionId, turnId, this.runtime.cwd, preWorkspace);
|
|
363
|
+
(0, chat_trace_1.recordTraceEvent)(this.events, sessionId, {
|
|
1299
364
|
turnId,
|
|
1300
365
|
type: 'complete',
|
|
1301
366
|
finishReason: stats.finishReason,
|
|
@@ -1323,21 +388,21 @@ class AgentChatController {
|
|
|
1323
388
|
this.events.setStatus('Local command failed. Ready for the next input.');
|
|
1324
389
|
const assistantContent = `Local fast path failed for ${action.label}.\n\n${message}`;
|
|
1325
390
|
this.runtime.store.addMessage({ role: 'assistant', content: assistantContent });
|
|
1326
|
-
const finishReason = error instanceof LocalFastPathBlockedError ? 'blocked' : 'failed';
|
|
391
|
+
const finishReason = error instanceof chat_presentation_1.LocalFastPathBlockedError ? 'blocked' : 'failed';
|
|
1327
392
|
const stats = (0, framework_1.createLocalFastPathLoopStats)({
|
|
1328
393
|
finishReason,
|
|
1329
394
|
toolCalls: 0,
|
|
1330
395
|
});
|
|
1331
396
|
this.setLoopStats(stats);
|
|
1332
397
|
if (sessionId) {
|
|
1333
|
-
recordTraceEvent(this.events, sessionId, {
|
|
398
|
+
(0, chat_trace_1.recordTraceEvent)(this.events, sessionId, {
|
|
1334
399
|
turnId,
|
|
1335
400
|
type: 'error',
|
|
1336
401
|
name: action.tool,
|
|
1337
|
-
error: compactTraceError(error),
|
|
402
|
+
error: (0, chat_trace_1.compactTraceError)(error),
|
|
1338
403
|
});
|
|
1339
|
-
appendPostWorkspaceTrace(this.events, sessionId, turnId, this.runtime.cwd, preWorkspace);
|
|
1340
|
-
recordTraceEvent(this.events, sessionId, {
|
|
404
|
+
(0, chat_workspace_1.appendPostWorkspaceTrace)(this.events, sessionId, turnId, this.runtime.cwd, preWorkspace);
|
|
405
|
+
(0, chat_trace_1.recordTraceEvent)(this.events, sessionId, {
|
|
1341
406
|
turnId,
|
|
1342
407
|
type: 'complete',
|
|
1343
408
|
finishReason: stats.finishReason,
|
|
@@ -1368,7 +433,7 @@ class AgentChatController {
|
|
|
1368
433
|
setSession: session => {
|
|
1369
434
|
this.runtime.setSession(session);
|
|
1370
435
|
const renderer = this.controllerOptions.uiRenderer ?? this.runtime.config.ui?.renderer ?? 'terminal';
|
|
1371
|
-
this.events.replaceTranscript(sessionMessagesToTranscriptEntries(session.id, {
|
|
436
|
+
this.events.replaceTranscript((0, chat_presentation_1.sessionMessagesToTranscriptEntries)(session.id, {
|
|
1372
437
|
includeToolOutputViews: renderer === 'tui',
|
|
1373
438
|
}));
|
|
1374
439
|
},
|
|
@@ -1423,7 +488,7 @@ class AgentChatController {
|
|
|
1423
488
|
if (sessionId) {
|
|
1424
489
|
const traceType = stateToTraceType[event.state];
|
|
1425
490
|
if (traceType) {
|
|
1426
|
-
recordTraceEvent(this.events, sessionId, {
|
|
491
|
+
(0, chat_trace_1.recordTraceEvent)(this.events, sessionId, {
|
|
1427
492
|
turnId: String(turnId),
|
|
1428
493
|
type: traceType,
|
|
1429
494
|
name: `${event.role}:${event.taskId}`,
|
|
@@ -1501,11 +566,16 @@ class AgentChatController {
|
|
|
1501
566
|
// any provider request so failures without usage cannot inherit stale data.
|
|
1502
567
|
this.runtime.store.setState({ tokenUsage: null });
|
|
1503
568
|
const abortSignal = options.abortSignal;
|
|
1504
|
-
const turnId = traceTurnId(options.turnId);
|
|
569
|
+
const turnId = (0, chat_trace_1.traceTurnId)(options.turnId);
|
|
1505
570
|
const activeSession = this.runtime.getSession() ??
|
|
1506
571
|
this.runtime.ensureSession() ??
|
|
1507
572
|
(0, session_storage_1.loadSessionMeta)(this.runtime.getSession()?.id ?? '');
|
|
1508
573
|
const sessionId = activeSession?.id;
|
|
574
|
+
(0, observability_1.setDiagnosticTraceContext)({
|
|
575
|
+
traceId: `${sessionId ?? 'unsaved'}:${turnId}`,
|
|
576
|
+
...(sessionId ? { sessionId } : {}),
|
|
577
|
+
turnId,
|
|
578
|
+
});
|
|
1509
579
|
const preWorkspace = (0, workspace_state_1.captureWorkspaceSnapshot)(this.runtime.cwd);
|
|
1510
580
|
const runtimeTools = (0, tools_1.getRuntimeTools)();
|
|
1511
581
|
const skillResolution = (0, skills_1.resolveSkillsForTurn)({
|
|
@@ -1523,13 +593,13 @@ class AgentChatController {
|
|
|
1523
593
|
timestamp: Date.now(),
|
|
1524
594
|
appliedSkills: appliedSkillNames.length > 0 ? appliedSkillNames : undefined,
|
|
1525
595
|
});
|
|
1526
|
-
recordTraceEvent(this.events, sessionId, {
|
|
596
|
+
(0, chat_trace_1.recordTraceEvent)(this.events, sessionId, {
|
|
1527
597
|
turnId,
|
|
1528
598
|
type: 'turn_start',
|
|
1529
|
-
inputBytes: byteLength(input),
|
|
599
|
+
inputBytes: (0, chat_trace_1.byteLength)(input),
|
|
1530
600
|
note: appliedSkillNames.length > 0 ? `skills=${appliedSkillNames.join(',')}` : undefined,
|
|
1531
601
|
});
|
|
1532
|
-
appendWorkspaceSnapshotTrace(this.events, sessionId, turnId, 'pre_turn', preWorkspace);
|
|
602
|
+
(0, chat_workspace_1.appendWorkspaceSnapshotTrace)(this.events, sessionId, turnId, 'pre_turn', preWorkspace);
|
|
1533
603
|
}
|
|
1534
604
|
if (options.persistAsUserMessage !== false) {
|
|
1535
605
|
this.runtime.store.addMessage({ role: 'user', content: input });
|
|
@@ -1576,8 +646,8 @@ class AgentChatController {
|
|
|
1576
646
|
onSubtaskEvent: event => {
|
|
1577
647
|
this.handleSubtaskEvent(event, sessionId, turnId);
|
|
1578
648
|
},
|
|
1579
|
-
onSubtaskResult: (result, _batchId) => {
|
|
1580
|
-
if (!projectPath
|
|
649
|
+
onSubtaskResult: (result, _batchId, objective, researchContext) => {
|
|
650
|
+
if (!projectPath)
|
|
1581
651
|
return;
|
|
1582
652
|
const json = JSON.stringify(result);
|
|
1583
653
|
const artifact = (0, tool_artifacts_1.storeArtifact)(projectPath, `subtask_${result.role}`, json, Buffer.byteLength(json, 'utf8'));
|
|
@@ -1586,7 +656,7 @@ class AgentChatController {
|
|
|
1586
656
|
// The subtask state transition (subtask_completed) is already
|
|
1587
657
|
// emitted by handleSubtaskEvent above.
|
|
1588
658
|
if (sessionId) {
|
|
1589
|
-
recordTraceEvent(this.events, sessionId, {
|
|
659
|
+
(0, chat_trace_1.recordTraceEvent)(this.events, sessionId, {
|
|
1590
660
|
turnId: String(turnId),
|
|
1591
661
|
type: 'subtask_artifact_stored',
|
|
1592
662
|
name: `${result.role}:${result.id}`,
|
|
@@ -1596,6 +666,74 @@ class AgentChatController {
|
|
|
1596
666
|
});
|
|
1597
667
|
}
|
|
1598
668
|
}
|
|
669
|
+
// v0.1.4 Research-to-Evidence integration: normalize every
|
|
670
|
+
// terminal research result (including partial/failure states),
|
|
671
|
+
// persist it under a packet-specific CAS scope, and forward the
|
|
672
|
+
// canonical lifecycle stream to every renderer.
|
|
673
|
+
if (result.role !== 'research' || !sessionId)
|
|
674
|
+
return;
|
|
675
|
+
try {
|
|
676
|
+
const goal = this.goalCoordinator?.goal;
|
|
677
|
+
const objectiveRevision = goal?.contract?.objectiveRevision;
|
|
678
|
+
const hasGoalBinding = typeof goal?.goalId === 'string' && typeof objectiveRevision === 'number';
|
|
679
|
+
// Preserve the authoritative request produced from the
|
|
680
|
+
// original subtask capability. Reconstruct local-only only for
|
|
681
|
+
// legacy callers that predate the additive callback context.
|
|
682
|
+
const baseRequest = researchContext?.request ??
|
|
683
|
+
(0, subagents_1.createLocalResearchRequest)(objective?.trim() || result.summary || 'repository research', projectPath);
|
|
684
|
+
const request = {
|
|
685
|
+
...baseRequest,
|
|
686
|
+
scope: { ...baseRequest.scope, projectRoot: projectPath },
|
|
687
|
+
...(hasGoalBinding
|
|
688
|
+
? {
|
|
689
|
+
goalBinding: {
|
|
690
|
+
goalId: goal.goalId,
|
|
691
|
+
objectiveRevision,
|
|
692
|
+
},
|
|
693
|
+
}
|
|
694
|
+
: {}),
|
|
695
|
+
};
|
|
696
|
+
const packet = (0, subagents_1.subtaskResultToPacket)(result, request, {
|
|
697
|
+
projectPath,
|
|
698
|
+
sessionId,
|
|
699
|
+
...(hasGoalBinding ? { goalId: goal.goalId, objectiveRevision } : {}),
|
|
700
|
+
}, {
|
|
701
|
+
externalSources: researchContext?.web?.sources,
|
|
702
|
+
externalNotes: researchContext?.web?.notes,
|
|
703
|
+
externalTimedOut: researchContext?.web?.timedOut,
|
|
704
|
+
externalAborted: researchContext?.web?.aborted,
|
|
705
|
+
});
|
|
706
|
+
// Citation resolution can downgrade claims and mark superseded
|
|
707
|
+
// same-URL sources stale. Resolve before validation/persistence so
|
|
708
|
+
// the CAS token, durable packet and renderer view describe the
|
|
709
|
+
// exact same final state (#105).
|
|
710
|
+
const resolution = (0, subagents_1.resolveCitations)(packet);
|
|
711
|
+
const validation = (0, subagents_1.validatePacket)(packet);
|
|
712
|
+
if (!validation.ok)
|
|
713
|
+
return;
|
|
714
|
+
const saved = (0, subagents_1.saveResearchPacket)((0, subagents_1.createFileArtifactStore)(projectPath), packet, {
|
|
715
|
+
projectPath,
|
|
716
|
+
sessionId,
|
|
717
|
+
packetId: packet.packetId,
|
|
718
|
+
...(packet.goalId ? { goalId: packet.goalId } : {}),
|
|
719
|
+
});
|
|
720
|
+
const view = (0, subagents_1.buildResearchView)(packet, resolution);
|
|
721
|
+
for (const event of (0, subagents_1.toLifecycleEvents)(view, resolution)) {
|
|
722
|
+
this.events.researchEvent?.(event);
|
|
723
|
+
}
|
|
724
|
+
(0, chat_trace_1.recordTraceEvent)(this.events, sessionId, {
|
|
725
|
+
turnId: String(turnId),
|
|
726
|
+
type: 'subtask_artifact_stored',
|
|
727
|
+
name: `research:${packet.packetId}`,
|
|
728
|
+
argsSummary: `${view.stage}/${view.auditStatus}: ${packet.summary}`.slice(0, 200),
|
|
729
|
+
argsArtifactId: `research-${saved.casToken.slice(0, 16)}`,
|
|
730
|
+
argsBytes: Buffer.byteLength(JSON.stringify(packet), 'utf8'),
|
|
731
|
+
});
|
|
732
|
+
}
|
|
733
|
+
catch {
|
|
734
|
+
// Research persistence/rendering is observational. A storage
|
|
735
|
+
// failure must not alter the child result or root turn state.
|
|
736
|
+
}
|
|
1599
737
|
},
|
|
1600
738
|
// R6: wire live permission state so the subagent policy gate can
|
|
1601
739
|
// prevent background delegation while the user is deciding a tool
|
|
@@ -1640,8 +778,8 @@ class AgentChatController {
|
|
|
1640
778
|
let pendingCompact;
|
|
1641
779
|
const verificationResults = [];
|
|
1642
780
|
const sessionMessagesToRecord = [];
|
|
1643
|
-
const assistantStream = createAssistantStreamPresenter(this.events, abortSignal);
|
|
1644
|
-
const toolEvents = createToolEventPresenter(this.events, {
|
|
781
|
+
const assistantStream = (0, chat_presentation_1.createAssistantStreamPresenter)(this.events, abortSignal);
|
|
782
|
+
const toolEvents = (0, chat_presentation_1.createToolEventPresenter)(this.events, {
|
|
1645
783
|
projectPath: this.runtime.cwd,
|
|
1646
784
|
turnId,
|
|
1647
785
|
});
|
|
@@ -1681,6 +819,10 @@ class AgentChatController {
|
|
|
1681
819
|
},
|
|
1682
820
|
sessionId,
|
|
1683
821
|
turnId,
|
|
822
|
+
// Tools that fan out to other tools (batch_read) have to re-run the
|
|
823
|
+
// permission gate per sub-step; they need the mode and the allowlist.
|
|
824
|
+
permissionMode: snapshot.permissionMode,
|
|
825
|
+
toolAllowlist: this.resolveToolAllowlist(),
|
|
1684
826
|
});
|
|
1685
827
|
};
|
|
1686
828
|
const loopBudget = (0, loop_budget_1.resolveRuntimeLoopBudget)(input, this.runtime.config, harness.toJSON());
|
|
@@ -1748,7 +890,7 @@ class AgentChatController {
|
|
|
1748
890
|
assistantStream.discardSegment();
|
|
1749
891
|
this.events.setStatus((0, agent_status_1.agentStepStatus)(event.turn));
|
|
1750
892
|
if (sessionId) {
|
|
1751
|
-
recordTraceEvent(this.events, sessionId, {
|
|
893
|
+
(0, chat_trace_1.recordTraceEvent)(this.events, sessionId, {
|
|
1752
894
|
turnId,
|
|
1753
895
|
type: 'request_start',
|
|
1754
896
|
model: event.model,
|
|
@@ -1758,7 +900,7 @@ class AgentChatController {
|
|
|
1758
900
|
break;
|
|
1759
901
|
case 'prompt_assembly':
|
|
1760
902
|
if (sessionId) {
|
|
1761
|
-
recordTraceEvent(this.events, sessionId, {
|
|
903
|
+
(0, chat_trace_1.recordTraceEvent)(this.events, sessionId, {
|
|
1762
904
|
turnId,
|
|
1763
905
|
type: 'prompt_assembly',
|
|
1764
906
|
promptModelId: event.modelId,
|
|
@@ -1782,7 +924,7 @@ class AgentChatController {
|
|
|
1782
924
|
{
|
|
1783
925
|
const batchReadOnlyCount = event.toolCalls.filter(tc => {
|
|
1784
926
|
const def = skillResolution.tools.find(t => t.name === tc.function.name);
|
|
1785
|
-
const args = parseToolCallArgsForRuntime(tc);
|
|
927
|
+
const args = (0, chat_checkpoint_1.parseToolCallArgsForRuntime)(tc);
|
|
1786
928
|
return args && def?.isReadOnly?.(args) === true;
|
|
1787
929
|
}).length;
|
|
1788
930
|
const suggestion = (0, agent_status_1.batchingSuggestion)(batchReadOnlyCount);
|
|
@@ -1790,8 +932,8 @@ class AgentChatController {
|
|
|
1790
932
|
this.events.append({ role: 'status', content: suggestion });
|
|
1791
933
|
}
|
|
1792
934
|
}
|
|
1793
|
-
const checkpointId =
|
|
1794
|
-
const checkpointResult = createPreToolCheckpoint(this.events, sessionId, turnId, checkpointId, this.runtime.cwd, event.toolCalls);
|
|
935
|
+
const checkpointId = `${turnId}-${checkpointSequence + 1}-${(0, crypto_1.randomUUID)()}`;
|
|
936
|
+
const checkpointResult = (0, chat_checkpoint_1.createPreToolCheckpoint)(this.events, sessionId, turnId, checkpointId, this.runtime.cwd, event.toolCalls);
|
|
1795
937
|
if (checkpointResult.created) {
|
|
1796
938
|
checkpointIds.push(checkpointId);
|
|
1797
939
|
checkpointSequence++;
|
|
@@ -1813,11 +955,11 @@ class AgentChatController {
|
|
|
1813
955
|
});
|
|
1814
956
|
}
|
|
1815
957
|
if (sessionId) {
|
|
1816
|
-
recordTraceEvent(this.events, sessionId, {
|
|
958
|
+
(0, chat_trace_1.recordTraceEvent)(this.events, sessionId, {
|
|
1817
959
|
turnId,
|
|
1818
960
|
type: 'assistant_tool_calls',
|
|
1819
961
|
toolCallCount: event.toolCalls.length,
|
|
1820
|
-
contentBytes: byteLength(event.content || ''),
|
|
962
|
+
contentBytes: (0, chat_trace_1.byteLength)(event.content || ''),
|
|
1821
963
|
});
|
|
1822
964
|
}
|
|
1823
965
|
sessionMessagesToRecord.push({
|
|
@@ -1841,8 +983,8 @@ class AgentChatController {
|
|
|
1841
983
|
assistantStream.closeSegment();
|
|
1842
984
|
toolEvents.start(event);
|
|
1843
985
|
if (sessionId) {
|
|
1844
|
-
const traceArgs = buildTraceArgsDetails(this.runtime.cwd, event.name, event.args);
|
|
1845
|
-
recordTraceEvent(this.events, sessionId, {
|
|
986
|
+
const traceArgs = (0, chat_trace_1.buildTraceArgsDetails)(this.runtime.cwd, event.name, event.args);
|
|
987
|
+
(0, chat_trace_1.recordTraceEvent)(this.events, sessionId, {
|
|
1846
988
|
turnId,
|
|
1847
989
|
type: 'tool_call',
|
|
1848
990
|
name: event.name,
|
|
@@ -1855,17 +997,17 @@ class AgentChatController {
|
|
|
1855
997
|
break;
|
|
1856
998
|
case 'permission_decision':
|
|
1857
999
|
if (sessionId) {
|
|
1858
|
-
recordTraceEvent(this.events, sessionId, {
|
|
1000
|
+
(0, chat_trace_1.recordTraceEvent)(this.events, sessionId, {
|
|
1859
1001
|
turnId,
|
|
1860
1002
|
type: 'permission_decision',
|
|
1861
1003
|
name: event.name,
|
|
1862
1004
|
callId: event.callId,
|
|
1863
|
-
argsSummary: compactToolArgs(event.args),
|
|
1005
|
+
argsSummary: (0, chat_trace_1.compactToolArgs)(event.args),
|
|
1864
1006
|
permissionBehavior: event.decision.behavior,
|
|
1865
1007
|
permissionApproved: event.decision.approved,
|
|
1866
1008
|
permissionSource: event.decision.source,
|
|
1867
1009
|
permissionReason: event.decision.reason
|
|
1868
|
-
? compactMiddle(event.decision.reason, 240)
|
|
1010
|
+
? (0, chat_trace_1.compactMiddle)(event.decision.reason, 240)
|
|
1869
1011
|
: undefined,
|
|
1870
1012
|
permissionDuration: event.decision.duration,
|
|
1871
1013
|
batchCount: event.batchCount,
|
|
@@ -1874,22 +1016,22 @@ class AgentChatController {
|
|
|
1874
1016
|
}
|
|
1875
1017
|
break;
|
|
1876
1018
|
case 'tool_result': {
|
|
1877
|
-
observedToolResultBytes += event.outputBytes ?? byteLength(event.result);
|
|
1878
|
-
observedModelVisibleToolBytes += byteLength(event.modelVisibleResult);
|
|
1019
|
+
observedToolResultBytes += event.outputBytes ?? (0, chat_trace_1.byteLength)(event.result);
|
|
1020
|
+
observedModelVisibleToolBytes += (0, chat_trace_1.byteLength)(event.modelVisibleResult);
|
|
1879
1021
|
toolEvents.finish(event);
|
|
1880
1022
|
if (sessionId) {
|
|
1881
|
-
recordTraceEvent(this.events, sessionId, {
|
|
1023
|
+
(0, chat_trace_1.recordTraceEvent)(this.events, sessionId, {
|
|
1882
1024
|
turnId,
|
|
1883
1025
|
type: 'tool_result',
|
|
1884
1026
|
name: event.name,
|
|
1885
1027
|
callId: event.callId,
|
|
1886
|
-
argsSummary: compactToolArgs(event.args),
|
|
1028
|
+
argsSummary: (0, chat_trace_1.compactToolArgs)(event.args),
|
|
1887
1029
|
success: event.success,
|
|
1888
1030
|
duration: event.duration,
|
|
1889
1031
|
outputBytes: event.outputBytes,
|
|
1890
|
-
modelVisibleBytes: byteLength(event.modelVisibleResult),
|
|
1032
|
+
modelVisibleBytes: (0, chat_trace_1.byteLength)(event.modelVisibleResult),
|
|
1891
1033
|
artifactId: event.artifactRef?.id,
|
|
1892
|
-
error: event.error ? compactMiddle(event.error, 240) : undefined,
|
|
1034
|
+
error: event.error ? (0, chat_trace_1.compactMiddle)(event.error, 240) : undefined,
|
|
1893
1035
|
batchCount: event.batchCount,
|
|
1894
1036
|
batchIndex: event.batchIndex,
|
|
1895
1037
|
});
|
|
@@ -1903,7 +1045,7 @@ class AgentChatController {
|
|
|
1903
1045
|
});
|
|
1904
1046
|
if (verificationResult) {
|
|
1905
1047
|
verificationResults.push(verificationResult);
|
|
1906
|
-
appendVerificationResultTrace(this.events, sessionId, turnId, verificationResult);
|
|
1048
|
+
(0, chat_workspace_1.appendVerificationResultTrace)(this.events, sessionId, turnId, verificationResult);
|
|
1907
1049
|
}
|
|
1908
1050
|
sessionMessagesToRecord.push({
|
|
1909
1051
|
role: 'tool',
|
|
@@ -1917,10 +1059,10 @@ class AgentChatController {
|
|
|
1917
1059
|
case 'strategy_exhausted':
|
|
1918
1060
|
this.events.append({ role: 'status', content: event.suggestion });
|
|
1919
1061
|
if (sessionId) {
|
|
1920
|
-
recordTraceEvent(this.events, sessionId, {
|
|
1062
|
+
(0, chat_trace_1.recordTraceEvent)(this.events, sessionId, {
|
|
1921
1063
|
turnId,
|
|
1922
1064
|
type: 'strategy_exhausted',
|
|
1923
|
-
note: compactMiddle(event.suggestion, 240),
|
|
1065
|
+
note: (0, chat_trace_1.compactMiddle)(event.suggestion, 240),
|
|
1924
1066
|
});
|
|
1925
1067
|
}
|
|
1926
1068
|
break;
|
|
@@ -1936,10 +1078,10 @@ class AgentChatController {
|
|
|
1936
1078
|
finalContent = event.content;
|
|
1937
1079
|
assistantStream.ensureMessage(event.content);
|
|
1938
1080
|
if (sessionId) {
|
|
1939
|
-
recordTraceEvent(this.events, sessionId, {
|
|
1081
|
+
(0, chat_trace_1.recordTraceEvent)(this.events, sessionId, {
|
|
1940
1082
|
turnId,
|
|
1941
1083
|
type: 'message',
|
|
1942
|
-
contentBytes: byteLength(event.content),
|
|
1084
|
+
contentBytes: (0, chat_trace_1.byteLength)(event.content),
|
|
1943
1085
|
});
|
|
1944
1086
|
}
|
|
1945
1087
|
if (event.content) {
|
|
@@ -1973,12 +1115,12 @@ class AgentChatController {
|
|
|
1973
1115
|
pendingCompact = event.compact;
|
|
1974
1116
|
if (event.stats) {
|
|
1975
1117
|
pendingCompleteStats = event.stats;
|
|
1976
|
-
recordProviderTraceEvents(this.events, sessionId, turnId, event.stats);
|
|
1118
|
+
(0, chat_trace_1.recordProviderTraceEvents)(this.events, sessionId, turnId, event.stats);
|
|
1977
1119
|
pendingCompleteTrace = {
|
|
1978
1120
|
turnId,
|
|
1979
1121
|
type: 'complete',
|
|
1980
1122
|
model: event.model,
|
|
1981
|
-
contentBytes: byteLength(event.content || ''),
|
|
1123
|
+
contentBytes: (0, chat_trace_1.byteLength)(event.content || ''),
|
|
1982
1124
|
finishReason: event.stats.finishReason,
|
|
1983
1125
|
llmRequests: event.stats.llmRequests,
|
|
1984
1126
|
toolCalls: event.stats.toolCalls,
|
|
@@ -2002,7 +1144,7 @@ class AgentChatController {
|
|
|
2002
1144
|
turnId,
|
|
2003
1145
|
type: 'complete',
|
|
2004
1146
|
model: event.model,
|
|
2005
|
-
contentBytes: byteLength(event.content || ''),
|
|
1147
|
+
contentBytes: (0, chat_trace_1.byteLength)(event.content || ''),
|
|
2006
1148
|
};
|
|
2007
1149
|
}
|
|
2008
1150
|
break;
|
|
@@ -2013,7 +1155,7 @@ class AgentChatController {
|
|
|
2013
1155
|
const stats = pendingCompleteStats ??
|
|
2014
1156
|
(0, framework_1.createFailedLoopStats)({
|
|
2015
1157
|
loopBudget,
|
|
2016
|
-
diagnostics: observedLlmRequests > 0 ? getLastRequestDiagnostics(this.runtime.llm) : undefined,
|
|
1158
|
+
diagnostics: observedLlmRequests > 0 ? (0, chat_trace_1.getLastRequestDiagnostics)(this.runtime.llm) : undefined,
|
|
2017
1159
|
turnsStarted: observedTurnsStarted,
|
|
2018
1160
|
llmRequests: observedLlmRequests,
|
|
2019
1161
|
toolCalls: observedToolCalls,
|
|
@@ -2025,16 +1167,16 @@ class AgentChatController {
|
|
|
2025
1167
|
persistInterruptedAccounting(finalUsage, stats, finalUsage !== undefined || stats.llmRequests === 0);
|
|
2026
1168
|
assistantStream.discardSegment();
|
|
2027
1169
|
this.events.setStatus('Interrupted.');
|
|
2028
|
-
removeTrailingUserMessage(this.runtime);
|
|
1170
|
+
(0, chat_presentation_1.removeTrailingUserMessage)(this.runtime);
|
|
2029
1171
|
if (sessionId) {
|
|
2030
|
-
const { delta } = appendPostWorkspaceTrace(this.events, sessionId, turnId, this.runtime.cwd, preWorkspace, verificationResults);
|
|
2031
|
-
recordTraceEvent(this.events, sessionId, {
|
|
1172
|
+
const { delta } = (0, chat_workspace_1.appendPostWorkspaceTrace)(this.events, sessionId, turnId, this.runtime.cwd, preWorkspace, verificationResults);
|
|
1173
|
+
(0, chat_trace_1.recordTraceEvent)(this.events, sessionId, {
|
|
2032
1174
|
turnId,
|
|
2033
1175
|
type: 'aborted',
|
|
2034
1176
|
note: 'aborted_after_query',
|
|
2035
1177
|
});
|
|
2036
|
-
const recoveryNotice = workspaceDeltaHasTurnChanges(delta)
|
|
2037
|
-
? formatFailureRecoveryNotice(turnId, delta, checkpointIds)
|
|
1178
|
+
const recoveryNotice = (0, chat_workspace_1.workspaceDeltaHasTurnChanges)(delta)
|
|
1179
|
+
? (0, chat_workspace_1.formatFailureRecoveryNotice)(turnId, delta, checkpointIds)
|
|
2038
1180
|
: undefined;
|
|
2039
1181
|
if (recoveryNotice) {
|
|
2040
1182
|
this.events.append({
|
|
@@ -2055,15 +1197,15 @@ class AgentChatController {
|
|
|
2055
1197
|
}
|
|
2056
1198
|
assistantStream.closeSegment();
|
|
2057
1199
|
if (sessionId) {
|
|
2058
|
-
const { profile, summary } = appendPostWorkspaceTrace(this.events, sessionId, turnId, this.runtime.cwd, preWorkspace, verificationResults);
|
|
1200
|
+
const { profile, summary } = (0, chat_workspace_1.appendPostWorkspaceTrace)(this.events, sessionId, turnId, this.runtime.cwd, preWorkspace, verificationResults);
|
|
2059
1201
|
if (profile.changedFiles.length > 0 && profile.required) {
|
|
2060
1202
|
this.events.setStatus((0, agent_status_1.verifyingStatus)(profile.profile));
|
|
2061
1203
|
this.controllerOptions.onVerificationStateChange?.('running');
|
|
2062
1204
|
}
|
|
2063
|
-
if (shouldRecordVerificationLoopStats(profile, summary)) {
|
|
1205
|
+
if ((0, chat_workspace_1.shouldRecordVerificationLoopStats)(profile, summary)) {
|
|
2064
1206
|
const stats = pendingCompleteStats ?? this.runtime.store.getSnapshot().lastLoopStats;
|
|
2065
1207
|
if (stats) {
|
|
2066
|
-
pendingCompleteStats = withVerificationLoopStats(stats, summary);
|
|
1208
|
+
pendingCompleteStats = (0, chat_workspace_1.withVerificationLoopStats)(stats, summary);
|
|
2067
1209
|
}
|
|
2068
1210
|
}
|
|
2069
1211
|
if ((0, verification_profile_1.shouldGateCompletion)(summary)) {
|
|
@@ -2077,16 +1219,16 @@ class AgentChatController {
|
|
|
2077
1219
|
content: notice,
|
|
2078
1220
|
});
|
|
2079
1221
|
finalContent = finalContent ? `${finalContent}\n\n${notice}` : notice;
|
|
2080
|
-
appendAssistantNotice(sessionMessagesToRecord, notice);
|
|
1222
|
+
(0, chat_trace_1.appendAssistantNotice)(sessionMessagesToRecord, notice);
|
|
2081
1223
|
if (pendingCompleteTrace) {
|
|
2082
1224
|
pendingCompleteTrace.finishReason = 'completion_gate';
|
|
2083
|
-
pendingCompleteTrace.contentBytes = byteLength(finalContent);
|
|
1225
|
+
pendingCompleteTrace.contentBytes = (0, chat_trace_1.byteLength)(finalContent);
|
|
2084
1226
|
pendingCompleteTrace.note = 'verification_incomplete';
|
|
2085
1227
|
}
|
|
2086
1228
|
const stats = pendingCompleteStats ?? this.runtime.store.getSnapshot().lastLoopStats;
|
|
2087
1229
|
if (stats) {
|
|
2088
1230
|
pendingCompleteStats = {
|
|
2089
|
-
...withVerificationLoopStats(stats, summary),
|
|
1231
|
+
...(0, chat_workspace_1.withVerificationLoopStats)(stats, summary),
|
|
2090
1232
|
finishReason: 'completion_gate',
|
|
2091
1233
|
};
|
|
2092
1234
|
}
|
|
@@ -2125,7 +1267,7 @@ class AgentChatController {
|
|
|
2125
1267
|
content: notice,
|
|
2126
1268
|
});
|
|
2127
1269
|
finalContent = finalContent ? `${finalContent}\n\n${notice}` : notice;
|
|
2128
|
-
appendAssistantNotice(sessionMessagesToRecord, notice);
|
|
1270
|
+
(0, chat_trace_1.appendAssistantNotice)(sessionMessagesToRecord, notice);
|
|
2129
1271
|
}
|
|
2130
1272
|
if (pendingCompleteStats) {
|
|
2131
1273
|
this.setLoopStats(this.foldSubagentUsage(pendingCompleteStats, subagentBundle));
|
|
@@ -2162,7 +1304,7 @@ class AgentChatController {
|
|
|
2162
1304
|
}
|
|
2163
1305
|
this.runtime.store.setContextUsage(pendingCompact.after);
|
|
2164
1306
|
if (sessionId) {
|
|
2165
|
-
recordTraceEvent(this.events, sessionId, {
|
|
1307
|
+
(0, chat_trace_1.recordTraceEvent)(this.events, sessionId, {
|
|
2166
1308
|
turnId,
|
|
2167
1309
|
type: 'compact_completed',
|
|
2168
1310
|
checkpointId: committedCheckpointId,
|
|
@@ -2179,11 +1321,11 @@ class AgentChatController {
|
|
|
2179
1321
|
}
|
|
2180
1322
|
catch (error) {
|
|
2181
1323
|
if (sessionId) {
|
|
2182
|
-
recordTraceEvent(this.events, sessionId, {
|
|
1324
|
+
(0, chat_trace_1.recordTraceEvent)(this.events, sessionId, {
|
|
2183
1325
|
turnId,
|
|
2184
1326
|
type: 'compact_failed',
|
|
2185
1327
|
model: finalModel || this.runtime.llm.getModel(),
|
|
2186
|
-
error: compactTraceError(error),
|
|
1328
|
+
error: (0, chat_trace_1.compactTraceError)(error),
|
|
2187
1329
|
note: pendingCompact.mode,
|
|
2188
1330
|
});
|
|
2189
1331
|
}
|
|
@@ -2214,10 +1356,10 @@ class AgentChatController {
|
|
|
2214
1356
|
});
|
|
2215
1357
|
const harnessState = harness.toJSON();
|
|
2216
1358
|
this.runtime.store.setState({ harnessState });
|
|
2217
|
-
emitHarnessDiagnostics(this.events, harnessState);
|
|
1359
|
+
(0, chat_trace_1.emitHarnessDiagnostics)(this.events, harnessState);
|
|
2218
1360
|
if (sessionId) {
|
|
2219
1361
|
if (pendingCompleteTrace) {
|
|
2220
|
-
recordTraceEvent(this.events, sessionId, pendingCompleteTrace);
|
|
1362
|
+
(0, chat_trace_1.recordTraceEvent)(this.events, sessionId, pendingCompleteTrace);
|
|
2221
1363
|
}
|
|
2222
1364
|
(0, session_storage_1.updateSessionSkills)(sessionId, appliedSkillNames);
|
|
2223
1365
|
(0, session_storage_1.updateSessionHarnessState)(sessionId, harnessState);
|
|
@@ -2230,7 +1372,7 @@ class AgentChatController {
|
|
|
2230
1372
|
}
|
|
2231
1373
|
catch (error) {
|
|
2232
1374
|
// v0.2.25: Provider retry exhausted is a recoverable turn failure.
|
|
2233
|
-
if (error instanceof
|
|
1375
|
+
if (error instanceof provider_resilience_1.ProviderRetryExhaustedError) {
|
|
2234
1376
|
const diag = error.diagnostics;
|
|
2235
1377
|
const attempts = diag?.attempts?.length ?? '?';
|
|
2236
1378
|
const kind = diag?.attempts?.[diag.attempts.length - 1]?.failureKind ?? 'unknown';
|
|
@@ -2254,12 +1396,12 @@ class AgentChatController {
|
|
|
2254
1396
|
}
|
|
2255
1397
|
return;
|
|
2256
1398
|
}
|
|
2257
|
-
if (isAbortError(error, abortSignal)) {
|
|
1399
|
+
if ((0, chat_trace_1.isAbortError)(error, abortSignal)) {
|
|
2258
1400
|
const interruptedStats = error instanceof framework_1.QueryLoopError
|
|
2259
1401
|
? error.stats
|
|
2260
1402
|
: (0, framework_1.createFailedLoopStats)({
|
|
2261
1403
|
loopBudget,
|
|
2262
|
-
diagnostics: observedLlmRequests > 0 ? getLastRequestDiagnostics(this.runtime.llm) : undefined,
|
|
1404
|
+
diagnostics: observedLlmRequests > 0 ? (0, chat_trace_1.getLastRequestDiagnostics)(this.runtime.llm) : undefined,
|
|
2263
1405
|
turnsStarted: observedTurnsStarted,
|
|
2264
1406
|
llmRequests: observedLlmRequests,
|
|
2265
1407
|
toolCalls: observedToolCalls,
|
|
@@ -2275,16 +1417,16 @@ class AgentChatController {
|
|
|
2275
1417
|
persistInterruptedAccounting(interruptedRootUsage, interruptedStats, interruptedStats.llmRequests === 0);
|
|
2276
1418
|
assistantStream.discardSegment();
|
|
2277
1419
|
this.events.setStatus('Interrupted.');
|
|
2278
|
-
removeTrailingUserMessage(this.runtime);
|
|
1420
|
+
(0, chat_presentation_1.removeTrailingUserMessage)(this.runtime);
|
|
2279
1421
|
if (sessionId) {
|
|
2280
|
-
const { delta } = appendPostWorkspaceTrace(this.events, sessionId, turnId, this.runtime.cwd, preWorkspace, verificationResults);
|
|
2281
|
-
recordTraceEvent(this.events, sessionId, {
|
|
1422
|
+
const { delta } = (0, chat_workspace_1.appendPostWorkspaceTrace)(this.events, sessionId, turnId, this.runtime.cwd, preWorkspace, verificationResults);
|
|
1423
|
+
(0, chat_trace_1.recordTraceEvent)(this.events, sessionId, {
|
|
2282
1424
|
turnId,
|
|
2283
1425
|
type: 'aborted',
|
|
2284
1426
|
note: 'abort_error',
|
|
2285
1427
|
});
|
|
2286
|
-
const recoveryNotice = workspaceDeltaHasTurnChanges(delta)
|
|
2287
|
-
? formatFailureRecoveryNotice(turnId, delta, checkpointIds)
|
|
1428
|
+
const recoveryNotice = (0, chat_workspace_1.workspaceDeltaHasTurnChanges)(delta)
|
|
1429
|
+
? (0, chat_workspace_1.formatFailureRecoveryNotice)(turnId, delta, checkpointIds)
|
|
2288
1430
|
: undefined;
|
|
2289
1431
|
if (recoveryNotice) {
|
|
2290
1432
|
this.events.append({
|
|
@@ -2301,15 +1443,15 @@ class AgentChatController {
|
|
|
2301
1443
|
assistantStream.discardSegment();
|
|
2302
1444
|
this.events.append({
|
|
2303
1445
|
role: 'error',
|
|
2304
|
-
content: formatChatError(error),
|
|
2305
|
-
errorLayer: errorLayerForChatError(error),
|
|
1446
|
+
content: (0, chat_trace_1.formatChatError)(error),
|
|
1447
|
+
errorLayer: (0, chat_trace_1.errorLayerForChatError)(error),
|
|
2306
1448
|
});
|
|
2307
1449
|
this.events.setStatus('Turn failed. Ready for the next input.');
|
|
2308
1450
|
const failedStats = this.foldSubagentUsage(error instanceof framework_1.QueryLoopError
|
|
2309
1451
|
? error.stats
|
|
2310
1452
|
: (0, framework_1.createFailedLoopStats)({
|
|
2311
1453
|
loopBudget,
|
|
2312
|
-
diagnostics: observedLlmRequests > 0 ? getLastRequestDiagnostics(this.runtime.llm) : undefined,
|
|
1454
|
+
diagnostics: observedLlmRequests > 0 ? (0, chat_trace_1.getLastRequestDiagnostics)(this.runtime.llm) : undefined,
|
|
2313
1455
|
turnsStarted: observedTurnsStarted,
|
|
2314
1456
|
llmRequests: observedLlmRequests,
|
|
2315
1457
|
toolCalls: observedToolCalls,
|
|
@@ -2329,10 +1471,10 @@ class AgentChatController {
|
|
|
2329
1471
|
}
|
|
2330
1472
|
this.setLoopStats(failedStats);
|
|
2331
1473
|
if (sessionId) {
|
|
2332
|
-
recordProviderTraceEvents(this.events, sessionId, turnId, failedStats);
|
|
2333
|
-
const { delta } = appendPostWorkspaceTrace(this.events, sessionId, turnId, this.runtime.cwd, preWorkspace, verificationResults);
|
|
2334
|
-
const recoveryNotice = workspaceDeltaHasTurnChanges(delta)
|
|
2335
|
-
? formatFailureRecoveryNotice(turnId, delta, checkpointIds)
|
|
1474
|
+
(0, chat_trace_1.recordProviderTraceEvents)(this.events, sessionId, turnId, failedStats);
|
|
1475
|
+
const { delta } = (0, chat_workspace_1.appendPostWorkspaceTrace)(this.events, sessionId, turnId, this.runtime.cwd, preWorkspace, verificationResults);
|
|
1476
|
+
const recoveryNotice = (0, chat_workspace_1.workspaceDeltaHasTurnChanges)(delta)
|
|
1477
|
+
? (0, chat_workspace_1.formatFailureRecoveryNotice)(turnId, delta, checkpointIds)
|
|
2336
1478
|
: undefined;
|
|
2337
1479
|
if (recoveryNotice) {
|
|
2338
1480
|
this.events.append({
|
|
@@ -2342,13 +1484,13 @@ class AgentChatController {
|
|
|
2342
1484
|
content: recoveryNotice,
|
|
2343
1485
|
});
|
|
2344
1486
|
}
|
|
2345
|
-
recordTraceEvent(this.events, sessionId, {
|
|
1487
|
+
(0, chat_trace_1.recordTraceEvent)(this.events, sessionId, {
|
|
2346
1488
|
turnId,
|
|
2347
1489
|
type: 'error',
|
|
2348
|
-
error: compactTraceError(error),
|
|
1490
|
+
error: (0, chat_trace_1.compactTraceError)(error),
|
|
2349
1491
|
note: recoveryNotice,
|
|
2350
1492
|
});
|
|
2351
|
-
recordTraceEvent(this.events, sessionId, {
|
|
1493
|
+
(0, chat_trace_1.recordTraceEvent)(this.events, sessionId, {
|
|
2352
1494
|
turnId,
|
|
2353
1495
|
type: 'complete',
|
|
2354
1496
|
model: failedStats.providerFinalModel ?? this.runtime.llm.getModel(),
|
|
@@ -2368,6 +1510,12 @@ class AgentChatController {
|
|
|
2368
1510
|
localFastPathUsed: failedStats.localFastPathUsed,
|
|
2369
1511
|
});
|
|
2370
1512
|
(0, session_storage_1.removeLastIncompleteAssistantMessage)(sessionId);
|
|
1513
|
+
// A failed turn must not leave the user's prompt dangling in the
|
|
1514
|
+
// persisted session (it would replay on resume). The in-memory history
|
|
1515
|
+
// is cleaned above (2969-2972); mirror that for the on-disk transcript.
|
|
1516
|
+
if (options.persistAsUserMessage !== false) {
|
|
1517
|
+
(0, session_storage_1.removeTrailingSessionUserMessage)(sessionId);
|
|
1518
|
+
}
|
|
2371
1519
|
}
|
|
2372
1520
|
const history = this.runtime.store.getSnapshot().conversationHistory;
|
|
2373
1521
|
if (history.length > 0) {
|