Files
learnharness/components/phase-divider.tsx
T
amosblomqvist bc1f668e2a Extraction surfaces: sidebar coverage block, chat-bar ring, phase un-pill, panel death
The owner-locked extraction-UX redesign (dispatch 2026-09-24), UI
chunk over Platform's data layer (eed4b4e — GET /api/chats/[id]
carries `coverage`, the threshold is Graph ▸ extractionChunkTokens):

1. SIDEBAR BLOCK (components/extraction-coverage.tsx +
   sidebar's session menu): the coverage info block at the TOP of
   the context menu — uncovered tokens, uncovered messages, running
   state — then the Extract affordance (optimistic "extracting… /
   Running" until the server says running; 409 = benign, the trigger
   raced us), fetched ON MENU OPEN (the block mounts with the menu —
   on-demand, never eagerly), polled at 2s while a run is in flight.
   Visually separated from Rename/Delete by a hairline; those stay
   the two session-management actions. Failed read → nothing (never
   fake zeros).

2. RING METER (CoverageRing, chat top bar, before the PhaseChip):
   a 16px donut filling uncoveredTokens / extractionChunkTokens —
   "how close this session is to its next extraction run". Click →
   the exact numbers (covered/uncovered tokens, messages, the
   threshold, lastFoldedAt via timeAgo). Refresh chains: mount, the
   turn-settle bump (chat.tsx coverageTick), the settings signal
   (threshold/kill-switch re-read live), a 2s drain-poll while a run
   is in flight, and the ACTIVITY FEED — a run for this session
   appearing or settling in the dock's feed re-reads coverage (runs
   fire from other surfaces — the sidebar menu, the turn pipeline —
   and no turn-settle bump announces them; the runs-empty-transition
   the graph view rides). Vanishes entirely when the graph is off or
   before the first honest read. Running = the whole ring PULSES
   (implementer's visual call: motion is the working-state signal in
   this app's quiet register).

3. PHASECHIP UN-PILL: the phase label is a flat tag — no border, no
   rounding, no padding. The Plan chip is the only button-shaped
   thing in the top bar. Drag-surface (pointer-events-none) and aria
   semantics unchanged; the transcript PhaseDivider keeps its look.

4. PANEL DEATH: components/graph-coverage.tsx, its graph-view
   mount, and tests/render-graph-coverage.test.tsx die whole.
   Confirmed: after this, NOTHING client-side consumes GET
   /api/graph/coverage — the only remaining client use of the
   coverage endpoints is the Extract POST (kept, by design); the
   routes stay (Platform's call).

Pure seams exported for tests: ringFill (clamp math),
CoverageMenuBody, CoverageRingGlyph, CoverageRingDetail.
901/901.

Live-verified on :3001: ring fill arcs match the API byte-for-byte
(483/4096 = 4.45/37.70; 1991/4096 = 18.32/37.70); the sidebar block
reads "2k uncovered / 4 messages unextracted"; a real Extract run
went optimistic → dock run → menu settled "fully extracted" AND the
ring drained to the empty arc (the feed chain); graph off → the ring
vanishes; the flat phase label renders chrome-free beside the Plan
pill.
2026-09-24 15:26:22 +03:00

94 lines
4.0 KiB
TypeScript

import type { Phase3 } from "@/src/core";
/**
* The in-session phase presentation (owner, minimal-color round —
* monochrome now): the header chip next to the session title, and the
* dotted boundary rule the transcript draws where the session moves into a
* new phase. Phase COLOR is retired app-wide (phases only advance, so
* color-as-signal was decoration); the label text carries the phase, and
* the chip's old dot slot is repurposed for the braille spinner while a
* turn is in flight — motion is the honest state signal. Replaces the old
* inline plan-divider (artifact registry): the boundary is a MESSAGE-level
* seam, so chat.tsx renders it at the message where the phase changes, not
* inside a tool part.
*
* Quiet register (matches the old divider): hairline rules, small chips —
* never a banner. Probe never renders a divider: phases only advance, so
* probe is the start of the transcript and "Planning"/"Teaching" are the two
* visible seams.
*
* Owner, minimal-color round 2: the chip is LABEL-ONLY, deliberately — a
* working-state spinner was tried here and rejected: the pill's curve and
* the square braille cell fought for space, and the chat surface already
* shows in-flight work (thinking shimmer, the dock). The chip states the
* phase; work-state is the sidebar row's spinner.
*/
/** Header-chip labels: the phases as the learner thinks of them. */
const CHIP_LABEL: Record<Phase3, string> = {
probe: "Probing",
plan: "Planning",
teach: "Teaching",
};
/** The header label: the phase as a quiet flat tag (owner,
* extraction-UX redesign 2026-09-24 — the UN-PILL round): no border, no
* pill chrome, no padding — the Plan chip is the only button-shaped thing
* in the top bar now. Still pure decoration (owner ask, 2026-09-17): no
* tooltip, not selectable, not interactive in any way — no pointer events
* at all, so it is part of the drag surface instead of a carved-out
* target. */
export function PhaseChip({ phase }: { phase: Phase3 }) {
return (
<span
data-testid="phase-chip"
data-phase={phase}
aria-hidden="true"
className="pointer-events-none flex shrink-0 select-none items-center text-xs font-medium uppercase tracking-wide text-muted-foreground"
>
{CHIP_LABEL[phase]}
</span>
);
}
/**
* The transcript boundary: a monochrome dotted rule at the message where
* the session enters `phase` (owner, minimal-color round — the label
* carries the transition; the phase color never did). The plan seam
* carries its node count ("Plan · 4 nodes"); teaching is just the label.
* Null for probe (defensive — the fold never emits a probe transition
* after the start).
*/
export function PhaseDivider({ phase, nodeCount }: { phase: Phase3; nodeCount?: number }) {
if (phase === "probe") return null;
const label =
phase === "plan" && nodeCount
? `Plan · ${nodeCount} node${nodeCount === 1 ? "" : "s"}`
: CHIP_LABEL[phase];
return (
<div className="my-4 flex w-full items-center gap-3" data-testid={`phase-divider-${phase}`}>
<span className="h-0 flex-1 border-t-2 border-dotted border-border/50" aria-hidden />
<span className="rounded-full border border-border/80 px-2.5 py-0.5 text-xs font-medium uppercase tracking-wide text-muted-foreground">
{label}
</span>
<span className="h-0 flex-1 border-t-2 border-dotted border-border/50" aria-hidden />
</div>
);
}
/**
* The node count for a plan seam: the first plan-op tree output in the
* message that carries the seam (the plan_init that made the phase flip).
* Structural slice of a UI message, same shape-of-shapes as core/phases.ts.
*/
export function planNodeCount(
message: { parts: ReadonlyArray<{ type: string; state?: string; output?: unknown; [k: string]: unknown }> },
): number | undefined {
for (const part of message.parts) {
if (!part.type.startsWith("tool-plan_") || part.state !== "output-available") continue;
const tree = (part.output as { tree?: { nodes?: unknown[] } } | undefined)?.tree;
if (tree && Array.isArray(tree.nodes) && tree.nodes.length > 0) return tree.nodes.length;
}
return undefined;
}