@agent-custody/receipts 0.16.12 → 0.16.14

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/docs/door.md CHANGED
@@ -4,7 +4,7 @@
4
4
 
5
5
  The gateway stands between an agent and the tools it uses. The door stands between the world and your own HTTP surface: a website, an API, a form. Every arrival, a browser, an API client, a crawler, or an agent acting for someone, is classified by what it presented, decided by a Cedar policy for the route it hit, relayed to your origin or refused, and receipted either way. The receipt is the same signed, logged, independently verifiable receipt the gateway issues, with `issuer.kind: "door"`.
6
6
 
7
- New to the door? [Put the door in front of a site](door-quickstart.md) walks through one form in about fifteen minutes. A Node site can run the same decision loop in its own process instead, as Express middleware or around a Next.js route handler: [the door in your Node app](door-middleware.md). Already run nginx or Envoy? The door can answer their authz checks instead of relaying, and the site keeps its proxy: [behind nginx or Envoy](#behind-nginx-or-envoy-authz-mode). A site in Go, Rails, Django, or Spring can ask the same check from a middleware: [the door in Go, Rails, Django, and Spring](door-languages.md). A site already on Cloudflare can run the door at the edge, as a Worker: [the door as a Cloudflare Worker](door-worker.md).
7
+ New to the door? [Put the door in front of a site](door-quickstart.md) walks through one form in about fifteen minutes. A Node site can run the same decision loop in its own process instead, as Express middleware or around a Next.js route handler: [the door in your Node app](door-middleware.md). Already run nginx or Envoy? The door can answer their authz checks instead of relaying, and the site keeps its proxy: [behind nginx or Envoy](#behind-nginx-or-envoy-authz-mode). A site in Go, Rails, Django, or Spring can ask the same check from a middleware: [the door in Go, Rails, Django, and Spring](door-languages.md). A site already on Cloudflare can run the door at the edge, as a Worker: [the door as a Cloudflare Worker](door-worker.md). A WordPress site installs a plugin that protects its comments and forms: [the door as a WordPress plugin](door-wordpress.md).
8
8
 
9
9
  This is the first piece of the agent front door. It answers "what may this arrival do here" and "what did it do, provably". It does not yet answer "is this an agent" for web traffic: that is detection, and the door records only what it can check. An agent that wants to be known can say so in a way the door checks: a grant, or a [Web Bot Auth signature](#web-bot-auth-signatures). Read [what the door knows](#what-the-door-knows-about-an-arrival) before writing a policy.
10
10
 
@@ -39,7 +39,7 @@ To run it as a service, the gateway image has a `door` mode (`docker run ... ghc
39
39
 
40
40
  Every field of the config, with its type and default, is in [the door reference](../../../site/reference/door.md#config).
41
41
 
42
- `agent-custody check --config door.json` reads a door config the way the door would: unknown keys, the key, the principal keys, the policy (including a permit that names an agent without requiring a verified arrival, see below), the routes, what is precommitted, the challenge provider or its absence, the partner engine and its key, the `behaviour` signals (with a warning that the proxy must overwrite `behaviour.tlsHeader`), the revocation file, the origin's scheme, every credential variable the door reads at startup (origin headers, the log, Splunk, OTel, the capture key, the challenge secret), and the paths. It exits 1 on an error.
42
+ `agent-custody check --config door.json` reads a door config the way the door would: unknown keys, the key, the principal keys, the policy (including a permit that names an agent without requiring a verified arrival, see below), the routes, what is precommitted, the challenge provider or its absence, the partner engine and its key, the `behaviour` signals (with a warning that the proxy must overwrite `behaviour.tlsHeader`), the revocation file, the trusted registry keys (an error for one that does not load, or for `trustedRegistryKeys` without `webBotAuth`, and a warning when more than one is trusted and any is bound to no registry URL), the admission lists file (an error for one that cannot be read or is not valid), the origin's scheme, every credential variable the door reads at startup (origin headers, the log, Splunk, OTel, the capture key, the challenge secret), and the paths. It exits 1 on an error.
43
43
 
44
44
  ## What the door knows about an arrival
45
45
 
@@ -47,12 +47,14 @@ The door records one fact for every arrival, `arrival`, observed by the door its
47
47
 
48
48
  | field | values | meaning |
49
49
  | --- | --- | --- |
50
- | `class` | `verified`, `claimed`, `unknown` | `verified`: a grant signed by a trusted principal, inside its window, naming this route among its scopes; or, with no grant, a [Web Bot Auth signature](#web-bot-auth-signatures) that checked against the key its agent's directory publishes. `claimed`: something was asserted that the door could not accept: a grant from a stranger, an expired one, a revoked one, one for other routes, one presented under another agent's signature, a declared agent name, or a signature that did not check or was not checked. `unknown`: nothing was presented |
50
+ | `class` | `verified`, `claimed`, `unknown` | `verified`: a grant signed by a trusted principal, inside its window, naming this route among its scopes; or, with no grant, a [Web Bot Auth signature](#web-bot-auth-signatures) that checked against the key its agent's directory publishes, or a [registry passport](#a-registry-passport) under a signature by the did:key it names. `claimed`: something was asserted that the door could not accept: a grant from a stranger, an expired one, a revoked one, one for other routes, one presented under another agent's signature, a declared agent name, or a signature that did not check or was not checked. `unknown`: nothing was presented |
51
51
  | `subject` | string | the agent named in a verified grant; else the signature agent of a verified signature (its https origin); else the declared name or the agent a rejected grant named; else `unknown`. Only a verified subject reaches the Cedar `principal` |
52
52
  | `grant` | `verified`, `out-of-scope`, `invalid`, `revoked`, `wrong-sender`, `absent` | what became of the grant header, with `grantError` when it was not accepted. `revoked`: the grant verified, and it or a grant above it in its chain is in `revokedGrants` (see [revoking a grant](#revoking-a-grant)). `wrong-sender`: the grant verified, and the request is signed by a signature agent, or by a did:key, that the grant does not name |
53
53
  | `signature` | `verified`, `invalid`, `unavailable`, `unchecked`, `absent` | what became of an RFC 9421 signature tagged `web-bot-auth`, with `signatureError` when it was not verified. `unchecked`: a `Signature-Input` arrived and the config has no `webBotAuth`, so it is a claim. See [Web Bot Auth signatures](#web-bot-auth-signatures) |
54
54
  | `signatureAgent`, `signatureKeyid` | strings | the `Signature-Agent` origin and the keyid the signature named. For a signature by a did:key's key, both are the did:key. Checked only when `signature` is `verified` |
55
55
  | `declared` | string | the `x-agent-custody-agent` header, when sent. A claim |
56
+ | `passport` | `{ outcome, error?, registry?, registryKeyid?, agentId?, agent?, name?, owner?, capabilities?, agentVersion?, endpoints?, erc8004?, expiresAt?, digest?, envelope? }` | only when the arrival sent `x-agent-custody-passport`. `verified`: a key in `trustedRegistryKeys` signed it, it is in its window, and the request is signed by the did:key it names, with a signature that covers `@method`, `@path`, `@query`, the passport header, and on a write a `Content-Digest` that matches the body. `unbound`: it verified and the request is signed by its key, without that coverage. `wrong-sender`: it verified, and the request is not signed by that key. `invalid`: it did not verify. `unchecked`: the door trusts no registry key. Only a `verified` passport puts the registry's entry (`agentId`, `name`, `owner`, `capabilities`, `erc8004` when the registry linked an ERC-8004 identity, `expiresAt`, `digest`) and the passport itself (`envelope`) in the fact; another outcome records at most `registry` and `agent`. See [a registry passport](#a-registry-passport) |
57
+ | `admission` | `{ lists, digest }` | only when the config has `admissionLists`. The names of the site's [admission lists](admission-lists.md) the arrival's agent is on, sorted (empty when none), and the sha256 of the lists file in force. Only a `verified` arrival is on a list: by its subject, or by the registry entry or ERC-8004 identity of its `verified` passport |
56
58
  | `remote` | string | the arrival's address |
57
59
  | `challenge` | `{ provider, outcome, error? }` | only when `challenge` is configured. `passed`: the provider confirmed the token the arrival sent. `failed`: the provider refused the token (`invalid-input-response`, `timeout-or-duplicate`, `expired-input-response`, `already-seen-response`, `missing-input-response`, with the codes in `error`), it confirmed a token issued on another hostname or for another action, or the token was longer than 4096 characters, which is refused without calling the provider. `unavailable`: the provider did not answer in time, answered a non-200, a redirect, or something that is not JSON, answered a code that is its own or the operator's fault (`internal-error`, `bad-request`, `missing-input-secret`, `invalid-input-secret`, `sitekey-secret-mismatch`, `invalid-sitekey`, `missing-sitekey`, `invalid-remoteip`: a rotated secret gives every person one of these), or `maxInFlight` checks were already waiting. `absent`: no token. A passed challenge leaves `class` as it was: it says a provider's test was passed in front of this arrival, not who the arrival is |
58
60
  | `partner` | `{ engine, outcome, error? }` | only when `partner` is configured and the route is in `partner.routes`. `verified`: the engine's verdict was signed for this arrival under `partner.keyFile`, and is the `partner` fact. `rejected`: the engine answered with anything else. `unavailable`: it did not answer in time or at all. See [a partner engine's verdict](#a-partner-engines-verdict) |
@@ -73,6 +75,8 @@ There is no `human` class. The door cannot tell a person from a program that pre
73
75
 
74
76
  **A did:key grant under a signature by its own key is bound to its sender.** <a id="a-did-key-signature"></a>With `webBotAuth` configured, the agent signs the request as for [Web Bot Auth](#web-bot-auth-signatures) (RFC 9421, Ed25519, `tag="web-bot-auth"`, `@authority` covered, `created`, `expires`, and a nonce), and sets `keyid` to its did:key. It sends no `Signature-Agent`, and the door fetches no directory, because the did:key carries the key. The door applies the same checks of the window, the authority, the covered components, and the nonce, and verifies the signature with the key that the did:key names. When the grant verifies and names that did:key, the arrival is `verified` with `signature: "verified"`, and `signatureAgent` and `signatureKeyid` are the did:key. The policy condition for a bound grant, `context.facts.arrival.grant == "verified" && context.facts.arrival.signature == "verified"`, holds for it. A did:key grant under a signature by another did:key's key, or under a Web Bot Auth signature from an https origin, is `wrong-sender`, and the arrival is `claimed`. Anyone can make a key and its did:key, so a did:key signature counts only with a verified grant that names it. With no grant, with a grant that is not verified, or with a grant for another agent, the door records `signature: "invalid"` and the reason in `signatureError`, and the arrival is never `verified` by that signature. `agents` does not list a did:key: the grant of a trusted principal is what admits it. The door keeps the nonce of a did:key signature only when a trusted principal signed the request's grant for that did:key, so signatures by keys that no principal granted cannot fill the nonce store. A door without `webBotAuth` records the signature as `unchecked`, and the grant stays bearer-grade.
75
77
 
78
+ **A registry passport.** <a id="a-registry-passport"></a>An agent registered in an [agent registry](agent-registry.md) holds a passport: a statement, signed by the registry, of the agent's did:key, its owner, a contact, and its capabilities, valid for a day by default. List the registry's key in `trustedRegistryKeys` (the key document is at the registry's `/.well-known/agent-custody-registry.json`) and configure `webBotAuth` (its `agents` may be empty). The agent sends the passport as base64url JSON in `X-Agent-Custody-Passport` and signs the request with its did:key, as [above](#a-did-key-signature), covering `@method`, `@path`, `@query`, the passport header, and on a write `content-digest` ([the agent registry](agent-registry.md#admit-registered-agents-at-a-door) has the full list). With no grant, that arrival is `verified`, its `subject` is the did:key, and `arrival.passport` carries the registry's entry, so a policy can read `context.facts.arrival.passport.capabilities` or `.owner` (test `context.facts.arrival has passport` and `context.facts.arrival.passport.outcome == "verified"` first). The door needs no setup per agent and asks the registry nothing at request time. A passport is public, so on its own it is worth nothing: under another key's signature it is `wrong-sender`, and with no signature it is a claim, and the arrival is `claimed`. A request that presents a grant is judged by its grant; its passport is only recorded. The receipt names the agent as `observed`, as for any signature: a reader can check the recorded passport again under the registry's key, but not the request's signature. Revoking an agent in the registry stops new passports; the one the agent holds works until it expires, so `passportSeconds` on the registry is how long a revocation can take to reach the door.
79
+
76
80
  **Revoking a grant.** <a id="revoking-a-grant"></a>With `revokedGrants` in the config, a grant can be withdrawn before it expires: the file is the gateway's, a JSON array of grant digests, and `agent-custody revoke --config door.json --grant grant.json` appends one. The door re-reads the file when it changes and checks every grant against it after the signature and before the window and the scope, so a running door classifies the next arrival that carries the grant as `claimed` with `grant: "revoked"`, and the Cedar principal is not the agent. Revoking a grant revokes every grant delegated from it (`grantError` says "a grant above it in its chain has been revoked"). A file that is there and cannot be read stops the door from starting; one that becomes unreadable while it runs makes every grant `revoked` until it can be read, so a broken list never lets a grant through. A missing file is an empty list. Without `revokedGrants`, a grant stands until it expires, and `check` warns when the door trusts principals.
77
81
 
78
82
  <a id="challenging-a-human"></a>**Challenging a human.** The door builds no CAPTCHA. With `challenge` configured, a page in front of a protected route renders the provider's widget (Cloudflare Turnstile or hCaptcha) with `siteKey`, and sends the token the widget produced in the `challenge.header` header of its request. The door posts the token and the secret from `secretEnv` to the provider's `siteverify` endpoint, with a timeout, and records the answer as `challenge.outcome`. It adds the arrival's address as `remoteip` only with `trustProxy`, where that address is the client's; without it the socket's address may be a proxy's, and the provider would refuse a token the client solved. It never follows a redirect, which would resend the secret and the token elsewhere. To hCaptcha it also sends `siteKey` as `sitekey`: an hCaptcha secret belongs to the account, and without it a token solved on the account's easiest widget would pass on the hardest. A Turnstile secret belongs to one widget already. `success` alone does not pass: the token must have been issued on one of `hostnames`, and for `action` when one is set, or a token solved on another site that uses this site key, or for another widget, would count. At most `maxInFlight` checks wait on the provider at once; an arrival past that is `unavailable`. The token is stripped before the request is relayed, and neither the token nor the secret is recorded. A policy admits a person on a form route with
@@ -20,7 +20,7 @@ jobs:
20
20
  runs-on: ubuntu-latest
21
21
  steps:
22
22
  - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
23
- - uses: svayatta/agent-custody@<commit sha of the release> # 0.16.12
23
+ - uses: svayatta/agent-custody@<commit sha of the release> # 0.16.14
24
24
  with:
25
25
  path: .custody/receipts
26
26
  issuer-key: .custody/keys/agent.pub
@@ -37,7 +37,7 @@ Pin the action to the commit of a release, as you pin every other action. A movi
37
37
  | `principal-key` | the public key files of the principals whose grants a gateway receipt carries, one path on each line; SDK and Claude Code hook receipts need none | |
38
38
  | `log-url` | the URL of the log; the action fetches the log key from it (`verify --log-url`) | |
39
39
  | `log-id` | the id that every tree head must name (`verify --log-id`) | |
40
- | `version` | the `@agent-custody/receipts` version that `npx` runs | `0.16.12` |
40
+ | `version` | the `@agent-custody/receipts` version that `npx` runs | `0.16.14` |
41
41
  | `github-token` | a token that can write pull request comments; an empty value writes the job summary only | `github.token` |
42
42
  | `comment-author` | the login of the account that `github-token` posts as; the action edits only a comment from this account | `github-actions[bot]` |
43
43
 
package/docs/tutorials.md CHANGED
@@ -70,6 +70,10 @@ Suggested reading order is the numbering. Output lands in `examples-out/`, which
70
70
  | 59 | Demo 1, the refund (API leg): the door and the gateway together | [59-refund-demo.ts](../examples/59-refund-demo.ts) | a shop with the door in front of its refund API and two payment lanes through the gateway; a shopping agent with a passport is paid £25 once, even on retry; £80, and a forged passport, are refused at the door and never reach the shop; an agent with no passport goes to a person, who approves the exact refund with `agent-custody approvals approve`, and is then paid once; an auditor with public keys and a read-only view of Stripe verifies all ten receipts and finds the £10 refund made in Stripe directly; `bun run demo:refund` |
71
71
  | 60 | the door's behaviour and fingerprint signals, read by a policy as reasons to ask for a challenge | [60-door-behaviour-signals.ts](../examples/60-door-behaviour-signals.ts) | a door with `behaviour` and a challenge in front of a contact form; a browser's page load and form post carry no flag and pass; a tool's direct post is `directWrite`, and a script that states a browser has four flags, and each is refused with the rule's id and how to pass the challenge; a person whose address changed, and whose form page is on another host of the site, is flagged too, and passes with a challenge token; the site never receives the form report header; every receipt verified, with its flags |
72
72
  | 61 | the false-positive rate of each door flag, measured on a labelled set | [61-door-measure.ts](../examples/61-door-measure.ts) | the labelled set recorded from real clients is replayed through the door's signal functions; each flag's false-positive rate and detection rate are printed per session and per arrival with the 95% interval; no real browser is flagged, and the interval is still wide because the set is small |
73
+ | 62 | the agent registry: an organisation registers its agent, receives a passport, and a door that holds only the registry's key admits it | [62-agent-registry.ts](../examples/62-agent-registry.ts) | the portal runs the registry and publishes its key document; a company registers its shopping agent by the agent's own did:key with the capability `refunds`, and gets a passport; a shop's door trusts the registry's key and nothing else; the agent's refund, with its passport and signed by its key, is `verified` and the policy reads the capability; the same passport under another key's signature is `wrong-sender` and refused; after the company revokes the agent the registry issues it no passport; every receipt verified |
74
+ | 63 | linking a registered agent to its ERC-8004 identity, checked on chain by the registry and carried in its passport | [63-agent-registry-erc8004.ts](../examples/63-agent-registry-erc8004.ts) | a stand-in Base node and file host; the registry links the agent to token 7 because its registration file lists the agent's did:key, and records the owner and the block; the passport carries the link; a link to token 8, whose file names another key, is refused |
75
+ | 64 | admission lists: a site finds agents in the registry by capability, lists a partner by its registry entry and blocks another by its key, and its policy reads the lists | [64-admission-lists.ts](../examples/64-admission-lists.ts) | two companies register shopping agents with `refunds`; the shop's search finds both; its door trusts the registry's key and reads `admission.json`; Carted's agent is on `partners` and its refund is allowed; Grabby's agent is verified and on `blocked`, and its refund is refused; each receipt records the lists and their digest, and verifies |
76
+ | 65 | Demo 3, agent admitted: an agent-commerce company registers its agent and is admitted by a marketplace that had been blocking it | [65-agent-admitted-demo.ts](../examples/65-agent-admitted-demo.ts) | the marketplace's door admits only its partners; Carted's agent, with only a signature, is `claimed` and blocked; Carted registers it and gets a passport; with the passport it is `verified`, named, and owned, and still blocked; the marketplace searches the registry for `orders`, lists the agent by its registry entry, and the door reads the list on the next request; the order is placed once; the merchant verifies all three receipts with the door's key and reads who, whose, and what |
73
77
 
74
78
  ## How policies are defined, in one paragraph
75
79
 
package/docs/usage.md CHANGED
@@ -125,7 +125,7 @@ At startup the gateway fetches the agent's card from `<url>/.well-known/agent-ca
125
125
  "log": { "url": "https://log.example.com/", "tokenEnv": "AGENT_CUSTODY_LOG_TOKEN" }
126
126
  ```
127
127
 
128
- Exactly one of the two. The bearer token comes from the named environment variable, never from the file, and a missing variable fails at startup. Add `"hashOnly": true` for any log run by someone else: the gateway then sends only the leaf hash, sha256 of the receipt envelope with the RFC 6962 prefix, so the log commits to the receipt without ever holding it, and the receipts with their arguments and results stay in `receiptsDir`. The verifier does not change; it hashes the envelope itself. A log that serves several tenants is reached at `<url>/t/<tenant>/`, and each of its tree heads names its log, which a verifier checks with `--log-id`. With a remote log the tree head in each receipt is signed by the log's key, and a verifier must be given that key with `--log-key`. The gateway does not take the log's answer on trust either: the tree head in every append's answer must verify against the log's keys, name the expected log, match the proof's size, and the inclusion proof must place that very leaf under the signed root, all before a pre-committed call is forwarded and before any receipt is handed out; an answer that fails any of it is a refusal. `"keys": ["keys/log.pub"]` pins the log's public keys, `"logId"` the id its heads must carry; without `keys` the log's key document at `/.well-known/agent-custody-log.json` is fetched from the log itself once, on the first append, and pinned. That catches a log that turns dishonest later, not one that is dishonest from the start, so a gateway config with `precommit` and a remote log must list `keys`. When the log rotates its key, add the new public key to `keys`; a gateway that fetched the keys needs a restart. An append that gets no answer within `timeoutMs` (default 10000) counts as unreachable and is retried like a server error, so a log that accepts connections and never answers cannot hold a call forever. If the log does not take a receipt, the gateway keeps the signed receipt in `receipts/outbox/<receiptId>.json` and returns the real outcome of the call to the agent, with the receipt id and `_meta["agent-custody/log-pending"]: true`. The gateway appends the outbox at startup and every 30 seconds, and writes `receipts/<receiptId>.json` when the log takes the receipt. Until then no bundle exists, so no receipt that was never logged is handed out. The table [below](#when-the-log-fails) gives each case. For a tool named in `precommit` the order is reversed, below, and the action never happens. A fact lookup is different: it runs before the policy decides, because the policy decides on it, and only once the intercepted tool is in the grant's scope, so a fact tool must be a read. Naming a fact tool in `precommit` is refused at startup; `"*"` covers the tools the agent calls, not the gateway's own lookups. Every lookup is on the receipt with its arguments. The reference log server is `node src/cli.ts log --file log.jsonl --key keys/log.key --port 8787 --token-env AGENT_CUSTODY_LOG_TOKEN [--log-id <id>] [--tenants tenants.json]`. It serves `POST /append` with `{leaf}` or `{leafHash}` (token required when one is configured), `GET /root?size=N`, `GET /consistency?old=M&new=N`, and `GET /head`; [verification.md](verification.md) says what each proves. `--log-id` writes that id into every tree head. `--tenants` names a JSON file, `{ "acme": { "file": "acme.jsonl", "tokenEnv": "ACME_TOKEN", "logId": "acme-eu" } }`, and each tenant is its own log at `/t/acme/…` with its own token and id; the default log stays at the root paths. With `--hash-only` the server refuses `{leaf}` at append and accepts only `{leafHash}`, so a log run for other people never receives a receipt regardless of the client's configuration; the hosted deployment sets it. With `--db-env DATABASE_URL` the server keeps its logs in Postgres instead of files, and needs the `pg` package beside it: leaves as hashes in one table keyed by tenant, one writer per tenant enforced with an advisory lock so a second instance is safe, tenants and their tokens in tables of their own with tokens stored only as hashes, and rate limits per token (50 appends a second, burst 100, a 64 KB body cap; a refused append answers 429 with `retry-after`, and the gateway's sink retries a few times). Tenants are managed with `log-admin --db-env DATABASE_URL`: `tenant add <id> [--log-id <id>]` (both plain identifiers: letters, digits, `.`, `_`, `-`), `token add <tenant> --label <text>` (the token is printed once), `token revoke <tenant> <hash-prefix>`, `tenant disable <id>`, `tenant plan <id> <free|team|enterprise>`, and `import --file log.jsonl [--tenant default]` to bring an existing file log in as hashes. Every tenant is on a plan, `free` unless moved: free allows ten thousand appends a calendar month, team a million, enterprise has no allowance. An append past the allowance is refused with 429, the numbers, and a `retry-after` that reaches the start of next month; the gateway behind it then withholds pre-committed calls and financial operations, so a tenant out of quota never acts on those without evidence. Any other call is forwarded, and its receipt waits in the outbox ([below](#when-the-log-fails)). The tenant's own `GET /t/<name>/usage` reports the plan and quota beside the month's appends. The tenant portal, `agent-custody portal --db-env DATABASE_URL --secret-env PORTAL_SECRET --public-url <log url> [--checkpoints-url <url>] [--portal-url <url>] [--stripe-key-env NAME --stripe-webhook-env NAME --stripe-price-team <price id>] [--trust-proxy]`, is the self-serve front of the same tables: a team registers with an email, a password (scrypt), and a tenant id and gets the tenant and its first key shown once with the welcome sheet; the dashboard shows appends against the plan, the tree size and root, the latest checkpoint, the log's URLs, keys, and the audit rows; keys are minted and revoked there, recorded as `portal:<email>`; the export command is on the page; and with the three Stripe variables the team plan is bought through Stripe Checkout, the signed webhook moving the plan (`stripe:<event>` in the audit trail) and the customer portal handling cancellation. Sessions are a signed cookie, `SameSite=Strict`, and every write needs a JSON body: one over 64 KB is answered 413, one that is not JSON 400, and any other failure a plain 500 with the detail in the portal's log, never in the answer. Each member has a role (`owner`, `admin`, `reviewer`, `readonly`), an account can turn on TOTP MFA, and the operator can set up single sign-on through the tenant's own OIDC or SAML identity provider with `log-admin sso set`; the [hosted log reference](https://docs.agent-custody.dev/reference/hosted) lists the routes. SAML needs `@node-saml/node-saml` beside the CLI. The compose file runs it as the `portal` service at `PORTAL_HOST`. The root paths serve the tenant `default`, created on first start with `--log-id`, and `--token-env` still works for it. The key that signs tree heads can live in its own process: `agent-custody signer --key keys/log.key --port 8790 --token-env SIGNER_TOKEN` holds it and answers `POST /sign` with the shared secret and `GET /keys` to anyone; the log server then runs with `--signer-url http://signer:8790/ --signer-token-env SIGNER_TOKEN` instead of `--key`, and the process that faces the internet never holds the key. Either way the log serves its keys at `/.well-known/agent-custody-log.json`, current key first and retired keys (`--retired-key old.pub`) after it, so verifiers fetch and pin them with `verify --log-url` and `audit --log-url` rather than receiving a key file from the operator. With `--checkpoint-dir <dir>` the server publishes a signed checkpoint, every `--checkpoint-every` seconds (default 300), for each log whose tree has grown, and every `--checkpoint-heartbeat` seconds (default 21600, six hours) for a log that has not, so a quiet log's latest checkpoint is never more than six hours old and the monitor can tell quiet from stalled, as `<dir>/<tenant>/<treeSize>.json` and `latest.json`, and with a database also as rows; `GET /checkpoints?since=<size>` and `GET /t/<tenant>/checkpoints` list them. Serve the directory read-only from a second host, so the record of what the log signed does not depend on the log's API being up; a verifier who kept an earlier head audits against a later checkpoint with `audit --older <bundle> --newer <checkpoint> --log-url <url>`. With `--admin-token-env ADMIN_TOKEN` (Postgres only) the server also serves the operator's page at `/admin` and its API under `/admin/`: list and create tenants, mint a token that is shown once beside the tenant's welcome sheet, revoke tokens, disable tenants. Everything under `/admin`, the page included, needs the admin token: the browser asks for it (any user name, the token as the password) and an API client sends it as a bearer; a handful of wrong attempts from one address are throttled for a minute. Every change made there or with `log-admin` is recorded: who (the name entered at the browser prompt and the address, `bearer` for an API client, or the user and host for the command line), what (`tenant.add`, `tenant.disable`, `token.add`, `token.revoke`), which tenant, and the detail, never the token itself; the page shows it under Activity, `GET /admin/audit?tenant=&limit=` and `log-admin audit` list it, and a tenant reads their own rows at `GET /t/<name>/audit` with their token. Nothing else is stored by the page. Behind a reverse proxy, start the server with `--trust-proxy` so those per-address limits key on `X-Forwarded-For` instead of on the proxy's own address, and only there, since the header is otherwise the client's to forge. `--public-url` and `--checkpoints-url` fill the sheet in. The witness closes the last gap: `agent-custody witness --key witness.key --log-url <url> --checkpoints-url <url> --out <dir> [--tenant <name>]...` runs on a machine the log's operator does not control, fetches each watched log's latest checkpoint, verifies it against the log's published keys, proves with the log's consistency proof that it extends the last head the witness signed, and countersigns it into `<dir>/<tenant>/<size>.json` and `latest.json`; a checkpoint that does not extend, or a second history at the same size, gets `ALARM.json` instead. Its key document is `<dir>/.well-known/agent-custody-witness.json`. Serve `<dir>` from the witness's own host; verifiers add `--witness-url` (or `--witness-key`) to `audit`, and the newer head must then carry the witness's signature. Two more things an operator needs. `agent-custody log-check --log-url <url> --checkpoints-url <url> [--witness-url <url>] [--tenant <name>]... [--max-lag <seconds>]` is the outside monitor: it verifies the head against the published keys, that the latest checkpoint verifies and keeps up with the head, that the head extends the checkpoint, and, with a witness, that the witness has countersigned, keeps up, and has raised no alarm; it exits 1 on any failure, so cron or a scheduled workflow on a machine that is not the log's turns it into an alert. `GET /health` on the server is the liveness check for a load balancer. And `GET /admin/usage?month=YYYY-MM`, on the admin page and as `/admin/usage.csv`, is the metering: appends per tenant for the month, leaves in total, live tokens, the numbers any invoice rests on. A tenant needs none of that to leave with their evidence: `agent-custody log-export --log-url <url> --tenant <name> --token-env AGENT_CUSTODY_LOG_TOKEN --out <dir>` fetches, with their own token, every leaf hash (`GET /t/<name>/leaves?since=&limit=`, pages of up to ten thousand), the signed head, the published keys, the signed checkpoints, their own usage (`GET /t/<name>/usage?month=`), and the administrative actions on their tenant (`GET /t/<name>/audit`, into `audit.json`), checks that the head and every checkpoint verify against the keys and that the leaves fetched hash to their roots, and writes `log.jsonl` in the format `verify --log` and `audit --log` read, so the export verifies receipts with no server at all. It exits 1 and says what did not add up if anything does not. Both routes answer only to that tenant's token. [deploy/](../../deploy/README.md) runs the server, the signer, Postgres, and the checkpoints host as containers, and [deploy/witness/](../../deploy/witness/) the witness.
128
+ Exactly one of the two. The bearer token comes from the named environment variable, never from the file, and a missing variable fails at startup. Add `"hashOnly": true` for any log run by someone else: the gateway then sends only the leaf hash, sha256 of the receipt envelope with the RFC 6962 prefix, so the log commits to the receipt without ever holding it, and the receipts with their arguments and results stay in `receiptsDir`. The verifier does not change; it hashes the envelope itself. A log that serves several tenants is reached at `<url>/t/<tenant>/`, and each of its tree heads names its log, which a verifier checks with `--log-id`. With a remote log the tree head in each receipt is signed by the log's key, and a verifier must be given that key with `--log-key`. The gateway does not take the log's answer on trust either: the tree head in every append's answer must verify against the log's keys, name the expected log, match the proof's size, and the inclusion proof must place that very leaf under the signed root, all before a pre-committed call is forwarded and before any receipt is handed out; an answer that fails any of it is a refusal. `"keys": ["keys/log.pub"]` pins the log's public keys, `"logId"` the id its heads must carry; without `keys` the log's key document at `/.well-known/agent-custody-log.json` is fetched from the log itself once, on the first append, and pinned. That catches a log that turns dishonest later, not one that is dishonest from the start, so a gateway config with `precommit` and a remote log must list `keys`. When the log rotates its key, add the new public key to `keys`; a gateway that fetched the keys needs a restart. An append that gets no answer within `timeoutMs` (default 10000) counts as unreachable and is retried like a server error, so a log that accepts connections and never answers cannot hold a call forever. If the log does not take a receipt, the gateway keeps the signed receipt in `receipts/outbox/<receiptId>.json` and returns the real outcome of the call to the agent, with the receipt id and `_meta["agent-custody/log-pending"]: true`. The gateway appends the outbox at startup and every 30 seconds, and writes `receipts/<receiptId>.json` when the log takes the receipt. Until then no bundle exists, so no receipt that was never logged is handed out. The table [below](#when-the-log-fails) gives each case. For a tool named in `precommit` the order is reversed, below, and the action never happens. A fact lookup is different: it runs before the policy decides, because the policy decides on it, and only once the intercepted tool is in the grant's scope, so a fact tool must be a read. Naming a fact tool in `precommit` is refused at startup; `"*"` covers the tools the agent calls, not the gateway's own lookups. Every lookup is on the receipt with its arguments. The reference log server is `node src/cli.ts log --file log.jsonl --key keys/log.key --port 8787 --token-env AGENT_CUSTODY_LOG_TOKEN [--log-id <id>] [--tenants tenants.json]`. It serves `POST /append` with `{leaf}` or `{leafHash}` (token required when one is configured), `GET /root?size=N`, `GET /consistency?old=M&new=N`, and `GET /head`; [verification.md](verification.md) says what each proves. `--log-id` writes that id into every tree head. `--tenants` names a JSON file, `{ "acme": { "file": "acme.jsonl", "tokenEnv": "ACME_TOKEN", "logId": "acme-eu" } }`, and each tenant is its own log at `/t/acme/…` with its own token and id; the default log stays at the root paths. With `--hash-only` the server refuses `{leaf}` at append and accepts only `{leafHash}`, so a log run for other people never receives a receipt regardless of the client's configuration; the hosted deployment sets it. With `--db-env DATABASE_URL` the server keeps its logs in Postgres instead of files, and needs the `pg` package beside it: leaves as hashes in one table keyed by tenant, one writer per tenant enforced with an advisory lock so a second instance is safe, tenants and their tokens in tables of their own with tokens stored only as hashes, and rate limits per token (50 appends a second, burst 100, a 64 KB body cap; a refused append answers 429 with `retry-after`, and the gateway's sink retries a few times). Tenants are managed with `log-admin --db-env DATABASE_URL`: `tenant add <id> [--log-id <id>]` (both plain identifiers: letters, digits, `.`, `_`, `-`), `token add <tenant> --label <text>` (the token is printed once), `token revoke <tenant> <hash-prefix>`, `tenant disable <id>`, `tenant plan <id> <free|team|enterprise>`, and `import --file log.jsonl [--tenant default]` to bring an existing file log in as hashes. Every tenant is on a plan, `free` unless moved: free allows ten thousand appends a calendar month, team a million, enterprise has no allowance. An append past the allowance is refused with 429, the numbers, and a `retry-after` that reaches the start of next month; the gateway behind it then withholds pre-committed calls and financial operations, so a tenant out of quota never acts on those without evidence. Any other call is forwarded, and its receipt waits in the outbox ([below](#when-the-log-fails)). The tenant's own `GET /t/<name>/usage` reports the plan and quota beside the month's appends. The tenant portal, `agent-custody portal --db-env DATABASE_URL --secret-env PORTAL_SECRET --public-url <log url> [--checkpoints-url <url>] [--portal-url <url>] [--stripe-key-env NAME --stripe-webhook-env NAME --stripe-price-team <price id>] [--trust-proxy]`, is the self-serve front of the same tables: a team registers with an email, a password (scrypt), and a tenant id and gets the tenant and its first key shown once with the welcome sheet; the dashboard shows appends against the plan, the tree size and root, the latest checkpoint, the log's URLs, keys, and the audit rows; keys are minted and revoked there, recorded as `portal:<email>`; the export command is on the page; and with the three Stripe variables the team plan is bought through Stripe Checkout, the signed webhook moving the plan (`stripe:<event>` in the audit trail) and the customer portal handling cancellation. Sessions are a signed cookie, `SameSite=Strict`, and every write needs a JSON body: one over 64 KB is answered 413, one that is not JSON 400, and any other failure a plain 500 with the detail in the portal's log, never in the answer. Each member has a role (`owner`, `admin`, `reviewer`, `readonly`), an account can turn on TOTP MFA, and the operator can set up single sign-on through the tenant's own OIDC or SAML identity provider with `log-admin sso set`; the [hosted log reference](https://docs.agent-custody.dev/reference/hosted) lists the routes. With `--registry-key-env NAME` (or `--registry-signer-url`) and `--portal-url`, the portal also runs the [agent registry](agent-registry.md): a tenant registers its agents by their did:keys, and the portal signs their passports. SAML needs `@node-saml/node-saml` beside the CLI. The compose file runs it as the `portal` service at `PORTAL_HOST`. The root paths serve the tenant `default`, created on first start with `--log-id`, and `--token-env` still works for it. The key that signs tree heads can live in its own process: `agent-custody signer --key keys/log.key --port 8790 --token-env SIGNER_TOKEN` holds it and answers `POST /sign` with the shared secret and `GET /keys` to anyone; the log server then runs with `--signer-url http://signer:8790/ --signer-token-env SIGNER_TOKEN` instead of `--key`, and the process that faces the internet never holds the key. Either way the log serves its keys at `/.well-known/agent-custody-log.json`, current key first and retired keys (`--retired-key old.pub`) after it, so verifiers fetch and pin them with `verify --log-url` and `audit --log-url` rather than receiving a key file from the operator. With `--checkpoint-dir <dir>` the server publishes a signed checkpoint, every `--checkpoint-every` seconds (default 300), for each log whose tree has grown, and every `--checkpoint-heartbeat` seconds (default 21600, six hours) for a log that has not, so a quiet log's latest checkpoint is never more than six hours old and the monitor can tell quiet from stalled, as `<dir>/<tenant>/<treeSize>.json` and `latest.json`, and with a database also as rows; `GET /checkpoints?since=<size>` and `GET /t/<tenant>/checkpoints` list them. Serve the directory read-only from a second host, so the record of what the log signed does not depend on the log's API being up; a verifier who kept an earlier head audits against a later checkpoint with `audit --older <bundle> --newer <checkpoint> --log-url <url>`. With `--admin-token-env ADMIN_TOKEN` (Postgres only) the server also serves the operator's page at `/admin` and its API under `/admin/`: list and create tenants, mint a token that is shown once beside the tenant's welcome sheet, revoke tokens, disable tenants. Everything under `/admin`, the page included, needs the admin token: the browser asks for it (any user name, the token as the password) and an API client sends it as a bearer; a handful of wrong attempts from one address are throttled for a minute. Every change made there or with `log-admin` is recorded: who (the name entered at the browser prompt and the address, `bearer` for an API client, or the user and host for the command line), what (`tenant.add`, `tenant.disable`, `token.add`, `token.revoke`), which tenant, and the detail, never the token itself; the page shows it under Activity, `GET /admin/audit?tenant=&limit=` and `log-admin audit` list it, and a tenant reads their own rows at `GET /t/<name>/audit` with their token. Nothing else is stored by the page. Behind a reverse proxy, start the server with `--trust-proxy` so those per-address limits key on `X-Forwarded-For` instead of on the proxy's own address, and only there, since the header is otherwise the client's to forge. `--public-url` and `--checkpoints-url` fill the sheet in. The witness closes the last gap: `agent-custody witness --key witness.key --log-url <url> --checkpoints-url <url> --out <dir> [--tenant <name>]...` runs on a machine the log's operator does not control, fetches each watched log's latest checkpoint, verifies it against the log's published keys, proves with the log's consistency proof that it extends the last head the witness signed, and countersigns it into `<dir>/<tenant>/<size>.json` and `latest.json`; a checkpoint that does not extend, or a second history at the same size, gets `ALARM.json` instead. Its key document is `<dir>/.well-known/agent-custody-witness.json`. Serve `<dir>` from the witness's own host; verifiers add `--witness-url` (or `--witness-key`) to `audit`, and the newer head must then carry the witness's signature. Two more things an operator needs. `agent-custody log-check --log-url <url> --checkpoints-url <url> [--witness-url <url>] [--tenant <name>]... [--max-lag <seconds>]` is the outside monitor: it verifies the head against the published keys, that the latest checkpoint verifies and keeps up with the head, that the head extends the checkpoint, and, with a witness, that the witness has countersigned, keeps up, and has raised no alarm; it exits 1 on any failure, so cron or a scheduled workflow on a machine that is not the log's turns it into an alert. `GET /health` on the server is the liveness check for a load balancer. And `GET /admin/usage?month=YYYY-MM`, on the admin page and as `/admin/usage.csv`, is the metering: appends per tenant for the month, leaves in total, live tokens, the numbers any invoice rests on. A tenant needs none of that to leave with their evidence: `agent-custody log-export --log-url <url> --tenant <name> --token-env AGENT_CUSTODY_LOG_TOKEN --out <dir>` fetches, with their own token, every leaf hash (`GET /t/<name>/leaves?since=&limit=`, pages of up to ten thousand), the signed head, the published keys, the signed checkpoints, their own usage (`GET /t/<name>/usage?month=`), and the administrative actions on their tenant (`GET /t/<name>/audit`, into `audit.json`), checks that the head and every checkpoint verify against the keys and that the leaves fetched hash to their roots, and writes `log.jsonl` in the format `verify --log` and `audit --log` read, so the export verifies receipts with no server at all. It exits 1 and says what did not add up if anything does not. Both routes answer only to that tenant's token. [deploy/](../../deploy/README.md) runs the server, the signer, Postgres, and the checkpoints host as containers, and [deploy/witness/](../../deploy/witness/) the witness.
129
129
 
130
130
  `otel`, optional in both the gateway and SDK configs, sends every receipt to the collector you already run as one span over OTLP/HTTP, after the receipt is issued: `"otel": { "url": "http://localhost:4318", "headersEnv": { "x-api-key": "OTEL_KEY" }, "serviceName": "support-agents" }`. The span's trace id is the receipt id, its attributes carry the tool, agent, principal, execution status, policy decision, and log position, and its status is an error only when the upstream failed or errored, since a denial is the policy working. A door receipt records an inbound request, so its span kind is `SERVER`; every other issuer's span is `CLIENT`. Export is best effort: a collector that is down or refuses costs a line on stderr, never a receipt. Tutorial 18 shows it against a stand-in collector.
131
131
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agent-custody/receipts",
3
- "version": "0.16.12",
3
+ "version": "0.16.14",
4
4
  "mcpName": "io.github.svayatta/agent-custody",
5
5
  "description": "Proof of what your AI agents did. Give your agents real power, without losing control of them: signed, verifiable receipts for tool calls, an MCP gateway with Cedar or Rego policy, and a Merkle transparency log.",
6
6
  "license": "Apache-2.0",
@@ -71,6 +71,7 @@
71
71
  "coverage": "vitest run --coverage.enabled",
72
72
  "demo": "tsx scripts/demo.ts",
73
73
  "demo:refund": "node examples/59-refund-demo.ts",
74
+ "demo:admitted": "node examples/65-agent-admitted-demo.ts",
74
75
  "vectors": "tsx scripts/vectors.ts",
75
76
  "bench": "node scripts/hot-path-bench.ts"
76
77
  },