Public: anyone can read this; the crew can change it.
Talk has Display preferences of the person's own, and one small motion vocabulary that never moves what is read #16286
Check · Review · Land · Live done — Landed and live in production.
talk/look-3a-display → main 0 commits 4 threads · 4 unresolved
docs/design/areas/talk.md +1
| @@ -119,3 +119,4 @@ Prior art: Claude and ChatGPT (one centred column, the person's words in a quiet | ||
| 119 | 119 | - `.talk-fill`: how full the context is, a small `meter` and a word, in the head only from 60 %; the figures themselves are `.talk-figures` at the top of the conversation menu. |
| 120 | 120 | - `.talk-figures`: the spend and context lines inside the conversation menu. |
| 121 | 121 | - `.talk-time`: a centred quiet time before the first turn and wherever the conversation paused 30 minutes or more; the time is said once a group, not under every message (a person's message keeps its time for a screen reader). |
| 122 | - `.talk-display`: Display, at the end of the conversation menu: the person's Talk preferences (spacing, motion, Enter, steps) as one plain form of selects (`core/settings.ts`). |
docs/design/size-budget.json +2 −2
| @@ -68,8 +68,8 @@ | ||
| 68 | 68 | "css": 48384 |
| 69 | 69 | }, |
| 70 | 70 | "/talk": { |
| 71 | "js": 34048, | |
| 72 | "css": 52480 | |
| 71 | "js": 34304, | |
| 72 | "css": 52992 | |
| 73 | 73 | }, |
| 74 | 74 | "/:owner/:name/pulls/:number": { |
| 75 | 75 | "js": 32000, |
docs/features/talk-display.md added +29
| @@ -0,0 +1,29 @@ | ||
| 1 | --- | |
| 2 | topic: Tell the crew | |
| 3 | row: Talk display: your spacing, motion, Enter and steps choices, set on the page or in the terminal | |
| 4 | --- | |
| 5 | # Talk's Display | |
| 6 | ||
| 7 | Four preferences of your own for Talk, kept in your settings and read by the page and the terminal alike: set one in either place and the other shows it. | |
| 8 | ||
| 9 | | Choice | What it does | Where it shows | | |
| 10 | | ------- | --------------------------------------------------------------------- | ---------------------- | | |
| 11 | | Spacing | Comfortable, or compact (the spacing scale only, never the type size) | /talk | | |
| 12 | | Motion | As the system says, or reduced (nothing in Talk animates) | /talk | | |
| 13 | | Enter | Sends, or adds a line (Ctrl or Cmd+Enter sends) | /talk | | |
| 14 | | Steps | A reply's steps start folded (one line, "3 steps"), or open | /talk and the terminal | | |
| 15 | ||
| 16 | ## On the page | |
| 17 | ||
| 18 | Open a conversation, then ⋯ → **Display**. Each choice is a select; **Save** keeps them, and the page is drawn with them from its first paint. The form works without the script (`POST /talk/display`, signed in). | |
| 19 | ||
| 20 | ## In the terminal | |
| 21 | ||
| 22 | `ssh <forge>`, `:` → **Conversations**, open one: | |
| 23 | ||
| 24 | - **D** opens Talk display: `j`/`k` move, **Enter** moves the row to its next choice and keeps it at once, **Esc** goes back. | |
| 25 | - **v** flips Steps between folded and open in place. | |
| 26 | ||
| 27 | The terminal draws a conversation's steps itself, so Steps is the one that changes what it shows; Spacing, Motion and Enter are kept for the page. | |
| 28 | ||
| 29 | Code: `src/core/settings.ts` (the four keys, read and written), `src/web/pages/talk.ts` (the form), `src/tui/screens/talk_display.ts` (the terminal screen). Proof: `test/talk-display.test.ts`, `test/tui-talk-chats.test.ts`. |
docs/features/talk.md +7 −1
| @@ -136,7 +136,7 @@ A reply is drawn by the README renderer and then, for Talk alone, by `linkTalk` | ||
| 136 | 136 | |
| 137 | 137 | An agent reply is Markdown, drawn on the server by the same renderer as a README: fenced code is highlighted, tables and links render, and everything else is escaped (a `<script>` in a reply shows as text). A table wider than the column scrolls inside it; the page does not. The reply sits in the column like a person's turn, with none of the README's padding or line measure. |
| 138 | 138 | |
| 139 | A reply grows in one live element while it is written (see "Live") and is then stored as one finished turn; the page only appends a turn whose id it has not drawn (a repeat is ignored). Turns already on the page are not touched, so nothing above a new reply moves, and the page follows the end only if you were already there (otherwise "Latest" appears). An unfinished fence in a stored reply is closed for drawing. The page's own bytes are held by a test (`test/talk-page.test.ts`): the stylesheet under 13,600 B, the script under 29,400 B, and a page with a code reply under 42,000 B. | |
| 139 | A reply grows in one live element while it is written (see "Live") and is then stored as one finished turn; the page only appends a turn whose id it has not drawn (a repeat is ignored). Turns already on the page are not touched, so nothing above a new reply moves, and the page follows the end only if you were already there (otherwise "Latest" appears). An unfinished fence in a stored reply is closed for drawing. The page's own bytes are held by a test (`test/talk-page.test.ts`): the stylesheet under 14,700 B, the script under 29,700 B, and a page with a code reply under 43,000 B (its own page: one question and a code reply). | |
| 140 | 140 | |
| 141 | 141 | ## Following |
| 142 | 142 | |
| @@ -182,3 +182,9 @@ After you confirm a held action, the thread shows a receipt: the verb, the objec | ||
| 182 | 182 | `GET /talk/:id.md` (also `/talk/:id/download`; the Download link beside Archive) returns the conversation as one `text/markdown` attachment: a title, then each turn under `## who · when` in the order written, attachments as links. Only its owner gets it; anyone else sees not found. The MCP `say` tool with `action: download` and `conversation` returns the same text as `markdown`. Code: `src/core/conversation_markdown.ts`; test: `test/conversation-download.test.ts`. |
| 183 | 183 | |
| 184 | 184 | The terminal's Talk screen reads the same file: `d` on the list, or `d` or `x` in an open chat, shows the conversation as the Markdown `/talk/:id/download` serves (`conversationMarkdown`), its owner's alone. Each turn's words sit in a fenced block, so no message can forge a turn heading; past a million characters the earliest turns are left out and the file says so. The MCP `say` tool's `download` with no `conversation` takes the latest one. |
| 185 | ||
| 186 | ## Display (#15734) | |
| 187 | ||
| 188 | Four preferences of the person's own, at the end of the conversation menu (⋯ → Display), one plain form that works without the script (`POST /talk/display`, signed in, same origin): spacing (comfortable or compact: the spacing scale only, never the type size), motion (as the system says, or reduced: Talk's arrivals, the head's slide and the shimmer stop whatever the system says), what Enter does (sends, or adds a line with Ctrl or Cmd+Enter sending) and whether a reply's steps start folded or open. They are the person's `user_setting` rows (`talk.density`, `talk.motion`, `talk.enter`, `talk.steps`, read by `talkDisplay` in `src/core/settings.ts`), applied by the server so the first paint is right; a value that is not one of a preference's own choices is never kept. No theme builder, no colours. The terminal honours the same steps choice: a conversation opened in `forge talk` shows a run of steps as one line ("3 steps") or each step, and `v` there flips the choice for both places, while `D` opens Talk display to set all four (docs/features/talk-display.md); spacing, motion and Enter are the page's own (the terminal has its own rows, no animation, and its `s` prompt always sends on Enter). | |
| 189 | ||
| 190 | **Motion.** One vocabulary: a thing arriving (a sent message, a step, a receipt, the follow control, a version chip) fades and rises 4 px over `--dur-3` (200 ms) with `--ease`, once; the live block's new paragraphs only fade, and the stored reply that takes its place does not move. Opacity and transform only, so nothing on screen shifts; none under `prefers-reduced-motion` or the person's reduced. Proof: `test/talk-display.test.ts`, `test/talk-page.test.ts`. |
src/core/settings.ts +96
| @@ -38,3 +38,99 @@ export function setUserSetting( | ||
| 38 | 38 | ON CONFLICT (user_id, key) DO UPDATE SET value = excluded.value`, |
| 39 | 39 | ).run(userId, key, value.slice(0, MAX_VALUE)); |
| 40 | 40 | } |
| 41 | ||
| 42 | /** | |
| 43 | * How Talk is shown to one person (#15734): a small, real set of preferences kept in the person's | |
| 44 | * own `user_setting` rows (above) and applied by the server, so the first paint is | |
| 45 | * right. Spacing only, never the type size; motion only ever towards less. | |
| 46 | */ | |
| 47 | ||
| 48 | ||
| 49 | export interface TalkDisplay { | |
| 50 | /** The spacing of the thread: comfortable, or compact (the spacing scale only). */ | |
| 51 | readonly density: "comfortable" | "compact"; | |
| 52 | /** On follows the system; reduced turns Talk's motion off whatever the system says. */ | |
| 53 | readonly motion: "on" | "reduced"; | |
| 54 | /** What Enter does in the composer: send, or a new line with Ctrl/Cmd+Enter to send. */ | |
| 55 | readonly enter: "send" | "newline"; | |
| 56 | /** Whether a reply's steps start folded, or open. */ | |
| 57 | readonly steps: "folded" | "open"; | |
| 58 | } | |
| 59 | ||
| 60 | /** Each preference, its key, its choices (the first is the default) and the words for each. */ | |
| 61 | export const TALK_DISPLAY = { | |
| 62 | density: { | |
| 63 | key: "talk.density", | |
| 64 | label: "Spacing", | |
| 65 | choices: [ | |
| 66 | ["comfortable", "Comfortable"], | |
| 67 | ["compact", "Compact"], | |
| 68 | ], | |
| 69 | }, | |
| 70 | motion: { | |
| 71 | key: "talk.motion", | |
| 72 | label: "Motion", | |
| 73 | choices: [ | |
| 74 | ["on", "As the system says"], | |
| 75 | ["reduced", "Reduced"], | |
| 76 | ], | |
| 77 | }, | |
| 78 | enter: { | |
| 79 | key: "talk.enter", | |
| 80 | label: "Enter", | |
| 81 | choices: [ | |
| 82 | ["send", "Sends"], | |
| 83 | ["newline", "Adds a line (Ctrl or Cmd+Enter sends)"], | |
| 84 | ], | |
| 85 | }, | |
| 86 | steps: { | |
| 87 | key: "talk.steps", | |
| 88 | label: "Steps", | |
| 89 | choices: [ | |
| 90 | ["folded", "Start folded"], | |
| 91 | ["open", "Start open"], | |
| 92 | ], | |
| 93 | }, | |
| 94 | } as const; | |
| 95 | ||
| 96 | export type DisplayName = keyof typeof TALK_DISPLAY; | |
| 97 | export const DISPLAY_NAMES = Object.keys(TALK_DISPLAY) as DisplayName[]; | |
| 98 | ||
| 99 | /** A choice that is one of the preference's own, else undefined. */ | |
| 100 | export function displayChoice( | |
| 101 | name: DisplayName, | |
| 102 | value: unknown, | |
| 103 | ): string | undefined { | |
| 104 | return TALK_DISPLAY[name].choices.some(([v]) => v === value) | |
| 105 | ? (value as string) | |
| 106 | : undefined; | |
| 107 | } | |
| 108 | ||
| 109 | /** The person's Talk display, each preference at its default until they choose. */ | |
| 110 | export function talkDisplay(db: Database, userId: string): TalkDisplay { | |
| 111 | const read = (name: DisplayName): string => | |
| 112 | displayChoice(name, getUserSetting(db, userId, TALK_DISPLAY[name].key)) ?? | |
| 113 | TALK_DISPLAY[name].choices[0][0]; | |
| 114 | return { | |
| 115 | density: read("density"), | |
| 116 | motion: read("motion"), | |
| 117 | enter: read("enter"), | |
| 118 | steps: read("steps"), | |
| 119 | } as TalkDisplay; | |
| 120 | } | |
| 121 | ||
| 122 | /** Keep the choices given; anything that is not one of a preference's own choices is left as it was. */ | |
| 123 | export function setTalkDisplay( | |
| 124 | db: Database, | |
| 125 | userId: string, | |
| 126 | given: Partial<Record<DisplayName, unknown>>, | |
| 127 | ): number { | |
| 128 | let kept = 0; | |
| 129 | for (const name of DISPLAY_NAMES) { | |
| 130 | const value = displayChoice(name, given[name]); | |
| 131 | if (value === undefined) continue; | |
| 132 | setUserSetting(db, userId, TALK_DISPLAY[name].key, value); | |
| 133 | kept++; | |
| 134 | } | |
| 135 | return kept; | |
| 136 | } |
src/http/server.ts +2 −1
| @@ -171,7 +171,7 @@ import { | ||
| 171 | 171 | themeSubmit, |
| 172 | 172 | } from "../web/pages/site.ts"; |
| 173 | 173 | import { talkBuild, talkPublish, talkRestore } from "../web/talk_build.ts"; |
| 174 | import { talkAct, talkAgainSend, talkArchive, talkConfirm, talkDownload, talkNew, talkPin, talkQueueCancel, talkRename, talkSend, talkUndo, talkStream, talkView } from "../web/pages/talk.ts"; | |
| 174 | import { talkAct, talkAgainSend, talkArchive, talkConfirm, talkDisplaySave, talkDownload, talkNew, talkPin, talkQueueCancel, talkRename, talkSend, talkUndo, talkStream, talkView } from "../web/pages/talk.ts"; | |
| 175 | 175 | import { |
| 176 | 176 | recoverFinish, |
| 177 | 177 | recoverOptions, |
| @@ -1246,6 +1246,7 @@ export function buildRouter(): Router<Handler> { | ||
| 1246 | 1246 | router.add("POST", "/talk/undo/:turn", talkUndo); |
| 1247 | 1247 | router.add("POST", "/talk/act", talkAct); |
| 1248 | 1248 | router.add("POST", "/talk/new", talkNew); |
| 1249 | router.add("POST", "/talk/display", talkDisplaySave); | |
| 1249 | 1250 | router.add("POST", "/talk/build", talkBuild); |
| 1250 | 1251 | router.add("GET", "/talk/:id", talkView); |
| 1251 | 1252 | router.add("GET", "/talk/:id/download", talkDownload); |
src/tui/screens/talk_chats.ts +27 −1
| @@ -30,6 +30,8 @@ import { conversationMarkdown } from "../../core/conversation_markdown.ts"; | ||
| 30 | 30 | import { publicOrigin } from "../../core/public_origin.ts"; |
| 31 | 31 | import { filesOf, repoOf, stepOf } from "../../core/talk_steps.ts"; |
| 32 | 32 | import { cardsPlaced, plainVoice } from "../../core/talk_voice.ts"; |
| 33 | import { setTalkDisplay, talkDisplay } from "../../core/settings.ts"; | |
| 34 | import { talkDisplayScreen } from "./talk_display.ts"; | |
| 33 | 35 | import type { ShownCard } from "../../core/talk_voice.ts"; |
| 34 | 36 | import { workspaceOf } from "../../actions/talk_workspace.ts"; |
| 35 | 37 | import type { Ctx, Screen } from "../app/app.ts"; |
| @@ -102,6 +104,8 @@ function chatScreen(f: Session, ctx: Ctx, chat: Conversation, hit?: string): Scr | ||
| 102 | 104 | let mark = 0; |
| 103 | 105 | let placed = false; |
| 104 | 106 | let pane = false; |
| 107 | // Display's steps choice is the person's own, the page's and the terminal's: v flips it here. | |
| 108 | const stepsNow = () => (f.user === undefined ? "folded" : talkDisplay(f.app.db, f.user.id).steps); | |
| 105 | 109 | type Turns = Exclude<ReturnType<typeof listTurns>, { ok: false }>["value"]; |
| 106 | 110 | let turns: Turns = []; |
| 107 | 111 | let recent: Turns = []; |
| @@ -143,9 +147,18 @@ function chatScreen(f: Session, ctx: Ctx, chat: Conversation, hit?: string): Scr | ||
| 143 | 147 | ]; |
| 144 | 148 | const refs = refTarget(f.app.db, f.user, repo); |
| 145 | 149 | let n = 0; |
| 146 | return turns.flatMap((t) => { | |
| 150 | const stepAt = (i: number) => (turns[i]?.role === "tool" ? stepOf(turns[i]!.text) : undefined); | |
| 151 | return turns.flatMap((t, i) => { | |
| 147 | 152 | if (t.id === around) mark = n; |
| 148 | 153 | const step = t.role === "tool" ? stepOf(t.text) : undefined; |
| 154 | // Folded, a run of steps reads as one line: its one step's words, or how many. | |
| 155 | if (stepsNow() === "folded" && step !== undefined) { | |
| 156 | if (stepAt(i - 1) !== undefined) return []; | |
| 157 | let run = 1; | |
| 158 | while (stepAt(i + run) !== undefined) run++; | |
| 159 | n += 2; | |
| 160 | return [[{ text: run === 1 ? step.label : `${String(run)} steps`, style: style(c.mutedFg, c.bg) }], []]; | |
| 161 | } | |
| 149 | 162 | const said = t.role === "agent" ? pathRefs(plainVoice(t.text, cards), refs) : t.text; |
| 150 | 163 | const own = (step === undefined ? said : [step.label, ...step.details.map((d) => ` ${d}`)].join("\n")).split("\n").flatMap((l) => wrap(l, Math.max(10, width - 2))); |
| 151 | 164 | n += own.length + 2; |
| @@ -167,6 +180,8 @@ function chatScreen(f: Session, ctx: Ctx, chat: Conversation, hit?: string): Scr | ||
| 167 | 180 | binding(["r"], "reload"), |
| 168 | 181 | binding(["p"], "pane"), |
| 169 | 182 | binding(["b"], "a result's buttons"), |
| 183 | binding(["v"], "steps open or folded"), | |
| 184 | binding(["D"], "display"), | |
| 170 | 185 | binding(["d", "x"], "export as Markdown"), |
| 171 | 186 | binding(["esc"], "back"), |
| 172 | 187 | ], |
| @@ -196,6 +211,17 @@ function chatScreen(f: Session, ctx: Ctx, chat: Conversation, hit?: string): Scr | ||
| 196 | 211 | ctx.invalidate(); |
| 197 | 212 | return true; |
| 198 | 213 | } |
| 214 | if (e.key === "D") { | |
| 215 | ctx.push(talkDisplayScreen(f, ctx)); | |
| 216 | return true; | |
| 217 | } | |
| 218 | if (e.key === "v") { | |
| 219 | const steps = stepsNow() === "open" ? "folded" : "open"; | |
| 220 | setTalkDisplay(f.app.db, user.id, { steps }); | |
| 221 | note = steps === "open" ? "Steps open, here and on /talk." : "Steps folded, here and on /talk."; | |
| 222 | ctx.invalidate(); | |
| 223 | return true; | |
| 224 | } | |
| 199 | 225 | if (e.key === "esc" || e.key === "q") { |
| 200 | 226 | ctx.pop(); |
| 201 | 227 | return true; |
src/tui/screens/talk_display.ts added +97
| @@ -0,0 +1,97 @@ | ||
| 1 | /** | |
| 2 | * Talk's Display in the terminal (#15734): the person's four Talk preferences, read and written | |
| 3 | * through the same `talkDisplay` / `setTalkDisplay` the page's Display form uses, so a choice set | |
| 4 | * here is the page's next paint and the other way round. Enter moves the row under the cursor to its | |
| 5 | * next choice and keeps it at once. Steps is the one the terminal draws itself (a conversation's | |
| 6 | * steps as one line or each step); spacing, motion and Enter are the page's, set here for it. | |
| 7 | */ | |
| 8 | ||
| 9 | import { | |
| 10 | DISPLAY_NAMES, | |
| 11 | setTalkDisplay, | |
| 12 | TALK_DISPLAY, | |
| 13 | talkDisplay, | |
| 14 | type DisplayName, | |
| 15 | } from "../../core/settings.ts"; | |
| 16 | import type { Ctx, Screen } from "../app/app.ts"; | |
| 17 | import { binding } from "../app/keys.ts"; | |
| 18 | import { style } from "../term/style.ts"; | |
| 19 | import { truncate } from "../term/width.ts"; | |
| 20 | import type { Session } from "../session.ts"; | |
| 21 | import { fill, len, split } from "../ui/layout.ts"; | |
| 22 | import { ListState, drawList, type ListRow } from "./common.ts"; | |
| 23 | ||
| 24 | /** Where each choice shows: the terminal draws steps itself; the rest are the page's. */ | |
| 25 | const WHERE: Readonly<Record<DisplayName, string>> = { | |
| 26 | density: "on /talk", | |
| 27 | motion: "on /talk", | |
| 28 | enter: "on /talk", | |
| 29 | steps: "here and on /talk", | |
| 30 | }; | |
| 31 | ||
| 32 | export function talkDisplayScreen(f: Session, ctx: Ctx): Screen { | |
| 33 | const state = new ListState(); | |
| 34 | let note = ""; | |
| 35 | const now = () => | |
| 36 | f.user === undefined ? undefined : talkDisplay(f.app.db, f.user.id); | |
| 37 | const rows = (): ListRow[] => { | |
| 38 | const d = now(); | |
| 39 | return DISPLAY_NAMES.map((name) => { | |
| 40 | const value = d?.[name]; | |
| 41 | const words = | |
| 42 | TALK_DISPLAY[name].choices.find(([v]) => v === value)?.[1] ?? ""; | |
| 43 | return { | |
| 44 | title: `${TALK_DISPLAY[name].label}: ${words}`, | |
| 45 | secondary: WHERE[name], | |
| 46 | meta: "", | |
| 47 | }; | |
| 48 | }); | |
| 49 | }; | |
| 50 | ||
| 51 | const screen: Screen = { | |
| 52 | title: "Talk display", | |
| 53 | keys: [ | |
| 54 | binding(["j", "k"], "move cursor"), | |
| 55 | binding(["enter"], "next choice"), | |
| 56 | binding(["esc"], "back"), | |
| 57 | ], | |
| 58 | render(area, s) { | |
| 59 | const c = ctx.theme.c; | |
| 60 | const [head, body] = split(area, "v", [len(1), fill(1)]); | |
| 61 | const text = | |
| 62 | note !== "" | |
| 63 | ? note | |
| 64 | : "Your Talk preferences, the page's and the terminal's; Enter changes one."; | |
| 65 | s.text( | |
| 66 | head!.x, | |
| 67 | head!.y, | |
| 68 | truncate(text, head!.w), | |
| 69 | style(c.mutedFg, c.bg), | |
| 70 | head!.x + head!.w, | |
| 71 | ); | |
| 72 | drawList(s, body!, c, state, rows()); | |
| 73 | }, | |
| 74 | key(e) { | |
| 75 | if (state.key(e, DISPLAY_NAMES.length)) return true; | |
| 76 | if (e.ctrl || e.alt) return false; | |
| 77 | if (e.key === "esc" || e.key === "q") { | |
| 78 | ctx.pop(); | |
| 79 | return true; | |
| 80 | } | |
| 81 | const user = f.user; | |
| 82 | const name = DISPLAY_NAMES[state.index]; | |
| 83 | if (e.key !== "enter" || user === undefined || name === undefined) | |
| 84 | return false; | |
| 85 | const choices = TALK_DISPLAY[name].choices; | |
| 86 | const at = choices.findIndex( | |
| 87 | ([v]) => v === talkDisplay(f.app.db, user.id)[name], | |
| 88 | ); | |
| 89 | const next = choices[(at + 1) % choices.length]!; | |
| 90 | setTalkDisplay(f.app.db, user.id, { [name]: next[0] }); | |
| 91 | note = `${TALK_DISPLAY[name].label}: ${next[1]}. Kept, ${WHERE[name]}.`; | |
| 92 | ctx.invalidate(); | |
| 93 | return true; | |
| 94 | }, | |
| 95 | }; | |
| 96 | return screen; | |
| 97 | } |
src/web/pages/talk.ts +33 −6
| @@ -69,6 +69,7 @@ import { crewLineHtml } from "../crew_now.ts"; | ||
| 69 | 69 | import { agentHtml, liveHtml, voiceCss, voiceOf, type Voice } from "../talk_parts.ts"; |
| 70 | 70 | import { badge, btn, icon, iconBtn, menu, meter, row, time } from "../ui.ts"; |
| 71 | 71 | import { inlineIcons } from "../icons.ts"; |
| 72 | import { DISPLAY_NAMES, setTalkDisplay, TALK_DISPLAY, talkDisplay, type TalkDisplay } from "../../core/settings.ts"; | |
| 72 | 73 | import { buildCss, chosenTemplate, panelFor, templateChips } from "../talk_build.ts"; |
| 73 | 74 | import type { User } from "../../core/users.ts"; |
| 74 | 75 | import { chatBuildOf } from "../../core/chat_build.ts"; |
| @@ -221,11 +222,11 @@ export function timeGroups(turns: readonly Turn[], drawn: readonly Html[]): Html | ||
| 221 | 222 | * closed disclosure, one tab stop: "3 steps". The stream's script folds a step that arrives later |
| 222 | 223 | * into the run it joins the same way. |
| 223 | 224 | */ |
| 224 | export function foldSteps(turns: readonly Html[]): Html[] { | |
| 225 | export function foldSteps(open: boolean, turns: readonly Html[]): Html[] { | |
| 225 | 226 | const out: Html[] = []; |
| 226 | 227 | let run: Html[] = []; |
| 227 | 228 | const close = (): void => { |
| 228 | if (run.length > 0) out.push(html`<li class="talk-fold" data-steps><details><summary class="small muted">${raw(stepsWord(run))}</summary><ol class="talk-fold-list">${run}</ol></details></li>`); | |
| 229 | if (run.length > 0) out.push(html`<li class="talk-fold" data-steps><details${open ? raw(" open") : null}><summary class="small muted">${raw(stepsWord(run))}</summary><ol class="talk-fold-list">${run}</ol></details></li>`); | |
| 229 | 230 | run = []; |
| 230 | 231 | }; |
| 231 | 232 | for (const t of turns) { |
| @@ -418,11 +419,23 @@ function chats(ctx: Ctx, conversation: Conversation, showArchived: boolean, type | ||
| 418 | 419 | </nav>`; |
| 419 | 420 | } |
| 420 | 421 | |
| 422 | /** | |
| 423 | * Display, at the end of the conversation menu: the person's Talk preferences as a plain form, | |
| 424 | * kept in their own settings (`core/settings.ts`) and applied by the server on the next paint. | |
| 425 | */ | |
outdated
Clean: the |
||
| 426 | function displayForm(display: TalkDisplay, back: string): Html { | |
| 427 | return html`<details class="talk-display"><summary class="menu-item">${icon("settings")}<span class="grow">Display</span></summary> | |
| 428 | <form method="post" action="${HERE}/display"><input type="hidden" name="back" value="${back}" /> | |
| 429 | ${DISPLAY_NAMES.map((name) => html`<label class="small">${TALK_DISPLAY[name].label}<select class="input" name="${name}">${TALK_DISPLAY[name].choices.map(([v, words]) => html`<option value="${v}"${display[name] === v ? raw(" selected") : null}>${words}</option>`)}</select></label>`)} | |
| 430 | ${btn("Save", { size: "sm" })} | |
outdated
Both doors: Display exists only on the page. The terminal needs a way to view and set these four preferences through |
||
| 431 | </form></details>`; | |
| 432 | } | |
| 433 | ||
| 421 | 434 | /** |
| 422 | 435 | * The open conversation's head: on a phone the way to the list, then its name, what it has cost, |
| 423 | 436 | * and one menu for Rename, Download, Pin and Archive, each a plain form or link. |
| 424 | 437 | */ |
| 425 | function hereBar(ctx: Ctx, conversation: Conversation, context: Context | undefined, tabs: Html | null): Html { | |
| 438 | function hereBar(ctx: Ctx, conversation: Conversation, context: Context | undefined, display: TalkDisplay, tabs: Html | null): Html { | |
| 426 | 439 | const archived = conversation.archivedAt !== null; |
| 427 | 440 | const item = (action: string, field: string, value: string, label: string, ic: "pin" | "history" | "trash"): Html => |
| 428 | 441 | html`<form method="post" action="${urlOf(conversation)}/${action}"><input type="hidden" name="${field}" value="${value}" /><button class="menu-item" type="submit">${icon(ic)}<span class="grow">${label}</span></button></form>`; |
| @@ -444,6 +457,7 @@ function hereBar(ctx: Ctx, conversation: Conversation, context: Context | undefi | ||
| 444 | 457 | { label: "Download", href: `${urlOf(conversation)}.md`, icon: "download" }, |
| 445 | 458 | ...(archived ? [] : [item("pin", "pinned", conversation.pinnedAt === null ? "1" : "0", conversation.pinnedAt === null ? "Pin" : "Unpin", "pin")]), |
| 446 | 459 | item("archive", "archived", archived ? "0" : "1", archived ? "Restore" : "Archive", archived ? "history" : "trash"), |
| 460 | displayForm(display, urlOf(conversation)), | |
| 447 | 461 | ], |
| 448 | 462 | })} |
| 449 | 463 | <form method="post" action="${HERE}/new">${iconBtn("plus", "New conversation", { variant: "ghost" })}</form> |
| @@ -522,12 +536,13 @@ async function talkPage(ctx: Ctx, conversation: Conversation, before0: string | | ||
| 522 | 536 | // The frame shows what runs; beside a build it waits for the build's own preview. |
| 523 | 537 | const framed = pane.live && !pending; |
| 524 | 538 | const about = editing === undefined ? aboutLine(ctx) : null; |
| 539 | const display = talkDisplay(ctx.app.db, user.id); | |
| 525 | 540 | // The crew's line says something only while a run is live: idle is silence. |
| 526 | 541 | const crew = liveCrewRows(ctx, user); |
| 527 | 542 | const body = html`<div class="talk-page" data-shell data-pane="${shown}"${listing ? raw(" data-view=\"list\"") : null}${split ? raw(" data-split") : null}><h1 class="sr-only">Talk</h1> |
| 528 | 543 | <div class="talk-side">${chats(ctx, conversation, showArchived, typed)}</div> |
| 529 | <div class="talk" data-talk data-user="${user.id}" data-c="${conversation.id}" data-here="${here}" data-paged="${paged ? "1" : "0"}" data-running="${running && !paged ? "1" : "0"}"> | |
| 530 | ${hereBar(ctx, conversation, context, split ? html`<nav class="seg talk-tabs" aria-label="Chat or preview"><a href="?pane=chat"${shown === "chat" ? raw(' aria-current="page"') : null}>Chat</a><a href="?pane=preview"${shown !== "chat" ? raw(' aria-current="page"') : null}>Preview</a></nav>` : null)} | |
| 544 | <div class="talk" data-talk data-density="${display.density}" data-motion="${display.motion}" data-enter="${display.enter}" data-fold="${display.steps}" data-user="${user.id}" data-c="${conversation.id}" data-here="${here}" data-paged="${paged ? "1" : "0"}" data-running="${running && !paged ? "1" : "0"}"> | |
| 545 | ${hereBar(ctx, conversation, context, display, split ? html`<nav class="seg talk-tabs" aria-label="Chat or preview"><a href="?pane=chat"${shown === "chat" ? raw(' aria-current="page"') : null}>Chat</a><a href="?pane=preview"${shown !== "chat" ? raw(' aria-current="page"') : null}>Preview</a></nav>` : null)} | |
| 531 | 546 | ${turns.length === DEFAULT_PAGE && turns[0] !== undefined |
| 532 | 547 | ? html`<p class="talk-more small"><a href="${here}?before=${turns[0].id}">Earlier</a></p>` |
| 533 | 548 | : null} |
| @@ -535,7 +550,7 @@ async function talkPage(ctx: Ctx, conversation: Conversation, before0: string | | ||
| 535 | 550 | <ol class="talk-log" role="log" data-last="${last}" aria-label="Conversation with the forge"> |
| 536 | 551 | ${empty |
| 537 | 552 | ? hello(ctx, user, here, buildMode, chosen) |
| 538 | : foldSteps(timeGroups(turns, turns.map((t) => turnHtml(t, waiting, costs.get(t.id), acts.get(t.id), works.get(t.id), sent.get(t.id), expired, undone, refs, voice, look))))} | |
| 553 | : foldSteps(display.steps === "open", timeGroups(turns, turns.map((t) => turnHtml(t, waiting, costs.get(t.id), acts.get(t.id), works.get(t.id), sent.get(t.id), expired, undone, refs, voice, look))))} | |
| 539 | 554 | ${!paged && running ? queuedTalk(ctx.app, user, conversation.id).map(queuedHtml) : null} |
| 540 | 555 | </ol> |
| 541 | 556 | ${crew.length === 0 ? null : crewLineHtml(crew)} |
| @@ -651,6 +666,18 @@ export async function talkArchive(ctx: Ctx): Promise<Response> { | ||
| 651 | 666 | return flashTo(ctx, archive ? HERE : urlOf(conversation), { tone: "success", message: archive ? "Archived. It is under Archived." : "Restored." }); |
| 652 | 667 | } |
| 653 | 668 | |
| 669 | // POST /talk/display — the person's Talk display preferences; a choice that is not one of a | |
| 670 | // preference's own is left as it was. Back to the conversation the form came from. | |
| 671 | export async function talkDisplaySave(ctx: Ctx): Promise<Response> { | |
| 672 | const user = ctx.auth.user; | |
| 673 | if (user === undefined) return signInFirst(ctx); | |
| 674 | const form = await readForm(ctx, "rw"); | |
| 675 | if (form instanceof Response) return form; | |
| 676 | setTalkDisplay(ctx.app.db, user.id, Object.fromEntries(DISPLAY_NAMES.map((n) => [n, form.get(n)]))); | |
| 677 | const back = form.get("back"); | |
| 678 | return flashTo(ctx, typeof back === "string" && /^\/talk(\/[0-9a-z]{1,40})?$/.test(back) ? back : HERE, { tone: "success", message: "Display saved." }); | |
| 679 | } | |
| 680 | ||
| 654 | 681 | // POST /talk/:id/pin — pinned=1 keeps it at the top of the list, 0 lets it go; the list stays as it |
| 655 | 682 | // was. |
| 656 | 683 | export async function talkPin(ctx: Ctx): Promise<Response> { |
src/web/pages/talk_client.ts +25 −1
| @@ -26,6 +26,11 @@ | ||
| 26 | 26 | * answer runs and the box is empty; words typed meanwhile queue, and Steer appears beside it. |
| 27 | 27 | * - While an answer runs the last exchange's actions keep their room, unseen, so nothing above |
| 28 | 28 | * them moves; the answer's end replaces them. |
| 29 | * - Motion is one vocabulary: a thing arriving fades and rises 4 px over --dur-3 with --ease, once | |
| 30 | * (`data-in` is set only on what the stream or the panel adds, never on a re-render, and never on | |
| 31 | * the stored reply that takes the live block's place); the live block's new blocks only fade. | |
| 32 | * None under prefers-reduced-motion, or when the person chose reduced (Display). Opacity and | |
| 33 | * transform only, so nothing on screen moves. | |
| 29 | 34 | * - The conversation's head slides away while the reader scrolls down and comes back on the way up. |
| 30 | 35 | * - Copy buttons are drawn by the script, not the server: without the script |
| 31 | 36 | * they would do nothing. |
| @@ -56,6 +61,9 @@ body:has(.talk-page) .foot { display: none; } | ||
| 56 | 61 | .talk-fill meter { width: 3rem; } |
| 57 | 62 | .talk-figures { display: grid; gap: 2px; padding: 8px 12px; border-bottom: 1px solid var(--border); } |
| 58 | 63 | .talk-figures p { margin: 0; } |
| 64 | .talk-display form { display: grid; gap: 8px; padding: 8px 12px; } | |
| 65 | .talk-display label { display: grid; gap: 4px; } | |
| 66 | .talk-display select { font-size: 16px; } | |
| 59 | 67 | .talk-head .btn-icon, .talk-head summary.btn { position: relative; min-width: 2.5rem; min-height: 2.5rem; } |
| 60 | 68 | .talk-head .btn-icon::after, .talk-head summary.btn::after, .talk-tools .btn-icon::after, .talk-copy::after, .talk-act::after, .talk-fold summary::after, .talk-more a::after { content: ""; position: absolute; inset: -6px; } |
| 61 | 69 | .talk-rename { display: flex; gap: 8px; padding: 8px; } |
| @@ -108,6 +116,17 @@ body:has(.talk-page) .foot { display: none; } | ||
| 108 | 116 | .talk-person > :is(.talk-meta, .talk-acts) { order: -1; flex: none; } |
| 109 | 117 | .talk-person:has(~ .talk-person):not(:focus-within) > .talk-meta { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); } |
| 110 | 118 | .talk-time { justify-self: center; margin-block: 4px -4px; } |
| 119 | .talk[data-density=compact] .talk-log { gap: 8px; line-height: 1.5; } | |
| 120 | .talk[data-density=compact] .talk-person > .talk-body { padding: 4px 12px; } | |
| 121 | .talk[data-density=compact] .talk-body.prose :is(p, ul, ol, pre, table, blockquote) { margin-bottom: 8px; } | |
| 122 | @keyframes talk-in { from { opacity: 0; transform: translateY(4px); } } | |
| 123 | @keyframes talk-fade { from { opacity: 0; } } | |
| 124 | @media (prefers-reduced-motion: no-preference) { | |
| 125 | .talk:not([data-motion=reduced]) :is(.talk-log > [data-in], .talk-fold-list > [data-in], .talk-jump:not([hidden])) { animation: talk-in var(--dur-3) var(--ease); } | |
| 126 | .talk:not([data-motion=reduced]) .talk-live [data-in] { animation: talk-fade var(--dur-3) var(--ease); } | |
| 127 | .talk-versions [data-in] { animation: talk-in var(--dur-3) var(--ease); } | |
| 128 | } | |
| 129 | .talk[data-motion=reduced] :is(*, ::before, ::after) { animation: none !important; transition: none !important; } | |
| 111 | 130 | .talk-person > .talk-body { min-width: 0; max-width: min(calc(100% - 4.5rem), 36rem); padding: 8px 16px; border-radius: 18px; background: var(--muted); white-space: pre-wrap; } |
| 112 | 131 | .talk-agent > .talk-body, .talk-person > .talk-body + .talk-files, .talk-agent > .talk-steps { flex: 1 0 100%; } |
| 113 | 132 | .talk-agent > .talk-links { order: 1; margin: 0; margin-inline-end: 8px; font-size: 12.5px; } |
| @@ -302,10 +321,12 @@ export const liveJs = ` | ||
| 302 | 321 | const liveDrop = () => { const l = document.getElementById("live"); if (l) l.remove(); }; |
| 303 | 322 | const liveMorph = (el, nodes) => { |
| 304 | 323 | let i = 0; |
| 324 | const had = el.childNodes.length; | |
| 305 | 325 | while (i < nodes.length && el.childNodes[i] && el.childNodes[i].isEqualNode(nodes[i])) i++; |
| 306 | 326 | const o = el.childNodes[i], n = nodes[i]; |
| 307 | 327 | if (o && n && o.nodeName === "DIV" && n.nodeName === "DIV" && o.className === n.className) { liveMorph(o, [...n.childNodes]); i++; } |
| 308 | 328 | while (el.childNodes.length > i) el.lastChild.remove(); |
| 329 | nodes.slice(i).forEach((x, k) => { if (i + k >= had && x.nodeType === 1) x.setAttribute("data-in", ""); }); | |
| 309 | 330 | el.append(...nodes.slice(i)); |
| 310 | 331 | }; |
| 311 | 332 | const liveOn = (src) => { |
| @@ -495,6 +516,7 @@ if (root) { | ||
| 495 | 516 | if (!li) return; |
| 496 | 517 | const at = log.querySelector("#live, [data-queued]"); |
| 497 | 518 | const put = (x) => (at ? at.before(x) : log.append(x)); |
| 519 | if (!li.classList.contains("talk-agent")) li.setAttribute("data-in", ""); | |
| 498 | 520 | if (!li.hasAttribute("data-step")) return put(li); |
| 499 | 521 | const prev = at ? at.previousElementSibling : log.lastElementChild; |
| 500 | 522 | let fold = prev && prev.hasAttribute("data-steps") ? prev : null; |
| @@ -502,6 +524,7 @@ if (root) { | ||
| 502 | 524 | fold = Object.assign(document.createElement("li"), { className: "talk-fold" }); |
| 503 | 525 | fold.setAttribute("data-steps", ""); |
| 504 | 526 | const d = document.createElement("details"); |
| 527 | d.open = root.dataset.fold === "open"; | |
outdated
|
||
| 505 | 528 | d.append(Object.assign(document.createElement("summary"), { className: "small muted" }), Object.assign(document.createElement("ol"), { className: "talk-fold-list" })); |
| 506 | 529 | fold.append(d); |
| 507 | 530 | put(fold); |
| @@ -738,7 +761,8 @@ ${dictateJs} | ||
| 738 | 761 | }); |
| 739 | 762 | box.addEventListener("keydown", (e) => { |
| 740 | 763 | if (e.key === "Escape" && editing) { editing = false; box.value = ""; grow(); say(""); return; } |
| 741 | if (e.key === "Enter" && !e.shiftKey && !e.isComposing) { e.preventDefault(); form.requestSubmit(); } | |
| 764 | const lines = root.dataset.enter === "newline"; | |
| 765 | if (e.key === "Enter" && !e.shiftKey && !e.isComposing && (!lines || e.metaKey || e.ctrlKey)) { e.preventDefault(); form.requestSubmit(); } | |
| 742 | 766 | }); |
| 743 | 767 | log.addEventListener("submit", async (e) => { |
| 744 | 768 | const r = e.target.closest("form[data-again]"); |
test/talk-display.test.ts added +145
| @@ -0,0 +1,145 @@ | ||
| 1 | /** | |
| 2 | * Talk's Display preferences (#15734): kept in the person's own settings, applied by the server on | |
| 3 | * the first paint, set by a plain form that works without the script, and never anything but one of | |
| 4 | * each preference's own choices. | |
| 5 | */ | |
| 6 | import { afterAll, beforeAll, expect, test } from "bun:test"; | |
| 7 | import { mkdtemp, rm } from "node:fs/promises"; | |
| 8 | import { tmpdir } from "node:os"; | |
| 9 | import { join } from "node:path"; | |
| 10 | import { createApp, type App } from "../src/app.ts"; | |
| 11 | import { appendTurn, openConversation } from "../src/core/conversations.ts"; | |
| 12 | import { createSession } from "../src/core/sessions.ts"; | |
| 13 | import { getUserSetting } from "../src/core/settings.ts"; | |
| 14 | import { setTalkDisplay, talkDisplay } from "../src/core/settings.ts"; | |
| 15 | import { createUser, type User } from "../src/core/users.ts"; | |
| 16 | import { serve, type Servers } from "../src/http/server.ts"; | |
| 17 | import { quietLogs } from "./helpers/globals.ts"; | |
| 18 | import { promote } from "./helpers/members.ts"; | |
| 19 | ||
| 20 | quietLogs(); | |
| 21 | ||
| 22 | let dir: string; | |
| 23 | let app: App; | |
| 24 | let servers: Servers; | |
| 25 | let alice: User; | |
| 26 | let bob: User; | |
| 27 | const cookie = (u: User) => | |
| 28 | `forge_session=${createSession(app.db, u.id).token}`; | |
| 29 | const page = async (u: User) => | |
| 30 | ( | |
| 31 | await fetch(`${servers.url}/talk`, { headers: { cookie: cookie(u) } }) | |
| 32 | ).text(); | |
| 33 | const post = (u: User, form: Record<string, string>, origin = servers.url) => | |
| 34 | fetch(`${servers.url}/talk/display`, { | |
| 35 | method: "POST", | |
| 36 | redirect: "manual", | |
| 37 | headers: { origin, cookie: cookie(u) }, | |
| 38 | body: new URLSearchParams(form), | |
| 39 | }); | |
| 40 | ||
| 41 | beforeAll(async () => { | |
| 42 | dir = await mkdtemp(join(tmpdir(), "forge-talk-display-")); | |
| 43 | app = createApp({ dataDir: dir, port: 0 }); | |
| 44 | servers = await serve(app); | |
| 45 | for (const name of ["alice", "bob"]) { | |
| 46 | const made = await createUser(app.db, { | |
| 47 | origin: "seed", | |
| 48 | trusted: true, | |
| 49 | username: name, | |
| 50 | email: `${name}@forge.local`, | |
| 51 | password: "a-good-passphrase", | |
| 52 | adminIfFirst: name === "alice", | |
| 53 | }); | |
| 54 | if (!made.ok) throw new Error(made.error); | |
| 55 | promote(app.db, made.value); | |
| 56 | if (name === "alice") alice = made.value; | |
| 57 | else bob = made.value; | |
| 58 | } | |
| 59 | const c = openConversation(app.db, alice.id); | |
| 60 | appendTurn(app.db, alice.id, c.id, { role: "person", text: "why" }); | |
| 61 | appendTurn(app.db, alice.id, c.id, { | |
| 62 | role: "tool", | |
| 63 | text: 'read_file {"repo":"a/b","path":"x.ts"}', | |
| 64 | }); | |
| 65 | appendTurn(app.db, alice.id, c.id, { role: "agent", text: "Because." }); | |
| 66 | }); | |
| 67 | afterAll(async () => { | |
| 68 | servers.stop(); | |
| 69 | app.close(); | |
| 70 | await rm(dir, { recursive: true, force: true }); | |
| 71 | }); | |
| 72 | ||
| 73 | test("each preference starts at its default, and only its own choices are kept", () => { | |
| 74 | expect(talkDisplay(app.db, bob.id)).toEqual({ | |
| 75 | density: "comfortable", | |
| 76 | motion: "on", | |
| 77 | enter: "send", | |
| 78 | steps: "folded", | |
| 79 | }); | |
| 80 | expect( | |
| 81 | setTalkDisplay(app.db, bob.id, { | |
| 82 | density: "compact", | |
| 83 | motion: "loud", | |
| 84 | enter: "<script>", | |
| 85 | steps: "open", | |
| 86 | }), | |
| 87 | ).toBe(2); | |
| 88 | expect(talkDisplay(app.db, bob.id)).toEqual({ | |
| 89 | density: "compact", | |
| 90 | motion: "on", | |
| 91 | enter: "send", | |
| 92 | steps: "open", | |
| 93 | }); | |
| 94 | expect(getUserSetting(app.db, bob.id, "talk.motion")).toBeUndefined(); | |
| 95 | }); | |
| 96 | ||
| 97 | test("the page draws the person's display on the first paint, and the menu offers it as a plain form", async () => { | |
| 98 | const before = await page(alice); | |
| 99 | expect(before).toContain( | |
| 100 | 'data-density="comfortable" data-motion="on" data-enter="send" data-fold="folded"', | |
| 101 | ); | |
| 102 | expect(before).toMatch( | |
| 103 | /<details class="talk-display"><summary class="menu-item">/, | |
| 104 | ); | |
| 105 | expect(before).toContain('<form method="post" action="/talk/display">'); | |
| 106 | expect(before).toMatch(/<li class="talk-fold" data-steps><details><summary/); | |
| 107 | const saved = await post(alice, { | |
| 108 | density: "compact", | |
| 109 | motion: "reduced", | |
| 110 | enter: "newline", | |
| 111 | steps: "open", | |
| 112 | back: "/talk", | |
| 113 | }); | |
| 114 | expect(saved.status).toBe(303); | |
| 115 | expect(saved.headers.get("location")).toStartWith("/talk"); | |
| 116 | const after = await page(alice); | |
| 117 | expect(after).toContain( | |
| 118 | 'data-density="compact" data-motion="reduced" data-enter="newline" data-fold="open"', | |
| 119 | ); | |
| 120 | expect(after).toMatch( | |
| 121 | /<li class="talk-fold" data-steps><details open><summary/, | |
| 122 | ); | |
| 123 | expect(after).toContain('<option value="compact" selected>'); | |
| 124 | // Bob's own page is his own: Alice's choices are not his. | |
| 125 | expect(await page(bob)).toContain('data-motion="on"'); | |
| 126 | }); | |
| 127 | ||
| 128 | test("the form goes back only to a Talk page, refuses another site, and asks for sign-in", async () => { | |
| 129 | const away = await post(alice, { | |
| 130 | density: "comfortable", | |
| 131 | back: "https://evil.example/", | |
| 132 | }); | |
| 133 | expect(away.headers.get("location")).toStartWith("/talk"); | |
| 134 | expect( | |
| 135 | (await post(alice, { density: "compact" }, "https://evil.example")).status, | |
| 136 | ).toBe(403); | |
| 137 | const out = await fetch(`${servers.url}/talk/display`, { | |
| 138 | method: "POST", | |
| 139 | redirect: "manual", | |
| 140 | headers: { origin: servers.url }, | |
| 141 | body: new URLSearchParams({ density: "compact" }), | |
| 142 | }); | |
| 143 | expect(out.status).toBe(303); | |
| 144 | expect(out.headers.get("location")).toStartWith("/signin"); | |
| 145 | }); |
test/talk-page.test.ts +56 −6
| @@ -282,7 +282,7 @@ describe("the page", () => { | ||
| 282 | 282 | test("the server folds each run of steps into one closed disclosure, one tab stop for the run", async () => { |
| 283 | 283 | const { foldSteps, turnHtml } = await import("../src/web/pages/talk.ts"); |
| 284 | 284 | const turn = (id: string, role: string, text: string) => turnHtml({ id, role, text, createdAt: "2026-01-01T00:00:00Z" } as any, new Set()); |
| 285 | const out = foldSteps([turn("1", "person", "why"), turn("2", "tool", 'read_file {"repo":"a/b","path":"x.ts"}'), turn("3", "tool", 'runs {"repo":"a/b"}'), turn("4", "agent", "Because."), turn("5", "tool", 'read_file {"repo":"a/b","path":"y.ts"}')]).map((h) => h.text).join(""); | |
| 285 | const out = foldSteps(false, [turn("1", "person", "why"), turn("2", "tool", 'read_file {"repo":"a/b","path":"x.ts"}'), turn("3", "tool", 'runs {"repo":"a/b"}'), turn("4", "agent", "Because."), turn("5", "tool", 'read_file {"repo":"a/b","path":"y.ts"}')]).map((h) => h.text).join(""); | |
| 286 | 286 | expect(out.match(/data-steps/g)?.length).toBe(2); |
| 287 | 287 | expect(out).toContain('<summary class="small muted">2 steps</summary>'); |
| 288 | 288 | expect(out).toContain('<summary class="small muted">Read y.ts</summary>'); |
| @@ -290,6 +290,17 @@ describe("the page", () => { | ||
| 290 | 290 | expect(out).not.toMatch(/<details open/); |
| 291 | 291 | }); |
| 292 | 292 | |
| 293 | test("motion is one vocabulary under reduced motion and the person's own choice, opacity and transform only", async () => { | |
| 294 | const { talkCss } = await import("../src/web/pages/talk_client.ts"); | |
| 295 | const anim = [...talkCss.matchAll(/@keyframes [\w-]+ \{([^@]*?)\}\s*\}/g)].map((m) => m[1]!); | |
| 296 | expect(anim.length).toBeGreaterThan(0); | |
| 297 | for (const a of anim) expect(a).not.toMatch(/(height|width|margin|padding|top|bottom)\s*:/); | |
| 298 | expect(talkCss).toContain("@media (prefers-reduced-motion: no-preference) {"); | |
| 299 | expect(talkCss).toContain(".talk[data-motion=reduced] :is(*, ::before, ::after) { animation: none !important; transition: none !important; }"); | |
| 300 | // Every arrival takes the motion tokens; only the running line's shimmer loops, and it is ambient. | |
| 301 | for (const [, v] of talkCss.matchAll(/animation: ([^;}]+)/g)) expect(v!.includes("var(--dur") || v!.includes("infinite") || v!.startsWith("none")).toBe(true); | |
| 302 | }); | |
| 303 | ||
| 293 | 304 | test("the page mirrors in rtl: its own sheets set no physical side, only logical ones", async () => { |
| 294 | 305 | const { talkCss } = await import("../src/web/pages/talk_client.ts"); |
| 295 | 306 | const { paneCss } = await import("../src/web/pages/talk_preview.ts"); |
| @@ -394,11 +405,14 @@ describe("the page", () => { | ||
| 394 | 405 | |
| 395 | 406 | test("the page's own bytes are held: stylesheet and script stay small", async () => { |
| 396 | 407 | const { talkCss, talkJs } = await import("../src/web/pages/talk_client.ts"); |
| 397 | expect(Buffer.byteLength(talkCss)).toBeLessThan(13_600); | |
| 398 | expect(Buffer.byteLength(talkJs)).toBeLessThan(29_400); | |
| 399 | say(alice, "agent", "```ts\nlet x = 1;\n```"); | |
| 400 | const page = await get("/talk", alice); | |
| 401 | const size = (await page.arrayBuffer()).byteLength; | |
| 408 | expect(Buffer.byteLength(talkCss)).toBeLessThan(14_700); | |
| 409 | expect(Buffer.byteLength(talkJs)).toBeLessThan(29_700); | |
| 410 | // A page of its own, so what other tests said to alice never counts: one question and a code reply. | |
| 411 | const sizer = await createUser(app.db, { origin: "seed", trusted: true, username: "sizer", email: "[email protected]", password: "a-good-passphrase" }); | |
| 412 | if (!sizer.ok) throw new Error(sizer.error); | |
| 413 | say(sizer.value, "person", "how?"); | |
| 414 | say(sizer.value, "agent", "```ts\nlet x = 1;\n```"); | |
| 415 | const size = (await (await get("/talk", sizer.value)).arrayBuffer()).byteLength; | |
| 402 | 416 | expect(size).toBeLessThan(43_000); |
| 403 | 417 | }); |
| 404 | 418 | |
| @@ -850,6 +864,13 @@ describe("the page", () => { | ||
| 850 | 864 | expect(t.copied).toEqual(["let a = 1;"]); |
| 851 | 865 | }); |
| 852 | 866 | |
| 867 | test("with steps set to start open (Display), a step that streams in opens its fold as the first paint does", async () => { | |
| 868 | const t = await boot(); | |
| 869 | t.doc.querySelector("[data-talk]").dataset.fold = "open"; | |
| 870 | t.emit("2", '<li class="talk-turn talk-tool talk-step" id="t-2" data-step><details><summary>Read a.ts</summary></details></li>'); | |
| 871 | expect(t.doc.querySelector(".talk-fold > details").open).toBe(true); | |
| 872 | }); | |
| 873 | ||
| 853 | 874 | test("a step that streams in joins the run before it under one closed disclosure: one step by its words, more by their count", async () => { |
| 854 | 875 | const t = await boot(); |
| 855 | 876 | const step = (id: string, label: string) => t.emit(id, `<li class="talk-turn talk-tool talk-step" id="t-${id}" data-step><details><summary>${label} <span class="talk-when">now</span></summary><p>x</p></details></li>`); |
| @@ -893,6 +914,35 @@ describe("the page", () => { | ||
| 893 | 914 | expect(Object.keys(t.store).filter((k) => k.startsWith("talk-draft:"))).toEqual([]); |
| 894 | 915 | }); |
| 895 | 916 | |
| 917 | test("with Enter set to add a line (Display), Enter adds a line and Ctrl or Cmd+Enter sends", async () => { | |
| 918 | const t = await boot(); | |
| 919 | t.doc.querySelector("[data-talk]").dataset.enter = "newline"; | |
| 920 | t.box.value = "two lines"; | |
| 921 | expect(t.key({})).toBe(true); | |
| 922 | await tick(); | |
| 923 | expect(t.sent).toEqual([]); | |
| 924 | expect(t.key({ metaKey: true })).toBe(false); | |
| 925 | await tick(); | |
| 926 | expect(t.sent).toEqual(["two lines"]); | |
| 927 | }); | |
| 928 | ||
| 929 | test("what the stream adds arrives once, marked to settle in; the stored reply taking the live block's place is not", async () => { | |
| 930 | const t = await boot(); | |
| 931 | t.emit("2", '<li class="talk-turn talk-person" id="t-2"><div class="talk-body">hi</div></li>'); | |
| 932 | t.emit("3", '<li class="talk-turn talk-agent" id="t-3"><div class="talk-body prose"><p>Hello</p></div></li>'); | |
| 933 | expect(t.doc.getElementById("t-2").hasAttribute("data-in")).toBe(true); | |
| 934 | expect(t.doc.getElementById("t-3").hasAttribute("data-in")).toBe(false); | |
| 935 | const frame = (html: string) => t.sources.at(-1)!.on["live"]!({ data: JSON.stringify({ html, tool: "", thinking: false }) }); | |
| 936 | frame('<div class="talk-body prose"><p>One</p></div>'); | |
| 937 | frame('<div class="talk-body prose"><p>One</p><p>Two</p></div>'); | |
| 938 | const ps = t.doc.querySelectorAll("#live p"); | |
| 939 | // The new block fades in; the one already there is left as it was. | |
| 940 | expect([ps[0].hasAttribute("data-in"), ps[1].hasAttribute("data-in")]).toEqual([false, true]); | |
| 941 | frame('<div class="talk-body prose"><p>One</p><p>Two, more</p></div>'); | |
| 942 | expect(t.doc.querySelectorAll("#live p")[0]).toBe(ps[0]); | |
| 943 | expect(t.doc.querySelectorAll("#live p")[1].hasAttribute("data-in")).toBe(false); | |
| 944 | }); | |
| 945 | ||
| 896 | 946 | test("a code block in a streamed turn gets its Copy button too", async () => { |
| 897 | 947 | const t = await boot(); |
| 898 | 948 | t.emit("2", '<li class="talk-turn" id="t-2"><div class="talk-body"><pre><code>x</code></pre></div><p class="talk-meta">Forge</p></li>'); |
test/tui-talk-chats.test.ts +30
| @@ -13,6 +13,7 @@ import { createIssue } from "../src/core/issues.ts"; | ||
| 13 | 13 | import { createUser, type User } from "../src/core/users.ts"; |
| 14 | 14 | import { createRepo } from "../src/actions/repos.ts"; |
| 15 | 15 | import { STARTER_PROMPTS } from "../src/actions/talk.ts"; |
| 16 | import { setTalkDisplay, talkDisplay } from "../src/core/settings.ts"; | |
| 16 | 17 | import { createForgeApp } from "../src/tui/forge.ts"; |
| 17 | 18 | import { headlessTerminal } from "../src/tui/term/terminal.ts"; |
| 18 | 19 | import { settleApp } from "./helpers/tui.ts"; |
| @@ -179,6 +180,35 @@ describe("the terminal's conversations screen", () => { | ||
| 179 | 180 | expect(text).not.toContain("mcp__forge__read_file"); |
| 180 | 181 | }); |
| 181 | 182 | |
| 183 | test("steps fold or open as Display says, and v flips the same choice the page reads", async () => { | |
| 184 | const made = createConversation(app.db, bob.id); | |
| 185 | if (!made.ok) throw new Error(made.error); | |
| 186 | for (const p of ["src/a.ts", "src/b.ts", "src/c.ts"]) appendTurn(app.db, bob.id, made.value.id, { role: "tool", text: `mcp__forge__read_file {"repo":"bob/steps","path":"${p}"}` }); | |
| 187 | renameConversation(app.db, bob.id, made.value.id, "Steps here"); | |
| 188 | const folded = await drive(bob, [...open, "/", "Steps here", "\r", "\r"]); | |
| 189 | expect(folded).toContain("3 steps"); | |
| 190 | expect(folded).not.toContain("Read src/b.ts"); | |
| 191 | const opened = await drive(bob, [...open, "/", "Steps here", "\r", "\r", "v"]); | |
| 192 | expect(opened).toContain("Read src/b.ts"); | |
| 193 | expect(opened).toContain("Steps open, here and on /talk."); | |
| 194 | expect(talkDisplay(app.db, bob.id).steps).toBe("open"); | |
| 195 | setTalkDisplay(app.db, bob.id, { steps: "folded" }); | |
| 196 | }); | |
| 197 | ||
| 198 | test("D opens Talk display: Enter moves a choice on and keeps it, the same setting the page reads", async () => { | |
| 199 | const made = createConversation(app.db, bob.id); | |
| 200 | if (!made.ok) throw new Error(made.error); | |
| 201 | appendTurn(app.db, bob.id, made.value.id, { role: "person", text: "hello" }); | |
| 202 | renameConversation(app.db, bob.id, made.value.id, "Display here"); | |
| 203 | const shown = await drive(bob, [...open, "/", "Display here", "\r", "\r", "D"]); | |
| 204 | expect(shown).toContain("Spacing: Comfortable"); | |
| 205 | expect(shown).toContain("Steps: Start folded"); | |
| 206 | const changed = await drive(bob, [...open, "/", "Display here", "\r", "\r", "D", "\r"]); | |
| 207 | expect(changed).toContain("Spacing: Compact. Kept, on /talk."); | |
| 208 | expect(talkDisplay(app.db, bob.id).density).toBe("compact"); | |
| 209 | setTalkDisplay(app.db, bob.id, { density: "comfortable" }); | |
| 210 | }); | |
| 211 | ||
| 182 | 212 | test("p shows what the chat works on, as the web's pane does; a repository it cannot read shows nothing of it", async () => { |
| 183 | 213 | const made = createConversation(app.db, alice.id); |
| 184 | 214 | if (!made.ok) throw new Error(made.error); |
Non-blocking: two blank lines after a floating doc comment. Attach it to
TalkDisplayor drop the extra blank.