@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,591 @@
|
|
|
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
|
+
|
|
8
|
+
import type { HookInput, HookOutput } from "../../types/index.js";
|
|
9
|
+
import {
|
|
10
|
+
classifyData,
|
|
11
|
+
classifyOperation,
|
|
12
|
+
scoreAlignment,
|
|
13
|
+
createFlowPolicyEngine,
|
|
14
|
+
createFlowTracker,
|
|
15
|
+
createLeakPrevention,
|
|
16
|
+
createTaintTracker,
|
|
17
|
+
type FlowPolicyEngineHandle,
|
|
18
|
+
type FlowTrackerHandle,
|
|
19
|
+
type LeakPreventionHandle,
|
|
20
|
+
type TaintTrackerHandle,
|
|
21
|
+
type AgentIntent,
|
|
22
|
+
type ActionContext,
|
|
23
|
+
} from "./index.js";
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Security configuration for hooks
|
|
27
|
+
*/
|
|
28
|
+
export interface SecurityHookConfig {
|
|
29
|
+
/** Enable all security checks */
|
|
30
|
+
enabled: boolean;
|
|
31
|
+
|
|
32
|
+
/** Check intent alignment before actions */
|
|
33
|
+
checkIntentAlignment: boolean;
|
|
34
|
+
|
|
35
|
+
/** Enforce flow policies */
|
|
36
|
+
enforceFlowPolicies: boolean;
|
|
37
|
+
|
|
38
|
+
/** Check for data leaks */
|
|
39
|
+
preventLeaks: boolean;
|
|
40
|
+
|
|
41
|
+
/** Track taint propagation */
|
|
42
|
+
trackTaints: boolean;
|
|
43
|
+
|
|
44
|
+
/** Log security events */
|
|
45
|
+
logEvents: boolean;
|
|
46
|
+
|
|
47
|
+
/** Block on violations (false = log only) */
|
|
48
|
+
blockOnViolation: boolean;
|
|
49
|
+
|
|
50
|
+
/** Minimum alignment score to allow (0-1) */
|
|
51
|
+
minAlignmentScore: number;
|
|
52
|
+
|
|
53
|
+
/** Sensitivities that require approval */
|
|
54
|
+
approvalRequiredSensitivities: string[];
|
|
55
|
+
|
|
56
|
+
/** Domains that require signed actions (every action cryptographically signed) */
|
|
57
|
+
requireSignedActions: string[];
|
|
58
|
+
|
|
59
|
+
/** Threshold for drift detection (0-1, higher = more strict) */
|
|
60
|
+
driftThreshold: number;
|
|
61
|
+
|
|
62
|
+
/** Enable immutable directives (cryptographically signed rules outside AI context) */
|
|
63
|
+
enableImmutableDirectives: boolean;
|
|
64
|
+
|
|
65
|
+
/** Require approval for operations above this sensitivity level */
|
|
66
|
+
approvalSensitivityLevel: string;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export const DEFAULT_SECURITY_CONFIG: SecurityHookConfig = {
|
|
70
|
+
enabled: true,
|
|
71
|
+
checkIntentAlignment: true,
|
|
72
|
+
enforceFlowPolicies: true,
|
|
73
|
+
preventLeaks: true,
|
|
74
|
+
trackTaints: true,
|
|
75
|
+
logEvents: true,
|
|
76
|
+
blockOnViolation: true,
|
|
77
|
+
minAlignmentScore: 0.5,
|
|
78
|
+
approvalRequiredSensitivities: ["secret", "top_secret"],
|
|
79
|
+
// Domains requiring cryptographic action signing
|
|
80
|
+
requireSignedActions: ["financial", "external", "credentials"],
|
|
81
|
+
// Drift detection threshold - flag when behavior deviates > 30%
|
|
82
|
+
driftThreshold: 0.3,
|
|
83
|
+
// Enable immutable directives from secure storage
|
|
84
|
+
enableImmutableDirectives: true,
|
|
85
|
+
// Sensitivity level requiring explicit user approval
|
|
86
|
+
approvalSensitivityLevel: "confidential",
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Security event for logging
|
|
91
|
+
*/
|
|
92
|
+
export interface SecurityEvent {
|
|
93
|
+
timestamp: number;
|
|
94
|
+
hook: string;
|
|
95
|
+
tool?: string;
|
|
96
|
+
action: "check" | "allow" | "deny" | "sanitize";
|
|
97
|
+
reason?: string;
|
|
98
|
+
sensitivity?: string;
|
|
99
|
+
category?: string;
|
|
100
|
+
alignmentScore?: number;
|
|
101
|
+
dataId?: string;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Cognitive Security Hook Handler
|
|
106
|
+
*
|
|
107
|
+
* Maintains state across hooks and provides security check methods.
|
|
108
|
+
*/
|
|
109
|
+
export class CognitiveSecurityHooks {
|
|
110
|
+
private config: SecurityHookConfig;
|
|
111
|
+
private intent: AgentIntent | null = null;
|
|
112
|
+
private policyEngine: FlowPolicyEngineHandle | null = null;
|
|
113
|
+
private flowTracker: FlowTrackerHandle | null = null;
|
|
114
|
+
private leakPrevention: LeakPreventionHandle | null = null;
|
|
115
|
+
private taintTracker: TaintTrackerHandle | null = null;
|
|
116
|
+
private events: SecurityEvent[] = [];
|
|
117
|
+
private initialized = false;
|
|
118
|
+
private sessionId: string | null = null;
|
|
119
|
+
|
|
120
|
+
constructor(config: Partial<SecurityHookConfig> = {}) {
|
|
121
|
+
this.config = { ...DEFAULT_SECURITY_CONFIG, ...config };
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Initialize security components (called on SessionStart)
|
|
126
|
+
*/
|
|
127
|
+
private async initialize(): Promise<void> {
|
|
128
|
+
if (this.initialized) return;
|
|
129
|
+
|
|
130
|
+
try {
|
|
131
|
+
if (this.config.enforceFlowPolicies) {
|
|
132
|
+
this.policyEngine = await createFlowPolicyEngine();
|
|
133
|
+
}
|
|
134
|
+
if (this.config.trackTaints) {
|
|
135
|
+
this.flowTracker = await createFlowTracker();
|
|
136
|
+
this.taintTracker = await createTaintTracker();
|
|
137
|
+
}
|
|
138
|
+
if (this.config.preventLeaks) {
|
|
139
|
+
this.leakPrevention = await createLeakPrevention();
|
|
140
|
+
}
|
|
141
|
+
this.initialized = true;
|
|
142
|
+
this.log("SessionStart", undefined, "check", "Security hooks initialized");
|
|
143
|
+
} catch (error) {
|
|
144
|
+
this.log("SessionStart", undefined, "check", `Init failed: ${error}`);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* Set the agent intent for alignment checking
|
|
150
|
+
*/
|
|
151
|
+
setIntent(intent: AgentIntent): void {
|
|
152
|
+
this.intent = intent;
|
|
153
|
+
this.log("SessionStart", undefined, "check", `Intent loaded: ${intent.identity.name}`);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* SessionStart hook - Initialize security and load intent
|
|
158
|
+
*/
|
|
159
|
+
async onSessionStart(input: HookInput): Promise<HookOutput> {
|
|
160
|
+
await this.initialize();
|
|
161
|
+
this.sessionId = input.session_id || null;
|
|
162
|
+
|
|
163
|
+
// Intent should be set externally before session starts
|
|
164
|
+
// This is just initialization
|
|
165
|
+
|
|
166
|
+
return { decision: "allow" };
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* PreToolUse hook - Check intent, classify action, enforce policies
|
|
171
|
+
*/
|
|
172
|
+
async onPreToolUse(input: HookInput): Promise<HookOutput> {
|
|
173
|
+
if (!this.config.enabled) {
|
|
174
|
+
return { decision: "allow" };
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
await this.initialize();
|
|
178
|
+
const toolName = input.tool_name || "unknown";
|
|
179
|
+
const toolInput = input.tool_input || {};
|
|
180
|
+
|
|
181
|
+
// 1. Classify the operation
|
|
182
|
+
const actionContext: ActionContext = {
|
|
183
|
+
actionType: this.inferActionType(toolName),
|
|
184
|
+
domain: this.inferDomain(toolName),
|
|
185
|
+
operation: toolName,
|
|
186
|
+
target: typeof toolInput.file_path === "string" ? toolInput.file_path : undefined,
|
|
187
|
+
params: toolInput,
|
|
188
|
+
reasoning: `Tool: ${toolName}`,
|
|
189
|
+
};
|
|
190
|
+
|
|
191
|
+
try {
|
|
192
|
+
const classifiedAction = await classifyOperation(
|
|
193
|
+
toolName,
|
|
194
|
+
actionContext.domain,
|
|
195
|
+
actionContext.target,
|
|
196
|
+
actionContext.reasoning
|
|
197
|
+
);
|
|
198
|
+
|
|
199
|
+
// 2. Check intent alignment
|
|
200
|
+
if (this.config.checkIntentAlignment && this.intent) {
|
|
201
|
+
const alignment = await scoreAlignment(actionContext, this.intent);
|
|
202
|
+
|
|
203
|
+
this.log("PreToolUse", toolName, "check",
|
|
204
|
+
`Alignment: ${alignment.score.toFixed(2)}`,
|
|
205
|
+
undefined, undefined, alignment.score
|
|
206
|
+
);
|
|
207
|
+
|
|
208
|
+
if (alignment.shouldBlock || alignment.score < this.config.minAlignmentScore) {
|
|
209
|
+
const reason = alignment.boundaryConcerns.length > 0
|
|
210
|
+
? `Boundary concerns: ${alignment.boundaryConcerns.join(", ")}`
|
|
211
|
+
: `Low alignment score: ${alignment.score.toFixed(2)}`;
|
|
212
|
+
|
|
213
|
+
this.log("PreToolUse", toolName, "deny", reason);
|
|
214
|
+
|
|
215
|
+
if (this.config.blockOnViolation) {
|
|
216
|
+
return {
|
|
217
|
+
decision: "deny",
|
|
218
|
+
reason: `[Security] ${reason}`,
|
|
219
|
+
};
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
// 3. Check flow policy
|
|
225
|
+
if (this.config.enforceFlowPolicies && this.policyEngine) {
|
|
226
|
+
// Extract content for classification
|
|
227
|
+
const content = this.extractContent(toolInput);
|
|
228
|
+
const classified = await classifyData(content, actionContext.domain, [toolName]);
|
|
229
|
+
|
|
230
|
+
this.log("PreToolUse", toolName, "check",
|
|
231
|
+
`Classified: ${classified.sensitivity}/${classified.category}`,
|
|
232
|
+
classified.sensitivity, classified.category
|
|
233
|
+
);
|
|
234
|
+
|
|
235
|
+
// Determine target domain
|
|
236
|
+
const targetDomain = this.isExternalTool(toolName) ? "external" : "internal";
|
|
237
|
+
|
|
238
|
+
const flowResult = this.policyEngine.evaluate(
|
|
239
|
+
classified,
|
|
240
|
+
actionContext.domain,
|
|
241
|
+
targetDomain
|
|
242
|
+
);
|
|
243
|
+
|
|
244
|
+
if (!flowResult.allowed) {
|
|
245
|
+
this.log("PreToolUse", toolName, "deny", flowResult.reason);
|
|
246
|
+
|
|
247
|
+
if (this.config.blockOnViolation) {
|
|
248
|
+
return {
|
|
249
|
+
decision: "deny",
|
|
250
|
+
reason: `[Security] Flow policy violation: ${flowResult.reason}`,
|
|
251
|
+
};
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
// Check if approval required
|
|
256
|
+
if (flowResult.requireApproval ||
|
|
257
|
+
this.config.approvalRequiredSensitivities.includes(classified.sensitivity)) {
|
|
258
|
+
// For now, just log - in full implementation would prompt user
|
|
259
|
+
this.log("PreToolUse", toolName, "check", "Approval recommended");
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
this.log("PreToolUse", toolName, "allow", "Checks passed");
|
|
264
|
+
return { decision: "allow" };
|
|
265
|
+
|
|
266
|
+
} catch (error) {
|
|
267
|
+
const msg = error instanceof Error ? error.message : String(error);
|
|
268
|
+
this.log("PreToolUse", toolName, "check", `Error: ${msg}`);
|
|
269
|
+
// On error, allow but log
|
|
270
|
+
return { decision: "allow" };
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
/**
|
|
275
|
+
* PostToolUse hook - Check output for leaks, track flows
|
|
276
|
+
*/
|
|
277
|
+
async onPostToolUse(input: HookInput): Promise<HookOutput> {
|
|
278
|
+
if (!this.config.enabled) {
|
|
279
|
+
return { decision: "allow" };
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
await this.initialize();
|
|
283
|
+
const toolName = input.tool_name || "unknown";
|
|
284
|
+
const toolResult = input.tool_result || "";
|
|
285
|
+
const toolIsError = input.tool_result_is_error || false;
|
|
286
|
+
|
|
287
|
+
// Skip error results
|
|
288
|
+
if (toolIsError) {
|
|
289
|
+
return { decision: "allow" };
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
try {
|
|
293
|
+
// 1. Classify output
|
|
294
|
+
const content = typeof toolResult === "string" ? toolResult : JSON.stringify(toolResult);
|
|
295
|
+
const classified = await classifyData(content, "agent", [toolName, "output"]);
|
|
296
|
+
|
|
297
|
+
this.log("PostToolUse", toolName, "check",
|
|
298
|
+
`Output: ${classified.sensitivity}/${classified.category}`,
|
|
299
|
+
classified.sensitivity, classified.category
|
|
300
|
+
);
|
|
301
|
+
|
|
302
|
+
// 2. Check for leaks
|
|
303
|
+
if (this.config.preventLeaks && this.leakPrevention) {
|
|
304
|
+
const channel = this.isExternalTool(toolName) ? "external" : "internal";
|
|
305
|
+
const leakCheck = this.leakPrevention.check(content, channel);
|
|
306
|
+
|
|
307
|
+
if (leakCheck.action === "block") {
|
|
308
|
+
const patterns = leakCheck.detections.map(d => d.pattern_name).join(", ");
|
|
309
|
+
this.log("PostToolUse", toolName, "sanitize", `Leaks detected: ${patterns}`);
|
|
310
|
+
|
|
311
|
+
if (this.config.blockOnViolation) {
|
|
312
|
+
// Sanitize the output
|
|
313
|
+
const sanitized = this.leakPrevention.sanitize(content);
|
|
314
|
+
this.log("PostToolUse", toolName, "sanitize", "Output sanitized");
|
|
315
|
+
|
|
316
|
+
return {
|
|
317
|
+
decision: "allow",
|
|
318
|
+
modified_input: {
|
|
319
|
+
tool_result: sanitized,
|
|
320
|
+
},
|
|
321
|
+
};
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
// 3. Track flow
|
|
327
|
+
if (this.config.trackTaints && this.flowTracker && this.policyEngine) {
|
|
328
|
+
const sourceDomain = "agent";
|
|
329
|
+
const targetDomain = this.isExternalTool(toolName) ? "external" : "internal";
|
|
330
|
+
|
|
331
|
+
const flowResult = this.policyEngine.evaluate(
|
|
332
|
+
classified,
|
|
333
|
+
sourceDomain,
|
|
334
|
+
targetDomain
|
|
335
|
+
);
|
|
336
|
+
|
|
337
|
+
this.flowTracker.record(
|
|
338
|
+
classified,
|
|
339
|
+
sourceDomain,
|
|
340
|
+
targetDomain,
|
|
341
|
+
this.isExternalTool(toolName) ? "outbound" : "internal",
|
|
342
|
+
flowResult,
|
|
343
|
+
this.sessionId,
|
|
344
|
+
null
|
|
345
|
+
);
|
|
346
|
+
|
|
347
|
+
this.log("PostToolUse", toolName, "check", "Flow tracked");
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
this.log("PostToolUse", toolName, "allow", "Output checks passed");
|
|
351
|
+
return { decision: "allow" };
|
|
352
|
+
|
|
353
|
+
} catch (error) {
|
|
354
|
+
const msg = error instanceof Error ? error.message : String(error);
|
|
355
|
+
this.log("PostToolUse", toolName, "check", `Error: ${msg}`);
|
|
356
|
+
return { decision: "allow" };
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
/**
|
|
361
|
+
* UserPromptSubmit hook - Check user input for injection attempts
|
|
362
|
+
*/
|
|
363
|
+
async onUserPromptSubmit(input: HookInput): Promise<HookOutput> {
|
|
364
|
+
if (!this.config.enabled) {
|
|
365
|
+
return { decision: "allow" };
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
const prompt = input.prompt || "";
|
|
369
|
+
await this.initialize();
|
|
370
|
+
|
|
371
|
+
try {
|
|
372
|
+
// Check for potential injection patterns
|
|
373
|
+
const suspiciousPatterns = [
|
|
374
|
+
/ignore (all )?(previous|above) instructions/i,
|
|
375
|
+
/you are now/i,
|
|
376
|
+
/disregard (all )?(rules|policies)/i,
|
|
377
|
+
/system:? prompt/i,
|
|
378
|
+
/\[system\]/i,
|
|
379
|
+
/<\|.*?\|>/,
|
|
380
|
+
];
|
|
381
|
+
|
|
382
|
+
for (const pattern of suspiciousPatterns) {
|
|
383
|
+
if (pattern.test(prompt)) {
|
|
384
|
+
this.log("UserPromptSubmit", undefined, "check", "Suspicious pattern detected");
|
|
385
|
+
|
|
386
|
+
if (this.config.blockOnViolation) {
|
|
387
|
+
return {
|
|
388
|
+
decision: "deny",
|
|
389
|
+
reason: "[Security] Prompt contains potentially unsafe patterns",
|
|
390
|
+
};
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
// Classify user input
|
|
396
|
+
const classified = await classifyData(prompt, "user_input", []);
|
|
397
|
+
|
|
398
|
+
this.log("UserPromptSubmit", undefined, "check",
|
|
399
|
+
`Input: ${classified.sensitivity}`,
|
|
400
|
+
classified.sensitivity
|
|
401
|
+
);
|
|
402
|
+
|
|
403
|
+
return { decision: "allow" };
|
|
404
|
+
|
|
405
|
+
} catch (error) {
|
|
406
|
+
return { decision: "allow" };
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
/**
|
|
411
|
+
* SessionEnd hook - Generate security report
|
|
412
|
+
*/
|
|
413
|
+
async onSessionEnd(_input: HookInput): Promise<HookOutput> {
|
|
414
|
+
const stats = this.getStats();
|
|
415
|
+
|
|
416
|
+
this.log("SessionEnd", undefined, "check",
|
|
417
|
+
`Session ended - ${stats.totalEvents} events, ${stats.deniedCount} denied`
|
|
418
|
+
);
|
|
419
|
+
|
|
420
|
+
return { decision: "allow" };
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
// ============================================
|
|
424
|
+
// Utility Methods
|
|
425
|
+
// ============================================
|
|
426
|
+
|
|
427
|
+
private inferActionType(toolName: string): string {
|
|
428
|
+
const typeMap: Record<string, string> = {
|
|
429
|
+
Read: "observe",
|
|
430
|
+
Glob: "observe",
|
|
431
|
+
Grep: "observe",
|
|
432
|
+
Write: "modify",
|
|
433
|
+
Edit: "modify",
|
|
434
|
+
MultiEdit: "modify",
|
|
435
|
+
Bash: "execute",
|
|
436
|
+
NotebookEdit: "modify",
|
|
437
|
+
};
|
|
438
|
+
return typeMap[toolName] || "observe";
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
private inferDomain(toolName: string): string {
|
|
442
|
+
const domainMap: Record<string, string> = {
|
|
443
|
+
Read: "filesystem",
|
|
444
|
+
Write: "filesystem",
|
|
445
|
+
Edit: "filesystem",
|
|
446
|
+
Glob: "filesystem",
|
|
447
|
+
Grep: "filesystem",
|
|
448
|
+
Bash: "shell",
|
|
449
|
+
MultiEdit: "filesystem",
|
|
450
|
+
};
|
|
451
|
+
return domainMap[toolName] || "agent";
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
private isExternalTool(toolName: string): boolean {
|
|
455
|
+
const externalTools = ["Bash", "Write", "Edit", "MultiEdit", "NotebookEdit"];
|
|
456
|
+
return externalTools.includes(toolName);
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
private extractContent(input: Record<string, unknown>): string {
|
|
460
|
+
const parts: string[] = [];
|
|
461
|
+
for (const [key, value] of Object.entries(input)) {
|
|
462
|
+
if (typeof value === "string") {
|
|
463
|
+
parts.push(value);
|
|
464
|
+
} else if (typeof value === "object" && value !== null) {
|
|
465
|
+
parts.push(JSON.stringify(value));
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
return parts.join(" ");
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
private log(
|
|
472
|
+
hook: string,
|
|
473
|
+
tool: string | undefined,
|
|
474
|
+
action: SecurityEvent["action"],
|
|
475
|
+
reason: string,
|
|
476
|
+
sensitivity?: string,
|
|
477
|
+
category?: string,
|
|
478
|
+
alignmentScore?: number
|
|
479
|
+
): void {
|
|
480
|
+
const event: SecurityEvent = {
|
|
481
|
+
timestamp: Date.now(),
|
|
482
|
+
hook,
|
|
483
|
+
tool,
|
|
484
|
+
action,
|
|
485
|
+
reason,
|
|
486
|
+
sensitivity,
|
|
487
|
+
category,
|
|
488
|
+
alignmentScore,
|
|
489
|
+
};
|
|
490
|
+
|
|
491
|
+
this.events.push(event);
|
|
492
|
+
|
|
493
|
+
if (this.config.logEvents) {
|
|
494
|
+
const prefix = action === "deny" ? "\x1b[31m[Security]\x1b[0m" : "\x1b[90m[Security]\x1b[0m";
|
|
495
|
+
const toolStr = tool ? ` ${tool}:` : "";
|
|
496
|
+
// Use console.error to avoid interfering with TUI (stdout is used by renderer)
|
|
497
|
+
console.error(`${prefix}${toolStr} ${reason}`);
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
/**
|
|
502
|
+
* Get all security events
|
|
503
|
+
*/
|
|
504
|
+
getEvents(): SecurityEvent[] {
|
|
505
|
+
return [...this.events];
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
/**
|
|
509
|
+
* Get security statistics
|
|
510
|
+
*/
|
|
511
|
+
getStats(): {
|
|
512
|
+
totalEvents: number;
|
|
513
|
+
allowedCount: number;
|
|
514
|
+
deniedCount: number;
|
|
515
|
+
sanitizedCount: number;
|
|
516
|
+
bySensitivity: Record<string, number>;
|
|
517
|
+
avgAlignmentScore: number;
|
|
518
|
+
} {
|
|
519
|
+
const allowedCount = this.events.filter(e => e.action === "allow").length;
|
|
520
|
+
const deniedCount = this.events.filter(e => e.action === "deny").length;
|
|
521
|
+
const sanitizedCount = this.events.filter(e => e.action === "sanitize").length;
|
|
522
|
+
|
|
523
|
+
const bySensitivity: Record<string, number> = {};
|
|
524
|
+
for (const event of this.events) {
|
|
525
|
+
if (event.sensitivity) {
|
|
526
|
+
bySensitivity[event.sensitivity] = (bySensitivity[event.sensitivity] || 0) + 1;
|
|
527
|
+
}
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
const alignmentScores = this.events
|
|
531
|
+
.filter(e => e.alignmentScore !== undefined)
|
|
532
|
+
.map(e => e.alignmentScore!);
|
|
533
|
+
const avgAlignmentScore = alignmentScores.length > 0
|
|
534
|
+
? alignmentScores.reduce((a, b) => a + b, 0) / alignmentScores.length
|
|
535
|
+
: 0;
|
|
536
|
+
|
|
537
|
+
return {
|
|
538
|
+
totalEvents: this.events.length,
|
|
539
|
+
allowedCount,
|
|
540
|
+
deniedCount,
|
|
541
|
+
sanitizedCount,
|
|
542
|
+
bySensitivity,
|
|
543
|
+
avgAlignmentScore,
|
|
544
|
+
};
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
/**
|
|
548
|
+
* Clear event history
|
|
549
|
+
*/
|
|
550
|
+
clearEvents(): void {
|
|
551
|
+
this.events = [];
|
|
552
|
+
}
|
|
553
|
+
}
|
|
554
|
+
|
|
555
|
+
// Singleton instance
|
|
556
|
+
let globalHooks: CognitiveSecurityHooks | null = null;
|
|
557
|
+
|
|
558
|
+
/**
|
|
559
|
+
* Get global security hooks instance
|
|
560
|
+
*/
|
|
561
|
+
export function getSecurityHooks(
|
|
562
|
+
config?: Partial<SecurityHookConfig>
|
|
563
|
+
): CognitiveSecurityHooks {
|
|
564
|
+
if (!globalHooks) {
|
|
565
|
+
globalHooks = new CognitiveSecurityHooks(config);
|
|
566
|
+
}
|
|
567
|
+
return globalHooks;
|
|
568
|
+
}
|
|
569
|
+
|
|
570
|
+
/**
|
|
571
|
+
* Create hook handlers for HookManager
|
|
572
|
+
*/
|
|
573
|
+
export function createSecurityHookHandlers(
|
|
574
|
+
config?: Partial<SecurityHookConfig>
|
|
575
|
+
): {
|
|
576
|
+
SessionStart: (input: HookInput) => Promise<HookOutput>;
|
|
577
|
+
PreToolUse: (input: HookInput) => Promise<HookOutput>;
|
|
578
|
+
PostToolUse: (input: HookInput) => Promise<HookOutput>;
|
|
579
|
+
UserPromptSubmit: (input: HookInput) => Promise<HookOutput>;
|
|
580
|
+
SessionEnd: (input: HookInput) => Promise<HookOutput>;
|
|
581
|
+
} {
|
|
582
|
+
const hooks = new CognitiveSecurityHooks(config);
|
|
583
|
+
|
|
584
|
+
return {
|
|
585
|
+
SessionStart: (input) => hooks.onSessionStart(input),
|
|
586
|
+
PreToolUse: (input) => hooks.onPreToolUse(input),
|
|
587
|
+
PostToolUse: (input) => hooks.onPostToolUse(input),
|
|
588
|
+
UserPromptSubmit: (input) => hooks.onUserPromptSubmit(input),
|
|
589
|
+
SessionEnd: (input) => hooks.onSessionEnd(input),
|
|
590
|
+
};
|
|
591
|
+
}
|