@devries-cameron20 / t3code-1 / commits / 4283e23392
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

refactor(web): move proactive right-panel opening out of ChatView (#20309)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>

Julius Marminge committed Oct 16, 2026 at 17:39 UTC 4283e23392f272fe69a4387d9768af9ed69883a4
3 files changed +224 -143
apps/web/src/components/ChatView.tsx
+15 -143
@@ -62,7 +62,6 @@ import {
62 type ServerProvider,
63 type ScopedThreadRef,
64 type ThreadId,
65 - type ThreadLinkedPullRequest,
65 type RunId,
66 type RuntimeRequestId,
67 type KeybindingCommand,
@@ -225,7 +224,6 @@ import {
224 } from "../rightPanelLayout";
225 import { PopoverCreateHandle } from "./ui/popover";
226 import {
228 - pullRequestSurface,
227 selectActiveRightPanel,
228 selectActiveRightPanelSurface,
229 selectThreadPanelOpen,
@@ -463,6 +461,7 @@ import {
461 } from "./chat/ThreadErrorBanner";
462 import { QueuedRunsControl, type QueuedRunsControlHandle } from "./chat/QueuedRunsControl";
463 import { useThreadLinkedPullRequest } from "./pullRequest/useThreadLinkedPullRequest";
464 +import { useProactivePanels } from "../hooks/useProactivePanels";
465 import type { ComposerBannerStackItem } from "./chat/ComposerBannerStack";
466 import { ThreadStatusLine } from "./chat/ThreadStatusLine";
467 import { formatRelativeTimeLabel, formatRelativeTimeUntilLabel } from "../timestampFormat";
@@ -502,9 +501,6 @@ import {
501 isBranchMismatchDismissedForSession,
502 shouldShowBranchMismatchBanner,
503 shouldShowPlanFollowUpPrompt,
505 - shouldOpenProactivePullRequest,
506 - shouldRetargetThreadPullRequestPanel,
507 - shouldOpenProactiveTurnDiff,
504 shouldReleaseTimelineAnchorForToolActivity,
505 shouldRenderPreviewMiniPlayer,
506 getStartedThreadModelChangeBlockReason,
@@ -522,8 +518,6 @@ import {
518 resolveComposerInteractionMode,
519 resolveComposerProviderSelection,
520 getAntigravitySendBlockReason,
525 - observeProactivePanelUserChoice,
526 - resolveProactiveTurnDiffAction,
521 resolveThreadMetadataUpdateForNextTurn,
522 resolveSendEnvMode,
523 revokeBlobPreviewUrl,
@@ -4270,147 +4264,25 @@ export default function ChatView(props: ChatViewProps) {
4264 )
4265 : linkedThreadPullRequestKey;
4266 const activeRunningTurnId = activeRuntime?.activeRunId ?? null;
4273 - const proactivePanelObservationRef = useRef<ReturnType<
4274 - typeof observeProactivePanelUserChoice
4275 - > | null>(null);
4276 - const observedThreadPullRequestRef = useRef<{
4277 - readonly threadKey: string;
4278 - readonly reference: ThreadLinkedPullRequest | null;
4279 - } | null>(null);
4280 -
4281 - useEffect(() => {
4282 - if (!isServerThread || activeThreadKey === null || activeThreadRef === null) {
4283 - proactivePanelObservationRef.current = null;
4284 - observedThreadPullRequestRef.current = null;
4285 - return;
4286 - }
4287 - const panels = useRightPanelStore.getState();
4288 - const observation = observeProactivePanelUserChoice(proactivePanelObservationRef.current, {
4289 - threadKey: activeThreadKey,
4290 - runningTurnId: activeRunningTurnId,
4291 - userActionRevision: panels.getUserActionRevision(activeThreadRef),
4292 - });
4293 - proactivePanelObservationRef.current = observation;
4294 - const {
4295 - runningTurnId: previousRunningTurnId,
4296 - targetKey: previousTargetKey,
4297 - userActionRevision,
4298 - } = observation;
4299 - const openSurface = selectActiveRightPanelSurface(panels.byThreadKey, activeThreadRef);
4300 - const previousPullRequest = observedThreadPullRequestRef.current;
4301 - observedThreadPullRequestRef.current = {
4302 - threadKey: activeThreadKey,
4303 - reference: linkedThreadPullRequest,
4304 - };
4305 - const followSelectedPullRequest =
4306 - previousPullRequest?.threadKey === activeThreadKey &&
4307 - shouldRetargetThreadPullRequestPanel(
4308 - previousPullRequest.reference,
4309 - linkedThreadPullRequest,
4310 - openSurface,
4311 - );
4312 - if (followSelectedPullRequest && linkedThreadPullRequest !== null) {
4313 - panels.openProactive(
4314 - activeThreadRef,
4315 - pullRequestSurface(linkedThreadPullRequest),
4316 - userActionRevision,
4317 - );
4318 - }
4319 - if (!clientSettingsHydrated) return;
4320 -
4321 - const proactivePanelsEnabled = settings.proactivePanelsEnabled && !shouldUsePlanSidebarSheet;
4322 - const eligibleLink =
4323 - proactivePanelsEnabled &&
4324 - shouldOpenProactivePullRequest(previousTargetKey, proactivePullRequestsKey);
4325 - const shouldDeferLink = eligibleLink && !pullRequestsCapabilityKnown;
4326 - proactivePanelObservationRef.current = {
4327 - ...observation,
4328 - targetKey: shouldDeferLink ? (previousTargetKey ?? null) : proactivePullRequestsKey,
4329 - };
4330 - if (eligibleLink && pullRequestsCapabilityKnown) {
4331 - if (
4332 - pullRequestsSurfaceAvailable &&
4333 - (visiblePullRequestCount > 1 || !hasLinkedPullRequestDetail || !supportsPullRequests)
4334 - ) {
4335 - panels.openProactive(
4336 - activeThreadRef,
4337 - { id: "pull-requests", kind: "pull-requests" },
4338 - userActionRevision,
4339 - );
4340 - } else if (
4341 - !followSelectedPullRequest &&
4342 - supportsPullRequests &&
4343 - linkedThreadPullRequest !== null
4344 - ) {
4345 - panels.openProactive(
4346 - activeThreadRef,
4347 - pullRequestSurface(linkedThreadPullRequest),
4348 - userActionRevision,
4349 - );
4350 - }
4351 - }
4352 - if (threadDetailLoading) return;
4353 -
4354 - const settledTurnId = latestRunSettled ? (activeLatestRun?.runId ?? null) : null;
4355 - const newlyCompletedTurnId = shouldOpenProactiveTurnDiff({
4356 - previousRunningTurnId,
4357 - runningTurnId: activeRunningTurnId,
4358 - settledTurnId,
4359 - turnCompleted: activeLatestRun?.status === "completed",
4360 - })
4361 - ? settledTurnId
4362 - : null;
4363 - const eligibleCompletion =
4364 - proactivePanelsEnabled &&
4365 - newlyCompletedTurnId !== null &&
4366 - !(
4367 - proactivePullRequestsKey !== null &&
4368 - (!pullRequestsCapabilityKnown || supportsPullRequests || pullRequestsSurfaceAvailable)
4369 - );
4370 - const completedCheckpoint = eligibleCompletion
4371 - ? turnDiffSummaries.find((checkpoint) => checkpoint.runId === newlyCompletedTurnId)
4372 - : undefined;
4373 - const diffAction = eligibleCompletion
4374 - ? resolveProactiveTurnDiffAction({
4375 - checkpoint: completedCheckpoint,
4376 - isGitRepo: gitStatusQuery.data?.isRepo,
4377 - activeSurfaceKind: openSurface?.kind ?? null,
4378 - })
4379 - : "ignore";
4380 - proactivePanelObservationRef.current = {
4381 - ...proactivePanelObservationRef.current,
4382 - runningTurnId:
4383 - diffAction === "defer" || shouldDeferLink ? previousRunningTurnId : activeRunningTurnId,
4384 - };
4385 - if (diffAction !== "open" || newlyCompletedTurnId === null) return;
4386 - if (!panels.openProactive(activeThreadRef, { id: "diff", kind: "diff" }, userActionRevision)) {
4387 - return;
4388 - }
4389 - useDiffPanelStore.getState().selectGitScope(activeThreadRef, "branch");
4390 - onDiffPanelOpen?.();
4391 - }, [
4392 - turnDiffSummaries,
4393 - activeLatestRun?.runId,
4394 - activeLatestRun?.status,
4395 - activeRunningTurnId,
4396 - activeThreadKey,
4397 - activeThreadRef,
4398 - clientSettingsHydrated,
4399 - gitStatusQuery.data?.isRepo,
4400 - isServerThread,
4267 + useProactivePanels({
4268 + threadRef: isServerThread ? activeThreadRef : null,
4269 + enabled: settings.proactivePanelsEnabled && !shouldUsePlanSidebarSheet,
4270 + settingsHydrated: clientSettingsHydrated,
4271 + threadDetailLoading,
4272 + runningTurnId: activeRunningTurnId,
4273 + latestRun: activeLatestRun,
4274 latestRunSettled,
4402 - linkedThreadPullRequest,
4403 - proactivePullRequestsKey,
4275 + turnDiffSummaries,
4276 + isGitRepo: gitStatusQuery.data?.isRepo,
4277 + linkedPullRequest: linkedThreadPullRequest,
4278 hasLinkedPullRequestDetail,
4405 - onDiffPanelOpen,
4279 + pullRequestsKey: proactivePullRequestsKey,
4280 pullRequestsCapabilityKnown,
4281 + supportsPullRequests,
4282 pullRequestsSurfaceAvailable,
4283 visiblePullRequestCount,
4409 -
4410 - settings.proactivePanelsEnabled,
4411 - shouldUsePlanSidebarSheet,
4412 - threadDetailLoading,
4413 - ]);
4284 + onDiffPanelOpen,
4285 + });
4286 const closePreviewPanel = () => {
4287 if (activeThreadRef) {
4288 if (activeRightPanelSurface?.kind === "preview" && activeRightPanelSurface.resourceId) {
apps/web/src/hooks/useProactivePanels.ts new
+208
@@ -0,0 +1,208 @@
1 +import type { RunId, ScopedThreadRef, ThreadLinkedPullRequest } from "@t3tools/contracts";
2 +import { scopedThreadKey } from "@t3tools/client-runtime/environment";
3 +import { useEffect, useRef } from "react";
4 +import { useDiffPanelStore } from "../diffPanelStore";
5 +import {
6 + selectActiveRightPanelSurface,
7 + pullRequestSurface,
8 + useRightPanelStore,
9 +} from "../rightPanelStore";
10 +import type { TurnDiffSummary } from "../types";
11 +import {
12 + observeProactivePanelUserChoice,
13 + resolveProactiveTurnDiffAction,
14 + shouldOpenProactivePullRequest,
15 + shouldOpenProactiveTurnDiff,
16 + shouldRetargetThreadPullRequestPanel,
17 +} from "../components/ChatView.logic";
18 +
19 +/**
20 + * Opens the right panel on its own when there is something new to look at: a
21 + * change request linked to the thread, or the diff of a turn that just
22 + * completed. A panel the user opened or closed since wins; see
23 + * observeProactivePanelUserChoice.
24 + */
25 +export function useProactivePanels(input: {
26 + // Null for drafts and while the thread is unavailable.
27 + readonly threadRef: ScopedThreadRef | null;
28 + readonly enabled: boolean;
29 + readonly settingsHydrated: boolean;
30 + readonly threadDetailLoading: boolean;
31 + readonly runningTurnId: RunId | null;
32 + readonly latestRun: { readonly runId: RunId; readonly status: string } | null;
33 + readonly latestRunSettled: boolean;
34 + readonly turnDiffSummaries: ReadonlyArray<TurnDiffSummary>;
35 + readonly isGitRepo: boolean | undefined;
36 + readonly linkedPullRequest: ThreadLinkedPullRequest | null;
37 + readonly hasLinkedPullRequestDetail: boolean;
38 + // Identifies the change requests the thread shows, so a new one can open the panel.
39 + readonly pullRequestsKey: string | null;
40 + readonly pullRequestsCapabilityKnown: boolean;
41 + readonly supportsPullRequests: boolean;
42 + readonly pullRequestsSurfaceAvailable: boolean;
43 + readonly visiblePullRequestCount: number;
44 + readonly onDiffPanelOpen: (() => void) | undefined;
45 +}) {
46 + const {
47 + threadRef,
48 + enabled: proactivePanelsEnabledSetting,
49 + settingsHydrated: clientSettingsHydrated,
50 + threadDetailLoading,
51 + runningTurnId: activeRunningTurnId,
52 + latestRun: activeLatestRun,
53 + latestRunSettled,
54 + turnDiffSummaries,
55 + isGitRepo,
56 + linkedPullRequest: linkedThreadPullRequest,
57 + hasLinkedPullRequestDetail,
58 + pullRequestsKey: proactivePullRequestsKey,
59 + pullRequestsCapabilityKnown,
60 + supportsPullRequests,
61 + pullRequestsSurfaceAvailable,
62 + visiblePullRequestCount,
63 + onDiffPanelOpen,
64 + } = input;
65 + const proactivePanelObservationRef = useRef<ReturnType<
66 + typeof observeProactivePanelUserChoice
67 + > | null>(null);
68 + const observedThreadPullRequestRef = useRef<{
69 + readonly threadKey: string;
70 + readonly reference: ThreadLinkedPullRequest | null;
71 + } | null>(null);
72 + const threadKey = threadRef ? scopedThreadKey(threadRef) : null;
73 +
74 + useEffect(() => {
75 + if (threadKey === null || threadRef === null) {
76 + proactivePanelObservationRef.current = null;
77 + observedThreadPullRequestRef.current = null;
78 + return;
79 + }
80 + const panels = useRightPanelStore.getState();
81 + const observation = observeProactivePanelUserChoice(proactivePanelObservationRef.current, {
82 + threadKey: threadKey,
83 + runningTurnId: activeRunningTurnId,
84 + userActionRevision: panels.getUserActionRevision(threadRef),
85 + });
86 + proactivePanelObservationRef.current = observation;
87 + const {
88 + runningTurnId: previousRunningTurnId,
89 + targetKey: previousTargetKey,
90 + userActionRevision,
91 + } = observation;
92 + const openSurface = selectActiveRightPanelSurface(panels.byThreadKey, threadRef);
93 + const previousPullRequest = observedThreadPullRequestRef.current;
94 + observedThreadPullRequestRef.current = {
95 + threadKey: threadKey,
96 + reference: linkedThreadPullRequest,
97 + };
98 + const followSelectedPullRequest =
99 + previousPullRequest?.threadKey === threadKey &&
100 + shouldRetargetThreadPullRequestPanel(
101 + previousPullRequest.reference,
102 + linkedThreadPullRequest,
103 + openSurface,
104 + );
105 + // Following the selected linked PR does not open an unrelated panel, so it
106 + // remains available with proactive panels off. It still respects a later choice.
107 + if (followSelectedPullRequest && linkedThreadPullRequest !== null) {
108 + panels.openProactive(
109 + threadRef,
110 + pullRequestSurface(linkedThreadPullRequest),
111 + userActionRevision,
112 + );
113 + }
114 + if (!clientSettingsHydrated) return;
115 +
116 + const proactivePanelsEnabled = proactivePanelsEnabledSetting;
117 + const eligibleLink =
118 + proactivePanelsEnabled &&
119 + shouldOpenProactivePullRequest(previousTargetKey, proactivePullRequestsKey);
120 + const shouldDeferLink = eligibleLink && !pullRequestsCapabilityKnown;
121 + proactivePanelObservationRef.current = {
122 + ...observation,
123 + targetKey: shouldDeferLink ? (previousTargetKey ?? null) : proactivePullRequestsKey,
124 + };
125 + if (eligibleLink && pullRequestsCapabilityKnown) {
126 + if (
127 + pullRequestsSurfaceAvailable &&
128 + (visiblePullRequestCount > 1 || !hasLinkedPullRequestDetail || !supportsPullRequests)
129 + ) {
130 + panels.openProactive(
131 + threadRef,
132 + { id: "pull-requests", kind: "pull-requests" },
133 + userActionRevision,
134 + );
135 + } else if (
136 + !followSelectedPullRequest &&
137 + supportsPullRequests &&
138 + linkedThreadPullRequest !== null
139 + ) {
140 + panels.openProactive(
141 + threadRef,
142 + pullRequestSurface(linkedThreadPullRequest),
143 + userActionRevision,
144 + );
145 + }
146 + }
147 + if (threadDetailLoading) return;
148 +
149 + const settledTurnId = latestRunSettled ? (activeLatestRun?.runId ?? null) : null;
150 + const newlyCompletedTurnId = shouldOpenProactiveTurnDiff({
151 + previousRunningTurnId,
152 + runningTurnId: activeRunningTurnId,
153 + settledTurnId,
154 + turnCompleted: activeLatestRun?.status === "completed",
155 + })
156 + ? settledTurnId
157 + : null;
158 + const eligibleCompletion =
159 + proactivePanelsEnabled &&
160 + newlyCompletedTurnId !== null &&
161 + !(
162 + proactivePullRequestsKey !== null &&
163 + (!pullRequestsCapabilityKnown || supportsPullRequests || pullRequestsSurfaceAvailable)
164 + );
165 + const completedCheckpoint = eligibleCompletion
166 + ? turnDiffSummaries.find((checkpoint) => checkpoint.runId === newlyCompletedTurnId)
167 + : undefined;
168 + const diffAction = eligibleCompletion
169 + ? resolveProactiveTurnDiffAction({
170 + checkpoint: completedCheckpoint,
171 + isGitRepo,
172 + activeSurfaceKind: openSurface?.kind ?? null,
173 + })
174 + : "ignore";
175 + proactivePanelObservationRef.current = {
176 + ...proactivePanelObservationRef.current,
177 + // Preserve first-entry eligibility while capabilities, checkpoint or repository load.
178 + runningTurnId:
179 + diffAction === "defer" || shouldDeferLink ? previousRunningTurnId : activeRunningTurnId,
180 + };
181 + if (diffAction !== "open" || newlyCompletedTurnId === null) return;
182 + if (!panels.openProactive(threadRef, { id: "diff", kind: "diff" }, userActionRevision)) {
183 + return;
184 + }
185 + useDiffPanelStore.getState().selectGitScope(threadRef, "branch");
186 + onDiffPanelOpen?.();
187 + }, [
188 + activeLatestRun?.runId,
189 + activeLatestRun?.status,
190 + activeRunningTurnId,
191 + clientSettingsHydrated,
192 + hasLinkedPullRequestDetail,
193 + isGitRepo,
194 + latestRunSettled,
195 + linkedThreadPullRequest,
196 + onDiffPanelOpen,
197 + proactivePanelsEnabledSetting,
198 + proactivePullRequestsKey,
199 + pullRequestsCapabilityKnown,
200 + pullRequestsSurfaceAvailable,
201 + supportsPullRequests,
202 + threadDetailLoading,
203 + threadKey,
204 + threadRef,
205 + turnDiffSummaries,
206 + visiblePullRequestCount,
207 + ]);
208 +}
vite.config.ts
+1
@@ -332,6 +332,7 @@ export default defineConfig({
332 "apps/web/src/components/chat/useUsageLimitsPanel.ts",
333 "apps/web/src/components/pullRequest/useThreadLinkedPullRequest.ts",
334 "apps/web/src/components/terminal/**",
335 + "apps/web/src/hooks/useProactivePanels.ts",
336 ],
337 rules: {
338 "react/exhaustive-effect-dependencies": "error",