Skip to content

feat(review): select, stage, unstage, revert and commit exactly what was chosen - #94

Merged
AetherAI3 merged 5 commits into
mainfrom
lane/aa-ship-02-s2b
Aug 23, 2026
Merged

AetherAI3 merged 5 commits into
mainfrom
lane/aa-ship-02-s2b

Conversation

@AetherAI3

Copy link
Copy Markdown
Owner

Second of the AA-SHIP-02 stack. Stacked on #93 — review that one first;
this diff is only src/core/review_actions.ts plus its tests.

The mutating half of the review rail. Four properties are structural here, not
remembered:

  1. You may only act on a path the state reported. Every entry point takes
    the RepoState and a selection of names, resolves them against the paths git
    listed, and refuses the rest — a crafted name never reaches git at all. With
    -- and core.literalPathspecs on top, there is no route from a name to a
    git option. (a refused selection never reaches git at all asserts zero
    calls were made.)
  2. Nothing is destroyed that a preview did not name. planRevert returns
    the exact patch it would discard; applyRevert re-reads and refuses if the
    file moved since. A file with staged content is described as restoring to
    its staged state, because that is what git restore does.
  3. A commit contains the selection and nothing else. planCommit refuses an
    index already holding unselected paths; commitSelected stages, verifies the
    index equals the selection, verifies the worktree still matches the index,
    and resets rather than committing if either check fails.
  4. 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

  • npm run typecheck clean.
  • node --test dist/test/review_actions.test.js — 16/16 pass; eleven drive a
    real repository (staging isolation, hunk stage/unstage round trip, revert
    preview binding, revert race, staged-state revert, untracked refusal, commit
    isolation, unrelated-staged refusal, empty message).
  • Mutation checks: disabling the unrelated-staged refusal fails
    someone else's staged file is not swept into the commit; disabling the
    preview comparison fails
    a file that moved between preview and confirmation is not discarded.

Note for the reviewer

A second agent began writing an overlapping review/ship surface into the shared
~/aa-ship-02-wt worktree while this was in progress (src/commands/review.ts,
src/core/git_review.ts, src/core/review_hunks.ts). This stack was moved to
its own worktree to stop the two from overwriting each other. If that work also
becomes a pull request, the two need reconciling before either command layer
lands — the core layers (#93, this) are the part that should survive.

…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.
@AetherAI3

Copy link
Copy Markdown
Owner Author

CI evidence for this stacked branch. ci.yml only triggers on pull requests targeting main, so this PR reports no checks of its own; the branch was run through workflow_dispatch instead — same workflow, same ubuntu + windows matrix, same npm test:

https://github.com/AetherAI3/aether-agent/actions/runs/32579887601 — success on lane/aa-ship-02-s2b @ 74b3551

Base automatically changed from lane/aa-ship-02-s1-state to main August 23, 2026 00:50
@AetherAI3
AetherAI3 merged commit c38b3be into main Aug 23, 2026
5 checks passed
@AetherAI3
AetherAI3 deleted the lane/aa-ship-02-s2b branch August 23, 2026 00:54
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