@agent-custody/receipts 0.13.0 → 0.15.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (58) hide show
  1. package/README.md +46 -28
  2. package/dist/check.d.ts +10 -0
  3. package/dist/check.js +179 -3
  4. package/dist/claude-init.d.ts +46 -0
  5. package/dist/claude-init.js +208 -0
  6. package/dist/cli.js +126 -11
  7. package/dist/config.d.ts +128 -1
  8. package/dist/config.js +92 -3
  9. package/dist/console.js +16 -7
  10. package/dist/deny-report.d.ts +30 -0
  11. package/dist/deny-report.js +106 -0
  12. package/dist/door.d.ts +203 -0
  13. package/dist/door.js +712 -0
  14. package/dist/export.d.ts +39 -0
  15. package/dist/export.js +95 -0
  16. package/dist/gateway.js +53 -21
  17. package/dist/index.d.ts +8 -0
  18. package/dist/index.js +7 -0
  19. package/dist/issue.js +5 -65
  20. package/dist/lock.d.ts +12 -0
  21. package/dist/lock.js +124 -0
  22. package/dist/log-admin.js +3 -3
  23. package/dist/log.d.ts +20 -3
  24. package/dist/log.js +117 -24
  25. package/dist/opa-server.d.ts +34 -0
  26. package/dist/opa-server.js +93 -0
  27. package/dist/policy-rego.d.ts +30 -0
  28. package/dist/policy-rego.js +114 -0
  29. package/dist/policy.d.ts +6 -0
  30. package/dist/policy.js +17 -0
  31. package/dist/pr-summary.d.ts +25 -0
  32. package/dist/pr-summary.js +87 -0
  33. package/dist/receipt.d.ts +3 -1
  34. package/dist/retention.d.ts +1 -1
  35. package/dist/retention.js +14 -4
  36. package/dist/sdk/claude.js +18 -2
  37. package/dist/sdk/index.d.ts +2 -0
  38. package/dist/sdk/index.js +11 -2
  39. package/dist/simulate.d.ts +3 -1
  40. package/dist/simulate.js +15 -7
  41. package/dist/verify.js +6 -3
  42. package/dist/witness.js +3 -3
  43. package/docs/compliance.md +117 -7
  44. package/docs/configuration.md +3 -3
  45. package/docs/door-signals.md +66 -0
  46. package/docs/door.md +168 -0
  47. package/docs/github-action.md +164 -0
  48. package/docs/policies.md +124 -1
  49. package/docs/sdk.md +99 -1
  50. package/docs/tutorials.md +5 -0
  51. package/docs/usage.md +3 -3
  52. package/docs/verification.md +9 -2
  53. package/package.json +16 -14
  54. package/templates/claude-code.cedar +373 -0
  55. package/vectors/audit.json +27 -27
  56. package/vectors/canonical.json +5 -5
  57. package/vectors/merkle.json +123 -0
  58. package/vectors/receipts.json +1258 -1005
package/docs/door.md ADDED
@@ -0,0 +1,168 @@
1
+ # The door: a receipted reverse proxy in front of your own site or API
2
+
3
+ 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"`.
4
+
5
+ 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. Read [what the door knows](#what-the-door-knows-about-an-arrival) before writing a policy.
6
+
7
+ ```bash
8
+ agent-custody keygen --dir keys --name door
9
+ agent-custody check --config door.json
10
+ agent-custody door --config door.json --port 8780
11
+ ```
12
+
13
+ ## The config file
14
+
15
+ `door.json`, paths relative to the file. Loaded with `loadDoorConfig(path)`.
16
+
17
+ ```json
18
+ {
19
+ "identity": { "keyFile": "keys/door.key" },
20
+ "origin": { "url": "http://127.0.0.1:3000", "timeoutMs": 30000 },
21
+ "routes": [
22
+ { "name": "catalogue", "methods": ["GET"], "path": "/catalogue/*" },
23
+ { "name": "refund", "methods": ["POST"], "path": "/refunds" },
24
+ { "name": "api", "path": "/api/*" }
25
+ ],
26
+ "unmatchedRoute": "other",
27
+ "trustedPrincipalKeys": ["keys/principal.pub"],
28
+ "policyFile": "policy.cedar",
29
+ "receiptsDir": "receipts",
30
+ "logFile": "log.jsonl"
31
+ }
32
+ ```
33
+
34
+ | field | meaning |
35
+ | --- | --- |
36
+ | `identity.keyFile` | the door's Ed25519 key; signs every receipt. From `agent-custody keygen` |
37
+ | `origin.url` | where allowed arrivals are relayed: the site or API behind the door. `headers` and `headerEnv` add headers to every relayed request, the latter from the environment, so the origin can require a secret only the door holds. `timeoutMs` bounds one relayed request, default 30 s. A path in the URL (`https://host/api/v1`) is kept: the arrival's path goes under it, and a redirect from the origin to a place under it comes back as a door path |
38
+ | `routes` | what the policy sees as the action. `path` is exact (`/refunds`), a prefix (`/api/*`), or `*`; `methods` narrows it, default every method. The first route that matches wins; an arrival no route matches is the action `unmatchedRoute`, default `other`. The match reads the path as the origin will: percent-decoded once, so `/%61dmin` falls under `/admin/*`, and with empty segments merged, so `//admin/users` and `/admin//users` fall under it too (nginx, Apache, and many frameworks merge them). A trailing slash matches as none: `/refunds/` falls under `/refunds`. The origin is sent that merged, decoded form, trailing slash kept, so the door and the origin read one path. A path with a segment that does not decode, or decodes to a slash or a backslash, falls under `unmatchedRoute` and is never relayed |
39
+ | `trustedPrincipalKeys` | public keys of principals whose signed grants the door accepts as a passport. Without any, no arrival can be `verified` |
40
+ | `policyFile` | the Cedar policy, re-read when the file changes; one that does not parse is refused and the policy in force stays |
41
+ | `mode` | `enforce` (default) refuses what the policy denies. `observe` relays everything and records the decision with `enforced: false` |
42
+ | `trustProxy` | behind one reverse proxy you run: the arrival's address is the last in `X-Forwarded-For`, the one your proxy appended; everything before it is what the client sent. The proxy's `X-Forwarded-For`, `-Proto`, and `-Host` are kept on the relay, with the door's own socket address appended, and the other client-address headers (`Forwarded`, `X-Real-IP`, `True-Client-IP`, `CF-Connecting-IP`, every `X-Forwarded-*`) are relayed as the proxy sent them. Without `trustProxy` the client wrote all of these: the door drops them and sets `X-Forwarded-For`, `-Host`, `-Proto`, and `X-Real-IP` itself |
43
+ | `maxBodyBytes` | the largest request body the door relays; a larger one gets 413 and a `withheld` receipt once the policy has allowed it. Default 1 MiB |
44
+ | `maxResponseBytes` | the largest origin response the door relays; see [what the arrival gets back](#what-the-arrival-gets-back). Default 32 MiB |
45
+ | `maxInFlight` | arrivals handled at once. Each holds its body and the origin's answer in memory until it is answered, so this bounds the door's memory at about `maxInFlight × (maxBodyBytes + maxResponseBytes)`. Past it the next arrival gets 503 with `Retry-After: 1` before its body is read: it is not decided, relayed, or receipted. Default 256 |
46
+ | `precommit` | route names whose arrivals are committed to the log before they are relayed whatever their method, or `["*"]`. Every arrival whose method is not GET, HEAD, or OPTIONS is committed regardless; see [before the origin hears of it](#before-the-origin-hears-of-it). Default `[]` |
47
+ | `challenge` | the human branch: `{ provider: "turnstile" or "hcaptcha", siteKey, secretEnv, hostnames, action?, header?, timeoutMs?, maxInFlight? }`. `hostnames` lists the hosts of the pages that render the widget, `action` (Turnstile only) the widget's action, and `maxInFlight` (default 64) how many checks may wait on the provider at once. A token an arrival sends in `header` (default `x-agent-custody-challenge`) is verified with the provider, and the outcome is the arrival's `challenge` signal; see [challenging a human](#challenging-a-human). The secret comes from the environment variable, read at startup; missing is a startup error |
48
+ | `receiptsDir`, `logFile` or `log`, `otel`, `splunk`, `capture`, `captureKeyEnv` | as for the [gateway](configuration.md): where receipts and the log go, exporters, and private evidence per route. A remote `log` needs `log.keys`, because its answer is checked before a request is relayed. Unlike the gateway, the door withholds by default: see [what a receipt records](#what-a-receipt-records-of-the-query-and-the-body) |
49
+
50
+ `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 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.
51
+
52
+ ## What the door knows about an arrival
53
+
54
+ The door records one fact for every arrival, `arrival`, observed by the door itself, and the policy reads it as `context.facts.arrival`:
55
+
56
+ | field | values | meaning |
57
+ | --- | --- | --- |
58
+ | `class` | `verified`, `claimed`, `unknown` | `verified`: a grant signed by a trusted principal, inside its window, naming this route among its scopes. `claimed`: something was asserted that the door could not accept: a grant from a stranger, an expired one, one for other routes, a declared agent name, or an HTTP signature header. `unknown`: nothing was presented |
59
+ | `subject` | string | the agent named in a verified grant; else the declared name or the agent a rejected grant named; else `unknown`. Only a verified subject reaches the Cedar `principal` |
60
+ | `grant` | `verified`, `out-of-scope`, `invalid`, `absent` | what became of the grant header, with `grantError` when it was not accepted |
61
+ | `signature` | boolean | an RFC 9421 `Signature-Input` header was present. **Not checked yet.** It is a claim |
62
+ | `declared` | string | the `x-agent-custody-agent` header, when sent. A claim |
63
+ | `remote` | string | the arrival's address |
64
+ | `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 |
65
+ | `rate` | `{ by, burst, minute }` | arrivals from the same source in the last 10 and 60 seconds, this one included, whatever was decided about them, counted by this door process alone. `by` is `agent` for a verified arrival (counted by the agent's name across addresses) or `remote` (by address). A pace, not a verdict |
66
+ | `method`, `path`, `route` | strings | what arrived, and the route it fell under |
67
+
68
+ [Door signals](door-signals.md) says, for each field, what it establishes and what it does not, and how a policy should read it.
69
+
70
+ There is no `human` class. The door cannot tell a person from a program that presents nothing, and it does not pretend to. With `challenge` configured, a policy can require a passed challenge on a route instead; without it, a policy that lets `unknown` through on a route is letting everything through on that route, and should say so.
71
+
72
+ **Presenting a passport.** An agent presents its grant exactly as it does to the HTTP gateway: the DSSE envelope as base64url in `Authorization: Bearer <value>` or in `X-Agent-Custody-Grant`. The scopes of the grant are route names. A grant that travelled in `Authorization` is stripped before the request is relayed, so the origin never sees it; one in the custom header is stripped too. The door's own headers are added to the relayed request: `X-Agent-Custody-Receipt` (the receipt id), `X-Agent-Custody-Class`, and `X-Forwarded-For`, `-Host`, `-Proto`, with `X-Real-IP` when `trustProxy` is off.
73
+
74
+ **A verified arrival is bearer-grade.** The door checks the grant's signature, window, and scope. It does not check that the sender holds the agent's key: there is no request signature yet (RFC 9421 is [future work](#what-it-does-not-do-yet)). Anyone who holds the grant's bytes is that agent until the grant expires, and every verified receipt carries the grant in `delegation`, so a person who can read one receipt can replay its grant. Issue door grants with short lifetimes (minutes, not days), scope them to the routes they need, bound what a route allows per call in the policy, and treat receipt files and logs as holding live credentials until those grants expire.
75
+
76
+ **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
77
+
78
+ ```cedar
79
+ permit(principal, action == Action::"refund", resource)
80
+ when { context.facts.arrival.challenge.outcome == "passed" };
81
+ ```
82
+
83
+ and a refused arrival that has not passed is told how in the 403 body: `challenge: { provider, siteKey, header }`, so a page can render the widget and try again.
84
+
85
+ **A token serves one request.** Turnstile and hCaptcha refuse a token they have seen (`timeout-or-duplicate`, `already-seen-response`), and the door keeps no pass between requests: it does not set a cookie or remember an address. So the page must take a new token for every request it sends to a challenged route, and for every retry: call `turnstile.reset()` or `hcaptcha.reset()` after each request, and wait for the new token before the next. The door checks the token before it reads the body, so a request refused for its size (413), its path (400), or by the policy has used its token too. A second request that sends the same token is `failed`, and the person sees another 403. The outcome is a signal, not a class: a `verified` agent that also passes a challenge is still the agent its grant names, and an `unknown` arrival that passes is still `unknown`, with `challenge.outcome: "passed"` beside it. What the provider's pass means, and what it does not, is in [door signals](door-signals.md). Passkeys are not a provider here: a passkey proves possession of a credential the site registered, which is a login, not a challenge, and belongs to the origin.
86
+
87
+ ## How an arrival becomes a Cedar request
88
+
89
+ | Cedar slot | value |
90
+ | --- | --- |
91
+ | `principal` | `Agent::"<agent>"` for the agent a verified grant names; `Agent::"unknown"` for every other arrival. A declared name and the agent a rejected grant names stay in the arrival fact: a permit on `principal == Agent::"shopping-agent"` cannot be satisfied by sending a header |
92
+ | `action` | `Action::"<route>"` |
93
+ | `resource` | `Tool::"<route>"` |
94
+ | `context.args` | `{ method, path, query, headers, body?, bodyBytes, bodyDigest }`. `query` holds every parameter by name, as own properties, so `?constructor=x` is a parameter. `headers` carries `user-agent`, `content-type`, `accept`, and `host` only. `body` is present for a JSON body of at most 64 KiB; every body the door read is recorded by `bodyDigest` (sha256 of the raw bytes) and `bodyBytes`. A body above `maxBodyBytes` is dropped as it passes the limit and recorded as `bodyBytes` read so far and `bodyOversized: true`, with no digest and no `body`. The policy reads a copy that Cedar accepts: Cedar has no `null` and no non-integer number, and refuses the whole request on either, so in the copy a `null` member is dropped and a number that is not a safe integer becomes its string (`9.99` becomes `"9.99"`). A rule that compares such a value as a number then errors, and that rule's deny is the answer. The receipt keeps the body as it arrived. **Provenance: claimed** |
95
+ | `context.facts.arrival` | the fact above. **Provenance: observed** |
96
+ | `context.grant` | `{ principal, scopes }`, present only when the arrival is `verified`. **Provenance: attested** |
97
+
98
+ Every rule the gateway's policies obey applies: default deny, `forbid` wins, an evaluation error is a deny, the policy digest is in the receipt. A policy for the shop in the tutorial:
99
+
100
+ ```cedar
101
+ // The catalogue is public: humans, agents, anyone.
102
+ permit(principal, action == Action::"catalogue", resource);
103
+
104
+ // Refunds: a verified agent, in its grant's scope, for a positive amount of at most £50.
105
+ permit(principal, action == Action::"refund", resource)
106
+ when {
107
+ context.facts.arrival.class == "verified" &&
108
+ context.args.body.amount > 0 &&
109
+ context.args.body.amount <= 5000
110
+ };
111
+
112
+ // Everything else on the API is for verified agents.
113
+ permit(principal, action == Action::"api", resource)
114
+ when { context.facts.arrival.class == "verified" };
115
+ ```
116
+
117
+ A refund without a JSON body, with no `amount`, or with an `amount` that is not an integer (`45.5` reaches the policy as `"45.5"`), is an evaluation error and a deny. That is the behaviour you want in front of a payments route. The bound has two ends on purpose: `amount <= 5000` alone admits `{"amount": -1}`, and the door relays the body as it came.
118
+
119
+ A permit that names an agent, `permit(principal == Agent::"shopping-agent", action == Action::"refund", resource)`, admits only an arrival whose verified grant names that agent, since nothing else reaches the principal slot. `agent-custody check` still warns on such a permit when it does not also require `context.facts.arrival.class == "verified"`: the same text in a gateway policy reads differently, and the condition says what the permit relies on.
120
+
121
+ ## Before the origin hears of it
122
+
123
+ A request that can change something at the origin, any method but GET, HEAD, and OPTIONS, and any arrival at a route named in `precommit`, is committed to the log before it is relayed, exactly as the gateway's precommit does for a consequential tool call: the door signs an authorization statement (the receipt without its outcome), appends it, writes it as `receipts/<receiptId>.authorization.json`, and only then relays. The receipt embeds it as `authorization`, and the verifier checks that it names this receipt and sits in the log before it. A door that dies between the relay and the receipt leaves the authorization behind, so the side effect has a record and a retry can be told from a first attempt. If the log will not take the authorization, the request is not relayed: 503 and a `withheld` receipt. In observe mode it is relayed and the missing authorization is printed.
124
+
125
+ ## What the arrival gets back
126
+
127
+ | the door's decision | HTTP | body | receipt `execution.status` |
128
+ | --- | --- | --- | --- |
129
+ | policy allows, origin answered | the origin's status and body, plus the door's headers | the origin's | `executed`, or `failed` when the origin answered 5xx |
130
+ | policy denies, whatever the body's size | 403 | `{ error, reason, receipt }`, plus `challenge: { provider, siteKey, header }` when a challenge is configured and this arrival has not passed it | `denied` |
131
+ | origin unreachable: the connection was refused or the host did not resolve | 502 | `{ error, detail, receipt }`, "the origin could not be reached" | `error`; the request never left the door |
132
+ | the request left, and its answer did not arrive: a timeout, a reset, or a body that stopped after the headers | 504 | `{ error, detail, receipt }`, "the origin may have acted on the request ... Do not retry" | `error`, and `execution.error` says the origin may have acted. Find out from the origin before retrying a refund |
133
+ | policy allows, body above `maxBodyBytes` | 413 | `{ error, reason, receipt }` | `withheld`; nothing was relayed |
134
+ | policy allows, the log refused the authorization | 503 | `{ error, reason, receipt }` | `withheld`; nothing was relayed |
135
+ | policy allows, the path does not decode cleanly | 400 | `{ error, reason, receipt }` | `withheld`; nothing was relayed |
136
+ | policy allows, the origin's response above `maxResponseBytes` | 502 | `{ error, receipt }`, and "do not retry" | `executed` or `failed`: the origin acted; `result` carries the status and `bodyOversized: true`, no digest |
137
+ | the receipt could not be written | 500 | `{ error, outcome, receipt }` | none on disk; `outcome` says whether the origin acted, so that a refund is not retried on the strength of a 500 |
138
+ | more than `maxInFlight` arrivals at once | 503, `Retry-After: 1` | `{ error }` | none: the arrival was not read, decided, or relayed |
139
+
140
+ A redirect from the origin to its own host, on any scheme or port, is rewritten to a path, so the client's next request comes back through the door and is classified again. A path under the origin's path loses that prefix; any other path, including one that `..` takes out of it, is kept as it is. A redirect to another host is relayed as sent. Every `Set-Cookie` the origin sent reaches the client. An `Expect: 100-continue` is the client's conversation with the door, which answers it; the origin does not see the header.
141
+
142
+ Every answer carries `X-Agent-Custody-Receipt` and `X-Agent-Custody-Class`. When the log did not take the receipt, it waits in `receipts/outbox/` and the answer also carries `X-Agent-Custody-Log-Pending: true`; a serving door appends the outbox every 30 seconds, as the gateway does.
143
+
144
+ `GET /.well-known/agent-custody-door` answers the door's key id, the policy digest in force, the version, and the count of pending receipts.
145
+
146
+ ## What a receipt records of the query and the body
147
+
148
+ A query can carry an API key (`?api_key=sk_live_...`) and a JSON body a password. When the config gives a route no `capture` rule, and has no `"*"` rule, the door applies its own private rule to it: `method`, `path`, `headers` (the four above), `bodyBytes`, and `bodyOversized` stay in clear, and the query, the body, and `bodyDigest` leave one salted commitment, `request.args.$rest`, in their place. The policy still decides on the real values, because the rule is applied after the decision, and the receipt still verifies. As under any private rule, the denial reason and the policy's error messages are withheld too; the client's 403 still carries the reason. The facts (the arrival) and the result (the origin's status and digest) stay in clear.
149
+
150
+ To record more in clear, give the route a rule of its own, as for the gateway ([private evidence](configuration.md)): `{ "capture": { "refund": { "args": { "mode": "digest", "clear": ["method", "path", "body"] } } } }` keeps a refund's body in clear, and `{ "capture": { "*": { "args": { "mode": "clear" } } } }` keeps every route's arguments in clear, as before.
151
+
152
+ ## The receipt
153
+
154
+ A door receipt is a v0.2 receipt with `issuer.kind: "door"` and `issuer.framework: "http"`. The route is the tool, observed. `request.args` is the arrival as the table above describes it, claimed. `facts.arrival` is the door's observation. When the arrival was verified, `principal` and `agent` are attested and `delegation` carries the grant; otherwise `principal` is `{ id: null, provenance: "claimed" }` and `agent` is the subject, claimed. `execution.result` for a relayed call is `{ status, contentType?, bodyBytes, bodyDigest }`: the origin's body is never copied into the receipt, only committed to.
155
+
156
+ The verifier runs `door receipt carries a policy decision` in place of the gateway's two checks, and otherwise the same checks: a verified arrival's receipt passes `delegation binds principal and agent` and `executed tool within delegated scope`; an unknown arrival's passes `principal is claimed, not attested`; a receipt that carries an `authorization` passes the authorization checks, including `authorization logged before execution`. Both verifiers, the Python verifier, and `policy simulate` accept door receipts; the conformance vectors `door-unknown-executed`, `door-unknown-denied`, and `door-verified-executed` pin them.
157
+
158
+ ## What it does not do yet
159
+
160
+ - Detect agents in web or API traffic. The only signals are the ones in the arrival fact: `signature` and `declared` are claims, and `rate` is a pace ([door signals](door-signals.md)).
161
+ - Check RFC 9421 HTTP message signatures, Web Bot Auth directories, or AP2 mandates. The grant is the only passport today.
162
+ - Challenge an arrival with a passkey. Turnstile and hCaptcha are the providers; see [challenging a human](#challenging-a-human).
163
+ - Revoke a grant by a revocation list; a grant stands until it expires.
164
+ - Bind a grant to its sender. A verified arrival is bearer-grade: see [presenting a passport](#what-the-door-knows-about-an-arrival).
165
+ - Stream a request body: the body is read whole, up to `maxBodyBytes`, so that the policy can read it and the receipt can commit to it.
166
+ - Relay a response larger than `maxResponseBytes`, or stream one: the body is relayed whole so that its digest can be recorded. A larger one is not held: reading stops at the limit, the client gets 502, and the receipt records that the origin answered.
167
+
168
+ Tutorial: [40-door.ts](../examples/40-door.ts).
@@ -0,0 +1,164 @@
1
+ # Verifying receipts on a pull request
2
+
3
+ A pull request is where a team reviews the work of an agent. The GitHub Action in this repository verifies the receipts of that work and puts the result on the pull request. A reviewer sees the result and installs nothing.
4
+
5
+ The action runs `agent-custody verify --markdown` on a directory of receipt bundles. It writes one table to the job summary. On a pull request it also posts the same table as one comment, and it edits that comment on each later push. The `agent-custody export` command puts the receipts into the branch, and it refuses a receipt that publishes the call.
6
+
7
+ ## The workflow file
8
+
9
+ Copy this file to `.github/workflows/receipts.yml`.
10
+
11
+ ```yaml
12
+ name: receipts
13
+ on:
14
+ pull_request:
15
+ permissions:
16
+ contents: read
17
+ pull-requests: write
18
+ jobs:
19
+ verify:
20
+ runs-on: ubuntu-latest
21
+ steps:
22
+ - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
23
+ - uses: svayatta/agent-custody@<commit sha of the release> # 0.15.0
24
+ with:
25
+ path: .custody/receipts
26
+ issuer-key: .custody/keys/agent.pub
27
+ ```
28
+
29
+ Pin the action to the commit of a release, as you pin every other action. A moving tag lets a third party change what runs with your token.
30
+
31
+ ## The inputs
32
+
33
+ | input | meaning | default |
34
+ | --- | --- | --- |
35
+ | `path` | a directory of receipt bundles; the action reads the `.json` files in it, not `<id>.authorization.json` files, not symbolic links, and not subdirectories | `.custody/receipts` |
36
+ | `issuer-key` | the public key files of the issuers you trust, one path on each line (required) | |
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
+ | `log-url` | the URL of the log; the action fetches the log key from it (`verify --log-url`) | |
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.15.0` |
41
+ | `github-token` | a token that can write pull request comments | `github.token` |
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
+
44
+ ## What the action does
45
+
46
+ 1. It sets up Node 22 and runs `npx @agent-custody/receipts@<version> verify --markdown <path> --issuer-key ...`.
47
+ 2. It writes the table to `$GITHUB_STEP_SUMMARY`.
48
+ 3. On a `pull_request` event, it looks for an earlier comment that starts with `<!-- agent-custody -->` and that the account in `comment-author` posted, and it edits that comment. When there is none, it posts a new comment.
49
+ 4. It fails the step when one receipt does not verify, and when the directory holds no receipt.
50
+
51
+ Any user can post a comment that starts with the marker line. The action ignores such a comment, because the author does not match. If you give `github-token` the token of a user or of an app, set `comment-author` to the login of that account. With the wrong login, the action does not find its own comment, and it posts a new comment on each push.
52
+
53
+ When the token cannot write a comment, the action prints a warning and keeps the job summary. This is the case for a pull request from a fork, where GitHub gives the `pull_request` event a read-only token. The step does not fail for that reason. Do not switch to `pull_request_target` to get the comment. That event gives a write token to a workflow that handles code from the fork.
54
+
55
+ The table has one row for each receipt. The failed rows come first.
56
+
57
+ | Receipt | Tool | Status | Result |
58
+ | --- | --- | --- | --- |
59
+ | `981d2afd-63f2-49ed-854a-83fc1bf1c035` | - | - | `receipt signature (issuer key)` |
60
+ | `6e2de8f3-4e51-43e5-af8b-a2b283dd7709` | `stripe.refund` | executed | verified |
61
+
62
+ - `Status` is the execution status in the signed receipt: `executed`, `denied`, `failed`, `error`, or `withheld`. When the signature does not verify, the table shows `-`, because nothing in that receipt is trusted.
63
+ - `Result` is `verified`, or the names of the checks that failed. [Verifying a receipt](verification.md#what-each-check-means) explains each check.
64
+ - A file that is not valid JSON shows `not a JSON file`, and a file with the wrong shape shows `not a receipt bundle`. The table never shows text from the file, because anyone who can change the branch can choose the file. The action does not read a symbolic link in `path`, so a link cannot bring a file from the runner into the comment.
65
+ - `verify --markdown` follows a symbolic link when the link is the file argument or the directory argument itself, but not a link inside the directory. The table shows only fixed error text or verified fields, so a followed link shows no text from its target.
66
+ - A file whose name is not `<receipt id>.json` fails with `file name matches receipt id`. A valid receipt under the name of another receipt could hide that receipt.
67
+ - The table shows 200 rows at most. Every failed row is in it.
68
+
69
+ ## What the table proves, and what it does not
70
+
71
+ A `verified` row proves that the issuer key you gave signed the receipt, that the receipt has not changed since, and that its checks hold. It does not prove that the receipts are all the calls the agent made. The author of the pull request chooses which receipts to commit. [Completeness](completeness.md) answers that question from the provider's side.
72
+
73
+ Keep the key files out of reach of the pull request. With the `pull_request` event, the workflow checks out the merge of the pull request. An author who changes `.custody/keys/agent.pub` in the same pull request can sign a receipt with a key of their own. Protect the key path with a code owner rule, or keep the key in a repository that the author cannot change.
74
+
75
+ ## How receipts get into the pull request
76
+
77
+ Receipts stay on the machine of the developer, in the `receiptsDir` of the gateway or the SDK. The action reads a directory in the checkout, so the receipts you want reviewed must be in the branch. The `export` command puts them there.
78
+
79
+ ```bash
80
+ agent-custody export --receipts ~/.config/agent-custody/receipts --out .custody/receipts \
81
+ --issuer-key .custody/keys/agent.pub --since 2026-11-02T09:00:00Z
82
+ git add .custody/receipts
83
+ ```
84
+
85
+ The command prints one line for each receipt, then a count.
86
+
87
+ ```
88
+ copied 6e2de8f3-4e51-43e5-af8b-a2b283dd7709.json
89
+ refused 981d2afd-63f2-49ed-854a-83fc1bf1c035.json: args and result in clear: a capture rule must withhold it (or give --allow-clear)
90
+ skipped 0b7c5f6e-93f7-4f06-a1f1-2f8d2d5f63a0.json: issued 2026-11-01T17:02:11.480Z, before --since
91
+ 1 copied, 1 refused, 1 skipped
92
+ ```
93
+
94
+ | flag | meaning |
95
+ | --- | --- |
96
+ | `--receipts <dir>` | the receipts directory of the machine |
97
+ | `--out <dir>` | where the copies go; the command creates it when it copies a receipt |
98
+ | `--issuer-key <pub>` | the public key of the issuer; repeat it for more than one issuer (required) |
99
+ | `--principal-key <pub>` | the public key of a principal whose grant a gateway receipt carries; SDK and Claude Code hook receipts need none |
100
+ | `--approval-key <pub>` | the public key of an approver, for a gateway receipt that carries approval evidence |
101
+ | `--since <ISO time>` | keep the receipts issued at or after this time, for example the start of the branch |
102
+ | `--allow-clear` | copy a receipt that carries plain values; see the warning below |
103
+
104
+ What the command does, in this order, for each file:
105
+
106
+ 1. It reads only the `<id>.json` files at the top level of `--receipts`. It never reads or copies `salts/`, `outbox/`, `*.authorization.json`, a subdirectory, a symbolic link, or any other file.
107
+ 2. It verifies the receipt with the issuer key. It refuses a receipt that does not verify, and a receipt whose file name is not its signed receipt id (`file name matches receipt id`, as the action does). `--issuer-key` is required, because the next step trusts what the signed receipt says about its own capture. An unverified file can claim anything.
108
+ 3. It skips a receipt issued before `--since`. A skipped receipt is not a failure.
109
+ 4. It runs the privacy check below. It refuses a receipt that fails the check.
110
+ 5. It copies the file byte for byte. It never rewrites a receipt, because the signature covers it. It writes nothing to `--out` for a refused or a skipped receipt.
111
+
112
+ The command exits 1 when it refuses any receipt, and when it copies none. The other receipts are still copied. A file in the directory with a `.json` name that is not a receipt bundle is refused as well.
113
+
114
+ ### The privacy check
115
+
116
+ The signed receipt has a capture note. The note lists the paths that hold a commitment in place of the value. The check reads the note, and it refuses a receipt when a side that holds data has no withheld path under it. The sides are the arguments (`request.args`), the result (`execution.result`, with the error message and the denial reason), and the value of each fact (`facts.<name>.value`). The command prints the sides in the reason, for example `args and result in clear`.
117
+
118
+ A field that a rule lists in its `clear` list stays in clear on purpose, so the check allows it when the rule withholds the other fields of that side. An empty side is not data.
119
+
120
+ `--allow-clear` turns the check off. The command then copies the receipt, marks it `(plain values: args, result)`, and prints this warning on standard error: each receipt marked with plain values publishes its arguments or its result to everyone who can read the output directory.
121
+
122
+ The check has limits. Read them before you rely on it.
123
+
124
+ - A receipt cannot be redacted after it is issued. The arguments and the result are signed as they are, and a change breaks the signature. Only a capture rule at issue time keeps a value out of the receipt. A receipt that an agent made before you set the rule stays in clear. Use `--since` to leave it out.
125
+ - A side whose every field is on the `clear` list has nothing left to withhold, so it has no commitment. The check cannot tell it from a side in mode `clear`, and it refuses it. A `Bash` call with the argument `command` alone is such a side under the second rule below. Read the receipt, and give `--allow-clear` if you accept it.
126
+ - The check does not look inside a value that the rule keeps in clear. The command text of a `Bash` call can hold a secret as well, for example a token in a `curl` header or in an `export` line. Keep a field in clear only when you accept that a reader sees all of it.
127
+ - The tool name, the ids, the timestamps, the status, and the policy decision always stay in clear.
128
+
129
+ ### A committed receipt publishes the call
130
+
131
+ By default a receipt carries the call in plain text. It holds the arguments the agent sent and the result the tool returned. For a `Bash` call that is the command and its output. For a file tool it is the content of the file. Anyone who can read the repository can read these values. If the repository is public, everyone can.
132
+
133
+ Before you commit a receipt, check these points.
134
+
135
+ 1. Set a capture rule before the session starts. A `capture` rule in the gateway config or in the SDK config (`sdk.json`) withholds a side of the call. With mode `digest`, the receipt holds one commitment over the fields you do not list in `clear`. With mode `encrypted`, it holds the same commitment and the value encrypted under a key that only you hold (`captureKeyEnv`). The rule applies to the receipt, to the log, and to every exporter. [Private evidence](usage.md#private-evidence) has the full rules. Two rules follow.
136
+
137
+ The strict rule. Every tool, every side, in mode `digest`. A reviewer sees the tool name, the status, and the decision of each call, and no value.
138
+
139
+ ```json
140
+ "capture": {
141
+ "*": { "args": { "mode": "digest" }, "result": { "mode": "digest" }, "facts": { "mode": "digest" } }
142
+ }
143
+ ```
144
+
145
+ The rule that shows the commands. The `command` argument of `Bash` stays in clear, and the result is in mode `digest`. A reviewer sees what the agent ran, and not what it printed. Every other tool takes the strict rule from `"*"`.
146
+
147
+ ```json
148
+ "capture": {
149
+ "*": { "args": { "mode": "digest" }, "result": { "mode": "digest" }, "facts": { "mode": "digest" } },
150
+ "Bash": { "args": { "mode": "digest", "clear": ["command"] }, "result": { "mode": "digest" } }
151
+ }
152
+ ```
153
+
154
+ The second rule has a cost. The command text can hold a secret: a token on a command line, a password in a connection string, a path that names a customer. The rule publishes that text. In the second rule the other arguments of `Bash` (`description`, `timeout`) are withheld together in one commitment. Use the strict rule when you cannot read every command.
155
+
156
+ 2. Run `agent-custody export` instead of a copy by hand. It leaves `salts/`, `outbox/`, `*.authorization.json`, and a local `log.jsonl` behind. The salts let a reader confirm a guess of a withheld value, and the authorization files and the log hold the call data as well. Never copy these files into a branch.
157
+ 3. Keep the capture key out of the repository and out of the workflow. The action needs no key. A receipt with withheld values verifies as committed, and the table still shows the tool and the status, because those parts stay in clear.
158
+ 4. Read one exported receipt before the first push. Run `agent-custody verify <file> --issuer-key <pub>` and read the `args` and `execution` rows.
159
+
160
+ A reviewer who needs a withheld value asks the owner of the key for a disclosure (`agent-custody reveal`), and verifies it with `verify --disclose`.
161
+
162
+ If you set up the Claude Code hook with `agent-custody init claude-code`, the `sdk.json` that it writes has no `capture` rule. Add the rule to that file before the session, and run `export` on the `receipts` directory next to it.
163
+
164
+ An agent that runs inside the CI job needs no transport. Write its receipts in the job and run the action in the same job.
package/docs/policies.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Writing policies
2
2
 
3
- Policies are written in [Cedar](https://www.cedarpolicy.com/), the language AWS uses for AgentCore and Verified Permissions. There is no home-grown policy language here. Every example on this page is executed against the real evaluator in the test suite.
3
+ Policies are written in [Cedar](https://www.cedarpolicy.com/), the language AWS uses for AgentCore and Verified Permissions, or in [Rego](https://www.openpolicyagent.org/docs/policy-language), the language of Open Policy Agent. There is no home-grown policy language here. Cedar is the default and most of this page uses it; [Rego](#rego) has its own section, including the choice between a Rego file the gateway compiles and an OPA server you already run. Every example on this page is executed against the real evaluator in the test suite.
4
4
 
5
5
  ## How a tool call becomes a Cedar request
6
6
 
@@ -168,6 +168,112 @@ permit(principal, action == Action::"memory.retract", resource)
168
168
  when { context.facts has target && context.facts.target.provenance == "claimed" };
169
169
  ```
170
170
 
171
+ ## Rego
172
+
173
+ A gateway decides by Rego in one of two ways. Give `policyFile` a path ending in `.rego`, and the gateway compiles the file itself. Or give `opa` instead of `policyFile`, and the gateway asks an OPA server you run. Both read the same request and the same rules, so a policy moves between them unchanged.
174
+
175
+ ### The request and the rules
176
+
177
+ The input is the Cedar request with plain strings for the three identifiers:
178
+
179
+ | Rego | value |
180
+ | --- | --- |
181
+ | `input.principal` | the agent id from the grant |
182
+ | `input.action` | the tool name |
183
+ | `input.resource` | the tool name |
184
+ | `input.context.args` | the call's arguments. **Provenance: claimed.** |
185
+ | `input.context.facts` | the gateway's own upstream lookups. **Provenance: observed.** |
186
+ | `input.context.grant` | `{ principal, scopes }` from the signed delegation. **Provenance: attested.** |
187
+
188
+ The policy declares `package agentcustody` and defines two rules:
189
+
190
+ - **`allow`**, a boolean. **Default deny:** the call is permitted only when `allow` is exactly `true`.
191
+ - **`deny`**, a set of strings. Any entry wins over `allow`, as a Cedar `forbid` wins over a `permit`. Its strings are the reasons in the receipt and in the message the agent gets.
192
+ - **Errors deny.** A policy that fails while it evaluates, or whose `allow` is not a boolean or whose `deny` is not a set of strings, denies the call. The receipt records the error.
193
+ - **The scope check and the fact lookups run first**, exactly as for Cedar, and no policy can override them.
194
+
195
+ The fixture policy from the top of this page, in Rego:
196
+
197
+ ```rego
198
+ package agentcustody
199
+
200
+ # Reads of customer records are permitted to any agent holding the scope.
201
+ allow if input.action == "customer.lookup"
202
+
203
+ # Refunds: a whole number of pence from 1 to 100000 (£1,000), and only for customers the gateway itself verified.
204
+ allow if {
205
+ input.action == "stripe.refund"
206
+ amount := input.context.args.amount
207
+ is_number(amount)
208
+ amount == floor(amount)
209
+ amount > 0
210
+ amount <= 100000
211
+ input.context.facts.customer.verified == true
212
+ }
213
+
214
+ deny contains "this customer is flagged for review" if {
215
+ input.action == "stripe.refund"
216
+ input.context.facts.customer.flagged == true
217
+ }
218
+ ```
219
+
220
+ A missing attribute is *undefined* in Rego, not an error: the rule does not hold when there is no `amount`, so the call is denied. That is the same outcome as Cedar's error, reached a different way. Rego has floats, which Cedar does not, so `amount <= 100000` alone would hold for `0.5`, and for `0` and `-1` as well. Amounts are integer minor units: `amount == floor(amount)` holds only for a whole number, and `amount > 0` sets the floor.
221
+
222
+ ### A Rego file, or an OPA server
223
+
224
+ | | `policyFile: "policy.rego"` | `opa: { "url": ... }` |
225
+ | --- | --- | --- |
226
+ | where the policy lives | a file beside `gateway.json`, as with Cedar | in the bundles of an OPA server your platform team runs |
227
+ | how it is evaluated | compiled to WebAssembly by `opa build` when the file loads or changes, then evaluated inside the gateway | an HTTP query to the server's Data API for every call |
228
+ | what it needs | the `opa` binary on `PATH` when the policy loads, never on a call. The gateway image includes it | a reachable server at an `https` URL, or `http` on a loopback address. A call it cannot answer within `timeoutMs` (default 2000) is denied |
229
+ | what `policyDigest` in a receipt is | the sha256 of the file's text, as for Cedar. The portal can name it, and anyone with the file can check it | the sha256 of the decision URL and the revision of every bundle the server reports. Map it back with `receipts/policy-reloads.jsonl`. A call the server did not answer is denied under the URL's own "unanswered" digest, never under a revision that did not decide it |
230
+ | changing the policy | write the file by rename. It applies from the next call, and a file that does not compile is refused while the policy in force stays | publish a new bundle revision. The first call under it records the new digest |
231
+ | builtins | those the WebAssembly runtime supports. `http.send`, `time.now_ns`, and other builtins it cannot run are refused when the file loads | everything the server allows, including `http.send` |
232
+ | best for | a gateway that should decide on its own, with the policy text pinned in every receipt | an organisation that already governs policy centrally in OPA and wants agents under the same bundles |
233
+
234
+ **What a receipt can prove differs.** With a file, the receipt pins the exact text that decided, so a verifier holding the file can show it was this policy. With a server, the receipt pins only what the server *said* it was running: the bundle revisions in its `provenance` answer. The gateway asks for provenance on every query, records each new combination in `policy-reloads.jsonl` with the bundle names and revisions, and prints it. Serve the policy from a bundle built with `opa build --revision <id>`, so the revision names a version you can find again. A server that reports no revision still works, but the gateway warns at start and on each new answer that its receipts cannot name the policy. `agent-custody check` warns about it as well.
235
+
236
+ **A server outside the policy also decides.** A Rego file is evaluated where the gateway runs, under the operator's control. An OPA server's answer is trusted as it comes back over HTTP. Run it where only your platform team can change it, and give the gateway a token with `tokenEnv` when the server requires one. Each query carries the call's arguments and that token, so the gateway refuses a plain `http` URL unless the host is a loopback address, and it never follows a redirect: a 3xx answer denies the call. The gateway refuses to start when it cannot reach the server, or when the server does not define the package.
237
+
238
+ A gateway config with an OPA server:
239
+
240
+ ```json
241
+ "opa": {
242
+ "url": "http://localhost:8181",
243
+ "decision": "agentcustody",
244
+ "tokenEnv": "OPA_TOKEN",
245
+ "timeoutMs": 2000
246
+ }
247
+ ```
248
+
249
+ `decision` is the package path under `/v1/data`, such as `authz/agents` for `package authz.agents`, and defaults to `agentcustody`. The document at that path must have the `allow` and `deny` rules above. The gateway posts `{ "input": ... }` to `<url>/v1/data/<decision>?provenance=true`.
250
+
251
+ ### Testing and simulating a Rego policy
252
+
253
+ `opa test` runs Rego unit tests as usual. `evaluateRego` and `compileRego` from `@agent-custody/receipts` evaluate a policy exactly as the gateway does, with the same decision and digest:
254
+
255
+ ```ts
256
+ import { compileRego, evaluateRego, policyDigest } from "@agent-custody/receipts";
257
+
258
+ const text = readFileSync("policy.rego", "utf8");
259
+ const { policy, errors } = compileRego(text); // errors: why it cannot load
260
+ const d = evaluateRego(policy!, policyDigest(text), { agentId: "support-agent", tool: "stripe.refund", context: { args: { amount: 50000 }, facts: { customer: { verified: true } } } });
261
+ ```
262
+
263
+ `agent-custody policy simulate --policy proposed.rego ...` replays recorded receipts against a Rego policy, including receipts a Cedar policy decided, so a move from Cedar to Rego can be checked against history before it is enforced. `agent-custody check` compiles a `.rego` file, or queries the OPA server once. An SDK issuer reads a `.rego` `policyFile` the same way. The console's policy editor, the deny report, and `init claude-code` work with Cedar only for now.
264
+
265
+ ## Saying why a rule denies
266
+
267
+ Put a `@reason("...")` annotation before a `forbid` rule. The Claude Code hook shows the text to the agent and to the person who reads the session, and `agent-custody report` prints it before the rule.
268
+
269
+ ```cedar
270
+ @reason("force push rewrites shared history")
271
+ forbid(principal, action == Action::"Bash", resource)
272
+ when { context.args has command && context.args.command like "*git push*--force*" };
273
+ ```
274
+
275
+ The hook text is `agent-custody denied this call: force push rewrites shared history (rule policy1, receipt <id>)`. A rule with no annotation shows its id. The annotation is part of the policy file, so it changes the policy digest, but it never changes the decision or the receipt format. Keep the reason short and say what the rule forbids, not what the agent did. Only the Claude Code hook and the report read it today.
276
+
171
277
  ## Gotchas
172
278
 
173
279
  - **Integers only.** `12.50` is not a Cedar value. Send `1250`.
@@ -224,3 +330,20 @@ The report lists every call whose `allow` or `deny` decision changes, grouped by
224
330
  Every run records a `runId`, `timestamp`, the proposed text's sha256 as `policyDigest`, and the original digests as `previousPolicyDigests`. `--out` saves the full JSON report, and `--json` prints it to stdout. Changes alone exit 0. A report that cannot replay every call says `INCOMPLETE` and exits 1: `skipped` names each receipt and why. This includes record-only receipts with no policy baseline, withheld arguments or fact values, calls whose receipt is missing, and calls stopped before Cedar could evaluate. Grant failures cannot become permits through a policy change, and neither can an approval refusal: the gateway checks the approval before Cedar runs, so the call is skipped as a non-policy gate. The approval record says so even under a private rule. Withheld results alone do not prevent replay. A reconciliation receipt is a provider read, so no policy decision exists to replay. The report counts it in `reconciliations`, not in `evaluated` or `skipped`, and it does not make the report incomplete. A reconciliation whose original receipt is missing is the exception: the call that it settles cannot be replayed, so the report skips that call and says `INCOMPLETE`. The library trusts a reconciliation receipt only after `verifyBundle` accepts it; the CLI and the console verify first.
225
331
 
226
332
  The report is an analysis of the supplied receipt directory; it does not prove that the directory contains the whole history. Keep the report beside the proposed policy and review the changed receipt ids before switching from observe mode to enforcement. [Tutorial 28](../examples/28-policy-simulation.ts) records three refunds, stops the gateway, and replays them against a lower limit.
333
+
334
+ ## How an arrival at the door becomes a Cedar request
335
+
336
+ The [door](door.md) uses the same evaluator for arrivals at your own HTTP surface. `principal` is `Agent::"<agent>"` for the agent a verified grant names, and `Agent::"unknown"` for every other arrival: a declared name is a claim and stays in the arrival fact. `action` and `resource` are the route the arrival fell under. `context.args` is the request (`method`, `path`, `query`, `headers`, a JSON `body` when small, `bodyBytes`, `bodyDigest`; `bodyOversized: true` and no digest when the body passed `maxBodyBytes`), claimed. The policy reads it with `null` members dropped and numbers that are not safe integers as strings, since Cedar refuses both. `context.facts.arrival` is the door's own observation of the arrival: its `class` (`verified`, `claimed`, `unknown`), `subject`, what became of its `grant`, and its `remote` address. `context.grant` is present only for a verified arrival. A policy that lets `unknown` through on a route lets everything through on that route.
337
+
338
+ ```cedar
339
+ permit(principal, action == Action::"catalogue", resource);
340
+
341
+ permit(principal, action == Action::"refund", resource)
342
+ when {
343
+ context.facts.arrival.class == "verified" &&
344
+ context.args.body.amount > 0 &&
345
+ context.args.body.amount <= 5000
346
+ };
347
+ ```
348
+
349
+ A bound on an amount needs both ends: `amount <= 5000` alone lets a negative refund through, and the door relays the body as it came. A permit that names an agent, `principal == Agent::"shopping-agent"`, is satisfied only by a verified grant for that agent: a declared name never reaches the principal slot. `agent-custody check` still warns on a permit that names an agent without requiring `context.facts.arrival.class == "verified"`, because a policy copied from the gateway reads as if it did.