Repository navigation
pi: add cwd support to revdiff_review - #241
Conversation
There was a problem hiding this comment.
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
cwdparameter torevdiff_review, validate it as an existing directory, and thread it through smart detection, file resolution, and the finalspawnSyncexecution. - Add home directory expansion (
~) support and update file-target existence checks to becwd-relative. - Extend the Pi extension executable regression harness to cover
cwdbehavior.
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
umputun
left a comment
There was a problem hiding this comment.
two things before merge, one minor:
-
testToolCwdParameterfails on macOS. It asserts the launchedpwdequals theos.tmpdir()-derivedtargetRepo, 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.realpathSyncthe temp dir up front, or comparerealpathSync(cwdOut)vsrealpathSync(targetRepo). -
cwddoesn't make it intoReviewResult(buildResultin revdiff.ts). On a "Continue review" rerun the agent replaysargsonly, 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 intoReviewResult(+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.
|
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
left a comment
There was a problem hiding this comment.
all addressed, verified locally (the bun regression passes on macOS now):
- macOS test:
realpathSyncon both sides, fixed. - cwd across reruns:
ReviewResult.cwd+buildResult(..., cwd)+ the SKILL.md step-7 note, and the new rerun test replaysdetails.argsText/details.cwdand 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.
Problem
revdiff_reviewcurrently resolves smart detection, file shorthand, and the finalrevdifflaunch 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
cwdparameter to the Pirevdiff_reviewtool and thread the resolved directory through target detection, file target resolution,detect-ref.sh, fallback git detection, and the finalrevdiffprocess 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'scwdparameter rather than passing directory wording through as revdiff args.This keeps the behavior at the Pi tool boundary; it does not add a new
revdiffCLI flag.