Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 21 additions & 5 deletions apps/pi-extension/server/serverReview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import {
gitAddFile as gitAddFileCore,
gitResetFile as gitResetFileCore,
parseWorktreeDiffType,
resolveBaseBranch,
type ReviewGitRuntime,
runGitDiff as runGitDiffCore,
validateFilePath,
Expand Down Expand Up @@ -192,6 +193,10 @@ export async function startReviewServer(options: {
let currentGitRef = options.gitRef;
let currentDiffType: DiffType = options.diffType || "uncommitted";
let currentError = options.error;
// Tracks the base branch the user picked from the UI. Agent review prompts
// read this (not gitContext.defaultBranch) so they analyze the same diff
// the reviewer is currently looking at.
let currentBase = options.gitContext?.defaultBranch || "main";

// Agent jobs — background process manager (late-binds serverUrl via getter)
let serverUrl = "";
Expand All @@ -213,7 +218,7 @@ export async function startReviewServer(options: {
async buildCommand(provider, config) {
const cwd = resolveAgentCwd();
const hasAgentLocalAccess = !!options.agentCwd || !!options.gitContext;
const userMessageOptions = { defaultBranch: options.gitContext?.defaultBranch, hasLocalAccess: hasAgentLocalAccess };
const userMessageOptions = { defaultBranch: currentBase, hasLocalAccess: hasAgentLocalAccess };

if (provider === "tour") {
return tour.buildCommand({
Expand Down Expand Up @@ -503,12 +508,18 @@ export async function startReviewServer(options: {
json(res, { error: "Missing diffType" }, 400);
return;
}
const defaultBranch = options.gitContext?.defaultBranch || "main";
const detectedBase = options.gitContext?.defaultBranch || "main";
const base = resolveBaseBranch(
typeof body.base === "string" ? body.base : undefined,
options.gitContext?.availableBranches,
detectedBase,
);
const defaultCwd = options.gitContext?.cwd;
const result = await runGitDiff(newType, defaultBranch, defaultCwd);
const result = await runGitDiff(newType, base, defaultCwd);
currentPatch = result.patch;
currentGitRef = result.label;
currentDiffType = newType;
currentBase = base;
currentError = result.error;
json(res, {
rawPatch: currentPatch,
Expand Down Expand Up @@ -613,12 +624,17 @@ export async function startReviewServer(options: {

// Local mode first (matches Bun server priority)
if (hasLocalAccess && !isPRMode) {
const defaultBranch = options.gitContext?.defaultBranch || "main";
const detectedBase = options.gitContext?.defaultBranch || "main";
const base = resolveBaseBranch(
url.searchParams.get("base") ?? undefined,
options.gitContext?.availableBranches,
detectedBase,
);
const defaultCwd = options.gitContext?.cwd;
const result = await getFileContentsForDiffCore(
reviewRuntime,
currentDiffType,
defaultBranch,
base,
filePath,
oldPath,
defaultCwd,
Expand Down
22 changes: 19 additions & 3 deletions bun.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading