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
package/README.md CHANGED
@@ -1,5 +1,21 @@
1
1
  # hmcp-core
2
2
 
3
- This name is reserved for [hardened-mcp](https://github.com/aoutix/hardened-mcp), a security
4
- gateway between your AI apps and the MCP servers they use. Version 0.0.1 is a placeholder with
5
- no code; the first real release (0.1.0) follows shortly.
3
+ The security-relevant half of [hardened-mcp](https://github.com/aoutix/hardened-mcp):
4
+ policy schema, the decision engine, the enforcement pipeline, approvals and
5
+ standing grants, the tool inventory, the hash-chained audit log, redaction, and
6
+ the egress guard.
7
+
8
+ Everything a gateway enforces and everything the console describes comes from
9
+ here, so the two cannot drift apart. `decide()` is pure and synchronous on
10
+ purpose: if enforcement ever needed to reach the network to make a decision,
11
+ that would be a hole rather than a feature.
12
+
13
+ This is a library. You most likely want
14
+ [`hmcp-gateway`](https://www.npmjs.com/package/hmcp-gateway) instead.
15
+
16
+ ## License
17
+
18
+ Free to use, including at work, and you may change it for your own use. You may not sell it,
19
+ publish it, share copies of it, or offer it to others as a service. The terms are the
20
+ [PolyForm Internal Use License 1.0.0](https://polyformproject.org/licenses/internal-use/1.0.0)
21
+ with an added permission for personal use; see `LICENSE`. © 2026 Aditya Das
@@ -0,0 +1,508 @@
1
+ import { DatabaseSync } from "node:sqlite";
2
+ import { type CallBindings } from "./canonical.js";
3
+ import { type ApprovalsConfig, type Effect } from "./policy.js";
4
+ import { type StandingGrantDraft, type StandingGrantRow } from "./grants.js";
5
+ import { type ToolExposureRow } from "./exposure.js";
6
+ import type { Scope } from "./tenant.js";
7
+ import { type RuntimeStateRow } from "./runtime-state.js";
8
+ import { type PinOutcome, type ToolChangeInput, type ToolChangeRow, type ToolContract } from "./pins.js";
9
+ import { type LiveConfigStateRow, type LiveRequest } from "./live-state.js";
10
+ import { type ToolInventoryInput, type ToolInventoryRow } from "./inventory.js";
11
+ export type ApprovalState = "pending" | "granted" | "denied" | "used" | "expired";
12
+ export interface ApprovalRow {
13
+ readonly id: string;
14
+ /** Which server this belongs to; "" on a row written before scoping. */
15
+ readonly component: string;
16
+ /** Whose data the call touches; "" when no tenant is configured. */
17
+ readonly tenant: string;
18
+ readonly created_at: number;
19
+ readonly expires_at: number;
20
+ readonly tool: string;
21
+ readonly effect: string | null;
22
+ readonly binding_hash: string;
23
+ readonly args_redacted: string;
24
+ readonly reason: string;
25
+ readonly actor: string;
26
+ readonly session: string;
27
+ readonly state: ApprovalState;
28
+ readonly decided_at: number | null;
29
+ readonly decided_by: string | null;
30
+ readonly decision_note: string | null;
31
+ /**
32
+ * The bounds this call failed, as a JSON array of messages, when a bound is
33
+ * why it is being asked about. Null on a row written before the column
34
+ * existed, which means "not recorded" rather than "none".
35
+ */
36
+ readonly violations: string | null;
37
+ /** Which rule held the call. */
38
+ readonly rule_id: string | null;
39
+ /** Digest of the policy that rule came from, so a past grant can be read. */
40
+ readonly policy_digest: string | null;
41
+ /**
42
+ * Which `bindingHash` framing `binding_hash` was computed under. Redemption
43
+ * compares a digest only against rows carrying the scheme it came from, so
44
+ * an older digest can never release a newer row.
45
+ */
46
+ readonly binding_version: number;
47
+ /**
48
+ * The arguments that broke a bound, as a JSON array of paths, when a bound
49
+ * is why the call is held. Null on a row written before the column existed,
50
+ * which means "not recorded" rather than "none".
51
+ */
52
+ readonly held_args: string | null;
53
+ }
54
+ /**
55
+ * What a caller supplies to create an approval row. The provenance fields are
56
+ * optional: a call held by a posture rather than by a bound has no violations
57
+ * to record, and a surface that predates them records none.
58
+ */
59
+ export type ApprovalInsert = Omit<ApprovalRow, "component" | "tenant" | "decided_at" | "decided_by" | "decision_note" | "state" | "violations" | "rule_id" | "policy_digest" | "binding_version" | "held_args"> & {
60
+ readonly violations?: readonly string[] | undefined;
61
+ readonly held_args?: readonly string[] | undefined;
62
+ readonly rule_id?: string | undefined;
63
+ readonly policy_digest?: string | undefined;
64
+ };
65
+ /** Decodes the recorded violations. An unreadable value reads as none. */
66
+ export declare function approvalViolations(row: ApprovalRow): string[];
67
+ export declare function newApprovalId(): string;
68
+ export interface ApprovalStoreOptions {
69
+ /**
70
+ * How long to wait for another process that is holding the database, in ms.
71
+ *
72
+ * Applies both to SQLite's own `busy_timeout` and to the retry budget for
73
+ * putting a new database into WAL mode. Exists because a cold start racing a
74
+ * peer is the one situation where this number is visible at all, and because
75
+ * a test cannot verify that waiting happens if the only way to observe it is
76
+ * to wait five seconds.
77
+ */
78
+ readonly busyTimeoutMs?: number;
79
+ }
80
+ /**
81
+ * A store path that holds something other than a SQLite database.
82
+ *
83
+ * Its own class so a caller can report it as a message rather than a stack
84
+ * trace: it is a mistyped path, not a fault in the program.
85
+ */
86
+ export declare class NotADatabase extends Error {
87
+ }
88
+ export declare class ApprovalStore {
89
+ private readonly db;
90
+ readonly path: string;
91
+ constructor(path: string, cwd?: string, options?: ApprovalStoreOptions);
92
+ close(): void;
93
+ /**
94
+ * The view a call path works through: every query below is filtered to one
95
+ * component and one tenant, by the database rather than by the caller
96
+ * remembering to.
97
+ */
98
+ scoped(scope: Scope): ScopedApprovals;
99
+ /**
100
+ * Marks every past-due pending or granted row expired, across every scope.
101
+ *
102
+ * Deliberately unscoped: expiry is a property of the clock, not of who owns
103
+ * the row, and a tenant whose server never runs again should not keep a
104
+ * stale "pending" row for ever because nobody swept their scope.
105
+ */
106
+ expireStale(now?: number): number;
107
+ /**
108
+ * Every waiting request in the file, whoever it belongs to.
109
+ *
110
+ * For an operator looking at the database as a database — draining rows left
111
+ * by a server that no longer exists, or the ones a pre-scoping version wrote
112
+ * under ("",""). Not for a call path: `scoped(...).listPending()` is.
113
+ */
114
+ listPendingAll(limit?: number): ApprovalRow[];
115
+ /**
116
+ * Every request in the file, decided or not, newest first.
117
+ *
118
+ * The operator counterpart to `scoped(...).list()`. An `hmcp` at a terminal
119
+ * has a policy file and a database path and no idea which component it is
120
+ * standing in front of, so scoping it by default would mean scoping it to a
121
+ * guess. It shows the scope on each row instead.
122
+ */
123
+ listAll(limit?: number): ApprovalRow[];
124
+ /**
125
+ * One request by id, whatever scope it is in.
126
+ *
127
+ * Safe to be unscoped because the id is the primary key, so there is nothing
128
+ * to confuse it with, and because anyone who can call this already has the
129
+ * database file open — scoping an operator tool against someone holding the
130
+ * file would be theatre. The enforcement path never uses it; it has
131
+ * `scoped(...).get()`, which cannot reach another tenant's row.
132
+ */
133
+ getAny(id: string): ApprovalRow | undefined;
134
+ /** An operator's decision on any parked request, by id. */
135
+ decideAny(id: string, state: "granted" | "denied", by: string, note?: string): ApprovalRow | undefined;
136
+ /** Which (component, tenant) pairs have rows here, for an operator view. */
137
+ listScopes(): Scope[];
138
+ /**
139
+ * Announces which policy this process is enforcing, replacing any row from a
140
+ * previous run of the same server.
141
+ *
142
+ * One row per component, not per process: two servers sharing a component
143
+ * would be two answers to a question that has one, and the last to start is
144
+ * the better guess. The digest is what the reader actually needs — `pid` and
145
+ * `started_at` are there to make a stale row legible rather than merely wrong.
146
+ */
147
+ recordRuntimeState(row: Omit<RuntimeStateRow, "last_seen"> & {
148
+ last_seen?: number;
149
+ }): void;
150
+ /**
151
+ * Marks this server still alive, without touching what it reported.
152
+ *
153
+ * Scoped to the pid that wrote the row so a process that has been superseded
154
+ * cannot keep a live successor's row looking like its own. A row gone stale
155
+ * (its writer stopped beating, so it has exited) is taken over instead:
156
+ * with two app processes on one toolbox, the second one's row replaces the
157
+ * first's, and when the second exits the first must not look dead for good.
158
+ */
159
+ touchRuntimeState(component: string, pid: number, now?: number,
160
+ /** The survivor's own policy, written on a takeover so the row doesn't claim the stopped process's (R2 N6). */
161
+ own?: {
162
+ policy_digest: string;
163
+ policy_path: string;
164
+ }): void;
165
+ runtimeState(component: string): RuntimeStateRow | undefined;
166
+ /**
167
+ * Compares a tool's advertised contract against the pin, and records it.
168
+ *
169
+ * Records in every case, including a change: the point is to notice the
170
+ * change once and keep going, not to report it on every start forever. The
171
+ * finding is in the audit log, which is where a record that must not be
172
+ * overwritten belongs.
173
+ */
174
+ pinTool(component: string, tool: string, digest: string, by?: string, now?: number, contract?: ToolContract,
175
+ /**
176
+ * Whether a change moves the pin to what was just seen.
177
+ *
178
+ * True where the change is only being reported: the finding is in the
179
+ * audit log, which cannot be overwritten, and repeating it on every start
180
+ * forever is a warning nobody reads.
181
+ *
182
+ * False where something is being withheld until a person accepts it. A
183
+ * pin that advanced on detection would mean the tool was quarantined for
184
+ * the life of one process and served by the next -- and that merely
185
+ * looking at it, with any command that connects, cleared a quarantine
186
+ * nobody had reviewed.
187
+ */
188
+ advance?: boolean): PinOutcome;
189
+ /**
190
+ * Accepts what a tool advertises now as the pin, attributed to a person.
191
+ *
192
+ * Without this the only way to stop a reported change being reported is to
193
+ * let the gateway record it silently, which would mean a reviewer could
194
+ * never say "yes, I looked at that, it is fine" in a way that is written
195
+ * down. Returns whether anything was written.
196
+ */
197
+ acceptPin(component: string, tool: string, digest: string, by: string, now?: number, contract?: ToolContract): boolean;
198
+ /** One pin in full, so a caller can put it back exactly as it was. */
199
+ getPin(component: string, tool: string): {
200
+ digest: string;
201
+ contract: ToolContract | undefined;
202
+ pinnedAt: number;
203
+ pinnedBy: string;
204
+ } | undefined;
205
+ /**
206
+ * Replaces the changed contracts this component is holding with the ones it
207
+ * holds now.
208
+ *
209
+ * Delete-then-insert in one transaction, like the inventory beside it: a
210
+ * change that is no longer pending -- accepted, or the upstream went back --
211
+ * has to disappear rather than linger as something to review.
212
+ */
213
+ publishToolChanges(component: string, pid: number, changes: readonly ToolChangeInput[], now?: number): void;
214
+ /**
215
+ * The changes this component published that nobody has accepted yet.
216
+ *
217
+ * A row is settled once a person has pinned the digest it describes. The
218
+ * gateway only re-checks its pins when its tool list is rebuilt, so between
219
+ * an acceptance and the next rebuild it may republish a change that has
220
+ * already been accepted; reading through the pin is what keeps that from
221
+ * reappearing as work to do. A pin the gateway moved itself (under `warn`)
222
+ * does not settle anything: nobody looked at it.
223
+ */
224
+ toolChanges(component: string): ToolChangeRow[];
225
+ /** Drops one published change, once it has been dealt with. */
226
+ clearToolChange(component: string, tool: string): void;
227
+ /** Every pin this component holds, for a reader that wants to show them. */
228
+ listPins(component: string): {
229
+ tool: string;
230
+ digest: string;
231
+ pinnedAt: number;
232
+ pinnedBy: string;
233
+ }[];
234
+ /**
235
+ * Replaces everything this component publishes with what it is serving now.
236
+ *
237
+ * Delete-then-insert in one transaction, so a tool an upstream stopped
238
+ * offering disappears rather than lingering as a row a reader would present
239
+ * as current. A partial write is the one outcome worth ruling out: half a
240
+ * tool list is indistinguishable from a gateway that genuinely narrowed.
241
+ */
242
+ publishInventory(component: string, pid: number, tools: readonly ToolInventoryInput[], now?: number): void;
243
+ /**
244
+ * What this component last published.
245
+ *
246
+ * Unfiltered by pid on purpose: a caller that cares which process wrote these
247
+ * rows has to compare them against `runtimeState(component)` anyway, and
248
+ * silently returning nothing would be indistinguishable from a gateway that
249
+ * has never run. `inventoryPid` is the cheap form of that question.
250
+ */
251
+ inventory(component: string): ToolInventoryRow[];
252
+ /** Which process wrote the rows this component published, if any. */
253
+ inventoryPid(component: string): number | undefined;
254
+ /** Publish this process's view, replacing its previous row. Called on the heartbeat. */
255
+ writeLiveState(row: LiveConfigStateRow): void;
256
+ /**
257
+ * Every live process's view of one component, newest heartbeat first.
258
+ *
259
+ * A row whose heartbeat is older than `LIVE_STATE_STALE_MS` belongs to a
260
+ * process that is gone -- killed, or its AI app quit -- and is deleted here
261
+ * rather than shown, so "connected" is never reported by a process that no
262
+ * longer exists.
263
+ */
264
+ readLiveState(component: string, now?: number): LiveConfigStateRow[];
265
+ /** Remove this process's row, on a clean shutdown. */
266
+ clearLiveState(component: string, pid: number): void;
267
+ /**
268
+ * Ask the running gateways for a component to do something now -- today,
269
+ * retry one server rather than wait for its backoff. A request already
270
+ * waiting for the same server is returned instead of queuing a second one,
271
+ * so a person clicking "Try again" twice causes one retry.
272
+ */
273
+ requestLive(component: string, upstream: string, kind: LiveRequest["kind"], now?: Date): LiveRequest;
274
+ /**
275
+ * The requests for a component that this process has not acted on yet.
276
+ *
277
+ * Every live process sees each request once. Several AI apps can each run a
278
+ * gateway for the same toolbox, and a server can be connected in one and
279
+ * failed in another; if the first to poll took the request away, the
280
+ * process where it actually failed might never retry. So each taker marks a
281
+ * request seen for its pid, and a request is deleted once every live
282
+ * process (and this one) has seen it, or once it is older than the stale
283
+ * window -- a retry nobody picked up in time is no longer what the person
284
+ * asked for. All in one write transaction, so two processes polling at once
285
+ * cannot both miss the delete or both take the same request twice.
286
+ */
287
+ takeLiveRequests(component: string, pid: number, now?: number): LiveRequest[];
288
+ }
289
+ /**
290
+ * One component's rows, for one tenant.
291
+ *
292
+ * Every statement here carries `component = ? AND tenant = ?`. That is the
293
+ * whole of the isolation, and it is deliberately in the SQL rather than folded
294
+ * into `binding_hash` or enforced by a convention: a `WHERE` clause can be
295
+ * read, grepped and tested, and a caller that forgets the scope cannot compile
296
+ * rather than quietly matching everything.
297
+ *
298
+ * Two bugs this closes, both of which were live whenever a database was shared
299
+ * — which is the default. `consume` matched on `binding_hash` alone, and the
300
+ * hash covers only the tool name and arguments, so one tenant's granted
301
+ * approval released another tenant's identical call. `consumeGrant` matched on
302
+ * tool, effect and arguments, so one tenant's standing grant released another
303
+ * tenant's call and charged the use to the wrong grant.
304
+ */
305
+ export declare class ScopedApprovals {
306
+ private readonly db;
307
+ readonly scope: Scope;
308
+ constructor(db: DatabaseSync, scope: Scope);
309
+ private get where();
310
+ /** Expiry is global; it is re-exposed here so scoped reads can sweep first. */
311
+ private expireStale;
312
+ insertPending(row: ApprovalInsert): ApprovalRow;
313
+ /** Records an already-decided grant, e.g. one obtained via elicitation. */
314
+ insertGranted(row: ApprovalInsert, decidedBy: string, note?: string, state?: ApprovalState): ApprovalRow;
315
+ get(id: string): ApprovalRow | undefined;
316
+ listPending(limit?: number): ApprovalRow[];
317
+ list(limit?: number): ApprovalRow[];
318
+ /**
319
+ * The most recent "no" a person gave to this exact call since `since`, if
320
+ * any. A refusal the AI is never told about just turns into a new,
321
+ * identical question on its next try, so the broker answers that try
322
+ * itself for a while after a no.
323
+ */
324
+ findRecentlyDenied(binding: string, since: number): ApprovalRow | undefined;
325
+ /**
326
+ * The request already waiting on a human for this exact call, if there is
327
+ * one. Current framing only: a pending row is always written under it.
328
+ */
329
+ findPending(binding: string, now?: number): ApprovalRow | undefined;
330
+ /** Human decision on a parked request. */
331
+ decide(id: string, state: "granted" | "denied", by: string, note?: string): ApprovalRow | undefined;
332
+ /**
333
+ * Atomically finds and consumes a usable grant for this exact call. The
334
+ * binding hash covers the tool name and every argument, so a grant issued for
335
+ * one set of arguments cannot release a different one — and the scope filter
336
+ * is what stops an identical call in another tenant from redeeming it.
337
+ */
338
+ /**
339
+ * Redeems a grant for this exact call.
340
+ *
341
+ * `bindings` carries one digest per framing `bindingHash` has used, and each
342
+ * is matched only against rows stamped with that framing. Pairing them in the
343
+ * `WHERE` rather than matching on either digest is what keeps the older
344
+ * scheme from releasing a row written under the newer one -- and it keeps the
345
+ * whole transition readable in one SQL clause, which is the same reason the
346
+ * tenant filter lives here rather than inside the hash.
347
+ *
348
+ * The legacy arm exists so an approval a human had already granted when this
349
+ * build was deployed still releases the retry it was granted for. It matches
350
+ * nothing once those rows expire.
351
+ */
352
+ consume(binding: string | CallBindings, singleUse: boolean, now?: number): ApprovalRow | undefined;
353
+ /**
354
+ * `decide` with the "why not" the CLI and the console both need. `decide`
355
+ * returns `undefined` for a missing row and for an already-decided one alike;
356
+ * a reviewer needs to be told which it was.
357
+ */
358
+ decideChecked(id: string, state: "granted" | "denied", by: string, note?: string): {
359
+ ok: true;
360
+ row: ApprovalRow;
361
+ } | {
362
+ ok: false;
363
+ error: string;
364
+ };
365
+ createGrant(draft: StandingGrantDraft, now?: number): StandingGrantRow;
366
+ getGrant(id: string): StandingGrantRow | undefined;
367
+ listGrants(options?: {
368
+ activeOnly?: boolean;
369
+ limit?: number;
370
+ }): StandingGrantRow[];
371
+ /** Marks past-due grants expired. Lazy, like `expireStale` for approvals. */
372
+ expireStaleGrants(now?: number): number;
373
+ revokeGrant(id: string, by: string, now?: number): StandingGrantRow | undefined;
374
+ /**
375
+ * Finds the oldest live grant covering this call and charges one use to it.
376
+ *
377
+ * Returns undefined when nothing covers the call, which is the signal to fall
378
+ * through to ordinary approval. A grant that matches the tool but whose
379
+ * argument constraints reject the arguments is simply not a match: it must not
380
+ * become a denial.
381
+ */
382
+ consumeGrant(tool: string, effect: Effect | null, args: Record<string, unknown>, now?: number,
383
+ /** Arguments that broke a rule's bound, when that is why the call is held. */
384
+ heldArgs?: readonly string[]): StandingGrantRow | undefined;
385
+ /**
386
+ * Switches one tool off, for this component and this tenant.
387
+ *
388
+ * Idempotent, and it only ever subtracts: there is no corresponding row that
389
+ * can make a call reachable. `set_at` and `set_by` are refreshed on a repeat
390
+ * so the audit trail and the console both show who last asserted it.
391
+ */
392
+ disableTool(tool: string, by: string, reason?: string): ToolExposureRow;
393
+ /** Clears the override, handing the question back to policy. */
394
+ enableTool(tool: string): ToolExposureRow | undefined;
395
+ toolExposure(tool: string): ToolExposureRow | undefined;
396
+ /** Every tool switched off in this scope, newest first. */
397
+ listDisabledTools(): ToolExposureRow[];
398
+ }
399
+ /** Shape of the host-facing elicitation call, kept transport-agnostic. */
400
+ export interface ElicitFn {
401
+ (request: {
402
+ message: string;
403
+ requestedSchema: {
404
+ type: "object";
405
+ properties: Record<string, unknown>;
406
+ required?: string[];
407
+ };
408
+ }): Promise<{
409
+ action: "accept" | "decline" | "cancel";
410
+ content?: Record<string, unknown>;
411
+ }>;
412
+ }
413
+ export interface ApprovalRequest {
414
+ readonly tool: string;
415
+ readonly effect: Effect | null;
416
+ readonly args: Record<string, unknown>;
417
+ readonly reason: string;
418
+ readonly actor: string;
419
+ readonly session: string;
420
+ /** Shown to the human: what this call will do upstream. */
421
+ readonly target?: string;
422
+ /** Which rule held the call, recorded on the row. */
423
+ readonly ruleId?: string | undefined;
424
+ /**
425
+ * The bounds the call failed, when a bound is why it is being asked about.
426
+ * Shown to the reviewer: `args_redacted` truncates long arrays and collapses
427
+ * deep subtrees, so the bounded value may not appear in the row at all, and
428
+ * a reviewer approving a binding over a value they were never shown is the
429
+ * worst version of this feature.
430
+ */
431
+ readonly violations?: readonly string[] | undefined;
432
+ /** Digest of the policy the bound came from. */
433
+ readonly policyDigest?: string | undefined;
434
+ /**
435
+ * The arguments that failed a bound, when that is why the call is held. A
436
+ * standing grant releases such a call only if it bounds these itself.
437
+ */
438
+ readonly heldArgs?: readonly string[] | undefined;
439
+ }
440
+ export type ApprovalOutcome = {
441
+ readonly granted: true;
442
+ readonly approvalId: string;
443
+ readonly via: "cached" | "standing" | "elicit" | "cli";
444
+ /** Set when a standing grant released the call, for the audit record. */
445
+ readonly grantId?: string;
446
+ } | {
447
+ readonly granted: false;
448
+ readonly approvalId: string | null;
449
+ readonly reason: string;
450
+ /** Text handed back to the agent telling it how the human can release the call. */
451
+ readonly instructions?: string;
452
+ /**
453
+ * Set when the call is waiting for out-of-band review: `new` the first
454
+ * time it is parked, `existing` when a retry was handed the request that
455
+ * was already open. What tells a caller whether anyone needs telling.
456
+ */
457
+ readonly parked?: "new" | "existing";
458
+ /** Set when a person said no to this exact call: it is refused, not waiting. */
459
+ readonly refusedByPerson?: true;
460
+ };
461
+ export interface ApprovalBrokerOptions {
462
+ readonly config: ApprovalsConfig;
463
+ /**
464
+ * Already bound to one component and one tenant. The broker reads and writes
465
+ * approvals on the hot path, so handing it an unscoped store is precisely
466
+ * the mistake that let one tenant's grant release another's call — this type
467
+ * is what makes that unrepresentable.
468
+ */
469
+ readonly store: ScopedApprovals;
470
+ /** Supplied when the connected host advertises the elicitation capability. */
471
+ readonly elicit?: ElicitFn | undefined;
472
+ readonly redactKeys?: readonly string[];
473
+ /**
474
+ * Records what a tool does, when the reviewer says so while approving a
475
+ * call that was held because nothing classified it. Supplied by a caller
476
+ * that has a policy file it is allowed to write; without it the prompt does
477
+ * not ask. Returns the id of the rule it wrote.
478
+ */
479
+ readonly classify?: ((tool: string, effect: Effect) => string | Promise<string>) | undefined;
480
+ /**
481
+ * Turns an approval into a standing grant for calls like it, when the
482
+ * reviewer asks for that in the prompt. Supplied by a caller that can bound
483
+ * the grant and record it; without it the prompt does not offer. Returns
484
+ * the id of the grant it made.
485
+ */
486
+ readonly remember?: ((req: ApprovalRequest, ttlSeconds: number, approvalId: string) => string | Promise<string>) | undefined;
487
+ /** Overridable for tests. */
488
+ readonly now?: () => number;
489
+ }
490
+ /**
491
+ * Runs the approval flow for a single call: reuse an existing grant, else ask
492
+ * the host interactively, else park the request for out-of-band review.
493
+ */
494
+ export declare class ApprovalBroker {
495
+ private readonly config;
496
+ private readonly store;
497
+ private readonly elicit;
498
+ private readonly redactKeys;
499
+ private readonly classify;
500
+ private readonly remember;
501
+ private readonly now;
502
+ constructor(options: ApprovalBrokerOptions);
503
+ request(req: ApprovalRequest): Promise<ApprovalOutcome>;
504
+ /** Polls the store until the request is decided or `deadline` passes. */
505
+ private waitForDecision;
506
+ }
507
+ /** How long a person's "no" to an exact call is remembered and told to the AI. */
508
+ export declare const DENY_REMEMBER_MS: number;