clawsec 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +560 -0
- package/dist/bin/clawsec.d.ts +7 -0
- package/dist/bin/clawsec.d.ts.map +1 -0
- package/dist/bin/clawsec.js +12 -0
- package/dist/bin/clawsec.js.map +1 -0
- package/dist/src/actions/block.d.ts +22 -0
- package/dist/src/actions/block.d.ts.map +1 -0
- package/dist/src/actions/block.js +83 -0
- package/dist/src/actions/block.js.map +1 -0
- package/dist/src/actions/confirm.d.ts +35 -0
- package/dist/src/actions/confirm.d.ts.map +1 -0
- package/dist/src/actions/confirm.js +156 -0
- package/dist/src/actions/confirm.js.map +1 -0
- package/dist/src/actions/executor.d.ts +64 -0
- package/dist/src/actions/executor.d.ts.map +1 -0
- package/dist/src/actions/executor.js +114 -0
- package/dist/src/actions/executor.js.map +1 -0
- package/dist/src/actions/index.d.ts +13 -0
- package/dist/src/actions/index.d.ts.map +1 -0
- package/dist/src/actions/index.js +15 -0
- package/dist/src/actions/index.js.map +1 -0
- package/dist/src/actions/log.d.ts +19 -0
- package/dist/src/actions/log.d.ts.map +1 -0
- package/dist/src/actions/log.js +63 -0
- package/dist/src/actions/log.js.map +1 -0
- package/dist/src/actions/types.d.ts +85 -0
- package/dist/src/actions/types.d.ts.map +1 -0
- package/dist/src/actions/types.js +78 -0
- package/dist/src/actions/types.js.map +1 -0
- package/dist/src/actions/warn.d.ts +22 -0
- package/dist/src/actions/warn.d.ts.map +1 -0
- package/dist/src/actions/warn.js +84 -0
- package/dist/src/actions/warn.js.map +1 -0
- package/dist/src/approval/agent-confirm.d.ts +104 -0
- package/dist/src/approval/agent-confirm.d.ts.map +1 -0
- package/dist/src/approval/agent-confirm.js +173 -0
- package/dist/src/approval/agent-confirm.js.map +1 -0
- package/dist/src/approval/index.d.ts +14 -0
- package/dist/src/approval/index.d.ts.map +1 -0
- package/dist/src/approval/index.js +9 -0
- package/dist/src/approval/index.js.map +1 -0
- package/dist/src/approval/native.d.ts +56 -0
- package/dist/src/approval/native.d.ts.map +1 -0
- package/dist/src/approval/native.js +196 -0
- package/dist/src/approval/native.js.map +1 -0
- package/dist/src/approval/store.d.ts +88 -0
- package/dist/src/approval/store.d.ts.map +1 -0
- package/dist/src/approval/store.js +192 -0
- package/dist/src/approval/store.js.map +1 -0
- package/dist/src/approval/types.d.ts +119 -0
- package/dist/src/approval/types.d.ts.map +1 -0
- package/dist/src/approval/types.js +6 -0
- package/dist/src/approval/types.js.map +1 -0
- package/dist/src/approval/webhook.d.ts +170 -0
- package/dist/src/approval/webhook.d.ts.map +1 -0
- package/dist/src/approval/webhook.js +362 -0
- package/dist/src/approval/webhook.js.map +1 -0
- package/dist/src/cli/commands/audit.d.ts +43 -0
- package/dist/src/cli/commands/audit.d.ts.map +1 -0
- package/dist/src/cli/commands/audit.js +115 -0
- package/dist/src/cli/commands/audit.js.map +1 -0
- package/dist/src/cli/commands/feedback.d.ts +27 -0
- package/dist/src/cli/commands/feedback.d.ts.map +1 -0
- package/dist/src/cli/commands/feedback.js +228 -0
- package/dist/src/cli/commands/feedback.js.map +1 -0
- package/dist/src/cli/commands/index.d.ts +11 -0
- package/dist/src/cli/commands/index.d.ts.map +1 -0
- package/dist/src/cli/commands/index.js +13 -0
- package/dist/src/cli/commands/index.js.map +1 -0
- package/dist/src/cli/commands/status.d.ts +20 -0
- package/dist/src/cli/commands/status.d.ts.map +1 -0
- package/dist/src/cli/commands/status.js +122 -0
- package/dist/src/cli/commands/status.js.map +1 -0
- package/dist/src/cli/commands/test.d.ts +23 -0
- package/dist/src/cli/commands/test.d.ts.map +1 -0
- package/dist/src/cli/commands/test.js +134 -0
- package/dist/src/cli/commands/test.js.map +1 -0
- package/dist/src/cli/commands/types.d.ts +81 -0
- package/dist/src/cli/commands/types.d.ts.map +1 -0
- package/dist/src/cli/commands/types.js +6 -0
- package/dist/src/cli/commands/types.js.map +1 -0
- package/dist/src/cli/index.d.ts +17 -0
- package/dist/src/cli/index.d.ts.map +1 -0
- package/dist/src/cli/index.js +267 -0
- package/dist/src/cli/index.js.map +1 -0
- package/dist/src/config/defaults.d.ts +20 -0
- package/dist/src/config/defaults.d.ts.map +1 -0
- package/dist/src/config/defaults.js +123 -0
- package/dist/src/config/defaults.js.map +1 -0
- package/dist/src/config/index.d.ts +8 -0
- package/dist/src/config/index.d.ts.map +1 -0
- package/dist/src/config/index.js +41 -0
- package/dist/src/config/index.js.map +1 -0
- package/dist/src/config/loader.d.ts +99 -0
- package/dist/src/config/loader.d.ts.map +1 -0
- package/dist/src/config/loader.js +242 -0
- package/dist/src/config/loader.js.map +1 -0
- package/dist/src/config/schema.d.ts +627 -0
- package/dist/src/config/schema.d.ts.map +1 -0
- package/dist/src/config/schema.js +585 -0
- package/dist/src/config/schema.js.map +1 -0
- package/dist/src/detectors/destructive/cloud-detector.d.ts +51 -0
- package/dist/src/detectors/destructive/cloud-detector.d.ts.map +1 -0
- package/dist/src/detectors/destructive/cloud-detector.js +556 -0
- package/dist/src/detectors/destructive/cloud-detector.js.map +1 -0
- package/dist/src/detectors/destructive/code-detector.d.ts +59 -0
- package/dist/src/detectors/destructive/code-detector.d.ts.map +1 -0
- package/dist/src/detectors/destructive/code-detector.js +558 -0
- package/dist/src/detectors/destructive/code-detector.js.map +1 -0
- package/dist/src/detectors/destructive/index.d.ts +54 -0
- package/dist/src/detectors/destructive/index.d.ts.map +1 -0
- package/dist/src/detectors/destructive/index.js +168 -0
- package/dist/src/detectors/destructive/index.js.map +1 -0
- package/dist/src/detectors/destructive/shell-detector.d.ts +43 -0
- package/dist/src/detectors/destructive/shell-detector.d.ts.map +1 -0
- package/dist/src/detectors/destructive/shell-detector.js +302 -0
- package/dist/src/detectors/destructive/shell-detector.js.map +1 -0
- package/dist/src/detectors/destructive/types.d.ts +143 -0
- package/dist/src/detectors/destructive/types.d.ts.map +1 -0
- package/dist/src/detectors/destructive/types.js +6 -0
- package/dist/src/detectors/destructive/types.js.map +1 -0
- package/dist/src/detectors/exfiltration/cloud-detector.d.ts +51 -0
- package/dist/src/detectors/exfiltration/cloud-detector.d.ts.map +1 -0
- package/dist/src/detectors/exfiltration/cloud-detector.js +427 -0
- package/dist/src/detectors/exfiltration/cloud-detector.js.map +1 -0
- package/dist/src/detectors/exfiltration/http-detector.d.ts +47 -0
- package/dist/src/detectors/exfiltration/http-detector.d.ts.map +1 -0
- package/dist/src/detectors/exfiltration/http-detector.js +429 -0
- package/dist/src/detectors/exfiltration/http-detector.js.map +1 -0
- package/dist/src/detectors/exfiltration/index.d.ts +44 -0
- package/dist/src/detectors/exfiltration/index.d.ts.map +1 -0
- package/dist/src/detectors/exfiltration/index.js +118 -0
- package/dist/src/detectors/exfiltration/index.js.map +1 -0
- package/dist/src/detectors/exfiltration/network-detector.d.ts +55 -0
- package/dist/src/detectors/exfiltration/network-detector.d.ts.map +1 -0
- package/dist/src/detectors/exfiltration/network-detector.js +504 -0
- package/dist/src/detectors/exfiltration/network-detector.js.map +1 -0
- package/dist/src/detectors/exfiltration/types.d.ts +139 -0
- package/dist/src/detectors/exfiltration/types.d.ts.map +1 -0
- package/dist/src/detectors/exfiltration/types.js +6 -0
- package/dist/src/detectors/exfiltration/types.js.map +1 -0
- package/dist/src/detectors/purchase/domain-detector.d.ts +44 -0
- package/dist/src/detectors/purchase/domain-detector.d.ts.map +1 -0
- package/dist/src/detectors/purchase/domain-detector.js +296 -0
- package/dist/src/detectors/purchase/domain-detector.js.map +1 -0
- package/dist/src/detectors/purchase/form-detector.d.ts +27 -0
- package/dist/src/detectors/purchase/form-detector.d.ts.map +1 -0
- package/dist/src/detectors/purchase/form-detector.js +344 -0
- package/dist/src/detectors/purchase/form-detector.js.map +1 -0
- package/dist/src/detectors/purchase/index.d.ts +65 -0
- package/dist/src/detectors/purchase/index.d.ts.map +1 -0
- package/dist/src/detectors/purchase/index.js +216 -0
- package/dist/src/detectors/purchase/index.js.map +1 -0
- package/dist/src/detectors/purchase/spend-tracker.d.ts +132 -0
- package/dist/src/detectors/purchase/spend-tracker.d.ts.map +1 -0
- package/dist/src/detectors/purchase/spend-tracker.js +313 -0
- package/dist/src/detectors/purchase/spend-tracker.js.map +1 -0
- package/dist/src/detectors/purchase/types.d.ts +139 -0
- package/dist/src/detectors/purchase/types.d.ts.map +1 -0
- package/dist/src/detectors/purchase/types.js +6 -0
- package/dist/src/detectors/purchase/types.js.map +1 -0
- package/dist/src/detectors/purchase/url-detector.d.ts +31 -0
- package/dist/src/detectors/purchase/url-detector.d.ts.map +1 -0
- package/dist/src/detectors/purchase/url-detector.js +292 -0
- package/dist/src/detectors/purchase/url-detector.js.map +1 -0
- package/dist/src/detectors/secrets/api-key-detector.d.ts +30 -0
- package/dist/src/detectors/secrets/api-key-detector.d.ts.map +1 -0
- package/dist/src/detectors/secrets/api-key-detector.js +297 -0
- package/dist/src/detectors/secrets/api-key-detector.js.map +1 -0
- package/dist/src/detectors/secrets/index.d.ts +43 -0
- package/dist/src/detectors/secrets/index.d.ts.map +1 -0
- package/dist/src/detectors/secrets/index.js +261 -0
- package/dist/src/detectors/secrets/index.js.map +1 -0
- package/dist/src/detectors/secrets/pii-detector.d.ts +54 -0
- package/dist/src/detectors/secrets/pii-detector.d.ts.map +1 -0
- package/dist/src/detectors/secrets/pii-detector.js +286 -0
- package/dist/src/detectors/secrets/pii-detector.js.map +1 -0
- package/dist/src/detectors/secrets/token-detector.d.ts +51 -0
- package/dist/src/detectors/secrets/token-detector.d.ts.map +1 -0
- package/dist/src/detectors/secrets/token-detector.js +233 -0
- package/dist/src/detectors/secrets/token-detector.js.map +1 -0
- package/dist/src/detectors/secrets/types.d.ts +157 -0
- package/dist/src/detectors/secrets/types.d.ts.map +1 -0
- package/dist/src/detectors/secrets/types.js +6 -0
- package/dist/src/detectors/secrets/types.js.map +1 -0
- package/dist/src/detectors/website/category-detector.d.ts +22 -0
- package/dist/src/detectors/website/category-detector.d.ts.map +1 -0
- package/dist/src/detectors/website/category-detector.js +162 -0
- package/dist/src/detectors/website/category-detector.js.map +1 -0
- package/dist/src/detectors/website/index.d.ts +53 -0
- package/dist/src/detectors/website/index.d.ts.map +1 -0
- package/dist/src/detectors/website/index.js +232 -0
- package/dist/src/detectors/website/index.js.map +1 -0
- package/dist/src/detectors/website/pattern-matcher.d.ts +33 -0
- package/dist/src/detectors/website/pattern-matcher.d.ts.map +1 -0
- package/dist/src/detectors/website/pattern-matcher.js +121 -0
- package/dist/src/detectors/website/pattern-matcher.js.map +1 -0
- package/dist/src/detectors/website/types.d.ts +105 -0
- package/dist/src/detectors/website/types.d.ts.map +1 -0
- package/dist/src/detectors/website/types.js +6 -0
- package/dist/src/detectors/website/types.js.map +1 -0
- package/dist/src/engine/analyzer.d.ts +87 -0
- package/dist/src/engine/analyzer.d.ts.map +1 -0
- package/dist/src/engine/analyzer.js +427 -0
- package/dist/src/engine/analyzer.js.map +1 -0
- package/dist/src/engine/cache.d.ts +80 -0
- package/dist/src/engine/cache.d.ts.map +1 -0
- package/dist/src/engine/cache.js +167 -0
- package/dist/src/engine/cache.js.map +1 -0
- package/dist/src/engine/index.d.ts +11 -0
- package/dist/src/engine/index.d.ts.map +1 -0
- package/dist/src/engine/index.js +11 -0
- package/dist/src/engine/index.js.map +1 -0
- package/dist/src/engine/llm-client.d.ts +210 -0
- package/dist/src/engine/llm-client.d.ts.map +1 -0
- package/dist/src/engine/llm-client.js +506 -0
- package/dist/src/engine/llm-client.js.map +1 -0
- package/dist/src/engine/types.d.ts +163 -0
- package/dist/src/engine/types.d.ts.map +1 -0
- package/dist/src/engine/types.js +21 -0
- package/dist/src/engine/types.js.map +1 -0
- package/dist/src/feedback/index.d.ts +9 -0
- package/dist/src/feedback/index.d.ts.map +1 -0
- package/dist/src/feedback/index.js +8 -0
- package/dist/src/feedback/index.js.map +1 -0
- package/dist/src/feedback/learner.d.ts +222 -0
- package/dist/src/feedback/learner.d.ts.map +1 -0
- package/dist/src/feedback/learner.js +401 -0
- package/dist/src/feedback/learner.js.map +1 -0
- package/dist/src/feedback/store.d.ts +113 -0
- package/dist/src/feedback/store.d.ts.map +1 -0
- package/dist/src/feedback/store.js +228 -0
- package/dist/src/feedback/store.js.map +1 -0
- package/dist/src/feedback/types.d.ts +126 -0
- package/dist/src/feedback/types.d.ts.map +1 -0
- package/dist/src/feedback/types.js +6 -0
- package/dist/src/feedback/types.js.map +1 -0
- package/dist/src/hooks/before-agent-start/handler.d.ts +37 -0
- package/dist/src/hooks/before-agent-start/handler.d.ts.map +1 -0
- package/dist/src/hooks/before-agent-start/handler.js +109 -0
- package/dist/src/hooks/before-agent-start/handler.js.map +1 -0
- package/dist/src/hooks/before-agent-start/index.d.ts +8 -0
- package/dist/src/hooks/before-agent-start/index.d.ts.map +1 -0
- package/dist/src/hooks/before-agent-start/index.js +7 -0
- package/dist/src/hooks/before-agent-start/index.js.map +1 -0
- package/dist/src/hooks/before-agent-start/prompts.d.ts +48 -0
- package/dist/src/hooks/before-agent-start/prompts.d.ts.map +1 -0
- package/dist/src/hooks/before-agent-start/prompts.js +103 -0
- package/dist/src/hooks/before-agent-start/prompts.js.map +1 -0
- package/dist/src/hooks/before-tool-call/handler.d.ts +42 -0
- package/dist/src/hooks/before-tool-call/handler.d.ts.map +1 -0
- package/dist/src/hooks/before-tool-call/handler.js +226 -0
- package/dist/src/hooks/before-tool-call/handler.js.map +1 -0
- package/dist/src/hooks/before-tool-call/index.d.ts +7 -0
- package/dist/src/hooks/before-tool-call/index.d.ts.map +1 -0
- package/dist/src/hooks/before-tool-call/index.js +6 -0
- package/dist/src/hooks/before-tool-call/index.js.map +1 -0
- package/dist/src/hooks/tool-result-persist/filter.d.ts +72 -0
- package/dist/src/hooks/tool-result-persist/filter.d.ts.map +1 -0
- package/dist/src/hooks/tool-result-persist/filter.js +305 -0
- package/dist/src/hooks/tool-result-persist/filter.js.map +1 -0
- package/dist/src/hooks/tool-result-persist/handler.d.ts +49 -0
- package/dist/src/hooks/tool-result-persist/handler.d.ts.map +1 -0
- package/dist/src/hooks/tool-result-persist/handler.js +217 -0
- package/dist/src/hooks/tool-result-persist/handler.js.map +1 -0
- package/dist/src/hooks/tool-result-persist/index.d.ts +11 -0
- package/dist/src/hooks/tool-result-persist/index.d.ts.map +1 -0
- package/dist/src/hooks/tool-result-persist/index.js +11 -0
- package/dist/src/hooks/tool-result-persist/index.js.map +1 -0
- package/dist/src/index.d.ts +256 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +222 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/notifications/discord.d.ts +10 -0
- package/dist/src/notifications/discord.d.ts.map +1 -0
- package/dist/src/notifications/discord.js +218 -0
- package/dist/src/notifications/discord.js.map +1 -0
- package/dist/src/notifications/index.d.ts +37 -0
- package/dist/src/notifications/index.d.ts.map +1 -0
- package/dist/src/notifications/index.js +68 -0
- package/dist/src/notifications/index.js.map +1 -0
- package/dist/src/notifications/slack.d.ts +10 -0
- package/dist/src/notifications/slack.d.ts.map +1 -0
- package/dist/src/notifications/slack.js +218 -0
- package/dist/src/notifications/slack.js.map +1 -0
- package/dist/src/notifications/telegram.d.ts +10 -0
- package/dist/src/notifications/telegram.d.ts.map +1 -0
- package/dist/src/notifications/telegram.js +242 -0
- package/dist/src/notifications/telegram.js.map +1 -0
- package/dist/src/notifications/types.d.ts +119 -0
- package/dist/src/notifications/types.d.ts.map +1 -0
- package/dist/src/notifications/types.js +6 -0
- package/dist/src/notifications/types.js.map +1 -0
- package/dist/src/proxy/index.d.ts +8 -0
- package/dist/src/proxy/index.d.ts.map +1 -0
- package/dist/src/proxy/index.js +9 -0
- package/dist/src/proxy/index.js.map +1 -0
- package/dist/src/proxy/middleware.d.ts +55 -0
- package/dist/src/proxy/middleware.d.ts.map +1 -0
- package/dist/src/proxy/middleware.js +215 -0
- package/dist/src/proxy/middleware.js.map +1 -0
- package/dist/src/proxy/server.d.ts +57 -0
- package/dist/src/proxy/server.d.ts.map +1 -0
- package/dist/src/proxy/server.js +298 -0
- package/dist/src/proxy/server.js.map +1 -0
- package/dist/src/proxy/types.d.ts +136 -0
- package/dist/src/proxy/types.d.ts.map +1 -0
- package/dist/src/proxy/types.js +6 -0
- package/dist/src/proxy/types.js.map +1 -0
- package/dist/src/sanitization/index.d.ts +10 -0
- package/dist/src/sanitization/index.d.ts.map +1 -0
- package/dist/src/sanitization/index.js +9 -0
- package/dist/src/sanitization/index.js.map +1 -0
- package/dist/src/sanitization/patterns.d.ts +51 -0
- package/dist/src/sanitization/patterns.d.ts.map +1 -0
- package/dist/src/sanitization/patterns.js +266 -0
- package/dist/src/sanitization/patterns.js.map +1 -0
- package/dist/src/sanitization/scanner.d.ts +29 -0
- package/dist/src/sanitization/scanner.d.ts.map +1 -0
- package/dist/src/sanitization/scanner.js +328 -0
- package/dist/src/sanitization/scanner.js.map +1 -0
- package/dist/src/sanitization/types.d.ts +57 -0
- package/dist/src/sanitization/types.d.ts.map +1 -0
- package/dist/src/sanitization/types.js +5 -0
- package/dist/src/sanitization/types.js.map +1 -0
- package/openclaw.plugin.json +114 -0
- package/package.json +63 -0
- package/rules/builtin/README.md +139 -0
- package/rules/builtin/ai-services.yaml +70 -0
- package/rules/builtin/api-keys.yaml +64 -0
- package/rules/builtin/authentication.yaml +56 -0
- package/rules/builtin/aws-security.yaml +57 -0
- package/rules/builtin/azure-security.yaml +58 -0
- package/rules/builtin/cicd-security.yaml +64 -0
- package/rules/builtin/cloud-storage.yaml +64 -0
- package/rules/builtin/container-registry.yaml +55 -0
- package/rules/builtin/crypto-wallets.yaml +71 -0
- package/rules/builtin/database-nosql.yaml +58 -0
- package/rules/builtin/database-sql.yaml +62 -0
- package/rules/builtin/development-env.yaml +67 -0
- package/rules/builtin/docker.yaml +57 -0
- package/rules/builtin/filesystem.yaml +71 -0
- package/rules/builtin/financial-pci.yaml +61 -0
- package/rules/builtin/gcp-security.yaml +57 -0
- package/rules/builtin/git-operations.yaml +68 -0
- package/rules/builtin/healthcare-hipaa.yaml +64 -0
- package/rules/builtin/kubernetes.yaml +60 -0
- package/rules/builtin/messaging-services.yaml +53 -0
- package/rules/builtin/minimal.yaml +47 -0
- package/rules/builtin/mobile-development.yaml +61 -0
- package/rules/builtin/monitoring.yaml +63 -0
- package/rules/builtin/network-security.yaml +57 -0
- package/rules/builtin/package-managers.yaml +74 -0
- package/rules/builtin/payment-processing.yaml +66 -0
- package/rules/builtin/pii-protection.yaml +48 -0
- package/rules/builtin/production-strict.yaml +55 -0
- package/rules/builtin/secrets-management.yaml +63 -0
- package/rules/builtin/serverless.yaml +74 -0
- package/rules/builtin/ssh-security.yaml +66 -0
- package/rules/builtin/terraform.yaml +51 -0
- package/rules/builtin/web-security.yaml +62 -0
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Clawsec Default Configuration
|
|
3
|
+
* Sensible default values for the security plugin
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Default configuration for Clawsec
|
|
7
|
+
*
|
|
8
|
+
* All features enabled by default with conservative settings:
|
|
9
|
+
* - Purchases are blocked by default
|
|
10
|
+
* - Destructive commands require confirmation
|
|
11
|
+
* - Secrets and exfiltration are blocked
|
|
12
|
+
*/
|
|
13
|
+
export const defaultConfig = {
|
|
14
|
+
version: '1.0',
|
|
15
|
+
global: {
|
|
16
|
+
enabled: true,
|
|
17
|
+
logLevel: 'info',
|
|
18
|
+
},
|
|
19
|
+
llm: {
|
|
20
|
+
enabled: true,
|
|
21
|
+
model: null, // Use OpenClaw's configured model
|
|
22
|
+
},
|
|
23
|
+
rules: {
|
|
24
|
+
purchase: {
|
|
25
|
+
enabled: true,
|
|
26
|
+
severity: 'critical',
|
|
27
|
+
action: 'block',
|
|
28
|
+
spendLimits: {
|
|
29
|
+
perTransaction: 100,
|
|
30
|
+
daily: 500,
|
|
31
|
+
},
|
|
32
|
+
domains: {
|
|
33
|
+
mode: 'blocklist',
|
|
34
|
+
blocklist: [
|
|
35
|
+
'amazon.com',
|
|
36
|
+
'stripe.com',
|
|
37
|
+
'paypal.com',
|
|
38
|
+
'checkout.stripe.com',
|
|
39
|
+
'buy.stripe.com',
|
|
40
|
+
'billing.stripe.com',
|
|
41
|
+
],
|
|
42
|
+
},
|
|
43
|
+
},
|
|
44
|
+
website: {
|
|
45
|
+
enabled: true,
|
|
46
|
+
mode: 'blocklist',
|
|
47
|
+
severity: 'high',
|
|
48
|
+
action: 'block',
|
|
49
|
+
blocklist: [
|
|
50
|
+
'*.malware.com',
|
|
51
|
+
'phishing-*.com',
|
|
52
|
+
'*.darkweb.*',
|
|
53
|
+
],
|
|
54
|
+
allowlist: [
|
|
55
|
+
'docs.openclaw.ai',
|
|
56
|
+
'github.com',
|
|
57
|
+
'stackoverflow.com',
|
|
58
|
+
'developer.mozilla.org',
|
|
59
|
+
],
|
|
60
|
+
},
|
|
61
|
+
destructive: {
|
|
62
|
+
enabled: true,
|
|
63
|
+
severity: 'critical',
|
|
64
|
+
action: 'confirm',
|
|
65
|
+
shell: {
|
|
66
|
+
enabled: true,
|
|
67
|
+
},
|
|
68
|
+
cloud: {
|
|
69
|
+
enabled: true,
|
|
70
|
+
},
|
|
71
|
+
code: {
|
|
72
|
+
enabled: true,
|
|
73
|
+
},
|
|
74
|
+
},
|
|
75
|
+
secrets: {
|
|
76
|
+
enabled: true,
|
|
77
|
+
severity: 'critical',
|
|
78
|
+
action: 'block',
|
|
79
|
+
},
|
|
80
|
+
exfiltration: {
|
|
81
|
+
enabled: true,
|
|
82
|
+
severity: 'high',
|
|
83
|
+
action: 'block',
|
|
84
|
+
},
|
|
85
|
+
sanitization: {
|
|
86
|
+
enabled: true,
|
|
87
|
+
severity: 'high',
|
|
88
|
+
action: 'block',
|
|
89
|
+
minConfidence: 0.5,
|
|
90
|
+
redactMatches: false,
|
|
91
|
+
categories: {
|
|
92
|
+
instructionOverride: true,
|
|
93
|
+
systemLeak: true,
|
|
94
|
+
jailbreak: true,
|
|
95
|
+
encodedPayload: true,
|
|
96
|
+
},
|
|
97
|
+
},
|
|
98
|
+
},
|
|
99
|
+
approval: {
|
|
100
|
+
native: {
|
|
101
|
+
enabled: true,
|
|
102
|
+
timeout: 300, // 5 minutes
|
|
103
|
+
},
|
|
104
|
+
agentConfirm: {
|
|
105
|
+
enabled: true,
|
|
106
|
+
parameterName: '_clawsec_confirm',
|
|
107
|
+
},
|
|
108
|
+
webhook: {
|
|
109
|
+
enabled: false,
|
|
110
|
+
url: undefined,
|
|
111
|
+
timeout: 30,
|
|
112
|
+
headers: {},
|
|
113
|
+
},
|
|
114
|
+
},
|
|
115
|
+
};
|
|
116
|
+
/**
|
|
117
|
+
* Returns a deep clone of the default configuration
|
|
118
|
+
* to prevent accidental mutations
|
|
119
|
+
*/
|
|
120
|
+
export function getDefaultConfig() {
|
|
121
|
+
return structuredClone(defaultConfig);
|
|
122
|
+
}
|
|
123
|
+
//# sourceMappingURL=defaults.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"defaults.js","sourceRoot":"","sources":["../../../src/config/defaults.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,aAAa,GAAkB;IAC1C,OAAO,EAAE,KAAK;IAEd,MAAM,EAAE;QACN,OAAO,EAAE,IAAI;QACb,QAAQ,EAAE,MAAM;KACjB;IAED,GAAG,EAAE;QACH,OAAO,EAAE,IAAI;QACb,KAAK,EAAE,IAAI,EAAE,kCAAkC;KAChD;IAED,KAAK,EAAE;QACL,QAAQ,EAAE;YACR,OAAO,EAAE,IAAI;YACb,QAAQ,EAAE,UAAU;YACpB,MAAM,EAAE,OAAO;YACf,WAAW,EAAE;gBACX,cAAc,EAAE,GAAG;gBACnB,KAAK,EAAE,GAAG;aACX;YACD,OAAO,EAAE;gBACP,IAAI,EAAE,WAAW;gBACjB,SAAS,EAAE;oBACT,YAAY;oBACZ,YAAY;oBACZ,YAAY;oBACZ,qBAAqB;oBACrB,gBAAgB;oBAChB,oBAAoB;iBACrB;aACF;SACF;QAED,OAAO,EAAE;YACP,OAAO,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;;GAGG;AACH,MAAM,UAAU,gBAAgB;IAC9B,OAAO,eAAe,CAAC,aAAa,CAAC,CAAC;AACxC,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Clawsec Configuration Module
|
|
3
|
+
* Re-exports for clean imports
|
|
4
|
+
*/
|
|
5
|
+
export { SeveritySchema, ActionSchema, LogLevelSchema, FilterModeSchema, type Severity, type Action, type LogLevel, type FilterMode, GlobalConfigSchema, type GlobalConfig, LLMConfigSchema, type LLMConfig, SpendLimitsSchema, PurchaseDomainsSchema, PurchaseRuleSchema, type SpendLimits, type PurchaseDomains, type PurchaseRule, WebsiteRuleSchema, type WebsiteRule, ShellProtectionSchema, CloudProtectionSchema, CodeProtectionSchema, DestructiveRuleSchema, type ShellProtection, type CloudProtection, type CodeProtection, type DestructiveRule, SecretsRuleSchema, type SecretsRule, ExfiltrationRuleSchema, type ExfiltrationRule, RulesConfigSchema, type RulesConfig, NativeApprovalSchema, AgentConfirmSchema, WebhookApprovalSchema, ApprovalConfigSchema, type NativeApproval, type AgentConfirm, type WebhookApproval, type ApprovalConfig, ClawsecConfigSchema, type ClawsecConfig, type PartialClawsecConfig, } from './schema.js';
|
|
6
|
+
export { defaultConfig, getDefaultConfig } from './defaults.js';
|
|
7
|
+
export { ConfigValidationError, ConfigLoadError, validateConfig, isValidConfig, mergeWithDefaults, mergeConfigs, findConfigFile, loadConfig, loadConfigFromString, } from './loader.js';
|
|
8
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/config/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAEL,cAAc,EACd,YAAY,EACZ,cAAc,EACd,gBAAgB,EAEhB,KAAK,QAAQ,EACb,KAAK,MAAM,EACX,KAAK,QAAQ,EACb,KAAK,UAAU,EAEf,kBAAkB,EAClB,KAAK,YAAY,EAEjB,eAAe,EACf,KAAK,SAAS,EAEd,iBAAiB,EACjB,qBAAqB,EACrB,kBAAkB,EAClB,KAAK,WAAW,EAChB,KAAK,eAAe,EACpB,KAAK,YAAY,EAEjB,iBAAiB,EACjB,KAAK,WAAW,EAEhB,qBAAqB,EACrB,qBAAqB,EACrB,oBAAoB,EACpB,qBAAqB,EACrB,KAAK,eAAe,EACpB,KAAK,eAAe,EACpB,KAAK,cAAc,EACnB,KAAK,eAAe,EAEpB,iBAAiB,EACjB,KAAK,WAAW,EAEhB,sBAAsB,EACtB,KAAK,gBAAgB,EAErB,iBAAiB,EACjB,KAAK,WAAW,EAEhB,oBAAoB,EACpB,kBAAkB,EAClB,qBAAqB,EACrB,oBAAoB,EACpB,KAAK,cAAc,EACnB,KAAK,YAAY,EACjB,KAAK,eAAe,EACpB,KAAK,cAAc,EAEnB,mBAAmB,EACnB,KAAK,aAAa,EAClB,KAAK,oBAAoB,GAC1B,MAAM,aAAa,CAAC;AAGrB,OAAO,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAGhE,OAAO,EAEL,qBAAqB,EACrB,eAAe,EAEf,cAAc,EACd,aAAa,EAEb,iBAAiB,EACjB,YAAY,EAEZ,cAAc,EACd,UAAU,EACV,oBAAoB,GACrB,MAAM,aAAa,CAAC"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Clawsec Configuration Module
|
|
3
|
+
* Re-exports for clean imports
|
|
4
|
+
*/
|
|
5
|
+
// Schema and types
|
|
6
|
+
export {
|
|
7
|
+
// Enums
|
|
8
|
+
SeveritySchema, ActionSchema, LogLevelSchema, FilterModeSchema,
|
|
9
|
+
// Global config
|
|
10
|
+
GlobalConfigSchema,
|
|
11
|
+
// LLM config
|
|
12
|
+
LLMConfigSchema,
|
|
13
|
+
// Purchase rule
|
|
14
|
+
SpendLimitsSchema, PurchaseDomainsSchema, PurchaseRuleSchema,
|
|
15
|
+
// Website rule
|
|
16
|
+
WebsiteRuleSchema,
|
|
17
|
+
// Destructive rule
|
|
18
|
+
ShellProtectionSchema, CloudProtectionSchema, CodeProtectionSchema, DestructiveRuleSchema,
|
|
19
|
+
// Secrets rule
|
|
20
|
+
SecretsRuleSchema,
|
|
21
|
+
// Exfiltration rule
|
|
22
|
+
ExfiltrationRuleSchema,
|
|
23
|
+
// Rules config
|
|
24
|
+
RulesConfigSchema,
|
|
25
|
+
// Approval config
|
|
26
|
+
NativeApprovalSchema, AgentConfirmSchema, WebhookApprovalSchema, ApprovalConfigSchema,
|
|
27
|
+
// Root config
|
|
28
|
+
ClawsecConfigSchema, } from './schema.js';
|
|
29
|
+
// Defaults
|
|
30
|
+
export { defaultConfig, getDefaultConfig } from './defaults.js';
|
|
31
|
+
// Loader
|
|
32
|
+
export {
|
|
33
|
+
// Error types
|
|
34
|
+
ConfigValidationError, ConfigLoadError,
|
|
35
|
+
// Validation functions
|
|
36
|
+
validateConfig, isValidConfig,
|
|
37
|
+
// Merging functions
|
|
38
|
+
mergeWithDefaults, mergeConfigs,
|
|
39
|
+
// File loading functions
|
|
40
|
+
findConfigFile, loadConfig, loadConfigFromString, } from './loader.js';
|
|
41
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/config/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,mBAAmB;AACnB,OAAO;AACL,QAAQ;AACR,cAAc,EACd,YAAY,EACZ,cAAc,EACd,gBAAgB;AAMhB,gBAAgB;AAChB,kBAAkB;AAElB,aAAa;AACb,eAAe;AAEf,gBAAgB;AAChB,iBAAiB,EACjB,qBAAqB,EACrB,kBAAkB;AAIlB,eAAe;AACf,iBAAiB;AAEjB,mBAAmB;AACnB,qBAAqB,EACrB,qBAAqB,EACrB,oBAAoB,EACpB,qBAAqB;AAKrB,eAAe;AACf,iBAAiB;AAEjB,oBAAoB;AACpB,sBAAsB;AAEtB,eAAe;AACf,iBAAiB;AAEjB,kBAAkB;AAClB,oBAAoB,EACpB,kBAAkB,EAClB,qBAAqB,EACrB,oBAAoB;AAKpB,cAAc;AACd,mBAAmB,GAGpB,MAAM,aAAa,CAAC;AAErB,WAAW;AACX,OAAO,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAEhE,SAAS;AACT,OAAO;AACL,cAAc;AACd,qBAAqB,EACrB,eAAe;AACf,uBAAuB;AACvB,cAAc,EACd,aAAa;AACb,oBAAoB;AACpB,iBAAiB,EACjB,YAAY;AACZ,yBAAyB;AACzB,cAAc,EACd,UAAU,EACV,oBAAoB,GACrB,MAAM,aAAa,CAAC"}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Clawsec Configuration Loader
|
|
3
|
+
* YAML file loading and validation utilities
|
|
4
|
+
*/
|
|
5
|
+
import { z } from 'zod';
|
|
6
|
+
import { type ClawsecConfig, type PartialClawsecConfig } from './schema.js';
|
|
7
|
+
/**
|
|
8
|
+
* Error thrown when configuration validation fails
|
|
9
|
+
*/
|
|
10
|
+
export declare class ConfigValidationError extends Error {
|
|
11
|
+
readonly errors: Array<{
|
|
12
|
+
path: string;
|
|
13
|
+
message: string;
|
|
14
|
+
}>;
|
|
15
|
+
constructor(message: string, errors: Array<{
|
|
16
|
+
path: string;
|
|
17
|
+
message: string;
|
|
18
|
+
}>);
|
|
19
|
+
/**
|
|
20
|
+
* Create a ConfigValidationError from a ZodError
|
|
21
|
+
*/
|
|
22
|
+
static fromZodError(zodError: z.ZodError): ConfigValidationError;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Error thrown when configuration file cannot be loaded
|
|
26
|
+
*/
|
|
27
|
+
export declare class ConfigLoadError extends Error {
|
|
28
|
+
readonly filePath: string;
|
|
29
|
+
readonly cause?: Error | undefined;
|
|
30
|
+
constructor(message: string, filePath: string, cause?: Error | undefined);
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Validates a configuration object using the Zod schema.
|
|
34
|
+
*
|
|
35
|
+
* @param config - Unknown configuration object to validate
|
|
36
|
+
* @returns Validated and typed configuration
|
|
37
|
+
* @throws ConfigValidationError if validation fails
|
|
38
|
+
*/
|
|
39
|
+
export declare function validateConfig(config: unknown): ClawsecConfig;
|
|
40
|
+
/**
|
|
41
|
+
* Checks if a configuration object is valid without throwing.
|
|
42
|
+
*
|
|
43
|
+
* @param config - Unknown configuration object to validate
|
|
44
|
+
* @returns Object with success status and either data or errors
|
|
45
|
+
*/
|
|
46
|
+
export declare function isValidConfig(config: unknown): {
|
|
47
|
+
valid: true;
|
|
48
|
+
config: ClawsecConfig;
|
|
49
|
+
} | {
|
|
50
|
+
valid: false;
|
|
51
|
+
errors: Array<{
|
|
52
|
+
path: string;
|
|
53
|
+
message: string;
|
|
54
|
+
}>;
|
|
55
|
+
};
|
|
56
|
+
/**
|
|
57
|
+
* Deep merges a partial configuration with the default configuration.
|
|
58
|
+
* Partial config values take precedence over defaults.
|
|
59
|
+
*
|
|
60
|
+
* @param partial - Partial configuration object
|
|
61
|
+
* @returns Complete configuration merged with defaults
|
|
62
|
+
*/
|
|
63
|
+
export declare function mergeWithDefaults(partial: PartialClawsecConfig): ClawsecConfig;
|
|
64
|
+
/**
|
|
65
|
+
* Finds a configuration file in the specified directory or its parents.
|
|
66
|
+
*
|
|
67
|
+
* @param startDir - Directory to start searching from
|
|
68
|
+
* @returns Path to found config file, or null if not found
|
|
69
|
+
*/
|
|
70
|
+
export declare function findConfigFile(startDir?: string): string | null;
|
|
71
|
+
/**
|
|
72
|
+
* Loads configuration from a YAML file.
|
|
73
|
+
*
|
|
74
|
+
* If no path is provided, searches for config file in standard locations.
|
|
75
|
+
* If no config file is found, returns default configuration.
|
|
76
|
+
*
|
|
77
|
+
* @param configPath - Optional path to configuration file
|
|
78
|
+
* @returns Validated configuration
|
|
79
|
+
* @throws ConfigLoadError if specified file doesn't exist or can't be parsed
|
|
80
|
+
* @throws ConfigValidationError if configuration is invalid
|
|
81
|
+
*/
|
|
82
|
+
export declare function loadConfig(configPath?: string): ClawsecConfig;
|
|
83
|
+
/**
|
|
84
|
+
* Loads configuration from a YAML string.
|
|
85
|
+
*
|
|
86
|
+
* @param yamlContent - YAML string to parse
|
|
87
|
+
* @returns Validated configuration
|
|
88
|
+
* @throws ConfigValidationError if configuration is invalid
|
|
89
|
+
*/
|
|
90
|
+
export declare function loadConfigFromString(yamlContent: string): ClawsecConfig;
|
|
91
|
+
/**
|
|
92
|
+
* Loads and merges configuration from multiple sources.
|
|
93
|
+
* Later sources override earlier ones.
|
|
94
|
+
*
|
|
95
|
+
* @param sources - Array of config objects to merge
|
|
96
|
+
* @returns Merged and validated configuration
|
|
97
|
+
*/
|
|
98
|
+
export declare function mergeConfigs(...sources: PartialClawsecConfig[]): ClawsecConfig;
|
|
99
|
+
//# sourceMappingURL=loader.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"loader.d.ts","sourceRoot":"","sources":["../../../src/config/loader.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAKH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAuB,KAAK,aAAa,EAAE,KAAK,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAOjG;;GAEG;AACH,qBAAa,qBAAsB,SAAQ,KAAK;aAG5B,MAAM,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC;gBADhE,OAAO,EAAE,MAAM,EACC,MAAM,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC;IAMlE;;OAEG;IACH,MAAM,CAAC,YAAY,CAAC,QAAQ,EAAE,CAAC,CAAC,QAAQ,GAAG,qBAAqB;CAUjE;AAED;;GAEG;AACH,qBAAa,eAAgB,SAAQ,KAAK;aAGtB,QAAQ,EAAE,MAAM;aAChB,KAAK,CAAC,EAAE,KAAK;gBAF7B,OAAO,EAAE,MAAM,EACC,QAAQ,EAAE,MAAM,EAChB,KAAK,CAAC,EAAE,KAAK,YAAA;CAKhC;AAMD;;;;;;GAMG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,OAAO,GAAG,aAAa,CAQ7D;AAED;;;;;GAKG;AACH,wBAAgB,aAAa,CAC3B,MAAM,EAAE,OAAO,GACd;IAAE,KAAK,EAAE,IAAI,CAAC;IAAC,MAAM,EAAE,aAAa,CAAA;CAAE,GAAG;IAAE,KAAK,EAAE,KAAK,CAAC;IAAC,MAAM,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC,CAAA;CAAE,CAc7G;AAMD;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,oBAAoB,GAAG,aAAa,CAI9E;AAiCD;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,QAAQ,GAAE,MAAsB,GAAG,MAAM,GAAG,IAAI,CAuB9E;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,UAAU,CAAC,UAAU,CAAC,EAAE,MAAM,GAAG,aAAa,CA8B7D;AAED;;;;;;GAMG;AACH,wBAAgB,oBAAoB,CAAC,WAAW,EAAE,MAAM,GAAG,aAAa,CASvE;AAED;;;;;;GAMG;AACH,wBAAgB,YAAY,CAAC,GAAG,OAAO,EAAE,oBAAoB,EAAE,GAAG,aAAa,CAQ9E"}
|
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Clawsec Configuration Loader
|
|
3
|
+
* YAML file loading and validation utilities
|
|
4
|
+
*/
|
|
5
|
+
import * as fs from 'node:fs';
|
|
6
|
+
import * as path from 'node:path';
|
|
7
|
+
import { parse as parseYaml } from 'yaml';
|
|
8
|
+
import { ClawsecConfigSchema } from './schema.js';
|
|
9
|
+
import { getDefaultConfig } from './defaults.js';
|
|
10
|
+
// =============================================================================
|
|
11
|
+
// ERROR TYPES
|
|
12
|
+
// =============================================================================
|
|
13
|
+
/**
|
|
14
|
+
* Error thrown when configuration validation fails
|
|
15
|
+
*/
|
|
16
|
+
export class ConfigValidationError extends Error {
|
|
17
|
+
errors;
|
|
18
|
+
constructor(message, errors) {
|
|
19
|
+
super(message);
|
|
20
|
+
this.errors = errors;
|
|
21
|
+
this.name = 'ConfigValidationError';
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Create a ConfigValidationError from a ZodError
|
|
25
|
+
*/
|
|
26
|
+
static fromZodError(zodError) {
|
|
27
|
+
const errors = zodError.issues.map((issue) => ({
|
|
28
|
+
path: issue.path.map(String).join('.'),
|
|
29
|
+
message: issue.message,
|
|
30
|
+
}));
|
|
31
|
+
const message = `Configuration validation failed:\n${errors
|
|
32
|
+
.map((e) => ` - ${e.path || '(root)'}: ${e.message}`)
|
|
33
|
+
.join('\n')}`;
|
|
34
|
+
return new ConfigValidationError(message, errors);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Error thrown when configuration file cannot be loaded
|
|
39
|
+
*/
|
|
40
|
+
export class ConfigLoadError extends Error {
|
|
41
|
+
filePath;
|
|
42
|
+
cause;
|
|
43
|
+
constructor(message, filePath, cause) {
|
|
44
|
+
super(message);
|
|
45
|
+
this.filePath = filePath;
|
|
46
|
+
this.cause = cause;
|
|
47
|
+
this.name = 'ConfigLoadError';
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
// =============================================================================
|
|
51
|
+
// VALIDATION
|
|
52
|
+
// =============================================================================
|
|
53
|
+
/**
|
|
54
|
+
* Validates a configuration object using the Zod schema.
|
|
55
|
+
*
|
|
56
|
+
* @param config - Unknown configuration object to validate
|
|
57
|
+
* @returns Validated and typed configuration
|
|
58
|
+
* @throws ConfigValidationError if validation fails
|
|
59
|
+
*/
|
|
60
|
+
export function validateConfig(config) {
|
|
61
|
+
const result = ClawsecConfigSchema.safeParse(config);
|
|
62
|
+
if (!result.success) {
|
|
63
|
+
throw ConfigValidationError.fromZodError(result.error);
|
|
64
|
+
}
|
|
65
|
+
return result.data;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Checks if a configuration object is valid without throwing.
|
|
69
|
+
*
|
|
70
|
+
* @param config - Unknown configuration object to validate
|
|
71
|
+
* @returns Object with success status and either data or errors
|
|
72
|
+
*/
|
|
73
|
+
export function isValidConfig(config) {
|
|
74
|
+
const result = ClawsecConfigSchema.safeParse(config);
|
|
75
|
+
if (result.success) {
|
|
76
|
+
return { valid: true, config: result.data };
|
|
77
|
+
}
|
|
78
|
+
return {
|
|
79
|
+
valid: false,
|
|
80
|
+
errors: result.error.issues.map((issue) => ({
|
|
81
|
+
path: issue.path.map(String).join('.'),
|
|
82
|
+
message: issue.message,
|
|
83
|
+
})),
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
// =============================================================================
|
|
87
|
+
// MERGING
|
|
88
|
+
// =============================================================================
|
|
89
|
+
/**
|
|
90
|
+
* Deep merges a partial configuration with the default configuration.
|
|
91
|
+
* Partial config values take precedence over defaults.
|
|
92
|
+
*
|
|
93
|
+
* @param partial - Partial configuration object
|
|
94
|
+
* @returns Complete configuration merged with defaults
|
|
95
|
+
*/
|
|
96
|
+
export function mergeWithDefaults(partial) {
|
|
97
|
+
// Zod's parse with defaults handles the merging for us
|
|
98
|
+
// by applying defaults for any missing fields
|
|
99
|
+
return validateConfig(partial);
|
|
100
|
+
}
|
|
101
|
+
// =============================================================================
|
|
102
|
+
// FILE LOADING
|
|
103
|
+
// =============================================================================
|
|
104
|
+
/**
|
|
105
|
+
* Standard config file names to look for
|
|
106
|
+
*/
|
|
107
|
+
const CONFIG_FILE_NAMES = ['clawsec.yaml', 'clawsec.yml', '.clawsec.yaml', '.clawsec.yml'];
|
|
108
|
+
/**
|
|
109
|
+
* Reads and parses a YAML configuration file.
|
|
110
|
+
*
|
|
111
|
+
* @param filePath - Path to the YAML file
|
|
112
|
+
* @returns Parsed YAML content as unknown
|
|
113
|
+
* @throws ConfigLoadError if file cannot be read or parsed
|
|
114
|
+
*/
|
|
115
|
+
function readYamlFile(filePath) {
|
|
116
|
+
try {
|
|
117
|
+
const content = fs.readFileSync(filePath, 'utf-8');
|
|
118
|
+
return parseYaml(content);
|
|
119
|
+
}
|
|
120
|
+
catch (error) {
|
|
121
|
+
if (error instanceof Error && 'code' in error && error.code === 'ENOENT') {
|
|
122
|
+
throw new ConfigLoadError(`Configuration file not found: ${filePath}`, filePath, error);
|
|
123
|
+
}
|
|
124
|
+
if (error instanceof Error) {
|
|
125
|
+
throw new ConfigLoadError(`Failed to parse YAML file: ${error.message}`, filePath, error);
|
|
126
|
+
}
|
|
127
|
+
throw new ConfigLoadError(`Failed to read configuration file`, filePath);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Finds a configuration file in the specified directory or its parents.
|
|
132
|
+
*
|
|
133
|
+
* @param startDir - Directory to start searching from
|
|
134
|
+
* @returns Path to found config file, or null if not found
|
|
135
|
+
*/
|
|
136
|
+
export function findConfigFile(startDir = process.cwd()) {
|
|
137
|
+
let currentDir = path.resolve(startDir);
|
|
138
|
+
const root = path.parse(currentDir).root;
|
|
139
|
+
while (currentDir !== root) {
|
|
140
|
+
for (const fileName of CONFIG_FILE_NAMES) {
|
|
141
|
+
const filePath = path.join(currentDir, fileName);
|
|
142
|
+
if (fs.existsSync(filePath)) {
|
|
143
|
+
return filePath;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
currentDir = path.dirname(currentDir);
|
|
147
|
+
}
|
|
148
|
+
// Check root directory as well
|
|
149
|
+
for (const fileName of CONFIG_FILE_NAMES) {
|
|
150
|
+
const filePath = path.join(root, fileName);
|
|
151
|
+
if (fs.existsSync(filePath)) {
|
|
152
|
+
return filePath;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
return null;
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Loads configuration from a YAML file.
|
|
159
|
+
*
|
|
160
|
+
* If no path is provided, searches for config file in standard locations.
|
|
161
|
+
* If no config file is found, returns default configuration.
|
|
162
|
+
*
|
|
163
|
+
* @param configPath - Optional path to configuration file
|
|
164
|
+
* @returns Validated configuration
|
|
165
|
+
* @throws ConfigLoadError if specified file doesn't exist or can't be parsed
|
|
166
|
+
* @throws ConfigValidationError if configuration is invalid
|
|
167
|
+
*/
|
|
168
|
+
export function loadConfig(configPath) {
|
|
169
|
+
// If explicit path provided, load from that path
|
|
170
|
+
if (configPath) {
|
|
171
|
+
const resolvedPath = path.resolve(configPath);
|
|
172
|
+
const content = readYamlFile(resolvedPath);
|
|
173
|
+
// Handle empty file case
|
|
174
|
+
if (content === null || content === undefined) {
|
|
175
|
+
return getDefaultConfig();
|
|
176
|
+
}
|
|
177
|
+
return validateConfig(content);
|
|
178
|
+
}
|
|
179
|
+
// Try to find config file
|
|
180
|
+
const foundPath = findConfigFile();
|
|
181
|
+
if (foundPath) {
|
|
182
|
+
const content = readYamlFile(foundPath);
|
|
183
|
+
// Handle empty file case
|
|
184
|
+
if (content === null || content === undefined) {
|
|
185
|
+
return getDefaultConfig();
|
|
186
|
+
}
|
|
187
|
+
return validateConfig(content);
|
|
188
|
+
}
|
|
189
|
+
// No config file found, return defaults
|
|
190
|
+
return getDefaultConfig();
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* Loads configuration from a YAML string.
|
|
194
|
+
*
|
|
195
|
+
* @param yamlContent - YAML string to parse
|
|
196
|
+
* @returns Validated configuration
|
|
197
|
+
* @throws ConfigValidationError if configuration is invalid
|
|
198
|
+
*/
|
|
199
|
+
export function loadConfigFromString(yamlContent) {
|
|
200
|
+
const content = parseYaml(yamlContent);
|
|
201
|
+
// Handle empty content
|
|
202
|
+
if (content === null || content === undefined) {
|
|
203
|
+
return getDefaultConfig();
|
|
204
|
+
}
|
|
205
|
+
return validateConfig(content);
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* Loads and merges configuration from multiple sources.
|
|
209
|
+
* Later sources override earlier ones.
|
|
210
|
+
*
|
|
211
|
+
* @param sources - Array of config objects to merge
|
|
212
|
+
* @returns Merged and validated configuration
|
|
213
|
+
*/
|
|
214
|
+
export function mergeConfigs(...sources) {
|
|
215
|
+
// Start with an empty object and deep merge all sources
|
|
216
|
+
const merged = sources.reduce((acc, source) => deepMerge(acc, source), {});
|
|
217
|
+
return validateConfig(merged);
|
|
218
|
+
}
|
|
219
|
+
/**
|
|
220
|
+
* Deep merges two objects. Source values override target values.
|
|
221
|
+
*/
|
|
222
|
+
function deepMerge(target, source) {
|
|
223
|
+
const result = { ...target };
|
|
224
|
+
for (const key of Object.keys(source)) {
|
|
225
|
+
const sourceValue = source[key];
|
|
226
|
+
const targetValue = result[key];
|
|
227
|
+
if (isPlainObject(sourceValue) && isPlainObject(targetValue)) {
|
|
228
|
+
result[key] = deepMerge(targetValue, sourceValue);
|
|
229
|
+
}
|
|
230
|
+
else if (sourceValue !== undefined) {
|
|
231
|
+
result[key] = sourceValue;
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
return result;
|
|
235
|
+
}
|
|
236
|
+
/**
|
|
237
|
+
* Checks if a value is a plain object (not an array, null, or other type)
|
|
238
|
+
*/
|
|
239
|
+
function isPlainObject(value) {
|
|
240
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
241
|
+
}
|
|
242
|
+
//# sourceMappingURL=loader.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"loader.js","sourceRoot":"","sources":["../../../src/config/loader.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAC9B,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAClC,OAAO,EAAE,KAAK,IAAI,SAAS,EAAE,MAAM,MAAM,CAAC;AAE1C,OAAO,EAAE,mB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