@codyswann/lisa 8.2.5 → 8.2.6

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 (93) hide show
  1. package/all/copy-overwrite/scripts/check-threshold-ratchet.mjs +280 -46
  2. package/all/copy-overwrite/scripts/npm-updater-helper-graph.json +3 -3
  3. package/all/copy-overwrite/scripts/threshold-ratchet-compare.mjs +433 -21
  4. package/all/copy-overwrite/scripts/threshold-ratchet-families.mjs +77 -4
  5. package/dist/core/lisa-owned-hash-ledger.json +56 -2
  6. package/dist/core/nightly-e2e-guard-behavior-certificate.js +2 -2
  7. package/dist/core/upstream-evidence-manifest.json +21 -14
  8. package/package.json +4 -4
  9. package/plugins/lisa/.claude-plugin/plugin.json +1 -1
  10. package/plugins/lisa/.codex-plugin/plugin.json +1 -1
  11. package/plugins/lisa/hooks/threshold-ratchet-compare.mjs +433 -21
  12. package/plugins/lisa/hooks/threshold-ratchet-families.mjs +77 -4
  13. package/plugins/lisa/hooks/threshold-ratchet.mjs +280 -46
  14. package/plugins/lisa-agy/plugin.json +1 -1
  15. package/plugins/lisa-cdk/.claude-plugin/plugin.json +1 -1
  16. package/plugins/lisa-cdk/.codex-plugin/plugin.json +1 -1
  17. package/plugins/lisa-cdk-agy/plugin.json +1 -1
  18. package/plugins/lisa-cdk-copilot/.claude-plugin/plugin.json +1 -1
  19. package/plugins/lisa-cdk-cursor/.claude-plugin/plugin.json +1 -1
  20. package/plugins/lisa-cdk-devin/.claude-plugin/plugin.json +1 -1
  21. package/plugins/lisa-cdk-devin/.devin-plugin/plugin.json +1 -1
  22. package/plugins/lisa-copilot/.claude-plugin/plugin.json +1 -1
  23. package/plugins/lisa-copilot/hooks/threshold-ratchet-compare.mjs +433 -21
  24. package/plugins/lisa-copilot/hooks/threshold-ratchet-families.mjs +77 -4
  25. package/plugins/lisa-copilot/hooks/threshold-ratchet.mjs +280 -46
  26. package/plugins/lisa-cursor/.claude-plugin/plugin.json +1 -1
  27. package/plugins/lisa-cursor/hooks/threshold-ratchet-compare.mjs +433 -21
  28. package/plugins/lisa-cursor/hooks/threshold-ratchet-families.mjs +77 -4
  29. package/plugins/lisa-cursor/hooks/threshold-ratchet.mjs +280 -46
  30. package/plugins/lisa-devin/.claude-plugin/plugin.json +1 -1
  31. package/plugins/lisa-devin/.devin-plugin/plugin.json +1 -1
  32. package/plugins/lisa-devin/hooks/threshold-ratchet-compare.mjs +433 -21
  33. package/plugins/lisa-devin/hooks/threshold-ratchet-families.mjs +77 -4
  34. package/plugins/lisa-devin/hooks/threshold-ratchet.mjs +280 -46
  35. package/plugins/lisa-expo/.claude-plugin/plugin.json +1 -1
  36. package/plugins/lisa-expo/.codex-plugin/plugin.json +1 -1
  37. package/plugins/lisa-expo-agy/plugin.json +1 -1
  38. package/plugins/lisa-expo-copilot/.claude-plugin/plugin.json +1 -1
  39. package/plugins/lisa-expo-cursor/.claude-plugin/plugin.json +1 -1
  40. package/plugins/lisa-expo-devin/.claude-plugin/plugin.json +1 -1
  41. package/plugins/lisa-expo-devin/.devin-plugin/plugin.json +1 -1
  42. package/plugins/lisa-harper-fabric/.claude-plugin/plugin.json +1 -1
  43. package/plugins/lisa-harper-fabric/.codex-plugin/plugin.json +1 -1
  44. package/plugins/lisa-harper-fabric-agy/plugin.json +1 -1
  45. package/plugins/lisa-harper-fabric-copilot/.claude-plugin/plugin.json +1 -1
  46. package/plugins/lisa-harper-fabric-cursor/.claude-plugin/plugin.json +1 -1
  47. package/plugins/lisa-harper-fabric-devin/.claude-plugin/plugin.json +1 -1
  48. package/plugins/lisa-harper-fabric-devin/.devin-plugin/plugin.json +1 -1
  49. package/plugins/lisa-nestjs/.claude-plugin/plugin.json +1 -1
  50. package/plugins/lisa-nestjs/.codex-plugin/plugin.json +1 -1
  51. package/plugins/lisa-nestjs-agy/plugin.json +1 -1
  52. package/plugins/lisa-nestjs-copilot/.claude-plugin/plugin.json +1 -1
  53. package/plugins/lisa-nestjs-cursor/.claude-plugin/plugin.json +1 -1
  54. package/plugins/lisa-nestjs-devin/.claude-plugin/plugin.json +1 -1
  55. package/plugins/lisa-nestjs-devin/.devin-plugin/plugin.json +1 -1
  56. package/plugins/lisa-phaser/.claude-plugin/plugin.json +1 -1
  57. package/plugins/lisa-phaser/.codex-plugin/plugin.json +1 -1
  58. package/plugins/lisa-phaser-agy/plugin.json +1 -1
  59. package/plugins/lisa-phaser-copilot/.claude-plugin/plugin.json +1 -1
  60. package/plugins/lisa-phaser-cursor/.claude-plugin/plugin.json +1 -1
  61. package/plugins/lisa-phaser-devin/.claude-plugin/plugin.json +1 -1
  62. package/plugins/lisa-phaser-devin/.devin-plugin/plugin.json +1 -1
  63. package/plugins/lisa-rails/.claude-plugin/plugin.json +1 -1
  64. package/plugins/lisa-rails/.codex-plugin/plugin.json +1 -1
  65. package/plugins/lisa-rails-agy/plugin.json +1 -1
  66. package/plugins/lisa-rails-copilot/.claude-plugin/plugin.json +1 -1
  67. package/plugins/lisa-rails-cursor/.claude-plugin/plugin.json +1 -1
  68. package/plugins/lisa-rails-devin/.claude-plugin/plugin.json +1 -1
  69. package/plugins/lisa-rails-devin/.devin-plugin/plugin.json +1 -1
  70. package/plugins/lisa-typescript/.claude-plugin/plugin.json +1 -1
  71. package/plugins/lisa-typescript/.codex-plugin/plugin.json +1 -1
  72. package/plugins/lisa-typescript-agy/plugin.json +1 -1
  73. package/plugins/lisa-typescript-copilot/.claude-plugin/plugin.json +1 -1
  74. package/plugins/lisa-typescript-cursor/.claude-plugin/plugin.json +1 -1
  75. package/plugins/lisa-typescript-devin/.claude-plugin/plugin.json +1 -1
  76. package/plugins/lisa-typescript-devin/.devin-plugin/plugin.json +1 -1
  77. package/plugins/lisa-wiki/.claude-plugin/plugin.json +1 -1
  78. package/plugins/lisa-wiki/.codex-plugin/plugin.json +1 -1
  79. package/plugins/lisa-wiki-agy/plugin.json +1 -1
  80. package/plugins/lisa-wiki-copilot/.claude-plugin/plugin.json +1 -1
  81. package/plugins/lisa-wiki-cursor/.claude-plugin/plugin.json +1 -1
  82. package/plugins/lisa-wiki-devin/.claude-plugin/plugin.json +1 -1
  83. package/plugins/lisa-wiki-devin/.devin-plugin/plugin.json +1 -1
  84. package/plugins/src/base/hooks/threshold-ratchet-compare.mjs +433 -21
  85. package/plugins/src/base/hooks/threshold-ratchet-families.mjs +77 -4
  86. package/plugins/src/base/hooks/threshold-ratchet.mjs +280 -46
  87. package/rails/copy-overwrite/scripts/check-threshold-ratchet.mjs +280 -46
  88. package/rails/copy-overwrite/scripts/threshold-ratchet-compare.mjs +433 -21
  89. package/rails/copy-overwrite/scripts/threshold-ratchet-families.mjs +77 -4
  90. package/typescript/copy-contents/.husky/pre-commit +3 -2
  91. package/typescript/copy-overwrite/scripts/check-threshold-ratchet.mjs +280 -46
  92. package/typescript/copy-overwrite/scripts/threshold-ratchet-compare.mjs +433 -21
  93. package/typescript/copy-overwrite/scripts/threshold-ratchet-families.mjs +77 -4
@@ -32,7 +32,21 @@
32
32
  * reason, only when the regression is justified; a person can reverse it by
33
33
  * removing the entry. Honored ONLY from the baseline side (HEAD /
34
34
  * merge-base), never from the change under review — an agent cannot grant
35
- * itself an exception in the same change that weakens a gate. `key: "*"`
35
+ * itself an exception in the same change that weakens a gate. So an exception
36
+ * takes two changes, and the first has to be able to land (#5099): a change
37
+ * whose only findings are added entries, each with a reason and an `until`
38
+ * day that has not passed, is ACCEPTED in every mode with a notice, and
39
+ * exempts nothing until it is merged. An entry that arrives with any other
40
+ * finding is refused. Under `humanGate.mode: "strict"` — read from the
41
+ * baseline, like the allow list — an added entry is refused as before: there
42
+ * an exception is a person's decision, and no layer of this check can see
43
+ * that a person approved. See `settleAddedExceptions`.
44
+ *
45
+ * "Merged" has to mean the same thing at commit as it does in a pull request.
46
+ * `--staged` and `--hook` baseline against HEAD, which is whatever the branch
47
+ * last committed, so there an entry counts only when a protected branch
48
+ * (the remote's default branch, or a `deploy.branches` branch) also holds it
49
+ * as the remote last reported it. See `protectedBranchRefs`. `key: "*"`
36
50
  * allows every key in the file, and reports as file-wide so it is not mistaken
37
51
  * for a key-scoped one. A declared threshold leaves by this same list and by
38
52
  * nothing else: `file` is `.lisa.config.json` and `key` is
@@ -64,13 +78,18 @@ import { fileURLToPath } from "node:url";
64
78
  import {
65
79
  extractAllowEntries,
66
80
  familyFor,
81
+ humanGateModeOfText,
67
82
  parseJson,
68
83
  } from "./threshold-ratchet-families.mjs";
69
84
  import {
70
85
  applyAllowList,
71
86
  compareFile,
72
87
  describeAllowList,
88
+ describeNearMisses,
89
+ describeUnmergedCover,
73
90
  formatReport,
91
+ settleAddedExceptions,
92
+ splitMergedEntries,
74
93
  } from "./threshold-ratchet-compare.mjs";
75
94
 
76
95
  /**
@@ -102,6 +121,9 @@ const GIT_LOCATIONS = [
102
121
  ];
103
122
  const GIT = GIT_LOCATIONS.find(candidate => fs.existsSync(candidate)) ?? "git";
104
123
 
124
+ /** Where the remote-tracking refs of `origin` live. */
125
+ const REMOTE_REFS = "refs/remotes/origin/";
126
+
105
127
  /** Git flag shared by every changed-file listing. */
106
128
  const NAME_ONLY = "--name-only";
107
129
  /**
@@ -192,7 +214,16 @@ function resolvePlan(mode, root, baseRef, onlyFiles) {
192
214
  baselineRef: "HEAD",
193
215
  readCurrent: f => {
194
216
  try {
195
- return fs.readFileSync(path.join(root, f), "utf-8");
217
+ // Inside the repository only, by REAL location: the name can come
218
+ // from an allow entry, and a `..` segment or a symlink must not make
219
+ // this read a file somewhere else and print what it holds.
220
+ const home = fs.realpathSync(root);
221
+ const target = fs.realpathSync(path.resolve(root, f));
222
+ if (!target.startsWith(home + path.sep)) return null;
223
+ // Regular files only. Reading a named pipe would block for ever, and
224
+ // a hook that hangs wedges the agent session it is advising.
225
+ if (!fs.statSync(target).isFile()) return null;
226
+ return fs.readFileSync(target, "utf-8");
196
227
  } catch {
197
228
  // probe-direction: fail-closed — an unreadable current file compares as
198
229
  // absent against the baseline, which is the strict side of the ratchet.
@@ -288,26 +319,42 @@ function isPromotion(root, baselineConfig, baseRef, headRef) {
288
319
  * @param {"hook"|"staged"|"base"} mode Comparison mode
289
320
  * @param {string | undefined} baseRef Base ref (base mode only)
290
321
  * @param {string | undefined} headRef Head ref (base mode only)
291
- * @returns {{ entries: object[], promotion: boolean, note: string | null }}
292
- * Entries, whether this is a promotion, and an audit line to print when the
293
- * entries came from anywhere but the baseline
322
+ * @returns {{ entries: object[], unmerged: object[], protectedRefs: string[], promotion: boolean, note: string | null, humanGateMode: string }}
323
+ * Entries to honour, entries only this branch holds (local modes), the
324
+ * protected refs consulted for that, whether this is a promotion, an audit
325
+ * line to print when the entries came from anywhere but the baseline, and
326
+ * the baseline's `humanGate.mode`
294
327
  */
295
328
  function resolveAllowList(root, baselineRef, mode, baseRef, headRef) {
296
- const baselineConfig = parseJson(
297
- git(["show", `${baselineRef}:.lisa.config.json`], root)
298
- );
299
- if (mode !== "base" || !isPromotion(root, baselineConfig, baseRef, headRef)) {
329
+ const baselineText = git(["show", `${baselineRef}:.lisa.config.json`], root);
330
+ const baselineConfig = parseJson(baselineText);
331
+ const humanGateMode = humanGateModeOfText(baselineText);
332
+ if (mode !== "base") {
333
+ return {
334
+ ...localAllowList(root, baselineConfig),
335
+ promotion: false,
336
+ note: null,
337
+ humanGateMode,
338
+ };
339
+ }
340
+ if (!isPromotion(root, baselineConfig, baseRef, headRef)) {
300
341
  return {
301
342
  entries: extractAllowEntries(baselineConfig),
343
+ unmerged: [],
344
+ protectedRefs: [],
302
345
  promotion: false,
303
346
  note: null,
347
+ humanGateMode,
304
348
  };
305
349
  }
306
350
  return {
307
351
  entries: extractAllowEntries(
308
352
  parseJson(git(["show", "HEAD:.lisa.config.json"], root))
309
353
  ),
354
+ unmerged: [],
355
+ protectedRefs: [],
310
356
  promotion: true,
357
+ humanGateMode,
311
358
  note:
312
359
  `threshold-ratchet: promotion ${bareBranch(headRef)} → ` +
313
360
  `${bareBranch(baseRef)}; both are deploy-chain branches declared at ` +
@@ -317,19 +364,132 @@ function resolveAllowList(root, baselineRef, mode, baseRef, headRef) {
317
364
  };
318
365
  }
319
366
 
367
+ /**
368
+ * The remote-tracking refs of this repository's protected branches: the
369
+ * remote's default branch and every `deploy.branches` branch it declares.
370
+ *
371
+ * Which branches are protected is read from the remote's default branch and
372
+ * from nowhere else. HEAD's own `deploy.branches` is never consulted: a
373
+ * branch could name itself a deploy branch there, push, and count its own
374
+ * unmerged entry as merged.
375
+ *
376
+ * `origin` is the only remote consulted, the same assumption `bareBranch`
377
+ * makes.
378
+ *
379
+ * This is a local check and can be argued with: whoever owns `.git` owns
380
+ * these refs, and can repoint `origin/HEAD` or write a tracking ref by hand.
381
+ * The pull-request check, which compares against the base on the server's
382
+ * checkout, is the layer that cannot.
383
+ * @param {string} root Repo root
384
+ * @returns {string[]} Full ref names that resolve, e.g.
385
+ * `refs/remotes/origin/main`, `refs/remotes/origin/dev`; empty when the
386
+ * remote's default branch cannot be named
387
+ */
388
+ function protectedBranchRefs(root) {
389
+ const resolves = ref =>
390
+ git(["rev-parse", "--verify", "--quiet", `${ref}^{commit}`], root) !== null;
391
+ // Full ref names throughout. A short `origin/main` resolves to a LOCAL
392
+ // branch of that name before the remote-tracking one, so one
393
+ // `git branch origin/main` would have made an unmerged entry count as merged.
394
+ const declared = git(
395
+ ["symbolic-ref", "--quiet", "refs/remotes/origin/HEAD"],
396
+ root
397
+ )?.trim();
398
+ // Only the symbolic default counts. `origin/HEAD` is missing in a
399
+ // repository that was fetched rather than cloned, or freshly pushed, and it
400
+ // is tempting to try `origin/main` there. But a branch called `main` is not
401
+ // protected because of its name: where the default is `trunk`, an entry on
402
+ // an unprotected `origin/main` would count as merged. With no symbolic
403
+ // default nothing is returned, and the caller refuses and names the remedy.
404
+ const defaultRef =
405
+ declared?.startsWith(REMOTE_REFS) && resolves(declared) ? declared : null;
406
+ if (!defaultRef) return [];
407
+ const chain = deployChain(
408
+ parseJson(git(["show", `${defaultRef}:.lisa.config.json`], root))
409
+ );
410
+ return [
411
+ ...new Set([defaultRef, ...chain.map(branch => `${REMOTE_REFS}${branch}`)]),
412
+ ].filter(resolves);
413
+ }
414
+
415
+ /**
416
+ * Whether `origin` has any remote-tracking ref at all.
417
+ *
418
+ * A probe that fails is not an answer. `git()` returns null for every
419
+ * failure, a timeout included, and reading that as "never fetched" would let
420
+ * a transient error switch the local fence off.
421
+ * @param {string} root Repo root
422
+ * @returns {boolean | null} True when something was ever fetched from
423
+ * `origin`, false when the probe ran and found nothing, null when the probe
424
+ * itself failed
425
+ */
426
+ function originWasFetched(root) {
427
+ const first = git(
428
+ ["for-each-ref", "--count=1", "--format=%(refname)", REMOTE_REFS],
429
+ root
430
+ );
431
+ if (first === null) return null;
432
+ return first.trim() !== "";
433
+ }
434
+
435
+ /**
436
+ * The allow list for the local modes (`--staged`, `--hook`).
437
+ *
438
+ * HEAD's entries, minus those no protected branch holds yet. Two cases have
439
+ * no protected branch to ask, and they are opposite:
440
+ *
441
+ * nothing was ever fetched from `origin` — there is no merge for an entry
442
+ * to wait for, so every HEAD entry counts, as it always did. Refusing
443
+ * would wedge a repository that has no pull requests at all.
444
+ * `origin` was fetched, and its default branch cannot be named — there IS
445
+ * a merge to wait for and nothing here can tell whether it happened, so
446
+ * no HEAD entry counts. The refusal names the command that fixes it. A
447
+ * probe that fails is read the same way.
448
+ * @param {string} root Repo root
449
+ * @param {unknown} headConfig `.lisa.config.json` at HEAD
450
+ * @returns {{ entries: object[], unmerged: object[], protectedRefs: string[] }}
451
+ * Entries to honour, entries only this branch holds, and the refs consulted
452
+ */
453
+ function localAllowList(root, headConfig) {
454
+ const entries = extractAllowEntries(headConfig);
455
+ const protectedRefs = protectedBranchRefs(root);
456
+ if (protectedRefs.length === 0) {
457
+ // Honour HEAD only on a positive "nothing was ever fetched". A probe that
458
+ // failed is treated like a fetched remote whose default is unknown.
459
+ return originWasFetched(root) === false
460
+ ? { entries, unmerged: [], protectedRefs }
461
+ : { entries: [], unmerged: entries, protectedRefs };
462
+ }
463
+ const { merged, unmerged } = splitMergedEntries(
464
+ entries,
465
+ protectedRefs.map(ref =>
466
+ extractAllowEntries(
467
+ parseJson(git(["show", `${ref}:.lisa.config.json`], root))
468
+ )
469
+ )
470
+ );
471
+ return { entries: merged, unmerged, protectedRefs };
472
+ }
473
+
320
474
  /**
321
475
  * Split off the allow-entry additions a promotion is carrying forward.
322
476
  *
323
- * `applyAllowList` never drops an `allow-added` finding, from either side —
324
- * an exception must not approve its own creation. That is right for an
325
- * ordinary PR and wrong for a promotion, where the entry is not being created:
326
- * it already exists on the upstream branch, where its creation faced this same
327
- * unconditional block and needed a human to clear it. Without this the fix
328
- * would be cosmetic — a promotion carrying an approved exemption also carries
329
- * the `.lisa.config.json` diff that records it, so it would still be blocked
330
- * by the finding for the record of its own approval.
477
+ * An `allow-added` finding is never covered by an allow entry, from either
478
+ * side — an exception must not approve its own creation — and an entry that
479
+ * arrives with any other finding is refused (`settleAddedExceptions`). That is
480
+ * right for an ordinary PR and wrong for a promotion, where the entry is not
481
+ * being created: it already exists on the upstream branch, where it was
482
+ * recorded in a change of its own. Without this the fix would be cosmetic — a
483
+ * promotion carrying an approved exemption also carries the
484
+ * `.lisa.config.json` diff that records it, so it would still be blocked by
485
+ * the finding for the record of its own approval.
331
486
  *
332
- * Only `allow-added` is carried. An actual threshold weakening in the same
487
+ * A root config that stopped being `strict` is carried for the same reason:
488
+ * the change already landed on the upstream branch, and the downstream branch
489
+ * can only catch up by promotion, so refusing it here would refuse every
490
+ * promotion from then on, including ones carrying unrelated work.
491
+ *
492
+ * Nothing else is carried. An actual threshold weakening in the same
333
493
  * promotion still has to be covered by an allow entry.
334
494
  * @param {Array<{ type: string }>} findings All findings from the change
335
495
  * @param {boolean} promotion Whether the change is a recognised promotion
@@ -338,9 +498,12 @@ function resolveAllowList(root, baselineRef, mode, baseRef, headRef) {
338
498
  */
339
499
  function partitionCarriedEntries(findings, promotion) {
340
500
  if (!promotion) return { carried: [], rest: findings };
501
+ const isCarried = f =>
502
+ f.type === "allow-added" ||
503
+ (f.file === ".lisa.config.json" && f.key === "humanGate.mode");
341
504
  return {
342
- carried: findings.filter(f => f.type === "allow-added"),
343
- rest: findings.filter(f => f.type !== "allow-added"),
505
+ carried: findings.filter(isCarried),
506
+ rest: findings.filter(f => !isCarried(f)),
344
507
  };
345
508
  }
346
509
 
@@ -430,57 +593,128 @@ function run(mode, baseRef, onlyFiles, headRef) {
430
593
  // moment the condition passes, and reporting it only when something else has
431
594
  // already failed is how a list nobody reads stays a list nobody reads.
432
595
  if (findings.length === 0) {
433
- reportAllowList(allow.entries, []);
596
+ reportAllowList(allow.entries);
434
597
  return 0;
435
598
  }
436
- return reportFindings(findings, allow, mode);
599
+ return reportFindings(findings, allow, mode, plan.readCurrent);
437
600
  }
438
601
 
439
602
  /**
440
- * Print the allow entries a human has to act on, minus the ones a refusal is
441
- * about to name in full.
603
+ * The allow entries a human has to act on, minus the ones a refusal is about
604
+ * to name in full.
442
605
  * @param {object[]} entries The resolved allow list
443
606
  * @param {Array<{ message: string }>} expired Refusals already being printed
607
+ * @returns {string[]} One line per entry still to report
608
+ */
609
+ function allowListLines(entries, expired) {
610
+ return describeAllowList(entries)
611
+ .filter(line => !expired.some(item => item.message.startsWith(line)))
612
+ .map(line => `threshold-ratchet: ${line}`);
613
+ }
614
+
615
+ /**
616
+ * Print the allow entries a human has to act on.
617
+ * @param {object[]} entries The resolved allow list
618
+ * @returns {void}
619
+ */
620
+ function reportAllowList(entries) {
621
+ for (const line of allowListLines(entries, [])) {
622
+ process.stdout.write(`${line}\n`);
623
+ }
624
+ }
625
+
626
+ /**
627
+ * Write a passing run's lines where their reader will see them.
628
+ *
629
+ * At commit and in CI that is stdout. An agent-time hook that exits 0 is a
630
+ * different matter: the runtime shows the agent nothing from stdout unless it
631
+ * is the hook reply object, so a notice printed as plain text there reaches
632
+ * nobody. When the run recorded a new exception, hook mode therefore answers
633
+ * with the reply object and puts every line in `additionalContext`. Without a
634
+ * notice it prints plain lines exactly as it always has.
635
+ *
636
+ * Parity: the reply object is the Claude Code and Codex hook contract. A
637
+ * runtime that does not read it shows the JSON text or nothing; the commit and
638
+ * pull-request layers print the same notice in plain text there.
639
+ * @param {string[]} lines Lines to deliver
640
+ * @param {boolean} asHookReply Whether to wrap them in the hook reply object
444
641
  * @returns {void}
445
642
  */
446
- function reportAllowList(entries, expired) {
447
- for (const line of describeAllowList(entries)) {
448
- if (expired.some(item => item.message.startsWith(line))) continue;
449
- process.stdout.write(`threshold-ratchet: ${line}\n`);
643
+ function deliver(lines, asHookReply) {
644
+ if (lines.length === 0) return;
645
+ if (!asHookReply) {
646
+ process.stdout.write(`${lines.join("\n")}\n`);
647
+ return;
450
648
  }
649
+ process.stdout.write(
650
+ `${JSON.stringify({
651
+ hookSpecificOutput: {
652
+ hookEventName: "PostToolUse",
653
+ additionalContext: lines.join("\n"),
654
+ },
655
+ })}\n`
656
+ );
451
657
  }
452
658
 
453
659
  /**
454
660
  * Print the verdict for a change that produced findings.
455
661
  * @param {object[]} findings Findings from every watched file
456
- * @param {{ entries: object[], promotion: boolean, note: string | null }} allow
457
- * The resolved allow list and its provenance
662
+ * @param {{ entries: object[], unmerged: object[], protectedRefs: string[], promotion: boolean, note: string | null, humanGateMode: string }} allow
663
+ * The resolved allow list, its provenance and the baseline's mode
458
664
  * @param {"hook"|"staged"|"base"} mode Comparison mode
665
+ * @param {(file: string) => string | null} readCurrent Reads a repository
666
+ * file as the change has it
459
667
  * @returns {number} Process exit code (2 for hook mode, 1 otherwise; 0 clean)
460
668
  */
461
- function reportFindings(findings, allow, mode) {
669
+ function reportFindings(findings, allow, mode, readCurrent) {
462
670
  const split = partitionCarriedEntries(findings, allow.promotion);
463
- const { blocked, allowed, expired } = applyAllowList(
671
+ const settled = settleAddedExceptions(
464
672
  split.rest,
673
+ allow.humanGateMode,
674
+ Date.now(),
675
+ readCurrent
676
+ );
677
+ const { blocked, allowed, expired } = applyAllowList(
678
+ settled.rest,
465
679
  allow.entries
466
680
  );
467
- if (allow.note) process.stdout.write(`${allow.note}\n`);
468
- reportAllowList(allow.entries, expired);
469
- for (const finding of split.carried) {
470
- process.stdout.write(
471
- `threshold-ratchet: carried forward by this promotion, approved upstream — ${finding.message}\n`
472
- );
473
- }
474
- for (const item of allowed) {
475
- process.stdout.write(
476
- `threshold-ratchet: ${item.message} (.lisa.config.json exception)\n`
477
- );
478
- }
681
+ const refused = [...settled.refused, ...blocked];
682
+ const passed = refused.length === 0;
683
+ // A notice that an exception was recorded is only true of a change that
684
+ // lands. Printed beside a refusal it tells the reader to go on to the
685
+ // threshold change while the entry it speaks of was never committed.
686
+ const recorded = passed ? settled.accepted : [];
687
+ const lines = [
688
+ ...(allow.note ? [allow.note] : []),
689
+ ...allowListLines(allow.entries, expired),
690
+ ...split.carried.map(
691
+ finding =>
692
+ `threshold-ratchet: carried forward by this promotion, approved upstream — ${finding.message}`
693
+ ),
694
+ ...allowed.map(
695
+ item => `threshold-ratchet: ${item.message} (.lisa.config.json exception)`
696
+ ),
697
+ ...recorded.map(item => `threshold-ratchet: ${item.message}`),
698
+ ];
699
+ deliver(lines, mode === "hook" && recorded.length > 0);
479
700
  for (const item of expired) {
480
701
  process.stderr.write(`threshold-ratchet: refused — ${item.message}\n`);
481
702
  }
482
- if (blocked.length === 0) return 0;
483
- process.stderr.write(`${formatReport(blocked)}\n`);
703
+ for (const line of describeUnmergedCover(
704
+ blocked,
705
+ allow.unmerged,
706
+ allow.protectedRefs.map(ref => ref.replace(/^refs\/remotes\//u, ""))
707
+ )) {
708
+ process.stderr.write(`threshold-ratchet: refused — ${line}\n`);
709
+ }
710
+ for (const line of describeNearMisses(blocked, [
711
+ ...allow.entries,
712
+ ...allow.unmerged,
713
+ ])) {
714
+ process.stderr.write(`threshold-ratchet: refused — ${line}\n`);
715
+ }
716
+ if (passed) return 0;
717
+ process.stderr.write(`${formatReport(refused, allow.humanGateMode)}\n`);
484
718
  return mode === "hook" ? 2 : 1;
485
719
  }
486
720
 
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lisa",
3
- "version": "8.2.5",
3
+ "version": "8.2.6",
4
4
  "description": "Universal governance — agents, skills, commands, hooks, and rules for all projects",
5
5
  "author": {
6
6
  "name": "Cody Swann"
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lisa-cdk",
3
- "version": "8.2.5",
3
+ "version": "8.2.6",
4
4
  "description": "AWS CDK-specific plugin",
5
5
  "author": {
6
6
  "name": "Cody Swann"
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lisa-cdk",
3
- "version": "8.2.5",
3
+ "version": "8.2.6",
4
4
  "description": "AWS CDK-specific Lisa plugin.",
5
5
  "author": {
6
6
  "name": "Cody Swann"
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lisa-cdk",
3
- "version": "8.2.5",
3
+ "version": "8.2.6",
4
4
  "description": "AWS CDK-specific plugin",
5
5
  "author": {
6
6
  "name": "Cody Swann"
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lisa-cdk",
3
- "version": "8.2.5",
3
+ "version": "8.2.6",
4
4
  "description": "AWS CDK-specific plugin",
5
5
  "author": {
6
6
  "name": "Cody Swann"
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lisa-cdk",
3
- "version": "8.2.5",
3
+ "version": "8.2.6",
4
4
  "description": "AWS CDK-specific plugin",
5
5
  "author": {
6
6
  "name": "Cody Swann"
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lisa-cdk",
3
- "version": "8.2.5",
3
+ "version": "8.2.6",
4
4
  "description": "AWS CDK-specific plugin",
5
5
  "author": {
6
6
  "name": "Cody Swann"
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lisa-cdk",
3
- "version": "8.2.5",
3
+ "version": "8.2.6",
4
4
  "description": "AWS CDK-specific plugin",
5
5
  "author": {
6
6
  "name": "Cody Swann"
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lisa",
3
- "version": "8.2.5",
3
+ "version": "8.2.6",
4
4
  "description": "Universal governance — agents, skills, commands, hooks, and rules for all projects",
5
5
  "author": {
6
6
  "name": "Cody Swann"