Repository navigation
feat(review): the review to commit to pull request rail, reachable as a command - #102
Merged
Merged
Conversation
…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]>
| 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, "\\$&"))); |
…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]>
…w-ship # Conflicts: # src/main.ts
…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.
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.
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.tsand 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 undersrc/core/and modifies none. Review it after those four.The surface
/reviewand/shipare 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 verifygoes throughverifyAndRecord— the single writer — handing it aToolExecutoras theVerifyRunner. No command string is assembled at this layer. An empty--test-cmdfalls through to that function's own "unknown, nothing configured" reading rather than inventing a default.Printed strings that became actions
code.ts:453ended a--reporun withprocess.stderr.write(prCreateHint(...))offerShip()— asks on a TTY, and the command it names in a pipe/CI run exists/stage-diffended with "copy the commit message above"/reviewand/shiprelease_canaries.test.tssaid canary 5 was not writable because no PR-creation path existedprCreateHintinsrc/core/repo.tsis 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-staysnulland renders+? -?. Totals name the paths they exclude rather than counting them. The verification line isclassifyVerification's own reason string, verbatim, in both the review screen and the ship confirmation. There is no branch in this layer that can turnstaleorunknowninto anything greener.Mutation-tested three ways, each restored:
verifiedunconditionallythe ship confirmation prints the verification status and reason verbatim,every non-verified status reaches the screen unchanged--jsonmapsunknown/staletoverifiedthe verification line is never green for a tree nobody verified(e2e, real repo)verifiedunconditionallythe review screen prints the verification status and reason verbatim2. 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
truncatedmarker 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 configuredpushurlmakes them differ, and there is a test for the fork case.3.
--yesis 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:--yesalone: nopushargv, noghprocess at all (not even the auth probe), andfor-each-refon the remote still shows onlyrefs/heads/main.--approve publish: the push happens,gh pr createhappens, the ref appears.--yesalone on a revert: the file keeps its edits on disk.Test evidence
Neighbours, all still green:
cli_registry4,slash_registry8,command_docs_parity1,slash13,slash_git_tools12,release_canaries4,ship_rail15,code_wiring2,review_state14,review_actions16,verification_record11,publish18,verify_run6,ship_record11,migration_guard3,production_hardening8.npm run typecheckclean.test/review_ship_e2e.test.tsruns the whole rail — edit, select, stage, commit, publish, PR — through the realrunReview/runShipentry points against a real git repo with a real bare remote, and asserts:git diff --cached --name-only)git show --name-only)git show :kept.tshas the first edit and not the second, while the worktree has bothHEAD, andrefs/heads/maindid not movegh pr createargv (--head feature/rail,--title ...)refs/heads/feature/rail:refs/heads/feature/rail, and no--force,--force-with-lease,--mirror,--delete,--tags,--follow-tags,push --all,pr merge,--admin,--autoor--squashanywhere in any argvHEADdoes not moveghreports the failure and says the branch is published, because it isThe fixture's bare repo lives under a directory literally named
github.com/octocat/hello-world.git, sogithubSpec()resolves it while every push is a real push to a real repository on disk.ghis faked at theRunnerseam, not onPATH, in the portable tests. Node refuses to spawn a.cmd/.batshim without a shell (the CVE-2024-27980 fix), so aPATHshim cannot run on Windows. The last test does write an executableghscript ontoPATHand drivedefaultShipDeps, 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— twocaseblocks (review,ship, lazy-imported); seven newparseArgsoption declarations:files,hunks,message(shortm),approve,title,body,base. Declared becauseparseArgsruns withstrict: false: an undeclared flag is swallowed intovaluesand stripped from the positionals, so the command sees neither and reports success having done nothing.test/review_flags.test.tsasserts the parsed argv for each one, and proves the trap is real by deleting a declaration.src/commands/cli_registry.ts— two entries inStart.COMMANDS.md—review,shipin the CLI index;review,shipin the slash index;reviewrenamed toproject-reviewin the slash index; three table rows.src/commands/slash_registry.ts—reviewandshipadded underUVT Tools; the Agent-Modesreviewentry renamed.src/commands/slash.ts— twocaseblocks, two imports, andcase "review":moved out of the prompt-mode fallthrough group tocase "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_COMMANDSseam lands first, these hunks adapt.Declared: a shipped slash command was renamed
/reviewbecomes/project-review. The Agent-Modes prompt macro ("full project review + summary") keeps working under the new name;/code-reviewand/self-revieware untouched.This was forced, not cosmetic.
applyPromptModeruns beforehandleSlashinchat.tsand 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/reviewfor 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 fromgit diff --numstat -z, staged and unstaged.ChangedFileinreview_state.tscarries no counts, andreadRepoState'sRunneris 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-diffrewrite: the state read itself goes through the synchronous sharedRunner. Naming that plainly rather than claiming the whole command is async.Two rules this respects
aether SHIPis not a command, exactly like every existing one. Asserted.casebodies.Not proven
PATH-shim form of fake-gh on Windows (skipped there; proven on POSIX/CI).ghis faked in every test by design.🤖 Generated with Claude Code