@dashclaw/openclaw-plugin 1.6.2 → 1.6.3
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/README.md +233 -219
- package/dist/index.js +141 -3
- package/dist/liveness-probe.d.ts +79 -0
- package/dist/liveness-probe.js +185 -0
- package/openclaw.plugin.json +1 -1
- package/package.json +80 -80
- package/src/index.ts +154 -2
- package/src/liveness-probe.ts +232 -0
package/dist/index.js
CHANGED
|
@@ -21,7 +21,10 @@
|
|
|
21
21
|
*/
|
|
22
22
|
import { definePluginEntry, } from 'openclaw/plugin-sdk/plugin-entry';
|
|
23
23
|
import { DashClaw, } from 'dashclaw';
|
|
24
|
+
import { existsSync, readFileSync, statSync } from 'node:fs';
|
|
25
|
+
import { resolve as resolvePath } from 'node:path';
|
|
24
26
|
import { maybeAutoPair } from './auto-pairing.js';
|
|
27
|
+
import { runLivenessProbe, shouldProbeNow, PROBE_AGENT_ID } from './liveness-probe.js';
|
|
25
28
|
/**
|
|
26
29
|
* Resolve the DashClaw URL from (in order of precedence):
|
|
27
30
|
* 1. `config.dashclawUrl` (canonical plugin-config key)
|
|
@@ -220,6 +223,75 @@ const PACKAGE_COMMANDS = new Set([
|
|
|
220
223
|
const DEPLOY_PATTERN = /(?:git\s+push|deploy|vercel|kubectl|terraform|docker\s+push|helm)/i;
|
|
221
224
|
const DESTRUCTIVE_PATTERN = /(?:rm\s+-rf|DROP\s+TABLE|DELETE\s+FROM|TRUNCATE)/i;
|
|
222
225
|
const SENSITIVE_PATH_PATTERN = /(?:\.env|secret|credential|private_key|\.pem|id_rsa|\.key)/i;
|
|
226
|
+
// Interpreters/runners that indicate the next non-flag token is a local
|
|
227
|
+
// script file worth attaching as evidence (see incident: `node
|
|
228
|
+
// tmp/domain-buy.mjs <name>` was graded from self-declared risk alone
|
|
229
|
+
// because the plugin attached no `act`).
|
|
230
|
+
const SCRIPT_RUNNERS = new Set([
|
|
231
|
+
'node', 'nodejs', 'python', 'python2', 'python3', 'bash', 'sh', 'zsh',
|
|
232
|
+
'deno', 'bun', 'tsx', 'ts-node', 'ruby', 'perl', 'php', 'npx',
|
|
233
|
+
]);
|
|
234
|
+
const SCRIPT_CONTENT_MAX_BYTES = 64 * 1024;
|
|
235
|
+
const SCRIPT_EXCERPT_MAX_CHARS = 6144;
|
|
236
|
+
/**
|
|
237
|
+
* Find the first chain segment (split on &&, ||, ;, |) whose command word,
|
|
238
|
+
* after stripping a leading `cd ...` segment, env assignments, `timeout N`,
|
|
239
|
+
* and `sudo`, is a known script runner — then return the next non-flag
|
|
240
|
+
* token as the candidate script path. Returns undefined when no segment
|
|
241
|
+
* qualifies.
|
|
242
|
+
*/
|
|
243
|
+
function findScriptPathToken(command) {
|
|
244
|
+
const segments = command.split(/&&|\|\||;|\|/);
|
|
245
|
+
for (const segment of segments) {
|
|
246
|
+
const tokens = segment.trim().split(/\s+/).filter(Boolean);
|
|
247
|
+
if (tokens.length === 0 || tokens[0] === 'cd')
|
|
248
|
+
continue;
|
|
249
|
+
while (tokens.length && /^[A-Za-z_][A-Za-z0-9_]*=/.test(tokens[0]))
|
|
250
|
+
tokens.shift();
|
|
251
|
+
if (tokens[0] === 'timeout')
|
|
252
|
+
tokens.splice(0, 2);
|
|
253
|
+
if (tokens[0] === 'sudo')
|
|
254
|
+
tokens.shift();
|
|
255
|
+
if (tokens.length === 0)
|
|
256
|
+
continue;
|
|
257
|
+
const cmdWord = tokens[0].replace(/^.*[/\\]/, '');
|
|
258
|
+
if (!SCRIPT_RUNNERS.has(cmdWord))
|
|
259
|
+
continue;
|
|
260
|
+
const pathToken = tokens.slice(1).find((t) => !t.startsWith('-'));
|
|
261
|
+
if (pathToken)
|
|
262
|
+
return pathToken;
|
|
263
|
+
}
|
|
264
|
+
return undefined;
|
|
265
|
+
}
|
|
266
|
+
/**
|
|
267
|
+
* Attach the local script's content when a shell command invokes one, so
|
|
268
|
+
* the server's evidence classifier sees what actually runs instead of
|
|
269
|
+
* grading only the self-declared risk_score. Fail-soft everywhere: any
|
|
270
|
+
* resolution, stat, or read error yields no `script` at all. Sensitive
|
|
271
|
+
* paths (.env, credentials, keys) still attach `path` for policy matching
|
|
272
|
+
* but never their content.
|
|
273
|
+
*/
|
|
274
|
+
function detectLocalScript(command, workspace) {
|
|
275
|
+
try {
|
|
276
|
+
const rawPath = findScriptPathToken(command);
|
|
277
|
+
if (!rawPath)
|
|
278
|
+
return undefined;
|
|
279
|
+
const resolved = resolvePath(workspace || process.cwd(), rawPath);
|
|
280
|
+
if (SENSITIVE_PATH_PATTERN.test(rawPath)) {
|
|
281
|
+
return existsSync(resolved) ? { path: rawPath } : undefined;
|
|
282
|
+
}
|
|
283
|
+
if (!existsSync(resolved))
|
|
284
|
+
return undefined;
|
|
285
|
+
const stat = statSync(resolved);
|
|
286
|
+
if (!stat.isFile() || stat.size > SCRIPT_CONTENT_MAX_BYTES)
|
|
287
|
+
return undefined;
|
|
288
|
+
const content = readFileSync(resolved, 'utf8');
|
|
289
|
+
return { path: rawPath, content_excerpt: content.slice(0, SCRIPT_EXCERPT_MAX_CHARS) };
|
|
290
|
+
}
|
|
291
|
+
catch {
|
|
292
|
+
return undefined;
|
|
293
|
+
}
|
|
294
|
+
}
|
|
223
295
|
function classifyBash(command, defaultRisk) {
|
|
224
296
|
if (!command) {
|
|
225
297
|
return { actionType: 'other', riskScore: defaultRisk, reversible: true, systemsTouched: [], declaredGoal: 'Bash: (empty)' };
|
|
@@ -276,12 +348,14 @@ function classifyFile(toolName, params, defaultRisk) {
|
|
|
276
348
|
}
|
|
277
349
|
return { actionType: 'apply', riskScore: defaultRisk, reversible: true, systemsTouched: ['filesystem'], declaredGoal: goal };
|
|
278
350
|
}
|
|
279
|
-
function classifyToolCall(toolName, params, config) {
|
|
351
|
+
function classifyToolCall(toolName, params, config, workspace) {
|
|
280
352
|
const defaultRisk = config.highRiskTools.has(toolName) ? 85 : config.riskScoreDefault;
|
|
281
353
|
const classified = TOOL_CLASSIFIERS
|
|
282
354
|
.map((classify) => classify(toolName, params, defaultRisk))
|
|
283
355
|
.find((result) => result !== null);
|
|
284
|
-
|
|
356
|
+
const base = classified ?? classifyDefaultTool(toolName, params, defaultRisk);
|
|
357
|
+
const act = buildGuardAct(toolName, params, workspace);
|
|
358
|
+
return act ? { ...base, act } : base;
|
|
285
359
|
}
|
|
286
360
|
const WRITE_TOOLS = new Set(['write', 'edit', 'apply_patch']);
|
|
287
361
|
const REVIEW_TOOLS = new Set([
|
|
@@ -292,6 +366,35 @@ const REVIEW_TOOLS = new Set([
|
|
|
292
366
|
'memory_get',
|
|
293
367
|
'image',
|
|
294
368
|
]);
|
|
369
|
+
/**
|
|
370
|
+
* Translate OpenClaw tool params into the narrow evidence-first guard wire
|
|
371
|
+
* contract. Do not truncate the command or the file path: a lost suffix
|
|
372
|
+
* could hide the risk. If a value exceeds the server contract, omit it and
|
|
373
|
+
* retain the normal classified request. File content is intentionally
|
|
374
|
+
* excluded, since a path is sufficient for protected/sensitive-path
|
|
375
|
+
* policies and content may itself be sensitive. Shell commands that
|
|
376
|
+
* execute a local script (e.g. `node tmp/domain-buy.mjs`) are the
|
|
377
|
+
* exception: the script's content is what actually runs, so its first
|
|
378
|
+
* 6144 chars are attached via `script.content_excerpt` (see
|
|
379
|
+
* detectLocalScript) — bounded per the server contract, not exempt from it.
|
|
380
|
+
*/
|
|
381
|
+
function buildGuardAct(toolName, params, workspace) {
|
|
382
|
+
if (toolName === 'bash' || toolName === 'exec') {
|
|
383
|
+
const command = params?.command;
|
|
384
|
+
if (typeof command === 'string' && command.length > 0 && command.length <= 8192) {
|
|
385
|
+
const script = detectLocalScript(command, workspace);
|
|
386
|
+
return script ? { kind: 'shell', command, script } : { kind: 'shell', command };
|
|
387
|
+
}
|
|
388
|
+
return undefined;
|
|
389
|
+
}
|
|
390
|
+
if (WRITE_TOOLS.has(toolName)) {
|
|
391
|
+
const path = params?.file_path ?? params?.path;
|
|
392
|
+
if (typeof path === 'string' && path.length > 0 && path.length <= 1024) {
|
|
393
|
+
return { kind: 'file', file: { path } };
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
return undefined;
|
|
397
|
+
}
|
|
295
398
|
const TOOL_CLASSIFIERS = [
|
|
296
399
|
classifyShellTool,
|
|
297
400
|
classifyWriteTool,
|
|
@@ -357,10 +460,42 @@ function registerRunCleanup(api, config) {
|
|
|
357
460
|
function registerOutcomeRecorder(api, config) {
|
|
358
461
|
api.on('after_tool_call', async (event, _ctx) => handleAfterToolCall(event, config));
|
|
359
462
|
}
|
|
463
|
+
/**
|
|
464
|
+
* Enforcement-liveness probe on `session_start` (v8.2; per-seam since
|
|
465
|
+
* drizzle/0072). Proves the `before_tool_call` veto above actually HOLDS a
|
|
466
|
+
* synthetic action, and files the verdict under `runtime: openclaw` so this
|
|
467
|
+
* seam is scored on its own instead of inheriting another runtime's green.
|
|
468
|
+
*
|
|
469
|
+
* Fire-and-forget, like maybeAutoPair: session start is never delayed or
|
|
470
|
+
* failed by it. Self-throttled to once per 12h.
|
|
471
|
+
*
|
|
472
|
+
* It drives handleBeforeToolCall — the REAL handler, not a copy — under a
|
|
473
|
+
* synthetic identity. `smoke-` prefixed agents are excluded from every
|
|
474
|
+
* aggregate, and the identity swap is orthogonal to the enforcement mechanics
|
|
475
|
+
* being probed, so it costs no seam fidelity while keeping the probe's guard
|
|
476
|
+
* rows out of the operator's real numbers.
|
|
477
|
+
*/
|
|
478
|
+
function registerLivenessProbe(api, config) {
|
|
479
|
+
api.on('session_start', async (_event, _ctx) => {
|
|
480
|
+
if (!config.dashclawUrl || !config.dashclawApiKey)
|
|
481
|
+
return;
|
|
482
|
+
if (!shouldProbeNow())
|
|
483
|
+
return;
|
|
484
|
+
const probeConfig = { ...config, agentId: PROBE_AGENT_ID };
|
|
485
|
+
void runLivenessProbe({
|
|
486
|
+
dashclawUrl: config.dashclawUrl,
|
|
487
|
+
dashclawApiKey: config.dashclawApiKey,
|
|
488
|
+
driveSeam: (event) => handleBeforeToolCall(event, probeConfig),
|
|
489
|
+
}).catch((err) => {
|
|
490
|
+
console.warn(`[dashclaw-governance] liveness probe failed: ${errorMessage(err) || 'unknown'}`);
|
|
491
|
+
});
|
|
492
|
+
});
|
|
493
|
+
}
|
|
360
494
|
async function handleBeforeToolCall(event, config) {
|
|
361
495
|
const { toolName, params, toolCallId, runId } = event;
|
|
362
496
|
const key = callKey(toolName, toolCallId, runId);
|
|
363
|
-
const
|
|
497
|
+
const workspace = typeof event.workspace === 'string' ? event.workspace : undefined;
|
|
498
|
+
const classification = classifyToolCall(toolName, params, config, workspace);
|
|
364
499
|
const client = getBeforeClient(config);
|
|
365
500
|
if ('result' in client)
|
|
366
501
|
return client.result;
|
|
@@ -426,6 +561,7 @@ async function guardClassifiedAction(client, classification, config) {
|
|
|
426
561
|
declared_goal: classification.declaredGoal,
|
|
427
562
|
reversible: classification.reversible,
|
|
428
563
|
systems_touched: classification.systemsTouched,
|
|
564
|
+
...(classification.act ? { act: classification.act } : {}),
|
|
429
565
|
}),
|
|
430
566
|
};
|
|
431
567
|
}
|
|
@@ -474,6 +610,7 @@ async function createGovernanceAction(ctx) {
|
|
|
474
610
|
risk_score: riskScore,
|
|
475
611
|
reversible,
|
|
476
612
|
systems_touched: systemsTouched,
|
|
613
|
+
...(ctx.classification.act ? { act: ctx.classification.act } : {}),
|
|
477
614
|
metadata: { openclaw_tool_name: ctx.toolName },
|
|
478
615
|
});
|
|
479
616
|
return {
|
|
@@ -692,6 +829,7 @@ const pluginEntry = definePluginEntry({
|
|
|
692
829
|
registerTokenAttribution(api, config);
|
|
693
830
|
registerRunCleanup(api, config);
|
|
694
831
|
registerOutcomeRecorder(api, config);
|
|
832
|
+
registerLivenessProbe(api, config);
|
|
695
833
|
},
|
|
696
834
|
});
|
|
697
835
|
export default pluginEntry;
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Enforcement-liveness probe for the OpenClaw seam (roadmap v8.2, per-seam
|
|
3
|
+
* since drizzle/0072).
|
|
4
|
+
*
|
|
5
|
+
* Why this is TypeScript instead of the canonical `hooks/enforcement_liveness_probe.py`.
|
|
6
|
+
* That script probes a seam it can SPAWN: it reads a harness config file, runs
|
|
7
|
+
* the installed hook command as a subprocess, and emulates the harness's
|
|
8
|
+
* contract around it. OpenClaw's seam has none of those parts. Governance here
|
|
9
|
+
* is an in-process `before_tool_call` handler whose return value the gateway
|
|
10
|
+
* obeys directly — there is no config file to read, no command to run, and no
|
|
11
|
+
* exit code to interpret. A subprocess probe cannot reach it at all. So this
|
|
12
|
+
* module reuses the python probe's CONTRACT (same synthetic held action, same
|
|
13
|
+
* witness rule, same three verdicts, same POST payload) while driving the seam
|
|
14
|
+
* the only way it can be driven: by calling it.
|
|
15
|
+
*
|
|
16
|
+
* The witness rule is preserved exactly, and it is the point. The verdict never
|
|
17
|
+
* comes from what the guard DECIDED — the decision ledger is what kept lying in
|
|
18
|
+
* v4.72.1. It comes from whether the held action executed: if the seam does not
|
|
19
|
+
* veto, the probe performs the write the seam should have stopped, and the
|
|
20
|
+
* file's existence is the evidence.
|
|
21
|
+
*
|
|
22
|
+
* Verdicts:
|
|
23
|
+
* held the seam vetoed the synthetic action; the witness was never written.
|
|
24
|
+
* executed the seam let it through and the witness file exists.
|
|
25
|
+
* unprovable the seam ran but enforcement cannot be proven (no policy holds
|
|
26
|
+
* the probe action, or the probe could not run). Rendered broken
|
|
27
|
+
* on the surfaces — you cannot claim enforcement you cannot prove.
|
|
28
|
+
*/
|
|
29
|
+
/** `smoke-` is the established synthetic marker: these guard rows are excluded
|
|
30
|
+
* from every aggregate, exactly as the python probe's agent id is. */
|
|
31
|
+
export declare const PROBE_AGENT_ID = "smoke-liveness-probe";
|
|
32
|
+
export declare const PROBE_RUNTIME = "openclaw";
|
|
33
|
+
export interface SeamResult {
|
|
34
|
+
block?: boolean;
|
|
35
|
+
blockReason?: string;
|
|
36
|
+
}
|
|
37
|
+
export interface ProbeCheck {
|
|
38
|
+
id: string;
|
|
39
|
+
title: string;
|
|
40
|
+
status: 'pass' | 'fail';
|
|
41
|
+
detail?: string;
|
|
42
|
+
durationMs?: number;
|
|
43
|
+
}
|
|
44
|
+
export interface LivenessRun {
|
|
45
|
+
source: string;
|
|
46
|
+
runtime: string;
|
|
47
|
+
verdict: 'held' | 'executed' | 'unprovable';
|
|
48
|
+
detail: string;
|
|
49
|
+
witness: {
|
|
50
|
+
path: string;
|
|
51
|
+
executed: boolean;
|
|
52
|
+
};
|
|
53
|
+
checks: ProbeCheck[];
|
|
54
|
+
startedAt: string;
|
|
55
|
+
finishedAt: string;
|
|
56
|
+
}
|
|
57
|
+
export interface ProbeOptions {
|
|
58
|
+
/** Drives the REAL before_tool_call handler with the synthetic event. */
|
|
59
|
+
driveSeam: (event: {
|
|
60
|
+
toolName: string;
|
|
61
|
+
params: Record<string, unknown>;
|
|
62
|
+
toolCallId: string;
|
|
63
|
+
runId: string;
|
|
64
|
+
}) => Promise<SeamResult | void>;
|
|
65
|
+
dashclawUrl: string;
|
|
66
|
+
dashclawApiKey: string;
|
|
67
|
+
source?: string;
|
|
68
|
+
/** Overridable so tests do not touch the real home directory. */
|
|
69
|
+
witnessRoot?: string;
|
|
70
|
+
now?: () => number;
|
|
71
|
+
fetchImpl?: typeof fetch;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Once per 12h, mirroring the python probe's SessionStart throttle. Returns
|
|
75
|
+
* true when this session should probe, and stamps the marker as it does so —
|
|
76
|
+
* a failure to stamp never blocks the run.
|
|
77
|
+
*/
|
|
78
|
+
export declare function shouldProbeNow(root?: string, now?: number): boolean;
|
|
79
|
+
export declare function runLivenessProbe(options: ProbeOptions): Promise<LivenessRun>;
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Enforcement-liveness probe for the OpenClaw seam (roadmap v8.2, per-seam
|
|
3
|
+
* since drizzle/0072).
|
|
4
|
+
*
|
|
5
|
+
* Why this is TypeScript instead of the canonical `hooks/enforcement_liveness_probe.py`.
|
|
6
|
+
* That script probes a seam it can SPAWN: it reads a harness config file, runs
|
|
7
|
+
* the installed hook command as a subprocess, and emulates the harness's
|
|
8
|
+
* contract around it. OpenClaw's seam has none of those parts. Governance here
|
|
9
|
+
* is an in-process `before_tool_call` handler whose return value the gateway
|
|
10
|
+
* obeys directly — there is no config file to read, no command to run, and no
|
|
11
|
+
* exit code to interpret. A subprocess probe cannot reach it at all. So this
|
|
12
|
+
* module reuses the python probe's CONTRACT (same synthetic held action, same
|
|
13
|
+
* witness rule, same three verdicts, same POST payload) while driving the seam
|
|
14
|
+
* the only way it can be driven: by calling it.
|
|
15
|
+
*
|
|
16
|
+
* The witness rule is preserved exactly, and it is the point. The verdict never
|
|
17
|
+
* comes from what the guard DECIDED — the decision ledger is what kept lying in
|
|
18
|
+
* v4.72.1. It comes from whether the held action executed: if the seam does not
|
|
19
|
+
* veto, the probe performs the write the seam should have stopped, and the
|
|
20
|
+
* file's existence is the evidence.
|
|
21
|
+
*
|
|
22
|
+
* Verdicts:
|
|
23
|
+
* held the seam vetoed the synthetic action; the witness was never written.
|
|
24
|
+
* executed the seam let it through and the witness file exists.
|
|
25
|
+
* unprovable the seam ran but enforcement cannot be proven (no policy holds
|
|
26
|
+
* the probe action, or the probe could not run). Rendered broken
|
|
27
|
+
* on the surfaces — you cannot claim enforcement you cannot prove.
|
|
28
|
+
*/
|
|
29
|
+
import { mkdirSync, existsSync, rmSync, statSync, writeFileSync } from 'node:fs';
|
|
30
|
+
import { homedir } from 'node:os';
|
|
31
|
+
import { join } from 'node:path';
|
|
32
|
+
/** `smoke-` is the established synthetic marker: these guard rows are excluded
|
|
33
|
+
* from every aggregate, exactly as the python probe's agent id is. */
|
|
34
|
+
export const PROBE_AGENT_ID = 'smoke-liveness-probe';
|
|
35
|
+
export const PROBE_RUNTIME = 'openclaw';
|
|
36
|
+
const THROTTLE_MS = 12 * 60 * 60 * 1000;
|
|
37
|
+
function probeRoot() {
|
|
38
|
+
return join(homedir(), '.dashclaw', 'liveness-probe');
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Once per 12h, mirroring the python probe's SessionStart throttle. Returns
|
|
42
|
+
* true when this session should probe, and stamps the marker as it does so —
|
|
43
|
+
* a failure to stamp never blocks the run.
|
|
44
|
+
*/
|
|
45
|
+
export function shouldProbeNow(root = probeRoot(), now = Date.now()) {
|
|
46
|
+
const marker = join(root, '.last-run-openclaw');
|
|
47
|
+
try {
|
|
48
|
+
if (now - statSync(marker).mtimeMs < THROTTLE_MS)
|
|
49
|
+
return false;
|
|
50
|
+
}
|
|
51
|
+
catch {
|
|
52
|
+
// no marker yet: first run in this install
|
|
53
|
+
}
|
|
54
|
+
try {
|
|
55
|
+
mkdirSync(root, { recursive: true });
|
|
56
|
+
writeFileSync(marker, String(now), 'utf8');
|
|
57
|
+
}
|
|
58
|
+
catch {
|
|
59
|
+
// a throttle we cannot record is still a probe worth running
|
|
60
|
+
}
|
|
61
|
+
return true;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* The synthetic held action: a Write to a probe-owned `.env` path outside the
|
|
65
|
+
* workspace. Identical in shape to the python probe's, so both seams are
|
|
66
|
+
* judged against the same class of action — the path trips sensitive-path and
|
|
67
|
+
* outside-workspace risk boosts and matches protected-path/.env policy rules,
|
|
68
|
+
* while remaining a file the probe owns and may safely create when the seam
|
|
69
|
+
* fails open (broken enforcement is exactly when it WILL be written).
|
|
70
|
+
*/
|
|
71
|
+
function syntheticEvent(witnessPath, runId) {
|
|
72
|
+
return {
|
|
73
|
+
toolName: 'Write',
|
|
74
|
+
params: {
|
|
75
|
+
file_path: witnessPath,
|
|
76
|
+
content: `DashClaw enforcement-liveness probe witness ${runId} — if this file exists, an action the policy should have held EXECUTED.`,
|
|
77
|
+
},
|
|
78
|
+
toolCallId: `elp-${runId}`,
|
|
79
|
+
runId: `liveness-probe-${runId}`,
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
export async function runLivenessProbe(options) {
|
|
83
|
+
const now = options.now ?? Date.now;
|
|
84
|
+
const startedAt = new Date(now()).toISOString();
|
|
85
|
+
const t0 = now();
|
|
86
|
+
// Not crypto: this only has to be unique per run so concurrent probes do not
|
|
87
|
+
// share a witness path.
|
|
88
|
+
const runId = `${now().toString(36)}${Math.floor(Math.random() * 1e6).toString(36)}`;
|
|
89
|
+
const witnessDir = join(options.witnessRoot ?? probeRoot(), runId);
|
|
90
|
+
const witnessPath = join(witnessDir, '.env');
|
|
91
|
+
const checks = [];
|
|
92
|
+
let verdict;
|
|
93
|
+
let detail;
|
|
94
|
+
let witnessExecuted = false;
|
|
95
|
+
const seamT0 = now();
|
|
96
|
+
let seam = undefined;
|
|
97
|
+
let seamError = null;
|
|
98
|
+
try {
|
|
99
|
+
seam = await options.driveSeam(syntheticEvent(witnessPath, runId));
|
|
100
|
+
}
|
|
101
|
+
catch (err) {
|
|
102
|
+
seamError = err instanceof Error ? err.message : String(err);
|
|
103
|
+
}
|
|
104
|
+
const seamMs = now() - seamT0;
|
|
105
|
+
if (seamError) {
|
|
106
|
+
// The handler threw. OpenClaw treats a throwing hook as non-blocking, so
|
|
107
|
+
// the tool would have proceeded — same fail-open reading the python probe
|
|
108
|
+
// applies to a hook that cannot run.
|
|
109
|
+
verdict = 'unprovable';
|
|
110
|
+
detail = `The governance hook threw instead of deciding (${seamError}) — the gateway would have let the action proceed, and enforcement cannot be proven this run.`;
|
|
111
|
+
checks.push({ id: 'seam', title: 'before_tool_call threw', status: 'fail', detail, durationMs: seamMs });
|
|
112
|
+
}
|
|
113
|
+
else if (seam && seam.block) {
|
|
114
|
+
verdict = 'held';
|
|
115
|
+
detail = seam.blockReason
|
|
116
|
+
? `Probe action vetoed at the seam: ${seam.blockReason}`
|
|
117
|
+
: 'Probe action vetoed at the seam; the witness was never executed.';
|
|
118
|
+
checks.push({ id: 'seam', title: 'Hook held the synthetic action', status: 'pass', detail, durationMs: seamMs });
|
|
119
|
+
}
|
|
120
|
+
else {
|
|
121
|
+
// The seam let it through: execute the witness, exactly as the gateway
|
|
122
|
+
// would have. Its existence is the evidence — never the ledger.
|
|
123
|
+
try {
|
|
124
|
+
mkdirSync(witnessDir, { recursive: true });
|
|
125
|
+
writeFileSync(witnessPath, `executed by openclaw liveness probe ${runId} at ${new Date(now()).toISOString()}\n`, 'utf8');
|
|
126
|
+
witnessExecuted = existsSync(witnessPath);
|
|
127
|
+
}
|
|
128
|
+
catch {
|
|
129
|
+
witnessExecuted = false;
|
|
130
|
+
}
|
|
131
|
+
verdict = 'unprovable';
|
|
132
|
+
detail =
|
|
133
|
+
'No policy held the probe action — the seam ran and allowed it. Add or scope a policy that blocks writes to *.env (protected paths or risk_threshold) so enforcement is provable.';
|
|
134
|
+
checks.push({
|
|
135
|
+
id: 'seam',
|
|
136
|
+
title: 'Hook let the synthetic action proceed',
|
|
137
|
+
status: 'fail',
|
|
138
|
+
detail,
|
|
139
|
+
durationMs: seamMs,
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
checks.push({
|
|
143
|
+
id: 'witness',
|
|
144
|
+
title: 'Witness: did the held action execute?',
|
|
145
|
+
status: witnessExecuted ? 'fail' : 'pass',
|
|
146
|
+
detail: `${witnessPath} ${witnessExecuted ? 'EXISTS — the action executed' : 'absent'}`,
|
|
147
|
+
});
|
|
148
|
+
try {
|
|
149
|
+
rmSync(witnessDir, { recursive: true, force: true });
|
|
150
|
+
}
|
|
151
|
+
catch {
|
|
152
|
+
// best effort — a leftover witness never changes a verdict already decided
|
|
153
|
+
}
|
|
154
|
+
const run = {
|
|
155
|
+
source: options.source ?? 'session-start',
|
|
156
|
+
runtime: PROBE_RUNTIME,
|
|
157
|
+
verdict,
|
|
158
|
+
detail,
|
|
159
|
+
witness: { path: witnessPath, executed: witnessExecuted },
|
|
160
|
+
checks,
|
|
161
|
+
startedAt,
|
|
162
|
+
finishedAt: new Date(now()).toISOString(),
|
|
163
|
+
};
|
|
164
|
+
await reportRun(run, options);
|
|
165
|
+
void t0;
|
|
166
|
+
return run;
|
|
167
|
+
}
|
|
168
|
+
async function reportRun(run, options) {
|
|
169
|
+
const base = (options.dashclawUrl || '').replace(/\/+$/, '');
|
|
170
|
+
if (!base || !options.dashclawApiKey)
|
|
171
|
+
return;
|
|
172
|
+
const doFetch = options.fetchImpl ?? fetch;
|
|
173
|
+
try {
|
|
174
|
+
await doFetch(`${base}/api/enforcement-liveness`, {
|
|
175
|
+
method: 'POST',
|
|
176
|
+
headers: { 'content-type': 'application/json', 'x-api-key': options.dashclawApiKey },
|
|
177
|
+
body: JSON.stringify(run),
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
catch (err) {
|
|
181
|
+
// A verdict we cannot file is not a reason to break session start. The
|
|
182
|
+
// seam going quiet is itself rendered `stale` by the fleet rollup.
|
|
183
|
+
console.warn(`[dashclaw-governance] liveness verdict not reported: ${err instanceof Error ? err.message : 'unknown'}`);
|
|
184
|
+
}
|
|
185
|
+
}
|
package/openclaw.plugin.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"id": "dashclaw-governance",
|
|
3
3
|
"name": "DashClaw Governance",
|
|
4
4
|
"description": "Policy enforcement, human-in-the-loop approval, and decision recording for every OpenClaw tool call. Powered by DashClaw.",
|
|
5
|
-
"version": "1.6.
|
|
5
|
+
"version": "1.6.3",
|
|
6
6
|
"entry": "dist/index.js",
|
|
7
7
|
"main": "./dist/index.js",
|
|
8
8
|
"configSchema": {
|
package/package.json
CHANGED
|
@@ -1,80 +1,80 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@dashclaw/openclaw-plugin",
|
|
3
|
-
"version": "1.6.
|
|
4
|
-
"description": "DashClaw governance for OpenClaw — policy enforcement, human approval, and decision recording for every tool call.",
|
|
5
|
-
"main": "./dist/index.js",
|
|
6
|
-
"types": "./dist/index.d.ts",
|
|
7
|
-
"type": "module",
|
|
8
|
-
"license": "MIT",
|
|
9
|
-
"author": "DashClaw",
|
|
10
|
-
"keywords": [
|
|
11
|
-
"openclaw",
|
|
12
|
-
"openclaw-plugin",
|
|
13
|
-
"dashclaw",
|
|
14
|
-
"governance",
|
|
15
|
-
"ai-safety",
|
|
16
|
-
"hitl",
|
|
17
|
-
"approval"
|
|
18
|
-
],
|
|
19
|
-
"repository": {
|
|
20
|
-
"type": "git",
|
|
21
|
-
"url": "git+https://github.com/ucsandman/DashClaw.git",
|
|
22
|
-
"directory": "packages/openclaw-plugin"
|
|
23
|
-
},
|
|
24
|
-
"homepage": "https://github.com/ucsandman/DashClaw/tree/main/packages/openclaw-plugin#readme",
|
|
25
|
-
"files": [
|
|
26
|
-
"dist/",
|
|
27
|
-
"src/",
|
|
28
|
-
"openclaw.plugin.json",
|
|
29
|
-
"README.md",
|
|
30
|
-
"LICENSE"
|
|
31
|
-
],
|
|
32
|
-
"openclaw": {
|
|
33
|
-
"extensions": [
|
|
34
|
-
"./dist/index.js"
|
|
35
|
-
],
|
|
36
|
-
"hooks": [
|
|
37
|
-
"./dist/index.js"
|
|
38
|
-
],
|
|
39
|
-
"compat": {
|
|
40
|
-
"pluginApi": ">=2026.4.15",
|
|
41
|
-
"minGatewayVersion": "2026.4.15"
|
|
42
|
-
},
|
|
43
|
-
"build": {
|
|
44
|
-
"openclawVersion": "2026.4.15",
|
|
45
|
-
"pluginSdkVersion": "2026.4.15"
|
|
46
|
-
}
|
|
47
|
-
},
|
|
48
|
-
"scripts": {
|
|
49
|
-
"build": "tsc",
|
|
50
|
-
"typecheck": "tsc --noEmit",
|
|
51
|
-
"prepack": "npm run build"
|
|
52
|
-
},
|
|
53
|
-
"dependencies": {
|
|
54
|
-
"dashclaw": "^5.0.0"
|
|
55
|
-
},
|
|
56
|
-
"peerDependencies": {
|
|
57
|
-
"openclaw": "^2026.4.15"
|
|
58
|
-
},
|
|
59
|
-
"peerDependenciesMeta": {
|
|
60
|
-
"openclaw": {
|
|
61
|
-
"optional": false
|
|
62
|
-
}
|
|
63
|
-
},
|
|
64
|
-
"devDependencies": {
|
|
65
|
-
"@types/node": "^20.11.0",
|
|
66
|
-
"typescript": "^5.4.0"
|
|
67
|
-
},
|
|
68
|
-
"overrides": {
|
|
69
|
-
"axios": "^1.16.0",
|
|
70
|
-
"tar": "^7.5.22",
|
|
71
|
-
"protobufjs": "^7.6.5",
|
|
72
|
-
"gaxios": {
|
|
73
|
-
"uuid": "^11.1.1"
|
|
74
|
-
},
|
|
75
|
-
"brace-expansion": "^5.0.8",
|
|
76
|
-
"@hono/node-server": "^
|
|
77
|
-
"fast-uri": "^3.1.4",
|
|
78
|
-
"hono": "^4.12.
|
|
79
|
-
}
|
|
80
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@dashclaw/openclaw-plugin",
|
|
3
|
+
"version": "1.6.3",
|
|
4
|
+
"description": "DashClaw governance for OpenClaw — policy enforcement, human approval, and decision recording for every tool call.",
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"types": "./dist/index.d.ts",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"license": "MIT",
|
|
9
|
+
"author": "DashClaw",
|
|
10
|
+
"keywords": [
|
|
11
|
+
"openclaw",
|
|
12
|
+
"openclaw-plugin",
|
|
13
|
+
"dashclaw",
|
|
14
|
+
"governance",
|
|
15
|
+
"ai-safety",
|
|
16
|
+
"hitl",
|
|
17
|
+
"approval"
|
|
18
|
+
],
|
|
19
|
+
"repository": {
|
|
20
|
+
"type": "git",
|
|
21
|
+
"url": "git+https://github.com/ucsandman/DashClaw.git",
|
|
22
|
+
"directory": "packages/openclaw-plugin"
|
|
23
|
+
},
|
|
24
|
+
"homepage": "https://github.com/ucsandman/DashClaw/tree/main/packages/openclaw-plugin#readme",
|
|
25
|
+
"files": [
|
|
26
|
+
"dist/",
|
|
27
|
+
"src/",
|
|
28
|
+
"openclaw.plugin.json",
|
|
29
|
+
"README.md",
|
|
30
|
+
"LICENSE"
|
|
31
|
+
],
|
|
32
|
+
"openclaw": {
|
|
33
|
+
"extensions": [
|
|
34
|
+
"./dist/index.js"
|
|
35
|
+
],
|
|
36
|
+
"hooks": [
|
|
37
|
+
"./dist/index.js"
|
|
38
|
+
],
|
|
39
|
+
"compat": {
|
|
40
|
+
"pluginApi": ">=2026.4.15",
|
|
41
|
+
"minGatewayVersion": "2026.4.15"
|
|
42
|
+
},
|
|
43
|
+
"build": {
|
|
44
|
+
"openclawVersion": "2026.4.15",
|
|
45
|
+
"pluginSdkVersion": "2026.4.15"
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
"scripts": {
|
|
49
|
+
"build": "tsc",
|
|
50
|
+
"typecheck": "tsc --noEmit",
|
|
51
|
+
"prepack": "npm run build"
|
|
52
|
+
},
|
|
53
|
+
"dependencies": {
|
|
54
|
+
"dashclaw": "^5.0.0"
|
|
55
|
+
},
|
|
56
|
+
"peerDependencies": {
|
|
57
|
+
"openclaw": "^2026.4.15"
|
|
58
|
+
},
|
|
59
|
+
"peerDependenciesMeta": {
|
|
60
|
+
"openclaw": {
|
|
61
|
+
"optional": false
|
|
62
|
+
}
|
|
63
|
+
},
|
|
64
|
+
"devDependencies": {
|
|
65
|
+
"@types/node": "^20.11.0",
|
|
66
|
+
"typescript": "^5.4.0"
|
|
67
|
+
},
|
|
68
|
+
"overrides": {
|
|
69
|
+
"axios": "^1.16.0",
|
|
70
|
+
"tar": "^7.5.22",
|
|
71
|
+
"protobufjs": "^7.6.5",
|
|
72
|
+
"gaxios": {
|
|
73
|
+
"uuid": "^11.1.1"
|
|
74
|
+
},
|
|
75
|
+
"brace-expansion": "^5.0.8",
|
|
76
|
+
"@hono/node-server": "^1.19.15",
|
|
77
|
+
"fast-uri": "^3.1.4",
|
|
78
|
+
"hono": "^4.12.34"
|
|
79
|
+
}
|
|
80
|
+
}
|