# Dynamic Workflow: Presentation (spec) Status: implemented. This document describes how a workflow is drawn, before and during a run: the display payload the tool hands the GUI, the timeline built from it, the live-run overlay, and the surfaces that show them. The analyzer that produces the graphs is `apps/zcode-cli/packages/dynamic-workflow/docs/analysis.md`; the engine that produces the run events is `apps/zcode-cli/packages/dynamic-workflow/docs/execution-engine.md`; the launch flow around the confirmation window is `docs/dynamic-workflow/launch.md`; the completion card, notifications and the script transcript are `docs/dynamic-workflow/transcript-and-notifications.md`. ## What the user sees A workflow is drawn as one horizontal **timeline**: a rail, with the script's phases as **stations** on it, the subagents of each phase as **pills** hanging under their station, and the control-flow edges that skip or loop as **arcs** in the air above the rail. Phases whose subagents run at the same time stand on parallel **tracks** between a fork and a merge. The same timeline appears in three places, and all three build it with one pure function, `buildWorkflowTimeline(graph, run)` (`packages/ui/src/components/workflow-timeline/timeline-model.ts`): | Surface | What it draws | Run data | |---|---|---| | The `CreateWorkflow` and `AmendWorkflow` tool rows in the chat | while the model is still writing: the phase line alone, written out by a pen; after that a one-line summary | none | | The confirmation window | the full timeline, static, above the collapsed script | none | | The run card under the turn (`WorkflowRunDigest`) | the timeline, live: lamps, pills and ink follow the run | `workflowRuns` | | The run side pane | the same model read vertically as a **spine**: one section per phase, pills as rows, questions under their asker, artifacts at the bottom | `workflowRuns` | The timeline changes shape during a run in exactly one way: at a **fill**, when the main agent writes the body of a hole and a new display payload for the effective script replaces the old one ("Holes on the timeline"). Between fills the set and order of stations, rails and arcs is fixed; a run only changes lamps, pill status and ink, and can only add pills (when one card splits into per-instance cards). There is no picture of the run's end: the last station is the last phase, and nothing marks "may finish here". Status is never colour alone. Every lamp sits next to a word or an icon with an `aria-label`, and a `pending` pill is pixel-identical to a static one. ## The display contract The GUI never sees the analyzer's graphs. A bounding layer in `packages/core`, `boundCausalityGraph(causality, flow, handoff)` (`apps/zcode-cli/packages/core/src/tool/handlers/create-workflow-graph-bounds.ts`), folds the causality graph, the control-flow graph and the hand-off graph into one display payload, `causalityGraph` (the field keeps its historical name). The same payload rides the confirmation request's `display` and the tool output that is persisted on the tool row, so the confirmation window, the tool row and the run pane read one contract. Three schemas mirror it field for field: `apps/zcode-cli/packages/contracts/src/tools/create-workflow.ts` (the authority), `packages/shared/src/zcode-protocol-v4/create-workflow-display.ts`, and the v3 protocol; all are `.strict()`. ```ts interface CreateWorkflowCausalityGraph { steps: Step[]; // ≤ 64: ask / world-read sites; the join key for run status lanes: Lane[]; // ≤ 32: actors, plus `workspace` / `unknown` participants: Participant[]; // ≤ 64: one card per (phase, lane), in hand-off order handoffs: Handoff[]; // ≤ 256: {from, to, back?, types?} between participants phases?: Phase[]; // ≤ 32: {id, name?, line?, column?, alongside?}, first-reach order phaseEdges?: Edge[]; // ≤ 128: {from, to, back?} between phases phaseStreams?: Stream[]; // ≤ 128: {from, to} — phase `from` feeds phase `to` while both run exits?: string[]; // phases after which control flow can complete normally sink?: string[]; // steps whose artifacts reach the return holes?: Hole[]; // ≤ 32: {siteId, name, type, phase?, tail?}, the open holes in source order; // a phase or step written by a fill carries `fill: `; // a hole's own phase carries the hole enclosing it truncated?: true; } interface Step { id; kind: "ask" | "world-read"; label; labelPattern?; line?; column?; lane; lanes?; source?; phase?; repeat?: "stack" | "serial" } interface Lane { id; name?; namePattern?: { head?; tail? }; line?; column? } interface Participant { id; phase; lane; steps: string[]; member?: { index; of }; many?: true } ``` Ids are at most 64 characters, names and labels at most 128. **One arrow.** An edge says one thing, "runs after", and carries one optional mark: `back` for a loop's back edge. The analyzer's edge kinds, certainty and exactness, its regions and a step's region and certainty never enter the payload; the GUI draws none of them. Phase edges are the control-flow quotient (see analysis.md, "The control-flow graph"), so an arrow between phases answers "where can execution go next", not "which phase must precede which". Hand-offs are the causality graph quotiented by participant (analysis.md, "The hand-off graph"). Both are reduced before they are sent. **Bounding order.** The collections reference each other, so the layer cuts them in a fixed order and keeps referential integrity over retention: the UI must never receive an id that points at nothing. 1. Steps: the first 64 in source order. 2. Lanes: only the lanes surviving steps stand in, in graph order, then the first 32. A step whose own lane was dropped goes; a may-set step merely narrows. 3. Participants: a card's `steps` narrow to the surviving ones and a card left with none goes; then the first 64 in the analyzer's order (the opener survives, the tail does not). Hand-offs touching a dropped card go with it, then the first 256; each hand-off keeps at most 8 `types`. A dropped card's steps stay in `steps`, so run status still joins on them; they just have no card. 4. `sink`: the surviving steps among the analyzer's `fedBy`. 5. Phases: the control-flow graph's phase table, whole, including marker-only phases (a position control passes through must show). Phase edges: drop any edge touching `entry` or `abort`; an edge into the flow `sink` becomes an entry in `exits`; drop self-loops; fold the rest per ordered pair, `back` only when every folded edge was a `loop`; then reduce (below). If the phase table exceeds 32 or the reduced edge list exceeds 128, the **whole vocabulary** is dropped: `phases`, `phaseEdges`, `exits` and every `Step.phase` go together, and `truncated` is set. Half a phase picture would lie. A participant whose phase is not listed is re-homed to `unphased`; its id does not change. 6. Phase streams (below): cut at 128 after the phase edges; more than 128 drops the whole vocabulary the same way. `phases`, `phaseEdges`, `phaseStreams`, `exits` and `Step.phase` are all-or-nothing: a script with no `phase()` marker has none of them, and `exits` may be empty inside the group (a script with no normal completion path) but never appears outside it. `phaseStreams` is omitted inside the group when there are none. **Alongside.** A phase carries `alongside`: the listed phases whose strands were still running when this phase was entered (analysis.md, "Strands and frames"), in phase-table order, at most 32 ids, omitted when empty. It is a **node fact**, not an edge. Control did not pass from those phases to this one; both are simply in flight. So it never enters `phaseEdges` and never goes through the reduction, which would read it as "runs after" and cut a real edge in its name. The bounding layer copies it from the control-flow projection under the same referential integrity the edges get: a reference to an unlisted phase is dropped, the phase's own id is dropped, the rest are deduplicated in order and cut at 32. It rides the vocabulary all-or-nothing with `phases`, `phaseEdges` and `exits`. **Streams.** A stage written as a `future` that hands items to the next stage through a channel (authoring.md, "Streams") is concurrent with it, so the control-flow view relates the two only by `alongside` and has no arrow between them: a five-stage pipeline arrived as five unrelated strands. The **causality** view does see the hand-off: a `send` is a container write and the `for await` reads it back, so the causality phase quotient carries a `data` edge from producer to consumer. A **phase stream** `{from, to}` is such an edge whose two ends are alongside each other (either one's `alongside` lists the other): two live strands can exchange data only through a shared container, which is what a stream is. A `data` edge into a phase that is not alongside — the writer after `await Promise.all([...stages])` — is already the control arrow's business and is not a stream, and two futures with no channel between them have no `data` edge and stay two strands. The bounding layer reads `causality.phaseEdges` for kind `data`, drops self-loops, edges touching an unlisted phase and pairs that are not alongside, dedupes per ordered pair in the analyzer's order, and cuts at 128. A stream is not a `phaseEdge` and never goes through the reduction (the causality quotient arrives reduced); an arrow still means only "runs after". The analyzer does not see a feedback channel (a consumer's later `send` into a producer's channel follows the producer's read in walk order), so every stream it produces today points from an earlier strand to a later one; the UI draws whatever direction arrives. **Untyped reduction.** The folded phase edges are fed to the analyzer's `reduceOrdering`, exported for exactly this purpose: every forward edge as one kind, every back edge as a carry. That turns the typed reduction into an untyped one, which is what a single arrow style needs: the drawn set is an irredundant generating set of the "runs after" relation, reachability unchanged, no forward edge implied by a path of length two or more, no back edge implied by forward → one back hop → forward, back edges never serving as witnesses. It reduces the **condensation**, not the graph itself (`create-workflow-graph-fold.ts`). Take the strongly connected components of the folded forward edges — back edges are excluded, because they say "next round", and counting them would shrink a whole loop body to one point and leave its genuinely redundant edges undeletable. An edge whose two ends share a component survives unconditionally; only the inter-component edges are reduced, deduplicated per component pair and kind, and the survivors are expanded back over the raw edges. A witness that passes through a node sharing a cycle with either endpoint asserts nothing about whether control can reach the target directly, so it may not delete an edge. Two independent choices reusing the same pair of phase names are the case that forces the rule: the quotient carries `left → right` and `right → left` as ordinary branch edges, and reducing the raw graph deletes `choose → left` on the witness `choose → right → left`, drawing a picture that says the branch always goes right and `left` is a detour off `right`. Interleaved phases (`a; b; a`) are one component for the same reason and keep their forward edges both ways. Hand-offs arrive already reduced by the analyzer and are only truncated here. **Text.** Names, labels and pattern affixes come from script literals, so they are cut with a surrogate-safe slice: a boundary that lands after a high surrogate drops the half character. An empty actor name or phase name becomes an absent `name` (the UI localizes the fallback); an empty ask label falls back to the step id; a pattern whose affixes are both cut away is omitted rather than sent as `{}`. **Old payloads.** The schema is strict and has no compatibility shim. A persisted display that carries fields the schema no longer knows fails `safeParse`, and the tool row falls back to plain text with no graph. That fallback is now the *whole* cost of an unknown field: since 2026-09-21 the v4 envelope carries every display payload as `.optional().catch(undefined)`, so a payload this side cannot read is dropped and the frame is still delivered (`docs/v4-refactor/10-protocol-spec.md` §4.4.5). Before that, a strict display failure rejected the entire frame and took the subscription down with it — twice, for one added key each time. Two exceptions are handled, both by the same pre-parse scrub in `apps/zcode-cli/packages/contracts/src/tools/tool-result-metadata.ts` that the two parse entry points share. Displays persisted while the withdrawn name-refinement feature existed carry `refinedName` on lanes and phases and `refinedLabel` on steps, and those three keys are stripped. Persisted `get_workflow_run` displays carry `providerStop` on their `error`, written while the card reused the tool output's error schema, and that key is stripped too. **Who reads what.** `phases` and `phaseEdges` become stations, rails and arcs, `alongside` becomes bands, and `phaseStreams` become stream rails and take strands out of their band. `participants` become pills, in payload order. `steps` and `lanes` are the join key and the naming material. `sink` decides whether the implicit phase of an unmarked script counts as an exit. `handoffs` and `exits` are transported and validated but no component reads them today (see "Open questions"). ## The timeline model `buildWorkflowTimeline(graph, run)` is a pure function with no React, no DOM and no clock. Its output: ```ts interface WorkflowTimelineModel { stations: TimelineStation[]; // one per phase, declared order rails: TimelineRail[]; // two stations next to each other on one track arcs: TimelineArc[]; // every other edge bands: TimelineBand[]; // parallel phases, ascending by `from`; empty without `alongside` runningIndex?: number; // the running station (rightmost if several) live: boolean; // a run took part draft?: { agents: number }; // only the pen's model has this } interface TimelineStation { id; naming: { id; name? }; pills; status?; visited; rounds; onLoop; track; fraction?; typing? } interface TimelineRail { from; to; ink; kind?: "fork" | "merge" | "twin" | "stream" } // absent kind = a plain rail on one track interface TimelineArc { from; to; lane; ink; air; stream? } // `air` = whose track's air it flies in interface TimelineTrack { stations: number[]; entry: TimelineInk; exit: TimelineInk } interface TimelineBand { from; to; pred?; join?; tracks: TimelineTrack[] } // inclusive range; tracks[0] = the main line interface TimelinePill { key; lane: LaneRef; laneClass; runtimeName?; avatarIndex?; status?; instance?: { siteId; ordinal; sessionId? }; slot?: { siteId; ordinal }; workspace?: { phaseId }; stepIds; asking? } type TimelineInk = "faint" | "strong" | "march"; ``` **Cost.** The model is linear in the run: one pass indexes the listed nodes by `(actorSiteId, actorOrdinal)` and every card reads that index instead of re-scanning `run.nodes`, so a build costs O(actors + nodes) and never their product — at the table bound of 1024 actors and 1024 nodes the product is a million comparisons per frame. The model is also built **once per `(graph, run)` pair** and shared by every surface: the graph and the run state are immutable protocol objects (a changed run arrives as a new object), so `buildWorkflowTimeline` memoizes on their identity and the second surface of a frame — the run card and the run pane draw the same run side by side — pays a lookup, not a build. **The implicit phase.** A script with no markers has no phase vocabulary. The UI gives it one phase, id `workflow` (localized "Workflow"), before anything else: every step and card is re-homed to it, there are no phase edges, and `exits` is `[workflow]` when the script returns something. `withImplicitPhase` returns a graph with a vocabulary unchanged (reference-equal, so memoization holds). The analyzer's own `unphased` (localized "Ungrouped") means "before the first marker" and is a different phase. **Stations** are the payload's `phases` in declared order, which is the order of first `phase()` markers. There is no ranking: two sibling phases that share only a predecessor stand in declared order, and the edge between them becomes an arc — or, when the two are parallel, nothing at all, the fork having said it already. **Rails and arcs.** Each phase edge whose endpoints are both listed and distinct is folded once per ordered pair and becomes a rail or an arc; the classification is below, the rails first and then what a band does to the edges that touch it. An arc is a **back edge** when its target is to the left of its source; the payload's `back` mark is not consulted, because the analyzer classifies a re-entry (a second `phase("plan")` marker) as a forward edge and on the timeline it still points left. A station is `onLoop` when it is the source or target of a back edge, and every member of a band is `onLoop` when a back arc touches the band; only such stations show a round count. **Bands and tracks.** `foldPhaseBands` (`timeline-bands.ts`) turns `alongside` into the picture. It works on station indexes alone, with no ids, no ink and no pixels, so the sidebar's mini rail shares it (see "The sidebar run line"). The relation is symmetrized first: only the later phase can report the earlier one, and on screen the two are equals. Connected components with two or more members give the intervals `[min, max]`; overlapping intervals merge, and every index inside an interval is a member, gaps closed for robustness (they do not occur without loops). A **band** is one such interval. Its members are split into **tracks** by greedy interval colouring in declared order: each member takes the lowest track none of whose members is parallel to it, else opens a new one. The first member therefore always takes track 0, the **main line**. A station outside every band has `track: 0`. **Streams take strands out of the band.** With `phaseStreams` (see "The display contract"), two members are parallel *for the colouring* only when neither reaches the other along stream edges: a stage and every stage downstream of it are one line of work, however concurrently they run, and belong on one track in declared order. A band whose members all land on one track is **dissolved**: it is not a band, its stations stand on the main line with no fork, no merge and no twins, and they are joined by the rails below. A five-stage pipeline is therefore five stations in a row. A strand no stream reaches (a side future) still takes a track of its own, and the band stays a band around it. `foldPhaseBands` takes the streams as an optional third argument; the sidebar's mini rail passes none, so its bands are the `alongside` bands (see "The sidebar run line"). A band's `pred` is `from − 1` and its `join` is `to + 1`, each only when that station stands outside every band and an edge runs from it into a member, or from a member into it. Two bands standing next to each other have neither; what lies between them is a plain rail. **Rails.** A rail joins two stations that stand next to each other on one track. There are five kinds: 1. two adjacent stations outside every band with an edge between them, as before; two adjacent stations with no edge have no rail, and the rail never lies; 2. two consecutive members of one track, **unconditionally**: a track is one strand, and the edge between two of its members may have been reduced away — in an overlap chain `A → C` stands for `A → B → C` with B on the other track, and the strand would otherwise break; 3. `pred` → the first member of each track, plain for track 0 and `fork` above it; 4. the last member of each track → `join`, plain for track 0 and `merge` above it; 5. `twin`, between two declared-adjacent members of one band that sit on different tracks. Only the ledge and the sidebar read a twin; the card and the spine never draw one, and it never marches. It says "these two are parallel", not "control went this way". 6. `stream`, for a phase stream between two stations that stand next to each other on one track: two adjacent stations outside every band (a dissolved band's, typically), or two consecutive members of one track. It replaces the plain rail of the same pair. It says "feeds, while both run", not "runs after". A phase stream that is not adjacent on one track becomes an **arc** with `stream: true`: in that track's air when both ends share a band track, else in the top air. A stream between two tracks of one band is not drawn; the fork and the merge already say the two run together. A track's `entry` is the ink of its fork, or, with no `pred`, strong iff its first member is visited; its `exit` is the ink of its merge, or, with no `join`, strong iff its last member is visited. The spine inks the branches of its fork and merge rows from those two. **Edges with bands.** A band is one node to an edge. For a folded edge `(f, t)`, with `B(x)` the band of `x`: - **same band, same track**: consecutive on the track → nothing, the strand already says it; otherwise an arc in that track's air. - **same band, different tracks**: a forward edge is dropped, because the fork already said control passed through both; a back edge becomes the band's self-loop, an arc re-rooted to `from = B.to`, `to = B.from`. - **one end in a band**: absorbed as the `pred` or the `join` when the outside end is adjacent to the band; otherwise an arc re-rooted to the band's last station when it leaves and its first station when it arrives, in the top air. - **two bands**: an arc from the first band's last station to the second band's first station, or a plain rail between them when the two bands stand next to each other. - **both outside**: a rail when adjacent, else an arc, as before. Arcs are deduped per air and endpoint pair after the re-rooting. An arc's **air** is the track whose air it flies in: an arc inside one track stays in that track's air, everything else goes to the top one, `R − 1` for `R` the largest track count of any band and at least 1. Without bands there are no bands to fold, every station has `track: 0`, every arc `air: 0`, and the rails are the ones the old rule produced, rail for rail. **Arc lanes.** Arcs are assigned heights by greedy interval colouring (`assignArcLanes`): sorted by span, shortest first (payload order breaks ties), each arc takes the lowest lane on which no already-placed arc intersects it in station index, intersection counted on closed intervals (two arcs sharing an endpoint would merge their vertical segments). Arcs that do not touch share a height; nested arcs stack inner-low, outer-high; only arcs that cross are pushed up. Lanes are assigned **per air** (`assignAirLanes`): two arcs that fly in different airs never push each other up, however much they cross in x. `arcLaneCount` is the highest lane plus one, asked per air, and sets how much air the renderer leaves above that track's row. Lanes keep two arcs that share a station apart in height; the terminal slots (see "Rails and arcs" under "Drawing the timeline") keep their verticals apart in x. **Pills.** The pills of a station are that phase's participants from the live participant view (see "Splitting cards by instance"), in payload order, which is hand-off order with the opener first. The main agent's lane (`main`) never makes a pill: its only steps are open holes, and an open hole is drawn as its own station (see "Holes on the timeline"), not as a subagent of the phase that holds the `hole()` call. A pill's name is the runtime name the engine reported for its bound instance when there is one, otherwise the lane's display name (see "Names"). `avatarIndex` is assigned by first appearance of `lane@ordinal` across the whole timeline, so the same subagent keeps its face across phases and the first nine subagents never share a colour. In a live run an agent pill carries `slot`, the identity it hands over when clicked: the instance's ordinal when there is one, otherwise the ordinal it will get, `member.index + 1` for a member card and 1 for a single or `many` card (the engine numbers ordinals per site in order). A workspace pill carries `workspace: { phaseId }` instead. A pill is `asking` when `run.pendingQuestions` names its instance. **Run entry records.** A station is matched to `run.phases[]` by **name**: exact match first, and when the display name is exactly 128 characters (the bound), a prefix match on the runtime name (`phaseNameMatches`, `phase-name.ts`). The same rule decides whether a station is `run.currentPhase`. A phase with no name (`unphased`, `workflow`) never matches. **What a station observes.** `observePhase` walks `run.nodes` and keeps those whose site id is one of the station's member steps (`step.source ?? step.id`, the same key the overlay uses) and whose birth phase belongs to this station (see "Narrowing by phase"). From them: `visited` (any node, or an entry record), `rounds` (the largest node ordinal, or the entry record's `rounds`, whichever is larger), and `fraction` = settled / observed, absent when nothing was observed. **Station status.** A **stage** — a station with any `alongside` partner or any stream, and at least one member step — takes its lamp from its own nodes and from the stages that feed it, never from `currentPhase` or its entry record. Every stage future runs its marker the moment it starts, so "entered" and "current" say nothing about it: in the triggering run all five markers ran within 108ms, a stage still waiting on its channel read `done`, and the last stage (the one `currentPhase`) took the run's final state without having run a node. The stage rule: 1. no node observed: `pending` while the run is `pending` or `running`; after it ends, `done` when the run `completed` and the station was entered, else `pending`; 2. else the fold's value, except that a `done` stage stays `running` while the run is live and a stage feeding it (a stream source) is **open**. A stage is open while the run is live and it is `running` or `pending` by the fold (no node counts as pending), or a stage feeding it is open — a fixpoint, so a feedback cycle terminates. A station that is not a stage, or a stage with no member steps (a marker-only phase), keeps the sequential rule. Member nodes speak first, then control flow: 1. If the member steps fold (see "Folding statuses") to `running` or `failed`, that. 2. Else if the station is `currentPhase` and the run is `pending` or `running`: `running` (control flow is here between the first dispatch and the next marker). 3. Else if it is `currentPhase` and the run has ended: `done` for `completed`, `failed` otherwise (the failure happened in this phase whether or not it has nodes; a stopped run draws like a failed node). 4. Else the fold's value if it has one. 5. Else `done` if the station was entered, `pending` otherwise. Without a run every station is `undefined`, every pill `undefined`, every rail and arc `faint`, no rounds, no fractions. **Ink.** A rail is `strong` when both its stations are visited, else `faint`. A back arc is `strong` when its source is visited and its target has `rounds ≥ 2`; a forward arc when both ends are visited. A stream rail or stream arc is `march` when both of its stations are `running` (items are crossing now), else `strong` when its target is visited (something crossed), else `faint`. A stream arc is not a loop: it never makes a station `onLoop`. **March** is the ink of the edge control flow took into a running station, and it is decided once per running station rather than once for the timeline: two tracks of one band can be running at the same time, and each wants its own way in. For a running station `r`: 1. a re-entry back arc landing on `r`, or on `B(r).from` when `r` is in a band, with a visited source and `rounds(r) ≥ 2`, marches, and nothing else into `r` does; 2. else every non-twin rail into `r` from a visited source marches, so a join gets its main-row piece and every merge, and the first member of a branch gets its fork; 3. else one arc landing on `r` from a visited source. Stream rails and stream arcs take no part: their ink was decided above and says whether items are crossing, not which way control came. `runningIndex` is still the rightmost running station; it is what the camera follows, not what marches. The projection has no timestamps, so this is the most honest answer available and a known approximation. `pillActivity(graph, run, pill)` counts a pill's ask steps and world-read steps and names the step that is running (else the last settled, else the first); the pane shows the counts, not the label. ## Joining runtime instances The analyzer never learns from a run. The engine reports instances `{siteId, ordinal}`, and the GUI decorates the static picture by site id (analysis.md, "Joining runtime instances"). ### Node status `statusOfRunNode` maps a node's lifecycle phase to the four-value `StepRunStatus`: | Node phase | Status | Why | |---|---|---| | `executing`, `repairing`, `nudged` | `running` | a model request is out | | `settled` with outcome `ok` (cached included) | `done` | | | `settled` with outcome `failed` or `cancelled` | `failed` | the journal tells them apart; the four-value picture does not | | `queued`, `dispatched`, `waiting` | `pending` | no request is at the provider yet | ### Folding statuses `aggregateRunStatuses` is the only fold, applied to a multiset of instance statuses: - an empty set folds to `undefined`: **absence is not a status**, and no fold invents one; - any `running` → `running`, deliberately ahead of `failed`: the reader most needs to know whether anything is still moving; - some settled and some queued → `running`: started, not finished; - all queued → `pending`; - all settled → `failed` if any failed, else `done`. All four rules are "any" tests, so folding per site and then per participant gives the same result as folding the instances directly. `collapseStatuses(stepIds, table)` collects the entries that exist and folds them; a step with no entry does not take part. ### The overlay `workflowRunOverlay(run, graph)` (`components/workflow-graph/run-status.ts`) returns a **partial** table `statuses: Partial>`: a step no instance was observed for has no entry. "Never ran" and "queued" must not share a value; when they did, a branch whose other arm never runs (a ternary receiver, an `if` without `else`, a skipped `catch`, an unselected may-set copy) dragged its whole station to `pending` after it had finished. Each step becomes a target keyed by its **site id**, `step.source ?? step.id`. A may-set copy (`ask#2~actor#1`) and a phase copy (`ask#1~phase#3`) share a site with their siblings, so a node found by site id is admitted to a target only if it passes that target's claims: - **lane**: a copy with `source` admits only nodes whose `actorSiteId` equals its lane. A node with no `actorSiteId` is admitted to every copy of the site (over-lighting, never a dark picture). A step without `source` makes no lane claim: the single card drawn for a receiver with more than four candidates may run on any of them. - **phase**: a step with `phase` admits only nodes whose birth phase belongs to that phase, decided by the phase binder below. A node whose site id is not in the graph is ignored; the overlay never adds or removes nodes. `animatedEdges` is true when any step is running. ### Narrowing by phase The engine stamps every node and actor with `phaseName`, the name of the phase current when its ordinal was minted (the moment `agent()` or `.ask()` ran, not the moment the event was emitted). The name is the one vocabulary the engine and the analyzer share. `phasesOf(name, graph, runHasVocabulary)` (`instance-phases.ts`) says which display phases a stamp belongs to: | Stamp | Run has any stamp | Belongs to | |---|---|---| | present | — | the phases whose display name matches (`phaseNameMatches`) | | absent | yes | the nameless phase (`unphased` or `workflow`): the analyzer puts pre-marker steps there too | | absent | no | every phase (an older CLI, an older run, an unmarked script) | Whenever the answer would be empty, it is every phase: better a subagent shown twice than a running subagent hidden. `phaseBinder(graph, run)` caches these answers and, when the graph itself has no phases yet, answers "belongs" for everything. The binder is shared by the overlay, the participant view and the station observation, so the three never disagree. Without it a helper called from five phases that fans out twenty subagents each lit all five stations when the first batch ran. ### Splitting cards by instance `liveParticipantView(graph, run)` (`participant-model.ts`) is the one place a card meets its instances. A card's instances are the actors on its lane that left a node on **this card's sites** with a stamp in this card's phase, plus actors that left no node on those sites yet and whose own birth stamp belongs to this phase, sorted by ordinal. On a run with no stamps this reduces to "every actor on the lane", the older behaviour. | Card | Instances | Result | |---|---|---| | `many` (family of unknown size) | 0 | the card stays, status by step fold | | `many` | ≥ 1 | one card per instance, id `${id}@${ordinal}`; hand-offs copied to each | | single | 0 | the card stays | | single | 1 | the card **binds** the instance: id unchanged, runtime name shown, status by step fold | | single | ≥ 2 | split like `many`: runtime multiplicity beats static multiplicity | | member `[i]` (literal fan-out) | — | binds the i-th instance by ordinal; none yet → `pending`; instances past `of` get no card | A bound or split card's status is folded from that instance's nodes on the card's sites alone, and an instance with no node there yet is `pending`. A workspace card has no instances and never moves. A run that ended is replayed from the journal, so a reopened session still shows runtime names. ### Names Site ids are identity; names are presentation, and no name is ever a site id. A lane's display name (`laneDisplayName`, `lane-name.ts`) is, in order: the fixed word for a synthetic lane ("Script" for `workspace`, an "unresolved" label for `unknown`); the author's literal `agent("planner")` unchanged (localizing it would rewrite the author); the name pattern rendered as `head…tail` for an interpolated name; else "Anonymous Subagent", numbered `… N` only when two or more anonymous agent lanes coexist, in lane order, patterned lanes not counted. A phase's display name is its `name`, else the localized word for `unphased` or `workflow`. Localization happens at render time, never in the memoized model: the user may switch language mid-session. A pill shows the runtime name over all of these. ## Drawing the timeline `WorkflowTimeline` (`components/workflow-timeline/WorkflowTimeline.tsx`) is plain DOM plus one SVG layer for the arcs. There is no canvas library. ### Geometry | Constant | Value | Meaning | |---|---|---| | `STATION_WIDTH` / `STATION_GAP` / `STATION_PITCH` | 168 / 24 / 192 | five stations fit a 960px column | | `MARK_X` | 17 | lamp centre from the station's left edge, over the pills' face column | | `RAIL_ROW` | 24 | height of the rail row | | `ARC_BASE` / `ARC_LANE` | 26 / 14 | lowest arc lane above the rail's centre; lane spacing | | `TERMINAL_PITCH` | 10 | distance between two arc terminals on one lamp | | `PILL_HEIGHT` / `PILL_GAP` | 32 / 6 | | | `PILL_STAGGER_MS` | 30 | delay between pills landing | | `PLATFORM_ROW` | 24 | height of the caption row; only a banded timeline has one | | `CAPTION_X` | 12 | a caption's left edge from its station's left edge | | `TAIL` / `STUB` | 4 / 6 | the main line's tail before a band with no `pred`, its stub after one with no `join` | `ARC_BASE` must leave room after the 8px corner radius for a downward run long enough to hold the 5.25px arrowhead; at 16 the last segment pointed up by a pixel and the arrowhead vanished. **The rows.** `timelineLayout(arcs, bands)` lays the picture out from the top down and is pure, so `timelineHeight(model)` can be had without rendering: the run card animates its frame between two of these values. There are `R` track rows, 1 without bands and otherwise the largest track count of any band, at least 2. For each track from the top down the layout leaves that track's **air** — 6px for the top row when that air holds no lanes, 0 for the others when theirs holds none, else `8 + 26 − 12 + 14 × (lanes − 1)` counted over the arcs of that air alone — and then a 24px row with the rail down its middle. The main line is therefore the bottom row. After the rows comes the platform row, 24px, only when there is a band; then 8px, the tallest pill column, and 8px for the scrollbar. The whole rail shifts right by an **inset** of 12px when a band starts at station 0, so that the fork has somewhere to stand. Without a band `R` is 1, there is no platform row, and the arithmetic is the old arc air + 24 + 8 + pills + 8 to the pixel. ### The station head A station head is a pill with no background: the lamp (10px) over the faces column, the name (`text-ui-caption`, medium) over the names column, then the metadata in mono: `⟳ n` when the station is on a loop and has rounds, a `·`, and `settled/observed` when nodes were observed. A pending station's name is subtle; others are foreground. The head's `title` is the name, plus "visited n times" on a loop station. Lamps use one vocabulary, `STATUS_DOT` (`run-status-presentation.ts`): | Status | Lamp | |---|---| | `pending` | hollow ring, 1.5px `foreground-subtlest` border | | `running` | filled `warning` with a steady 3px warning halo, beating (below); the only glow on the page | | `done` | filled `success` | | `failed` | filled `destructive` with a 2px destructive ring | **The beat.** The running lamp is the one thing on the timeline that moves on a clock, and it carries the whole statement "work is happening here". `wf-lamp-running` holds the 3px halo steady at 20% warning and beats every 1.6s (`--wf-beat`, declared beside `--wf-ease` on `.wf-motion`): the lamp thumps to 1.12×, peaking at 12% of the beat and back at 40%, and sends out one ring, a second shadow layer born at the halo's edge at 35% warning that widens to 8px past the lamp and fades to nothing by 70%, then rests. The halo never leaves, so the lamp is lit between beats and the ring is the lamp's own light rather than a second glow. The spine's lamp and the ledge's folded lamps carry the same class and beat with it. `running` is `warning`, not `primary`: primary inverts across themes and reads as emphasis; warning is the activity colour in both. Run-level lamps derive from the same table: `RUN_STATUS_DOT` maps `completed → done`, `errored → failed`, and `pending` and `stopped` to the hollow ring (a stopped run is recoverable, not broken). The status word beside a run lamp uses matching text colours and, for `stopped`, appends the reason: "by you", "by the agent", "model error", "process exited". A run whose state carries `resumable: true` appends a third word after the reason, "resumable" / 「可恢复」: the verb on the button says what the action does, not what survives it, so the status line carries the consequence. It is the CLI's status bit, shipped on the run, never derived in the UI from the status word. When the host passes `onSelectStation` the head is a `