@codyswann/lisa 4.36.1 → 4.37.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (82) hide show
  1. package/all/copy-overwrite/scripts/lisa-enforcement-fallback.sh +2 -2
  2. package/all/copy-overwrite/scripts/lisa-hooks/block-blind-automerge.sh +626 -0
  3. package/dist/core/lisa-owned-hash-ledger.d.ts.map +1 -1
  4. package/dist/core/lisa-owned-hash-ledger.js +10 -0
  5. package/dist/core/lisa-owned-hash-ledger.js.map +1 -1
  6. package/dist/core/nightly-e2e-guard-behavior-certificate.js +2 -2
  7. package/dist/core/upstream-evidence-manifest.d.ts.map +1 -1
  8. package/dist/core/upstream-evidence-manifest.js +26 -7
  9. package/dist/core/upstream-evidence-manifest.js.map +1 -1
  10. package/dist/strategies/package-lisa.js +10 -0
  11. package/dist/strategies/package-lisa.js.map +1 -1
  12. package/package.json +5 -4
  13. package/plugins/lisa/.claude-plugin/plugin.json +5 -1
  14. package/plugins/lisa/.codex-plugin/hooks.json +4 -0
  15. package/plugins/lisa/.codex-plugin/plugin.json +1 -1
  16. package/plugins/lisa/hooks/block-blind-automerge.agy.sh +54 -0
  17. package/plugins/lisa/hooks/block-blind-automerge.sh +623 -0
  18. package/plugins/lisa-agy/hooks/block-blind-automerge.agy.sh +54 -0
  19. package/plugins/lisa-agy/hooks/block-blind-automerge.sh +623 -0
  20. package/plugins/lisa-agy/hooks.json +13 -0
  21. package/plugins/lisa-agy/plugin.json +1 -1
  22. package/plugins/lisa-cdk/.claude-plugin/plugin.json +1 -1
  23. package/plugins/lisa-cdk/.codex-plugin/plugin.json +1 -1
  24. package/plugins/lisa-cdk-agy/plugin.json +1 -1
  25. package/plugins/lisa-cdk-copilot/.claude-plugin/plugin.json +1 -1
  26. package/plugins/lisa-cdk-cursor/.claude-plugin/plugin.json +1 -1
  27. package/plugins/lisa-copilot/.claude-plugin/plugin.json +5 -1
  28. package/plugins/lisa-copilot/hooks/block-blind-automerge.sh +623 -0
  29. package/plugins/lisa-cursor/.claude-plugin/plugin.json +1 -1
  30. package/plugins/lisa-cursor/hooks/block-blind-automerge.sh +623 -0
  31. package/plugins/lisa-cursor/hooks/hooks.json +4 -0
  32. package/plugins/lisa-expo/.claude-plugin/plugin.json +1 -1
  33. package/plugins/lisa-expo/.codex-plugin/plugin.json +1 -1
  34. package/plugins/lisa-expo-agy/plugin.json +1 -1
  35. package/plugins/lisa-expo-copilot/.claude-plugin/plugin.json +1 -1
  36. package/plugins/lisa-expo-cursor/.claude-plugin/plugin.json +1 -1
  37. package/plugins/lisa-harper-fabric/.claude-plugin/plugin.json +1 -1
  38. package/plugins/lisa-harper-fabric/.codex-plugin/plugin.json +1 -1
  39. package/plugins/lisa-harper-fabric-agy/plugin.json +1 -1
  40. package/plugins/lisa-harper-fabric-copilot/.claude-plugin/plugin.json +1 -1
  41. package/plugins/lisa-harper-fabric-cursor/.claude-plugin/plugin.json +1 -1
  42. package/plugins/lisa-nestjs/.claude-plugin/plugin.json +1 -1
  43. package/plugins/lisa-nestjs/.codex-plugin/plugin.json +1 -1
  44. package/plugins/lisa-nestjs-agy/plugin.json +1 -1
  45. package/plugins/lisa-nestjs-copilot/.claude-plugin/plugin.json +1 -1
  46. package/plugins/lisa-nestjs-cursor/.claude-plugin/plugin.json +1 -1
  47. package/plugins/lisa-openclaw/.claude-plugin/plugin.json +1 -1
  48. package/plugins/lisa-openclaw/.codex-plugin/plugin.json +1 -1
  49. package/plugins/lisa-openclaw-agy/plugin.json +1 -1
  50. package/plugins/lisa-openclaw-copilot/.claude-plugin/plugin.json +1 -1
  51. package/plugins/lisa-openclaw-cursor/.claude-plugin/plugin.json +1 -1
  52. package/plugins/lisa-phaser/.claude-plugin/plugin.json +1 -1
  53. package/plugins/lisa-phaser/.codex-plugin/plugin.json +1 -1
  54. package/plugins/lisa-phaser-agy/plugin.json +1 -1
  55. package/plugins/lisa-phaser-copilot/.claude-plugin/plugin.json +1 -1
  56. package/plugins/lisa-phaser-cursor/.claude-plugin/plugin.json +1 -1
  57. package/plugins/lisa-rails/.claude-plugin/plugin.json +1 -1
  58. package/plugins/lisa-rails/.codex-plugin/plugin.json +1 -1
  59. package/plugins/lisa-rails-agy/plugin.json +1 -1
  60. package/plugins/lisa-rails-copilot/.claude-plugin/plugin.json +1 -1
  61. package/plugins/lisa-rails-cursor/.claude-plugin/plugin.json +1 -1
  62. package/plugins/lisa-typescript/.claude-plugin/plugin.json +1 -1
  63. package/plugins/lisa-typescript/.codex-plugin/plugin.json +1 -1
  64. package/plugins/lisa-typescript-agy/plugin.json +1 -1
  65. package/plugins/lisa-typescript-copilot/.claude-plugin/plugin.json +1 -1
  66. package/plugins/lisa-typescript-cursor/.claude-plugin/plugin.json +1 -1
  67. package/plugins/lisa-wiki/.claude-plugin/plugin.json +1 -1
  68. package/plugins/lisa-wiki/.codex-plugin/plugin.json +1 -1
  69. package/plugins/lisa-wiki-agy/plugin.json +1 -1
  70. package/plugins/lisa-wiki-copilot/.claude-plugin/plugin.json +1 -1
  71. package/plugins/lisa-wiki-cursor/.claude-plugin/plugin.json +1 -1
  72. package/plugins/materialized-artifacts.json +1 -0
  73. package/plugins/src/base/.claude-plugin/plugin.json +4 -0
  74. package/plugins/src/base/hooks/block-blind-automerge.agy.sh +54 -0
  75. package/plugins/src/base/hooks/block-blind-automerge.sh +623 -0
  76. package/scripts/build-plugins.sh +1 -1
  77. package/scripts/check-self-dependency-pin.mjs +401 -0
  78. package/scripts/generate-agy-plugin-artifacts.mjs +11 -0
  79. package/scripts/lib/per-agent-hook-filter.mjs +10 -0
  80. package/scripts/lisa-enforcement-fallback.sh +2 -2
  81. package/scripts/merge-generated-artifact.mjs +182 -20
  82. package/scripts/two-channel-couplings.json +1 -1
@@ -8,7 +8,7 @@
8
8
  #
9
9
  # Every PreToolUse guard — block-no-verify, parity-safety-net,
10
10
  # block-shell-json-parsing, block-instruction-file-edits,
11
- # block-direct-issue-create — is declared in the
11
+ # block-direct-issue-create, block-blind-automerge — is declared in the
12
12
  # Lisa plugin. A cloud session
13
13
  # installs plugins at session start from the marketplace the repository
14
14
  # declares, and when that does not happen the container runs with
@@ -316,7 +316,7 @@ plugin_tree_used=0
316
316
 
317
317
  for guard in block-no-verify parity-safety-net block-shell-json-parsing \
318
318
  block-instruction-file-edits block-direct-issue-create \
319
- block-managed-file-edits; do
319
+ block-managed-file-edits block-blind-automerge; do
320
320
  if [ -f "$host_tree/$guard.sh" ]; then
321
321
  guard_names+=("$guard")
322
322
  guard_scripts+=("$host_tree/$guard.sh")
@@ -0,0 +1,626 @@
1
+ #!/usr/bin/env bash
2
+ # This file is managed by Lisa and IS replaced on each `lisa` run.
3
+ # Do not edit directly — durable changes belong upstream in Lisa.
4
+
5
+ # PreToolUse hook for Bash: refuse to ARM auto-merge on a pull request that
6
+ # GitHub already says is blocked on review.
7
+ #
8
+ # WHY THIS IS A HOOK AND NOT A RULE
9
+ #
10
+ # Arming auto-merge is the moment an agent claims "this will merge", and the
11
+ # claim can be false at exactly that moment. Measured on this repository: three
12
+ # of five open PRs sat armed, fully green, with `reviewDecision =
13
+ # CHANGES_REQUESTED`. Nothing surfaced it. `reviewDecision` is not part of the
14
+ # check rollup, so the failing-check count read 0, the checks tab was entirely
15
+ # green, and three separate agents armed and moved on. One PR had been parked
16
+ # for hours before someone queried the field by hand.
17
+ #
18
+ # The stale case is the one actually observed, and it is the one prose cannot
19
+ # help with: the `base` ruleset sets `dismiss_stale_reviews_on_push: false`, so
20
+ # a CHANGES_REQUESTED review stays attached to the commit it was made on and
21
+ # pushing the fix never clears it, while `required_approving_review_count: 0`
22
+ # means no scheduled re-review will ever clear it either. The PR is blocked
23
+ # indefinitely and every check-based signal reads ready.
24
+ #
25
+ # WHAT IT CHECKS, AND WHY THAT AND NOT THE CHECK ROLLUP
26
+ #
27
+ # The defect class here is a probe that measures what it can see rather than
28
+ # what it means. A signal assembled from check-runs reports "ready to merge" on
29
+ # a PR that can never merge — that is precisely how this stayed invisible — and
30
+ # a code-review gate can arrive as a commit STATUS rather than a check-run, so
31
+ # a check-run-only query misses that too. So this guard does not look at checks
32
+ # at all. It asks GitHub the one question whose answer is the blocker:
33
+ # `reviewDecision`.
34
+ #
35
+ # `mergeStateStatus` is deliberately NOT read. It is computed rather than
36
+ # stored, reports UNKNOWN transiently while GitHub recomputes it, and was
37
+ # observed reporting CONFLICTING on two PRs minutes apart where one had a real
38
+ # conflict and the other merged cleanly with zero conflicted paths. Same field,
39
+ # opposite truths. A guard built on it would refuse honest commands at random,
40
+ # which is how a guard gets switched off.
41
+ #
42
+ # WHAT THIS GUARD DOES *NOT* CLAIM
43
+ #
44
+ # It answers "is there a standing review verdict blocking this merge?", not
45
+ # "can this PR merge?". The difference matters for one measured case that looks
46
+ # like this ticket and is not it: a PR opened against a base where reviews are
47
+ # disabled gets a review bot reporting `success` with the description "Review
48
+ # skipped: reviews are disabled for this base branch", and the repository's two
49
+ # review-evidence gates then FAIL. That PR cannot merge either — but it is not
50
+ # invisible: the failing-check count is 2, and any check-based signal reports it
51
+ # correctly. Only the individual bot's *conclusion* misleads, and nothing here
52
+ # reads conclusions.
53
+ #
54
+ # So that case is deliberately out of scope rather than overlooked, and the
55
+ # distinction is the whole reason this guard exists: `CHANGES_REQUESTED` shows
56
+ # ZERO failing checks. A guard that also tried to adjudicate check descriptions
57
+ # would be re-deriving gates that already run, and would start refusing commands
58
+ # on evidence CI already surfaces. The suite pins the boundary with a case, so a
59
+ # later reader can see it was decided rather than missed.
60
+ #
61
+ # SCOPE: `--auto` ONLY
62
+ #
63
+ # A direct `gh pr merge` against a blocked PR fails loudly and immediately, so
64
+ # it is not the invisible failure this exists to close — and refusing it would
65
+ # also refuse the deliberate `--admin` override a human reaches for. Only the
66
+ # ARMING form is intercepted, because only arming produces a false report of
67
+ # success that outlives the command.
68
+ #
69
+ # The refusal is not a dead end: dismissing a genuinely stale review is a
70
+ # supported step of `lisa-drive-pr-to-merge`, and that is what the message
71
+ # names. There is deliberately no env-var escape hatch — an override the
72
+ # governed agent can set is theatre, and the real remedy is one command away.
73
+ #
74
+ # SUBSTRATES
75
+ #
76
+ # Arming has TWO shell spellings, not one. `gh pr merge --auto` is the common
77
+ # one; `gh api graphql` running the `enablePullRequestAutoMerge` mutation is the
78
+ # same act through the API, and a guard that recognises only the first reports
79
+ # safety about both. That is the failure mode CodySwannGT/lisa#3753 records one
80
+ # guard over — a control that sees a single substrate and speaks for all of
81
+ # them — so both are matched here. The mutation names a node id rather than a
82
+ # number, so the probe resolves it through `node(id:)`; a mutation whose id
83
+ # cannot be read at all FAILS CLOSED, because silence about an arming this
84
+ # guard could not inspect is this ticket's own defect in a new place.
85
+ #
86
+ # Recorded residual: the guard is registered `matcher: "Bash"`, so a structured
87
+ # tool call that arms auto-merge would not reach it. No MCP server provisioned
88
+ # here exposes auto-merge arming — the GitHub MCP merges directly, which is out
89
+ # of scope by the paragraph above — so the gap is currently unreachable rather
90
+ # than open. If one appears, the fix is #3753's: move the registration AND the
91
+ # internal `tool_name` gate together, since either alone ships a change that
92
+ # nothing fails on. Whether it earns its own `matcher: ""` group is a cost
93
+ # question that PR measured and bounded (~11.5ms per non-Bash call, with the
94
+ # whole broad set to stay under ~100ms); re-measure rather than assume.
95
+ #
96
+ # The line below is what lets `lisa apply` tell a downstream copy of this guard
97
+ # that is BEHIND from one that is AHEAD. Add a name here in the same commit that
98
+ # closes a vector.
99
+ # lisa-guard-capabilities: automerge-arm-review-decision, automerge-arm-graphql
100
+ set -euo pipefail
101
+
102
+ input="$(cat)"
103
+
104
+ # Both interpreters are probed BEFORE use, and a missing one is ANNOUNCED
105
+ # rather than swallowed. Under `set -e` an absent jq would abort with 127, and
106
+ # Claude Code treats any non-2 exit as a non-blocking hook error — so the guard
107
+ # would silently permit the very thing it exists to stop. Degrading to "allow"
108
+ # is right (a hook that cannot parse its input cannot tell an arming command
109
+ # from an ordinary one); doing it quietly is not.
110
+ for required in jq python3; do
111
+ if ! command -v "$required" >/dev/null 2>&1; then
112
+ printf 'block-blind-automerge: %s not found; auto-merge review-gate protection is NOT active\n' \
113
+ "$required" >&2
114
+ exit 0
115
+ fi
116
+ done
117
+
118
+ tool_name="$(printf '%s' "$input" | jq -r '.tool_name // empty' 2>/dev/null || true)"
119
+ if [ "$tool_name" != "Bash" ]; then
120
+ exit 0
121
+ fi
122
+
123
+ command_str="$(printf '%s' "$input" | jq -r '.tool_input.command // empty' 2>/dev/null || true)"
124
+ if [ -z "$command_str" ]; then
125
+ exit 0
126
+ fi
127
+
128
+ if ! BLOCK_BLIND_AUTOMERGE_COMMAND="$command_str" python3 - <<'PY'
129
+ import json
130
+ import os
131
+ import re
132
+ import shlex
133
+ import subprocess
134
+ import sys
135
+
136
+ command = os.environ.get("BLOCK_BLIND_AUTOMERGE_COMMAND", "")
137
+
138
+ # The one verdict that means "GitHub is refusing this merge on review grounds".
139
+ BLOCKING_REVIEW_DECISION = "CHANGES_REQUESTED"
140
+
141
+ # A hook must not become the reason a command hangs. `timeout(1)` is not
142
+ # present on every machine this runs on, so the bound is expressed where it is
143
+ # always available — and a TimeoutExpired is a NAMED exception, so a slow
144
+ # network can never be mistaken for a PR that reads as clean.
145
+ GH_TIMEOUT_SECONDS = 20
146
+
147
+ # gh's persistent flags that take a SEPARATE value token, which must be skipped
148
+ # when looking for the subcommand: `gh --repo o/r pr merge` reaches `merge`.
149
+ GH_SEPARATE_VALUE = {"-R", "--repo", "--hostname"}
150
+
151
+ # `gh pr merge` options taking a separate value. Listed so a VALUE is never
152
+ # mistaken for the PR selector — `gh pr merge --subject "fix 12" --auto` must
153
+ # not read `fix 12` as the PR.
154
+ MERGE_SEPARATE_VALUE = {
155
+ "-b", "--body", "-F", "--body-file", "-t", "--subject",
156
+ "--match-head-commit", "--author-email",
157
+ }
158
+
159
+ COMMAND_SEPARATORS = {
160
+ ";", "|", "||", "&", "&&", "(", ")", "<", ">", ">>", "<<", "&|",
161
+ }
162
+
163
+ # Shell wrappers whose `-c` argument is a command in a string rather than argv.
164
+ # The outer argv names bash, so the arming is invisible without recursing once.
165
+ SHELL_WRAPPERS = {"bash", "sh", "zsh", "dash"}
166
+
167
+ # The GraphQL mutation that arms auto-merge. Same act as `gh pr merge --auto`,
168
+ # reached through the API instead of the porcelain.
169
+ AUTO_MERGE_MUTATION = "enablePullRequestAutoMerge"
170
+
171
+ # gh's field flags. `-f`/`--raw-field` and friends carry `name=value` pairs, so
172
+ # both the mutation text and its variables arrive through them.
173
+ GH_FIELD_FLAGS = {"-f", "--field", "-F", "--raw-field"}
174
+
175
+ # How the mutation names its subject, whether inline or as a variable.
176
+ PULL_REQUEST_ID_PATTERN = re.compile(
177
+ r"pullRequestId\s*:\s*(?:\"([^\"]+)\"|'([^']+)'|\$([A-Za-z_][A-Za-z0-9_]*))"
178
+ )
179
+
180
+ # A PR node id as GitHub issues them. Matched rather than accepted verbatim so
181
+ # a variable reference is never sent to the API as if it were an id.
182
+ NODE_ID_PATTERN = re.compile(r"^[A-Za-z0-9_=-]+$")
183
+
184
+ # The probe that resolves a node id to the same fields `gh pr view` returns.
185
+ NODE_QUERY = (
186
+ "query($id:ID!){node(id:$id){... on PullRequest"
187
+ "{number url reviewDecision state}}}"
188
+ )
189
+
190
+ # What a probe spec asks for. `view` and `node` differ only in how the PR is
191
+ # named; `unreadable` is an arming whose subject could not be determined.
192
+ PROBE_VIEW = "view"
193
+ PROBE_NODE = "node"
194
+ PROBE_UNREADABLE = "unreadable"
195
+
196
+
197
+ def strip_heredocs(text):
198
+ """Drop heredoc bodies, which are data rather than commands.
199
+
200
+ A PR body or commit message pasted into a heredoc can contain the literal
201
+ text of an arming command; running the guard over it would refuse a command
202
+ that arms nothing.
203
+
204
+ Args:
205
+ text: The raw command line.
206
+
207
+ Returns:
208
+ The command with heredoc payloads removed.
209
+ """
210
+ lines = text.splitlines()
211
+ output = []
212
+ pending = []
213
+ marker_pattern = re.compile(
214
+ r"<<-?\s*(?:'([^']+)'|\"([^\"]+)\"|([A-Za-z_][A-Za-z0-9_]*))"
215
+ )
216
+ index = 0
217
+ while index < len(lines):
218
+ line = lines[index]
219
+ output.append(line)
220
+ pending.extend(
221
+ next(group for group in match.groups() if group)
222
+ for match in marker_pattern.finditer(line)
223
+ )
224
+ index += 1
225
+ while pending and index < len(lines):
226
+ if lines[index].strip() == pending[0]:
227
+ output.append(lines[index])
228
+ pending.pop(0)
229
+ index += 1
230
+ break
231
+ index += 1
232
+ return "\n".join(output)
233
+
234
+
235
+ def line_boundaries_as_separators(text):
236
+ """Turn newlines into command separators, keeping continuations intact.
237
+
238
+ Args:
239
+ text: The command line, heredoc payloads already stripped.
240
+
241
+ Returns:
242
+ The same command with line breaks spelled as separators.
243
+ """
244
+ joined = text.replace("\r\n", "\n").replace("\\\n", " ")
245
+ return joined.replace("\n", " ; ")
246
+
247
+
248
+ def shell_tokens(text):
249
+ """Tokenize a command with shell operators kept as their own tokens.
250
+
251
+ Args:
252
+ text: The command line, heredoc payloads already stripped.
253
+
254
+ Returns:
255
+ The token list, with `;`, `|`, `&&`, `(` and friends standing alone.
256
+ """
257
+ lexer = shlex.shlex(
258
+ line_boundaries_as_separators(text), posix=True, punctuation_chars=True
259
+ )
260
+ lexer.whitespace_split = True
261
+ lexer.commenters = ""
262
+ return list(lexer)
263
+
264
+
265
+ def is_gh(token):
266
+ """Whether a token invokes the gh CLI.
267
+
268
+ Args:
269
+ token: A single shell token.
270
+
271
+ Returns:
272
+ True for a bare `gh` or any absolute/relative path ending in `/gh`.
273
+ """
274
+ return token == "gh" or token.endswith("/gh")
275
+
276
+
277
+ def merge_argv_after_gh(tokens, start):
278
+ """Find a `pr merge` invocation's argv within one gh command.
279
+
280
+ Args:
281
+ tokens: The operator-aware token list.
282
+ start: Index just past the `gh` token.
283
+
284
+ Returns:
285
+ The argv following `merge`, or None when this gh call is not a merge.
286
+ """
287
+ words = []
288
+ index = start
289
+ while index < len(tokens):
290
+ token = tokens[index]
291
+ if token in COMMAND_SEPARATORS:
292
+ break
293
+ if token.startswith("-"):
294
+ # `--repo=o/r` carries its value; `--repo o/r` eats the next token.
295
+ index += 2 if token in GH_SEPARATE_VALUE else 1
296
+ continue
297
+ words.append((token, index))
298
+ index += 1
299
+ for position, entry in enumerate(words):
300
+ if entry[0] == "merge" and position > 0 and words[position - 1][0] == "pr":
301
+ return tokens[entry[1] + 1:]
302
+ return None
303
+
304
+
305
+ def arms_auto_merge(argv):
306
+ """Whether a `gh pr merge` argv carries `--auto`.
307
+
308
+ Args:
309
+ argv: Tokens following the `merge` subcommand.
310
+
311
+ Returns:
312
+ True if this invocation arms auto-merge rather than merging now.
313
+ """
314
+ index = 0
315
+ while index < len(argv):
316
+ token = argv[index]
317
+ index += 1
318
+ if token in COMMAND_SEPARATORS:
319
+ return False
320
+ if token == "--auto" or token.startswith("--auto="):
321
+ return True
322
+ if token in MERGE_SEPARATE_VALUE:
323
+ index += 1
324
+ return False
325
+
326
+
327
+ def pr_selector(argv):
328
+ """The PR the arming command names, as gh itself would read it.
329
+
330
+ Returned verbatim so it can be handed straight back to `gh pr view`, which
331
+ accepts the same number, URL, or branch. When the command names none, gh
332
+ resolves the current branch and so does the probe.
333
+
334
+ Args:
335
+ argv: Tokens following the `merge` subcommand.
336
+
337
+ Returns:
338
+ The selector token, or None when the command relies on the branch.
339
+ """
340
+ index = 0
341
+ while index < len(argv):
342
+ token = argv[index]
343
+ index += 1
344
+ if token in COMMAND_SEPARATORS:
345
+ return None
346
+ if token in MERGE_SEPARATE_VALUE:
347
+ index += 1
348
+ continue
349
+ if not token.startswith("-"):
350
+ return token
351
+ return None
352
+
353
+
354
+ def repo_flag(tokens, start):
355
+ """The `--repo` value a gh invocation carries, in either spelling.
356
+
357
+ Args:
358
+ tokens: The operator-aware token list.
359
+ start: Index just past the `gh` token.
360
+
361
+ Returns:
362
+ A list of gh arguments re-expressing the repo, empty when none.
363
+ """
364
+ index = start
365
+ while index < len(tokens):
366
+ token = tokens[index]
367
+ if token in COMMAND_SEPARATORS:
368
+ break
369
+ if token in {"-R", "--repo"} and index + 1 < len(tokens):
370
+ return ["--repo", tokens[index + 1]]
371
+ if token.startswith("--repo="):
372
+ return ["--repo", token.split("=", 1)[1]]
373
+ index += 1
374
+ return []
375
+
376
+
377
+ def gh_invocation_tokens(tokens, start):
378
+ """The tokens belonging to one gh invocation, up to the next separator.
379
+
380
+ Args:
381
+ tokens: The operator-aware token list.
382
+ start: Index just past the `gh` token.
383
+
384
+ Returns:
385
+ The invocation's own tokens.
386
+ """
387
+ end = start
388
+ while end < len(tokens) and tokens[end] not in COMMAND_SEPARATORS:
389
+ end += 1
390
+ return tokens[start:end]
391
+
392
+
393
+ def field_values(argv):
394
+ """The `name=value` payloads a gh invocation passes as fields.
395
+
396
+ Args:
397
+ argv: One gh invocation's tokens.
398
+
399
+ Returns:
400
+ A dict of field name to value. Later fields win, as gh does.
401
+ """
402
+ values = {}
403
+ index = 0
404
+ while index < len(argv):
405
+ token = argv[index]
406
+ index += 1
407
+ raw = None
408
+ if token in GH_FIELD_FLAGS and index < len(argv):
409
+ raw = argv[index]
410
+ index += 1
411
+ elif token.startswith("--field=") or token.startswith("--raw-field="):
412
+ raw = token.split("=", 1)[1]
413
+ if raw is not None and "=" in raw:
414
+ name, value = raw.split("=", 1)
415
+ values[name] = value
416
+ return values
417
+
418
+
419
+ def graphql_arming_id(argv):
420
+ """The PR node id a `gh api graphql` auto-merge mutation names.
421
+
422
+ Args:
423
+ argv: One gh invocation's tokens, `api` included.
424
+
425
+ Returns:
426
+ A pair (is_arming, node_id). `node_id` is None when the mutation arms
427
+ auto-merge but names its subject in a way this cannot resolve — which
428
+ is a refusal, not a pass.
429
+ """
430
+ words = [token for token in argv if not token.startswith("-")]
431
+ if len(words) < 2 or words[0] != "api" or words[1] != "graphql":
432
+ return (False, None)
433
+ fields = field_values(argv)
434
+ query = " ".join(
435
+ value for name, value in fields.items() if AUTO_MERGE_MUTATION in value
436
+ )
437
+ if not query:
438
+ return (False, None)
439
+ match = PULL_REQUEST_ID_PATTERN.search(query)
440
+ if match is None:
441
+ return (True, None)
442
+ inline = match.group(1) or match.group(2)
443
+ if inline:
444
+ return (True, inline if NODE_ID_PATTERN.match(inline) else None)
445
+ # `pullRequestId: $prId` — the id arrives as a separate variable field.
446
+ variable = fields.get(match.group(3))
447
+ if variable and NODE_ID_PATTERN.match(variable):
448
+ return (True, variable)
449
+ return (True, None)
450
+
451
+
452
+ def arming_invocations(text, depth=0):
453
+ """Every auto-merge arming this command line performs.
454
+
455
+ Args:
456
+ text: The command line, heredoc payloads already stripped.
457
+ depth: Recursion depth, bounding the `bash -c` unwrap to one level.
458
+
459
+ Returns:
460
+ A list of (kind, subject, repo_args) probe specs, one per arming.
461
+ """
462
+ try:
463
+ tokens = shell_tokens(text)
464
+ except ValueError:
465
+ return []
466
+ found = []
467
+ for index, token in enumerate(tokens):
468
+ if depth == 0 and token.split("/")[-1] in SHELL_WRAPPERS:
469
+ # `bash -c '<command>'` hides the whole invocation inside one token.
470
+ if index + 2 < len(tokens) and tokens[index + 1] == "-c":
471
+ found.extend(arming_invocations(tokens[index + 2], depth + 1))
472
+ continue
473
+ if not is_gh(token):
474
+ continue
475
+ repo_args = repo_flag(tokens, index + 1)
476
+ argv = merge_argv_after_gh(tokens, index + 1)
477
+ if argv is not None and arms_auto_merge(argv):
478
+ found.append((PROBE_VIEW, pr_selector(argv), repo_args))
479
+ continue
480
+ is_arming, node_id = graphql_arming_id(
481
+ gh_invocation_tokens(tokens, index + 1)
482
+ )
483
+ if is_arming:
484
+ kind = PROBE_NODE if node_id else PROBE_UNREADABLE
485
+ found.append((kind, node_id, repo_args))
486
+ return found
487
+
488
+
489
+ def probe_args(kind, subject, repo_args):
490
+ """The gh command that answers the review question for one arming.
491
+
492
+ Args:
493
+ kind: PROBE_VIEW or PROBE_NODE.
494
+ subject: A PR selector, a node id, or None for the current branch.
495
+ repo_args: gh arguments naming the repository, possibly empty.
496
+
497
+ Returns:
498
+ The full gh argv.
499
+ """
500
+ if kind == PROBE_NODE:
501
+ # `--jq` unwraps the envelope so both probes return the same shape.
502
+ return [
503
+ "gh", "api", "graphql",
504
+ "-f", "query=" + NODE_QUERY,
505
+ "-f", "id=" + subject,
506
+ "--jq", ".data.node",
507
+ ]
508
+ args = ["gh", "pr", "view"]
509
+ if subject is not None:
510
+ args.append(subject)
511
+ args.extend(repo_args)
512
+ args.extend(["--json", "number,reviewDecision,state,url"])
513
+ return args
514
+
515
+
516
+ def pull_request_state(kind, subject, repo_args):
517
+ """Ask GitHub for the fields that decide whether a merge can happen.
518
+
519
+ Args:
520
+ kind: PROBE_VIEW or PROBE_NODE.
521
+ subject: A PR selector, a node id, or None for the current branch.
522
+ repo_args: gh arguments naming the repository, possibly empty.
523
+
524
+ Returns:
525
+ A pair (payload, failure). Exactly one is non-None: `payload` is the
526
+ decoded pull request object, `failure` is a human-readable reason the
527
+ question could not be answered.
528
+ """
529
+ args = probe_args(kind, subject, repo_args)
530
+ try:
531
+ result = subprocess.run(
532
+ args, capture_output=True, text=True, timeout=GH_TIMEOUT_SECONDS
533
+ )
534
+ except FileNotFoundError:
535
+ return (None, "gh not found")
536
+ except subprocess.TimeoutExpired:
537
+ return (None, "gh timed out after %ds" % GH_TIMEOUT_SECONDS)
538
+ except OSError as error:
539
+ return (None, "gh could not be run (%s)" % error)
540
+ if result.returncode != 0:
541
+ return (None, "gh exited %d" % result.returncode)
542
+ try:
543
+ payload = json.loads(result.stdout or "{}")
544
+ except ValueError:
545
+ return (None, "gh returned unreadable JSON")
546
+ if not isinstance(payload, dict):
547
+ return (None, "gh returned unreadable JSON")
548
+ return (payload, None)
549
+
550
+
551
+ def pr_name(payload):
552
+ """The most identifying name available for the PR in a refusal message.
553
+
554
+ Args:
555
+ payload: The decoded `gh pr view --json` object.
556
+
557
+ Returns:
558
+ A URL, a `#<number>`, or a generic phrase.
559
+ """
560
+ if payload.get("url"):
561
+ return payload["url"]
562
+ if payload.get("number"):
563
+ return "#%s" % payload["number"]
564
+ return "this PR"
565
+
566
+
567
+ REFUSAL = """Blocked: arming auto-merge on %s would report a merge that can never happen.
568
+
569
+ GitHub reports reviewDecision = CHANGES_REQUESTED. That is a merge blocker with
570
+ NO check-run representation: the failing-check count reads 0 and the checks tab
571
+ is entirely green while the PR is permanently unmergeable. Where the ruleset
572
+ sets dismiss_stale_reviews_on_push: false, pushing the fix does not clear it and
573
+ no re-review is scheduled to.
574
+
575
+ Clear the blocker, then arm:
576
+ - resolve every review thread and address or reply to the feedback
577
+ (`lisa-pull-request-review`);
578
+ - if the review is stale — made on an older head, with the fix already pushed
579
+ — dismiss it (`lisa-drive-pr-to-merge`, review-gate stall), then re-arm.
580
+
581
+ Do not report the PR as armed-and-merging until this reads anything other than
582
+ CHANGES_REQUESTED.
583
+ """
584
+
585
+ UNREADABLE_REFUSAL = """Blocked: this command arms auto-merge through a GraphQL mutation whose
586
+ pullRequestId cannot be read, so whether the PR is blocked on review is
587
+ unknowable at the moment the claim "this will merge" is made.
588
+
589
+ Arm through `gh pr merge <pr> --auto` instead, or pass the node id as a literal
590
+ or as a field this command also sets. An arming nobody can inspect is the
591
+ failure this guard exists to close, one substrate over.
592
+ """
593
+
594
+ armings = arming_invocations(strip_heredocs(command))
595
+ if not armings:
596
+ sys.exit(0)
597
+
598
+ for kind, subject, repo_args in armings:
599
+ if kind == PROBE_UNREADABLE:
600
+ # Fails CLOSED, unlike every other unanswerable case below. Those are
601
+ # the guard being unable to run; this is the command refusing to say
602
+ # what it acts on, which is a property of the command.
603
+ sys.stderr.write(UNREADABLE_REFUSAL)
604
+ sys.exit(1)
605
+ payload, failure = pull_request_state(kind, subject, repo_args)
606
+ if failure is not None:
607
+ # A guard that is silently absent reads exactly like a guard that is
608
+ # passing, so say so and let the command through.
609
+ sys.stderr.write(
610
+ "block-blind-automerge: could not read reviewDecision (%s); "
611
+ "auto-merge review-gate protection is NOT active for this command\n"
612
+ % failure
613
+ )
614
+ continue
615
+ if (payload.get("reviewDecision") or "") != BLOCKING_REVIEW_DECISION:
616
+ continue
617
+ sys.stderr.write(REFUSAL % pr_name(payload))
618
+ sys.exit(1)
619
+
620
+ sys.exit(0)
621
+ PY
622
+ then
623
+ exit 2
624
+ fi
625
+
626
+ exit 0
@@ -1 +1 @@
1
- {"version":3,"file":"lisa-owned-hash-ledger.d.ts","sourceRoot":"","sources":["../../src/core/lisa-owned-hash-ledger.ts"],"names":[],"mappings":"AACA,6EAA6E;AAE7E;;;;;;;GAOG;AACH,eAAO,MAAM,sBAAsB,EAAE,QAAQ,CAC3C,MAAM,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,CAAC,CAu+BjC,CAAC;AAEH;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,+BAA+B,EAAE,QAAQ,CACpD,MAAM,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,CAAC,CA04BjC,CAAC"}
1
+ {"version":3,"file":"lisa-owned-hash-ledger.d.ts","sourceRoot":"","sources":["../../src/core/lisa-owned-hash-ledger.ts"],"names":[],"mappings":"AACA,6EAA6E;AAE7E;;;;;;;GAOG;AACH,eAAO,MAAM,sBAAsB,EAAE,QAAQ,CAC3C,MAAM,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,CAAC,CA4+BjC,CAAC;AAEH;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,+BAA+B,EAAE,QAAQ,CACpD,MAAM,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,CAAC,CA+4BjC,CAAC"}
@@ -404,6 +404,7 @@ export const LISA_OWNED_HASH_LEDGER = Object.freeze({
404
404
  "1bec5f3c284b3febdc471487ee6a23ffb72bd4e7b293f9e26b0188f32318c722",
405
405
  "27f4e4b54986f49ddb9a3bf6e02b926d41d85ecd46ab2263cb17a5746820f8bd",
406
406
  "3049c2f1051c7c02dd60b62355964651e1565ebe6bdcb5e37634cd686cf1deb1",
407
+ "531ef11fc42705826d5fa6fe80a972218411fdf5915a69f9c84d620968fdca8b",
407
408
  "68e1b78d5d4471fadbe2eb575ae46221838217290123a9910d76dba0f1c34131",
408
409
  "7d333dc10be8c810b9b5aca35ab7f6f60413134414d82bf0cdaedb4e6e3ca8da",
409
410
  "8dc942ac4edc2017d6b8277296c8f80542e7c024eef1bb65de609979d0ca9a0e",
@@ -578,6 +579,10 @@ export const LISA_OWNED_HASH_LEDGER = Object.freeze({
578
579
  "f9e94e7daa0fffedefb224882c2944f66a8f39d60e6a4c1f4410975a7f98ef24",
579
580
  "fbd68cf571985d7cfccf0f280cfe8112955849126e44d27d55ad619f9abb79ef",
580
581
  ]),
582
+ "scripts/lisa-hooks/block-blind-automerge.sh": Object.freeze([
583
+ "699ec1a7470583916f3d36e301c4d4b6f52741f8e111e5528074bea05e3ee25c",
584
+ "fa4733a5df4bcf29fe385d92bd3456cee22bd06f089a60d26631dafb5f7601e3",
585
+ ]),
581
586
  "scripts/lisa-hooks/block-direct-issue-create.sh": Object.freeze([
582
587
  "014510942610f36b17f006dee4b96c7737abad3e3acc4f5b416ab6d52403c793",
583
588
  "0e4a69c6f072cdf8c77931dd846348cf3f08ea0f47c6c0b0f5c4828cde5a8daa",
@@ -1396,6 +1401,7 @@ export const LISA_OWNED_HASH_HISTORY_DERIVED = Object.freeze({
1396
1401
  "1bec5f3c284b3febdc471487ee6a23ffb72bd4e7b293f9e26b0188f32318c722",
1397
1402
  "27f4e4b54986f49ddb9a3bf6e02b926d41d85ecd46ab2263cb17a5746820f8bd",
1398
1403
  "3049c2f1051c7c02dd60b62355964651e1565ebe6bdcb5e37634cd686cf1deb1",
1404
+ "531ef11fc42705826d5fa6fe80a972218411fdf5915a69f9c84d620968fdca8b",
1399
1405
  "68e1b78d5d4471fadbe2eb575ae46221838217290123a9910d76dba0f1c34131",
1400
1406
  "7d333dc10be8c810b9b5aca35ab7f6f60413134414d82bf0cdaedb4e6e3ca8da",
1401
1407
  "8dc942ac4edc2017d6b8277296c8f80542e7c024eef1bb65de609979d0ca9a0e",
@@ -1526,6 +1532,10 @@ export const LISA_OWNED_HASH_HISTORY_DERIVED = Object.freeze({
1526
1532
  "f8ebc11f8bbb27ce8cea883044687f7c023302a928de1d917209cae84274367a",
1527
1533
  "fbd68cf571985d7cfccf0f280cfe8112955849126e44d27d55ad619f9abb79ef",
1528
1534
  ]),
1535
+ "scripts/lisa-hooks/block-blind-automerge.sh": Object.freeze([
1536
+ "699ec1a7470583916f3d36e301c4d4b6f52741f8e111e5528074bea05e3ee25c",
1537
+ "fa4733a5df4bcf29fe385d92bd3456cee22bd06f089a60d26631dafb5f7601e3",
1538
+ ]),
1529
1539
  "scripts/lisa-hooks/block-direct-issue-create.sh": Object.freeze([
1530
1540
  "014510942610f36b17f006dee4b96c7737abad3e3acc4f5b416ab6d52403c793",
1531
1541
  "0e4a69c6f072cdf8c77931dd846348cf3f08ea0f47c6c0b0f5c4828cde5a8daa",