@ebowwa/coder 0.7.63 → 0.7.65
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/dist/core/__tests__/permissions.test.d.ts +12 -0
- package/dist/core/__tests__/permissions.test.d.ts.map +1 -0
- package/dist/core/__tests__/permissions.test.js +851 -0
- package/dist/core/agent-loop/__tests__/compaction.test.d.ts +5 -0
- package/dist/core/agent-loop/__tests__/compaction.test.d.ts.map +1 -0
- package/dist/core/agent-loop/__tests__/compaction.test.js +209 -0
- package/dist/core/agent-loop/__tests__/formatters.test.d.ts +5 -0
- package/dist/core/agent-loop/__tests__/formatters.test.d.ts.map +1 -0
- package/dist/core/agent-loop/__tests__/formatters.test.js +195 -0
- package/dist/core/agent-loop/__tests__/index.test.d.ts +5 -0
- package/dist/core/agent-loop/__tests__/index.test.d.ts.map +1 -0
- package/dist/core/agent-loop/__tests__/index.test.js +121 -0
- package/dist/core/agent-loop/__tests__/loop-state.test.d.ts +5 -0
- package/dist/core/agent-loop/__tests__/loop-state.test.d.ts.map +1 -0
- package/dist/core/agent-loop/__tests__/loop-state.test.js +340 -0
- package/dist/core/agent-loop/__tests__/message-builder.test.d.ts +5 -0
- package/dist/core/agent-loop/__tests__/message-builder.test.d.ts.map +1 -0
- package/dist/core/agent-loop/__tests__/message-builder.test.js +178 -0
- package/dist/core/agent-loop/__tests__/tool-executor.test.d.ts +5 -0
- package/dist/core/agent-loop/__tests__/tool-executor.test.d.ts.map +1 -0
- package/dist/core/agent-loop/__tests__/tool-executor.test.js +331 -0
- package/dist/core/agent-loop/compaction.d.ts +39 -0
- package/dist/core/agent-loop/compaction.d.ts.map +1 -0
- package/dist/core/agent-loop/compaction.js +51 -0
- package/dist/core/agent-loop/formatters.d.ts +21 -0
- package/dist/core/agent-loop/formatters.d.ts.map +1 -0
- package/dist/core/agent-loop/formatters.js +42 -0
- package/dist/core/agent-loop/index.d.ts +25 -0
- package/dist/core/agent-loop/index.d.ts.map +1 -0
- package/dist/core/agent-loop/index.js +83 -0
- package/dist/core/agent-loop/loop-state.d.ts +74 -0
- package/dist/core/agent-loop/loop-state.d.ts.map +1 -0
- package/dist/core/agent-loop/loop-state.js +147 -0
- package/dist/core/agent-loop/message-builder.d.ts +13 -0
- package/dist/core/agent-loop/message-builder.d.ts.map +1 -0
- package/dist/core/agent-loop/message-builder.js +49 -0
- package/dist/core/agent-loop/tool-executor.d.ts +23 -0
- package/dist/core/agent-loop/tool-executor.d.ts.map +1 -0
- package/dist/core/agent-loop/tool-executor.js +152 -0
- package/dist/core/agent-loop/turn-executor.d.ts +57 -0
- package/dist/core/agent-loop/turn-executor.d.ts.map +1 -0
- package/dist/core/agent-loop/turn-executor.js +124 -0
- package/dist/core/agent-loop/types.d.ts +141 -0
- package/dist/core/agent-loop/types.d.ts.map +1 -0
- package/dist/core/agent-loop/types.js +4 -0
- package/dist/core/agent-loop.d.ts +17 -0
- package/dist/core/agent-loop.d.ts.map +1 -0
- package/dist/core/agent-loop.js +16 -0
- package/dist/core/api-client-impl.d.ts +62 -0
- package/dist/core/api-client-impl.d.ts.map +1 -0
- package/dist/core/api-client-impl.js +479 -0
- package/dist/core/api-client.d.ts +6 -0
- package/dist/core/api-client.d.ts.map +1 -0
- package/dist/core/api-client.js +5 -0
- package/dist/core/checkpoints.d.ts +128 -0
- package/dist/core/checkpoints.d.ts.map +1 -0
- package/dist/core/checkpoints.js +438 -0
- package/dist/core/claude-md.d.ts +71 -0
- package/dist/core/claude-md.d.ts.map +1 -0
- package/dist/core/claude-md.js +198 -0
- package/dist/core/cognitive-security/hooks.d.ts +138 -0
- package/dist/core/cognitive-security/hooks.d.ts.map +1 -0
- package/dist/core/cognitive-security/hooks.js +389 -0
- package/dist/core/cognitive-security/index.d.ts +751 -0
- package/dist/core/cognitive-security/index.d.ts.map +1 -0
- package/dist/core/cognitive-security/index.js +1123 -0
- package/dist/core/cognitive-security/middleware.d.ts +136 -0
- package/dist/core/cognitive-security/middleware.d.ts.map +1 -0
- package/dist/core/cognitive-security/middleware.js +376 -0
- package/dist/core/config-loader.d.ts +127 -0
- package/dist/core/config-loader.d.ts.map +1 -0
- package/dist/core/config-loader.js +219 -0
- package/dist/core/context-compaction.d.ts +87 -0
- package/dist/core/context-compaction.d.ts.map +1 -0
- package/dist/core/context-compaction.js +428 -0
- package/dist/core/git-status.d.ts +25 -0
- package/dist/core/git-status.d.ts.map +1 -0
- package/dist/core/git-status.js +204 -0
- package/dist/core/image.d.ts +69 -0
- package/dist/core/image.d.ts.map +1 -0
- package/dist/core/image.js +290 -0
- package/dist/core/image.test.d.ts +2 -0
- package/dist/core/image.test.d.ts.map +1 -0
- package/dist/core/image.test.js +149 -0
- package/dist/core/models.d.ts +123 -0
- package/dist/core/models.d.ts.map +1 -0
- package/dist/core/models.js +325 -0
- package/dist/core/permissions.d.ts +81 -0
- package/dist/core/permissions.d.ts.map +1 -0
- package/dist/core/permissions.js +327 -0
- package/dist/core/retry.d.ts +25 -0
- package/dist/core/retry.d.ts.map +1 -0
- package/dist/core/retry.js +121 -0
- package/dist/core/session-store.d.ts +9 -0
- package/dist/core/session-store.d.ts.map +1 -0
- package/dist/core/session-store.js +10 -0
- package/dist/core/sessions/export.d.ts +47 -0
- package/dist/core/sessions/export.d.ts.map +1 -0
- package/dist/core/sessions/export.js +256 -0
- package/dist/core/sessions/index.d.ts +132 -0
- package/dist/core/sessions/index.d.ts.map +1 -0
- package/dist/core/sessions/index.js +442 -0
- package/dist/core/sessions/metadata.d.ts +77 -0
- package/dist/core/sessions/metadata.d.ts.map +1 -0
- package/dist/core/sessions/metadata.js +233 -0
- package/dist/core/sessions/persistence.d.ts +72 -0
- package/dist/core/sessions/persistence.d.ts.map +1 -0
- package/dist/core/sessions/persistence.js +201 -0
- package/dist/core/sessions/types.d.ts +110 -0
- package/dist/core/sessions/types.d.ts.map +1 -0
- package/dist/core/sessions/types.js +4 -0
- package/dist/core/stream-highlighter.d.ts +18 -0
- package/dist/core/stream-highlighter.d.ts.map +1 -0
- package/dist/core/stream-highlighter.js +916 -0
- package/dist/core/system-reminders.d.ts +89 -0
- package/dist/core/system-reminders.d.ts.map +1 -0
- package/dist/core/system-reminders.js +285 -0
- package/dist/ecosystem/hooks/__tests__/index.test.d.ts +5 -0
- package/dist/ecosystem/hooks/__tests__/index.test.d.ts.map +1 -0
- package/dist/ecosystem/hooks/__tests__/index.test.js +458 -0
- package/dist/ecosystem/hooks/index.d.ts +59 -0
- package/dist/ecosystem/hooks/index.d.ts.map +1 -0
- package/dist/ecosystem/hooks/index.js +294 -0
- package/dist/ecosystem/hooks/prompt-evaluator.d.ts +32 -0
- package/dist/ecosystem/hooks/prompt-evaluator.d.ts.map +1 -0
- package/dist/ecosystem/hooks/prompt-evaluator.js +229 -0
- package/dist/ecosystem/skills/index.d.ts +55 -0
- package/dist/ecosystem/skills/index.d.ts.map +1 -0
- package/dist/ecosystem/skills/index.js +258 -0
- package/dist/ecosystem/tools/__tests__/index.test.d.ts +7 -0
- package/dist/ecosystem/tools/__tests__/index.test.d.ts.map +1 -0
- package/dist/ecosystem/tools/__tests__/index.test.js +856 -0
- package/dist/ecosystem/tools/index.d.ts +24 -0
- package/dist/ecosystem/tools/index.d.ts.map +1 -0
- package/dist/ecosystem/tools/index.js +1709 -0
- package/dist/index.d.ts +24 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +33688 -49712
- package/dist/interfaces/mcp/client.d.ts +40 -0
- package/dist/interfaces/mcp/client.d.ts.map +1 -0
- package/dist/interfaces/mcp/client.js +309 -0
- package/dist/interfaces/ui/index.d.ts +36 -0
- package/dist/interfaces/ui/index.d.ts.map +1 -0
- package/dist/interfaces/ui/index.js +61 -0
- package/dist/interfaces/ui/spinner.d.ts +140 -0
- package/dist/interfaces/ui/spinner.d.ts.map +1 -0
- package/dist/interfaces/ui/spinner.js +342 -0
- package/dist/interfaces/ui/terminal/cli/index.d.ts +12 -0
- package/dist/interfaces/ui/terminal/cli/index.d.ts.map +1 -0
- package/dist/interfaces/ui/terminal/cli/index.js +32012 -50526
- package/dist/interfaces/ui/terminal/native/README.md +53 -0
- package/dist/interfaces/ui/terminal/native/claude_code_native.darwin-x64.node +0 -0
- package/dist/interfaces/ui/terminal/native/claude_code_native.dylib +0 -0
- package/dist/interfaces/ui/terminal/native/index.d.ts +0 -0
- package/dist/interfaces/ui/terminal/native/index.darwin-arm64.node +0 -0
- package/dist/interfaces/ui/terminal/native/index.js +43 -0
- package/dist/interfaces/ui/terminal/native/index.node +0 -0
- package/dist/interfaces/ui/terminal/native/package.json +34 -0
- package/dist/interfaces/ui/terminal/shared/args.d.ts +39 -0
- package/dist/interfaces/ui/terminal/shared/args.d.ts.map +1 -0
- package/dist/interfaces/ui/terminal/shared/args.js +176 -0
- package/dist/interfaces/ui/terminal/shared/index.d.ts +11 -0
- package/dist/interfaces/ui/terminal/shared/index.d.ts.map +1 -0
- package/dist/interfaces/ui/terminal/shared/index.js +16 -0
- package/dist/interfaces/ui/terminal/shared/loading-state.d.ts +124 -0
- package/dist/interfaces/ui/terminal/shared/loading-state.d.ts.map +1 -0
- package/dist/interfaces/ui/terminal/shared/loading-state.js +246 -0
- package/dist/interfaces/ui/terminal/shared/query.d.ts +22 -0
- package/dist/interfaces/ui/terminal/shared/query.d.ts.map +1 -0
- package/dist/interfaces/ui/terminal/shared/query.js +100 -0
- package/dist/interfaces/ui/terminal/shared/setup.d.ts +33 -0
- package/dist/interfaces/ui/terminal/shared/setup.d.ts.map +1 -0
- package/dist/interfaces/ui/terminal/shared/setup.js +226 -0
- package/dist/interfaces/ui/terminal/shared/status-line.d.ts +117 -0
- package/dist/interfaces/ui/terminal/shared/status-line.d.ts.map +1 -0
- package/dist/interfaces/ui/terminal/shared/status-line.js +267 -0
- package/dist/interfaces/ui/terminal/shared/system-prompt.d.ts +38 -0
- package/dist/interfaces/ui/terminal/shared/system-prompt.d.ts.map +1 -0
- package/dist/interfaces/ui/terminal/shared/system-prompt.js +102 -0
- package/dist/interfaces/ui/terminal/tui/HelpPanel.d.ts +39 -0
- package/dist/interfaces/ui/terminal/tui/HelpPanel.d.ts.map +1 -0
- package/dist/interfaces/ui/terminal/tui/HelpPanel.js +215 -0
- package/dist/interfaces/ui/terminal/tui/InputContext.d.ts +91 -0
- package/dist/interfaces/ui/terminal/tui/InputContext.d.ts.map +1 -0
- package/dist/interfaces/ui/terminal/tui/InputContext.js +154 -0
- package/dist/interfaces/ui/terminal/tui/InputField.d.ts +18 -0
- package/dist/interfaces/ui/terminal/tui/InputField.d.ts.map +1 -0
- package/dist/interfaces/ui/terminal/tui/InputField.js +41 -0
- package/dist/interfaces/ui/terminal/tui/InteractiveTUI.d.ts +16 -0
- package/dist/interfaces/ui/terminal/tui/InteractiveTUI.d.ts.map +1 -0
- package/dist/interfaces/ui/terminal/tui/InteractiveTUI.js +451 -0
- package/dist/interfaces/ui/terminal/tui/MessageArea.d.ts +10 -0
- package/dist/interfaces/ui/terminal/tui/MessageArea.d.ts.map +1 -0
- package/dist/interfaces/ui/terminal/tui/MessageArea.js +91 -0
- package/dist/interfaces/ui/terminal/tui/MessageStore.d.ts +48 -0
- package/dist/interfaces/ui/terminal/tui/MessageStore.d.ts.map +1 -0
- package/dist/interfaces/ui/terminal/tui/MessageStore.js +151 -0
- package/dist/interfaces/ui/terminal/tui/StatusBar.d.ts +9 -0
- package/dist/interfaces/ui/terminal/tui/StatusBar.d.ts.map +1 -0
- package/dist/interfaces/ui/terminal/tui/StatusBar.js +36 -0
- package/dist/interfaces/ui/terminal/tui/commands.d.ts +21 -0
- package/dist/interfaces/ui/terminal/tui/commands.d.ts.map +1 -0
- package/dist/interfaces/ui/terminal/tui/commands.js +359 -0
- package/dist/interfaces/ui/terminal/tui/components/InteractiveElements.d.ts +115 -0
- package/dist/interfaces/ui/terminal/tui/components/InteractiveElements.d.ts.map +1 -0
- package/dist/interfaces/ui/terminal/tui/components/InteractiveElements.js +306 -0
- package/dist/interfaces/ui/terminal/tui/components/MultilineInput.d.ts +92 -0
- package/dist/interfaces/ui/terminal/tui/components/MultilineInput.d.ts.map +1 -0
- package/dist/interfaces/ui/terminal/tui/components/MultilineInput.js +399 -0
- package/dist/interfaces/ui/terminal/tui/components/PaneManager.d.ts +59 -0
- package/dist/interfaces/ui/terminal/tui/components/PaneManager.d.ts.map +1 -0
- package/dist/interfaces/ui/terminal/tui/components/PaneManager.js +139 -0
- package/dist/interfaces/ui/terminal/tui/components/Sidebar.d.ts +68 -0
- package/dist/interfaces/ui/terminal/tui/components/Sidebar.d.ts.map +1 -0
- package/dist/interfaces/ui/terminal/tui/components/Sidebar.js +340 -0
- package/dist/interfaces/ui/terminal/tui/components/index.d.ts +23 -0
- package/dist/interfaces/ui/terminal/tui/components/index.d.ts.map +1 -0
- package/dist/interfaces/ui/terminal/tui/components/index.js +51 -0
- package/dist/interfaces/ui/terminal/tui/console.d.ts +20 -0
- package/dist/interfaces/ui/terminal/tui/console.d.ts.map +1 -0
- package/dist/interfaces/ui/terminal/tui/console.js +46 -0
- package/dist/interfaces/ui/terminal/tui/index.d.ts +20 -0
- package/dist/interfaces/ui/terminal/tui/index.d.ts.map +1 -0
- package/dist/interfaces/ui/terminal/tui/index.js +28 -0
- package/dist/interfaces/ui/terminal/tui/run.d.ts +13 -0
- package/dist/interfaces/ui/terminal/tui/run.d.ts.map +1 -0
- package/dist/interfaces/ui/terminal/tui/run.js +31 -0
- package/dist/interfaces/ui/terminal/tui/spinner.d.ts +44 -0
- package/dist/interfaces/ui/terminal/tui/spinner.d.ts.map +1 -0
- package/dist/interfaces/ui/terminal/tui/spinner.js +59 -0
- package/dist/interfaces/ui/terminal/tui/tui-app.d.ts +39 -0
- package/dist/interfaces/ui/terminal/tui/tui-app.d.ts.map +1 -0
- package/dist/interfaces/ui/terminal/tui/tui-app.js +198 -0
- package/dist/interfaces/ui/terminal/tui/tui-footer.d.ts +167 -0
- package/dist/interfaces/ui/terminal/tui/tui-footer.d.ts.map +1 -0
- package/dist/interfaces/ui/terminal/tui/tui-footer.js +330 -0
- package/dist/interfaces/ui/terminal/tui/types.d.ts +165 -0
- package/dist/interfaces/ui/terminal/tui/types.d.ts.map +1 -0
- package/dist/interfaces/ui/terminal/tui/types.js +5 -0
- package/dist/interfaces/ui/terminal/tui/useInputHandler.d.ts +23 -0
- package/dist/interfaces/ui/terminal/tui/useInputHandler.d.ts.map +1 -0
- package/dist/interfaces/ui/terminal/tui/useInputHandler.js +72 -0
- package/dist/interfaces/ui/terminal/tui/useNativeInput.d.ts +90 -0
- package/dist/interfaces/ui/terminal/tui/useNativeInput.d.ts.map +1 -0
- package/dist/interfaces/ui/terminal/tui/useNativeInput.js +188 -0
- package/dist/native/README.md +53 -0
- package/dist/native/claude_code_native.darwin-x64.node +0 -0
- package/dist/native/claude_code_native.dylib +0 -0
- package/dist/native/index.d.ts +0 -0
- package/dist/native/index.d.ts.map +1 -0
- package/dist/native/index.darwin-arm64.node +0 -0
- package/dist/native/index.js +43 -0
- package/dist/native/index.node +0 -0
- package/dist/native/package.json +34 -0
- package/dist/teammates/index.d.ts +161 -0
- package/dist/teammates/index.d.ts.map +1 -0
- package/dist/teammates/index.js +827 -0
- package/dist/types/index.d.ts +482 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +52 -0
- package/native/index.darwin-arm64.node +0 -0
- package/native/index.js +33 -19
- package/package.json +6 -3
- package/packages/src/core/__tests__/permissions.test.ts +1091 -0
- package/packages/src/core/agent-loop/__tests__/compaction.test.ts +283 -0
- package/packages/src/core/agent-loop/__tests__/formatters.test.ts +234 -0
- package/packages/src/core/agent-loop/__tests__/index.test.ts +162 -0
- package/packages/src/core/agent-loop/__tests__/loop-state.test.ts +413 -0
- package/packages/src/core/agent-loop/__tests__/message-builder.test.ts +229 -0
- package/packages/src/core/agent-loop/__tests__/tool-executor.test.ts +457 -0
- package/packages/src/core/agent-loop/compaction.ts +92 -0
- package/packages/src/core/agent-loop/formatters.ts +50 -0
- package/packages/src/core/agent-loop/index.ts +137 -0
- package/packages/src/core/agent-loop/loop-state.ts +187 -0
- package/packages/src/core/agent-loop/message-builder.ts +62 -0
- package/packages/src/core/agent-loop/tool-executor.ts +211 -0
- package/packages/src/core/agent-loop/turn-executor.ts +226 -0
- package/packages/src/core/agent-loop/types.ts +152 -0
- package/packages/src/core/agent-loop.ts +18 -0
- package/packages/src/core/api-client-impl.ts +729 -0
- package/packages/src/core/api-client.ts +6 -0
- package/packages/src/core/checkpoints.ts +606 -0
- package/packages/src/core/claude-md.ts +272 -0
- package/packages/src/core/cognitive-security/hooks.ts +591 -0
- package/packages/src/core/cognitive-security/index.ts +2041 -0
- package/packages/src/core/cognitive-security/middleware.ts +536 -0
- package/packages/src/core/config/todo +7 -0
- package/packages/src/core/config-loader.ts +324 -0
- package/packages/src/core/context/__tests__/integration.test.ts +334 -0
- package/packages/src/core/context/compaction.ts +170 -0
- package/packages/src/core/context/constants.ts +58 -0
- package/packages/src/core/context/extraction.ts +85 -0
- package/packages/src/core/context/index.ts +66 -0
- package/packages/src/core/context/summarization.ts +251 -0
- package/packages/src/core/context/token-estimation.ts +98 -0
- package/packages/src/core/context/types.ts +59 -0
- package/packages/src/core/git-status.ts +262 -0
- package/packages/src/core/image.test.ts +180 -0
- package/packages/src/core/image.ts +350 -0
- package/packages/src/core/lmdb.db +0 -0
- package/packages/src/core/lmdb.db-lock +0 -0
- package/packages/src/core/models.ts +507 -0
- package/packages/src/core/normalizers/todo +8 -0
- package/packages/src/core/permissions.ts +431 -0
- package/packages/src/core/providers/README.md +230 -0
- package/packages/src/core/providers/__tests__/providers.test.ts +135 -0
- package/packages/src/core/providers/index.ts +419 -0
- package/packages/src/core/providers/types.ts +132 -0
- package/packages/src/core/retry.ts +180 -0
- package/packages/src/core/session-store.ts +36 -0
- package/packages/src/core/sessions/export.ts +329 -0
- package/packages/src/core/sessions/index.ts +587 -0
- package/packages/src/core/sessions/metadata.ts +309 -0
- package/packages/src/core/sessions/persistence.ts +244 -0
- package/packages/src/core/sessions/types.ts +169 -0
- package/packages/src/core/stream-highlighter.ts +1123 -0
- package/packages/src/core/system-reminders.ts +402 -0
- package/packages/src/core/todo +8 -0
- package/packages/src/ecosystem/hooks/__tests__/index.test.ts +561 -0
- package/packages/src/ecosystem/hooks/index.ts +341 -0
- package/packages/src/ecosystem/hooks/prompt-evaluator.ts +300 -0
- package/packages/src/ecosystem/skills/index.ts +295 -0
- package/packages/src/ecosystem/tools/__tests__/index.test.ts +1335 -0
- package/packages/src/ecosystem/tools/index.ts +2051 -0
- package/packages/src/index.ts +141 -0
- package/packages/src/interfaces/mcp/client.ts +389 -0
- package/packages/src/interfaces/ui/index.ts +158 -0
- package/packages/src/interfaces/ui/lmdb.db +0 -0
- package/packages/src/interfaces/ui/lmdb.db-lock +0 -0
- package/packages/src/interfaces/ui/spinner.ts +451 -0
- package/packages/src/interfaces/ui/terminal/bridge/index.ts +370 -0
- package/packages/src/interfaces/ui/terminal/bridge/ipc.ts +829 -0
- package/packages/src/interfaces/ui/terminal/bridge/screen-export.ts +968 -0
- package/packages/src/interfaces/ui/terminal/bridge/types.ts +226 -0
- package/packages/src/interfaces/ui/terminal/bridge/useBridge.ts +210 -0
- package/packages/src/interfaces/ui/terminal/cli/bootstrap.ts +132 -0
- package/packages/src/interfaces/ui/terminal/cli/index.ts +415 -0
- package/packages/src/interfaces/ui/terminal/cli/interactive/index.ts +110 -0
- package/packages/src/interfaces/ui/terminal/cli/interactive/input-handler.ts +393 -0
- package/packages/src/interfaces/ui/terminal/cli/interactive/interactive-runner.ts +820 -0
- package/packages/src/interfaces/ui/terminal/cli/interactive/message-store.ts +299 -0
- package/packages/src/interfaces/ui/terminal/cli/interactive/types.ts +274 -0
- package/packages/src/interfaces/ui/terminal/lmdb.db +0 -0
- package/packages/src/interfaces/ui/terminal/lmdb.db-lock +0 -0
- package/packages/src/interfaces/ui/terminal/shared/args.ts +222 -0
- package/packages/src/interfaces/ui/terminal/shared/index.ts +84 -0
- package/packages/src/interfaces/ui/terminal/shared/loading-state.ts +322 -0
- package/packages/src/interfaces/ui/terminal/shared/query.ts +152 -0
- package/packages/src/interfaces/ui/terminal/shared/setup.ts +299 -0
- package/packages/src/interfaces/ui/terminal/shared/spinner-frames.ts +73 -0
- package/packages/src/interfaces/ui/terminal/shared/status-line.ts +366 -0
- package/packages/src/interfaces/ui/terminal/shared/system-prompt.ts +146 -0
- package/packages/src/lmdb.db +0 -0
- package/packages/src/lmdb.db-lock +0 -0
- package/packages/src/native/index.ts +2722 -0
- package/packages/src/native/tui_v2_types.ts +39 -0
- package/packages/src/teammates/coordination.test.ts +279 -0
- package/packages/src/teammates/coordination.ts +646 -0
- package/packages/src/teammates/index.ts +1052 -0
- package/packages/src/teammates/integration.test.ts +272 -0
- package/packages/src/teammates/runner.test.ts +235 -0
- package/packages/src/teammates/runner.ts +750 -0
- package/packages/src/teammates/schemas.ts +673 -0
- package/packages/src/types/index.ts +723 -0
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Loop State - Mutable state management for the agent loop
|
|
3
|
+
*/
|
|
4
|
+
import type { Message, ToolUseBlock, QueryMetrics, CacheMetrics, UsageMetrics } from "../../types/index.js";
|
|
5
|
+
import type { CompactionResult, getCompactionStats } from "../context-compaction.js";
|
|
6
|
+
/**
|
|
7
|
+
* Creates an initial cache metrics object
|
|
8
|
+
*/
|
|
9
|
+
export declare function createInitialCacheMetrics(): CacheMetrics;
|
|
10
|
+
/**
|
|
11
|
+
* LoopState class encapsulates all mutable state during the agent loop
|
|
12
|
+
*/
|
|
13
|
+
export declare class LoopState {
|
|
14
|
+
messages: Message[];
|
|
15
|
+
metrics: QueryMetrics[];
|
|
16
|
+
allToolsUsed: ToolUseBlock[];
|
|
17
|
+
totalCost: number;
|
|
18
|
+
totalDuration: number;
|
|
19
|
+
turnNumber: number;
|
|
20
|
+
previousCost: number;
|
|
21
|
+
compactionCount: number;
|
|
22
|
+
totalTokensCompacted: number;
|
|
23
|
+
cacheMetrics: CacheMetrics;
|
|
24
|
+
constructor(initialMessages: Message[]);
|
|
25
|
+
/**
|
|
26
|
+
* Get the latest metrics entry
|
|
27
|
+
*/
|
|
28
|
+
get latestMetrics(): QueryMetrics | undefined;
|
|
29
|
+
/**
|
|
30
|
+
* Get usage for reminder building (with fallback)
|
|
31
|
+
*/
|
|
32
|
+
get currentUsage(): UsageMetrics;
|
|
33
|
+
/**
|
|
34
|
+
* Add a turn's results to the state
|
|
35
|
+
*/
|
|
36
|
+
addTurnResult(result: {
|
|
37
|
+
message: {
|
|
38
|
+
content: unknown[];
|
|
39
|
+
stop_reason: string | null;
|
|
40
|
+
id: string;
|
|
41
|
+
};
|
|
42
|
+
usage: UsageMetrics;
|
|
43
|
+
cacheMetrics?: CacheMetrics;
|
|
44
|
+
costUSD: number;
|
|
45
|
+
durationMs: number;
|
|
46
|
+
model: string;
|
|
47
|
+
messageCount: number;
|
|
48
|
+
}): QueryMetrics;
|
|
49
|
+
/**
|
|
50
|
+
* Add assistant message to history
|
|
51
|
+
*/
|
|
52
|
+
addAssistantMessage(content: unknown[]): void;
|
|
53
|
+
/**
|
|
54
|
+
* Add user message (tool results) to history
|
|
55
|
+
*/
|
|
56
|
+
addUserMessage(content: import("../../types/index.js").ToolResultBlock[]): void;
|
|
57
|
+
/**
|
|
58
|
+
* Track tool usage
|
|
59
|
+
*/
|
|
60
|
+
trackToolUse(toolUseBlocks: ToolUseBlock[]): void;
|
|
61
|
+
/**
|
|
62
|
+
* Apply compaction result to state
|
|
63
|
+
*/
|
|
64
|
+
applyCompaction(compactionResult: CompactionResult, getStats: typeof getCompactionStats): boolean;
|
|
65
|
+
/**
|
|
66
|
+
* Increment turn counter
|
|
67
|
+
*/
|
|
68
|
+
incrementTurn(): number;
|
|
69
|
+
/**
|
|
70
|
+
* Convert to AgentLoopResult
|
|
71
|
+
*/
|
|
72
|
+
toResult(): import("./types.js").AgentLoopResult;
|
|
73
|
+
}
|
|
74
|
+
//# sourceMappingURL=loop-state.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"loop-state.d.ts","sourceRoot":"","sources":["../../../packages/src/core/agent-loop/loop-state.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EACV,OAAO,EACP,YAAY,EACZ,YAAY,EACZ,YAAY,EACZ,YAAY,EACb,MAAM,sBAAsB,CAAC;AAC9B,OAAO,KAAK,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAErF;;GAEG;AACH,wBAAgB,yBAAyB,IAAI,YAAY,CASxD;AAED;;GAEG;AACH,qBAAa,SAAS;IACpB,QAAQ,EAAE,OAAO,EAAE,CAAC;IACpB,OAAO,EAAE,YAAY,EAAE,CAAM;IAC7B,YAAY,EAAE,YAAY,EAAE,CAAM;IAClC,SAAS,SAAK;IACd,aAAa,SAAK;IAClB,UAAU,SAAK;IACf,YAAY,SAAK;IACjB,eAAe,SAAK;IACpB,oBAAoB,SAAK;IACzB,YAAY,EAAE,YAAY,CAAC;gBAEf,eAAe,EAAE,OAAO,EAAE;IAKtC;;OAEG;IACH,IAAI,aAAa,IAAI,YAAY,GAAG,SAAS,CAE5C;IAED;;OAEG;IACH,IAAI,YAAY,IAAI,YAAY,CAK/B;IAED;;OAEG;IACH,aAAa,CAAC,MAAM,EAAE;QACpB,OAAO,EAAE;YAAE,OAAO,EAAE,OAAO,EAAE,CAAC;YAAC,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;YAAC,EAAE,EAAE,MAAM,CAAA;SAAE,CAAC;QACxE,KAAK,EAAE,YAAY,CAAC;QACpB,YAAY,CAAC,EAAE,YAAY,CAAC;QAC5B,OAAO,EAAE,MAAM,CAAC;QAChB,UAAU,EAAE,MAAM,CAAC;QACnB,KAAK,EAAE,MAAM,CAAC;QACd,YAAY,EAAE,MAAM,CAAC;KACtB,GAAG,YAAY;IAqChB;;OAEG;IACH,mBAAmB,CAAC,OAAO,EAAE,OAAO,EAAE,GAAG,IAAI;IAO7C;;OAEG;IACH,cAAc,CAAC,OAAO,EAAE,OAAO,sBAAsB,EAAE,eAAe,EAAE,GAAG,IAAI;IAO/E;;OAEG;IACH,YAAY,CAAC,aAAa,EAAE,YAAY,EAAE,GAAG,IAAI;IAIjD;;OAEG;IACH,eAAe,CACb,gBAAgB,EAAE,gBAAgB,EAClC,QAAQ,EAAE,OAAO,kBAAkB,GAClC,OAAO;IAoBV;;OAEG;IACH,aAAa,IAAI,MAAM;IAIvB;;OAEG;IACH,QAAQ,IAAI,OAAO,YAAY,EAAE,eAAe;CAWjD"}
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Loop State - Mutable state management for the agent loop
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Creates an initial cache metrics object
|
|
6
|
+
*/
|
|
7
|
+
export function createInitialCacheMetrics() {
|
|
8
|
+
return {
|
|
9
|
+
cacheHits: 0,
|
|
10
|
+
cacheMisses: 0,
|
|
11
|
+
totalCacheReadTokens: 0,
|
|
12
|
+
totalCacheWriteTokens: 0,
|
|
13
|
+
cacheHitRate: 0,
|
|
14
|
+
estimatedSavingsUSD: 0,
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* LoopState class encapsulates all mutable state during the agent loop
|
|
19
|
+
*/
|
|
20
|
+
export class LoopState {
|
|
21
|
+
messages;
|
|
22
|
+
metrics = [];
|
|
23
|
+
allToolsUsed = [];
|
|
24
|
+
totalCost = 0;
|
|
25
|
+
totalDuration = 0;
|
|
26
|
+
turnNumber = 0;
|
|
27
|
+
previousCost = 0;
|
|
28
|
+
compactionCount = 0;
|
|
29
|
+
totalTokensCompacted = 0;
|
|
30
|
+
cacheMetrics;
|
|
31
|
+
constructor(initialMessages) {
|
|
32
|
+
this.messages = [...initialMessages];
|
|
33
|
+
this.cacheMetrics = createInitialCacheMetrics();
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Get the latest metrics entry
|
|
37
|
+
*/
|
|
38
|
+
get latestMetrics() {
|
|
39
|
+
return this.metrics[this.metrics.length - 1];
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Get usage for reminder building (with fallback)
|
|
43
|
+
*/
|
|
44
|
+
get currentUsage() {
|
|
45
|
+
return this.latestMetrics?.usage ?? {
|
|
46
|
+
input_tokens: 0,
|
|
47
|
+
output_tokens: 0,
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Add a turn's results to the state
|
|
52
|
+
*/
|
|
53
|
+
addTurnResult(result) {
|
|
54
|
+
const queryMetrics = {
|
|
55
|
+
model: result.model,
|
|
56
|
+
messageCount: result.messageCount,
|
|
57
|
+
messageTokens: result.usage.input_tokens + result.usage.output_tokens,
|
|
58
|
+
usage: result.usage,
|
|
59
|
+
cacheMetrics: result.cacheMetrics,
|
|
60
|
+
durationMs: result.durationMs,
|
|
61
|
+
ttftMs: 0, // Will be set by caller if available
|
|
62
|
+
costUSD: result.costUSD,
|
|
63
|
+
stopReason: result.message.stop_reason,
|
|
64
|
+
requestId: result.message.id,
|
|
65
|
+
};
|
|
66
|
+
this.metrics.push(queryMetrics);
|
|
67
|
+
this.previousCost = this.totalCost;
|
|
68
|
+
this.totalCost += result.costUSD;
|
|
69
|
+
this.totalDuration += result.durationMs;
|
|
70
|
+
// Aggregate cache metrics
|
|
71
|
+
if (result.cacheMetrics) {
|
|
72
|
+
this.cacheMetrics.cacheHits += result.cacheMetrics.cacheHits;
|
|
73
|
+
this.cacheMetrics.cacheMisses += result.cacheMetrics.cacheMisses;
|
|
74
|
+
this.cacheMetrics.totalCacheReadTokens += result.cacheMetrics.totalCacheReadTokens;
|
|
75
|
+
this.cacheMetrics.totalCacheWriteTokens += result.cacheMetrics.totalCacheWriteTokens;
|
|
76
|
+
this.cacheMetrics.estimatedSavingsUSD += result.cacheMetrics.estimatedSavingsUSD;
|
|
77
|
+
}
|
|
78
|
+
// Update cache hit rate
|
|
79
|
+
const totalCacheOps = this.cacheMetrics.cacheHits + this.cacheMetrics.cacheMisses;
|
|
80
|
+
this.cacheMetrics.cacheHitRate = totalCacheOps > 0
|
|
81
|
+
? this.cacheMetrics.cacheHits / totalCacheOps
|
|
82
|
+
: 0;
|
|
83
|
+
return queryMetrics;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Add assistant message to history
|
|
87
|
+
*/
|
|
88
|
+
addAssistantMessage(content) {
|
|
89
|
+
this.messages.push({
|
|
90
|
+
role: "assistant",
|
|
91
|
+
content: content,
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Add user message (tool results) to history
|
|
96
|
+
*/
|
|
97
|
+
addUserMessage(content) {
|
|
98
|
+
this.messages.push({
|
|
99
|
+
role: "user",
|
|
100
|
+
content,
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Track tool usage
|
|
105
|
+
*/
|
|
106
|
+
trackToolUse(toolUseBlocks) {
|
|
107
|
+
this.allToolsUsed.push(...toolUseBlocks);
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Apply compaction result to state
|
|
111
|
+
*/
|
|
112
|
+
applyCompaction(compactionResult, getStats) {
|
|
113
|
+
// Only apply compaction if it actually saved tokens
|
|
114
|
+
if (!compactionResult.didCompact || compactionResult.tokensAfter >= compactionResult.tokensBefore) {
|
|
115
|
+
return false;
|
|
116
|
+
}
|
|
117
|
+
// Replace messages array content
|
|
118
|
+
this.messages.length = 0;
|
|
119
|
+
this.messages.push(...compactionResult.messages);
|
|
120
|
+
this.compactionCount++;
|
|
121
|
+
const tokensSaved = compactionResult.tokensBefore - compactionResult.tokensAfter;
|
|
122
|
+
this.totalTokensCompacted += tokensSaved;
|
|
123
|
+
const stats = getStats(compactionResult);
|
|
124
|
+
console.log(`Context compacted: ${stats.reductionPercent}% reduction, ${stats.tokensSaved} tokens saved`);
|
|
125
|
+
return true;
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Increment turn counter
|
|
129
|
+
*/
|
|
130
|
+
incrementTurn() {
|
|
131
|
+
return ++this.turnNumber;
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Convert to AgentLoopResult
|
|
135
|
+
*/
|
|
136
|
+
toResult() {
|
|
137
|
+
return {
|
|
138
|
+
messages: this.messages,
|
|
139
|
+
metrics: this.metrics,
|
|
140
|
+
totalCost: this.totalCost,
|
|
141
|
+
totalDuration: this.totalDuration,
|
|
142
|
+
totalCacheMetrics: this.cacheMetrics,
|
|
143
|
+
compactionCount: this.compactionCount,
|
|
144
|
+
totalTokensCompacted: this.totalTokensCompacted,
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Message Builder - API message construction with reminder injection
|
|
3
|
+
*/
|
|
4
|
+
import type { Message, ContentBlock } from "../../types/index.js";
|
|
5
|
+
/**
|
|
6
|
+
* Build API messages with system reminders injected
|
|
7
|
+
*/
|
|
8
|
+
export declare function buildAPIMessages(messages: Message[], systemPrompt: string, systemReminder?: string): Message[];
|
|
9
|
+
/**
|
|
10
|
+
* Inject system reminder into content blocks
|
|
11
|
+
*/
|
|
12
|
+
export declare function injectReminderIntoContent(content: ContentBlock[], reminder: string): ContentBlock[];
|
|
13
|
+
//# sourceMappingURL=message-builder.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"message-builder.d.ts","sourceRoot":"","sources":["../../../packages/src/core/agent-loop/message-builder.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,YAAY,EAAa,MAAM,sBAAsB,CAAC;AAE7E;;GAEG;AACH,wBAAgB,gBAAgB,CAC9B,QAAQ,EAAE,OAAO,EAAE,EACnB,YAAY,EAAE,MAAM,EACpB,cAAc,CAAC,EAAE,MAAM,GACtB,OAAO,EAAE,CAuBX;AAED;;GAEG;AACH,wBAAgB,yBAAyB,CACvC,OAAO,EAAE,YAAY,EAAE,EACvB,QAAQ,EAAE,MAAM,GACf,YAAY,EAAE,CAiBhB"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Message Builder - API message construction with reminder injection
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Build API messages with system reminders injected
|
|
6
|
+
*/
|
|
7
|
+
export function buildAPIMessages(messages, systemPrompt, systemReminder) {
|
|
8
|
+
// If we have a system reminder, inject it into the last user message
|
|
9
|
+
if (systemReminder && messages.length > 0) {
|
|
10
|
+
const result = [...messages];
|
|
11
|
+
// Find the last user message
|
|
12
|
+
for (let i = result.length - 1; i >= 0; i--) {
|
|
13
|
+
const msg = result[i];
|
|
14
|
+
if (msg && msg.role === "user") {
|
|
15
|
+
// Clone the message to avoid mutating original
|
|
16
|
+
const updatedMessage = {
|
|
17
|
+
role: "user",
|
|
18
|
+
content: Array.isArray(msg.content)
|
|
19
|
+
? injectReminderIntoContent(msg.content, systemReminder)
|
|
20
|
+
: [{ type: "text", text: `${String(msg.content)}\n\n${systemReminder}` }],
|
|
21
|
+
};
|
|
22
|
+
result[i] = updatedMessage;
|
|
23
|
+
break;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return result;
|
|
27
|
+
}
|
|
28
|
+
return messages;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Inject system reminder into content blocks
|
|
32
|
+
*/
|
|
33
|
+
export function injectReminderIntoContent(content, reminder) {
|
|
34
|
+
// Check if the last block is a text block we can append to
|
|
35
|
+
if (content.length > 0) {
|
|
36
|
+
const lastBlock = content[content.length - 1];
|
|
37
|
+
if (lastBlock && lastBlock.type === "text") {
|
|
38
|
+
// Append to existing text block
|
|
39
|
+
const textBlock = {
|
|
40
|
+
type: "text",
|
|
41
|
+
text: `${lastBlock.text}\n\n${reminder}`,
|
|
42
|
+
};
|
|
43
|
+
return [...content.slice(0, -1), textBlock];
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
// Add as new text block
|
|
47
|
+
const newBlock = { type: "text", text: `\n\n${reminder}` };
|
|
48
|
+
return [...content, newBlock];
|
|
49
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tool Executor - Parallel tool execution with hooks and permissions
|
|
3
|
+
*/
|
|
4
|
+
import type { ToolDefinition, ToolUseBlock, ToolResultBlock, ToolResult, PermissionMode } from "../../types/index.js";
|
|
5
|
+
import type { HookManager } from "../../ecosystem/hooks/index.js";
|
|
6
|
+
export interface ToolExecutionOptions {
|
|
7
|
+
tools: ToolDefinition[];
|
|
8
|
+
workingDirectory: string;
|
|
9
|
+
permissionMode: PermissionMode;
|
|
10
|
+
hookManager?: HookManager;
|
|
11
|
+
sessionId?: string;
|
|
12
|
+
signal?: AbortSignal;
|
|
13
|
+
permissionManager: import("../permissions.js").PermissionManager;
|
|
14
|
+
onToolResult?: (result: {
|
|
15
|
+
id: string;
|
|
16
|
+
result: ToolResult;
|
|
17
|
+
}) => void;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Execute multiple tools in parallel and collect results
|
|
21
|
+
*/
|
|
22
|
+
export declare function executeTools(toolUseBlocks: ToolUseBlock[], options: ToolExecutionOptions): Promise<ToolResultBlock[]>;
|
|
23
|
+
//# sourceMappingURL=tool-executor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tool-executor.d.ts","sourceRoot":"","sources":["../../../packages/src/core/agent-loop/tool-executor.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EACV,cAAc,EACd,YAAY,EACZ,eAAe,EACf,UAAU,EACV,cAAc,EACf,MAAM,sBAAsB,CAAC;AAE9B,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gCAAgC,CAAC;AAClE,MAAM,WAAW,oBAAoB;IACnC,KAAK,EAAE,cAAc,EAAE,CAAC;IACxB,gBAAgB,EAAE,MAAM,CAAC;IACzB,cAAc,EAAE,cAAc,CAAC;IAC/B,WAAW,CAAC,EAAE,WAAW,CAAC;IAC1B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB,iBAAiB,EAAE,OAAO,mBAAmB,EAAE,iBAAiB,CAAC;IACjE,YAAY,CAAC,EAAE,CAAC,MAAM,EAAE;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,UAAU,CAAA;KAAE,KAAK,IAAI,CAAC;CACrE;AA8JD;;GAEG;AACH,wBAAsB,YAAY,CAChC,aAAa,EAAE,YAAY,EAAE,EAC7B,OAAO,EAAE,oBAAoB,GAC5B,OAAO,CAAC,eAAe,EAAE,CAAC,CAwB5B"}
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tool Executor - Parallel tool execution with hooks and permissions
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Execute a single tool with permission checks and hooks
|
|
6
|
+
*/
|
|
7
|
+
async function executeSingleTool(toolUse, options) {
|
|
8
|
+
const { tools, workingDirectory, permissionMode, hookManager, sessionId, signal, permissionManager } = options;
|
|
9
|
+
const tool = tools.find((t) => t.name === toolUse.name);
|
|
10
|
+
if (!tool) {
|
|
11
|
+
return {
|
|
12
|
+
toolUseId: toolUse.id,
|
|
13
|
+
result: {
|
|
14
|
+
type: "tool_result",
|
|
15
|
+
tool_use_id: toolUse.id,
|
|
16
|
+
content: `Error: Unknown tool "${toolUse.name}"`,
|
|
17
|
+
is_error: true,
|
|
18
|
+
},
|
|
19
|
+
toolResult: null,
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
// Check permissions using PermissionManager
|
|
23
|
+
const permissionResult = await permissionManager.checkPermission(tool.name, toolUse.input);
|
|
24
|
+
if (permissionResult.decision === "deny" || permissionResult.decision === "denyAlways") {
|
|
25
|
+
return {
|
|
26
|
+
toolUseId: toolUse.id,
|
|
27
|
+
result: {
|
|
28
|
+
type: "tool_result",
|
|
29
|
+
tool_use_id: toolUse.id,
|
|
30
|
+
content: `Permission denied for tool "${toolUse.name}"${permissionResult.reason ? `: ${permissionResult.reason}` : ""}`,
|
|
31
|
+
is_error: true,
|
|
32
|
+
},
|
|
33
|
+
toolResult: null,
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
// Execute PreToolUse hooks
|
|
37
|
+
if (hookManager) {
|
|
38
|
+
const hookResult = await hookManager.execute("PreToolUse", {
|
|
39
|
+
tool_name: tool.name,
|
|
40
|
+
tool_input: toolUse.input,
|
|
41
|
+
session_id: sessionId,
|
|
42
|
+
});
|
|
43
|
+
if (hookResult.decision === "deny" || hookResult.decision === "block") {
|
|
44
|
+
return {
|
|
45
|
+
toolUseId: toolUse.id,
|
|
46
|
+
result: {
|
|
47
|
+
type: "tool_result",
|
|
48
|
+
tool_use_id: toolUse.id,
|
|
49
|
+
content: hookResult.reason || `Tool "${tool.name}" blocked by hook`,
|
|
50
|
+
is_error: true,
|
|
51
|
+
},
|
|
52
|
+
toolResult: null,
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
// Apply modified input if provided
|
|
56
|
+
if (hookResult.modified_input) {
|
|
57
|
+
Object.assign(toolUse.input, hookResult.modified_input);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
// Execute tool
|
|
61
|
+
try {
|
|
62
|
+
const handlerResult = await tool.handler(toolUse.input, {
|
|
63
|
+
workingDirectory,
|
|
64
|
+
permissionMode,
|
|
65
|
+
abortSignal: signal,
|
|
66
|
+
});
|
|
67
|
+
// Execute PostToolUse hooks
|
|
68
|
+
let finalContent = handlerResult.content;
|
|
69
|
+
if (hookManager) {
|
|
70
|
+
const hookResult = await hookManager.execute("PostToolUse", {
|
|
71
|
+
tool_name: tool.name,
|
|
72
|
+
tool_input: toolUse.input,
|
|
73
|
+
tool_result: handlerResult,
|
|
74
|
+
tool_result_is_error: handlerResult.is_error,
|
|
75
|
+
session_id: sessionId,
|
|
76
|
+
});
|
|
77
|
+
if (hookResult.decision === "deny" || hookResult.decision === "block") {
|
|
78
|
+
return {
|
|
79
|
+
toolUseId: toolUse.id,
|
|
80
|
+
result: {
|
|
81
|
+
type: "tool_result",
|
|
82
|
+
tool_use_id: toolUse.id,
|
|
83
|
+
content: hookResult.reason || `Tool "${tool.name}" result blocked by hook`,
|
|
84
|
+
is_error: true,
|
|
85
|
+
},
|
|
86
|
+
toolResult: null,
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
// Apply modified output if provided
|
|
90
|
+
if (hookResult.modified_input?.tool_result) {
|
|
91
|
+
finalContent = hookResult.modified_input.tool_result;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
return {
|
|
95
|
+
toolUseId: toolUse.id,
|
|
96
|
+
result: {
|
|
97
|
+
type: "tool_result",
|
|
98
|
+
tool_use_id: toolUse.id,
|
|
99
|
+
content: finalContent,
|
|
100
|
+
is_error: handlerResult.is_error,
|
|
101
|
+
},
|
|
102
|
+
toolResult: {
|
|
103
|
+
id: toolUse.id,
|
|
104
|
+
result: { ...handlerResult, content: finalContent },
|
|
105
|
+
},
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
catch (error) {
|
|
109
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
110
|
+
// Execute PostToolUseFailure hooks
|
|
111
|
+
if (hookManager) {
|
|
112
|
+
await hookManager.execute("PostToolUseFailure", {
|
|
113
|
+
tool_name: tool.name,
|
|
114
|
+
tool_input: toolUse.input,
|
|
115
|
+
error: errorMessage,
|
|
116
|
+
session_id: sessionId,
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
return {
|
|
120
|
+
toolUseId: toolUse.id,
|
|
121
|
+
result: {
|
|
122
|
+
type: "tool_result",
|
|
123
|
+
tool_use_id: toolUse.id,
|
|
124
|
+
content: `Error: ${errorMessage}`,
|
|
125
|
+
is_error: true,
|
|
126
|
+
},
|
|
127
|
+
toolResult: null,
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Execute multiple tools in parallel and collect results
|
|
133
|
+
*/
|
|
134
|
+
export async function executeTools(toolUseBlocks, options) {
|
|
135
|
+
// Check for abort before starting parallel execution
|
|
136
|
+
if (options.signal?.aborted) {
|
|
137
|
+
return [];
|
|
138
|
+
}
|
|
139
|
+
// Map each tool use to an async operation
|
|
140
|
+
const toolExecutions = toolUseBlocks.map((toolUse) => executeSingleTool(toolUse, options));
|
|
141
|
+
// Execute all tools in parallel
|
|
142
|
+
const executionResults = await Promise.all(toolExecutions);
|
|
143
|
+
// Collect results and notify callbacks
|
|
144
|
+
const toolResults = [];
|
|
145
|
+
for (const executionResult of executionResults) {
|
|
146
|
+
toolResults.push(executionResult.result);
|
|
147
|
+
if (executionResult.toolResult && options.onToolResult) {
|
|
148
|
+
options.onToolResult(executionResult.toolResult);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
return toolResults;
|
|
152
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Turn Executor - Single turn execution logic
|
|
3
|
+
*/
|
|
4
|
+
import type { ToolDefinition, StopReason, PermissionMode } from "../../types/index.js";
|
|
5
|
+
import type { PermissionManager } from "../permissions.js";
|
|
6
|
+
import type { HookManager } from "../../ecosystem/hooks/index.js";
|
|
7
|
+
import type { LoopState } from "./loop-state.js";
|
|
8
|
+
/**
|
|
9
|
+
* Options for turn execution
|
|
10
|
+
*/
|
|
11
|
+
export interface TurnExecutorOptions {
|
|
12
|
+
apiKey: string;
|
|
13
|
+
model: string;
|
|
14
|
+
maxTokens: number;
|
|
15
|
+
systemPrompt: string;
|
|
16
|
+
tools: ToolDefinition[];
|
|
17
|
+
cacheConfig: import("../../types/index.js").CacheConfig;
|
|
18
|
+
thinking?: import("../../types/index.js").ThinkingConfig;
|
|
19
|
+
extendedThinking?: import("../../types/index.js").ExtendedThinkingConfig;
|
|
20
|
+
workingDirectory: string;
|
|
21
|
+
gitStatus: import("../../types/index.js").GitStatus | null;
|
|
22
|
+
reminderConfig: import("../system-reminders.js").SystemReminderConfig;
|
|
23
|
+
hookManager?: HookManager;
|
|
24
|
+
sessionId?: string;
|
|
25
|
+
signal?: AbortSignal;
|
|
26
|
+
onText?: (text: string) => void;
|
|
27
|
+
onThinking?: (thinking: string) => void;
|
|
28
|
+
onToolUse?: (toolUse: {
|
|
29
|
+
id: string;
|
|
30
|
+
name: string;
|
|
31
|
+
input: unknown;
|
|
32
|
+
}) => void;
|
|
33
|
+
onReminder?: (reminder: string) => void;
|
|
34
|
+
permissionMode: PermissionMode;
|
|
35
|
+
permissionManager: PermissionManager;
|
|
36
|
+
onMetrics?: (metrics: import("../../types/index.js").QueryMetrics) => void;
|
|
37
|
+
onToolResult?: (result: {
|
|
38
|
+
id: string;
|
|
39
|
+
result: import("../../types/index.js").ToolResult;
|
|
40
|
+
}) => void;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Result of executing a turn
|
|
44
|
+
*/
|
|
45
|
+
export interface ExecuteTurnResult {
|
|
46
|
+
/** Whether the loop should continue */
|
|
47
|
+
shouldContinue: boolean;
|
|
48
|
+
/** Stop reason if the loop should stop */
|
|
49
|
+
stopReason?: StopReason;
|
|
50
|
+
/** The metrics from this turn (if any) */
|
|
51
|
+
metrics?: import("../../types/index.js").QueryMetrics;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Execute a single turn of the agent loop
|
|
55
|
+
*/
|
|
56
|
+
export declare function executeTurn(state: LoopState, options: TurnExecutorOptions): Promise<ExecuteTurnResult>;
|
|
57
|
+
//# sourceMappingURL=turn-executor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"turn-executor.d.ts","sourceRoot":"","sources":["../../../packages/src/core/agent-loop/turn-executor.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EACV,cAAc,EAGd,UAAU,EACV,cAAc,EACf,MAAM,sBAAsB,CAAC;AAG9B,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAC3D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gCAAgC,CAAC;AAClE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAKjD;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,MAAM,CAAC;IAClB,YAAY,EAAE,MAAM,CAAC;IACrB,KAAK,EAAE,cAAc,EAAE,CAAC;IACxB,WAAW,EAAE,OAAO,sBAAsB,EAAE,WAAW,CAAC;IACxD,QAAQ,CAAC,EAAE,OAAO,sBAAsB,EAAE,cAAc,CAAC;IACzD,gBAAgB,CAAC,EAAE,OAAO,sBAAsB,EAAE,sBAAsB,CAAC;IACzE,gBAAgB,EAAE,MAAM,CAAC;IACzB,SAAS,EAAE,OAAO,sBAAsB,EAAE,SAAS,GAAG,IAAI,CAAC;IAC3D,cAAc,EAAE,OAAO,wBAAwB,EAAE,oBAAoB,CAAC;IACtE,WAAW,CAAC,EAAE,WAAW,CAAC;IAC1B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB,MAAM,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IAChC,UAAU,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,IAAI,CAAC;IACxC,SAAS,CAAC,EAAE,CAAC,OAAO,EAAE;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,OAAO,CAAA;KAAE,KAAK,IAAI,CAAC;IAC5E,UAAU,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,IAAI,CAAC;IACxC,cAAc,EAAE,cAAc,CAAC;IAC/B,iBAAiB,EAAE,iBAAiB,CAAC;IACrC,SAAS,CAAC,EAAE,CAAC,OAAO,EAAE,OAAO,sBAAsB,EAAE,YAAY,KAAK,IAAI,CAAC;IAC3E,YAAY,CAAC,EAAE,CAAC,MAAM,EAAE;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,OAAO,sBAAsB,EAAE,UAAU,CAAA;KAAE,KAAK,IAAI,CAAC;CACpG;AAED;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,uCAAuC;IACvC,cAAc,EAAE,OAAO,CAAC;IACxB,0CAA0C;IAC1C,UAAU,CAAC,EAAE,UAAU,CAAC;IACxB,0CAA0C;IAC1C,OAAO,CAAC,EAAE,OAAO,sBAAsB,EAAE,YAAY,CAAC;CACvD;AAED;;GAEG;AACH,wBAAsB,WAAW,CAC/B,KAAK,EAAE,SAAS,EAChB,OAAO,EAAE,mBAAmB,GAC3B,OAAO,CAAC,iBAAiB,CAAC,CA2J5B"}
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Turn Executor - Single turn execution logic
|
|
3
|
+
*/
|
|
4
|
+
import { createMessageStream } from "../api-client.js";
|
|
5
|
+
import { buildCombinedReminder } from "../system-reminders.js";
|
|
6
|
+
import { buildAPIMessages } from "./message-builder.js";
|
|
7
|
+
import { handleProactiveCompaction, handleReactiveCompaction, DEFAULT_PROACTIVE_OPTIONS, DEFAULT_REACTIVE_OPTIONS } from "./compaction.js";
|
|
8
|
+
import { executeTools } from "./tool-executor.js";
|
|
9
|
+
/**
|
|
10
|
+
* Execute a single turn of the agent loop
|
|
11
|
+
*/
|
|
12
|
+
export async function executeTurn(state, options) {
|
|
13
|
+
const { apiKey, model, maxTokens, systemPrompt, tools, cacheConfig, thinking, extendedThinking, workingDirectory, gitStatus, reminderConfig, hookManager, sessionId, signal, onText, onThinking, onToolUse, onReminder, permissionMode, permissionManager, onToolResult, } = options;
|
|
14
|
+
// Increment turn counter
|
|
15
|
+
state.incrementTurn();
|
|
16
|
+
const turnNumber = state.turnNumber;
|
|
17
|
+
// Build system reminder for this turn
|
|
18
|
+
const reminder = buildCombinedReminder({
|
|
19
|
+
usage: state.currentUsage,
|
|
20
|
+
maxTokens,
|
|
21
|
+
totalCost: state.totalCost,
|
|
22
|
+
previousCost: state.previousCost,
|
|
23
|
+
toolsUsed: state.allToolsUsed,
|
|
24
|
+
workingDirectory,
|
|
25
|
+
gitStatus,
|
|
26
|
+
turnNumber,
|
|
27
|
+
config: reminderConfig,
|
|
28
|
+
});
|
|
29
|
+
if (reminder) {
|
|
30
|
+
onReminder?.(reminder);
|
|
31
|
+
}
|
|
32
|
+
// Proactive compaction check - compact BEFORE hitting the limit
|
|
33
|
+
await handleProactiveCompaction(state, maxTokens, DEFAULT_PROACTIVE_OPTIONS);
|
|
34
|
+
// Build API messages with system reminders
|
|
35
|
+
const apiMessages = buildAPIMessages(state.messages, systemPrompt, reminder);
|
|
36
|
+
// Create streaming request
|
|
37
|
+
const streamResult = await createMessageStream(apiMessages, {
|
|
38
|
+
apiKey,
|
|
39
|
+
model,
|
|
40
|
+
maxTokens,
|
|
41
|
+
systemPrompt,
|
|
42
|
+
cacheConfig,
|
|
43
|
+
thinking,
|
|
44
|
+
extendedThinking,
|
|
45
|
+
tools: tools.map((t) => ({
|
|
46
|
+
name: t.name,
|
|
47
|
+
description: t.description,
|
|
48
|
+
input_schema: t.input_schema,
|
|
49
|
+
})),
|
|
50
|
+
onToken: onText,
|
|
51
|
+
onThinking,
|
|
52
|
+
onToolUse,
|
|
53
|
+
signal,
|
|
54
|
+
});
|
|
55
|
+
const { message, usage, cacheMetrics, costUSD, durationMs, ttftMs } = streamResult;
|
|
56
|
+
// Track metrics
|
|
57
|
+
const queryMetrics = state.addTurnResult({
|
|
58
|
+
message,
|
|
59
|
+
usage,
|
|
60
|
+
cacheMetrics,
|
|
61
|
+
costUSD,
|
|
62
|
+
durationMs,
|
|
63
|
+
model,
|
|
64
|
+
messageCount: state.messages.length,
|
|
65
|
+
});
|
|
66
|
+
// Add assistant message to history
|
|
67
|
+
state.addAssistantMessage(message.content);
|
|
68
|
+
// Check stop reason
|
|
69
|
+
if (message.stop_reason === "end_turn" || message.stop_reason === "stop_sequence") {
|
|
70
|
+
return {
|
|
71
|
+
shouldContinue: false,
|
|
72
|
+
stopReason: message.stop_reason,
|
|
73
|
+
metrics: queryMetrics,
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
if (message.stop_reason === "max_tokens") {
|
|
77
|
+
// Context window limit reached - compact and continue
|
|
78
|
+
const compacted = await handleReactiveCompaction(state, maxTokens, DEFAULT_REACTIVE_OPTIONS);
|
|
79
|
+
if (compacted) {
|
|
80
|
+
// Continue the loop with compacted context
|
|
81
|
+
return {
|
|
82
|
+
shouldContinue: true,
|
|
83
|
+
metrics: queryMetrics,
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
else {
|
|
87
|
+
// Could not compact further or compaction didn't help, must stop
|
|
88
|
+
return {
|
|
89
|
+
shouldContinue: false,
|
|
90
|
+
stopReason: "max_tokens",
|
|
91
|
+
metrics: queryMetrics,
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
// Handle tool use
|
|
96
|
+
const toolUseBlocks = message.content.filter((block) => block.type === "tool_use");
|
|
97
|
+
// Track all tools used for summary
|
|
98
|
+
state.trackToolUse(toolUseBlocks);
|
|
99
|
+
if (toolUseBlocks.length === 0) {
|
|
100
|
+
return {
|
|
101
|
+
shouldContinue: false,
|
|
102
|
+
metrics: queryMetrics,
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
// Execute tools in parallel and collect results
|
|
106
|
+
const toolExecutionOptions = {
|
|
107
|
+
tools,
|
|
108
|
+
workingDirectory,
|
|
109
|
+
permissionMode,
|
|
110
|
+
hookManager,
|
|
111
|
+
sessionId,
|
|
112
|
+
signal,
|
|
113
|
+
permissionManager,
|
|
114
|
+
onToolResult,
|
|
115
|
+
};
|
|
116
|
+
const toolResults = await executeTools(toolUseBlocks, toolExecutionOptions);
|
|
117
|
+
// Add tool results as user message
|
|
118
|
+
state.addUserMessage(toolResults);
|
|
119
|
+
// Continue loop to process tool results
|
|
120
|
+
return {
|
|
121
|
+
shouldContinue: true,
|
|
122
|
+
metrics: queryMetrics,
|
|
123
|
+
};
|
|
124
|
+
}
|