@agent-custody/receipts 0.16.3 → 0.16.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -16,6 +16,7 @@ Anyone holding the public keys can verify a receipt offline. The agent is not tr
16
16
 
17
17
  - [Reference](https://docs.agent-custody.dev/reference/): every function, endpoint, MCP tool, and command with its request and response
18
18
  - [Tutorials](docs/tutorials.md): runnable examples, one per aspect of the code, all executed by the test suite
19
+ - [Put the door in front of a site](docs/door-quickstart.md): a fifteen-minute quick start for a site owner, from keys to verified receipts.
19
20
  - [The door](docs/door.md): a receipted reverse proxy in front of your own site or API; what it knows about an arrival, how an arrival becomes a Cedar request, what the arrival gets back, and what it does not do yet
20
21
  - [The egress witness](docs/egress.md): a receipted forward proxy for calls that go around the gateway; lockdown, how the witness knows the agent, the Cedar request (or Rego input) per destination, the receipt, and what it cannot see: payloads, traffic when lockdown is off, and non-HTTP protocols
21
22
  - [Writing egress policies](../../site/guide/egress-policies.md): per-agent allow lists, wildcard hosts and the `*.example.com` trap, ports, IP literals, why a provider that needs a credential stays in the gateway, `forbid`, and rolling out from observe mode with `egress draft-policy`; every example is tested
package/dist/check.js CHANGED
@@ -36,6 +36,9 @@ function writableAncestor(path) {
36
36
  dir = up;
37
37
  }
38
38
  try {
39
+ // the path itself may be a file; anything above it must be a directory
40
+ if (dir !== resolve(path) && !statSync(dir).isDirectory())
41
+ return null;
39
42
  accessSync(dir, constants.W_OK);
40
43
  return dir;
41
44
  }
package/dist/log-sink.js CHANGED
@@ -9,7 +9,7 @@ import { dsseSign, dsseVerify, loadPublicKey } from "./crypto.js";
9
9
  import { createHash } from "node:crypto";
10
10
  import { leafHash, MerkleLog, verifyInclusion } from "./log.js";
11
11
  import { fileBackend, RateLimiter } from "./log-store.js";
12
- import { fetchLogKeys, localSigner } from "./signer.js";
12
+ import { fetchLogKeys, localSigner, shownUrl } from "./signer.js";
13
13
  import { adminRoutes } from "./log-admin.js";
14
14
  import { TREEHEAD_TYPE } from "./receipt.js";
15
15
  function signedHead(e, key, logId) {
@@ -46,22 +46,23 @@ export function fileLog(file, key) {
46
46
  */
47
47
  export function httpLog(url, opts = {}) {
48
48
  const f = opts.fetch ?? fetch;
49
+ const shown = shownUrl(url);
49
50
  const base = url.endsWith("/") ? url : `${url}/`;
50
51
  const attempts = opts.retries ?? 3;
51
52
  const timeoutMs = opts.timeoutMs ?? 10_000;
52
53
  let pinned = opts.keys?.length ? Promise.resolve(opts.keys) : null;
53
- const keys = () => (pinned ??= fetchLogKeys(base, f).then((r) => r.keys).catch((e) => { pinned = null; throw new Error(`log ${url}: its keys could not be fetched to check the append, and none are configured: ${e instanceof Error ? e.message : String(e)}`); }));
54
+ const keys = () => (pinned ??= fetchLogKeys(base, f).then((r) => r.keys).catch((e) => { pinned = null; throw new Error(`log ${shown}: its keys could not be fetched to check the append, and none are configured: ${e instanceof Error ? e.message : String(e)}`); }));
54
55
  const checked = async (entry, leaf) => {
55
56
  const th = dsseVerify(entry.treeHead, await keys());
56
57
  if (!th.ok || entry.treeHead.payloadType !== TREEHEAD_TYPE)
57
- throw new Error(`log ${url} answered with a tree head that does not verify against its keys${th.ok ? " (wrong payload type)" : `: ${th.error}`}`);
58
+ throw new Error(`log ${shown} answered with a tree head that does not verify against its keys${th.ok ? " (wrong payload type)" : `: ${th.error}`}`);
58
59
  const head = th.payload;
59
60
  if (opts.logId !== undefined && head.log !== opts.logId)
60
- throw new Error(`log ${url} signed a tree head for log "${head.log ?? ""}", not "${opts.logId}"`);
61
+ throw new Error(`log ${shown} signed a tree head for log "${head.log ?? ""}", not "${opts.logId}"`);
61
62
  if (head.treeSize !== entry.inclusion.treeSize)
62
- throw new Error(`log ${url} answered with a tree head of size ${head.treeSize} and a proof for size ${entry.inclusion.treeSize}`);
63
+ throw new Error(`log ${shown} answered with a tree head of size ${head.treeSize} and a proof for size ${entry.inclusion.treeSize}`);
63
64
  if (!verifyInclusion(leafHash(leaf), entry.inclusion, head.rootHash))
64
- throw new Error(`log ${url} answered with an inclusion proof that does not place this leaf under the signed root`);
65
+ throw new Error(`log ${shown} answered with an inclusion proof that does not place this leaf under the signed root`);
65
66
  return entry;
66
67
  };
67
68
  return {
@@ -80,7 +81,7 @@ export function httpLog(url, opts = {}) {
80
81
  });
81
82
  }
82
83
  catch (e) {
83
- last = `log ${url} unreachable: ${e instanceof Error ? e.message : String(e)}`;
84
+ last = `log ${shown} unreachable: ${e instanceof Error ? e.message : String(e)}`;
84
85
  if (i + 1 < attempts)
85
86
  await new Promise((r) => setTimeout(r, 200 * 2 ** i));
86
87
  continue;
@@ -88,10 +89,10 @@ export function httpLog(url, opts = {}) {
88
89
  if (res.ok) {
89
90
  const body = (await res.json());
90
91
  if (!body.inclusion || !body.treeHead)
91
- throw new Error(`log ${url} returned a malformed append result`);
92
+ throw new Error(`log ${shown} returned a malformed append result`);
92
93
  return checked(body, leaf);
93
94
  }
94
- last = `log ${url} refused the append: ${res.status} ${(await res.text()).slice(0, 200)}`;
95
+ last = `log ${shown} refused the append: ${res.status} ${(await res.text()).slice(0, 200)}`;
95
96
  if (res.status !== 429 && res.status < 500)
96
97
  break;
97
98
  if (i + 1 < attempts) {
@@ -1,7 +1,7 @@
1
1
  // Adapter for Claude Code hooks (command hooks over stdin/stdout) and the Claude Agent SDK (in-process hooks).
2
2
  // Both use the same input and output JSON, so one handler serves both.
3
3
  import { reasonOfRule } from "../policy.js";
4
- import { createSdkIssuer, receiptIdOf, denies } from "./index.js";
4
+ import { createSdkIssuer, noReceipt, receiptIdOf, denies } from "./index.js";
5
5
  /** What Claude Code and the person see. A rule with a `@reason` gives its text; any other rule gives its id. The rules are in file order. A deny with no rule keeps the plain text. */
6
6
  function denialText(issuer, policy, reason, evidence) {
7
7
  if (policy.reasons.length === 0)
@@ -33,7 +33,7 @@ export async function handleHookEvent(issuer, input) {
33
33
  evidence = `receipt ${receiptIdOf(await issuer.record(ev, { status: "denied", reason }, policy))}`;
34
34
  }
35
35
  catch (e) {
36
- evidence = `no receipt: ${e instanceof Error ? e.message : String(e)}`;
36
+ evidence = noReceipt(e);
37
37
  }
38
38
  return {
39
39
  continue: true,
@@ -17,7 +17,7 @@
17
17
  // `agent-custody hook` command works through it unchanged, one process per call. This plugin is the in-process path.
18
18
  import { z } from "zod";
19
19
  import { loadSdkConfig } from "../config.js";
20
- import { createSdkIssuer, denies, receiptIdOf } from "./index.js";
20
+ import { createSdkIssuer, denies, noReceipt, receiptIdOf } from "./index.js";
21
21
  function toEvent(exec) {
22
22
  const raw = exec.arguments;
23
23
  const args = raw && typeof raw === "object" && !Array.isArray(raw) ? raw : { input: raw ?? null };
@@ -43,7 +43,7 @@ export function deepseekHarnessHooks(issuer) {
43
43
  return { kind: "deny", reason: `agent-custody: ${reason} (receipt ${receiptIdOf(bundle)})` };
44
44
  }
45
45
  catch (e) {
46
- return { kind: "deny", reason: `agent-custody: ${reason}; the denial receipt could not be issued (${e instanceof Error ? e.message : String(e)})` };
46
+ return { kind: "deny", reason: `agent-custody: ${reason} (${noReceipt(e)})` };
47
47
  }
48
48
  },
49
49
  postExecute: async (exec, result, next) => {
@@ -47,4 +47,10 @@ export declare class PolicyDeniedError extends Error {
47
47
  constructor(tool: string, reason: string, receiptId: string);
48
48
  }
49
49
  export declare function createSdkIssuer(cfg: SdkConfig): SdkIssuer;
50
+ /**
51
+ * The end of a deny reason whose receipt could not be issued: `no receipt: <why>`. The reason reaches the model, so it
52
+ * names the failure class only; the error itself, which can carry a log URL with credentials or the text of the log's
53
+ * answer, goes to stderr.
54
+ */
55
+ export declare function noReceipt(e: unknown): string;
50
56
  export declare function receiptIdOf(bundle: ReceiptBundle): string;
package/dist/sdk/index.js CHANGED
@@ -101,6 +101,15 @@ export function createSdkIssuer(cfg) {
101
101
  },
102
102
  };
103
103
  }
104
+ /**
105
+ * The end of a deny reason whose receipt could not be issued: `no receipt: <why>`. The reason reaches the model, so it
106
+ * names the failure class only; the error itself, which can carry a log URL with credentials or the text of the log's
107
+ * answer, goes to stderr.
108
+ */
109
+ export function noReceipt(e) {
110
+ console.error(`agent-custody: no receipt: ${e instanceof Error ? e.message : String(e)}`);
111
+ return "no receipt: the receipt could not be recorded";
112
+ }
104
113
  export function receiptIdOf(bundle) {
105
114
  const st = JSON.parse(Buffer.from(bundle.envelope.payload, "base64").toString());
106
115
  return st.predicate.receiptId;
@@ -4,7 +4,7 @@
4
4
  // observeRunner: receipts only, from the runner's agent_tool_start / agent_tool_end events. Cannot block, so it
5
5
  // evaluates no policy. Use one or the other per tool, not both.
6
6
  // Typed structurally so this file does not import the package.
7
- import { receiptIdOf, denies } from "./index.js";
7
+ import { noReceipt, receiptIdOf, denies } from "./index.js";
8
8
  function parseArgs(input) {
9
9
  if (!input)
10
10
  return {};
@@ -33,8 +33,12 @@ export function wrapTools(issuer, tools) {
33
33
  const policy = issuer.decide(ev);
34
34
  if (denies(policy)) {
35
35
  const reason = [...policy.reasons, ...policy.errors].join("; ") || "no permit policy matched";
36
- const bundle = await issuer.record(ev, { status: "denied", reason }, policy);
37
- return `Denied by policy: ${reason} (receipt ${receiptIdOf(bundle)})`;
36
+ try {
37
+ return `Denied by policy: ${reason} (receipt ${receiptIdOf(await issuer.record(ev, { status: "denied", reason }, policy))})`;
38
+ }
39
+ catch (e) {
40
+ return `Denied by policy: ${reason} (${noReceipt(e)})`;
41
+ }
38
42
  }
39
43
  try {
40
44
  const result = await t.invoke(ctx, input, details);
@@ -8,7 +8,7 @@
8
8
  // import { registerOpenClaw } from "@agent-custody/receipts/sdk/openclaw";
9
9
  // export default definePluginEntry({ id: "agent-custody", name: "agent-custody", description: "A receipt for every tool call",
10
10
  // register(api) { registerOpenClaw(api, createSdkIssuer(loadSdkConfig(process.env.AGENT_CUSTODY_CONFIG!))); } });
11
- import { denies, receiptIdOf } from "./index.js";
11
+ import { denies, noReceipt, receiptIdOf } from "./index.js";
12
12
  function toEvent(event, ctx) {
13
13
  const raw = event.params;
14
14
  const args = raw && typeof raw === "object" && !Array.isArray(raw) ? raw : { input: raw ?? null };
@@ -34,7 +34,7 @@ export function openclawHooks(issuer) {
34
34
  return { block: true, blockReason: `agent-custody: ${reason} (receipt ${receiptIdOf(bundle)})` };
35
35
  }
36
36
  catch (e) {
37
- return { block: true, blockReason: `agent-custody: ${reason}; the denial receipt could not be issued (${e instanceof Error ? e.message : String(e)})` };
37
+ return { block: true, blockReason: `agent-custody: ${reason} (${noReceipt(e)})` };
38
38
  }
39
39
  },
40
40
  after_tool_call: async (event, ctx) => {
package/dist/signer.d.ts CHANGED
@@ -57,6 +57,8 @@ export declare function serveSigner(kp: KeyPair, opts: SignerServerOptions & {
57
57
  port: number;
58
58
  host?: string;
59
59
  }): Promise<RunningSigner>;
60
+ /** The URL for an error message: no user, password, query, or fragment. */
61
+ export declare function shownUrl(url: string): string;
60
62
  /** For verifiers: the keys a log publishes, fetched from its origin and returned as key references pinned by keyid. */
61
63
  export declare function fetchLogKeys(logUrl: string, f?: typeof fetch): Promise<{
62
64
  doc: KeyDocument;
package/dist/signer.js CHANGED
@@ -29,29 +29,30 @@ export function localSigner(kp, opts = {}) {
29
29
  export async function connectSigner(url, opts = {}) {
30
30
  const f = opts.fetch ?? fetch;
31
31
  const base = url.endsWith("/") ? url : `${url}/`;
32
+ const shown = shownUrl(url);
32
33
  const headers = { "content-type": "application/json", ...(opts.token ? { authorization: `Bearer ${opts.token}` } : {}) };
33
34
  const res = await f(new URL("keys", base), { headers, signal: AbortSignal.timeout(10_000) });
34
35
  if (!res.ok)
35
- throw new Error(`signer ${url} refused the key request: ${res.status}`);
36
+ throw new Error(`signer ${shown} refused the key request: ${res.status}`);
36
37
  const doc = (await res.json());
37
38
  const current = doc.keys[0];
38
39
  if (!current)
39
- throw new Error(`signer ${url} lists no key`);
40
+ throw new Error(`signer ${shown} lists no key`);
40
41
  return {
41
42
  keyid: current.keyid,
42
43
  async sign(payloadType, payload) {
43
44
  const r = await f(new URL("sign", base), { method: "POST", headers, body: JSON.stringify({ payloadType, payload }), signal: AbortSignal.timeout(5000) });
44
45
  if (!r.ok)
45
- throw new Error(`signer ${url} refused to sign: ${r.status} ${(await r.text()).slice(0, 200)}`);
46
+ throw new Error(`signer ${shown} refused to sign: ${r.status} ${(await r.text()).slice(0, 200)}`);
46
47
  const env = (await r.json());
47
48
  if (typeof env.payload !== "string" || !Array.isArray(env.signatures))
48
- throw new Error(`signer ${url} returned a malformed envelope`);
49
+ throw new Error(`signer ${shown} returned a malformed envelope`);
49
50
  return env;
50
51
  },
51
52
  async keys() {
52
53
  const k = await f(new URL("keys", base), { headers, signal: AbortSignal.timeout(10_000) });
53
54
  if (!k.ok)
54
- throw new Error(`signer ${url} refused the key request: ${k.status}`);
55
+ throw new Error(`signer ${shown} refused the key request: ${k.status}`);
55
56
  return (await k.json());
56
57
  },
57
58
  };
@@ -118,18 +119,28 @@ export function serveSigner(kp, opts) {
118
119
  });
119
120
  });
120
121
  }
122
+ /** The URL for an error message: no user, password, query, or fragment. */
123
+ export function shownUrl(url) {
124
+ try {
125
+ const u = new URL(url);
126
+ return `${u.protocol}//${u.host}${u.pathname}`;
127
+ }
128
+ catch {
129
+ return "(a URL that does not parse)";
130
+ }
131
+ }
121
132
  /** For verifiers: the keys a log publishes, fetched from its origin and returned as key references pinned by keyid. */
122
133
  export async function fetchLogKeys(logUrl, f = fetch) {
123
134
  const res = await f(new URL("/.well-known/agent-custody-log.json", logUrl), { signal: AbortSignal.timeout(10_000) });
124
135
  if (!res.ok)
125
- throw new Error(`log ${logUrl} serves no key document: ${res.status}`);
136
+ throw new Error(`log ${shownUrl(logUrl)} serves no key document: ${res.status}`);
126
137
  const doc = (await res.json());
127
138
  if (!Array.isArray(doc.keys) || doc.keys.length === 0)
128
- throw new Error(`log ${logUrl} lists no keys`);
139
+ throw new Error(`log ${shownUrl(logUrl)} lists no keys`);
129
140
  const keys = doc.keys.map((k) => {
130
141
  const ref = publicKeyFromPem(k.publicKeyPem);
131
142
  if (ref.keyid !== k.keyid)
132
- throw new Error(`log ${logUrl} lists key ${k.keyid.slice(0, 12)} whose pem has keyid ${ref.keyid.slice(0, 12)}`);
143
+ throw new Error(`log ${shownUrl(logUrl)} lists key ${k.keyid.slice(0, 12)} whose pem has keyid ${ref.keyid.slice(0, 12)}`);
133
144
  return ref;
134
145
  });
135
146
  return { doc, keys };
package/dist/verify.js CHANGED
@@ -570,6 +570,7 @@ export function auditExtends(older, newer, proof, keys, logId, opts = {}) {
570
570
  const ISSUER_NOTE = {
571
571
  gateway: "enforced outside the agent's process; the agent could neither skip nor forge this receipt",
572
572
  sdk: "self-reported by the agent's own process; tamper-evident after issue, but nothing here was enforced outside the agent",
573
+ door: "enforced in front of the business's own HTTP surface; the arriving party could not forge this receipt and is attested only when it presented a grant, and a request that reached the origin some other way leaves no receipt",
573
574
  guardian: "decided by an ACS Guardian outside the agent's process and signed with its own key, so the decision is attributable to it; the call is the agent's own report, and the agent could skip the Guardian or ignore its answer",
574
575
  egress: "observed by a forward proxy in the agent's network path, for a connection that went around the gateway: where it went and how much, never what was sent; the agent is known only by the proxy credential the witness checked, and a connection that skipped the proxy (no lockdown) leaves no receipt at all",
575
576
  };
@@ -0,0 +1,198 @@
1
+ # Put the door in front of a site
2
+
3
+ This page is for someone who runs a website or an API. In about fifteen minutes you run the door in front of a small stand-in site, write one policy for a sign-up form, and watch four arrivals: a bot that is refused and told how to pass the challenge, a bot that only claims to be an agent, a person who passes the challenge, and an agent that shows a passport. Then you verify the receipts with public keys only.
4
+
5
+ You need Node 22 or later and `curl`. The person in step 6 passes Cloudflare Turnstile with its public test keys, which needs no account but does call Cloudflare once. Everything else runs on your machine.
6
+
7
+ The door does not have its own container yet ([#258](https://github.com/svayatta/agent-custody/issues/258)), so this page runs the CLI from npm:
8
+
9
+ ```bash
10
+ alias agent-custody='npx -y -p @agent-custody/receipts@0.16.4 agent-custody'
11
+ mkdir door-quickstart && cd door-quickstart
12
+ ```
13
+
14
+ ## 1. Keys
15
+
16
+ The door signs every receipt with its own key. The principal key belongs to whoever vouches for an agent: it signs the agent's passport, and the door trusts the passports it signs.
17
+
18
+ ```bash
19
+ agent-custody keygen --dir keys --name door
20
+ agent-custody keygen --dir keys --name principal
21
+ ```
22
+
23
+ ## 2. A stand-in site
24
+
25
+ Your real site goes here later. This one answers a page on `GET /` and accepts a sign-up on `POST /form`:
26
+
27
+ ```bash
28
+ node -e 'require("http").createServer((q,s)=>{s.setHeader("content-type","text/plain");s.end(q.method==="GET"?"the sign-up page\n":"thanks, you are signed up\n")}).listen(3000,"127.0.0.1")' &
29
+ ```
30
+
31
+ ## 3. The policy
32
+
33
+ The door names each request by the route it falls under, and the policy decides per route. Anything the policy does not permit is refused. `policy.cedar`:
34
+
35
+ ```cedar
36
+ // The page is public.
37
+ permit(principal, action == Action::"page", resource);
38
+
39
+ // The form takes a person who has passed the challenge...
40
+ permit(principal, action == Action::"form", resource)
41
+ when { context.facts.arrival.challenge.outcome == "passed" };
42
+
43
+ // ...or an agent whose passport covers the form.
44
+ permit(principal, action == Action::"form", resource)
45
+ when { context.facts.arrival.class == "verified" };
46
+ ```
47
+
48
+ ## 4. The door's config
49
+
50
+ `door.json`:
51
+
52
+ ```json
53
+ {
54
+ "identity": { "keyFile": "keys/door.key" },
55
+ "origin": { "url": "http://127.0.0.1:3000" },
56
+ "routes": [
57
+ { "name": "page", "methods": ["GET"], "path": "/" },
58
+ { "name": "form", "methods": ["POST"], "path": "/form" }
59
+ ],
60
+ "trustedPrincipalKeys": ["keys/principal.pub"],
61
+ "policyFile": "policy.cedar",
62
+ "receiptsDir": "receipts",
63
+ "logFile": "log.jsonl",
64
+ "challenge": {
65
+ "provider": "turnstile",
66
+ "siteKey": "1x00000000000000000000AA",
67
+ "secretEnv": "TURNSTILE_SECRET",
68
+ "hostnames": ["example.com"]
69
+ }
70
+ }
71
+ ```
72
+
73
+ `1x00000000000000000000AA` and the secret below are Cloudflare's [test keys](https://developers.cloudflare.com/turnstile/troubleshooting/testing/): every token passes, and the answer names the host `example.com`. Check the config before you start the door; it should end with `no errors, 0 warnings`:
74
+
75
+ ```bash
76
+ export TURNSTILE_SECRET=1x0000000000000000000000000000000AA
77
+ agent-custody check --config door.json
78
+ ```
79
+
80
+ ## 5. Start the door
81
+
82
+ ```bash
83
+ agent-custody door --config door.json --port 8780 &
84
+ curl -s http://127.0.0.1:8780/
85
+ ```
86
+
87
+ ```text
88
+ the sign-up page
89
+ ```
90
+
91
+ The page went through the door, so it already has a receipt.
92
+
93
+ ## 6. Four arrivals at the form
94
+
95
+ **A bot.** It presents nothing. The policy refuses it, and the 403 says how to pass the challenge, so your page can show the widget and try again:
96
+
97
+ ```bash
98
+ curl -si -X POST http://127.0.0.1:8780/form -H 'content-type: application/json' -d '{"email":"a@example.com"}'
99
+ ```
100
+
101
+ ```text
102
+ HTTP/1.1 403 Forbidden
103
+ x-agent-custody-receipt: 454a8bef-8044-4cc7-9806-b421918507d2
104
+ x-agent-custody-class: unknown
105
+
106
+ {"error":"refused by the door's policy","reason":"no permit policy matched","receipt":"454a8bef-8044-4cc7-9806-b421918507d2","challenge":{"provider":"turnstile","siteKey":"1x00000000000000000000AA","header":"x-agent-custody-challenge"}}
107
+ ```
108
+
109
+ **A bot that says it is an agent.** A name in a header is a claim, and the door records it as one: the class is `claimed`, and no permit reads a claim:
110
+
111
+ ```bash
112
+ curl -si -X POST http://127.0.0.1:8780/form -H 'content-type: application/json' -H 'x-agent-custody-agent: shopping-agent' -d '{"email":"a@example.com"}'
113
+ ```
114
+
115
+ ```text
116
+ HTTP/1.1 403 Forbidden
117
+ x-agent-custody-class: claimed
118
+ ```
119
+
120
+ **A person.** On a real page the Turnstile widget produces a token, and the page sends it in `x-agent-custody-challenge`. The door asks Cloudflare whether it is good. With the test secret any token passes:
121
+
122
+ ```bash
123
+ curl -si -X POST http://127.0.0.1:8780/form -H 'content-type: application/json' -H 'x-agent-custody-challenge: XXXX.DUMMY.TOKEN.XXXX' -d '{"email":"a@example.com"}'
124
+ ```
125
+
126
+ ```text
127
+ HTTP/1.1 200 OK
128
+ x-agent-custody-class: unknown
129
+
130
+ thanks, you are signed up
131
+ ```
132
+
133
+ The class stays `unknown`: a passed challenge says the arrival solved a challenge, not who it is.
134
+
135
+ **An agent with a passport.** The principal signs a grant that names the agent and the routes it may use. The agent sends it, base64url-encoded, in `x-agent-custody-grant` (or as `Authorization: Bearer`):
136
+
137
+ ```bash
138
+ agent-custody grant --key keys/principal.key --principal agent-co --agent shopping-agent --scopes form --out grant.json
139
+ PASSPORT=$(node -e 'process.stdout.write(Buffer.from(require("fs").readFileSync("grant.json","utf8")).toString("base64url"))')
140
+ curl -si -X POST http://127.0.0.1:8780/form -H 'content-type: application/json' -H "x-agent-custody-grant: $PASSPORT" -d '{"email":"agent@example.com"}'
141
+ ```
142
+
143
+ ```text
144
+ HTTP/1.1 200 OK
145
+ x-agent-custody-receipt: 3e30a694-f144-4b78-9b57-a906c8777803
146
+ x-agent-custody-class: verified
147
+
148
+ thanks, you are signed up
149
+ ```
150
+
151
+ ## 7. Verify the receipts
152
+
153
+ Every arrival left a receipt in `receipts/`, refused or not, and every one is in the log. A sign-up has two: the door commits it to the log before your site hears of it, then receipts the outcome. Your receipt ids differ from the ones here; take them from the `x-agent-custody-receipt` headers.
154
+
155
+ The refused bot, checked with the door's public key and the log:
156
+
157
+ ```bash
158
+ agent-custody verify receipts/454a8bef-8044-4cc7-9806-b421918507d2.json --issuer-key keys/door.pub --log log.jsonl
159
+ ```
160
+
161
+ ```text
162
+ PASS policy decision consistent with execution (deny -> denied)
163
+ PASS log inclusion proof (leaf 2 of 3, root c1b6db0a0f60)
164
+
165
+ RESULT: VERIFIED
166
+
167
+ ISSUER: door (http), enforced in front of the business's own HTTP surface; the arriving party could not forge this receipt and is attested only when it presented a grant, and a request that reached the origin some other way leaves no receipt
168
+ ```
169
+
170
+ The agent, with the principal's key as well, so the passport is checked too:
171
+
172
+ ```bash
173
+ agent-custody verify receipts/3e30a694-f144-4b78-9b57-a906c8777803.json --issuer-key keys/door.pub --principal-key keys/principal.pub --log log.jsonl
174
+ ```
175
+
176
+ ```text
177
+ PASS delegation signature (principal key) (signed by 9ebc1bcd4701)
178
+ PASS executed tool within delegated scope (form)
179
+ PASS authorization logged before execution (authorization leaf 6, receipt leaf 7)
180
+
181
+ RESULT: VERIFIED
182
+
183
+ principal attested agent-co
184
+ agent attested shopping-agent
185
+ policy observed allow [policy2] policy fbb0e37266c4
186
+ ```
187
+
188
+ The output above is cut to the lines that matter; the full report lists every check. The request body is not in either receipt, only its digest: the door withholds by default ([what a receipt records](door.md#what-a-receipt-records-of-the-query-and-the-body)).
189
+
190
+ Stop the door and the stand-in site with `kill %1 %2`.
191
+
192
+ ## Before you put it in front of your own site
193
+
194
+ - **Use your own Turnstile keys.** Put the widget on the page that posts the form, set `siteKey`, the secret in `TURNSTILE_SECRET`, and `hostnames` to your site's hosts. A token serves one request, so the page takes a new one for each submit ([challenging a human](door.md#what-the-door-knows-about-an-arrival)).
195
+ - **Make the door the only way in.** A request that reaches your site some other way leaves no receipt. Bind the site to a private address, or have it require a header that only the door adds (`origin.headerEnv`).
196
+ - **Behind your own TLS proxy,** set `trustProxy` so the door reads the client's address, not the proxy's.
197
+ - **A passport is bearer-grade.** The door checks its signature, window, and scope, not that the sender holds the agent's key. Keep the time to live short.
198
+ - **Read [the door](door.md)** for every field of the config, and [door signals](door-signals.md) for what each fact about an arrival does and does not establish, before you write a policy for a route that matters.
package/docs/door.md CHANGED
@@ -2,6 +2,8 @@
2
2
 
3
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
4
 
5
+ New to the door? [Put the door in front of a site](door-quickstart.md) walks through one form in about fifteen minutes.
6
+
5
7
  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
8
 
7
9
  ```bash
@@ -249,7 +251,7 @@ execution observed denied: (reason withheld under the capture rule)
249
251
 
250
252
  The pass run's receipt records `challenge.outcome: "passed"`, and the door relayed the request. The fail run's receipt records `challenge.outcome: "failed"` with Cloudflare's code `invalid-input-response`, and the policy refused the request. The token does not appear in either receipt.
251
253
 
252
- **What this run shows, and what it does not.** Test keys prove the wire path, not bot detection. The door reaches the real `siteverify`, sends the secret and the token, and records the answer. A test secret gives a fixed answer and no widget runs, so the run says nothing about how well Turnstile tells a person from a bot. The run did not exercise the `unavailable` outcome, a hostname mismatch, an action mismatch, the `timeout-or-duplicate` code, or `remoteip` (the config sets no `trustProxy`, so the door sent none). `test/door.test.ts` covers those against a stubbed `siteverify`. In the output above, the two `sha256` digests are shortened to eight characters and `…`. Nothing else is changed. The CLI was `agent-custody` 0.16.2, run from this repository at commit `64285ef`.
254
+ **What this run shows, and what it does not.** Test keys prove the wire path, not bot detection. The door reaches the real `siteverify`, sends the secret and the token, and records the answer. A test secret gives a fixed answer and no widget runs, so the run says nothing about how well Turnstile tells a person from a bot. The run did not exercise the `unavailable` outcome, a hostname mismatch, an action mismatch, the `timeout-or-duplicate` code, or `remoteip` (the config sets no `trustProxy`, so the door sent none). `test/door.test.ts` covers those against a stubbed `siteverify`. In the output above, the two `sha256` digests are shortened to eight characters and `…`. Nothing else is changed. The CLI was `agent-custody` 0.16.2, run from this repository at commit `64285ef`. That version had no note for door receipts, so its `ISSUER` lines end with `unknown issuer kind`; later versions say what a door receipt proves there: the arriving party could not forge it and is attested only when it presented a grant, and a request that reached the origin some other way leaves no receipt.
253
255
 
254
256
  ## How an arrival becomes a Cedar request
255
257
 
@@ -20,7 +20,7 @@ jobs:
20
20
  runs-on: ubuntu-latest
21
21
  steps:
22
22
  - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
23
- - uses: svayatta/agent-custody@<commit sha of the release> # 0.16.3
23
+ - uses: svayatta/agent-custody@<commit sha of the release> # 0.16.4
24
24
  with:
25
25
  path: .custody/receipts
26
26
  issuer-key: .custody/keys/agent.pub
@@ -37,7 +37,7 @@ Pin the action to the commit of a release, as you pin every other action. A movi
37
37
  | `principal-key` | the public key files of the principals whose grants a gateway receipt carries, one path on each line; SDK and Claude Code hook receipts need none | |
38
38
  | `log-url` | the URL of the log; the action fetches the log key from it (`verify --log-url`) | |
39
39
  | `log-id` | the id that every tree head must name (`verify --log-id`) | |
40
- | `version` | the `@agent-custody/receipts` version that `npx` runs | `0.16.3` |
40
+ | `version` | the `@agent-custody/receipts` version that `npx` runs | `0.16.4` |
41
41
  | `github-token` | a token that can write pull request comments; an empty value writes the job summary only | `github.token` |
42
42
  | `comment-author` | the login of the account that `github-token` posts as; the action edits only a comment from this account | `github-actions[bot]` |
43
43
 
package/docs/sdk.md CHANGED
@@ -120,6 +120,8 @@ A rule with no annotation gives its id in place of the reason: `agent-custody de
120
120
 
121
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
122
 
123
+ When the denial receipt cannot be issued, the call is blocked all the same, and the reason ends with `(no receipt: <why>)` in place of the receipt id. `<why>` names the kind of failure and nothing more. In TypeScript it is `the receipt could not be recorded`. In Python it is `the sidecar could not be reached`, `the sidecar answered HTTP <status>`, `the sidecar refused the request`, `the sidecar's answer was malformed`, or `an unexpected <exception type>`. The reason goes into the model's context, and the error behind it can carry a log or sidecar URL with credentials in it, or the text of an upstream answer. So the error itself goes to stderr in TypeScript and to the `agent_custody` logger at `WARNING` in Python, never into the reason, and the URL in it is shown without its user, password, or query string. Every adapter that answers a deny with text works this way: Claude Code, the Claude Agent SDK and OpenAI Agents in both languages, OpenClaw, DeepSeek Harness, Hermes, Google ADK, and CrewAI. OpenAI Agents in both languages and CrewAI used to raise the error when the denial receipt failed; they now return the denial text, as the others do, and the tool still does not run. The Vercel AI `wrapTools` and `issuer.wrap` throw `PolicyDeniedError`, which needs a receipt id, so there a failed denial receipt still rejects with the log's error.
124
+
123
125
  ### The report
124
126
 
125
127
  ```bash
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agent-custody/receipts",
3
- "version": "0.16.3",
3
+ "version": "0.16.4",
4
4
  "mcpName": "io.github.svayatta/agent-custody",
5
5
  "description": "Proof of what your AI agents did. Give your agents real power, without losing control of them: signed, verifiable receipts for tool calls, an MCP gateway with Cedar or Rego policy, and a Merkle transparency log.",
6
6
  "license": "Apache-2.0",