@dashclaw/openclaw-plugin 1.6.0 → 1.6.1

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 CHANGED
@@ -124,6 +124,7 @@ empty because the wait target didn't exist. Fixed in `1.0.1`.
124
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`). |
125
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. |
126
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. |
127
+ | `approvalWaitMs` | number | `60000` | How long a `require_approval` decision waits for the operator before blocking with a retry hint. Keep it below your runtime's per-tool-call watchdog — Codex's embedded dynamic-tool RPC kills calls at ~90s, which would silently drop the tool result instead of blocking cleanly. The approval stays open ~300s server-side, so the operator can approve after the wait and the agent's retry of the same call passes (guard approval grant + idempotent `createAction`). |
127
128
 
128
129
  ## Automatic identity pairing
129
130
 
package/dist/index.js CHANGED
@@ -59,6 +59,7 @@ function resolveConfig(raw) {
59
59
  const autoPairing = cfg.autoPairing !== false; // default true
60
60
  const riskScoreDefault = numberFromConfig(cfg.riskScoreDefault, 50);
61
61
  const highRiskTools = stringSetFromConfig(cfg.highRiskTools);
62
+ const approvalWaitMs = numberFromConfig(cfg.approvalWaitMs, 60_000, false) || 60_000;
62
63
  const dashclawUrl = firstString(cfg.dashclawUrl, cfg.baseUrl, env.DASHCLAW_BASE_URL, env.DASHCLAW_URL);
63
64
  const dashclawApiKey = firstString(cfg.dashclawApiKey, cfg.apiKey, env.DASHCLAW_API_KEY);
64
65
  const agentId = firstString(cfg.agentId, env.DASHCLAW_AGENT_ID) || 'openclaw';
@@ -72,6 +73,7 @@ function resolveConfig(raw) {
72
73
  autoPairing,
73
74
  riskScoreDefault,
74
75
  highRiskTools,
76
+ approvalWaitMs,
75
77
  };
76
78
  }
77
79
  // ---------------------------------------------------------------------------
@@ -457,7 +459,7 @@ async function openActionRecord(ctx) {
457
459
  const created = await createGovernanceAction(ctx);
458
460
  if ('result' in created)
459
461
  return created.result;
460
- const approval = await waitForRequiredApproval(ctx.client, ctx.decision, created.value);
462
+ const approval = await waitForRequiredApproval(ctx, created.value);
461
463
  if (approval)
462
464
  return approval;
463
465
  rememberPendingAction(ctx.key, created.value.actionId, ctx.runId);
@@ -495,13 +497,17 @@ async function createGovernanceAction(ctx) {
495
497
  return { result: undefined };
496
498
  }
497
499
  }
498
- async function waitForRequiredApproval(client, decision, created) {
499
- const needsApproval = decision.decision === 'require_approval' ||
500
+ async function waitForRequiredApproval(ctx, created) {
501
+ const needsApproval = ctx.decision.decision === 'require_approval' ||
500
502
  created.status === 'pending_approval';
501
503
  if (!needsApproval || !created.actionId)
502
504
  return undefined;
505
+ const timeout = ctx.config.approvalWaitMs;
503
506
  try {
504
- const { action } = await client.waitForApproval(created.actionId);
507
+ const { action } = await ctx.client.waitForApproval(created.actionId, {
508
+ timeout,
509
+ interval: approvalPollInterval(timeout),
510
+ });
505
511
  if (isApproved(action))
506
512
  return undefined;
507
513
  return {
@@ -510,12 +516,32 @@ async function waitForRequiredApproval(client, decision, created) {
510
516
  };
511
517
  }
512
518
  catch (err) {
519
+ if (isApprovalTimeout(err)) {
520
+ // The server keeps the approval open past this bounded wait
521
+ // (approval_wait_seconds = 300): the operator can still approve, and a
522
+ // retry of the same call passes via the guard's approval grant and
523
+ // createAction's idempotent-retry dedupe instead of opening a duplicate.
524
+ return {
525
+ block: true,
526
+ blockReason: `Approval not received within ${Math.round(timeout / 1000)}s — ` +
527
+ `action ${created.actionId} is still awaiting the operator. ` +
528
+ `Approve it at ${ctx.config.dashclawUrl}/approvals, then retry this tool call.`,
529
+ };
530
+ }
513
531
  return {
514
532
  block: true,
515
533
  blockReason: `Approval denied or wait failed: ${errorMessage(err) || 'denied'}`,
516
534
  };
517
535
  }
518
536
  }
537
+ /** Sample the approval at least ~4 times inside the window; keep the SDK's 5s ceiling. */
538
+ function approvalPollInterval(timeoutMs) {
539
+ return Math.min(5000, Math.max(50, Math.floor(timeoutMs / 4)));
540
+ }
541
+ /** Matches the SDK's approval-timeout error (a plain Error, distinct from denial). */
542
+ function isApprovalTimeout(err) {
543
+ return errorMessage(err).startsWith('Timed out waiting for approval');
544
+ }
519
545
  function rememberPendingAction(key, actionId, runId) {
520
546
  if (!actionId)
521
547
  return;
@@ -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.0",
5
+ "version": "1.6.1",
6
6
  "entry": "src/index.ts",
7
7
  "main": "./src/index.ts",
8
8
  "configSchema": {
@@ -55,6 +55,11 @@
55
55
  "items": { "type": "string" },
56
56
  "default": [],
57
57
  "description": "Tool names that should always get risk_score 80+ (e.g. bash, exec, deploy)"
58
+ },
59
+ "approvalWaitMs": {
60
+ "type": "number",
61
+ "default": 60000,
62
+ "description": "How long (ms) a require_approval decision waits for the operator before blocking with a retry hint. Keep below your runtime's per-tool-call watchdog (Codex embedded dynamic-tool RPC kills calls at ~90s). The DashClaw approval stays open ~300s server-side, so approving after the wait and retrying the call still works."
58
63
  }
59
64
  }
60
65
  },
@@ -68,6 +73,7 @@
68
73
  "failClosed": { "label": "Fail-closed when DashClaw unreachable", "advanced": true },
69
74
  "autoPairing": { "label": "Auto-answer pairing requests", "advanced": true },
70
75
  "riskScoreDefault": { "label": "Default risk score", "advanced": true },
71
- "highRiskTools": { "label": "High-risk tool names", "advanced": true }
76
+ "highRiskTools": { "label": "High-risk tool names", "advanced": true },
77
+ "approvalWaitMs": { "label": "Approval wait (ms)", "advanced": true }
72
78
  }
73
79
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dashclaw/openclaw-plugin",
3
- "version": "1.6.0",
3
+ "version": "1.6.1",
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",
package/src/HOOK.md CHANGED
@@ -10,7 +10,7 @@ Intercepts every OpenClaw tool call through a four-step governance loop:
10
10
 
11
11
  1. **Guard** — `before_tool_call` sends the tool name, risk score, and a 500-character parameter summary to DashClaw `/api/guard`. Policies decide `allow`, `warn`, `block`, or `require_approval`.
12
12
  2. **Record** — On `allow`/`warn`/`require_approval`, the hook opens a governance record via `/api/actions`. The server is authoritative — it may upgrade an `allow` decision to `pending_approval` for capabilities that require human review.
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.
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. The wait is bounded by `approvalWaitMs` (default 60s — under Codex's ~90s per-tool-call RPC watchdog); on timeout the call blocks with a retry hint while the approval stays open ~300s server-side, so approving late and retrying the same call still works.
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
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.
@@ -27,7 +27,7 @@ The plugin accepts three interchangeable configuration shapes — pick whichever
27
27
 
28
28
  Precedence is `plugin config > env vars`. If env vars are set before the gateway starts, the plugin config can omit URL and API key entirely.
29
29
 
30
- See the `configSchema` section in `openclaw.plugin.json` for the full list of optional fields (`agentId`, `failClosed`, `riskScoreDefault`, `highRiskTools`).
30
+ See the `configSchema` section in `openclaw.plugin.json` for the full list of optional fields (`agentId`, `failClosed`, `riskScoreDefault`, `highRiskTools`, `approvalWaitMs`).
31
31
 
32
32
  ## Failure modes
33
33
 
package/src/index.ts CHANGED
@@ -48,6 +48,13 @@ interface PluginConfig {
48
48
  autoPairing: boolean;
49
49
  riskScoreDefault: number;
50
50
  highRiskTools: ReadonlySet<string>;
51
+ // Bounded human-approval wait. Codex's embedded dynamic-tool RPC enforces a
52
+ // per-call watchdog (~90s): a longer synchronous wait is killed mid-flight
53
+ // and the tool result (e.g. an outbound message) is silently dropped, so the
54
+ // default stays under that ceiling. The server-side approval window
55
+ // (approval_wait_seconds, 300s) is intentionally longer — see
56
+ // waitForRequiredApproval for the retry-after-approval path.
57
+ approvalWaitMs: number;
51
58
  }
52
59
 
53
60
  /**
@@ -93,6 +100,7 @@ function resolveConfig(raw: Record<string, unknown> | undefined): PluginConfig {
93
100
  const autoPairing = cfg.autoPairing !== false; // default true
94
101
  const riskScoreDefault = numberFromConfig(cfg.riskScoreDefault, 50);
95
102
  const highRiskTools = stringSetFromConfig(cfg.highRiskTools);
103
+ const approvalWaitMs = numberFromConfig(cfg.approvalWaitMs, 60_000, false) || 60_000;
96
104
 
97
105
  const dashclawUrl = firstString(
98
106
  cfg.dashclawUrl,
@@ -120,6 +128,7 @@ function resolveConfig(raw: Record<string, unknown> | undefined): PluginConfig {
120
128
  autoPairing,
121
129
  riskScoreDefault,
122
130
  highRiskTools,
131
+ approvalWaitMs,
123
132
  };
124
133
  }
125
134
 
@@ -705,7 +714,7 @@ async function openActionRecord(ctx: OpenActionContext): Promise<HookResult> {
705
714
  const created = await createGovernanceAction(ctx);
706
715
  if ('result' in created) return created.result;
707
716
 
708
- const approval = await waitForRequiredApproval(ctx.client, ctx.decision, created.value);
717
+ const approval = await waitForRequiredApproval(ctx, created.value);
709
718
  if (approval) return approval;
710
719
  rememberPendingAction(ctx.key, created.value.actionId, ctx.runId);
711
720
  return;
@@ -747,23 +756,39 @@ async function createGovernanceAction(
747
756
  }
748
757
 
749
758
  async function waitForRequiredApproval(
750
- client: DashClaw,
751
- decision: GuardDecision,
759
+ ctx: OpenActionContext,
752
760
  created: CreatedAction,
753
761
  ): Promise<HookBlockResult | undefined> {
754
762
  const needsApproval =
755
- decision.decision === 'require_approval' ||
763
+ ctx.decision.decision === 'require_approval' ||
756
764
  created.status === 'pending_approval';
757
765
  if (!needsApproval || !created.actionId) return undefined;
758
766
 
767
+ const timeout = ctx.config.approvalWaitMs;
759
768
  try {
760
- const { action } = await client.waitForApproval(created.actionId);
769
+ const { action } = await ctx.client.waitForApproval(created.actionId, {
770
+ timeout,
771
+ interval: approvalPollInterval(timeout),
772
+ });
761
773
  if (isApproved(action)) return undefined;
762
774
  return {
763
775
  block: true,
764
776
  blockReason: action?.error_message || 'Action denied by operator',
765
777
  };
766
778
  } catch (err) {
779
+ if (isApprovalTimeout(err)) {
780
+ // The server keeps the approval open past this bounded wait
781
+ // (approval_wait_seconds = 300): the operator can still approve, and a
782
+ // retry of the same call passes via the guard's approval grant and
783
+ // createAction's idempotent-retry dedupe instead of opening a duplicate.
784
+ return {
785
+ block: true,
786
+ blockReason:
787
+ `Approval not received within ${Math.round(timeout / 1000)}s — ` +
788
+ `action ${created.actionId} is still awaiting the operator. ` +
789
+ `Approve it at ${ctx.config.dashclawUrl}/approvals, then retry this tool call.`,
790
+ };
791
+ }
767
792
  return {
768
793
  block: true,
769
794
  blockReason: `Approval denied or wait failed: ${errorMessage(err) || 'denied'}`,
@@ -771,6 +796,16 @@ async function waitForRequiredApproval(
771
796
  }
772
797
  }
773
798
 
799
+ /** Sample the approval at least ~4 times inside the window; keep the SDK's 5s ceiling. */
800
+ function approvalPollInterval(timeoutMs: number): number {
801
+ return Math.min(5000, Math.max(50, Math.floor(timeoutMs / 4)));
802
+ }
803
+
804
+ /** Matches the SDK's approval-timeout error (a plain Error, distinct from denial). */
805
+ function isApprovalTimeout(err: unknown): boolean {
806
+ return errorMessage(err).startsWith('Timed out waiting for approval');
807
+ }
808
+
774
809
  function rememberPendingAction(
775
810
  key: string,
776
811
  actionId: string | undefined,