openclaw-zero-agency 0.2.4 → 0.2.5
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/dist/index.js +18 -13
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
import { Type } from "typebox";
|
|
9
9
|
import { definePluginEntry } from "openclaw/plugin-sdk/plugin-entry";
|
|
10
10
|
import { readFile, appendFile, mkdir } from "node:fs/promises";
|
|
11
|
-
import {
|
|
11
|
+
import { rename, writeFile } from "node:fs/promises";
|
|
12
12
|
import { statSync } from "node:fs";
|
|
13
13
|
import { createHash, randomUUID } from "node:crypto";
|
|
14
14
|
import { dirname } from "node:path";
|
|
@@ -26,17 +26,17 @@ const cache = new Map();
|
|
|
26
26
|
// Receipts are shared through a file, not memory: the tool and the hook run in
|
|
27
27
|
// different execution contexts inside the plugin host, so a Map is not shared.
|
|
28
28
|
let receiptPath = "/tmp/zero-agency-receipts.json";
|
|
29
|
-
function readReceipts() {
|
|
29
|
+
async function readReceipts() {
|
|
30
30
|
try {
|
|
31
|
-
return JSON.parse(
|
|
31
|
+
return JSON.parse(await readFile(receiptPath, "utf8"));
|
|
32
32
|
}
|
|
33
33
|
catch {
|
|
34
34
|
return {};
|
|
35
35
|
}
|
|
36
36
|
}
|
|
37
|
-
function writeReceipt(runId, rec) {
|
|
37
|
+
async function writeReceipt(runId, rec) {
|
|
38
38
|
const now = Date.now();
|
|
39
|
-
const all = readReceipts();
|
|
39
|
+
const all = await readReceipts();
|
|
40
40
|
for (const k of Object.keys(all)) {
|
|
41
41
|
const v = all[k];
|
|
42
42
|
if (!v || v.expires < now)
|
|
@@ -46,15 +46,18 @@ function writeReceipt(runId, rec) {
|
|
|
46
46
|
if (runId)
|
|
47
47
|
all[runId] = rec;
|
|
48
48
|
try {
|
|
49
|
-
|
|
49
|
+
await mkdir(dirname(receiptPath), { recursive: true });
|
|
50
50
|
const tmp = `${receiptPath}.tmp`;
|
|
51
|
-
|
|
52
|
-
|
|
51
|
+
await writeFile(tmp, JSON.stringify(all));
|
|
52
|
+
await rename(tmp, receiptPath);
|
|
53
|
+
return true;
|
|
54
|
+
}
|
|
55
|
+
catch {
|
|
56
|
+
return false;
|
|
53
57
|
}
|
|
54
|
-
catch { /* a missing receipt fails safe */ }
|
|
55
58
|
}
|
|
56
|
-
function findReceipt(runId) {
|
|
57
|
-
const all = readReceipts();
|
|
59
|
+
async function findReceipt(runId) {
|
|
60
|
+
const all = await readReceipts();
|
|
58
61
|
const now = Date.now();
|
|
59
62
|
const r = (runId ? all[runId] : undefined) ?? all.global;
|
|
60
63
|
return r && r.expires > now ? r : undefined;
|
|
@@ -148,7 +151,9 @@ export default definePluginEntry({
|
|
|
148
151
|
if (candidates.length) {
|
|
149
152
|
const runId = ctx?.runId ?? ctx?.sessionId ?? null;
|
|
150
153
|
receipt = createHash("sha256").update(`${runId ?? "global"}:${candidates[0].id}:${Date.now()}:${randomUUID()}`).digest("hex").slice(0, 16);
|
|
151
|
-
writeReceipt(runId, { id: receipt, pack: candidates[0].pack, at: Date.now(), expires: Date.now() + ttl });
|
|
154
|
+
const wrote = await writeReceipt(runId, { id: receipt, pack: candidates[0].pack, at: Date.now(), expires: Date.now() + ttl });
|
|
155
|
+
if (!wrote)
|
|
156
|
+
await telemetry(telemetryPath, { kind: "receipt-write-failed", path: receiptPath, receipt });
|
|
152
157
|
}
|
|
153
158
|
await telemetry(telemetryPath, { kind: "route", agent: ctx?.agentId ?? null, session: ctx?.sessionKey ?? null, query: params.task.slice(0, 200), selected: candidates[0]?.id ?? null, candidates: candidates.length, receipt });
|
|
154
159
|
return { content: [{ type: "text", text: JSON.stringify({ candidates, receipt, note }) }], details: { candidates, receipt, note } };
|
|
@@ -175,7 +180,7 @@ export default definePluginEntry({
|
|
|
175
180
|
return undefined;
|
|
176
181
|
const runId = event?.runId ?? ctx?.runId ?? "unknown-run";
|
|
177
182
|
prune();
|
|
178
|
-
const r = findReceipt(runId);
|
|
183
|
+
const r = await findReceipt(runId);
|
|
179
184
|
if (r) {
|
|
180
185
|
await telemetry(telemetryPath, { kind: "gate", decision: "receipt-ok", tool: event?.toolName, runId, receipt: r.id });
|
|
181
186
|
return undefined;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "openclaw-zero-agency",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.5",
|
|
4
4
|
"description": "Zero Agency: capability packs, programmatic routing and a receipt gate for OpenClaw. Packs inform judgement; they never confer authority.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|