@agent-custody/state 0.9.0 → 0.11.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/README.md +2 -1
- package/dist/cli.js +13 -2
- package/dist/http.js +22 -1
- package/dist/stores.d.ts +1 -1
- package/dist/stores.js +5 -1
- package/dist/verify-web.d.ts +1 -0
- package/dist/verify-web.js +11 -3
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -77,7 +77,7 @@ The lookup for writes is optional, so a write that supersedes nothing needs no l
|
|
|
77
77
|
|
|
78
78
|
**Attested executions.** Started with `--key memory.key`, the server signs every result for the receipt the gateway is issuing. A verifier given `memory.pub` then reports the execution of each memory call as attested by the memory server, not only observed by the gateway; the test suite verifies a write this way.
|
|
79
79
|
|
|
80
|
-
**Shared over HTTP.** `agent-custody-memory serve --ledger ./ledger.jsonl --http --port 8790 --token-env MEMORY_TOKEN --allow-direct --direct-token-env MEMORY_DIRECT_TOKEN` serves the same tools over Streamable HTTP, so several gateways, one per agent host, and, with `--allow-direct`, SDK-only agents share one ledger. The two kinds of caller hold different tokens, and the token decides what the server believes: a gateway's call carries the receipt id, the agent, and the facts the gateway observed in its `_meta`, and that is what makes a write attested or verified; a direct writer's `_meta` is dropped before the server reads it, so it can claim a fact and never attest one, whatever its call says. Never give a direct writer the gateway's token. That is the deployment quarantine was built for: writes arriving through a gateway are attested, writes arriving directly are claimed and hidden until a gateway confirms them, and the ledger tells them apart. A gateway reaches it with `"upstream": { "url": "http://127.0.0.1:8790/mcp", "tokenEnv": "MEMORY_TOKEN" }` in its config. The server does not start over HTTP without the gateway token, because without it any caller that reaches the port could pass as a gateway. The test suite runs exactly this: one gateway writer, one direct writer, one ledger.
|
|
80
|
+
**Shared over HTTP.** `agent-custody-memory serve --ledger ./ledger.jsonl --http --port 8790 --token-env MEMORY_TOKEN --allow-direct --direct-token-env MEMORY_DIRECT_TOKEN` serves the same tools over Streamable HTTP, so several gateways, one per agent host, and, with `--allow-direct`, SDK-only agents share one ledger. The two kinds of caller hold different tokens, and the token decides what the server believes: a gateway's call carries the receipt id, the agent, and the facts the gateway observed in its `_meta`, and that is what makes a write attested or verified; a direct writer's `_meta` is dropped before the server reads it, so it can claim a fact and never attest one, whatever its call says. Never give a direct writer the gateway's token. That is the deployment quarantine was built for: writes arriving through a gateway are attested, writes arriving directly are claimed and hidden until a gateway confirms them, and the ledger tells them apart. A gateway reaches it with `"upstream": { "url": "http://127.0.0.1:8790/mcp", "tokenEnv": "MEMORY_TOKEN" }` in its config. The server does not start over HTTP without the gateway token, because without it any caller that reaches the port could pass as a gateway. The test suite runs exactly this: one gateway writer, one direct writer, one ledger. SIGINT or SIGTERM closes the server and the ledger, so a container runtime or systemd stops it cleanly; the review console does the same. The server stops listening, closes idle connections at once, and lets a request in flight finish. After 3 seconds it cuts the connections that remain, for example a request whose body never arrives. The server opens no GET stream (it answers GET with 405, which the gateway's client accepts), so a connected gateway does not hold the stop.
|
|
81
81
|
|
|
82
82
|
[Writing policies](../receipts/docs/policies.md#policies-for-memory) in the receipts guide has six tested policies for the memory tools, from confining an agent to its team's space to a complete support-agent policy. Trust tiers are Cedar policies over the space and, through `includeClaimed`, over quarantine: `permit(principal, action == Action::"memory.write", resource) when { context.args.space == "team:support" };` lets this agent write team memory and nothing else. A read's receipt carries, as `observed`, the exact facts returned, so the ids the agent relied on are already on the record.
|
|
83
83
|
|
|
@@ -239,6 +239,7 @@ Limits:
|
|
|
239
239
|
|
|
240
240
|
- An entry whose `storedAt` is missing or does not parse counts as young. The sweep never removes it. When the metadata has no `storedAt`, the adapters fall back to the creation time of the store: the `created_at` column for pgvector, and the creation time that the client reports for Mem0, Zep, Letta, and LangGraph. Cognee has a fallback only if its listing has a creation time. Letta records `storedAt` in the tag `stored:<iso>`.
|
|
241
241
|
- One store scope belongs to one ledger. A store scope is a pgvector table, a Mem0 user, a Zep user or graph, a Letta agent with its exact tag set, a LangGraph namespace, or a Cognee dataset. Two ledgers that share a scope already leak recall between them, and a repair on one ledger removes the entries of the other.
|
|
242
|
+
- A change to the tag set of a Letta store strands the passages that the store wrote under the old tags. The exact tag set is the scope, as the namespace is for LangGraph. The new store does not list the old passages, and `memory.repair` cannot remove the orphans among them. `lettaStore` throws on a tag that is `agent-custody` or starts with `fact:`, `space:`, `stored:`, or `receipt:`.
|
|
242
243
|
- The clocks of the memory servers must agree to within a few minutes. `storedAt` comes from the clock of the writer, and the cutoff comes from the clock of the repairer.
|
|
243
244
|
- A store without `list` is reported in `unlisted` and is not swept. Mem0, Zep, and Letta get `list` when their client has a method to list entries.
|
|
244
245
|
- The sweep finds only entries that carry custody metadata (`source: "agent-custody"` and a fact id). It does not touch other entries in the store.
|
package/dist/cli.js
CHANGED
|
@@ -112,6 +112,14 @@ const USAGE = `agent-custody-memory <command>
|
|
|
112
112
|
blast --ledger <ledger.jsonl> --receipts <dir> --fact <factId> [--capture-key-env NAME] [--json]
|
|
113
113
|
everything that relied on a fact: later calls, derived beliefs, and whether it was retracted
|
|
114
114
|
`;
|
|
115
|
+
/**
|
|
116
|
+
* Resolves on SIGINT or SIGTERM: a container runtime and systemd stop a service with SIGTERM, which PID 1 ignores unless
|
|
117
|
+
* it is handled. Call it before the service starts, so a signal that arrives while it starts up is kept.
|
|
118
|
+
*/
|
|
119
|
+
const untilStopped = () => new Promise((resolve) => {
|
|
120
|
+
process.once("SIGINT", resolve);
|
|
121
|
+
process.once("SIGTERM", resolve);
|
|
122
|
+
});
|
|
115
123
|
async function main(argv) {
|
|
116
124
|
const [cmd, ...rest] = argv;
|
|
117
125
|
switch (cmd) {
|
|
@@ -136,12 +144,14 @@ async function main(argv) {
|
|
|
136
144
|
throw new Error(`serve: environment variable ${values["direct-token-env"]} is not set`);
|
|
137
145
|
if (values["allow-direct"] && !directToken)
|
|
138
146
|
throw new Error("serve --http --allow-direct needs --direct-token-env: direct writers present their own token, never the gateways'");
|
|
147
|
+
const stopped = untilStopped();
|
|
139
148
|
const running = await serveMemoryHttp(ledger, { port: Number(values.port), host: values.host, ...common, tokens: [token], ...(directToken ? { directTokens: [directToken] } : {}) });
|
|
140
149
|
console.error(`agent-custody-memory: ${running.url} ledger=${values.ledger} events=${await ledger.count()} gateway token required ${values["allow-direct"] ? "direct writers with their own token" : "gateway calls only"}`);
|
|
141
150
|
if (digestWarning)
|
|
142
151
|
console.error(digestWarning);
|
|
143
|
-
await
|
|
152
|
+
await stopped;
|
|
144
153
|
await running.close();
|
|
154
|
+
await ledger.close();
|
|
145
155
|
return 0;
|
|
146
156
|
}
|
|
147
157
|
console.error(`agent-custody-memory: ledger=${values.ledger} events=${await ledger.count()} ${values["allow-direct"] ? "direct calls allowed" : "gateway calls only"}`);
|
|
@@ -322,9 +332,10 @@ async function main(argv) {
|
|
|
322
332
|
await ledger?.close();
|
|
323
333
|
return 0;
|
|
324
334
|
}
|
|
335
|
+
const stopped = untilStopped();
|
|
325
336
|
const running = await serveReview(o, { port: Number(values.port), host: values.host });
|
|
326
337
|
console.error(`agent-custody-memory review: ${running.url} receipts=${values.receipts}${ledger ? ` ledger=${values.ledger}` : ""}${keys ? " verifying" : " not verifying (no keys given)"}`);
|
|
327
|
-
await
|
|
338
|
+
await stopped;
|
|
328
339
|
await running.close();
|
|
329
340
|
await ledger?.close();
|
|
330
341
|
return 0;
|
package/dist/http.js
CHANGED
|
@@ -38,6 +38,12 @@ export function memoryHttpHandler(ledger, opts) {
|
|
|
38
38
|
res.end(JSON.stringify({ error: "unauthorized" }));
|
|
39
39
|
return;
|
|
40
40
|
}
|
|
41
|
+
// The server is stateless and sends no server-initiated message, so it offers no GET stream. A held stream would also keep close() from finishing.
|
|
42
|
+
if (req.method !== "POST") {
|
|
43
|
+
res.writeHead(405, { allow: "POST", "content-type": "application/json" });
|
|
44
|
+
res.end(JSON.stringify({ error: "method not allowed" }));
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
41
47
|
const transport = new StreamableHTTPServerTransport({ sessionIdGenerator: undefined, enableJsonResponse: true });
|
|
42
48
|
// A direct writer's _meta is dropped: with requireGateway it is then refused outright, without it its writes are claimed.
|
|
43
49
|
const server = createMemoryServer(ledger, { ...opts, trustMeta: caller === "gateway" });
|
|
@@ -49,6 +55,21 @@ export function memoryHttpHandler(ledger, opts) {
|
|
|
49
55
|
await transport.handleRequest(req, res);
|
|
50
56
|
};
|
|
51
57
|
}
|
|
58
|
+
/** How long a stop waits for requests in flight before it cuts the connections that remain. */
|
|
59
|
+
const STOP_DEADLINE_MS = 3000;
|
|
60
|
+
/** Stops listening. Requests in flight finish. Idle connections close at once, and any connection that remains after the deadline closes too. */
|
|
61
|
+
function stopServer(server) {
|
|
62
|
+
return new Promise((resolve) => {
|
|
63
|
+
const idle = setInterval(() => server.closeIdleConnections(), 100);
|
|
64
|
+
const deadline = setTimeout(() => server.closeAllConnections(), STOP_DEADLINE_MS);
|
|
65
|
+
server.close(() => {
|
|
66
|
+
clearInterval(idle);
|
|
67
|
+
clearTimeout(deadline);
|
|
68
|
+
resolve();
|
|
69
|
+
});
|
|
70
|
+
server.closeIdleConnections();
|
|
71
|
+
});
|
|
72
|
+
}
|
|
52
73
|
/** Starts the memory server over HTTP. Port 0 picks a free port. Host defaults to loopback; bind wider only behind auth. */
|
|
53
74
|
export async function serveMemoryHttp(ledger, opts) {
|
|
54
75
|
const host = opts.host ?? "127.0.0.1";
|
|
@@ -59,7 +80,7 @@ export async function serveMemoryHttp(ledger, opts) {
|
|
|
59
80
|
return new Promise((resolve) => {
|
|
60
81
|
server.listen(opts.port, host, () => {
|
|
61
82
|
const { port } = server.address();
|
|
62
|
-
resolve({ url: `http://${host}:${port}/mcp`, close: () =>
|
|
83
|
+
resolve({ url: `http://${host}:${port}/mcp`, close: () => stopServer(server) });
|
|
63
84
|
});
|
|
64
85
|
});
|
|
65
86
|
}
|
package/dist/stores.d.ts
CHANGED
|
@@ -210,7 +210,7 @@ export interface LettaLike {
|
|
|
210
210
|
export interface LettaOptions {
|
|
211
211
|
/** the agent whose archival memory receives the fact */
|
|
212
212
|
agentId: string;
|
|
213
|
-
/** tags attached to every passage, beside the custody tags; list() returns only passages whose tags, beside the custody tags, are exactly this set; default none */
|
|
213
|
+
/** tags attached to every passage, beside the custody tags; list() returns only passages whose tags, beside the custody tags, are exactly this set; a tag that is `agent-custody` or starts with `fact:`, `space:`, `stored:`, or `receipt:` is reserved, and lettaStore throws on it; default none */
|
|
214
214
|
tags?: string[];
|
|
215
215
|
}
|
|
216
216
|
/**
|
package/dist/stores.js
CHANGED
|
@@ -185,11 +185,15 @@ export function pgvectorStore(client, opts) {
|
|
|
185
185
|
},
|
|
186
186
|
};
|
|
187
187
|
}
|
|
188
|
+
const lettaCustodyTag = (t) => t === "agent-custody" || /^(fact|space|stored|receipt):/.test(t);
|
|
188
189
|
/**
|
|
189
190
|
* Letta keeps archival memory as passages with text and tags, no free metadata. Custody travels as tags
|
|
190
191
|
* (`agent-custody`, `fact:<id>`, `space:<name>`, `receipt:<id>`) so a passage always leads back to its fact.
|
|
191
192
|
*/
|
|
192
193
|
export function lettaStore(client, opts) {
|
|
194
|
+
const reserved = opts.tags?.find(lettaCustodyTag);
|
|
195
|
+
if (reserved !== undefined)
|
|
196
|
+
throw new Error(`lettaStore: the tag "${reserved}" is reserved for custody; use another tag`);
|
|
193
197
|
const tagsFor = (f) => ["agent-custody", `fact:${f.factId}`, `space:${f.space}`, `stored:${new Date().toISOString()}`, ...(f.source.receiptId ? [`receipt:${f.source.receiptId}`] : []), ...(opts.tags ?? [])];
|
|
194
198
|
return {
|
|
195
199
|
name: "letta",
|
|
@@ -225,7 +229,7 @@ export function lettaStore(client, opts) {
|
|
|
225
229
|
if (!p.id || !fresh.has(p.id))
|
|
226
230
|
continue;
|
|
227
231
|
const factTag = p.tags?.find((t) => t.startsWith("fact:"));
|
|
228
|
-
const rest = new Set((p.tags ?? []).filter((t) =>
|
|
232
|
+
const rest = new Set((p.tags ?? []).filter((t) => !lettaCustodyTag(t)));
|
|
229
233
|
if (p.id && factTag && p.tags.includes("agent-custody") && rest.size === own.size && [...own].every((t) => rest.has(t)))
|
|
230
234
|
out.push({ externalId: p.id, factId: factTag.slice("fact:".length), text: p.text, ...stored(p.tags.find((t) => t.startsWith("stored:"))?.slice("stored:".length), p.created_at) });
|
|
231
235
|
}
|
package/dist/verify-web.d.ts
CHANGED
package/dist/verify-web.js
CHANGED
|
@@ -453,6 +453,12 @@ export async function verifyBundle(bundle, opts) {
|
|
|
453
453
|
const p = st.predicate;
|
|
454
454
|
add("issuer kind is known", p.issuer.kind === "gateway" || p.issuer.kind === "sdk", `${p.issuer.kind}${p.issuer.framework ? ` / ${p.issuer.framework}` : ""}`);
|
|
455
455
|
add("issuer keyid matches signer", p.issuer.keyid === sig.keyid);
|
|
456
|
+
if (opts.requireStrict) {
|
|
457
|
+
add("strict mode in force", p.issuer.kind === "gateway" && p.issuer.strict === true, p.issuer.strict === true ? undefined : "the issuer does not say it ran in strict mode");
|
|
458
|
+
// under strict mode every call is precommitted; a provider read the operator ran is a lookup, not a call
|
|
459
|
+
const forwarded = p.execution.status === "executed" || p.execution.status === "failed" || p.execution.status === "error";
|
|
460
|
+
add("strict: call precommitted before forwarding", !forwarded || !!p.reconciliation || !!p.authorization, forwarded && !p.reconciliation && !p.authorization ? `the call was ${p.execution.status} with no authorization committed first` : undefined);
|
|
461
|
+
}
|
|
456
462
|
if (p.operation) {
|
|
457
463
|
add("operation observed by gateway", p.issuer.kind === "gateway" && p.operation.provenance === "observed");
|
|
458
464
|
if (!p.reconciliation) {
|
|
@@ -826,7 +832,7 @@ export function formatReport(r) {
|
|
|
826
832
|
if (!r.statement)
|
|
827
833
|
return lines.join("\n");
|
|
828
834
|
const p = r.statement.predicate;
|
|
829
|
-
lines.push("", `ISSUER: ${p.issuer.kind}${p.issuer.framework ? ` (${p.issuer.framework})` : ""}, ${r.issuerNote}`, "", "field provenance value");
|
|
835
|
+
lines.push("", `ISSUER: ${p.issuer.kind}${p.issuer.framework ? ` (${p.issuer.framework})` : ""}${p.issuer.strict ? ", strict mode" : ""}, ${r.issuerNote}`, "", "field provenance value");
|
|
830
836
|
const row = (f, prov, v) => lines.push(`${f.padEnd(15)} ${prov.padEnd(11)} ${typeof v === "string" ? v : JSON.stringify(v)}`);
|
|
831
837
|
row("principal", p.principal.provenance, p.principal.id ?? "(none)");
|
|
832
838
|
row("agent", p.agent.provenance, p.agent.id);
|
|
@@ -838,7 +844,9 @@ export function formatReport(r) {
|
|
|
838
844
|
row("args", p.request.provenance, p.request.args);
|
|
839
845
|
for (const [k, f] of Object.entries(p.facts))
|
|
840
846
|
row(`fact.${k}`, f.provenance, f.value);
|
|
841
|
-
if (p.
|
|
847
|
+
if (p.reconciliation)
|
|
848
|
+
row("policy", "-", "(none evaluated: a provider read, not a call)");
|
|
849
|
+
else if (p.policy)
|
|
842
850
|
row("policy", p.policy.provenance, `${p.policy.decision}${p.policy.enforced === false ? " (observe mode, not enforced)" : ""} [${p.policy.reasons.join(",")}] policy ${short(p.policy.policyDigest)}`);
|
|
843
851
|
else
|
|
844
852
|
row("policy", "-", "(none evaluated)");
|
|
@@ -851,6 +859,6 @@ export function formatReport(r) {
|
|
|
851
859
|
const byProvider = hasUpstream && !!p.execution.upstream.provider;
|
|
852
860
|
const attestedAs = upstreamCheck?.ok ? (byProvider ? "attested (shared secret)" : "attested") : p.execution.provenance;
|
|
853
861
|
const note = !hasUpstream ? "" : upstreamCheck ? (upstreamCheck.ok ? ` (${byProvider ? upstreamCheck.detail : `signed by upstream ${upstreamCheck.detail}`})` : " (upstream signature FAILED)") : byProvider ? " (carries a provider delivery; add the provider secret to check it)" : " (carries an upstream signature; add the upstream key to check it)";
|
|
854
|
-
row("execution", attestedAs, `${p.execution.status}${note}`);
|
|
862
|
+
row("execution", attestedAs, `${p.reconciliation ? "provider read, " : ""}${p.execution.status}${note}`);
|
|
855
863
|
return lines.join("\n");
|
|
856
864
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agent-custody/state",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.11.0",
|
|
4
4
|
"description": "Governed memory for AI agents: a fact ledger with provenance, valid time, rollback, lineage, certified forget, and a store that is a JSONL file, SQLite, or Postgres, built on @agent-custody/receipts",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
"node": ">=22"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@agent-custody/receipts": "0.
|
|
36
|
+
"@agent-custody/receipts": "0.11.0",
|
|
37
37
|
"@modelcontextprotocol/sdk": "^1.30.0",
|
|
38
38
|
"zod": "^4.5.4"
|
|
39
39
|
},
|