@chrono-meta/fh-gate 3.27.0 → 3.29.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 (71) hide show
  1. package/.claude-plugin/marketplace.json +4 -4
  2. package/CHEATSHEET.md +2 -2
  3. package/CLAUDE.md +6 -3
  4. package/README.ja.md +2 -4
  5. package/README.ko.md +2 -4
  6. package/README.md +19 -19
  7. package/README.zh.md +2 -4
  8. package/docs/REFERENCE.md +4 -1
  9. package/knowledge/shared/harness-core/claude_md_full_reference.md +2 -0
  10. package/knowledge/shared/harness-core/claude_md_gate_details.md +7 -0
  11. package/knowledge/shared/harness-core/dispatch_conditional_prohibition.md +12 -0
  12. package/knowledge/shared/harness-core/fh_module_contract.md +97 -0
  13. package/knowledge/shared/harness-core/fh_three_layer_canon.md +12 -0
  14. package/knowledge/shared/harness-core/measurement-integrity-checklist.md +16 -0
  15. package/knowledge/shared/learnings/subagent_invocations_log.yaml +137 -0
  16. package/package.json +12 -1
  17. package/plugins/fh-commons/.claude-plugin/plugin.json +1 -1
  18. package/plugins/fh-commons/skills/ko-tech-writer/SKILL.md +84 -4
  19. package/plugins/fh-commons/skills/ko-tech-writer/fh-module.yaml +19 -0
  20. package/plugins/fh-commons/skills/ko-tech-writer/fixtures/known_negative.md +73 -1
  21. package/plugins/fh-commons/skills/ko-tech-writer/fixtures/known_positive.md +39 -1
  22. package/plugins/fh-commons/skills/ko-tech-writer/fixtures/known_unclosed.md +6 -0
  23. package/plugins/fh-meta/.claude-plugin/plugin.json +1 -1
  24. package/plugins/fh-meta/CHANGELOG.md +32 -0
  25. package/plugins/fh-meta/skills/auto-decorrelation/SKILL.md +17 -0
  26. package/plugins/fh-meta/skills/frontier-digest/SKILL.md +14 -10
  27. package/plugins/fh-meta/skills/frontier-digest/SKILL_detail.md +17 -1
  28. package/plugins/fh-meta/skills/sim-conductor/SKILL.md +2 -2
  29. package/plugins/fh-meta/skills/sim-conductor/SKILL_detail.md +3 -3
  30. package/plugins/fh-meta/skills/steel-quench/SKILL.md +25 -1
  31. package/plugins/fh-preprep/.claude-plugin/plugin.json +1 -1
  32. package/plugins/fh-qp/.claude-plugin/plugin.json +1 -1
  33. package/scripts/degrade_direction_scan.sh +43 -0
  34. package/scripts/dispatch_receipt.py +185 -0
  35. package/scripts/doc_claim_triad_scan.py +43 -4
  36. package/scripts/fh-gate.sh +71 -11
  37. package/scripts/fh_module_check.py +686 -0
  38. package/scripts/finding_fleet.sh +15 -3
  39. package/scripts/fixtures/frontier_digest_recall.tsv +5 -0
  40. package/scripts/ko_tech_writer_calibrate.py +288 -15
  41. package/scripts/package_coverage_check.sh +5 -0
  42. package/scripts/probe_live_eval.sh +19 -1
  43. package/scripts/probe_live_eval_lib.py +174 -5
  44. package/scripts/resident_cost.py +1 -1
  45. package/scripts/selfcheck.sh +48 -21
  46. package/scripts/session_checklist.py +214 -5
  47. package/scripts/session_close_check.sh +44 -0
  48. package/scripts/sim_isolated_run.sh +31 -0
  49. package/scripts/test_claude_md_size_lanes.sh +22 -7
  50. package/scripts/test_degrade_scan_shell_probes.sh +81 -0
  51. package/scripts/test_dispatch_receipt_lanes.sh +95 -0
  52. package/scripts/test_doc_claim_triad_lanes.sh +30 -0
  53. package/scripts/test_fh_audit_check_lanes.sh +10 -5
  54. package/scripts/test_fh_gate_regressions.sh +71 -1
  55. package/scripts/test_fh_module_check_lanes.sh +581 -0
  56. package/scripts/test_finding_pipeline_lanes.sh +83 -0
  57. package/scripts/test_frontier_digest_recall.sh +26 -0
  58. package/scripts/test_frontier_digest_recall_negctl.sh +15 -0
  59. package/scripts/test_ko_tech_writer_lanes.sh +1 -1
  60. package/scripts/test_locale_invariance_lanes.sh +19 -0
  61. package/scripts/test_mutation_probe_lanes.sh +22 -6
  62. package/scripts/test_probe_live_eval_lanes.sh +116 -0
  63. package/scripts/test_resident_cost_lanes.sh +1 -1
  64. package/scripts/test_selfcheck_state_lanes.sh +32 -0
  65. package/scripts/test_session_checklist_lanes.sh +167 -0
  66. package/scripts/test_sim_isolated_run_lanes.sh +51 -0
  67. package/scripts/test_utterance_checklist_hook_lanes.sh +175 -0
  68. package/scripts/utterance_checklist_hook.py +193 -0
  69. package/scripts/utterance_checklist_hook.sh +31 -0
  70. package/templates/PRE-PUBLISH-CHECKLIST.md +10 -0
  71. package/templates/degrade_direction_scan.sh +43 -0
@@ -0,0 +1,175 @@
1
+ #!/usr/bin/env bash
2
+ # Lanes for scripts/utterance_checklist_hook.sh (UserPromptSubmit: capture · cadence nudge · language line).
3
+ # Every lane runs the real hook against a temp CLAUDE_PROJECT_DIR — nothing touches the real hub.
4
+ # Known pairs: Korean ↔ English prompt (language line present ↔ absent) · content ↔ ack (row ↔ counted only) ·
5
+ # cadence row N ↔ N+1 (nudge ↔ none) · good ↔ broken input (output ↔ silent, both rc 0).
6
+ set -u
7
+ HERE="$(cd "$(dirname "$0")" && pwd)"
8
+ HOOK="$HERE/utterance_checklist_hook.sh"
9
+ pass=0; fail=0
10
+ ok() { pass=$((pass+1)); echo " PASS $1"; }
11
+ no() { fail=$((fail+1)); echo " FAIL $1 — $2"; }
12
+ [ -f "$HOOK" ] || { echo "HARNESS-ERROR: hook missing"; exit 10; }
13
+ T="$(mktemp -d)"; trap 'rm -rf "$T"' EXIT
14
+ SID="0123abcd-0000-4000-8000-000000000001"
15
+ run() { # $1 prompt [$2 sid] → stdout; rc in $RC
16
+ local p="$1" s="${2:-$SID}"
17
+ OUT=$(python3 -c 'import json,sys;print(json.dumps({"prompt":sys.argv[1],"session_id":sys.argv[2],"transcript_path":"/x/t.jsonl","hook_event_name":"UserPromptSubmit"}))' "$p" "$s" | CLAUDE_PROJECT_DIR="$T" FH_CHECKLIST_CADENCE="${CAD:-15}" bash "$HOOK"); RC=$?
18
+ }
19
+ D="$T/tracks/_meta/utterances"
20
+
21
+ # U1 language line: Korean → present, English → absent
22
+ run "세션바를 조금 더 위로 올려 줘"
23
+ [ $RC = 0 ] && printf '%s' "$OUT" | grep -q '이번 메시지를 한글로' && ok "U1a Korean prompt → language line" || no U1a "rc=$RC out=$OUT"
24
+ run "please move the session bar up a little"
25
+ [ $RC = 0 ] && ! printf '%s' "$OUT" | grep -q '한글로' && ok "U1b English prompt → no language line" || no U1b "rc=$RC out=$OUT"
26
+
27
+ # U2 content is written down; a short ack is counted, not listed
28
+ rows_before=$(wc -l < "$D/$SID.jsonl" 2>/dev/null | tr -d " " || echo 0)
29
+ run "ㅇㅇ"
30
+ rows_after=$(wc -l < "$D/$SID.jsonl" 2>/dev/null | tr -d " " || echo 0)
31
+ acks=$(python3 -c 'import json,sys;print(json.load(open(sys.argv[1]))["acks"])' "$D/$SID.state.json" 2>/dev/null)
32
+ [ "$rows_before" = "$rows_after" ] && [ "$acks" = 1 ] && ok "U2a ack → counted (acks=1), no row" || no U2a "rows ${rows_before}→${rows_after} acks=${acks}"
33
+ [ "$rows_before" = 2 ] && python3 -c 'import json,sys;r=[json.loads(l) for l in open(sys.argv[1])];assert r[0]["text"].startswith("세션바") and r[0]["n"]==1' "$D/$SID.jsonl" && ok "U2b content prompts → rows with text and n" || no U2b "rows=$rows_before"
34
+ run "왜 이게 떠?" # short but a question → a row
35
+ [ "$(wc -l < "$D/$SID.jsonl" | tr -d " ")" = 3 ] && ok "U2c a short question is written down" || no U2c "rows=$(wc -l < "$D/$SID.jsonl" | tr -d " ")"
36
+
37
+ # U3 cadence nudge: with cadence 3, rows 3 and 6 nudge; rows 4 and 5 do not
38
+ S2="0123abcd-0000-4000-8000-000000000002"
39
+ CAD=3
40
+ n=0; got=""
41
+ for p in "첫 번째 요청을 받아 적어 둔다" "두 번째 요청을 받아 적어 둔다" "세 번째 요청을 받아 적어 둔다" "네 번째 요청을 받아 적어 둔다" "다섯 번째 요청을 받아 적어 둔다" "여섯 번째 요청을 받아 적어 둔다"; do # content, not an ack
42
+ n=$((n+1)); run "$p" "$S2"
43
+ printf '%s' "$OUT" | grep -q '체크리스트 점검 시점' && got="$got$n,"
44
+ done
45
+ CAD=15
46
+ [ "$got" = "3,6," ] && ok "U3 cadence 3 → nudges at rows 3 and 6 only" || no U3 "nudged at: $got"
47
+ CAD=3; run "세 번째 다음의 요청 하나를 더 적어 둔다" "0123abcd-0000-4000-8000-000000000003"; run "두 번째 요청을 하나 더 받아 적는다" "0123abcd-0000-4000-8000-000000000003"; run "세 번째 요청을 하나 더 받아 적는다" "0123abcd-0000-4000-8000-000000000003"; CAD=15
48
+ printf '%s' "$OUT" | grep -q "session_checklist.py extract --transcript /x/t.jsonl --out tracks/_meta/session_checklist_" && ok "U3b the nudge names the extract command with this transcript" || no U3b "out=$OUT"
49
+
50
+ # U4 broken input → rc 0, silent; injected notices are not the operator
51
+ for bad in "" "not json" '{"prompt":"안녕하세요 반갑습니다","session_id":"../../etc"}' '{"prompt":"","session_id":"0123abcd-0000"}'; do
52
+ OUT=$(printf '%s' "$bad" | CLAUDE_PROJECT_DIR="$T" bash "$HOOK"); RC=$?
53
+ [ $RC = 0 ] && [ -z "$OUT" ] && ok "U4 bad input silent rc0: ${bad:0:24}" || no U4 "rc=$RC out=$OUT input=$bad"
54
+ done
55
+ ls "$T/etc" >/dev/null 2>&1 && no U4b "path escape created a dir" || ok "U4b a session id with ../ writes nothing outside"
56
+ before=$(wc -l < "$D/$SID.jsonl" | tr -d " "); run "<task-notification>배경 작업이 끝났다 길게 적은 알림</task-notification>"
57
+ [ "$(wc -l < "$D/$SID.jsonl" | tr -d " ")" = "$before" ] && ok "U4c an injected notice is not written down" || no U4c "row added"
58
+ # U4d a subagent hand-back relayed into the prompt is not the operator (first live use: 2 of 15 rows were hand-backs)
59
+ before=$(wc -l < "$D/$SID.jsonl" | tr -d " "); run '<agent-message from="a0000000000000000"> [Subagent hand-back] 체크리스트 259행을 전부 채웠다</agent-message>'
60
+ [ "$(wc -l < "$D/$SID.jsonl" | tr -d " ")" = "$before" ] && ok "U4d a subagent hand-back is not written down" || no U4d "row added"
61
+
62
+ # U5 output is valid JSON with the UserPromptSubmit shape whenever there is output
63
+ run "한글로 된 내용 있는 요청입니다"
64
+ printf '%s' "$OUT" | python3 -c 'import json,sys;o=json.load(sys.stdin);h=o["hookSpecificOutput"];assert h["hookEventName"]=="UserPromptSubmit" and h["additionalContext"]' && ok "U5 output shape" || no U5 "out=$OUT"
65
+
66
+ # U6 the real hub is untouched (control: the temp hub got the files)
67
+ [ -f "$D/$SID.jsonl" ] && [ ! -e "$HERE/../tracks/_meta/utterances/$SID.jsonl" ] && ok "U6 writes only under CLAUDE_PROJECT_DIR" || no U6 "real hub touched or temp missing"
68
+
69
+ # U7 the close chain asks for the result sheet (①-g) and reads session_checklist.py's rc the way that tool defines it
70
+ SCC="$HERE/session_close_check.sh"; SCPY="$HERE/session_checklist.py"
71
+ if grep -q '①-g' "$SCC" && grep -q 'python3 "$_SC_PY" check --file "$_f"' "$SCC"; then ok "U7a ①-g calls session_checklist.py check"; else no U7a "wiring missing"; fi
72
+ grep -q 'session_checklist_\*_"${_UI_SID:0:8}".md' "$SCC" && ok "U7c ①-g selects this session's sheet by id (not any sheet of today)" || no U7c "selection by today only"
73
+ grep -q 'restates it on each mostly-Hangul message' "$HERE/../CLAUDE.md" && grep -q 'every 15 written-down requests' "$HERE/../CLAUDE.md" && ok "U7d CLAUDE.md describes what the hook really does" || no U7d "wording drift"
74
+ cat > "$T/ok.md" <<'MD'
75
+ | # | 발화 | 상태 | 증거 | 사유 | 제안 |
76
+ |---|---|---|---|---|---|
77
+ | 1 | 세션바를 올려 줘 | ✅DONE | FoD #70 | | |
78
+ MD
79
+ cat > "$T/empty.md" <<'MD'
80
+ | # | 발화 | 상태 | 증거 | 사유 | 제안 |
81
+ |---|---|---|---|---|---|
82
+ | 1 | 세션바를 올려 줘 | | | | |
83
+ MD
84
+ python3 "$SCPY" check --file "$T/ok.md" >/dev/null 2>&1; r_ok=$?
85
+ python3 "$SCPY" check --file "$T/empty.md" >/dev/null 2>&1; r_empty=$?
86
+ [ "$r_ok" = 0 ] && [ "$r_empty" = 1 ] && ok "U7b check rc: filled row 0 · empty status 1 (the values ①-g branches on)" || no U7b "rc ok=$r_ok empty=$r_empty"
87
+
88
+ # ── codex R1 (2026-10-18) cases ──
89
+ mk() { python3 -c 'import json,sys;print(json.dumps({"prompt":sys.argv[1],"session_id":sys.argv[2],"transcript_path":sys.argv[3] if len(sys.argv)>3 else "/x/t.jsonl"}))' "$@"; }
90
+ # U8 A1 symlink: a symlinked utterances dir (or file) is refused — nothing lands at the link target
91
+ T2="$(mktemp -d)"; mkdir -p "$T2/tracks/_meta" "$T2/outside"; ln -s "$T2/outside" "$T2/tracks/_meta/utterances"
92
+ mk "심볼릭 링크 너머로 쓰면 안 되는 요청이다" "0123abcd-0000-4000-8000-0000000000a1" | CLAUDE_PROJECT_DIR="$T2" bash "$HOOK" >/dev/null; RC=$?
93
+ [ $RC = 0 ] && [ -z "$(ls -A "$T2/outside")" ] && ok "U8a symlinked dir refused, nothing written at the target" || no U8a "rc=$RC files=$(ls "$T2/outside")"
94
+ T3="$(mktemp -d)"; mkdir -p "$T3/tracks/_meta/utterances" && : > "$T3/public.md"; ln -s "$T3/public.md" "$T3/tracks/_meta/utterances/0123abcd-0000-4000-8000-0000000000a2.jsonl"
95
+ mk "파일 심볼릭 링크로 공개 파일에 쓰면 안 된다" "0123abcd-0000-4000-8000-0000000000a2" | CLAUDE_PROJECT_DIR="$T3" bash "$HOOK" >/dev/null
96
+ [ ! -s "$T3/public.md" ] && ok "U8b symlinked jsonl refused (public file untouched)" || no U8b "written: $(cat "$T3/public.md")"
97
+ # control: the same prompt with no symlink IS written (the refusal is the symlink's doing)
98
+ mk "파일 심볼릭 링크로 공개 파일에 쓰면 안 된다" "0123abcd-0000-4000-8000-0000000000a3" | CLAUDE_PROJECT_DIR="$T3" bash "$HOOK" >/dev/null
99
+ [ -s "$T3/tracks/_meta/utterances/0123abcd-0000-4000-8000-0000000000a3.jsonl" ] && ok "U8c control: a regular path is written" || no U8c "not written"
100
+ # U9 A2 a FIFO at the record path does not stall the prompt
101
+ mkfifo "$T3/tracks/_meta/utterances/0123abcd-0000-4000-8000-0000000000a4.jsonl"
102
+ t0=$(python3 -c 'import time;print(time.time())')
103
+ # a hung hook must fail this lane, not hang the suite: run it under a 5 s limit (python — macOS has no timeout(1))
104
+ RC=$(python3 - "$HOOK" "$T3" <<'PY'
105
+ import json, subprocess, sys
106
+ inp = json.dumps({"prompt": "파이프 파일이 있어도 멈추면 안 되는 요청", "session_id": "0123abcd-0000-4000-8000-0000000000a4", "transcript_path": "/x/t.jsonl"})
107
+ import os, signal
108
+ p = subprocess.Popen(["bash", sys.argv[1]], stdin=subprocess.PIPE, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL,
109
+ env={"CLAUDE_PROJECT_DIR": sys.argv[2], "PATH": "/usr/bin:/bin", "HOME": "/tmp"}, start_new_session=True)
110
+ try:
111
+ p.communicate(inp.encode(), timeout=5); print(p.returncode)
112
+ except subprocess.TimeoutExpired:
113
+ os.killpg(p.pid, signal.SIGKILL); p.wait(); print("hung") # the whole group: a grandchild blocked on the FIFO must not outlive the lane
114
+ PY
115
+ )
116
+ el=$(python3 -c "import time;print(round(time.time()-$t0,2))")
117
+ python3 -c "import sys;sys.exit(0 if $el < 2.0 else 1)" && [ $RC = 0 ] && ok "U9 FIFO: rc 0 in ${el}s (no block)" || no U9 "rc=$RC ${el}s"
118
+ # U10 B7 a 3 MB prompt is handled (stdin, not env)
119
+ # the input is generated inside python (a multi-MB argv would itself hit E2BIG in the test — measured)
120
+ OUT=$(python3 -c 'import json;print(json.dumps({"prompt":"가"*1500000,"session_id":"0123abcd-0000-4000-8000-0000000000a5","transcript_path":"/x/t.jsonl"},ensure_ascii=False))' | CLAUDE_PROJECT_DIR="$T" bash "$HOOK"); RC=$?
121
+ printf '%s' "$OUT" | grep -q '한글로' && [ $RC = 0 ] && ok "U10 a 1.5M-char prompt still gets the language line (no E2BIG)" || no U10 "rc=$RC"
122
+ python3 -c 'import json,sys;r=[json.loads(l) for l in open(sys.argv[1])][-1];assert r.get("truncated") is True and r["chars"]==1500000 and len(r["text"])==20000' "$D/0123abcd-0000-4000-8000-0000000000a5.jsonl" && ok "U10b a long utterance is marked truncated with its real length (B6)" || no U10b "not marked"
123
+ # U11 B5 short real requests and <tag> requests are written down; acks are not
124
+ for p in "버그 고쳐줘" "<div>이 컴포넌트를 수정해 주세요</div>"; do
125
+ b=$(cat "$D/$SID.jsonl" 2>/dev/null | wc -l | tr -d ' '); run "$p"; a=$(wc -l < "$D/$SID.jsonl" | tr -d ' ')
126
+ [ "$a" = $((b+1)) ] && ok "U11 written down: $p" || no U11 "not written: $p"
127
+ done
128
+ for p in "ㅇㅇ" "ㄱㄱ" "ㅇㅋ" "확인완료" "ok"; do
129
+ b=$(wc -l < "$D/$SID.jsonl" | tr -d ' '); run "$p"; a=$(wc -l < "$D/$SID.jsonl" | tr -d ' ')
130
+ [ "$a" = "$b" ] && ok "U11b ack not listed: $p" || no U11b "listed: $p"
131
+ done
132
+ # U12 B9 language: Japanese is not Korean; Korean prose with pasted English code is Korean
133
+ run "このバグを直してください。「한글」という単語を含みます"
134
+ ! printf '%s' "$OUT" | grep -q '한글로' && ok "U12a Japanese prompt → no Korean line" || no U12a "fired"
135
+ run $'이 함수 좀 고쳐 줘\n```js\nfunction computeTheThingWithAVeryLongEnglishName(argumentOne, argumentTwo) { return argumentOne + argumentTwo }\n```'
136
+ printf '%s' "$OUT" | grep -q '한글로' && ok "U12b Korean prose + English code → Korean line" || no U12b "missed"
137
+ # U13 B12 the nudge names only statuses the checker accepts; B10 the path is shell-quoted
138
+ S4="0123abcd-0000-4000-8000-0000000000a6"; CAD=3
139
+ for i in 1 2 3; do OUT=$(mk "점검 박자 확인용 요청 번호 $i 입니다" "$S4" "/tmp/with space/t.jsonl" | CLAUDE_PROJECT_DIR="$T" FH_CHECKLIST_CADENCE=3 bash "$HOOK"); done; CAD=15
140
+ printf '%s' "$OUT" | grep -q '🔎UNVERIFIED' && ! printf '%s' "$OUT" | grep -q '❓' && ok "U13a nudge lists 🔎UNVERIFIED (accepted by session_checklist.py), not ❓" || no U13a "out=$OUT"
141
+ printf '%s' "$OUT" | grep -qF -- "--transcript '/tmp/with space/t.jsonl'" && ok "U13b transcript path is shell-quoted" || no U13b "out=$OUT"
142
+ # U14 B8 HOME and CLAUDE_PROJECT_DIR unset → still rc 0
143
+ OUT=$(mk "홈 변수가 없어도 죽으면 안 된다" "0123abcd-0000-4000-8000-0000000000a7" | env -i PATH=/usr/bin:/bin bash "$HOOK"); RC=$?
144
+ [ $RC = 0 ] && ok "U14 no HOME, no CLAUDE_PROJECT_DIR → rc 0" || no U14 "rc=$RC"
145
+ # U15 B3 ten prompts at once: ten rows, numbered 1..10 with no duplicate, state says 10
146
+ S5="0123abcd-0000-4000-8000-0000000000a8"
147
+ for i in $(seq 1 10); do (mk "동시에 들어온 요청 번호 $i 입니다 길게" "$S5" | CLAUDE_PROJECT_DIR="$T" bash "$HOOK" >/dev/null) & done; wait
148
+ python3 -c 'import json,sys;r=[json.loads(l)["n"] for l in open(sys.argv[1])];s=json.load(open(sys.argv[2]));assert sorted(r)==list(range(1,11)) and s["rows"]==10,(sorted(r),s)' "$D/$S5.jsonl" "$D/$S5.state.json" && ok "U15 10 concurrent prompts → rows 1..10, state 10 (locked)" || no U15 "race"
149
+ rm -rf "$T2" "$T3"
150
+
151
+ # ── codex R2 (final round) cases ──
152
+ T4="$(mktemp -d)"; mkdir -p "$T4/tracks/_meta/utterances"; : > "$T4/outside.md"
153
+ ln "$T4/outside.md" "$T4/tracks/_meta/utterances/0123abcd-0000-4000-8000-0000000000b1.jsonl"
154
+ mk "하드 링크로 바깥 파일에 쓰면 안 되는 요청" "0123abcd-0000-4000-8000-0000000000b1" | CLAUDE_PROJECT_DIR="$T4" bash "$HOOK" >/dev/null
155
+ [ ! -s "$T4/outside.md" ] && ok "U16 hard-linked record refused (outside file untouched)" || no U16 "written through hard link"
156
+ t0=$(python3 -c 'import time;print(time.time())')
157
+ python3 -c 'import json;print(json.dumps({"prompt":"ㅋ"*20000+"x","session_id":"0123abcd-0000-4000-8000-0000000000b2"}))' | CLAUDE_PROJECT_DIR="$T4" bash "$HOOK" >/dev/null
158
+ el=$(python3 -c "import time;print(round(time.time()-$t0,2))")
159
+ python3 -c "import sys;sys.exit(0 if $el < 1.0 else 1)" && ok "U17 a 20000-char near-ack is handled in ${el}s (no regex blow-up)" || no U17 "${el}s"
160
+ S6="0123abcd-0000-4000-8000-0000000000b3"; mkdir -p "$T4/tracks/_meta/utterances/$S6.state.json" # state can never be written
161
+ for i in 1 2 3; do mk "상태 저장이 안 돼도 번호가 겹치면 안 된다 $i" "$S6" | CLAUDE_PROJECT_DIR="$T4" bash "$HOOK" >/dev/null; done
162
+ python3 -c 'import json,sys;r=[json.loads(l)["n"] for l in open(sys.argv[1])];assert r==[1,2,3],r' "$T4/tracks/_meta/utterances/$S6.jsonl" && ok "U18 numbering comes from the record when state cannot be saved (1,2,3)" || no U18 "repeated numbers"
163
+ rm -rf "$T4"
164
+
165
+ # U19 the body runs on its own (the .sh is a thin wrapper): FH_HUB set → row + language line, FH_HUB unset → silent, rc 0 both
166
+ PYB="$HERE/utterance_checklist_hook.py"
167
+ S19="0123abcd-0000-4000-8000-000000000019"
168
+ J19=$(python3 -c 'import json,sys;print(json.dumps({"prompt":"본체를 직접 실행해서 받아 적는지 본다","session_id":sys.argv[1]}))' "$S19")
169
+ O19=$(printf '%s' "$J19" | FH_HUB="$T" python3 "$PYB"); R19=$?
170
+ [ $R19 = 0 ] && printf '%s' "$O19" | grep -q '한글로' && [ "$(wc -l < "$D/$S19.jsonl" 2>/dev/null | tr -d ' ')" = 1 ] && ok "U19a body run directly → row + language line" || no U19a "rc=$R19 out=$O19"
171
+ O19b=$(printf '%s' "$J19" | env -u FH_HUB python3 "$PYB"); R19b=$?
172
+ [ $R19b = 0 ] && [ -z "$O19b" ] && [ "$(wc -l < "$D/$S19.jsonl" | tr -d ' ')" = 1 ] && ok "U19b body without FH_HUB → silent, nothing written" || no U19b "rc=$R19b out=$O19b"
173
+
174
+ echo "lanes: pass=$pass fail=$fail"
175
+ [ $fail = 0 ]
@@ -0,0 +1,193 @@
1
+ #!/usr/bin/env python3
2
+ """utterance_checklist_hook.py — body of scripts/utterance_checklist_hook.sh (UserPromptSubmit). See the .sh header for WHY.
3
+
4
+ Reads the hook JSON on STDIN (never through the environment: a multi-MB prompt hit E2BIG and silently disabled the hook —
5
+ codex R1 B7). Contract: exit 0 always, output only JSON hookSpecificOutput.additionalContext on stdout, never write outside
6
+ <hub>/tracks/_meta/utterances/, never follow a symlink there, never block on a FIFO or a held lock.
7
+
8
+ codex R1 (2026-10-18, 12 findings) fixed here: symlink escape (A1) · FIFO/lock stall (A2) · unlocked read-modify-write (B3) ·
9
+ counter advanced on a failed append (B4) · «<…» / short real requests dropped (B5) · silent truncation (B6) · env E2BIG (B7) ·
10
+ HOME unbound (B8, in the .sh) · Japanese/Chinese read as Korean, pasted code counted (B9) · unquoted path in the suggested
11
+ command (B10) · a status label the checker rejects (B12).
12
+ """
13
+ import errno, fcntl, json, os, re, shlex, stat, sys, time
14
+
15
+ ACK = re.compile(r"^(?:ㅇ+|ㄱ+|ㅇㅋ+|ㅇㅇㄱㄱ|ㄴㄴ|ok(?:ay)?|ㅇㅋㅇㅋ|넵|네+|응+|좋아|굿|확인(?:완료)?|ㄱㄱ+|go|yes|y|no|n|ㅋ+|ㅎ+)[\s.!~?ㅋㅎ]*$", re.I)
16
+ INJECTED = re.compile(r"^\s*(?:<(?:task-notification|system-reminder|command-name|command-message|command-args|local-command-stdout|local-command-stderr|bash-input|bash-stdout|bash-stderr|agent-message)\b|\[SYSTEM NOTIFICATION|\[Cross-session delivery notice\]|\[automated-run)", re.I)
17
+ MAX_KEEP = 20000 # chars kept per utterance; longer ones are marked truncated, never cut silently
18
+ MAX_SCAN = 20000 # chars scanned for language (bounded work on huge pastes)
19
+
20
+
21
+ def safe_dir(hub):
22
+ """<hub>/tracks/_meta/utterances as a real directory inside the hub, or None. No symlink anywhere on the last two hops."""
23
+ meta = os.path.join(hub, "tracks", "_meta")
24
+ d = os.path.join(meta, "utterances")
25
+ try:
26
+ tracks = os.path.dirname(meta)
27
+ for p in (tracks, meta):
28
+ if os.path.islink(p):
29
+ return None
30
+ if not os.path.lexists(p):
31
+ try: os.mkdir(p, 0o700)
32
+ except FileExistsError: pass # a parallel first prompt made it (Sonnet R2 #4)
33
+ if not stat.S_ISDIR(os.lstat(p).st_mode):
34
+ return None
35
+ if not os.path.lexists(d):
36
+ try: os.mkdir(d, 0o700)
37
+ except FileExistsError: pass
38
+ st = os.lstat(d)
39
+ if not stat.S_ISDIR(st.st_mode): # a symlink or anything else → refuse
40
+ return None
41
+ real_hub = os.path.realpath(hub)
42
+ if not os.path.realpath(d).startswith(real_hub + os.sep):
43
+ return None
44
+ return d
45
+ except OSError:
46
+ return None
47
+
48
+
49
+ DFD = None # directory fd of utterances/ — every file opens relative to it (codex R2: the folder can't be swapped after the check)
50
+
51
+
52
+ def open_regular(name, flags, mode=0o600):
53
+ """open <name> inside utterances/ via its directory fd, without following a symlink and without blocking on a FIFO;
54
+ refuse anything but a regular file with a single link (a hard link would write into a file elsewhere — codex R2)."""
55
+ fd = os.open(name, flags | os.O_NOFOLLOW | os.O_NONBLOCK, mode, dir_fd=DFD)
56
+ try:
57
+ st = os.fstat(fd)
58
+ if not stat.S_ISREG(st.st_mode) or st.st_nlink != 1:
59
+ raise OSError(errno.EINVAL, "not a single-link regular file")
60
+ fl = fcntl.fcntl(fd, fcntl.F_GETFL)
61
+ fcntl.fcntl(fd, fcntl.F_SETFL, fl & ~os.O_NONBLOCK)
62
+ return fd
63
+ except Exception:
64
+ os.close(fd)
65
+ raise
66
+
67
+
68
+ def prose_only(text):
69
+ t = re.sub(r"```.*?```", " ", text[:MAX_SCAN], flags=re.S) # fenced code
70
+ t = re.sub(r"`[^`\n]*`", " ", t) # inline code
71
+ t = re.sub(r"https?://\S+|(?:~|/)[\w.\-/]+", " ", t) # urls and paths
72
+ return t
73
+
74
+
75
+ def main():
76
+ try:
77
+ raw = sys.stdin.buffer.read(32 * 1024 * 1024).decode("utf-8", "replace")
78
+ ev = json.loads(raw)
79
+ except Exception:
80
+ return
81
+ if not isinstance(ev, dict):
82
+ return
83
+ prompt = ev.get("prompt") if isinstance(ev.get("prompt"), str) else ""
84
+ sid = ev.get("session_id") if isinstance(ev.get("session_id"), str) else ""
85
+ if not prompt.strip() or not re.fullmatch(r"[A-Za-z0-9-]{8,80}", sid):
86
+ return
87
+ if INJECTED.match(prompt):
88
+ return # notices relayed by the runtime, not the operator
89
+ text = prompt.strip()
90
+ substantive = not (len(text) <= 40 and ACK.match(text)) # acks are short; never run the pattern on long text (codex R2)
91
+ hub = os.environ.get("FH_HUB") or ""
92
+ if not hub:
93
+ return
94
+ notes = []
95
+
96
+ global DFD
97
+ d = safe_dir(hub)
98
+ if d:
99
+ try:
100
+ DFD = os.open(d, os.O_RDONLY | os.O_DIRECTORY | os.O_NOFOLLOW)
101
+ except OSError:
102
+ d = None
103
+ if d:
104
+ lock_p = sid + ".lock"
105
+ try:
106
+ lfd = open_regular(lock_p, os.O_RDWR | os.O_CREAT)
107
+ except OSError:
108
+ lfd = None
109
+ if lfd is not None:
110
+ locked = False
111
+ deadline = time.monotonic() + 0.3 # never hold the operator's prompt on a lock for long (codex R2)
112
+ while time.monotonic() < deadline:
113
+ try:
114
+ fcntl.flock(lfd, fcntl.LOCK_EX | fcntl.LOCK_NB); locked = True; break
115
+ except OSError:
116
+ time.sleep(0.02)
117
+ if locked:
118
+ try:
119
+ state_p = sid + ".state.json"
120
+ try:
121
+ sfd = open_regular(state_p, os.O_RDONLY)
122
+ if os.fstat(sfd).st_size > 65536: # bounded: a state file is a few dozen bytes
123
+ os.close(sfd); raise ValueError
124
+ with os.fdopen(sfd, "r") as f:
125
+ st = json.load(f)
126
+ if not isinstance(st, dict):
127
+ raise ValueError
128
+ except Exception:
129
+ st = {"rows": 0, "acks": 0, "last_nudge": 0}
130
+ if substantive:
131
+ n_prev = int(st.get("rows", 0))
132
+ try: # the record is the source of n — a failed state write must not repeat numbers (codex R2)
133
+ rfd = open_regular(sid + ".jsonl", os.O_RDONLY)
134
+ with os.fdopen(rfd, "rb") as f:
135
+ n_prev = max(n_prev, f.read(16 * 1024 * 1024).count(b"\n"))
136
+ except OSError:
137
+ pass
138
+ row = {"ts": time.strftime("%Y-%m-%dT%H:%M:%S"), "n": n_prev + 1, "text": text[:MAX_KEEP]}
139
+ if len(text) > MAX_KEEP:
140
+ row["truncated"] = True; row["chars"] = len(text)
141
+ try:
142
+ afd = open_regular(sid + ".jsonl", os.O_WRONLY | os.O_APPEND | os.O_CREAT)
143
+ with os.fdopen(afd, "a", encoding="utf-8") as f:
144
+ f.write(json.dumps(row, ensure_ascii=False) + "\n")
145
+ st["rows"] = row["n"] # count only what was really written down
146
+ except OSError:
147
+ pass
148
+ else:
149
+ st["acks"] = int(st.get("acks", 0)) + 1
150
+ try:
151
+ cadence = max(3, int(os.environ.get("FH_CHECKLIST_CADENCE", "15")))
152
+ except Exception:
153
+ cadence = 15
154
+ if substantive and int(st.get("rows", 0)) - int(st.get("last_nudge", 0)) >= cadence:
155
+ st["last_nudge"] = st["rows"]
156
+ tp = ev.get("transcript_path") if isinstance(ev.get("transcript_path"), str) and ev.get("transcript_path") else ""
157
+ out = f"tracks/_meta/session_checklist_{time.strftime('%Y-%m-%d')}_{sid[:8]}.md"
158
+ cmd = (f"python3 scripts/session_checklist.py extract --transcript {shlex.quote(tp)} --out {shlex.quote(out)}"
159
+ if tp else "python3 scripts/session_checklist.py extract --transcript (이 세션 전사본 경로) --out " + shlex.quote(out))
160
+ notes.append(
161
+ f"📋 [FH 체크리스트 점검 시점] 이 세션에서 받아 적은 운영자 발화가 {st['rows']}건이다(지난 점검 뒤 {cadence}건 이상). "
162
+ f"이번 답을 마치기 전에 체크리스트를 갱신하라: {cmd} → 상태 칸을 ✅DONE·🟡PARTIAL·⏳IN-PROGRESS·❌NOT-DONE·⏸HELD·🔎UNVERIFIED 중 하나로, "
163
+ f"완료는 증거·미완은 사유+제안과 함께 채우고 → 표를 운영자에게 보여라(열린 줄이 위로). 받아 적은 원문: tracks/_meta/utterances/{sid}.jsonl")
164
+ fd, tmp = None, f"{sid}.state.{os.getpid()}.tmp"
165
+ try:
166
+ fd = open_regular(tmp, os.O_WRONLY | os.O_CREAT | os.O_TRUNC | os.O_EXCL)
167
+ with os.fdopen(fd, "w") as f:
168
+ json.dump(st, f)
169
+ os.replace(tmp, state_p, src_dir_fd=DFD, dst_dir_fd=DFD)
170
+ except OSError:
171
+ try: os.unlink(tmp, dir_fd=DFD)
172
+ except OSError: pass
173
+ finally:
174
+ try: fcntl.flock(lfd, fcntl.LOCK_UN)
175
+ except OSError: pass
176
+ os.close(lfd)
177
+
178
+ p = prose_only(text)
179
+ hangul = len(re.findall(r"[가-힣]", p))
180
+ other_cjk = len(re.findall(r"[぀-ヿ一-鿿]", p)) # kana + Han
181
+ latin = len(re.findall(r"[A-Za-z]", p))
182
+ if hangul >= 2 and hangul >= other_cjk and hangul * 2 >= latin:
183
+ notes.append("🗣️ 운영자는 이번 메시지를 한글로 썼다 — 이 턴에 운영자에게 보이는 글은 전부 한글로(도구 호출 사이 진행 메모 포함). 영어는 커밋 메시지·코드·서브에이전트 지시문에만.")
184
+ if notes:
185
+ print(json.dumps({"hookSpecificOutput": {"hookEventName": "UserPromptSubmit", "additionalContext": "\n".join(notes)}}, ensure_ascii=False))
186
+
187
+
188
+ if __name__ == "__main__":
189
+ try:
190
+ main()
191
+ except Exception:
192
+ pass
193
+ sys.exit(0)
@@ -0,0 +1,31 @@
1
+ #!/usr/bin/env bash
2
+ # utterance_checklist_hook.sh — UserPromptSubmit: write each operator utterance down AS IT IS SAID, nudge a mid-session
3
+ # review every N rows, and keep the reply language with the operator's.
4
+ #
5
+ # WHY (operator 2026-10-18, after a 102-utterance session where the close check could not confirm 57):
6
+ # «fh의 정체성과 엔진이라면 이걸 모두 놓치지않아야할것같아. 체크리스트에 받아적고 마무리시점이나 중간에 한번씩 파악해보는거»
7
+ # and, four times the same day, replies drifting to English mid-turn: «한글로좀 말해줘».
8
+ # The capture half already existed (session_checklist.py extract reads the transcript + compaction summaries); what was
9
+ # missing was the CADENCE — nothing made the session look at the list before the close, and in a long session the close
10
+ # came too late. The 2026-09-18 design (fh_signal_2026-09-18_request-checklist-close-report.md) planned a close step and a
11
+ # promotion; neither was wired. This hook is the cadence; session_close_check.sh ①-g is the close step.
12
+ #
13
+ # WHAT
14
+ # · appends {ts, n, text} to tracks/_meta/utterances/<session_id>.jsonl (gitignored — never committed) for prompts
15
+ # that carry content — everything except a short ack (≤ 40 chars matching the ack pattern: «ㅇㅇ», «ㄱㄱ», «ok»),
16
+ # which is counted, not listed; runtime-injected notices (<task-notification>, <system-reminder> …) are skipped
17
+ # · every CADENCE rows (default 15, FH_CHECKLIST_CADENCE) since the last nudge: tells the session to refresh the
18
+ # checklist (session_checklist.py extract → fill 상태 → show the operator the table)
19
+ # · when the prompt is mostly Hangul: one line «reply in Korean, progress notes between tool calls included»
20
+ #
21
+ # CONTRACT: exit 0 ALWAYS (a non-zero UserPromptSubmit hook would block the operator's message); output is JSON
22
+ # hookSpecificOutput.additionalContext on stdout, or nothing. Any internal failure → silent. No network. Fast: O(1) per
23
+ # prompt (append + a small state file), never reads the transcript. Body: scripts/utterance_checklist_hook.py.
24
+ set -u
25
+ HUB="${CLAUDE_PROJECT_DIR:-${HOME:-}/projects/forge-harness}"
26
+ PY="$(cd "$(dirname "$0")" 2>/dev/null && pwd)/utterance_checklist_hook.py" # the body sits next to this wrapper
27
+ command -v python3 >/dev/null 2>&1 || exit 0
28
+ [ -f "$PY" ] || exit 0
29
+ # stdin goes straight through (no env copy — a multi-MB prompt hit E2BIG through the environment, codex R1 B7)
30
+ FH_HUB="$HUB" python3 "$PY" 2>/dev/null || true
31
+ exit 0
@@ -19,6 +19,10 @@
19
19
 
20
20
  ## When it applies
21
21
 
22
+ The leak gates (Steps 0–3) apply to any first-time public action below. The last item of
23
+ **§Read it as a reader** (Area B) applies to every minor/major release and every public announcement
24
+ of the harness itself, not only the first one.
25
+
22
26
  Any first-time public action:
23
27
  - `gh repo create --public` / `gh repo create ... --public`
24
28
  - `gh repo edit --visibility public` (private → public flip)
@@ -128,6 +132,12 @@ opens and look at what they see:
128
132
 
129
133
  A lens already exists — `/sim-conductor` A-1 (`beginner` cold-read) — or just render it and read it.
130
134
 
135
+ - [ ] **Minor/major release or public announcement of the harness itself**: run `/sim-conductor` Area B
136
+ (whole-set internal audit: outside-reader briefing · naming/structure gaps · challenger) unless one
137
+ already ran since the previous minor release. This replaced a 30-day terminal reminder on
138
+ 2026-10-19 (operator decision): Area B's distinct value is an outsider's view of the whole set,
139
+ and that view pays at publication, not on a clock.
140
+
131
141
  🟥 **Why this is a human step and not a scan**: a static check catches what is ABSENT, never what is
132
142
  UNREADABLE. Two independent measurements arrived here the same day (2026-08-17): one harness axis
133
143
  found 12 readability defects with **0** caught by static scanners; a third-harness review
@@ -588,6 +588,49 @@ for f in "${FILES[@]}"; do
588
588
  | grep -vE '^[0-9]+:[[:space:]]*#' \
589
589
  | grep -vE '#[[:space:]]*noqa[:[:space:]]*degrade')
590
590
  fi
591
+
592
+ # S7 — `set -e` under a declared exit contract that has its OWN error code, with no ERR trap.
593
+ # Under `set -e` a command that fails where nobody expected it ends the script with THAT
594
+ # command's status — usually 1. If the contract reserves a separate code for "the tool itself
595
+ # broke" (10 HARNESS_ERROR and the like), the low codes are verdicts, so a crash leaks out as
596
+ # one of them. Measured 2026-10-20 on fh-gate.sh: a failing `mktemp` exited 1 = PENDING
597
+ # ("proceed with awareness"); reported from outside, fixed in #927. The cure is an ERR trap
598
+ # that exits the error code, plus an exit-time check that 0..N only leave through the verdict
599
+ # sites (`set -u` and a failing EXIT-trap function end with 1 WITHOUT firing ERR).
600
+ # SCOPE, so this stays quiet: all three must hold — `set -…e…` · a comment header naming exit
601
+ # codes · a contract line naming an error code (harness/internal/tool error). A contract of
602
+ # just "0 = pass, 1 = fail" is excluded: there an unexpected 1 already points the safe way.
603
+ # Census 2026-10-20 over this repo's tracked shell: 1 file matched the shape (fh-gate.sh).
604
+ # FILE-level probe: it reports the `set -e` line once.
605
+ # Round-1 cross-family review (codex) widened three things: `set -o errexit` and `cmd; set -e`
606
+ # activate it; an `EXIT_*ERROR=10`-style constant counts as a contract; and a trap only counts
607
+ # when it EXITS — `trap cleanup ERR` (no exit) and a commented-out trap do not protect anything.
608
+ # A grep that ERRORS (rc>1) is reported as S7-UNMEASURED, never read as "no hit" — the same
609
+ # default-toward-clean shape this probe exists to find.
610
+ _s7_rc() { grep "$@" "$f" >/dev/null 2>&1; echo $?; }
611
+ _s7_lines=$(grep -nE '(^|[;{&|])[[:space:]]*set[[:space:]]+(-[A-Za-z]*e[A-Za-z]*|-o[[:space:]]+errexit)([[:space:];]|$)' "$f" 2>/dev/null); _s7_r1=$?
612
+ _s7_set=$(printf '%s\n' "$_s7_lines" | grep -vE '^[0-9]+:[[:space:]]*#' | grep -vE '#[[:space:]]*noqa[:[:space:]]*degrade' | sed -n 1p)
613
+ _s7_r2=$(_s7_rc -qE '^[[:space:]]*#.*\b[Ee]xit([[:space:]]+codes?|[[:space:]]+status(es)?)?[[:space:]]*:')
614
+ _s7_r3=$(_s7_rc -qiE '^[[:space:]]*#.*\b[0-9]+([[:space:]]*(—|–|-|=|:|\))[[:space:]]*.{0,40}|[[:space:]]+)(harness|internal|tool)[ _-]?error')
615
+ # ^ a CONTRACT ENTRY (`10 — Harness error`, `10 harness error`), not prose that happens to hold a
616
+ # number and the word (an old test file's comment «the count is 0 … HARNESS_ERROR» was flagged).
617
+ _s7_r4=$(_s7_rc -qE '^[[:space:]]*[A-Z_]*(HARNESS|INTERNAL|TOOL)_?ERR(OR)?[A-Z_]*=[0-9]+')
618
+ # protecting trap: an ACTIVE (non-comment) `trap … ERR` line that exits, or that names a handler
619
+ # function whose body (next 12 lines) exits.
620
+ _s7_traps=$(grep -nE "^[^#]*\btrap[[:space:]].*[[:space:]'\"]ERR(['\"]|[[:space:];]|$)" "$f" 2>/dev/null); _s7_r5=$?
621
+ _s7_guard=""
622
+ if [ -n "$_s7_traps" ]; then
623
+ if printf '%s\n' "$_s7_traps" | grep -qE '\bexit\b'; then _s7_guard=1
624
+ else
625
+ _s7_h=$(printf '%s\n' "$_s7_traps" | sed -nE "s/.*trap[[:space:]]+['\"]?([A-Za-z_][A-Za-z0-9_]*)['\"]?[[:space:]].*/\\1/p" | sed -n 1p)
626
+ [ -n "$_s7_h" ] && grep -A12 -E "^[[:space:]]*(function[[:space:]]+)?${_s7_h}[[:space:]]*\(\)" "$f" 2>/dev/null | grep -qE '\bexit\b' && _s7_guard=1
627
+ fi
628
+ fi
629
+ if [ "$_s7_r1" -gt 1 ] || [ "$_s7_r2" -gt 1 ] || [ "$_s7_r3" -gt 1 ] || [ "$_s7_r4" -gt 1 ] || [ "$_s7_r5" -gt 1 ]; then
630
+ emit "$f" 1 "S7-UNMEASURED(sh)" "could not read this file for the set -e / exit-contract check (grep error) — NOT checked, not clean"
631
+ elif [ -n "$_s7_set" ] && { { [ "$_s7_r2" -eq 0 ] && [ "$_s7_r3" -eq 0 ]; } || [ "$_s7_r4" -eq 0 ]; } && [ -z "$_s7_guard" ]; then
632
+ emit "$f" "${_s7_set%%:*}" "S7:set-e-leaks-verdict(sh)" "\`set -e\` under an exit contract that has its own error code, but no ERR trap that exits — an unexpected failure exits with the failing command's status (usually 1), which the contract reads as a verdict; add \`trap '…; exit <error-code>' ERR\` and an EXIT check that 0..N only leave through the verdict sites (set -u and EXIT-trap failures do not fire ERR). Do NOT add set -E without checking \`\$( ) || rc=\$?\` captures"
633
+ fi
591
634
  fi
592
635
 
593
636
  # Probe A — except/else/finally block returning a permissive value within 2 lines.