Skip to content

feat(#922): Phase A — citation grounding checker and measured verdict on the gate - #928

Merged
admarble merged 6 commits into
mainfrom
feature/922-feat-spec-measure-first-grounding-gate-for-exp
Aug 10, 2026
Merged

admarble merged 6 commits into
mainfrom
feature/922-feat-spec-measure-first-grounding-gate-for-exp

Conversation

@admarble

@admarble admarble commented Aug 9, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Phase A of #922: a deterministic citation-grounding checker, plus the measurement instrument that answers whether a grounding gate is worth wiring into /spec at all.

  • scripts/spec/ground-check.ts — read-only, offline existence checker. Extracts path- and symbol-like citations from plan text and resolves them via git ls-tree/git grep. Always exits 0; findings live in the JSON and consumers decide gating (the scripts/qa/precheck.ts idiom). Never writes, never reaches the network, so it is safe to wire into /spec later — 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):

Metric Value
Grounded at spec time 870
Planned-new (created afterwards) 69
Untracked-but-real (dist/, .sequant/state.json) 4
Raw asserted-phantom rate 2.8%
Adjudicated hallucination rate 0.31% (3 of 972)
Coverage rate 51.6% (497/963 claim lines)

Reading all 27 raw asserted-phantoms by hand, 3 are genuine confabulations and 24 are hypotheticals, rejected proposals, or renames:

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

AC Status Evidence
AC-1 script exists, JSON shape, git ls-files/grep only, no writes/network ✅ scripts/spec/ground-check.ts; CLI integration tests assert exit 0 on findings
AC-2 report over ≥10 plan comments, phantom and coverage rate, existence-score caveat ✅ 45 comments (39 closed); report posted on #922
AC-3 decision gate recorded ✅ Recommendation + data on #922
AC-4 real captured fixtures, path.posix, unit + CLI integration tests ✅ 48 tests; fixtures are verbatim excerpts from #915/#920/#921
AC-5–AC-8 (Phase B) 🔄 Deferred Blocked on AC-3; not started

Three defects the corpus caught that synthetic fixtures did not

Each is now a regression test (#551/#547 — validate against a real corpus):

  1. Elided-prefix paths. commands/ready.ts is really src/commands/ready.ts. Authors drop leading directories constantly; without suffix resolution these scored as phantoms.
  2. Proposed aliases. fix(run): phase-restricted runs without an implementing phase must skip PR creation — spec-only batches always report failed #920's "export an alias hasDeliverableCommits" is a proposal, not a claim about existing code — it scored as an asserted phantom until export|alias joined the creation verbs.
  3. Untracked-but-real paths and git idioms. 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:

Mutation Result
Remove suffix resolution in resolvePath ✅ exactly 1 failed — the elided-prefix regression test
Drop export|alias from CREATION_VERBS ✅ exactly 1 failed — the proposed-alias test
stripFences returns input unchanged ⚠️ 1 failed, not 2 — exposed a tautology; see below

The 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 — clean
  • npm run lint — clean
  • npm test — 259/259 files, 5353 passed, on Node 22.23.0
  • 48 new tests (42 unit + 6 CLI integration)
  • Explicit tsc --noEmit --strict on both new scripts — clean

Two pre-existing environment notes, neither caused by this branch and neither fixed here:

  • scripts/ sits outside tsconfig.json's include and npm run lint's scope, so neither typechecks nor lints it — same for the existing scripts/qa/precheck.ts. Hence the explicit tsc run above.
  • On Node 20 the suite reports 97 failures from the >=22.13.0 engine floor. Identical on origin/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 --ref integration test. It resolved origin/main to obtain a historical commit, which works locally but not under actions/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.ts but not src/new.ts at 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 linted

tsconfig.json covers only src/+bin/ (what build emits) and 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 — sat outside both gates, and npx eslint scripts/... failed outright.

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 — "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.existsSync alone means a fresh worktree without dist/ or .sequant/state.json scores paths as phantoms that a built checkout resolves — non-reproducibility in a measurement instrument. Now also consults git 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

first run after instrument fixes after gap pass
Asserted phantoms 34 27 17
Rate 3.5% 2.8% 1.7%
Instrument noise 24 24 14
False-flag ratio 8:1 8:1 ~4.7:1

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)

Mutation Result
Remove the git check-ignore branch ✅ exactly 1 failed — the gitignored-path test
Remove the repo-external branch ✅ exactly 1 failed — the external-path test
Revert the vitest name placement ✅ reproduces "No projects matched the filter"

Gates

build ✅ · lint (now incl. scripts/) ✅ · tsc --noEmit ✅ · typecheck:scripts ✅ · npm test 259/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 resolvedSha provenance 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.

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
`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
admarble merged commit e9a1a8a into main Aug 10, 2026
5 checks passed
@admarble
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant