@ebowwa/coder 0.2.1 → 0.7.64
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +31 -32
- 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 +32 -2
- 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 +167 -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/index.d.ts +480 -0
- package/dist/native/index.d.ts.map +1 -0
- package/dist/native/index.js +1625 -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/README.md +5 -5
- package/native/index.darwin-arm64.node +0 -0
- package/native/index.node +0 -0
- package/native/package.json +4 -4
- package/package.json +33 -16
- package/packages/src/core/__tests__/permissions.test.ts +1091 -0
- package/packages/src/core/agent-loop/__tests__/compaction.test.ts +280 -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 +88 -0
- package/packages/src/core/agent-loop/formatters.ts +50 -0
- package/packages/src/core/agent-loop/index.ts +135 -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 +222 -0
- package/packages/src/core/agent-loop/types.ts +148 -0
- package/packages/src/core/agent-loop.ts +18 -0
- package/packages/src/core/api-client-impl.ts +619 -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 +590 -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-loader.ts +324 -0
- package/packages/src/core/context-compaction.ts +578 -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 +430 -0
- package/packages/src/core/normalizers/todo +4 -0
- package/packages/src/core/permissions.ts +431 -0
- package/packages/src/core/retry.ts +170 -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 +1877 -0
- package/packages/src/index.ts +120 -0
- package/packages/src/interfaces/mcp/client.ts +389 -0
- package/packages/src/interfaces/ui/Screenshot 2026-03-02 at 9.23.10/342/200/257PM.png +0 -0
- package/packages/src/interfaces/ui/Screenshot 2026-03-03 at 10.55.11/342/200/257AM.png +0 -0
- package/packages/src/interfaces/ui/index.ts +161 -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/cli/index.ts +228 -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 +71 -0
- package/packages/src/interfaces/ui/terminal/shared/loading-state.ts +322 -0
- package/packages/src/interfaces/ui/terminal/shared/query.ts +146 -0
- package/packages/src/interfaces/ui/terminal/shared/setup.ts +295 -0
- package/packages/src/interfaces/ui/terminal/shared/status-line.ts +358 -0
- package/packages/src/interfaces/ui/terminal/shared/system-prompt.ts +146 -0
- package/packages/src/interfaces/ui/terminal/tui/HelpPanel.tsx +262 -0
- package/packages/src/interfaces/ui/terminal/tui/InputContext.tsx +232 -0
- package/packages/src/interfaces/ui/terminal/tui/InputField.tsx +62 -0
- package/packages/src/interfaces/ui/terminal/tui/InteractiveTUI.tsx +537 -0
- package/packages/src/interfaces/ui/terminal/tui/MessageArea.tsx +107 -0
- package/packages/src/interfaces/ui/terminal/tui/MessageStore.tsx +240 -0
- package/packages/src/interfaces/ui/terminal/tui/StatusBar.tsx +54 -0
- package/packages/src/interfaces/ui/terminal/tui/commands.ts +438 -0
- package/packages/src/interfaces/ui/terminal/tui/components/InteractiveElements.tsx +584 -0
- package/packages/src/interfaces/ui/terminal/tui/components/MultilineInput.tsx +614 -0
- package/packages/src/interfaces/ui/terminal/tui/components/PaneManager.tsx +333 -0
- package/packages/src/interfaces/ui/terminal/tui/components/Sidebar.tsx +604 -0
- package/packages/src/interfaces/ui/terminal/tui/components/index.ts +118 -0
- package/packages/src/interfaces/ui/terminal/tui/console.ts +49 -0
- package/packages/src/interfaces/ui/terminal/tui/index.ts +90 -0
- package/packages/src/interfaces/ui/terminal/tui/run.tsx +42 -0
- package/packages/src/interfaces/ui/terminal/tui/spinner.ts +69 -0
- package/packages/src/interfaces/ui/terminal/tui/tui-app.tsx +390 -0
- package/packages/src/interfaces/ui/terminal/tui/tui-footer.ts +422 -0
- package/packages/src/interfaces/ui/terminal/tui/types.ts +186 -0
- package/packages/src/interfaces/ui/terminal/tui/useInputHandler.ts +104 -0
- package/packages/src/interfaces/ui/terminal/tui/useNativeInput.ts +239 -0
- package/packages/src/lmdb.db +0 -0
- package/packages/src/lmdb.db-lock +0 -0
- package/packages/src/native/index.ts +2345 -0
- package/packages/src/teammates/index.ts +982 -0
- package/packages/src/types/index.ts +722 -0
- package/dist/cli.js +0 -148
- package/dist/index-0pkak453.js +0 -136
- package/dist/index-0qd0x8b4.js +0 -110
- package/dist/index-0x3kprq6.js +0 -240
- package/dist/index-1eawy937.js +0 -308
- package/dist/index-24m2aygy.js +0 -240
- package/dist/index-29xcjnne.js +0 -280
- package/dist/index-2avyytn5.js +0 -349
- package/dist/index-4ms367ey.js +0 -136
- package/dist/index-4w2t3b0m.js +0 -240
- package/dist/index-4xfgd8nz.js +0 -261
- package/dist/index-5acjp9gc.js +0 -157
- package/dist/index-5s15hr56.js +0 -136
- package/dist/index-6e4wf341.js +0 -349
- package/dist/index-6fvnkedw.js +0 -240
- package/dist/index-6rqpmd4g.js +0 -128
- package/dist/index-77ckwnbm.js +0 -280
- package/dist/index-9knxy49k.js +0 -128
- package/dist/index-9zrnw4zx.js +0 -128
- package/dist/index-bk21w99v.js +0 -280
- package/dist/index-c41n76fv.js +0 -240
- package/dist/index-cb4ppjdt.js +0 -255
- package/dist/index-cfb2edt6.js +0 -240
- package/dist/index-cmfa38hh.js +0 -308
- package/dist/index-datjz8q1.js +0 -257
- package/dist/index-eadf4wvn.js +0 -240
- package/dist/index-em5k0m3z.js +0 -345
- package/dist/index-gh8r333a.js +0 -110
- package/dist/index-gkx6k2tr.js +0 -261
- package/dist/index-h5cabfks.js +0 -155
- package/dist/index-hcrpwyy3.js +0 -261
- package/dist/index-hk7fwwa8.js +0 -257
- package/dist/index-jb8cw7f8.js +0 -136
- package/dist/index-kbyw4th1.js +0 -347
- package/dist/index-kgj5gqnm.js +0 -345
- package/dist/index-mdf6xp1z.js +0 -255
- package/dist/index-mrhv8kvc.js +0 -280
- package/dist/index-mt4743dd.js +0 -161
- package/dist/index-qnwsg97q.js +0 -240
- package/dist/index-qwdy6x44.js +0 -261
- package/dist/index-rmj77261.js +0 -157
- package/dist/index-sbbw1a61.js +0 -349
- package/dist/index-svy5bcpn.js +0 -345
- package/dist/index-tvmy7tm9.js +0 -261
- package/dist/index-tzz4vzkj.js +0 -312
- package/dist/index-vz80zmhe.js +0 -110
- package/dist/index-wed2fk67.js +0 -240
- package/dist/index-wksgzz8e.js +0 -280
- package/dist/index-wn2m4wma.js +0 -240
- package/dist/index-xha05vjc.js +0 -257
- package/dist/index-yc6eh8p8.js +0 -136
- package/dist/index-ycjxx9ft.js +0 -240
- package/dist/index-z0gzd0fc.js +0 -110
- package/dist/index-z8cwtf8j.js +0 -240
- package/dist/index-zy5mtt00.js +0 -128
|
@@ -0,0 +1,331 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tool Executor Tests - Parallel tool execution with hooks and permissions
|
|
3
|
+
*/
|
|
4
|
+
import { describe, it, expect, beforeEach } from "bun:test";
|
|
5
|
+
import { executeTools } from "../tool-executor.js";
|
|
6
|
+
import { PermissionManager } from "../../permissions.js";
|
|
7
|
+
// Mock tool definitions
|
|
8
|
+
const createMockTool = (name, handler) => ({
|
|
9
|
+
name,
|
|
10
|
+
description: `Mock ${name} tool`,
|
|
11
|
+
input_schema: {
|
|
12
|
+
type: "object",
|
|
13
|
+
properties: {},
|
|
14
|
+
},
|
|
15
|
+
handler,
|
|
16
|
+
});
|
|
17
|
+
describe("executeTools", () => {
|
|
18
|
+
let permissionManager;
|
|
19
|
+
let toolResults;
|
|
20
|
+
beforeEach(() => {
|
|
21
|
+
permissionManager = new PermissionManager("bypassPermissions");
|
|
22
|
+
toolResults = [];
|
|
23
|
+
});
|
|
24
|
+
const createOptions = (tools, overrides = {}) => ({
|
|
25
|
+
tools,
|
|
26
|
+
workingDirectory: "/test",
|
|
27
|
+
permissionMode: "bypassPermissions",
|
|
28
|
+
permissionManager,
|
|
29
|
+
onToolResult: (result) => toolResults.push(result),
|
|
30
|
+
...overrides,
|
|
31
|
+
});
|
|
32
|
+
describe("basic execution", () => {
|
|
33
|
+
it("should execute a single tool and return result", async () => {
|
|
34
|
+
const tools = [
|
|
35
|
+
createMockTool("TestTool", async () => ({ content: "Success" })),
|
|
36
|
+
];
|
|
37
|
+
const toolUseBlocks = [
|
|
38
|
+
{ type: "tool_use", id: "tool1", name: "TestTool", input: {} },
|
|
39
|
+
];
|
|
40
|
+
const results = await executeTools(toolUseBlocks, createOptions(tools));
|
|
41
|
+
expect(results).toHaveLength(1);
|
|
42
|
+
expect(results[0]?.tool_use_id).toBe("tool1");
|
|
43
|
+
expect(results[0]?.content).toBe("Success");
|
|
44
|
+
expect(results[0]?.is_error).toBeFalsy();
|
|
45
|
+
});
|
|
46
|
+
it("should execute multiple tools in parallel", async () => {
|
|
47
|
+
const executionOrder = [];
|
|
48
|
+
const tools = [
|
|
49
|
+
createMockTool("Tool1", async () => {
|
|
50
|
+
executionOrder.push("Tool1");
|
|
51
|
+
await new Promise((r) => setTimeout(r, 10));
|
|
52
|
+
return { content: "Result 1" };
|
|
53
|
+
}),
|
|
54
|
+
createMockTool("Tool2", async () => {
|
|
55
|
+
executionOrder.push("Tool2");
|
|
56
|
+
await new Promise((r) => setTimeout(r, 5));
|
|
57
|
+
return { content: "Result 2" };
|
|
58
|
+
}),
|
|
59
|
+
];
|
|
60
|
+
const toolUseBlocks = [
|
|
61
|
+
{ type: "tool_use", id: "tool1", name: "Tool1", input: {} },
|
|
62
|
+
{ type: "tool_use", id: "tool2", name: "Tool2", input: {} },
|
|
63
|
+
];
|
|
64
|
+
const results = await executeTools(toolUseBlocks, createOptions(tools));
|
|
65
|
+
expect(results).toHaveLength(2);
|
|
66
|
+
// Both should have been started before either finished (parallel)
|
|
67
|
+
expect(executionOrder).toContain("Tool1");
|
|
68
|
+
expect(executionOrder).toContain("Tool2");
|
|
69
|
+
});
|
|
70
|
+
it("should return error for unknown tool", async () => {
|
|
71
|
+
const tools = [
|
|
72
|
+
createMockTool("KnownTool", async () => ({ content: "OK" })),
|
|
73
|
+
];
|
|
74
|
+
const toolUseBlocks = [
|
|
75
|
+
{ type: "tool_use", id: "tool1", name: "UnknownTool", input: {} },
|
|
76
|
+
];
|
|
77
|
+
const results = await executeTools(toolUseBlocks, createOptions(tools));
|
|
78
|
+
expect(results).toHaveLength(1);
|
|
79
|
+
expect(results[0]?.is_error).toBe(true);
|
|
80
|
+
expect(results[0]?.content).toContain("Unknown tool");
|
|
81
|
+
});
|
|
82
|
+
it("should handle tool handler errors", async () => {
|
|
83
|
+
const tools = [
|
|
84
|
+
createMockTool("FailingTool", async () => {
|
|
85
|
+
throw new Error("Handler error");
|
|
86
|
+
}),
|
|
87
|
+
];
|
|
88
|
+
const toolUseBlocks = [
|
|
89
|
+
{ type: "tool_use", id: "tool1", name: "FailingTool", input: {} },
|
|
90
|
+
];
|
|
91
|
+
const results = await executeTools(toolUseBlocks, createOptions(tools));
|
|
92
|
+
expect(results).toHaveLength(1);
|
|
93
|
+
expect(results[0]?.is_error).toBe(true);
|
|
94
|
+
expect(results[0]?.content).toContain("Handler error");
|
|
95
|
+
});
|
|
96
|
+
it("should pass tool input to handler", async () => {
|
|
97
|
+
let receivedInput = null;
|
|
98
|
+
const tools = [
|
|
99
|
+
createMockTool("InputTool", async (args) => {
|
|
100
|
+
receivedInput = args;
|
|
101
|
+
return { content: "OK" };
|
|
102
|
+
}),
|
|
103
|
+
];
|
|
104
|
+
const toolUseBlocks = [
|
|
105
|
+
{
|
|
106
|
+
type: "tool_use",
|
|
107
|
+
id: "tool1",
|
|
108
|
+
name: "InputTool",
|
|
109
|
+
input: { path: "/test/file.txt", mode: "read" },
|
|
110
|
+
},
|
|
111
|
+
];
|
|
112
|
+
await executeTools(toolUseBlocks, createOptions(tools));
|
|
113
|
+
expect(receivedInput).not.toBeNull();
|
|
114
|
+
expect(receivedInput).toEqual({ path: "/test/file.txt", mode: "read" });
|
|
115
|
+
});
|
|
116
|
+
});
|
|
117
|
+
describe("tool result callbacks", () => {
|
|
118
|
+
it("should call onToolResult for successful tools", async () => {
|
|
119
|
+
const tools = [
|
|
120
|
+
createMockTool("SuccessTool", async () => ({ content: "Done" })),
|
|
121
|
+
];
|
|
122
|
+
const toolUseBlocks = [
|
|
123
|
+
{ type: "tool_use", id: "tool1", name: "SuccessTool", input: {} },
|
|
124
|
+
];
|
|
125
|
+
await executeTools(toolUseBlocks, createOptions(tools));
|
|
126
|
+
expect(toolResults).toHaveLength(1);
|
|
127
|
+
expect(toolResults[0]?.id).toBe("tool1");
|
|
128
|
+
expect(toolResults[0]?.result.content).toBe("Done");
|
|
129
|
+
});
|
|
130
|
+
it("should not call onToolResult for unknown tools", async () => {
|
|
131
|
+
const tools = [];
|
|
132
|
+
const toolUseBlocks = [
|
|
133
|
+
{ type: "tool_use", id: "tool1", name: "Unknown", input: {} },
|
|
134
|
+
];
|
|
135
|
+
await executeTools(toolUseBlocks, createOptions(tools));
|
|
136
|
+
expect(toolResults).toHaveLength(0);
|
|
137
|
+
});
|
|
138
|
+
it("should not call onToolResult for failed tools", async () => {
|
|
139
|
+
const tools = [
|
|
140
|
+
createMockTool("FailingTool", async () => {
|
|
141
|
+
throw new Error("Fail");
|
|
142
|
+
}),
|
|
143
|
+
];
|
|
144
|
+
const toolUseBlocks = [
|
|
145
|
+
{ type: "tool_use", id: "tool1", name: "FailingTool", input: {} },
|
|
146
|
+
];
|
|
147
|
+
await executeTools(toolUseBlocks, createOptions(tools));
|
|
148
|
+
expect(toolResults).toHaveLength(0);
|
|
149
|
+
});
|
|
150
|
+
});
|
|
151
|
+
describe("abort signal", () => {
|
|
152
|
+
it("should return empty array if signal is already aborted", async () => {
|
|
153
|
+
const tools = [
|
|
154
|
+
createMockTool("Tool", async () => ({ content: "OK" })),
|
|
155
|
+
];
|
|
156
|
+
const controller = new AbortController();
|
|
157
|
+
controller.abort();
|
|
158
|
+
const toolUseBlocks = [
|
|
159
|
+
{ type: "tool_use", id: "tool1", name: "Tool", input: {} },
|
|
160
|
+
];
|
|
161
|
+
const results = await executeTools(toolUseBlocks, createOptions(tools, { signal: controller.signal }));
|
|
162
|
+
expect(results).toHaveLength(0);
|
|
163
|
+
});
|
|
164
|
+
});
|
|
165
|
+
describe("permission checks", () => {
|
|
166
|
+
it("should deny tool when permission is denied", async () => {
|
|
167
|
+
const tools = [
|
|
168
|
+
createMockTool("RestrictedTool", async () => ({ content: "Should not reach" })),
|
|
169
|
+
];
|
|
170
|
+
const denyManager = new PermissionManager("dontAsk");
|
|
171
|
+
const toolUseBlocks = [
|
|
172
|
+
{ type: "tool_use", id: "tool1", name: "RestrictedTool", input: {} },
|
|
173
|
+
];
|
|
174
|
+
const results = await executeTools(toolUseBlocks, createOptions(tools, { permissionManager: denyManager }));
|
|
175
|
+
expect(results).toHaveLength(1);
|
|
176
|
+
expect(results[0]?.is_error).toBe(true);
|
|
177
|
+
expect(results[0]?.content).toContain("Permission denied");
|
|
178
|
+
});
|
|
179
|
+
it("should allow tool when permission is granted", async () => {
|
|
180
|
+
const tools = [
|
|
181
|
+
createMockTool("AllowedTool", async () => ({ content: "Success" })),
|
|
182
|
+
];
|
|
183
|
+
const toolUseBlocks = [
|
|
184
|
+
{ type: "tool_use", id: "tool1", name: "AllowedTool", input: {} },
|
|
185
|
+
];
|
|
186
|
+
const results = await executeTools(toolUseBlocks, createOptions(tools, { permissionManager }));
|
|
187
|
+
expect(results[0]?.is_error).toBeFalsy();
|
|
188
|
+
expect(results[0]?.content).toBe("Success");
|
|
189
|
+
});
|
|
190
|
+
});
|
|
191
|
+
describe("hook integration", () => {
|
|
192
|
+
it("should execute PreToolUse hooks", async () => {
|
|
193
|
+
let hookCalled = false;
|
|
194
|
+
const mockHookManager = {
|
|
195
|
+
execute: async (event, input) => {
|
|
196
|
+
if (event === "PreToolUse") {
|
|
197
|
+
hookCalled = true;
|
|
198
|
+
}
|
|
199
|
+
return { decision: "allow" };
|
|
200
|
+
},
|
|
201
|
+
};
|
|
202
|
+
const tools = [
|
|
203
|
+
createMockTool("HookTool", async () => ({ content: "OK" })),
|
|
204
|
+
];
|
|
205
|
+
const toolUseBlocks = [
|
|
206
|
+
{ type: "tool_use", id: "tool1", name: "HookTool", input: {} },
|
|
207
|
+
];
|
|
208
|
+
await executeTools(toolUseBlocks, createOptions(tools, { hookManager: mockHookManager }));
|
|
209
|
+
expect(hookCalled).toBe(true);
|
|
210
|
+
});
|
|
211
|
+
it("should block tool when PreToolUse hook denies", async () => {
|
|
212
|
+
const mockHookManager = {
|
|
213
|
+
execute: async (event, input) => {
|
|
214
|
+
if (event === "PreToolUse") {
|
|
215
|
+
return { decision: "deny", reason: "Blocked by hook" };
|
|
216
|
+
}
|
|
217
|
+
return { decision: "allow" };
|
|
218
|
+
},
|
|
219
|
+
};
|
|
220
|
+
const tools = [
|
|
221
|
+
createMockTool("BlockedTool", async () => ({ content: "Should not reach" })),
|
|
222
|
+
];
|
|
223
|
+
const toolUseBlocks = [
|
|
224
|
+
{ type: "tool_use", id: "tool1", name: "BlockedTool", input: {} },
|
|
225
|
+
];
|
|
226
|
+
const results = await executeTools(toolUseBlocks, createOptions(tools, { hookManager: mockHookManager }));
|
|
227
|
+
expect(results[0]?.is_error).toBe(true);
|
|
228
|
+
expect(results[0]?.content).toContain("Blocked by hook");
|
|
229
|
+
});
|
|
230
|
+
it("should execute PostToolUse hooks", async () => {
|
|
231
|
+
let postHookCalled = false;
|
|
232
|
+
const mockHookManager = {
|
|
233
|
+
execute: async (event, input) => {
|
|
234
|
+
if (event === "PostToolUse") {
|
|
235
|
+
postHookCalled = true;
|
|
236
|
+
}
|
|
237
|
+
return { decision: "allow" };
|
|
238
|
+
},
|
|
239
|
+
};
|
|
240
|
+
const tools = [
|
|
241
|
+
createMockTool("PostHookTool", async () => ({ content: "Result" })),
|
|
242
|
+
];
|
|
243
|
+
const toolUseBlocks = [
|
|
244
|
+
{ type: "tool_use", id: "tool1", name: "PostHookTool", input: {} },
|
|
245
|
+
];
|
|
246
|
+
await executeTools(toolUseBlocks, createOptions(tools, { hookManager: mockHookManager }));
|
|
247
|
+
expect(postHookCalled).toBe(true);
|
|
248
|
+
});
|
|
249
|
+
it("should modify tool input via hook", async () => {
|
|
250
|
+
let receivedInput = null;
|
|
251
|
+
const mockHookManager = {
|
|
252
|
+
execute: async (event, input) => {
|
|
253
|
+
if (event === "PreToolUse") {
|
|
254
|
+
return {
|
|
255
|
+
decision: "allow",
|
|
256
|
+
modified_input: { modified: true },
|
|
257
|
+
};
|
|
258
|
+
}
|
|
259
|
+
return { decision: "allow" };
|
|
260
|
+
},
|
|
261
|
+
};
|
|
262
|
+
const tools = [
|
|
263
|
+
createMockTool("ModifiedInputTool", async (args) => {
|
|
264
|
+
receivedInput = args;
|
|
265
|
+
return { content: "OK" };
|
|
266
|
+
}),
|
|
267
|
+
];
|
|
268
|
+
const toolUseBlocks = [
|
|
269
|
+
{
|
|
270
|
+
type: "tool_use",
|
|
271
|
+
id: "tool1",
|
|
272
|
+
name: "ModifiedInputTool",
|
|
273
|
+
input: { original: true },
|
|
274
|
+
},
|
|
275
|
+
];
|
|
276
|
+
await executeTools(toolUseBlocks, createOptions(tools, { hookManager: mockHookManager }));
|
|
277
|
+
// Object.assign merges properties, so we get both original and modified
|
|
278
|
+
expect(receivedInput).not.toBeNull();
|
|
279
|
+
expect(receivedInput).toEqual({ original: true, modified: true });
|
|
280
|
+
});
|
|
281
|
+
it("should execute PostToolUseFailure hooks on error", async () => {
|
|
282
|
+
let failureHookCalled = false;
|
|
283
|
+
const mockHookManager = {
|
|
284
|
+
execute: async (event, input) => {
|
|
285
|
+
if (event === "PostToolUseFailure") {
|
|
286
|
+
failureHookCalled = true;
|
|
287
|
+
expect(input.error).toContain("Handler crashed");
|
|
288
|
+
}
|
|
289
|
+
return { decision: "allow" };
|
|
290
|
+
},
|
|
291
|
+
};
|
|
292
|
+
const tools = [
|
|
293
|
+
createMockTool("CrashTool", async () => {
|
|
294
|
+
throw new Error("Handler crashed");
|
|
295
|
+
}),
|
|
296
|
+
];
|
|
297
|
+
const toolUseBlocks = [
|
|
298
|
+
{ type: "tool_use", id: "tool1", name: "CrashTool", input: {} },
|
|
299
|
+
];
|
|
300
|
+
await executeTools(toolUseBlocks, createOptions(tools, { hookManager: mockHookManager }));
|
|
301
|
+
expect(failureHookCalled).toBe(true);
|
|
302
|
+
});
|
|
303
|
+
});
|
|
304
|
+
describe("error handling", () => {
|
|
305
|
+
it("should handle non-Error thrown objects", async () => {
|
|
306
|
+
const tools = [
|
|
307
|
+
createMockTool("StringThrowTool", async () => {
|
|
308
|
+
throw "String error";
|
|
309
|
+
}),
|
|
310
|
+
];
|
|
311
|
+
const toolUseBlocks = [
|
|
312
|
+
{ type: "tool_use", id: "tool1", name: "StringThrowTool", input: {} },
|
|
313
|
+
];
|
|
314
|
+
const results = await executeTools(toolUseBlocks, createOptions(tools));
|
|
315
|
+
expect(results[0]?.is_error).toBe(true);
|
|
316
|
+
expect(results[0]?.content).toContain("String error");
|
|
317
|
+
});
|
|
318
|
+
it("should handle null thrown", async () => {
|
|
319
|
+
const tools = [
|
|
320
|
+
createMockTool("NullThrowTool", async () => {
|
|
321
|
+
throw null;
|
|
322
|
+
}),
|
|
323
|
+
];
|
|
324
|
+
const toolUseBlocks = [
|
|
325
|
+
{ type: "tool_use", id: "tool1", name: "NullThrowTool", input: {} },
|
|
326
|
+
];
|
|
327
|
+
const results = await executeTools(toolUseBlocks, createOptions(tools));
|
|
328
|
+
expect(results[0]?.is_error).toBe(true);
|
|
329
|
+
});
|
|
330
|
+
});
|
|
331
|
+
});
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Compaction Handler - Context compaction strategies
|
|
3
|
+
*/
|
|
4
|
+
import { needsCompaction } from "../context-compaction.js";
|
|
5
|
+
import type { LoopState } from "./loop-state.js";
|
|
6
|
+
/**
|
|
7
|
+
* Compaction options
|
|
8
|
+
*/
|
|
9
|
+
export interface CompactionOptions {
|
|
10
|
+
/** Number of initial messages to preserve (0 = none) */
|
|
11
|
+
keepFirst?: number;
|
|
12
|
+
/** Number of recent messages to preserve */
|
|
13
|
+
keepLast?: number;
|
|
14
|
+
/** Preserve tool use/result pairs */
|
|
15
|
+
preserveToolPairs?: boolean;
|
|
16
|
+
}
|
|
17
|
+
/** Default compaction options for proactive compaction */
|
|
18
|
+
export declare const DEFAULT_PROACTIVE_OPTIONS: CompactionOptions;
|
|
19
|
+
/** Default compaction options for reactive compaction (on max_tokens) */
|
|
20
|
+
export declare const DEFAULT_REACTIVE_OPTIONS: CompactionOptions;
|
|
21
|
+
/**
|
|
22
|
+
* Check if compaction is needed and apply it proactively
|
|
23
|
+
* @returns true if compaction was applied
|
|
24
|
+
*/
|
|
25
|
+
export declare function handleProactiveCompaction(state: LoopState, maxTokens: number, options?: CompactionOptions): Promise<boolean>;
|
|
26
|
+
/**
|
|
27
|
+
* Handle reactive compaction when max_tokens is hit
|
|
28
|
+
* @returns true if compaction was applied and loop should continue
|
|
29
|
+
*/
|
|
30
|
+
export declare function handleReactiveCompaction(state: LoopState, maxTokens: number, options?: CompactionOptions): Promise<boolean>;
|
|
31
|
+
/**
|
|
32
|
+
* Check if messages need compaction
|
|
33
|
+
*/
|
|
34
|
+
export { needsCompaction };
|
|
35
|
+
/**
|
|
36
|
+
* Get token estimate for messages
|
|
37
|
+
*/
|
|
38
|
+
export { estimateMessagesTokens } from "../context-compaction.js";
|
|
39
|
+
//# sourceMappingURL=compaction.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compaction.d.ts","sourceRoot":"","sources":["../../../packages/src/core/agent-loop/compaction.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,EACL,eAAe,EAIhB,MAAM,0BAA0B,CAAC;AAClC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAEjD;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,wDAAwD;IACxD,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,4CAA4C;IAC5C,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,qCAAqC;IACrC,iBAAiB,CAAC,EAAE,OAAO,CAAC;CAC7B;AAED,0DAA0D;AAC1D,eAAO,MAAM,yBAAyB,EAAE,iBAIvC,CAAC;AAEF,yEAAyE;AACzE,eAAO,MAAM,wBAAwB,EAAE,iBAItC,CAAC;AAEF;;;GAGG;AACH,wBAAsB,yBAAyB,CAC7C,KAAK,EAAE,SAAS,EAChB,SAAS,EAAE,MAAM,EACjB,OAAO,GAAE,iBAA6C,GACrD,OAAO,CAAC,OAAO,CAAC,CAYlB;AAED;;;GAGG;AACH,wBAAsB,wBAAwB,CAC5C,KAAK,EAAE,SAAS,EAChB,SAAS,EAAE,MAAM,EACjB,OAAO,GAAE,iBAA4C,GACpD,OAAO,CAAC,OAAO,CAAC,CAQlB;AAED;;GAEG;AACH,OAAO,EAAE,eAAe,EAAE,CAAC;AAE3B;;GAEG;AACH,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Compaction Handler - Context compaction strategies
|
|
3
|
+
*/
|
|
4
|
+
import { needsCompaction, compactMessages, getCompactionStats, } from "../context-compaction.js";
|
|
5
|
+
/** Default compaction options for proactive compaction */
|
|
6
|
+
export const DEFAULT_PROACTIVE_OPTIONS = {
|
|
7
|
+
keepFirst: 0, // Don't preserve first message - summary covers it
|
|
8
|
+
keepLast: 3, // Only keep last 3 messages for more aggressive compaction
|
|
9
|
+
preserveToolPairs: true,
|
|
10
|
+
};
|
|
11
|
+
/** Default compaction options for reactive compaction (on max_tokens) */
|
|
12
|
+
export const DEFAULT_REACTIVE_OPTIONS = {
|
|
13
|
+
keepFirst: 0, // Don't preserve first message
|
|
14
|
+
keepLast: 3, // More aggressive - only keep last 3
|
|
15
|
+
preserveToolPairs: true,
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* Check if compaction is needed and apply it proactively
|
|
19
|
+
* @returns true if compaction was applied
|
|
20
|
+
*/
|
|
21
|
+
export async function handleProactiveCompaction(state, maxTokens, options = DEFAULT_PROACTIVE_OPTIONS) {
|
|
22
|
+
if (!needsCompaction(state.messages, maxTokens)) {
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
const compactionResult = await compactMessages(state.messages, maxTokens, {
|
|
26
|
+
keepFirst: options.keepFirst ?? 0,
|
|
27
|
+
keepLast: options.keepLast ?? 3,
|
|
28
|
+
preserveToolPairs: options.preserveToolPairs ?? true,
|
|
29
|
+
});
|
|
30
|
+
return state.applyCompaction(compactionResult, getCompactionStats);
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Handle reactive compaction when max_tokens is hit
|
|
34
|
+
* @returns true if compaction was applied and loop should continue
|
|
35
|
+
*/
|
|
36
|
+
export async function handleReactiveCompaction(state, maxTokens, options = DEFAULT_REACTIVE_OPTIONS) {
|
|
37
|
+
const compactionResult = await compactMessages(state.messages, maxTokens, {
|
|
38
|
+
keepFirst: options.keepFirst ?? 0,
|
|
39
|
+
keepLast: options.keepLast ?? 3,
|
|
40
|
+
preserveToolPairs: options.preserveToolPairs ?? true,
|
|
41
|
+
});
|
|
42
|
+
return state.applyCompaction(compactionResult, getCompactionStats);
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Check if messages need compaction
|
|
46
|
+
*/
|
|
47
|
+
export { needsCompaction };
|
|
48
|
+
/**
|
|
49
|
+
* Get token estimate for messages
|
|
50
|
+
*/
|
|
51
|
+
export { estimateMessagesTokens } from "../context-compaction.js";
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Formatters - Cost and metrics display utilities
|
|
3
|
+
*/
|
|
4
|
+
import type { QueryMetrics, CacheMetrics } from "../../types/index.js";
|
|
5
|
+
/**
|
|
6
|
+
* Format cost for display
|
|
7
|
+
*/
|
|
8
|
+
export declare function formatCost(costUSD: number): string;
|
|
9
|
+
/**
|
|
10
|
+
* Format metrics for display
|
|
11
|
+
*/
|
|
12
|
+
export declare function formatMetrics(metrics: QueryMetrics): string;
|
|
13
|
+
/**
|
|
14
|
+
* Format brief cost for per-turn display (less verbose)
|
|
15
|
+
*/
|
|
16
|
+
export declare function formatCostBrief(metrics: QueryMetrics): string;
|
|
17
|
+
/**
|
|
18
|
+
* Format cache metrics for display
|
|
19
|
+
*/
|
|
20
|
+
export declare function formatCacheMetrics(cacheMetrics: CacheMetrics): string;
|
|
21
|
+
//# sourceMappingURL=formatters.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"formatters.d.ts","sourceRoot":"","sources":["../../../packages/src/core/agent-loop/formatters.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAEvE;;GAEG;AACH,wBAAgB,UAAU,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAKlD;AAED;;GAEG;AACH,wBAAgB,aAAa,CAAC,OAAO,EAAE,YAAY,GAAG,MAAM,CAY3D;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,OAAO,EAAE,YAAY,GAAG,MAAM,CAI7D;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,YAAY,EAAE,YAAY,GAAG,MAAM,CAIrE"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Formatters - Cost and metrics display utilities
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Format cost for display
|
|
6
|
+
*/
|
|
7
|
+
export function formatCost(costUSD) {
|
|
8
|
+
if (costUSD < 0.01) {
|
|
9
|
+
return `$${costUSD.toFixed(4)}`;
|
|
10
|
+
}
|
|
11
|
+
return `$${costUSD.toFixed(2)}`;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Format metrics for display
|
|
15
|
+
*/
|
|
16
|
+
export function formatMetrics(metrics) {
|
|
17
|
+
const cost = formatCost(metrics.costUSD);
|
|
18
|
+
const tokens = `${metrics.usage.input_tokens.toLocaleString()} input, ${metrics.usage.output_tokens.toLocaleString()} output`;
|
|
19
|
+
// Include cache info if available
|
|
20
|
+
if (metrics.usage.cache_read_input_tokens || metrics.usage.cache_creation_input_tokens) {
|
|
21
|
+
const cacheRead = metrics.usage.cache_read_input_tokens?.toLocaleString() ?? "0";
|
|
22
|
+
const cacheWrite = metrics.usage.cache_creation_input_tokens?.toLocaleString() ?? "0";
|
|
23
|
+
return `Cost: ${cost} | Tokens: ${tokens} | Cache: ${cacheRead} read, ${cacheWrite} write`;
|
|
24
|
+
}
|
|
25
|
+
return `Cost: ${cost} | Tokens: ${tokens}`;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Format brief cost for per-turn display (less verbose)
|
|
29
|
+
*/
|
|
30
|
+
export function formatCostBrief(metrics) {
|
|
31
|
+
const cost = formatCost(metrics.costUSD);
|
|
32
|
+
const totalTokens = metrics.usage.input_tokens + metrics.usage.output_tokens;
|
|
33
|
+
return `Cost: ${cost} | Tokens: ${totalTokens.toLocaleString()}`;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Format cache metrics for display
|
|
37
|
+
*/
|
|
38
|
+
export function formatCacheMetrics(cacheMetrics) {
|
|
39
|
+
const savings = formatCost(cacheMetrics.estimatedSavingsUSD);
|
|
40
|
+
const hitRate = (cacheMetrics.cacheHitRate * 100).toFixed(1);
|
|
41
|
+
return `Cache: ${hitRate}% hit rate | ${cacheMetrics.totalCacheReadTokens.toLocaleString()} read | ${cacheMetrics.totalCacheWriteTokens.toLocaleString()} written | Saved: ${savings}`;
|
|
42
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Agent Loop - Turn-based processing system
|
|
3
|
+
*
|
|
4
|
+
* This is the main orchestrator that coordinates:
|
|
5
|
+
* - State management (loop-state.ts)
|
|
6
|
+
* - Turn execution (turn-executor.ts)
|
|
7
|
+
* - Tool execution (tool-executor.ts)
|
|
8
|
+
* - Context compaction (compaction.ts)
|
|
9
|
+
* - Message building (message-builder.ts)
|
|
10
|
+
* - Formatting utilities (formatters.ts)
|
|
11
|
+
*/
|
|
12
|
+
import type { Message } from "../../types/index.js";
|
|
13
|
+
import type { AgentLoopOptions, AgentLoopResult } from "./types.js";
|
|
14
|
+
export type { AgentLoopOptions, AgentLoopResult } from "./types.js";
|
|
15
|
+
export { formatCost, formatMetrics, formatCostBrief, formatCacheMetrics } from "./formatters.js";
|
|
16
|
+
export { LoopState } from "./loop-state.js";
|
|
17
|
+
export { executeTurn } from "./turn-executor.js";
|
|
18
|
+
export { executeTools, type ToolExecutionOptions } from "./tool-executor.js";
|
|
19
|
+
export { buildAPIMessages, injectReminderIntoContent } from "./message-builder.js";
|
|
20
|
+
export { handleProactiveCompaction, handleReactiveCompaction, needsCompaction, estimateMessagesTokens, DEFAULT_PROACTIVE_OPTIONS, DEFAULT_REACTIVE_OPTIONS, } from "./compaction.js";
|
|
21
|
+
/**
|
|
22
|
+
* Main agent loop - processes messages in turns until completion
|
|
23
|
+
*/
|
|
24
|
+
export declare function agentLoop(initialMessages: Message[], options: AgentLoopOptions): Promise<AgentLoopResult>;
|
|
25
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../packages/src/core/agent-loop/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAMpD,OAAO,KAAK,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAKpE,YAAY,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AACpE,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,eAAe,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AACjG,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,EAAE,YAAY,EAAE,KAAK,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAC7E,OAAO,EAAE,gBAAgB,EAAE,yBAAyB,EAAE,MAAM,sBAAsB,CAAC;AACnF,OAAO,EACL,yBAAyB,EACzB,wBAAwB,EACxB,eAAe,EACf,sBAAsB,EACtB,yBAAyB,EACzB,wBAAwB,GACzB,MAAM,iBAAiB,CAAC;AAEzB;;GAEG;AACH,wBAAsB,SAAS,CAC7B,eAAe,EAAE,OAAO,EAAE,EAC1B,OAAO,EAAE,gBAAgB,GACxB,OAAO,CAAC,eAAe,CAAC,CA0F1B"}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Agent Loop - Turn-based processing system
|
|
3
|
+
*
|
|
4
|
+
* This is the main orchestrator that coordinates:
|
|
5
|
+
* - State management (loop-state.ts)
|
|
6
|
+
* - Turn execution (turn-executor.ts)
|
|
7
|
+
* - Tool execution (tool-executor.ts)
|
|
8
|
+
* - Context compaction (compaction.ts)
|
|
9
|
+
* - Message building (message-builder.ts)
|
|
10
|
+
* - Formatting utilities (formatters.ts)
|
|
11
|
+
*/
|
|
12
|
+
import { DEFAULT_CACHE_CONFIG } from "../../types/index.js";
|
|
13
|
+
import { PermissionManager } from "../permissions.js";
|
|
14
|
+
import { DEFAULT_REMINDER_CONFIG } from "../system-reminders.js";
|
|
15
|
+
import { LoopState } from "./loop-state.js";
|
|
16
|
+
import { executeTurn } from "./turn-executor.js";
|
|
17
|
+
export { formatCost, formatMetrics, formatCostBrief, formatCacheMetrics } from "./formatters.js";
|
|
18
|
+
export { LoopState } from "./loop-state.js";
|
|
19
|
+
export { executeTurn } from "./turn-executor.js";
|
|
20
|
+
export { executeTools } from "./tool-executor.js";
|
|
21
|
+
export { buildAPIMessages, injectReminderIntoContent } from "./message-builder.js";
|
|
22
|
+
export { handleProactiveCompaction, handleReactiveCompaction, needsCompaction, estimateMessagesTokens, DEFAULT_PROACTIVE_OPTIONS, DEFAULT_REACTIVE_OPTIONS, } from "./compaction.js";
|
|
23
|
+
/**
|
|
24
|
+
* Main agent loop - processes messages in turns until completion
|
|
25
|
+
*/
|
|
26
|
+
export async function agentLoop(initialMessages, options) {
|
|
27
|
+
const { apiKey, model = "claude-sonnet-4-6", maxTokens = 4096, systemPrompt, tools, permissionMode, workingDirectory, gitStatus = null, reminderConfig, cacheConfig = DEFAULT_CACHE_CONFIG, thinking, extendedThinking, hookManager, sessionId, onText, onThinking, onToolUse, onToolResult, onMetrics, onReminder, onPermissionRequest, signal, } = options;
|
|
28
|
+
// Initialize state
|
|
29
|
+
const state = new LoopState(initialMessages);
|
|
30
|
+
const permissionManager = new PermissionManager(permissionMode, onPermissionRequest);
|
|
31
|
+
const mergedReminderConfig = { ...DEFAULT_REMINDER_CONFIG, ...reminderConfig };
|
|
32
|
+
// Execute SessionStart hook
|
|
33
|
+
if (hookManager) {
|
|
34
|
+
await hookManager.execute("SessionStart", {
|
|
35
|
+
session_id: sessionId,
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
let shouldContinue = true;
|
|
39
|
+
while (shouldContinue) {
|
|
40
|
+
if (signal?.aborted) {
|
|
41
|
+
break;
|
|
42
|
+
}
|
|
43
|
+
// Build turn executor options
|
|
44
|
+
const turnOptions = {
|
|
45
|
+
apiKey,
|
|
46
|
+
model,
|
|
47
|
+
maxTokens,
|
|
48
|
+
systemPrompt,
|
|
49
|
+
tools,
|
|
50
|
+
cacheConfig,
|
|
51
|
+
thinking,
|
|
52
|
+
extendedThinking,
|
|
53
|
+
workingDirectory,
|
|
54
|
+
gitStatus,
|
|
55
|
+
reminderConfig: mergedReminderConfig,
|
|
56
|
+
hookManager,
|
|
57
|
+
sessionId,
|
|
58
|
+
signal,
|
|
59
|
+
onText,
|
|
60
|
+
onThinking,
|
|
61
|
+
onToolUse,
|
|
62
|
+
onReminder,
|
|
63
|
+
permissionMode,
|
|
64
|
+
permissionManager,
|
|
65
|
+
onMetrics,
|
|
66
|
+
onToolResult,
|
|
67
|
+
};
|
|
68
|
+
// Execute a single turn
|
|
69
|
+
const turnResult = await executeTurn(state, turnOptions);
|
|
70
|
+
shouldContinue = turnResult.shouldContinue;
|
|
71
|
+
// Call onMetrics callback with the latest metrics
|
|
72
|
+
if (turnResult.metrics && onMetrics) {
|
|
73
|
+
onMetrics(turnResult.metrics);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
// Execute SessionEnd hook
|
|
77
|
+
if (hookManager) {
|
|
78
|
+
await hookManager.execute("SessionEnd", {
|
|
79
|
+
session_id: sessionId,
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
return state.toResult();
|
|
83
|
+
}
|