@soleur/opencode 3.357.15 → 3.357.17

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.
@@ -0,0 +1,141 @@
1
+ #!/usr/bin/env bash
2
+ # collision-precheck.sh -- before plan or review work starts on issue <N>,
3
+ # report live work that may already be doing the same change:
4
+ #
5
+ # probe 1: gh pr list --state open --search "<N>" open PRs naming the issue
6
+ # probe 2: lib/proc.sh list_runs <basename> foreign-owned process rows
7
+ # (a sibling session's live
8
+ # gate in another worktree)
9
+ #
10
+ # A hit is REPORTED, never resolved: this script is read-only -- it never
11
+ # comments on, edits, closes or pushes to anyone's change. The caller surfaces
12
+ # every hit to the operator before work starts. The measured failure was two
13
+ # sessions of the same operator converting the same file for the same issue
14
+ # (#10320 / #10322; issue #10333) -- discovered only at the end of review,
15
+ # through a foreign worktree's test run and `gh pr list --head`.
16
+ #
17
+ # Usage:
18
+ # collision-precheck.sh <issue-number> [<proc-basename>...]
19
+ #
20
+ # <issue-number> digits only
21
+ # <proc-basename> process basenames for the proc.sh half (default:
22
+ # test-all.sh). proc.sh matches on BASENAME and refuses any
23
+ # pattern containing '/', so pass e.g. test-all.sh, never a
24
+ # path.
25
+ #
26
+ # Output: one plain-language line per finding (and per probe that could not
27
+ # run), then ONE machine line:
28
+ # SOLEUR_COLLISION exit=<code> prs=<csv|none|unchecked> foreign=<csv|none|unchecked>
29
+ #
30
+ # Exit codes:
31
+ # 0 clear -- both probes ran and found nothing
32
+ # 10 hit -- >=1 open PR names the issue, or >=1 foreign process row
33
+ # 2 could not check -- a probe failed AND the other found nothing; a check
34
+ # that could not run never reads as clear
35
+ # 64 usage error
36
+ #
37
+ # `set -uo pipefail`, deliberately NOT `-e`: the probes' failures are inputs,
38
+ # never aborts. Portable to bash 3.2 (no associative arrays, no mapfile).
39
+
40
+ set -uo pipefail
41
+ export LC_ALL=C
42
+
43
+ SELF_DIR="$(cd -P "$(dirname "${BASH_SOURCE[0]}")" && pwd -P)"
44
+ PROC_SH="$SELF_DIR/lib/proc.sh"
45
+
46
+ usage() {
47
+ echo "usage: $0 <issue-number> [<proc-basename>...]" >&2
48
+ echo " reports open PRs naming the issue and foreign proc.sh list_runs rows; read-only." >&2
49
+ }
50
+
51
+ ISSUE="${1:-}"
52
+ case "$ISSUE" in
53
+ *[!0-9]* | "")
54
+ echo "collision-precheck: issue number must be digits only (got: '${ISSUE:-<empty>}')" >&2
55
+ usage
56
+ exit 64
57
+ ;;
58
+ esac
59
+ shift
60
+
61
+ PATS=()
62
+ while (($#)); do
63
+ case "$1" in
64
+ */* | "")
65
+ echo "collision-precheck: proc pattern '$1' is not a bare basename (proc.sh rejects '/')." >&2
66
+ exit 64
67
+ ;;
68
+ esac
69
+ PATS+=("$1")
70
+ shift
71
+ done
72
+ if [[ ${#PATS[@]} -eq 0 ]]; then PATS=(test-all.sh); fi
73
+
74
+ say() { printf '%s\n' "$*"; }
75
+
76
+ PRS=""
77
+ PR_STATE=unchecked
78
+ FGN=""
79
+ FGN_STATE=unchecked
80
+
81
+ # --- probe 1: open PRs naming the issue -------------------------------------
82
+ if ! command -v gh >/dev/null 2>&1; then
83
+ say "I could not check open PRs for #$ISSUE (gh is not installed)."
84
+ elif ! rows="$(gh pr list --state open --search "$ISSUE" -L 100 \
85
+ --json number,url --jq '.[] | "\(.number)\t\(.url)"' 2>/dev/null)"; then
86
+ say "I could not check open PRs for #$ISSUE (gh pr list failed -- auth, network or API error)."
87
+ else
88
+ PR_STATE=none
89
+ while IFS=$'\t' read -r _n _u; do
90
+ [[ -n "$_n" ]] || continue
91
+ PR_STATE=csv
92
+ PRS="${PRS:+$PRS,}$_n"
93
+ say "An open change names #$ISSUE: PR #$_n -- $_u"
94
+ done <<< "$rows"
95
+ fi
96
+
97
+ # --- probe 2: foreign proc.sh rows ------------------------------------------
98
+ if [[ ! -f "$PROC_SH" ]]; then
99
+ say "I could not check sibling-session processes ($PROC_SH is missing)."
100
+ else
101
+ _ok=0
102
+ _failed=0
103
+ for _pat in ${PATS[@]+"${PATS[@]}"}; do
104
+ _out="$(bash "$PROC_SH" list_runs "$_pat" 2>/dev/null)"
105
+ _rc=$?
106
+ if ((_rc == 0)); then
107
+ _ok=$((_ok + 1))
108
+ while IFS=$'\t' read -r _pid _owner _cwd; do
109
+ [[ "$_owner" == "foreign" ]] || continue
110
+ FGN="${FGN:+$FGN,}$_pid"
111
+ say "A running process matching '$_pat' is owned by another worktree: pid $_pid ($_cwd)"
112
+ done <<< "$_out"
113
+ else
114
+ _failed=$((_failed + 1))
115
+ say "I could not check sibling-session processes for '$_pat' (proc.sh exited $_rc)."
116
+ fi
117
+ done
118
+ if [[ -n "$FGN" ]]; then
119
+ FGN_STATE=csv
120
+ elif ((_ok > 0 && _failed == 0)); then
121
+ FGN_STATE=none
122
+ fi
123
+ fi
124
+
125
+ # --- verdict ----------------------------------------------------------------
126
+ if [[ -z "$PRS" && -z "$FGN" && "$PR_STATE" == "none" && "$FGN_STATE" == "none" ]]; then
127
+ say "No open change names #$ISSUE and no foreign gate process is running."
128
+ printf 'SOLEUR_COLLISION exit=0 prs=none foreign=none\n'
129
+ exit 0
130
+ fi
131
+
132
+ if [[ -n "$PRS" || -n "$FGN" ]]; then
133
+ say "Report the hit(s) above before work starts -- never silently continue on a live duplicate."
134
+ printf 'SOLEUR_COLLISION exit=10 prs=%s foreign=%s\n' \
135
+ "${PRS:-$PR_STATE}" "${FGN:-$FGN_STATE}"
136
+ exit 10
137
+ fi
138
+
139
+ say "The collision pre-check could not fully run; that is not a clear result."
140
+ printf 'SOLEUR_COLLISION exit=2 prs=%s foreign=%s\n' "$PR_STATE" "$FGN_STATE"
141
+ exit 2
@@ -204,6 +204,12 @@ affected_timeout() {
204
204
  # only when a CI test workflow was detected.
205
205
  AFFECTED_BUDGET_ACTIVE=0
206
206
  AFFECTED_DEADLINE=0
207
+ # The content trigger (lib content-trigger.sh) is armed by the gate only after the
208
+ # whole three-key config group validates, and made eligible only at the exits that
209
+ # ran or reported a non-`--full` verdict. Same rule as above: initialised here,
210
+ # never inherited from the caller's environment.
211
+ AFFECTED_CT_ARMED=0
212
+ AFFECTED_CT_ELIGIBLE=0
207
213
  affected_bound() {
208
214
  if [[ "$AFFECTED_BUDGET_ACTIVE" == "1" ]]; then
209
215
  local rem
@@ -297,12 +303,23 @@ _affected_cmd_vacuous() { # <command string> → rc 0 when it certifies nothing
297
303
  # global-paths | full-requested |
298
304
  # custom-command | delegated | runner-refused | runner-signal | foreign-runner |
299
305
  # no-stack | bad-config key=<k> | vacuous-test-command | no-base-ref |
300
- # toolchain-missing | no-tests | budget-deferred | bad-usage | help
306
+ # toolchain-missing | no-tests | budget-deferred | bad-usage | help |
307
+ # content-trigger-failed | inert-content-trigger
301
308
  # Counts are decimal, or `-` when the path does not produce a count
302
309
  # (delegated runner, opaque test_command, refused runs).
303
310
  finish() {
304
311
  local rc="$1" mode="${2:--}" reason="${3:--}" stack="${4:--}" ci="${5:-none}"
305
- local ran="${6:--}" of="${7:--}" skipped="${8:--}"
312
+ local ran="${6:--}" of="${7:--}" skipped="${8:--}" ct_field=""
313
+ # Content trigger (content-trigger.sh): runs the configured command after a
314
+ # passing verdict whose diff adds the configured string, folds its result into
315
+ # rc/reason, and names the outcome in one trailing marker field. The hook never
316
+ # exits and never calls finish(); an unarmed gate skips this block byte-for-byte.
317
+ if [[ "${AFFECTED_CT_ARMED:-0}" == 1 ]]; then
318
+ affected_ct_hook "$rc" "$reason"
319
+ rc="$AFFECTED_CT_OUT_RC"; reason="$AFFECTED_CT_OUT_REASON"
320
+ if [[ "${AFFECTED_CT_OUT_RESET:-0}" == 1 ]]; then mode="selected"; ran="-"; of="-"; skipped="-"; fi
321
+ ct_field="$AFFECTED_CT_OUT_FIELD"
322
+ fi
306
323
  case "$rc" in
307
324
  0)
308
325
  if [[ "$reason" == inert ]]; then
@@ -360,6 +377,6 @@ finish() {
360
377
  echo "No test suite detected in this repository; the affected-suite gate had nothing to run."
361
378
  ;;
362
379
  esac
363
- echo "AFFECTED_GATE ran=$ran of=$of skipped=$skipped mode=$mode reason=$reason stack=$stack ci=$ci"
380
+ echo "AFFECTED_GATE ran=$ran of=$of skipped=$skipped mode=$mode reason=$reason stack=$stack ci=$ci${ct_field:+ content_trigger=$ct_field}"
364
381
  exit "$rc"
365
382
  }
@@ -0,0 +1,248 @@
1
+ #!/usr/bin/env bash
2
+ # content-trigger.sh — the gate's config-declared CONTENT trigger (#10924 P4b).
3
+ #
4
+ # Sourced by plugins/soleur/scripts/affected-tests.sh. Declarations only: no
5
+ # `exit`, no top-level side effects — the one exit site stays finish() in
6
+ # common.sh, which calls affected_ct_hook just before it prints the verdict.
7
+ #
8
+ # WHAT IT IS. A selector that matches diff PATHS cannot see a test fixture that
9
+ # merely NAMES a path (a `knowledge-base/` literal in a new test file): the path
10
+ # is a test-tree path, the dependency is in the text. The three flat keys in
11
+ # `.soleur-test-gate.json` —
12
+ # content_trigger_pattern fixed string (never a regex)
13
+ # content_trigger_paths globs the scan is limited to
14
+ # content_trigger_command what to run when the string is ADDED there
15
+ # — declare one such rule. When the diff adds a line (tracked files) or holds a
16
+ # line (untracked files) containing the pattern, in a file under the globs, a
17
+ # passing run that the operator did not make `--full` additionally runs the
18
+ # command. The plugin stays repo-agnostic: nothing here names a repository suite.
19
+ #
20
+ # FAIL DIRECTION. Anything that stops the scan from deciding (no base ref, a git
21
+ # failure, a path git C-quotes, an untracked tree too large to read) RUNS the
22
+ # command. A missed ratchet is a CI-only red; a spurious run is a few minutes.
23
+ #
24
+ # Variables are `_ct_`-prefixed locals; results travel through the AFFECTED_CT_*
25
+ # globals. The scan keeps its working data in variables, never in scratch files:
26
+ # nothing to register with affected_mktemp, nothing to leak on an early exit.
27
+
28
+ AFFECTED_CT_PATTERN=""
29
+ AFFECTED_CT_COMMAND=""
30
+ AFFECTED_CT_PATHS=()
31
+
32
+ # Scan results.
33
+ AFFECTED_CT_STATE=none # none | fired | scan-error
34
+ AFFECTED_CT_LEG="" # which leg could not decide (scan-error only)
35
+
36
+ # Hook results, read by finish().
37
+ AFFECTED_CT_OUT_RC=""
38
+ AFFECTED_CT_OUT_REASON=""
39
+ AFFECTED_CT_OUT_RESET=0 # 1 => the command ran on an inert diff: finish() replaces mode and counts
40
+ AFFECTED_CT_OUT_FIELD=""
41
+
42
+ # Untracked-leg bounds: past either the verdict is "could not decide" (command runs).
43
+ # The first bounds the listing the glob loop walks, the second the per-file reads.
44
+ AFFECTED_CT_MAX_LISTED=20000
45
+ AFFECTED_CT_MAX_READ=500
46
+
47
+ # _affected_ct_in_globs <path> — rc 0 when the path matches a configured glob.
48
+ _affected_ct_in_globs() {
49
+ local _ct_p="$1" _ct_g
50
+ for _ct_g in ${AFFECTED_CT_PATHS[@]+"${AFFECTED_CT_PATHS[@]}"}; do
51
+ affected_glob_match "$_ct_p" "$_ct_g" && return 0
52
+ done
53
+ return 1
54
+ }
55
+
56
+ # affected_ct_scan — sets AFFECTED_CT_STATE / _LEG; returns at the first hit.
57
+ #
58
+ # base: --base, else origin/main, else origin/master — never @{upstream}
59
+ # (on a pushed feature branch it hides every pushed fixture);
60
+ # then `git merge-base <base> HEAD`.
61
+ # tracked: ONE `git diff -U0 --text` of the working tree against the merge-base
62
+ # (committed + staged + unstaged), parsed by an awk state machine so
63
+ # a header, a path or a removal line can never count as added text.
64
+ # `--text` makes git diff files marked `-diff`/`binary` or holding NUL.
65
+ # untracked: `git ls-files --others --exclude-standard`, limited to the globs,
66
+ # regular files only (a symlink is not read), each read with
67
+ # `grep -aqF` (as text, like the tracked leg's `--text`; under `-q` GNU grep
68
+ # exits 0 on a binary match either way, so `-a` is belt-and-braces for
69
+ # greps that would otherwise answer `Binary file matches`).
70
+ affected_ct_scan() {
71
+ AFFECTED_CT_STATE=none
72
+ AFFECTED_CT_LEG=""
73
+ local _ct_base="" _ct_mb="" _ct_b _ct_rc=0 _ct_p _ct_hits _ct_untr _ct_listed=0 _ct_read=0
74
+
75
+ if ! declare -F affected_glob_match >/dev/null 2>&1; then
76
+ AFFECTED_CT_STATE=scan-error; AFFECTED_CT_LEG="glob-matcher"; return 0
77
+ fi
78
+
79
+ if [[ -n "${ARG_BASE:-}" ]]; then
80
+ # A ref the operator named, handed to git as an operand: never an option.
81
+ if [[ "$ARG_BASE" == -* ]]; then
82
+ AFFECTED_CT_STATE=scan-error; AFFECTED_CT_LEG="bad-base"; return 0
83
+ fi
84
+ _ct_base="$ARG_BASE"
85
+ else
86
+ for _ct_b in origin/main origin/master; do
87
+ if git rev-parse --verify --quiet "$_ct_b" >/dev/null 2>&1; then
88
+ _ct_base="$_ct_b"
89
+ break
90
+ fi
91
+ done
92
+ fi
93
+ if [[ -z "$_ct_base" ]]; then
94
+ AFFECTED_CT_STATE=scan-error; AFFECTED_CT_LEG="no-base"; return 0
95
+ fi
96
+ _ct_mb="$(git merge-base "$_ct_base" HEAD 2>/dev/null)" || _ct_rc=$?
97
+ if (( _ct_rc != 0 )) || [[ -z "$_ct_mb" ]]; then
98
+ AFFECTED_CT_STATE=scan-error; AFFECTED_CT_LEG="no-merge-base"; return 0
99
+ fi
100
+
101
+ # --- tracked leg ---------------------------------------------------------
102
+ # The diff is piped straight into awk (which reads to EOF, so the producer can
103
+ # never take a SIGPIPE) and only the matching PATHS are kept, in a variable:
104
+ # no scratch file, so nothing to leak and no redirect target to prove absolute.
105
+ # pipefail (set by the gate) turns a failing `git diff` into a non-zero status.
106
+ #
107
+ # The pattern travels in the environment: `awk -v` processes backslash
108
+ # escapes, ENVIRON does not. State resets on every `diff --git`; the path comes
109
+ # from the `+++ b/<path>` header (git appends a TAB when it contains a space);
110
+ # nothing counts until the first `@@` of that file, so a header or path that
111
+ # NAMES the pattern, or a removal line, can never fire. A header git C-quotes
112
+ # (`+++ "b/..."`: a name holding a quote, backslash or control byte) cannot be
113
+ # decoded here, so a quoted-name file that adds the pattern reports `?quoted`
114
+ # and the scan declines to decide rather than dropping it.
115
+ _ct_rc=0
116
+ # `--no-renames`: a renamed file is then a delete plus an add, so moving a file that
117
+ # already names the string INTO the globs (or editing it while moving) fires, as an
118
+ # added file does; with rename detection git shows only the delta. `tr -d` keeps a
119
+ # NUL (which `--text` can emit) from truncating a line in awks that stop at one.
120
+ _ct_hits="$(git -c core.quotePath=false diff -U0 --text --no-color --no-ext-diff --no-textconv --no-renames \
121
+ --src-prefix=a/ --dst-prefix=b/ "$_ct_mb" -- 2>/dev/null \
122
+ | LC_ALL=C tr -d '\000' \
123
+ | CT_PAT="$AFFECTED_CT_PATTERN" awk '
124
+ BEGIN { pat = ENVIRON["CT_PAT"]; path = ""; inh = 0; seen = 0 }
125
+ /^diff --git / { path = ""; inh = 0; seen = 0; next }
126
+ inh == 0 && /^\+\+\+ / {
127
+ p = substr($0, 5)
128
+ sub(/\t$/, "", p)
129
+ if (substr(p, 1, 1) == "\"") path = "?quoted"
130
+ else if (substr(p, 1, 2) == "b/") path = substr(p, 3)
131
+ else path = ""
132
+ next
133
+ }
134
+ inh == 0 && /^@@ / { inh = 1; next }
135
+ inh == 1 && substr($0, 1, 1) == "+" && seen == 0 && path != "" {
136
+ if (index(substr($0, 2), pat) > 0) { print path; seen = 1 }
137
+ }
138
+ ')" || _ct_rc=$?
139
+ if (( _ct_rc != 0 )); then
140
+ AFFECTED_CT_STATE=scan-error; AFFECTED_CT_LEG="diff"; return 0
141
+ fi
142
+ while IFS= read -r _ct_p; do
143
+ [[ -n "$_ct_p" ]] || continue
144
+ if [[ "$_ct_p" == "?quoted" ]]; then
145
+ AFFECTED_CT_STATE=scan-error; AFFECTED_CT_LEG="quoted-path"; return 0
146
+ fi
147
+ if _affected_ct_in_globs "$_ct_p"; then AFFECTED_CT_STATE=fired; return 0; fi
148
+ done <<<"$_ct_hits"
149
+
150
+ # --- untracked leg -------------------------------------------------------
151
+ _ct_rc=0
152
+ _ct_untr="$(git -c core.quotePath=false ls-files --others --exclude-standard 2>/dev/null)" || _ct_rc=$?
153
+ if (( _ct_rc != 0 )); then
154
+ AFFECTED_CT_STATE=scan-error; AFFECTED_CT_LEG="ls-files"; return 0
155
+ fi
156
+ while IFS= read -r _ct_p; do
157
+ [[ -n "$_ct_p" ]] || continue
158
+ _ct_listed=$((_ct_listed + 1))
159
+ if (( _ct_listed > AFFECTED_CT_MAX_LISTED )); then
160
+ AFFECTED_CT_STATE=scan-error; AFFECTED_CT_LEG="untracked-cap"; return 0
161
+ fi
162
+ if [[ "$_ct_p" == \"* ]]; then
163
+ AFFECTED_CT_STATE=scan-error; AFFECTED_CT_LEG="quoted-path"; return 0
164
+ fi
165
+ [[ -f "$_ct_p" && ! -L "$_ct_p" ]] || continue
166
+ _affected_ct_in_globs "$_ct_p" || continue
167
+ _ct_read=$((_ct_read + 1))
168
+ if (( _ct_read > AFFECTED_CT_MAX_READ )); then
169
+ AFFECTED_CT_STATE=scan-error; AFFECTED_CT_LEG="untracked-cap"; return 0
170
+ fi
171
+ _ct_rc=0
172
+ grep -aqF -- "$AFFECTED_CT_PATTERN" "$_ct_p" 2>/dev/null || _ct_rc=$?
173
+ case "$_ct_rc" in
174
+ 0) AFFECTED_CT_STATE=fired; return 0 ;;
175
+ 1) : ;;
176
+ *) AFFECTED_CT_STATE=scan-error; AFFECTED_CT_LEG="grep"; return 0 ;;
177
+ esac
178
+ done <<<"$_ct_untr"
179
+ return 0
180
+ }
181
+
182
+ # affected_ct_hook <rc> <reason> — called by finish() (armed only) on its way out.
183
+ # Sets AFFECTED_CT_OUT_*; never exits and never calls finish().
184
+ affected_ct_hook() {
185
+ local _ct_rc="$1" _ct_reason="$2" _ct_crc=0
186
+ AFFECTED_CT_OUT_RC="$_ct_rc"
187
+ AFFECTED_CT_OUT_REASON="$_ct_reason"
188
+ AFFECTED_CT_OUT_RESET=0
189
+ AFFECTED_CT_OUT_FIELD=""
190
+
191
+ # Only the exits that set the flag are decided here. An operator's --full,
192
+ # test_command, --self-check, help, refusals and no-test exits never reach it.
193
+ [[ "${AFFECTED_CT_ELIGIBLE:-0}" == 1 ]] || return 0
194
+
195
+ # --explain: report what the scan sees, run nothing, add no marker field.
196
+ if [[ "${ARG_EXPLAIN:-0}" == 1 ]]; then
197
+ affected_ct_scan
198
+ echo "CONTENT_TRIGGER armed=1 state=${AFFECTED_CT_STATE} paths=${#AFFECTED_CT_PATHS[@]}"
199
+ return 0
200
+ fi
201
+
202
+ # A primary run that did not pass owns the verdict; the command adds nothing.
203
+ if (( _ct_rc != 0 )); then
204
+ AFFECTED_CT_OUT_FIELD=skipped
205
+ return 0
206
+ fi
207
+
208
+ affected_ct_scan
209
+ case "$AFFECTED_CT_STATE" in
210
+ none)
211
+ AFFECTED_CT_OUT_FIELD=clear
212
+ return 0 ;;
213
+ scan-error)
214
+ AFFECTED_CT_OUT_FIELD=scan-error
215
+ echo "affected-tests: the content-trigger scan could not decide (leg=$(affected_marker_field "$AFFECTED_CT_LEG")) — running the declared command." ;;
216
+ *)
217
+ AFFECTED_CT_OUT_FIELD=ran
218
+ echo "affected-tests: content trigger fired (the configured string is added under the configured paths) — running the declared command." ;;
219
+ esac
220
+
221
+ # The command's result is a gate result: it runs under the same remaining
222
+ # budget as the primary run, and its failure is the gate's failure.
223
+ affected_bound bash -c "$AFFECTED_CT_COMMAND" || _ct_crc=$?
224
+ if (( _ct_crc != 0 )); then
225
+ (( _ct_crc == 137 )) && echo "affected-tests: the content-trigger command exited 137 (SIGKILL — OOM or kill escalation), not necessarily budget expiry." >&2
226
+ if [[ ( "$_ct_crc" == 124 || "$_ct_crc" == 137 ) && "$AFFECTED_BUDGET_ACTIVE" == 1 && "${CI_NAME:-none}" != none ]]; then
227
+ AFFECTED_CT_OUT_RC=6
228
+ AFFECTED_CT_OUT_REASON=budget-deferred
229
+ AFFECTED_CT_OUT_FIELD=deferred
230
+ echo "affected-tests: the content-trigger command did not finish within the shared budget — the selected tests passed; only the command is owed to CI."
231
+ else
232
+ AFFECTED_CT_OUT_RC=1
233
+ AFFECTED_CT_OUT_REASON=content-trigger-failed
234
+ AFFECTED_CT_OUT_FIELD=failed
235
+ echo "CONTENT_TRIGGER_FAILED rc=$_ct_crc"
236
+ echo " remedy: run the content_trigger_command from .soleur-test-gate.json directly (bash -c '<command>'), fix it, re-run the gate"
237
+ fi
238
+ fi
239
+
240
+ # An inert diff that nonetheless ran the command is no longer "docs-only":
241
+ # keep the pass line honest, and keep changed-file counts (the inert path's
242
+ # unit) out of a marker that describes a command run.
243
+ if [[ "$_ct_reason" == inert ]]; then
244
+ AFFECTED_CT_OUT_RESET=1
245
+ [[ "$AFFECTED_CT_OUT_RC" == 0 ]] && AFFECTED_CT_OUT_REASON=inert-content-trigger
246
+ fi
247
+ return 0
248
+ }
@@ -127,20 +127,22 @@ Refine the idea through collaborative dialogue using the **AskUserQuestion tool*
127
127
 
128
128
  ### 0.6. Pre-Research Premise Validation (Always)
129
129
 
130
- Run BEFORE spawning any research (Phase 1) — research and downstream phases are expensive, and building a plan atop a stale premise wastes all of it. `brainstorm` Phase 1.1 does this validation when a brainstorm precedes plan, but `plan` is frequently entered directly (including the one-shot → plan path that skips brainstorm), so the cheap probe must also live here. This is distinct from Phase 1.7 reconciliation (which checks spec claims AFTER research returns) — this gate fires before research is even dispatched.
130
+ Run BEFORE spawning any research (Phase 1) — a plan atop a stale premise wastes the fan-out. `brainstorm` Phase 1.1 does this when a brainstorm precedes plan, but `plan` is frequently entered directly (including the one-shot → plan path that skips brainstorm), so the cheap probe must live here. This is distinct from Phase 1.7 reconciliation (spec claims AFTER research returns) — it fires before research is dispatched.
131
131
 
132
- This also covers your **own** option-bounding capability claims — not just cited references. Before asserting that a repo tool/skill/script "only does X" or "can't do Y" to bound the plan's options, grep/read it first or phrase it as a question (`hr-verify-repo-capability-claim-before-assert`).
132
+ This also covers your **own** capability claims — not just cited references. Before asserting that a repo tool/skill/script "only does X" or "can't do Y", grep/read it or ask (`hr-verify-repo-capability-claim-before-assert`).
133
133
 
134
134
  For every issue, blocker, dependency, or prior-art artifact the feature description **cites by reference**, verify it still holds:
135
135
 
136
136
  1. **Cited GitHub issues / PRs** (`#N`, `Closes #N`, "blocked by #N", "follow-up to #N"): run `gh issue view <N> --json state,title,closedByPullRequestsReferences` and `gh pr view <N> --json state,merged` where applicable. If a blocker is already `closed`/`merged`, or the issue this plan targets is already closed by a merged PR, **the premise is stale** — surface via **AskUserQuestion** ("Issue #N appears already resolved by PR #M. Re-scope, or close as done?") rather than planning against it.
137
- 2. **Cited file/symbol/migration paths** (a function, route, component, or migration the plan assumes exists): confirm with `git show origin/main:<path>` or `git grep -n "<symbol>" origin/main`. If the cited artifact does not exist on `origin/main`, the premise ("fix the bug in X") may really be "X was never built" — flag it; the plan's shape changes from *fix* to *build*.
138
- 3. **"UI exists but is broken" claims**: distinguish *broken behavior* from *never-built*. If the description asserts a UI/endpoint misbehaves, confirm the route/component is actually present (`git grep`) before planning a behavioral fix — a silently-absent feature needs a build plan, not a patch.
137
+ 2. **Cited file/symbol/migration paths** (a function, route, component, or migration the plan assumes exists): confirm with `git show origin/main:<path>` or `git grep -n "<symbol>" origin/main`. If the artifact is absent on `origin/main`, the premise ("fix the bug in X") may really be "X was never built" — flag it; the plan's shape changes from *fix* to *build*.
138
+ 3. **"UI exists but is broken" claims**: distinguish *broken* from *never-built* — confirm the route/component exists (`git grep`) before planning a fix; a silently-absent feature needs a build plan, not a patch.
139
139
  4. **Proposed *mechanism* vs. the ADR corpus** (the feature names HOW to do it — a frontmatter flip, a new table, a polling cron, a config tier): grep `knowledge-base/engineering/architecture/decisions/` for the mechanism's keywords (not the cited issue number — issues don't know what an ADR decided) and read any hit's `## Decision` + `## Alternatives Considered`. A mechanism sitting in an ADR's rejected-alternatives table is not an unconsidered idea — it is an explicitly-rejected one; re-scope to "did the ADR leave a gap this still addresses?" rather than planning the rejected approach. Corollary: when the feature pins an *absolute* value (a fixed model/tier/limit), check its interaction with the *most capable* end of the range, not just the cheap end (an absolute `opus` reviewer pin is a downgrade on a Fable session). **Why:** #5087 — the issue's frontmatter-tiering approach matched the exact alternative ADR-053 rejected the day before (#5096); caught only at deepen-plan, three phases deep. See `knowledge-base/project/learnings/2026-06-11-brainstorm-grep-adr-corpus-for-proposed-mechanism-not-just-issue-refs.md`.
140
140
 
141
141
  5. **The set that must do Y is whoever the Y-enforcing mechanism reaches — grep its call sites, not a nearby inventory; a shape rule over that set is a claim about every member — read each member's prescribed strings before writing it; and before designing a side channel out of a spawned CLI, run it once with `--output-format json` and read the result event.** **Why:** #8076 — the brainstorm's population (`TASK_INVENTORY`, five) was the heartbeat's liveness subset; the filing population was the nine `resolveOutputAwareOk` callers (the first missed cron fired two days after merge); a `[Scheduled]`-prefixed title rule would have broken campaign-calendar's `[Content] Overdue:` filings; a hook-written deny log plus nine caller edits dissolved once `permission_denials[]` was probed. See `knowledge-base/project/learnings/2026-09-11-a-filer-with-no-honest-exit-takes-the-free-one-at-any-price.md`.
142
142
 
143
- Emit a one-paragraph **Premise Validation** note (what was checked, what held, what was stale) into the research-insights scratch so Phase 1.7 and the plan's "Research Reconciliation" section can carry it forward. If nothing is cited by reference, state "no external premises to validate" and proceed.
143
+ 6. **Collision pre-check:** run `bash "${CLAUDE_PLUGIN_ROOT}/scripts/collision-precheck.sh" <N>` for each cited issue — open PRs naming it (`gh pr list --state open --search "<N>" -L 100`) plus foreign `proc.sh list_runs` rows; report every hit before work starts (#10333).
144
+
145
+ Emit a one-paragraph **Premise Validation** note (what was checked, what held, what was stale) into the research-insights scratch so Phase 1.7 and the plan's "Research Reconciliation" section can carry it forward. If nothing is cited, state "no external premises to validate" and proceed.
144
146
 
145
147
  ### 0.6b. Mechanism Minimality Gate (Always)
146
148
 
@@ -29,7 +29,6 @@ Review here means this agent pipeline (`rf-never-skip-qa-review-before-merging`,
29
29
 
30
30
  <requirements>
31
31
  - Git repository with GitHub CLI (`gh`) installed and authenticated
32
- - Clean main/master branch
33
32
  - Proper permissions to create worktrees and access the repository
34
33
  - For document reviews: Path to a markdown file or document
35
34
  </requirements>
@@ -46,8 +45,6 @@ if [[ -f "CLAUDE.md" ]]; then
46
45
  fi
47
46
  ```
48
47
 
49
- Read `CLAUDE.md` if it exists - apply project conventions during review.
50
-
51
48
  **A FIX COMMIT IS THE LEAST-AUDITED SURFACE IN THE DIFF — GRADE IT AS ITS OWN CHANGE.** When a commit's subject says it closes a defect class, read its NEW code for that same class before reading anything else, and check whether the fix was applied to the INSTANCE or to the CLASS (grep every other consumer of the same input). For an anchor assertion, "anchored on a call-form a comment cannot produce" is necessary and NOT sufficient: also require the haystack to be comment-STRIPPED, SCOPED to the region under test, and the match UNIQUE within it — and never accept a `grep -c … -ge N` as a placement claim, because a count is evidence about a file, never about a branch. **Why:** #7695 — `cq-assert-anchor-not-bare-token` recurred three times on one branch, twice inside the commits fixing it (one arm sat a single function below the reference implementation that comment-strips); separately, a `"actions": []` fix applied at two addresses left ~10 sibling counters blind, so three destroys of sole-copy volumes scored a clean plan with `destroy_count` 0. `T1.9c` asserted "both refusals exit non-zero" via `grep -c '^exit 1$' -ge 3` against a file containing nine, and printed `ok` with both refusals flipped to `exit 0`. See `knowledge-base/project/learnings/2026-09-04-every-fix-reintroduced-the-class-it-was-fixing.md`.
52
49
 
53
50
  **WHEN A ROW CARRIES ONE FREE-TEXT FIELD, EVERY OTHER FIELD IN IT IS A TRUSTED FIELD — READ WHERE
@@ -88,10 +85,6 @@ copy is the impoverished one. See
88
85
 
89
86
  <review_target> #$ARGUMENTS </review_target>
90
87
 
91
- <thinking>
92
- First, I need to determine the review target type and set up the code for analysis.
93
- </thinking>
94
-
95
88
  #### Immediate Actions:
96
89
 
97
90
  <task_list>
@@ -103,20 +96,19 @@ First, I need to determine the review target type and set up the code for analys
103
96
  - [ ] If ALREADY on the target branch (PR branch, requested branch name, or the branch already checked out for review) → proceed with analysis on current branch
104
97
  - [ ] If DIFFERENT branch than the review target → offer to use worktree: "Use git-worktree skill for isolated Call `skill: git-worktree` with branch name
105
98
  - [ ] Fetch PR metadata using `gh pr view --json` for title, body, files, linked issues
99
+ - [ ] Collision pre-check: `bash "${CLAUDE_PLUGIN_ROOT}/scripts/collision-precheck.sh" <N>` per linked issue — open PRs + foreign `proc.sh list_runs` rows; report hits before the panel (#10333)
106
100
  - [ ] `git fetch origin main && git merge-tree --write-tree origin/main HEAD >/dev/null; echo rc=$?` — a non-zero rc is a conflict with `main`; rebase BEFORE spawning the panel. A conflict found by a seat costs a rebase plus a second fix→CI round (PR #8052: `PROMOTED_FILES` collided with a sibling promotion, found by the code-quality seat).
107
101
  - [ ] Read `gh pr view --json mergeable,mergeStateStatus` BEFORE reading the check set as a verdict. GitHub cannot build a merge ref for a `CONFLICTING`/`DIRTY` PR, and **every `pull_request`-triggered workflow is then suppressed** — so the checks that do report (CodeQL, CLA, `push`-triggered jobs) are all green and the PR looks clean while the suites that would judge the diff never ran. An ABSENT check is not a passing one, and nothing on the PR page says so. **Why:** #8209/PR #8563 — a branch sat green-but-incomplete for a day; merging `origin/main` took the run from 4 checks to 57, two of which were red.
108
- - [ ] Set up language-specific analysis tools
109
- - [ ] Prepare security scanning environment
110
- - [ ] Make sure we are on the branch we are reviewing. Use gh pr checkout to switch to the branch or manually checkout the branch.
111
- - [ ] Push the branch before spawning the panel (`git push -u origin $(git branch --show-current)`; agents read remote state [rf-before-spawning-review-agents-push-the]) after running ship's `prepush-secret-scan.sh` (Bash `timeout: 400000`; 0/43 continue, else STOP); `incr ci_cycles` after the push.
102
+ - [ ] Use `gh pr checkout` or a manual checkout so the reviewed branch is current
103
+ - [ ] Push the branch before spawning the panel (`git push -u origin $(git branch --show-current)`; review agents read remote state [rf-before-spawning-review-agents-push-the]) after running ship's `prepush-secret-scan.sh` (Bash `timeout: 400000`; 0/43 continue, else STOP). That push drives a CI cycle — `incr ci_cycles` after it (ship's convention).
112
104
 
113
- Ensure that the code is ready for analysis (either in worktree or on current branch). ONLY then proceed to the next step.
105
+ Proceed once the tree is ready (worktree or current branch).
114
106
 
115
107
  </task_list>
116
108
 
117
109
  #### Change Classification Gate
118
110
 
119
- Before spawning review agents, classify the PR to avoid spawning agents whose expertise is irrelevant to the change.
111
+ Before spawning review agents, classify the PR to right-size the panel.
120
112
 
121
113
  1. Run `git diff --name-only origin/main...HEAD | head -n 200` to get the list of changed files. Also capture status letters and line counts. Use `git rev-parse --git-dir` to resolve a writable tmp path that works in both regular checkouts and worktrees: in a worktree `.git` is a file (gitdir pointer), not a directory, so `> .git/review-*.txt` fails with `Not a directory (os error 20)`. The resolver returns the worktree's actual gitdir (e.g., `<bare>/worktrees/<name>/`):
122
114
 
@@ -198,8 +190,10 @@ Before spawning review agents, classify the PR to avoid spawning agents whose ex
198
190
  Spawned agents run only the suites targeting the files they were given — mechanically,
199
191
  `bash "${CLAUDE_PLUGIN_ROOT}/scripts/affected-tests.sh"` — it delegates `--affected`
200
192
  to a capability-positive [runner](../../../../scripts/test-all.sh) when present, else its
201
- stack adapters select; the founder-repo runner-side equivalent is
202
- `TEST_GROUP=affected bash scripts/test-all.sh`. No hand-derived suite list is needed.
193
+ stack adapters select. A spawned agent handed an EXPLICIT file list may instead run
194
+ `TEST_GROUP=affected bash scripts/test-all.sh` — a DIFFERENT, heuristic selector (#8591)
195
+ that prints `[affected] MODE=full` and runs nearly everything on an undecidable diff
196
+ (2026-10-15 `apps/web-platform/infra/`: ran >1h).
203
197
  **`SOLEUR_SUBAGENT=1` is a
204
198
  convention a lead MAY export before spawning — the harness does not set it** (measured 2026-08-19:
205
199
  UNSET inside spawned agents). When it IS exported, a plain `test-all.sh` invocation exits 4 while `affected`
@@ -207,7 +201,12 @@ proceeds. Agents must not run the runner unscoped,
207
201
  `apps/web-platform/infra/run-registered-suites.sh`, or any other full-gate runner: this panel is
208
202
  the densest concurrency in the whole pipeline, and concurrent full-gate runs inflate each other's
209
203
  timings and corrupt the measurement (860→1675 s, 2026-08-11). The lead runs the gate ONCE after the
210
- panel returns — `bash "${CLAUDE_PLUGIN_ROOT}/scripts/affected-tests.sh"` ([contract](${CLAUDE_PLUGIN_ROOT}/skills/ship/references/affected-gate-contract.md)); absent a [runner](../../../../scripts/test-all.sh) it is the sole scope. Two backstops:
204
+ panel returns — the bounded default `bash scripts/test-all.sh` (bare resolves `--affected`;
205
+ plugin-portable: `bash "${CLAUDE_PLUGIN_ROOT}/scripts/affected-tests.sh"`, sole scope absent a
206
+ [runner](../../../../scripts/test-all.sh) — [contract](${CLAUDE_PLUGIN_ROOT}/skills/ship/references/affected-gate-contract.md)),
207
+ previewed by `bash scripts/test-all.sh --print-selection` and reported with the `selected N of M`:
208
+ "every covering suite ran" is the printed selection vs the run's per-suite results, not memory
209
+ (#10333). Two backstops:
211
210
  [scripts/test-all.sh](../../../../scripts/test-all.sh) exits 4 when it MEASURES a sibling full-gate run already in flight
212
211
  (#7553) — `affected` is exempt from that too — and `tc_acquire`'s advisory lock (ADR-133)
213
212
  serialises whatever gets past that. The
@@ -255,13 +254,13 @@ Record `PANEL_SHA=$(git rev-parse HEAD)` before dispatch — fix rounds diff aga
255
254
 
256
255
  </parallel_tasks>
257
256
 
258
- **Note:** The conditional agents block below (agents 9-14: Rails reviewers, migration experts, soleur:engineering:review:test-design-reviewer, semgrep) is **unaffected** by the classification gate. Both gates run independently — the classification controls only the always-on agents above.
257
+ **Note:** the conditional agents below (9-14) are unaffected by the classification gate — it controls only the always-on agents above.
259
258
 
260
259
  #### Conditional Agents (Run if applicable):
261
260
 
262
261
  <conditional_agents>
263
262
 
264
- These agents are run ONLY when the PR matches specific criteria. Check the PR files list and project structure to determine if they apply:
263
+ These agents run ONLY when the PR matches the criteria below:
265
264
 
266
265
  **If project is a Rails app (Gemfile AND config/routes.rb exist at repo root):**
267
266
 
@@ -361,7 +361,8 @@ Then run the affected-suite gate — the plugin entry point, wired the same in
361
361
  repo the gate capability-probes and delegates [scripts/test-all.sh](../../../../scripts/test-all.sh), so the
362
362
  always-on fast tier (#9763), ADR-262's PR-gated mutation batteries, and the
363
363
  infra consumed edge still apply — and a docs-only diff returns
364
- `NO_TESTS_AFFECTED`, which is not coverage.
364
+ `NO_TESTS_AFFECTED`, which is not coverage. Preview with
365
+ `bash scripts/test-all.sh --print-selection`, stating `selected N of M` (#10333).
365
366
 
366
367
  **Probe capacity first (#7545).** An affected run can still DEGRADE to the
367
368
  full battery (undecidable diff, runner/index touched, FORCE_ALL), so spend ~3 s
@@ -372,8 +373,8 @@ bash scripts/test-all.sh --capacity
372
373
  ```
373
374
 
374
375
  It prints one verdict — `CAPACITY_OK` / `CAPACITY_CONTENDED reason=…` / `CAPACITY_UNKNOWN reason=…`,
375
- each with the measured value and the threshold — plus the pid, worktree and elapsed time of every
376
- sibling run. It takes no lock, runs no suite and always exits 0.
376
+ each with the measured value and threshold — plus pid, worktree and elapsed time per sibling run.
377
+ It takes no lock, runs no suite and always exits 0.
377
378
 
378
379
  **It does not gate this phase and must never be treated as permission to skip it.** A
379
380
  `CAPACITY_CONTENDED` verdict changes what a RED below is *worth* (apply
@@ -397,8 +398,8 @@ from a `pull_request` run — which GitHub builds against `refs/pull/N/merge`. C
397
398
  therefore verified `merge(HEAD, base)`, not the HEAD tree the local battery would
398
399
  run, and those are the same tree only when `origin/main` is already an ancestor of
399
400
  HEAD. The gate refuses when it is not, so "CI already verified this exact tree" is
400
- a claim it establishes rather than one it assumes. The practical consequence: to
401
- get the saving on a re-run, sync with `main` first.
401
+ a claim it establishes rather than assumes. Re-run savings need `main` synced
402
+ first.
402
403
 
403
404
  Branch on the exit code, never on the prose:
404
405