@agent-custody/receipts 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.
Files changed (65) hide show
  1. package/README.md +29 -13
  2. package/dist/capture.d.ts +2 -0
  3. package/dist/capture.js +13 -2
  4. package/dist/check.d.ts +1 -1
  5. package/dist/check.js +34 -10
  6. package/dist/cli.js +54 -9
  7. package/dist/config.d.ts +27 -2
  8. package/dist/config.js +66 -2
  9. package/dist/console-page.js +144 -50
  10. package/dist/deny-report.d.ts +7 -0
  11. package/dist/deny-report.js +8 -3
  12. package/dist/design.d.ts +11 -0
  13. package/dist/design.js +91 -0
  14. package/dist/door-app.d.ts +28 -0
  15. package/dist/door-app.js +244 -0
  16. package/dist/door-partner.d.ts +66 -0
  17. package/dist/door-partner.js +94 -0
  18. package/dist/door.d.ts +139 -10
  19. package/dist/door.js +297 -137
  20. package/dist/gateway-http.d.ts +1 -1
  21. package/dist/index.d.ts +8 -2
  22. package/dist/index.js +5 -1
  23. package/dist/log-admin.js +100 -59
  24. package/dist/log-store.d.ts +8 -2
  25. package/dist/log-store.js +22 -12
  26. package/dist/perathos.d.ts +50 -0
  27. package/dist/perathos.js +188 -0
  28. package/dist/portal.d.ts +66 -5
  29. package/dist/portal.js +895 -242
  30. package/dist/receipt.d.ts +4 -1
  31. package/dist/session-audit.d.ts +46 -0
  32. package/dist/session-audit.js +150 -0
  33. package/dist/site-links.d.ts +23 -0
  34. package/dist/site-links.js +29 -0
  35. package/dist/verify.js +44 -4
  36. package/dist/web-bot-auth.d.ts +105 -0
  37. package/dist/web-bot-auth.js +508 -0
  38. package/docs/acs.md +2 -0
  39. package/docs/approvals.md +1 -1
  40. package/docs/completeness.md +1 -1
  41. package/docs/configuration.md +2 -0
  42. package/docs/console.md +11 -2
  43. package/docs/door-languages.md +168 -0
  44. package/docs/door-middleware.md +216 -0
  45. package/docs/door-quickstart.md +1 -1
  46. package/docs/door-signals.md +43 -6
  47. package/docs/door.md +129 -32
  48. package/docs/egress.md +3 -1
  49. package/docs/github-action.md +2 -2
  50. package/docs/mandates.md +1 -1
  51. package/docs/perathos.md +100 -0
  52. package/docs/sdk.md +32 -1
  53. package/docs/threat-model.md +2 -1
  54. package/docs/tutorials.md +6 -0
  55. package/docs/usage.md +3 -1
  56. package/docs/verification.md +3 -1
  57. package/package.json +7 -1
  58. package/vectors/audit.json +27 -27
  59. package/vectors/canonical.json +5 -5
  60. package/vectors/interop/perathos/LICENSE +21 -0
  61. package/vectors/interop/perathos/README.md +17 -0
  62. package/vectors/interop/perathos/pocketos-replay/session.head.json +11 -0
  63. package/vectors/interop/perathos/pocketos-replay/session.jsonl +8 -0
  64. package/vectors/interop/perathos/pocketos-replay/verification.json +65 -0
  65. package/vectors/receipts.json +1701 -1210
package/README.md CHANGED
@@ -7,7 +7,7 @@ Chain of custody for AI agents: a signed receipt for every tool call, checkable
7
7
  Five producers, one receipt format, one verifier.
8
8
 
9
9
  - **The gateway** is an MCP proxy between an agent and the systems it can affect: MCP servers, REST APIs described as tools, and other agents it delegates to over A2A. For every tool call, allowed or denied, it checks a delegation grant signed by the human principal and any required human approval of the exact arguments, gathers the facts the policy needs by calling upstream itself, evaluates a Cedar or Rego policy that fails closed (Rego from a file or from your own OPA server), forwards the call only on allow, and emits a signed receipt appended to a Merkle transparency log.
10
- - **The door** is the gateway turned around: a reverse proxy in front of your own website, API, or forms. Every arrival, a browser, an API client, a crawler, or an agent, is classified by what it presented (a grant signed by a principal you trust makes it `verified`; an assertion the door cannot check is `claimed`; nothing is `unknown`), decided by a Cedar policy for its route, relayed or refused, and receipted either way with the same receipt. It is the first piece of an agent front door; it does not yet detect agents in web traffic, and says so ([the door](docs/door.md)).
10
+ - **The door** is the gateway turned around: a reverse proxy in front of your own website, API, or forms. Every arrival, a browser, an API client, a crawler, or an agent, is classified by what it presented (a grant signed by a principal you trust, or a Web Bot Auth signature checked against the signer's key directory, makes it `verified`; an assertion the door cannot check is `claimed`; nothing is `unknown`), decided by a Cedar policy for its route, relayed or refused, and receipted either way with the same receipt. A Node site can run the same loop in its own process: `app.use(door("door.json"))` in Express, or a wrapper around a Next.js route handler ([the door in your Node app](docs/door-middleware.md)). A site in Go, Rails, Django, or Spring asks a door in authz mode from a middleware ([the door in Go, Rails, Django, and Spring](docs/door-languages.md)). A partner detection engine (Cloudflare Bot Management, HUMAN, DataDome, behind an adapter that holds a key) can sign its verdict for each arrival, and the policy reads it and the receipt carries it, attested. It is the first piece of an agent front door; it does not yet detect agents in web traffic itself, and says so ([the door](docs/door.md)).
11
11
  - **The egress witness** covers the calls that go around the gateway. Under egress lockdown, a locked-down agent's network reaches only the gateway and the witness. The witness is a forward proxy: it identifies the agent by the proxy credential it checked, lets a Cedar or Rego policy decide per destination, relays or refuses the connection, and receipts it either way (issuer kind `egress`). It records the destination, the times, and the byte counts. It never records a payload, because there is no TLS interception. It sees nothing when lockdown is off, and it relays no protocol other than HTTP. A receipt is an observed bypass, not a record of what was done.
12
12
  - **The ACS Guardian**, a spike, answers an agent that asks before it acts over the OWASP Agent Control Standard: it decides `steps/toolCallRequest` and `steps/toolCallResult` by a Cedar policy and receipts each decision (issuer kind `guardian`). It carries out nothing, and the agent chooses to ask and to obey, so a receipt proves the decision, not that the call ran or did not ([the ACS Guardian](docs/acs.md)).
13
13
  - **The SDK** is an interceptor inside the agent's own process, hooked into the framework's tool-call callbacks: Claude Code, the Claude Agent SDK, the OpenAI Agents SDK, the Vercel AI SDK, OpenClaw, DeepSeek Harness, Hermes, Google ADK, LangChain, or any function you wrap. It reaches everything the gateway cannot see and issues the same receipts, labelled as self-reported.
@@ -17,11 +17,13 @@ Anyone holding the public keys can verify a receipt offline. The agent is not tr
17
17
  - [Reference](https://docs.agent-custody.dev/reference/): every function, endpoint, MCP tool, and command with its request and response
18
18
  - [Tutorials](docs/tutorials.md): runnable examples, one per aspect of the code, all executed by the test suite
19
19
  - [Put the door in front of a site](docs/door-quickstart.md): a fifteen-minute quick start for a site owner, from keys to verified receipts.
20
- - [The door](docs/door.md): a receipted reverse proxy in front of your own site or API; what it knows about an arrival, how an arrival becomes a Cedar request, what the arrival gets back, and what it does not do yet
20
+ - [The door](docs/door.md): a receipted reverse proxy in front of your own site or API; what it knows about an arrival, how an arrival becomes a Cedar request, what the arrival gets back, behind stock nginx or Envoy as their authz check (receipts of the decision, not the result), and what it does not do yet
21
21
  - [The egress witness](docs/egress.md): a receipted forward proxy for calls that go around the gateway; lockdown, how the witness knows the agent, the Cedar request (or Rego input) per destination, the receipt, and what it cannot see: payloads, traffic when lockdown is off, and non-HTTP protocols
22
22
  - [Writing egress policies](../../site/guide/egress-policies.md): per-agent allow lists, wildcard hosts and the `*.example.com` trap, ports, IP literals, why a provider that needs a credential stays in the gateway, `forbid`, and rolling out from observe mode with `egress draft-policy`; every example is tested
23
23
  - [The ACS Guardian](docs/acs.md): agent-custody as an OWASP Agent Control Standard Guardian for `steps/toolCallRequest` and `steps/toolCallResult`; each decision a receipt a third party can check, the ACS sections it relies on, and what it does not implement
24
- - [Door signals](docs/door-signals.md): every field of the arrival fact, labelled checked, observed, or a claim, with what it does and does not mean and how a policy should read it
24
+ - [The door in your Node app](docs/door-middleware.md): the same decision loop in-process, as Express middleware or a Next.js route-handler wrapper; quick starts for both, what the app receives, and what the receipt records of its answer and what it does not
25
+ - [The door in Go, Rails, Django, and Spring](docs/door-languages.md): standard-library middleware for `net/http`, Rack, Django and WSGI, and the JDK `HttpServer`, with a Spring filter snippet, each a client of the door's authz check that fails closed when the door does not answer
26
+ - [Door signals](docs/door-signals.md): every field of the arrival fact and of a partner engine's signed verdict, labelled checked, observed, or a claim, with what it does and does not mean and how a policy should read it
25
27
  - [Financial operations](docs/financial-operations.md): durable operation ids, provider idempotency keys, atomic daily budget reservations, and reconciliation receipts for uncertain outcomes
26
28
  - [The gateway console](docs/console.md): an admin service for the person who runs a gateway: config, tools, receipts with a verdict each, a policy editor that replays recorded calls before it saves, grant revocation, and an audit trail
27
29
  - [Configuring the gateway](docs/configuration.md): who may use which tools and where the tools live, a worked example with two agents, the Docker image, and `agent-custody check` to validate a config before it starts
@@ -39,6 +41,7 @@ Anyone holding the public keys can verify a receipt offline. The agent is not tr
39
41
  - [Threat model](docs/threat-model.md): every party who could make a receipt false, the move, what stops it, and whether that is a property of the evidence or of the deployment; and what is not defended
40
42
  - [What a receipt costs](docs/performance.md): each step of the issuer's hot path in microseconds, measured with `bun run bench`, what is and is not fsynced, and where the time goes
41
43
  - [Aligning with IETF SCITT](docs/scitt.md): the receipt as a SCITT signed statement, the log as a transparency service, our RFC 9162 proofs as COSE Receipts (RFC 9942), what differs and the options for each, an agent-action profile, and the steps toward the working group
44
+ - [Reading a Perathos log](docs/perathos.md): `verify-perathos` checks another project's agent records, a Perathos session log, against its spec; what a valid log proves and does not, and how its fields map onto an agent-custody receipt
42
45
 
43
46
  ## Getting started
44
47
 
@@ -69,7 +72,7 @@ const bundle = JSON.parse(readFileSync("receipts/<id>.json", "utf8"));
69
72
  verifyBundle(bundle, { issuerKeys: [loadPublicKey("keys/app.pub")], logFile: "log.jsonl" }).ok; // true
70
73
  ```
71
74
 
72
- For your own Claude Code sessions, one command does the whole setup (key, config in observe mode, starter deny policy, hooks), and `agent-custody report` lists the calls the policy would have denied: `npm install -g @agent-custody/receipts`, then `agent-custody init claude-code`, then see [docs/sdk.md](docs/sdk.md#claude-code).
75
+ To see first what it would have caught, `npx -y @agent-custody/receipts audit-sessions --since 7d` reads your past Claude Code transcripts against the starter policy and writes nothing ([docs/sdk.md](docs/sdk.md#before-you-install-your-past-sessions)). For your own Claude Code sessions, one command does the whole setup (key, config in observe mode, starter deny policy, hooks), and `agent-custody report` lists the calls the policy would have denied: `npm install -g @agent-custody/receipts`, then `agent-custody init claude-code`, then see [docs/sdk.md](docs/sdk.md#claude-code).
73
76
 
74
77
  Framework hooks and adapters, including Claude Code, the OpenAI Agents SDK, the Vercel AI SDK, LangChain, OpenClaw, DeepSeek Harness, Hermes and Google ADK, are in [docs/sdk.md](docs/sdk.md). To enforce rather than record, put the gateway between the agent and its tools: `npx @agent-custody/receipts gateway --config gateway.json`, set up in [docs/usage.md](docs/usage.md); between an agent and the agents it delegates to over A2A, `--a2a` serves the gateway as an A2A agent itself. The gateway is listed in the [MCP Registry](https://registry.modelcontextprotocol.io/) as `io.github.svayatta/agent-custody`; its entry is [server.json](server.json), published after each npm release by running the `mcp-registry` workflow from the Actions tab (GitHub OIDC, no token).
75
78
 
@@ -114,12 +117,12 @@ Three parties hold keys. The **principal** signs a grant saying which agent may
114
117
 
115
118
  | | gateway | door | egress witness | ACS Guardian | SDK |
116
119
  | --- | --- | --- | --- | --- | --- |
117
- | where it runs | separate process between agent and tools | separate process between the world and your own site or API | forward proxy in a locked-down agent's network path | separate process the agent asks, one JSON-RPC document at a time | inside the agent's process |
120
+ | where it runs | separate process between agent and tools | separate process between the world and your own site or API, or in-process in a Node site | forward proxy in a locked-down agent's network path | separate process the agent asks, one JSON-RPC document at a time | inside the agent's process |
118
121
  | what it sees | MCP tool calls | every HTTP arrival, by route | each connection that does not go to the gateway: destination, times, byte counts, never the payload | the tool-call requests and results the agent chooses to send | whatever the framework's hooks expose |
119
122
  | enforcement | yes, denied calls never reach upstream | yes, refused arrivals never reach the origin | yes, refused connections are never opened; only under lockdown, since an agent can ignore the proxy | no: it decides, and the agent honours the answer or not | only where a hook can block |
120
123
  | provenance of its fields | `attested` and `observed` | `observed`; `attested` only when the arrival presented a grant, else `claimed` | `observed`; the agent is `observed` only through a proxy credential the witness checked, else `claimed` | the decision and the policy `observed`; the agent, the tool, and the arguments `claimed` | `claimed`, all of them |
121
124
  | what a verifier learns | the agent could not skip or forge this | the arrival could not skip or forge this; who it was is proven only with a grant | the agent connected to this destination around the gateway; not what it sent | the Guardian made this decision on this request under this policy; not that the call ran | the agent's process reported this and it has not changed since |
122
- | install | one line in the host's MCP config | a reverse proxy in front of the origin | a forward proxy plus egress lockdown (`deploy/gateway/lockdown`) | `agent-custody acs --config acs.json`, or `createAcsGuardian` in code | a hook entry or a wrapped function |
125
+ | install | one line in the host's MCP config | a reverse proxy in front of the origin, or `app.use(door(...))` in Express and `guard.route(handler)` in Next.js | a forward proxy plus egress lockdown (`deploy/gateway/lockdown`) | `agent-custody acs --config acs.json`, or `createAcsGuardian` in code | a hook entry or a wrapped function |
123
126
 
124
127
  Every receipt names its issuer, and the verifier prints what that issuer kind is worth before anything else. A dashboard full of `sdk` rows is the reason to route the consequential calls through the gateway. The door is the gateway turned around ([the door](docs/door.md)). The egress witness receipts the connections that go around the gateway ([the egress witness](docs/egress.md)). The ACS Guardian receipts the decisions it gives an agent that asks ([the ACS Guardian](docs/acs.md)).
125
128
 
@@ -144,6 +147,9 @@ Every receipt names its issuer, and the verifier prints what that issuer kind is
144
147
  | any MCP host in any language: Claude Agent SDK Python, OpenAI Agents Python | gateway | yes | | the gateway is an MCP server; [usage.md](docs/usage.md#python-hosts) |
145
148
  | any REST API, as tools the agent reaches through the gateway | gateway, `rest` upstream | yes | | a stand-in HTTP API; [usage.md](docs/usage.md#setup-step-by-step) |
146
149
  | any agent reached over A2A (Google ADK `RemoteA2aAgent`, or any A2A client) | gateway, `a2a` upstream and `gateway --a2a` | yes | | stand-in A2A agents in both wire formats; ADK's own `to_a2a` and `RemoteA2aAgent` in the Python suite; [usage.md](docs/usage.md#the-gateway-as-an-a2a-agent) |
150
+ | a site any agent arrives at, built on Express or Connect | door, in-process | `app.use(door("door.json"))` | | Express 5.2.1 with `express.json()`, `express.urlencoded()`, and a raw stream read after the door; [guide](docs/door-middleware.md) |
151
+ | a site any agent arrives at, built on Go `net/http`, Rails (Rack), Django (or WSGI), or Spring | door, authz mode, asked by a middleware | `Door(url, timeout)(handler)`, `AgentCustody::Door`, `DoorMiddleware` / `DoorWSGI`, `CustodyDoor` with a filter | | each example against a live door: Go through `ServeHTTP`, Rack with a Rack env, WSGI under `wsgiref`, Django with a stand-in request and `HttpResponse`, the JDK `HttpServer` filter; the Spring filter is a doc snippet, not compiled; [guide](docs/door-languages.md) |
152
+ | a site any agent arrives at, built on Next.js (App Router) | door, in-process | `guard.route(handler)` on each route handler | | fetch `Request` and `Response` objects in the tests; by hand, a fresh `create-next-app` (Next.js 16.4.6) under `next dev` and `next start`; [guide](docs/door-middleware.md) |
147
153
 
148
154
  The framework packages, `pg`, and `@node-saml/node-saml` (for SAML sign-in to the portal) are optional peer dependencies. Each adapter imports only from its own package.
149
155
 
@@ -262,7 +268,8 @@ src/crypto.ts canonical JSON, sha256, Ed25519 keys, DSSE sign/verify
262
268
  src/log.ts Merkle log: append, root, inclusion and consistency proofs, verify, JSONL persistence; a lock file makes an append safe when several processes share one log file, and a partial last line from a killed writer is moved to `<file>.torn`
263
269
  src/lock.ts the one lock file design (owner token, liveness check, rename to break a stale lock) that the local log, prune, and the gateway outbox share
264
270
  src/log-check.ts the outside monitor: verifies the head, checkpoints, witness, and anchor of a running log
265
- src/portal.ts the tenant portal: register, first key, usage against plan, keys, Stripe billing, export, member roles, TOTP MFA, single sign-on, on the log's Postgres
271
+ src/design.ts the design tokens and shared components (button, select, card, dialog, headings) that the site, the portal, and the consoles share; the app pages inline DESIGN_CSS
272
+ src/portal.ts the tenant portal: register, first key, usage against plan, activity, keys with last use, Stripe billing, export, member roles, password reset and change, TOTP MFA with a QR code and recovery codes, single sign-on, on the log's Postgres
266
273
  src/sso.ts enterprise sign-in for the portal: OIDC (code and PKCE, id_token checked against the IdP's key set) and SAML 2.0 (signed assertions only, through @node-saml/node-saml)
267
274
  src/log-export.ts a tenant's export of their own log, self-checked, as a log file the verifier reads
268
275
  src/witness.ts the witness: countersigns the log's checkpoints from another operator's machine, or refuses with an alarm
@@ -286,7 +293,10 @@ src/issue.ts sign, log, and write a receipt, or commit an authorization fi
286
293
  src/gateway.ts the MCP proxy: a host (key, policy, upstreams, log) and a session per grant; scope check, facts, policy, forward, receipt
287
294
  src/operations.ts SQLite operation claims and daily budget reservations, retained across retries and process crashes
288
295
  src/gateway-http.ts the gateway over Streamable HTTP: one process, a session per connection, each under the grant it presents
289
- src/door.ts the door: a reverse proxy in front of your own HTTP surface; every arrival classified, decided per route, relayed or refused, receipted as issuer kind door
296
+ src/door.ts the door: a reverse proxy in front of your own HTTP surface, or the authz check behind nginx and Envoy; every arrival classified, decided per route, relayed or refused, receipted as issuer kind door; its decision loop is shared with door-app.ts
297
+ src/door-app.ts the door in-process (`@agent-custody/receipts/door`): Express or Connect middleware and a fetch route-handler wrapper (Next.js), over the same decision loop
298
+ src/web-bot-auth.ts the door's Web Bot Auth check: RFC 9421 signature base, RFC 8941 dictionaries, Ed25519, the signer's key directory fetched and cached, nonces
299
+ src/door-partner.ts the door's partner engine slot: asks a detection engine about an arrival, accepts only a verdict signed for that receipt and route (the upstream attestation format), and `signVerdict` for engines
290
300
  src/egress.ts the egress witness: a forward proxy (CONNECT and plain HTTP, no TLS interception) for calls around the gateway; agent by proxy credential, decided per destination, receipted as issuer kind egress
291
301
  src/egress-draft.ts `egress draft-policy`: a first egress policy from verified observe-mode receipts, one permit per agent and scheme over the destinations it used, for review
292
302
  src/acs.ts an OWASP ACS Guardian: steps/toolCallRequest and steps/toolCallResult over JSON-RPC, decided by Cedar, each decision receipted as issuer kind guardian
@@ -300,7 +310,7 @@ src/rest.ts the REST connector: an HTTP API described as tools, standing
300
310
  src/a2a.ts agents delegating to agents: a remote A2A agent as an upstream, and the gateway serving A2A itself in front of it
301
311
  src/upstream.ts attested execution: an upstream signs its result for the receipt; the verifier checks it with the upstream key
302
312
  src/capture.ts private evidence: per-tool capture rules applied by the issuer to the whole statement, withheld values as salted commitments or encrypted under the customer's key, restore and reveal
303
- vectors/ conformance vectors: receipts, keys, logs, proofs, and expected verdicts; `bun run vectors` regenerates them
313
+ vectors/ conformance vectors: receipts, keys, logs, proofs, and expected verdicts; `bun run vectors` regenerates them; `interop/` holds other projects' records, copied as they wrote them and never regenerated
304
314
  src/verify.ts offline verification, the human-readable report, and the audit that a later log extends an earlier one
305
315
  src/claude-init.ts `init claude-code`: the agent key, the observe-mode config, the starter policy, and the three hooks merged into the settings file with absolute paths
306
316
  src/deny-report.ts `report`: verifies the receipts of an SDK config and lists the calls the policy would have denied
@@ -309,8 +319,8 @@ src/cli.ts keygen, grant, gateway, door, egress, egress draft-policy, ac
309
319
  src/retention.ts pruning the log: leaves become their hashes, bundles are removed, proofs survive
310
320
  src/index.ts the package's public surface; adapters are exported on ./sdk/<framework> subpaths
311
321
  tsconfig.build.json emits dist/ (JavaScript plus declarations) for consumers; the repo itself runs the .ts directly
312
- scripts/ fake Stripe upstream (signs its results with --key), a second fake upstream, fixture builders for gateway, SDK, door (with a stand-in origin), and the egress witness (with a stand-in destination), the replay builder (`replay.ts`: example 27 and state example 07 as a folder of receipts and public keys anyone can verify with the published packages), demo, the site's numbers (`bench.ts`), and the per-step hot-path benchmark (`hot-path-bench.ts`, `bun run bench`)
313
- examples/ runnable tutorials, plus examples/languages/: Python, Go, Java, and Rust clients of the sidecar, run by the test suite, one per aspect; each is run by the test suite
322
+ scripts/ fake Stripe upstream (signs its results with --key), a second fake upstream, a fake partner detection engine for the door (`fake-partner.ts`, signs its verdicts), fixture builders for gateway, SDK, door (with a stand-in origin), and the egress witness (with a stand-in destination), the replay builder (`replay.ts`: example 27 and state example 07 as a folder of receipts and public keys anyone can verify with the published packages), demo, the site's numbers (`bench.ts`), and the per-step hot-path benchmark (`hot-path-bench.ts`, `bun run bench`)
323
+ examples/ runnable tutorials, plus examples/languages/: Python, Go, Java, and Rust clients of the sidecar, and in door/ the Go, Rack, Django and WSGI, and JDK middleware clients of the door's authz check, run by the test suite, one per aspect; each is run by the test suite
314
324
  test/ unit tests per module, end-to-end gateway test, SDK and hook tests,
315
325
  adapter tests against the real packages, and tests that run every policy in docs/policies.md and site/guide/egress-policies.md
316
326
  docs/ tutorials, usage (gateway), codex-recovery (live demo), approvals, sdk, policies, verification, performance
@@ -318,10 +328,14 @@ docs/ tutorials, usage (gateway), codex-recovery (live demo), appro
318
328
 
319
329
  ## Plan
320
330
 
321
- The design is several producers feeding one verifier. The SDK is the top of the funnel: cheap to install, wide reach, honest about being self-reported. The gateway is what a security or compliance owner mandates for consequential actions. The door turns the gateway around, in front of the business's own surface. The egress witness receipts what goes around the gateway. The ACS Guardian, a spike, receipts the decisions it gives an agent that asks before it acts. All five exist; the work is widening each, and the door's next steps are detection signals with published error rates and standards-based passports (RFC 9421, AP2).
331
+ The design is several producers feeding one verifier. The SDK is the top of the funnel: cheap to install, wide reach, honest about being self-reported. The gateway is what a security or compliance owner mandates for consequential actions. The door turns the gateway around, in front of the business's own surface. The egress witness receipts what goes around the gateway. The ACS Guardian, a spike, receipts the decisions it gives an agent that asks before it acts. All five exist; the work is widening each, and the door's next steps are detection signals with published error rates and AP2 mandates as a passport.
322
332
 
323
333
  **Done**
324
334
 
335
+ - The door for sites that are not Node (svayatta/pm#4): standard-library middleware for Go `net/http`, Rack (Rails), Django and WSGI, and the JDK `HttpServer`, in `examples/languages/door/`, each a client of the door's authz check. It forwards the method, path, query, and headers, runs the app only on the door's 200 with the receipt id and class in the request and the grant removed, returns any refusal as the door gave it, and answers 503 when the door cannot be reached or does not answer in time. A Spring `OncePerRequestFilter` around the same Java client is a doc snippet, not compiled by the tests ([the door in Go, Rails, Django, and Spring](docs/door-languages.md)).
336
+ - The door's partner engine slot (svayatta/pm#13): with `partner` in the door config, the door asks a detection engine (Cloudflare Bot Management, HUMAN, DataDome, behind an adapter that holds an Ed25519 key) about each arrival on the listed routes, naming the receipt it is writing. The engine signs its verdict for that receipt and route in the upstream attestation format; only a verdict whose signature verifies under the configured key reaches the policy, as `context.facts.partner`, and lands in the receipt as an attested fact, checked again by all three verifiers with `--upstream-key`. A verdict for another arrival is refused, and an engine that is down, slow, or signs wrongly never becomes an allow: the arrival is refused with 503 (`onFailure: "deny"`, the default) or the policy decides without the fact (`"absent"`) ([the door](docs/door.md#a-partner-engines-verdict), tutorial 52).
337
+ - The door in-process: `@agent-custody/receipts/door` runs the door's decision loop inside a Node site, the proxy's own code path split out of it. Express takes `app.use(door("door.json"))`; a Next.js App Router route takes `export const POST = guard.route(handler)`. An allowed request reaches the app with the receipt id and the class in its headers, the grant removed, and the body the policy read handed on to the app's own parsers; a refused one never reaches it; a request that can change something is in the log before the app runs; and the receipt records the app's status and a digest of its body. Neither framework is a dependency. Next.js pages, Server Actions, and its middleware file are not covered ([the door in your Node app](docs/door-middleware.md), tutorial 48).
338
+ - The door checks Web Bot Auth signatures (svayatta/pm#18): with `webBotAuth`, an RFC 9421 signature tagged `web-bot-auth` is checked against the Ed25519 key the `Signature-Agent` origin publishes in its directory, fetched over https from that origin only, for origins listed in `agents`, with a timeout, a size cap, and a cache. It must cover `@authority` (one of `authorities`) and the `Signature-Agent` member, be at most five minutes old, and carry a nonce that serves one request. A signed arrival without a grant is `verified` as its origin; a grant under its agent's signature is bound to its sender, and under another agent's it is `wrong-sender` ([the door](docs/door.md#web-bot-auth-signatures), tutorial 47).
325
339
  - A cheaper receipt hot path: a Cedar policy is parsed once per text instead of on every decision (a few slots, evicted oldest first), and the local log keeps one descriptor open for its appends, reopened when a prune replaces the file. The log lock reads its owner's start time once per process instead of running `ps` on every append on macOS. The receipt format, the decisions, and what is fsynced are unchanged. `bun run bench` times each step, Cedar and Rego both; [docs/performance.md](docs/performance.md) has the numbers.
326
340
  - The egress witness decides by Rego as well as Cedar: a `policyFile` ending in `.rego` is compiled with `opa build` as the gateway compiles one, the input is the Cedar request with plain strings, and a file that does not compile is not loaded. An OPA server is not supported for egress yet ([the egress witness](docs/egress.md#the-same-policy-in-rego), tutorial 44).
327
341
  - Drafting an egress policy: `agent-custody egress draft-policy --receipts <dir> --issuer-key <witness.pub>` verifies each egress receipt, keeps the connections the witness relayed for a verified agent, and prints one `permit` per agent and scheme over the `host:port` destinations it used, sorted, with a count and the first and last time seen for each. The output starts with a warning that it permits whatever the agents did, bad destinations included. [Writing egress policies](../../site/guide/egress-policies.md) is the guide, and its examples are tested; tutorial [42-egress-draft.ts](examples/42-egress-draft.ts).
@@ -331,6 +345,7 @@ The design is several producers feeding one verifier. The SDK is the top of the
331
345
  - One command for Claude Code (issue #204): `agent-custody init claude-code` makes the agent key, writes `sdk.json` in observe mode with no log, writes a starter deny policy, and merges the three hooks into `.claude/settings.local.json` or `~/.claude/settings.json` with absolute paths, safe to run two times. `agent-custody report` verifies the receipts and prints the calls the policy would have denied, with the reason, the rule, and the receipt id; removing the `mode` line enforces. The default local log takes a lock for each append, so hooks that run at the same time keep one log; `--log-url` needs `--log-key`; a second run keeps the pinned log key and warns about log flags it does not apply; `init` warns when git does not ignore the project settings file ([sdk.md](docs/sdk.md#claude-code), tutorial 36).
332
346
  - `agent-custody export`: copies the receipt bundles of a session into a directory for a pull request, byte for byte. It verifies each receipt against the issuer key, refuses one that carries plain arguments, results, or facts (unless `--allow-clear`), reads only `<id>.json` at the top level (never `salts/`, `outbox/`, or `*.authorization.json`), and keeps only the receipts issued at or after `--since`; [guide](docs/github-action.md), tutorial 39.
333
347
  - A GitHub Action (`action.yml` at the repository root) that runs `verify --markdown` on a directory of receipt bundles, posts one table as a pull request comment that it edits on each push, writes the same table to the job summary, and fails when a receipt does not verify or none exists; [guide](docs/github-action.md). [Issue #205](https://github.com/svayatta/agent-custody/issues/205).
348
+ - The door behind stock nginx and Envoy: with `"authz": true` the door relays nothing and answers nginx `auth_request` and Envoy `ext_authz` (HTTP mode) checks from `X-Original-Method` and `X-Original-URI`: 200 with the receipt id and class for the proxy to pass upstream, or 403, and a request that can change something is committed to the log before the 200. It never sees the body or the origin's answer, so its receipts say `issuer.framework: "authz"`, an allow is `withheld`, and all three verifiers run `door authz decided, relayed nothing`. `deploy/door/` has the stock configs and `demo.sh`, which CI runs ([the door](docs/door.md#behind-nginx-or-envoy-authz-mode), tutorial 49).
334
349
  - The door, step one of the agent front door: `agent-custody door` is a reverse proxy in front of a business's own site or API. Every arrival is classified by what it presented (`verified` by a grant from a trusted principal in scope for its route, `claimed`, or `unknown`), decided by the Cedar policy for its route with the door's own arrival fact in context (the Cedar principal is a verified agent or `unknown`, never a declared name), committed to the log before any request that can change something is relayed, relayed to the origin or refused with 403, and receipted either way as issuer kind `door`; both verifiers, the Python verifier, and `policy simulate` accept the receipts, and five conformance vectors pin them. A Turnstile or hCaptcha token is verified with the provider and recorded as the `challenge` signal, so a policy can admit a person on a route that refuses `unknown`. It does not yet detect agents in web traffic or check HTTP message signatures ([the door](docs/door.md), [door signals](docs/door-signals.md), tutorial 40).
335
350
  - Strict mode: `"strict": true` refuses a local log, a log that is not hash-only, and a log without pinned keys; precommits every tool, in observe mode too; and turns the outbox off. No call the agent makes is forwarded before its authorization is in a log the operator does not run, every receipt says `issuer.strict`, and `verify --require-strict` requires it ([usage](docs/usage.md#strict-mode), tutorial 34). [Issue #177](https://github.com/svayatta/agent-custody/issues/177).
336
351
  - Policy reload: the gateway re-reads `policy.cedar` whenever it changes and applies it from the next call, with no restart and no dropped session; a policy that does not parse is refused and the one in force stays, and every change or refusal is recorded in `receipts/policy-reloads.jsonl` ([usage](docs/usage.md)).
@@ -380,7 +395,7 @@ The design is several producers feeding one verifier. The SDK is the top of the
380
395
  - Completeness from the provider's side (issue #178): `agent-custody completeness` lists Stripe's refunds, payouts, or transfers over a window with the auditor's own read-only key, and matches each to a verified receipt by the provider's object id. It reports actions with no receipt, receipts the provider does not have, amount, currency, and beneficiary mismatches, calls forwarded without an outcome receipt, and receipts it cannot match ([completeness](docs/completeness.md), example 35).
381
396
 
382
397
  **Next, in the order it pays off**
383
-
398
+ <!-- #region receipts-next -->
384
399
  The first three close the gap between a log the operator cannot rewrite and a record the operator cannot shape.
385
400
 
386
401
  1. Run the anchor for log.agent-custody.dev on mainnet: a funded key held only by the anchor service on the host, its records served beside the checkpoints, its address and each tenant's log id published in the welcome sheet and on the security page, and the monitor checking it. The code is done. [Issue #176](https://github.com/svayatta/agent-custody/issues/176).
@@ -390,3 +405,4 @@ The first three close the gap between a log the operator cannot rewrite and a re
390
405
  5. Post-quantum signatures: ML-DSA beside Ed25519 in the same DSSE envelope, hybrid by default when a PQ key is present, in every signed artefact and in the browser verifier. [Issue #11](https://github.com/svayatta/agent-custody/issues/11).
391
406
  6. Receiver attestation for agent-to-agent calls: the delegate signs its answer for the receipt, as a signing upstream does today.
392
407
  7. SD-JWT redaction, then ZK proofs of policy compliance. Not before.
408
+ <!-- #endregion receipts-next -->
package/dist/capture.d.ts CHANGED
@@ -90,6 +90,8 @@ export declare function ruleFor(capture: CaptureConfig | undefined, tool: string
90
90
  * issuer both call this, so the fact arguments kept in clear and the view agree.
91
91
  */
92
92
  export declare function effectiveRule(capture: CaptureConfig | undefined, tool: string, unknownTool?: boolean): CaptureRule | undefined;
93
+ /** The same test for any signed content: an attestation envelope that binds this receipt, this tool, and `digest`, and nothing else. A partner engine's verdict is signed this way, over the verdict's digest. */
94
+ export declare function isPlainEnvelope(envelope: unknown, receiptId: unknown, tool: unknown, digest: string): boolean;
93
95
  /** The one mode a rule withholds in: encrypted when any side is, else digest; clear when no side is private. */
94
96
  export declare function ruleMode(rule: CaptureRule | undefined): CaptureMode;
95
97
  export declare const pathKey: (p: Path) => string;
package/dist/capture.js CHANGED
@@ -156,9 +156,13 @@ export function effectiveRule(capture, tool, unknownTool = false) {
156
156
  * rule publishes from the same upstream.
157
157
  */
158
158
  function isPlainAttestation(envelope, receiptId, tool, result) {
159
+ return isObject(result) && isPlainEnvelope(envelope, receiptId, tool, contentDigest(result));
160
+ }
161
+ /** The same test for any signed content: an attestation envelope that binds this receipt, this tool, and `digest`, and nothing else. A partner engine's verdict is signed this way, over the verdict's digest. */
162
+ export function isPlainEnvelope(envelope, receiptId, tool, digest) {
159
163
  if (!isObject(envelope) || !exactKeys(envelope, ["payload", "payloadType", "signatures"]))
160
164
  return false;
161
- if (envelope.payloadType !== UPSTREAM_TYPE || typeof envelope.payload !== "string" || !isObject(result))
165
+ if (envelope.payloadType !== UPSTREAM_TYPE || typeof envelope.payload !== "string")
162
166
  return false;
163
167
  const sigs = envelope.signatures;
164
168
  if (!Array.isArray(sigs) || sigs.length !== 1)
@@ -176,7 +180,7 @@ function isPlainAttestation(envelope, receiptId, tool, result) {
176
180
  // compared as bytes: decoding to text would turn an invalid byte into U+FFFD and let it through
177
181
  if (!isObject(p) || !exactKeys(p, ["contentDigest", "receiptId", "tool"]) || !bytes.equals(Buffer.from(canonicalize(p), "utf8")))
178
182
  return false;
179
- return p.receiptId === receiptId && p.tool === tool && p.contentDigest === contentDigest(result);
183
+ return p.receiptId === receiptId && p.tool === tool && p.contentDigest === digest;
180
184
  }
181
185
  catch {
182
186
  return false;
@@ -396,6 +400,13 @@ export function privateView(predicate, rule, key, ctx = {}, prior) {
396
400
  if (argsSide)
397
401
  fields(["facts", name, "args"], v, { clear: new Set(ownOf(ctx.clearFactArgs, name) ?? []), key: argsSide.key });
398
402
  }
403
+ else if (f === "attestation") {
404
+ // a fact its source signed (the door's partner verdict): kept beside a value the rule leaves in clear only
405
+ // when it is exactly the plain attestation of that value for this receipt and route, as an upstream's is
406
+ if (!factsSide && !ctx.unknownTool && isPlainEnvelope(v, predicate.receiptId, predicate.tool.name, digestOf(fact.value)))
407
+ continue;
408
+ hide(["facts", name, f], v, factsSide ? factsSide.key : k);
409
+ }
399
410
  else if (!CLEAR_IN.fact.has(f))
400
411
  hide(["facts", name, f], v, k);
401
412
  }
package/dist/check.d.ts CHANGED
@@ -15,7 +15,7 @@ export interface CheckOptions {
15
15
  /** cancels --connect while it is starting the upstreams; whatever was started is closed */
16
16
  signal?: AbortSignal;
17
17
  }
18
- /** True when the file is a door config rather than a gateway config: it names an origin, which no gateway config has. */
18
+ /** True when the file is a door config rather than a gateway config: it names an origin, door routes, or answers authz checks, which no gateway config does. An in-process door's config has routes and no origin. */
19
19
  export declare function isDoorConfig(configPath: string): boolean;
20
20
  /**
21
21
  * The agents named by permits that do not also require a verified arrival. At the door the principal is the agent of a
package/dist/check.js CHANGED
@@ -51,11 +51,11 @@ function onPath(command) {
51
51
  return existsSync(command);
52
52
  return (process.env.PATH ?? "").split(delimiter).some((d) => d && existsSync(join(d, command)));
53
53
  }
54
- /** True when the file is a door config rather than a gateway config: it names an origin, which no gateway config has. */
54
+ /** True when the file is a door config rather than a gateway config: it names an origin, door routes, or answers authz checks, which no gateway config does. An in-process door's config has routes and no origin. */
55
55
  export function isDoorConfig(configPath) {
56
56
  try {
57
57
  const raw = JSON.parse(readFileSync(configPath, "utf8"));
58
- return !!raw && typeof raw === "object" && !Array.isArray(raw) && "origin" in raw && !("upstream" in raw) && !("upstreams" in raw);
58
+ return !!raw && typeof raw === "object" && !Array.isArray(raw) && ("origin" in raw || "routes" in raw || "authz" in raw) && !("upstream" in raw) && !("upstreams" in raw) && !("agents" in raw);
59
59
  }
60
60
  catch {
61
61
  return false;
@@ -164,14 +164,20 @@ export function checkDoorConfig(configPath) {
164
164
  add("warn", "routes", `no routes: every arrival is the action "${cfg.unmatchedRoute}"`);
165
165
  else
166
166
  add("ok", "routes", `${cfg.routes.length} route(s); unmatched arrivals are "${cfg.unmatchedRoute}"`);
167
- const origin = new URL(cfg.origin.url);
168
- if (origin.protocol !== "https:" && !["localhost", "127.0.0.1", "[::1]"].includes(origin.hostname))
169
- add("warn", "origin", `${cfg.origin.url} is plain HTTP to a remote host; the relayed traffic is not encrypted on that leg`);
170
- else
171
- add("ok", "origin", `relays to ${cfg.origin.url}`);
172
- for (const [, variable] of Object.entries(cfg.origin.headerEnv ?? {}))
173
- if (!process.env[variable])
174
- add("error", "credentials", `origin header variable ${variable} is not set in this environment`);
167
+ if (cfg.authz)
168
+ add("ok", "authz", "answers nginx auth_request and Envoy ext_authz checks: the proxy relays, and the receipts record the decision, never the body or the origin's answer");
169
+ else if (!cfg.origin)
170
+ add("ok", "origin", "no origin: a config for the door in-process (Express or Next.js); `agent-custody door` needs origin.url, or authz: true behind nginx or Envoy");
171
+ else {
172
+ const origin = new URL(cfg.origin.url);
173
+ if (origin.protocol !== "https:" && !["localhost", "127.0.0.1", "[::1]"].includes(origin.hostname))
174
+ add("warn", "origin", `${cfg.origin.url} is plain HTTP to a remote host; the relayed traffic is not encrypted on that leg`);
175
+ else
176
+ add("ok", "origin", `relays to ${cfg.origin.url}`);
177
+ for (const [, variable] of Object.entries(cfg.origin.headerEnv ?? {}))
178
+ if (!process.env[variable])
179
+ add("error", "credentials", `origin header variable ${variable} is not set in this environment`);
180
+ }
175
181
  if (cfg.log?.tokenEnv && !process.env[cfg.log.tokenEnv])
176
182
  add("error", "credentials", `log token variable ${cfg.log.tokenEnv} is not set in this environment`);
177
183
  if (cfg.splunk?.tokenEnv && !process.env[cfg.splunk.tokenEnv])
@@ -191,6 +197,24 @@ export function checkDoorConfig(configPath) {
191
197
  }
192
198
  else
193
199
  add("ok", "challenge", "no challenge: an unknown arrival has no way to become anything else on this door");
200
+ if (cfg.webBotAuth) {
201
+ const w = cfg.webBotAuth;
202
+ add("ok", "web bot auth", `Ed25519 signatures tagged web-bot-auth from ${w.agents.join(", ")} are checked against their directories, for ${w.authorities.join(", ")}, at most ${w.maxAgeSeconds} s after created; a verified signature without a grant makes the arrival verified as its origin`);
203
+ if (!w.requireNonce)
204
+ add("warn", "web bot auth", `requireNonce is false: a signature without a nonce can be replayed for up to ${w.maxAgeSeconds + w.clockSkewSeconds} s, and a minimal one covers only the authority, so the replay may use any method and path`);
205
+ }
206
+ else
207
+ add("ok", "web bot auth", "no webBotAuth: a Signature-Input header is recorded as signature \"unchecked\", a claim");
208
+ if (cfg.partner) {
209
+ const p = cfg.partner;
210
+ try {
211
+ loadPublicKey(p.keyFile);
212
+ add("ok", "partner", `${p.engine} at ${p.url} is asked about ${p.routes.join(", ")} within ${p.timeoutMs} ms; only a verdict signed under ${p.keyFile} for the arrival reaches context.facts.partner. Without one: ${p.onFailure === "deny" ? "the arrival is refused with 503" : "the policy decides without the fact"}`);
213
+ }
214
+ catch (e) {
215
+ add("error", "partner", `${p.keyFile}: ${e instanceof Error ? e.message : String(e)}`);
216
+ }
217
+ }
194
218
  const dir = writableAncestor(cfg.receiptsDir);
195
219
  if (!dir)
196
220
  add("error", "paths", `${cfg.receiptsDir} cannot be created: no writable directory above it`);
package/dist/cli.js CHANGED
@@ -23,6 +23,8 @@ import { createDoorHost, serveDoor } from "./door.js";
23
23
  import { createEgressHost, serveEgress } from "./egress.js";
24
24
  import { draftEgressPolicy } from "./egress-draft.js";
25
25
  import { createAcsGuardian } from "./acs.js";
26
+ import { auditSessions, defaultTranscriptDir, formatSessionAudit, parseSince } from "./session-audit.js";
27
+ import { formatPerathosReport, perathosHead, verifyPerathosLog } from "./perathos.js";
26
28
  import { serveA2a } from "./a2a.js";
27
29
  import { PortalStore, sendFollowUps, servePortal } from "./portal.js";
28
30
  import { exportLog, formatExport } from "./log-export.js";
@@ -100,7 +102,9 @@ const USAGE = `agent-custody <command>
100
102
  door --config <door.json> [--port 8780] [--host 127.0.0.1]
101
103
  a reverse proxy in front of your own site or API: every arrival classified (verified by a
102
104
  trusted grant, claimed, or unknown), decided by the Cedar policy for its route, relayed to the
103
- origin or refused with 403, and receipted either way; GET /.well-known/agent-custody-door
105
+ origin or refused with 403, and receipted either way; GET /.well-known/agent-custody-door.
106
+ With "authz": true in the config it relays nothing and answers nginx auth_request and
107
+ Envoy ext_authz checks instead: 200 with the receipt headers, or 403
104
108
  egress --config <egress.json> [--port 8791] [--host 127.0.0.1]
105
109
  the egress witness: a forward proxy (CONNECT and plain HTTP, no TLS interception) for a
106
110
  locked-down agent's calls that do not go to the gateway. Each agent proves itself with its own
@@ -115,6 +119,8 @@ const USAGE = `agent-custody <command>
115
119
  init claude-code [--dir <dir>] [--user] [--enforce] [--log-url <url> [--log-id <id>] [--log-token-env NAME] [--log-key <pub>]]
116
120
  one command for your own Claude Code sessions: an agent key, sdk.json in observe mode, a starter deny
117
121
  policy, and the three hooks in .claude/settings.local.json (--user: ~/.claude/settings.json). Safe to run twice
122
+ audit-sessions [--since 7d|24h|<date>|all] [--dir <claude projects dir>] [--policy <file.cedar>] [--counts] [--json]
123
+ a read-only preview: which of your past Claude Code tool calls the policy would have denied, from the transcripts; writes nothing
118
124
  report --config <sdk.json> the calls that the policy would have denied, from the receipts: tool, command or path, rule, receipt id;
119
125
  a receipt that does not verify is counted apart. Exits 1 when any receipt does not verify
120
126
  hook [--config <sdk.json>] Claude Code hook command; reads the event on stdin (or AGENT_CUSTODY_CONFIG)
@@ -124,6 +130,8 @@ const USAGE = `agent-custody <command>
124
130
  log --file <log.jsonl> --key <log.key> [--port 8787] [--host 127.0.0.1] [--token-env <NAME>] reference log server
125
131
  verify <bundle.json> --issuer-key <pub> [--principal-key <pub>] [--approval-key <pub>] [--log-key <pub> | --log-url <url>] [--log-id <id>] [--require-strict] [--upstream-key <pub>] [--stripe-secret-env NAME] [--github-secret-env NAME] [--log <log.jsonl>] [--disclose <file>] [--capture-key-env NAME] [--json]
126
132
  verify --markdown <dir|bundle.json>... --issuer-key <pub> one Markdown table for a directory of bundles; exit 1 when one does not verify or none exists
133
+ verify-perathos <session.jsonl> [--key <hex>]... [--allow-unsigned] [--head <session.head.json>] [--json]
134
+ check another project's record format, a Perathos session log (perathos.receipt/v1), against its spec; exit 1 when it is not valid
127
135
  export --receipts <dir> --out <dir> --issuer-key <pub>... [--principal-key <pub>]... [--approval-key <pub>]... [--since <ISO time>] [--allow-clear]
128
136
  copies the verified receipt bundles that keep their values private into a directory for a pull request, byte for byte.
129
137
  Reads only <id>.json at the top level; never salts/, outbox/, or *.authorization.json. Exits 1 when it refuses a receipt, and when it copies none
@@ -179,7 +187,8 @@ const USAGE = `agent-custody <command>
179
187
  [--stripe-key-env NAME --stripe-webhook-env NAME --stripe-price-team <price id>] [--trust-proxy]
180
188
  the tenant portal: register, first key, usage against plan, keys, billing, export
181
189
  log-admin --db-env NAME import --file <log.jsonl> [--tenant default] copies a file log into the database as hashes
182
- portal-followup --db-env NAME --mail-key-env NAME --mail-from <address> [--mail-notify <address>] [--portal-url <url>] [--dry-run]
190
+ portal-followup --db-env NAME --secret-env NAME --mail-key-env NAME --mail-from <address> [--mail-notify <address>] [--mail-reply-to <address>]
191
+ [--signer <name>] [--signer-role <role>] [--portal-url <url>] [--dry-run]
183
192
  the founder's note to registrations an hour to a week old that have not had it; hourly from cron
184
193
  audit --older <bundle.json> --newer <bundle.json> (--log <log.jsonl> | --log-url <url>) [--issuer-key <pub>] [--log-key <pub>] [--log-id <id>] [--witness-key <pub> | --witness-url <url>] [--json]
185
194
  with --log-url the log's published keys are fetched and pinned by keyid; with a witness key or
@@ -372,7 +381,7 @@ async function main(argv) {
372
381
  const cfg = loadDoorConfig(values.config);
373
382
  const host = await createDoorHost(cfg, { autoFlush: true });
374
383
  const running = await serveDoor(host, { port: Number(values.port), host: values.host });
375
- console.error(`agent-custody door: ${running.url} keyid=${host.keyid} in front of ${cfg.origin.url}; ${cfg.routes.length} route(s), unmatched arrivals are "${cfg.unmatchedRoute}"`);
384
+ console.error(`agent-custody door: ${running.url} keyid=${host.keyid} ${cfg.authz ? "answering authz checks" : `in front of ${cfg.origin?.url}`}; ${cfg.routes.length} route(s), unmatched arrivals are "${cfg.unmatchedRoute}"`);
376
385
  await untilStopped();
377
386
  await running.close();
378
387
  await host.close();
@@ -456,6 +465,20 @@ async function main(argv) {
456
465
  });
457
466
  return 0;
458
467
  }
468
+ case "audit-sessions": {
469
+ const { values } = parseArgs({ args: rest, options: { since: { type: "string", default: "7d" }, dir: { type: "string" }, policy: { type: "string" }, json: { type: "boolean", default: false }, counts: { type: "boolean", default: false } } });
470
+ if (values.policy && isRegoFile(values.policy))
471
+ throw new Error("audit-sessions reads a Cedar policy; a Rego policy needs opa, which writes files");
472
+ const templateUrl = new URL("../templates/claude-code.cedar", import.meta.url);
473
+ const audit = auditSessions({
474
+ dir: values.dir ?? defaultTranscriptDir(),
475
+ policyText: readFileSync(values.policy ?? templateUrl, "utf8"),
476
+ policyName: values.policy ?? "the init claude-code template",
477
+ ...(values.since === "all" ? {} : { since: parseSince(values.since) }),
478
+ });
479
+ console.log(values.json ? JSON.stringify(audit, null, 2) : formatSessionAudit(audit, { counts: values.counts }));
480
+ return 0;
481
+ }
459
482
  case "report": {
460
483
  const { values } = parseArgs({ args: rest, options: { config: { type: "string" } } });
461
484
  if (!values.config)
@@ -592,18 +615,21 @@ async function main(argv) {
592
615
  }
593
616
  case "portal-followup": {
594
617
  // The founder's note to every registration between an hour and a week old that has not had it; run hourly from cron.
595
- const { values } = parseArgs({ args: rest, options: { "db-env": { type: "string" }, "mail-key-env": { type: "string" }, "mail-from": { type: "string" }, "mail-notify": { type: "string" }, "portal-url": { type: "string", default: "https://app.agent-custody.dev/" }, "dry-run": { type: "boolean", default: false } } });
596
- if (!values["db-env"] || !values["mail-key-env"] || !values["mail-from"])
597
- throw new Error("portal-followup needs --db-env, --mail-key-env, and --mail-from");
618
+ const { values } = parseArgs({ args: rest, options: { "db-env": { type: "string" }, "mail-key-env": { type: "string" }, "mail-from": { type: "string" }, "mail-notify": { type: "string" }, "mail-reply-to": { type: "string" }, "secret-env": { type: "string" }, signer: { type: "string" }, "signer-role": { type: "string" }, "portal-url": { type: "string", default: "https://app.agent-custody.dev/" }, "dry-run": { type: "boolean", default: false } } });
619
+ if (!values["db-env"] || !values["secret-env"] || !values["mail-key-env"] || !values["mail-from"])
620
+ throw new Error("portal-followup needs --db-env, --secret-env, --mail-key-env, and --mail-from");
598
621
  const apiKey = process.env[values["mail-key-env"]];
599
622
  if (!apiKey)
600
623
  throw new Error(`portal-followup: environment variable ${values["mail-key-env"]} is not set`);
601
- const r = await sendFollowUps(new PortalStore(openPostgres(values["db-env"])), { apiKey, from: values["mail-from"], ...(values["mail-notify"] ? { notify: values["mail-notify"] } : {}) }, { portalUrl: values["portal-url"], dryRun: values["dry-run"] });
624
+ const secret = process.env[values["secret-env"]];
625
+ if (!secret)
626
+ throw new Error(`portal-followup: environment variable ${values["secret-env"]} is not set`);
627
+ const r = await sendFollowUps(new PortalStore(openPostgres(values["db-env"])), { apiKey, from: values["mail-from"], ...(values["mail-notify"] ? { notify: values["mail-notify"] } : {}), ...(values["mail-reply-to"] ? { replyTo: values["mail-reply-to"] } : {}) }, { portalUrl: values["portal-url"], secret, ...(values.signer ? { signer: values.signer } : {}), ...(values["signer-role"] ? { signerRole: values["signer-role"] } : {}), dryRun: values["dry-run"] });
602
628
  console.log(`${values["dry-run"] ? "would send" : "sent"} ${r.sent.length}, skipped ${r.skipped.length} (operator's own), failed ${r.failed.length}${r.sent.length ? `: ${r.sent.join(", ")}` : ""}`);
603
629
  return r.failed.length ? 1 : 0;
604
630
  }
605
631
  case "portal": {
606
- const { values } = parseArgs({ args: rest, options: { "db-env": { type: "string" }, "secret-env": { type: "string" }, "public-url": { type: "string" }, "checkpoints-url": { type: "string" }, "portal-url": { type: "string" }, port: { type: "string", default: "8792" }, host: { type: "string", default: "127.0.0.1" }, "stripe-key-env": { type: "string" }, "stripe-webhook-env": { type: "string" }, "stripe-price-team": { type: "string" }, "mail-key-env": { type: "string" }, "mail-from": { type: "string" }, "mail-notify": { type: "string" }, "github-client-id": { type: "string" }, "github-secret-env": { type: "string" }, "google-client-id": { type: "string" }, "google-secret-env": { type: "string" }, "trust-proxy": { type: "boolean", default: false } } });
632
+ const { values } = parseArgs({ args: rest, options: { "db-env": { type: "string" }, "secret-env": { type: "string" }, "public-url": { type: "string" }, "checkpoints-url": { type: "string" }, "portal-url": { type: "string" }, port: { type: "string", default: "8792" }, host: { type: "string", default: "127.0.0.1" }, "stripe-key-env": { type: "string" }, "stripe-webhook-env": { type: "string" }, "stripe-price-team": { type: "string" }, "mail-key-env": { type: "string" }, "mail-from": { type: "string" }, "mail-notify": { type: "string" }, "mail-reply-to": { type: "string" }, "github-client-id": { type: "string" }, "github-secret-env": { type: "string" }, "google-client-id": { type: "string" }, "google-secret-env": { type: "string" }, "trust-proxy": { type: "boolean", default: false } } });
607
633
  if (!values["db-env"] || !values["secret-env"] || !values["public-url"])
608
634
  throw new Error("portal needs --db-env, --secret-env, and --public-url");
609
635
  let oauth;
@@ -628,7 +654,7 @@ async function main(argv) {
628
654
  const apiKey = process.env[values["mail-key-env"]];
629
655
  if (!apiKey)
630
656
  throw new Error(`portal: environment variable ${values["mail-key-env"]} is not set`);
631
- mail = { apiKey, from: values["mail-from"], ...(values["mail-notify"] ? { notify: values["mail-notify"] } : {}) };
657
+ mail = { apiKey, from: values["mail-from"], ...(values["mail-notify"] ? { notify: values["mail-notify"] } : {}), ...(values["mail-reply-to"] ? { replyTo: values["mail-reply-to"] } : {}) };
632
658
  }
633
659
  const secret = process.env[values["secret-env"]];
634
660
  if (!secret || secret.length < 32)
@@ -839,6 +865,25 @@ async function main(argv) {
839
865
  await running.close();
840
866
  return 0;
841
867
  }
868
+ case "verify-perathos": {
869
+ const { values, positionals } = parseArgs({
870
+ args: rest,
871
+ allowPositionals: true,
872
+ options: { key: { type: "string", multiple: true }, "allow-unsigned": { type: "boolean", default: false }, head: { type: "string" }, json: { type: "boolean", default: false } },
873
+ });
874
+ if (positionals.length !== 1)
875
+ throw new Error("verify-perathos needs one session log");
876
+ for (const k of values.key ?? [])
877
+ if (!/^[0-9a-fA-F]{64}$/.test(k))
878
+ throw new Error(`--key takes an Ed25519 public key as 64 hex characters; got "${k}"`);
879
+ const report = verifyPerathosLog(readFileSync(positionals[0], "utf8"), {
880
+ ...(values.key ? { trustedKeys: values.key } : {}),
881
+ allowUnsigned: values["allow-unsigned"],
882
+ ...(values.head ? { head: perathosHead(readFileSync(values.head, "utf8")) } : {}),
883
+ });
884
+ console.log(values.json ? JSON.stringify(report, null, 2) : formatPerathosReport(report));
885
+ return report.ok ? 0 : 1;
886
+ }
842
887
  case "verify": {
843
888
  const { values, positionals } = parseArgs({
844
889
  args: rest,
package/dist/config.d.ts CHANGED
@@ -388,12 +388,13 @@ export declare const DoorConfigSchema: z.ZodObject<{
388
388
  identity: z.ZodObject<{
389
389
  keyFile: z.ZodString;
390
390
  }, z.core.$strip>;
391
- origin: z.ZodObject<{
391
+ origin: z.ZodOptional<z.ZodObject<{
392
392
  url: z.ZodString;
393
393
  headers: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
394
394
  headerEnv: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
395
395
  timeoutMs: z.ZodDefault<z.ZodNumber>;
396
- }, z.core.$strip>;
396
+ }, z.core.$strip>>;
397
+ authz: z.ZodOptional<z.ZodBoolean>;
397
398
  routes: z.ZodDefault<z.ZodArray<z.ZodObject<{
398
399
  name: z.ZodString;
399
400
  methods: z.ZodOptional<z.ZodArray<z.ZodEnum<{
@@ -432,6 +433,30 @@ export declare const DoorConfigSchema: z.ZodObject<{
432
433
  action: z.ZodOptional<z.ZodString>;
433
434
  maxInFlight: z.ZodDefault<z.ZodNumber>;
434
435
  }, z.core.$strip>>;
436
+ webBotAuth: z.ZodOptional<z.ZodObject<{
437
+ agents: z.ZodArray<z.ZodPipe<z.ZodString, z.ZodTransform<string, string>>>;
438
+ authorities: z.ZodArray<z.ZodPipe<z.ZodString, z.ZodTransform<string, string>>>;
439
+ requireNonce: z.ZodDefault<z.ZodBoolean>;
440
+ maxAgeSeconds: z.ZodDefault<z.ZodNumber>;
441
+ clockSkewSeconds: z.ZodDefault<z.ZodNumber>;
442
+ timeoutMs: z.ZodDefault<z.ZodNumber>;
443
+ maxDirectoryBytes: z.ZodDefault<z.ZodNumber>;
444
+ cacheSeconds: z.ZodDefault<z.ZodNumber>;
445
+ maxNonces: z.ZodDefault<z.ZodNumber>;
446
+ }, z.core.$strip>>;
447
+ partner: z.ZodOptional<z.ZodObject<{
448
+ engine: z.ZodString;
449
+ url: z.ZodString;
450
+ keyFile: z.ZodString;
451
+ routes: z.ZodArray<z.ZodString>;
452
+ timeoutMs: z.ZodDefault<z.ZodNumber>;
453
+ onFailure: z.ZodDefault<z.ZodEnum<{
454
+ absent: "absent";
455
+ deny: "deny";
456
+ }>>;
457
+ maxInFlight: z.ZodDefault<z.ZodNumber>;
458
+ maxResponseBytes: z.ZodDefault<z.ZodNumber>;
459
+ }, z.core.$strip>>;
435
460
  receiptsDir: z.ZodString;
436
461
  logFile: z.ZodOptional<z.ZodString>;
437
462
  log: z.ZodOptional<z.ZodObject<{