Skip to content

Commit d1034d6

Browse files
t3dotggclaude
andauthored
fix(web): diff panel opens on all branch changes, not just uncommitted (#15005)
Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
1 parent 8283b48 commit d1034d6

18 files changed

Lines changed: 611 additions & 176 deletions

‎apps/mobile/src/features/review/ReviewSheet.tsx‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,8 @@ function ReviewHeader(
126126
id: "sections",
127127
inline: true,
128128
items: [
129-
sectionAction(props.sectionMenu.workingTree, "Working tree"),
130-
sectionAction(props.sectionMenu.branchChanges, "Branch changes"),
129+
sectionAction(props.sectionMenu.branchChanges, "Changes"),
130+
sectionAction(props.sectionMenu.workingTree, "Uncommitted"),
131131
sectionAction(props.sectionMenu.latestTurn, "Latest turn"),
132132
],
133133
},

‎apps/mobile/src/features/review/reviewModel.test.ts‎

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ describe("buildReviewSectionItems", () => {
6262
{
6363
id: "working-tree",
6464
kind: "working-tree",
65-
title: "Dirty worktree",
65+
title: "Uncommitted",
6666
baseRef: "HEAD",
6767
headRef: null,
6868
diff: "diff --git a/a.ts b/a.ts",
@@ -72,7 +72,7 @@ describe("buildReviewSectionItems", () => {
7272
{
7373
id: "branch-range",
7474
kind: "branch-range",
75-
title: "Against main",
75+
title: "Changes vs main",
7676
baseRef: "main",
7777
headRef: "feature",
7878
diff: "diff --git a/a.ts b/a.ts",
@@ -105,10 +105,28 @@ describe("buildReviewSectionItems", () => {
105105
isLoading: false,
106106
diff: expect.stringContaining("loaded.ts"),
107107
});
108-
expect(getDefaultReviewSectionId(items)).toBe("turn:2");
108+
expect(getDefaultReviewSectionId(items)).toBe("git:branch-range");
109109
});
110110

111-
it("shows dirty worktree while git preview is loading", () => {
111+
it("falls back to the first turn without git sections", () => {
112+
const items = buildReviewSectionItems({
113+
checkpoints: [
114+
makeCheckpoint({
115+
runId: RunId.make("run-1"),
116+
checkpointTurnCount: 1,
117+
completedAt: "2026-04-01T00:00:00.000Z",
118+
}),
119+
],
120+
gitSections: [],
121+
turnDiffById: {},
122+
loadingTurnIds: {},
123+
loadingGitSections: false,
124+
});
125+
126+
expect(getDefaultReviewSectionId(items)).toBe("turn:1");
127+
});
128+
129+
it("holds the Changes place while git preview is loading", () => {
112130
const items = buildReviewSectionItems({
113131
checkpoints: [],
114132
gitSections: [],
@@ -119,15 +137,14 @@ describe("buildReviewSectionItems", () => {
119137

120138
expect(items).toEqual([
121139
expect.objectContaining({
122-
id: "git:working-tree",
123-
kind: "working-tree",
124-
title: "Dirty worktree",
125-
subtitle: "Tracked, staged, and untracked worktree changes",
140+
id: "git:branch-range",
141+
kind: "branch-range",
142+
title: "Changes",
126143
diff: null,
127144
isLoading: true,
128145
}),
129146
]);
130-
expect(getDefaultReviewSectionId(items)).toBe("git:working-tree");
147+
expect(getDefaultReviewSectionId(items)).toBe("git:branch-range");
131148
});
132149
});
133150

‎apps/mobile/src/features/review/reviewModel.ts‎

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ import * as Order from "effect/Order";
99

1010
export type ReviewSectionKind = "turn" | "working-tree" | "branch-range";
1111

12-
const DIRTY_WORKTREE_SECTION_ID = "git:working-tree";
13-
const DIRTY_WORKTREE_TITLE = "Dirty worktree";
14-
const DIRTY_WORKTREE_SUBTITLE = "Tracked, staged, and untracked worktree changes";
12+
const CHANGES_SECTION_ID = "git:branch-range";
13+
const CHANGES_TITLE = "Changes";
14+
const UNCOMMITTED_SUBTITLE = "Staged, unstaged, and untracked files";
1515

1616
export interface ReviewSectionItem {
1717
readonly id: string;
@@ -124,7 +124,7 @@ const readyCheckpointOrder = Order.make<ThreadCheckpointSummary>(
124124

125125
function gitSubtitle(section: ReviewDiffPreviewSource): string | null {
126126
if (section.kind === "working-tree") {
127-
return DIRTY_WORKTREE_SUBTITLE;
127+
return UNCOMMITTED_SUBTITLE;
128128
}
129129
if (section.baseRef) {
130130
return `${section.baseRef} ... ${section.headRef ?? "HEAD"}`;
@@ -443,15 +443,16 @@ export function buildReviewSectionItems(input: {
443443
truncated: section.truncated,
444444
isLoading: false,
445445
}));
446-
const hasDirtyWorktreeItem = gitItems.some((item) => item.id === DIRTY_WORKTREE_SECTION_ID);
446+
// Changes is the default section, so it holds the place while git sources load.
447+
const hasChangesItem = gitItems.some((item) => item.id === CHANGES_SECTION_ID);
447448
const visibleGitItems =
448-
input.loadingGitSections && !hasDirtyWorktreeItem
449+
input.loadingGitSections && !hasChangesItem
449450
? [
450451
{
451-
id: DIRTY_WORKTREE_SECTION_ID,
452-
kind: "working-tree",
453-
title: DIRTY_WORKTREE_TITLE,
454-
subtitle: DIRTY_WORKTREE_SUBTITLE,
452+
id: CHANGES_SECTION_ID,
453+
kind: "branch-range",
454+
title: CHANGES_TITLE,
455+
subtitle: null,
455456
diff: null,
456457
isLoading: true,
457458
} satisfies ReviewSectionItem,
@@ -462,10 +463,11 @@ export function buildReviewSectionItems(input: {
462463
return [...turnItems, ...visibleGitItems];
463464
}
464465

466+
/** Prefers Changes, then the first section (a turn when the project is not a git repo). */
465467
export function getDefaultReviewSectionId(
466468
sections: ReadonlyArray<ReviewSectionItem>,
467469
): string | null {
468-
return sections[0]?.id ?? null;
470+
return (sections.find((section) => section.id === CHANGES_SECTION_ID) ?? sections[0])?.id ?? null;
469471
}
470472

471473
export function buildReviewParsedDiff(

‎apps/mobile/src/features/threads/git/GitOverviewSheet.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ export function GitOverviewSheet(props: GitOverviewSheetProps) {
282282
<SheetListRow
283283
icon="text.bubble"
284284
title="Review changes"
285-
subtitle="Inspect turn diffs, worktree changes, and base branch diff"
285+
subtitle="Inspect changes, uncommitted edits, and turn diffs"
286286
disabled={busy || !isRepo}
287287
onPress={() => {
288288
const params = { environmentId, threadId };

‎apps/server/src/git/GitManager.ts‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1000,7 +1000,7 @@ export const make = Effect.gen(function* () {
10001000
const canonicalizeExistingPath = (value: string) =>
10011001
fileSystem.realPath(value).pipe(Effect.orElseSucceed(() => value));
10021002
const normalizeStatusCacheKey = canonicalizeExistingPath;
1003-
const nonRepositoryStatusDetails = {
1003+
const nonRepositoryStatusDetails: GitVcsDriver.GitStatusDetails = {
10041004
isRepo: false,
10051005
hasOriginRemote: false,
10061006
isDefaultBranch: false,
@@ -1012,10 +1012,10 @@ export const make = Effect.gen(function* () {
10121012
aheadCount: 0,
10131013
behindCount: 0,
10141014
aheadOfDefaultCount: 0,
1015-
} satisfies GitVcsDriver.GitStatusDetails;
1015+
};
10161016
const readLocalStatus = Effect.fn("readLocalStatus")(function* (cwd: string) {
10171017
const details = yield* gitCore
1018-
.statusDetailsLocal(cwd, { includeDivergence: false })
1018+
.statusDetailsLocal(cwd, { includeDivergence: false, includeBranchChanges: true })
10191019
.pipe(
10201020
Effect.catchIf(isNotGitRepositoryError, () => Effect.succeed(nonRepositoryStatusDetails)),
10211021
);
@@ -1031,6 +1031,7 @@ export const make = Effect.gen(function* () {
10311031
refName: details.branch,
10321032
hasWorkingTreeChanges: details.hasWorkingTreeChanges,
10331033
workingTree: details.workingTree,
1034+
...(details.branchChanges ? { branchChanges: details.branchChanges } : {}),
10341035
} satisfies VcsStatusLocalResult;
10351036
});
10361037
const localStatusResultCache = yield* Cache.makeWith(readLocalStatus, {

‎apps/server/src/vcs/GitVcsDriver.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ export interface GitStatusDetails {
7676
upstreamRef: string | null;
7777
hasWorkingTreeChanges: boolean;
7878
workingTree: VcsStatusResult["workingTree"];
79+
branchChanges?: VcsStatusResult["branchChanges"];
7980
hasUpstream: boolean;
8081
aheadCount: number;
8182
behindCount: number;
@@ -85,6 +86,8 @@ export interface GitStatusDetails {
8586
export interface GitLocalStatusOptions {
8687
/** Skip revision walks and return zero divergence counts for local-only consumers. */
8788
readonly includeDivergence?: boolean;
89+
/** Also read the diff panel's Changes totals. Failures leave them out. */
90+
readonly includeBranchChanges?: boolean;
8891
}
8992

9093
export interface GitRemoteStatusDetails {

0 commit comments

Comments
 (0)