diff --git a/pm-stack/aggregator/src/derive.ts b/pm-stack/aggregator/src/derive.ts index de405adc74..5d8d7cbf3d 100644 --- a/pm-stack/aggregator/src/derive.ts +++ b/pm-stack/aggregator/src/derive.ts @@ -19,7 +19,7 @@ export interface ExecutionStrip { unknown: RefKey[]; } -const IMPLEMENTING_LABELS = new Set(["status:in-progress", "in-progress", "ready-for-agent"]); +const IMPLEMENTING_LABELS = new Set(["status:in-progress", "in-progress"]); export function executionStrip(links: Link[], items: Map): ExecutionStrip { const strip: ExecutionStrip = { diff --git a/pm-stack/aggregator/src/render.ts b/pm-stack/aggregator/src/render.ts index 18cc3946a7..11368f7ddc 100644 --- a/pm-stack/aggregator/src/render.ts +++ b/pm-stack/aggregator/src/render.ts @@ -1786,6 +1786,8 @@ export interface ItemExtras { epicRollup?: EpicRollup; /** Project-pool briefs for linked refs (#1279). */ briefs?: Map; + /** Real ready-for-agent dispatch state for explicitly labelled linked issues. */ + dispatchStates?: { ref: RefKey; state: string; provenance: { source: string; observedAt: string } }[]; /** The shared audit stream, scoped to the item's canonical refs. */ activity?: { events: AuditEvent[]; globalHref: string; gaps: GapRecord[]; coverage?: readonly ActivityCoverage[] }; } @@ -1871,12 +1873,20 @@ export function renderItem( ? `

Live services: ${extras.serviceLinks.map((s) => `${esc(s.label)} ↗`).join(" · ")}

` : ""; const epicRollup = extras?.epicRollup ? epicRollupHtml(extras.epicRollup) : ""; + const dispatchSection = extras?.dispatchStates?.length + ? `

ready-for-agent dispatch

    ${extras.dispatchStates + .map( + (entry) => + `
  • ${esc(entry.ref)}: ${esc(entry.state)} · ${esc(entry.provenance.source)} checked ${esc(entry.provenance.observedAt)}
  • `, + ) + .join("")}
` + : ""; const activitySection = extras?.activity ? `

Activity stream

View these events in the global river

Freshness: unknown. The ingestion checkpoint records deliveries, not successful source polls. An empty event list does not establish complete coverage. Known gaps and documented source coverage are shown below.

${eventTableHtml(extras.activity.events)}

Known activity gaps

Gap records are source-scoped and do not currently identify affected item refs, so this is the global known-gap list.

${gapsHtml(extras.activity.gaps)}

Activity source coverage

${activityCoverageHtml(extras.activity.coverage)}
` : ""; return layout( title, - `

${esc(title)}

subject: ${esc(subject)}

${epicRollup}${svcLinks}${stripHtml(items, links)} + `

${esc(title)}

subject: ${esc(subject)}

${epicRollup}${svcLinks}${dispatchSection}${stripHtml(items, links)} ${ extras?.briefs ? briefPanelsForRefs( diff --git a/pm-stack/aggregator/src/server.ts b/pm-stack/aggregator/src/server.ts index f815c6ba31..2a3c077bd2 100644 --- a/pm-stack/aggregator/src/server.ts +++ b/pm-stack/aggregator/src/server.ts @@ -135,12 +135,51 @@ import type { Source } from "./source.ts"; import { fixtureSource } from "./sources/fixtures.ts"; import { liveSource } from "./sources/live.ts"; import { buildQueueView, queueInputsStale } from "./queue-view.ts"; +import { dispatchStateFor, fetchRfaState, RFA_NOT_PICKED_UP } from "./sources/ready-for-agent.ts"; const cfg = loadConfig(); const commentsStore = new CommentsStore(cfg.commentsFile); const roadmapAnnotationsStore = new RoadmapAnnotationsStore(cfg.roadmapAnnotationsFile); const coverageStore = new CoverageSnapshotStore(cfg.coverageSnapshotFile); +async function readyAgentDispatchStates(items: Map) { + const targets = [...items.values()].filter((item) => + item.labels.some((label) => label.toLowerCase() === "ready-for-agent") && /#\d+$/.test(item.ref), + ); + if (!targets.length) return []; + const observedAt = new Date().toISOString(); + if (cfg.source !== "live") { + // #4969 (Codex on PR #5283): fixtures mode must never read the live + // harness — deterministic fixture dispatch data, mirroring the + // health.ts fixtures boundary. The canned set has no picked-up + // work item, so every labelled fixture item is honestly + // "not picked up". + return targets.map((item) => ({ + ref: item.ref, + state: RFA_NOT_PICKED_UP, + provenance: { source: "ready-for-agent", observedAt, repository: item.ref.split("#")[0], mode: "fixtures" }, + })); + } + try { + const state = await fetchRfaState(cfg.readyForAgent.baseUrl); + return targets.map((item) => { + const match = /^(.*)#(\d+)$/.exec(item.ref); + if (!match) return null; + return { + ref: item.ref, + state: dispatchStateFor(state, match[1], Number(match[2])) || RFA_NOT_PICKED_UP, + provenance: { source: "ready-for-agent", observedAt, repository: match[1] }, + }; + }).filter((entry): entry is NonNullable => entry !== null); + } catch { + return targets.map((item) => ({ + ref: item.ref, + state: "unavailable", + provenance: { source: "ready-for-agent", observedAt, repository: item.ref.split("#")[0], error: "harness read failed" }, + })); + } +} + /** #1220: the coverage snapshot behind the /projects panel — computed * from the feed's items + the Project pool, rotated weekly by * nextCoverageSnapshot, persisted only when it actually changes. */ @@ -2127,12 +2166,15 @@ async function handler(req: Request): Promise { return json(body); } + const itemJsonMatch = /^\/api\/item\/(.+)\.json$/.exec(path); const itemMatch = /^\/item\/(.+)$/.exec(path); - if (itemMatch) { + const matchedItemPath = itemJsonMatch ?? itemMatch; + if (matchedItemPath) { // #2748: same guard as /discuss — JSON 400 on malformed encoding. - const id = decodePathSegment(itemMatch[1]); + const encodedId = matchedItemPath[1]; + const id = decodePathSegment(encodedId); if (id === null) { - return json({ error: `malformed percent-encoding in path segment: ${itemMatch[1]}` }, 400); + return json({ error: `malformed percent-encoding in path segment: ${encodedId}` }, 400); } const [board, rows] = await Promise.all([source.board().catch(() => []), source.roadmap().catch(() => [])]); const roadmapRow = rows.find((r) => r.subject === id); @@ -2175,6 +2217,14 @@ async function handler(req: Request): Promise { // item page carries the status-request control for that pool item. const pooled = pool.find((p) => refs.includes(p.ref)); const epicRollup = pooled?.kind === "Epic" ? buildEpicRollups(pool).get(pooled.ref) : undefined; + const dispatchStates = await readyAgentDispatchStates(items); + if (itemJsonMatch) { + return json({ + subject, + linkedItems: [...items.values()], + dispatchStates, + }); + } const extras = { dashComments, ...(roadmapRow ? { roadmapAnnotations } : {}), @@ -2194,6 +2244,7 @@ async function handler(req: Request): Promise { : {}), ...(epicRollup ? { epicRollup } : {}), briefs, + ...(dispatchStates.length ? { dispatchStates } : {}), activity: { events: itemEvents, globalHref: `/events?${activityQuery.toString()}`, @@ -2203,6 +2254,9 @@ async function handler(req: Request): Promise { }; return html(renderItem(title, id, links, items, comments, prov(), extras)); } + // #4969 (Codex on PR #5283): an unresolved /api/item/.json id + // gets the structured JSON 404, not the HTML page response. + if (itemJsonMatch) return notFoundResponse(path); return html( `

Not found

no board item or roadmap row with subject ${esc(id)}

`, 404, diff --git a/pm-stack/aggregator/test/boot.test.ts b/pm-stack/aggregator/test/boot.test.ts index a60992bbd7..f0fbd5339b 100644 --- a/pm-stack/aggregator/test/boot.test.ts +++ b/pm-stack/aggregator/test/boot.test.ts @@ -45,6 +45,36 @@ describe("server boots from fixtures", () => { expect(body.source.board).toBe("fixtures"); }); + test("item JSON exposes ready-for-agent dispatch state and provenance", async () => { + const id = "kaneo:code/fx0dispatchtrial0000107"; + const res = await fetch(`http://127.0.0.1:${port}/api/item/${encodeURIComponent(id)}.json`); + expect(res.status).toBe(200); + const body = (await res.json()) as { + linkedItems: { ref: string; labels: string[] }[]; + dispatchStates: { ref: string; state: string; provenance: { source: string; observedAt: string } }[]; + }; + expect(body.linkedItems.find((item) => item.ref === "developing-today/code#762")?.labels).toContain("ready-for-agent"); + expect(body.dispatchStates).toHaveLength(1); + // Fixtures mode is deterministic and never reads the live harness: + // the canned dispatch-trial item has no work item, so its state is + // exactly "not picked up" — never an environment-dependent + // "unavailable". + expect(body.dispatchStates[0].state).toBe("not picked up"); + expect(body.dispatchStates[0].provenance.source).toBe("ready-for-agent"); + expect(body.dispatchStates[0].provenance.observedAt).toBeTruthy(); + }); + + test("unknown item JSON id returns a structured JSON 404", async () => { + const res = await fetch(`http://127.0.0.1:${port}/api/item/${encodeURIComponent("kaneo:code/no-such-item-4969")}.json`); + expect(res.status).toBe(404); + expect(res.headers.get("content-type")).toContain("application/json"); + const body = (await res.json()) as { error: string }; + expect(body.error).toBe("not found"); + const page = await fetch(`http://127.0.0.1:${port}/item/${encodeURIComponent("kaneo:code/no-such-item-4969")}`); + expect(page.status).toBe(404); + expect(page.headers.get("content-type")).toContain("text/html"); + }); + test("front door renders the overview, board lives at /board (#1134)", async () => { const root = await fetch(`http://127.0.0.1:${port}/`); expect(root.status).toBe(200); diff --git a/pm-stack/aggregator/test/render.test.ts b/pm-stack/aggregator/test/render.test.ts index 3839b9816c..2a204b3986 100644 --- a/pm-stack/aggregator/test/render.test.ts +++ b/pm-stack/aggregator/test/render.test.ts @@ -93,8 +93,8 @@ describe("execution strip", () => { expect(strip.merged.map((i) => i.ref)).toContain("developing-today/code#752"); expect(strip.review.map((i) => i.ref)).toContain("developing-today/code#763"); expect(strip.implementing.map((i) => i.ref)).toContain("developing-today/code#900"); - // #762 is labelled ready-for-agent, so it counts as implementing. - expect(strip.implementing.map((i) => i.ref)).toContain("developing-today/code#762"); + // The label alone is not evidence that the harness picked the issue up. + expect(strip.queued.map((i) => i.ref)).toContain("developing-today/code#762"); }); test("records unresolved refs", () => { const strip = executionStrip([{ ref: "nowhere/repo#9999", relation: "tracks" }], items); @@ -304,6 +304,25 @@ describe("render smoke (fixtures)", () => { expect(html).not.toContain("Planning notes"); expect(html).not.toContain("PM-stack design & phase plan"); }); + test("item page shows explicit harness dispatch state with provenance", () => { + const item = FIXTURE_BOARD[0]; + const html = renderItem(item.title, item.id, item.links, items, [], fixtureSource().provenance(), { + dashComments: [], + formRef: item.id, + formOpts: { identities: [] }, + sessions: [], + dispatchStates: [ + { + ref: "developing-today/code#762", + state: "not picked up", + provenance: { source: "ready-for-agent fixture state", observedAt: "2026-11-04T00:00:00Z" }, + }, + ], + }); + expect(html).toContain("ready-for-agent dispatch"); + expect(html).toContain("not picked up"); + expect(html).toContain("ready-for-agent fixture state checked 2026-11-04T00:00:00Z"); + }); test("item activity reuses shared events and discloses unknown freshness and partial coverage", async () => { const src = fixtureSource(); const item = FIXTURE_BOARD.find((b) => b.id.includes("aggregator")) as BoardItem;