@chrono-meta/fh-gate 3.20.0 → 3.20.1

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.
@@ -11,25 +11,25 @@
11
11
  "plugins": [
12
12
  {
13
13
  "name": "fh-meta",
14
- "version": "3.20.0",
14
+ "version": "3.20.1",
15
15
  "description": "New in 2.2.0: BREAKING (gate): chamber step 6 now reads ACTUAL.md, not BUDGET.md — an in-flight chamber run whose actual cost sits in BUDGET.md blocks until the ACTUAL: line moves to tracks/_chamber/<slug>/ACTUAL.md (the runner prints the path). Why: BUDGET.md's pre-verdict hash IS the ordering witness, and step 6 hard-blocked until that same file changed, so every run that reached COMPLETE necessarily mutated a witnessed artifact and verify returned TAMPERED — the chamber's promotion condition was unsatisfiable by construction, not by strictness. Two roles (immutable witness / post-verdict calibration sink) had collided in one file; each was correct alone, so neither side's code showed the conflict. Also: ko-tech-writer Step 2/4-b scans are now calibration-backed (known-pair fixtures + reproducible command, shipped) — discrimination is proven, 'zero residue' is explicitly NOT; chamber lane suite 12 -> 33 including the runner x witness seam no test covered; chamber_run.sh now teaches the two-commit discipline (gate hashes and verdict hash must land in separate commits/PRs — it previously advised the opposite). New in 2.1.0: BREAKING (gate): `crossfamily: declined` in an Axes 2-3 marker now requires grounds naming a record path that RESOLVES on disk — bare `declined`, and `declined` justified by author judgment, are blocked at commit. Remedy: cite where the operator decision lives (e.g. `.. — operator declined sidecars, per knowledge/shared/rules/operational_adaptation.md`), or use `DEGRADED_PANEL_UNUSED` if a panel was reachable and you chose not to recruit it — which is what author judgment actually is. `declined` was the only enum value with no grounds requirement; a cross-family review then broke the first (vocabulary-grep) fix three ways — self-validating on the value's own token, vacuous keyword passes, and over-blocking real declinations in natural prose — so the check asserts a resolvable record instead of words. Also: standpoint axis gains `tier1b` (a STATIC read of a target repo, executed nothing) plus a decide-in-order procedure, after blind floor-tier sims graded pure cold-reads as `tier2` three rounds running; steel-quench Wave 1's sixth angle (gate-locality) gains the output-template row it never had, so a mandatory angle stops being structurally unreportable; verify-bidirectional gains category 5 (prescriptive doctrine statement); Sister Asset Protocol gains an active-adoption trigger; new resident doctrine — Mechanization Boundary, Local Execution First, Skeleton-not-Muscle, Expedition track, and this package's versioning policy. Hub meta-operations toolkit — 35 skills + 7 agents. New in 2.0.1: harness-doctor cadence hook, portability lint wired into pre-commit, branch_claim.sh claim-count-vs-tree-count warning, louder confidentiality-scan fail-open notice, fh-gate.sh missing-package.json survival, identity ① reclassified 🟢 (cross-harness adapters + relay argument channel). New in 1.4.53: `fh-codex-doctor` (npm bin) — Codex adapter drift scanner; reads the documented M1/M2/M3 skill tier map + skill/agent source and reports codex-native/adapter-required/claude-native/unclassified per unit, wired into `npm test`/`prepublishOnly` (fail-closed on unclassified Claude-native primitives). New in 1.4.49: steel-quench gains Step 0.6 Verdict-Invariance Probe (groundedness axis — a load-bearing judged gate's verdict must track behavior, not rubric phrasing; measured flip-count over cross-family paraphrases; arXiv:2605.06161 Policy Invariance anchor); multi_model_sidecar_strategy §Vendor-native harness (a model is strongest in its own vendor CLI — Claude/CC, GPT/codex, Gemini/Antigravity; a universal router degrades all of them, so it stays an autocomplete/QA sidecar, never orchestration); predelete_check.sh fail-closed rewrite; memory-hygiene A-TMA anchor. New in 1.4.48: phantom-quench + steel-quench gain external frontier anchors (arXiv:2607.02052 package-hallucination; arXiv:2607.02057 prompt-coverage-adequacy); README model-flat claim reframed from a per-release point-curve to structural invariants (operation flattens across tiers; depth tier-order fixed within a generation). New in 1.4.47: onboarding step ① surfaces the Mode D companion-store session-start load in the auto-read salience anchor (previously only in the local binding + rules, so a greeting could skip the load). New in 1.4.46: context-doctor command-output axis (route to rtk/proxy for verbose CLI stdout, complementing .claudeignore; risk-gated to token-scarce envs). New in 1.4.41: context-doctor 2026 trigger vocab (context engineering/rot/collapse) + phantom-citation hardening; hub measurement-integrity-checklist (cross-model measurement pre-flight: display-name pin/reps≥3/discriminating probe). New in 1.4.40: install-wizard queryable-wiki scaffold (INDEX + session-start read + R/W/C ingest). New in 1.4.39: auto-decorrelation (cross-family verifier sidecar recruitment) + video-ingest (capability-routed video ingestion). New in 1.4.x: verify-axis check-class taxonomy (mandatory-pass/measured/judged), no-reinvention Tier-0 inventory, 7-class failure taxonomy, Destructive-Op Gate, Wave-T (Temper), tier-floor governance, Mode D Model Notice, FC consent lane, default-Sonnet guidance. New in 1.3.0: public-surface-audit, field-harvest Mode B auto-trigger, 4-axis gate scope ext. Validated cross-CLI: Claude Code, Codex, Gemini.",
16
16
  "source": "./plugins/fh-meta"
17
17
  },
18
18
  {
19
19
  "name": "fh-commons",
20
- "version": "3.20.0",
20
+ "version": "3.20.1",
21
21
  "description": "Project-agnostic utility skills — 6 skills (convergence-loop · deliberation · mcp-circuit-breaker · token-budget-gate · ko-tech-writer · persona-cast) + 7 agents (quench-challenger + the web-review cast: designer · ux-writer · fe-dev · be-dev · qa · a11y). Domain-independent utilities transplantable into any project.",
22
22
  "source": "./plugins/fh-commons"
23
23
  },
24
24
  {
25
25
  "name": "fh-qp",
26
- "version": "3.20.0",
26
+ "version": "3.20.1",
27
27
  "description": "QP (Quality Platform) — the generic edition of a field QA harness's Prepare→Automation→Regression loop as an FH plugin: 4 skills (qp router · qp-plan · qp-run · qp-regress) + qp_tools.sh (target-class · adapter-probe · mask · surface-reach · mtm-check · run-verbs, typed exit codes) + a zero-domain-constant profile slot + 29 known-pair lanes. Drives web targets through the session's Playwright MCP and desktop targets through computer-use MCP (mobile deferred); calls a registered qasp typed capability when one exists (strictest-wins) — none is registered today, so the MCP fallback is the first edition. Verdict contract: a MACHINE closure requires a recorded assertion; a failed first step is attributed BLOCKED, not FAIL; surface_reach counts every TC in the denominator. Born as chamber run #18 (EMIT, 2026-09-05).",
28
28
  "source": "./plugins/fh-qp"
29
29
  },
30
30
  {
31
31
  "name": "fh-preprep",
32
- "version": "3.20.0",
32
+ "version": "3.20.1",
33
33
  "description": "preprep — a presentation-preparation harness. 1 skill. One CLI over 17 lanes (7 built-in + 10 module) that reads a declared surface manifest and checks a talk's assets against each other: canonical terms, jargon glosses, retired vocabulary, inter-slide dependencies, pacing, get/put round-trips, adjacent duplication, slide relations, geometry, attribute consistency, fonts, diagrams, slide refs, and screen-parity between manuscript and deck. Verdict contract: exit 0 pass / 1 findings / 2 cannot-judge — a surface that could not be read is UNMEASURED, never 0. Promoted out of fh-commons 2026-09-13 after the skill grew past one role (routing / lane modules / fixtures).",
34
34
  "source": "./plugins/fh-preprep"
35
35
  }
@@ -4375,3 +4375,25 @@
4375
4375
  (주석자 본인이 보고). 결함은 팔이 아니라 내 발주였다. #2 를 중립 파일명으로 재발주해 키로 썼다.
4376
4376
  주간감사 팔은 자기 selfcheck 출력을 `tail` 로 잘라 rc 를 못 잡았고 그걸 UNCALIBRATED 로
4377
4377
  정직하게 적었다 — PASS 로 접지 않았다.
4378
+
4379
+ - date: 2026-09-25
4380
+ session: 52d2b905 (FH 클라우드 세션 · 크레딧 소진 갈래 · 거버너 Opus 5.5)
4381
+ agent: general-purpose (opus ×6)
4382
+ task: >-
4383
+ ① qasp 프런티어 E1~E7 대조·구현(외부 발송 금지 코드) ② FoD gate_hook 적대 감사(수정 금지)
4384
+ ③ FH ④-e 수리 블라인드 Axis 2 리뷰 ④ qasp P2 «결함 수=커버리지» 수리 ⑤ FoD 자유배회 수면 수리
4385
+ (워크트리) ⑥ FoD 클라우드 브리지 — 비콘·릴레이·브리지(워크트리)
4386
+ count: 6
4387
+ outcome: partial
4388
+ evidence: >-
4389
+ ①④⑤⑥ 산출 채택 — qasp #336 머지(ce05f31, 새 레인 33) · FoD #120(수면 레인 21/21, 원본 16 적색 ·
4390
+ 클라우드 e2e 46/46 진짜 clawd 포함). ③ 결함 4건 재현, 3건 반영(열린 stdin fail-open 은 초판이 만든 것).
4391
+ 🟥 partial 인 이유 둘: ② 감사는 끝냈는데 **보고가 안전 분류기에 막혀 결함 목록이 한 건도 안 왔다** —
4392
+ 거버너가 차분 측정으로 확인한 갭만 고쳤다. ④⑤ 는 **핸드백 없이 종료** — 커밋은 있었고 거버너가
4393
+ diff·레인·스위트를 처음부터 다시 돌려 검증했다(보고 주장 대신 실행으로).
4394
+ learning: >-
4395
+ 🟥 **우회 명령을 문맥 없이 대량 열거하는 형태는 방어 목적이어도 분류기에 막힌다** — 팔의 보고와
4396
+ 거버너 자신의 코퍼스 생성 둘 다 막혔다. 처방은 «말을 바꿔 재시도» 가 아니라 **확인된 소수 갭만 코드에서
4397
+ 고치고 재현은 레인 파일 안에만** 두는 것이었다. 두 병렬 팔이 같은 게이트 번호(G30)를 각자 써서
4398
+ cherry-pick 에서 충돌했다 — 병렬 팔에 번호 대역을 미리 나눠 주지 않은 발주 결함.
4399
+ ⚠️ 보고 없이 끝난 팔 둘은 «커밋 있음» 이 곧 «검증됨» 이 아니다 — 매번 거버너 재실행으로 닫았다.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@chrono-meta/fh-gate",
3
- "version": "3.20.0",
3
+ "version": "3.20.1",
4
4
  "description": "FH runtime adapters — run FH governance, skills, and agents via Claude or Codex with machine-parseable gates.",
5
5
  "homepage": "https://github.com/chrono-meta/forge-harness#readme",
6
6
  "bugs": {
@@ -248,6 +248,8 @@
248
248
  "scripts/test_degrade_scan_shell_probes.sh",
249
249
  "scripts/test_destructive_pre_gate_lanes.sh",
250
250
  "scripts/test_dispatch_log_lanes.sh",
251
+ "scripts/test_subagent_tally_hook_lanes.sh",
252
+ "scripts/subagent_tally_hook.sh",
251
253
  "scripts/test_doc_claim_triad_lanes.sh",
252
254
  "scripts/test_env_layer_fingerprint_lanes.sh",
253
255
  "scripts/test_env_purity_lanes.sh",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fh-commons",
3
- "version": "3.20.0",
3
+ "version": "3.20.1",
4
4
  "engines": {
5
5
  "claudeCode": ">=1.0.0"
6
6
  },
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fh-meta",
3
- "version": "3.20.0",
3
+ "version": "3.20.1",
4
4
  "engines": {
5
5
  "claudeCode": ">=1.0.0"
6
6
  },
@@ -1,5 +1,16 @@
1
1
  # forge-harness (fh-meta) Changelog
2
2
 
3
+ ### [3.20.1] — 2026-09-26 — 마감 게이트 ④-e 가 Claude Code 내부 에이전트를 디스패치로 세지 않는다
4
+
5
+ **patch — 오탐 수리.** 소비자의 게이트 수용은 안 깬다(과다 계수 → 정확 계수 방향).
6
+
7
+ - **`scripts/subagent_tally_hook.sh`** (신규 출하) — SubagentStop 이 압축 같은 CC 내부 에이전트(`agent_type: ""`)에도
8
+ 울려 디스패치 0 인 세션이 ④-e 에 막히던 오탐 수리. «필드가 있고 정확히 빈 문자열» 일 때만 빼고 의심은 전부 센다.
9
+ 표준입력은 python 이 유휴 2s · 총 3s · 8 MiB 로 읽는다 — 맥 `/bin/bash` 3.2 는 `read -t` 타임아웃 때 부분 줄을
10
+ 버려 bash 판이 맥에서만 틀렸다(bash 5 에선 안 보임). 총 제한은 훅 timeout(5s)보다 짧게. 레인 24/0(bash 3.2·5.3).
11
+ - **`templates/subagent-tally-hook.json`** — 본문이 위 스크립트를 부른다(스크립트 없는 옛 클론은 옛 동작으로 폴백).
12
+ 🟥 **기존 install 은 `.claude/settings.json` 의 SubagentStop 블록을 재병합해야** 새 동작을 받는다.
13
+
3
14
  ### [3.20.0] — 2026-09-24 — 스쿼시 머지가 브랜치를 «다 실었나» 를 명령으로 확인한다
4
15
 
5
16
  **minor — 새 출하 스크립트 둘 + 머지 절차 교리 변경.** 소비자의 게이트 수용은 안 깬다(새 스크립트는
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fh-preprep",
3
- "version": "3.20.0",
3
+ "version": "3.20.1",
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.20.0",
3
+ "version": "3.20.1",
4
4
  "engines": {
5
5
  "claudeCode": ">=1.0.0"
6
6
  },
@@ -2225,6 +2225,17 @@ if [ -f scripts/test_dispatch_log_lanes.sh ]; then
2225
2225
  fail=1
2226
2226
  fi
2227
2227
  fi
2228
+ # The tally hook's BODY (2026-09-25): SubagentStop also fires for Claude Code's internal agents
2229
+ # (compaction → agent_type ""), and the date-only inline hook counted them as dispatches.
2230
+ if [ -f scripts/test_subagent_tally_hook_lanes.sh ]; then
2231
+ if _out=$(bash scripts/test_subagent_tally_hook_lanes.sh 2>&1); then
2232
+ echo "PASS test_subagent_tally_hook_lanes.sh (internal-agent skip + count-on-doubt lanes)"
2233
+ else
2234
+ echo "FAIL test_subagent_tally_hook_lanes.sh: the dispatch tally would mis-count"
2235
+ _show_failure "$_out"
2236
+ fail=1
2237
+ fi
2238
+ fi
2228
2239
 
2229
2240
  # selfcheck's own subject-presence discriminators. Every other guard under scripts/ has a lane suite;
2230
2241
  # this decision had none, and it shipped two mis-routings in one session — a two-arm form that fell
@@ -0,0 +1,95 @@
1
+ #!/usr/bin/env bash
2
+ # subagent_tally_hook.sh — SubagentStop hook body: append today's date to the dispatch tally that
3
+ # session_close_check.sh ④-e reconciles against the invocation log. TALLIES ONLY — it never writes a
4
+ # log entry (a fabricated outcome/evidence would poison the 60/40 promotion gate).
5
+ #
6
+ # WHY THIS IS A SCRIPT NOW (2026-09-25, fh_signal_2026-09-25_subagent-tally-counts-internal-agents):
7
+ # SubagentStop also fires for Claude Code's OWN internal agents — measured: `/compact` produced a
8
+ # SubagentStop with `agent_type: ""` (PreCompact fired alongside it), while a dispatched Explore
9
+ # agent carried `agent_type: "Explore"` and a dispatch with subagent_type OMITTED carried
10
+ # `agent_type: "general-purpose"` (claude 2.1.282, headless, 2026-09-25). The inline hook counted
11
+ # all three, so a session that dispatched nothing failed ④-e after a context compaction — and the
12
+ # operator was twice told «probably a peer session», which was false.
13
+ #
14
+ # DISCRIMINATOR — and why it is this narrow:
15
+ # skip ONLY when `agent_type` is PRESENT and EXACTLY "". Everything else counts:
16
+ # field absent (older CLI) · non-JSON stdin · empty stdin · no python3 → COUNT.
17
+ # Over-counting re-creates the known false positive (loud, the operator sees it). Under-counting a
18
+ # real dispatch is the fail-open ④-e exists to close (silent). So every doubt lands on «count».
19
+ #
20
+ # ALSO RECORDED: session_id and agent_type go to a SIDE file, never into the tally line — ④-e matches
21
+ # `^DATE$` exactly, and changing the tally format would silently zero every count on a machine
22
+ # running the old checker. The side file is for attribution when a count looks wrong.
23
+ #
24
+ # exit 0 ALWAYS — a failing hook must never block a subagent from finishing.
25
+
26
+ HUB="${CLAUDE_PROJECT_DIR:-$(git rev-parse --show-toplevel 2>/dev/null || echo "$HOME/projects/forge-harness")}"
27
+ T="${FH_TALLY_FILE:-$HUB/tracks/_meta/.subagent_dispatch_tally}"
28
+ # 🟥 Read with a TIME LIMIT, never a bare `cat`. A caller that never closes stdin would park `cat` on
29
+ # EOF until the hook's own `timeout` kills it — BEFORE the append below — and a real dispatch would
30
+ # vanish silently (Axis-2 blind review, 2026-09-25, reproduced with `sleep 8 | …`; the old inline
31
+ # hook never read stdin, so this was new).
32
+ # 🟥 The bounded read lives in python, not in a bash `read` loop (2026-09-25, local macOS run):
33
+ # · line-wise `read -t` — /bin/bash 3.2 DISCARDS a partial line on timeout (bash ≥4 keeps it), so a
34
+ # payload without a trailing newline on an open pipe read as EMPTY on macOS only
35
+ # (measured: 3.2 rc=1 got=[] · 5.3 rc=142 got=[abc]);
36
+ # · char-wise `read -n 1` — fixes that but is superlinear: 50 KB took 19 s, and SubagentStop
37
+ # carries the agent's last message.
38
+ # Rules, all landing on COUNT when in doubt: stop at EOF, or after 2 s with no new bytes (open pipe
39
+ # → classify what arrived), or at 3 s total (under the 5 s hook timeout) · over 8 MiB → count · a raw NUL → json rejects it →
40
+ # count (codex review 2026-09-25 showed a bash char-reader turning NUL into whitespace → silent
41
+ # «internal»; json does the rejecting here, so there is deliberately no separate NUL guard — a
42
+ # revert probe showed one would be decorative).
43
+ # No python3 → stdin is not read at all → count (the old inline hook never read it either).
44
+ CLS="count"
45
+ AT=""; SID=""
46
+ if command -v python3 >/dev/null 2>&1; then
47
+ _r=$(python3 -c '
48
+ import json, os, select, sys, time
49
+ fd = 0; buf = b""; cap = 8 << 20; doubt = False
50
+ t_end = time.monotonic() + 3.0 # < settings.json hook timeout 5 s — the kill would land BEFORE the append
51
+ try:
52
+ while True:
53
+ left = t_end - time.monotonic()
54
+ if left <= 0:
55
+ break
56
+ r, _, _ = select.select([fd], [], [], min(2.0, left))
57
+ if not r:
58
+ break # idle 2 s — pipe left open; classify what arrived
59
+ chunk = os.read(fd, 65536)
60
+ if not chunk:
61
+ break # EOF
62
+ buf += chunk
63
+ if len(buf) > cap:
64
+ doubt = True; break
65
+ except Exception:
66
+ doubt = True
67
+ if doubt or not buf.strip():
68
+ print("count\t\t"); sys.exit(0)
69
+ try:
70
+ d = json.loads(buf.decode("utf-8"))
71
+ except Exception:
72
+ print("count\t\t"); sys.exit(0)
73
+ if not isinstance(d, dict):
74
+ print("count\t\t"); sys.exit(0)
75
+ at = d.get("agent_type", None)
76
+ sid = d.get("session_id", "")
77
+ sid = sid if isinstance(sid, str) else ""
78
+ if at == "":
79
+ print("internal\t\t" + sid)
80
+ else:
81
+ print("count\t" + (at if isinstance(at, str) else "?") + "\t" + sid)
82
+ ' 2>/dev/null) || _r=""
83
+ if [ -n "$_r" ]; then
84
+ CLS=$(printf '%s' "$_r" | cut -f1)
85
+ AT=$(printf '%s' "$_r" | cut -f2)
86
+ SID=$(printf '%s' "$_r" | cut -f3)
87
+ fi
88
+ fi
89
+
90
+ mkdir -p "$(dirname "$T")" 2>/dev/null
91
+ D=$(date +%Y-%m-%d)
92
+ printf '%s\t%s\t%s\t%s\n' "$D" "$CLS" "${AT:--}" "${SID:--}" >> "$T.detail" 2>/dev/null
93
+ [ "$CLS" = internal ] && exit 0
94
+ printf '%s\n' "$D" >> "$T" 2>/dev/null
95
+ exit 0
@@ -0,0 +1,105 @@
1
+ #!/usr/bin/env bash
2
+ # test_subagent_tally_hook_lanes.sh — known-pair lanes for scripts/subagent_tally_hook.sh.
3
+ #
4
+ # WHAT IS PINNED: SubagentStop fires for dispatched agents AND for Claude Code's internal agents.
5
+ # Fixture shapes below are the MEASURED payloads (claude 2.1.282 headless, 2026-09-25), trimmed to
6
+ # the fields that matter:
7
+ # dispatch, subagent_type=Explore → agent_type "Explore"
8
+ # dispatch, subagent_type omitted → agent_type "general-purpose"
9
+ # /compact (internal, PreCompact fired) → agent_type ""
10
+ # The tally must count the first two and skip the third — and must COUNT on every doubtful input
11
+ # (absent field · non-JSON · empty stdin), because under-counting a real dispatch is the silent
12
+ # fail-open ④-e exists to close.
13
+ #
14
+ # REVERT PROBE: the old inline hook (date-only append) is replayed against the internal-agent
15
+ # fixture and MUST count it. If it ever stops counting, the lane pair is no longer measuring the
16
+ # defect it was written for.
17
+ #
18
+ # Exit 0 = discriminates · 1 = would mis-tally.
19
+ set -uo pipefail
20
+ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
21
+ SUBJ="$SCRIPT_DIR/subagent_tally_hook.sh"
22
+ FAILED=0; PASS=0
23
+ chk() { if [ "$1" -eq 0 ]; then PASS=$((PASS+1)); echo " ✅ $2"; else FAILED=1; echo " ❌ $2"; fi; }
24
+ [ -f "$SUBJ" ] || { echo "FAIL subject $SUBJ missing"; exit 1; }
25
+ command -v python3 >/dev/null 2>&1 || { echo "SKIP python3 absent — the discriminator cannot run here (the hook then COUNTS everything, the safe direction). Not a pass."; exit 0; }
26
+
27
+ T=$(mktemp -d); trap 'rm -rf "$T"' EXIT
28
+ TODAY=$(date +%Y-%m-%d)
29
+ run() { # $1 = stdin payload ; echoes today's tally count after one invocation on a fresh file
30
+ local f="$T/tally.$RANDOM$RANDOM"
31
+ printf '%s' "$1" | FH_TALLY_FILE="$f" bash "$SUBJ" >/dev/null 2>&1 || { echo RC_NONZERO; return; }
32
+ if [ -f "$f" ]; then grep -c "^$TODAY$" "$f"; else echo 0; fi
33
+ }
34
+ P_EXPLORE='{"session_id":"s1","hook_event_name":"SubagentStop","agent_id":"a1","agent_type":"Explore"}'
35
+ P_GENERAL='{"session_id":"s1","hook_event_name":"SubagentStop","agent_id":"a2","agent_type":"general-purpose"}'
36
+ P_INTERNAL='{"session_id":"s1","hook_event_name":"SubagentStop","agent_id":"a3","agent_type":""}'
37
+ P_NOFIELD='{"session_id":"s1","hook_event_name":"SubagentStop","agent_id":"a4"}'
38
+
39
+ echo "── known-positive: dispatched agents are counted"
40
+ [ "$(run "$P_EXPLORE")" = 1 ] ; chk $? "agent_type Explore → counted"
41
+ [ "$(run "$P_GENERAL")" = 1 ] ; chk $? "subagent_type omitted (general-purpose) → counted"
42
+ echo "── known-negative: the internal agent is skipped"
43
+ [ "$(run "$P_INTERNAL")" = 0 ] ; chk $? "agent_type \"\" (compaction) → NOT counted"
44
+ echo "── every doubt counts (under-count is the silent direction)"
45
+ [ "$(run "$P_NOFIELD")" = 1 ] ; chk $? "agent_type absent (older CLI) → counted"
46
+ [ "$(run 'not json {')" = 1 ] ; chk $? "non-JSON stdin → counted"
47
+ [ "$(run '')" = 1 ] ; chk $? "empty stdin → counted"
48
+ [ "$(run '[1,2]')" = 1 ] ; chk $? "JSON but not an object → counted"
49
+ [ "$(run '{"agent_type":null}')" = 1 ] ; chk $? "agent_type null (not the empty string) → counted"
50
+
51
+ echo "── tally line format unchanged (④-e matches ^DATE\$ exactly)"
52
+ f="$T/fmt"; printf '%s' "$P_EXPLORE" | FH_TALLY_FILE="$f" bash "$SUBJ"
53
+ [ "$(cat "$f")" = "$TODAY" ] ; chk $? "the tally line is the bare date, nothing appended"
54
+ printf '%s' "$P_INTERNAL" | FH_TALLY_FILE="$f" bash "$SUBJ"
55
+ grep -q "$(printf '%s\tinternal\t-\ts1' "$TODAY")" "$f.detail" ; chk $? "the skipped internal agent is still RECORDED in the side file (attributable, not vanished)"
56
+
57
+ echo "── rc"
58
+ out=$(printf 'garbage' | FH_TALLY_FILE=/nonexistent-dir/x/y bash "$SUBJ" 2>&1); rc=$?
59
+ [ "$rc" -eq 0 ] ; chk $? "unwritable tally path → still exit 0 (a hook must never block a subagent)"
60
+
61
+ echo "── revert probe: the OLD inline body counts the internal agent (control)"
62
+ old() { printf '%s\n' "$(date +%Y-%m-%d)" >> "$1"; }
63
+ f="$T/old"; printf '%s' "$P_INTERNAL" | old "$f"
64
+ [ "$(grep -c "^$TODAY$" "$f")" = 1 ] ; chk $? "control alive: date-only append DOES count compaction — the defect this lane exists for"
65
+
66
+ echo "── stdin never closed (the caller keeps the pipe open) → still counts, within the limit"
67
+ f="$T/open"
68
+ # 🟥 time the HOOK only — timing the whole pipeline also waits for the producer's `sleep`.
69
+ ( sleep 5 ) | { s0=$(date +%s); FH_TALLY_FILE="$f" bash "$SUBJ"; echo $(( $(date +%s) - s0 )) > "$f.dur"; }
70
+ dur=$(cat "$f.dur" 2>/dev/null || echo 99)
71
+ [ "$(grep -c "^$TODAY$" "$f" 2>/dev/null || echo 0)" = 1 ] ; chk $? "open, silent stdin → counted (a bare \`cat\` blocked here until the hook was killed)"
72
+ [ "$dur" -le 4 ] ; chk $? "and the hook returned by its read limit, not at the caller's EOF (${dur}s)"
73
+ f="$T/open2"; ( printf '%s' "$P_INTERNAL"; sleep 5 ) | FH_TALLY_FILE="$f" bash "$SUBJ"
74
+ [ "$(grep -c "^$TODAY$" "$f" 2>/dev/null || echo 0)" = 0 ] ; chk $? "payload delivered but pipe left open → still classified (internal skipped)"
75
+
76
+ f="$T/nul"; printf '%s\0 ' "$P_INTERNAL" | FH_TALLY_FILE="$f" bash "$SUBJ"
77
+ [ "$(grep -c "^$TODAY$" "$f" 2>/dev/null || echo 0)" = 1 ] ; chk $? "raw NUL after an internal payload → counted (OUTCOME lane: json rejects NUL — the bash reader that turned it into whitespace is gone; codex 2026-09-25)"
78
+ f="$T/big"; { printf '{"agent_type":"","pad":"'; head -c 9000000 /dev/zero | tr '\0' x; printf '"}'; } | { s0=$(date +%s); FH_TALLY_FILE="$f" bash "$SUBJ"; echo $(( $(date +%s) - s0 )) > "$f.dur"; }; e=$(cat "$f.dur" 2>/dev/null || echo 99)
79
+ [ "$(grep -c "^$TODAY$" "$f" 2>/dev/null || echo 0)" = 1 ] ; chk $? "payload over the 8 MiB cap → truncated → DOUBT → counted"
80
+ [ "$e" -le 8 ] ; chk $? "and the cap bounds the read time (${e}s)"
81
+
82
+ # 🟥 time the HOOK only (see the «stdin never closed» lane above) — CI runners ignore SIGPIPE, so the
83
+ # producer keeps sleeping after the hook exits and a whole-pipeline timer read 8 s there (4 s on macOS).
84
+ f="$T/trickle"; ( for i in 1 2 3 4 5 6 7 8; do printf ' '; sleep 1; done; printf '%s' "$P_INTERNAL" ) | { s0=$(date +%s); FH_TALLY_FILE="$f" bash "$SUBJ"; echo $(( $(date +%s) - s0 )) > "$f.dur"; }; e=$(cat "$f.dur" 2>/dev/null || echo 99)
85
+ [ "$(grep -c "^$TODAY$" "$f" 2>/dev/null || echo 0)" = 1 ] ; chk $? "slow trickle (1 byte/s, never idle 2 s) → deadline cuts it → counted"
86
+ [ "$e" -le 4 ] ; chk $? "and the deadline lands inside the settings.json hook timeout (5 s) with margin (${e}s — a 5 s deadline raced the kill, which lands BEFORE the append)"
87
+
88
+ echo "── wiring: EXECUTE the shipped template command (a grep for the path matched the _readme text)"
89
+ TPL="$SCRIPT_DIR/../templates/subagent-tally-hook.json"
90
+ CMD=$(python3 -c 'import json,sys;print(json.load(open(sys.argv[1]))["hooks"]["SubagentStop"][0]["hooks"][0]["command"])' "$TPL" 2>/dev/null)
91
+ [ -n "$CMD" ] ; chk $? "template command extracted from hooks.SubagentStop[0].hooks[0].command"
92
+ tpl_run() { # $1 = hub dir · $2 = payload → today's count in that hub's tally
93
+ printf '%s' "$2" | CLAUDE_PROJECT_DIR="$1" bash -c "$CMD" >/dev/null 2>&1
94
+ local t="$1/tracks/_meta/.subagent_dispatch_tally"
95
+ if [ -f "$t" ]; then grep -c "^$TODAY$" "$t"; else echo 0; fi
96
+ }
97
+ H1="$T/hub_with"; mkdir -p "$H1/scripts"; cp "$SUBJ" "$H1/scripts/"
98
+ [ "$(tpl_run "$H1" "$P_INTERNAL")" = 0 ] ; chk $? "template + script present: internal agent → 0 (the command really calls the script)"
99
+ [ "$(tpl_run "$H1" "$P_EXPLORE")" = 1 ] ; chk $? "template + script present: Explore → 1"
100
+ H2="$T/hub_without"; mkdir -p "$H2"
101
+ [ "$(tpl_run "$H2" "$P_INTERNAL")" = 1 ] ; chk $? "template + script MISSING (older clone): falls back to counting → 1, never silence"
102
+
103
+ echo ""
104
+ if [ "$FAILED" -eq 0 ]; then echo "PASS subagent tally hook: $PASS lanes"; exit 0; fi
105
+ echo "FAIL subagent tally hook"; exit 1
@@ -1,5 +1,5 @@
1
1
  {
2
- "_readme": "FH dispatch-tally hook. Merge the `hooks.SubagentStop` block below into your .claude/settings.json (that file is gitignored, which is why this template exists). It feeds session_close_check.sh ④-e, which blocks a close push when sub-agents were dispatched and the day's invocation-log entries are zero. The hook TALLIES ONLY — it never writes a log entry, because a fabricated outcome/evidence field would poison the 60/40 promotion gate worse than a missing one. Root resolution is 3-tier (CLAUDE_PROJECT_DIR -> git rev-parse --show-toplevel -> hardcoded path), matching the SAME convention fh_node_check.sh already uses in its own SessionStart hook -- a 2026-08-16 standpoint review on a sibling harness (pmh-dev) found this template's earlier 2-tier version get copy-pasted without picking up that convention, silently diverging from session_close_check.sh's own git-toplevel-first resolution in a nested/worktree/subagent context. If you adapt this template for another repo, keep the 3-tier form.",
2
+ "_readme": "FH dispatch-tally hook. Merge the `hooks.SubagentStop` block below into your .claude/settings.json (that file is gitignored, which is why this template exists). It feeds session_close_check.sh ④-e, which blocks a close push when sub-agents were dispatched and the day's invocation-log entries are zero. The hook TALLIES ONLY — it never writes a log entry, because a fabricated outcome/evidence field would poison the 60/40 promotion gate worse than a missing one. Root resolution is 3-tier (CLAUDE_PROJECT_DIR -> git rev-parse --show-toplevel -> hardcoded path), matching the SAME convention fh_node_check.sh already uses in its own SessionStart hook -- a 2026-08-16 standpoint review on a sibling harness (pmh-dev) found this template's earlier 2-tier version get copy-pasted without picking up that convention, silently diverging from session_close_check.sh's own git-toplevel-first resolution in a nested/worktree/subagent context. If you adapt this template for another repo, keep the 3-tier form. 2026-09-25: the body moved to scripts/subagent_tally_hook.sh so it can read the payload — SubagentStop also fires for Claude Code's internal agents (context compaction arrives with agent_type \"\"), which the date-only inline form counted as dispatches (④-e false positive). If the script is missing (an older clone), the command falls back to the old date-only append — over-count, never under-count. RE-MERGE this block into your .claude/settings.json: an existing inline hook keeps the old behaviour.",
3
3
  "hooks": {
4
4
  "SubagentStop": [
5
5
  {
@@ -7,7 +7,7 @@
7
7
  "hooks": [
8
8
  {
9
9
  "type": "command",
10
- "command": "bash -c 'HUB=\"${CLAUDE_PROJECT_DIR:-$(git rev-parse --show-toplevel 2>/dev/null || echo \"$HOME/projects/forge-harness\")}\"; T=\"$HUB/tracks/_meta/.subagent_dispatch_tally\"; mkdir -p \"$(dirname \"$T\")\" 2>/dev/null; printf \"%s\\n\" \"$(date +%Y-%m-%d)\" >> \"$T\" 2>/dev/null; exit 0'",
10
+ "command": "bash -c 'HUB=\"${CLAUDE_PROJECT_DIR:-$(git rev-parse --show-toplevel 2>/dev/null || echo \"$HOME/projects/forge-harness\")}\"; S=\"$HUB/scripts/subagent_tally_hook.sh\"; if [ -f \"$S\" ]; then CLAUDE_PROJECT_DIR=\"$HUB\" bash \"$S\"; else T=\"$HUB/tracks/_meta/.subagent_dispatch_tally\"; mkdir -p \"$(dirname \"$T\")\" 2>/dev/null; printf \"%s\\n\" \"$(date +%Y-%m-%d)\" >> \"$T\" 2>/dev/null; fi; exit 0'",
11
11
  "timeout": 5
12
12
  }
13
13
  ]