Skip to content

feat(review): the review to commit to pull request rail, reachable as a command - #102

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

AetherAI3 merged 15 commits into
mainfrom
lane/aa-ship-02-review-ship

Conversation

@AetherAI3

Copy link
Copy Markdown
Owner

What this is

The command and UX layer over the review core: aether review / aether ship, /review / /ship.

Commit #86 landed a secure PR-creation core in src/core/ship.ts and deliberately did not wire it to anything — its own message said the CLI surface was the next slice. This is that slice.

Stacked on lane/aa-ship-02-s4-verify @ 31255cd (PR #97). Its stack: #93 (review_state.ts, verification_record.ts) → #94 (review_actions.ts) → #95 (publish.ts, ship_record.ts) → #97 (verify_run.ts). This PR adds no file under src/core/ and modifies none. Review it after those four.

The surface

aether review                                 show what changed (interactive on a TTY)
aether review stage    --files a,b | --all    stage the selection
aether review stage    --files a --hunks 1,3  stage only those hunks of one file
aether review unstage  --files a,b | --all
aether review revert   --files a,b            DISCARD work (needs --approve destructive)
aether review commit   --files a,b -m "msg"   commit exactly the selection
aether review diff     --files a              full diff, every hunk numbered
aether review verify   --test-cmd "npm test"  run it and record what it proved
aether ship            [--title t] [--base b] publish the head branch, open the PR

/review and /ship are the same rail inside the REPL. The interactive layer is a line-oriented loop, not a raw-mode key grabber: raw mode has to own the terminal (which fights the REPL it is called from) and it makes behaviour reachable only by synthesising keypresses. Every branch of the loop calls the same exported function the non-interactive subcommand calls.

aether review verify goes through verifyAndRecord — the single writer — handing it a ToolExecutor as the VerifyRunner. No command string is assembled at this layer. An empty --test-cmd falls through to that function's own "unknown, nothing configured" reading rather than inventing a default.

Printed strings that became actions

was now
code.ts:453 ended a --repo run with process.stderr.write(prCreateHint(...)) offerShip() — asks on a TTY, and the command it names in a pipe/CI run exists
/stage-diff ended with "copy the commit message above" ends with /review and /ship
release_canaries.test.ts said canary 5 was not writable because no PR-creation path existed canary 5 is written, split by layer, and the coverage map says so

prCreateHint in src/core/repo.ts is now unreferenced. I left it there rather than delete a core export from outside my lease — flagging it for whoever owns that file.

The three invariants, and how each is proven

1. Unknown is never zero and never verified.

Counts come from git diff --numstat -z; a binary file's - stays null and renders +? -?. Totals name the paths they exclude rather than counting them. The verification line is classifyVerification's own reason string, verbatim, in both the review screen and the ship confirmation. There is no branch in this layer that can turn stale or unknown into anything greener.

Mutation-tested three ways, each restored:

mutation tests that failed
ship confirmation prints verified unconditionally the ship confirmation prints the verification status and reason verbatim, every non-verified status reaches the screen unchanged
--json maps unknown/stale to verified the verification line is never green for a tree nobody verified (e2e, real repo)
review screen prints verified unconditionally the review screen prints the verification status and reason verbatim

2. A command is fully viewable before approval.

The ship confirmation renders each command as its argv vector, one element per line, nothing truncated. A test builds a 5000-character title and a 40-line body and asserts every line appears and that no ellipsis or truncated marker does. A single-line $ gh pr create --title "..." preview is wrong twice: it implies a shell parses it, and it has to elide.

The screen also shows the push URL (via renderPublishPlan), not the fetch URL — a configured pushurl makes them differ, and there is a test for the fork case.

3. --yes is not authority.

It approves reading, staging, committing. Discarding needs --approve destructive; publishing needs --approve publish. Proven by absence, against a real repo and a real bare remote:

  • --yes alone: no push argv, no gh process at all (not even the auth probe), and for-each-ref on the remote still shows only refs/heads/main.
  • the same run with --approve publish: the push happens, gh pr create happens, the ref appears.
  • --yes alone on a revert: the file keeps its edits on disk.

Test evidence

review_command.test.ts   27 pass  0 fail
review_flags.test.ts      9 pass  0 fail
review_ship_e2e.test.ts  11 pass  0 fail  1 skipped (PATH shim, win32 only)

Neighbours, all still green: cli_registry 4, slash_registry 8, command_docs_parity 1, slash 13, slash_git_tools 12, release_canaries 4, ship_rail 15, code_wiring 2, review_state 14, review_actions 16, verification_record 11, publish 18, verify_run 6, ship_record 11, migration_guard 3, production_hardening 8. npm run typecheck clean.

test/review_ship_e2e.test.ts runs the whole rail — edit, select, stage, commit, publish, PR — through the real runReview / runShip entry points against a real git repo with a real bare remote, and asserts:

  • the index holds exactly the selected path (git diff --cached --name-only)
  • the commit contains exactly the selection (git show --name-only)
  • hunk selection: git show :kept.ts has the first edit and not the second, while the worktree has both
  • the ref really arrived on the remote, its tip equals local HEAD, and refs/heads/main did not move
  • the exact gh pr create argv (--head feature/rail, --title ...)
  • one push, whose refspec is refs/heads/feature/rail:refs/heads/feature/rail, and no --force, --force-with-lease, --mirror, --delete, --tags, --follow-tags, push --all, pr merge, --admin, --auto or --squash anywhere in any argv
  • revert discards only the selected file; the unselected one keeps its edits and is not even mentioned as at risk
  • commit refuses while the index holds unselected work, and HEAD does not move
  • detached HEAD and a zero-commit branch are refused before any push
  • a signed-out gh reports the failure and says the branch is published, because it is

The fixture's bare repo lives under a directory literally named github.com/octocat/hello-world.git, so githubSpec() resolves it while every push is a real push to a real repository on disk.

gh is faked at the Runner seam, not on PATH, in the portable tests. Node refuses to spawn a .cmd/.bat shim without a shell (the CVE-2024-27980 fix), so a PATH shim cannot run on Windows. The last test does write an executable gh script onto PATH and drive defaultShipDeps, asserting the argv the shim recorded — it is skipped on win32, so that form is unproven on Windows and proven on CI.

Declared: shared-file hunks

Four lanes are touching these. Every hunk here is additive except the rename.

  • src/main.ts — two case blocks (review, ship, lazy-imported); seven new parseArgs option declarations: files, hunks, message (short m), approve, title, body, base. Declared because parseArgs runs with strict: false: an undeclared flag is swallowed into values and stripped from the positionals, so the command sees neither and reports success having done nothing. test/review_flags.test.ts asserts the parsed argv for each one, and proves the trap is real by deleting a declaration.
  • src/commands/cli_registry.ts — two entries in Start.
  • COMMANDS.md — review, ship in the CLI index; review, ship in the slash index; review renamed to project-review in the slash index; three table rows.
  • src/commands/slash_registry.ts — review and ship added under UVT Tools; the Agent-Modes review entry renamed.
  • src/commands/slash.ts — two case blocks, two imports, and case "review": moved out of the prompt-mode fallthrough group to case "project-review":.
  • src/commands/prompt_modes.ts — the macro renamed.

Written against the tree as it is (main.ts switch + cli_registry entry + COMMANDS.md token). If PR #98's DISPATCH_COMMANDS seam lands first, these hunks adapt.

Declared: a shipped slash command was renamed

/review becomes /project-review. The Agent-Modes prompt macro ("full project review + summary") keeps working under the new name; /code-review and /self-review are untouched.

This was forced, not cosmetic. applyPromptMode runs before handleSlash in chat.ts and matches no-arg modes by prefix, so while that entry said /review, every /review ... line was rewritten into a prompt and the slash dispatcher never saw it. The two commands could not share the name. Registering /review for the rail without the rename would have shipped a dead command.

Declared: open question with the peer lane

src/commands/review_counts.ts (~170 lines) reads per-file line counts asynchronously from git diff --numstat -z, staged and unstaged. ChangedFile in review_state.ts carries no counts, and readRepoState's Runner is synchronous by contract — forcing an async path into it would be worse than this. The peer has taken an equivalent into core as PR #101 (src/core/diff_counts.ts); deleting this file in favour of it is a scheduled follow-up, not a blocker here.

It is also the only genuinely async part of the /stage-diff rewrite: the state read itself goes through the synchronous shared Runner. Naming that plainly rather than claiming the whole command is async.

Two rules this respects

  • Casing stays case-sensitive. Nothing here lowercases the dispatched token; aether SHIP is not a command, exactly like every existing one. Asserted.
  • No argv rebuild. Flags reach the commands as a typed options object; nothing re-renders a command line for a second parse. Asserted against the case bodies.

Not proven

  • The PATH-shim form of fake-gh on Windows (skipped there; proven on POSIX/CI).
  • Nothing here has run against a live GitHub remote — gh is faked in every test by design.

🤖 Generated with Claude Code

AetherAI3 and others added 6 commits August 22, 2026 10:37
…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.
… command

Commit #86 landed a secure PR-creation core in src/core/ship.ts and
deliberately did not wire it to anything. Its own message said the CLI
surface was the next slice. This is that slice: the command and UX layer
over the review core, so a finished piece of work can be looked at,
selected, committed, published and turned into a pull request without
leaving the terminal.

    aether review / /review     what changed, pick files or hunks,
                                stage, unstage, revert, commit, verify
    aether ship   / /ship       publish the head branch, open the PR

What was a printed string before and is an action now:

  * src/commands/code.ts ended a --repo run with prCreateHint() — a gh
    incantation the user retyped. It offers the rail instead, and the
    command it names in a pipe/CI run exists.
  * /stage-diff ended with "copy the commit message above". It ends with
    /review and /ship.

Three properties the shape of this layer comes from:

  1. Unknown is never rendered as zero or as verified. Line counts come
     from `git diff --numstat -z`; a binary file's "-" stays null and
     renders "+? -?", and the totals NAME the files they exclude. The
     verification line is classifyVerification's own reason, verbatim,
     in both the review screen and the ship confirmation — there is no
     branch in this layer that can turn stale or unknown into green.
  2. A command is fully viewable before approval. The ship confirmation
     renders each command as its argv VECTOR, one element per line, with
     nothing truncated — a 5000-character title and a 40-line body are
     shown whole. A one-line `$ gh pr create --title "…"` preview is
     wrong twice: it implies a shell parses it, and it has to elide.
  3. `--yes` is not authority. It approves reading, staging and
     committing. Discarding work needs `--approve destructive`;
     publishing needs `--approve publish`. Both boundaries are proven by
     the ABSENCE of the mutation and of the spawn, not by a warning.

Everything about what may be pushed, where, and whether it fast-forwards
stays in core/publish.ts; every mutation is a call into
core/review_actions.ts. This layer re-derives none of it.

`/review` was already taken by an Agent-Modes prompt macro. It is
renamed `/project-review`, here and in COMMANDS.md — stated rather than
silently replaced. It could not coexist: applyPromptMode runs before
handleSlash and matches no-arg modes by prefix, so every `/review …`
line was rewritten into a prompt and the dispatcher never saw it.

Every flag the layer reads is declared in main.ts's parseArgs options.
parseArgs runs with strict:false, which swallows an undeclared flag into
values and strips it from the positionals — so an undeclared --files
reaches the command as neither, and the command reports success having
done nothing. test/review_flags.test.ts asserts the parsed argv for each
one, and proves the trap is real by removing a declaration.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
test/prompt_modes.test.ts still looked `/review` up in the modes table and
called .startsWith on undefined, so the rename to `/project-review` left the
suite red. Stopping the throw was not enough: the property that broke is which
handler a typed token reaches, and "`/review` is absent from MODES" can stay
true while the bug returns — re-add a mode named `/rev`, or loosen the prefix
rule, and `/review` is a paid prompt rewrite again.

So the guard drives the real composition (applyPromptMode, then handleSlash,
in chat.ts's order) against a real temp repository and identifies the handler
that answered by output only it can produce: `/review help` must print the
rail's "usage: aether review", `/code-review` must reach the code-review macro,
`/project-review` must reach the prose macro. The two membership assertions are
kept as cheap failure localisers, not as the guard. Verified by mutation: with
the prose macro renamed back onto the `/review` prefix, the routing test fails.

COMMANDS.md carried the rename too — the Agent-modes row still described
`/review` as the prose macro — and the rail's `/review` and `/ship` had no
human row at all, only the markered index the parity test reads.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Comment thread test/review_ship_e2e.test.ts Outdated
assert.ok(create, "gh pr create was never invoked");
assert.equal(create![create!.indexOf("--head") + 1], "feature/rail");
assert.equal(create![create!.indexOf("--title") + 1], "fix: keep the kept one");
assert.match(shipped.text(), new RegExp(PR_URL.replace(/[/.]/g, "\\$&")));
AetherAI3 and others added 7 commits August 22, 2026 16:08
…lt from it

CodeQL flagged `js/incomplete-sanitization` (high) here: the assertion built a
RegExp out of PR_URL with `.replace(/[/.]/g, "\$&")`, which escapes slashes and
dots and leaves backslashes alone. It was the only new alert on this branch and
it turned the advanced-security check red on everything carrying this stack.

Escaping a URL into a pattern is the wrong tool for "this exact text was
printed". The failure mode is the dangerous direction: a metacharacter the
escape set misses silently WIDENS what the assertion accepts, so the test keeps
passing while checking less than it claims to. PR_URL is a constant and the test
wants it back verbatim, so there is no pattern to match — `includes()` says
exactly that, and cannot be widened by a character nobody remembered.

Mutation-checked rather than assumed: dropping `${opened.url}` from ship.ts's
"PR opened:" line fails this assertion with "the pull request URL was never
reported". Restored byte-identical afterwards.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Base automatically changed from lane/aa-ship-02-s4-verify to main August 23, 2026 00:59
Comment thread test/review_ship_e2e.test.ts Fixed
…tring

CodeQL flagged includes(PR_URL) as js/incomplete-url-substring-sanitization.
It is a test assertion rather than sanitization, but the substring form is
also the weaker check: any host wrapping the URL would satisfy it. Split the
output on whitespace and require the URL verbatim as its own token.
@AetherAI3
AetherAI3 merged commit a6649eb into main Aug 23, 2026
5 checks passed
@AetherAI3
AetherAI3 deleted the lane/aa-ship-02-review-ship branch August 23, 2026 01:08
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.

3 participants