/** * 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 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