Skip to content

Commit 71ee529

Browse files
fix(web): consume diff offers while a panel is active
1 parent 856958a commit 71ee529

5 files changed

Lines changed: 45 additions & 19 deletions

File tree

‎apps/web/src/components/ChatView.logic.test.ts‎

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1744,7 +1744,6 @@ describe("proactive completed diff guard", () => {
17441744
resolveProactiveTurnDiffAction({
17451745
checkpoint: changedCheckpoint,
17461746
isGitRepo: true,
1747-
activeSurfaceKind: null,
17481747
}),
17491748
).toBe(action);
17501749
},
@@ -1764,41 +1763,37 @@ describe("proactive completed diff guard", () => {
17641763
resolveProactiveTurnDiffAction({
17651764
checkpoint: undefined,
17661765
isGitRepo: true,
1767-
activeSurfaceKind: null,
17681766
}),
17691767
).toBe("defer");
17701768
expect(
17711769
resolveProactiveTurnDiffAction({
17721770
checkpoint: missingCheckpoint,
17731771
isGitRepo: true,
1774-
activeSurfaceKind: null,
17751772
}),
17761773
).toBe("defer");
17771774
expect(
17781775
resolveProactiveTurnDiffAction({
17791776
checkpoint: changedCheckpoint,
17801777
isGitRepo: undefined,
1781-
activeSurfaceKind: null,
17821778
}),
17831779
).toBe("defer");
17841780
});
17851781

1786-
it("keeps an active pull request above a completed turn diff", () => {
1782+
it("delegates a qualifying completed diff to the store while a pull request is active", () => {
17871783
const changedCheckpoint = {
17881784
status: "ready",
1789-
files: [{ path: "src/app.ts", kind: "modified", additions: 1, deletions: 0 }],
1785+
files: [{ path: "src/app.ts", kind: "modified", additions: 50, deletions: 0 }],
17901786
} satisfies Pick<TurnDiffSummary, "status" | "files">;
17911787

17921788
expect(
17931789
resolveProactiveTurnDiffAction({
17941790
checkpoint: changedCheckpoint,
17951791
isGitRepo: true,
1796-
activeSurfaceKind: "pull-request",
17971792
}),
1798-
).toBe("ignore");
1793+
).toBe("open");
17991794
});
18001795

1801-
it("leaves an already open diff and its chosen scope alone", () => {
1796+
it("delegates a qualifying completion to the store while a diff is already open", () => {
18021797
const largeCheckpoint = {
18031798
status: "ready",
18041799
files: Array.from({ length: 3 }, (_, index) => ({
@@ -1813,9 +1808,8 @@ describe("proactive completed diff guard", () => {
18131808
resolveProactiveTurnDiffAction({
18141809
checkpoint: largeCheckpoint,
18151810
isGitRepo: true,
1816-
activeSurfaceKind: "diff",
18171811
}),
1818-
).toBe("ignore");
1812+
).toBe("open");
18191813
});
18201814
});
18211815

‎apps/web/src/components/ChatView.logic.ts‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -181,12 +181,7 @@ export function shouldOpenProactiveTurnDiff(input: {
181181
export function resolveProactiveTurnDiffAction(input: {
182182
checkpoint: Pick<TurnDiffSummary, "status" | "files"> | undefined;
183183
isGitRepo: boolean | undefined;
184-
activeSurfaceKind: RightPanelSurface["kind"] | null;
185184
}): "defer" | "ignore" | "open" {
186-
// An open diff already shows the work; reopening it would reset the chosen scope.
187-
if (input.activeSurfaceKind === "pull-request" || input.activeSurfaceKind === "diff") {
188-
return "ignore";
189-
}
190185
if (input.checkpoint === undefined || input.checkpoint.status === "missing") return "defer";
191186
if (input.isGitRepo === undefined) return "defer";
192187
if (

‎apps/web/src/hooks/useProactivePanels.ts‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,6 @@ export function useProactivePanels(input: {
169169
? resolveProactiveTurnDiffAction({
170170
checkpoint: completedCheckpoint,
171171
isGitRepo,
172-
activeSurfaceKind: openSurface?.kind ?? null,
173172
})
174173
: "ignore";
175174
proactivePanelObservationRef.current = {

‎apps/web/src/rightPanelStore.test.ts‎

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,16 +349,44 @@ describe("rightPanelStore", () => {
349349
const nextTurn = { ...completedDiff, turnId: RunId.make("turn-2") };
350350
expect(store.openProactive(refA, nextTurn, store.getUserActionRevision(refA))).toBe(true);
351351
expect(selectActiveRightPanel(useRightPanelStore.getState().byThreadKey, refA)).toBe("diff");
352+
353+
const completedWhileOpen = { ...completedDiff, turnId: RunId.make("turn-3") };
354+
const existingDiff = selectActiveRightPanelSurface(
355+
useRightPanelStore.getState().byThreadKey,
356+
refA,
357+
);
358+
expect(store.openProactive(refA, completedWhileOpen, store.getUserActionRevision(refA))).toBe(
359+
false,
360+
);
361+
expect(selectActiveRightPanelSurface(useRightPanelStore.getState().byThreadKey, refA)).toEqual(
362+
existingDiff,
363+
);
352364
store.closeSurface(refA, "diff");
365+
await reloadRightPanelStore();
366+
expect(store.openProactive(refA, completedWhileOpen, store.getUserActionRevision(refA))).toBe(
367+
false,
368+
);
369+
expect(selectActiveRightPanel(useRightPanelStore.getState().byThreadKey, refA)).toBeNull();
353370

354371
// A later storage migration must preserve the dismissal, just like an ordinary reload.
355372
const { storage, name, version } = useRightPanelStore.persist.getOptions();
356373
const persisted = await storage!.getItem(name!);
357374
await storage!.setItem(name!, { ...persisted!, version: version! - 1 });
358375
await reloadRightPanelStore();
359-
expect(store.openProactive(refA, nextTurn, store.getUserActionRevision(refA))).toBe(false);
376+
expect(store.openProactive(refA, completedWhileOpen, store.getUserActionRevision(refA))).toBe(
377+
false,
378+
);
360379
expect(selectActiveRightPanel(useRightPanelStore.getState().byThreadKey, refA)).toBeNull();
361380

381+
expect(
382+
store.openProactive(
383+
refA,
384+
{ ...completedDiff, turnId: RunId.make("turn-4") },
385+
store.getUserActionRevision(refA),
386+
),
387+
).toBe(true);
388+
expect(selectActiveRightPanel(useRightPanelStore.getState().byThreadKey, refA)).toBe("diff");
389+
store.closeSurface(refA, "diff");
362390
store.open(refA, "diff");
363391
expect(selectActiveRightPanel(useRightPanelStore.getState().byThreadKey, refA)).toBe("diff");
364392
});
@@ -382,6 +410,14 @@ describe("rightPanelStore", () => {
382410
expect(selectActiveRightPanelSurface(useRightPanelStore.getState().byThreadKey, refA)).toEqual(
383411
linkedPullRequest,
384412
);
413+
expect(
414+
selectThreadRightPanelState(useRightPanelStore.getState().byThreadKey, refA).surfaces,
415+
).toEqual([linkedPullRequest]);
416+
await reloadRightPanelStore();
417+
expect(store.openProactive(refA, nextTurn, store.getUserActionRevision(refA))).toBe(false);
418+
expect(selectActiveRightPanelSurface(useRightPanelStore.getState().byThreadKey, refA)).toEqual(
419+
linkedPullRequest,
420+
);
385421
store.closeSurface(refA, linkedPullRequest.id);
386422
await reloadRightPanelStore();
387423
expect(store.openProactive(refA, nextTurn, store.getUserActionRevision(refA))).toBe(false);

‎apps/web/src/rightPanelStore.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -612,7 +612,9 @@ export const useRightPanelStore = create<RightPanelStoreState>()(
612612
activePanel === "pull-request" || activePanel === "pull-requests";
613613
opened =
614614
(state.userActionRevisionByThreadKey[threadKey] ?? 0) ===
615-
expectedUserActionRevision && !pullRequestActive;
615+
expectedUserActionRevision &&
616+
activePanel !== "diff" &&
617+
!pullRequestActive;
616618
// Record the offer even when refused, so a revisit does not retry this turn.
617619
return automaticUpdate(state, threadKey, (thread) => ({
618620
...(opened ? upsertSurface(thread, singletonSurface("diff")) : thread),

0 commit comments

Comments
 (0)