@chrono-meta/fh-gate 3.43.0 → 3.45.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (105) hide show
  1. package/.claude/rules/fh_4axis_gate.md +50 -608
  2. package/.claude-plugin/marketplace.json +4 -4
  3. package/AGENTS.md +5 -1
  4. package/CATALOG.md +21 -0
  5. package/CHEATSHEET.md +7 -1
  6. package/docs/USER_GUIDE.md +95 -0
  7. package/docs/codex-compat.md +1 -1
  8. package/knowledge/shared/harness-core/fh_4axis_gate_detail.md +679 -0
  9. package/knowledge/shared/harness-core/fh_integration_contract.md +1 -1
  10. package/knowledge/shared/harness-core/fh_module_contract.md +106 -3
  11. package/knowledge/shared/harness-core/governance_engineering_definition.md +16 -0
  12. package/knowledge/shared/harness-core/heavy_skill_to_cartridge.md +185 -0
  13. package/knowledge/shared/learnings/subagent_invocations_log.yaml +221 -0
  14. package/knowledge/shared/plugin-catalog/recommended_plugins.md +53 -9
  15. package/package.json +24 -1
  16. package/plugins/fh-commons/.claude-plugin/plugin.json +1 -1
  17. package/plugins/fh-commons/skills/ko-tech-writer/SKILL.md +50 -14
  18. package/plugins/fh-commons/skills/ko-tech-writer/SKILL_detail.md +80 -0
  19. package/plugins/fh-commons/skills/ko-tech-writer/fixtures/sense_negative.md +30 -0
  20. package/plugins/fh-commons/skills/ko-tech-writer/fixtures/sense_positive.md +56 -0
  21. package/plugins/fh-meta/.claude-plugin/plugin.json +1 -1
  22. package/plugins/fh-meta/CHANGELOG.md +118 -0
  23. package/plugins/fh-meta/skills/auto-decorrelation/SKILL.md +58 -1
  24. package/plugins/fh-meta/skills/install-wizard/SKILL_detail.md +4 -0
  25. package/plugins/fh-meta/skills/sim-conductor/SKILL_detail.md +3 -3
  26. package/plugins/fh-meta/skills/steel-quench/SKILL_detail.md +9 -4
  27. package/plugins/fh-preprep/.claude-plugin/plugin.json +1 -1
  28. package/plugins/fh-qp/.claude-plugin/plugin.json +1 -1
  29. package/scripts/agy_launch_guard.sh +165 -0
  30. package/scripts/agy_remote_run.sh +187 -0
  31. package/scripts/below_floor_scan.sh +30 -0
  32. package/scripts/codex_launch_guard.sh +123 -0
  33. package/scripts/correction_moments.py +23 -2
  34. package/scripts/fh-gate.sh +612 -14
  35. package/scripts/fh-goal.sh +56 -12
  36. package/scripts/fh-run.sh +1 -1
  37. package/scripts/fh_gate_exec.sh +272 -0
  38. package/scripts/fh_session_load.sh +17 -0
  39. package/scripts/finding_fleet.sh +36 -2
  40. package/scripts/finding_verifier.sh +7 -2
  41. package/scripts/fixtures/heavy_skill_smell/clean/tidy-notes/README.md +16 -0
  42. package/scripts/fixtures/heavy_skill_smell/clean/tidy-notes/scripts/check_refs.py +12 -0
  43. package/scripts/fixtures/heavy_skill_smell/clean/tidy-notes/scripts/test_check_refs.py +24 -0
  44. package/scripts/fixtures/heavy_skill_smell/clean/tidy-notes/skills/tidy-notes/SKILL.md +16 -0
  45. package/scripts/fixtures/heavy_skill_smell/clean/tidy-notes/skills/tidy-notes/fh-module.yaml +20 -0
  46. package/scripts/fixtures/heavy_skill_smell/heavy/docs-publisher-pro/SKILL.md +25 -0
  47. package/scripts/fixtures/heavy_skill_smell/heavy/docs-publisher-pro/hooks/hooks.json +7 -0
  48. package/scripts/fixtures/heavy_skill_smell/heavy/docs-publisher-pro/scripts/check_links.py +25 -0
  49. package/scripts/fixtures/heavy_skill_smell/heavy/docs-publisher-pro/scripts/publish.sh +9 -0
  50. package/scripts/fixtures/heavy_skill_smell/heavy/docs-publisher-pro/scripts/publish_guard.py +6 -0
  51. package/scripts/fixtures/heavy_skill_smell/heavy/docs-publisher-pro/scripts/setup.sh +5 -0
  52. package/scripts/fixtures/heavy_skill_smell/heavy/release-notes-pro/SKILL.md +25 -0
  53. package/scripts/fixtures/heavy_skill_smell/heavy/release-notes-pro/hooks/hooks.json +10 -0
  54. package/scripts/fixtures/heavy_skill_smell/heavy/release-notes-pro/scripts/check_refs.py +12 -0
  55. package/scripts/fixtures/heavy_skill_smell/heavy/release-notes-pro/scripts/guard_push.py +9 -0
  56. package/scripts/fixtures/heavy_skill_smell/heavy/release-notes-pro/scripts/install.sh +6 -0
  57. package/scripts/fixtures/heavy_skill_smell/heavy/release-notes-pro/scripts/ship.sh +9 -0
  58. package/scripts/heavy_skill_smell.py +311 -0
  59. package/scripts/job_heartbeat.py +186 -0
  60. package/scripts/ko_tech_writer_calibrate.py +88 -1
  61. package/scripts/live_eval_matrix.py +128 -0
  62. package/scripts/live_eval_trace.py +199 -5
  63. package/scripts/package_coverage_check.sh +18 -0
  64. package/scripts/prepush_guard_check.sh +41 -20
  65. package/scripts/probe_live_eval.sh +33 -1
  66. package/scripts/probe_live_eval_lib.py +14 -6
  67. package/scripts/selfcheck.sh +162 -2
  68. package/scripts/selfcheck_shard_weights.txt +2 -0
  69. package/scripts/session_checklist.py +109 -5
  70. package/scripts/sidecar_calibrate.sh +15 -5
  71. package/scripts/sidecar_wait.sh +21 -1
  72. package/scripts/sim_isolated_run.sh +20 -0
  73. package/scripts/test_agy_launch_guard_lanes.sh +347 -0
  74. package/scripts/test_agy_remote_run_lanes.sh +228 -0
  75. package/scripts/test_below_floor_scan_lanes.sh +85 -0
  76. package/scripts/test_codex_launch_guard_lanes.sh +183 -0
  77. package/scripts/test_correction_moments_lanes.sh +37 -0
  78. package/scripts/test_fh_gate_absorb_lanes.sh +255 -0
  79. package/scripts/test_fh_gate_defaults_lanes.sh +169 -0
  80. package/scripts/test_fh_gate_exec_lanes.sh +244 -0
  81. package/scripts/test_fh_gate_fusion_lanes.sh +202 -0
  82. package/scripts/test_fh_gate_regressions.sh +92 -1
  83. package/scripts/test_fh_goal_change_detection_lanes.sh +103 -3
  84. package/scripts/test_finding_pipeline_lanes.sh +41 -3
  85. package/scripts/test_guard_anchor_override_env_lanes.sh +84 -0
  86. package/scripts/test_heavy_skill_smell_lanes.sh +160 -0
  87. package/scripts/test_job_heartbeat_lanes.sh +96 -0
  88. package/scripts/test_live_eval_construct_lanes.sh +29 -6
  89. package/scripts/test_live_eval_matrix_lanes.sh +53 -0
  90. package/scripts/test_live_eval_trace_lanes.sh +165 -12
  91. package/scripts/test_name_boundary_locale_lanes.sh +36 -5
  92. package/scripts/test_preprep_speech_coach_lanes.sh +18 -2
  93. package/scripts/test_prepush_guard_failure_visibility_lanes.sh +152 -0
  94. package/scripts/test_prepush_marker_lookup_lanes.sh +143 -0
  95. package/scripts/test_probe_live_eval_lanes.sh +43 -0
  96. package/scripts/test_regression_guard_sibling_lanes.sh +52 -1
  97. package/scripts/test_session_checklist_lanes.sh +205 -0
  98. package/scripts/test_sidecar_calibrate_lanes.sh +5 -1
  99. package/scripts/test_sidecar_wait_stdin.sh +18 -0
  100. package/scripts/test_sim_isolated_run_lanes.sh +43 -0
  101. package/scripts/universal_guard_check.sh +8 -0
  102. package/templates/.claude/rules/mcp_tool_gating.md +27 -0
  103. package/templates/.git-hooks/pre-push +60 -3
  104. package/templates/regression_guard.sh +8 -4
  105. package/templates/settings.LaneGap.snippet.json +27 -0
@@ -19,6 +19,14 @@
19
19
  # Runs in throwaway repos (mktemp): never touches this repo's index or worktree.
20
20
  # Usage: bash scripts/prepush_guard_check.sh → exit 0 all pairs hold, 1 otherwise.
21
21
  set -uo pipefail
22
+ # Measure the pre-push hook as it behaves by DEFAULT: an override the caller exported (PUBLIC_SURFACE_OK=1 …) must
23
+ # not reach the hook under test (pmh-dev #91 ②, 2026-11-15). Lane: scripts/test_guard_anchor_override_env_lanes.sh.
24
+ # Also the two non-override inputs the hook reads from the environment (codex R1): PSA_PATTERNS replaces the
25
+ # fixtures' synthetic operator patterns, FH_DESTRUCTIVE_BASE moves the destructive-advisory baseline.
26
+ unset PUBLIC_SURFACE_OK DESTRUCTIVE_OP_OK FH_NOVELTY_OK MAIN_PUSH_OK PUSH_ZONE_OK TAG_VERSION_OK TRACKS_GITLINK_OK TRACKS_PUBLIC_OK PSA_PATTERNS FH_DESTRUCTIVE_BASE 2>/dev/null || true
27
+ # Every PSA_* input too (codex R2: PSA_ALLOWLIST suppressed a planted positive) — by prefix, so a new PSA_ input
28
+ # cannot slip past a hand-written list. The scan library sets the ones it needs itself.
29
+ for _v in $(compgen -v | grep '^PSA_'); do unset "$_v"; done; unset _v
22
30
 
23
31
  REPO_ROOT=$(git rev-parse --show-toplevel 2>/dev/null || pwd)
24
32
  HOOK_SRC="$REPO_ROOT/templates/.git-hooks/pre-push"
@@ -41,6 +49,18 @@ esac
41
49
  HOOK="$WORK/hook"
42
50
 
43
51
  FAILED=0
52
+ # Each pair's name, exit code and elapsed time when it breaks. The BLOCKED line at the end names them,
53
+ # because a caller that shows only the last lines of this output (selfcheck did: tail -12) otherwise
54
+ # reads «a known pair broke» with the pair itself cut off above. A downstream consumer hit exactly that
55
+ # under heavy load and could not say which pair broke, or whether it timed out. Elapsed is per pair
56
+ # (whole seconds, $SECONDS): a pair that ran long points at a timeout, a short one at a wrong verdict.
57
+ FAILED_LIST=()
58
+ _t0=$SECONDS
59
+ _el() { printf '%ss' "$((SECONDS - _t0))"; }
60
+ _pair_fail() { # called inside check/sb_check: reads their locals name and rc
61
+ FAILED=1
62
+ FAILED_LIST+=("$(printf '%s' "$name" | tr -s ' ') (rc=${rc:-?}, $(_el))")
63
+ }
44
64
  # Fixtures assembled at runtime so this file's own bytes carry no matching credential shape
45
65
  # (same rule as universal_guard_check.sh — a fixture file excluded from scanning would be a hole).
46
66
  AWSK="AKIA""1234567890ABCDEF"
@@ -67,14 +87,14 @@ newrepo() { # echoes a fresh repo path with the pattern layers in place and one
67
87
  # check <name> <repo> <expect: block|pass> <refline...>
68
88
  check() {
69
89
  local name="$1" repo="$2" expect="$3"; shift 3
70
- local out rc got
90
+ local out rc got; _t0=$SECONDS
71
91
  out=$(printf '%s\n' "$@" | ( cd "$repo" && bash templates/.git-hooks/pre-push origin git@example:x/y.git 2>&1 )); rc=$?
72
92
  # A runtime fault is its own failure mode, checked BEFORE the verdict: an aborted hook that exits 0
73
93
  # would otherwise be scored as a clean pass — the exact defect this anchor was written for.
74
94
  if printf '%s' "$out" | grep -qiE 'bad substitution|unbound variable|syntax error|command not found'; then
75
- echo " ❌ $name — RUNTIME FAULT in the hook (a hook that aborts is not a hook that passed)"
95
+ echo " ❌ $name [$(_el)] — RUNTIME FAULT in the hook (a hook that aborts is not a hook that passed)"
76
96
  printf '%s\n' "$out" | grep -iE 'bad substitution|unbound|syntax error|command not found' | sed 's/^/ /' | head -3
77
- FAILED=1; return
97
+ _pair_fail; return
78
98
  fi
79
99
  # A hook killed by a signal, or one that dies printing nothing, produces no fault TEXT — the grep
80
100
  # above cannot see it, and rc alone would score it as a pass (R7 audit, 2026-07-26). So a `pass`
@@ -88,23 +108,23 @@ check() {
88
108
  if printf '%s' "$out" | grep -qE '(leak —|leak in pushed|incomplete confidentiality instrument|unusable pattern)'; then
89
109
  got=block
90
110
  else
91
- echo " ❌ $name — blocked, but for a HARNESS reason, not a confidentiality finding"
111
+ echo " ❌ $name [$(_el)] — blocked, but for a HARNESS reason, not a confidentiality finding"
92
112
  printf '%s\n' "$out" | sed 's/^/ | /' | head -6
93
- FAILED=1; return
113
+ _pair_fail; return
94
114
  fi
95
115
  elif printf '%s' "$out" | grep -qF 'FH Pre-Publish'; then
96
116
  got=pass
97
117
  else
98
- echo " ❌ $name — hook exited 0 without reaching the publish check (silent abort is not a pass)"
118
+ echo " ❌ $name [$(_el)] — hook exited 0 without reaching the publish check (silent abort is not a pass)"
99
119
  printf '%s\n' "$out" | sed 's/^/ | /' | head -5
100
- FAILED=1; return
120
+ _pair_fail; return
101
121
  fi
102
122
  if [ "$got" = "$expect" ]; then
103
- echo " ✅ $name (expected $expect)"
123
+ echo " ✅ $name [$(_el)] (expected $expect)"
104
124
  else
105
- echo " ❌ $name — expected $expect, got $got"
125
+ echo " ❌ $name [$(_el)] — expected $expect, got $got"
106
126
  printf '%s\n' "$out" | sed 's/^/ | /' | head -8
107
- FAILED=1
127
+ _pair_fail
108
128
  fi
109
129
  }
110
130
 
@@ -256,10 +276,10 @@ sb_check() { # sb_check <name> <repo> <expect: warn|skip|none> <refline> [must-
256
276
  # [must-name]: a branch the warning MUST name. "a warning appeared" is too weak an assertion —
257
277
  # under a mutation that broke the self-exclusion, the advisory still warned, but about the
258
278
  # pushed branch ITSELF. The leg went green while the defect was live (measured 2026-07-27).
259
- local name="$1" repo="$2" expect="$3" refline="$4" mustname="${5:-}" out rc got
279
+ local name="$1" repo="$2" expect="$3" refline="$4" mustname="${5:-}" out rc got; _t0=$SECONDS
260
280
  out=$(printf '%s\n' "$refline" | ( cd "$repo" && bash templates/.git-hooks/pre-push origin git@example:x/y.git 2>&1 )); rc=$?
261
281
  if printf '%s' "$out" | grep -qiE 'bad substitution|unbound variable|syntax error|command not found'; then
262
- echo " ❌ $name — RUNTIME FAULT in the hook"; FAILED=1; return
282
+ echo " ❌ $name [$(_el)] — RUNTIME FAULT in the hook"; _pair_fail; return
263
283
  fi
264
284
  if printf '%s' "$out" | grep -qF "$SB_MARK"; then
265
285
  # Key on a machine token, not prose. Measured 2026-07-27: this classifier first grepped the
@@ -270,23 +290,23 @@ sb_check() { # sb_check <name> <repo> <expect: warn|skip|none> <refline> [must-
270
290
  got=none
271
291
  fi
272
292
  if [ "$got" != "$expect" ]; then
273
- echo " ❌ $name — expected $expect, got $got"
293
+ echo " ❌ $name [$(_el)] — expected $expect, got $got"
274
294
  printf '%s\n' "$out" | sed 's/^/ | /' | head -8
275
- FAILED=1; return
295
+ _pair_fail; return
276
296
  fi
277
297
  # The advisory must not move the verdict. These legs are otherwise-clean pushes, so a non-zero
278
298
  # exit means the advisory (or something it perturbed) started blocking.
279
299
  if [ "$rc" -ne 0 ]; then
280
- echo " ❌ $name — advisory changed the verdict (exit $rc); it must be advisory only"
300
+ echo " ❌ $name [$(_el)] — advisory changed the verdict (exit $rc); it must be advisory only"
281
301
  printf '%s\n' "$out" | sed 's/^/ | /' | head -6
282
- FAILED=1; return
302
+ _pair_fail; return
283
303
  fi
284
304
  if [ -n "$mustname" ] && ! printf '%s' "$out" | grep -qF "$mustname"; then
285
- echo " ❌ $name — warned, but never named '$mustname' (warning for the wrong reason)"
305
+ echo " ❌ $name [$(_el)] — warned, but never named '$mustname' (warning for the wrong reason)"
286
306
  printf '%s\n' "$out" | grep -F "$SB_MARK" -A5 | sed 's/^/ | /' | head -8
287
- FAILED=1; return
307
+ _pair_fail; return
288
308
  fi
289
- echo " ✅ $name ($expect, verdict unchanged${mustname:+, named $mustname})"
309
+ echo " ✅ $name [$(_el)] ($expect, verdict unchanged${mustname:+, named $mustname})"
290
310
  }
291
311
  # ⚠️ 계기 주의 (실측): 처음엔 remote_sha 를 all-zero(=신규 브랜치)로 줬는데, 그러면 push 범위에
292
312
  # 샌드박스의 base 커밋(= templates/.git-hooks/pre-push 사본을 담고 있다)이 들어가 이 훅의 **기존**
@@ -382,7 +402,8 @@ if [ "$FAILED" -eq 0 ]; then
382
402
  echo "[prepush-guard] ✅ all known pairs hold"
383
403
  exit 0
384
404
  fi
385
- echo "[prepush-guard] ❌ BLOCKED — a known pair broke."
405
+ _broken=""; for _b in ${FAILED_LIST[@]+"${FAILED_LIST[@]}"}; do _broken="${_broken:+$_broken; }$_b"; done
406
+ echo "[prepush-guard] ❌ BLOCKED — ${#FAILED_LIST[@]} known pair(s) broke after ${SECONDS}s: ${_broken:-<unnamed>}"
386
407
  echo " BLOCK→PASS = the publish boundary stopped covering something it claims to cover."
387
408
  echo " PASS→BLOCK = over-blocking, which trains PUBLIC_SURFACE_OK into reflex and disarms the gate."
388
409
  echo " RUNTIME FAULT = the hook aborted; that is never a pass, however it exited."
@@ -138,7 +138,7 @@ MODEL="sonnet"
138
138
  # ⚠️ 비용: reps=3 이면 프로브당 `claude -p` 호출이 2 → 6 이다(12 프로브 = 24 → 72).
139
139
  REPS=1
140
140
  # §TRACE (2026-11-14, FH-3): arms keep their event stream so the scorer can read tool calls and the
141
- # init tool/MCP list (behave: probes · INVALID-COMPARISON). FH_LIVE_TRACE=0 restores text-only runs.
141
+ # init tool/MCP/plugin lists (behave: probes · INVALID-COMPARISON). FH_LIVE_TRACE=0 restores text-only runs.
142
142
  if [ "${FH_LIVE_TRACE:-1}" = 0 ]; then FH_LIVE_TRACE_ARG=""; else FH_LIVE_TRACE_ARG="--trace"; fi
143
143
  DRYRUN=0
144
144
  SUBSET=""
@@ -439,6 +439,38 @@ score_rc=$?
439
439
  done < "$SPEC_DIR/selected_ids.txt"
440
440
  } >> "$REPORT_PATH"
441
441
 
442
+ # Behaviour profile (2026-11-17, arXiv:2611.17440 — record only, never read by the scorer above).
443
+ # Two arms with the same pass rate can still behave differently — one may skip verification and pass
444
+ # anyway. One line per rep: the arm's top-level tool calls in four bins, counted from the event stream
445
+ # the runner already keeps (bin rules: scripts/live_eval_trace.py). A rep with no stream says MISSING,
446
+ # an unreadable one UNREADABLE — never counts of 0. Appended AFTER score; score_rc is untouched.
447
+ {
448
+ echo ""
449
+ echo "## Behaviour profile (record only — not scored)"
450
+ echo ""
451
+ if [ -z "$FH_LIVE_TRACE_ARG" ]; then
452
+ echo "behaviour-profile: not recorded — FH_LIVE_TRACE=0 (no event stream kept)"
453
+ else
454
+ while IFS= read -r id; do
455
+ [ -z "$id" ] && continue
456
+ for arm in primary control control_b; do
457
+ [ "$arm" = control_b ] && [ ! -f "$SPEC_DIR/$id.control_b.txt" ] && continue
458
+ r=1
459
+ while [ "$r" -le "$REPS" ]; do
460
+ st="$OUTDIR/$id/${arm}_r${r}.stream.jsonl"
461
+ if [ ! -f "$st" ]; then
462
+ echo "behaviour-profile: $id $arm r$r trace=MISSING"
463
+ else
464
+ bp="$(python3 "$REPO_ROOT/scripts/live_eval_trace.py" profile "$st" 2>/dev/null)"
465
+ echo "behaviour-profile: $id $arm r$r ${bp:-trace=UNREADABLE}"
466
+ fi
467
+ r=$((r + 1))
468
+ done
469
+ done
470
+ done < "$SPEC_DIR/selected_ids.txt"
471
+ fi
472
+ } >> "$REPORT_PATH"
473
+
442
474
  if [ -n "$EVIDENCE_DIR" ]; then
443
475
  # The report is part of the evidence: a preserved body set with no verdict beside it forces the
444
476
  # next reader to re-derive what the run concluded.
@@ -312,7 +312,7 @@ FAILED_TO_RUN = 'FAILED-TO-RUN'
312
312
  UNCALIBRATED = 'UNCALIBRATED'
313
313
  PASS = 'PASS'
314
314
  FAIL = 'FAIL'
315
- INVALID_COMPARISON = 'INVALID-COMPARISON' # arms ran with different tool/MCP surfaces (FH-3, 2026-11-14)
315
+ INVALID_COMPARISON = 'INVALID-COMPARISON' # arms ran with different tool/MCP/plugin surfaces (FH-3 2026-11-14; plugins 2026-11-15)
316
316
 
317
317
  try: # §TRACE — sibling module; absent = every probe is scored on text only and labelled MENTION-ONLY
318
318
  import live_eval_trace as _trace
@@ -529,6 +529,7 @@ def score_run(live_rows, run_root, ids_in_order, threshold, model, reps=1):
529
529
  except (ValueError, re.error) as e:
530
530
  behave_err, behave = str(e), None
531
531
  inventories, inv_unknown, traces, no_trace, b_reps = set(), 0, {}, 0, []
532
+ inv_parts = {} # inventory string → its three sets, so the INVALID reason can name the difference
532
533
  damaged, any_trace = 0, False
533
534
  ctrl_b_absent = False # rep-1 only, diagnostic: which arm actually produced nothing
534
535
  per_rep = [] # [(verdict, phit, chit, primary_text, control_text)]
@@ -569,6 +570,7 @@ def score_run(live_rows, run_root, ids_in_order, threshold, model, reps=1):
569
570
  inv = _trace.inventory(tr)
570
571
  if inv is not None:
571
572
  inventories.add(inv)
573
+ inv_parts[inv] = _trace.inventory_parts(tr)
572
574
  elif tr is not None:
573
575
  inv_unknown += 1
574
576
  traces[(arm, i)] = tr
@@ -633,10 +635,16 @@ def score_run(live_rows, run_root, ids_in_order, threshold, model, reps=1):
633
635
  elif behave and any_trace and (no_trace or damaged):
634
636
  row['reason'] = 'TRACE-INCOMPLETE: %d rep(s) missing an arm trace · %d damaged stream(s)' % (no_trace, damaged)
635
637
  elif len(inventories) > 1:
636
- row['reason'] = 'INVALID-COMPARISON: arms saw %d different tool/MCP lists — %s' % (
637
- len(inventories), ' ≠ '.join(sorted(inventories)))
638
+ # Name what differs FIRST (2026-11-20 weekly audit: two 840-char lists side by side, the
639
+ # diff left to a human, INVALID rose 0→3/12 unexplained); the full lists still follow.
640
+ _d = _trace.surface_diff([inv_parts[x] for x in sorted(inventories)])
641
+ row['reason'] = 'INVALID-COMPARISON: arms saw %d different tool/MCP/plugin lists — %s%s' % (
642
+ len(inventories), ('not in every arm: %s — ' % (_d or 'none — the lists differ only in duplicates or count')),
643
+ ' ≠ '.join(sorted(inventories)))
638
644
  if len(ran_reps) > 1 and 0 < len(pass_reps) < len(ran_reps):
639
- row['reason'] = 'FLAKY across reps (%s)' % ','.join(r[0] for r in per_rep)
645
+ flaky = 'FLAKY across reps (%s)' % ','.join(r[0] for r in per_rep)
646
+ # an INVALID-COMPARISON reason must survive: the surface mismatch is why there is no number
647
+ row['reason'] = (row['reason'] + '; ' + flaky) if verdict == INVALID_COMPARISON and row['reason'] else flaky
640
648
  if adv_pat is not None:
641
649
  row['advisory'] = '%d/%d' % (adv_hits, len(ran_reps) if ran_reps else 0)
642
650
  row['advisory_re'] = adv_re
@@ -979,7 +987,7 @@ def render_report_md(select_result, score_result, run_date, instrument=None):
979
987
  score_result['uncalibrated'], score_result['passed'], pr_s))
980
988
  lines.append("")
981
989
  lines.append("- scored by behaviour: **%d** of %d PASS · MENTION-ONLY: **%d** (a MENTION-ONLY PASS read the "
982
- "reply text; it is not evidence the rule acted) · tool/MCP surfaces in this run: %s"
990
+ "reply text; it is not evidence the rule acted) · tool/MCP/plugin surfaces in this run: %s"
983
991
  % (score_result.get('behaviour_backed', 0), score_result['passed'],
984
992
  score_result.get('mention_only_pass', 0),
985
993
  score_result.get('run_inventories') or 'UNMEASURED (no trace)'))
@@ -1006,7 +1014,7 @@ def render_report_md(select_result, score_result, run_date, instrument=None):
1006
1014
  lines.extend(["## Scored by — behaviour or mention", "",
1007
1015
  "`BEHAVIOUR` = the probe's `behave:` action was read from the event stream in every rep "
1008
1016
  "(primary did it, control did not). `MENTION-ONLY` = the verdict rests on reply text.", "",
1009
- "| Probe | scored_by | behave (primary did · control did) | tool/MCP lists |", "|---|---|---|---|"])
1017
+ "| Probe | scored_by | behave (primary did · control did) | tool/MCP/plugin lists |", "|---|---|---|---|"])
1010
1018
  for r in score_result['rows']:
1011
1019
  lines.append("| %s | %s | %s | %s |" % (r['id'], r.get('scored_by', 'MENTION-ONLY'),
1012
1020
  _md_escape(r.get('behave', '-')), _md_escape(r.get('inventory', '-'))))
@@ -397,6 +397,17 @@ else
397
397
  fail=1
398
398
  fi
399
399
 
400
+ # fh-gate review stage + execution layer (2026-11-19): the built-in /code-review is the default reviewer on
401
+ # the claude backend, its findings carried as labelled; E0 scanners and E1 target lanes run in a copy. Both
402
+ # suites are token-free (stub backends, scratch repos) and ship with the package, as the gate does.
403
+ for _fhg_lane in scripts/test_fh_gate_defaults_lanes.sh scripts/test_fh_gate_exec_lanes.sh scripts/test_fh_gate_fusion_lanes.sh scripts/test_fh_gate_absorb_lanes.sh; do
404
+ if [ -f "$_fhg_lane" ]; then
405
+ bash "$_fhg_lane" || fail=1
406
+ else
407
+ echo "FAIL fh-gate: $_fhg_lane missing"; fail=1
408
+ fi
409
+ done
410
+
400
411
  # pre-push stdin integrity — anchors the 2026-07-20 fail-open hole (a stdin-inheriting subprocess
401
412
  # above the ref loop drains git's ref list → Destructive-Op gate silently allows a delete/force push).
402
413
  # Wired here, not left standalone: an unwired checker is the exact defect this session found in
@@ -513,12 +524,15 @@ if [ ! -f scripts/prepush_guard_check.sh ]; then
513
524
  _absent_subject_verdict "prepush-guard known-pair" "scripts/prepush_guard_check.sh" || fail=1
514
525
  else
515
526
  # 🟥 파이프 앞에서 rc 를 잡는다 — 표시 필터의 rc 를 읽으면 실패가 0 으로 보인다.
527
+ # 🟥 tail -12 로 자르지 않는다 — 하위 소비자가 «BLOCKED — a known pair broke» 만 받고 어느 쌍인지
528
+ # 못 읽은 실사고(2026-11-16, 원인은 UNMEASURED). ❌ 줄을 뽑는 _show_failure 로 보이고, 전체 경과도 찍는다.
529
+ _pg_t0=$SECONDS
516
530
  _pg_out="$(bash scripts/prepush_guard_check.sh 2>&1)"; _pg_rc=$?
517
531
  if [ "$_pg_rc" -eq 0 ]; then
518
532
  echo "PASS prepush-guard known-pair"
519
533
  else
520
- echo "FAIL prepush-guard known-pair (rc=$_pg_rc)"
521
- [ -n "$_pg_out" ] && printf '%s\n' "$_pg_out" | tail -12 | sed 's/^/ /'
534
+ echo "FAIL prepush-guard known-pair (rc=$_pg_rc, $((SECONDS - _pg_t0))s)"
535
+ _show_failure "$_pg_out"
522
536
  fail=1
523
537
  fi
524
538
  fi
@@ -1182,7 +1196,10 @@ for _pair in \
1182
1196
  "scripts/destructive_pre_gate.sh|scripts/test_destructive_pre_gate_lanes.sh" \
1183
1197
  "scripts/probe_live_eval_lib.py|scripts/test_live_eval_transitions_lanes.sh" \
1184
1198
  "scripts/correction_moments.py|scripts/test_correction_moments_lanes.sh" \
1199
+ "scripts/below_floor_scan.sh|scripts/test_below_floor_scan_lanes.sh" \
1200
+ "scripts/job_heartbeat.py|scripts/test_job_heartbeat_lanes.sh" \
1185
1201
  "scripts/probe_live_eval_lib.py|scripts/test_live_eval_construct_lanes.sh" \
1202
+ "scripts/live_eval_matrix.py|scripts/test_live_eval_matrix_lanes.sh" \
1186
1203
  "scripts/live_eval_trace.py|scripts/test_live_eval_trace_lanes.sh" \
1187
1204
  "scripts/probe_live_eval_lib.py|scripts/test_live_eval_trace_lanes.sh" \
1188
1205
  "scripts/sim_isolated_run.sh|scripts/test_live_eval_trace_lanes.sh" \
@@ -1221,6 +1238,14 @@ for _pair in \
1221
1238
  "plugins/fh-meta/skills/frontier-digest/SKILL.md|scripts/test_frontier_digest_recall.sh" \
1222
1239
  "scripts/test_frontier_digest_recall.sh|scripts/test_frontier_digest_recall_negctl.sh" \
1223
1240
  "scripts/fh_module_check.py|scripts/test_fh_module_check_lanes.sh" \
1241
+ "scripts/heavy_skill_smell.py|scripts/test_heavy_skill_smell_lanes.sh" \
1242
+ "scripts/cartridge_loader.py|scripts/test_cartridge_loader_lanes.sh" \
1243
+ "scripts/scoreboard_render.py|scripts/test_scoreboard_render_lanes.sh" \
1244
+ "scripts/fh_gate_exec.sh|scripts/test_fh_gate_exec_lanes.sh" \
1245
+ "scripts/fh-gate.sh|scripts/test_fh_gate_fusion_lanes.sh" \
1246
+ "scripts/fh-gate.sh|scripts/test_fh_gate_absorb_lanes.sh" \
1247
+ "scripts/fh-gate.sh|scripts/test_fh_gate_defaults_lanes.sh" \
1248
+ "scripts/fh_techwriter_sync_check.sh|scripts/test_fh_techwriter_sync_lanes.sh" \
1224
1249
  "scripts/knowledge_seam_check.sh|scripts/test_knowledge_seam_lanes.sh" \
1225
1250
  "templates/.git-hooks/pre-commit|scripts/test_marker_crossfamily_lanes.sh" \
1226
1251
  "templates/.git-hooks/pre-commit|scripts/test_marker_floor_lanes.sh" \
@@ -1868,6 +1893,52 @@ else
1868
1893
  echo "FAIL test_sidecar_calibrate_lanes.sh: sidecar_calibrate.sh present but its anchor is missing"
1869
1894
  fail=1
1870
1895
  fi
1896
+ # agy launch guard (2026-11-16). The guard is the only thing between an FH script and a cloud agent
1897
+ # CLI that reads this machine and sends what it read to the model; its lanes use fake agy stubs only.
1898
+ if [ ! -f scripts/agy_launch_guard.sh ]; then
1899
+ _absent_subject_verdict "test_agy_launch_guard_lanes.sh" "scripts/agy_launch_guard.sh" || fail=1
1900
+ elif [ -f scripts/test_agy_launch_guard_lanes.sh ]; then
1901
+ if ! bash scripts/test_agy_launch_guard_lanes.sh < /dev/null; then
1902
+ fail=1
1903
+ fi
1904
+ else
1905
+ echo "FAIL test_agy_launch_guard_lanes.sh: agy_launch_guard.sh present but its anchor is missing"
1906
+ fail=1
1907
+ fi
1908
+ # agy remote runner (2026-11-16) — the only route the guard's remote-os-user marker opens; its lanes use a fake ssh/scp.
1909
+ if [ ! -f scripts/agy_remote_run.sh ]; then
1910
+ _absent_subject_verdict "test_agy_remote_run_lanes.sh" "scripts/agy_remote_run.sh" || fail=1
1911
+ elif [ -f scripts/test_agy_remote_run_lanes.sh ]; then
1912
+ if ! env -u FH_AGY_REMOTE -u FH_AGY_REMOTE_DENY -u FH_AGY_REMOTE_RECEIPT_DIR bash scripts/test_agy_remote_run_lanes.sh < /dev/null; then
1913
+ fail=1
1914
+ fi
1915
+ else
1916
+ echo "FAIL test_agy_remote_run_lanes.sh: agy_remote_run.sh present but its anchor is missing"
1917
+ fail=1
1918
+ fi
1919
+ # codex launch guard (2026-11-16) — refuses a codex verifier arm whose prompt/args/cwd name a company root.
1920
+ if [ ! -f scripts/codex_launch_guard.sh ]; then
1921
+ _absent_subject_verdict "test_codex_launch_guard_lanes.sh" "scripts/codex_launch_guard.sh" || fail=1
1922
+ elif [ -f scripts/test_codex_launch_guard_lanes.sh ]; then
1923
+ if ! bash scripts/test_codex_launch_guard_lanes.sh < /dev/null; then
1924
+ fail=1
1925
+ fi
1926
+ else
1927
+ echo "FAIL test_codex_launch_guard_lanes.sh: codex_launch_guard.sh present but its anchor is missing"
1928
+ fail=1
1929
+ fi
1930
+ # prepush-guard failure visibility (2026-11-16) — a broken known pair must be named, with rc and
1931
+ # elapsed, in the last lines of the check and in selfcheck's own rendering of it.
1932
+ if [ ! -f scripts/prepush_guard_check.sh ]; then
1933
+ _absent_subject_verdict "test_prepush_guard_failure_visibility_lanes.sh" "scripts/prepush_guard_check.sh" || fail=1
1934
+ elif [ -f scripts/test_prepush_guard_failure_visibility_lanes.sh ]; then
1935
+ if ! bash scripts/test_prepush_guard_failure_visibility_lanes.sh < /dev/null; then
1936
+ fail=1
1937
+ fi
1938
+ else
1939
+ echo "FAIL test_prepush_guard_failure_visibility_lanes.sh: prepush_guard_check.sh present but its anchor is missing"
1940
+ fail=1
1941
+ fi
1871
1942
  # Squash-merge verification + its merge-path wiring (2026-09-24). Same subject/anchor pairing as above:
1872
1943
  # both scripts return verdict exit codes, and pr_merge_verified's whole job is to REFUSE before merging —
1873
1944
  # a refusal nobody re-runs is one the next edit quietly removes. Lanes are hermetic (temp repos, fake gh).
@@ -2174,6 +2245,28 @@ else
2174
2245
  fail=1
2175
2246
  fi
2176
2247
 
2248
+ # prepush_marker_lookup — the pre-push Load-Bearing gate reads this branch's marker where pre-commit
2249
+ # writes it (the evidence root), not a path only the main checkout has.
2250
+ if [ -f scripts/test_prepush_marker_lookup_lanes.sh ]; then
2251
+ if ! bash scripts/test_prepush_marker_lookup_lanes.sh; then
2252
+ fail=1
2253
+ fi
2254
+ else
2255
+ echo "FAIL test_prepush_marker_lookup_lanes.sh: absent — the pre-push marker lookup has no lane"
2256
+ fail=1
2257
+ fi
2258
+
2259
+ # guard_anchor_override_env — the two guard anchors (universal_guard_check.sh · prepush_guard_check.sh)
2260
+ # must measure the hook's default whatever override the caller exported (PUBLIC_SURFACE_OK=1 …).
2261
+ if [ -f scripts/test_guard_anchor_override_env_lanes.sh ]; then
2262
+ if ! bash scripts/test_guard_anchor_override_env_lanes.sh; then
2263
+ fail=1
2264
+ fi
2265
+ else
2266
+ echo "FAIL test_guard_anchor_override_env_lanes.sh: absent — the anchors' override scrub has no lane"
2267
+ fail=1
2268
+ fi
2269
+
2177
2270
  # And the ablation calibrator, for the third instance of the same reason. Its whole job is telling
2178
2271
  # apart states that look identical from outside — "the arm could not answer" vs "the runner is dead"
2179
2272
  # vs "the runner read the answer off disk" — and round 2 of its own adversarial review found that
@@ -2649,6 +2742,62 @@ else
2649
2742
  fail=1
2650
2743
  fi
2651
2744
 
2745
+ # fh_module_check.py — the REAL-CORPUS arm. Wired 2026-11-16 (clean-room audit round 9) because the
2746
+ # 19 RD fixture lanes in test_fh_module_check_lanes.sh measure the CHECKER and nothing measured its
2747
+ # SUBJECTS. Three `fh-module.yaml` manifests ship (plugins/fh-commons/skills/{ko-tech-writer,
2748
+ # persona-cast,convergence-loop}) and no standing channel ever ran the install-time check over them:
2749
+ # measured with grep over scripts/, templates/.git-hooks/ and .github/ — 0 callers, the only hits
2750
+ # being this file's pair declaration, the spec, CATALOG.md and the lane suite's own fixtures.
2751
+ # plugins/fh-meta/CHANGELOG.md asserts "The three modules in this package pass". That was true when
2752
+ # measured by hand (all three rc 0, re-measured 2026-11-16) and had NO channel behind it, so a drift
2753
+ # in a manifest, or in a shipped .py inside one of those skills, would have been found by the
2754
+ # consumer installing the module rather than here. The install-time verdict is exactly what a
2755
+ # context-less clone user meets first, which is why it belongs in this file and not in a lane.
2756
+ # Package mode is decided by BOTH sides being absent — the `probe_scope_check.sh` idiom two blocks
2757
+ # up, whose own comment earns the rule that over-blocking the normal case is a defect too.
2758
+ # The subject's exit contract, from its own header: 0 OK · 1 BLOCK · 2 UNMEASURED ·
2759
+ # 3 OK-but-UNCALIBRATED, which it calls "never a clean pass" — so 2 and 3 are NOT passes here. They
2760
+ # print at the LINE HEAD as `INCOMPLETE fh-module …` rather than only as a ⬜ decoration, because a
2761
+ # non-pass written in a local decoration is one the next round's log diff cannot count (round 8).
2762
+ # Why not `_show_failure`: that helper extracts ❌-marked lines from a SUITE's output, and this
2763
+ # subject speaks a different vocabulary — `BLOCK:`/`UNMEASURED:`/`RESULT:` lines. Handing it this
2764
+ # output would print the trailing NOTE instead of the reason, so the reason is lifted directly.
2765
+ _fmc_why() { printf '%s\n' "$1" | grep -E '^(BLOCK|UNMEASURED|UNCAL|RESULT):' | head -6 | sed 's/^/ /'; }
2766
+ _fmc_manifests=$(find . -name fh-module.yaml -not -path './node_modules/*' -not -path './.git/*' 2>/dev/null | sort)
2767
+ # `wc -l` over a sed-stripped list rather than `grep -c . || true`: grep exits 1 on a zero count, so
2768
+ # the obvious form needs a `|| true`, and a short-circuit to a permissive value is the exact shape
2769
+ # degrade_direction_scan.sh exists to flag. `wc` always exits 0, so the count needs no rescue.
2770
+ _fmc_n=$(printf '%s\n' "$_fmc_manifests" | sed '/^[[:space:]]*$/d' | wc -l | tr -d ' ')
2771
+ if [ ! -f scripts/fh_module_check.py ] && [ "$_fmc_n" -eq 0 ]; then
2772
+ echo "SKIP fh_module_check.py corpus (package mode: neither the checker nor any fh-module.yaml is here)"
2773
+ elif [ ! -f scripts/fh_module_check.py ]; then
2774
+ echo "FAIL fh_module_check.py corpus: $_fmc_n manifest(s) present but the checker is missing — the install-time verdict is UNMEASURED, not clean"
2775
+ fail=1
2776
+ elif [ "$_fmc_n" -eq 0 ]; then
2777
+ echo "FAIL fh_module_check.py corpus: the checker is here but no fh-module.yaml was found — the corpus vanished; UNMEASURED, not clean"
2778
+ fail=1
2779
+ else
2780
+ _fmc_bad=0
2781
+ while IFS= read -r _m; do
2782
+ [ -n "$_m" ] || continue
2783
+ _out=$(python3 scripts/fh_module_check.py check "$_m" 2>&1); _rc=$?
2784
+ case "$_rc" in
2785
+ 0) echo "PASS fh-module ${_m#./} (install-time check: OK)" ;;
2786
+ 1) echo "FAIL fh-module ${_m#./}: BLOCK (rc 1) — this module would be refused at install time"
2787
+ _fmc_why "$_out"; _fmc_bad=1 ;;
2788
+ 2) echo "INCOMPLETE fh-module ${_m#./}: ⬜ UNMEASURED (rc 2 — unreadable, tooling down, or empty core list). NOT a pass"
2789
+ _fmc_why "$_out"; _fmc_bad=1 ;;
2790
+ 3) echo "INCOMPLETE fh-module ${_m#./}: ⬜ OK-but-UNCALIBRATED (rc 3) — the subject's own contract calls this never a clean pass"
2791
+ _fmc_bad=1 ;;
2792
+ *) echo "INCOMPLETE fh-module ${_m#./}: ⬜ the checker exited $_rc, outside its documented 0/1/2/3 contract — UNMEASURED"
2793
+ _fmc_why "$_out"; _fmc_bad=1 ;;
2794
+ esac
2795
+ done <<_FMC_EOF
2796
+ $_fmc_manifests
2797
+ _FMC_EOF
2798
+ [ "$_fmc_bad" -eq 0 ] || fail=1
2799
+ fi
2800
+
2652
2801
  # utterance landing check — the close chain's CONTENT anchor, and it has to be RUN, not parsed.
2653
2802
  # Measured 2026-08-08 on the branch that introduced it: the only thing in this file that touched
2654
2803
  # `scripts/utterance_landing_check.sh` was the `bash -n` syntax sweep at the top. Syntax passing is
@@ -3077,6 +3226,17 @@ fi
3077
3226
  # Lane-identity tripwire — record-only: a WARN line, never a FAIL (a hit is a past event in the
3078
3227
  # repo, not this run's verdict). Runs AFTER the lanes, which is when a leaked commit would have just landed.
3079
3228
  if [ -f scripts/lane_identity_tripwire.sh ]; then bash scripts/lane_identity_tripwire.sh . | grep -v '^LANE-TRIPWIRE ok' ; fi
3229
+ # fh-techwriter copy sync (2026-11-19) — record-only: an INFO line, never a FAIL. The copy lives in another
3230
+ # repository and is regenerated and pushed there by a human, so its state is not this tree's verdict. Shard 1
3231
+ # only, source tree only. Exit 2 (no copy here, export failed) prints «not measured», never «in sync».
3232
+ if [ -f scripts/fh_techwriter_sync_check.sh ] && [ "$_CONSUMER" -ne 1 ] && { [ -z "${_SHARD_N:-}" ] || [ "${_SHARD_I:-1}" = 1 ]; }; then
3233
+ _tw=$(bash scripts/fh_techwriter_sync_check.sh </dev/null 2>&1); _twrc=$?
3234
+ case "$_twrc" in
3235
+ 0) echo "INFO fh-techwriter copy: in sync — $(printf '%s\n' "$_tw" | grep '^fh-techwriter sync:' | cut -c21-)";;
3236
+ 1) printf '%s\n' "$_tw" | sed 's/^/INFO fh-techwriter copy: /';;
3237
+ *) echo "INFO fh-techwriter copy: not measured — $(printf '%s\n' "$_tw" | tail -1)";;
3238
+ esac
3239
+ fi
3080
3240
  if [ "$_CONSUMER" -eq 1 ]; then
3081
3241
  _n=$(printf '%s\n' $CONSUMER_SKIPPED | grep -c .)
3082
3242
  echo "CONSUMER PROFILE — $_n checkout-only suite(s) NOT measured here (not a pass):$CONSUMER_SKIPPED"
@@ -57,6 +57,8 @@
57
57
  4 test_degrade_scan_shell_probes.sh
58
58
  4 test_destructive_pre_gate_lanes.sh
59
59
  4 test_fh_module_check_lanes.sh
60
+ 3 test_heavy_skill_smell_lanes.sh
61
+ 4 test_cartridge_loader_lanes.sh
60
62
  4 test_heavy_classifier_lanes.sh
61
63
  4 test_marker_first_use_lanes.sh
62
64
  4 test_memory_link_check.sh
@@ -660,21 +660,119 @@ def _cells(line):
660
660
 
661
661
 
662
662
  CARRY_HEADING = "## 이전 결과서에서 이어받지 못한 판정"
663
+ KEEP_HEADING = "## 이전 결과서의 표 밖 내용 (extract 가 다시 만들지 않는 줄 — 원래 순서)"
664
+ # Lines do_extract writes itself, matched by their WHOLE shape (a stale copy, whose counts changed between runs, is not
665
+ # the operator's content). Whole-line, not prefix: a note the person starts with «🟥 훅 기록 …» or appends to a status
666
+ # line is theirs and must survive (independent review 2026-11-15 reproduced prefix matching dropping both).
667
+ _GENERATED_LINE_RES = tuple(re.compile(p) for p in (
668
+ r"^# 세션 요청 체크리스트 \(스켈레톤\) — [^\n]+$",
669
+ r"^채널 2/2 열음 — raw \d+건 · 압축 요약 \d+건\(중복 제거 후 \d+건 추가\)$",
670
+ "^" + chr(0x1F4CE) + r" 원장 = .* \(\d+ lines\)$",
671
+ r"^🟥 JSONL 파싱 실패 \d+줄 — 그 줄의 발화는 이 표에 없다 \(rc=2\)$",
672
+ r"^🪝 훅 기록 채널 읽음 — \d+건 · 전사와 일치 \d+건 · 훅 전용 \d+건 \(행 번호 H = 훅 전용, S = 요약, 숫자 = 전사\)$",
673
+ r"^🟨 훅 기록 채널 안 읽음 — 파일 없음: .* \(0건이 아니라 미열람; 훅이 안 걸렸거나 다른 허브일 수 있다\)$",
674
+ r"^🟥 훅 기록 채널 오류 — .*: .* \(rc=2; 전사 행은 그대로 아래에 있다\)$",
675
+ r"^🟥 훅 기록 \d+줄 해석 실패 — 그 줄의 발화는 이 표에 없을 수 있다 \(rc=2\)$",
676
+ r"^↩️ 이전 결과서에서 판정 \d+줄 이어받음 · 못 맞춘 판정 \d+줄은 맨 아래 «이전 결과서에서 이어받지 못한 판정»에 보존"
677
+ r"( · 표 밖 줄 \d+줄은 맨 아래 «이전 결과서의 표 밖 내용»에 보존)?$",
678
+ ))
679
+ _GENERATED_ROW_ID_RE = re.compile(r"^(\d+|H\d+|S\d+)$") # the «#» ids do_extract writes: 7 · H2 · S1
680
+ _GENERATED_HEADER = "| # | 시각 | 발화(요지) | 상태 | 증거 | 사유 / 남은 것 | 제안(이번 세션 vs 이월) |"
681
+ _GENERATED_SEPARATOR = "|---|---|---|---|---|---|---|"
682
+
683
+
684
+ def _carry_skip(c):
685
+ """rows carry_forward never reads as a checklist row: a header («#» · empty first cell) or a separator in any
686
+ markdown spelling. ONE definition for both passes — when carry_forward skipped a row and _unconsumed assumed
687
+ carry_forward had it, the row vanished (review R3: «| --- | … |», «| :--- | … |», a person's «| # | … |» header)."""
688
+ if c[0] in ("#", "") or all(re.fullmatch(r":?-+:?", x) for x in c):
689
+ return True
690
+ return c[0] != "-" and set(c[0]) <= set("-") # «-» alone is an orphan row, not a separator
691
+
692
+
693
+ def _is_generated(line):
694
+ return line in (CARRY_HEADING, KEEP_HEADING) or any(r.match(line) for r in _GENERATED_LINE_RES)
695
+
696
+
697
+ def _fenced(old):
698
+ """indices of lines inside a CLOSED fenced code block, markers included — a person's code is kept verbatim, never
699
+ read as table rows or separators (review 2026-11-15). Same opener rule as load_tables (FENCE_RE: same character,
700
+ closer at least as long). An unclosed fence is ignored here, and so is an opener whose closer lies beyond extract's
701
+ own table header: either way the live table was swallowed and every judgment below it detached (review R2)."""
702
+ idx, opened = set(), None # opened = (index, char, length)
703
+ for i, l in enumerate(old):
704
+ if l == _GENERATED_HEADER and opened is not None:
705
+ opened = None # a fence never spans extract's own table: an opener above it is unclosed (review R2 repro)
706
+ continue
707
+ m = FENCE_RE.match(l)
708
+ if not m:
709
+ continue
710
+ tick = m.group(1)
711
+ if opened is None:
712
+ opened = (i, tick[0], len(tick))
713
+ elif tick[0] == opened[1] and len(tick) >= opened[2] and l.strip() == tick:
714
+ idx.update(range(opened[0], i + 1)); opened = None
715
+ return idx
716
+
717
+
718
+ def _unconsumed(old, lines_out):
719
+ """lines of the previous sheet that the table parser does not consume and extract does not regenerate —
720
+ a result-sheet section written below the table, a preface above it, prose between (2026-11-14 harvest H3: 13 such
721
+ lines vanished on one re-extract), closed fenced code verbatim, a person's own 7-column separator, and a hand-added
722
+ row with empty judgment cells whose «#» is not an id extract writes. Kept in their original order; outside fences blank runs collapse and edges are
723
+ trimmed, so a re-run over its own output yields the same block (idempotent)."""
724
+ regenerated = set(lines_out)
725
+ fenced = _fenced(old)
726
+ kept = []
727
+ for i, l in enumerate(old):
728
+ if i in fenced:
729
+ kept.append(l); continue
730
+ if not l.strip():
731
+ if kept and kept[-1] != "":
732
+ kept.append("")
733
+ continue
734
+ if l == _GENERATED_SEPARATOR:
735
+ # regenerated only where extract writes it — right under its own header; a person's 7-column table keeps it
736
+ if i > 0 and old[i - 1] == _GENERATED_HEADER:
737
+ continue
738
+ kept.append(l); continue
739
+ if l in regenerated or _is_generated(l):
740
+ continue
741
+ c = _cells(l)
742
+ if c is not None:
743
+ # a row carry_forward reads (not _carry_skip, has a judgment) is carried or orphaned there; an empty row
744
+ # with an id extract writes (7 · H2 · S1) is a skeleton row from some run — never the person's content,
745
+ # even when this run no longer writes it (review R2). Everything else — a person's own header, separator
746
+ # or empty labelled row — is kept here (the generated header was already dropped as `regenerated`).
747
+ if not _carry_skip(c) and any(c[3:]):
748
+ continue # carry_forward carries or orphans it
749
+ if not _carry_skip(c) and _GENERATED_ROW_ID_RE.match(c[0]):
750
+ continue # an empty skeleton row from some run
751
+ kept.append(l)
752
+ while kept and kept[-1] == "":
753
+ kept.pop()
754
+ return kept
663
755
 
664
756
 
665
757
  def carry_forward(lines_out, out_path):
666
758
  try:
667
759
  with open(out_path, "r", encoding="utf-8", errors="replace") as f:
668
- old = f.read().split("\n")
760
+ text = f.read()
669
761
  except OSError:
670
762
  return lines_out
763
+ old = (text[1:] if text.startswith("\ufeff") else text).split("\n") # a BOM (Notepad) broke every ^-anchored match
671
764
  prev, orphans_prev = {}, []
672
765
  in_orphans = False
673
- for l in old:
766
+ fenced = _fenced(old)
767
+ for i, l in enumerate(old):
768
+ if i in fenced:
769
+ continue # a person's code block: kept verbatim by _unconsumed
674
770
  if l.startswith(CARRY_HEADING):
675
771
  in_orphans = True; continue
676
772
  c = _cells(l)
677
- if not c or c[0] in ("#", "---") or set(c[0]) <= set("-"):
773
+ # «-» alone is how an orphan row is written (below) — not a separator. Reading it as one dropped every orphan
774
+ # judgment on the SECOND re-extract (found 2026-11-15 by the idempotency lane L55; origin/main reproduces it).
775
+ if not c or _carry_skip(c):
678
776
  continue
679
777
  if not any(c[3:]):
680
778
  continue # an empty row has nothing to carry
@@ -691,11 +789,17 @@ def carry_forward(lines_out, out_path):
691
789
  out.append(l)
692
790
  orphans = ["| %s | %s | %s | %s | %s | %s | %s |" % ((("-",) + k + tuple(v))) for k, vs in prev.items() for v in vs]
693
791
  orphans += orphans_prev
694
- if used or orphans:
695
- out.insert(4, "↩️ 이전 결과서에서 판정 %d줄 이어받음 · 못 맞춘 판정 %d줄은 맨 아래 «이전 결과서에서 이어받지 못한 판정»에 보존" % (used, len(orphans)))
792
+ kept = _unconsumed(old, lines_out)
793
+ if used or orphans or kept:
794
+ msg = "↩️ 이전 결과서에서 판정 %d줄 이어받음 · 못 맞춘 판정 %d줄은 맨 아래 «이전 결과서에서 이어받지 못한 판정»에 보존" % (used, len(orphans))
795
+ if kept:
796
+ msg += " · 표 밖 줄 %d줄은 맨 아래 «이전 결과서의 표 밖 내용»에 보존" % sum(1 for l in kept if l)
797
+ out.insert(4, msg)
696
798
  if orphans:
697
799
  out += ["", CARRY_HEADING, "", "| # | 시각 | 발화(요지) | 상태 | 증거 | 사유 / 남은 것 | 제안(이번 세션 vs 이월) |",
698
800
  "|---|---|---|---|---|---|---|"] + orphans
801
+ if kept:
802
+ out += ["", KEEP_HEADING, ""] + kept
699
803
  return out
700
804
 
701
805