@dashclaw/openclaw-plugin 1.5.0 → 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 +20 -0
- package/dist/auto-pairing.d.ts +29 -0
- package/dist/auto-pairing.js +119 -0
- package/dist/index.js +6 -0
- package/openclaw.plugin.json +7 -1
- package/package.json +1 -1
- package/src/auto-pairing.ts +150 -0
- package/src/dashclaw.d.ts +4 -0
- package/src/index.ts +8 -0
package/README.md
CHANGED
|
@@ -121,9 +121,29 @@ empty because the wait target didn't exist. Fixed in `1.0.1`.
|
|
|
121
121
|
| `agentId` | string | `"openclaw"` | Identifier this OpenClaw instance reports to DashClaw. |
|
|
122
122
|
| `defaultModel` | string | `""` | Fallback model id (e.g. `claude-sonnet-5`, `openai-codex/gpt-5.4`) used when `llm_output` events don't include a `model` field. Without this, unpriced turns land `tokens_in`/`tokens_out` but `cost_estimate` stays `$0`. Env var: `DASHCLAW_DEFAULT_MODEL`. |
|
|
123
123
|
| `failClosed` | boolean | `true` | If DashClaw is unreachable, block the tool call. Set `false` to fail open. |
|
|
124
|
+
| `autoPairing` | boolean | `true` | Automatically answer operator pairing requests from the DashClaw `/identities` page. 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`). |
|
|
124
125
|
| `riskScoreDefault` | number | `50` | Fallback risk score for tool calls the classifier doesn't recognize. Recognized commands (git, curl, rm, npm, etc.) compute their own risk score automatically. |
|
|
125
126
|
| `highRiskTools` | string[] | `[]` | Tool names that should always start at risk score 85 before classification. The classifier may raise the score further (e.g. `rm -rf` → 90) but will never lower it below 85 for tools in this list. |
|
|
126
127
|
|
|
128
|
+
## Automatic identity pairing
|
|
129
|
+
|
|
130
|
+
When an admin clicks **Request pairing** for this agent on the DashClaw
|
|
131
|
+
`/identities` page, the plugin answers on the agent's next tool call — no LLM
|
|
132
|
+
involvement:
|
|
133
|
+
|
|
134
|
+
1. It reads the agent's unread DashClaw inbox and finds the
|
|
135
|
+
`dashclaw.pairing_request` directive.
|
|
136
|
+
2. It generates an RSA-2048 keypair locally. The private key is written to
|
|
137
|
+
`~/.dashclaw/identity/<agentId>.pem` (mode 600) and never leaves the
|
|
138
|
+
machine.
|
|
139
|
+
3. It POSTs the public key to `/api/pairings` and marks the message read.
|
|
140
|
+
|
|
141
|
+
The pairing then appears under **Pending Pairings** on `/identities` for the
|
|
142
|
+
admin's one-click approval — approval is what creates the identity. Disable
|
|
143
|
+
with `autoPairing: false`. To rotate keys, delete the `.pem` file and click
|
|
144
|
+
**Request pairing** again. Auto-pairing is fire-and-forget: it runs once per
|
|
145
|
+
gateway process and can never block or fail a tool call.
|
|
146
|
+
|
|
127
147
|
## Fail-closed vs fail-open
|
|
128
148
|
|
|
129
149
|
- **`failClosed: true` (default)** — if DashClaw is unreachable for any reason (network error, 5xx, timeout), the plugin blocks the tool call with a clear reason. This is the safe default for governance: no decisions slip through unrecorded.
|
|
@@ -0,0 +1,29 @@
|
|
|
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
|
+
import type { DashClaw } from 'dashclaw';
|
|
19
|
+
export declare const PAIRING_REQUEST_KIND = "dashclaw.pairing_request";
|
|
20
|
+
export interface AutoPairConfig {
|
|
21
|
+
dashclawUrl: string;
|
|
22
|
+
dashclawApiKey: string;
|
|
23
|
+
agentId: string;
|
|
24
|
+
autoPairing: boolean;
|
|
25
|
+
}
|
|
26
|
+
/** Test-only: reset the per-process attempt guard. */
|
|
27
|
+
export declare function __resetAutoPairing(): void;
|
|
28
|
+
export declare function identityKeyPath(agentId: string): string;
|
|
29
|
+
export declare function maybeAutoPair(client: DashClaw, config: AutoPairConfig): Promise<void>;
|
|
@@ -0,0 +1,119 @@
|
|
|
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
|
+
import { existsSync, mkdirSync, writeFileSync } from 'node:fs';
|
|
19
|
+
import { homedir } from 'node:os';
|
|
20
|
+
import { dirname, join } from 'node:path';
|
|
21
|
+
import { generateKeyPairSync } from 'node:crypto';
|
|
22
|
+
export const PAIRING_REQUEST_KIND = 'dashclaw.pairing_request';
|
|
23
|
+
// One attempt per gateway process per (url, agent). Added BEFORE the first
|
|
24
|
+
// await so concurrent tool calls cannot double-run the flow. Per-process on
|
|
25
|
+
// purpose: a transient failure retries at the next gateway start.
|
|
26
|
+
let attempted = new Set();
|
|
27
|
+
/** Test-only: reset the per-process attempt guard. */
|
|
28
|
+
export function __resetAutoPairing() {
|
|
29
|
+
attempted = new Set();
|
|
30
|
+
}
|
|
31
|
+
export function identityKeyPath(agentId) {
|
|
32
|
+
const safe = agentId.replace(/[^A-Za-z0-9._-]/g, '_');
|
|
33
|
+
return join(homedir(), '.dashclaw', 'identity', `${safe}.pem`);
|
|
34
|
+
}
|
|
35
|
+
/** Same fence contract as app/lib/pairing-request.ts. */
|
|
36
|
+
function directiveTargets(body, agentId) {
|
|
37
|
+
if (typeof body !== 'string')
|
|
38
|
+
return false;
|
|
39
|
+
const match = body.match(/```json\s*([\s\S]*?)```/);
|
|
40
|
+
if (!match || !match[1])
|
|
41
|
+
return false;
|
|
42
|
+
try {
|
|
43
|
+
const parsed = JSON.parse(match[1]);
|
|
44
|
+
return parsed?.kind === PAIRING_REQUEST_KIND && parsed.agent_id === agentId;
|
|
45
|
+
}
|
|
46
|
+
catch {
|
|
47
|
+
return false;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
function apiUrl(config, pathAndQuery) {
|
|
51
|
+
return `${config.dashclawUrl.replace(/\/+$/, '')}${pathAndQuery}`;
|
|
52
|
+
}
|
|
53
|
+
async function fetchUnreadInbox(config) {
|
|
54
|
+
const res = await fetch(apiUrl(config, `/api/messages?agent_id=${encodeURIComponent(config.agentId)}&direction=inbox&unread=true&limit=50`), { headers: { 'x-api-key': config.dashclawApiKey } });
|
|
55
|
+
if (!res.ok)
|
|
56
|
+
throw new Error(`messages GET failed (${res.status})`);
|
|
57
|
+
const data = (await res.json());
|
|
58
|
+
return Array.isArray(data.messages) ? data.messages : [];
|
|
59
|
+
}
|
|
60
|
+
async function markRead(config, messageIds) {
|
|
61
|
+
const res = await fetch(apiUrl(config, '/api/messages'), {
|
|
62
|
+
method: 'PATCH',
|
|
63
|
+
headers: { 'x-api-key': config.dashclawApiKey, 'Content-Type': 'application/json' },
|
|
64
|
+
body: JSON.stringify({ message_ids: messageIds, action: 'read', agent_id: config.agentId }),
|
|
65
|
+
});
|
|
66
|
+
if (!res.ok)
|
|
67
|
+
throw new Error(`messages PATCH failed (${res.status})`);
|
|
68
|
+
}
|
|
69
|
+
export async function maybeAutoPair(client, config) {
|
|
70
|
+
if (!config.autoPairing)
|
|
71
|
+
return;
|
|
72
|
+
const key = `${config.dashclawUrl}|${config.agentId}`;
|
|
73
|
+
if (attempted.has(key))
|
|
74
|
+
return;
|
|
75
|
+
attempted.add(key);
|
|
76
|
+
try {
|
|
77
|
+
const pemPath = identityKeyPath(config.agentId);
|
|
78
|
+
if (existsSync(pemPath)) {
|
|
79
|
+
// Already enrolled or pending. Deleting the pem + clicking Request
|
|
80
|
+
// pairing again is the rotation path.
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
const inbox = await fetchUnreadInbox(config);
|
|
84
|
+
const requests = inbox.filter((m) => directiveTargets(m.body, config.agentId));
|
|
85
|
+
if (requests.length === 0)
|
|
86
|
+
return;
|
|
87
|
+
const { publicKey, privateKey } = generateKeyPairSync('rsa', {
|
|
88
|
+
modulusLength: 2048,
|
|
89
|
+
publicKeyEncoding: { type: 'spki', format: 'pem' },
|
|
90
|
+
privateKeyEncoding: { type: 'pkcs8', format: 'pem' },
|
|
91
|
+
});
|
|
92
|
+
const created = await client.createPairing(publicKey);
|
|
93
|
+
const pairingId = created.pairing?.id ??
|
|
94
|
+
created.id ??
|
|
95
|
+
'(pending)';
|
|
96
|
+
// POST-then-write: a failed POST leaves no pem, so the next gateway
|
|
97
|
+
// start retries cleanly. A failed write AFTER a successful POST is the
|
|
98
|
+
// one loud case — that pending pairing has no usable private key.
|
|
99
|
+
try {
|
|
100
|
+
mkdirSync(dirname(pemPath), { recursive: true });
|
|
101
|
+
writeFileSync(pemPath, privateKey, { mode: 0o600 });
|
|
102
|
+
}
|
|
103
|
+
catch (err) {
|
|
104
|
+
console.warn(`[dashclaw-governance] auto-pairing: submitted pairing ${pairingId} but FAILED to store ` +
|
|
105
|
+
`the private key at ${pemPath}: ${errText(err)}. Reject that pairing on /identities, ` +
|
|
106
|
+
`fix the disk issue, and click Request pairing again.`);
|
|
107
|
+
return; // leave the message unread so a later gateway start retries
|
|
108
|
+
}
|
|
109
|
+
await markRead(config, requests.map((m) => m.id));
|
|
110
|
+
console.log(`[dashclaw-governance] auto-pairing submitted (${pairingId}) — approve it on /identities. ` +
|
|
111
|
+
`Private key stored at ${pemPath} (never sent).`);
|
|
112
|
+
}
|
|
113
|
+
catch (err) {
|
|
114
|
+
console.warn(`[dashclaw-governance] auto-pairing skipped: ${errText(err)}`);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
function errText(err) {
|
|
118
|
+
return err instanceof Error ? err.message : String(err);
|
|
119
|
+
}
|
package/dist/index.js
CHANGED
|
@@ -21,6 +21,7 @@
|
|
|
21
21
|
*/
|
|
22
22
|
import { definePluginEntry, } from 'openclaw/plugin-sdk/plugin-entry';
|
|
23
23
|
import { DashClaw, } from 'dashclaw';
|
|
24
|
+
import { maybeAutoPair } from './auto-pairing.js';
|
|
24
25
|
/**
|
|
25
26
|
* Resolve the DashClaw URL from (in order of precedence):
|
|
26
27
|
* 1. `config.dashclawUrl` (canonical plugin-config key)
|
|
@@ -55,6 +56,7 @@ function resolveConfig(raw) {
|
|
|
55
56
|
const cfg = raw ?? {};
|
|
56
57
|
const env = typeof process !== 'undefined' && process?.env ? process.env : {};
|
|
57
58
|
const failClosed = cfg.failClosed !== false; // default true
|
|
59
|
+
const autoPairing = cfg.autoPairing !== false; // default true
|
|
58
60
|
const riskScoreDefault = numberFromConfig(cfg.riskScoreDefault, 50);
|
|
59
61
|
const highRiskTools = stringSetFromConfig(cfg.highRiskTools);
|
|
60
62
|
const dashclawUrl = firstString(cfg.dashclawUrl, cfg.baseUrl, env.DASHCLAW_BASE_URL, env.DASHCLAW_URL);
|
|
@@ -67,6 +69,7 @@ function resolveConfig(raw) {
|
|
|
67
69
|
agentId,
|
|
68
70
|
defaultModel,
|
|
69
71
|
failClosed,
|
|
72
|
+
autoPairing,
|
|
70
73
|
riskScoreDefault,
|
|
71
74
|
highRiskTools,
|
|
72
75
|
};
|
|
@@ -359,6 +362,9 @@ async function handleBeforeToolCall(event, config) {
|
|
|
359
362
|
const client = getBeforeClient(config);
|
|
360
363
|
if ('result' in client)
|
|
361
364
|
return client.result;
|
|
365
|
+
// Fire-and-forget: answers a pending operator pairing request once per
|
|
366
|
+
// gateway process. Never blocks or fails the tool call.
|
|
367
|
+
void maybeAutoPair(client.value, config);
|
|
362
368
|
await maybeStartSession(event, client.value, config);
|
|
363
369
|
const decision = await guardClassifiedAction(client.value, classification, config);
|
|
364
370
|
if ('result' in decision)
|
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.
|
|
5
|
+
"version": "1.6.0",
|
|
6
6
|
"entry": "src/index.ts",
|
|
7
7
|
"main": "./src/index.ts",
|
|
8
8
|
"configSchema": {
|
|
@@ -40,6 +40,11 @@
|
|
|
40
40
|
"default": true,
|
|
41
41
|
"description": "If true, block tool calls when DashClaw is unreachable. If false, allow them to proceed."
|
|
42
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
|
+
},
|
|
43
48
|
"riskScoreDefault": {
|
|
44
49
|
"type": "number",
|
|
45
50
|
"default": 50,
|
|
@@ -61,6 +66,7 @@
|
|
|
61
66
|
"agentId": { "label": "Agent ID" },
|
|
62
67
|
"defaultModel": { "label": "Default model (for cost pricing)", "placeholder": "openai-codex/gpt-5.4", "advanced": true },
|
|
63
68
|
"failClosed": { "label": "Fail-closed when DashClaw unreachable", "advanced": true },
|
|
69
|
+
"autoPairing": { "label": "Auto-answer pairing requests", "advanced": true },
|
|
64
70
|
"riskScoreDefault": { "label": "Default risk score", "advanced": true },
|
|
65
71
|
"highRiskTools": { "label": "High-risk tool names", "advanced": true }
|
|
66
72
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dashclaw/openclaw-plugin",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.6.0",
|
|
4
4
|
"description": "DashClaw governance for OpenClaw — policy enforcement, human approval, and decision recording for every tool call.",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -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
|
@@ -67,6 +67,10 @@ declare module 'dashclaw' {
|
|
|
67
67
|
sessionId: string,
|
|
68
68
|
updates: Record<string, unknown>
|
|
69
69
|
): Promise<unknown>;
|
|
70
|
+
createPairing(
|
|
71
|
+
publicKeyPem: string,
|
|
72
|
+
opts?: { algorithm?: string; agentName?: string }
|
|
73
|
+
): Promise<{ pairing?: { id?: string; status?: string }; [key: string]: unknown }>;
|
|
70
74
|
}
|
|
71
75
|
|
|
72
76
|
export class ApprovalDeniedError extends Error {
|
package/src/index.ts
CHANGED
|
@@ -29,6 +29,7 @@ import {
|
|
|
29
29
|
type ActionRecord,
|
|
30
30
|
type GuardDecision,
|
|
31
31
|
} from 'dashclaw';
|
|
32
|
+
import { maybeAutoPair } from './auto-pairing.js';
|
|
32
33
|
|
|
33
34
|
// ---------------------------------------------------------------------------
|
|
34
35
|
// Config
|
|
@@ -44,6 +45,7 @@ interface PluginConfig {
|
|
|
44
45
|
// but no cost" failure mode. Empty string disables the fallback.
|
|
45
46
|
defaultModel: string;
|
|
46
47
|
failClosed: boolean;
|
|
48
|
+
autoPairing: boolean;
|
|
47
49
|
riskScoreDefault: number;
|
|
48
50
|
highRiskTools: ReadonlySet<string>;
|
|
49
51
|
}
|
|
@@ -88,6 +90,7 @@ function resolveConfig(raw: Record<string, unknown> | undefined): PluginConfig {
|
|
|
88
90
|
const env = typeof process !== 'undefined' && process?.env ? process.env : {};
|
|
89
91
|
|
|
90
92
|
const failClosed = cfg.failClosed !== false; // default true
|
|
93
|
+
const autoPairing = cfg.autoPairing !== false; // default true
|
|
91
94
|
const riskScoreDefault = numberFromConfig(cfg.riskScoreDefault, 50);
|
|
92
95
|
const highRiskTools = stringSetFromConfig(cfg.highRiskTools);
|
|
93
96
|
|
|
@@ -114,6 +117,7 @@ function resolveConfig(raw: Record<string, unknown> | undefined): PluginConfig {
|
|
|
114
117
|
agentId,
|
|
115
118
|
defaultModel,
|
|
116
119
|
failClosed,
|
|
120
|
+
autoPairing,
|
|
117
121
|
riskScoreDefault,
|
|
118
122
|
highRiskTools,
|
|
119
123
|
};
|
|
@@ -576,6 +580,10 @@ async function handleBeforeToolCall(
|
|
|
576
580
|
const client = getBeforeClient(config);
|
|
577
581
|
if ('result' in client) return client.result;
|
|
578
582
|
|
|
583
|
+
// Fire-and-forget: answers a pending operator pairing request once per
|
|
584
|
+
// gateway process. Never blocks or fails the tool call.
|
|
585
|
+
void maybeAutoPair(client.value, config);
|
|
586
|
+
|
|
579
587
|
await maybeStartSession(event, client.value, config);
|
|
580
588
|
|
|
581
589
|
const decision = await guardClassifiedAction(client.value, classification, config);
|