openclaw-zero-agency 0.0.0-stage → 0.1.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 +21 -0
- package/README.md +37 -2
- package/dist/index.js +186 -0
- package/openclaw.plugin.json +18 -0
- package/package.json +30 -4
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
|
-
#
|
|
1
|
+
# openclaw-zero-agency
|
|
2
2
|
|
|
3
|
-
|
|
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/index.js
ADDED
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
// Zero Agency — capability routing, receipt gate, telemetry.
|
|
2
|
+
// Packs inform judgement; they never confer authority.
|
|
3
|
+
import { Type } from "typebox";
|
|
4
|
+
import { definePluginEntry } from "openclaw/plugin-sdk/plugin-entry";
|
|
5
|
+
import { readFile, appendFile, mkdir } from "node:fs/promises";
|
|
6
|
+
import { createHash, randomUUID } from "node:crypto";
|
|
7
|
+
import { dirname } from "node:path";
|
|
8
|
+
const receipts = new Map(); // runId -> receipt
|
|
9
|
+
const registryCache = new Map();
|
|
10
|
+
const now = () => Date.now();
|
|
11
|
+
const norm = (s) => String(s ?? "").toLowerCase().replace(/[^a-z0-9\s-]/g, " ").replace(/\s+/g, " ").trim();
|
|
12
|
+
async function loadRegistry(path) {
|
|
13
|
+
const { statSync } = await import("node:fs");
|
|
14
|
+
const st = statSync(path);
|
|
15
|
+
const hit = registryCache.get(path);
|
|
16
|
+
if (hit && hit.mtimeMs === st.mtimeMs)
|
|
17
|
+
return hit.data;
|
|
18
|
+
const data = JSON.parse(await readFile(path, "utf8"));
|
|
19
|
+
registryCache.set(path, { mtimeMs: st.mtimeMs, data });
|
|
20
|
+
return data;
|
|
21
|
+
}
|
|
22
|
+
function scoreCapability(cap, q) {
|
|
23
|
+
let score = 0;
|
|
24
|
+
const hits = [];
|
|
25
|
+
for (const t of cap.triggers ?? []) {
|
|
26
|
+
const nt = norm(t);
|
|
27
|
+
if (nt && q.includes(nt)) {
|
|
28
|
+
score += 3;
|
|
29
|
+
hits.push(t);
|
|
30
|
+
}
|
|
31
|
+
else if (nt) {
|
|
32
|
+
const words = nt.split(" ").filter((w) => w.length > 3);
|
|
33
|
+
const overlap = words.filter((w) => q.includes(w)).length;
|
|
34
|
+
if (words.length && overlap === words.length) {
|
|
35
|
+
score += 2;
|
|
36
|
+
hits.push(t);
|
|
37
|
+
}
|
|
38
|
+
else if (overlap > 0) {
|
|
39
|
+
score += overlap / words.length;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
const descWords = norm(cap.description).split(" ").filter((w) => w.length > 4);
|
|
44
|
+
score += 0.5 * descWords.filter((w) => q.includes(w)).length;
|
|
45
|
+
return { score, hits };
|
|
46
|
+
}
|
|
47
|
+
async function writeTelemetry(path, record) {
|
|
48
|
+
if (!path)
|
|
49
|
+
return;
|
|
50
|
+
try {
|
|
51
|
+
await mkdir(dirname(path), { recursive: true });
|
|
52
|
+
await appendFile(path, JSON.stringify({ ts: new Date().toISOString(), ...record }) + "\n");
|
|
53
|
+
}
|
|
54
|
+
catch { /* telemetry must never break a turn */ }
|
|
55
|
+
}
|
|
56
|
+
function prune(ttl) {
|
|
57
|
+
const t = now();
|
|
58
|
+
for (const [k, v] of receipts)
|
|
59
|
+
if (v.expires < t)
|
|
60
|
+
receipts.delete(k);
|
|
61
|
+
}
|
|
62
|
+
export default definePluginEntry({
|
|
63
|
+
id: "zero-agency",
|
|
64
|
+
name: "Zero Agency",
|
|
65
|
+
description: "Capability routing with a receipt gate. Packs inform judgement; they never confer authority.",
|
|
66
|
+
register(api) {
|
|
67
|
+
const cfg = api.config ?? api.pluginConfig ?? {};
|
|
68
|
+
const registryPath = cfg.registryPath ?? "";
|
|
69
|
+
const telemetryPath = cfg.telemetryPath ?? "";
|
|
70
|
+
const gateMode = cfg.gateMode ?? "advisory";
|
|
71
|
+
const consequentialTools = cfg.consequentialTools ?? ["exec", "apply_patch"];
|
|
72
|
+
const ttl = cfg.receiptTtlMs ?? 15 * 60 * 1000;
|
|
73
|
+
api.registerTool({
|
|
74
|
+
name: "zero_agency_route",
|
|
75
|
+
description: "Find the Zero Agency capability pack that governs a domain task. Call before acting on security review, release verification, or incident triage. Returns a receipt required by the gate.",
|
|
76
|
+
parameters: Type.Object({
|
|
77
|
+
task: Type.String({ description: "The task or question, in natural language." }),
|
|
78
|
+
limit: Type.Optional(Type.Integer({ minimum: 1, maximum: 5 })),
|
|
79
|
+
}),
|
|
80
|
+
outputSchema: Type.Object({
|
|
81
|
+
candidates: Type.Array(Type.Object({
|
|
82
|
+
id: Type.String(), pack: Type.String(), score: Type.Number(), triggers: Type.Array(Type.String()),
|
|
83
|
+
})),
|
|
84
|
+
receipt: Type.Union([Type.String(), Type.Null()]),
|
|
85
|
+
note: Type.String(),
|
|
86
|
+
}, { additionalProperties: false }),
|
|
87
|
+
async execute(_id, params, ctx) {
|
|
88
|
+
const q = norm(params.task);
|
|
89
|
+
const limit = params.limit ?? 3;
|
|
90
|
+
let candidates = [];
|
|
91
|
+
let note = "";
|
|
92
|
+
if (!registryPath) {
|
|
93
|
+
note = "zero-agency is not configured: registryPath is unset";
|
|
94
|
+
}
|
|
95
|
+
else {
|
|
96
|
+
try {
|
|
97
|
+
const reg = await loadRegistry(registryPath);
|
|
98
|
+
candidates = (reg.capabilities ?? [])
|
|
99
|
+
.map((c) => ({ c, ...scoreCapability(c, q) }))
|
|
100
|
+
.filter((x) => x.score > 0)
|
|
101
|
+
.sort((a, b) => b.score - a.score)
|
|
102
|
+
.slice(0, limit)
|
|
103
|
+
.map((x) => ({ id: x.c.id, pack: x.c.pack, score: Number(x.score.toFixed(2)), triggers: x.hits }));
|
|
104
|
+
if (!candidates.length)
|
|
105
|
+
note = "no capability matched; if this action is consequential, stop and ask";
|
|
106
|
+
else
|
|
107
|
+
note = `load ${candidates[0].pack} before acting`;
|
|
108
|
+
}
|
|
109
|
+
catch (e) {
|
|
110
|
+
note = `registry unavailable: ${e.message}`;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
let receipt = null;
|
|
114
|
+
if (candidates.length) {
|
|
115
|
+
const runId = ctx?.runId ?? "unknown-run";
|
|
116
|
+
receipt = createHash("sha256").update(`${runId}:${candidates[0].id}:${now()}:${randomUUID()}`).digest("hex").slice(0, 16);
|
|
117
|
+
receipts.set(runId, { id: receipt, pack: candidates[0].pack, at: now(), expires: now() + ttl });
|
|
118
|
+
prune(ttl);
|
|
119
|
+
}
|
|
120
|
+
await writeTelemetry(telemetryPath, {
|
|
121
|
+
kind: "route", runId: ctx?.runId ?? null, agent: ctx?.agentId ?? null,
|
|
122
|
+
session: ctx?.sessionKey ?? null, query: params.task.slice(0, 200),
|
|
123
|
+
selected: candidates[0]?.id ?? null, candidates: candidates.length, receipt,
|
|
124
|
+
});
|
|
125
|
+
return {
|
|
126
|
+
content: [{ type: "text", text: JSON.stringify({ candidates, receipt, note }) }],
|
|
127
|
+
details: { candidates, receipt, note },
|
|
128
|
+
};
|
|
129
|
+
},
|
|
130
|
+
});
|
|
131
|
+
api.registerTool({
|
|
132
|
+
name: "zero_agency_status",
|
|
133
|
+
description: "Report Zero Agency registry version, capability count and gate mode.",
|
|
134
|
+
parameters: Type.Object({}),
|
|
135
|
+
outputSchema: Type.Object({
|
|
136
|
+
gateMode: Type.String(), registry: Type.String(), capabilities: Type.Integer(),
|
|
137
|
+
receipts: Type.Integer(), registryError: Type.Union([Type.String(), Type.Null()]),
|
|
138
|
+
}, { additionalProperties: false }),
|
|
139
|
+
async execute() {
|
|
140
|
+
let capabilities = 0;
|
|
141
|
+
let registryError = null;
|
|
142
|
+
try {
|
|
143
|
+
const reg = await loadRegistry(registryPath);
|
|
144
|
+
capabilities = (reg.capabilities ?? []).length;
|
|
145
|
+
}
|
|
146
|
+
catch (e) {
|
|
147
|
+
registryError = e.message;
|
|
148
|
+
}
|
|
149
|
+
return {
|
|
150
|
+
content: [{ type: "text", text: `zero-agency: ${capabilities} capabilities, gate=${gateMode}` }],
|
|
151
|
+
details: { gateMode, registry: registryPath, capabilities, receipts: receipts.size, registryError },
|
|
152
|
+
};
|
|
153
|
+
},
|
|
154
|
+
});
|
|
155
|
+
// Receipt gate. Fail-closed in enforce mode: no receipt, no consequential call.
|
|
156
|
+
api.on("before_tool_call", async (event, ctx) => {
|
|
157
|
+
if (gateMode === "off")
|
|
158
|
+
return undefined;
|
|
159
|
+
const runId = event?.runId ?? ctx?.runId ?? "unknown-run";
|
|
160
|
+
prune(ttl);
|
|
161
|
+
const r = receipts.get(runId);
|
|
162
|
+
if (r) {
|
|
163
|
+
await writeTelemetry(telemetryPath, { kind: "gate", decision: "receipt-ok", tool: event?.toolName, runId, receipt: r.id });
|
|
164
|
+
return undefined;
|
|
165
|
+
}
|
|
166
|
+
await writeTelemetry(telemetryPath, {
|
|
167
|
+
kind: "gate", decision: gateMode === "enforce" ? "blocked" : "advisory-miss",
|
|
168
|
+
tool: event?.toolName, runId,
|
|
169
|
+
});
|
|
170
|
+
if (gateMode !== "enforce")
|
|
171
|
+
return undefined;
|
|
172
|
+
return {
|
|
173
|
+
requireApproval: {
|
|
174
|
+
title: `Zero Agency: no capability receipt (${event?.toolName ?? "tool"})`,
|
|
175
|
+
description: "This consequential call was made without a capability pack lookup. Approve to proceed for this call only, or deny and run zero_agency_route first.",
|
|
176
|
+
severity: "warning",
|
|
177
|
+
timeoutMs: 120000,
|
|
178
|
+
allowedDecisions: ["allow-once", "deny"],
|
|
179
|
+
onResolution: async (decision) => {
|
|
180
|
+
await writeTelemetry(telemetryPath, { kind: "gate", decision, tool: event?.toolName, runId, receipt: null });
|
|
181
|
+
},
|
|
182
|
+
},
|
|
183
|
+
};
|
|
184
|
+
}, { matcher: consequentialTools, priority: 50 });
|
|
185
|
+
},
|
|
186
|
+
});
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
{
|
|
2
|
+
"id": "zero-agency",
|
|
3
|
+
"name": "Zero Agency",
|
|
4
|
+
"description": "Capability routing with a receipt gate. Packs inform judgement; they never confer authority.",
|
|
5
|
+
"activation": { "onStartup": true },
|
|
6
|
+
"contracts": { "tools": ["zero_agency_route", "zero_agency_status"] },
|
|
7
|
+
"configSchema": {
|
|
8
|
+
"type": "object",
|
|
9
|
+
"additionalProperties": false,
|
|
10
|
+
"properties": {
|
|
11
|
+
"registryPath": { "type": "string", "description": "Absolute path to capabilities.json (read-only mount)." },
|
|
12
|
+
"telemetryPath": { "type": "string", "description": "Absolute path to the JSONL telemetry file." },
|
|
13
|
+
"gateMode": { "type": "string", "enum": ["off", "advisory", "enforce"], "default": "advisory" },
|
|
14
|
+
"consequentialTools": { "type": "array", "items": { "type": "string" }, "default": ["exec", "apply_patch"] },
|
|
15
|
+
"receiptTtlMs": { "type": "integer", "minimum": 1000, "default": 900000 }
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,32 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "openclaw-zero-agency",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.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": ["openclaw", "openclaw-plugin", "agents", "capability-routing", "governance"],
|
|
9
|
+
"files": ["dist", "openclaw.plugin.json", "README.md", "LICENSE"],
|
|
10
|
+
"scripts": {
|
|
11
|
+
"build": "tsc -p tsconfig.build.json",
|
|
12
|
+
"typecheck": "tsc --noEmit -p tsconfig.json",
|
|
13
|
+
"prepack": "npm run build"
|
|
14
|
+
},
|
|
15
|
+
"dependencies": {
|
|
16
|
+
"typebox": "^1.4.3"
|
|
17
|
+
},
|
|
18
|
+
"peerDependencies": {
|
|
19
|
+
"openclaw": ">=2026.10.1"
|
|
20
|
+
},
|
|
21
|
+
"devDependencies": {
|
|
22
|
+
"@types/node": "^22.0.0",
|
|
23
|
+
"typescript": "^7.0.2"
|
|
24
|
+
},
|
|
25
|
+
"openclaw": {
|
|
26
|
+
"extensions": ["./dist/index.js"],
|
|
27
|
+
"compat": {
|
|
28
|
+
"pluginApi": ">=2026.10.1",
|
|
29
|
+
"minGatewayVersion": "2026.10.1"
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|