Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 32 additions & 3 deletions pm-stack/aggregator/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Design record (source of truth):
| Route | View | Machine-first JSON |
| ----------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------- |
| `/today` | **Today** (slice 2, #898) — the day's top objectives, prioritized, plus per-project momentum (moving / stalled / blocked-by-what, recent accomplishments). From the orchestration job's goal measurements (#899) when a section exists; derived from board + roadmap + item activity, and labelled as derived, until then. | `/api/today.json` |
| `/attention` | **Needs you** (#852, tiered in slice 2) — **NEEDS DREW** (default; only items that genuinely require Drew, each with its reason), **NEEDS ORCHESTRATOR** (the fleet's own queue), then every current session with source labels and plain-language states. Finished runs and stale items expire out. | `/api/attention.json`, `/api/coverage.json` |
| `/attention` | **Needs you** (#852, tiered in slice 2) — **NEEDS USER** (default; the intake queue the orchestrator works first — only items it cannot resolve escalate here, each with its reason), **NEEDS ORCHESTRATOR** (the fleet's own queue), then every current session with source labels and plain-language states. Finished runs and stale items expire out. | `/api/attention.json`, `/api/coverage.json` |
| `/` | **Cross-repo WIP board** — the curated in-flight set across all four repos, with an execution strip per card (implementing → review → merged → queued). | `/api/board.json` |
| `/roadmap` | **Roadmap** — Grist's `Program roadmap` table as a timeline; `?h=` switches the horizon: `quarter` (default), `month`, `week`, `3d`, `today` — one data model at every grain. | `/api/roadmap.json` |
| `/quota` | **Usage & billing** (hub, design 2026-10-25; pools from #851) — needs-attention strip (bubble rules: >80% of a limit, >$5 projected unbilled PAYG), token-quota pools + PAYG dollars card, SaaS service cards grouped by kind with highlight metrics, charges evidence strip. Per-service detail: `/quota/service/<id>`. | `/api/quota.json` (extended: `saas`/`payg`/`charges`/…), `/api/quota/service.json?id=` |
Expand All @@ -40,7 +40,7 @@ that is plumbing, not links).
### Needs-you tiers + session clarity (slice 2, #898)

- **Tiering** (`buildAttention` in `src/derive.ts`): every classified
session lands in NEEDS DREW (with an explainable `drewReason`),
session lands in NEEDS USER (with an explainable `drewReason`),
NEEDS ORCHESTRATOR (with the fleet's next step), or in-motion. Drew
rules, in order: the orchestration job's own classification (#899 —
its tiers win for anything they name, reason verbatim) → a keeper
Expand Down Expand Up @@ -138,7 +138,7 @@ Two kinds, visually distinct everywhere they render:
pass polls `GET /api/comments.json?kind=message&state=new` (and
`?kind=github&state=new` for pending GitHub posts), triages each into
its normal flow — update the item, queue work, escalate to Drew via
the usual NEEDS DREW path; github-kind ones get posted and reported —
the usual NEEDS USER path; github-kind ones get posted and reported —
then marks them consumed with `POST /api/comments/triage { ids }`.
Notes are never polled; they are read from
`/api/comments.json?object=<ref>` when an item is picked up. Item
Expand Down Expand Up @@ -362,6 +362,35 @@ projector-ized live per-source feeds.
in `pm-stack/kaneo-projects.json` (Session H): `code`, `opencode`,
`openchamber` under `developing-today/`, `nix` under `dezren39/`.

## Honesty + freshness (#1139, #1267, #1138)

- **No silent zeros (#1139).** The orchestration section is
diagnosed on every read — live / stale (>90 min) / absent /
invalid (with the failing check named) — via
`diagnoseOrchestrationSection` in `src/feed.ts` and
`Source.diagnostics()`. `/attention` banners an absent, invalid, or
stale tier source at the point of display and renders the tier
counts as "unknown" rather than a confident 0 when the source is
missing; `/today`'s derived-view banner names the section's true
state. The stale/absent banner is also the aggregator-side
dead-man's switch for #1148: if the orchestration job dies, the
surfaces Drew reads say so. Visible tier wording is role-based —
NEEDS USER, not NEEDS DREW (Drew's 2026-10-27 direction; internal
field names and the orchestration contract are unchanged). The
NEEDS USER queue is an intake the orchestrator works first; only
items it cannot resolve escalate to the user.
- **Health primes (#1267).** Provenance strings populate lazily, one
facet per method call, so `/api/health` exercises every facet
(60 s-cached) before answering — its report no longer depends on
which pages were visited since boot. The response also carries the
structured `sections` diagnosis beside the provenance strings.
- **Freshness chips (#1138).** Pages render per-source chips
(source · state · age, counts always with their noun) for exactly
the sources they use, from `Source.provenanceDetail()`; the full
provenance line moves to a collapsed "source detail" disclosure in
the footer. The registry chip counts the merged store total — the
same number the /sessions header renders.

## Design notes — the two new views (#851, #852)

Both were added as **design issues** (2026-10-25) and are implemented
Expand Down
57 changes: 55 additions & 2 deletions pm-stack/aggregator/src/derive.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Pure derivations from the read model: the execution strip, the roadmap
// timeline lanes, and the unified comment stream. No I/O here.
import type { SectionDiagnosis } from "./feed.ts";
import type { Comment, GhItem, Link, RefKey, RoadmapRow } from "./model.ts";

export interface ExecutionStrip {
Expand Down Expand Up @@ -335,6 +336,22 @@ export function tierEntry(e: AttentionEntry, match?: SectionMatch | null): Tiere
return { ...e, tier: "needs-orchestrator", orchestratorNote: ORCHESTRATOR_NOTES[e.state] };
}

/**
* Where the tiers came from, honestly (#1139): when the orchestration
* section is absent, invalid, or stale, the tier counts are not the
* orchestrator's published queues and the page must say so at the
* point of display instead of rendering a confident zero. `present`
* means a valid section was served (stale counts as present — its
* numbers render, badged old).
*/
export interface TierSourceInfo {
present: boolean;
state: SectionDiagnosis["state"];
runId?: string;
generatedAt?: string;
failedChecks?: string[];
}

export interface AttentionView {
drew: TieredEntry[];
orchestrator: TieredEntry[];
Expand All @@ -345,14 +362,34 @@ export interface AttentionView {
all: TieredEntry[];
/** Finished/stale entries dropped before display. */
expiredCount: number;
/** The tier source's diagnosis (#1139); drives the banner + counts. */
tierSource: TierSourceInfo;
}

/** Classify, expire, and tier a raw session feed in one pass. */
export function buildAttention(
feed: SessionFeedEntry[],
section?: OrchestrationSection | null,
now = Date.now(),
diagnosis?: SectionDiagnosis,
): AttentionView {
// The tier source's state (#1139): the caller's diagnosis when it
// has one (the live source tracks it in Source.diagnostics()); else
// derive the coarse form from the section itself — a served section
// is present, a missing one is absent. "invalid" can only come from
// a real diagnosis, since an invalid section never reaches here as
// a section.
const tierSource: TierSourceInfo = diagnosis
? {
present: diagnosis.state === "live" || diagnosis.state === "stale",
state: diagnosis.state,
runId: diagnosis.runId,
generatedAt: diagnosis.generatedAt,
failedChecks: diagnosis.failedChecks,
}
: section
? { present: true, state: "live", runId: section.runId, generatedAt: section.generatedAt }
: { present: false, state: "absent" };
const { current, expired } = partitionFresh(feed, now);
const bySession = new Map<string, SectionMatch>();
if (section) {
Expand Down Expand Up @@ -392,6 +429,7 @@ export function buildAttention(
orchestratorExtra: extras(section?.tiers.needsOrchestrator),
all,
expiredCount: expired.length,
tierSource,
};
}

Expand Down Expand Up @@ -580,6 +618,12 @@ export interface TodayView {
generatedAt?: string;
/** What the orchestrator pushed back into motion (section path only). */
actions?: { at: string; kind: string; target: string; summary: string }[];
/**
* The orchestration section's diagnosis (#1139): the derived view's
* banner names the true state (absent vs invalid vs stale) instead
* of always claiming the job "has not published yet".
*/
sectionDiagnosis?: SectionDiagnosis;
}

const PRIORITY_ORDER: Record<string, number> = { urgent: 0, high: 1, normal: 2, medium: 2, low: 3 };
Expand Down Expand Up @@ -648,8 +692,17 @@ export function deriveToday(
items: Map<RefKey, GhItem>,
section: OrchestrationSection | null,
now = new Date(),
diagnosis?: SectionDiagnosis,
): TodayView {
if (section) return todayFromSection(section);
if (section) {
const view = todayFromSection(section);
view.sectionDiagnosis = diagnosis ?? {
state: "live",
runId: section.runId,
generatedAt: section.generatedAt,
};
return view;
}

// Derived until #899 lands: today's dated roadmap rows first, then the
// board's in-progress work by priority, then what's in review.
Expand Down Expand Up @@ -707,7 +760,7 @@ export function deriveToday(
detail: inProgress ? undefined : "nothing in progress on the board",
});
}
return { fromOrchestrator: false, objectives, momentum };
return { fromOrchestrator: false, objectives, momentum, sectionDiagnosis: diagnosis ?? { state: "absent" } };
}

// ---------------------------------------------------------------------------
Expand Down
53 changes: 48 additions & 5 deletions pm-stack/aggregator/src/feed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,44 @@ export function isOrchestrationSection(v: unknown): v is OrchestrationSection {
return orchestrationSectionProblem(v) === null;
}

/**
* A section older than this at the hourly cadence is stale (#1139,
* #1148's threshold): still served, but every surface that renders its
* numbers must say the data is old instead of presenting it as current.
*/
export const ORCHESTRATION_STALE_MS = 90 * 60_000;

/**
* The diagnosis behind the honesty surfaces (#1139/#1140): a section
* the aggregator holds is in exactly one of these states. "invalid"
* names the failing checks (from orchestrationSectionProblem — the
* gate itself, so the diagnosis can never drift from the validation)
* and is never collapsed into "absent": a publisher whose section is
* being rejected has a bug to fix, not a run that never happened.
*/
export interface SectionDiagnosis {
state: "live" | "absent" | "invalid" | "stale";
generatedAt?: string;
runId?: string;
ageMs?: number;
/** Names of the failing structural checks; never values. */
failedChecks?: string[];
}

export function diagnoseOrchestrationSection(v: unknown, now = Date.now()): SectionDiagnosis {
if (v === null || v === undefined) return { state: "absent" };
const problem = orchestrationSectionProblem(v);
if (problem !== null) return { state: "invalid", failedChecks: [problem] };
const s = v as OrchestrationSection;
const ageMs = Math.max(0, now - Date.parse(s.generatedAt));
return {
state: ageMs > ORCHESTRATION_STALE_MS ? "stale" : "live",
generatedAt: s.generatedAt,
runId: s.runId,
ageMs,
};
}

/**
* A valid section with its provenance in the canonical object form:
* a legacy plain-string provenance becomes `{ sources: [it] }`.
Expand Down Expand Up @@ -174,11 +212,16 @@ export async function loadFeed(path: string): Promise<FleetFeed | null> {
}
}

/** "3m old", "2h old", "fresh" — for an age in milliseconds. */
export function ageMsText(ageMs: number): string {
const ms = Math.max(0, ageMs);
if (ms < 90_000) return "fresh";
if (ms < 3_600_000) return `${Math.round(ms / 60_000)}m old`;
if (ms < 86_400_000) return `${(ms / 3_600_000).toFixed(1)}h old`;
return `${Math.round(ms / 86_400_000)}d old`;
}

/** "3m old", "2h old", "fresh" — for provenance strings. */
export function feedAgeText(generatedAt: string, now = Date.now()): string {
const ageMs = Math.max(0, now - Date.parse(generatedAt));
if (ageMs < 90_000) return "fresh";
if (ageMs < 3_600_000) return `${Math.round(ageMs / 60_000)}m old`;
if (ageMs < 86_400_000) return `${(ageMs / 3_600_000).toFixed(1)}h old`;
return `${Math.round(ageMs / 86_400_000)}d old`;
return ageMsText(now - Date.parse(generatedAt));
}
18 changes: 18 additions & 0 deletions pm-stack/aggregator/src/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,24 @@ export interface Provenance {
aa: string;
}

/**
* One facet's freshness, structured (#1138): the human string above,
* plus the machine state the freshness chips render. `count` always
* ships with its noun (`countLabel`) so a chip can never show a bare
* number that contradicts a page header counting the same thing.
*/
export interface ProvenanceFacet {
/** The provenance string, unchanged — also the chip's tooltip. */
text: string;
state: "live" | "fixtures" | "stale" | "absent" | "invalid";
ageMs?: number;
count?: number;
countLabel?: string;
}

/** Per-facet freshness detail, keyed exactly like Provenance. */
export type ProvenanceDetail = Record<keyof Provenance, ProvenanceFacet>;

// ---------------------------------------------------------------------------
// Quota + throughput view (#851). Machine-first: the same shapes the API
// returns are what the GUI renders. No code from the CCC reference design
Expand Down
2 changes: 1 addition & 1 deletion pm-stack/aggregator/src/pages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export const PAGES: PageDef[] = [
title: "Needs you",
route: "/attention",
api: "/api/attention.json",
blurb: "NEEDS DREW vs NEEDS ORCHESTRATOR, and every live session.",
blurb: "NEEDS USER vs NEEDS ORCHESTRATOR, and every live session.",
},
{ id: "board", title: "Board", route: "/", api: "/api/board.json", blurb: "The curated cross-repo WIP board." },
{
Expand Down
2 changes: 1 addition & 1 deletion pm-stack/aggregator/src/program.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ export const PROGRAM: ProgramDoc = {
{
title: "Slice 2 — mobile, tiers, horizons, Today",
detail:
"Mobile-first views; NEEDS DREW vs NEEDS ORCHESTRATOR with a why-you reason and staleness expiry; roadmap horizons quarter/month/week/3-day/today; the /today view rendering the orchestrator's goal measurements; session source labels (OpenCode sandbox/laptop, Jules).",
"Mobile-first views; NEEDS USER vs NEEDS ORCHESTRATOR with a why-you reason and staleness expiry; roadmap horizons quarter/month/week/3-day/today; the /today view rendering the orchestrator's goal measurements; session source labels (OpenCode sandbox/laptop, Jules).",
refs: [issue(898)],
links: [prLink(901)],
},
Expand Down
2 changes: 1 addition & 1 deletion pm-stack/aggregator/src/project-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,7 @@ export const PROJECT_CONFIGS: ProjectConfig[] = [
{
title: "Plaid / Citi still not linked",
detail:
"Plaid blocks Muse's browser, so linking Citi (Costco, Diamond, Double Cash) needs Drew's own browser session. Several vendor meters are also console-only, so some /quota numbers are dated manual reads rather than live meters.",
"Plaid blocks Muse's browser, so linking Citi (Costco, Diamond, Double Cash) needs the user's own browser session. Several vendor meters are also console-only, so some /quota numbers are dated manual reads rather than live meters.",
},
],
},
Expand Down
Loading
Loading