An open-source, faster Devin alternative
TypeScript
cve-swarm: paginate live feed and stop defaulting all repos
Mohamed Habib via Computerf25fe9585a86
diff --git a/web/src/managed-agents/security/SecurityOnboarding.tsx b/web/src/managed-agents/security/SecurityOnboarding.tsxindex b74e07f0..7eccba8c 100644--- a/web/src/managed-agents/security/SecurityOnboarding.tsx+++ b/web/src/managed-agents/security/SecurityOnboarding.tsx@@ -751,16 +751,9 @@ function PayloadBuilder({[target, declaration, repositories, cveIds, authenticated, activeScan, loginUrl],)- // Default to every connected repo the moment the list lands — the operator- // asked to swarm their whole surface, so that's the useful starting point.- // One-shot: once defaulted (or the operator edits first) we leave the- // selection alone, so a removed repo doesn't snap back on the next render.- const defaultedRef = useRef(false)- useEffect(() => {- if (defaultedRef.current || availableRepos.length === 0) return- defaultedRef.current = true- setRepositories((current) => (current.length > 0 ? current : availableRepos))- }, [availableRepos])+ // Repos start unselected — the operator picks the ones that are real evidence+ // for the target rather than cloning their whole surface by default. "Select+ // all" is one click away in the picker when they do want everything.// The target is the asset under test, and the declaration attests ownership// of "this web application" — so a launch needs a real https(s) URL. An empty@@ -871,7 +864,7 @@ function PayloadBuilder({<Fieldlabel="Repositories"- hint="Every repo from your GitHub install, selected by default. These are shared evidence — every CVE agent gets all of them cloned to investigate the target against."+ hint="Pick the repos behind this target — they're shared evidence every CVE agent clones to prove reachability. Use Select all for your whole install, or choose just the ones that back this endpoint."><RepoPickeravailable={availableRepos}diff --git a/web/src/managed-agents/security/feeds.test.ts b/web/src/managed-agents/security/feeds.test.tsindex 33138c01..e1fd8b85 100644--- a/web/src/managed-agents/security/feeds.test.ts+++ b/web/src/managed-agents/security/feeds.test.ts@@ -1,8 +1,9 @@-import { describe, expect, it } from 'vitest'+import { afterEach, describe, expect, it, vi } from 'vitest'import {DISCOVERY_ANGLES,SWARM_FEEDS,assignAngles,+ fetchLiveCves,feedSeedingLines,} from './feeds'@@ -52,3 +53,77 @@ describe('feed seeding', () => {expect(text).toContain('check_stack')})})++describe('fetchLiveCves', () => {+ afterEach(() => {+ vi.restoreAllMocks()+ })++ // One page of the entries API: `count` entries numbered from `start`, plus the+ // cursor to the following page (null for the last page). Not async — returning+ // a resolved promise keeps eslint's require-await happy.+ const page = (start: number, count: number, nextCursor: string | null) => {+ const entries = Array.from({ length: count }, (_, i) => ({+ id: `CVE-2026-${start + i}`,+ title: `Entry ${start + i}`,+ cvss: 5,+ statedSeverity: 'medium',+ kev: false,+ firstSeenAt: '2026-10-24T00:00:00Z',+ }))+ return { ok: true, json: () => Promise.resolve({ entries, nextCursor }) }+ }++ it('follows the cursor across pages until it reaches the limit', async () => {+ const fetchMock = vi+ .fn()+ .mockResolvedValueOnce(page(0, 30, 'c1'))+ .mockResolvedValueOnce(page(30, 30, 'c2'))+ .mockResolvedValueOnce(page(60, 30, 'c3'))+ vi.stubGlobal('fetch', fetchMock)+ const cves = await fetchLiveCves(80)+ expect(cves).toHaveLength(80)+ // Second call carries the first page's cursor.+ const secondUrl = String(fetchMock.mock.calls[1][0])+ expect(secondUrl).toContain('cursor=c1')+ })++ it('stops when the feed runs out before the limit', async () => {+ const fetchMock = vi+ .fn()+ .mockResolvedValueOnce(page(0, 30, 'c1'))+ .mockResolvedValueOnce(page(30, 10, null))+ vi.stubGlobal('fetch', fetchMock)+ const cves = await fetchLiveCves(100)+ expect(cves).toHaveLength(40)+ expect(fetchMock).toHaveBeenCalledTimes(2)+ })++ it('de-duplicates ids that repeat across pages', async () => {+ const fetchMock = vi+ .fn()+ .mockResolvedValueOnce(page(0, 30, 'c1'))+ // Overlaps the first page by ten ids.+ .mockResolvedValueOnce(page(20, 30, null))+ vi.stubGlobal('fetch', fetchMock)+ const cves = await fetchLiveCves(100)+ expect(cves).toHaveLength(50)+ expect(new Set(cves.map((c) => c.id)).size).toBe(50)+ })++ it('throws when the first page fails', async () => {+ const fetchMock = vi.fn().mockResolvedValueOnce({ ok: false, status: 503 })+ vi.stubGlobal('fetch', fetchMock)+ await expect(fetchLiveCves(50)).rejects.toThrow('503')+ })++ it('keeps gathered entries when a later page fails', async () => {+ const fetchMock = vi+ .fn()+ .mockResolvedValueOnce(page(0, 30, 'c1'))+ .mockResolvedValueOnce({ ok: false, status: 500 })+ vi.stubGlobal('fetch', fetchMock)+ const cves = await fetchLiveCves(100)+ expect(cves).toHaveLength(30)+ })+})diff --git a/web/src/managed-agents/security/feeds.ts b/web/src/managed-agents/security/feeds.tsindex 52c12288..23ad7b84 100644--- a/web/src/managed-agents/security/feeds.ts+++ b/web/src/managed-agents/security/feeds.ts@@ -97,24 +97,22 @@ export function severityRank(cve: FeedCve): number {return kev + cvss + bucket}-// Fetch the current cve.now feed slice and return it severity-sorted (worst-// first), ready for the onboarding top-N picker. `limit` caps how many raw-// entries we pull before ranking; the caller slices to the chosen N. Throws on a-// non-OK response or a malformed body so the UI can show a retry.-export async function fetchLiveCves(- limit = 50,- signal?: AbortSignal,-): Promise<FeedCve[]> {- const url = `${CVE_NOW_ENTRIES_API}?limit=${encodeURIComponent(String(limit))}`- const res = await fetch(url, { signal, headers: { accept: 'application/json' } })- if (!res.ok) {- throw new Error(`cve.now feed responded ${res.status}`)- }- const body: unknown = await res.json()- const entries =- body && typeof body === 'object' && Array.isArray((body as { entries?: unknown }).entries)- ? ((body as { entries: unknown[] }).entries)- : []+// cve.now serves a fixed ~30 entries per page regardless of the `limit` we ask+// for, cursor-paginated via `nextCursor`. To offer a top-N picker larger than+// one page we follow the cursor until we have enough — bounded so a broken or+// endless feed can never loop without limit.+const MAX_FEED_PAGES = 20++// Validate one entries-API page: pull the well-formed CVE rows out and surface+// the cursor to the next page (null when the feed has no more). Malformed rows+// are dropped rather than failing the whole page.+function parseEntriesPage(body: unknown): {+ cves: FeedCve[]+ nextCursor: string | null+} {+ const obj =+ body && typeof body === 'object' ? (body as Record<string, unknown>) : {}+ const entries = Array.isArray(obj.entries) ? obj.entries : []const cves: FeedCve[] = []for (const raw of entries) {if (!raw || typeof raw !== 'object') continue@@ -129,7 +127,50 @@ export async function fetchLiveCves(firstSeenAt: typeof e.firstSeenAt === 'string' ? e.firstSeenAt : null,})}- return cves.sort((a, b) => severityRank(b) - severityRank(a))+ const nextCursor =+ typeof obj.nextCursor === 'string' && obj.nextCursor.length > 0+ ? obj.nextCursor+ : null+ return { cves, nextCursor }+}++// Fetch the current cve.now feed and return it severity-sorted (worst first),+// ready for the onboarding top-N picker. Follows the cursor across pages until+// it has gathered `limit` entries or the feed runs out, de-duplicating ids. The+// first page failing throws so the UI can show a retry; a later page failing+// keeps what we already gathered rather than losing the whole list.+export async function fetchLiveCves(+ limit = 50,+ signal?: AbortSignal,+): Promise<FeedCve[]> {+ const cves: FeedCve[] = []+ const seen = new Set<string>()+ let cursor: string | null = null+ for (let page = 0; page < MAX_FEED_PAGES && cves.length < limit; page += 1) {+ const url = new URL(CVE_NOW_ENTRIES_API)+ url.searchParams.set('limit', String(limit))+ if (cursor) url.searchParams.set('cursor', cursor)+ let res: Response+ try {+ res = await fetch(url, { signal, headers: { accept: 'application/json' } })+ } catch (err) {+ if (page === 0) throw err+ break+ }+ if (!res.ok) {+ if (page === 0) throw new Error(`cve.now feed responded ${res.status}`)+ break+ }+ const { cves: pageCves, nextCursor } = parseEntriesPage(await res.json())+ for (const cve of pageCves) {+ if (seen.has(cve.id)) continue+ seen.add(cve.id)+ cves.push(cve)+ }+ cursor = nextCursor+ if (!cursor) break+ }+ return cves.sort((a, b) => severityRank(b) - severityRank(a)).slice(0, limit)}// cve.now's MCP server. `check_stack` matches a repository's lockfile against