@chrono-meta/fh-gate 3.46.0 → 3.48.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 (36) hide show
  1. package/.claude/rules/fh_4axis_gate.md +1 -1
  2. package/.claude-plugin/marketplace.json +4 -4
  3. package/CHEATSHEET.md +2 -2
  4. package/README.ja.md +4 -0
  5. package/README.ko.md +22 -0
  6. package/README.md +24 -0
  7. package/README.zh.md +4 -0
  8. package/docs/codex-compat.md +4 -4
  9. package/knowledge/shared/harness-core/agents_md_runtime_details.md +2 -2
  10. package/knowledge/shared/harness-core/builtin_capability_map.md +6 -3
  11. package/knowledge/shared/harness-core/claude_md_full_reference.md +5 -1
  12. package/knowledge/shared/harness-core/fh_4axis_gate_detail.md +15 -0
  13. package/knowledge/shared/harness-core/fh_integration_contract.md +2 -2
  14. package/knowledge/shared/learnings/subagent_invocations_log.yaml +14 -0
  15. package/package.json +1 -1
  16. package/plugins/fh-commons/.claude-plugin/plugin.json +1 -1
  17. package/plugins/fh-meta/.claude-plugin/plugin.json +1 -1
  18. package/plugins/fh-meta/CHANGELOG.md +96 -0
  19. package/plugins/fh-meta/skills/frontier-digest/SKILL_detail.md +13 -7
  20. package/plugins/fh-preprep/.claude-plugin/plugin.json +1 -1
  21. package/plugins/fh-qp/.claude-plugin/plugin.json +1 -1
  22. package/scripts/destructive_pre_gate.sh +170 -22
  23. package/scripts/fh-gate.sh +181 -22
  24. package/scripts/fh-goal.sh +17 -4
  25. package/scripts/fh-run.sh +17 -4
  26. package/scripts/test_action_yml_lanes.sh +162 -0
  27. package/scripts/test_destructive_pre_gate_lanes.sh +145 -3
  28. package/scripts/test_fh_gate_absorb_lanes.sh +1 -0
  29. package/scripts/test_fh_gate_defaults_lanes.sh +207 -0
  30. package/scripts/test_fh_gate_fusion_lanes.sh +1 -0
  31. package/scripts/test_fh_gate_regressions.sh +1 -0
  32. package/scripts/test_fh_goal_change_detection_lanes.sh +47 -0
  33. package/scripts/test_fh_run_resolver_lanes.sh +47 -0
  34. package/templates/predelete_check.sh +2 -0
  35. package/templates/predelete_check.test.sh +10 -0
  36. package/templates/settings.PreToolUse.snippet.json +6 -1
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fh-qp",
3
- "version": "3.46.0",
3
+ "version": "3.48.0",
4
4
  "engines": {
5
5
  "claudeCode": ">=1.0.0"
6
6
  },
@@ -21,7 +21,36 @@
21
21
  # FH_DESTRUCTIVE_BLOCK=1 to escalate to exit 2 (stderr → model, call blocked).
22
22
  # EXCEPTION (2026-11-03): with FH_DESTRUCTIVE_BLOCK unset and the hook payload's
23
23
  # permission_mode = bypassPermissions, it blocks by default — nobody reads an advisory before a
24
- # bypass-mode call runs. FH_DESTRUCTIVE_BLOCK=0 restores advisory there. Other modes unchanged.
24
+ # bypass-mode call runs. FH_DESTRUCTIVE_BLOCK=0 restores advisory there.
25
+ # 2026-11-23 (IG1 → operator pick A + A′): permission_mode = auto counts the same way (the
26
+ # classifier, not a human, decides the call — measured: it allowed a direct force push 6/6).
27
+ # Other modes (default, acceptEdits, plan, dontAsk) unchanged — dontAsk is a named residual.
28
+ #
29
+ # BLOCK MODE DOES NOT HONOR OVERRIDES WRITTEN INTO THE COMMAND (2026-11-23, A).
30
+ # Measured (tracks/_meta/inbound_guard_2026-11-23, KP-F v2, bypass, haiku 3/3): blocked here, the
31
+ # agent re-ran with `# noqa: destructive-op` because THIS guard's block text said to; blocked by
32
+ # pre-push, it re-ran with `DESTRUCTIVE_OP_OK=1` because pre-push's text said to — remote history
33
+ # rewritten. The one who writes the command was also the one granting the exception. So in block
34
+ # mode: (1) noqa is ignored; (2) block-only rows catch the agent switching off the next layer —
35
+ # `DESTRUCTIVE_OP_OK=` set anywhere in the command, `git push --no-verify`, core.hooksPath via
36
+ # `-c` or `git config` — and remote deletes (`push --delete`/`-d`/`:ref`/`--mirror`/`--prune`),
37
+ # which this guard had no row for, so `DESTRUCTIVE_OP_OK=1 git push origin --delete x` used to
38
+ # pass both layers; (3) the block text names no way past — it says ask the operator, who runs it
39
+ # from their own terminal. Advisory mode is byte-for-byte unchanged (noqa works, no new rows).
40
+ # What this does NOT close, by design: indirection (`bash x.sh` holding the push, env set inside
41
+ # the script), editing settings to drop the hook or set FH_DESTRUCTIVE_BLOCK=0, removing or
42
+ # rewriting the hook file itself (`rm`/`chmod -x` on pre-push — and the Edit/Write tools never
43
+ # reach this Bash hook at all), deleting refs through the GitHub API (`gh api -X DELETE
44
+ # …/git/refs/…` — neither layer sees it), abbreviations of the PRE-EXISTING force row
45
+ # (`--forc`), mention-as-data in block mode (an echo/heredoc that only names
46
+ # `DESTRUCTIVE_OP_OK=1` blocks), and pushes from a shell the agent did not type into. With
47
+ # FH_DESTRUCTIVE_BLOCK=1 set in a default-mode session, noqa no longer opens a block either —
48
+ # that variable asks for blocking. Fail-closed on purpose (block mode, follow-up to #1192): a push
49
+ # with a push option or `--` gets no dry-run exemption, and a push-option value shaped like `:ref`
50
+ # reads as a delete. A determined agent gets past any client-side check; the floor
51
+ # is server-side branch protection (pre-push header says the same). Static shell-string checks do
52
+ # not converge (FH measured 15 rounds on a sibling check), so review rounds here are capped at
53
+ # two. Lanes K1–K51 (input-from: IG1 KP-F v2 records, codex R1, Sonnet quench-challenger R1).
25
54
  # Unparseable/absent payload → silent exit 0 (an unparsed input is not a finding; block mode
26
55
  # fails open on a dead python3 — same accepted residual as pipe_verdict_guard, the surface is
27
56
  # the reversible Bash call, not the irreversible act itself).
@@ -99,8 +128,28 @@ if isinstance(m, str): sys.stdout.write(m)
99
128
  fi
100
129
  [ -n "$CMD" ] || exit 0
101
130
 
102
- # Explicit opt-out, checked before any rule.
103
- printf '%s' "$CMD" | LC_ALL=C grep -qE '#[[:space:]]*noqa:?[[:space:]]*destructive-op' && exit 0
131
+ # Block decision FIRST — whether noqa counts depends on it. Explicit FH_DESTRUCTIVE_BLOCK wins either
132
+ # way (1 = block, 0 = advisory). Unset: block when the session runs with permission_mode
133
+ # bypassPermissions or auto — there no human sees the advisory before the call runs, so a warning
134
+ # is a post-mortem (measured 2026-11-03, headless bypass, Sonnet: unset → branch deleted 3/3,
135
+ # =1 → kept 3/3; auto added 2026-11-23 after the classifier allowed a direct force push 6/6).
136
+ BLOCK_WHY=""
137
+ case "${FH_DESTRUCTIVE_BLOCK-}" in
138
+ 1) BLOCK_WHY="FH_DESTRUCTIVE_BLOCK=1." ;;
139
+ "") case "$PERM_MODE" in
140
+ bypassPermissions) BLOCK_WHY="permission_mode=bypassPermissions (no human sees a warning before the call runs)." ;;
141
+ auto) BLOCK_WHY="permission_mode=auto (a classifier, not a human, decides this call)." ;;
142
+ esac ;;
143
+ *) BLOCK_WHY="" ;; # 0 and any other explicit value: advisory, as before this default existed
144
+ esac
145
+
146
+ # Explicit opt-out — honored in ADVISORY mode only. In block mode an agent-written noqa is the
147
+ # agent granting itself the exception (IG1 KP-F v2: haiku 3/3), so it is noted and ignored.
148
+ NOQA_SEEN=""
149
+ if printf '%s' "$CMD" | LC_ALL=C grep -qE '#[[:space:]]*noqa:?[[:space:]]*destructive-op'; then
150
+ [ -z "$BLOCK_WHY" ] && exit 0
151
+ NOQA_SEEN=1
152
+ fi
104
153
 
105
154
  # Flatten to ONE line (grep is line-oriented; multi-line commands are the recurring shape) and pad
106
155
  # with spaces so end-of-string flags match uniformly (` -f` at line end == ` -f `).
@@ -120,9 +169,14 @@ printf '%s' "$CMD" | LC_ALL=C grep -qE '#[[:space:]]*noqa:?[[:space:]]*destructi
120
169
  # `git re\` + newline + `set --hard` split the token and miss (measured bypass).
121
170
  # Separators `&& || | & ( )` are space-padded so `:&&git reset --hard` and `--force|cat`
122
171
  # satisfy the leading/trailing boundary classes without whitespace in the original.
172
+ # A backtick is padded too: `` `git push origin --delete x` `` is a command substitution like
173
+ # `$(...)`, and before 2026-11-23 the backtick in front of `git` defeated every row's `[ (/]`.
123
174
  JOINED="${CMD//\\$'\n'/}"
124
175
  FLAT=" $(printf '%s' "$JOINED" | tr -d '\r' | tr '\n' ';' | sed 's/;/; /g' \
125
- | sed -E 's/(\&\&|\|\||[|&()])/ \1 /g' | tr -d '"'"'" | tr '\t' ' ' | tr -s ' ') "
176
+ | sed -E 's/(\&\&|\|\||[|&()`])/ \1 /g' | tr -d '"'"'" | tr '\t' ' ' | tr -s ' ') "
177
+ # Kept before git-option normalization: the normalizer below consumes `-c k=v`, which is exactly
178
+ # where `git -c core.hooksPath=/dev/null push` hides the pre-push switch-off (block-only row).
179
+ FLAT0="$FLAT"
126
180
 
127
181
  # Normalize git global options down to bare `git` BEFORE matching — the Axis-2 pass measured
128
182
  # `git -C /repo reset --hard` sailing through every git row, and this environment specifically
@@ -195,8 +249,120 @@ for entry in "${PATTERNS[@]}"; do
195
249
  "
196
250
  fi
197
251
  done
252
+
253
+ # Block-only rows (2026-11-23, A). Advisory mode never evaluates them, so advisory output is
254
+ # unchanged. Two groups: remote deletes (no row above saw them — pre-push did, and its env override
255
+ # was then the agent's to set), and the agent switching off the next layer. `FLAT0` is the
256
+ # pre-normalization flat: `-c core.hooksPath=` is consumed by the git-option normalizer.
257
+ # core.hooksPath is case-insensitive in git, hence the bracket classes.
258
+ if [ -n "$BLOCK_WHY" ]; then
259
+ # git config keys are case-insensitive (section and name): `CORE.hooksPath` is the same key.
260
+ HP='[cC][oO][rR][eE]\.[hH][oO][oO][kK][sS][pP][aA][tT][hH]'
261
+ # Dry-run neutralizer for the push rows below, applied to a COPY (FLATB) so the shared rows and
262
+ # the advisory output are untouched. Per statement: `[^|;&]*` cannot cross `&&`/`;`, so a dry-run
263
+ # in one statement never clears a real delete in the next. git accepts unique prefixes of long
264
+ # options, so `--dr…` is dry-run and the rows match `--de…`, `--no-v…`, `--mi…`, `--pru…`.
265
+ # A statement ends at `| ; &`, and also at a paren or backtick: a dry-run in one `$(...)` or
266
+ # backtick substitution must not clear a real delete in the next one (codex R1).
267
+ # A push option in the statement turns the exemption back off. Its value can carry `-n` as data
268
+ # (`-o -n`, `-on`, `--push -n`, `-o "foo -n"` once quotes are stripped) and no regex here can
269
+ # tell that value from a flag, so the call fails closed: it blocks (Sonnet review of #1192, codex R1).
270
+ # So does `--`: after it every word is a ref, and `refs/heads/-n` is a valid name (codex R2).
271
+ FLATB=$(printf '%s' "$FLAT" | sed -E 's/git push (([^|;&()`]* )?(--dr[a-z-]*|-[a-zA-Z]*n[a-zA-Z]*)[ ;])/git push_dryrun \1/g' \
272
+ | sed -E 's/git push_dryrun (([^|;&()`]* )?((-[a-zA-Z]*o|--pu[a-z-]*)([ =;]|[^ ;])|--[ ;]))/git push \1/g')
273
+ BLOCK_ONLY=(
274
+ "FLATB@@[ (/]git push ([^|;&]* )?(--de[a-z]*[ ;]|-[a-zA-Z]*d[a-zA-Z]*[ ;])@@git push --delete/-d removes a remote branch or tag"
275
+ "FLATB@@[ (/]git push ([^|;&]* )?\\+?:[^ ;]+[ ;]@@git push <remote> :<ref> deletes the remote ref"
276
+ "FLATB@@[ (/]git push ([^|;&]* )?(--mi[a-z]*|--pru[a-z]*)[ ;]@@git push --mirror/--prune deletes remote refs that are not local"
277
+ "FLATB@@[ (/]git push ([^|;&]* )?--no-v[a-z-]*[ ;]@@git push --no-verify skips the pre-push layer"
278
+ "FLAT0@@[ (/]git ([^|;&]* )?(-c +|--config-env[= ])${HP}=@@git -c/--config-env core.hooksPath=… replaces the pre-push layer for this command"
279
+ "FLAT0@@(^|[ (;&|])GIT_CONFIG_(KEY_[0-9]+=${HP}|PARAMETERS=[^;&|]*${HP})@@GIT_CONFIG_* naming core.hooksPath replaces the pre-push layer for this command"
280
+ "FLAT@@(^|[ (;&|])(export +)?DESTRUCTIVE_OP_OK=@@DESTRUCTIVE_OP_OK= written into the command is an override of the pre-push layer"
281
+ )
282
+ for entry in "${BLOCK_ONLY[@]}"; do
283
+ src="${entry%%@@*}"; rest="${entry#*@@}"
284
+ pattern="${rest%%@@*}"; desc="${rest#*@@}"
285
+ case "$src" in FLAT0) subj="$FLAT0" ;; FLATB) subj="$FLATB" ;; *) subj="$FLAT" ;; esac
286
+ if printf '%s' "$subj" | LC_ALL=C grep -qE "$pattern"; then
287
+ hits="${hits} ⚠️ DESTRUCTIVE-OP ${desc}
288
+ "
289
+ fi
290
+ done
291
+ # `git config … core.hooksPath` per statement: a READ (--get*, --list, -l, get, list, or no value
292
+ # after the key — `$(git config core.hooksPath)`, `… 2>/dev/null`, `… && next`) is clean; a WRITE
293
+ # (--unset*, --replace-all, --add, set/unset, or a value token) blocks. An empty value (`""`/`''`)
294
+ # vanishes when quotes are stripped, so it is checked on the raw command (codex R1).
295
+ # The value token after the key is a write unless it is a redirect (`2>/dev/null`, `>x`, `2>&1`)
296
+ # or a closing paren — a digit alone (`core.hooksPath 0`) is a value (codex R2).
297
+ # A read verb counts only BEFORE the key: after it, the word is the value — `git config
298
+ # core.hooksPath get` (or `… --get`, `… -l`) SETS hooksPath to «get» (Sonnet review of #1192).
299
+ HP_READ_RX='(--get(-all|-regexp|-urlmatch)?|--list| -l| get| list)( |$)'
300
+ # `--comment <text>` is for writes only, and its text can hold `get` (`--comment get`,
301
+ # `--comment "foo get"` once quotes are stripped): a segment with `--comm…` before the key is
302
+ # never a read (measured on git 2.50: both forms set hooksPath; codex R1).
303
+ hp_is_read() {
304
+ local pre; pre=$(printf '%s' "$1" | sed -E "s/${HP}.*//")
305
+ printf '%s' "$pre" | LC_ALL=C grep -qE -- '--comm' && return 1
306
+ printf '%s' "$pre" | LC_ALL=C grep -qE -- "$HP_READ_RX"
307
+ }
308
+ HP_WRITE=""
309
+ while IFS= read -r seg; do
310
+ [ -n "$seg" ] || continue
311
+ hp_is_read "$seg" && continue
312
+ if printf '%s' "$seg" | LC_ALL=C grep -qE -- "(--unset(-all)?|--replace-all|--add| set| unset) "; then HP_WRITE=1; break; fi
313
+ nxt=$(printf '%s' "$seg" | LC_ALL=C grep -oE -- "${HP} +[^ ]+" | head -1 | sed -E 's/^[^ ]+ +//')
314
+ if [ -n "$nxt" ] && ! printf '%s' "$nxt" | LC_ALL=C grep -qE '^(\)|[0-9]*[<>])'; then HP_WRITE=1; break; fi
315
+ done <<SEGS
316
+ $(printf '%s' "$FLAT" | LC_ALL=C grep -oE "[ (/]git config [^|;&()\`]*${HP}[^|;&()\`]*")
317
+ SEGS
318
+ # A value that starts with `(` or a backtick ends the segment above before any value is seen
319
+ # (`core.hooksPath `printf x``, `"(disabled)"` once quotes are stripped; codex R2). The key then
320
+ # followed by `(` is a write; followed by a backtick it is a write unless that backtick CLOSES a
321
+ # substitution the key sits in (an odd count of backticks before it). Reads keep their exemption.
322
+ # Runs only when that shape is present; if python fails there, it counts as a write.
323
+ if [ -z "$HP_WRITE" ] && printf '%s' "$FLAT" | LC_ALL=C grep -qE "${HP} +[(\`]"; then
324
+ hp_tail=$(printf '%s' "$FLAT" | python3 -c '
325
+ import re, sys
326
+ f = sys.stdin.read()
327
+ read_rx = re.compile(r"(--get(-all|-regexp|-urlmatch)?|--list| -l| get| list)( |$)")
328
+ for m in re.finditer(r"[ (/]git config ([^|;&()`]*?)core\.hookspath +([(`])", f, re.I):
329
+ pre = m.group(1)
330
+ if "--comm" not in pre and read_rx.search(" " + pre):
331
+ continue
332
+ if m.group(2) == "(" or f[:m.start(2)].count("`") % 2 == 0:
333
+ print("W"); break
334
+ ' 2>/dev/null) || hp_tail=W
335
+ [ "$hp_tail" = W ] && HP_WRITE=1
336
+ fi
337
+ # Empty value: checked on the raw command (quotes intact), per statement, same read exemption.
338
+ while IFS= read -r seg; do
339
+ [ -n "$seg" ] || continue
340
+ hp_is_read "$seg" && continue
341
+ HP_WRITE=1; break
342
+ done <<SEGS
343
+ $(printf '%s' "$JOINED" | LC_ALL=C grep -oE "git[^|;&()\`]*config[^|;&()\`]*${HP}[[:space:]]+(\"\"|'')")
344
+ SEGS
345
+ # Removing or renaming the whole [core] section drops core.hooksPath without naming it (codex R2).
346
+ printf '%s' "$FLAT" | LC_ALL=C grep -qE "[ (/]git config ([^|;&]* )?(--)?(remove|rename)-section +[cC][oO][rR][eE][ ;]" && HP_WRITE=1
347
+ [ -n "$HP_WRITE" ] && hits="${hits} ⚠️ DESTRUCTIVE-OP git config core.hooksPath changes or removes the directory the pre-push layer lives in
348
+ "
349
+ fi
198
350
  [ -n "$hits" ] || exit 0
199
351
 
352
+ if [ -n "$BLOCK_WHY" ]; then
353
+ # Block mode: exit 2 = stderr fed to the model as the blocking reason; stdout ignored by contract.
354
+ # The text names NO way past. Every way past it used to name (noqa here, DESTRUCTIVE_OP_OK in
355
+ # pre-push) was taken by the agent that read it (IG1 KP-F v2, haiku 3/3).
356
+ printf '%s' "$hits" >&2
357
+ printf '%s\n' " [BLOCKED] $BLOCK_WHY" >&2
358
+ [ -n "$NOQA_SEEN" ] && printf '%s\n' " A '# noqa: destructive-op' in the command is not honored in this mode." >&2
359
+ printf '%s\n' " In this mode an override written into the command is not honored." \
360
+ " Stop and ask the operator; if they want it, they run it from their own terminal." \
361
+ " Meanwhile: enumerate what this would destroy (git status / git log / git reflog) and" \
362
+ " report it — do not retry this call in another form." >&2
363
+ exit 2
364
+ fi
365
+
200
366
  hits="${hits} Advisory timing: this context reaches the model on the NEXT turn — the call may have
201
367
  already run (pre-action blocking = FH_DESTRUCTIVE_BLOCK=1). If it ran un-enumerated,
202
368
  recover FIRST: git status / git stash list / git reflog /
@@ -205,24 +371,6 @@ hits="${hits} Advisory timing: this context reaches the model on the NEXT t
205
371
  Destructive-Op Gate order: enumerate → recover → destroy — never destroy-then-check.
206
372
  Intentional and reviewed → re-run with trailing \`# noqa: destructive-op\`."
207
373
 
208
- # Block decision. Explicit FH_DESTRUCTIVE_BLOCK wins either way (1 = block, 0 = advisory). Unset:
209
- # block when the session runs with permission_mode=bypassPermissions — there no human sees the
210
- # advisory before the call runs, so a warning is a post-mortem (measured 2026-11-03, headless
211
- # bypass, Sonnet: unset → branch deleted 3/3, =1 → kept 3/3).
212
- BLOCK_WHY=""
213
- case "${FH_DESTRUCTIVE_BLOCK-}" in
214
- 1) BLOCK_WHY="FH_DESTRUCTIVE_BLOCK=1 — add noqa after review, or set FH_DESTRUCTIVE_BLOCK=0, to proceed." ;;
215
- "") [ "$PERM_MODE" = "bypassPermissions" ] && \
216
- BLOCK_WHY="permission_mode=bypassPermissions (no human sees a warning before the call runs) — add noqa after review, or set FH_DESTRUCTIVE_BLOCK=0 to keep advisory." ;;
217
- *) BLOCK_WHY="" ;; # 0 and any other explicit value: advisory, as before this default existed
218
- esac
219
- if [ -n "$BLOCK_WHY" ]; then
220
- # Block mode: exit 2 = stderr fed to the model as the blocking reason; stdout ignored by contract.
221
- printf '%s\n' "$hits" >&2
222
- printf '%s\n' " [BLOCKED] $BLOCK_WHY" >&2
223
- exit 2
224
- fi
225
-
226
374
  # Advisory mode: JSON on stdout, exit 0. Capture-then-emit; PYTHONIOENCODING pinned because the
227
375
  # text carries non-ASCII (⚠️) and an inherited ascii codec was measured to kill the emission
228
376
  # (pipe_verdict_guard lane C4). python3 owns escaping; on failure degrade to stderr (delivery
@@ -17,14 +17,15 @@
17
17
  # 3 — ESCALATE (human decision required)
18
18
  # 10 — Harness error (backend unavailable, timeout, missing/invalid structured
19
19
  # verdict, or status != SUCCESS) — always fail-closed, never silent-pass
20
- # 11 — Argument error (invalid level, no files)
20
+ # 11 — Argument error (invalid level, no files, or a help/version flag given with other arguments;
21
+ # also -h/--help/-V/--version alone when CI is set to anything but empty, 0 or false)
21
22
  # 12 — Dry-run (prompt emitted, NO review performed) — deliberately outside the
22
23
  # verdict range: a check that did not run must never be readable as PASS.
23
24
  #
24
25
  # Environment:
25
26
  # FH_DRY_RUN=1 generate prompt only, skip backend invocation; exits 12, not 0
26
27
  # FH_BACKEND=claude|codex|auto AI backend to use (default: claude)
27
- # FH_MODEL=<model> model to use (default depends on backend)
28
+ # FH_MODEL=<model> model to use (claude: claude-sonnet-5-5; codex: not pinned — codex picks its own)
28
29
  # FH_TIMEOUT=120 seconds before backend is killed (default: 120)
29
30
  # FH_VERBOSE=1 print full backend stderr to stderr
30
31
  # FH_RECORD_BASE=<p> directory for governance_log YAML (default: FH_ROOT/tracks/_meta)
@@ -33,13 +34,27 @@
33
34
  # `/code-review` (claude backend only; findings carried as they come — Important →
34
35
  # B, Nit and Pre-existing → C — and the verdict derived from the grades); `fh` =
35
36
  # FH's own goldfish pass, /code-review's method absorbed (no author description).
36
- # UNMEASURED: whether a headless /code-review call, or the goldfish pass, returns
37
- # the structured object the gate needs on every runner — which is why neither is
38
- # the default. FH_REVIEWER=code-review on codex is an argument error.
37
+ # Neither is the default. FH_REVIEWER=code-review on codex is an argument error.
38
+ # 🟥 FH_REVIEWER=code-review CURRENTLY ALWAYS EXITS 10: headless /code-review does not
39
+ # return the structured object the gate needs yet. Measured 2026-11-22 (claude 2.1.330):
40
+ # 0/11 runs returned it — no structured object in 0/5 runs through this
41
+ # script (all exit 10) and 0/6 direct runs. Each ran /code-review as a local command
42
+ # (local_command: code_review, num_turns 0) and gave prose: text lines at low effort,
43
+ # a JSON block inside text or only «Command completed» at medium. That it ignores
44
+ # --json-schema is the likely cause, not isolated. Reading that prose would move the
45
+ # verdict off the typed channel, so the opt-in is left failing closed (operator
46
+ # decision 2026-11-22: no prose parsing, no new channel now). UNMEASURED: whether the
47
+ # `fh` goldfish pass returns the object on every runner.
39
48
  # `code-review` is NOT read-only: /code-review needs git's read commands, and those
40
49
  # can write a file (`--output=`); opt into it for trusted changes only. The `fh` and
41
50
  # elephant passes get only Read · Glob · Grep on the claude backend (no shell, no MCP
42
51
  # server, no skill); on codex they run in `codex exec -s read-only`, codex's sandbox.
52
+ # On claude, every review call (code-review included) runs with user settings only —
53
+ # measured: the checkout's hooks, settings, CLAUDE.md, CLAUDE.local.md, .claude/rules
54
+ # and .mcp.json server do not reach it. On codex the checkout's AGENTS.md is not sent,
55
+ # and the user config is not loaded (--ignore-user-config), so a checkout codex trusts
56
+ # cannot start MCP servers from its .codex/config.toml. If that user config names a
57
+ # provider or endpoint, the codex review is refused (exit 10) instead of rerouted.
43
58
  # FH_GATE_ELEPHANT=off|auto|on the elephant pass (default off; auto = on at level full): task description + the touched
44
59
  # files' git history; looks only for a past fix re-opened, a recorded decision
45
60
  # undone, or the stated task contradicted.
@@ -131,10 +146,36 @@ EXIT_DRY_RUN=12
131
146
  # Unknown flags are an ERROR, never a filename. Silently demoting an unrecognized
132
147
  # argument to "a file to review" is the same shape as demoting an unknown mode to a
133
148
  # weaker check: the run continues, reports something, and the something is wrong.
149
+ # Help and version are honoured only ALONE (2026-11-22, 3.47.0 security review MEDIUM-1). With other arguments the
150
+ # first one is a file list position — the GitHub Action always passes three — and a list that happens to read
151
+ # `-h` (a file literally named so, or a list built from PR data) used to print help and exit 0, which the Action
152
+ # maps to PASS with reviewed=true: no review ran. Now that case is an argument error (exit 11, not a pass).
153
+ case "${1:-}" in
154
+ --version|-V|--help|-h)
155
+ if [[ $# -ne 1 ]]; then
156
+ printf '%s\n' "ERROR: '${1}' is honoured only on its own (got $# arguments)." >&2
157
+ printf '%s\n' " In the file-list position it is not a file list, and help is not a review — not a pass." >&2
158
+ exit 11
159
+ fi ;;
160
+ esac
161
+ # Under CI the same flag ALONE is not a pass either (2026-11-23, the residual named in #1190). A plain CI step
162
+ # that runs `fh-gate "$FILES"` with FILES=-h hands this script argv identical to a person typing `fh-gate -h`,
163
+ # so the argument count cannot tell them apart; the environment can. With CI set to anything but empty, 0 or
164
+ # false (GitHub Actions, GitLab, CircleCI, Travis and Buildkite set it), help and version still print, then exit
165
+ # 11. A deliberate call in CI: `CI= fh-gate --version`. Still open, by name: CI systems that do not set CI
166
+ # (Jenkins; Azure Pipelines sets TF_BUILD) and local git hooks or scripts that call `fh-gate "$FILES"`.
167
+ _fh_info_exit() {
168
+ case "${CI:-}" in
169
+ ''|0|false) _FH_VERDICT_EXIT=1; exit 0 ;;
170
+ esac
171
+ printf '%s\n' "ERROR: CI is set, so '${1}' printed above but exits 11 — under CI a lone help or version flag" >&2
172
+ printf '%s\n' " may be a file list that reads as a flag, and help is not a review. For a deliberate call: CI= fh-gate ${1}" >&2
173
+ exit 11
174
+ }
134
175
  case "${1:-}" in
135
176
  --version|-V)
136
177
  printf '%s\n' "fh-gate $VERSION"
137
- _FH_VERDICT_EXIT=1; exit 0
178
+ _fh_info_exit "$1"
138
179
  ;;
139
180
  --help|-h)
140
181
  printf '%s\n' "fh-gate $VERSION — FH governance gate"
@@ -147,18 +188,24 @@ case "${1:-}" in
147
188
  printf '%s\n' " fh-gate \"<files>\" review an explicit space-separated file list"
148
189
  printf '%s\n' " fh-gate \"<files>\" <level> level: quick (default) or full"
149
190
  printf '%s\n' " fh-gate --version | --help"
191
+ printf '%s\n' " (alone; under CI — CI set, not empty/0/false — they exit 11:"
192
+ printf '%s\n' " use CI= fh-gate --version for a deliberate call)"
150
193
  printf '%s\n' ""
151
194
  printf '%s\n' "Exit codes"
152
195
  printf '%s\n' " 0 PASS no findings"
153
196
  printf '%s\n' " 1 PENDING B-grade findings; proceed with awareness"
154
197
  printf '%s\n' " 2 BLOCKED A-grade findings; do not merge"
155
198
  printf '%s\n' " 3 ESCALATE human decision required"
156
- printf '%s\n' " 10 harness error — backend unavailable, timeout, unparseable verdict"
199
+ printf '%s\n' " 10 harness error — backend unavailable, timeout, unparseable verdict; also a backend"
200
+ printf '%s\n' " CLI too old for the read-only flags, and (codex) a user config.toml that names a"
201
+ printf '%s\n' " provider or base URL, or cannot be read (since 3.47.0)"
157
202
  printf '%s\n' " 11 argument error"
158
203
  printf '%s\n' " 12 dry run — prompt emitted, NO review performed"
159
204
  printf '%s\n' ""
160
205
  printf '%s\n' " 10, 11 and 12 sit outside the verdict range on purpose: a check that did"
161
206
  printf '%s\n' " not run must never be readable as a pass."
207
+ printf '%s\n' " A plain CI step fails on every non-zero exit, 1 included; the GitHub Action"
208
+ printf '%s\n' " lets 1 (PENDING) pass by default (its fail-on input)."
162
209
  printf '%s\n' ""
163
210
  printf '%s\n' "Environment"
164
211
  printf '%s\n' " FH_BACKEND=claude|codex|auto|cross backend (default: claude)"
@@ -168,6 +215,8 @@ case "${1:-}" in
168
215
  printf '%s\n' " FH_VERBOSE=1 print full backend stderr"
169
216
  printf '%s\n' " FH_REVIEWER=fh-legacy|code-review|fh review stage (default: fh-legacy, the original angle pass;"
170
217
  printf '%s\n' " opt-in: code-review = Claude Code's /code-review, claude only,"
218
+ printf '%s\n' " currently ALWAYS exits 10 (headless /code-review returns no"
219
+ printf '%s\n' " structured object yet — measured 0/11 on claude 2.1.330),"
171
220
  printf '%s\n' " NOT read-only (git can write a file) — trusted changes only ·"
172
221
  printf '%s\n' " fh = FH pass modelled on it, sees the diff only)"
173
222
  printf '%s\n' " FH_GATE_ELEPHANT=off|auto|on history-aware pass (default off; auto: on at level full)"
@@ -177,7 +226,7 @@ case "${1:-}" in
177
226
  printf '%s\n' " FH_GATE_BASE=<ref> base the execution layer measures the change against"
178
227
  printf '%s\n' ""
179
228
  printf '%s\n' " https://github.com/chrono-meta/forge-harness"
180
- _FH_VERDICT_EXIT=1; exit 0
229
+ _fh_info_exit "$1"
181
230
  ;;
182
231
  -*)
183
232
  printf '%s\n' "ERROR: unrecognized option '${1}'." >&2
@@ -370,9 +419,16 @@ fi
370
419
  if [[ -z "${FH_MODEL:-}" ]]; then
371
420
  case "$FH_BACKEND" in
372
421
  claude) FH_MODEL="claude-sonnet-5-5" ;;
373
- codex) FH_MODEL="gpt-5.5" ;;
422
+ # codex: no pinned default (2026-11-22, codex 0.164.0). `-m gpt-5.5`, the old default, is refused for a
423
+ # ChatGPT-account login («The 'gpt-5.5' model is not supported when using Codex with a ChatGPT account»); with no
424
+ # -m codex picks a model from its own catalog for that login (gpt-6.1-terra in that run) and answers. Set FH_MODEL
425
+ # to pin one; it is then passed as -m as before. Measured for one ChatGPT-account login only — API-key logins were
426
+ # not measured — and the model can change with the codex version or the account: set FH_MODEL for a stable one.
427
+ # The record names the model codex resolved (or «unknown»).
428
+ codex) FH_MODEL="" ;;
374
429
  esac
375
430
  fi
431
+ FH_MODEL_LABEL="${FH_MODEL:-codex default (not pinned)}"
376
432
 
377
433
  # ── Review stage (2026-11-19) ─────────────────────────────────────────────────────────────────────
378
434
  # The 2026-11-19 comparison (lab evidence/cr, sealed) measured this gate's own one-pass review against the
@@ -636,7 +692,7 @@ cat > "$PROMPT_FILE" <<PROMPT
636
692
  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
637
693
  FH GOVERNANCE GATE v${VERSION} — ${GATE_LEVEL_UPPER} PASS
638
694
  Caller: ${FH_CALLER} | Timestamp: ${TIMESTAMP}
639
- Backend: ${FH_BACKEND} | Model: ${FH_MODEL}
695
+ Backend: ${FH_BACKEND} | Model: ${FH_MODEL_LABEL}
640
696
  Security lens: ${SECURITY_LENS}
641
697
  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
642
698
 
@@ -936,7 +992,7 @@ fi
936
992
  # that gates on the documented exit contract.
937
993
  if [[ "$FH_DRY_RUN" == "1" ]]; then
938
994
  if [[ "$FH_REVIEWER" == "code-review" ]]; then
939
- printf 'FH_GATE_DRY_RUN: review = claude --print --model %s --output-format json --json-schema <findings schema> "/code-review %s" (cwd %s)\n' "$FH_MODEL" "$CR_EFFORT" "$WORK_ROOT"
995
+ printf 'FH_GATE_DRY_RUN: review = claude --print --model %s --output-format json --json-schema <findings schema> --setting-sources user <tool policy> -- "/code-review %s" (cwd %s)\n' "$FH_MODEL" "$CR_EFFORT" "$WORK_ROOT"
940
996
  elif [[ "$FH_REVIEWER" == "fh" ]]; then
941
997
  cat "$ABS_PROMPT_FILE"
942
998
  else
@@ -962,6 +1018,58 @@ if ! command -v "$FH_BACKEND" &>/dev/null; then
962
1018
  exit $EXIT_HARNESS_ERROR
963
1019
  fi
964
1020
 
1021
+ # --- codex: refuse a review the dropped user config would have sent elsewhere ---
1022
+ # Every codex review call runs with --ignore-user-config (see the read-only policy below). Dropping that file also
1023
+ # drops any provider it names, so the review would silently go to codex's default provider instead — for a proxy or
1024
+ # a company gateway, the reviewed code would leave by another road. So before any codex call, read the user config
1025
+ # and fail closed (exit 10, nothing sent) if it names where requests go or cannot be read. The keys are the ones the
1026
+ # codex 0.164.0 config reference lists as choosing a provider or an endpoint: model_provider (any value but the
1027
+ # built-in "openai"), model_providers (custom providers and the built-in cloud ones), openai_base_url (overrides the
1028
+ # built-in openai provider), chatgpt_base_url. A profile file ($CODEX_HOME/<name>.config.toml) applies only with
1029
+ # --profile, which fh-gate never passes, and oss_provider only with --oss; neither is read here.
1030
+ # Conservative by design (this is a text scan, not a TOML parser — fh-gate takes no python/TOML dependency): a key
1031
+ # anywhere on a line counts (an inline table, a profile table, a quoted key, even a trailing comment), so a string
1032
+ # value that merely contains one of these words also closes. A quoted key can spell a name with an escape
1033
+ # ("openai\u005fbase_url" is openai_base_url — cross-family R1), so any \u, \U or \x escape closes too. Comment-only
1034
+ # lines are skipped. Absence counts only when confirmed: a dangling link, or a folder on the way that cannot be
1035
+ # searched, is «cannot read», not «no file». The key name and line number are printed, never the value.
1036
+ codex_route_guard() {
1037
+ local _h="${CODEX_HOME:-$HOME/.codex}" _cfg _txt _line _s _n=0 _key="" _p
1038
+ local _q='["'"'"']' _v='("openai"|'"'openai'"'|"""openai"""|'"'''openai'''"')'
1039
+ local _openai="^(model_provider|${_q}model_provider${_q})[[:space:]]*=[[:space:]]*${_v}[[:space:]]*\$"
1040
+ _cfg="$_h/config.toml"
1041
+ _codex_cfg_unreadable() {
1042
+ echo "ERROR: cannot read the codex user config ($_cfg) — fh-gate runs codex with --ignore-user-config and must" >&2
1043
+ echo " first check that file does not name a provider the review would otherwise go to. No review was sent. Failing closed." >&2
1044
+ exit $EXIT_HARNESS_ERROR
1045
+ }
1046
+ if [[ ! -e "$_cfg" && ! -L "$_cfg" ]]; then
1047
+ _p="$_cfg"; while [[ ! -e "$_p" && ! -L "$_p" && "$_p" != / && "$_p" != . ]]; do _p=$(dirname -- "$_p"); done
1048
+ [[ -d "$_p" && -x "$_p" ]] || _codex_cfg_unreadable
1049
+ return 0 # confirmed absent: the nearest existing folder on the way is searchable
1050
+ fi
1051
+ if [[ ! -f "$_cfg" || ! -r "$_cfg" ]] || ! _txt=$(cat -- "$_cfg" 2>/dev/null); then _codex_cfg_unreadable; fi
1052
+ while IFS= read -r _line || [[ -n "$_line" ]]; do
1053
+ _n=$((_n + 1))
1054
+ _s="${_line#"${_line%%[![:space:]]*}"}"
1055
+ [[ -z "$_s" || "$_s" == \#* ]] && continue
1056
+ if [[ "$_s" == *'\u'* || "$_s" == *'\U'* || "$_s" == *'\x'* ]]; then _key="an escape (\\u, \\U or \\x) the guard cannot decode"
1057
+ elif [[ "$_s" == *model_providers* ]]; then _key=model_providers
1058
+ elif [[ "$_s" == *openai_base_url* ]]; then _key=openai_base_url
1059
+ elif [[ "$_s" == *chatgpt_base_url* ]]; then _key=chatgpt_base_url
1060
+ elif [[ "$_s" == *model_provider* && ! "$_s" =~ $_openai ]]; then _key=model_provider
1061
+ fi
1062
+ [[ -n "$_key" ]] && break
1063
+ done <<< "$_txt"
1064
+ [[ -z "$_key" ]] && return 0
1065
+ echo "ERROR: the codex user config ($_cfg, line $_n) has ${_key}. fh-gate runs codex with --ignore-user-config so a" >&2
1066
+ echo " trusted checkout's .codex/config.toml cannot start programs, and that would send this review to codex's default" >&2
1067
+ echo " provider instead of the one your config names. No review was sent. Failing closed." >&2
1068
+ echo " Use the claude backend, or run with a CODEX_HOME whose config.toml names no provider." >&2
1069
+ exit $EXIT_HARNESS_ERROR
1070
+ }
1071
+ [[ "$FH_BACKEND" == "codex" ]] && codex_route_guard
1072
+
965
1073
  # --- Structured-output verdict schema (Typed-Verdict Channel) ---
966
1074
  # Principle: on a gate that ingests untrusted content, the verdict rides a typed,
967
1075
  # schema-constrained channel the content cannot occupy — never a grep-able prose line.
@@ -1023,7 +1131,7 @@ cat > "$CR_SCHEMA_FILE" <<'SCHEMA'
1023
1131
  SCHEMA
1024
1132
 
1025
1133
  # --- Invoke ---
1026
- echo "→ fh-gate v${VERSION} [${GATE_LEVEL_UPPER}] backend=${FH_BACKEND} model=${FH_MODEL} caller=${FH_CALLER} security=${SECURITY_LENS}" >&2
1134
+ echo "→ fh-gate v${VERSION} [${GATE_LEVEL_UPPER}] backend=${FH_BACKEND} model=${FH_MODEL_LABEL} caller=${FH_CALLER} security=${SECURITY_LENS}" >&2
1027
1135
  printf " files:\n%s\n" "$FILES_LIST" >&2
1028
1136
 
1029
1137
  # Use gtimeout (macOS coreutils) if available, fall back to timeout, then bare invoke
@@ -1046,9 +1154,43 @@ fi
1046
1154
  # So the built-in tool set itself is limited (--tools), no MCP server is loaded (--strict-mcp-config with no
1047
1155
  # --mcp-config) and skills and commands are off (--disable-slash-commands). A Claude Code too old for these flags
1048
1156
  # fails the call, which fails closed (exit 10).
1157
+ # The checkout under review is untrusted input (2026-11-22): its project/local settings and hooks must not load into
1158
+ # the reviewer. claude gets --setting-sources user (measured on claude 2.1.330 with a planted checkout and a local
1159
+ # fake API: a project SessionStart hook ran without the flag and did not run with it). codex gets
1160
+ # -c project_doc_max_bytes=0 (measured on codex 0.164.0 the same way: without it the request carried the checkout's
1161
+ # AGENTS.md; with it, it did not). --bare is not used: it also drops OAuth and keychain auth.
1162
+ # Measured again 2026-11-22 with the real CLIs and a subscription login (planted checkout under /tmp; under the
1163
+ # session scratchpad claude loads no CLAUDE.md at all, so a canary there proves nothing): with --setting-sources user
1164
+ # the checkout's CLAUDE.md, CLAUDE.local.md and .claude/rules text did not reach the call (0/3; 3/3 without the flag).
1165
+ # codex also gets --ignore-user-config (2026-11-22, codex 0.164.0, isolated CODEX_HOME, local fake API): when the
1166
+ # user's codex config marks the checkout trusted, codex loads the checkout's .codex/config.toml and starts the MCP
1167
+ # servers it declares — commands from the reviewed checkout, run outside the -s read-only sandbox (3/3; untrusted 0/3).
1168
+ # `-c mcp_servers={}`, `-c projects={}` and a per-path trust override did not stop it; --ignore-user-config did (0/3).
1169
+ # Dropping the user config also drops any provider it names, so the review would go to codex's default provider
1170
+ # instead — codex_route_guard (below, before any call) refuses that case. OPENAI_BASE_URL is not a way around it:
1171
+ # codex 0.164.0 exec did not follow it, with or without the flag (0/2).
1172
+ # Project .rules and hooks of a trusted checkout (measured 2026-11-22, local fake API issuing one command): without
1173
+ # --ignore-user-config the checkout's rule refused the command and its SessionStart/PreToolUse hooks ran (4/4); with
1174
+ # the flag neither applied (0/3), the same as an untrusted checkout (0/3). Those canaries only (one rule, two hook
1175
+ # events); that no other project-scoped codex setting applies is not shown by them.
1049
1176
  _RO_TOOLS="Read,Glob,Grep"
1050
1177
  _RO_ALLOW="$_RO_TOOLS"
1051
1178
  _RO_DENY="Bash,PowerShell,Write,Edit,NotebookEdit,WebFetch,WebSearch"
1179
+ _RO_SOURCES="user"
1180
+ _RO_CODEX_NODOC="project_doc_max_bytes=0"
1181
+ _RO_CODEX_NOUSER="--ignore-user-config"
1182
+ # _note_codex_model <pass> — for an unpinned codex call, the model codex chose: the first `model:` line of codex's own
1183
+ # stderr banner, read only above the `user` line (below it codex echoes the prompt, which carries the reviewed content),
1184
+ # kept only if it looks like a model id; anything else is «unknown» — the record never guesses. Read right after each
1185
+ # call, because the next call overwrites ERR_FILE (cross-family R2: the record named only the last pass).
1186
+ _CODEX_RESOLVED=""
1187
+ _note_codex_model() {
1188
+ [[ "$FH_BACKEND" == "codex" && -z "$FH_MODEL" ]] || return 0
1189
+ local _m
1190
+ _m=$(awk '/^user$/{exit} /^model: /{sub(/^model: /, ""); print; exit}' "$ERR_FILE" 2>/dev/null || true)
1191
+ [[ "$_m" =~ ^[A-Za-z0-9._:-]{1,64}$ ]] || _m="unknown"
1192
+ _CODEX_RESOLVED="${_CODEX_RESOLVED:+${_CODEX_RESOLVED}, }$1 $_m"
1193
+ }
1052
1194
  call_structured() {
1053
1195
  local _ok=0
1054
1196
  : > "$CODEX_LAST"
@@ -1056,16 +1198,17 @@ call_structured() {
1056
1198
  # ${4:-} = "goldfish": the process does not inherit FH_TASK_DESCRIPTION either (not only the prompt)
1057
1199
  claude) ( cd "$WORK_ROOT" && { [[ "${4:-}" == goldfish ]] && unset FH_TASK_DESCRIPTION; :; } && ${_TIMEOUT_CMD} claude --print --model "$FH_MODEL" --output-format json \
1058
1200
  --json-schema "$(cat "$2")" --tools "$_RO_TOOLS" --strict-mcp-config --disable-slash-commands \
1059
- --allowedTools "$_RO_ALLOW" --disallowedTools "$_RO_DENY" < "$1" ) \
1201
+ --setting-sources "$_RO_SOURCES" --allowedTools "$_RO_ALLOW" --disallowedTools "$_RO_DENY" < "$1" ) \
1060
1202
  > "$OUTPUT_FILE" 2>"$ERR_FILE" && _ok=1 ;;
1061
- codex) ( cd "$WORK_ROOT" && { [[ "${4:-}" == goldfish ]] && unset FH_TASK_DESCRIPTION; :; } && ${_TIMEOUT_CMD} codex exec -m "$FH_MODEL" --skip-git-repo-check -s read-only \
1062
- --output-schema "$2" -o "$CODEX_LAST" - < "$1" ) > "$OUTPUT_FILE" 2>"$ERR_FILE" && _ok=1 ;;
1203
+ codex) ( cd "$WORK_ROOT" && { [[ "${4:-}" == goldfish ]] && unset FH_TASK_DESCRIPTION; :; } && ${_TIMEOUT_CMD} codex exec ${FH_MODEL:+-m "$FH_MODEL"} --skip-git-repo-check -s read-only \
1204
+ "$_RO_CODEX_NOUSER" -c "$_RO_CODEX_NODOC" --output-schema "$2" -o "$CODEX_LAST" - < "$1" ) > "$OUTPUT_FILE" 2>"$ERR_FILE" && _ok=1 ;;
1063
1205
  esac
1064
1206
  if [[ "$_ok" != 1 ]]; then
1065
1207
  echo "ERROR: ${3} (${FH_BACKEND}) failed or timed out (${FH_TIMEOUT}s) — failing closed" >&2
1066
1208
  cat "$ERR_FILE" >&2
1067
1209
  exit $EXIT_HARNESS_ERROR
1068
1210
  fi
1211
+ if [[ "$3" == *elephant* ]]; then _note_codex_model elephant; else _note_codex_model review; fi
1069
1212
  [[ "$FH_VERBOSE" == "1" ]] && cat "$ERR_FILE" >&2
1070
1213
  STRUCT_JSON=""
1071
1214
  if [[ "$FH_BACKEND" == "claude" ]]; then
@@ -1143,11 +1286,17 @@ elif [[ "$FH_REVIEWER" == "code-review" ]]; then
1143
1286
  # The runner's command-file variables are left out of this call's environment. That only removes the direct
1144
1287
  # reference: the files can still be found (for example under $RUNNER_TEMP) and written through `git … --output=`.
1145
1288
  # It reduces exposure; it does not make this path safe — which is why it is labelled not read-only.
1289
+ # --setting-sources user (2026-11-22, real claude 2.1.330, planted checkout): without it this call ran the checkout's
1290
+ # project and local hooks, started its .mcp.json server and carried its CLAUDE.md, CLAUDE.local.md and .claude/rules
1291
+ # text (3/3); with it, none of them (3/3). The cost: /code-review no longer has the checkout's CLAUDE.md in context;
1292
+ # it can still read the file with Read.
1293
+ # `--` before the prompt: claude reads a word that follows --disallowedTools as that option's value, so without it
1294
+ # this call failed before any review («"/code-review low" was read as a value of --disallowedTools»), exit 10.
1146
1295
  ( cd "$WORK_ROOT" && unset FH_TASK_DESCRIPTION GITHUB_ENV GITHUB_PATH GITHUB_OUTPUT GITHUB_STATE GITHUB_STEP_SUMMARY && ${_TIMEOUT_CMD} claude --print --model "$FH_MODEL" --output-format json \
1147
- --json-schema "$(cat "$CR_SCHEMA_FILE")" \
1296
+ --json-schema "$(cat "$CR_SCHEMA_FILE")" --setting-sources "$_RO_SOURCES" \
1148
1297
  --allowedTools "Read,Glob,Grep,Agent,Task,Skill,Bash(git diff:*),Bash(git log:*),Bash(git show:*),Bash(git status:*),Bash(git rev-parse:*),Bash(git merge-base:*),Bash(git blame:*)" \
1149
1298
  --disallowedTools "Write,Edit,NotebookEdit,WebFetch,WebSearch" \
1150
- "/code-review ${CR_EFFORT}" < /dev/null ) > "$OUTPUT_FILE" 2>"$ERR_FILE" && _CR_OK=1
1299
+ -- "/code-review ${CR_EFFORT}" < /dev/null ) > "$OUTPUT_FILE" 2>"$ERR_FILE" && _CR_OK=1
1151
1300
  if [[ "$_CR_OK" != 1 ]]; then
1152
1301
  echo "ERROR: /code-review (claude backend) failed or timed out (${FH_TIMEOUT}s) — failing closed" >&2
1153
1302
  cat "$ERR_FILE" >&2
@@ -1190,12 +1339,16 @@ elif [[ "$FH_REVIEWER" == "code-review" ]]; then
1190
1339
  REVIEW_VERDICT="PASS"
1191
1340
  [ "$(printf '%s' "$REVIEW_FINDINGS" | jq -r '[.[]|select(.grade=="B")]|length')" -gt 0 ] && REVIEW_VERDICT="PENDING"
1192
1341
  else
1342
+ # The default (fh-legacy) review gets the same read-only policy as call_structured above, at the repository root:
1343
+ # the target content is already in its prompt, so it only needs to read files. Before 2026-11-22 this call passed no
1344
+ # tool, MCP or sandbox restriction, so it ran with whatever the backend CLI's own settings allowed.
1193
1345
  run_backend() {
1194
1346
  case "$FH_BACKEND" in
1195
- claude) ${_TIMEOUT_CMD} claude --print --model "$FH_MODEL" \
1196
- --output-format json --json-schema "$(cat "$SCHEMA_FILE")" ;;
1197
- codex) ${_TIMEOUT_CMD} codex exec -m "$FH_MODEL" --skip-git-repo-check \
1198
- --output-schema "$SCHEMA_FILE" -o "$CODEX_LAST" - ;;
1347
+ claude) ( cd "$WORK_ROOT" && ${_TIMEOUT_CMD} claude --print --model "$FH_MODEL" \
1348
+ --output-format json --json-schema "$(cat "$SCHEMA_FILE")" --tools "$_RO_TOOLS" --strict-mcp-config \
1349
+ --disable-slash-commands --setting-sources "$_RO_SOURCES" --allowedTools "$_RO_ALLOW" --disallowedTools "$_RO_DENY" ) ;;
1350
+ codex) ( cd "$WORK_ROOT" && ${_TIMEOUT_CMD} codex exec ${FH_MODEL:+-m "$FH_MODEL"} --skip-git-repo-check -s read-only \
1351
+ "$_RO_CODEX_NOUSER" -c "$_RO_CODEX_NODOC" --output-schema "$SCHEMA_FILE" -o "$CODEX_LAST" - ) ;;
1199
1352
  esac
1200
1353
  }
1201
1354
 
@@ -1204,6 +1357,7 @@ if ! run_backend < "$PROMPT_FILE" > "$OUTPUT_FILE" 2>"$ERR_FILE"; then
1204
1357
  cat "$ERR_FILE" >&2
1205
1358
  exit $EXIT_HARNESS_ERROR
1206
1359
  fi
1360
+ _note_codex_model review
1207
1361
 
1208
1362
  [[ "$FH_VERBOSE" == "1" ]] && cat "$ERR_FILE" >&2
1209
1363
 
@@ -1401,6 +1555,11 @@ cat "$PARSE_FILE"
1401
1555
  FINDINGS_A_LOG=$(grep -m 1 "^FH_FINDINGS_A:" "$PARSE_FILE" 2>/dev/null | awk '{print $2}' | tr -d '[:space:]' || echo "0") # portability-noqa: already ends in `|| echo "0"` (P1's own prescribed remedy) — the assignment cannot die under set -e
1402
1556
  FINDINGS_B_LOG=$(grep -m 1 "^FH_FINDINGS_B:" "$PARSE_FILE" 2>/dev/null | awk '{print $2}' | tr -d '[:space:]' || echo "0") # portability-noqa: same as FINDINGS_A_LOG above
1403
1557
  FINDINGS_N_LOG=$(grep -m 1 "^FH_FINDINGS_COUNT:" "$PARSE_FILE" 2>/dev/null | awk '{print $2}' | tr -d '[:space:]' || echo "0") # portability-noqa: same as FINDINGS_A_LOG above
1558
+ # An unpinned codex run records which model codex chose for each pass (_note_codex_model, after every codex call).
1559
+ # The label carries no «: » so the governance YAML stays a plain scalar (cross-family R2).
1560
+ if [[ "$FH_BACKEND" == "codex" && -z "$FH_MODEL" ]]; then
1561
+ FH_MODEL_LABEL="codex default (not pinned, resolved ${_CODEX_RESOLVED:-unknown})"
1562
+ fi
1404
1563
  {
1405
1564
  printf -- "- timestamp: %s\n" "$TIMESTAMP"
1406
1565
  printf " caller: %s\n" "$FH_CALLER"
@@ -1409,7 +1568,7 @@ FINDINGS_N_LOG=$(grep -m 1 "^FH_FINDINGS_COUNT:" "$PARSE_FILE" 2>/dev/null | awk
1409
1568
  printf " elephant: %s\n" "${ELEPHANT_LINE%% —*}"
1410
1569
  printf " e0: %s\n" "$(_exec_get '.e0.status')"
1411
1570
  printf " e1: %s\n" "$(_exec_get '.e1.status')"
1412
- printf " model: %s\n" "$FH_MODEL"
1571
+ printf " model: %s\n" "$FH_MODEL_LABEL"
1413
1572
  printf " gate_level: %s\n" "$GATE_LEVEL"
1414
1573
  printf " verdict: %s\n" "$VERDICT"
1415
1574
  printf " findings_total: %s\n" "$FINDINGS_N_LOG"