Repository navigation
feat(#922): Phase A — citation grounding checker and measured verdict on the gate - #928
Merged
admarble merged 6 commits intoAug 10, 2026
Conversation
Phase A of #922. Two scripts, deliberately split: - `scripts/spec/ground-check.ts` — read-only, offline existence checker. Extracts path- and symbol-like citations from plan text and resolves them against the tree via `git ls-tree`/`git grep`. Always exits 0; findings live in the JSON, consumers decide gating (the `scripts/qa/precheck.ts` idiom). Safe to wire into `/spec` later because it never writes and never reaches the network — AC-1. - `scripts/spec/measure-corpus.ts` — the measurement instrument. Reaches the network (`gh`) so the checker does not have to. Reports the phantom rate AND the coverage rate, because a phantom rate alone reads as a clean bill of health when the real story is "almost nothing was checkable". Design notes worth keeping: Nonexistent is not phantom. Plans legitimately name code they propose to create. The discriminator is deterministic rather than verb-sniffing: check each citation at the commit contemporaneous with the comment AND at HEAD. Missing-then/exists-now is planned-new; missing at both is a phantom candidate. That is only valid once the work merged, so the headline corpus is restricted to closed issues and open ones are reported separately as un-discriminable. Two false positives found by running against the real corpus, neither of which synthetic fixtures produced (#551/#547): - `commands/ready.ts` is really `src/commands/ready.ts`. Authors elide leading directories constantly, so path resolution needed suffix matching. - `hasDeliverableCommits` came from "export an alias `hasDeliverableCommits`" in the #920 plan — a proposal, not a claim about existing code. Scored as an asserted phantom until `export|alias` joined the creation verbs. Both are now regression tests with verbatim fixture text. Windows/POSIX: all path manipulation goes through `path.posix`, since every path handled originates from git (always `/`-separated) or from citation text. `path.join` would emit `\` on Windows and silently break every comparison against the tracked-file set — AC-4. Tests: 39 unit + 6 CLI integration. The CLI file carries the `.integration.` infix so it lands in the integration project (serialized, 30s floor) rather than the unit project's 5s default (#842). Refs #922
…nale Mutation-testing `stripFences` (return the text unchanged) failed only one test, not two — which exposed the fenced-block extraction test as a tautology. Its fixture used an *unbackticked* path inside a fence, and extraction requires backticks, so the assertion held whether or not fences were stripped. Rewritten with a backticked path; the mutation now fails both tests. Chasing that down produced a measurement worth recording: a backticked path inside a fence occurs **0 times** across the 1.18 MB corpus of 159 real plan comments. Fence-stripping therefore has no effect on citation extraction — the rationale the doc comment previously gave. It is genuinely load-bearing for `measure-corpus.ts`'s claim-line counting, where fenced lines starting `-` or `|` would otherwise inflate the coverage denominator. The comment now states both, and flags the test fixture as constructed rather than captured since the corpus supplies no instance. Also drops a duplicate `docs` entry from SYMBOL_STOPLIST (a Set, so inert — but it read as two different exclusions). Refs #922
The first full corpus run put the asserted-phantom rate at 3.5% (34 of 976 citations). Reading all 34 showed most were the measurement's fault, not the plans': - **Untracked-but-real paths.** `dist/`, `dist/bin/cli.js`, `.sequant/state.json`, `scripts/dev/` — all real, all gitignored, none in `git ls-tree`. 6 of 34. Now resolved via a filesystem fallback. - **Git and shell idioms.** `origin/`, `fix/`, `./`, `../` matched the directory regex. 4 of 34. Now a stoplist. Both classes are now regression-tested. The filesystem fallback needed care: applied naively it also answers "does this exist now" to the "did it exist then" question, which collapses the planned-new discriminator and *understates* the phantom rate — the opposite error, and a quieter one. Two CLI tests caught it immediately (`--ref` resolving a file that only exists on this branch). It is now passed only for working-tree checks, and `measure-corpus.ts` enables it solely on the "now" leg, with untracked-but-real given its own verdict rather than being folded into planned-new — it was never created by the plan. Corrected rate: 2.8% asserted-phantom, coverage 51.6%, over 39 merged plans and 972 citations. Refs #922
4 of 7 tasks
`build (22.x)` failed on 1 of 5356 tests — mine. The test resolved `origin/main` to get a historical commit, which works locally and not under `actions/checkout`, where no such ref exists. The assertion was sound; the setup depended on ambient repository state. It now builds a two-commit repo in a temp dir: commit one has `src/old.ts`, commit two adds `src/new.ts`. Checking the same input at the first commit must resolve `old.ts` and not `new.ts`, and against the working tree must resolve both — so the difference is attributable to the ref rather than to extraction, which the previous single-assertion version could not show. This is the discriminator `measure-corpus.ts` depends on to separate planned-new from phantom, so it is worth pinning precisely. Refs #922
Three repo-level gaps and one instrument gap, all previously reported as "pre-existing, not fixed here". **`scripts/` was neither typechecked nor linted.** `tsconfig.json` includes only `src/` and `bin/` (what `npm run build` emits), and `npm run lint` ran `eslint src/ bin/`. So every CLI that `/qa` and `/spec` shell out to — `precheck.ts`, `tautology-detector-cli.ts`, the new #922 scripts — was outside both gates, and `npx eslint scripts/...` failed outright with "not found in any of the provided project(s)". - New `tsconfig.scripts.json`: typecheck-only project over `scripts/`, `noEmit` so nothing reaches `dist/`. `allowImportingTsExtensions` is safe precisely because it never emits, and the scripts import each other with explicit `.ts` specifiers that `tsx` resolves at runtime. - `eslint.config.js` points `scripts/**/*.ts` at that project. - `lint` now covers `scripts/`; new `typecheck:scripts`; CI's typecheck job runs it. Turning the gates on surfaced 11 real problems, all fixed: two `no-useless-escape` errors in `ready-backtest.ts`, an unused `catch` binding in `qa-cache-cli.ts`, and eight stale `eslint-disable no-console` directives (`no-console` is not enabled in this config) across `precheck.ts` and the #922 scripts. **`vitest run --project <name>` never worked.** Vitest 4 reads a project's `name` only from inside its `test` block; declared as a sibling it is ignored, and the symptom is "No projects matched the filter" — which reads like a typo in the command, not a config defect. Both projects still ran, so what was lost was the ability to target one: the #842 split between the 5s unit project and the serialized 30s integration project could not be verified from the CLI. Now it can, and it confirms the #922 split — 42 unit, 6 integration. **The untracked-path check was checkout-dependent.** `fs.existsSync` alone means a fresh worktree with no `dist/` and no `.sequant/state.json` scores paths as phantoms that a built checkout resolves — non-reproducibility in a measurement instrument. Now also consults `git check-ignore`, which is checkout- and history-independent, plus an explicit repo-external case (`../worktrees/`) compared on the resolved path rather than by looking for ".." in the string. Effect on the Phase A number: asserted phantoms 34 -> 27 -> **17** (1.7%), instrument noise 24 -> 14. The adjudicated hallucination count is unchanged at 3, so the AC-3 recommendation stands — on a cleaner denominator, with the false-flag ratio down from 8:1 to ~4.7:1. Refs #922
Grounding has a shelf life: a check runs against a tree that keeps moving, and the old output could not say which tree. `ref` echoed the raw CLI string — a moving name like a branch, or null in working-tree mode — so a consumer reading the JSON later had no way to tell whether the confirmation was stale. `GroundCheckResult` now carries `resolvedSha`: the full SHA of `ref` resolved via `git rev-parse --verify`, or of HEAD in working-tree mode (where `ref: null` continues to signal that uncommitted changes may sit on top). An unresolvable ref pins null rather than silently reporting HEAD as if it were the requested ref, mirroring `buildRepoIndex`'s empty-index degrade. This is the Phase-A-safe slice of @zeweihan's shelf-life review point on the issue: no gate is wired (AC-3 recommends against), but the surviving on-demand checker now emits drift-detectable provenance for free, so any future consumer gets "when and against what" without a schema change. Mutation-verified: deleting `resolvedSha` from the result object fails exactly the four new assertions (working-tree pin, historical-ref pin, HEAD-vs-base distinction, unresolvable-ref null); restored. Refs #922
admarble
deleted the
feature/922-feat-spec-measure-first-grounding-gate-for-exp
branch
August 10, 2026 00:33
admarble
added a commit
that referenced
this pull request
Aug 10, 2026
…heck scope (#930) #928 widened `npm run lint` to `scripts/` and added `tsconfig.scripts.json`. Both then reached `scripts/dev/` — gitignored developer scratch with zero tracked files (.gitignore:65). That directory does not exist in CI, so CI went green while `npm run lint` failed for every developer who had it: scripts/dev/tui-demo.tsx 0:0 error Parsing error: "parserOptions.project" has been provided The file was not found in any of the provided project(s) The eslint override added in #928 matches `scripts/**/*.ts`, so the `.tsx` file had no project to resolve against. Rather than extend the override to `.tsx`, the directory is excluded outright from both tools: linting untracked scratch is meaningless, and any rule applied there can only ever fail locally and never in CI. Adding `exclude` to `tsconfig.scripts.json` exposed a second trap: `exclude` REPLACES the inherited list rather than extending it. The first attempt dropped the base's `**/*.test.ts` entry and pulled test files into the project, surfacing three pre-existing errors in `lint-skill-calls.test.ts`. The base entries are now repeated verbatim with a comment saying why. Verified: lint, typecheck, typecheck:scripts, build and the scripts/spec suite (50 tests) all pass. CI behavior is unchanged — `scripts/dev/` is absent there, so both settings are no-ops in CI by construction. Entire-Checkpoint: e57435dd8109
This was referenced Aug 13, 2026
This was referenced Aug 28, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Phase A of #922: a deterministic citation-grounding checker, plus the measurement instrument that answers whether a grounding gate is worth wiring into
/specat all.scripts/spec/ground-check.ts— read-only, offline existence checker. Extracts path- and symbol-like citations from plan text and resolves them viagit ls-tree/git grep. Always exits 0; findings live in the JSON and consumers decide gating (thescripts/qa/precheck.tsidiom). Never writes, never reaches the network, so it is safe to wire into/speclater — AC-1.scripts/spec/measure-corpus.ts— the Phase A instrument. Reaches the network (gh) so the checker does not have to.Note this PR does not wire anything into
/spec. Phase B is gated on the AC-3 decision, and the data argues against it — see the measurement report.Headline result
Over 39 merged plan comments / 972 citations, each checked twice (at the commit contemporaneous with the comment, and at HEAD):
dist/,.sequant/state.json)Reading all 27 raw asserted-phantoms by hand, 3 are genuine confabulations and 24 are hypotheticals, rejected proposals, or renames:
executeIssue— invented in two independent plans (fix(run): exec that leaves work uncommitted reports success and the run passes with no PR — #534's empty-branch escape, reopened via a new route #879, feat(run): --ready-gate — run the post-QA ready gate insidesequant run(automates the any-gaps/fix-gaps second look, stops at human merge) #817), both giving concrete edit instructions for it. The real function isexecuteBatch.finalizePhaseLog(fix(cli): post-run SUMMARY duration sums per-issue times instead of wall clock — 4-issue parallel run reported 1h 12m for 36m 18s #867) — cited as an existing pattern with a fabricated line number: "MirrorsfinalizeRunLog/finalizePhaseLog(run-log-schema.ts:389/415)".finalizeRunLogis real (line 477, so the line ref is wrong too);finalizePhaseLoghas never existed. A real sibling lending credibility to an invented one is the textbook shape.All three are symbols. Zero path citations were genuine phantoms.
Why this argues against shipping the gate
At 3 true positives against 24 false flags, a shipped gate runs an 8:1 noise ratio — enough to train readers to ignore it, which is how #608's 0%-action-rate gates died. Recommendation recorded on the issue is to close as acceptable-as-is per AC-3.
AC verification
git ls-files/grep only, no writes/networkscripts/spec/ground-check.ts; CLI integration tests assert exit 0 on findingspath.posix, unit + CLI integration testsThree defects the corpus caught that synthetic fixtures did not
Each is now a regression test (#551/#547 — validate against a real corpus):
commands/ready.tsis reallysrc/commands/ready.ts. Authors drop leading directories constantly; without suffix resolution these scored as phantoms.hasDeliverableCommits" is a proposal, not a claim about existing code — it scored as an asserted phantom untilexport|aliasjoined the creation verbs.dist/,.sequant/state.json,origin/,./— 10 of the original 34 "phantoms" were the instrument reporting its own errors as plan defects.The filesystem fallback for (3) needed care: applied naively it also answers "does this exist now" to the "did it exist then" question, collapsing the planned-new discriminator and understating the phantom rate — the quieter, worse error. Two CLI tests caught it. It is now enabled only for working-tree checks.
Mutation verification
Per CLAUDE.md, each gate test was mutation-verified — delete the thing it asserts, confirm exactly that test fails, restore:
resolvePathexport|aliasfromCREATION_VERBSstripFencesreturns input unchangedThe third mutation is the useful one. The fenced-block extraction test used an unbackticked path inside a fence, and extraction requires backticks, so the assertion held whether or not fences were stripped. Rewritten with a backticked path; the mutation now fails both tests (verified).
Chasing it down produced a measurement worth keeping: a backticked path inside a fence occurs 0 times across the 1.18 MB corpus, so fence-stripping has no effect on extraction — the rationale the doc comment previously claimed. It is genuinely load-bearing for claim-line counting. The comment now states both, and flags that fixture as constructed rather than captured.
Test plan
npm run build— cleannpm run lint— cleannpm test— 259/259 files, 5353 passed, on Node 22.23.0tsc --noEmit --stricton both new scripts — cleanTwo pre-existing environment notes, neither caused by this branch and neither fixed here:
scripts/sits outsidetsconfig.json'sincludeandnpm run lint's scope, so neither typechecks nor lints it — same for the existingscripts/qa/precheck.ts. Hence the explicittscrun above.>=22.13.0engine floor. Identical onorigin/main.Scope notes
No CHANGELOG entry: AC-8 scopes that to Phase B, and Phase A ships developer-only measurement tooling with no user-facing surface.
Closes nothing on its own — #922 stays open pending the AC-3 decision.
Refs #922
🤖 Generated with Claude Code
Post-review fix: one CI failure, mine
The first CI run failed
build (22.x)on 1 of 5356 tests — the--refintegration test. It resolvedorigin/mainto obtain a historical commit, which works locally but not underactions/checkout, where no such ref exists. The assertion was sound; the setup depended on ambient repository state.Rewritten hermetically: it builds a two-commit repo in a temp dir, then asserts that the same input resolves
src/old.tsbut notsrc/new.tsat the first commit, and resolves both against the working tree. The two-sided assertion attributes the difference to the ref rather than to extraction, which the single-assertion version could not show.CI is now green on all five checks.
Gap-closing pass
Every limitation flagged as "pre-existing, not fixed here" in the first review is now fixed.
scripts/was neither typechecked nor lintedtsconfig.jsoncovers onlysrc/+bin/(whatbuildemits) andlintraneslint src/ bin/. So every CLI that/qaand/specshell out to —precheck.ts,tautology-detector-cli.ts, the new #922 scripts — sat outside both gates, andnpx eslint scripts/...failed outright.tsconfig.scripts.json(typecheck-only,noEmit);eslint.config.jspointsscripts/**/*.tsat it;lintcoversscripts/; newtypecheck:scripts, wired into CI's typecheck job.no-useless-escapeerrors inready-backtest.ts, an unusedcatchbinding inqa-cache-cli.ts, and 8 staleeslint-disable no-consoledirectives acrossprecheck.tsand the feat(spec): measure-first grounding gate for explorer findings — deterministically verify cited paths/symbols before they enter the plan #922 scripts.vitest run --project <name>never workedVitest 4 reads a project's
nameonly from inside itstestblock. Declared as a sibling it is ignored, and the symptom — "No projects matched the filter" — reads like a typo in the command rather than a config defect. Both projects still ran; what was lost was the ability to target one, so the #842 split could not be verified from the CLI. Now it can, and it confirms this PR's split: 42 unit, 6 integration.The untracked-path check was checkout-dependent
fs.existsSyncalone means a fresh worktree withoutdist/or.sequant/state.jsonscores paths as phantoms that a built checkout resolves — non-reproducibility in a measurement instrument. Now also consultsgit check-ignore(checkout- and history-independent), plus an explicit repo-external case compared on the resolved path rather than by looking for".."in the string.Effect on the measured number
Adjudicated hallucinations remain 3 throughout — the fixes removed noise, not signal. The AC-3 recommendation is unchanged, now on a cleaner denominator.
Mutation verification (this pass)
git check-ignorebranchnameplacementGates
build✅ ·lint(now incl.scripts/) ✅ ·tsc --noEmit✅ ·typecheck:scripts✅ ·npm test259/259 files, 5355 passed · CI green on all 5 checks.Not done, deliberately
Phase B (AC-5–AC-8). It is gated on AC-3, and the data recommends against it. The
resolvedShaprovenance from @zeweihan's shelf-life point landed separately as the Phase-A-safe slice; the per-finding provenance flag has no plan artifact to live in until a gate exists.