@chrono-meta/fh-gate 3.44.0 → 3.46.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 (101) hide show
  1. package/.claude/rules/fh_4axis_gate.md +50 -608
  2. package/.claude-plugin/marketplace.json +4 -4
  3. package/CATALOG.md +21 -0
  4. package/CHEATSHEET.md +13 -3
  5. package/docs/codex-compat.md +1 -1
  6. package/knowledge/shared/harness-core/fh_4axis_gate_detail.md +679 -0
  7. package/knowledge/shared/harness-core/fh_detail_protocols.md +1 -0
  8. package/knowledge/shared/harness-core/fh_integration_contract.md +1 -1
  9. package/knowledge/shared/harness-core/fh_module_contract.md +106 -3
  10. package/knowledge/shared/harness-core/heavy_skill_to_cartridge.md +185 -0
  11. package/knowledge/shared/learnings/subagent_invocations_log.yaml +209 -0
  12. package/package.json +19 -1
  13. package/plugins/fh-commons/.claude-plugin/plugin.json +1 -1
  14. package/plugins/fh-commons/skills/ko-tech-writer/SKILL.md +9 -8
  15. package/plugins/fh-commons/skills/ko-tech-writer/SKILL_detail.md +20 -0
  16. package/plugins/fh-commons/skills/mcp-circuit-breaker/SKILL.md +12 -6
  17. package/plugins/fh-meta/.claude-plugin/plugin.json +1 -1
  18. package/plugins/fh-meta/CHANGELOG.md +122 -0
  19. package/plugins/fh-meta/skills/auto-decorrelation/SKILL.md +13 -0
  20. package/plugins/fh-meta/skills/context-doctor/SKILL.md +1 -0
  21. package/plugins/fh-meta/skills/deep-clarify/SKILL.md +76 -22
  22. package/plugins/fh-meta/skills/harvest-loop/SKILL.md +2 -2
  23. package/plugins/fh-meta/skills/install-wizard/SKILL_detail.md +4 -0
  24. package/plugins/fh-meta/skills/memory-hygiene/SKILL.md +6 -0
  25. package/plugins/fh-meta/skills/steel-quench/SKILL_detail.md +2 -1
  26. package/plugins/fh-preprep/.claude-plugin/plugin.json +1 -1
  27. package/plugins/fh-qp/.claude-plugin/plugin.json +1 -1
  28. package/scripts/agy_launch_guard.sh +117 -1
  29. package/scripts/below_floor_scan.sh +30 -0
  30. package/scripts/codex_launch_guard.sh +38 -2
  31. package/scripts/correction_moments.py +23 -2
  32. package/scripts/fh-gate.sh +612 -14
  33. package/scripts/fh-goal.sh +56 -12
  34. package/scripts/fh-run.sh +1 -1
  35. package/scripts/fh_gate_exec.sh +272 -0
  36. package/scripts/fh_session_load.sh +17 -0
  37. package/scripts/finding_fleet.sh +2 -1
  38. package/scripts/finding_verifier.sh +2 -1
  39. package/scripts/fixtures/heavy_skill_smell/clean/tidy-notes/README.md +16 -0
  40. package/scripts/fixtures/heavy_skill_smell/clean/tidy-notes/scripts/check_refs.py +12 -0
  41. package/scripts/fixtures/heavy_skill_smell/clean/tidy-notes/scripts/test_check_refs.py +24 -0
  42. package/scripts/fixtures/heavy_skill_smell/clean/tidy-notes/skills/tidy-notes/SKILL.md +16 -0
  43. package/scripts/fixtures/heavy_skill_smell/clean/tidy-notes/skills/tidy-notes/fh-module.yaml +20 -0
  44. package/scripts/fixtures/heavy_skill_smell/heavy/docs-publisher-pro/SKILL.md +25 -0
  45. package/scripts/fixtures/heavy_skill_smell/heavy/docs-publisher-pro/hooks/hooks.json +7 -0
  46. package/scripts/fixtures/heavy_skill_smell/heavy/docs-publisher-pro/scripts/check_links.py +25 -0
  47. package/scripts/fixtures/heavy_skill_smell/heavy/docs-publisher-pro/scripts/publish.sh +9 -0
  48. package/scripts/fixtures/heavy_skill_smell/heavy/docs-publisher-pro/scripts/publish_guard.py +6 -0
  49. package/scripts/fixtures/heavy_skill_smell/heavy/docs-publisher-pro/scripts/setup.sh +5 -0
  50. package/scripts/fixtures/heavy_skill_smell/heavy/release-notes-pro/SKILL.md +25 -0
  51. package/scripts/fixtures/heavy_skill_smell/heavy/release-notes-pro/hooks/hooks.json +10 -0
  52. package/scripts/fixtures/heavy_skill_smell/heavy/release-notes-pro/scripts/check_refs.py +12 -0
  53. package/scripts/fixtures/heavy_skill_smell/heavy/release-notes-pro/scripts/guard_push.py +9 -0
  54. package/scripts/fixtures/heavy_skill_smell/heavy/release-notes-pro/scripts/install.sh +6 -0
  55. package/scripts/fixtures/heavy_skill_smell/heavy/release-notes-pro/scripts/ship.sh +9 -0
  56. package/scripts/heavy_skill_smell.py +311 -0
  57. package/scripts/job_heartbeat.py +186 -0
  58. package/scripts/live_eval_matrix.py +128 -0
  59. package/scripts/live_eval_trace.py +197 -4
  60. package/scripts/package_coverage_check.sh +18 -0
  61. package/scripts/pr_merge_verified.sh +14 -4
  62. package/scripts/prepush_guard_check.sh +8 -0
  63. package/scripts/probe_live_eval.sh +32 -0
  64. package/scripts/probe_live_eval_lib.py +8 -2
  65. package/scripts/selfcheck.sh +113 -0
  66. package/scripts/selfcheck_shard_weights.txt +2 -0
  67. package/scripts/sidecar_calibrate.sh +7 -5
  68. package/scripts/sim_isolated_run.sh +20 -0
  69. package/scripts/test_agy_launch_guard_lanes.sh +120 -0
  70. package/scripts/test_below_floor_scan_lanes.sh +85 -0
  71. package/scripts/test_codex_launch_guard_lanes.sh +45 -0
  72. package/scripts/test_correction_moments_lanes.sh +37 -0
  73. package/scripts/test_deep_clarify_interview_lanes.sh +108 -0
  74. package/scripts/test_deep_clarify_spec_path_lanes.sh +91 -0
  75. package/scripts/test_fh_gate_absorb_lanes.sh +255 -0
  76. package/scripts/test_fh_gate_defaults_lanes.sh +188 -0
  77. package/scripts/test_fh_gate_exec_lanes.sh +244 -0
  78. package/scripts/test_fh_gate_fusion_lanes.sh +202 -0
  79. package/scripts/test_fh_gate_regressions.sh +92 -1
  80. package/scripts/test_fh_goal_change_detection_lanes.sh +103 -3
  81. package/scripts/test_finding_pipeline_lanes.sh +35 -1
  82. package/scripts/test_guard_anchor_override_env_lanes.sh +84 -0
  83. package/scripts/test_heavy_skill_smell_lanes.sh +160 -0
  84. package/scripts/test_job_heartbeat_lanes.sh +96 -0
  85. package/scripts/test_live_eval_construct_lanes.sh +29 -6
  86. package/scripts/test_live_eval_matrix_lanes.sh +53 -0
  87. package/scripts/test_live_eval_trace_lanes.sh +132 -5
  88. package/scripts/test_name_boundary_locale_lanes.sh +36 -5
  89. package/scripts/test_pr_merge_verified_lanes.sh +15 -2
  90. package/scripts/test_prepush_marker_lookup_lanes.sh +143 -0
  91. package/scripts/test_probe_live_eval_lanes.sh +44 -0
  92. package/scripts/test_regression_guard_sibling_lanes.sh +52 -1
  93. package/scripts/test_sidecar_calibrate_lanes.sh +1 -1
  94. package/scripts/test_sim_isolated_run_lanes.sh +43 -0
  95. package/scripts/universal_guard_check.sh +8 -0
  96. package/scripts/worktree_reclaim.sh +1 -1
  97. package/templates/.claude/rules/mcp_tool_gating.md +27 -0
  98. package/templates/.git-hooks/pre-push +60 -3
  99. package/templates/PRE-PUBLISH-CHECKLIST.md +22 -0
  100. package/templates/regression_guard.sh +8 -4
  101. package/templates/settings.LaneGap.snippet.json +27 -0
@@ -72,12 +72,12 @@ Session end
72
72
  **운영자 발화가 인용돼 기록되는 순간** 승인된다. 전자는 세션이 자기 권한을 넓히는 형태다.
73
73
 
74
74
  산출: 오늘자 `tracks/_meta/fh_signal_{date}_{source}.md` 에 `retro: close` 를 달고
75
- `## Session Retrospective` 4필드를 채운다(형식 정본 = fh_detail_protocols.md).
75
+ `## Session Retrospective` 5필드를 채운다(형식 정본 = fh_detail_protocols.md).
76
76
  「없음」·「0」도 유효한 값이고, **비우는 것만 안 된다.**
77
77
 
78
78
  Done When:
79
79
  + 오늘자 signal 파일이 존재하고 `retro: close` 를 달고 있다 — mandatory-pass
80
- + Session Retrospective 4필드가 전부 채워졌다 — mandatory-pass
80
+ + Session Retrospective 5필드가 전부 채워졌다 — mandatory-pass
81
81
  + 정정 건수는 **세었지 회상하지 않았다** — measured
82
82
  + FH Registration Candidate 가 비면 그 이유가 한 줄 적혀 있다 — mandatory-pass
83
83
 
@@ -591,6 +591,10 @@ fi
591
591
  # skill's own Per-item-approval principle). Ask BEFORE running the python:
592
592
  # "Register the SessionStart hooks (floor check · env-delta · companion load) into
593
593
  # .claude/settings.json? (Y/N)
594
+ # [only when templates/settings.CartridgeLoader.snippet.json exists — a hub checkout, not the npm
595
+ # package:] This also registers the cartridge loader. It injects nothing until you write
596
+ # .claude/cartridges.enabled yourself (example: templates/cartridges.enabled.example) — it
597
+ # loads only admitted snapshots you list.
594
598
  # On N: you get no turn-0 mechanical signal — floor gaps, env changes and companion freshness
595
599
  # fall back to session prose, and some of FH's intended features will not run as designed.
596
600
  # The decline is recorded and a one-line per-session reminder will note the state
@@ -100,6 +100,12 @@ FRESH (<threshold):
100
100
 
101
101
  ### Step 3 — Re-verify Stale Entries
102
102
 
103
+ **Evidence pointer first.** An entry may carry `metadata.evidence:` — one line naming the narrowest source of
104
+ the lesson: a commit hash, a PR number, a log line or a `file:line`. Write it when the memory is created, next to
105
+ the session link it already has. When it is present, re-verify against it before the type method below; it is the
106
+ place to go back to. It is optional and never inferred: an older entry without it is not an error, and a pointer
107
+ that no longer resolves is reported as such, not filled in.
108
+
103
109
  For each stale entry, run the appropriate re-verification:
104
110
 
105
111
  **Reference type** (URLs, DOIs, GitHub):
@@ -365,7 +365,8 @@ fi
365
365
  # (intermittent hang class, ~50% observed 2026-06-11); -p auto-approves tool execution,
366
366
  # so feed only trusted artifacts — never untrusted external content. 🟥 Its tools also READ the
367
367
  # machine and send what they print to the cloud model: start it only through
368
- # scripts/agy_launch_guard.sh, which refuses unless FH_AGY_ISOLATION=container|os-user — never on a
368
+ # scripts/agy_launch_guard.sh, which refuses unless FH_AGY_ISOLATION=container|os-user (or no-tools-agent,
369
+ # a tools: [] agent with every run checked — public material only) — never on a
369
370
  # host where company repositories are readable (auto-decorrelation §Step 2). Serial by design
370
371
  # (worst case ~6 min if the hang class fires on every call) — do NOT copy the T1-T4
371
372
  # `VAR=$(...) &` pattern: it assigns inside a background subshell.
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fh-preprep",
3
- "version": "3.44.0",
3
+ "version": "3.46.0",
4
4
  "engines": {
5
5
  "claudeCode": ">=1.0.0"
6
6
  },
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fh-qp",
3
- "version": "3.44.0",
3
+ "version": "3.46.0",
4
4
  "engines": {
5
5
  "claudeCode": ">=1.0.0"
6
6
  },
@@ -23,12 +23,127 @@
23
23
  # marker only if every read fails. Never on the host that holds company repositories, and never because
24
24
  # of `--sandbox`.
25
25
  #
26
+ # NO-TOOLS AGENT (2026-11-19, on this machine). FH_AGY_ISOLATION=no-tools-agent is the one marker the guard
27
+ # can partly CHECK rather than take on trust. Measured 2026-11-19 with canaries: a custom agent whose
28
+ # definition says `tools: []` made 0 file reads in 4 of 4 runs, while a control with the same body and no
29
+ # `tools` line read both canaries; settings keys and `permissions.deny` did not stop reads, and `init.tools`
30
+ # lists 60 tools either way (not a signal). `manage_task` (agy's own task list) still ran. So on this route:
31
+ # 1. refuse unless the prompt (stdin), the arguments and the working folder carry no company-repo root —
32
+ # the matcher is codex_launch_guard.sh's, and an UNCONFIGURED list is refused here, not warned;
33
+ # 2. refuse a caller's own --agent or any output format but text (a caller's `--output-format text` is
34
+ # dropped — this route prints the result text; FH's fleet and verifier pass it);
35
+ # 3. write an FH-owned definition with `tools: []` under a unique name into the folder agy discovers
36
+ # (FH_AGY_AGENTS_DIR, default ~/.gemini/agents — measured: `agy agents` lists definitions from
37
+ # ~/.gemini/agents and ~/.gemini/config/agents only, not from the working folder), run agy with
38
+ # --agent <it> --output-format stream-json, and remove the definition when the run ends;
39
+ # 4. read the whole stream and VOID the run (exit 4, nothing on stdout) when a line does not parse, the
40
+ # init event names another agent, a step is neither user_input nor agent_response nor a tool step whose
41
+ # tool_name AND tool_info.name are both exactly manage_task (any state — ACTIVE, DONE or ERROR), an event
42
+ # is not init / step_update / result, or no successful result arrives — naming the step or tool. Only a
43
+ # run that passes prints the result text on stdout. Deny by default: 13 probe runs saw manage_task,
44
+ # read_file, search_web and write_file, which is not every tool agy has.
45
+ # 🟥 A void cannot un-send: what a forbidden tool read has already gone to the cloud model. That is why step 1
46
+ # refuses company paths before the start, and why this route is for public material only.
47
+ #
26
48
  # Usage: bash scripts/agy_launch_guard.sh <agy-binary> [agy arguments...]
27
- # Exit: 3 = refused, agy was not started · 2 = usage · otherwise agy's own exit code
49
+ # Exit: 3 = refused, agy was not started · 2 = usage · 4 = no-tools-agent run voided (stdout empty)
50
+ # · otherwise agy's own exit code
28
51
  set -uo pipefail
29
52
  [ $# -ge 1 ] || { echo "usage: agy_launch_guard.sh <agy-binary> [agy arguments...]" >&2; exit 2; }
30
53
  case "${FH_AGY_ISOLATION-}" in
31
54
  container|os-user) exec "$@" ;;
55
+ no-tools-agent)
56
+ _here="$(cd "$(dirname "$0")" && pwd -P)"
57
+ _refuse() { echo "AGY-REFUSED: $1 — agy was not started (FH_AGY_ISOLATION=no-tools-agent)." >&2; exit 3; }
58
+ # The caller's own `--output-format text` is dropped (this route prints the result text anyway — FH's
59
+ # fleet and verifier pass it); any other output format or an --agent is refused.
60
+ _args=(); _skip=0
61
+ for _a in "${@:2}"; do
62
+ if [ "$_skip" = 1 ]; then
63
+ _skip=0; [ "$_a" = text ] && continue
64
+ _refuse "the caller asked for --output-format $_a; this route prints text only"
65
+ fi
66
+ case "$_a" in
67
+ --output-format) _skip=1 ;;
68
+ --output-format=text) ;;
69
+ --output-format=*) _refuse "the caller asked for $_a; this route prints text only" ;;
70
+ --agent|--agent=*) _refuse "the caller passed $_a; this route sets the agent itself" ;;
71
+ *) _args+=("$_a") ;;
72
+ esac
73
+ done
74
+ [ "$_skip" = 0 ] || _refuse "--output-format has no value"
75
+ set -- "$1" ${_args[@]+"${_args[@]}"}
76
+ [ -f "$_here/codex_launch_guard.sh" ] || _refuse "codex_launch_guard.sh (the company-path matcher) is missing beside this guard"
77
+ _w="$(mktemp -d "${TMPDIR:-/tmp}/fh_agy_nt.XXXXXX")" || _refuse "no temp dir"
78
+ _def=""
79
+ trap 'rm -rf "$_w"; [ -n "$_def" ] && rm -f "$_def"' EXIT
80
+ if [ -t 0 ]; then : > "$_w/prompt"; else cat > "$_w/prompt"; fi
81
+ _chk="$(bash "$_here/codex_launch_guard.sh" /usr/bin/true "$@" < "$_w/prompt" 2>&1)"; _crc=$? # the agy path itself too
82
+ [ "$_crc" -eq 0 ] || _refuse "the company-path check refused or failed: $(printf '%s' "$_chk" | tr '\n' ' ' | cut -c1-200)"
83
+ case "$_chk" in *"no company roots configured"*) _refuse "no company-repo roots are configured, so the prompt could not be checked" ;; esac
84
+ _dir="${FH_AGY_AGENTS_DIR:-$HOME/.gemini/agents}"
85
+ mkdir -p "$_dir" || _refuse "cannot create the agents folder $_dir"
86
+ _name="fh-notools-$(od -An -N6 -tx1 /dev/urandom | tr -d ' \n')"
87
+ [ "${#_name}" -eq 23 ] || _refuse "could not make a unique agent name"
88
+ _def="$_dir/$_name.md"
89
+ [ ! -e "$_def" ] || _refuse "an agent definition named $_name already exists"
90
+ printf -- '---\nname: %s\ndescription: FH tool-less agent (written by agy_launch_guard.sh, removed after the run)\ntools: []\n---\nYou have no tools. Answer from the prompt text only.\n' "$_name" > "$_def" \
91
+ || _refuse "cannot write the agent definition"
92
+ "$1" "${@:2}" --agent "$_name" --output-format stream-json < "$_w/prompt" > "$_w/stream" 2> "$_w/err"; _arc=$?
93
+ rm -f "$_def"; _def=""
94
+ _v="$(python3 - "$_w/stream" "$_name" "$_w/response" <<'PY'
95
+ import json, sys
96
+ path, name, out = sys.argv[1], sys.argv[2], sys.argv[3]
97
+ def void(why): print("VOID " + why); sys.exit(0)
98
+ init = result = None
99
+ try: lines = open(path, encoding="utf-8").read().splitlines()
100
+ except (OSError, UnicodeDecodeError) as e: void("stream unreadable (%s)" % type(e).__name__)
101
+ for n, raw in enumerate(lines, 1):
102
+ if not raw.strip(): void("line %d is blank" % n) # deny by default: agy does not print blank lines
103
+ try: d = json.loads(raw)
104
+ except ValueError: void("line %d is not JSON" % n)
105
+ if not isinstance(d, dict): void("line %d is not an object" % n)
106
+ ev = d.get("event")
107
+ body = d.get(ev) if isinstance(ev, str) else None
108
+ if not isinstance(body, dict): void("line %d has no event body" % n)
109
+ if ev == "init":
110
+ if init is not None: void("a second init event on line %d" % n)
111
+ init = body
112
+ if body.get("agent") != name: void("init names agent %r, not %s" % (body.get("agent"), name))
113
+ elif ev == "step_update":
114
+ if init is None: void("a step before the init event (line %d)" % n)
115
+ st = body.get("step_type")
116
+ if st in ("user_input", "agent_response"): continue
117
+ if st == "tool":
118
+ # agy 1.5.11 names a tool step twice: step_update.tool_name and step_update.tool_info.name (13 probe
119
+ # runs, 2026-11-19). Both must say manage_task; a missing or different one voids — whatever the
120
+ # state (ACTIVE, DONE or ERROR: a tool that started has run).
121
+ info = body.get("tool_info")
122
+ n1, n2 = body.get("tool_name"), (info.get("name") if isinstance(info, dict) else None)
123
+ if n1 == "manage_task" and n2 == "manage_task": continue
124
+ void("tool step %s (index %s, state %s)" % ("/".join(sorted({str(n1), str(n2)})), body.get("step_index"), body.get("state")))
125
+ void("step of type %r (index %s; keys %s)" % (st, body.get("step_index"), ",".join(sorted(body))))
126
+ elif ev == "result":
127
+ if result is not None: void("a second result event on line %d" % n)
128
+ result = body
129
+ else:
130
+ void("unknown event %r on line %d" % (ev, n))
131
+ if init is None: void("no init event")
132
+ if result is None: void("no result event")
133
+ if result.get("status") != "SUCCESS": void("result status %r" % result.get("status"))
134
+ resp = result.get("response")
135
+ if not isinstance(resp, str): void("result has no response text")
136
+ open(out, "w", encoding="utf-8").write(resp)
137
+ print("OK")
138
+ PY
139
+ )"
140
+ case "$_v" in
141
+ OK) cat "$_w/response"; exit "$_arc" ;;
142
+ VOID*) echo "AGY-VOID: ${_v#VOID } — the run was discarded (agy rc=$_arc). Anything a tool read has already been sent; this route takes public material only." >&2
143
+ [ -s "$_w/err" ] && tail -3 "$_w/err" >&2
144
+ exit 4 ;;
145
+ *) echo "AGY-VOID: the stream check did not run (${_v:-no output}) — the run was discarded (agy rc=$_arc)." >&2; exit 4 ;;
146
+ esac ;;
32
147
  remote-os-user)
33
148
  # Honoured for ONE route only: the target must be FH's remote runner beside this guard, which runs
34
149
  # agy as a separate OS user on another machine and itself refuses without a fresh canary receipt.
@@ -45,5 +160,6 @@ esac
45
160
  echo " agy runs shell and file tools and sends their output to a cloud model, so it must not run where"
46
161
  echo " company repositories are readable. Run it in a container or a separate OS user that sees only the"
47
162
  echo " frozen inputs, then set FH_AGY_ISOLATION=container|os-user there — or use a tool-less API call."
163
+ echo " On this machine, for public material only: FH_AGY_ISOLATION=no-tools-agent (a tools: [] agent, every run checked)."
48
164
  } >&2
49
165
  exit 3
@@ -23,7 +23,37 @@ MARKER_DIR="$REPO_ROOT/tracks/_meta"
23
23
  PENDING=0
24
24
  TOTAL=0
25
25
 
26
+ # Worktree redirect (2026-11-20 weekly audit): tracks/ is gitignored, so a git worktree has no
27
+ # markers of its own and the scan printed «0 total, 0 pending» rc 0 while the main checkout held
28
+ # 4 markers — «not read» rendered as «clean». The pre-commit hook WRITES markers to EVIDENCE_ROOT
29
+ # (the main checkout, via --git-common-dir), so with no root argument a worktree reads exactly
30
+ # there — the same rule, so writer and reader agree. If that place has no tracks/_meta, say
31
+ # NOT READ (rc unchanged — a CI worktree must not turn red). An explicit root is never redirected;
32
+ # a main checkout and a fresh clone are unchanged. The common dir is resolved to an absolute path
33
+ # from the cwd (git prints it relative to the cwd, not to the top level) and must be a `.git`
34
+ # directory, so a bare repo, --separate-git-dir or a submodule never names an unrelated parent.
35
+ WT_NOTE=""
36
+ if [ -z "${1:-}" ]; then
37
+ _gcd=$(git rev-parse --git-common-dir 2>/dev/null); _rc=$?
38
+ if [ "$_rc" -eq 0 ] && [ -n "$_gcd" ]; then
39
+ _gcd=$(cd "$_gcd" 2>/dev/null && pwd -P) || _gcd=""
40
+ _here=$(cd "$REPO_ROOT" 2>/dev/null && pwd -P) || _here="$REPO_ROOT"
41
+ if [ -n "$_gcd" ] && [ "$(basename "$_gcd")" = .git ]; then
42
+ _hub=$(dirname "$_gcd")
43
+ if [ "$_hub" != "$_here" ]; then
44
+ if [ -d "$_hub/tracks/_meta" ]; then
45
+ MARKER_DIR="$_hub/tracks/_meta"
46
+ WT_NOTE=" (git worktree — read the main checkout's tracks/_meta, where the pre-commit hook writes markers)"
47
+ else
48
+ WT_NOTE=" (git worktree — the main checkout has no tracks/_meta: markers NOT READ, the counts below are not a clean result)"
49
+ fi
50
+ fi
51
+ fi
52
+ fi
53
+ fi
54
+
26
55
  echo "── below-floor marker scan: $MARKER_DIR ──"
56
+ [ -n "$WT_NOTE" ] && echo "$WT_NOTE"
27
57
 
28
58
  if [ ! -d "$MARKER_DIR" ]; then
29
59
  echo " (no tracks/_meta directory — nothing to scan)"
@@ -22,7 +22,7 @@
22
22
  # UNCONFIGURED. No list, or an empty one: codex runs and the guard prints «CODEX-GUARD: no company roots
23
23
  # configured — not checked» on stderr. That is said out loud, never shown as clean.
24
24
  #
25
- # Usage: bash scripts/codex_launch_guard.sh <codex-binary> [codex arguments...] (prompt on stdin)
25
+ # Usage: bash scripts/codex_launch_guard.sh <codex-binary> [codex arguments...] (prompt on stdin; see STDIN below)
26
26
  # Exit: 3 = refused (codex not started; stderr starts «HARNESS-ERROR: CODEX-REFUSED») · 2 = usage
27
27
  # · otherwise codex's own exit code (a codex exit of 3 is told apart by the missing CODEX-REFUSED line)
28
28
  set -uo pipefail
@@ -31,7 +31,43 @@ _here="$(cd "$(dirname "$0")" && pwd -P)"
31
31
  _rootsfile="${FH_COMPANY_ROOTS_FILE:-$_here/../.claude/rules/.company-roots}"
32
32
  _tmp="$(mktemp "${TMPDIR:-/tmp}/fh_codex_prompt.XXXXXX")" || { echo "HARNESS-ERROR: codex_launch_guard cannot create a temp file — codex not started" >&2; exit 3; }
33
33
  trap 'rm -f "$_tmp"' EXIT
34
- if [ -t 0 ]; then : > "$_tmp"; else cat > "$_tmp"; fi
34
+ # STDIN. A terminal means no prompt (nothing is read). Anything else is read until it ends — but not forever:
35
+ # a stdin that sends nothing new for FH_GUARD_STDIN_IDLE_S seconds (default 60), or has not ended after
36
+ # FH_GUARD_STDIN_MAX_S seconds in all (default 600), is a refusal — never a partial or empty prompt passed on,
37
+ # never a hang. An agent's background shell hands its children a stdin that stays open and never ends;
38
+ # measured 2026-11-20, a plain `cat` here waited 2 h 30 min and, after the guard was killed, still held the
39
+ # caller's output pipe open. Each limit is a whole number of seconds from 1 to 86400 (unset or empty = the
40
+ # default); anything else is refused.
41
+ if [ -t 0 ]; then : > "$_tmp"
42
+ else
43
+ _idle="${FH_GUARD_STDIN_IDLE_S:-60}"; _max="${FH_GUARD_STDIN_MAX_S:-600}"
44
+ for _lim in "FH_GUARD_STDIN_IDLE_S=$_idle" "FH_GUARD_STDIN_MAX_S=$_max"; do
45
+ _v="${_lim#*=}"
46
+ case "$_v" in ''|*[!0-9]*) _v=x ;; *) [ "${#_v}" -le 5 ] && [ "$((10#$_v))" -ge 1 ] && [ "$((10#$_v))" -le 86400 ] || _v=x ;; esac
47
+ [ "$_v" = x ] && { echo "HARNESS-ERROR: CODEX-REFUSED — ${_lim%%=*}='${_lim#*=}' is not a whole number of seconds from 1 to 86400; codex was not started." >&2; exit 3; }
48
+ done
49
+ python3 -c '
50
+ import os, select, sys, time
51
+ idle, total = int(sys.argv[1], 10), int(sys.argv[2], 10); out = sys.stdout.buffer
52
+ end = time.monotonic() + total
53
+ try:
54
+ while True:
55
+ left = end - time.monotonic()
56
+ if left <= 0: sys.exit(125)
57
+ if not select.select([0], [], [], min(idle, left))[0]:
58
+ sys.exit(125 if time.monotonic() >= end else 124)
59
+ b = os.read(0, 65536)
60
+ if not b: break
61
+ out.write(b)
62
+ except OSError: sys.exit(5)
63
+ ' "$_idle" "$_max" > "$_tmp"
64
+ case $? in
65
+ 0) ;;
66
+ 124) echo "HARNESS-ERROR: CODEX-REFUSED — stdin is open but sent nothing for ${_idle} s and never ended (an agent background shell does this); codex was not started. Pipe the prompt in, or run with < /dev/null." >&2; exit 3 ;;
67
+ 125) echo "HARNESS-ERROR: CODEX-REFUSED — stdin had not ended after ${_max} s in all; codex was not started. Pipe in a prompt that ends, or run with < /dev/null." >&2; exit 3 ;;
68
+ *) echo "HARNESS-ERROR: CODEX-REFUSED — codex_launch_guard could not read the prompt from stdin; codex was not started." >&2; exit 3 ;;
69
+ esac
70
+ fi
35
71
  _verdict="$(FH_GUARD_PROMPT="$_tmp" FH_GUARD_ROOTS_FILE="$_rootsfile" python3 - "${@:2}" <<'PY'
36
72
  import os, re, sys
37
73
  def roots():
@@ -14,6 +14,15 @@ What it claims and what it does not:
14
14
  · "recurring" = two cue hits on different days that share >= --min-shared content words. Word
15
15
  overlap is a candidate filter, not a topic judgment — the reader decides whether a group is one rule.
16
16
  · every exclusion is counted and printed (malformed rows, short rows), never dropped silently.
17
+ · scheduled-trigger prompts (cron / self-scheduled check-ins) land in the ledger as if the operator
18
+ typed them. A row is a `repeated-prompt` (excluded, counted) when its whole text — whitespace
19
+ collapsed, digits removed so a time or counter inside it does not hide the repeat — is at least
20
+ REPEAT_MIN_CHARS long and occurs >= REPEAT_MIN times across ALL parseable ledger rows (counted
21
+ before --since, so the verdict does not depend on the window). Short texts are never excluded:
22
+ a short correction said three times is the signal this tool exists for. 2026-11-20 weekly audit:
23
+ 24 of 24 «recurring pairs» were two cron prompts pairing on «linked list_sessions».
24
+ Residual: a long correction pasted verbatim three times is excluded (counted, so it is visible);
25
+ a cron prompt over MAX_CHARS is counted under `long`, not here.
17
26
 
18
27
  usage: python3 scripts/correction_moments.py [ledger_dir] [--since YYYY-MM-DD] [--min-shared N] [--all]
19
28
  exit: 0 = ran · 2 = ledger dir missing or holds no rows (NOT a "no corrections" result)
@@ -27,6 +36,8 @@ STOP = set("그리고 그런데 그러면 이거 이건 그거 그건 저거 지
27
36
  "있어 있는 없어 없는 아니 아냐 아니야 아니라 말고 다시 정정 해줘 해봐 한번 모두 전부 같은 같아 "
28
37
  "this that with from have what when which there would could about into than then also only does your will".split())
29
38
  MIN_CHARS = 6
39
+ REPEAT_MIN_CHARS = 40 # shorter texts are never treated as scheduled prompts
40
+ REPEAT_MIN = 3 # occurrences across all ledger rows that make a text a scheduled prompt
30
41
  MAX_CHARS = 600 # longer rows are almost always pasted reports or documents, not a correction in the operator's words
31
42
 
32
43
 
@@ -54,6 +65,8 @@ def main(argv):
54
65
  min_shared = int(opt.get("--min-shared", "2"))
55
66
  files = sorted(glob.glob(os.path.join(d, "*.jsonl")))
56
67
  rows, bad, short, envelope, long_ = [], 0, 0, 0, 0
68
+ norm = lambda t: re.sub(r"\d+", "", " ".join(t.split()))
69
+ seen = {}
57
70
  for f in files:
58
71
  sess = os.path.basename(f)[:8]
59
72
  for line in open(f, encoding="utf-8", errors="replace"):
@@ -64,6 +77,7 @@ def main(argv):
64
77
  t, ts = x.get("text"), x.get("ts")
65
78
  if not isinstance(t, str) or not isinstance(ts, str):
66
79
  bad += 1; continue
80
+ seen[norm(t)] = seen.get(norm(t), 0) + 1
67
81
  if ts[:10] < since:
68
82
  continue
69
83
  if t.lstrip().startswith("<"):
@@ -74,6 +88,13 @@ def main(argv):
74
88
  if len(t) > MAX_CHARS:
75
89
  long_ += 1; continue
76
90
  rows.append((ts, sess, t))
91
+ is_rep = lambda t: len(norm(t)) >= REPEAT_MIN_CHARS and seen[norm(t)] >= REPEAT_MIN
92
+ repeated = sum(1 for _, _, t in rows if is_rep(t))
93
+ rows = [r for r in rows if not is_rep(r[2])]
94
+ if not rows and repeated:
95
+ print("⬜ every row is a repeated scheduled prompt (repeated-prompt=%d, envelope=%d short=%d long=%d malformed=%d)"
96
+ " — NOT MEASURED, not «no corrections»" % (repeated, envelope, short, long_, bad))
97
+ return 2
77
98
  if not rows:
78
99
  print("⬜ no ledger rows under %s (files=%d) — NOT MEASURED, not «no corrections»" % (d, len(files)))
79
100
  return 2
@@ -94,9 +115,9 @@ def main(argv):
94
115
  recurring.sort(key=lambda p: -len(p[2]))
95
116
  days = sorted({r[0][:10] for r in rows})
96
117
  print("# correction moments — %s .. %s (%d days)" % (days[0], days[-1], len(days)))
97
- print("ledgers=%d · utterances=%d · excluded: envelope=%d short(<%d chars)=%d long(>%d chars)=%d malformed=%d · cue hits=%d · "
118
+ print("ledgers=%d · utterances=%d · excluded: envelope=%d short(<%d chars)=%d long(>%d chars)=%d malformed=%d repeated-prompt=%d · cue hits=%d · "
98
119
  "recurring pairs (different days, >=%d shared words)=%d · re-pasted pairs dropped=%d" % (len(files), len(rows), envelope, MIN_CHARS, short, MAX_CHARS, long_, bad,
99
- len(hits), min_shared, len(recurring), repaste))
120
+ repeated, len(hits), min_shared, len(recurring), repaste))
100
121
  print("limits: cue-word recall only (a correction with no cue word is invisible — e.g. «영어로 써졌네», 2026-10-18) · word overlap is a candidate filter\n")
101
122
  for k, (i, j, sh) in enumerate(recurring, 1):
102
123
  print("## R%d — shared: %s" % (k, " ".join(sorted(sh)[:8])))