@lannguyensi/harness 0.59.2 → 0.60.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/CHANGELOG.md +36 -0
- package/README.md +1 -1
- package/dist/cli/apply/apply.d.ts +20 -0
- package/dist/cli/apply/apply.js +13 -7
- package/dist/cli/apply/apply.js.map +1 -1
- package/dist/cli/apply/install-codex-config.d.ts +11 -3
- package/dist/cli/apply/install-codex-config.js +130 -52
- package/dist/cli/apply/install-codex-config.js.map +1 -1
- package/dist/cli/approve/understanding.js +34 -28
- package/dist/cli/approve/understanding.js.map +1 -1
- package/dist/cli/doctor/format.js +22 -0
- package/dist/cli/doctor/format.js.map +1 -1
- package/dist/cli/doctor/index.js +60 -31
- package/dist/cli/doctor/index.js.map +1 -1
- package/dist/cli/doctor/types.d.ts +17 -0
- package/dist/cli/dry-run.js +7 -0
- package/dist/cli/dry-run.js.map +1 -1
- package/dist/cli/index.js +46 -144
- package/dist/cli/index.js.map +1 -1
- package/dist/cli/pack/auto-approve-path.js +25 -11
- package/dist/cli/pack/auto-approve-path.js.map +1 -1
- package/dist/cli/pack/hook-codex-post-tool-use.js +2 -2
- package/dist/cli/pack/hook-codex-post-tool-use.js.map +1 -1
- package/dist/cli/pack/hook-codex-pre-tool-use.js +32 -5
- package/dist/cli/pack/hook-codex-pre-tool-use.js.map +1 -1
- package/dist/cli/pack/hook-post-merge-gate-record.d.ts +7 -0
- package/dist/cli/pack/hook-post-merge-gate-record.js +39 -2
- package/dist/cli/pack/hook-post-merge-gate-record.js.map +1 -1
- package/dist/cli/pack/hook-post-tool-use.js +2 -2
- package/dist/cli/pack/hook-post-tool-use.js.map +1 -1
- package/dist/cli/pack/hook-pre-tool-use.js +60 -15
- package/dist/cli/pack/hook-pre-tool-use.js.map +1 -1
- package/dist/cli/policy/intercept.js +5 -1
- package/dist/cli/policy/intercept.js.map +1 -1
- package/dist/cli/record/index.d.ts +11 -2
- package/dist/cli/record/index.js +18 -5
- package/dist/cli/record/index.js.map +1 -1
- package/dist/cli/session-start/branch-check.d.ts +3 -29
- package/dist/cli/session-start/branch-check.js +7 -37
- package/dist/cli/session-start/branch-check.js.map +1 -1
- package/dist/cli/session-start/index.d.ts +16 -30
- package/dist/cli/session-start/index.js +72 -26
- package/dist/cli/session-start/index.js.map +1 -1
- package/dist/cli/session-start/shared-options.d.ts +92 -0
- package/dist/cli/session-start/shared-options.js +109 -0
- package/dist/cli/session-start/shared-options.js.map +1 -0
- package/dist/cli/session-start/stale-base-check.d.ts +3 -28
- package/dist/cli/session-start/stale-base-check.js +7 -37
- package/dist/cli/session-start/stale-base-check.js.map +1 -1
- package/dist/cli/session-start/toolchain-parity.d.ts +5 -21
- package/dist/cli/session-start/toolchain-parity.js +6 -38
- package/dist/cli/session-start/toolchain-parity.js.map +1 -1
- package/dist/cli/smoke/index.d.ts +1 -1
- package/dist/cli/smoke/index.js +8 -11
- package/dist/cli/smoke/index.js.map +1 -1
- package/dist/policy-packs/builtin/post-merge-gate-runtime.d.ts +11 -0
- package/dist/policy-packs/builtin/post-merge-gate-runtime.js +11 -0
- package/dist/policy-packs/builtin/post-merge-gate-runtime.js.map +1 -1
- package/dist/policy-packs/builtin/understanding-before-execution/expiry-reason.d.ts +36 -0
- package/dist/policy-packs/builtin/understanding-before-execution/expiry-reason.js +73 -0
- package/dist/policy-packs/builtin/understanding-before-execution/expiry-reason.js.map +1 -0
- package/dist/policy-packs/builtin/understanding-before-execution/index.d.ts +3 -2
- package/dist/policy-packs/builtin/understanding-before-execution/index.js +5 -2
- package/dist/policy-packs/builtin/understanding-before-execution/index.js.map +1 -1
- package/dist/policy-packs/builtin/understanding-before-execution/markers.js +1 -0
- package/dist/policy-packs/builtin/understanding-before-execution/markers.js.map +1 -1
- package/dist/policy-packs/builtin/understanding-before-execution/persisted-reports.d.ts +205 -1
- package/dist/policy-packs/builtin/understanding-before-execution/persisted-reports.js +360 -3
- package/dist/policy-packs/builtin/understanding-before-execution/persisted-reports.js.map +1 -1
- package/dist/policy-packs/builtin/understanding-before-execution/post-tool-use-boundary.d.ts +1 -1
- package/dist/policy-packs/builtin/understanding-before-execution/post-tool-use-boundary.js +2 -2
- package/dist/policy-packs/builtin/understanding-before-execution/post-tool-use-boundary.js.map +1 -1
- package/dist/policy-packs/builtin/understanding-before-execution/task-markers.d.ts +36 -0
- package/dist/policy-packs/builtin/understanding-before-execution/task-markers.js +50 -0
- package/dist/policy-packs/builtin/understanding-before-execution/task-markers.js.map +1 -1
- package/dist/runtime/bash-prefix-parse.js +319 -126
- package/dist/runtime/bash-prefix-parse.js.map +1 -1
- package/dist/runtime/intercept.d.ts +38 -0
- package/dist/runtime/intercept.js +224 -5
- package/dist/runtime/intercept.js.map +1 -1
- package/dist/runtime/read-only-bash.js +11 -1
- package/dist/runtime/read-only-bash.js.map +1 -1
- package/dist/runtime/shell-word.d.ts +16 -1
- package/dist/runtime/shell-word.js +82 -1
- package/dist/runtime/shell-word.js.map +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"markers.js","sourceRoot":"","sources":["../../../../src/policy-packs/builtin/understanding-before-execution/markers.ts"],"names":[],"mappings":"AAAA,yEAAyE;AACzE,6EAA6E;AAC7E,sEAAsE;AACtE,iDAAiD;AACjD,uEAAuE;AACvE,kCAAkC;AAElC,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAC9B,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAClC,OAAO,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAC9D,OAAO,EAAE,+BAA+B,EAAE,MAAM,kCAAkC,CAAC;AACnF,OAAO,EAAE,UAAU,EAAE,qBAAqB,EAAE,MAAM,sCAAsC,CAAC;AACzF,OAAO,EAAE,wBAAwB,EAAE,MAAM,iDAAiD,CAAC;AAC3F,OAAO,EAAE,aAAa,EAAE,MAAM,gCAAgC,CAAC;AAC/D,OAAO,EAAE,eAAe,EAAE,MAAM,mBAA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C,IAAI,CAAC,GAAG,IAAI,IAAI,IAAI,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC;YACjD,MAAM,KAAK,GAAG,KAAK,GAAG,YAAY,CAAC;YACnC,IAAI,KAAK,GAAG,IAAI,CAAC,QAAQ,EAAE,CAAC;gBAC1B,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,GAAG,MAAM,CAAC,CAAC;gBAC1C,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,QAAQ,GAAG,MAAM,CAAC,CAAC;gBAClD,OAAO;oBACL,OAAO,EAAE,KAAK;oBACd,MAAM,EAAE,mBAAmB,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,iBAAiB,MAAM,WAAW,MAAM,kBAAkB,UAAU,GAAG;oBACzH,MAAM;oBACN,OAAO,EAAE,IAAI;oBACb,MAAM,EAAE,KAAK;iBACd,CAAC;YACJ,CAAC;QACH,CAAC;IACH,CAAC;IACD,OAAO;QACL,OAAO,EAAE,IAAI;QACb,MAAM,EAAE,uBAAuB,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,iBAAiB,UAAU,OAAO,UAAU,sBAAsB;QACxH,MAAM;QACN,OAAO,EAAE,KAAK;QACd,MAAM,EAAE,KAAK;KACd,CAAC;AACJ,CAAC;AAED,mFAAmF;AACnF,MAAM,UAAU,mBAAmB,CAAC,YAAoB,EAAE,SAAiB;IACzE,IAAI,CAAC;QACH,EAAE,CAAC,MAAM,CAAC,qBAAqB,CAAC,YAAY,EAAE,SAAS,CAAC,CAAC,CAAC;IAC5D,CAAC;IAAC,MAAM,CAAC;QACP,kBAAkB;IACpB,CAAC;AACH,CAAC"}
|
|
1
|
+
{"version":3,"file":"markers.js","sourceRoot":"","sources":["../../../../src/policy-packs/builtin/understanding-before-execution/markers.ts"],"names":[],"mappings":"AAAA,yEAAyE;AACzE,6EAA6E;AAC7E,sEAAsE;AACtE,iDAAiD;AACjD,uEAAuE;AACvE,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AAC;AACJ,CAAC;AAED,mFAAmF;AACnF,MAAM,UAAU,mBAAmB,CAAC,YAAoB,EAAE,SAAiB;IACzE,IAAI,CAAC;QACH,EAAE,CAAC,MAAM,CAAC,qBAAqB,CAAC,YAAY,EAAE,SAAS,CAAC,CAAC,CAAC;IAC5D,CAAC;IAAC,MAAM,CAAC;QACP,kBAAkB;IACpB,CAAC;AACH,CAAC"}
|
|
@@ -3,6 +3,15 @@ export interface PersistedReport {
|
|
|
3
3
|
sessionId: string | null;
|
|
4
4
|
approvalStatus: string | null;
|
|
5
5
|
approvedAt: string | null;
|
|
6
|
+
/**
|
|
7
|
+
* Event a PostToolUse boundary expired this report for
|
|
8
|
+
* (`tool:<tool_name>` or `bash:/<regex>/`), stamped by
|
|
9
|
+
* `expirePersistedReport`; null for a report without the field (older
|
|
10
|
+
* reports, package producers, or a TTL-only lapse).
|
|
11
|
+
*/
|
|
12
|
+
expiredBy: string | null;
|
|
13
|
+
/** ISO timestamp `expirePersistedReport` stamped; null when absent. */
|
|
14
|
+
expiredAt: string | null;
|
|
6
15
|
/**
|
|
7
16
|
* ISO timestamp the producer stamped when it wrote the report; null
|
|
8
17
|
* for legacy reports without the field.
|
|
@@ -165,6 +174,18 @@ export declare function selectNewestStrictSessionReport(reports: PersistedReport
|
|
|
165
174
|
* only need the report (the gate read and expiry paths).
|
|
166
175
|
*/
|
|
167
176
|
export declare function findLatestReportForSession(reports: PersistedReport[], sessionId: string, opts?: FindReportOptions): PersistedReport | null;
|
|
177
|
+
/**
|
|
178
|
+
* `detail` is not an inert log line: both PreToolUse hooks embed it
|
|
179
|
+
* verbatim into their block `reason`, and the Codex hook additionally
|
|
180
|
+
* writes it to stderr, the block-reason surface an operator reads
|
|
181
|
+
* directly. The report file's basename and its `approvedAt` field both
|
|
182
|
+
* come from a JSON file whose content the gated agent controls (it is
|
|
183
|
+
* only unsigned evidence, task 7402301d), so neither is trusted
|
|
184
|
+
* verbatim here: control characters (including newlines, which could
|
|
185
|
+
* forge extra `reason:`-looking lines) are replaced with a space and
|
|
186
|
+
* the result is capped so one field cannot blow out the surface.
|
|
187
|
+
*/
|
|
188
|
+
export declare function sanitizeDetailValue(value: string): string;
|
|
168
189
|
/**
|
|
169
190
|
* What the gate learns from the persisted report: EVIDENCE, never
|
|
170
191
|
* authority (task 7402301d). Until that task the report was the second
|
|
@@ -209,7 +230,7 @@ export interface PersistedReportEvidence {
|
|
|
209
230
|
* best-effort cleanup so a missing report dir or unrelated I/O issue
|
|
210
231
|
* does not escalate into a session-breaking hook failure.
|
|
211
232
|
*/
|
|
212
|
-
export declare function expirePersistedReport(reportsDir: string, sessionId: string, now?: Date): {
|
|
233
|
+
export declare function expirePersistedReport(reportsDir: string, sessionId: string, now?: Date, trigger?: string): {
|
|
213
234
|
ok: true;
|
|
214
235
|
filePath: string;
|
|
215
236
|
previousStatus: string | null;
|
|
@@ -235,3 +256,186 @@ export declare function expirePersistedReport(reportsDir: string, sessionId: str
|
|
|
235
256
|
* `understanding-gate approve` CLI, which writes no signed marker).
|
|
236
257
|
*/
|
|
237
258
|
export declare function checkPersistedReport(reportsDir: string, sessionId: string): PersistedReportEvidence;
|
|
259
|
+
/**
|
|
260
|
+
* `approval expired because <event> at <time>` for a report a PostToolUse
|
|
261
|
+
* boundary expired (`expirePersistedReport` stamps `expiredBy` and
|
|
262
|
+
* `expiredAt`), `undefined` for any other report, including an older one or
|
|
263
|
+
* one a package producer wrote that carries no `expiredBy`. Both values come
|
|
264
|
+
* from a JSON file the gated agent can write, so both pass
|
|
265
|
+
* `sanitizeDetailValue`.
|
|
266
|
+
*/
|
|
267
|
+
export declare function describeBoundaryExpiry(report: Pick<PersistedReport, "approvalStatus" | "expiredBy" | "expiredAt">): string | undefined;
|
|
268
|
+
/**
|
|
269
|
+
* Largest report file, in bytes, the canonical hash reads from disk (1 MiB).
|
|
270
|
+
* Every `*.json` entry of the reports directory reaches the hash through the
|
|
271
|
+
* gate-read scan, and the agent can write that directory, so without a bound
|
|
272
|
+
* a planted file of a few hundred megabytes made the hook run out of heap or
|
|
273
|
+
* past its time budget instead of deciding (a hook that dies or overruns is a
|
|
274
|
+
* non-blocking error for the runtime). A real report is a few kilobytes, far
|
|
275
|
+
* below the cap. A file over the cap matches nothing at gate read, and both
|
|
276
|
+
* producers refuse to approve such a report.
|
|
277
|
+
*/
|
|
278
|
+
export declare const MAX_HASHED_REPORT_BYTES: number;
|
|
279
|
+
/** Result of {@link walkContainerDepth}. */
|
|
280
|
+
export interface ContainerDepthWalk {
|
|
281
|
+
/** True when some array/object nests deeper than the walk's `max` levels. */
|
|
282
|
+
tooDeep: boolean;
|
|
283
|
+
/** Values the walk took off its stack: the root plus every array/object below it. */
|
|
284
|
+
visited: number;
|
|
285
|
+
}
|
|
286
|
+
/**
|
|
287
|
+
* Iterative walk over the arrays and objects of `value` (the value itself is
|
|
288
|
+
* level 1) that stops at the first one nested deeper than `max` levels.
|
|
289
|
+
* Iterative, so the walk itself cannot overflow the stack. Only arrays and
|
|
290
|
+
* objects are pushed: a scalar child (string, number, boolean, null) cannot
|
|
291
|
+
* nest, so a wide array of scalars costs no stack slot per element, and
|
|
292
|
+
* `visited` counts the root plus the containers below it. Exported for tests.
|
|
293
|
+
*/
|
|
294
|
+
export declare function walkContainerDepth(value: unknown, max: number): ContainerDepthWalk;
|
|
295
|
+
/**
|
|
296
|
+
* The hash an approval marker signs as its `reportContentHash`, and the one
|
|
297
|
+
* the gate recomputes at read time (task fa423e9b): sha256 over a key-sorted
|
|
298
|
+
* JSON serialisation of the parsed report with the lifecycle fields in
|
|
299
|
+
* `LIFECYCLE_REPORT_FIELDS` removed. A raw-bytes hash cannot do this job: the
|
|
300
|
+
* producers hash before `rewriteReportApproved` re-serialises the file and
|
|
301
|
+
* `expirePersistedReport` rewrites it again, so the raw bytes of an untouched
|
|
302
|
+
* report never match what the marker signed. One function on purpose, shared
|
|
303
|
+
* by both producers (`harness approve understanding`, the auto-approval path)
|
|
304
|
+
* and the verifier.
|
|
305
|
+
*
|
|
306
|
+
* Total: returns null instead of throwing for a report nested deeper than
|
|
307
|
+
* `MAX_CANONICAL_REPORT_DEPTH`. The verifier counts such a file as one that
|
|
308
|
+
* matches nothing; both producers refuse to approve such a report, so no
|
|
309
|
+
* marker is ever signed without a content binding because of it. Report
|
|
310
|
+
* files reach it only after {@link readReportFileBounded} bounded their type
|
|
311
|
+
* and size (the gate-read scan and `harness approve understanding` through
|
|
312
|
+
* {@link hashReportFile}, the auto-approval path directly).
|
|
313
|
+
*/
|
|
314
|
+
export declare function canonicalReportHash(report: Record<string, unknown>): string | null;
|
|
315
|
+
/** Why {@link readReportFileBounded} returned no content. */
|
|
316
|
+
export type ReportFileReadFailure = "unreadable" | "not-regular" | "too-large" | "grew";
|
|
317
|
+
export type BoundedReportRead = {
|
|
318
|
+
ok: true;
|
|
319
|
+
raw: string;
|
|
320
|
+
} | {
|
|
321
|
+
ok: false;
|
|
322
|
+
reason: ReportFileReadFailure;
|
|
323
|
+
detail: string;
|
|
324
|
+
};
|
|
325
|
+
/**
|
|
326
|
+
* Read a report file for hashing, bounded by type and size. This is the one
|
|
327
|
+
* read every canonical report hash goes through: the gate-read scan (via
|
|
328
|
+
* {@link hashReportFile}) and both producers. The path is opened once,
|
|
329
|
+
* read-only and non-blocking (`O_NONBLOCK`: opening a FIFO with no writer
|
|
330
|
+
* returns at once instead of waiting for one); its type and size come from
|
|
331
|
+
* `fstat` on that descriptor, and the content is read through the same
|
|
332
|
+
* descriptor, so nothing can be swapped in between (no separate stat of the
|
|
333
|
+
* path, which a symlink flipped to a FIFO used to race). Refused without
|
|
334
|
+
* reading: anything that is not a regular file, and a file larger than
|
|
335
|
+
* `MAX_HASHED_REPORT_BYTES`. The read stops one byte past the fstat size
|
|
336
|
+
* (never more than the cap plus one byte); a file that grows into that byte
|
|
337
|
+
* while being read is refused too. The descriptor is always closed. Never
|
|
338
|
+
* throws.
|
|
339
|
+
*/
|
|
340
|
+
export declare function readReportFileBounded(filePath: string): BoundedReportRead;
|
|
341
|
+
/** Why a report file has no canonical hash. */
|
|
342
|
+
export type UnhashableReportReason = ReportFileReadFailure | "not-json-object" | "too-deep";
|
|
343
|
+
export type ReportFileHash = {
|
|
344
|
+
ok: true;
|
|
345
|
+
hash: string;
|
|
346
|
+
} | {
|
|
347
|
+
ok: false;
|
|
348
|
+
reason: UnhashableReportReason;
|
|
349
|
+
detail: string;
|
|
350
|
+
};
|
|
351
|
+
/**
|
|
352
|
+
* Canonical hash of the report file at `filePath`, read through
|
|
353
|
+
* {@link readReportFileBounded}, or why it has none: not a regular file, over
|
|
354
|
+
* `MAX_HASHED_REPORT_BYTES`, unreadable, grown while read, not a JSON object,
|
|
355
|
+
* or nested too deeply. `harness approve understanding` refuses a report on
|
|
356
|
+
* any of these (the `detail` is its message); the gate-read scan counts such
|
|
357
|
+
* a file as one that matches nothing. Never throws.
|
|
358
|
+
*/
|
|
359
|
+
export declare function hashReportFile(filePath: string): ReportFileHash;
|
|
360
|
+
/** Canonical hash of the report file at `filePath` ({@link hashReportFile}); null when it has none. */
|
|
361
|
+
export declare function canonicalReportHashOfFile(filePath: string): string | null;
|
|
362
|
+
/** Marker kind whose signed report hash the gate checks. */
|
|
363
|
+
export type ApprovalMarkerKind = "task" | "session";
|
|
364
|
+
/** One matched marker's signed `reportContentHash`, tagged with its kind. */
|
|
365
|
+
export interface MarkerReportBinding {
|
|
366
|
+
kind: ApprovalMarkerKind;
|
|
367
|
+
reportContentHash: string | null;
|
|
368
|
+
}
|
|
369
|
+
export type ApprovedReportHashVerification = {
|
|
370
|
+
ok: true;
|
|
371
|
+
kind: ApprovalMarkerKind;
|
|
372
|
+
} | {
|
|
373
|
+
ok: false;
|
|
374
|
+
detail: string;
|
|
375
|
+
};
|
|
376
|
+
/**
|
|
377
|
+
* Gate-read cross-check of a matched approval marker against the persisted
|
|
378
|
+
* reports (task fa423e9b). Both PreToolUse hooks call it after
|
|
379
|
+
* `checkOperatorApprovalMarkers` matched, through `verifyMatchedMarkerReport`.
|
|
380
|
+
*
|
|
381
|
+
* Rule: a marker with a non-null signed `reportContentHash` is valid iff at
|
|
382
|
+
* least one parseable report file in `reportsDir` (any session, any
|
|
383
|
+
* `approvalStatus`) has a canonical hash equal to it. The hash already
|
|
384
|
+
* leaves the lifecycle fields out, so approving, expiring or re-approving
|
|
385
|
+
* the report never changes it. The signed hash therefore proves one thing:
|
|
386
|
+
* the content the operator approved is still on disk unmodified. Editing
|
|
387
|
+
* that file (in place, by swap, by symlink, by an unparseable rewrite)
|
|
388
|
+
* removes the only match and the marker stops opening the gate. Comparing
|
|
389
|
+
* against the session's newest approved report instead would deny
|
|
390
|
+
* legitimate approvals (a newer report approved for the same claim, two
|
|
391
|
+
* sessions on one claim) and would let a swap pass by moving the swapped
|
|
392
|
+
* report out of the selection.
|
|
393
|
+
*
|
|
394
|
+
* Bounded input: only a regular file of at most `MAX_HASHED_REPORT_BYTES`
|
|
395
|
+
* (1 MiB) that parses as a JSON object nested at most 64 levels deep has a
|
|
396
|
+
* canonical hash, read through {@link readReportFileBounded} (opened
|
|
397
|
+
* non-blocking, typed and sized by `fstat` on the open descriptor, read
|
|
398
|
+
* through it). Every other `*.json` entry (a FIFO, a directory, a device, a
|
|
399
|
+
* symlink to one of them, a file over the cap, an unreadable, unparseable or
|
|
400
|
+
* too deeply nested file) still counts as a report file but matches nothing,
|
|
401
|
+
* so it can neither open the gate nor make the scan block, run out of
|
|
402
|
+
* memory or die instead of deciding.
|
|
403
|
+
*
|
|
404
|
+
* Residuals: (1) the check proves only that some file carries the approved
|
|
405
|
+
* content. Any regular `*.json` file within the size cap whose content
|
|
406
|
+
* equals it keeps a match, whether it was kept before the edit (a copy) or
|
|
407
|
+
* re-created after it (the agent wrote that content, so it can write it
|
|
408
|
+
* again), and the marker still opens the gate. (2) A reports directory that
|
|
409
|
+
* is empty, unreadable or holds no `*.json` entry at all (every report
|
|
410
|
+
* deleted, the directory made unreadable, the reports renamed) falls back to
|
|
411
|
+
* the "no report file" allow, the same as before this check existed. The
|
|
412
|
+
* marker and the operator's approval itself are untouched in both cases;
|
|
413
|
+
* only the audit trail loses its claim to be the approved content. (3) The
|
|
414
|
+
* cap bounds each file, not their number: the scan time grows with the
|
|
415
|
+
* total volume of report files, so an agent that plants hundreds of
|
|
416
|
+
* megabytes of files just under the cap can still push one scan past the
|
|
417
|
+
* hook's time budget, which the runtime treats as a non-blocking error (the
|
|
418
|
+
* same allow as before this check existed).
|
|
419
|
+
*
|
|
420
|
+
* Removing the approved report while other report files remain is a deny:
|
|
421
|
+
* nothing on disk carries the signed content any more. `harness gc --apply`
|
|
422
|
+
* can do that legitimately: it ages approved reports out by their createdAt
|
|
423
|
+
* but markers by their file mtime, so a report written long before its
|
|
424
|
+
* approval can go while the marker stays. Re-approving recovers.
|
|
425
|
+
*
|
|
426
|
+
* `primary` is the marker that satisfied the gate (task-scoped first),
|
|
427
|
+
* `fallback` a session marker that matched behind a task marker. The
|
|
428
|
+
* fallback is consulted only when the primary fails the check, so a task
|
|
429
|
+
* marker signed for another report does not hide a session marker that
|
|
430
|
+
* verifies. Unchanged behaviour: a null hash on the accepted marker (no
|
|
431
|
+
* report resolved, or `--force` over a report the producer could not hash:
|
|
432
|
+
* too deeply nested or over the size cap) and a reports directory with no
|
|
433
|
+
* `*.json` entry at all both allow. A forced approval of a hashable report
|
|
434
|
+
* signs its hash and is checked like any other.
|
|
435
|
+
*
|
|
436
|
+
* The `detail` is the block reason. It names the failing marker kind and the
|
|
437
|
+
* one-command fix, which is also the single migration step for a marker
|
|
438
|
+
* written before the canonical hash existed. It carries no report-derived
|
|
439
|
+
* value, so nothing in it needs sanitising.
|
|
440
|
+
*/
|
|
441
|
+
export declare function verifyApprovedReportHash(reportsDir: string, primary: MarkerReportBinding, fallback?: MarkerReportBinding | null): ApprovedReportHashVerification;
|
|
@@ -14,6 +14,7 @@ import * as fs from "node:fs";
|
|
|
14
14
|
import * as path from "node:path";
|
|
15
15
|
import { atomicWriteFile } from "../../../io/atomic-write.js";
|
|
16
16
|
import { safeJsonParse } from "../../../io/safe-json-parse.js";
|
|
17
|
+
import { sha256Hex } from "../../../runtime/approval-signing.js";
|
|
17
18
|
const DEFAULT_REPORTS_DIRNAME = ".understanding-gate";
|
|
18
19
|
const REPORTS_SUBDIR = "reports";
|
|
19
20
|
/**
|
|
@@ -86,6 +87,8 @@ function readPersistedReport(filePath, mtimeMs) {
|
|
|
86
87
|
sessionId: typeof obj["sessionId"] === "string" ? obj["sessionId"] : null,
|
|
87
88
|
approvalStatus: typeof obj["approvalStatus"] === "string" ? obj["approvalStatus"] : null,
|
|
88
89
|
approvedAt: typeof obj["approvedAt"] === "string" ? obj["approvedAt"] : null,
|
|
90
|
+
expiredBy: typeof obj["expiredBy"] === "string" ? obj["expiredBy"] : null,
|
|
91
|
+
expiredAt: typeof obj["expiredAt"] === "string" ? obj["expiredAt"] : null,
|
|
89
92
|
createdAt,
|
|
90
93
|
createdAtMs,
|
|
91
94
|
};
|
|
@@ -265,7 +268,7 @@ const DETAIL_VALUE_MAX_LENGTH = 120;
|
|
|
265
268
|
* forge extra `reason:`-looking lines) are replaced with a space and
|
|
266
269
|
* the result is capped so one field cannot blow out the surface.
|
|
267
270
|
*/
|
|
268
|
-
function sanitizeDetailValue(value) {
|
|
271
|
+
export function sanitizeDetailValue(value) {
|
|
269
272
|
// Deliberately strips C0/DEL control characters (including newline,
|
|
270
273
|
// which could otherwise forge an extra `reason:`-looking stderr line).
|
|
271
274
|
const flattened = value.replace(/[\x00-\x1f\x7f]/g, " ");
|
|
@@ -292,7 +295,7 @@ function sanitizeDetailValue(value) {
|
|
|
292
295
|
* best-effort cleanup so a missing report dir or unrelated I/O issue
|
|
293
296
|
* does not escalate into a session-breaking hook failure.
|
|
294
297
|
*/
|
|
295
|
-
export function expirePersistedReport(reportsDir, sessionId, now = new Date()) {
|
|
298
|
+
export function expirePersistedReport(reportsDir, sessionId, now = new Date(), trigger) {
|
|
296
299
|
const reports = listPersistedReports(reportsDir);
|
|
297
300
|
if (reports.length === 0) {
|
|
298
301
|
return { ok: false, reason: `no reports under ${reportsDir}` };
|
|
@@ -327,6 +330,13 @@ export function expirePersistedReport(reportsDir, sessionId, now = new Date()) {
|
|
|
327
330
|
const previousStatus = typeof parsed["approvalStatus"] === "string" ? parsed["approvalStatus"] : null;
|
|
328
331
|
parsed["approvalStatus"] = "expired";
|
|
329
332
|
parsed["expiredAt"] = now.toISOString();
|
|
333
|
+
if (trigger !== undefined && trigger !== "") {
|
|
334
|
+
parsed["expiredBy"] = trigger;
|
|
335
|
+
}
|
|
336
|
+
else {
|
|
337
|
+
// No event to record: drop a stale one from an earlier expiry.
|
|
338
|
+
delete parsed["expiredBy"];
|
|
339
|
+
}
|
|
330
340
|
try {
|
|
331
341
|
atomicWriteFile(latest.filePath, `${JSON.stringify(parsed, null, 2)}\n`);
|
|
332
342
|
}
|
|
@@ -374,9 +384,11 @@ export function checkPersistedReport(reportsDir, sessionId) {
|
|
|
374
384
|
}
|
|
375
385
|
const safeFileName = sanitizeDetailValue(path.basename(latest.filePath));
|
|
376
386
|
if (latest.approvalStatus !== "approved") {
|
|
387
|
+
const boundaryExpiry = describeBoundaryExpiry(latest);
|
|
388
|
+
const expirySuffix = boundaryExpiry !== undefined ? `; ${boundaryExpiry}` : "";
|
|
377
389
|
return {
|
|
378
390
|
claimsApproved: false,
|
|
379
|
-
detail: `latest report ${safeFileName} has approvalStatus=${sanitizeDetailValue(latest.approvalStatus ?? "<missing>")}`,
|
|
391
|
+
detail: `latest report ${safeFileName} has approvalStatus=${sanitizeDetailValue(latest.approvalStatus ?? "<missing>")}${expirySuffix}`,
|
|
380
392
|
report: latest,
|
|
381
393
|
};
|
|
382
394
|
}
|
|
@@ -390,4 +402,349 @@ export function checkPersistedReport(reportsDir, sessionId) {
|
|
|
390
402
|
report: latest,
|
|
391
403
|
};
|
|
392
404
|
}
|
|
405
|
+
/**
|
|
406
|
+
* `approval expired because <event> at <time>` for a report a PostToolUse
|
|
407
|
+
* boundary expired (`expirePersistedReport` stamps `expiredBy` and
|
|
408
|
+
* `expiredAt`), `undefined` for any other report, including an older one or
|
|
409
|
+
* one a package producer wrote that carries no `expiredBy`. Both values come
|
|
410
|
+
* from a JSON file the gated agent can write, so both pass
|
|
411
|
+
* `sanitizeDetailValue`.
|
|
412
|
+
*/
|
|
413
|
+
export function describeBoundaryExpiry(report) {
|
|
414
|
+
if (report.approvalStatus !== "expired")
|
|
415
|
+
return undefined;
|
|
416
|
+
if (report.expiredBy === null || report.expiredBy === "")
|
|
417
|
+
return undefined;
|
|
418
|
+
const when = report.expiredAt !== null && report.expiredAt !== ""
|
|
419
|
+
? ` at ${sanitizeDetailValue(report.expiredAt)}`
|
|
420
|
+
: "";
|
|
421
|
+
return `approval expired because ${sanitizeDetailValue(report.expiredBy)}${when}`;
|
|
422
|
+
}
|
|
423
|
+
/**
|
|
424
|
+
* Report fields the approval and expiry lifecycles rewrite. They are left
|
|
425
|
+
* out of {@link canonicalReportHash}: `rewriteReportApproved` flips
|
|
426
|
+
* `approvalStatus`/`approvedAt`/`approvedBy`, may stamp `sessionId`, and
|
|
427
|
+
* drops `expiredAt`/`expiredBy`; `expirePersistedReport` later sets
|
|
428
|
+
* `approvalStatus`/`expiredAt`/`expiredBy` again. The hash must survive all
|
|
429
|
+
* of that for an untouched report, so it covers only the content the
|
|
430
|
+
* operator actually reviewed.
|
|
431
|
+
*/
|
|
432
|
+
const LIFECYCLE_REPORT_FIELDS = new Set([
|
|
433
|
+
"approvalStatus",
|
|
434
|
+
"approvedAt",
|
|
435
|
+
"approvedBy",
|
|
436
|
+
"expiredAt",
|
|
437
|
+
"expiredBy",
|
|
438
|
+
"sessionId",
|
|
439
|
+
]);
|
|
440
|
+
/**
|
|
441
|
+
* Deepest array/object nesting {@link canonicalReportHash} serialises (the
|
|
442
|
+
* report object itself is level 1). `sortKeysDeep` and `JSON.stringify`
|
|
443
|
+
* recurse once per level, and any agent-written `*.json` file in the reports
|
|
444
|
+
* directory reaches them through the gate-read scan, so without a bound a
|
|
445
|
+
* file nested a few thousand levels deep overflows the stack and the hook
|
|
446
|
+
* process dies instead of deciding. A real report nests a handful of levels.
|
|
447
|
+
*/
|
|
448
|
+
const MAX_CANONICAL_REPORT_DEPTH = 64;
|
|
449
|
+
/**
|
|
450
|
+
* Largest report file, in bytes, the canonical hash reads from disk (1 MiB).
|
|
451
|
+
* Every `*.json` entry of the reports directory reaches the hash through the
|
|
452
|
+
* gate-read scan, and the agent can write that directory, so without a bound
|
|
453
|
+
* a planted file of a few hundred megabytes made the hook run out of heap or
|
|
454
|
+
* past its time budget instead of deciding (a hook that dies or overruns is a
|
|
455
|
+
* non-blocking error for the runtime). A real report is a few kilobytes, far
|
|
456
|
+
* below the cap. A file over the cap matches nothing at gate read, and both
|
|
457
|
+
* producers refuse to approve such a report.
|
|
458
|
+
*/
|
|
459
|
+
export const MAX_HASHED_REPORT_BYTES = 1024 * 1024;
|
|
460
|
+
/**
|
|
461
|
+
* Iterative walk over the arrays and objects of `value` (the value itself is
|
|
462
|
+
* level 1) that stops at the first one nested deeper than `max` levels.
|
|
463
|
+
* Iterative, so the walk itself cannot overflow the stack. Only arrays and
|
|
464
|
+
* objects are pushed: a scalar child (string, number, boolean, null) cannot
|
|
465
|
+
* nest, so a wide array of scalars costs no stack slot per element, and
|
|
466
|
+
* `visited` counts the root plus the containers below it. Exported for tests.
|
|
467
|
+
*/
|
|
468
|
+
export function walkContainerDepth(value, max) {
|
|
469
|
+
const nodes = [value];
|
|
470
|
+
const depths = [1];
|
|
471
|
+
let visited = 0;
|
|
472
|
+
while (nodes.length > 0) {
|
|
473
|
+
const node = nodes.pop();
|
|
474
|
+
const depth = depths.pop() ?? 1;
|
|
475
|
+
visited += 1;
|
|
476
|
+
if (node === null || typeof node !== "object")
|
|
477
|
+
continue;
|
|
478
|
+
if (depth > max)
|
|
479
|
+
return { tooDeep: true, visited };
|
|
480
|
+
for (const child of Array.isArray(node) ? node : Object.values(node)) {
|
|
481
|
+
if (child !== null && typeof child === "object") {
|
|
482
|
+
nodes.push(child);
|
|
483
|
+
depths.push(depth + 1);
|
|
484
|
+
}
|
|
485
|
+
}
|
|
486
|
+
}
|
|
487
|
+
return { tooDeep: false, visited };
|
|
488
|
+
}
|
|
489
|
+
/** True when `value` nests arrays/objects deeper than `max` levels. */
|
|
490
|
+
function nestsDeeperThan(value, max) {
|
|
491
|
+
return walkContainerDepth(value, max).tooDeep;
|
|
492
|
+
}
|
|
493
|
+
function sortKeysDeep(value) {
|
|
494
|
+
if (Array.isArray(value))
|
|
495
|
+
return value.map(sortKeysDeep);
|
|
496
|
+
if (value !== null && typeof value === "object") {
|
|
497
|
+
const entries = Object.entries(value)
|
|
498
|
+
.sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0))
|
|
499
|
+
.map(([k, v]) => [k, sortKeysDeep(v)]);
|
|
500
|
+
// `Object.fromEntries` defines own properties, so a report key named
|
|
501
|
+
// `__proto__` stays data instead of re-parenting the copy.
|
|
502
|
+
return Object.fromEntries(entries);
|
|
503
|
+
}
|
|
504
|
+
return value;
|
|
505
|
+
}
|
|
506
|
+
/**
|
|
507
|
+
* The hash an approval marker signs as its `reportContentHash`, and the one
|
|
508
|
+
* the gate recomputes at read time (task fa423e9b): sha256 over a key-sorted
|
|
509
|
+
* JSON serialisation of the parsed report with the lifecycle fields in
|
|
510
|
+
* `LIFECYCLE_REPORT_FIELDS` removed. A raw-bytes hash cannot do this job: the
|
|
511
|
+
* producers hash before `rewriteReportApproved` re-serialises the file and
|
|
512
|
+
* `expirePersistedReport` rewrites it again, so the raw bytes of an untouched
|
|
513
|
+
* report never match what the marker signed. One function on purpose, shared
|
|
514
|
+
* by both producers (`harness approve understanding`, the auto-approval path)
|
|
515
|
+
* and the verifier.
|
|
516
|
+
*
|
|
517
|
+
* Total: returns null instead of throwing for a report nested deeper than
|
|
518
|
+
* `MAX_CANONICAL_REPORT_DEPTH`. The verifier counts such a file as one that
|
|
519
|
+
* matches nothing; both producers refuse to approve such a report, so no
|
|
520
|
+
* marker is ever signed without a content binding because of it. Report
|
|
521
|
+
* files reach it only after {@link readReportFileBounded} bounded their type
|
|
522
|
+
* and size (the gate-read scan and `harness approve understanding` through
|
|
523
|
+
* {@link hashReportFile}, the auto-approval path directly).
|
|
524
|
+
*/
|
|
525
|
+
export function canonicalReportHash(report) {
|
|
526
|
+
// `Object.fromEntries` (not `kept[key] = value`): a report key named
|
|
527
|
+
// `__proto__` must stay hashed data, not re-parent the copy and vanish.
|
|
528
|
+
const kept = Object.fromEntries(Object.entries(report).filter(([key]) => !LIFECYCLE_REPORT_FIELDS.has(key)));
|
|
529
|
+
if (nestsDeeperThan(kept, MAX_CANONICAL_REPORT_DEPTH))
|
|
530
|
+
return null;
|
|
531
|
+
return sha256Hex(JSON.stringify(sortKeysDeep(kept)));
|
|
532
|
+
}
|
|
533
|
+
function errorCode(err) {
|
|
534
|
+
const code = err?.code;
|
|
535
|
+
return typeof code === "string" ? code : String(err);
|
|
536
|
+
}
|
|
537
|
+
/**
|
|
538
|
+
* Read a report file for hashing, bounded by type and size. This is the one
|
|
539
|
+
* read every canonical report hash goes through: the gate-read scan (via
|
|
540
|
+
* {@link hashReportFile}) and both producers. The path is opened once,
|
|
541
|
+
* read-only and non-blocking (`O_NONBLOCK`: opening a FIFO with no writer
|
|
542
|
+
* returns at once instead of waiting for one); its type and size come from
|
|
543
|
+
* `fstat` on that descriptor, and the content is read through the same
|
|
544
|
+
* descriptor, so nothing can be swapped in between (no separate stat of the
|
|
545
|
+
* path, which a symlink flipped to a FIFO used to race). Refused without
|
|
546
|
+
* reading: anything that is not a regular file, and a file larger than
|
|
547
|
+
* `MAX_HASHED_REPORT_BYTES`. The read stops one byte past the fstat size
|
|
548
|
+
* (never more than the cap plus one byte); a file that grows into that byte
|
|
549
|
+
* while being read is refused too. The descriptor is always closed. Never
|
|
550
|
+
* throws.
|
|
551
|
+
*/
|
|
552
|
+
export function readReportFileBounded(filePath) {
|
|
553
|
+
let fd;
|
|
554
|
+
try {
|
|
555
|
+
fd = fs.openSync(filePath, fs.constants.O_RDONLY | fs.constants.O_NONBLOCK);
|
|
556
|
+
}
|
|
557
|
+
catch (err) {
|
|
558
|
+
return { ok: false, reason: "unreadable", detail: `could not be opened (${errorCode(err)})` };
|
|
559
|
+
}
|
|
560
|
+
try {
|
|
561
|
+
const stat = fs.fstatSync(fd);
|
|
562
|
+
if (!stat.isFile())
|
|
563
|
+
return { ok: false, reason: "not-regular", detail: "not a regular file" };
|
|
564
|
+
if (stat.size > MAX_HASHED_REPORT_BYTES) {
|
|
565
|
+
return {
|
|
566
|
+
ok: false,
|
|
567
|
+
reason: "too-large",
|
|
568
|
+
detail: `${stat.size} bytes, over the ${MAX_HASHED_REPORT_BYTES}-byte cap for hashing its content`,
|
|
569
|
+
};
|
|
570
|
+
}
|
|
571
|
+
const buf = Buffer.allocUnsafe(stat.size + 1);
|
|
572
|
+
let total = 0;
|
|
573
|
+
while (total < buf.length) {
|
|
574
|
+
const n = fs.readSync(fd, buf, total, buf.length - total, null);
|
|
575
|
+
if (n === 0)
|
|
576
|
+
break;
|
|
577
|
+
total += n;
|
|
578
|
+
}
|
|
579
|
+
if (total > stat.size)
|
|
580
|
+
return { ok: false, reason: "grew", detail: "grew while being read" };
|
|
581
|
+
return { ok: true, raw: buf.toString("utf8", 0, total) };
|
|
582
|
+
}
|
|
583
|
+
catch (err) {
|
|
584
|
+
return { ok: false, reason: "unreadable", detail: `could not be read (${errorCode(err)})` };
|
|
585
|
+
}
|
|
586
|
+
finally {
|
|
587
|
+
try {
|
|
588
|
+
fs.closeSync(fd);
|
|
589
|
+
}
|
|
590
|
+
catch {
|
|
591
|
+
// Already gone; nothing left to release.
|
|
592
|
+
}
|
|
593
|
+
}
|
|
594
|
+
}
|
|
595
|
+
/**
|
|
596
|
+
* Canonical hash of the report file at `filePath`, read through
|
|
597
|
+
* {@link readReportFileBounded}, or why it has none: not a regular file, over
|
|
598
|
+
* `MAX_HASHED_REPORT_BYTES`, unreadable, grown while read, not a JSON object,
|
|
599
|
+
* or nested too deeply. `harness approve understanding` refuses a report on
|
|
600
|
+
* any of these (the `detail` is its message); the gate-read scan counts such
|
|
601
|
+
* a file as one that matches nothing. Never throws.
|
|
602
|
+
*/
|
|
603
|
+
export function hashReportFile(filePath) {
|
|
604
|
+
const read = readReportFileBounded(filePath);
|
|
605
|
+
if (!read.ok)
|
|
606
|
+
return read;
|
|
607
|
+
const parsed = safeJsonParse(read.raw);
|
|
608
|
+
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
|
|
609
|
+
return { ok: false, reason: "not-json-object", detail: "not a JSON object" };
|
|
610
|
+
}
|
|
611
|
+
const hash = canonicalReportHash(parsed);
|
|
612
|
+
if (hash === null) {
|
|
613
|
+
return { ok: false, reason: "too-deep", detail: "nested too deeply to hash its content" };
|
|
614
|
+
}
|
|
615
|
+
return { ok: true, hash };
|
|
616
|
+
}
|
|
617
|
+
/** Canonical hash of the report file at `filePath` ({@link hashReportFile}); null when it has none. */
|
|
618
|
+
export function canonicalReportHashOfFile(filePath) {
|
|
619
|
+
const hashed = hashReportFile(filePath);
|
|
620
|
+
return hashed.ok ? hashed.hash : null;
|
|
621
|
+
}
|
|
622
|
+
/**
|
|
623
|
+
* Hash every `*.json` entry of `dir` (any session, any `approvalStatus`)
|
|
624
|
+
* through {@link canonicalReportHashOfFile} and report which of the `wanted`
|
|
625
|
+
* hashes occur. Stops as soon as every wanted hash was found. Every entry
|
|
626
|
+
* counts as a report file; one that is not a regular file, is larger than
|
|
627
|
+
* `MAX_HASHED_REPORT_BYTES`, cannot be opened or read, grows while read, is
|
|
628
|
+
* not a JSON object, or nests too deeply matches nothing. The cost is linear
|
|
629
|
+
* in the number and size of the report files (each read at most up to the
|
|
630
|
+
* cap), and the usual allow path scans nearly all of them: the directory
|
|
631
|
+
* listing comes back in name order and report names start with a timestamp,
|
|
632
|
+
* so the approved (newest) report tends to come last.
|
|
633
|
+
*/
|
|
634
|
+
function scanReportHashes(dir, wanted) {
|
|
635
|
+
const scan = { files: 0, matched: new Set() };
|
|
636
|
+
let names;
|
|
637
|
+
try {
|
|
638
|
+
names = fs.readdirSync(dir);
|
|
639
|
+
}
|
|
640
|
+
catch {
|
|
641
|
+
return scan;
|
|
642
|
+
}
|
|
643
|
+
for (const name of names) {
|
|
644
|
+
if (!name.endsWith(".json"))
|
|
645
|
+
continue;
|
|
646
|
+
const full = path.join(dir, name);
|
|
647
|
+
scan.files += 1;
|
|
648
|
+
const hash = canonicalReportHashOfFile(full);
|
|
649
|
+
if (hash !== null && wanted.has(hash)) {
|
|
650
|
+
scan.matched.add(hash);
|
|
651
|
+
if (scan.matched.size === wanted.size)
|
|
652
|
+
break;
|
|
653
|
+
}
|
|
654
|
+
}
|
|
655
|
+
return scan;
|
|
656
|
+
}
|
|
657
|
+
/**
|
|
658
|
+
* Gate-read cross-check of a matched approval marker against the persisted
|
|
659
|
+
* reports (task fa423e9b). Both PreToolUse hooks call it after
|
|
660
|
+
* `checkOperatorApprovalMarkers` matched, through `verifyMatchedMarkerReport`.
|
|
661
|
+
*
|
|
662
|
+
* Rule: a marker with a non-null signed `reportContentHash` is valid iff at
|
|
663
|
+
* least one parseable report file in `reportsDir` (any session, any
|
|
664
|
+
* `approvalStatus`) has a canonical hash equal to it. The hash already
|
|
665
|
+
* leaves the lifecycle fields out, so approving, expiring or re-approving
|
|
666
|
+
* the report never changes it. The signed hash therefore proves one thing:
|
|
667
|
+
* the content the operator approved is still on disk unmodified. Editing
|
|
668
|
+
* that file (in place, by swap, by symlink, by an unparseable rewrite)
|
|
669
|
+
* removes the only match and the marker stops opening the gate. Comparing
|
|
670
|
+
* against the session's newest approved report instead would deny
|
|
671
|
+
* legitimate approvals (a newer report approved for the same claim, two
|
|
672
|
+
* sessions on one claim) and would let a swap pass by moving the swapped
|
|
673
|
+
* report out of the selection.
|
|
674
|
+
*
|
|
675
|
+
* Bounded input: only a regular file of at most `MAX_HASHED_REPORT_BYTES`
|
|
676
|
+
* (1 MiB) that parses as a JSON object nested at most 64 levels deep has a
|
|
677
|
+
* canonical hash, read through {@link readReportFileBounded} (opened
|
|
678
|
+
* non-blocking, typed and sized by `fstat` on the open descriptor, read
|
|
679
|
+
* through it). Every other `*.json` entry (a FIFO, a directory, a device, a
|
|
680
|
+
* symlink to one of them, a file over the cap, an unreadable, unparseable or
|
|
681
|
+
* too deeply nested file) still counts as a report file but matches nothing,
|
|
682
|
+
* so it can neither open the gate nor make the scan block, run out of
|
|
683
|
+
* memory or die instead of deciding.
|
|
684
|
+
*
|
|
685
|
+
* Residuals: (1) the check proves only that some file carries the approved
|
|
686
|
+
* content. Any regular `*.json` file within the size cap whose content
|
|
687
|
+
* equals it keeps a match, whether it was kept before the edit (a copy) or
|
|
688
|
+
* re-created after it (the agent wrote that content, so it can write it
|
|
689
|
+
* again), and the marker still opens the gate. (2) A reports directory that
|
|
690
|
+
* is empty, unreadable or holds no `*.json` entry at all (every report
|
|
691
|
+
* deleted, the directory made unreadable, the reports renamed) falls back to
|
|
692
|
+
* the "no report file" allow, the same as before this check existed. The
|
|
693
|
+
* marker and the operator's approval itself are untouched in both cases;
|
|
694
|
+
* only the audit trail loses its claim to be the approved content. (3) The
|
|
695
|
+
* cap bounds each file, not their number: the scan time grows with the
|
|
696
|
+
* total volume of report files, so an agent that plants hundreds of
|
|
697
|
+
* megabytes of files just under the cap can still push one scan past the
|
|
698
|
+
* hook's time budget, which the runtime treats as a non-blocking error (the
|
|
699
|
+
* same allow as before this check existed).
|
|
700
|
+
*
|
|
701
|
+
* Removing the approved report while other report files remain is a deny:
|
|
702
|
+
* nothing on disk carries the signed content any more. `harness gc --apply`
|
|
703
|
+
* can do that legitimately: it ages approved reports out by their createdAt
|
|
704
|
+
* but markers by their file mtime, so a report written long before its
|
|
705
|
+
* approval can go while the marker stays. Re-approving recovers.
|
|
706
|
+
*
|
|
707
|
+
* `primary` is the marker that satisfied the gate (task-scoped first),
|
|
708
|
+
* `fallback` a session marker that matched behind a task marker. The
|
|
709
|
+
* fallback is consulted only when the primary fails the check, so a task
|
|
710
|
+
* marker signed for another report does not hide a session marker that
|
|
711
|
+
* verifies. Unchanged behaviour: a null hash on the accepted marker (no
|
|
712
|
+
* report resolved, or `--force` over a report the producer could not hash:
|
|
713
|
+
* too deeply nested or over the size cap) and a reports directory with no
|
|
714
|
+
* `*.json` entry at all both allow. A forced approval of a hashable report
|
|
715
|
+
* signs its hash and is checked like any other.
|
|
716
|
+
*
|
|
717
|
+
* The `detail` is the block reason. It names the failing marker kind and the
|
|
718
|
+
* one-command fix, which is also the single migration step for a marker
|
|
719
|
+
* written before the canonical hash existed. It carries no report-derived
|
|
720
|
+
* value, so nothing in it needs sanitising.
|
|
721
|
+
*/
|
|
722
|
+
export function verifyApprovedReportHash(reportsDir, primary, fallback = null) {
|
|
723
|
+
if (primary.reportContentHash === null)
|
|
724
|
+
return { ok: true, kind: primary.kind };
|
|
725
|
+
if (fallback !== null && fallback.reportContentHash === null) {
|
|
726
|
+
return { ok: true, kind: fallback.kind };
|
|
727
|
+
}
|
|
728
|
+
const wanted = new Set([primary.reportContentHash]);
|
|
729
|
+
if (fallback !== null && fallback.reportContentHash !== null) {
|
|
730
|
+
wanted.add(fallback.reportContentHash);
|
|
731
|
+
}
|
|
732
|
+
const scan = scanReportHashes(reportsDir, wanted);
|
|
733
|
+
if (scan.files === 0 || scan.matched.has(primary.reportContentHash)) {
|
|
734
|
+
return { ok: true, kind: primary.kind };
|
|
735
|
+
}
|
|
736
|
+
if (fallback !== null &&
|
|
737
|
+
fallback.reportContentHash !== null &&
|
|
738
|
+
scan.matched.has(fallback.reportContentHash)) {
|
|
739
|
+
return { ok: true, kind: fallback.kind };
|
|
740
|
+
}
|
|
741
|
+
const kinds = fallback !== null
|
|
742
|
+
? `${primary.kind} and ${fallback.kind} approval markers were`
|
|
743
|
+
: `${primary.kind} approval marker was`;
|
|
744
|
+
return {
|
|
745
|
+
ok: false,
|
|
746
|
+
detail: `no report in the reports directory matches the content the ${kinds} signed for ` +
|
|
747
|
+
`(the approved report was changed or removed after approval); re-run \`harness approve understanding\``,
|
|
748
|
+
};
|
|
749
|
+
}
|
|
393
750
|
//# sourceMappingURL=persisted-reports.js.map
|