@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.
- package/README.md +46 -28
- package/dist/check.d.ts +10 -0
- package/dist/check.js +179 -3
- package/dist/claude-init.d.ts +46 -0
- package/dist/claude-init.js +208 -0
- package/dist/cli.js +126 -11
- package/dist/config.d.ts +128 -1
- package/dist/config.js +92 -3
- package/dist/console.js +16 -7
- package/dist/deny-report.d.ts +30 -0
- package/dist/deny-report.js +106 -0
- package/dist/door.d.ts +203 -0
- package/dist/door.js +712 -0
- package/dist/export.d.ts +39 -0
- package/dist/export.js +95 -0
- package/dist/gateway.js +53 -21
- package/dist/index.d.ts +8 -0
- package/dist/index.js +7 -0
- package/dist/issue.js +5 -65
- package/dist/lock.d.ts +12 -0
- package/dist/lock.js +124 -0
- package/dist/log-admin.js +3 -3
- package/dist/log.d.ts +20 -3
- package/dist/log.js +117 -24
- package/dist/opa-server.d.ts +34 -0
- package/dist/opa-server.js +93 -0
- package/dist/policy-rego.d.ts +30 -0
- package/dist/policy-rego.js +114 -0
- package/dist/policy.d.ts +6 -0
- package/dist/policy.js +17 -0
- package/dist/pr-summary.d.ts +25 -0
- package/dist/pr-summary.js +87 -0
- package/dist/receipt.d.ts +3 -1
- package/dist/retention.d.ts +1 -1
- package/dist/retention.js +14 -4
- package/dist/sdk/claude.js +18 -2
- package/dist/sdk/index.d.ts +2 -0
- package/dist/sdk/index.js +11 -2
- package/dist/simulate.d.ts +3 -1
- package/dist/simulate.js +15 -7
- package/dist/verify.js +6 -3
- package/dist/witness.js +3 -3
- package/docs/compliance.md +117 -7
- package/docs/configuration.md +3 -3
- package/docs/door-signals.md +66 -0
- package/docs/door.md +168 -0
- package/docs/github-action.md +164 -0
- package/docs/policies.md +124 -1
- package/docs/sdk.md +99 -1
- package/docs/tutorials.md +5 -0
- package/docs/usage.md +3 -3
- package/docs/verification.md +9 -2
- package/package.json +16 -14
- package/templates/claude-code.cedar +373 -0
- package/vectors/audit.json +27 -27
- package/vectors/canonical.json +5 -5
- package/vectors/merkle.json +123 -0
- package/vectors/receipts.json +1258 -1005
package/docs/sdk.md
CHANGED
|
@@ -38,6 +38,104 @@ Policies see `context.args` and an empty `context.facts`. A policy that reads `c
|
|
|
38
38
|
|
|
39
39
|
## Claude Code
|
|
40
40
|
|
|
41
|
+
### One command
|
|
42
|
+
|
|
43
|
+
```bash
|
|
44
|
+
npx @agent-custody/receipts init claude-code
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
The command sets up custody for your own Claude Code sessions. It prints each step.
|
|
48
|
+
|
|
49
|
+
1. It makes an agent key in `~/.config/agent-custody/keys/`.
|
|
50
|
+
2. It writes `sdk.json` in `~/.config/agent-custody/` with `"mode": "observe"` and a `receiptsDir`. No log is configured, so the receipts stay on your machine.
|
|
51
|
+
3. It writes a starter deny set to `policy.cedar`: force push (`--force`, `-f`, and `+refspec`), `rm -rf` on `/`, `~`, and `$HOME`, `terraform destroy`, `terraform apply -destroy`, and `drop database` in both cases. Each rule has a `@reason`, so the denial text says what the rule forbids. The policy permits every other call, and it permits `git push --force-with-lease` (see [The starter deny set](#the-starter-deny-set)).
|
|
52
|
+
4. It registers the `PreToolUse`, `PostToolUse`, and `PostToolUseFailure` hooks in `.claude/settings.local.json` of the current directory. Claude Code adds that file to your global git ignore only when Claude Code itself creates it, so `init` does not rely on that. When the project is a git repository and git does not ignore the file, `init` prints a warning with the line to add to `.gitignore`: `.claude/settings.local.json`. The file holds absolute paths of your home directory. `init` never edits `.gitignore`. With `--user`, the hooks go to `~/.claude/settings.json` and apply to every project.
|
|
53
|
+
5. It prints the next step: start a Claude Code session, then run the report.
|
|
54
|
+
|
|
55
|
+
The hook command in the settings file uses absolute paths: the Node binary, the CLI script that runs now, and the absolute path of `sdk.json`. The command merges into an existing settings file. It keeps every other key and every other hook, and it does not add a hook that is already there. If the settings file is not valid JSON, the command stops with an error and changes nothing.
|
|
56
|
+
|
|
57
|
+
Each hook is its own process, and Claude Code runs hooks at the same time for parallel tool calls, subagents, and several sessions. The local log `log.jsonl` takes the lock file `log.jsonl.lock` for each append, reads the leaves that other processes appended, and then writes its own leaf. The lock file holds an owner token, the process id, and the start time of the process. A holder removes the lock file only when it still holds its own token. A lock is stale when its process on this host is gone. The lock of a live process on this host is never broken. The lock of a process on another host, or a lock file with no readable owner, is stale when nobody touched it for 60 seconds. To break a stale lock, a writer first takes `log.jsonl.lock.break` with an exclusive create, so only one writer breaks at a time. It then reads the lock again, and moves it away only when its inode and token are still the ones it judged stale. A lock file that is gone between the create and the judgment is not broken: the writer tries the create again. The outbox of the gateway uses the same lock code. `agent-custody prune` takes the same lock, so a hook that appends during a prune waits and its leaf is kept.
|
|
58
|
+
|
|
59
|
+
A writer that waits for the lock gives up after 20 seconds. A `PreToolUse` hook that gives up cannot record a denial: in enforce mode the call is still blocked, and the denial text ends with `no receipt: <reason>`. A `PostToolUse` or `PostToolUseFailure` hook that gives up exits with code 1 and prints the error on stderr. That receipt is lost, because the tool call has already run and the hook does not retry. The other receipts are not affected. If a process was killed in the middle of a write, the last line of `log.jsonl` has no newline. The next append moves those bytes to `log.jsonl.torn`, and the log continues after the last whole line. No leaf was returned for those bytes.
|
|
60
|
+
|
|
61
|
+
The hook command pins the path of the Node binary that runs `init`. With nvm, a removed Node version breaks the hook, and every tool call then prints an error. After you remove a Node version, run `init` again. The second run updates the path.
|
|
62
|
+
|
|
63
|
+
You can run the command two times. It never overwrites an existing key, `sdk.json`, `policy.cedar`, or `log.pub`, so your edits and your pinned log key stay. When `sdk.json` exists, the command ignores `--enforce` and the log options, and it prints a warning that names each flag that it did not apply. A second run does update the path in a hook of ours. When the first run came from the npx cache (a path with `/_npx/`), the command prints a warning, because npm can clear that cache and the hooks then stop working. Install the package globally with `npm install -g @agent-custody/receipts` and run the command again. The second run replaces the old path.
|
|
64
|
+
|
|
65
|
+
| option | effect |
|
|
66
|
+
| --- | --- |
|
|
67
|
+
| `--dir <dir>` | the directory for the key, the config, the policy, and the receipts. Default: `~/.config/agent-custody` |
|
|
68
|
+
| `--user` | write the hooks to `~/.claude/settings.json` |
|
|
69
|
+
| `--enforce` | leave out `"mode": "observe"`, so a denied call is blocked |
|
|
70
|
+
| `--log-url <url>` | send the receipts to a log as hashes (`hashOnly`, a 3 second timeout) instead of a local `log.jsonl`. It needs `--log-key`: without the key of the log, `report` cannot check the tree head of any receipt, so the command stops with an error |
|
|
71
|
+
| `--log-id <id>` | the log id that the tree heads must name |
|
|
72
|
+
| `--log-token-env NAME` | the NAME of the environment variable that holds the log token. Default: `AGENT_CUSTODY_LOG_TOKEN`. The command refuses a value that is not an uppercase variable name, so a token never enters a file |
|
|
73
|
+
| `--log-key <pub>` | the log's public key file, in PEM form. The command refuses a private key and any other file. It copies the file to `log.pub` and pins it in `log.keys` when it writes a new `sdk.json`. A second run does not replace `log.pub` |
|
|
74
|
+
|
|
75
|
+
### The starter deny set
|
|
76
|
+
|
|
77
|
+
Each rule matches the text of a Bash command with the Cedar `like` operator, and `*` is the only wildcard of `like`. The rules catch the plain form of each command. They are not a sandbox.
|
|
78
|
+
|
|
79
|
+
| command | the policy |
|
|
80
|
+
| --- | --- |
|
|
81
|
+
| `git push --force`, `git push -f`, `git push origin main -f`, `git push origin -f main`, `git push origin +main`, `git -C repo push --force` | denied |
|
|
82
|
+
| `git push origin main --force && gh pr create`, `git push origin +main && echo done` | denied |
|
|
83
|
+
| `git push --force-with-lease`, `git -C repo push --force-with-lease` | allowed. It is a force push that fails when the remote has new commits, so it is the safer form. The `@reason` of the rule says so |
|
|
84
|
+
| `git push origin main && rm -f stale.lock`, `git push origin fix-f`, `git push origin main && npm install --force`, `git push && git status -f` | allowed |
|
|
85
|
+
| `rm -rf /`, `rm -fr /`, `rm -Rf /`, `rm -r -f /`, `rm -rf /*`, `rm -rf ~`, `rm -rf $HOME`, `rm -rf "$HOME"`, `rm -rf ${HOME}` | denied |
|
|
86
|
+
| `rm -rf /tmp/build`, `rm -rf ~/projects/app/dist`, `rm -rf "$HOME"/projects/app/dist` | allowed |
|
|
87
|
+
| `terraform destroy`, `terraform apply -destroy` | denied |
|
|
88
|
+
| `terraform plan`, `terraform plan -destroy` | allowed |
|
|
89
|
+
|
|
90
|
+
A force push has `--force`, `-f`, or a refspec that starts with `+`. The push can be `git push` or `git -C <dir> push` (any `git` option before `push`). A flag counts in three cases: it is the first argument after `push`, or no `&`, `|`, `;`, or newline follows `push`, or one of them follows the flag. A flag that comes after an operator belongs to another command, so `git push origin main && npm install --force` passes.
|
|
91
|
+
|
|
92
|
+
The `rm` rules know the flags `-rf`, `-fr`, `-Rf`, `-fR`, and the separate forms `-r -f`, `-f -r`, `-R -f`, `-f -R`. The home directory can be `~`, `$HOME`, or `${HOME}`, and `$HOME` can be in double quotes.
|
|
93
|
+
|
|
94
|
+
The rule ids are the place of each rule in `policy.cedar`: the permit rule is `policy0`, the force push rule is `policy1`, and `terraform destroy` is `policy5`. Change a rule in place, and add a new rule at the end of the file, so that an id keeps naming the same rule. Receipts, reports, and pages name rules by id.
|
|
95
|
+
|
|
96
|
+
What Cedar `like` cannot express, and the starter policy therefore does not catch:
|
|
97
|
+
|
|
98
|
+
- `like` has `*` and nothing else. It cannot find where one shell command ends. A chain with two operators after `git push` can be denied by mistake: `git push && npm install --force && echo done` is denied.
|
|
99
|
+
- It cannot read shell words. These forms pass: `rm --recursive --force /`, `rm --no-preserve-root -rf /`, `terraform -chdir=infra destroy`, a command in a variable or in a script file, and a path that reaches the same directory (`rm -rf /usr/..`).
|
|
100
|
+
- It cannot tell a flag from the text of an argument. `git push origin "message -f"` is denied.
|
|
101
|
+
- A force push that the git configuration or an alias sets (a `+` in `remote.<name>.push`) is not in the text of the command.
|
|
102
|
+
|
|
103
|
+
Use a sandbox, or a protected branch on the remote, for these. `test/claude-init.test.ts` runs every command of this table and of this list.
|
|
104
|
+
|
|
105
|
+
### The denial text
|
|
106
|
+
|
|
107
|
+
A Cedar policy can carry a `@reason("...")` annotation. When a rule that denies a call has one, the hook returns its text. When several rules deny the call, the hook joins their reasons with `; ` in file order and lists the rules.
|
|
108
|
+
|
|
109
|
+
```cedar
|
|
110
|
+
@reason("terraform destroy deletes infrastructure")
|
|
111
|
+
forbid(principal, action == Action::"Bash", resource)
|
|
112
|
+
when { context.args has command && context.args.command like "*terraform destroy*" };
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
```text
|
|
116
|
+
agent-custody denied this call: terraform destroy deletes infrastructure (rule policy5, receipt 47eb52af-...)
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
A rule with no annotation gives its id in place of the reason: `agent-custody denied this call: policy3 (rule policy3, receipt ...)`. A deny that names no rule keeps the plain text, such as `agent-custody: no permit policy matched (receipt ...)` or the evaluation error. The issuer parses the annotations one time, when it loads the policy.
|
|
120
|
+
|
|
121
|
+
The receipt does not change. It keeps the policy ids and the policy digest, and its `execution.reason` stays the list of ids. The reason text is for the agent and for the person who reads the session. The other adapters in this file still return the rule ids.
|
|
122
|
+
|
|
123
|
+
### The report
|
|
124
|
+
|
|
125
|
+
```bash
|
|
126
|
+
agent-custody report --config ~/.config/agent-custody/sdk.json
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
`init` prints this command with absolute paths. The report reads the receipts directory of the config and verifies each receipt with the agent's key. Then it prints `would have denied N calls`, and for each call the tool, the command or the file path, the `@reason` of the rule when it has one, the Cedar rule (cut to 160 characters), and the receipt id. A receipt that does not verify is counted apart, listed with the reason, and never counted as a denial. The command then exits with code 1. The report ends with the next step: remove the `"mode": "observe"` line from `sdk.json` to enforce the policy. A denial that the policy enforced (a config without the observe line) is listed apart as `denied`.
|
|
130
|
+
|
|
131
|
+
`policy simulate` answers another question: what a proposed policy would change in recorded history. Use `report` to read what the policy in the config decided in observe mode.
|
|
132
|
+
|
|
133
|
+
### An incident replay
|
|
134
|
+
|
|
135
|
+
`node examples/38-incident-replay.ts` runs the hook in enforce mode with scripted events. `terraform plan` runs. `terraform destroy -auto-approve` and `rm -rf ~` are denied before they run, and a reviewer verifies the denial receipts with the public key only. The page [An incident replay](../../../site/guide/incident-replay.md) shows the output and the limit: a credential in the agent's environment goes around the hook.
|
|
136
|
+
|
|
137
|
+
### Register the hook by hand
|
|
138
|
+
|
|
41
139
|
Register the hook command in `.claude/settings.json`. The same command handles all three events.
|
|
42
140
|
|
|
43
141
|
```json
|
|
@@ -58,7 +156,7 @@ Register the hook command in `.claude/settings.json`. The same command handles a
|
|
|
58
156
|
|
|
59
157
|
`AGENT_CUSTODY_CONFIG` works instead of `--config`. Behaviour per event:
|
|
60
158
|
|
|
61
|
-
- **PreToolUse.** Evaluates the policy. On deny, issues a denial receipt and returns `permissionDecision: "deny"` with the receipt id
|
|
159
|
+
- **PreToolUse.** Evaluates the policy. On deny, issues a denial receipt and returns `permissionDecision: "deny"` with a reason that says what the rule forbids: `agent-custody denied this call: terraform destroy deletes infrastructure (rule policy5, receipt <id>)`. See [The denial text](#the-denial-text). If the log does not take the receipt, the hook still denies the call, and the text ends with `no receipt` and why instead of the receipt id. On allow, or with no policy, returns no decision, so Claude Code's own permission prompts still apply. The hook never auto-approves.
|
|
62
160
|
- **PostToolUse.** Issues an executed receipt carrying `tool_response`.
|
|
63
161
|
- **PostToolUseFailure.** Issues a failed receipt.
|
|
64
162
|
|
package/docs/tutorials.md
CHANGED
|
@@ -45,6 +45,11 @@ Suggested reading order is the numbering. Output lands in `examples-out/`, which
|
|
|
45
45
|
| 33 | anchoring the log on a chain | [33-chain-anchor.ts](../examples/33-chain-anchor.ts) | a log publishes a checkpoint, the anchor commits it to a stand-in chain in one transaction, and `log-check` passes against the chain; the operator swaps in a rewritten log under the same key and log id, and `log-check` fails it from the chain alone |
|
|
46
46
|
| 34 | strict mode | [34-strict-mode.ts](../examples/34-strict-mode.ts) | `check` lists what strict mode would refuse; a local log and a log that is not hash-only are refused at startup; behind a hash-only log with a pinned key, a read is precommitted and its receipt says `issuer.strict`; `requireStrict` accepts it and refuses an ordinary receipt; with the log down the call is not forwarded and the outbox stays empty | `src/config.ts`, `src/gateway.ts`, `src/check.ts`, `src/verify.ts` |
|
|
47
47
|
| 35 | completeness from the provider's side | [35-completeness.ts](../examples/35-completeness.ts) | two refunds through the gateway and a third issued straight through the provider; the auditor lists the provider's refunds with a read-only key, matches two to verified receipts, and reports the third as an action with no receipt |
|
|
48
|
+
| 36 | one command for Claude Code | [36-claude-code-init.ts](../examples/36-claude-code-init.ts) | `init claude-code` in a temporary home: the key, the observe-mode config, the starter policy, and the three hooks; a second run adds nothing; a session of four calls; the report that lists the two calls the policy would have denied | `src/claude-init.ts`, `src/deny-report.ts` |
|
|
49
|
+
| 37 | receipts on a pull request | [37-pr-summary.ts](../examples/37-pr-summary.ts) | two receipts from a gateway verify into one Markdown table (what `verify --markdown` and the GitHub Action post); one changed byte makes the table name the failed check; a directory with no receipt fails | `src/pr-summary.ts`, `action.yml` |
|
|
50
|
+
| 38 | an incident replay | [38-incident-replay.ts](../examples/38-incident-replay.ts) | the same setup as `init claude-code --enforce`, in a temporary home; a scripted Claude Code session that runs the real hook command for each event: `terraform plan` runs and gets an executed receipt, `terraform destroy -auto-approve` and `rm -rf ~` are denied before they run, with the denial text and the receipt id; a reviewer with only the public key verifies all three receipts, and a stranger's key fails | `src/sdk/claude.ts`, `src/claude-init.ts`, `templates/claude-code.cedar` |
|
|
51
|
+
| 39 | exporting receipts to a pull request | [39-export.ts](../examples/39-export.ts) | an agent works under a capture rule; `export` copies the two receipts that withhold their values, byte for byte, and refuses the one that records plain values; one changed byte makes it refuse a third | `src/export.ts`, `src/cli.ts` |
|
|
52
|
+
| 40 | the door: a receipted reverse proxy in front of your own API | [40-door.ts](../examples/40-door.ts) | a stand-in shop behind the door; an unknown arrival reads the catalogue and is refused a refund; an agent with a grant signed by the shop's principal is verified and refunds within the policy, refused above it; a forged grant is claimed; the origin saw only what was allowed; both receipts verified | `src/door.ts`, `src/config.ts` |
|
|
48
53
|
|
|
49
54
|
## How policies are defined, in one paragraph
|
|
50
55
|
|
package/docs/usage.md
CHANGED
|
@@ -123,7 +123,7 @@ At startup the gateway fetches the agent's card from `<url>/.well-known/agent-ca
|
|
|
123
123
|
"log": { "url": "https://log.example.com/", "tokenEnv": "AGENT_CUSTODY_LOG_TOKEN" }
|
|
124
124
|
```
|
|
125
125
|
|
|
126
|
-
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>]`, `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, so a tenant out of quota never acts without evidence. 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. 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.
|
|
126
|
+
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>]`, `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. 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.
|
|
127
127
|
|
|
128
128
|
`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. 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.
|
|
129
129
|
|
|
@@ -148,7 +148,7 @@ The grant is checked on every call, not only when the session opens: a call afte
|
|
|
148
148
|
|
|
149
149
|
The outbox is appended in the order of the signed statements' timestamps, oldest first. A log refusal stops the flush, so one receipt that the log refuses holds the receipts after it. `GET /health` on the HTTP gateway reports `pendingReceipts`. Only a gateway that serves (stdio, `--http`, `--a2a`) runs the flush, at start and every 30 seconds; `check`, `reconcile`, and the other commands never append the outbox. A gateway that stops waits for a flush that runs. A gateway that stops before the log takes the receipt keeps the outbox on disk and appends it on the next start. The gateway writes the outbox entry to disk, and syncs the file and its directory, before the agent gets the result.
|
|
150
150
|
|
|
151
|
-
Several gateways, or a gateway and a command, can share one `receipts/` directory. A flush takes the lock file `receipts/outbox/.lock` with an exclusive create. When another process holds the lock, the flush does nothing and reports the entries as `pending`. The gateway breaks a lock whose owner process no longer runs on this host,
|
|
151
|
+
Several gateways, or a gateway and a command, can share one `receipts/` directory. A flush takes the lock file `receipts/outbox/.lock` with an exclusive create. When another process holds the lock, the flush does nothing and reports the entries as `pending`. The gateway breaks a lock whose owner process no longer runs on this host. It never breaks the lock of a live process on this host. It breaks the lock of a process on another host, or a lock file with no readable owner, when nobody has touched it for 15 minutes (one minute for a file with no owner). It uses the same break procedure as the local log ([sdk.md](sdk.md)).
|
|
152
152
|
|
|
153
153
|
When the log takes a receipt, the gateway records the log's answer in the outbox entry before it writes the bundle. If the bundle write then fails (a full disk, a permission error), the gateway prints the error on stderr, and the next flush writes the bundle from the recorded answer and does not append the leaf again. A process that dies between the append and that record appends the leaf again on the next flush; the log then holds it twice, and either copy proves the receipt. A gateway that dies after the forward and before the outbox write leaves no receipt; `precommit` is the guard for the calls where that matters. Before the gateway appends an outbox entry, it checks the entry. It renames an entry to `<name>.bad`, does not append it, and prints a warning, when the file is damaged, when the entry carries this gateway's key id but the signature does not verify, or when the receipt id in the statement is not the id in the file name. An entry that another key signed (a rotated gateway key, or a restored backup) is not appended, is not called forged, and stays in the outbox; the gateway prints a warning on each flush. Restore the key that signed it, or move the entry away. Until the log takes a pending receipt, `receipts/<id>.json` does not exist, so `verify`, `explain`, `blast`, the review console, and `prune` do not see the call yet.
|
|
154
154
|
|
|
@@ -253,7 +253,7 @@ A reviewer verifies such a receipt three ways:
|
|
|
253
253
|
- With the key: `agent-custody verify ... --capture-key-env AGENT_CUSTODY_CAPTURE_KEY` decrypts every encrypted value, checks each against its commitment, and recomputes the digests and the upstream's signature from the real values. A key that is not the one the values were encrypted under fails the checks, naming the key id, rather than passing them as committed.
|
|
254
254
|
- With a disclosure: `agent-custody verify ... --disclose disclosure.json` does the same from a file holding, at each withheld path, the real value and the salt its commitment was made with: `{ "receiptId", "request": { "args": { "$rest": { "$custody": "disclosed", "salt": "<hex>", "value": { "reason": "…" } } } }, "execution": { "result": { "$rest": { … } }, "error", "upstream": { "rawBody", "signature", "bind" } }, "policy": { "errors" }, "facts": { "<name>": { "value": { "$rest": { … } }, "args": { … }, "resultDigest" } } }`, any part of it. A disclosed `$rest` is folded back into its object before the digest is recomputed. A value without its salt cannot be checked and is refused as such. A disclosure that contradicts a commitment fails the check with the path named, a fact's value included: a reviewer cannot be handed a false policy fact. A disclosure for another receipt is refused.
|
|
255
255
|
|
|
256
|
-
`agent-custody reveal receipts/<id>.json --capture-key-env AGENT_CUSTODY_CAPTURE_KEY --issuer-key keys/gateway.pub --out disclosure.json` writes that disclosure from the key, every encrypted value decrypted and checked against its commitment, with its salt. The bundle must verify against the issuer key given, and each ciphertext is bound to its receipt and path, so a bundle someone assembled around another receipt's ciphertexts reveals nothing. The file is written owner-only and never through a symlink. A value withheld as a digest only carries nothing to reveal, and the command says which paths it could not reveal. With `--include-salts` it also writes, at each such path, the salt from the issuer's salts file beside the receipt, for whoever holds the value to add `value` beside; a file with a salt and no value does not verify, so it cannot be handed over unfinished by mistake. Hand the finished file to the reviewer with the receipt, never the salts file.
|
|
256
|
+
`agent-custody reveal receipts/<id>.json --capture-key-env AGENT_CUSTODY_CAPTURE_KEY --issuer-key keys/gateway.pub --out disclosure.json` writes that disclosure from the key, every encrypted value decrypted and checked against its commitment, with its salt. The bundle must verify against the issuer key given, and each ciphertext is bound to its receipt and path, so a bundle someone assembled around another receipt's ciphertexts reveals nothing. The file is written owner-only and never through a symlink. A value withheld as a digest only carries nothing to reveal, and the command says which paths it could not reveal. With `--include-salts` it also writes, at each such path, the salt from the issuer's salts file beside the receipt, for whoever holds the value to add `value` beside; a file with a salt and no value does not verify, so it cannot be handed over unfinished by mistake. Hand the finished file to the reviewer with the receipt, never the salts file. To put receipts into a pull request, use `agent-custody export`: it copies only the receipts that keep their values private, and never the salts ([receipts on a pull request](github-action.md)).
|
|
257
257
|
|
|
258
258
|
The salts file, `receipts/salts/<id>.json`, is written for the owner alone (mode 0600 in a 0700 directory) and is as sensitive as the values: with it a guess can be confirmed. In mode `digest` it is also the only copy of each salt: lose it, and nobody can disclose those values again, not even the party that holds them, since a value alone cannot be checked against its commitment; the receipt then verifies only as committed. Back the directory up with the receipts, under the same access control as the values themselves. Mode `encrypted` carries each salt inside the ciphertext and nowhere else (the salts file holds only the digest-only ones), so the key alone recovers everything; choose it when a key is easier to keep safe than a directory of files. The key must be 32 random bytes: a reviewer sees its sha256 as `keyid` in every encrypted commitment, which is harmless for a random key and an offline oracle for a key derived from a passphrase. `agent-custody prune` removes the salts and the pre-committed authorization with the receipt.
|
|
259
259
|
|
package/docs/verification.md
CHANGED
|
@@ -69,16 +69,21 @@ execution observed executed
|
|
|
69
69
|
|
|
70
70
|
A refused call's `execution` row carries the reason the receipt records, for example `denied: delegation grant has been revoked`, and so does a `withheld` one. Under a capture rule the reason is a commitment, and the row says `(reason withheld under the capture rule)` rather than printing it.
|
|
71
71
|
|
|
72
|
+
## A directory of receipts, as a Markdown table
|
|
73
|
+
|
|
74
|
+
`verify --markdown <dir> --issuer-key <pub>` verifies every bundle in a directory and prints one table: the receipt id, the tool, the status (`executed`, `denied`, `failed`, `error`, `withheld`), and `verified` or the names of the failed checks. It takes the same key and log options as `verify`. It reads regular `.json` files only, not symbolic links in the directory; it follows a link that is itself the file argument or the directory argument, and the table shows only fixed error text or verified fields. It does not combine with `--json` or `--disclose`. The exit code is 1 when one receipt does not verify and when the directory holds no receipt. The [GitHub Action](github-action.md) posts this table on a pull request. A receipt that goes into a repository publishes its arguments and result unless a capture rule withholds them; that page says how to commit private receipts.
|
|
75
|
+
|
|
72
76
|
## What each check means
|
|
73
77
|
|
|
74
78
|
| check | what it establishes | what a failure usually means |
|
|
75
79
|
| --- | --- | --- |
|
|
76
80
|
| receipt signature (issuer key) | the bundle's envelope was signed by a key you trust as an issuer and has not changed since | edited receipt, or an issuer key you do not trust |
|
|
77
81
|
| receipt payload type | the payload is an in-toto Statement with this project's predicate type | wrong file, or a different envelope replayed as a receipt |
|
|
78
|
-
| issuer kind is known | the receipt says whether a gateway or an SDK produced it; the detail shows which, and the framework | a predicate this verifier does not understand |
|
|
82
|
+
| issuer kind is known | the receipt says whether a gateway, a door, or an SDK produced it; the detail shows which, and the framework | a predicate this verifier does not understand |
|
|
79
83
|
| issuer keyid matches signer | the receipt's own claim of who signed it matches the actual signature | mixed-up or forged predicate |
|
|
80
84
|
| gateway receipt carries a delegation | gateway receipts always embed the signed grant they enforced | an SDK receipt relabelled as gateway |
|
|
81
85
|
| gateway receipt carries a policy decision | gateway receipts always record the Cedar decision | same |
|
|
86
|
+
| door receipt carries a policy decision | a door decides every arrival by policy; it carries a grant only when the arrival presented one, so there is no delegation check for it | a record-only receipt relabelled as door |
|
|
82
87
|
| delegation signature (principal key) | the embedded grant was signed by a key you trust as a principal | a grant the principal never issued |
|
|
83
88
|
| delegation chain to the principal | only when the grant embeds a parent: every link is signed by the key its parent names, holds no scope its parent lacks, sits inside its parent's window, and names the same principal, up to three delegations deep | a sub-agent given more than its delegator had, a link signed by the wrong key, a chain that never reaches a trusted principal |
|
|
84
89
|
| delegation binds principal and agent | the grant names the same principal and agent the receipt names, and the principal keyid matches | a valid grant for someone else, spliced in |
|
|
@@ -204,6 +209,8 @@ The remote log also serves `GET /head`, its current tree head signed with the lo
|
|
|
204
209
|
|
|
205
210
|
`vectors/` in the package holds fixed receipts, keys, logs, proofs, and the verdicts this verifier produces for them, generated by `bun run vectors` and checked by the test suite on every run. A verifier written elsewhere proves it agrees by reproducing every verdict. They are published at [agent-custody.dev/receipt/vectors](https://agent-custody.dev/receipt/vectors).
|
|
206
211
|
|
|
212
|
+
The Lean 4 model in [`spec/lean`](../../../spec/lean/README.md) checks the Merkle vectors as a third implementation. It also proves the inclusion check of `log.ts` complete and sound: for every tree, each audit path verifies, and an accepted proof places the leaf at its index unless the node hash has a collision.
|
|
213
|
+
|
|
207
214
|
## Attested execution
|
|
208
215
|
|
|
209
216
|
On a gateway receipt the execution is `observed`: the gateway saw what the upstream returned. An upstream that holds a key can do better and sign its result for the receipt being issued; the gateway embeds the signature, and a verifier given the upstream's public key checks it and reports the execution as `attested` by that key. The check binds the signature to the receipt id, the tool, and the digest of the result content, so a signature cannot be moved between receipts.
|
|
@@ -228,5 +235,5 @@ Receipts hold values: request arguments, results, facts. The log is append-only
|
|
|
228
235
|
node src/cli.ts prune --log log.jsonl --before 2026-06-01T00:00:00Z --receipts receipts
|
|
229
236
|
```
|
|
230
237
|
|
|
231
|
-
Every leaf whose receipt is older than the cutoff is replaced in the file by its leaf hash, and the receipt's bundle file is deleted. The Merkle tree is built from leaf hashes, so every root, every inclusion proof, and every consistency proof for the remaining leaves is unchanged, and `--log` verification of later receipts still passes. Someone who kept a pruned receipt's bundle can still prove it was in the log; nobody holding only the log can recover what it said. Run it on the same schedule as memory retention.
|
|
238
|
+
Every leaf whose receipt is older than the cutoff is replaced in the file by its leaf hash, and the receipt's bundle file is deleted. The Merkle tree is built from leaf hashes, so every root, every inclusion proof, and every consistency proof for the remaining leaves is unchanged, and `--log` verification of later receipts still passes. Someone who kept a pruned receipt's bundle can still prove it was in the log; nobody holding only the log can recover what it said. `prune` holds the log lock (`<log>.lock`) while it rewrites the file, so a process that appends at the same time waits, and its leaf is kept. `prune` waits up to 20 seconds for the lock. Run it on the same schedule as memory retention.
|
|
232
239
|
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agent-custody/receipts",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.15.0",
|
|
4
4
|
"mcpName": "io.github.svayatta/agent-custody",
|
|
5
|
-
"description": "Chain of custody for AI agents: signed, independently verifiable receipts for tool calls. MCP gateway + Cedar policy + Merkle transparency log",
|
|
5
|
+
"description": "Chain of custody for AI agents: signed, independently verifiable receipts for tool calls. MCP gateway + Cedar or Rego policy + Merkle transparency log",
|
|
6
6
|
"license": "Apache-2.0",
|
|
7
7
|
"repository": {
|
|
8
8
|
"type": "git",
|
|
@@ -57,6 +57,7 @@
|
|
|
57
57
|
"files": [
|
|
58
58
|
"dist",
|
|
59
59
|
"docs",
|
|
60
|
+
"templates",
|
|
60
61
|
"vectors"
|
|
61
62
|
],
|
|
62
63
|
"scripts": {
|
|
@@ -70,23 +71,24 @@
|
|
|
70
71
|
"node": ">=22"
|
|
71
72
|
},
|
|
72
73
|
"dependencies": {
|
|
73
|
-
"@cedar-policy/cedar-wasm": "
|
|
74
|
-
"@modelcontextprotocol/sdk": "
|
|
75
|
-
"
|
|
74
|
+
"@cedar-policy/cedar-wasm": "4.12.0",
|
|
75
|
+
"@modelcontextprotocol/sdk": "1.30.0",
|
|
76
|
+
"@open-policy-agent/opa-wasm": "1.10.0",
|
|
77
|
+
"zod": "4.5.4"
|
|
76
78
|
},
|
|
77
79
|
"devDependencies": {
|
|
78
80
|
"@electric-sql/pglite": "0.5.8",
|
|
79
|
-
"@langchain/core": "
|
|
80
|
-
"@node-saml/node-saml": "
|
|
81
|
-
"@openai/agents": "
|
|
82
|
-
"@types/node": "
|
|
83
|
-
"ai": "
|
|
81
|
+
"@langchain/core": "1.2.9",
|
|
82
|
+
"@node-saml/node-saml": "5.1.0",
|
|
83
|
+
"@openai/agents": "0.18.0",
|
|
84
|
+
"@types/node": "26.4.1",
|
|
85
|
+
"ai": "7.0.93",
|
|
84
86
|
"langchain": "1.5.15",
|
|
85
|
-
"tsx": "
|
|
86
|
-
"typescript": "
|
|
87
|
+
"tsx": "4.23.13",
|
|
88
|
+
"typescript": "7.0.2",
|
|
87
89
|
"viem": "2.57.4",
|
|
88
|
-
"vitest": "
|
|
89
|
-
"xml-crypto": "
|
|
90
|
+
"vitest": "5.0.0",
|
|
91
|
+
"xml-crypto": "6.4.0"
|
|
90
92
|
},
|
|
91
93
|
"peerDependencies": {
|
|
92
94
|
"@langchain/core": ">=1.0.0",
|