@ebowwa/coder 0.7.63 → 0.7.65
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/core/__tests__/permissions.test.d.ts +12 -0
- package/dist/core/__tests__/permissions.test.d.ts.map +1 -0
- package/dist/core/__tests__/permissions.test.js +851 -0
- package/dist/core/agent-loop/__tests__/compaction.test.d.ts +5 -0
- package/dist/core/agent-loop/__tests__/compaction.test.d.ts.map +1 -0
- package/dist/core/agent-loop/__tests__/compaction.test.js +209 -0
- package/dist/core/agent-loop/__tests__/formatters.test.d.ts +5 -0
- package/dist/core/agent-loop/__tests__/formatters.test.d.ts.map +1 -0
- package/dist/core/agent-loop/__tests__/formatters.test.js +195 -0
- package/dist/core/agent-loop/__tests__/index.test.d.ts +5 -0
- package/dist/core/agent-loop/__tests__/index.test.d.ts.map +1 -0
- package/dist/core/agent-loop/__tests__/index.test.js +121 -0
- package/dist/core/agent-loop/__tests__/loop-state.test.d.ts +5 -0
- package/dist/core/agent-loop/__tests__/loop-state.test.d.ts.map +1 -0
- package/dist/core/agent-loop/__tests__/loop-state.test.js +340 -0
- package/dist/core/agent-loop/__tests__/message-builder.test.d.ts +5 -0
- package/dist/core/agent-loop/__tests__/message-builder.test.d.ts.map +1 -0
- package/dist/core/agent-loop/__tests__/message-builder.test.js +178 -0
- package/dist/core/agent-loop/__tests__/tool-executor.test.d.ts +5 -0
- package/dist/core/agent-loop/__tests__/tool-executor.test.d.ts.map +1 -0
- package/dist/core/agent-loop/__tests__/tool-executor.test.js +331 -0
- package/dist/core/agent-loop/compaction.d.ts +39 -0
- package/dist/core/agent-loop/compaction.d.ts.map +1 -0
- package/dist/core/agent-loop/compaction.js +51 -0
- package/dist/core/agent-loop/formatters.d.ts +21 -0
- package/dist/core/agent-loop/formatters.d.ts.map +1 -0
- package/dist/core/agent-loop/formatters.js +42 -0
- package/dist/core/agent-loop/index.d.ts +25 -0
- package/dist/core/agent-loop/index.d.ts.map +1 -0
- package/dist/core/agent-loop/index.js +83 -0
- package/dist/core/agent-loop/loop-state.d.ts +74 -0
- package/dist/core/agent-loop/loop-state.d.ts.map +1 -0
- package/dist/core/agent-loop/loop-state.js +147 -0
- package/dist/core/agent-loop/message-builder.d.ts +13 -0
- package/dist/core/agent-loop/message-builder.d.ts.map +1 -0
- package/dist/core/agent-loop/message-builder.js +49 -0
- package/dist/core/agent-loop/tool-executor.d.ts +23 -0
- package/dist/core/agent-loop/tool-executor.d.ts.map +1 -0
- package/dist/core/agent-loop/tool-executor.js +152 -0
- package/dist/core/agent-loop/turn-executor.d.ts +57 -0
- package/dist/core/agent-loop/turn-executor.d.ts.map +1 -0
- package/dist/core/agent-loop/turn-executor.js +124 -0
- package/dist/core/agent-loop/types.d.ts +141 -0
- package/dist/core/agent-loop/types.d.ts.map +1 -0
- package/dist/core/agent-loop/types.js +4 -0
- package/dist/core/agent-loop.d.ts +17 -0
- package/dist/core/agent-loop.d.ts.map +1 -0
- package/dist/core/agent-loop.js +16 -0
- package/dist/core/api-client-impl.d.ts +62 -0
- package/dist/core/api-client-impl.d.ts.map +1 -0
- package/dist/core/api-client-impl.js +479 -0
- package/dist/core/api-client.d.ts +6 -0
- package/dist/core/api-client.d.ts.map +1 -0
- package/dist/core/api-client.js +5 -0
- package/dist/core/checkpoints.d.ts +128 -0
- package/dist/core/checkpoints.d.ts.map +1 -0
- package/dist/core/checkpoints.js +438 -0
- package/dist/core/claude-md.d.ts +71 -0
- package/dist/core/claude-md.d.ts.map +1 -0
- package/dist/core/claude-md.js +198 -0
- package/dist/core/cognitive-security/hooks.d.ts +138 -0
- package/dist/core/cognitive-security/hooks.d.ts.map +1 -0
- package/dist/core/cognitive-security/hooks.js +389 -0
- package/dist/core/cognitive-security/index.d.ts +751 -0
- package/dist/core/cognitive-security/index.d.ts.map +1 -0
- package/dist/core/cognitive-security/index.js +1123 -0
- package/dist/core/cognitive-security/middleware.d.ts +136 -0
- package/dist/core/cognitive-security/middleware.d.ts.map +1 -0
- package/dist/core/cognitive-security/middleware.js +376 -0
- package/dist/core/config-loader.d.ts +127 -0
- package/dist/core/config-loader.d.ts.map +1 -0
- package/dist/core/config-loader.js +219 -0
- package/dist/core/context-compaction.d.ts +87 -0
- package/dist/core/context-compaction.d.ts.map +1 -0
- package/dist/core/context-compaction.js +428 -0
- package/dist/core/git-status.d.ts +25 -0
- package/dist/core/git-status.d.ts.map +1 -0
- package/dist/core/git-status.js +204 -0
- package/dist/core/image.d.ts +69 -0
- package/dist/core/image.d.ts.map +1 -0
- package/dist/core/image.js +290 -0
- package/dist/core/image.test.d.ts +2 -0
- package/dist/core/image.test.d.ts.map +1 -0
- package/dist/core/image.test.js +149 -0
- package/dist/core/models.d.ts +123 -0
- package/dist/core/models.d.ts.map +1 -0
- package/dist/core/models.js +325 -0
- package/dist/core/permissions.d.ts +81 -0
- package/dist/core/permissions.d.ts.map +1 -0
- package/dist/core/permissions.js +327 -0
- package/dist/core/retry.d.ts +25 -0
- package/dist/core/retry.d.ts.map +1 -0
- package/dist/core/retry.js +121 -0
- package/dist/core/session-store.d.ts +9 -0
- package/dist/core/session-store.d.ts.map +1 -0
- package/dist/core/session-store.js +10 -0
- package/dist/core/sessions/export.d.ts +47 -0
- package/dist/core/sessions/export.d.ts.map +1 -0
- package/dist/core/sessions/export.js +256 -0
- package/dist/core/sessions/index.d.ts +132 -0
- package/dist/core/sessions/index.d.ts.map +1 -0
- package/dist/core/sessions/index.js +442 -0
- package/dist/core/sessions/metadata.d.ts +77 -0
- package/dist/core/sessions/metadata.d.ts.map +1 -0
- package/dist/core/sessions/metadata.js +233 -0
- package/dist/core/sessions/persistence.d.ts +72 -0
- package/dist/core/sessions/persistence.d.ts.map +1 -0
- package/dist/core/sessions/persistence.js +201 -0
- package/dist/core/sessions/types.d.ts +110 -0
- package/dist/core/sessions/types.d.ts.map +1 -0
- package/dist/core/sessions/types.js +4 -0
- package/dist/core/stream-highlighter.d.ts +18 -0
- package/dist/core/stream-highlighter.d.ts.map +1 -0
- package/dist/core/stream-highlighter.js +916 -0
- package/dist/core/system-reminders.d.ts +89 -0
- package/dist/core/system-reminders.d.ts.map +1 -0
- package/dist/core/system-reminders.js +285 -0
- package/dist/ecosystem/hooks/__tests__/index.test.d.ts +5 -0
- package/dist/ecosystem/hooks/__tests__/index.test.d.ts.map +1 -0
- package/dist/ecosystem/hooks/__tests__/index.test.js +458 -0
- package/dist/ecosystem/hooks/index.d.ts +59 -0
- package/dist/ecosystem/hooks/index.d.ts.map +1 -0
- package/dist/ecosystem/hooks/index.js +294 -0
- package/dist/ecosystem/hooks/prompt-evaluator.d.ts +32 -0
- package/dist/ecosystem/hooks/prompt-evaluator.d.ts.map +1 -0
- package/dist/ecosystem/hooks/prompt-evaluator.js +229 -0
- package/dist/ecosystem/skills/index.d.ts +55 -0
- package/dist/ecosystem/skills/index.d.ts.map +1 -0
- package/dist/ecosystem/skills/index.js +258 -0
- package/dist/ecosystem/tools/__tests__/index.test.d.ts +7 -0
- package/dist/ecosystem/tools/__tests__/index.test.d.ts.map +1 -0
- package/dist/ecosystem/tools/__tests__/index.test.js +856 -0
- package/dist/ecosystem/tools/index.d.ts +24 -0
- package/dist/ecosystem/tools/index.d.ts.map +1 -0
- package/dist/ecosystem/tools/index.js +1709 -0
- package/dist/index.d.ts +24 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +33688 -49712
- package/dist/interfaces/mcp/client.d.ts +40 -0
- package/dist/interfaces/mcp/client.d.ts.map +1 -0
- package/dist/interfaces/mcp/client.js +309 -0
- package/dist/interfaces/ui/index.d.ts +36 -0
- package/dist/interfaces/ui/index.d.ts.map +1 -0
- package/dist/interfaces/ui/index.js +61 -0
- package/dist/interfaces/ui/spinner.d.ts +140 -0
- package/dist/interfaces/ui/spinner.d.ts.map +1 -0
- package/dist/interfaces/ui/spinner.js +342 -0
- package/dist/interfaces/ui/terminal/cli/index.d.ts +12 -0
- package/dist/interfaces/ui/terminal/cli/index.d.ts.map +1 -0
- package/dist/interfaces/ui/terminal/cli/index.js +32012 -50526
- package/dist/interfaces/ui/terminal/native/README.md +53 -0
- package/dist/interfaces/ui/terminal/native/claude_code_native.darwin-x64.node +0 -0
- package/dist/interfaces/ui/terminal/native/claude_code_native.dylib +0 -0
- package/dist/interfaces/ui/terminal/native/index.d.ts +0 -0
- package/dist/interfaces/ui/terminal/native/index.darwin-arm64.node +0 -0
- package/dist/interfaces/ui/terminal/native/index.js +43 -0
- package/dist/interfaces/ui/terminal/native/index.node +0 -0
- package/dist/interfaces/ui/terminal/native/package.json +34 -0
- package/dist/interfaces/ui/terminal/shared/args.d.ts +39 -0
- package/dist/interfaces/ui/terminal/shared/args.d.ts.map +1 -0
- package/dist/interfaces/ui/terminal/shared/args.js +176 -0
- package/dist/interfaces/ui/terminal/shared/index.d.ts +11 -0
- package/dist/interfaces/ui/terminal/shared/index.d.ts.map +1 -0
- package/dist/interfaces/ui/terminal/shared/index.js +16 -0
- package/dist/interfaces/ui/terminal/shared/loading-state.d.ts +124 -0
- package/dist/interfaces/ui/terminal/shared/loading-state.d.ts.map +1 -0
- package/dist/interfaces/ui/terminal/shared/loading-state.js +246 -0
- package/dist/interfaces/ui/terminal/shared/query.d.ts +22 -0
- package/dist/interfaces/ui/terminal/shared/query.d.ts.map +1 -0
- package/dist/interfaces/ui/terminal/shared/query.js +100 -0
- package/dist/interfaces/ui/terminal/shared/setup.d.ts +33 -0
- package/dist/interfaces/ui/terminal/shared/setup.d.ts.map +1 -0
- package/dist/interfaces/ui/terminal/shared/setup.js +226 -0
- package/dist/interfaces/ui/terminal/shared/status-line.d.ts +117 -0
- package/dist/interfaces/ui/terminal/shared/status-line.d.ts.map +1 -0
- package/dist/interfaces/ui/terminal/shared/status-line.js +267 -0
- package/dist/interfaces/ui/terminal/shared/system-prompt.d.ts +38 -0
- package/dist/interfaces/ui/terminal/shared/system-prompt.d.ts.map +1 -0
- package/dist/interfaces/ui/terminal/shared/system-prompt.js +102 -0
- package/dist/interfaces/ui/terminal/tui/HelpPanel.d.ts +39 -0
- package/dist/interfaces/ui/terminal/tui/HelpPanel.d.ts.map +1 -0
- package/dist/interfaces/ui/terminal/tui/HelpPanel.js +215 -0
- package/dist/interfaces/ui/terminal/tui/InputContext.d.ts +91 -0
- package/dist/interfaces/ui/terminal/tui/InputContext.d.ts.map +1 -0
- package/dist/interfaces/ui/terminal/tui/InputContext.js +154 -0
- package/dist/interfaces/ui/terminal/tui/InputField.d.ts +18 -0
- package/dist/interfaces/ui/terminal/tui/InputField.d.ts.map +1 -0
- package/dist/interfaces/ui/terminal/tui/InputField.js +41 -0
- package/dist/interfaces/ui/terminal/tui/InteractiveTUI.d.ts +16 -0
- package/dist/interfaces/ui/terminal/tui/InteractiveTUI.d.ts.map +1 -0
- package/dist/interfaces/ui/terminal/tui/InteractiveTUI.js +451 -0
- package/dist/interfaces/ui/terminal/tui/MessageArea.d.ts +10 -0
- package/dist/interfaces/ui/terminal/tui/MessageArea.d.ts.map +1 -0
- package/dist/interfaces/ui/terminal/tui/MessageArea.js +91 -0
- package/dist/interfaces/ui/terminal/tui/MessageStore.d.ts +48 -0
- package/dist/interfaces/ui/terminal/tui/MessageStore.d.ts.map +1 -0
- package/dist/interfaces/ui/terminal/tui/MessageStore.js +151 -0
- package/dist/interfaces/ui/terminal/tui/StatusBar.d.ts +9 -0
- package/dist/interfaces/ui/terminal/tui/StatusBar.d.ts.map +1 -0
- package/dist/interfaces/ui/terminal/tui/StatusBar.js +36 -0
- package/dist/interfaces/ui/terminal/tui/commands.d.ts +21 -0
- package/dist/interfaces/ui/terminal/tui/commands.d.ts.map +1 -0
- package/dist/interfaces/ui/terminal/tui/commands.js +359 -0
- package/dist/interfaces/ui/terminal/tui/components/InteractiveElements.d.ts +115 -0
- package/dist/interfaces/ui/terminal/tui/components/InteractiveElements.d.ts.map +1 -0
- package/dist/interfaces/ui/terminal/tui/components/InteractiveElements.js +306 -0
- package/dist/interfaces/ui/terminal/tui/components/MultilineInput.d.ts +92 -0
- package/dist/interfaces/ui/terminal/tui/components/MultilineInput.d.ts.map +1 -0
- package/dist/interfaces/ui/terminal/tui/components/MultilineInput.js +399 -0
- package/dist/interfaces/ui/terminal/tui/components/PaneManager.d.ts +59 -0
- package/dist/interfaces/ui/terminal/tui/components/PaneManager.d.ts.map +1 -0
- package/dist/interfaces/ui/terminal/tui/components/PaneManager.js +139 -0
- package/dist/interfaces/ui/terminal/tui/components/Sidebar.d.ts +68 -0
- package/dist/interfaces/ui/terminal/tui/components/Sidebar.d.ts.map +1 -0
- package/dist/interfaces/ui/terminal/tui/components/Sidebar.js +340 -0
- package/dist/interfaces/ui/terminal/tui/components/index.d.ts +23 -0
- package/dist/interfaces/ui/terminal/tui/components/index.d.ts.map +1 -0
- package/dist/interfaces/ui/terminal/tui/components/index.js +51 -0
- package/dist/interfaces/ui/terminal/tui/console.d.ts +20 -0
- package/dist/interfaces/ui/terminal/tui/console.d.ts.map +1 -0
- package/dist/interfaces/ui/terminal/tui/console.js +46 -0
- package/dist/interfaces/ui/terminal/tui/index.d.ts +20 -0
- package/dist/interfaces/ui/terminal/tui/index.d.ts.map +1 -0
- package/dist/interfaces/ui/terminal/tui/index.js +28 -0
- package/dist/interfaces/ui/terminal/tui/run.d.ts +13 -0
- package/dist/interfaces/ui/terminal/tui/run.d.ts.map +1 -0
- package/dist/interfaces/ui/terminal/tui/run.js +31 -0
- package/dist/interfaces/ui/terminal/tui/spinner.d.ts +44 -0
- package/dist/interfaces/ui/terminal/tui/spinner.d.ts.map +1 -0
- package/dist/interfaces/ui/terminal/tui/spinner.js +59 -0
- package/dist/interfaces/ui/terminal/tui/tui-app.d.ts +39 -0
- package/dist/interfaces/ui/terminal/tui/tui-app.d.ts.map +1 -0
- package/dist/interfaces/ui/terminal/tui/tui-app.js +198 -0
- package/dist/interfaces/ui/terminal/tui/tui-footer.d.ts +167 -0
- package/dist/interfaces/ui/terminal/tui/tui-footer.d.ts.map +1 -0
- package/dist/interfaces/ui/terminal/tui/tui-footer.js +330 -0
- package/dist/interfaces/ui/terminal/tui/types.d.ts +165 -0
- package/dist/interfaces/ui/terminal/tui/types.d.ts.map +1 -0
- package/dist/interfaces/ui/terminal/tui/types.js +5 -0
- package/dist/interfaces/ui/terminal/tui/useInputHandler.d.ts +23 -0
- package/dist/interfaces/ui/terminal/tui/useInputHandler.d.ts.map +1 -0
- package/dist/interfaces/ui/terminal/tui/useInputHandler.js +72 -0
- package/dist/interfaces/ui/terminal/tui/useNativeInput.d.ts +90 -0
- package/dist/interfaces/ui/terminal/tui/useNativeInput.d.ts.map +1 -0
- package/dist/interfaces/ui/terminal/tui/useNativeInput.js +188 -0
- package/dist/native/README.md +53 -0
- package/dist/native/claude_code_native.darwin-x64.node +0 -0
- package/dist/native/claude_code_native.dylib +0 -0
- package/dist/native/index.d.ts +0 -0
- package/dist/native/index.d.ts.map +1 -0
- package/dist/native/index.darwin-arm64.node +0 -0
- package/dist/native/index.js +43 -0
- package/dist/native/index.node +0 -0
- package/dist/native/package.json +34 -0
- package/dist/teammates/index.d.ts +161 -0
- package/dist/teammates/index.d.ts.map +1 -0
- package/dist/teammates/index.js +827 -0
- package/dist/types/index.d.ts +482 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +52 -0
- package/native/index.darwin-arm64.node +0 -0
- package/native/index.js +33 -19
- package/package.json +6 -3
- package/packages/src/core/__tests__/permissions.test.ts +1091 -0
- package/packages/src/core/agent-loop/__tests__/compaction.test.ts +283 -0
- package/packages/src/core/agent-loop/__tests__/formatters.test.ts +234 -0
- package/packages/src/core/agent-loop/__tests__/index.test.ts +162 -0
- package/packages/src/core/agent-loop/__tests__/loop-state.test.ts +413 -0
- package/packages/src/core/agent-loop/__tests__/message-builder.test.ts +229 -0
- package/packages/src/core/agent-loop/__tests__/tool-executor.test.ts +457 -0
- package/packages/src/core/agent-loop/compaction.ts +92 -0
- package/packages/src/core/agent-loop/formatters.ts +50 -0
- package/packages/src/core/agent-loop/index.ts +137 -0
- package/packages/src/core/agent-loop/loop-state.ts +187 -0
- package/packages/src/core/agent-loop/message-builder.ts +62 -0
- package/packages/src/core/agent-loop/tool-executor.ts +211 -0
- package/packages/src/core/agent-loop/turn-executor.ts +226 -0
- package/packages/src/core/agent-loop/types.ts +152 -0
- package/packages/src/core/agent-loop.ts +18 -0
- package/packages/src/core/api-client-impl.ts +729 -0
- package/packages/src/core/api-client.ts +6 -0
- package/packages/src/core/checkpoints.ts +606 -0
- package/packages/src/core/claude-md.ts +272 -0
- package/packages/src/core/cognitive-security/hooks.ts +591 -0
- package/packages/src/core/cognitive-security/index.ts +2041 -0
- package/packages/src/core/cognitive-security/middleware.ts +536 -0
- package/packages/src/core/config/todo +7 -0
- package/packages/src/core/config-loader.ts +324 -0
- package/packages/src/core/context/__tests__/integration.test.ts +334 -0
- package/packages/src/core/context/compaction.ts +170 -0
- package/packages/src/core/context/constants.ts +58 -0
- package/packages/src/core/context/extraction.ts +85 -0
- package/packages/src/core/context/index.ts +66 -0
- package/packages/src/core/context/summarization.ts +251 -0
- package/packages/src/core/context/token-estimation.ts +98 -0
- package/packages/src/core/context/types.ts +59 -0
- package/packages/src/core/git-status.ts +262 -0
- package/packages/src/core/image.test.ts +180 -0
- package/packages/src/core/image.ts +350 -0
- package/packages/src/core/lmdb.db +0 -0
- package/packages/src/core/lmdb.db-lock +0 -0
- package/packages/src/core/models.ts +507 -0
- package/packages/src/core/normalizers/todo +8 -0
- package/packages/src/core/permissions.ts +431 -0
- package/packages/src/core/providers/README.md +230 -0
- package/packages/src/core/providers/__tests__/providers.test.ts +135 -0
- package/packages/src/core/providers/index.ts +419 -0
- package/packages/src/core/providers/types.ts +132 -0
- package/packages/src/core/retry.ts +180 -0
- package/packages/src/core/session-store.ts +36 -0
- package/packages/src/core/sessions/export.ts +329 -0
- package/packages/src/core/sessions/index.ts +587 -0
- package/packages/src/core/sessions/metadata.ts +309 -0
- package/packages/src/core/sessions/persistence.ts +244 -0
- package/packages/src/core/sessions/types.ts +169 -0
- package/packages/src/core/stream-highlighter.ts +1123 -0
- package/packages/src/core/system-reminders.ts +402 -0
- package/packages/src/core/todo +8 -0
- package/packages/src/ecosystem/hooks/__tests__/index.test.ts +561 -0
- package/packages/src/ecosystem/hooks/index.ts +341 -0
- package/packages/src/ecosystem/hooks/prompt-evaluator.ts +300 -0
- package/packages/src/ecosystem/skills/index.ts +295 -0
- package/packages/src/ecosystem/tools/__tests__/index.test.ts +1335 -0
- package/packages/src/ecosystem/tools/index.ts +2051 -0
- package/packages/src/index.ts +141 -0
- package/packages/src/interfaces/mcp/client.ts +389 -0
- package/packages/src/interfaces/ui/index.ts +158 -0
- package/packages/src/interfaces/ui/lmdb.db +0 -0
- package/packages/src/interfaces/ui/lmdb.db-lock +0 -0
- package/packages/src/interfaces/ui/spinner.ts +451 -0
- package/packages/src/interfaces/ui/terminal/bridge/index.ts +370 -0
- package/packages/src/interfaces/ui/terminal/bridge/ipc.ts +829 -0
- package/packages/src/interfaces/ui/terminal/bridge/screen-export.ts +968 -0
- package/packages/src/interfaces/ui/terminal/bridge/types.ts +226 -0
- package/packages/src/interfaces/ui/terminal/bridge/useBridge.ts +210 -0
- package/packages/src/interfaces/ui/terminal/cli/bootstrap.ts +132 -0
- package/packages/src/interfaces/ui/terminal/cli/index.ts +415 -0
- package/packages/src/interfaces/ui/terminal/cli/interactive/index.ts +110 -0
- package/packages/src/interfaces/ui/terminal/cli/interactive/input-handler.ts +393 -0
- package/packages/src/interfaces/ui/terminal/cli/interactive/interactive-runner.ts +820 -0
- package/packages/src/interfaces/ui/terminal/cli/interactive/message-store.ts +299 -0
- package/packages/src/interfaces/ui/terminal/cli/interactive/types.ts +274 -0
- package/packages/src/interfaces/ui/terminal/lmdb.db +0 -0
- package/packages/src/interfaces/ui/terminal/lmdb.db-lock +0 -0
- package/packages/src/interfaces/ui/terminal/shared/args.ts +222 -0
- package/packages/src/interfaces/ui/terminal/shared/index.ts +84 -0
- package/packages/src/interfaces/ui/terminal/shared/loading-state.ts +322 -0
- package/packages/src/interfaces/ui/terminal/shared/query.ts +152 -0
- package/packages/src/interfaces/ui/terminal/shared/setup.ts +299 -0
- package/packages/src/interfaces/ui/terminal/shared/spinner-frames.ts +73 -0
- package/packages/src/interfaces/ui/terminal/shared/status-line.ts +366 -0
- package/packages/src/interfaces/ui/terminal/shared/system-prompt.ts +146 -0
- package/packages/src/lmdb.db +0 -0
- package/packages/src/lmdb.db-lock +0 -0
- package/packages/src/native/index.ts +2722 -0
- package/packages/src/native/tui_v2_types.ts +39 -0
- package/packages/src/teammates/coordination.test.ts +279 -0
- package/packages/src/teammates/coordination.ts +646 -0
- package/packages/src/teammates/index.ts +1052 -0
- package/packages/src/teammates/integration.test.ts +272 -0
- package/packages/src/teammates/runner.test.ts +235 -0
- package/packages/src/teammates/runner.ts +750 -0
- package/packages/src/teammates/schemas.ts +673 -0
- package/packages/src/types/index.ts +723 -0
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cognitive Security Hooks
|
|
3
|
+
*
|
|
4
|
+
* Automatic security checks integrated into the agent lifecycle.
|
|
5
|
+
* No manual calls needed - hooks intercept all operations.
|
|
6
|
+
*/
|
|
7
|
+
import type { HookInput, HookOutput } from "../../types/index.js";
|
|
8
|
+
import { type AgentIntent } from "./index.js";
|
|
9
|
+
/**
|
|
10
|
+
* Security configuration for hooks
|
|
11
|
+
*/
|
|
12
|
+
export interface SecurityHookConfig {
|
|
13
|
+
/** Enable all security checks */
|
|
14
|
+
enabled: boolean;
|
|
15
|
+
/** Check intent alignment before actions */
|
|
16
|
+
checkIntentAlignment: boolean;
|
|
17
|
+
/** Enforce flow policies */
|
|
18
|
+
enforceFlowPolicies: boolean;
|
|
19
|
+
/** Check for data leaks */
|
|
20
|
+
preventLeaks: boolean;
|
|
21
|
+
/** Track taint propagation */
|
|
22
|
+
trackTaints: boolean;
|
|
23
|
+
/** Log security events */
|
|
24
|
+
logEvents: boolean;
|
|
25
|
+
/** Block on violations (false = log only) */
|
|
26
|
+
blockOnViolation: boolean;
|
|
27
|
+
/** Minimum alignment score to allow (0-1) */
|
|
28
|
+
minAlignmentScore: number;
|
|
29
|
+
/** Sensitivities that require approval */
|
|
30
|
+
approvalRequiredSensitivities: string[];
|
|
31
|
+
/** Domains that require signed actions (every action cryptographically signed) */
|
|
32
|
+
requireSignedActions: string[];
|
|
33
|
+
/** Threshold for drift detection (0-1, higher = more strict) */
|
|
34
|
+
driftThreshold: number;
|
|
35
|
+
/** Enable immutable directives (cryptographically signed rules outside AI context) */
|
|
36
|
+
enableImmutableDirectives: boolean;
|
|
37
|
+
/** Require approval for operations above this sensitivity level */
|
|
38
|
+
approvalSensitivityLevel: string;
|
|
39
|
+
}
|
|
40
|
+
export declare const DEFAULT_SECURITY_CONFIG: SecurityHookConfig;
|
|
41
|
+
/**
|
|
42
|
+
* Security event for logging
|
|
43
|
+
*/
|
|
44
|
+
export interface SecurityEvent {
|
|
45
|
+
timestamp: number;
|
|
46
|
+
hook: string;
|
|
47
|
+
tool?: string;
|
|
48
|
+
action: "check" | "allow" | "deny" | "sanitize";
|
|
49
|
+
reason?: string;
|
|
50
|
+
sensitivity?: string;
|
|
51
|
+
category?: string;
|
|
52
|
+
alignmentScore?: number;
|
|
53
|
+
dataId?: string;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Cognitive Security Hook Handler
|
|
57
|
+
*
|
|
58
|
+
* Maintains state across hooks and provides security check methods.
|
|
59
|
+
*/
|
|
60
|
+
export declare class CognitiveSecurityHooks {
|
|
61
|
+
private config;
|
|
62
|
+
private intent;
|
|
63
|
+
private policyEngine;
|
|
64
|
+
private flowTracker;
|
|
65
|
+
private leakPrevention;
|
|
66
|
+
private taintTracker;
|
|
67
|
+
private events;
|
|
68
|
+
private initialized;
|
|
69
|
+
private sessionId;
|
|
70
|
+
constructor(config?: Partial<SecurityHookConfig>);
|
|
71
|
+
/**
|
|
72
|
+
* Initialize security components (called on SessionStart)
|
|
73
|
+
*/
|
|
74
|
+
private initialize;
|
|
75
|
+
/**
|
|
76
|
+
* Set the agent intent for alignment checking
|
|
77
|
+
*/
|
|
78
|
+
setIntent(intent: AgentIntent): void;
|
|
79
|
+
/**
|
|
80
|
+
* SessionStart hook - Initialize security and load intent
|
|
81
|
+
*/
|
|
82
|
+
onSessionStart(input: HookInput): Promise<HookOutput>;
|
|
83
|
+
/**
|
|
84
|
+
* PreToolUse hook - Check intent, classify action, enforce policies
|
|
85
|
+
*/
|
|
86
|
+
onPreToolUse(input: HookInput): Promise<HookOutput>;
|
|
87
|
+
/**
|
|
88
|
+
* PostToolUse hook - Check output for leaks, track flows
|
|
89
|
+
*/
|
|
90
|
+
onPostToolUse(input: HookInput): Promise<HookOutput>;
|
|
91
|
+
/**
|
|
92
|
+
* UserPromptSubmit hook - Check user input for injection attempts
|
|
93
|
+
*/
|
|
94
|
+
onUserPromptSubmit(input: HookInput): Promise<HookOutput>;
|
|
95
|
+
/**
|
|
96
|
+
* SessionEnd hook - Generate security report
|
|
97
|
+
*/
|
|
98
|
+
onSessionEnd(_input: HookInput): Promise<HookOutput>;
|
|
99
|
+
private inferActionType;
|
|
100
|
+
private inferDomain;
|
|
101
|
+
private isExternalTool;
|
|
102
|
+
private extractContent;
|
|
103
|
+
private log;
|
|
104
|
+
/**
|
|
105
|
+
* Get all security events
|
|
106
|
+
*/
|
|
107
|
+
getEvents(): SecurityEvent[];
|
|
108
|
+
/**
|
|
109
|
+
* Get security statistics
|
|
110
|
+
*/
|
|
111
|
+
getStats(): {
|
|
112
|
+
totalEvents: number;
|
|
113
|
+
allowedCount: number;
|
|
114
|
+
deniedCount: number;
|
|
115
|
+
sanitizedCount: number;
|
|
116
|
+
bySensitivity: Record<string, number>;
|
|
117
|
+
avgAlignmentScore: number;
|
|
118
|
+
};
|
|
119
|
+
/**
|
|
120
|
+
* Clear event history
|
|
121
|
+
*/
|
|
122
|
+
clearEvents(): void;
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Get global security hooks instance
|
|
126
|
+
*/
|
|
127
|
+
export declare function getSecurityHooks(config?: Partial<SecurityHookConfig>): CognitiveSecurityHooks;
|
|
128
|
+
/**
|
|
129
|
+
* Create hook handlers for HookManager
|
|
130
|
+
*/
|
|
131
|
+
export declare function createSecurityHookHandlers(config?: Partial<SecurityHookConfig>): {
|
|
132
|
+
SessionStart: (input: HookInput) => Promise<HookOutput>;
|
|
133
|
+
PreToolUse: (input: HookInput) => Promise<HookOutput>;
|
|
134
|
+
PostToolUse: (input: HookInput) => Promise<HookOutput>;
|
|
135
|
+
UserPromptSubmit: (input: HookInput) => Promise<HookOutput>;
|
|
136
|
+
SessionEnd: (input: HookInput) => Promise<HookOutput>;
|
|
137
|
+
};
|
|
138
|
+
//# sourceMappingURL=hooks.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hooks.d.ts","sourceRoot":"","sources":["../../../packages/src/core/cognitive-security/hooks.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,389 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cognitive Security Hooks
|
|
3
|
+
*
|
|
4
|
+
* Automatic security checks integrated into the agent lifecycle.
|
|
5
|
+
* No manual calls needed - hooks intercept all operations.
|
|
6
|
+
*/
|
|
7
|
+
import { classifyData, classifyOperation, scoreAlignment, createFlowPolicyEngine, createFlowTracker, createLeakPrevention, createTaintTracker, } from "./index.js";
|
|
8
|
+
export const DEFAULT_SECURITY_CONFIG = {
|
|
9
|
+
enabled: true,
|
|
10
|
+
checkIntentAlignment: true,
|
|
11
|
+
enforceFlowPolicies: true,
|
|
12
|
+
preventLeaks: true,
|
|
13
|
+
trackTaints: true,
|
|
14
|
+
logEvents: true,
|
|
15
|
+
blockOnViolation: true,
|
|
16
|
+
minAlignmentScore: 0.5,
|
|
17
|
+
approvalRequiredSensitivities: ["secret", "top_secret"],
|
|
18
|
+
// Domains requiring cryptographic action signing
|
|
19
|
+
requireSignedActions: ["financial", "external", "credentials"],
|
|
20
|
+
// Drift detection threshold - flag when behavior deviates > 30%
|
|
21
|
+
driftThreshold: 0.3,
|
|
22
|
+
// Enable immutable directives from secure storage
|
|
23
|
+
enableImmutableDirectives: true,
|
|
24
|
+
// Sensitivity level requiring explicit user approval
|
|
25
|
+
approvalSensitivityLevel: "confidential",
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* Cognitive Security Hook Handler
|
|
29
|
+
*
|
|
30
|
+
* Maintains state across hooks and provides security check methods.
|
|
31
|
+
*/
|
|
32
|
+
export class CognitiveSecurityHooks {
|
|
33
|
+
config;
|
|
34
|
+
intent = null;
|
|
35
|
+
policyEngine = null;
|
|
36
|
+
flowTracker = null;
|
|
37
|
+
leakPrevention = null;
|
|
38
|
+
taintTracker = null;
|
|
39
|
+
events = [];
|
|
40
|
+
initialized = false;
|
|
41
|
+
sessionId = null;
|
|
42
|
+
constructor(config = {}) {
|
|
43
|
+
this.config = { ...DEFAULT_SECURITY_CONFIG, ...config };
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Initialize security components (called on SessionStart)
|
|
47
|
+
*/
|
|
48
|
+
async initialize() {
|
|
49
|
+
if (this.initialized)
|
|
50
|
+
return;
|
|
51
|
+
try {
|
|
52
|
+
if (this.config.enforceFlowPolicies) {
|
|
53
|
+
this.policyEngine = await createFlowPolicyEngine();
|
|
54
|
+
}
|
|
55
|
+
if (this.config.trackTaints) {
|
|
56
|
+
this.flowTracker = await createFlowTracker();
|
|
57
|
+
this.taintTracker = await createTaintTracker();
|
|
58
|
+
}
|
|
59
|
+
if (this.config.preventLeaks) {
|
|
60
|
+
this.leakPrevention = await createLeakPrevention();
|
|
61
|
+
}
|
|
62
|
+
this.initialized = true;
|
|
63
|
+
this.log("SessionStart", undefined, "check", "Security hooks initialized");
|
|
64
|
+
}
|
|
65
|
+
catch (error) {
|
|
66
|
+
this.log("SessionStart", undefined, "check", `Init failed: ${error}`);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Set the agent intent for alignment checking
|
|
71
|
+
*/
|
|
72
|
+
setIntent(intent) {
|
|
73
|
+
this.intent = intent;
|
|
74
|
+
this.log("SessionStart", undefined, "check", `Intent loaded: ${intent.identity.name}`);
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* SessionStart hook - Initialize security and load intent
|
|
78
|
+
*/
|
|
79
|
+
async onSessionStart(input) {
|
|
80
|
+
await this.initialize();
|
|
81
|
+
this.sessionId = input.session_id || null;
|
|
82
|
+
// Intent should be set externally before session starts
|
|
83
|
+
// This is just initialization
|
|
84
|
+
return { decision: "allow" };
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* PreToolUse hook - Check intent, classify action, enforce policies
|
|
88
|
+
*/
|
|
89
|
+
async onPreToolUse(input) {
|
|
90
|
+
if (!this.config.enabled) {
|
|
91
|
+
return { decision: "allow" };
|
|
92
|
+
}
|
|
93
|
+
await this.initialize();
|
|
94
|
+
const toolName = input.tool_name || "unknown";
|
|
95
|
+
const toolInput = input.tool_input || {};
|
|
96
|
+
// 1. Classify the operation
|
|
97
|
+
const actionContext = {
|
|
98
|
+
actionType: this.inferActionType(toolName),
|
|
99
|
+
domain: this.inferDomain(toolName),
|
|
100
|
+
operation: toolName,
|
|
101
|
+
target: typeof toolInput.file_path === "string" ? toolInput.file_path : undefined,
|
|
102
|
+
params: toolInput,
|
|
103
|
+
reasoning: `Tool: ${toolName}`,
|
|
104
|
+
};
|
|
105
|
+
try {
|
|
106
|
+
const classifiedAction = await classifyOperation(toolName, actionContext.domain, actionContext.target, actionContext.reasoning);
|
|
107
|
+
// 2. Check intent alignment
|
|
108
|
+
if (this.config.checkIntentAlignment && this.intent) {
|
|
109
|
+
const alignment = await scoreAlignment(actionContext, this.intent);
|
|
110
|
+
this.log("PreToolUse", toolName, "check", `Alignment: ${alignment.score.toFixed(2)}`, undefined, undefined, alignment.score);
|
|
111
|
+
if (alignment.shouldBlock || alignment.score < this.config.minAlignmentScore) {
|
|
112
|
+
const reason = alignment.boundaryConcerns.length > 0
|
|
113
|
+
? `Boundary concerns: ${alignment.boundaryConcerns.join(", ")}`
|
|
114
|
+
: `Low alignment score: ${alignment.score.toFixed(2)}`;
|
|
115
|
+
this.log("PreToolUse", toolName, "deny", reason);
|
|
116
|
+
if (this.config.blockOnViolation) {
|
|
117
|
+
return {
|
|
118
|
+
decision: "deny",
|
|
119
|
+
reason: `[Security] ${reason}`,
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
// 3. Check flow policy
|
|
125
|
+
if (this.config.enforceFlowPolicies && this.policyEngine) {
|
|
126
|
+
// Extract content for classification
|
|
127
|
+
const content = this.extractContent(toolInput);
|
|
128
|
+
const classified = await classifyData(content, actionContext.domain, [toolName]);
|
|
129
|
+
this.log("PreToolUse", toolName, "check", `Classified: ${classified.sensitivity}/${classified.category}`, classified.sensitivity, classified.category);
|
|
130
|
+
// Determine target domain
|
|
131
|
+
const targetDomain = this.isExternalTool(toolName) ? "external" : "internal";
|
|
132
|
+
const flowResult = this.policyEngine.evaluate(classified, actionContext.domain, targetDomain);
|
|
133
|
+
if (!flowResult.allowed) {
|
|
134
|
+
this.log("PreToolUse", toolName, "deny", flowResult.reason);
|
|
135
|
+
if (this.config.blockOnViolation) {
|
|
136
|
+
return {
|
|
137
|
+
decision: "deny",
|
|
138
|
+
reason: `[Security] Flow policy violation: ${flowResult.reason}`,
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
// Check if approval required
|
|
143
|
+
if (flowResult.requireApproval ||
|
|
144
|
+
this.config.approvalRequiredSensitivities.includes(classified.sensitivity)) {
|
|
145
|
+
// For now, just log - in full implementation would prompt user
|
|
146
|
+
this.log("PreToolUse", toolName, "check", "Approval recommended");
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
this.log("PreToolUse", toolName, "allow", "Checks passed");
|
|
150
|
+
return { decision: "allow" };
|
|
151
|
+
}
|
|
152
|
+
catch (error) {
|
|
153
|
+
const msg = error instanceof Error ? error.message : String(error);
|
|
154
|
+
this.log("PreToolUse", toolName, "check", `Error: ${msg}`);
|
|
155
|
+
// On error, allow but log
|
|
156
|
+
return { decision: "allow" };
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* PostToolUse hook - Check output for leaks, track flows
|
|
161
|
+
*/
|
|
162
|
+
async onPostToolUse(input) {
|
|
163
|
+
if (!this.config.enabled) {
|
|
164
|
+
return { decision: "allow" };
|
|
165
|
+
}
|
|
166
|
+
await this.initialize();
|
|
167
|
+
const toolName = input.tool_name || "unknown";
|
|
168
|
+
const toolResult = input.tool_result || "";
|
|
169
|
+
const toolIsError = input.tool_result_is_error || false;
|
|
170
|
+
// Skip error results
|
|
171
|
+
if (toolIsError) {
|
|
172
|
+
return { decision: "allow" };
|
|
173
|
+
}
|
|
174
|
+
try {
|
|
175
|
+
// 1. Classify output
|
|
176
|
+
const content = typeof toolResult === "string" ? toolResult : JSON.stringify(toolResult);
|
|
177
|
+
const classified = await classifyData(content, "agent", [toolName, "output"]);
|
|
178
|
+
this.log("PostToolUse", toolName, "check", `Output: ${classified.sensitivity}/${classified.category}`, classified.sensitivity, classified.category);
|
|
179
|
+
// 2. Check for leaks
|
|
180
|
+
if (this.config.preventLeaks && this.leakPrevention) {
|
|
181
|
+
const channel = this.isExternalTool(toolName) ? "external" : "internal";
|
|
182
|
+
const leakCheck = this.leakPrevention.check(content, channel);
|
|
183
|
+
if (leakCheck.action === "block") {
|
|
184
|
+
const patterns = leakCheck.detections.map(d => d.pattern_name).join(", ");
|
|
185
|
+
this.log("PostToolUse", toolName, "sanitize", `Leaks detected: ${patterns}`);
|
|
186
|
+
if (this.config.blockOnViolation) {
|
|
187
|
+
// Sanitize the output
|
|
188
|
+
const sanitized = this.leakPrevention.sanitize(content);
|
|
189
|
+
this.log("PostToolUse", toolName, "sanitize", "Output sanitized");
|
|
190
|
+
return {
|
|
191
|
+
decision: "allow",
|
|
192
|
+
modified_input: {
|
|
193
|
+
tool_result: sanitized,
|
|
194
|
+
},
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
// 3. Track flow
|
|
200
|
+
if (this.config.trackTaints && this.flowTracker && this.policyEngine) {
|
|
201
|
+
const sourceDomain = "agent";
|
|
202
|
+
const targetDomain = this.isExternalTool(toolName) ? "external" : "internal";
|
|
203
|
+
const flowResult = this.policyEngine.evaluate(classified, sourceDomain, targetDomain);
|
|
204
|
+
this.flowTracker.record(classified, sourceDomain, targetDomain, this.isExternalTool(toolName) ? "outbound" : "internal", flowResult, this.sessionId, null);
|
|
205
|
+
this.log("PostToolUse", toolName, "check", "Flow tracked");
|
|
206
|
+
}
|
|
207
|
+
this.log("PostToolUse", toolName, "allow", "Output checks passed");
|
|
208
|
+
return { decision: "allow" };
|
|
209
|
+
}
|
|
210
|
+
catch (error) {
|
|
211
|
+
const msg = error instanceof Error ? error.message : String(error);
|
|
212
|
+
this.log("PostToolUse", toolName, "check", `Error: ${msg}`);
|
|
213
|
+
return { decision: "allow" };
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* UserPromptSubmit hook - Check user input for injection attempts
|
|
218
|
+
*/
|
|
219
|
+
async onUserPromptSubmit(input) {
|
|
220
|
+
if (!this.config.enabled) {
|
|
221
|
+
return { decision: "allow" };
|
|
222
|
+
}
|
|
223
|
+
const prompt = input.prompt || "";
|
|
224
|
+
await this.initialize();
|
|
225
|
+
try {
|
|
226
|
+
// Check for potential injection patterns
|
|
227
|
+
const suspiciousPatterns = [
|
|
228
|
+
/ignore (all )?(previous|above) instructions/i,
|
|
229
|
+
/you are now/i,
|
|
230
|
+
/disregard (all )?(rules|policies)/i,
|
|
231
|
+
/system:? prompt/i,
|
|
232
|
+
/\[system\]/i,
|
|
233
|
+
/<\|.*?\|>/,
|
|
234
|
+
];
|
|
235
|
+
for (const pattern of suspiciousPatterns) {
|
|
236
|
+
if (pattern.test(prompt)) {
|
|
237
|
+
this.log("UserPromptSubmit", undefined, "check", "Suspicious pattern detected");
|
|
238
|
+
if (this.config.blockOnViolation) {
|
|
239
|
+
return {
|
|
240
|
+
decision: "deny",
|
|
241
|
+
reason: "[Security] Prompt contains potentially unsafe patterns",
|
|
242
|
+
};
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
// Classify user input
|
|
247
|
+
const classified = await classifyData(prompt, "user_input", []);
|
|
248
|
+
this.log("UserPromptSubmit", undefined, "check", `Input: ${classified.sensitivity}`, classified.sensitivity);
|
|
249
|
+
return { decision: "allow" };
|
|
250
|
+
}
|
|
251
|
+
catch (error) {
|
|
252
|
+
return { decision: "allow" };
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
/**
|
|
256
|
+
* SessionEnd hook - Generate security report
|
|
257
|
+
*/
|
|
258
|
+
async onSessionEnd(_input) {
|
|
259
|
+
const stats = this.getStats();
|
|
260
|
+
this.log("SessionEnd", undefined, "check", `Session ended - ${stats.totalEvents} events, ${stats.deniedCount} denied`);
|
|
261
|
+
return { decision: "allow" };
|
|
262
|
+
}
|
|
263
|
+
// ============================================
|
|
264
|
+
// Utility Methods
|
|
265
|
+
// ============================================
|
|
266
|
+
inferActionType(toolName) {
|
|
267
|
+
const typeMap = {
|
|
268
|
+
Read: "observe",
|
|
269
|
+
Glob: "observe",
|
|
270
|
+
Grep: "observe",
|
|
271
|
+
Write: "modify",
|
|
272
|
+
Edit: "modify",
|
|
273
|
+
MultiEdit: "modify",
|
|
274
|
+
Bash: "execute",
|
|
275
|
+
NotebookEdit: "modify",
|
|
276
|
+
};
|
|
277
|
+
return typeMap[toolName] || "observe";
|
|
278
|
+
}
|
|
279
|
+
inferDomain(toolName) {
|
|
280
|
+
const domainMap = {
|
|
281
|
+
Read: "filesystem",
|
|
282
|
+
Write: "filesystem",
|
|
283
|
+
Edit: "filesystem",
|
|
284
|
+
Glob: "filesystem",
|
|
285
|
+
Grep: "filesystem",
|
|
286
|
+
Bash: "shell",
|
|
287
|
+
MultiEdit: "filesystem",
|
|
288
|
+
};
|
|
289
|
+
return domainMap[toolName] || "agent";
|
|
290
|
+
}
|
|
291
|
+
isExternalTool(toolName) {
|
|
292
|
+
const externalTools = ["Bash", "Write", "Edit", "MultiEdit", "NotebookEdit"];
|
|
293
|
+
return externalTools.includes(toolName);
|
|
294
|
+
}
|
|
295
|
+
extractContent(input) {
|
|
296
|
+
const parts = [];
|
|
297
|
+
for (const [key, value] of Object.entries(input)) {
|
|
298
|
+
if (typeof value === "string") {
|
|
299
|
+
parts.push(value);
|
|
300
|
+
}
|
|
301
|
+
else if (typeof value === "object" && value !== null) {
|
|
302
|
+
parts.push(JSON.stringify(value));
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
return parts.join(" ");
|
|
306
|
+
}
|
|
307
|
+
log(hook, tool, action, reason, sensitivity, category, alignmentScore) {
|
|
308
|
+
const event = {
|
|
309
|
+
timestamp: Date.now(),
|
|
310
|
+
hook,
|
|
311
|
+
tool,
|
|
312
|
+
action,
|
|
313
|
+
reason,
|
|
314
|
+
sensitivity,
|
|
315
|
+
category,
|
|
316
|
+
alignmentScore,
|
|
317
|
+
};
|
|
318
|
+
this.events.push(event);
|
|
319
|
+
if (this.config.logEvents) {
|
|
320
|
+
const prefix = action === "deny" ? "\x1b[31m[Security]\x1b[0m" : "\x1b[90m[Security]\x1b[0m";
|
|
321
|
+
const toolStr = tool ? ` ${tool}:` : "";
|
|
322
|
+
console.log(`${prefix}${toolStr} ${reason}`);
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
/**
|
|
326
|
+
* Get all security events
|
|
327
|
+
*/
|
|
328
|
+
getEvents() {
|
|
329
|
+
return [...this.events];
|
|
330
|
+
}
|
|
331
|
+
/**
|
|
332
|
+
* Get security statistics
|
|
333
|
+
*/
|
|
334
|
+
getStats() {
|
|
335
|
+
const allowedCount = this.events.filter(e => e.action === "allow").length;
|
|
336
|
+
const deniedCount = this.events.filter(e => e.action === "deny").length;
|
|
337
|
+
const sanitizedCount = this.events.filter(e => e.action === "sanitize").length;
|
|
338
|
+
const bySensitivity = {};
|
|
339
|
+
for (const event of this.events) {
|
|
340
|
+
if (event.sensitivity) {
|
|
341
|
+
bySensitivity[event.sensitivity] = (bySensitivity[event.sensitivity] || 0) + 1;
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
const alignmentScores = this.events
|
|
345
|
+
.filter(e => e.alignmentScore !== undefined)
|
|
346
|
+
.map(e => e.alignmentScore);
|
|
347
|
+
const avgAlignmentScore = alignmentScores.length > 0
|
|
348
|
+
? alignmentScores.reduce((a, b) => a + b, 0) / alignmentScores.length
|
|
349
|
+
: 0;
|
|
350
|
+
return {
|
|
351
|
+
totalEvents: this.events.length,
|
|
352
|
+
allowedCount,
|
|
353
|
+
deniedCount,
|
|
354
|
+
sanitizedCount,
|
|
355
|
+
bySensitivity,
|
|
356
|
+
avgAlignmentScore,
|
|
357
|
+
};
|
|
358
|
+
}
|
|
359
|
+
/**
|
|
360
|
+
* Clear event history
|
|
361
|
+
*/
|
|
362
|
+
clearEvents() {
|
|
363
|
+
this.events = [];
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
// Singleton instance
|
|
367
|
+
let globalHooks = null;
|
|
368
|
+
/**
|
|
369
|
+
* Get global security hooks instance
|
|
370
|
+
*/
|
|
371
|
+
export function getSecurityHooks(config) {
|
|
372
|
+
if (!globalHooks) {
|
|
373
|
+
globalHooks = new CognitiveSecurityHooks(config);
|
|
374
|
+
}
|
|
375
|
+
return globalHooks;
|
|
376
|
+
}
|
|
377
|
+
/**
|
|
378
|
+
* Create hook handlers for HookManager
|
|
379
|
+
*/
|
|
380
|
+
export function createSecurityHookHandlers(config) {
|
|
381
|
+
const hooks = new CognitiveSecurityHooks(config);
|
|
382
|
+
return {
|
|
383
|
+
SessionStart: (input) => hooks.onSessionStart(input),
|
|
384
|
+
PreToolUse: (input) => hooks.onPreToolUse(input),
|
|
385
|
+
PostToolUse: (input) => hooks.onPostToolUse(input),
|
|
386
|
+
UserPromptSubmit: (input) => hooks.onUserPromptSubmit(input),
|
|
387
|
+
SessionEnd: (input) => hooks.onSessionEnd(input),
|
|
388
|
+
};
|
|
389
|
+
}
|