@inquiryon/openclaw-amp-governance 1.0.6 → 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 +11 -10
- 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,16 +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
|
-
|
|
126
|
-
|
|
127
|
-
function notifyUser(sender, message) {
|
|
128
|
-
if (!sender?.from || !sender?.channelId) return;
|
|
129
|
-
const safeMsg = message.replace(/"/g, '\\"');
|
|
130
|
-
const cmd = `${OPENCLAW_BIN} message send --channel ${sender.channelId} --target "${sender.from}" --message "${safeMsg}"`;
|
|
127
|
+
async function notifyUser(sender, message) {
|
|
128
|
+
if (!sender?.from || !_runtime) return;
|
|
131
129
|
console.log(`[AMP Governance] Sending notification to ${sender.from}: ${message}`);
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
})
|
|
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
|
+
}
|
|
135
135
|
}
|
|
136
136
|
|
|
137
137
|
// ── HITL POLICY ENGINE ───────────────────────────────────────────────────────
|
|
@@ -389,6 +389,7 @@ export default {
|
|
|
389
389
|
description: 'AMP transparency, accountability, and HITL integration for OpenClaw',
|
|
390
390
|
register(api) {
|
|
391
391
|
api.logger.info('AMP Governance registered. Phase 4 - eval policy enforcement active.');
|
|
392
|
+
_runtime = api.runtime;
|
|
392
393
|
|
|
393
394
|
// ── INBOUND MESSAGE: cache sender for HITL notifications ─────────────────
|
|
394
395
|
api.on('message_received', (event, ctx) => {
|