An open-source, faster Devin alternative
TypeScript
feat(web): move the CVE swarm grid onto a project /swarm page
Mohamed Habib via Computer456223a4ca20
diff --git a/web/src/App.tsx b/web/src/App.tsxindex 672af25d..d13ff811 100644--- a/web/src/App.tsx+++ b/web/src/App.tsx@@ -43,6 +43,9 @@ const ManagedTemplateNew = lazy(() => import('./managed-agents/TemplateNew'))const ManagedSecurityOnboarding = lazy(() => import('./managed-agents/security/SecurityOnboarding'),)+const ManagedProjectSwarm = lazy(+ () => import('./managed-agents/security/ProjectSwarm'),+)const ModelAccessCallback = lazy(() => import('./managed-agents/ModelAccessCallback'),)@@ -118,6 +121,10 @@ export default function App() {path="projects/:projectId/sessions/:sessionId"element={<ManagedSessionDetail />}/>+ <Route+ path="projects/:projectId/swarm"+ element={<ManagedProjectSwarm />}+ /><Routepath="projects/:projectId/:tab"element={<ManagedProjectDetail />}diff --git a/web/src/components/app-shell-nav.ts b/web/src/components/app-shell-nav.tsindex 109a273f..03694aca 100644--- a/web/src/components/app-shell-nav.ts+++ b/web/src/components/app-shell-nav.ts@@ -14,6 +14,7 @@ import {Monitor,Package,Plug,+ Radar,Rocket,Settings,Webhook,@@ -40,6 +41,7 @@ export function managedAgentsNav(options: {durableSessionsEnabled: booleaninfrastructureEnabled: booleancomputerEnabled?: boolean+ swarmEnabled?: boolean}): NavGroup[] {const groups: NavGroup[] = []@@ -57,6 +59,11 @@ export function managedAgentsNav(options: {},{items: [+ // Only CVE Swarm projects declare the findings resource, so the+ // Swarm grid is offered just for them.+ ...(options.swarmEnabled+ ? [{ to: `${projectPath}/swarm`, label: 'Swarm', icon: Radar }]+ : []),{to: `${projectPath}/deployments`,label: 'Deployments',diff --git a/web/src/components/app-shell.tsx b/web/src/components/app-shell.tsxindex 51b4eaee..bde97ae1 100644--- a/web/src/components/app-shell.tsx+++ b/web/src/components/app-shell.tsx@@ -64,7 +64,11 @@ import {trackUpsellShown,upgradeHref,} from '@/lib/billing-onramp'-import { getManagedProject } from '@/managed-agents/api'+import {+ getManagedMemoryResources,+ getManagedProject,+} from '@/managed-agents/api'+import { SECURITY_FINDINGS_RESOURCE } from '@/managed-agents/security/catalog'import {projectEnvironmentMode,projectEnvironmentSearch,@@ -335,12 +339,25 @@ function SidebarNav({ onNavigate }: { onNavigate?: () => void }) {const navigate = useNavigate()const projectId = projectIdFromPath(location.pathname)const computerEnabled = user?.computerEnabled ?? false+ // A CVE Swarm project is the one that declares the findings resource; only+ // those get the Swarm grid in their nav.+ const swarmResources = useQuery({+ queryKey: ['managed-memory-resources', projectId],+ queryFn: () =>+ getManagedMemoryResources({ projectId: projectId!, environment: 'default' }),+ enabled: Boolean(managedAgentsExperimentEnabled && projectId),+ staleTime: 60_000,+ })+ const swarmEnabled = (swarmResources.data?.resources ?? []).some(+ (resource) => resource.id === SECURITY_FINDINGS_RESOURCE,+ )const nav = managedAgentsExperimentEnabled? managedAgentsNav({projectId,durableSessionsEnabled: user?.durableSessionsEnabled ?? false,infrastructureEnabled: user?.infrastructureEnabled ?? false,computerEnabled,+ swarmEnabled,}): LEGACY_NAVconst activeCollapsibleGroup = nav.find(diff --git a/web/src/managed-agents/security/ProjectSwarm.tsx b/web/src/managed-agents/security/ProjectSwarm.tsxnew file mode 100644index 00000000..1ce155f0--- /dev/null+++ b/web/src/managed-agents/security/ProjectSwarm.tsx@@ -0,0 +1,75 @@+import { useQuery } from '@tanstack/react-query'+import { Link, useParams } from 'react-router-dom'+import { Loader2, Radar } from 'lucide-react'+import { PageHeader } from '@/components/page-header'+import { Button } from '@/components/ui/button'+import {+ getManagedMemoryDocument,+ getManagedMemoryDocuments,+} from '../api'+import {+ latestManifestId,+ parseRunManifest,+ SECURITY_FINDINGS_RESOURCE,+} from './catalog'+import { SwarmGrid } from './SwarmGrid'++// The swarm page for a deployed CVE Swarm project. The launch records a run+// manifest under the findings resource; here we read the latest one back and+// render its grid, so the run is reachable by URL and survives a reload — the+// grid's own React state no longer holds the session ids.+export default function ProjectSwarm() {+ const { projectId = '' } = useParams()++ const manifest = useQuery({+ queryKey: ['swarm-manifest', projectId],+ enabled: Boolean(projectId),+ queryFn: async () => {+ const page = await getManagedMemoryDocuments({+ projectId,+ resource: SECURITY_FINDINGS_RESOURCE,+ environment: 'default',+ })+ const id = latestManifestId(page.documents)+ if (!id) return null+ const read = await getManagedMemoryDocument({+ projectId,+ resource: SECURITY_FINDINGS_RESOURCE,+ environment: 'default',+ id,+ })+ return parseRunManifest(read.document.text)+ },+ })++ return (+ <div className="mx-auto max-w-5xl px-4 py-8">+ <PageHeader+ title="CVE Swarm"+ description="Each cell proves whether one CVE is reachable in one repository. Open a cell to read its full session."+ className="mb-6"+ />+ {manifest.isPending ? (+ <div className="text-muted-foreground inline-flex items-center gap-2 text-sm">+ <Loader2 className="size-4 animate-spin" /> Loading the latest run…+ </div>+ ) : manifest.data ? (+ <SwarmGrid+ projectId={projectId}+ runId={manifest.data.runId}+ cells={manifest.data.cells}+ />+ ) : (+ <div className="rounded-lg border border-dashed p-10 text-center">+ <Radar className="text-muted-foreground mx-auto size-6" />+ <p className="text-muted-foreground mt-3 text-sm">+ No swarm has run in this project yet.+ </p>+ <Button asChild variant="outline" className="mt-4">+ <Link to="/security">Launch a swarm</Link>+ </Button>+ </div>+ )}+ </div>+ )+}diff --git a/web/src/managed-agents/security/SecurityOnboarding.tsx b/web/src/managed-agents/security/SecurityOnboarding.tsxindex 2080af02..5c3f2510 100644--- a/web/src/managed-agents/security/SecurityOnboarding.tsx+++ b/web/src/managed-agents/security/SecurityOnboarding.tsx@@ -1,10 +1,10 @@import { useMemo, useState } from 'react'+import { useNavigate } from 'react-router-dom'import { useMutation, useQuery } from '@tanstack/react-query'import {FolderGit2,Loader2,Radar,- RotateCcw,Rocket,ShieldCheck,X,@@ -39,15 +39,16 @@ import {composeCellPrompt,composeLaunchPrompt,DEFAULT_SWARM_MODEL,+ runManifestDocumentId,SCAN_DECLARATION,SECURITY_FINDINGS_RESOURCE,SECURITY_SWARM_TEMPLATE_REPOSITORY,SEED_CVES,+ serializeRunManifest,swarmCells,type LaunchedCell,type SwarmPayload,} from './catalog'-import { SwarmGrid } from './SwarmGrid'// Each cell is one microVM session, so cap the matrix to keep an accidental// 20×20 launch from spinning up hundreds of sandboxes at once.@@ -71,10 +72,8 @@ async function waitForInstallation(id: string) {return installation}-type SwarmRun = { runId: string; cells: LaunchedCell[] }-export default function SecurityOnboarding() {- const [run, setRun] = useState<SwarmRun | null>(null)+ const navigate = useNavigate()// Step 1 — GitHub connection. An active install means the boundary is set.const connections = useQuery({@@ -166,13 +165,14 @@ export default function SecurityOnboarding() {onError: (error) => notifyError("Couldn't deploy the CVE Swarm.", error),})- // Launch fans the payload's repository × CVE matrix out into one bound,- // labelled session per cell. Each cell gets its own findings document, created- // first (a binding to a missing document fails admission), then a session- // bound read-write to it with labels that tie it back to the run. The sessions- // run in parallel; the grid below polls them by `swarmRun` label.+ // Launch fans the payload's repository × CVE matrix out into one bound session+ // per cell. Each cell gets its own findings document, created first (a binding+ // to a missing document fails admission), then a session bound read-write to+ // it. The session ids are recorded in a run manifest document so the swarm+ // page can rebuild the grid after we navigate to it — the ids don't survive in+ // React state across the route change.const launch = useMutation({- mutationFn: async (payload: SwarmPayload): Promise<SwarmRun> => {+ mutationFn: async (payload: SwarmPayload): Promise<{ projectId: string }> => {if (!deployed) throw new Error('Deploy the swarm before launching.')const cells = swarmCells(payload)if (cells.length === 0) {@@ -212,9 +212,26 @@ export default function SecurityOnboarding() {return { cell, sessionId }}),)- return { runId, cells: launched }+ // Persist the run so the swarm page is reachable by URL and survives a+ // reload. agentWrites stays disabled — only cell findings are agent-owned.+ await createManagedMemoryDocument({+ projectId: deployed.projectId,+ resource: SECURITY_FINDINGS_RESOURCE,+ environment: 'default',+ id: runManifestDocumentId(runId),+ title: `Swarm run ${runId}`,+ text: serializeRunManifest({+ runId,+ model: payload.model,+ target: payload.target,+ cells: launched,+ }),+ agentWrites: 'disabled',+ })+ return { projectId: deployed.projectId }},- onSuccess: (started) => setRun(started),+ onSuccess: ({ projectId }) =>+ navigate(`/projects/${encodeURIComponent(projectId)}/swarm`),onError: (error) => notifyError("Couldn't start the swarm.", error),})@@ -312,32 +329,14 @@ export default function SecurityOnboarding() {index={2}current={step}icon={Radar}- title={run ? 'Swarm running' : 'Launch swarm from payload'}+ title="Launch swarm from payload"done={false}>- {run && deployed ? (- <div className="space-y-4">- <SwarmGrid- projectId={deployed.projectId}- runId={run.runId}- cells={run.cells}- />- <Button- type="button"- variant="outline"- onClick={() => setRun(null)}- >- <RotateCcw />- New swarm- </Button>- </div>- ) : (- <PayloadBuilder- canLaunch={!!deployed}- launching={launch.isPending}- onLaunch={(payload) => launch.mutate(payload)}- />- )}+ <PayloadBuilder+ canLaunch={!!deployed}+ launching={launch.isPending}+ onLaunch={(payload) => launch.mutate(payload)}+ /></StepCard></div></div>diff --git a/web/src/managed-agents/security/SwarmGrid.tsx b/web/src/managed-agents/security/SwarmGrid.tsxindex 8da71336..9cfd8fb3 100644--- a/web/src/managed-agents/security/SwarmGrid.tsx+++ b/web/src/managed-agents/security/SwarmGrid.tsx@@ -1,6 +1,14 @@import { useMemo } from 'react'+import { Link } from 'react-router-dom'import { useQuery } from '@tanstack/react-query'-import { ExternalLink, Loader2, ShieldAlert, ShieldCheck, ShieldQuestion } from 'lucide-react'+import {+ ArrowUpRight,+ ExternalLink,+ Loader2,+ ShieldAlert,+ ShieldCheck,+ ShieldQuestion,+} from 'lucide-react'import { cn } from '@/lib/utils'import {getManagedAgentSession,@@ -21,6 +29,7 @@ import {// each cell's findings document (for the verdict) until every cell settles.type CellState = {cell: SwarmCell+ sessionId: stringsessionStatus?: stringfinding: CellFinding | null}@@ -128,6 +137,7 @@ export function SwarmGrid({const states: CellState[] = cells.map(({ cell, sessionId }) => ({cell,+ sessionId,sessionStatus: statusBySession[sessionId],finding: findings.data?.[cellDocumentId(runId, cell)] ?? null,}))@@ -174,11 +184,12 @@ export function SwarmGrid({) : null}</div>- <div className="grid gap-2.5 sm:grid-cols-2">+ <div className="grid gap-2.5 sm:grid-cols-2 lg:grid-cols-3">{states.map((state) => (<CellTilekey={cellDocumentId(runId, state.cell)}state={state}+ projectId={projectId}/>))}</div>@@ -211,7 +222,13 @@ function SummaryPill({)}-function CellTile({ state }: { state: CellState }) {+function CellTile({+ state,+ projectId,+}: {+ state: CellState+ projectId: string+}) {const phase = cellPhase(state)const [owner, name] = state.cell.repository.split('/')return (@@ -233,17 +250,26 @@ function CellTile({ state }: { state: CellState }) {{state.finding.reasoning}</p>) : null}- {state.finding?.pullRequest ? (- <a- href={state.finding.pullRequest}- target="_blank"- rel="noreferrer"- className="text-status-running mt-2 inline-flex items-center gap-1 text-xs hover:underline"+ <div className="mt-2 flex items-center gap-3">+ <Link+ to={`/projects/${encodeURIComponent(projectId)}/sessions/${encodeURIComponent(state.sessionId)}`}+ className="text-muted-foreground hover:text-foreground inline-flex items-center gap-1 text-xs hover:underline">- <ExternalLink className="size-3" />- Fix pull request- </a>- ) : null}+ <ArrowUpRight className="size-3" />+ Open session+ </Link>+ {state.finding?.pullRequest ? (+ <a+ href={state.finding.pullRequest}+ target="_blank"+ rel="noreferrer"+ className="text-status-running inline-flex items-center gap-1 text-xs hover:underline"+ >+ <ExternalLink className="size-3" />+ Fix pull request+ </a>+ ) : null}+ </div></div>)}diff --git a/web/src/managed-agents/security/catalog.test.ts b/web/src/managed-agents/security/catalog.test.tsindex ac5ea6e8..94641e5e 100644--- a/web/src/managed-agents/security/catalog.test.ts+++ b/web/src/managed-agents/security/catalog.test.ts@@ -2,9 +2,14 @@ import { describe, expect, it } from 'vitest'import {cellDocumentId,composeCellPrompt,+ latestManifestId,parseCellFinding,+ parseRunManifest,+ runManifestDocumentId,+ serializeRunManifest,swarmCells,type SwarmPayload,+ type SwarmRunManifest,} from './catalog'const payload: SwarmPayload = {@@ -93,3 +98,54 @@ describe('parseCellFinding', () => {})})})++describe('run manifest', () => {+ const manifest: SwarmRunManifest = {+ runId: 'run-abc',+ model: 'GLM-5.3',+ target: 'https://app.example.com',+ cells: [+ { cell: { repository: 'acme/web', cveId: 'CVE-2026-1' }, sessionId: 's1' },+ { cell: { repository: 'acme/api', cveId: 'CVE-2026-1' }, sessionId: 's2' },+ ],+ }++ it('keeps the manifest document clear of cell findings documents', () => {+ expect(runManifestDocumentId('run-abc')).toBe('manifest__run-abc')+ expect(runManifestDocumentId('run-abc')).not.toBe(+ cellDocumentId('run-abc', { repository: 'acme/web', cveId: 'CVE-2026-1' }),+ )+ })++ it('round-trips through serialize and parse', () => {+ expect(parseRunManifest(serializeRunManifest(manifest))).toEqual(manifest)+ })++ it('rejects malformed or empty manifests', () => {+ expect(parseRunManifest('not json')).toBeNull()+ expect(parseRunManifest('{}')).toBeNull()+ expect(parseRunManifest(JSON.stringify({ runId: 'r', cells: [] }))).toBeNull()+ expect(+ parseRunManifest(+ JSON.stringify({ runId: 'r', cells: [{ cell: { repository: 'a/b' } }] }),+ ),+ ).toBeNull()+ })++ it('picks the most recently updated manifest, ignoring findings docs', () => {+ const latest = latestManifestId([+ { id: 'run-old__acme-web__cve-2026-1', updatedAt: '2026-10-22T10:00:00Z' },+ { id: 'manifest__run-old', updatedAt: '2026-10-22T09:00:00Z' },+ { id: 'manifest__run-new', updatedAt: '2026-10-22T12:00:00Z' },+ ])+ expect(latest).toBe('manifest__run-new')+ })++ it('returns null when no manifest has been written', () => {+ expect(+ latestManifestId([+ { id: 'run-x__acme-web__cve-1', updatedAt: '2026-10-22T10:00:00Z' },+ ]),+ ).toBeNull()+ })+})diff --git a/web/src/managed-agents/security/catalog.ts b/web/src/managed-agents/security/catalog.tsindex 040f1b5d..13a47ecf 100644--- a/web/src/managed-agents/security/catalog.ts+++ b/web/src/managed-agents/security/catalog.ts@@ -80,8 +80,8 @@ export type SwarmPayload = {// A single unit of swarm work: one repository checked against one CVE. The// launch fans the payload's repository × CVE matrix into one cell per pair, and-// starts one bound, labelled session for each so they run in parallel and each-// writes its own findings document.+// starts one bound session for each so they run in parallel and each writes its+// own findings document.export type SwarmCell = {readonly repository: stringreadonly cveId: string@@ -126,6 +126,80 @@ export function cellDocumentId(runId: string, cell: SwarmCell): string {return `${runId}__${slug(cell.repository)}__${slug(cell.cveId)}`}+// The launch records what it started as a run manifest, persisted as its own+// document under the findings resource so the swarm page can rebuild the grid+// after navigation or a reload (the session ids live in the manifest, not in+// React state). The `manifest__` prefix keeps it clear of the cell findings+// documents, whose ids are `<runId>__<repo>__<cve>`.+export const SWARM_MANIFEST_PREFIX = 'manifest__'++export function runManifestDocumentId(runId: string): string {+ return `${SWARM_MANIFEST_PREFIX}${runId}`+}++export type SwarmRunManifest = {+ readonly runId: string+ readonly model: string+ readonly target: string+ readonly cells: readonly LaunchedCell[]+}++export function serializeRunManifest(manifest: SwarmRunManifest): string {+ return JSON.stringify(manifest)+}++// Rebuild a manifest from its stored text. Returns null for anything that is+// not a well-formed manifest with at least one launched cell, so the swarm page+// can fall back to its empty state rather than render a broken grid.+export function parseRunManifest(text: string): SwarmRunManifest | null {+ let parsed: unknown+ try {+ parsed = JSON.parse(text)+ } catch {+ return null+ }+ if (!parsed || typeof parsed !== 'object') return null+ const obj = parsed as Record<string, unknown>+ if (typeof obj.runId !== 'string' || !Array.isArray(obj.cells)) return null+ const cells: LaunchedCell[] = []+ for (const entry of obj.cells) {+ if (!entry || typeof entry !== 'object') return null+ const e = entry as Record<string, unknown>+ const cell = e.cell as Record<string, unknown> | undefined+ if (+ !cell ||+ typeof cell.repository !== 'string' ||+ typeof cell.cveId !== 'string' ||+ typeof e.sessionId !== 'string'+ ) {+ return null+ }+ cells.push({+ cell: { repository: cell.repository, cveId: cell.cveId },+ sessionId: e.sessionId,+ })+ }+ if (cells.length === 0) return null+ return {+ runId: obj.runId,+ model: typeof obj.model === 'string' ? obj.model : '',+ target: typeof obj.target === 'string' ? obj.target : '',+ cells,+ }+}++// From a page of findings-resource documents, the id of the most recently+// updated run manifest — the run the swarm page shows by default. Null when no+// swarm has run in the project yet.+export function latestManifestId(+ docs: readonly { id: string; updatedAt: string }[],+): string | null {+ const manifests = docs+ .filter((doc) => doc.id.startsWith(SWARM_MANIFEST_PREFIX))+ .sort((a, b) => b.updatedAt.localeCompare(a.updatedAt))+ return manifests[0]?.id ?? null+}+// One cell's first-run input: a single repository checked against a single CVE.// The worker agent already collapses to a 1×1 matrix when the payload names one// of each, so this is the launch prompt narrowed to the cell.