@chrono-meta/fh-gate 3.20.1 → 3.22.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (36) hide show
  1. package/.claude-plugin/marketplace.json +4 -4
  2. package/CATALOG.md +5 -0
  3. package/CLAUDE.md +67 -283
  4. package/knowledge/shared/dialogue/claude_code_runtime_flow.md +1 -0
  5. package/knowledge/shared/harness-core/checkout_layer_drift.md +28 -0
  6. package/knowledge/shared/harness-core/claude_md_gate_details.md +343 -0
  7. package/knowledge/shared/harness-core/dispatch_conditional_prohibition.md +89 -0
  8. package/knowledge/shared/harness-core/fh_detail_protocols.md +88 -0
  9. package/knowledge/shared/harness-core/fh_three_layer_canon.md +49 -0
  10. package/knowledge/shared/harness-core/field_verdict_crossfamily_gate.md +29 -0
  11. package/knowledge/shared/harness-core/hook_channel_visibility.md +80 -0
  12. package/knowledge/shared/harness-core/measurement-integrity-checklist.md +9 -0
  13. package/knowledge/shared/learnings/subagent_invocations_log.yaml +39 -0
  14. package/knowledge/shared/rules/operations.md +7 -0
  15. package/package.json +8 -1
  16. package/plugins/fh-commons/.claude-plugin/plugin.json +1 -1
  17. package/plugins/fh-meta/.claude-plugin/plugin.json +1 -1
  18. package/plugins/fh-meta/CHANGELOG.md +36 -0
  19. package/plugins/fh-meta/skills/goal-quench/SKILL.md +1 -1
  20. package/plugins/fh-preprep/.claude-plugin/plugin.json +1 -1
  21. package/plugins/fh-qp/.claude-plugin/plugin.json +1 -1
  22. package/scripts/fh_node_check.sh +4 -1
  23. package/scripts/fh_session_load.sh +55 -0
  24. package/scripts/hook_drift_check.sh +188 -0
  25. package/scripts/selfcheck.sh +71 -0
  26. package/scripts/session_close_check.sh +44 -7
  27. package/scripts/session_config_fingerprint.sh +139 -0
  28. package/scripts/sidecar_calibrate.sh +168 -13
  29. package/scripts/test_claude_md_size_lanes.sh +74 -0
  30. package/scripts/test_fh_audit_check_lanes.sh +140 -0
  31. package/scripts/test_hook_drift_lanes.sh +143 -0
  32. package/scripts/test_ollama_panel_lanes.sh +69 -10
  33. package/scripts/test_session_config_fingerprint_lanes.sh +116 -0
  34. package/scripts/test_session_load_mirror_fp_lanes.sh +122 -0
  35. package/scripts/test_subagent_tally_hook_lanes.sh +11 -7
  36. package/templates/.claude/rules/mcp_tool_gating.md +17 -1
@@ -35,7 +35,7 @@ trap 'stop_stub' EXIT
35
35
  # The stub is written to a file so the heredoc cannot collide with the lane script's own quoting.
36
36
  STUB="$(mktemp -d)/stub.py"
37
37
  cat > "$STUB" <<'PY'
38
- import json, sys
38
+ import json, sys, time
39
39
  from http.server import BaseHTTPRequestHandler, HTTPServer
40
40
  PORT = int(sys.argv[1]); MODE = sys.argv[2]
41
41
 
@@ -46,8 +46,17 @@ class H(BaseHTTPRequestHandler):
46
46
  self.send_response(code); self.send_header("Content-Type", "application/json")
47
47
  self.send_header("Content-Length", str(len(b))); self.end_headers(); self.wfile.write(b)
48
48
  def do_GET(self):
49
- if self.path == "/api/version": self._send({"version": "stub"})
50
- elif self.path == "/api/tags": self._send({"models": [{"name": "stub-model:1b"}]})
49
+ if self.path == "/api/version":
50
+ if MODE == "notollama": self._send({"error": "not found"}, 404); return
51
+ if MODE == "fake200": # answers 200 to everything, but is not Ollama
52
+ b = b"<html>ok</html>"
53
+ self.send_response(200); self.send_header("Content-Type", "text/html")
54
+ self.send_header("Content-Length", str(len(b))); self.end_headers(); self.wfile.write(b); return
55
+ self._send({"version": "stub"})
56
+ elif self.path == "/api/tags":
57
+ if MODE == "tags500": self._send({"error": "listing failed"}, 500); return
58
+ if MODE == "tagsdrop": self.close_connection = True; return
59
+ self._send({"models": [{"name": "stub-model:1b"}]})
51
60
  else: self._send({}, 404)
52
61
  def do_POST(self):
53
62
  n = int(self.headers.get("Content-Length", 0))
@@ -57,8 +66,26 @@ class H(BaseHTTPRequestHandler):
57
66
  # BOGUS control. 'accept' mode is the dangerous server: it serves SOMETHING for a name
58
67
  # that cannot exist, so the pin is never validated at all.
59
68
  if MODE == "accept": self._send({"model": m, "response": "PASS"})
69
+ elif MODE == "ctl500": self._send({"error": "llama runner crashed"}, 500)
60
70
  else: self._send({"error": f"model '{m}' not found"})
61
71
  return
72
+ # Real Ollama refuses with a 4xx + {"error": ...}. The G1 incident (2026-09-24) was exactly
73
+ # these two bodies rendered as UNREACHABLE because `curl -sf` threw them away.
74
+ if MODE == "notfound":
75
+ self._send({"error": f"model '{m}' not found"}, 404); return
76
+ if MODE == "invalid":
77
+ self._send({"error": "invalid model name"}, 400); return
78
+ if MODE == "srv500":
79
+ self._send({"error": "llama runner process has terminated"}, 500); return
80
+ if MODE == "drop": # no HTTP answer at all -> curl http_code 000 (empty reply)
81
+ self.close_connection = True; return
82
+ if MODE == "fake200": # echoes the pin — would be PIN-OK if the host were trusted
83
+ self._send({"model": m, "response": "PASS"}); return
84
+ if MODE == "stall": # full-looking JSON, but Content-Length promises more; then hang
85
+ b = json.dumps({"model": m, "response": "PASS"}).encode()
86
+ self.send_response(200); self.send_header("Content-Type", "application/json")
87
+ self.send_header("Content-Length", str(len(b) + 64)); self.end_headers()
88
+ self.wfile.write(b); self.wfile.flush(); time.sleep(6); return
62
89
  if MODE == "substitute": # the agy failure, in this protocol
63
90
  self._send({"model": "some-other-model:9b", "response": "PASS"}); return
64
91
  if MODE == "starved": # reasoning model spent the whole budget thinking
@@ -74,24 +101,31 @@ start_stub() {
74
101
  python3 "$STUB" "$PORT" "$1" >/dev/null 2>&1 &
75
102
  SRV_PID=$!
76
103
  for _ in $(seq 1 40); do
77
- curl -sf --max-time 1 "http://127.0.0.1:$PORT/api/version" >/dev/null 2>&1 && return 0
104
+ # Ready = ANY HTTP answer, not a 2xx: the notollama mode answers /api/version with a 404 on
105
+ # purpose, and `-f` would read that as "stub never came up".
106
+ _c="$(curl -s -o /dev/null --max-time 1 -w '%{http_code}' "http://127.0.0.1:$PORT/api/version" 2>/dev/null)"
107
+ [ "${_c:-000}" != "000" ] && return 0
78
108
  sleep 0.25
79
109
  done
80
110
  return 1
81
111
  }
82
112
 
83
- # expect <label> <mode> <expect-in-panel: YES|NO> [needle]
113
+ # expect <label> <mode> <expect-in-panel: YES|NO> [needle] [forbid]
114
+ # forbid — a string that must NOT appear. A needle alone passes when the right label AND the wrong
115
+ # one are both printed; the G1 lanes need "MODEL-ERROR and NOT UNREACHABLE", not just the former.
116
+ # MODELS (env) overrides FH_OLLAMA_MODELS for the input-contract lanes; unset = the usual pin.
84
117
  expect() {
85
- local label="$1" mode="$2" want="$3" needle="${4:-}" out inpanel
118
+ local label="$1" mode="$2" want="$3" needle="${4:-}" forbid="${5:-}" out inpanel forbidden=0
86
119
  start_stub "$mode" || { printf ' ❌ %-44s stub failed to start\n' "$label"; fail=$((fail+1)); return; }
87
- out=$( FH_OLLAMA_HOST="http://127.0.0.1:$PORT" FH_OLLAMA_MODELS="stub-model:1b" \
88
- bash "$CAL" --only ollama --quiet 2>&1 )
120
+ out=$( FH_OLLAMA_HOST="http://127.0.0.1:$PORT" FH_OLLAMA_MODELS="${MODELS-stub-model:1b}" \
121
+ FH_OLLAMA_GEN_TIMEOUT="${GEN_TIMEOUT:-240}" bash "$CAL" --only ollama --quiet 2>&1 )
89
122
  stop_stub
90
123
  if printf '%s' "$out" | grep -q 'PANEL:.*ollama:stub-model:1b'; then inpanel=YES; else inpanel=NO; fi
91
- if [ "$inpanel" = "$want" ] && { [ -z "$needle" ] || printf '%s' "$out" | grep -q "$needle"; }; then
124
+ if [ -n "$forbid" ]; then case "$out" in *"$forbid"*) forbidden=1 ;; esac; fi
125
+ if [ "$inpanel" = "$want" ] && [ "$forbidden" -eq 0 ] && { [ -z "$needle" ] || printf '%s' "$out" | grep -q "$needle"; }; then
92
126
  printf ' ✅ %-44s in-panel=%s\n' "$label" "$inpanel"; pass=$((pass+1))
93
127
  else
94
- printf ' ❌ %-44s in-panel=%s (expected %s%s)\n' "$label" "$inpanel" "$want" "${needle:+, needle '$needle'}"
128
+ printf ' ❌ %-44s in-panel=%s (expected %s%s%s)\n' "$label" "$inpanel" "$want" "${needle:+, needle '$needle'}" "${forbid:+, forbid '$forbid'}"
95
129
  printf ' out: %s\n' "$(printf '%s' "$out" | head -4)"; fail=$((fail+1))
96
130
  fi
97
131
  }
@@ -103,6 +137,31 @@ expect "S3 empty answer (budget starvation)" starved NO "larger FH_OLLAM
103
137
  expect "S4 prose answer cannot carry a verdict" prose NO "VERDICT-UNPARSEABLE"
104
138
  expect "S5 server accepts a bogus model name" accept YES "accepts-bogus"
105
139
 
140
+ # ── G1 (2026-09-24): a server that ANSWERS with a refusal is not an unreachable server ─────────
141
+ # The known-positive for UNREACHABLE is S7 (no HTTP answer); the known-negatives are S8/S9 (a real
142
+ # 4xx body). Reverting `_http` to `curl -sf` turns S8/S9 red and leaves S7 green — the revert probe.
143
+ expect "S7 no HTTP answer (connection dropped)" drop NO "UNREACHABLE-THIS-RUN" "MODEL-ERROR"
144
+ expect "S8 404 model not found → MODEL-ERROR" notfound NO "MODEL-ERROR(model 'stub-model:1b' not found)" "UNREACHABLE"
145
+ expect "S9 400 invalid model name → MODEL-ERROR" invalid NO "MODEL-ERROR(invalid model name)" "UNREACHABLE"
146
+ expect "S10 500 from server → SERVER-ERROR" srv500 NO "SERVER-ERROR(http 500" "UNREACHABLE"
147
+ expect "S11 non-Ollama host → HOST-ERROR" notollama NO "HOST-ERROR" "ABSENT"
148
+ MODELS="" expect "S12 /api/tags 500 ≠ empty listing" tags500 NO "model list UNMEASURED" "no models listed"
149
+
150
+ # ── cross-family review 2026-09-26: four more places where a non-answer read as an answer ──────
151
+ expect "S15 any-200 host is not Ollama → HOST-ERROR" fake200 NO "not the Ollama shape" "PIN-OK"
152
+ expect "S16 control 5xx is not rejection" ctl500 YES "control: unmeasured" "rejects-bogus"
153
+ MODELS="" expect "S17 tags 000 does not claim REACHABLE" tagsdrop NO "model list UNMEASURED (tags call got no HTTP answer" "REACHABLE"
154
+ GEN_TIMEOUT=2 \
155
+ expect "S18 200 then mid-body stall → UNMEASURED" stall NO "UNMEASURED-THIS-RUN (http 200" "PIN-OK"
156
+ MODELS=" , " \
157
+ expect "S19 explicit-but-empty list → INPUT-ERROR" ok NO "no model names after trimming" "PIN-OK"
158
+
159
+ # ── FH_OLLAMA_MODELS contract: comma-separated. Inner whitespace is rejected, not guessed. ─────
160
+ MODELS="stub-model:1b other:2b" \
161
+ expect "S13 space-separated list → INPUT-ERROR" ok NO "did you mean: FH_OLLAMA_MODELS=\"stub-model:1b,other:2b\"" "UNREACHABLE"
162
+ MODELS=" stub-model:1b , " \
163
+ expect "S14 padding around commas is trimmed" ok YES "PIN-OK(envelope)" "INPUT-ERROR"
164
+
106
165
  # S6 — absence must be MEASURED, never assumed. No server at the host at all.
107
166
  out=$( FH_OLLAMA_HOST="http://127.0.0.1:$((PORT+7))" bash "$CAL" --only ollama --quiet 2>&1 )
108
167
  if printf '%s' "$out" | grep -q 'ABSENT — no server at the configured host'; then
@@ -0,0 +1,116 @@
1
+ #!/usr/bin/env bash
2
+ # test_session_config_fingerprint_lanes.sh — lanes for scripts/session_config_fingerprint.sh and
3
+ # its consumer ④-f of scripts/session_close_check.sh. Uses a scratch FH root and a scratch HOME
4
+ # only — the operator's real ~/.claude and this repo's gitignored files are never read or written.
5
+ #
6
+ # Defect pinned (2026-09-26): a sub-agent's measurement run overwrote this checkout's .claude/settings.json and
7
+ # CLAUDE.md mid-session and nothing noticed. Revert probe at the end: a mutant compare that only
8
+ # checks «file present» must go red on the one-file-changed fixture.
9
+ # Runs under bash 3.2 (/bin/bash) and bash 5.
10
+ set -uo pipefail
11
+ HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
12
+ ROOT="$(cd "$HERE/.." && pwd)"
13
+ SUBJ="$ROOT/scripts/session_config_fingerprint.sh"
14
+ CLOSE="$ROOT/scripts/session_close_check.sh"
15
+ T="$(mktemp -d 2>/dev/null || mktemp -d -t cfgfp)"
16
+ [ -n "$T" ] && [ -d "$T" ] || { echo "HARNESS-ERROR: mktemp failed"; exit 2; }
17
+ trap 'rm -rf "$T"' EXIT
18
+ pass=0; fail=0
19
+ chk() { if [ "$1" -eq 0 ]; then echo " ✅ $2"; pass=$((pass+1)); else echo " ❌ $2"; fail=$((fail+1)); fi; }
20
+ [ -f "$SUBJ" ] || { echo "HARNESS-ERROR: subject missing: $SUBJ"; exit 2; }
21
+
22
+ FHR="$T/fh"; HM="$T/home"
23
+ mkdir -p "$FHR/.claude" "$FHR/scripts" "$HM/.claude"
24
+ echo '{"a":1}' > "$FHR/.claude/settings.json"
25
+ echo 'local' > "$FHR/CLAUDE.local.md"
26
+ echo '# hub' > "$FHR/CLAUDE.md"
27
+ echo '{"h":1}' > "$HM/.claude/settings.json"
28
+ cp "$SUBJ" "$FHR/scripts/"
29
+ export CLAUDE_CODE_SESSION_ID="lane-session-1"
30
+ fp() { bash "$FHR/scripts/session_config_fingerprint.sh" "$@" --fh "$FHR" --home "$HM"; }
31
+ SNAP="$FHR/tracks/_meta/.session_config_fingerprint"
32
+
33
+ echo "── no snapshot ──"
34
+ out=$(fp compare 2>&1); rc=$?
35
+ [ "$rc" -eq 3 ]; chk $? "no snapshot → rc 3"
36
+ printf '%s\n' "$out" | grep -q 'NOT MEASURED'; chk $? "no snapshot → says NOT MEASURED (not «unchanged»)"
37
+
38
+ echo "── snapshot + unchanged ──"
39
+ fp snap >/dev/null 2>&1; [ -f "$SNAP" ]; chk $? "snap writes the snapshot under tracks/_meta"
40
+ grep -q '^session=lane-session-1$' "$SNAP"; chk $? "snapshot carries the session id"
41
+ [ "$(grep -c ' ' "$SNAP")" -eq 6 ]; chk $? "snapshot has one row per target (6)"
42
+ grep -q "$HM" "$SNAP"; [ $? -ne 0 ]; chk $? "snapshot rows carry labels, not the absolute home path"
43
+ out=$(fp compare 2>&1); rc=$?
44
+ [ "$rc" -eq 0 ]; chk $? "nothing changed → rc 0 (quiet)"
45
+ printf '%s\n' "$out" | grep -q '↳'; [ $? -ne 0 ]; chk $? "nothing changed → names no file"
46
+
47
+ echo "── one file changed ──"
48
+ echo '{"a":2}' > "$FHR/.claude/settings.json"
49
+ out=$(fp compare 2>&1); rc=$?
50
+ [ "$rc" -eq 1 ]; chk $? "one change → rc 1 (advisory)"
51
+ printf '%s\n' "$out" | grep -q 'repo:.claude/settings.json — content changed'; chk $? "names the changed file"
52
+ [ "$(printf '%s\n' "$out" | grep -c '↳')" -eq 1 ]; chk $? "names ONLY that file"
53
+ printf '%s\n' "$out" | grep -q '§Config-Overwrite-Recovery'; chk $? "points at the recovery procedure (repo doc, not memory)"
54
+ grep -q '^## 9. Config-Overwrite-Recovery' "$ROOT/knowledge/shared/harness-core/checkout_layer_drift.md"
55
+ chk $? "the pointed-at section exists"
56
+ echo '{"a":1}' > "$FHR/.claude/settings.json"
57
+
58
+ echo "── home file appears / clear keeps baseline ──"
59
+ echo 'x' > "$HM/.claude/CLAUDE.md"
60
+ out=$(fp compare 2>&1)
61
+ printf '%s\n' "$out" | grep -q 'home:~/.claude/CLAUDE.md — ABSENT → PRESENT'; chk $? "a home config file appearing is named"
62
+ fp snap --source clear >/dev/null 2>&1
63
+ out=$(fp compare 2>&1); rc=$?
64
+ [ "$rc" -eq 1 ]; chk $? "/clear in the same session keeps the baseline (evidence not erased)"
65
+ CLAUDE_CODE_SESSION_ID="lane-session-2" bash "$FHR/scripts/session_config_fingerprint.sh" snap --fh "$FHR" --home "$HM" --source clear >/dev/null 2>&1
66
+ grep -q '^session=lane-session-2$' "$SNAP"; chk $? "a NEW session re-snaps even on source=clear"
67
+ rm -f "$HM/.claude/CLAUDE.md"
68
+ export CLAUDE_CODE_SESSION_ID="lane-session-2"
69
+ fp snap >/dev/null 2>&1
70
+
71
+ echo "── touched, same bytes (cross-family 2026-09-26) ──"
72
+ cp "$FHR/CLAUDE.local.md" "$T/cl.bak"; touch -t 202001010000 "$FHR/CLAUDE.local.md"
73
+ out=$(fp compare 2>&1); rc=$?
74
+ [ "$rc" -eq 0 ] && printf '%s\n' "$out" | grep -q 'repo:CLAUDE.local.md — touched (내용 동일'
75
+ chk $? "mtime-only change → rc 0, reported separately as touched (not counted as a change)"
76
+ printf '%s\n' "$out" | grep -q 'content changed'; [ $? -ne 0 ]; chk $? " … and not reported as content changed"
77
+ fp snap >/dev/null 2>&1
78
+
79
+ echo "── unreadable is not unchanged ──"
80
+ if [ "$(id -u)" != 0 ]; then
81
+ chmod 000 "$FHR/CLAUDE.local.md"
82
+ out=$(fp compare 2>&1); rc=$?
83
+ chmod 644 "$FHR/CLAUDE.local.md"
84
+ [ "$rc" -eq 1 ] && printf '%s\n' "$out" | grep -q 'CLAUDE.local.md — unreadable'
85
+ chk $? "file turned unreadable → named as NOT MEASURED, not folded into «unchanged»"
86
+ else
87
+ echo " ⏭️ unreadable lane skipped (root) — not a pass"
88
+ fi
89
+
90
+ echo "── consumer ④-f ──"
91
+ cp "$CLOSE" "$FHR/scripts/session_close_check.sh"
92
+ echo '# hub changed' > "$FHR/CLAUDE.md"
93
+ out=$(bash "$FHR/scripts/session_close_check.sh" "$FHR" 2>&1)
94
+ printf '%s\n' "$out" | grep -q '^④-f .*repo:CLAUDE.md — content changed'; chk $? "close check ④-f names the overwritten CLAUDE.md"
95
+ echo '# hub' > "$FHR/CLAUDE.md"
96
+ rm -f "$SNAP"
97
+ out=$(bash "$FHR/scripts/session_close_check.sh" "$FHR" 2>&1)
98
+ printf '%s\n' "$out" | grep -q '^④-f .*NOT MEASURED'; chk $? "close check ④-f with no snapshot → NOT MEASURED"
99
+ mkdir -p "$T/stubroot/scripts"; cp "$CLOSE" "$T/stubroot/scripts/session_close_check.sh"
100
+ printf '#!/bin/sh\necho stub-output\nexit 7\n' > "$T/stubroot/scripts/session_config_fingerprint.sh"
101
+ out=$(bash "$T/stubroot/scripts/session_close_check.sh" "$T/stubroot" 2>&1)
102
+ printf '%s\n' "$out" | grep -q '④-f .*checker exited 7'; chk $? "④-f keeps the checker's rc (exit 7 → instrument error named, not hidden by the sed decoration)"
103
+ wired=$(grep -c 'session_config_fingerprint.sh" snap' "$ROOT/scripts/fh_session_load.sh")
104
+ [ "$wired" -ge 1 ]; chk $? "snap is wired into fh_session_load.sh (SessionStart)"
105
+
106
+ echo "── revert probe: compare that only checks presence ──"
107
+ sed 's/elif \[ "\$hash" != "\$old_hash" \]; then/elif false; then # MUTANT-NO-HASH/' "$SUBJ" > "$T/mutant.sh"
108
+ grep -q 'MUTANT-NO-HASH' "$T/mutant.sh"; chk $? "mutation applied (control for the probe itself)"
109
+ fp snap >/dev/null 2>&1
110
+ echo '{"a":9}' > "$FHR/.claude/settings.json"
111
+ bash "$T/mutant.sh" compare --fh "$FHR" --home "$HM" >/dev/null 2>&1; mrc=$?
112
+ [ "$mrc" -eq 0 ]; chk $? "mutant reports «unchanged» on the one-file-changed fixture → the «names the changed file» lane would be RED"
113
+
114
+ echo
115
+ if [ "$fail" -eq 0 ]; then echo "CONFIG-FINGERPRINT LANES: PASS ($pass/$pass)"; exit 0; fi
116
+ echo "CONFIG-FINGERPRINT LANES: FAIL ($fail failed, $pass passed)"; exit 1
@@ -0,0 +1,122 @@
1
+ #!/usr/bin/env bash
2
+ # test_session_load_mirror_fp_lanes.sh — lanes for fh_session_load.sh §3 «NEWER THAN SESSION CARD».
3
+ #
4
+ # Defect (measured 2026-09-26): sync-to-be.sh rewrites every tracks/_meta mirror it touches, so a
5
+ # mirror's mtime is «when the sync ran», not «when its content was new». Two result files the card
6
+ # had already absorbed were listed under «READ THESE BEFORE ACTING». The fix demotes a $TM mirror
7
+ # whose line 1 is EXACTLY the sync banner, whose remaining bytes equal the hub canonical copy, AND
8
+ # whose content the companion git committed at/before the card (clean tree).
9
+ #
10
+ # The lanes are a known pair plus the fail-open guards: the FP (L1) must stay quiet, and every
11
+ # case that is NOT provably old-and-identical (L2–L6, L8–L11) must still be listed. L0 is the instrument
12
+ # control — the hook actually reached the freshness block — so a script that dies early cannot
13
+ # pass L1 by printing nothing.
14
+ set -uo pipefail
15
+ HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
16
+ SUBJECT="$HERE/fh_session_load.sh"
17
+ [ -f "$SUBJECT" ] || { echo "HARNESS-ERROR subject missing: $SUBJECT"; exit 2; }
18
+
19
+ T="$(mktemp -d "${TMPDIR:-/tmp}/fhsl_mirror.XXXXXX")" || { echo "HARNESS-ERROR mktemp"; exit 2; }
20
+ trap 'rm -rf "$T"' EXIT
21
+ HUB="$T/hub"; BE="$T/be"
22
+ mkdir -p "$HUB/tracks/_meta/sub" "$BE/tracks-meta/sub" "$BE/handoff"
23
+ git -C "$BE" init -q 2>/dev/null || { echo "HARNESS-ERROR git init"; exit 2; }
24
+
25
+ BANNER='<!-- MIRROR COPY — synced from the forge-harness hub. Do NOT edit here; the next sync overwrites it. Edit the canonical file under the hub instead. -->'
26
+ mirror() { { printf '%s\n' "$BANNER"; cat "$1"; } > "$2"; } # $1 = hub file, $2 = mirror path
27
+
28
+ echo card > "$HUB/tracks/_meta/reference_next_session_starter.md"
29
+ touch -t 202601010000 "$HUB/tracks/_meta/reference_next_session_starter.md" # card = old
30
+
31
+ # L1 FP: identical mirror, restamped by sync (mtime newer than card)
32
+ printf 'result body\nline2\n' > "$HUB/tracks/_meta/same.md"
33
+ mirror "$HUB/tracks/_meta/same.md" "$BE/tracks-meta/same.md"
34
+ printf 'nested\n' > "$HUB/tracks/_meta/sub/nested_same.md"
35
+ mirror "$HUB/tracks/_meta/sub/nested_same.md" "$BE/tracks-meta/sub/nested_same.md"
36
+ # L2 known-positive: genuine non-mirror file, newer
37
+ printf 'genuinely new\n' > "$BE/tracks-meta/genuine.md"
38
+ # L3 mirror whose content differs from the hub copy
39
+ printf 'hub version\n' > "$HUB/tracks/_meta/differs.md"
40
+ { printf '%s\n' "$BANNER"; printf 'remote version\n'; } > "$BE/tracks-meta/differs.md"
41
+ # L4 mirror whose hub canonical is absent (arrived from another machine)
42
+ { printf '%s\n' "$BANNER"; printf 'only remote\n'; } > "$BE/tracks-meta/nohub.md"
43
+ # L5 line 1 merely MENTIONS the phrase — not the exact banner; rest identical to a hub file
44
+ printf 'body\n' > "$HUB/tracks/_meta/lookalike.md"
45
+ { printf 'notes on MIRROR COPY handling\n'; cat "$HUB/tracks/_meta/lookalike.md"; } > "$BE/tracks-meta/lookalike.md"
46
+ # L6 outside $TM: a bannered identical file under handoff/ is NOT demoted
47
+ printf 'handoff body\n' > "$HUB/tracks/_meta/ho.md"
48
+ mirror "$HUB/tracks/_meta/ho.md" "$BE/handoff/ho.md"
49
+ # L7 identical mirror OLDER than the card: neither listed nor noted
50
+ printf 'old\n' > "$HUB/tracks/_meta/old_same.md"
51
+ mirror "$HUB/tracks/_meta/old_same.md" "$BE/tracks-meta/old_same.md"
52
+ touch -t 202512010000 "$BE/tracks-meta/old_same.md"
53
+
54
+ # L8 cross-family [high]: identical mirror, but first committed AFTER the card (written today)
55
+ printf 'todays result\n' > "$HUB/tracks/_meta/new_today.md"
56
+ mirror "$HUB/tracks/_meta/new_today.md" "$BE/tracks-meta/new_today.md"
57
+ # L9 identical mirror whose committed version is OLD but the tree is dirty (new content, unsynced commit)
58
+ printf 'v1\n' > "$HUB/tracks/_meta/dirty.md"; mirror "$HUB/tracks/_meta/dirty.md" "$BE/tracks-meta/dirty.md"
59
+ # L10 identical mirror never committed (untracked)
60
+ printf 'untracked\n' > "$HUB/tracks/_meta/untracked.md"
61
+
62
+ G() { git -C "$BE" -c user.name=t -c user.email=t@t "$@"; }
63
+ OLD='2025-12-15T00:00:00' # before the card (2026-01-01)
64
+ G add tracks-meta/same.md tracks-meta/sub/nested_same.md tracks-meta/old_same.md tracks-meta/dirty.md \
65
+ tracks-meta/genuine.md tracks-meta/differs.md tracks-meta/nohub.md tracks-meta/lookalike.md handoff/ho.md >/dev/null
66
+ GIT_AUTHOR_DATE="$OLD" GIT_COMMITTER_DATE="$OLD" G commit -qm old >/dev/null || { echo "HARNESS-ERROR commit old"; exit 2; }
67
+ G add tracks-meta/new_today.md >/dev/null; G commit -qm today >/dev/null || { echo "HARNESS-ERROR commit today"; exit 2; }
68
+ printf 'v2\n' > "$HUB/tracks/_meta/dirty.md"; mirror "$HUB/tracks/_meta/dirty.md" "$BE/tracks-meta/dirty.md"
69
+ mirror "$HUB/tracks/_meta/untracked.md" "$BE/tracks-meta/untracked.md"
70
+ touch "$BE/tracks-meta/same.md" "$BE/tracks-meta/sub/nested_same.md" # the sync restamp
71
+ touch -t 202512010000 "$BE/tracks-meta/old_same.md" # re-assert L7 (older than card)
72
+
73
+ OUT="$(printf '{"source":"startup"}' | HUB_DIR="$HUB" BE_DIR="$BE" bash "$SUBJECT" 2>&1)"
74
+ # The NEWER list = the « - » lines right after the header.
75
+ LIST="$(printf '%s\n' "$OUT" | awk '/NEWER THAN SESSION CARD/{on=1;next} on&&/^ - /{print;next} on{exit}')"
76
+ NOTE="$(printf '%s\n' "$OUT" | /usr/bin/grep -A1 'mirror cop(y/ies) newer than the card' || true)"
77
+
78
+ pass=0; fail=0
79
+ ok() { echo "PASS $1"; pass=$((pass+1)); }
80
+ bad() { echo "FAIL $1"; fail=$((fail+1)); }
81
+ # Substring tests use `case`, not `printf | grep -q`: under pipefail an early-exiting grep can
82
+ # SIGPIPE the printf and flip the verdict (pipefail class-lock lane L12c).
83
+ has() { case "$1" in *"$2"*) return 0 ;; esac; return 1; }
84
+ listed() { has "$LIST" "- $1"; }
85
+
86
+ has "$OUT" 'NEWER THAN SESSION CARD' \
87
+ && ok "L0 control — hook reached the NEWER block" \
88
+ || { bad "L0 control — NEWER block never printed (instrument dead)"; printf '%s\n' "$OUT" | tail -15; }
89
+
90
+ listed "tracks-meta/same.md" && bad "L1 FP — identical mirror listed as NEWER" || ok "L1 FP — identical mirror not listed"
91
+ listed "tracks-meta/sub/nested_same.md" && bad "L1b FP — nested identical mirror listed" || ok "L1b FP — nested identical mirror not listed"
92
+ has "$NOTE" 'same.md' && has "$NOTE" ' ⓘ 2 ' \
93
+ && ok "L1c demoted mirrors are NAMED in the note (not silently dropped), count=2" \
94
+ || bad "L1c demoted mirrors missing from the note: [$NOTE]"
95
+ listed "tracks-meta/genuine.md" && ok "L2 known-positive — genuine newer file listed" || bad "L2 genuine newer file NOT listed (fail-open)"
96
+ listed "tracks-meta/differs.md" && ok "L3 differing mirror listed" || bad "L3 differing mirror NOT listed (fail-open)"
97
+ listed "tracks-meta/nohub.md" && ok "L4 mirror with no hub copy listed" || bad "L4 mirror with no hub copy NOT listed (fail-open)"
98
+ listed "tracks-meta/lookalike.md" && ok "L5 non-exact banner listed" || bad "L5 non-exact banner NOT listed (substring match = fail-open)"
99
+ listed "handoff/ho.md" && ok "L6 bannered file outside \$TM listed" || bad "L6 outside-\$TM file demoted"
100
+ { listed "tracks-meta/old_same.md" || has "$NOTE" 'old_same'; } \
101
+ && bad "L7 older-than-card mirror surfaced" || ok "L7 older-than-card mirror stays quiet"
102
+
103
+ listed "tracks-meta/new_today.md" && ok "L8 identical mirror committed AFTER the card listed" || bad "L8 today's identical mirror hidden (fail-open — cross-family [high])"
104
+ listed "tracks-meta/dirty.md" && ok "L9 identical-but-dirty mirror listed" || bad "L9 dirty mirror hidden (fail-open)"
105
+ listed "tracks-meta/untracked.md" && ok "L10 identical-but-untracked mirror listed" || bad "L10 untracked mirror hidden (fail-open)"
106
+
107
+ # L11 git unavailable → demotion OFF (mirror listed) AND the output says so — never silently.
108
+ NOGIT="$T/nogit"; mkdir -p "$NOGIT"
109
+ for x in /bin/* /usr/bin/*; do
110
+ b="${x##*/}"; [ "$b" = git ] && continue; [ -e "$NOGIT/$b" ] || ln -s "$x" "$NOGIT/$b" 2>/dev/null
111
+ done
112
+ OUT2="$(printf '{"source":"startup"}' | PATH="$NOGIT" HUB_DIR="$HUB" BE_DIR="$BE" /bin/bash "$SUBJECT" 2>&1)"
113
+ LIST2="$(printf '%s\n' "$OUT2" | awk '/NEWER THAN SESSION CARD/{on=1;next} on&&/^ - /{print;next} on{exit}')"
114
+ if has "$LIST2" "- tracks-meta/same.md" \
115
+ && has "$OUT2" 'git unavailable — mirror-copy demotion is OFF'; then
116
+ ok "L11 git unavailable → mirror listed + stated"
117
+ else
118
+ bad "L11 git unavailable → silent or demoted"; printf '%s\n' "$OUT2" | tail -8
119
+ fi
120
+
121
+ echo "── mirror-FP lanes: pass=$pass fail=$fail"
122
+ [ "$fail" -eq 0 ]
@@ -63,27 +63,31 @@ old() { printf '%s\n' "$(date +%Y-%m-%d)" >> "$1"; }
63
63
  f="$T/old"; printf '%s' "$P_INTERNAL" | old "$f"
64
64
  [ "$(grep -c "^$TODAY$" "$f")" = 1 ] ; chk $? "control alive: date-only append DOES count compaction — the defect this lane exists for"
65
65
 
66
+ # 🟥 millisecond timer — whole-second `date +%s` rounds a 3.2 s run up to 4 or 5 across a second boundary,
67
+ # and under full-selfcheck load that alone turned the deadline lane red (2026-09-26, 607/608). perl is on
68
+ # every macOS/Linux runner this repo supports; missing perl → 99999 (loud red, never a silent pass).
69
+ now_ms() { perl -MTime::HiRes=time -e 'printf "%d", time*1000' 2>/dev/null || echo 0; }
66
70
  echo "── stdin never closed (the caller keeps the pipe open) → still counts, within the limit"
67
71
  f="$T/open"
68
72
  # 🟥 time the HOOK only — timing the whole pipeline also waits for the producer's `sleep`.
69
- ( sleep 5 ) | { s0=$(date +%s); FH_TALLY_FILE="$f" bash "$SUBJ"; echo $(( $(date +%s) - s0 )) > "$f.dur"; }
70
- dur=$(cat "$f.dur" 2>/dev/null || echo 99)
73
+ ( sleep 5 ) | { s0=$(now_ms); FH_TALLY_FILE="$f" bash "$SUBJ"; s1=$(now_ms); [ "$s0" -gt 0 ] && [ "$s1" -gt 0 ] && echo $(( s1 - s0 )) > "$f.dur" || echo 99999 > "$f.dur"; }
74
+ dur=$(cat "$f.dur" 2>/dev/null || echo 99999)
71
75
  [ "$(grep -c "^$TODAY$" "$f" 2>/dev/null || echo 0)" = 1 ] ; chk $? "open, silent stdin → counted (a bare \`cat\` blocked here until the hook was killed)"
72
- [ "$dur" -le 4 ] ; chk $? "and the hook returned by its read limit, not at the caller's EOF (${dur}s)"
76
+ [ "$dur" -le 4000 ] ; chk $? "and the hook returned by its read limit, not at the caller's EOF (${dur} ms)"
73
77
  f="$T/open2"; ( printf '%s' "$P_INTERNAL"; sleep 5 ) | FH_TALLY_FILE="$f" bash "$SUBJ"
74
78
  [ "$(grep -c "^$TODAY$" "$f" 2>/dev/null || echo 0)" = 0 ] ; chk $? "payload delivered but pipe left open → still classified (internal skipped)"
75
79
 
76
80
  f="$T/nul"; printf '%s\0 ' "$P_INTERNAL" | FH_TALLY_FILE="$f" bash "$SUBJ"
77
81
  [ "$(grep -c "^$TODAY$" "$f" 2>/dev/null || echo 0)" = 1 ] ; chk $? "raw NUL after an internal payload → counted (OUTCOME lane: json rejects NUL — the bash reader that turned it into whitespace is gone; codex 2026-09-25)"
78
- f="$T/big"; { printf '{"agent_type":"","pad":"'; head -c 9000000 /dev/zero | tr '\0' x; printf '"}'; } | { s0=$(date +%s); FH_TALLY_FILE="$f" bash "$SUBJ"; echo $(( $(date +%s) - s0 )) > "$f.dur"; }; e=$(cat "$f.dur" 2>/dev/null || echo 99)
82
+ f="$T/big"; { printf '{"agent_type":"","pad":"'; head -c 9000000 /dev/zero | tr '\0' x; printf '"}'; } | { s0=$(now_ms); FH_TALLY_FILE="$f" bash "$SUBJ"; s1=$(now_ms); [ "$s0" -gt 0 ] && [ "$s1" -gt 0 ] && echo $(( s1 - s0 )) > "$f.dur" || echo 99999 > "$f.dur"; }; e=$(cat "$f.dur" 2>/dev/null || echo 99999)
79
83
  [ "$(grep -c "^$TODAY$" "$f" 2>/dev/null || echo 0)" = 1 ] ; chk $? "payload over the 8 MiB cap → truncated → DOUBT → counted"
80
- [ "$e" -le 8 ] ; chk $? "and the cap bounds the read time (${e}s)"
84
+ [ "$e" -le 8000 ] ; chk $? "and the cap bounds the read time (${e} ms)"
81
85
 
82
86
  # 🟥 time the HOOK only (see the «stdin never closed» lane above) — CI runners ignore SIGPIPE, so the
83
87
  # producer keeps sleeping after the hook exits and a whole-pipeline timer read 8 s there (4 s on macOS).
84
- f="$T/trickle"; ( for i in 1 2 3 4 5 6 7 8; do printf ' '; sleep 1; done; printf '%s' "$P_INTERNAL" ) | { s0=$(date +%s); FH_TALLY_FILE="$f" bash "$SUBJ"; echo $(( $(date +%s) - s0 )) > "$f.dur"; }; e=$(cat "$f.dur" 2>/dev/null || echo 99)
88
+ f="$T/trickle"; ( for i in 1 2 3 4 5 6 7 8; do printf ' '; sleep 1; done; printf '%s' "$P_INTERNAL" ) | { s0=$(now_ms); FH_TALLY_FILE="$f" bash "$SUBJ"; s1=$(now_ms); [ "$s0" -gt 0 ] && [ "$s1" -gt 0 ] && echo $(( s1 - s0 )) > "$f.dur" || echo 99999 > "$f.dur"; }; e=$(cat "$f.dur" 2>/dev/null || echo 99999)
85
89
  [ "$(grep -c "^$TODAY$" "$f" 2>/dev/null || echo 0)" = 1 ] ; chk $? "slow trickle (1 byte/s, never idle 2 s) → deadline cuts it → counted"
86
- [ "$e" -le 4 ] ; chk $? "and the deadline lands inside the settings.json hook timeout (5 s) with margin (${e}s — a 5 s deadline raced the kill, which lands BEFORE the append)"
90
+ [ "$e" -le 4500 ] ; chk $? "and the deadline lands inside the settings.json hook timeout (5 s) with margin (${e} ms — a 5 s deadline raced the kill, which lands BEFORE the append)"
87
91
 
88
92
  echo "── wiring: EXECUTE the shipped template command (a grep for the path matched the _readme text)"
89
93
  TPL="$SCRIPT_DIR/../templates/subagent-tally-hook.json"
@@ -112,6 +112,17 @@ Unlisted tool name → **ask** (fail-closed), then add it to the table. Listed-b
112
112
  is the same case: a name in the table earns its allow tier from confirmed behavior (§1),
113
113
  not from sounding harmless.
114
114
 
115
+ > ⚠️ **"ask" stops a call only if nothing answers the prompt for you** (measured 2026-09-25,
116
+ > Claude Code 2.1.282, interactive): a `PreToolUse` hook returning **ask** was *swallowed* when a
117
+ > `PermissionRequest` hook answered **allow** — the call ran **5/5** (auto mode 3 · acceptEdits 2).
118
+ > A hook returning **deny** stopped it **0/2** landed. Headless runs went the other way (the
119
+ > `PermissionRequest` hook was not called after ask), so the result is surface-specific. So under
120
+ > any auto-approver (a `PermissionRequest` allow hook, a desktop approval app, a wrapper that
121
+ > clicks "yes"), an ask-tier call is **not** fail-closed — only **deny / exit 2** stops it. Not
122
+ > measured: auto mode *without* such a hook (one run, did not land — below bar), and whether a
123
+ > `permissions.ask` **rule** (step 4 below) is swallowed the same way. Detail:
124
+ > `knowledge/shared/harness-core/hook_channel_visibility.md`.
125
+
115
126
  ## 3. Per-server table ([CUSTOMIZE] — fill at mount time)
116
127
 
117
128
  | Server | Tool name | Tier | Note |
@@ -127,7 +138,10 @@ not from sounding harmless.
127
138
  3. Anything that writes outside the repo, or grants/answers an approval → ask.
128
139
  4. Where supported, mirror the ask-tier into the platform's permission config
129
140
  (e.g. Claude Code `permissions.ask` entries for `mcp__{server}__{tool}`) so the
130
- gate is mechanical, not prose-only. This rule file is the fallback for hosts
141
+ gate is mechanical, not prose-only. ⚠️ Mechanical against a human at the prompt — whether an
142
+ auto-approver answers a `permissions.ask` rule the way it answered a hook's ask (§2 note)
143
+ is **unmeasured**; where one is installed, use a `permissions.deny` entry for calls that
144
+ must never run unattended. This rule file is the fallback for hosts
131
145
  without per-tool permission config.
132
146
  5. For `http`/`sse`-transport servers, record the resolved endpoint address at mount
133
147
  (host + path) in the §3 table's Note column. This checklist gates tool *behavior*
@@ -151,6 +165,8 @@ Done When (per mounted server):
151
165
  - §3 table filled, every enumerated tool name present (check class: mandatory-pass — file inspection)
152
166
  - ask-tier tools wired to a per-call approval surface: host per-tool permission entry exists,
153
167
  or this rule file is installed and loaded in the session (check class: mandatory-pass)
168
+ — and if the session runs under an auto-approver, the surface is a **deny** entry, not ask
169
+ (§2 note; check class: mandatory-pass — grep the settings for a `PermissionRequest` hook)
154
170
  - non-ask tiers assigned only with a behavior-confirmation note in the §3 Note column
155
171
  (check class: judged — pair with an adversarial pass asking "could this name mislead?")
156
172
  - for `http`/`sse`-transport servers, the mounted endpoint address is recorded in §3