diff --git a/pm-stack/aggregator/scripts/collect-fleet-feed.ts b/pm-stack/aggregator/scripts/collect-fleet-feed.ts index 3f92b6e31a..b558926a69 100644 --- a/pm-stack/aggregator/scripts/collect-fleet-feed.ts +++ b/pm-stack/aggregator/scripts/collect-fleet-feed.ts @@ -13,16 +13,19 @@ // attribution for the quota view. // - jules-review-state.json — keeper supervision entries annotate // matching sessions as evidence. +// - orchestration.json — the orchestration job's latest section +// (#899: tiers, dependencies, goal measurements), embedded as-is +// after a structural check; absent/malformed = section omitted. // // Usage: bun run scripts/collect-fleet-feed.ts [--out ] // Env overrides: QUOTA_VIEW_PATH, JULES_STATE_PATH, SANDBOX_OPENCODE_URL, -// OPENCODE_SERVER_PASSWORD_FILE. +// OPENCODE_SERVER_PASSWORD_FILE, ORCHESTRATION_PATH. import { readFile, writeFile } from "node:fs/promises"; import { homedir } from "node:os"; import { dirname, join } from "node:path"; import { fileURLToPath } from "node:url"; -import type { FleetFeed } from "../src/feed.ts"; -import type { QuotaPool, SessionFeedEntry } from "../src/model.ts"; +import { isOrchestrationSection, type FleetFeed } from "../src/feed.ts"; +import type { OrchestrationSection, QuotaPool, SessionFeedEntry } from "../src/model.ts"; import { extractQuotaPools } from "../src/quota-extract.ts"; import { computeChoices } from "../src/quota-guidance.ts"; import { mapServerSessions, poolBurn } from "../src/sources/opencode.ts"; @@ -40,6 +43,7 @@ const quotaViewPath = "workspace/goals/stewardship-commission-recurring-review-and-dispatch/hidden_files/visibility/quota-view.md", ); const julesStatePath = process.env.JULES_STATE_PATH ?? join(HIDDEN, "jules-review-state.json"); +const orchestrationPath = process.env.ORCHESTRATION_PATH ?? join(HIDDEN, "orchestration.json"); const serverUrl = process.env.SANDBOX_OPENCODE_URL ?? "http://127.0.0.1:4096"; const passwordFile = process.env.OPENCODE_SERVER_PASSWORD_FILE ?? join(HOME, "tools/secrets.d/opencode-server-password"); @@ -139,16 +143,32 @@ async function main(): Promise { console.error(`collector: sandbox server read failed (${err}); attention empty`); } + // --- orchestration section (#899) -------------------------------------- + let orchestration: OrchestrationSection | undefined; + try { + const parsed: unknown = JSON.parse(await readFile(orchestrationPath, "utf8")); + if (isOrchestrationSection(parsed)) { + orchestration = parsed; + } else { + console.error("collector: orchestration.json failed its structural check; section omitted"); + } + } catch { + // No orchestration file yet (the job has not run) is the normal + // pre-#899 state — omit the section silently. + } + const feed: FleetFeed = { version: 1, generatedAt: now.toISOString(), quota: { pools, burn: [], choices: computeChoices(pools, now.getTime()) }, attention, + ...(orchestration ? { orchestration } : {}), }; await writeFile(outPath, JSON.stringify(feed, null, 2)); const withReads = pools.filter((p) => p.windows.length > 0).length; console.log( - `collector: wrote ${outPath} — ${pools.length} pools (${withReads} with reads), ${attention.length} sandbox sessions`, + `collector: wrote ${outPath} — ${pools.length} pools (${withReads} with reads), ${attention.length} sandbox sessions` + + (orchestration ? `, orchestration ${orchestration.runId}` : ", no orchestration section"), ); } diff --git a/pm-stack/aggregator/src/feed.ts b/pm-stack/aggregator/src/feed.ts index 277bd2cbc6..b0d52e390e 100644 --- a/pm-stack/aggregator/src/feed.ts +++ b/pm-stack/aggregator/src/feed.ts @@ -4,7 +4,7 @@ // record live on the sandbox). The aggregator renders the feed as-is; // a stale feed keeps rendering with its age stated in provenance. import { readFile } from "node:fs/promises"; -import type { QuotaView, SessionFeedEntry } from "./model.ts"; +import type { OrchestrationSection, QuotaView, SessionFeedEntry } from "./model.ts"; export interface FleetFeed { version: 1; @@ -13,6 +13,30 @@ export interface FleetFeed { quota: QuotaView; /** Sandbox-server sessions, pre-classification (render classifies). */ attention: SessionFeedEntry[]; + /** The orchestration job's latest section (#899), when one exists. */ + orchestration?: OrchestrationSection; +} + +/** + * Minimal structural check for an orchestration section, shared by the + * collector (which embeds the orchestrator's file fail-soft) and the + * live source (which serves it). Absent or malformed = "not measured". + */ +export function isOrchestrationSection(v: unknown): v is OrchestrationSection { + if (typeof v !== "object" || v === null) return false; + const s = v as Partial; + return ( + s.version === 1 && + typeof s.generatedAt === "string" && + typeof s.runId === "string" && + typeof s.tiers === "object" && + s.tiers !== null && + Array.isArray(s.tiers.needsDrew) && + Array.isArray(s.tiers.needsOrchestrator) && + Array.isArray(s.dependencies) && + Array.isArray(s.goals) && + Array.isArray(s.actions) + ); } export function isFleetFeed(v: unknown): v is FleetFeed { diff --git a/pm-stack/aggregator/src/model.ts b/pm-stack/aggregator/src/model.ts index efcf1e5ff4..090ee31c5e 100644 --- a/pm-stack/aggregator/src/model.ts +++ b/pm-stack/aggregator/src/model.ts @@ -241,3 +241,110 @@ export function refUrl(key: RefKey, kind: GhKind = "issue"): string { const { repo, number } = parseRef(key); return `https://github.com/${repo}/${kind === "pr" ? "pull" : "issues"}/${number}`; } + +// --------------------------------------------------------------------------- +// Orchestration section (#899): the recurring orchestration job's output, +// carried in the fleet feed and served at /api/orchestration.json. The +// dashboard's today view (#898) consumes it: tiered needs-you items with +// per-item reasons, a flat dependency view, and per-goal measurements. +// The orchestrator republishes the whole section every run; an item +// absent from the newest section has expired out. +// --------------------------------------------------------------------------- + +/** Assignment/measurement horizon buckets (the #899 priority ladder). */ +export type Horizon = "today" | "tomorrow" | "next-3-days" | "longer" | "incoming"; + +export type TierName = "needs-drew" | "needs-orchestrator"; + +/** Where a queue item came from — same source labels as the session feed. */ +export type OrchestrationSource = + | "opencode-sandbox" + | "opencode-laptop" + | "jules" + | "claude" + | "backlog" + | "tracked" + | "github"; + +/** A prerequisite: "blocked by X; X is being worked by session S". */ +export interface DependencyRef { + /** Human label of the prerequisite task. */ + task: string; + /** "owner/repo#123" when the prerequisite is a GitHub item. */ + ref?: RefKey; + status: "in-progress" | "queued" | "stalled" | "done" | "unknown"; + /** Session working the blocker, when one is. */ + workerSessionId?: string; + /** Human label for the worker, e.g. "opencode-laptop · Jules 4259…". */ + workerLabel?: string; +} + +/** One classified queue item in a needs-* tier. */ +export interface TierItem { + /** sessionId | "owner/repo#123" | "jules:" | tracked goal id. */ + id: string; + kind: "session" | "decision" | "task" | "gap"; + title: string; + source: OrchestrationSource; + /** AttentionState for sessions; a free label otherwise. */ + state?: string; + /** One line: why this item sits in this tier. */ + reason: string; + /** ISO: first classified into this tier. */ + since: string; + /** ISO: most recent orchestrator run that still observed the item. */ + lastSeenAt: string; + ref?: RefKey; + sessionId?: string; + /** The pending question, trimmed, for question-stopped items. */ + question?: string; + /** Task items: ladder bucket. */ + horizon?: Horizon; + blockedBy?: DependencyRef[]; + /** The orchestrator's recorded resolution or handoff note. */ + recommendedAction?: string; +} + +/** One task lined up under a goal, with its ladder bucket. */ +export interface LinedUpTask { + title: string; + ref?: RefKey; + status: "in-progress" | "queued" | "blocked" | "done-recently"; + horizon: Horizon; + /** Why this bucket (due date, Drew's pick, NEXT marker, …). */ + horizonWhy: string; + blockedBy?: DependencyRef[]; +} + +/** The orchestrator's measurement of one of Drew's top goals. */ +export interface GoalMeasurement { + /** Tracked/user goal id when known. */ + goalId: string | null; + goal: string; + momentum: "moving" | "stalled" | "blocked" | "no-work-lined-up"; + /** One line. */ + summary: string; + linedUp: LinedUpTask[]; + /** What progressed since the previous orchestrator run, as evidence lines. */ + progressedSinceLastRun: string[]; + stalled: { title: string; since: string; blocker?: string }[]; + /** Findings, e.g. "goal has no tasks lined up". */ + gaps: string[]; +} + +/** The whole orchestration section, as embedded in the fleet feed. */ +export interface OrchestrationSection { + version: 1; + /** ISO timestamp of the orchestrator run that produced this section. */ + generatedAt: string; + /** "orch-" — the producing run. */ + runId: string; + /** Sources + run, human-readable (the section's own provenance). */ + provenance: string; + tiers: { needsDrew: TierItem[]; needsOrchestrator: TierItem[] }; + /** Flat cross-item dependency view for one-place rendering. */ + dependencies: (DependencyRef & { taskRef?: RefKey })[]; + goals: GoalMeasurement[]; + /** What the producing run pushed back into motion. */ + actions: { at: string; kind: string; target: string; summary: string }[]; +} diff --git a/pm-stack/aggregator/src/server.ts b/pm-stack/aggregator/src/server.ts index fd3e3cd362..a121abaa91 100644 --- a/pm-stack/aggregator/src/server.ts +++ b/pm-stack/aggregator/src/server.ts @@ -77,6 +77,12 @@ async function handler(req: Request): Promise { if (path === "/api/attention.json") { return json(await source.attention()); } + if (path === "/api/orchestration.json") { + // #899: the orchestration job's tiers + goal measurements. Absent + // means "not measured yet" — never an empty queue. + const section = await source.orchestration(); + return json(section ?? { status: "absent", reason: "no orchestration run has published yet" }); + } if (path === "/api/health") { return json({ status: "ok", source: prov() }); } diff --git a/pm-stack/aggregator/src/source.ts b/pm-stack/aggregator/src/source.ts index 6c200dce9c..b434376d22 100644 --- a/pm-stack/aggregator/src/source.ts +++ b/pm-stack/aggregator/src/source.ts @@ -5,6 +5,7 @@ import type { BoardItem, Comment, GhItem, + OrchestrationSection, Provenance, QuotaView, RefKey, @@ -25,5 +26,7 @@ export interface Source { quota(): Promise; /** Raw session feed for the "needs you" view (#852), pre-classification. */ attention(): Promise; + /** The orchestration job's latest section (#899); null = not measured yet. */ + orchestration(): Promise; provenance(): Provenance; } diff --git a/pm-stack/aggregator/src/sources/fixtures.ts b/pm-stack/aggregator/src/sources/fixtures.ts index dd8fcb1035..cb14a6e32a 100644 --- a/pm-stack/aggregator/src/sources/fixtures.ts +++ b/pm-stack/aggregator/src/sources/fixtures.ts @@ -525,6 +525,9 @@ export function fixtureSource(): Source { }, quota: async () => FIXTURE_QUOTA, attention: async () => FIXTURE_ATTENTION, + // Fixtures carry no orchestration section: "not measured" is the + // honest fixture state for a job that only runs live (#899). + orchestration: async () => null, provenance: () => provenance, }; } diff --git a/pm-stack/aggregator/src/sources/live.ts b/pm-stack/aggregator/src/sources/live.ts index ad4ab233a6..0d256251bd 100644 --- a/pm-stack/aggregator/src/sources/live.ts +++ b/pm-stack/aggregator/src/sources/live.ts @@ -5,7 +5,7 @@ // provenance strings say exactly which facet is live vs fixture-backed. import { readFile } from "node:fs/promises"; import type { Config } from "../config.ts"; -import { feedAgeText, loadFeed } from "../feed.ts"; +import { feedAgeText, isOrchestrationSection, loadFeed } from "../feed.ts"; import { fixtureSource } from "./fixtures.ts"; import { mapServerSessions } from "./opencode.ts"; import { @@ -480,6 +480,16 @@ export function liveSource(cfg: Config): Source { provenance.attention = "fixtures (no live attention source reachable)"; return fix.attention(); }, + async orchestration() { + // #899: the orchestration section rides the fleet feed, embedded + // by the collector from the orchestrator's own output file. The + // section carries its own provenance; absent = not measured yet. + const feed = await loadFeed(cfg.feedFile); + if (feed?.orchestration && isOrchestrationSection(feed.orchestration)) { + return feed.orchestration; + } + return null; + }, provenance: () => provenance, }; } diff --git a/pm-stack/aggregator/test/orchestration.test.ts b/pm-stack/aggregator/test/orchestration.test.ts new file mode 100644 index 0000000000..b9727e22f7 --- /dev/null +++ b/pm-stack/aggregator/test/orchestration.test.ts @@ -0,0 +1,73 @@ +import { describe, expect, test } from "bun:test"; +import { isFleetFeed, isOrchestrationSection } from "../src/feed.ts"; +import type { OrchestrationSection } from "../src/model.ts"; + +// #899: the orchestration section rides the fleet feed. The collector +// embeds the orchestrator's output file only when it passes the +// structural check; the aggregator serves it at /api/orchestration.json. + +const SECTION: OrchestrationSection = { + version: 1, + generatedAt: "2026-10-25T17:20:00.000Z", + runId: "orch-2026-10-25T17:20:00.000Z", + provenance: "orchestration-pass run orch-2026-10-25T17:20:00.000Z", + tiers: { + needsDrew: [ + { + id: "developing-today/code#812", + kind: "decision", + title: "Decide the public directory feed design", + source: "backlog", + reason: "Scope requires an owner design decision only Drew can make.", + since: "2026-10-25T17:20:00.000Z", + lastSeenAt: "2026-10-25T17:20:00.000Z", + ref: "developing-today/code#812", + }, + ], + needsOrchestrator: [], + }, + dependencies: [], + goals: [ + { + goalId: null, + goal: "Keep the four repos healthy", + momentum: "moving", + summary: "Sweeps merged 3 PRs since the last run.", + linedUp: [], + progressedSinceLastRun: ["PR #888 merged"], + stalled: [], + gaps: [], + }, + ], + actions: [], +}; + +describe("orchestration section validation", () => { + test("accepts a well-formed section", () => { + expect(isOrchestrationSection(SECTION)).toBe(true); + }); + + test("rejects non-objects and wrong versions", () => { + expect(isOrchestrationSection(null)).toBe(false); + expect(isOrchestrationSection("orchestration")).toBe(false); + expect(isOrchestrationSection({ ...SECTION, version: 2 })).toBe(false); + }); + + test("rejects missing tier arrays or goal list", () => { + const { tiers: _t, ...noTiers } = SECTION; + expect(isOrchestrationSection(noTiers)).toBe(false); + expect(isOrchestrationSection({ ...SECTION, tiers: { needsDrew: [] } })).toBe(false); + expect(isOrchestrationSection({ ...SECTION, goals: undefined })).toBe(false); + }); + + test("a fleet feed carrying the section still validates as a feed", () => { + const feed = { + version: 1, + generatedAt: "2026-10-25T17:25:00.000Z", + quota: { pools: [], burn: [], choices: { hasHeadroom: [], burnBeforeReset: [], doNotStart: [] } }, + attention: [], + orchestration: SECTION, + }; + expect(isFleetFeed(feed)).toBe(true); + }); +});