@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
@@ -59,11 +59,13 @@ command -v gtimeout >/dev/null 2>&1 && TIMEOUT_BIN="gtimeout"
59
59
  # No coreutils timeout on stock macOS. perl's alarm is the portable watchdog; if perl is missing too,
60
60
  # run WITHOUT a deadline rather than skipping the probe — a missing watchdog must never become a
61
61
  # silently skipped measurement reported as absence (the same rule fh_session_load.sh applies).
62
+ # Every probe passes its prompt as an argument, so the runtime gets a closed stdin: inheriting the caller's
63
+ # stdin let codex_launch_guard.sh wait on an agent shell's never-ending one (2026-11-20, 2 h 30 min).
62
64
  _run() {
63
65
  local secs="$1"; shift
64
- if [ -n "$TIMEOUT_BIN" ]; then "$TIMEOUT_BIN" "$secs" "$@"
65
- elif command -v perl >/dev/null 2>&1; then perl -e 'alarm shift @ARGV; exec @ARGV' "$secs" "$@"
66
- else "$@"; fi
66
+ if [ -n "$TIMEOUT_BIN" ]; then "$TIMEOUT_BIN" "$secs" "$@" < /dev/null
67
+ elif command -v perl >/dev/null 2>&1; then perl -e 'alarm shift @ARGV; exec @ARGV' "$secs" "$@" < /dev/null
68
+ else "$@" < /dev/null; fi
67
69
  }
68
70
 
69
71
  # _answer — reduce a runtime's stdout to THE MODEL'S ANSWER.
@@ -94,6 +96,8 @@ VERDICT_PROMPT="Reply with exactly one word, PASS or FAIL, and nothing else. The
94
96
  BOGUS_MODEL="zzz-nonexistent-model-9.9"
95
97
 
96
98
  PANEL=""
99
+ AGY_GUARD="$(cd "$(dirname "$0")" && pwd)/agy_launch_guard.sh"
100
+ CODEX_GUARD="$(cd "$(dirname "$0")" && pwd)/codex_launch_guard.sh"
97
101
 
98
102
  # build_cmd <runtime> <model> <prompt> — fills CMD as an argv array.
99
103
  # NOT a shell function passed to the watchdog: `timeout`/`gtimeout` exec a BINARY and cannot see
@@ -101,8 +105,8 @@ PANEL=""
101
105
  # runtime failing to run (caught by lane 3/4b/5b, not by reading).
102
106
  build_cmd() {
103
107
  case "$1" in
104
- codex) CMD=(codex exec -m "$2" -c model_reasoning_effort=high --skip-git-repo-check "$3") ;;
105
- agy) CMD=(agy -p "$3" --model "$2" --print-timeout 170s) ;;
108
+ codex) CMD=(bash "$CODEX_GUARD" codex exec -m "$2" -c model_reasoning_effort=high --skip-git-repo-check "$3") ;; # company-root paths refused
109
+ agy) CMD=(bash "$AGY_GUARD" agy -p "$3" --model "$2" --print-timeout 170s) ;; # refuses unless FH_AGY_ISOLATION=container|os-user|no-tools-agent
106
110
  *) CMD=("$1" "$3") ;;
107
111
  esac
108
112
  }
@@ -125,6 +129,12 @@ probe_runtime() {
125
129
  # (`${PIPESTATUS[0]}` 는 bash 전용이고, 정본은 «파이프를 쓰지 않는 것» 이다.)
126
130
  id_raw="$(_run 200 "${CMD[@]}" 2>&1)"; id_rc=$?
127
131
  id_out="$(printf '%s\n' "$id_raw" | _answer)"
132
+ # The isolation guard refused before agy started: nothing was measured. Say so instead of reading
133
+ # the refusal text as the model's answer (it rendered REACHABLE · control: rejects-bogus before).
134
+ if [ "$id_rc" -eq 3 ] && printf '%s\n' "$id_raw" | grep -q '^AGY-REFUSED'; then
135
+ printf '%-6s REFUSED — agy_launch_guard: FH_AGY_ISOLATION is not container|os-user|no-tools-agent (or that route refused), agy not started, nothing measured\n' "$rt"
136
+ return 0
137
+ fi
128
138
 
129
139
  # Discriminating check — the answer must be the MODEL's self-report naming the model that was
130
140
  # pinned. What counts as "naming it" is the VERSION token, not every token of the pin slug:
@@ -27,12 +27,18 @@
27
27
  # SIDECAR_VERDICT=TIMEOUT waited=<n>s bytes=<n> still alive when the budget ran out; NOT a result
28
28
  # SIDECAR_VERDICT=EMPTY exit=<n> exited cleanly having written nothing — the only
29
29
  # state in which "the sidecar said nothing" is true
30
+ # SIDECAR_VERDICT=HARNESS-ERROR exit=<n> reason=model-not-available|guard-refused the CLI refused the
31
+ # model, or a launch guard refused to start it
32
+ # (exit 3) — nothing was reviewed; never read as 0 findings
30
33
  #
31
34
  # Usage:
32
35
  # bash scripts/sidecar_wait.sh <outfile> <timeout_seconds> -- <command> [args...]
33
- # printf '%s' "$prompt" | bash scripts/sidecar_wait.sh out.txt 600 -- codex exec -m gpt-5.5 -
36
+ # printf '%s' "$prompt" | bash scripts/sidecar_wait.sh out.txt 600 -- bash scripts/codex_launch_guard.sh codex exec -
37
+ # (no -m: the CLI default answers; a pinned model can be retired — gpt-5.5 / gpt-5 return HTTP 400
38
+ # on 2026-11-16 — and then this wrapper reports HARNESS-ERROR, not a result)
34
39
  #
35
40
  # Exit: 0 = COMPLETE (with or without output) · 1 = TIMEOUT (verdict withheld, not a failure claim)
41
+ # · 3 = HARNESS-ERROR (the CLI refused the model; nothing was reviewed)
36
42
  set -uo pipefail
37
43
 
38
44
  OUT="${1:?usage: sidecar_wait.sh <outfile> <timeout_s> -- <cmd...>}"
@@ -118,6 +124,20 @@ done
118
124
 
119
125
  wait "$PID"; rc=$?
120
126
  size=$(wc -c < "$OUT" 2>/dev/null | tr -d ' ')
127
+ # A model the CLI refuses (measured 2026-11-16: codex `-m gpt-5.5` → HTTP 400 «not supported when using
128
+ # Codex with a ChatGPT account», rc 1) is a broken instrument, not a review that found nothing. COMPLETE
129
+ # with that body reads as «the reviewer answered», so it gets its own verdict and a non-zero exit.
130
+ if [ "$rc" -ne 0 ] && grep -qE 'model_not_found|model is not supported|requires a newer version of Codex' "$OUT" 2>/dev/null; then
131
+ echo "SIDECAR_VERDICT=HARNESS-ERROR exit=$rc reason=model-not-available bytes=${size:-0}"
132
+ echo " the sidecar refused the requested model — nothing was reviewed. Drop the -m pin (CLI default) or pin a model that answers." >&2
133
+ exit 3
134
+ fi
135
+ # A launch guard that refused (codex_launch_guard.sh / agy_launch_guard.sh) started nothing: same verdict.
136
+ if [ "$rc" -ne 0 ] && grep -qE 'CODEX-REFUSED|AGY-REFUSED' "$OUT" 2>/dev/null; then
137
+ echo "SIDECAR_VERDICT=HARNESS-ERROR exit=$rc reason=guard-refused bytes=${size:-0}"
138
+ echo " a launch guard refused — the sidecar was never started, so nothing was reviewed." >&2
139
+ exit 3
140
+ fi
121
141
  if [ "${size:-0}" -eq 0 ]; then
122
142
  echo "SIDECAR_VERDICT=EMPTY exit=$rc"
123
143
  else
@@ -683,6 +683,7 @@ echo "out=$OUTDIR"
683
683
  snapshot "$OUTDIR/_machine_before.txt"
684
684
 
685
685
  CONTAMINATED=0
686
+ N_CAPTURED=0; N_EMPTY=0; N_UNMEASURED=0 # run-level tally (AQ-20261108-6) — record only
686
687
  for r in $(seq 1 "$REPS"); do
687
688
  # A reused --out must not carry the previous run's budget record into a rep that fails before
688
689
  # writing its own (clone failure `continue`s first) — a stale `ended_at_cap=no` would be read as
@@ -931,6 +932,14 @@ for r in $(seq 1 "$REPS"); do
931
932
  # `timeout 300`, which killed exactly the heavy arms — the ones where the behaviour under test
932
933
  # actually fired — and left 0-byte files that read as "the identity did not fire". A false RED
933
934
  # generated by the instrument. So the verdict here is three-valued, never two.
935
+ # Tally kind (record only). Multi-turn writes «===== turn k (rc=…) =====» headers, so bytes>0
936
+ # even when every turn died — under --turns a rep with no rc-0 turn row counts as unmeasured.
937
+ _tk=captured
938
+ if [ "$rc" -ne 0 ] && [ "$bytes" -eq 0 ]; then _tk=unmeasured
939
+ elif [ "$bytes" -eq 0 ]; then _tk=empty
940
+ elif [ -n "$TURNS" ] && ! awk -F'\t' 'NR>1 && $2=="0"{f=1} END{exit !f}' "$OUTDIR/${ARM}_r${r}.turns.tsv" 2>/dev/null; then _tk=unmeasured
941
+ fi
942
+ case "$_tk" in unmeasured) N_UNMEASURED=$((N_UNMEASURED+1)) ;; empty) N_EMPTY=$((N_EMPTY+1)) ;; *) N_CAPTURED=$((N_CAPTURED+1)) ;; esac
934
943
  if [ "$rc" -ne 0 ] && [ "$bytes" -eq 0 ]; then
935
944
  echo " ⚠️ r$r UNMEASURED (rc=$rc, 0 bytes) — timeout or crash, NOT a negative result"
936
945
  elif [ "$bytes" -eq 0 ]; then
@@ -975,6 +984,17 @@ echo " 🟥 컨트롤 팔 없이 낸 숫자는 숫자가 아니다."
975
984
  echo " 🟢 «이게 FH 때문인가»가 궁금하면 같은 프롬프트를 --no-harness 로 한 번 더 돌려라."
976
985
  [ "$NOHARNESS" -eq 1 ] && echo " ⚠️ 이 실행은 --no-harness 다 — FH 를 잰 것이 아니라 «FH 없이도 그런가»를 잰 것이다."
977
986
  echo ""
987
+ # 🟥 Run-level tally (2026-11-19, AQ-20261108-6). The per-rep lines above already say UNMEASURED,
988
+ # but the run used to end on «RESULT: CLEAN» alone — and CLEAN is about contamination, not about
989
+ # whether anything ran. Measured elsewhere (fh-cartridges, 2026-11-08): every run of a batch died on
990
+ # an auth failure and the scorer wrote 0/6. A run where no rep produced output is FAILED-TO-RUN —
991
+ # not a score of zero. RECORD ONLY: no early stop, exit code unchanged (detector, never a gate).
992
+ # not_launched = reps that left the loop before the sim (clone / base-clone / blind-strip failure).
993
+ N_NOTLAUNCHED=$(( REPS - N_CAPTURED - N_EMPTY - N_UNMEASURED )); [ "$N_NOTLAUNCHED" -ge 0 ] || N_NOTLAUNCHED=0
994
+ echo "REPS: captured=$N_CAPTURED empty=$N_EMPTY unmeasured=$N_UNMEASURED not_launched=$N_NOTLAUNCHED of $REPS"
995
+ if [ "$REPS" -gt 0 ] && [ $(( N_CAPTURED + N_EMPTY )) -eq 0 ]; then
996
+ echo "RUN: FAILED-TO-RUN — no rep produced output ($N_UNMEASURED died, $N_NOTLAUNCHED never launched, of $REPS). Not a score of 0: fix the cause (auth · timeout · CLI · clone) and rerun."
997
+ fi
978
998
  [ "$CONTAMINATED" -eq 1 ] && echo "RESULT: CONTAMINATED — do not score" || echo "RESULT: CLEAN"
979
999
  echo "OUT: $OUTDIR"
980
1000
  # Detector, never a gate: always exit 0 so a caller cannot be trained to skip running it.
@@ -0,0 +1,347 @@
1
+ #!/usr/bin/env bash
2
+ # test_agy_launch_guard_lanes.sh — lanes for scripts/agy_launch_guard.sh and the three FH callers that
3
+ # launch agy (finding_fleet.sh default fleet · finding_verifier.sh --family gemini · sidecar_calibrate.sh).
4
+ #
5
+ # WHAT IS CHECKED: that no FH caller starts agy unless FH_AGY_ISOLATION is exactly `container` or
6
+ # `os-user`, that a refused launch is visible (AGY-REFUSED on stderr, non-zero), and that with the marker
7
+ # the call goes through with its arguments intact. Every lane uses a FAKE agy that only records that it
8
+ # was started — no real agy runs here.
9
+ # WHAT IS NOT CHECKED: whether the isolation the marker names is real. The marker is self-declared;
10
+ # no lane here can see a container or an OS user. Doc snippets (steel-quench / sim-conductor) that show
11
+ # `agy -p` are prose, not scripts, and are outside the static scan in G9.
12
+ #
13
+ # Usage: bash scripts/test_agy_launch_guard_lanes.sh Exit: 0 all pass · 1 any fail
14
+ set -uo pipefail
15
+ REPO="$(cd "$(dirname "$0")/.." && pwd)"
16
+ GUARD="$REPO/scripts/agy_launch_guard.sh"
17
+ FLEET="$REPO/scripts/finding_fleet.sh"
18
+ VERIFIER="$REPO/scripts/finding_verifier.sh"
19
+ CAL="$REPO/scripts/sidecar_calibrate.sh"
20
+ D="$(mktemp -d "${TMPDIR:-/tmp}/agyguard.XXXXXX")" || { echo "ENV-BLOCKED: mktemp failed — unmeasured, not a pass"; exit 1; }
21
+ trap 'rm -rf "$D"' EXIT
22
+ unset FH_AGY_ISOLATION
23
+ PASS=0; FAIL=0
24
+ ok() { PASS=$((PASS+1)); echo " ✅ $1"; }
25
+ bad() { FAIL=$((FAIL+1)); echo " ❌ $1"; }
26
+
27
+ # Fake agy: records that it started (and its argv, one per line), prints one JSONL finding / one word.
28
+ mkfake() { # $1 = path $2 = sentinel
29
+ cat > "$1" <<EOF
30
+ #!/usr/bin/env bash
31
+ printf '%s\n' "\$@" > "$2"
32
+ cat >/dev/null 2>&1 || true
33
+ echo '{"title":"fake finding","file":"t.py","line":1,"severity":"B","category":"x","detail":"d","defeater":"df","confidence":0.5}'
34
+ EOF
35
+ chmod +x "$1"
36
+ }
37
+ mkfake "$D/agy_fake" "$D/ran"
38
+ # Hermetic floor: a recording `agy` on the underlying PATH. If interception ever breaks, a bare `agy`
39
+ # lands here (recorded in ran_host) instead of on a real CLI. Every lane also asserts it never started.
40
+ mkdir -p "$D/hostbin"; mkfake "$D/hostbin/agy" "$D/ran_host"
41
+ REAL_AGY="$(command -v agy 2>/dev/null || true)" # N10 (opt-in) needs the real one — resolved BEFORE the fake shadows it
42
+ export PATH="$D/hostbin:$PATH"
43
+ printf 'def f():\n return 1\n' > "$D/t.py"
44
+
45
+ echo "── guard alone"
46
+ # G1 no marker → refused, fake never started
47
+ rm -f "$D/ran"
48
+ out=$(bash "$GUARD" "$D/agy_fake" -p "hello" < /dev/null 2>&1); rc=$?
49
+ if [ "$rc" -eq 3 ] && [ ! -e "$D/ran" ] && printf '%s' "$out" | grep -q 'AGY-REFUSED'; then ok "G1 no marker: rc=3, AGY-REFUSED, agy not started"
50
+ else bad "G1 no marker: rc=$rc ran=$([ -e "$D/ran" ] && echo yes || echo no) out=${out:0:120}"; fi
51
+
52
+ # G2 marker=container → started, argv intact (an argument with spaces survives as one)
53
+ rm -f "$D/ran"
54
+ FH_AGY_ISOLATION=container bash "$GUARD" "$D/agy_fake" -p "two words" --mode plan < /dev/null >/dev/null 2>&1; rc=$?
55
+ if [ "$rc" -eq 0 ] && [ -e "$D/ran" ] && [ "$(sed -n 2p "$D/ran")" = "two words" ] && [ "$(wc -l < "$D/ran" | tr -d ' ')" = 4 ]; then
56
+ ok "G2 container: started, argv intact"
57
+ else bad "G2 container: rc=$rc argv=$(tr '\n' '|' < "$D/ran" 2>/dev/null)"; fi
58
+
59
+ # G3 marker=os-user → started
60
+ rm -f "$D/ran"
61
+ FH_AGY_ISOLATION=os-user bash "$GUARD" "$D/agy_fake" -p x < /dev/null >/dev/null 2>&1; rc=$?
62
+ [ "$rc" -eq 0 ] && [ -e "$D/ran" ] && ok "G3 os-user: started" || bad "G3 os-user: rc=$rc"
63
+
64
+ # G4 near-miss values → refused (a truthy word is not an isolation statement)
65
+ for v in 1 yes true Container "container " none ""; do
66
+ rm -f "$D/ran"
67
+ FH_AGY_ISOLATION="$v" bash "$GUARD" "$D/agy_fake" -p x < /dev/null >/dev/null 2>&1; rc=$?
68
+ if [ "$rc" -eq 3 ] && [ ! -e "$D/ran" ]; then ok "G4 value '$v': refused"; else bad "G4 value '$v': rc=$rc started=$([ -e "$D/ran" ] && echo yes || echo no)"; fi
69
+ done
70
+
71
+ # G5 no binary given → usage, nothing started
72
+ bash "$GUARD" < /dev/null >/dev/null 2>&1; rc=$?
73
+ [ "$rc" -eq 2 ] && ok "G5 no args: rc=2" || bad "G5 no args: rc=$rc"
74
+
75
+ # G15 remote-os-user with any other target → refused, target not started
76
+ rm -f "$D/ran"
77
+ FH_AGY_ISOLATION=remote-os-user bash "$GUARD" "$D/agy_fake" -p x < /dev/null >/dev/null 2>&1; rc=$?
78
+ if [ "$rc" -eq 3 ] && [ ! -e "$D/ran" ]; then ok "G15 remote-os-user + other target: refused"; else bad "G15 remote-os-user + other target: rc=$rc started=$([ -e "$D/ran" ] && echo yes || echo no)"; fi
79
+ # G16 remote-os-user with a file NAMED agy_remote_run.sh elsewhere → refused (the path, not the name, is the route)
80
+ mkdir -p "$D/elsewhere"; mkfake "$D/elsewhere/agy_remote_run.sh" "$D/ran"
81
+ rm -f "$D/ran"
82
+ FH_AGY_ISOLATION=remote-os-user bash "$GUARD" "$D/elsewhere/agy_remote_run.sh" -p x < /dev/null >/dev/null 2>&1; rc=$?
83
+ if [ "$rc" -eq 3 ] && [ ! -e "$D/ran" ]; then ok "G16 remote-os-user + same-named file elsewhere: refused"; else bad "G16 same-named file elsewhere: rc=$rc started=$([ -e "$D/ran" ] && echo yes || echo no)"; fi
84
+
85
+ echo "── finding_fleet.sh default fleet (gemini row)"
86
+ cat > "$D/codex_fake" <<'EOF'
87
+ #!/usr/bin/env bash
88
+ cat >/dev/null 2>&1 || true
89
+ echo '{"title":"codex finding","file":"t.py","line":1,"severity":"B","category":"x","detail":"d","defeater":"df","confidence":0.5}'
90
+ EOF
91
+ chmod +x "$D/codex_fake"
92
+ # G6 no marker → gemini member not started and recorded as failed with the refusal; codex still runs
93
+ rm -f "$D/ran"
94
+ FH_CODEX_BIN="$D/codex_fake" FH_AGY_BIN="$D/agy_fake" bash "$FLEET" "$D/t.py" --out "$D/f6" < /dev/null > "$D/f6.out" 2>&1; rc=$?
95
+ if [ ! -e "$D/ran" ] && grep -qs 'AGY-REFUSED' "$D/f6/err_gemini_security.txt" && [ "$rc" -eq 0 ]; then
96
+ ok "G6 fleet no marker: gemini refused (err file), codex member kept rc=0"
97
+ else bad "G6 fleet no marker: rc=$rc agy_started=$([ -e "$D/ran" ] && echo yes || echo no) err=$(head -c 120 "$D/f6/err_gemini_security.txt" 2>/dev/null)"; fi
98
+ # G7 control — with the marker the same fleet DOES start the fake (the lane can see a start)
99
+ rm -f "$D/ran"
100
+ FH_AGY_ISOLATION=container FH_CODEX_BIN="$D/codex_fake" FH_AGY_BIN="$D/agy_fake" bash "$FLEET" "$D/t.py" --out "$D/f7" < /dev/null > "$D/f7.out" 2>&1; rc=$?
101
+ [ -e "$D/ran" ] && [ "$rc" -eq 0 ] && ok "G7 fleet with marker: gemini member started (control alive)" || bad "G7 fleet with marker: rc=$rc started=$([ -e "$D/ran" ] && echo yes || echo no)"
102
+
103
+ # G7b round 2 without the marker (reusing G7's round-1 findings) → not started, refusal in the r2 err file
104
+ rm -f "$D/ran"
105
+ FH_CODEX_BIN="$D/codex_fake" FH_AGY_BIN="$D/agy_fake" bash "$FLEET" "$D/t.py" --out "$D/f7b" --reuse-r1 "$D/f7" --round2 < /dev/null > "$D/f7b.out" 2>&1
106
+ if [ ! -e "$D/ran" ] && grep -qs 'AGY-REFUSED' "$D/f7b/err2_gemini_security.txt"; then ok "G7b fleet round 2 no marker: gemini refused"
107
+ else bad "G7b fleet round 2 no marker: started=$([ -e "$D/ran" ] && echo yes || echo no) err=$(head -c 120 "$D/f7b/err2_gemini_security.txt" 2>/dev/null)"; fi
108
+ # G7c control — round 2 with the marker starts it
109
+ rm -f "$D/ran"
110
+ FH_AGY_ISOLATION=container FH_CODEX_BIN="$D/codex_fake" FH_AGY_BIN="$D/agy_fake" bash "$FLEET" "$D/t.py" --out "$D/f7c" --reuse-r1 "$D/f7" --round2 < /dev/null > "$D/f7c.out" 2>&1
111
+ [ -e "$D/ran" ] && ok "G7c fleet round 2 with marker: started (control alive)" || bad "G7c fleet round 2 with marker: not started"
112
+ # G7d custom table rows that reach agy by NAME, in shapes a word match misses (redirection glued to the
113
+ # name, behind `env`, AGY_BIN behind `env`) → refused without the marker; G7e same rows with it → started.
114
+ # The real binary is FH_AGY_BIN (the fake); the shim on PATH is what a bare `agy` resolves to.
115
+ n=0
116
+ for row in 'agy -p "$(cat PROMPT_FILE)"' 'agy</dev/null -p hello' 'env agy -p hello' 'env AGY_BIN -p hello'; do
117
+ n=$((n+1)); printf 'gemini|security|%s\n' "$row" > "$D/direct$n.tbl"
118
+ rm -f "$D/ran"
119
+ FH_AGY_BIN="$D/agy_fake" bash "$FLEET" "$D/t.py" --out "$D/f7d$n" --fleet "$D/direct$n.tbl" < /dev/null > "$D/f7d$n.out" 2>&1
120
+ if [ ! -e "$D/ran" ] && grep -qs 'AGY-REFUSED' "$D/f7d$n/err_gemini_security.txt"; then ok "G7d row [$row]: refused without marker"
121
+ else bad "G7d row [$row]: started=$([ -e "$D/ran" ] && echo yes || echo no)"; fi
122
+ rm -f "$D/ran"
123
+ FH_AGY_ISOLATION=os-user FH_AGY_BIN="$D/agy_fake" bash "$FLEET" "$D/t.py" --out "$D/f7e$n" --fleet "$D/direct$n.tbl" < /dev/null > "$D/f7e$n.out" 2>&1
124
+ [ -e "$D/ran" ] && ok "G7e row [$row]: started with marker (control alive)" || bad "G7e row [$row]: not started with marker ($(head -c 100 "$D/f7e$n/err_gemini_security.txt" 2>/dev/null))"
125
+ done
126
+ # G7d-r2 a by-name row in ROUND 2 without the marker → refused (refusal text in the r2 err file);
127
+ # G7e-r2 same with the marker → started. Round-1 findings come from G7's run.
128
+ printf 'gemini|security|%s\n' 'agy -p "$(cat PROMPT_FILE)"' > "$D/direct_r2.tbl"
129
+ # --reuse-r1 takes the fleet from the round-1 dir, so round 1 runs with THIS table (marker on, r1 only)
130
+ FH_AGY_ISOLATION=container FH_AGY_BIN="$D/agy_fake" bash "$FLEET" "$D/t.py" --out "$D/f7r1d" --fleet "$D/direct_r2.tbl" --r1-only < /dev/null > /dev/null 2>&1
131
+ rm -f "$D/ran"
132
+ FH_AGY_BIN="$D/agy_fake" bash "$FLEET" "$D/t.py" --out "$D/f7dr2" --reuse-r1 "$D/f7r1d" --round2 < /dev/null > "$D/f7dr2.out" 2>&1
133
+ if [ ! -e "$D/ran" ] && grep -qs 'AGY-REFUSED' "$D/f7dr2/err2_gemini_security.txt"; then ok "G7d-r2 by-name row in round 2: refused without marker"
134
+ else bad "G7d-r2 by-name row in round 2: started=$([ -e "$D/ran" ] && echo yes || echo no) err=$(head -c 100 "$D/f7dr2/err2_gemini_security.txt" 2>/dev/null)"; fi
135
+ rm -f "$D/ran"
136
+ FH_AGY_ISOLATION=container FH_AGY_BIN="$D/agy_fake" bash "$FLEET" "$D/t.py" --out "$D/f7er2" --reuse-r1 "$D/f7r1d" --round2 < /dev/null > "$D/f7er2.out" 2>&1
137
+ [ -e "$D/ran" ] && ok "G7e-r2 by-name row in round 2 with marker: started (control alive)" || bad "G7e-r2 by-name row in round 2 with marker: not started"
138
+ # G7j an exported shell function named agy does not outrank the shim
139
+ agy() { : > "$D/ran_func"; }; export -f agy
140
+ rm -f "$D/ran" "$D/ran_func"
141
+ FH_AGY_BIN="$D/agy_fake" bash "$FLEET" "$D/t.py" --out "$D/f7j" --fleet "$D/direct1.tbl" < /dev/null > "$D/f7j.out" 2>&1
142
+ unset -f agy
143
+ if [ ! -e "$D/ran_func" ] && [ ! -e "$D/ran" ] && grep -qs 'AGY-REFUSED' "$D/f7j/err_gemini_security.txt"; then ok "G7j exported agy function: shim still wins, refused"
144
+ else bad "G7j exported agy function: func_ran=$([ -e "$D/ran_func" ] && echo yes || echo no)"; fi
145
+ # G14a hermetic floor so far — no unmarked lane above reached the underlying-PATH agy (G7k below starts it on purpose)
146
+ [ ! -e "$D/ran_host" ] && ok "G14a underlying-PATH agy not started by G1–G7j" || bad "G14a underlying-PATH agy was started before G7k — interception broke"
147
+ # G7k FH_AGY_BIN given as a bare name resolves once (no shim loop) — with the marker the PATH agy starts
148
+ rm -f "$D/ran_host"
149
+ FH_AGY_ISOLATION=container FH_CODEX_BIN="$D/codex_fake" FH_AGY_BIN=agy bash "$FLEET" "$D/t.py" --out "$D/f7k" < /dev/null > "$D/f7k.out" 2>&1 &
150
+ kpid=$!; k=0; while kill -0 "$kpid" 2>/dev/null && [ "$k" -lt 30 ]; do sleep 1; k=$((k+1)); done
151
+ if kill -0 "$kpid" 2>/dev/null; then kill "$kpid" 2>/dev/null; bad "G7k bare FH_AGY_BIN: still running after 30s (shim loop)"
152
+ elif [ -e "$D/ran_host" ]; then ok "G7k bare FH_AGY_BIN=agy: resolved to the PATH binary once"
153
+ else bad "G7k bare FH_AGY_BIN=agy: PATH agy never started"; fi
154
+ rm -f "$D/ran_host"
155
+ # G7h over-block control — a codex row whose TEXT mentions agy is not refused
156
+ printf 'codex|logic|%s\n' 'CODEX_BIN exec "review agy behavior"' > "$D/text.tbl"
157
+ FH_CODEX_BIN="$D/codex_fake" bash "$FLEET" "$D/t.py" --out "$D/f7i" --fleet "$D/text.tbl" < /dev/null > "$D/f7i.out" 2>&1; rc=$?
158
+ if [ "$rc" -eq 0 ] && ! grep -qs 'AGY-REFUSED' "$D/f7i/err_codex_logic.txt"; then ok "G7h codex row mentioning agy in text: runs (no over-block)"
159
+ else bad "G7h codex row mentioning agy in text: rc=$rc"; fi
160
+ # G7f a row that quotes the token ("AGY_BIN") still names one command (with the marker it starts)
161
+ printf 'gemini|security|%s\n' '"AGY_BIN" -p "$(cat PROMPT_FILE)"' > "$D/quoted.tbl"
162
+ rm -f "$D/ran"
163
+ FH_AGY_ISOLATION=container FH_AGY_BIN="$D/agy_fake" bash "$FLEET" "$D/t.py" --out "$D/f7f" --fleet "$D/quoted.tbl" < /dev/null > "$D/f7f.out" 2>&1
164
+ [ -e "$D/ran" ] && ok "G7f quoted \"AGY_BIN\" row: started with the marker" || bad "G7f quoted \"AGY_BIN\" row: not started ($(head -c 120 "$D/f7f/err_gemini_security.txt" 2>/dev/null))"
165
+ # G7g scripts installed under a directory whose name holds `&` and the text PROMPT_FILE: no marker → refused,
166
+ # marker → started (a pasted path could otherwise background the launch or be rewritten)
167
+ W="$D/a&agy&PROMPT_FILE"; mkdir -p "$W"; cp "$FLEET" "$GUARD" "$W/"
168
+ rm -f "$D/ran"
169
+ FH_CODEX_BIN="$D/codex_fake" FH_AGY_BIN="$D/agy_fake" bash "$W/finding_fleet.sh" "$D/t.py" --out "$D/f7g" < /dev/null > "$D/f7g.out" 2>&1
170
+ g1=$([ -e "$D/ran" ] && echo started || echo not-started)
171
+ rm -f "$D/ran"
172
+ FH_AGY_ISOLATION=container FH_CODEX_BIN="$D/codex_fake" FH_AGY_BIN="$D/agy_fake" bash "$W/finding_fleet.sh" "$D/t.py" --out "$D/f7h" < /dev/null > "$D/f7h.out" 2>&1
173
+ g2=$([ -e "$D/ran" ] && echo started || echo not-started)
174
+ [ "$g1" = not-started ] && [ "$g2" = started ] && ok "G7g odd install path: refused without marker, started with it" || bad "G7g odd install path: without=$g1 with=$g2"
175
+
176
+ echo "── finding_verifier.sh --family gemini"
177
+ 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"
178
+ # G8 no marker → not started, non-zero
179
+ rm -f "$D/ran"
180
+ FH_AGY_BIN="$D/agy_fake" bash "$VERIFIER" --family gemini --target "$D/t.py" < "$D/claims.jsonl" > "$D/v8.out" 2> "$D/v8.err"; rc=$?
181
+ if [ ! -e "$D/ran" ] && [ "$rc" -ne 0 ]; then ok "G8 verifier no marker: agy not started, rc=$rc"
182
+ else bad "G8 verifier no marker: rc=$rc started=$([ -e "$D/ran" ] && echo yes || echo no)"; fi
183
+ # G9 control — with the marker the verifier starts it
184
+ rm -f "$D/ran"
185
+ FH_AGY_ISOLATION=container FH_AGY_BIN="$D/agy_fake" bash "$VERIFIER" --family gemini --target "$D/t.py" < "$D/claims.jsonl" >/dev/null 2>&1
186
+ [ -e "$D/ran" ] && ok "G9 verifier with marker: started (control alive)" || bad "G9 verifier with marker: not started"
187
+
188
+ echo "── sidecar_calibrate.sh --only agy"
189
+ mkdir -p "$D/bin"; mkfake "$D/bin/agy" "$D/ran"
190
+ # G10 no marker → the PATH agy is not started; the row is not PINNED/PASS
191
+ rm -f "$D/ran"
192
+ c_out=$(PATH="$D/bin:$PATH" bash "$CAL" --only agy 2>&1 < /dev/null)
193
+ if [ ! -e "$D/ran" ] && printf '%s' "$c_out" | grep -qE '^agy +REFUSED' && ! printf '%s' "$c_out" | grep -qE '^agy +.*REACHABLE'; then ok "G10 calibrate no marker: agy not started, row says REFUSED (not REACHABLE)"
194
+ else bad "G10 calibrate no marker: started=$([ -e "$D/ran" ] && echo yes || echo no) out=$(printf '%s' "$c_out" | grep -m1 '^agy' | cut -c1-120)"; fi
195
+ # G11 control — with the marker the probe starts the PATH agy
196
+ rm -f "$D/ran"
197
+ FH_AGY_ISOLATION=container PATH="$D/bin:$PATH" bash "$CAL" --only agy >/dev/null 2>&1 < /dev/null
198
+ [ -e "$D/ran" ] && ok "G11 calibrate with marker: started (control alive)" || bad "G11 calibrate with marker: not started"
199
+
200
+ echo "── static: no shipped script launches agy around the guard"
201
+ # G12 every line in scripts/*.sh (not lanes, not the guard) that starts agy with a prompt/mode flag must
202
+ # go through the guard. Comment lines are skipped. Known residual: a launch built from pieces
203
+ # (variables, eval of a table row other than AGY_BIN) is not seen by a line scan.
204
+ hits=$(cd "$REPO/scripts" && grep -nE '(^|[[:space:]("=])("?\$\{?AGY\}?"?|agy)[[:space:]]+(-p|--print|--prompt|--mode|-i)([[:space:]]|$)' \
205
+ $(ls *.sh | grep -vE '^(test_|agy_launch_guard\.sh$)') 2>/dev/null \
206
+ | grep -vE ':[0-9]+:[[:space:]]*#' | grep -v 'AGY_GUARD' || true)
207
+ if [ -z "$hits" ]; then ok "G12 static scan: no unguarded agy launch in shipped scripts"
208
+ else bad "G12 static scan: unguarded launch(es):"; printf ' %s\n' "$hits"; fi
209
+ # G13 control for G12 — the same pattern DOES see an unguarded line
210
+ printf 'out=$(agy -p "$1")\n' > "$D/probe.sh"
211
+ grep -qE '(^|[[:space:]("=])("?\$\{?AGY\}?"?|agy)[[:space:]]+(-p|--print|--prompt|--mode|-i)([[:space:]]|$)' "$D/probe.sh" \
212
+ && ok "G13 static pattern sees a known unguarded line (control alive)" || bad "G13 static pattern blind to a known unguarded line"
213
+
214
+ # G7l exported agy function AND bare FH_AGY_BIN AND marker — still resolves to the PATH binary (no loop)
215
+ agy() { : > "$D/ran_func"; }; export -f agy
216
+ rm -f "$D/ran_host" "$D/ran_func"
217
+ FH_AGY_ISOLATION=container FH_CODEX_BIN="$D/codex_fake" FH_AGY_BIN=agy bash "$FLEET" "$D/t.py" --out "$D/f7l" < /dev/null > "$D/f7l.out" 2>&1 &
218
+ kpid=$!; k=0; while kill -0 "$kpid" 2>/dev/null && [ "$k" -lt 30 ]; do sleep 1; k=$((k+1)); done
219
+ unset -f agy
220
+ if kill -0 "$kpid" 2>/dev/null; then kill "$kpid" 2>/dev/null; bad "G7l exported function + bare name: still running after 30s (loop)"
221
+ elif [ -e "$D/ran_host" ] && [ ! -e "$D/ran_func" ]; then ok "G7l exported function + bare name: PATH agy started once, function ignored"
222
+ else bad "G7l exported function + bare name: host=$([ -e "$D/ran_host" ] && echo yes || echo no) func=$([ -e "$D/ran_func" ] && echo yes || echo no)"; fi
223
+ rm -f "$D/ran_host"
224
+ # G14b hermetic floor after G7k — the lanes after it (verifier, calibrate, static) did not reach it either
225
+ [ ! -e "$D/ran_host" ] && ok "G14b underlying-PATH agy not started after G7k" || bad "G14b underlying-PATH agy was started after G7k"
226
+
227
+ echo "── FH_AGY_ISOLATION=no-tools-agent (fake agy emitting a chosen stream)"
228
+ # The fake records the definition it was pointed at (as the run saw it) and prints the stream NT_MODE names.
229
+ # Stream shape copied from a real agy 1.5.11 run on 2026-11-19 (init · step_update · result events).
230
+ cat > "$D/agy_nt" <<'EOF'
231
+ #!/usr/bin/env bash
232
+ name=""; prev=""; for a in "$@"; do [ "$prev" = --agent ] && name="$a"; prev="$a"; done
233
+ : > "$NT_LOG.ran"; cat "$FH_AGY_AGENTS_DIR/$name.md" > "$NT_LOG.def" 2>/dev/null
234
+ cat > /dev/null
235
+ init() { printf '{"event":"init","init":{"model":"m","agent":"%s","tools":["a","b"]}}\n' "$1"; }
236
+ step() { printf '{"event":"step_update","step_update":{"step_index":"%s","state":"DONE","step_type":"%s"%s}}\n' "$1" "$2" "${3:-}"; }
237
+ res() { printf '{"event":"result","result":{"status":"%s","response":"FAKE-OK\\n"}}\n' "$1"; }
238
+ # A real tool step (agy 1.5.11, 13 probe runs) names the tool twice: tool_name and tool_info.name.
239
+ tool() { printf ',"tool_name":"%s","tool_info":{"name":"%s","parameters":{}}' "$1" "${2-$1}"; }
240
+ case "$NT_MODE" in
241
+ ok) init "$name"; step 0 user_input; step 1 agent_response; res SUCCESS ;;
242
+ mt) init "$name"; step 0 user_input; step 1 tool "$(tool manage_task)"; step 2 agent_response; res SUCCESS ;;
243
+ read) init "$name"; step 0 user_input; step 1 tool "$(tool read_file)"; step 2 agent_response; res SUCCESS ;;
244
+ readerr) init "$name"; step 0 user_input; step 1 tool "$(tool read_file)" | sed 's/"DONE"/"ERROR"/'; step 2 agent_response; res SUCCESS ;;
245
+ noname) init "$name"; step 0 user_input; step 1 tool; step 2 agent_response; res SUCCESS ;;
246
+ mixed) init "$name"; step 0 user_input; step 1 tool "$(tool manage_task read_file)"; res SUCCESS ;;
247
+ mixed2) init "$name"; step 0 user_input; step 1 tool "$(tool search_web manage_task)"; res SUCCESS ;;
248
+ halfname) init "$name"; step 0 user_input; step 1 tool ',"tool_name":"manage_task"'; res SUCCESS ;;
249
+ other) init "someone-else"; step 0 user_input; step 1 agent_response; res SUCCESS ;;
250
+ garbage) init "$name"; echo 'not json {'; step 1 agent_response; res SUCCESS ;;
251
+ blank) init "$name"; echo ' '; step 1 agent_response; res SUCCESS ;;
252
+ noresult) init "$name"; step 0 user_input; step 1 agent_response ;;
253
+ unknown) init "$name"; step 0 user_input; step 1 browser_action; res SUCCESS ;;
254
+ failed) init "$name"; step 0 user_input; step 1 agent_response; res ERROR ;;
255
+ noinit) step 0 user_input; step 1 agent_response; res SUCCESS ;;
256
+ esac
257
+ EOF
258
+ chmod +x "$D/agy_nt"
259
+ mkdir -p "$D/agents" "$D/ntcwd"
260
+ export FH_AGY_AGENTS_DIR="$D/agents"
261
+ NT() { # $1 = mode ; rest = extra args. Sets rc, out, err. Configured roots name a folder nothing here uses.
262
+ rm -f "$D/nt.ran" "$D/nt.def"
263
+ out=$( cd "$D/ntcwd" && NT_MODE="$1" NT_LOG="$D/nt" FH_COMPANY_ROOTS="$D/corp" FH_AGY_ISOLATION=no-tools-agent \
264
+ bash "$GUARD" "$D/agy_nt" -p "public text" --mode plan "${@:2}" < /dev/null 2> "$D/nt.err" ); rc=$?
265
+ err=$(cat "$D/nt.err")
266
+ }
267
+ left() { ls "$D/agents" | grep -c 'fh-notools-' || true; }
268
+ NT ok
269
+ if [ "$rc" -eq 0 ] && [ "$out" = "FAKE-OK" ] && grep -q '^tools: \[\]$' "$D/nt.def" && [ "$(left)" = 0 ]; then ok "N1 clean run: rc=0, response on stdout, the agent it ran had tools: [], definition removed"
270
+ else bad "N1 clean run: rc=$rc out=[$out] def=$(head -c 80 "$D/nt.def" 2>/dev/null) left=$(left) err=${err:0:120}"; fi
271
+ NT mt
272
+ [ "$rc" -eq 0 ] && [ "$out" = "FAKE-OK" ] && ok "N2 a manage_task step only: passes" || bad "N2 manage_task only: rc=$rc out=[$out] err=${err:0:120}"
273
+ for m in read readerr noname mixed mixed2 halfname other garbage blank noresult unknown failed noinit; do
274
+ NT "$m"
275
+ if [ "$rc" -eq 4 ] && [ -z "$out" ] && printf '%s' "$err" | grep -q '^AGY-VOID' && [ "$(left)" = 0 ]; then ok "N3 stream '$m': voided (rc=4, stdout empty, definition removed) — ${err:9:60}"
276
+ else bad "N3 stream '$m': rc=$rc out=[$out] left=$(left) err=${err:0:120}"; fi
277
+ done
278
+ NT read
279
+ printf '%s' "$err" | grep -q 'read_file' && ok "N4 the void names the tool (read_file)" || bad "N4 void does not name the tool: ${err:0:120}"
280
+ # Refusals happen BEFORE agy starts.
281
+ rm -f "$D/nt.ran"
282
+ out=$( cd "$D/ntcwd" && NT_MODE=ok NT_LOG="$D/nt" FH_COMPANY_ROOTS="$D/corp" FH_AGY_ISOLATION=no-tools-agent \
283
+ bash "$GUARD" "$D/agy_nt" -p "summarise $D/corp/src/a.py" < /dev/null 2>&1 ); rc=$?
284
+ [ "$rc" -eq 3 ] && [ ! -e "$D/nt.ran" ] && ok "N5 a company root in the arguments: refused, agy not started" || bad "N5 company root in args: rc=$rc started=$([ -e "$D/nt.ran" ] && echo yes || echo no)"
285
+ rm -f "$D/nt.ran"
286
+ out=$( cd "$D/ntcwd" && printf 'look at %s/x\n' "$D/corp" | NT_MODE=ok NT_LOG="$D/nt" FH_COMPANY_ROOTS="$D/corp" FH_AGY_ISOLATION=no-tools-agent \
287
+ bash "$GUARD" "$D/agy_nt" -p - 2>&1 ); rc=$?
288
+ [ "$rc" -eq 3 ] && [ ! -e "$D/nt.ran" ] && ok "N6 a company root in the prompt on stdin: refused, agy not started" || bad "N6 company root on stdin: rc=$rc started=$([ -e "$D/nt.ran" ] && echo yes || echo no)"
289
+ mkdir -p "$D/corp/bin"; cp "$D/agy_nt" "$D/corp/bin/agy"; rm -f "$D/nt.ran"
290
+ out=$( cd "$D/ntcwd" && NT_MODE=ok NT_LOG="$D/nt" FH_COMPANY_ROOTS="$D/corp" FH_AGY_ISOLATION=no-tools-agent \
291
+ bash "$GUARD" "$D/corp/bin/agy" -p x < /dev/null 2>&1 ); rc=$?
292
+ [ "$rc" -eq 3 ] && [ ! -e "$D/nt.ran" ] && ok "N6b the agy binary itself under a company root: refused" || bad "N6b binary under company root: rc=$rc started=$([ -e "$D/nt.ran" ] && echo yes || echo no)"
293
+ mkdir -p "$D/corp/sub"; rm -f "$D/nt.ran"
294
+ out=$( cd "$D/corp/sub" && NT_MODE=ok NT_LOG="$D/nt" FH_COMPANY_ROOTS="$D/corp" FH_AGY_ISOLATION=no-tools-agent \
295
+ bash "$GUARD" "$D/agy_nt" -p x < /dev/null 2>&1 ); rc=$?
296
+ [ "$rc" -eq 3 ] && [ ! -e "$D/nt.ran" ] && ok "N7 working folder under a company root: refused" || bad "N7 company cwd: rc=$rc"
297
+ rm -f "$D/nt.ran"
298
+ out=$( cd "$D/ntcwd" && NT_MODE=ok NT_LOG="$D/nt" FH_COMPANY_ROOTS= FH_COMPANY_ROOTS_FILE="$D/no-such-list" FH_AGY_ISOLATION=no-tools-agent \
299
+ bash "$GUARD" "$D/agy_nt" -p x < /dev/null 2>&1 ); rc=$?
300
+ [ "$rc" -eq 3 ] && [ ! -e "$D/nt.ran" ] && printf '%s' "$out" | grep -q 'no company-repo roots' && ok "N8 no company-root list: refused (unchecked is not clean)" || bad "N8 unconfigured: rc=$rc out=${out:0:120}"
301
+ for extra in "--agent mine" "--agent=mine" "--output-format=json" "--output-format stream-json" "--output-format"; do
302
+ rm -f "$D/nt.ran"; NT ok $extra
303
+ [ "$rc" -eq 3 ] && [ ! -e "$D/nt.ran" ] && ok "N9 caller passes [$extra]: refused" || bad "N9 caller passes [$extra]: rc=$rc"
304
+ done
305
+ # N9b FH's own callers pass `--output-format text` — dropped, not refused, and not handed to agy (agy gets stream-json once)
306
+ for extra in "--output-format text" "--output-format=text"; do
307
+ rm -f "$D/nt.ran"; NT ok $extra
308
+ if [ "$rc" -eq 0 ] && [ "$out" = "FAKE-OK" ]; then ok "N9b caller passes [$extra] (as finding_fleet / finding_verifier do): runs, text out"
309
+ else bad "N9b caller passes [$extra]: rc=$rc err=${err:0:120}"; fi
310
+ done
311
+ # N9c the fake records its argv: exactly one --output-format, and it is stream-json; the caller's other flags survive
312
+ cat > "$D/agy_argv" <<'EOF'
313
+ #!/usr/bin/env bash
314
+ printf '%s\n' "$@" > "$NT_LOG.argv"; name=""; prev=""; for a in "$@"; do [ "$prev" = --agent ] && name="$a"; prev="$a"; done
315
+ cat >/dev/null
316
+ printf '{"event":"init","init":{"agent":"%s"}}\n{"event":"result","result":{"status":"SUCCESS","response":"x"}}\n' "$name"
317
+ EOF
318
+ chmod +x "$D/agy_argv"
319
+ ( cd "$D/ntcwd" && NT_LOG="$D/nt" FH_COMPANY_ROOTS="$D/corp" FH_AGY_ISOLATION=no-tools-agent \
320
+ bash "$GUARD" "$D/agy_argv" --mode plan --sandbox --output-format text -p "two words" < /dev/null >/dev/null 2>&1 )
321
+ if [ "$(grep -c '^--output-format$' "$D/nt.argv")" = 1 ] && grep -qx 'stream-json' "$D/nt.argv" && ! grep -qx 'text' "$D/nt.argv" \
322
+ && grep -qx 'two words' "$D/nt.argv" && grep -qx -- '--sandbox' "$D/nt.argv"; then ok "N9c agy got one --output-format (stream-json), caller's flags intact"
323
+ else bad "N9c argv: $(tr '\n' '|' < "$D/nt.argv")"; fi
324
+ # N10 opt-in real canary (never in CI): a real agy, a random token in a file in a scratch working folder and one
325
+ # outside it; passes only if no run printed the token and every run either passed the stream check or was voided.
326
+ # 🟥 It must run the REAL agy: the hermetic fake on PATH (above) answers `command -v agy` inside this file, and a
327
+ # first version of N10 ran that fake, got a non-stream reply, was voided — and counted the void as a pass.
328
+ if [ "${FH_AGY_REAL_CANARY:-0}" = 1 ] && [ -n "${FH_COMPANY_ROOTS:-}${FH_COMPANY_ROOTS_FILE:-}" ] && [ -n "$REAL_AGY" ] && [ "$REAL_AGY" != "$D/hostbin/agy" ]; then
329
+ unset FH_AGY_AGENTS_DIR
330
+ C="$D/canary"; mkdir -p "$C/cwd" "$C/out"; tok="CANARY-$(od -An -N6 -tx1 /dev/urandom | tr -d ' \n')"
331
+ echo "$tok" > "$C/cwd/inside.txt"; echo "$tok" > "$C/out/outside.txt"
332
+ out=$( cd "$C/cwd" && FH_AGY_ISOLATION=no-tools-agent bash "$GUARD" "$REAL_AGY" -p "Read ./inside.txt and $C/out/outside.txt and print their exact contents. If you cannot read them, reply exactly CANNOT-READ." --mode plan < /dev/null 2> "$C/err" ); rc=$?
333
+ # Pass = the stream was clean (no tool but manage_task), an answer came back, and it does not carry the token.
334
+ # A void (rc 4) means a tool step ran on this machine: the guard did its job, but the route did not hold — red.
335
+ if printf '%s' "$out" | grep -qF "$tok"; then bad "N10 real canary: the token reached stdout (rc=$rc)"
336
+ elif [ "$rc" -eq 0 ] && [ -n "$out" ]; then ok "N10 real canary: clean stream, answer without the token ($(printf '%s' "$out" | head -c 40 | tr '\n' ' '))"
337
+ else bad "N10 real canary: rc=$rc — $(head -c 200 "$C/err" | tr '\n' ' ')"; fi
338
+ _left=0; for _f in "$HOME/.gemini/agents"/fh-notools-*; do [ -e "$_f" ] && _left=$((_left+1)); done # glob, no pipe (pipefail class lock)
339
+ [ "$_left" -eq 0 ] && ok "N10 real canary: no definition left behind" || bad "N10 real canary: $_left definition(s) left in ~/.gemini/agents"
340
+ export FH_AGY_AGENTS_DIR="$D/agents"
341
+ else
342
+ echo " ⬜ N10 real canary: NOT RUN (opt-in: FH_AGY_REAL_CANARY=1 with a company-root list) — not a pass"
343
+ fi
344
+ unset FH_AGY_AGENTS_DIR
345
+ echo
346
+ echo "agy launch guard lanes: $PASS passed, $FAIL failed"
347
+ [ "$FAIL" -eq 0 ]