0071. Coach text, disclosure and states in `@ci/ui`
Source:
docs/decisions/0071-coach-text-and-states.md. Generated at build time; edit the source file.
Date: 2026-11-22. Status: accepted (M5b Task 3). Builds on ADR 0060 (model text is stored as segments), spec §14 (AI disclosure), DESIGN.md (“Severity and marks”, “Type”, “Semantic states”, B18).
Context
Section titled “Context”Every coach surface of M5b (report, weekly review, weakness notes, the chat) shows text written
by a model. The worker stores that text as resolved segments (Rust ai::segments::Segment) and
a stored ai_disclosure. The web must render both the same way everywhere, must never parse
{{…}} tokens, must show that the text is AI-written, and must show work in progress without a
spinner. @ci/ui must not import from the web app.
Decision
Section titled “Decision”@ci/ui/coach holds five components and a structural copy of Segment (types.ts):
- Segment rendering (
SegmentText).textrenders as text.move,pv,lineandsquarerender in the notation face (Literata 600, lining tabular figures).bestadds the good mark:good-textcolour, the solid good arrowhead drawn inline (shape as well as colour), and “better move” for screen readers.numrenders the server’sdisplaystring; without one, a finitevaluein en-GB, otherwise nothing.daterenders a<time dateTime>in UTC at day precision (“12 Nov 2026”); an unreadable date renders nothing.engrenders its text with a dashedpencilunderline and a visible “engine check” label, as anotenamed “Engine check: …”. - The link rule. A
move,best,pvorlinesegment is a link exactly when the host’shrefForreturns a URL (the web’ssegmentHref).@ci/uibuilds no URLs itself; a throwinghrefForis treated as no link, and only internal paths, fragments and http(s) URLs are emitted (external ones withrel="noopener noreferrer"). - Unknown kinds. A segment whose
kindthis build does not know (or a malformed one) renders nothing and never throws, so a newer worker never breaks an older page. NoNaN,Infinity,undefinedornulltext can come out of a segment. - Disclosure.
AiDisclosureshows the stored label (a quietwellpill), the stored note and “Written on 12 Nov 2026”;compactkeeps the note behind an info button that opens a popover on click, tap or Enter (a 44px touch target), and in screen-reader text. A tooltip was rejected: it never opens on touch. While an answer streams and no disclosure is stored yet, the message shows the fixed label (AI_LABEL, the RustAI_DISCLOSURE_LABEL). A done message with text but no stored disclosure still shows the fixed label. - States (
CoachState).buildingandwritingare a title and body over aProgressPlaceholder(shapelist) whose label says what is happening (“Building 2 / 5 sections”, “Writing”), never “Analysing” and never a spinner (B18).ProgressPlaceholder’s verb gainsBuildingandWritingfor this; existing callers are unchanged.failedandbudgetuse the warning treatment (ink onwell,rule-strongedge, Warning or Clock icon),unavailableandcomputed_onlythe info treatment,emptya plain note; red is never used, because none of these is the player’s mistake. - Placeholder copy. An assistant message that is
pendingwith nothing streamed shows “Your coach is reading your games” as awritingplaceholder. A streaming message adds “Your coach is still writing” under its text; a failed message without server copy says “This answer could not be written. Ask again in a minute.” - Chat. Streamed chunks render in
seqorder; consecutive answer chunks join into one paragraph, and an interim chunk is apencilaside (a dashed pencil ring,ink-softtext). The streamed block settles in on thepenspring on mount (reduced motion: instant). A failed answer hides any partial stream, which was never validated. The message isaria-busywhile pending or streaming, inside a polite live region, so assistive tech reads the answer once. Engine checks read “Engine check: 28. Nd2 e4 29. Nxe4 (done)”, numbered from the check’sstartPly; without one the moves are unnumbered, never counted from move 1. Done, pending (“checking”) and failed checks differ in mark as well as word. The answer’s wrapper is a polite live region only while pending or streaming, so the final text is not read a second time. The composer counts code points as the server does, shows the count from 200 characters left (“1 character over” inpen-text, a form error), sends on Enter, breaks on Shift+Enter, refuses empty or over-limit text, ignores a second send while one is in flight, keeps the text whenonSubmitreturns false, and showsdisabledReasonin place of the send button.
Consequences
Section titled “Consequences”- Every coach page renders model text through one path, so the honesty and token rules are
enforced in one place and pinned by
packages/ui/test/coach.test.tsx. - The component prop is named
roleas the plan’s interface says; Biome’suseValidAriaRoleflags a literalrole="user"on the component, so callers pass it through a spread or a variable.