@verax-ai/body 0.6.1 → 0.8.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/dist/alarm-outbox.d.ts +18 -0
- package/dist/alarm-outbox.js +199 -0
- package/dist/alarm-webhook.d.ts +16 -0
- package/dist/alarm-webhook.js +106 -0
- package/dist/approval-bound.d.ts +9 -0
- package/dist/approval-bound.js +16 -0
- package/dist/approve-cli.d.ts +7 -0
- package/dist/approve-cli.js +37 -17
- package/dist/cli.js +14 -0
- package/dist/config.d.ts +27 -0
- package/dist/config.js +35 -0
- package/dist/control-signature.d.ts +1 -0
- package/dist/control-signature.js +15 -3
- package/dist/doctor.js +9 -0
- package/dist/downstream.js +13 -7
- package/dist/halt.d.ts +28 -9
- package/dist/halt.js +126 -18
- package/dist/held-spend.d.ts +1 -1
- package/dist/held-spend.js +11 -6
- package/dist/incidents.d.ts +67 -0
- package/dist/incidents.js +627 -0
- package/dist/keys.d.ts +18 -1
- package/dist/keys.js +109 -5
- package/dist/memory-reattest-cli.d.ts +9 -0
- package/dist/memory-reattest-cli.js +110 -0
- package/dist/memory-rehead-cli.d.ts +9 -0
- package/dist/memory-rehead-cli.js +65 -0
- package/dist/memory-store.d.ts +157 -0
- package/dist/memory-store.js +917 -0
- package/dist/operator-door.js +7 -3
- package/dist/operator-handlers.js +36 -8
- package/dist/reconcile-cli.js +3 -1
- package/dist/server.js +49 -17
- package/dist/tools/memory.d.ts +12 -6
- package/dist/tools/memory.js +80 -124
- package/dist/verify-cli.js +1 -0
- package/dist/watch.js +3 -1
- package/dist/wiring.d.ts +14 -1
- package/dist/wiring.js +71 -14
- package/package.json +3 -3
|
@@ -14,6 +14,7 @@ import { canonical } from "@cedulon/core";
|
|
|
14
14
|
import { listPieceFiles } from "@verax-ai/proxy";
|
|
15
15
|
import { asAssertion, assertionMatches, indexRemovalMark, noteChainRemoval, passkeyRemovedAt, readLines, signedAfterRemovalSegment, trustOf, } from "./approval-signature.js";
|
|
16
16
|
import { historyTail } from "./halt.js";
|
|
17
|
+
import { INCIDENT_BY } from "./incidents.js";
|
|
17
18
|
import { credentialsPath, findCredential, hasRegisteredOperator, readCredentialsAt, updateCounter, } from "./operator-credentials.js";
|
|
18
19
|
import { readRpConfig } from "./rp-config.js";
|
|
19
20
|
import { verifyAssertion } from "./webauthn-verify.js";
|
|
@@ -73,6 +74,9 @@ export function gateControlSignature(opts) {
|
|
|
73
74
|
},
|
|
74
75
|
};
|
|
75
76
|
}
|
|
77
|
+
function integrityAccepted(control, action) {
|
|
78
|
+
return action === "halt" && control.via === "integrity" && control.by === INCIDENT_BY;
|
|
79
|
+
}
|
|
76
80
|
function controlSignatureOf(value) {
|
|
77
81
|
if (!value || typeof value !== "object")
|
|
78
82
|
return null;
|
|
@@ -133,6 +137,7 @@ export async function verifyControlSignatures(stateDir, opts = {}) {
|
|
|
133
137
|
let unsignedHttp = 0;
|
|
134
138
|
let cli = 0;
|
|
135
139
|
let file = 0;
|
|
140
|
+
let integrity = 0;
|
|
136
141
|
const lineHashByLine = new Map();
|
|
137
142
|
const used = new Set();
|
|
138
143
|
// Ledger order, not history-line order. A removal between two control
|
|
@@ -153,7 +158,14 @@ export async function verifyControlSignatures(stateDir, opts = {}) {
|
|
|
153
158
|
if (!control)
|
|
154
159
|
continue;
|
|
155
160
|
const at = typeof control.line === "number" && Number.isInteger(control.line) ? control.line : -1;
|
|
156
|
-
|
|
161
|
+
const action = claims.subject === "verax.halt" ? "halt" : "resume";
|
|
162
|
+
if (control.via === "integrity") {
|
|
163
|
+
if (integrityAccepted(control, action) && control.signature === undefined)
|
|
164
|
+
integrity += 1;
|
|
165
|
+
else
|
|
166
|
+
signedFailed += 1;
|
|
167
|
+
}
|
|
168
|
+
else if (control.signature === undefined) {
|
|
157
169
|
if (control.via === "http")
|
|
158
170
|
unsignedHttp += 1;
|
|
159
171
|
else if (control.via === "cli")
|
|
@@ -164,7 +176,6 @@ export async function verifyControlSignatures(stateDir, opts = {}) {
|
|
|
164
176
|
else {
|
|
165
177
|
const sig = controlSignatureOf(control.signature);
|
|
166
178
|
const expectedPrev = at === 0 ? null : at > 0 ? lineHashByLine.get(at - 1) : undefined;
|
|
167
|
-
const action = claims.subject === "verax.halt" ? "halt" : "resume";
|
|
168
179
|
const challenge = sig && expectedPrev !== undefined && sig.prev === expectedPrev
|
|
169
180
|
? controlChallenge({ action, prev: expectedPrev })
|
|
170
181
|
: null;
|
|
@@ -192,7 +203,8 @@ export async function verifyControlSignatures(stateDir, opts = {}) {
|
|
|
192
203
|
unsignedHttp,
|
|
193
204
|
cli,
|
|
194
205
|
file,
|
|
195
|
-
|
|
206
|
+
integrity,
|
|
207
|
+
line: `control signatures signed-verified ${signedVerified} · signed-failed ${signedFailed} · unsigned-http ${unsignedHttp} · cli ${cli} · file ${file} · integrity ${integrity}${signedAfterRemovalSegment(signedAfterRemoval)}`,
|
|
196
208
|
trustSource: trust.trustSource,
|
|
197
209
|
trustNote: trust.trustNote,
|
|
198
210
|
};
|
package/dist/doctor.js
CHANGED
|
@@ -10,6 +10,7 @@ import { lockHolderAlive, lockState } from "@verax-ai/proxy";
|
|
|
10
10
|
import { readLockFile } from "./unlock.js";
|
|
11
11
|
import { pendingAnchors } from "./anchor-cli.js";
|
|
12
12
|
import { readWitnessListen } from "./witness.js";
|
|
13
|
+
import { pathIsInsideDir, resolveKeysDir } from "./keys.js";
|
|
13
14
|
const SECRET_RE = /sk-|-----BEGIN|Bearer |eyJ[A-Za-z0-9_-]{10,}\./;
|
|
14
15
|
const SECRET_NAME = /^(VERAX_DEV_TOKEN|.*_(TOKEN|SECRET|KEY))$/;
|
|
15
16
|
/**
|
|
@@ -133,6 +134,14 @@ export function runDoctor(env, argv, opts = {}) {
|
|
|
133
134
|
const custody = keyCustodyCheck(stateDir, env, opts.elevated ?? (() => defaultElevated()), opts.keyOwner ?? defaultKeyOwner);
|
|
134
135
|
if (custody)
|
|
135
136
|
checks.push(custody);
|
|
137
|
+
const keysDir = resolveKeysDir(stateDir, env.VERAX_KEYS_DIR);
|
|
138
|
+
if (pathIsInsideDir(stateDir, keysDir)) {
|
|
139
|
+
checks.push({
|
|
140
|
+
id: "record-key-location",
|
|
141
|
+
level: "warn",
|
|
142
|
+
detail: "record key is inside the state directory; a state-directory writer also holds the key. Set VERAX_KEYS_DIR to a directory outside the state directory.",
|
|
143
|
+
});
|
|
144
|
+
}
|
|
136
145
|
}
|
|
137
146
|
const secretNames = Object.entries(env)
|
|
138
147
|
.filter(([k, v]) => Boolean(v) && ((SECRET_NAME.test(k) && !PUBLIC_KEY_PATH_NAMES.has(k)) || SECRET_RE.test(String(v))))
|
package/dist/downstream.js
CHANGED
|
@@ -229,12 +229,18 @@ function asTextResult(raw) {
|
|
|
229
229
|
const content = [];
|
|
230
230
|
const items = Array.isArray(rec.content) ? rec.content : [];
|
|
231
231
|
for (const item of items) {
|
|
232
|
-
if (item !== null &&
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
232
|
+
if (item !== null && typeof item === "object") {
|
|
233
|
+
const block = item;
|
|
234
|
+
if (block.type === "text" && typeof block.text === "string") {
|
|
235
|
+
content.push({ type: "text", text: block.text });
|
|
236
|
+
continue;
|
|
237
|
+
}
|
|
238
|
+
if ((block.type === "image" || block.type === "audio") &&
|
|
239
|
+
typeof block.data === "string" &&
|
|
240
|
+
typeof block.mimeType === "string") {
|
|
241
|
+
content.push({ type: block.type, data: block.data, mimeType: block.mimeType });
|
|
242
|
+
continue;
|
|
243
|
+
}
|
|
238
244
|
}
|
|
239
245
|
content.push({ type: "text", text: JSON.stringify(item) });
|
|
240
246
|
}
|
|
@@ -763,5 +769,5 @@ export async function openDownstream(spec, opts) {
|
|
|
763
769
|
};
|
|
764
770
|
}
|
|
765
771
|
function textOf(result) {
|
|
766
|
-
return result.content.map((c) => c.text).join("");
|
|
772
|
+
return result.content.map((c) => (c.type === "text" ? c.text : "")).join("");
|
|
767
773
|
}
|
package/dist/halt.d.ts
CHANGED
|
@@ -1,7 +1,12 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type ControlSignature } from "@verax-ai/proxy";
|
|
2
2
|
/**
|
|
3
|
-
* The proxy refuses every call while `<stateDir>/halted`
|
|
4
|
-
*
|
|
3
|
+
* The proxy refuses every call while `<stateDir>/halted` is a regular file, or
|
|
4
|
+
* while this process has marked a halt that could not persist that file.
|
|
5
|
+
* The process flag is set only when that write fails; a written file is the
|
|
6
|
+
* single source of truth, so a later `verax resume` in another process can
|
|
7
|
+
* lift a normal halt by removing the file. A flag-only halt (path blocked)
|
|
8
|
+
* is lifted in this process by `resumeBody` — HTTP `POST /api/resume`.
|
|
9
|
+
* The file is the switch and stays empty. Who flipped it and when goes to
|
|
5
10
|
* `halt-history.jsonl` beside it, one line per halt or resume, so the panel
|
|
6
11
|
* can say "stopped by operator-7 at 14:02" and a resume is not silent.
|
|
7
12
|
*
|
|
@@ -15,18 +20,29 @@ import type { ControlSignature } from "@verax-ai/proxy";
|
|
|
15
20
|
*
|
|
16
21
|
* An HTTP halt or resume made with the operator's passkey carries that
|
|
17
22
|
* assertion on its line, and the control record carries it on from there.
|
|
23
|
+
* A memory integrity failure uses `via: "integrity"` and
|
|
24
|
+
* `by: "verax:memory-integrity"`.
|
|
18
25
|
*/
|
|
19
26
|
export type HaltEvent = {
|
|
20
27
|
action: "halt" | "resume";
|
|
21
28
|
atMs: number;
|
|
22
29
|
by: string;
|
|
23
|
-
via: "cli" | "http";
|
|
30
|
+
via: "cli" | "http" | "integrity";
|
|
24
31
|
signature?: ControlSignature;
|
|
32
|
+
/** Integrity halt only: the incident this switch is bound to. */
|
|
33
|
+
eventId?: string;
|
|
34
|
+
triggerCode?: string;
|
|
35
|
+
memoryHead?: {
|
|
36
|
+
seq: number;
|
|
37
|
+
lastHash: string;
|
|
38
|
+
};
|
|
25
39
|
};
|
|
26
40
|
export type HaltState = {
|
|
27
41
|
halted: boolean;
|
|
28
42
|
since?: HaltEvent;
|
|
29
43
|
};
|
|
44
|
+
/** The switch is an empty file. A folder at the path is a blocked write, not a halt. */
|
|
45
|
+
export declare function isHaltSwitchFile(stateDir: string): boolean;
|
|
30
46
|
/**
|
|
31
47
|
* SHA-256 of the newest history line, as the control record names that line
|
|
32
48
|
* (`lineHash`), or `null` when there is none. A signed halt or resume binds
|
|
@@ -35,13 +51,16 @@ export type HaltState = {
|
|
|
35
51
|
export declare function historyTail(stateDir: string): string | null;
|
|
36
52
|
export declare function readHalt(stateDir: string): HaltState;
|
|
37
53
|
/** Halting twice is one halt: the first line keeps saying who stopped it. */
|
|
38
|
-
export declare function haltBody(stateDir: string, by: string, via: HaltEvent["via"], now?: number, signature?: ControlSignature): HaltState;
|
|
54
|
+
export declare function haltBody(stateDir: string, by: string, via: HaltEvent["via"], now?: number, signature?: ControlSignature, incident?: Pick<HaltEvent, "eventId" | "triggerCode" | "memoryHead">): HaltState;
|
|
39
55
|
/**
|
|
40
56
|
* Resuming a body that is not halted changes nothing and writes nothing.
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
*
|
|
57
|
+
* Undelivered incidents are verified/re-signed and written to the outbox, or
|
|
58
|
+
* marked closed-pending-delivery with an atomic write. If that mark cannot be
|
|
59
|
+
* written, this throws and the body stays halted. The history line is
|
|
60
|
+
* appended after the mark: if the append throws, the body stays halted
|
|
61
|
+
* rather than running again with no record of who let it. Then the switch
|
|
62
|
+
* is removed. A later integrity halt is a new event. Pending outbox files stay.
|
|
44
63
|
*/
|
|
45
|
-
export declare function resumeBody(stateDir: string, by: string, via: HaltEvent["via"], now?: number, signature?: ControlSignature): HaltState;
|
|
64
|
+
export declare function resumeBody(stateDir: string, by: string, via: HaltEvent["via"], now?: number, signature?: ControlSignature, keysDir?: string | null): HaltState;
|
|
46
65
|
export declare function runHalt(stateDir: string, writeErr?: (s: string) => void): number;
|
|
47
66
|
export declare function runResume(stateDir: string, writeErr?: (s: string) => void): number;
|
package/dist/halt.js
CHANGED
|
@@ -1,10 +1,35 @@
|
|
|
1
1
|
import { createHash } from "node:crypto";
|
|
2
|
-
import {
|
|
2
|
+
import { closeSync, fsyncSync, mkdirSync, openSync, readFileSync, 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";
|
|
6
|
+
import { clearProcessHalted, isProcessHalted, markProcessHalted, persistHaltedSwitch, } from "@verax-ai/proxy";
|
|
7
|
+
import { closeIncidentsOnResume } from "./incidents.js";
|
|
8
|
+
import { markHistoryUnavailable } from "./memory-store.js";
|
|
6
9
|
const SWITCH = "halted";
|
|
7
10
|
const HISTORY = "halt-history.jsonl";
|
|
11
|
+
function oneLine(err) {
|
|
12
|
+
const text = err instanceof Error ? err.message : String(err);
|
|
13
|
+
return text.replace(/[\r\n]+/g, " ").slice(0, 300);
|
|
14
|
+
}
|
|
15
|
+
/** The switch is an empty file. A folder at the path is a blocked write, not a halt. */
|
|
16
|
+
export function isHaltSwitchFile(stateDir) {
|
|
17
|
+
try {
|
|
18
|
+
return statSync(join(stateDir, SWITCH)).isFile();
|
|
19
|
+
}
|
|
20
|
+
catch {
|
|
21
|
+
return false;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
/** Something occupies the switch path that is not the halt file (a folder, etc.). */
|
|
25
|
+
function isSwitchPathBlocked(stateDir) {
|
|
26
|
+
try {
|
|
27
|
+
return !statSync(join(stateDir, SWITCH)).isFile();
|
|
28
|
+
}
|
|
29
|
+
catch {
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
8
33
|
function cliUser() {
|
|
9
34
|
try {
|
|
10
35
|
return userInfo().username || "unknown";
|
|
@@ -14,7 +39,15 @@ function cliUser() {
|
|
|
14
39
|
}
|
|
15
40
|
}
|
|
16
41
|
function appendHistory(stateDir, event) {
|
|
17
|
-
|
|
42
|
+
mkdirSync(stateDir, { recursive: true, mode: 0o700 });
|
|
43
|
+
const fd = openSync(join(stateDir, HISTORY), "a", 0o600);
|
|
44
|
+
try {
|
|
45
|
+
writeSync(fd, `${JSON.stringify(event)}\n`, null, "utf8");
|
|
46
|
+
fsyncSync(fd);
|
|
47
|
+
}
|
|
48
|
+
finally {
|
|
49
|
+
closeSync(fd);
|
|
50
|
+
}
|
|
18
51
|
}
|
|
19
52
|
/**
|
|
20
53
|
* SHA-256 of the newest history line, as the control record names that line
|
|
@@ -40,6 +73,11 @@ export function historyTail(stateDir) {
|
|
|
40
73
|
return null;
|
|
41
74
|
return createHash("sha256").update(canonical(last), "utf8").digest("hex");
|
|
42
75
|
}
|
|
76
|
+
function haltVia(raw) {
|
|
77
|
+
if (raw === "http" || raw === "integrity")
|
|
78
|
+
return raw;
|
|
79
|
+
return "cli";
|
|
80
|
+
}
|
|
43
81
|
function lastHalt(stateDir) {
|
|
44
82
|
let raw;
|
|
45
83
|
try {
|
|
@@ -53,7 +91,16 @@ function lastHalt(stateDir) {
|
|
|
53
91
|
try {
|
|
54
92
|
const row = JSON.parse(lines[i] ?? "");
|
|
55
93
|
if (row.action === "halt" && typeof row.atMs === "number" && typeof row.by === "string") {
|
|
56
|
-
|
|
94
|
+
const event = { action: "halt", atMs: row.atMs, by: row.by, via: haltVia(row.via) };
|
|
95
|
+
if (typeof row.eventId === "string" && row.eventId !== "")
|
|
96
|
+
event.eventId = row.eventId;
|
|
97
|
+
if (typeof row.triggerCode === "string" && row.triggerCode !== "")
|
|
98
|
+
event.triggerCode = row.triggerCode;
|
|
99
|
+
const head = row.memoryHead;
|
|
100
|
+
if (head && typeof head === "object" && typeof head.seq === "number" && typeof head.lastHash === "string") {
|
|
101
|
+
event.memoryHead = { seq: head.seq, lastHash: head.lastHash };
|
|
102
|
+
}
|
|
103
|
+
return event;
|
|
57
104
|
}
|
|
58
105
|
if (row.action === "resume")
|
|
59
106
|
return undefined;
|
|
@@ -65,30 +112,71 @@ function lastHalt(stateDir) {
|
|
|
65
112
|
return undefined;
|
|
66
113
|
}
|
|
67
114
|
export function readHalt(stateDir) {
|
|
68
|
-
if (!
|
|
115
|
+
if (!isHaltSwitchFile(stateDir))
|
|
69
116
|
return { halted: false };
|
|
70
117
|
const since = lastHalt(stateDir);
|
|
71
118
|
return since ? { halted: true, since } : { halted: true };
|
|
72
119
|
}
|
|
73
120
|
/** Halting twice is one halt: the first line keeps saying who stopped it. */
|
|
74
|
-
export function haltBody(stateDir, by, via, now = Date.now(), signature) {
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
121
|
+
export function haltBody(stateDir, by, via, now = Date.now(), signature, incident) {
|
|
122
|
+
try {
|
|
123
|
+
mkdirSync(stateDir, { recursive: true, mode: 0o700 });
|
|
124
|
+
const hadSwitch = isHaltSwitchFile(stateDir);
|
|
125
|
+
if (!hadSwitch) {
|
|
126
|
+
writeFileSync(join(stateDir, SWITCH), "", { encoding: "utf8", mode: 0o600 });
|
|
127
|
+
}
|
|
128
|
+
// The file is the single source of truth once it exists. History is a
|
|
129
|
+
// separate write: an older flag-only halt must not survive a later
|
|
130
|
+
// successful switch, even if the history line cannot be appended.
|
|
131
|
+
if (isHaltSwitchFile(stateDir))
|
|
132
|
+
clearProcessHalted(stateDir);
|
|
133
|
+
if (!hadSwitch && isHaltSwitchFile(stateDir)) {
|
|
134
|
+
appendHistory(stateDir, {
|
|
135
|
+
action: "halt",
|
|
136
|
+
atMs: now,
|
|
137
|
+
by,
|
|
138
|
+
via,
|
|
139
|
+
...(signature ? { signature } : {}),
|
|
140
|
+
...(incident?.eventId ? { eventId: incident.eventId } : {}),
|
|
141
|
+
...(incident?.triggerCode ? { triggerCode: incident.triggerCode } : {}),
|
|
142
|
+
...(incident?.memoryHead ? { memoryHead: incident.memoryHead } : {}),
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
catch (err) {
|
|
147
|
+
process.stderr.write(`verax: halt: ${oneLine(err)}\n`);
|
|
148
|
+
if (isHaltSwitchFile(stateDir)) {
|
|
149
|
+
clearProcessHalted(stateDir);
|
|
150
|
+
throw err;
|
|
151
|
+
}
|
|
152
|
+
markProcessHalted(stateDir);
|
|
153
|
+
persistHaltedSwitch(stateDir);
|
|
154
|
+
if (!isHaltSwitchFile(stateDir)) {
|
|
155
|
+
markHistoryUnavailable(stateDir);
|
|
156
|
+
}
|
|
157
|
+
else {
|
|
158
|
+
clearProcessHalted(stateDir);
|
|
159
|
+
throw err;
|
|
160
|
+
}
|
|
79
161
|
}
|
|
80
162
|
return readHalt(stateDir);
|
|
81
163
|
}
|
|
82
164
|
/**
|
|
83
165
|
* Resuming a body that is not halted changes nothing and writes nothing.
|
|
84
|
-
*
|
|
85
|
-
*
|
|
86
|
-
*
|
|
166
|
+
* Undelivered incidents are verified/re-signed and written to the outbox, or
|
|
167
|
+
* marked closed-pending-delivery with an atomic write. If that mark cannot be
|
|
168
|
+
* written, this throws and the body stays halted. The history line is
|
|
169
|
+
* appended after the mark: if the append throws, the body stays halted
|
|
170
|
+
* rather than running again with no record of who let it. Then the switch
|
|
171
|
+
* is removed. A later integrity halt is a new event. Pending outbox files stay.
|
|
87
172
|
*/
|
|
88
|
-
export function resumeBody(stateDir, by, via, now = Date.now(), signature) {
|
|
89
|
-
if (
|
|
173
|
+
export function resumeBody(stateDir, by, via, now = Date.now(), signature, keysDir) {
|
|
174
|
+
if (isHaltSwitchFile(stateDir) || isProcessHalted(stateDir)) {
|
|
175
|
+
closeIncidentsOnResume(stateDir, keysDir);
|
|
90
176
|
appendHistory(stateDir, { action: "resume", atMs: now, by, via, ...(signature ? { signature } : {}) });
|
|
91
|
-
|
|
177
|
+
if (isHaltSwitchFile(stateDir))
|
|
178
|
+
rmSync(join(stateDir, SWITCH), { force: true });
|
|
179
|
+
clearProcessHalted(stateDir);
|
|
92
180
|
}
|
|
93
181
|
return readHalt(stateDir);
|
|
94
182
|
}
|
|
@@ -97,7 +185,17 @@ export function runHalt(stateDir, writeErr = (s) => process.stderr.write(s)) {
|
|
|
97
185
|
writeErr("verax halt <stateDir>\n");
|
|
98
186
|
return 78;
|
|
99
187
|
}
|
|
100
|
-
|
|
188
|
+
try {
|
|
189
|
+
haltBody(stateDir, cliUser(), "cli");
|
|
190
|
+
}
|
|
191
|
+
catch (err) {
|
|
192
|
+
writeErr(`halt-failed: ${oneLine(err)}\n`);
|
|
193
|
+
return 1;
|
|
194
|
+
}
|
|
195
|
+
if (!readHalt(stateDir).halted) {
|
|
196
|
+
writeErr("halt-failed: switch-unwritable\n");
|
|
197
|
+
return 1;
|
|
198
|
+
}
|
|
101
199
|
writeErr("halted\n");
|
|
102
200
|
return 0;
|
|
103
201
|
}
|
|
@@ -106,11 +204,21 @@ export function runResume(stateDir, writeErr = (s) => process.stderr.write(s)) {
|
|
|
106
204
|
writeErr("verax resume <stateDir>\n");
|
|
107
205
|
return 78;
|
|
108
206
|
}
|
|
109
|
-
if (
|
|
207
|
+
if (isSwitchPathBlocked(stateDir)) {
|
|
208
|
+
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
|
+
return 1;
|
|
210
|
+
}
|
|
211
|
+
if (!isHaltSwitchFile(stateDir) && !isProcessHalted(stateDir)) {
|
|
110
212
|
writeErr("not halted\n");
|
|
111
213
|
return 0;
|
|
112
214
|
}
|
|
113
|
-
|
|
215
|
+
try {
|
|
216
|
+
resumeBody(stateDir, cliUser(), "cli", Date.now(), undefined, process.env.VERAX_KEYS_DIR);
|
|
217
|
+
}
|
|
218
|
+
catch (err) {
|
|
219
|
+
writeErr(`resume-failed: ${oneLine(err)}\n`);
|
|
220
|
+
return 1;
|
|
221
|
+
}
|
|
114
222
|
writeErr("resumed\n");
|
|
115
223
|
return 0;
|
|
116
224
|
}
|
package/dist/held-spend.d.ts
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* one. The terminal and the operator door read the same four fields from
|
|
4
4
|
* here, so neither can show a payee or an amount the other would not.
|
|
5
5
|
*/
|
|
6
|
-
import type
|
|
6
|
+
import { type ApprovalRow } from "@verax-ai/proxy";
|
|
7
7
|
export type HeldSpend = {
|
|
8
8
|
payee: string;
|
|
9
9
|
amountMinor: number | null;
|
package/dist/held-spend.js
CHANGED
|
@@ -1,20 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What a held spend is shown as, wherever an operator is asked to approve
|
|
3
|
+
* one. The terminal and the operator door read the same four fields from
|
|
4
|
+
* here, so neither can show a payee or an amount the other would not.
|
|
5
|
+
*/
|
|
6
|
+
import { approvalDispatchArgs } from "@verax-ai/proxy";
|
|
1
7
|
function integerMinor(value) {
|
|
2
8
|
return typeof value === "number" && Number.isInteger(value) ? value : null;
|
|
3
9
|
}
|
|
4
10
|
/** An integer minor-unit amount, or null when the stored amount cannot be read as one. */
|
|
5
11
|
export function minorUnits(row) {
|
|
6
|
-
|
|
7
|
-
return integerMinor(row.amount);
|
|
8
|
-
return integerMinor(row.args.amountMinor);
|
|
12
|
+
return integerMinor(approvalDispatchArgs(row).amountMinor);
|
|
9
13
|
}
|
|
10
14
|
/** Null for a held call that is not a spend. */
|
|
11
15
|
export function heldSpend(row) {
|
|
12
16
|
if (row.subject !== "spend")
|
|
13
17
|
return null;
|
|
18
|
+
const args = approvalDispatchArgs(row);
|
|
14
19
|
return {
|
|
15
|
-
payee: typeof
|
|
20
|
+
payee: typeof args.payee === "string" ? args.payee : String(args.payee ?? ""),
|
|
16
21
|
amountMinor: minorUnits(row),
|
|
17
|
-
currency: typeof
|
|
18
|
-
reference: typeof
|
|
22
|
+
currency: typeof args.currency === "string" ? args.currency : String(args.currency ?? ""),
|
|
23
|
+
reference: typeof args.reference === "string" ? args.reference : "",
|
|
19
24
|
};
|
|
20
25
|
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { type AlarmEnvelope } from "./alarm-outbox.ts";
|
|
2
|
+
import { type IntegrityReason } from "./memory-store.ts";
|
|
3
|
+
export declare const INCIDENT_BY = "verax:memory-integrity";
|
|
4
|
+
export declare const INCIDENT_RECORD = "incident.json";
|
|
5
|
+
export declare const INCIDENTS_DIR = "incidents";
|
|
6
|
+
export type IncidentPayload = {
|
|
7
|
+
v: 1;
|
|
8
|
+
purpose: "verax.incident.v1";
|
|
9
|
+
eventId: string;
|
|
10
|
+
observedAt: number;
|
|
11
|
+
triggerCode: string;
|
|
12
|
+
scopeKind: "global";
|
|
13
|
+
enforcementState: "halted";
|
|
14
|
+
keyId: string;
|
|
15
|
+
memoryHead?: {
|
|
16
|
+
seq: number;
|
|
17
|
+
lastHash: string;
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
export declare function recordKeyId(publicKeyPem: string): string;
|
|
21
|
+
export type IncidentEventIdGenerators = {
|
|
22
|
+
randomUUID: () => string;
|
|
23
|
+
randomBytes: (size: number) => Buffer;
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* randomUUID, then randomBytes, then a SHA-256 UUID of observedAt+trigger+record key.
|
|
27
|
+
* Generators are a parameter so a failing producer can be injected; that is
|
|
28
|
+
* dependency injection, not a product-code test hook. The last resort is
|
|
29
|
+
* stable for the same inputs (a retry of one incident stays one id).
|
|
30
|
+
*/
|
|
31
|
+
export declare function incidentEventIdFrom(opts: {
|
|
32
|
+
observedAt: number;
|
|
33
|
+
triggerCode: string;
|
|
34
|
+
publicKeyPem: string;
|
|
35
|
+
}, generators: IncidentEventIdGenerators): string;
|
|
36
|
+
/** Production path: the same cascade; last resort mixes pid, a counter, and extra bytes. */
|
|
37
|
+
export declare function allocateIncidentEventId(opts: {
|
|
38
|
+
observedAt: number;
|
|
39
|
+
triggerCode: string;
|
|
40
|
+
publicKeyPem: string;
|
|
41
|
+
}): string;
|
|
42
|
+
export declare function signIncident(payload: IncidentPayload, privateKeyPem: string): AlarmEnvelope;
|
|
43
|
+
/** Resume: same verify/re-sign path; pending marker is atomic or resume does not finish. */
|
|
44
|
+
export declare function closeIncidentsOnResume(stateDir: string, keysDir?: string | null): void;
|
|
45
|
+
export declare function raiseMemoryIntegrityIncident(opts: {
|
|
46
|
+
stateDir: string;
|
|
47
|
+
reason: IntegrityReason;
|
|
48
|
+
publicKeyPem: string;
|
|
49
|
+
privateKeyPem: string;
|
|
50
|
+
memoryHead?: {
|
|
51
|
+
seq: number;
|
|
52
|
+
lastHash: string;
|
|
53
|
+
};
|
|
54
|
+
alarmWebhookUrl?: string;
|
|
55
|
+
now?: number;
|
|
56
|
+
}): AlarmEnvelope | null;
|
|
57
|
+
/** On open: finish a missing halt, a missing outbox, or a resume-pending delivery. Same eventId. */
|
|
58
|
+
export declare function completeMemoryIntegrityIncident(opts: {
|
|
59
|
+
stateDir: string;
|
|
60
|
+
publicKeyPem: string;
|
|
61
|
+
privateKeyPem: string;
|
|
62
|
+
memoryHead?: {
|
|
63
|
+
seq: number;
|
|
64
|
+
lastHash: string;
|
|
65
|
+
};
|
|
66
|
+
alarmWebhookUrl?: string;
|
|
67
|
+
}): AlarmEnvelope | null;
|