@ebowwa/coder 0.7.63 → 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/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 -52192
- 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 +159 -52768
- 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/package.json +4 -2
- 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
|
@@ -0,0 +1,431 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Permission System - Interactive permission prompts
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import * as readline from "readline";
|
|
6
|
+
|
|
7
|
+
// ============================================
|
|
8
|
+
// TYPES
|
|
9
|
+
// ============================================
|
|
10
|
+
|
|
11
|
+
export type PermissionMode =
|
|
12
|
+
| "default"
|
|
13
|
+
| "acceptEdits"
|
|
14
|
+
| "bypassPermissions"
|
|
15
|
+
| "dontAsk"
|
|
16
|
+
| "interactive"
|
|
17
|
+
| "plan";
|
|
18
|
+
|
|
19
|
+
export type PermissionDecision =
|
|
20
|
+
| "allow"
|
|
21
|
+
| "deny"
|
|
22
|
+
| "allowAlways"
|
|
23
|
+
| "denyAlways";
|
|
24
|
+
|
|
25
|
+
export interface PermissionRequest {
|
|
26
|
+
toolName: string;
|
|
27
|
+
toolInput: Record<string, unknown>;
|
|
28
|
+
riskLevel: "low" | "medium" | "high" | "critical";
|
|
29
|
+
description: string;
|
|
30
|
+
file?: string;
|
|
31
|
+
command?: string;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export interface PermissionResult {
|
|
35
|
+
decision: PermissionDecision;
|
|
36
|
+
reason?: string;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export interface PermissionCache {
|
|
40
|
+
[key: string]: {
|
|
41
|
+
decision: PermissionDecision;
|
|
42
|
+
timestamp: number;
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export type PermissionPromptCallback = (
|
|
47
|
+
request: PermissionRequest
|
|
48
|
+
) => Promise<PermissionResult>;
|
|
49
|
+
|
|
50
|
+
// ============================================
|
|
51
|
+
// RISK LEVEL ASSESSMENT
|
|
52
|
+
// ============================================
|
|
53
|
+
|
|
54
|
+
const TOOL_RISK_LEVELS: Record<string, "low" | "medium" | "high" | "critical"> = {
|
|
55
|
+
// Low risk - read-only, non-destructive
|
|
56
|
+
Read: "low",
|
|
57
|
+
Glob: "low",
|
|
58
|
+
Grep: "low",
|
|
59
|
+
Task: "low",
|
|
60
|
+
|
|
61
|
+
// Medium risk - modifies files but reversible
|
|
62
|
+
Write: "medium",
|
|
63
|
+
Edit: "medium",
|
|
64
|
+
NotebookEdit: "medium",
|
|
65
|
+
|
|
66
|
+
// Bash is assessed dynamically based on command
|
|
67
|
+
// Default to medium, elevated to high/critical by assessRiskLevel
|
|
68
|
+
Bash: "medium",
|
|
69
|
+
|
|
70
|
+
// Critical risk - irreversible operations
|
|
71
|
+
// (handled by input analysis)
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
// Read-only commands that are safe to auto-approve
|
|
75
|
+
const READ_ONLY_COMMANDS = [
|
|
76
|
+
/^date\b/,
|
|
77
|
+
/^ls\b/,
|
|
78
|
+
/^cat\b/,
|
|
79
|
+
/^head\b/,
|
|
80
|
+
/^tail\b/,
|
|
81
|
+
/^echo\b/,
|
|
82
|
+
/^pwd\b/,
|
|
83
|
+
/^whoami\b/,
|
|
84
|
+
/^which\b/,
|
|
85
|
+
/^uname\b/,
|
|
86
|
+
/^hostname\b/,
|
|
87
|
+
/^id\b/,
|
|
88
|
+
/^printenv\b/,
|
|
89
|
+
/^env\b/,
|
|
90
|
+
/^git\s+status\b/,
|
|
91
|
+
/^git\s+log\b/,
|
|
92
|
+
/^git\s+diff\b/,
|
|
93
|
+
/^git\s+branch\b/,
|
|
94
|
+
/^git\s+remote\b/,
|
|
95
|
+
/^git\s+rev-parse\b/,
|
|
96
|
+
/^git\s+show\b/,
|
|
97
|
+
/^npm\s+list\b/,
|
|
98
|
+
/^bun\s+--version\b/,
|
|
99
|
+
/^bun\s+-v\b/,
|
|
100
|
+
/^node\s+--version\b/,
|
|
101
|
+
/^node\s+-v\b/,
|
|
102
|
+
/^python\s+--version\b/,
|
|
103
|
+
/^python3\s+--version\b/,
|
|
104
|
+
/^uv\s+--version\b/,
|
|
105
|
+
/^doppler\s+\w+\s+--help\b/,
|
|
106
|
+
];
|
|
107
|
+
|
|
108
|
+
const CRITICAL_PATTERNS = [
|
|
109
|
+
/\brm\s+-rf\b/,
|
|
110
|
+
/\brm\s+-r\b/,
|
|
111
|
+
/\brm\s+[^-]/,
|
|
112
|
+
/\bgit\s+push\s+--force\b/,
|
|
113
|
+
/\bgit\s+reset\s+--hard\b/,
|
|
114
|
+
/\bgit\s+clean\s+-fd\b/,
|
|
115
|
+
/\bdrop\b/i,
|
|
116
|
+
/\bdelete\b/i,
|
|
117
|
+
/\btruncate\b/i,
|
|
118
|
+
/\bformat\b/i,
|
|
119
|
+
/\bdd\s+if=/,
|
|
120
|
+
/\bshred\b/,
|
|
121
|
+
/\b:\(\)\{\s*:\|:\s*&\s*\};\s*:\b/, // Fork bomb
|
|
122
|
+
];
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Assess risk level for a tool operation
|
|
126
|
+
*/
|
|
127
|
+
export function assessRiskLevel(
|
|
128
|
+
toolName: string,
|
|
129
|
+
toolInput: Record<string, unknown>
|
|
130
|
+
): "low" | "medium" | "high" | "critical" {
|
|
131
|
+
// Start with base risk level
|
|
132
|
+
let riskLevel = TOOL_RISK_LEVELS[toolName] ?? "medium";
|
|
133
|
+
|
|
134
|
+
// Check for critical patterns in Bash commands
|
|
135
|
+
if (toolName === "Bash") {
|
|
136
|
+
const command = String(toolInput.command ?? "");
|
|
137
|
+
|
|
138
|
+
for (const pattern of CRITICAL_PATTERNS) {
|
|
139
|
+
if (pattern.test(command)) {
|
|
140
|
+
return "critical";
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
// Elevated commands increase risk
|
|
145
|
+
if (/\bsudo\b/.test(command) || /\bchmod\b/.test(command)) {
|
|
146
|
+
riskLevel = "high";
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
// Write to sensitive files increases risk
|
|
151
|
+
if (toolName === "Write" || toolName === "Edit") {
|
|
152
|
+
const filePath = String(toolInput.file_path ?? toolInput.path ?? "");
|
|
153
|
+
|
|
154
|
+
if (/\.(env|pem|key|secret|credentials)/.test(filePath)) {
|
|
155
|
+
riskLevel = "high";
|
|
156
|
+
}
|
|
157
|
+
if (/\/\.ssh\//.test(filePath) || /\/\.gnupg\//.test(filePath)) {
|
|
158
|
+
riskLevel = "critical";
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
return riskLevel;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* Generate a human-readable description of the tool operation
|
|
167
|
+
*/
|
|
168
|
+
export function generateDescription(
|
|
169
|
+
toolName: string,
|
|
170
|
+
toolInput: Record<string, unknown>
|
|
171
|
+
): string {
|
|
172
|
+
switch (toolName) {
|
|
173
|
+
case "Read":
|
|
174
|
+
return `Read file: ${toolInput.file_path ?? "unknown"}`;
|
|
175
|
+
case "Write":
|
|
176
|
+
return `Write file: ${toolInput.file_path ?? "unknown"} (${String(toolInput.content ?? "").length} chars)`;
|
|
177
|
+
case "Edit":
|
|
178
|
+
return `Edit file: ${toolInput.file_path ?? "unknown"}`;
|
|
179
|
+
case "Bash":
|
|
180
|
+
return `Execute: ${String(toolInput.command ?? "").slice(0, 100)}${String(toolInput.command ?? "").length > 100 ? "..." : ""}`;
|
|
181
|
+
case "Glob":
|
|
182
|
+
return `Find files: ${toolInput.pattern ?? "*"}`;
|
|
183
|
+
case "Grep":
|
|
184
|
+
return `Search: "${toolInput.pattern ?? ""}" in ${toolInput.path ?? "."}`;
|
|
185
|
+
case "Task":
|
|
186
|
+
return `Spawn agent: ${toolInput.subagent_type ?? "unknown"}`;
|
|
187
|
+
default:
|
|
188
|
+
return `Use tool: ${toolName}`;
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
// ============================================
|
|
193
|
+
// PERMISSION MANAGER
|
|
194
|
+
// ============================================
|
|
195
|
+
|
|
196
|
+
export class PermissionManager {
|
|
197
|
+
private cache: PermissionCache = {};
|
|
198
|
+
private cacheTimeout = 5 * 60 * 1000; // 5 minutes
|
|
199
|
+
private promptCallback: PermissionPromptCallback;
|
|
200
|
+
private mode: PermissionMode;
|
|
201
|
+
|
|
202
|
+
constructor(
|
|
203
|
+
mode: PermissionMode = "default",
|
|
204
|
+
promptCallback?: PermissionPromptCallback
|
|
205
|
+
) {
|
|
206
|
+
this.mode = mode;
|
|
207
|
+
this.promptCallback = promptCallback ?? this.defaultPrompt.bind(this);
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
/**
|
|
211
|
+
* Check if a tool operation is permitted
|
|
212
|
+
*/
|
|
213
|
+
async checkPermission(
|
|
214
|
+
toolName: string,
|
|
215
|
+
toolInput: Record<string, unknown>
|
|
216
|
+
): Promise<PermissionResult> {
|
|
217
|
+
// Bypass mode - always allow
|
|
218
|
+
if (this.mode === "bypassPermissions") {
|
|
219
|
+
return { decision: "allow" };
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
// DontAsk mode - always deny
|
|
223
|
+
if (this.mode === "dontAsk") {
|
|
224
|
+
return { decision: "deny", reason: "Permission mode is dontAsk" };
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
// AcceptEdits mode - allow file operations and non-critical Bash commands
|
|
228
|
+
if (this.mode === "acceptEdits") {
|
|
229
|
+
const fileTools = ["Read", "Write", "Edit", "Glob", "Grep"];
|
|
230
|
+
if (fileTools.includes(toolName)) {
|
|
231
|
+
return { decision: "allow" };
|
|
232
|
+
}
|
|
233
|
+
// Also allow non-critical Bash commands (low/medium risk)
|
|
234
|
+
if (toolName === "Bash") {
|
|
235
|
+
const riskLevel = assessRiskLevel(toolName, toolInput);
|
|
236
|
+
if (riskLevel === "low" || riskLevel === "medium") {
|
|
237
|
+
return { decision: "allow" };
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
// Plan mode - deny all write operations
|
|
243
|
+
if (this.mode === "plan") {
|
|
244
|
+
const readOnlyTools = ["Read", "Glob", "Grep", "Task"];
|
|
245
|
+
if (readOnlyTools.includes(toolName)) {
|
|
246
|
+
return { decision: "allow" };
|
|
247
|
+
}
|
|
248
|
+
return { decision: "deny", reason: "Plan mode - write operations disabled" };
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
// Check cache for "always" decisions
|
|
252
|
+
const cacheKey = this.getCacheKey(toolName, toolInput);
|
|
253
|
+
const cached = this.cache[cacheKey];
|
|
254
|
+
|
|
255
|
+
if (cached && Date.now() - cached.timestamp < this.cacheTimeout) {
|
|
256
|
+
if (cached.decision === "allowAlways") {
|
|
257
|
+
return { decision: "allow", reason: "Previously approved (always)" };
|
|
258
|
+
}
|
|
259
|
+
if (cached.decision === "denyAlways") {
|
|
260
|
+
return { decision: "deny", reason: "Previously denied (always)" };
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
// Assess risk level
|
|
265
|
+
const riskLevel = assessRiskLevel(toolName, toolInput);
|
|
266
|
+
const description = generateDescription(toolName, toolInput);
|
|
267
|
+
|
|
268
|
+
// Create permission request
|
|
269
|
+
const request: PermissionRequest = {
|
|
270
|
+
toolName,
|
|
271
|
+
toolInput,
|
|
272
|
+
riskLevel,
|
|
273
|
+
description,
|
|
274
|
+
file: (toolInput.file_path ?? toolInput.path) as string | undefined,
|
|
275
|
+
command: toolName === "Bash" ? toolInput.command as string : undefined,
|
|
276
|
+
};
|
|
277
|
+
|
|
278
|
+
// Prompt user for interactive/default modes
|
|
279
|
+
if (this.mode === "interactive" || this.mode === "default") {
|
|
280
|
+
const result = await this.promptCallback(request);
|
|
281
|
+
|
|
282
|
+
// Cache "always" decisions
|
|
283
|
+
if (result.decision === "allowAlways" || result.decision === "denyAlways") {
|
|
284
|
+
this.cache[cacheKey] = {
|
|
285
|
+
decision: result.decision,
|
|
286
|
+
timestamp: Date.now(),
|
|
287
|
+
};
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
return result;
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
// Default to allow for unknown modes
|
|
294
|
+
return { decision: "allow" };
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
/**
|
|
298
|
+
* Generate cache key for permission
|
|
299
|
+
*/
|
|
300
|
+
private getCacheKey(toolName: string, toolInput: Record<string, unknown>): string {
|
|
301
|
+
// For file operations, key on file path
|
|
302
|
+
if (["Read", "Write", "Edit"].includes(toolName)) {
|
|
303
|
+
return `${toolName}:${toolInput.file_path ?? toolInput.path ?? "unknown"}`;
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
// For bash, key on command (first 100 chars)
|
|
307
|
+
if (toolName === "Bash") {
|
|
308
|
+
const cmd = String(toolInput.command ?? "").slice(0, 100);
|
|
309
|
+
return `${toolName}:${cmd}`;
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
// Default: key on tool name only
|
|
313
|
+
return toolName;
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
/**
|
|
317
|
+
* Default prompt implementation using readline
|
|
318
|
+
*/
|
|
319
|
+
private async defaultPrompt(request: PermissionRequest): Promise<PermissionResult> {
|
|
320
|
+
return new Promise((resolve) => {
|
|
321
|
+
const rl = readline.createInterface({
|
|
322
|
+
input: process.stdin,
|
|
323
|
+
output: process.stdout,
|
|
324
|
+
});
|
|
325
|
+
|
|
326
|
+
// Format risk level with color
|
|
327
|
+
const riskColors: Record<string, string> = {
|
|
328
|
+
low: "\x1b[32m", // Green
|
|
329
|
+
medium: "\x1b[33m", // Yellow
|
|
330
|
+
high: "\x1b[31m", // Red
|
|
331
|
+
critical: "\x1b[35m", // Magenta
|
|
332
|
+
};
|
|
333
|
+
const riskColor = riskColors[request.riskLevel] ?? "\x1b[0m";
|
|
334
|
+
const reset = "\x1b[0m";
|
|
335
|
+
|
|
336
|
+
console.log("");
|
|
337
|
+
console.log(`\x1b[36m━━━ Permission Required ━━━\x1b[0m`);
|
|
338
|
+
console.log(`Tool: \x1b[1m${request.toolName}\x1b[0m`);
|
|
339
|
+
console.log(`Risk: ${riskColor}${request.riskLevel.toUpperCase()}${reset}`);
|
|
340
|
+
console.log(`Action: ${request.description}`);
|
|
341
|
+
|
|
342
|
+
if (request.file) {
|
|
343
|
+
console.log(`File: ${request.file}`);
|
|
344
|
+
}
|
|
345
|
+
if (request.command) {
|
|
346
|
+
console.log(`Command: ${request.command.slice(0, 200)}${request.command.length > 200 ? "..." : ""}`);
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
console.log("");
|
|
350
|
+
|
|
351
|
+
const options = "[y]es / [n]o / [a]lways / [d]eny always";
|
|
352
|
+
rl.question(`Allow? ${options}: `, (answer) => {
|
|
353
|
+
rl.close();
|
|
354
|
+
|
|
355
|
+
const input = answer.trim().toLowerCase();
|
|
356
|
+
|
|
357
|
+
switch (input) {
|
|
358
|
+
case "y":
|
|
359
|
+
case "yes":
|
|
360
|
+
resolve({ decision: "allow" });
|
|
361
|
+
break;
|
|
362
|
+
case "a":
|
|
363
|
+
case "always":
|
|
364
|
+
resolve({ decision: "allowAlways" });
|
|
365
|
+
break;
|
|
366
|
+
case "d":
|
|
367
|
+
case "deny":
|
|
368
|
+
case "deny always":
|
|
369
|
+
resolve({ decision: "denyAlways" });
|
|
370
|
+
break;
|
|
371
|
+
case "n":
|
|
372
|
+
case "no":
|
|
373
|
+
default:
|
|
374
|
+
resolve({ decision: "deny" });
|
|
375
|
+
break;
|
|
376
|
+
}
|
|
377
|
+
});
|
|
378
|
+
});
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
/**
|
|
382
|
+
* Clear permission cache
|
|
383
|
+
*/
|
|
384
|
+
clearCache(): void {
|
|
385
|
+
this.cache = {};
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
/**
|
|
389
|
+
* Set permission mode
|
|
390
|
+
*/
|
|
391
|
+
setMode(mode: PermissionMode): void {
|
|
392
|
+
this.mode = mode;
|
|
393
|
+
// Clear cache when mode changes
|
|
394
|
+
this.clearCache();
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
// ============================================
|
|
399
|
+
// PERMISSION CATEGORIES
|
|
400
|
+
// ============================================
|
|
401
|
+
|
|
402
|
+
/**
|
|
403
|
+
* Tool categories for permission decisions
|
|
404
|
+
*/
|
|
405
|
+
export const TOOL_CATEGORIES = {
|
|
406
|
+
readOnly: ["Read", "Glob", "Grep", "Task"],
|
|
407
|
+
fileEdit: ["Write", "Edit", "NotebookEdit"],
|
|
408
|
+
system: ["Bash"],
|
|
409
|
+
network: [], // Future: HTTP requests, etc.
|
|
410
|
+
} as const;
|
|
411
|
+
|
|
412
|
+
/**
|
|
413
|
+
* Check if tool is read-only
|
|
414
|
+
*/
|
|
415
|
+
export function isReadOnlyTool(toolName: string): boolean {
|
|
416
|
+
return TOOL_CATEGORIES.readOnly.includes(toolName as typeof TOOL_CATEGORIES.readOnly[number]);
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
/**
|
|
420
|
+
* Check if tool modifies files
|
|
421
|
+
*/
|
|
422
|
+
export function isFileEditTool(toolName: string): boolean {
|
|
423
|
+
return TOOL_CATEGORIES.fileEdit.includes(toolName as typeof TOOL_CATEGORIES.fileEdit[number]);
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
/**
|
|
427
|
+
* Check if tool executes system commands
|
|
428
|
+
*/
|
|
429
|
+
export function isSystemTool(toolName: string): boolean {
|
|
430
|
+
return TOOL_CATEGORIES.system.includes(toolName as typeof TOOL_CATEGORIES.system[number]);
|
|
431
|
+
}
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Retry Logic - Exponential backoff with jitter for API failures
|
|
3
|
+
* Handles rate limits, network errors, and transient failures
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
export interface RetryOptions {
|
|
7
|
+
maxRetries?: number;
|
|
8
|
+
baseDelayMs?: number;
|
|
9
|
+
maxDelayMs?: number;
|
|
10
|
+
jitterFactor?: number;
|
|
11
|
+
retryableStatusCodes?: number[];
|
|
12
|
+
onRetry?: (attempt: number, error: Error, delayMs: number) => void;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const DEFAULT_RETRY_OPTIONS = {
|
|
16
|
+
maxRetries: 3,
|
|
17
|
+
baseDelayMs: 1000,
|
|
18
|
+
maxDelayMs: 30000,
|
|
19
|
+
jitterFactor: 0.2,
|
|
20
|
+
retryableStatusCodes: [429, 500, 502, 503, 504, 529],
|
|
21
|
+
onRetry: undefined as ((attempt: number, error: Error, delayMs: number) => void) | undefined,
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Calculate delay with exponential backoff and jitter
|
|
26
|
+
*/
|
|
27
|
+
function calculateDelay(
|
|
28
|
+
attempt: number,
|
|
29
|
+
baseDelayMs: number,
|
|
30
|
+
maxDelayMs: number,
|
|
31
|
+
jitterFactor: number
|
|
32
|
+
): number {
|
|
33
|
+
// Exponential backoff: baseDelay * 2^attempt
|
|
34
|
+
const exponentialDelay = baseDelayMs * Math.pow(2, attempt);
|
|
35
|
+
|
|
36
|
+
// Add jitter to prevent thundering herd
|
|
37
|
+
const jitter = exponentialDelay * jitterFactor * (Math.random() * 2 - 1);
|
|
38
|
+
|
|
39
|
+
// Cap at max delay
|
|
40
|
+
return Math.min(exponentialDelay + jitter, maxDelayMs);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Check if an error is retryable
|
|
45
|
+
*/
|
|
46
|
+
function isRetryableError(
|
|
47
|
+
error: Error,
|
|
48
|
+
retryableStatusCodes: number[]
|
|
49
|
+
): boolean {
|
|
50
|
+
// Check for rate limit errors
|
|
51
|
+
if (error.message.includes("429") || error.message.includes("rate limit")) {
|
|
52
|
+
return true;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// Check for server errors
|
|
56
|
+
if (error.message.includes("500") ||
|
|
57
|
+
error.message.includes("502") ||
|
|
58
|
+
error.message.includes("503") ||
|
|
59
|
+
error.message.includes("504")) {
|
|
60
|
+
return true;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// Check for network errors
|
|
64
|
+
if (error.message.includes("ECONNREFUSED") ||
|
|
65
|
+
error.message.includes("ENOTFOUND") ||
|
|
66
|
+
error.message.includes("ETIMEDOUT") ||
|
|
67
|
+
error.message.includes("network") ||
|
|
68
|
+
error.message.includes("fetch failed")) {
|
|
69
|
+
return true;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// Check for specific status codes in error message
|
|
73
|
+
for (const code of retryableStatusCodes) {
|
|
74
|
+
if (error.message.includes(String(code))) {
|
|
75
|
+
return true;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
return false;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Sleep for a given number of milliseconds
|
|
84
|
+
*/
|
|
85
|
+
function sleep(ms: number): Promise<void> {
|
|
86
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Execute a function with retry logic
|
|
91
|
+
*/
|
|
92
|
+
export async function withRetry<T>(
|
|
93
|
+
fn: () => Promise<T>,
|
|
94
|
+
options: RetryOptions = {}
|
|
95
|
+
): Promise<T> {
|
|
96
|
+
const opts = { ...DEFAULT_RETRY_OPTIONS, ...options };
|
|
97
|
+
let lastError: Error | null = null;
|
|
98
|
+
|
|
99
|
+
for (let attempt = 0; attempt <= opts.maxRetries!; attempt++) {
|
|
100
|
+
try {
|
|
101
|
+
return await fn();
|
|
102
|
+
} catch (error) {
|
|
103
|
+
lastError = error instanceof Error ? error : new Error(String(error));
|
|
104
|
+
|
|
105
|
+
// Check if we should retry
|
|
106
|
+
if (attempt < opts.maxRetries! && isRetryableError(lastError, opts.retryableStatusCodes!)) {
|
|
107
|
+
const delayMs = calculateDelay(
|
|
108
|
+
attempt,
|
|
109
|
+
opts.baseDelayMs!,
|
|
110
|
+
opts.maxDelayMs!,
|
|
111
|
+
opts.jitterFactor!
|
|
112
|
+
);
|
|
113
|
+
|
|
114
|
+
// Log retry attempt
|
|
115
|
+
if (opts.onRetry) {
|
|
116
|
+
opts.onRetry(attempt + 1, lastError, delayMs);
|
|
117
|
+
} else {
|
|
118
|
+
console.warn(
|
|
119
|
+
`\x1b[33mRetry ${attempt + 1}/${opts.maxRetries} after ${delayMs}ms: ${lastError.message}\x1b[0m`
|
|
120
|
+
);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
await sleep(delayMs);
|
|
124
|
+
} else {
|
|
125
|
+
// Non-retryable error or max retries reached
|
|
126
|
+
throw lastError;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
throw lastError || new Error("Max retries exceeded");
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Create a retry wrapper for fetch
|
|
136
|
+
*/
|
|
137
|
+
export function createFetchWithRetry(
|
|
138
|
+
options: RetryOptions = {}
|
|
139
|
+
): (url: string, init?: RequestInit) => Promise<Response> {
|
|
140
|
+
return async (url: string, init?: RequestInit): Promise<Response> => {
|
|
141
|
+
return withRetry(
|
|
142
|
+
async () => {
|
|
143
|
+
const response = await fetch(url, init);
|
|
144
|
+
|
|
145
|
+
// Check for retryable status codes
|
|
146
|
+
if (options.retryableStatusCodes?.includes(response.status)) {
|
|
147
|
+
const text = await response.text();
|
|
148
|
+
throw new Error(`API error: ${response.status} - ${text}`);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
return response;
|
|
152
|
+
},
|
|
153
|
+
options
|
|
154
|
+
);
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* Parse retry-after header from rate limit response
|
|
160
|
+
*/
|
|
161
|
+
export function parseRetryAfter(response: Response): number | null {
|
|
162
|
+
const retryAfter = response.headers.get("retry-after");
|
|
163
|
+
if (retryAfter) {
|
|
164
|
+
const seconds = parseInt(retryAfter, 10);
|
|
165
|
+
if (!isNaN(seconds)) {
|
|
166
|
+
return seconds * 1000; // Convert to milliseconds
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
return null;
|
|
170
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Session Store - Backward compatibility layer
|
|
3
|
+
* Re-exports from composable sessions module
|
|
4
|
+
*
|
|
5
|
+
* @deprecated Import from "./sessions/index.js" instead for composable access
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
// Re-export everything from the new composable module
|
|
9
|
+
export {
|
|
10
|
+
SessionStore,
|
|
11
|
+
SessionPersistence,
|
|
12
|
+
SessionMetadataManager,
|
|
13
|
+
SessionExporter,
|
|
14
|
+
formatSessionSummary,
|
|
15
|
+
printSessionsList,
|
|
16
|
+
// Types
|
|
17
|
+
type SessionMetadata,
|
|
18
|
+
type SessionMessage,
|
|
19
|
+
type SessionToolUse,
|
|
20
|
+
type SessionMetrics,
|
|
21
|
+
type SessionContext,
|
|
22
|
+
type SessionCheckpoint,
|
|
23
|
+
type SessionEntry,
|
|
24
|
+
type LoadedSession,
|
|
25
|
+
type SessionSummary,
|
|
26
|
+
type SessionFilter,
|
|
27
|
+
type SessionEvent,
|
|
28
|
+
type SessionEventType,
|
|
29
|
+
type SessionEventHandler,
|
|
30
|
+
type ExportFormat,
|
|
31
|
+
type ISessionPersistence,
|
|
32
|
+
type ISessionExporter,
|
|
33
|
+
} from "./sessions/index.js";
|
|
34
|
+
|
|
35
|
+
// Default export
|
|
36
|
+
export { SessionStore as default } from "./sessions/index.js";
|