Skip to content

feat: add stagereview prep command and simplify agent skill#37

Merged
dastratakos merged 4 commits into
mainfrom
dastratakos/simplify-agent-skill-offload-to-cli
May 7, 2026
Merged

feat: add stagereview prep command and simplify agent skill#37
dastratakos merged 4 commits into
mainfrom
dastratakos/simplify-agent-skill-offload-to-cli

Conversation

@dastratakos

@dastratakos dastratakos commented May 7, 2026

Copy link
Copy Markdown
Contributor

Summary

Move all non-LLM work (diff fetching, parsing, filtering, formatting) into the CLI so the agent skill becomes trivially simple. stagereview prep writes a plain-text file with line-numbered hunks and commit messages; stagereview show now auto-detects simplified agent output ({ chapters, prologue }) and independently computes scope, "Other changes" chapter, and generatedAt.

Changes

  • New types: packages/types/src/parsed-diff.tsFILE_STATUS, LINE_TYPE, DiffLine, Hunk, PullRequestFile with Zod schemas
  • New modules: diff-parser.ts, filter-files.ts, format-diff.ts, build-other-changes.ts — ported from hosted Stage
  • New command: stagereview prep — resolves scope, parses + filters diff, formats hunks with line numbers, writes plain-text output
  • Enhanced show: 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)
  • Git helpers: detectBaseRef, resolveMergeBase, resolveHead, getRawDiff, getUntrackedFiles, getUntrackedDiff, getCommitMessages, hasUncommittedChanges, resolveScope
  • SKILL.md: simplified from ~350 to ~280 lines — agent no longer handles scope/SHAs/otherChanges/generatedAt/full schema; uses prep + show flow instead
  • Bug fix: working-tree diff now uses baseSha instead of HEAD for correct merge-base comparison
  • Tests: 4 new test files ported from hosted Stage (diff-parser, filter-files, format-diff, build-other-changes)

Testing

  • pnpm typecheck — all packages pass
  • pnpm lint — biome clean
  • pnpm test — 248 tests pass (21 test files)
  • pnpm build — CLI builds successfully
  • Manual: tested stagereview prep + agent skill flow end-to-end, incorporated agent feedback on prep output format, line numbers, validation, and file-writing ergonomics

Open in Stage

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

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread packages/cli/src/git.ts Outdated
Comment thread packages/cli/src/git.ts
Comment thread packages/cli/src/git.ts
Comment thread packages/cli/src/git.ts Outdated
Comment thread packages/cli/src/git.ts
Comment thread packages/cli/src/show.ts
Comment thread packages/cli/src/show.ts
Comment thread packages/cli/src/format-diff.ts
- 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

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ 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.

Comment thread packages/cli/src/git.ts
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.
@dastratakos dastratakos marked this pull request as ready for review May 7, 2026 06:44
@dastratakos dastratakos merged commit 30b3cff into main May 7, 2026
5 checks passed
@dastratakos dastratakos deleted the dastratakos/simplify-agent-skill-offload-to-cli branch May 7, 2026 06:44

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment thread packages/cli/src/git.ts
Comment on lines +142 to +146
const out = execFileSync("git", ["ls-files", "--others", "--exclude-standard"], {
encoding: "utf8",
stdio: ["ignore", "pipe", "ignore"],
}).trim();
return out ? out.split("\n") : [];

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

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