Skip to content

pi: add cwd support to revdiff_review - #241

Merged
umputun merged 3 commits into
umputun:masterfrom
terrorobe:terrorobe/pi-revdiff-review-capture
Jun 24, 2026
Merged

umputun merged 3 commits into
umputun:masterfrom
terrorobe:terrorobe/pi-revdiff-review-capture

Conversation

@terrorobe

Copy link
Copy Markdown
Contributor

Problem

revdiff_review currently resolves smart detection, file shorthand, and the final revdiff launch from the Pi session working directory. That breaks agent-driven reviews when Pi is running from one directory but the requested review target lives in another repository: smart detection checks the wrong repo, file shorthand is resolved against the wrong path, and revdiff launches in the wrong tree.

Solution

Add an optional structured cwd parameter to the Pi revdiff_review tool and thread the resolved directory through target detection, file target resolution, detect-ref.sh, fallback git detection, and the final revdiff process launch.

The parameter defaults to Pi's ctx.cwd, supports leading ~, and is validated as an existing directory before launch. The skill guidance now tells the agent to translate natural directory requests (for example, “review main in ~/source/repo”) into the tool's cwd parameter rather than passing directory wording through as revdiff args.

This keeps the behavior at the Pi tool boundary; it does not add a new revdiff CLI flag.

@terrorobe
terrorobe requested a review from umputun as a code owner June 24, 2026 14:45
Copilot AI review requested due to automatic review settings June 24, 2026 14:45

Copilot AI 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.

Pull request overview

Adds an optional cwd parameter to Pi’s revdiff_review tool so git/ref detection, file shorthand resolution, and the final revdiff launch all occur relative to the intended working directory (instead of always using the Pi session/process directory). This aligns the Pi tool behavior with agent-driven reviews that target repos outside the current session directory.

Changes:

  • Add cwd parameter to revdiff_review, validate it as an existing directory, and thread it through smart detection, file resolution, and the final spawnSync execution.
  • Add home directory expansion (~) support and update file-target existence checks to be cwd-relative.
  • Extend the Pi extension executable regression harness to cover cwd behavior.
Show a summary per file
File Description
plugins/pi/skills/revdiff/SKILL.md Updates skill guidance to map “in ~/path/to/repo” phrasing to the tool’s structured cwd parameter.
plugins/pi/extensions/revdiff.ts Implements cwd plumbing through detection and execution, plus ~ expansion and directory validation.
app/plugin_exit_code_test.go Updates the Pi extension regression harness and adds a new test covering the cwd parameter behavior.

Copilot's findings

Tip

Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

  • Files reviewed: 3/3 changed files
  • Comments generated: 2

Comment thread plugins/pi/extensions/revdiff.ts Resolved
Comment thread app/plugin_exit_code_test.go Resolved

@umputun umputun left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

two things before merge, one minor:

  1. testToolCwdParameter fails on macOS. It asserts the launched pwd equals the os.tmpdir()-derived targetRepo, but macOS resolves /var/folders/... to /private/var/folders/... so the exact-string compare fails (Linux CI passes, tmpdir isn't symlinked there). Canonicalize both sides, e.g. realpathSync the temp dir up front, or compare realpathSync(cwdOut) vs realpathSync(targetRepo).

  2. cwd doesn't make it into ReviewResult (buildResult in revdiff.ts). On a "Continue review" rerun the agent replays args only, so the rerun loses the cwd and runs against the session dir instead of the reviewed repo. That's the same bug this PR fixes for the first pass. Thread the resolved cwd into ReviewResult (+ details), add a line to the SKILL.md rerun guidance so reruns keep it, plus a test that cwd survives a rerun.

minor: nothing covers the reject path (missing / non-dir cwd -> "Could not resolve revdiff working directory") or a relative cwd resolved against ctx.cwd. Both cheap to add.

@terrorobe

Copy link
Copy Markdown
Contributor Author

Thanks for the quick feedback, sorry about the test failure, seemed to work fine on my local Sonoma.

All comments should be addressed, let me know if that looks good.

@umputun umputun left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

all addressed, verified locally (the bun regression passes on macOS now):

  • macOS test: realpathSync on both sides, fixed.
  • cwd across reruns: ReviewResult.cwd + buildResult(..., cwd) + the SKILL.md step-7 note, and the new rerun test replays details.argsText/details.cwd and checks the launch dir, exactly what was needed.
  • the reject-path and relative-cwd tests cover the minor gaps too.

no new issues. LGTM, thx.

@umputun
umputun merged commit a53197d into umputun:master Jun 24, 2026
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