From dc66ff1d5ce54c01433cd7e8599fac74c844c65a Mon Sep 17 00:00:00 2001 From: Theo Browne Date: Thu, 23 Jul 2026 19:38:32 -0700 Subject: [PATCH] Add pre-run confirmation screen to review sweep The sidebar button now only navigates to /review-sweep; the sweep no longer auto-starts. The idle screen shows exactly what a run will do before any model call happens: how many threads will be reviewed (and how many the cap would skip), which text-generation model each environment's server will use, and a cost/latency heads-up when the run is large (15+ threads). Starting requires an explicit click. Co-Authored-By: Claude Fable 5 --- apps/web/src/components/SidebarV2.tsx | 4 +- .../reviewSweep/ReviewSweepView.tsx | 159 +++++++++++++----- apps/web/src/reviewSweepStore.ts | 30 +++- 3 files changed, 146 insertions(+), 47 deletions(-) diff --git a/apps/web/src/components/SidebarV2.tsx b/apps/web/src/components/SidebarV2.tsx index f75bd52a8c..677b4cab66 100644 --- a/apps/web/src/components/SidebarV2.tsx +++ b/apps/web/src/components/SidebarV2.tsx @@ -71,7 +71,6 @@ import { type SidebarProjectGroupMember, type SidebarProjectSnapshot, } from "../sidebarProjectGrouping"; -import { startReviewSweep } from "../reviewSweepStore"; import { legacyProjectCwdPreferenceKey, useUiStateStore } from "../uiStateStore"; import { useThreadSelectionStore } from "../threadSelectionStore"; import { useThreadActions } from "../hooks/useThreadActions"; @@ -1741,9 +1740,10 @@ export default function SidebarV2() { openCommandPalette({ open: "new-thread-in" }); }, [isMobile, newThreadContext, projectGroups.length, setOpenMobile]); + // Navigate only โ€” the review-sweep page shows a pre-run summary (thread + // count + models that will be used) and the sweep starts on explicit click. const handleReviewSweepClick = useCallback(() => { if (isMobile) setOpenMobile(false); - startReviewSweep(); void router.navigate({ to: "/review-sweep" }); }, [isMobile, router, setOpenMobile]); diff --git a/apps/web/src/components/reviewSweep/ReviewSweepView.tsx b/apps/web/src/components/reviewSweep/ReviewSweepView.tsx index 1e44beeefe..0986e3b882 100644 --- a/apps/web/src/components/reviewSweep/ReviewSweepView.tsx +++ b/apps/web/src/components/reviewSweep/ReviewSweepView.tsx @@ -11,12 +11,15 @@ import { applySweepSettle, applySweepTitle, dismissSweepItem, + isSweepCandidate, retrySweepItem, startReviewSweep, + SWEEP_MAX_THREADS, useReviewSweepStore, type SweepItem, } from "../../reviewSweepStore"; -import { useProjects } from "../../state/entities"; +import { useClientSettings } from "../../hooks/useSettings"; +import { useProjects, useServerConfigs, useThreadShells } from "../../state/entities"; import { buildThreadRouteParams } from "../../threadRoutes"; import { Badge } from "../ui/badge"; import { Button } from "../ui/button"; @@ -142,6 +145,94 @@ function SweepItemCard({ item }: { item: SweepItem }) { ); } +/** Cost-transparency threshold: at or above this many candidate threads the + pre-run screen calls out that the sweep may be slow/expensive. */ +const SWEEP_COST_NOTE_THRESHOLD = 15; + +/** Pre-run summary: how many threads a sweep would cover and which model + each environment's server will use, so starting is an informed choice. */ +function SweepPreRunSummary() { + const shells = useThreadShells(); + const serverConfigs = useServerConfigs(); + const autoSettleAfterDays = useClientSettings((settings) => settings.sidebarAutoSettleAfterDays); + + const { candidateCount, modelsByEnvironment } = useMemo(() => { + const now = new Date().toISOString(); + let count = 0; + const models = new Map(); + for (const shell of shells) { + const config = serverConfigs.get(shell.environmentId); + if (!isSweepCandidate(shell, config?.environment.capabilities, { now, autoSettleAfterDays })) + continue; + count += 1; + const selection = config?.settings.textGenerationModelSelection; + const entry = models.get(shell.environmentId); + if (entry) { + entry.threads += 1; + } else { + models.set(shell.environmentId, { + label: config?.environment.label ?? shell.environmentId, + model: selection ? `${selection.model}` : "server default", + threads: 1, + }); + } + } + return { candidateCount: count, modelsByEnvironment: [...models.values()] }; + }, [autoSettleAfterDays, serverConfigs, shells]); + + const reviewedCount = Math.min(candidateCount, SWEEP_MAX_THREADS); + + if (candidateCount === 0) { + return ( + + + All caught up + No unsettled threads to review right now. + + + ); + } + + return ( + + + Review your in-progress work + + This sweep runs one AI review per thread to summarize it, catch stale titles, and find + threads ready to settle. Nothing is applied without your click. + + +
+
+ {reviewedCount}{" "} + {reviewedCount === 1 ? "thread" : "threads"} will be reviewed + {candidateCount > SWEEP_MAX_THREADS + ? ` (${candidateCount - SWEEP_MAX_THREADS} least-recently-active skipped)` + : ""} +
+ {modelsByEnvironment.map((entry) => ( +
+ {entry.label}: {entry.model} ยท {entry.threads}{" "} + {entry.threads === 1 ? "thread" : "threads"} +
+ ))} + {reviewedCount >= SWEEP_COST_NOTE_THRESHOLD ? ( +
+ Heads up: {reviewedCount} model calls may take a few minutes and use noticeable credits. + You can change the model under Settings โ†’ Models. +
+ ) : ( +
Model is configurable under Settings โ†’ Models (text generation).
+ )} +
+ +
+ ); +} + export function ReviewSweepView() { const phase = useReviewSweepStore((state) => state.phase); const order = useReviewSweepStore((state) => state.order); @@ -210,50 +301,42 @@ export function ReviewSweepView() { )} ) : null} -
- - -
+ {phase !== "idle" ? ( +
+ + +
+ ) : null}
- {visibleItems.length === 0 ? ( + {phase === "idle" ? ( + + ) : visibleItems.length === 0 ? ( - - {phase === "idle" ? "Review your in-progress work" : "All caught up"} - - - {phase === "idle" - ? "Run a sweep to summarize every unsettled thread, catch stale titles, and find threads ready to settle." - : "No unsettled threads to review right now."} - + All caught up + No unsettled threads to review right now. - {phase === "idle" ? ( - - ) : null} ) : (
diff --git a/apps/web/src/reviewSweepStore.ts b/apps/web/src/reviewSweepStore.ts index b98e81741a..d543ab1089 100644 --- a/apps/web/src/reviewSweepStore.ts +++ b/apps/web/src/reviewSweepStore.ts @@ -91,21 +91,37 @@ function readServerCapabilities(environmentId: EnvironmentId) { .capabilities; } +/** The sweep-eligibility predicate, mirroring SidebarV2's active-card + partition. Exported so the pre-run confirmation screen counts exactly + the threads a run would review. */ +export function isSweepCandidate( + shell: EnvironmentThreadShell, + capabilities: { threadSettlement?: boolean; reviewSweep?: boolean } | undefined, + options: { readonly now: string; readonly autoSettleAfterDays: number | null }, +): boolean { + if (shell.archivedAt !== null) return false; + if (capabilities?.threadSettlement !== true || capabilities.reviewSweep !== true) return false; + // PR state is owned by per-row VCS subscriptions in the sidebar and isn't + // readable here; passing null may include a few threads the sidebar shows + // as settled (merged PR + idle). Reviewing them is harmless. + return !effectiveSettled(shell, { + now: options.now, + autoSettleAfterDays: options.autoSettleAfterDays, + changeRequestState: null, + }); +} + /** All unsettled, unarchived threads across every connected environment that - supports the sweep, mirroring SidebarV2's active-card predicate. */ + supports the sweep. */ function collectSweepCandidates(): EnvironmentThreadShell[] { const now = new Date().toISOString(); const autoSettleAfterDays = getClientSettings().sidebarAutoSettleAfterDays; const candidates: EnvironmentThreadShell[] = []; for (const ref of readThreadRefs()) { const shell = readThreadShell(ref); - if (!shell || shell.archivedAt !== null) continue; + if (!shell) continue; const capabilities = readServerCapabilities(shell.environmentId); - if (capabilities?.threadSettlement !== true || capabilities.reviewSweep !== true) continue; - // PR state is owned by per-row VCS subscriptions in the sidebar and isn't - // readable here; passing null may include a few threads the sidebar shows - // as settled (merged PR + idle). Reviewing them is harmless. - if (effectiveSettled(shell, { now, autoSettleAfterDays, changeRequestState: null })) continue; + if (!isSweepCandidate(shell, capabilities, { now, autoSettleAfterDays })) continue; candidates.push(shell); } // Most recently active first, so the SWEEP_MAX_THREADS cap drops the