feat: add stagereview prep command and simplify agent skill#37
Conversation
Move all non-LLM work (diff fetching, parsing, filtering, formatting)
into the CLI so the agent skill becomes trivially simple. `prep` writes
a temp JSON file with formatted hunks and commit messages; `show` now
auto-detects simplified agent output ({ chapters, prologue }) and
independently computes scope, "Other changes" chapter, and generatedAt.
Address agent testing feedback: - Switch prep output to plain text with line numbers instead of JSON - Add hunk coverage validation in show (errors on missing/extra hunks) - Add lineRef sanitization in show (silently drops out-of-bounds refs) - Warn in SKILL.md not to modify files between prep and show - Use bash heredoc for agent output writing - Fix working-tree diff to use baseSha instead of HEAD
There was a problem hiding this comment.
Code Review
This pull request introduces a new prep command to the CLI, which automates the parsing of git diffs and prepares input for chapter generation. It includes logic to filter out lockfiles and binary assets, format diff hunks with line numbers, and handle git operations more robustly. The review comments suggest improvements to git command execution, specifically recommending the enforcement of standard a/ and b/ prefixes in diff output, increasing maxBuffer sizes for execFileSync to prevent overflows on large repositories, and ensuring cross-platform compatibility when splitting output strings.
- Force --src-prefix=a/ --dst-prefix=b/ in getRawDiff and getUntrackedDiff to handle user diff.noprefix config - Add maxBuffer to getUntrackedDiff for large untracked files - Fix hunk span computation: remove Math.max so oldLines=0 hunks correctly produce empty deletion-side ranges - Detect duplicate hunkRefs across chapters in validation
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 36d488c. Configure here.
Allow users to specify a custom base ref (e.g. --base feature-a) instead of always auto-detecting main/master. Useful when working on a branch that targets another feature branch. The SKILL.md instructs the agent to pass --base when the user specifies a base branch.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: f57a7f90ad
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| const out = execFileSync("git", ["ls-files", "--others", "--exclude-standard"], { | ||
| encoding: "utf8", | ||
| stdio: ["ignore", "pipe", "ignore"], | ||
| }).trim(); | ||
| return out ? out.split("\n") : []; |
There was a problem hiding this comment.
Collect untracked files from repository root
resolveScope() now includes untracked files, but getUntrackedFiles() runs git ls-files --others --exclude-standard without -C <repoRoot> or --full-name, so when stagereview prep/show is executed from a subdirectory, Git reports CWD-scoped relative paths (its help notes --full-name is needed to make paths project-top-relative). That causes untracked files outside the current subdirectory to be omitted, and files inside it to be emitted as wrong repo paths (e.g. in.txt instead of subdir/in.txt), which then breaks hunk/file-path matching in the generated review data.
Useful? React with 👍 / 👎.

Summary
Move all non-LLM work (diff fetching, parsing, filtering, formatting) into the CLI so the agent skill becomes trivially simple.
stagereview prepwrites a plain-text file with line-numbered hunks and commit messages;stagereview shownow auto-detects simplified agent output ({ chapters, prologue }) and independently computes scope, "Other changes" chapter, andgeneratedAt.Changes
packages/types/src/parsed-diff.ts—FILE_STATUS,LINE_TYPE,DiffLine,Hunk,PullRequestFilewith Zod schemasdiff-parser.ts,filter-files.ts,format-diff.ts,build-other-changes.ts— ported from hosted Stagestagereview prep— resolves scope, parses + filters diff, formats hunks with line numbers, writes plain-text outputshow: auto-detects agent output vs full ChaptersFile; validates hunk coverage (errors on missing/extra hunks); sanitizes lineRefs (silently drops out-of-bounds, duplicate, or invalid refs)detectBaseRef,resolveMergeBase,resolveHead,getRawDiff,getUntrackedFiles,getUntrackedDiff,getCommitMessages,hasUncommittedChanges,resolveScopeprep+showflow insteadbaseShainstead ofHEADfor correct merge-base comparisonTesting
pnpm typecheck— all packages passpnpm lint— biome cleanpnpm test— 248 tests pass (21 test files)pnpm build— CLI builds successfullystagereview prep+ agent skill flow end-to-end, incorporated agent feedback on prep output format, line numbers, validation, and file-writing ergonomics