@chrono-meta/fh-gate 3.26.2 → 3.27.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.
@@ -0,0 +1,61 @@
1
+ #!/usr/bin/env bash
2
+ # test_env_delta_worktree_lanes.sh — lanes for the linked-worktree rule in scripts/fh_env_delta_scan.sh.
3
+ #
4
+ # WHY: 2026-10-15 the SessionStart hook reported «33 unmapped sibling repos»; 30 of them were linked
5
+ # worktrees of repos the hub already knows (friends-on-desk, qasp-dev, clawd-on-desk, the hub itself).
6
+ # A worktree is another checkout of its main repo, not a new project. These lanes pin both sides:
7
+ # - a linked worktree is NOT counted as a sibling (the fix)
8
+ # - its unmapped main repo IS still counted (known-positive — the fix must not hide real repos)
9
+ # - a `.git` FILE that is not a worktree pointer (submodule shape) still counts (old behaviour kept)
10
+ # - cwd inside a worktree of a MAPPED repo → silent; of an UNMAPPED repo → names the main repo
11
+ set -u
12
+ HERE="$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)"
13
+ SCAN="$HERE/fh_env_delta_scan.sh"
14
+ [ -f "$SCAN" ] || { echo "FAIL subject missing: $SCAN"; exit 1; }
15
+ command -v git >/dev/null 2>&1 || { echo "FAIL git not on PATH — lanes cannot build fixtures"; exit 1; }
16
+
17
+ T="$(mktemp -d "${TMPDIR:-/tmp}/fh_envdelta_wt.XXXXXX")"
18
+ trap 'rm -rf "$T"' EXIT
19
+ ROOT="$T/projects"; HUB="$ROOT/hub"; SENT="$T/sent"
20
+ mkdir -p "$HUB/tracks/beta" "$HUB/scripts" "$SENT"
21
+ cp "$SCAN" "$HUB/scripts/"; [ -f "$HERE/hook_source_lib.sh" ] && cp "$HERE/hook_source_lib.sh" "$HUB/scripts/"
22
+
23
+ _repo() { git init -q "$1" && git -C "$1" -c user.email=t@t -c user.name=t commit -q --allow-empty -m init; }
24
+ _repo "$ROOT/alpha" # unmapped main repo
25
+ _repo "$ROOT/beta" # mapped main repo (tracks/beta)
26
+ git -C "$ROOT/alpha" worktree add -q "$ROOT/alpha-wt" -b wt-a 2>/dev/null
27
+ git -C "$ROOT/beta" worktree add -q "$ROOT/beta-wt" -b wt-b 2>/dev/null
28
+ mkdir -p "$ROOT/gamma"; printf 'gitdir: %s\n' "$T/elsewhere/.git/modules/gamma" > "$ROOT/gamma/.git" # submodule shape
29
+
30
+ FAILED=0; PASSED=0
31
+ _pass() { echo "✅ $1"; PASSED=$((PASSED+1)); }
32
+ _fail() { echo "❌ $1"; FAILED=1; }
33
+ _run() { # $1 = cwd to report as CLAUDE_PROJECT_DIR
34
+ printf '{"source":"startup"}' | HUB_DIR="$HUB" FH_PROJECTS_ROOT="$ROOT" CC_SENTINEL_DIR="$SENT" \
35
+ CLAUDE_PROJECT_DIR="$1" bash "$HUB/scripts/fh_env_delta_scan.sh" 2>&1
36
+ }
37
+
38
+ # Fixture sanity: the worktrees really are worktrees (else every lane below is vacuous).
39
+ for w in alpha-wt beta-wt; do
40
+ grep -q '/.git/worktrees/' "$ROOT/$w/.git" 2>/dev/null && _pass "fixture: $w is a linked worktree" \
41
+ || _fail "fixture: $w is not a linked worktree — lanes would be vacuous"
42
+ done
43
+
44
+ OUT="$(_run "$HUB")"
45
+ case "$OUT" in *"2 unmapped sibling repo(s)"*) _pass "siblings: count = 2 (alpha + gamma)";;
46
+ *) _fail "siblings: expected «2 unmapped sibling repo(s)», got: $(printf '%s' "$OUT" | tr '\n' ' ')";; esac
47
+
48
+ OUT="$(_run "$ROOT/beta-wt")"
49
+ case "$OUT" in *"current cwd"*) _fail "cwd in worktree of MAPPED repo: should be silent, got cwd line";;
50
+ *) _pass "cwd in worktree of mapped repo → no cwd line";; esac
51
+
52
+ OUT="$(_run "$ROOT/alpha-wt")"
53
+ case "$OUT" in *"current cwd 'alpha'"*) _pass "cwd in worktree of UNMAPPED repo → names main repo 'alpha'";;
54
+ *) _fail "cwd in worktree of unmapped repo: expected «current cwd 'alpha'», got: $(printf '%s' "$OUT" | tr '\n' ' ')";; esac
55
+
56
+ OUT="$(_run "$ROOT/gamma")"
57
+ case "$OUT" in *"current cwd 'gamma'"*) _pass "submodule-shape .git file still counts (cwd 'gamma')";;
58
+ *) _fail "submodule-shape .git file no longer counts";; esac
59
+
60
+ if [ "$FAILED" -ne 0 ]; then echo "ENV-DELTA WORKTREE LANES: FAIL ($PASSED passed)"; exit 1; fi
61
+ echo "ENV-DELTA WORKTREE LANES: PASS ($PASSED lanes)"
@@ -0,0 +1,210 @@
1
+ #!/usr/bin/env bash
2
+ # test_memory_gc_report_lanes.sh — known-pair lanes for scripts/memory_gc_report.py
3
+ # Every lane asserts an EXACT value or an exact collection (codex R1 2026-10-15: prefix / presence
4
+ # checks stayed green under 4 mutants). Fixtures carry their own negative next to each positive.
5
+ set -u
6
+ HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
7
+ PY="${PYTHON:-python3}"
8
+ T="$(mktemp -d)"; trap 'rm -rf "$T"' EXIT
9
+ pass=0; fail=0
10
+ eq(){ if [ "$2" = "$3" ]; then echo "PASS $1"; pass=$((pass+1)); else echo "FAIL $1 — got [$2] want [$3]"; fail=$((fail+1)); fi; }
11
+
12
+ M="$T/m"; mkdir -p "$M"
13
+ w(){ printf '%s\n' "$2" > "$M/$1"; }
14
+ hdr='---
15
+ name: x
16
+ description: fixture
17
+ metadata:'
18
+ w user_z.md "$hdr
19
+ type: user
20
+ ---
21
+ body"
22
+ w user_a.md "$hdr
23
+ type: user
24
+ hits:
25
+ - 2026-01-01 | old founding, user entries never go cold
26
+ ---
27
+ body"
28
+ w fb_promote.md "$hdr
29
+ type: feedback
30
+ hits:
31
+ - 2026-10-01 | first
32
+
33
+ # a comment inside the list must not end it
34
+ - 2026-10-01 | same day again
35
+ - 2026-10-05 | other day
36
+ ---
37
+ body"
38
+ w fb_two_two.md "$hdr
39
+ type: feedback
40
+ hits:
41
+ - 2026-10-03 | a
42
+ - 2026-10-04 | b
43
+ ---
44
+ body"
45
+ w fb_sameday.md "$hdr
46
+ type: feedback
47
+ hits:
48
+ - 2026-10-02 | a
49
+ - 2026-10-02 | b
50
+ - 2026-10-02 | c
51
+ ---
52
+ body"
53
+ w fb_cold.md "$hdr
54
+ type: feedback
55
+ hits:
56
+ - 2026-09-15 | exactly 30 days before today
57
+ ---
58
+ body"
59
+ w fb_fresh.md "$hdr
60
+ type: feedback
61
+ hits:
62
+ - 2026-09-16 | 29 days, not cold yet
63
+ ---
64
+ body"
65
+ w fb_unmeasured.md "$hdr
66
+ type: feedback
67
+ ---
68
+ body"
69
+ w fb_unlisted.md "$hdr
70
+ type: feedback
71
+ ---
72
+ body"
73
+ w fb_baddate.md "$hdr
74
+ type: feedback
75
+ hits:
76
+ - 2026-99-99 | impossible
77
+ - 2026-99-98 | impossible
78
+ - 2026-99-97 | impossible
79
+ ---
80
+ body"
81
+ w fb_future.md "$hdr
82
+ type: feedback
83
+ hits:
84
+ - 2027-01-01 | future
85
+ ---
86
+ body"
87
+ w fb_inline.md "$hdr
88
+ type: feedback
89
+ hits: [bad]
90
+ ---
91
+ body"
92
+ w fb_foreign.md "---
93
+ name: x
94
+ other:
95
+ hits:
96
+ - 2026-10-01 | not under metadata
97
+ metadata:
98
+ type: feedback
99
+ ---
100
+ body"
101
+ w fb_unterm.md "---
102
+ name: x
103
+ metadata:
104
+ type: feedback
105
+ hits:
106
+ - 2026-10-01 | never closed"
107
+ mkdir "$M/fb_dir.md"
108
+ w MEMORY.md "# Memory Index
109
+ - [Z](user_z.md) — user listed first
110
+ - [A](user_a.md) — user listed second
111
+ - [S](fb_sameday.md \"titled\") — titled link
112
+ - [P](./fb_promote.md) — dot-slash link
113
+ - [T](fb_two_two.md#part) — fragment link
114
+ - [C](fb_cold.md)
115
+ - [F](fb_fresh.md)
116
+ - [N](fb_unmeasured.md)
117
+ - [B](fb_baddate.md)
118
+ - [U](fb_future.md)
119
+ - [I](fb_inline.md)
120
+ - [O](fb_foreign.md)
121
+ - [X](fb_unterm.md)
122
+ - [web](https://example.com/page.md) — external, not a local file
123
+ - [P again](fb_promote.md) — duplicate
124
+ - [gone](fb_missing.md#sec) — dangling with fragment"
125
+
126
+ J="$(python3 "$HERE/memory_gc_report.py" "$M" --today 2026-10-15 --json)"; rc=$?
127
+ q(){ printf '%s' "$J" | "$PY" -c "import json,sys;d=json.load(sys.stdin);E={e['file']:e for e in d['entries']};print($1)"; }
128
+
129
+ eq "L0 report runs" "$rc" 0
130
+ eq "L1 promote = exactly age≥3 over ≥2 days (2-hit/2-day and same-day x3 excluded)" "$(q "d['promote']")" "[['fb_promote.md', 3, 2]]"
131
+ eq "L2 blank line + comment inside hits do not truncate the list" "$(q "E['fb_promote.md']['age']")" 3
132
+ eq "L3 cold = non-user age 1 at ≥30 days (29 days and old user entry stay)" "$(q "d['cold']")" "['fb_cold.md']"
133
+ eq "L4 no hits = UNMEASURED (age None), not age 1" "$(q "E['fb_unmeasured.md']['age']")" None
134
+ eq "L5 hits outside metadata are ignored" "$(q "E['fb_foreign.md']['age']")" None
135
+ eq "L6 impossible dates never measure or promote" "$(q "(E['fb_baddate.md']['age'], E['fb_baddate.md']['status'], len(E['fb_baddate.md']['bad']))")" "(None, 'HITS_MALFORMED', 3)"
136
+ eq "L7 future date rejected" "$(q "(E['fb_future.md']['age'], E['fb_future.md']['status'])")" "(None, 'HITS_MALFORMED')"
137
+ eq "L8 inline hits flagged" "$(q "E['fb_inline.md']['status']")" HITS_MALFORMED
138
+ eq "L9 unterminated frontmatter flagged" "$(q "E['fb_unterm.md']['status']")" UNTERMINATED_FRONTMATTER
139
+ eq "L10 unreadable topic flagged, not folded into no-hits" "$(q "E['fb_dir.md']['status']")" READ_ERROR
140
+ eq "L11 errors list is exact" "$(q "sorted(x[0] for x in d['errors'])")" "['fb_baddate.md', 'fb_dir.md', 'fb_future.md', 'fb_inline.md', 'fb_unterm.md']"
141
+ eq "L12 ./ , titled and #fragment links resolve; only the real orphan is unlisted" "$(q "sorted(d['unlisted'])")" "['fb_dir.md', 'fb_unlisted.md']"
142
+ eq "L13 duplicate reported with both line numbers" "$(q "d['duplicates']")" "[['fb_promote.md', 5, 16]]"
143
+ eq "L14 dangling local link (fragment stripped); external https ignored" "$(q "d['dangling']")" "[['fb_missing.md', 17]]"
144
+ eq "L15 full order: users in index order, measured by age (ties index order), rest in index order, cold out" \
145
+ "$(q "d['order']")" \
146
+ "['user_z.md', 'user_a.md', 'fb_sameday.md', 'fb_promote.md', 'fb_two_two.md', 'fb_fresh.md', 'fb_unmeasured.md', 'fb_baddate.md', 'fb_future.md', 'fb_inline.md', 'fb_foreign.md', 'fb_unterm.md']"
147
+ eq "L16 every topic file has an entry" "$(q "len(d['entries'])")" 15
148
+
149
+ # cap boundary: an index that fits exactly is within cap; one char over names the line and the loaded prefix
150
+ C="$T/c"; mkdir -p "$C"; printf '[a](a.md)' > "$C/MEMORY.md"; printf -- '---\nmetadata:\n type: feedback\n---\n' > "$C/a.md"
151
+ eq "L17 exact-fit index is within cap" "$(python3 "$HERE/memory_gc_report.py" "$C" --cap 9 --json | "$PY" -c "import json,sys;print(json.load(sys.stdin)['cut'])")" None
152
+ printf 'line one\n[a](a.md)\n' > "$C/MEMORY.md"
153
+ eq "L18 cut names line 2 with 3 chars loaded" "$(python3 "$HERE/memory_gc_report.py" "$C" --cap 12 --json | "$PY" -c "import json,sys;c=json.load(sys.stdin)['cut'];print(c['line'],c['chars_loaded_in_line'])")" "2 3"
154
+
155
+ python3 "$HERE/memory_gc_report.py" "$T/nope" >/dev/null 2>&1; eq "L19 missing dir = HARNESS-ERROR rc=2, not an empty report" "$?" 2
156
+ before="$(cd "$M" && find . -type f -exec cksum {} + | sort)"; python3 "$HERE/memory_gc_report.py" "$M" >/dev/null 2>&1; after="$(cd "$M" && find . -type f -exec cksum {} + | sort)"
157
+ eq "L20 read-only: fixture bytes unchanged" "$before" "$after"
158
+
159
+ # R2 fixtures (codex R2): mixed validity never drives lifecycle · indentless list flagged ·
160
+ # <...> / %20 / balanced-paren destinations · past_cap by the link's own offset
161
+ R="$T/r"; mkdir -p "$R"
162
+ rw(){ printf '%s\n' "$2" > "$R/$1"; }
163
+ rw mix_cold.md "$hdr
164
+ type: feedback
165
+ hits:
166
+ - 2026-08-01 | valid old
167
+ - 2027-01-01 | future
168
+ ---"
169
+ rw mix_prom.md "$hdr
170
+ type: feedback
171
+ hits:
172
+ - 2026-10-01 | a
173
+ - 2026-10-02 | b
174
+ - 2026-10-03 | c
175
+ - nonsense line
176
+ ---"
177
+ rw flat.md "$hdr
178
+ type: feedback
179
+ hits:
180
+ - 2026-10-01 | indentless
181
+ ---"
182
+ rw "my note.md" "$hdr
183
+ type: feedback
184
+ ---"
185
+ rw "sp name.md" "$hdr
186
+ type: feedback
187
+ ---"
188
+ rw "note(v2).md" "$hdr
189
+ type: feedback
190
+ ---"
191
+ rw MEMORY.md "- [m](mix_cold.md) [p](mix_prom.md) [f](flat.md)
192
+ - [a](<my note.md>) [b](sp%20name.md) [c](note(v2).md) [x](<gone note.md>) [y](gone(v2).md)"
193
+ JR="$(python3 "$HERE/memory_gc_report.py" "$R" --today 2026-10-15 --json)"
194
+ qr(){ printf '%s' "$JR" | "$PY" -c "import json,sys;d=json.load(sys.stdin);E={e['file']:e for e in d['entries']};print($1)"; }
195
+ eq "L21 valid-old + future hit: flagged, not cold" "$(qr "(E['mix_cold.md']['status'], d['cold'])")" "('HITS_MALFORMED', [])"
196
+ eq "L22 three valid + one malformed: no promotion" "$(qr "d['promote']")" "[]"
197
+ eq "L23 indentless hits item flagged, not silently dropped" "$(qr "(E['flat.md']['status'], E['flat.md']['age'])")" "('HITS_MALFORMED', None)"
198
+ eq "L24 <...>, %20 and balanced-paren destinations resolve" "$(qr "sorted(d['unlisted'])")" "[]"
199
+ eq "L25 their missing twins are dangling" "$(qr "sorted(x[0] for x in d['dangling'])")" "['gone note.md', 'gone(v2).md']"
200
+ JP="$(python3 "$HERE/memory_gc_report.py" "$R" --today 2026-10-15 --cap 22 --json)"
201
+ eq "L26 past_cap follows the link's own offset on a shared line" \
202
+ "$(printf '%s' "$JP" | "$PY" -c "import json,sys;E={e['file']:e for e in json.load(sys.stdin)['entries']};print(E['mix_cold.md']['past_cap'],E['mix_prom.md']['past_cap'])")" "False True"
203
+
204
+ # R3 (codex): two links on ONE line keep their link order, not filename order
205
+ Q="$T/q"; mkdir -p "$Q"; for f in z a; do printf -- '---\nmetadata:\n type: user\n---\n' > "$Q/$f.md"; done
206
+ printf -- '- [z](z.md) [a](a.md)\n' > "$Q/MEMORY.md"
207
+ eq "L27 same-line links keep link order" "$(python3 "$HERE/memory_gc_report.py" "$Q" --json | "$PY" -c "import json,sys;print(json.load(sys.stdin)['order'])")" "['z.md', 'a.md']"
208
+
209
+ echo "memory_gc_report lanes: $pass pass · $fail fail"
210
+ [ $fail -eq 0 ]
@@ -0,0 +1,193 @@
1
+ #!/usr/bin/env bash
2
+ # test_regression_guard_sibling_lanes.sh — Axis 1's «moved is not lost» sibling lookup.
3
+ #
4
+ # WHY (2026-10-16): CLAUDE.md became a ~95-line resident core and the full ruleset moved to
5
+ # knowledge/shared/harness-core/claude_md_full_reference.md. The guard's sibling lookup only knew
6
+ # SKILL.md <-> SKILL_detail.md, so the move read as 100% token loss and hard-blocked the commit.
7
+ # The pair was added to the same symmetric lookup. No lane covered the lookup before — not even the
8
+ # SKILL pair — so these lanes cover both pairs and both directions:
9
+ # moved into the sibling -> no M-tier (exit != 2)
10
+ # dropped from both -> M-tier block (exit 2) <- the lookup must not become a free pass
11
+ # plus a REVERT PROBE: the CLAUDE.md case is deleted from a copy of the guard and lane S1 must turn red.
12
+ #
13
+ # Usage: bash scripts/test_regression_guard_sibling_lanes.sh Exit: 0 = all behave; 1 = regression.
14
+
15
+ set -uo pipefail
16
+ . "$(dirname "${BASH_SOURCE[0]}")/fixture_guard_lib.sh" # fixtures never write the real repo
17
+ REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
18
+ GUARD="$REPO_ROOT/templates/regression_guard.sh"
19
+ T="$(fh_fixture_root "$(mktemp -d)")"
20
+ : "${T:?fixture root unset — refusing to run git in cwd}"
21
+ trap 'rm -rf "$T"' EXIT
22
+ FAIL=0
23
+ REF=knowledge/shared/harness-core/claude_md_full_reference.md
24
+
25
+ BODY='## Execution Steps
26
+ Step 0 read. Step 1 scan. Step 2 propose. Step 3 run.
27
+ ```bash
28
+ bash scripts/x.sh
29
+ ```
30
+ ```bash
31
+ bash scripts/y.sh
32
+ ```
33
+ ```bash
34
+ bash scripts/z.sh
35
+ ```
36
+ ## Done When
37
+ the gate says PASS or BLOCK.
38
+ M-tier and S-tier are defined in the guard.
39
+ '
40
+
41
+ # $1=dir — base commit: CLAUDE.md and a skill both carry the tokens, no siblings yet
42
+ mkrepo() {
43
+ local d=$1
44
+ mkdir -p "$d/plugins/p/skills/s" "$d/knowledge/shared/harness-core"
45
+ git -C "$d" init -q && git -C "$d" config user.email t@t && git -C "$d" config user.name t
46
+ printf '# hub\n%s' "$BODY" > "$d/CLAUDE.md"
47
+ printf -- '---\nname: s\ndescription: d\n---\n# s\n%s' "$BODY" > "$d/plugins/p/skills/s/SKILL.md"
48
+ git -C "$d" add -A && git -C "$d" commit -q -m base
49
+ }
50
+
51
+ # $1=id $2=dir $3=guard $4=expect(block|pass)
52
+ run_lane() {
53
+ local id=$1 d=$2 g=$3 want=$4 rc out
54
+ out=$(cd "$d" && bash "$g" --staged 2>&1); rc=$?
55
+ if [ -z "$out" ]; then echo " ❌ $id — guard printed nothing (instrument silence, not a pass)"; FAIL=1; return; fi
56
+ if [ "$rc" -ne 0 ] && [ "$rc" -ne 1 ] && [ "$rc" -ne 2 ]; then
57
+ echo " ❌ $id — guard rc=$rc (could not run)"; printf '%s\n' "$out" | tail -3 | sed 's/^/ /'; FAIL=1; return
58
+ fi
59
+ if [ "$want" = block ] && [ "$rc" -eq 2 ]; then echo " ✅ $id — M-tier block (rc=2)"
60
+ elif [ "$want" = pass ] && [ "$rc" -ne 2 ] && grep -q "moved to" <<<"$out"; then echo " ✅ $id — no M-tier, move recognised (rc=$rc)"
61
+ elif [ "$want" = pass ] && [ "$rc" -ne 2 ]; then echo " ❌ $id — rc=$rc but no «moved to» line: the pair was never examined (a SKIP is not a pass)"; FAIL=1
62
+ else echo " ❌ $id — expected $want, got rc=$rc"; printf '%s\n' "$out" | grep -E 'M-TIER|moved' | head -4 | sed 's/^/ /'; FAIL=1; fi
63
+ }
64
+
65
+ echo "── regression_guard sibling lanes ──"
66
+
67
+ # S1: CLAUDE.md slimmed, content moved to the reference file -> move, not loss
68
+ d=$T/s1; mkrepo "$d"
69
+ printf '# hub\nresident core only.\n' > "$d/CLAUDE.md"
70
+ printf '# full reference\n%s' "$BODY" > "$d/$REF"
71
+ git -C "$d" add -A
72
+ run_lane "S1 CLAUDE.md -> reference move" "$d" "$GUARD" pass
73
+
74
+ # S2: CLAUDE.md slimmed, reference file lacks the content -> real loss still blocks
75
+ d=$T/s2; mkrepo "$d"
76
+ printf '# hub\nresident core only.\n' > "$d/CLAUDE.md"
77
+ printf '# full reference\nunrelated.\n' > "$d/$REF"
78
+ git -C "$d" add -A
79
+ run_lane "S2 CLAUDE.md loss with empty reference" "$d" "$GUARD" block
80
+
81
+ # S3: CLAUDE.md slimmed, no reference file at all -> blocks
82
+ d=$T/s3; mkrepo "$d"
83
+ printf '# hub\nresident core only.\n' > "$d/CLAUDE.md"
84
+ git -C "$d" add -A
85
+ run_lane "S3 CLAUDE.md loss, reference absent" "$d" "$GUARD" block
86
+
87
+ # S4: the older pair still works — SKILL.md content moved to SKILL_detail.md
88
+ d=$T/s4; mkrepo "$d"
89
+ printf -- '---\nname: s\ndescription: d\n---\n# s\nsee detail.\n' > "$d/plugins/p/skills/s/SKILL.md"
90
+ printf '# detail\n%s' "$BODY" > "$d/plugins/p/skills/s/SKILL_detail.md"
91
+ git -C "$d" add -A
92
+ run_lane "S4 SKILL.md -> SKILL_detail.md move" "$d" "$GUARD" pass
93
+
94
+ # S5: a file that is NOT a pair member does not borrow the reference's content
95
+ d=$T/s5; mkrepo "$d"
96
+ printf '# agents\n%s' "$BODY" > "$d/AGENTS.md"; git -C "$d" add AGENTS.md; git -C "$d" commit -q -m agents
97
+ printf '# agents\nshort.\n' > "$d/AGENTS.md"
98
+ printf '# full reference\n%s' "$BODY" > "$d/$REF"
99
+ git -C "$d" add -A
100
+ out=$(cd "$d" && bash "$GUARD" --staged 2>&1)
101
+ if grep -q "AGENTS.md" <<<"$out" && ! grep -qE "moved to SKILL_detail.md.*" <<<"$out"; then
102
+ sec=$(grep -A30 "AGENTS.md" <<<"$out"); if [[ "$sec" == *"M-TIER"* ]]; then echo " ✅ S5 AGENTS.md loss is not excused by the reference file"
103
+ else echo " ❌ S5 AGENTS.md token loss produced no M-TIER line"; FAIL=1; fi
104
+ else echo " ❌ S5 AGENTS.md was not examined, or was treated as a move"; FAIL=1; fi
105
+
106
+ # S6: the sibling ALREADY held the content (unchanged this commit) -> deleting from CLAUDE.md still blocks
107
+ d=$T/s6; mkrepo "$d"
108
+ printf '# full reference\n%s' "$BODY" > "$d/$REF"; git -C "$d" add -A; git -C "$d" commit -q -m ref
109
+ printf '# hub\nresident core only.\n' > "$d/CLAUDE.md"
110
+ git -C "$d" add -A
111
+ run_lane "S6 unchanged sibling does not mask a CLAUDE.md loss" "$d" "$GUARD" block
112
+
113
+ # S7: both files lose the content in the same commit -> blocks
114
+ d=$T/s7; mkrepo "$d"
115
+ printf '# hub\n%s%s' "$BODY" "$BODY" > "$d/CLAUDE.md"; printf '# full reference\n%s%s' "$BODY" "$BODY" > "$d/$REF"; git -C "$d" add -A; git -C "$d" commit -q -m two
116
+ printf '# hub\n%s' "$BODY" > "$d/CLAUDE.md"; printf '# full reference\n%s' "$BODY" > "$d/$REF"
117
+ git -C "$d" add -A
118
+ run_lane "S7 simultaneous loss in both files" "$d" "$GUARD" block
119
+
120
+ # S8: reverse direction — reference content moved back into CLAUDE.md -> move (reference side examined)
121
+ d=$T/s8; mkrepo "$d"
122
+ printf '# hub\nresident core only.\n' > "$d/CLAUDE.md"; printf '# full reference\n%s' "$BODY" > "$d/$REF"
123
+ git -C "$d" add -A; git -C "$d" commit -q -m split
124
+ printf '# hub\n%s' "$BODY" > "$d/CLAUDE.md"; printf '# full reference\nmoved back.\n' > "$d/$REF"
125
+ git -C "$d" add -A
126
+ out=$(cd "$d" && bash "$GUARD" --staged 2>&1)
127
+ sec=$(grep -A60 "claude_md_full_reference.md" <<<"$out"); if [[ "$sec" == *"moved to"* ]] && [[ "$sec" != *"M-TIER"* ]]; then
128
+ echo " ✅ S8 reference -> CLAUDE.md reverse move recognised"
129
+ else echo " ❌ S8 reverse move not recognised on the reference side"; FAIL=1; fi
130
+
131
+ # S9 (F2 isolated): the sibling already holds a «## Trigger Phrases» heading, unchanged; CLAUDE.md drops
132
+ # its own. No F4 token is involved, so only the section check can catch it.
133
+ d=$T/s9; mkrepo "$d"
134
+ printf '# hub\n## Trigger Phrases\n- say hi\n' > "$d/CLAUDE.md"; printf '# full reference\n## Trigger Phrases\n- say hi\n' > "$d/$REF"
135
+ git -C "$d" add -A; git -C "$d" commit -q -m trig
136
+ printf '# hub\nno triggers.\n- say hi\n' > "$d/CLAUDE.md"; git -C "$d" add -A
137
+ out=$(cd "$d" && bash "$GUARD" --staged 2>&1)
138
+ if grep -q "'Triggers' section group dropped" <<<"$out"; then echo " ✅ S9 F2: unchanged sibling heading does not excuse a dropped section"
139
+ else echo " ❌ S9 F2: dropped section was excused (no «section group dropped» line)"; FAIL=1; fi
140
+
141
+ # S10 (F3 isolated): sibling already holds fences, unchanged; CLAUDE.md loses all of its fences
142
+ d=$T/s10; mkrepo "$d"
143
+ F6=$(printf '```bash\nx\n```\n```bash\ny\n```\n```bash\nz\n```\n')
144
+ printf '# hub\n%s\n' "$F6" > "$d/CLAUDE.md"; printf '# full reference\n%s\n' "$F6" > "$d/$REF"
145
+ git -C "$d" add -A; git -C "$d" commit -q -m fences
146
+ printf '# hub\nno code.\n' > "$d/CLAUDE.md"; git -C "$d" add -A
147
+ out=$(cd "$d" && bash "$GUARD" --staged 2>&1)
148
+ if grep -q "code blocks reduced" <<<"$out"; then echo " ✅ S10 F3: unchanged sibling fences do not excuse lost code blocks"
149
+ else echo " ❌ S10 F3: lost code blocks were excused"; FAIL=1; fi
150
+
151
+ # R1: revert probe — delete the CLAUDE.md case from a copy of the guard; S1 must now block
152
+ G2=$T/guard_reverted.sh
153
+ grep -v '^ CLAUDE.md) ' "$GUARD" > "$G2"
154
+ if cmp -s "$GUARD" "$G2"; then echo " ❌ R1 revert probe: the mutation did not apply (pattern drift) — HARNESS-ERROR"; FAIL=1
155
+ else
156
+ d=$T/r1; mkrepo "$d"
157
+ printf '# hub\nresident core only.\n' > "$d/CLAUDE.md"
158
+ printf '# full reference\n%s' "$BODY" > "$d/$REF"
159
+ git -C "$d" add -A
160
+ run_lane "R1 revert probe: without the pair, S1 blocks" "$d" "$G2" block
161
+ fi
162
+
163
+ # R2: revert probe — credit the sibling's whole total again (the old behaviour); S6 must turn green-wrong
164
+ G3=$T/guard_total.sh
165
+ sed 's/a=\${a:-0}; b=\${b:-0}; \[ "\$a" -gt "\$b" \] \&\& echo \$((a - b)) || echo 0/a=${a:-0}; echo "$a"/' "$GUARD" > "$G3"
166
+ if cmp -s "$GUARD" "$G3"; then echo " ❌ R2 revert probe: the mutation did not apply (pattern drift) — HARNESS-ERROR"; FAIL=1
167
+ else
168
+ d=$T/r2; mkrepo "$d"
169
+ printf '# full reference\n%s' "$BODY" > "$d/$REF"; git -C "$d" add -A; git -C "$d" commit -q -m ref
170
+ printf '# hub\nresident core only.\n' > "$d/CLAUDE.md"; git -C "$d" add -A
171
+ rc=0; out=$(cd "$d" && bash "$G3" --staged 2>&1) || rc=$?
172
+ if { [ "$rc" -eq 0 ] || [ "$rc" -eq 1 ]; } && grep -q "moved to" <<<"$out"; then echo " ✅ R2 revert probe: whole-total credit lets S6 through as a «move» (rc=$rc) — S6 is what catches it"
173
+ else echo " ❌ R2 revert probe: S6 still blocked with whole-total credit — S6 is not anchoring the gain rule"; FAIL=1; fi
174
+ fi
175
+
176
+ # R3: revert probe — drop the reverse arm; S8 must fail
177
+ G4=$T/guard_noreverse.sh
178
+ grep -v 'claude_md_full_reference.md) sib="CLAUDE.md"' "$GUARD" > "$G4"
179
+ if cmp -s "$GUARD" "$G4"; then echo " ❌ R3 revert probe: the mutation did not apply (pattern drift) — HARNESS-ERROR"; FAIL=1
180
+ else
181
+ d=$T/r3; mkrepo "$d"
182
+ printf '# hub\nresident core only.\n' > "$d/CLAUDE.md"; printf '# full reference\n%s' "$BODY" > "$d/$REF"
183
+ git -C "$d" add -A; git -C "$d" commit -q -m split
184
+ printf '# hub\n%s' "$BODY" > "$d/CLAUDE.md"; printf '# full reference\nmoved back.\n' > "$d/$REF"; git -C "$d" add -A
185
+ rc=0; out=$(cd "$d" && bash "$G4" --staged 2>&1) || rc=$?
186
+ if [ "$rc" -gt 2 ] || ! grep -q "claude_md_full_reference.md" <<<"$out"; then echo " ❌ R3 revert probe: mutated guard did not run or never examined the reference (rc=$rc) — HARNESS-ERROR"; FAIL=1
187
+ elif sec=$(grep -A60 "claude_md_full_reference.md" <<<"$out"); [[ "$sec" == *"moved to"* ]]; then echo " ❌ R3 revert probe: reverse move still recognised without the reverse arm"; FAIL=1
188
+ else echo " ✅ R3 revert probe: without the reverse arm the reference side no longer sees a move"; fi
189
+ fi
190
+
191
+ echo
192
+ if [ "$FAIL" -eq 0 ]; then echo "ALL regression_guard sibling lanes behave."; exit 0; fi
193
+ echo "regression_guard sibling lanes: FAIL"; exit 1
@@ -425,11 +425,29 @@ print('OK')
425
425
  # too, the reverse consolidation (detail → SKILL.md, e.g. un-splitting a skill) would otherwise
426
426
  # read as content loss in the detail file and fire a false positive on exactly the refactor
427
427
  # salience-splitter is designed to reverse.
428
- detail_content=""
428
+ # The resident/reference pair (2026-10-16): CLAUDE.md keeps a ~95-line resident core and the full
429
+ # ruleset lives in claude_md_full_reference.md with section names unchanged — the same split
430
+ # shape as SKILL.md/SKILL_detail.md, so it gets the same symmetric lookup. Only these two exact
431
+ # paths pair; any other file keeps an empty sibling, so this does not widen what counts as a move.
432
+ #
433
+ # 🟥 Credit only what the sibling GAINED in this change (2026-10-16, cross-family codex HIGH).
434
+ # The lookup used to compare against the sibling's CURRENT total, so a sibling that already held
435
+ # the content excused any later deletion — reproduced: an unchanged reference with matching tokens
436
+ # let CLAUDE.md lose its rules and PASS, and «both files lose half» (2+2 → 1+1) also passed. The
437
+ # SKILL pair had the same hole. Now every count below is after(sibling) − before(sibling), floored
438
+ # at 0: content counts as moved only if it arrived in the sibling in this same change.
439
+ detail_content=""; detail_before=""; sib=""
429
440
  case "$f" in
430
- */SKILL.md) detail_content=$(read_after "$(dirname "$f")/SKILL_detail.md") ;;
431
- */SKILL_detail.md) detail_content=$(read_after "$(dirname "$f")/SKILL.md") ;;
441
+ */SKILL.md) sib="$(dirname "$f")/SKILL_detail.md" ;;
442
+ */SKILL_detail.md) sib="$(dirname "$f")/SKILL.md" ;;
443
+ CLAUDE.md) sib="knowledge/shared/harness-core/claude_md_full_reference.md" ;;
444
+ knowledge/shared/harness-core/claude_md_full_reference.md) sib="CLAUDE.md" ;;
432
445
  esac
446
+ if [ -n "$sib" ]; then detail_content=$(read_after "$sib"); detail_before=$(read_before "$sib"); fi
447
+ _gain() { # $1=counter fn $2=pattern -> max(0, count in sibling after − count in sibling before)
448
+ local a b; a=$("$1" "$detail_content" "$2"); b=$("$1" "$detail_before" "$2")
449
+ a=${a:-0}; b=${b:-0}; [ "$a" -gt "$b" ] && echo $((a - b)) || echo 0
450
+ }
433
451
 
434
452
  # Deprecation/tombstone exemption (stub-shaped): a file soft-deleted into a small pointer
435
453
  # stub. Content loss is the INTENT (mirrors the file-deletion skip above), so content-
@@ -489,14 +507,14 @@ print('OK')
489
507
  before=$(count_regex_in "$before_content" "$pattern")
490
508
  after=$(count_regex_in "$after_content" "$pattern")
491
509
  detail=0
492
- [ -n "$detail_content" ] && detail=$(count_regex_in "$detail_content" "$pattern")
510
+ [ -n "$detail_content" ] && detail=$(_gain count_regex_in "$pattern")
493
511
  combined=$((after + detail))
494
512
  if [ "$before" -gt 0 ] && [ "$combined" -lt "$before" ]; then
495
513
  echo " ❌ M-TIER '$label' section group dropped ($before → $combined)"
496
514
  M_TIER=$((M_TIER + 1))
497
515
  elif [ "$before" -gt 0 ] && [ "$after" -lt "$before" ]; then
498
516
  if [ "$detail" -gt 0 ]; then
499
- echo " ℹ️ '$label' section moved to SKILL_detail.md ($before → $after + $detail in detail)"
517
+ echo " ℹ️ '$label' section moved to ${sib##*/} ($before → $after + $detail in detail)"
500
518
  verbose "suppressed section loss: sibling SKILL_detail.md preserves '$label' section header count"
501
519
  else
502
520
  echo " ℹ️ '$label' section heading renamed within known synonym group ($before → $after)"
@@ -513,7 +531,7 @@ print('OK')
513
531
  group_before=$(count_regex_in "$before_content" "$group_pattern")
514
532
  group_after=$(count_regex_in "$after_content" "$group_pattern")
515
533
  group_detail=0
516
- [ -n "$detail_content" ] && group_detail=$(count_regex_in "$detail_content" "$group_pattern")
534
+ [ -n "$detail_content" ] && group_detail=$(_gain count_regex_in "$group_pattern")
517
535
  group_combined=$((group_after + group_detail))
518
536
  [ "$group_before" -gt 0 ] && [ "$group_combined" -ge "$group_before" ] || return
519
537
  for name in "$@"; do
@@ -521,7 +539,7 @@ print('OK')
521
539
  before=$(count_regex_in "$before_content" "$exact_pattern")
522
540
  after=$(count_regex_in "$after_content" "$exact_pattern")
523
541
  detail=0
524
- [ -n "$detail_content" ] && detail=$(count_regex_in "$detail_content" "$exact_pattern")
542
+ [ -n "$detail_content" ] && detail=$(_gain count_regex_in "$exact_pattern")
525
543
  if [ "$before" -gt 0 ] && [ $((after + detail)) -lt "$before" ]; then
526
544
  verbose "suppressed dropped heading '$name': '$group_label' known-synonym group is preserved ($group_before → $group_combined)"
527
545
  fi
@@ -547,7 +565,7 @@ print('OK')
547
565
  [ -n "$header" ] || continue
548
566
  before=$(count_exact_line_in "$before_content" "$header")
549
567
  after=$(count_exact_line_in "$after_content" "$header")
550
- detail=$(count_exact_line_in "$detail_content" "$header")
568
+ detail=$(_gain count_exact_line_in "$header")
551
569
  if [ "$before" -gt 0 ] && [ "$after" -lt "$before" ] && [ $((after + detail)) -ge "$before" ]; then
552
570
  verbose "suppressed section-header reduction: '$header' moved to sibling SKILL_detail.md"
553
571
  fi
@@ -560,12 +578,12 @@ print('OK')
560
578
  before_code=$(count_in "$before_content" '^```')
561
579
  after_code=$(count_in "$after_content" '^```')
562
580
  detail_code=0
563
- [ -n "$detail_content" ] && detail_code=$(count_in "$detail_content" '^```')
581
+ [ -n "$detail_content" ] && detail_code=$(_gain count_in '^```')
564
582
  if [ "$before_code" -gt 0 ]; then
565
583
  combined_code=$((after_code + detail_code))
566
584
  delta=$((before_code - combined_code))
567
585
  if [ "$after_code" -lt "$before_code" ] && [ "$combined_code" -ge "$before_code" ]; then
568
- echo " ℹ️ code blocks moved to SKILL_detail.md ($before_code → $after_code + $detail_code in detail)"
586
+ echo " ℹ️ code blocks moved to ${sib##*/} ($before_code → $after_code + $detail_code in detail)"
569
587
  verbose "suppressed code-block reduction: sibling SKILL_detail.md preserves fenced-block count"
570
588
  fi
571
589
  if [ "$delta" -gt 4 ]; then
@@ -588,9 +606,9 @@ print('OK')
588
606
  after=$(count_in "$after_content" "$token")
589
607
  if [ "$before" -gt 0 ] && [ "$after" -lt "$before" ]; then
590
608
  if [ -n "$detail_content" ]; then
591
- in_detail=$(count_in "$detail_content" "$token")
609
+ in_detail=$(_gain count_in "$token")
592
610
  if [ $((after + in_detail)) -ge "$before" ]; then
593
- echo " ℹ️ token '$token' moved to SKILL_detail.md ($before → $after + $in_detail in detail)"
611
+ echo " ℹ️ token '$token' moved to ${sib##*/} ($before → $after + $in_detail in detail)"
594
612
  verbose "suppressed token reduction: sibling SKILL_detail.md preserves '$token' count"
595
613
  continue
596
614
  fi