@inquiryon/openclaw-amp-governance 1.0.5 → 1.0.7
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.js +12 -12
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import * as fs from 'fs';
|
|
2
|
-
import { exec } from 'child_process';
|
|
3
2
|
|
|
4
3
|
console.log('[AMP Governance] Plugin module loaded — Phase 4.');
|
|
5
4
|
|
|
@@ -27,6 +26,9 @@ let _instanceId = null;
|
|
|
27
26
|
// Last known sender — populated by message_received, used for HITL notifications
|
|
28
27
|
let _lastSender = null; // { from: string, channelId: string }
|
|
29
28
|
|
|
29
|
+
// Set by register() so notifyUser can use the runtime API directly
|
|
30
|
+
let _runtime = null;
|
|
31
|
+
|
|
30
32
|
function readSession() {
|
|
31
33
|
try {
|
|
32
34
|
return JSON.parse(fs.readFileSync(SESSION_FILE, 'utf-8'));
|
|
@@ -122,14 +124,14 @@ async function ampLog(instanceId, message, level = 'INFO') {
|
|
|
122
124
|
* to finish. Uses the openclaw CLI so we don't need to reverse-engineer the
|
|
123
125
|
* gateway REST API. Fire-and-forget — errors are logged but never thrown.
|
|
124
126
|
*/
|
|
125
|
-
function notifyUser(sender, message) {
|
|
126
|
-
if (!sender?.from || !
|
|
127
|
-
const safeMsg = message.replace(/"/g, '\\"');
|
|
128
|
-
const cmd = `openclaw message send --channel ${sender.channelId} --target "${sender.from}" --message "${safeMsg}"`;
|
|
127
|
+
async function notifyUser(sender, message) {
|
|
128
|
+
if (!sender?.from || !_runtime) return;
|
|
129
129
|
console.log(`[AMP Governance] Sending notification to ${sender.from}: ${message}`);
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
})
|
|
130
|
+
try {
|
|
131
|
+
await _runtime.channel.whatsapp.sendMessageWhatsApp(sender.from, message, { verbose: false });
|
|
132
|
+
} catch (err) {
|
|
133
|
+
console.warn('[AMP Governance] notifyUser failed:', err.message);
|
|
134
|
+
}
|
|
133
135
|
}
|
|
134
136
|
|
|
135
137
|
// ── HITL POLICY ENGINE ───────────────────────────────────────────────────────
|
|
@@ -387,6 +389,7 @@ export default {
|
|
|
387
389
|
description: 'AMP transparency, accountability, and HITL integration for OpenClaw',
|
|
388
390
|
register(api) {
|
|
389
391
|
api.logger.info('AMP Governance registered. Phase 4 - eval policy enforcement active.');
|
|
392
|
+
_runtime = api.runtime;
|
|
390
393
|
|
|
391
394
|
// ── INBOUND MESSAGE: cache sender for HITL notifications ─────────────────
|
|
392
395
|
api.on('message_received', (event, ctx) => {
|
|
@@ -434,17 +437,14 @@ export default {
|
|
|
434
437
|
await ampLog(instanceId, message, event.success === false ? 'ERROR' : 'INFO');
|
|
435
438
|
});
|
|
436
439
|
|
|
437
|
-
// ── OUTBOUND MESSAGE LOGGING
|
|
440
|
+
// ── OUTBOUND MESSAGE LOGGING ──────────────────────────────────────────────
|
|
438
441
|
api.on('message_sending', async (event) => {
|
|
439
442
|
const instanceId = _instanceId || readSession()?.instanceId;
|
|
440
443
|
const msgText = event.content || event.text || event.message || JSON.stringify(event);
|
|
441
444
|
const preview = msgText.substring(0, 100);
|
|
442
|
-
console.log(`[AMP Governance] message_sending fired: ${preview}`);
|
|
443
445
|
if (instanceId) {
|
|
444
446
|
await ampLog(instanceId, `Agent reply: ${preview}`);
|
|
445
447
|
}
|
|
446
|
-
// Prefix every outbound message so the user can distinguish agent replies
|
|
447
|
-
return { content: `[OpenClaw]\n${msgText}` };
|
|
448
448
|
});
|
|
449
449
|
},
|
|
450
450
|
};
|