@chrono-meta/fh-gate 3.20.0 → 3.21.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.
- package/.claude-plugin/marketplace.json +4 -4
- package/CATALOG.md +5 -0
- package/CLAUDE.md +4 -1
- package/knowledge/shared/dialogue/claude_code_runtime_flow.md +1 -0
- package/knowledge/shared/harness-core/checkout_layer_drift.md +17 -0
- package/knowledge/shared/harness-core/hook_channel_visibility.md +80 -0
- package/knowledge/shared/harness-core/measurement-integrity-checklist.md +9 -0
- package/knowledge/shared/learnings/subagent_invocations_log.yaml +41 -0
- package/knowledge/shared/rules/operations.md +7 -0
- package/package.json +7 -1
- package/plugins/fh-commons/.claude-plugin/plugin.json +1 -1
- package/plugins/fh-meta/.claude-plugin/plugin.json +1 -1
- package/plugins/fh-meta/CHANGELOG.md +30 -0
- package/plugins/fh-meta/skills/goal-quench/SKILL.md +1 -1
- package/plugins/fh-preprep/.claude-plugin/plugin.json +1 -1
- package/plugins/fh-qp/.claude-plugin/plugin.json +1 -1
- package/scripts/fh_node_check.sh +4 -1
- package/scripts/fh_session_load.sh +9 -0
- package/scripts/hook_drift_check.sh +188 -0
- package/scripts/selfcheck.sh +41 -0
- package/scripts/session_close_check.sh +44 -7
- package/scripts/session_config_fingerprint.sh +139 -0
- package/scripts/subagent_tally_hook.sh +95 -0
- package/scripts/test_hook_drift_lanes.sh +143 -0
- package/scripts/test_session_config_fingerprint_lanes.sh +116 -0
- package/scripts/test_subagent_tally_hook_lanes.sh +109 -0
- package/templates/.claude/rules/mcp_tool_gating.md +17 -1
- package/templates/subagent-tally-hook.json +2 -2
package/scripts/selfcheck.sh
CHANGED
|
@@ -2225,6 +2225,47 @@ if [ -f scripts/test_dispatch_log_lanes.sh ]; then
|
|
|
2225
2225
|
fail=1
|
|
2226
2226
|
fi
|
|
2227
2227
|
fi
|
|
2228
|
+
# ④-e's «hook installed» verdict + the checker behind it (2026-09-26): a PRESENT-but-STALE tally
|
|
2229
|
+
# hook (the pre-2026-09-25 inline form) used to pass as measured. Revert probe inside the lane.
|
|
2230
|
+
if [ ! -f scripts/hook_drift_check.sh ]; then
|
|
2231
|
+
_absent_subject_verdict "hook-drift lanes" "scripts/hook_drift_check.sh" || fail=1
|
|
2232
|
+
elif [ -f scripts/test_hook_drift_lanes.sh ]; then
|
|
2233
|
+
if _out=$(bash scripts/test_hook_drift_lanes.sh 2>&1); then
|
|
2234
|
+
echo "PASS test_hook_drift_lanes.sh (CURRENT/STALE/ABSENT/UNKNOWN + ④-e consumer + revert probe)"
|
|
2235
|
+
else
|
|
2236
|
+
echo "FAIL test_hook_drift_lanes.sh: installed-hook drift would be misjudged"
|
|
2237
|
+
_show_failure "$_out"
|
|
2238
|
+
fail=1
|
|
2239
|
+
fi
|
|
2240
|
+
else
|
|
2241
|
+
echo "FAIL hook-drift lanes: hook_drift_check.sh present but its anchor is missing"; fail=1
|
|
2242
|
+
fi
|
|
2243
|
+
# ④-f session config fingerprint (2026-09-26): a mid-session overwrite of settings/CLAUDE.md went
|
|
2244
|
+
# unnoticed on 2026-09-25. Advisory at close; the lane pins «no snapshot = NOT MEASURED».
|
|
2245
|
+
if [ ! -f scripts/session_config_fingerprint.sh ]; then
|
|
2246
|
+
_absent_subject_verdict "config-fingerprint lanes" "scripts/session_config_fingerprint.sh" || fail=1
|
|
2247
|
+
elif [ -f scripts/test_session_config_fingerprint_lanes.sh ]; then
|
|
2248
|
+
if _out=$(bash scripts/test_session_config_fingerprint_lanes.sh 2>&1); then
|
|
2249
|
+
echo "PASS test_session_config_fingerprint_lanes.sh (snap/compare + ④-f consumer + revert probe)"
|
|
2250
|
+
else
|
|
2251
|
+
echo "FAIL test_session_config_fingerprint_lanes.sh: a config overwrite would go unnamed"
|
|
2252
|
+
_show_failure "$_out"
|
|
2253
|
+
fail=1
|
|
2254
|
+
fi
|
|
2255
|
+
else
|
|
2256
|
+
echo "FAIL config-fingerprint lanes: session_config_fingerprint.sh present but its anchor is missing"; fail=1
|
|
2257
|
+
fi
|
|
2258
|
+
# The tally hook's BODY (2026-09-25): SubagentStop also fires for Claude Code's internal agents
|
|
2259
|
+
# (compaction → agent_type ""), and the date-only inline hook counted them as dispatches.
|
|
2260
|
+
if [ -f scripts/test_subagent_tally_hook_lanes.sh ]; then
|
|
2261
|
+
if _out=$(bash scripts/test_subagent_tally_hook_lanes.sh 2>&1); then
|
|
2262
|
+
echo "PASS test_subagent_tally_hook_lanes.sh (internal-agent skip + count-on-doubt lanes)"
|
|
2263
|
+
else
|
|
2264
|
+
echo "FAIL test_subagent_tally_hook_lanes.sh: the dispatch tally would mis-count"
|
|
2265
|
+
_show_failure "$_out"
|
|
2266
|
+
fail=1
|
|
2267
|
+
fi
|
|
2268
|
+
fi
|
|
2228
2269
|
|
|
2229
2270
|
# selfcheck's own subject-presence discriminators. Every other guard under scripts/ has a lane suite;
|
|
2230
2271
|
# this decision had none, and it shipped two mis-routings in one session — a two-arm form that fell
|
|
@@ -470,15 +470,34 @@ fi
|
|
|
470
470
|
# from. Installable snippet: templates/subagent-tally-hook.json.
|
|
471
471
|
TALLY="$FH/tracks/_meta/.subagent_dispatch_tally"
|
|
472
472
|
LOG="$FH/knowledge/shared/learnings/subagent_invocations_log.yaml"
|
|
473
|
+
# 🟥 2026-09-26 — «installed» means CURRENT, not PRESENT. The old test was
|
|
474
|
+
# `grep -q '"SubagentStop"'`, which also passed an install still carrying the pre-2026-09-25
|
|
475
|
+
# INLINE hook (date-only append, counts Claude Code's internal agents as dispatches). The template
|
|
476
|
+
# itself says «RE-MERGE», and nothing compared the gitignored installed copy against it. So the
|
|
477
|
+
# verdict now comes from hook_drift_check.sh: CURRENT → measured · STALE → old hook, re-merge ·
|
|
478
|
+
# ABSENT → none · UNKNOWN (read failure / checker missing) → NOT MEASURED, never folded into OK.
|
|
479
|
+
# Lane: scripts/test_hook_drift_lanes.sh (incl. a revert probe back to the presence grep).
|
|
473
480
|
HOOK_OK=0
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
echo " (that file is gitignored, so a fresh clone has none). An unmeasured dispatch count is"
|
|
480
|
-
echo " NOT a count of zero. Install: templates/subagent-tally-hook.json → .claude/settings.json"
|
|
481
|
+
HOOK_STATE=UNKNOWN
|
|
482
|
+
if [ -f "$FH/scripts/hook_drift_check.sh" ]; then
|
|
483
|
+
HOOK_STATE=$(bash "$FH/scripts/hook_drift_check.sh" --settings "$FH/.claude/settings.json" \
|
|
484
|
+
--templates "$FH/templates" --only subagent_tally_hook.sh --verdict 2>/dev/null)
|
|
485
|
+
case "$HOOK_STATE" in (CURRENT|STALE|ABSENT|UNKNOWN) ;; (*) HOOK_STATE=UNKNOWN ;; esac
|
|
481
486
|
fi
|
|
487
|
+
[ "$HOOK_STATE" = CURRENT ] && HOOK_OK=1
|
|
488
|
+
case "$HOOK_STATE" in
|
|
489
|
+
(STALE)
|
|
490
|
+
echo "⚠️ ④-e dispatch log NOT MEASURED — 옛 훅: the SubagentStop tally hook in .claude/settings.json"
|
|
491
|
+
echo " differs from templates/subagent-tally-hook.json (re-merge needed — an old inline hook"
|
|
492
|
+
echo " counts internal agents as dispatches). Re-merge that block, then re-run." ;;
|
|
493
|
+
(ABSENT)
|
|
494
|
+
echo "⚠️ ④-e dispatch log NOT MEASURED — no SubagentStop tally hook in .claude/settings.json"
|
|
495
|
+
echo " (that file is gitignored, so a fresh clone has none). An unmeasured dispatch count is"
|
|
496
|
+
echo " NOT a count of zero. Install: templates/subagent-tally-hook.json → .claude/settings.json" ;;
|
|
497
|
+
(UNKNOWN)
|
|
498
|
+
echo "⚠️ ④-e dispatch log NOT MEASURED — could not determine whether the tally hook is current"
|
|
499
|
+
echo " (settings unreadable, or scripts/hook_drift_check.sh missing). Not a pass." ;;
|
|
500
|
+
esac
|
|
482
501
|
# `grep -c` PRINTS 0 and EXITS 1 when the count is zero. Under `set -o pipefail` (line 16) that
|
|
483
502
|
# makes the pipeline fail, `|| echo 0` appends a SECOND line, and the value becomes "0\n0" — which
|
|
484
503
|
# `[ -eq ]` rejects as a bash error, so the branch it guards is skipped. The guard was therefore
|
|
@@ -549,6 +568,24 @@ elif [ "$HOOK_OK" -eq 1 ]; then
|
|
|
549
568
|
echo "✅ ④-e dispatch log: no sub-agent dispatches tallied today"
|
|
550
569
|
fi
|
|
551
570
|
|
|
571
|
+
# ④-f CONFIG FINGERPRINT (advisory, never blocks) — 2026-09-26.
|
|
572
|
+
# A sub-agent's measurement run overwrote this checkout's .claude/settings.json and CLAUDE.md on 2026-09-26 and
|
|
573
|
+
# nothing noticed: settings is gitignored (no status line, no undo). fh_session_load.sh snaps
|
|
574
|
+
# sha256+mtime of six config files at SessionStart; this compares and NAMES what changed.
|
|
575
|
+
# Advisory because a session may change its own settings on purpose. No snapshot → NOT MEASURED
|
|
576
|
+
# (never «unchanged»). Lane: scripts/test_session_config_fingerprint_lanes.sh.
|
|
577
|
+
if [ -f "$FH/scripts/session_config_fingerprint.sh" ]; then
|
|
578
|
+
# Capture FIRST, then decorate — piping into sed hid the checker's rc (2026-09-26, cross-family).
|
|
579
|
+
_FP_OUT=$(bash "$FH/scripts/session_config_fingerprint.sh" compare --fh "$FH" 2>&1); _FP_RC=$?
|
|
580
|
+
printf '%s\n' "$_FP_OUT" | sed 's/^/④-f /'
|
|
581
|
+
case "$_FP_RC" in
|
|
582
|
+
(0|1|3) ;; # unchanged · changed (advisory) · NOT MEASURED — all already printed above
|
|
583
|
+
(*) echo "⚠️ ④-f config fingerprint NOT MEASURED — checker exited $_FP_RC (instrument error, not «unchanged»)" ;;
|
|
584
|
+
esac
|
|
585
|
+
else
|
|
586
|
+
echo "⚠️ ④-f config fingerprint NOT MEASURED — scripts/session_config_fingerprint.sh missing"
|
|
587
|
+
fi
|
|
588
|
+
|
|
552
589
|
# ⑤ CARD-LAST invariant — the card must be the NEWEST close artifact. A card older than
|
|
553
590
|
# fh_completed / signal files written this session = ⑤ ran before ①–④ finished (the bug class).
|
|
554
591
|
if [ -f "$CARD" ]; then
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# session_config_fingerprint.sh — snapshot the session's config files at start, compare at close.
|
|
3
|
+
#
|
|
4
|
+
# WHY (2026-09-26, measured on this repo): a sub-agent's measurement run (empty work-dir path →
|
|
5
|
+
# `cd "" ` succeeded in place) overwrote this checkout's
|
|
6
|
+
# .claude/settings.json and CLAUDE.md mid-session, and FH did not notice. The settings file is
|
|
7
|
+
# gitignored (no `git status`, no `git checkout` undo), and the only existing guard —
|
|
8
|
+
# sim_isolated_run.sh — compares ~/.claude/settings.json mtime around ITS OWN runs, nothing else.
|
|
9
|
+
# So a silent config rewrite by anything else in the session had no detector at all.
|
|
10
|
+
#
|
|
11
|
+
# WHAT: `snap` records sha256 + mtime of six files (below) into a gitignored snapshot with the
|
|
12
|
+
# session id. `compare` recomputes and NAMES every file that changed. It is ADVISORY by design —
|
|
13
|
+
# a session may legitimately change its own settings — so it never blocks; it makes a change
|
|
14
|
+
# visible, and says where the recovery procedure lives.
|
|
15
|
+
#
|
|
16
|
+
# Files: <FH>/.claude/settings.json · <FH>/.claude/settings.local.json · <FH>/CLAUDE.local.md ·
|
|
17
|
+
# <FH>/CLAUDE.md (tracked, but an overwrite target on 2026-09-26) ·
|
|
18
|
+
# <HOME>/.claude/settings.json · <HOME>/.claude/CLAUDE.md
|
|
19
|
+
#
|
|
20
|
+
# 🟥 No snapshot → NOT MEASURED, never «no change». A compare against nothing is not a zero.
|
|
21
|
+
# READ-ONLY on every file it fingerprints; writes only its own snapshot file.
|
|
22
|
+
#
|
|
23
|
+
# Usage:
|
|
24
|
+
# bash scripts/session_config_fingerprint.sh snap [--fh DIR] [--home DIR] [--out FILE] [--source SRC]
|
|
25
|
+
# bash scripts/session_config_fingerprint.sh compare [--fh DIR] [--home DIR] [--out FILE]
|
|
26
|
+
# --source clear|compact keeps an existing snapshot of the SAME session (a /clear or compaction
|
|
27
|
+
# is the same session continuing — re-snapping there would erase the evidence).
|
|
28
|
+
# Exit (compare): 0 unchanged · 1 changed (advisory) · 3 NOT MEASURED · 2 usage
|
|
29
|
+
# Exit (snap): 0 written or kept · 3 could not write · 2 usage
|
|
30
|
+
set -uo pipefail
|
|
31
|
+
|
|
32
|
+
MODE="${1:-}"; shift 2>/dev/null || true
|
|
33
|
+
FH="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
|
34
|
+
H="${HOME:-}"
|
|
35
|
+
OUT=""
|
|
36
|
+
SRC="unknown"
|
|
37
|
+
while [ $# -gt 0 ]; do
|
|
38
|
+
case "$1" in
|
|
39
|
+
--fh) [ -n "${2:-}" ] || { echo "usage: --fh needs a path" >&2; exit 2; }; FH="$2"; shift 2 ;;
|
|
40
|
+
--home) [ -n "${2:-}" ] || { echo "usage: --home needs a path" >&2; exit 2; }; H="$2"; shift 2 ;;
|
|
41
|
+
--out) [ -n "${2:-}" ] || { echo "usage: --out needs a path" >&2; exit 2; }; OUT="$2"; shift 2 ;;
|
|
42
|
+
--source) SRC="${2:-unknown}"; shift 2 ;;
|
|
43
|
+
*) echo "usage: unknown argument: $1" >&2; exit 2 ;;
|
|
44
|
+
esac
|
|
45
|
+
done
|
|
46
|
+
[ -n "$OUT" ] || OUT="$FH/tracks/_meta/.session_config_fingerprint"
|
|
47
|
+
SID="${CLAUDE_CODE_SESSION_ID:-pid-${PPID:-$$}}"
|
|
48
|
+
|
|
49
|
+
_mtime() { stat -c %Y "$1" 2>/dev/null || stat -f %m "$1" 2>/dev/null || echo "?"; }
|
|
50
|
+
_hash() {
|
|
51
|
+
if command -v shasum >/dev/null 2>&1; then shasum -a 256 "$1" 2>/dev/null | awk '{print $1}'
|
|
52
|
+
elif command -v sha256sum >/dev/null 2>&1; then sha256sum "$1" 2>/dev/null | awk '{print $1}'
|
|
53
|
+
else cksum "$1" 2>/dev/null | awk '{print "cksum-"$1"-"$2}'; fi
|
|
54
|
+
}
|
|
55
|
+
# label<TAB>path — labels are what the report prints, so they never carry an absolute home path.
|
|
56
|
+
_targets() {
|
|
57
|
+
printf 'repo:.claude/settings.json\t%s\n' "$FH/.claude/settings.json"
|
|
58
|
+
printf 'repo:.claude/settings.local.json\t%s\n' "$FH/.claude/settings.local.json"
|
|
59
|
+
printf 'repo:CLAUDE.local.md\t%s\n' "$FH/CLAUDE.local.md"
|
|
60
|
+
printf 'repo:CLAUDE.md\t%s\n' "$FH/CLAUDE.md"
|
|
61
|
+
printf 'home:~/.claude/settings.json\t%s\n' "$H/.claude/settings.json"
|
|
62
|
+
printf 'home:~/.claude/CLAUDE.md\t%s\n' "$H/.claude/CLAUDE.md"
|
|
63
|
+
}
|
|
64
|
+
# one line per target: label<TAB>state<TAB>hash<TAB>mtime (state PRESENT|ABSENT|UNREADABLE)
|
|
65
|
+
_measure() {
|
|
66
|
+
_targets | while IFS="$(printf '\t')" read -r label path; do
|
|
67
|
+
if [ ! -e "$path" ]; then printf '%s\tABSENT\t-\t-\n' "$label"
|
|
68
|
+
elif [ ! -r "$path" ]; then printf '%s\tUNREADABLE\t-\t-\n' "$label"
|
|
69
|
+
else
|
|
70
|
+
h="$(_hash "$path")"
|
|
71
|
+
if [ -n "$h" ]; then printf '%s\tPRESENT\t%s\t%s\n' "$label" "$h" "$(_mtime "$path")"
|
|
72
|
+
else printf '%s\tUNREADABLE\t-\t-\n' "$label"; fi
|
|
73
|
+
fi
|
|
74
|
+
done
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
case "$MODE" in
|
|
78
|
+
snap)
|
|
79
|
+
if [ -f "$OUT" ]; then
|
|
80
|
+
prev_sid="$(sed -n '/^session=/{s/^session=//p;q;}' "$OUT" 2>/dev/null)"
|
|
81
|
+
case "$SRC" in
|
|
82
|
+
clear|compact) if [ "$prev_sid" = "$SID" ]; then exit 0; fi ;;
|
|
83
|
+
esac
|
|
84
|
+
fi
|
|
85
|
+
mkdir -p "$(dirname "$OUT")" 2>/dev/null
|
|
86
|
+
tmp="$OUT.tmp.$$"
|
|
87
|
+
{ printf 'session=%s\nat=%s\nsource=%s\n' "$SID" "$(date +%s)" "$SRC"; _measure; } > "$tmp" 2>/dev/null \
|
|
88
|
+
&& mv "$tmp" "$OUT" 2>/dev/null && exit 0
|
|
89
|
+
rm -f "$tmp" 2>/dev/null; exit 3 ;;
|
|
90
|
+
compare)
|
|
91
|
+
if [ ! -r "$OUT" ]; then
|
|
92
|
+
echo "⚠️ config fingerprint NOT MEASURED — no session-start snapshot ($(basename "$OUT"))."
|
|
93
|
+
echo " No snapshot is not «no change». The snap runs from scripts/fh_session_load.sh at SessionStart."
|
|
94
|
+
exit 3
|
|
95
|
+
fi
|
|
96
|
+
snap_sid="$(sed -n '/^session=/{s/^session=//p;q;}' "$OUT")"
|
|
97
|
+
now="$(_measure)"
|
|
98
|
+
changed=""; n=0; touched=""
|
|
99
|
+
while IFS="$(printf '\t')" read -r label state hash mt; do
|
|
100
|
+
[ -n "$label" ] || continue
|
|
101
|
+
old="$(awk -F'\t' -v l="$label" '$1==l {print $2"\t"$3"\t"$4; exit}' "$OUT")"
|
|
102
|
+
if [ -z "$old" ]; then changed="$changed
|
|
103
|
+
↳ $label — not in snapshot (NOT MEASURED)"; n=$((n+1)); continue; fi
|
|
104
|
+
old_state="${old%% *}"; _rest="${old#* }"; old_hash="${_rest%% *}"; old_mt="${_rest#* }"
|
|
105
|
+
if [ "$state" = UNREADABLE ] || [ "$old_state" = UNREADABLE ]; then
|
|
106
|
+
changed="$changed
|
|
107
|
+
↳ $label — unreadable now or at start (NOT MEASURED)"; n=$((n+1))
|
|
108
|
+
elif [ "$state" != "$old_state" ]; then
|
|
109
|
+
changed="$changed
|
|
110
|
+
↳ $label — $old_state → $state"; n=$((n+1))
|
|
111
|
+
elif [ "$hash" != "$old_hash" ]; then
|
|
112
|
+
changed="$changed
|
|
113
|
+
↳ $label — content changed"; n=$((n+1))
|
|
114
|
+
elif [ "$state" = PRESENT ] && [ "$mt" != "$old_mt" ]; then
|
|
115
|
+
# 🟥 2026-09-26 (cross-family): mtime was snapped and never compared. Decision: the content
|
|
116
|
+
# hash is the verdict (a rewrite with identical bytes restores nothing and loses nothing),
|
|
117
|
+
# but a touch is still a sign something wrote there — so it is REPORTED separately and
|
|
118
|
+
# NOT counted as a change. Folding it into «changed» would cry wolf on every editor save;
|
|
119
|
+
# dropping it would hide the one trace a same-bytes rewrite leaves.
|
|
120
|
+
touched="$touched
|
|
121
|
+
↳ $label — touched (내용 동일, mtime only)"
|
|
122
|
+
fi
|
|
123
|
+
done <<EOF_NOW
|
|
124
|
+
$now
|
|
125
|
+
EOF_NOW
|
|
126
|
+
note=""
|
|
127
|
+
[ "$snap_sid" = "$SID" ] || note=" (snapshot belongs to session $snap_sid, not this one — baseline may be older)"
|
|
128
|
+
if [ "$n" -eq 0 ]; then
|
|
129
|
+
echo "✅ config fingerprint: none of the 6 config files changed since session start$note"
|
|
130
|
+
[ -z "$touched" ] || echo " ⓘ written without content change (advisory, not counted):$touched"
|
|
131
|
+
exit 0
|
|
132
|
+
fi
|
|
133
|
+
echo "⚠️ config fingerprint: $n config file(s) changed since session start$note$changed"
|
|
134
|
+
[ -z "$touched" ] || echo " ⓘ written without content change (advisory, not counted):$touched"
|
|
135
|
+
echo " Intended change → ignore. Not yours → back it up now and recover per"
|
|
136
|
+
echo " knowledge/shared/harness-core/checkout_layer_drift.md §Config-Overwrite-Recovery"
|
|
137
|
+
exit 1 ;;
|
|
138
|
+
*) sed -n '2,30p' "$0"; exit 2 ;;
|
|
139
|
+
esac
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# subagent_tally_hook.sh — SubagentStop hook body: append today's date to the dispatch tally that
|
|
3
|
+
# session_close_check.sh ④-e reconciles against the invocation log. TALLIES ONLY — it never writes a
|
|
4
|
+
# log entry (a fabricated outcome/evidence would poison the 60/40 promotion gate).
|
|
5
|
+
#
|
|
6
|
+
# WHY THIS IS A SCRIPT NOW (2026-09-25, fh_signal_2026-09-25_subagent-tally-counts-internal-agents):
|
|
7
|
+
# SubagentStop also fires for Claude Code's OWN internal agents — measured: `/compact` produced a
|
|
8
|
+
# SubagentStop with `agent_type: ""` (PreCompact fired alongside it), while a dispatched Explore
|
|
9
|
+
# agent carried `agent_type: "Explore"` and a dispatch with subagent_type OMITTED carried
|
|
10
|
+
# `agent_type: "general-purpose"` (claude 2.1.282, headless, 2026-09-25). The inline hook counted
|
|
11
|
+
# all three, so a session that dispatched nothing failed ④-e after a context compaction — and the
|
|
12
|
+
# operator was twice told «probably a peer session», which was false.
|
|
13
|
+
#
|
|
14
|
+
# DISCRIMINATOR — and why it is this narrow:
|
|
15
|
+
# skip ONLY when `agent_type` is PRESENT and EXACTLY "". Everything else counts:
|
|
16
|
+
# field absent (older CLI) · non-JSON stdin · empty stdin · no python3 → COUNT.
|
|
17
|
+
# Over-counting re-creates the known false positive (loud, the operator sees it). Under-counting a
|
|
18
|
+
# real dispatch is the fail-open ④-e exists to close (silent). So every doubt lands on «count».
|
|
19
|
+
#
|
|
20
|
+
# ALSO RECORDED: session_id and agent_type go to a SIDE file, never into the tally line — ④-e matches
|
|
21
|
+
# `^DATE$` exactly, and changing the tally format would silently zero every count on a machine
|
|
22
|
+
# running the old checker. The side file is for attribution when a count looks wrong.
|
|
23
|
+
#
|
|
24
|
+
# exit 0 ALWAYS — a failing hook must never block a subagent from finishing.
|
|
25
|
+
|
|
26
|
+
HUB="${CLAUDE_PROJECT_DIR:-$(git rev-parse --show-toplevel 2>/dev/null || echo "$HOME/projects/forge-harness")}"
|
|
27
|
+
T="${FH_TALLY_FILE:-$HUB/tracks/_meta/.subagent_dispatch_tally}"
|
|
28
|
+
# 🟥 Read with a TIME LIMIT, never a bare `cat`. A caller that never closes stdin would park `cat` on
|
|
29
|
+
# EOF until the hook's own `timeout` kills it — BEFORE the append below — and a real dispatch would
|
|
30
|
+
# vanish silently (Axis-2 blind review, 2026-09-25, reproduced with `sleep 8 | …`; the old inline
|
|
31
|
+
# hook never read stdin, so this was new).
|
|
32
|
+
# 🟥 The bounded read lives in python, not in a bash `read` loop (2026-09-25, local macOS run):
|
|
33
|
+
# · line-wise `read -t` — /bin/bash 3.2 DISCARDS a partial line on timeout (bash ≥4 keeps it), so a
|
|
34
|
+
# payload without a trailing newline on an open pipe read as EMPTY on macOS only
|
|
35
|
+
# (measured: 3.2 rc=1 got=[] · 5.3 rc=142 got=[abc]);
|
|
36
|
+
# · char-wise `read -n 1` — fixes that but is superlinear: 50 KB took 19 s, and SubagentStop
|
|
37
|
+
# carries the agent's last message.
|
|
38
|
+
# Rules, all landing on COUNT when in doubt: stop at EOF, or after 2 s with no new bytes (open pipe
|
|
39
|
+
# → classify what arrived), or at 3 s total (under the 5 s hook timeout) · over 8 MiB → count · a raw NUL → json rejects it →
|
|
40
|
+
# count (codex review 2026-09-25 showed a bash char-reader turning NUL into whitespace → silent
|
|
41
|
+
# «internal»; json does the rejecting here, so there is deliberately no separate NUL guard — a
|
|
42
|
+
# revert probe showed one would be decorative).
|
|
43
|
+
# No python3 → stdin is not read at all → count (the old inline hook never read it either).
|
|
44
|
+
CLS="count"
|
|
45
|
+
AT=""; SID=""
|
|
46
|
+
if command -v python3 >/dev/null 2>&1; then
|
|
47
|
+
_r=$(python3 -c '
|
|
48
|
+
import json, os, select, sys, time
|
|
49
|
+
fd = 0; buf = b""; cap = 8 << 20; doubt = False
|
|
50
|
+
t_end = time.monotonic() + 3.0 # < settings.json hook timeout 5 s — the kill would land BEFORE the append
|
|
51
|
+
try:
|
|
52
|
+
while True:
|
|
53
|
+
left = t_end - time.monotonic()
|
|
54
|
+
if left <= 0:
|
|
55
|
+
break
|
|
56
|
+
r, _, _ = select.select([fd], [], [], min(2.0, left))
|
|
57
|
+
if not r:
|
|
58
|
+
break # idle 2 s — pipe left open; classify what arrived
|
|
59
|
+
chunk = os.read(fd, 65536)
|
|
60
|
+
if not chunk:
|
|
61
|
+
break # EOF
|
|
62
|
+
buf += chunk
|
|
63
|
+
if len(buf) > cap:
|
|
64
|
+
doubt = True; break
|
|
65
|
+
except Exception:
|
|
66
|
+
doubt = True
|
|
67
|
+
if doubt or not buf.strip():
|
|
68
|
+
print("count\t\t"); sys.exit(0)
|
|
69
|
+
try:
|
|
70
|
+
d = json.loads(buf.decode("utf-8"))
|
|
71
|
+
except Exception:
|
|
72
|
+
print("count\t\t"); sys.exit(0)
|
|
73
|
+
if not isinstance(d, dict):
|
|
74
|
+
print("count\t\t"); sys.exit(0)
|
|
75
|
+
at = d.get("agent_type", None)
|
|
76
|
+
sid = d.get("session_id", "")
|
|
77
|
+
sid = sid if isinstance(sid, str) else ""
|
|
78
|
+
if at == "":
|
|
79
|
+
print("internal\t\t" + sid)
|
|
80
|
+
else:
|
|
81
|
+
print("count\t" + (at if isinstance(at, str) else "?") + "\t" + sid)
|
|
82
|
+
' 2>/dev/null) || _r=""
|
|
83
|
+
if [ -n "$_r" ]; then
|
|
84
|
+
CLS=$(printf '%s' "$_r" | cut -f1)
|
|
85
|
+
AT=$(printf '%s' "$_r" | cut -f2)
|
|
86
|
+
SID=$(printf '%s' "$_r" | cut -f3)
|
|
87
|
+
fi
|
|
88
|
+
fi
|
|
89
|
+
|
|
90
|
+
mkdir -p "$(dirname "$T")" 2>/dev/null
|
|
91
|
+
D=$(date +%Y-%m-%d)
|
|
92
|
+
printf '%s\t%s\t%s\t%s\n' "$D" "$CLS" "${AT:--}" "${SID:--}" >> "$T.detail" 2>/dev/null
|
|
93
|
+
[ "$CLS" = internal ] && exit 0
|
|
94
|
+
printf '%s\n' "$D" >> "$T" 2>/dev/null
|
|
95
|
+
exit 0
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# test_hook_drift_lanes.sh — lanes for scripts/hook_drift_check.sh and its consumer, ④-e of
|
|
3
|
+
# scripts/session_close_check.sh. Fixtures only (mktemp): never reads or writes the operator's
|
|
4
|
+
# real ~/.claude or this repo's gitignored settings.
|
|
5
|
+
#
|
|
6
|
+
# The defect these lanes pin (2026-09-26): ④-e treated «a SubagentStop hook exists» as «the tally
|
|
7
|
+
# is measured». An install still carrying the pre-2026-09-25 INLINE hook passed that test while
|
|
8
|
+
# over-counting. The revert probe at the end puts the presence grep back and requires the lane to
|
|
9
|
+
# go red on exactly that fixture — otherwise this file would be green whether or not the fix exists.
|
|
10
|
+
#
|
|
11
|
+
# Runs under bash 3.2 (/bin/bash) and bash 5.
|
|
12
|
+
set -uo pipefail
|
|
13
|
+
HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
14
|
+
ROOT="$(cd "$HERE/.." && pwd)"
|
|
15
|
+
SUBJ="$ROOT/scripts/hook_drift_check.sh"
|
|
16
|
+
CLOSE="$ROOT/scripts/session_close_check.sh"
|
|
17
|
+
T="$(mktemp -d 2>/dev/null || mktemp -d -t hookdrift)"
|
|
18
|
+
[ -n "$T" ] && [ -d "$T" ] || { echo "HARNESS-ERROR: mktemp failed"; exit 2; }
|
|
19
|
+
trap 'chmod -R u+rw "$T" 2>/dev/null; rm -rf "$T"' EXIT
|
|
20
|
+
pass=0; fail=0
|
|
21
|
+
chk() { if [ "$1" -eq 0 ]; then echo " ✅ $2"; pass=$((pass+1)); else echo " ❌ $2"; fail=$((fail+1)); fi; }
|
|
22
|
+
|
|
23
|
+
[ -f "$SUBJ" ] || { echo "HARNESS-ERROR: subject missing: $SUBJ"; exit 2; }
|
|
24
|
+
PY="$(command -v python3 2>/dev/null || echo /usr/bin/python3)"
|
|
25
|
+
|
|
26
|
+
mkdir -p "$T/tpl"
|
|
27
|
+
cp "$ROOT"/templates/*.json "$T/tpl/" || { echo "HARNESS-ERROR: cannot copy templates"; exit 2; }
|
|
28
|
+
|
|
29
|
+
# ── fixtures ──
|
|
30
|
+
# (a) CURRENT: the template's own SubagentStop block, byte-for-byte
|
|
31
|
+
"$PY" - "$ROOT/templates/subagent-tally-hook.json" "$T/current.json" <<'PY' || { echo "HARNESS-ERROR: fixture build"; exit 2; }
|
|
32
|
+
import json, sys
|
|
33
|
+
d = json.load(open(sys.argv[1]))
|
|
34
|
+
json.dump({"hooks": d["hooks"]}, open(sys.argv[2], "w"))
|
|
35
|
+
PY
|
|
36
|
+
# (b) STALE: the pre-2026-09-25 inline form (date-only append, no script)
|
|
37
|
+
cat > "$T/old_inline.json" <<'JSON'
|
|
38
|
+
{"hooks":{"SubagentStop":[{"matcher":"","hooks":[{"type":"command","command":"bash -c 'HUB=\"${CLAUDE_PROJECT_DIR:-$(git rev-parse --show-toplevel)}\"; T=\"$HUB/tracks/_meta/.subagent_dispatch_tally\"; printf \"%s\\n\" \"$(date +%Y-%m-%d)\" >> \"$T\"; exit 0'","timeout":5}]}]}}
|
|
39
|
+
JSON
|
|
40
|
+
# (c) matcher drift: same command, different matcher
|
|
41
|
+
"$PY" - "$T/current.json" "$T/matcher.json" <<'PY'
|
|
42
|
+
import json, sys
|
|
43
|
+
d = json.load(open(sys.argv[1])); d["hooks"]["SubagentStop"][0]["matcher"] = "general-purpose"
|
|
44
|
+
json.dump(d, open(sys.argv[2], "w"))
|
|
45
|
+
PY
|
|
46
|
+
# (d) unrelated SubagentStop hook only → ABSENT, not STALE (same event is not the same hook)
|
|
47
|
+
echo '{"hooks":{"SubagentStop":[{"matcher":"","hooks":[{"type":"command","command":"echo hi"}]}]}}' > "$T/unrelated.json"
|
|
48
|
+
# (e) malformed JSON → UNKNOWN
|
|
49
|
+
echo '{"hooks": {"SubagentStop": [' > "$T/broken.json"
|
|
50
|
+
# (f) template form AND the old inline form installed side by side — CC runs BOTH, old behaviour lives
|
|
51
|
+
"$PY" - "$T/current.json" "$T/old_inline.json" "$T/both.json" <<'PY'
|
|
52
|
+
import json, sys
|
|
53
|
+
cur = json.load(open(sys.argv[1])); old = json.load(open(sys.argv[2]))
|
|
54
|
+
cur["hooks"]["SubagentStop"][0]["hooks"] += old["hooks"]["SubagentStop"][0]["hooks"]
|
|
55
|
+
json.dump(cur, open(sys.argv[3], "w"))
|
|
56
|
+
PY
|
|
57
|
+
# (g) an installed hook entry with no command — unidentifiable, so not evidence of absence
|
|
58
|
+
echo '{"hooks":{"SubagentStop":[{"matcher":"","hooks":[{"type":"command"}]}]}}' > "$T/nocmd.json"
|
|
59
|
+
|
|
60
|
+
v() { bash "$SUBJ" --settings "$1" --templates "$T/tpl" --only subagent_tally_hook.sh --verdict 2>/dev/null; }
|
|
61
|
+
vr() { bash "$SUBJ" --settings "$1" --templates "$T/tpl" --only subagent_tally_hook.sh --verdict >/dev/null 2>&1; echo $?; }
|
|
62
|
+
|
|
63
|
+
echo "── verdicts (known pair + the two degrade cases) ──"
|
|
64
|
+
[ "$(v "$T/current.json")" = CURRENT ]; chk $? "template-identical hook → CURRENT"
|
|
65
|
+
[ "$(vr "$T/current.json")" = 0 ]; chk $? " … rc 0"
|
|
66
|
+
[ "$(v "$T/old_inline.json")" = STALE ]; chk $? "old inline hook → STALE (the defect: presence grep called this installed)"
|
|
67
|
+
[ "$(vr "$T/old_inline.json")" = 1 ]; chk $? " … rc 1"
|
|
68
|
+
[ "$(v "$T/matcher.json")" = STALE ]; chk $? "same command, different matcher → STALE"
|
|
69
|
+
[ "$(v "$T/unrelated.json")" = ABSENT ]; chk $? "unrelated SubagentStop hook → ABSENT (event match is not identity match)"
|
|
70
|
+
[ "$(v "$T/nonexistent.json")" = ABSENT ]; chk $? "no settings file → ABSENT"
|
|
71
|
+
[ "$(v "$T/broken.json")" = UNKNOWN ]; chk $? "malformed settings → UNKNOWN (not folded into CURRENT)"
|
|
72
|
+
[ "$(vr "$T/broken.json")" = 3 ]; chk $? " … rc 3"
|
|
73
|
+
if [ "$(id -u)" != 0 ]; then
|
|
74
|
+
cp "$T/current.json" "$T/noread.json"; chmod 000 "$T/noread.json"
|
|
75
|
+
[ "$(v "$T/noread.json")" = UNKNOWN ]; chk $? "unreadable settings (mode 000) → UNKNOWN even though its content is CURRENT"
|
|
76
|
+
else
|
|
77
|
+
echo " ⏭️ unreadable lane skipped (running as root — mode 000 is readable; not a pass)"
|
|
78
|
+
fi
|
|
79
|
+
[ "$(bash "$SUBJ" --settings "$T/current.json" --templates "$T/tpl" --only no_such_hook.sh --verdict 2>/dev/null)" = UNKNOWN ]
|
|
80
|
+
chk $? "--only with no matching template entry → UNKNOWN (nothing compared is not CURRENT)"
|
|
81
|
+
[ "$(bash "$SUBJ" --settings "$T/current.json" --templates "$T/empty_tpl" --verdict 2>/dev/null)" = UNKNOWN ]
|
|
82
|
+
chk $? "no templates found → UNKNOWN"
|
|
83
|
+
bash "$SUBJ" --settings "" >/dev/null 2>&1; [ $? -eq 2 ]; chk $? "empty --settings path refused (usage rc 2)"
|
|
84
|
+
tbl=$(bash "$SUBJ" --settings "$T/old_inline.json" --templates "$T/tpl" 2>/dev/null)
|
|
85
|
+
printf '%s\n' "$tbl" | grep -q '^STALE SubagentStop .*re-merge needed'; chk $? "table names the STALE hook and says re-merge"
|
|
86
|
+
printf '%s\n' "$tbl" | grep -q 'MODE_D_ONLY not compared'; chk $? "private-path Mode D block is reported as not compared (not silently dropped)"
|
|
87
|
+
|
|
88
|
+
# ── consumer: ④-e of session_close_check.sh, run on a scratch root ──
|
|
89
|
+
mk_root() { # $1 = root dir, $2 = settings fixture, $3 = close-check script to install
|
|
90
|
+
mkdir -p "$1/scripts" "$1/templates" "$1/.claude"
|
|
91
|
+
cp "$SUBJ" "$1/scripts/"; cp "$3" "$1/scripts/session_close_check.sh"; cp "$T/tpl/"*.json "$1/templates/"
|
|
92
|
+
cp "$2" "$1/.claude/settings.json"
|
|
93
|
+
}
|
|
94
|
+
# capture first, filter second — a pipe here would let the checker's own failure hide behind grep/head
|
|
95
|
+
e_line() { local _o; _o=$(bash "$1/scripts/session_close_check.sh" "$1" 2>&1); awk '/④-e/ && n<3 {print; n++}' <<<"$_o"; }
|
|
96
|
+
echo "── duplicate install · malformed entry (cross-family 2026-09-26) ──"
|
|
97
|
+
[ "$(v "$T/both.json")" = STALE ]; chk $? "template + old inline installed together → STALE (both run; was CURRENT via any())"
|
|
98
|
+
_dup=$(bash "$SUBJ" --settings "$T/both.json" --templates "$T/tpl" --only subagent_tally_hook.sh 2>/dev/null)
|
|
99
|
+
printf '%s\n' "$_dup" | grep -q '중복 설치'
|
|
100
|
+
chk $? " … says duplicate install (remove the old entry)"
|
|
101
|
+
[ "$(v "$T/nocmd.json")" = UNKNOWN ]; chk $? "installed entry without a command → UNKNOWN (형식 불량), not ABSENT"
|
|
102
|
+
# revert probes on the subject itself — each mutation must be confirmed applied, then flip its lane
|
|
103
|
+
sed 's/if exact and len(related) <= 1 and len(exact) == 1:/if exact: # MUTANT-ANY/' "$SUBJ" > "$T/mut_any.sh"
|
|
104
|
+
grep -q 'MUTANT-ANY' "$T/mut_any.sh"; chk $? "revert probe (any): mutation applied"
|
|
105
|
+
[ "$(bash "$T/mut_any.sh" --settings "$T/both.json" --templates "$T/tpl" --only subagent_tally_hook.sh --verdict 2>/dev/null)" = CURRENT ]
|
|
106
|
+
chk $? "revert probe (any): old any() rule calls the duplicate install CURRENT → the STALE lane would be RED"
|
|
107
|
+
sed 's/ if ev in inst_bad:/ if False: # MUTANT-NOBAD/' "$SUBJ" > "$T/mut_bad.sh"
|
|
108
|
+
grep -q 'MUTANT-NOBAD' "$T/mut_bad.sh"; chk $? "revert probe (malformed): mutation applied"
|
|
109
|
+
[ "$(bash "$T/mut_bad.sh" --settings "$T/nocmd.json" --templates "$T/tpl" --only subagent_tally_hook.sh --verdict 2>/dev/null)" = ABSENT ]
|
|
110
|
+
chk $? "revert probe (malformed): without the guard the entry folds to ABSENT → the UNKNOWN lane would be RED"
|
|
111
|
+
|
|
112
|
+
echo "── consumer ④-e ──"
|
|
113
|
+
mk_root "$T/r_old" "$T/old_inline.json" "$CLOSE"
|
|
114
|
+
out=$(e_line "$T/r_old")
|
|
115
|
+
printf '%s\n' "$out" | grep -q 'NOT MEASURED — 옛 훅'; chk $? "old inline hook → ④-e says NOT MEASURED (옛 훅, re-merge)"
|
|
116
|
+
mk_root "$T/r_cur" "$T/current.json" "$CLOSE"
|
|
117
|
+
out=$(e_line "$T/r_cur")
|
|
118
|
+
printf '%s\n' "$out" | grep -q 'NOT MEASURED'; [ $? -ne 0 ]; chk $? "current hook → ④-e measured (control: the lane can go green)"
|
|
119
|
+
mk_root "$T/r_miss" "$T/current.json" "$CLOSE"; rm -f "$T/r_miss/scripts/hook_drift_check.sh"
|
|
120
|
+
out=$(e_line "$T/r_miss")
|
|
121
|
+
printf '%s\n' "$out" | grep -q 'NOT MEASURED — could not determine'; chk $? "checker missing → NOT MEASURED (not a pass)"
|
|
122
|
+
|
|
123
|
+
# ── revert probe: put the presence grep back; the old-inline lane must go RED ──
|
|
124
|
+
echo "── revert probe ──"
|
|
125
|
+
"$PY" - "$CLOSE" "$T/mutant_close.sh" <<'PY'
|
|
126
|
+
import re, sys
|
|
127
|
+
s = open(sys.argv[1], encoding="utf-8").read()
|
|
128
|
+
start = s.index("HOOK_OK=0\nHOOK_STATE=UNKNOWN")
|
|
129
|
+
end = s.index("esac\n", s.index("case \"$HOOK_STATE\" in\n (STALE)")) + len("esac\n")
|
|
130
|
+
mut = ('HOOK_OK=0\nif [ -f "$FH/.claude/settings.json" ]; then\n'
|
|
131
|
+
' grep -q \'"SubagentStop"\' "$FH/.claude/settings.json" 2>/dev/null && HOOK_OK=1\nfi\n'
|
|
132
|
+
'# MUTANT-PRESENCE-GREP\n')
|
|
133
|
+
open(sys.argv[2], "w", encoding="utf-8").write(s[:start] + mut + s[end:])
|
|
134
|
+
PY
|
|
135
|
+
grep -q 'MUTANT-PRESENCE-GREP' "$T/mutant_close.sh"; chk $? "mutation applied (control for the probe itself)"
|
|
136
|
+
mk_root "$T/r_mut" "$T/old_inline.json" "$T/mutant_close.sh"
|
|
137
|
+
out=$(e_line "$T/r_mut")
|
|
138
|
+
printf '%s\n' "$out" | grep -q 'NOT MEASURED'; [ $? -ne 0 ]
|
|
139
|
+
chk $? "with the presence grep restored, the old inline hook is treated as measured → the consumer lane above would be RED"
|
|
140
|
+
|
|
141
|
+
echo
|
|
142
|
+
if [ "$fail" -eq 0 ]; then echo "HOOK-DRIFT LANES: PASS ($pass/$pass)"; exit 0; fi
|
|
143
|
+
echo "HOOK-DRIFT LANES: FAIL ($fail failed, $pass passed)"; exit 1
|
|
@@ -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
|