@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,3281 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* orion code - Command Registry
|
|
4
|
+
*
|
|
5
|
+
* 注册所有 slash 命令,提供查找和列表功能。
|
|
6
|
+
*/
|
|
7
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
8
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
9
|
+
};
|
|
10
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
+
exports.getCommandCategoryLabel = getCommandCategoryLabel;
|
|
12
|
+
exports.sortCommands = sortCommands;
|
|
13
|
+
exports.getCommands = getCommands;
|
|
14
|
+
exports.getVisibleCommands = getVisibleCommands;
|
|
15
|
+
exports.findCommand = findCommand;
|
|
16
|
+
exports.getCommandNames = getCommandNames;
|
|
17
|
+
exports.executeChat = handleChat;
|
|
18
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
19
|
+
const types_1 = require("./types");
|
|
20
|
+
const ui_view_model_1 = require("../runtime/ui-view-model");
|
|
21
|
+
const task_manager_1 = require("../services/task-manager");
|
|
22
|
+
const agent_runner_1 = require("../services/agent-runner");
|
|
23
|
+
const config_1 = require("../services/config");
|
|
24
|
+
const box_1 = require("../ui/box");
|
|
25
|
+
const stream_markdown_1 = require("../ui/stream-markdown");
|
|
26
|
+
const progress_1 = require("../ui/progress");
|
|
27
|
+
const format_1 = require("../services/format");
|
|
28
|
+
const framework_1 = require("../framework");
|
|
29
|
+
const tools_1 = require("../tools");
|
|
30
|
+
const mcp_1 = require("../tools/mcp");
|
|
31
|
+
const session_storage_1 = require("../services/session-storage");
|
|
32
|
+
const session_index_1 = require("../services/session-index");
|
|
33
|
+
const coordinator_1 = require("../runtime/goals/coordinator");
|
|
34
|
+
const auto_compact_1 = require("../services/compact/auto-compact");
|
|
35
|
+
const coordinator_2 = require("../services/compact/coordinator");
|
|
36
|
+
const harness_1 = require("../harness");
|
|
37
|
+
const skills_1 = require("../skills");
|
|
38
|
+
const file_context_1 = require("../services/file-context");
|
|
39
|
+
const project_instructions_1 = require("../services/project-instructions");
|
|
40
|
+
const prompt_context_1 = require("../services/prompt-context");
|
|
41
|
+
const doctor_1 = require("../services/doctor");
|
|
42
|
+
const model_context_1 = require("../services/model-context");
|
|
43
|
+
const token_estimate_1 = require("../utils/token-estimate");
|
|
44
|
+
const model_catalog_1 = require("../services/model-catalog");
|
|
45
|
+
const workspace_diff_1 = require("../services/workspace-diff");
|
|
46
|
+
const commit_plan_1 = require("../services/commit-plan");
|
|
47
|
+
const tool_artifacts_1 = require("../core/tool-artifacts");
|
|
48
|
+
const checkpoint_1 = require("../core/checkpoint");
|
|
49
|
+
const storage_maintenance_1 = require("../services/storage-maintenance");
|
|
50
|
+
const agent_status_1 = require("../runtime/agent-status");
|
|
51
|
+
const loop_budget_1 = require("../runtime/loop-budget");
|
|
52
|
+
const usage_state_1 = require("../services/usage-state");
|
|
53
|
+
const command_1 = require("../migration/command");
|
|
54
|
+
// ============================================================================
|
|
55
|
+
// 颜色常量
|
|
56
|
+
// ============================================================================
|
|
57
|
+
const BRAND = chalk_1.default.hex('#FF6B35');
|
|
58
|
+
const ACCENT = chalk_1.default.hex('#00D4AA');
|
|
59
|
+
const DIM = chalk_1.default.dim;
|
|
60
|
+
const ERROR = chalk_1.default.red;
|
|
61
|
+
const WARN = chalk_1.default.yellow;
|
|
62
|
+
const SUCCESS = chalk_1.default.green;
|
|
63
|
+
const HEADER = chalk_1.default.cyan.bold;
|
|
64
|
+
const CATEGORY_ORDER = [
|
|
65
|
+
'workflow',
|
|
66
|
+
'session',
|
|
67
|
+
'context',
|
|
68
|
+
'tools',
|
|
69
|
+
'model',
|
|
70
|
+
'system',
|
|
71
|
+
'diagnostics',
|
|
72
|
+
'legacy',
|
|
73
|
+
];
|
|
74
|
+
function commandUICapabilities(ctx) {
|
|
75
|
+
return (0, ui_view_model_1.createStatusSnapshot)({
|
|
76
|
+
renderer: ctx.uiRenderer ?? ctx.config.ui?.renderer ?? 'terminal',
|
|
77
|
+
capabilities: ctx.uiCapabilities,
|
|
78
|
+
}).renderer.capabilities;
|
|
79
|
+
}
|
|
80
|
+
function formatTokenCount(tokens) {
|
|
81
|
+
if (tokens >= 1000000)
|
|
82
|
+
return `${(tokens / 1000000).toFixed(1)}M`;
|
|
83
|
+
if (tokens >= 1000)
|
|
84
|
+
return `${Math.round(tokens / 1000)}K`;
|
|
85
|
+
return String(tokens);
|
|
86
|
+
}
|
|
87
|
+
function formatThreshold(value) {
|
|
88
|
+
return `${Math.round(value * 100)}%`;
|
|
89
|
+
}
|
|
90
|
+
function formatDurationMs(ms) {
|
|
91
|
+
if (ms >= 1000)
|
|
92
|
+
return `${(ms / 1000).toFixed(1)}s`;
|
|
93
|
+
return `${Math.round(ms)}ms`;
|
|
94
|
+
}
|
|
95
|
+
function formatRendererStatus(ctx) {
|
|
96
|
+
const snapshot = (0, ui_view_model_1.createStatusSnapshot)({
|
|
97
|
+
renderer: ctx.uiRenderer ?? ctx.config.ui?.renderer ?? 'terminal',
|
|
98
|
+
capabilities: ctx.uiCapabilities,
|
|
99
|
+
});
|
|
100
|
+
const status = snapshot.renderer.status === 'deprecated'
|
|
101
|
+
? WARN('deprecated')
|
|
102
|
+
: snapshot.renderer.status === 'beta' || (0, config_1.isBetaUIRenderer)(snapshot.renderer.name)
|
|
103
|
+
? WARN('beta')
|
|
104
|
+
: snapshot.renderer.status === 'stable'
|
|
105
|
+
? SUCCESS('stable')
|
|
106
|
+
: snapshot.renderer.status === 'non-interactive'
|
|
107
|
+
? DIM('non-interactive')
|
|
108
|
+
: DIM('custom');
|
|
109
|
+
return `${BRAND(snapshot.renderer.name)} ${status} ${DIM(snapshot.renderer.capabilityLabels.join(', '))}`;
|
|
110
|
+
}
|
|
111
|
+
function formatModelAliasHelp() {
|
|
112
|
+
return Object.keys((0, model_catalog_1.getModelCatalogAliases)()).sort().join(', ');
|
|
113
|
+
}
|
|
114
|
+
function formatLoopBudgetSource(stats) {
|
|
115
|
+
const source = stats.loopBudgetSource ?? 'unknown';
|
|
116
|
+
if (source === 'config' && stats.loopBudgetBaseProfile) {
|
|
117
|
+
return `config over ${stats.loopBudgetBaseProfile}`;
|
|
118
|
+
}
|
|
119
|
+
return source;
|
|
120
|
+
}
|
|
121
|
+
function formatLoopStatsLines(stats, detail = false) {
|
|
122
|
+
const lines = [
|
|
123
|
+
`Finish ${stats.finishReason}`,
|
|
124
|
+
`Requests ${stats.llmRequests} LLM / ${stats.turnsStarted} turns`,
|
|
125
|
+
`Tools ${stats.toolCalls} total (${stats.readOnlyToolCalls} read-only, ${stats.unsafeToolCalls} unsafe)`,
|
|
126
|
+
`Tool bytes ${(0, format_1.formatBytes)(stats.modelVisibleToolBytes)} model-visible / ${(0, format_1.formatBytes)(stats.toolResultBytes)} total`,
|
|
127
|
+
];
|
|
128
|
+
if (stats.summarizedBytes > 0) {
|
|
129
|
+
lines.push(`Saved ${(0, format_1.formatBytes)(stats.summarizedBytes)} from model context`);
|
|
130
|
+
}
|
|
131
|
+
if (stats.compactTrigger) {
|
|
132
|
+
lines.push(`Compact ${stats.compactTrigger}`);
|
|
133
|
+
}
|
|
134
|
+
if (stats.localFastPathUsed) {
|
|
135
|
+
lines.push('Fast path yes');
|
|
136
|
+
}
|
|
137
|
+
if (stats.budgetExceededReason) {
|
|
138
|
+
lines.push(`Budget ${stats.budgetExceededReason}`);
|
|
139
|
+
}
|
|
140
|
+
if (stats.continuationActions && stats.continuationActions.length > 0) {
|
|
141
|
+
lines.push(`Next ${stats.continuationActions.join(', ')}`);
|
|
142
|
+
}
|
|
143
|
+
if ((stats.providerRetryCount ?? 0) > 0) {
|
|
144
|
+
const retryParts = [
|
|
145
|
+
`${stats.providerRetryCount} retries`,
|
|
146
|
+
`delay ${formatDurationMs(stats.providerRetryDelayMs ?? 0)}`,
|
|
147
|
+
stats.providerLastRetryErrorType
|
|
148
|
+
? `last ${stats.providerLastRetryErrorType}${stats.providerLastRetryStatus ? `/${stats.providerLastRetryStatus}` : ''}`
|
|
149
|
+
: undefined,
|
|
150
|
+
].filter(Boolean);
|
|
151
|
+
lines.push(`Provider ${retryParts.join(', ')}`);
|
|
152
|
+
}
|
|
153
|
+
if ((stats.providerFallbackCount ?? 0) > 0 || stats.providerUsingFallback) {
|
|
154
|
+
const fallbackPath = stats.providerFallbackFromModel && stats.providerFallbackToModel
|
|
155
|
+
? `${stats.providerFallbackFromModel} -> ${stats.providerFallbackToModel}`
|
|
156
|
+
: stats.providerFinalModel
|
|
157
|
+
? `final ${stats.providerFinalModel}`
|
|
158
|
+
: 'active';
|
|
159
|
+
lines.push(`Fallback ${fallbackPath}`);
|
|
160
|
+
}
|
|
161
|
+
if (typeof stats.verificationClaimAllowed === 'boolean') {
|
|
162
|
+
const verificationParts = [
|
|
163
|
+
stats.verificationProfile ?? 'unknown',
|
|
164
|
+
`required=${stats.verificationRequired ? 'yes' : 'no'}`,
|
|
165
|
+
`passed=${stats.verificationPassedCommands?.length ?? 0}`,
|
|
166
|
+
`failed=${stats.verificationFailedCommands?.length ?? 0}`,
|
|
167
|
+
`missing=${stats.verificationMissingCommands?.length ?? 0}`,
|
|
168
|
+
`claim=${stats.verificationClaimAllowed ? 'yes' : 'no'}`,
|
|
169
|
+
];
|
|
170
|
+
lines.push(`Verify ${verificationParts.join(' ')}`);
|
|
171
|
+
}
|
|
172
|
+
if (typeof stats.loopBudgetMaxLlmRequests === 'number'
|
|
173
|
+
|| typeof stats.loopBudgetMaxToolCalls === 'number'
|
|
174
|
+
|| typeof stats.loopBudgetMaxModelVisibleBytes === 'number') {
|
|
175
|
+
const caps = [
|
|
176
|
+
typeof stats.loopBudgetMaxLlmRequests === 'number'
|
|
177
|
+
? `${stats.llmRequests}/${stats.loopBudgetMaxLlmRequests} LLM`
|
|
178
|
+
: undefined,
|
|
179
|
+
typeof stats.loopBudgetMaxToolCalls === 'number'
|
|
180
|
+
? `${stats.toolCalls}/${stats.loopBudgetMaxToolCalls} tools`
|
|
181
|
+
: undefined,
|
|
182
|
+
typeof stats.loopBudgetMaxModelVisibleBytes === 'number'
|
|
183
|
+
? `${(0, format_1.formatBytes)(stats.modelVisibleToolBytes)}/${(0, format_1.formatBytes)(stats.loopBudgetMaxModelVisibleBytes)} visible`
|
|
184
|
+
: undefined,
|
|
185
|
+
typeof stats.loopBudgetMaxReadOnlyFragmentation === 'number'
|
|
186
|
+
? `fragment ${stats.singleReadOnlyStreak}/${stats.loopBudgetMaxReadOnlyFragmentation}`
|
|
187
|
+
: undefined,
|
|
188
|
+
].filter(Boolean);
|
|
189
|
+
lines.push(`Budget cap ${caps.join(', ')} (${formatLoopBudgetSource(stats)})`);
|
|
190
|
+
}
|
|
191
|
+
if (stats.singleReadOnlyStreak > 0 || stats.batchReadSuggestionCount > 0) {
|
|
192
|
+
lines.push(`Read-only streak ${stats.singleReadOnlyStreak}, batch_read hints ${stats.batchReadSuggestionCount}`);
|
|
193
|
+
}
|
|
194
|
+
if (detail) {
|
|
195
|
+
lines.push(`Unsafe ${stats.unsafeToolCalls}`);
|
|
196
|
+
if (stats.providerRetryErrorTypes && stats.providerRetryErrorTypes.length > 0) {
|
|
197
|
+
lines.push(`Retry type ${stats.providerRetryErrorTypes.join(', ')}`);
|
|
198
|
+
}
|
|
199
|
+
if (stats.verificationFailedCommands && stats.verificationFailedCommands.length > 0) {
|
|
200
|
+
lines.push(`Failed ${stats.verificationFailedCommands.join(' && ')}`);
|
|
201
|
+
}
|
|
202
|
+
if (stats.verificationMissingCommands && stats.verificationMissingCommands.length > 0) {
|
|
203
|
+
lines.push(`Missing ${stats.verificationMissingCommands.join(' && ')}`);
|
|
204
|
+
}
|
|
205
|
+
if (stats.verificationSkippedReason) {
|
|
206
|
+
lines.push(`Verify why ${stats.verificationSkippedReason}`);
|
|
207
|
+
}
|
|
208
|
+
if (stats.continuationHint) {
|
|
209
|
+
lines.push(`Next why ${stats.continuationHint}`);
|
|
210
|
+
}
|
|
211
|
+
lines.push(`Budget hit ${stats.finishReason === 'budget_exceeded' ? 'yes' : 'no'}`);
|
|
212
|
+
}
|
|
213
|
+
return lines;
|
|
214
|
+
}
|
|
215
|
+
const CATEGORY_LABELS = {
|
|
216
|
+
workflow: 'Workflow',
|
|
217
|
+
session: 'Session',
|
|
218
|
+
context: 'Context',
|
|
219
|
+
tools: 'Tools',
|
|
220
|
+
model: 'Model',
|
|
221
|
+
system: 'System',
|
|
222
|
+
diagnostics: 'Diagnostics',
|
|
223
|
+
legacy: 'Legacy',
|
|
224
|
+
};
|
|
225
|
+
function commandCategory(command) {
|
|
226
|
+
return command.category ?? 'system';
|
|
227
|
+
}
|
|
228
|
+
function getCommandCategoryLabel(category) {
|
|
229
|
+
return CATEGORY_LABELS[category ?? 'system'];
|
|
230
|
+
}
|
|
231
|
+
function sortCommands(commands) {
|
|
232
|
+
return [...commands].sort((a, b) => {
|
|
233
|
+
const categoryDelta = CATEGORY_ORDER.indexOf(commandCategory(a)) - CATEGORY_ORDER.indexOf(commandCategory(b));
|
|
234
|
+
if (categoryDelta !== 0)
|
|
235
|
+
return categoryDelta;
|
|
236
|
+
const priorityDelta = (a.priority ?? 100) - (b.priority ?? 100);
|
|
237
|
+
if (priorityDelta !== 0)
|
|
238
|
+
return priorityDelta;
|
|
239
|
+
return a.name.localeCompare(b.name);
|
|
240
|
+
});
|
|
241
|
+
}
|
|
242
|
+
function isAbortError(error, abortSignal) {
|
|
243
|
+
if (abortSignal?.aborted)
|
|
244
|
+
return true;
|
|
245
|
+
if (error instanceof Error) {
|
|
246
|
+
return error.name === 'AbortError' || error.message.toLowerCase().includes('aborted');
|
|
247
|
+
}
|
|
248
|
+
return false;
|
|
249
|
+
}
|
|
250
|
+
// ============================================================================
|
|
251
|
+
// 工具参数摘要
|
|
252
|
+
// ============================================================================
|
|
253
|
+
// ============================================================================
|
|
254
|
+
// 命令实现
|
|
255
|
+
// ============================================================================
|
|
256
|
+
let taskManager = null;
|
|
257
|
+
function showHelp() {
|
|
258
|
+
console.log();
|
|
259
|
+
console.log(HEADER('Commands:'));
|
|
260
|
+
console.log();
|
|
261
|
+
const visible = getVisibleCommands();
|
|
262
|
+
for (const category of CATEGORY_ORDER) {
|
|
263
|
+
const items = visible.filter(cmd => commandCategory(cmd) === category);
|
|
264
|
+
if (items.length === 0)
|
|
265
|
+
continue;
|
|
266
|
+
console.log(DIM(getCommandCategoryLabel(category)));
|
|
267
|
+
for (const cmd of items) {
|
|
268
|
+
const aliases = cmd.aliases ? ` (${cmd.aliases.join(', ')})` : '';
|
|
269
|
+
const params = cmd.argumentHint || cmd.params?.map(p => `<${p.name}>`).join(' ') || '';
|
|
270
|
+
console.log(` ${ACCENT(`/${cmd.name}`)}${aliases} ${DIM(params)}`);
|
|
271
|
+
console.log(` ${DIM(cmd.description)}`);
|
|
272
|
+
}
|
|
273
|
+
console.log();
|
|
274
|
+
}
|
|
275
|
+
console.log(DIM('Type any text without / prefix to chat with the LLM.'));
|
|
276
|
+
console.log();
|
|
277
|
+
return { success: true };
|
|
278
|
+
}
|
|
279
|
+
function showStatus(ctx) {
|
|
280
|
+
console.log();
|
|
281
|
+
console.log(HEADER('System Status'));
|
|
282
|
+
console.log(DIM('─'.repeat(40)));
|
|
283
|
+
const brainStatus = ctx.runtime.brain.getStatus();
|
|
284
|
+
const memStatus = ctx.runtime.memory.getStatus();
|
|
285
|
+
const storeStats = ctx.runtime.store.getStats();
|
|
286
|
+
console.log(` Mode ${BRAND(ctx.config.mode)}`);
|
|
287
|
+
console.log(` Log level ${DIM(ctx.config.logLevel)}`);
|
|
288
|
+
const modelId = ctx.llm?.getModel() ?? snapshotCurrentModel(ctx);
|
|
289
|
+
const modelContext = (0, model_context_1.resolveModelContext)(modelId);
|
|
290
|
+
const compactStats = getCommandAutoCompact(ctx, modelId).getStats();
|
|
291
|
+
console.log(` Model ${BRAND(modelId)}`);
|
|
292
|
+
console.log(` Context ${DIM(`${formatTokenCount(modelContext.contextWindow)} tokens (${modelContext.source}${modelContext.source === 'fuzzy' ? `:${modelContext.matchedId}` : ''})`)}`);
|
|
293
|
+
console.log(` Compact ${compactStats.enabled ? SUCCESS('auto') : WARN('off')} ${DIM(`predict ${formatThreshold(compactStats.predictiveCompactThreshold)}, hard ${formatThreshold(compactStats.threshold)}, used ${compactStats.ctxPercent}%`)}`);
|
|
294
|
+
console.log(` Renderer ${formatRendererStatus(ctx)}`);
|
|
295
|
+
console.log();
|
|
296
|
+
console.log(` Agents ${SUCCESS(brainStatus.agents.length)} registered`);
|
|
297
|
+
console.log(` Tasks ${brainStatus.pendingTasks} pending (${brainStatus.strategy} strategy)`);
|
|
298
|
+
console.log();
|
|
299
|
+
console.log(` Memory (inline):`);
|
|
300
|
+
console.log(` Working ${memStatus.working} entries`);
|
|
301
|
+
console.log(` Short-term ${memStatus['short-term']} entries`);
|
|
302
|
+
console.log(` Long-term ${memStatus['long-term']} entries`);
|
|
303
|
+
console.log();
|
|
304
|
+
console.log(` Memory (store):`);
|
|
305
|
+
console.log(` Working ${storeStats.working} entries`);
|
|
306
|
+
console.log(` Short-term ${storeStats['short-term']} entries`);
|
|
307
|
+
console.log(` Long-term ${storeStats['long-term']} entries`);
|
|
308
|
+
(0, prompt_context_1.refreshProjectInstructions)(ctx.store, ctx.cwd);
|
|
309
|
+
const snapshot = ctx.store.getSnapshot();
|
|
310
|
+
const instructionFiles = (0, project_instructions_1.loadProjectInstructionFiles)(ctx.cwd);
|
|
311
|
+
console.log();
|
|
312
|
+
console.log(` Context:`);
|
|
313
|
+
console.log(` Project rules ${instructionFiles.length > 0 ? SUCCESS(`${instructionFiles.length} files`) : DIM('none')}`);
|
|
314
|
+
for (const file of instructionFiles.slice(0, 8)) {
|
|
315
|
+
console.log(` ${DIM(file.path)}${file.truncated ? ` ${WARN('(truncated)')}` : ''}`);
|
|
316
|
+
}
|
|
317
|
+
if (instructionFiles.length > 8) {
|
|
318
|
+
console.log(` ${DIM(`... ${instructionFiles.length - 8} more`)}`);
|
|
319
|
+
}
|
|
320
|
+
console.log(` Prompt rules ${snapshot.projectInstructionsContent ? SUCCESS(`${snapshot.projectInstructionsContent.length} chars`) : DIM('none')}`);
|
|
321
|
+
console.log(` Project memory ${snapshot.memoryContent ? SUCCESS(`${snapshot.memoryContent.length} chars`) : DIM('none')}`);
|
|
322
|
+
console.log(` Skills index ${snapshot.skillsContent ? SUCCESS(`${snapshot.skillsContent.length} chars`) : DIM('none')}`);
|
|
323
|
+
if (snapshot.lastLoopStats) {
|
|
324
|
+
const stats = snapshot.lastLoopStats;
|
|
325
|
+
console.log();
|
|
326
|
+
console.log(` Last loop:`);
|
|
327
|
+
for (const line of formatLoopStatsLines(stats)) {
|
|
328
|
+
console.log(` ${line}`);
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
const harnessState = snapshot.harnessState;
|
|
332
|
+
if (harnessState?.contract || harnessState?.capsule) {
|
|
333
|
+
console.log();
|
|
334
|
+
console.log(` Harness:`);
|
|
335
|
+
if (harnessState.contract) {
|
|
336
|
+
console.log(` Objective ${ACCENT(harnessState.contract.objective)}`);
|
|
337
|
+
}
|
|
338
|
+
console.log(` Ledger ${DIM(`${harnessState.ledger.length} entries`)}`);
|
|
339
|
+
if (harnessState.capsule) {
|
|
340
|
+
console.log(` Next ${DIM(harnessState.capsule.nextAction)}`);
|
|
341
|
+
const passed = harnessState.capsule.verification.passed.length;
|
|
342
|
+
const failed = harnessState.capsule.verification.failed.length;
|
|
343
|
+
console.log(` Verify ${SUCCESS(`${passed} passed`)} / ${failed > 0 ? ERROR(`${failed} failed`) : DIM('0 failed')}`);
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
console.log();
|
|
347
|
+
return { success: true };
|
|
348
|
+
}
|
|
349
|
+
function handleLoopStats(ctx) {
|
|
350
|
+
const stats = ctx.store.getSnapshot().lastLoopStats;
|
|
351
|
+
if (!stats) {
|
|
352
|
+
console.log('No agent-loop stats recorded yet.');
|
|
353
|
+
return { success: true };
|
|
354
|
+
}
|
|
355
|
+
console.log(HEADER('Agent Loop Stats'));
|
|
356
|
+
console.log();
|
|
357
|
+
for (const line of formatLoopStatsLines(stats, true)) {
|
|
358
|
+
console.log(` ${line}`);
|
|
359
|
+
}
|
|
360
|
+
console.log();
|
|
361
|
+
console.log(DIM('Use this to spot excessive LLM requests, fragmented read-only tool calls, and local fast-path hits.'));
|
|
362
|
+
return { success: true };
|
|
363
|
+
}
|
|
364
|
+
function formatTraceEventLine(event) {
|
|
365
|
+
const time = new Date(event.timestamp).toLocaleTimeString();
|
|
366
|
+
const prefix = `${DIM(time)} ${ACCENT(event.type)}`;
|
|
367
|
+
switch (event.type) {
|
|
368
|
+
case 'turn_start':
|
|
369
|
+
return `${prefix} input=${(0, format_1.formatBytes)(event.inputBytes ?? 0)}${event.localFastPathUsed ? ' fast-path' : ''}${event.note ? ` ${DIM(event.note)}` : ''}`;
|
|
370
|
+
case 'request_start':
|
|
371
|
+
return `${prefix} model=${event.model ?? 'unknown'} iteration=${event.turn ?? '?'}`;
|
|
372
|
+
case 'provider_retry': {
|
|
373
|
+
const parts = [
|
|
374
|
+
`count=${event.providerRetryCount ?? 0}`,
|
|
375
|
+
`delay=${formatDurationMs(event.providerRetryDelayMs ?? 0)}`,
|
|
376
|
+
event.providerLastRetryErrorType
|
|
377
|
+
? `last=${event.providerLastRetryErrorType}${event.providerLastRetryStatus ? `/${event.providerLastRetryStatus}` : ''}`
|
|
378
|
+
: '',
|
|
379
|
+
event.providerRetryErrorTypes?.length ? `types=${event.providerRetryErrorTypes.join(',')}` : '',
|
|
380
|
+
event.providerFinalModel ? `final=${event.providerFinalModel}` : '',
|
|
381
|
+
].filter(Boolean);
|
|
382
|
+
return `${prefix} ${parts.join(' ')}`;
|
|
383
|
+
}
|
|
384
|
+
case 'provider_fallback': {
|
|
385
|
+
const path = event.providerFallbackFromModel && event.providerFallbackToModel
|
|
386
|
+
? `${event.providerFallbackFromModel}->${event.providerFallbackToModel}`
|
|
387
|
+
: event.providerFinalModel ?? 'active';
|
|
388
|
+
const parts = [
|
|
389
|
+
`count=${event.providerFallbackCount ?? 0}`,
|
|
390
|
+
`path=${path}`,
|
|
391
|
+
`using=${event.providerUsingFallback ? 'yes' : 'no'}`,
|
|
392
|
+
];
|
|
393
|
+
return `${prefix} ${parts.join(' ')}`;
|
|
394
|
+
}
|
|
395
|
+
case 'prompt_assembly': {
|
|
396
|
+
const parts = [
|
|
397
|
+
`model=${event.promptModelId ?? 'unknown'}`,
|
|
398
|
+
`tokens=${event.promptEstimatedTokens ?? 0}/${event.promptBudgetTokens ?? 0}`,
|
|
399
|
+
`core=${event.promptCoreTokens ?? 0}`,
|
|
400
|
+
`evidenceBudget=${event.promptEvidenceBudgetTokens ?? 0}`,
|
|
401
|
+
`recentBudget=${event.promptRecentTurnBudgetTokens ?? 0}`,
|
|
402
|
+
`included=${event.promptIncludedEvidenceCount ?? 0}`,
|
|
403
|
+
`omitted=${event.promptOmittedEvidenceCount ?? 0}`,
|
|
404
|
+
];
|
|
405
|
+
const sections = event.promptSections?.length
|
|
406
|
+
? ` sections=${event.promptSections.join(',')}`
|
|
407
|
+
: '';
|
|
408
|
+
const evidence = event.promptIncludedEvidence?.length
|
|
409
|
+
? ` evidence=${event.promptIncludedEvidence.slice(0, 6).join(', ')}${event.promptIncludedEvidence.length > 6 ? ', ...' : ''}`
|
|
410
|
+
: '';
|
|
411
|
+
return `${prefix} ${parts.join(' ')}${sections ? DIM(sections) : ''}${evidence ? ` ${DIM(evidence)}` : ''}`;
|
|
412
|
+
}
|
|
413
|
+
case 'assistant_tool_calls':
|
|
414
|
+
return `${prefix} calls=${event.toolCallCount ?? 0} assistant=${(0, format_1.formatBytes)(event.contentBytes ?? 0)}`;
|
|
415
|
+
case 'checkpoint': {
|
|
416
|
+
const files = event.checkpointFiles?.length
|
|
417
|
+
? ` files=${event.checkpointFiles.slice(0, 6).join(', ')}${event.checkpointFiles.length > 6 ? ', ...' : ''}`
|
|
418
|
+
: '';
|
|
419
|
+
const targets = event.workspaceFiles?.length && !files
|
|
420
|
+
? ` targets=${event.workspaceFiles.slice(0, 6).join(', ')}${event.workspaceFiles.length > 6 ? ', ...' : ''}`
|
|
421
|
+
: '';
|
|
422
|
+
return `${prefix} id=${event.checkpointId ?? 'unknown'} saved=${event.checkpointFileCount ?? 0}${files}${targets}${event.note ? ` ${DIM(event.note)}` : ''}`;
|
|
423
|
+
}
|
|
424
|
+
case 'tool_call':
|
|
425
|
+
return `${prefix} ${event.name ?? 'tool'}${event.argsSummary ? ` ${DIM(event.argsSummary)}` : ''}${event.argsArtifactId ? ` ${DIM(`args=/artifacts show ${event.argsArtifactId} --full${event.argsBytes ? ` (${(0, format_1.formatBytes)(event.argsBytes)})` : ''}`)}` : ''}${event.callId ? ` ${DIM(event.callId)}` : ''}`;
|
|
426
|
+
case 'permission_decision': {
|
|
427
|
+
const status = event.permissionApproved ? SUCCESS('approved') : ERROR('denied');
|
|
428
|
+
const parts = [
|
|
429
|
+
`source=${event.permissionSource ?? 'unknown'}`,
|
|
430
|
+
`behavior=${event.permissionBehavior ?? 'unknown'}`,
|
|
431
|
+
];
|
|
432
|
+
if (typeof event.permissionDuration === 'number') {
|
|
433
|
+
parts.push(`${event.permissionDuration}ms`);
|
|
434
|
+
}
|
|
435
|
+
return `${prefix} ${status} ${event.name ?? 'tool'} ${DIM(parts.join(' '))}${event.permissionReason ? ` ${DIM(event.permissionReason)}` : ''}`;
|
|
436
|
+
}
|
|
437
|
+
case 'tool_result': {
|
|
438
|
+
const status = event.success === false ? ERROR('error') : SUCCESS('ok');
|
|
439
|
+
const bytes = [
|
|
440
|
+
`output=${(0, format_1.formatBytes)(event.outputBytes ?? 0)}`,
|
|
441
|
+
`model=${(0, format_1.formatBytes)(event.modelVisibleBytes ?? 0)}`,
|
|
442
|
+
];
|
|
443
|
+
if (event.artifactId)
|
|
444
|
+
bytes.push(`artifact=${event.artifactId}`);
|
|
445
|
+
return `${prefix} ${status} ${event.name ?? 'tool'} ${DIM(`${event.duration ?? 0}ms`)} ${DIM(bytes.join(' '))}${event.error ? ` ${ERROR(event.error)}` : ''}`;
|
|
446
|
+
}
|
|
447
|
+
case 'message':
|
|
448
|
+
return `${prefix} assistant=${(0, format_1.formatBytes)(event.contentBytes ?? 0)}`;
|
|
449
|
+
case 'strategy_exhausted':
|
|
450
|
+
return `${prefix}${event.note ? ` ${WARN(event.note)}` : ''}`;
|
|
451
|
+
case 'complete': {
|
|
452
|
+
const stats = [
|
|
453
|
+
`finish=${event.finishReason ?? 'unknown'}`,
|
|
454
|
+
`llm=${typeof event.llmRequests === 'number' ? event.llmRequests : 'unknown'}`,
|
|
455
|
+
`tools=${typeof event.toolCalls === 'number' ? event.toolCalls : 'unknown'}`,
|
|
456
|
+
];
|
|
457
|
+
if (event.loopBudgetSource
|
|
458
|
+
|| typeof event.loopBudgetMaxLlmRequests === 'number'
|
|
459
|
+
|| typeof event.loopBudgetMaxToolCalls === 'number'
|
|
460
|
+
|| typeof event.loopBudgetMaxModelVisibleBytes === 'number') {
|
|
461
|
+
const source = event.loopBudgetSource === 'config' && event.loopBudgetBaseProfile
|
|
462
|
+
? `config/${event.loopBudgetBaseProfile}`
|
|
463
|
+
: event.loopBudgetSource ?? 'unknown';
|
|
464
|
+
const caps = [
|
|
465
|
+
typeof event.loopBudgetMaxLlmRequests === 'number'
|
|
466
|
+
? `${typeof event.llmRequests === 'number' ? event.llmRequests : '?'}/${event.loopBudgetMaxLlmRequests}llm`
|
|
467
|
+
: undefined,
|
|
468
|
+
typeof event.loopBudgetMaxToolCalls === 'number'
|
|
469
|
+
? `${typeof event.toolCalls === 'number' ? event.toolCalls : '?'}/${event.loopBudgetMaxToolCalls}tools`
|
|
470
|
+
: undefined,
|
|
471
|
+
typeof event.loopBudgetMaxModelVisibleBytes === 'number'
|
|
472
|
+
? `${(0, format_1.formatBytes)(event.loopBudgetMaxModelVisibleBytes)}visible`
|
|
473
|
+
: undefined,
|
|
474
|
+
typeof event.loopBudgetMaxReadOnlyFragmentation === 'number'
|
|
475
|
+
? `frag=${event.loopBudgetMaxReadOnlyFragmentation}`
|
|
476
|
+
: undefined,
|
|
477
|
+
event.loopBudgetConfigOverride ? 'override=yes' : undefined,
|
|
478
|
+
].filter(Boolean);
|
|
479
|
+
stats.push(`budgetProfile=${source}${caps.length ? `(${caps.join(',')})` : ''}`);
|
|
480
|
+
}
|
|
481
|
+
if (event.budgetExceededReason)
|
|
482
|
+
stats.push(`budget=${event.budgetExceededReason}`);
|
|
483
|
+
if (event.continuationActions?.length)
|
|
484
|
+
stats.push(`next=${event.continuationActions.join(',')}`);
|
|
485
|
+
if (event.continuationHint)
|
|
486
|
+
stats.push(`hint=${event.continuationHint}`);
|
|
487
|
+
if (event.localFastPathUsed)
|
|
488
|
+
stats.push('fast-path=yes');
|
|
489
|
+
return `${prefix} ${stats.join(' ')}`;
|
|
490
|
+
}
|
|
491
|
+
case 'local_fast_path':
|
|
492
|
+
return `${prefix} ${event.name ?? 'tool'}${event.argsSummary ? ` ${DIM(event.argsSummary)}` : ''}${event.argsArtifactId ? ` ${DIM(`args=/artifacts show ${event.argsArtifactId} --full${event.argsBytes ? ` (${(0, format_1.formatBytes)(event.argsBytes)})` : ''}`)}` : ''}${event.note ? ` ${DIM(event.note)}` : ''}`;
|
|
493
|
+
case 'workspace_snapshot': {
|
|
494
|
+
const state = event.workspaceGitAvailable === false
|
|
495
|
+
? WARN('not-git')
|
|
496
|
+
: event.workspaceDirty ? WARN('dirty') : SUCCESS('clean');
|
|
497
|
+
const files = event.workspaceFiles?.length
|
|
498
|
+
? ` files=${event.workspaceFiles.slice(0, 6).join(', ')}${event.workspaceFiles.length > 6 ? ', ...' : ''}`
|
|
499
|
+
: '';
|
|
500
|
+
return `${prefix} ${event.workspacePhase ?? 'unknown'} ${state} count=${event.workspaceFileCount ?? 0}${event.workspaceBranch ? ` branch=${event.workspaceBranch}` : ''}${files}${event.error ? ` ${ERROR(event.error)}` : ''}`;
|
|
501
|
+
}
|
|
502
|
+
case 'workspace_delta': {
|
|
503
|
+
const added = event.workspaceNewByTurn ?? [];
|
|
504
|
+
const changed = event.workspaceChangedByTurn ?? [];
|
|
505
|
+
const modifiedPreExisting = event.workspaceModifiedPreExistingByTurn ?? [];
|
|
506
|
+
const resolved = event.workspaceResolvedByTurn ?? [];
|
|
507
|
+
const parts = [
|
|
508
|
+
`after=${event.workspaceFileCount ?? 0}`,
|
|
509
|
+
`new=${added.length}`,
|
|
510
|
+
`changed=${changed.length}`,
|
|
511
|
+
`pre-existing-modified=${modifiedPreExisting.length}`,
|
|
512
|
+
`resolved=${resolved.length}`,
|
|
513
|
+
];
|
|
514
|
+
const details = [
|
|
515
|
+
added.length ? `new: ${added.slice(0, 6).join(', ')}${added.length > 6 ? ', ...' : ''}` : '',
|
|
516
|
+
changed.length ? `changed: ${changed.slice(0, 6).join(', ')}${changed.length > 6 ? ', ...' : ''}` : '',
|
|
517
|
+
modifiedPreExisting.length ? `pre-existing modified: ${modifiedPreExisting.slice(0, 6).join(', ')}${modifiedPreExisting.length > 6 ? ', ...' : ''}` : '',
|
|
518
|
+
resolved.length ? `resolved: ${resolved.slice(0, 6).join(', ')}${resolved.length > 6 ? ', ...' : ''}` : '',
|
|
519
|
+
].filter(Boolean).join(' | ');
|
|
520
|
+
return `${prefix} ${parts.join(' ')}${details ? ` ${DIM(details)}` : ''}${event.note ? ` ${DIM(event.note)}` : ''}`;
|
|
521
|
+
}
|
|
522
|
+
case 'verification_profile': {
|
|
523
|
+
const commands = event.verificationCommands ?? [];
|
|
524
|
+
const files = event.verificationChangedFiles ?? [];
|
|
525
|
+
const details = [
|
|
526
|
+
`profile=${event.verificationProfile ?? 'unknown'}`,
|
|
527
|
+
`required=${event.verificationRequired === false ? 'no' : 'yes'}`,
|
|
528
|
+
`commands=${commands.length}`,
|
|
529
|
+
`files=${files.length}`,
|
|
530
|
+
];
|
|
531
|
+
if (event.verificationRisky) {
|
|
532
|
+
details.push(`risk=${WARN('high')}(${files.length} files)`);
|
|
533
|
+
}
|
|
534
|
+
const commandPreview = commands.length
|
|
535
|
+
? ` cmds: ${commands.slice(0, 4).join(' && ')}${commands.length > 4 ? ' && ...' : ''}`
|
|
536
|
+
: '';
|
|
537
|
+
return `${prefix} ${details.join(' ')}${commandPreview ? ` ${DIM(commandPreview)}` : ''}${event.note ? ` ${DIM(event.note)}` : ''}`;
|
|
538
|
+
}
|
|
539
|
+
case 'verification_result': {
|
|
540
|
+
const status = event.verificationPassed === true ? SUCCESS('passed') : ERROR('failed');
|
|
541
|
+
const command = event.verificationCommand ?? 'unknown';
|
|
542
|
+
return `${prefix} ${status} ${command}${typeof event.outputBytes === 'number' ? ` ${DIM((0, format_1.formatBytes)(event.outputBytes))}` : ''}${event.error ? ` ${ERROR(event.error)}` : ''}`;
|
|
543
|
+
}
|
|
544
|
+
case 'verification_summary': {
|
|
545
|
+
const passed = event.verificationPassedCommands?.length ?? 0;
|
|
546
|
+
const failed = event.verificationFailedCommands?.length ?? 0;
|
|
547
|
+
const missing = event.verificationMissingCommands?.length ?? 0;
|
|
548
|
+
const parts = [
|
|
549
|
+
`profile=${event.verificationProfile ?? 'unknown'}`,
|
|
550
|
+
`required=${event.verificationRequired === false ? 'no' : 'yes'}`,
|
|
551
|
+
`passed=${passed}`,
|
|
552
|
+
`failed=${failed}`,
|
|
553
|
+
`missing=${missing}`,
|
|
554
|
+
`claimAllowed=${event.verificationClaimAllowed ? 'yes' : 'no'}`,
|
|
555
|
+
];
|
|
556
|
+
const missingPreview = missing > 0
|
|
557
|
+
? ` missing: ${(event.verificationMissingCommands ?? []).slice(0, 4).join(' && ')}${missing > 4 ? ' && ...' : ''}`
|
|
558
|
+
: '';
|
|
559
|
+
return `${prefix} ${parts.join(' ')}${missingPreview ? ` ${DIM(missingPreview)}` : ''}${event.note ? ` ${DIM(event.note)}` : ''}`;
|
|
560
|
+
}
|
|
561
|
+
case 'aborted':
|
|
562
|
+
return `${prefix}${event.note ? ` ${WARN(event.note)}` : ''}`;
|
|
563
|
+
case 'error':
|
|
564
|
+
return `${prefix} ${ERROR(event.error ?? 'unknown error')}`;
|
|
565
|
+
default:
|
|
566
|
+
return prefix;
|
|
567
|
+
}
|
|
568
|
+
}
|
|
569
|
+
function handleTrace(ctx, args = '') {
|
|
570
|
+
const session = ctx.getSession?.() ?? (ctx.sessionId ? (0, session_storage_1.loadSessionMeta)(ctx.sessionId) : null);
|
|
571
|
+
if (!session) {
|
|
572
|
+
console.log(ERROR('No active session.'));
|
|
573
|
+
console.log(DIM('Use /resume <session-id> first, or start a chat turn to create a session.'));
|
|
574
|
+
return { success: false };
|
|
575
|
+
}
|
|
576
|
+
const events = (0, session_storage_1.readSessionTraceEvents)(session.id);
|
|
577
|
+
if (events.length === 0) {
|
|
578
|
+
console.log(DIM(`No trace events recorded for session ${session.id.slice(0, 8)} yet.`));
|
|
579
|
+
return { success: true };
|
|
580
|
+
}
|
|
581
|
+
const ref = args.trim();
|
|
582
|
+
const requestedTurnId = ref && ref !== 'latest' ? ref : events[events.length - 1].turnId;
|
|
583
|
+
const turnEvents = events.filter(event => event.turnId === requestedTurnId);
|
|
584
|
+
if (turnEvents.length === 0) {
|
|
585
|
+
const recentTurnIds = [...new Set(events.map(event => event.turnId))].slice(-8).reverse();
|
|
586
|
+
console.log(ERROR(`Trace turn not found: ${requestedTurnId}`));
|
|
587
|
+
console.log(DIM(`Recent turns: ${recentTurnIds.join(', ')}`));
|
|
588
|
+
return { success: false };
|
|
589
|
+
}
|
|
590
|
+
console.log(HEADER(`Trace ${requestedTurnId}`));
|
|
591
|
+
console.log(DIM(`Session ${session.id} Events ${turnEvents.length}`));
|
|
592
|
+
console.log(DIM('─'.repeat(40)));
|
|
593
|
+
for (const event of turnEvents) {
|
|
594
|
+
console.log(` ${formatTraceEventLine(event)}`);
|
|
595
|
+
}
|
|
596
|
+
console.log();
|
|
597
|
+
console.log(DIM('Trace stores metadata only; full transcript and tool output stay in session/artifacts.'));
|
|
598
|
+
return { success: true };
|
|
599
|
+
}
|
|
600
|
+
function latestToolTrace(events) {
|
|
601
|
+
for (let index = events.length - 1; index >= 0; index--) {
|
|
602
|
+
const event = events[index];
|
|
603
|
+
if (event.type !== 'tool_result' && event.type !== 'tool_call')
|
|
604
|
+
continue;
|
|
605
|
+
const callId = event.callId;
|
|
606
|
+
const result = event.type === 'tool_result' ? event : undefined;
|
|
607
|
+
const call = event.type === 'tool_call'
|
|
608
|
+
? event
|
|
609
|
+
: callId
|
|
610
|
+
? events.slice(0, index).reverse().find(candidate => candidate.type === 'tool_call' && candidate.callId === callId)
|
|
611
|
+
: undefined;
|
|
612
|
+
return { call, result };
|
|
613
|
+
}
|
|
614
|
+
return null;
|
|
615
|
+
}
|
|
616
|
+
/** Find tool trace by 1-based sequence number across all tool events. */
|
|
617
|
+
function toolTraceBySeq(events, seq) {
|
|
618
|
+
let counter = 0;
|
|
619
|
+
const toolEvents = new Map();
|
|
620
|
+
for (const event of events) {
|
|
621
|
+
if (event.type !== 'tool_call' && event.type !== 'tool_result')
|
|
622
|
+
continue;
|
|
623
|
+
if (!event.callId)
|
|
624
|
+
continue;
|
|
625
|
+
const entry = toolEvents.get(event.callId) ?? {};
|
|
626
|
+
if (event.type === 'tool_call') {
|
|
627
|
+
counter++;
|
|
628
|
+
entry.call = event;
|
|
629
|
+
}
|
|
630
|
+
else {
|
|
631
|
+
if (!entry.call)
|
|
632
|
+
counter++;
|
|
633
|
+
entry.result = event;
|
|
634
|
+
}
|
|
635
|
+
toolEvents.set(event.callId, entry);
|
|
636
|
+
if (counter === seq) {
|
|
637
|
+
return toolEvents.get(event.callId) ?? null;
|
|
638
|
+
}
|
|
639
|
+
}
|
|
640
|
+
return null;
|
|
641
|
+
}
|
|
642
|
+
/** Find tool trace by callId prefix. */
|
|
643
|
+
function toolTraceByCallId(events, callIdPrefix) {
|
|
644
|
+
let call;
|
|
645
|
+
let result;
|
|
646
|
+
for (const event of events) {
|
|
647
|
+
if (event.type !== 'tool_call' && event.type !== 'tool_result')
|
|
648
|
+
continue;
|
|
649
|
+
if (!event.callId?.startsWith(callIdPrefix))
|
|
650
|
+
continue;
|
|
651
|
+
if (event.type === 'tool_call')
|
|
652
|
+
call = event;
|
|
653
|
+
else
|
|
654
|
+
result = event;
|
|
655
|
+
}
|
|
656
|
+
if (!call && !result)
|
|
657
|
+
return null;
|
|
658
|
+
return { call, result };
|
|
659
|
+
}
|
|
660
|
+
/** Collect all tool trace pairs ordered by appearance (1-based sequence). */
|
|
661
|
+
function collectToolTracePairs(events) {
|
|
662
|
+
const pairs = [];
|
|
663
|
+
const seen = new Map();
|
|
664
|
+
let counter = 0;
|
|
665
|
+
for (const event of events) {
|
|
666
|
+
if (event.type !== 'tool_call' && event.type !== 'tool_result')
|
|
667
|
+
continue;
|
|
668
|
+
if (!event.callId)
|
|
669
|
+
continue;
|
|
670
|
+
let entry = seen.get(event.callId);
|
|
671
|
+
if (!entry) {
|
|
672
|
+
counter++;
|
|
673
|
+
entry = { seq: counter };
|
|
674
|
+
seen.set(event.callId, entry);
|
|
675
|
+
pairs.push(entry);
|
|
676
|
+
}
|
|
677
|
+
if (event.type === 'tool_call')
|
|
678
|
+
entry.call = event;
|
|
679
|
+
else
|
|
680
|
+
entry.result = event;
|
|
681
|
+
}
|
|
682
|
+
return pairs;
|
|
683
|
+
}
|
|
684
|
+
function parseLastToolArgs(args = '') {
|
|
685
|
+
const parts = args.trim().split(/\s+/).filter(Boolean);
|
|
686
|
+
const ref = parts.length > 0 && !parts[0].startsWith('--') ? parts[0] : undefined;
|
|
687
|
+
return {
|
|
688
|
+
full: parts.includes('--full'),
|
|
689
|
+
preview: !parts.includes('--no-preview'),
|
|
690
|
+
ref,
|
|
691
|
+
};
|
|
692
|
+
}
|
|
693
|
+
function printLastToolArtifactPreview(projectPath, label, artifactId, full) {
|
|
694
|
+
if (!artifactId)
|
|
695
|
+
return;
|
|
696
|
+
const artifact = (0, tool_artifacts_1.findArtifact)(projectPath, artifactId);
|
|
697
|
+
if (!artifact) {
|
|
698
|
+
console.log(` ${label} preview ${DIM(`artifact not found or ambiguous: ${artifactId}`)}`);
|
|
699
|
+
return;
|
|
700
|
+
}
|
|
701
|
+
const content = (0, tool_artifacts_1.retrieveArtifact)(artifact.path);
|
|
702
|
+
if (content == null) {
|
|
703
|
+
console.log(` ${label} preview ${DIM(`artifact cannot be read: ${artifact.id}`)}`);
|
|
704
|
+
return;
|
|
705
|
+
}
|
|
706
|
+
const redacted = (0, session_storage_1.redactTraceText)(content);
|
|
707
|
+
const maxPreviewBytes = 4 * 1024;
|
|
708
|
+
const shouldTruncate = !full && Buffer.byteLength(redacted, 'utf8') > maxPreviewBytes;
|
|
709
|
+
const preview = shouldTruncate
|
|
710
|
+
? Buffer.from(redacted, 'utf8').subarray(0, maxPreviewBytes).toString('utf8')
|
|
711
|
+
: redacted;
|
|
712
|
+
console.log(` ${label} preview`);
|
|
713
|
+
console.log(` ${DIM('─'.repeat(40))}`);
|
|
714
|
+
for (const line of preview.split('\n')) {
|
|
715
|
+
console.log(` ${line}`);
|
|
716
|
+
}
|
|
717
|
+
if (shouldTruncate) {
|
|
718
|
+
console.log(` ${DIM(`... preview truncated at ${(0, format_1.formatBytes)(maxPreviewBytes)}. Use /last-tool --full or /artifacts show ${artifact.id} --full.`)}`);
|
|
719
|
+
}
|
|
720
|
+
}
|
|
721
|
+
function lastToolInputLabel(toolName) {
|
|
722
|
+
return toolName === 'exec_command' ? 'Command' : 'Args';
|
|
723
|
+
}
|
|
724
|
+
function lastToolField(label) {
|
|
725
|
+
return label.padEnd(13, ' ');
|
|
726
|
+
}
|
|
727
|
+
function handleLastTool(ctx, args = '') {
|
|
728
|
+
const options = parseLastToolArgs(args);
|
|
729
|
+
const session = ctx.getSession?.() ?? (ctx.sessionId ? (0, session_storage_1.loadSessionMeta)(ctx.sessionId) : null);
|
|
730
|
+
if (!session) {
|
|
731
|
+
console.log(ERROR('No active session.'));
|
|
732
|
+
console.log(DIM('Use /resume <session-id> first, or start a chat turn to create a session.'));
|
|
733
|
+
return { success: false };
|
|
734
|
+
}
|
|
735
|
+
const events = (0, session_storage_1.readSessionTraceEvents)(session.id);
|
|
736
|
+
// Resolve reference: latest (default), #N, or callId prefix
|
|
737
|
+
let trace = null;
|
|
738
|
+
let listMode = false;
|
|
739
|
+
if (!options.ref || options.ref === 'latest') {
|
|
740
|
+
trace = latestToolTrace(events);
|
|
741
|
+
}
|
|
742
|
+
else if (/^#?\d+$/.test(options.ref)) {
|
|
743
|
+
const seq = parseInt(options.ref.replace('#', ''), 10);
|
|
744
|
+
trace = toolTraceBySeq(events, seq);
|
|
745
|
+
if (!trace) {
|
|
746
|
+
console.log(ERROR(`Tool #${seq} not found in session trace.`));
|
|
747
|
+
// Fall back to listing available tools
|
|
748
|
+
listMode = true;
|
|
749
|
+
}
|
|
750
|
+
}
|
|
751
|
+
else {
|
|
752
|
+
trace = toolTraceByCallId(events, options.ref);
|
|
753
|
+
if (!trace) {
|
|
754
|
+
console.log(ERROR(`Tool with callId prefix "${options.ref}" not found in session trace.`));
|
|
755
|
+
listMode = true;
|
|
756
|
+
}
|
|
757
|
+
}
|
|
758
|
+
if (listMode || !trace) {
|
|
759
|
+
const pairs = collectToolTracePairs(events);
|
|
760
|
+
if (pairs.length === 0) {
|
|
761
|
+
console.log(DIM(`No tool trace events recorded for session ${session.id.slice(0, 8)} yet.`));
|
|
762
|
+
return { success: true };
|
|
763
|
+
}
|
|
764
|
+
console.log(HEADER(`Tools (${pairs.length})`));
|
|
765
|
+
console.log(DIM('─'.repeat(60)));
|
|
766
|
+
for (const pair of pairs.slice(-30)) {
|
|
767
|
+
const source = pair.result ?? pair.call;
|
|
768
|
+
const name = source?.name ?? 'tool';
|
|
769
|
+
const status = pair.result
|
|
770
|
+
? (pair.result.success === false ? '✗' : '✓')
|
|
771
|
+
: '…';
|
|
772
|
+
const duration = typeof pair.result?.duration === 'number'
|
|
773
|
+
? ` (${formatDurationMs(pair.result.duration)})`
|
|
774
|
+
: '';
|
|
775
|
+
const argsShort = (pair.call?.argsSummary ?? '').slice(0, 40);
|
|
776
|
+
console.log(` #${pair.seq} ${status} ${ACCENT(name)}${duration} ${DIM(argsShort)}`);
|
|
777
|
+
}
|
|
778
|
+
console.log();
|
|
779
|
+
console.log(DIM('Use /last-tool #N or /last-tool <callId> for details.'));
|
|
780
|
+
return { success: true };
|
|
781
|
+
}
|
|
782
|
+
const call = trace.call;
|
|
783
|
+
const result = trace.result;
|
|
784
|
+
const source = result ?? call;
|
|
785
|
+
const argsSource = call ?? result;
|
|
786
|
+
const name = source?.name ?? 'tool';
|
|
787
|
+
const inputLabel = lastToolInputLabel(name);
|
|
788
|
+
const callId = source?.callId ?? call?.callId;
|
|
789
|
+
const status = result ? (result.success === false ? ERROR('error') : SUCCESS('ok')) : WARN('running');
|
|
790
|
+
// Resolve sequence number from the trace events
|
|
791
|
+
let seqLabel = '';
|
|
792
|
+
if (options.ref && /^#?\d+$/.test(options.ref)) {
|
|
793
|
+
seqLabel = `#${parseInt(options.ref.replace('#', ''), 10)} `;
|
|
794
|
+
}
|
|
795
|
+
else if (result || call) {
|
|
796
|
+
const allPairs = collectToolTracePairs(events);
|
|
797
|
+
const matchingPair = allPairs.find(p => p.call?.callId === callId || p.result?.callId === callId);
|
|
798
|
+
if (matchingPair)
|
|
799
|
+
seqLabel = `#${matchingPair.seq} `;
|
|
800
|
+
}
|
|
801
|
+
console.log(HEADER(`Last Tool ${seqLabel}`.trimEnd()));
|
|
802
|
+
console.log(DIM('─'.repeat(40)));
|
|
803
|
+
console.log(` Tool ${ACCENT(name)}`);
|
|
804
|
+
console.log(` Turn ${DIM(source?.turnId ?? 'unknown')}`);
|
|
805
|
+
if (callId)
|
|
806
|
+
console.log(` Call ${DIM(callId)}`);
|
|
807
|
+
console.log(` Status ${status}`);
|
|
808
|
+
if (typeof result?.duration === 'number') {
|
|
809
|
+
console.log(` Time ${DIM(formatDurationMs(result.duration))}`);
|
|
810
|
+
}
|
|
811
|
+
if (argsSource?.argsSummary) {
|
|
812
|
+
console.log(` ${lastToolField(inputLabel)}${DIM((0, session_storage_1.redactTraceText)(argsSource.argsSummary))}`);
|
|
813
|
+
}
|
|
814
|
+
if (argsSource?.argsArtifactId) {
|
|
815
|
+
const size = typeof argsSource.argsBytes === 'number' ? ` (${(0, format_1.formatBytes)(argsSource.argsBytes)})` : '';
|
|
816
|
+
console.log(` ${lastToolField(`${inputLabel} full`)}${DIM(`/artifacts show ${argsSource.argsArtifactId} --full${size}`)}`);
|
|
817
|
+
}
|
|
818
|
+
if (typeof result?.outputBytes === 'number') {
|
|
819
|
+
const modelVisible = typeof result.modelVisibleBytes === 'number'
|
|
820
|
+
? `, model-visible ${(0, format_1.formatBytes)(result.modelVisibleBytes)}`
|
|
821
|
+
: '';
|
|
822
|
+
console.log(` Output ${DIM(`${(0, format_1.formatBytes)(result.outputBytes)}${modelVisible}`)}`);
|
|
823
|
+
}
|
|
824
|
+
if (result?.artifactId) {
|
|
825
|
+
console.log(` Output full ${DIM(`/artifacts show ${result.artifactId} --full`)}`);
|
|
826
|
+
}
|
|
827
|
+
if (result?.error) {
|
|
828
|
+
console.log(` Error ${ERROR((0, session_storage_1.redactTraceText)(result.error))}`);
|
|
829
|
+
}
|
|
830
|
+
if (options.preview) {
|
|
831
|
+
const projectPath = session.projectPath || ctx.cwd;
|
|
832
|
+
printLastToolArtifactPreview(projectPath, inputLabel, argsSource?.argsArtifactId, options.full);
|
|
833
|
+
printLastToolArtifactPreview(projectPath, 'Output', result?.artifactId, options.full);
|
|
834
|
+
}
|
|
835
|
+
console.log();
|
|
836
|
+
console.log(DIM('Use /last-tool --full for redacted full previews, --no-preview for metadata only, or /trace latest for the ordered turn timeline.'));
|
|
837
|
+
return { success: true };
|
|
838
|
+
}
|
|
839
|
+
function formatDateTime(timestamp) {
|
|
840
|
+
return new Date(timestamp).toLocaleString();
|
|
841
|
+
}
|
|
842
|
+
function parseArtifactArgs(args) {
|
|
843
|
+
const parts = args.trim().split(/\s+/).filter(Boolean);
|
|
844
|
+
let full = false;
|
|
845
|
+
let limit = 20;
|
|
846
|
+
const positional = [];
|
|
847
|
+
for (let i = 0; i < parts.length; i++) {
|
|
848
|
+
const part = parts[i];
|
|
849
|
+
if (part === '--full') {
|
|
850
|
+
full = true;
|
|
851
|
+
continue;
|
|
852
|
+
}
|
|
853
|
+
if ((part === '--limit' || part === '-n') && parts[i + 1]) {
|
|
854
|
+
const parsed = Number(parts[i + 1]);
|
|
855
|
+
if (Number.isInteger(parsed) && parsed > 0) {
|
|
856
|
+
limit = Math.min(parsed, 200);
|
|
857
|
+
}
|
|
858
|
+
i++;
|
|
859
|
+
continue;
|
|
860
|
+
}
|
|
861
|
+
positional.push(part);
|
|
862
|
+
}
|
|
863
|
+
if (positional[0] === 'show' || positional[0] === 'cat') {
|
|
864
|
+
return { action: 'show', ref: positional[1], full, limit };
|
|
865
|
+
}
|
|
866
|
+
if (positional[0]) {
|
|
867
|
+
return { action: 'show', ref: positional[0], full, limit };
|
|
868
|
+
}
|
|
869
|
+
return { action: 'list', full, limit };
|
|
870
|
+
}
|
|
871
|
+
function printArtifactPreview(content, full) {
|
|
872
|
+
const maxPreviewBytes = 16 * 1024;
|
|
873
|
+
if (full || Buffer.byteLength(content, 'utf8') <= maxPreviewBytes) {
|
|
874
|
+
console.log(content);
|
|
875
|
+
return;
|
|
876
|
+
}
|
|
877
|
+
const preview = Buffer.from(content, 'utf8').subarray(0, maxPreviewBytes).toString('utf8');
|
|
878
|
+
console.log(preview);
|
|
879
|
+
console.log();
|
|
880
|
+
console.log(DIM(`... preview truncated at ${(0, format_1.formatBytes)(maxPreviewBytes)}. Use /artifacts show <id> --full for full output.`));
|
|
881
|
+
}
|
|
882
|
+
function formatArtifactPathForDisplay(artifactPath) {
|
|
883
|
+
return (0, session_storage_1.redactTraceText)(artifactPath);
|
|
884
|
+
}
|
|
885
|
+
function handleArtifacts(ctx, args = '') {
|
|
886
|
+
const parsed = parseArtifactArgs(args);
|
|
887
|
+
if (parsed.action === 'list') {
|
|
888
|
+
const artifacts = (0, tool_artifacts_1.listArtifacts)(ctx.cwd, parsed.limit);
|
|
889
|
+
console.log(HEADER('Artifacts'));
|
|
890
|
+
console.log(DIM('─'.repeat(40)));
|
|
891
|
+
if (artifacts.length === 0) {
|
|
892
|
+
console.log(DIM('No artifacts found for this project.'));
|
|
893
|
+
return { success: true };
|
|
894
|
+
}
|
|
895
|
+
for (const artifact of artifacts) {
|
|
896
|
+
console.log(`${ACCENT(artifact.id)} ${DIM(artifact.toolName)} ${(0, format_1.formatBytes)(artifact.outputBytes)}`);
|
|
897
|
+
console.log(` ${DIM(formatDateTime(artifact.modifiedAt))}`);
|
|
898
|
+
console.log(` ${DIM(formatArtifactPathForDisplay(artifact.path))}`);
|
|
899
|
+
}
|
|
900
|
+
console.log();
|
|
901
|
+
console.log(DIM('Use /artifacts show <id|prefix> to preview, or add --full for full output.'));
|
|
902
|
+
return { success: true };
|
|
903
|
+
}
|
|
904
|
+
if (!parsed.ref) {
|
|
905
|
+
console.log(ERROR('Usage: /artifacts show <id|prefix> [--full]'));
|
|
906
|
+
return { success: false };
|
|
907
|
+
}
|
|
908
|
+
const artifact = (0, tool_artifacts_1.findArtifact)(ctx.cwd, parsed.ref);
|
|
909
|
+
if (!artifact) {
|
|
910
|
+
console.log(ERROR(`Artifact not found or ambiguous: ${parsed.ref}`));
|
|
911
|
+
console.log(DIM('Run /artifacts to list available artifact ids.'));
|
|
912
|
+
return { success: false };
|
|
913
|
+
}
|
|
914
|
+
const content = (0, tool_artifacts_1.retrieveArtifact)(artifact.path);
|
|
915
|
+
if (content == null) {
|
|
916
|
+
console.log(ERROR(`Artifact exists but cannot be read: ${artifact.id}`));
|
|
917
|
+
console.log(DIM(formatArtifactPathForDisplay(artifact.path)));
|
|
918
|
+
return { success: false };
|
|
919
|
+
}
|
|
920
|
+
console.log(HEADER(`Artifact ${artifact.id}`));
|
|
921
|
+
console.log(DIM(`Tool ${artifact.toolName} Size ${(0, format_1.formatBytes)(artifact.outputBytes)} Modified ${formatDateTime(artifact.modifiedAt)}`));
|
|
922
|
+
console.log(DIM(formatArtifactPathForDisplay(artifact.path)));
|
|
923
|
+
console.log(DIM('─'.repeat(40)));
|
|
924
|
+
printArtifactPreview(content, parsed.full);
|
|
925
|
+
return { success: true };
|
|
926
|
+
}
|
|
927
|
+
function findCheckpointByRef(ctx, ref) {
|
|
928
|
+
const checkpoints = (0, checkpoint_1.listCheckpoints)(ctx.cwd);
|
|
929
|
+
const exact = checkpoints.find(checkpoint => checkpoint.turnId === ref);
|
|
930
|
+
if (exact)
|
|
931
|
+
return { checkpoint: exact, ambiguous: false };
|
|
932
|
+
const matches = checkpoints.filter(checkpoint => checkpoint.turnId.startsWith(ref));
|
|
933
|
+
return {
|
|
934
|
+
checkpoint: matches.length === 1 ? matches[0] : undefined,
|
|
935
|
+
ambiguous: matches.length > 1,
|
|
936
|
+
};
|
|
937
|
+
}
|
|
938
|
+
function handleCheckpoint(ctx, args = '') {
|
|
939
|
+
const tokens = args.trim().split(/\s+/).filter(Boolean);
|
|
940
|
+
const action = tokens[0] ?? 'list';
|
|
941
|
+
if (action === 'list') {
|
|
942
|
+
const checkpoints = (0, checkpoint_1.listCheckpoints)(ctx.cwd);
|
|
943
|
+
console.log(HEADER('Checkpoints'));
|
|
944
|
+
console.log(DIM('─'.repeat(40)));
|
|
945
|
+
if (checkpoints.length === 0) {
|
|
946
|
+
console.log(DIM('No checkpoints found for this project.'));
|
|
947
|
+
return { success: true };
|
|
948
|
+
}
|
|
949
|
+
for (const checkpoint of checkpoints.slice(0, 20)) {
|
|
950
|
+
console.log(`${ACCENT(checkpoint.turnId)} ${DIM(formatDateTime(checkpoint.createdAt))}`);
|
|
951
|
+
const files = checkpoint.files.map(file => file.path).slice(0, 8).join(', ');
|
|
952
|
+
console.log(` ${DIM(`${checkpoint.files.length} file(s)${files ? `: ${files}` : ''}`)}`);
|
|
953
|
+
}
|
|
954
|
+
console.log();
|
|
955
|
+
console.log(DIM('Use /checkpoint restore <turn-id|prefix> to preview, then add --yes to restore.'));
|
|
956
|
+
return { success: true };
|
|
957
|
+
}
|
|
958
|
+
if (action !== 'restore') {
|
|
959
|
+
console.log(ERROR('Usage: /checkpoint [list|restore <turn-id|prefix> [--yes]]'));
|
|
960
|
+
return { success: false };
|
|
961
|
+
}
|
|
962
|
+
const ref = tokens.find(token => token !== 'restore' && token !== '--yes');
|
|
963
|
+
const confirmed = tokens.includes('--yes');
|
|
964
|
+
if (!ref) {
|
|
965
|
+
console.log(ERROR('Usage: /checkpoint restore <turn-id|prefix> [--yes]'));
|
|
966
|
+
return { success: false };
|
|
967
|
+
}
|
|
968
|
+
const { checkpoint, ambiguous } = findCheckpointByRef(ctx, ref);
|
|
969
|
+
if (!checkpoint) {
|
|
970
|
+
console.log(ERROR(ambiguous
|
|
971
|
+
? `Checkpoint prefix is ambiguous: ${ref}`
|
|
972
|
+
: `Checkpoint not found: ${ref}`));
|
|
973
|
+
console.log(DIM('Run /checkpoint to list available checkpoint ids.'));
|
|
974
|
+
return { success: false };
|
|
975
|
+
}
|
|
976
|
+
if (!confirmed) {
|
|
977
|
+
console.log(HEADER(`Checkpoint ${checkpoint.turnId}`));
|
|
978
|
+
console.log(DIM(`${formatDateTime(checkpoint.createdAt)} ${checkpoint.files.length} file(s)`));
|
|
979
|
+
for (const file of checkpoint.files.slice(0, 20)) {
|
|
980
|
+
console.log(` ${file.path} ${DIM((0, format_1.formatBytes)(file.sizeBytes))}`);
|
|
981
|
+
}
|
|
982
|
+
console.log();
|
|
983
|
+
console.log(WARN(`This will overwrite current files from checkpoint ${checkpoint.turnId}.`));
|
|
984
|
+
console.log(DIM(`Run /checkpoint restore ${checkpoint.turnId} --yes to restore.`));
|
|
985
|
+
return { success: true };
|
|
986
|
+
}
|
|
987
|
+
const result = (0, checkpoint_1.restoreCheckpoint)(ctx.cwd, checkpoint.turnId);
|
|
988
|
+
if (result.error) {
|
|
989
|
+
console.log(ERROR(result.error));
|
|
990
|
+
return { success: false, error: result.error };
|
|
991
|
+
}
|
|
992
|
+
console.log(SUCCESS(`Restored ${result.restored.length} file(s) from checkpoint ${checkpoint.turnId}.`));
|
|
993
|
+
for (const file of result.restored.slice(0, 20)) {
|
|
994
|
+
console.log(` ${file}`);
|
|
995
|
+
}
|
|
996
|
+
return { success: true, output: result.restored.join('\n') };
|
|
997
|
+
}
|
|
998
|
+
function snapshotCurrentModel(ctx) {
|
|
999
|
+
return ctx.store.getSnapshot().currentModel || ctx.config.model;
|
|
1000
|
+
}
|
|
1001
|
+
function getCommandAutoCompact(ctx, modelId) {
|
|
1002
|
+
if (ctx.compactCoordinator) {
|
|
1003
|
+
ctx.compactCoordinator.configure({
|
|
1004
|
+
modelId,
|
|
1005
|
+
llm: ctx.llm,
|
|
1006
|
+
outputReserveTokens: ctx.llm?.getMaxTokens?.(),
|
|
1007
|
+
});
|
|
1008
|
+
return ctx.compactCoordinator.getAutomatic();
|
|
1009
|
+
}
|
|
1010
|
+
return (0, auto_compact_1.getAutoCompact)({ modelId });
|
|
1011
|
+
}
|
|
1012
|
+
function showAgents(ctx) {
|
|
1013
|
+
console.log();
|
|
1014
|
+
console.log(HEADER('Registered Agents'));
|
|
1015
|
+
console.log(DIM('─'.repeat(40)));
|
|
1016
|
+
for (const agent of ctx.runtime.agents) {
|
|
1017
|
+
const status = agent.getStatus();
|
|
1018
|
+
const statusColor = status.status === 'idle' ? SUCCESS : WARN;
|
|
1019
|
+
console.log();
|
|
1020
|
+
console.log(` ${ACCENT(status.name)} ${DIM(`(${status.id})`)}`);
|
|
1021
|
+
console.log(` Status: ${statusColor(status.status)}`);
|
|
1022
|
+
console.log(` Capabilities: ${status.capabilities.join(', ')}`);
|
|
1023
|
+
}
|
|
1024
|
+
console.log();
|
|
1025
|
+
return { success: true };
|
|
1026
|
+
}
|
|
1027
|
+
function showMemory(ctx) {
|
|
1028
|
+
console.log();
|
|
1029
|
+
console.log(HEADER('Memory Status'));
|
|
1030
|
+
console.log(DIM('─'.repeat(40)));
|
|
1031
|
+
const memStatus = ctx.runtime.memory.getStatus();
|
|
1032
|
+
const storeStats = ctx.runtime.store.getStats();
|
|
1033
|
+
console.log();
|
|
1034
|
+
console.log(HEADER(' Inline MemorySystem:'));
|
|
1035
|
+
console.log(` Working ${memStatus.working} / ${ctx.runtime.config.memory.workingCapacity}`);
|
|
1036
|
+
console.log(` Short-term ${memStatus['short-term']} / ${ctx.runtime.config.memory.shortTermCapacity}`);
|
|
1037
|
+
console.log(` Long-term ${memStatus['long-term']} entries`);
|
|
1038
|
+
console.log();
|
|
1039
|
+
console.log(HEADER(' Modular MemoryStore:'));
|
|
1040
|
+
console.log(` Working ${storeStats.working}`);
|
|
1041
|
+
console.log(` Short-term ${storeStats['short-term']}`);
|
|
1042
|
+
console.log(` Long-term ${storeStats['long-term']} entries`);
|
|
1043
|
+
console.log();
|
|
1044
|
+
return { success: true };
|
|
1045
|
+
}
|
|
1046
|
+
async function handleMemoryReindex(_ctx) {
|
|
1047
|
+
const { isSemanticEnabled, getSemanticSearchService } = require('../memory/semantic-search');
|
|
1048
|
+
if (!isSemanticEnabled()) {
|
|
1049
|
+
console.log();
|
|
1050
|
+
console.log(WARN('⚠ Semantic search is not enabled.'));
|
|
1051
|
+
console.log(DIM(' Set ORION_CODE_EMBEDDING_PROVIDER=ollama or openai to enable.'));
|
|
1052
|
+
console.log();
|
|
1053
|
+
return { success: false };
|
|
1054
|
+
}
|
|
1055
|
+
console.log();
|
|
1056
|
+
console.log(HEADER('Reindexing project memories...'));
|
|
1057
|
+
try {
|
|
1058
|
+
const service = getSemanticSearchService();
|
|
1059
|
+
const count = await service.indexExistingMemories(process.cwd());
|
|
1060
|
+
console.log(SUCCESS(`✔ Indexed ${count} memories`));
|
|
1061
|
+
}
|
|
1062
|
+
catch (err) {
|
|
1063
|
+
console.log(ERROR(`✗ Reindex failed: ${err.message}`));
|
|
1064
|
+
return { success: false };
|
|
1065
|
+
}
|
|
1066
|
+
console.log();
|
|
1067
|
+
return { success: true };
|
|
1068
|
+
}
|
|
1069
|
+
async function handleMemory(ctx, args) {
|
|
1070
|
+
const sub = args.trim().toLowerCase();
|
|
1071
|
+
if (sub === 'reindex') {
|
|
1072
|
+
return handleMemoryReindex(ctx);
|
|
1073
|
+
}
|
|
1074
|
+
return showMemory(ctx);
|
|
1075
|
+
}
|
|
1076
|
+
function showSafety(ctx) {
|
|
1077
|
+
console.log();
|
|
1078
|
+
console.log(HEADER('Safety Checker'));
|
|
1079
|
+
console.log(DIM('─'.repeat(40)));
|
|
1080
|
+
const policy = ctx.runtime.safety.getPolicy();
|
|
1081
|
+
const summary = ctx.runtime.safety.getAuditSummary();
|
|
1082
|
+
console.log();
|
|
1083
|
+
console.log(` Enabled ${policy.enabled ? SUCCESS('yes') : ERROR('no')}`);
|
|
1084
|
+
console.log(` Sandbox ${policy.sandboxMode ? WARN('on') : DIM('off')}`);
|
|
1085
|
+
console.log();
|
|
1086
|
+
console.log(` Blocked patterns:`);
|
|
1087
|
+
for (const pattern of policy.blocked) {
|
|
1088
|
+
console.log(` ${ERROR('✗')} ${DIM(pattern)}`);
|
|
1089
|
+
}
|
|
1090
|
+
console.log();
|
|
1091
|
+
console.log(` Dangerous patterns:`);
|
|
1092
|
+
for (const pattern of policy.dangerousPatterns) {
|
|
1093
|
+
console.log(` ${WARN('⚠')} ${DIM(pattern)}`);
|
|
1094
|
+
}
|
|
1095
|
+
console.log();
|
|
1096
|
+
console.log(` Audit summary: ${summary.total} checks | ${SUCCESS(`${summary.passed} passed`)} | ${ERROR(`${summary.blocked} blocked`)}`);
|
|
1097
|
+
console.log();
|
|
1098
|
+
return { success: true };
|
|
1099
|
+
}
|
|
1100
|
+
function showHarness(ctx, args = '') {
|
|
1101
|
+
const explain = args.trim().toLowerCase() === 'explain';
|
|
1102
|
+
console.log();
|
|
1103
|
+
console.log(HEADER(explain ? 'Harness Explain' : 'Harness'));
|
|
1104
|
+
console.log(DIM('─'.repeat(40)));
|
|
1105
|
+
const cfg = ctx.runtime.harness.getConfig();
|
|
1106
|
+
console.log();
|
|
1107
|
+
if (!explain) {
|
|
1108
|
+
console.log(` Max steps ${cfg.maxSteps}`);
|
|
1109
|
+
console.log(` Boundary check ${cfg.boundaryCheck ? SUCCESS('on') : ERROR('off')}`);
|
|
1110
|
+
console.log(` Goal constraint ${cfg.goalConstraint ? SUCCESS('on') : ERROR('off')}`);
|
|
1111
|
+
console.log(` Result validate ${cfg.resultValidation ? SUCCESS('on') : ERROR('off')}`);
|
|
1112
|
+
console.log(` Sandbox ${cfg.sandbox ? WARN('on') : DIM('off')}`);
|
|
1113
|
+
console.log(` Timeout ${cfg.timeout}ms`);
|
|
1114
|
+
console.log(` Blocked actions ${DIM(cfg.blockedActions.join(', ') || 'none')}`);
|
|
1115
|
+
}
|
|
1116
|
+
const state = ctx.store.getSnapshot().harnessState;
|
|
1117
|
+
if (!state) {
|
|
1118
|
+
console.log();
|
|
1119
|
+
console.log(DIM(' No Context Harness state for this session yet.'));
|
|
1120
|
+
console.log();
|
|
1121
|
+
return { success: true };
|
|
1122
|
+
}
|
|
1123
|
+
if (explain) {
|
|
1124
|
+
// Build explain output from harnessState in store
|
|
1125
|
+
const contract = state.contract;
|
|
1126
|
+
// Contract section
|
|
1127
|
+
console.log(HEADER(' Contract'));
|
|
1128
|
+
if (contract) {
|
|
1129
|
+
console.log(` Objective ${ACCENT(contract.objective || '(none)')}`);
|
|
1130
|
+
if (contract.requirements?.length) {
|
|
1131
|
+
console.log(` Requires ${DIM(contract.requirements.slice(0, 3).join(' | '))}`);
|
|
1132
|
+
}
|
|
1133
|
+
if (contract.prohibitions?.length) {
|
|
1134
|
+
console.log(` Prohibits ${WARN(contract.prohibitions.slice(0, 3).join(' | '))}`);
|
|
1135
|
+
}
|
|
1136
|
+
if (contract.successCriteria?.length) {
|
|
1137
|
+
console.log(` Success ${DIM(contract.successCriteria.slice(0, 3).join(' | '))}`);
|
|
1138
|
+
}
|
|
1139
|
+
}
|
|
1140
|
+
else {
|
|
1141
|
+
console.log(DIM(' (no contract established)'));
|
|
1142
|
+
}
|
|
1143
|
+
console.log();
|
|
1144
|
+
// Context source
|
|
1145
|
+
console.log(HEADER(' Context Source'));
|
|
1146
|
+
const session = ctx.getSession?.() ?? (ctx.sessionId ? (0, session_storage_1.loadSessionMeta)(ctx.sessionId) : null);
|
|
1147
|
+
const isRestored = session?.transcriptDisplayStartTime != null;
|
|
1148
|
+
const isCompactActive = Boolean(state.promptAssemblyStats);
|
|
1149
|
+
console.log(` Root ${ACCENT(state.rootObjective || contract?.objective || '(none)')}`);
|
|
1150
|
+
console.log(` Active ${DIM(state.activeInstruction || contract?.userIntent || '(none)')}`);
|
|
1151
|
+
console.log(` Source ${isRestored ? WARN('restored session') : DIM('live turn')}`);
|
|
1152
|
+
if (isRestored && session) {
|
|
1153
|
+
const restoredTime = session.transcriptDisplayStartTime
|
|
1154
|
+
? new Date(session.transcriptDisplayStartTime).toLocaleString()
|
|
1155
|
+
: 'unknown';
|
|
1156
|
+
console.log(` Restored ${DIM(restoredTime)}`);
|
|
1157
|
+
}
|
|
1158
|
+
if (isCompactActive) {
|
|
1159
|
+
console.log(` Compact ${SUCCESS('active')}`);
|
|
1160
|
+
}
|
|
1161
|
+
console.log();
|
|
1162
|
+
// Evidence index summary
|
|
1163
|
+
console.log(HEADER(' Evidence Index'));
|
|
1164
|
+
const evidenceItems = state.evidenceIndex?.length ?? 0;
|
|
1165
|
+
const evidenceKinds = new Map();
|
|
1166
|
+
if (state.evidenceIndex) {
|
|
1167
|
+
for (const item of state.evidenceIndex) {
|
|
1168
|
+
const kind = item.kind || 'unknown';
|
|
1169
|
+
evidenceKinds.set(kind, (evidenceKinds.get(kind) || 0) + 1);
|
|
1170
|
+
}
|
|
1171
|
+
}
|
|
1172
|
+
console.log(` Total ${ACCENT(String(evidenceItems))} items`);
|
|
1173
|
+
if (evidenceKinds.size > 0) {
|
|
1174
|
+
const kinds = Array.from(evidenceKinds.entries())
|
|
1175
|
+
.sort((a, b) => b[1] - a[1])
|
|
1176
|
+
.slice(0, 10);
|
|
1177
|
+
for (const [kind, count] of kinds) {
|
|
1178
|
+
console.log(` ${DIM(kind.padEnd(16))} ${count}`);
|
|
1179
|
+
}
|
|
1180
|
+
}
|
|
1181
|
+
else {
|
|
1182
|
+
console.log(DIM(' (no evidence records yet)'));
|
|
1183
|
+
}
|
|
1184
|
+
console.log();
|
|
1185
|
+
// Intent history
|
|
1186
|
+
console.log(HEADER(' Recent Intents'));
|
|
1187
|
+
const intents = state.intentHistory?.slice(-5) ?? [];
|
|
1188
|
+
if (intents.length > 0) {
|
|
1189
|
+
for (const intent of intents) {
|
|
1190
|
+
const conf = intent.confidence != null ? ` (${Math.round(intent.confidence * 100)}%)` : '';
|
|
1191
|
+
console.log(` ${ACCENT(intent.kind)}${DIM(conf)} ${DIM(intent.summary?.slice(0, 50) || '')}`);
|
|
1192
|
+
}
|
|
1193
|
+
}
|
|
1194
|
+
else {
|
|
1195
|
+
console.log(DIM(' (no intents recorded)'));
|
|
1196
|
+
}
|
|
1197
|
+
console.log();
|
|
1198
|
+
// Capsule snapshot
|
|
1199
|
+
console.log(HEADER(' Capsule'));
|
|
1200
|
+
const capsule = state.capsule;
|
|
1201
|
+
if (capsule) {
|
|
1202
|
+
console.log(` Next ${DIM(capsule.nextAction)}`);
|
|
1203
|
+
if (capsule.completed?.length) {
|
|
1204
|
+
console.log(` Done ${SUCCESS(`${capsule.completed.length} steps`)}`);
|
|
1205
|
+
}
|
|
1206
|
+
if (capsule.openTodos?.length) {
|
|
1207
|
+
console.log(` Open ${WARN(`${capsule.openTodos.length} todos`)}`);
|
|
1208
|
+
}
|
|
1209
|
+
if (capsule.changedFiles?.length) {
|
|
1210
|
+
console.log(` Files ${DIM(capsule.changedFiles.slice(0, 5).join(', '))}`);
|
|
1211
|
+
}
|
|
1212
|
+
const passed = capsule.verification?.passed?.length ?? 0;
|
|
1213
|
+
const failed = capsule.verification?.failed?.length ?? 0;
|
|
1214
|
+
console.log(` Verify ${SUCCESS(`${passed} passed`)} / ${failed > 0 ? ERROR(`${failed} failed`) : DIM('0 failed')}`);
|
|
1215
|
+
}
|
|
1216
|
+
else {
|
|
1217
|
+
console.log(DIM(' (no capsule yet)'));
|
|
1218
|
+
}
|
|
1219
|
+
console.log();
|
|
1220
|
+
// Prompt assembly stats
|
|
1221
|
+
const stats = state.promptAssemblyStats;
|
|
1222
|
+
console.log(HEADER(' Prompt Assembly'));
|
|
1223
|
+
if (stats) {
|
|
1224
|
+
console.log(` Model ${ACCENT(stats.modelId)}`);
|
|
1225
|
+
console.log(` Budget ${DIM(`${stats.estimatedTokens}/${stats.budgetTokens} tokens`)}`);
|
|
1226
|
+
console.log(` Sections ${DIM(stats.sections.join(', ') || 'none')}`);
|
|
1227
|
+
console.log(` Ledger ${DIM(`${state.ledger?.length ?? 0} entries`)}`);
|
|
1228
|
+
console.log(` Evidence ${DIM(`${state.evidenceIndex?.length ?? 0} records`)}`);
|
|
1229
|
+
console.log(` Turns ${DIM(`${state.turnSummaries?.length ?? 0} summaries`)}`);
|
|
1230
|
+
console.log();
|
|
1231
|
+
console.log(HEADER(' Included Evidence'));
|
|
1232
|
+
for (const item of stats.includedEvidence.slice(0, 10)) {
|
|
1233
|
+
console.log(` ${ACCENT(item.id)} ${DIM(`[${item.kind}] score=${item.score} tokens=${item.tokens}`)}`);
|
|
1234
|
+
console.log(` ${DIM(item.reason)}`);
|
|
1235
|
+
}
|
|
1236
|
+
if (stats.includedEvidence.length === 0) {
|
|
1237
|
+
console.log(DIM(' none'));
|
|
1238
|
+
}
|
|
1239
|
+
if (stats.omittedEvidence.length > 0) {
|
|
1240
|
+
console.log();
|
|
1241
|
+
console.log(HEADER(' Omitted Evidence'));
|
|
1242
|
+
for (const item of stats.omittedEvidence.slice(0, 8)) {
|
|
1243
|
+
console.log(` ${DIM(item.id)} ${DIM(`[${item.kind}] score=${item.score} tokens=${item.tokens}`)}`);
|
|
1244
|
+
console.log(` ${DIM(item.reason)}`);
|
|
1245
|
+
}
|
|
1246
|
+
}
|
|
1247
|
+
}
|
|
1248
|
+
else {
|
|
1249
|
+
console.log(DIM(' No prompt assembly stats recorded yet. Run a chat turn first.'));
|
|
1250
|
+
}
|
|
1251
|
+
console.log();
|
|
1252
|
+
console.log(HEADER(' Auto Compact'));
|
|
1253
|
+
const compactStats = getCommandAutoCompact(ctx, state.promptAssemblyStats?.modelId ?? snapshotCurrentModel(ctx)).getStats();
|
|
1254
|
+
const contextInfo = (0, model_context_1.resolveModelContext)(compactStats.modelId);
|
|
1255
|
+
console.log(` Model ${ACCENT(compactStats.modelId)}`);
|
|
1256
|
+
console.log(` Window ${DIM(`${formatTokenCount(contextInfo.contextWindow)} tokens (${contextInfo.source}${contextInfo.source === 'fuzzy' ? `:${contextInfo.matchedId}` : ''})`)}`);
|
|
1257
|
+
console.log(` Thresholds ${DIM(`predict ${formatThreshold(compactStats.predictiveCompactThreshold)}, hard ${formatThreshold(compactStats.threshold)}, prewarm ${formatThreshold(compactStats.preCompactThreshold)}`)}`);
|
|
1258
|
+
console.log(` Usage ${DIM(`${compactStats.lastTokenCount} tokens, ${compactStats.ctxPercent}%`)}`);
|
|
1259
|
+
console.log(` Armed ${compactStats.preCompactArmed ? SUCCESS('yes') : DIM('no')}`);
|
|
1260
|
+
console.log(` Last mode ${DIM(compactStats.lastCompactMode ?? 'none')}`);
|
|
1261
|
+
console.log();
|
|
1262
|
+
return { success: true };
|
|
1263
|
+
}
|
|
1264
|
+
console.log();
|
|
1265
|
+
console.log(HEADER(' Context State'));
|
|
1266
|
+
console.log(` Version ${ACCENT(String(state.version ?? 1))}`);
|
|
1267
|
+
console.log(` Epoch ${ACCENT(String(state.taskEpoch ?? 1))}`);
|
|
1268
|
+
console.log(` Objective ${ACCENT(state.rootObjective ?? state.contract?.objective ?? '(none)')}`);
|
|
1269
|
+
console.log(` Active ${DIM(state.activeInstruction ?? state.contract?.userIntent ?? '(none)')}`);
|
|
1270
|
+
console.log(` Ledger ${DIM(`${state.ledger.length} entries`)}`);
|
|
1271
|
+
console.log(` Evidence ${DIM(`${state.evidenceIndex?.length ?? 0} records`)}`);
|
|
1272
|
+
console.log(` Turns ${DIM(`${state.turnSummaries?.length ?? 0} summaries`)}`);
|
|
1273
|
+
if (state.activeConstraints && state.activeConstraints.length > 0) {
|
|
1274
|
+
console.log(` Constraints ${DIM(state.activeConstraints.slice(0, 3).join(' | '))}`);
|
|
1275
|
+
}
|
|
1276
|
+
if (state.capsule) {
|
|
1277
|
+
console.log(` Next ${DIM(state.capsule.nextAction)}`);
|
|
1278
|
+
const passed = state.capsule.verification.passed.length;
|
|
1279
|
+
const failed = state.capsule.verification.failed.length;
|
|
1280
|
+
console.log(` Verify ${SUCCESS(`${passed} passed`)} / ${failed > 0 ? ERROR(`${failed} failed`) : DIM('0 failed')}`);
|
|
1281
|
+
}
|
|
1282
|
+
if (state.diagnostics && state.diagnostics.length > 0) {
|
|
1283
|
+
console.log(` Diagnostics ${WARN(state.diagnostics.slice(-2).join(' | '))}`);
|
|
1284
|
+
}
|
|
1285
|
+
console.log();
|
|
1286
|
+
return { success: true };
|
|
1287
|
+
}
|
|
1288
|
+
function showConfig(ctx) {
|
|
1289
|
+
console.log();
|
|
1290
|
+
console.log(HEADER('Configuration'));
|
|
1291
|
+
console.log(DIM('─'.repeat(40)));
|
|
1292
|
+
const summary = {
|
|
1293
|
+
name: ctx.config.name,
|
|
1294
|
+
model: ctx.config.model,
|
|
1295
|
+
apiBaseUrl: ctx.config.apiBaseUrl || '(default OpenAI)',
|
|
1296
|
+
apiKey: ctx.config.apiKey ? `${ctx.config.apiKey.slice(0, 7)}***` : '(not set)',
|
|
1297
|
+
mode: ctx.config.mode,
|
|
1298
|
+
logLevel: ctx.config.logLevel,
|
|
1299
|
+
toolConfirmation: ctx.config.toolConfirmation,
|
|
1300
|
+
};
|
|
1301
|
+
const llmSummary = ctx.llm?.getConfigSummary() ?? {};
|
|
1302
|
+
for (const [key, val] of Object.entries(summary)) {
|
|
1303
|
+
console.log(` ${ACCENT(key.padEnd(16))} ${DIM(val)}`);
|
|
1304
|
+
}
|
|
1305
|
+
console.log();
|
|
1306
|
+
console.log(HEADER(' LLM Settings:'));
|
|
1307
|
+
for (const [key, val] of Object.entries(llmSummary)) {
|
|
1308
|
+
console.log(` ${ACCENT(key.padEnd(16))} ${DIM(val)}`);
|
|
1309
|
+
}
|
|
1310
|
+
console.log();
|
|
1311
|
+
return { success: true };
|
|
1312
|
+
}
|
|
1313
|
+
function handleModel(ctx, args) {
|
|
1314
|
+
const trimmedArgs = args.trim().toLowerCase();
|
|
1315
|
+
// 显示当前模型
|
|
1316
|
+
if (!args || trimmedArgs === '?' || trimmedArgs === 'info') {
|
|
1317
|
+
console.log();
|
|
1318
|
+
if (ctx.llm) {
|
|
1319
|
+
const currentModel = ctx.llm.getModel();
|
|
1320
|
+
const aliasEntry = (0, model_catalog_1.getModelCatalogEntry)(currentModel);
|
|
1321
|
+
const contextInfo = (0, model_context_1.resolveModelContext)(currentModel);
|
|
1322
|
+
const compactStats = getCommandAutoCompact(ctx, currentModel).getStats();
|
|
1323
|
+
console.log(HEADER('Current Model'));
|
|
1324
|
+
console.log(DIM('─'.repeat(40)));
|
|
1325
|
+
console.log(` Model ${BRAND(currentModel)}`);
|
|
1326
|
+
if (aliasEntry) {
|
|
1327
|
+
console.log(` Alias ${ACCENT(aliasEntry.alias)}`);
|
|
1328
|
+
console.log(` Provider ${DIM(aliasEntry.provider)}`);
|
|
1329
|
+
}
|
|
1330
|
+
console.log(` Context ${DIM(`${formatTokenCount(contextInfo.contextWindow)} tokens`)}`);
|
|
1331
|
+
if (contextInfo.maxOutputTokens) {
|
|
1332
|
+
console.log(` Output ${DIM(`${formatTokenCount(contextInfo.maxOutputTokens)} tokens`)}`);
|
|
1333
|
+
}
|
|
1334
|
+
console.log(` Source ${DIM(`${contextInfo.source}${contextInfo.source === 'fuzzy' ? `:${contextInfo.matchedId}` : ''}`)}`);
|
|
1335
|
+
console.log(` Compact ${compactStats.enabled ? SUCCESS('auto') : WARN('off')} ${DIM(`predict ${formatThreshold(compactStats.predictiveCompactThreshold)}, hard ${formatThreshold(compactStats.threshold)}`)}`);
|
|
1336
|
+
}
|
|
1337
|
+
else {
|
|
1338
|
+
console.log(ERROR('LLM not initialized. Set ORION_CODE_API_KEY first.'));
|
|
1339
|
+
}
|
|
1340
|
+
console.log();
|
|
1341
|
+
return { success: true };
|
|
1342
|
+
}
|
|
1343
|
+
// 显示模型列表
|
|
1344
|
+
if (trimmedArgs === 'list' || trimmedArgs === 'ls') {
|
|
1345
|
+
console.log();
|
|
1346
|
+
console.log(HEADER('Available Models'));
|
|
1347
|
+
console.log(DIM('─'.repeat(40)));
|
|
1348
|
+
const currentModel = ctx.llm?.getModel() || '';
|
|
1349
|
+
const modelPicker = (0, ui_view_model_1.createModelPickerState)({
|
|
1350
|
+
currentModel,
|
|
1351
|
+
models: (0, model_catalog_1.listModelCatalogEntries)().map(model => {
|
|
1352
|
+
const contextInfo = (0, model_context_1.resolveModelContext)(model.name);
|
|
1353
|
+
return {
|
|
1354
|
+
...model,
|
|
1355
|
+
contextWindow: contextInfo.contextWindow,
|
|
1356
|
+
maxOutputTokens: contextInfo.maxOutputTokens,
|
|
1357
|
+
source: contextInfo.source,
|
|
1358
|
+
};
|
|
1359
|
+
}),
|
|
1360
|
+
});
|
|
1361
|
+
for (const item of modelPicker.visibleItems) {
|
|
1362
|
+
const marker = item.isCurrent ? SUCCESS('●') : DIM('○');
|
|
1363
|
+
const alias = item.alias ? `(${item.alias})` : '';
|
|
1364
|
+
const context = `${formatTokenCount(item.contextWindow ?? 0)} ctx`;
|
|
1365
|
+
const current = item.isCurrent ? BRAND('(current)') : '';
|
|
1366
|
+
console.log(` ${marker} ${ACCENT(item.name)} ${DIM(alias)} ${DIM(context)} ${current}`);
|
|
1367
|
+
console.log(` ${DIM(item.provider ?? 'unknown')}`);
|
|
1368
|
+
}
|
|
1369
|
+
console.log();
|
|
1370
|
+
console.log(DIM('Use /model <name|alias> to switch, e.g. /model sonnet'));
|
|
1371
|
+
console.log();
|
|
1372
|
+
return { success: true };
|
|
1373
|
+
}
|
|
1374
|
+
// 显示帮助
|
|
1375
|
+
if (trimmedArgs === 'help') {
|
|
1376
|
+
console.log();
|
|
1377
|
+
console.log(HEADER('/model Command Help'));
|
|
1378
|
+
console.log(DIM('─'.repeat(40)));
|
|
1379
|
+
console.log();
|
|
1380
|
+
console.log(` ${ACCENT('/model')} Show current model`);
|
|
1381
|
+
console.log(` ${ACCENT('/model list')} Show available models`);
|
|
1382
|
+
console.log(` ${ACCENT('/model <name>')} Switch to specific model`);
|
|
1383
|
+
console.log(` ${ACCENT('/model <alias>')} Switch using alias (opus, sonnet, haiku)`);
|
|
1384
|
+
console.log();
|
|
1385
|
+
console.log(DIM(`Aliases: ${formatModelAliasHelp()}`));
|
|
1386
|
+
console.log();
|
|
1387
|
+
return { success: true };
|
|
1388
|
+
}
|
|
1389
|
+
// 设置模型
|
|
1390
|
+
if (!ctx.llm) {
|
|
1391
|
+
console.log(ERROR('LLM not initialized. Set ORION_CODE_API_KEY first.'));
|
|
1392
|
+
console.log();
|
|
1393
|
+
return { success: false };
|
|
1394
|
+
}
|
|
1395
|
+
// 解析别名
|
|
1396
|
+
const resolvedModel = (0, model_catalog_1.resolveModelAlias)(args);
|
|
1397
|
+
ctx.llm.setModel(resolvedModel);
|
|
1398
|
+
getCommandAutoCompact(ctx, resolvedModel);
|
|
1399
|
+
ctx.store.setState({ currentModel: resolvedModel });
|
|
1400
|
+
console.log(SUCCESS(`✔ Model changed to ${BRAND(resolvedModel)}`));
|
|
1401
|
+
const contextInfo = (0, model_context_1.resolveModelContext)(resolvedModel);
|
|
1402
|
+
console.log(DIM(` Context window ${formatTokenCount(contextInfo.contextWindow)} tokens (${contextInfo.source})`));
|
|
1403
|
+
console.log();
|
|
1404
|
+
return { success: true };
|
|
1405
|
+
}
|
|
1406
|
+
function normalizePermissionMode(raw) {
|
|
1407
|
+
const value = raw.trim().toLowerCase();
|
|
1408
|
+
if (!value)
|
|
1409
|
+
return null;
|
|
1410
|
+
if (value === 'accept' || value === 'acceptedits' || value === 'accept-edits' || value === 'edit') {
|
|
1411
|
+
return 'acceptEdits';
|
|
1412
|
+
}
|
|
1413
|
+
if (value === 'default' || value === 'ask')
|
|
1414
|
+
return 'default';
|
|
1415
|
+
if (value === 'plan' || value === 'readonly' || value === 'read-only')
|
|
1416
|
+
return 'plan';
|
|
1417
|
+
if (value === 'auto' || value === 'full-auto')
|
|
1418
|
+
return 'auto';
|
|
1419
|
+
return null;
|
|
1420
|
+
}
|
|
1421
|
+
function handleMode(ctx, args) {
|
|
1422
|
+
const current = ctx.store.getSnapshot().permissionMode;
|
|
1423
|
+
const trimmed = args.trim();
|
|
1424
|
+
if (!trimmed || trimmed === '?' || trimmed === 'help') {
|
|
1425
|
+
console.log();
|
|
1426
|
+
console.log(HEADER('Permission Mode'));
|
|
1427
|
+
console.log(DIM('─'.repeat(40)));
|
|
1428
|
+
console.log(` Current ${ACCENT(current)} ${DIM((0, types_1.getModeDisplayText)(current) || 'ask before sensitive actions')}`);
|
|
1429
|
+
console.log();
|
|
1430
|
+
console.log(` ${ACCENT('/mode next')} Cycle to the next mode`);
|
|
1431
|
+
console.log(` ${ACCENT('/mode default')} Ask before sensitive actions`);
|
|
1432
|
+
console.log(` ${ACCENT('/mode accept-edits')} Auto-accept file edits`);
|
|
1433
|
+
console.log(` ${ACCENT('/mode plan')} Plan first, avoid executing edits`);
|
|
1434
|
+
console.log(` ${ACCENT('/mode auto')} Auto-run allowed actions`);
|
|
1435
|
+
console.log();
|
|
1436
|
+
return { success: true };
|
|
1437
|
+
}
|
|
1438
|
+
const next = trimmed === 'next'
|
|
1439
|
+
? (0, types_1.getNextPermissionMode)(current)
|
|
1440
|
+
: normalizePermissionMode(trimmed);
|
|
1441
|
+
if (!next || !types_1.PERMISSION_MODES.includes(next)) {
|
|
1442
|
+
return {
|
|
1443
|
+
success: false,
|
|
1444
|
+
error: `Unknown mode: ${trimmed}. Use one of: default, accept-edits, plan, auto, next.`,
|
|
1445
|
+
};
|
|
1446
|
+
}
|
|
1447
|
+
ctx.store.setPermissionMode(next);
|
|
1448
|
+
const display = (0, types_1.getModeDisplayText)(next);
|
|
1449
|
+
return {
|
|
1450
|
+
success: true,
|
|
1451
|
+
output: `Mode changed to ${next}${display ? ` (${display})` : ''}.`,
|
|
1452
|
+
};
|
|
1453
|
+
}
|
|
1454
|
+
function handleTask(ctx, args) {
|
|
1455
|
+
const [sub] = args.trim().split(/\s+/);
|
|
1456
|
+
if (sub === 'list' || sub === 'ls') {
|
|
1457
|
+
if (!taskManager) {
|
|
1458
|
+
taskManager = new task_manager_1.TaskManager();
|
|
1459
|
+
}
|
|
1460
|
+
console.log();
|
|
1461
|
+
console.log(HEADER('Task List'));
|
|
1462
|
+
console.log(DIM('─'.repeat(40)));
|
|
1463
|
+
const stats = taskManager.getStats();
|
|
1464
|
+
console.log(` Total ${stats.total}`);
|
|
1465
|
+
console.log(` Pending ${stats.pending}`);
|
|
1466
|
+
console.log(` Running ${stats.running}`);
|
|
1467
|
+
console.log(` Completed ${SUCCESS(stats.completed)}`);
|
|
1468
|
+
console.log(` Failed ${ERROR(stats.failed)}`);
|
|
1469
|
+
console.log(` Cancelled ${DIM(stats.cancelled)}`);
|
|
1470
|
+
const tasks = taskManager.list();
|
|
1471
|
+
if (tasks.length > 0) {
|
|
1472
|
+
console.log();
|
|
1473
|
+
for (const t of tasks) {
|
|
1474
|
+
const statusIcon = t.status === 'completed' ? SUCCESS('✓')
|
|
1475
|
+
: t.status === 'failed' ? ERROR('✗')
|
|
1476
|
+
: t.status === 'running' ? WARN('◌')
|
|
1477
|
+
: t.status === 'cancelled' ? DIM('⊘')
|
|
1478
|
+
: DIM('○');
|
|
1479
|
+
console.log(` ${statusIcon} ${ACCENT(t.name)} ${DIM(`(${t.id.slice(0, 8)})`)}`);
|
|
1480
|
+
console.log(` ${DIM(`[${t.priority}]`)} ${t.description.slice(0, 60)}`);
|
|
1481
|
+
}
|
|
1482
|
+
}
|
|
1483
|
+
console.log();
|
|
1484
|
+
return { success: true };
|
|
1485
|
+
}
|
|
1486
|
+
// 默认行为: 作为任务名提交
|
|
1487
|
+
const taskName = args.trim() || 'demo-task';
|
|
1488
|
+
const task = {
|
|
1489
|
+
id: `cli-${Date.now()}`,
|
|
1490
|
+
name: taskName,
|
|
1491
|
+
description: `Task submitted from CLI: ${taskName}`,
|
|
1492
|
+
priority: 'P1',
|
|
1493
|
+
assignedTo: 'leader',
|
|
1494
|
+
status: 'pending',
|
|
1495
|
+
};
|
|
1496
|
+
console.log();
|
|
1497
|
+
ctx.runtime.brain.submitTask(task);
|
|
1498
|
+
console.log(SUCCESS(`✔ Task "${taskName}" submitted`));
|
|
1499
|
+
console.log();
|
|
1500
|
+
return { success: true };
|
|
1501
|
+
}
|
|
1502
|
+
async function handleRun(ctx, args) {
|
|
1503
|
+
if (!args.trim()) {
|
|
1504
|
+
console.log(ERROR('Usage: /run <task description>'));
|
|
1505
|
+
console.log(DIM(' Creates a task and executes it through the Agent + LLM pipeline.'));
|
|
1506
|
+
console.log();
|
|
1507
|
+
return { success: false };
|
|
1508
|
+
}
|
|
1509
|
+
if (!ctx.llm || !(0, config_1.isConfigured)(ctx.config)) {
|
|
1510
|
+
console.log(WARN('⚠ LLM not configured. Set ORION_CODE_API_KEY in .env to enable run mode.'));
|
|
1511
|
+
console.log();
|
|
1512
|
+
return { success: false };
|
|
1513
|
+
}
|
|
1514
|
+
if (!taskManager) {
|
|
1515
|
+
taskManager = new task_manager_1.TaskManager();
|
|
1516
|
+
}
|
|
1517
|
+
const taskOptions = {
|
|
1518
|
+
name: args.slice(0, 80),
|
|
1519
|
+
description: args,
|
|
1520
|
+
priority: 'P1',
|
|
1521
|
+
assignedTo: 'leader',
|
|
1522
|
+
tags: ['cli', 'interactive'],
|
|
1523
|
+
};
|
|
1524
|
+
const record = taskManager.create(taskOptions);
|
|
1525
|
+
console.log();
|
|
1526
|
+
console.log(SUCCESS(`✔ Task created: ${ACCENT(record.name)}`));
|
|
1527
|
+
console.log(DIM(` ID: ${record.id} | Tags: ${record.tags.join(', ')}`));
|
|
1528
|
+
taskManager.start(record.id);
|
|
1529
|
+
console.log(WARN('◌ Running task through Agent + LLM...'));
|
|
1530
|
+
try {
|
|
1531
|
+
const agent = ctx.runtime.agents[0];
|
|
1532
|
+
if (!agent) {
|
|
1533
|
+
throw new Error('No agents registered');
|
|
1534
|
+
}
|
|
1535
|
+
const runner = new agent_runner_1.AgentRunner(agent, ctx.llm);
|
|
1536
|
+
const task = taskManager.toTask(record);
|
|
1537
|
+
const result = await runner.run(task);
|
|
1538
|
+
if (result.success) {
|
|
1539
|
+
taskManager.complete(record.id, result);
|
|
1540
|
+
console.log(SUCCESS(`✓ Task completed in ${result.duration}ms`));
|
|
1541
|
+
if (result.tokenUsage) {
|
|
1542
|
+
console.log(DIM(` Tokens: ${result.tokenUsage.promptTokens} in / ${result.tokenUsage.completionTokens} out`));
|
|
1543
|
+
}
|
|
1544
|
+
if (result.data?.summary) {
|
|
1545
|
+
console.log();
|
|
1546
|
+
console.log(ACCENT(' Summary:'));
|
|
1547
|
+
console.log(` ${result.data.summary}`);
|
|
1548
|
+
}
|
|
1549
|
+
}
|
|
1550
|
+
else {
|
|
1551
|
+
taskManager.fail(record.id, result.error, result);
|
|
1552
|
+
console.log(ERROR(`✗ Task failed: ${result.error}`));
|
|
1553
|
+
}
|
|
1554
|
+
}
|
|
1555
|
+
catch (error) {
|
|
1556
|
+
taskManager.fail(record.id, error.message);
|
|
1557
|
+
console.log(ERROR(`✗ Task error: ${error.message}`));
|
|
1558
|
+
}
|
|
1559
|
+
console.log();
|
|
1560
|
+
return { success: true };
|
|
1561
|
+
}
|
|
1562
|
+
async function handleChat(ctx, input) {
|
|
1563
|
+
const ui = commandUICapabilities(ctx);
|
|
1564
|
+
const writeOutput = ctx.writeOutput ?? ((text) => process.stdout.write(text));
|
|
1565
|
+
const writeLine = ctx.writeLine ?? ((text = '') => console.log(text));
|
|
1566
|
+
if (!input) {
|
|
1567
|
+
console.log(ERROR('Usage: /chat <message>'));
|
|
1568
|
+
console.log();
|
|
1569
|
+
return { success: false };
|
|
1570
|
+
}
|
|
1571
|
+
if (!ctx.llm || !(0, config_1.isConfigured)(ctx.config)) {
|
|
1572
|
+
console.log(WARN('⚠ LLM not configured. Set ORION_CODE_API_KEY in .env to enable chat.'));
|
|
1573
|
+
console.log();
|
|
1574
|
+
return { success: false };
|
|
1575
|
+
}
|
|
1576
|
+
const activeSession = ctx.getSession?.() ?? ctx.ensureSession?.() ?? (ctx.sessionId ? (0, session_storage_1.loadSessionMeta)(ctx.sessionId) : null);
|
|
1577
|
+
const sessionId = activeSession?.id ?? ctx.sessionId;
|
|
1578
|
+
const runtimeTools = (0, tools_1.getRuntimeTools)();
|
|
1579
|
+
const skillResolution = (0, skills_1.resolveSkillsForTurn)({
|
|
1580
|
+
cwd: ctx.cwd,
|
|
1581
|
+
input,
|
|
1582
|
+
tools: runtimeTools,
|
|
1583
|
+
projectPath: activeSession?.projectPath,
|
|
1584
|
+
sessionId,
|
|
1585
|
+
});
|
|
1586
|
+
const appliedSkillNames = skillResolution.skills.map(skill => skill.name);
|
|
1587
|
+
// Record user message to session
|
|
1588
|
+
if (sessionId) {
|
|
1589
|
+
(0, session_storage_1.appendSessionMessage)(sessionId, {
|
|
1590
|
+
role: 'user',
|
|
1591
|
+
content: input,
|
|
1592
|
+
timestamp: Date.now(),
|
|
1593
|
+
appliedSkills: appliedSkillNames.length > 0 ? appliedSkillNames : undefined,
|
|
1594
|
+
});
|
|
1595
|
+
}
|
|
1596
|
+
ctx.store.addMessage({ role: 'user', content: input });
|
|
1597
|
+
(0, prompt_context_1.refreshProjectInstructions)(ctx.store, ctx.cwd);
|
|
1598
|
+
const snapshot = ctx.store.getSnapshot();
|
|
1599
|
+
const harness = (0, harness_1.createContextHarness)({
|
|
1600
|
+
cwd: ctx.cwd,
|
|
1601
|
+
modelId: ctx.llm.getModel(),
|
|
1602
|
+
state: snapshot.harnessState,
|
|
1603
|
+
config: {
|
|
1604
|
+
enabled: true,
|
|
1605
|
+
driftGuard: 'warn',
|
|
1606
|
+
completionGate: true,
|
|
1607
|
+
},
|
|
1608
|
+
});
|
|
1609
|
+
const intent = harness.updateContractFromUserInput(input);
|
|
1610
|
+
harness.recordAppliedSkills(skillResolution.skills);
|
|
1611
|
+
const promptCtx = {
|
|
1612
|
+
cwd: ctx.cwd,
|
|
1613
|
+
platform: process.platform,
|
|
1614
|
+
nodeVersion: process.version,
|
|
1615
|
+
tools: skillResolution.tools,
|
|
1616
|
+
memoryContent: snapshot.memoryContent,
|
|
1617
|
+
skillsContent: snapshot.skillsContent,
|
|
1618
|
+
projectInstructionsContent: snapshot.projectInstructionsContent,
|
|
1619
|
+
activeSkillsContent: skillResolution.promptInjection,
|
|
1620
|
+
referencedFilesContent: (0, file_context_1.buildReferencedFilesPrompt)(input, ctx.cwd),
|
|
1621
|
+
};
|
|
1622
|
+
const systemPrompt = (0, framework_1.getSystemPrompt)(promptCtx);
|
|
1623
|
+
const spinner = (0, box_1.createSpinner)();
|
|
1624
|
+
const useSpinner = !ui.inlineProgress;
|
|
1625
|
+
if (useSpinner) {
|
|
1626
|
+
spinner.start('Thinking');
|
|
1627
|
+
}
|
|
1628
|
+
let finalContent = '';
|
|
1629
|
+
let finalModel = '';
|
|
1630
|
+
let finalUsage;
|
|
1631
|
+
let responseStarted = false;
|
|
1632
|
+
const sessionMessagesToRecord = [];
|
|
1633
|
+
// Issue #22: 批量工具调用进度显示
|
|
1634
|
+
let toolCallCount = 0;
|
|
1635
|
+
let lastProgressUpdate = 0;
|
|
1636
|
+
// 流式 Markdown 渲染器
|
|
1637
|
+
let streamRenderer = null;
|
|
1638
|
+
// Issue #32 #3.2: toolExecutor 支持 abortSignal
|
|
1639
|
+
const toolExecutor = async (name, args, abortSignal) => {
|
|
1640
|
+
if (!skillResolution.tools.some(tool => tool.name === name)) {
|
|
1641
|
+
return JSON.stringify({
|
|
1642
|
+
success: false,
|
|
1643
|
+
error: skillResolution.toolScopeActive
|
|
1644
|
+
? `Tool ${name} is not available for the active skill scope. Available tools: ${skillResolution.tools.map(tool => tool.name).join(', ') || 'none'}`
|
|
1645
|
+
: `Tool ${name} is not available.`,
|
|
1646
|
+
});
|
|
1647
|
+
}
|
|
1648
|
+
const result = await (0, tools_1.executeTool)(name, args, abortSignal, {
|
|
1649
|
+
cwd: ctx.cwd,
|
|
1650
|
+
config: {
|
|
1651
|
+
name: ctx.config.name,
|
|
1652
|
+
mode: ctx.config.mode,
|
|
1653
|
+
},
|
|
1654
|
+
sessionId,
|
|
1655
|
+
turnId: ctx.turnId,
|
|
1656
|
+
});
|
|
1657
|
+
// 不在这里打印,让 tool_result 事件处理
|
|
1658
|
+
return result;
|
|
1659
|
+
};
|
|
1660
|
+
const streamCallbacks = {
|
|
1661
|
+
onChunk: (chunk) => {
|
|
1662
|
+
if (ctx.abortSignal?.aborted) {
|
|
1663
|
+
return;
|
|
1664
|
+
}
|
|
1665
|
+
if (!responseStarted) {
|
|
1666
|
+
responseStarted = true;
|
|
1667
|
+
spinner.stop();
|
|
1668
|
+
// 打印换行,让流式输出在新行开始
|
|
1669
|
+
writeLine();
|
|
1670
|
+
// 初始化流式渲染器
|
|
1671
|
+
streamRenderer = (0, stream_markdown_1.createStreamRenderer)();
|
|
1672
|
+
}
|
|
1673
|
+
// 使用流式渲染器处理 chunk
|
|
1674
|
+
if (streamRenderer) {
|
|
1675
|
+
const rendered = streamRenderer.feed(chunk);
|
|
1676
|
+
if (rendered) {
|
|
1677
|
+
writeOutput(rendered);
|
|
1678
|
+
}
|
|
1679
|
+
}
|
|
1680
|
+
else {
|
|
1681
|
+
writeOutput(chunk);
|
|
1682
|
+
}
|
|
1683
|
+
},
|
|
1684
|
+
};
|
|
1685
|
+
try {
|
|
1686
|
+
const messages = [{ role: 'system', content: systemPrompt }, ...snapshot.conversationHistory];
|
|
1687
|
+
for await (const event of (0, framework_1.query)({
|
|
1688
|
+
messages,
|
|
1689
|
+
tools: skillResolution.tools,
|
|
1690
|
+
toolExecutor,
|
|
1691
|
+
llm: ctx.llm,
|
|
1692
|
+
streamCallbacks,
|
|
1693
|
+
costTracker: snapshot.costTracker,
|
|
1694
|
+
permissionMode: snapshot.permissionMode,
|
|
1695
|
+
toolConfirmation: ctx.config.toolConfirmation,
|
|
1696
|
+
toolContext: {
|
|
1697
|
+
cwd: ctx.cwd,
|
|
1698
|
+
config: {
|
|
1699
|
+
name: ctx.config.name,
|
|
1700
|
+
mode: ctx.config.mode,
|
|
1701
|
+
},
|
|
1702
|
+
sessionId,
|
|
1703
|
+
turnId: ctx.turnId,
|
|
1704
|
+
},
|
|
1705
|
+
abortSignal: ctx.abortSignal,
|
|
1706
|
+
harness,
|
|
1707
|
+
input,
|
|
1708
|
+
loopBudget: (0, loop_budget_1.resolveRuntimeLoopBudget)(input, ctx.config, harness.toJSON()),
|
|
1709
|
+
})) {
|
|
1710
|
+
switch (event.type) {
|
|
1711
|
+
case 'request_start':
|
|
1712
|
+
// 停止 spinner,等待 LLM 响应
|
|
1713
|
+
spinner.stop();
|
|
1714
|
+
writeLine();
|
|
1715
|
+
writeLine(DIM((0, agent_status_1.agentStepStatus)(event.turn)));
|
|
1716
|
+
// 重置流式渲染器
|
|
1717
|
+
streamRenderer = (0, stream_markdown_1.createStreamRenderer)();
|
|
1718
|
+
// Issue #22: 重置工具调用计数器
|
|
1719
|
+
toolCallCount = 0;
|
|
1720
|
+
lastProgressUpdate = 0;
|
|
1721
|
+
break;
|
|
1722
|
+
case 'assistant_tool_calls':
|
|
1723
|
+
if (event.toolCalls.length > 1) {
|
|
1724
|
+
writeLine(DIM((0, agent_status_1.runningToolsStatus)(event.toolCalls.length)));
|
|
1725
|
+
}
|
|
1726
|
+
sessionMessagesToRecord.push({
|
|
1727
|
+
role: 'assistant',
|
|
1728
|
+
content: event.content || '',
|
|
1729
|
+
timestamp: Date.now(),
|
|
1730
|
+
tool_calls: event.toolCalls,
|
|
1731
|
+
});
|
|
1732
|
+
break;
|
|
1733
|
+
case 'tool_call':
|
|
1734
|
+
// Issue #22: 批量工具调用进度显示
|
|
1735
|
+
toolCallCount++;
|
|
1736
|
+
if (toolCallCount >= 3 && Date.now() - lastProgressUpdate > 1000) {
|
|
1737
|
+
(0, progress_1.showToolProgress)(toolCallCount, event.name);
|
|
1738
|
+
lastProgressUpdate = Date.now();
|
|
1739
|
+
}
|
|
1740
|
+
break;
|
|
1741
|
+
case 'tool_result':
|
|
1742
|
+
// Issue #22: 隐藏进度指示
|
|
1743
|
+
(0, progress_1.hideProgress)();
|
|
1744
|
+
// 显示工具结果后,准备下一轮(不启动 spinner)
|
|
1745
|
+
writeLine(event.summary || (0, box_1.toolLine)(event.name, event.args, event.success, event.duration));
|
|
1746
|
+
// 显示错误详情
|
|
1747
|
+
if (!event.success && event.error) {
|
|
1748
|
+
writeLine(ERROR(` Error: ${event.error}`));
|
|
1749
|
+
}
|
|
1750
|
+
// Debug: 显示接收到的参数
|
|
1751
|
+
if (!event.success && Object.keys(event.args).length === 0) {
|
|
1752
|
+
writeLine(WARN(` ⚠ Tool received empty arguments - LLM may not be providing parameters correctly`));
|
|
1753
|
+
writeLine(DIM(` Try using /model qwen or /model gpt4o for better tool calling support`));
|
|
1754
|
+
}
|
|
1755
|
+
// Record tool result for session
|
|
1756
|
+
sessionMessagesToRecord.push({
|
|
1757
|
+
role: 'tool',
|
|
1758
|
+
content: event.result,
|
|
1759
|
+
modelVisibleContent: event.modelVisibleResult,
|
|
1760
|
+
timestamp: Date.now(),
|
|
1761
|
+
toolCallId: event.callId,
|
|
1762
|
+
});
|
|
1763
|
+
break;
|
|
1764
|
+
case 'message':
|
|
1765
|
+
if (event.content) {
|
|
1766
|
+
sessionMessagesToRecord.push({
|
|
1767
|
+
role: 'assistant',
|
|
1768
|
+
content: event.content,
|
|
1769
|
+
timestamp: Date.now(),
|
|
1770
|
+
});
|
|
1771
|
+
}
|
|
1772
|
+
break;
|
|
1773
|
+
case 'strategy_exhausted':
|
|
1774
|
+
writeLine(WARN(`⚠ ${event.suggestion}`));
|
|
1775
|
+
break;
|
|
1776
|
+
case 'complete':
|
|
1777
|
+
finalContent = event.content;
|
|
1778
|
+
finalModel = event.model;
|
|
1779
|
+
finalUsage = event.usage;
|
|
1780
|
+
if (event.stats) {
|
|
1781
|
+
ctx.store.setLastLoopStats(event.stats);
|
|
1782
|
+
}
|
|
1783
|
+
break;
|
|
1784
|
+
}
|
|
1785
|
+
}
|
|
1786
|
+
// 刷新流式渲染器,输出剩余内容
|
|
1787
|
+
if (streamRenderer) {
|
|
1788
|
+
const remaining = streamRenderer.flush();
|
|
1789
|
+
if (remaining) {
|
|
1790
|
+
writeOutput(remaining);
|
|
1791
|
+
}
|
|
1792
|
+
streamRenderer = null;
|
|
1793
|
+
}
|
|
1794
|
+
const wasAborted = ctx.abortSignal?.aborted === true;
|
|
1795
|
+
if (finalContent && !wasAborted) {
|
|
1796
|
+
ctx.store.addMessage({ role: 'assistant', content: finalContent });
|
|
1797
|
+
}
|
|
1798
|
+
if (sessionId && sessionMessagesToRecord.length > 0 && !wasAborted) {
|
|
1799
|
+
(0, session_storage_1.appendSessionMessages)(sessionId, sessionMessagesToRecord);
|
|
1800
|
+
}
|
|
1801
|
+
if (finalUsage && !wasAborted) {
|
|
1802
|
+
ctx.store.setTokenUsage(finalUsage);
|
|
1803
|
+
}
|
|
1804
|
+
if (!wasAborted) {
|
|
1805
|
+
harness.ingestTurn({
|
|
1806
|
+
userInput: input,
|
|
1807
|
+
assistantContent: finalContent,
|
|
1808
|
+
sessionMessages: sessionMessagesToRecord,
|
|
1809
|
+
intent,
|
|
1810
|
+
});
|
|
1811
|
+
const harnessState = harness.toJSON();
|
|
1812
|
+
ctx.store.setState({ harnessState });
|
|
1813
|
+
if (sessionId) {
|
|
1814
|
+
(0, session_storage_1.updateSessionSkills)(sessionId, appliedSkillNames);
|
|
1815
|
+
(0, session_storage_1.updateSessionHarnessState)(sessionId, harnessState);
|
|
1816
|
+
const recordedMessages = (0, session_storage_1.readSessionMessages)(sessionId);
|
|
1817
|
+
if (recordedMessages.length > 0) {
|
|
1818
|
+
(0, session_storage_1.updateSessionSummary)(sessionId, recordedMessages);
|
|
1819
|
+
}
|
|
1820
|
+
}
|
|
1821
|
+
}
|
|
1822
|
+
if (responseStarted) {
|
|
1823
|
+
writeLine();
|
|
1824
|
+
if (ui.extraAssistantSpacing) {
|
|
1825
|
+
writeLine();
|
|
1826
|
+
}
|
|
1827
|
+
}
|
|
1828
|
+
if (!ui.suppressLegacyTokenMeta) {
|
|
1829
|
+
const stats = [
|
|
1830
|
+
finalUsage ? `tokens: ${finalUsage.promptTokens}+${finalUsage.completionTokens}` : '',
|
|
1831
|
+
finalModel ? finalModel : '',
|
|
1832
|
+
].filter(Boolean).join(' ');
|
|
1833
|
+
if (stats) {
|
|
1834
|
+
writeLine(DIM(stats));
|
|
1835
|
+
}
|
|
1836
|
+
}
|
|
1837
|
+
}
|
|
1838
|
+
catch (error) {
|
|
1839
|
+
spinner.stop();
|
|
1840
|
+
writeLine();
|
|
1841
|
+
if (isAbortError(error, ctx.abortSignal)) {
|
|
1842
|
+
(0, progress_1.hideProgress)();
|
|
1843
|
+
if (!ui.suppressAbortNotice) {
|
|
1844
|
+
writeLine(DIM('Interrupted.'));
|
|
1845
|
+
}
|
|
1846
|
+
}
|
|
1847
|
+
else {
|
|
1848
|
+
writeLine(ERROR(`✗ ${error.message || String(error)}`));
|
|
1849
|
+
const hist = ctx.store.getSnapshot().conversationHistory;
|
|
1850
|
+
if (hist.length > 0) {
|
|
1851
|
+
ctx.store.setState({ conversationHistory: hist.slice(0, -1) });
|
|
1852
|
+
}
|
|
1853
|
+
}
|
|
1854
|
+
}
|
|
1855
|
+
return { success: true };
|
|
1856
|
+
}
|
|
1857
|
+
async function handleExit(ctx) {
|
|
1858
|
+
console.log();
|
|
1859
|
+
console.log(DIM('Shutting down...'));
|
|
1860
|
+
// Update session summary before exit
|
|
1861
|
+
if (ctx.sessionId) {
|
|
1862
|
+
const messages = (0, session_storage_1.readSessionMessages)(ctx.sessionId);
|
|
1863
|
+
if (messages.length > 0) {
|
|
1864
|
+
(0, session_storage_1.updateSessionSummary)(ctx.sessionId, messages);
|
|
1865
|
+
}
|
|
1866
|
+
(0, session_storage_1.endSession)(ctx.sessionId);
|
|
1867
|
+
}
|
|
1868
|
+
await ctx.runtime.shutdown();
|
|
1869
|
+
console.log(SUCCESS('Goodbye! 🐴'));
|
|
1870
|
+
process.exit(0);
|
|
1871
|
+
}
|
|
1872
|
+
function handleCost(ctx) {
|
|
1873
|
+
console.log();
|
|
1874
|
+
console.log(HEADER('Lifetime Cost'));
|
|
1875
|
+
console.log(DIM('─'.repeat(40)));
|
|
1876
|
+
const costTracker = ctx.store.getSnapshot().costTracker;
|
|
1877
|
+
const state = (0, usage_state_1.loadUsageState)();
|
|
1878
|
+
const ledger = (0, usage_state_1.summarizeUsageLedger)();
|
|
1879
|
+
if (state.totalTokens === 0 && state.totalCost === 0) {
|
|
1880
|
+
console.log(DIM(' No usage recorded yet.'));
|
|
1881
|
+
console.log(DIM(' Use /run or /chat to interact with LLM.'));
|
|
1882
|
+
console.log();
|
|
1883
|
+
return { success: true };
|
|
1884
|
+
}
|
|
1885
|
+
// Summary
|
|
1886
|
+
console.log();
|
|
1887
|
+
console.log(` ${ACCENT('Total Tokens')} ${state.totalTokens.toLocaleString()}`);
|
|
1888
|
+
console.log(` ${ACCENT('Tracked Cost')} ${costTracker.formatCost(state.totalCost)}`);
|
|
1889
|
+
console.log(` ${ACCENT('Provider Cost')} ${costTracker.formatCost(state.providerCost)}`);
|
|
1890
|
+
console.log(` ${ACCENT('Estimated Cost')} ${costTracker.formatCost(state.estimatedCost)}`);
|
|
1891
|
+
console.log(` ${ACCENT('Requests')} ${state.usageRecords.toLocaleString()}`);
|
|
1892
|
+
console.log(` ${ACCENT('Sessions')} ${state.totalSessions.toLocaleString()}`);
|
|
1893
|
+
// By Model
|
|
1894
|
+
if (Object.keys(ledger.byModel).length > 0) {
|
|
1895
|
+
console.log();
|
|
1896
|
+
console.log(HEADER(' By Model:'));
|
|
1897
|
+
for (const [model, data] of Object.entries(ledger.byModel)) {
|
|
1898
|
+
console.log(` ${BRAND(model.padEnd(20))} ${data.tokens} tokens, ${costTracker.formatCost(data.cost)}`);
|
|
1899
|
+
}
|
|
1900
|
+
}
|
|
1901
|
+
console.log();
|
|
1902
|
+
console.log(HEADER(' Cost Sources:'));
|
|
1903
|
+
for (const source of ['provider', 'configured', 'builtin', 'fallback']) {
|
|
1904
|
+
const data = ledger.bySource[source];
|
|
1905
|
+
if (data.count === 0)
|
|
1906
|
+
continue;
|
|
1907
|
+
console.log(` ${source.padEnd(12)} ${data.count} requests, ${costTracker.formatCost(data.cost)}`);
|
|
1908
|
+
}
|
|
1909
|
+
if (state.baselineCost > 0 || state.baselineTokens > 0) {
|
|
1910
|
+
console.log(DIM(` legacy ${state.baselineTokens.toLocaleString()} tokens, ${costTracker.formatCost(state.baselineCost)}`));
|
|
1911
|
+
}
|
|
1912
|
+
if (ledger.bySource.fallback.count > 0) {
|
|
1913
|
+
console.log();
|
|
1914
|
+
console.log(WARN(' Unknown-model fallback pricing is an estimate.'));
|
|
1915
|
+
console.log(DIM(' Configure cost.modelPricing in ~/.orion-code/orion.json for accuracy.'));
|
|
1916
|
+
}
|
|
1917
|
+
// Budget
|
|
1918
|
+
const budget = costTracker.getBudget();
|
|
1919
|
+
if (budget !== null) {
|
|
1920
|
+
const check = costTracker.checkBudget();
|
|
1921
|
+
console.log();
|
|
1922
|
+
console.log(HEADER(' Budget:'));
|
|
1923
|
+
console.log(` ${ACCENT('Limit')} ${costTracker.formatCost(budget)}`);
|
|
1924
|
+
console.log(` ${ACCENT('Used this run')} ${costTracker.formatCost(check.used)}`);
|
|
1925
|
+
console.log(` ${check.ok ? SUCCESS('✓ Within budget') : WARN('⚠ Budget exceeded')}`);
|
|
1926
|
+
}
|
|
1927
|
+
console.log();
|
|
1928
|
+
return { success: true };
|
|
1929
|
+
}
|
|
1930
|
+
function handleSkills(_ctx) {
|
|
1931
|
+
console.log();
|
|
1932
|
+
console.log(HEADER('Loaded Skills'));
|
|
1933
|
+
console.log(DIM('─'.repeat(40)));
|
|
1934
|
+
try {
|
|
1935
|
+
const registry = (0, skills_1.getSkillsRegistry)();
|
|
1936
|
+
const summary = registry.getSummary();
|
|
1937
|
+
if (summary.count === 0) {
|
|
1938
|
+
console.log();
|
|
1939
|
+
console.log(DIM(' No skills loaded.'));
|
|
1940
|
+
console.log(DIM(' Place SKILL.md files in ~/.orion-code/skills/<name>/ or .orion-code/skills/<name>/'));
|
|
1941
|
+
console.log();
|
|
1942
|
+
return { success: true };
|
|
1943
|
+
}
|
|
1944
|
+
console.log();
|
|
1945
|
+
console.log(` Total ${SUCCESS(summary.count)} skills (${WARN(summary.autoCount)} auto-trigger)`);
|
|
1946
|
+
console.log();
|
|
1947
|
+
for (const skill of registry.getAllSkills()) {
|
|
1948
|
+
const source = registry.getSource(skill.name);
|
|
1949
|
+
const sourceType = source?.type || 'unknown';
|
|
1950
|
+
const resourceRoot = skill.resourceRoot || skill.source || source?.path;
|
|
1951
|
+
const skillFile = resourceRoot
|
|
1952
|
+
? `${resourceRoot.replace(/\/SKILL\.md$/i, '')}/SKILL.md`
|
|
1953
|
+
: source?.skillFile;
|
|
1954
|
+
console.log(` ${ACCENT(skill.name)} ${DIM(`(${sourceType})`)}`);
|
|
1955
|
+
console.log(` ${DIM(skill.description || '(no description)')}`);
|
|
1956
|
+
if (skillFile)
|
|
1957
|
+
console.log(` ${DIM(`SKILL.md ${skillFile}`)}`);
|
|
1958
|
+
if (resourceRoot)
|
|
1959
|
+
console.log(` ${DIM(`Root ${resourceRoot}`)}`);
|
|
1960
|
+
}
|
|
1961
|
+
console.log();
|
|
1962
|
+
}
|
|
1963
|
+
catch (err) {
|
|
1964
|
+
console.log(ERROR(`✗ ${err.message}`));
|
|
1965
|
+
return { success: false };
|
|
1966
|
+
}
|
|
1967
|
+
return { success: true };
|
|
1968
|
+
}
|
|
1969
|
+
function handleSkill(ctx, args) {
|
|
1970
|
+
const trimmed = args.trim();
|
|
1971
|
+
const registry = (0, skills_1.getSkillsRegistry)();
|
|
1972
|
+
registry.initialize();
|
|
1973
|
+
if (!trimmed) {
|
|
1974
|
+
const names = registry.getAllSkills().map(skill => skill.name).sort();
|
|
1975
|
+
return {
|
|
1976
|
+
success: false,
|
|
1977
|
+
error: [
|
|
1978
|
+
'Usage: /skill <name> <task>',
|
|
1979
|
+
`Loaded skills: ${names.join(', ') || 'none'}`,
|
|
1980
|
+
].join('\n'),
|
|
1981
|
+
};
|
|
1982
|
+
}
|
|
1983
|
+
const parsed = (0, skills_1.parseSkillCommandInput)(`/skill ${trimmed}`);
|
|
1984
|
+
const rawName = trimmed.split(/\s+/, 1)[0] || '';
|
|
1985
|
+
const requestedName = parsed.skillName || (0, skills_1.normalizeRequestedSkillName)(rawName);
|
|
1986
|
+
const referencedSkill = (0, skills_1.loadExplicitSkillReference)(`/skill ${trimmed}`, ctx.cwd);
|
|
1987
|
+
if (parsed.skillPath && !referencedSkill) {
|
|
1988
|
+
return {
|
|
1989
|
+
success: false,
|
|
1990
|
+
error: `Invalid skill reference: ${parsed.skillPath}`,
|
|
1991
|
+
};
|
|
1992
|
+
}
|
|
1993
|
+
const skill = referencedSkill || registry.getAllSkills()
|
|
1994
|
+
.find(candidate => (0, skills_1.skillActivationNames)(candidate)
|
|
1995
|
+
.some(name => (0, skills_1.normalizeRequestedSkillName)(name) === requestedName));
|
|
1996
|
+
if (!skill) {
|
|
1997
|
+
const suggestions = registry.getAllSkills()
|
|
1998
|
+
.map(candidate => candidate.name)
|
|
1999
|
+
.filter(name => name.includes(requestedName) || requestedName.includes(name))
|
|
2000
|
+
.slice(0, 5);
|
|
2001
|
+
return {
|
|
2002
|
+
success: false,
|
|
2003
|
+
error: suggestions.length > 0
|
|
2004
|
+
? `Unknown skill: ${rawName}\nDid you mean: ${suggestions.join(', ')}?`
|
|
2005
|
+
: `Unknown skill: ${rawName}`,
|
|
2006
|
+
};
|
|
2007
|
+
}
|
|
2008
|
+
const task = parsed.task;
|
|
2009
|
+
const source = registry.getSource(skill.name);
|
|
2010
|
+
const resourceRoot = skill.resourceRoot || skill.source || source?.path;
|
|
2011
|
+
const skillFile = resourceRoot
|
|
2012
|
+
? `${resourceRoot.replace(/\/SKILL\.md$/i, '')}/SKILL.md`
|
|
2013
|
+
: source?.skillFile;
|
|
2014
|
+
if (!task) {
|
|
2015
|
+
const usageSelector = parsed.skillPath
|
|
2016
|
+
? `[$${skill.name}](${formatSkillReferencePath(parsed.skillPath)})`
|
|
2017
|
+
: skill.name;
|
|
2018
|
+
return {
|
|
2019
|
+
success: true,
|
|
2020
|
+
output: [
|
|
2021
|
+
parsed.skillPath
|
|
2022
|
+
? `Skill reference ${skill.name} is valid for one turn.`
|
|
2023
|
+
: `Skill ${skill.name} is loaded.`,
|
|
2024
|
+
skillFile ? `SKILL.md ${skillFile}` : '',
|
|
2025
|
+
resourceRoot ? `Root ${resourceRoot}` : '',
|
|
2026
|
+
`Use: /skill ${usageSelector} <task>`,
|
|
2027
|
+
].filter(Boolean).join('\n'),
|
|
2028
|
+
};
|
|
2029
|
+
}
|
|
2030
|
+
return {
|
|
2031
|
+
success: true,
|
|
2032
|
+
continueAsChat: true,
|
|
2033
|
+
chatInput: parsed.skillPath
|
|
2034
|
+
? `/skill [$${skill.name}](${formatSkillReferencePath(parsed.skillPath)}) ${task}`
|
|
2035
|
+
: `/skill ${skill.name} ${task}`,
|
|
2036
|
+
};
|
|
2037
|
+
}
|
|
2038
|
+
function formatSkillReferencePath(path) {
|
|
2039
|
+
return /[\s()]/u.test(path) ? `<${path}>` : path;
|
|
2040
|
+
}
|
|
2041
|
+
function handleMcp(_ctx) {
|
|
2042
|
+
console.log();
|
|
2043
|
+
console.log(HEADER('MCP Servers'));
|
|
2044
|
+
console.log(DIM('─'.repeat(40)));
|
|
2045
|
+
const status = mcp_1.mcpManager.getStatus();
|
|
2046
|
+
if (status.length === 0) {
|
|
2047
|
+
console.log();
|
|
2048
|
+
console.log(DIM(' No servers configured. Add to ~/.orion-code/mcp.json'));
|
|
2049
|
+
console.log();
|
|
2050
|
+
return { success: true };
|
|
2051
|
+
}
|
|
2052
|
+
console.log();
|
|
2053
|
+
for (const s of status) {
|
|
2054
|
+
const stateLabel = s.dead
|
|
2055
|
+
? ERROR('dead')
|
|
2056
|
+
: s.connected
|
|
2057
|
+
? SUCCESS('connected')
|
|
2058
|
+
: WARN('disconnected');
|
|
2059
|
+
console.log(` ${ACCENT(s.name.padEnd(20))} ${stateLabel} ${DIM(`${s.toolCount} tools`)}`);
|
|
2060
|
+
}
|
|
2061
|
+
console.log();
|
|
2062
|
+
return { success: true };
|
|
2063
|
+
}
|
|
2064
|
+
function handleDoctor(ctx) {
|
|
2065
|
+
const report = (0, doctor_1.collectDoctorReport)(ctx);
|
|
2066
|
+
console.log();
|
|
2067
|
+
console.log((0, doctor_1.formatDoctorReport)(report));
|
|
2068
|
+
console.log();
|
|
2069
|
+
return { success: !(0, doctor_1.hasDoctorFailures)(report) };
|
|
2070
|
+
}
|
|
2071
|
+
function handleStorage(_ctx, args) {
|
|
2072
|
+
const trimmed = args.trim();
|
|
2073
|
+
const [action = 'doctor'] = trimmed.split(/\s+/);
|
|
2074
|
+
if (action === 'cleanup') {
|
|
2075
|
+
const dryRun = /\b--dry-run\b/.test(trimmed);
|
|
2076
|
+
const result = (0, storage_maintenance_1.cleanupStorage)({ dryRun });
|
|
2077
|
+
console.log();
|
|
2078
|
+
console.log((0, storage_maintenance_1.formatStorageCleanupResult)(result));
|
|
2079
|
+
console.log();
|
|
2080
|
+
return { success: true };
|
|
2081
|
+
}
|
|
2082
|
+
if (action === 'repair') {
|
|
2083
|
+
const result = (0, storage_maintenance_1.repairProjectMetadata)();
|
|
2084
|
+
console.log();
|
|
2085
|
+
console.log(HEADER('Orion Code Storage Repair'));
|
|
2086
|
+
console.log(DIM('─'.repeat(40)));
|
|
2087
|
+
console.log(` Repaired ${ACCENT(String(result.repaired.length))}`);
|
|
2088
|
+
console.log(` Skipped ${DIM(String(result.skipped.length))}`);
|
|
2089
|
+
for (const project of result.repaired.slice(0, 12)) {
|
|
2090
|
+
console.log(` ${SUCCESS('✓')} ${DIM(project)}`);
|
|
2091
|
+
}
|
|
2092
|
+
if (result.repaired.length > 12) {
|
|
2093
|
+
console.log(DIM(` ... ${result.repaired.length - 12} more`));
|
|
2094
|
+
}
|
|
2095
|
+
console.log();
|
|
2096
|
+
return { success: true };
|
|
2097
|
+
}
|
|
2098
|
+
if (action !== 'doctor' && action !== 'status') {
|
|
2099
|
+
return {
|
|
2100
|
+
success: false,
|
|
2101
|
+
error: 'Usage: /storage [doctor|status|repair|cleanup --dry-run]',
|
|
2102
|
+
};
|
|
2103
|
+
}
|
|
2104
|
+
const report = (0, storage_maintenance_1.collectStorageReport)();
|
|
2105
|
+
console.log();
|
|
2106
|
+
console.log((0, storage_maintenance_1.formatStorageReport)(report));
|
|
2107
|
+
console.log();
|
|
2108
|
+
return { success: true };
|
|
2109
|
+
}
|
|
2110
|
+
function handleTarget(ctx, args) {
|
|
2111
|
+
const trimmed = args.trim();
|
|
2112
|
+
// GoalCoordinator needs projectPath + sessionId — derive from context
|
|
2113
|
+
const projectPath = ctx.cwd ?? process.cwd();
|
|
2114
|
+
const sessionId = ctx.sessionId ?? 'default';
|
|
2115
|
+
const coordinator = new coordinator_1.GoalCoordinator(projectPath, sessionId);
|
|
2116
|
+
// /target (no args) — show current goal
|
|
2117
|
+
if (!trimmed) {
|
|
2118
|
+
const snap = coordinator.snapshot();
|
|
2119
|
+
if (!snap) {
|
|
2120
|
+
console.log(chalk_1.default.gray('No goal is currently set. Use /target <objective> to create one.'));
|
|
2121
|
+
return { success: true };
|
|
2122
|
+
}
|
|
2123
|
+
console.log(chalk_1.default.bold('Goal: ') + snap.objective);
|
|
2124
|
+
console.log(chalk_1.default.gray(`Status: ${snap.status} | Continuations: ${snap.continuationCount}`));
|
|
2125
|
+
console.log(chalk_1.default.gray(`Tokens: ${snap.tokensUsed} | Time: ${snap.timeUsedMs}ms`));
|
|
2126
|
+
return { success: true };
|
|
2127
|
+
}
|
|
2128
|
+
// Sub-commands
|
|
2129
|
+
const subCommand = trimmed.split(/\s+/)[0].toLowerCase();
|
|
2130
|
+
const rest = trimmed.slice(subCommand.length).trim();
|
|
2131
|
+
switch (subCommand) {
|
|
2132
|
+
case 'pause': {
|
|
2133
|
+
const ok = coordinator.pause();
|
|
2134
|
+
console.log(ok ? chalk_1.default.yellow('Goal paused.') : chalk_1.default.red('Cannot pause.'));
|
|
2135
|
+
return { success: ok };
|
|
2136
|
+
}
|
|
2137
|
+
case 'resume': {
|
|
2138
|
+
const ok = coordinator.resume();
|
|
2139
|
+
console.log(ok ? chalk_1.default.green('Goal resumed.') : chalk_1.default.red('Cannot resume.'));
|
|
2140
|
+
return { success: ok };
|
|
2141
|
+
}
|
|
2142
|
+
case 'clear': {
|
|
2143
|
+
const ok = coordinator.clear();
|
|
2144
|
+
console.log(ok ? chalk_1.default.gray('Goal cleared.') : chalk_1.default.gray('No goal to clear.'));
|
|
2145
|
+
return { success: ok };
|
|
2146
|
+
}
|
|
2147
|
+
case 'status': {
|
|
2148
|
+
const snap = coordinator.snapshot();
|
|
2149
|
+
if (!snap) {
|
|
2150
|
+
console.log(chalk_1.default.gray('No goal set.'));
|
|
2151
|
+
return { success: true };
|
|
2152
|
+
}
|
|
2153
|
+
console.log(chalk_1.default.bold(`Status: ${snap.status}`));
|
|
2154
|
+
console.log(`Objective: ${snap.objective}`);
|
|
2155
|
+
console.log(`Continuations: ${snap.continuationCount} | Tokens: ${snap.tokensUsed}`);
|
|
2156
|
+
return { success: true };
|
|
2157
|
+
}
|
|
2158
|
+
case 'edit': {
|
|
2159
|
+
if (!rest) {
|
|
2160
|
+
console.log(chalk_1.default.red('Usage: /target edit <new objective text>'));
|
|
2161
|
+
return { success: false };
|
|
2162
|
+
}
|
|
2163
|
+
const ok = coordinator.edit(rest);
|
|
2164
|
+
console.log(ok ? chalk_1.default.green('Goal objective updated.') : chalk_1.default.red('Cannot edit.'));
|
|
2165
|
+
return { success: ok };
|
|
2166
|
+
}
|
|
2167
|
+
case 'replace': {
|
|
2168
|
+
if (!rest) {
|
|
2169
|
+
console.log(chalk_1.default.red('Usage: /target replace <new objective text>'));
|
|
2170
|
+
return { success: false };
|
|
2171
|
+
}
|
|
2172
|
+
const ok = coordinator.replace(rest);
|
|
2173
|
+
console.log(ok ? chalk_1.default.green('Goal replaced.') : chalk_1.default.red('Cannot replace.'));
|
|
2174
|
+
return { success: ok };
|
|
2175
|
+
}
|
|
2176
|
+
default: {
|
|
2177
|
+
// Treat as new objective
|
|
2178
|
+
const result = coordinator.create(trimmed);
|
|
2179
|
+
console.log(result.ok ? chalk_1.default.green('Goal created: ') + trimmed : chalk_1.default.red(result.error ?? 'Failed'));
|
|
2180
|
+
return { success: result.ok };
|
|
2181
|
+
}
|
|
2182
|
+
}
|
|
2183
|
+
}
|
|
2184
|
+
function handleDiff(ctx, args) {
|
|
2185
|
+
const maxFilesMatch = args.match(/--max-files(?:=|\s+)(\d+)/);
|
|
2186
|
+
const maxFiles = maxFilesMatch ? Number(maxFilesMatch[1]) : 40;
|
|
2187
|
+
const report = (0, workspace_diff_1.collectWorkspaceDiff)({ cwd: ctx.cwd, maxFiles });
|
|
2188
|
+
console.log();
|
|
2189
|
+
console.log((0, workspace_diff_1.formatWorkspaceDiff)(report, { maxFiles }));
|
|
2190
|
+
console.log();
|
|
2191
|
+
return { success: report.isGitRepo };
|
|
2192
|
+
}
|
|
2193
|
+
function handleCommitPlan(ctx, args) {
|
|
2194
|
+
const maxFilesMatch = args.match(/--max-files(?:=|\s+)(\d+)/);
|
|
2195
|
+
const maxFiles = maxFilesMatch ? Number(maxFilesMatch[1]) : 20;
|
|
2196
|
+
const plan = (0, commit_plan_1.createCommitPlan)({ cwd: ctx.cwd, maxFiles });
|
|
2197
|
+
console.log();
|
|
2198
|
+
console.log((0, commit_plan_1.formatCommitPlan)(plan));
|
|
2199
|
+
console.log();
|
|
2200
|
+
return { success: plan.diff.isGitRepo };
|
|
2201
|
+
}
|
|
2202
|
+
function handleTools(ctx) {
|
|
2203
|
+
const tools = ctx.store.getSnapshot().tools.length > 0
|
|
2204
|
+
? ctx.store.getSnapshot().tools
|
|
2205
|
+
: (0, tools_1.getRuntimeTools)();
|
|
2206
|
+
const staticTools = tools.filter(tool => !tool.name.startsWith('mcp__'));
|
|
2207
|
+
const mcpTools = tools.filter(tool => tool.name.startsWith('mcp__'));
|
|
2208
|
+
console.log();
|
|
2209
|
+
console.log(HEADER('Available Tools'));
|
|
2210
|
+
console.log(DIM('─'.repeat(40)));
|
|
2211
|
+
console.log(` Static tools ${ACCENT(String(staticTools.length))}`);
|
|
2212
|
+
console.log(` MCP tools ${ACCENT(String(mcpTools.length))}`);
|
|
2213
|
+
console.log();
|
|
2214
|
+
const visible = [...staticTools, ...mcpTools].slice(0, 28);
|
|
2215
|
+
for (const tool of visible) {
|
|
2216
|
+
const label = tool.name.startsWith('mcp__') ? 'mcp' : 'tool';
|
|
2217
|
+
console.log(` ${ACCENT(tool.name)} ${DIM(`[${label}]`)}`);
|
|
2218
|
+
console.log(` ${DIM(tool.description.slice(0, 96))}`);
|
|
2219
|
+
}
|
|
2220
|
+
if (tools.length > visible.length) {
|
|
2221
|
+
console.log();
|
|
2222
|
+
console.log(DIM(` ... ${tools.length - visible.length} more tools hidden`));
|
|
2223
|
+
}
|
|
2224
|
+
console.log();
|
|
2225
|
+
return { success: true };
|
|
2226
|
+
}
|
|
2227
|
+
function handleTodos(ctx) {
|
|
2228
|
+
const todos = ctx.store.getSnapshot().todos;
|
|
2229
|
+
console.log();
|
|
2230
|
+
console.log(HEADER('Todos'));
|
|
2231
|
+
console.log(DIM('─'.repeat(40)));
|
|
2232
|
+
if (todos.length === 0) {
|
|
2233
|
+
console.log(DIM(' No active todos yet.'));
|
|
2234
|
+
console.log();
|
|
2235
|
+
return { success: true };
|
|
2236
|
+
}
|
|
2237
|
+
for (const todo of todos) {
|
|
2238
|
+
const marker = todo.status === 'completed' ? SUCCESS('✓')
|
|
2239
|
+
: todo.status === 'in_progress' ? WARN('›')
|
|
2240
|
+
: DIM('○');
|
|
2241
|
+
console.log(` ${marker} ${todo.content}`);
|
|
2242
|
+
if (todo.activeForm && todo.activeForm !== todo.content) {
|
|
2243
|
+
console.log(` ${DIM(todo.activeForm)}`);
|
|
2244
|
+
}
|
|
2245
|
+
}
|
|
2246
|
+
console.log();
|
|
2247
|
+
return { success: true };
|
|
2248
|
+
}
|
|
2249
|
+
function handleClearHistory(ctx) {
|
|
2250
|
+
const history = ctx.store.getSnapshot().conversationHistory;
|
|
2251
|
+
if (history.length === 0) {
|
|
2252
|
+
console.log(DIM('Conversation history is already empty'));
|
|
2253
|
+
console.log();
|
|
2254
|
+
return { success: true };
|
|
2255
|
+
}
|
|
2256
|
+
ctx.store.resetConversation();
|
|
2257
|
+
(0, framework_1.resetToolState)();
|
|
2258
|
+
console.log(SUCCESS(`✔ Cleared ${history.length} messages from conversation history`));
|
|
2259
|
+
console.log(DIM(' Configuration and system state preserved'));
|
|
2260
|
+
console.log();
|
|
2261
|
+
return { success: true };
|
|
2262
|
+
}
|
|
2263
|
+
async function handleCompact(ctx, args) {
|
|
2264
|
+
const history = ctx.store.getSnapshot().conversationHistory;
|
|
2265
|
+
if (history.length === 0) {
|
|
2266
|
+
console.log(DIM('Conversation history is empty, nothing to compact'));
|
|
2267
|
+
console.log();
|
|
2268
|
+
return { success: true };
|
|
2269
|
+
}
|
|
2270
|
+
// 解析参数
|
|
2271
|
+
const thresholdArg = parseInt(args.trim(), 10);
|
|
2272
|
+
const threshold = thresholdArg > 0 ? thresholdArg : 50;
|
|
2273
|
+
console.log();
|
|
2274
|
+
console.log(HEADER('Compacting Conversation'));
|
|
2275
|
+
console.log(DIM('─'.repeat(40)));
|
|
2276
|
+
console.log(` Current messages: ${history.length}`);
|
|
2277
|
+
console.log(` Threshold: ${threshold}`);
|
|
2278
|
+
console.log();
|
|
2279
|
+
if (history.length <= threshold) {
|
|
2280
|
+
console.log(DIM(`Conversation has ${history.length} messages, below compact threshold ${threshold}.`));
|
|
2281
|
+
console.log(DIM('Nothing compacted.'));
|
|
2282
|
+
console.log();
|
|
2283
|
+
return { success: true };
|
|
2284
|
+
}
|
|
2285
|
+
console.log(DIM((0, agent_status_1.compactStatus)()));
|
|
2286
|
+
try {
|
|
2287
|
+
const modelId = ctx.llm?.getModel() ?? ctx.store.getSnapshot().currentModel;
|
|
2288
|
+
const coordinator = ctx.compactCoordinator ?? new coordinator_2.CompactCoordinator({
|
|
2289
|
+
modelId,
|
|
2290
|
+
llm: ctx.llm,
|
|
2291
|
+
outputReserveTokens: ctx.llm?.getMaxTokens?.(),
|
|
2292
|
+
getContextCapsule: () => ctx.store.getSnapshot().harnessState?.capsule,
|
|
2293
|
+
getHarnessState: () => ctx.store.getSnapshot().harnessState,
|
|
2294
|
+
});
|
|
2295
|
+
coordinator.configure({
|
|
2296
|
+
modelId,
|
|
2297
|
+
llm: ctx.llm,
|
|
2298
|
+
outputReserveTokens: ctx.llm?.getMaxTokens?.(),
|
|
2299
|
+
getContextCapsule: () => ctx.store.getSnapshot().harnessState?.capsule,
|
|
2300
|
+
getHarnessState: () => ctx.store.getSnapshot().harnessState,
|
|
2301
|
+
});
|
|
2302
|
+
const beforeTokens = (0, token_estimate_1.estimateMessagesTokens)(history);
|
|
2303
|
+
const automaticStats = coordinator.getAutomatic().getStats();
|
|
2304
|
+
const beforeUsage = (0, model_context_1.createContextUsageSnapshot)({
|
|
2305
|
+
modelId,
|
|
2306
|
+
usedTokens: beforeTokens,
|
|
2307
|
+
source: 'estimated',
|
|
2308
|
+
outputReserveTokens: ctx.llm?.getMaxTokens?.(),
|
|
2309
|
+
warningThreshold: automaticStats.preCompactThreshold,
|
|
2310
|
+
autoCompactThreshold: automaticStats.threshold,
|
|
2311
|
+
autoCompactEnabled: automaticStats.enabled,
|
|
2312
|
+
});
|
|
2313
|
+
const result = await coordinator.compactManual(history, threshold);
|
|
2314
|
+
const compacted = result.messages;
|
|
2315
|
+
const compactedTokens = (0, token_estimate_1.estimateMessagesTokens)(compacted);
|
|
2316
|
+
const afterUsage = (0, model_context_1.createContextUsageSnapshot)({
|
|
2317
|
+
modelId,
|
|
2318
|
+
usedTokens: compactedTokens,
|
|
2319
|
+
source: 'estimated',
|
|
2320
|
+
outputReserveTokens: ctx.llm?.getMaxTokens?.(),
|
|
2321
|
+
warningThreshold: automaticStats.preCompactThreshold,
|
|
2322
|
+
autoCompactThreshold: automaticStats.threshold,
|
|
2323
|
+
autoCompactEnabled: automaticStats.enabled,
|
|
2324
|
+
});
|
|
2325
|
+
const reduction = history.length - compacted.length;
|
|
2326
|
+
const percent = Math.round((reduction / history.length) * 100);
|
|
2327
|
+
const sessionId = ctx.getSession?.()?.id ?? ctx.sessionId;
|
|
2328
|
+
if (sessionId) {
|
|
2329
|
+
const sourceMessageCount = (0, session_storage_1.readSessionMessages)(sessionId).length;
|
|
2330
|
+
const checkpoint = (0, session_storage_1.commitSessionCompactCheckpoint)({
|
|
2331
|
+
sessionId,
|
|
2332
|
+
mode: 'manual',
|
|
2333
|
+
modelId,
|
|
2334
|
+
sourceMessageCount,
|
|
2335
|
+
transcriptStartMessageIndex: Math.max(0, sourceMessageCount - threshold),
|
|
2336
|
+
modelHistory: compacted,
|
|
2337
|
+
summary: {
|
|
2338
|
+
text: result.summary,
|
|
2339
|
+
generatedAt: result.summaryGeneratedAt,
|
|
2340
|
+
source: result.summarySource,
|
|
2341
|
+
},
|
|
2342
|
+
beforeUsage,
|
|
2343
|
+
afterUsage,
|
|
2344
|
+
});
|
|
2345
|
+
ctx.store.setState({ conversationHistory: checkpoint.modelHistory });
|
|
2346
|
+
}
|
|
2347
|
+
else {
|
|
2348
|
+
ctx.store.setState({ conversationHistory: compacted });
|
|
2349
|
+
}
|
|
2350
|
+
ctx.store.setContextUsage(afterUsage);
|
|
2351
|
+
console.log(SUCCESS(`✔ Compacted ${history.length} → ${compacted.length} messages`));
|
|
2352
|
+
console.log(DIM(` Reduced by ${reduction} messages (${percent}%)`));
|
|
2353
|
+
console.log();
|
|
2354
|
+
return { success: true };
|
|
2355
|
+
}
|
|
2356
|
+
catch (err) {
|
|
2357
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
2358
|
+
console.log(ERROR(`✗ Compact failed: ${message}`));
|
|
2359
|
+
console.log();
|
|
2360
|
+
return { success: false };
|
|
2361
|
+
}
|
|
2362
|
+
}
|
|
2363
|
+
function handleUsage(ctx) {
|
|
2364
|
+
console.log();
|
|
2365
|
+
console.log(HEADER('Usage Statistics'));
|
|
2366
|
+
console.log(DIM('─'.repeat(40)));
|
|
2367
|
+
const snapshot = ctx.store.getSnapshot();
|
|
2368
|
+
const usage = snapshot.tokenUsage;
|
|
2369
|
+
const history = snapshot.conversationHistory;
|
|
2370
|
+
console.log();
|
|
2371
|
+
// Token usage
|
|
2372
|
+
console.log(HEADER(' Tokens:'));
|
|
2373
|
+
if (usage) {
|
|
2374
|
+
console.log(` Input ${ACCENT(usage.promptTokens.toLocaleString())}`);
|
|
2375
|
+
console.log(` Output ${ACCENT(usage.completionTokens.toLocaleString())}`);
|
|
2376
|
+
const total = usage.promptTokens + usage.completionTokens;
|
|
2377
|
+
console.log(` Total ${DIM(total.toLocaleString())}`);
|
|
2378
|
+
const ratio = usage.completionTokens / usage.promptTokens;
|
|
2379
|
+
console.log(` Ratio ${DIM(ratio.toFixed(2))} (output/input)`);
|
|
2380
|
+
}
|
|
2381
|
+
else {
|
|
2382
|
+
console.log(DIM(' No token usage recorded'));
|
|
2383
|
+
}
|
|
2384
|
+
console.log();
|
|
2385
|
+
// Conversation stats
|
|
2386
|
+
console.log(HEADER(' Conversation:'));
|
|
2387
|
+
console.log(` Messages ${DIM(history.length.toString())}`);
|
|
2388
|
+
console.log(` Turns ${DIM(Math.floor(history.length / 2).toString())}`);
|
|
2389
|
+
// Count by role
|
|
2390
|
+
const byRole = { user: 0, assistant: 0, system: 0, tool: 0 };
|
|
2391
|
+
for (const msg of history) {
|
|
2392
|
+
byRole[msg.role] = (byRole[msg.role] || 0) + 1;
|
|
2393
|
+
}
|
|
2394
|
+
console.log(` User msgs ${DIM(byRole.user.toString())}`);
|
|
2395
|
+
console.log(` Assistant ${DIM(byRole.assistant.toString())}`);
|
|
2396
|
+
console.log();
|
|
2397
|
+
// Model info
|
|
2398
|
+
console.log(HEADER(' Model:'));
|
|
2399
|
+
console.log(` Current ${BRAND(snapshot.currentModel)}`);
|
|
2400
|
+
if (ctx.llm) {
|
|
2401
|
+
console.log(` Active ${ACCENT(ctx.llm.getModel())}`);
|
|
2402
|
+
}
|
|
2403
|
+
console.log();
|
|
2404
|
+
return { success: true };
|
|
2405
|
+
}
|
|
2406
|
+
// ============================================================================
|
|
2407
|
+
// Session 命令
|
|
2408
|
+
// ============================================================================
|
|
2409
|
+
function parseSessionScopeArgs(args, cwd) {
|
|
2410
|
+
const parts = args.trim().split(/\s+/).filter(Boolean);
|
|
2411
|
+
let allProjects = false;
|
|
2412
|
+
let last = false;
|
|
2413
|
+
let projectPath = (0, session_storage_1.resolveProjectPath)(cwd);
|
|
2414
|
+
const queryParts = [];
|
|
2415
|
+
for (let i = 0; i < parts.length; i++) {
|
|
2416
|
+
const part = parts[i];
|
|
2417
|
+
if (part === '--all' || part === '-a') {
|
|
2418
|
+
allProjects = true;
|
|
2419
|
+
continue;
|
|
2420
|
+
}
|
|
2421
|
+
if (part === '--last' || part === '-l') {
|
|
2422
|
+
last = true;
|
|
2423
|
+
continue;
|
|
2424
|
+
}
|
|
2425
|
+
if ((part === '--project' || part === '-p') && parts[i + 1]) {
|
|
2426
|
+
projectPath = (0, session_storage_1.resolveProjectPath)(parts[i + 1]);
|
|
2427
|
+
i++;
|
|
2428
|
+
continue;
|
|
2429
|
+
}
|
|
2430
|
+
queryParts.push(part);
|
|
2431
|
+
}
|
|
2432
|
+
return {
|
|
2433
|
+
allProjects,
|
|
2434
|
+
projectPath,
|
|
2435
|
+
last,
|
|
2436
|
+
query: queryParts.join(' '),
|
|
2437
|
+
};
|
|
2438
|
+
}
|
|
2439
|
+
function sessionTitle(session) {
|
|
2440
|
+
return session.name || session.taskSummary || '(untitled)';
|
|
2441
|
+
}
|
|
2442
|
+
function truncateText(text, max) {
|
|
2443
|
+
return text.length > max ? text.slice(0, max - 3) + '...' : text;
|
|
2444
|
+
}
|
|
2445
|
+
function printSessionRows(sessions, options = {}) {
|
|
2446
|
+
for (let i = 0; i < sessions.length; i++) {
|
|
2447
|
+
const session = sessions[i];
|
|
2448
|
+
const startTime = new Date(session.startTime).toLocaleString();
|
|
2449
|
+
const updatedTime = new Date(session.updatedAt ?? session.startTime).toLocaleString();
|
|
2450
|
+
const duration = session.endTime
|
|
2451
|
+
? Math.round((session.endTime - session.startTime) / 1000) + 's'
|
|
2452
|
+
: 'active';
|
|
2453
|
+
const status = session.endTime ? DIM('completed') : ACCENT('active');
|
|
2454
|
+
const index = options.indexed ? `${String(i + 1).padStart(2, ' ')}. ` : ' ';
|
|
2455
|
+
const name = session.name ? ` ${ACCENT(`"${session.name}"`)}` : '';
|
|
2456
|
+
console.log(`${index}${status} ${BRAND(session.id.slice(0, 8))}${name} ${DIM(session.model)}`);
|
|
2457
|
+
console.log(` ${truncateText(sessionTitle(session), 96)}`);
|
|
2458
|
+
console.log(` ${DIM(`Started: ${startTime}`)} ${DIM(`Updated: ${updatedTime}`)} ${DIM(`Duration: ${duration}`)}`);
|
|
2459
|
+
console.log(` ${DIM(`Messages: ${session.messageCount ?? 0}`)} ${DIM(`Size: ${(0, format_1.formatBytes)(session.historySizeBytes ?? 0)}`)} ${DIM(`Tokens: ${session.tokenCount}`)} ${DIM(`Cost: $${session.cost.toFixed(4)}`)}`);
|
|
2460
|
+
if (options.showIndexSummary) {
|
|
2461
|
+
const indexSummary = (0, session_index_1.loadSessionIndex)(session.id, session.projectPath);
|
|
2462
|
+
if (indexSummary) {
|
|
2463
|
+
const toolCount = Object.values(indexSummary.tools).reduce((total, count) => total + count, 0);
|
|
2464
|
+
console.log(` ${DIM(`Index: ${indexSummary.files.length} files, ${toolCount} tool calls, ${indexSummary.topics.length} topics`)}`);
|
|
2465
|
+
}
|
|
2466
|
+
else {
|
|
2467
|
+
console.log(` ${DIM('Index: not built')}`);
|
|
2468
|
+
}
|
|
2469
|
+
}
|
|
2470
|
+
if (options.showProject) {
|
|
2471
|
+
console.log(` ${DIM(`Project: ${session.projectPath}`)}`);
|
|
2472
|
+
}
|
|
2473
|
+
console.log();
|
|
2474
|
+
}
|
|
2475
|
+
}
|
|
2476
|
+
function parsePickerIndex(ref, max) {
|
|
2477
|
+
const trimmed = ref.trim();
|
|
2478
|
+
const match = trimmed.match(/^#?(\d+)$/);
|
|
2479
|
+
if (!match)
|
|
2480
|
+
return null;
|
|
2481
|
+
const index = Number(match[1]);
|
|
2482
|
+
if (!Number.isInteger(index) || index < 1 || index > max)
|
|
2483
|
+
return null;
|
|
2484
|
+
return index - 1;
|
|
2485
|
+
}
|
|
2486
|
+
function printSessionConflict(ref, matches) {
|
|
2487
|
+
console.log(ERROR(`Session reference is ambiguous: ${ref}`));
|
|
2488
|
+
console.log(DIM('Use a longer id prefix, exact session name, or pick one of these:'));
|
|
2489
|
+
console.log();
|
|
2490
|
+
printSessionRows(matches.slice(0, 10), { indexed: true, showProject: true });
|
|
2491
|
+
console.log(DIM('Example: /resume <longer-session-id>'));
|
|
2492
|
+
console.log();
|
|
2493
|
+
}
|
|
2494
|
+
function printSessionPicker(sessions, options) {
|
|
2495
|
+
console.log(HEADER(options.title));
|
|
2496
|
+
console.log(DIM('─'.repeat(Math.min(process.stdout.columns || 80, 96))));
|
|
2497
|
+
printSessionRows(sessions, { indexed: true, showProject: options.showProject });
|
|
2498
|
+
if (options.moreCount && options.moreCount > 0) {
|
|
2499
|
+
console.log(DIM(`... ${options.moreCount} more sessions. Use /sessions to list them, or /resume <session-id>.`));
|
|
2500
|
+
}
|
|
2501
|
+
console.log(DIM('Use /resume <number|session-id|name> or /resume --last.'));
|
|
2502
|
+
}
|
|
2503
|
+
function handleSessions(ctx, args = '') {
|
|
2504
|
+
const scope = parseSessionScopeArgs(args, ctx.cwd);
|
|
2505
|
+
const query = scope.query?.trim();
|
|
2506
|
+
// If there's a search query, use the session index
|
|
2507
|
+
if (query && !query.startsWith('--')) {
|
|
2508
|
+
const allSessions = scope.allProjects
|
|
2509
|
+
? (0, session_storage_1.listSessions)()
|
|
2510
|
+
: (0, session_storage_1.listProjectSessions)(scope.projectPath);
|
|
2511
|
+
const matchedIds = (0, session_index_1.searchSessions)(query, allSessions.map(session => ({
|
|
2512
|
+
id: session.id,
|
|
2513
|
+
projectPath: session.projectPath,
|
|
2514
|
+
})));
|
|
2515
|
+
if (matchedIds.length === 0) {
|
|
2516
|
+
console.log();
|
|
2517
|
+
console.log(HEADER(`Sessions (search: "${query}")`));
|
|
2518
|
+
console.log(DIM('─'.repeat(40)));
|
|
2519
|
+
console.log(DIM(' No matching sessions found'));
|
|
2520
|
+
console.log();
|
|
2521
|
+
console.log(DIM('Tip: search by file path, tool name, or topic keyword'));
|
|
2522
|
+
console.log();
|
|
2523
|
+
return { success: true };
|
|
2524
|
+
}
|
|
2525
|
+
// Rebuild session list in matched order
|
|
2526
|
+
const sessionMap = new Map(allSessions.map(s => [s.id, s]));
|
|
2527
|
+
const matchedSessions = matchedIds.map(id => sessionMap.get(id)).filter(Boolean);
|
|
2528
|
+
console.log();
|
|
2529
|
+
console.log(HEADER(`Sessions (search: "${query}") — ${matchedSessions.length} matches`));
|
|
2530
|
+
console.log(DIM('─'.repeat(40)));
|
|
2531
|
+
console.log();
|
|
2532
|
+
printSessionRows(matchedSessions, { indexed: true, showProject: scope.allProjects, showIndexSummary: true });
|
|
2533
|
+
console.log();
|
|
2534
|
+
console.log(DIM(`Searched ${allSessions.length} sessions, found ${matchedSessions.length} matches`));
|
|
2535
|
+
console.log(DIM('Use /resume <number|session-id|name> to restore a session'));
|
|
2536
|
+
console.log();
|
|
2537
|
+
return { success: true };
|
|
2538
|
+
}
|
|
2539
|
+
console.log();
|
|
2540
|
+
console.log(HEADER(scope.allProjects ? 'Sessions (all projects)' : 'Sessions'));
|
|
2541
|
+
console.log(DIM('─'.repeat(40)));
|
|
2542
|
+
const sessions = scope.allProjects
|
|
2543
|
+
? (0, session_storage_1.listSessions)(10)
|
|
2544
|
+
: (0, session_storage_1.listProjectSessions)(scope.projectPath, 10);
|
|
2545
|
+
if (sessions.length === 0) {
|
|
2546
|
+
console.log(DIM(scope.allProjects ? ' No sessions found' : ' No sessions found for this project'));
|
|
2547
|
+
console.log();
|
|
2548
|
+
return { success: true };
|
|
2549
|
+
}
|
|
2550
|
+
console.log();
|
|
2551
|
+
printSessionRows(sessions, { indexed: true, showProject: scope.allProjects });
|
|
2552
|
+
console.log(DIM('Use /resume <number|session-id|name> to restore a session'));
|
|
2553
|
+
console.log(DIM('Use /session-rename <number|session-id|name> <new name> to rename'));
|
|
2554
|
+
console.log(DIM('Use /sessions --all to list sessions from every project'));
|
|
2555
|
+
console.log(DIM('Use /sessions <query> to search by file, tool, or keyword'));
|
|
2556
|
+
console.log();
|
|
2557
|
+
return { success: true };
|
|
2558
|
+
}
|
|
2559
|
+
function handleResume(ctx, args) {
|
|
2560
|
+
const ui = commandUICapabilities(ctx);
|
|
2561
|
+
const scope = parseSessionScopeArgs(args, ctx.cwd);
|
|
2562
|
+
const sessionRef = scope.query;
|
|
2563
|
+
const scopedSessions = (scope.allProjects ? (0, session_storage_1.listSessions)() : (0, session_storage_1.listProjectSessions)(scope.projectPath))
|
|
2564
|
+
.filter(session => (session.messageCount ?? 0) > 0);
|
|
2565
|
+
if (!sessionRef) {
|
|
2566
|
+
const lastSession = scopedSessions[0];
|
|
2567
|
+
if (!lastSession) {
|
|
2568
|
+
console.log(ERROR('No previous session found for this project'));
|
|
2569
|
+
console.log(DIM('Use /sessions --all to list all sessions'));
|
|
2570
|
+
console.log();
|
|
2571
|
+
return { success: false };
|
|
2572
|
+
}
|
|
2573
|
+
if (scope.last || scopedSessions.length === 1) {
|
|
2574
|
+
return restoreSession(ctx, lastSession, true);
|
|
2575
|
+
}
|
|
2576
|
+
const picker = {
|
|
2577
|
+
title: scope.allProjects ? 'Pick a Session (all projects)' : 'Pick a Session',
|
|
2578
|
+
showProject: scope.allProjects,
|
|
2579
|
+
moreCount: 0,
|
|
2580
|
+
sessions: scopedSessions,
|
|
2581
|
+
allProjects: scope.allProjects,
|
|
2582
|
+
maxVisibleItems: 10,
|
|
2583
|
+
};
|
|
2584
|
+
if (ui.structuredPickers) {
|
|
2585
|
+
return { success: true, sessionPicker: picker };
|
|
2586
|
+
}
|
|
2587
|
+
const visibleSessions = scopedSessions.slice(0, 10);
|
|
2588
|
+
console.log();
|
|
2589
|
+
printSessionPicker(visibleSessions, {
|
|
2590
|
+
title: picker.title,
|
|
2591
|
+
showProject: picker.showProject,
|
|
2592
|
+
moreCount: Math.max(0, scopedSessions.length - visibleSessions.length),
|
|
2593
|
+
});
|
|
2594
|
+
console.log();
|
|
2595
|
+
return { success: true };
|
|
2596
|
+
}
|
|
2597
|
+
const pickerIndex = parsePickerIndex(sessionRef, scopedSessions.length);
|
|
2598
|
+
if (pickerIndex !== null) {
|
|
2599
|
+
return restoreSession(ctx, scopedSessions[pickerIndex], false);
|
|
2600
|
+
}
|
|
2601
|
+
// Resume specific session
|
|
2602
|
+
const result = (0, session_storage_1.lookupSessionRef)(sessionRef, scope.projectPath, { allProjects: scope.allProjects });
|
|
2603
|
+
if (result.status === 'ambiguous') {
|
|
2604
|
+
printSessionConflict(sessionRef, result.matches);
|
|
2605
|
+
return { success: false };
|
|
2606
|
+
}
|
|
2607
|
+
if (result.status === 'not_found') {
|
|
2608
|
+
console.log(ERROR(`Session not found: ${sessionRef}`));
|
|
2609
|
+
console.log(DIM(scope.allProjects ? 'Use /sessions --all to list sessions' : 'Use /sessions to list project sessions, or /resume <id> --all'));
|
|
2610
|
+
console.log();
|
|
2611
|
+
return { success: false };
|
|
2612
|
+
}
|
|
2613
|
+
return restoreSession(ctx, result.session, false);
|
|
2614
|
+
}
|
|
2615
|
+
function restoreSession(ctx, session, isLast) {
|
|
2616
|
+
const resumed = (0, session_storage_1.resumeSession)(session.id) ?? session;
|
|
2617
|
+
// Swap in the resumed session's transcript BEFORE emitting any command output,
|
|
2618
|
+
// so the output is appended after the history rather than wiped by the
|
|
2619
|
+
// transcript replacement below.
|
|
2620
|
+
ctx.setSession?.(resumed);
|
|
2621
|
+
// Load history and notify runtime/TUI consumers.
|
|
2622
|
+
const history = (0, session_storage_1.loadSessionHistory)(resumed.id);
|
|
2623
|
+
const transcriptMessages = (0, session_storage_1.loadSessionTranscriptMessages)(resumed.id);
|
|
2624
|
+
const rawMessages = (0, session_storage_1.readSessionMessages)(resumed.id);
|
|
2625
|
+
const checkpoint = (0, session_storage_1.loadSessionCompactCheckpoint)(resumed.id);
|
|
2626
|
+
const resumeGeneratedAt = Date.now();
|
|
2627
|
+
const summary = checkpoint?.summary.text ?? (history.length > 0 ? generateHistorySummary(history) : '');
|
|
2628
|
+
const summaryGeneratedAt = checkpoint?.summary.generatedAt ?? resumeGeneratedAt;
|
|
2629
|
+
const summarySource = checkpoint?.summary.source ?? 'resume_heuristic';
|
|
2630
|
+
const summaryCoveredMessages = checkpoint?.summary.sourceMessageCount ?? rawMessages.length;
|
|
2631
|
+
if (history.length > 0) {
|
|
2632
|
+
const eventSummary = checkpoint?.summary.text ?? generateRestoredSessionEventSummary(history);
|
|
2633
|
+
ctx.store.setState({ conversationHistory: history });
|
|
2634
|
+
ctx.store.setState({ harnessState: (0, session_storage_1.loadSessionHarnessState)(resumed.id) ?? resumed.harnessState });
|
|
2635
|
+
(0, framework_1.resetToolState)();
|
|
2636
|
+
ctx.sessionRestored?.({
|
|
2637
|
+
sessionId: resumed.id,
|
|
2638
|
+
projectPath: resumed.projectPath,
|
|
2639
|
+
model: resumed.model,
|
|
2640
|
+
restoredMessages: history.length,
|
|
2641
|
+
messageCount: resumed.messageCount,
|
|
2642
|
+
summary: eventSummary,
|
|
2643
|
+
summaryGeneratedAt,
|
|
2644
|
+
summarySource,
|
|
2645
|
+
summaryCoveredMessages,
|
|
2646
|
+
checkpointId: checkpoint?.checkpointId,
|
|
2647
|
+
transcriptMessages: transcriptMessages.length,
|
|
2648
|
+
});
|
|
2649
|
+
}
|
|
2650
|
+
else {
|
|
2651
|
+
ctx.sessionRestored?.({
|
|
2652
|
+
sessionId: resumed.id,
|
|
2653
|
+
projectPath: resumed.projectPath,
|
|
2654
|
+
model: resumed.model,
|
|
2655
|
+
restoredMessages: 0,
|
|
2656
|
+
messageCount: resumed.messageCount,
|
|
2657
|
+
summaryGeneratedAt,
|
|
2658
|
+
summarySource,
|
|
2659
|
+
summaryCoveredMessages,
|
|
2660
|
+
checkpointId: checkpoint?.checkpointId,
|
|
2661
|
+
transcriptMessages: transcriptMessages.length,
|
|
2662
|
+
});
|
|
2663
|
+
}
|
|
2664
|
+
// Emit the resume summary. In TUI (inline-surface) mode, route through the
|
|
2665
|
+
// command-output sink instead of raw console.log: a bare console.log writes
|
|
2666
|
+
// directly to stdout and desyncs the surface's cursor tracking, leaving the
|
|
2667
|
+
// live region mis-positioned (blank lower screen, content stuck at top).
|
|
2668
|
+
// Plain text is used so no raw ANSI escapes leak into the TUI frame.
|
|
2669
|
+
const bannerLines = [
|
|
2670
|
+
isLast ? 'Resuming last session' : `Resuming session ${resumed.id.slice(0, 8)}`,
|
|
2671
|
+
` ID: ${resumed.id}`,
|
|
2672
|
+
` Model: ${resumed.model}`,
|
|
2673
|
+
` Project: ${resumed.projectPath}`,
|
|
2674
|
+
` Started: ${new Date(resumed.startTime).toLocaleString()}`,
|
|
2675
|
+
];
|
|
2676
|
+
if (history.length > 0) {
|
|
2677
|
+
bannerLines.push(` Summary: ${summary}`);
|
|
2678
|
+
bannerLines.push(` Generated: ${new Date(summaryGeneratedAt).toLocaleString()} (${checkpoint ? 'compact checkpoint' : 'generated on resume'})`);
|
|
2679
|
+
bannerLines.push(` Covers: ${summaryCoveredMessages} source messages`);
|
|
2680
|
+
bannerLines.push(`✔ Restored ${history.length} model-context messages / ${transcriptMessages.length} transcript messages`);
|
|
2681
|
+
}
|
|
2682
|
+
else {
|
|
2683
|
+
bannerLines.push(' No messages in session');
|
|
2684
|
+
}
|
|
2685
|
+
if (ctx.uiRenderer === 'tui' || ctx.uiRenderer === 'ink') {
|
|
2686
|
+
if (!ctx.sessionRestored) {
|
|
2687
|
+
for (const line of bannerLines)
|
|
2688
|
+
ctx.writeLine?.(line);
|
|
2689
|
+
}
|
|
2690
|
+
}
|
|
2691
|
+
else {
|
|
2692
|
+
console.log();
|
|
2693
|
+
console.log(HEADER(bannerLines[0]));
|
|
2694
|
+
for (const line of bannerLines.slice(1)) {
|
|
2695
|
+
console.log(line.startsWith('✔') ? SUCCESS(line) : DIM(line));
|
|
2696
|
+
}
|
|
2697
|
+
console.log();
|
|
2698
|
+
}
|
|
2699
|
+
return { success: true };
|
|
2700
|
+
}
|
|
2701
|
+
function handleSessionRename(ctx, args) {
|
|
2702
|
+
const scope = parseSessionScopeArgs(args, ctx.cwd);
|
|
2703
|
+
const parts = scope.query.split(/\s+/).filter(Boolean);
|
|
2704
|
+
const ref = parts.shift();
|
|
2705
|
+
const newName = parts.join(' ').trim();
|
|
2706
|
+
if (!ref || !newName) {
|
|
2707
|
+
console.log(ERROR('Usage: /session-rename <number|session-id|name> <new name>'));
|
|
2708
|
+
console.log(DIM('Run /sessions first to see picker numbers for this project.'));
|
|
2709
|
+
console.log();
|
|
2710
|
+
return { success: false };
|
|
2711
|
+
}
|
|
2712
|
+
const scopedSessions = scope.allProjects ? (0, session_storage_1.listSessions)() : (0, session_storage_1.listProjectSessions)(scope.projectPath);
|
|
2713
|
+
const pickerIndex = parsePickerIndex(ref, scopedSessions.length);
|
|
2714
|
+
let session = pickerIndex !== null ? scopedSessions[pickerIndex] : null;
|
|
2715
|
+
if (!session) {
|
|
2716
|
+
const result = (0, session_storage_1.lookupSessionRef)(ref, scope.projectPath, { allProjects: scope.allProjects });
|
|
2717
|
+
if (result.status === 'ambiguous') {
|
|
2718
|
+
printSessionConflict(ref, result.matches);
|
|
2719
|
+
return { success: false };
|
|
2720
|
+
}
|
|
2721
|
+
if (result.status === 'not_found') {
|
|
2722
|
+
console.log(ERROR(`Session not found: ${ref}`));
|
|
2723
|
+
console.log(DIM(scope.allProjects ? 'Use /sessions --all to list sessions' : 'Use /sessions to list project sessions'));
|
|
2724
|
+
console.log();
|
|
2725
|
+
return { success: false };
|
|
2726
|
+
}
|
|
2727
|
+
session = result.session;
|
|
2728
|
+
}
|
|
2729
|
+
const duplicate = scopedSessions.find(s => s.id !== session.id && s.name === newName);
|
|
2730
|
+
const renamed = (0, session_storage_1.renameSession)(session.id, newName);
|
|
2731
|
+
if (!renamed) {
|
|
2732
|
+
console.log(ERROR(`Session not found: ${ref}`));
|
|
2733
|
+
console.log();
|
|
2734
|
+
return { success: false };
|
|
2735
|
+
}
|
|
2736
|
+
if (ctx.getSession?.()?.id === renamed.id) {
|
|
2737
|
+
ctx.setSession?.(renamed);
|
|
2738
|
+
}
|
|
2739
|
+
console.log();
|
|
2740
|
+
console.log(SUCCESS(`✔ Renamed session ${renamed.id.slice(0, 8)} to "${newName}"`));
|
|
2741
|
+
if (duplicate) {
|
|
2742
|
+
console.log(WARN(` Name already exists on ${duplicate.id.slice(0, 8)}; /resume "${newName}" will be ambiguous.`));
|
|
2743
|
+
}
|
|
2744
|
+
console.log();
|
|
2745
|
+
return { success: true };
|
|
2746
|
+
}
|
|
2747
|
+
async function handleEditPreview(ctx) {
|
|
2748
|
+
const lastEdit = (0, framework_1.getToolState)().lastEditFileArgs;
|
|
2749
|
+
if (!lastEdit) {
|
|
2750
|
+
console.log(ERROR('No previous edit_file call found for preview'));
|
|
2751
|
+
console.log(DIM('Run an edit_file tool call first, then use /edit-preview to inspect the match candidates.'));
|
|
2752
|
+
console.log();
|
|
2753
|
+
return { success: false };
|
|
2754
|
+
}
|
|
2755
|
+
const hasMetadata = Boolean(lastEdit.sessionId || lastEdit.turnId);
|
|
2756
|
+
if (!hasMetadata) {
|
|
2757
|
+
console.log(WARN('Using legacy edit-preview state without session/turn tags. Running preview as best-effort.'));
|
|
2758
|
+
}
|
|
2759
|
+
const staleBySession = Boolean(lastEdit.sessionId && ctx.sessionId && lastEdit.sessionId !== ctx.sessionId);
|
|
2760
|
+
const staleByTurn = Boolean(lastEdit.turnId != null && ctx.turnId != null && String(lastEdit.turnId) !== String(ctx.turnId));
|
|
2761
|
+
if (staleBySession || staleByTurn) {
|
|
2762
|
+
const mismatch = [];
|
|
2763
|
+
if (staleBySession)
|
|
2764
|
+
mismatch.push(`session ${lastEdit.sessionId} vs ${ctx.sessionId}`);
|
|
2765
|
+
if (staleByTurn)
|
|
2766
|
+
mismatch.push(`turn ${String(lastEdit.turnId)} vs ${String(ctx.turnId)}`);
|
|
2767
|
+
console.log(ERROR('Edit preview target does not match current context.'));
|
|
2768
|
+
console.log(DIM(`Stale edit target: ${mismatch.join(', ')}.`));
|
|
2769
|
+
console.log();
|
|
2770
|
+
return { success: false };
|
|
2771
|
+
}
|
|
2772
|
+
if (hasMetadata && !(ctx.sessionId || ctx.turnId)) {
|
|
2773
|
+
console.log(WARN('Edit preview context is available, but current command context is missing session/turn metadata.'));
|
|
2774
|
+
console.log(DIM('Preview is allowed, but stale checks cannot be fully validated.'));
|
|
2775
|
+
}
|
|
2776
|
+
const rawResult = await (0, tools_1.executeTool)('edit_file', {
|
|
2777
|
+
...lastEdit,
|
|
2778
|
+
preview: true,
|
|
2779
|
+
}, ctx.abortSignal, {
|
|
2780
|
+
cwd: ctx.cwd,
|
|
2781
|
+
config: {
|
|
2782
|
+
name: ctx.config.name,
|
|
2783
|
+
mode: ctx.config.mode,
|
|
2784
|
+
},
|
|
2785
|
+
sessionId: ctx.sessionId,
|
|
2786
|
+
turnId: ctx.turnId,
|
|
2787
|
+
});
|
|
2788
|
+
let parsed;
|
|
2789
|
+
try {
|
|
2790
|
+
parsed = JSON.parse(rawResult);
|
|
2791
|
+
}
|
|
2792
|
+
catch {
|
|
2793
|
+
parsed = { success: false, error: rawResult };
|
|
2794
|
+
}
|
|
2795
|
+
console.log();
|
|
2796
|
+
console.log(HEADER('Edit Preview'));
|
|
2797
|
+
console.log(DIM('─'.repeat(40)));
|
|
2798
|
+
if (parsed.success) {
|
|
2799
|
+
console.log(parsed.output || DIM('No preview output'));
|
|
2800
|
+
}
|
|
2801
|
+
else {
|
|
2802
|
+
console.log(ERROR(parsed.error || 'Preview failed'));
|
|
2803
|
+
}
|
|
2804
|
+
console.log();
|
|
2805
|
+
// Return structured data for terminal/TUI/Ink picker rendering.
|
|
2806
|
+
if (parsed.success && parsed.metadata?.candidates && Array.isArray(parsed.metadata.candidates)) {
|
|
2807
|
+
return {
|
|
2808
|
+
success: true,
|
|
2809
|
+
editPreview: {
|
|
2810
|
+
path: lastEdit.path,
|
|
2811
|
+
newString: lastEdit.new_string,
|
|
2812
|
+
kind: (lastEdit.fuzzy_match ? 'fuzzy' : 'exact'),
|
|
2813
|
+
candidates: parsed.metadata.candidates,
|
|
2814
|
+
},
|
|
2815
|
+
};
|
|
2816
|
+
}
|
|
2817
|
+
return { success: parsed.success === true };
|
|
2818
|
+
}
|
|
2819
|
+
/** Generate a brief summary of conversation history */
|
|
2820
|
+
function truncateRedactedSummary(text, maxLength) {
|
|
2821
|
+
const redacted = (0, session_storage_1.redactTraceText)(text);
|
|
2822
|
+
if (redacted.length <= maxLength)
|
|
2823
|
+
return redacted;
|
|
2824
|
+
let truncated = redacted.slice(0, maxLength);
|
|
2825
|
+
for (const marker of ['[REDACTED_SECRET]']) {
|
|
2826
|
+
const markerStart = truncated.indexOf(marker.slice(0, 6));
|
|
2827
|
+
if (markerStart >= 0 && !truncated.includes(marker)) {
|
|
2828
|
+
truncated = `${truncated.slice(0, markerStart)}${marker}`;
|
|
2829
|
+
break;
|
|
2830
|
+
}
|
|
2831
|
+
}
|
|
2832
|
+
return `${truncated}...`;
|
|
2833
|
+
}
|
|
2834
|
+
function generateHistorySummary(messages) {
|
|
2835
|
+
const userMsgs = messages.filter(m => m.role === 'user' && m.content);
|
|
2836
|
+
const assistantMsgsWithTools = messages.filter(m => m.role === 'assistant' && m.tool_calls && m.tool_calls.length > 0);
|
|
2837
|
+
// Extract topics from first few user messages
|
|
2838
|
+
const topics = userMsgs.slice(0, 3).map(m => {
|
|
2839
|
+
return truncateRedactedSummary(m.content || '', 40);
|
|
2840
|
+
});
|
|
2841
|
+
// Extract tools used
|
|
2842
|
+
const toolsUsed = assistantMsgsWithTools.flatMap(m => m.tool_calls?.map(tc => tc.function.name) || []);
|
|
2843
|
+
const uniqueTools = [...new Set(toolsUsed)];
|
|
2844
|
+
// Build summary
|
|
2845
|
+
const parts = [];
|
|
2846
|
+
if (topics.length > 0) {
|
|
2847
|
+
parts.push(`Topics: ${topics.join('; ')}`);
|
|
2848
|
+
}
|
|
2849
|
+
if (uniqueTools.length > 0) {
|
|
2850
|
+
parts.push(`Tools: ${uniqueTools.join(', ')}`);
|
|
2851
|
+
}
|
|
2852
|
+
if (parts.length === 0) {
|
|
2853
|
+
return 'No significant activity';
|
|
2854
|
+
}
|
|
2855
|
+
return parts.join('. ');
|
|
2856
|
+
}
|
|
2857
|
+
function generateRestoredSessionEventSummary(messages) {
|
|
2858
|
+
const assistantMsgsWithTools = messages.filter(m => m.role === 'assistant' && m.tool_calls && m.tool_calls.length > 0);
|
|
2859
|
+
const toolsUsed = assistantMsgsWithTools.flatMap(m => m.tool_calls?.map(tc => tc.function.name) || []);
|
|
2860
|
+
const uniqueTools = [...new Set(toolsUsed)].slice(0, 8);
|
|
2861
|
+
if (uniqueTools.length === 0)
|
|
2862
|
+
return undefined;
|
|
2863
|
+
return `Tools: ${uniqueTools.join(', ')}`;
|
|
2864
|
+
}
|
|
2865
|
+
function continueAsSlashChat(name, args) {
|
|
2866
|
+
const trimmed = args.trim();
|
|
2867
|
+
return {
|
|
2868
|
+
success: true,
|
|
2869
|
+
continueAsChat: true,
|
|
2870
|
+
chatInput: `/${name}${trimmed ? ` ${trimmed}` : ''}`,
|
|
2871
|
+
};
|
|
2872
|
+
}
|
|
2873
|
+
// ============================================================================
|
|
2874
|
+
// 命令注册表
|
|
2875
|
+
// ============================================================================
|
|
2876
|
+
const COMMANDS = [
|
|
2877
|
+
// Coding workflows
|
|
2878
|
+
{
|
|
2879
|
+
name: 'target',
|
|
2880
|
+
description: 'Create, view, pause, resume, or clear a persistent goal target',
|
|
2881
|
+
argumentHint: '[objective | pause | resume | clear | status | edit <text>]',
|
|
2882
|
+
category: 'workflow',
|
|
2883
|
+
priority: 3,
|
|
2884
|
+
type: 'builtin',
|
|
2885
|
+
execute: (ctx, args) => handleTarget(ctx, args),
|
|
2886
|
+
},
|
|
2887
|
+
{
|
|
2888
|
+
name: 'goal',
|
|
2889
|
+
description: 'Alias for /target — manage a persistent goal target',
|
|
2890
|
+
argumentHint: '[objective | pause | resume | clear | status | edit <text>]',
|
|
2891
|
+
category: 'workflow',
|
|
2892
|
+
priority: 2,
|
|
2893
|
+
type: 'builtin',
|
|
2894
|
+
execute: (ctx, args) => handleTarget(ctx, args),
|
|
2895
|
+
},
|
|
2896
|
+
{
|
|
2897
|
+
name: 'diff',
|
|
2898
|
+
description: 'Summarize current git workspace changes and touched files',
|
|
2899
|
+
argumentHint: '[--max-files N]',
|
|
2900
|
+
category: 'workflow',
|
|
2901
|
+
priority: 5,
|
|
2902
|
+
type: 'builtin',
|
|
2903
|
+
execute: (ctx, args) => handleDiff(ctx, args),
|
|
2904
|
+
},
|
|
2905
|
+
{
|
|
2906
|
+
name: 'commit',
|
|
2907
|
+
description: 'Create a read-only commit plan and suggested message for current changes',
|
|
2908
|
+
argumentHint: '[--max-files N]',
|
|
2909
|
+
category: 'workflow',
|
|
2910
|
+
priority: 8,
|
|
2911
|
+
type: 'builtin',
|
|
2912
|
+
execute: (ctx, args) => handleCommitPlan(ctx, args),
|
|
2913
|
+
},
|
|
2914
|
+
{
|
|
2915
|
+
name: 'review',
|
|
2916
|
+
description: 'Review the current change or requested files',
|
|
2917
|
+
argumentHint: '[scope]',
|
|
2918
|
+
category: 'workflow',
|
|
2919
|
+
priority: 10,
|
|
2920
|
+
type: 'chat',
|
|
2921
|
+
execute: (_ctx, args) => continueAsSlashChat('review', args),
|
|
2922
|
+
},
|
|
2923
|
+
{
|
|
2924
|
+
name: 'security',
|
|
2925
|
+
aliases: ['audit'],
|
|
2926
|
+
description: 'Review code or dependencies for security risks',
|
|
2927
|
+
argumentHint: '[scope]',
|
|
2928
|
+
category: 'workflow',
|
|
2929
|
+
priority: 20,
|
|
2930
|
+
type: 'chat',
|
|
2931
|
+
execute: (_ctx, args) => continueAsSlashChat('security', args),
|
|
2932
|
+
},
|
|
2933
|
+
{
|
|
2934
|
+
name: 'test-gen',
|
|
2935
|
+
aliases: ['tests'],
|
|
2936
|
+
description: 'Generate or improve tests for a target area',
|
|
2937
|
+
argumentHint: '[scope]',
|
|
2938
|
+
category: 'workflow',
|
|
2939
|
+
priority: 30,
|
|
2940
|
+
type: 'chat',
|
|
2941
|
+
execute: (_ctx, args) => continueAsSlashChat('test-gen', args),
|
|
2942
|
+
},
|
|
2943
|
+
{
|
|
2944
|
+
name: 'todos',
|
|
2945
|
+
aliases: ['todo'],
|
|
2946
|
+
description: 'Show current agent todo state',
|
|
2947
|
+
category: 'workflow',
|
|
2948
|
+
priority: 40,
|
|
2949
|
+
type: 'builtin',
|
|
2950
|
+
execute: (ctx) => handleTodos(ctx),
|
|
2951
|
+
},
|
|
2952
|
+
// Sessions and context lifecycle
|
|
2953
|
+
{
|
|
2954
|
+
name: 'resume',
|
|
2955
|
+
description: 'Resume a previous session',
|
|
2956
|
+
argumentHint: '[number|session-id|name]',
|
|
2957
|
+
category: 'session',
|
|
2958
|
+
priority: 10,
|
|
2959
|
+
type: 'builtin',
|
|
2960
|
+
execute: (ctx, args) => handleResume(ctx, args),
|
|
2961
|
+
},
|
|
2962
|
+
{
|
|
2963
|
+
name: 'sessions',
|
|
2964
|
+
description: 'List recent sessions, or search by file/tool/keyword',
|
|
2965
|
+
argumentHint: '[<query>|--all]',
|
|
2966
|
+
category: 'session',
|
|
2967
|
+
priority: 20,
|
|
2968
|
+
type: 'builtin',
|
|
2969
|
+
execute: (ctx, args) => handleSessions(ctx, args),
|
|
2970
|
+
},
|
|
2971
|
+
{
|
|
2972
|
+
name: 'session-rename',
|
|
2973
|
+
aliases: ['rename-session'],
|
|
2974
|
+
description: 'Rename a saved session',
|
|
2975
|
+
argumentHint: '<number|session-id|name> <new name>',
|
|
2976
|
+
category: 'session',
|
|
2977
|
+
priority: 30,
|
|
2978
|
+
type: 'builtin',
|
|
2979
|
+
execute: (ctx, args) => handleSessionRename(ctx, args),
|
|
2980
|
+
},
|
|
2981
|
+
{
|
|
2982
|
+
name: 'compact',
|
|
2983
|
+
description: 'Compact conversation history to reduce context size',
|
|
2984
|
+
argumentHint: '[threshold]',
|
|
2985
|
+
category: 'session',
|
|
2986
|
+
priority: 40,
|
|
2987
|
+
type: 'builtin',
|
|
2988
|
+
execute: (ctx, args) => handleCompact(ctx, args),
|
|
2989
|
+
},
|
|
2990
|
+
{
|
|
2991
|
+
name: 'clear-history',
|
|
2992
|
+
aliases: ['reset'],
|
|
2993
|
+
description: 'Clear conversation history (keep config)',
|
|
2994
|
+
category: 'session',
|
|
2995
|
+
priority: 50,
|
|
2996
|
+
type: 'builtin',
|
|
2997
|
+
execute: (ctx) => handleClearHistory(ctx),
|
|
2998
|
+
},
|
|
2999
|
+
// Harness, memory, and skills
|
|
3000
|
+
{
|
|
3001
|
+
name: 'harness',
|
|
3002
|
+
description: 'Show Context Harness state, or `/harness explain` for prompt assembly details',
|
|
3003
|
+
argumentHint: '[explain]',
|
|
3004
|
+
category: 'context',
|
|
3005
|
+
priority: 10,
|
|
3006
|
+
type: 'builtin',
|
|
3007
|
+
execute: (ctx, args) => showHarness(ctx, args),
|
|
3008
|
+
},
|
|
3009
|
+
{
|
|
3010
|
+
name: 'skills',
|
|
3011
|
+
description: 'List loaded skills (built-in / user / project)',
|
|
3012
|
+
category: 'context',
|
|
3013
|
+
priority: 20,
|
|
3014
|
+
type: 'builtin',
|
|
3015
|
+
execute: (ctx) => handleSkills(ctx),
|
|
3016
|
+
},
|
|
3017
|
+
{
|
|
3018
|
+
name: 'skill',
|
|
3019
|
+
aliases: ['use-skill', 'activate-skill'],
|
|
3020
|
+
description: 'Activate a loaded skill for one chat turn',
|
|
3021
|
+
argumentHint: '<name> <task>',
|
|
3022
|
+
category: 'context',
|
|
3023
|
+
priority: 21,
|
|
3024
|
+
type: 'chat',
|
|
3025
|
+
execute: (ctx, args) => handleSkill(ctx, args),
|
|
3026
|
+
},
|
|
3027
|
+
{
|
|
3028
|
+
name: 'memory',
|
|
3029
|
+
description: 'Show memory status, or `/memory reindex` to rebuild semantic index',
|
|
3030
|
+
argumentHint: '[reindex]',
|
|
3031
|
+
category: 'context',
|
|
3032
|
+
priority: 30,
|
|
3033
|
+
type: 'builtin',
|
|
3034
|
+
execute: (ctx, args) => handleMemory(ctx, args),
|
|
3035
|
+
},
|
|
3036
|
+
// Tools and safety
|
|
3037
|
+
{
|
|
3038
|
+
name: 'tools',
|
|
3039
|
+
aliases: ['tool'],
|
|
3040
|
+
description: 'List available built-in and MCP tools',
|
|
3041
|
+
category: 'tools',
|
|
3042
|
+
priority: 10,
|
|
3043
|
+
type: 'builtin',
|
|
3044
|
+
execute: (ctx) => handleTools(ctx),
|
|
3045
|
+
},
|
|
3046
|
+
{
|
|
3047
|
+
name: 'edit-preview',
|
|
3048
|
+
description: 'Preview the last edit_file match candidates without writing',
|
|
3049
|
+
category: 'tools',
|
|
3050
|
+
priority: 15,
|
|
3051
|
+
type: 'builtin',
|
|
3052
|
+
execute: (ctx) => handleEditPreview(ctx),
|
|
3053
|
+
},
|
|
3054
|
+
{
|
|
3055
|
+
name: 'mcp',
|
|
3056
|
+
description: 'Show connected MCP servers and their status',
|
|
3057
|
+
category: 'tools',
|
|
3058
|
+
priority: 20,
|
|
3059
|
+
type: 'builtin',
|
|
3060
|
+
execute: (ctx) => handleMcp(ctx),
|
|
3061
|
+
},
|
|
3062
|
+
{
|
|
3063
|
+
name: 'safety',
|
|
3064
|
+
description: 'Show safety checker status and audit summary',
|
|
3065
|
+
category: 'tools',
|
|
3066
|
+
priority: 30,
|
|
3067
|
+
type: 'builtin',
|
|
3068
|
+
execute: (ctx) => showSafety(ctx),
|
|
3069
|
+
},
|
|
3070
|
+
// Model and runtime configuration
|
|
3071
|
+
{
|
|
3072
|
+
name: 'model',
|
|
3073
|
+
description: 'Show or change the current model',
|
|
3074
|
+
argumentHint: '[model|list|help]',
|
|
3075
|
+
category: 'model',
|
|
3076
|
+
priority: 10,
|
|
3077
|
+
type: 'builtin',
|
|
3078
|
+
execute: (ctx, args) => handleModel(ctx, args),
|
|
3079
|
+
},
|
|
3080
|
+
{
|
|
3081
|
+
name: 'mode',
|
|
3082
|
+
aliases: ['permissions', 'perm'],
|
|
3083
|
+
description: 'Show or change tool permission mode',
|
|
3084
|
+
argumentHint: '[default|accept-edits|plan|auto|next]',
|
|
3085
|
+
category: 'model',
|
|
3086
|
+
priority: 20,
|
|
3087
|
+
type: 'builtin',
|
|
3088
|
+
execute: (ctx, args) => handleMode(ctx, args),
|
|
3089
|
+
},
|
|
3090
|
+
{
|
|
3091
|
+
name: 'config',
|
|
3092
|
+
description: 'Show current configuration',
|
|
3093
|
+
category: 'model',
|
|
3094
|
+
priority: 30,
|
|
3095
|
+
type: 'builtin',
|
|
3096
|
+
execute: (ctx) => showConfig(ctx),
|
|
3097
|
+
},
|
|
3098
|
+
// System commands
|
|
3099
|
+
{
|
|
3100
|
+
name: 'help',
|
|
3101
|
+
aliases: ['h'],
|
|
3102
|
+
description: 'Show available commands',
|
|
3103
|
+
category: 'system',
|
|
3104
|
+
priority: 10,
|
|
3105
|
+
type: 'builtin',
|
|
3106
|
+
execute: () => showHelp(),
|
|
3107
|
+
},
|
|
3108
|
+
{
|
|
3109
|
+
name: 'status',
|
|
3110
|
+
aliases: ['s'],
|
|
3111
|
+
description: 'Show system status overview',
|
|
3112
|
+
category: 'system',
|
|
3113
|
+
priority: 20,
|
|
3114
|
+
type: 'builtin',
|
|
3115
|
+
execute: (ctx) => showStatus(ctx),
|
|
3116
|
+
},
|
|
3117
|
+
{
|
|
3118
|
+
name: 'clear',
|
|
3119
|
+
description: 'Clear the terminal screen',
|
|
3120
|
+
category: 'system',
|
|
3121
|
+
priority: 30,
|
|
3122
|
+
type: 'builtin',
|
|
3123
|
+
execute: () => {
|
|
3124
|
+
process.stdout.write('\x1Bc');
|
|
3125
|
+
return { success: true };
|
|
3126
|
+
},
|
|
3127
|
+
},
|
|
3128
|
+
{
|
|
3129
|
+
name: 'exit',
|
|
3130
|
+
aliases: ['quit', 'q'],
|
|
3131
|
+
description: 'Shutdown and exit',
|
|
3132
|
+
category: 'system',
|
|
3133
|
+
priority: 40,
|
|
3134
|
+
type: 'builtin',
|
|
3135
|
+
execute: (ctx) => handleExit(ctx),
|
|
3136
|
+
},
|
|
3137
|
+
// Diagnostics
|
|
3138
|
+
{
|
|
3139
|
+
name: 'doctor',
|
|
3140
|
+
aliases: ['diag', 'diagnose'],
|
|
3141
|
+
description: 'Run configuration, tools, MCP, skills, session, and harness diagnostics',
|
|
3142
|
+
category: 'diagnostics',
|
|
3143
|
+
priority: 5,
|
|
3144
|
+
type: 'builtin',
|
|
3145
|
+
execute: (ctx) => handleDoctor(ctx),
|
|
3146
|
+
},
|
|
3147
|
+
{
|
|
3148
|
+
name: 'storage',
|
|
3149
|
+
description: 'Inspect, repair, or clean Orion Code storage layout',
|
|
3150
|
+
argumentHint: '[doctor|repair|cleanup --dry-run]',
|
|
3151
|
+
category: 'diagnostics',
|
|
3152
|
+
priority: 8,
|
|
3153
|
+
type: 'builtin',
|
|
3154
|
+
execute: (ctx, args) => handleStorage(ctx, args),
|
|
3155
|
+
},
|
|
3156
|
+
{
|
|
3157
|
+
name: 'usage',
|
|
3158
|
+
aliases: ['stats'],
|
|
3159
|
+
description: 'Show detailed usage statistics',
|
|
3160
|
+
category: 'diagnostics',
|
|
3161
|
+
priority: 10,
|
|
3162
|
+
type: 'builtin',
|
|
3163
|
+
execute: (ctx) => handleUsage(ctx),
|
|
3164
|
+
},
|
|
3165
|
+
{
|
|
3166
|
+
name: 'loop-stats',
|
|
3167
|
+
aliases: ['loop'],
|
|
3168
|
+
description: 'Show detailed agent-loop budget and efficiency diagnostics',
|
|
3169
|
+
category: 'diagnostics',
|
|
3170
|
+
priority: 12,
|
|
3171
|
+
type: 'builtin',
|
|
3172
|
+
execute: (ctx) => handleLoopStats(ctx),
|
|
3173
|
+
},
|
|
3174
|
+
{
|
|
3175
|
+
name: 'trace',
|
|
3176
|
+
description: 'Show structured event timeline for the latest or selected turn',
|
|
3177
|
+
argumentHint: '[latest|turn-id]',
|
|
3178
|
+
category: 'diagnostics',
|
|
3179
|
+
priority: 14,
|
|
3180
|
+
type: 'builtin',
|
|
3181
|
+
execute: (ctx, args) => handleTrace(ctx, args),
|
|
3182
|
+
},
|
|
3183
|
+
{
|
|
3184
|
+
name: 'last-tool',
|
|
3185
|
+
aliases: ['tool-last'],
|
|
3186
|
+
description: 'Show the latest tool call/result with full inspection hints',
|
|
3187
|
+
category: 'diagnostics',
|
|
3188
|
+
priority: 15,
|
|
3189
|
+
type: 'builtin',
|
|
3190
|
+
execute: (ctx, args) => handleLastTool(ctx, args),
|
|
3191
|
+
},
|
|
3192
|
+
{
|
|
3193
|
+
name: 'artifacts',
|
|
3194
|
+
aliases: ['artifact'],
|
|
3195
|
+
description: 'List or inspect saved full tool outputs for this project',
|
|
3196
|
+
argumentHint: '[show <id|prefix> --full]',
|
|
3197
|
+
category: 'diagnostics',
|
|
3198
|
+
priority: 16,
|
|
3199
|
+
type: 'builtin',
|
|
3200
|
+
execute: (ctx, args) => handleArtifacts(ctx, args),
|
|
3201
|
+
},
|
|
3202
|
+
{
|
|
3203
|
+
name: 'checkpoint',
|
|
3204
|
+
aliases: ['checkpoints'],
|
|
3205
|
+
description: 'List or restore file checkpoints created before agent edits',
|
|
3206
|
+
argumentHint: '[list|restore <turn-id|prefix> --yes]',
|
|
3207
|
+
category: 'diagnostics',
|
|
3208
|
+
priority: 18,
|
|
3209
|
+
type: 'builtin',
|
|
3210
|
+
execute: (ctx, args) => handleCheckpoint(ctx, args),
|
|
3211
|
+
},
|
|
3212
|
+
{
|
|
3213
|
+
name: 'cost',
|
|
3214
|
+
description: 'Show session token usage',
|
|
3215
|
+
category: 'diagnostics',
|
|
3216
|
+
priority: 20,
|
|
3217
|
+
type: 'builtin',
|
|
3218
|
+
execute: (ctx) => handleCost(ctx),
|
|
3219
|
+
},
|
|
3220
|
+
{
|
|
3221
|
+
name: 'agents',
|
|
3222
|
+
description: 'List registered agents and their status',
|
|
3223
|
+
category: 'diagnostics',
|
|
3224
|
+
priority: 30,
|
|
3225
|
+
type: 'builtin',
|
|
3226
|
+
execute: (ctx) => showAgents(ctx),
|
|
3227
|
+
},
|
|
3228
|
+
{
|
|
3229
|
+
name: 'migrate',
|
|
3230
|
+
description: 'Migrate data from OpenHorse to Orion Code',
|
|
3231
|
+
argumentHint: 'openhorse [--dry-run] [--include-env] [--include-project-files]',
|
|
3232
|
+
category: 'diagnostics',
|
|
3233
|
+
priority: 32,
|
|
3234
|
+
type: 'builtin',
|
|
3235
|
+
execute: (ctx, args) => (0, command_1.handleMigrateCommand)(ctx, args),
|
|
3236
|
+
},
|
|
3237
|
+
// Legacy commands kept executable for compatibility, but not shown in Ink help/palette.
|
|
3238
|
+
{
|
|
3239
|
+
name: 'task',
|
|
3240
|
+
description: 'Submit or list tasks',
|
|
3241
|
+
params: [{ name: 'action', description: 'list | <task-name>', required: false }],
|
|
3242
|
+
category: 'legacy',
|
|
3243
|
+
type: 'builtin',
|
|
3244
|
+
isHidden: true,
|
|
3245
|
+
execute: (ctx, args) => handleTask(ctx, args),
|
|
3246
|
+
},
|
|
3247
|
+
{
|
|
3248
|
+
name: 'run',
|
|
3249
|
+
description: 'Create and run a task through Agent + LLM',
|
|
3250
|
+
params: [{ name: 'description', description: 'Task description', required: true }],
|
|
3251
|
+
category: 'legacy',
|
|
3252
|
+
type: 'builtin',
|
|
3253
|
+
isHidden: true,
|
|
3254
|
+
execute: (ctx, args) => handleRun(ctx, args),
|
|
3255
|
+
},
|
|
3256
|
+
{
|
|
3257
|
+
name: 'chat',
|
|
3258
|
+
description: 'Send a message to the LLM',
|
|
3259
|
+
params: [{ name: 'message', description: 'Message to send', required: true }],
|
|
3260
|
+
category: 'legacy',
|
|
3261
|
+
type: 'chat',
|
|
3262
|
+
isHidden: true,
|
|
3263
|
+
execute: (ctx, args) => ({ success: true, continueAsChat: true, chatInput: args }),
|
|
3264
|
+
},
|
|
3265
|
+
];
|
|
3266
|
+
// ============================================================================
|
|
3267
|
+
// 导出
|
|
3268
|
+
// ============================================================================
|
|
3269
|
+
function getCommands() {
|
|
3270
|
+
return sortCommands(COMMANDS);
|
|
3271
|
+
}
|
|
3272
|
+
function getVisibleCommands() {
|
|
3273
|
+
return sortCommands(COMMANDS.filter(command => !command.isHidden));
|
|
3274
|
+
}
|
|
3275
|
+
function findCommand(name) {
|
|
3276
|
+
return COMMANDS.find(c => c.name === name || c.aliases?.includes(name));
|
|
3277
|
+
}
|
|
3278
|
+
function getCommandNames() {
|
|
3279
|
+
return getVisibleCommands().map(c => c.name);
|
|
3280
|
+
}
|
|
3281
|
+
//# sourceMappingURL=index.js.map
|