@agent-custody/state 0.16.5 → 0.16.7

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 CHANGED
@@ -158,7 +158,7 @@ agent-custody-memory review --verify-case refund.case.json --issuer-key keys/gat
158
158
  agent-custody-memory review --verify-case refund.case.html --issuer-key keys/gateway.pub --principal-key keys/principal.pub
159
159
  ```
160
160
 
161
- Filters combine with AND, match exact case-sensitive ids, and search only public arguments, results, and gateway facts. Times must be ISO 8601 date-times with `Z` or a UTC offset. An identifier withheld by a capture rule cannot be searched. A record that lacks a part the pages read (it fails the verifier's structural check) is shown as NOT VERIFIED with the reason, and it does not stop an export. A ledger or file error is not a defect of the record: it fails the export, and the live page answers 500. Search stops at 64 levels of nesting and ignores JSON text longer than 64 KiB, so one hostile argument cannot stall the index. A receipt with a value that search skipped is marked "partially indexed", and an id filter keeps it in the list, because the id may be in the skipped value. The index never drops a record: a file whose receipt id differs from its name is listed as NOT VERIFIED ("file name does not match receipt id"), and the header counts the files that could not be read. `--out <dir>` writes an index, receipt pages and bundles, and each receipt's `.case.html` and `.case.json`; its browser search covers only the receipts included in that export. Add `--approval-key` (once for each human approver) when the receipts are for calls that a human approved: without those keys such a receipt is NOT VERIFIED. Add `--log-key`, `--log-id`, and `--upstream-key` when those signatures need independent keys.
161
+ Filters combine with AND, match exact case-sensitive ids, and search only public arguments, results, and gateway facts. Times must be ISO 8601 date-times with `Z` or a UTC offset. The two date fields on the review page are date and time inputs; the page reads their values as UTC and the labels say so, and the route also reads a value without an offset (for example `2026-10-01T00:00`) as UTC. The page and the offline case file share one header: the logo, the theme toggle with the portal's saved choice, and the token palette. An identifier withheld by a capture rule cannot be searched. A record that lacks a part the pages read (it fails the verifier's structural check) is shown as NOT VERIFIED with the reason, and it does not stop an export. A ledger or file error is not a defect of the record: it fails the export, and the live page answers 500. Search stops at 64 levels of nesting and ignores JSON text longer than 64 KiB, so one hostile argument cannot stall the index. A receipt with a value that search skipped is marked "partially indexed", and an id filter keeps it in the list, because the id may be in the skipped value. The index never drops a record: a file whose receipt id differs from its name is listed as NOT VERIFIED ("file name does not match receipt id"), and the header counts the files that could not be read. `--out <dir>` writes an index, receipt pages and bundles, and each receipt's `.case.html` and `.case.json`; its browser search covers only the receipts included in that export. Add `--approval-key` (once for each human approver) when the receipts are for calls that a human approved: without those keys such a receipt is NOT VERIFIED. Add `--log-key`, `--log-id`, and `--upstream-key` when those signatures need independent keys.
162
162
 
163
163
  A portable HTML case contains the signed receipts, embedded signed authorizations, inclusion proofs, signed log heads, public keys (issuer, principal, approval, log, and upstream) and their fingerprints, the ten answers, and any ledger snapshot. Open it locally: its embedded WebCrypto verifier runs fresh checks on the signed evidence without external requests. That result is not independent, because the script is in the same file as the data: whoever edits the file can edit the script too, and the page does not compare the ten answers with the receipts. `review --verify-case` is the independent check. It takes the format from the file name: a name that ends in `.json` is read as JSON, and every other name as a page. Content that does not match the name fails. It reads the file, rebuilds the ten answers from the signed receipt and prints them (a saved answer that differs fails the check "ten answers match the signed receipt and the unsigned ledger snapshot"), and exits 1 on failed verification. For a `.case.html` it also fails unless the page is exactly what its data renders, so a changed visible answer or a second copy of the data fails. Trust the answers that the command prints, not the page. The check covers the answers that come from the signed receipt. The belief, dependency, and reversal lines come from the ledger snapshot in the file, which nobody signs, so a forged snapshot with matching answers passes: those lines are not attested. Without key flags it uses the bundled keys; supplied public keys replace the entire bundled trust set. Confirm bundled fingerprints through a trusted source. The explanation and ledger snapshot are unsigned exporter assertions; verification establishes the recorded gateway decision and detects receipt tampering, not that an external payment occurred. Without a ledger, belief dependencies remain `unknown without a ledger`. Capture keys, private keys, salts, and restored withheld values are never added to a case file.
164
164
 
@@ -343,6 +343,6 @@ tsconfig.build.json emits dist/ for consumers; the repo itself runs the .ts dir
343
343
  - Quarantine: facts carry `attested` or `claimed` provenance; claimed facts are hidden from reads by default and a gateway-only `memory.confirm` lifts them, as a recorded event.
344
344
 
345
345
  **Next, in the order it pays off**
346
-
346
+ <!-- #region state-next -->
347
347
  1. The hosted plane, behind early access: tenanted log, then memory, then reports and a control plane, with SSO, SCIM, residency, and SIEM export. [Issue #6](https://github.com/svayatta/agent-custody/issues/6).
348
-
348
+ <!-- #endregion state-next -->
package/dist/case-file.js CHANGED
@@ -4,7 +4,7 @@ import { readFileSync } from "node:fs";
4
4
  import * as nodeModule from "node:module";
5
5
  import { join } from "node:path";
6
6
  import { fileURLToPath } from "node:url";
7
- import { keyidOf, publicKeyFromPem, publicKeyToPem, verifyBundle } from "@agent-custody/receipts";
7
+ import { APP_HEADER_CSS, appHeader, DESIGN_CSS, THEME_SCRIPT, keyidOf, publicKeyFromPem, publicKeyToPem, verifyBundle } from "@agent-custody/receipts";
8
8
  import { buildActionPack, formatExplain } from "./explain.js";
9
9
  // Keep this pure and self-contained: the same validation function runs inside the offline page.
10
10
  function caseProblem(file) {
@@ -203,10 +203,10 @@ export function renderCaseFile(file) {
203
203
  const data = JSON.stringify(file).replace(/</g, "\\u003c").replace(/\u2028/g, "\\u2028").replace(/\u2029/g, "\\u2029");
204
204
  // HTML normalizes CRLF before CSP hashing in the browser, including files exported on Windows.
205
205
  const script = `"use strict";\n${browserVerifierSource()}\nconst caseProblem = ${caseProblem.toString()};\n${BROWSER_CASE_SCRIPT}`.replace(/\r\n?/g, "\n");
206
- const hash = createHash("sha256").update(script).digest("base64");
206
+ const hash = [script, THEME_SCRIPT].map((s) => `'sha256-${createHash("sha256").update(s).digest("base64")}'`).join(" ");
207
207
  const text = (value) => escapeHtml(typeof value === "string" ? value : JSON.stringify(value, null, 2));
208
208
  const keyText = problem ? "Malformed public key set" : Object.entries(file.keys).filter(([role]) => role !== "logId").map(([role, keys]) => `${role}:\n${keys.map((key) => `SHA-256 ${key.keyid}\n${key.pem}`).join("\n") || "(none)"}`).join("\n\n");
209
- return `<!doctype html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><meta http-equiv="Content-Security-Policy" content="default-src 'none'; script-src 'sha256-${hash}'; style-src 'unsafe-inline'; base-uri 'none'; form-action 'none'"><title>Custody case ${text(file?.receiptId ?? "invalid")}</title><style>body{font:16px/1.6 system-ui,sans-serif;max-width:1040px;margin:2rem auto;padding:0 1rem;color:#202020;background:#faf9f6}h1,h2{line-height:1.2}pre{white-space:pre-wrap;overflow-wrap:anywhere;background:#fff;border:1px solid #ccc;border-radius:6px;padding:1rem}button{font:inherit;padding:.5rem 1rem;cursor:pointer}summary{cursor:pointer}#fresh-report{border-left:4px solid #a66c00}small{color:#555}</style></head><body><h1>Custody case file</h1><p>Receipt <code>${text(file?.receiptId ?? "invalid")}</code>. Saved ${text(file?.generatedAt ?? "unknown")}.</p><p>This file contains signed receipts, embedded signed authorizations, log heads and inclusion proofs, and public keys. It works offline when opened locally.</p><p><strong>Trust:</strong> bundled keys demonstrate internal consistency. Confirm each SHA-256 fingerprint with the issuer, principal, log operator, or upstream through an independent channel before trusting their identity. A signed receipt records a claim about execution; it does not by itself prove that an external side effect occurred.</p><p>Withheld values remain commitments; their hidden contents are not recomputed here. The ten answers and belief/ledger data are an exporter snapshot, not independently attested facts. The exporter report below is historical; the browser recomputes signatures, authorizations, digests and inclusion proofs.</p><h2>Fresh browser verification</h2><p><strong>This page does not check itself independently.</strong> Its result comes from the script in this same file, and whoever edits the file can edit the script and the answers too. This page does not compare the ten answers with the receipts. To check this file, run <code>agent-custody-memory review --verify-case &lt;this file&gt; --issuer-key &lt;issuer.pub&gt; --principal-key &lt;principal.pub&gt;</code>. The command reads this .html file and checks that the page is exactly what its data renders. It prints the ten answers that it rebuilds from the signed receipt. Trust the answers that the command prints, not the answers on this page.</p><button id="verify" type="button">Verify again offline</button><pre id="fresh-report" role="status" aria-live="polite">NOT CHECKED: waiting for WebCrypto verification. If this stays unchanged, this browser could not run the verifier.</pre><noscript><p>NOT CHECKED: JavaScript is disabled. Use the independent command-line verifier: <code>agent-custody-memory review --verify-case &lt;this file&gt; --issuer-key &lt;issuer.pub&gt; --principal-key &lt;principal.pub&gt;</code>.</p></noscript><h2>Ten answers (saved text, NOT CHECKED in this page)</h2><pre>${text(problem ?? file.explanation)}</pre><h2>Export-time verification (recomputed when rendering)</h2><pre>${text(report)}</pre><h2>Public keys and fingerprints</h2><pre>${text(keyText)}</pre><details><summary>All receipts, authorizations, proofs and ledger snapshot (JSON)</summary><pre>${text(file)}</pre></details><script id="case-data" type="application/json">${data}</script><script>${script}</script></body></html>`;
209
+ return `<!doctype html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><meta http-equiv="Content-Security-Policy" content="default-src 'none'; script-src ${hash}; style-src 'unsafe-inline'; base-uri 'none'; form-action 'none'"><title>Custody case ${text(file?.receiptId ?? "invalid")}</title><style>${DESIGN_CSS}${APP_HEADER_CSS}body{font-size:var(--text-md);line-height:1.6}main{max-width:1040px;margin:2rem auto;padding:0 1rem}h2{margin-top:var(--space-6)}pre{white-space:pre-wrap;overflow-wrap:anywhere;background:var(--panel);border:1px solid var(--line);border-radius:var(--radius-sm);padding:1rem;font-size:var(--text-sm)}summary{cursor:pointer}#fresh-report{border-left:4px solid var(--accent)}small{color:var(--ink2)}</style></head><body>${appHeader("Case file")}<main><h1>Custody case file</h1><p>Receipt <code>${text(file?.receiptId ?? "invalid")}</code>. Saved ${text(file?.generatedAt ?? "unknown")}.</p><p>This file contains signed receipts, embedded signed authorizations, log heads and inclusion proofs, and public keys. It works offline when opened locally.</p><p><strong>Trust:</strong> bundled keys demonstrate internal consistency. Confirm each SHA-256 fingerprint with the issuer, principal, log operator, or upstream through an independent channel before trusting their identity. A signed receipt records a claim about execution; it does not by itself prove that an external side effect occurred.</p><p>Withheld values remain commitments; their hidden contents are not recomputed here. The ten answers and belief/ledger data are an exporter snapshot, not independently attested facts. The exporter report below is historical; the browser recomputes signatures, authorizations, digests and inclusion proofs.</p><h2>Fresh browser verification</h2><p><strong>This page does not check itself independently.</strong> Its result comes from the script in this same file, and whoever edits the file can edit the script and the answers too. This page does not compare the ten answers with the receipts. To check this file, run <code>agent-custody-memory review --verify-case &lt;this file&gt; --issuer-key &lt;issuer.pub&gt; --principal-key &lt;principal.pub&gt;</code>. The command reads this .html file and checks that the page is exactly what its data renders. It prints the ten answers that it rebuilds from the signed receipt. Trust the answers that the command prints, not the answers on this page.</p><button id="verify" type="button">Verify again offline</button><pre id="fresh-report" role="status" aria-live="polite">NOT CHECKED: waiting for WebCrypto verification. If this stays unchanged, this browser could not run the verifier.</pre><noscript><p>NOT CHECKED: JavaScript is disabled. Use the independent command-line verifier: <code>agent-custody-memory review --verify-case &lt;this file&gt; --issuer-key &lt;issuer.pub&gt; --principal-key &lt;principal.pub&gt;</code>.</p></noscript><h2>Ten answers (saved text, NOT CHECKED in this page)</h2><pre>${text(problem ?? file.explanation)}</pre><h2>Export-time verification (recomputed when rendering)</h2><pre>${text(report)}</pre><h2>Public keys and fingerprints</h2><pre>${text(keyText)}</pre><details><summary>All receipts, authorizations, proofs and ledger snapshot (JSON)</summary><pre>${text(file)}</pre></details></main><script id="case-data" type="application/json">${data}</script><script>${script}</script><script>${THEME_SCRIPT}</script></body></html>`;
210
210
  }
211
211
  const BROWSER_CASE_SCRIPT = `
212
212
  const caseFile = JSON.parse(document.getElementById("case-data").textContent);
package/dist/review.js CHANGED
@@ -7,7 +7,7 @@ import { readdirSync, readFileSync, mkdirSync, writeFileSync } from "node:fs";
7
7
  import { createServer } from "node:http";
8
8
  import { join } from "node:path";
9
9
  import { createHash } from "node:crypto";
10
- import { structuralProblem, verifyBundle } from "@agent-custody/receipts";
10
+ import { APP_HEADER_CSS, appHeader, DESIGN_CSS, THEME_SCRIPT, structuralProblem, verifyBundle } from "@agent-custody/receipts";
11
11
  import { buildActionPack, decodeStatement, formatExplain } from "./explain.js";
12
12
  import { matchesReceiptSearch, receiptSearchTerms, validateReceiptSearch } from "./search.js";
13
13
  import { buildCaseFile, renderCaseFile } from "./case-file.js";
@@ -46,28 +46,23 @@ export function scanReceipts(o, query = o.search ?? {}) {
46
46
  return { rows: rows.sort((a, b) => b.timestamp.localeCompare(a.timestamp)), unreadable };
47
47
  }
48
48
  export const listReceipts = (o, query = o.search ?? {}) => scanReceipts(o, query).rows;
49
- const STYLE = `
50
- :root { color-scheme: light dark; --ink: #1b2430; --ink2: #5b6b7a; --line: #d7dfe5; --bg: #fafbfc; --panel: #ffffff; --accent: #0f6e63; --bad: #b3261e; --mono: ui-monospace, Menlo, monospace; }
51
- @media (prefers-color-scheme: dark) { :root { --ink: #e6ecf0; --ink2: #9fb0bd; --line: #27333c; --bg: #0e1418; --panel: #151d23; --accent: #4fc3b0; --bad: #ff8a80; } }
52
- body { margin: 0; background: var(--bg); color: var(--ink); font: 15px/1.5 system-ui, sans-serif; }
49
+ const STYLE = `${DESIGN_CSS}${APP_HEADER_CSS}
53
50
  main { max-width: 74rem; margin: 0 auto; padding: 2rem 1.25rem 4rem; }
54
- h1 { font-size: 1.4rem; margin: 0 0 .25rem; } h2 { font-size: 1.05rem; margin: 1.75rem 0 .6rem; }
51
+ h1 { margin: 0 0 .25rem; } h2 { margin: 1.75rem 0 .6rem; }
55
52
  .sub { color: var(--ink2); margin: 0 0 1.25rem; }
56
- a { color: var(--accent); }
57
53
  table { border-collapse: collapse; width: 100%; font-size: .93rem; }
58
54
  th, td { text-align: left; padding: .5rem .6rem; border-bottom: 1px solid var(--line); vertical-align: top; white-space: nowrap; }
59
- th { font-size: .78rem; letter-spacing: .04em; text-transform: uppercase; color: var(--ink2); }
60
- code, pre, .mono { font-family: var(--mono); font-size: .88em; }
61
- pre { background: var(--panel); border: 1px solid var(--line); border-radius: 4px; padding: .9rem 1rem; overflow-x: auto; white-space: pre-wrap; }
55
+ th { font-size: var(--text-xs); font-weight: 600; color: var(--ink2); } th::first-letter { text-transform: uppercase; }
56
+ code, pre, .mono { font-size: .88em; }
57
+ pre { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: .9rem 1rem; overflow-x: auto; white-space: pre-wrap; }
62
58
  dl { display: grid; grid-template-columns: max-content 1fr; gap: .45rem 1.25rem; margin: 0; }
63
- dt { font-size: .78rem; letter-spacing: .04em; text-transform: uppercase; color: var(--ink2); padding-top: .15rem; }
59
+ dt { font-size: var(--text-xs); font-weight: 600; color: var(--ink2); padding-top: .15rem; } dt::first-letter { text-transform: uppercase; }
64
60
  dd { margin: 0; white-space: pre-wrap; }
65
- .ok { color: var(--accent); font-weight: 600; } .bad { color: var(--bad); font-weight: 600; } .muted { color: var(--ink2); }
61
+ .ok { color: var(--ok); font-weight: 600; } .bad { color: var(--bad); font-weight: 600; } .muted { color: var(--ink2); }
66
62
  .wrap { overflow-x: auto; }
67
- form { display: flex; flex-wrap: wrap; gap: .8rem; padding: 1rem; border: 1px solid var(--line); margin-bottom: 1rem; }
68
- label { display: grid; gap: .25rem; font-size: .85rem; }
69
- input, button { font: inherit; padding: .45rem; color: var(--ink); background: var(--panel); border: 1px solid var(--line); border-radius: 3px; }
70
- button { cursor: pointer; align-self: end; }
63
+ form { display: flex; flex-wrap: wrap; gap: .8rem; padding: 1rem; border: 1px solid var(--line); border-radius: var(--radius-md); background: var(--panel); margin-bottom: 1rem; }
64
+ label { display: grid; gap: .25rem; font-size: var(--text-xs); font-weight: 600; color: var(--ink2); }
65
+ form button { align-self: end; }
71
66
  [hidden] { display: none !important; }
72
67
  @media (max-width: 40rem) { dl { grid-template-columns: 1fr; } }
73
68
  `;
@@ -78,7 +73,8 @@ const form = document.getElementById('receipt-search');
78
73
  form.addEventListener('submit', (event) => {
79
74
  event.preventDefault();
80
75
  const value = (name) => form.elements.namedItem(name).value.trim();
81
- const from = value('from'), to = value('to');
76
+ const utc = (v) => v ? (v.length === 16 ? v + ':00' : v) + 'Z' : '';
77
+ const from = utc(value('from')), to = utc(value('to'));
82
78
  const error = document.getElementById('search-error');
83
79
  try {
84
80
  validateReceiptSearch({ ...(from ? { from } : {}), ...(to ? { to } : {}) });
@@ -106,15 +102,21 @@ form.addEventListener('reset', () => {
106
102
  queueMicrotask(() => form.requestSubmit());
107
103
  });
108
104
  `.replace(/\r\n?/g, "\n");
109
- const REVIEW_CSP = `default-src 'none'; style-src 'unsafe-inline'; script-src 'sha256-${createHash("sha256").update(SEARCH_SCRIPT).digest("base64")}'; img-src data:; form-action 'self'; base-uri 'none'`;
105
+ const REVIEW_CSP = `default-src 'none'; style-src 'unsafe-inline'; script-src ${[SEARCH_SCRIPT, THEME_SCRIPT].map((s) => `'sha256-${createHash("sha256").update(s).digest("base64")}'`).join(" ")}; img-src data:; form-action 'self'; base-uri 'none'`;
110
106
  const page = (title, body, script = "") => `<!doctype html>
107
+ <html lang="en">
111
108
  <meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1">
112
109
  <meta http-equiv="content-security-policy" content="${esc(REVIEW_CSP)}">
113
110
  <title>${esc(title)}</title>
114
111
  <style>${STYLE}</style>
112
+ ${appHeader("Review")}
115
113
  <main>${body}</main>
116
114
  ${script ? `<script>${script}</script>` : ""}
115
+ <script>${THEME_SCRIPT}</script>
117
116
  `;
117
+ // The date inputs hold a local-looking value without an offset. The review reads that value as UTC.
118
+ const asUtc = (v) => (/^\d{4}-\d\d-\d\dT\d\d:\d\d(:\d\d)?$/.test(v) ? `${v.length === 16 ? `${v}:00` : v}Z` : v);
119
+ const inputValue = (v) => (v && Number.isFinite(Date.parse(v)) ? new Date(Date.parse(v)).toISOString().slice(0, 19) : "");
118
120
  /** The index: one row per receipt, newest first. */
119
121
  export function renderIndex(rows, o, link, staticPage = false, unreadable = 0) {
120
122
  const withKeys = !!o.keys;
@@ -125,8 +127,9 @@ export function renderIndex(rows, o, link, staticPage = false, unreadable = 0) {
125
127
  <h1>${esc(o.title ?? "Receipts")}</h1>
126
128
  <p class="sub"><span id="receipt-count">${rows.length} receipt(s)</span> in ${esc(o.receiptsDir)}${withKeys ? ", each checked against the keys given" : ", not checked: start the review with the gateway's and principal's public keys to verify"}${o.ledger ? "; beliefs from the ledger" : "; no ledger, so what depended on a call is not known here"}.</p>
127
129
  ${unreadable ? `<p class="bad" role="alert">${unreadable} file(s) could not be read and are not in this list.</p>\n` : ""}<form id="receipt-search" method="get">
128
- ${[['transaction', 'Transaction ID', 're_… / pi_… / charge ID'], ['customer', 'Customer ID', 'cust_…'], ['agent', 'Agent', 'support-agent'], ['from', 'From (inclusive)', '2026-10-14T00:00:00Z'], ['to', 'To (inclusive)', '2026-10-15T00:00:00Z']].map(([name, label, placeholder]) => `<label>${label}<input name="${name}" value="${esc(o.search?.[name] ?? "")}" placeholder="${placeholder}"${name === 'from' || name === 'to' ? ' pattern="[0-9]{4}-[0-9]{2}-[0-9]{2}T.+(Z|[+-][0-9]{2}:[0-9]{2})"' : ''}></label>`).join("\n")}
129
- <button type="submit">Search receipts</button>${staticPage ? '<button type="reset">Clear filters</button>' : '<a href="/?transaction=&amp;customer=&amp;agent=&amp;from=&amp;to=">Clear filters</a>'}
130
+ ${[['transaction', 'Transaction ID', 're_… / pi_… / charge ID'], ['customer', 'Customer ID', 'cust_…'], ['agent', 'Agent', 'support-agent']].map(([name, label, placeholder]) => `<label>${label}<input name="${name}" value="${esc(o.search?.[name] ?? "")}" placeholder="${placeholder}"></label>`).join("\n")}
131
+ ${[['from', 'From (UTC, inclusive)'], ['to', 'To (UTC, inclusive)']].map(([name, label]) => `<label>${label}<input type="datetime-local" step="1" name="${name}" value="${esc(inputValue(o.search?.[name]))}"></label>`).join("\n")}
132
+ <button type="submit">Search receipts</button>${staticPage ? '<button class="quiet" type="reset">Clear filters</button>' : '<a href="/?transaction=&amp;customer=&amp;agent=&amp;from=&amp;to=">Clear filters</a>'}
130
133
  </form>
131
134
  <p class="muted">Filters combine and match exact IDs. Search covers public arguments, results and gateway facts; identifiers withheld by a capture rule are unavailable.${staticPage ? ' This export searches only the receipts included here.' : ''}</p>
132
135
  <p id="search-error" role="alert" class="bad"></p>
@@ -211,7 +214,7 @@ export function reviewHandler(o) {
211
214
  for (const name of ['transaction', 'customer', 'agent', 'from', 'to']) {
212
215
  if (!url.searchParams.has(name))
213
216
  continue;
214
- const value = url.searchParams.get(name).trim();
217
+ const value = asUtc(url.searchParams.get(name).trim());
215
218
  if (value)
216
219
  search[name] = value;
217
220
  else
@@ -300,9 +300,12 @@ const ISSUER_NOTE = {
300
300
  gateway: "enforced outside the agent's process; the agent could neither skip nor forge this receipt",
301
301
  sdk: "self-reported by the agent's own process; tamper-evident after issue, but nothing here was enforced outside the agent",
302
302
  door: "enforced in front of the business's own HTTP surface; the arriving party could not forge this receipt and is attested only when it presented a grant, and a request that reached the origin some other way leaves no receipt",
303
+ "door/authz": "decided by the door for a proxy in front of the business's own HTTP surface (nginx auth_request or Envoy ext_authz): the receipt records the decision, not the result, since the proxy relayed an allowed request and the door saw neither its body nor the origin's answer; the arriving party could not forge this receipt and is attested only when it presented a grant",
303
304
  guardian: "decided by an ACS Guardian outside the agent's process and signed with its own key, so the decision is attributable to it; the call is the agent's own report, and the agent could skip the Guardian or ignore its answer",
304
305
  egress: "observed by a forward proxy in the agent's network path, for a connection that went around the gateway: where it went and how much, never what was sent; the agent is known only by the proxy credential the witness checked, and a connection that skipped the proxy (no lockdown) leaves no receipt at all",
305
306
  };
307
+ /** What kind of evidence the issuer gives; a door answering a proxy's authz check gives a decision only. */
308
+ const issuerNote = (issuer) => (issuer.kind === "door" && issuer.framework === "authz" ? ISSUER_NOTE["door/authz"] : ISSUER_NOTE[issuer.kind] ?? "unknown issuer kind");
306
309
  const short = (s) => s.slice(0, 12);
307
310
  async function hmacHex(secret, data) {
308
311
  const key = await subtle().importKey("raw", enc.encode(secret), { name: "HMAC", hash: "SHA-256" }, false, ["sign"]);
@@ -544,7 +547,7 @@ export async function verifyBundle(bundle, opts) {
544
547
  const checks = [];
545
548
  const add = (name, ok, detail) => { checks.push(detail === undefined ? { name, ok } : { name, ok, detail }); return ok; };
546
549
  let treeHeadSigner = null;
547
- const done = (statement) => ({ ok: checks.every((c) => c.ok), checks, statement, issuerNote: statement ? (ISSUER_NOTE[statement.predicate.issuer.kind] ?? "unknown issuer kind") : null, treeHeadSigner });
550
+ const done = (statement) => ({ ok: checks.every((c) => c.ok), checks, statement, issuerNote: statement ? issuerNote(statement.predicate.issuer) : null, treeHeadSigner });
548
551
  const sig = await dsseVerify(bundle.envelope, opts.issuerKeys);
549
552
  if (!sig.ok) {
550
553
  add("receipt signature (issuer key)", false, sig.error);
@@ -583,6 +586,11 @@ export async function verifyBundle(bundle, opts) {
583
586
  }
584
587
  if (p.issuer.kind === "door")
585
588
  add("door receipt carries a policy decision", p.policy !== null);
589
+ // In authz mode the door answers a proxy's check and relays nothing: the receipt is a decision, never a result.
590
+ if (p.issuer.kind === "door" && p.issuer.framework === "authz") {
591
+ const decided = p.execution.status === "withheld" || (p.execution.status === "denied" && p.policy?.decision === "deny");
592
+ add("door authz decided, relayed nothing", decided, decided ? `${p.policy?.decision}; a decision for the proxy, which relays: the door saw neither the body nor the origin's answer` : `the receipt says ${p.execution.status} with a policy ${p.policy?.decision ?? "absent"}`);
593
+ }
586
594
  // An egress witness saw a connection that went around the gateway: where it went and how much, never what was sent.
587
595
  // Its destination is its own observation; its agent is only as good as the proxy credential it checked.
588
596
  if (p.issuer.kind === "egress") {
@@ -744,6 +752,42 @@ export async function verifyBundle(bundle, opts) {
744
752
  const isProvider = (v) => !!v && (v.provider === "stripe-webhook" || v.provider === "github-delivery") && stringOrCommitment(v.rawBody) && stringOrCommitment(v.signature) && stringOrCommitment(v.bind);
745
753
  // a check is skipped only for a part the signed note declares withheld; a part that is simply not there, or commitment-shaped without the note saying so, fails
746
754
  const declared = (path) => (note?.withheld ?? []).some((w) => JSON.stringify(w) === JSON.stringify(path));
755
+ // a fact its source signed (the door's partner verdict), marked attested by the issuer: checked again under the key the reader trusts for that source
756
+ for (const [name, f] of Object.entries(p.facts)) {
757
+ if (f?.provenance !== "attested")
758
+ continue;
759
+ const label = `fact ${name} signature (upstream key)`;
760
+ const env = f.attestation;
761
+ const wellFormed = !!env && typeof env === "object" && typeof env.payload === "string" && Array.isArray(env.signatures);
762
+ if ((note?.withheld ?? []).some((w) => w.length >= 3 && w[0] === "facts" && w[1] === name && w[2] === "value"))
763
+ add(`fact ${name} signature not checked`, true, "the value is withheld; disclose it with the command-line verifier to check its signature");
764
+ else if (declared(["facts", name, "attestation"]))
765
+ add(label, false, "the value is in clear but its signature is withheld; disclose it or give the capture key to check it");
766
+ else if (!wellFormed)
767
+ add(label, false, "the fact is marked attested and carries no signature, and the capture note does not say it is withheld");
768
+ else if (!opts.upstreamKeys?.length)
769
+ add(label, false, "the fact is marked attested; give the signer's public key to check it");
770
+ else {
771
+ const u = await dsseVerify(env, opts.upstreamKeys);
772
+ let ok = u.ok && env.payloadType === UPSTREAM_TYPE;
773
+ let detail = u.ok ? (ok ? `keyid ${short(u.keyid)}` : `payload type ${env.payloadType}`) : u.error;
774
+ if (ok && u.ok) {
775
+ if (u.payload.receiptId !== p.receiptId) {
776
+ ok = false;
777
+ detail = "signed for a different receipt";
778
+ }
779
+ else if (u.payload.tool !== p.tool.name) {
780
+ ok = false;
781
+ detail = `signed for tool ${u.payload.tool}`;
782
+ }
783
+ else if (u.payload.contentDigest !== await digestOf(f.value)) {
784
+ ok = false;
785
+ detail = "signed content differs from the result in the receipt";
786
+ }
787
+ }
788
+ add(label, ok, detail);
789
+ }
790
+ }
747
791
  if (executedOrFailed && p.execution.upstream && isProvider(p.execution.upstream)) {
748
792
  if (opts.providerSecrets) {
749
793
  const parts = ["rawBody", "signature", "bind"];
@@ -976,8 +1020,14 @@ export function formatReport(r) {
976
1020
  row("model", p.model.provenance, p.model.id === null ? "(none supplied)" : idText(p.model.id));
977
1021
  row("tool", p.tool.provenance, p.tool.name);
978
1022
  row("args", p.request.provenance, p.request.args);
979
- for (const [k, f] of Object.entries(p.facts))
980
- row(`fact.${k}`, f.provenance, f.value);
1023
+ for (const [k, f] of Object.entries(p.facts)) {
1024
+ if (f.provenance !== "attested") {
1025
+ row(`fact.${k}`, f.provenance, f.value);
1026
+ continue;
1027
+ }
1028
+ const signed = r.checks.find((c) => c.name === `fact ${k} signature (upstream key)`);
1029
+ row(`fact.${k}`, f.provenance, `${JSON.stringify(f.value)}${signed ? (signed.ok ? ` (signed by ${signed.detail})` : " (signature FAILED)") : " (signature not checked)"}`);
1030
+ }
981
1031
  if (p.reconciliation)
982
1032
  row("policy", "-", "(none evaluated: a provider read, not a call)");
983
1033
  else if (p.policy)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agent-custody/state",
3
- "version": "0.16.5",
3
+ "version": "0.16.7",
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": {
@@ -34,7 +34,7 @@
34
34
  "node": ">=22"
35
35
  },
36
36
  "dependencies": {
37
- "@agent-custody/receipts": "0.16.5",
37
+ "@agent-custody/receipts": "0.16.7",
38
38
  "@modelcontextprotocol/sdk": "1.30.0",
39
39
  "zod": "4.5.4"
40
40
  },