@agent-custody/receipts 0.13.0 → 0.14.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 +16 -11
- package/dist/claude-init.d.ts +46 -0
- package/dist/claude-init.js +208 -0
- package/dist/cli.js +44 -0
- package/dist/deny-report.d.ts +30 -0
- package/dist/deny-report.js +106 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/log-admin.js +3 -3
- package/dist/log.d.ts +13 -2
- package/dist/log.js +97 -17
- package/dist/policy.d.ts +6 -0
- package/dist/policy.js +17 -0
- package/dist/sdk/claude.js +18 -2
- package/dist/sdk/index.d.ts +2 -0
- package/dist/sdk/index.js +3 -1
- package/dist/witness.js +3 -3
- package/docs/compliance.md +117 -7
- package/docs/policies.md +12 -0
- package/docs/sdk.md +83 -1
- package/docs/tutorials.md +2 -0
- package/docs/usage.md +1 -1
- package/package.json +3 -2
- package/templates/claude-code.cedar +96 -0
package/dist/log.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// Append-only Merkle log with RFC 6962 / RFC 9162 hashing and inclusion proofs.
|
|
2
2
|
// Leaves are stored as JSONL so anyone holding the file can recompute the root.
|
|
3
3
|
import { createHash } from "node:crypto";
|
|
4
|
-
import { appendFileSync,
|
|
4
|
+
import { appendFileSync, closeSync, mkdirSync, openSync, readSync, statSync, unlinkSync } from "node:fs";
|
|
5
5
|
import { dirname } from "node:path";
|
|
6
6
|
const h = (...parts) => {
|
|
7
7
|
const c = createHash("sha256");
|
|
@@ -153,26 +153,108 @@ export function verifyInclusion(leaf, proof, rootHex) {
|
|
|
153
153
|
}
|
|
154
154
|
return sn === 0 && r.toString("hex") === rootHex;
|
|
155
155
|
}
|
|
156
|
+
const LOCK_STALE_MS = 10_000;
|
|
157
|
+
const LOCK_WAIT_MS = 20_000;
|
|
158
|
+
const pause = (ms) => Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, ms);
|
|
156
159
|
export class MerkleLog {
|
|
157
160
|
hashes = [];
|
|
158
|
-
tree;
|
|
161
|
+
tree = new SubtreeCache(this.hashes);
|
|
159
162
|
file;
|
|
163
|
+
bytes = 0;
|
|
164
|
+
inode = -1;
|
|
160
165
|
constructor(file) {
|
|
161
166
|
this.file = file;
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
167
|
+
mkdirSync(dirname(file), { recursive: true });
|
|
168
|
+
this.catchUp();
|
|
169
|
+
}
|
|
170
|
+
/** Reads the leaves that another handle or process appended since the last read. A file that was replaced or cut short is read again from the start. */
|
|
171
|
+
catchUp() {
|
|
172
|
+
let st;
|
|
173
|
+
try {
|
|
174
|
+
st = statSync(this.file);
|
|
175
|
+
}
|
|
176
|
+
catch {
|
|
177
|
+
st = null;
|
|
178
|
+
}
|
|
179
|
+
if (!st || st.ino !== this.inode || st.size < this.bytes) {
|
|
180
|
+
this.hashes.length = 0;
|
|
181
|
+
this.tree = new SubtreeCache(this.hashes);
|
|
182
|
+
this.bytes = 0;
|
|
183
|
+
}
|
|
184
|
+
if (!st)
|
|
185
|
+
return;
|
|
186
|
+
this.inode = st.ino;
|
|
187
|
+
if (st.size === this.bytes)
|
|
188
|
+
return;
|
|
189
|
+
const buf = Buffer.alloc(st.size - this.bytes);
|
|
190
|
+
const fd = openSync(this.file, "r");
|
|
191
|
+
let got = 0;
|
|
192
|
+
try {
|
|
193
|
+
while (got < buf.length) {
|
|
194
|
+
const n = readSync(fd, buf, got, buf.length - got, this.bytes + got);
|
|
195
|
+
if (n === 0)
|
|
196
|
+
break;
|
|
197
|
+
got += n;
|
|
171
198
|
}
|
|
172
199
|
}
|
|
173
|
-
|
|
174
|
-
|
|
200
|
+
finally {
|
|
201
|
+
closeSync(fd);
|
|
202
|
+
}
|
|
203
|
+
this.bytes += got;
|
|
204
|
+
for (const line of buf.subarray(0, got).toString("utf8").split("\n")) {
|
|
205
|
+
if (!line.trim())
|
|
206
|
+
continue;
|
|
207
|
+
const parsed = JSON.parse(line);
|
|
208
|
+
// A pruned leaf keeps only its hash, and a leaf appended by hash never had content here: the tree, its
|
|
209
|
+
// roots, and every proof are the same either way.
|
|
210
|
+
this.hashes.push(typeof parsed === "string" ? leafHash(parsed) : Buffer.from((parsed.pruned ?? parsed.hash), "hex"));
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
/**
|
|
214
|
+
* Runs `fn` while this process holds `<file>.lock`, made with O_EXCL. Each hook of a coding agent is its own
|
|
215
|
+
* process, so appends overlap. A lock older than ten seconds belongs to a process that died: the next writer removes it.
|
|
216
|
+
*/
|
|
217
|
+
locked(fn) {
|
|
218
|
+
const lock = `${this.file}.lock`;
|
|
219
|
+
const deadline = Date.now() + LOCK_WAIT_MS;
|
|
220
|
+
for (;;) {
|
|
221
|
+
try {
|
|
222
|
+
closeSync(openSync(lock, "wx"));
|
|
223
|
+
break;
|
|
224
|
+
}
|
|
225
|
+
catch (e) {
|
|
226
|
+
if (e.code !== "EEXIST")
|
|
227
|
+
throw e;
|
|
228
|
+
}
|
|
229
|
+
try {
|
|
230
|
+
if (Date.now() - statSync(lock).mtimeMs > LOCK_STALE_MS)
|
|
231
|
+
unlinkSync(lock);
|
|
232
|
+
}
|
|
233
|
+
catch {
|
|
234
|
+
// The holder released the lock between the two calls. Try again.
|
|
235
|
+
}
|
|
236
|
+
if (Date.now() > deadline)
|
|
237
|
+
throw new Error(`${lock} is held by another process, so the log is not appended. Remove the file if no agent-custody process runs.`);
|
|
238
|
+
pause(2 + Math.random() * 8);
|
|
175
239
|
}
|
|
240
|
+
try {
|
|
241
|
+
return fn();
|
|
242
|
+
}
|
|
243
|
+
finally {
|
|
244
|
+
try {
|
|
245
|
+
unlinkSync(lock);
|
|
246
|
+
}
|
|
247
|
+
catch { /* a writer removed it as stale */ }
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
/** Under the lock: reads what other writers appended, then writes this line, so each leaf gets the next index. */
|
|
251
|
+
appendLine(line, hash) {
|
|
252
|
+
return this.locked(() => {
|
|
253
|
+
this.catchUp();
|
|
254
|
+
appendFileSync(this.file, line);
|
|
255
|
+
this.bytes += Buffer.byteLength(line);
|
|
256
|
+
return this.pushHash(hash());
|
|
257
|
+
});
|
|
176
258
|
}
|
|
177
259
|
get size() {
|
|
178
260
|
return this.hashes.length;
|
|
@@ -183,8 +265,7 @@ export class MerkleLog {
|
|
|
183
265
|
}
|
|
184
266
|
/** Appends a leaf (an opaque string, typically a canonical JSON envelope). Returns its proof against the new root. */
|
|
185
267
|
append(leaf) {
|
|
186
|
-
|
|
187
|
-
return this.pushHash(leafHash(leaf));
|
|
268
|
+
return this.appendLine(JSON.stringify(leaf) + "\n", () => leafHash(leaf));
|
|
188
269
|
}
|
|
189
270
|
/**
|
|
190
271
|
* Appends a leaf by its RFC 6962 leaf hash, sha256(0x00 || leaf), as hex. The log commits to the leaf without ever
|
|
@@ -193,8 +274,7 @@ export class MerkleLog {
|
|
|
193
274
|
appendHash(leafHashHex) {
|
|
194
275
|
if (!/^[0-9a-f]{64}$/.test(leafHashHex))
|
|
195
276
|
throw new Error("leafHash must be 64 lowercase hex characters");
|
|
196
|
-
|
|
197
|
-
return this.pushHash(Buffer.from(leafHashHex, "hex"));
|
|
277
|
+
return this.appendLine(JSON.stringify({ hash: leafHashHex }) + "\n", () => Buffer.from(leafHashHex, "hex"));
|
|
198
278
|
}
|
|
199
279
|
pushHash(hash) {
|
|
200
280
|
this.hashes.push(hash);
|
package/dist/policy.d.ts
CHANGED
|
@@ -18,6 +18,12 @@ export interface PolicyRequest {
|
|
|
18
18
|
export declare function hasPermitRule(policyText: string): boolean;
|
|
19
19
|
/** Why Cedar cannot parse the policy set, or an empty list when it can. */
|
|
20
20
|
export declare function policyParseErrors(policyText: string): string[];
|
|
21
|
+
/** The text of each static policy, in file order. Cedar names them `policy0`, `policy1`, and so on in this order. */
|
|
22
|
+
export declare function policyRules(policyText: string): string[];
|
|
23
|
+
/** The `@reason("...")` annotation of each static policy, in file order, or null for a policy without one. */
|
|
24
|
+
export declare function policyReasons(policyText: string): (string | null)[];
|
|
25
|
+
/** The reason of the policy that a Cedar id such as `policy3` names: its `@reason` text, or the id when it has none. */
|
|
26
|
+
export declare function reasonOfRule(id: string, reasons: readonly (string | null)[]): string;
|
|
21
27
|
export declare function policyDigest(policyText: string): string;
|
|
22
28
|
/**
|
|
23
29
|
* Cedar's JSON context reads `{ "__entity": … }` and `{ "__extn": … }` as typed values. Arguments come from the agent,
|
package/dist/policy.js
CHANGED
|
@@ -16,6 +16,23 @@ export function policyParseErrors(policyText) {
|
|
|
16
16
|
const parsed = cedar.checkParsePolicySet({ staticPolicies: policyText });
|
|
17
17
|
return parsed.type === "success" ? [] : parsed.errors.map((e) => e.message);
|
|
18
18
|
}
|
|
19
|
+
/** The text of each static policy, in file order. Cedar names them `policy0`, `policy1`, and so on in this order. */
|
|
20
|
+
export function policyRules(policyText) {
|
|
21
|
+
const parts = cedar.policySetTextToParts(policyText);
|
|
22
|
+
return parts.type === "success" ? parts.policies : [];
|
|
23
|
+
}
|
|
24
|
+
/** The `@reason("...")` annotation of each static policy, in file order, or null for a policy without one. */
|
|
25
|
+
export function policyReasons(policyText) {
|
|
26
|
+
return policyRules(policyText).map((rule) => {
|
|
27
|
+
const j = cedar.policyToJson(rule);
|
|
28
|
+
const reason = j.type === "success" ? j.json.annotations?.reason : undefined;
|
|
29
|
+
return typeof reason === "string" && reason.trim() ? reason.trim() : null;
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
/** The reason of the policy that a Cedar id such as `policy3` names: its `@reason` text, or the id when it has none. */
|
|
33
|
+
export function reasonOfRule(id, reasons) {
|
|
34
|
+
return reasons[Number(id.replace(/^policy/, ""))] ?? id;
|
|
35
|
+
}
|
|
19
36
|
export function policyDigest(policyText) {
|
|
20
37
|
return sha256Hex(policyText);
|
|
21
38
|
}
|
package/dist/sdk/claude.js
CHANGED
|
@@ -1,6 +1,15 @@
|
|
|
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
|
+
import { reasonOfRule } from "../policy.js";
|
|
3
4
|
import { createSdkIssuer, receiptIdOf, denies } from "./index.js";
|
|
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
|
+
function denialText(issuer, policy, reason, evidence) {
|
|
7
|
+
if (policy.reasons.length === 0)
|
|
8
|
+
return `agent-custody: ${reason} (${evidence})`;
|
|
9
|
+
const ids = [...policy.reasons].sort((a, b) => Number(a.replace(/^policy/, "")) - Number(b.replace(/^policy/, "")));
|
|
10
|
+
const said = [...ids.map((id) => reasonOfRule(id, issuer.ruleReasons)), ...policy.errors].join("; ");
|
|
11
|
+
return `agent-custody denied this call: ${said} (${ids.length === 1 ? "rule" : "rules"} ${ids.join(", ")}, ${evidence})`;
|
|
12
|
+
}
|
|
4
13
|
function toEvent(input) {
|
|
5
14
|
const raw = input.tool_input;
|
|
6
15
|
const args = raw && typeof raw === "object" && !Array.isArray(raw) ? raw : { input: raw ?? null };
|
|
@@ -18,13 +27,20 @@ export async function handleHookEvent(issuer, input) {
|
|
|
18
27
|
const policy = issuer.decide(ev);
|
|
19
28
|
if (denies(policy)) {
|
|
20
29
|
const reason = [...policy.reasons, ...policy.errors].join("; ") || "no permit policy matched";
|
|
21
|
-
|
|
30
|
+
// A hook that throws does not block the call, so a log outage must not cost the denial.
|
|
31
|
+
let evidence;
|
|
32
|
+
try {
|
|
33
|
+
evidence = `receipt ${receiptIdOf(await issuer.record(ev, { status: "denied", reason }, policy))}`;
|
|
34
|
+
}
|
|
35
|
+
catch (e) {
|
|
36
|
+
evidence = `no receipt: ${e instanceof Error ? e.message : String(e)}`;
|
|
37
|
+
}
|
|
22
38
|
return {
|
|
23
39
|
continue: true,
|
|
24
40
|
hookSpecificOutput: {
|
|
25
41
|
hookEventName: "PreToolUse",
|
|
26
42
|
permissionDecision: "deny",
|
|
27
|
-
permissionDecisionReason:
|
|
43
|
+
permissionDecisionReason: denialText(issuer, policy, reason, evidence),
|
|
28
44
|
},
|
|
29
45
|
};
|
|
30
46
|
}
|
package/dist/sdk/index.d.ts
CHANGED
|
@@ -27,6 +27,8 @@ export interface SdkIssuer {
|
|
|
27
27
|
keyid: string;
|
|
28
28
|
/** where the leaves go: the local file or the remote log */
|
|
29
29
|
log: LogSink;
|
|
30
|
+
/** The `@reason` text of each policy in the policy file, in file order, or null for a policy without one. Parsed once at load. */
|
|
31
|
+
ruleReasons: readonly (string | null)[];
|
|
30
32
|
/** Evaluates the configured policy for a call. Returns null when no policy is configured. */
|
|
31
33
|
decide(ev: ToolEvent): PolicyDecision | null;
|
|
32
34
|
/** Issues one receipt for a completed, failed, denied, or errored call. Rejects if the log refuses it. */
|
package/dist/sdk/index.js
CHANGED
|
@@ -7,7 +7,7 @@ import { digestOf, loadPrivateKey } from "../crypto.js";
|
|
|
7
7
|
import { createIssuer } from "../issue.js";
|
|
8
8
|
import { openExporter } from "../otel.js";
|
|
9
9
|
import { openLog } from "../log-sink.js";
|
|
10
|
-
import { evaluate } from "../policy.js";
|
|
10
|
+
import { evaluate, policyReasons } from "../policy.js";
|
|
11
11
|
export const SDK_VERSION = "0.1.0";
|
|
12
12
|
/** True when a decision is a deny that must be enforced: a deny made in observe mode (`enforced: false`) is recorded, not acted on. */
|
|
13
13
|
export function denies(policy) {
|
|
@@ -36,6 +36,7 @@ export function createSdkIssuer(cfg) {
|
|
|
36
36
|
// the capture rules are applied by the issuer to every statement it signs, so every adapter's receipt gets them
|
|
37
37
|
const issuer = createIssuer(key, cfg.receiptsDir, openLog(cfg, key), { exporter: openExporter(cfg), capture: { rules: cfg.capture, key: captureKey } });
|
|
38
38
|
const policyText = cfg.policyFile ? readFileSync(cfg.policyFile, "utf8") : null;
|
|
39
|
+
const ruleReasons = policyText === null ? [] : policyReasons(policyText);
|
|
39
40
|
const decide = (ev) => {
|
|
40
41
|
if (policyText === null)
|
|
41
42
|
return null;
|
|
@@ -68,6 +69,7 @@ export function createSdkIssuer(cfg) {
|
|
|
68
69
|
agentId: cfg.agentId,
|
|
69
70
|
keyid: issuer.keyid,
|
|
70
71
|
log: issuer.log,
|
|
72
|
+
ruleReasons,
|
|
71
73
|
decide,
|
|
72
74
|
record,
|
|
73
75
|
wrap(tool, fn, meta = {}) {
|
package/dist/witness.js
CHANGED
|
@@ -41,7 +41,7 @@ export class Witness {
|
|
|
41
41
|
}
|
|
42
42
|
}
|
|
43
43
|
async logKeys() {
|
|
44
|
-
const res = await this.f(new URL("/.well-known/agent-custody-log.json", this.o.logUrl));
|
|
44
|
+
const res = await this.f(new URL("/.well-known/agent-custody-log.json", this.o.logUrl), { signal: AbortSignal.timeout(10_000) });
|
|
45
45
|
if (!res.ok)
|
|
46
46
|
throw new Error(`log key document: ${res.status}`);
|
|
47
47
|
const doc = (await res.json());
|
|
@@ -49,7 +49,7 @@ export class Witness {
|
|
|
49
49
|
}
|
|
50
50
|
async latest(tenant) {
|
|
51
51
|
const base = this.o.checkpointsUrl.endsWith("/") ? this.o.checkpointsUrl : `${this.o.checkpointsUrl}/`;
|
|
52
|
-
const res = await this.f(new URL(`${safe(tenant)}/latest.json`, base));
|
|
52
|
+
const res = await this.f(new URL(`${safe(tenant)}/latest.json`, base), { signal: AbortSignal.timeout(10_000) });
|
|
53
53
|
if (res.status === 404)
|
|
54
54
|
return null;
|
|
55
55
|
if (!res.ok)
|
|
@@ -59,7 +59,7 @@ export class Witness {
|
|
|
59
59
|
async proof(tenant, oldSize, newSize) {
|
|
60
60
|
const base = this.o.logUrl.endsWith("/") ? this.o.logUrl : `${this.o.logUrl}/`;
|
|
61
61
|
const path = tenant === "default" ? `consistency?old=${oldSize}&new=${newSize}` : `t/${tenant}/consistency?old=${oldSize}&new=${newSize}`;
|
|
62
|
-
const res = await this.f(new URL(path, base));
|
|
62
|
+
const res = await this.f(new URL(path, base), { signal: AbortSignal.timeout(10_000) });
|
|
63
63
|
if (!res.ok)
|
|
64
64
|
throw new Error(`consistency proof for ${tenant}: ${res.status}`);
|
|
65
65
|
return (await res.json()).hashes;
|
package/docs/compliance.md
CHANGED
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
Auditors ask for controls by their names. This page maps the requirements they cite most to the artefacts agent-custody produces, so a security questionnaire can be answered with a file rather than a paragraph. It is a map, not a certificate: the artefacts are evidence that a control operated, and the control itself, the policy, the grant, the retention window, the person who reviews an alarm, is yours.
|
|
4
4
|
|
|
5
|
+
This page is dated. The SOC 2, ISO/IEC 27001, and UK GDPR sections below are not re-checked against primary text since they were first written. The section "Regulations and frameworks for AI agents" carries a primary source and an "as of" date for each framework. No part of this page says that the product makes you compliant.
|
|
6
|
+
|
|
5
7
|
Two rules keep the answers honest. First, say which producer made the receipt: a gateway receipt was enforced outside the agent's process, an SDK receipt is the agent's own report, and the receipt's `issuer.kind` says which. Second, say where the log runs: with the default local log the operator can rewrite history, with a log run by someone else they cannot, and with a witness neither operator can. The [proof table](../README.md#what-a-receipt-proves-and-what-it-does-not) has the full list of claims and against whom each holds.
|
|
6
8
|
|
|
7
9
|
## The artefacts
|
|
@@ -41,14 +43,122 @@ Two rules keep the answers honest. First, say which producer made the receipt: a
|
|
|
41
43
|
| A.8.16, monitoring activities | networks, systems, and applications are monitored | `log-check` from a machine that is not the log's, and the per-receipt spans in the SIEM |
|
|
42
44
|
| A.8.32, change management | changes are subject to change management | the policy digest, the grant's window, and the receipts either side of a change; for agent-made changes, the merge gate below |
|
|
43
45
|
|
|
44
|
-
##
|
|
46
|
+
## Regulations and frameworks for AI agents
|
|
45
47
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
|
51
|
-
|
|
|
48
|
+
This section was checked against primary sources on 2026-11-02. Each row links to the primary text. Each framework has its own "as of" date. A rule can change after that date. Open the link before you rely on a date or a quotation.
|
|
49
|
+
|
|
50
|
+
Read the last column of each table first. It states what a receipt does not supply. No row says that a receipt makes you compliant. Compliance depends on facts that no receipt records, and on how a regulator or an auditor reads the rule. This page is not legal advice.
|
|
51
|
+
|
|
52
|
+
| framework | kind | status on 2026-11-02 | applies from | as of |
|
|
53
|
+
| --- | --- | --- | --- | --- |
|
|
54
|
+
| [EU AI Act](#eu-ai-act), Regulation (EU) 2024/1689 | regulation | in force. The Digital Omnibus on AI, Regulation (EU) 2026/1744, is adopted law, not a proposal | high-risk duties in Chapter III, Sections 1 to 3: 2 December 2027 for Annex III systems, 2 August 2028 for Annex I systems | 2026-11-02 |
|
|
55
|
+
| [FINRA](#finra) | existing rules and a guidance report | no new rule for agents. The 2026 report is guidance | not applicable | 2026-11-02 |
|
|
56
|
+
| [MAS](#mas-singapore), Guidelines on Artificial Intelligence Risk Management | supervisory expectations | issued 7 October 2026 | 7 October 2027. Sections 5 and 6 may be met by 7 October 2028 | 2026-11-02 |
|
|
57
|
+
| [Colorado](#colorado), SB26-189 | state statute | signed into law | 1 January 2027, for consequential decisions made on or after that date | 2026-11-02 |
|
|
58
|
+
| [DORA](#dora), Regulation (EU) 2022/2554 | regulation | applies | 17 January 2025 | 2026-11-02 |
|
|
59
|
+
| [CSA AICM](#csa-ai-controls-matrix) | voluntary control framework | version 1.1 is published | not applicable | 2026-11-02 |
|
|
60
|
+
| [OWASP agentic guidance](#owasp-top-10-for-agentic-applications) | voluntary risk list | 2026 edition, December 2025 | not applicable | 2026-11-02 |
|
|
61
|
+
| [ISO/IEC 42001](#iso-iec-42001) | voluntary management system standard | edition 1, 2023 | not applicable | 2026-11-02 |
|
|
62
|
+
|
|
63
|
+
### EU AI Act
|
|
64
|
+
|
|
65
|
+
**Dates.** The regulation as first published sets the general date of application at 2 August 2026 ([Article 113](https://eur-lex.europa.eu/eli/reg/2024/1689/oj)). Regulation [(EU) 2026/1744](https://eur-lex.europa.eu/eli/reg/2026/1744/oj), the Digital Omnibus on AI, replaces point (c) of the third paragraph of Article 113. It is dated 8 July 2026. It appeared in the Official Journal on 24 July 2026. It enters into force on the third day after publication, which is 27 July 2026. It is adopted law. Chapter III, Sections 1, 2, and 3, now apply from:
|
|
66
|
+
|
|
67
|
+
- 2 December 2027, for AI systems classified as high-risk under Article 6(2) and Annex III;
|
|
68
|
+
- 2 August 2028, for AI systems classified as high-risk under Article 6(1) and Annex I.
|
|
69
|
+
|
|
70
|
+
Articles 12 and 14 are in Section 2. Articles 19 and 26 are in Section 3. So none of them applies to a high-risk system on 2026-11-02. The Omnibus does not amend Article 12, 14, 19, or 26, and it does not amend the list in Annex III. The Omnibus changes other dates too, for example for Article 50(2) and for new Article 5 prohibitions. This page covers the logging duties only. This page lists no later amending act. Check the Official Journal before you rely on a date.
|
|
71
|
+
|
|
72
|
+
**Scope.** Articles 12, 19, and 26(6) bind high-risk AI systems. Annex III lists eight areas: biometrics; critical infrastructure; education and vocational training; employment and workers' management; access to essential private and public services and benefits (including credit scoring and life and health insurance pricing); law enforcement; migration, asylum, and border control; and the administration of justice and democratic processes. A general agent that calls tools is not high-risk by that fact. It is in scope when its intended use sits in one of these areas, or when Article 6(1) and Annex I make it high-risk. Article 6(3) lets a provider show that an Annex III system is not high-risk. It never excludes a system that profiles natural persons.
|
|
73
|
+
|
|
74
|
+
| provision | what it asks | what a receipt supplies | what a receipt does not supply |
|
|
75
|
+
| --- | --- | --- | --- |
|
|
76
|
+
| [Article 12](https://eur-lex.europa.eu/eli/reg/2024/1689/oj), record-keeping | High-risk systems "technically allow for the automatic recording of events (logs) over the lifetime of the system". The logs help to identify risk situations, to support post-market monitoring, and to monitor operation under Article 26(5). Systems in Annex III point 1(a) have more minimum items in Article 12(3). | One signed receipt for each tool call that goes through the gateway: the grant, the policy decision and its digest, digests of the arguments and the result, and the position in the log. `explain` traces an action to its causes and consequences. | Events that are not tool calls, for example what the model did inside one step. The items in Article 12(3), for example the reference database and the input data that matched. A decision on whether your system is high-risk. An SDK receipt is the agent's own report, so it is weaker evidence than a gateway receipt. |
|
|
77
|
+
| [Article 19](https://eur-lex.europa.eu/eli/reg/2024/1689/oj), logs kept by providers | Providers keep the Article 12(1) logs "to the extent such logs are under their control". The period suits the intended purpose and is "at least six months", unless other Union or national law says otherwise, in particular data protection law. Providers that are financial institutions keep the logs with the documentation that financial services law requires. | Receipts and the log stay with the party that runs the gateway. The hosted log holds hashes only, so the receipts stay with you. `prune` keeps every proof valid after the content goes. In the memory server, retention windows apply by space and a legal hold overrides them. | The six-month minimum. `prune` takes any cutoff that you give it and has no minimum. You set the period, and you check it against data protection law. The hosted log is not a copy of the receipts. Logs outside the gateway. |
|
|
78
|
+
| [Article 26(6)](https://eur-lex.europa.eu/eli/reg/2024/1689/oj), logs kept by deployers | Deployers keep the logs that the high-risk system generates, "to the extent such logs are under their control", for at least six months, unless other law says otherwise. Deployers that are financial institutions keep them with their financial services documentation. | The same receipts and the same log. A tenant on the hosted log has its own log identifier and checkpoints, and an export that works with no server. | The same limits as Article 19. A receipt is a record of a tool call through the gateway. It may not be all the logs that the system generates. |
|
|
79
|
+
| [Article 26(5)](https://eur-lex.europa.eu/eli/reg/2024/1689/oj), monitoring by deployers | Deployers monitor the operation of the system on the basis of the instructions for use. They inform the provider, and in some cases the market surveillance authority. They suspend use when there is a risk. | The monitor, `log-check`, the OpenTelemetry and Splunk exports, and `agent-custody revoke`, which makes every session under a grant refuse its next call. | The decision that a risk exists. The duty to inform the provider or an authority. The instructions for use. |
|
|
80
|
+
| [Article 14](https://eur-lex.europa.eu/eli/reg/2024/1689/oj), human oversight | Systems are designed so that natural persons can oversee them, understand their output, and stop them. | The grant is a human's signature over what the agent may do. A payload-bound approval records the human who approved one action. Retract and forget are receipted calls. | The human-machine interface. The training of the overseer. Evidence that the overseer understood the output. |
|
|
81
|
+
|
|
82
|
+
Source for this section: Regulation (EU) 2024/1689 and Regulation (EU) 2026/1744 in the Official Journal. As of 2026-11-02.
|
|
83
|
+
|
|
84
|
+
### FINRA
|
|
85
|
+
|
|
86
|
+
FINRA has no rule written for AI agents. Its rules are technology-neutral. Regulatory Notice 24-09 (27 June 2024) says that FINRA rules apply to the use of generative AI "just as they apply when member firms use any other technology or tool", and that it "does not create new legal or regulatory requirements". The 2026 Annual Regulatory Oversight Report (9 December 2025) adds a section on AI agents. It is guidance, not a rule.
|
|
87
|
+
|
|
88
|
+
| provision | what it asks | what a receipt supplies | what a receipt does not supply |
|
|
89
|
+
| --- | --- | --- | --- |
|
|
90
|
+
| Rule 3110, supervision, as the [2026 report](https://www.finra.org/rules-guidance/guidance/reports/2026-finra-annual-regulatory-oversight-report/gen-ai) cites it | A member firm has "a reasonably designed supervisory system tailored to its business". | Per-call evidence that a supervisor can sample: who authorized the call, the policy decision, and the result. | The supervisory system itself: the procedures, the reviews, and the person who reads the records. |
|
|
91
|
+
| [2026 report, AI agents](https://www.finra.org/rules-guidance/guidance/reports/2026-finra-annual-regulatory-oversight-report/gen-ai) | Lists the risks of autonomy without human validation, of action beyond the intended scope and authority, and of outcomes that are "difficult to trace or explain". Says that firms may consider "how to track agent actions and decisions" and how to set guardrails. | A receipt for each call, allowed or denied. The grant states the scope, and the policy enforces it outside the agent's process. `explain` traces one action. | A record of the agent's reasoning. A guarantee that every action went through the gateway. A human check, unless you use approvals. |
|
|
92
|
+
| [2026 report, generative AI](https://www.finra.org/rules-guidance/guidance/reports/2026-finra-annual-regulatory-oversight-report/gen-ai) | Says that generative AI "can implicate rules regarding supervision, communications, recordkeeping and fair dealing". Says that a firm may consider "storing prompt and output logs". The section names no recordkeeping rule. | Tool-call records in a signed, tamper-evident log. | Prompts and model outputs: a receipt has no prompt text. Customer communications. A finding that a record meets a books-and-records storage rule. This page did not check such a rule. |
|
|
93
|
+
|
|
94
|
+
Sources: the 2026 report, in the links above; [Regulatory Notice 24-09](https://www.finra.org/rules-guidance/notices/24-09). As of 2026-11-02.
|
|
95
|
+
|
|
96
|
+
### MAS, Singapore
|
|
97
|
+
|
|
98
|
+
The Monetary Authority of Singapore issued its Guidelines on Artificial Intelligence Risk Management on 7 October 2026. They set supervisory expectations. They apply to all financial institutions and all forms of AI, and paragraph 1.5 names AI agents. The guidelines take effect on 7 October 2027. Paragraph 1.8 says that firms may meet the expectations in Sections 3 and 4 from that date, and those in Sections 5 and 6 by 7 October 2028. The two paragraphs below are in Section 5.
|
|
99
|
+
|
|
100
|
+
| provision | what it asks | what a receipt supplies | what a receipt does not supply |
|
|
101
|
+
| --- | --- | --- | --- |
|
|
102
|
+
| [Paragraph 5.9(d)](https://www.mas.gov.sg/-/media/mas-media-library/regulation/guidelines/bd/guidelines-on-artificial-intelligence-risk-management-for-financial-institutions/guidelines-on-artificial-intelligence-risk-management.pdf), human oversight: documentation and review | Processes "to document logs and other records generated through development, deployment, operation, monitoring and incident management", and a regular review of human oversight decisions and interventions. | Operation records: each call with its decision. The grant, approval, retract, and forget calls are receipts too, so they show when a human intervened. | Logs of development. The review process and its findings. |
|
|
103
|
+
| [Paragraph 5.23(d)](https://www.mas.gov.sg/-/media/mas-media-library/regulation/guidelines/bd/guidelines-on-artificial-intelligence-risk-management-for-financial-institutions/guidelines-on-artificial-intelligence-risk-management.pdf), post-deployment monitoring: documentation | Records of monitoring, results, incidents, and remediation. Access to AI systems "should be strictly controlled and logged". For generative AI or AI agents, "enhanced documentation" such as "logging prompts and model responses, together with applicable model versions and reasoning processes" may be considered. | A tamper-evident record of tool calls and of the policy that decided each one. The receipt names the model, in a field marked `claimed`. | Prompts, model responses, and reasoning. A verified model version: no hosted provider signs the model identity. Records of the monitoring that people did. |
|
|
104
|
+
|
|
105
|
+
Source: the [MAS guidelines](https://www.mas.gov.sg/regulation/guidelines/guidelines-on-artificial-intelligence-risk-management-for-financial-institutions), dated 7 October 2026. As of 2026-11-02.
|
|
106
|
+
|
|
107
|
+
### Colorado
|
|
108
|
+
|
|
109
|
+
Colorado Senate Bill 26-189 repeals and re-enacts part 17 of article 1 of title 6 of the Colorado Revised Statutes, which was the 2024 Colorado AI Act. It regulates "automated decision-making technology" (ADMT) that is used to materially influence a "consequential decision". The bill page shows that the Governor signed it on 14 May 2026. Section 5 of the act says that the act takes effect on 1 January 2027, except a few provisions that took effect on passage. It also says that the act applies to consequential decisions made on or after 1 January 2027. A consequential decision is one about a covered domain: education, employment, residential real estate, a financial or lending service, insurance, health-care services, or essential government services and public benefits. The Attorney General enforces the act. The act creates no new private right of action. The act tells the Attorney General to adopt rules on post-adverse-outcome disclosure on or before 1 January 2027. Read those rules, and check for any court order, before you rely on the date.
|
|
110
|
+
|
|
111
|
+
| provision | what it asks | what a receipt supplies | what a receipt does not supply |
|
|
112
|
+
| --- | --- | --- | --- |
|
|
113
|
+
| [Section 6-1-1703](https://leg.colorado.gov/bill_files/116489/download), deployer record keeping | A deployer retains, for not less than three years after the date of a consequential decision, "records reasonably necessary to demonstrate compliance" with part 17. The records may include ADMT version identifiers, changelogs, and documentation of material mitigation changes. | A signed record of each tool call. The policy digest identifies the exact policy that decided the call, so a change to the policy is visible. `prune` and the retention windows let you keep a record for the period that you choose. | The notices, the post-adverse-outcome disclosures, and the consumer rights that part 17 creates. A test of whether a decision is consequential. An ADMT version identifier: the model identity is `claimed`. A three-year minimum: `prune` has no minimum. The arguments of a call can hold personal data, so privacy law can ask you to delete what this law asks you to keep. |
|
|
114
|
+
| [Section 6-1-1702](https://leg.colorado.gov/bill_files/116489/download), developer documentation | From 1 January 2027, a developer of a covered ADMT makes documentation available to each deployer. A developer retains records for not less than three years after their creation. | Nothing here. A receipt records a call, not the documentation of a developer. | The developer documentation. |
|
|
115
|
+
|
|
116
|
+
Sources: the [bill page](https://leg.colorado.gov/bills/sb26-189) and the [enrolled act](https://leg.colorado.gov/bill_files/116489/download) of Senate Bill 26-189. As of 2026-11-02.
|
|
117
|
+
|
|
118
|
+
### DORA
|
|
119
|
+
|
|
120
|
+
Regulation (EU) 2022/2554 applies from 17 January 2025 (Article 64). It covers the financial entities listed in Article 2, for example credit institutions, payment institutions, investment firms, and insurance undertakings. It also covers ICT third-party service providers. The text of DORA and the text of the logging standard below do not use the term "artificial intelligence". Each firm decides whether it treats the tool calls of an agent as ICT operations.
|
|
121
|
+
|
|
122
|
+
| provision | what it asks | what a receipt supplies | what a receipt does not supply |
|
|
123
|
+
| --- | --- | --- | --- |
|
|
124
|
+
| [Article 17](https://eur-lex.europa.eu/eli/reg/2022/2554/oj), ICT-related incident management | Financial entities "record all ICT-related incidents and significant cyber threats". The process identifies, tracks, logs, categorises, and classifies incidents. | Evidence about what an agent did around an incident: the action pack, the blast radius of a wrong fact, and the receipts of denied calls. | The incident register. The classification under Article 18. The report to the authority. The root cause analysis. |
|
|
125
|
+
| [Delegated Regulation (EU) 2024/1774, Article 12](https://eur-lex.europa.eu/eli/reg_del/2024/1774/oj), logging | Logging procedures, protocols, and tools. They log events about access control and identity management, change management, and ICT operations. They protect log systems "against tampering, deletion, and unauthorised access", and they synchronise clocks. The entity sets the retention period. | A signed, hashed, append-only log. The audit proves that nobody rewrote the log between two points. The grant records who may act. The policy digest records a change to the policy. | Logs of capacity management and network traffic. The retention period: you set it. Synchronised clocks: the timestamp in a receipt is the producer's own. |
|
|
126
|
+
|
|
127
|
+
Sources: Regulation (EU) 2022/2554 and Delegated Regulation (EU) 2024/1774 in the Official Journal. As of 2026-11-02.
|
|
128
|
+
|
|
129
|
+
### CSA AI Controls Matrix
|
|
130
|
+
|
|
131
|
+
The AI Controls Matrix (AICM) of the Cloud Security Alliance is a voluntary framework. Version 1.1 has 247 control objectives in 18 domains. It maps to ISO/IEC 42001, ISO/IEC 27001, the EU AI Act, NIST AI RMF and AI 600-1, BSI AIC4, and AIUC-1. Its questionnaire, the AI-CAIQ, has 320 questions. The CSA artifact page gives 22 June 2026 as the release date. The CSA announcement is dated 14 July 2026.
|
|
132
|
+
|
|
133
|
+
| provision | what it asks | what a receipt supplies | what a receipt does not supply |
|
|
134
|
+
| --- | --- | --- | --- |
|
|
135
|
+
| [AICM v1.1](https://cloudsecurityalliance.org/artifacts/ai-controls-matrix-v1-1) as a whole | Control objectives that an organization assesses itself against, or that a third party assesses, through the AI-CAIQ. | Evidence for any control objective that asks for a record of what an AI system did: the artefacts in the table under "The artefacts". | A mapping to control identifiers. The control spreadsheet is a download that this update did not read, so this page names no AICM control. A receipt is evidence for a control. It is not the control. |
|
|
136
|
+
|
|
137
|
+
Sources: the [CSA artifact page](https://cloudsecurityalliance.org/artifacts/ai-controls-matrix-v1-1) and the [CSA announcement](https://cloudsecurityalliance.org/blog/2026/07/14/ai-controls-matrix-v1-1-strengthening-the-foundation-for-trustworthy-ai). As of 2026-11-02.
|
|
138
|
+
|
|
139
|
+
### OWASP Top 10 for Agentic Applications
|
|
140
|
+
|
|
141
|
+
The OWASP Gen AI Security Project published the Top 10 for Agentic Applications for 2026 on 9 December 2025. It is a list of risks and mitigations. It is guidance, not law. Its mitigation lists ask for logs in several places. The rows below name five of them.
|
|
142
|
+
|
|
143
|
+
| item | what it asks | what a receipt supplies | what a receipt does not supply |
|
|
144
|
+
| --- | --- | --- | --- |
|
|
145
|
+
| ASI01, Agent Goal Hijack | "Comprehensive logging and continuous monitoring of agent activity", with a baseline of tool-use patterns. | A record of each tool call, the monitor, and the SIEM exports. | The baseline and the alerts. You build them. |
|
|
146
|
+
| ASI02, Tool Misuse and Exploitation | "Immutable logs of all tool invocations and parameter changes", and monitoring for anomalous tool chains. | A signed receipt in a Merkle log for each call through the gateway, with the digest of the arguments. | Calls that do not go through the gateway. Detection of an anomalous chain. |
|
|
147
|
+
| ASI08, Cascading Failures | Tamper-evident, time-stamped logs of inter-agent messages, policy decisions, and execution outcomes, with lineage for every propagated action. | Policy decisions and execution outcomes. `explain` and the blast radius give lineage. | Inter-agent messages that are not tool calls. |
|
|
148
|
+
| ASI09, Human-Agent Trust Exploitation | "Immutable logs" of user queries and agent actions. | The actions of the agent. | User queries. |
|
|
149
|
+
| ASI10, Rogue Agents | "Immutable and signed audit logs of all agent actions, tool calls, and inter-agent communication". | Signed receipts of tool calls. | Inter-agent communication. A kill switch: the document lists one as a separate mitigation. |
|
|
150
|
+
|
|
151
|
+
Source: the [OWASP document](https://genai.owasp.org/resource/owasp-top-10-for-agentic-applications-for-2026/), version 2026, December 2025. As of 2026-11-02.
|
|
152
|
+
|
|
153
|
+
### ISO/IEC 42001
|
|
154
|
+
|
|
155
|
+
ISO/IEC 42001:2023 is the standard for an artificial intelligence management system. Edition 1 was published on 2023-12-18. It specifies requirements for establishing, implementing, and maintaining a management system in an organization that offers or uses AI-enabled products or services.
|
|
156
|
+
|
|
157
|
+
| provision | what it asks | what a receipt supplies | what a receipt does not supply |
|
|
158
|
+
| --- | --- | --- | --- |
|
|
159
|
+
| [ISO/IEC 42001:2023](https://webstore.iec.ch/publication/90574) as a whole | A management system for an organization: its policies, roles, risk processes, and controls. | Operating evidence that a control ran, in a form that an auditor verifies with public keys. | The management system. A certificate: an audit of the organization produces that. A mapping to clauses or Annex A controls. The standard is sold, and this update did not read the text, so this page names no clause. |
|
|
160
|
+
|
|
161
|
+
Source: the [IEC publication page](https://webstore.iec.ch/publication/90574). As of 2026-11-02.
|
|
52
162
|
|
|
53
163
|
## UK GDPR
|
|
54
164
|
|
package/docs/policies.md
CHANGED
|
@@ -168,6 +168,18 @@ permit(principal, action == Action::"memory.retract", resource)
|
|
|
168
168
|
when { context.facts has target && context.facts.target.provenance == "claimed" };
|
|
169
169
|
```
|
|
170
170
|
|
|
171
|
+
## Saying why a rule denies
|
|
172
|
+
|
|
173
|
+
Put a `@reason("...")` annotation before a `forbid` rule. The Claude Code hook shows the text to the agent and to the person who reads the session, and `agent-custody report` prints it before the rule.
|
|
174
|
+
|
|
175
|
+
```cedar
|
|
176
|
+
@reason("force push rewrites shared history")
|
|
177
|
+
forbid(principal, action == Action::"Bash", resource)
|
|
178
|
+
when { context.args has command && context.args.command like "*git push*--force*" };
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
The hook text is `agent-custody denied this call: force push rewrites shared history (rule policy1, receipt <id>)`. A rule with no annotation shows its id. The annotation is part of the policy file, so it changes the policy digest, but it never changes the decision or the receipt format. Keep the reason short and say what the rule forbids, not what the agent did. Only the Claude Code hook and the report read it today.
|
|
182
|
+
|
|
171
183
|
## Gotchas
|
|
172
184
|
|
|
173
185
|
- **Integers only.** `12.50` is not a Cedar value. Send `1250`.
|
package/docs/sdk.md
CHANGED
|
@@ -38,6 +38,88 @@ 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, `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. A lock file that is older than ten seconds belongs to a process that died, and the next append removes it.
|
|
58
|
+
|
|
59
|
+
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.
|
|
60
|
+
|
|
61
|
+
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.
|
|
62
|
+
|
|
63
|
+
| option | effect |
|
|
64
|
+
| --- | --- |
|
|
65
|
+
| `--dir <dir>` | the directory for the key, the config, the policy, and the receipts. Default: `~/.config/agent-custody` |
|
|
66
|
+
| `--user` | write the hooks to `~/.claude/settings.json` |
|
|
67
|
+
| `--enforce` | leave out `"mode": "observe"`, so a denied call is blocked |
|
|
68
|
+
| `--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 |
|
|
69
|
+
| `--log-id <id>` | the log id that the tree heads must name |
|
|
70
|
+
| `--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 |
|
|
71
|
+
| `--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` |
|
|
72
|
+
|
|
73
|
+
### The starter deny set
|
|
74
|
+
|
|
75
|
+
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.
|
|
76
|
+
|
|
77
|
+
| command | the policy |
|
|
78
|
+
| --- | --- |
|
|
79
|
+
| `git push --force`, `git push -f`, `git push origin main -f` | denied |
|
|
80
|
+
| `git 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 |
|
|
81
|
+
| `git push origin main && rm -f stale.lock`, `git push origin fix-f` | allowed |
|
|
82
|
+
| `rm -rf /`, `rm -fr /`, `rm -rf /*`, `rm -rf ~`, `rm -rf $HOME`, `rm -rf ${HOME}` | denied |
|
|
83
|
+
| `rm -rf /tmp/build`, `rm -rf ~/projects/app/dist` | allowed |
|
|
84
|
+
| `terraform destroy`, `terraform apply -destroy` | denied |
|
|
85
|
+
| `terraform plan`, `terraform plan -destroy` | allowed |
|
|
86
|
+
|
|
87
|
+
A `--force` flag matches anywhere after `git push`. A `-f` flag matches right after `git push` or at the end of the command. A `-f` in the middle of a command does not match. The reason is that `like` cannot find where one shell command ends and the next starts, and a match there would block `git push origin main && rm -f stale.lock`. `test/claude-init.test.ts` runs every command of this table.
|
|
88
|
+
|
|
89
|
+
### The denial text
|
|
90
|
+
|
|
91
|
+
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.
|
|
92
|
+
|
|
93
|
+
```cedar
|
|
94
|
+
@reason("terraform destroy deletes infrastructure")
|
|
95
|
+
forbid(principal, action == Action::"Bash", resource)
|
|
96
|
+
when { context.args has command && context.args.command like "*terraform destroy*" };
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
```text
|
|
100
|
+
agent-custody denied this call: terraform destroy deletes infrastructure (rule policy5, receipt 47eb52af-...)
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
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.
|
|
104
|
+
|
|
105
|
+
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.
|
|
106
|
+
|
|
107
|
+
### The report
|
|
108
|
+
|
|
109
|
+
```bash
|
|
110
|
+
agent-custody report --config ~/.config/agent-custody/sdk.json
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
`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, 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`.
|
|
114
|
+
|
|
115
|
+
`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.
|
|
116
|
+
|
|
117
|
+
### An incident replay
|
|
118
|
+
|
|
119
|
+
`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.
|
|
120
|
+
|
|
121
|
+
### Register the hook by hand
|
|
122
|
+
|
|
41
123
|
Register the hook command in `.claude/settings.json`. The same command handles all three events.
|
|
42
124
|
|
|
43
125
|
```json
|
|
@@ -58,7 +140,7 @@ Register the hook command in `.claude/settings.json`. The same command handles a
|
|
|
58
140
|
|
|
59
141
|
`AGENT_CUSTODY_CONFIG` works instead of `--config`. Behaviour per event:
|
|
60
142
|
|
|
61
|
-
- **PreToolUse.** Evaluates the policy. On deny, issues a denial receipt and returns `permissionDecision: "deny"` with the receipt id
|
|
143
|
+
- **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
144
|
- **PostToolUse.** Issues an executed receipt carrying `tool_response`.
|
|
63
145
|
- **PostToolUseFailure.** Issues a failed receipt.
|
|
64
146
|
|
package/docs/tutorials.md
CHANGED
|
@@ -45,6 +45,8 @@ 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
|
+
| 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` |
|
|
48
50
|
|
|
49
51
|
## How policies are defined, in one paragraph
|
|
50
52
|
|