Public: anyone can read this; the crew can change it.
Talk's pane shows the crew building from the moment its run is queued, and the app as soon as it answers #16339
Check · Review · Land · Live done — Landed and live in production.
talk/live-pane → main 0 commits 2 threads · 2 unresolved
17 files
changed +759
−36
docs/design/areas/talk.md +1
| @@ -133,3 +133,4 @@ Prior art: Claude and ChatGPT (one centred column, the person's words in a quiet | ||
| 133 | 133 | - `.talk-display-sheet`: Display as its own small dialog from the conversation menu, every choice in view; without the script it stays a disclosure in the menu. |
| 134 | 134 | - `.talk-links`: what a reply opened or changed, folded behind its count ("3 files") on the reply's one last line, each file by its path in its repository. |
| 135 | 135 | - `.talk-stage-files`: before a first version, the pane says what will appear and when, and shows the files the app starts from. |
| 136 | - `.talk-crew-now`, `.talk-crew-steps`: the crew's run in the pane's wait stage: why it waits or that it works, its newest steps in plain words as lines of text, and the run's page. |
docs/design/size-budget.json +2 −2
| @@ -68,8 +68,8 @@ | ||
| 68 | 68 | "css": 48384 |
| 69 | 69 | }, |
| 70 | 70 | "/talk": { |
| 71 | "js": 37888, | |
| 72 | "css": 54528 | |
| 71 | "js": 39168, | |
| 72 | "css": 55040 | |
| 73 | 73 | }, |
| 74 | 74 | "/:owner/:name/pulls/:number": { |
| 75 | 75 | "js": 32000, |
docs/features/talk.md +5 −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 18,000 B, the script under 43,500 B, and a page with a code reply under 50,000 B (its own page: one question and a code reply; the widgets' rules ride every page, so a chart drawn in a live reply is styled at once). | |
| 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 18,000 B, the script under 47,300 B, and a page with a code reply under 52,000 B (its own page: one question and a code reply; the widgets' rules ride every page, so a chart drawn in a live reply is styled at once). | |
| 140 | 140 | |
| 141 | 141 | ## Following |
| 142 | 142 | |
| @@ -230,3 +230,7 @@ Beside a conversation that builds or changes an app, the pane's **Code** tab is | ||
| 230 | 230 | The pane's Preview tab frames the app the conversation builds, on the app's own host. An app's answer says who may frame it; the proxy (`admitForgeFrame`, `src/apps/frame_policy.ts`) adds the forge's own origin, and only that origin, to a `frame-ancestors` that restricts framing (`'none'` becomes the forge, `'self'` or a list keeps its sources and gains the forge). A policy that frames freely (`*`, or none) is the app's choice and stays as it is. An `X-Frame-Options: DENY` or `SAMEORIGIN` becomes `frame-ancestors <forge>`. Any other site that frames the app is refused by the browser, as before. |
| 231 | 231 | |
| 232 | 232 | A private preview signs the person in inside the frame through their own grant. That grant's cookie is set inside the frame as `SameSite=None; Secure; Partitioned`, so it is kept per embedding site, is sent only while the forge is the framing page, and lives half an hour. A frame that is not signed in gets one sentence and a link that opens the preview on its own, never a redirect it cannot follow. A preview that is not serving shows the forge's own sentence inside the frame, with its links opening beside it. Proof: `test/apps-frame-policy.test.ts`, `test/talk-preview-frame.test.ts` (a real Chromium). |
| 233 | ||
| 234 | ## The pane while the crew works (#15734) | |
| 235 | ||
| 236 | Until the app answers, the pane's Preview tab shows what the crew is doing on the repository: its newest run in plain words (`crewNow`, `src/core/talk_work.ts`). A queued run says why it waits (the hold sentence, with the control that changes it); a running one lists its newest six steps (a file read or changed, a search, the checks, a commit, a push), each added as the run writes it, from the forge's own event stream (`run.log`), by the same `plainStep` the server uses; a finished or failed one says how it ended. A log line is the builder's untrusted text: it is only ever drawn as text, and only for a reader who may read the run's log (`mayReadRunLog`: the repository's own facts or the crew); anyone else who may see the runs reads how it stands and the link, never a step, and the live tail is never sent them (`/events` sends `run.log` only to who may read it). "See the whole run" links the run's page, which is all of it without the script. The pane is a live region on the repository's runs, so the first deploy that turns running swaps the frame in; the page names the app's production origin in `frame-src` ahead, and a frame of another origin draws the page once. The pane opens by itself once the crew is on the repository the conversation names; a new app is named by its receipt (`New app owner/name`). In the terminal, the conversation's pane (`p`) prints the same lines and redraws as the run writes. Proof: `test/talk-live-pane.test.ts`. |
src/core/conversation_writes.ts +10 −6
| @@ -99,19 +99,23 @@ export function unended(db: Database, via: string): string[] { | ||
| 99 | 99 | } |
| 100 | 100 | |
| 101 | 101 | /** |
| 102 | * What this turn's finished `tell` calls answered, oldest first; an answer that is not the tell's | |
| 103 | * shape is skipped. | |
| 102 | * What this turn's finished `tell` and `new_app` calls answered, oldest first: the issue each opened | |
| 103 | * and its page, and for a new app its repository; an answer that is not that shape is skipped. | |
| 104 | 104 | */ |
| 105 | export function toldIn(db: Database, via: string): { issue: number; page: string }[] { | |
| 106 | const out: { issue: number; page: string }[] = []; | |
| 105 | export function toldIn(db: Database, via: string): { issue: number; page: string; app?: string }[] { | |
| 106 | const out: { issue: number; page: string; app?: string }[] = []; | |
| 107 | 107 | for (const row of db |
| 108 | .query<{ result: string }, [string]>("SELECT result FROM conversation_write WHERE via = ?1 AND tool = 'tell' AND result IS NOT NULL ORDER BY id") | |
| 108 | .query<{ tool: string; result: string }, [string]>("SELECT tool, result FROM conversation_write WHERE via = ?1 AND tool IN ('tell', 'new_app') AND result IS NOT NULL ORDER BY id") | |
| 109 | 109 | .all(via)) { |
| 110 | 110 | try { |
| 111 | 111 | const data = JSON.parse(row.result) as Record<string, unknown> | null; |
| 112 | 112 | const issue = data?.["issue"]; |
| 113 | 113 | const page = data?.["page"]; |
| 114 | if (typeof issue === "number" && Number.isInteger(issue) && issue > 0 && typeof page === "string") out.push({ issue, page }); | |
| 114 | const repo = data?.["repo"]; | |
| 115 | if (row.tool === "new_app") { | |
| 116 | // A new app's first build is on the issue it opened: the receipt follows that build. | |
| 117 | if (typeof issue === "number" && Number.isInteger(issue) && issue > 0 && typeof repo === "string" && /^[^/\s]+\/[^/\s]+$/.test(repo)) out.push({ issue, page: `/${repo}/issues/${String(issue)}`, app: repo }); | |
| 118 | } else if (typeof issue === "number" && Number.isInteger(issue) && issue > 0 && typeof page === "string") out.push({ issue, page }); | |
| 115 | 119 | } catch { |
| 116 | 120 | // A result cut at RESULT_MAX is not JSON: it is not a receipt. |
| 117 | 121 | } |
src/core/talk_steps.ts +16
| @@ -162,10 +162,26 @@ export function repoOf(turns: readonly Said[]): string | undefined { | ||
| 162 | 162 | if (t.role !== "tool") continue; |
| 163 | 163 | const repo = parseCall(t.text)?.args["repo"]; |
| 164 | 164 | if (typeof repo === "string" && REPO.test(repo)) return repo; |
| 165 | // A receipt names its repository by its page (`/owner/name`, or an issue of it): a new app has no | |
| 166 | // call that names it, only the receipt of the call that made it. | |
| 167 | const href = receiptHref(t.text); | |
| 168 | const named = href === undefined ? undefined : /^\/([^/]+\/[^/]+)(?:\/|$)/.exec(href)?.[1]; | |
| 169 | if (named !== undefined && REPO.test(named)) return named; | |
| 165 | 170 | } |
| 166 | 171 | return undefined; |
| 167 | 172 | } |
| 168 | 173 | |
| 174 | /** A receipt turn's page, or undefined when the turn is not one. */ | |
| 175 | const receiptHref = (text: string): string | undefined => { | |
| 176 | if (!text.startsWith("{")) return undefined; | |
| 177 | try { | |
| 178 | const href = (JSON.parse(text) as { done?: unknown; receipt?: { href?: unknown } }).receipt?.href; | |
| 179 | return typeof href === "string" ? href : undefined; | |
| 180 | } catch { | |
| 181 | return undefined; | |
| 182 | } | |
| 183 | }; | |
| 184 | ||
| 169 | 185 | const PATH = /^(?!\/)(?!.*(?:^|\/)\.\.(?:\/|$))[^\0\n]{1,300}$/; |
| 170 | 186 | |
| 171 | 187 | /** The files the calls on `repo` read or edited, newest first, each once, at most `max`. */ |
src/core/talk_work.ts +78 −4
| @@ -214,18 +214,20 @@ const forMinutes = (at: string | null, now: number): string => | ||
| 214 | 214 | const WORK_WORDS = { closed: "Done: it is closed.", landed: "landed", ready: "is ready: waiting for you to land it.", checksRunning: "checks running", checksFailed: "checks failed", pushed: "pushed", queued: "Queued for", working: "has been working on it", failed: "'s run did not finish.", finished: "finished.", assigned: "Assigned to", crew: "The crew" } as const; |
| 215 | 215 | |
| 216 | 216 | /** |
| 217 | * What the crew is doing on an issue now, in one line, read when it is asked for: closed; a pull | |
| 218 | * its run pushed (landed, ready and waiting for the person, checks running or red); the run queued, | |
| 217 | * What the crew is doing on an issue now, in one line, read when it is asked for: the pull its run | |
| 218 | * landed (even once that closed the issue); closed; a pull its run pushed (ready and waiting for the | |
| 219 | * person, checks running or red); the run queued, | |
| 219 | 220 | * working (for how long), or ended; else who it is assigned to; "" when nobody is on it. |
| 220 | 221 | */ |
| 221 | 222 | export function workLine(db: Database, issue: Issue, now: number): string { |
| 222 | if (issue.state === "closed") return WORK_WORDS.closed; | |
| 223 | 223 | const named = issue.assigneeId === null ? undefined : getUserById(db, issue.assigneeId)?.username; |
| 224 | 224 | const who = named ?? WORK_WORDS.crew; |
| 225 | 225 | const run = lastRun(db, issue); |
| 226 | 226 | const pull = run === null || run.branch === "" ? null : db.query<{ id: string; number: number; merged_at: string | null }, [string, string]>("SELECT i.id, i.number, p.merged_at FROM pull p JOIN issue i ON i.id = p.issue_id WHERE p.head_branch = ?1 AND i.repo_id = ?2 ORDER BY i.number DESC LIMIT 1").get(run.branch, issue.repoId); |
| 227 | // A landed pull says so even once it closed its issue: "landed #2" is the news, "closed" is not. | |
| 228 | if (pull !== null && pull.merged_at !== null) return `${who} ${WORK_WORDS.landed} #${pull.number}.`; | |
| 229 | if (issue.state === "closed") return WORK_WORDS.closed; | |
| 227 | 230 | if (pull !== null) { |
| 228 | if (pull.merged_at !== null) return `${who} ${WORK_WORDS.landed} #${pull.number}.`; | |
| 229 | 231 | const check = db.query<{ state: string }, [string]>("SELECT state FROM run WHERE issue_id = ?1 AND kind = 'check' ORDER BY id DESC LIMIT 1").get(pull.id); |
| 230 | 232 | if (check?.state === "ok") return `${who} ${WORK_WORDS.pushed} #${pull.number}, which ${WORK_WORDS.ready}`; |
| 231 | 233 | return `${who} ${WORK_WORDS.pushed} #${pull.number}: ${check?.state === "failed" ? WORK_WORDS.checksFailed : WORK_WORDS.checksRunning}.`; |
| @@ -408,3 +410,75 @@ export function liveReceipts(db: Database, dataDir: string, user: User, turns: r | ||
| 408 | 410 | /** The work line of each receipt, by turn id, as the page draws it. */ |
| 409 | 411 | export const receiptLines = (db: Database, dataDir: string, user: User, turns: readonly { readonly id: string; readonly role: string; readonly text: string }[]): Map<string, WorkLine> => |
| 410 | 412 | new Map([...liveReceipts(db, dataDir, user, turns)].map(([id, r]) => [id, r.line])); |
| 413 | ||
| 414 | /** | |
| 415 | * One line of a crew run's log in plain words, or undefined for a line a person need not read: a | |
| 416 | * file read or changed, a search, the tests, a commit, a push, the run's end. The page's live tail | |
| 417 | * runs this same function (its source is sent with the page's script), so both say the same. | |
| 418 | */ | |
| 419 | export function plainStep(line: string): string | undefined { | |
| 420 | const tool = /^→ (\S+)(?: (.*))?$/.exec(line); | |
| 421 | if (tool !== null) { | |
| 422 | const name = tool[1] ?? ""; | |
| 423 | const rest = (tool[2] ?? "").trim(); | |
| 424 | const short = (s: string): string => (s.length > 80 ? `${s.slice(0, 79)}…` : s); | |
| 425 | if (name === "Read") return rest === "" ? "Read a file" : `Read ${short(rest)}`; | |
| 426 | if (name === "Edit" || name === "Write" || name === "MultiEdit" || name === "NotebookEdit") return rest === "" ? "Changed a file" : `Changed ${short(rest)}`; | |
| 427 | if (name === "Grep" || name === "Glob") return "Searched the code"; | |
| 428 | if (name === "Bash") { | |
| 429 | if (/^git push\b/.test(rest)) return "Pushed its work"; | |
| 430 | if (/^git commit\b/.test(rest)) return "Committed"; | |
| 431 | if (/\b(bun|npm|pnpm|yarn) (run )?test\b|\bbun x tsc\b/.test(rest)) return "Ran the checks"; | |
| 432 | return "Ran a command"; | |
| 433 | } | |
| 434 | return undefined; | |
| 435 | } | |
| 436 | const done = /^done: (.*)$/.exec(line); | |
| 437 | if (done !== null) return `Done: ${(done[1] ?? "").slice(0, 120)}`; | |
| 438 | if (/^cloning \S+$/.test(line)) return "Started on a fresh copy of the repository"; | |
| 439 | return undefined; | |
| 440 | } | |
| 441 | ||
| 442 | /** How many of a run's plain steps the pane shows at once: enough to see it move. */ | |
| 443 | export const STEPS_SHOWN = 6; | |
| 444 | ||
| 445 | /** What the crew is doing on a repository now, for the pane: its newest run, in words. */ | |
| 446 | export interface PaneCrew { | |
| 447 | readonly runId: string; | |
| 448 | readonly state: "queued" | "running" | "ok" | "failed"; | |
| 449 | /** One line: why it waits, that it is working, or how it ended. */ | |
| 450 | readonly line: WorkLine; | |
| 451 | /** The newest plain steps of its log, oldest first; none for a reader who may not read the log. */ | |
| 452 | readonly steps: readonly string[]; | |
| 453 | /** The reader may read the run's log: the page tails it live, by the run's id. */ | |
| 454 | readonly tail: boolean; | |
| 455 | } | |
| 456 | ||
| 457 | /** What a reader may see of a repository's runs, as `actions/runs.ts` decides it. */ | |
| 458 | export interface RunsSeen { | |
| 459 | /** The runs themselves (`mayReadRuns`). */ | |
| 460 | readonly runs: boolean; | |
| 461 | /** Their logs (`mayReadRunLog`): the repository's own facts or the crew's. */ | |
| 462 | readonly logs: boolean; | |
| 463 | } | |
| 464 | ||
| 465 | /** | |
| 466 | * The repository's newest crew run, as the pane says it; undefined when the crew has never run there | |
| 467 | * or the reader may not see its runs. A step is read from the log only for a reader who may read it. | |
| 468 | */ | |
| 469 | export function paneCrew(db: Database, dataDir: string, repoId: string, reader: User | undefined, seen: RunsSeen): PaneCrew | undefined { | |
| 470 | if (!seen.runs) return undefined; | |
| 471 | const run = db | |
| 472 | .query<{ id: string; state: string }, [string]>("SELECT id, state FROM run WHERE repo_id = ?1 AND kind = 'agent' ORDER BY id DESC LIMIT 1") | |
| 473 | .get(repoId); | |
| 474 | if (run === null) return undefined; | |
| 475 | const steps = seen.logs ? readRunLogTail(dataDir, run.id, 200).lines.flatMap((l) => plainStep(l) ?? []).slice(-STEPS_SHOWN) : []; | |
| 476 | const at = { runId: run.id, steps, tail: seen.logs }; | |
| 477 | if (run.state === "queued") { | |
| 478 | const hold = holdNow(db, dataDir, run.id); | |
| 479 | return { ...at, state: "queued", line: hold === undefined ? { says: "Queued for the crew: it starts when a builder is free." } : holdWords(hold, holdReader(db, repoId, reader)) }; | |
| 480 | } | |
| 481 | if (run.state === "running") return { ...at, state: "running", line: { says: "The crew is building it now." } }; | |
| 482 | if (run.state === "ok") return { ...at, state: "ok", line: { says: "The crew finished this run." } }; | |
| 483 | return { ...at, state: "failed", line: { says: "The crew's run did not finish." } }; | |
| 484 | } |
src/crew/conversation_brief.ts +1
| @@ -24,6 +24,7 @@ export const VOICE: readonly string[] = [ | ||
| 24 | 24 | "After you act, say what changed and where in at most three lines, and give detail only when they ask; the known block is for questions about the state of things, never an appendix to a change.", |
| 25 | 25 | "Use a value the person gave (a colour, a name, a number) exactly; if it fails something real, such as contrast, say so in one line and offer the nearest value that passes.", |
| 26 | 26 | "Never say the forge lacks something you have not looked for, and never say a held action will do more than its call does.", |
| 27 | "When you have set the crew building, say that the line under the receipt follows the build as it goes (waiting, working, pushed, landed): never a moment's state such as that it is queued and not built yet, and never that a pull request will appear for them to land, since the crew may land it itself and the line says when.", | |
| 27 | 28 | "When a tool answer about a run carries `waiting`, say that sentence as it is and give its `change` address as a link worded with `changeWords`; never say only that it is queued or has not started.", |
| 28 | 29 | "Say each thing once: a choice offered as buttons is not asked again in prose, and never say nothing is waiting on them while you hold an ask.", |
| 29 | 30 | "When you make an app, say in the same reply who can open it: a new app is private, so only they and people they invite can, and anyone else gets a not-found page; say how they open it up or invite someone.", |
src/crew/filed.ts +6 −4
| @@ -1,6 +1,7 @@ | ||
| 1 | 1 | /** |
| 2 | 2 | * Where a line said in /talk went (#13942): when the turn's agent told the |
| 3 | * crew, a receipt turn names each issue it opened — "Filed #N" linking to it — | |
| 3 | * crew, a receipt turn names each issue it opened — "Filed #N" linking to it, | |
| 4 | * or "New app owner/name" linking to the issue its first build is on — | |
| 4 | 5 | * whatever the turn did next; and when a turn that answered had words that |
| 5 | 6 | * matched an ask for work and nothing was filed, a plain turn says only that. |
| 6 | 7 | * Plain data in, the JSON of one `tool` turn out. |
| @@ -40,16 +41,17 @@ const PAGE = /^\/([^/\s]+)\/([^/\s]+)\/issues\/(\d+)$/; | ||
| 40 | 41 | export function filedTurns(db: Database, via: string, words: string, answered: boolean): string[] { |
| 41 | 42 | const told = toldIn(db, via); |
| 42 | 43 | if (told.length === 0) return answered && asksForWork(words) ? [JSON.stringify({ filed: false, done: true, says: FILED_NOTHING })] : []; |
| 43 | return told.flatMap(({ issue, page }) => { | |
| 44 | return told.flatMap(({ issue, page, app }) => { | |
| 44 | 45 | let path: string; |
| 45 | 46 | try { |
| 46 | path = new URL(page).pathname; | |
| 47 | path = page.startsWith("/") ? page : new URL(page).pathname; | |
| 47 | 48 | } catch { |
| 48 | 49 | return []; |
| 49 | 50 | } |
| 50 | 51 | const m = PAGE.exec(path); |
| 51 | 52 | const repo = m === null ? undefined : getRepo(db, m[1]!, m[2]!); |
| 52 | 53 | const title = repo === undefined ? "" : (getIssue(db, repo.id, issue)?.title ?? ""); |
| 53 | return [JSON.stringify({ filed: true, done: true, ...(title === "" ? {} : { title }), receipt: { verb: "Filed", object: `#${issue}`, href: path } })]; | |
| 54 | const receipt = app === undefined ? { verb: "Filed", object: `#${issue}`, href: path } : { verb: "New app", object: app, href: path }; | |
| 55 | return [JSON.stringify({ filed: true, done: true, ...(title === "" ? {} : { title }), receipt })]; | |
| 54 | 56 | }); |
| 55 | 57 | } |
src/crew/receipt.ts +6 −2
| @@ -69,10 +69,14 @@ const verbOf = (tool: string): string => { | ||
| 69 | 69 | export function receiptOf(tool: string, args: Args, value: unknown, before: Seen | undefined): Receipt | undefined { |
| 70 | 70 | const target = targetOf(args); |
| 71 | 71 | if (!INVERSES.has(tool) || target === undefined || before === undefined || typeof value !== "object" || value === null) { |
| 72 | const repo = repoOf(args); | |
| 72 | // A call that made the repository (`new_app`) names it in the forge's answer, not its arguments. | |
| 73 | const made = typeof value === "object" && value !== null ? (value as Record<string, unknown>)["repo"] : undefined; | |
| 74 | const repo = repoOf(args) ?? (typeof made === "string" ? repoOf({ repo: made }) : undefined); | |
| 73 | 75 | if (repo === undefined) return undefined; |
| 76 | // A made app names the issue its first build is on: the receipt follows that build live. | |
| 77 | const filed = made !== undefined && typeof (value as Record<string, unknown>)["issue"] === "number" ? ((value as Record<string, unknown>)["issue"] as number) : undefined; | |
| 74 | 78 | const number = target?.number; |
| 75 | const page = number === undefined ? `/${repo}` : `/${repo}/${before?.kind === "pull" ? "pulls" : "issues"}/${number}`; | |
| 79 | const page = number === undefined ? (filed === undefined ? `/${repo}` : `/${repo}/issues/${String(filed)}`) : `/${repo}/${before?.kind === "pull" ? "pulls" : "issues"}/${number}`; | |
| 76 | 80 | return { verb: verbOf(tool), object: number === undefined ? repo : `${repo}#${number}`, href: page }; |
| 77 | 81 | } |
| 78 | 82 | const answer = value as Record<string, unknown>; |
src/tui/screens/talk_chats.ts +22 −2
| @@ -32,13 +32,15 @@ import { filesOf, repoOf, stepOf } from "../../core/talk_steps.ts"; | ||
| 32 | 32 | import { cardsPlaced, holdsCard, plainVoice } from "../../core/talk_voice.ts"; |
| 33 | 33 | import { setTalkDisplay, talkDisplay } from "../../core/settings.ts"; |
| 34 | 34 | import { talkDisplayScreen } from "./talk_display.ts"; |
| 35 | import { liveReceipts, type LiveReceipt } from "../../core/talk_work.ts"; | |
| 35 | import { liveReceipts, paneCrew, type LiveReceipt } from "../../core/talk_work.ts"; | |
| 36 | import { tapRunLogs } from "../../runs/log.ts"; | |
| 37 | import { mayReadRunLog, mayReadRuns } from "../../actions/runs.ts"; | |
| 36 | 38 | import { confirmsScreen } from "./confirms.ts"; |
| 37 | 39 | import { waitingConfirms } from "../../actions/conversation_confirms.ts"; |
| 38 | 40 | import { branchDiff, chatBuildOf } from "../../core/chat_build.ts"; |
| 39 | 41 | import { addCommentThrough } from "../../actions/issues.ts"; |
| 40 | 42 | import { getIssue } from "../../core/issues.ts"; |
| 41 | import { canRead, getRepo } from "../../core/repos.ts"; | |
| 43 | import { canRead, getRepo, getRepoById } from "../../core/repos.ts"; | |
| 42 | 44 | import type { ShownCard } from "../../core/talk_voice.ts"; |
| 43 | 45 | import { workspaceOf } from "../../actions/talk_workspace.ts"; |
| 44 | 46 | import type { Ctx, Screen } from "../app/app.ts"; |
| @@ -165,6 +167,18 @@ function chatScreen(f: Session, ctx: Ctx, chat: Conversation, hit?: string): Scr | ||
| 165 | 167 | const sign = { add: "+", del: "-", context: " " } as const; |
| 166 | 168 | changed = d === undefined ? undefined : { branch: d.branch, files: d.diff.files.map((x) => ({ path: x.path, additions: x.additions, deletions: x.deletions, lines: x.hunks.flatMap((h) => h.lines.map((l) => `${sign[l.kind]}${l.content}`)) })) }; |
| 167 | 169 | }; |
| 170 | // The crew's newest run on the repository, as the page's waiting pane says it, tailed live while the | |
| 171 | // pane is open: its log taps this screen (`load`), and a new line of that run redraws it. | |
| 172 | let watched: string | undefined; | |
| 173 | const crewLines = (repoId: string): string[] => { | |
| 174 | const home = getRepoById(f.app.db, repoId); | |
| 175 | const crew = f.user === undefined || home === undefined ? undefined : paneCrew(f.app.db, f.app.config.dataDir, repoId, f.user, { runs: mayReadRuns(f.app, f.user, home), logs: mayReadRunLog(f.app, f.user, home) }); | |
| 176 | watched = crew?.runId; | |
| 177 | if (crew === undefined) return []; | |
| 178 | const l = crew.line; | |
| 179 | const said = l.change === undefined ? l.says : `${l.says} ${l.change.words}: ${f.app.config.url === undefined ? l.change.href : publicOrigin(f.app.config.url, "") + l.change.href}`; | |
| 180 | return ["", `Crew: ${said}`, ...crew.steps.map((step) => ` ${step}`), `The whole run: /${repo ?? ""}/runs/${crew.runId}`]; | |
| 181 | }; | |
| 168 | 182 | const paneLines = (): string[] => { |
| 169 | 183 | if (repo === undefined || f.user === undefined) return ["No repository yet."]; |
| 170 | 184 | const ws = workspaceOf(f.app, f.user, repo); |
| @@ -174,6 +188,7 @@ function chatScreen(f: Session, ctx: Ctx, chat: Conversation, hit?: string): Scr | ||
| 174 | 188 | `${repo} · ${ws.pull === undefined ? "Production" : `Pull #${String(ws.pull)}`}`, |
| 175 | 189 | "", |
| 176 | 190 | ws.url === undefined ? "Nothing running yet." : `Preview: ${ws.url}`, |
| 191 | ...(ws.url === undefined ? crewLines(ws.repo.id) : []), | |
| 177 | 192 | ws.pull === undefined ? "No open pull yet." : `Diff: /${repo}/pulls/${String(ws.pull)}/files`, |
| 178 | 193 | "", |
| 179 | 194 | ...(changed === undefined |
| @@ -233,6 +248,11 @@ function chatScreen(f: Session, ctx: Ctx, chat: Conversation, hit?: string): Scr | ||
| 233 | 248 | return [...thread, ...dock]; |
| 234 | 249 | }; |
| 235 | 250 | const screen: Screen = { |
| 251 | async load(signal) { | |
| 252 | tapRunLogs((runId) => { | |
| 253 | if (pane && runId === watched) ctx.invalidate(); | |
| 254 | }, signal); | |
| 255 | }, | |
| 236 | 256 | get title() { |
| 237 | 257 | return chat.title === "" ? "Untitled conversation" : chat.title; |
| 238 | 258 | }, |
src/web/pages/talk.ts +11 −5
| @@ -63,6 +63,7 @@ import { field, readForm } from "../form.ts"; | ||
| 63 | 63 | import { html, raw, type Html } from "../html.ts"; |
| 64 | 64 | import { flashTo, fragment, page, redirect } from "../layout.ts"; |
| 65 | 65 | import { getRepoById } from "../../core/repos.ts"; |
| 66 | import { mayReadRunLog, mayReadRuns } from "../../actions/runs.ts"; | |
| 66 | 67 | import { codePaneCss } from "../talk_code.ts"; |
| 67 | 68 | import { linkRefs, refTarget } from "../../text/talk_links.ts"; |
| 68 | 69 | import { appLook, linkTalk, talkLook, type TalkLook } from "../../text/talk_link_words.ts"; |
| @@ -73,7 +74,8 @@ import { badge, btn, icon, iconBtn, menu, meter, row, time } from "../ui.ts"; | ||
| 73 | 74 | import { inlineIcons } from "../icons.ts"; |
| 74 | 75 | import { DISPLAY_NAMES, setTalkDisplay, TALK_DISPLAY, talkDisplay, type TalkDisplay } from "../../core/settings.ts"; |
| 75 | 76 | import { peekCss, workLineHtml } from "../talk_peek.ts"; |
| 76 | import { receiptLines, type WorkLine } from "../../core/talk_work.ts"; | |
| 77 | import { paneCrew, receiptLines, type WorkLine } from "../../core/talk_work.ts"; | |
| 78 | import { workspaceOf } from "../../actions/talk_workspace.ts"; | |
| 77 | 79 | import { buildCss, chosenTemplate, panelFor, templateChips } from "../talk_build.ts"; |
| 78 | 80 | import type { User } from "../../core/users.ts"; |
| 79 | 81 | import { chatBuildOf } from "../../core/chat_build.ts"; |
| @@ -599,15 +601,15 @@ async function talkPage(ctx: Ctx, conversation: Conversation, before0: string | | ||
| 599 | 601 | // A tab asks for the pane alone, so it swaps in place without the page. |
| 600 | 602 | if (ctx.url.searchParams.get("fragment") === "pane") return fragment(pane.html, { request: ctx.request }); |
| 601 | 603 | // The side pane is there only when it has something to show: an app being built, or one running. |
| 602 | const split = panel !== null || pane.live; | |
| 604 | const split = panel !== null || pane.live || pane.crew; | |
| 603 | 605 | // The frame shows what runs; beside a build it waits for the build's own preview. |
| 604 | const framed = pane.live && !pending; | |
| 606 | const framed = (pane.live || pane.crew) && !pending; | |
| 605 | 607 | const about = editing === undefined ? aboutLine(ctx) : null; |
| 606 | 608 | const display = talkDisplay(ctx.app.db, user.id); |
| 607 | 609 | const lines = receiptLines(ctx.app.db, ctx.app.config.dataDir, user, turns); |
| 608 | 610 | // The crew's line says something only while a run is live: idle is silence. |
| 609 | 611 | const crew = liveCrewRows(ctx, user); |
| 610 | 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> | |
| 612 | const body = html`<div class="talk-page" data-shell${pane.frame === undefined || !framed ? null : html` data-frame-origin="${pane.frame}"`} data-pane="${shown}"${listing ? raw(" data-view=\"list\"") : null}${split ? raw(" data-split") : null}><h1 class="sr-only">Talk</h1> | |
| 611 | 613 | <div class="talk-side">${chats(ctx, conversation, showArchived, typed)}</div> |
| 612 | 614 | <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"}"> |
| 613 | 615 | ${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)} |
| @@ -653,7 +655,7 @@ async function talkPage(ctx: Ctx, conversation: Conversation, before0: string | | ||
| 653 | 655 | </div> |
| 654 | 656 | ${split ? html`<div class="talk-work">${panel}${pane.html}</div>` : null} |
| 655 | 657 | </div>`; |
| 656 | return page({ ctx, title: conversation.title === "" ? "Talk" : `${conversation.title} · Talk`, body, styleCss: talkCss + peekCss + (split ? paneCss + codePaneCss : "") + (panel === null ? "" : buildCss) + voiceCss, scriptJs: `${talkJs}\n${liveRegionsJs}`, description: "Talk to the forge.", wide: true, ...(pane.frame === undefined || !framed ? {} : { frameSrc: pane.frame }) }); | |
| 658 | return page({ ctx, title: conversation.title === "" ? "Talk" : `${conversation.title} · Talk`, body, styleCss: talkCss + peekCss + paneCss + codePaneCss + (panel === null ? "" : buildCss) + voiceCss, scriptJs: `${talkJs}\n${liveRegionsJs}`, description: "Talk to the forge.", wide: true, ...(pane.frame === undefined || !framed ? {} : { frameSrc: pane.frame }) }); | |
| 657 | 659 | } |
| 658 | 660 | |
| 659 | 661 | /** |
| @@ -977,7 +979,11 @@ export function talkStream(ctx: Ctx): Response { | ||
| 977 | 979 | const costs = [...turnSpend(app.db, conversation.id)].slice(-5).map(([id, spend]) => ({ id: `t-${id}`, html: costLine(spend).text })); |
| 978 | 980 | const context = contextOf(app.db, conversation.id); |
| 979 | 981 | const total = conversationTotal(app.db, conversation.id); |
| 982 | // The pane opens once the repository it works on has something running or the crew on it. | |
| 983 | const ws = cited === undefined ? undefined : workspaceOf(app, user, cited); | |
| 984 | const doing = ws === undefined ? undefined : paneCrew(app.db, app.config.dataDir, ws.repo.id, user, { runs: mayReadRuns(app, user, ws.repo), logs: mayReadRunLog(app, user, ws.repo) })?.state; | |
| 980 | 985 | emit("done", { |
| 986 | pane: ws !== undefined && (ws.url !== undefined || doing === "queued" || doing === "running"), | |
| 981 | 987 | costs, |
| 982 | 988 | total: total === undefined ? "" : totalText(total), |
| 983 | 989 | context: context === undefined ? "" : contextText(context), |
src/web/pages/talk_client.ts +45
| @@ -50,6 +50,8 @@ | ||
| 50 | 50 | * phone, is a plain link: the list is its own page below 900 px. |
| 51 | 51 | */ |
| 52 | 52 | |
| 53 | import { plainStep, STEPS_SHOWN } from "../../core/talk_work.ts"; | |
| 54 | ||
| 53 | 55 | export const talkCss = /* css */ ` |
| 54 | 56 | #main:has(> .talk-page) { padding-top: 0; padding-bottom: 0; } |
| 55 | 57 | body:has(.talk-page) .foot { display: none; } |
| @@ -706,6 +708,9 @@ if (root) { | ||
| 706 | 708 | reframe(); |
| 707 | 709 | pullBuild(); |
| 708 | 710 | const o = JSON.parse(e.data), c = root.querySelector("[data-context]"), t = root.querySelector("[data-total]"); |
| 711 | // A reply that made an app or set the crew on one opens the pane: the page is drawn again once, | |
| 712 | // so the app's origin joins frame-src (the build panel does the same when its preview turns ready). | |
| 713 | if (o.pane === true) openPane(); | |
| 709 | 714 | for (const k of o.costs || []) { const li = document.getElementById(k.id); if (li && !li.querySelector(".talk-cost")) li.insertAdjacentHTML("beforeend", k.html); } |
| 710 | 715 | if (o.total && t) { t.hidden = false; t.textContent = o.total; } |
| 711 | 716 | if (o.context && c) { c.hidden = false; c.textContent = o.context; } |
| @@ -922,6 +927,46 @@ ${dictateJs} | ||
| 922 | 927 | }); |
| 923 | 928 | resume(); |
| 924 | 929 | if (root.dataset.running === "1" && !paged) { log.setAttribute("aria-busy", "true"); follow(); } |
| 930 | // The crew's run in the pane's wait stage: each line it writes, in the same plain words the server | |
| 931 | // drew the first ones in, added as text only (a log line is never markup), the newest few kept. | |
| 932 | const plainStep = ${String(plainStep)}; | |
| 933 | document.addEventListener("forge:run-log", (e) => { | |
| 934 | const d = e.detail, steps = d && [...document.querySelectorAll("[data-crew-steps]")].find((el) => el.dataset.crewSteps === d.run); | |
| 935 | if (!steps || !Array.isArray(d.lines)) return; | |
| 936 | for (const line of d.lines) { | |
| 937 | const step = typeof line === "string" ? plainStep(line) : undefined; | |
| 938 | if (!step) continue; | |
| 939 | const p = document.createElement("p"); | |
| 940 | p.textContent = step; | |
| 941 | steps.append(p); | |
| 942 | } | |
| 943 | while (steps.children.length > ${STEPS_SHOWN}) steps.firstElementChild.remove(); | |
| 944 | }); | |
| 945 | // A reply that set the crew on an app opens the pane in place: the page is read again and its head | |
| 946 | // (the Chat and Preview tabs) and its pane are swapped in. Only a pane that already frames the app | |
| 947 | // draws the page once, since its origin must join frame-src, which a page cannot change on itself. | |
| 948 | async function openPane() { | |
| 949 | const shell = document.querySelector("[data-shell]"); | |
| 950 | if (!shell || shell.hasAttribute("data-split")) return; | |
| 951 | try { | |
| 952 | const t = document.createElement("template"); | |
| 953 | t.innerHTML = await (await fetch(window.location.href, { headers: { accept: "text/html" } })).text(); | |
| 954 | const fresh = t.content.querySelector("[data-shell]"), work = fresh && fresh.querySelector(".talk-work"), head = fresh && fresh.querySelector(".talk-head"); | |
| 955 | if (!work) return; | |
| 956 | if (work.querySelector("[data-frame]")) { if (!box.value.trim()) window.location.reload(); return; } | |
| 957 | const mine = shell.querySelector(".talk-head"); | |
| 958 | if (head && mine && !mine.contains(document.activeElement)) mine.replaceWith(head); | |
| 959 | shell.append(work); | |
| 960 | shell.setAttribute("data-split", ""); | |
| 961 | } catch (_) {} | |
| 962 | } | |
| 963 | // A deploy that turns running swaps the frame into the waiting pane; one on another origin than the | |
| 964 | // page names in frame-src draws the page once instead, as a ready build does. | |
| 965 | document.addEventListener("forge:swapped", (e) => { | |
| 966 | if (e.target.id !== "talk-pane") return; | |
| 967 | const f = e.target.querySelector("[data-frame]"), shell = document.querySelector("[data-shell]"); | |
| 968 | if (f && shell && shell.dataset.frameOrigin !== new URL(f.src).origin && !answering) window.location.reload(); | |
| 969 | }); | |
| 925 | 970 | const reframe = () => document.querySelectorAll("[data-frame]").forEach((f) => { |
| 926 | 971 | const s = f.closest("[data-stage]"), n = s && s.querySelector("[data-stage-note]"); |
| 927 | 972 | if (n) { s.setAttribute("data-busy", ""); n.hidden = false; } |
src/web/pages/talk_preview.ts +46 −4
| @@ -13,7 +13,12 @@ | ||
| 13 | 13 | |
| 14 | 14 | import { workspaceOf, type Apps } from "../../actions/talk_workspace.ts"; |
| 15 | 15 | import type { User } from "../../core/users.ts"; |
| 16 | import type { Work } from "../../core/talk_work.ts"; | |
| 16 | import { paneCrew, type PaneCrew, type Work } from "../../core/talk_work.ts"; | |
| 17 | import { mayReadRunLog, mayReadRuns } from "../../actions/runs.ts"; | |
| 18 | import { getAppByRepo } from "../../core/apps.ts"; | |
| 19 | import { appsRuntime } from "../../apps/runtime.ts"; | |
| 20 | import { originOf } from "../../actions/talk_workspace.ts"; | |
| 21 | import { workLineHtml } from "../talk_peek.ts"; | |
| 17 | 22 | import type { Ctx } from "../../http/context.ts"; |
| 18 | 23 | import { html, raw, type Html } from "../html.ts"; |
| 19 | 24 | import { emptyLine } from "../empty_words.ts"; |
| @@ -27,6 +32,11 @@ export interface Pane { | ||
| 27 | 32 | readonly frame: string | undefined; |
| 28 | 33 | /** Something is running to frame: the page gives the pane its room only then. */ |
| 29 | 34 | readonly live: boolean; |
| 35 | /** | |
| 36 | * The crew is on the repository (a run queued or going): the pane opens to show it, and the page | |
| 37 | * names the app's production origin in `frame-src` ahead, so its first deploy swaps in. | |
| 38 | */ | |
| 39 | readonly crew: boolean; | |
| 30 | 40 | } |
| 31 | 41 | |
| 32 | 42 | export const VIEWS = ["preview", "code", "diff"] as const; |
| @@ -47,6 +57,7 @@ export async function talkPane(ctx: Ctx, user: User, name: string | undefined, w | ||
| 47 | 57 | const empty = (words: Html): Pane => ({ |
| 48 | 58 | frame: undefined, |
| 49 | 59 | live: false, |
| 60 | crew: false, | |
| 50 | 61 | html: html`<aside class="talk-pane" aria-label="Preview">${words}</aside>`, |
| 51 | 62 | }); |
| 52 | 63 | if (name === undefined) return empty(emptyLine("talkRepos")); |
| @@ -56,20 +67,27 @@ export async function talkPane(ctx: Ctx, user: User, name: string | undefined, w | ||
| 56 | 67 | const tab = (id: View, label: string): Html => html`<a href="?pane=${id}"${view === id ? raw(' aria-current="page"') : null}>${label}</a>`; |
| 57 | 68 | // Code and Diff are the forge's own browser and diff, read only when their tab is chosen. |
| 58 | 69 | const work = { repo: ws.repo, build: ask.build, pull: pull ?? ask.build?.pullNumber ?? undefined }; |
| 70 | // While nothing is framed, what the crew is doing on the repository, read from its newest run. | |
| 71 | const crew = view === "preview" && (url === undefined || ask.wait !== undefined) ? paneCrew(ctx.app.db, ctx.app.config.dataDir, ws.repo.id, user, { runs: mayReadRuns(ctx.app, user, ws.repo), logs: mayReadRunLog(ctx.app, user, ws.repo) }) : undefined; | |
| 72 | const going = crew !== undefined && (crew.state === "queued" || crew.state === "running"); | |
| 59 | 73 | const panel = |
| 60 | 74 | view === "code" |
| 61 | 75 | ? await codeView(ctx.app, work) |
| 62 | 76 | : view === "diff" |
| 63 | 77 | ? await diffView(ctx.app, work, ask.version) |
| 64 | 78 | : url === undefined || ask.wait !== undefined |
| 65 | ? html`<div class="talk-stage talk-stage-wait" data-stage${ask.busy === true ? raw(" data-busy") : null}><p class="talk-stage-note" data-stage-note>${ask.wait ?? ask.idle ?? "Nothing is running yet: the app appears here once it is built."}</p></div>${ask.build === undefined ? null : html`<h2 class="talk-stage-files small muted">The files it starts from</h2>${await codeView(ctx.app, work)}`}` | |
| 79 | ? html`<div class="talk-stage talk-stage-wait" data-stage${ask.busy === true ? raw(" data-busy") : null}><p class="talk-stage-note" data-stage-note>${ask.wait ?? ask.idle ?? "Nothing is running yet: the app appears here once it is built."}</p>${crew === undefined ? null : crewBlock(crew, `/${ws.repo.ownerName}/${ws.repo.name}`)}</div>${ask.build === undefined ? null : html`<h2 class="talk-stage-files small muted">The files it starts from</h2>${await codeView(ctx.app, work)}`}` | |
| 66 | 80 | : html`<div class="talk-stage" data-stage><iframe class="talk-frame" data-frame src="${url}" title="Live preview of ${name}" referrerpolicy="no-referrer" sandbox="allow-scripts allow-same-origin allow-forms allow-popups"></iframe><p class="talk-stage-note small" data-stage-note hidden>Updating the preview…</p></div>`; |
| 67 | 81 | // The address bar of what runs: which environment, where it lives, reload and open on its own. |
| 68 | 82 | const where = url === undefined ? null : html`<span class="talk-addr small" title="${url}"><span class="muted">${pull === undefined ? "Production" : `Pull #${String(pull)}`}</span> ${new URL(url).host}</span>`; |
| 83 | // Waiting, the pane is a live region on the repository's runs: a deploy that turns running swaps | |
| 84 | // the frame in, and the crew's next run is read as it is queued, starts or ends. | |
| 85 | const waiting = url === undefined && view === "preview"; | |
| 69 | 86 | return { |
| 70 | frame: ws.origin, | |
| 87 | frame: ws.origin ?? (going ? productionOrigin(ctx, ws.repo.id) : undefined), | |
| 71 | 88 | live: url !== undefined, |
| 72 | html: html`<aside class="talk-pane" aria-label="Preview of ${name}" data-pane-of="${name}"> | |
| 89 | crew: going, | |
| 90 | html: html`<aside class="talk-pane" id="talk-pane" aria-label="Preview of ${name}" data-pane-of="${name}"${waiting ? html` data-live="run.*" data-live-repo="${ws.repo.ownerName}/${ws.repo.name}" data-live-src="?pane=preview&fragment=pane"` : null}> | |
| 73 | 91 | <div class="talk-pane-bar"> |
| 74 | 92 | <nav class="seg" aria-label="Preview, code or diff">${tab("preview", "Preview")}${tab("code", "Code")}${tab("diff", "Diff")}</nav> |
| 75 | 93 | ${where} |
| @@ -81,6 +99,26 @@ export async function talkPane(ctx: Ctx, user: User, name: string | undefined, w | ||
| 81 | 99 | }; |
| 82 | 100 | } |
| 83 | 101 | |
| 102 | /** Where the app's production answers, as a bare origin: what `frame-src` names before its first deploy. */ | |
| 103 | function productionOrigin(ctx: Ctx, repoId: string): string | undefined { | |
| 104 | const record = getAppByRepo(ctx.app.db, repoId); | |
| 105 | const runtime = appsRuntime(ctx.app); | |
| 106 | return record === undefined || runtime === undefined ? undefined : originOf(runtime.urlFor(record, "production")); | |
| 107 | } | |
| 108 | ||
| 109 | /** | |
| 110 | * The crew's run in the wait stage: why it waits or that it works, its newest steps in plain words | |
| 111 | * (the script adds each new one as the run writes it; a log line is only ever text here), and the | |
| 112 | * run's own page, which is the whole of it without the script. | |
| 113 | */ | |
| 114 | function crewBlock(crew: PaneCrew, base: string): Html { | |
| 115 | return html`<div class="talk-crew-now"> | |
| 116 | <p class="small">${workLineHtml(crew.line)}</p> | |
| 117 | ${!crew.tail || (crew.steps.length === 0 && crew.state !== "running") ? null : html`<div class="talk-crew-steps small muted" data-crew-steps="${crew.runId}" aria-live="polite">${crew.steps.map((step) => html`<p>${step}</p>`)}</div>`} | |
| 118 | <a class="small" href="${base}/runs/${crew.runId}">See the whole run</a> | |
| 119 | </div>`; | |
| 120 | } | |
| 121 | ||
| 84 | 122 | /** |
| 85 | 123 | * The pane's own styles, sent only on a page that draws one (`data-split`). Spacing is the scale. |
| 86 | 124 | */ |
| @@ -96,6 +134,10 @@ export const paneCss = /* css */ ` | ||
| 96 | 134 | .talk-stage-wait .talk-stage-note { position: static; padding: 0; text-align: start; } |
| 97 | 135 | .talk-stage-files { margin: 16px 0 8px; font-size: 12.5px; font-weight: 600; } |
| 98 | 136 | .talk-stage-note[hidden] { display: none; } |
| 137 | .talk-crew-now { display: grid; gap: 8px; justify-items: start; margin-top: 12px; } | |
outdated
Principles 3 and 7, and unusable on a phone: absolute positioning at 58% inside a content-sized |
||
| 138 | .talk-crew-now p { margin: 0; } | |
| 139 | .talk-crew-steps { display: grid; gap: 2px; overflow-wrap: anywhere; } | |
| 140 | .talk-crew-steps p { margin: 0; } | |
| 99 | 141 | (max-width: 30rem) { .talk-addr { display: none; } } |
| 100 | 142 | (prefers-reduced-motion: reduce) { .talk-frame { transition: none; } } |
| 101 | 143 | `; |
test/talk-live-pane.test.ts added +290
| @@ -0,0 +1,290 @@ | ||
| 1 | /** | |
| 2 | * The live pane (#15734): while the crew is on the conversation's repository, the pane's wait stage | |
| 3 | * shows its newest run in plain words: why it waits (the hold sentence), or its newest steps as it | |
| 4 | * writes them, or how it ended; the run's own page is the link that holds it all without the script. | |
| 5 | * A log line is the builder's shell's untrusted text: it is only ever drawn as text. The pane opens | |
| 6 | * by itself once the crew is on the repository (a new app has no call naming it, only its receipt), | |
| 7 | * and the terminal's pane tails the same run. | |
| 8 | */ | |
| 9 | import { afterAll, beforeAll, describe, expect, test } from "bun:test"; | |
| 10 | import { mkdtemp, rm } from "node:fs/promises"; | |
| 11 | import { tmpdir } from "node:os"; | |
| 12 | import { join } from "node:path"; | |
| 13 | import { createRepo } from "../src/actions/repos.ts"; | |
| 14 | import { createApp, type App } from "../src/app.ts"; | |
| 15 | import { appendTurn, createConversation } from "../src/core/conversations.ts"; | |
| 16 | import { createRun } from "../src/core/runs.ts"; | |
| 17 | import { createSession } from "../src/core/sessions.ts"; | |
| 18 | import { repoOf } from "../src/core/talk_steps.ts"; | |
| 19 | import { paneCrew, plainStep } from "../src/core/talk_work.ts"; | |
| 20 | import { createUser, type User } from "../src/core/users.ts"; | |
| 21 | import { receiptOf } from "../src/crew/receipt.ts"; | |
| 22 | import type { Ctx } from "../src/http/context.ts"; | |
| 23 | import { serve, type Servers } from "../src/http/server.ts"; | |
| 24 | import { appendRunLog, flushRunLogs } from "../src/runs/log.ts"; | |
| 25 | import { createForgeApp } from "../src/tui/forge.ts"; | |
| 26 | import { headlessTerminal } from "../src/tui/term/terminal.ts"; | |
| 27 | import { talkPane } from "../src/web/pages/talk_preview.ts"; | |
| 28 | import { promote } from "./helpers/members.ts"; | |
| 29 | import { settleApp } from "./helpers/tui.ts"; | |
| 30 | ||
| 31 | test("a log line in plain words: what it read or changed, a search, the checks, a commit, a push, the end; nothing else", () => { | |
| 32 | const table: [string, string | undefined][] = [ | |
| 33 | ["→ Read src/app.ts", "Read src/app.ts"], | |
| 34 | ["→ Edit src/app.ts", "Changed src/app.ts"], | |
| 35 | ["→ Write public/index.html", "Changed public/index.html"], | |
| 36 | ["→ Grep TODO", "Searched the code"], | |
| 37 | ["→ Bash bun test test/app.test.ts", "Ran the checks"], | |
| 38 | ["→ Bash git commit -m first", "Committed"], | |
| 39 | ["→ Bash git push origin crew/arena", "Pushed its work"], | |
| 40 | ["→ Bash ls -la", "Ran a command"], | |
| 41 | ["→ TodoWrite", undefined], | |
| 42 | [ | |
| 43 | "done: pushed crew/arena, opened #2", | |
| 44 | "Done: pushed crew/arena, opened #2", | |
| 45 | ], | |
| 46 | ["cloning trevato/tiny-arena", "Started on a fresh copy of the repository"], | |
| 47 | ["I will now make the arena.", undefined], | |
| 48 | ["subscription: main", undefined], | |
| 49 | ]; | |
| 50 | for (const [line, plain] of table) | |
| 51 | expect([line, plainStep(line)]).toEqual([line, plain]); | |
| 52 | }); | |
| 53 | ||
| 54 | describe("the pane, by the crew's newest run on the repository", () => { | |
| 55 | let dir: string; | |
| 56 | let app: App; | |
| 57 | let servers: Servers; | |
| 58 | let alice: User; | |
| 59 | let ctx: Ctx; | |
| 60 | let n = 0; | |
| 61 | let bob: User; | |
| 62 | beforeAll(async () => { | |
| 63 | dir = await mkdtemp(join(tmpdir(), "forge-talk-live-pane-")); | |
| 64 | app = createApp({ dataDir: dir, port: 0 }); | |
| 65 | servers = await serve(app); | |
| 66 | const made = await createUser(app.db, { | |
| 67 | origin: "seed", | |
| 68 | trusted: true, | |
| 69 | username: "alice", | |
| 70 | email: "[email protected]", | |
| 71 | password: "a-good-passphrase", | |
| 72 | adminIfFirst: true, | |
| 73 | }); | |
| 74 | if (!made.ok) throw new Error(made.error); | |
| 75 | promote(app.db, made.value); | |
| 76 | alice = made.value; | |
| 77 | const other = await createUser(app.db, { origin: "seed", trusted: true, username: "bob", email: "[email protected]", password: "a-good-passphrase" }); | |
| 78 | if (!other.ok) throw new Error(other.error); | |
| 79 | promote(app.db, other.value); | |
| 80 | bob = other.value; | |
| 81 | ctx = { app } as Ctx; | |
| 82 | }); | |
| 83 | afterAll(async () => { | |
| 84 | servers.stop(); | |
| 85 | app.close(); | |
| 86 | await rm(dir, { recursive: true, force: true }); | |
| 87 | }); | |
| 88 | /** A fresh repository with one crew run in `state`, its log the given lines. */ | |
| 89 | const withRun = async ( | |
| 90 | state: "queued" | "running" | "ok" | "failed", | |
| 91 | lines: readonly string[] = [], | |
| 92 | ) => { | |
| 93 | n += 1; | |
| 94 | const repo = await createRepo(app, alice, { | |
| 95 | name: `arena${String(n)}`, | |
| 96 | visibility: "public", | |
| 97 | }); | |
| 98 | if (!repo.ok) throw new Error(String(repo.error)); | |
| 99 | const run = createRun(app.db, { | |
| 100 | repoId: repo.value.id, | |
| 101 | kind: "agent", | |
| 102 | reason: "assigned", | |
| 103 | }); | |
| 104 | if (state !== "queued") | |
| 105 | app.db.run("UPDATE run SET state = ?1 WHERE id = ?2", [state, run.id]); | |
| 106 | for (const line of lines) appendRunLog(dir, run.id, line); | |
| 107 | flushRunLogs(); | |
| 108 | return { repo: repo.value, run, name: `alice/${repo.value.name}` }; | |
| 109 | }; | |
| 110 | const pane = (name: string) => | |
| 111 | talkPane(ctx, alice, name, new Map(), "preview"); | |
| 112 | ||
| 113 | test("no run: the wait stage as it was, and the pane does not open for it", async () => { | |
| 114 | n += 1; | |
| 115 | const repo = await createRepo(app, alice, { | |
| 116 | name: `quiet${String(n)}`, | |
| 117 | visibility: "public", | |
| 118 | }); | |
| 119 | if (!repo.ok) throw new Error(String(repo.error)); | |
| 120 | expect(paneCrew(app.db, dir, repo.value.id, alice, { runs: true, logs: true })).toBeUndefined(); | |
| 121 | const p = await pane(`alice/${repo.value.name}`); | |
| 122 | expect(p.html.text).not.toContain("talk-crew-now"); | |
| 123 | expect(p.crew).toBe(false); | |
| 124 | }); | |
| 125 | ||
| 126 | test("queued with a hold: the hold sentence and its control; the pane opens and listens on the repository's runs", async () => { | |
| 127 | const { run, name } = await withRun("queued", [ | |
| 128 | "queued, not started: 92% of the week used, the crew may use up to 90%; it waits for the reset 2026-11-29 02:00 UTC.", | |
| 129 | ]); | |
| 130 | const p = await pane(name); | |
| 131 | expect(p.crew).toBe(true); | |
| 132 | const flat = p.html.text.replace(/\s+/g, " "); | |
| 133 | expect(flat).toContain( | |
| 134 | 'Waits for the reset, Sun 29 Nov, 02:00 UTC: the crew has used 92% of this week and may use 90%. <a href="/settings/crew#knob-budget">Change the limit</a>', | |
| 135 | ); | |
| 136 | expect(flat).toContain( | |
| 137 | `href="/${name}/runs/${run.id}">See the whole run</a>`, | |
| 138 | ); | |
| 139 | expect(flat).toContain(`id="talk-pane"`); | |
| 140 | expect(flat).toContain( | |
| 141 | `data-live="run.*" data-live-repo="${name}" data-live-src="?pane=preview&fragment=pane"`, | |
| 142 | ); | |
| 143 | }); | |
| 144 | ||
| 145 | test("queued with no hold logged: it says it waits for a builder", async () => { | |
| 146 | const { name } = await withRun("queued"); | |
| 147 | expect((await pane(name)).html.text).toContain( | |
| 148 | "Queued for the crew: it starts when a builder is free.", | |
| 149 | ); | |
| 150 | }); | |
| 151 | ||
| 152 | test("running: its newest steps in plain words, as text only, with the run's id for the live tail", async () => { | |
| 153 | const lines = [ | |
| 154 | "cloning alice/arena", | |
| 155 | "→ Read src/a.ts", | |
| 156 | "thinking aloud", | |
| 157 | ...Array.from({ length: 8 }, (_, i) => `→ Edit src/f${String(i)}.ts`), | |
| 158 | "→ Read <img src=x onerror=alert(1)>", | |
| 159 | ]; | |
| 160 | const { run, name } = await withRun("running", lines); | |
| 161 | const now = paneCrew( | |
| 162 | app.db, | |
| 163 | dir, | |
| 164 | (await import("../src/core/repos.ts")).getRepo( | |
| 165 | app.db, | |
| 166 | "alice", | |
| 167 | name.split("/")[1]!, | |
| 168 | )!.id, | |
| 169 | alice, | |
| 170 | { runs: true, logs: true }, | |
| 171 | )!; | |
| 172 | expect(now.state).toBe("running"); | |
| 173 | expect(now.steps).toHaveLength(6); | |
| 174 | expect(now.steps.at(-1)).toBe("Read <img src=x onerror=alert(1)>"); | |
| 175 | const html = (await pane(name)).html.text; | |
| 176 | expect(html).toContain("The crew is building it now."); | |
| 177 | expect(html).toContain(`data-crew-steps="${run.id}"`); | |
| 178 | expect(html).toContain("<p>Changed src/f7.ts</p>"); | |
| 179 | expect(html).toContain("<p>Read <img src=x onerror=alert(1)></p>"); | |
| 180 | expect(html).not.toContain("<img src=x"); | |
| 181 | }); | |
| 182 | ||
| 183 | test("finished and failed: how it ended, its last steps, and the run; the pane no longer opens for it", async () => { | |
| 184 | const ok = await withRun("ok", ["→ Bash git push origin crew/a"]); | |
| 185 | const done = await pane(ok.name); | |
| 186 | expect(done.html.text).toContain("The crew finished this run."); | |
| 187 | expect(done.html.text).toContain("<p>Pushed its work</p>"); | |
| 188 | expect(done.crew).toBe(false); | |
| 189 | const failed = await withRun("failed"); | |
| 190 | const ended = await pane(failed.name); | |
| 191 | expect(ended.html.text.replace(/&#(?:39|x27);/g, "'")).toContain("The crew's run did not finish."); | |
| 192 | expect(ended.html.text).toContain( | |
| 193 | `href="/${failed.name}/runs/${failed.run.id}"`, | |
| 194 | ); | |
| 195 | expect(ended.html.text).not.toContain("data-crew-steps"); | |
| 196 | }); | |
| 197 | ||
| 198 | test("a reader who may see the runs but not read their logs gets how it stands and the run, never a step; one who may not read the repository gets nothing", async () => { | |
| 199 | const { run, name } = await withRun("running", ["\u2192 Read src/secret-plan.ts"]); | |
| 200 | const { mayReadRunLog, mayReadRuns } = await import("../src/actions/runs.ts"); | |
| 201 | const repo = (await import("../src/core/repos.ts")).getRepo(app.db, "alice", name.split("/")[1]!)!; | |
| 202 | expect([mayReadRuns(app, bob, repo), mayReadRunLog(app, bob, repo)]).toEqual([true, false]); | |
| 203 | const theirs = (await talkPane(ctx, bob, name, new Map(), "preview")).html.text; | |
| 204 | expect(theirs).toContain("The crew is building it now."); | |
| 205 | expect(theirs).toContain(`href="/${name}/runs/${run.id}"`); | |
| 206 | expect(theirs).not.toContain("secret-plan"); | |
| 207 | expect(theirs).not.toContain("data-crew-steps"); | |
| 208 | // A private repository: no pane for who may not read it, so nothing of its run either. | |
| 209 | const hidden = await createRepo(app, alice, { name: `vault${String(++n)}`, visibility: "private" }); | |
| 210 | if (!hidden.ok) throw new Error(String(hidden.error)); | |
| 211 | const vaultRun = createRun(app.db, { repoId: hidden.value.id, kind: "agent", reason: "assigned" }); | |
| 212 | appendRunLog(dir, vaultRun.id, "\u2192 Read src/vault.ts"); | |
| 213 | flushRunLogs(); | |
| 214 | const none = (await talkPane(ctx, bob, `alice/${hidden.value.name}`, new Map(), "preview")).html.text; | |
| 215 | expect(none).not.toContain("talk-crew-now"); | |
| 216 | expect(none).not.toContain("vault.ts"); | |
| 217 | }); | |
| 218 | ||
| 219 | test("the page opens the pane once the crew is on the repository a new app's receipt names", async () => { | |
| 220 | const { repo, name } = await withRun("queued"); | |
| 221 | const chat = createConversation(app.db, alice.id); | |
| 222 | if (!chat.ok) throw new Error(chat.error); | |
| 223 | appendTurn(app.db, alice.id, chat.value.id, { | |
| 224 | role: "person", | |
| 225 | text: "build me an arena", | |
| 226 | }); | |
| 227 | // new_app names its repository only in the forge's answer: its receipt says it. | |
| 228 | const receipt = receiptOf( | |
| 229 | "new_app", | |
| 230 | { name: repo.name }, | |
| 231 | { repo: name }, | |
| 232 | undefined, | |
| 233 | ); | |
| 234 | expect(receipt).toEqual({ | |
| 235 | verb: "New app", | |
| 236 | object: name, | |
| 237 | href: `/${name}`, | |
| 238 | }); | |
| 239 | appendTurn(app.db, alice.id, chat.value.id, { | |
| 240 | role: "tool", | |
| 241 | text: JSON.stringify({ done: true, receipt }), | |
| 242 | }); | |
| 243 | expect( | |
| 244 | repoOf([{ role: "tool", text: JSON.stringify({ done: true, receipt }) }]), | |
| 245 | ).toBe(name); | |
| 246 | const page = await ( | |
| 247 | await fetch(`${servers.url}/talk/${chat.value.id}`, { | |
| 248 | headers: { | |
| 249 | cookie: `forge_session=${createSession(app.db, alice.id).token}`, | |
| 250 | }, | |
| 251 | }) | |
| 252 | ).text(); | |
| 253 | expect(page).toContain("data-split"); | |
| 254 | expect(page).toContain("talk-crew-now"); | |
| 255 | }); | |
| 256 | ||
| 257 | test("the terminal's pane says the same and names the whole run", async () => { | |
| 258 | const { run, name } = await withRun("running", [ | |
| 259 | "→ Read src/a.ts", | |
| 260 | "→ Bash git push", | |
| 261 | ]); | |
| 262 | const chat = createConversation(app.db, alice.id); | |
| 263 | if (!chat.ok) throw new Error(chat.error); | |
| 264 | appendTurn(app.db, alice.id, chat.value.id, { | |
| 265 | role: "tool", | |
| 266 | text: `mcp__forge__read_file ${JSON.stringify({ repo: name, path: "a" })}`, | |
| 267 | }); | |
| 268 | const terminal = headlessTerminal(120, 30); | |
| 269 | const { app: tui } = createForgeApp( | |
| 270 | app, | |
| 271 | { | |
| 272 | sshUsername: "alice", | |
| 273 | remoteAddress: "127.0.0.1", | |
| 274 | fingerprint: "SHA256:test", | |
| 275 | user: alice, | |
| 276 | }, | |
| 277 | { terminal, exitHooks: false }, | |
| 278 | ); | |
| 279 | tui.start(); | |
| 280 | for (const k of [":", "Conversations", "\r", "\r", "p"]) { | |
| 281 | terminal.feed(k); | |
| 282 | await settleApp(tui); | |
| 283 | } | |
| 284 | const text = tui.screen.toText(); | |
| 285 | expect(text).toContain("Crew: The crew is building it now."); | |
| 286 | expect(text).toContain(" Read src/a.ts"); | |
| 287 | expect(text).toContain(" Pushed its work"); | |
| 288 | expect(text).toContain(`The whole run: /${name}/runs/${run.id}`); | |
| 289 | }); | |
| 290 | }); |
test/talk-page.test.ts +40 −3
| @@ -453,7 +453,7 @@ describe("the page", () => { | ||
| 453 | 453 | test("the page's own bytes are held: stylesheet and script stay small", async () => { |
| 454 | 454 | const { talkCss, talkJs } = await import("../src/web/pages/talk_client.ts"); |
| 455 | 455 | expect(Buffer.byteLength(talkCss)).toBeLessThan(18_000); |
| 456 | expect(Buffer.byteLength(talkJs)).toBeLessThan(43_500); | |
| 456 | expect(Buffer.byteLength(talkJs)).toBeLessThan(47_300); | |
| 457 | 457 | // A page of its own, so what other tests said to alice never counts: one question and a code reply. |
| 458 | 458 | const sizer = await createUser(app.db, { origin: "seed", trusted: true, username: "sizer", email: "[email protected]", password: "a-good-passphrase" }); |
| 459 | 459 | if (!sizer.ok) throw new Error(sizer.error); |
| @@ -468,7 +468,7 @@ describe("the page", () => { | ||
| 468 | 468 | // Talk page, because a chart can arrive in a live reply, and a page drawn without them would |
| 469 | 469 | // show it unstyled until a reload. 48,328 measured. Then to 50,000 by the reply's one last line |
| 470 | 470 | // and the pane's first-version words: 49,466 measured. |
| 471 | expect(size).toBeLessThan(50_000); | |
| 471 | expect(size).toBeLessThan(52_000); | |
| 472 | 472 | }); |
| 473 | 473 | |
| 474 | 474 | describe("the script, driven against a DOM", () => { |
| @@ -574,7 +574,7 @@ describe("the page", () => { | ||
| 574 | 574 | const bodies: { files?: string[] }[] = []; |
| 575 | 575 | const fetchStub = async (u: string, init: { body: string; method?: string }) => { |
| 576 | 576 | urls.push(u); |
| 577 | if (u.startsWith("?pane=") || u === "/talk" || u.endsWith("?fragment=build")) return { ok: true, text: async () => page.html }; | |
| 577 | if (u.startsWith("?pane=") || u === "/talk" || u === "http://localhost/talk" || u.endsWith("?fragment=build")) return { ok: true, text: async () => page.html }; | |
| 578 | 578 | if (u.endsWith("?fragment=1")) return { ok: true, text: async () => '<div class="blob">const a = 2;</div>' }; |
| 579 | 579 | if (u.endsWith("?fragment=explorer")) return { ok: true, text: async () => '<ul><li><a class="ex-file" data-ex-file tabindex="-1" title="src/a.ts" href="/erin/site/blob/b/src/a.ts">a.ts</a></li></ul>' }; |
| 580 | 580 | if (u.includes("/confirm/")) { sent.push("answer:" + u + ":" + String(init.body)); return { ok: answer.status === 200, status: answer.status, json: async () => (answer.status === 200 ? { ok: true } : { ok: false, message: "this confirm was already answered; it does nothing twice" }) }; } |
| @@ -1185,6 +1185,43 @@ describe("the page", () => { | ||
| 1185 | 1185 | expect([!!t.doc.querySelector(".talk-display > form"), !!t.doc.querySelector("dialog.talk-display-sheet")]).toEqual([true, false]); |
| 1186 | 1186 | }); |
| 1187 | 1187 | |
| 1188 | test("the waiting pane tails the crew's run in plain words, as text only, the newest six; a reply that opens the pane swaps it in, and draws the page only for a frame", async () => { | |
| 1189 | const t = await boot(); | |
| 1190 | t.doc.body.insertAdjacentHTML("beforeend", '<aside id="talk-pane"><div data-crew-steps="r1"></div></aside>'); | |
| 1191 | const steps = t.doc.querySelector("[data-crew-steps]"); | |
| 1192 | const tail = (run: string, lines: string[]) => t.doc.dispatchEvent(new t.window.CustomEvent("forge:run-log", { detail: { run, lines } })); | |
| 1193 | tail("r1", ["\u2192 Read a.ts", "a thought", "\u2192 Bash git push origin x", "\u2192 Read <img src=x onerror=alert(1)>"]); | |
| 1194 | tail("r2", ["\u2192 Read other.ts"]); | |
| 1195 | expect([...steps.children].map((li: any) => li.textContent)).toEqual(["Read a.ts", "Pushed its work", "Read <img src=x onerror=alert(1)>"]); | |
| 1196 | expect(steps.querySelector("img")).toBeNull(); | |
| 1197 | tail("r1", Array.from({ length: 8 }, (_, i) => "\u2192 Edit f" + String(i) + ".ts")); | |
| 1198 | expect([...steps.children].map((li: any) => li.textContent)).toEqual(["Changed f2.ts", "Changed f3.ts", "Changed f4.ts", "Changed f5.ts", "Changed f6.ts", "Changed f7.ts"]); | |
| 1199 | // The same words as the server's: the script runs core's own function. | |
| 1200 | const { plainStep } = await import("../src/core/talk_work.ts"); | |
| 1201 | expect(steps.lastElementChild.textContent).toBe(plainStep("\u2192 Edit f7.ts")); | |
| 1202 | // A reply that set the crew on an app, on a page with no pane yet, opens it in place: the page is | |
| 1203 | // read again and its head and its waiting pane are swapped in, with no reload. | |
| 1204 | let reloads = 0; | |
| 1205 | Object.defineProperty(t.window.location, "reload", { value: () => { reloads += 1; }, configurable: true }); | |
| 1206 | t.doc.body.insertAdjacentHTML("beforeend", '<div data-shell><header class="talk-head">old</header></div>'); | |
| 1207 | t.page.html = '<div data-shell data-split><header class="talk-head">tabs</header><div class="talk-work"><aside class="talk-pane" id="talk-pane"><div class="talk-crew-now">Queued for the crew</div></aside></div></div>'; | |
| 1208 | t.sources.at(-1)!.on["done"]!({ data: JSON.stringify({ pane: true, costs: [] }) }); | |
| 1209 | await tick(); | |
| 1210 | await tick(); | |
| 1211 | const shell = t.doc.querySelector("body > [data-shell]"); | |
| 1212 | expect([reloads, shell.hasAttribute("data-split"), shell.querySelector(".talk-head").textContent, !!shell.querySelector(".talk-work #talk-pane .talk-crew-now")]).toEqual([0, true, "tabs", true]); | |
| 1213 | // A pane that already frames the app draws the page once: its origin must join frame-src. | |
| 1214 | const u = await boot(); | |
| 1215 | let redraws = 0; | |
| 1216 | Object.defineProperty(u.window.location, "reload", { value: () => { redraws += 1; }, configurable: true }); | |
| 1217 | u.doc.body.insertAdjacentHTML("beforeend", '<div data-shell><header class="talk-head">old</header></div>'); | |
| 1218 | u.page.html = '<div data-shell data-split><div class="talk-work"><aside class="talk-pane"><iframe data-frame src="http://app.test/"></iframe></aside></div></div>'; | |
| 1219 | u.sources.at(-1)!.on["done"]!({ data: JSON.stringify({ pane: true, costs: [] }) }); | |
| 1220 | await tick(); | |
| 1221 | await tick(); | |
| 1222 | expect([redraws, u.doc.querySelector("body > [data-shell]").hasAttribute("data-split")]).toEqual([1, false]); | |
| 1223 | }); | |
| 1224 | ||
| 1188 | 1225 | test("a code block in a streamed turn gets its Copy button too", async () => { |
| 1189 | 1226 | const t = await boot(); |
| 1190 | 1227 | 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/talk-receipt-follow.test.ts added +175
| @@ -0,0 +1,175 @@ | ||
| 1 | /** | |
| 2 | * A new app's receipt follows its build (#15734): the receipt `new_app` leaves names the issue its | |
| 3 | * first build is on, so its live work line goes waiting, working, pushed, landed, the way the | |
| 4 | * owner's own tip-calculator did on production, and still says "landed" once the pull has closed the | |
| 5 | * issue. The agent says the line follows the build, not a moment's state. | |
| 6 | */ | |
| 7 | import { afterAll, beforeAll, expect, test } from "bun:test"; | |
| 8 | import { mkdtemp, rm } from "node:fs/promises"; | |
| 9 | import { tmpdir } from "node:os"; | |
| 10 | import { join } from "node:path"; | |
| 11 | import { createRepo } from "../src/actions/repos.ts"; | |
| 12 | import { createApp, type App } from "../src/app.ts"; | |
| 13 | import { appendTurn, createConversation } from "../src/core/conversations.ts"; | |
| 14 | import { | |
| 15 | createIssue, | |
| 16 | getIssue, | |
| 17 | setIssueState, | |
| 18 | type Issue, | |
| 19 | } from "../src/core/issues.ts"; | |
| 20 | import { claimRun, createRun } from "../src/core/runs.ts"; | |
| 21 | import { createSession } from "../src/core/sessions.ts"; | |
| 22 | import { liveReceipts } from "../src/core/talk_work.ts"; | |
| 23 | import { createUser, type User } from "../src/core/users.ts"; | |
| 24 | import { conversationBrief } from "../src/crew/conversation_brief.ts"; | |
| 25 | import { receiptOf } from "../src/crew/receipt.ts"; | |
| 26 | import { filedTurns } from "../src/crew/filed.ts"; | |
| 27 | import { completeWrite, recordWrite } from "../src/core/conversation_writes.ts"; | |
| 28 | import { serve, type Servers } from "../src/http/server.ts"; | |
| 29 | import { promote } from "./helpers/members.ts"; | |
| 30 | ||
| 31 | let dir: string; | |
| 32 | let app: App; | |
| 33 | let servers: Servers; | |
| 34 | let alice: User; | |
| 35 | let issue: Issue; | |
| 36 | let repoId: string; | |
| 37 | ||
| 38 | beforeAll(async () => { | |
| 39 | dir = await mkdtemp(join(tmpdir(), "forge-receipt-follow-")); | |
| 40 | app = createApp({ dataDir: dir, port: 0 }); | |
| 41 | servers = await serve(app); | |
| 42 | const made = await createUser(app.db, { | |
| 43 | origin: "seed", | |
| 44 | trusted: true, | |
| 45 | username: "alice", | |
| 46 | email: "[email protected]", | |
| 47 | password: "a-good-passphrase", | |
| 48 | adminIfFirst: true, | |
| 49 | }); | |
| 50 | if (!made.ok) throw new Error(made.error); | |
| 51 | promote(app.db, made.value); | |
| 52 | alice = made.value; | |
| 53 | const repo = await createRepo(app, alice, { | |
| 54 | name: "tip-calculator", | |
| 55 | visibility: "public", | |
| 56 | }); | |
| 57 | if (!repo.ok) throw new Error(String(repo.error)); | |
| 58 | repoId = repo.value.id; | |
| 59 | const filed = createIssue(app.db, { | |
| 60 | repoId, | |
| 61 | authorId: alice.id, | |
| 62 | title: "Build a tip calculator", | |
| 63 | body: "b", | |
| 64 | }); | |
| 65 | if (!filed.ok) throw new Error("issue"); | |
| 66 | issue = filed.value; | |
| 67 | }); | |
| 68 | afterAll(async () => { | |
| 69 | servers.stop(); | |
| 70 | app.close(); | |
| 71 | await rm(dir, { recursive: true, force: true }); | |
| 72 | }); | |
| 73 | ||
| 74 | test("new_app's receipt names the issue its first build is on", () => { | |
| 75 | expect( | |
| 76 | receiptOf( | |
| 77 | "new_app", | |
| 78 | { name: "tip-calculator" }, | |
| 79 | { repo: "alice/tip-calculator", issue: 1 }, | |
| 80 | undefined, | |
| 81 | ), | |
| 82 | ).toEqual({ | |
| 83 | verb: "New app", | |
| 84 | object: "alice/tip-calculator", | |
| 85 | href: "/alice/tip-calculator/issues/1", | |
| 86 | }); | |
| 87 | // With no issue in the answer it names the repository, as before. | |
| 88 | expect( | |
| 89 | receiptOf("new_app", { name: "x" }, { repo: "alice/x" }, undefined)?.href, | |
| 90 | ).toBe("/alice/x"); | |
| 91 | }); | |
| 92 | ||
| 93 | test("its live line walks the build: waiting, working, pushed with checks running, landed, and still landed once the issue is closed", async () => { | |
| 94 | const chat = createConversation(app.db, alice.id); | |
| 95 | if (!chat.ok) throw new Error(chat.error); | |
| 96 | // What the turn stores when new_app ran straight through /mcp for this conversation (no hold): the | |
| 97 | // write and its answer, read back at the turn's end into a receipt turn (`crew/filed.ts`). | |
| 98 | const via = `conversation:${chat.value.id}`; | |
| 99 | const wrote = recordWrite(app.db, via, "new_app", { name: "tip-calculator", sentence: "a tip calculator" }); | |
| 100 | completeWrite(app.db, wrote, JSON.stringify({ repo: "alice/tip-calculator", url: null, issue: issue.number, agent: "builder", run: "queued" })); | |
| 101 | const stored = filedTurns(app.db, via, "build me a tip calculator", true); | |
| 102 | expect(stored).toHaveLength(1); | |
| 103 | const text = stored[0]!; | |
| 104 | expect(JSON.parse(text)).toMatchObject({ filed: true, done: true, receipt: { verb: "New app", object: "alice/tip-calculator", href: `/alice/tip-calculator/issues/${String(issue.number)}` } }); | |
| 105 | appendTurn(app.db, alice.id, chat.value.id, { role: "person", text: "build me a tip calculator" }); | |
| 106 | const turn = appendTurn(app.db, alice.id, chat.value.id, { | |
| 107 | role: "tool", | |
| 108 | text, | |
| 109 | }); | |
| 110 | if (!turn.ok) throw new Error(String(turn.error)); | |
| 111 | const line = () => | |
| 112 | liveReceipts(app.db, dir, alice, [ | |
| 113 | { | |
| 114 | id: turn.value.id, | |
| 115 | role: "tool", | |
| 116 | text, | |
| 117 | }, | |
| 118 | ]).get(turn.value.id)?.line.says; | |
| 119 | const run = createRun(app.db, { | |
| 120 | repoId, | |
| 121 | kind: "agent", | |
| 122 | issueId: issue.id, | |
| 123 | reason: "assigned", | |
| 124 | branch: "crew/tip", | |
| 125 | }); | |
| 126 | expect(line()).toBe("Queued for the crew."); | |
| 127 | claimRun(app.db, run.id); | |
| 128 | expect(line()).toMatch(/^The crew has been working on it( for \d+ min)?\.$/); | |
| 129 | const pull = createIssue(app.db, { | |
| 130 | repoId, | |
| 131 | authorId: alice.id, | |
| 132 | title: "Tip calculator", | |
| 133 | body: "Closes #1", | |
| 134 | kind: "pull", | |
| 135 | }); | |
| 136 | if (!pull.ok) throw new Error("pull"); | |
| 137 | app.db.run( | |
| 138 | "INSERT INTO pull (issue_id, base_branch, head_branch, base_oid, head_oid) VALUES (?1, 'main', 'crew/tip', '', '')", | |
| 139 | [pull.value.id], | |
| 140 | ); | |
| 141 | expect(line()).toBe( | |
| 142 | `The crew pushed #${String(pull.value.number)}: checks running.`, | |
| 143 | ); | |
| 144 | app.db.run("UPDATE pull SET merged_at = ?1 WHERE issue_id = ?2", [ | |
| 145 | new Date().toISOString(), | |
| 146 | pull.value.id, | |
| 147 | ]); | |
| 148 | app.db.run("UPDATE run SET state = 'ok' WHERE id = ?1", [run.id]); | |
| 149 | setIssueState(app.db, issue.id, "closed"); | |
| 150 | expect(getIssue(app.db, repoId, issue.number)?.state).toBe("closed"); | |
| 151 | expect(line()).toBe(`The crew landed #${String(pull.value.number)}.`); | |
| 152 | // The page draws it as a live line, read again as runs and pulls move. | |
| 153 | const page = await ( | |
| 154 | await fetch(`${servers.url}/talk/${chat.value.id}`, { | |
| 155 | headers: { | |
| 156 | cookie: `forge_session=${createSession(app.db, alice.id).token}`, | |
| 157 | }, | |
| 158 | }) | |
| 159 | ).text(); | |
| 160 | expect(page).toContain(`id="w-${turn.value.id}"`); | |
| 161 | expect(page).toContain(`The crew landed #${String(pull.value.number)}.`); | |
| 162 | }); | |
| 163 | ||
| 164 | test("the brief: the line under the receipt follows the build; never a moment's queued, never a pull for them to land", () => { | |
| 165 | const brief = conversationBrief([]); | |
| 166 | expect(brief).toContain( | |
| 167 | "say that the line under the receipt follows the build as it goes", | |
| 168 | ); | |
| 169 | expect(brief).toContain( | |
| 170 | "never a moment's state such as that it is queued and not built yet", | |
| 171 | ); | |
| 172 | expect(brief).toContain( | |
| 173 | "never that a pull request will appear for them to land", | |
| 174 | ); | |
| 175 | }); |
test/talk-receipt-live.test.ts +5 −3
| @@ -134,9 +134,11 @@ test("the work line follows the run: nobody, queued, working for how long, the p | ||
| 134 | 134 | ) |
| 135 | 135 | .run(pull.value.id); |
| 136 | 136 | expect(workLine(app.db, issue, Date.now())).toBe("The crew landed #2."); |
| 137 | expect(workLine(app.db, { ...issue, state: "closed" }, Date.now())).toBe( | |
| 138 | "Done: it is closed.", | |
| 139 | ); | |
| 137 | // Landed and closed by its pull, the line says it landed; closed with nothing landed, done. | |
| 138 | expect(workLine(app.db, { ...issue, state: "closed" }, Date.now())).toBe("The crew landed #2."); | |
| 139 | app.db.run("UPDATE pull SET merged_at = NULL WHERE issue_id = ?1", [pull.value.id]); | |
| 140 | expect(workLine(app.db, { ...issue, state: "closed" }, Date.now())).toBe("Done: it is closed."); | |
| 141 | app.db.run("UPDATE pull SET merged_at = '2026-01-01T00:00:00Z' WHERE issue_id = ?1", [pull.value.id]); | |
| 140 | 142 | }); |
| 141 | 143 | |
| 142 | 144 | test("the work line's other ends: checks failed, a run that did not finish, one that finished, assigned with no run", () => { |
new above
offline
A full page reload when the reply opens the pane drops the reader's scroll and the typed state of the page. Swap the pane in place, or say why the
frame-srcchange forces a reload.