@chrono-meta/fh-gate 3.15.0 → 3.17.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 (60) hide show
  1. package/.claude-plugin/marketplace.json +4 -4
  2. package/AGENTS.md +27 -0
  3. package/CATALOG.md +60 -0
  4. package/CLAUDE.md +5 -0
  5. package/README.ja.md +2 -2
  6. package/README.ko.md +2 -2
  7. package/README.md +2 -2
  8. package/README.zh.md +2 -2
  9. package/docs/OUTPUT_EVIDENCE.md +1 -1
  10. package/docs/codex-compat.md +24 -0
  11. package/knowledge/shared/harness-core/checkout_layer_drift.md +301 -0
  12. package/knowledge/shared/learnings/subagent_invocations_log.yaml +66 -0
  13. package/package.json +13 -1
  14. package/plugins/fh-commons/.claude-plugin/plugin.json +1 -1
  15. package/plugins/fh-meta/.claude-plugin/plugin.json +1 -1
  16. package/plugins/fh-meta/CHANGELOG.md +42 -0
  17. package/plugins/fh-preprep/.claude-plugin/plugin.json +1 -1
  18. package/plugins/fh-preprep/skills/preprep/SKILL.md +5 -0
  19. package/plugins/fh-preprep/skills/preprep/lane_font_embed.py +235 -0
  20. package/plugins/fh-preprep/skills/preprep/ooxml/gate.py +67 -5
  21. package/plugins/fh-preprep/skills/preprep/ooxml/test_gate_exitcodes.py +136 -0
  22. package/plugins/fh-preprep/skills/preprep/preprep.py +16 -1
  23. package/plugins/fh-preprep/skills/preprep/presentation_checklist.md +108 -6
  24. package/plugins/fh-preprep/skills/preprep/safe_install.py +22 -3
  25. package/plugins/fh-preprep/skills/preprep/surfaces.example.yaml +11 -0
  26. package/plugins/fh-preprep/skills/preprep/test_lane_font_embed.py +117 -0
  27. package/plugins/fh-preprep/skills/preprep/test_safe_install_app_xml.py +77 -0
  28. package/plugins/fh-qp/.claude-plugin/plugin.json +1 -1
  29. package/scripts/count_check.sh +46 -14
  30. package/scripts/daily_report.sh +17 -1
  31. package/scripts/env_layer_fingerprint.sh +309 -0
  32. package/scripts/gate_bootstrap_ephemeral.sh +248 -0
  33. package/scripts/governor_board.sh +841 -0
  34. package/scripts/map_postprocess.py +89 -4
  35. package/scripts/multibyte_bracket_lint.sh +135 -0
  36. package/scripts/outbound_pr_gate.sh +12 -0
  37. package/scripts/package_coverage_check.sh +34 -0
  38. package/scripts/selfcheck.sh +263 -0
  39. package/scripts/session_close_check.sh +96 -1
  40. package/scripts/stale_ref_scan.py +511 -0
  41. package/scripts/test_count_check_decl_lanes.sh +176 -0
  42. package/scripts/test_env_layer_fingerprint_lanes.sh +192 -0
  43. package/scripts/test_gate_bootstrap_ephemeral_lanes.sh +262 -0
  44. package/scripts/test_locale_invariance_lanes.sh +581 -0
  45. package/scripts/test_map_postprocess_lanes.sh +84 -4
  46. package/scripts/test_marker_crossfamily_lanes.sh +5 -1
  47. package/scripts/test_marker_defense_lanes.sh +5 -1
  48. package/scripts/test_marker_standpoint_lanes.sh +5 -1
  49. package/scripts/test_marker_thirdparty_lanes.sh +5 -1
  50. package/scripts/test_multibyte_bracket_lint_lanes.sh +107 -0
  51. package/scripts/test_outbound_pr_gate_lanes.sh +133 -0
  52. package/scripts/test_preprep_drift_anchor.sh +34 -9
  53. package/scripts/test_preprep_drift_anchor_lanes.sh +64 -2
  54. package/scripts/test_session_close_chain_lanes.sh +45 -0
  55. package/scripts/test_stale_ref_close_lanes.sh +197 -0
  56. package/scripts/test_stale_ref_scan_lanes.sh +134 -0
  57. package/scripts/test_worktree_reclaim_lanes.sh +267 -1
  58. package/scripts/worktree_reclaim.sh +246 -11
  59. package/templates/.git-hooks/pre-commit +108 -27
  60. package/templates/settings.PreToolUse.snippet.json +54 -1
@@ -61,8 +61,274 @@ OUT="$(bash "$SUT" "$M" 2>&1)"; RC=$?; [ "$RC" -eq 2 ] && ok "W5 main checkout a
61
61
  OUT="$(bash "$SUT" "$T" 2>&1)"; RC=$?; [ "$RC" -eq 2 ] && ok "W5b non-repo dir → rc=2" || ng "W5b rc=$RC (기대 2)"
62
62
  OUT="$(bash "$SUT" "$W" --bogus 2>&1)"; RC=$?; [ "$RC" -eq 2 ] && ok "W5c unknown flag → rc=2" || ng "W5c rc=$RC (기대 2)"
63
63
  OUT="$(bash "$SUT" 2>&1)"; RC=$?; [ "$RC" -eq 2 ] && ok "W5d no argument → rc=2" || ng "W5d rc=$RC (기대 2)"
64
+ # 🟥 W5e 는 2026-09-21 에 기대값이 뒤집혔다. 종전 판은 «tracks/ 없음 → rc=0 회수할 것 없음» 을
65
+ # **옳은 동작으로 박아** 뒀는데, 그게 결함이다 — 스크립트가 tracks/ 만 보던 시절의 기대값이
66
+ # 레인에 화석으로 남아 거짓 초록을 인증하고 있었다. tracks/ 가 없으면 «그 구역이 빈» 것이지
67
+ # «워크트리에 아무것도 없는» 것이 아니다. 지금은 진짜로 비어 있을 때만 rc=0 이다.
64
68
  mk_pair "$T/c"; rm -rf "$T/c/wt/tracks"; OUT="$(bash "$SUT" "$T/c/wt" 2>&1)"; RC=$?
65
- [ "$RC" -eq 0 ] && ok "W5e worktree without tracks/ → rc=0 nothing to reclaim" || ng "W5e rc=$RC (기대 0)"
69
+ [ "$RC" -eq 0 ] && ok "W5e worktree with no tracks/ AND no other artifact → rc=0" || ng "W5e rc=$RC (기대 0)"
70
+
71
+ echo "── W6 범위: «안 본 것» 을 «없는 것» 으로 렌더하나 (2026-09-21 실측) ──"
72
+ # WHY: 정책렌즈 워크트리가 `scripts/fixtures/…`(52파일)과 `scripts/score_policy_lens.sh` 를
73
+ # untracked 로만 들고 있었다. tracks/ 만 보던 스크립트는 «only-in-worktree: 0» 을 내고
74
+ # **«✅ safe to: git worktree remove»** 를 찍었다 — 비가역 표면에서 파괴를 «승인» 한 것이다.
75
+
76
+ mk_pair "$T/f"; M="$T/f/main"; W="$T/f/wt"
77
+ mkdir -p "$W/tracks/_meta" "$W/scripts/fixtures/kp" # tracks/ 는 있고 «비어 있다» = 순수 얼굴
78
+ echo scorer > "$W/scripts/score_policy_lens.sh"; echo fx > "$W/scripts/fixtures/kp/a.txt"
79
+ OUT="$(bash "$SUT" "$W" 2>&1)"; RC=$?
80
+ case "$RC:$OUT" in
81
+ 0:*"safe to"*) ng "W6 tracks/ 밖 산출 2건인데 «safe to remove» 를 찍었다 — 거짓 초록" ;;
82
+ 0:*) ng "W6 rc=0 (기대 비영) — 제거를 막지 않는다" ;;
83
+ *"score_policy_lens.sh"*) ok "W6 tracks/ 밖 untracked 산출을 이름으로 세우고 제거를 안 승인한다 (rc=$RC)" ;;
84
+ *) ng "W6 rc=$RC 인데 출력에 파일명이 없다 — 왜 막는지 안 알려준다" ;;
85
+ esac
86
+ [ ! -e "$M/scripts/score_policy_lens.sh" ] \
87
+ && ok "W6b OUTSIDE 는 자동 복사 «안» 한다 (목적지는 판단이지 기본값이 아니다)" \
88
+ || ng "W6b OUTSIDE 를 본 체크아웃에 멋대로 옮겼다"
89
+
90
+ mk_pair "$T/g"; W="$T/g/wt"; rm -rf "$W/tracks"; echo art > "$W/leftover.md"
91
+ OUT="$(bash "$SUT" "$W" 2>&1)"; RC=$?
92
+ case "$RC:$OUT" in
93
+ 0:*"nothing to reclaim"*) ng "W6c tracks/ 부재를 «회수할 것 없음» 으로 읽었다 (:42 조기 exit)" ;;
94
+ 0:*) ng "W6c rc=0 — leftover.md 가 있는데 제거를 승인했다" ;;
95
+ *"leftover.md"*) ok "W6c tracks/ 가 없어도 다른 산출을 본다 (rc=$RC)" ;;
96
+ *) ng "W6c rc=$RC / 출력에 leftover.md 없음" ;;
97
+ esac
98
+
99
+ # 🟥 과차단 컨트롤 — 재생성 가능한 것으로 막으면 override 를 훈련시킨다(= 게이트 무장해제).
100
+ mk_pair "$T/h"; W="$T/h/wt"; mkdir -p "$W/tracks/_meta" "$W/node_modules/x" "$W/__pycache__" "$W/dist"
101
+ printf 'tracks/\nnode_modules/\n__pycache__/\ndist/\n.DS_Store\n*.pyc\n' > "$W/.gitignore"
102
+ echo j > "$W/node_modules/x/p.js"; echo c > "$W/__pycache__/m.pyc"; echo d > "$W/dist/out.js"
103
+ echo s > "$W/.DS_Store"; echo y > "$W/stale.pyc"
104
+ OUT="$(bash "$SUT" "$W" 2>&1)"; RC=$?
105
+ [ "$RC" -eq 0 ] && ok "W6d 과차단 컨트롤: node_modules·__pycache__·dist·.DS_Store·*.pyc 는 안 막는다" \
106
+ || ng "W6d 재생성 가능한 것으로 막았다 (rc=$RC) — override 훈련 방향"
107
+ # 🟥 그 컨트롤이 «아무거나 다 통과» 라서 초록인 게 아님을 같이 증명한다(죽은 컨트롤 방지).
108
+ echo real > "$W/keepme.md"; OUT="$(bash "$SUT" "$W" 2>&1)"; RC=$?
109
+ [ "$RC" -ne 0 ] && printf '%s' "$OUT" | grep -q "keepme.md" \
110
+ && ok "W6e 같은 트리에 진짜 산출 1개를 더하면 막는다 — W6d 가 죽은 컨트롤이 아니다" \
111
+ || ng "W6e rc=$RC — 제외 목록이 전부를 삼키고 있다"
112
+
113
+ # --apply 로도 OUTSIDE 는 안 사라진다: tracks/ 는 회수하고, 밖의 것은 여전히 사람 몫.
114
+ mk_pair "$T/i"; M="$T/i/main"; W="$T/i/wt"; mkdir -p "$W/tracks/_meta"
115
+ echo sig > "$W/tracks/_meta/sig.md"; echo out > "$W/outside.md"
116
+ OUT="$(bash "$SUT" "$W" --apply 2>&1)"; RC=$?
117
+ if [ -f "$M/tracks/_meta/sig.md" ] && [ ! -e "$M/outside.md" ] && [ "$RC" -ne 0 ]; then
118
+ ok "W6f --apply: tracks/ 는 회수, OUTSIDE 는 안 옮기고 제거 승인도 안 한다 (rc=$RC)"
119
+ else
120
+ ng "W6f copied=$([ -f "$M/tracks/_meta/sig.md" ] && echo 1 || echo 0) leaked=$([ -e "$M/outside.md" ] && echo 1 || echo 0) rc=$RC"
121
+ fi
122
+
123
+ echo "── W7 cross-family 가 잡은 것들 (2026-09-21, 적대검증 S1·A3) ──"
124
+ # 🟥 W6 가 전부 초록이었는데도 아래 넷이 살아 있었다. 원인 하나: mk_pair 의 .gitignore 가
125
+ # `tracks/` 한 줄뿐이라 픽스처에 ⓐ `!!` 접두 ⓑ ignored 디렉터리 ⓒ tracked-modified 줄 이
126
+ # **원리적으로 존재하지 않았다.** 계기가 대상과 다른 형태였다([[feedback_instrument_blindspot_correlated_with_arm]]).
127
+
128
+ # W7a 🟥 S-1 — 열거기가 죽으면 «빈 결과» 가 «깨끗함» 으로 읽히나. 실측 재현: git rc=128 · script rc=0 · «safe to».
129
+ mk_pair "$T/j"; W="$T/j/wt"; mkdir -p "$W/tracks/_meta"
130
+ G="$(git -C "$W" rev-parse --git-dir 2>/dev/null)"; printf 'garbage' > "$G/index"
131
+ OUT="$(bash "$SUT" "$W" 2>&1)"; RC=$?
132
+ if printf '%s' "$OUT" | grep -q "safe to"; then
133
+ ng "W7a 열거기가 죽었는데 «safe to remove» 를 찍었다 (rc=$RC) — 이 스크립트 자신의 병"
134
+ elif [ "$RC" -eq 10 ]; then ok "W7a git status 실패 → rc=10 harness-error (빈 결과를 «깨끗함» 으로 안 읽는다)"
135
+ else ng "W7a rc=$RC (기대 10)"; fi
136
+
137
+ # W7b 🟥 A-1 — `${_l#?? }` 의 `?` 가 glob 이라 모든 상태줄을 먹었다. tracked-modified 가 OUTSIDE 로 샜다.
138
+ mk_pair "$T/k"; W="$T/k/wt"; mkdir -p "$W/tracks/_meta"; echo more >> "$W/README.md"
139
+ OUT="$(bash "$SUT" "$W" 2>&1)"; RC=$?
140
+ if printf '%s' "$OUT" | grep -q "OUTSIDE README.md"; then
141
+ ng "W7b tracked 파일(README.md)이 «git will not carry this» 로 찍혔다 — 거짓 라벨 + 과차단"
142
+ elif [ "$RC" -eq 0 ]; then ok "W7b tracked-modified 는 OUTSIDE 가 아니다 (커밋하면 살아남는다)"
143
+ else ng "W7b rc=$RC (기대 0) — tracked 변경만 있는데 막았다"; fi
144
+
145
+ # W7c 🟥 A-3 — ignored(«규칙을 일부러 쓴 것») 은 나열하되 막지 않는다. 안 그러면 실제 레포에서 rc=1 이 영구가 되고
146
+ # «치울 수 없는 게이트» 가 `--force` 를 훈련시킨다(실측: fod 워크트리 `!!` 6줄, FH 본체는 세션마다 늘어난다).
147
+ mk_pair "$T/l"; W="$T/l/wt"; mkdir -p "$W/tracks/_meta" "$W/.claude"
148
+ # 🟥 초판 픽스처는 `.claude/.sentinel_abc` 라는 «지어낸 이름» 이었고, 그게 S-2 를 «옳음» 으로
149
+ # 동결했다 — 이름은 실물에서 뽑는다([[feedback_fixture_shape_from_artifact_not_mental_model]]).
150
+ printf 'tracks/\n.claude/.prior_art_prompted_*\n' > "$W/.gitignore"
151
+ echo s > "$W/.claude/.prior_art_prompted_abc123"
152
+ OUT="$(bash "$SUT" "$W" 2>&1)"; RC=$?
153
+ if [ "$RC" -eq 0 ] && printf '%s' "$OUT" | grep -q "SKIP .claude/.prior_art_prompted_abc123"; then
154
+ ok "W7c 세션 런타임 센티널은 «이름으로 나열하되 안 막는다» (rc=0)"
155
+ elif [ "$RC" -ne 0 ]; then ng "W7c 런타임 센티널로 막았다 (rc=$RC) — 영구 rc=1 · --force 훈련 방향"
156
+ else ng "W7c rc=0 인데 SKIP 목록에 이름이 없다 — 조용히 버렸다"; fi
157
+
158
+ # W7d 컨트롤 — W7c 가 «ignored 면 다 통과» 로 새지 않았나. 같은 트리에 untracked 를 하나 더하면 막아야 한다.
159
+ echo real > "$W/keep_me.md"; OUT="$(bash "$SUT" "$W" 2>&1)"; RC=$?
160
+ [ "$RC" -ne 0 ] && printf '%s' "$OUT" | grep -q "OUTSIDE keep_me.md" \
161
+ && ok "W7d untracked 는 여전히 막는다 — W7c 가 차단을 통째로 끄지 않았다" \
162
+ || ng "W7d rc=$RC — ignored 완화가 untracked 차단까지 껐다"
163
+
164
+ # W7e 🟥 A-2 — 제외 목록의 «과소차단» 방향이 무음이었다. 이제 SKIP 으로 세고 목록 파일에 남긴다.
165
+ mk_pair "$T/m"; M="$T/m/main"; W="$T/m/wt"; mkdir -p "$W/tracks/_meta" "$W/node_modules/x"
166
+ printf 'tracks/\nnode_modules/\n' > "$W/.gitignore" # 🟥 ignored 여야 SKIP (B-7: untracked 는 막는다)
167
+ echo j > "$W/node_modules/x/p.js"
168
+ OUT="$(bash "$SUT" "$W" 2>&1)"; RC=$?
169
+ L="$(ls -t "$M"/tracks/_meta/dispatch/reclaim_wt_*.txt 2>/dev/null | head -1)"
170
+ if [ "$RC" -eq 0 ] && printf '%s' "$OUT" | grep -q "non-blocking: skipped 1" \
171
+ && [ -n "$L" ] && grep -q "^SKIP node_modules/x/p.js" "$L"; then
172
+ ok "W7e 제외분은 «버리는» 게 아니라 «세고 목록에 남긴다» — 과소차단 방향이 더는 무음이 아니다"
173
+ else
174
+ ng "W7e rc=$RC · 요약에 skipped-regenerable 없음 또는 리스트에 SKIP 줄 없음"
175
+ fi
176
+
177
+ # W7f 🟥 B-4 — bash 3.2 호환 주장에 실행 팔이 0개였다. 빈 배열 경로를 /bin/bash 로 한 번 민다.
178
+ if [ -x /bin/bash ]; then
179
+ mk_pair "$T/n"; W="$T/n/wt"; rm -rf "$W/tracks"
180
+ OUT="$(/bin/bash "$SUT" "$W" 2>&1)"; RC=$?
181
+ [ "$RC" -eq 0 ] && ok "W7f /bin/bash(3.2) 로 빈 배열 전 경로 통과 — 주장이 실행으로 선다" \
182
+ || ng "W7f /bin/bash rc=$RC: $(printf '%s' "$OUT" | head -2)"
183
+ else
184
+ ng "W7f /bin/bash 가 없다 — 3.2 주장은 이 머신에서 미측정(NOT a pass)"
185
+ fi
186
+
187
+ # W7g 🟥 S-2 — ignored 인데 «지우면 아픈» 내용물. 1차 수리(«ignored 는 안 막는다»)가 판 구멍이다.
188
+ mk_pair "$T/o"; W="$T/o/wt"; mkdir -p "$W/tracks/_meta" "$W/knowledge/shared" "$W/outputs"
189
+ printf 'tracks/\nknowledge/**/*_paper_draft.md\noutputs/\n' > "$W/.gitignore"
190
+ echo draft > "$W/knowledge/shared/fh_paper_draft.md"; echo art > "$W/outputs/act2.png"
191
+ OUT="$(bash "$SUT" "$W" 2>&1)"; RC=$?
192
+ if printf '%s' "$OUT" | grep -q "safe to"; then
193
+ ng "W7g 미출간 초고·주행 산출을 두고 «safe to remove» 를 찍었다 (rc=$RC) — ignored 완화가 판 구멍"
194
+ elif [ "$RC" -ne 0 ] && printf '%s' "$OUT" | grep -q "fh_paper_draft.md"; then
195
+ ok "W7g ignored 라도 «화이트리스트 밖» 내용물은 막는다 (rc=$RC)"
196
+ else ng "W7g rc=$RC 인데 출력에 초고 이름이 없다"; fi
197
+
198
+ # W7h 🟥 A-5 — git 이 rc=0 으로 끝나면서 경고만 내는 «부분 열거». rc 만 보면 못 본다.
199
+ mk_pair "$T/q"; W="$T/q/wt"; mkdir -p "$W/tracks/_meta" "$W/blocked/inner"
200
+ echo real > "$W/blocked/inner/artifact.md"; chmod 000 "$W/blocked" 2>/dev/null
201
+ OUT="$(bash "$SUT" "$W" 2>&1)"; RC=$?
202
+ chmod 755 "$W/blocked" 2>/dev/null
203
+ # 🟥 초판은 `[ "$RC" -ne 0 ]` 하나였고, 그래서 **크래시(rc=1, `_p: unbound variable`)를 통과로
204
+ # 인증**하고 있었다. 비정상 종료와 «옳게 막힘» 이 레인에서 같은 값이 됐다. rc 값 그 자체 ·
205
+ # 기대 메시지 존재 · 「통과 문구」 부재 · 크래시 문자열 부재 넷을 같이 건다.
206
+ if printf '%s' "$OUT" | grep -q "safe to"; then
207
+ ng "W7h 읽기불가 디렉터리로 열거가 잘렸는데 «safe to remove» 를 찍었다 (rc=$RC)"
208
+ elif printf '%s' "$OUT" | grep -q "unbound variable"; then
209
+ ng "W7h 스크립트가 크래시했다 — 막힌 게 아니라 죽은 것이다 (rc=$RC)"
210
+ elif [ "$RC" -eq 10 ] && printf '%s' "$OUT" | grep -q "PARTIAL"; then
211
+ ok "W7h 부분 열거 → rc=10 «PARTIAL» (크래시도 초록도 아니다)"
212
+ else ng "W7h rc=$RC (기대 10) 또는 PARTIAL 문구 없음"; fi
213
+
214
+ # W7i 🟥 A-4 — SKIP 이 0 이 아닐 때 초록 문장이 그 사실을 데리고 나가나.
215
+ mk_pair "$T/r"; W="$T/r/wt"; mkdir -p "$W/tracks/_meta" "$W/node_modules"
216
+ printf 'tracks/\nnode_modules/\n' > "$W/.gitignore"; echo j > "$W/node_modules/p.js"
217
+ OUT="$(bash "$SUT" "$W" 2>&1)"; RC=$?
218
+ [ "$RC" -eq 0 ] && printf '%s' "$OUT" | grep -q "skipped as regenerable/sentinel" \
219
+ && ok "W7i 초록 문장이 «무엇을 건너뛰었는지» 를 데리고 나간다" \
220
+ || ng "W7i rc=$RC — «nothing left» 가 SKIP 을 가린다"
221
+
222
+ echo "── W8 3라운드 적대검증 (같은 계열 + 다른 계열 두 팔) ──"
223
+ # 🟥 셋 다 «2R 수리가 만든» 것이다. 1R→2R→3R 세 라운드 연속 같은 방향이었다.
224
+
225
+ # W8a 🟥 S-3 — 화이트리스트가 «undo 가 없는» 설정 파일을 통과시켰다(같은 계열 팔).
226
+ mk_pair "$T/s"; W="$T/s/wt"; mkdir -p "$W/tracks/_meta" "$W/.claude"
227
+ printf 'tracks/\n.claude/settings.json*\n.claude/settings.local.json*\n' > "$W/.gitignore"
228
+ echo '{"hooks":{}}' > "$W/.claude/settings.json"; echo '{"permissions":{}}' > "$W/.claude/settings.local.json"
229
+ # 🟥 4R 정정: 3R 은 이걸 «차단» 으로 고쳤는데 그게 A-3(영구 rc=1 → --force 훈련) 재발이었다.
230
+ # 실측이 결론을 바꿨다 — 갓 만든 워크트리는 ignored 파일이 **0건**이고, 워크트리의
231
+ # settings 는 «그 워크트리 세션이 만든 것» 이다. 그래서 차단도 무음 SKIP 도 아니고
232
+ # **CONFIG — 안 막되 초록 문장이 이름으로 데리고 나간다**.
233
+ OUT="$(bash "$SUT" "$W" 2>&1)"; RC=$?
234
+ if [ "$RC" -ne 0 ]; then
235
+ ng "W8a 워크트리-로컬 settings 로 막았다 (rc=$RC) — 거의 모든 워크트리에 있어 영구 차단이 된다"
236
+ elif printf '%s' "$OUT" | grep -q "CONFIG .claude/settings.local.json" \
237
+ && printf '%s' "$OUT" | grep -q "WILL BE DESTROYED"; then
238
+ ok "W8a 워크트리-로컬 settings 는 «안 막되 파괴된다고 이름으로» 말한다 (rc=0)"
239
+ else ng "W8a rc=0 인데 CONFIG 줄이나 «WILL BE DESTROYED» 경고가 없다 — 조용히 사라진다"; fi
240
+ # 컨트롤: `.bak` 은 여전히 통과해야 한다(진짜 재생성물)
241
+ rm -f "$W/.claude/settings.json" "$W/.claude/settings.local.json"
242
+ printf 'tracks/\n.claude/settings*.json.bak\n' > "$W/.gitignore"; echo x > "$W/.claude/settings.json.bak"
243
+ OUT="$(bash "$SUT" "$W" 2>&1)"; RC=$?
244
+ [ "$RC" -eq 0 ] && ok "W8b 컨트롤: «.bak» 은 통과한다 — 원본만 조인 것이지 통째로 막은 게 아니다" \
245
+ || ng "W8b «.bak» 까지 막았다 (rc=$RC) — 과차단"
246
+
247
+ # W8c 🟥 다른 계열 팔의 단독 발견 — 워크트리에만 있는 스크린샷 증거.
248
+ mk_pair "$T/t"; W="$T/t/wt"; mkdir -p "$W/tracks/_meta" "$W/.playwright-mcp"
249
+ printf 'tracks/\n.playwright-mcp/\n' > "$W/.gitignore"; echo shot > "$W/.playwright-mcp/evidence.png"
250
+ OUT="$(bash "$SUT" "$W" 2>&1)"; RC=$?
251
+ [ "$RC" -ne 0 ] && printf '%s' "$OUT" | grep -q "evidence.png" \
252
+ && ok "W8c 워크트리 전용 스크린샷 증거를 막는다" \
253
+ || ng "W8c rc=$RC — .playwright-mcp 가 «재생성 가능» 으로 통과했다"
254
+
255
+ # W8d 🟥 A-10 — 손실 클래스가 «regenerable» 로 라벨되고 같은 경로가 두 번 렌더됐다.
256
+ mk_pair "$T/u"; W="$T/u/wt"; mkdir -p "$W/tracks/_meta"; echo sig > "$W/tracks/_meta/x.md"
257
+ OUT="$(bash "$SUT" "$W" 2>&1)"; RC=$?
258
+ if printf '%s' "$OUT" | grep -q "SKIP tracks/"; then
259
+ ng "W8d tracks/ 파일이 «regenerable 로 건너뜀» 으로 보고됐다 — 이 도구가 지키려는 바로 그 클래스다"
260
+ elif [ "$RC" -ne 0 ] && printf '%s' "$OUT" | grep -q "ONLY _meta/x.md"; then
261
+ ok "W8d tracks/ 는 자기 구역에서만 판정된다 — 이중 렌더 없음 (rc=$RC)"
262
+ else ng "W8d rc=$RC / ONLY 줄 없음"; fi
263
+
264
+ # W8e 🟥 A-11 — `tracks/` 가 ignored «가 아닌» 소비자 레포. 레인 픽스처엔 이 형태가 없었다.
265
+ T2="$T/v"; mkdir -p "$T2" && ( cd "$T2" && git init -q main && cd main \
266
+ && git config user.email l@example.invalid && git config user.name lane \
267
+ && printf '# no tracks rule\n' > .gitignore && echo x > README.md \
268
+ && git add -A && git commit -qm init && git worktree add -q ../wt -b wt-b ) >/dev/null 2>&1
269
+ W="$T2/wt"; M="$T2/main"; mkdir -p "$W/tracks/_meta"; echo sig > "$W/tracks/_meta/x.md"
270
+ OUT="$(bash "$SUT" "$W" --apply 2>&1)"; RC=$?
271
+ if printf '%s' "$OUT" | grep -q "OUTSIDE tracks/"; then
272
+ ng "W8e tracks/ 가 ignored 아닌 레포에서 «NOT auto-copied» 라고 하면서 실제로는 복사했다 — 영구 rc=1"
273
+ elif [ -f "$M/tracks/_meta/x.md" ]; then
274
+ OUT2="$(bash "$SUT" "$W" 2>&1)"; RC2=$?
275
+ [ "$RC2" -eq 0 ] && ok "W8e tracks/ 가 ignored 아니어도 회수되고, 재실행이 rc=0 으로 «풀린다»" \
276
+ || ng "W8e 회수는 됐는데 재실행 rc=$RC2 — 게이트가 안 풀린다"
277
+ else ng "W8e --apply 가 tracks/ 를 회수하지 못했다 (rc=$RC)"; fi
278
+
279
+ # W8f 🟥 A-9 — 화이트리스트가 이 레포 자신의 `.gitignore` 와 대조된 적이 없었다.
280
+ # 눈으로는 다시 안 맞춰지는 드리프트라 레인이 대조한다.
281
+ GI="$ROOT/.gitignore"
282
+ if [ -f "$GI" ]; then
283
+ miss=0; checked=0; names=""
284
+ for tok in .claude/.outbound_hook_uncalibrated_notice .claude/be_last_sync \
285
+ .claude/.prior_art_events.tsv .claude/.proposal_hook_events.tsv \
286
+ .claude/.outbound_hook_events.tsv; do
287
+ grep -qF "$tok" "$GI" || continue # 이 레포에 없는 항목은 대조 대상이 아니다
288
+ checked=$((checked+1))
289
+ grep -qF "$tok" "$SUT" || { miss=$((miss+1)); names="$names $tok"; }
290
+ done
291
+ # 🟥 4R B — 종전 판은 `.gitignore` 에 토큰이 없으면 조용히 `continue` 해서 **«대조 0건인데
292
+ # 초록»** 을 냈다. 실증: 그 다섯 줄을 지운 `.gitignore` 로 돌려도 42/0 이었다.
293
+ # 이 레포 자신의 결함 일가(「미측정을 0으로」)가 레인 안에서 재발한 자리다.
294
+ if [ "$checked" -eq 0 ]; then
295
+ ng "W8f 대조한 토큰이 0개다 — 「대조했다」가 아니라 「대조할 게 없었다」(NOT a pass)"
296
+ elif [ "$miss" -eq 0 ]; then
297
+ ok "W8f .gitignore 의 센티널 $checked 개를 대조했고 전부 화이트리스트에 있다"
298
+ else
299
+ ng "W8f 화이트리스트에 없는 센티널 $miss/$checked 개:$names — 재생성물이 제거를 막는다"
300
+ fi
301
+ else
302
+ ng "W8f .gitignore 를 못 찾았다 — 대조 «안 한» 것이지 통과가 아니다"
303
+ fi
304
+
305
+ echo "── W9 4라운드 (다른 계열, 3R 수리만 겨냥) ──"
306
+
307
+ # W9a 🟥 컨트롤 — CONFIG 완화가 «차단» 을 통째로 끄지 않았나.
308
+ mk_pair "$T/w"; W="$T/w/wt"; mkdir -p "$W/tracks/_meta" "$W/.claude" "$W/knowledge"
309
+ printf 'tracks/\n.claude/settings.json*\n.claude/settings.local.json*\nknowledge/*_draft.md\n' > "$W/.gitignore"
310
+ echo '{}' > "$W/.claude/settings.local.json"; echo draft > "$W/knowledge/paper_draft.md"
311
+ OUT="$(bash "$SUT" "$W" 2>&1)"; RC=$?
312
+ [ "$RC" -ne 0 ] && printf '%s' "$OUT" | grep -q "paper_draft.md" \
313
+ && ok "W9a CONFIG 완화가 «화이트리스트 밖 ignored 내용물» 차단을 안 껐다 (rc=$RC)" \
314
+ || ng "W9a rc=$RC — settings 완화가 차단을 통째로 껐다"
315
+
316
+ # W9b 🟥 4R B — `LC_ALL=C` 가 장식인지. 되돌려도 안 빨개졌다(diff 출력 파싱이 로케일 의존인데도).
317
+ # 행동 레인을 못 지으니(이 머신 diff 의 NLS 유무가 미상) **기록의 성질**을 단언한다.
318
+ # §Mechanization Boundary: 채널(그 호출이 로케일을 고정하나)은 기계화하고, 진위는 안 묻는다.
319
+ if grep -q 'LC_ALL=C git -C "$WT"' "$SUT" && grep -q 'LC_ALL=C diff -rq' "$SUT"; then
320
+ ok "W9b 열거기 둘 다 로케일 고정 — 정적 단언(행동 레인 아님, 잔여로 명시)"
321
+ else
322
+ ng "W9b git status 또는 diff 의 LC_ALL=C 가 빠졌다 — 번역된 경고/출력이 조용히 폐기된다"
323
+ fi
324
+
325
+ # W9c 🟥 ZONE 이 «판정을 쥐지 않는다» 를 확인 — tracks 가 회수되면 재실행이 rc=0 으로 풀려야 한다.
326
+ mk_pair "$T/x"; M="$T/x/main"; W="$T/x/wt"; mkdir -p "$W/tracks/_meta"; echo sig > "$W/tracks/_meta/z.md"
327
+ bash "$SUT" "$W" --apply >/dev/null 2>&1
328
+ OUT="$(bash "$SUT" "$W" 2>&1)"; RC=$?
329
+ [ "$RC" -eq 0 ] && [ -f "$M/tracks/_meta/z.md" ] \
330
+ && ok "W9c ZONE 은 판정을 안 쥔다 — 회수 뒤 재실행이 rc=0 으로 풀린다" \
331
+ || ng "W9c rc=$RC / 회수됨=$([ -f "$M/tracks/_meta/z.md" ] && echo 1 || echo 0)"
66
332
 
67
333
  echo
68
334
  echo "── worktree-reclaim lanes: PASS=$PASS FAIL=$FAIL ──"
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env bash
2
- # worktree_reclaim.sh — reclaim gitignored `tracks/**` artifacts from a git worktree BEFORE it is removed.
2
+ # worktree_reclaim.sh — reclaim what a worktree removal would silently destroy, BEFORE it is removed.
3
3
  #
4
4
  # WHY (N=2, so a script — 2026-09-02 signal + 2026-09-05 push-zone dispatch): the Destructive-Op gate
5
5
  # enumerates COMMITS, and `tracks/**` is gitignored, so a worktree removal can delete a session's only
@@ -9,14 +9,52 @@
9
9
  # remove — is exactly what this script does, in that order, because after the copy «never existed»
10
10
  # and «already moved» are indistinguishable (the list file is the evidence).
11
11
  #
12
+ # 🟥 SCOPE WIDENED 2026-09-21 — the first version looked ONLY at `tracks/`, and that made it lie.
13
+ # Measured the same day: a policy-lens worktree held `scripts/fixtures/…` (52 files) and
14
+ # `scripts/score_policy_lens.sh` as UNTRACKED files outside `tracks/`. The script enumerated
15
+ # «only-in-worktree: 0» and printed «✅ nothing left only in the worktree — safe to: git worktree
16
+ # remove». It was not merely incomplete — it ACTIVELY AUTHORIZED the destroy step on an irreversible
17
+ # surface. Second face of the same defect: `[ -d "$SRC" ] || exit 0` read «no tracks/ dir» as
18
+ # «nothing to reclaim» ([[feedback_not_found_is_not_zero_family]]). 🟥 And the LANE had frozen that
19
+ # false green as correct (old W5e: «worktree without tracks/ → rc=0 nothing to reclaim»).
20
+ #
21
+ # Two zones, deliberately NOT symmetric:
22
+ # tracks/** AUTO-RECLAIM — the measured loss class. Copied on --apply, byte-verified.
23
+ # everywhere SURFACE-ONLY — every other path git will not carry. Listed and it WITHHOLDS the
24
+ # «safe to remove» line, but is never auto-copied: the destination is a judgment
25
+ # (is `scripts/foo.sh` for the main tree, or worktree scratch?), and guessing it
26
+ # into a SHARED checkout is its own accident.
27
+ #
28
+ # 🟥 WHAT DOES *NOT* BLOCK, and why that list is short (S-2, 2026-09-21, 2nd cross-family round).
29
+ # The first attempt at the over-block problem below said «ignored never blocks». That opened a
30
+ # hole big enough to lose the exact thing this script exists to protect: measured on this repo's
31
+ # own `.gitignore`, a worktree holding ONLY `knowledge/**/*_paper_draft.md` (unpublished drafts)
32
+ # and `outputs/` (field-harness run artifacts) was told **«✅ safe to: git worktree remove»**.
33
+ # `CLAUDE.local.md`, `.claude/specs/`, `.claude/rules/.public-surface-patterns` are the same class
34
+ # — ignored AND irreplaceable, several of them with no undo at all.
35
+ # 🟥 That was the SECOND time in one session that a fix here re-created the disease it was fixing.
36
+ # So the non-blocking set is now a NAMED WHITELIST, not a category:
37
+ # ⓐ session runtime sentinels the hooks rewrite every run (`_runtime_sentinel`)
38
+ # ⓑ path-shaped build output, and ONLY when git already ignores it (`_regenerable`)
39
+ # Everything else blocks. Both lists are small frozen judgments (§Mechanization Boundary), accepted
40
+ # because their failure is LOUD and cheap (one extra path a human glances at) rather than silent.
41
+ # 🟥 `_regenerable` deliberately does NOT apply to UNTRACKED paths: «nobody ever told git about it»
42
+ # is no evidence that a path named `build/` is disposable, and a freshly written
43
+ # `scripts/build/report.md` is real work. Over-blocking trains the override, so the lane carries an
44
+ # over-block control (W6d), a control ON that control (W6e), and an ignored-CONTENT arm (W7g) whose
45
+ # fixture is taken from the real loss class rather than from a made-up sentinel name.
46
+ #
12
47
  # USAGE
13
48
  # bash scripts/worktree_reclaim.sh <worktree-path> # enumerate only (writes the list file)
14
49
  # bash scripts/worktree_reclaim.sh <worktree-path> --apply # enumerate + copy + verify
15
50
  #
16
- # EXIT 0 = nothing to reclaim, or everything reclaimed and byte-verified
17
- # 1 = files exist on BOTH sides with different content — a human must merge (listed, not copied)
51
+ # EXIT 0 = nothing left in the worktree that its removal would destroy
52
+ # 1 = something is still worktree-only: tracks/ files not yet reclaimed · both-sides DIFF ·
53
+ # OUTSIDE artifacts a human must dispose of (listed, never auto-copied)
18
54
  # 2 = usage / not a worktree of a main checkout
19
- # 10 = harness error (list file unwritable, copy failed verification)
55
+ # 10 = the sweep itself could not be trusted — enumerator failed (git status / diff), the
56
+ # enumeration was PARTIAL (a git warning), the main-worktree root did not resolve, the
57
+ # list file was unwritable, or a copy failed byte verification
20
58
  #
21
59
  # NEVER removes the worktree. Removal stays an explicit `git worktree remove` after this exits 0.
22
60
  set -uo pipefail
@@ -36,17 +74,163 @@ COMMON="$(cd "$COMMON" && pwd -P)"; GITDIR="$(cd "$GITDIR" && pwd -P)"
36
74
  if [ "$COMMON" = "$GITDIR" ]; then
37
75
  echo "🟥 $WT is the MAIN checkout (git-dir == git-common-dir), not a worktree — nothing to reclaim from itself" >&2; exit 2
38
76
  fi
39
- ROOT="$(dirname "$COMMON")" # main checkout root = parent of the shared .git
77
+ # 🟥 A-6 — `dirname "$COMMON"` assumes «the shared .git sits directly under the repo root». In a
78
+ # SUBMODULE worktree `--git-common-dir` is `<super>/.git/modules/<name>`, so ROOT became
79
+ # `<super>/.git/modules` and reclaimed files were copied INSIDE `.git`. This script is shipped on
80
+ # npm (`package.json` files[]), so the consumer's layout is the target, not this repo's.
81
+ ROOT="$(git -C "$WT" worktree list --porcelain 2>/dev/null | sed -n '1s/^worktree //p')"
82
+ [ -n "$ROOT" ] && [ -d "$ROOT" ] || { echo "🟥 could not resolve the main worktree root for $WT" >&2; exit 10; }
40
83
  WT="$(cd "$WT" && pwd -P)"
41
84
  SRC="$WT/tracks"; DST="$ROOT/tracks"
42
- [ -d "$SRC" ] || { echo "ℹ️ no tracks/ in worktree — nothing to reclaim (rc=0)"; exit 0; }
85
+ # 🟥 NO early exit on a missing `tracks/`. «tracks/ 가 없다» is not «there is nothing to reclaim» —
86
+ # that green is exactly what authorized the destroy step. A missing tracks/ empties THAT ZONE;
87
+ # the OUTSIDE sweep below still runs.
43
88
  mkdir -p "$DST/_meta/dispatch" 2>/dev/null || { echo "🟥 cannot create $DST/_meta/dispatch" >&2; exit 10; }
44
89
 
45
90
  NAME="$(basename "$WT")"; TS="$(date +%Y%m%d-%H%M%S)"
46
91
  LIST="$DST/_meta/dispatch/reclaim_${NAME}_${TS}.txt"
47
92
 
48
93
  # 1. ENUMERATE — the list lands in a file FIRST (the evidence that survives the copy)
49
- ONLY=(); DIFF=()
94
+ ONLY=(); DIFF=(); OUTSIDE=(); SKIPPED=(); ZONE=(); CONFIG=(); _DIRTY=0
95
+ _p=''; _k='' # 🟥 A-7 — `set -u` kills the loop below if a warning line arrives first
96
+
97
+ # 1-a. OUTSIDE — every path git will NOT carry, outside `tracks/`. Source is git itself, not a
98
+ # hand-rolled find: `-uall` lists untracked files individually; `--ignored` collapses wholly
99
+ # ignored dirs, which is the shape the exclusion list matches on.
100
+ # ⓐ Session runtime sentinels — rewritten by hooks on every run, and measured to be present in a
101
+ # real worktree on every run (this is what made «ignored blocks» an unpassable gate).
102
+ # 🟥 THE TEST FOR THIS LIST IS «the hooks rewrite it every run», NOT «it lives under .claude/».
103
+ # Two entries failed that test and were REMOVED in the 3rd adversarial round (2026-09-21):
104
+ # `.claude/settings.json` / `.claude/settings.local.json` — written by a human or the wizard,
105
+ # and `[[feedback_gitignored_config_has_no_undo]]` measured that losing one has NO undo
106
+ # (not in `git status`, not recoverable by `git checkout`). settings.local.json is the
107
+ # session's PERMISSION LEDGER. A worktree holding only those two was told «safe to remove».
108
+ # `.playwright-mcp/*` — holds screenshots/snapshots that exist ONLY in that worktree.
109
+ # Both were found by adversarial review, both reproduced by execution, neither self-caught.
110
+ # 🟥 And this list had never been cross-checked against this repo's OWN `.gitignore`: one entry of
111
+ # the five in the same «prior-art hook runtime sentinels» comment block was missing, so genuinely
112
+ # regenerable files were blocking. The lane now diffs the two (W7j) — this drift does not get
113
+ # re-noticed by eye.
114
+ # ⓒ Worktree-LOCAL config. 🟥 4th round: pulling `.claude/settings*.json` out of ⓐ (they are not
115
+ # «rewritten by the hooks») made them BLOCK, and a session that works in a worktree creates them
116
+ # there — so the gate became unclearable again, which is the `--force` training A-3 closed.
117
+ # Measured before deciding: a FRESH `git worktree add` carries **zero** ignored files — the main
118
+ # checkout's `.claude/settings.json` is NOT copied in. So a worktree's copy exists only because a
119
+ # session made it there, and it is scoped to that worktree's session (settings.local.json is that
120
+ # session's permission approvals). The main checkout's settings are never at risk from this tool.
121
+ # ⇒ They get their OWN verdict: they do not block, and the green line NAMES them, because
122
+ # «silently skipped» and «blocks forever» are both wrong here. The loss becomes visible AT the
123
+ # decision point instead of at neither end.
124
+ _worktree_local_config() {
125
+ case "$1" in
126
+ .claude/settings.json|.claude/settings.local.json) return 0 ;;
127
+ esac
128
+ return 1
129
+ }
130
+
131
+ _runtime_sentinel() {
132
+ case "$1" in
133
+ .claude/.prior_art_prompted_*|.claude/.prior_art_events.tsv) return 0 ;;
134
+ .claude/.outbound_hook_events.tsv|.claude/.proposal_hook_events.tsv) return 0 ;;
135
+ .claude/settings*.json.bak) return 0 ;; # 🟥 백업만. 원본은 아래 주석 참조
136
+ .claude/.outbound_hook_uncalibrated_notice|.claude/be_last_sync) return 0 ;;
137
+ .claude/worktrees/*|.claude/mcp_circuit/*|.claude/registry/*) return 0 ;;
138
+ .claude/skills/*|skills-lock.json|.codex/*) return 0 ;;
139
+ .claude/*.lock|.claude/goal-quench.*) return 0 ;;
140
+ .claude-octopus/*|.claude-octopus/) return 0 ;;
141
+ .fd_*|*/.fd_*) return 0 ;;
142
+ *-playwright-demo.png) return 0 ;;
143
+ .DS_Store|*/.DS_Store) return 0 ;;
144
+ esac
145
+ return 1
146
+ }
147
+
148
+ # ⓑ Path-shaped build output. 🟥 Consulted ONLY for paths git already ignores — see the header.
149
+ _regenerable() {
150
+ case "$1" in
151
+ tracks/*|tracks/) return 0 ;; # handled by its own zone below
152
+ .git/*|.git/) return 0 ;;
153
+ node_modules/*|*/node_modules/*) return 0 ;;
154
+ __pycache__/*|*/__pycache__/*) return 0 ;;
155
+ .venv/*|venv/*|*/.venv/*|*/venv/*) return 0 ;;
156
+ dist/*|build/*|target/*|*/dist/*|*/build/*|*/target/*) return 0 ;;
157
+ .next/*|.cache/*|*/.next/*|*/.cache/*) return 0 ;;
158
+ *.pyc|*.pyo|*.DS_Store) return 0 ;;
159
+ esac
160
+ return 1 # 🟥 unknown path → LISTED, never skipped
161
+ }
162
+ # 🟥 S-1 (2026-09-21, cross-family) — the FIRST version of this sweep threw the rc away:
163
+ # `done < <(git … 2>/dev/null)`. Process substitution is not a pipeline, so `pipefail` never
164
+ # applied, there is no `set -e`, and `2>/dev/null` ate the fatal message. A corrupt worktree
165
+ # index made git exit 128 with ZERO stdout lines → OUTSIDE=() → «outside-tracks: 0» →
166
+ # **«✅ safe to: git worktree remove»**. Measured, not theorised (rc=128, script rc=0).
167
+ # 🟥 That is THIS SCRIPT'S OWN DISEASE, re-introduced one layer up: the widening meant to stop
168
+ # «unlooked» rendering as «none» was itself carried by an unchecked enumerator.
169
+ # So the enumerator's rc is now load-bearing: it cannot fail quietly.
170
+ # 🟥 A-8 — `warning:`/`fatal:` below are ENGLISH git strings. git translates them under NLS
171
+ # (ko `경고:`, ja `警告:`), and a translated warning falls through to `*) continue` — which is
172
+ # exactly the partial-enumeration hole the `_DIRTY` branch exists to close. This ships on npm,
173
+ # so the consumer's locale is the target and «this machine is English» is not evidence
174
+ # ([[feedback_compare_beats_pinning_a_constant]]). B-5: `core.quotePath=false` so a non-ASCII
175
+ # path prints as itself — the script tells a human to «move or delete each one», and they cannot
176
+ # find a file named `\355\225\234.md`.
177
+ _ST=$(LC_ALL=C git -C "$WT" -c core.quotePath=false status --porcelain --ignored -uall 2>&1); _ST_RC=$?
178
+ if [ "$_ST_RC" -ne 0 ]; then
179
+ echo "🟥 git status failed (rc=$_ST_RC) — the worktree could not be enumerated." >&2
180
+ echo " An empty result here is NOT «clean». Do NOT remove the worktree." >&2
181
+ printf ' %s\n' "$_ST" >&2
182
+ exit 10
183
+ fi
184
+ while IFS= read -r _l; do
185
+ [ -n "$_l" ] || continue
186
+ # 🟥 A-1 — the first version used `${_l#?? }`. In parameter expansion the word is a PATTERN, so
187
+ # `?` is a glob: `?? ` matched EVERY porcelain status line. Consequences, all measured:
188
+ # the `!! ` branch was dead code, the `continue` guard never fired, ` M README.md` (a TRACKED
189
+ # file) was reported as OUTSIDE «git will not carry this», and `R old -> new` produced a path
190
+ # that does not exist. Literal `case` patterns instead — and the ??/!! KIND is now kept,
191
+ # because that distinction is the only signal that separates A-3's two populations.
192
+ case "$_l" in
193
+ '?? '*) _p="${_l#?? }"; _k=U ;; # untracked — nobody ever told git about it
194
+ '!! '*) _p="${_l#!! }"; _k=I ;; # ignored — someone wrote a rule for it on purpose
195
+ # 🟥 A-5 — `2>&1` merged git's warnings INTO this stream, and `*) continue` then discarded them
196
+ # as «not a line we parse». git exits 0 on `warning: could not open directory … Permission
197
+ # denied`, so rc alone does not see a PARTIAL enumeration — and a partial enumeration is
198
+ # exactly «unlooked rendered as none». Louder than the `2>/dev/null` it replaced, not quieter.
199
+ 'warning:'*|'fatal:'*|'error:'*) printf ' %s\n' "$_l" >&2; _DIRTY=1; continue ;;
200
+ *) continue ;; # tracked states (M/A/D/R/U…) die with nothing
201
+ esac
202
+ case "$_p" in '"'*'"') _p="${_p#\"}"; _p="${_p%\"}" ;; esac # git quotes non-ASCII paths
203
+ # 🟥 A-10/A-11 — `tracks/` gets its OWN bucket, before anything else looks at it. The 2nd-round
204
+ # code sent it through `_regenerable` (whose first case is `tracks/*`), so every tracks file was
205
+ # labelled «skipped as REGENERABLE» to the reader — the measured loss class, reported as
206
+ # disposable — and the SAME path printed twice, once as ONLY (blocking) and once as SKIP (not).
207
+ # And where `tracks/` is NOT gitignored it arrived as `??` and blocked forever: `--apply` copied
208
+ # it and the screen still said «NOT auto-copied», with rc=1 that re-running never cleared.
209
+ # Both reproduced by execution. It is neither skipped nor blocked here — it is JUDGED BELOW.
210
+ case "$_p" in tracks/*|tracks/) ZONE+=("$_p"); continue ;; esac
211
+ # 🟥 S-2 — the non-blocking set is a NAMED WHITELIST, and it is consulted only for `!!`.
212
+ # An untracked path blocks whatever it is called: a path SHAPED like build output is not
213
+ # evidence that it IS build output when nobody ever told git about it.
214
+ if [ "$_k" = "I" ] && _worktree_local_config "$_p"; then
215
+ CONFIG+=("$_p") # 🟥 4R — named in the verdict, does not block
216
+ elif [ "$_k" = "I" ] && { _runtime_sentinel "$_p" || _regenerable "$_p"; }; then
217
+ SKIPPED+=("$_p") # 🟥 A-2 — counted and listed, never vanished
218
+ else
219
+ OUTSIDE+=("$_p") # untracked, or ignored-but-not-whitelisted → BLOCKS
220
+ fi
221
+ done <<EOF
222
+ $_ST
223
+ EOF
224
+
225
+ # 1-b. tracks/ — both-sides comparison. 🟥 `diff` rc is three-valued: 0 same · 1 differ · 2 ERROR.
226
+ # The first version discarded it, so an EACCES on one subdirectory gave partial output and a
227
+ # green verdict — in the zone that holds the MEASURED loss class. Same face as S-1.
228
+ if [ -d "$SRC" ]; then
229
+ _DF=$(LC_ALL=C diff -rq "$SRC" "$DST" 2>&1); _DF_RC=$?
230
+ if [ "$_DF_RC" -gt 1 ]; then
231
+ echo "🟥 diff failed (rc=$_DF_RC) comparing $SRC — tracks/ could not be compared." >&2
232
+ printf ' %s\n' "$_DF" >&2; exit 10
233
+ fi
50
234
  while IFS= read -r line; do
51
235
  case "$line" in
52
236
  "Only in $SRC"*)
@@ -60,18 +244,40 @@ while IFS= read -r line; do
60
244
  fi ;;
61
245
  "Files $SRC"*" differ") DIFF+=("$(printf '%s' "${line#Files }" | sed "s# and .*##; s#^$SRC/##")") ;;
62
246
  esac
63
- done < <(diff -rq "$SRC" "$DST" 2>/dev/null)
247
+ done <<EOF
248
+ $_DF
249
+ EOF
250
+ fi
64
251
 
65
252
  {
66
253
  echo "# worktree_reclaim — $WT → $ROOT ($TS)"
67
- echo "# only-in-worktree: ${#ONLY[@]} differ-both-sides: ${#DIFF[@]} mode: ${MODE:-enumerate}"
254
+ echo "# blocking: only-in ${#ONLY[@]} · differ ${#DIFF[@]} · outside ${#OUTSIDE[@]} | non-blocking: skipped ${#SKIPPED[@]} · tracks-zone ${#ZONE[@]} · config ${#CONFIG[@]} mode: ${MODE:-enumerate}"
255
+ [ -d "$SRC" ] || echo "# note: worktree has no tracks/ — that ZONE is empty, which is not 'nothing to reclaim'"
68
256
  for p in ${ONLY[@]+"${ONLY[@]}"}; do echo "ONLY $p"; done
69
257
  for p in ${DIFF[@]+"${DIFF[@]}"}; do echo "DIFF $p"; done
258
+ for p in ${OUTSIDE[@]+"${OUTSIDE[@]}"}; do echo "OUTSIDE $p"; done
259
+ for p in ${SKIPPED[@]+"${SKIPPED[@]}"}; do echo "SKIP $p"; done
260
+ for p in ${ZONE[@]+"${ZONE[@]}"}; do echo "ZONE $p"; done
261
+ for p in ${CONFIG[@]+"${CONFIG[@]}"}; do echo "CONFIG $p"; done
70
262
  } > "$LIST" || { echo "🟥 cannot write list file $LIST" >&2; exit 10; }
71
263
  echo "── worktree_reclaim: $NAME ──"
72
- echo " only-in-worktree: ${#ONLY[@]} · differ-both-sides: ${#DIFF[@]} · list: ${LIST#$ROOT/}"
264
+ echo " ⛔ blocking: only-in ${#ONLY[@]} · differ ${#DIFF[@]} · outside ${#OUTSIDE[@]} | ℹ️ non-blocking: skipped ${#SKIPPED[@]} · tracks-zone ${#ZONE[@]} · config ${#CONFIG[@]}"
265
+ echo " list: ${LIST#$ROOT/}"
73
266
  for p in ${ONLY[@]+"${ONLY[@]}"}; do echo " ONLY $p"; done
74
267
  for p in ${DIFF[@]+"${DIFF[@]}"}; do echo " DIFF $p (both sides exist and differ — NOT copied, merge by hand)"; done
268
+ for p in ${OUTSIDE[@]+"${OUTSIDE[@]}"}; do echo " OUTSIDE $p (untracked — git will not carry this, NOT auto-copied)"; done
269
+ for p in ${SKIPPED[@]+"${SKIPPED[@]}"}; do echo " SKIP $p (on the named regenerable/sentinel list — does not block)"; done
270
+ [ "${#ZONE[@]}" -gt 0 ] && echo " ZONE ${#ZONE[@]} path(s) under tracks/ — judged by the tracks/ zone above, not here"
271
+ for p in ${CONFIG[@]+"${CONFIG[@]}"}; do echo " CONFIG $p (worktree-local session config — will be DESTROYED with the worktree)"; done
272
+
273
+ # 🟥 B-6 — this check used to sit AFTER the copy loop, so a partial enumeration printed a column of
274
+ # «✅ reclaimed …» before the warning. Copying is additive, so nothing was destroyed — but a human
275
+ # stops scrolling at green check marks. A partial sweep must not reach the reclaim decision.
276
+ if [ "$_DIRTY" -ne 0 ]; then
277
+ echo "🟥 git reported a warning while enumerating — the sweep was PARTIAL, not clean (rc=10)." >&2
278
+ echo " Nothing was reclaimed. Do NOT remove the worktree." >&2
279
+ exit 10
280
+ fi
75
281
 
76
282
  # 2. RECLAIM (--apply) — copy, then verify byte-identical; a copy that cannot be verified is a harness error
77
283
  if [ "$MODE" = "--apply" ] && [ "${#ONLY[@]}" -gt 0 ]; then
@@ -91,5 +297,34 @@ if [ "${#ONLY[@]}" -gt 0 ] && [ "$MODE" != "--apply" ]; then
91
297
  echo "ℹ️ ${#ONLY[@]} file(s) exist only in the worktree — re-run with --apply to copy them (rc=1 until reclaimed)"
92
298
  exit 1
93
299
  fi
94
- echo "✅ nothing left only in the worktree — safe to: git worktree remove $WT"
300
+ # 🟥 OUTSIDE does not clear with --apply — it is deliberately not copied, so a human must dispose
301
+ # of it before this script will say the removal is safe.
302
+ # 🟥 A-3 — only UNTRACKED blocks. Measured on the real repo: an FH worktree carries ignored runtime
303
+ # sentinels outside tracks/ on every run (`.claude/.prior_art_prompted_<session>`,
304
+ # `.claude/.outbound_hook_events.tsv`, `.claude-octopus/state.json`, …). Blocking on those made
305
+ # rc=1 PERMANENT, and the only ways past are deleting a sentinel the hooks still need or reaching
306
+ # for `git worktree remove --force` — i.e. this script's own header warning («over-blocking trains
307
+ # the override») coming true on its primary target.
308
+ # 🟥 NOT «ignored always passes»: `tracks/**` is ignored AND is the measured loss class, which is
309
+ # exactly why it keeps its own zone above. The split is by PROVENANCE — untracked means nobody
310
+ # ever told git about it, ignored means someone wrote a rule for it on purpose.
311
+ if [ "${#OUTSIDE[@]}" -gt 0 ]; then
312
+ echo "🟥 ${#OUTSIDE[@]} untracked path(s) live ONLY in the worktree and git will not carry them."
313
+ echo " NOT copied — the destination is a judgment call, not a default."
314
+ echo " Move or delete each one, then re-run. Until then: do NOT remove the worktree (rc=1)."
315
+ exit 1
316
+ fi
317
+ # 🟥 A-4 — the green line used to be unconditional, so it said «nothing left» forty lines under a
318
+ # list of files it had just printed. What is skipped must ride along with the verdict.
319
+ if [ "${#CONFIG[@]}" -gt 0 ]; then
320
+ echo "✅ nothing that needs reclaiming — safe to: git worktree remove $WT"
321
+ echo " 🟥 ${#CONFIG[@]} worktree-local config file(s) WILL BE DESTROYED (listed above)."
322
+ echo " A fresh worktree has none; these exist because a session wrote them here."
323
+ [ "${#SKIPPED[@]}" -gt 0 ] && echo " (plus ${#SKIPPED[@]} skipped as regenerable/sentinel)"
324
+ elif [ "${#SKIPPED[@]}" -gt 0 ]; then
325
+ echo "✅ nothing that needs reclaiming — safe to: git worktree remove $WT"
326
+ echo " (${#SKIPPED[@]} path(s) skipped as regenerable/sentinel — listed above, judged, not unseen)"
327
+ else
328
+ echo "✅ nothing left only in the worktree — safe to: git worktree remove $WT"
329
+ fi
95
330
  exit 0