@chrono-meta/fh-gate 3.43.0 → 3.45.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 (105) hide show
  1. package/.claude/rules/fh_4axis_gate.md +50 -608
  2. package/.claude-plugin/marketplace.json +4 -4
  3. package/AGENTS.md +5 -1
  4. package/CATALOG.md +21 -0
  5. package/CHEATSHEET.md +7 -1
  6. package/docs/USER_GUIDE.md +95 -0
  7. package/docs/codex-compat.md +1 -1
  8. package/knowledge/shared/harness-core/fh_4axis_gate_detail.md +679 -0
  9. package/knowledge/shared/harness-core/fh_integration_contract.md +1 -1
  10. package/knowledge/shared/harness-core/fh_module_contract.md +106 -3
  11. package/knowledge/shared/harness-core/governance_engineering_definition.md +16 -0
  12. package/knowledge/shared/harness-core/heavy_skill_to_cartridge.md +185 -0
  13. package/knowledge/shared/learnings/subagent_invocations_log.yaml +221 -0
  14. package/knowledge/shared/plugin-catalog/recommended_plugins.md +53 -9
  15. package/package.json +24 -1
  16. package/plugins/fh-commons/.claude-plugin/plugin.json +1 -1
  17. package/plugins/fh-commons/skills/ko-tech-writer/SKILL.md +50 -14
  18. package/plugins/fh-commons/skills/ko-tech-writer/SKILL_detail.md +80 -0
  19. package/plugins/fh-commons/skills/ko-tech-writer/fixtures/sense_negative.md +30 -0
  20. package/plugins/fh-commons/skills/ko-tech-writer/fixtures/sense_positive.md +56 -0
  21. package/plugins/fh-meta/.claude-plugin/plugin.json +1 -1
  22. package/plugins/fh-meta/CHANGELOG.md +118 -0
  23. package/plugins/fh-meta/skills/auto-decorrelation/SKILL.md +58 -1
  24. package/plugins/fh-meta/skills/install-wizard/SKILL_detail.md +4 -0
  25. package/plugins/fh-meta/skills/sim-conductor/SKILL_detail.md +3 -3
  26. package/plugins/fh-meta/skills/steel-quench/SKILL_detail.md +9 -4
  27. package/plugins/fh-preprep/.claude-plugin/plugin.json +1 -1
  28. package/plugins/fh-qp/.claude-plugin/plugin.json +1 -1
  29. package/scripts/agy_launch_guard.sh +165 -0
  30. package/scripts/agy_remote_run.sh +187 -0
  31. package/scripts/below_floor_scan.sh +30 -0
  32. package/scripts/codex_launch_guard.sh +123 -0
  33. package/scripts/correction_moments.py +23 -2
  34. package/scripts/fh-gate.sh +612 -14
  35. package/scripts/fh-goal.sh +56 -12
  36. package/scripts/fh-run.sh +1 -1
  37. package/scripts/fh_gate_exec.sh +272 -0
  38. package/scripts/fh_session_load.sh +17 -0
  39. package/scripts/finding_fleet.sh +36 -2
  40. package/scripts/finding_verifier.sh +7 -2
  41. package/scripts/fixtures/heavy_skill_smell/clean/tidy-notes/README.md +16 -0
  42. package/scripts/fixtures/heavy_skill_smell/clean/tidy-notes/scripts/check_refs.py +12 -0
  43. package/scripts/fixtures/heavy_skill_smell/clean/tidy-notes/scripts/test_check_refs.py +24 -0
  44. package/scripts/fixtures/heavy_skill_smell/clean/tidy-notes/skills/tidy-notes/SKILL.md +16 -0
  45. package/scripts/fixtures/heavy_skill_smell/clean/tidy-notes/skills/tidy-notes/fh-module.yaml +20 -0
  46. package/scripts/fixtures/heavy_skill_smell/heavy/docs-publisher-pro/SKILL.md +25 -0
  47. package/scripts/fixtures/heavy_skill_smell/heavy/docs-publisher-pro/hooks/hooks.json +7 -0
  48. package/scripts/fixtures/heavy_skill_smell/heavy/docs-publisher-pro/scripts/check_links.py +25 -0
  49. package/scripts/fixtures/heavy_skill_smell/heavy/docs-publisher-pro/scripts/publish.sh +9 -0
  50. package/scripts/fixtures/heavy_skill_smell/heavy/docs-publisher-pro/scripts/publish_guard.py +6 -0
  51. package/scripts/fixtures/heavy_skill_smell/heavy/docs-publisher-pro/scripts/setup.sh +5 -0
  52. package/scripts/fixtures/heavy_skill_smell/heavy/release-notes-pro/SKILL.md +25 -0
  53. package/scripts/fixtures/heavy_skill_smell/heavy/release-notes-pro/hooks/hooks.json +10 -0
  54. package/scripts/fixtures/heavy_skill_smell/heavy/release-notes-pro/scripts/check_refs.py +12 -0
  55. package/scripts/fixtures/heavy_skill_smell/heavy/release-notes-pro/scripts/guard_push.py +9 -0
  56. package/scripts/fixtures/heavy_skill_smell/heavy/release-notes-pro/scripts/install.sh +6 -0
  57. package/scripts/fixtures/heavy_skill_smell/heavy/release-notes-pro/scripts/ship.sh +9 -0
  58. package/scripts/heavy_skill_smell.py +311 -0
  59. package/scripts/job_heartbeat.py +186 -0
  60. package/scripts/ko_tech_writer_calibrate.py +88 -1
  61. package/scripts/live_eval_matrix.py +128 -0
  62. package/scripts/live_eval_trace.py +199 -5
  63. package/scripts/package_coverage_check.sh +18 -0
  64. package/scripts/prepush_guard_check.sh +41 -20
  65. package/scripts/probe_live_eval.sh +33 -1
  66. package/scripts/probe_live_eval_lib.py +14 -6
  67. package/scripts/selfcheck.sh +162 -2
  68. package/scripts/selfcheck_shard_weights.txt +2 -0
  69. package/scripts/session_checklist.py +109 -5
  70. package/scripts/sidecar_calibrate.sh +15 -5
  71. package/scripts/sidecar_wait.sh +21 -1
  72. package/scripts/sim_isolated_run.sh +20 -0
  73. package/scripts/test_agy_launch_guard_lanes.sh +347 -0
  74. package/scripts/test_agy_remote_run_lanes.sh +228 -0
  75. package/scripts/test_below_floor_scan_lanes.sh +85 -0
  76. package/scripts/test_codex_launch_guard_lanes.sh +183 -0
  77. package/scripts/test_correction_moments_lanes.sh +37 -0
  78. package/scripts/test_fh_gate_absorb_lanes.sh +255 -0
  79. package/scripts/test_fh_gate_defaults_lanes.sh +169 -0
  80. package/scripts/test_fh_gate_exec_lanes.sh +244 -0
  81. package/scripts/test_fh_gate_fusion_lanes.sh +202 -0
  82. package/scripts/test_fh_gate_regressions.sh +92 -1
  83. package/scripts/test_fh_goal_change_detection_lanes.sh +103 -3
  84. package/scripts/test_finding_pipeline_lanes.sh +41 -3
  85. package/scripts/test_guard_anchor_override_env_lanes.sh +84 -0
  86. package/scripts/test_heavy_skill_smell_lanes.sh +160 -0
  87. package/scripts/test_job_heartbeat_lanes.sh +96 -0
  88. package/scripts/test_live_eval_construct_lanes.sh +29 -6
  89. package/scripts/test_live_eval_matrix_lanes.sh +53 -0
  90. package/scripts/test_live_eval_trace_lanes.sh +165 -12
  91. package/scripts/test_name_boundary_locale_lanes.sh +36 -5
  92. package/scripts/test_preprep_speech_coach_lanes.sh +18 -2
  93. package/scripts/test_prepush_guard_failure_visibility_lanes.sh +152 -0
  94. package/scripts/test_prepush_marker_lookup_lanes.sh +143 -0
  95. package/scripts/test_probe_live_eval_lanes.sh +43 -0
  96. package/scripts/test_regression_guard_sibling_lanes.sh +52 -1
  97. package/scripts/test_session_checklist_lanes.sh +205 -0
  98. package/scripts/test_sidecar_calibrate_lanes.sh +5 -1
  99. package/scripts/test_sidecar_wait_stdin.sh +18 -0
  100. package/scripts/test_sim_isolated_run_lanes.sh +43 -0
  101. package/scripts/universal_guard_check.sh +8 -0
  102. package/templates/.claude/rules/mcp_tool_gating.md +27 -0
  103. package/templates/.git-hooks/pre-push +60 -3
  104. package/templates/regression_guard.sh +8 -4
  105. package/templates/settings.LaneGap.snippet.json +27 -0
@@ -0,0 +1,228 @@
1
+ #!/usr/bin/env bash
2
+ # test_agy_remote_run_lanes.sh — lanes for scripts/agy_remote_run.sh (agy only as a remote OS user).
3
+ #
4
+ # HOW. A fake `ssh`/`scp` pair stands in for the remote machine: a temp folder is the remote user's
5
+ # home, and the three PowerShell scripts the runner sends (canary.ps1 · run.ps1 · cleanup.ps1) are
6
+ # EMULATED by the fake ssh, not executed. A fake agy records that it started. No network, no real agy.
7
+ # WHAT IS CHECKED: the local half — refusal without a target or a fresh PASS receipt, refusal on a
8
+ # changed setting, no local fallback when the route is down, argument and file transport, exit codes,
9
+ # and that only the run's own work folder is removed.
10
+ # WHAT IS NOT CHECKED: the PowerShell scripts themselves (no PowerShell here) — they were run for real
11
+ # against a Windows remote on 2026-11-16 (canary PASS 6/6, one agy round trip); and whether the remote
12
+ # OS user is really isolated (that is what --canary measures, on the day it runs).
13
+ # Usage: bash scripts/test_agy_remote_run_lanes.sh Exit: 0 all pass · 1 any fail
14
+ set -uo pipefail
15
+ REPO="$(cd "$(dirname "$0")/.." && pwd)"
16
+ RUN="$REPO/scripts/agy_remote_run.sh"
17
+ GUARD="$REPO/scripts/agy_launch_guard.sh"
18
+ D="$(mktemp -d "${TMPDIR:-/tmp}/agyremote.XXXXXX")" || { echo "ENV-BLOCKED: mktemp failed — unmeasured, not a pass"; exit 1; }
19
+ trap 'rm -rf "$D"' EXIT
20
+ PASS=0; FAIL=0
21
+ ok() { PASS=$((PASS+1)); echo " ✅ $1"; }
22
+ bad() { FAIL=$((FAIL+1)); echo " ❌ $1"; }
23
+ RH="$D/rhome"; mkdir -p "$RH" "$D/bin"
24
+
25
+ # ── fake remote ────────────────────────────────────────────────────────────────────────────────────
26
+ cat > "$D/bin/ssh" <<EOF
27
+ #!/usr/bin/env bash
28
+ RH="$RH"; D="$D"
29
+ [ "\${FAKE_SSH_DOWN:-0}" = 1 ] && exit 255
30
+ while [ \$# -gt 0 ] && [ "\$1" = -o ]; do shift 2; done
31
+ shift # target
32
+ cmd="\$*"
33
+ case "\$cmd" in
34
+ "mkdir "*) mkdir "\$RH/\${cmd#mkdir }" ;;
35
+ powershell*-File*) f="\${cmd##*-File }"; wd="\${f%%\\\\*}"; sc="\${f##*\\\\}"; W="\$RH/\$wd"
36
+ mkdir -p "\$D/seen"; cp "\$W/\$sc" "\$D/seen/\$sc" 2>/dev/null
37
+ case "\$sc" in
38
+ canary.ps1) while IFS= read -r p; do ao=0; case "\$p" in '?'*) ao=1; p="\${p#?}" ;; esac
39
+ if grep -qxF -- "\$p" "\$D/readable" 2>/dev/null; then echo "DENY-FAIL \$p (readable)"
40
+ elif grep -qxF -- "\$p" "\$D/notfound" 2>/dev/null; then [ \$ao = 1 ] && echo "DENY-OK \$p (ItemNotFoundException)" || echo "DENY-FAIL \$p (not measured: ItemNotFoundException)"
41
+ else echo "DENY-OK \$p (UnauthorizedAccessException)"; fi
42
+ done < "\$W/deny.txt"
43
+ [ "\${FAKE_POS_FAIL:-0}" = 1 ] && echo POS-FAIL || echo POS-OK
44
+ exit "\${FAKE_SSH_CANARY_RC:-0}" ;;
45
+ run.ps1) ( cd "\$W" && args=(); while IFS= read -r a; do [ -n "\$a" ] && args+=("\$a"); done < args.txt
46
+ "\$D/fake_agy" -p "\$(cat prompt.txt)" \${args[@]+"\${args[@]}"} --settings "\$W/settings.json"; arc=\$?
47
+ echo "FH_AGY_RC=\$arc"; [ "\${FAKE_LATE_LINE:-0}" = 1 ] && echo "FH_AGY_RC=0"
48
+ exit "\${FAKE_SSH_RUN_RC:-\$arc}" ); exit \$? ;;
49
+ cleanup.ps1) n="\$wd"
50
+ if ! printf '%s' "\$n" | grep -Eq '^fh_agy_[0-9]{14}_[0-9a-f]{6}$'; then echo "CLEANUP-REFUSED \$n"; exit 3; fi
51
+ [ "\${FAKE_CLEANUP_FAIL:-0}" = 1 ] && { echo CLEANUP-FAILED; exit 5; }
52
+ rm -rf "\$W"; echo CLEANUP-OK ;;
53
+ esac ;;
54
+ *) echo "fake ssh: unexpected command: \$cmd" >&2; exit 99 ;;
55
+ esac
56
+ EOF
57
+ cat > "$D/bin/scp" <<EOF
58
+ #!/usr/bin/env bash
59
+ RH="$RH"
60
+ args=(); while [ \$# -gt 0 ]; do case "\$1" in -q) shift ;; -o) shift 2 ;; *) args+=("\$1"); shift ;; esac; done
61
+ dst="\${args[\${#args[@]}-1]}"; unset 'args[\${#args[@]}-1]'
62
+ case "\$dst" in
63
+ *:*) for s in "\${args[@]}"; do cp "\$s" "\$RH/\${dst#*:}" || exit 1; done ;;
64
+ *) for s in "\${args[@]}"; do cp "\$RH/\${s#*:}" "\$dst" || exit 1; done ;;
65
+ esac
66
+ EOF
67
+ cat > "$D/fake_agy" <<EOF
68
+ #!/usr/bin/env bash
69
+ printf '%s\n' "\$@" > "$D/agy_argv"
70
+ echo "fake-output" > out.txt
71
+ echo "FAKE-AGY-RAN"
72
+ [ -n "\${FAKE_AGY_SLEEP:-}" ] && sleep "\$FAKE_AGY_SLEEP"
73
+ [ -n "\${FAKE_AGY_FORGE:-}" ] && echo "FH_AGY_RC=0"
74
+ exit \${FAKE_AGY_RC:-0}
75
+ EOF
76
+ # a recording `agy` on PATH: if the runner ever fell back to a local agy, this would record it
77
+ printf '#!/usr/bin/env bash\n: > "%s/local_agy_ran"\n' "$D" > "$D/bin/agy"
78
+ chmod +x "$D/bin/ssh" "$D/bin/scp" "$D/fake_agy" "$D/bin/agy"
79
+ export PATH="$D/bin:$PATH" # fake ssh/scp by name, first on PATH — the runner has no override switch
80
+ export FH_AGY_REMOTE_RECEIPT_DIR="$D/receipts"
81
+ DENY='C:\Users\admin;C:\Users\Public;D:\'
82
+ # first / newest receipt without an early-exit reader on a pipe (pipefail class-lock)
83
+ first_receipt() { local f; for f in "$D"/receipts/receipt_*.txt; do [ -f "$f" ] && { printf '%s' "$f"; return 0; }; done; return 1; }
84
+ newest_receipt() { local f n=""; for f in "$D"/receipts/receipt_*.txt; do [ -f "$f" ] || continue; { [ -z "$n" ] || [ "$f" -nt "$n" ]; } && n="$f"; done; printf '%s' "$n"; }
85
+ leftover() { find "$RH" -mindepth 1 -maxdepth 1 -name 'fh_agy_*' | wc -l | tr -d ' '; }
86
+ run() { out=$("$@" 2>"$D/err" </dev/null); rc=$?; err=$(cat "$D/err"); }
87
+
88
+ echo "── refusals before any canary"
89
+ run env -u FH_AGY_REMOTE bash "$RUN" -p hi
90
+ [ "$rc" -eq 3 ] && printf '%s' "$err" | grep -q AGY-REMOTE-REFUSED && ok "R1 no FH_AGY_REMOTE: rc=3 refused" || bad "R1 no target: rc=$rc"
91
+ export FH_AGY_REMOTE=user@remote FH_AGY_REMOTE_DENY="$DENY"
92
+ run bash "$RUN" -p hi
93
+ [ "$rc" -eq 3 ] && printf '%s' "$err" | grep -q 'no canary receipt' && ok "R2 no receipt: rc=3 refused" || bad "R2 no receipt: rc=$rc err=${err:0:100}"
94
+ run env FH_AGY_REMOTE_DENY= bash "$RUN" --canary
95
+ [ "$rc" -eq 2 ] && ok "R3 canary with an empty deny list: rc=2" || bad "R3 empty deny canary: rc=$rc"
96
+
97
+ echo "── canary"
98
+ : > "$D/readable"
99
+ run bash "$RUN" --canary
100
+ R="$(first_receipt)"
101
+ if [ "$rc" -eq 0 ] && grep -qx 'verdict=PASS' "$R" && grep -qx 'denied=3/3' "$R" && [ "$(leftover)" = 0 ]; then ok "R4 canary all denied: PASS 3/3, receipt written, remote folder removed"
102
+ else bad "R4 canary PASS: rc=$rc receipt=$(head -4 "$R" 2>/dev/null | tr '\n' ' ') left=$(leftover)"; fi
103
+ printf 'C:\\Users\\Public\n' > "$D/readable"
104
+ run bash "$RUN" --canary
105
+ [ "$rc" -eq 1 ] && grep -qx 'verdict=FAIL' "$R" && ok "R5 canary with one readable path: FAIL rc=1" || bad "R5 canary readable: rc=$rc"
106
+ run bash "$RUN" -p hi
107
+ [ "$rc" -eq 3 ] && printf '%s' "$err" | grep -q 'did not pass' && ok "R6 run after a FAIL receipt: rc=3 refused" || bad "R6 run after FAIL: rc=$rc"
108
+ : > "$D/readable"
109
+ run env FAKE_POS_FAIL=1 bash "$RUN" --canary
110
+ [ "$rc" -eq 1 ] && grep -qx 'positive=FAIL' "$R" && ok "R7 canary whose positive control fails: FAIL" || bad "R7 positive fail: rc=$rc"
111
+ run bash "$RUN" --canary
112
+ [ "$rc" -eq 0 ] && ok "R8 canary PASS again (for the run lanes)" || bad "R8 canary PASS again: rc=$rc"
113
+
114
+ echo "── run"
115
+ printf 'frozen input\n' > "$D/in.txt"
116
+ rm -f "$D/agy_argv"
117
+ run bash "$RUN" --input "$D/in.txt" --fetch out.txt --fetch-dir "$D/back" -p "two words prompt" --model m1 --output-format text
118
+ argv="$(tr '\n' '|' < "$D/agy_argv" 2>/dev/null)"
119
+ if [ "$rc" -eq 0 ] && printf '%s' "$out" | grep -q FAKE-AGY-RAN && [ "$(cat "$D/back/out.txt" 2>/dev/null)" = fake-output ] \
120
+ && printf '%s' "$argv" | grep -q '^-p|two words prompt|--model|m1|--output-format|text|--settings|' && [ "$(leftover)" = 0 ]; then
121
+ ok "R9 run: prompt and flags intact, --settings added, fetched file back, remote folder removed"
122
+ else bad "R9 run: rc=$rc argv=$argv left=$(leftover) err=${err:0:120}"; fi
123
+ run env FAKE_AGY_RC=7 bash "$RUN" -p hi
124
+ [ "$rc" -eq 1 ] && printf '%s' "$err" | grep -q 'AGY_RC=7' && ok "R10 remote agy rc 7: runner rc=1 with AGY_RC=7" || bad "R10 agy rc: rc=$rc err=${err:0:80}"
125
+ run env FAKE_CLEANUP_FAIL=1 bash "$RUN" -p hi
126
+ [ "$rc" -eq 5 ] && ok "R11 cleanup not confirmed: rc=5" || bad "R11 cleanup fail: rc=$rc"
127
+ rm -rf "$RH"/fh_agy_*
128
+ run env FAKE_SSH_DOWN=1 bash "$RUN" -p hi
129
+ [ "$rc" -eq 4 ] && printf '%s' "$err" | grep -q 'not falling back' && ok "R12 route down: rc=4, says it does not fall back" || bad "R12 route down: rc=$rc"
130
+ printf 'x' > "$D/bad name.txt"
131
+ run bash "$RUN" --input "$D/bad name.txt" -p hi
132
+ [ "$rc" -eq 2 ] && ok "R13 input name with a space: rc=2" || bad "R13 bad name: rc=$rc"
133
+ mkdir -p "$D/other"; cp "$D/in.txt" "$D/other/in.txt"
134
+ run bash "$RUN" --input "$D/in.txt" --input "$D/other/in.txt" -p hi
135
+ [ "$rc" -eq 2 ] && ok "R14 two inputs with one name: rc=2" || bad "R14 duplicate: rc=$rc"
136
+ run bash "$RUN" -p hi --settings x.json
137
+ [ "$rc" -eq 2 ] && ok "R15 caller --settings: rc=2 (the runner owns it)" || bad "R15 settings: rc=$rc"
138
+
139
+ echo "── receipt freshness and settings"
140
+ R="$(first_receipt)"
141
+ sed -i.bak 's/^epoch=.*/epoch=1000/' "$R"
142
+ run bash "$RUN" -p hi
143
+ [ "$rc" -eq 3 ] && printf '%s' "$err" | grep -q 'older than 7 days' && ok "R16 receipt older than 7 days: rc=3" || bad "R16 stale: rc=$rc"
144
+ run bash "$RUN" --canary
145
+ run env FH_AGY_REMOTE_DENY='C:\Users\admin' bash "$RUN" -p hi
146
+ [ "$rc" -eq 3 ] && printf '%s' "$err" | grep -q 'no canary receipt' && ok "R17 deny list changed since the canary: rc=3 (new settings, no receipt)" || bad "R17 changed: rc=$rc"
147
+ h_t=user@remote; h_d='C:\Users\admin'; h_a='%LOCALAPPDATA%\agy\bin\agy.exe'
148
+ cp "$R" "$D/receipts/receipt_$(printf 'v1|%d:%s|%d:%s|%d:%s' "${#h_t}" "$h_t" "${#h_d}" "$h_d" "${#h_a}" "$h_a" | shasum -a 256 | cut -c1-16).txt"
149
+ run env FH_AGY_REMOTE_DENY='C:\Users\admin' bash "$RUN" -p hi
150
+ [ "$rc" -eq 3 ] && printf '%s' "$err" | grep -q 'different settings' && ok "R18 receipt copied under another name: rc=3 (hash inside does not match)" || bad "R18 copied receipt: rc=$rc err=${err:0:80}"
151
+
152
+ echo "── through the guard"
153
+ run env FH_AGY_ISOLATION=remote-os-user bash "$GUARD" "$RUN" -p hi
154
+ [ "$rc" -eq 0 ] && printf '%s' "$out" | grep -q FAKE-AGY-RAN && ok "R19 guard + remote-os-user + this runner: runs" || bad "R19 guard route: rc=$rc err=${err:0:100}"
155
+ run env -u FH_AGY_ISOLATION bash "$GUARD" "$RUN" -p hi
156
+ [ "$rc" -eq 3 ] && ok "R20 guard without the marker: refused even for this runner" || bad "R20 guard no marker: rc=$rc"
157
+
158
+ echo "── review round 1 holes"
159
+ run bash "$RUN" --canary
160
+ printf '#!/usr/bin/env bash\n: > "%s/override_ran"\n' "$D" > "$D/override"; chmod +x "$D/override"
161
+ run env FH_AGY_REMOTE_SSH="$D/override" FH_AGY_REMOTE_SCP="$D/override" FH_AGY_REMOTE_LANE=1 bash "$RUN" -p hi
162
+ [ ! -e "$D/override_ran" ] && [ "$rc" -eq 0 ] && ok "R22 FH_AGY_REMOTE_SSH/SCP/LANE in the environment have no effect (no override exists)" || bad "R22 override honoured: rc=$rc"
163
+ printf 'x' > "$D/RUN.PS1"
164
+ run bash "$RUN" --input "$D/RUN.PS1" -p hi
165
+ [ "$rc" -eq 2 ] && printf '%s' "$err" | grep -q reserved && ok "R23 input named RUN.PS1 (case differs): rc=2 reserved" || bad "R23 RUN.PS1: rc=$rc"
166
+ run env FH_AGY_REMOTE_AGY="C:\\x$(printf '\342\200\231'); Remove-Item C:\\s #" bash "$RUN" -p hi
167
+ [ "$rc" -eq 2 ] && ok "R24 remote agy path with a smart quote: rc=2" || bad "R24 smart quote: rc=$rc"
168
+ run env FAKE_SSH_RUN_RC=255 bash "$RUN" -p hi
169
+ [ "$rc" -eq 4 ] && ok "R25 ssh exits 255 after agy ran: rc=4 (not success)" || bad "R25 ssh rc: rc=$rc"
170
+ rm -rf "$RH"/fh_agy_*
171
+ run env FAKE_CLEANUP_FAIL=1 bash "$RUN" --canary
172
+ R="$(printf '%s' "$out" | sed -n 's/.*receipt=//p')"
173
+ [ "$rc" -ne 0 ] && grep -qx 'verdict=FAIL' "$R" && ok "R26 canary whose cleanup fails: not PASS" || bad "R26 canary cleanup: rc=$rc verdict=$(sed -n 's/^verdict=//p' "$R")"
174
+ rm -rf "$RH"/fh_agy_*
175
+ : > "$D/afile" # a receipt dir UNDER a regular file cannot be created, even by root
176
+ run env FH_AGY_REMOTE_RECEIPT_DIR="$D/afile/sub" bash "$RUN" --canary
177
+ [ "$rc" -eq 4 ] && ok "R27 receipt cannot be written: rc=4" || bad "R27 unwritable receipt: rc=$rc"
178
+ run env FH_AGY_REMOTE_DENY="$(printf 'C:\\a\nC:\\b')" bash "$RUN" --canary
179
+ [ "$rc" -eq 2 ] && ok "R28 deny list with a line break: rc=2" || bad "R28 newline in deny: rc=$rc"
180
+ # R29 the uploaded scripts themselves carry the probes the emulator stands in for
181
+ if grep -q 'Get-ChildItem -LiteralPath \$p -Force -ErrorAction Stop' "$D/seen/canary.ps1" 2>/dev/null && grep -q "UnauthorizedAccess" "$D/seen/canary.ps1" \
182
+ && grep -q "OpenRead(\$p)" "$D/seen/canary.ps1" && grep -q "POS-OK" "$D/seen/canary.ps1" \
183
+ && grep -qF "'^fh_agy_[0-9]{14}_[0-9a-f]{6}\$'" "$D/seen/cleanup.ps1" && grep -qF '$parent -ne $env:USERPROFILE' "$D/seen/cleanup.ps1" \
184
+ && grep -qF '"FH_AGY_RC=$rc"' "$D/seen/run.ps1" && grep -qF "prompt.txt' -Raw -Encoding UTF8" "$D/seen/run.ps1"; then
185
+ ok "R29 uploaded canary/cleanup/run scripts carry the read probe, the access-denied rule, the name+parent check and the final rc line"
186
+ else bad "R29 uploaded script content missing a probe or check"; fi
187
+ echo "── review round 2 holes"
188
+ printf 'C:\\Users\\Typo\n' > "$D/notfound"
189
+ run env FH_AGY_REMOTE_DENY='C:\Users\Typo;C:\Users\Public' bash "$RUN" --canary
190
+ [ "$rc" -eq 1 ] && printf '%s' "$out" | grep -q 'FAIL' && ok "R30 a deny path that does not exist (no ?): FAIL, not measured" || bad "R30 typo path: rc=$rc"
191
+ run env FH_AGY_REMOTE_DENY='?C:\Users\Typo;C:\Users\Public' bash "$RUN" --canary
192
+ [ "$rc" -eq 0 ] && ok "R31 the same path marked ? (absence accepted): PASS" || bad "R31 ? path: rc=$rc"
193
+ : > "$D/notfound"; rm -rf "$RH"/fh_agy_*
194
+ run env FAKE_SSH_CANARY_RC=255 bash "$RUN" --canary
195
+ [ "$rc" -eq 1 ] && ok "R32 canary whose ssh exits 255 after printing all probes: FAIL" || bad "R32 canary ssh rc: rc=$rc"
196
+ rm -rf "$RH"/fh_agy_*
197
+ run bash "$RUN" --canary
198
+ run env FAKE_AGY_FORGE=1 FAKE_AGY_RC=7 bash "$RUN" -p hi
199
+ [ "$rc" -eq 1 ] && printf '%s' "$err" | grep -q 'AGY_RC=7' && ok "R33 agy prints a forged FH_AGY_RC=0 then exits 7: runner rc=1 (only the last line counts)" || bad "R33 forged rc: rc=$rc"
200
+ printf 'a' > "$D/Evidence.txt"; printf 'b' > "$D/other/evidence.txt"
201
+ run bash "$RUN" --input "$D/Evidence.txt" --input "$D/other/evidence.txt" -p hi
202
+ [ "$rc" -eq 2 ] && ok "R34 inputs Evidence.txt and evidence.txt: rc=2 (Windows ignores case)" || bad "R34 case dup: rc=$rc"
203
+ echo "── narrowed round 3: verdict and destructive paths"
204
+ rm -rf "$RH"/fh_agy_*
205
+ run bash "$RUN" --canary
206
+ run bash "$RUN" --fetch ../outside.txt --fetch-dir "$D/back" -p hi
207
+ [ "$rc" -eq 2 ] && ok "R35 --fetch ../outside.txt: rc=2 (bare names only)" || bad "R35 fetch traversal: rc=$rc"
208
+ R="$(printf '%s' "$out" | sed -n 's/.*receipt=//p')"; [ -n "$R" ] || R="$(newest_receipt)"
209
+ run bash "$RUN" --canary; R="$(printf '%s' "$out" | sed -n 's/.*receipt=//p')"
210
+ sed -i.bak 's/^epoch=.*/epoch=9999999999/' "$R"
211
+ run bash "$RUN" -p hi
212
+ [ "$rc" -eq 3 ] && printf '%s' "$err" | grep -q 'future' && ok "R36 receipt dated in the future: rc=3" || bad "R36 future receipt: rc=$rc"
213
+ run bash "$RUN" --canary
214
+ run env FAKE_AGY_RC=7 FAKE_LATE_LINE=1 bash "$RUN" -p hi
215
+ [ "$rc" -ne 0 ] && ok "R37 agy exits 7, a late line prints FH_AGY_RC=0: not success (rc=$rc)" || bad "R37 late forged line: rc=0"
216
+ rm -rf "$RH"/fh_agy_*
217
+ FAKE_AGY_SLEEP=3 bash "$RUN" -p hi > "$D/int.out" 2> "$D/int.err" < /dev/null &
218
+ ipid=$!; k=0; until ls "$RH"/fh_agy_* >/dev/null 2>&1 || [ "$k" -ge 50 ]; do sleep 0.1; k=$((k+1)); done
219
+ sleep 0.5; kill -TERM "$ipid" 2>/dev/null; wait "$ipid" 2>/dev/null; irc=$?
220
+ if [ "$(leftover)" = 0 ] && [ "$irc" = 130 ]; then ok "R38 TERM during a run: the runner's own handler exits 130 and the remote work folder is removed"
221
+ else bad "R38 interrupt: left=$(leftover) irc=$irc waited=$k out=$(head -c 80 "$D/int.out" | tr "\n" " ") err=$(head -c 120 "$D/int.err")"; fi
222
+ if grep -qF "deny.txt') -Encoding UTF8" "$D/seen/canary.ps1" && grep -qF 'InnerException' "$D/seen/canary.ps1" \
223
+ && grep -qF 'exit $rc' "$D/seen/run.ps1"; then ok "R39 uploaded scripts read the deny list as UTF-8, walk wrapped errors, and exit with agy's code"
224
+ else bad "R39 uploaded script content missing UTF-8 deny read / inner-error walk / exit code"; fi
225
+ [ ! -e "$D/local_agy_ran" ] && ok "R21 no lane started a local agy" || bad "R21 a local agy was started"
226
+ echo
227
+ echo "agy remote run lanes: $PASS passed, $FAIL failed"
228
+ [ "$FAIL" -eq 0 ]
@@ -0,0 +1,85 @@
1
+ #!/usr/bin/env bash
2
+ # Lanes for scripts/below_floor_scan.sh — fixture repos only.
3
+ #
4
+ # Why (2026-11-20 weekly audit): run from a git worktree, the scan read the worktree's own
5
+ # tracks/_meta — gitignored, so empty — and printed «0 total, 0 pending» with rc 0. The main
6
+ # checkout held 4 markers. «Not read» rendered as «clean». With no root given, a worktree now reads
7
+ # the main checkout's tracks/_meta — the EVIDENCE_ROOT the pre-commit hook writes markers to — and
8
+ # says so; if the main checkout has no tracks/_meta it says NOT READ (rc unchanged).
9
+ #
10
+ # B1 worktree, no arg → reads the main checkout: 1 pending, rc 1, names the source
11
+ # B2 main checkout, no arg → unchanged: 1 pending, rc 1, no worktree note
12
+ # B3 explicit root arg → that root only (the worktree path given → «no tracks/_meta», rc 0)
13
+ # B4 fresh repo, no tracks → unchanged: «no tracks/_meta directory», rc 0 (CI / public clone)
14
+ # B5 worktree with an EMPTY tracks/_meta (session hooks create one) → still reads the main checkout
15
+ # B6 worktree with a marker file of its own → still the main checkout (the writer's place wins)
16
+ # B7 worktree whose main checkout has no tracks/_meta → NOT READ, rc 0 (a CI worktree stays green)
17
+ # B8 worktree, cwd in a subdirectory → still the main checkout (relative common dir resolved from cwd)
18
+ # B9 main checkout, cwd in a subdirectory → unchanged, no worktree note
19
+ set -u
20
+ . "$(dirname "${BASH_SOURCE[0]}")/fixture_guard_lib.sh" # scrub inherited GIT_* env first (#1088)
21
+ FH="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
22
+ S="$FH/scripts/below_floor_scan.sh"
23
+ T=$(mktemp -d "${TMPDIR:-/tmp}/bfs.XXXXXX")
24
+ trap 'rm -rf "$T"' EXIT
25
+ pass=0; fail=0
26
+ ok() { echo "PASS $1"; pass=$((pass + 1)); }
27
+ no() { echo "FAIL $1 — $2"; fail=$((fail + 1)); }
28
+
29
+ g() { git -c user.name=t -c user.email=t@t -c commit.gpgsign=false "$@"; }
30
+ mkdir -p "$T/main" && cd "$T/main" && g init -q && printf 'tracks/\n' > .gitignore && g add .gitignore && g commit -qm init || { echo "HARNESS-ERROR: fixture repo"; exit 2; }
31
+ mkdir -p tracks/_meta
32
+ cat > tracks/_meta/.axes_23_passed_x_2026-11-01.marker <<'EOF'
33
+ floor-status: below-floor
34
+ axis2-model: haiku
35
+ below-floor-ack: operator ok
36
+ EOF
37
+ g worktree add -q "$T/wt" -b wt-branch 2>/dev/null || { echo "HARNESS-ERROR: worktree add"; exit 2; }
38
+ [ -d "$T/wt/tracks" ] && { echo "HARNESS-ERROR: fixture worktree already has tracks/ (gitignore not applied)"; exit 2; }
39
+
40
+ out=$(cd "$T/wt" && bash "$S" 2>&1); rc=$?
41
+ MAINDIR=$(cd "$T/main" && pwd -P)/tracks/_meta
42
+ if [ "$rc" = 1 ] && printf '%s' "$out" | grep -q '1 total, 1 pending' && printf '%s' "$out" | grep -qF "scan: $MAINDIR ──" && printf '%s' "$out" | grep -q 'main checkout'; then ok B1-worktree-reads-main
43
+ else no B1-worktree-reads-main "rc=$rc · $(printf '%s' "$out" | tail -2 | tr '\n' ' ')"; fi
44
+
45
+ out=$(cd "$T/main" && bash "$S" 2>&1); rc=$?
46
+ if [ "$rc" = 1 ] && printf '%s' "$out" | grep -q '1 total, 1 pending' && ! printf '%s' "$out" | grep -q 'main checkout'; then ok B2-main-unchanged
47
+ else no B2-main-unchanged "rc=$rc · $(printf '%s' "$out" | tail -2 | tr '\n' ' ')"; fi
48
+
49
+ out=$(cd "$T/wt" && bash "$S" "$T/wt" 2>&1); rc=$?
50
+ if [ "$rc" = 0 ] && printf '%s' "$out" | grep -q 'no tracks/_meta directory'; then ok B3-explicit-root-only
51
+ else no B3-explicit-root-only "rc=$rc · $(printf '%s' "$out" | tail -1)"; fi
52
+
53
+ mkdir -p "$T/fresh" && (cd "$T/fresh" && g init -q)
54
+ out=$(cd "$T/fresh" && bash "$S" 2>&1); rc=$?
55
+ if [ "$rc" = 0 ] && printf '%s' "$out" | grep -q 'no tracks/_meta directory'; then ok B4-fresh-clone-unchanged
56
+ else no B4-fresh-clone-unchanged "rc=$rc · $(printf '%s' "$out" | tail -1)"; fi
57
+
58
+ mkdir -p "$T/wt/tracks/_meta"
59
+ out=$(cd "$T/wt" && bash "$S" 2>&1); rc=$?
60
+ if [ "$rc" = 1 ] && printf '%s' "$out" | grep -q '1 total, 1 pending' && printf '%s' "$out" | grep -q 'main checkout'; then ok B5-empty-dir-still-reads-main
61
+ else no B5-empty-dir-still-reads-main "rc=$rc · $(printf '%s' "$out" | tail -2 | tr '\n' ' ')"; fi
62
+
63
+ printf 'floor-status: above-floor\n' > "$T/wt/tracks/_meta/.axes_23_passed_wt_2026-11-02.marker"
64
+ out=$(cd "$T/wt" && bash "$S" 2>&1); rc=$?
65
+ if [ "$rc" = 1 ] && printf '%s' "$out" | grep -qF "scan: $MAINDIR ──"; then ok B6-own-marker-still-reads-main
66
+ else no B6-own-marker-still-reads-main "rc=$rc · $(printf '%s' "$out" | head -2 | tr '\n' ' ')"; fi
67
+
68
+ mkdir -p "$T/wt/sub/deeper"
69
+ out=$(cd "$T/wt/sub/deeper" && bash "$S" 2>&1); rc=$?
70
+ if [ "$rc" = 1 ] && printf '%s' "$out" | grep -qF "scan: $MAINDIR ──"; then ok B8-subdir-cwd-reads-main
71
+ else no B8-subdir-cwd-reads-main "rc=$rc · $(printf '%s' "$out" | head -2 | tr '\n' ' ')"; fi
72
+
73
+ mkdir -p "$T/main/sub"
74
+ out=$(cd "$T/main/sub" && bash "$S" 2>&1); rc=$?
75
+ if [ "$rc" = 1 ] && printf '%s' "$out" | grep -qF "scan: $MAINDIR ──" && ! printf '%s' "$out" | grep -q 'git worktree'; then ok B9-main-subdir-unchanged
76
+ else no B9-main-subdir-unchanged "rc=$rc · $(printf '%s' "$out" | head -2 | tr '\n' ' ')"; fi
77
+
78
+ mkdir -p "$T/main2" && (cd "$T/main2" && g init -q && printf 'tracks/\n' > .gitignore && g add .gitignore && g commit -qm init && g worktree add -q "$T/wt2" -b wt2 2>/dev/null)
79
+ mkdir -p "$T/wt2/tracks/_meta"
80
+ out=$(cd "$T/wt2" && bash "$S" 2>&1); rc=$?
81
+ if [ "$rc" = 0 ] && printf '%s' "$out" | grep -q 'NOT READ'; then ok B7-no-main-record-says-not-read
82
+ else no B7-no-main-record-says-not-read "rc=$rc · $(printf '%s' "$out" | head -3 | tr '\n' ' ')"; fi
83
+
84
+ echo "below_floor_scan lanes: $pass passed · $fail failed"
85
+ [ "$fail" -eq 0 ]
@@ -0,0 +1,183 @@
1
+ #!/usr/bin/env bash
2
+ # test_codex_launch_guard_lanes.sh — lanes for scripts/codex_launch_guard.sh and the FH callers that start
3
+ # codex (finding_fleet.sh codex rows · finding_verifier.sh --family codex · sidecar_calibrate.sh probe).
4
+ #
5
+ # WHAT IS CHECKED: codex is not started when the prompt (stdin), an argument or the working folder refers
6
+ # to a configured company-repo root; it is started — with the prompt intact and its own exit code passed
7
+ # back — when nothing does; and an unconfigured list is said out loud, never shown as clean. A FAKE codex
8
+ # records whether it started; no real codex runs. The roots used here are temp folders this lane makes.
9
+ # WHAT IS NOT CHECKED: a company path the prompt carries in another shape (relative path, file content
10
+ # pasted without its path, encoding) — the guard matches root paths as strings, nothing more.
11
+ #
12
+ # Also checked: a stdin that is open but never ends (an agent background shell's) is refused within the idle
13
+ # limit instead of hanging (C12–C12f).
14
+ #
15
+ # Usage: bash scripts/test_codex_launch_guard_lanes.sh Exit: 0 all pass · 1 any fail
16
+ set -uo pipefail
17
+ REPO="$(cd "$(dirname "$0")/.." && pwd)"
18
+ GUARD="$REPO/scripts/codex_launch_guard.sh"
19
+ FLEET="$REPO/scripts/finding_fleet.sh"
20
+ VERIFIER="$REPO/scripts/finding_verifier.sh"
21
+ D="$(mktemp -d "${TMPDIR:-/tmp}/codexguard.XXXXXX")" || { echo "ENV-BLOCKED: mktemp failed — unmeasured, not a pass"; exit 1; }
22
+ trap 'rm -rf "$D"' EXIT
23
+ D="$(cd "$D" && pwd -P)"
24
+ unset FH_COMPANY_ROOTS FH_COMPANY_ROOTS_FILE
25
+ export FH_COMPANY_ROOTS_FILE="$D/no-such-roots-file" # keep the operator's own list out of these lanes
26
+ PASS=0; FAIL=0
27
+ ok() { PASS=$((PASS+1)); echo " ✅ $1"; }
28
+ bad() { FAIL=$((FAIL+1)); echo " ❌ $1"; }
29
+
30
+ cat > "$D/codex_fake" <<EOF
31
+ #!/usr/bin/env bash
32
+ cat > "$D/stdin_seen"
33
+ printf '%s\n' "\$@" > "$D/argv_seen"
34
+ : > "$D/ran"
35
+ echo '{"title":"fake","file":"t.py","line":1,"severity":"B","category":"x","detail":"d","defeater":"df","confidence":0.5}'
36
+ exit \${FAKE_CODEX_RC:-0}
37
+ EOF
38
+ chmod +x "$D/codex_fake"
39
+ mkdir -p "$D/company/repo-a/src" "$D/public"
40
+ ROOT="$D/company/repo-a"
41
+ run() { rm -f "$D/ran" "$D/stdin_seen"; out=$("$@" 2>"$D/err"); rc=$?; err=$(cat "$D/err"); }
42
+
43
+ echo "── guard alone"
44
+ run env -u FH_COMPANY_ROOTS bash "$GUARD" "$D/codex_fake" exec - <<< "review this public diff"
45
+ if [ "$rc" -eq 0 ] && [ -e "$D/ran" ] && printf '%s' "$err" | grep -q 'not checked'; then ok "C1 no list configured: codex runs, and the guard says «not checked» (not «clean»)"
46
+ else bad "C1 unconfigured: rc=$rc ran=$([ -e "$D/ran" ] && echo yes || echo no) err=${err:0:100}"; fi
47
+
48
+ export FH_COMPANY_ROOTS="$ROOT"
49
+ run bash "$GUARD" "$D/codex_fake" exec - <<< "please review $ROOT/src/app.py for bugs"
50
+ if [ "$rc" -eq 3 ] && [ ! -e "$D/ran" ] && printf '%s' "$err" | grep -q 'CODEX-REFUSED' && printf '%s' "$err" | grep -q 'prompt'; then ok "C2 company root in the prompt: refused rc=3, codex not started, says «prompt»"
51
+ else bad "C2 prompt: rc=$rc ran=$([ -e "$D/ran" ] && echo yes || echo no) err=${err:0:120}"; fi
52
+
53
+ printf 'diff --git a/x.sh b/x.sh\n+echo hi\n' > "$D/public.diff"
54
+ run env FAKE_CODEX_RC=5 bash "$GUARD" "$D/codex_fake" exec --sandbox read-only - < "$D/public.diff"
55
+ if [ "$rc" -eq 5 ] && [ -e "$D/ran" ] && cmp -s "$D/stdin_seen" "$D/public.diff" && [ "$(sed -n 2p "$D/argv_seen")" = "--sandbox" ]; then ok "C3 public diff: codex runs with the prompt byte-for-byte and its own rc (5) comes back"
56
+ else bad "C3 public: rc=$rc ran=$([ -e "$D/ran" ] && echo yes || echo no) same_stdin=$(cmp -s "$D/stdin_seen" "$D/public.diff" && echo yes || echo no)"; fi
57
+
58
+ run bash "$GUARD" "$D/codex_fake" exec -C "$ROOT" - <<< "hello"
59
+ [ "$rc" -eq 3 ] && [ ! -e "$D/ran" ] && printf '%s' "$err" | grep -q 'argument' && ok "C4 company root in an argument: refused" || bad "C4 argument: rc=$rc err=${err:0:100}"
60
+
61
+ run bash -c 'cd "$1" && bash "$2" "$3" exec - <<< "hello"' _ "$ROOT/src" "$GUARD" "$D/codex_fake"
62
+ [ "$rc" -eq 3 ] && [ ! -e "$D/ran" ] && printf '%s' "$err" | grep -q 'working folder' && ok "C5 working folder inside a company root: refused" || bad "C5 cwd: rc=$rc err=${err:0:100}"
63
+
64
+ echo "── stdin that never ends (an agent background shell's stdin: open, not a terminal)"
65
+ # Known pair: on the guard before 2026-11-20 C12 does not return until the writer goes away (a plain `cat`
66
+ # read stdin), and then codex starts — red on «returned within 10 s» and on «not started».
67
+ # The writer holds a FIFO open for 20 s; each lane kills it afterwards.
68
+ mkfifo "$D/fifo"
69
+ # The guard runs under a 15 s watchdog, so a guard that waits forever turns these lanes red instead of hanging them.
70
+ command -v perl >/dev/null 2>&1 || bad "C12* not measured: perl (the watchdog) is missing"
71
+ held() { # held <writer command...> — guard reads a FIFO the writer keeps open; sets rc, err, secs
72
+ bash -c 'exec "$@"' _ "$@" > "$D/fifo" & local wpid=$!
73
+ local t0=$SECONDS
74
+ run env FH_GUARD_STDIN_IDLE_S=2 perl -e 'alarm 15; exec @ARGV' bash "$GUARD" "$D/codex_fake" exec - < "$D/fifo"
75
+ secs=$((SECONDS - t0)); kill "$wpid" 2>/dev/null; wait "$wpid" 2>/dev/null
76
+ }
77
+ held sleep 20
78
+ if [ "$rc" -eq 3 ] && [ ! -e "$D/ran" ] && [ "$secs" -le 10 ] && printf '%s' "$err" | grep -q 'CODEX-REFUSED' && printf '%s' "$err" | grep -q 'never ended'; then ok "C12 open stdin, nothing sent: refused rc=3 within ${secs} s, codex not started"
79
+ else bad "C12 open stdin: rc=$rc secs=$secs ran=$([ -e "$D/ran" ] && echo yes || echo no) err=${err:0:120}"; fi
80
+
81
+ held bash -c 'printf "review this public diff\n"; exec sleep 20'
82
+ if [ "$rc" -eq 3 ] && [ ! -e "$D/ran" ] && [ "$secs" -le 10 ]; then ok "C12b part of a prompt, then open and silent: refused, the partial prompt is not passed on"
83
+ else bad "C12b partial prompt: rc=$rc secs=$secs ran=$([ -e "$D/ran" ] && echo yes || echo no)"; fi
84
+
85
+ printf 'slow but ending\n' > "$D/slow.expect"
86
+ rm -f "$D/ran" "$D/stdin_seen"
87
+ out=$( { sleep 1; printf 'slow but ending\n'; } | FH_GUARD_STDIN_IDLE_S=3 bash "$GUARD" "$D/codex_fake" exec - 2>"$D/err"); rc=$?
88
+ if [ "$rc" -eq 0 ] && [ -e "$D/ran" ] && cmp -s "$D/stdin_seen" "$D/slow.expect"; then ok "C12c a slow writer that ends inside the idle limit: codex runs with the prompt intact (control alive)"
89
+ else bad "C12c slow writer: rc=$rc ran=$([ -e "$D/ran" ] && echo yes || echo no) err=$(head -c 120 "$D/err")"; fi
90
+
91
+ bad_lim=""
92
+ for v in soon 00 0 99999999999999999999 86401; do
93
+ run env FH_GUARD_STDIN_IDLE_S="$v" bash "$GUARD" "$D/codex_fake" exec - <<< "hello"
94
+ { [ "$rc" -eq 3 ] && [ ! -e "$D/ran" ] && printf '%s' "$err" | grep -q "FH_GUARD_STDIN_IDLE_S='$v' is not"; } || bad_lim="$bad_lim idle=$v:rc=$rc"
95
+ done
96
+ run env FH_GUARD_STDIN_MAX_S=0 bash "$GUARD" "$D/codex_fake" exec - <<< "hello"
97
+ { [ "$rc" -eq 3 ] && [ ! -e "$D/ran" ] && printf '%s' "$err" | grep -q "FH_GUARD_STDIN_MAX_S='0' is not"; } || bad_lim="$bad_lim max=0:rc=$rc"
98
+ [ -z "$bad_lim" ] && ok "C12d a malformed, zero or out-of-range limit is a refusal by name, not a default (soon · 00 · 0 · 20 digits · 86401 · max 0)" || bad "C12d limits:$bad_lim"
99
+
100
+ # C12f a writer that keeps sending a little and never ends: the idle limit never fires, the total one does.
101
+ FH_GUARD_STDIN_MAX_S=3 held bash -c 'while :; do printf x; sleep 0.5; done'
102
+ if [ "$rc" -eq 3 ] && [ ! -e "$D/ran" ] && [ "$secs" -le 10 ] && printf '%s' "$err" | grep -q 'had not ended after 3 s'; then ok "C12f a trickling writer that never ends: refused on the total limit within ${secs} s"
103
+ else bad "C12f trickle: rc=$rc secs=$secs ran=$([ -e "$D/ran" ] && echo yes || echo no) err=${err:0:120}"; fi
104
+
105
+
106
+ # C6 the same root written another way: /private stripped (macOS /tmp = /private/tmp) and ~ for $HOME
107
+ case "$ROOT" in
108
+ /private/*) alt="${ROOT#/private}"
109
+ run bash "$GUARD" "$D/codex_fake" exec - <<< "look at $alt/src"
110
+ [ "$rc" -eq 3 ] && [ ! -e "$D/ran" ] && ok "C6a root written without /private: refused" || bad "C6a /private form: rc=$rc" ;;
111
+ *) echo " ➖ C6a /private form not applicable (temp root is not under /private)" ;;
112
+ esac
113
+ HROOT="$HOME/.fh-codex-guard-lane-$$"
114
+ run env FH_COMPANY_ROOTS="$HROOT" bash "$GUARD" "$D/codex_fake" exec - <<< "see ~/.fh-codex-guard-lane-$$/x"
115
+ [ "$rc" -eq 3 ] && [ ! -e "$D/ran" ] && ok "C6b root under HOME written with ~: refused" || bad "C6b ~ form: rc=$rc"
116
+
117
+ # C7 the list can come from a file (one path per line, # comments) instead of the environment
118
+ printf '# lane roots\n\n%s\n' "$ROOT" > "$D/roots"
119
+ run env -u FH_COMPANY_ROOTS FH_COMPANY_ROOTS_FILE="$D/roots" bash "$GUARD" "$D/codex_fake" exec - <<< "check $ROOT/src"
120
+ [ "$rc" -eq 3 ] && [ ! -e "$D/ran" ] && ok "C7 roots from a file: refused" || bad "C7 roots file: rc=$rc err=${err:0:100}"
121
+ # C7b a near-miss path (root name as a prefix of another folder) is NOT a match
122
+ run bash "$GUARD" "$D/codex_fake" exec - <<< "check $D/company/repo-ab/src"
123
+ [ "$rc" -eq 0 ] && [ -e "$D/ran" ] && ok "C7b ${ROOT##*/}b is not ${ROOT##*/}: runs (no prefix over-block)" || bad "C7b near-miss: rc=$rc"
124
+
125
+ # C7c a list file that exists but cannot be read is a refusal, not «unconfigured»
126
+ mkdir -p "$D/unreadable_roots" # a directory where a file is expected: open() fails with an error other than not-found
127
+ run env -u FH_COMPANY_ROOTS FH_COMPANY_ROOTS_FILE="$D/unreadable_roots" bash "$GUARD" "$D/codex_fake" exec - <<< "hello"
128
+ [ "$rc" -eq 3 ] && [ ! -e "$D/ran" ] && printf '%s' "$err" | grep -q 'cannot be read' && ok "C7c unreadable roots file: refused (not «not checked»)" || bad "C7c unreadable list: rc=$rc err=${err:0:100}"
129
+
130
+ echo "── callers"
131
+ printf 'def f():\n return "%s/src"\n' "$ROOT" > "$D/t_company.py"
132
+ printf 'def f():\n return 1\n' > "$D/t_public.py"
133
+ printf 'codex|logic|CODEX_BIN exec -\n' > "$D/codex.tbl"
134
+ rm -f "$D/ran"
135
+ FH_CODEX_BIN="$D/codex_fake" bash "$FLEET" "$D/t_company.py" --out "$D/f1" --fleet "$D/codex.tbl" < /dev/null > "$D/f1.out" 2>&1
136
+ if [ ! -e "$D/ran" ] && grep -qs 'CODEX-REFUSED' "$D/f1/err_codex_logic.txt"; then ok "C8 fleet codex row on a file that names a company root: refused"
137
+ else bad "C8 fleet company: started=$([ -e "$D/ran" ] && echo yes || echo no)"; fi
138
+ rm -f "$D/ran"
139
+ FH_CODEX_BIN="$D/codex_fake" bash "$FLEET" "$D/t_public.py" --out "$D/f2" --fleet "$D/codex.tbl" < /dev/null > "$D/f2.out" 2>&1
140
+ [ -e "$D/ran" ] && ok "C8b fleet codex row on a public file: runs (control alive)" || bad "C8b fleet public: not started"
141
+ printf 'codex|logic|codex exec -\n' > "$D/byname.tbl"
142
+ mkdir -p "$D/bin"; cp "$D/codex_fake" "$D/bin/codex"
143
+ rm -f "$D/ran"
144
+ PATH="$D/bin:$PATH" FH_CODEX_BIN="$D/codex_fake" bash "$FLEET" "$D/t_company.py" --out "$D/f3" --fleet "$D/byname.tbl" < /dev/null > "$D/f3.out" 2>&1
145
+ [ ! -e "$D/ran" ] && ok "C8c fleet row calling codex by name on a company file: refused" || bad "C8c by name: started"
146
+ # C8d round 2: round-1 findings from a public file, round 2 aimed at a company file — still refused
147
+ FH_CODEX_BIN="$D/codex_fake" bash "$FLEET" "$D/t_public.py" --out "$D/f4r1" --fleet "$D/codex.tbl" --r1-only < /dev/null > /dev/null 2>&1
148
+ rm -f "$D/ran"
149
+ FH_CODEX_BIN="$D/codex_fake" bash "$FLEET" "$D/t_company.py" --out "$D/f4r2" --reuse-r1 "$D/f4r1" --round2 < /dev/null > "$D/f4r2.out" 2>&1
150
+ if [ ! -e "$D/ran" ] && grep -qs 'CODEX-REFUSED' "$D/f4r2/err2_codex_logic.txt"; then ok "C8d fleet round 2 on a company file: refused"
151
+ else bad "C8d round 2: started=$([ -e "$D/ran" ] && echo yes || echo no) r2err=$(head -c 80 "$D/f4r2/err2_codex_logic.txt" 2>/dev/null)"; fi
152
+ # C8e a guard refusal seen through sidecar_wait is HARNESS-ERROR (nothing was reviewed), not COMPLETE
153
+ SW="$REPO/scripts/sidecar_wait.sh"
154
+ rm -f "$D/ran"
155
+ printf 'review %s/src\n' "$ROOT" | SIDECAR_POLL=1 bash "$SW" "$D/sw.out" 20 -- bash "$GUARD" "$D/codex_fake" exec - > "$D/sw.txt" 2>&1; swrc=$?
156
+ grep -q 'SIDECAR_VERDICT=HARNESS-ERROR.*reason=guard-refused' "$D/sw.txt" && [ "$swrc" -eq 3 ] && [ ! -e "$D/ran" ] \
157
+ && ok "C8e guard refusal through sidecar_wait: HARNESS-ERROR reason=guard-refused (rc 3)" || bad "C8e sidecar_wait: rc=$swrc verdict=$(grep -m1 SIDECAR_VERDICT "$D/sw.txt")"
158
+ printf '%s\n' '{"id":"x1","title":"t","file":"t.py","line":1,"severity":"B","category":"x","detail":"d","defeater":"df","confidence":0.5}' > "$D/claims.jsonl"
159
+ rm -f "$D/ran"
160
+ FH_CODEX_BIN="$D/codex_fake" bash "$VERIFIER" --family codex --target "$D/t_company.py" < "$D/claims.jsonl" > "$D/v1.out" 2> "$D/v1.err"; vrc=$?
161
+ [ ! -e "$D/ran" ] && [ "$vrc" -ne 0 ] && ok "C9 verifier --family codex on a company file: not started (rc=$vrc)" || bad "C9 verifier company: rc=$vrc started=$([ -e "$D/ran" ] && echo yes || echo no)"
162
+ rm -f "$D/ran"
163
+ FH_CODEX_BIN="$D/codex_fake" bash "$VERIFIER" --family codex --target "$D/t_public.py" < "$D/claims.jsonl" > /dev/null 2>&1
164
+ [ -e "$D/ran" ] && ok "C9b verifier on a public file: runs (control alive)" || bad "C9b verifier public: not started"
165
+
166
+ echo "── static"
167
+ # C10 shipped scripts start codex only through the guard. Comment lines are skipped; lanes and the guard
168
+ # itself are excluded. Residual: a launch assembled from pieces is not seen by a line scan.
169
+ hits=$(cd "$REPO/scripts" && grep -nE '(^|[[:space:](="])("?\$\{?CODEX\}?"?|codex)[[:space:]]+exec([[:space:]]|$)' \
170
+ $(ls *.sh | grep -vE '^(test_|codex_launch_guard\.sh$|docker_phase1_verify\.sh$|fh-goal\.sh$|fh-gate\.sh$|fh-run\.sh$)') 2>/dev/null | grep -vE ':[0-9]+:[[:space:]]*#' | grep -v 'CODEX_GUARD' || true)
171
+ # Excluded by name, on purpose:
172
+ # · docker_phase1_verify.sh — runs codex INSIDE a container with a fixed «reply OK» prompt; no file of
173
+ # this machine can reach that call.
174
+ # · fh-goal.sh · fh-gate.sh · fh-run.sh — runtime adapters: codex there is the user's chosen agent doing
175
+ # the user's own work, not a verifier arm handed someone else's material. Guarding them would block a
176
+ # consumer whose organisation allows codex. This guard covers verifier arms only.
177
+ [ -z "$hits" ] && ok "C10 no shipped script starts codex around the guard" || { bad "C10 unguarded codex launch(es):"; printf ' %s\n' "$hits"; }
178
+ printf 'out=$(codex exec -)\n' > "$D/probe.sh"
179
+ grep -qE '(^|[[:space:](="])("?\$\{?CODEX\}?"?|codex)[[:space:]]+exec([[:space:]]|$)' "$D/probe.sh" && ok "C11 static pattern sees a known unguarded line (control alive)" || bad "C11 static pattern blind"
180
+
181
+ echo
182
+ echo "codex launch guard lanes: $PASS passed, $FAIL failed"
183
+ [ "$FAIL" -eq 0 ]
@@ -37,6 +37,43 @@ printf '%s\n' '{"ts": "2026-10-01T10:00:00", "n": 1, "text": "아니 이 표의
37
37
  printf '%s\n' '{"ts": "2026-10-03T10:00:00", "n": 1, "text": "아니 이 표의 분모가 틀렸어 재현율 다시 계산"}' > "$T/rep/c2.jsonl"
38
38
  check L6-repaste-dropped 0 'recurring pairs .*=0 · re-pasted pairs dropped=1' "$T/rep"
39
39
  check L7-empty-not-zero 2 'NOT MEASURED' "$T/empty"
40
+ # L8: scheduled-trigger prompts land in the ledger as if the operator typed them. Two different cron
41
+ # prompts, each fired on three days, share words («linked list_sessions») and paired with each other
42
+ # across days — 2026-11-20 weekly audit: 24 of 24 «recurring pairs» were cron text. A prompt whose
43
+ # first 40 characters repeat >= 3 times is a scheduled prompt: excluded and COUNTED, never a hit.
44
+ # The one-off correction on the same days must still be a hit (control: the exclusion is not blanket).
45
+ mkdir -p "$T/cron"
46
+ for d in 01 02 03; do
47
+ printf '%s\n' "{\"ts\": \"2026-10-${d}T01:17:00\", \"n\": 1, \"text\": \"[야간 자동 재개 점검 — 매시 17분] 왜 멈췄는지 linked list_sessions 로 확인하고 재개\"}"
48
+ printf '%s\n' "{\"ts\": \"2026-10-${d}T03:53:00\", \"n\": 2, \"text\": \"Night check (root, lease) — list_sessions linked: don't merge what the lease does not allow\"}"
49
+ done > "$T/cron/c.jsonl"
50
+ printf '%s\n' '{"ts": "2026-10-02T12:00:00", "n": 3, "text": "증명을 한게 아니잖아 다시 확인해"}' >> "$T/cron/c.jsonl"
51
+ check L8-cron-prompt-excluded 0 'malformed=0 repeated-prompt=6 · cue hits=1 · recurring pairs .*=0 ' "$T/cron"
52
+ cron_all=$(python3 "$S" "$T/cron" --all)
53
+ if printf '%s' "$cron_all" | grep -q '증명을 한게 아니잖아'; then echo "PASS L8c-one-off-still-a-hit"; pass=$((pass + 1)); else echo "FAIL L8c-one-off-still-a-hit"; fail=$((fail + 1)); fi
54
+ # L9: an operator phrase said twice (below the threshold) is not a scheduled prompt
55
+ mkdir -p "$T/twice"
56
+ printf '%s\n' '{"ts": "2026-10-01T10:00:00", "n": 1, "text": "아니 그 표 분모가 틀렸어 재현율로"}' '{"ts": "2026-10-05T10:00:00", "n": 2, "text": "아니 그 표 분모가 틀렸어 정밀도 말고"}' > "$T/twice/t.jsonl"
57
+ check L9-twice-is-not-cron 0 'repeated-prompt=0 · cue hits=2 ' "$T/twice"
58
+ # L10: a SHORT correction said three times is the signal this tool exists for — never excluded
59
+ mkdir -p "$T/short3"
60
+ for d in 01 03 05; do printf '%s\n' "{\"ts\": \"2026-10-${d}T10:00:00\", \"n\": 1, \"text\": \"아니 증명을 한게 아니잖아\"}"; done > "$T/short3/s.jsonl"
61
+ check L10-short-repeat-kept 0 'repeated-prompt=0 · cue hits=3 ' "$T/short3"
62
+ # L11: three different corrections that share a long opener are not one repeated prompt
63
+ mkdir -p "$T/opener"
64
+ for w in 분모 분자 표본수; do printf '%s\n' "{\"ts\": \"2026-10-02T10:00:00\", \"n\": 1, \"text\": \"아니 지난번 보고서 둘째 표에서 계산한 숫자들 다시 봐야 해, ${w} 가 틀렸어\"}"; done > "$T/opener/o.jsonl"
65
+ check L11-shared-opener-kept 0 'repeated-prompt=0 · cue hits=3 ' "$T/opener"
66
+ # L12: the verdict does not depend on --since — one fire before the window still counts toward the repeat,
67
+ # and a time inside the prompt (digits) does not hide the repeat
68
+ mkdir -p "$T/win"
69
+ for h in 1 2 3; do printf '%s\n' "{\"ts\": \"2026-10-0${h}T0${h}:17:00\", \"n\": 1, \"text\": \"[야간 점검 — 매시 ${h}7분, 10-0${h} 01시] 왜 멈췄는지 확인하고 멈춘 세션은 재개해 줘\"}"; done > "$T/win/w.jsonl"
70
+ printf '%s\n' '{"ts": "2026-10-03T12:00:00", "n": 2, "text": "아니 그건 틀렸어 다시 해"}' >> "$T/win/w.jsonl"
71
+ win_out=$(python3 "$S" "$T/win" --since 2026-10-02 2>&1)
72
+ if printf '%s' "$win_out" | grep -q 'repeated-prompt=2 · cue hits=1 '; then echo "PASS L12-since-and-digits"; pass=$((pass + 1)); else echo "FAIL L12-since-and-digits"; printf '%s\n' "$win_out" | sed -n 2p | sed 's/^/ /'; fail=$((fail + 1)); fi
73
+ # L13: a window holding only scheduled prompts is NOT MEASURED (rc 2), with the counts named
74
+ mkdir -p "$T/onlycron"
75
+ grep -v '그건 틀렸어' "$T/win/w.jsonl" > "$T/onlycron/c.jsonl"
76
+ check L13-only-cron-not-zero 2 'NOT MEASURED' "$T/onlycron"
40
77
  rm -rf "$T"
41
78
  echo "correction_moments lanes: $pass pass · $fail fail"
42
79
  [ "$fail" -eq 0 ]