Background sweep, launch modal, PR investigation, and merge queue
Four features from real-data testing feedback: - The sidebar button now opens a launch modal (scope + model + cost summary) instead of navigating. Starting closes the modal and shows a "running in background" toast; completion raises a toast with an actionable-count summary and a "View results" link. The sweep was already navigation-proof; now the UX matches. - Reviews investigate deeper: when a thread's branch has a PR, the server fetches state, review decision, CI rollup, mergeability, and the last five comments via `gh pr view`, feeds them into the review prompt, and returns a prStatus with a computed mergeReady flag (open + clean merge + CI not failing + not blocked on review). Lookups degrade to "no PR context" on any failure. - New "Merge ready" bucket at the top of the results grid with per-card "Merge & settle" and a section-level "Merge all (N)". - Merging runs through a SEQUENTIAL queue: each PR is re-validated against live GitHub state before merging (an earlier queue entry may have just changed the base), merged PRs settle their thread immediately, and a conflict marks the card and hands the rebase to the thread's own agent via a turn message — the queue continues past it. review.mergePullRequest returns conflict/already-closed/not-ready as outcomes rather than errors so the queue can branch on them. Co-Authored-By: Claude Fable 5 <[email protected]>
This commit is contained in:
1 parent
ade848702d
commit
3e757bd28b
19 files changed
+1000
-15
No files matched your search
@@ -82,6 +82,7 @@ import {
|
||||
type SidebarProjectSnapshot,
|
||||
} from "../sidebarProjectGrouping";
|
||||
import { publishSweepChangeRequestStates } from "../reviewSweepStore";
|
||||
import { ReviewSweepLaunchDialog } from "./reviewSweep/ReviewSweepLaunchDialog";
|
||||
import { legacyProjectCwdPreferenceKey, useUiStateStore } from "../uiStateStore";
|
||||
import { useThreadSelectionStore } from "../threadSelectionStore";
|
||||
import { useThreadActions } from "../hooks/useThreadActions";
|
||||
@@ -2205,12 +2206,13 @@ 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.
|
||||
// Open the launch modal — the sweep itself runs in the background and
|
||||
// announces completion with a toast, so no navigation happens here.
|
||||
const [reviewSweepDialogOpen, setReviewSweepDialogOpen] = useState(false);
|
||||
const handleReviewSweepClick = useCallback(() => {
|
||||
if (isMobile) setOpenMobile(false);
|
||||
void router.navigate({ to: "/review-sweep" });
|
||||
}, [isMobile, router, setOpenMobile]);
|
||||
setReviewSweepDialogOpen(true);
|
||||
}, [isMobile, setOpenMobile]);
|
||||
|
||||
const commandPaletteShortcutLabel = shortcutLabelForCommand(keybindings, "commandPalette.toggle");
|
||||
// Same resolution as v1: prefer the local-thread binding, fall back to
|
||||
@@ -2221,6 +2223,10 @@ export default function SidebarV2() {
|
||||
return (
|
||||
<>
|
||||
<SidebarChromeHeader isElectron={isElectron} />
|
||||
<ReviewSweepLaunchDialog
|
||||
open={reviewSweepDialogOpen}
|
||||
onOpenChange={setReviewSweepDialogOpen}
|
||||
/>
|
||||
<SidebarContent className="gap-0">
|
||||
<SidebarGroup className="px-2 pb-2 pt-3">
|
||||
<div className="flex items-center gap-1">
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
import { useRouter } from "@tanstack/react-router";
|
||||
import { useEffect } from "react";
|
||||
|
||||
import { setSweepResultsNavigator, useReviewSweepStore } from "../../reviewSweepStore";
|
||||
import { stackedThreadToast, toastManager } from "../ui/toast";
|
||||
import { Dialog, DialogDescription, DialogHeader, DialogPopup, DialogTitle } from "../ui/dialog";
|
||||
import { SweepPreRunSummary } from "./ReviewSweepView";
|
||||
|
||||
/** Launch modal for the work-review sweep. The sweep itself runs in the
|
||||
background (module-level runner), so the modal just confirms scope/cost
|
||||
and closes; a toast announces completion with a link to the results. */
|
||||
export function ReviewSweepLaunchDialog({
|
||||
open,
|
||||
onOpenChange,
|
||||
}: {
|
||||
open: boolean;
|
||||
onOpenChange: (open: boolean) => void;
|
||||
}) {
|
||||
const router = useRouter();
|
||||
const phase = useReviewSweepStore((state) => state.phase);
|
||||
|
||||
// Install the navigator the store's completion toast uses. The dialog is
|
||||
// mounted for the sidebar's lifetime, so this stays registered.
|
||||
useEffect(() => {
|
||||
setSweepResultsNavigator(() => {
|
||||
void router.navigate({ to: "/review-sweep" });
|
||||
});
|
||||
return () => setSweepResultsNavigator(null);
|
||||
}, [router]);
|
||||
|
||||
const handleStarted = () => {
|
||||
onOpenChange(false);
|
||||
toastManager.add(
|
||||
stackedThreadToast({
|
||||
type: "info",
|
||||
title: "Reviewing your work in the background",
|
||||
description: "You'll get a notification when the results are ready.",
|
||||
actionVariant: "outline",
|
||||
actionProps: {
|
||||
children: "Watch progress",
|
||||
onClick: () => void router.navigate({ to: "/review-sweep" }),
|
||||
},
|
||||
}),
|
||||
);
|
||||
};
|
||||
|
||||
return (
|
||||
<Dialog open={open} onOpenChange={onOpenChange}>
|
||||
<DialogPopup className="max-w-lg">
|
||||
<DialogHeader>
|
||||
<DialogTitle>Review unsettled work</DialogTitle>
|
||||
<DialogDescription>
|
||||
{phase === "running"
|
||||
? "A review is already running — results will arrive as a notification."
|
||||
: "One AI review per unsettled thread, run in the background."}
|
||||
</DialogDescription>
|
||||
</DialogHeader>
|
||||
{phase === "running" ? null : <SweepPreRunSummary onStarted={handleStarted} />}
|
||||
</DialogPopup>
|
||||
</Dialog>
|
||||
);
|
||||
}
|
||||
@@ -8,6 +8,7 @@ import {
|
||||
ArchiveIcon,
|
||||
ArrowRightIcon,
|
||||
CircleAlertIcon,
|
||||
GitMergeIcon,
|
||||
InfoIcon,
|
||||
ListChecksIcon,
|
||||
LoaderIcon,
|
||||
@@ -26,7 +27,9 @@ import {
|
||||
applySweepTitle,
|
||||
dismissSweepItem,
|
||||
isSweepCandidate,
|
||||
mergeSweepItem,
|
||||
retrySweepItem,
|
||||
runMergeQueue,
|
||||
sortSweepCandidates,
|
||||
startReviewSweep,
|
||||
SWEEP_MAX_THREADS,
|
||||
@@ -56,9 +59,17 @@ import { Tooltip, TooltipPopup, TooltipProvider, TooltipTrigger } from "../ui/to
|
||||
// reading, then no-action-possible tails.
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
type SweepBucket = "settle" | "title" | "attention" | "inFlight" | "failed" | "reviewing";
|
||||
type SweepBucket =
|
||||
| "mergeReady"
|
||||
| "settle"
|
||||
| "title"
|
||||
| "attention"
|
||||
| "inFlight"
|
||||
| "failed"
|
||||
| "reviewing";
|
||||
|
||||
const BUCKET_ORDER: readonly SweepBucket[] = [
|
||||
"mergeReady",
|
||||
"settle",
|
||||
"title",
|
||||
"attention",
|
||||
@@ -71,6 +82,12 @@ const BUCKET_META: Record<
|
||||
SweepBucket,
|
||||
{ title: string; hint: string; accent: string; icon: typeof ArchiveIcon }
|
||||
> = {
|
||||
mergeReady: {
|
||||
title: "Merge ready",
|
||||
hint: "Open PRs with green CI, approvals, and clean merges.",
|
||||
accent: "border-s-violet-500/70",
|
||||
icon: GitMergeIcon,
|
||||
},
|
||||
settle: {
|
||||
title: "Ready to settle",
|
||||
hint: "Work concluded — one click clears each from your active list.",
|
||||
@@ -112,6 +129,10 @@ const BUCKET_META: Record<
|
||||
function classifySweepItem(item: SweepItem): SweepBucket {
|
||||
if (item.status === "error") return "failed";
|
||||
if (item.status !== "done" || item.result === null) return "reviewing";
|
||||
// Merge-ready wins over everything: it's the highest-leverage one-click.
|
||||
// Items stay in the bucket through the queue lifecycle (queued → merging
|
||||
// → merged/conflicted) so progress is visible in place.
|
||||
if (item.result.prStatus?.mergeReady && !item.settleApplied) return "mergeReady";
|
||||
if (item.result.recommendSettle && !item.settleApplied) return "settle";
|
||||
if (item.result.suggestedTitle && !item.titleApplied) return "title";
|
||||
// Live shell wins over review-time knowledge: a thread blocked on the user
|
||||
@@ -165,12 +186,44 @@ function SweepItemMetaRow({
|
||||
{item.branch}
|
||||
</span>
|
||||
) : null}
|
||||
{item.result?.prStatus ? (
|
||||
<a
|
||||
href={item.result.prStatus.url}
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
className="shrink-0 font-mono text-[11px] text-muted-foreground hover:text-foreground hover:underline"
|
||||
>
|
||||
#{item.result.prStatus.number}
|
||||
</a>
|
||||
) : null}
|
||||
{age ? <span className="shrink-0">{age}</span> : null}
|
||||
<DiffStatsLabel item={item} />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function MergeStatusBadge({ item }: { item: SweepItem }) {
|
||||
switch (item.mergeStatus) {
|
||||
case "queued":
|
||||
return <Badge variant="secondary">Queued</Badge>;
|
||||
case "merging":
|
||||
return (
|
||||
<Badge variant="info">
|
||||
<Spinner className="me-1 size-3" />
|
||||
Merging
|
||||
</Badge>
|
||||
);
|
||||
case "merged":
|
||||
return <Badge variant="success">Merged</Badge>;
|
||||
case "conflicted":
|
||||
return <Badge variant="warning">Conflict — agent rebasing</Badge>;
|
||||
case "failed":
|
||||
return <Badge variant="error">Merge failed</Badge>;
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
function SweepItemCard({
|
||||
item,
|
||||
bucket,
|
||||
@@ -188,7 +241,23 @@ function SweepItemCard({
|
||||
const meta = BUCKET_META[bucket];
|
||||
|
||||
const primaryAction =
|
||||
bucket === "settle" ? (
|
||||
bucket === "mergeReady" ? (
|
||||
item.mergeStatus === "idle" || item.mergeStatus === "failed" ? (
|
||||
<Button
|
||||
size="xs"
|
||||
variant="outline"
|
||||
className="shrink-0"
|
||||
disabled={applying}
|
||||
onClick={() => {
|
||||
setApplying(true);
|
||||
void mergeSweepItem(key).finally(() => setApplying(false));
|
||||
}}
|
||||
>
|
||||
<GitMergeIcon className="me-1 size-3.5" />
|
||||
Merge & settle
|
||||
</Button>
|
||||
) : null
|
||||
) : bucket === "settle" ? (
|
||||
<Button
|
||||
size="xs"
|
||||
variant="outline"
|
||||
@@ -246,6 +315,7 @@ function SweepItemCard({
|
||||
{bucket === "settle" && item.settleApplied ? (
|
||||
<Badge variant="outline">Settled</Badge>
|
||||
) : null}
|
||||
{bucket === "mergeReady" ? <MergeStatusBadge item={item} /> : null}
|
||||
<div className="ms-auto flex shrink-0 items-center gap-1">
|
||||
{result?.summary ? (
|
||||
<Tooltip>
|
||||
@@ -282,6 +352,8 @@ function SweepItemCard({
|
||||
|
||||
{item.status === "error" ? (
|
||||
<p className="line-clamp-2 text-sm text-red-400/90">{item.errorMessage}</p>
|
||||
) : item.mergeStatus === "conflicted" || item.mergeStatus === "failed" ? (
|
||||
<p className="line-clamp-2 text-sm text-warning-foreground">{item.mergeDetail}</p>
|
||||
) : nextStep ? (
|
||||
<p className="line-clamp-2 text-sm text-foreground/90">{nextStep}</p>
|
||||
) : null}
|
||||
@@ -313,8 +385,10 @@ function SweepItemCard({
|
||||
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() {
|
||||
each environment's server will use, so starting is an informed choice.
|
||||
Rendered on the idle /review-sweep page and inside the sidebar's launch
|
||||
modal. `onStarted` lets the modal close itself when the sweep kicks off. */
|
||||
export function SweepPreRunSummary({ onStarted }: { onStarted?: () => void } = {}) {
|
||||
const shells = useThreadShells();
|
||||
const serverConfigs = useServerConfigs();
|
||||
const autoSettleAfterDays = useClientSettings((settings) => settings.sidebarAutoSettleAfterDays);
|
||||
@@ -405,7 +479,13 @@ function SweepPreRunSummary() {
|
||||
<div>Model is configurable under Settings → Models (text generation).</div>
|
||||
)}
|
||||
</div>
|
||||
<Button size="sm" onClick={() => startReviewSweep()}>
|
||||
<Button
|
||||
size="sm"
|
||||
onClick={() => {
|
||||
startReviewSweep();
|
||||
onStarted?.();
|
||||
}}
|
||||
>
|
||||
<ListChecksIcon className="me-1.5 size-4" />
|
||||
Review {reviewedCount} {reviewedCount === 1 ? "thread" : "threads"}
|
||||
</Button>
|
||||
@@ -479,6 +559,7 @@ export function ReviewSweepView() {
|
||||
).length;
|
||||
const running = phase === "running";
|
||||
const [applyingAll, setApplyingAll] = useState(false);
|
||||
const [mergingAll, setMergingAll] = useState(false);
|
||||
|
||||
return (
|
||||
<SidebarInset className="h-dvh min-h-0 overflow-hidden overscroll-y-none bg-background text-foreground isolate">
|
||||
@@ -564,6 +645,12 @@ export function ReviewSweepView() {
|
||||
{buckets.map(([bucket, bucketItems]) => {
|
||||
const meta = BUCKET_META[bucket];
|
||||
const BucketIcon = meta.icon;
|
||||
const mergeableCount =
|
||||
bucket === "mergeReady"
|
||||
? bucketItems.filter(
|
||||
(item) => item.mergeStatus === "idle" || item.mergeStatus === "queued",
|
||||
).length
|
||||
: 0;
|
||||
return (
|
||||
<section key={bucket} className="flex flex-col gap-2">
|
||||
<div className="flex items-baseline gap-2">
|
||||
@@ -579,6 +666,21 @@ export function ReviewSweepView() {
|
||||
{meta.hint}
|
||||
</span>
|
||||
) : null}
|
||||
{bucket === "mergeReady" && mergeableCount > 0 ? (
|
||||
<Button
|
||||
size="xs"
|
||||
variant="outline"
|
||||
className="ms-auto shrink-0"
|
||||
disabled={mergingAll}
|
||||
onClick={() => {
|
||||
setMergingAll(true);
|
||||
void runMergeQueue().finally(() => setMergingAll(false));
|
||||
}}
|
||||
>
|
||||
<GitMergeIcon className="me-1 size-3.5" />
|
||||
Merge all ({mergeableCount})
|
||||
</Button>
|
||||
) : null}
|
||||
</div>
|
||||
<div className="grid grid-cols-1 gap-2.5 md:grid-cols-2 xl:grid-cols-3">
|
||||
{bucketItems.map((item) => {
|
||||
|
||||
Reference in new issue
Block a user