Approval gate (#68)
Tools flagged "requiresApproval": true in spec/registry-manifest.json (today: fs.write_file) do not run until a host approves the call. The model never approves anything: no approval tool exists in the catalog, tools/list or MCP. The gate is on by default (approval.mode: 'required'); opt out explicitly with approval: { mode: 'off' }.
Pipeline order: resolve → enabled (TOOL_DISABLED wins) → approval → dispatch → envelope.
Flow
- The model calls the tool. The runtime answers
ok: false,error.code = APPROVAL_REQUIRED, withmeta.approvalIdandmeta.approvalExpiresAt. - The host approves or denies out of band:
- SDK:
kit.approve(id)/kit.deny(id)(Node, .NETApprove/Deny, Pythonapprove/deny). - Callback:
runtime.approval.onRequest(req) → true|false(sync or async in Node/.NET, sync in Python). It gets{ approvalId, tool, argsHash, expiresAt }. An exception or any value other thantruemeans deny (fail closed). When a callback is set, no pending id is issued. - MCP stdio (Node and Python): JSON-RPC method
wartools/approvalwith params{ id, decision: 'approve'|'deny', token }. It only exists whenWARTOOLS_ADMIN_TOKENis set; otherwise it returns-32601. A wrong token returns-32001. - MCP SSE (Node):
POST /approvals/{id}withAuthorization: Bearer $WARTOOLS_ADMIN_TOKENand body{ "decision": "approve"|"deny" }. - Workbench:
executeWarTool('workbench/approval', { approvalId, decision }, config). This is a host-only operation and is not in the catalog. - The model retries with identical arguments plus
approvalId. The id is single-use and bound totool + argsHash + sessionId.argsHash= sha256 of the canonical JSON of the args withoutsessionId/approvalId, first 16 hex chars; it is identical in all SDKs.
While the gate is active, tools/list adds an approvalId property to the input schema of gated tools and a retry hint to their description.
Error codes
| Code | recoverable | Meaning |
|---|---|---|
APPROVAL_REQUIRED |
yes | No approvalId given; a pending approval was created (meta.approvalId, meta.approvalExpiresAt). |
APPROVAL_PENDING |
yes | The id exists but the host has not decided yet. |
APPROVAL_DENIED |
no | The host or onRequest denied the call, or the callback threw. |
APPROVAL_EXPIRED |
yes | The TTL elapsed (default 300000 ms, approval.ttlMs). |
APPROVAL_MISMATCH |
no | The id belongs to another tool or different arguments. |
APPROVAL_INVALID |
no | Unknown id, already used (replay), or a different sessionId. |
Configuration
- Node:
WarTools.create({ runtime: { approval: { mode, ttlMs, onRequest }, policyStore, policyScope } }). - Python:
WarTools.create(runtime={"approval": {...}, "policyStore": ..., "policyScope": ...}). - .NET:
new WarToolsOptions { Runtime = new RuntimeOptions { Approval = new ApprovalOptions { ... }, PolicyStore, PolicyScope } }. - CLI:
--approval required|off(defaultrequired); envWARTOOLS_ADMIN_TOKENenables the out-of-band MCP approval channel.
Approval state lives in a PolicyStateStore (in memory by default), separate from KvStore. It never appears in snapshots, checkpoints, kv.* or traces; restoring a checkpoint cannot revive a used approval. Runtimes that share approvals (such as the workbench, which builds one runtime per call) must share a policyStore and a fixed policyScope.
Contract cases live in spec/contracts/runtime.json. Runners map config.runtime.approval.onRequest: "approve" | "deny" | "throw" to a host callback.