openclaw-zero-agency 0.0.0-stage → 0.2.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Apurva Sukant
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,38 @@
1
- # Temporary Holding Version
1
+ # openclaw-zero-agency
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Capability routing and a receipt gate for OpenClaw fleets.
4
+
5
+ **Packs inform judgement; they never confer authority.**
6
+
7
+ - `zero_agency_route` — match a task to a capability pack, issue a receipt
8
+ - `zero_agency_status` — registry version, capability count, gate mode
9
+ - `before_tool_call` gate — consequential tools require a receipt
10
+
11
+ ## Install
12
+
13
+ ```bash
14
+ openclaw plugins install openclaw-zero-agency
15
+ ```
16
+
17
+ ## Configure
18
+
19
+ ```json
20
+ {
21
+ "plugins": {
22
+ "entries": {
23
+ "zero-agency": {
24
+ "config": {
25
+ "registryPath": "/opt/zero-agency/registry/capabilities.json",
26
+ "telemetryPath": "/var/log/zero-agency/events.jsonl",
27
+ "gateMode": "advisory",
28
+ "consequentialTools": ["exec", "apply_patch"]
29
+ }
30
+ }
31
+ }
32
+ }
33
+ }
34
+ ```
35
+
36
+ `gateMode`: `off` | `advisory` (log only) | `enforce` (require approval, fail-closed).
37
+
38
+ Requires `openclaw >= 2026.10.1`.
package/dist/gate.js ADDED
@@ -0,0 +1,51 @@
1
+ // Zero Agency receipt gate. Consequential tool calls require a routing receipt.
2
+ import { definePluginEntry } from "openclaw/plugin-sdk/plugin-entry";
3
+ import { appendFile, mkdir } from "node:fs/promises";
4
+ import { dirname } from "node:path";
5
+ import { get, prune } from "./receipts.js";
6
+ async function telemetry(path, record) {
7
+ if (!path)
8
+ return;
9
+ try {
10
+ await mkdir(dirname(path), { recursive: true });
11
+ await appendFile(path, JSON.stringify({ ts: new Date().toISOString(), ...record }) + "\n");
12
+ }
13
+ catch { /* never break a turn */ }
14
+ }
15
+ export default definePluginEntry({
16
+ id: "zero-agency-gate",
17
+ name: "Zero Agency Gate",
18
+ description: "Requires a Zero Agency routing receipt before consequential tool calls.",
19
+ register(api) {
20
+ const cfg = api.config ?? api.pluginConfig ?? {};
21
+ const mode = cfg.gateMode ?? "advisory";
22
+ const tools = cfg.consequentialTools ?? ["exec", "apply_patch"];
23
+ const tel = cfg.telemetryPath;
24
+ api.on("before_tool_call", async (event, ctx) => {
25
+ if (mode === "off")
26
+ return undefined;
27
+ const runId = event?.runId ?? ctx?.runId ?? "unknown-run";
28
+ prune();
29
+ const r = get(runId);
30
+ if (r) {
31
+ await telemetry(tel, { kind: "gate", decision: "receipt-ok", tool: event?.toolName, runId, receipt: r.id });
32
+ return undefined;
33
+ }
34
+ await telemetry(tel, { kind: "gate", decision: mode === "enforce" ? "blocked" : "advisory-miss", tool: event?.toolName, runId });
35
+ if (mode !== "enforce")
36
+ return undefined;
37
+ return {
38
+ requireApproval: {
39
+ title: `Zero Agency: no capability receipt (${event?.toolName ?? "tool"})`,
40
+ description: "Consequential call without a capability lookup. Approve for this call only, or deny and run zero_agency_route first.",
41
+ severity: "warning",
42
+ timeoutMs: 120000,
43
+ allowedDecisions: ["allow-once", "deny"],
44
+ onResolution: async (decision) => {
45
+ await telemetry(tel, { kind: "gate", decision, tool: event?.toolName, runId, receipt: null });
46
+ },
47
+ },
48
+ };
49
+ }, { matcher: tools, priority: 50 });
50
+ },
51
+ });
@@ -0,0 +1,22 @@
1
+ const KEY = Symbol.for("openclaw.zero-agency.receipts.v1");
2
+ function store() {
3
+ const g = globalThis;
4
+ if (!g[KEY])
5
+ g[KEY] = new Map();
6
+ return g[KEY];
7
+ }
8
+ export function put(runId, receipt) {
9
+ store().set(runId, receipt);
10
+ }
11
+ export function get(runId) {
12
+ return store().get(runId);
13
+ }
14
+ export function prune() {
15
+ const t = Date.now();
16
+ for (const [k, v] of store())
17
+ if (v.expires < t)
18
+ store().delete(k);
19
+ }
20
+ export function size() {
21
+ return store().size;
22
+ }
package/dist/tools.js ADDED
@@ -0,0 +1,143 @@
1
+ // Zero Agency — capability routing tools. Packs inform judgement; they never confer authority.
2
+ import { Type } from "typebox";
3
+ import { defineToolPlugin } from "openclaw/plugin-sdk/tool-plugin";
4
+ import { readFile, appendFile, mkdir } from "node:fs/promises";
5
+ import { statSync } from "node:fs";
6
+ import { createHash, randomUUID } from "node:crypto";
7
+ import { dirname } from "node:path";
8
+ import { put, prune, size } from "./receipts.js";
9
+ const cache = new Map();
10
+ const norm = (s) => String(s ?? "").toLowerCase().replace(/[^a-z0-9\s-]/g, " ").replace(/\s+/g, " ").trim();
11
+ async function loadRegistry(path) {
12
+ const st = statSync(path);
13
+ const hit = cache.get(path);
14
+ if (hit && hit.mtimeMs === st.mtimeMs)
15
+ return hit.data;
16
+ const data = JSON.parse(await readFile(path, "utf8"));
17
+ cache.set(path, { mtimeMs: st.mtimeMs, data });
18
+ return data;
19
+ }
20
+ function score(cap, q) {
21
+ let s = 0;
22
+ const hits = [];
23
+ for (const t of cap.triggers ?? []) {
24
+ const nt = norm(t);
25
+ if (nt && q.includes(nt)) {
26
+ s += 3;
27
+ hits.push(t);
28
+ continue;
29
+ }
30
+ const words = nt.split(" ").filter((w) => w.length > 3);
31
+ const overlap = words.filter((w) => q.includes(w)).length;
32
+ if (words.length && overlap === words.length) {
33
+ s += 2;
34
+ hits.push(t);
35
+ }
36
+ else if (overlap)
37
+ s += overlap / words.length;
38
+ }
39
+ const dw = norm(cap.description).split(" ").filter((w) => w.length > 4);
40
+ s += 0.5 * dw.filter((w) => q.includes(w)).length;
41
+ return { score: s, hits };
42
+ }
43
+ async function telemetry(path, record) {
44
+ if (!path)
45
+ return;
46
+ try {
47
+ await mkdir(dirname(path), { recursive: true });
48
+ await appendFile(path, JSON.stringify({ ts: new Date().toISOString(), ...record }) + "\n");
49
+ }
50
+ catch { /* telemetry must never break a turn */ }
51
+ }
52
+ export default defineToolPlugin({
53
+ id: "zero-agency",
54
+ name: "Zero Agency",
55
+ description: "Capability routing for the fleet. Packs inform judgement; they never confer authority.",
56
+ configSchema: Type.Object({
57
+ registryPath: Type.String({ description: "Absolute path to capabilities.json (read-only)." }),
58
+ telemetryPath: Type.Optional(Type.String({ description: "JSONL telemetry path." })),
59
+ receiptTtlMs: Type.Optional(Type.Integer({ minimum: 1000 })),
60
+ gateMode: Type.Optional(Type.Union([Type.Literal("off"), Type.Literal("advisory"), Type.Literal("enforce")], { description: "Receipt gate mode (default advisory)." })),
61
+ consequentialTools: Type.Optional(Type.Array(Type.String(), { description: "Tool ids gated by receipt." })),
62
+ }),
63
+ tools: (tool) => [
64
+ tool({
65
+ name: "zero_agency_route",
66
+ label: "Zero Agency Route",
67
+ description: "Find the capability pack governing a domain task. Call before acting on security review, release verification or incident triage. Issues a receipt the gate accepts.",
68
+ parameters: Type.Object({
69
+ task: Type.String({ description: "The task or question, in natural language." }),
70
+ limit: Type.Optional(Type.Integer({ minimum: 1, maximum: 5 })),
71
+ }),
72
+ outputSchema: Type.Object({
73
+ candidates: Type.Array(Type.Object({
74
+ id: Type.String(), pack: Type.String(), score: Type.Number(), triggers: Type.Array(Type.String()),
75
+ })),
76
+ receipt: Type.Union([Type.String(), Type.Null()]),
77
+ note: Type.String(),
78
+ }, { additionalProperties: false }),
79
+ async execute(params, config, context) {
80
+ context?.signal?.throwIfAborted?.();
81
+ const q = norm(params.task);
82
+ const limit = params.limit ?? 3;
83
+ const ttl = config.receiptTtlMs ?? 900000;
84
+ let candidates = [];
85
+ let note = "";
86
+ try {
87
+ const reg = await loadRegistry(config.registryPath);
88
+ candidates = (reg.capabilities ?? [])
89
+ .map((c) => ({ c, ...score(c, q) }))
90
+ .filter((x) => x.score > 0)
91
+ .sort((a, b) => b.score - a.score)
92
+ .slice(0, limit)
93
+ .map((x) => ({ id: x.c.id, pack: x.c.pack, score: Number(x.score.toFixed(2)), triggers: x.hits }));
94
+ note = candidates.length
95
+ ? `load ${candidates[0].pack} before acting`
96
+ : "no capability matched; if this action is consequential, stop and ask";
97
+ }
98
+ catch (e) {
99
+ note = `registry unavailable: ${e?.message ?? "unknown"}`;
100
+ }
101
+ let receipt = null;
102
+ if (candidates.length) {
103
+ const runId = context?.runId ?? context?.sessionId ?? "unknown-run";
104
+ receipt = createHash("sha256").update(`${runId}:${candidates[0].id}:${Date.now()}:${randomUUID()}`).digest("hex").slice(0, 16);
105
+ put(runId, { id: receipt, pack: candidates[0].pack, at: Date.now(), expires: Date.now() + ttl });
106
+ prune();
107
+ }
108
+ await telemetry(config.telemetryPath, {
109
+ kind: "route", agent: context?.agentId ?? null,
110
+ session: context?.sessionId ?? null, query: params.task.slice(0, 200),
111
+ selected: candidates[0]?.id ?? null, candidates: candidates.length, receipt,
112
+ });
113
+ return { candidates, receipt, note };
114
+ },
115
+ }),
116
+ tool({
117
+ name: "zero_agency_status",
118
+ label: "Zero Agency Status",
119
+ description: "Report the Zero Agency registry state: capability count, token total and live receipts.",
120
+ parameters: Type.Object({}),
121
+ outputSchema: Type.Object({
122
+ registry: Type.String(), capabilities: Type.Integer(), tokens: Type.Integer(),
123
+ receipts: Type.Integer(), registryError: Type.Union([Type.String(), Type.Null()]),
124
+ }, { additionalProperties: false }),
125
+ async execute(_params, config) {
126
+ try {
127
+ const reg = await loadRegistry(config.registryPath);
128
+ const caps = reg.capabilities ?? [];
129
+ return {
130
+ registry: config.registryPath,
131
+ capabilities: caps.length,
132
+ tokens: caps.reduce((s, c) => s + (c.tokens ?? 0), 0),
133
+ receipts: size(),
134
+ registryError: null,
135
+ };
136
+ }
137
+ catch (e) {
138
+ return { registry: config.registryPath, capabilities: 0, tokens: 0, receipts: size(), registryError: e?.message ?? "unknown" };
139
+ }
140
+ },
141
+ }),
142
+ ],
143
+ });
@@ -0,0 +1,59 @@
1
+ {
2
+ "id": "zero-agency",
3
+ "name": "Zero Agency",
4
+ "description": "Capability routing for the fleet. Packs inform judgement; they never confer authority.",
5
+ "activation": {
6
+ "onStartup": true
7
+ },
8
+ "configSchema": {
9
+ "type": "object",
10
+ "required": [
11
+ "registryPath"
12
+ ],
13
+ "properties": {
14
+ "registryPath": {
15
+ "type": "string",
16
+ "description": "Absolute path to capabilities.json (read-only)."
17
+ },
18
+ "telemetryPath": {
19
+ "type": "string",
20
+ "description": "JSONL telemetry path."
21
+ },
22
+ "receiptTtlMs": {
23
+ "type": "integer",
24
+ "minimum": 1000
25
+ },
26
+ "gateMode": {
27
+ "anyOf": [
28
+ {
29
+ "type": "string",
30
+ "const": "off"
31
+ },
32
+ {
33
+ "type": "string",
34
+ "const": "advisory"
35
+ },
36
+ {
37
+ "type": "string",
38
+ "const": "enforce"
39
+ }
40
+ ],
41
+ "description": "Receipt gate mode (default advisory)."
42
+ },
43
+ "consequentialTools": {
44
+ "type": "array",
45
+ "items": {
46
+ "type": "string"
47
+ },
48
+ "description": "Tool ids gated by receipt."
49
+ }
50
+ }
51
+ },
52
+ "version": "0.2.0",
53
+ "contracts": {
54
+ "tools": [
55
+ "zero_agency_route",
56
+ "zero_agency_status"
57
+ ]
58
+ }
59
+ }
package/package.json CHANGED
@@ -1,6 +1,46 @@
1
1
  {
2
2
  "name": "openclaw-zero-agency",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.2.0",
4
+ "description": "Zero Agency: capability packs, programmatic routing and a receipt gate for OpenClaw. Packs inform judgement; they never confer authority.",
5
+ "type": "module",
6
+ "main": "./dist/index.js",
7
+ "license": "MIT",
8
+ "keywords": [
9
+ "openclaw",
10
+ "openclaw-plugin",
11
+ "agents",
12
+ "capability-routing",
13
+ "governance"
14
+ ],
15
+ "files": [
16
+ "dist",
17
+ "openclaw.plugin.json",
18
+ "README.md",
19
+ "LICENSE"
20
+ ],
21
+ "scripts": {
22
+ "build": "tsc -p tsconfig.build.json",
23
+ "typecheck": "tsc --noEmit -p tsconfig.json",
24
+ "prepack": "npm run build"
25
+ },
26
+ "dependencies": {
27
+ "typebox": "^1.4.3"
28
+ },
29
+ "peerDependencies": {
30
+ "openclaw": ">=2026.10.1"
31
+ },
32
+ "devDependencies": {
33
+ "@types/node": "^22.0.0",
34
+ "typescript": "^7.0.2"
35
+ },
36
+ "openclaw": {
37
+ "extensions": [
38
+ "./dist/tools.js",
39
+ "./dist/gate.js"
40
+ ],
41
+ "compat": {
42
+ "pluginApi": ">=2026.10.1",
43
+ "minGatewayVersion": "2026.10.1"
44
+ }
45
+ }
46
+ }