hmcp-core 0.0.1 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (76) hide show
  1. package/README.md +19 -3
  2. package/dist/approvals.d.ts +508 -0
  3. package/dist/approvals.js +1445 -0
  4. package/dist/argpath.d.ts +75 -0
  5. package/dist/argpath.js +189 -0
  6. package/dist/audit.d.ts +297 -0
  7. package/dist/audit.js +524 -0
  8. package/dist/canonical.d.ts +78 -0
  9. package/dist/canonical.js +146 -0
  10. package/dist/classify-held.d.ts +47 -0
  11. package/dist/classify-held.js +60 -0
  12. package/dist/classify-name.d.ts +55 -0
  13. package/dist/classify-name.js +255 -0
  14. package/dist/decide.d.ts +168 -0
  15. package/dist/decide.js +518 -0
  16. package/dist/egress.d.ts +123 -0
  17. package/dist/egress.js +544 -0
  18. package/dist/enforce.d.ts +78 -0
  19. package/dist/enforce.js +231 -0
  20. package/dist/exposure-apply.d.ts +51 -0
  21. package/dist/exposure-apply.js +69 -0
  22. package/dist/exposure.d.ts +81 -0
  23. package/dist/exposure.js +65 -0
  24. package/dist/file-lock.d.ts +70 -0
  25. package/dist/file-lock.js +165 -0
  26. package/dist/glob.d.ts +11 -0
  27. package/dist/glob.js +55 -0
  28. package/dist/grants.d.ts +204 -0
  29. package/dist/grants.js +372 -0
  30. package/dist/http-util.d.ts +52 -0
  31. package/dist/http-util.js +81 -0
  32. package/dist/index.d.ts +35 -0
  33. package/dist/index.js +36 -0
  34. package/dist/inventory.d.ts +100 -0
  35. package/dist/inventory.js +88 -0
  36. package/dist/ip.d.ts +15 -0
  37. package/dist/ip.js +186 -0
  38. package/dist/jwt.d.ts +57 -0
  39. package/dist/jwt.js +199 -0
  40. package/dist/live-state.d.ts +76 -0
  41. package/dist/live-state.js +57 -0
  42. package/dist/migrate.d.ts +22 -0
  43. package/dist/migrate.js +318 -0
  44. package/dist/pins.d.ts +119 -0
  45. package/dist/pins.js +125 -0
  46. package/dist/policy-batch.d.ts +89 -0
  47. package/dist/policy-batch.js +340 -0
  48. package/dist/policy-source.d.ts +161 -0
  49. package/dist/policy-source.js +299 -0
  50. package/dist/policy-write.d.ts +627 -0
  51. package/dist/policy-write.js +1697 -0
  52. package/dist/policy.d.ts +456 -0
  53. package/dist/policy.js +448 -0
  54. package/dist/redact.d.ts +65 -0
  55. package/dist/redact.js +191 -0
  56. package/dist/registry.d.ts +41 -0
  57. package/dist/registry.js +121 -0
  58. package/dist/remember-defaults.d.ts +9 -0
  59. package/dist/remember-defaults.js +9 -0
  60. package/dist/remember.d.ts +91 -0
  61. package/dist/remember.js +386 -0
  62. package/dist/resolve.d.ts +22 -0
  63. package/dist/resolve.js +34 -0
  64. package/dist/runtime-state.d.ts +65 -0
  65. package/dist/runtime-state.js +35 -0
  66. package/dist/secrets.d.ts +159 -0
  67. package/dist/secrets.js +361 -0
  68. package/dist/tenant.d.ts +83 -0
  69. package/dist/tenant.js +182 -0
  70. package/dist/unicode.d.ts +40 -0
  71. package/dist/unicode.js +103 -0
  72. package/dist/within-host.d.ts +33 -0
  73. package/dist/within-host.js +91 -0
  74. package/dist/within-real.d.ts +7 -0
  75. package/dist/within-real.js +28 -0
  76. package/package.json +33 -4
@@ -0,0 +1,75 @@
1
+ /**
2
+ * Argument paths, for bounding a value that is not at the top level of a call.
3
+ *
4
+ * A bound written against `args[name]` can only reach a flat argument, which
5
+ * means a tool taking `{transfer: {amount: 1e9}}` or `{items: [{qty: 99999}]}`
6
+ * cannot be bounded at all — and a bound that is walked around by nesting the
7
+ * payload is decoration. The vocabulary here is deliberately small:
8
+ *
9
+ * amount a top-level argument, as before
10
+ * transfer.amount a nested one
11
+ * items[] every element of an array
12
+ * items[].qty one field of every element
13
+ *
14
+ * `*` is not a path operator. It means something else three lines away in
15
+ * `glob.ts`, which globs tool names, and one character meaning two things in
16
+ * one policy file is how an operator writes a bound that does not bind.
17
+ *
18
+ * Paths are parsed when the policy is parsed, so an unwritable path is a
19
+ * startup failure rather than a silent no-match that reads as a satisfied
20
+ * bound.
21
+ */
22
+ /** A step in a path pattern. `items` fans out over every element of an array. */
23
+ export type PathSegment = {
24
+ readonly kind: "key";
25
+ readonly name: string;
26
+ } | {
27
+ readonly kind: "items";
28
+ };
29
+ /** A step in a resolved path. A number is an array index that actually existed. */
30
+ export type ConcreteSegment = string | number;
31
+ export interface PathMatch {
32
+ /** Where the value was found, with real indices rather than `[]`. */
33
+ readonly path: readonly ConcreteSegment[];
34
+ readonly value: unknown;
35
+ }
36
+ export type ParseResult = {
37
+ readonly ok: true;
38
+ readonly segments: readonly PathSegment[];
39
+ } | {
40
+ readonly ok: false;
41
+ readonly error: string;
42
+ };
43
+ /**
44
+ * Parses a path pattern. Rejects anything ambiguous rather than guessing: an
45
+ * empty key, a dangling dot, `[` without `]`, an index inside the brackets
46
+ * (`items[0]` would bound one element and leave the rest unbounded, which is
47
+ * never what the author meant).
48
+ */
49
+ export declare function parseArgPath(spec: string): ParseResult;
50
+ /** True when a pattern fans out, so having nothing to bound is not an absence. */
51
+ export declare function hasWildcard(segments: readonly PathSegment[]): boolean;
52
+ /** `transfer.amount`, `items[3].qty` — what a violation names. */
53
+ export declare function formatPath(path: readonly ConcreteSegment[]): string;
54
+ /**
55
+ * Every place a pattern actually matches. A pattern that matches nothing
56
+ * resolves to an empty list; distinguishing "absent" from "present and out of
57
+ * bounds" is the caller's job, because the two have different policies.
58
+ */
59
+ export declare function resolveArgPath(root: unknown, segments: readonly PathSegment[]): PathMatch[];
60
+ /**
61
+ * Every leaf in an argument object, with concrete indices. This is what a
62
+ * closed world is checked against: an argument no constraint claims is one
63
+ * nobody bounded.
64
+ *
65
+ * An empty object or array is itself a leaf. There is nothing under it to
66
+ * bound, and treating it as an interior node would quietly exempt
67
+ * `{options: {}}` from a closed world.
68
+ */
69
+ export declare function leafPaths(root: unknown): PathMatch[];
70
+ /**
71
+ * True when `inner` is `outer` or sits beneath it. Compared segment by
72
+ * segment rather than as formatted strings, so a constraint on `item` does
73
+ * not claim `items`.
74
+ */
75
+ export declare function isAtOrUnder(inner: readonly ConcreteSegment[], outer: readonly ConcreteSegment[]): boolean;
@@ -0,0 +1,189 @@
1
+ /**
2
+ * Argument paths, for bounding a value that is not at the top level of a call.
3
+ *
4
+ * A bound written against `args[name]` can only reach a flat argument, which
5
+ * means a tool taking `{transfer: {amount: 1e9}}` or `{items: [{qty: 99999}]}`
6
+ * cannot be bounded at all — and a bound that is walked around by nesting the
7
+ * payload is decoration. The vocabulary here is deliberately small:
8
+ *
9
+ * amount a top-level argument, as before
10
+ * transfer.amount a nested one
11
+ * items[] every element of an array
12
+ * items[].qty one field of every element
13
+ *
14
+ * `*` is not a path operator. It means something else three lines away in
15
+ * `glob.ts`, which globs tool names, and one character meaning two things in
16
+ * one policy file is how an operator writes a bound that does not bind.
17
+ *
18
+ * Paths are parsed when the policy is parsed, so an unwritable path is a
19
+ * startup failure rather than a silent no-match that reads as a satisfied
20
+ * bound.
21
+ */
22
+ /** Characters a key may not contain, because they are the path syntax itself. */
23
+ const KEY_FORBIDDEN = /[.[\]]/;
24
+ /**
25
+ * Parses a path pattern. Rejects anything ambiguous rather than guessing: an
26
+ * empty key, a dangling dot, `[` without `]`, an index inside the brackets
27
+ * (`items[0]` would bound one element and leave the rest unbounded, which is
28
+ * never what the author meant).
29
+ */
30
+ export function parseArgPath(spec) {
31
+ if (spec.length === 0)
32
+ return { ok: false, error: "an argument path cannot be empty" };
33
+ const segments = [];
34
+ let i = 0;
35
+ let expectKey = true;
36
+ while (i < spec.length) {
37
+ if (expectKey) {
38
+ let key = "";
39
+ while (i < spec.length && !KEY_FORBIDDEN.test(spec[i]))
40
+ key += spec[i++];
41
+ if (key.length === 0) {
42
+ return { ok: false, error: `expected an argument name at position ${i} in "${spec}"` };
43
+ }
44
+ segments.push({ kind: "key", name: key });
45
+ expectKey = false;
46
+ continue;
47
+ }
48
+ const ch = spec[i];
49
+ if (ch === ".") {
50
+ i += 1;
51
+ if (i === spec.length)
52
+ return { ok: false, error: `"${spec}" ends with a dot` };
53
+ expectKey = true;
54
+ continue;
55
+ }
56
+ if (ch === "[") {
57
+ if (spec[i + 1] !== "]") {
58
+ return {
59
+ ok: false,
60
+ error: `"${spec}" must use "[]" to mean every element; a specific index would leave the other elements unbounded`
61
+ };
62
+ }
63
+ segments.push({ kind: "items" });
64
+ i += 2;
65
+ continue;
66
+ }
67
+ return { ok: false, error: `unexpected "${ch}" at position ${i} in "${spec}"` };
68
+ }
69
+ if (expectKey)
70
+ return { ok: false, error: `"${spec}" ends with a dot` };
71
+ return { ok: true, segments };
72
+ }
73
+ /** True when a pattern fans out, so having nothing to bound is not an absence. */
74
+ export function hasWildcard(segments) {
75
+ return segments.some((s) => s.kind === "items");
76
+ }
77
+ /** `transfer.amount`, `items[3].qty` — what a violation names. */
78
+ export function formatPath(path) {
79
+ let out = "";
80
+ for (const seg of path) {
81
+ if (typeof seg === "number")
82
+ out += `[${seg}]`;
83
+ else
84
+ out += out.length === 0 ? seg : `.${seg}`;
85
+ }
86
+ return out;
87
+ }
88
+ function isPlainObject(value) {
89
+ return typeof value === "object" && value !== null && !Array.isArray(value);
90
+ }
91
+ /**
92
+ * Every place a pattern actually matches. A pattern that matches nothing
93
+ * resolves to an empty list; distinguishing "absent" from "present and out of
94
+ * bounds" is the caller's job, because the two have different policies.
95
+ */
96
+ export function resolveArgPath(root, segments) {
97
+ let frontier = [{ path: [], value: root }];
98
+ for (const segment of segments) {
99
+ const next = [];
100
+ for (const match of frontier) {
101
+ if (segment.kind === "key") {
102
+ if (!isPlainObject(match.value))
103
+ continue;
104
+ // An own property, rather than a truthiness check or `in`. An explicit
105
+ // null is a value the caller chose to send, not an absence -- and
106
+ // `constructor` or `toString` on an empty object is something every
107
+ // object inherits, not something the caller sent.
108
+ if (!Object.hasOwn(match.value, segment.name))
109
+ continue;
110
+ const value = match.value[segment.name];
111
+ if (value === undefined)
112
+ continue;
113
+ next.push({ path: [...match.path, segment.name], value });
114
+ }
115
+ else {
116
+ if (!Array.isArray(match.value))
117
+ continue;
118
+ match.value.forEach((value, index) => {
119
+ if (value === undefined)
120
+ return;
121
+ next.push({ path: [...match.path, index], value });
122
+ });
123
+ }
124
+ }
125
+ frontier = next;
126
+ if (frontier.length === 0)
127
+ return [];
128
+ }
129
+ return frontier;
130
+ }
131
+ /**
132
+ * Every leaf in an argument object, with concrete indices. This is what a
133
+ * closed world is checked against: an argument no constraint claims is one
134
+ * nobody bounded.
135
+ *
136
+ * An empty object or array is itself a leaf. There is nothing under it to
137
+ * bound, and treating it as an interior node would quietly exempt
138
+ * `{options: {}}` from a closed world.
139
+ */
140
+ export function leafPaths(root) {
141
+ const out = [];
142
+ const walk = (value, path) => {
143
+ if (Array.isArray(value)) {
144
+ if (value.length === 0) {
145
+ out.push({ path, value });
146
+ return;
147
+ }
148
+ value.forEach((v, i) => walk(v, [...path, i]));
149
+ return;
150
+ }
151
+ if (isPlainObject(value)) {
152
+ const keys = Object.keys(value).filter((k) => value[k] !== undefined);
153
+ if (keys.length === 0) {
154
+ out.push({ path, value });
155
+ return;
156
+ }
157
+ for (const key of keys)
158
+ walk(value[key], [...path, key]);
159
+ return;
160
+ }
161
+ out.push({ path, value });
162
+ };
163
+ // The root itself is never a leaf: a call with no arguments has nothing
164
+ // unclaimed, rather than one anonymous unclaimed argument.
165
+ if (Array.isArray(root)) {
166
+ root.forEach((v, i) => walk(v, [i]));
167
+ }
168
+ else if (isPlainObject(root)) {
169
+ for (const key of Object.keys(root)) {
170
+ if (root[key] !== undefined)
171
+ walk(root[key], [key]);
172
+ }
173
+ }
174
+ return out;
175
+ }
176
+ /**
177
+ * True when `inner` is `outer` or sits beneath it. Compared segment by
178
+ * segment rather than as formatted strings, so a constraint on `item` does
179
+ * not claim `items`.
180
+ */
181
+ export function isAtOrUnder(inner, outer) {
182
+ if (outer.length > inner.length)
183
+ return false;
184
+ for (let i = 0; i < outer.length; i += 1) {
185
+ if (inner[i] !== outer[i])
186
+ return false;
187
+ }
188
+ return true;
189
+ }
@@ -0,0 +1,297 @@
1
+ import { type AuditConfig, type DecisionKind, type Effect } from "./policy.js";
2
+ export declare const GENESIS_HASH: string;
3
+ export interface AuditRecord {
4
+ readonly ts: string;
5
+ readonly seq: number;
6
+ readonly id: string;
7
+ readonly actor: string;
8
+ readonly session: string;
9
+ readonly component: string;
10
+ readonly tool: string;
11
+ readonly effect: Effect | null;
12
+ readonly decision: DecisionKind;
13
+ readonly rule_id: string;
14
+ readonly reason: string;
15
+ readonly tenant: string | null;
16
+ readonly args_hash: string;
17
+ readonly args_redacted: Record<string, unknown> | null;
18
+ readonly upstream: {
19
+ readonly host: string | null;
20
+ readonly method: string | null;
21
+ readonly path: string | null;
22
+ readonly status: number | null;
23
+ readonly bytes: number | null;
24
+ } | null;
25
+ /**
26
+ * `relayed` is a call policy permitted and handed back to the client that
27
+ * runs it -- Claude Code, through the guard hook -- rather than run here.
28
+ * Whether it then completed is the client's to report, in a later record.
29
+ */
30
+ readonly outcome: "completed" | "denied" | "pending-approval" | "error" | "relayed";
31
+ readonly error: string | null;
32
+ readonly duration_ms: number | null;
33
+ readonly approval_id: string | null;
34
+ /**
35
+ * Set when a standing grant released this call, or on the administrative
36
+ * records written when one is created or revoked.
37
+ *
38
+ * Records written before standing grants existed have no such key at all.
39
+ * `canonicalJson` drops `undefined`, so those records still hash to exactly
40
+ * what they did before and an old log keeps verifying.
41
+ */
42
+ readonly grant_id: string | null;
43
+ /**
44
+ * Present, and `true`, on a call that ran in observe mode.
45
+ *
46
+ * `decision`, `rule_id` and `reason` on such a record are what policy
47
+ * *would* have decided; nothing was refused or held, and `outcome` says
48
+ * what actually happened. Absent everywhere else, so a record written
49
+ * under enforcement hashes to what it always did and an old log keeps
50
+ * verifying.
51
+ */
52
+ readonly observe?: true;
53
+ readonly prev_hash: string;
54
+ readonly hash: string;
55
+ }
56
+ /** Everything except the fields the log assigns itself (ts, seq, id, hashes). */
57
+ export interface AuditEntry {
58
+ readonly tool: string;
59
+ readonly decision: DecisionKind;
60
+ readonly outcome: AuditRecord["outcome"];
61
+ readonly effect?: Effect | null;
62
+ readonly rule_id?: string;
63
+ readonly reason?: string;
64
+ readonly tenant?: string | null;
65
+ readonly args_hash?: string;
66
+ readonly args_redacted?: Record<string, unknown> | null;
67
+ readonly upstream?: AuditRecord["upstream"];
68
+ readonly error?: string | null;
69
+ readonly duration_ms?: number | null;
70
+ readonly approval_id?: string | null;
71
+ readonly grant_id?: string | null;
72
+ /** The call ran in observe mode; the decision recorded was not applied. */
73
+ readonly observe?: boolean;
74
+ readonly actor?: string;
75
+ readonly session?: string;
76
+ readonly component?: string;
77
+ }
78
+ /**
79
+ * Who a record says made the call.
80
+ *
81
+ * One column holds three very different kinds of answer: an operating-system
82
+ * user (a human at a console or a terminal), the literal "agent" for a server
83
+ * that serves one client and has no identity to offer, and — once a gateway
84
+ * verifies a caller's token — whoever that token names.
85
+ *
86
+ * Only the last of those is chosen by someone outside the deployment, which
87
+ * is why only the last is namespaced. A token minted with `sub: "aditya"`
88
+ * must not produce a line indistinguishable from a human's console approval,
89
+ * and a reserved prefix is what makes that forgery unrepresentable rather
90
+ * than merely unlikely. Prefixing the operator too would churn stored history
91
+ * to protect against nobody.
92
+ */
93
+ /** A server with one client and no caller identity to claim. */
94
+ export declare const ACTOR_AGENT = "agent";
95
+ /** The gateway process itself: startup findings, structural refusals. */
96
+ export declare const ACTOR_GATEWAY = "gateway";
97
+ /**
98
+ * A token that verified but named no subject.
99
+ *
100
+ * Deliberately not "unknown", which already means "could not name the
101
+ * operating-system user". This says something narrower and truer: the token
102
+ * proved a *tenant*, not an identity.
103
+ */
104
+ export declare const ACTOR_ANONYMOUS = "token:anonymous";
105
+ /**
106
+ * The actor for a caller named by a verified token.
107
+ *
108
+ * The subject is not quoted anywhere it could be mistaken for structure, but
109
+ * it is interpolated into prose reasons in the console and the admin API, so
110
+ * it is flattened to one line and capped here rather than at each use.
111
+ *
112
+ * The tenant is deliberately *not* folded in: every record already carries a
113
+ * `tenant` column, and `(tenant, actor)` is the real key. Nor is the issuer,
114
+ * which is pinned to one value per deployment. If multiple issuers ever
115
+ * become possible the format grows to `token:<iss>#<sub>`.
116
+ */
117
+ export declare function tokenActor(subject: string | undefined): string;
118
+ export interface AuditLogOptions {
119
+ readonly config: AuditConfig;
120
+ readonly actor?: string;
121
+ readonly session?: string;
122
+ readonly component?: string;
123
+ /** Base for resolving a relative audit path. */
124
+ readonly cwd?: string;
125
+ }
126
+ /**
127
+ * Append-only JSONL audit log with an optional hash chain.
128
+ *
129
+ * Each record commits to the one before it, so a deleted or edited line makes
130
+ * `verifyAuditLog` fail at that point. Appends are guarded by an exclusive lock
131
+ * file, because the chain requires a read-tail-then-append critical section and
132
+ * a generated server plus a gateway may share one log.
133
+ */
134
+ export declare class AuditLog {
135
+ readonly path: string;
136
+ readonly enabled: boolean;
137
+ private readonly config;
138
+ private readonly actor;
139
+ private readonly session;
140
+ private readonly component;
141
+ constructor(options: AuditLogOptions);
142
+ /**
143
+ * Writes one record and returns it. Failure to log is reported to stderr but
144
+ * never thrown: a broken log must not become a way to suppress enforcement.
145
+ * Callers that need write-or-refuse semantics should use `appendStrict`.
146
+ */
147
+ append(entry: AuditEntry): AuditRecord | null;
148
+ appendStrict(entry: AuditEntry): AuditRecord | null;
149
+ /**
150
+ * Throws unless a record could be appended right now.
151
+ *
152
+ * For a caller about to do something it must not do unrecorded. Opening the
153
+ * file for append is what an append does first, so this fails for a missing
154
+ * or read-only directory, a path that is not a file, or a full quota, and
155
+ * leaves the log untouched when it succeeds. It cannot promise the append
156
+ * that follows will work -- nothing can -- but it turns the common, lasting
157
+ * failures into a refusal rather than a line on stderr.
158
+ */
159
+ assertWritable(): void;
160
+ /**
161
+ * Redacts free text bound for this log -- an upstream's error message --
162
+ * with the same key list the arguments beside it are redacted with.
163
+ */
164
+ prepareText(text: string, args?: Record<string, unknown>): string;
165
+ /** Redacts arguments with this log's configured key list and hashes the original. */
166
+ prepareArgs(args: Record<string, unknown> | undefined): {
167
+ args_hash: string;
168
+ args_redacted: Record<string, unknown>;
169
+ };
170
+ }
171
+ export interface TailRead {
172
+ readonly hash: string;
173
+ readonly seq: number;
174
+ /** How many bytes from the end were read to find it, for diagnostics and tests. */
175
+ readonly bytesRead: number;
176
+ }
177
+ /**
178
+ * The last complete record, found by seeking backwards from the end.
179
+ *
180
+ * Every append needs this, because each record carries the previous one's
181
+ * hash. It used to read the whole file, which is fine for a day and not for a
182
+ * year: on a 6 MB log every tool call read 6 MB synchronously, inside the
183
+ * append lock, so the cost of using the gateway grew with how long it had
184
+ * been used.
185
+ *
186
+ * Read backwards in blocks instead. Three things this has to keep getting
187
+ * right, and each has a test:
188
+ *
189
+ * - a torn trailing line, left by a process killed mid-append, is skipped and
190
+ * the search continues to the last *complete* record;
191
+ * - a record longer than one block is still found, because a block boundary
192
+ * is not a record boundary;
193
+ * - and when nothing can be found within `TAIL_READ_LIMIT`, this says so by
194
+ * returning null rather than reading an unbounded amount -- a log that has
195
+ * been corrupted at the end must not turn every append into a full scan.
196
+ */
197
+ export declare function readLastRecord(path: string): TailRead | null;
198
+ export interface VerifyResult {
199
+ readonly ok: boolean;
200
+ readonly count: number;
201
+ readonly problems: readonly {
202
+ readonly line: number;
203
+ readonly message: string;
204
+ }[];
205
+ /**
206
+ * The hash of the last record: this log's head. Worth writing down
207
+ * somewhere the log's owner does not control, because it is the only thing
208
+ * that detects the end of the log being cut off.
209
+ */
210
+ readonly head?: string | undefined;
211
+ /** Where an expected head was found, as a record number, when one was given. */
212
+ readonly headPosition?: number | undefined;
213
+ }
214
+ export interface VerifyOptions {
215
+ /**
216
+ * A head hash recorded earlier, somewhere else.
217
+ *
218
+ * Checked by finding it in the chain. Finding it anywhere means every
219
+ * record up to it is still present and unaltered; not finding it means
220
+ * either that it never came from this log or that the records carrying it
221
+ * are gone. A chain cannot tell those apart from the inside, and neither
222
+ * can this -- it reports both as what they are: the recorded head is not
223
+ * here.
224
+ */
225
+ readonly expectHead?: string | undefined;
226
+ }
227
+ /**
228
+ * Walks the chain and reports the first point at which it stops being
229
+ * consistent: a modified record, a removed one, or a reordered one.
230
+ */
231
+ export declare function verifyAuditLog(path: string, options?: VerifyOptions): VerifyResult;
232
+ export declare function readAuditLog(path: string): AuditRecord[];
233
+ export interface AuditQuery {
234
+ readonly decision?: readonly DecisionKind[];
235
+ readonly outcome?: readonly AuditRecord["outcome"][];
236
+ /** Glob over the tool name, same dialect as policy rule patterns. */
237
+ readonly tool?: string;
238
+ readonly component?: readonly string[];
239
+ /**
240
+ * Records from these components are left out. Several toolboxes write to
241
+ * one log by default (`~/.hmcp/audit.jsonl`), so one toolbox's view leaves
242
+ * out the records its neighbours wrote there, while keeping its own and
243
+ * the console's.
244
+ */
245
+ readonly excludeComponent?: readonly string[];
246
+ /**
247
+ * Whose data the call touched.
248
+ *
249
+ * One log file holds every tenant's records — the hash chain is per file, so
250
+ * splitting it is not free — which makes this the only way to read one
251
+ * tenant's history out of it. `""` selects records from a deployment with no
252
+ * tenant configured, and from anything written before the field was set.
253
+ */
254
+ readonly tenant?: readonly string[];
255
+ readonly actor?: readonly string[];
256
+ /** Inclusive ISO 8601 bounds on `ts`. */
257
+ readonly since?: string;
258
+ readonly until?: string;
259
+ /** Only records with a lower `seq`; the cursor for paging backwards. */
260
+ readonly beforeSeq?: number;
261
+ readonly limit?: number;
262
+ /**
263
+ * Anything refused, or anything that did not run to completion. Kept as one
264
+ * flag rather than expressed through `decision`/`outcome` because it is an
265
+ * OR of the two, and because it is the question a reviewer actually asks.
266
+ */
267
+ readonly noteworthy?: boolean;
268
+ }
269
+ /**
270
+ * Anything refused, or anything that did not complete. A relayed call is
271
+ * neither: it was let through, and what became of it is its own record.
272
+ */
273
+ export declare function isNoteworthy(record: AuditRecord): boolean;
274
+ export interface AuditPage {
275
+ /** Newest first. */
276
+ readonly records: AuditRecord[];
277
+ /** Pass as `beforeSeq` for the next page, or null at the start of the log. */
278
+ readonly nextCursor: number | null;
279
+ readonly scanned: number;
280
+ /** Lines that could not be parsed. Reported rather than thrown on. */
281
+ readonly malformed: number;
282
+ }
283
+ /**
284
+ * Bounded, newest-first query over the log.
285
+ *
286
+ * `readAuditLog` parses the whole file and throws on the first malformed line,
287
+ * which makes it unusable for a long-running reader: a console asking for the
288
+ * last 50 records should not pay for a 200MB log, and one torn line should not
289
+ * hide every record around it. This scans backwards in fixed chunks and stops
290
+ * as soon as the limit is met, so the cost is proportional to what was asked
291
+ * for rather than to the size of the log.
292
+ *
293
+ * Chunk boundaries are handled as bytes, not text: a partial line is carried
294
+ * over as a Buffer so a multi-byte character split across two reads is decoded
295
+ * once, intact.
296
+ */
297
+ export declare function queryAuditLog(path: string, query?: AuditQuery): AuditPage;