@verax-ai/body 0.6.1 → 0.7.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/approve-cli.js +1 -1
- 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/halt.d.ts +28 -9
- package/dist/halt.js +126 -18
- 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-handlers.js +29 -8
- package/dist/server.js +39 -8
- 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
package/dist/keys.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { createPublicKey, generateKeyPairSync } from "node:crypto";
|
|
2
|
-
import { mkdirSync, readFileSync, renameSync, writeFileSync, existsSync } from "node:fs";
|
|
3
|
-
import { join } from "node:path";
|
|
1
|
+
import { createPrivateKey, createPublicKey, generateKeyPairSync } from "node:crypto";
|
|
2
|
+
import { mkdirSync, readFileSync, realpathSync, renameSync, writeFileSync, existsSync } from "node:fs";
|
|
3
|
+
import { basename, dirname, isAbsolute, join, relative, resolve, sep } from "node:path";
|
|
4
4
|
import { EX_CONFIG } from "./config.js";
|
|
5
5
|
export class KeysPartialError extends Error {
|
|
6
6
|
code = EX_CONFIG;
|
|
@@ -40,8 +40,62 @@ function writePemAtomic(path, pem) {
|
|
|
40
40
|
writeFileSync(tmp, pem, { encoding: "utf8", mode: 0o600 });
|
|
41
41
|
renameSync(tmp, path);
|
|
42
42
|
}
|
|
43
|
-
|
|
44
|
-
|
|
43
|
+
/** Keys live here. Default is `<stateDir>/keys`; `listen` / `createBodyServices` may pass `keysDir`. */
|
|
44
|
+
export function resolveKeysDir(stateDir, keysDir) {
|
|
45
|
+
const explicit = keysDir?.trim();
|
|
46
|
+
if (explicit)
|
|
47
|
+
return explicit;
|
|
48
|
+
return join(stateDir, "keys");
|
|
49
|
+
}
|
|
50
|
+
/** Memory head lives here. `VERAX_MEMORY_HEAD_DIR` wins; otherwise the keys directory. */
|
|
51
|
+
export function resolveHeadDir(stateDir, keysDir, headDir) {
|
|
52
|
+
const explicit = headDir?.trim();
|
|
53
|
+
if (explicit)
|
|
54
|
+
return explicit;
|
|
55
|
+
return resolveKeysDir(stateDir, keysDir);
|
|
56
|
+
}
|
|
57
|
+
/** Physical path for custody and head identity: junctions resolved, win32 case-folded. */
|
|
58
|
+
export function canonicalizeDirPath(dir) {
|
|
59
|
+
const abs = resolve(dir);
|
|
60
|
+
let real = abs;
|
|
61
|
+
try {
|
|
62
|
+
real = realpathSync.native(abs);
|
|
63
|
+
}
|
|
64
|
+
catch {
|
|
65
|
+
// Missing leaf: realpath the nearest existing ancestor, then reattach the rest.
|
|
66
|
+
const missing = [];
|
|
67
|
+
let cursor = abs;
|
|
68
|
+
for (;;) {
|
|
69
|
+
const parent = dirname(cursor);
|
|
70
|
+
if (parent === cursor)
|
|
71
|
+
break;
|
|
72
|
+
missing.unshift(basename(cursor));
|
|
73
|
+
try {
|
|
74
|
+
real = join(realpathSync.native(parent), ...missing);
|
|
75
|
+
break;
|
|
76
|
+
}
|
|
77
|
+
catch {
|
|
78
|
+
cursor = parent;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
return process.platform === "win32" ? real.toLowerCase() : real;
|
|
83
|
+
}
|
|
84
|
+
/** True when `inner` is `root` or a path under it. */
|
|
85
|
+
export function pathIsInsideDir(root, inner) {
|
|
86
|
+
const rootAbs = canonicalizeDirPath(root);
|
|
87
|
+
const innerAbs = canonicalizeDirPath(inner);
|
|
88
|
+
if (innerAbs === rootAbs)
|
|
89
|
+
return true;
|
|
90
|
+
const rel = relative(rootAbs, innerAbs);
|
|
91
|
+
if (rel === "")
|
|
92
|
+
return true;
|
|
93
|
+
if (isAbsolute(rel))
|
|
94
|
+
return false;
|
|
95
|
+
return rel !== ".." && !rel.startsWith(`..${sep}`);
|
|
96
|
+
}
|
|
97
|
+
export function loadOrCreateSigners(stateDir, keysDir) {
|
|
98
|
+
const dir = resolveKeysDir(stateDir, keysDir);
|
|
45
99
|
mkdirSync(dir, { recursive: true, mode: 0o700 });
|
|
46
100
|
const recPriv = join(dir, "record.private.pem");
|
|
47
101
|
const recPub = join(dir, "record.public.pem");
|
|
@@ -76,3 +130,53 @@ export function loadOrCreateSigners(stateDir) {
|
|
|
76
130
|
assertEd25519PublicKey(loaded.effectSigner.publicKeyPem, "effect");
|
|
77
131
|
return loaded;
|
|
78
132
|
}
|
|
133
|
+
function publicKeyDer(pem) {
|
|
134
|
+
return createPublicKey(pem).export({ type: "spki", format: "der" });
|
|
135
|
+
}
|
|
136
|
+
function publicKeyDerFromPrivate(pem) {
|
|
137
|
+
return createPublicKey(createPrivateKey(pem)).export({ type: "spki", format: "der" });
|
|
138
|
+
}
|
|
139
|
+
function assertSignerMatchesPublicKey(publicKeyPem, privateKeyPem) {
|
|
140
|
+
if (!publicKeyDer(publicKeyPem).equals(publicKeyDerFromPrivate(privateKeyPem))) {
|
|
141
|
+
throw new Error("record-public-key-mismatch");
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
function resolveTrustPublicKey(opts) {
|
|
145
|
+
const explicit = opts.keysDir?.trim();
|
|
146
|
+
if (!explicit) {
|
|
147
|
+
assertSignerMatchesPublicKey(opts.recordSigner.publicKeyPem, opts.recordSigner.privateKeyPem);
|
|
148
|
+
return opts.recordSigner.publicKeyPem;
|
|
149
|
+
}
|
|
150
|
+
const trustPub = join(resolveKeysDir(opts.stateDir, explicit), "record.public.pem");
|
|
151
|
+
if (!existsSync(trustPub)) {
|
|
152
|
+
throw new Error(`record-public-key-missing:${trustPub}`);
|
|
153
|
+
}
|
|
154
|
+
const publicKeyPem = readFileSync(trustPub, "utf8");
|
|
155
|
+
assertEd25519PublicKey(publicKeyPem, "record");
|
|
156
|
+
assertSignerMatchesPublicKey(publicKeyPem, opts.recordSigner.privateKeyPem);
|
|
157
|
+
return publicKeyPem;
|
|
158
|
+
}
|
|
159
|
+
function assertRecordPubkeyPin(publicKeyPem) {
|
|
160
|
+
const pin = process.env.VERAX_RECORD_PUBKEY_PIN?.trim() ?? "";
|
|
161
|
+
if (pin === "")
|
|
162
|
+
return;
|
|
163
|
+
let pinnedDer;
|
|
164
|
+
try {
|
|
165
|
+
pinnedDer = publicKeyDer(pin);
|
|
166
|
+
}
|
|
167
|
+
catch {
|
|
168
|
+
throw new Error("record-pubkey-pin-mismatch");
|
|
169
|
+
}
|
|
170
|
+
if (!pinnedDer.equals(publicKeyDer(publicKeyPem))) {
|
|
171
|
+
throw new Error("record-pubkey-pin-mismatch");
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Record public/private match plus `VERAX_RECORD_PUBKEY_PIN` (PEM).
|
|
176
|
+
* Body open, rehead, and reattest call this before any head write.
|
|
177
|
+
*/
|
|
178
|
+
export function assertRecordKeyTrust(opts) {
|
|
179
|
+
const publicKeyPem = resolveTrustPublicKey(opts);
|
|
180
|
+
assertRecordPubkeyPin(publicKeyPem);
|
|
181
|
+
return publicKeyPem;
|
|
182
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Convert 0.6.1 flat `<id>.json` files to revision 1 and append signed commits.
|
|
3
|
+
* The body must be stopped: a running body holds the ledger lock.
|
|
4
|
+
*/
|
|
5
|
+
export declare function runMemoryReattest(argv: string[], stdout?: {
|
|
6
|
+
write(s: string): unknown;
|
|
7
|
+
}, stderr?: {
|
|
8
|
+
write(s: string): unknown;
|
|
9
|
+
}, env?: NodeJS.ProcessEnv): Promise<number>;
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { readFileSync } from "node:fs";
|
|
2
|
+
import { FileLedger } from "@verax-ai/proxy";
|
|
3
|
+
import { EX_CONFIG } from "./config.js";
|
|
4
|
+
import { assertRecordKeyTrust, loadOrCreateSigners, resolveHeadDir } from "./keys.js";
|
|
5
|
+
import { listLegacyMemoryFiles, openMemoryStoreSync } from "./memory-store.js";
|
|
6
|
+
function usage() {
|
|
7
|
+
return "verax memory reattest <stateDir>\n";
|
|
8
|
+
}
|
|
9
|
+
function parseLegacy(raw) {
|
|
10
|
+
let parsed;
|
|
11
|
+
try {
|
|
12
|
+
parsed = JSON.parse(raw);
|
|
13
|
+
}
|
|
14
|
+
catch {
|
|
15
|
+
return null;
|
|
16
|
+
}
|
|
17
|
+
if (parsed === null || typeof parsed !== "object" || Array.isArray(parsed))
|
|
18
|
+
return null;
|
|
19
|
+
const item = parsed;
|
|
20
|
+
if (typeof item.id !== "string" || item.id === "")
|
|
21
|
+
return null;
|
|
22
|
+
if (item.source === null || typeof item.source !== "object" || Array.isArray(item.source))
|
|
23
|
+
return null;
|
|
24
|
+
if (typeof item.validUntilMs !== "number")
|
|
25
|
+
return null;
|
|
26
|
+
const validFromMs = typeof item.validFromMs === "number" ? item.validFromMs : 0;
|
|
27
|
+
return { id: item.id, body: item.body, source: item.source, validFromMs, validUntilMs: item.validUntilMs };
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Convert 0.6.1 flat `<id>.json` files to revision 1 and append signed commits.
|
|
31
|
+
* The body must be stopped: a running body holds the ledger lock.
|
|
32
|
+
*/
|
|
33
|
+
export async function runMemoryReattest(argv, stdout = process.stdout, stderr = process.stderr, env = process.env) {
|
|
34
|
+
if (argv[0] !== "reattest") {
|
|
35
|
+
stderr.write(usage());
|
|
36
|
+
return EX_CONFIG;
|
|
37
|
+
}
|
|
38
|
+
const stateDir = (argv[1] ?? env.VERAX_STATE_DIR ?? "").trim();
|
|
39
|
+
if (stateDir === "") {
|
|
40
|
+
stderr.write(usage());
|
|
41
|
+
return EX_CONFIG;
|
|
42
|
+
}
|
|
43
|
+
let ledger;
|
|
44
|
+
try {
|
|
45
|
+
ledger = new FileLedger(stateDir);
|
|
46
|
+
}
|
|
47
|
+
catch (err) {
|
|
48
|
+
const msg = err instanceof Error ? err.message : "";
|
|
49
|
+
if (msg.startsWith("ledger-locked")) {
|
|
50
|
+
stderr.write("memory-reattest-body-running\n");
|
|
51
|
+
return 1;
|
|
52
|
+
}
|
|
53
|
+
stderr.write(`memory-reattest-failed:${msg.split("\n")[0] ?? "unknown"}\n`);
|
|
54
|
+
return 1;
|
|
55
|
+
}
|
|
56
|
+
try {
|
|
57
|
+
const keysDir = env.VERAX_KEYS_DIR;
|
|
58
|
+
const signers = loadOrCreateSigners(stateDir, keysDir);
|
|
59
|
+
const publicKeyPem = assertRecordKeyTrust({
|
|
60
|
+
stateDir,
|
|
61
|
+
keysDir,
|
|
62
|
+
recordSigner: signers.recordSigner,
|
|
63
|
+
});
|
|
64
|
+
const store = openMemoryStoreSync({
|
|
65
|
+
stateDir,
|
|
66
|
+
publicKeyPem,
|
|
67
|
+
privateKeyPem: signers.recordSigner.privateKeyPem,
|
|
68
|
+
headDir: resolveHeadDir(stateDir, keysDir, env.VERAX_MEMORY_HEAD_DIR),
|
|
69
|
+
});
|
|
70
|
+
if (store.historyUnavailable) {
|
|
71
|
+
stderr.write("memory-reattest-history-unavailable\n");
|
|
72
|
+
return 1;
|
|
73
|
+
}
|
|
74
|
+
const files = listLegacyMemoryFiles(stateDir);
|
|
75
|
+
if (files.length === 0) {
|
|
76
|
+
stdout.write("reattested:none\n");
|
|
77
|
+
return 0;
|
|
78
|
+
}
|
|
79
|
+
for (const file of files) {
|
|
80
|
+
const parsed = parseLegacy(readFileSync(file.path, "utf8"));
|
|
81
|
+
if (parsed === null || parsed.id !== file.id) {
|
|
82
|
+
stderr.write(`memory-reattest-skip:${file.tenantKey}/${file.id}\n`);
|
|
83
|
+
continue;
|
|
84
|
+
}
|
|
85
|
+
const result = await store.reattestLegacy({
|
|
86
|
+
tenantKey: file.tenantKey,
|
|
87
|
+
id: file.id,
|
|
88
|
+
body: parsed.body,
|
|
89
|
+
source: parsed.source,
|
|
90
|
+
validFromMs: parsed.validFromMs,
|
|
91
|
+
validUntilMs: parsed.validUntilMs,
|
|
92
|
+
legacyPath: file.path,
|
|
93
|
+
});
|
|
94
|
+
if ("skipped" in result) {
|
|
95
|
+
stderr.write(`memory-reattest-skip:${file.tenantKey}/${file.id}\n`);
|
|
96
|
+
continue;
|
|
97
|
+
}
|
|
98
|
+
stdout.write(`${file.id}\n`);
|
|
99
|
+
}
|
|
100
|
+
return 0;
|
|
101
|
+
}
|
|
102
|
+
catch (err) {
|
|
103
|
+
const msg = err instanceof Error ? err.message : "unknown";
|
|
104
|
+
stderr.write(`memory-reattest-failed:${msg.split("\n")[0] ?? "unknown"}\n`);
|
|
105
|
+
return 1;
|
|
106
|
+
}
|
|
107
|
+
finally {
|
|
108
|
+
ledger.close();
|
|
109
|
+
}
|
|
110
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Write a signed memory head from the current commit tip.
|
|
3
|
+
* The body must be stopped: a running body holds the ledger lock.
|
|
4
|
+
*/
|
|
5
|
+
export declare function runMemoryRehead(argv: string[], stdout?: {
|
|
6
|
+
write(s: string): unknown;
|
|
7
|
+
}, stderr?: {
|
|
8
|
+
write(s: string): unknown;
|
|
9
|
+
}, env?: NodeJS.ProcessEnv): Promise<number>;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { FileLedger } from "@verax-ai/proxy";
|
|
2
|
+
import { EX_CONFIG } from "./config.js";
|
|
3
|
+
import { assertRecordKeyTrust, loadOrCreateSigners, resolveHeadDir } from "./keys.js";
|
|
4
|
+
import { reheadMemoryFromChain } from "./memory-store.js";
|
|
5
|
+
function usage() {
|
|
6
|
+
return "verax memory rehead <stateDir>\n";
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Write a signed memory head from the current commit tip.
|
|
10
|
+
* The body must be stopped: a running body holds the ledger lock.
|
|
11
|
+
*/
|
|
12
|
+
export async function runMemoryRehead(argv, stdout = process.stdout, stderr = process.stderr, env = process.env) {
|
|
13
|
+
if (argv[0] !== "rehead") {
|
|
14
|
+
stderr.write(usage());
|
|
15
|
+
return EX_CONFIG;
|
|
16
|
+
}
|
|
17
|
+
const stateDir = (argv[1] ?? env.VERAX_STATE_DIR ?? "").trim();
|
|
18
|
+
if (stateDir === "") {
|
|
19
|
+
stderr.write(usage());
|
|
20
|
+
return EX_CONFIG;
|
|
21
|
+
}
|
|
22
|
+
let ledger;
|
|
23
|
+
try {
|
|
24
|
+
ledger = new FileLedger(stateDir);
|
|
25
|
+
}
|
|
26
|
+
catch (err) {
|
|
27
|
+
const msg = err instanceof Error ? err.message : "";
|
|
28
|
+
if (msg.startsWith("ledger-locked")) {
|
|
29
|
+
stderr.write("memory-rehead-body-running\n");
|
|
30
|
+
return 1;
|
|
31
|
+
}
|
|
32
|
+
stderr.write(`memory-rehead-failed:${msg.split("\n")[0] ?? "unknown"}\n`);
|
|
33
|
+
return 1;
|
|
34
|
+
}
|
|
35
|
+
try {
|
|
36
|
+
const keysDir = env.VERAX_KEYS_DIR;
|
|
37
|
+
const signers = loadOrCreateSigners(stateDir, keysDir);
|
|
38
|
+
const publicKeyPem = assertRecordKeyTrust({
|
|
39
|
+
stateDir,
|
|
40
|
+
keysDir,
|
|
41
|
+
recordSigner: signers.recordSigner,
|
|
42
|
+
});
|
|
43
|
+
const result = reheadMemoryFromChain({
|
|
44
|
+
stateDir,
|
|
45
|
+
publicKeyPem,
|
|
46
|
+
privateKeyPem: signers.recordSigner.privateKeyPem,
|
|
47
|
+
headDir: resolveHeadDir(stateDir, keysDir, env.VERAX_MEMORY_HEAD_DIR),
|
|
48
|
+
});
|
|
49
|
+
if (!result.ok) {
|
|
50
|
+
stderr.write("memory-rehead-invalid\n");
|
|
51
|
+
return 1;
|
|
52
|
+
}
|
|
53
|
+
const shortHash = result.lastHash === null ? "-" : result.lastHash.slice(0, 16);
|
|
54
|
+
stdout.write(`${result.seq} ${shortHash}\n`);
|
|
55
|
+
return 0;
|
|
56
|
+
}
|
|
57
|
+
catch (err) {
|
|
58
|
+
const msg = err instanceof Error ? err.message : "unknown";
|
|
59
|
+
stderr.write(`memory-rehead-failed:${msg.split("\n")[0] ?? "unknown"}\n`);
|
|
60
|
+
return 1;
|
|
61
|
+
}
|
|
62
|
+
finally {
|
|
63
|
+
ledger.close();
|
|
64
|
+
}
|
|
65
|
+
}
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
export declare const MEMORY_COMMITS_FILE = "memory-commits.jsonl";
|
|
2
|
+
export declare const MEMORY_PURPOSE = "verax.memory.v2";
|
|
3
|
+
export declare const MEMORY_HASH_SCHEMA = 2;
|
|
4
|
+
export type MemoryObject = {
|
|
5
|
+
id: string;
|
|
6
|
+
revision: number;
|
|
7
|
+
tenantKey: string;
|
|
8
|
+
body: unknown;
|
|
9
|
+
source: unknown;
|
|
10
|
+
validFromMs: number;
|
|
11
|
+
validUntilMs: number;
|
|
12
|
+
versionHash: string;
|
|
13
|
+
};
|
|
14
|
+
export type MemoryIndexEntry = {
|
|
15
|
+
revision: number;
|
|
16
|
+
versionHash: string;
|
|
17
|
+
objectPath: string;
|
|
18
|
+
};
|
|
19
|
+
export type IntegrityReason = "memory-integrity-mismatch" | "memory-integrity-missing" | "memory-integrity-unattested" | "memory-integrity-history-unavailable";
|
|
20
|
+
export type VerifiedMemory = {
|
|
21
|
+
kind: "ok";
|
|
22
|
+
object: MemoryObject;
|
|
23
|
+
versionHash: string;
|
|
24
|
+
} | {
|
|
25
|
+
kind: "not-found";
|
|
26
|
+
} | {
|
|
27
|
+
kind: "integrity";
|
|
28
|
+
reason: IntegrityReason;
|
|
29
|
+
};
|
|
30
|
+
export type MemoryCommitPayload = {
|
|
31
|
+
v: 1;
|
|
32
|
+
seq: number;
|
|
33
|
+
tenantKey: string;
|
|
34
|
+
id: string;
|
|
35
|
+
revision: number;
|
|
36
|
+
versionHash: string;
|
|
37
|
+
objectPath: string;
|
|
38
|
+
putRef: string;
|
|
39
|
+
prevCommitHash: string | null;
|
|
40
|
+
ts: number;
|
|
41
|
+
};
|
|
42
|
+
export type MemoryHeadPayload = {
|
|
43
|
+
v: 1;
|
|
44
|
+
stateDirHash: string;
|
|
45
|
+
seq: number;
|
|
46
|
+
lastHash: string | null;
|
|
47
|
+
ts: number;
|
|
48
|
+
};
|
|
49
|
+
export declare function memoryVersionHash(fields: {
|
|
50
|
+
tenantKey: string;
|
|
51
|
+
id: string;
|
|
52
|
+
revision: number;
|
|
53
|
+
body: unknown;
|
|
54
|
+
source: unknown;
|
|
55
|
+
validFromMs: number;
|
|
56
|
+
validUntilMs: number;
|
|
57
|
+
}): string;
|
|
58
|
+
export declare function memoryStateDirHash(stateDir: string): string;
|
|
59
|
+
export declare function memoryHeadPath(stateDir: string, headDir: string): string;
|
|
60
|
+
export declare function relativeObjectPath(tenantKey: string, id: string, revision: number): string;
|
|
61
|
+
export declare class MemoryStore {
|
|
62
|
+
readonly stateDir: string;
|
|
63
|
+
readonly headDir: string;
|
|
64
|
+
readonly publicKeyPem: string;
|
|
65
|
+
readonly privateKeyPem: string;
|
|
66
|
+
historyUnavailable: boolean;
|
|
67
|
+
private readonly index;
|
|
68
|
+
private lastSeq;
|
|
69
|
+
private lastHash;
|
|
70
|
+
constructor(opts: {
|
|
71
|
+
stateDir: string;
|
|
72
|
+
headDir: string;
|
|
73
|
+
publicKeyPem: string;
|
|
74
|
+
privateKeyPem: string;
|
|
75
|
+
historyUnavailable: boolean;
|
|
76
|
+
index: Map<string, MemoryIndexEntry>;
|
|
77
|
+
lastSeq: number;
|
|
78
|
+
lastHash: string | null;
|
|
79
|
+
});
|
|
80
|
+
private persistHead;
|
|
81
|
+
rememberDecisionSnapshot(_tenantKey: string, _object: MemoryObject): void;
|
|
82
|
+
withTenantLock<T>(tenantKey: string, fn: () => Promise<T>): Promise<T>;
|
|
83
|
+
/** The signed commit tip, when the store has one. Omitted from an alarm when absent. */
|
|
84
|
+
memoryHead(): {
|
|
85
|
+
seq: number;
|
|
86
|
+
lastHash: string;
|
|
87
|
+
} | undefined;
|
|
88
|
+
lookup(tenantKey: string, id: string): MemoryIndexEntry | undefined;
|
|
89
|
+
idHeldByTenant(id: string, tenantKey: string): boolean;
|
|
90
|
+
idVisibleForOtherTenant(id: string, selfKey: string): boolean;
|
|
91
|
+
objectPresent(tenantKey: string, id: string): boolean;
|
|
92
|
+
verifiedRead(tenantKey: string, id: string): VerifiedMemory;
|
|
93
|
+
put(opts: {
|
|
94
|
+
tenantKey: string;
|
|
95
|
+
id: string;
|
|
96
|
+
body: unknown;
|
|
97
|
+
source: unknown;
|
|
98
|
+
validFromMs: number;
|
|
99
|
+
validUntilMs: number;
|
|
100
|
+
putRef: string;
|
|
101
|
+
quotaBytes: number;
|
|
102
|
+
}): Promise<{
|
|
103
|
+
ok: true;
|
|
104
|
+
id: string;
|
|
105
|
+
revision: number;
|
|
106
|
+
versionHash: string;
|
|
107
|
+
} | {
|
|
108
|
+
ok: false;
|
|
109
|
+
error: "memory-quota" | "memory-integrity-history-unavailable";
|
|
110
|
+
}>;
|
|
111
|
+
reattestLegacy(opts: {
|
|
112
|
+
tenantKey: string;
|
|
113
|
+
id: string;
|
|
114
|
+
body: unknown;
|
|
115
|
+
source: unknown;
|
|
116
|
+
validFromMs: number;
|
|
117
|
+
validUntilMs: number;
|
|
118
|
+
legacyPath: string;
|
|
119
|
+
}): Promise<{
|
|
120
|
+
id: string;
|
|
121
|
+
revision: number;
|
|
122
|
+
versionHash: string;
|
|
123
|
+
} | {
|
|
124
|
+
skipped: true;
|
|
125
|
+
}>;
|
|
126
|
+
private currentUsageBytes;
|
|
127
|
+
}
|
|
128
|
+
export declare function publishMemoryStore(store: MemoryStore): MemoryStore;
|
|
129
|
+
/** Same-process memory gate when the halt switch file cannot be written. */
|
|
130
|
+
export declare function markHistoryUnavailable(stateDir: string): void;
|
|
131
|
+
export declare function reheadMemoryFromChain(opts: {
|
|
132
|
+
stateDir: string;
|
|
133
|
+
publicKeyPem: string;
|
|
134
|
+
privateKeyPem: string;
|
|
135
|
+
headDir?: string;
|
|
136
|
+
}): {
|
|
137
|
+
ok: true;
|
|
138
|
+
seq: number;
|
|
139
|
+
lastHash: string | null;
|
|
140
|
+
} | {
|
|
141
|
+
ok: false;
|
|
142
|
+
};
|
|
143
|
+
export declare function openMemoryStoreSync(opts: {
|
|
144
|
+
stateDir: string;
|
|
145
|
+
publicKeyPem: string;
|
|
146
|
+
privateKeyPem: string;
|
|
147
|
+
headDir?: string;
|
|
148
|
+
}): MemoryStore;
|
|
149
|
+
export declare function memoryStoreFor(stateDir: string, keys?: {
|
|
150
|
+
publicKeyPem: string;
|
|
151
|
+
privateKeyPem: string;
|
|
152
|
+
}): MemoryStore;
|
|
153
|
+
export declare function listLegacyMemoryFiles(stateDir: string): Array<{
|
|
154
|
+
tenantKey: string;
|
|
155
|
+
id: string;
|
|
156
|
+
path: string;
|
|
157
|
+
}>;
|