@codyswann/lisa 4.96.0 → 4.96.2

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 (90) hide show
  1. package/all/copy-overwrite/scripts/check-third-party-review-evidence.mjs +688 -3
  2. package/dist/configs/vitest/socket-safe-temp-base.d.ts +4 -3
  3. package/dist/configs/vitest/socket-safe-temp-base.d.ts.map +1 -1
  4. package/dist/configs/vitest/socket-safe-temp-base.js +11 -5
  5. package/dist/configs/vitest/socket-safe-temp-base.js.map +1 -1
  6. package/dist/core/lisa-owned-hash-ledger.d.ts.map +1 -1
  7. package/dist/core/lisa-owned-hash-ledger.js +12 -0
  8. package/dist/core/lisa-owned-hash-ledger.js.map +1 -1
  9. package/dist/core/nightly-e2e-guard-behavior-certificate.js +2 -2
  10. package/dist/core/upstream-evidence-manifest.d.ts.map +1 -1
  11. package/dist/core/upstream-evidence-manifest.js +4 -2
  12. package/dist/core/upstream-evidence-manifest.js.map +1 -1
  13. package/package.json +4 -4
  14. package/plugins/lisa/.claude-plugin/plugin.json +1 -1
  15. package/plugins/lisa/.codex-plugin/plugin.json +1 -1
  16. package/plugins/lisa/.codex-plugin/skills/lisa-drive-pr-to-merge/SKILL.md +110 -30
  17. package/plugins/lisa/skills/lisa-drive-pr-to-merge/SKILL.md +110 -30
  18. package/plugins/lisa-agy/plugin.json +1 -1
  19. package/plugins/lisa-agy/skills/lisa-drive-pr-to-merge/SKILL.md +110 -30
  20. package/plugins/lisa-cdk/.claude-plugin/plugin.json +1 -1
  21. package/plugins/lisa-cdk/.codex-plugin/plugin.json +1 -1
  22. package/plugins/lisa-cdk-agy/plugin.json +1 -1
  23. package/plugins/lisa-cdk-copilot/.claude-plugin/plugin.json +1 -1
  24. package/plugins/lisa-cdk-cursor/.claude-plugin/plugin.json +1 -1
  25. package/plugins/lisa-cdk-devin/.claude-plugin/plugin.json +1 -1
  26. package/plugins/lisa-cdk-devin/.devin-plugin/plugin.json +1 -1
  27. package/plugins/lisa-copilot/.claude-plugin/plugin.json +1 -1
  28. package/plugins/lisa-copilot/skills/lisa-drive-pr-to-merge/SKILL.md +110 -30
  29. package/plugins/lisa-cursor/.claude-plugin/plugin.json +1 -1
  30. package/plugins/lisa-cursor/skills/lisa-drive-pr-to-merge/SKILL.md +110 -30
  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/skills/lisa-drive-pr-to-merge/SKILL.md +110 -30
  34. package/plugins/lisa-expo/.claude-plugin/plugin.json +1 -1
  35. package/plugins/lisa-expo/.codex-plugin/plugin.json +1 -1
  36. package/plugins/lisa-expo-agy/plugin.json +1 -1
  37. package/plugins/lisa-expo-copilot/.claude-plugin/plugin.json +1 -1
  38. package/plugins/lisa-expo-cursor/.claude-plugin/plugin.json +1 -1
  39. package/plugins/lisa-expo-devin/.claude-plugin/plugin.json +1 -1
  40. package/plugins/lisa-expo-devin/.devin-plugin/plugin.json +1 -1
  41. package/plugins/lisa-harper-fabric/.claude-plugin/plugin.json +1 -1
  42. package/plugins/lisa-harper-fabric/.codex-plugin/plugin.json +1 -1
  43. package/plugins/lisa-harper-fabric-agy/plugin.json +1 -1
  44. package/plugins/lisa-harper-fabric-copilot/.claude-plugin/plugin.json +1 -1
  45. package/plugins/lisa-harper-fabric-cursor/.claude-plugin/plugin.json +1 -1
  46. package/plugins/lisa-harper-fabric-devin/.claude-plugin/plugin.json +1 -1
  47. package/plugins/lisa-harper-fabric-devin/.devin-plugin/plugin.json +1 -1
  48. package/plugins/lisa-nestjs/.claude-plugin/plugin.json +1 -1
  49. package/plugins/lisa-nestjs/.codex-plugin/plugin.json +1 -1
  50. package/plugins/lisa-nestjs-agy/plugin.json +1 -1
  51. package/plugins/lisa-nestjs-copilot/.claude-plugin/plugin.json +1 -1
  52. package/plugins/lisa-nestjs-cursor/.claude-plugin/plugin.json +1 -1
  53. package/plugins/lisa-nestjs-devin/.claude-plugin/plugin.json +1 -1
  54. package/plugins/lisa-nestjs-devin/.devin-plugin/plugin.json +1 -1
  55. package/plugins/lisa-openclaw/.claude-plugin/plugin.json +1 -1
  56. package/plugins/lisa-openclaw/.codex-plugin/plugin.json +1 -1
  57. package/plugins/lisa-openclaw-agy/plugin.json +1 -1
  58. package/plugins/lisa-openclaw-copilot/.claude-plugin/plugin.json +1 -1
  59. package/plugins/lisa-openclaw-cursor/.claude-plugin/plugin.json +1 -1
  60. package/plugins/lisa-openclaw-devin/.claude-plugin/plugin.json +1 -1
  61. package/plugins/lisa-openclaw-devin/.devin-plugin/plugin.json +1 -1
  62. package/plugins/lisa-phaser/.claude-plugin/plugin.json +1 -1
  63. package/plugins/lisa-phaser/.codex-plugin/plugin.json +1 -1
  64. package/plugins/lisa-phaser-agy/plugin.json +1 -1
  65. package/plugins/lisa-phaser-copilot/.claude-plugin/plugin.json +1 -1
  66. package/plugins/lisa-phaser-cursor/.claude-plugin/plugin.json +1 -1
  67. package/plugins/lisa-phaser-devin/.claude-plugin/plugin.json +1 -1
  68. package/plugins/lisa-phaser-devin/.devin-plugin/plugin.json +1 -1
  69. package/plugins/lisa-rails/.claude-plugin/plugin.json +1 -1
  70. package/plugins/lisa-rails/.codex-plugin/plugin.json +1 -1
  71. package/plugins/lisa-rails-agy/plugin.json +1 -1
  72. package/plugins/lisa-rails-copilot/.claude-plugin/plugin.json +1 -1
  73. package/plugins/lisa-rails-cursor/.claude-plugin/plugin.json +1 -1
  74. package/plugins/lisa-rails-devin/.claude-plugin/plugin.json +1 -1
  75. package/plugins/lisa-rails-devin/.devin-plugin/plugin.json +1 -1
  76. package/plugins/lisa-typescript/.claude-plugin/plugin.json +1 -1
  77. package/plugins/lisa-typescript/.codex-plugin/plugin.json +1 -1
  78. package/plugins/lisa-typescript-agy/plugin.json +1 -1
  79. package/plugins/lisa-typescript-copilot/.claude-plugin/plugin.json +1 -1
  80. package/plugins/lisa-typescript-cursor/.claude-plugin/plugin.json +1 -1
  81. package/plugins/lisa-typescript-devin/.claude-plugin/plugin.json +1 -1
  82. package/plugins/lisa-typescript-devin/.devin-plugin/plugin.json +1 -1
  83. package/plugins/lisa-wiki/.claude-plugin/plugin.json +1 -1
  84. package/plugins/lisa-wiki/.codex-plugin/plugin.json +1 -1
  85. package/plugins/lisa-wiki-agy/plugin.json +1 -1
  86. package/plugins/lisa-wiki-copilot/.claude-plugin/plugin.json +1 -1
  87. package/plugins/lisa-wiki-cursor/.claude-plugin/plugin.json +1 -1
  88. package/plugins/lisa-wiki-devin/.claude-plugin/plugin.json +1 -1
  89. package/plugins/lisa-wiki-devin/.devin-plugin/plugin.json +1 -1
  90. package/plugins/src/base/skills/lisa-drive-pr-to-merge/SKILL.md +110 -30
@@ -121,6 +121,14 @@
121
121
  * CLI:
122
122
  * node scripts/check-third-party-review-evidence.mjs --sha <sha> [--json]
123
123
  * [--context <context>] [--root <dir>] [--repo <owner/repo>]
124
+ * [--arm [--vacuity-report <path>]]
125
+ *
126
+ * `--arm` answers the merge driver's arm gate instead (#4653): whether
127
+ * auto-merge may be turned on for this head, and if not, what to do next.
128
+ * `--vacuity-report` is the saved `check-skipped-required-checks.mjs --vacuity
129
+ * --json` output on hosts that ship that classifier; without it the decision
130
+ * rests on the config-declared reviewer alone, which is every stack's case.
131
+ * Exit 0 means arm; read `arm` and `action`, not the exit code, to know why.
124
132
  *
125
133
  * `--context` names the status context or check-run name that woke the run.
126
134
  * When it is given and belongs to no declared reviewer, the run is an explicit
@@ -130,6 +138,8 @@
130
138
  *
131
139
  * @module scripts/check-third-party-review-evidence
132
140
  */
141
+ import { existsSync, readFileSync } from "node:fs";
142
+
133
143
  import { boundedExecFileSync } from "./lib/bounded-spawn.mjs";
134
144
  import { invokedAsScript } from "./lib/invoked-as-script.mjs";
135
145
  import { EVIDENCE_DEFAULTS, PULL_REQUEST, readGates } from "./lisa-gates.mjs";
@@ -846,6 +856,400 @@ export function reviewEvidenceVerdict({
846
856
  return { outcome: EVIDENCE_OUTCOMES.unsatisfied, sha, readings };
847
857
  }
848
858
 
859
+ /**
860
+ * What the merge driver does after the arm decision (#4653).
861
+ *
862
+ * Only `arm` turns auto-merge on. Every other action leaves it off, and names
863
+ * the next step so the caller never has to re-derive it from a verdict.
864
+ */
865
+ export const ARM_ACTIONS = Object.freeze({
866
+ /** Every engaged signal proved work. Turn auto-merge on. */
867
+ arm: "arm",
868
+ /** Nothing read this head. Post the local adversarial review, then decide again. */
869
+ substitute: "substitute",
870
+ /** Not an answer yet. Do not arm; keep driving. */
871
+ watch: "watch",
872
+ /** A review ran and objected. A real blocker. */
873
+ blocker: "blocker",
874
+ /** A read the decision depends on failed. Stop under the access gate. */
875
+ stop: "stop",
876
+ });
877
+
878
+ /**
879
+ * Classifier violation kinds that say the review context did no work, which a
880
+ * writer's substitute for this head may stand in for.
881
+ */
882
+ const SUBSTITUTABLE_KINDS = new Set([
883
+ "review_evidence_waived",
884
+ "review_evidence_carried_unreviewed",
885
+ "vacuous_required_check",
886
+ "unproven_required_check",
887
+ "absent_required_check",
888
+ ]);
889
+
890
+ /** The classifier's refusal that means it has nothing declared to read. */
891
+ const VACUITY_NONE_DECLARED = "vacuity_none_declared";
892
+
893
+ /** The proof phrase that proves work was done AND that the work objected. */
894
+ const OBJECTING_PROOF = normalizeDescription("Changes requested");
895
+
896
+ /** Which non-arm action wins when signals disagree; earlier wins. */
897
+ const ACTION_PRIORITY = [
898
+ ARM_ACTIONS.stop,
899
+ ARM_ACTIONS.blocker,
900
+ ARM_ACTIONS.watch,
901
+ ARM_ACTIONS.substitute,
902
+ ];
903
+
904
+ /**
905
+ * One signal's answer.
906
+ * @param {string} action - One of {@link ARM_ACTIONS}.
907
+ * @param {string} reason - Why, in an operator's words.
908
+ * @returns {{engaged: boolean, action: string, reason: string, viaSubstitute?: boolean}} The signal.
909
+ */
910
+ const engagedSignal = (action, reason) => ({ engaged: true, action, reason });
911
+
912
+ /** A signal that has nothing declared to read. */
913
+ const NOT_ENGAGED = Object.freeze({
914
+ engaged: false,
915
+ action: ARM_ACTIONS.arm,
916
+ reason: "",
917
+ });
918
+
919
+ /**
920
+ * Whether every given context has a writer's first-line substitute at this head.
921
+ * @param {ReadonlyArray<string>} contexts - Contexts that showed no review.
922
+ * @param {ReadonlySet<string>} substitutes - Contexts a writer substituted for.
923
+ * @returns {boolean} True only when there is something to cover and all of it is.
924
+ */
925
+ const allSubstituted = (contexts, substitutes) =>
926
+ contexts.length > 0 && contexts.every(context => substitutes.has(context));
927
+
928
+ /**
929
+ * What the config-declared reviewer says about arming.
930
+ *
931
+ * The prover's own `substituted` outcome counts a marker ANYWHERE in ANY
932
+ * comment, which is right for the response arm and wrong here: arming turns a
933
+ * blocking verdict into a merge, so a substitute counts only as the first line
934
+ * of a comment by someone with write access — the classifier's rule, for the
935
+ * same reason. A `Changes requested` proof proves the reviewer worked, not that
936
+ * the head may merge.
937
+ * @param {{outcome: string, readings?: ReadonlyArray<{context: string, reviewed: boolean, observed?: string|null}>}} evidence - This prover's verdict.
938
+ * @param {ReadonlySet<string>} substitutes - Contexts a writer substituted for at this head.
939
+ * @returns {{engaged: boolean, action: string, reason: string, viaSubstitute?: boolean}} The signal.
940
+ */
941
+ function evidenceSignal(evidence, substitutes) {
942
+ const readings = evidence.readings ?? [];
943
+ const unreviewed = readings
944
+ .filter(reading => !reading.reviewed)
945
+ .map(reading => reading.context);
946
+ if (evidence.outcome === EVIDENCE_OUTCOMES.noReviewerConfigured) {
947
+ return NOT_ENGAGED;
948
+ }
949
+ if (evidence.outcome === EVIDENCE_OUTCOMES.pullRequestsUnreadable) {
950
+ return engagedSignal(
951
+ ARM_ACTIONS.stop,
952
+ "the pull requests could not be read, so the review is unknown"
953
+ );
954
+ }
955
+ // Under EVERY outcome, not only `satisfied`: one reviewer's objection is
956
+ // not cancelled by another reviewer's substitute.
957
+ if (
958
+ readings.some(
959
+ reading => normalizeDescription(reading.observed) === OBJECTING_PROOF
960
+ )
961
+ ) {
962
+ return engagedSignal(
963
+ ARM_ACTIONS.blocker,
964
+ "a configured reviewer requested changes"
965
+ );
966
+ }
967
+ // A substitute never stands in for a review still in flight: armed now, the
968
+ // latch would merge on whatever that review concludes, objection included.
969
+ if (readings.some(reading => reading.reading === EVIDENCE_READINGS.pending)) {
970
+ return engagedSignal(
971
+ ARM_ACTIONS.watch,
972
+ "a configured reviewer is still running"
973
+ );
974
+ }
975
+ switch (evidence.outcome) {
976
+ case EVIDENCE_OUTCOMES.satisfied:
977
+ return engagedSignal(
978
+ ARM_ACTIONS.arm,
979
+ "every configured reviewer showed its reviewed-when evidence"
980
+ );
981
+ case EVIDENCE_OUTCOMES.substituted:
982
+ case EVIDENCE_OUTCOMES.unsatisfied:
983
+ return allSubstituted(unreviewed, substitutes)
984
+ ? {
985
+ ...engagedSignal(
986
+ ARM_ACTIONS.arm,
987
+ "a writer's first-line substitute review is posted for this head"
988
+ ),
989
+ viaSubstitute: true,
990
+ }
991
+ : engagedSignal(
992
+ ARM_ACTIONS.substitute,
993
+ "a configured reviewer showed no evidence it read this head, and no writer's first-line substitute stands in for it"
994
+ );
995
+ default:
996
+ return engagedSignal(
997
+ ARM_ACTIONS.watch,
998
+ `the reviewer evidence is not an answer yet (${evidence.outcome})`
999
+ );
1000
+ }
1001
+ }
1002
+
1003
+ /**
1004
+ * The action one classifier violation calls for, or null when it says nothing
1005
+ * about the review context.
1006
+ * @param {{kind?: string, condition?: string, contexts?: string[]}} violation - One violation.
1007
+ * @param {ReadonlySet<string>} substitutes - Contexts a writer substituted for at this head.
1008
+ * @param {ReadonlySet<string>|null} reviewContexts - The classifier's review contexts; null when unknown.
1009
+ * @returns {string|null} One of {@link ARM_ACTIONS}, or null.
1010
+ */
1011
+ function violationAction(violation, substitutes, reviewContexts) {
1012
+ const kind = String(violation?.kind ?? "");
1013
+ const named = violationContexts(violation);
1014
+ // vacuous / unproven / absent name ANY required check, a CI job included.
1015
+ // Only a review context's absence is a review signal; a CI job that has not
1016
+ // reported yet is GitHub's to wait for, and the latch already does.
1017
+ if (
1018
+ !kind.startsWith("review_evidence_") &&
1019
+ reviewContexts !== null &&
1020
+ !named.some(name => reviewContexts.has(name))
1021
+ ) {
1022
+ return null;
1023
+ }
1024
+ const condition = String(violation?.condition ?? "");
1025
+ if (kind === "review_evidence_objected") return ARM_ACTIONS.blocker;
1026
+ if (kind === "review_evidence_objection_unread") return ARM_ACTIONS.stop;
1027
+ if (kind === "review_evidence_unsatisfied" && condition === "objected") {
1028
+ return ARM_ACTIONS.blocker;
1029
+ }
1030
+ if (kind === "review_evidence_unsatisfied" && condition === "pending") {
1031
+ return ARM_ACTIONS.watch;
1032
+ }
1033
+ const substitutable =
1034
+ SUBSTITUTABLE_KINDS.has(kind) || kind === "review_evidence_unsatisfied";
1035
+ // A review kind this file does not know — a newer classifier's — is not
1036
+ // evidence of work. Fail closed rather than read it as silence.
1037
+ if (!substitutable) {
1038
+ return kind.startsWith("review_evidence_") ? ARM_ACTIONS.watch : null;
1039
+ }
1040
+ return allSubstituted(
1041
+ reviewContexts === null
1042
+ ? named
1043
+ : named.filter(name => reviewContexts.has(name)),
1044
+ substitutes
1045
+ )
1046
+ ? null
1047
+ : ARM_ACTIONS.substitute;
1048
+ }
1049
+
1050
+ /**
1051
+ * The check names one classifier violation is about.
1052
+ * @param {{contexts?: unknown, token?: unknown}} violation - One violation.
1053
+ * @returns {string[]} Its contexts, else its token, else nothing.
1054
+ */
1055
+ function violationContexts(violation) {
1056
+ if (Array.isArray(violation?.contexts) && violation.contexts.length > 0) {
1057
+ return violation.contexts.map(String);
1058
+ }
1059
+ return typeof violation?.token === "string" ? [violation.token] : [];
1060
+ }
1061
+
1062
+ /**
1063
+ * The review contexts the classifier judged, or null when it did not say.
1064
+ *
1065
+ * Null fails closed: every vacuous, unproven or absent check is then read as a
1066
+ * possible review context.
1067
+ * @param {any} report - The classifier report.
1068
+ * @returns {Set<string>|null} The evidence-bearing check names.
1069
+ */
1070
+ function reviewContextsOf(report) {
1071
+ const states = report?.vacuity?.gateStates;
1072
+ return states && typeof states === "object" && Object.keys(states).length > 0
1073
+ ? new Set(Object.keys(states))
1074
+ : null;
1075
+ }
1076
+
1077
+ /**
1078
+ * What the vacuity classifier says about arming, where a host ships one.
1079
+ *
1080
+ * An allowlist: it proves work only when it inspected, trusted its own
1081
+ * declaration, read THIS head, and found nothing wrong with the review context.
1082
+ * @param {object|null} vacuity - `check-skipped-required-checks.mjs --vacuity --json` output, or null.
1083
+ * @param {{sha: string, substitutes: ReadonlySet<string>, classifierDeclared: boolean}} context - The head and what else is known.
1084
+ * @returns {{engaged: boolean, action: string, reason: string, viaSubstitute?: boolean}} The signal.
1085
+ */
1086
+ function vacuitySignal(vacuity, { sha, substitutes, classifierDeclared }) {
1087
+ const report = /** @type {any} */ (vacuity);
1088
+ if (report === null || report === undefined) {
1089
+ return classifierDeclared
1090
+ ? engagedSignal(
1091
+ ARM_ACTIONS.watch,
1092
+ ".github/required-checks.json declares an evidence-bearing check, but no --vacuity-report was passed"
1093
+ )
1094
+ : NOT_ENGAGED;
1095
+ }
1096
+ const refusal = report.vacuity?.refusal?.kind ?? report.refusal?.kind ?? null;
1097
+ if (refusal === VACUITY_NONE_DECLARED) {
1098
+ return classifierDeclared
1099
+ ? engagedSignal(
1100
+ ARM_ACTIONS.watch,
1101
+ "the vacuity report says nothing is declared, but .github/required-checks.json declares an evidence-bearing check"
1102
+ )
1103
+ : NOT_ENGAGED;
1104
+ }
1105
+ if (report.inspected !== true || report.answered === false) {
1106
+ return engagedSignal(
1107
+ ARM_ACTIONS.watch,
1108
+ `the vacuity classifier did not answer (${refusal ?? "uninspected"}); an empty inspection is not a pass`
1109
+ );
1110
+ }
1111
+ const reportSha = report.vacuity?.headSha ?? report.headSha ?? null;
1112
+ if (reportSha !== sha) {
1113
+ return engagedSignal(
1114
+ ARM_ACTIONS.watch,
1115
+ `the vacuity report is for ${reportSha ?? "an unnamed head"}, not ${sha}`
1116
+ );
1117
+ }
1118
+ const reviewContexts = reviewContextsOf(report);
1119
+ const violations = [
1120
+ ...(report.violations ?? []),
1121
+ ...(report.vacuity?.violations ?? []),
1122
+ ];
1123
+ const actions = violations
1124
+ .map(violation => violationAction(violation, substitutes, reviewContexts))
1125
+ .filter(action => action !== null);
1126
+ if (actions.length === 0) {
1127
+ // Clean only because a substitute covered it: the arm is head-scoped.
1128
+ const viaSubstitute = violations.some(
1129
+ violation =>
1130
+ violationAction(violation, new Set(), reviewContexts) ===
1131
+ ARM_ACTIONS.substitute
1132
+ );
1133
+ return {
1134
+ ...engagedSignal(
1135
+ ARM_ACTIONS.arm,
1136
+ viaSubstitute
1137
+ ? "a writer's substitute covers the declared review check at this head"
1138
+ : "the declared review check did work at this head"
1139
+ ),
1140
+ viaSubstitute,
1141
+ };
1142
+ }
1143
+ const [first] = [...actions].sort(byPriority);
1144
+ return engagedSignal(first, "the declared review check did not prove work");
1145
+ }
1146
+
1147
+ /**
1148
+ * Order actions so the most serious comes first.
1149
+ * @param {string} left - An action.
1150
+ * @param {string} right - An action.
1151
+ * @returns {number} Sort order.
1152
+ */
1153
+ const byPriority = (left, right) =>
1154
+ ACTION_PRIORITY.indexOf(left) - ACTION_PRIORITY.indexOf(right);
1155
+
1156
+ /**
1157
+ * Decide whether auto-merge may be armed (#4653).
1158
+ *
1159
+ * The gate engages on EITHER declaration: a reviewer in `.lisa.config.json`
1160
+ * (this prover, which ships to every stack), or an evidence-bearing check in
1161
+ * `.github/required-checks.json` (the vacuity classifier, which ships only to
1162
+ * TypeScript-family hosts). Keying it to the second alone left every other
1163
+ * stack arming against a rate-limited `neutral` check run. Arming requires
1164
+ * every engaged signal to say arm; with neither engaged there is no review
1165
+ * context to protect, and arming is unchanged. A standing objection at the
1166
+ * head blocks whatever the signals say.
1167
+ * @param {object} options - Decision inputs.
1168
+ * @param {{outcome: string, sha?: string, readings?: ReadonlyArray<object>}} options.evidence - This prover's verdict for the head.
1169
+ * @param {object|null} [options.vacuity] - The vacuity classifier's JSON report, or null.
1170
+ * @param {string} [options.sha] - The head commit being decided.
1171
+ * @param {ReadonlySet<string>} [options.substitutes] - Contexts a writer posted a first-line substitute for at this head.
1172
+ * @param {number|null} [options.objections] - `CHANGES_REQUESTED` reviews at this head; null when they could not be read.
1173
+ * @param {boolean} [options.classifierDeclared] - Whether `required-checks.json` declares an evidence-bearing check.
1174
+ * @param {boolean} [options.projectRoot] - Whether the root read has a `.lisa.config.json`; false means the declarations were never seen.
1175
+ * @returns {{arm: boolean, action: string, reason: string, engaged: {reviewer: boolean, vacuity: boolean}, basis?: "review"|"substitute"|"none"}} The decision; `basis` is set only when arming.
1176
+ */
1177
+ export function armDecision({
1178
+ evidence,
1179
+ vacuity = null,
1180
+ sha = evidence.sha,
1181
+ substitutes = new Set(),
1182
+ objections = 0,
1183
+ classifierDeclared = false,
1184
+ projectRoot = true,
1185
+ }) {
1186
+ // An empty declaration read from the wrong directory looks exactly like a
1187
+ // project that declares nothing, which is the one case that arms.
1188
+ if (!projectRoot) {
1189
+ return {
1190
+ arm: false,
1191
+ action: ARM_ACTIONS.stop,
1192
+ reason:
1193
+ "no .lisa.config.json at --root, so the reviewer declarations were never read; run from the project root",
1194
+ engaged: { reviewer: false, vacuity: false },
1195
+ };
1196
+ }
1197
+ const reviewer = evidenceSignal(evidence, substitutes);
1198
+ const classifier = vacuitySignal(vacuity, {
1199
+ sha,
1200
+ substitutes,
1201
+ classifierDeclared,
1202
+ });
1203
+ const engaged = { reviewer: reviewer.engaged, vacuity: classifier.engaged };
1204
+ const reviewEngaged = reviewer.engaged || classifier.engaged;
1205
+ const standing =
1206
+ objections === null && reviewEngaged
1207
+ ? engagedSignal(
1208
+ ARM_ACTIONS.stop,
1209
+ "the reviews on this pull request could not be read, or the repository is unknown"
1210
+ )
1211
+ : (objections ?? 0) > 0
1212
+ ? engagedSignal(
1213
+ ARM_ACTIONS.blocker,
1214
+ "a review requested changes and has not been approved or dismissed since"
1215
+ )
1216
+ : NOT_ENGAGED;
1217
+ const signals = [standing, reviewer, classifier];
1218
+ const held = signals.filter(
1219
+ signal => signal.engaged && signal.action !== ARM_ACTIONS.arm
1220
+ );
1221
+ if (held.length === 0) {
1222
+ const proving = signals.filter(signal => signal.engaged);
1223
+ // `substitute` means the latch is authorised for THIS head only: a push
1224
+ // makes a new head that no substitute covers, so the caller must disarm
1225
+ // before pushing and decide again afterwards.
1226
+ const basis = proving.some(signal => signal.viaSubstitute === true)
1227
+ ? "substitute"
1228
+ : proving.length === 0
1229
+ ? "none"
1230
+ : "review";
1231
+ return {
1232
+ arm: true,
1233
+ action: ARM_ACTIONS.arm,
1234
+ basis,
1235
+ reason:
1236
+ proving.length === 0
1237
+ ? "no review context is declared anywhere; nothing to withhold the latch from"
1238
+ : proving.map(signal => signal.reason).join("; "),
1239
+ engaged,
1240
+ };
1241
+ }
1242
+ const [first] = [...held].sort((left, right) =>
1243
+ byPriority(left.action, right.action)
1244
+ );
1245
+ return {
1246
+ arm: false,
1247
+ action: first.action,
1248
+ reason: held.map(signal => signal.reason).join("; "),
1249
+ engaged,
1250
+ };
1251
+ }
1252
+
849
1253
  /**
850
1254
  * A reading as the report prints it.
851
1255
  * @typedef {object} ReportedReading
@@ -942,7 +1346,7 @@ function describeSeen(reading) {
942
1346
  /**
943
1347
  * Parse the CLI arguments.
944
1348
  * @param {string[]} argv - Arguments after the script path.
945
- * @returns {{sha: string|null, context: string|null, root: string, repo: string|null, json: boolean}} Options.
1349
+ * @returns {{sha: string|null, context: string|null, root: string, repo: string|null, json: boolean, arm: boolean, "vacuity-report": string|null}} Options.
946
1350
  */
947
1351
  export function parseArgs(argv) {
948
1352
  const opts = {
@@ -951,11 +1355,13 @@ export function parseArgs(argv) {
951
1355
  root: process.cwd(),
952
1356
  repo: null,
953
1357
  json: false,
1358
+ arm: false,
1359
+ "vacuity-report": null,
954
1360
  };
955
1361
  for (let index = 0; index < argv.length; index += 1) {
956
1362
  const arg = argv[index];
957
- if (arg === "--json") {
958
- opts.json = true;
1363
+ if (arg === "--json" || arg === "--arm") {
1364
+ opts[arg.slice(2)] = true;
959
1365
  continue;
960
1366
  }
961
1367
  const [flag, inline] = arg.startsWith("--") ? splitFlag(arg) : [null, null];
@@ -1135,6 +1541,278 @@ function checkRunsByContext(reviewers, sha, read) {
1135
1541
  return runs;
1136
1542
  }
1137
1543
 
1544
+ /** Repository permissions whose holder may stand in for a reviewer. */
1545
+ const SUBSTITUTE_WRITER_PERMISSIONS = new Set(["admin", "maintain", "write"]);
1546
+
1547
+ /** A substitute marker as a comment's whole first line. */
1548
+ const FIRST_LINE_MARKER = new RegExp(
1549
+ `^<!-- ${SUBSTITUTE_MARKER} context="([^"]+)" head="([^"]+)" -->$`,
1550
+ "u"
1551
+ );
1552
+
1553
+ /**
1554
+ * Whether a login holds write access to the repository.
1555
+ *
1556
+ * probe-direction: fail-closed — any failure to read the permission answers
1557
+ * `false`, which can only leave a substitute uncounted, never count one. A bot author such as
1558
+ * `github-actions[bot]` is not a collaborator and never counts.
1559
+ * @param {string} repo - `owner/repo`.
1560
+ * @param {string} login - The comment author.
1561
+ * @returns {boolean} Whether the login may stand in for a reviewer.
1562
+ */
1563
+ function fetchWritePermission(repo, login) {
1564
+ if (!/^[A-Za-z0-9-]+$/u.test(login)) return false;
1565
+ try {
1566
+ const permission = boundedExecFileSync(
1567
+ "gh",
1568
+ [
1569
+ "api",
1570
+ `repos/${repo}/collaborators/${encodeURIComponent(login)}/permission`,
1571
+ "--jq",
1572
+ ".permission",
1573
+ ],
1574
+ { encoding: "utf8" }
1575
+ ).trim();
1576
+ return SUBSTITUTE_WRITER_PERMISSIONS.has(permission);
1577
+ } catch {
1578
+ return false;
1579
+ }
1580
+ }
1581
+
1582
+ /**
1583
+ * The contexts a writer posted a first-line substitute for at this head.
1584
+ *
1585
+ * Stricter than the response arm on purpose, because here a match arms a
1586
+ * merge: the marker must be the comment's FIRST LINE (a comment that quotes
1587
+ * it is not a review), and the author must hold write access (anyone who can
1588
+ * comment can type the marker).
1589
+ * @param {ReadonlyArray<{body?: string, user?: {login?: string}}>} comments - Pull request comments.
1590
+ * @param {string} sha - The head commit.
1591
+ * @param {(login: string) => boolean} canWrite - Whether a login holds write access.
1592
+ * @returns {Set<string>} The substituted contexts.
1593
+ */
1594
+ export function writerSubstitutes(comments, sha, canWrite) {
1595
+ const found = new Set();
1596
+ const seen = new Map();
1597
+ const writer = login => {
1598
+ if (!seen.has(login)) seen.set(login, canWrite(login) === true);
1599
+ return seen.get(login);
1600
+ };
1601
+ for (const comment of comments ?? []) {
1602
+ const firstLine = String(comment?.body ?? "")
1603
+ .split("\n")[0]
1604
+ .replace(/\r$/u, "");
1605
+ const match = FIRST_LINE_MARKER.exec(firstLine);
1606
+ if (match === null || match[2] !== sha) continue;
1607
+ if (writer(String(comment?.user?.login ?? ""))) found.add(match[1]);
1608
+ }
1609
+ return found;
1610
+ }
1611
+
1612
+ /**
1613
+ * Standing `CHANGES_REQUESTED` reviews, latest decisive review per author.
1614
+ *
1615
+ * Across EVERY commit, not only the head: a change request stands until its
1616
+ * author approves or it is dismissed, and a later push clears neither. Reading
1617
+ * only the head would let a push arm the latch over an objection nobody
1618
+ * addressed. A dismissed review reads as a comment, so it never counts.
1619
+ * @param {ReadonlyArray<{commit_id?: string, state?: string, submitted_at?: string, user?: {login?: string}}>|null} reviews - Review objects; null when the read failed.
1620
+ * @returns {number|null} The count, or null when the reviews could not be read.
1621
+ */
1622
+ export function standingObjections(reviews) {
1623
+ if (reviews === null) return null;
1624
+ const latest = new Map();
1625
+ [...reviews]
1626
+ .sort((left, right) =>
1627
+ String(left?.submitted_at ?? "").localeCompare(
1628
+ String(right?.submitted_at ?? "")
1629
+ )
1630
+ )
1631
+ .forEach((review, index) => {
1632
+ const author = String(review?.user?.login ?? `#${index}`);
1633
+ if (classifyReviewObject(review) !== REVIEW_OBJECT_VERDICTS.comment) {
1634
+ latest.set(author, review);
1635
+ }
1636
+ });
1637
+ return [...latest.values()].filter(
1638
+ review => classifyReviewObject(review) === REVIEW_OBJECT_VERDICTS.objection
1639
+ ).length;
1640
+ }
1641
+
1642
+ /**
1643
+ * Every issue comment on the given pull requests, across all pages.
1644
+ *
1645
+ * A writer's substitute for the current head is among the NEWEST comments, so
1646
+ * a single page of a long pull request is exactly the one that misses it.
1647
+ * @param {string} repo - `owner/repo`.
1648
+ * @param {number[]} numbers - Pull request numbers.
1649
+ * @returns {ReadonlyArray<object>} The comments; a failed page reads as none, which only leaves a substitute uncounted.
1650
+ */
1651
+ function readAllComments(repo, numbers) {
1652
+ return numbers.flatMap(
1653
+ number =>
1654
+ readAllPages(`repos/${repo}/issues/${number}/comments?per_page=100`) ?? []
1655
+ );
1656
+ }
1657
+
1658
+ /**
1659
+ * Review objects on the given pull requests; null when any read failed.
1660
+ * @param {string} repo - `owner/repo`.
1661
+ * @param {number[]} numbers - Pull request numbers.
1662
+ * @returns {ReadonlyArray<object>|null} The reviews.
1663
+ */
1664
+ function readReviews(repo, numbers) {
1665
+ const lists = numbers.map(number => readAllReviews(repo, number));
1666
+ return lists.every(Array.isArray) ? lists.flat() : null;
1667
+ }
1668
+
1669
+ /**
1670
+ * Every review on one pull request, across all pages.
1671
+ *
1672
+ * The reviews at the current head are the NEWEST, so a single page of a long
1673
+ * pull request is exactly the one that leaves them out.
1674
+ * @param {string} repo - `owner/repo`.
1675
+ * @param {number} number - Pull request number.
1676
+ * @returns {ReadonlyArray<object>|null} The reviews, or null when any page failed.
1677
+ */
1678
+ function readAllReviews(repo, number) {
1679
+ return readAllPages(`repos/${repo}/pulls/${number}/reviews?per_page=100`);
1680
+ }
1681
+
1682
+ /**
1683
+ * Every row of one paginated list endpoint.
1684
+ * @param {string} path - The API path.
1685
+ * @returns {ReadonlyArray<object>|null} The rows, or null when any page failed.
1686
+ */
1687
+ function readAllPages(path) {
1688
+ // probe-direction: fail-closed — a failed read is null; reviews then stop the arm decision, and comments then count no substitute.
1689
+ try {
1690
+ const pages = JSON.parse(
1691
+ boundedExecFileSync("gh", ["api", "--paginate", "--slurp", path], {
1692
+ encoding: "utf8",
1693
+ })
1694
+ );
1695
+ return Array.isArray(pages) && pages.every(Array.isArray)
1696
+ ? pages.flat()
1697
+ : null;
1698
+ } catch {
1699
+ return null;
1700
+ }
1701
+ }
1702
+
1703
+ /**
1704
+ * Whether `.github/required-checks.json` declares an evidence-bearing check.
1705
+ *
1706
+ * probe-direction: fail-closed — only a file that does not exist answers
1707
+ * "not declared". A file that exists but cannot be read, or does not parse,
1708
+ * counts as declared: the caller then needs the classifier's report, which
1709
+ * holds the latch off rather than arming past it.
1710
+ * @param {string} root - The project root.
1711
+ * @param {(path: string) => string} read - File reader.
1712
+ * @returns {boolean} Whether the classifier has something declared to read.
1713
+ */
1714
+ function declaresEvidenceBearingChecks(root, read) {
1715
+ let text;
1716
+ try {
1717
+ text = read(`${root}/.github/required-checks.json`);
1718
+ } catch (error) {
1719
+ // probe-direction: fail-closed — anything but ENOENT counts as declared.
1720
+ return /** @type {{code?: string}} */ (error)?.code !== "ENOENT";
1721
+ }
1722
+ // probe-direction: fail-closed — a file that does not parse counts as declared.
1723
+ try {
1724
+ const checks = JSON.parse(text)?.evidence_bearing_checks;
1725
+ if (checks === undefined || checks === null) return false;
1726
+ return Array.isArray(checks)
1727
+ ? checks.length > 0
1728
+ : Object.keys(checks).length > 0;
1729
+ } catch {
1730
+ return true;
1731
+ }
1732
+ }
1733
+
1734
+ /**
1735
+ * The vacuity classifier's saved report, when the caller passed one.
1736
+ *
1737
+ * A path that cannot be read or parsed is NOT "no classifier": the caller said
1738
+ * one exists, so it is reported as an inspection that read nothing.
1739
+ * @param {string|null} path - `--vacuity-report`, or null.
1740
+ * @param {(path: string) => string} read - File reader.
1741
+ * @returns {object|null} The parsed report, null when none was passed.
1742
+ */
1743
+ function loadVacuityReport(path, read) {
1744
+ if (path === null) return null;
1745
+ // probe-direction: fail-closed — an unreadable report is an empty inspection, never a pass.
1746
+ try {
1747
+ return JSON.parse(read(path));
1748
+ } catch {
1749
+ return {
1750
+ inspected: false,
1751
+ vacuity: { refusal: { kind: "vacuity_report_unreadable" } },
1752
+ };
1753
+ }
1754
+ }
1755
+
1756
+ /**
1757
+ * Write the `--arm` decision and return its exit code: 0 to arm, 1 otherwise.
1758
+ * @param {{outcome: string, sha: string}} verdict - This prover's verdict.
1759
+ * @param {object} context - What the CLI already resolved.
1760
+ * @param {{json: boolean, root: string, "vacuity-report": string|null}} context.opts - Parsed options.
1761
+ * @param {object} context.io - Injected side effects.
1762
+ * @param {{write: (text: string) => void}} context.out - Stdout.
1763
+ * @param {string} context.repo - `owner/repo`, possibly empty.
1764
+ * @param {number[]|null|undefined} context.pulls - Head pull requests already read, if any.
1765
+ * @returns {number} The exit code.
1766
+ */
1767
+ function writeArmDecision(verdict, { opts, io, out, repo, pulls }) {
1768
+ const readFile = io.readFile ?? (path => readFileSync(path, "utf8"));
1769
+ const validRepo = /^[^/\s]+\/[^/\s]+$/u.test(repo);
1770
+ const numbers =
1771
+ Array.isArray(pulls) && pulls.length > 0
1772
+ ? pulls
1773
+ : validRepo
1774
+ ? (io.pulls ?? (sha => readHeadPulls(repo, sha)))(verdict.sha)
1775
+ : [];
1776
+ const heads = numbers ?? [];
1777
+ const comments =
1778
+ heads.length === 0
1779
+ ? []
1780
+ : (io.comments ?? (list => readAllComments(repo, list)))(heads);
1781
+ // An unknown repository is an unread review surface, never an empty one.
1782
+ const reviews =
1783
+ numbers === null || !validRepo
1784
+ ? null
1785
+ : heads.length === 0
1786
+ ? []
1787
+ : (io.reviews ?? (list => readReviews(repo, list)))(heads);
1788
+ const canWrite =
1789
+ io.canWrite ??
1790
+ (login => (validRepo ? fetchWritePermission(repo, login) : false));
1791
+ const decision = armDecision({
1792
+ evidence: verdict,
1793
+ vacuity: loadVacuityReport(opts["vacuity-report"], readFile),
1794
+ sha: verdict.sha,
1795
+ substitutes: writerSubstitutes(comments, verdict.sha, canWrite),
1796
+ objections: standingObjections(reviews),
1797
+ classifierDeclared: (
1798
+ io.requiredChecks ??
1799
+ (() => declaresEvidenceBearingChecks(opts.root, readFile))
1800
+ )(),
1801
+ // Injected gates stand for a project the caller already read.
1802
+ projectRoot:
1803
+ io.gates !== undefined || existsSync(`${opts.root}/.lisa.config.json`),
1804
+ });
1805
+ const report = { ...decision, evidence: verdict };
1806
+ const held = `DO NOT ARM — ${decision.action}`;
1807
+ const headline = decision.arm ? "ARM" : held;
1808
+ out.write(
1809
+ opts.json
1810
+ ? `${JSON.stringify(report, null, 2)}\n`
1811
+ : `${headline}: ${decision.reason}\n${humanReport(verdict)}\n`
1812
+ );
1813
+ return decision.arm ? 0 : 1;
1814
+ }
1815
+
1138
1816
  /**
1139
1817
  * The CLI body.
1140
1818
  * @param {string[]} argv - Arguments after the script path.
@@ -1148,6 +1826,10 @@ function checkRunsByContext(reviewers, sha, read) {
1148
1826
  * means the caller supplies the evidence, and mixing a live read into it
1149
1827
  * would judge a fixture against the network.
1150
1828
  * @param {(numbers: number[]) => ReadonlyArray<object>} [io.comments] - Comment reader.
1829
+ * @param {(path: string) => string} [io.readFile] - Reader for `--vacuity-report` and `required-checks.json`.
1830
+ * @param {(numbers: number[]) => ReadonlyArray<object>|null} [io.reviews] - Review-object reader, `--arm` only.
1831
+ * @param {(login: string) => boolean} [io.canWrite] - Write-permission reader, `--arm` only.
1832
+ * @param {() => boolean} [io.requiredChecks] - Whether `required-checks.json` declares an evidence-bearing check, `--arm` only.
1151
1833
  * @param {{write: (text: string) => void}} [io.out] - Stdout.
1152
1834
  * @param {{write: (text: string) => void}} [io.err] - Stderr.
1153
1835
  * @returns {number} The exit code.
@@ -1206,6 +1888,9 @@ export function main(argv, io = {}) {
1206
1888
  sha: opts.sha,
1207
1889
  isPullRequestHead,
1208
1890
  });
1891
+ if (opts.arm) {
1892
+ return writeArmDecision(verdict, { opts, io, out, repo, pulls });
1893
+ }
1209
1894
  out.write(
1210
1895
  `${opts.json ? JSON.stringify(verdict, null, 2) : humanReport(verdict)}\n`
1211
1896
  );