clawsec 0.0.1 → 0.0.2

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.
Files changed (146) hide show
  1. package/dist/src/actions/block.js +2 -2
  2. package/dist/src/actions/block.js.map +1 -1
  3. package/dist/src/actions/confirm.d.ts +1 -1
  4. package/dist/src/actions/confirm.d.ts.map +1 -1
  5. package/dist/src/actions/confirm.js +57 -26
  6. package/dist/src/actions/confirm.js.map +1 -1
  7. package/dist/src/actions/executor.d.ts +3 -1
  8. package/dist/src/actions/executor.d.ts.map +1 -1
  9. package/dist/src/actions/executor.js +48 -11
  10. package/dist/src/actions/executor.js.map +1 -1
  11. package/dist/src/actions/warn.js +2 -2
  12. package/dist/src/actions/warn.js.map +1 -1
  13. package/dist/src/approval/agent-confirm.d.ts +4 -0
  14. package/dist/src/approval/agent-confirm.d.ts.map +1 -1
  15. package/dist/src/approval/agent-confirm.js +14 -0
  16. package/dist/src/approval/agent-confirm.js.map +1 -1
  17. package/dist/src/approval/store.d.ts +4 -0
  18. package/dist/src/approval/store.d.ts.map +1 -1
  19. package/dist/src/approval/store.js +19 -0
  20. package/dist/src/approval/store.js.map +1 -1
  21. package/dist/src/config/loader.d.ts +7 -4
  22. package/dist/src/config/loader.d.ts.map +1 -1
  23. package/dist/src/config/loader.js +58 -27
  24. package/dist/src/config/loader.js.map +1 -1
  25. package/dist/src/config/schema.d.ts +60 -41
  26. package/dist/src/config/schema.d.ts.map +1 -1
  27. package/dist/src/config/schema.js +12 -0
  28. package/dist/src/config/schema.js.map +1 -1
  29. package/dist/src/config/template-loader.d.ts +34 -0
  30. package/dist/src/config/template-loader.d.ts.map +1 -0
  31. package/dist/src/config/template-loader.js +127 -0
  32. package/dist/src/config/template-loader.js.map +1 -0
  33. package/dist/src/detectors/destructive/cloud-detector.d.ts +10 -3
  34. package/dist/src/detectors/destructive/cloud-detector.d.ts.map +1 -1
  35. package/dist/src/detectors/destructive/cloud-detector.js +45 -5
  36. package/dist/src/detectors/destructive/cloud-detector.js.map +1 -1
  37. package/dist/src/detectors/destructive/code-detector.d.ts +9 -2
  38. package/dist/src/detectors/destructive/code-detector.d.ts.map +1 -1
  39. package/dist/src/detectors/destructive/code-detector.js +43 -4
  40. package/dist/src/detectors/destructive/code-detector.js.map +1 -1
  41. package/dist/src/detectors/destructive/index.d.ts +5 -3
  42. package/dist/src/detectors/destructive/index.d.ts.map +1 -1
  43. package/dist/src/detectors/destructive/index.js +42 -10
  44. package/dist/src/detectors/destructive/index.js.map +1 -1
  45. package/dist/src/detectors/destructive/shell-detector.d.ts +10 -3
  46. package/dist/src/detectors/destructive/shell-detector.d.ts.map +1 -1
  47. package/dist/src/detectors/destructive/shell-detector.js +44 -5
  48. package/dist/src/detectors/destructive/shell-detector.js.map +1 -1
  49. package/dist/src/detectors/destructive/types.d.ts +6 -0
  50. package/dist/src/detectors/destructive/types.d.ts.map +1 -1
  51. package/dist/src/detectors/exfiltration/cloud-detector.d.ts +3 -2
  52. package/dist/src/detectors/exfiltration/cloud-detector.d.ts.map +1 -1
  53. package/dist/src/detectors/exfiltration/cloud-detector.js +21 -3
  54. package/dist/src/detectors/exfiltration/cloud-detector.js.map +1 -1
  55. package/dist/src/detectors/exfiltration/http-detector.d.ts +3 -2
  56. package/dist/src/detectors/exfiltration/http-detector.d.ts.map +1 -1
  57. package/dist/src/detectors/exfiltration/http-detector.js +21 -3
  58. package/dist/src/detectors/exfiltration/http-detector.js.map +1 -1
  59. package/dist/src/detectors/exfiltration/index.d.ts +5 -3
  60. package/dist/src/detectors/exfiltration/index.d.ts.map +1 -1
  61. package/dist/src/detectors/exfiltration/index.js +44 -11
  62. package/dist/src/detectors/exfiltration/index.js.map +1 -1
  63. package/dist/src/detectors/exfiltration/network-detector.d.ts +3 -2
  64. package/dist/src/detectors/exfiltration/network-detector.d.ts.map +1 -1
  65. package/dist/src/detectors/exfiltration/network-detector.js +26 -8
  66. package/dist/src/detectors/exfiltration/network-detector.js.map +1 -1
  67. package/dist/src/detectors/exfiltration/types.d.ts +2 -0
  68. package/dist/src/detectors/exfiltration/types.d.ts.map +1 -1
  69. package/dist/src/detectors/purchase/domain-detector.d.ts +1 -1
  70. package/dist/src/detectors/purchase/domain-detector.d.ts.map +1 -1
  71. package/dist/src/detectors/purchase/domain-detector.js +1 -1
  72. package/dist/src/detectors/purchase/domain-detector.js.map +1 -1
  73. package/dist/src/detectors/purchase/form-detector.d.ts +2 -2
  74. package/dist/src/detectors/purchase/form-detector.d.ts.map +1 -1
  75. package/dist/src/detectors/purchase/form-detector.js +7 -4
  76. package/dist/src/detectors/purchase/form-detector.js.map +1 -1
  77. package/dist/src/detectors/purchase/index.d.ts +5 -3
  78. package/dist/src/detectors/purchase/index.d.ts.map +1 -1
  79. package/dist/src/detectors/purchase/index.js +35 -6
  80. package/dist/src/detectors/purchase/index.js.map +1 -1
  81. package/dist/src/detectors/purchase/spend-tracker.d.ts +6 -2
  82. package/dist/src/detectors/purchase/spend-tracker.d.ts.map +1 -1
  83. package/dist/src/detectors/purchase/spend-tracker.js +19 -3
  84. package/dist/src/detectors/purchase/spend-tracker.js.map +1 -1
  85. package/dist/src/detectors/purchase/url-detector.d.ts +2 -2
  86. package/dist/src/detectors/purchase/url-detector.d.ts.map +1 -1
  87. package/dist/src/detectors/purchase/url-detector.js +3 -3
  88. package/dist/src/detectors/purchase/url-detector.js.map +1 -1
  89. package/dist/src/detectors/secrets/api-key-detector.d.ts +6 -6
  90. package/dist/src/detectors/secrets/api-key-detector.d.ts.map +1 -1
  91. package/dist/src/detectors/secrets/api-key-detector.js +33 -7
  92. package/dist/src/detectors/secrets/api-key-detector.js.map +1 -1
  93. package/dist/src/detectors/secrets/index.d.ts +5 -3
  94. package/dist/src/detectors/secrets/index.d.ts.map +1 -1
  95. package/dist/src/detectors/secrets/index.js +52 -11
  96. package/dist/src/detectors/secrets/index.js.map +1 -1
  97. package/dist/src/detectors/secrets/pii-detector.d.ts +2 -2
  98. package/dist/src/detectors/secrets/pii-detector.d.ts.map +1 -1
  99. package/dist/src/detectors/secrets/pii-detector.js +3 -3
  100. package/dist/src/detectors/secrets/pii-detector.js.map +1 -1
  101. package/dist/src/detectors/secrets/token-detector.d.ts +2 -2
  102. package/dist/src/detectors/secrets/token-detector.d.ts.map +1 -1
  103. package/dist/src/detectors/secrets/token-detector.js +3 -3
  104. package/dist/src/detectors/secrets/token-detector.js.map +1 -1
  105. package/dist/src/detectors/secrets/types.d.ts +5 -3
  106. package/dist/src/detectors/secrets/types.d.ts.map +1 -1
  107. package/dist/src/detectors/website/index.d.ts +5 -3
  108. package/dist/src/detectors/website/index.d.ts.map +1 -1
  109. package/dist/src/detectors/website/index.js +21 -6
  110. package/dist/src/detectors/website/index.js.map +1 -1
  111. package/dist/src/engine/analyzer.d.ts +3 -1
  112. package/dist/src/engine/analyzer.d.ts.map +1 -1
  113. package/dist/src/engine/analyzer.js +66 -10
  114. package/dist/src/engine/analyzer.js.map +1 -1
  115. package/dist/src/engine/types.d.ts +4 -1
  116. package/dist/src/engine/types.d.ts.map +1 -1
  117. package/dist/src/engine/types.js.map +1 -1
  118. package/dist/src/hooks/before-agent-start/handler.d.ts +3 -1
  119. package/dist/src/hooks/before-agent-start/handler.d.ts.map +1 -1
  120. package/dist/src/hooks/before-agent-start/handler.js +59 -12
  121. package/dist/src/hooks/before-agent-start/handler.js.map +1 -1
  122. package/dist/src/hooks/before-tool-call/handler.d.ts +3 -1
  123. package/dist/src/hooks/before-tool-call/handler.d.ts.map +1 -1
  124. package/dist/src/hooks/before-tool-call/handler.js +86 -54
  125. package/dist/src/hooks/before-tool-call/handler.js.map +1 -1
  126. package/dist/src/hooks/tool-result-persist/handler.d.ts +3 -1
  127. package/dist/src/hooks/tool-result-persist/handler.d.ts.map +1 -1
  128. package/dist/src/hooks/tool-result-persist/handler.js +36 -34
  129. package/dist/src/hooks/tool-result-persist/handler.js.map +1 -1
  130. package/dist/src/index.d.ts +45 -47
  131. package/dist/src/index.d.ts.map +1 -1
  132. package/dist/src/index.js +120 -96
  133. package/dist/src/index.js.map +1 -1
  134. package/dist/src/notifications/index.d.ts.map +1 -1
  135. package/dist/src/notifications/index.js +2 -1
  136. package/dist/src/notifications/index.js.map +1 -1
  137. package/dist/src/notifications/telegram.js +1 -1
  138. package/dist/src/notifications/telegram.js.map +1 -1
  139. package/dist/src/notifications/types.d.ts +1 -1
  140. package/dist/src/notifications/types.d.ts.map +1 -1
  141. package/dist/src/utils/logger.d.ts +26 -0
  142. package/dist/src/utils/logger.d.ts.map +1 -0
  143. package/dist/src/utils/logger.js +76 -0
  144. package/dist/src/utils/logger.js.map +1 -0
  145. package/openclaw.plugin.json +7 -22
  146. package/package.json +8 -2
@@ -8,28 +8,30 @@ import { createAnalyzer } from '../../engine/analyzer.js';
8
8
  import { createActionExecutor } from '../../actions/executor.js';
9
9
  import { createAgentConfirmHandler } from '../../approval/agent-confirm.js';
10
10
  import { getDefaultApprovalStore } from '../../approval/store.js';
11
+ import { createLogger } from '../../utils/logger.js';
11
12
  /**
12
13
  * Convert hook ToolCallContext to engine ToolCallContext
13
14
  * The engine context has a slightly different shape
14
15
  */
15
16
  function toEngineContext(hookContext) {
17
+ const toolInput = hookContext.toolInput || {};
16
18
  return {
17
19
  toolName: hookContext.toolName,
18
- toolInput: hookContext.toolInput,
20
+ toolInput,
19
21
  // url can be extracted from toolInput if present
20
- url: typeof hookContext.toolInput.url === 'string' ? hookContext.toolInput.url : undefined,
22
+ url: typeof toolInput.url === 'string' ? toolInput.url : undefined,
21
23
  };
22
24
  }
23
25
  /**
24
- * Convert analysis result and action result to BeforeToolCallResult
26
+ * Convert analysis result and action result to BeforeToolCallResult (modern API)
25
27
  */
26
28
  function toBeforeToolCallResult(actionResult, detection) {
27
29
  const result = {
28
- allow: actionResult.allowed,
30
+ block: !actionResult.allowed, // Inverted: !allow = block
29
31
  };
30
- // Add block message if not allowed
32
+ // Add block reason if blocked
31
33
  if (!actionResult.allowed && actionResult.message) {
32
- result.blockMessage = actionResult.message;
34
+ result.blockReason = actionResult.message;
33
35
  }
34
36
  // Add metadata from primary detection
35
37
  if (detection) {
@@ -43,48 +45,48 @@ function toBeforeToolCallResult(actionResult, detection) {
43
45
  result.metadata.rule = detection.metadata.rule;
44
46
  }
45
47
  }
46
- // Add pending approval instructions to block message if present
48
+ // Add pending approval instructions to block reason if present
47
49
  if (actionResult.pendingApproval) {
48
50
  const approvalInfo = `\n\nApproval ID: ${actionResult.pendingApproval.id}\nTimeout: ${actionResult.pendingApproval.timeout}s\nMethods: ${actionResult.pendingApproval.methods.join(', ')}`;
49
- result.blockMessage = (result.blockMessage || 'Approval required') + approvalInfo;
51
+ result.blockReason = (result.blockReason || 'Approval required') + approvalInfo;
50
52
  }
51
53
  return result;
52
54
  }
53
55
  /**
54
- * Create the allow result for when no threats are detected
56
+ * Create the allow result for when no threats are detected (modern API)
55
57
  */
56
58
  function createAllowResult() {
57
59
  return {
58
- allow: true,
60
+ block: false, // Modern: explicit false means allow
59
61
  };
60
62
  }
61
63
  /**
62
- * Create a result for valid agent-confirm flow
64
+ * Create a result for valid agent-confirm flow (modern API)
63
65
  */
64
66
  function createAgentConfirmAllowResult(strippedInput) {
65
67
  return {
66
- allow: true,
67
- modifiedInput: strippedInput,
68
+ block: false,
69
+ params: strippedInput, // Modern: renamed from modifiedInput
68
70
  };
69
71
  }
70
72
  /**
71
- * Create a result for invalid agent-confirm flow
73
+ * Create a result for invalid agent-confirm flow (modern API)
72
74
  */
73
75
  function createAgentConfirmInvalidResult(error) {
74
76
  return {
75
- allow: false,
76
- blockMessage: error || 'Invalid or expired approval confirmation',
77
+ block: true, // Modern: true = block
78
+ blockReason: error || 'Invalid or expired approval confirmation',
77
79
  metadata: {
78
80
  reason: 'Agent confirmation parameter was present but invalid',
79
81
  },
80
82
  };
81
83
  }
82
84
  /**
83
- * Create a result for disabled plugin
85
+ * Create a result for disabled plugin (modern API)
84
86
  */
85
87
  function createDisabledResult() {
86
88
  return {
87
- allow: true,
89
+ block: false,
88
90
  };
89
91
  }
90
92
  /**
@@ -99,58 +101,88 @@ function createDisabledResult() {
99
101
  *
100
102
  * @param config - Clawsec configuration
101
103
  * @param options - Optional custom components
104
+ * @param logger - Optional logger instance
102
105
  * @returns BeforeToolCallHandler function
103
106
  */
104
- export function createBeforeToolCallHandler(config, options) {
107
+ export function createBeforeToolCallHandler(config, options, logger) {
108
+ const log = logger ?? createLogger(null, null);
105
109
  // Create or use provided components
106
- const analyzer = options?.analyzer ?? createAnalyzer(config);
107
- const executor = options?.executor ?? createActionExecutor();
110
+ const analyzer = options?.analyzer ?? createAnalyzer(config, undefined, log);
111
+ const executor = options?.executor ?? createActionExecutor({ logger: log });
108
112
  const agentConfirm = options?.agentConfirm ??
109
113
  createAgentConfirmHandler({
110
114
  enabled: config.approval?.agentConfirm?.enabled ?? true,
111
115
  parameterName: config.approval?.agentConfirm?.parameterName,
112
116
  store: getDefaultApprovalStore(),
117
+ logger: log,
113
118
  });
114
119
  // Get the parameter name from config
115
120
  const confirmParamName = config.approval?.agentConfirm?.parameterName ?? '_clawsec_confirm';
116
121
  return async (context) => {
117
- // 1. Check if plugin is disabled
118
- if (config.global?.enabled === false) {
119
- return createDisabledResult();
120
- }
121
- // 2. Check for agent-confirm parameter
122
- if (config.approval?.agentConfirm?.enabled !== false) {
123
- const confirmResult = agentConfirm.checkConfirmation(context.toolInput, confirmParamName);
124
- if (confirmResult.confirmed) {
125
- // Agent is trying to confirm a previous action
126
- const processResult = agentConfirm.processConfirmation(context.toolInput, confirmParamName);
127
- if (processResult.valid) {
128
- // Valid confirmation - strip the parameter and allow
129
- const strippedInput = agentConfirm.stripConfirmParameter(context.toolInput, confirmParamName);
130
- return createAgentConfirmAllowResult(strippedInput);
131
- }
132
- else {
133
- // Invalid confirmation - block
134
- return createAgentConfirmInvalidResult(processResult.error);
122
+ try {
123
+ // Normalize context: OpenClaw may send 'params' instead of 'toolInput'
124
+ // Support both field names for backward compatibility
125
+ const normalizedContext = {
126
+ ...context,
127
+ toolInput: context.toolInput || context.params || {},
128
+ };
129
+ const toolName = normalizedContext.toolName;
130
+ log.info(`[Hook:before-tool-call] Entry: tool=${toolName}`);
131
+ // Validate context (using normalized version)
132
+ if (!normalizedContext || !normalizedContext.toolName || !normalizedContext.toolInput) {
133
+ log.error(`[Hook:before-tool-call] Invalid context received`, context);
134
+ return createAllowResult(); // Fail-open for invalid context
135
+ }
136
+ // 1. Check if plugin is disabled
137
+ if (config.global?.enabled === false) {
138
+ log.info(`[Hook:before-tool-call] Plugin disabled, allowing tool`);
139
+ return createDisabledResult();
140
+ }
141
+ // 2. Check for agent-confirm parameter
142
+ if (config.approval?.agentConfirm?.enabled !== false) {
143
+ const confirmResult = agentConfirm.checkConfirmation(normalizedContext.toolInput, confirmParamName);
144
+ if (confirmResult.confirmed) {
145
+ // Agent is trying to confirm a previous action
146
+ const processResult = agentConfirm.processConfirmation(normalizedContext.toolInput, confirmParamName);
147
+ if (processResult.valid) {
148
+ // Valid confirmation - strip the parameter and allow
149
+ const strippedInput = agentConfirm.stripConfirmParameter(normalizedContext.toolInput, confirmParamName);
150
+ log.info(`[Hook:before-tool-call] Exit: tool=${toolName}, result=allow (agent-confirm validated)`);
151
+ return createAgentConfirmAllowResult(strippedInput);
152
+ }
153
+ else {
154
+ // Invalid confirmation - block
155
+ log.warn(`[Hook:before-tool-call] Exit: tool=${toolName}, result=block (invalid agent-confirm)`);
156
+ return createAgentConfirmInvalidResult(processResult.error);
157
+ }
135
158
  }
136
159
  }
160
+ // 3. Run the analyzer (using normalized context)
161
+ const engineContext = toEngineContext(normalizedContext);
162
+ const analysis = await analyzer.analyze(engineContext);
163
+ // 4. If no detections or action is allow/log/warn, handle appropriately
164
+ if (analysis.action === 'allow') {
165
+ log.debug(`[Hook:before-tool-call] Exit: tool=${toolName}, result=allow`);
166
+ return createAllowResult();
167
+ }
168
+ // 5. Execute the action
169
+ const actionContext = {
170
+ analysis,
171
+ toolCall: engineContext,
172
+ config,
173
+ };
174
+ const actionResult = await executor.execute(actionContext);
175
+ // 6. Convert to BeforeToolCallResult
176
+ const result = toBeforeToolCallResult(actionResult, analysis.primaryDetection);
177
+ log.info(`[Hook:before-tool-call] Exit: tool=${toolName}, result=${result.block ? 'block' : 'allow'}`);
178
+ return result;
137
179
  }
138
- // 3. Run the analyzer
139
- const engineContext = toEngineContext(context);
140
- const analysis = await analyzer.analyze(engineContext);
141
- // 4. If no detections or action is allow/log/warn, handle appropriately
142
- if (analysis.action === 'allow') {
143
- return createAllowResult();
180
+ catch (error) {
181
+ // Error handling: log and fail-open (allow the action)
182
+ const errorMessage = error instanceof Error ? error.message : String(error);
183
+ log.error(`[Hook:before-tool-call] Unhandled error: ${errorMessage}`, error);
184
+ return createAllowResult(); // Fail-open on errors
144
185
  }
145
- // 5. Execute the action
146
- const actionContext = {
147
- analysis,
148
- toolCall: engineContext,
149
- config,
150
- };
151
- const actionResult = await executor.execute(actionContext);
152
- // 6. Convert to BeforeToolCallResult
153
- return toBeforeToolCallResult(actionResult, analysis.primaryDetection);
154
186
  };
155
187
  }
156
188
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"handler.js","sourceRoot":"","sources":["../../../../src/hooks/before-tool-call/handler.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAiBH,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAC1D,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AACjE,OAAO,EAAE,yBAAyB,EAAE,MAAM,iCAAiC,CAAC;AAC5E,OAAO,EAAE,uBAAuB,EAAE,MAAM,yBAAyB,CAAC;AAclE;;;GAGG;AACH,SAAS,eAAe,CAAC,WAAgC;IACvD,OAAO;QACL,QAAQ,EAAE,WAAW,CAAC,QAAQ;QAC9B,SAAS,EAAE,WAAW,CAAC,SAAS;QAChC,iDAAiD;QACjD,GAAG,EAAE,OAAO,WAAW,CAAC,SAAS,CAAC,GAAG,KAAK,QAAQ,CAAC,CAAC,CAAC,WAAW,CAAC,SAAS,C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ChB;YACD,YAAY,EAAE;gBACZ,OAAO,EAAE,IAAI;gBACb,QAAQ,EAAE,MAAM;gBAChB,MAAM,EAAE,OAAO;gBACf,aAAa,EAAE,GAAG;gBAClB,aAAa,EAAE,KAAK;gBACpB,UAAU,EAAE;oBACV,mBAAmB,EAAE,IAAI;oBACzB,UAAU,EAAE,IAAI;oBAChB,SAAS,EAAE,IAAI;oBACf,cAAc,EAAE,IAAI;iBACrB;aACF;SACF;QACD,QAAQ,EAAE;YACR,MAAM,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,EAAE;YACvC,YAAY,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,aAAa,EAAE,kBAAkB,EAAE;YAClE,OAAO,EAAE,EAAE,OAAO,EAAE,KAAK,EAAE,GAAG,EAAE,SAAS,EAAE,OAAO,EAAE,EAAE,EAAE,OAAO,EAAE,EAAE,EAAE;SACtE;KACF,CAAC;IAEF,OAAO,2BAA2B,CAAC,aAAa,CAAC,CAAC;AACpD,CAAC"}
@@ -6,6 +6,7 @@
6
6
  */
7
7
  import type { ToolResultPersistHandler } from '../../index.js';
8
8
  import type { ClawsecConfig } from '../../config/schema.js';
9
+ import { type Logger } from '../../utils/logger.js';
9
10
  /**
10
11
  * Options for creating a tool-result-persist handler
11
12
  */
@@ -39,9 +40,10 @@ export interface ToolResultPersistHandlerOptions {
39
40
  *
40
41
  * @param config - Clawsec configuration
41
42
  * @param options - Optional handler options
43
+ * @param logger - Optional logger instance
42
44
  * @returns ToolResultPersistHandler function
43
45
  */
44
- export declare function createToolResultPersistHandler(config: ClawsecConfig, options?: ToolResultPersistHandlerOptions): ToolResultPersistHandler;
46
+ export declare function createToolResultPersistHandler(config: ClawsecConfig, options?: ToolResultPersistHandlerOptions, logger?: Logger): ToolResultPersistHandler;
45
47
  /**
46
48
  * Create a default tool-result-persist handler with default configuration
47
49
  */
@@ -1 +1 @@
1
- {"version":3,"file":"handler.d.ts","sourceRoot":"","sources":["../../../../src/hooks/tool-result-persist/handler.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAGV,wBAAwB,EACzB,MAAM,gBAAgB,CAAC;AACxB,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAO5D;;GAEG;AACH,MAAM,WAAW,+BAA+B;IAC9C;;;OAGG;IACH,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB;;;OAGG;IACH,cAAc,CAAC,EAAE,OAAO,CAAC;CAC1B;AAkDD;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,8BAA8B,CAC5C,MAAM,EAAE,aAAa,EACrB,OAAO,CAAC,EAAE,+BAA+B,GACxC,wBAAwB,CA6F1B;AAED;;GAEG;AACH,wBAAgB,qCAAqC,IAAI,wBAAwB,CAmEhF"}
1
+ {"version":3,"file":"handler.d.ts","sourceRoot":"","sources":["../../../../src/hooks/tool-result-persist/handler.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAGV,wBAAwB,EACzB,MAAM,gBAAgB,CAAC;AACxB,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAK5D,OAAO,EAAgB,KAAK,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAElE;;GAEG;AACH,MAAM,WAAW,+BAA+B;IAC9C;;;OAGG;IACH,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB;;;OAGG;IACH,cAAc,CAAC,EAAE,OAAO,CAAC;CAC1B;AAqDD;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,8BAA8B,CAC5C,MAAM,EAAE,aAAa,EACrB,OAAO,CAAC,EAAE,+BAA+B,EACzC,MAAM,CAAC,EAAE,MAAM,GACd,wBAAwB,CA8F1B;AAED;;GAEG;AACH,wBAAgB,qCAAqC,IAAI,wBAAwB,CAmEhF"}
@@ -4,34 +4,37 @@
4
4
  * Hook handler that scans tool outputs for secrets/PII, prompt injections,
5
5
  * and filters sensitive data before it's persisted.
6
6
  */
7
- import { createSecretsDetector } from '../../detectors/secrets/index.js';
8
7
  import { scan, sanitize } from '../../sanitization/scanner.js';
9
8
  import { filterOutput } from './filter.js';
9
+ import { createLogger } from '../../utils/logger.js';
10
10
  /**
11
- * Create an allow result with no filtering
11
+ * Create an allow result with no filtering (modern API)
12
12
  */
13
13
  function createAllowResult() {
14
- return {
15
- allow: true,
16
- };
14
+ return {}; // Modern API: empty object means no changes (allow)
17
15
  }
18
16
  /**
19
- * Create a block result for detected prompt injections
17
+ * Create a block result for detected prompt injections (modern API)
18
+ * Note: Modern API doesn't support blocking, only filtering.
19
+ * We'll return empty message with redactions metadata.
20
20
  */
21
21
  function createBlockResult(redactions) {
22
22
  return {
23
- allow: false,
24
- redactions,
23
+ message: {
24
+ content: '[BLOCKED: Content violated security policy]',
25
+ redactions,
26
+ },
25
27
  };
26
28
  }
27
29
  /**
28
- * Create a result with filtered output and redaction info
30
+ * Create a result with filtered output and redaction info (modern API)
29
31
  */
30
32
  function createFilteredResult(filteredOutput, redactions) {
31
33
  return {
32
- allow: true,
33
- filteredOutput,
34
- redactions,
34
+ message: {
35
+ content: filteredOutput,
36
+ redactions,
37
+ },
35
38
  };
36
39
  }
37
40
  /**
@@ -64,17 +67,15 @@ function outputToString(output) {
64
67
  *
65
68
  * @param config - Clawsec configuration
66
69
  * @param options - Optional handler options
70
+ * @param logger - Optional logger instance
67
71
  * @returns ToolResultPersistHandler function
68
72
  */
69
- export function createToolResultPersistHandler(config, options) {
73
+ export function createToolResultPersistHandler(config, options, logger) {
74
+ const log = logger ?? createLogger(null, null);
70
75
  const filterEnabled = options?.filter ?? true;
71
76
  const scanInjectionsEnabled = options?.scanInjections ?? true;
72
- // Create secrets detector from config
73
- const secretsDetector = createSecretsDetector({
74
- enabled: config.rules?.secrets?.enabled ?? true,
75
- severity: config.rules?.secrets?.severity ?? 'critical',
76
- action: config.rules?.secrets?.action ?? 'block',
77
- });
77
+ // Note: We don't use the async secrets detector here because this handler
78
+ // must be synchronous. The filterOutput function provides synchronous pattern matching.
78
79
  // Create scanner config from sanitization rules
79
80
  const sanitizationConfig = config.rules?.sanitization;
80
81
  const scannerConfig = {
@@ -88,27 +89,35 @@ export function createToolResultPersistHandler(config, options) {
88
89
  minConfidence: sanitizationConfig?.minConfidence ?? 0.5,
89
90
  redactMatches: sanitizationConfig?.redactMatches ?? false,
90
91
  };
91
- return async (context) => {
92
+ return (context) => {
93
+ const toolName = context.toolName;
94
+ log.debug(`[Hook:tool-result-persist] Entry: tool=${toolName}`);
92
95
  // 1. Check if plugin is globally disabled
93
96
  if (config.global?.enabled === false) {
97
+ log.debug(`[Hook:tool-result-persist] Plugin disabled, allowing output`);
94
98
  return createAllowResult();
95
99
  }
96
100
  // Convert output to string for scanning
97
101
  const toolOutputString = outputToString(context.toolOutput);
98
102
  // 2. Run prompt injection scanner if enabled
99
103
  if (scanInjectionsEnabled && sanitizationConfig?.enabled !== false && toolOutputString) {
104
+ log.debug(`[Hook:tool-result-persist] Scanning for prompt injections`);
100
105
  const scanResult = scan(toolOutputString, scannerConfig);
101
106
  if (scanResult.hasInjection) {
107
+ const categories = [...new Set(scanResult.matches.map(m => m.category))];
108
+ log.warn(`[Hook:tool-result-persist] Prompt injection detected: categories=${categories.join(',')}, matches=${scanResult.matches.length}`);
102
109
  const injectionRedactions = scanResult.matches.map(match => ({
103
110
  type: `injection-${match.category}`,
104
111
  description: `Prompt injection detected: ${match.match.substring(0, 50)}${match.match.length > 50 ? '...' : ''}`,
105
112
  }));
106
113
  // If action is 'block', reject the output entirely
107
114
  if (sanitizationConfig?.action === 'block') {
115
+ log.info(`[Hook:tool-result-persist] Blocking output due to injection`);
108
116
  return createBlockResult(injectionRedactions);
109
117
  }
110
118
  // If redactMatches is enabled, sanitize the output
111
119
  if (sanitizationConfig?.redactMatches) {
120
+ log.info(`[Hook:tool-result-persist] Sanitizing injection patterns`);
112
121
  const sanitizedOutput = sanitize(toolOutputString, scanResult.matches);
113
122
  return createFilteredResult(sanitizedOutput, injectionRedactions);
114
123
  }
@@ -120,27 +129,20 @@ export function createToolResultPersistHandler(config, options) {
120
129
  if (!filterEnabled || config.rules?.secrets?.enabled === false) {
121
130
  return createAllowResult();
122
131
  }
123
- // 4. Run secrets detector on the tool output
124
- let detections = [];
125
- try {
126
- detections = await secretsDetector.detectAll({
127
- toolName: context.toolName,
128
- toolInput: context.toolInput,
129
- toolOutput: toolOutputString,
130
- });
131
- }
132
- catch {
133
- // If detection fails, allow the output through without filtering
134
- // This ensures tool results aren't lost due to detector errors
135
- return createAllowResult();
136
- }
132
+ // 4. Skip async secrets detector - filterOutput below does synchronous pattern matching
133
+ // Note: This handler must be synchronous per OpenClaw requirements
134
+ // The filterOutput function (line 211) catches secrets via regex patterns
135
+ log.debug(`[Hook:tool-result-persist] Using synchronous pattern matching for secrets`);
136
+ const detections = [];
137
137
  // 5. Filter output with pattern matching (catches secrets detector might have missed)
138
138
  const filterResult = filterOutput(context.toolOutput, detections);
139
139
  // 6. If nothing was redacted, allow through unchanged
140
140
  if (!filterResult.wasRedacted) {
141
+ log.debug(`[Hook:tool-result-persist] Exit: tool=${toolName}, no filtering needed`);
141
142
  return createAllowResult();
142
143
  }
143
144
  // 7. Return filtered result with redaction metadata
145
+ log.info(`[Hook:tool-result-persist] Exit: tool=${toolName}, redactions=${filterResult.redactions.length}`);
144
146
  return createFilteredResult(filterResult.filteredOutput, filterResult.redactions);
145
147
  };
146
148
  }
@@ -1 +1 @@
1
- {"version":3,"file":"handler.js","sourceRoot":"","sources":["../../../../src/hooks/tool-result-persist/handler.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AASH,OAAO,EAAE,qBAAqB,EAAE,MAAM,kCAAkC,CAAC;AACzE,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,+BAA+B,CAAC;AAE/D,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAkB3C;;GAEG;AACH,SAAS,iBAAiB;IACxB,OAAO;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AAG;gBAClB,aAAa,EAAE,KAAK;gBACpB,UAAU,EAAE;oBACV,mBAAmB,EAAE,IAAI;oBACzB,UAAU,EAAE,IAAI;oBAChB,SAAS,EAAE,IAAI;oBACf,cAAc,EAAE,IAAI;iBACrB;aACF;SACF;QACD,QAAQ,EAAE;YACR,MAAM,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,EAAE;YACvC,YAAY,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,aAAa,EAAE,kBAAkB,EAAE;YAClE,OAAO,EAAE,EAAE,OAAO,EAAE,KAAK,EAAE,GAAG,EAAE,SAAS,EAAE,OAAO,EAAE,EAAE,EAAE,OAAO,EAAE,EAAE,EAAE;SACtE;KACF,CAAC;IAEF,OAAO,8BAA8B,CAAC,aAAa,CAAC,CAAC;AACvD,CAAC"}
1
+ {"version":3,"file":"handler.js","sourceRoot":"","sources":["../../../../src/hooks/tool-result-persist/handler.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AASH,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,+BAA+B,CAAC;AAE/D,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,EAAE,YAAY,EAAe,MAAM,uBAAuB,CAAC;AAkBlE;;GAEG;AACH,SAAS,iBAAiB;IACxB,OAAO,EAAE,CAAC,CAAC,oDAAoD;AACjE,CAAC;AAED;;;;GAIG;AACH,SAAS,iBAAiB,CACxB,UAAwD;IAExD,OAAO;QACL,OAAO,EAAE;YACP,OAAO,EAAE,6CAA6C;YACtD,UAAU;SACX;KACF,CAAC;AACJ,CAAC;AAED;;GAEG;AACH,SAAS,oBAAoB,CAC3B,cAAuB,EACvB,UAAwD;IAExD,OAAO;QACL,OAAO,EAAE;YACP,OAAO,EAAE,cAAc;YACvB,UAAU;SACX;KACF,CAAC;AACJ,CAAC;AAED;;GAEG;AACH,SAAS,cAAc,CAAC,MAAe;IACrC,IAAI,OAAO,MAAM,K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O;gBACf,aAAa,EAAE,GAAG;gBAClB,aAAa,EAAE,KAAK;gBACpB,UAAU,EAAE;oBACV,mBAAmB,EAAE,IAAI;oBACzB,UAAU,EAAE,IAAI;oBAChB,SAAS,EAAE,IAAI;oBACf,cAAc,EAAE,IAAI;iBACrB;aACF;SACF;QACD,QAAQ,EAAE;YACR,MAAM,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,EAAE;YACvC,YAAY,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,aAAa,EAAE,kBAAkB,EAAE;YAClE,OAAO,EAAE,EAAE,OAAO,EAAE,KAAK,EAAE,GAAG,EAAE,SAAS,EAAE,OAAO,EAAE,EAAE,EAAE,OAAO,EAAE,EAAE,EAAE;SACtE;KACF,CAAC;IAEF,OAAO,8BAA8B,CAAC,aAAa,CAAC,CAAC;AACvD,CAAC"}
@@ -5,6 +5,7 @@
5
5
  export declare const VERSION = "0.0.1";
6
6
  export declare const PLUGIN_ID = "clawsec";
7
7
  export declare const PLUGIN_NAME = "Clawsec Security Plugin";
8
+ import { type Logger } from './utils/logger.js';
8
9
  /**
9
10
  * Severity levels for security detections
10
11
  */
@@ -16,12 +17,12 @@ export type Action = 'block' | 'confirm' | 'agent-confirm' | 'warn' | 'log';
16
17
  /**
17
18
  * Categories of security threats
18
19
  */
19
- export type ThreatCategory = 'purchase' | 'website' | 'destructive' | 'secrets' | 'exfiltration';
20
+ export type ThreatCategory = 'purchase' | 'website' | 'destructive' | 'secrets' | 'exfiltration' | 'unknown';
20
21
  /**
21
22
  * Base context provided to all hooks
22
23
  */
23
24
  export interface HookContext {
24
- sessionId: string;
25
+ sessionId?: string;
25
26
  userId?: string;
26
27
  timestamp: number;
27
28
  }
@@ -30,22 +31,23 @@ export interface HookContext {
30
31
  */
31
32
  export interface ToolCallContext extends HookContext {
32
33
  toolName: string;
33
- toolInput: Record<string, unknown>;
34
+ toolInput?: Record<string, unknown>;
35
+ params?: Record<string, unknown>;
34
36
  conversationHistory?: Array<{
35
37
  role: 'user' | 'assistant';
36
38
  content: string;
37
39
  }>;
38
40
  }
39
41
  /**
40
- * Result from before-tool-call hook
42
+ * Result from before-tool-call hook (modern API)
41
43
  */
42
44
  export interface BeforeToolCallResult {
43
- /** Whether to allow the tool call to proceed */
44
- allow: boolean;
45
- /** Modified tool input (if transformed) */
46
- modifiedInput?: Record<string, unknown>;
47
- /** Message to display when blocked */
48
- blockMessage?: string;
45
+ /** Whether to block the tool call (default: false = allow) */
46
+ block?: boolean;
47
+ /** Reason for blocking (if blocked) */
48
+ blockReason?: string;
49
+ /** Modified tool parameters (if transformed) */
50
+ params?: Record<string, unknown>;
49
51
  /** Metadata about the detection */
50
52
  metadata?: {
51
53
  category?: ThreatCategory;
@@ -64,13 +66,22 @@ export type BeforeToolCallHandler = (context: ToolCallContext) => Promise<Before
64
66
  export interface AgentStartContext extends HookContext {
65
67
  systemPrompt?: string;
66
68
  agentConfig?: Record<string, unknown>;
69
+ prompt?: string;
70
+ messages?: Array<{
71
+ role: 'user' | 'assistant' | 'toolResult' | string;
72
+ content: unknown;
73
+ timestamp?: number;
74
+ [key: string]: unknown;
75
+ }>;
67
76
  }
68
77
  /**
69
- * Result from before-agent-start hook
78
+ * Result from before-agent-start hook (modern API)
70
79
  */
71
80
  export interface BeforeAgentStartResult {
72
- /** Modified or injected system prompt content */
73
- systemPromptAddition?: string;
81
+ /** System prompt replacement (replaces entire prompt) */
82
+ systemPrompt?: string;
83
+ /** Context to prepend before user message (OpenClaw's actual API field) */
84
+ prependContext?: string;
74
85
  /** Modified agent configuration */
75
86
  modifiedConfig?: Record<string, unknown>;
76
87
  }
@@ -87,49 +98,38 @@ export interface ToolResultContext extends HookContext {
87
98
  toolOutput: unknown;
88
99
  }
89
100
  /**
90
- * Result from tool-result-persist hook
101
+ * Result from tool-result-persist hook (modern API)
91
102
  */
92
103
  export interface ToolResultPersistResult {
93
- /** Whether to allow the result to be persisted */
94
- allow: boolean;
95
- /** Filtered/redacted output */
96
- filteredOutput?: unknown;
97
- /** Metadata about any redactions */
98
- redactions?: Array<{
99
- type: string;
100
- description: string;
101
- }>;
104
+ /** Modified message object (if filtering/redacting) */
105
+ message?: {
106
+ content?: unknown;
107
+ redactions?: Array<{
108
+ type: string;
109
+ description: string;
110
+ }>;
111
+ };
102
112
  }
103
113
  /**
104
114
  * Handler type for tool-result-persist hook
115
+ * Note: This hook must be synchronous per OpenClaw requirements
105
116
  */
106
- export type ToolResultPersistHandler = (context: ToolResultContext) => Promise<ToolResultPersistResult>;
117
+ export type ToolResultPersistHandler = (context: ToolResultContext) => ToolResultPersistResult;
107
118
  /**
108
119
  * OpenClaw plugin API interface
109
120
  */
110
121
  export interface OpenClawPluginAPI {
111
- /** Register a hook handler */
112
- registerHook: (hookName: string, handler: unknown, options?: HookOptions) => void;
113
- /** Unregister a hook handler */
114
- unregisterHook: (hookName: string, handlerId: string) => void;
115
- /** Get plugin configuration */
116
- getConfig: () => PluginConfig;
122
+ /** Register a hook handler (modern event-based API) */
123
+ on: (hookName: string, handler: unknown, options?: {
124
+ priority?: number;
125
+ }) => void;
126
+ /** Plugin configuration */
127
+ config: PluginConfig;
117
128
  /** Log a message */
118
129
  log: (level: 'debug' | 'info' | 'warn' | 'error', message: string, data?: unknown) => void;
119
130
  /** Request user approval */
120
131
  requestApproval: (request: ApprovalRequest) => Promise<ApprovalResponse>;
121
132
  }
122
- /**
123
- * Hook registration options
124
- */
125
- export interface HookOptions {
126
- /** Unique identifier for this handler */
127
- id?: string;
128
- /** Priority (lower runs first) */
129
- priority?: number;
130
- /** Whether this hook is enabled */
131
- enabled?: boolean;
132
- }
133
133
  /**
134
134
  * Plugin configuration from OpenClaw
135
135
  */
@@ -161,15 +161,13 @@ export interface ApprovalResponse {
161
161
  approvedBy?: string;
162
162
  timestamp: number;
163
163
  }
164
+ import type { ClawsecConfig } from './config/schema.js';
164
165
  interface PluginState {
165
166
  api: OpenClawPluginAPI | null;
166
167
  config: PluginConfig | null;
168
+ clawsecConfig: ClawsecConfig | null;
167
169
  initialized: boolean;
168
- handlers: {
169
- beforeToolCall: BeforeToolCallHandler | null;
170
- beforeAgentStart: BeforeAgentStartHandler | null;
171
- toolResultPersist: ToolResultPersistHandler | null;
172
- };
170
+ logger: Logger;
173
171
  }
174
172
  /**
175
173
  * Activates the Clawsec security plugin and registers all hooks.
@@ -221,7 +219,7 @@ export declare const pluginConfigSchema: {
221
219
  *
222
220
  * @param api - The OpenClaw plugin API
223
221
  */
224
- declare function register(api: OpenClawPluginAPI): void;
222
+ declare function register(api: OpenClawPluginAPI): () => void;
225
223
  declare const _default: {
226
224
  id: string;
227
225
  name: string;