TypeScript
fix(web): stop empty diffs replacing pull requests (#9753)
mariad115a96763b7
diff --git a/apps/web/src/components/ChatView.logic.test.ts b/apps/web/src/components/ChatView.logic.test.tsindex c8afd10d372..c67ea3f3d5c 100644--- a/apps/web/src/components/ChatView.logic.test.ts+++ b/apps/web/src/components/ChatView.logic.test.ts@@ -41,6 +41,7 @@ import {resolveComposerInteractionMode,resolveComposerProviderSelection,resolveDraftPromotionNavigationTarget,+ resolveProactiveTurnDiffAction,resolveThreadMetadataUpdateForNextTurn,resolveSendEnvMode,resolveDraftHeroState,@@ -159,6 +160,80 @@ describe("proactive panels", () => {}),).toBe(false);});++ it("opens a completed turn diff only for changed files", () => {+ const changedCheckpoint = {+ status: "ready",+ files: [{ path: "src/app.ts", kind: "modified", additions: 1, deletions: 0 }],+ } satisfies Pick<TurnDiffSummary, "status" | "files">;+ const unchangedCheckpoint = {+ status: "ready",+ files: [],+ } satisfies Pick<TurnDiffSummary, "status" | "files">;++ expect(+ resolveProactiveTurnDiffAction({+ checkpoint: changedCheckpoint,+ isGitRepo: true,+ activeSurfaceKind: null,+ }),+ ).toBe("open");+ expect(+ resolveProactiveTurnDiffAction({+ checkpoint: unchangedCheckpoint,+ isGitRepo: true,+ activeSurfaceKind: null,+ }),+ ).toBe("ignore");+ });++ it("waits for definitive checkpoint and repository state", () => {+ const missingCheckpoint = {+ status: "missing",+ files: [],+ } satisfies Pick<TurnDiffSummary, "status" | "files">;+ const changedCheckpoint = {+ status: "ready",+ files: [{ path: "src/app.ts", kind: "modified", additions: 1, deletions: 0 }],+ } satisfies Pick<TurnDiffSummary, "status" | "files">;++ expect(+ resolveProactiveTurnDiffAction({+ checkpoint: undefined,+ isGitRepo: true,+ activeSurfaceKind: null,+ }),+ ).toBe("defer");+ expect(+ resolveProactiveTurnDiffAction({+ checkpoint: missingCheckpoint,+ isGitRepo: true,+ activeSurfaceKind: null,+ }),+ ).toBe("defer");+ expect(+ resolveProactiveTurnDiffAction({+ checkpoint: changedCheckpoint,+ isGitRepo: undefined,+ activeSurfaceKind: null,+ }),+ ).toBe("defer");+ });++ it("keeps an active pull request above a completed turn diff", () => {+ const changedCheckpoint = {+ status: "ready",+ files: [{ path: "src/app.ts", kind: "modified", additions: 1, deletions: 0 }],+ } satisfies Pick<TurnDiffSummary, "status" | "files">;++ expect(+ resolveProactiveTurnDiffAction({+ checkpoint: changedCheckpoint,+ isGitRepo: true,+ activeSurfaceKind: "pull-request",+ }),+ ).toBe("ignore");+ });});describe("toolGroupConsumesUpwardNavigation", () => {diff --git a/apps/web/src/components/ChatView.logic.ts b/apps/web/src/components/ChatView.logic.tsindex 4a0b9f57610..10c2fd4710e 100644--- a/apps/web/src/components/ChatView.logic.ts+++ b/apps/web/src/components/ChatView.logic.ts@@ -121,6 +121,24 @@ export function shouldOpenProactiveTurnDiff(input: {);}+export function resolveProactiveTurnDiffAction(input: {+ checkpoint: Pick<TurnDiffSummary, "status" | "files"> | undefined;+ isGitRepo: boolean | undefined;+ activeSurfaceKind: RightPanelSurface["kind"] | null;+}): "defer" | "ignore" | "open" {+ if (input.activeSurfaceKind === "pull-request") return "ignore";+ if (input.checkpoint === undefined || input.checkpoint.status === "missing") return "defer";+ if (input.isGitRepo === undefined) return "defer";+ if (+ !input.isGitRepo ||+ input.checkpoint.status !== "ready" ||+ input.checkpoint.files.length === 0+ ) {+ return "ignore";+ }+ return "open";+}+export function codexArtifactTemplatePromptToAppend(currentDraft: string,template: CodexArtifactTemplate,diff --git a/apps/web/src/components/ChatView.tsx b/apps/web/src/components/ChatView.tsxindex ccd970e6dda..cfbeb3aa7f7 100644--- a/apps/web/src/components/ChatView.tsx+++ b/apps/web/src/components/ChatView.tsx@@ -385,6 +385,7 @@ import {resolveComposerInteractionMode,resolveComposerProviderSelection,resolveDraftHeroState,+ resolveProactiveTurnDiffAction,resolveThreadMetadataUpdateForNextTurn,resolveSendEnvMode,revokeBlobPreviewUrl,@@ -3922,18 +3923,21 @@ export default function ChatView(props: ChatViewProps) {: null;const eligibleCompletion =settings.proactivePanelsEnabled && !shouldUseRightPanelSheet && newlyCompletedTurnId !== null;- const checkpointReady =- eligibleCompletion &&- activeThread?.checkpoints.some((checkpoint) => checkpoint.turnId === newlyCompletedTurnId) ===- true;- const shouldOpenTurn = checkpointReady && gitStatusQuery.data?.isRepo === true;- const shouldDeferCompletion =- eligibleCompletion && !shouldOpenTurn && gitStatusQuery.data?.isRepo !== false;+ const completedCheckpoint = eligibleCompletion+ ? activeThread?.checkpoints.find((checkpoint) => checkpoint.turnId === newlyCompletedTurnId)+ : undefined;+ const diffAction = eligibleCompletion+ ? resolveProactiveTurnDiffAction({+ checkpoint: completedCheckpoint,+ isGitRepo: gitStatusQuery.data?.isRepo,+ activeSurfaceKind: activeRightPanelSurface?.kind ?? null,+ })+ : "ignore";proactiveTurnObservationRef.current = {threadKey: activeThreadKey,- runningTurnId: shouldDeferCompletion ? (previousRunningTurnId ?? null) : activeRunningTurnId,+ runningTurnId: diffAction === "defer" ? (previousRunningTurnId ?? null) : activeRunningTurnId,};- if (!shouldOpenTurn || newlyCompletedTurnId === null) return;+ if (diffAction !== "open" || newlyCompletedTurnId === null) return;useDiffPanelStore.getState().selectTurn(activeThreadRef, newlyCompletedTurnId);useRightPanelStore.getState().open(activeThreadRef, "diff");@@ -3945,6 +3949,7 @@ export default function ChatView(props: ChatViewProps) {activeRunningTurnId,activeThreadKey,activeThreadRef,+ activeRightPanelSurface?.kind,clientSettingsHydrated,gitStatusQuery.data?.isRepo,isServerThread,diff --git a/apps/web/src/components/settings/SettingsPanels.tsx b/apps/web/src/components/settings/SettingsPanels.tsxindex d78828da5cf..b0344b64039 100644--- a/apps/web/src/components/settings/SettingsPanels.tsx+++ b/apps/web/src/components/settings/SettingsPanels.tsx@@ -2308,7 +2308,7 @@ export function GeneralSettingsPanel() {<SettingsRow{...searchableSetting("proactive-panels")}- description="Open linked pull requests when found and turn diffs when work finishes."+ description="Open linked pull requests when found and turn diffs when work changes files."resetAction={settings.proactivePanelsEnabled !== DEFAULT_UNIFIED_SETTINGS.proactivePanelsEnabled ? (<SettingResetButtondiff --git a/docs/user/source-control.md b/docs/user/source-control.mdindex 482b3ccd1f1..71f6548dd6b 100644--- a/docs/user/source-control.md+++ b/docs/user/source-control.md@@ -64,7 +64,7 @@ T3 Code works with the platforms your team already uses:changed files as folders and jump straight to any of them. The toolbar toggle remembers yourchoice.- Enable **Settings → General → Proactive panels** to open a newly linked review automatically and- switch to the completed turn's diff when agent work finishes+ switch to the completed turn's diff when agent work changes files. An open review stays in front- Open the review directly in your browser with one click- If T3 Code cannot load a GitHub pull request, including when GitHub rate limits requests, use**Open on GitHub** in the error view