@verax-ai/body 0.8.1 → 0.8.2
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/approval-signature.js +3 -3
- package/dist/cli.js +41 -0
- package/dist/control-signature.js +1 -1
- package/dist/doctor.js +1 -1
- package/dist/halt.d.ts +2 -0
- package/dist/halt.js +57 -1
- package/dist/install.js +1 -1
- package/dist/reconcile-cli.js +1 -1
- package/dist/verify-cli.js +31 -2
- package/dist/watch.js +14 -9
- package/package.json +3 -3
|
@@ -222,7 +222,7 @@ export function passkeyRemovedAt(credentialId, removed) {
|
|
|
222
222
|
}
|
|
223
223
|
/** Omitted when the count is zero, so a line with none stays as it was. */
|
|
224
224
|
export function signedAfterRemovalSegment(count) {
|
|
225
|
-
return count > 0 ? `
|
|
225
|
+
return count > 0 ? ` | signed-after-removal ${count}` : "";
|
|
226
226
|
}
|
|
227
227
|
/**
|
|
228
228
|
* Recount operator approvals without a body. A signature is checked against
|
|
@@ -339,7 +339,7 @@ export async function verifyApprovalSignatures(stateDir, opts = {}) {
|
|
|
339
339
|
else
|
|
340
340
|
signedFailed += 1;
|
|
341
341
|
}
|
|
342
|
-
const originSuffix = origins.length === 0 ? "" : `
|
|
342
|
+
const originSuffix = origins.length === 0 ? "" : ` | origin ${origins.join(", ")}`;
|
|
343
343
|
const report = {
|
|
344
344
|
ok: signedFailed === 0 && signedAfterRemoval === 0,
|
|
345
345
|
signedVerified,
|
|
@@ -347,7 +347,7 @@ export async function verifyApprovalSignatures(stateDir, opts = {}) {
|
|
|
347
347
|
signedAfterRemoval,
|
|
348
348
|
unsignedHttp,
|
|
349
349
|
cli,
|
|
350
|
-
line: `approval signatures signed-verified ${signedVerified}
|
|
350
|
+
line: `approval signatures signed-verified ${signedVerified} | signed-failed ${signedFailed} | unsigned-http ${unsignedHttp} | cli ${cli}${other > 0 ? ` | other ${other}` : ""}${originSuffix}${signedAfterRemovalSegment(signedAfterRemoval)}`,
|
|
351
351
|
trustSource: trust.trustSource,
|
|
352
352
|
trustNote: trust.trustNote,
|
|
353
353
|
};
|
package/dist/cli.js
CHANGED
|
@@ -87,6 +87,35 @@ VERAX_STATE_DIR and VERAX_POLICY_FILE; \`verax doctor\` names what is missing.
|
|
|
87
87
|
Records stay on this machine, under VERAX_STATE_DIR.
|
|
88
88
|
`;
|
|
89
89
|
const version = bodyVersion;
|
|
90
|
+
/**
|
|
91
|
+
* Left to run, these read a help flag as a path or as an argument: `verax
|
|
92
|
+
* witness --help` started a witness in a new directory named `--help`. verify,
|
|
93
|
+
* anchor and watch print their own usage.
|
|
94
|
+
*/
|
|
95
|
+
const ANSWERED_BY_HELP = new Set([
|
|
96
|
+
"approve",
|
|
97
|
+
"demo",
|
|
98
|
+
"desktop",
|
|
99
|
+
"doctor",
|
|
100
|
+
"downstream",
|
|
101
|
+
"halt",
|
|
102
|
+
"init",
|
|
103
|
+
"install",
|
|
104
|
+
"memory",
|
|
105
|
+
"operator",
|
|
106
|
+
"reconcile",
|
|
107
|
+
"resume",
|
|
108
|
+
"serve",
|
|
109
|
+
"uninstall",
|
|
110
|
+
"unlock",
|
|
111
|
+
"witness",
|
|
112
|
+
]);
|
|
113
|
+
function refusedAsOption(arg, stderr) {
|
|
114
|
+
if (!arg.startsWith("-"))
|
|
115
|
+
return false;
|
|
116
|
+
stderr.write(`unknown option: ${terminalText(arg)}\n`);
|
|
117
|
+
return true;
|
|
118
|
+
}
|
|
90
119
|
function isCliEntry() {
|
|
91
120
|
const entry = process.argv[1];
|
|
92
121
|
if (!entry)
|
|
@@ -115,6 +144,10 @@ export async function runCli(argv, hooks = {}) {
|
|
|
115
144
|
stdout.write(HELP);
|
|
116
145
|
return 0;
|
|
117
146
|
}
|
|
147
|
+
if (ANSWERED_BY_HELP.has(argv[0] ?? "") && (argv.includes("--help") || argv.includes("-h"))) {
|
|
148
|
+
stdout.write(HELP);
|
|
149
|
+
return 0;
|
|
150
|
+
}
|
|
118
151
|
if (argv[0] === "--version" || argv[0] === "-v") {
|
|
119
152
|
stdout.write(`${version()}\n`);
|
|
120
153
|
return 0;
|
|
@@ -210,6 +243,8 @@ async function dispatchCli(argv, stdout, stderr, env) {
|
|
|
210
243
|
stderr.write("verax halt <stateDir>\n");
|
|
211
244
|
return 78;
|
|
212
245
|
}
|
|
246
|
+
if (refusedAsOption(stateDir, stderr))
|
|
247
|
+
return 64;
|
|
213
248
|
return runHalt(stateDir, (s) => stderr.write(s));
|
|
214
249
|
}
|
|
215
250
|
if (argv[0] === "watch") {
|
|
@@ -231,6 +266,8 @@ async function dispatchCli(argv, stdout, stderr, env) {
|
|
|
231
266
|
stderr.write("verax resume <stateDir>\n");
|
|
232
267
|
return 78;
|
|
233
268
|
}
|
|
269
|
+
if (refusedAsOption(stateDir, stderr))
|
|
270
|
+
return 64;
|
|
234
271
|
return runResume(stateDir, (s) => stderr.write(s));
|
|
235
272
|
}
|
|
236
273
|
if (argv[0] === "unlock") {
|
|
@@ -240,6 +277,8 @@ async function dispatchCli(argv, stdout, stderr, env) {
|
|
|
240
277
|
stderr.write("verax unlock [--force] <stateDir>\n");
|
|
241
278
|
return 78;
|
|
242
279
|
}
|
|
280
|
+
if (refusedAsOption(stateDir, stderr))
|
|
281
|
+
return 64;
|
|
243
282
|
return runUnlock(stateDir, (s) => stderr.write(s), { force });
|
|
244
283
|
}
|
|
245
284
|
if (argv[0] === "init") {
|
|
@@ -343,6 +382,8 @@ async function dispatchCli(argv, stdout, stderr, env) {
|
|
|
343
382
|
stderr.write("verax witness <stateDir>\n");
|
|
344
383
|
return 78;
|
|
345
384
|
}
|
|
385
|
+
if (refusedAsOption(stateDir, stderr))
|
|
386
|
+
return 64;
|
|
346
387
|
await runWitness(stateDir);
|
|
347
388
|
return 0;
|
|
348
389
|
}
|
|
@@ -204,7 +204,7 @@ export async function verifyControlSignatures(stateDir, opts = {}) {
|
|
|
204
204
|
cli,
|
|
205
205
|
file,
|
|
206
206
|
integrity,
|
|
207
|
-
line: `control signatures signed-verified ${signedVerified}
|
|
207
|
+
line: `control signatures signed-verified ${signedVerified} | signed-failed ${signedFailed} | unsigned-http ${unsignedHttp} | cli ${cli} | file ${file} | integrity ${integrity}${signedAfterRemovalSegment(signedAfterRemoval)}`,
|
|
208
208
|
trustSource: trust.trustSource,
|
|
209
209
|
trustNote: trust.trustNote,
|
|
210
210
|
};
|
package/dist/doctor.js
CHANGED
|
@@ -201,7 +201,7 @@ export function runDoctor(env, argv, opts = {}) {
|
|
|
201
201
|
checks.push({
|
|
202
202
|
id: "panel-issuer",
|
|
203
203
|
level: "warn",
|
|
204
|
-
detail: `panel last-resort issuer ${panelIssuer} differs from VERAX_ISSUER ${configuredIssuer}; the session reads authorization_servers from resource metadata
|
|
204
|
+
detail: `panel last-resort issuer ${panelIssuer} differs from VERAX_ISSUER ${configuredIssuer}; the session reads authorization_servers from resource metadata; if that document is unreachable the panel will not start`,
|
|
205
205
|
});
|
|
206
206
|
}
|
|
207
207
|
const tokenScope = scopeFromDevToken(env.VERAX_DEV_TOKEN);
|
package/dist/halt.d.ts
CHANGED
|
@@ -41,6 +41,8 @@ export type HaltState = {
|
|
|
41
41
|
halted: boolean;
|
|
42
42
|
since?: HaltEvent;
|
|
43
43
|
};
|
|
44
|
+
/** The same check for `verax watch`, which halts on its own: the refusal to print, or null. */
|
|
45
|
+
export declare function notStateDir(stateDir: string): string | null;
|
|
44
46
|
/** The switch is an empty file. A folder at the path is a blocked write, not a halt. */
|
|
45
47
|
export declare function isHaltSwitchFile(stateDir: string): boolean;
|
|
46
48
|
/**
|
package/dist/halt.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createHash } from "node:crypto";
|
|
2
|
-
import { closeSync, fsyncSync, mkdirSync, openSync, readFileSync, rmSync, statSync, writeFileSync, writeSync } from "node:fs";
|
|
2
|
+
import { closeSync, fsyncSync, mkdirSync, openSync, readFileSync, readdirSync, rmSync, statSync, writeFileSync, writeSync } from "node:fs";
|
|
3
3
|
import { userInfo } from "node:os";
|
|
4
4
|
import { join } from "node:path";
|
|
5
5
|
import { canonical } from "@cedulon/core";
|
|
@@ -12,6 +12,50 @@ function oneLine(err) {
|
|
|
12
12
|
const text = err instanceof Error ? err.message : String(err);
|
|
13
13
|
return text.replace(/[\r\n]+/g, " ").slice(0, 300);
|
|
14
14
|
}
|
|
15
|
+
const STATE_DIR_ENTRIES = new Set([
|
|
16
|
+
"decisions.jsonl",
|
|
17
|
+
"effects.jsonl",
|
|
18
|
+
"starts.jsonl",
|
|
19
|
+
"heartbeat.json",
|
|
20
|
+
"ledger.lock",
|
|
21
|
+
"keys",
|
|
22
|
+
"policy.json",
|
|
23
|
+
"verax.env",
|
|
24
|
+
SWITCH,
|
|
25
|
+
HISTORY,
|
|
26
|
+
]);
|
|
27
|
+
/**
|
|
28
|
+
* An operator types this path by hand, and a body only reads the switch in its
|
|
29
|
+
* own state directory. Writing the switch anywhere else would answer `halted`
|
|
30
|
+
* while the running body keeps allowing calls. An empty directory stays
|
|
31
|
+
* allowed, since a body started on it reads the switch. A directory this
|
|
32
|
+
* process may not list is left to the write that follows, which names the
|
|
33
|
+
* permission error.
|
|
34
|
+
*/
|
|
35
|
+
function checkStateDir(stateDir) {
|
|
36
|
+
let entries;
|
|
37
|
+
try {
|
|
38
|
+
entries = readdirSync(stateDir);
|
|
39
|
+
}
|
|
40
|
+
catch (err) {
|
|
41
|
+
const code = err.code;
|
|
42
|
+
if (code === "ENOENT")
|
|
43
|
+
return { problem: "no such directory" };
|
|
44
|
+
if (code === "ENOTDIR")
|
|
45
|
+
return { problem: "not a directory" };
|
|
46
|
+
return { empty: false };
|
|
47
|
+
}
|
|
48
|
+
if (entries.length === 0)
|
|
49
|
+
return { empty: true };
|
|
50
|
+
return entries.some((name) => STATE_DIR_ENTRIES.has(name))
|
|
51
|
+
? { empty: false }
|
|
52
|
+
: { problem: "no ledger files there" };
|
|
53
|
+
}
|
|
54
|
+
/** The same check for `verax watch`, which halts on its own: the refusal to print, or null. */
|
|
55
|
+
export function notStateDir(stateDir) {
|
|
56
|
+
const checked = checkStateDir(stateDir);
|
|
57
|
+
return "problem" in checked ? `not-a-state-dir: ${oneLine(stateDir)}: ${checked.problem}; nothing was halted` : null;
|
|
58
|
+
}
|
|
15
59
|
/** The switch is an empty file. A folder at the path is a blocked write, not a halt. */
|
|
16
60
|
export function isHaltSwitchFile(stateDir) {
|
|
17
61
|
try {
|
|
@@ -185,6 +229,11 @@ export function runHalt(stateDir, writeErr = (s) => process.stderr.write(s)) {
|
|
|
185
229
|
writeErr("verax halt <stateDir>\n");
|
|
186
230
|
return 78;
|
|
187
231
|
}
|
|
232
|
+
const checked = checkStateDir(stateDir);
|
|
233
|
+
if ("problem" in checked) {
|
|
234
|
+
writeErr(`halt-failed: not-a-state-dir: ${oneLine(stateDir)}: ${checked.problem}; nothing was halted\n`);
|
|
235
|
+
return 1;
|
|
236
|
+
}
|
|
188
237
|
try {
|
|
189
238
|
haltBody(stateDir, cliUser(), "cli");
|
|
190
239
|
}
|
|
@@ -197,6 +246,8 @@ export function runHalt(stateDir, writeErr = (s) => process.stderr.write(s)) {
|
|
|
197
246
|
return 1;
|
|
198
247
|
}
|
|
199
248
|
writeErr("halted\n");
|
|
249
|
+
if (checked.empty)
|
|
250
|
+
writeErr("note: this directory was empty; no body has written here yet\n");
|
|
200
251
|
return 0;
|
|
201
252
|
}
|
|
202
253
|
export function runResume(stateDir, writeErr = (s) => process.stderr.write(s)) {
|
|
@@ -204,6 +255,11 @@ export function runResume(stateDir, writeErr = (s) => process.stderr.write(s)) {
|
|
|
204
255
|
writeErr("verax resume <stateDir>\n");
|
|
205
256
|
return 78;
|
|
206
257
|
}
|
|
258
|
+
const checked = checkStateDir(stateDir);
|
|
259
|
+
if ("problem" in checked) {
|
|
260
|
+
writeErr(`resume-failed: not-a-state-dir: ${oneLine(stateDir)}: ${checked.problem}; nothing was resumed\n`);
|
|
261
|
+
return 1;
|
|
262
|
+
}
|
|
207
263
|
if (isSwitchPathBlocked(stateDir)) {
|
|
208
264
|
writeErr("resume-failed: switch-path-blocked; a running body may hold the halt in memory; clear the path and use POST /api/resume\n");
|
|
209
265
|
return 1;
|
package/dist/install.js
CHANGED
|
@@ -3292,7 +3292,7 @@ async function waitHealth(port, timeoutMs, io, nonce) {
|
|
|
3292
3292
|
return true;
|
|
3293
3293
|
const elapsed = Date.now() - start;
|
|
3294
3294
|
while (elapsed >= nextMark && nextMark < timeoutMs) {
|
|
3295
|
-
io.stderr.write(`waiting for the body (${nextMark / 1000} s)
|
|
3295
|
+
io.stderr.write(`waiting for the body (${nextMark / 1000} s)...\n`);
|
|
3296
3296
|
nextMark += 10_000;
|
|
3297
3297
|
}
|
|
3298
3298
|
const left = timeoutMs - (Date.now() - start);
|
package/dist/reconcile-cli.js
CHANGED
|
@@ -242,7 +242,7 @@ export function runReconcile(argv, writeErr = (s) => process.stderr.write(s)) {
|
|
|
242
242
|
if (parsed.channel === "card") {
|
|
243
243
|
const mismatch = report.ghost.filter((g) => g.reason === "amount-mismatch").length;
|
|
244
244
|
const unknown = report.ghost.filter((g) => g.reason === "amount-unknown").length;
|
|
245
|
-
writeErr(`matched ${report.matched.length}
|
|
245
|
+
writeErr(`matched ${report.matched.length} | ghost ${report.ghost.length} | authorizedUnpaid ${report.authorizedUnpaid.length} | mismatch ${mismatch} | unknown ${unknown}\n`);
|
|
246
246
|
}
|
|
247
247
|
return 0;
|
|
248
248
|
}
|
package/dist/verify-cli.js
CHANGED
|
@@ -109,6 +109,35 @@ const CONTROL_NOT_CHECKED = {
|
|
|
109
109
|
trustSource: "none",
|
|
110
110
|
trustNote: "control signatures were not checked",
|
|
111
111
|
};
|
|
112
|
+
/**
|
|
113
|
+
* The line a reader stops at. A bare VERIFIED reads as "not tampered with", so
|
|
114
|
+
* it is kept for a run that checked what that takes: every key from the reader,
|
|
115
|
+
* a checkpoint reaching the newest record, and a receipt from a service someone
|
|
116
|
+
* else runs, since only a checkpoint held elsewhere detects a rollback of the
|
|
117
|
+
* files. Anything less names what is missing. The exit code and `--json` are
|
|
118
|
+
* unchanged.
|
|
119
|
+
*/
|
|
120
|
+
function verdictLine(r, approval, control) {
|
|
121
|
+
if (!r.ok)
|
|
122
|
+
return "NOT VERIFIED";
|
|
123
|
+
const fromFiles = [r.trust, r.effectTrust, r.witnessTrust, r.checkpointTrust].some((trust) => trust?.source === "in-ledger") ||
|
|
124
|
+
approval.trustSource === "in-ledger" ||
|
|
125
|
+
control.trustSource === "in-ledger";
|
|
126
|
+
if (fromFiles || r.trust.source !== "pinned")
|
|
127
|
+
return "VERIFIED (internal consistency only)";
|
|
128
|
+
const { checkpoint } = r.tail;
|
|
129
|
+
if (!checkpoint)
|
|
130
|
+
return "VERIFIED (tail not covered: no checkpoint)";
|
|
131
|
+
if (checkpoint.receiptCount === null || checkpoint.ledgerHoldsRecord !== true) {
|
|
132
|
+
return "VERIFIED (tail not covered: the newest checkpoint does not reach a known record)";
|
|
133
|
+
}
|
|
134
|
+
const after = r.decisions - checkpoint.receiptCount;
|
|
135
|
+
if (after > 0)
|
|
136
|
+
return `VERIFIED (tail not covered: ${after} record(s) after the newest checkpoint)`;
|
|
137
|
+
if (r.anchors.verified === 0)
|
|
138
|
+
return "VERIFIED (rollback not checked: no anchored checkpoint)";
|
|
139
|
+
return "VERIFIED";
|
|
140
|
+
}
|
|
112
141
|
export function renderVerify(r, approval = APPROVAL_NOT_CHECKED, control = CONTROL_NOT_CHECKED, starts) {
|
|
113
142
|
const lines = [];
|
|
114
143
|
lines.push(`ledger ${r.directory}`);
|
|
@@ -180,10 +209,10 @@ export function renderVerify(r, approval = APPROVAL_NOT_CHECKED, control = CONTR
|
|
|
180
209
|
for (const p of r.problems.slice(0, 50))
|
|
181
210
|
lines.push(` - ${p}`);
|
|
182
211
|
if (r.problems.length > 50)
|
|
183
|
-
lines.push(`
|
|
212
|
+
lines.push(` ... and ${r.problems.length - 50} more`);
|
|
184
213
|
}
|
|
185
214
|
lines.push("");
|
|
186
|
-
lines.push(r
|
|
215
|
+
lines.push(verdictLine(r, approval, control));
|
|
187
216
|
// Escape before the join. verify reads a ledger someone else wrote, and a
|
|
188
217
|
// line break in that text must not become a line of its own.
|
|
189
218
|
return lines.map((line) => terminalText(line)).join("\n");
|
package/dist/watch.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { spawn } from "node:child_process";
|
|
2
2
|
import { readFileSync } from "node:fs";
|
|
3
3
|
import { setTimeout as delay } from "node:timers/promises";
|
|
4
|
-
import { haltBody, readHalt } from "./halt.js";
|
|
4
|
+
import { haltBody, notStateDir, readHalt } from "./halt.js";
|
|
5
5
|
import { readHeartbeat } from "./health-extras.js";
|
|
6
6
|
import { isLoopbackHost } from "./config.js";
|
|
7
7
|
const USAGE = "usage: verax watch <stateDir> | --url <https://host/healthz> --token-file <path> [--max-silence 30s] [--once] [--on-silence halt|exec] [--exec <command>]";
|
|
@@ -175,6 +175,7 @@ export async function runWatch(argv, hooks = {}) {
|
|
|
175
175
|
if (reason && !silent) {
|
|
176
176
|
silent = true;
|
|
177
177
|
let actionResult = "halted";
|
|
178
|
+
let refused = null;
|
|
178
179
|
if (opts.action === "exec") {
|
|
179
180
|
actionResult = await execute(opts, reason, hooks) ? "exec-ok" : "exec-failed";
|
|
180
181
|
}
|
|
@@ -182,18 +183,22 @@ export async function runWatch(argv, hooks = {}) {
|
|
|
182
183
|
actionResult = "remote halt is out of scope";
|
|
183
184
|
}
|
|
184
185
|
else {
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
if (!readHalt(opts.stateDir).halted)
|
|
188
|
-
actionResult = "halt-failed";
|
|
189
|
-
}
|
|
190
|
-
catch {
|
|
186
|
+
refused = notStateDir(opts.stateDir);
|
|
187
|
+
if (refused)
|
|
191
188
|
actionResult = "halt-failed";
|
|
192
|
-
|
|
189
|
+
else
|
|
190
|
+
try {
|
|
191
|
+
haltBody(opts.stateDir, "verax-watch", "cli", now);
|
|
192
|
+
if (!readHalt(opts.stateDir).halted)
|
|
193
|
+
actionResult = "halt-failed";
|
|
194
|
+
}
|
|
195
|
+
catch {
|
|
196
|
+
actionResult = "halt-failed";
|
|
197
|
+
}
|
|
193
198
|
}
|
|
194
199
|
stdout.write(`${JSON.stringify({ event: "silence", atMs: now, reason, action: opts.action, actionResult })}\n`);
|
|
195
200
|
if (actionResult === "halt-failed") {
|
|
196
|
-
stderr.write(
|
|
201
|
+
stderr.write(`verax-watch: ${refused ?? "could not persist halt"}\n`);
|
|
197
202
|
return 3;
|
|
198
203
|
}
|
|
199
204
|
if (opts.url && opts.action === "halt")
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@verax-ai/body",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.2",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"engines": {
|
|
@@ -26,8 +26,8 @@
|
|
|
26
26
|
"@cedulon/cose": "0.13.1",
|
|
27
27
|
"@cedulon/effect-extract": "0.13.1",
|
|
28
28
|
"@modelcontextprotocol/sdk": "^1.30.0",
|
|
29
|
-
"@verax-ai/inventory": "^0.8.
|
|
30
|
-
"@verax-ai/proxy": "^0.8.
|
|
29
|
+
"@verax-ai/inventory": "^0.8.2",
|
|
30
|
+
"@verax-ai/proxy": "^0.8.2",
|
|
31
31
|
"jose": "^6.2.12"
|
|
32
32
|
},
|
|
33
33
|
"description": "VERAX body: an MCP server that decides, records and proves what an agent did.",
|