Skip to content

feat(review): line counts beside the state, not inside it - #101

Merged
AetherAI3 merged 11 commits into
mainfrom
lane/aa-ship-02-s5-counts
Aug 23, 2026
Merged

AetherAI3 merged 11 commits into
mainfrom
lane/aa-ship-02-s5-counts

Conversation

@AetherAI3

Copy link
Copy Markdown
Owner

Fifth of the AA-SHIP-02 core stack. Stacked on #97. One new core file plus
tests; nothing existing is modified.

Closes a real hole in the core API that the command lane hit: readRepoState
answers what changed but not how much, so the headline of a review screen —
+312 −48 — could not be rendered from core at all.

Why it is a sibling and not a field on RepoState

readRepoState is synchronous by contract and every caller depends on that.
Counting lines wants to be async, and forcing an async path through a
synchronous module is worse than the separation it would avoid. So this brings
its own AsyncRunner with the same argv discipline — no shell,
core.literalPathspecs, --no-optional-locks so a read stays a read — and
nothing about the existing contract changes.

The two parsing facts

  • A rename spans three NUL fields. --numstat -z writes adds\tdels\t and
    then the old path and the new path as separate fields. Reading fields
    uniformly turns every rename into two phantom entries with no counts.
  • - is not zero. git writes - for a binary file. +0 −0 beside a changed
    PNG reads as nothing changed rather than not counted.

That distinction runs through the types: an absent count is null and renders as
? or binary, never 0; a failed read leaves nulls rather than zeros; and
totalCounts returns the paths it could not count instead of skipping them,
so a total over a selection containing binaries or untracked files can say what
it is a total of.

Evidence

  • npm run typecheck clean.
  • 9/9 in test/diff_counts.test.ts, including a real-git case with both sides of
    the same file counted separately, a rename reported only under its new path,
    and an untracked file named as uncounted.
  • Mutation check: making binary parse as 0 instead of null fails two tests.
  • CI: dispatched on this ref (stacked PRs get no checks — ci.yml triggers only
    on pull requests targeting main).

Follow-up for the command lane

src/commands/review_counts.ts in the command-layer branch is the same
computation. Once this lands it should be deleted and the screen should call
readDiffCounts / renderCounts / totalCounts, so there is one source of truth
for diff counts. That is a small follow-up and deliberately not done here — the
command layer is a peer lane's file and this PR does not touch it.

…ows what it verified

The review/ship rail needs one honest answer to "what is the state of this
repository right now?" before it can offer to stage, commit or publish
anything. This is that answer, plus the piece that keeps "verified" from
becoming a label with no tree behind it.

review_state.ts reads the whole state in one pass through an injected Runner:
repository root, remote identity, head branch and revision, base branch and the
revision it resolved to, commits ahead of and behind that base, and every
changed path with both halves of its status code. Three things it refuses to
round off:

- The push URL is read with `git remote get-url --push`, separately from the
  fetch URL. A configured `remote.<name>.pushurl` makes them differ, and a rail
  that confirmed the fetch URL would then publish somewhere the user was never
  shown. The pull-request target follows the push URL for the same reason.
- Unknown stays unknown. An unresolvable base leaves ahead/behind null rather
  than zero; a base read from a local tracking ref is never reported as
  fetched; a failed fetch carries git's own reason.
- A rename entry in porcelain v2 spans two NUL fields. Reading each field as an
  entry turns the origin path of every rename into a phantom changed file, so
  the parser consumes it deliberately.

verification_record.ts stores a verify-gate result together with the identity
of what it verified: the head commit and a digest of the working tree, where
untracked content is hashed rather than listed (a green run that depended on an
untracked fixture must not survive an edit to that fixture). classify()
compares identity BEFORE it consults the exit code, so neither a stale green
record nor a stale red one can be rendered as current. There is no path that
upgrades unknown or stale to verified.

Tests cover the parser vectors, the pushurl-divergence case, unknown-not-zero,
disk round-trip, corruption and a future schema version, plus two real-git
canaries. Mutation check: disabling the head-identity comparison fails three
tests, including the stale-red one.
…was chosen

The second layer of the review/ship rail: the mutating half. It turns a
selection over the repository state from the previous commit into index and
worktree changes, and it is written so that four properties are structural
rather than remembered.

You may only act on a path the state reported. Every entry point takes the
state and a selection of names, resolves the names against the paths git
listed, and refuses the ones that do not match — so a crafted name never
reaches git at all rather than being escaped on the way. Combined with `--`
and core.literalPathspecs, there is no route from a name to a git option.

Nothing is destroyed that a preview did not name. planRevert returns the exact
patch text it would discard; applyRevert re-reads the diff and refuses if it no
longer matches, so an edit landing between the preview and the confirmation
cancels the revert instead of discarding whatever is there now. A file with
staged content is described as restoring to "its staged state", because that is
what `git restore` actually does.

A commit contains the selection and nothing else. planCommit refuses an index
that already holds paths the user did not select (selecting them is how you
include them); commitSelected stages, verifies the index equals the selection,
verifies the worktree still matches the index, and resets rather than
committing if either check fails.

Hunk selection is real: a patch is rebuilt from the selected hunks with git's
own preamble and applied with `git apply --cached`, so half a file can be
staged and the rest left in the worktree. Binary files are refused rather than
half-handled.

Evidence: 16/16 in test/review_actions.test.ts, eleven of them driving a real
repository. Mutation checks — disabling the unrelated-staged refusal fails the
"someone else's staged file" test; disabling the preview comparison fails the
revert-race test.
…ries it

The third layer of the review/ship rail, and the one where work leaves the
machine. Everything before it is local and undoable; a push is neither, so
publish.ts is written as a list of refusals.

Only HEAD is pushed, to a branch of the same name, through a refspec that is
fully qualified on both sides — the short form resolves the source through
git's ref lookup, where a tag or a remote ref sharing the name is what actually
travels. A head named main, master, HEAD, trunk or develop is refused outright,
and so is a head that is also the resolved base: work committed to the base was
committed in the wrong place, and publishing it is not the fix. There is no
--force, --force-with-lease, --delete, --tags or --mirror anywhere in the file,
and a test asserts the argv never grows one. A rejected non-fast-forward push
returns git's own message plus a hint that says, in as many words, that this
rail does not force.

The destination is re-read immediately before the push and compared to what the
plan rendered. A remote that changed between the confirmation and the push is a
different destination, and the consent was for the old one.

planShip derives the pull request from the same state, using the remote's PUSH
url — so the pull request opens against the repository the commits actually went
to, which is the one thing a fetch-url slug cannot guarantee. It refuses a
non-GitHub remote plainly instead of inventing a slug.

ship_record.ts joins the five identities that were each recorded separately and
never together: session, worktree, branch, commit, pull request. Two rules carry
it. A record whose commit no longer matches is rebound rather than updated, so an
old pull request never describes newer work. And a worktree may only be cleaned
up when everything in it exists somewhere else — clean tree, published commit,
pull request that carries it. Branch names are hashed into the record path, never
used as one.

Evidence: 29/29 across test/publish.test.ts and test/ship_record.test.ts,
including a real-git canary that pushes into a real bare repository and then
asserts the base ref on the server did not move and no tags were pushed.
Mutation checks: dropping the protected-head list fails three tests; dropping
the destination re-read fails the changed-remote test; carrying a stale record
forward fails the new-commit test.
…ondition it writes under

verification_record.ts could only be read. A field with no writer is the defect
class this repository keeps finding, and a read-only verification store is that
defect with a safety label on it: the rail would have shown "unknown" forever
and nobody would have noticed it could never show anything else.

verifyAndRecord is the only writer. It identifies the working tree, runs the
command through the caller's VerifyRunner — the same interface and the same
ToolExecutor the host verify gate uses, so no command string is assembled or
interpreted here — and identifies the tree again afterwards.

If the tree moved while the command ran, nothing is written. A suite takes time,
and an agent write or an editor save during it leaves a result that is true of
no tree that exists; recording it would mint exactly the misleading claim that
classifyVerification exists to catch on read. The reading returned in that case
is "unknown" with a reason that says the run cannot be attributed, and the raw
output and exit code are still handed back for the caller to display.

Otherwise the record is written and classified through classifyVerification —
the same function a later read uses, so the status shown now and the status
shown in ten minutes come from one implementation.

Evidence: 6/6 in test/verify_run.test.ts, five driving a real repository (green,
red with a parsed failing count, a tracked file changing mid-run, an untracked
file appearing mid-run, and replace-then-go-stale). Mutation check: removing the
before/after comparison fails both attribution tests.
readRepoState answers what changed but not how much, so the headline of a review
screen — "+312 −48" — could not be rendered from the core at all. It was about
to be re-derived at the command layer, which is how two implementations of the
same number start disagreeing about renames.

It does not go INSIDE readRepoState. That module is synchronous by contract and
every caller depends on it; counting lines wants to be async, and forcing an
async path through a synchronous module is worse than the separation it avoids.
So this is a sibling with its own async runner and the same argv discipline —
no shell, pathspec magic off, --no-optional-locks so a read stays a read.

Two parsing facts carry the file. A rename in `--numstat -z` is "adds\tdels\t"
followed by two further NUL fields, the old path and the new one; reading fields
uniformly turns every rename into two phantom entries with no counts. And git
writes "-" for a binary file, which is not zero: "+0 −0" beside a changed PNG
reads as "nothing changed" rather than "not counted".

That distinction runs through the types. A count that does not exist is null and
renders as "?" or "binary", never 0. A failed read leaves nulls rather than
zeros. totalCounts RETURNS the paths it could not count instead of skipping
them, so a total over a selection containing binaries or untracked files can say
what it is a total of.

Evidence: 9/9 in test/diff_counts.test.ts, including a real-git case covering
both sides of the same file, a rename reported only under its new path, and an
untracked file named as uncounted. Mutation check: making binary read as 0
instead of null fails two tests.
@AetherAI3

Copy link
Copy Markdown
Owner Author

CI evidence for this stacked branch (ci.yml triggers only on pull requests targeting main, so a stacked PR reports no checks of its own):

https://github.com/AetherAI3/aether-agent/actions/runs/32580393268 — success on lane/aa-ship-02-s5-counts @ 8cb7a34, via workflow_dispatch: Test (ubuntu-latest) pass, Test (windows-latest) pass, supply-chain pass.

Base automatically changed from lane/aa-ship-02-s4-verify to main August 23, 2026 00:59
@AetherAI3
AetherAI3 merged commit dbdb0cc into main Aug 23, 2026
5 checks passed
@AetherAI3
AetherAI3 deleted the lane/aa-ship-02-s5-counts branch August 23, 2026 01:03
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