Repository navigation
Description
Blocked by: #1093 Tier: mechanical Doc: guard plan 2026-09-18 (16-bug classification; research: differential testing, Csmith/EMI)
Why
pre-tool.sh is a ~1,600-line bash/awk parser and the repo's hottest regression chain: #763 (segment-aware guards) broke forms #981 fixed, and #981's strip_comments broke the -F - heredoc subject that #1064 fixed. Each fix was tested against the forms its author thought of. Nothing replays the forms previous fixes protected.
A golden corpus makes the parser's whole observed input space a fixture: every command form, with the verdict the hook gives it today. A change that flips any verdict fails the test until the snapshot is updated in the same PR, so the flip is visible in review instead of discovered in the field.
Change
__tests__/fixtures/hook-corpus.jsonl: one line per case{ "command": "...", "tool": "Bash", "exit": 0|2, "block": "<HOOK_BLOCKED reason or null>", "source": "#763|#981|#1064|logs|manual" }. Seed from every command string in__tests__/pre-tool-hook.integration.test.ts(114runHook(sites), plus commands harvested from two machine-local sources: the hook's own log~/.sequant/logs/claude-hook.log(<ts> BLOCKED [<rule>] <redacted command>lines — 603 on the planning host, already redacted, verdict known) and the Bashtool_useblocks in the Claude Code transcripts~/.claude/projects/<project-slug>/*.jsonl(5,519 distinct commands on the planning host; verdict obtained by replaying through the hook)..sequant/logs/run-*.jsonis not a source: Phase 0 found zero command strings in 93 files (lab notes §3). De-duplicated, secrets scrubbed,sourceset tohook-logortranscript. The harvest is a maintainer-host step; the committed corpus is what CI and--diffread.__tests__/hook-corpus.integration.test.ts: runs each case through all three hook copies and asserts exit and block reason match the snapshot.scripts/hook-corpus.ts --harvest [--transcripts <dir>] [--hook-log <file>]: appends new distinct commands from the two sources above with their current verdicts;--diff <ref>runs the corpus through the hook at<ref>and at HEAD and prints only the verdict changes.- The exec skill's checklist for any
pre-tool.shchange: run--diff origin/mainand list each changed verdict in the PR body underHook verdicts changed:.
Release-graph plan — guard-2026-09 (2026-09-20)
Graph: guard-2026-09 Tier: mechanical Wave: 3
May touch: __tests__/fixtures/hook-corpus.jsonl, __tests__/hook-corpus.integration.test.ts, scripts/hook-corpus.ts, scripts/hook-corpus.test.ts, exec SKILL.md ×3, CHANGELOG.md; read-only on the three pre-tool.sh copies
The npm run build && npm test AC is verified by the runner from a clean shell after the PR opens (PLAN I-1); the agent runs only the test files its ACs name. Mutation markers use failedTest starting with the test file path (I-4). Fixture first: commit the corpus and the snapshot test before the --diff tooling. The harvest runs on the maintainer host (the sources are local); the PR body states which sources were read and the redaction pass. Skill edits: I-3 applies (byte-identical mirrors, no relay word).
Acceptance criteria
- AC-1: the corpus holds at least 150 distinct commands including every form from fix(hooks):
^gh (issue|pr)prefix skip disarms all 5 pre-tool guards for compound commands, and re-breaks on anycdprefix #763, fix(hooks): commit-message validator extracts from the whole command, so an earlier quoted string or unrelated heredoc blocks a valid conventional commit #981 and bug(hooks): commit validator strips#from agit commit -F -heredoc subject, blocking everytype(#N):message sent via stdin #1064 — Verify:wc -l < __tests__/fixtures/hook-corpus.jsonl≥ 150 andgrep -c '"source": "#1064"' __tests__/fixtures/hook-corpus.jsonl≥ 5, andjq -c 'select(.source=="hook-log" and .exit!=0)' __tests__/fixtures/hook-corpus.jsonl | wc -l≥ 10 withjq -c 'select(.source=="hook-log" and .exit==0)' … | wc -l= 0 (every hook-log case is a whole command whose block the replay reproduces; blocks the harness cannot reproduce — background-task, orchestrator-env and state-dependent guards — are tracked separately, not pinned as allow). Edited 2026-09-20 by the runner, second edit: the host log holds 42 eligible commands, only 13 reproduce under the replay harness; the rest are the follow-up's coverage. - AC-2: gate test — the snapshot test passes on all three hook copies and fails when any verdict changes — Verify:
npx vitest run __tests__/hook-corpus.integration.test.ts→ green. Mutation-verified per CLAUDE.md §Testing: re-apply the bug(hooks): commit validator strips#from agit commit -F -heredoc subject, blocking everytype(#N):message sent via stdin #1064 mutation (heredoc_first_line(raw, start)→heredoc_first_line(s, start)) in one copy → the test fails naming the-F -cases; restore. - AC-3:
npx tsx scripts/hook-corpus.ts --diff origin/mainon an unchanged hook prints0 verdict changesand exits 0 — Verify: run it on main. - AC-4:
--harvestadds no secrets: a run log containing aghp_token orAuthorization:header yields a corpus line with the value replaced by<redacted>— Verify:npx vitest run scripts/hook-corpus.test.ts -t "redacts"→ green. - AC-5: the exec skill names the
--diffstep for hook changes in all three skill copies — Verify:grep -c "hook-corpus.ts --diff" .claude/skills/exec/SKILL.md skills/exec/SKILL.md templates/skills/exec/SKILL.md→ 1 each. - AC-6:
npm run build && npm testgreen.
Not in scope
Fuzzing the hook with generated commands; that is the parser property-test issue.
Activity
admarble commentedon Sep 20, 2026
Runner context — guard-2026-09 wave 3 launch, 2026-09-20. Base:
origin/mainat138d12ac(waves 1 and 2 merged: #1093 settle-against-base script + red-main rule + CI jobtest, #1069 merge-not-rebase, #1087, #1097, plus all of wave 1). These rules override the exec AND qa skills' defaults for this run:npm testin the worktree — this applies to the qa phase too. Under concurrent phase agents that one call exceeds the 30-minute no-progress wall and the phase is killed (three wave-1 phases died this way). Verify each AC by its own command; run only the test files the ACs name. The runner runs the full suite once per PR from a clean shell and records it on the PR.<!-- SEQUANT_MUTATION: {"ac":"AC-N","mutation":"<what you deleted>","failedTest":"<test file path> > <describe> > <case>"} -->in the PR body.failedTestMUST start with the test file path. RunparseMutationMarkerson your body before opening the PR. Commit before mutating.timeout.git commit -m "...", noCo-Authored-By. Push the branch and open the PR yourself (one wave-1 exec forgot). Never rebase or force-push after pushing. One AC per line in the PR body, idsAC-Nonly.Issue-specific: Fixture first: commit the corpus and the snapshot test before the
--difftooling. Harvest sources on this host:~/.sequant/logs/claude-hook.logrecords only BLOCKED commands (<epoch> BLOCKED [<rule>] <command>), so the bulk of the corpus comes from Claude Code transcripts under~/.claude/projects/-Users-tony-Projects-sequant/*.jsonl(Bash tool_use inputs,.message.content[].input.command). Redact before writing (AC-4). Only this issue edits the execSKILL.mdmirrors this wave;npm run lint:skill-syncmust report 0 diverged and no SKILL.md may contain the word relay. Any gate test inscripts/must call a production function (tautology detector). The threepre-tool.shcopies are read-only.admarble commentedon Sep 20, 2026
Complexity: Standard (6 ACs, 5 directories)
AC Quality Check
"source": "#1064"(space after the colon).JSON.stringifyemits"source":"#1064", so the writer needs a custom serializer (,and:separators) or the counts return 0. AC-1 also useshook-logwhile the schema line sayslogs. Usehook-logandtranscripteverywhere.hook-log≥ 50) is not reachable on this host.~/.sequant/logs/claude-hook.loghas 641 lines but only 39 distinct single-line Bash commands (env-dump 14, no-changes 8, commit-format 6, background-task 6, force-push 2, staged-secret 1, sensitive-file 1, git-reset-hard 1). The other 71 BLOCKED lines are JSON payloads for non-Bash tools (worktree-boundary, random tmp paths, and the replay needsSEQUANT_WORKTREE). Multi-line commands are split across log lines. Needs an owner decision (Q1).ghp_token orAuthorization:header.Scope Assessment
Non-Goals: ✅ "Not in scope: fuzzing with generated commands".
__tests__,scripts, 3 skill dirs,CHANGELOG)Verdict:⚠️ SCOPE_WARNING (directory count only; the mirrors are one logical edit).
Acceptance Criteria
AC-1: ≥150 distinct commands, all #763/#981/#1064 forms, ≥5
#1064, ≥50hook-logVerification: Integration Test (the
wc/grep -ccommands in the issue)Scenario: Given the committed corpus → When the AC-1 commands run → Then counts meet the thresholds
Assumptions: the
hook-logthreshold is corrected per Q1; serializer spacing matches the greps.AC-2: snapshot test green on all three hook copies, red on any verdict change
Verification: Integration Test + mutation check
Scenario: Given the corpus → When
hooks/,.claude/hooks/andtemplates/hooks/each replay every case → Then exit and block reason match. Givenheredoc_first_line(raw, start)→(s, start)(line 1316) in one copy → Then the-F -cases fail by name.Assumptions: cases are
it.eachper copy, titled<source> <command prefix>, so the failure names the cases. The gate-test marker usesfailedTest=__tests__/hook-corpus.integration.test.ts > <describe> > <case>and is recorded in the PR body.AC-3:
--diff origin/mainon an unchanged hook prints0 verdict changes, exit 0Verification: Integration Test (CLI run)
Scenario: Given no hook change → When
npx tsx scripts/hook-corpus.ts --diff origin/mainruns → Then0 verdict changes, exit 0Assumptions:
origin/mainresolves in the runner's clone. It vacuously passes on an unchanged hook, so add a derived check (see Derived ACs).AC-4: harvest redacts secrets
Verification: Unit Test (
npx vitest run scripts/hook-corpus.test.ts -t "redacts")Scenario: Given a candidate command with
ghp_…orAuthorization: Bearer …→ When it passes through the production redactor → Then the value becomes<redacted>Assumptions: the test calls the exported production function (tautology detector). The hook's own
redact_secretscovers too few shapes (ghp/xoxb/AIza…) for transcripts: 102 of 5,626 distinct transcript commands match a broader token/key pattern.AC-5: exec skill names the
--diffstep in all three copiesVerification: Manual Test (
grep -c "hook-corpus.ts --diff"→ 1 each)Scenario: Given the three exec
SKILL.mdfiles → When grepped → Then exactly 1 match each, andlint:skill-syncreports 0 diverged with norelayanywhere.AC-6:
npm run build && npm testgreenVerification: Integration Test, run by the runner from a clean shell after the PR opens. Per the runner comment, the agent runs only the named test files.
Implementation Plan
Fixture first: commit the corpus and the snapshot test before any
--difftooling.Phase 1: Corpus and snapshot test (AC-1, AC-2)
scripts/hook-corpus.ts:replayCase(hookDir, case, state)andserializeCase. The test imports it.HOMEandCLAUDE_PLUGIN_DATAto tmp, and deletesSEQUANT_*andCLAUDE_HOOKS_DISABLED, likecleanEnv().main.git initsetscommit.gpgsign=falseand identity viagit config, before any commit.runHookto dump{command, cwd-state, code}while the suite runs. Do not commit the instrumentation. Regex-parsing 114 call sites misses the commands built throughmakeStagedRepoand template variables. Tagsourceby describe block (fix(hooks):^gh (issue|pr)prefix skip disarms all 5 pre-tool guards for compound commands, and re-breaks on anycdprefix #763, fix(hooks): commit-message validator extracts from the whole command, so an earlier quoted string or unrelated heredoc blocks a valid conventional commit #981, bug(hooks): commit validator strips#from agit commit -F -heredoc subject, blocking everytype(#N):message sent via stdin #1064, elsemanual).~/.claude/projects/-Users-tony-Projects-sequant/*.jsonl. The slug-prefix siblings are bench runs and other projects./Users/tony, emails and tokens too, not only secrets.__tests__/hook-corpus.integration.test.tsasdescribe.each(HOOK_COPIES)+it.each(cases). The.integration.name puts it in the 30s project.Phase 2: Tooling (AC-3, AC-4)
scripts/hook-corpus.ts: CLI--harvest [--transcripts <dir>] [--hook-log <file>](append-only, sorted, deterministic) and--diff <ref>.--diffmust extract the wholehooks/dir at<ref>, notpre-tool.shalone. The hook sources the siblingparallel-marker.sh(line 139), and a single-file extract would silently change verdicts.hooks/copy at both<ref>and HEAD.scripts/hook-corpus.test.tsstays pure and in-process: redaction, dedupe, serializer spacing, diff formatting. It is in the 5sunitproject, andvitest.config.tsis not in "May touch", so nothing there may spawn bash or build repos.Phase 3: Skill and changelog (AC-5)
.claude/skills/exec,skills/execandtemplates/skills/exec. Whenpre-tool.shchanges, runnpx tsx scripts/hook-corpus.ts --diff origin/mainand list each changed verdict underHook verdicts changed:. Use the phrase exactly once per file. Then runlint:skill-syncandlint:skill-gates. Add a CHANGELOG entry.Design Review
scripts/hook-corpus.ts, exported. The test and the CLI share it, so the--diffverdicts and the CI verdicts cannot drift.HOOK_COPIESdescribe.eachparity inpre-tool-hook.integration.test.ts, andsettle-against-base(real git, integration project).Feature Quality Planning
--diffruns one copy (hooks/). The other two are covered by the parity test, so a copy that drifts is caught by AC-2, not AC-3.Derived ACs
--diffagainst a ref containing the #1064 mutation prints ≥1 verdict change naming the-F -cases and exits non-zero (or prints the count). Otherwise AC-3 passes vacuously./Users/, an email, or a token-shaped string (test over the committed file).Open Questions
hook-log≥ 50 vs 39 available (Q1) — Recommendation: lower it to ≥ 30, or count normalized non-Bash payloads. Impact if unchanged: AC-1 fails on a true corpus, or gets padded with invented commands, which the AC forbids. Per project practice, rewrite the AC line and run with force; a comment alone won't re-open exec.git commit|push|reset,gh,env,sudo, heredocs), ≤ ~400 total. Impact: CI time vs coverage.state(stageddefault,clean) so the existingcleanRepocases keep their verdicts. The issue's schema has no such field. Impact: without it, ~10 seeds replay against the wrong state.138d12ac, clean. The exec phase should reuse it.Recommended Workflow
Phases: spec → testgen → exec → qa
Quality Loop: enabled (SCOPE_WARNING)
Reasoning: AC-2 and AC-4 declare vitest evidence (unit/integration), so testgen stubs first; the plan is fixture-first anyway. Skip
test(no UI). No security-review phase, but AC-4/AC-8 need a hand check on the scrubbed corpus, because the repo is public. If the runner follows its wave rules, exec runs only the named test files.Label Review
Current: enhancement
Recommended: enhancement, planned
Reason: feature work, plan posted
Quality Loop: auto-enabled by SCOPE_WARNING
fix(#1094): hook-log harvest skips first-line fragments of multi-line…
admarble commentedon Sep 20, 2026
Runner edit to AC-1 (2026-09-20). The qa phase measured the
hook-log ≥ 50floor as unreachable: the host's hook log holds 42 distinct eligible blocked commands, and the log records only the first line of multi-line commands, so a naive re-harvest adds heredoc fragments that replay as allowed. Two changes: (1)extractHookLogCommandsnow skips fragments (heredoc openers, trailing operators, unbalanced quotes/parens), gate-tested, matching its own doc comment;GUARD_RELEVANTanchors per line. (2) AC-1's per-source floor is now ≥ 30 whole real blocks (spec Open Question 1); the corpus holds 39. No secrets in the added lines (scanned). Recorded as D-22 in the plan.fix(#1094): hook-log harvest keeps only reproduced blocks and drops r…
admarble commentedon Sep 20, 2026
Runner edit to AC-1, second pass (2026-09-20). The qa phase showed 26 of the 39 re-harvested hook-log cases were pinned as
allowalthough the log recorded a block: the replay harness cannot reproduce background-task, orchestrator-env or state-dependent guards. Pinning the wrong side would make the snapshot lie, so the harvester now keeps only reproduced blocks (86ee3e8b), drops rule-mismatched first lines, and redacts session links, foreign project paths and--reponames; the corpus holds 13 hook-log cases, all blocks. AC-1's per-source floor is now ≥ 10 reproduced blocks with zero allow-pinned hook-log cases. The unreproducible 29 are the coverage gap tracked in #1129.admarble commentedon Sep 20, 2026
QA Verdict: AC_MET_BUT_NOT_A_PLUS
AC coverage: 0/1 met
Gaps:
Suggestions:
--harvestwith no--transcripts/--hook-logstill rewrites the corpus file unconditionally (main()→writeCorpus). Harmless today, but a no-op invocation touching a committed fixture is a footgun; guard onadded.length > 0.GUARD_RELEVANT,MAX_COMMAND_LENGTH,CORPUS_PATH,caseKey,writeCorpus,diffVerdicts,extractHooksAt) are never imported outside the module. Not dead — all are called internally — just over-exported.chore(#1094): merge origin/main
test(#1094): golden-corpus verdict snapshot for pre-tool.sh, replayed…
docs(guides): when QA says AC_NOT_MET — read the gaps, then fix, retr…