@moltnet/guard 1.0.4 → 1.0.6

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 (2) hide show
  1. package/index.ts +17 -15
  2. package/package.json +1 -1
package/index.ts CHANGED
@@ -343,36 +343,38 @@ const register: PluginRegisterFn = (api: PluginAPI) => {
343
343
  })();
344
344
 
345
345
  // Hook: Intercept tool results before persistence
346
- api.hooks?.register('tool_result_persist', (toolResult) => {
347
- if (!toolResult || typeof toolResult !== 'object') return toolResult;
348
-
349
- const { name, input } = toolResult as { name?: string; input?: Record<string, unknown> };
350
- if (!name) return toolResult;
346
+ // Clawdbot passes { message, toolName, toolInput, ... }
347
+ api.on('tool_result_persist', (event: any) => {
348
+ const toolName = event.toolName || event.name;
349
+ const toolInput = event.toolInput || event.input || {};
350
+
351
+ if (!toolName) return;
351
352
 
352
- const risk = getToolRisk(name, input || {});
353
+ const risk = getToolRisk(toolName, toolInput);
353
354
  const shouldGate = cfg.gateHighRisk &&
354
355
  (risk === 'high' || risk === 'critical') &&
355
- cfg.gateTools?.includes(name);
356
+ cfg.gateTools?.includes(toolName);
356
357
 
357
- // Log the action (async, don't block)
358
- logAction(cfg, agentName, state.sessionId, name, input || {}, risk, shouldGate ? 'pending' : 'executed')
358
+ // Log the action (fire and forget - this hook must be sync)
359
+ logAction(cfg, agentName, state.sessionId, toolName, toolInput, risk, shouldGate ? 'pending' : 'executed')
359
360
  .catch(err => console.error('[moltguard] Failed to log action:', err));
360
361
 
361
- return toolResult;
362
+ // Don't modify the message
363
+ return undefined;
362
364
  });
363
365
 
364
366
  // Hook: Log agent bootstrap (session start)
365
- api.hooks?.register('agent:bootstrap', (event) => {
367
+ api.on('agent:bootstrap', (event) => {
366
368
  if (cfg.logThoughts) {
367
369
  logTrace(cfg, agentName, state.sessionId, 'session', 'Session Started', 'Agent bootstrap initiated')
368
370
  .catch(() => {});
369
371
  }
370
372
  });
371
373
 
372
- // Hook: Log commands
373
- api.hooks?.register('command', (event) => {
374
- if (cfg.logThoughts && event.action) {
375
- logTrace(cfg, agentName, state.sessionId, 'command', `Command: /${event.action}`, `User issued /${event.action}`)
374
+ // Hook: Log commands
375
+ api.on('command', (event) => {
376
+ if (cfg.logThoughts && (event as any).action) {
377
+ logTrace(cfg, agentName, state.sessionId, 'command', `Command: /${(event as any).action}`, `User issued /${(event as any).action}`)
376
378
  .catch(() => {});
377
379
  }
378
380
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@moltnet/guard",
3
- "version": "1.0.4",
3
+ "version": "1.0.6",
4
4
  "description": "MoltGuard plugin for Clawdbot - Security & observability for AI agents",
5
5
  "main": "index.ts",
6
6
  "type": "module",