@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.
- package/index.ts +17 -15
- 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
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
const
|
|
350
|
-
|
|
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(
|
|
353
|
+
const risk = getToolRisk(toolName, toolInput);
|
|
353
354
|
const shouldGate = cfg.gateHighRisk &&
|
|
354
355
|
(risk === 'high' || risk === 'critical') &&
|
|
355
|
-
cfg.gateTools?.includes(
|
|
356
|
+
cfg.gateTools?.includes(toolName);
|
|
356
357
|
|
|
357
|
-
// Log the action (
|
|
358
|
-
logAction(cfg, agentName, state.sessionId,
|
|
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
|
-
|
|
362
|
+
// Don't modify the message
|
|
363
|
+
return undefined;
|
|
362
364
|
});
|
|
363
365
|
|
|
364
366
|
// Hook: Log agent bootstrap (session start)
|
|
365
|
-
api.
|
|
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.
|
|
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
|
});
|