open-swe/ui/src/routes/review.tsx
Adam Moussa 589cd236c6
chore: cherry-pick clean upstream fixes + cherry-pick runbook (#117)
* fix: make plan view mobile friendly (#1636)

Co-authored-by: open-swe[bot] <open-swe@users.noreply.github.com>
(cherry picked from commit 7ee3e05724)

* fix: return to thread after plan approval (#1637)

Co-authored-by: Ramon Nogueira <270434257+ramon-langchain@users.noreply.github.com>
Co-authored-by: open-swe[bot] <open-swe@users.noreply.github.com>
(cherry picked from commit f32e492ab4)

* feat: reviews block agenda, sticky headers, accurate diff scroll (#1653)

Rework the AI-sorted blocks experience on the PR reviews page into a
Google-Docs-style outline: the left sidebar is now a clean number+title
agenda with scroll-spy highlighting of the active block; each block shows
its title + description (sticky) above its diff; and diff rows are pinned to
a uniform height so scroll-to lands precisely via the virtualizer's own
geometry instead of an estimate-driven correction loop.

Co-authored-by: open-swe[bot] <open-swe@users.noreply.github.com>
(cherry picked from commit 0b76afdc955e33805c7623d1502a75a9c7c9c1b7)

* fix: jump + ResizeObserver settle for review scroll-to (#1655)

Replace smooth-scroll plus frame-count correction loops on the PR
reviews page with an instant jump that re-asserts its target via a
ResizeObserver (the real "layout settled" signal). Block/file
navigation and finding/comment centering now land deterministically as
off-screen cards mount, files expand, and annotation cards measure,
instead of racing a smooth-scroll animation against height
reconciliation. Holds bail on user wheel/touch input and after a short
ceiling, and a new navigation cancels the previous hold.

Co-authored-by: open-swe[bot] <open-swe@users.noreply.github.com>
Co-authored-by: Johannes du Plessis <johannes@langchain.dev>
(cherry picked from commit 7530653bba7774d66a54b8bef0d2bbc25f519942)

* fix: purge expired thread_wakeup crons (#1656)

* fix: purge expired thread_wakeup crons

One-shot wakeup crons set an end_time that stops re-firing but the cron
row is never deleted, so dead rows accumulate (86 in prod). Add a purge
that deletes thread_wakeup crons past their end_time, called
opportunistically before scheduling a new wakeup, plus a one-time
backfill script. Conservative: matches only kind=thread_wakeup with a
past end_time.

* chore: retrigger Open SWE review

---------

Co-authored-by: open-swe[bot] <open-swe@users.noreply.github.com>
(cherry picked from commit 9e5a1924ef306269322c31342a1831e57831cfee)

* fix: add top padding to sticky review block header (#1660)

* fix: add top padding to sticky review block header

The sticky per-block header on the reviews page had padding below but
none above, so the block number badge sat glued against the top edge
when pinned. Add matching top padding for breathing room.

Co-authored-by: open-swe[bot] <open-swe@users.noreply.github.com>

* chore: use py-2 shorthand for review block header padding

Co-authored-by: open-swe[bot] <open-swe@users.noreply.github.com>

---------

Co-authored-by: open-swe[bot] <open-swe@users.noreply.github.com>
(cherry picked from commit 23bd4a63fc5ba0fe853babf79ed33feb866cc8b2)

* fix: use global tokens for sidebar filter popover border (#1661)

The filter popover renders via base-ui Menu.Portal into document.body,
outside the .agents-ui container where the --ui-* CSS variables are
scoped. As a result border-[var(--ui-border)] resolved to an undefined
variable and border-color fell back to currentColor, producing a strong
near-black border (separators/hover/labels were similarly off).

Switch the portaled popup styling to the same global shadcn tokens the
theme/settings popover (SidebarUserMenu) already uses (border-border,
bg-border, bg-muted, text-muted-foreground). These are defined at :root
so they resolve inside portals too, and match the settings popover.

Co-authored-by: open-swe[bot] <open-swe@users.noreply.github.com>
(cherry picked from commit 63eb9a08209f683016abf01cdcc548bc5905f158)

* fix: preserve dashboard redirect after login (#1668)

* fix: preserve dashboard redirect after login

Co-authored-by: open-swe[bot] <open-swe@users.noreply.github.com>

* test: cover plan login redirect in e2e

Co-authored-by: open-swe[bot] <open-swe@users.noreply.github.com>

---------

Co-authored-by: Ramon Nogueira <270434257+ramon-langchain@users.noreply.github.com>
Co-authored-by: open-swe[bot] <open-swe@users.noreply.github.com>
(cherry picked from commit bc7ce59169b5350da7286164afb83a7b037b528d)

* Disable React StrictMode (#1654)

Co-authored-by: open-swe[bot] <open-swe@users.noreply.github.com>
(cherry picked from commit 6575c327a3ac2b107a6e79a04fa61168d779dbf0)

* docs(upstream-sync): add cherry-pick runbook

Repo-specific runbook for bringing upstream (langchain-ai/open-swe) commits
into the fork: triage-sync discovery, the git cp workflow, the triage ledger,
themed-branch layout, and conflict/regression handling.

---------

Co-authored-by: Johannes du Plessis <johannes@langchain.dev>
Co-authored-by: open-swe[bot] <open-swe@users.noreply.github.com>
Co-authored-by: Ramon Nogueira <ramon.nogueira@langchain.dev>
Co-authored-by: Ramon Nogueira <270434257+ramon-langchain@users.noreply.github.com>
Co-authored-by: Caroline di Vittorio <43390382+carolinedivittorio@users.noreply.github.com>
2026-07-03 11:48:40 -04:00

277 lines
9.4 KiB
TypeScript

import { Link, createFileRoute } from "@tanstack/react-router";
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
import { CaretRightIcon } from "@phosphor-icons/react";
import { useEffect, useMemo, useState } from "react";
import { IoLogoGithub } from "react-icons/io5";
import type { ReposPayload, TeamSettings } from "@/lib/api";
import { AppShell, SettingsRow, SettingsSection } from "@/components/AppShell";
import { Button } from "@/components/ui/button";
import { Skeleton } from "@/components/ui/skeleton";
import { Switch } from "@/components/ui/switch";
import { Textarea } from "@/components/ui/textarea";
import { ApiError, api } from "@/lib/api";
import { RequireLogin } from "@/lib/auth-redirect";
import { useSession } from "@/lib/session";
export const Route = createFileRoute("/review")({ component: ReviewPage });
const DEFAULT_SETTINGS: TeamSettings = {
review_draft_prs: false,
pr_summaries: true,
review_trace_links: true,
review_tracing_project: null,
org_guidelines: null,
default_agent_model: null,
default_agent_reasoning_effort: null,
default_agent_subagent_model: null,
default_agent_subagent_reasoning_effort: null,
default_reviewer_model: null,
default_reviewer_reasoning_effort: null,
default_reviewer_subagent_model: null,
default_reviewer_subagent_reasoning_effort: null,
};
function ReviewPage() {
const session = useSession();
const qc = useQueryClient();
const settings = useQuery({
queryKey: ["teamSettings"],
queryFn: api.getTeamSettings,
enabled: !!session.data,
});
const [local, setLocal] = useState<TeamSettings>(DEFAULT_SETTINGS);
const [guidelinesDraft, setGuidelinesDraft] = useState("");
const [error, setError] = useState<string | null>(null);
useEffect(() => {
if (settings.data) {
setLocal(settings.data);
setGuidelinesDraft(settings.data.org_guidelines ?? "");
}
}, [settings.data]);
const save = useMutation({
mutationFn: (body: TeamSettings) => api.saveTeamSettings(body),
onSuccess: (saved) => {
qc.setQueryData(["teamSettings"], saved);
setError(null);
},
onError: (e: Error) => setError(e.message),
});
if (session.isLoading) {
return (
<main className="p-6">
<Skeleton className="h-64 w-full" />
</main>
);
}
if (!session.data) return <RequireLogin />;
const current: TeamSettings = local;
const canEdit = session.data.is_admin;
const persist = (patch: Partial<TeamSettings>) => {
const next: TeamSettings = { ...current, ...patch };
setLocal(next);
if (canEdit) save.mutate(next);
};
const trimmedGuidelines = guidelinesDraft.trim();
const savedGuidelines = current.org_guidelines ?? "";
const guidelinesDirty = trimmedGuidelines !== savedGuidelines.trim();
const saveGuidelines = () => {
if (!canEdit) return;
persist({ org_guidelines: trimmedGuidelines || null });
};
return (
<AppShell
user={session.data}
title="Open SWE Review"
description="Automatically review pull requests for bugs and issues. Runs are billed based on underlying agent usage."
>
<RepositoriesSection canEdit={canEdit} />
<SettingsSection title="Rules">
<Link
to="/review/styles"
className="flex items-center justify-between gap-6 px-4 py-3 hover:bg-muted/40"
>
<div className="flex flex-col gap-0.5">
<span className="text-xs font-medium text-foreground">Review Style Prompts</span>
<span className="text-xs text-muted-foreground">
Per-repo style guides learned from past PR review feedback.
</span>
</div>
<CaretRightIcon className="size-3.5 shrink-0 text-muted-foreground" />
</Link>
</SettingsSection>
<SettingsSection
title="Organization Guidelines"
description="Org-wide instructions injected into every review, across all repositories. Repository-specific style prompts take precedence when they conflict."
>
<div className="flex flex-col gap-2 p-4">
<Textarea
className="min-h-[200px] w-full font-mono text-xs"
value={guidelinesDraft}
onChange={(e) => setGuidelinesDraft(e.target.value)}
placeholder="e.g. Always flag missing input validation on new API endpoints. Prefer structured logging over print statements."
disabled={!canEdit}
/>
{canEdit && (
<div className="flex items-center gap-2">
<Button
size="sm"
disabled={!guidelinesDirty || save.isPending}
onClick={saveGuidelines}
>
Save guidelines
</Button>
{guidelinesDirty && (
<span className="text-xs text-muted-foreground">Unsaved changes</span>
)}
</div>
)}
</div>
</SettingsSection>
<SettingsSection title="Configuration">
<div className="divide-y divide-border">
<SettingsRow
label="Review Draft PRs"
description="Org-wide default for whether Open SWE Review runs on draft PRs. Each user can override this in Profile Settings."
control={
<Switch
checked={current.review_draft_prs}
onCheckedChange={(v) => persist({ review_draft_prs: v })}
disabled={!canEdit}
/>
}
/>
<SettingsRow
label="PR Summaries"
description="Generate descriptions on pull requests"
control={
<Switch
checked={current.pr_summaries}
onCheckedChange={(v) => persist({ pr_summaries: v })}
disabled={!canEdit}
/>
}
/>
<SettingsRow
label="Trace Links"
description="Include a LangSmith trace link in each review comment. Only members of your LangSmith workspace can open it."
control={
<Switch
checked={current.review_trace_links}
onCheckedChange={(v) => persist({ review_trace_links: v })}
disabled={!canEdit}
/>
}
/>
</div>
</SettingsSection>
{!canEdit && (
<p className="text-xs text-muted-foreground">
These settings are read-only. Ask a workspace admin to change them.
</p>
)}
{error && <p className="text-xs text-destructive">{error}</p>}
</AppShell>
);
}
function RepositoriesSection({ canEdit: _canEdit }: { canEdit: boolean }) {
const repos = useQuery<ReposPayload>({
queryKey: ["repos"],
queryFn: async () => {
try {
return await api.repos();
} catch (e) {
if (e instanceof ApiError && e.status === 401)
return { installations: [], repositories: [] };
throw e;
}
},
});
const enabled = useQuery({
queryKey: ["enabledReviewRepos"],
queryFn: api.listEnabledReviewRepos,
});
const enabledSet = useMemo(
() => new Set(enabled.data?.repos ?? []),
[enabled.data?.repos],
);
const grouped = useMemo(() => {
const byOwner = new Map<string, Array<{ full_name: string; private: boolean }>>();
for (const r of repos.data?.repositories ?? []) {
const [owner] = r.full_name.split("/");
if (!owner) continue;
const arr = byOwner.get(owner) ?? [];
arr.push(r);
byOwner.set(owner, arr);
}
return Array.from(byOwner.entries()).sort(([a], [b]) => a.localeCompare(b));
}, [repos.data?.repositories]);
const loading = repos.isLoading || enabled.isLoading;
return (
<SettingsSection
title="Repositories"
description="Source-control installations. Click into one to enable repos for automatic review."
>
<div className="divide-y divide-border">
{loading && (
<div className="p-4">
<Skeleton className="h-16 w-full" />
</div>
)}
{!loading && grouped.length === 0 && (
<p className="px-4 py-3 text-xs text-muted-foreground">
No GitHub App installations found. Install the open-swe GitHub App on an
account or org to manage repos here.
</p>
)}
{grouped.map(([owner, list]) => {
const enabledCount = list.filter((r) => enabledSet.has(r.full_name)).length;
return (
<Link
key={owner}
to="/review/repositories/$owner"
params={{ owner }}
className="flex items-center justify-between gap-4 px-4 py-3 hover:bg-muted/40"
>
<div className="flex items-center gap-3">
<IoLogoGithub className="size-5 shrink-0 text-muted-foreground" />
<div className="flex flex-col gap-0.5">
<div className="flex items-center gap-2 text-xs">
<span className="font-medium text-foreground">{owner}</span>
</div>
<span className="text-xs text-muted-foreground">GitHub</span>
</div>
</div>
<div className="flex items-center gap-2 text-xs text-muted-foreground">
<span>
{enabledCount}/{list.length} Repositories Enabled
</span>
<CaretRightIcon className="size-3.5" />
</div>
</Link>
);
})}
</div>
</SettingsSection>
);
}