approval-md 0.3.0 → 0.4.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 +83 -914
- package/SPEC.md +98 -13
- package/cli.js +66 -7
- package/dist/src/adapters/smtp.d.ts +18 -0
- package/dist/src/adapters/smtp.js +24 -3
- package/dist/src/adapters/smtp.js.map +1 -1
- package/dist/src/channels/contract.d.ts +19 -0
- package/dist/src/channels/contract.js +105 -1
- package/dist/src/channels/contract.js.map +1 -1
- package/dist/src/channels/relay-server.d.ts +90 -0
- package/dist/src/channels/relay-server.js +295 -0
- package/dist/src/channels/relay-server.js.map +1 -0
- package/dist/src/channels/relay.d.ts +273 -0
- package/dist/src/channels/relay.js +564 -0
- package/dist/src/channels/relay.js.map +1 -0
- package/dist/src/channels/tagging.js +6 -1
- package/dist/src/channels/tagging.js.map +1 -1
- package/dist/src/channels/telegram-webhook.d.ts +273 -0
- package/dist/src/channels/telegram-webhook.js +536 -0
- package/dist/src/channels/telegram-webhook.js.map +1 -0
- package/dist/src/channels/telegram.d.ts +271 -1
- package/dist/src/channels/telegram.js +403 -45
- package/dist/src/channels/telegram.js.map +1 -1
- package/dist/src/cli/amend.js +350 -4
- package/dist/src/cli/amend.js.map +1 -1
- package/dist/src/cli/attest.js +43 -6
- package/dist/src/cli/attest.js.map +1 -1
- package/dist/src/cli/channel-relay.d.ts +108 -0
- package/dist/src/cli/channel-relay.js +334 -0
- package/dist/src/cli/channel-relay.js.map +1 -0
- package/dist/src/cli/channel-telegram-webhook.d.ts +273 -0
- package/dist/src/cli/channel-telegram-webhook.js +709 -0
- package/dist/src/cli/channel-telegram-webhook.js.map +1 -0
- package/dist/src/cli/channel-telegram.d.ts +272 -26
- package/dist/src/cli/channel-telegram.js +478 -41
- package/dist/src/cli/channel-telegram.js.map +1 -1
- package/dist/src/cli/channel.d.ts +1 -1
- package/dist/src/cli/channel.js +5 -1
- package/dist/src/cli/channel.js.map +1 -1
- package/dist/src/cli/daemon.js +37 -5
- package/dist/src/cli/daemon.js.map +1 -1
- package/dist/src/cli/doctor.d.ts +63 -0
- package/dist/src/cli/doctor.js +856 -111
- package/dist/src/cli/doctor.js.map +1 -1
- package/dist/src/cli/execute.d.ts +17 -1
- package/dist/src/cli/execute.js +341 -20
- package/dist/src/cli/execute.js.map +1 -1
- package/dist/src/cli/exit-codes.d.ts +12 -0
- package/dist/src/cli/exit-codes.js +13 -0
- package/dist/src/cli/exit-codes.js.map +1 -1
- package/dist/src/cli/gate.d.ts +2 -0
- package/dist/src/cli/gate.js +233 -2
- package/dist/src/cli/gate.js.map +1 -1
- package/dist/src/cli/help.d.ts +9 -1
- package/dist/src/cli/help.js +246 -38
- package/dist/src/cli/help.js.map +1 -1
- package/dist/src/cli/hook.d.ts +371 -3
- package/dist/src/cli/hook.js +1926 -44
- package/dist/src/cli/hook.js.map +1 -1
- package/dist/src/cli/init.js +16 -7
- package/dist/src/cli/init.js.map +1 -1
- package/dist/src/cli/instructions.js +24 -3
- package/dist/src/cli/instructions.js.map +1 -1
- package/dist/src/cli/log-anchor.d.ts +55 -0
- package/dist/src/cli/log-anchor.js +199 -60
- package/dist/src/cli/log-anchor.js.map +1 -1
- package/dist/src/cli/main.d.ts +0 -12
- package/dist/src/cli/main.js +51 -0
- package/dist/src/cli/main.js.map +1 -1
- package/dist/src/cli/muse.d.ts +2 -0
- package/dist/src/cli/muse.js +62 -0
- package/dist/src/cli/muse.js.map +1 -0
- package/dist/src/cli/payload.js +79 -1
- package/dist/src/cli/payload.js.map +1 -1
- package/dist/src/cli/scaffold.js +6 -0
- package/dist/src/cli/scaffold.js.map +1 -1
- package/dist/src/cli/serve.d.ts +53 -0
- package/dist/src/cli/serve.js +270 -0
- package/dist/src/cli/serve.js.map +1 -0
- package/dist/src/cli/up.js +21 -2
- package/dist/src/cli/up.js.map +1 -1
- package/dist/src/cli/verb-registry.d.ts +2 -0
- package/dist/src/cli/verb-registry.js +337 -39
- package/dist/src/cli/verb-registry.js.map +1 -1
- package/dist/src/cli/wordmark.d.ts +2 -2
- package/dist/src/cli/wordmark.js +2 -2
- package/dist/src/core/attest-bootstrap.d.ts +95 -0
- package/dist/src/core/attest-bootstrap.js +135 -0
- package/dist/src/core/attest-bootstrap.js.map +1 -0
- package/dist/src/core/attest.d.ts +20 -3
- package/dist/src/core/attest.js +25 -0
- package/dist/src/core/attest.js.map +1 -1
- package/dist/src/core/audit.d.ts +55 -3
- package/dist/src/core/audit.js +52 -5
- package/dist/src/core/audit.js.map +1 -1
- package/dist/src/core/channel-lease.d.ts +322 -0
- package/dist/src/core/channel-lease.js +663 -0
- package/dist/src/core/channel-lease.js.map +1 -0
- package/dist/src/core/command-class.d.ts +51 -0
- package/dist/src/core/command-class.js +760 -8
- package/dist/src/core/command-class.js.map +1 -1
- package/dist/src/core/daemon-host.d.ts +178 -0
- package/dist/src/core/daemon-host.js +228 -0
- package/dist/src/core/daemon-host.js.map +1 -0
- package/dist/src/core/daemon-identity.d.ts +238 -0
- package/dist/src/core/daemon-identity.js +252 -0
- package/dist/src/core/daemon-identity.js.map +1 -0
- package/dist/src/core/gate.d.ts +306 -5
- package/dist/src/core/gate.js +772 -24
- package/dist/src/core/gate.js.map +1 -1
- package/dist/src/core/harness-version.d.ts +128 -4
- package/dist/src/core/harness-version.js +179 -12
- package/dist/src/core/harness-version.js.map +1 -1
- package/dist/src/core/harness-wait.d.ts +82 -3
- package/dist/src/core/harness-wait.js +89 -3
- package/dist/src/core/harness-wait.js.map +1 -1
- package/dist/src/core/log-subscribe.d.ts +21 -0
- package/dist/src/core/log-subscribe.js +16 -6
- package/dist/src/core/log-subscribe.js.map +1 -1
- package/dist/src/core/log-write-layer.d.ts +55 -0
- package/dist/src/core/log-write-layer.js +91 -0
- package/dist/src/core/log-write-layer.js.map +1 -0
- package/dist/src/core/log.d.ts +50 -21
- package/dist/src/core/log.js +197 -19
- package/dist/src/core/log.js.map +1 -1
- package/dist/src/core/payload-census.d.ts +51 -0
- package/dist/src/core/payload-census.js +125 -2
- package/dist/src/core/payload-census.js.map +1 -1
- package/dist/src/core/payload-store.d.ts +31 -0
- package/dist/src/core/payload-store.js +113 -8
- package/dist/src/core/payload-store.js.map +1 -1
- package/dist/src/core/payload.d.ts +18 -3
- package/dist/src/core/payload.js +20 -4
- package/dist/src/core/payload.js.map +1 -1
- package/dist/src/core/policy-diff.d.ts +10 -0
- package/dist/src/core/policy-diff.js +10 -2
- package/dist/src/core/policy-diff.js.map +1 -1
- package/dist/src/core/policy-explain.d.ts +7 -1
- package/dist/src/core/policy-explain.js +16 -1
- package/dist/src/core/policy-explain.js.map +1 -1
- package/dist/src/core/policy-load.d.ts +24 -0
- package/dist/src/core/policy-load.js.map +1 -1
- package/dist/src/core/policy-match.d.ts +38 -0
- package/dist/src/core/policy-match.js +35 -0
- package/dist/src/core/policy-match.js.map +1 -1
- package/dist/src/core/policy-proposal.d.ts +23 -0
- package/dist/src/core/policy-proposal.js +8 -2
- package/dist/src/core/policy-proposal.js.map +1 -1
- package/dist/src/core/read-scope.d.ts +10 -0
- package/dist/src/core/read-scope.js +4 -0
- package/dist/src/core/read-scope.js.map +1 -1
- package/dist/src/core/run-payload.d.ts +160 -0
- package/dist/src/core/run-payload.js +304 -0
- package/dist/src/core/run-payload.js.map +1 -0
- package/dist/src/core/sender-identity.d.ts +35 -10
- package/dist/src/core/sender-identity.js +48 -11
- package/dist/src/core/sender-identity.js.map +1 -1
- package/dist/src/core/state.d.ts +52 -1
- package/dist/src/core/state.js +52 -6
- package/dist/src/core/state.js.map +1 -1
- package/dist/src/core/telegram-config.d.ts +79 -0
- package/dist/src/core/telegram-config.js +108 -0
- package/dist/src/core/telegram-config.js.map +1 -1
- package/dist/src/core/verify.d.ts +23 -1
- package/dist/src/core/verify.js +20 -2
- package/dist/src/core/verify.js.map +1 -1
- package/dist/src/daemon/audit.d.ts +80 -5
- package/dist/src/daemon/audit.js +126 -6
- package/dist/src/daemon/audit.js.map +1 -1
- package/dist/src/daemon/daemon.d.ts +174 -2
- package/dist/src/daemon/daemon.js +298 -7
- package/dist/src/daemon/daemon.js.map +1 -1
- package/dist/src/daemon/git-evidence.d.ts +2 -2
- package/dist/src/daemon/git-evidence.js +1 -1
- package/dist/src/daemon/projection.d.ts +13 -2
- package/dist/src/daemon/projection.js +39 -6
- package/dist/src/daemon/projection.js.map +1 -1
- package/dist/src/mcp/server.d.ts +39 -3
- package/dist/src/mcp/server.js +22 -3
- package/dist/src/mcp/server.js.map +1 -1
- package/dist/src/muse/server.d.ts +16 -0
- package/dist/src/muse/server.js +238 -0
- package/dist/src/muse/server.js.map +1 -0
- package/dist/src/serve/archive.d.ts +158 -0
- package/dist/src/serve/archive.js +354 -0
- package/dist/src/serve/archive.js.map +1 -0
- package/dist/src/serve/arguments.d.ts +93 -0
- package/dist/src/serve/arguments.js +228 -0
- package/dist/src/serve/arguments.js.map +1 -0
- package/dist/src/serve/credentials.d.ts +91 -0
- package/dist/src/serve/credentials.js +143 -0
- package/dist/src/serve/credentials.js.map +1 -0
- package/dist/src/serve/follow.d.ts +86 -0
- package/dist/src/serve/follow.js +101 -0
- package/dist/src/serve/follow.js.map +1 -0
- package/dist/src/serve/hook-thread.d.ts +134 -0
- package/dist/src/serve/hook-thread.js +333 -0
- package/dist/src/serve/hook-thread.js.map +1 -0
- package/dist/src/serve/hook-worker.d.ts +134 -0
- package/dist/src/serve/hook-worker.js +173 -0
- package/dist/src/serve/hook-worker.js.map +1 -0
- package/dist/src/serve/server.d.ts +412 -0
- package/dist/src/serve/server.js +1251 -0
- package/dist/src/serve/server.js.map +1 -0
- package/docs/README-extended.md +766 -0
- package/docs/cli-reference.md +1633 -43
- package/package.json +4 -2
- package/schema/event.schema.json +59 -2
- package/schema/fixtures/event/invalid/daemon-id-malformed.json +15 -0
- package/schema/fixtures/event/invalid/execution-started-truncated-policy-sha256.json +18 -0
- package/schema/fixtures/event/invalid/harness-cap-at-margin.json +16 -0
- package/schema/fixtures/event/invalid/harness-cap-fractional.json +16 -0
- package/schema/fixtures/event/invalid/harness-cap-negative.json +16 -0
- package/schema/fixtures/event/invalid/harness-cap-string.json +16 -0
- package/schema/fixtures/event/invalid/harness-cap-without-harness-execution.json +16 -0
- package/schema/fixtures/event/invalid/harness-cap-zero.json +16 -0
- package/schema/fixtures/event/valid/approval-requested-harness-cap.json +18 -0
- package/schema/fixtures/event/valid/daemon-identity-declared.json +17 -0
- package/schema/fixtures/event/valid/daemon-identity.json +15 -0
- package/schema/fixtures/event/valid/execution-started-policy-sha256.json +18 -0
- package/schema/fixtures/event/valid/harness-kind-hermes.json +23 -0
- package/schema/fixtures/policy/invalid/daemons-malformed-id.json +10 -0
- package/schema/fixtures/policy/valid/daemons-allowlist.json +19 -0
- package/schema/fixtures/policy-md/invalid/schema-invalid-agent-may-request.md +21 -0
- package/schema/fixtures/policy-md/valid/agent-may-request.md +24 -0
- package/schema/policy.schema.json +50 -6
package/dist/src/cli/hook.d.ts
CHANGED
|
@@ -76,8 +76,25 @@ import { type GateOptions } from "../core/gate.js";
|
|
|
76
76
|
import { type HarnessKind } from "../core/harness-version.js";
|
|
77
77
|
import { type HarnessLoopState } from "../core/loop.js";
|
|
78
78
|
import type { EventRecord } from "../core/log.js";
|
|
79
|
+
import { type ReadRecordsResult } from "../core/state.js";
|
|
79
80
|
import type { Streams } from "./main.js";
|
|
80
81
|
import { type Style } from "./style.js";
|
|
82
|
+
/**
|
|
83
|
+
* How many CONSECUTIVE torn-tail reads the decision wait reads past before it
|
|
84
|
+
* treats the log as unreadable (APRV-427 review).
|
|
85
|
+
*
|
|
86
|
+
* The poll reads the log while other writers append to it: the daemon beside
|
|
87
|
+
* a CLI hook, and every other hook call beside one run by `approval serve`. An
|
|
88
|
+
* append is one write on an O_APPEND handle, but a reader on a filesystem that
|
|
89
|
+
* grows a file a page at a time can see the front of a line before its end, and
|
|
90
|
+
* the verified read calls that a torn tail. It is a moment in someone else's
|
|
91
|
+
* write, and the next tick reads the whole line. Treating it as terminal
|
|
92
|
+
* withdrew a live question and denied `hook-io` because a DIFFERENT call was
|
|
93
|
+
* mid-append. So a torn read is read again next tick, like a view that lags;
|
|
94
|
+
* only a tail that stays torn for this many ticks in a row (a crashed write,
|
|
95
|
+
* which nobody is going to finish) takes the old withdraw-and-deny path.
|
|
96
|
+
*/
|
|
97
|
+
export declare const TORN_TAIL_RETRIES = 5;
|
|
81
98
|
/**
|
|
82
99
|
* How much of the command line goes in the (claimed) summary field.
|
|
83
100
|
*
|
|
@@ -166,8 +183,36 @@ export declare const HOOK_DENY_CODES: readonly [
|
|
|
166
183
|
* directory, once. Past the grace the hook withdraws it (reason `timeout`),
|
|
167
184
|
* because a question nothing will adopt is a message on a phone that decides
|
|
168
185
|
* nothing.
|
|
186
|
+
*
|
|
187
|
+
* **Who withdraws, stated because the deny text used to imply a scheduler
|
|
188
|
+
* that does not exist (APRV-410).** This process is over when it denies, so
|
|
189
|
+
* the withdrawal is made by the NEXT gated tool call this actor makes, from
|
|
190
|
+
* the sweep at the top of every gated invocation. It cannot be anyone else: a
|
|
191
|
+
* withdrawal is the requester's own (APRV-106 rule 1, `not-requester`), the
|
|
192
|
+
* gate refuses a `system:` withdrawal outright, and the event schema binds
|
|
193
|
+
* the one `system:` withdrawal that exists to `policy-drift` and to nothing
|
|
194
|
+
* else (APRV-235). So a session that denies here and then makes no further
|
|
195
|
+
* gated call leaves the question pending until the TTL, and a decision on it
|
|
196
|
+
* lands as an ordinary grant. What stops that grant authorizing anything is
|
|
197
|
+
* the other half of APRV-410: a retry past the grace does not carry it
|
|
198
|
+
* (`findHarnessCarry`), so it asks again.
|
|
169
199
|
*/
|
|
170
200
|
"hook-timeout",
|
|
201
|
+
/**
|
|
202
|
+
* The harness ceiling this hook was told it runs under leaves no window a
|
|
203
|
+
* human could answer in (APRV-423).
|
|
204
|
+
*
|
|
205
|
+
* `--harness-cap` (or the harness's own documented maximum) at or below
|
|
206
|
+
* `HARNESS_CAP_MARGIN_MS` means the question would lapse at the instant it
|
|
207
|
+
* was asked: the request must end a margin before the harness kills the
|
|
208
|
+
* process that opened it, and there is no room left for the asking. Nothing
|
|
209
|
+
* is registered, nothing is requested and nobody's phone lights up. The
|
|
210
|
+
* repair is a configuration change — raise the harness entry's timeout, or
|
|
211
|
+
* state the real one — and it is a refusal rather than a silent widening
|
|
212
|
+
* because a hook that quietly ignored its own ceiling would be back to
|
|
213
|
+
* recording grants on calls nobody holds.
|
|
214
|
+
*/
|
|
215
|
+
"hook-harness-cap-too-short",
|
|
171
216
|
/** The gate refused intake; the gate's own code follows a colon. */
|
|
172
217
|
"hook-gate-refused",
|
|
173
218
|
/**
|
|
@@ -250,6 +295,32 @@ export declare const HOOK_DENY_CODES: readonly [
|
|
|
250
295
|
* and it cannot recall a prompt the model has already been sent.
|
|
251
296
|
*/
|
|
252
297
|
"hook-muse-contributor-model",
|
|
298
|
+
/**
|
|
299
|
+
* A Hermes Agent `execute_code` call, refused before anything else looks at
|
|
300
|
+
* it (APRV-398).
|
|
301
|
+
*
|
|
302
|
+
* The tool takes a `code` string and runs it in-process. There is no path, no
|
|
303
|
+
* argv and no working directory: nothing the classifier reads exists in the
|
|
304
|
+
* call, so no class can be resolved and no payload can bind what will happen.
|
|
305
|
+
* A verdict over `{code}` would authorize a program this runtime never
|
|
306
|
+
* parsed, which is the same hole `hook-opaque` closes for `bash -c` and the
|
|
307
|
+
* same one `hook-unsupported-execution-context` closes for a command whose
|
|
308
|
+
* directory is invisible. SPEC.md §11.1 says ambiguity resolves to the
|
|
309
|
+
* stricter path, and the strictest honest answer to "may I run this arbitrary
|
|
310
|
+
* program" is no.
|
|
311
|
+
*
|
|
312
|
+
* Distinct from `hook-opaque`, and the distinction is the repair. That one
|
|
313
|
+
* says a command line carried a construct the classifier could not read, and
|
|
314
|
+
* the fix is to write the command differently. This one says the TOOL has no
|
|
315
|
+
* readable surface at all on this harness, so there is no spelling of an
|
|
316
|
+
* `execute_code` call that would be answered differently: the repair is to do
|
|
317
|
+
* the work through the shell tool, where the words are visible and the
|
|
318
|
+
* classifier can price them, or through `approval run` with a granted token.
|
|
319
|
+
*
|
|
320
|
+
* Distinct from `hook-unclassified`, which says the classifier had nothing to
|
|
321
|
+
* say about bytes it could see. Here there are no bytes to see.
|
|
322
|
+
*/
|
|
323
|
+
"hook-hermes-execute-code-unbound",
|
|
253
324
|
/** Malformed hook input, or a log/filesystem fact that stopped the check. */
|
|
254
325
|
"hook-io"];
|
|
255
326
|
export type HookDenyCode = (typeof HOOK_DENY_CODES)[number];
|
|
@@ -278,12 +349,47 @@ export declare function hookScope(flags: Record<string, string | boolean>, cwd:
|
|
|
278
349
|
* harnesses this runtime speaks a protocol for is the same set it knows a
|
|
279
350
|
* binary name for, and two copies of it would be two lists to drift.
|
|
280
351
|
*/
|
|
352
|
+
/**
|
|
353
|
+
* What a harness's own non-shell, non-file tool asks for (APRV-445).
|
|
354
|
+
*
|
|
355
|
+
* `gated` names the class the call is judged under and the headline the
|
|
356
|
+
* approver reads; the payload is always the WHOLE call (`{tool, input}`), so a
|
|
357
|
+
* grant binds every argument the harness will act on. `read` is a call that
|
|
358
|
+
* touches nothing and is allowed without a record, exactly as an in-scope read
|
|
359
|
+
* tool is. A rule returns `null` for a tool it does not know, and that tool
|
|
360
|
+
* keeps the not-a-gated-tool allow every unknown tool has.
|
|
361
|
+
*/
|
|
362
|
+
type ToolRuleVerdict = {
|
|
363
|
+
kind: "gated";
|
|
364
|
+
cls: string;
|
|
365
|
+
headline: string;
|
|
366
|
+
} | {
|
|
367
|
+
kind: "read";
|
|
368
|
+
reason: string;
|
|
369
|
+
};
|
|
370
|
+
/**
|
|
371
|
+
* The ceiling a harness puts on its hook process, in milliseconds, or `null`
|
|
372
|
+
* (APRV-423): the operator's stated `--harness-cap` clamped to the adapter's
|
|
373
|
+
* contractual maximum, or, with nothing stated, the adapter's documented
|
|
374
|
+
* default, falling back to that maximum.
|
|
375
|
+
*
|
|
376
|
+
* Exported so `approval serve` computes the same number the hook will before
|
|
377
|
+
* it hands the call to a thread (APRV-427 review): the budget a queued call
|
|
378
|
+
* has left is this less the time it has waited.
|
|
379
|
+
*/
|
|
380
|
+
export declare function effectiveHarnessCapMs(adapter: Pick<HarnessAdapter, "capCeilingMs" | "capDefaultMs">, statedCapMs: number | null): number | null;
|
|
281
381
|
interface HarnessAdapter {
|
|
282
382
|
kind: HarnessKind;
|
|
283
383
|
originApp: string;
|
|
284
384
|
defaultActor: string;
|
|
285
385
|
shellTool: string;
|
|
286
386
|
fileTools: readonly string[];
|
|
387
|
+
/**
|
|
388
|
+
* The harness's own tools that carry a side effect of their own, by name and
|
|
389
|
+
* arguments (APRV-445). Consulted after the shell, file and read tools, for
|
|
390
|
+
* the calls none of those owns.
|
|
391
|
+
*/
|
|
392
|
+
toolRules?: (toolName: string, toolInput: Record<string, unknown>) => ToolRuleVerdict | null;
|
|
287
393
|
/**
|
|
288
394
|
* Tools that READ a named path (APRV-347).
|
|
289
395
|
*
|
|
@@ -329,6 +435,47 @@ interface HarnessAdapter {
|
|
|
329
435
|
* its shell arm refuses outright; Claude Code has only the top-level one.
|
|
330
436
|
*/
|
|
331
437
|
shellCwdKey?: string;
|
|
438
|
+
/**
|
|
439
|
+
* The hard ceiling this harness's own contract puts on one hook process, in
|
|
440
|
+
* milliseconds, or absent when it documents none (APRV-423).
|
|
441
|
+
*
|
|
442
|
+
* A CEILING, not a configuration. Hermes states that a `hooks:` entry's
|
|
443
|
+
* `timeout` may not exceed 300 s, so no Hermes entry can outlive that however
|
|
444
|
+
* it is written, and this runtime may rely on it. Claude Code, Cursor, Grok,
|
|
445
|
+
* Muse and Codex document a DEFAULT hook timeout and no maximum, so they
|
|
446
|
+
* carry none: an adapter that guessed a ceiling would either invent a
|
|
447
|
+
* deadline the harness never imposed, or — worse, and the direction that
|
|
448
|
+
* actually costs something — guess high and leave the gap APRV-410 falls
|
|
449
|
+
* through. The operator states the entry they configured with
|
|
450
|
+
* `--harness-cap`, and the effective cap is the smaller of the two.
|
|
451
|
+
*/
|
|
452
|
+
capCeilingMs?: number;
|
|
453
|
+
/**
|
|
454
|
+
* The ceiling this harness imposes on a hook process when the operator has
|
|
455
|
+
* stated none, in milliseconds, or absent when the harness's defaults leave
|
|
456
|
+
* the process unbounded (APRV-423, second review pass).
|
|
457
|
+
*
|
|
458
|
+
* Read ONLY when `--harness-cap` is absent, and then it stands in for the
|
|
459
|
+
* flag: the operator has said nothing, so the runtime assumes the harness is
|
|
460
|
+
* running as shipped. It is the STRICTEST bound the harness's own defaults
|
|
461
|
+
* put on the process, because assuming a looser one is APRV-410 with a
|
|
462
|
+
* fictional deadline: a request judged against a window the harness will not
|
|
463
|
+
* keep open. On Hermes that is `plugins.hook_callback_timeout`, which bounds
|
|
464
|
+
* the whole hook dispatch and defaults to 30 s, well under the margin, so a
|
|
465
|
+
* Hermes hook with no flag is refused `hook-harness-cap-too-short` until the
|
|
466
|
+
* operator raises that setting and says so. A stated flag replaces this
|
|
467
|
+
* value (the operator knows what they configured) and is still clamped by
|
|
468
|
+
* {@link capCeilingMs}, so a stated cap can only shorten the contractual
|
|
469
|
+
* maximum, never exceed it.
|
|
470
|
+
*/
|
|
471
|
+
capDefaultMs?: number;
|
|
472
|
+
/**
|
|
473
|
+
* How an operator lifts a `hook-harness-cap-too-short` refusal on this
|
|
474
|
+
* harness, in the harness's own vocabulary (APRV-423, second review pass).
|
|
475
|
+
* Appended to the deny so the repair names the setting to change rather than
|
|
476
|
+
* a generic "raise the timeout". Absent adapters get the generic sentence.
|
|
477
|
+
*/
|
|
478
|
+
capRepair?: string;
|
|
332
479
|
/**
|
|
333
480
|
* Refuse every tool call when the envelope names a Contributor-tier model
|
|
334
481
|
* (APRV-350).
|
|
@@ -340,6 +487,19 @@ interface HarnessAdapter {
|
|
|
340
487
|
*/
|
|
341
488
|
contributorModelGuard?: boolean;
|
|
342
489
|
}
|
|
490
|
+
/**
|
|
491
|
+
* Hermes Agent's event names, which are its own and not Claude Code's
|
|
492
|
+
* (APRV-398).
|
|
493
|
+
*
|
|
494
|
+
* snake_case, and the VERBS differ too: `pre_tool_call` where every other
|
|
495
|
+
* harness in this table says `PreToolUse`. That is why they are constants
|
|
496
|
+
* rather than two more entries in {@link POST_TOOL_EVENTS} — a harness whose
|
|
497
|
+
* post-event name appeared in that shared list would also accept
|
|
498
|
+
* `PostToolUse` from an event nobody sent, and the dispatch would answer a
|
|
499
|
+
* name this harness never uses.
|
|
500
|
+
*/
|
|
501
|
+
export declare const HERMES_PRE_TOOL_EVENT = "pre_tool_call";
|
|
502
|
+
export declare const HERMES_POST_TOOL_EVENT = "post_tool_call";
|
|
343
503
|
/**
|
|
344
504
|
* Every harness this runtime speaks a hook protocol for, by kind (APRV-358).
|
|
345
505
|
*
|
|
@@ -358,6 +518,27 @@ interface HarnessAdapter {
|
|
|
358
518
|
* failed.
|
|
359
519
|
*/
|
|
360
520
|
export declare const HARNESS_ADAPTERS: Readonly<Record<HarnessKind, HarnessAdapter>>;
|
|
521
|
+
/**
|
|
522
|
+
* The block directive a harness reads, as bytes, for a refusal raised OUTSIDE
|
|
523
|
+
* the hook (APRV-421).
|
|
524
|
+
*
|
|
525
|
+
* `approval serve` can refuse a hook request before `commandHook` is reached
|
|
526
|
+
* at all: an oversized body, a credential at the wrong door, a method it does
|
|
527
|
+
* not answer. Each of those is a refusal by the transport, and a transport
|
|
528
|
+
* refusal a harness reads as "no verdict" is a harness that runs the command.
|
|
529
|
+
* So the refusal has to be spoken in the harness's own dialect, and the only
|
|
530
|
+
* correct source of that dialect is the function that prints it here.
|
|
531
|
+
*
|
|
532
|
+
* It renders through {@link deny} for that reason: one construction site per
|
|
533
|
+
* harness, still never `ask`. The exit code returned is the one the verb would
|
|
534
|
+
* have carried; a caller may impose a stricter one, and the transport does.
|
|
535
|
+
*/
|
|
536
|
+
export declare function harnessBlockDirective(code: string, detail: string, harness: HarnessKind): {
|
|
537
|
+
stdout: string;
|
|
538
|
+
exitCode: number;
|
|
539
|
+
};
|
|
540
|
+
/** The machine-readable code a Hermes `execute_code` call is refused with. */
|
|
541
|
+
export declare const HERMES_EXECUTE_CODE_REFUSAL = "hook-hermes-execute-code-unbound";
|
|
361
542
|
/** The machine-readable code a Contributor-tier session is refused with. */
|
|
362
543
|
export declare const MUSE_CONTRIBUTOR_REFUSAL = "hook-muse-contributor-model";
|
|
363
544
|
export interface HookInput {
|
|
@@ -500,12 +681,48 @@ export declare function resolveReadRoots(cwd: string, gateRoot: string, declared
|
|
|
500
681
|
*/
|
|
501
682
|
export declare function refineReadScope(result: CommandClassification, roots: readonly string[], cwd: string): RefinedClassification;
|
|
502
683
|
/**
|
|
503
|
-
* The
|
|
684
|
+
* The roots a write may land in, resolved.
|
|
685
|
+
*
|
|
686
|
+
* The scratch roots are the ones `resolveScratchRoots` already computes and
|
|
687
|
+
* already guards, so this rule and the delete rule cannot disagree about where
|
|
688
|
+
* the agent's own scratch is. The working directory is the other one, and it is
|
|
689
|
+
* the root the classifier's own text rule already implies: "a relative
|
|
690
|
+
* destination is the workspace" means the workspace is wherever the command
|
|
691
|
+
* runs.
|
|
692
|
+
*
|
|
693
|
+
* `cwd` is harness-supplied, and reading a root out of it does not offend
|
|
694
|
+
* SPEC.md §11.1 invariant 4, because this pass only ever narrows. The baseline
|
|
695
|
+
* it narrows from is no check at all, so a poisoned `cwd` buys back exactly
|
|
696
|
+
* today's answer and never a looser one. Compare the read pass, which checks
|
|
697
|
+
* containment against the GATE root: that pass decides whether a read is in
|
|
698
|
+
* scope at all, so the scope has to be one the subject cannot choose. This one
|
|
699
|
+
* only takes an allowance away.
|
|
700
|
+
*/
|
|
701
|
+
export declare function resolveWriteRoots(cwd: string): string[];
|
|
702
|
+
/**
|
|
703
|
+
* Tighten a `files.write.workspace` segment to the out-of-scope write class
|
|
704
|
+
* wherever the disk disagrees with the text.
|
|
705
|
+
*
|
|
706
|
+
* IMPURE by design and by contract, exactly as the other two passes are. The
|
|
707
|
+
* class it tightens to is the one `core/command-class.ts` already answers for
|
|
708
|
+
* an out-of-scope packaging destination rather than a new name: a class no
|
|
709
|
+
* policy mentions resolves by `defaults.autonomy` (SPEC.md §7), so minting
|
|
710
|
+
* `files.write.out_of_scope` here would arrive AUTONOMOUS in every deployment
|
|
711
|
+
* with permissive defaults, which is the one way a tightening pass could
|
|
712
|
+
* loosen something.
|
|
713
|
+
*
|
|
714
|
+
* `roots` empty means the caller asked for no write scoping, and every segment
|
|
715
|
+
* comes back untouched: the same "absent yields today's answer" the read pass
|
|
716
|
+
* promises.
|
|
717
|
+
*/
|
|
718
|
+
export declare function refineWriteScope(result: CommandClassification, roots: readonly string[], cwd: string): RefinedClassification;
|
|
719
|
+
/**
|
|
720
|
+
* The classifier, its context, and all four impure refinements, in the one
|
|
504
721
|
* order every caller must use.
|
|
505
722
|
*
|
|
506
723
|
* `hook classify` printing a different class from the one `hook claude-code`
|
|
507
724
|
* decides would make the explainer a different program (APRV-108's note), and
|
|
508
|
-
* that stays true now there are
|
|
725
|
+
* that stays true now there are four refinements in the chain.
|
|
509
726
|
*
|
|
510
727
|
* `readRoots` is the one argument whose ABSENCE is the loose answer rather than
|
|
511
728
|
* the strict one (APRV-347), so it is passed explicitly at every call site: an
|
|
@@ -523,7 +740,75 @@ export declare function classifyForHook(command: string, protectedPaths: readonl
|
|
|
523
740
|
* that the `json` veto on colour is the answer this process memoizes.
|
|
524
741
|
*/
|
|
525
742
|
export declare function renderClassification(result: CommandClassification, json: boolean, st?: Style): string;
|
|
743
|
+
/**
|
|
744
|
+
* Where a hook invocation stops appending and starts waiting, for a caller that
|
|
745
|
+
* shares one store with other work in the same process (APRV-427).
|
|
746
|
+
*
|
|
747
|
+
* `approval serve` runs many hook calls, verbs and log reads against one store
|
|
748
|
+
* from one process. Its per-store lock has to cover every stretch in which a
|
|
749
|
+
* hook call APPENDS (intake, the abandoned-question sweep, register, request,
|
|
750
|
+
* the spend, the withdrawals) so that no other in-process writer lands between
|
|
751
|
+
* a check and its append; and it must NOT cover the poll loop, where the hook
|
|
752
|
+
* only reads the verified log and sleeps, or one question waiting on a human
|
|
753
|
+
* holds the tenant's whole facade for as long as the human takes.
|
|
754
|
+
*
|
|
755
|
+
* So the loop says where it begins and ends. `enterWait` is called once, right
|
|
756
|
+
* before the first poll, and after it nothing is appended until `leaveWait`
|
|
757
|
+
* returns. `leaveWait` is called before every append the loop can reach (the
|
|
758
|
+
* spend on a grant, a withdrawal on a failed read, at the deadline, on a throw
|
|
759
|
+
* or a signal) and once more when the loop is left by any route, and it may
|
|
760
|
+
* BLOCK until the caller's lock is held again. Both are idempotent pairs: the
|
|
761
|
+
* hook never calls `leaveWait` without a matching `enterWait` before it.
|
|
762
|
+
*
|
|
763
|
+
* Absent (the CLI, the Codex bridge), both are no-ops and the invocation is
|
|
764
|
+
* byte-for-byte what it was. The seam decides nothing: no verdict, record or
|
|
765
|
+
* line depends on it, and the appends it brackets are compare-and-append
|
|
766
|
+
* either way (SPEC.md §11.1 invariant 5). It only tells an embedding caller
|
|
767
|
+
* which stretch of the call is safe to run beside other writers.
|
|
768
|
+
*/
|
|
769
|
+
export interface HookWaitSeam {
|
|
770
|
+
/** The poll loop is about to start: nothing is appended until {@link leaveWait}. */
|
|
771
|
+
enterWait(): void;
|
|
772
|
+
/** An append follows, or the loop is over. May block until the caller's lock is held. */
|
|
773
|
+
leaveWait(): void;
|
|
774
|
+
/**
|
|
775
|
+
* The read each poll tick makes. Omitted by every real caller, which gets
|
|
776
|
+
* `readVerifiedRecords`; it exists so a test can put a torn read in front of
|
|
777
|
+
* the loop without writing a torn line into a log.
|
|
778
|
+
*/
|
|
779
|
+
pollRead?: (logPath: string) => ReadRecordsResult;
|
|
780
|
+
/**
|
|
781
|
+
* Whether the party this invocation answers has gone away (APRV-427 review).
|
|
782
|
+
*
|
|
783
|
+
* `approval serve` sets it when the HTTP client that asked disconnects. Read
|
|
784
|
+
* on every poll tick, and once more after the lock is re-taken and before a
|
|
785
|
+
* grant is spent: while it is set, the invocation stops waiting WITHOUT
|
|
786
|
+
* spending and WITHOUT withdrawing, so the question (or its grant) is left
|
|
787
|
+
* exactly as a hook-timeout inside the retry grace leaves it, for the
|
|
788
|
+
* harness's retry to adopt. A grant already spent is not affected: the check
|
|
789
|
+
* precedes the spend, and nothing after it looks again.
|
|
790
|
+
*/
|
|
791
|
+
cancelled?: () => boolean;
|
|
792
|
+
/**
|
|
793
|
+
* What is LEFT of the harness's ceiling when this invocation begins, in
|
|
794
|
+
* milliseconds, as the embedding caller measured it (APRV-427 review).
|
|
795
|
+
*
|
|
796
|
+
* The harness's ceiling runs from the moment the harness sent the call, not
|
|
797
|
+
* from the moment this invocation began. `approval serve` may hold a call in
|
|
798
|
+
* line for a thread, and for the store lock, before the hook's first line
|
|
799
|
+
* runs; that time is spent out of the same budget. The caller computes the
|
|
800
|
+
* remainder ONCE, admits the call on it, and hands the same number here, so
|
|
801
|
+
* the hook judges, waits by and records on the request exactly what the
|
|
802
|
+
* caller admitted: a call the caller let through never meets
|
|
803
|
+
* `hook-harness-cap-too-short` a few milliseconds later. It can only
|
|
804
|
+
* shorten the ceiling the flags give (never lengthen it), and it is omitted
|
|
805
|
+
* by the CLI, where the process starts when the harness calls.
|
|
806
|
+
*/
|
|
807
|
+
remainingCapMs?: number;
|
|
808
|
+
}
|
|
526
809
|
interface HookRun {
|
|
810
|
+
/** APRV-427: the embedding caller's wait seam, or `null` from the CLI. */
|
|
811
|
+
waitSeam: HookWaitSeam | null;
|
|
527
812
|
logPath: string;
|
|
528
813
|
options: GateOptions;
|
|
529
814
|
actor: string;
|
|
@@ -539,6 +824,57 @@ interface HookRun {
|
|
|
539
824
|
graceMs: number;
|
|
540
825
|
/** `defaults.approval_ttl`, or `null` when the policy declares none. */
|
|
541
826
|
ttlMs: number | null;
|
|
827
|
+
/**
|
|
828
|
+
* The ceiling this harness puts on this process, in milliseconds, or `null`
|
|
829
|
+
* (APRV-423).
|
|
830
|
+
*
|
|
831
|
+
* The entry timeout the operator stated with `--harness-cap`, clamped to the
|
|
832
|
+
* harness's own documented maximum ({@link HarnessAdapter.capCeilingMs}); or,
|
|
833
|
+
* when no flag was passed, the harness's default bound
|
|
834
|
+
* ({@link HarnessAdapter.capDefaultMs}, falling back to the ceiling). It is
|
|
835
|
+
* written onto every request this invocation opens and read back by the gate,
|
|
836
|
+
* which judges the question against the shorter of it (minus the margin) and
|
|
837
|
+
* the policy's TTL — so the request ends while this process is still alive to
|
|
838
|
+
* be told, and the daemon's `approval.expired` lands before the harness gives
|
|
839
|
+
* up.
|
|
840
|
+
*/
|
|
841
|
+
harnessCapMs: number | null;
|
|
842
|
+
/**
|
|
843
|
+
* Whether {@link harnessCapMs} came from the operator's own `--harness-cap`
|
|
844
|
+
* (`true`) or was assumed from the adapter's documented defaults (`false`).
|
|
845
|
+
* A refusal for a cap with no room in it says which, because the repair
|
|
846
|
+
* differs: a stated cap is a real configuration to raise, an assumed one is
|
|
847
|
+
* a flag the operator has not passed yet.
|
|
848
|
+
*/
|
|
849
|
+
harnessCapStated: boolean;
|
|
850
|
+
/**
|
|
851
|
+
* The ceiling {@link harnessCapMs} was charged down from, or `null` where
|
|
852
|
+
* nothing was charged (APRV-427 review). Wording only.
|
|
853
|
+
*/
|
|
854
|
+
harnessCapCeilingMs: number | null;
|
|
855
|
+
/** {@link HarnessAdapter.capRepair}, or `null` for the generic sentence. */
|
|
856
|
+
harnessCapRepair: string | null;
|
|
857
|
+
/**
|
|
858
|
+
* How long THIS invocation actually waits, in milliseconds (APRV-423, third
|
|
859
|
+
* review pass): `timeoutMs`, clamped to what the harness ceiling leaves after
|
|
860
|
+
* the margin (`harnessCapMs - HARNESS_CAP_MARGIN_MS`) when there is one, and
|
|
861
|
+
* never below zero.
|
|
862
|
+
*
|
|
863
|
+
* The clamp is what closes the adopted-question gap. The too-short refusal
|
|
864
|
+
* fires only for a question this invocation would OPEN; an invocation whose
|
|
865
|
+
* every key is adopted (a retry of bytes an earlier, correctly-capped run
|
|
866
|
+
* asked about) opens nothing, so under a ceiling with no room in it (a Hermes
|
|
867
|
+
* hook with no `--harness-cap`, assumed 30 s) it would have sat in its poll
|
|
868
|
+
* loop for the configured wait, been killed at the ceiling, and let the call
|
|
869
|
+
* proceed on any harness without `fail_closed`. Bounding the wait itself means
|
|
870
|
+
* the hook always answers before the harness stops listening: a zero wait
|
|
871
|
+
* reads the verified log once (so a decision already recorded is still
|
|
872
|
+
* honoured) and then denies `hook-timeout`, leaving the adopted question open
|
|
873
|
+
* for the retry grace exactly as a wait that ran out would. The adopted
|
|
874
|
+
* question's OWN deadline is whatever was recorded when it was opened; this
|
|
875
|
+
* changes nothing about it.
|
|
876
|
+
*/
|
|
877
|
+
waitMs: number;
|
|
542
878
|
harness: HarnessKind;
|
|
543
879
|
originApp: string;
|
|
544
880
|
/** Exact native command bytes required in a Codex allow's identity update. */
|
|
@@ -755,6 +1091,26 @@ export interface DecideInput {
|
|
|
755
1091
|
timeoutMs: number;
|
|
756
1092
|
intervalMs: number;
|
|
757
1093
|
graceMs: number;
|
|
1094
|
+
/**
|
|
1095
|
+
* The harness's ceiling on this process, in milliseconds, or `null`
|
|
1096
|
+
* (APRV-423). See {@link HookRun.harnessCapMs}. A caller that is not run by a
|
|
1097
|
+
* harness on a timer — `cli/codex-bridge.ts` holds its own connection open —
|
|
1098
|
+
* passes `null` and the policy's TTL governs alone.
|
|
1099
|
+
*/
|
|
1100
|
+
harnessCapMs?: number | null;
|
|
1101
|
+
/**
|
|
1102
|
+
* Whether `harnessCapMs` was stated by the operator (`--harness-cap`) rather
|
|
1103
|
+
* than assumed from the adapter's documented defaults (APRV-423, second
|
|
1104
|
+
* review pass). Defaults to `false`; see {@link HookRun.harnessCapStated}.
|
|
1105
|
+
*/
|
|
1106
|
+
harnessCapStated?: boolean;
|
|
1107
|
+
/**
|
|
1108
|
+
* The ceiling `harnessCapMs` was charged down from, where an embedding
|
|
1109
|
+
* caller charged time spent before this invocation began (APRV-427 review).
|
|
1110
|
+
* Wording only: a refusal names both, so the operator's stated number is
|
|
1111
|
+
* not reported as the remainder.
|
|
1112
|
+
*/
|
|
1113
|
+
harnessCapCeilingMs?: number;
|
|
758
1114
|
/** Exact native command bytes a Codex allow must carry back, where there are any. */
|
|
759
1115
|
codexCommand?: string | undefined;
|
|
760
1116
|
/**
|
|
@@ -765,6 +1121,12 @@ export interface DecideInput {
|
|
|
765
1121
|
* lookup passes `null`, and both of them read the log themselves.
|
|
766
1122
|
*/
|
|
767
1123
|
windowRecords: EventRecord[] | null;
|
|
1124
|
+
/**
|
|
1125
|
+
* Where the wait begins and ends, for a caller that runs this beside other
|
|
1126
|
+
* writers in one process (APRV-427; see {@link HookWaitSeam}). Omitted by
|
|
1127
|
+
* every CLI route, where it is a no-op.
|
|
1128
|
+
*/
|
|
1129
|
+
waitSeam?: HookWaitSeam | null;
|
|
768
1130
|
}
|
|
769
1131
|
/**
|
|
770
1132
|
* Classify, resolve, gate and wait: one harness tool call, from the event to a
|
|
@@ -783,5 +1145,11 @@ export interface DecideInput {
|
|
|
783
1145
|
* progress and withdrawal lines, which are a report rather than a decision.
|
|
784
1146
|
*/
|
|
785
1147
|
export declare function decideHarnessCall(decide: DecideInput): HarnessVerdict;
|
|
786
|
-
export declare function commandHook(argv: string[], streams: Streams, cwd: string, readStdin?: () => string
|
|
1148
|
+
export declare function commandHook(argv: string[], streams: Streams, cwd: string, readStdin?: () => string,
|
|
1149
|
+
/**
|
|
1150
|
+
* APRV-427: where a harness hook's wait begins and ends, for `approval serve`,
|
|
1151
|
+
* which runs the call off its main thread and releases its store lock while
|
|
1152
|
+
* the call polls. Every CLI route omits it. See {@link HookWaitSeam}.
|
|
1153
|
+
*/
|
|
1154
|
+
waitSeam?: HookWaitSeam | null): number;
|
|
787
1155
|
export {};
|