@orion-agents/orion-code 0.1.0
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/LICENSE +21 -0
- package/README.md +179 -0
- package/README.zh-CN.md +496 -0
- package/assets/orion-tui-icon.png +0 -0
- package/bin/orion +56 -0
- package/dist/agents/coder.d.ts +12 -0
- package/dist/agents/coder.d.ts.map +1 -0
- package/dist/agents/coder.js +48 -0
- package/dist/agents/coder.js.map +1 -0
- package/dist/agents/coordinator.d.ts +86 -0
- package/dist/agents/coordinator.d.ts.map +1 -0
- package/dist/agents/coordinator.js +251 -0
- package/dist/agents/coordinator.js.map +1 -0
- package/dist/agents/fork.d.ts +61 -0
- package/dist/agents/fork.d.ts.map +1 -0
- package/dist/agents/fork.js +168 -0
- package/dist/agents/fork.js.map +1 -0
- package/dist/agents/leader.d.ts +12 -0
- package/dist/agents/leader.d.ts.map +1 -0
- package/dist/agents/leader.js +49 -0
- package/dist/agents/leader.js.map +1 -0
- package/dist/agents/router.d.ts +59 -0
- package/dist/agents/router.d.ts.map +1 -0
- package/dist/agents/router.js +193 -0
- package/dist/agents/router.js.map +1 -0
- package/dist/agents/worker-pool.d.ts +72 -0
- package/dist/agents/worker-pool.d.ts.map +1 -0
- package/dist/agents/worker-pool.js +215 -0
- package/dist/agents/worker-pool.js.map +1 -0
- package/dist/cli.d.ts +5 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +393 -0
- package/dist/cli.js.map +1 -0
- package/dist/commands/index.d.ts +15 -0
- package/dist/commands/index.d.ts.map +1 -0
- package/dist/commands/index.js +3281 -0
- package/dist/commands/index.js.map +1 -0
- package/dist/commands/parser.d.ts +26 -0
- package/dist/commands/parser.d.ts.map +1 -0
- package/dist/commands/parser.js +66 -0
- package/dist/commands/parser.js.map +1 -0
- package/dist/commands/target-command.d.ts +21 -0
- package/dist/commands/target-command.d.ts.map +1 -0
- package/dist/commands/target-command.js +81 -0
- package/dist/commands/target-command.js.map +1 -0
- package/dist/commands/types.d.ts +96 -0
- package/dist/commands/types.d.ts.map +1 -0
- package/dist/commands/types.js +32 -0
- package/dist/commands/types.js.map +1 -0
- package/dist/core/agent.d.ts +84 -0
- package/dist/core/agent.d.ts.map +1 -0
- package/dist/core/agent.js +58 -0
- package/dist/core/agent.js.map +1 -0
- package/dist/core/brain.d.ts +50 -0
- package/dist/core/brain.d.ts.map +1 -0
- package/dist/core/brain.js +95 -0
- package/dist/core/brain.js.map +1 -0
- package/dist/core/checkpoint.d.ts +50 -0
- package/dist/core/checkpoint.d.ts.map +1 -0
- package/dist/core/checkpoint.js +284 -0
- package/dist/core/checkpoint.js.map +1 -0
- package/dist/core/cost-tracker.d.ts +147 -0
- package/dist/core/cost-tracker.d.ts.map +1 -0
- package/dist/core/cost-tracker.js +275 -0
- package/dist/core/cost-tracker.js.map +1 -0
- package/dist/core/security-warning.d.ts +59 -0
- package/dist/core/security-warning.d.ts.map +1 -0
- package/dist/core/security-warning.js +163 -0
- package/dist/core/security-warning.js.map +1 -0
- package/dist/core/strategy-tracker.d.ts +61 -0
- package/dist/core/strategy-tracker.d.ts.map +1 -0
- package/dist/core/strategy-tracker.js +124 -0
- package/dist/core/strategy-tracker.js.map +1 -0
- package/dist/core/tool-artifacts.d.ts +48 -0
- package/dist/core/tool-artifacts.d.ts.map +1 -0
- package/dist/core/tool-artifacts.js +216 -0
- package/dist/core/tool-artifacts.js.map +1 -0
- package/dist/core/warn-dedup.d.ts +39 -0
- package/dist/core/warn-dedup.d.ts.map +1 -0
- package/dist/core/warn-dedup.js +80 -0
- package/dist/core/warn-dedup.js.map +1 -0
- package/dist/framework/index.d.ts +25 -0
- package/dist/framework/index.d.ts.map +1 -0
- package/dist/framework/index.js +53 -0
- package/dist/framework/index.js.map +1 -0
- package/dist/framework/prompt.d.ts +48 -0
- package/dist/framework/prompt.d.ts.map +1 -0
- package/dist/framework/prompt.js +174 -0
- package/dist/framework/prompt.js.map +1 -0
- package/dist/framework/query.d.ts +250 -0
- package/dist/framework/query.d.ts.map +1 -0
- package/dist/framework/query.js +870 -0
- package/dist/framework/query.js.map +1 -0
- package/dist/framework/store.d.ts +79 -0
- package/dist/framework/store.d.ts.map +1 -0
- package/dist/framework/store.js +92 -0
- package/dist/framework/store.js.map +1 -0
- package/dist/framework/tool-scheduler.d.ts +115 -0
- package/dist/framework/tool-scheduler.d.ts.map +1 -0
- package/dist/framework/tool-scheduler.js +285 -0
- package/dist/framework/tool-scheduler.js.map +1 -0
- package/dist/framework/tool-serializer.d.ts +21 -0
- package/dist/framework/tool-serializer.d.ts.map +1 -0
- package/dist/framework/tool-serializer.js +68 -0
- package/dist/framework/tool-serializer.js.map +1 -0
- package/dist/framework/tool-state.d.ts +39 -0
- package/dist/framework/tool-state.d.ts.map +1 -0
- package/dist/framework/tool-state.js +44 -0
- package/dist/framework/tool-state.js.map +1 -0
- package/dist/framework/tool.d.ts +110 -0
- package/dist/framework/tool.d.ts.map +1 -0
- package/dist/framework/tool.js +60 -0
- package/dist/framework/tool.js.map +1 -0
- package/dist/harness/assembler.d.ts +17 -0
- package/dist/harness/assembler.d.ts.map +1 -0
- package/dist/harness/assembler.js +206 -0
- package/dist/harness/assembler.js.map +1 -0
- package/dist/harness/capsule.d.ts +6 -0
- package/dist/harness/capsule.d.ts.map +1 -0
- package/dist/harness/capsule.js +192 -0
- package/dist/harness/capsule.js.map +1 -0
- package/dist/harness/context-harness.d.ts +81 -0
- package/dist/harness/context-harness.d.ts.map +1 -0
- package/dist/harness/context-harness.js +278 -0
- package/dist/harness/context-harness.js.map +1 -0
- package/dist/harness/contract.d.ts +6 -0
- package/dist/harness/contract.d.ts.map +1 -0
- package/dist/harness/contract.js +130 -0
- package/dist/harness/contract.js.map +1 -0
- package/dist/harness/drift-guard.d.ts +12 -0
- package/dist/harness/drift-guard.d.ts.map +1 -0
- package/dist/harness/drift-guard.js +50 -0
- package/dist/harness/drift-guard.js.map +1 -0
- package/dist/harness/evidence.d.ts +20 -0
- package/dist/harness/evidence.d.ts.map +1 -0
- package/dist/harness/evidence.js +195 -0
- package/dist/harness/evidence.js.map +1 -0
- package/dist/harness/harness.d.ts +58 -0
- package/dist/harness/harness.d.ts.map +1 -0
- package/dist/harness/harness.js +195 -0
- package/dist/harness/harness.js.map +1 -0
- package/dist/harness/index.d.ts +16 -0
- package/dist/harness/index.d.ts.map +1 -0
- package/dist/harness/index.js +39 -0
- package/dist/harness/index.js.map +1 -0
- package/dist/harness/intent.d.ts +4 -0
- package/dist/harness/intent.d.ts.map +1 -0
- package/dist/harness/intent.js +153 -0
- package/dist/harness/intent.js.map +1 -0
- package/dist/harness/ledger.d.ts +31 -0
- package/dist/harness/ledger.d.ts.map +1 -0
- package/dist/harness/ledger.js +135 -0
- package/dist/harness/ledger.js.map +1 -0
- package/dist/harness/safety.d.ts +91 -0
- package/dist/harness/safety.d.ts.map +1 -0
- package/dist/harness/safety.js +210 -0
- package/dist/harness/safety.js.map +1 -0
- package/dist/harness/state.d.ts +12 -0
- package/dist/harness/state.d.ts.map +1 -0
- package/dist/harness/state.js +114 -0
- package/dist/harness/state.js.map +1 -0
- package/dist/harness/turn-summary.d.ts +25 -0
- package/dist/harness/turn-summary.d.ts.map +1 -0
- package/dist/harness/turn-summary.js +120 -0
- package/dist/harness/turn-summary.js.map +1 -0
- package/dist/harness/types.d.ts +187 -0
- package/dist/harness/types.d.ts.map +1 -0
- package/dist/harness/types.js +3 -0
- package/dist/harness/types.js.map +1 -0
- package/dist/index.d.ts +34 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +68 -0
- package/dist/index.js.map +1 -0
- package/dist/init.d.ts +112 -0
- package/dist/init.d.ts.map +1 -0
- package/dist/init.js +312 -0
- package/dist/init.js.map +1 -0
- package/dist/ink/index.d.ts +54 -0
- package/dist/ink/index.d.ts.map +1 -0
- package/dist/ink/index.js +111 -0
- package/dist/ink/index.js.map +1 -0
- package/dist/ink-ui/App.d.ts +9 -0
- package/dist/ink-ui/App.d.ts.map +1 -0
- package/dist/ink-ui/App.js +12 -0
- package/dist/ink-ui/App.js.map +1 -0
- package/dist/ink-ui/components/Markdown.d.ts +10 -0
- package/dist/ink-ui/components/Markdown.d.ts.map +1 -0
- package/dist/ink-ui/components/Markdown.js +210 -0
- package/dist/ink-ui/components/Markdown.js.map +1 -0
- package/dist/ink-ui/components/NativeCursor.d.ts +12 -0
- package/dist/ink-ui/components/NativeCursor.d.ts.map +1 -0
- package/dist/ink-ui/components/NativeCursor.js +35 -0
- package/dist/ink-ui/components/NativeCursor.js.map +1 -0
- package/dist/ink-ui/components/PixelHorseBanner.d.ts +8 -0
- package/dist/ink-ui/components/PixelHorseBanner.d.ts.map +1 -0
- package/dist/ink-ui/components/PixelHorseBanner.js +97 -0
- package/dist/ink-ui/components/PixelHorseBanner.js.map +1 -0
- package/dist/ink-ui/components/PromptInput.d.ts +13 -0
- package/dist/ink-ui/components/PromptInput.d.ts.map +1 -0
- package/dist/ink-ui/components/PromptInput.js +30 -0
- package/dist/ink-ui/components/PromptInput.js.map +1 -0
- package/dist/ink-ui/components/RunningHorseIndicator.d.ts +13 -0
- package/dist/ink-ui/components/RunningHorseIndicator.d.ts.map +1 -0
- package/dist/ink-ui/components/RunningHorseIndicator.js +53 -0
- package/dist/ink-ui/components/RunningHorseIndicator.js.map +1 -0
- package/dist/ink-ui/components/SelectList.d.ts +16 -0
- package/dist/ink-ui/components/SelectList.d.ts.map +1 -0
- package/dist/ink-ui/components/SelectList.js +60 -0
- package/dist/ink-ui/components/SelectList.js.map +1 -0
- package/dist/ink-ui/components/StatusLine.d.ts +11 -0
- package/dist/ink-ui/components/StatusLine.d.ts.map +1 -0
- package/dist/ink-ui/components/StatusLine.js +70 -0
- package/dist/ink-ui/components/StatusLine.js.map +1 -0
- package/dist/ink-ui/components/ToolActivity.d.ts +19 -0
- package/dist/ink-ui/components/ToolActivity.d.ts.map +1 -0
- package/dist/ink-ui/components/ToolActivity.js +134 -0
- package/dist/ink-ui/components/ToolActivity.js.map +1 -0
- package/dist/ink-ui/components/Transcript.d.ts +14 -0
- package/dist/ink-ui/components/Transcript.d.ts.map +1 -0
- package/dist/ink-ui/components/Transcript.js +66 -0
- package/dist/ink-ui/components/Transcript.js.map +1 -0
- package/dist/ink-ui/controllers/chat-controller.d.ts +2 -0
- package/dist/ink-ui/controllers/chat-controller.d.ts.map +1 -0
- package/dist/ink-ui/controllers/chat-controller.js +18 -0
- package/dist/ink-ui/controllers/chat-controller.js.map +1 -0
- package/dist/ink-ui/hooks/use-raw-input-bridge.d.ts +6 -0
- package/dist/ink-ui/hooks/use-raw-input-bridge.d.ts.map +1 -0
- package/dist/ink-ui/hooks/use-raw-input-bridge.js +27 -0
- package/dist/ink-ui/hooks/use-raw-input-bridge.js.map +1 -0
- package/dist/ink-ui/hooks/use-terminal-size.d.ts +7 -0
- package/dist/ink-ui/hooks/use-terminal-size.d.ts.map +1 -0
- package/dist/ink-ui/hooks/use-terminal-size.js +34 -0
- package/dist/ink-ui/hooks/use-terminal-size.js.map +1 -0
- package/dist/ink-ui/launch.d.ts +9 -0
- package/dist/ink-ui/launch.d.ts.map +1 -0
- package/dist/ink-ui/launch.js +101 -0
- package/dist/ink-ui/launch.js.map +1 -0
- package/dist/ink-ui/runtime/grapheme.d.ts +10 -0
- package/dist/ink-ui/runtime/grapheme.d.ts.map +1 -0
- package/dist/ink-ui/runtime/grapheme.js +17 -0
- package/dist/ink-ui/runtime/grapheme.js.map +1 -0
- package/dist/ink-ui/runtime/input-buffer.d.ts +10 -0
- package/dist/ink-ui/runtime/input-buffer.d.ts.map +1 -0
- package/dist/ink-ui/runtime/input-buffer.js +18 -0
- package/dist/ink-ui/runtime/input-buffer.js.map +1 -0
- package/dist/ink-ui/runtime/layout-budget.d.ts +13 -0
- package/dist/ink-ui/runtime/layout-budget.d.ts.map +1 -0
- package/dist/ink-ui/runtime/layout-budget.js +25 -0
- package/dist/ink-ui/runtime/layout-budget.js.map +1 -0
- package/dist/ink-ui/runtime/native-cursor.d.ts +62 -0
- package/dist/ink-ui/runtime/native-cursor.d.ts.map +1 -0
- package/dist/ink-ui/runtime/native-cursor.js +398 -0
- package/dist/ink-ui/runtime/native-cursor.js.map +1 -0
- package/dist/ink-ui/runtime/prompt-layout.d.ts +10 -0
- package/dist/ink-ui/runtime/prompt-layout.d.ts.map +1 -0
- package/dist/ink-ui/runtime/prompt-layout.js +21 -0
- package/dist/ink-ui/runtime/prompt-layout.js.map +1 -0
- package/dist/ink-ui/runtime/raw-input.d.ts +4 -0
- package/dist/ink-ui/runtime/raw-input.d.ts.map +1 -0
- package/dist/ink-ui/runtime/raw-input.js +15 -0
- package/dist/ink-ui/runtime/raw-input.js.map +1 -0
- package/dist/ink-ui/runtime/transcript-state.d.ts +37 -0
- package/dist/ink-ui/runtime/transcript-state.d.ts.map +1 -0
- package/dist/ink-ui/runtime/transcript-state.js +91 -0
- package/dist/ink-ui/runtime/transcript-state.js.map +1 -0
- package/dist/ink-ui/screens/ReplScreen.d.ts +22 -0
- package/dist/ink-ui/screens/ReplScreen.d.ts.map +1 -0
- package/dist/ink-ui/screens/ReplScreen.js +616 -0
- package/dist/ink-ui/screens/ReplScreen.js.map +1 -0
- package/dist/ink-ui/types.d.ts +2 -0
- package/dist/ink-ui/types.d.ts.map +1 -0
- package/dist/ink-ui/types.js +18 -0
- package/dist/ink-ui/types.js.map +1 -0
- package/dist/memory/embeddings.d.ts +33 -0
- package/dist/memory/embeddings.d.ts.map +1 -0
- package/dist/memory/embeddings.js +138 -0
- package/dist/memory/embeddings.js.map +1 -0
- package/dist/memory/entrypoint.d.ts +55 -0
- package/dist/memory/entrypoint.d.ts.map +1 -0
- package/dist/memory/entrypoint.js +151 -0
- package/dist/memory/entrypoint.js.map +1 -0
- package/dist/memory/index.d.ts +14 -0
- package/dist/memory/index.d.ts.map +1 -0
- package/dist/memory/index.js +31 -0
- package/dist/memory/index.js.map +1 -0
- package/dist/memory/prompts.d.ts +12 -0
- package/dist/memory/prompts.d.ts.map +1 -0
- package/dist/memory/prompts.js +117 -0
- package/dist/memory/prompts.js.map +1 -0
- package/dist/memory/relevant-finder.d.ts +54 -0
- package/dist/memory/relevant-finder.d.ts.map +1 -0
- package/dist/memory/relevant-finder.js +157 -0
- package/dist/memory/relevant-finder.js.map +1 -0
- package/dist/memory/semantic-search.d.ts +45 -0
- package/dist/memory/semantic-search.d.ts.map +1 -0
- package/dist/memory/semantic-search.js +113 -0
- package/dist/memory/semantic-search.js.map +1 -0
- package/dist/memory/storage.d.ts +86 -0
- package/dist/memory/storage.d.ts.map +1 -0
- package/dist/memory/storage.js +339 -0
- package/dist/memory/storage.js.map +1 -0
- package/dist/memory/store.d.ts +104 -0
- package/dist/memory/store.d.ts.map +1 -0
- package/dist/memory/store.js +235 -0
- package/dist/memory/store.js.map +1 -0
- package/dist/memory/team-paths.d.ts +63 -0
- package/dist/memory/team-paths.d.ts.map +1 -0
- package/dist/memory/team-paths.js +151 -0
- package/dist/memory/team-paths.js.map +1 -0
- package/dist/memory/types.d.ts +40 -0
- package/dist/memory/types.d.ts.map +1 -0
- package/dist/memory/types.js +71 -0
- package/dist/memory/types.js.map +1 -0
- package/dist/memory/validation.d.ts +28 -0
- package/dist/memory/validation.d.ts.map +1 -0
- package/dist/memory/validation.js +147 -0
- package/dist/memory/validation.js.map +1 -0
- package/dist/memory/vector-store.d.ts +69 -0
- package/dist/memory/vector-store.d.ts.map +1 -0
- package/dist/memory/vector-store.js +356 -0
- package/dist/memory/vector-store.js.map +1 -0
- package/dist/migration/command.d.ts +9 -0
- package/dist/migration/command.d.ts.map +1 -0
- package/dist/migration/command.js +96 -0
- package/dist/migration/command.js.map +1 -0
- package/dist/migration/index.d.ts +7 -0
- package/dist/migration/index.d.ts.map +1 -0
- package/dist/migration/index.js +14 -0
- package/dist/migration/index.js.map +1 -0
- package/dist/migration/migrate.d.ts +19 -0
- package/dist/migration/migrate.d.ts.map +1 -0
- package/dist/migration/migrate.js +459 -0
- package/dist/migration/migrate.js.map +1 -0
- package/dist/migration/types.d.ts +56 -0
- package/dist/migration/types.d.ts.map +1 -0
- package/dist/migration/types.js +6 -0
- package/dist/migration/types.js.map +1 -0
- package/dist/print-ui/launch.d.ts +50 -0
- package/dist/print-ui/launch.d.ts.map +1 -0
- package/dist/print-ui/launch.js +225 -0
- package/dist/print-ui/launch.js.map +1 -0
- package/dist/product/environment.d.ts +37 -0
- package/dist/product/environment.d.ts.map +1 -0
- package/dist/product/environment.js +72 -0
- package/dist/product/environment.js.map +1 -0
- package/dist/product/identity.d.ts +39 -0
- package/dist/product/identity.d.ts.map +1 -0
- package/dist/product/identity.js +46 -0
- package/dist/product/identity.js.map +1 -0
- package/dist/product/index.d.ts +4 -0
- package/dist/product/index.d.ts.map +1 -0
- package/dist/product/index.js +63 -0
- package/dist/product/index.js.map +1 -0
- package/dist/product/paths.d.ts +61 -0
- package/dist/product/paths.d.ts.map +1 -0
- package/dist/product/paths.js +243 -0
- package/dist/product/paths.js.map +1 -0
- package/dist/runtime/agent-runtime-controller.d.ts +85 -0
- package/dist/runtime/agent-runtime-controller.d.ts.map +1 -0
- package/dist/runtime/agent-runtime-controller.js +417 -0
- package/dist/runtime/agent-runtime-controller.js.map +1 -0
- package/dist/runtime/agent-runtime-protocol.d.ts +118 -0
- package/dist/runtime/agent-runtime-protocol.d.ts.map +1 -0
- package/dist/runtime/agent-runtime-protocol.js +128 -0
- package/dist/runtime/agent-runtime-protocol.js.map +1 -0
- package/dist/runtime/agent-status.d.ts +9 -0
- package/dist/runtime/agent-status.d.ts.map +1 -0
- package/dist/runtime/agent-status.js +41 -0
- package/dist/runtime/agent-status.js.map +1 -0
- package/dist/runtime/aggregate-tool-presenter.d.ts +13 -0
- package/dist/runtime/aggregate-tool-presenter.d.ts.map +1 -0
- package/dist/runtime/aggregate-tool-presenter.js +44 -0
- package/dist/runtime/aggregate-tool-presenter.js.map +1 -0
- package/dist/runtime/chat-controller.d.ts +89 -0
- package/dist/runtime/chat-controller.d.ts.map +1 -0
- package/dist/runtime/chat-controller.js +2183 -0
- package/dist/runtime/chat-controller.js.map +1 -0
- package/dist/runtime/composer/buffer.d.ts +43 -0
- package/dist/runtime/composer/buffer.d.ts.map +1 -0
- package/dist/runtime/composer/buffer.js +176 -0
- package/dist/runtime/composer/buffer.js.map +1 -0
- package/dist/runtime/composer/grapheme.d.ts +19 -0
- package/dist/runtime/composer/grapheme.d.ts.map +1 -0
- package/dist/runtime/composer/grapheme.js +73 -0
- package/dist/runtime/composer/grapheme.js.map +1 -0
- package/dist/runtime/composer/history.d.ts +39 -0
- package/dist/runtime/composer/history.d.ts.map +1 -0
- package/dist/runtime/composer/history.js +91 -0
- package/dist/runtime/composer/history.js.map +1 -0
- package/dist/runtime/composer/layout.d.ts +40 -0
- package/dist/runtime/composer/layout.d.ts.map +1 -0
- package/dist/runtime/composer/layout.js +174 -0
- package/dist/runtime/composer/layout.js.map +1 -0
- package/dist/runtime/goals/accounting.d.ts +17 -0
- package/dist/runtime/goals/accounting.d.ts.map +1 -0
- package/dist/runtime/goals/accounting.js +45 -0
- package/dist/runtime/goals/accounting.js.map +1 -0
- package/dist/runtime/goals/completion-audit.d.ts +24 -0
- package/dist/runtime/goals/completion-audit.d.ts.map +1 -0
- package/dist/runtime/goals/completion-audit.js +48 -0
- package/dist/runtime/goals/completion-audit.js.map +1 -0
- package/dist/runtime/goals/coordinator.d.ts +42 -0
- package/dist/runtime/goals/coordinator.d.ts.map +1 -0
- package/dist/runtime/goals/coordinator.js +278 -0
- package/dist/runtime/goals/coordinator.js.map +1 -0
- package/dist/runtime/goals/prompt.d.ts +16 -0
- package/dist/runtime/goals/prompt.d.ts.map +1 -0
- package/dist/runtime/goals/prompt.js +50 -0
- package/dist/runtime/goals/prompt.js.map +1 -0
- package/dist/runtime/goals/tools.d.ts +18 -0
- package/dist/runtime/goals/tools.d.ts.map +1 -0
- package/dist/runtime/goals/tools.js +118 -0
- package/dist/runtime/goals/tools.js.map +1 -0
- package/dist/runtime/goals/types.d.ts +167 -0
- package/dist/runtime/goals/types.d.ts.map +1 -0
- package/dist/runtime/goals/types.js +72 -0
- package/dist/runtime/goals/types.js.map +1 -0
- package/dist/runtime/loop-budget.d.ts +5 -0
- package/dist/runtime/loop-budget.d.ts.map +1 -0
- package/dist/runtime/loop-budget.js +77 -0
- package/dist/runtime/loop-budget.js.map +1 -0
- package/dist/runtime/model-coordinator.d.ts +54 -0
- package/dist/runtime/model-coordinator.d.ts.map +1 -0
- package/dist/runtime/model-coordinator.js +121 -0
- package/dist/runtime/model-coordinator.js.map +1 -0
- package/dist/runtime/rich-text/ansi-parser.d.ts +31 -0
- package/dist/runtime/rich-text/ansi-parser.d.ts.map +1 -0
- package/dist/runtime/rich-text/ansi-parser.js +310 -0
- package/dist/runtime/rich-text/ansi-parser.js.map +1 -0
- package/dist/runtime/rich-text/layout.d.ts +12 -0
- package/dist/runtime/rich-text/layout.d.ts.map +1 -0
- package/dist/runtime/rich-text/layout.js +362 -0
- package/dist/runtime/rich-text/layout.js.map +1 -0
- package/dist/runtime/rich-text/markdown-parser.d.ts +17 -0
- package/dist/runtime/rich-text/markdown-parser.d.ts.map +1 -0
- package/dist/runtime/rich-text/markdown-parser.js +218 -0
- package/dist/runtime/rich-text/markdown-parser.js.map +1 -0
- package/dist/runtime/rich-text/sanitizer.d.ts +18 -0
- package/dist/runtime/rich-text/sanitizer.d.ts.map +1 -0
- package/dist/runtime/rich-text/sanitizer.js +32 -0
- package/dist/runtime/rich-text/sanitizer.js.map +1 -0
- package/dist/runtime/rich-text/types.d.ts +59 -0
- package/dist/runtime/rich-text/types.d.ts.map +1 -0
- package/dist/runtime/rich-text/types.js +17 -0
- package/dist/runtime/rich-text/types.js.map +1 -0
- package/dist/runtime/subagents/budget.d.ts +118 -0
- package/dist/runtime/subagents/budget.d.ts.map +1 -0
- package/dist/runtime/subagents/budget.js +173 -0
- package/dist/runtime/subagents/budget.js.map +1 -0
- package/dist/runtime/subagents/child-executor-guard.d.ts +60 -0
- package/dist/runtime/subagents/child-executor-guard.d.ts.map +1 -0
- package/dist/runtime/subagents/child-executor-guard.js +219 -0
- package/dist/runtime/subagents/child-executor-guard.js.map +1 -0
- package/dist/runtime/subagents/context-builder.d.ts +34 -0
- package/dist/runtime/subagents/context-builder.d.ts.map +1 -0
- package/dist/runtime/subagents/context-builder.js +99 -0
- package/dist/runtime/subagents/context-builder.js.map +1 -0
- package/dist/runtime/subagents/index.d.ts +21 -0
- package/dist/runtime/subagents/index.d.ts.map +1 -0
- package/dist/runtime/subagents/index.js +62 -0
- package/dist/runtime/subagents/index.js.map +1 -0
- package/dist/runtime/subagents/policy.d.ts +68 -0
- package/dist/runtime/subagents/policy.d.ts.map +1 -0
- package/dist/runtime/subagents/policy.js +230 -0
- package/dist/runtime/subagents/policy.js.map +1 -0
- package/dist/runtime/subagents/presets.d.ts +44 -0
- package/dist/runtime/subagents/presets.d.ts.map +1 -0
- package/dist/runtime/subagents/presets.js +148 -0
- package/dist/runtime/subagents/presets.js.map +1 -0
- package/dist/runtime/subagents/production.d.ts +47 -0
- package/dist/runtime/subagents/production.d.ts.map +1 -0
- package/dist/runtime/subagents/production.js +148 -0
- package/dist/runtime/subagents/production.js.map +1 -0
- package/dist/runtime/subagents/provider-gate.d.ts +104 -0
- package/dist/runtime/subagents/provider-gate.d.ts.map +1 -0
- package/dist/runtime/subagents/provider-gate.js +192 -0
- package/dist/runtime/subagents/provider-gate.js.map +1 -0
- package/dist/runtime/subagents/result-parser.d.ts +40 -0
- package/dist/runtime/subagents/result-parser.d.ts.map +1 -0
- package/dist/runtime/subagents/result-parser.js +240 -0
- package/dist/runtime/subagents/result-parser.js.map +1 -0
- package/dist/runtime/subagents/runner.d.ts +53 -0
- package/dist/runtime/subagents/runner.d.ts.map +1 -0
- package/dist/runtime/subagents/runner.js +172 -0
- package/dist/runtime/subagents/runner.js.map +1 -0
- package/dist/runtime/subagents/runtime-integration.d.ts +76 -0
- package/dist/runtime/subagents/runtime-integration.d.ts.map +1 -0
- package/dist/runtime/subagents/runtime-integration.js +152 -0
- package/dist/runtime/subagents/runtime-integration.js.map +1 -0
- package/dist/runtime/subagents/supervisor.d.ts +79 -0
- package/dist/runtime/subagents/supervisor.d.ts.map +1 -0
- package/dist/runtime/subagents/supervisor.js +301 -0
- package/dist/runtime/subagents/supervisor.js.map +1 -0
- package/dist/runtime/subagents/tool.d.ts +38 -0
- package/dist/runtime/subagents/tool.d.ts.map +1 -0
- package/dist/runtime/subagents/tool.js +171 -0
- package/dist/runtime/subagents/tool.js.map +1 -0
- package/dist/runtime/subagents/types.d.ts +152 -0
- package/dist/runtime/subagents/types.d.ts.map +1 -0
- package/dist/runtime/subagents/types.js +56 -0
- package/dist/runtime/subagents/types.js.map +1 -0
- package/dist/runtime/tool-detail-repository.d.ts +45 -0
- package/dist/runtime/tool-detail-repository.d.ts.map +1 -0
- package/dist/runtime/tool-detail-repository.js +131 -0
- package/dist/runtime/tool-detail-repository.js.map +1 -0
- package/dist/runtime/tool-output-presentation.d.ts +89 -0
- package/dist/runtime/tool-output-presentation.d.ts.map +1 -0
- package/dist/runtime/tool-output-presentation.js +329 -0
- package/dist/runtime/tool-output-presentation.js.map +1 -0
- package/dist/runtime/turn-controller.d.ts +41 -0
- package/dist/runtime/turn-controller.d.ts.map +1 -0
- package/dist/runtime/turn-controller.js +92 -0
- package/dist/runtime/turn-controller.js.map +1 -0
- package/dist/runtime/ui-events.d.ts +188 -0
- package/dist/runtime/ui-events.d.ts.map +1 -0
- package/dist/runtime/ui-events.js +37 -0
- package/dist/runtime/ui-events.js.map +1 -0
- package/dist/runtime/ui-view-model.d.ts +362 -0
- package/dist/runtime/ui-view-model.d.ts.map +1 -0
- package/dist/runtime/ui-view-model.js +700 -0
- package/dist/runtime/ui-view-model.js.map +1 -0
- package/dist/sdk/index.d.ts +10 -0
- package/dist/sdk/index.d.ts.map +1 -0
- package/dist/sdk/index.js +23 -0
- package/dist/sdk/index.js.map +1 -0
- package/dist/sdk/init.d.ts +24 -0
- package/dist/sdk/init.d.ts.map +1 -0
- package/dist/sdk/init.js +48 -0
- package/dist/sdk/init.js.map +1 -0
- package/dist/sdk/query.d.ts +19 -0
- package/dist/sdk/query.d.ts.map +1 -0
- package/dist/sdk/query.js +42 -0
- package/dist/sdk/query.js.map +1 -0
- package/dist/sdk/sessions.d.ts +19 -0
- package/dist/sdk/sessions.d.ts.map +1 -0
- package/dist/sdk/sessions.js +57 -0
- package/dist/sdk/sessions.js.map +1 -0
- package/dist/sdk/types.d.ts +47 -0
- package/dist/sdk/types.d.ts.map +1 -0
- package/dist/sdk/types.js +8 -0
- package/dist/sdk/types.js.map +1 -0
- package/dist/services/agent-runner.d.ts +68 -0
- package/dist/services/agent-runner.d.ts.map +1 -0
- package/dist/services/agent-runner.js +185 -0
- package/dist/services/agent-runner.js.map +1 -0
- package/dist/services/atomic-write.d.ts +12 -0
- package/dist/services/atomic-write.d.ts.map +1 -0
- package/dist/services/atomic-write.js +27 -0
- package/dist/services/atomic-write.js.map +1 -0
- package/dist/services/auth/auth.d.ts +121 -0
- package/dist/services/auth/auth.d.ts.map +1 -0
- package/dist/services/auth/auth.js +233 -0
- package/dist/services/auth/auth.js.map +1 -0
- package/dist/services/auth/aws.d.ts +27 -0
- package/dist/services/auth/aws.d.ts.map +1 -0
- package/dist/services/auth/aws.js +109 -0
- package/dist/services/auth/aws.js.map +1 -0
- package/dist/services/auth/index.d.ts +6 -0
- package/dist/services/auth/index.d.ts.map +1 -0
- package/dist/services/auth/index.js +17 -0
- package/dist/services/auth/index.js.map +1 -0
- package/dist/services/auto-fix/autoFixConfig.d.ts +33 -0
- package/dist/services/auto-fix/autoFixConfig.d.ts.map +1 -0
- package/dist/services/auto-fix/autoFixConfig.js +61 -0
- package/dist/services/auto-fix/autoFixConfig.js.map +1 -0
- package/dist/services/auto-fix/autoFixHook.d.ts +20 -0
- package/dist/services/auto-fix/autoFixHook.d.ts.map +1 -0
- package/dist/services/auto-fix/autoFixHook.js +90 -0
- package/dist/services/auto-fix/autoFixHook.js.map +1 -0
- package/dist/services/auto-fix/autoFixRunner.d.ts +60 -0
- package/dist/services/auto-fix/autoFixRunner.d.ts.map +1 -0
- package/dist/services/auto-fix/autoFixRunner.js +207 -0
- package/dist/services/auto-fix/autoFixRunner.js.map +1 -0
- package/dist/services/auto-fix/index.d.ts +7 -0
- package/dist/services/auto-fix/index.d.ts.map +1 -0
- package/dist/services/auto-fix/index.js +17 -0
- package/dist/services/auto-fix/index.js.map +1 -0
- package/dist/services/commit-plan.d.ts +17 -0
- package/dist/services/commit-plan.d.ts.map +1 -0
- package/dist/services/commit-plan.js +161 -0
- package/dist/services/commit-plan.js.map +1 -0
- package/dist/services/compact/auto-compact.d.ts +119 -0
- package/dist/services/compact/auto-compact.d.ts.map +1 -0
- package/dist/services/compact/auto-compact.js +273 -0
- package/dist/services/compact/auto-compact.js.map +1 -0
- package/dist/services/compact/compact.d.ts +65 -0
- package/dist/services/compact/compact.d.ts.map +1 -0
- package/dist/services/compact/compact.js +162 -0
- package/dist/services/compact/compact.js.map +1 -0
- package/dist/services/compact/coordinator.d.ts +26 -0
- package/dist/services/compact/coordinator.d.ts.map +1 -0
- package/dist/services/compact/coordinator.js +44 -0
- package/dist/services/compact/coordinator.js.map +1 -0
- package/dist/services/compact/index.d.ts +11 -0
- package/dist/services/compact/index.d.ts.map +1 -0
- package/dist/services/compact/index.js +25 -0
- package/dist/services/compact/index.js.map +1 -0
- package/dist/services/compact/micro-compact.d.ts +21 -0
- package/dist/services/compact/micro-compact.d.ts.map +1 -0
- package/dist/services/compact/micro-compact.js +99 -0
- package/dist/services/compact/micro-compact.js.map +1 -0
- package/dist/services/compact/summary-generator.d.ts +40 -0
- package/dist/services/compact/summary-generator.d.ts.map +1 -0
- package/dist/services/compact/summary-generator.js +226 -0
- package/dist/services/compact/summary-generator.js.map +1 -0
- package/dist/services/concurrent-sessions.d.ts +97 -0
- package/dist/services/concurrent-sessions.d.ts.map +1 -0
- package/dist/services/concurrent-sessions.js +265 -0
- package/dist/services/concurrent-sessions.js.map +1 -0
- package/dist/services/config-dir.d.ts +18 -0
- package/dist/services/config-dir.d.ts.map +1 -0
- package/dist/services/config-dir.js +118 -0
- package/dist/services/config-dir.js.map +1 -0
- package/dist/services/config.d.ts +55 -0
- package/dist/services/config.d.ts.map +1 -0
- package/dist/services/config.js +351 -0
- package/dist/services/config.js.map +1 -0
- package/dist/services/diagnostic-tracking/diagnosticTracking.d.ts +58 -0
- package/dist/services/diagnostic-tracking/diagnosticTracking.d.ts.map +1 -0
- package/dist/services/diagnostic-tracking/diagnosticTracking.js +167 -0
- package/dist/services/diagnostic-tracking/diagnosticTracking.js.map +1 -0
- package/dist/services/diagnostic-tracking/formatter.d.ts +17 -0
- package/dist/services/diagnostic-tracking/formatter.d.ts.map +1 -0
- package/dist/services/diagnostic-tracking/formatter.js +78 -0
- package/dist/services/diagnostic-tracking/formatter.js.map +1 -0
- package/dist/services/diagnostic-tracking/index.d.ts +7 -0
- package/dist/services/diagnostic-tracking/index.d.ts.map +1 -0
- package/dist/services/diagnostic-tracking/index.js +19 -0
- package/dist/services/diagnostic-tracking/index.js.map +1 -0
- package/dist/services/diagnostic-tracking/types.d.ts +52 -0
- package/dist/services/diagnostic-tracking/types.d.ts.map +1 -0
- package/dist/services/diagnostic-tracking/types.js +27 -0
- package/dist/services/diagnostic-tracking/types.js.map +1 -0
- package/dist/services/doctor.d.ts +35 -0
- package/dist/services/doctor.d.ts.map +1 -0
- package/dist/services/doctor.js +417 -0
- package/dist/services/doctor.js.map +1 -0
- package/dist/services/file-context.d.ts +21 -0
- package/dist/services/file-context.d.ts.map +1 -0
- package/dist/services/file-context.js +194 -0
- package/dist/services/file-context.js.map +1 -0
- package/dist/services/file-glob.d.ts +30 -0
- package/dist/services/file-glob.d.ts.map +1 -0
- package/dist/services/file-glob.js +140 -0
- package/dist/services/file-glob.js.map +1 -0
- package/dist/services/format.d.ts +2 -0
- package/dist/services/format.d.ts.map +1 -0
- package/dist/services/format.js +20 -0
- package/dist/services/format.js.map +1 -0
- package/dist/services/global-config.d.ts +161 -0
- package/dist/services/global-config.d.ts.map +1 -0
- package/dist/services/global-config.js +166 -0
- package/dist/services/global-config.js.map +1 -0
- package/dist/services/goal-storage.d.ts +22 -0
- package/dist/services/goal-storage.d.ts.map +1 -0
- package/dist/services/goal-storage.js +153 -0
- package/dist/services/goal-storage.js.map +1 -0
- package/dist/services/llm.d.ts +190 -0
- package/dist/services/llm.d.ts.map +1 -0
- package/dist/services/llm.js +740 -0
- package/dist/services/llm.js.map +1 -0
- package/dist/services/mcp/index.d.ts +5 -0
- package/dist/services/mcp/index.d.ts.map +1 -0
- package/dist/services/mcp/index.js +16 -0
- package/dist/services/mcp/index.js.map +1 -0
- package/dist/services/mcp/transports.d.ts +106 -0
- package/dist/services/mcp/transports.d.ts.map +1 -0
- package/dist/services/mcp/transports.js +375 -0
- package/dist/services/mcp/transports.js.map +1 -0
- package/dist/services/memory.d.ts +39 -0
- package/dist/services/memory.d.ts.map +1 -0
- package/dist/services/memory.js +88 -0
- package/dist/services/memory.js.map +1 -0
- package/dist/services/model-catalog.d.ts +14 -0
- package/dist/services/model-catalog.d.ts.map +1 -0
- package/dist/services/model-catalog.js +73 -0
- package/dist/services/model-catalog.js.map +1 -0
- package/dist/services/model-client-pool.d.ts +37 -0
- package/dist/services/model-client-pool.d.ts.map +1 -0
- package/dist/services/model-client-pool.js +88 -0
- package/dist/services/model-client-pool.js.map +1 -0
- package/dist/services/model-context.d.ts +89 -0
- package/dist/services/model-context.d.ts.map +1 -0
- package/dist/services/model-context.js +395 -0
- package/dist/services/model-context.js.map +1 -0
- package/dist/services/model-registry.d.ts +98 -0
- package/dist/services/model-registry.d.ts.map +1 -0
- package/dist/services/model-registry.js +271 -0
- package/dist/services/model-registry.js.map +1 -0
- package/dist/services/project-instructions.d.ts +16 -0
- package/dist/services/project-instructions.d.ts.map +1 -0
- package/dist/services/project-instructions.js +135 -0
- package/dist/services/project-instructions.js.map +1 -0
- package/dist/services/prompt-context.d.ts +3 -0
- package/dist/services/prompt-context.d.ts.map +1 -0
- package/dist/services/prompt-context.js +13 -0
- package/dist/services/prompt-context.js.map +1 -0
- package/dist/services/provider-diagnostics.d.ts +30 -0
- package/dist/services/provider-diagnostics.d.ts.map +1 -0
- package/dist/services/provider-diagnostics.js +314 -0
- package/dist/services/provider-diagnostics.js.map +1 -0
- package/dist/services/provider-resilience/circuit-breaker.d.ts +32 -0
- package/dist/services/provider-resilience/circuit-breaker.d.ts.map +1 -0
- package/dist/services/provider-resilience/circuit-breaker.js +88 -0
- package/dist/services/provider-resilience/circuit-breaker.js.map +1 -0
- package/dist/services/provider-resilience/coordinator.d.ts +38 -0
- package/dist/services/provider-resilience/coordinator.d.ts.map +1 -0
- package/dist/services/provider-resilience/coordinator.js +155 -0
- package/dist/services/provider-resilience/coordinator.js.map +1 -0
- package/dist/services/provider-resilience/error-classifier.d.ts +15 -0
- package/dist/services/provider-resilience/error-classifier.d.ts.map +1 -0
- package/dist/services/provider-resilience/error-classifier.js +162 -0
- package/dist/services/provider-resilience/error-classifier.js.map +1 -0
- package/dist/services/provider-resilience/index.d.ts +10 -0
- package/dist/services/provider-resilience/index.d.ts.map +1 -0
- package/dist/services/provider-resilience/index.js +23 -0
- package/dist/services/provider-resilience/index.js.map +1 -0
- package/dist/services/provider-resilience/request-gate.d.ts +41 -0
- package/dist/services/provider-resilience/request-gate.d.ts.map +1 -0
- package/dist/services/provider-resilience/request-gate.js +82 -0
- package/dist/services/provider-resilience/request-gate.js.map +1 -0
- package/dist/services/provider-resilience/stream-recovery.d.ts +46 -0
- package/dist/services/provider-resilience/stream-recovery.d.ts.map +1 -0
- package/dist/services/provider-resilience/stream-recovery.js +106 -0
- package/dist/services/provider-resilience/stream-recovery.js.map +1 -0
- package/dist/services/provider-resilience/types.d.ts +100 -0
- package/dist/services/provider-resilience/types.d.ts.map +1 -0
- package/dist/services/provider-resilience/types.js +22 -0
- package/dist/services/provider-resilience/types.js.map +1 -0
- package/dist/services/redaction.d.ts +2 -0
- package/dist/services/redaction.d.ts.map +1 -0
- package/dist/services/redaction.js +27 -0
- package/dist/services/redaction.js.map +1 -0
- package/dist/services/session-index.d.ts +50 -0
- package/dist/services/session-index.d.ts.map +1 -0
- package/dist/services/session-index.js +196 -0
- package/dist/services/session-index.js.map +1 -0
- package/dist/services/session-memory/index.d.ts +6 -0
- package/dist/services/session-memory/index.d.ts.map +1 -0
- package/dist/services/session-memory/index.js +15 -0
- package/dist/services/session-memory/index.js.map +1 -0
- package/dist/services/session-memory/prompts.d.ts +23 -0
- package/dist/services/session-memory/prompts.d.ts.map +1 -0
- package/dist/services/session-memory/prompts.js +70 -0
- package/dist/services/session-memory/prompts.js.map +1 -0
- package/dist/services/session-memory/sessionMemory.d.ts +64 -0
- package/dist/services/session-memory/sessionMemory.d.ts.map +1 -0
- package/dist/services/session-memory/sessionMemory.js +243 -0
- package/dist/services/session-memory/sessionMemory.js.map +1 -0
- package/dist/services/session-storage.d.ts +378 -0
- package/dist/services/session-storage.d.ts.map +1 -0
- package/dist/services/session-storage.js +1026 -0
- package/dist/services/session-storage.js.map +1 -0
- package/dist/services/smart-routing.d.ts +41 -0
- package/dist/services/smart-routing.d.ts.map +1 -0
- package/dist/services/smart-routing.js +134 -0
- package/dist/services/smart-routing.js.map +1 -0
- package/dist/services/storage-maintenance.d.ts +53 -0
- package/dist/services/storage-maintenance.d.ts.map +1 -0
- package/dist/services/storage-maintenance.js +370 -0
- package/dist/services/storage-maintenance.js.map +1 -0
- package/dist/services/task-manager.d.ts +156 -0
- package/dist/services/task-manager.d.ts.map +1 -0
- package/dist/services/task-manager.js +301 -0
- package/dist/services/task-manager.js.map +1 -0
- package/dist/services/usage-state.d.ts +70 -0
- package/dist/services/usage-state.d.ts.map +1 -0
- package/dist/services/usage-state.js +257 -0
- package/dist/services/usage-state.js.map +1 -0
- package/dist/services/verification-profile.d.ts +51 -0
- package/dist/services/verification-profile.d.ts.map +1 -0
- package/dist/services/verification-profile.js +307 -0
- package/dist/services/verification-profile.js.map +1 -0
- package/dist/services/web-search-adapters.d.ts +24 -0
- package/dist/services/web-search-adapters.d.ts.map +1 -0
- package/dist/services/web-search-adapters.js +271 -0
- package/dist/services/web-search-adapters.js.map +1 -0
- package/dist/services/web-search-mcp.d.ts +32 -0
- package/dist/services/web-search-mcp.d.ts.map +1 -0
- package/dist/services/web-search-mcp.js +270 -0
- package/dist/services/web-search-mcp.js.map +1 -0
- package/dist/services/web-search-provider.d.ts +28 -0
- package/dist/services/web-search-provider.d.ts.map +1 -0
- package/dist/services/web-search-provider.js +127 -0
- package/dist/services/web-search-provider.js.map +1 -0
- package/dist/services/workspace-diff.d.ts +27 -0
- package/dist/services/workspace-diff.d.ts.map +1 -0
- package/dist/services/workspace-diff.js +160 -0
- package/dist/services/workspace-diff.js.map +1 -0
- package/dist/services/workspace-state.d.ts +25 -0
- package/dist/services/workspace-state.d.ts.map +1 -0
- package/dist/services/workspace-state.js +115 -0
- package/dist/services/workspace-state.js.map +1 -0
- package/dist/services/yaml-config.d.ts +57 -0
- package/dist/services/yaml-config.d.ts.map +1 -0
- package/dist/services/yaml-config.js +176 -0
- package/dist/services/yaml-config.js.map +1 -0
- package/dist/skills/discovery.d.ts +22 -0
- package/dist/skills/discovery.d.ts.map +1 -0
- package/dist/skills/discovery.js +75 -0
- package/dist/skills/discovery.js.map +1 -0
- package/dist/skills/index.d.ts +11 -0
- package/dist/skills/index.d.ts.map +1 -0
- package/dist/skills/index.js +27 -0
- package/dist/skills/index.js.map +1 -0
- package/dist/skills/loader.d.ts +53 -0
- package/dist/skills/loader.d.ts.map +1 -0
- package/dist/skills/loader.js +406 -0
- package/dist/skills/loader.js.map +1 -0
- package/dist/skills/registry.d.ts +41 -0
- package/dist/skills/registry.d.ts.map +1 -0
- package/dist/skills/registry.js +157 -0
- package/dist/skills/registry.js.map +1 -0
- package/dist/skills/runtime.d.ts +46 -0
- package/dist/skills/runtime.d.ts.map +1 -0
- package/dist/skills/runtime.js +331 -0
- package/dist/skills/runtime.js.map +1 -0
- package/dist/skills/types.d.ts +112 -0
- package/dist/skills/types.d.ts.map +1 -0
- package/dist/skills/types.js +24 -0
- package/dist/skills/types.js.map +1 -0
- package/dist/terminal-ui/completion.d.ts +13 -0
- package/dist/terminal-ui/completion.d.ts.map +1 -0
- package/dist/terminal-ui/completion.js +95 -0
- package/dist/terminal-ui/completion.js.map +1 -0
- package/dist/terminal-ui/editor.d.ts +17 -0
- package/dist/terminal-ui/editor.d.ts.map +1 -0
- package/dist/terminal-ui/editor.js +53 -0
- package/dist/terminal-ui/editor.js.map +1 -0
- package/dist/terminal-ui/launch.d.ts +121 -0
- package/dist/terminal-ui/launch.d.ts.map +1 -0
- package/dist/terminal-ui/launch.js +1247 -0
- package/dist/terminal-ui/launch.js.map +1 -0
- package/dist/terminal-ui/output-queue.d.ts +43 -0
- package/dist/terminal-ui/output-queue.d.ts.map +1 -0
- package/dist/terminal-ui/output-queue.js +139 -0
- package/dist/terminal-ui/output-queue.js.map +1 -0
- package/dist/terminal-ui/raw-editor.d.ts +106 -0
- package/dist/terminal-ui/raw-editor.d.ts.map +1 -0
- package/dist/terminal-ui/raw-editor.js +704 -0
- package/dist/terminal-ui/raw-editor.js.map +1 -0
- package/dist/tools/_validate.d.ts +11 -0
- package/dist/tools/_validate.d.ts.map +1 -0
- package/dist/tools/_validate.js +55 -0
- package/dist/tools/_validate.js.map +1 -0
- package/dist/tools/bash_security.d.ts +74 -0
- package/dist/tools/bash_security.d.ts.map +1 -0
- package/dist/tools/bash_security.js +356 -0
- package/dist/tools/bash_security.js.map +1 -0
- package/dist/tools/git.d.ts +15 -0
- package/dist/tools/git.d.ts.map +1 -0
- package/dist/tools/git.js +285 -0
- package/dist/tools/git.js.map +1 -0
- package/dist/tools/index.d.ts +40 -0
- package/dist/tools/index.d.ts.map +1 -0
- package/dist/tools/index.js +1881 -0
- package/dist/tools/index.js.map +1 -0
- package/dist/tools/lsp.d.ts +18 -0
- package/dist/tools/lsp.d.ts.map +1 -0
- package/dist/tools/lsp.js +548 -0
- package/dist/tools/lsp.js.map +1 -0
- package/dist/tools/mcp.d.ts +86 -0
- package/dist/tools/mcp.d.ts.map +1 -0
- package/dist/tools/mcp.js +570 -0
- package/dist/tools/mcp.js.map +1 -0
- package/dist/tools/plan.d.ts +18 -0
- package/dist/tools/plan.d.ts.map +1 -0
- package/dist/tools/plan.js +82 -0
- package/dist/tools/plan.js.map +1 -0
- package/dist/tools/todo.d.ts +18 -0
- package/dist/tools/todo.d.ts.map +1 -0
- package/dist/tools/todo.js +161 -0
- package/dist/tools/todo.js.map +1 -0
- package/dist/tools/web.d.ts +26 -0
- package/dist/tools/web.d.ts.map +1 -0
- package/dist/tools/web.js +586 -0
- package/dist/tools/web.js.map +1 -0
- package/dist/tui-core/frame.d.ts +37 -0
- package/dist/tui-core/frame.d.ts.map +1 -0
- package/dist/tui-core/frame.js +157 -0
- package/dist/tui-core/frame.js.map +1 -0
- package/dist/tui-core/input-parser.d.ts +36 -0
- package/dist/tui-core/input-parser.d.ts.map +1 -0
- package/dist/tui-core/input-parser.js +291 -0
- package/dist/tui-core/input-parser.js.map +1 -0
- package/dist/tui-core/style.d.ts +103 -0
- package/dist/tui-core/style.d.ts.map +1 -0
- package/dist/tui-core/style.js +269 -0
- package/dist/tui-core/style.js.map +1 -0
- package/dist/tui-core/terminal-writer.d.ts +34 -0
- package/dist/tui-core/terminal-writer.d.ts.map +1 -0
- package/dist/tui-core/terminal-writer.js +105 -0
- package/dist/tui-core/terminal-writer.js.map +1 -0
- package/dist/tui-ui/inline-surface.d.ts +191 -0
- package/dist/tui-ui/inline-surface.d.ts.map +1 -0
- package/dist/tui-ui/inline-surface.js +636 -0
- package/dist/tui-ui/inline-surface.js.map +1 -0
- package/dist/tui-ui/input-ownership.d.ts +46 -0
- package/dist/tui-ui/input-ownership.d.ts.map +1 -0
- package/dist/tui-ui/input-ownership.js +74 -0
- package/dist/tui-ui/input-ownership.js.map +1 -0
- package/dist/tui-ui/launch.d.ts +11 -0
- package/dist/tui-ui/launch.d.ts.map +1 -0
- package/dist/tui-ui/launch.js +632 -0
- package/dist/tui-ui/launch.js.map +1 -0
- package/dist/tui-ui/layout.d.ts +59 -0
- package/dist/tui-ui/layout.d.ts.map +1 -0
- package/dist/tui-ui/layout.js +426 -0
- package/dist/tui-ui/layout.js.map +1 -0
- package/dist/tui-ui/pickers.d.ts +13 -0
- package/dist/tui-ui/pickers.d.ts.map +1 -0
- package/dist/tui-ui/pickers.js +38 -0
- package/dist/tui-ui/pickers.js.map +1 -0
- package/dist/tui-ui/render-scheduler.d.ts +37 -0
- package/dist/tui-ui/render-scheduler.d.ts.map +1 -0
- package/dist/tui-ui/render-scheduler.js +118 -0
- package/dist/tui-ui/render-scheduler.js.map +1 -0
- package/dist/tui-ui/runner.d.ts +149 -0
- package/dist/tui-ui/runner.d.ts.map +1 -0
- package/dist/tui-ui/runner.js +1255 -0
- package/dist/tui-ui/runner.js.map +1 -0
- package/dist/tui-ui/state.d.ts +219 -0
- package/dist/tui-ui/state.d.ts.map +1 -0
- package/dist/tui-ui/state.js +569 -0
- package/dist/tui-ui/state.js.map +1 -0
- package/dist/tui-ui/terminal-image.d.ts +24 -0
- package/dist/tui-ui/terminal-image.d.ts.map +1 -0
- package/dist/tui-ui/terminal-image.js +211 -0
- package/dist/tui-ui/terminal-image.js.map +1 -0
- package/dist/tui-ui/theme-profile.d.ts +25 -0
- package/dist/tui-ui/theme-profile.d.ts.map +1 -0
- package/dist/tui-ui/theme-profile.js +130 -0
- package/dist/tui-ui/theme-profile.js.map +1 -0
- package/dist/tui-ui/theme.d.ts +13 -0
- package/dist/tui-ui/theme.d.ts.map +1 -0
- package/dist/tui-ui/theme.js +20 -0
- package/dist/tui-ui/theme.js.map +1 -0
- package/dist/tui-ui/transcript-cache.d.ts +35 -0
- package/dist/tui-ui/transcript-cache.d.ts.map +1 -0
- package/dist/tui-ui/transcript-cache.js +74 -0
- package/dist/tui-ui/transcript-cache.js.map +1 -0
- package/dist/tui-ui/transcript-inspector-layout.d.ts +9 -0
- package/dist/tui-ui/transcript-inspector-layout.d.ts.map +1 -0
- package/dist/tui-ui/transcript-inspector-layout.js +97 -0
- package/dist/tui-ui/transcript-inspector-layout.js.map +1 -0
- package/dist/tui-ui/transcript-inspector-surface.d.ts +18 -0
- package/dist/tui-ui/transcript-inspector-surface.d.ts.map +1 -0
- package/dist/tui-ui/transcript-inspector-surface.js +88 -0
- package/dist/tui-ui/transcript-inspector-surface.js.map +1 -0
- package/dist/tui-ui/transcript-inspector.d.ts +35 -0
- package/dist/tui-ui/transcript-inspector.d.ts.map +1 -0
- package/dist/tui-ui/transcript-inspector.js +128 -0
- package/dist/tui-ui/transcript-inspector.js.map +1 -0
- package/dist/tui-ui/transcript-layout.d.ts +22 -0
- package/dist/tui-ui/transcript-layout.d.ts.map +1 -0
- package/dist/tui-ui/transcript-layout.js +442 -0
- package/dist/tui-ui/transcript-layout.js.map +1 -0
- package/dist/ui/box.d.ts +48 -0
- package/dist/ui/box.d.ts.map +1 -0
- package/dist/ui/box.js +196 -0
- package/dist/ui/box.js.map +1 -0
- package/dist/ui/command-panel.d.ts +79 -0
- package/dist/ui/command-panel.d.ts.map +1 -0
- package/dist/ui/command-panel.js +460 -0
- package/dist/ui/command-panel.js.map +1 -0
- package/dist/ui/file-completion.d.ts +65 -0
- package/dist/ui/file-completion.d.ts.map +1 -0
- package/dist/ui/file-completion.js +214 -0
- package/dist/ui/file-completion.js.map +1 -0
- package/dist/ui/markdown.d.ts +18 -0
- package/dist/ui/markdown.d.ts.map +1 -0
- package/dist/ui/markdown.js +301 -0
- package/dist/ui/markdown.js.map +1 -0
- package/dist/ui/multiline-input.d.ts +51 -0
- package/dist/ui/multiline-input.d.ts.map +1 -0
- package/dist/ui/multiline-input.js +100 -0
- package/dist/ui/multiline-input.js.map +1 -0
- package/dist/ui/progress.d.ts +34 -0
- package/dist/ui/progress.d.ts.map +1 -0
- package/dist/ui/progress.js +85 -0
- package/dist/ui/progress.js.map +1 -0
- package/dist/ui/shared/command-palette.d.ts +3 -0
- package/dist/ui/shared/command-palette.d.ts.map +1 -0
- package/dist/ui/shared/command-palette.js +54 -0
- package/dist/ui/shared/command-palette.js.map +1 -0
- package/dist/ui/shared/command-suggestions.d.ts +19 -0
- package/dist/ui/shared/command-suggestions.d.ts.map +1 -0
- package/dist/ui/shared/command-suggestions.js +67 -0
- package/dist/ui/shared/command-suggestions.js.map +1 -0
- package/dist/ui/shared/input-frame.d.ts +19 -0
- package/dist/ui/shared/input-frame.d.ts.map +1 -0
- package/dist/ui/shared/input-frame.js +74 -0
- package/dist/ui/shared/input-frame.js.map +1 -0
- package/dist/ui/shared/text.d.ts +5 -0
- package/dist/ui/shared/text.d.ts.map +1 -0
- package/dist/ui/shared/text.js +55 -0
- package/dist/ui/shared/text.js.map +1 -0
- package/dist/ui/shared/types.d.ts +27 -0
- package/dist/ui/shared/types.d.ts.map +1 -0
- package/dist/ui/shared/types.js +3 -0
- package/dist/ui/shared/types.js.map +1 -0
- package/dist/ui/status-bar.d.ts +33 -0
- package/dist/ui/status-bar.d.ts.map +1 -0
- package/dist/ui/status-bar.js +92 -0
- package/dist/ui/status-bar.js.map +1 -0
- package/dist/ui/stream-markdown.d.ts +50 -0
- package/dist/ui/stream-markdown.d.ts.map +1 -0
- package/dist/ui/stream-markdown.js +221 -0
- package/dist/ui/stream-markdown.js.map +1 -0
- package/dist/ui/suggestions.d.ts +35 -0
- package/dist/ui/suggestions.d.ts.map +1 -0
- package/dist/ui/suggestions.js +118 -0
- package/dist/ui/suggestions.js.map +1 -0
- package/dist/ui/tool-preview.d.ts +34 -0
- package/dist/ui/tool-preview.d.ts.map +1 -0
- package/dist/ui/tool-preview.js +127 -0
- package/dist/ui/tool-preview.js.map +1 -0
- package/dist/ui/user-input.d.ts +11 -0
- package/dist/ui/user-input.d.ts.map +1 -0
- package/dist/ui/user-input.js +70 -0
- package/dist/ui/user-input.js.map +1 -0
- package/dist/ui-v2/components/command-palette.d.ts +2 -0
- package/dist/ui-v2/components/command-palette.d.ts.map +1 -0
- package/dist/ui-v2/components/command-palette.js +18 -0
- package/dist/ui-v2/components/command-palette.js.map +1 -0
- package/dist/ui-v2/components/edit-preview-picker.d.ts +26 -0
- package/dist/ui-v2/components/edit-preview-picker.d.ts.map +1 -0
- package/dist/ui-v2/components/edit-preview-picker.js +79 -0
- package/dist/ui-v2/components/edit-preview-picker.js.map +1 -0
- package/dist/ui-v2/components/session-picker.d.ts +19 -0
- package/dist/ui-v2/components/session-picker.d.ts.map +1 -0
- package/dist/ui-v2/components/session-picker.js +52 -0
- package/dist/ui-v2/components/session-picker.js.map +1 -0
- package/dist/ui-v2/components/shell.d.ts +36 -0
- package/dist/ui-v2/components/shell.d.ts.map +1 -0
- package/dist/ui-v2/components/shell.js +131 -0
- package/dist/ui-v2/components/shell.js.map +1 -0
- package/dist/ui-v2/index.d.ts +11 -0
- package/dist/ui-v2/index.d.ts.map +1 -0
- package/dist/ui-v2/index.js +27 -0
- package/dist/ui-v2/index.js.map +1 -0
- package/dist/ui-v2/runtime/text.d.ts +2 -0
- package/dist/ui-v2/runtime/text.d.ts.map +1 -0
- package/dist/ui-v2/runtime/text.js +18 -0
- package/dist/ui-v2/runtime/text.js.map +1 -0
- package/dist/ui-v2/state/input-reducer.d.ts +39 -0
- package/dist/ui-v2/state/input-reducer.d.ts.map +1 -0
- package/dist/ui-v2/state/input-reducer.js +82 -0
- package/dist/ui-v2/state/input-reducer.js.map +1 -0
- package/dist/ui-v2/state/picker.d.ts +16 -0
- package/dist/ui-v2/state/picker.d.ts.map +1 -0
- package/dist/ui-v2/state/picker.js +52 -0
- package/dist/ui-v2/state/picker.js.map +1 -0
- package/dist/ui-v2/state/sessions.d.ts +15 -0
- package/dist/ui-v2/state/sessions.d.ts.map +1 -0
- package/dist/ui-v2/state/sessions.js +70 -0
- package/dist/ui-v2/state/sessions.js.map +1 -0
- package/dist/ui-v2/state/suggestions.d.ts +2 -0
- package/dist/ui-v2/state/suggestions.d.ts.map +1 -0
- package/dist/ui-v2/state/suggestions.js +18 -0
- package/dist/ui-v2/state/suggestions.js.map +1 -0
- package/dist/ui-v2/types.d.ts +2 -0
- package/dist/ui-v2/types.d.ts.map +1 -0
- package/dist/ui-v2/types.js +18 -0
- package/dist/ui-v2/types.js.map +1 -0
- package/dist/utils/token-estimate.d.ts +42 -0
- package/dist/utils/token-estimate.d.ts.map +1 -0
- package/dist/utils/token-estimate.js +150 -0
- package/dist/utils/token-estimate.js.map +1 -0
- package/package.json +100 -0
|
@@ -0,0 +1,2183 @@
|
|
|
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
|
+
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;
|
|
40
|
+
exports.loadSessionIntoRuntime = loadSessionIntoRuntime;
|
|
41
|
+
exports.closeSession = closeSession;
|
|
42
|
+
const commands_1 = require("../commands");
|
|
43
|
+
const parser_1 = require("../commands/parser");
|
|
44
|
+
const path = __importStar(require("path"));
|
|
45
|
+
const session_storage_1 = require("../services/session-storage");
|
|
46
|
+
const config_1 = require("../services/config");
|
|
47
|
+
const framework_1 = require("../framework");
|
|
48
|
+
const prompt_1 = require("./goals/prompt");
|
|
49
|
+
const harness_1 = require("../harness");
|
|
50
|
+
const tools_1 = require("../tools");
|
|
51
|
+
const tool_serializer_1 = require("../framework/tool-serializer");
|
|
52
|
+
const tool_artifacts_1 = require("../core/tool-artifacts");
|
|
53
|
+
const checkpoint_1 = require("../core/checkpoint");
|
|
54
|
+
const skills_1 = require("../skills");
|
|
55
|
+
const subagents_1 = require("./subagents");
|
|
56
|
+
const file_context_1 = require("../services/file-context");
|
|
57
|
+
const prompt_context_1 = require("../services/prompt-context");
|
|
58
|
+
const format_1 = require("../services/format");
|
|
59
|
+
const workspace_state_1 = require("../services/workspace-state");
|
|
60
|
+
const verification_profile_1 = require("../services/verification-profile");
|
|
61
|
+
const ui_events_1 = require("./ui-events");
|
|
62
|
+
const ui_view_model_1 = require("./ui-view-model");
|
|
63
|
+
const agent_status_1 = require("./agent-status");
|
|
64
|
+
const loop_budget_1 = require("./loop-budget");
|
|
65
|
+
const tool_output_presentation_1 = require("./tool-output-presentation");
|
|
66
|
+
const aggregate_tool_presenter_1 = require("./aggregate-tool-presenter");
|
|
67
|
+
const ANSI_PATTERN = /\x1b\[[0-9;?]*[A-Za-z]/g;
|
|
68
|
+
const LOCAL_FAST_PATH_INLINE_OUTPUT_BYTES = 2048;
|
|
69
|
+
const TRACE_ARGS_ARTIFACT_THRESHOLD_BYTES = 160;
|
|
70
|
+
const TOOL_TRANSCRIPT_ARG_BUDGET = 512;
|
|
71
|
+
function stripAnsi(text) {
|
|
72
|
+
return text.replace(ANSI_PATTERN, '');
|
|
73
|
+
}
|
|
74
|
+
function isAbortError(error, abortSignal) {
|
|
75
|
+
if (abortSignal?.aborted)
|
|
76
|
+
return true;
|
|
77
|
+
if (error instanceof Error) {
|
|
78
|
+
return error.name === 'AbortError' || error.message.toLowerCase().includes('aborted');
|
|
79
|
+
}
|
|
80
|
+
return false;
|
|
81
|
+
}
|
|
82
|
+
function errorLayerForChatError(error) {
|
|
83
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
84
|
+
const lower = message.toLowerCase();
|
|
85
|
+
if (/NotEnoughCvError|code:\s*11210|provider|quota|rate.?limit|timeout|connection/i.test(message)) {
|
|
86
|
+
return 'provider';
|
|
87
|
+
}
|
|
88
|
+
if (/tool|command|exec_command|write_file|edit_file/i.test(message)) {
|
|
89
|
+
return 'tool';
|
|
90
|
+
}
|
|
91
|
+
if (/\bmcp\b/i.test(message))
|
|
92
|
+
return 'mcp';
|
|
93
|
+
if (/\b(session|resume|compact|harness)\b/i.test(message))
|
|
94
|
+
return 'session';
|
|
95
|
+
if (/\b(skill|skills)\b/i.test(message))
|
|
96
|
+
return 'skills';
|
|
97
|
+
if (/\b(memory|vector store|recall|forget)\b/i.test(message))
|
|
98
|
+
return 'memory';
|
|
99
|
+
if (/\b(renderer|terminal|tty|prompt|resize|scrollback)\b/i.test(message))
|
|
100
|
+
return 'renderer';
|
|
101
|
+
if (lower.includes('abort') || lower.includes('interrupted'))
|
|
102
|
+
return 'runtime';
|
|
103
|
+
return 'unknown';
|
|
104
|
+
}
|
|
105
|
+
function formatChatError(error) {
|
|
106
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
107
|
+
if (/NotEnoughCvError|code:\s*11210/i.test(message)) {
|
|
108
|
+
return [
|
|
109
|
+
message,
|
|
110
|
+
'',
|
|
111
|
+
'Provider quota or credit appears insufficient. The Orion Code session is still active; switch model/provider or recharge the provider account, then continue.',
|
|
112
|
+
].join('\n');
|
|
113
|
+
}
|
|
114
|
+
return message;
|
|
115
|
+
}
|
|
116
|
+
function compactMiddle(text, maxLength) {
|
|
117
|
+
const compact = text.replace(/\s+/g, ' ').trim();
|
|
118
|
+
if (compact.length <= maxLength)
|
|
119
|
+
return compact;
|
|
120
|
+
if (maxLength <= 3)
|
|
121
|
+
return compact.slice(0, maxLength);
|
|
122
|
+
const headLength = Math.ceil((maxLength - 3) * 0.55);
|
|
123
|
+
const tailLength = Math.floor((maxLength - 3) * 0.45);
|
|
124
|
+
return `${compact.slice(0, headLength)}...${compact.slice(-tailLength)}`;
|
|
125
|
+
}
|
|
126
|
+
function compactToolArgs(args, maxLength = 160) {
|
|
127
|
+
for (const key of [
|
|
128
|
+
'path',
|
|
129
|
+
'file_path',
|
|
130
|
+
'file',
|
|
131
|
+
'cwd',
|
|
132
|
+
'command',
|
|
133
|
+
'pattern',
|
|
134
|
+
'query',
|
|
135
|
+
'url',
|
|
136
|
+
'target',
|
|
137
|
+
'sessionId',
|
|
138
|
+
]) {
|
|
139
|
+
const value = args[key];
|
|
140
|
+
if (typeof value === 'string') {
|
|
141
|
+
return compactMiddle(value, maxLength);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
const firstString = Object.values(args).find(value => typeof value === 'string');
|
|
145
|
+
if (typeof firstString === 'string') {
|
|
146
|
+
return compactMiddle(firstString, maxLength);
|
|
147
|
+
}
|
|
148
|
+
return '';
|
|
149
|
+
}
|
|
150
|
+
function fullToolArgsForTrace(name, args) {
|
|
151
|
+
if (name === 'exec_command' && typeof args.command === 'string') {
|
|
152
|
+
return `$ ${args.command}`;
|
|
153
|
+
}
|
|
154
|
+
try {
|
|
155
|
+
return JSON.stringify(args, null, 2);
|
|
156
|
+
}
|
|
157
|
+
catch {
|
|
158
|
+
return compactToolArgs(args, 2048);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
function buildTraceArgsDetails(projectPath, name, args) {
|
|
162
|
+
const argsSummary = compactToolArgs(args);
|
|
163
|
+
const fullArgs = (0, session_storage_1.redactTraceText)(fullToolArgsForTrace(name, args)).trim();
|
|
164
|
+
const argsBytes = byteLength(fullArgs);
|
|
165
|
+
if (!projectPath ||
|
|
166
|
+
!fullArgs ||
|
|
167
|
+
fullArgs === (0, session_storage_1.redactTraceText)(argsSummary) ||
|
|
168
|
+
argsBytes <= TRACE_ARGS_ARTIFACT_THRESHOLD_BYTES) {
|
|
169
|
+
return { argsSummary };
|
|
170
|
+
}
|
|
171
|
+
const artifact = (0, tool_artifacts_1.storeArtifact)(projectPath, `${name}-args`, fullArgs, argsBytes);
|
|
172
|
+
return artifact ? { argsSummary, argsArtifactId: artifact.id, argsBytes } : { argsSummary };
|
|
173
|
+
}
|
|
174
|
+
function parseToolCallArgsForRuntime(toolCall) {
|
|
175
|
+
try {
|
|
176
|
+
const parsed = JSON.parse(toolCall.function.arguments || '{}');
|
|
177
|
+
return typeof parsed === 'object' && parsed !== null && !Array.isArray(parsed)
|
|
178
|
+
? parsed
|
|
179
|
+
: null;
|
|
180
|
+
}
|
|
181
|
+
catch {
|
|
182
|
+
return null;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
function resolveProjectScopedPath(cwd, filePath) {
|
|
186
|
+
const absolute = path.resolve(cwd, filePath);
|
|
187
|
+
const relative = path.relative(cwd, absolute);
|
|
188
|
+
if (relative.startsWith('..') || path.isAbsolute(relative))
|
|
189
|
+
return null;
|
|
190
|
+
return absolute;
|
|
191
|
+
}
|
|
192
|
+
function checkpointTargetsFromToolCalls(cwd, toolCalls) {
|
|
193
|
+
const targets = new Set();
|
|
194
|
+
for (const toolCall of toolCalls) {
|
|
195
|
+
const name = toolCall.function.name;
|
|
196
|
+
if (name !== 'write_file' && name !== 'edit_file')
|
|
197
|
+
continue;
|
|
198
|
+
const args = parseToolCallArgsForRuntime(toolCall);
|
|
199
|
+
if (!args || typeof args.path !== 'string')
|
|
200
|
+
continue;
|
|
201
|
+
if (name === 'edit_file' && args.preview === true)
|
|
202
|
+
continue;
|
|
203
|
+
const target = resolveProjectScopedPath(cwd, args.path);
|
|
204
|
+
if (target)
|
|
205
|
+
targets.add(target);
|
|
206
|
+
}
|
|
207
|
+
return Array.from(targets);
|
|
208
|
+
}
|
|
209
|
+
function createPreToolCheckpoint(events, sessionId, turnId, checkpointId, cwd, toolCalls) {
|
|
210
|
+
const targets = checkpointTargetsFromToolCalls(cwd, toolCalls);
|
|
211
|
+
if (targets.length === 0)
|
|
212
|
+
return { created: false, targetCount: 0, risky: false };
|
|
213
|
+
const risky = (0, checkpoint_1.shouldCreateMultiFileCheckpoint)(targets.length);
|
|
214
|
+
const checkpoint = (0, checkpoint_1.createCheckpoint)(cwd, checkpointId, targets);
|
|
215
|
+
if (!sessionId)
|
|
216
|
+
return { created: true, targetCount: targets.length, risky };
|
|
217
|
+
const relativeTargets = targets.map(target => path.relative(cwd, target));
|
|
218
|
+
recordTraceEvent(events, sessionId, {
|
|
219
|
+
turnId,
|
|
220
|
+
type: 'checkpoint',
|
|
221
|
+
checkpointId,
|
|
222
|
+
checkpointFileCount: checkpoint?.files.length ?? 0,
|
|
223
|
+
checkpointFiles: checkpoint?.files.map(file => file.path) ?? [],
|
|
224
|
+
workspaceFiles: relativeTargets,
|
|
225
|
+
note: checkpoint
|
|
226
|
+
? risky
|
|
227
|
+
? 'risky_multi_file_checkpoint'
|
|
228
|
+
: 'pre_edit_checkpoint'
|
|
229
|
+
: 'pre_edit_checkpoint_skipped',
|
|
230
|
+
});
|
|
231
|
+
return { created: true, targetCount: targets.length, risky };
|
|
232
|
+
}
|
|
233
|
+
function byteLength(text) {
|
|
234
|
+
return Buffer.byteLength(text, 'utf8');
|
|
235
|
+
}
|
|
236
|
+
function traceTurnId(turnId) {
|
|
237
|
+
return turnId == null ? `turn-${Date.now()}` : String(turnId);
|
|
238
|
+
}
|
|
239
|
+
function compactTraceError(error) {
|
|
240
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
241
|
+
return compactMiddle(message, 240);
|
|
242
|
+
}
|
|
243
|
+
function getLastRequestDiagnostics(llm) {
|
|
244
|
+
if (!llm)
|
|
245
|
+
return undefined;
|
|
246
|
+
const reader = llm.getLastRequestDiagnostics;
|
|
247
|
+
return typeof reader === 'function' ? reader.call(llm) : undefined;
|
|
248
|
+
}
|
|
249
|
+
function compactPathList(paths, maxItems = 40) {
|
|
250
|
+
return paths.slice(0, maxItems);
|
|
251
|
+
}
|
|
252
|
+
function formatWorkspaceFileForTrace(file) {
|
|
253
|
+
const metadata = [
|
|
254
|
+
typeof file.sizeBytes === 'number' ? `${file.sizeBytes}B` : '',
|
|
255
|
+
typeof file.mtimeMs === 'number' ? `mtime=${file.mtimeMs}` : '',
|
|
256
|
+
]
|
|
257
|
+
.filter(Boolean)
|
|
258
|
+
.join(' ');
|
|
259
|
+
return `${file.status} ${file.path}${metadata ? ` (${metadata})` : ''}`;
|
|
260
|
+
}
|
|
261
|
+
function appendWorkspaceSnapshotTrace(events, sessionId, turnId, phase, snapshot) {
|
|
262
|
+
if (!sessionId)
|
|
263
|
+
return;
|
|
264
|
+
recordTraceEvent(events, sessionId, {
|
|
265
|
+
turnId,
|
|
266
|
+
type: 'workspace_snapshot',
|
|
267
|
+
workspacePhase: phase,
|
|
268
|
+
workspaceGitAvailable: snapshot.gitAvailable,
|
|
269
|
+
workspaceDirty: snapshot.dirty,
|
|
270
|
+
workspaceBranch: snapshot.branch,
|
|
271
|
+
workspaceFileCount: snapshot.fileCount,
|
|
272
|
+
workspaceFiles: compactPathList(snapshot.files.map(formatWorkspaceFileForTrace)),
|
|
273
|
+
error: snapshot.error ? compactMiddle(snapshot.error, 240) : undefined,
|
|
274
|
+
});
|
|
275
|
+
}
|
|
276
|
+
function appendWorkspaceDeltaTrace(events, sessionId, turnId, before, after) {
|
|
277
|
+
const delta = (0, workspace_state_1.diffWorkspaceSnapshots)(before, after);
|
|
278
|
+
if (sessionId) {
|
|
279
|
+
recordTraceEvent(events, sessionId, {
|
|
280
|
+
turnId,
|
|
281
|
+
type: 'workspace_delta',
|
|
282
|
+
workspaceFileCount: delta.filesAfterTurn.length,
|
|
283
|
+
workspaceFiles: compactPathList(delta.filesAfterTurn),
|
|
284
|
+
workspaceNewByTurn: compactPathList(delta.newFilesByTurn),
|
|
285
|
+
workspaceChangedByTurn: compactPathList(delta.changedByTurn),
|
|
286
|
+
workspaceModifiedPreExistingByTurn: compactPathList(delta.modifiedPreExistingByTurn),
|
|
287
|
+
workspaceResolvedByTurn: compactPathList(delta.resolvedByTurn),
|
|
288
|
+
note: `pre_existing=${delta.preExistingFiles.length}`,
|
|
289
|
+
});
|
|
290
|
+
}
|
|
291
|
+
return delta;
|
|
292
|
+
}
|
|
293
|
+
function workspaceDeltaHasTurnChanges(delta) {
|
|
294
|
+
return (delta.newFilesByTurn.length > 0 ||
|
|
295
|
+
delta.changedByTurn.length > 0 ||
|
|
296
|
+
delta.resolvedByTurn.length > 0);
|
|
297
|
+
}
|
|
298
|
+
function formatFailureRecoveryNotice(turnId, delta, checkpointIds) {
|
|
299
|
+
const files = compactPathList([...delta.newFilesByTurn, ...delta.changedByTurn, ...delta.resolvedByTurn], 8);
|
|
300
|
+
const fileText = files.length > 0 ? files.join(', ') : 'workspace changes recorded';
|
|
301
|
+
const checkpointText = checkpointIds.length > 0
|
|
302
|
+
? ` Checkpoints: ${checkpointIds.join(', ')}. Preview rollback with /checkpoint restore <id>; restore each listed checkpoint if multiple.`
|
|
303
|
+
: '';
|
|
304
|
+
return `Turn failed after modifying files: ${fileText}. Inspect /trace ${turnId}.${checkpointText}`;
|
|
305
|
+
}
|
|
306
|
+
function appendVerificationProfileTrace(events, sessionId, turnId, profile) {
|
|
307
|
+
if (!sessionId || profile.changedFiles.length === 0)
|
|
308
|
+
return;
|
|
309
|
+
recordTraceEvent(events, sessionId, {
|
|
310
|
+
turnId,
|
|
311
|
+
type: 'verification_profile',
|
|
312
|
+
verificationProfile: profile.profile,
|
|
313
|
+
verificationRequired: profile.required,
|
|
314
|
+
verificationRisky: (0, verification_profile_1.isRiskyEdit)(profile.changedFiles),
|
|
315
|
+
verificationCommands: compactPathList(profile.commands, 8),
|
|
316
|
+
verificationChangedFiles: compactPathList(profile.changedFiles),
|
|
317
|
+
note: profile.reason,
|
|
318
|
+
});
|
|
319
|
+
}
|
|
320
|
+
function appendVerificationResultTrace(events, sessionId, turnId, result) {
|
|
321
|
+
if (!sessionId)
|
|
322
|
+
return;
|
|
323
|
+
recordTraceEvent(events, sessionId, {
|
|
324
|
+
turnId,
|
|
325
|
+
type: 'verification_result',
|
|
326
|
+
verificationCommand: result.command,
|
|
327
|
+
verificationPassed: result.success,
|
|
328
|
+
outputBytes: result.outputBytes,
|
|
329
|
+
error: result.error ? compactMiddle(result.error, 240) : undefined,
|
|
330
|
+
});
|
|
331
|
+
}
|
|
332
|
+
function appendVerificationSummaryTrace(events, sessionId, turnId, summary, changedFiles) {
|
|
333
|
+
if (!sessionId || changedFiles.length === 0)
|
|
334
|
+
return;
|
|
335
|
+
recordTraceEvent(events, sessionId, {
|
|
336
|
+
turnId,
|
|
337
|
+
type: 'verification_summary',
|
|
338
|
+
verificationProfile: summary.profile,
|
|
339
|
+
verificationRequired: summary.required,
|
|
340
|
+
verificationCommands: compactPathList(summary.commandsRun, 12),
|
|
341
|
+
verificationPassedCommands: compactPathList(summary.passedCommands, 12),
|
|
342
|
+
verificationFailedCommands: compactPathList(summary.failedCommands, 12),
|
|
343
|
+
verificationMissingCommands: compactPathList(summary.missingCommands, 12),
|
|
344
|
+
verificationChangedFiles: compactPathList(changedFiles),
|
|
345
|
+
verificationClaimAllowed: summary.claimAllowed,
|
|
346
|
+
note: summary.skippedReason,
|
|
347
|
+
});
|
|
348
|
+
}
|
|
349
|
+
function compactVerificationCommands(commands, maxItems = 12) {
|
|
350
|
+
return commands.slice(0, maxItems).map(session_storage_1.redactTraceText);
|
|
351
|
+
}
|
|
352
|
+
function withVerificationLoopStats(stats, summary) {
|
|
353
|
+
return {
|
|
354
|
+
...stats,
|
|
355
|
+
verificationProfile: summary.profile,
|
|
356
|
+
verificationRequired: summary.required,
|
|
357
|
+
verificationClaimAllowed: summary.claimAllowed,
|
|
358
|
+
verificationPassedCommands: compactVerificationCommands(summary.passedCommands),
|
|
359
|
+
verificationFailedCommands: compactVerificationCommands(summary.failedCommands),
|
|
360
|
+
verificationMissingCommands: compactVerificationCommands(summary.missingCommands),
|
|
361
|
+
verificationSkippedReason: summary.skippedReason
|
|
362
|
+
? (0, session_storage_1.redactTraceText)(summary.skippedReason)
|
|
363
|
+
: undefined,
|
|
364
|
+
};
|
|
365
|
+
}
|
|
366
|
+
function shouldRecordVerificationLoopStats(profile, summary) {
|
|
367
|
+
return (profile.changedFiles.length > 0 ||
|
|
368
|
+
summary.commandsRun.length > 0 ||
|
|
369
|
+
summary.passedCommands.length > 0 ||
|
|
370
|
+
summary.failedCommands.length > 0 ||
|
|
371
|
+
summary.missingCommands.length > 0);
|
|
372
|
+
}
|
|
373
|
+
function appendPostWorkspaceTrace(events, sessionId, turnId, cwd, before, verificationResults = []) {
|
|
374
|
+
const postWorkspace = (0, workspace_state_1.captureWorkspaceSnapshot)(cwd);
|
|
375
|
+
appendWorkspaceSnapshotTrace(events, sessionId, turnId, 'post_turn', postWorkspace);
|
|
376
|
+
const delta = appendWorkspaceDeltaTrace(events, sessionId, turnId, before, postWorkspace);
|
|
377
|
+
const profile = (0, verification_profile_1.selectVerificationProfile)(cwd, delta.changedByTurn);
|
|
378
|
+
const summary = (0, verification_profile_1.summarizeVerificationState)(profile, verificationResults);
|
|
379
|
+
appendVerificationProfileTrace(events, sessionId, turnId, profile);
|
|
380
|
+
appendVerificationSummaryTrace(events, sessionId, turnId, summary, profile.changedFiles);
|
|
381
|
+
return { delta, profile, summary };
|
|
382
|
+
}
|
|
383
|
+
function appendAssistantNotice(messages, notice) {
|
|
384
|
+
for (let index = messages.length - 1; index >= 0; index--) {
|
|
385
|
+
const message = messages[index];
|
|
386
|
+
if (message.role === 'assistant' && !message.tool_calls) {
|
|
387
|
+
message.content = message.content ? `${message.content}\n\n${notice}` : notice;
|
|
388
|
+
return;
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
messages.push({
|
|
392
|
+
role: 'assistant',
|
|
393
|
+
content: notice,
|
|
394
|
+
timestamp: Date.now(),
|
|
395
|
+
});
|
|
396
|
+
}
|
|
397
|
+
function recordTraceEvent(events, sessionId, event) {
|
|
398
|
+
if (!sessionId)
|
|
399
|
+
return null;
|
|
400
|
+
const traceEvent = (0, session_storage_1.appendSessionTraceEvent)(sessionId, event);
|
|
401
|
+
if (traceEvent) {
|
|
402
|
+
events.traceEventRecorded?.(traceEvent);
|
|
403
|
+
}
|
|
404
|
+
return traceEvent;
|
|
405
|
+
}
|
|
406
|
+
function recordProviderTraceEvents(events, sessionId, turnId, stats) {
|
|
407
|
+
if ((stats.providerRetryCount ?? 0) > 0) {
|
|
408
|
+
recordTraceEvent(events, sessionId, {
|
|
409
|
+
turnId,
|
|
410
|
+
type: 'provider_retry',
|
|
411
|
+
providerRetryCount: stats.providerRetryCount,
|
|
412
|
+
providerRetryDelayMs: stats.providerRetryDelayMs,
|
|
413
|
+
providerRetryErrorTypes: stats.providerRetryErrorTypes,
|
|
414
|
+
providerLastRetryErrorType: stats.providerLastRetryErrorType,
|
|
415
|
+
providerLastRetryStatus: stats.providerLastRetryStatus,
|
|
416
|
+
providerFinalModel: stats.providerFinalModel,
|
|
417
|
+
providerUsingFallback: stats.providerUsingFallback,
|
|
418
|
+
});
|
|
419
|
+
}
|
|
420
|
+
if ((stats.providerFallbackCount ?? 0) > 0 || stats.providerUsingFallback) {
|
|
421
|
+
recordTraceEvent(events, sessionId, {
|
|
422
|
+
turnId,
|
|
423
|
+
type: 'provider_fallback',
|
|
424
|
+
providerFallbackCount: stats.providerFallbackCount,
|
|
425
|
+
providerFallbackFromModel: stats.providerFallbackFromModel,
|
|
426
|
+
providerFallbackToModel: stats.providerFallbackToModel,
|
|
427
|
+
providerFinalModel: stats.providerFinalModel,
|
|
428
|
+
providerUsingFallback: stats.providerUsingFallback,
|
|
429
|
+
});
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
function toHarnessDiagnostics(state) {
|
|
433
|
+
const stats = state.promptAssemblyStats;
|
|
434
|
+
const redactOptional = (value) => typeof value === 'string' ? (0, session_storage_1.redactTraceText)(value) : undefined;
|
|
435
|
+
const redactList = (values) => values?.slice(0, 6).map(session_storage_1.redactTraceText);
|
|
436
|
+
return {
|
|
437
|
+
taskEpoch: state.taskEpoch,
|
|
438
|
+
rootObjective: redactOptional(state.rootObjective ?? state.contract?.objective),
|
|
439
|
+
activeInstruction: redactOptional(state.activeInstruction ?? state.contract?.userIntent),
|
|
440
|
+
openQuestions: redactList(state.openQuestions),
|
|
441
|
+
diagnostics: redactList(state.diagnostics?.slice(-6)),
|
|
442
|
+
ledgerSize: state.ledger?.length ?? 0,
|
|
443
|
+
evidenceSize: state.evidenceIndex?.length ?? 0,
|
|
444
|
+
turnSummaryCount: state.turnSummaries?.length ?? 0,
|
|
445
|
+
promptAssembly: stats
|
|
446
|
+
? {
|
|
447
|
+
modelId: stats.modelId,
|
|
448
|
+
estimatedTokens: stats.estimatedTokens,
|
|
449
|
+
budgetTokens: stats.budgetTokens,
|
|
450
|
+
sections: stats.sections.slice(0, 12),
|
|
451
|
+
includedEvidence: stats.includedEvidence.length,
|
|
452
|
+
omittedEvidence: stats.omittedEvidence.length,
|
|
453
|
+
}
|
|
454
|
+
: undefined,
|
|
455
|
+
};
|
|
456
|
+
}
|
|
457
|
+
function emitHarnessDiagnostics(events, state) {
|
|
458
|
+
events.harnessDiagnosticsUpdated?.(toHarnessDiagnostics(state));
|
|
459
|
+
}
|
|
460
|
+
function toolStartContent(event) {
|
|
461
|
+
return (0, ui_view_model_1.formatToolActivityTranscript)((0, ui_view_model_1.toolActivityFromStarted)(event, compactToolArgs(event.args, TOOL_TRANSCRIPT_ARG_BUDGET)));
|
|
462
|
+
}
|
|
463
|
+
function toolFinishContent(event) {
|
|
464
|
+
return (0, ui_view_model_1.formatToolActivityTranscript)((0, ui_view_model_1.toolActivityFromFinished)(event, compactToolArgs(event.args, TOOL_TRANSCRIPT_ARG_BUDGET)));
|
|
465
|
+
}
|
|
466
|
+
function structuredToolStartActivity(event, seq) {
|
|
467
|
+
const command = event.name === 'exec_command' && typeof event.args.command === 'string'
|
|
468
|
+
? event.args.command
|
|
469
|
+
: undefined;
|
|
470
|
+
const safeCommand = command ? (0, session_storage_1.redactTraceText)(command) : undefined;
|
|
471
|
+
return {
|
|
472
|
+
state: 'running',
|
|
473
|
+
name: event.name,
|
|
474
|
+
detail: command ? '' : (0, session_storage_1.redactTraceText)(compactToolArgs(event.args, TOOL_TRANSCRIPT_ARG_BUDGET)),
|
|
475
|
+
command: safeCommand,
|
|
476
|
+
body: '',
|
|
477
|
+
seq,
|
|
478
|
+
};
|
|
479
|
+
}
|
|
480
|
+
function structuredToolFinishActivity(event, seq, options = {}) {
|
|
481
|
+
const modelVisible = (0, tool_serializer_1.parseToolResultEnvelope)(event.modelVisibleResult);
|
|
482
|
+
const durable = (0, tool_serializer_1.parseToolResultEnvelope)(event.result);
|
|
483
|
+
const durableOutput = typeof durable.output === 'string' ? durable.output : '';
|
|
484
|
+
const displayOutput = typeof modelVisible.output === 'string' ? modelVisible.output : durableOutput;
|
|
485
|
+
const outputBytes = event.outputBytes ?? Buffer.byteLength(durableOutput, 'utf8');
|
|
486
|
+
const aggregatePresentation = (0, aggregate_tool_presenter_1.presentAggregateToolResult)(event.name, durableOutput, outputBytes);
|
|
487
|
+
const aggregate = aggregatePresentation?.view;
|
|
488
|
+
const storedArtifact = event.artifactRef ?? (options.projectPath && durableOutput && (outputBytes > tool_output_presentation_1.DEFAULT_TOOL_OUTPUT_POLICY.inlineMaxBytes || aggregate)
|
|
489
|
+
? (0, tool_artifacts_1.storeArtifact)(options.projectPath, event.name, durableOutput, outputBytes) ?? undefined
|
|
490
|
+
: undefined);
|
|
491
|
+
const artifactRef = storedArtifact
|
|
492
|
+
? { id: storedArtifact.id, outputBytes: storedArtifact.outputBytes }
|
|
493
|
+
: undefined;
|
|
494
|
+
const outputView = (0, tool_output_presentation_1.createToolOutputView)({
|
|
495
|
+
toolName: event.name,
|
|
496
|
+
success: event.success,
|
|
497
|
+
summary: event.summary,
|
|
498
|
+
rawOutput: durableOutput.length <= 64 * 1024 ? durableOutput : displayOutput,
|
|
499
|
+
outputBytes,
|
|
500
|
+
artifactRef,
|
|
501
|
+
callId: event.callId,
|
|
502
|
+
sequence: seq,
|
|
503
|
+
turnId: options.turnId,
|
|
504
|
+
policy: tool_output_presentation_1.DEFAULT_TOOL_OUTPUT_POLICY,
|
|
505
|
+
});
|
|
506
|
+
if (aggregate) {
|
|
507
|
+
outputView.aggregate = {
|
|
508
|
+
...aggregate,
|
|
509
|
+
steps: aggregate.steps.map(step => ({ ...step, detailRef: outputView.detailRef })),
|
|
510
|
+
};
|
|
511
|
+
}
|
|
512
|
+
const command = event.name === 'exec_command' && typeof event.args.command === 'string'
|
|
513
|
+
? event.args.command
|
|
514
|
+
: undefined;
|
|
515
|
+
const safeCommand = command ? (0, session_storage_1.redactTraceText)(command) : undefined;
|
|
516
|
+
return {
|
|
517
|
+
state: event.success ? 'success' : 'error',
|
|
518
|
+
name: event.name,
|
|
519
|
+
detail: command ? '' : (0, session_storage_1.redactTraceText)(compactToolArgs(event.args, TOOL_TRANSCRIPT_ARG_BUDGET)),
|
|
520
|
+
command: safeCommand,
|
|
521
|
+
duration: `${event.duration}ms`,
|
|
522
|
+
summary: event.summary ? (0, session_storage_1.redactTraceText)(event.summary.split(/\r?\n/u, 1)[0]) : undefined,
|
|
523
|
+
outputBytes,
|
|
524
|
+
body: (0, session_storage_1.redactTraceText)(modelVisible.output),
|
|
525
|
+
error: event.error ? (0, session_storage_1.redactTraceText)(event.error) : undefined,
|
|
526
|
+
seq,
|
|
527
|
+
artifactHint: artifactRef ? `/artifacts show ${artifactRef.id} --full` : undefined,
|
|
528
|
+
callId: event.callId,
|
|
529
|
+
turnId: options.turnId,
|
|
530
|
+
outputView,
|
|
531
|
+
};
|
|
532
|
+
}
|
|
533
|
+
function isSyntheticCompactContext(content) {
|
|
534
|
+
return (content.startsWith('[Orion Code Context State v2]') ||
|
|
535
|
+
content.startsWith('[Context Summary]') ||
|
|
536
|
+
content.startsWith('I will continue from this Orion Code Context State') ||
|
|
537
|
+
content.startsWith('I understand the context. I will continue the conversation with this background information.'));
|
|
538
|
+
}
|
|
539
|
+
function sessionToolCallSummaries(message) {
|
|
540
|
+
return (message.tool_calls ?? []).map(call => {
|
|
541
|
+
const args = parseToolCallArgs(call.function.arguments);
|
|
542
|
+
const detail = compactToolArgs(args);
|
|
543
|
+
return {
|
|
544
|
+
id: call.id,
|
|
545
|
+
content: `Requested ${call.function.name}${detail ? ` ${detail}` : ''}`,
|
|
546
|
+
};
|
|
547
|
+
});
|
|
548
|
+
}
|
|
549
|
+
function parseToolCallArgs(rawArgs) {
|
|
550
|
+
try {
|
|
551
|
+
return rawArgs ? JSON.parse(rawArgs) : {};
|
|
552
|
+
}
|
|
553
|
+
catch {
|
|
554
|
+
return rawArgs ? { arguments: rawArgs } : {};
|
|
555
|
+
}
|
|
556
|
+
}
|
|
557
|
+
function parseSessionToolResult(content) {
|
|
558
|
+
try {
|
|
559
|
+
const parsed = JSON.parse(content);
|
|
560
|
+
return {
|
|
561
|
+
success: parsed.success === true,
|
|
562
|
+
error: typeof parsed.error === 'string' ? parsed.error : undefined,
|
|
563
|
+
summary: typeof parsed.summary === 'string' ? parsed.summary : undefined,
|
|
564
|
+
};
|
|
565
|
+
}
|
|
566
|
+
catch {
|
|
567
|
+
return { success: false, error: 'Invalid JSON result' };
|
|
568
|
+
}
|
|
569
|
+
}
|
|
570
|
+
function removeTrailingUserMessage(runtime) {
|
|
571
|
+
const history = runtime.store.getSnapshot().conversationHistory;
|
|
572
|
+
if (history.length === 0)
|
|
573
|
+
return;
|
|
574
|
+
const lastMsg = history[history.length - 1];
|
|
575
|
+
if (lastMsg?.role === 'user') {
|
|
576
|
+
runtime.store.setState({ conversationHistory: history.slice(0, -1) });
|
|
577
|
+
}
|
|
578
|
+
}
|
|
579
|
+
function sessionToolResultSummary(message, toolCallsById) {
|
|
580
|
+
if (!message.toolCallId)
|
|
581
|
+
return null;
|
|
582
|
+
const call = toolCallsById.get(message.toolCallId);
|
|
583
|
+
if (!call)
|
|
584
|
+
return null;
|
|
585
|
+
const args = parseToolCallArgs(call.function.arguments);
|
|
586
|
+
const detail = compactToolArgs(args);
|
|
587
|
+
const parsed = parseSessionToolResult(message.content);
|
|
588
|
+
const firstLine = parsed.summary ||
|
|
589
|
+
`${parsed.success ? '✓' : '✗'} ${call.function.name}${detail ? ` ${detail}` : ''}`;
|
|
590
|
+
return parsed.error ? `${firstLine}\nError: ${parsed.error}` : firstLine;
|
|
591
|
+
}
|
|
592
|
+
function sessionMessagesToTranscriptEntries(sessionId, options = {}) {
|
|
593
|
+
const messages = (0, session_storage_1.loadSessionTranscriptMessages)(sessionId);
|
|
594
|
+
const resultTraces = options.includeToolOutputViews
|
|
595
|
+
? (0, session_storage_1.readSessionTraceEvents)(sessionId).filter(trace => trace.type === 'tool_result' && trace.callId)
|
|
596
|
+
: [];
|
|
597
|
+
const resultTraceByCallId = new Map(resultTraces.map(trace => [trace.callId, trace]));
|
|
598
|
+
const sequenceByCallId = new Map();
|
|
599
|
+
resultTraces.forEach((trace, index) => {
|
|
600
|
+
if (!sequenceByCallId.has(trace.callId))
|
|
601
|
+
sequenceByCallId.set(trace.callId, index + 1);
|
|
602
|
+
});
|
|
603
|
+
const entries = [];
|
|
604
|
+
const toolCallsById = new Map();
|
|
605
|
+
const completedToolCallIds = new Set();
|
|
606
|
+
let fallbackToolSequence = 0;
|
|
607
|
+
for (const message of messages) {
|
|
608
|
+
for (const call of message.tool_calls ?? []) {
|
|
609
|
+
toolCallsById.set(call.id, call);
|
|
610
|
+
}
|
|
611
|
+
if (message.role === 'tool' && message.toolCallId) {
|
|
612
|
+
completedToolCallIds.add(message.toolCallId);
|
|
613
|
+
}
|
|
614
|
+
}
|
|
615
|
+
messages.forEach((message, index) => {
|
|
616
|
+
if (isSyntheticCompactContext(message.content))
|
|
617
|
+
return;
|
|
618
|
+
const idBase = `session-${sessionId.slice(0, 8)}-${index}`;
|
|
619
|
+
if (message.role === 'user') {
|
|
620
|
+
entries.push({ id: `${idBase}-user`, role: 'user', content: message.content });
|
|
621
|
+
return;
|
|
622
|
+
}
|
|
623
|
+
if (message.role === 'assistant') {
|
|
624
|
+
if (message.content?.trim()) {
|
|
625
|
+
entries.push({ id: `${idBase}-assistant`, role: 'assistant', content: message.content });
|
|
626
|
+
}
|
|
627
|
+
for (const summary of sessionToolCallSummaries(message)) {
|
|
628
|
+
if (!completedToolCallIds.has(summary.id)) {
|
|
629
|
+
entries.push({
|
|
630
|
+
id: `${idBase}-tool-call-${entries.length}`,
|
|
631
|
+
role: 'tool',
|
|
632
|
+
content: summary.content,
|
|
633
|
+
});
|
|
634
|
+
}
|
|
635
|
+
}
|
|
636
|
+
return;
|
|
637
|
+
}
|
|
638
|
+
if (message.role === 'tool') {
|
|
639
|
+
const summary = sessionToolResultSummary(message, toolCallsById);
|
|
640
|
+
const call = message.toolCallId ? toolCallsById.get(message.toolCallId) : undefined;
|
|
641
|
+
const trace = message.toolCallId ? resultTraceByCallId.get(message.toolCallId) : undefined;
|
|
642
|
+
const durable = (0, tool_serializer_1.parseToolResultEnvelope)(message.content);
|
|
643
|
+
const modelVisible = message.modelVisibleContent
|
|
644
|
+
? (0, tool_serializer_1.parseToolResultEnvelope)(message.modelVisibleContent)
|
|
645
|
+
: durable;
|
|
646
|
+
const durableOutput = typeof durable.output === 'string' ? durable.output : '';
|
|
647
|
+
const displayOutput = typeof modelVisible.output === 'string' ? modelVisible.output : durableOutput;
|
|
648
|
+
const outputBytes = trace?.outputBytes
|
|
649
|
+
?? (durable.schemaVersion === 1 ? durable.outputBytes : undefined)
|
|
650
|
+
?? Buffer.byteLength(durableOutput, 'utf8');
|
|
651
|
+
const artifactId = durable.artifactRef?.id ?? trace?.artifactId;
|
|
652
|
+
fallbackToolSequence += 1;
|
|
653
|
+
const sequence = message.toolCallId
|
|
654
|
+
? sequenceByCallId.get(message.toolCallId) ?? fallbackToolSequence
|
|
655
|
+
: fallbackToolSequence;
|
|
656
|
+
const outputView = options.includeToolOutputViews && call && message.toolCallId
|
|
657
|
+
? (0, tool_output_presentation_1.createToolOutputView)({
|
|
658
|
+
toolName: call.function.name,
|
|
659
|
+
success: durable.success,
|
|
660
|
+
summary: durable.summary,
|
|
661
|
+
rawOutput: durableOutput.length <= 64 * 1024 ? durableOutput : displayOutput,
|
|
662
|
+
outputBytes,
|
|
663
|
+
artifactRef: artifactId ? { id: artifactId, outputBytes } : undefined,
|
|
664
|
+
callId: message.toolCallId,
|
|
665
|
+
sequence,
|
|
666
|
+
turnId: trace?.turnId,
|
|
667
|
+
policy: tool_output_presentation_1.DEFAULT_TOOL_OUTPUT_POLICY,
|
|
668
|
+
})
|
|
669
|
+
: undefined;
|
|
670
|
+
entries.push({
|
|
671
|
+
id: `${idBase}-tool`,
|
|
672
|
+
role: 'tool',
|
|
673
|
+
content: summary ??
|
|
674
|
+
(message.toolCallId
|
|
675
|
+
? `Tool result ${message.toolCallId}\n${message.content}`
|
|
676
|
+
: message.content),
|
|
677
|
+
toolActivity: call && message.toolCallId && outputView
|
|
678
|
+
? {
|
|
679
|
+
state: durable.success ? 'success' : 'error',
|
|
680
|
+
name: call.function.name,
|
|
681
|
+
detail: (0, session_storage_1.redactTraceText)(compactToolArgs(parseToolCallArgs(call.function.arguments))),
|
|
682
|
+
summary: durable.summary
|
|
683
|
+
? (0, session_storage_1.redactTraceText)(durable.summary.split(/\r?\n/u, 1)[0])
|
|
684
|
+
: undefined,
|
|
685
|
+
outputBytes,
|
|
686
|
+
body: (0, session_storage_1.redactTraceText)(durableOutput.length <= 64 * 1024 ? durableOutput : displayOutput),
|
|
687
|
+
error: durable.error ? (0, session_storage_1.redactTraceText)(durable.error) : undefined,
|
|
688
|
+
duration: typeof trace?.duration === 'number' ? `${trace.duration}ms` : undefined,
|
|
689
|
+
seq: sequence,
|
|
690
|
+
artifactHint: artifactId ? `/artifacts show ${artifactId} --full` : undefined,
|
|
691
|
+
callId: message.toolCallId,
|
|
692
|
+
turnId: trace?.turnId,
|
|
693
|
+
outputView,
|
|
694
|
+
}
|
|
695
|
+
: undefined,
|
|
696
|
+
});
|
|
697
|
+
return;
|
|
698
|
+
}
|
|
699
|
+
if (message.role === 'system') {
|
|
700
|
+
entries.push({ id: `${idBase}-system`, role: 'system', content: message.content });
|
|
701
|
+
}
|
|
702
|
+
});
|
|
703
|
+
return entries;
|
|
704
|
+
}
|
|
705
|
+
function createAssistantStreamPresenter(events, abortSignal) {
|
|
706
|
+
let activeSegmentText = '';
|
|
707
|
+
let activeEntryId = null;
|
|
708
|
+
const ensureLiveEntry = () => {
|
|
709
|
+
if (abortSignal?.aborted || !activeSegmentText)
|
|
710
|
+
return null;
|
|
711
|
+
if (activeEntryId) {
|
|
712
|
+
events.update(activeEntryId, { content: activeSegmentText });
|
|
713
|
+
return activeEntryId;
|
|
714
|
+
}
|
|
715
|
+
activeEntryId = events.append({
|
|
716
|
+
role: 'assistant',
|
|
717
|
+
content: activeSegmentText,
|
|
718
|
+
live: true,
|
|
719
|
+
});
|
|
720
|
+
return activeEntryId;
|
|
721
|
+
};
|
|
722
|
+
const flushSegment = () => {
|
|
723
|
+
if (abortSignal?.aborted) {
|
|
724
|
+
if (activeEntryId)
|
|
725
|
+
events.remove(activeEntryId);
|
|
726
|
+
activeEntryId = null;
|
|
727
|
+
activeSegmentText = '';
|
|
728
|
+
return;
|
|
729
|
+
}
|
|
730
|
+
const entryId = ensureLiveEntry();
|
|
731
|
+
if (!entryId)
|
|
732
|
+
return;
|
|
733
|
+
events.finalize(entryId);
|
|
734
|
+
activeEntryId = null;
|
|
735
|
+
activeSegmentText = '';
|
|
736
|
+
};
|
|
737
|
+
return {
|
|
738
|
+
appendChunk(chunk) {
|
|
739
|
+
if (abortSignal?.aborted || !chunk)
|
|
740
|
+
return;
|
|
741
|
+
activeSegmentText += chunk;
|
|
742
|
+
ensureLiveEntry();
|
|
743
|
+
},
|
|
744
|
+
closeSegment() {
|
|
745
|
+
flushSegment();
|
|
746
|
+
},
|
|
747
|
+
discardSegment() {
|
|
748
|
+
if (activeEntryId)
|
|
749
|
+
events.remove(activeEntryId);
|
|
750
|
+
activeEntryId = null;
|
|
751
|
+
activeSegmentText = '';
|
|
752
|
+
},
|
|
753
|
+
ensureMessage(content) {
|
|
754
|
+
if (abortSignal?.aborted || !content || activeSegmentText.length > 0)
|
|
755
|
+
return;
|
|
756
|
+
activeSegmentText = content;
|
|
757
|
+
ensureLiveEntry();
|
|
758
|
+
},
|
|
759
|
+
replaceMessage(content) {
|
|
760
|
+
if (abortSignal?.aborted || !content)
|
|
761
|
+
return;
|
|
762
|
+
activeSegmentText = content;
|
|
763
|
+
ensureLiveEntry();
|
|
764
|
+
},
|
|
765
|
+
};
|
|
766
|
+
}
|
|
767
|
+
class LocalFastPathBlockedError extends Error {
|
|
768
|
+
constructor(message) {
|
|
769
|
+
super(message);
|
|
770
|
+
this.name = 'LocalFastPathBlockedError';
|
|
771
|
+
}
|
|
772
|
+
}
|
|
773
|
+
function parseLocalFastPath(input) {
|
|
774
|
+
const text = input.trim();
|
|
775
|
+
if (/^git\s+status$/i.test(text)) {
|
|
776
|
+
return { tool: 'git_status', args: {}, label: 'git status' };
|
|
777
|
+
}
|
|
778
|
+
const readMatch = /^(?:read|读取)\s+(.+)$/i.exec(text);
|
|
779
|
+
const readTarget = readMatch?.[1]?.trim();
|
|
780
|
+
const looksLikePath = Boolean(readTarget) &&
|
|
781
|
+
!/\s/.test(readTarget) &&
|
|
782
|
+
(/[/\\.]/.test(readTarget) || readTarget.startsWith('~'));
|
|
783
|
+
if (readTarget && looksLikePath) {
|
|
784
|
+
return { tool: 'read_file', args: { path: readTarget }, label: `read ${readTarget}` };
|
|
785
|
+
}
|
|
786
|
+
const grepMatch = /^(?:grep|搜索)\s+(.+)$/i.exec(text);
|
|
787
|
+
if (grepMatch?.[1]?.trim()) {
|
|
788
|
+
return {
|
|
789
|
+
tool: 'grep',
|
|
790
|
+
args: { pattern: grepMatch[1].trim() },
|
|
791
|
+
label: `grep ${grepMatch[1].trim()}`,
|
|
792
|
+
};
|
|
793
|
+
}
|
|
794
|
+
const runTestMatch = /^(?:run\s+test|运行测试)\s*[::]\s*(.+)$/i.exec(text);
|
|
795
|
+
if (runTestMatch?.[1]?.trim()) {
|
|
796
|
+
return {
|
|
797
|
+
tool: 'exec_command',
|
|
798
|
+
args: { command: runTestMatch[1].trim() },
|
|
799
|
+
label: `run test: ${runTestMatch[1].trim()}`,
|
|
800
|
+
};
|
|
801
|
+
}
|
|
802
|
+
return null;
|
|
803
|
+
}
|
|
804
|
+
function formatLocalFastPathAssistantContent(action, rawResult, projectPath) {
|
|
805
|
+
const envelope = (0, tool_serializer_1.parseToolResultEnvelope)(rawResult);
|
|
806
|
+
const rawOutput = typeof envelope.output === 'string' ? envelope.output : '';
|
|
807
|
+
const output = rawOutput.trim();
|
|
808
|
+
const summary = envelope.summary || `${action.tool} ${envelope.success ? 'completed' : 'failed'}`;
|
|
809
|
+
const lines = [
|
|
810
|
+
envelope.success
|
|
811
|
+
? `Local fast path completed ${action.label}.`
|
|
812
|
+
: `Local fast path failed ${action.label}.`,
|
|
813
|
+
'',
|
|
814
|
+
summary,
|
|
815
|
+
];
|
|
816
|
+
if (!envelope.success && envelope.error) {
|
|
817
|
+
lines.push(`Error: ${envelope.error}`);
|
|
818
|
+
}
|
|
819
|
+
if (!output) {
|
|
820
|
+
return { content: lines.join('\n'), artifactRef: envelope.artifactRef };
|
|
821
|
+
}
|
|
822
|
+
let artifactRef = envelope.artifactRef;
|
|
823
|
+
let preview = output;
|
|
824
|
+
const outputBytes = envelope.outputBytes ?? byteLength(rawOutput);
|
|
825
|
+
if (byteLength(rawOutput) > LOCAL_FAST_PATH_INLINE_OUTPUT_BYTES) {
|
|
826
|
+
if (!artifactRef) {
|
|
827
|
+
const artifact = (0, tool_artifacts_1.storeArtifact)(projectPath, action.tool, rawOutput, outputBytes);
|
|
828
|
+
artifactRef = artifact ? { id: artifact.id, outputBytes: artifact.outputBytes } : undefined;
|
|
829
|
+
}
|
|
830
|
+
preview = (0, tool_artifacts_1.truncateForContext)(output, LOCAL_FAST_PATH_INLINE_OUTPUT_BYTES);
|
|
831
|
+
}
|
|
832
|
+
if (artifactRef) {
|
|
833
|
+
lines.push('', `Full output: /artifacts show ${artifactRef.id} --full (${(0, format_1.formatBytes)(artifactRef.outputBytes)})`);
|
|
834
|
+
}
|
|
835
|
+
lines.push('', 'Preview:', preview);
|
|
836
|
+
return { content: lines.join('\n'), artifactRef };
|
|
837
|
+
}
|
|
838
|
+
function createToolEventPresenter(events, options = {}) {
|
|
839
|
+
const runningToolEntries = new Map();
|
|
840
|
+
let toolSequenceCounter = 0;
|
|
841
|
+
return {
|
|
842
|
+
start(event) {
|
|
843
|
+
const seq = ++toolSequenceCounter;
|
|
844
|
+
const entryId = events.append({
|
|
845
|
+
role: 'tool',
|
|
846
|
+
title: 'tool',
|
|
847
|
+
content: toolStartContent(event),
|
|
848
|
+
toolActivity: structuredToolStartActivity(event, seq),
|
|
849
|
+
});
|
|
850
|
+
runningToolEntries.set(event.callId, {
|
|
851
|
+
entryId,
|
|
852
|
+
name: event.name,
|
|
853
|
+
args: event.args,
|
|
854
|
+
sequence: seq,
|
|
855
|
+
batchCount: event.batchCount,
|
|
856
|
+
batchIndex: event.batchIndex,
|
|
857
|
+
});
|
|
858
|
+
events.toolStarted?.({
|
|
859
|
+
callId: event.callId,
|
|
860
|
+
name: event.name,
|
|
861
|
+
args: event.args,
|
|
862
|
+
sequence: seq,
|
|
863
|
+
batchCount: event.batchCount,
|
|
864
|
+
batchIndex: event.batchIndex,
|
|
865
|
+
});
|
|
866
|
+
},
|
|
867
|
+
finish(event) {
|
|
868
|
+
const content = toolFinishContent(event);
|
|
869
|
+
const stored = runningToolEntries.get(event.callId);
|
|
870
|
+
const seq = stored?.sequence ?? ++toolSequenceCounter;
|
|
871
|
+
const toolActivity = structuredToolFinishActivity(event, seq, options);
|
|
872
|
+
if (stored) {
|
|
873
|
+
events.finalize(stored.entryId, {
|
|
874
|
+
role: event.success ? 'tool' : 'error',
|
|
875
|
+
title: 'tool',
|
|
876
|
+
content,
|
|
877
|
+
toolActivity,
|
|
878
|
+
});
|
|
879
|
+
runningToolEntries.delete(event.callId);
|
|
880
|
+
}
|
|
881
|
+
else {
|
|
882
|
+
const entryId = events.append({
|
|
883
|
+
role: event.success ? 'tool' : 'error',
|
|
884
|
+
title: 'tool',
|
|
885
|
+
content,
|
|
886
|
+
toolActivity,
|
|
887
|
+
});
|
|
888
|
+
events.finalize(entryId);
|
|
889
|
+
}
|
|
890
|
+
events.toolFinished?.({
|
|
891
|
+
callId: event.callId,
|
|
892
|
+
name: event.name,
|
|
893
|
+
args: event.args,
|
|
894
|
+
success: event.success,
|
|
895
|
+
duration: event.duration,
|
|
896
|
+
summary: event.summary,
|
|
897
|
+
error: event.error,
|
|
898
|
+
outputBytes: event.outputBytes,
|
|
899
|
+
artifactRef: toolActivity.outputView?.detailRef?.artifactId
|
|
900
|
+
? {
|
|
901
|
+
id: toolActivity.outputView.detailRef.artifactId,
|
|
902
|
+
outputBytes: toolActivity.outputView.detailRef.outputBytes,
|
|
903
|
+
}
|
|
904
|
+
: event.artifactRef,
|
|
905
|
+
sequence: seq,
|
|
906
|
+
batchCount: event.batchCount,
|
|
907
|
+
batchIndex: event.batchIndex,
|
|
908
|
+
});
|
|
909
|
+
},
|
|
910
|
+
finalizePendingAsSkipped(reason = 'permission denied') {
|
|
911
|
+
for (const [callId, entry] of runningToolEntries) {
|
|
912
|
+
events.finalize(entry.entryId, {
|
|
913
|
+
role: 'tool',
|
|
914
|
+
title: 'tool',
|
|
915
|
+
content: `Skipped · ${reason}`,
|
|
916
|
+
toolActivity: {
|
|
917
|
+
state: 'skipped',
|
|
918
|
+
name: entry.name,
|
|
919
|
+
detail: '',
|
|
920
|
+
body: '',
|
|
921
|
+
error: reason,
|
|
922
|
+
seq: entry.sequence,
|
|
923
|
+
},
|
|
924
|
+
});
|
|
925
|
+
events.toolFinished?.({
|
|
926
|
+
callId,
|
|
927
|
+
name: entry.name,
|
|
928
|
+
args: entry.args,
|
|
929
|
+
success: false,
|
|
930
|
+
skipped: true,
|
|
931
|
+
duration: 0,
|
|
932
|
+
error: reason,
|
|
933
|
+
sequence: entry.sequence,
|
|
934
|
+
batchCount: entry.batchCount,
|
|
935
|
+
batchIndex: entry.batchIndex,
|
|
936
|
+
});
|
|
937
|
+
}
|
|
938
|
+
runningToolEntries.clear();
|
|
939
|
+
},
|
|
940
|
+
};
|
|
941
|
+
}
|
|
942
|
+
async function captureConsoleOutput(fn) {
|
|
943
|
+
const lines = [];
|
|
944
|
+
const originalLog = console.log;
|
|
945
|
+
const originalError = console.error;
|
|
946
|
+
const originalWarn = console.warn;
|
|
947
|
+
const capture = (...args) => {
|
|
948
|
+
lines.push(stripAnsi(args.map(arg => (typeof arg === 'string' ? arg : JSON.stringify(arg))).join(' ')));
|
|
949
|
+
};
|
|
950
|
+
console.log = capture;
|
|
951
|
+
console.error = capture;
|
|
952
|
+
console.warn = capture;
|
|
953
|
+
try {
|
|
954
|
+
const result = await fn();
|
|
955
|
+
return { result, output: lines.join('\n').trim() };
|
|
956
|
+
}
|
|
957
|
+
finally {
|
|
958
|
+
console.log = originalLog;
|
|
959
|
+
console.error = originalError;
|
|
960
|
+
console.warn = originalWarn;
|
|
961
|
+
}
|
|
962
|
+
}
|
|
963
|
+
class AgentChatController {
|
|
964
|
+
setGoalCoordinator(coord) {
|
|
965
|
+
this.goalCoordinator = coord;
|
|
966
|
+
}
|
|
967
|
+
constructor(runtime, events, controllerOptions = {}) {
|
|
968
|
+
this.runtime = runtime;
|
|
969
|
+
this.events = events;
|
|
970
|
+
this.controllerOptions = controllerOptions;
|
|
971
|
+
/** v0.2.26: optional goal coordinator for prompt injection and turn finalization. */
|
|
972
|
+
this.goalCoordinator = null;
|
|
973
|
+
}
|
|
974
|
+
setLoopStats(stats) {
|
|
975
|
+
this.runtime.store.setLastLoopStats(stats);
|
|
976
|
+
this.events.loopStatsUpdated?.(stats);
|
|
977
|
+
}
|
|
978
|
+
async runInput(input, options = {}) {
|
|
979
|
+
const text = input.trim();
|
|
980
|
+
if (!text)
|
|
981
|
+
return;
|
|
982
|
+
const parsed = (0, parser_1.parseInput)(text);
|
|
983
|
+
if (!parsed.isCommand) {
|
|
984
|
+
const localFastPath = parseLocalFastPath(text);
|
|
985
|
+
if (localFastPath) {
|
|
986
|
+
await this.runLocalFastPath(text, localFastPath, options);
|
|
987
|
+
return;
|
|
988
|
+
}
|
|
989
|
+
await this.runChat(text, options);
|
|
990
|
+
return;
|
|
991
|
+
}
|
|
992
|
+
if (parsed.name === 'clear') {
|
|
993
|
+
this.events.clearTranscript();
|
|
994
|
+
this.events.setStatus('View cleared. Conversation context is preserved.');
|
|
995
|
+
return;
|
|
996
|
+
}
|
|
997
|
+
if (parsed.name === 'exit' || parsed.name === 'quit' || parsed.name === 'q') {
|
|
998
|
+
await this.runtime.shutdown();
|
|
999
|
+
return;
|
|
1000
|
+
}
|
|
1001
|
+
const command = (0, commands_1.findCommand)(parsed.name);
|
|
1002
|
+
if (!command) {
|
|
1003
|
+
if ((0, skills_1.hasMatchingSkill)(text, this.runtime.cwd)) {
|
|
1004
|
+
await this.runChat(text, options);
|
|
1005
|
+
return;
|
|
1006
|
+
}
|
|
1007
|
+
const suggestions = (0, parser_1.buildCommandSuggestions)(parsed.name);
|
|
1008
|
+
this.events.append({
|
|
1009
|
+
role: 'error',
|
|
1010
|
+
title: 'unknown command',
|
|
1011
|
+
content: suggestions.length > 0
|
|
1012
|
+
? `Unknown command: /${parsed.name}\nDid you mean: ${suggestions.map(item => `/${item}`).join(', ')}?`
|
|
1013
|
+
: `Unknown command: /${parsed.name}`,
|
|
1014
|
+
errorLayer: 'runtime',
|
|
1015
|
+
});
|
|
1016
|
+
return;
|
|
1017
|
+
}
|
|
1018
|
+
const ctx = this.createCommandContext(options.abortSignal, options.turnId);
|
|
1019
|
+
const { result, output } = await captureConsoleOutput(() => command.execute(ctx, parsed.args));
|
|
1020
|
+
if (output) {
|
|
1021
|
+
this.events.append({
|
|
1022
|
+
role: result.success ? 'system' : 'error',
|
|
1023
|
+
title: `/${command.name}`,
|
|
1024
|
+
content: output,
|
|
1025
|
+
});
|
|
1026
|
+
}
|
|
1027
|
+
if (result.output) {
|
|
1028
|
+
this.events.append({
|
|
1029
|
+
role: result.success ? 'system' : 'error',
|
|
1030
|
+
title: `/${command.name}`,
|
|
1031
|
+
content: result.output,
|
|
1032
|
+
});
|
|
1033
|
+
}
|
|
1034
|
+
if (result.error) {
|
|
1035
|
+
this.events.append({
|
|
1036
|
+
role: 'error',
|
|
1037
|
+
title: `/${command.name}`,
|
|
1038
|
+
content: result.error,
|
|
1039
|
+
errorLayer: 'runtime',
|
|
1040
|
+
});
|
|
1041
|
+
}
|
|
1042
|
+
if (result.sessionPicker) {
|
|
1043
|
+
this.events.showSessionPicker(result.sessionPicker);
|
|
1044
|
+
return;
|
|
1045
|
+
}
|
|
1046
|
+
if (result.editPreview) {
|
|
1047
|
+
this.events.showEditPreview(result.editPreview);
|
|
1048
|
+
return;
|
|
1049
|
+
}
|
|
1050
|
+
if (result.continueAsChat) {
|
|
1051
|
+
await this.runChat(result.chatInput ?? parsed.args, options);
|
|
1052
|
+
}
|
|
1053
|
+
}
|
|
1054
|
+
async runLocalFastPath(input, action, options = {}) {
|
|
1055
|
+
const activeSession = this.runtime.getSession() ??
|
|
1056
|
+
this.runtime.ensureSession() ??
|
|
1057
|
+
(0, session_storage_1.loadSessionMeta)(this.runtime.getSession()?.id ?? '');
|
|
1058
|
+
const sessionId = activeSession?.id;
|
|
1059
|
+
const turnId = traceTurnId(options.turnId);
|
|
1060
|
+
const localCallId = `local-${turnId}`;
|
|
1061
|
+
const start = Date.now();
|
|
1062
|
+
const preWorkspace = (0, workspace_state_1.captureWorkspaceSnapshot)(this.runtime.cwd);
|
|
1063
|
+
const traceArgs = buildTraceArgsDetails(this.runtime.cwd, action.tool, action.args);
|
|
1064
|
+
if (sessionId) {
|
|
1065
|
+
(0, session_storage_1.appendSessionMessage)(sessionId, {
|
|
1066
|
+
role: 'user',
|
|
1067
|
+
content: input,
|
|
1068
|
+
timestamp: Date.now(),
|
|
1069
|
+
});
|
|
1070
|
+
recordTraceEvent(this.events, sessionId, {
|
|
1071
|
+
turnId,
|
|
1072
|
+
type: 'turn_start',
|
|
1073
|
+
inputBytes: byteLength(input),
|
|
1074
|
+
localFastPathUsed: true,
|
|
1075
|
+
});
|
|
1076
|
+
appendWorkspaceSnapshotTrace(this.events, sessionId, turnId, 'pre_turn', preWorkspace);
|
|
1077
|
+
recordTraceEvent(this.events, sessionId, {
|
|
1078
|
+
turnId,
|
|
1079
|
+
type: 'local_fast_path',
|
|
1080
|
+
name: action.tool,
|
|
1081
|
+
...traceArgs,
|
|
1082
|
+
note: compactMiddle(action.label, 160),
|
|
1083
|
+
});
|
|
1084
|
+
}
|
|
1085
|
+
this.runtime.store.addMessage({ role: 'user', content: input });
|
|
1086
|
+
this.events.setStatus(`Running local ${action.label}...`);
|
|
1087
|
+
try {
|
|
1088
|
+
const tool = (0, tools_1.getRuntimeTools)().find(candidate => candidate.name === action.tool);
|
|
1089
|
+
const toolContext = {
|
|
1090
|
+
cwd: this.runtime.cwd,
|
|
1091
|
+
config: {
|
|
1092
|
+
name: this.runtime.config.name,
|
|
1093
|
+
mode: this.runtime.config.mode,
|
|
1094
|
+
},
|
|
1095
|
+
sessionId,
|
|
1096
|
+
turnId,
|
|
1097
|
+
};
|
|
1098
|
+
const permission = tool?.checkPermissions?.(action.args, toolContext);
|
|
1099
|
+
if (permission?.behavior === 'deny' || tool?.isDestructive?.(action.args) === true) {
|
|
1100
|
+
const reason = permission?.reason || 'Local fast path blocked a destructive tool request.';
|
|
1101
|
+
throw new LocalFastPathBlockedError(reason);
|
|
1102
|
+
}
|
|
1103
|
+
if (permission?.behavior === 'ask') {
|
|
1104
|
+
throw new LocalFastPathBlockedError(permission.reason || 'Local fast path requires an allow-safe command.');
|
|
1105
|
+
}
|
|
1106
|
+
if (sessionId) {
|
|
1107
|
+
recordTraceEvent(this.events, sessionId, {
|
|
1108
|
+
turnId,
|
|
1109
|
+
type: 'tool_call',
|
|
1110
|
+
name: action.tool,
|
|
1111
|
+
callId: localCallId,
|
|
1112
|
+
...traceArgs,
|
|
1113
|
+
});
|
|
1114
|
+
}
|
|
1115
|
+
const result = await (0, tools_1.executeTool)(action.tool, action.args, options.abortSignal, {
|
|
1116
|
+
...toolContext,
|
|
1117
|
+
sessionId,
|
|
1118
|
+
turnId,
|
|
1119
|
+
});
|
|
1120
|
+
const duration = Date.now() - start;
|
|
1121
|
+
const envelope = (0, tool_serializer_1.parseToolResultEnvelope)(result);
|
|
1122
|
+
const outputBytes = typeof envelope.outputBytes === 'number'
|
|
1123
|
+
? envelope.outputBytes
|
|
1124
|
+
: Buffer.byteLength(result, 'utf8');
|
|
1125
|
+
const formattedLocalResult = formatLocalFastPathAssistantContent(action, result, this.runtime.cwd);
|
|
1126
|
+
const assistantContent = formattedLocalResult.content;
|
|
1127
|
+
const stats = (0, framework_1.createLocalFastPathLoopStats)({
|
|
1128
|
+
finishReason: envelope.success ? 'completed' : 'failed',
|
|
1129
|
+
toolCalls: 1,
|
|
1130
|
+
readOnlyToolCalls: action.tool === 'exec_command' ? 0 : 1,
|
|
1131
|
+
unsafeToolCalls: action.tool === 'exec_command' ? 1 : 0,
|
|
1132
|
+
toolResultBytes: outputBytes,
|
|
1133
|
+
modelVisibleToolBytes: 0,
|
|
1134
|
+
summarizedBytes: outputBytes,
|
|
1135
|
+
});
|
|
1136
|
+
const localToolResultEvent = {
|
|
1137
|
+
type: 'tool_result',
|
|
1138
|
+
name: action.tool,
|
|
1139
|
+
args: action.args,
|
|
1140
|
+
callId: localCallId,
|
|
1141
|
+
result,
|
|
1142
|
+
modelVisibleResult: result,
|
|
1143
|
+
duration,
|
|
1144
|
+
success: envelope.success,
|
|
1145
|
+
error: envelope.error,
|
|
1146
|
+
summary: envelope.summary,
|
|
1147
|
+
outputBytes,
|
|
1148
|
+
artifactRef: formattedLocalResult.artifactRef,
|
|
1149
|
+
};
|
|
1150
|
+
this.events.append({
|
|
1151
|
+
role: envelope.success ? 'tool' : 'error',
|
|
1152
|
+
title: 'local',
|
|
1153
|
+
content: toolFinishContent(localToolResultEvent),
|
|
1154
|
+
toolActivity: structuredToolFinishActivity(localToolResultEvent, 1, {
|
|
1155
|
+
projectPath: this.runtime.cwd,
|
|
1156
|
+
turnId,
|
|
1157
|
+
}),
|
|
1158
|
+
});
|
|
1159
|
+
this.runtime.store.addMessage({ role: 'assistant', content: assistantContent });
|
|
1160
|
+
this.setLoopStats(stats);
|
|
1161
|
+
if (sessionId) {
|
|
1162
|
+
recordTraceEvent(this.events, sessionId, {
|
|
1163
|
+
turnId,
|
|
1164
|
+
type: 'tool_result',
|
|
1165
|
+
name: action.tool,
|
|
1166
|
+
callId: localCallId,
|
|
1167
|
+
argsSummary: traceArgs.argsSummary,
|
|
1168
|
+
argsArtifactId: traceArgs.argsArtifactId,
|
|
1169
|
+
argsBytes: traceArgs.argsBytes,
|
|
1170
|
+
success: envelope.success,
|
|
1171
|
+
duration,
|
|
1172
|
+
outputBytes,
|
|
1173
|
+
modelVisibleBytes: 0,
|
|
1174
|
+
artifactId: formattedLocalResult.artifactRef?.id,
|
|
1175
|
+
error: envelope.error ? compactMiddle(envelope.error, 240) : undefined,
|
|
1176
|
+
});
|
|
1177
|
+
appendPostWorkspaceTrace(this.events, sessionId, turnId, this.runtime.cwd, preWorkspace);
|
|
1178
|
+
recordTraceEvent(this.events, sessionId, {
|
|
1179
|
+
turnId,
|
|
1180
|
+
type: 'complete',
|
|
1181
|
+
finishReason: stats.finishReason,
|
|
1182
|
+
llmRequests: stats.llmRequests,
|
|
1183
|
+
toolCalls: stats.toolCalls,
|
|
1184
|
+
readOnlyToolCalls: stats.readOnlyToolCalls,
|
|
1185
|
+
unsafeToolCalls: stats.unsafeToolCalls,
|
|
1186
|
+
localFastPathUsed: true,
|
|
1187
|
+
});
|
|
1188
|
+
(0, session_storage_1.appendSessionMessage)(sessionId, {
|
|
1189
|
+
role: 'assistant',
|
|
1190
|
+
content: assistantContent,
|
|
1191
|
+
timestamp: Date.now(),
|
|
1192
|
+
});
|
|
1193
|
+
const recordedMessages = (0, session_storage_1.readSessionMessages)(sessionId);
|
|
1194
|
+
if (recordedMessages.length > 0) {
|
|
1195
|
+
(0, session_storage_1.updateSessionSummary)(sessionId, recordedMessages);
|
|
1196
|
+
}
|
|
1197
|
+
}
|
|
1198
|
+
this.events.setStatus(envelope.success ? `Completed local ${action.label}` : `Failed local ${action.label}`);
|
|
1199
|
+
}
|
|
1200
|
+
catch (error) {
|
|
1201
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
1202
|
+
this.events.append({ role: 'error', title: 'local', content: message, errorLayer: 'tool' });
|
|
1203
|
+
this.events.setStatus('Local command failed. Ready for the next input.');
|
|
1204
|
+
const assistantContent = `Local fast path failed for ${action.label}.\n\n${message}`;
|
|
1205
|
+
this.runtime.store.addMessage({ role: 'assistant', content: assistantContent });
|
|
1206
|
+
const finishReason = error instanceof LocalFastPathBlockedError ? 'blocked' : 'failed';
|
|
1207
|
+
const stats = (0, framework_1.createLocalFastPathLoopStats)({
|
|
1208
|
+
finishReason,
|
|
1209
|
+
toolCalls: 0,
|
|
1210
|
+
});
|
|
1211
|
+
this.setLoopStats(stats);
|
|
1212
|
+
if (sessionId) {
|
|
1213
|
+
recordTraceEvent(this.events, sessionId, {
|
|
1214
|
+
turnId,
|
|
1215
|
+
type: 'error',
|
|
1216
|
+
name: action.tool,
|
|
1217
|
+
error: compactTraceError(error),
|
|
1218
|
+
});
|
|
1219
|
+
appendPostWorkspaceTrace(this.events, sessionId, turnId, this.runtime.cwd, preWorkspace);
|
|
1220
|
+
recordTraceEvent(this.events, sessionId, {
|
|
1221
|
+
turnId,
|
|
1222
|
+
type: 'complete',
|
|
1223
|
+
finishReason: stats.finishReason,
|
|
1224
|
+
llmRequests: stats.llmRequests,
|
|
1225
|
+
toolCalls: stats.toolCalls,
|
|
1226
|
+
localFastPathUsed: true,
|
|
1227
|
+
note: 'local_fast_path_failed',
|
|
1228
|
+
});
|
|
1229
|
+
(0, session_storage_1.appendSessionMessage)(sessionId, {
|
|
1230
|
+
role: 'assistant',
|
|
1231
|
+
content: assistantContent,
|
|
1232
|
+
timestamp: Date.now(),
|
|
1233
|
+
});
|
|
1234
|
+
}
|
|
1235
|
+
}
|
|
1236
|
+
}
|
|
1237
|
+
createCommandContext(abortSignal, turnId) {
|
|
1238
|
+
return {
|
|
1239
|
+
cwd: this.runtime.cwd,
|
|
1240
|
+
config: this.runtime.config,
|
|
1241
|
+
store: this.runtime.store,
|
|
1242
|
+
llm: this.runtime.llm,
|
|
1243
|
+
compactCoordinator: this.runtime.compactCoordinator,
|
|
1244
|
+
runtime: this.runtime.runtime,
|
|
1245
|
+
sessionId: this.runtime.getSession()?.id,
|
|
1246
|
+
turnId,
|
|
1247
|
+
ensureSession: this.runtime.ensureSession,
|
|
1248
|
+
setSession: session => {
|
|
1249
|
+
this.runtime.setSession(session);
|
|
1250
|
+
const renderer = this.controllerOptions.uiRenderer
|
|
1251
|
+
?? this.runtime.config.ui?.renderer
|
|
1252
|
+
?? 'terminal';
|
|
1253
|
+
this.events.replaceTranscript(sessionMessagesToTranscriptEntries(session.id, {
|
|
1254
|
+
includeToolOutputViews: renderer === 'tui',
|
|
1255
|
+
}));
|
|
1256
|
+
},
|
|
1257
|
+
sessionRestored: event => {
|
|
1258
|
+
this.events.sessionRestored?.(event);
|
|
1259
|
+
},
|
|
1260
|
+
getSession: this.runtime.getSession,
|
|
1261
|
+
abortSignal,
|
|
1262
|
+
writeOutput: text => {
|
|
1263
|
+
if (text.trim()) {
|
|
1264
|
+
this.events.append({ role: 'system', content: text });
|
|
1265
|
+
}
|
|
1266
|
+
},
|
|
1267
|
+
writeLine: text => {
|
|
1268
|
+
if (text?.trim()) {
|
|
1269
|
+
this.events.append({ role: 'system', content: text });
|
|
1270
|
+
}
|
|
1271
|
+
},
|
|
1272
|
+
uiRenderer: this.controllerOptions.uiRenderer ?? this.runtime.config.ui?.renderer ?? 'terminal',
|
|
1273
|
+
uiCapabilities: (0, ui_events_1.resolveUiRendererCapabilities)(this.controllerOptions.uiCapabilities, this.controllerOptions.uiRenderer ?? this.runtime.config.ui?.renderer),
|
|
1274
|
+
};
|
|
1275
|
+
}
|
|
1276
|
+
/**
|
|
1277
|
+
* Forward a subagent lifecycle event to the runtime event sink and session
|
|
1278
|
+
* trace. Renderers consume the same event across terminal/Ink/TUI; this is
|
|
1279
|
+
* the only place a subtask event touches the root loop.
|
|
1280
|
+
*/
|
|
1281
|
+
handleSubtaskEvent(event, sessionId, turnId) {
|
|
1282
|
+
// Emit the renderer-independent runtime event first so all renderers
|
|
1283
|
+
// (terminal/Ink/TUI) consume the same lifecycle through one protocol.
|
|
1284
|
+
this.events.subtaskEvent?.(event);
|
|
1285
|
+
const stateToTraceType = {
|
|
1286
|
+
queued: 'subtask_requested',
|
|
1287
|
+
running: 'subtask_started',
|
|
1288
|
+
completed: 'subtask_completed',
|
|
1289
|
+
failed: 'subtask_failed',
|
|
1290
|
+
cancelled: 'subtask_cancelled',
|
|
1291
|
+
rejected: 'subtask_rejected',
|
|
1292
|
+
timed_out: 'subtask_timed_out',
|
|
1293
|
+
};
|
|
1294
|
+
if (sessionId) {
|
|
1295
|
+
const traceType = stateToTraceType[event.state];
|
|
1296
|
+
if (traceType) {
|
|
1297
|
+
recordTraceEvent(this.events, sessionId, {
|
|
1298
|
+
turnId: String(turnId),
|
|
1299
|
+
type: traceType,
|
|
1300
|
+
name: `${event.role}:${event.taskId}`,
|
|
1301
|
+
argsSummary: event.objective.slice(0, 160),
|
|
1302
|
+
});
|
|
1303
|
+
}
|
|
1304
|
+
}
|
|
1305
|
+
// Surface start/complete/fail/cancel summaries in the transcript so all
|
|
1306
|
+
// renderers show subtask progress without renderer-local logic.
|
|
1307
|
+
if (event.state === 'running') {
|
|
1308
|
+
this.events.append({
|
|
1309
|
+
role: 'system',
|
|
1310
|
+
content: `▸ subtask ${event.role} started: ${event.objective.slice(0, 120)}`,
|
|
1311
|
+
});
|
|
1312
|
+
}
|
|
1313
|
+
else if (event.state === 'completed' ||
|
|
1314
|
+
event.state === 'failed' ||
|
|
1315
|
+
event.state === 'cancelled' ||
|
|
1316
|
+
event.state === 'timed_out' ||
|
|
1317
|
+
event.state === 'rejected') {
|
|
1318
|
+
const summary = event.summary ? ` — ${event.summary.slice(0, 200)}` : '';
|
|
1319
|
+
this.events.append({
|
|
1320
|
+
role: 'system',
|
|
1321
|
+
content: `◂ subtask ${event.role} ${event.state}${summary}`,
|
|
1322
|
+
});
|
|
1323
|
+
}
|
|
1324
|
+
}
|
|
1325
|
+
/**
|
|
1326
|
+
* Fold reconciled child aggregate usage into the root turn's loop stats so
|
|
1327
|
+
* `/cost` and loop-budget accounting reflect subagent cost. Child model
|
|
1328
|
+
* requests and tool calls are added to the root counters; a note records the
|
|
1329
|
+
* subagent contribution so it is distinguishable from root work.
|
|
1330
|
+
*/
|
|
1331
|
+
foldSubagentUsage(stats, bundle) {
|
|
1332
|
+
if (!bundle)
|
|
1333
|
+
return stats;
|
|
1334
|
+
const usage = bundle.getAggregateUsage();
|
|
1335
|
+
if (usage.modelRequests === 0 && usage.toolCalls === 0)
|
|
1336
|
+
return stats;
|
|
1337
|
+
const subtaskCount = bundle.getSubtaskCount();
|
|
1338
|
+
const subagentSuffix = `subagents: ${usage.modelRequests} req/${usage.toolCalls} calls across ${subtaskCount} task(s)`;
|
|
1339
|
+
return {
|
|
1340
|
+
...stats,
|
|
1341
|
+
llmRequests: (stats.llmRequests ?? 0) + usage.modelRequests,
|
|
1342
|
+
toolCalls: (stats.toolCalls ?? 0) + usage.toolCalls,
|
|
1343
|
+
readOnlyToolCalls: (stats.readOnlyToolCalls ?? 0) + usage.toolCalls,
|
|
1344
|
+
continuationHint: stats.continuationHint
|
|
1345
|
+
? `${stats.continuationHint} (${subagentSuffix})`
|
|
1346
|
+
: subagentSuffix,
|
|
1347
|
+
};
|
|
1348
|
+
}
|
|
1349
|
+
async runChat(input, options = {}) {
|
|
1350
|
+
if (!input) {
|
|
1351
|
+
this.events.append({
|
|
1352
|
+
role: 'error',
|
|
1353
|
+
content: 'Usage: /chat <message>',
|
|
1354
|
+
errorLayer: 'runtime',
|
|
1355
|
+
});
|
|
1356
|
+
return;
|
|
1357
|
+
}
|
|
1358
|
+
if (!this.runtime.llm || !(0, config_1.isConfigured)(this.runtime.config)) {
|
|
1359
|
+
this.events.append({
|
|
1360
|
+
role: 'error',
|
|
1361
|
+
content: 'LLM is not configured. Set ORION_CODE_API_KEY in ~/.orion-code/orion.json or environment.',
|
|
1362
|
+
errorLayer: 'provider',
|
|
1363
|
+
});
|
|
1364
|
+
return;
|
|
1365
|
+
}
|
|
1366
|
+
const abortSignal = options.abortSignal;
|
|
1367
|
+
const turnId = traceTurnId(options.turnId);
|
|
1368
|
+
const activeSession = this.runtime.getSession() ??
|
|
1369
|
+
this.runtime.ensureSession() ??
|
|
1370
|
+
(0, session_storage_1.loadSessionMeta)(this.runtime.getSession()?.id ?? '');
|
|
1371
|
+
const sessionId = activeSession?.id;
|
|
1372
|
+
const preWorkspace = (0, workspace_state_1.captureWorkspaceSnapshot)(this.runtime.cwd);
|
|
1373
|
+
const runtimeTools = (0, tools_1.getRuntimeTools)();
|
|
1374
|
+
const skillResolution = (0, skills_1.resolveSkillsForTurn)({
|
|
1375
|
+
cwd: this.runtime.cwd,
|
|
1376
|
+
input,
|
|
1377
|
+
tools: runtimeTools,
|
|
1378
|
+
projectPath: activeSession?.projectPath,
|
|
1379
|
+
sessionId,
|
|
1380
|
+
});
|
|
1381
|
+
const appliedSkillNames = skillResolution.skills.map(skill => skill.name);
|
|
1382
|
+
if (sessionId) {
|
|
1383
|
+
(0, session_storage_1.appendSessionMessage)(sessionId, {
|
|
1384
|
+
role: 'user',
|
|
1385
|
+
content: input,
|
|
1386
|
+
timestamp: Date.now(),
|
|
1387
|
+
appliedSkills: appliedSkillNames.length > 0 ? appliedSkillNames : undefined,
|
|
1388
|
+
});
|
|
1389
|
+
recordTraceEvent(this.events, sessionId, {
|
|
1390
|
+
turnId,
|
|
1391
|
+
type: 'turn_start',
|
|
1392
|
+
inputBytes: byteLength(input),
|
|
1393
|
+
note: appliedSkillNames.length > 0 ? `skills=${appliedSkillNames.join(',')}` : undefined,
|
|
1394
|
+
});
|
|
1395
|
+
appendWorkspaceSnapshotTrace(this.events, sessionId, turnId, 'pre_turn', preWorkspace);
|
|
1396
|
+
}
|
|
1397
|
+
this.runtime.store.addMessage({ role: 'user', content: input });
|
|
1398
|
+
(0, prompt_context_1.refreshProjectInstructions)(this.runtime.store, this.runtime.cwd);
|
|
1399
|
+
const snapshot = this.runtime.store.getSnapshot();
|
|
1400
|
+
const harness = (0, harness_1.createContextHarness)({
|
|
1401
|
+
cwd: this.runtime.cwd,
|
|
1402
|
+
modelId: this.runtime.llm.getModel(),
|
|
1403
|
+
state: snapshot.harnessState,
|
|
1404
|
+
config: {
|
|
1405
|
+
enabled: true,
|
|
1406
|
+
driftGuard: 'warn',
|
|
1407
|
+
completionGate: true,
|
|
1408
|
+
},
|
|
1409
|
+
});
|
|
1410
|
+
const intent = harness.updateContractFromUserInput(input);
|
|
1411
|
+
harness.recordAppliedSkills(skillResolution.skills);
|
|
1412
|
+
// Reconcile diagnostic: when harness state is present but objective may be incomplete
|
|
1413
|
+
if (snapshot.harnessState &&
|
|
1414
|
+
!snapshot.harnessState.rootObjective &&
|
|
1415
|
+
!snapshot.harnessState.contract?.objective) {
|
|
1416
|
+
this.events.setStatus('Resume diagnostic: harness state restored but objective may be incomplete. Run /harness explain to review.');
|
|
1417
|
+
}
|
|
1418
|
+
const subagentConfig = this.runtime.config.subagents;
|
|
1419
|
+
// The subtask capability is a root-level tool. It is exposed on normal
|
|
1420
|
+
// turns, but respects an active skill scope: when a skill restricts the
|
|
1421
|
+
// tool set, subtask is not appended (the skill owns the scope).
|
|
1422
|
+
const projectPath = activeSession?.projectPath;
|
|
1423
|
+
const subagentBundle = subagentConfig &&
|
|
1424
|
+
subagentConfig.mode !== 'off' &&
|
|
1425
|
+
this.runtime.llm &&
|
|
1426
|
+
!skillResolution.toolScopeActive
|
|
1427
|
+
? (0, subagents_1.createSubagentBundleForTurn)({
|
|
1428
|
+
config: subagentConfig,
|
|
1429
|
+
cwd: this.runtime.cwd,
|
|
1430
|
+
rootLlmConfig: (0, subagents_1.deriveRootLlmConfig)(this.runtime.config),
|
|
1431
|
+
modelLabel: this.runtime.llm.getModel(),
|
|
1432
|
+
rootObjectiveSummary: harness.toJSON()?.rootObjective ?? input,
|
|
1433
|
+
abortSignal,
|
|
1434
|
+
resilience: this.runtime.llm.resilience,
|
|
1435
|
+
onSubtaskEvent: event => {
|
|
1436
|
+
this.handleSubtaskEvent(event, sessionId, turnId);
|
|
1437
|
+
},
|
|
1438
|
+
onSubtaskResult: (result, _batchId) => {
|
|
1439
|
+
if (!projectPath || result.status !== 'completed')
|
|
1440
|
+
return;
|
|
1441
|
+
const json = JSON.stringify(result);
|
|
1442
|
+
const artifact = (0, tool_artifacts_1.storeArtifact)(projectPath, `subtask_${result.role}`, json, Buffer.byteLength(json, 'utf8'));
|
|
1443
|
+
if (artifact) {
|
|
1444
|
+
// Record a trace event for artifact discoverability only.
|
|
1445
|
+
// The subtask state transition (subtask_completed) is already
|
|
1446
|
+
// emitted by handleSubtaskEvent above.
|
|
1447
|
+
if (sessionId) {
|
|
1448
|
+
recordTraceEvent(this.events, sessionId, {
|
|
1449
|
+
turnId: String(turnId),
|
|
1450
|
+
type: 'subtask_artifact_stored',
|
|
1451
|
+
name: `${result.role}:${result.id}`,
|
|
1452
|
+
argsSummary: result.summary.slice(0, 200),
|
|
1453
|
+
argsArtifactId: artifact.id,
|
|
1454
|
+
argsBytes: artifact.outputBytes,
|
|
1455
|
+
});
|
|
1456
|
+
}
|
|
1457
|
+
}
|
|
1458
|
+
},
|
|
1459
|
+
// R6: wire live permission state so the subagent policy gate can
|
|
1460
|
+
// prevent background delegation while the user is deciding a tool
|
|
1461
|
+
// permission. Injected by AgentRuntimeController via chatOptions.
|
|
1462
|
+
hasPendingPermission: this.controllerOptions.hasPendingPermission,
|
|
1463
|
+
// R6: wire child usage callback so CostTracker records subagent
|
|
1464
|
+
// token consumption. Injected by AgentRuntimeController via chatOptions.
|
|
1465
|
+
onChildUsage: this.controllerOptions.onChildUsage,
|
|
1466
|
+
})
|
|
1467
|
+
: null;
|
|
1468
|
+
const subtaskTool = subagentBundle?.tool ?? null;
|
|
1469
|
+
const turnTools = subtaskTool ? [...skillResolution.tools, subtaskTool] : skillResolution.tools;
|
|
1470
|
+
const promptCtx = {
|
|
1471
|
+
cwd: this.runtime.cwd,
|
|
1472
|
+
platform: process.platform,
|
|
1473
|
+
nodeVersion: process.version,
|
|
1474
|
+
tools: turnTools,
|
|
1475
|
+
memoryContent: snapshot.memoryContent,
|
|
1476
|
+
skillsContent: snapshot.skillsContent,
|
|
1477
|
+
projectInstructionsContent: snapshot.projectInstructionsContent,
|
|
1478
|
+
activeSkillsContent: skillResolution.promptInjection,
|
|
1479
|
+
referencedFilesContent: (0, file_context_1.buildReferencedFilesPrompt)(input, this.runtime.cwd),
|
|
1480
|
+
goalContent: this.goalCoordinator?.goal?.status === 'active'
|
|
1481
|
+
? (0, prompt_1.buildGoalContextFragment)(this.goalCoordinator.goal)?.text
|
|
1482
|
+
: undefined,
|
|
1483
|
+
};
|
|
1484
|
+
const systemPrompt = (0, framework_1.buildSystemPrompt)(promptCtx);
|
|
1485
|
+
const messages = [
|
|
1486
|
+
{ role: 'system', content: systemPrompt.static, cacheControl: { type: 'ephemeral' } },
|
|
1487
|
+
...(systemPrompt.dynamic ? [{ role: 'system', content: systemPrompt.dynamic }] : []),
|
|
1488
|
+
...snapshot.conversationHistory,
|
|
1489
|
+
];
|
|
1490
|
+
let finalContent = '';
|
|
1491
|
+
let finalUsage;
|
|
1492
|
+
let finalModel = '';
|
|
1493
|
+
let pendingCompleteTrace = null;
|
|
1494
|
+
let pendingCompleteStats;
|
|
1495
|
+
let pendingCompact;
|
|
1496
|
+
const verificationResults = [];
|
|
1497
|
+
const sessionMessagesToRecord = [];
|
|
1498
|
+
const assistantStream = createAssistantStreamPresenter(this.events, abortSignal);
|
|
1499
|
+
const toolEvents = createToolEventPresenter(this.events, {
|
|
1500
|
+
projectPath: this.runtime.cwd,
|
|
1501
|
+
turnId,
|
|
1502
|
+
});
|
|
1503
|
+
let checkpointSequence = 0;
|
|
1504
|
+
const checkpointIds = [];
|
|
1505
|
+
const streamCallbacks = {
|
|
1506
|
+
onChunk: chunk => {
|
|
1507
|
+
assistantStream.appendChunk(chunk);
|
|
1508
|
+
},
|
|
1509
|
+
};
|
|
1510
|
+
const toolExecutor = async (name, args, signal) => {
|
|
1511
|
+
// The runtime-bound `subtask` tool is not in the global TOOLS registry;
|
|
1512
|
+
// dispatch it directly so it reaches the Supervisor closure.
|
|
1513
|
+
if (name === 'subtask' && subtaskTool) {
|
|
1514
|
+
const result = await subtaskTool.execute(args, {
|
|
1515
|
+
cwd: this.runtime.cwd,
|
|
1516
|
+
config: { name: this.runtime.config.name, mode: this.runtime.config.mode },
|
|
1517
|
+
abortSignal: signal,
|
|
1518
|
+
sessionId,
|
|
1519
|
+
turnId,
|
|
1520
|
+
});
|
|
1521
|
+
return JSON.stringify(result);
|
|
1522
|
+
}
|
|
1523
|
+
if (!turnTools.some(tool => tool.name === name)) {
|
|
1524
|
+
return JSON.stringify({
|
|
1525
|
+
success: false,
|
|
1526
|
+
error: skillResolution.toolScopeActive
|
|
1527
|
+
? `Tool ${name} is not available for the active skill scope. Available tools: ${skillResolution.tools.map(tool => tool.name).join(', ') || 'none'}`
|
|
1528
|
+
: `Tool ${name} is not available.`,
|
|
1529
|
+
});
|
|
1530
|
+
}
|
|
1531
|
+
return (0, tools_1.executeTool)(name, args, signal, {
|
|
1532
|
+
cwd: this.runtime.cwd,
|
|
1533
|
+
config: {
|
|
1534
|
+
name: this.runtime.config.name,
|
|
1535
|
+
mode: this.runtime.config.mode,
|
|
1536
|
+
},
|
|
1537
|
+
sessionId,
|
|
1538
|
+
turnId,
|
|
1539
|
+
});
|
|
1540
|
+
};
|
|
1541
|
+
const loopBudget = (0, loop_budget_1.resolveRuntimeLoopBudget)(input, this.runtime.config, harness.toJSON());
|
|
1542
|
+
let observedTurnsStarted = 0;
|
|
1543
|
+
let observedLlmRequests = 0;
|
|
1544
|
+
let observedToolCalls = 0;
|
|
1545
|
+
let observedReadOnlyToolCalls = 0;
|
|
1546
|
+
let observedUnsafeToolCalls = 0;
|
|
1547
|
+
let observedToolResultBytes = 0;
|
|
1548
|
+
let observedModelVisibleToolBytes = 0;
|
|
1549
|
+
try {
|
|
1550
|
+
for await (const event of (0, framework_1.query)({
|
|
1551
|
+
messages,
|
|
1552
|
+
tools: turnTools,
|
|
1553
|
+
toolExecutor,
|
|
1554
|
+
llm: this.runtime.llm,
|
|
1555
|
+
streamCallbacks,
|
|
1556
|
+
costTracker: snapshot.costTracker,
|
|
1557
|
+
permissionMode: snapshot.permissionMode,
|
|
1558
|
+
toolConfirmation: this.runtime.config.toolConfirmation,
|
|
1559
|
+
confirmToolUse: this.controllerOptions.confirmToolUse,
|
|
1560
|
+
toolContext: {
|
|
1561
|
+
cwd: this.runtime.cwd,
|
|
1562
|
+
config: {
|
|
1563
|
+
name: this.runtime.config.name,
|
|
1564
|
+
mode: this.runtime.config.mode,
|
|
1565
|
+
},
|
|
1566
|
+
sessionId,
|
|
1567
|
+
turnId,
|
|
1568
|
+
},
|
|
1569
|
+
abortSignal,
|
|
1570
|
+
harness,
|
|
1571
|
+
input,
|
|
1572
|
+
loopBudget,
|
|
1573
|
+
onContextUsage: usage => {
|
|
1574
|
+
this.runtime.store.setContextUsage(usage);
|
|
1575
|
+
},
|
|
1576
|
+
compactCoordinator: this.runtime.compactCoordinator,
|
|
1577
|
+
})) {
|
|
1578
|
+
switch (event.type) {
|
|
1579
|
+
case 'request_start':
|
|
1580
|
+
observedTurnsStarted = Math.max(observedTurnsStarted, event.turn);
|
|
1581
|
+
observedLlmRequests++;
|
|
1582
|
+
assistantStream.discardSegment();
|
|
1583
|
+
this.events.setStatus((0, agent_status_1.agentStepStatus)(event.turn));
|
|
1584
|
+
if (sessionId) {
|
|
1585
|
+
recordTraceEvent(this.events, sessionId, {
|
|
1586
|
+
turnId,
|
|
1587
|
+
type: 'request_start',
|
|
1588
|
+
model: event.model,
|
|
1589
|
+
turn: event.turn,
|
|
1590
|
+
});
|
|
1591
|
+
}
|
|
1592
|
+
break;
|
|
1593
|
+
case 'prompt_assembly':
|
|
1594
|
+
if (sessionId) {
|
|
1595
|
+
recordTraceEvent(this.events, sessionId, {
|
|
1596
|
+
turnId,
|
|
1597
|
+
type: 'prompt_assembly',
|
|
1598
|
+
promptModelId: event.modelId,
|
|
1599
|
+
promptEstimatedTokens: event.estimatedTokens,
|
|
1600
|
+
promptBudgetTokens: event.budgetTokens,
|
|
1601
|
+
promptCoreTokens: event.coreTokens,
|
|
1602
|
+
promptEvidenceBudgetTokens: event.evidenceBudgetTokens,
|
|
1603
|
+
promptRecentTurnBudgetTokens: event.recentTurnBudgetTokens,
|
|
1604
|
+
promptSections: event.sections,
|
|
1605
|
+
promptIncludedEvidence: event.includedEvidence,
|
|
1606
|
+
promptOmittedEvidence: event.omittedEvidence,
|
|
1607
|
+
promptIncludedEvidenceCount: event.includedEvidenceCount,
|
|
1608
|
+
promptOmittedEvidenceCount: event.omittedEvidenceCount,
|
|
1609
|
+
});
|
|
1610
|
+
}
|
|
1611
|
+
break;
|
|
1612
|
+
case 'assistant_tool_calls':
|
|
1613
|
+
assistantStream.ensureMessage(event.content || '');
|
|
1614
|
+
assistantStream.closeSegment();
|
|
1615
|
+
this.events.setStatus((0, agent_status_1.runningToolsStatus)(event.toolCalls.length));
|
|
1616
|
+
{
|
|
1617
|
+
const batchReadOnlyCount = event.toolCalls.filter(tc => {
|
|
1618
|
+
const def = skillResolution.tools.find(t => t.name === tc.function.name);
|
|
1619
|
+
const args = parseToolCallArgsForRuntime(tc);
|
|
1620
|
+
return args && def?.isReadOnly?.(args) === true;
|
|
1621
|
+
}).length;
|
|
1622
|
+
const suggestion = (0, agent_status_1.batchingSuggestion)(batchReadOnlyCount);
|
|
1623
|
+
if (suggestion) {
|
|
1624
|
+
this.events.append({ role: 'status', content: suggestion });
|
|
1625
|
+
}
|
|
1626
|
+
}
|
|
1627
|
+
const checkpointId = checkpointSequence === 0 ? turnId : `${turnId}-checkpoint-${checkpointSequence + 1}`;
|
|
1628
|
+
const checkpointResult = createPreToolCheckpoint(this.events, sessionId, turnId, checkpointId, this.runtime.cwd, event.toolCalls);
|
|
1629
|
+
if (checkpointResult.created) {
|
|
1630
|
+
checkpointIds.push(checkpointId);
|
|
1631
|
+
checkpointSequence++;
|
|
1632
|
+
}
|
|
1633
|
+
if (checkpointResult.created && checkpointResult.risky) {
|
|
1634
|
+
this.events.append({
|
|
1635
|
+
role: 'status',
|
|
1636
|
+
title: 'checkpoint',
|
|
1637
|
+
statusTone: 'warning',
|
|
1638
|
+
content: `Risky edit: ${checkpointResult.targetCount} files in one turn. Checkpoint ${checkpointId} created for rollback (/checkpoints restore ${checkpointId}).`,
|
|
1639
|
+
});
|
|
1640
|
+
}
|
|
1641
|
+
else if (checkpointResult.risky) {
|
|
1642
|
+
this.events.append({
|
|
1643
|
+
role: 'status',
|
|
1644
|
+
title: 'checkpoint',
|
|
1645
|
+
statusTone: 'warning',
|
|
1646
|
+
content: `Risky edit: ${checkpointResult.targetCount} files in one turn, but checkpoint creation failed. Restore any pre-existing checkpoint manually or revert via git.`,
|
|
1647
|
+
});
|
|
1648
|
+
}
|
|
1649
|
+
if (sessionId) {
|
|
1650
|
+
recordTraceEvent(this.events, sessionId, {
|
|
1651
|
+
turnId,
|
|
1652
|
+
type: 'assistant_tool_calls',
|
|
1653
|
+
toolCallCount: event.toolCalls.length,
|
|
1654
|
+
contentBytes: byteLength(event.content || ''),
|
|
1655
|
+
});
|
|
1656
|
+
}
|
|
1657
|
+
sessionMessagesToRecord.push({
|
|
1658
|
+
role: 'assistant',
|
|
1659
|
+
content: event.content || '',
|
|
1660
|
+
timestamp: Date.now(),
|
|
1661
|
+
tool_calls: event.toolCalls,
|
|
1662
|
+
});
|
|
1663
|
+
break;
|
|
1664
|
+
case 'tool_call':
|
|
1665
|
+
observedToolCalls++;
|
|
1666
|
+
{
|
|
1667
|
+
const toolDefinition = skillResolution.tools.find(tool => tool.name === event.name);
|
|
1668
|
+
if (toolDefinition?.isReadOnly?.(event.args) === true) {
|
|
1669
|
+
observedReadOnlyToolCalls++;
|
|
1670
|
+
}
|
|
1671
|
+
else {
|
|
1672
|
+
observedUnsafeToolCalls++;
|
|
1673
|
+
}
|
|
1674
|
+
}
|
|
1675
|
+
assistantStream.closeSegment();
|
|
1676
|
+
toolEvents.start(event);
|
|
1677
|
+
if (sessionId) {
|
|
1678
|
+
const traceArgs = buildTraceArgsDetails(this.runtime.cwd, event.name, event.args);
|
|
1679
|
+
recordTraceEvent(this.events, sessionId, {
|
|
1680
|
+
turnId,
|
|
1681
|
+
type: 'tool_call',
|
|
1682
|
+
name: event.name,
|
|
1683
|
+
callId: event.callId,
|
|
1684
|
+
...traceArgs,
|
|
1685
|
+
batchCount: event.batchCount,
|
|
1686
|
+
batchIndex: event.batchIndex,
|
|
1687
|
+
});
|
|
1688
|
+
}
|
|
1689
|
+
break;
|
|
1690
|
+
case 'permission_decision':
|
|
1691
|
+
if (sessionId) {
|
|
1692
|
+
recordTraceEvent(this.events, sessionId, {
|
|
1693
|
+
turnId,
|
|
1694
|
+
type: 'permission_decision',
|
|
1695
|
+
name: event.name,
|
|
1696
|
+
callId: event.callId,
|
|
1697
|
+
argsSummary: compactToolArgs(event.args),
|
|
1698
|
+
permissionBehavior: event.decision.behavior,
|
|
1699
|
+
permissionApproved: event.decision.approved,
|
|
1700
|
+
permissionSource: event.decision.source,
|
|
1701
|
+
permissionReason: event.decision.reason
|
|
1702
|
+
? compactMiddle(event.decision.reason, 240)
|
|
1703
|
+
: undefined,
|
|
1704
|
+
permissionDuration: event.decision.duration,
|
|
1705
|
+
batchCount: event.batchCount,
|
|
1706
|
+
batchIndex: event.batchIndex,
|
|
1707
|
+
});
|
|
1708
|
+
}
|
|
1709
|
+
break;
|
|
1710
|
+
case 'tool_result': {
|
|
1711
|
+
observedToolResultBytes += event.outputBytes ?? byteLength(event.result);
|
|
1712
|
+
observedModelVisibleToolBytes += byteLength(event.modelVisibleResult);
|
|
1713
|
+
toolEvents.finish(event);
|
|
1714
|
+
if (sessionId) {
|
|
1715
|
+
recordTraceEvent(this.events, sessionId, {
|
|
1716
|
+
turnId,
|
|
1717
|
+
type: 'tool_result',
|
|
1718
|
+
name: event.name,
|
|
1719
|
+
callId: event.callId,
|
|
1720
|
+
argsSummary: compactToolArgs(event.args),
|
|
1721
|
+
success: event.success,
|
|
1722
|
+
duration: event.duration,
|
|
1723
|
+
outputBytes: event.outputBytes,
|
|
1724
|
+
modelVisibleBytes: byteLength(event.modelVisibleResult),
|
|
1725
|
+
artifactId: event.artifactRef?.id,
|
|
1726
|
+
error: event.error ? compactMiddle(event.error, 240) : undefined,
|
|
1727
|
+
batchCount: event.batchCount,
|
|
1728
|
+
batchIndex: event.batchIndex,
|
|
1729
|
+
});
|
|
1730
|
+
}
|
|
1731
|
+
const verificationResult = (0, verification_profile_1.collectVerificationCommandResult)({
|
|
1732
|
+
toolName: event.name,
|
|
1733
|
+
args: event.args,
|
|
1734
|
+
success: event.success,
|
|
1735
|
+
outputBytes: event.outputBytes,
|
|
1736
|
+
error: event.error,
|
|
1737
|
+
});
|
|
1738
|
+
if (verificationResult) {
|
|
1739
|
+
verificationResults.push(verificationResult);
|
|
1740
|
+
appendVerificationResultTrace(this.events, sessionId, turnId, verificationResult);
|
|
1741
|
+
}
|
|
1742
|
+
sessionMessagesToRecord.push({
|
|
1743
|
+
role: 'tool',
|
|
1744
|
+
content: event.result,
|
|
1745
|
+
modelVisibleContent: event.modelVisibleResult,
|
|
1746
|
+
timestamp: Date.now(),
|
|
1747
|
+
toolCallId: event.callId,
|
|
1748
|
+
});
|
|
1749
|
+
break;
|
|
1750
|
+
}
|
|
1751
|
+
case 'strategy_exhausted':
|
|
1752
|
+
this.events.append({ role: 'status', content: event.suggestion });
|
|
1753
|
+
if (sessionId) {
|
|
1754
|
+
recordTraceEvent(this.events, sessionId, {
|
|
1755
|
+
turnId,
|
|
1756
|
+
type: 'strategy_exhausted',
|
|
1757
|
+
note: compactMiddle(event.suggestion, 240),
|
|
1758
|
+
});
|
|
1759
|
+
}
|
|
1760
|
+
break;
|
|
1761
|
+
case 'message':
|
|
1762
|
+
finalContent = event.content;
|
|
1763
|
+
assistantStream.ensureMessage(event.content);
|
|
1764
|
+
if (sessionId) {
|
|
1765
|
+
recordTraceEvent(this.events, sessionId, {
|
|
1766
|
+
turnId,
|
|
1767
|
+
type: 'message',
|
|
1768
|
+
contentBytes: byteLength(event.content),
|
|
1769
|
+
});
|
|
1770
|
+
}
|
|
1771
|
+
if (event.content) {
|
|
1772
|
+
sessionMessagesToRecord.push({
|
|
1773
|
+
role: 'assistant',
|
|
1774
|
+
content: event.content,
|
|
1775
|
+
timestamp: Date.now(),
|
|
1776
|
+
});
|
|
1777
|
+
}
|
|
1778
|
+
break;
|
|
1779
|
+
case 'complete':
|
|
1780
|
+
if (event.stats?.finishReason === 'blocked') {
|
|
1781
|
+
toolEvents.finalizePendingAsSkipped('permission denied');
|
|
1782
|
+
}
|
|
1783
|
+
if (event.content && !finalContent) {
|
|
1784
|
+
if (event.stats?.finishReason === 'budget_exceeded') {
|
|
1785
|
+
assistantStream.replaceMessage(event.content);
|
|
1786
|
+
}
|
|
1787
|
+
else {
|
|
1788
|
+
assistantStream.ensureMessage(event.content);
|
|
1789
|
+
}
|
|
1790
|
+
sessionMessagesToRecord.push({
|
|
1791
|
+
role: 'assistant',
|
|
1792
|
+
content: event.content,
|
|
1793
|
+
timestamp: Date.now(),
|
|
1794
|
+
});
|
|
1795
|
+
}
|
|
1796
|
+
finalContent = event.content;
|
|
1797
|
+
finalUsage = event.usage;
|
|
1798
|
+
finalModel = event.model;
|
|
1799
|
+
pendingCompact = event.compact;
|
|
1800
|
+
if (event.stats) {
|
|
1801
|
+
pendingCompleteStats = event.stats;
|
|
1802
|
+
recordProviderTraceEvents(this.events, sessionId, turnId, event.stats);
|
|
1803
|
+
pendingCompleteTrace = {
|
|
1804
|
+
turnId,
|
|
1805
|
+
type: 'complete',
|
|
1806
|
+
model: event.model,
|
|
1807
|
+
contentBytes: byteLength(event.content || ''),
|
|
1808
|
+
finishReason: event.stats.finishReason,
|
|
1809
|
+
llmRequests: event.stats.llmRequests,
|
|
1810
|
+
toolCalls: event.stats.toolCalls,
|
|
1811
|
+
readOnlyToolCalls: event.stats.readOnlyToolCalls,
|
|
1812
|
+
unsafeToolCalls: event.stats.unsafeToolCalls,
|
|
1813
|
+
loopBudgetSource: event.stats.loopBudgetSource,
|
|
1814
|
+
loopBudgetBaseProfile: event.stats.loopBudgetBaseProfile,
|
|
1815
|
+
loopBudgetMaxLlmRequests: event.stats.loopBudgetMaxLlmRequests,
|
|
1816
|
+
loopBudgetMaxToolCalls: event.stats.loopBudgetMaxToolCalls,
|
|
1817
|
+
loopBudgetMaxReadOnlyFragmentation: event.stats.loopBudgetMaxReadOnlyFragmentation,
|
|
1818
|
+
loopBudgetMaxModelVisibleBytes: event.stats.loopBudgetMaxModelVisibleBytes,
|
|
1819
|
+
loopBudgetConfigOverride: event.stats.loopBudgetConfigOverride,
|
|
1820
|
+
budgetExceededReason: event.stats.budgetExceededReason,
|
|
1821
|
+
continuationActions: event.stats.continuationActions,
|
|
1822
|
+
continuationHint: event.stats.continuationHint,
|
|
1823
|
+
localFastPathUsed: event.stats.localFastPathUsed,
|
|
1824
|
+
};
|
|
1825
|
+
}
|
|
1826
|
+
else {
|
|
1827
|
+
pendingCompleteTrace = {
|
|
1828
|
+
turnId,
|
|
1829
|
+
type: 'complete',
|
|
1830
|
+
model: event.model,
|
|
1831
|
+
contentBytes: byteLength(event.content || ''),
|
|
1832
|
+
};
|
|
1833
|
+
}
|
|
1834
|
+
break;
|
|
1835
|
+
}
|
|
1836
|
+
}
|
|
1837
|
+
const wasAborted = abortSignal?.aborted === true;
|
|
1838
|
+
if (wasAborted) {
|
|
1839
|
+
assistantStream.discardSegment();
|
|
1840
|
+
this.events.setStatus('Interrupted.');
|
|
1841
|
+
removeTrailingUserMessage(this.runtime);
|
|
1842
|
+
if (sessionId) {
|
|
1843
|
+
const { delta } = appendPostWorkspaceTrace(this.events, sessionId, turnId, this.runtime.cwd, preWorkspace, verificationResults);
|
|
1844
|
+
recordTraceEvent(this.events, sessionId, {
|
|
1845
|
+
turnId,
|
|
1846
|
+
type: 'aborted',
|
|
1847
|
+
note: 'aborted_after_query',
|
|
1848
|
+
});
|
|
1849
|
+
const recoveryNotice = workspaceDeltaHasTurnChanges(delta)
|
|
1850
|
+
? formatFailureRecoveryNotice(turnId, delta, checkpointIds)
|
|
1851
|
+
: undefined;
|
|
1852
|
+
if (recoveryNotice) {
|
|
1853
|
+
this.events.append({
|
|
1854
|
+
role: 'status',
|
|
1855
|
+
title: 'recovery',
|
|
1856
|
+
statusTone: 'warning',
|
|
1857
|
+
content: recoveryNotice,
|
|
1858
|
+
});
|
|
1859
|
+
}
|
|
1860
|
+
(0, session_storage_1.removeLastIncompleteAssistantMessage)(sessionId);
|
|
1861
|
+
}
|
|
1862
|
+
// Persist any accumulated session messages before returning,
|
|
1863
|
+
// so tool results from the interrupted turn are not lost.
|
|
1864
|
+
if (sessionId && sessionMessagesToRecord.length > 0) {
|
|
1865
|
+
(0, session_storage_1.appendSessionMessages)(sessionId, sessionMessagesToRecord);
|
|
1866
|
+
}
|
|
1867
|
+
return;
|
|
1868
|
+
}
|
|
1869
|
+
assistantStream.closeSegment();
|
|
1870
|
+
if (sessionId) {
|
|
1871
|
+
const { profile, summary } = appendPostWorkspaceTrace(this.events, sessionId, turnId, this.runtime.cwd, preWorkspace, verificationResults);
|
|
1872
|
+
if (profile.changedFiles.length > 0 && profile.required) {
|
|
1873
|
+
this.events.setStatus((0, agent_status_1.verifyingStatus)(profile.profile));
|
|
1874
|
+
this.controllerOptions.onVerificationStateChange?.('running');
|
|
1875
|
+
}
|
|
1876
|
+
if (shouldRecordVerificationLoopStats(profile, summary)) {
|
|
1877
|
+
const stats = pendingCompleteStats ?? this.runtime.store.getSnapshot().lastLoopStats;
|
|
1878
|
+
if (stats) {
|
|
1879
|
+
pendingCompleteStats = withVerificationLoopStats(stats, summary);
|
|
1880
|
+
}
|
|
1881
|
+
}
|
|
1882
|
+
if ((0, verification_profile_1.shouldGateCompletion)(summary)) {
|
|
1883
|
+
this.events.setStatus((0, agent_status_1.verificationGateStatus)(summary.skippedReason ?? 'verification checks not run'));
|
|
1884
|
+
this.controllerOptions.onVerificationStateChange?.('gated');
|
|
1885
|
+
const notice = (0, verification_profile_1.formatVerificationGateNotice)(summary);
|
|
1886
|
+
this.events.append({
|
|
1887
|
+
role: 'status',
|
|
1888
|
+
title: 'verification',
|
|
1889
|
+
statusTone: 'warning',
|
|
1890
|
+
content: notice,
|
|
1891
|
+
});
|
|
1892
|
+
finalContent = finalContent ? `${finalContent}\n\n${notice}` : notice;
|
|
1893
|
+
appendAssistantNotice(sessionMessagesToRecord, notice);
|
|
1894
|
+
if (pendingCompleteTrace) {
|
|
1895
|
+
pendingCompleteTrace.finishReason = 'completion_gate';
|
|
1896
|
+
pendingCompleteTrace.contentBytes = byteLength(finalContent);
|
|
1897
|
+
pendingCompleteTrace.note = 'verification_incomplete';
|
|
1898
|
+
}
|
|
1899
|
+
const stats = pendingCompleteStats ?? this.runtime.store.getSnapshot().lastLoopStats;
|
|
1900
|
+
if (stats) {
|
|
1901
|
+
pendingCompleteStats = {
|
|
1902
|
+
...withVerificationLoopStats(stats, summary),
|
|
1903
|
+
finishReason: 'completion_gate',
|
|
1904
|
+
};
|
|
1905
|
+
}
|
|
1906
|
+
}
|
|
1907
|
+
else if (profile.changedFiles.length > 0 && profile.required) {
|
|
1908
|
+
this.controllerOptions.onVerificationStateChange?.('passed');
|
|
1909
|
+
}
|
|
1910
|
+
}
|
|
1911
|
+
if (pendingCompleteStats?.finishReason === 'budget_exceeded') {
|
|
1912
|
+
const stats = pendingCompleteStats;
|
|
1913
|
+
const lines = ['Loop budget reached — stopping this turn.'];
|
|
1914
|
+
if (stats.budgetExceededReason) {
|
|
1915
|
+
lines.push(`Reason: ${stats.budgetExceededReason}`);
|
|
1916
|
+
}
|
|
1917
|
+
const progressParts = [];
|
|
1918
|
+
if (typeof stats.loopBudgetMaxLlmRequests === 'number') {
|
|
1919
|
+
progressParts.push(`${stats.llmRequests ?? 0}/${stats.loopBudgetMaxLlmRequests} LLM requests`);
|
|
1920
|
+
}
|
|
1921
|
+
if (typeof stats.loopBudgetMaxToolCalls === 'number') {
|
|
1922
|
+
progressParts.push(`${stats.toolCalls ?? 0}/${stats.loopBudgetMaxToolCalls} tool calls`);
|
|
1923
|
+
}
|
|
1924
|
+
if (progressParts.length) {
|
|
1925
|
+
lines.push(`Progress: ${progressParts.join(', ')}`);
|
|
1926
|
+
}
|
|
1927
|
+
if (stats.continuationActions?.length) {
|
|
1928
|
+
lines.push(`Next: ${stats.continuationActions.join('; ')}`);
|
|
1929
|
+
}
|
|
1930
|
+
else if (stats.continuationHint) {
|
|
1931
|
+
lines.push(`Next: ${stats.continuationHint}`);
|
|
1932
|
+
}
|
|
1933
|
+
const notice = lines.join('\n');
|
|
1934
|
+
this.events.append({
|
|
1935
|
+
role: 'status',
|
|
1936
|
+
title: 'budget',
|
|
1937
|
+
statusTone: 'warning',
|
|
1938
|
+
content: notice,
|
|
1939
|
+
});
|
|
1940
|
+
finalContent = finalContent ? `${finalContent}\n\n${notice}` : notice;
|
|
1941
|
+
appendAssistantNotice(sessionMessagesToRecord, notice);
|
|
1942
|
+
}
|
|
1943
|
+
if (pendingCompleteStats) {
|
|
1944
|
+
this.setLoopStats(this.foldSubagentUsage(pendingCompleteStats, subagentBundle));
|
|
1945
|
+
}
|
|
1946
|
+
if (finalContent) {
|
|
1947
|
+
this.runtime.store.addMessage({ role: 'assistant', content: finalContent });
|
|
1948
|
+
}
|
|
1949
|
+
if (sessionId && sessionMessagesToRecord.length > 0) {
|
|
1950
|
+
(0, session_storage_1.appendSessionMessages)(sessionId, sessionMessagesToRecord);
|
|
1951
|
+
}
|
|
1952
|
+
if (pendingCompact) {
|
|
1953
|
+
try {
|
|
1954
|
+
let committedCheckpointId;
|
|
1955
|
+
if (sessionId) {
|
|
1956
|
+
const sourceMessageCount = (0, session_storage_1.readSessionMessages)(sessionId).length;
|
|
1957
|
+
const checkpoint = (0, session_storage_1.commitSessionCompactCheckpoint)({
|
|
1958
|
+
sessionId,
|
|
1959
|
+
mode: pendingCompact.mode,
|
|
1960
|
+
modelId: finalModel || this.runtime.llm.getModel(),
|
|
1961
|
+
sourceMessageCount,
|
|
1962
|
+
transcriptStartMessageIndex: Math.max(0, sourceMessageCount - 20),
|
|
1963
|
+
modelHistory: pendingCompact.modelHistory,
|
|
1964
|
+
summary: pendingCompact.summary,
|
|
1965
|
+
beforeUsage: pendingCompact.before,
|
|
1966
|
+
afterUsage: pendingCompact.after,
|
|
1967
|
+
});
|
|
1968
|
+
committedCheckpointId = checkpoint.checkpointId;
|
|
1969
|
+
this.runtime.store.setState({ conversationHistory: checkpoint.modelHistory });
|
|
1970
|
+
}
|
|
1971
|
+
else {
|
|
1972
|
+
this.runtime.store.setState({
|
|
1973
|
+
conversationHistory: pendingCompact.modelHistory.filter(message => message.role !== 'system'),
|
|
1974
|
+
});
|
|
1975
|
+
}
|
|
1976
|
+
this.runtime.store.setContextUsage(pendingCompact.after);
|
|
1977
|
+
if (sessionId) {
|
|
1978
|
+
recordTraceEvent(this.events, sessionId, {
|
|
1979
|
+
turnId,
|
|
1980
|
+
type: 'compact_completed',
|
|
1981
|
+
checkpointId: committedCheckpointId,
|
|
1982
|
+
model: finalModel || this.runtime.llm.getModel(),
|
|
1983
|
+
note: pendingCompact.mode,
|
|
1984
|
+
});
|
|
1985
|
+
}
|
|
1986
|
+
this.events.append({
|
|
1987
|
+
role: 'status',
|
|
1988
|
+
title: 'auto-compact',
|
|
1989
|
+
statusTone: 'neutral',
|
|
1990
|
+
content: `Context reached ${pendingCompact.before.percent}% of the safe input budget. Agent core committed a ${pendingCompact.mode} compact checkpoint; current context is ${pendingCompact.after.percent}%.`,
|
|
1991
|
+
});
|
|
1992
|
+
}
|
|
1993
|
+
catch (error) {
|
|
1994
|
+
if (sessionId) {
|
|
1995
|
+
recordTraceEvent(this.events, sessionId, {
|
|
1996
|
+
turnId,
|
|
1997
|
+
type: 'compact_failed',
|
|
1998
|
+
model: finalModel || this.runtime.llm.getModel(),
|
|
1999
|
+
error: compactTraceError(error),
|
|
2000
|
+
note: pendingCompact.mode,
|
|
2001
|
+
});
|
|
2002
|
+
}
|
|
2003
|
+
this.events.append({
|
|
2004
|
+
role: 'error',
|
|
2005
|
+
title: 'compact-failed',
|
|
2006
|
+
content: `Compact checkpoint failed; the previous model context remains active. ${error instanceof Error ? error.message : String(error)}`,
|
|
2007
|
+
errorLayer: 'runtime',
|
|
2008
|
+
});
|
|
2009
|
+
}
|
|
2010
|
+
}
|
|
2011
|
+
if (finalUsage) {
|
|
2012
|
+
// Fold subagent token usage into /cost accounting.
|
|
2013
|
+
if (subagentBundle) {
|
|
2014
|
+
const subUsage = subagentBundle.getAggregateUsage();
|
|
2015
|
+
finalUsage = {
|
|
2016
|
+
promptTokens: finalUsage.promptTokens + subUsage.promptTokens,
|
|
2017
|
+
completionTokens: finalUsage.completionTokens + subUsage.completionTokens,
|
|
2018
|
+
};
|
|
2019
|
+
}
|
|
2020
|
+
this.runtime.store.setTokenUsage(finalUsage);
|
|
2021
|
+
}
|
|
2022
|
+
harness.ingestTurn({
|
|
2023
|
+
userInput: input,
|
|
2024
|
+
assistantContent: finalContent,
|
|
2025
|
+
sessionMessages: sessionMessagesToRecord,
|
|
2026
|
+
intent,
|
|
2027
|
+
});
|
|
2028
|
+
const harnessState = harness.toJSON();
|
|
2029
|
+
this.runtime.store.setState({ harnessState });
|
|
2030
|
+
emitHarnessDiagnostics(this.events, harnessState);
|
|
2031
|
+
if (sessionId) {
|
|
2032
|
+
if (pendingCompleteTrace) {
|
|
2033
|
+
recordTraceEvent(this.events, sessionId, pendingCompleteTrace);
|
|
2034
|
+
}
|
|
2035
|
+
(0, session_storage_1.updateSessionSkills)(sessionId, appliedSkillNames);
|
|
2036
|
+
(0, session_storage_1.updateSessionHarnessState)(sessionId, harnessState);
|
|
2037
|
+
const recordedMessages = (0, session_storage_1.readSessionMessages)(sessionId);
|
|
2038
|
+
if (recordedMessages.length > 0) {
|
|
2039
|
+
(0, session_storage_1.updateSessionSummary)(sessionId, recordedMessages);
|
|
2040
|
+
}
|
|
2041
|
+
}
|
|
2042
|
+
this.events.setStatus(finalModel ? `Completed with ${finalModel}` : 'Completed');
|
|
2043
|
+
}
|
|
2044
|
+
catch (error) {
|
|
2045
|
+
// v0.2.25: Provider retry exhausted is a recoverable turn failure.
|
|
2046
|
+
if (error instanceof Error && error.name === 'ProviderRetryExhaustedError') {
|
|
2047
|
+
const diag = error.diagnostics;
|
|
2048
|
+
const attempts = diag?.attempts?.length ?? '?';
|
|
2049
|
+
const kind = diag?.attempts?.[diag.attempts.length - 1]?.failureKind ?? 'unknown';
|
|
2050
|
+
this.events.setStatus(`Provider unavailable (${kind}, ${attempts} attempts). Retry exhausted — ready for next input.`);
|
|
2051
|
+
this.events.append({
|
|
2052
|
+
role: 'error',
|
|
2053
|
+
title: 'provider',
|
|
2054
|
+
content: `Provider retry exhausted after ${attempts} attempts (${kind}). The turn was not completed. You can try again or wait for the provider to recover.`,
|
|
2055
|
+
errorLayer: 'provider',
|
|
2056
|
+
});
|
|
2057
|
+
// v0.2.25: If a goal is active, pause it on provider retry exhaustion
|
|
2058
|
+
// so it doesn't auto-continue and burn retries.
|
|
2059
|
+
try {
|
|
2060
|
+
const gc = this.goalCoordinator;
|
|
2061
|
+
if (gc?.goal?.status === 'active') {
|
|
2062
|
+
gc.deferContinuation();
|
|
2063
|
+
}
|
|
2064
|
+
}
|
|
2065
|
+
catch { /* best effort */ }
|
|
2066
|
+
return;
|
|
2067
|
+
}
|
|
2068
|
+
if (isAbortError(error, abortSignal)) {
|
|
2069
|
+
assistantStream.discardSegment();
|
|
2070
|
+
this.events.setStatus('Interrupted.');
|
|
2071
|
+
removeTrailingUserMessage(this.runtime);
|
|
2072
|
+
if (sessionId) {
|
|
2073
|
+
const { delta } = appendPostWorkspaceTrace(this.events, sessionId, turnId, this.runtime.cwd, preWorkspace, verificationResults);
|
|
2074
|
+
recordTraceEvent(this.events, sessionId, {
|
|
2075
|
+
turnId,
|
|
2076
|
+
type: 'aborted',
|
|
2077
|
+
note: 'abort_error',
|
|
2078
|
+
});
|
|
2079
|
+
const recoveryNotice = workspaceDeltaHasTurnChanges(delta)
|
|
2080
|
+
? formatFailureRecoveryNotice(turnId, delta, checkpointIds)
|
|
2081
|
+
: undefined;
|
|
2082
|
+
if (recoveryNotice) {
|
|
2083
|
+
this.events.append({
|
|
2084
|
+
role: 'status',
|
|
2085
|
+
title: 'recovery',
|
|
2086
|
+
statusTone: 'warning',
|
|
2087
|
+
content: recoveryNotice,
|
|
2088
|
+
});
|
|
2089
|
+
}
|
|
2090
|
+
(0, session_storage_1.removeLastIncompleteAssistantMessage)(sessionId);
|
|
2091
|
+
}
|
|
2092
|
+
return;
|
|
2093
|
+
}
|
|
2094
|
+
assistantStream.discardSegment();
|
|
2095
|
+
this.events.append({
|
|
2096
|
+
role: 'error',
|
|
2097
|
+
content: formatChatError(error),
|
|
2098
|
+
errorLayer: errorLayerForChatError(error),
|
|
2099
|
+
});
|
|
2100
|
+
this.events.setStatus('Turn failed. Ready for the next input.');
|
|
2101
|
+
const failedStats = error instanceof framework_1.QueryLoopError
|
|
2102
|
+
? error.stats
|
|
2103
|
+
: (0, framework_1.createFailedLoopStats)({
|
|
2104
|
+
loopBudget,
|
|
2105
|
+
diagnostics: observedLlmRequests > 0 ? getLastRequestDiagnostics(this.runtime.llm) : undefined,
|
|
2106
|
+
turnsStarted: observedTurnsStarted,
|
|
2107
|
+
llmRequests: observedLlmRequests,
|
|
2108
|
+
toolCalls: observedToolCalls,
|
|
2109
|
+
readOnlyToolCalls: observedReadOnlyToolCalls,
|
|
2110
|
+
unsafeToolCalls: observedUnsafeToolCalls,
|
|
2111
|
+
toolResultBytes: observedToolResultBytes,
|
|
2112
|
+
modelVisibleToolBytes: observedModelVisibleToolBytes,
|
|
2113
|
+
});
|
|
2114
|
+
this.setLoopStats(failedStats);
|
|
2115
|
+
if (sessionId) {
|
|
2116
|
+
recordProviderTraceEvents(this.events, sessionId, turnId, failedStats);
|
|
2117
|
+
const { delta } = appendPostWorkspaceTrace(this.events, sessionId, turnId, this.runtime.cwd, preWorkspace, verificationResults);
|
|
2118
|
+
const recoveryNotice = workspaceDeltaHasTurnChanges(delta)
|
|
2119
|
+
? formatFailureRecoveryNotice(turnId, delta, checkpointIds)
|
|
2120
|
+
: undefined;
|
|
2121
|
+
if (recoveryNotice) {
|
|
2122
|
+
this.events.append({
|
|
2123
|
+
role: 'status',
|
|
2124
|
+
title: 'recovery',
|
|
2125
|
+
statusTone: 'warning',
|
|
2126
|
+
content: recoveryNotice,
|
|
2127
|
+
});
|
|
2128
|
+
}
|
|
2129
|
+
recordTraceEvent(this.events, sessionId, {
|
|
2130
|
+
turnId,
|
|
2131
|
+
type: 'error',
|
|
2132
|
+
error: compactTraceError(error),
|
|
2133
|
+
note: recoveryNotice,
|
|
2134
|
+
});
|
|
2135
|
+
recordTraceEvent(this.events, sessionId, {
|
|
2136
|
+
turnId,
|
|
2137
|
+
type: 'complete',
|
|
2138
|
+
model: failedStats.providerFinalModel ?? this.runtime.llm.getModel(),
|
|
2139
|
+
contentBytes: 0,
|
|
2140
|
+
finishReason: failedStats.finishReason,
|
|
2141
|
+
llmRequests: failedStats.llmRequests,
|
|
2142
|
+
toolCalls: failedStats.toolCalls,
|
|
2143
|
+
readOnlyToolCalls: failedStats.readOnlyToolCalls,
|
|
2144
|
+
unsafeToolCalls: failedStats.unsafeToolCalls,
|
|
2145
|
+
loopBudgetSource: failedStats.loopBudgetSource,
|
|
2146
|
+
loopBudgetBaseProfile: failedStats.loopBudgetBaseProfile,
|
|
2147
|
+
loopBudgetMaxLlmRequests: failedStats.loopBudgetMaxLlmRequests,
|
|
2148
|
+
loopBudgetMaxToolCalls: failedStats.loopBudgetMaxToolCalls,
|
|
2149
|
+
loopBudgetMaxReadOnlyFragmentation: failedStats.loopBudgetMaxReadOnlyFragmentation,
|
|
2150
|
+
loopBudgetMaxModelVisibleBytes: failedStats.loopBudgetMaxModelVisibleBytes,
|
|
2151
|
+
loopBudgetConfigOverride: failedStats.loopBudgetConfigOverride,
|
|
2152
|
+
localFastPathUsed: failedStats.localFastPathUsed,
|
|
2153
|
+
});
|
|
2154
|
+
(0, session_storage_1.removeLastIncompleteAssistantMessage)(sessionId);
|
|
2155
|
+
}
|
|
2156
|
+
const history = this.runtime.store.getSnapshot().conversationHistory;
|
|
2157
|
+
if (history.length > 0) {
|
|
2158
|
+
this.runtime.store.setState({ conversationHistory: history.slice(0, -1) });
|
|
2159
|
+
}
|
|
2160
|
+
}
|
|
2161
|
+
}
|
|
2162
|
+
}
|
|
2163
|
+
exports.AgentChatController = AgentChatController;
|
|
2164
|
+
exports.InkChatController = AgentChatController;
|
|
2165
|
+
function loadSessionIntoRuntime(runtime, sessionId) {
|
|
2166
|
+
const history = (0, session_storage_1.loadSessionHistory)(sessionId);
|
|
2167
|
+
runtime.store.setState({ conversationHistory: history });
|
|
2168
|
+
runtime.store.setState({
|
|
2169
|
+
harnessState: (0, session_storage_1.loadSessionHarnessState)(sessionId) ?? (0, session_storage_1.loadSessionMeta)(sessionId)?.harnessState,
|
|
2170
|
+
});
|
|
2171
|
+
return `Restored ${history.length} messages`;
|
|
2172
|
+
}
|
|
2173
|
+
function closeSession(runtime) {
|
|
2174
|
+
const session = runtime.getSession();
|
|
2175
|
+
if (!session)
|
|
2176
|
+
return;
|
|
2177
|
+
const messages = (0, session_storage_1.readSessionMessages)(session.id);
|
|
2178
|
+
if (messages.length > 0) {
|
|
2179
|
+
(0, session_storage_1.updateSessionSummary)(session.id, messages);
|
|
2180
|
+
}
|
|
2181
|
+
(0, session_storage_1.endSession)(session.id);
|
|
2182
|
+
}
|
|
2183
|
+
//# sourceMappingURL=chat-controller.js.map
|