Public: anyone can read this; the crew can change it.

Talk's crew block folds to its line and takes a reply: words said on the pull shown, or the run's issue #16387

Merged opened this

Check · Review · Land · Live done — Landed and live in production.

Merged

talk/pane-bar-b → main 0 commits

  • Merged. talk/pane-bar-b was merged into main as 7166b42.

Review

Sign in to review this change.
8 files changed +191 −26
docs/design/areas/talk.md +2
@@ -112,6 +112,8 @@ Prior art: Claude and ChatGPT (one centred column, the person's words in a quiet
112112 - `.talk-pane-info`: one muted line under the bar: for a pull's preview who made it, its number and title, checks and review, and a link to the pull; for Live the default branch and what last landed (`paneInfo`, the terminal prints the same).
113113 - `.talk-pane-fell`: one line when a picked pull's preview is gone: "#N landed: Live has it now."
114114 - `.talk-diff-change`: in Diff, one pull this conversation's work led to: a `<details>` whose summary links the pull and says landed, open or closed, the newest open.
115 - `.talk-crew-fold`: the crew's block while it works, a `<details>` whose summary is its one working line; folded, the fold is kept per conversation. A hold or a failure is drawn without it, so it can never be folded away.
116 - `.talk-crew-reply`: a box in the crew's block whose words are said on the pull shown above, else the run's issue (a comment the crew member reads next); the same path as a receipt's Reply.
115117 - `.talk-reload`: Reload the preview, an icon button drawn `js-only`.
116118 - `.talk-try`: the agent's one line of what to try in the frame (`pane`), above the stage: plain small muted text (`--muted-fg`), no box; text only, never a link.
117119 - `.talk-stage`: the frame's surface, on the card colour with a hairline; `data-busy` dims the frame while it loads again.
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`
136136
137137 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.
138138
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,100 B, the script under 53,500 B, and a page with a code reply under 54,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,100 B, the script under 54,800 B, and a page with a code reply under 55,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).
140140
141141 ## Following
142142
@@ -210,6 +210,10 @@ Under the bar, one line says what you are looking at: for a pull, who made it, i
210210
211211 Diff shows what this conversation's work changed: the pulls its receipts led to, open or landed, newest first, each with its change. With a pull picked in the bar, Diff shows that pull alone. A conversation that filed nothing on the repository asks you to pick a pull; it never shows the repository's newest pull on its own.
212212
213 ## The crew's block
214
215 Under the preview, while the crew works, its block says who is working and streams its steps and words. Its line folds the rest away (the fold is kept per conversation in the browser), and a box under the steps says your words on the pull shown above, or else on the issue the run works: a comment the crew member reads next, the same as a receipt's Reply. A hold (with the control that changes it) or a failed run is never folded away. Without the script the box posts the comment itself and you land on that issue's or pull's page; Back returns to Talk. In the terminal, `c` says words on the same place: the pull the pane shows, else the issue the crew's run works, else the newest receipt's issue.
216
213217 ## Display (#15734)
214218
215219 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).
src/core/talk_work.ts +7 −3
@@ -556,6 +556,10 @@ export interface PaneCrew {
556556 readonly who: string;
557557 /** The reader may read the run's log: the page tails it live, by the run's id. */
558558 readonly tail: boolean;
559 /** The issue the run works, by number: where a word for the crew member is said. */
560 readonly issue?: number;
561 /** It waits on a hold (`holdNow`): the line says why and names the control, so it is never folded away. */
562 readonly held?: boolean;
559563 }
560564
561565 /** What a reader may see of a repository's runs, as `actions/runs.ts` decides it. */
@@ -573,7 +577,7 @@ export interface RunsSeen {
573577 export function paneCrew(db: Database, dataDir: string, repoId: string, reader: User | undefined, seen: RunsSeen): PaneCrew | undefined {
574578 if (!seen.runs) return undefined;
575579 const run = db
576 .query<{ id: string; state: string; actor_id: string | null }, [string]>("SELECT id, state, actor_id FROM run WHERE repo_id = ?1 AND kind = 'agent' ORDER BY id DESC LIMIT 1")
580 .query<{ id: string; state: string; actor_id: string | null; issue: number | null }, [string]>("SELECT r.id, r.state, r.actor_id, i.number AS issue FROM run r LEFT JOIN issue i ON i.id = r.issue_id WHERE r.repo_id = ?1 AND r.kind = 'agent' ORDER BY r.id DESC LIMIT 1")
577581 .get(repoId);
578582 if (run === null) return undefined;
579583 const steps: CrewItem[] = seen.logs
@@ -587,10 +591,10 @@ export function paneCrew(db: Database, dataDir: string, repoId: string, reader:
587591 .slice(-STEPS_SHOWN)
588592 : [];
589593 const who = (run.actor_id === null ? undefined : getUserById(db, run.actor_id)?.username) ?? "the crew";
590 const at = { runId: run.id, steps, tail: seen.logs, who };
594 const at = { runId: run.id, steps, tail: seen.logs, who, ...(run.issue === null ? {} : { issue: run.issue }) };
591595 if (run.state === "queued") {
592596 const hold = holdNow(db, dataDir, run.id);
593 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)) };
597 return hold === undefined ? { ...at, state: "queued", line: { says: "Queued for the crew: it starts when a builder is free." } } : { ...at, state: "queued", held: true, line: holdWords(hold, holdReader(db, repoId, reader)) };
594598 }
595599 if (run.state === "running") return { ...at, state: "running", line: { says: `${who === "the crew" ? "The crew" : who} is working.` } };
596600 if (run.state === "ok") return { ...at, state: "ok", line: { says: "The crew finished this run." } };
src/tui/screens/talk_chats.ts +16 −3
@@ -49,6 +49,7 @@ import { binding } from "../app/keys.ts";
4949 import { style } from "../term/style.ts";
5050 import { truncate, wrap } from "../term/width.ts";
5151 import type { Session } from "../session.ts";
52 import type { User } from "../../core/users.ts";
5253 import { fill, len, split } from "../ui/layout.ts";
5354 import { ListState, Scroll, ago, drawLines, drawList, pickerScreen, promptScreen, runAsync, type ListRow, type PickItem } from "./common.ts";
5455 import { fresh, mayAct, pressCard, PRESS_REFUSED } from "../../actions/talk_act.ts";
@@ -203,6 +204,16 @@ function chatScreen(f: Session, ctx: Ctx, chat: Conversation, hit?: string): Scr
203204 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}`;
204205 return ["", `Crew: ${said}`, ...crew.steps.map((item) => (item.thought ? ` \u201c${item.text}\u201d` : ` ${item.text}`)), `The whole run: /${repo ?? ""}/runs/${crew.runId}`];
205206 };
207 // Where the terminal's c says words: the pull shown, the crew's run's issue, else the newest receipt's.
208 const replyTarget = (user: User): { owner: string; name: string; number: number; object: string } | undefined => {
209 const name = repo === undefined ? undefined : (paneRepo() ?? repo);
210 const ws = name === undefined ? undefined : workspaceOf(f.app, user, name, undefined, pointedAt(choice(), steerOn(name)));
211 const on = (n: number) => (ws === undefined ? undefined : { owner: ws.repo.ownerName, name: ws.repo.name, number: n, object: `${ws.repo.ownerName}/${ws.repo.name}#${String(n)}` });
212 if (ws?.shows !== undefined) return on(ws.shows);
213 const crew = ws === undefined ? undefined : paneCrew(f.app.db, f.app.config.dataDir, ws.repo.id, user, { runs: mayReadRuns(f.app, user, ws.repo), logs: false });
214 if (crew?.issue !== undefined) return on(crew.issue);
215 return [...turns].reverse().map((t) => receipts.get(t.id)).find((r) => r !== undefined);
216 };
206217 const paneLines = (): string[] => {
207218 if (repo === undefined || f.user === undefined) return ["No repository yet."];
208219 // Where the person picked, else where the agent pointed the pane (`pane`), as the page frames it.
@@ -471,10 +482,12 @@ function chatScreen(f: Session, ctx: Ctx, chat: Conversation, hit?: string): Scr
471482 return true;
472483 }
473484 if (e.key === "c") {
474 // The newest receipt's issue: words said there reach whoever works on it, as Reply does.
475 const last = [...turns].reverse().map((t) => receipts.get(t.id)).find((r) => r !== undefined);
485 // As the page's crew box says it: on the pull whose preview the pane shows, else the issue the
486 // crew's newest run works; else, as Reply does, the newest receipt's issue. Whoever works on
487 // it reads it next.
488 const last = replyTarget(user);
476489 if (last === undefined) {
477 note = "No receipt here names an issue to comment on.";
490 note = "No pull, run or receipt here names an issue to comment on.";
478491 ctx.invalidate();
479492 return true;
480493 }
src/web/pages/talk_client.ts +26 −7
@@ -860,6 +860,31 @@ ${dictateJs}
860860 e.preventDefault();
861861 take(e.dataTransfer.files);
862862 });
863 // Words on an issue or pull as a comment: Reply (through the composer) and the crew's box, one path.
864 const sayOn = async (href, text, who) => {
865 say("Sending…");
866 try {
867 const res = await fetch(href + "/comments", { method: "POST", body: new URLSearchParams({ body: text }), redirect: "manual" });
868 if (res.ok || res.type === "opaqueredirect") { say("Said on " + who + ". Whoever works on it reads it next."); return true; }
869 fail("That was not said on " + who + ".");
870 } catch (_) { fail("That was not sent: no connection."); }
871 return false;
872 };
873 document.addEventListener("submit", async (e) => {
874 const f = e.target.closest && e.target.closest("[data-crew-reply]"), t = f && f.querySelector("textarea");
875 if (!f) return;
876 e.preventDefault();
877 if (t.value.trim() && (await sayOn(f.getAttribute("action").replace(/[/]comments$/, ""), t.value.trim(), f.dataset.replyTo))) t.value = "";
878 });
879 // The crew's fold, kept per conversation and drawn again over each live swap (a click toggles after it dispatches).
880 const foldKey = "talk-crew-fold:" + (root.dataset.user || "") + ":" + (cid || "");
881 const crewFold = () => { const d = document.querySelector("#talk-crew-now .talk-crew-fold"); try { if (d && localStorage.getItem(foldKey) === "1") d.removeAttribute("open"); } catch (_) {} };
882 document.addEventListener("click", (e) => {
883 const s = e.target.closest && e.target.closest(".talk-crew-fold > summary");
884 if (s) setTimeout(() => { try { localStorage.setItem(foldKey, s.parentElement.open ? "" : "1"); } catch (_) {} });
885 });
886 document.addEventListener("forge:swapped", crewFold);
887 crewFold();
863888 const send = async (e) => {
864889 const by = e.submitter;
865890 if (by && by.hasAttribute("formaction")) { if (by.hasAttribute("data-answer")) { e.preventDefault(); answerConfirm(by); } return; }
@@ -868,13 +893,7 @@ ${dictateJs}
868893 hush = false;
869894 const text = box.value.trim();
870895 if (text && form.dataset.to) {
871 say("Sending…");
872 try {
873 const res = await fetch(form.dataset.to + "/comments", { method: "POST", body: new URLSearchParams({ body: text }), redirect: "manual" });
874 if (!res.ok && res.type !== "opaqueredirect") { fail("That was not said on " + toWho + "."); return; }
875 box.value = ""; grow(); clearTimeout(draftTimer); draft.save(""); paint();
876 say("Said on " + toWho + ". Whoever works on it reads it next.");
877 } catch (_) { fail("That was not sent: no connection."); }
896 if (await sayOn(form.dataset.to, text, toWho)) { box.value = ""; grow(); clearTimeout(draftTimer); draft.save(""); paint(); }
878897 return;
879898 }
880899 if (!text) { if (attached.length) say("Add a few words about what you attached."); return; }
src/web/pages/talk_preview.ts +37 −10
@@ -95,7 +95,7 @@ export async function talkPane(ctx: Ctx, user: User, name: string | undefined, w
9595 ? await diffView(ctx.app, work, ask.version, ask.mine === undefined ? undefined : { ...ask.mine, picked: at.pull })
9696 : url === undefined || ask.wait !== undefined
9797 ? 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}`, ws.repo, liveSrc)}</div>${ask.build === undefined ? null : html`<h2 class="talk-stage-files small muted">The files it starts from</h2>${await codeView(ctx.app, work)}`}`
98 : html`${steer === undefined || steer.try === "" ? null : html`<p class="talk-try small" data-pane-try>Try: ${steer.try}</p>`}<div class="talk-stage" data-stage data-env="${ws.shows === undefined ? "production" : previewEnv(ws.shows)}"><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>${crewRegion(crew !== undefined && (going || crew.state === "failed") ? crew : undefined, ws.repo, liveSrc)}`;
98 : html`${steer === undefined || steer.try === "" ? null : html`<p class="talk-try small" data-pane-try>Try: ${steer.try}</p>`}<div class="talk-stage" data-stage data-env="${ws.shows === undefined ? "production" : previewEnv(ws.shows)}"><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>${crewRegion(crew !== undefined && (going || crew.state === "failed") ? crew : undefined, ws.repo, liveSrc, ws.shows)}`;
9999 // The address bar of what runs: which environment, where it lives, reload and open on its own.
100100 const where = url === undefined ? null : html`<span class="talk-addr small" title="${url}"><span class="muted">${ws.shows === undefined ? "Production" : `Pull #${String(ws.shows)}`}</span> ${new URL(url).host}</span>`;
101101 // Waiting, the pane is a live region on the repository's runs: a deploy that turns running swaps
@@ -147,27 +147,45 @@ function productionOrigin(ctx: Ctx, repoId: string): string | undefined {
147147 * whenever the pane is open, so the crew's next run (the person's next change) is picked up on
148148 * run.* and drawn under the same frame, which the swap never touches.
149149 */
150 function crewRegion(crew: PaneCrew | undefined, repo: { readonly ownerName: string; readonly name: string }, src: string): Html {
150 function crewRegion(crew: PaneCrew | undefined, repo: { readonly ownerName: string; readonly name: string }, src: string, shows?: number): Html {
151151 return crew === undefined
152152 ? html`<div class="talk-crew-now" id="talk-crew-now" data-live="run.*" data-live-repo="${repo.ownerName}/${repo.name}" data-live-src="${src}"></div>`
153 : crewBlock(crew, `/${repo.ownerName}/${repo.name}`, repo, src);
153 : crewBlock(crew, `/${repo.ownerName}/${repo.name}`, repo, src, shows);
154154 }
155155
156156 /**
157157 * The crew's run in the wait stage: why it waits or that it works, its newest steps in plain words
158 * (the script adds each new one as the run writes it; a log line is only ever text here), and the
159 * run's own page, which is the whole of it without the script.
158 * (the script adds each new one as the run writes it; a log line is only ever text here), the run's
159 * own page, which is the whole of it without the script, and a box whose words are said on the pull
160 * shown above, else the run's issue, where the crew member working it reads them next. While it
161 * works it folds to its one line (a `<details>`, the fold kept per conversation by the script); a
162 * hold or a failure is drawn open and unfoldable, so neither is ever hidden.
160163 */
161 function crewBlock(crew: PaneCrew, base: string, repo: { readonly ownerName: string; readonly name: string }, src: string): Html {
164 function crewBlock(crew: PaneCrew, base: string, repo: { readonly ownerName: string; readonly name: string }, src: string, shows?: number): Html {
165 const working = crew.state === "running" ? " talk-crew-working" : "";
166 const line = html`<p class="small${working}">${workLineHtml(crew.line)}</p>`;
167 const steps = !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((item) => (item.thought ? html`<p class="talk-crew-thought">${item.text}</p>` : html`<p>${item.text}</p>`))}</div>`;
168 const run = html`<a class="small" href="${base}/runs/${crew.runId}">See the whole run</a>`;
169 // A pull's words go through its own page's door, an issue's through its own.
170 const reply = shows !== undefined ? crewReply(`${base}/pulls/${String(shows)}`, `#${String(shows)}`) : crew.issue === undefined ? null : crewReply(`${base}/issues/${String(crew.issue)}`, `#${String(crew.issue)}`);
162171 // Its own live region: the crew's next run is read as it is queued, starts or ends, and the frame
163172 // above it is never redrawn for it.
164173 return html`<div class="talk-crew-now" id="talk-crew-now" data-live="run.*" data-live-repo="${repo.ownerName}/${repo.name}" data-live-src="${src}">
165 <p class="small${crew.state === "running" ? " talk-crew-working" : ""}">${workLineHtml(crew.line)}</p>
166 ${!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((item) => (item.thought ? html`<p class="talk-crew-thought">${item.text}</p>` : html`<p>${item.text}</p>`))}</div>`}
167 <a class="small" href="${base}/runs/${crew.runId}">See the whole run</a>
174 ${crew.held === true || crew.state === "failed" ? html`${line}${steps}${run}` : html`<details class="talk-crew-fold" open><summary><span class="small${working}">${workLineHtml(crew.line)}</span></summary>${steps}${run}${reply}</details>`}
168175 </div>`;
169176 }
170177
178 /**
179 * Words for whoever works an issue or pull, said on it as a comment: the receipt's Reply and this box
180 * send through the one script path (`sayOn`); without the script the form posts the comment itself.
181 */
182 function crewReply(href: string, who: string): Html {
183 return html`<form class="talk-crew-reply" method="post" action="${href}/comments" data-crew-reply data-reply-to="${who}">
184 <textarea class="input" name="body" rows="1" required aria-label="Reply on ${who}" placeholder="Reply on ${who}"></textarea>
185 <button class="btn" data-size="sm" type="submit">Send</button>
186 </form>`;
187 }
188
171189 /**
172190 * The pane's own styles, sent only on a page that draws one (`data-split`). Spacing is the scale.
173191 */
@@ -190,9 +208,18 @@ export const paneCss = /* css */ `
190208 .talk-crew-steps { display: grid; gap: 2px; overflow-wrap: anywhere; }
191209 .talk-crew-steps p { margin: 0; }
192210 .talk-crew-steps .talk-crew-thought { color: var(--fg); }
211 .talk-crew-fold { display: grid; gap: 8px; }
212 .talk-crew-fold > summary { display: flex; align-items: center; gap: 8px; min-height: 2.75rem; cursor: pointer; list-style: none; }
213 .talk-crew-fold > summary::-webkit-details-marker { display: none; }
214 .talk-crew-fold > summary::before { content: "▾"; color: var(--muted-fg); transition: transform var(--dur-2) var(--ease); }
215 .talk-crew-fold:not([open]) > summary::before { transform: rotate(-90deg); }
216 .talk-crew-fold > :not(summary) { margin-inline-start: 24px; }
217 .talk-crew-reply { display: flex; gap: 8px; align-items: end; }
218 .talk-crew-reply textarea { flex: 1; min-height: 2.75rem; resize: vertical; }
219 @media (prefers-reduced-motion: reduce) { .talk-crew-fold > summary::before { transition: none; } }
193220 .talk-stage:not(.talk-stage-wait) + .talk-crew-now { margin-top: 12px; }
194221 /* While the crew works under it, the frame gives it room: both in view at once. */
195 .talk-stage:has(+ .talk-crew-now:not(:empty)) .talk-frame { height: calc(100dvh - 30rem); min-height: 14rem; }
222 .talk-stage:has(+ .talk-crew-now:not(:empty):not(:has(> .talk-crew-fold:not([open])))) .talk-frame { height: calc(100dvh - 30rem); min-height: 14rem; }
196223 .talk-addr-pick { display: flex; align-items: center; gap: 4px; padding: 2px 4px; overflow: visible; }
197224 .talk-addr-pick select, .talk-addr-pick input { min-width: 0; min-height: 2.75rem; border: 0; border-radius: 999px; background: transparent; color: var(--fg); font: inherit; padding: 0 8px; }
198225 .talk-addr-pick select { flex: 0 1 auto; min-width: 5rem; max-width: 14rem; text-overflow: ellipsis; }
test/talk-live-pane.test.ts +69 −1
@@ -16,6 +16,7 @@ import { appendTurn, createConversation } from "../src/core/conversations.ts";
1616 import { announceRun } from "../src/actions/runs.ts";
1717 import { listEvents } from "../src/core/events.ts";
1818 import { createRun } from "../src/core/runs.ts";
19 import { createIssue } from "../src/core/issues.ts";
1920 import { createSession } from "../src/core/sessions.ts";
2021 import { repoOf } from "../src/core/talk_steps.ts";
2122 import { paneCrew, plainStep, plainThought } from "../src/core/talk_work.ts";
@@ -144,6 +145,48 @@ describe("the pane, by the crew's newest run on the repository", () => {
144145 expect(flat).toContain(
145146 `data-live="run.*" data-live-repo="${name}" data-live-src="?pane=preview&amp;fragment=pane"`,
146147 );
148 // A hold is never folded away: no fold, its words and control in plain view.
149 expect(flat).not.toContain("talk-crew-fold");
150 });
151
152 test("working, the block folds to its one line, and its box says words on the run's issue, or on the pull shown above", async () => {
153 n += 1;
154 const made = await createRepo(app, alice, { name: `fold${String(n)}`, visibility: "public" });
155 if (!made.ok) throw new Error(String(made.error));
156 const issue = createIssue(app.db, { repoId: made.value.id, authorId: alice.id, title: "Bigger button", body: "b" });
157 if (!issue.ok) throw new Error("issue");
158 const run = createRun(app.db, { repoId: made.value.id, kind: "agent", issueId: issue.value.id, reason: "assigned" });
159 app.db.run("UPDATE run SET state = 'running' WHERE id = ?1", [run.id]);
160 const name = `alice/${made.value.name}`;
161 const production = { newestPull: () => undefined, urlOf: (_: unknown, env: string) => (env === "production" ? "https://fold.apps.test/" : undefined) };
162 const flat = (await talkPane(ctx, alice, name, new Map(), "preview", production)).html.text.replace(/\s+/g, " ");
163 // A summary holds phrasing only: the working line is a span in it.
164 expect(flat).toContain('<details class="talk-crew-fold" open><summary><span class="small talk-crew-working">');
165 expect(flat).toContain('aria-label="Reply on #');
166 expect(flat).not.toContain("whoever works on it reads it next");
167 const n1 = String(issue.value.number);
168 expect(flat).toContain(`<form class="talk-crew-reply" method="post" action="/${name}/issues/${n1}/comments" data-crew-reply data-reply-to="#${n1}">`);
169 // A pull's preview shown above: the words go to that pull.
170 const pulled = { newestPull: () => 7, urlOf: (_: unknown, env: string) => (env === "pull-7" ? "https://fold--7.apps.test/" : env === "production" ? "https://fold.apps.test/" : undefined) };
171 const onPull = (await talkPane(ctx, alice, name, new Map(), "preview", pulled)).html.text;
172 expect(onPull).toContain(`action="/${name}/pulls/7/comments"`);
173 // That path takes a pull's number: the form, sent without the script, says the words on the pull.
174 const pr = createIssue(app.db, { repoId: made.value.id, authorId: alice.id, title: "Bigger", body: "b", kind: "pull" });
175 if (!pr.ok) throw new Error("pull");
176 app.db.run("INSERT INTO pull (issue_id, base_branch, head_branch, base_oid, head_oid) VALUES (?1, 'main', 'crew/bigger', '', '')", [pr.value.id]);
177 const posted = await fetch(`${servers.url}/${name}/pulls/${String(pr.value.number)}/comments`, {
178 method: "POST",
179 redirect: "manual",
180 headers: { cookie: `forge_session=${createSession(app.db, alice.id).token}`, origin: servers.url, "content-type": "application/x-www-form-urlencoded" },
181 body: new URLSearchParams({ body: "make it green too" }),
182 });
183 expect(posted.status).toBe(303);
184 expect(app.db.query<{ body: string }, [string]>("SELECT body FROM comment WHERE issue_id = ?1").all(pr.value.id).map((c) => c.body)).toContain("make it green too");
185 // Failed: drawn open, no fold.
186 app.db.run("UPDATE run SET state = 'failed' WHERE id = ?1", [run.id]);
187 const failed = (await talkPane(ctx, alice, name, new Map(), "preview", production)).html.text;
188 expect(failed).toContain("The crew&#39;s run did not finish.");
189 expect(failed).not.toContain("talk-crew-fold");
147190 });
148191
149192 test("queued with no hold logged: it says it waits for a builder", async () => {
@@ -231,7 +274,7 @@ describe("the pane, by the crew's newest run on the repository", () => {
231274 expect(html).toContain('<iframe class="talk-frame" data-frame src="https://clicker.apps.test/"');
232275 expect(html).toContain('data-stage data-env="production"');
233276 expect(html).toContain('<span class="muted">Production</span>');
234 expect(html).toContain('<p class="small talk-crew-working">alice is working.</p>');
277 expect(html).toContain('<summary><span class="small talk-crew-working">alice is working.</span></summary>');
235278 expect(html).toContain('id="talk-crew-now" data-live="run.*"');
236279 expect(html).not.toMatch(/<aside[^>]*data-live=/);
237280 // The one escaping the page's html does to a thought: the apostrophe.
@@ -361,6 +404,31 @@ describe("the pane, by the crew's newest run on the repository", () => {
361404 expect(frame!.getAttribute("src")).toBe("https://clicker.apps.test/");
362405 });
363406
407 test("the terminal's c says words where the crew box does: on the issue the crew's run works", async () => {
408 n += 1;
409 const made = await createRepo(app, alice, { name: `said${String(n)}`, visibility: "public" });
410 if (!made.ok) throw new Error(String(made.error));
411 const issue = createIssue(app.db, { repoId: made.value.id, authorId: alice.id, title: "A footer", body: "b" });
412 if (!issue.ok) throw new Error("issue");
413 const run = createRun(app.db, { repoId: made.value.id, kind: "agent", issueId: issue.value.id, reason: "assigned" });
414 app.db.run("UPDATE run SET state = 'running' WHERE id = ?1", [run.id]);
415 const chat = createConversation(app.db, alice.id);
416 if (!chat.ok) throw new Error(chat.error);
417 appendTurn(app.db, alice.id, chat.value.id, { role: "tool", text: `mcp__forge__read_file ${JSON.stringify({ repo: `alice/${made.value.name}`, path: "a" })}` });
418 const terminal = headlessTerminal(120, 30);
419 const { app: tui } = createForgeApp(app, { sshUsername: "alice", remoteAddress: "127.0.0.1", fingerprint: "SHA256:test", user: alice }, { terminal, exitHooks: false });
420 tui.start();
421 for (const k of [":", "Conversations", "\r", "\r", "c"]) {
422 terminal.feed(k);
423 await settleApp(tui);
424 }
425 expect(tui.screen.toText()).toContain(`on alice/${made.value.name}#${String(issue.value.number)}, to whoever works on it`);
426 for (const ch of "make it green too") terminal.feed(ch);
427 terminal.feed("\r");
428 await pollUntil(() => app.db.query<{ n: number }, [string]>("SELECT COUNT(*) AS n FROM comment WHERE issue_id = ?1").get(issue.value.id)!.n > 0, "the words said on the issue");
429 expect(app.db.query<{ body: string }, [string]>("SELECT body FROM comment WHERE issue_id = ?1").get(issue.value.id)?.body).toBe("make it green too");
430 });
431
364432 test("a deploy of production that ends ok reaches the page as the event the pane reframes on: run.finished, the repository, a deploy, ok, its environment", async () => {
365433 // The page's handler (talk_client.ts) reads kind, repo, payload.kind, payload.state and payload.env;
366434 // this is that event as /events sends it to the app's owner, not a shape written by hand.
test/talk-page.test.ts +29 −1
@@ -454,7 +454,7 @@ describe("the page", () => {
454454 test("the page's own bytes are held: stylesheet and script stay small", async () => {
455455 const { talkCss, talkJs } = await import("../src/web/pages/talk_client.ts");
456456 expect(Buffer.byteLength(talkCss)).toBeLessThan(18_100);
457 expect(Buffer.byteLength(talkJs)).toBeLessThan(53_500);
457 expect(Buffer.byteLength(talkJs)).toBeLessThan(54_800);
458458 // A page of its own, so what other tests said to alice never counts: one question and a code reply.
459459 const sizer = await createUser(app.db, { origin: "seed", trusted: true, username: "sizer", email: "[email protected]", password: "a-good-passphrase" });
460460 if (!sizer.ok) throw new Error(sizer.error);
@@ -759,6 +759,34 @@ describe("the page", () => {
759759 expect(t.window.history.length).toBe(before + 2);
760760 });
761761
762 test("the crew's block folds to its line, kept per conversation over every live swap; its box says words on the issue through the one path Reply uses", async () => {
763 const store: Record<string, string> = {};
764 const t = await boot("u1", store);
765 const block = (open: boolean) => `<details class="talk-crew-fold"${open ? " open" : ""}><summary><p class="small talk-crew-working">juniper is working.</p></summary><div data-crew-steps="r1"></div><form class="talk-crew-reply" method="post" action="/alice/x/issues/3/comments" data-crew-reply data-reply-to="#3"><textarea name="body"></textarea><button type="submit">Send</button></form></details>`;
766 t.doc.body.insertAdjacentHTML("beforeend", `<div class="talk-crew-now" id="talk-crew-now">${block(true)}</div>`);
767 const region = t.doc.querySelector("#talk-crew-now");
768 region.querySelector("summary").dispatchEvent(new t.window.MouseEvent("click", { bubbles: true, cancelable: true }));
769 region.querySelector(".talk-crew-fold").removeAttribute("open");
770 await pollUntil(() => store["talk-crew-fold:u1:c1"] === "1", "the fold kept");
771 // The live region swaps the block in drawn open, as the server draws it: the fold is kept.
772 region.innerHTML = block(true);
773 region.dispatchEvent(new t.window.CustomEvent("forge:swapped", { bubbles: true }));
774 expect(region.querySelector(".talk-crew-fold").hasAttribute("open")).toBe(false);
775 // A hold has no fold: nothing is folded away.
776 region.innerHTML = '<p class="small">Waits for the reset.</p>';
777 region.dispatchEvent(new t.window.CustomEvent("forge:swapped", { bubbles: true }));
778 expect(region.textContent).toContain("Waits for the reset.");
779 // The box: its words are a comment on the issue, the same path a receipt's Reply takes.
780 region.innerHTML = block(true);
781 const box = region.querySelector("textarea");
782 box.value = "make it green too";
783 region.querySelector("form").dispatchEvent(new t.window.Event("submit", { bubbles: true, cancelable: true }));
784 await pollUntil(() => t.sent.some((s: string) => s.startsWith("comment:/alice/x/issues/3/comments")), "the comment sent");
785 expect(t.sent.find((s: string) => s.startsWith("comment:"))).toBe("comment:/alice/x/issues/3/comments:body=make+it+green+too");
786 await pollUntil(() => box.value === "", "the box emptied");
787 expect(t.doc.querySelector(".talk-status").textContent).toBe("Said on #3. Whoever works on it reads it next.");
788 });
789
762790 test("a pasted file becomes a chip with Remove, and a sent message carries its id once", async () => {
763791 const t = await boot();
764792 const paste = new t.window.Event("paste", { bubbles: true, cancelable: true }) as any;

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs