/** * The model-facing text for one `team` call. * * A handoff is stated as what happened and what did not: `handed off` names the peer * and the card, a failed send says the card is untouched, and an assignment that lost * a race after the send says the peer should claim it. Nothing here claims the peer * read the message — `delivered` means a message file was written for it. */ import { type Card, cardRef } from "../../lib/workflow/card.ts"; import type { AddTeammateResult } from "../../lib/workflow/config.ts"; import { teamPhrase } from "../../lib/workflow/round-text.ts"; import { sanitizeLine } from "../../lib/format.ts"; import { ALARM_REASON } from "../../lib/session-roster.ts"; import { type DeliveryFailure, notDeliveredLine } from "../../lib/session-tool.ts"; import type { TeamAction } from "./types.ts"; /** * A list of peers as a line prints it. * * A label is another session's text, like a message body or a path: it is sanitized where a sentence * is built, not left to the renderer, because the model reads these lines as well. `notDeliveredLine` * does the same to the failures beside them, so the two halves of one result cannot disagree about * what a peer's name is allowed to contain. */ function namesOf(labels: readonly string[]): string { return labels.map(sanitizeLine).join(", "); } /** * `/team join` landed: the label peers address, whether mail will reach this session, and what the * bar will draw for the name it just took. */ export function formatJoined(label: string, watching: { armed: boolean }, note?: string): string { const line = `team: ${teamPhrase({ label, listening: watching.armed })}.`; return note === undefined ? line : `${line} ${note}`; } /** `/team join` did not land, so nothing about this session changed. */ export function formatNotJoined(reason: string): string { return `team: not on the team — ${reason}`; } /** * What `/team exit` gave up: the name it was addressed by, and the claims that went back. * * The label is said to be free, because that is the fact a session comes back for: nothing else on * the bus holds the name it just left. */ export function formatLeft(label: string, released: readonly string[]): string { const line = `team: ${sanitizeLine(label)} is off the team — its record is gone and the label is free.`; return released.length === 0 ? line : `${line} Released: ${namesOf(released)}.`; } /** `/team exit` did not land, and the bus's own sentence says why. */ export function formatNotLeft(reason: string): string { return `team: still on the team — ${sanitizeLine(reason)}`; } /** * What still holds a session on the team, and the door that would free it. * * A pair rather than a sentence because `formatStillOn` joins the reasons into one head and prints * the doors under it: a reader who leaves twice with the same card is owed the verb, not the * reasoning that led to it. */ export interface LeaveBlocker { /** The fact, as the head sentence joins it: `#935 execute is yours`. */ reason: string; /** The verb that frees it, with the one clause a reader needs beside it. */ door: string; } /** `/team exit` refused: the session is still on the team, and each door under it says why not. */ export function formatStillOn(blockers: readonly LeaveBlocker[]): string { const head = `team: still on the team — ${blockers.map((blocker) => blocker.reason).join(" and ")}.`; return [head, ...blockers.map((blocker) => ` ${blocker.door}`)].join("\n"); } /** * What the join line says after the name: the bar's verdict on a typed label, else where a bare * join's name came from. * * One function because a join makes at most one of the two facts — a typed label is the one door that * writes the team, a picked one is read from it — and a line saying both would be about a change the * reader did not make and a choice they did not make either. Nothing when the team already held a * typed name: the bar names the session either way, and a second sentence would be about a change * that did not happen. */ export function joinNote(named: AddTeammateResult | undefined, picked: string | undefined): string | undefined { if (named !== undefined) { if (!named.ok) return `The bar will not name you: ${named.reason}.`; return named.changed ? "team.teammates now holds it, so the bar names you." : undefined; } if (picked === undefined) return undefined; return "Team name from `team.teammates` — `/team join