/** * The round as text: what `/team` prints, and what `/team who` lists. * * Pure over `(cards, now, roster)`, and that is the claim a reader can check from this header * alone: nothing here imports a store, asks the bus, takes a `pi`, or composes a notice — so every * line is a fact about what the board and the roster already say, and a case can hold it without a * temp directory or a mount. * * `lib/workflow/round-text.ts` owns the rollup's own lines; this module owns the notify's cap, the * presence listing, and the reclaim door `/team` adds to them. `commands.ts` reaches it with an * `import()` inside the handler, so the registration graph never pays for it. */ import { plural } from "../../lib/format.ts"; import { labelKey } from "../../lib/session-label.ts"; import { presenceOf, type RosterSession, rosterStateOf } from "../../lib/session-roster.ts"; import { type Card, cardRef } from "../../lib/workflow/card.ts"; import { buildRound, type RoundSummary } from "../../lib/workflow/round.ts"; import { formatRound, holdingLine, withLiveOwner } from "../../lib/workflow/round-text.ts"; /** * How many of the round's own lines print before it says how many it left out. * * The round is one notify with two growing parts, each bounded at its own number: the rollup at this * many lines, and the verbs a lead may type at {@link MAX_STALLED_LINES}. Each elision says how many * it left out and which surface draws the rest, so neither part can grow into a screen. */ export const MAX_ROUND_LINES = 10; /** * How many reclaim lines print before the rest become one elision. * * Five is the page's number, not a second one: the Team tab's queue folds its rows at five and puts * the rest behind a control, so a lead reading the terminal and a lead reading the tab meet the same * fold and the same count. */ export const MAX_STALLED_LINES = 5; /** * The round as the lines a lead reads: the rollup, then a count of who is live. * * Capped, because a notify is a message and not a screen: past its limit the round says how many * lines it left out and which surface draws the rest, instead of pushing the session up the screen. * The tail is a count and a door, not the paragraph that named every session twice: the rows are * `/team who`'s. */ export function roundText(cards: readonly Card[], now: number, roster?: readonly RosterSession[]): string { if (cards.length === 0) return "team: nothing to report — the board is empty"; // The name an owner is shown by is the one the bus holds now, resolved before anything groups // or compares labels: a rename moves the record and no card, and the rollup, the stalled lines, // and the presence line all speak of owners by their label. const named = cards.map((card) => withLiveOwner(card, roster)); const round = buildRound(named, now); // First of the two bounded parts: the rollup, elided at its own number. const lines = formatRound(named, round, roster).split("\n"); const shown = lines.slice(0, MAX_ROUND_LINES); if (lines.length > MAX_ROUND_LINES) { shown.push(`… ${plural(lines.length - MAX_ROUND_LINES, "line")} more — /board draws the whole round`); } // The second: the verbs a lead can type, folded at the page's own number, with the rest counted // and a door beside the count. const stalled = stalledLines(named, roster, now); for (const line of stalled.slice(0, MAX_STALLED_LINES)) shown.push(line); if (stalled.length > MAX_STALLED_LINES) { shown.push(`… ${plural(stalled.length - MAX_STALLED_LINES, "owner")} more — /board shows them`); } // The tail is the count a reader can ask for whole as `/team who`, so both read one grouping: // `presenceGroups` is the only place this module asks `rosterStateOf`. const who = roster === undefined || roster.length === 0 ? undefined : presenceTail(presenceGroups(round, roster, now), roster.length); if (who !== undefined) shown.push(who); return shown.join("\n"); } /** * The four states, in the order they print, with the word each one heads. * * `who` heads its sections with these words and `who