@codyswann/lisa 8.2.4 → 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 (94) hide show
  1. package/all/copy-overwrite/scripts/check-npm-publish-landed.mjs +10 -0
  2. package/all/copy-overwrite/scripts/check-threshold-ratchet.mjs +280 -46
  3. package/all/copy-overwrite/scripts/npm-updater-helper-graph.json +3 -3
  4. package/all/copy-overwrite/scripts/threshold-ratchet-compare.mjs +433 -21
  5. package/all/copy-overwrite/scripts/threshold-ratchet-families.mjs +77 -4
  6. package/dist/core/lisa-owned-hash-ledger.json +58 -2
  7. package/dist/core/nightly-e2e-guard-behavior-certificate.js +2 -2
  8. package/dist/core/upstream-evidence-manifest.json +36 -15
  9. package/package.json +4 -4
  10. package/plugins/lisa/.claude-plugin/plugin.json +1 -1
  11. package/plugins/lisa/.codex-plugin/plugin.json +1 -1
  12. package/plugins/lisa/hooks/threshold-ratchet-compare.mjs +433 -21
  13. package/plugins/lisa/hooks/threshold-ratchet-families.mjs +77 -4
  14. package/plugins/lisa/hooks/threshold-ratchet.mjs +280 -46
  15. package/plugins/lisa-agy/plugin.json +1 -1
  16. package/plugins/lisa-cdk/.claude-plugin/plugin.json +1 -1
  17. package/plugins/lisa-cdk/.codex-plugin/plugin.json +1 -1
  18. package/plugins/lisa-cdk-agy/plugin.json +1 -1
  19. package/plugins/lisa-cdk-copilot/.claude-plugin/plugin.json +1 -1
  20. package/plugins/lisa-cdk-cursor/.claude-plugin/plugin.json +1 -1
  21. package/plugins/lisa-cdk-devin/.claude-plugin/plugin.json +1 -1
  22. package/plugins/lisa-cdk-devin/.devin-plugin/plugin.json +1 -1
  23. package/plugins/lisa-copilot/.claude-plugin/plugin.json +1 -1
  24. package/plugins/lisa-copilot/hooks/threshold-ratchet-compare.mjs +433 -21
  25. package/plugins/lisa-copilot/hooks/threshold-ratchet-families.mjs +77 -4
  26. package/plugins/lisa-copilot/hooks/threshold-ratchet.mjs +280 -46
  27. package/plugins/lisa-cursor/.claude-plugin/plugin.json +1 -1
  28. package/plugins/lisa-cursor/hooks/threshold-ratchet-compare.mjs +433 -21
  29. package/plugins/lisa-cursor/hooks/threshold-ratchet-families.mjs +77 -4
  30. package/plugins/lisa-cursor/hooks/threshold-ratchet.mjs +280 -46
  31. package/plugins/lisa-devin/.claude-plugin/plugin.json +1 -1
  32. package/plugins/lisa-devin/.devin-plugin/plugin.json +1 -1
  33. package/plugins/lisa-devin/hooks/threshold-ratchet-compare.mjs +433 -21
  34. package/plugins/lisa-devin/hooks/threshold-ratchet-families.mjs +77 -4
  35. package/plugins/lisa-devin/hooks/threshold-ratchet.mjs +280 -46
  36. package/plugins/lisa-expo/.claude-plugin/plugin.json +1 -1
  37. package/plugins/lisa-expo/.codex-plugin/plugin.json +1 -1
  38. package/plugins/lisa-expo-agy/plugin.json +1 -1
  39. package/plugins/lisa-expo-copilot/.claude-plugin/plugin.json +1 -1
  40. package/plugins/lisa-expo-cursor/.claude-plugin/plugin.json +1 -1
  41. package/plugins/lisa-expo-devin/.claude-plugin/plugin.json +1 -1
  42. package/plugins/lisa-expo-devin/.devin-plugin/plugin.json +1 -1
  43. package/plugins/lisa-harper-fabric/.claude-plugin/plugin.json +1 -1
  44. package/plugins/lisa-harper-fabric/.codex-plugin/plugin.json +1 -1
  45. package/plugins/lisa-harper-fabric-agy/plugin.json +1 -1
  46. package/plugins/lisa-harper-fabric-copilot/.claude-plugin/plugin.json +1 -1
  47. package/plugins/lisa-harper-fabric-cursor/.claude-plugin/plugin.json +1 -1
  48. package/plugins/lisa-harper-fabric-devin/.claude-plugin/plugin.json +1 -1
  49. package/plugins/lisa-harper-fabric-devin/.devin-plugin/plugin.json +1 -1
  50. package/plugins/lisa-nestjs/.claude-plugin/plugin.json +1 -1
  51. package/plugins/lisa-nestjs/.codex-plugin/plugin.json +1 -1
  52. package/plugins/lisa-nestjs-agy/plugin.json +1 -1
  53. package/plugins/lisa-nestjs-copilot/.claude-plugin/plugin.json +1 -1
  54. package/plugins/lisa-nestjs-cursor/.claude-plugin/plugin.json +1 -1
  55. package/plugins/lisa-nestjs-devin/.claude-plugin/plugin.json +1 -1
  56. package/plugins/lisa-nestjs-devin/.devin-plugin/plugin.json +1 -1
  57. package/plugins/lisa-phaser/.claude-plugin/plugin.json +1 -1
  58. package/plugins/lisa-phaser/.codex-plugin/plugin.json +1 -1
  59. package/plugins/lisa-phaser-agy/plugin.json +1 -1
  60. package/plugins/lisa-phaser-copilot/.claude-plugin/plugin.json +1 -1
  61. package/plugins/lisa-phaser-cursor/.claude-plugin/plugin.json +1 -1
  62. package/plugins/lisa-phaser-devin/.claude-plugin/plugin.json +1 -1
  63. package/plugins/lisa-phaser-devin/.devin-plugin/plugin.json +1 -1
  64. package/plugins/lisa-rails/.claude-plugin/plugin.json +1 -1
  65. package/plugins/lisa-rails/.codex-plugin/plugin.json +1 -1
  66. package/plugins/lisa-rails-agy/plugin.json +1 -1
  67. package/plugins/lisa-rails-copilot/.claude-plugin/plugin.json +1 -1
  68. package/plugins/lisa-rails-cursor/.claude-plugin/plugin.json +1 -1
  69. package/plugins/lisa-rails-devin/.claude-plugin/plugin.json +1 -1
  70. package/plugins/lisa-rails-devin/.devin-plugin/plugin.json +1 -1
  71. package/plugins/lisa-typescript/.claude-plugin/plugin.json +1 -1
  72. package/plugins/lisa-typescript/.codex-plugin/plugin.json +1 -1
  73. package/plugins/lisa-typescript-agy/plugin.json +1 -1
  74. package/plugins/lisa-typescript-copilot/.claude-plugin/plugin.json +1 -1
  75. package/plugins/lisa-typescript-cursor/.claude-plugin/plugin.json +1 -1
  76. package/plugins/lisa-typescript-devin/.claude-plugin/plugin.json +1 -1
  77. package/plugins/lisa-typescript-devin/.devin-plugin/plugin.json +1 -1
  78. package/plugins/lisa-wiki/.claude-plugin/plugin.json +1 -1
  79. package/plugins/lisa-wiki/.codex-plugin/plugin.json +1 -1
  80. package/plugins/lisa-wiki-agy/plugin.json +1 -1
  81. package/plugins/lisa-wiki-copilot/.claude-plugin/plugin.json +1 -1
  82. package/plugins/lisa-wiki-cursor/.claude-plugin/plugin.json +1 -1
  83. package/plugins/lisa-wiki-devin/.claude-plugin/plugin.json +1 -1
  84. package/plugins/lisa-wiki-devin/.devin-plugin/plugin.json +1 -1
  85. package/plugins/src/base/hooks/threshold-ratchet-compare.mjs +433 -21
  86. package/plugins/src/base/hooks/threshold-ratchet-families.mjs +77 -4
  87. package/plugins/src/base/hooks/threshold-ratchet.mjs +280 -46
  88. package/rails/copy-overwrite/scripts/check-threshold-ratchet.mjs +280 -46
  89. package/rails/copy-overwrite/scripts/threshold-ratchet-compare.mjs +433 -21
  90. package/rails/copy-overwrite/scripts/threshold-ratchet-families.mjs +77 -4
  91. package/typescript/copy-contents/.husky/pre-commit +3 -2
  92. package/typescript/copy-overwrite/scripts/check-threshold-ratchet.mjs +280 -46
  93. package/typescript/copy-overwrite/scripts/threshold-ratchet-compare.mjs +433 -21
  94. package/typescript/copy-overwrite/scripts/threshold-ratchet-families.mjs +77 -4
@@ -11,6 +11,9 @@
11
11
  */
12
12
  import {
13
13
  ALLOW_STATE,
14
+ HUMAN_GATE_ACCESS_ONLY,
15
+ HUMAN_GATE_STRICT,
16
+ allowEntryExpiry,
14
17
  classifyAllowEntry,
15
18
  describeAllowScope,
16
19
  extractAllowEntries,
@@ -26,8 +29,13 @@ import {
26
29
  globRoot,
27
30
  isDeclaredDirection,
28
31
  parseJson,
32
+ reasonInWords,
29
33
  } from "./threshold-ratchet-families.mjs";
30
34
 
35
+ /** The one config the allow list and the `humanGate.mode` are read from. */
36
+ const ROOT_CONFIG = ".lisa.config.json";
37
+ /** Finding type: the change adds a `thresholdRatchet.allow` entry. */
38
+ const TYPE_ALLOW_ADDED = "allow-added";
31
39
  /** Finding type: a numeric bound or boolean gate moved the weakening way. */
32
40
  const TYPE_WEAKENED = "weakened";
33
41
  /** Finding type: a gate-shrinking exemption was added (Tier 3). */
@@ -44,6 +52,8 @@ const KIND_ALLOW_LIST = "allow-list";
44
52
  * @property {number|string} [base] Baseline value
45
53
  * @property {number|string} [current] Current value
46
54
  * @property {string} message Operator-readable explanation
55
+ * @property {{ file: string, key: string, reason?: unknown, until?: unknown }} [entry]
56
+ * The allow entry an `allow-added` finding is about, as the change wrote it
47
57
  */
48
58
 
49
59
  /**
@@ -254,8 +264,12 @@ function compareK6(relPath, base, current) {
254
264
  }
255
265
 
256
266
  /**
257
- * Compare .lisa.config.json allow lists: report added exception entries so a
258
- * change can never grant itself an exception.
267
+ * Compare .lisa.config.json allow lists: report every added exception entry.
268
+ *
269
+ * The finding says only what was added, and carries the entry. Whether an
270
+ * added entry is accepted or refused is {@link settleAddedExceptions}' call,
271
+ * because that depends on the rest of the change and on the repository's
272
+ * `humanGate.mode`, neither of which this comparison can see.
259
273
  * @param {string} relPath Repo-relative path
260
274
  * @param {unknown} base Parsed baseline config
261
275
  * @param {unknown} current Parsed current config
@@ -271,14 +285,239 @@ function compareAllowList(relPath, base, current) {
271
285
  findings.push({
272
286
  file: relPath,
273
287
  key: `thresholdRatchet.allow ${entry.file}#${entry.key}`,
274
- type: "allow-added",
275
- message: `${relPath}: new threshold exception — ${describeAllowScope(entry)}. Exceptions are a human decision: land this entry in its own human-approved change first, then make the threshold change. It needs a reason saying what resolves it and an "until": "YYYY-MM-DD" naming the day it is reviewed, because an exemption that cannot end is a permanent reduction in what the ratchet covers.`,
288
+ type: TYPE_ALLOW_ADDED,
289
+ message: `${relPath}: new threshold exception — ${describeAllowScope(entry)}.`,
290
+ entry,
276
291
  });
277
292
  }
278
293
  }
279
294
  return findings;
280
295
  }
281
296
 
297
+ /**
298
+ * What an added allow entry still lacks before it can be recorded.
299
+ *
300
+ * An entry needs a reason, so whoever meets it later knows what resolves it,
301
+ * and a day it ends, because an exemption that cannot end is a permanent
302
+ * reduction in what the ratchet covers (#3856). A day already past is refused
303
+ * too: such an entry would be dead on arrival and exempt nothing.
304
+ * @param {{ reason?: unknown, until?: unknown }} entry The entry as written
305
+ * @param {number} now Clock reading
306
+ * @returns {string[]} One clause per gap; empty when the entry is sound
307
+ */
308
+ function addedExceptionGaps(entry, now) {
309
+ const gaps = [];
310
+ if (reasonInWords(entry.reason) === "") {
311
+ gaps.push("it needs a reason saying what resolves it");
312
+ }
313
+ const expiresAt = allowEntryExpiry(entry.until);
314
+ if (expiresAt === undefined) {
315
+ gaps.push(
316
+ 'it needs an "until": "YYYY-MM-DD" day naming when it is reviewed'
317
+ );
318
+ } else if (now >= expiresAt) {
319
+ gaps.push(`its "until" day ${String(entry.until).trim()} has passed`);
320
+ }
321
+ return gaps;
322
+ }
323
+
324
+ /**
325
+ * How many threshold names a hint lists before it stops.
326
+ */
327
+ const HINT_LIMIT = 5;
328
+
329
+ /**
330
+ * The rule an allow entry is matched by, said once for every hint that needs it.
331
+ */
332
+ const COVER_RULE =
333
+ 'An entry covers a threshold only when its "file" is that threshold\'s file (the same path, or the name of a file of that name in a sub-folder) and its "key" is that threshold\'s key or "*".';
334
+
335
+ /**
336
+ * Warn that an entry refused for arriving with a threshold change would not
337
+ * cover that change even once merged.
338
+ *
339
+ * The refusal tells the reader to merge the entry first and then make the
340
+ * threshold change. With a key that names none of the thresholds the change
341
+ * loosens, following that to the letter ends in a second refusal with no
342
+ * explanation, so the mismatch is said here, where the entry is still being
343
+ * written.
344
+ * @param {{ file: string, key: string }} entry The added entry
345
+ * @param {Finding[]} others The other findings in the change
346
+ * @returns {string} A sentence to append, or nothing when the entry covers one
347
+ */
348
+ function keyMismatchNote(entry, others) {
349
+ if (others.some(finding => entryCovers(entry, finding))) return "";
350
+ const names = [...new Set(others.map(f => `${f.file} → ${f.key}`))];
351
+ const listed = names.slice(0, HINT_LIMIT).join("; ");
352
+ const more = names.length > HINT_LIMIT ? "; and more" : "";
353
+ return ` As written it would not cover what this change loosens either: it names ${entry.file} → ${entry.key}, and the thresholds changed here are ${listed}${more}. ${COVER_RULE}`;
354
+ }
355
+
356
+ /**
357
+ * The threshold names the ratchet finds in a file as the change has it.
358
+ *
359
+ * Taken from the comparison itself — every finding it reports when the file
360
+ * is emptied — so the names cannot differ from what an entry is matched
361
+ * against. `*` is left out: it is how an unreadable file reports itself, not
362
+ * a name anybody would write.
363
+ * @param {string} file Repo-relative path
364
+ * @param {string} text The file's text
365
+ * @returns {string[]} Names, in the order the comparison reports them
366
+ */
367
+ function thresholdNamesIn(file, text) {
368
+ return [
369
+ ...new Set(compareFile(file, text, "{}").map(finding => finding.key)),
370
+ ].filter(name => name !== "*");
371
+ }
372
+
373
+ /**
374
+ * Point out a sound, entry-only exception whose key names no threshold the
375
+ * ratchet finds in its file today.
376
+ *
377
+ * An entry is matched by its file and its exact key, and nothing at record
378
+ * time says which threshold it is meant for. A key that is nearly right — the
379
+ * name in the config file instead of the name the ratchet gives the threshold
380
+ * — is recorded, merged, and then covers nothing, and the operator learns of
381
+ * it one merge later. So when the named file can be read, the notice says
382
+ * what the ratchet finds in it.
383
+ *
384
+ * It states an observation and never a prediction. An entry can be right and
385
+ * still name nothing today: a threshold that is added later, a mutation
386
+ * exclusion that does not exist yet, or a file of the same name in a
387
+ * sub-folder, which an entry with a bare file name also matches. Saying such
388
+ * an entry "will cover nothing" would be false.
389
+ *
390
+ * It can never change the verdict. The file name comes from the entry, so a
391
+ * path that leaves the repository is not read, and any failure while reading
392
+ * or comparing — a file too deep to walk, say — yields no note rather than an
393
+ * error from code whose only job is a hint.
394
+ * @param {{ file: string, key: string }} entry The entry being recorded
395
+ * @param {(file: string) => string | null | undefined} readFile Reads a
396
+ * repository file as the change has it
397
+ * @returns {string} A sentence to append to the notice, or nothing
398
+ */
399
+ function unmatchedKeyNote(entry, readFile) {
400
+ const leavesRepository =
401
+ entry.file.startsWith("/") || entry.file.split(/[\\/]/u).includes("..");
402
+ if (entry.key === "*" || leavesRepository || !familyFor(entry.file)) {
403
+ return "";
404
+ }
405
+ try {
406
+ const text = readFile(entry.file);
407
+ if (typeof text !== "string") return "";
408
+ const names = thresholdNamesIn(entry.file, text);
409
+ if (names.length === 0 || names.includes(entry.key)) return "";
410
+ const listed = names
411
+ .slice(0, HINT_LIMIT)
412
+ .map(name => `"${name}"`)
413
+ .join(", ");
414
+ const more = names.length > HINT_LIMIT ? ", and more" : "";
415
+ return ` Check the key: the ratchet finds no threshold named "${entry.key}" in ${entry.file} at the repository root today. The names it finds there are ${listed}${more}. If the entry is meant for one of them, its key must be that name exactly. A threshold added later, a new exclusion, or a file of the same name in a sub-folder is still matched by the entry as written.`;
416
+ } catch {
417
+ return "";
418
+ }
419
+ }
420
+
421
+ /**
422
+ * Decide one added allow entry under the default policy.
423
+ * @param {Finding} finding The `allow-added` finding
424
+ * @param {Finding[]} others Every other ratchet finding in the change
425
+ * @param {number} now Clock reading
426
+ * @param {(file: string) => string | null | undefined} readFile Reads a
427
+ * repository file as the change has it
428
+ * @returns {{ accepted: boolean, message: string }} The verdict and its text:
429
+ * a notice when accepted, the refusal otherwise
430
+ */
431
+ function judgeAddedException(finding, others, now, readFile) {
432
+ const entry = finding.entry ?? {};
433
+ const said = finding.message.replace(/\.$/u, "");
434
+ if (finding.file !== ROOT_CONFIG) {
435
+ return {
436
+ accepted: false,
437
+ message: `${said} — is written in ${finding.file}, and the ratchet reads exceptions from the repository's root ${ROOT_CONFIG} only, so it would never exempt anything. Record it in the root ${ROOT_CONFIG} instead.`,
438
+ };
439
+ }
440
+ const gaps = addedExceptionGaps(entry, now);
441
+ if (gaps.length > 0) {
442
+ return {
443
+ accepted: false,
444
+ message: `${said} — cannot be recorded yet: ${gaps.join(", and ")}. Complete the entry and try again.`,
445
+ };
446
+ }
447
+ if (others.length > 0) {
448
+ return {
449
+ accepted: false,
450
+ message: `${said} — arrives together with another threshold change, and an exception exempts nothing until it is merged. Merge this entry in a change of its own first, then make the threshold change.${keyMismatchNote(entry, others)}`,
451
+ };
452
+ }
453
+ return {
454
+ accepted: true,
455
+ message: `new exception recorded — ${describeAllowScope(entry)}. Reason on record: "${reasonInWords(entry.reason)}". It ends after ${String(entry.until).trim()}. It exempts nothing until this change is merged, so make the threshold change in a later change.${unmatchedKeyNote(entry, readFile)}`,
456
+ };
457
+ }
458
+
459
+ /**
460
+ * Settle the allow entries a change adds: which are recorded, which refused.
461
+ *
462
+ * The fence this keeps is that a change cannot grant itself an exception. The
463
+ * allow list is honoured from the baseline only, so an entry exempts nothing
464
+ * until it is merged — and that ordering does not depend on refusing the
465
+ * change that records the entry. Refusing it anyway left the exception route
466
+ * unusable: the refusal told the reader to land the entry in a change of its
467
+ * own, which was the change being refused (#5099).
468
+ *
469
+ * Under the default `access-only` policy an agent records a risk acceptance
470
+ * and a person can reverse it (#4687), so an added entry is ACCEPTED when it
471
+ * is sound — a reason and a day it ends that has not passed — and the change
472
+ * holds no other ratchet finding. An entry that arrives with any other
473
+ * finding is refused whether or not it would cover that finding: accepting it
474
+ * would be the self-grant, one step removed.
475
+ *
476
+ * Under `strict` an exception stays a person's decision, and nothing here can
477
+ * see that a person approved, so every added entry is refused as it always
478
+ * was.
479
+ * @param {Finding[]} findings Every finding from the change, promotion-carried
480
+ * entries already taken out
481
+ * @param {string} mode The repository's `humanGate.mode`, from the baseline
482
+ * @param {number} [now] Clock reading, injected so the check is deterministic
483
+ * @param {(file: string) => string | null | undefined} [readFile] Reads a
484
+ * repository file as the change has it, so a recorded entry can be checked
485
+ * against the thresholds its file holds; reads nothing by default
486
+ * @returns {{
487
+ * accepted: Array<{ finding: Finding, message: string }>,
488
+ * refused: Finding[],
489
+ * rest: Finding[],
490
+ * }} Entries recorded (with the notice to print), entries refused (with the
491
+ * refusal as their message), and every finding that is not an added entry
492
+ */
493
+ export function settleAddedExceptions(
494
+ findings,
495
+ mode,
496
+ now = Date.now(),
497
+ readFile = () => null
498
+ ) {
499
+ const added = findings.filter(f => f.type === TYPE_ALLOW_ADDED);
500
+ const rest = findings.filter(f => f.type !== TYPE_ALLOW_ADDED);
501
+ if (mode !== HUMAN_GATE_ACCESS_ONLY) {
502
+ return {
503
+ accepted: [],
504
+ refused: added.map(finding => ({
505
+ ...finding,
506
+ message: `${finding.message} Exceptions are a human decision: land this entry in its own human-approved change first, then make the threshold change. It needs a reason saying what resolves it and an "until": "YYYY-MM-DD" naming the day it is reviewed, because an exemption that cannot end is a permanent reduction in what the ratchet covers.`,
507
+ })),
508
+ rest,
509
+ };
510
+ }
511
+ const accepted = [];
512
+ const refused = [];
513
+ for (const finding of added) {
514
+ const verdict = judgeAddedException(finding, rest, now, readFile);
515
+ if (verdict.accepted) accepted.push({ finding, message: verdict.message });
516
+ else refused.push({ ...finding, message: verdict.message });
517
+ }
518
+ return { accepted, refused, rest };
519
+ }
520
+
282
521
  /**
283
522
  * Say a part's folder the way an operator would.
284
523
  * @param {string} scope The part's folder; `.` is the whole repository
@@ -441,7 +680,7 @@ export function compareDeclaredThresholds(
441
680
  type: verdict.type,
442
681
  base: held.value,
443
682
  ...(verdict.current === undefined ? {} : { current: verdict.current }),
444
- message: `${relPath}: the ${held.direction} "${held.name}" of the ${held.gate} gate, for ${folderInWords(held.scope)}, ${verdict.told} If a person decides this loosening is right, they record an exception under thresholdRatchet.allow with "file": "${relPath}" and "key": "${held.key}".`,
683
+ message: `${relPath}: the ${held.direction} "${held.name}" of the ${held.gate} gate, for ${folderInWords(held.scope)}, ${verdict.told} To loosen it on purpose, an exception under thresholdRatchet.allow with "file": "${relPath}" and "key": "${held.key}" has to be merged first.`,
445
684
  });
446
685
  }
447
686
  return findings;
@@ -514,6 +753,58 @@ function compareLighthouse(relPath, base, current) {
514
753
  return findings;
515
754
  }
516
755
 
756
+ /**
757
+ * Whether a config's text literally declares `humanGate.mode: "strict"`.
758
+ * @param {string | null | undefined} text The config's text
759
+ * @returns {boolean} True only for a readable object whose mode, trimmed and
760
+ * lower-cased, is the word `strict`
761
+ */
762
+ function declaresStrict(text) {
763
+ const mode = parseJson(text)?.humanGate?.mode;
764
+ return (
765
+ typeof mode === "string" && mode.trim().toLowerCase() === HUMAN_GATE_STRICT
766
+ );
767
+ }
768
+
769
+ /**
770
+ * Report a root config whose `humanGate.mode` stops being `strict`.
771
+ *
772
+ * Under `strict` a threshold exception is a person's decision, and
773
+ * {@link settleAddedExceptions} refuses every added entry on that ground. The
774
+ * mode is read from the baseline, so a change cannot relax it for itself —
775
+ * but a change that ONLY relaxes it would, once merged, let the next change
776
+ * record an exception with no person involved. A strict repository could be
777
+ * walked down in three ordinary steps without this check ever objecting. So
778
+ * leaving `strict` is itself a loosening, and is reported like one.
779
+ * @param {string} relPath Repo-relative path
780
+ * @param {string} baselineText The config's text at the baseline
781
+ * @param {string | null | undefined} currentText Its text now; nothing when
782
+ * the file was deleted
783
+ * @returns {Finding[]} One finding when the mode left `strict`, else none
784
+ */
785
+ function compareHumanGateMode(relPath, baselineText, currentText) {
786
+ if (relPath !== ROOT_CONFIG) return [];
787
+ // Both sides are judged by whether the file literally DECLARES strict, not
788
+ // by the fail-safe reading used when exceptions are settled. A baseline
789
+ // that reads as strict only because nobody can read it — a misspelt mode, a
790
+ // block that is not an object, a file that does not parse — never said
791
+ // strict, and refusing the change that corrects it would wedge the
792
+ // repository on its own damage with no way through. The current side is
793
+ // held to the same literal reading, so respelling "strict" into something
794
+ // unreadable is reported here rather than slipping past as "still strict".
795
+ if (!declaresStrict(baselineText) || declaresStrict(currentText)) return [];
796
+ return [
797
+ {
798
+ file: relPath,
799
+ key: "humanGate.mode",
800
+ type: TYPE_WEAKENED,
801
+ base: HUMAN_GATE_STRICT,
802
+ current: HUMAN_GATE_ACCESS_ONLY,
803
+ message: `${relPath}: humanGate.mode stops being "strict". Under strict a threshold exception is a person's decision; with this change merged, the next one could be recorded with no person involved. This check cannot see that a person approved it.`,
804
+ },
805
+ ];
806
+ }
807
+
517
808
  /**
518
809
  * Compare one watched file's baseline and current contents and report every
519
810
  * weakening. Pure: no filesystem or git access.
@@ -530,12 +821,15 @@ export function compareFile(relPath, baselineText, currentText) {
530
821
  // Deleting an allow list grants nothing, so that half stays silent. The
531
822
  // thresholds the file declared are another matter: they go with it.
532
823
  if (family.kind === KIND_ALLOW_LIST) {
533
- return compareDeclaredThresholds(
534
- relPath,
535
- parseJson(baselineText),
536
- undefined,
537
- true
538
- );
824
+ return [
825
+ ...compareHumanGateMode(relPath, baselineText, currentText),
826
+ ...compareDeclaredThresholds(
827
+ relPath,
828
+ parseJson(baselineText),
829
+ undefined,
830
+ true
831
+ ),
832
+ ];
539
833
  }
540
834
  return [
541
835
  {
@@ -575,12 +869,15 @@ export function compareFile(relPath, baselineText, currentText) {
575
869
  // block every change touching the file without making anything safer.
576
870
  if (base === undefined) {
577
871
  return family.kind === KIND_ALLOW_LIST
578
- ? []
872
+ ? compareHumanGateMode(relPath, baselineText, currentText)
579
873
  : [unparseableBaseline(relPath)];
580
874
  }
581
875
  if (current === undefined) {
582
876
  return family.kind === KIND_ALLOW_LIST
583
- ? unreadableDeclaration(relPath, base)
877
+ ? [
878
+ ...compareHumanGateMode(relPath, baselineText, currentText),
879
+ ...unreadableDeclaration(relPath, base),
880
+ ]
584
881
  : [unparseable(relPath)];
585
882
  }
586
883
  switch (family.kind) {
@@ -598,6 +895,7 @@ export function compareFile(relPath, baselineText, currentText) {
598
895
  return compareLighthouse(relPath, base, current);
599
896
  case KIND_ALLOW_LIST:
600
897
  return [
898
+ ...compareHumanGateMode(relPath, baselineText, currentText),
601
899
  ...compareAllowList(relPath, base, current),
602
900
  ...compareDeclaredThresholds(relPath, base, current),
603
901
  ];
@@ -644,6 +942,102 @@ export function describeAllowList(allowEntries, now = Date.now()) {
644
942
  return lines;
645
943
  }
646
944
 
945
+ /**
946
+ * One allow entry as a comparable string: its scope, reason and end.
947
+ * @param {{ file: string, key: string, reason?: unknown, until?: unknown }} entry An allow entry
948
+ * @returns {string} A string equal for two entries that say the same thing
949
+ */
950
+ function entryIdentity(entry) {
951
+ return JSON.stringify([
952
+ entry.file,
953
+ entry.key,
954
+ entry.reason ?? null,
955
+ entry.until ?? null,
956
+ ]);
957
+ }
958
+
959
+ /**
960
+ * Split the allow entries on HEAD into those a protected branch already holds
961
+ * and those that exist only on this branch.
962
+ *
963
+ * At commit and at edit the baseline is HEAD, and HEAD is whatever this branch
964
+ * last committed. Once an entry-only change can be committed (#5099), reading
965
+ * the allow list from HEAD alone would let commit one record an exception and
966
+ * commit two use it, with nothing merged — the self-grant, split in two. So in
967
+ * those modes an entry counts only when it is also on a protected branch as
968
+ * the remote last reported it: the same "exempts nothing until it is merged"
969
+ * rule the pull-request check applies by comparing against the base.
970
+ *
971
+ * An entry is the same entry only when its scope, reason and end all match. A
972
+ * local edit to a merged entry — a later `until`, say — is not the merged one.
973
+ * @param {Array<{ file: string, key: string, reason?: unknown, until?: unknown }>} entries
974
+ * The allow list at HEAD
975
+ * @param {Array<Array<{ file: string, key: string, reason?: unknown, until?: unknown }>>} mergedLists
976
+ * The allow list of each protected branch that could be read
977
+ * @returns {{ merged: object[], unmerged: object[] }} Entries a protected
978
+ * branch holds, and entries only this branch holds
979
+ */
980
+ export function splitMergedEntries(entries, mergedLists) {
981
+ const known = new Set(mergedLists.flat().map(entryIdentity));
982
+ return {
983
+ merged: entries.filter(entry => known.has(entryIdentity(entry))),
984
+ unmerged: entries.filter(entry => !known.has(entryIdentity(entry))),
985
+ };
986
+ }
987
+
988
+ /**
989
+ * Say which refused findings an unmerged entry would have covered, so the
990
+ * reader is not left wondering why a recorded exception did nothing.
991
+ * @param {Finding[]} blocked Findings still refused
992
+ * @param {Array<{ file: string, key: string }>} unmerged Entries only this
993
+ * branch holds
994
+ * @param {string[]} refs The protected branches that were consulted; empty
995
+ * when the remote's default branch could not be named
996
+ * @returns {string[]} One line per unmerged entry that covers a refused finding
997
+ */
998
+ export function describeUnmergedCover(blocked, unmerged, refs) {
999
+ const why =
1000
+ refs.length === 0
1001
+ ? `is recorded on this branch, and which branch of the remote named origin is its default could not be determined, so nothing shows the entry is merged and it exempts nothing yet. Run "git fetch origin" and then "git remote set-head origin --auto", and try again.`
1002
+ : `is recorded on this branch but is not on ${refs.join(" or ")}, so it exempts nothing yet. Merge the change that records it first; if it is already merged, run "git fetch" and try again. Only the remote named origin is consulted, and "git remote set-head origin --auto" refreshes which of its branches is the default.`;
1003
+ return unmerged
1004
+ .filter(entry => blocked.some(finding => entryCovers(entry, finding)))
1005
+ .map(entry => `${describeAllowScope(entry)} ${why}`);
1006
+ }
1007
+
1008
+ /**
1009
+ * Explain a refusal that an exception on record looks meant for and misses.
1010
+ *
1011
+ * An entry is matched by its file and its exact key. One written with a key
1012
+ * that is nearly the threshold's — the name in the config file rather than
1013
+ * the name the ratchet gives it, say — is recorded without complaint, because
1014
+ * nothing at that moment says which threshold it is for. The first sign is
1015
+ * the refusal of the threshold change, which without this line reads as if
1016
+ * the exception had been ignored.
1017
+ * @param {Finding[]} blocked Findings still refused
1018
+ * @param {Array<{ file: string, key: string }>} entries Every allow entry on
1019
+ * record for this run, merged or not
1020
+ * @returns {string[]} One line per refused finding that an entry for the same
1021
+ * file names with a different key
1022
+ */
1023
+ export function describeNearMisses(blocked, entries) {
1024
+ const lines = [];
1025
+ for (const finding of blocked) {
1026
+ if (finding.type === TYPE_ALLOW_ADDED) continue;
1027
+ const near = entries.filter(
1028
+ entry =>
1029
+ !entryCovers(entry, finding) &&
1030
+ entryCovers({ file: entry.file, key: "*" }, finding)
1031
+ );
1032
+ if (near.length === 0) continue;
1033
+ const keys = [...new Set(near.map(entry => `"${entry.key}"`))].join(", ");
1034
+ lines.push(
1035
+ `${finding.file}: an exception on record for this file names ${keys}, which is not this threshold's key "${finding.key}", so it does not cover it. ${COVER_RULE}`
1036
+ );
1037
+ }
1038
+ return lines;
1039
+ }
1040
+
647
1041
  /**
648
1042
  * Drop findings covered by a LIVE baseline-side allow entry.
649
1043
  *
@@ -685,7 +1079,7 @@ export function applyAllowList(findings, allowEntries, now = Date.now()) {
685
1079
  const expired = [];
686
1080
  for (const finding of findings) {
687
1081
  const covering =
688
- finding.type === "allow-added"
1082
+ finding.type === TYPE_ALLOW_ADDED
689
1083
  ? []
690
1084
  : classified.filter(c => entryCovers(c.entry, finding));
691
1085
  const live = covering.find(c => c.state !== ALLOW_STATE.EXPIRED);
@@ -711,11 +1105,33 @@ export function applyAllowList(findings, allowEntries, now = Date.now()) {
711
1105
 
712
1106
  /**
713
1107
  * Render the operator-facing block message.
1108
+ *
1109
+ * The closing paragraph names the way to an exception, and it must name one
1110
+ * the check accepts. Under the default policy that is an entry merged in a
1111
+ * change of its own; under `strict` it stays a person's separate change.
714
1112
  * @param {Finding[]} findings Blocked findings
1113
+ * @param {string} [mode] The repository's `humanGate.mode`
715
1114
  * @returns {string} Multi-line report explaining what weakened and the
716
- * human-approved exception path
1115
+ * exception path
717
1116
  */
718
- export function formatReport(findings) {
1117
+ export function formatReport(findings, mode = HUMAN_GATE_ACCESS_ONLY) {
1118
+ const wayOut =
1119
+ mode === HUMAN_GATE_ACCESS_ONLY
1120
+ ? [
1121
+ "gate. If the regression is justified, record an exception in",
1122
+ ".lisa.config.json under thresholdRatchet.allow — with a reason saying",
1123
+ 'what resolves it, and an "until": "YYYY-MM-DD" naming the day it is',
1124
+ "reviewed — and merge it in a change of its own first; this check honors",
1125
+ "an exception only after it is merged, and only until its until date",
1126
+ "passes.",
1127
+ ]
1128
+ : [
1129
+ "gate. If a human decides an exception is genuinely correct, they record it",
1130
+ "in .lisa.config.json under thresholdRatchet.allow — with a reason saying",
1131
+ 'what resolves it, and an "until": "YYYY-MM-DD" naming the day it is',
1132
+ "reviewed — in a separate human-approved change; this check honors an",
1133
+ "exception only after it is merged, and only until its until date passes.",
1134
+ ];
719
1135
  return [
720
1136
  "⛔ Quality gate weakened — blocked by the threshold ratchet.",
721
1137
  "",
@@ -723,10 +1139,6 @@ export function formatReport(findings) {
723
1139
  "",
724
1140
  "Quality thresholds are a one-way ratchet: they may tighten but never",
725
1141
  "loosen. Fix the code so it meets the current gate instead of lowering the",
726
- "gate. If a human decides an exception is genuinely correct, they record it",
727
- "in .lisa.config.json under thresholdRatchet.allow — with a reason saying",
728
- 'what resolves it, and an "until": "YYYY-MM-DD" naming the day it is',
729
- "reviewed — in a separate human-approved change; this check honors an",
730
- "exception only after it is merged, and only until its until date passes.",
1142
+ ...wayOut,
731
1143
  ].join("\n");
732
1144
  }
@@ -575,6 +575,80 @@ export function extractAllowEntries(config) {
575
575
  );
576
576
  }
577
577
 
578
+ /** The `humanGate.mode` under which an agent records a risk acceptance. */
579
+ export const HUMAN_GATE_ACCESS_ONLY = "access-only";
580
+ /** The `humanGate.mode` under which a threshold exception stays a person's. */
581
+ export const HUMAN_GATE_STRICT = "strict";
582
+
583
+ /**
584
+ * The `humanGate.mode` a config declares, as the ratchet reads it.
585
+ *
586
+ * Same rule as `resolveHumanGateMode` in `scripts/human-gate-act.mjs`, written
587
+ * out here because this module ships inside a plugin payload and into host
588
+ * `scripts/` folders, and neither has that script beside it: only an absent
589
+ * mode is the default, `access-only`; a declared value is compared trimmed and
590
+ * lower-cased; and a value that is not a known mode fails safe, to `strict`,
591
+ * so a typo never loosens the gate.
592
+ *
593
+ * The caller passes the BASELINE config, the side the allow list is read from.
594
+ * A change therefore cannot relax the mode and add an exception in one step,
595
+ * and a personal `.lisa.config.local.json` — which no baseline holds — cannot
596
+ * relax it at all.
597
+ * @param {unknown} config Parsed `.lisa.config.json`, or nothing when the
598
+ * baseline has none
599
+ * @returns {"access-only" | "strict"} The mode in force
600
+ */
601
+ export function humanGateModeOf(config) {
602
+ if (!config || typeof config !== "object") return HUMAN_GATE_ACCESS_ONLY;
603
+ const block = config.humanGate;
604
+ if (block === undefined) return HUMAN_GATE_ACCESS_ONLY;
605
+ // A block that is present and is not an object declared something nobody
606
+ // can read. The other resolvers of this key fail safe on it, and so does
607
+ // this one: a malformed block must not read as "nothing declared".
608
+ if (block === null || typeof block !== "object" || Array.isArray(block)) {
609
+ return HUMAN_GATE_STRICT;
610
+ }
611
+ const declared = block.mode;
612
+ if (declared === undefined) return HUMAN_GATE_ACCESS_ONLY;
613
+ const mode =
614
+ typeof declared === "string" ? declared.trim().toLowerCase() : declared;
615
+ return mode === HUMAN_GATE_ACCESS_ONLY
616
+ ? HUMAN_GATE_ACCESS_ONLY
617
+ : HUMAN_GATE_STRICT;
618
+ }
619
+
620
+ /**
621
+ * The `humanGate.mode` of a `.lisa.config.json` given as text.
622
+ *
623
+ * Absent and unreadable are opposite cases and must not be conflated. A
624
+ * repository with no config at the baseline declared nothing, so the default
625
+ * applies. A config that is there and does not parse declared something
626
+ * nobody can read, and that fails safe like any other unreadable declaration.
627
+ * @param {string | null | undefined} text The file's text, or nothing when the
628
+ * baseline has no such file
629
+ * @returns {"access-only" | "strict"} The mode in force
630
+ */
631
+ export function humanGateModeOfText(text) {
632
+ if (text === null || text === undefined) return HUMAN_GATE_ACCESS_ONLY;
633
+ const config = parseJson(text);
634
+ const readable =
635
+ config !== null && typeof config === "object" && !Array.isArray(config);
636
+ return readable ? humanGateModeOf(config) : HUMAN_GATE_STRICT;
637
+ }
638
+
639
+ /**
640
+ * An allow entry's reason as one line of text.
641
+ *
642
+ * A reason is written by whoever records the entry and is printed into the
643
+ * check's own output. Left raw, a line break inside it starts a new line that
644
+ * reads as the check speaking, so every run of whitespace becomes one space.
645
+ * @param {unknown} reason The entry's `reason`
646
+ * @returns {string} The reason on one line; empty when there is none
647
+ */
648
+ export function reasonInWords(reason) {
649
+ return typeof reason === "string" ? reason.replace(/\s+/gu, " ").trim() : "";
650
+ }
651
+
578
652
  /**
579
653
  * The three states an allow entry's expiry condition can be in.
580
654
  *
@@ -670,10 +744,9 @@ export function describeAllowScope(entry) {
670
744
  */
671
745
  export function classifyAllowEntry(entry, now) {
672
746
  const scope = describeAllowScope(entry);
747
+ const reason = reasonInWords(entry.reason);
673
748
  const because =
674
- typeof entry.reason === "string" && entry.reason.trim() !== ""
675
- ? ` Reason on record: ${entry.reason.trim()}`
676
- : " No reason is recorded.";
749
+ reason === "" ? " No reason is recorded." : ` Reason on record: ${reason}`;
677
750
  const expiresAt = allowEntryExpiry(entry.until);
678
751
  if (expiresAt === undefined) {
679
752
  const summary = `names no condition anything can evaluate (until = ${JSON.stringify(entry.until ?? null)})`;
@@ -691,7 +764,7 @@ export function classifyAllowEntry(entry, now) {
691
764
  state: ALLOW_STATE.EXPIRED,
692
765
  scope,
693
766
  summary,
694
- detail: `${scope} ${summary} and no longer exempts anything. Delete it, or record a fresh human-approved entry naming the new condition.${because}`,
767
+ detail: `${scope} ${summary} and no longer exempts anything. Delete it, or record a fresh entry naming the new condition.${because}`,
695
768
  };
696
769
  }
697
770
  const summary = `is live until ${day}`;