The best way to control Claude Code, Codex and more from any computer or phone
refactor(web): review guide runs are watched from their answers, not from mounted components (#25459)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Julius Marminge committed
Oct 26, 2026 at 05:31 UTC
2acc7b55cfef71f493d189a6c95c2372f2598d80
11 files changed
+289
-101
apps/web/src/appInit.tsx
+2
@@ -14,6 +14,7 @@ import { startAgentOpenedPreviews } from "./components/preview/agentOpenedPrevie
14
import { startMainAppLocationTracking } from "./components/sidebar/mainAppLocation";
15
import { startDesktopUpdateLaunchNotice } from "./components/sidebar/updateEverythingRun";
16
import { startThreadNotifications } from "./components/ThreadNotificationCoordinator";
17
+import { startGuideRunNotifications } from "./components/pullRequest/guide/PullRequestGuideRunCoordinator";
18
import { APP_BASE_NAME, APP_DISPLAY_NAME, APP_STAGE_LABEL } from "./branding";
19
import { resolveServerBackedAppDisplayName } from "./branding.logic";
20
import { isElectron } from "./env";
@@ -151,6 +152,7 @@ export function startAppServices(): AppRouter {
152
startLegacyThreadMigrationToast();
153
startPermissionUpdateNotices(router);
154
startThreadNotifications(appAtomRegistry, router);
155
+ startGuideRunNotifications(appAtomRegistry, router);
156
if (isElectron) startDesktopUpdateLaunchNotice();
157
158
return router;
apps/web/src/components/pullRequest/PullRequestDetailPanel.tsx
+39
-33
@@ -260,6 +260,7 @@ export function PullRequestDetailPanel({
260
reference: requestedReference,
261
listEntry = null,
262
refreshToken: forcedRefreshToken = 0,
263
+ tabOnPage = false,
264
onActed,
265
onClose,
266
context = "page",
@@ -278,6 +279,11 @@ export function PullRequestDetailPanel({
279
reference: PullRequestRef;
280
listEntry?: PullRequestListEntry | null;
281
refreshToken?: number;
282
+ /**
283
+ * The pull requests page's panel: its tab lives in the guide run store, where a review guide
284
+ * notification can switch it.
285
+ */
286
+ tabOnPage?: boolean;
287
onActed?: (action?: PullRequestAction, phase?: "sent" | "done" | "failed") => void;
288
onClose?: () => void;
289
context?: "page" | "thread";
@@ -334,9 +340,33 @@ export function PullRequestDetailPanel({
340
useEnvironmentQuery(pullRequestEnvironment.changeBreakdown({ environmentId, input: reference }));
341
const [threadPickerOpen, setThreadPickerOpen] = useState(false);
342
const [openReviewRequest, setOpenReviewRequest] = useState(0);
337
- const [tab, setTab] = useState<PullRequestDetailTab>(initialTab);
343
+ const {
344
+ canWriteSourceControl,
345
+ detailQuery,
346
+ activityQuery,
347
+ activity,
348
+ sharedSummary,
349
+ coreDetail,
350
+ detail,
351
+ } = usePullRequestDetail(environmentId, reference, matchingListEntry);
352
+ const [selectedTab, setTab] = useState<PullRequestDetailTab>(initialTab);
353
+ const reviewGuidesEnabled = useEnvironmentSettings(
354
+ environmentId,
355
+ (settings) => settings.reviewGuidesEnabled,
356
+ );
357
+ const guideKey = guideRunKey(environmentId, reference);
358
+ const pageTab = useGuideRunStore((state) =>
359
+ tabOnPage && state.pageDetailTab?.key === guideKey ? state.pageDetailTab.tab : null,
360
+ );
361
+ const requestedTab = tabOnPage ? (pageTab ?? initialTab) : selectedTab;
362
+ const isTabAvailable = (value: PullRequestDetailTab) =>
363
+ (value !== "code" || detail === null || detail.capabilities.diff) &&
364
+ (value !== "guide" || reviewGuidesEnabled);
365
+ // An unavailable tab falls back without overwriting the saved selection.
366
+ const tab = isTabAvailable(requestedTab) ? requestedTab : "summary";
367
const selectTab = (next: PullRequestDetailTab) => {
339
- setTab(next);
368
+ if (tabOnPage) useGuideRunStore.getState().showPageDetailTab(guideKey, next);
369
+ else setTab(next);
370
onTabChange?.(next);
371
};
372
const [timelineOrder, setTimelineOrder] = useState<"newest" | "oldest">("newest");
@@ -363,15 +393,6 @@ export function PullRequestDetailPanel({
393
void loadCodeTab();
394
selectTab("code");
395
};
366
- const guideOpenRequested = useGuideRunStore(
367
- (state) => state.openRequestKey === guideRunKey(environmentId, reference),
368
- );
369
- if (guideOpenRequested && tab !== "guide") setTab("guide");
370
- useEffect(() => {
371
- if (!guideOpenRequested) return;
372
- useGuideRunStore.getState().requestOpen(null);
373
- onTabChange?.("guide");
374
- }, [guideOpenRequested, onTabChange]);
396
const tabScopeKey = `${environmentId}:${pullRequestKey}`;
397
const [tabMountState, setTabMountState] = useState(() => ({
398
key: tabScopeKey,
@@ -440,15 +461,6 @@ export function PullRequestDetailPanel({
461
};
462
const [handoff, setHandoff] = useState<string | null>(null);
463
const turnRefresh = usePullRequestTurnRefresh(environmentId);
443
- const {
444
- canWriteSourceControl,
445
- detailQuery,
446
- activityQuery,
447
- activity,
448
- sharedSummary,
449
- coreDetail,
450
- detail,
451
- } = usePullRequestDetail(environmentId, reference, matchingListEntry);
464
const handoffSummary = detail ?? sharedSummary;
465
const terminology = sourceControlClients.get(
466
handoffSummary?.provider ?? listEntry?.provider ?? repositoryIdentity?.provider,
@@ -811,8 +823,8 @@ export function PullRequestDetailPanel({
823
repository: reference.repository,
824
number: reference.number,
825
url: detail.url,
826
+ detailTab: "guide",
827
});
815
- useGuideRunStore.getState().requestOpen(guideRunKey(environmentId, reference));
828
}
829
}
830
if (opened === null) {
@@ -1103,17 +1115,7 @@ export function PullRequestDetailPanel({
1115
const workflowApprovalsRequired =
1116
detail?.state === "open" ? (detail.workflowApprovalsRequired ?? 0) : 0;
1117
const freshness = detail === null ? null : resolveBaseFreshness(detail);
1106
- const reviewGuidesEnabled = useEnvironmentSettings(
1107
- environmentId,
1108
- (settings) => settings.reviewGuidesEnabled,
1109
- );
1110
- const visibleTabs = TABS.filter(
1111
- (item) =>
1112
- (item.value !== "code" || detail === null || detail.capabilities.diff) &&
1113
- (item.value !== "guide" || reviewGuidesEnabled),
1114
- );
1115
- // Keep unavailable-tab fallbacks out of the saved selection.
1116
- if (!visibleTabs.some((item) => item.value === tab)) setTab("summary");
1118
+ const visibleTabs = TABS.filter((item) => isTabAvailable(item.value));
1119
const can = (action: PullRequestAction) =>
1120
detail?.capabilities.actions.includes(action) === true &&
1121
detail.viewerPermissions.actions.includes(action);
@@ -1741,7 +1743,11 @@ export function PullRequestDetailPanel({
1743
</div>
1744
) : null}
1745
{mountedTabs.has("guide") ? (
1744
- <div className={cn("absolute inset-0", tab !== "guide" && "invisible")}>
1746
+ <div
1747
+ className={cn("absolute inset-0", tab !== "guide" && "invisible")}
1748
+ // Read by the guide run notifier, which stays quiet for a guide on screen.
1749
+ data-guide-shown={tab === "guide" ? guideKey : undefined}
1750
+ >
1751
<PullRequestGuideTab
1752
environmentId={environmentId}
1753
reference={reference}
apps/web/src/components/pullRequest/PullRequestGuideTab.tsx
-11
@@ -8,7 +8,6 @@ import { Alert, AlertAction, AlertDescription } from "../ui/alert";
8
import { Button } from "../ui/button";
9
import { Spinner } from "../ui/spinner";
10
import type { ExcerptCommenting } from "./guide/GuideExcerpt";
11
-import { guideRunKey, useGuideRunStore } from "./guide/guideRunStore";
11
import { GuideProseContext } from "./guide/GuideProse";
12
import { GuideTour } from "./guide/GuideTour";
13
import { useReviewGuideWriter } from "./guide/useReviewGuideWriter";
@@ -53,7 +52,6 @@ export function PullRequestGuideTab({
52
reference,
53
title,
54
});
56
- const runKey = guideRunKey(environmentId, reference);
55
const reviewKey = pullRequestReviewKey(reference);
56
const pending = usePendingReviewComments(reference);
57
const addComment = usePullRequestReviewStore((store) => store.addComment);
@@ -77,15 +75,6 @@ export function PullRequestGuideTab({
75
onRemove: (commentId) => removeComment(reviewKey, commentId),
76
onAskAgent: onAskAboutLines,
77
};
80
- useEffect(() => {
81
- if (!active) return;
82
- useGuideRunStore.getState().setShown(runKey);
83
- return () => {
84
- if (useGuideRunStore.getState().shownKey === runKey)
85
- useGuideRunStore.getState().setShown(null);
86
- };
87
- }, [active, runKey]);
88
-
78
const guide = data?.guide ?? null;
79
const tourShown = active && guide !== null;
80
const reportTourShown = useEffectEvent(() => onTourShown?.());
apps/web/src/components/pullRequest/PullRequestsPage.tsx
+1
@@ -1523,6 +1523,7 @@ export function PullRequestsPage() {
1523
) ?? null
1524
}
1525
refreshToken={detailRefreshToken}
1526
+ tabOnPage
1527
onActed={(action, phase = "done") => {
1528
// From every row held, not the ones on screen: a pull request closed from an open
1529
// list has left the screen, and reopening it has to find it anyway.
apps/web/src/components/pullRequest/guide/PullRequestGuideRunCoordinator.test.ts
new
+122
@@ -0,0 +1,122 @@
1
+import type { AnyRouter } from "@tanstack/react-router";
2
+import {
3
+ EnvironmentId,
4
+ ProjectId,
5
+ type PullRequestRef,
6
+ type PullRequestReviewGuideResult,
7
+} from "@t3tools/contracts";
8
+import { AsyncResult, Atom, AtomRegistry } from "effect/reactivity";
9
+import { expect, it, vi } from "vite-plus/test";
10
+
11
+import { guideRunKey, useGuideRunStore } from "./guideRunStore";
12
+import { startGuideRunNotifications } from "./PullRequestGuideRunCoordinator";
13
+
14
+const guides = vi.hoisted(() => ({
15
+ family: null as unknown as (key: string) => unknown,
16
+}));
17
+vi.mock(import("~/state/pullRequests"), async (original) => {
18
+ const actual = await original();
19
+ return {
20
+ ...actual,
21
+ pullRequestEnvironment: {
22
+ ...actual.pullRequestEnvironment,
23
+ reviewGuide: ((target: { environmentId: string; input: PullRequestRef }) =>
24
+ guides.family(`${target.environmentId}:${target.input.number}`)) as never,
25
+ },
26
+ };
27
+});
28
+
29
+const guideAtom = Atom.family((_key: string) =>
30
+ Atom.make<AsyncResult.AsyncResult<PullRequestReviewGuideResult, never>>(AsyncResult.initial()),
31
+);
32
+guides.family = guideAtom;
33
+
34
+const environmentId = EnvironmentId.make("env-1");
35
+function reference(number: number): PullRequestRef {
36
+ return { projectId: ProjectId.make("project-1"), repository: "acme/app", number };
37
+}
38
+const running = {
39
+ guide: null,
40
+ run: { _tag: "Running" },
41
+} as unknown as PullRequestReviewGuideResult;
42
+const idle = { guide: null, run: null } as unknown as PullRequestReviewGuideResult;
43
+
44
+function setup() {
45
+ useGuideRunStore.setState({ watches: {} });
46
+ const registry = AtomRegistry.make();
47
+ const refresh = vi.spyOn(registry, "refresh");
48
+ const refreshed = () =>
49
+ refresh.mock.calls.flatMap(([atom]) =>
50
+ [1, 2].filter((number) => atom === guideAtom(`${environmentId}:${number}`)).map(String),
51
+ );
52
+ const stop = startGuideRunNotifications(registry, { navigate: vi.fn() } as unknown as AnyRouter);
53
+ const watch = (number: number, since = 0) =>
54
+ useGuideRunStore.getState().watch({
55
+ environmentId,
56
+ reference: reference(number),
57
+ title: null,
58
+ previousGuideAt: null,
59
+ previousFailedAt: null,
60
+ since,
61
+ });
62
+ return { registry, refreshed, stop, watch };
63
+}
64
+
65
+it("polls each watched run once, however often the watches change", () => {
66
+ using _timers = { [Symbol.dispose]: () => vi.useRealTimers() };
67
+ vi.useFakeTimers();
68
+ const { registry, refreshed, stop, watch } = setup();
69
+ registry.set(guideAtom(`${environmentId}:1`), AsyncResult.success(running));
70
+ registry.set(guideAtom(`${environmentId}:2`), AsyncResult.success(running));
71
+ watch(1);
72
+ watch(2);
73
+ vi.advanceTimersByTime(5_000);
74
+ expect(refreshed().toSorted()).toEqual(["1", "2"]);
75
+ stop();
76
+});
77
+
78
+it("does not keep polling a run that settles on its first read", () => {
79
+ using _timers = { [Symbol.dispose]: () => vi.useRealTimers() };
80
+ vi.useFakeTimers();
81
+ const { registry, refreshed, stop, watch } = setup();
82
+ // Long unseen and not running: the first read retires the watch.
83
+ registry.set(guideAtom(`${environmentId}:1`), AsyncResult.success(idle));
84
+ watch(1, 0);
85
+ expect(useGuideRunStore.getState().watches[guideRunKey(environmentId, reference(1))]).toBe(
86
+ undefined,
87
+ );
88
+ vi.advanceTimersByTime(5_000);
89
+ expect(refreshed()).toEqual([]);
90
+ stop();
91
+});
92
+
93
+it("does not report the previous run's failure when a Running answer starts a watch", () => {
94
+ using _timers = { [Symbol.dispose]: () => vi.useRealTimers() };
95
+ vi.useFakeTimers();
96
+ const { registry, stop } = setup();
97
+ const atom = guideAtom(`${environmentId}:1`);
98
+ const key = guideRunKey(environmentId, reference(1));
99
+ registry.set(
100
+ atom,
101
+ AsyncResult.success({
102
+ guide: null,
103
+ run: { _tag: "Failed", failedAt: "2026-10-01T00:00:00.000Z", detail: "old failure" },
104
+ } as unknown as PullRequestReviewGuideResult),
105
+ );
106
+ // What the reviewGuide answer handler does before the Running answer replaces the atom's value.
107
+ useGuideRunStore.getState().watch({
108
+ environmentId,
109
+ reference: reference(1),
110
+ title: null,
111
+ previousGuideAt: null,
112
+ previousFailedAt: null,
113
+ since: 0,
114
+ answeredRunning: true,
115
+ });
116
+ expect(useGuideRunStore.getState().watches[key]).toBeDefined();
117
+ registry.set(atom, AsyncResult.success(running));
118
+ expect(useGuideRunStore.getState().watches[key]).toBeDefined();
119
+ registry.set(atom, AsyncResult.success(idle));
120
+ expect(useGuideRunStore.getState().watches[key]).toBe(undefined);
121
+ stop();
122
+});
apps/web/src/components/pullRequest/guide/PullRequestGuideRunCoordinator.tsx
+79
-35
@@ -1,10 +1,11 @@
1
-import { useNavigate } from "@tanstack/react-router";
1
+import type { AnyRouter } from "@tanstack/react-router";
2
+import type { PullRequestReviewGuideResult } from "@t3tools/contracts";
3
import { CircleAlertIcon, CircleCheckIcon } from "lucide-react";
3
-import { useEffect, useRef } from "react";
4
+import * as Option from "effect/Option";
5
+import { AsyncResult, type AtomRegistry } from "effect/reactivity";
6
7
import { getClientSettings } from "~/hooks/useSettings";
6
-import { pullRequestEnvironment } from "~/state/pullRequests";
7
-import { useEnvironmentQuery } from "~/state/query";
8
+import { observedPullRequestTitle, pullRequestEnvironment } from "~/state/pullRequests";
9
import {
10
hasDesktopNotifications,
11
hasNotificationSound,
@@ -18,33 +19,58 @@ import { useGuideRunStore, type GuideRunWatch } from "./guideRunStore";
19
const RUN_POLL_MS = 5_000;
20
const UNSEEN_RUN_MS = 60_000;
21
21
-export function PullRequestGuideRunCoordinator() {
22
- const watches = useGuideRunStore((state) => state.watches);
23
- return Object.entries(watches).map(([key, watch]) => (
24
- <GuideRunWatcher key={key} runKey={key} watch={watch} />
25
- ));
22
+// The detail panel marks the guide tab it has on screen.
23
+function isGuideShown(runKey: string): boolean {
24
+ return document.querySelector(`[data-guide-shown="${CSS.escape(runKey)}"]`) !== null;
25
}
26
28
-function GuideRunWatcher({ runKey, watch }: { runKey: string; watch: GuideRunWatch }) {
29
- const query = useEnvironmentQuery(
30
- pullRequestEnvironment.reviewGuide({
31
- environmentId: watch.environmentId,
32
- input: watch.reference,
33
- }),
34
- );
35
- const navigate = useNavigate();
36
- const refresh = query.refresh;
37
- useEffect(() => {
38
- const timer = setInterval(refresh, RUN_POLL_MS);
39
- return () => clearInterval(timer);
40
- }, [refresh]);
27
+/** Polls every watched guide run and announces each one when it settles. App-lifetime. */
28
+export function startGuideRunNotifications(
29
+ registry: AtomRegistry.AtomRegistry,
30
+ router: AnyRouter,
31
+): () => void {
32
+ const running = new Map<string, () => void>();
33
+ const sync = (watches: Readonly<Record<string, GuideRunWatch>>) => {
34
+ for (const [key, stop] of running) {
35
+ if (watches[key] !== undefined) continue;
36
+ running.delete(key);
37
+ stop();
38
+ }
39
+ for (const [key, watch] of Object.entries(watches)) {
40
+ if (running.has(key)) continue;
41
+ const stop = watchGuideRun(registry, router, key, watch);
42
+ // The first read can settle the run before it is recorded as running.
43
+ if (useGuideRunStore.getState().watches[key] === watch) running.set(key, stop);
44
+ else stop();
45
+ }
46
+ };
47
+ sync(useGuideRunStore.getState().watches);
48
+ const unsubscribe = useGuideRunStore.subscribe((state, previous) => {
49
+ if (state.watches !== previous.watches) sync(state.watches);
50
+ });
51
+ return () => {
52
+ unsubscribe();
53
+ for (const stop of running.values()) stop();
54
+ running.clear();
55
+ };
56
+}
57
42
- const data = query.data;
43
- const sawRunning = useRef(false);
44
- useEffect(() => {
45
- if (data === null) return;
58
+function watchGuideRun(
59
+ registry: AtomRegistry.AtomRegistry,
60
+ router: AnyRouter,
61
+ runKey: string,
62
+ watch: GuideRunWatch,
63
+): () => void {
64
+ const atom = pullRequestEnvironment.reviewGuide({
65
+ environmentId: watch.environmentId,
66
+ input: watch.reference,
67
+ });
68
+ let sawRunning = watch.answeredRunning === true;
69
+ let subscribing = true;
70
+ let seen: PullRequestReviewGuideResult | null = null;
71
+ const onGuide = (data: PullRequestReviewGuideResult) => {
72
if (data.run?._tag === "Running") {
47
- sawRunning.current = true;
73
+ sawRunning = true;
74
return;
75
}
76
const failure =
@@ -54,7 +80,7 @@ function GuideRunWatcher({ runKey, watch }: { runKey: string; watch: GuideRunWat
80
const written =
81
failure === null && data.guide !== null && data.guide.generatedAt !== watch.previousGuideAt;
82
if (failure === null && !written) {
57
- if (sawRunning.current || Date.now() - watch.since > UNSEEN_RUN_MS) {
83
+ if (sawRunning || Date.now() - watch.since > UNSEEN_RUN_MS) {
84
useGuideRunStore.getState().settle(runKey);
85
}
86
return;
@@ -62,13 +88,16 @@ function GuideRunWatcher({ runKey, watch }: { runKey: string; watch: GuideRunWat
88
const store = useGuideRunStore.getState();
89
store.settle(runKey);
90
const looking = document.visibilityState === "visible" && document.hasFocus();
65
- if (looking && store.shownKey === runKey) return;
91
+ if (looking && isGuideShown(runKey)) return;
92
93
const title = failure === null ? "Review guide ready" : "Review guide failed";
68
- const body = watch.title ?? `${watch.reference.repository} #${watch.reference.number}`;
94
+ const body =
95
+ watch.title ??
96
+ observedPullRequestTitle(registry, watch.environmentId, watch.reference) ??
97
+ `${watch.reference.repository} #${watch.reference.number}`;
98
const open = () => {
70
- useGuideRunStore.getState().requestOpen(runKey);
71
- void navigate({
99
+ useGuideRunStore.getState().showPageDetailTab(runKey, "guide");
100
+ void router.navigate({
101
to: "/pull-requests",
102
search: {
103
...readPullRequestListPreferences(),
@@ -126,7 +155,22 @@ function GuideRunWatcher({ runKey, watch }: { runKey: string; watch: GuideRunWat
155
} catch {
156
// Some browsers expose Notification but reject desktop presentation.
157
}
129
- }, [data, navigate, runKey, watch]);
130
-
131
- return null;
158
+ };
159
+ const unsubscribe = registry.subscribe(
160
+ atom,
161
+ (result) => {
162
+ const data = Option.getOrNull(AsyncResult.value(result));
163
+ if (data === null || data === seen) return;
164
+ seen = data;
165
+ if (subscribing && watch.answeredRunning === true) return;
166
+ onGuide(data);
167
+ },
168
+ { immediate: true },
169
+ );
170
+ subscribing = false;
171
+ const timer = setInterval(() => registry.refresh(atom), RUN_POLL_MS);
172
+ return () => {
173
+ clearInterval(timer);
174
+ unsubscribe();
175
+ };
176
}
apps/web/src/components/pullRequest/guide/guideRunStore.ts
+12
-8
@@ -1,6 +1,8 @@
1
import type { EnvironmentId, PullRequestRef } from "@t3tools/contracts";
2
import { create } from "zustand";
3
4
+import type { PullRequestDetailTab } from "~/rightPanelStore";
5
+
6
import { pullRequestReviewKey } from "../pullRequestReviewStore";
7
8
export interface GuideRunWatch {
@@ -10,6 +12,11 @@ export interface GuideRunWatch {
12
readonly previousGuideAt: string | null;
13
readonly previousFailedAt: string | null;
14
readonly since: number;
15
+ /**
16
+ * Registered from a server answer that reports the run as Running. The guide atom still holds
17
+ * the previous answer then, and its outcome belongs to an earlier run.
18
+ */
19
+ readonly answeredRunning?: boolean;
20
}
21
22
export interface GuideProgress {
@@ -21,14 +28,13 @@ const NO_PROGRESS: GuideProgress = { position: 0, seen: new Set() };
28
29
interface GuideRunStoreState {
30
readonly watches: Readonly<Record<string, GuideRunWatch>>;
24
- readonly shownKey: string | null;
25
- readonly openRequestKey: string | null;
31
+ /** The tab the pull requests page shows, for the pull request (run key) it was chosen on. */
32
+ readonly pageDetailTab: { readonly key: string; readonly tab: PullRequestDetailTab } | null;
33
readonly progress: Readonly<Record<string, GuideProgress>>;
34
readonly setProgress: (key: string, change: (current: GuideProgress) => GuideProgress) => void;
35
readonly watch: (watch: GuideRunWatch) => void;
36
readonly settle: (key: string) => void;
30
- readonly setShown: (key: string | null) => void;
31
- readonly requestOpen: (key: string | null) => void;
37
+ readonly showPageDetailTab: (key: string, tab: PullRequestDetailTab) => void;
38
}
39
40
export function guideRunKey(environmentId: EnvironmentId, reference: PullRequestRef): string {
@@ -37,8 +43,7 @@ export function guideRunKey(environmentId: EnvironmentId, reference: PullRequest
43
44
export const useGuideRunStore = create<GuideRunStoreState>()((set) => ({
45
watches: {},
40
- shownKey: null,
41
- openRequestKey: null,
46
+ pageDetailTab: null,
47
progress: {},
48
setProgress: (key, change) =>
49
set((state) => ({
@@ -56,8 +61,7 @@ export const useGuideRunStore = create<GuideRunStoreState>()((set) => ({
61
const { [key]: _settled, ...watches } = state.watches;
62
return { watches };
63
}),
59
- setShown: (shownKey) => set({ shownKey }),
60
- requestOpen: (openRequestKey) => set({ openRequestKey }),
64
+ showPageDetailTab: (key, tab) => set({ pageDetailTab: { key, tab } }),
65
}));
66
67
export function guideProgressKey(runKey: string, headSha: string): string {
apps/web/src/components/pullRequest/guide/useReviewGuideWriter.ts
+6
-12
@@ -1,7 +1,7 @@
1
import type { EnvironmentId, PullRequestRef } from "@t3tools/contracts";
2
import { squashAtomCommandFailure } from "@t3tools/client-runtime/state/runtime";
3
import { useAtomValue } from "@effect/atom-react";
4
-import { useEffect, useEffectEvent, useState } from "react";
4
+import { useState } from "react";
5
6
import { pullRequestEnvironment } from "~/state/pullRequests";
7
import { useEnvironmentQuery } from "~/state/query";
@@ -33,7 +33,10 @@ export function useReviewGuideWriter({
33
const data = query.data;
34
const running = starting || data?.run?._tag === "Running";
35
36
- const watchRun = useEffectEvent(() =>
36
+ // A run reported by the server is watched where its answer lands (state/pullRequests.ts).
37
+ const write = async () => {
38
+ if (running) return;
39
+ setStarting(true);
40
useGuideRunStore.getState().watch({
41
environmentId,
42
reference,
@@ -41,16 +44,7 @@ export function useReviewGuideWriter({
44
previousGuideAt: data?.guide?.generatedAt ?? null,
45
previousFailedAt: data?.run?._tag === "Failed" ? data.run.failedAt : null,
46
since: Date.now(),
44
- }),
45
- );
46
- useEffect(() => {
47
- if (data?.run?._tag === "Running") watchRun();
48
- }, [data?.run?._tag]);
49
-
50
- const write = async () => {
51
- if (running) return;
52
- setStarting(true);
53
- watchRun();
47
+ });
48
const result = await generate({ environmentId, input: reference });
49
setStarting(false);
50
if (result._tag === "Failure") {
apps/web/src/routes/__root.tsx
-2
@@ -31,7 +31,6 @@ import { DesktopWebLinkCoordinator } from "../components/desktop/DesktopWebLinkC
31
import { RunningThreadKeepAlive } from "../components/desktop/RunningThreadKeepAlive";
32
import { ReopenClosedViewShortcut } from "../components/ReopenClosedViewShortcut";
33
import { ProjectCloneToastCoordinator } from "../components/ProjectCloneToastCoordinator";
34
-import { PullRequestGuideRunCoordinator } from "../components/pullRequest/guide/PullRequestGuideRunCoordinator";
34
import { SlowRpcRequestToastCoordinator } from "../components/SlowRpcRequestToastCoordinator";
35
import { ChatGptWelcomeCoordinator } from "../components/settings/ChatGptWelcomeCoordinator";
36
import { ThemeEditorHost } from "../components/settings/ThemeEditorHost";
@@ -245,7 +244,6 @@ function RootRouteBranch() {
244
<SlowRpcRequestToastCoordinator />
245
<ProjectCloneToastCoordinator />
246
<AddProjectToMachineDialogHost />
248
- <PullRequestGuideRunCoordinator />
247
<HostedStaticEnvironmentBootstrap />
248
{primaryEnvironmentAuthenticated ? (
249
<EventRouter skipInitialBootstrapNavigation={returningFromWelcome} />
apps/web/src/state/pullRequests.ts
+26
@@ -37,6 +37,7 @@ import {
37
} from "../components/pullRequest/pullRequestList.logic";
38
import { writePullRequestDetailSnapshot } from "../components/pullRequest/pullRequestDetail.logic";
39
import { pullRequestChecksState } from "../components/pullRequest/pullRequestPresentation";
40
+import { useGuideRunStore } from "../components/pullRequest/guide/guideRunStore";
41
import { formatEnvironmentQueryError } from "./query";
42
import { environmentThreadShells } from "./threads";
43
@@ -403,6 +404,20 @@ export const pullRequestEnvironment = createPullRequestEnvironmentAtoms(connecti
404
}),
405
);
406
}),
407
+ // Covers runs started elsewhere (another client, an agent) as well as this client's own.
408
+ reviewGuide: ({ environmentId, input }, guide) =>
409
+ Effect.map(Clock.currentTimeMillis, (since) => {
410
+ if (guide.run?._tag !== "Running") return;
411
+ useGuideRunStore.getState().watch({
412
+ environmentId,
413
+ reference: input,
414
+ title: null,
415
+ previousGuideAt: guide.guide?.generatedAt ?? null,
416
+ previousFailedAt: null,
417
+ since,
418
+ answeredRunning: true,
419
+ });
420
+ }),
421
});
422
423
export const linkedPullRequestDetailAtom = createLinkedPullRequestSummaryAtomFamily(
@@ -467,6 +482,17 @@ const savedPullRequestSummaryAtom = Atom.family((key: string) =>
482
),
483
);
484
485
+export function observedPullRequestTitle(
486
+ registry: AtomRegistry.AtomRegistry,
487
+ environmentId: EnvironmentId,
488
+ reference: PullRequestRef,
489
+): string | null {
490
+ return (
491
+ registry.get(pullRequestObservationsAtom(pullRequestSummaryKey(environmentId, reference)))
492
+ .metadata?.summary.title ?? null
493
+ );
494
+}
495
+
496
/** The newest of every list, detail, checks and linked-summary answer and the thread's saved link. */
497
export function useSharedPullRequestSummary(
498
environmentId: EnvironmentId | null,
packages/client-runtime/src/state/pullRequests.ts
+2
@@ -146,6 +146,7 @@ export interface PullRequestAnswerHandlers {
146
readonly list?: QueryAnswerHandler<PullRequestListInput, PullRequestListResult>;
147
readonly detail?: QueryAnswerHandler<PullRequestRef, PullRequestDetail>;
148
readonly checks?: QueryAnswerHandler<PullRequestRef, PullRequestChecks | null>;
149
+ readonly reviewGuide?: QueryAnswerHandler<PullRequestRef, PullRequestReviewGuideResult>;
150
}
151
152
export function createPullRequestStackAtomFamily<R, E>(
@@ -251,6 +252,7 @@ export function createPullRequestEnvironmentAtoms<R, E>(
252
execute: (input) => routedRequest(WS_METHODS.pullRequestsReviewGuide, input),
253
staleTimeMs: 60_000,
254
refreshTrigger: ({ environmentId }) => refreshes({ environmentId, input: {} }),
255
+ ...(onAnswer.reviewGuide === undefined ? {} : { onAnswer: onAnswer.reviewGuide }),
256
}),
257
);
258
const reviewerCandidates = writableQueryFamily(