An open-source, faster Devin alternative
TypeScript
Add Tier 1 run report to the swarm grid
Mohamed Habib via Computer06e590483292
diff --git a/web/src/managed-agents/security/ProjectSwarm.tsx b/web/src/managed-agents/security/ProjectSwarm.tsxindex 1ce155f0..67e46b6d 100644--- a/web/src/managed-agents/security/ProjectSwarm.tsx+++ b/web/src/managed-agents/security/ProjectSwarm.tsx@@ -58,6 +58,8 @@ export default function ProjectSwarm() {projectId={projectId}runId={manifest.data.runId}cells={manifest.data.cells}+ target={manifest.data.target}+ model={manifest.data.model}/>) : (<div className="rounded-lg border border-dashed p-10 text-center">diff --git a/web/src/managed-agents/security/SwarmGrid.tsx b/web/src/managed-agents/security/SwarmGrid.tsxindex 567ee956..674aa0f9 100644--- a/web/src/managed-agents/security/SwarmGrid.tsx+++ b/web/src/managed-agents/security/SwarmGrid.tsx@@ -1,4 +1,4 @@-import { useMemo, useRef } from 'react'+import { useEffect, useMemo, useRef } from 'react'import { Link } from 'react-router-dom'import { useQuery } from '@tanstack/react-query'import {@@ -11,17 +11,24 @@ import {} from 'lucide-react'import { cn } from '@/lib/utils'import {+ createManagedMemoryDocument,getManagedAgentSession,getManagedMemoryDocument,} from '../api'import {+ buildRunReport,cellDocumentId,parseCellFinding,+ runReportDocumentId,SECURITY_FINDINGS_RESOURCE,+ serializeRunReport,type CellFinding,type CveDisposition,type LaunchedCell,+ type ReportCell,+ type ReportDisposition,type SwarmCell,+ type SwarmRunReport,} from './catalog'// A cell is settled when its worker has either saved a verdict or its session@@ -52,11 +59,9 @@ function sessionFailed(progress: SessionProgress | undefined): boolean {return turn === 'failed' || turn === 'errored' || turn === 'cancelled'}-// Settled = we will never poll it again: the verdict is saved, or it failed.-function cellSettled(state: CellState): boolean {- return Boolean(state.finding) || sessionFailed(state.progress)-}-+// A cell is settled — we will never poll it again — when its verdict is saved+// or it failed, i.e. its phase is 'done' or 'failed'. The grid tracks that via+// `counts.pending === 0`.function cellPhase(state: CellState): 'done' | 'failed' | 'running' | 'queued' {if (state.finding) return 'done'if (sessionFailed(state.progress)) return 'failed'@@ -90,10 +95,14 @@ export function SwarmGrid({projectId,runId,cells,+ target = '',+ model = '',}: {projectId: stringrunId: stringcells: readonly LaunchedCell[]+ target?: string+ model?: string}) {// Both polls stop the moment every cell has settled (verdict saved, or// failed). We recompute that each render and park it in a ref the two@@ -114,7 +123,7 @@ export function SwarmGrid({return [sessionId, { status: session.status, lastTurnStatus }] as const}),)- return Object.fromEntries(entries) as Record<string, SessionProgress>+ return Object.fromEntries(entries)},refetchInterval: () => (allSettledRef.current ? false : 3_000),})@@ -155,8 +164,6 @@ export function SwarmGrid({finding: findings.data?.[cellDocumentId(runId, cell)] ?? null,}))- allSettledRef.current = states.every(cellSettled)-const counts = states.reduce((acc, state) => {const phase = cellPhase(state)@@ -170,6 +177,56 @@ export function SwarmGrid({)const settled = counts.pending === 0+ // Park the settled flag in the ref the two refetchInterval closures read, so+ // both polls stop once the run is done. Written in an effect (not during+ // render) so the ref update is a proper side effect.+ useEffect(() => {+ allSettledRef.current = settled+ }, [settled])++ // Once every cell has settled, roll the verdicts into the run report. This is+ // the swarm's artifact; we both show it and persist it (below) so a scheduled+ // run leaves something behind.+ const report: SwarmRunReport | null = settled+ ? buildRunReport(+ { runId, target, model, generatedAt: new Date().toISOString() },+ states.map((s): ReportCell => {+ const disposition: ReportDisposition = s.finding+ ? s.finding.disposition+ : 'failed'+ return {+ repository: s.cell.repository,+ cveId: s.cell.cveId,+ disposition,+ ...(s.finding?.reasoning ? { reasoning: s.finding.reasoning } : {}),+ ...(s.finding?.pullRequest+ ? { pullRequest: s.finding.pullRequest }+ : {}),+ }+ }),+ )+ : null++ // Persist the report exactly once, when the run first settles. create-once+ // (If-None-Match:*) means a reload that re-settles the same run is a no-op —+ // the first write wins and any later conflict is ignored.+ const reportWrittenRef = useRef(false)+ useEffect(() => {+ if (!report || reportWrittenRef.current) return+ reportWrittenRef.current = true+ void createManagedMemoryDocument({+ projectId,+ resource: SECURITY_FINDINGS_RESOURCE,+ environment: 'default',+ id: runReportDocumentId(runId),+ title: `Swarm report ${runId}`,+ text: serializeRunReport(report),+ agentWrites: 'disabled',+ }).catch(() => {+ // Already written by an earlier view of this run — leave it be.+ })+ }, [report, projectId, runId])+return (<div className="space-y-4"><div className="flex flex-wrap items-center gap-2 text-sm">@@ -208,10 +265,94 @@ export function SwarmGrid({/>))}</div>++ {report ? <RunReportCard report={report} /> : null}</div>)}+// The run's report: shown once every cell has settled. It is the swarm's+// artifact — the actionable verdicts rolled up and ranked. Tier 1 computes it+// from the cell findings the grid already holds; a later reducer agent can+// replace this with a written narrative over the same persisted document.+function RunReportCard({ report }: { report: SwarmRunReport }) {+ const actionable = report.cells.filter(+ (c) => c.disposition !== 'not-exposed',+ )+ return (+ <div className="mt-2 rounded-lg border">+ <div className="flex flex-wrap items-center justify-between gap-2 border-b px-4 py-3">+ <div>+ <h3 className="text-sm font-medium">Run report</h3>+ <p className="text-muted-foreground mt-0.5 text-xs">+ {report.counts.total} cells ·{' '}+ {report.counts.exposed} exposed · {report.counts.needsReview} to+ review · {report.counts.failed} failed · {report.counts.fixPrs} fix+ {report.counts.fixPrs === 1 ? ' PR' : ' PRs'}+ </p>+ </div>+ <span className="text-muted-foreground text-xs">+ {new Date(report.generatedAt).toLocaleString()}+ </span>+ </div>++ {actionable.length === 0 ? (+ <p className="text-muted-foreground px-4 py-6 text-sm">+ Nothing exposed. Every CVE checked was not reachable in its+ repository.+ </p>+ ) : (+ <ul className="divide-y">+ {actionable.map((c) => (+ <ReportRow key={`${c.repository}__${c.cveId}`} cell={c} />+ ))}+ </ul>+ )}+ </div>+ )+}++function ReportRow({ cell }: { cell: ReportCell }) {+ const meta =+ cell.disposition === 'failed'+ ? { label: 'Failed', className: 'text-muted-foreground border-border' }+ : DISPOSITION_META[cell.disposition]+ return (+ <li className="flex items-start gap-3 px-4 py-3">+ <span+ className={cn(+ 'mt-0.5 inline-flex shrink-0 items-center rounded-full border px-2 py-0.5 text-xs font-medium',+ meta.className,+ )}+ >+ {meta.label}+ </span>+ <div className="min-w-0 flex-1">+ <div className="font-mono text-xs">+ {cell.repository}{' '}+ <span className="text-muted-foreground">· {cell.cveId}</span>+ </div>+ {cell.reasoning ? (+ <p className="text-muted-foreground mt-1 line-clamp-2 text-xs leading-5">+ {cell.reasoning}+ </p>+ ) : null}+ </div>+ {cell.pullRequest ? (+ <a+ href={cell.pullRequest}+ target="_blank"+ rel="noreferrer"+ className="text-status-running mt-0.5 inline-flex shrink-0 items-center gap-1 text-xs hover:underline"+ >+ <ExternalLink className="size-3" />+ Fix PR+ </a>+ ) : null}+ </li>+ )+}+function SummaryPill({label,count,diff --git a/web/src/managed-agents/security/catalog.test.ts b/web/src/managed-agents/security/catalog.test.tsindex 94641e5e..cd8c5ed4 100644--- a/web/src/managed-agents/security/catalog.test.ts+++ b/web/src/managed-agents/security/catalog.test.ts@@ -1,13 +1,16 @@import { describe, expect, it } from 'vitest'import {+ buildRunReport,cellDocumentId,composeCellPrompt,latestManifestId,parseCellFinding,parseRunManifest,runManifestDocumentId,+ runReportDocumentId,serializeRunManifest,swarmCells,+ type ReportCell,type SwarmPayload,type SwarmRunManifest,} from './catalog'@@ -149,3 +152,61 @@ describe('run manifest', () => {).toBeNull()})})++describe('run report', () => {+ const cells: ReportCell[] = [+ { repository: 'acme/web', cveId: 'CVE-2026-9', disposition: 'not-exposed' },+ {+ repository: 'acme/api',+ cveId: 'CVE-2026-2',+ disposition: 'exposed',+ reasoning: 'vulnerable version in lockfile',+ pullRequest: 'https://github.com/acme/api/pull/7',+ },+ { repository: 'acme/db', cveId: 'CVE-2026-5', disposition: 'failed' },+ { repository: 'acme/ui', cveId: 'CVE-2026-3', disposition: 'needs-review' },+ ]+ const meta = {+ runId: 'run-abc',+ target: 'https://app.example.com',+ model: 'GLM-5.3',+ generatedAt: '2026-10-22T12:00:00Z',+ }++ it('keeps the report document clear of manifests and findings', () => {+ expect(runReportDocumentId('run-abc')).toBe('report__run-abc')+ expect(runReportDocumentId('run-abc')).not.toBe(+ runManifestDocumentId('run-abc'),+ )+ })++ it('derives counts from the cells', () => {+ const report = buildRunReport(meta, cells)+ expect(report.counts).toEqual({+ exposed: 1,+ notExposed: 1,+ needsReview: 1,+ failed: 1,+ fixPrs: 1,+ total: 4,+ })+ })++ it('ranks cells exposed → needs-review → failed → not-exposed', () => {+ const report = buildRunReport(meta, cells)+ expect(report.cells.map((c) => c.disposition)).toEqual([+ 'exposed',+ 'needs-review',+ 'failed',+ 'not-exposed',+ ])+ })++ it('carries the run metadata through', () => {+ const report = buildRunReport(meta, cells)+ expect(report.runId).toBe('run-abc')+ expect(report.target).toBe('https://app.example.com')+ expect(report.model).toBe('GLM-5.3')+ expect(report.generatedAt).toBe('2026-10-22T12:00:00Z')+ })+})diff --git a/web/src/managed-agents/security/catalog.ts b/web/src/managed-agents/security/catalog.tsindex 13a47ecf..608079a7 100644--- a/web/src/managed-agents/security/catalog.ts+++ b/web/src/managed-agents/security/catalog.ts@@ -265,6 +265,83 @@ export function parseCellFinding(text: string): CellFinding | null {}}+// The run report: the swarm's one artifact, rolled up from every cell's verdict+// once the grid has settled. It is computed client-side from the findings the+// cells already saved (Tier 1 — no reducer agent), then persisted as its own+// document so a scheduled run leaves something behind and the aggregator view+// has a real source. The `report__` prefix keeps it clear of manifests+// (`manifest__`) and cell findings (`<runId>__<repo>__<cve>`).+export const SWARM_REPORT_PREFIX = 'report__'++export function runReportDocumentId(runId: string): string {+ return `${SWARM_REPORT_PREFIX}${runId}`+}++// A cell as it appears in the report: its verdict resolved, including `failed`+// for a cell whose session stopped without saving one.+export type ReportDisposition = CveDisposition | 'failed'++export type ReportCell = {+ readonly repository: string+ readonly cveId: string+ readonly disposition: ReportDisposition+ readonly reasoning?: string+ readonly pullRequest?: string+}++export type SwarmReportCounts = {+ readonly exposed: number+ readonly notExposed: number+ readonly needsReview: number+ readonly failed: number+ readonly fixPrs: number+ readonly total: number+}++export type SwarmRunReport = {+ readonly runId: string+ readonly target: string+ readonly model: string+ readonly generatedAt: string+ readonly counts: SwarmReportCounts+ // Ordered most-actionable first: exposed, needs-review, failed, not-exposed.+ readonly cells: readonly ReportCell[]+}++const REPORT_ORDER: Record<ReportDisposition, number> = {+ exposed: 0,+ 'needs-review': 1,+ failed: 2,+ 'not-exposed': 3,+}++// Roll resolved cells into a report. Counts are derived here so a caller cannot+// desync them from the cells; cells are sorted most-actionable first.+export function buildRunReport(+ meta: { runId: string; target: string; model: string; generatedAt: string },+ cells: readonly ReportCell[],+): SwarmRunReport {+ const counts: SwarmReportCounts = {+ exposed: cells.filter((c) => c.disposition === 'exposed').length,+ notExposed: cells.filter((c) => c.disposition === 'not-exposed').length,+ needsReview: cells.filter((c) => c.disposition === 'needs-review').length,+ failed: cells.filter((c) => c.disposition === 'failed').length,+ fixPrs: cells.filter((c) => Boolean(c.pullRequest)).length,+ total: cells.length,+ }+ const sorted = [...cells].sort(+ (a, b) =>+ REPORT_ORDER[a.disposition] - REPORT_ORDER[b.disposition] ||+ a.repository.localeCompare(b.repository) ||+ a.cveId.localeCompare(b.cveId),+ )+ return { ...meta, counts, cells: sorted }+}++export function serializeRunReport(report: SwarmRunReport): string {+ return JSON.stringify(report)+}+// Compose the controller's first-run input from the payload. This is exactly// what the swarm agent receives as its opening instruction when the session// starts — the scan → prove → report pipeline, with fixes gated by the