@dashclaw/openclaw-plugin 1.2.5 → 1.6.0
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 +23 -3
- package/dist/auto-pairing.d.ts +29 -0
- package/dist/auto-pairing.js +119 -0
- package/dist/index.d.ts +24 -0
- package/dist/index.js +671 -0
- package/openclaw.plugin.json +73 -67
- package/package.json +80 -62
- package/src/HOOK.md +3 -1
- package/src/auto-pairing.ts +150 -0
- package/src/dashclaw.d.ts +83 -70
- package/src/index.ts +979 -669
package/openclaw.plugin.json
CHANGED
|
@@ -1,67 +1,73 @@
|
|
|
1
|
-
{
|
|
2
|
-
"id": "dashclaw-governance",
|
|
3
|
-
"name": "DashClaw Governance",
|
|
4
|
-
"description": "Policy enforcement, human-in-the-loop approval, and decision recording for every OpenClaw tool call. Powered by DashClaw.",
|
|
5
|
-
"version": "1.
|
|
6
|
-
"entry": "src/index.ts",
|
|
7
|
-
"main": "./src/index.ts",
|
|
8
|
-
"configSchema": {
|
|
9
|
-
"type": "object",
|
|
10
|
-
"additionalProperties": false,
|
|
11
|
-
"description": "Configure the DashClaw connection via any of three shapes: (a) canonical plugin-config keys `dashclawUrl` + `dashclawApiKey` (+ optional `agentId`); (b) SDK-style aliases `baseUrl` + `apiKey`; (c) environment variables `DASHCLAW_BASE_URL` (or legacy `DASHCLAW_URL`) + `DASHCLAW_API_KEY` (+ optional `DASHCLAW_AGENT_ID`) set before the gateway starts. Precedence is plugin config > env. No field is strictly required in this schema — env vars alone are sufficient.",
|
|
12
|
-
"properties": {
|
|
13
|
-
"dashclawUrl": {
|
|
14
|
-
"type": "string",
|
|
15
|
-
"description": "URL of your DashClaw instance (e.g. https://my-dashclaw.vercel.app). Optional if DASHCLAW_BASE_URL / DASHCLAW_URL env var is set, or if baseUrl is provided."
|
|
16
|
-
},
|
|
17
|
-
"dashclawApiKey": {
|
|
18
|
-
"type": "string",
|
|
19
|
-
"description": "DashClaw API key (starts with oc_live_). Optional if DASHCLAW_API_KEY env var is set, or if apiKey is provided."
|
|
20
|
-
},
|
|
21
|
-
"baseUrl": {
|
|
22
|
-
"type": "string",
|
|
23
|
-
"description": "SDK-style alias for dashclawUrl. Use whichever you prefer."
|
|
24
|
-
},
|
|
25
|
-
"apiKey": {
|
|
26
|
-
"type": "string",
|
|
27
|
-
"description": "SDK-style alias for dashclawApiKey. Use whichever you prefer."
|
|
28
|
-
},
|
|
29
|
-
"agentId": {
|
|
30
|
-
"type": "string",
|
|
31
|
-
"default": "openclaw",
|
|
32
|
-
"description": "Agent identifier in DashClaw"
|
|
33
|
-
},
|
|
34
|
-
"defaultModel": {
|
|
35
|
-
"type": "string",
|
|
36
|
-
"description": "Fallback model id (e.g. 'openai-codex/gpt-5.4') used when llm_output events fire without a model field. Without this, server-side cost estimation cannot price the turn and stores cost_estimate = 0. Also settable via DASHCLAW_DEFAULT_MODEL env var."
|
|
37
|
-
},
|
|
38
|
-
"failClosed": {
|
|
39
|
-
"type": "boolean",
|
|
40
|
-
"default": true,
|
|
41
|
-
"description": "If true, block tool calls when DashClaw is unreachable. If false, allow them to proceed."
|
|
42
|
-
},
|
|
43
|
-
"
|
|
44
|
-
"type": "
|
|
45
|
-
"default":
|
|
46
|
-
"description": "
|
|
47
|
-
},
|
|
48
|
-
"
|
|
49
|
-
"type": "
|
|
50
|
-
"
|
|
51
|
-
"
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
"
|
|
63
|
-
"
|
|
64
|
-
"
|
|
65
|
-
"
|
|
66
|
-
|
|
67
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"id": "dashclaw-governance",
|
|
3
|
+
"name": "DashClaw Governance",
|
|
4
|
+
"description": "Policy enforcement, human-in-the-loop approval, and decision recording for every OpenClaw tool call. Powered by DashClaw.",
|
|
5
|
+
"version": "1.6.0",
|
|
6
|
+
"entry": "src/index.ts",
|
|
7
|
+
"main": "./src/index.ts",
|
|
8
|
+
"configSchema": {
|
|
9
|
+
"type": "object",
|
|
10
|
+
"additionalProperties": false,
|
|
11
|
+
"description": "Configure the DashClaw connection via any of three shapes: (a) canonical plugin-config keys `dashclawUrl` + `dashclawApiKey` (+ optional `agentId`); (b) SDK-style aliases `baseUrl` + `apiKey`; (c) environment variables `DASHCLAW_BASE_URL` (or legacy `DASHCLAW_URL`) + `DASHCLAW_API_KEY` (+ optional `DASHCLAW_AGENT_ID`) set before the gateway starts. Precedence is plugin config > env. No field is strictly required in this schema — env vars alone are sufficient.",
|
|
12
|
+
"properties": {
|
|
13
|
+
"dashclawUrl": {
|
|
14
|
+
"type": "string",
|
|
15
|
+
"description": "URL of your DashClaw instance (e.g. https://my-dashclaw.vercel.app). Optional if DASHCLAW_BASE_URL / DASHCLAW_URL env var is set, or if baseUrl is provided."
|
|
16
|
+
},
|
|
17
|
+
"dashclawApiKey": {
|
|
18
|
+
"type": "string",
|
|
19
|
+
"description": "DashClaw API key (starts with oc_live_). Optional if DASHCLAW_API_KEY env var is set, or if apiKey is provided."
|
|
20
|
+
},
|
|
21
|
+
"baseUrl": {
|
|
22
|
+
"type": "string",
|
|
23
|
+
"description": "SDK-style alias for dashclawUrl. Use whichever you prefer."
|
|
24
|
+
},
|
|
25
|
+
"apiKey": {
|
|
26
|
+
"type": "string",
|
|
27
|
+
"description": "SDK-style alias for dashclawApiKey. Use whichever you prefer."
|
|
28
|
+
},
|
|
29
|
+
"agentId": {
|
|
30
|
+
"type": "string",
|
|
31
|
+
"default": "openclaw",
|
|
32
|
+
"description": "Agent identifier in DashClaw"
|
|
33
|
+
},
|
|
34
|
+
"defaultModel": {
|
|
35
|
+
"type": "string",
|
|
36
|
+
"description": "Fallback model id (e.g. 'openai-codex/gpt-5.4') used when llm_output events fire without a model field. Without this, server-side cost estimation cannot price the turn and stores cost_estimate = 0. Also settable via DASHCLAW_DEFAULT_MODEL env var."
|
|
37
|
+
},
|
|
38
|
+
"failClosed": {
|
|
39
|
+
"type": "boolean",
|
|
40
|
+
"default": true,
|
|
41
|
+
"description": "If true, block tool calls when DashClaw is unreachable. If false, allow them to proceed."
|
|
42
|
+
},
|
|
43
|
+
"autoPairing": {
|
|
44
|
+
"type": "boolean",
|
|
45
|
+
"default": true,
|
|
46
|
+
"description": "Automatically answer operator pairing requests from the DashClaw /identities page: generate a local keypair and submit the public key for admin approval. The private key is stored at ~/.dashclaw/identity/<agentId>.pem and never leaves this machine. Set false to require manual pairing (MCP dashclaw_pair or SDK createPairing)."
|
|
47
|
+
},
|
|
48
|
+
"riskScoreDefault": {
|
|
49
|
+
"type": "number",
|
|
50
|
+
"default": 50,
|
|
51
|
+
"description": "Default risk score for tool calls that don't have a specific mapping"
|
|
52
|
+
},
|
|
53
|
+
"highRiskTools": {
|
|
54
|
+
"type": "array",
|
|
55
|
+
"items": { "type": "string" },
|
|
56
|
+
"default": [],
|
|
57
|
+
"description": "Tool names that should always get risk_score 80+ (e.g. bash, exec, deploy)"
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
},
|
|
61
|
+
"uiHints": {
|
|
62
|
+
"dashclawApiKey": { "sensitive": true, "label": "DashClaw API Key" },
|
|
63
|
+
"dashclawUrl": { "label": "DashClaw URL", "placeholder": "https://my-dashclaw.vercel.app" },
|
|
64
|
+
"baseUrl": { "label": "DashClaw URL (alias)", "advanced": true },
|
|
65
|
+
"apiKey": { "sensitive": true, "label": "DashClaw API Key (alias)", "advanced": true },
|
|
66
|
+
"agentId": { "label": "Agent ID" },
|
|
67
|
+
"defaultModel": { "label": "Default model (for cost pricing)", "placeholder": "openai-codex/gpt-5.4", "advanced": true },
|
|
68
|
+
"failClosed": { "label": "Fail-closed when DashClaw unreachable", "advanced": true },
|
|
69
|
+
"autoPairing": { "label": "Auto-answer pairing requests", "advanced": true },
|
|
70
|
+
"riskScoreDefault": { "label": "Default risk score", "advanced": true },
|
|
71
|
+
"highRiskTools": { "label": "High-risk tool names", "advanced": true }
|
|
72
|
+
}
|
|
73
|
+
}
|
package/package.json
CHANGED
|
@@ -1,62 +1,80 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@dashclaw/openclaw-plugin",
|
|
3
|
-
"version": "1.
|
|
4
|
-
"description": "DashClaw governance for OpenClaw — policy enforcement, human approval, and decision recording for every tool call.",
|
|
5
|
-
"main": "
|
|
6
|
-
"
|
|
7
|
-
"
|
|
8
|
-
"
|
|
9
|
-
"
|
|
10
|
-
|
|
11
|
-
"openclaw
|
|
12
|
-
"
|
|
13
|
-
"
|
|
14
|
-
"
|
|
15
|
-
"
|
|
16
|
-
"
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
"
|
|
21
|
-
"
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
"
|
|
25
|
-
|
|
26
|
-
"
|
|
27
|
-
"
|
|
28
|
-
"
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
"
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
"
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
},
|
|
48
|
-
"
|
|
49
|
-
"
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
},
|
|
53
|
-
"
|
|
54
|
-
"
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
"
|
|
61
|
-
|
|
62
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@dashclaw/openclaw-plugin",
|
|
3
|
+
"version": "1.6.0",
|
|
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
|
+
"./src/index.ts"
|
|
35
|
+
],
|
|
36
|
+
"hooks": [
|
|
37
|
+
"./src/index.ts"
|
|
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": "^2.0.5",
|
|
77
|
+
"fast-uri": "^3.1.4",
|
|
78
|
+
"hono": "^4.12.27"
|
|
79
|
+
}
|
|
80
|
+
}
|
package/src/HOOK.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: dashclaw-governance
|
|
3
3
|
description: Policy enforcement, human-in-the-loop approval, and decision recording for every OpenClaw tool call. Powered by DashClaw.
|
|
4
|
-
version: 1.
|
|
4
|
+
version: 1.5.0
|
|
5
5
|
---
|
|
6
6
|
|
|
7
7
|
# DashClaw Governance Hook
|
|
@@ -13,6 +13,8 @@ Intercepts every OpenClaw tool call through a four-step governance loop:
|
|
|
13
13
|
3. **Wait** — For `pending_approval` actions, the hook calls `waitForApproval(action_id)` using the **action_records ID from step 2**, not the `guard_decisions` ID from step 1. Operators approve from the DashClaw dashboard, CLI, or mobile PWA.
|
|
14
14
|
4. **Outcome** — `after_tool_call` records `completed` or `failed` with the error message, giving DashClaw a full intent → policy → outcome trail.
|
|
15
15
|
|
|
16
|
+
On the first tool call of a run the plugin also opens a DashClaw **Agent Session** (`POST /api/sessions`), and closes it (`PATCH /api/sessions/:id` → `status: completed`) on `agent_end`, so each OpenClaw run appears under the Agent Sessions feature. Session calls are fully fail-safe — a session error never blocks a tool call or the run.
|
|
17
|
+
|
|
16
18
|
The hook never modifies tool parameters or results. It only blocks, allows, waits, or records.
|
|
17
19
|
|
|
18
20
|
## Configuration
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Auto-pairing consumer — answers the operator's /identities "Request
|
|
3
|
+
* pairing" click without an LLM in the loop.
|
|
4
|
+
*
|
|
5
|
+
* On the first tool call per gateway process the plugin checks this agent's
|
|
6
|
+
* DashClaw inbox for a `dashclaw.pairing_request` directive (the fenced-JSON
|
|
7
|
+
* contract in app/lib/pairing-request.ts). When one targets this agent it
|
|
8
|
+
* generates an RSA-2048 keypair locally, POSTs the public PEM via the SDK's
|
|
9
|
+
* createPairing, stores the private key at
|
|
10
|
+
* ~/.dashclaw/identity/<agent_id>.pem (mode 600 — same path as the MCP
|
|
11
|
+
* dashclaw_pair tool), and marks the message read. Identity creation still
|
|
12
|
+
* happens only when an admin approves the pairing on /identities.
|
|
13
|
+
*
|
|
14
|
+
* Custody rule: the private key never leaves this machine and is never
|
|
15
|
+
* logged. Failure rule: every error is a console.warn — this path must
|
|
16
|
+
* never throw into or block a tool call.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
import { existsSync, mkdirSync, writeFileSync } from 'node:fs';
|
|
20
|
+
import { homedir } from 'node:os';
|
|
21
|
+
import { dirname, join } from 'node:path';
|
|
22
|
+
import { generateKeyPairSync } from 'node:crypto';
|
|
23
|
+
import type { DashClaw } from 'dashclaw';
|
|
24
|
+
|
|
25
|
+
export const PAIRING_REQUEST_KIND = 'dashclaw.pairing_request';
|
|
26
|
+
|
|
27
|
+
export interface AutoPairConfig {
|
|
28
|
+
dashclawUrl: string;
|
|
29
|
+
dashclawApiKey: string;
|
|
30
|
+
agentId: string;
|
|
31
|
+
autoPairing: boolean;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
interface InboxMessage {
|
|
35
|
+
id: string;
|
|
36
|
+
body?: unknown;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// One attempt per gateway process per (url, agent). Added BEFORE the first
|
|
40
|
+
// await so concurrent tool calls cannot double-run the flow. Per-process on
|
|
41
|
+
// purpose: a transient failure retries at the next gateway start.
|
|
42
|
+
let attempted = new Set<string>();
|
|
43
|
+
|
|
44
|
+
/** Test-only: reset the per-process attempt guard. */
|
|
45
|
+
export function __resetAutoPairing(): void {
|
|
46
|
+
attempted = new Set();
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export function identityKeyPath(agentId: string): string {
|
|
50
|
+
const safe = agentId.replace(/[^A-Za-z0-9._-]/g, '_');
|
|
51
|
+
return join(homedir(), '.dashclaw', 'identity', `${safe}.pem`);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** Same fence contract as app/lib/pairing-request.ts. */
|
|
55
|
+
function directiveTargets(body: unknown, agentId: string): boolean {
|
|
56
|
+
if (typeof body !== 'string') return false;
|
|
57
|
+
const match = body.match(/```json\s*([\s\S]*?)```/);
|
|
58
|
+
if (!match || !match[1]) return false;
|
|
59
|
+
try {
|
|
60
|
+
const parsed = JSON.parse(match[1]) as { kind?: string; agent_id?: string } | null;
|
|
61
|
+
return parsed?.kind === PAIRING_REQUEST_KIND && parsed.agent_id === agentId;
|
|
62
|
+
} catch {
|
|
63
|
+
return false;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function apiUrl(config: AutoPairConfig, pathAndQuery: string): string {
|
|
68
|
+
return `${config.dashclawUrl.replace(/\/+$/, '')}${pathAndQuery}`;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
async function fetchUnreadInbox(config: AutoPairConfig): Promise<InboxMessage[]> {
|
|
72
|
+
const res = await fetch(
|
|
73
|
+
apiUrl(
|
|
74
|
+
config,
|
|
75
|
+
`/api/messages?agent_id=${encodeURIComponent(config.agentId)}&direction=inbox&unread=true&limit=50`
|
|
76
|
+
),
|
|
77
|
+
{ headers: { 'x-api-key': config.dashclawApiKey } }
|
|
78
|
+
);
|
|
79
|
+
if (!res.ok) throw new Error(`messages GET failed (${res.status})`);
|
|
80
|
+
const data = (await res.json()) as { messages?: InboxMessage[] };
|
|
81
|
+
return Array.isArray(data.messages) ? data.messages : [];
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
async function markRead(config: AutoPairConfig, messageIds: string[]): Promise<void> {
|
|
85
|
+
const res = await fetch(apiUrl(config, '/api/messages'), {
|
|
86
|
+
method: 'PATCH',
|
|
87
|
+
headers: { 'x-api-key': config.dashclawApiKey, 'Content-Type': 'application/json' },
|
|
88
|
+
body: JSON.stringify({ message_ids: messageIds, action: 'read', agent_id: config.agentId }),
|
|
89
|
+
});
|
|
90
|
+
if (!res.ok) throw new Error(`messages PATCH failed (${res.status})`);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export async function maybeAutoPair(client: DashClaw, config: AutoPairConfig): Promise<void> {
|
|
94
|
+
if (!config.autoPairing) return;
|
|
95
|
+
const key = `${config.dashclawUrl}|${config.agentId}`;
|
|
96
|
+
if (attempted.has(key)) return;
|
|
97
|
+
attempted.add(key);
|
|
98
|
+
|
|
99
|
+
try {
|
|
100
|
+
const pemPath = identityKeyPath(config.agentId);
|
|
101
|
+
if (existsSync(pemPath)) {
|
|
102
|
+
// Already enrolled or pending. Deleting the pem + clicking Request
|
|
103
|
+
// pairing again is the rotation path.
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
const inbox = await fetchUnreadInbox(config);
|
|
108
|
+
const requests = inbox.filter((m) => directiveTargets(m.body, config.agentId));
|
|
109
|
+
if (requests.length === 0) return;
|
|
110
|
+
|
|
111
|
+
const { publicKey, privateKey } = generateKeyPairSync('rsa', {
|
|
112
|
+
modulusLength: 2048,
|
|
113
|
+
publicKeyEncoding: { type: 'spki', format: 'pem' },
|
|
114
|
+
privateKeyEncoding: { type: 'pkcs8', format: 'pem' },
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
const created = await client.createPairing(publicKey);
|
|
118
|
+
const pairingId =
|
|
119
|
+
(created as { pairing?: { id?: string } }).pairing?.id ??
|
|
120
|
+
(created as { id?: string }).id ??
|
|
121
|
+
'(pending)';
|
|
122
|
+
|
|
123
|
+
// POST-then-write: a failed POST leaves no pem, so the next gateway
|
|
124
|
+
// start retries cleanly. A failed write AFTER a successful POST is the
|
|
125
|
+
// one loud case — that pending pairing has no usable private key.
|
|
126
|
+
try {
|
|
127
|
+
mkdirSync(dirname(pemPath), { recursive: true });
|
|
128
|
+
writeFileSync(pemPath, privateKey, { mode: 0o600 });
|
|
129
|
+
} catch (err) {
|
|
130
|
+
console.warn(
|
|
131
|
+
`[dashclaw-governance] auto-pairing: submitted pairing ${pairingId} but FAILED to store ` +
|
|
132
|
+
`the private key at ${pemPath}: ${errText(err)}. Reject that pairing on /identities, ` +
|
|
133
|
+
`fix the disk issue, and click Request pairing again.`
|
|
134
|
+
);
|
|
135
|
+
return; // leave the message unread so a later gateway start retries
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
await markRead(config, requests.map((m) => m.id));
|
|
139
|
+
console.log(
|
|
140
|
+
`[dashclaw-governance] auto-pairing submitted (${pairingId}) — approve it on /identities. ` +
|
|
141
|
+
`Private key stored at ${pemPath} (never sent).`
|
|
142
|
+
);
|
|
143
|
+
} catch (err) {
|
|
144
|
+
console.warn(`[dashclaw-governance] auto-pairing skipped: ${errText(err)}`);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
function errText(err: unknown): string {
|
|
149
|
+
return err instanceof Error ? err.message : String(err);
|
|
150
|
+
}
|
package/src/dashclaw.d.ts
CHANGED
|
@@ -1,70 +1,83 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Ambient type declarations for the `dashclaw` npm package.
|
|
3
|
-
*
|
|
4
|
-
* The published package ships as ESM JavaScript without `.d.ts` files, so we
|
|
5
|
-
* describe only the surface this plugin touches: the `DashClaw` client and the
|
|
6
|
-
* shapes of `guard()`, `createAction()`, `waitForApproval()`, and
|
|
7
|
-
* `updateOutcome()` responses.
|
|
8
|
-
*
|
|
9
|
-
* Shapes mirror `dashclaw@2.
|
|
10
|
-
* - `guard()` → `{ decision, action_id, reason, signals }`
|
|
11
|
-
* - `createAction()` → API returns `{ action, action_id, decision, ... }`
|
|
12
|
-
* - `waitForApproval()` → `{ action }`
|
|
13
|
-
*/
|
|
14
|
-
declare module 'dashclaw' {
|
|
15
|
-
export interface GuardDecision {
|
|
16
|
-
decision: 'allow' | 'block' | 'warn' | 'require_approval';
|
|
17
|
-
action_id: string;
|
|
18
|
-
reason?: string;
|
|
19
|
-
signals?: string[];
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export interface ActionRecord {
|
|
23
|
-
action_id?: string;
|
|
24
|
-
id?: string;
|
|
25
|
-
status?: string;
|
|
26
|
-
approved_by?: string | null;
|
|
27
|
-
error_message?: string | null;
|
|
28
|
-
[key: string]: unknown;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
/** Envelope returned by `POST /api/actions`. */
|
|
32
|
-
export interface CreateActionResult {
|
|
33
|
-
action: ActionRecord;
|
|
34
|
-
action_id?: string;
|
|
35
|
-
[key: string]: unknown;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
export interface WaitForApprovalResult {
|
|
39
|
-
action: ActionRecord;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
export interface DashClawOptions {
|
|
43
|
-
baseUrl: string;
|
|
44
|
-
apiKey: string;
|
|
45
|
-
agentId: string;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
export class DashClaw {
|
|
49
|
-
constructor(opts: DashClawOptions);
|
|
50
|
-
guard(context: Record<string, unknown>): Promise<GuardDecision>;
|
|
51
|
-
createAction(action: Record<string, unknown>): Promise<CreateActionResult>;
|
|
52
|
-
updateOutcome(
|
|
53
|
-
actionId: string,
|
|
54
|
-
outcome: Record<string, unknown>
|
|
55
|
-
): Promise<unknown>;
|
|
56
|
-
waitForApproval(
|
|
57
|
-
actionId: string,
|
|
58
|
-
opts?: { timeout?: number; interval?: number }
|
|
59
|
-
): Promise<WaitForApprovalResult>;
|
|
60
|
-
recordAssumption(assumption: Record<string, unknown>): Promise<unknown>;
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Ambient type declarations for the `dashclaw` npm package.
|
|
3
|
+
*
|
|
4
|
+
* The published package ships as ESM JavaScript without `.d.ts` files, so we
|
|
5
|
+
* describe only the surface this plugin touches: the `DashClaw` client and the
|
|
6
|
+
* shapes of `guard()`, `createAction()`, `waitForApproval()`, and
|
|
7
|
+
* `updateOutcome()` responses.
|
|
8
|
+
*
|
|
9
|
+
* Shapes mirror `dashclaw@4.2.x+/dashclaw.js`:
|
|
10
|
+
* - `guard()` → `{ decision, action_id, reason, signals }`
|
|
11
|
+
* - `createAction()` → API returns `{ action, action_id, decision, ... }`
|
|
12
|
+
* - `waitForApproval()` → `{ action }`
|
|
13
|
+
*/
|
|
14
|
+
declare module 'dashclaw' {
|
|
15
|
+
export interface GuardDecision {
|
|
16
|
+
decision: 'allow' | 'block' | 'warn' | 'require_approval';
|
|
17
|
+
action_id: string;
|
|
18
|
+
reason?: string;
|
|
19
|
+
signals?: string[];
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export interface ActionRecord {
|
|
23
|
+
action_id?: string;
|
|
24
|
+
id?: string;
|
|
25
|
+
status?: string;
|
|
26
|
+
approved_by?: string | null;
|
|
27
|
+
error_message?: string | null;
|
|
28
|
+
[key: string]: unknown;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** Envelope returned by `POST /api/actions`. */
|
|
32
|
+
export interface CreateActionResult {
|
|
33
|
+
action: ActionRecord;
|
|
34
|
+
action_id?: string;
|
|
35
|
+
[key: string]: unknown;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export interface WaitForApprovalResult {
|
|
39
|
+
action: ActionRecord;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export interface DashClawOptions {
|
|
43
|
+
baseUrl: string;
|
|
44
|
+
apiKey: string;
|
|
45
|
+
agentId: string;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export class DashClaw {
|
|
49
|
+
constructor(opts: DashClawOptions);
|
|
50
|
+
guard(context: Record<string, unknown>): Promise<GuardDecision>;
|
|
51
|
+
createAction(action: Record<string, unknown>): Promise<CreateActionResult>;
|
|
52
|
+
updateOutcome(
|
|
53
|
+
actionId: string,
|
|
54
|
+
outcome: Record<string, unknown>
|
|
55
|
+
): Promise<unknown>;
|
|
56
|
+
waitForApproval(
|
|
57
|
+
actionId: string,
|
|
58
|
+
opts?: { timeout?: number; interval?: number }
|
|
59
|
+
): Promise<WaitForApprovalResult>;
|
|
60
|
+
recordAssumption(assumption: Record<string, unknown>): Promise<unknown>;
|
|
61
|
+
createSession(
|
|
62
|
+
agentId?: string,
|
|
63
|
+
workspace?: string,
|
|
64
|
+
branch?: string | null
|
|
65
|
+
): Promise<{ session?: { id?: string }; [key: string]: unknown }>;
|
|
66
|
+
updateSession(
|
|
67
|
+
sessionId: string,
|
|
68
|
+
updates: Record<string, unknown>
|
|
69
|
+
): Promise<unknown>;
|
|
70
|
+
createPairing(
|
|
71
|
+
publicKeyPem: string,
|
|
72
|
+
opts?: { algorithm?: string; agentName?: string }
|
|
73
|
+
): Promise<{ pairing?: { id?: string; status?: string }; [key: string]: unknown }>;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export class ApprovalDeniedError extends Error {
|
|
77
|
+
status: string;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export class GuardBlockedError extends Error {
|
|
81
|
+
decision: GuardDecision;
|
|
82
|
+
}
|
|
83
|
+
}
|