Skip to content

Commit c5747e7

Browse files
committed
feat(web): add proactive panels
1 parent 28ddaf7 commit c5747e7

9 files changed

Lines changed: 244 additions & 3 deletions

File tree

‎apps/desktop/src/settings/DesktopClientSettings.test.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ const clientSettings: ClientSettings = {
4040
fontSmoothing: true,
4141
glassOpacity: 80,
4242
planModeEnabled: false,
43+
proactivePanelsEnabled: true,
4344
showSkillsInSlashMenu: false,
4445
providerModelPreferences: {},
4546
sidebarProjectGroupingMode: "repository_path",

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

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ import {
4040
codexArtifactTemplatePromptToAppend,
4141
shouldDockDraftHeroForSubmission,
4242
shouldReleaseTimelineAnchorForToolActivity,
43+
shouldOpenProactivePullRequest,
44+
shouldOpenProactiveTurnDiff,
4345
shouldShowBranchMismatchBanner,
4446
shouldShowPlanFollowUpPrompt,
4547
shouldWriteThreadErrorToCurrentServerThread,
@@ -83,6 +85,51 @@ describe("agent browser close confirmation", () => {
8385
});
8486
});
8587

88+
describe("proactive panels", () => {
89+
it("opens a pull request only after a newly observed link appears", () => {
90+
expect(shouldOpenProactivePullRequest(undefined, "project:repo:42")).toBe(false);
91+
expect(shouldOpenProactivePullRequest(null, "project:repo:42")).toBe(true);
92+
expect(shouldOpenProactivePullRequest("project:repo:42", "project:repo:42")).toBe(false);
93+
expect(shouldOpenProactivePullRequest("project:repo:42", null)).toBe(false);
94+
});
95+
96+
it("opens the diff only when the observed running turn settles", () => {
97+
const turnId = TurnId.make("turn-1");
98+
expect(
99+
shouldOpenProactiveTurnDiff({
100+
previousRunningTurnId: undefined,
101+
runningTurnId: null,
102+
settledTurnId: turnId,
103+
turnCompleted: true,
104+
}),
105+
).toBe(false);
106+
expect(
107+
shouldOpenProactiveTurnDiff({
108+
previousRunningTurnId: turnId,
109+
runningTurnId: null,
110+
settledTurnId: turnId,
111+
turnCompleted: true,
112+
}),
113+
).toBe(true);
114+
expect(
115+
shouldOpenProactiveTurnDiff({
116+
previousRunningTurnId: turnId,
117+
runningTurnId: TurnId.make("turn-2"),
118+
settledTurnId: turnId,
119+
turnCompleted: true,
120+
}),
121+
).toBe(false);
122+
expect(
123+
shouldOpenProactiveTurnDiff({
124+
previousRunningTurnId: turnId,
125+
runningTurnId: null,
126+
settledTurnId: turnId,
127+
turnCompleted: false,
128+
}),
129+
).toBe(false);
130+
});
131+
});
132+
86133
describe("isVideoPreviewRequestCurrent", () => {
87134
it("rejects changed threads and replaced previews", () => {
88135
expect(isVideoPreviewRequestCurrent("thread-1", "thread-2", 1, 1)).toBe(false);

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,28 @@ export function agentControlledBrowserCloseConfirmation(
7878
].join("\n");
7979
}
8080

81+
export function shouldOpenProactivePullRequest(
82+
previousTargetKey: string | null | undefined,
83+
targetKey: string | null,
84+
): boolean {
85+
return previousTargetKey !== undefined && targetKey !== null && targetKey !== previousTargetKey;
86+
}
87+
88+
export function shouldOpenProactiveTurnDiff(input: {
89+
previousRunningTurnId: TurnId | null | undefined;
90+
runningTurnId: TurnId | null;
91+
settledTurnId: TurnId | null;
92+
turnCompleted: boolean;
93+
}): boolean {
94+
return (
95+
input.previousRunningTurnId !== undefined &&
96+
input.previousRunningTurnId !== null &&
97+
input.runningTurnId === null &&
98+
input.turnCompleted &&
99+
input.settledTurnId === input.previousRunningTurnId
100+
);
101+
}
102+
81103
export function codexArtifactTemplatePromptToAppend(
82104
currentDraft: string,
83105
template: CodexArtifactTemplate,

‎apps/web/src/components/ChatView.tsx‎

Lines changed: 124 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,8 @@ import {
361361
shouldReleaseTimelineAnchorForToolActivity,
362362
shouldShowBranchMismatchBanner,
363363
shouldShowPlanFollowUpPrompt,
364+
shouldOpenProactivePullRequest,
365+
shouldOpenProactiveTurnDiff,
364366
getStartedThreadModelChangeBlockReason,
365367
LAST_INVOKED_SCRIPT_BY_PROJECT_KEY,
366368
LastInvokedScriptByProjectSchema,
@@ -1755,6 +1757,7 @@ function ChatViewContent(props: ChatViewProps) {
17551757
[activeThreadEnvironmentId, activeThreadId],
17561758
);
17571759
const activeThreadKey = activeThreadRef ? scopedThreadKey(activeThreadRef) : null;
1760+
const activeThreadShell = useThreadShell(isServerThread ? activeThreadRef : null);
17581761
const changeRequestSnapshotByKey = useAtomValue(threadChangeRequestSnapshotsAtom);
17591762
const [timelineAnchor, setTimelineAnchor] = useState<{
17601763
readonly threadKey: string | null;
@@ -3634,7 +3637,16 @@ function ChatViewContent(props: ChatViewProps) {
36343637
);
36353638
// The thread's own change request, placed against the project it belongs to. Without a
36363639
// project there is nothing to resolve it against, so the caller falls back to the browser.
3637-
const linkedThreadPullRequest = activeThread?.linkedPullRequest ?? null;
3640+
const linkedThreadPullRequest = isServerThread
3641+
? (activeThreadShell?.linkedPullRequest ?? activeThread?.linkedPullRequest ?? null)
3642+
: (activeThread?.linkedPullRequest ?? null);
3643+
const linkedThreadPullRequestKey = linkedThreadPullRequest
3644+
? JSON.stringify([
3645+
linkedThreadPullRequest.projectId,
3646+
linkedThreadPullRequest.repository,
3647+
linkedThreadPullRequest.number,
3648+
])
3649+
: null;
36383650
const activeProjectRepository = activeProject?.repositoryIdentity?.displayName ?? null;
36393651
const threadRepository = linkedThreadPullRequest?.repository ?? activeProjectRepository;
36403652
const openThreadPullRequest = useCallback(
@@ -3677,6 +3689,117 @@ function ChatViewContent(props: ChatViewProps) {
36773689
},
36783690
[activeProject, activeProjectRepository, activeThreadRef, supportsPullRequests],
36793691
);
3692+
const proactiveTurnObservationRef = useRef<{
3693+
threadKey: string;
3694+
runningTurnId: TurnId | null;
3695+
} | null>(null);
3696+
const proactivePullRequestObservationRef = useRef<{
3697+
threadKey: string;
3698+
targetKey: string | null;
3699+
} | null>(null);
3700+
3701+
useEffect(() => {
3702+
if (!isServerThread || activeThreadKey === null || activeThreadRef === null) {
3703+
proactiveTurnObservationRef.current = null;
3704+
return;
3705+
}
3706+
if (!clientSettingsHydrated || threadDetailLoading) {
3707+
return;
3708+
}
3709+
3710+
const previousObservation = proactiveTurnObservationRef.current;
3711+
const observingSameThread = previousObservation?.threadKey === activeThreadKey;
3712+
const previousRunningTurnId = observingSameThread
3713+
? previousObservation.runningTurnId
3714+
: undefined;
3715+
const settledTurnId = latestTurnSettled ? (activeLatestTurn?.turnId ?? null) : null;
3716+
const newlyCompletedTurnId = shouldOpenProactiveTurnDiff({
3717+
previousRunningTurnId,
3718+
runningTurnId: activeRunningTurnId,
3719+
settledTurnId,
3720+
turnCompleted: activeLatestTurn?.state === "completed",
3721+
})
3722+
? settledTurnId
3723+
: null;
3724+
const eligibleCompletion =
3725+
settings.proactivePanelsEnabled && !shouldUseRightPanelSheet && newlyCompletedTurnId !== null;
3726+
const checkpointReady =
3727+
eligibleCompletion &&
3728+
activeThread?.checkpoints.some((checkpoint) => checkpoint.turnId === newlyCompletedTurnId) ===
3729+
true;
3730+
const shouldOpenTurn = checkpointReady && gitStatusQuery.data?.isRepo === true;
3731+
const shouldDeferCompletion =
3732+
eligibleCompletion && !shouldOpenTurn && gitStatusQuery.data?.isRepo !== false;
3733+
proactiveTurnObservationRef.current = {
3734+
threadKey: activeThreadKey,
3735+
runningTurnId: shouldDeferCompletion ? (previousRunningTurnId ?? null) : activeRunningTurnId,
3736+
};
3737+
if (!shouldOpenTurn || newlyCompletedTurnId === null) return;
3738+
3739+
useDiffPanelStore.getState().selectTurn(activeThreadRef, newlyCompletedTurnId);
3740+
useRightPanelStore.getState().open(activeThreadRef, "diff");
3741+
onDiffPanelOpen?.();
3742+
}, [
3743+
activeThread?.checkpoints,
3744+
activeLatestTurn?.turnId,
3745+
activeLatestTurn?.state,
3746+
activeRunningTurnId,
3747+
activeThreadKey,
3748+
activeThreadRef,
3749+
clientSettingsHydrated,
3750+
gitStatusQuery.data?.isRepo,
3751+
isServerThread,
3752+
latestTurnSettled,
3753+
onDiffPanelOpen,
3754+
settings.proactivePanelsEnabled,
3755+
shouldUseRightPanelSheet,
3756+
threadDetailLoading,
3757+
]);
3758+
3759+
useEffect(() => {
3760+
if (!isServerThread || activeThreadKey === null || activeThreadRef === null) {
3761+
proactivePullRequestObservationRef.current = null;
3762+
return;
3763+
}
3764+
if (!clientSettingsHydrated || threadDetailLoading) {
3765+
return;
3766+
}
3767+
3768+
const previousObservation = proactivePullRequestObservationRef.current;
3769+
const observingSameThread = previousObservation?.threadKey === activeThreadKey;
3770+
const previousTargetKey = observingSameThread ? previousObservation.targetKey : undefined;
3771+
const newlyLinkedPullRequest = shouldOpenProactivePullRequest(
3772+
previousTargetKey,
3773+
linkedThreadPullRequestKey,
3774+
);
3775+
const eligibleLink =
3776+
settings.proactivePanelsEnabled && !shouldUseRightPanelSheet && newlyLinkedPullRequest;
3777+
const shouldOpenLink =
3778+
eligibleLink &&
3779+
pullRequestsCapabilityKnown &&
3780+
supportsPullRequests &&
3781+
linkedThreadPullRequest !== null;
3782+
const shouldDeferLink = eligibleLink && !pullRequestsCapabilityKnown;
3783+
proactivePullRequestObservationRef.current = {
3784+
threadKey: activeThreadKey,
3785+
targetKey: shouldDeferLink ? (previousTargetKey ?? null) : linkedThreadPullRequestKey,
3786+
};
3787+
if (!shouldOpenLink || linkedThreadPullRequest === null) return;
3788+
3789+
useRightPanelStore.getState().openPullRequest(activeThreadRef, linkedThreadPullRequest);
3790+
}, [
3791+
activeThreadKey,
3792+
activeThreadRef,
3793+
clientSettingsHydrated,
3794+
isServerThread,
3795+
linkedThreadPullRequest,
3796+
linkedThreadPullRequestKey,
3797+
pullRequestsCapabilityKnown,
3798+
settings.proactivePanelsEnabled,
3799+
shouldUseRightPanelSheet,
3800+
supportsPullRequests,
3801+
threadDetailLoading,
3802+
]);
36803803
const togglePreviewPanel = useCallback(() => {
36813804
if (!activeThreadRef || !isPreviewSupportedInRuntime()) return;
36823805
if (previewPanelOpen) {
@@ -4581,8 +4704,6 @@ function ChatViewContent(props: ChatViewProps) {
45814704
: null,
45824705
[activeThreadBranch, activeWorktreePath, envMode, gitStatusQuery.data?.refName, isServerThread],
45834706
);
4584-
// The server-projected settled state keeps the banner and sidebar in sync.
4585-
const activeThreadShell = useThreadShell(isServerThread ? activeThreadRef : null);
45864707
const activeComposerTasksProgress = useMemo(() => {
45874708
if (!activeLatestTurn || latestTurnSettled || activePlan?.turnId !== activeLatestTurn.turnId) {
45884709
return null;

‎apps/web/src/components/settings/SettingsPanels.tsx‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -519,6 +519,9 @@ export function useSettingsRestore(onRestored?: () => void) {
519519
...(settings.diffIgnoreWhitespace !== DEFAULT_UNIFIED_SETTINGS.diffIgnoreWhitespace
520520
? ["Diff whitespace changes"]
521521
: []),
522+
...(settings.proactivePanelsEnabled !== DEFAULT_UNIFIED_SETTINGS.proactivePanelsEnabled
523+
? ["Proactive panels"]
524+
: []),
522525
...(settings.showSkillsInSlashMenu !== DEFAULT_UNIFIED_SETTINGS.showSkillsInSlashMenu
523526
? ["Show skills in slash menu"]
524527
: []),
@@ -582,6 +585,7 @@ export function useSettingsRestore(onRestored?: () => void) {
582585
settings.defaultThreadEnvMode,
583586
settings.newWorktreesStartFromOrigin,
584587
settings.diffIgnoreWhitespace,
588+
settings.proactivePanelsEnabled,
585589
settings.environmentIdentificationMode,
586590
settings.contextWindowMeterEnabled,
587591
settings.fontFamilyCode,
@@ -676,6 +680,7 @@ export function useSettingsRestore(onRestored?: () => void) {
676680
timestampFormat: DEFAULT_UNIFIED_SETTINGS.timestampFormat,
677681
wordWrap: DEFAULT_UNIFIED_SETTINGS.wordWrap,
678682
diffIgnoreWhitespace: DEFAULT_UNIFIED_SETTINGS.diffIgnoreWhitespace,
683+
proactivePanelsEnabled: DEFAULT_UNIFIED_SETTINGS.proactivePanelsEnabled,
679684
showSkillsInSlashMenu: DEFAULT_UNIFIED_SETTINGS.showSkillsInSlashMenu,
680685
contextWindowMeterEnabled: DEFAULT_UNIFIED_SETTINGS.contextWindowMeterEnabled,
681686
environmentIdentificationMode: DEFAULT_UNIFIED_SETTINGS.environmentIdentificationMode,
@@ -2137,6 +2142,32 @@ export function GeneralSettingsPanel() {
21372142
}
21382143
/>
21392144

2145+
<SettingsRow
2146+
{...searchableSetting("proactive-panels")}
2147+
description="Automatically open the linked pull request when it appears and the turn diff when agent work finishes."
2148+
resetAction={
2149+
settings.proactivePanelsEnabled !== DEFAULT_UNIFIED_SETTINGS.proactivePanelsEnabled ? (
2150+
<SettingResetButton
2151+
label="proactive panels"
2152+
onClick={() =>
2153+
updateSettings({
2154+
proactivePanelsEnabled: DEFAULT_UNIFIED_SETTINGS.proactivePanelsEnabled,
2155+
})
2156+
}
2157+
/>
2158+
) : null
2159+
}
2160+
control={
2161+
<Switch
2162+
checked={settings.proactivePanelsEnabled}
2163+
onCheckedChange={(checked) =>
2164+
updateSettings({ proactivePanelsEnabled: Boolean(checked) })
2165+
}
2166+
aria-label="Proactive panels"
2167+
/>
2168+
}
2169+
/>
2170+
21402171
<SettingsRow
21412172
{...searchableSetting("skills-in-slash-menu")}
21422173
description="Also include skills in the / command menu. Skills always appear when you type $."

‎apps/web/src/components/settings/settingsSearch.ts‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,12 @@ export const SETTINGS_SEARCH_ITEMS = [
179179
to: "/settings/general",
180180
searchTerms: ["diff ignore spaces edits default"],
181181
},
182+
{
183+
id: "proactive-panels",
184+
title: "Proactive panels",
185+
to: "/settings/general",
186+
searchTerms: ["automatically open diff pull request pr right panel agent completion"],
187+
},
182188
{
183189
id: "skills-in-slash-menu",
184190
title: "Show skills in slash menu",

‎docs/user/source-control.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ T3 Code works with the platforms your team already uses:
4646
time, or change size
4747
- While working in a thread, open linked reviews in the same compact right-panel tabs without
4848
leaving the conversation
49+
- Enable **Settings → General → Proactive panels** to open a newly linked review automatically and
50+
switch to the completed turn's diff when agent work finishes
4951
- Open the review directly in your browser with one click
5052
- If T3 Code cannot load a GitHub pull request, including when GitHub rate limits requests, use
5153
**Open on GitHub** in the error view

‎packages/contracts/src/settings.test.ts‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,15 @@ describe("ClientSettings word wrap", () => {
6767
});
6868
});
6969

70+
describe("ClientSettings proactive panels", () => {
71+
it("is opt-in and accepts client-local updates", () => {
72+
expect(decodeClientSettings({}).proactivePanelsEnabled).toBe(false);
73+
expect(decodeClientSettingsPatch({ proactivePanelsEnabled: true }).proactivePanelsEnabled).toBe(
74+
true,
75+
);
76+
});
77+
});
78+
7079
describe("ClientSettings quit confirmation", () => {
7180
it("defaults to hold", () => {
7281
expect(decodeClientSettings({}).confirmQuit).toBe("hold");

‎packages/contracts/src/settings.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,7 @@ export const ClientSettingsSchema = Schema.Struct({
271271
// Legacy context window meter. The composer hides it by default; users who
272272
// still want the old usage indicator can restore it from Settings.
273273
contextWindowMeterEnabled: Schema.Boolean.pipe(Schema.withDecodingDefault(Effect.succeed(false))),
274+
proactivePanelsEnabled: Schema.Boolean.pipe(Schema.withDecodingDefault(Effect.succeed(false))),
274275
showSkillsInSlashMenu: Schema.Boolean.pipe(Schema.withDecodingDefault(Effect.succeed(true))),
275276
// Legacy sidebar (the original per-project tree). Deliberately a fresh key
276277
// (was `sidebarV2Enabled` + `sidebarV2ConfiguredByUser`): decoding drops the
@@ -998,6 +999,7 @@ export const ClientSettingsPatch = Schema.Struct({
998999
),
9991000
planModeEnabled: Schema.optionalKey(Schema.Boolean),
10001001
contextWindowMeterEnabled: Schema.optionalKey(Schema.Boolean),
1002+
proactivePanelsEnabled: Schema.optionalKey(Schema.Boolean),
10011003
showSkillsInSlashMenu: Schema.optionalKey(Schema.Boolean),
10021004
legacySidebarEnabled: Schema.optionalKey(Schema.Boolean),
10031005
sidebarProjectGroupingMode: Schema.optionalKey(SidebarProjectGroupingMode),

0 commit comments

Comments
 (0)