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

A talk answer's cited issue and pull numbers link to their pages, and only to pages the viewer may read #13438

Merged opened this

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

Merged

scout/forge:scout/13405-a-talk-answer-s-cited-issue-and-pull-num → main 7 commits fork 1 thread · 1 unresolved

  • Merged. scout/13405-a-talk-answer-s-cited-issue-and-pull-num was merged into main as 6199991.

Review

Sign in to review this change.
11 files changed +247 −25
docs/features/README.md +1
@@ -142,6 +142,7 @@ Read with the guide page [Tell the crew](../guide-tell-the-crew.md).
142142 - [/talk attachments](talk-attachments.md)
143143 - [Talk runs the captain](talk-captain.md)
144144 - [Talk to the forge's agent](talk.md)
145 - [Talk answers link the issue and pull numbers they cite](talk-links.md)
145146 - [Tell the crew from a share, with a look before it files](share-tell.md)
146147 - [The crew line on Home](crew-line.md)
147148 - [The crew list](crew-list.md)
src/actions/runs.ts +17 −9
@@ -1,11 +1,10 @@
11 /**
22 * Run actions: look at a repository's runs and their logs, cancel one,
3 * queue a finished agent run's task again, and — for the workers that produce runs — announce a run's state on the
4 * outbox. Reading follows the repository's visibility (a run's log is as
5 * private as the code it ran), and a private app's runs follow the app: a
6 * deploy log carries the app's own output, so only someone who may enter
7 * the app reads them (#620). Cancelling takes write access; announcing is
8 * the system's own voice and takes no actor.
3 * queue a finished agent run's task again, and — for the workers that produce runs — announce a
4 * run's state on the outbox. Reading follows the repository's visibility (a run's log is as private
5 * as the code it ran), and a private app's runs follow the app: a deploy log carries the app's own
6 * output, so only someone who may enter the app reads them (#620). Cancelling takes write access;
7 * announcing is the system's own voice and takes no actor.
98 */
109
1110 import { commitVerdicts, isCommitId, releaseCheck, type CommitCheck } from "../checks/commit_check.ts";
@@ -268,12 +267,18 @@ export async function checkOfCommit(
268267 );
269268 }
270269
271 /** One look of a check as the API words it: how many screens tall, and whether a phone look scrolls sideways. */
270 /**
271 * One look of a check as the API words it: how many screens tall, and whether a phone look scrolls
272 * sideways.
273 */
272274 export interface LookFigures {
273275 readonly look: string;
274276 readonly screens: string;
275277 readonly sideways: boolean;
276 /** The window and page as measured (`scrollWidth` vs `innerWidth` says whether it fits); absent when none was recorded. */
278 /**
279 * The window and page as measured (`scrollWidth` vs `innerWidth` says whether it fits); absent
280 * when none was recorded.
281 */
277282 readonly size?: PageSize;
278283 }
279284
@@ -297,7 +302,10 @@ export function looksOfCheck(
297302 }));
298303 }
299304
300 /** The own green or red verdicts of a page of commits, for whoever may read the runs; empty otherwise. */
305 /**
306 * The own green or red verdicts of a page of commits, for whoever may read the runs; empty
307 * otherwise.
308 */
301309 export function verdictsOfCommits(
302310 app: App,
303311 actor: User | undefined,
src/actions/talk.ts +4 −1
@@ -68,7 +68,10 @@ export function talk(app: App, user: User | undefined, text: string, files: read
6868 return said;
6969 }
7070
71 /** Edit the last message and resend it, regenerate the last reply, or retry a failed turn (#8817), in the named conversation or the latest. */
71 /**
72 * Edit the last message and resend it, regenerate the last reply, or retry a failed turn (#8817),
73 * in the named conversation or the latest.
74 */
7275 export function talkAgain(app: App, user: User | undefined, how: RedoHow, text = "", conversationId?: string): Result<Said, TalkRefusal> {
7376 if (user === undefined) return err("unauthorized");
7477 const options = conversationOptions(app);
src/core/conversation_markdown.ts +4 −3
@@ -2,7 +2,8 @@
22 * A talk conversation as one Markdown document (#13307): who, when, the text,
33 * and each attachment as a link, turns in the order they were written. The
44 * download route, the MCP `say` tool (`action: download`) and the terminal's talk screen all
5 * return this text; each turn's words sit in a fenced block, and only the conversation's owner is ever served it.
5 * return this text; each turn's words sit in a fenced block, and only the conversation's owner is
6 * ever served it.
67 */
78 import type { Database } from "bun:sqlite";
89 import { err, ok, type Result } from "../kernel/result.ts";
@@ -18,8 +19,8 @@ const plain = (s: string): string => s.replace(/[\r\n]+/g, " ").replace(/[[\]()<
1819 export const MAX_TEXT = 1_000_000;
1920
2021 /**
21 * The newest turns that still count (an edit's replaced ones are left out), oldest first, read a page
22 * at a time until `MAX_TEXT` is reached. `cut` is true when older turns were left unread.
22 * The newest turns that still count (an edit's replaced ones are left out), oldest first, read a
23 * page at a time until `MAX_TEXT` is reached. `cut` is true when older turns were left unread.
2324 */
2425 function recentTurns(db: Database, userId: string, conversationId: string): { turns: Turn[]; cut: boolean } {
2526 const out: Turn[] = [];
src/tui/screens/talk_chats.ts +8 −2
@@ -9,6 +9,7 @@
99 * sends that one through the same `talk()`.
1010 */
1111
12 import { pathRefs, refTarget } from "../../text/talk_links.ts";
1213 import { STARTER_PROMPTS, TALK_WORDS, talk } from "../../actions/talk.ts";
1314 import {
1415 archiveConversation,
@@ -39,7 +40,10 @@ const BAD_TITLE = `A title is up to ${TITLE_MAX} characters, on one line.`;
3940
4041 const WHO: Readonly<Record<string, string>> = { person: "You", agent: "Forge", tool: "Tool", confirm: "Asks" };
4142
42 /** The conversation as the Markdown download holds it, to read and scroll; the file itself is the web's /talk/:id/download. */
43 /**
44 * The conversation as the Markdown download holds it, to read and scroll; the file itself is the
45 * web's /talk/:id/download.
46 */
4347 function downloadScreen(f: Session, ctx: Ctx, chat: Conversation): Screen {
4448 const scroll = new Scroll();
4549 const made = f.user === undefined ? undefined : conversationMarkdown(f.app.db, f.user.id, chat.id, publicOrigin(f.app.config.url, `http://localhost:${f.app.config.port}`));
@@ -119,11 +123,13 @@ function chatScreen(f: Session, ctx: Ctx, chat: Conversation, hit?: string): Scr
119123 [{ text: "Nothing said yet; s says something, or a number sends one of these:", style: style(c.mutedFg, c.bg) }],
120124 ...STARTER_PROMPTS.map((p, i) => [{ text: ` ${String(i + 1)} ${p}`, style: style(c.fg, c.bg) }]),
121125 ];
126 const refs = refTarget(f.app.db, f.user, repo);
122127 let n = 0;
123128 return turns.flatMap((t) => {
124129 if (t.id === around) mark = n;
125130 const step = t.role === "tool" ? stepOf(t.text) : undefined;
126 const own = (step === undefined ? t.text : [step.label, ...step.details.map((d) => ` ${d}`)].join("\n")).split("\n").flatMap((l) => wrap(l, Math.max(10, width - 2)));
131 const said = t.role === "agent" ? pathRefs(t.text, refs) : t.text;
132 const own = (step === undefined ? said : [step.label, ...step.details.map((d) => ` ${d}`)].join("\n")).split("\n").flatMap((l) => wrap(l, Math.max(10, width - 2)));
127133 n += own.length + 2;
128134 return [
129135 [{ text: `${t.id === around ? "▶ " : ""}${WHO[t.role] ?? t.role}${t.replaced ? " · replaced" : ""} · ${ago(t.createdAt)}`, style: style(c.mutedFg, c.bg) }],
src/web/pages/talk.ts +14 −5
@@ -56,6 +56,7 @@ import { signInFirst, forbiddenPage, notFoundPage } from "../chrome.ts";
5656 import { readForm } from "../form.ts";
5757 import { html, raw, type Html } from "../html.ts";
5858 import { flashTo, page, redirect } from "../layout.ts";
59 import { linkRefs, refTarget } from "../../text/talk_links.ts";
5960 import { renderMarkdown } from "../markdown.ts";
6061 import { badge, btn, row, time } from "../ui.ts";
6162 import { buildBox, buildCss, chosenTemplate, panelFor } from "../talk_build.ts";
@@ -215,7 +216,7 @@ const totalLine = (usd: number | undefined): Html =>
215216 const costLine = (usd: number): Html => html`<p class="talk-cost small muted">${dollars(usd)} this turn</p>`;
216217
217218 /** One turn as the page and the stream both draw it; `waiting` is the confirms still open. */
218 export function turnHtml(turn: Turn, waiting: ReadonlySet<string>, cost?: number, act?: Html, work?: Work, files: readonly ConversationFile[] = [], expired: ReadonlySet<string> = new Set(), undone: ReadonlySet<string> = new Set()): Html {
219 export function turnHtml(turn: Turn, waiting: ReadonlySet<string>, cost?: number, act?: Html, work?: Work, files: readonly ConversationFile[] = [], expired: ReadonlySet<string> = new Set(), undone: ReadonlySet<string> = new Set(), refs?: (n: number) => string | undefined): Html {
219220 const id = `t-${turn.id}`;
220221 const set = turn.replaced ? " talk-replaced" : "";
221222 const acts = act === undefined ? null : html`<div class="talk-acts">${act}</div>`;
@@ -233,7 +234,7 @@ export function turnHtml(turn: Turn, waiting: ReadonlySet<string>, cost?: number
233234 </li>`;
234235 if (turn.role === "agent")
235236 return html`<li class="talk-turn talk-agent${set}" id="${id}">
236 <div class="talk-body prose">${renderMarkdown(turn.text)}</div>
237 <div class="talk-body prose">${refs === undefined ? renderMarkdown(turn.text) : linkRefs(renderMarkdown(turn.text), refs)}</div>
237238 ${work === undefined ? null : workHtml(work)}
238239 ${label("Forge")}
239240 ${cost === undefined ? null : costLine(cost)}${acts}
@@ -372,7 +373,9 @@ async function talkPage(ctx: Ctx, conversation: Conversation, before0: string |
372373 const asked = ctx.url.searchParams.get("pane");
373374 const view: View | undefined = VIEWS.find((p) => p === asked);
374375 const shown = view ?? "chat";
375 const pane = talkPane(ctx, user, repoOf(turns), works, view);
376 const cited = repoOf(turns);
377 const refs = refTarget(ctx.app.db, user, cited);
378 const pane = talkPane(ctx, user, cited, works, view);
376379 const body = html`<h1 class="sr-only">Talk</h1>
377380 ${box}
378381 <div class="talk-shell" data-shell data-pane="${shown}">
@@ -390,7 +393,7 @@ async function talkPage(ctx: Ctx, conversation: Conversation, before0: string |
390393 ${turns.length === 0
391394 ? html`<li class="muted talk-turn">Ask the forge anything, or tell it what to change. It acts as you, with your permissions, and asks before anything hard to undo.
392395 <div class="talk-suggest">${STARTER_PROMPTS.map((q) => html`<form method="post" action="${here}" data-starter><input type="hidden" name="text" value="${q}" />${btn(q)}</form>`)}</div></li>`
393 : turns.map((t) => turnHtml(t, waiting, costs.get(t.id), acts.get(t.id), works.get(t.id), sent.get(t.id), expired, undone))}
396 : turns.map((t) => turnHtml(t, waiting, costs.get(t.id), acts.get(t.id), works.get(t.id), sent.get(t.id), expired, undone, refs))}
394397 ${!paged && running ? queuedTalk(ctx.app, user, conversation.id).map(queuedHtml) : null}
395398 </ol>
396399 <div id="end"></div>
@@ -608,6 +611,9 @@ export function talkStream(ctx: Ctx): Response {
608611 const started = Date.now();
609612 let told = false;
610613 let shown = "";
614 // The repository the chat works on, kept across batches instead of re-reading the turns.
615 const before = listTurns(app.db, user.id, conversation.id, { limit: DEFAULT_PAGE });
616 let cited: string | undefined = before.ok ? repoOf(before.value) : undefined;
611617 const tick = (): void => {
612618 // Asked before the read: a turn that ends after this look is read whole next time.
613619 const running = clock.running(app, user.id, conversation.id);
@@ -618,8 +624,11 @@ export function talkStream(ctx: Ctx): Response {
618624 const undone = undoneIn(fresh);
619625 const works = worksOf(app.db, user.id, conversation.id, fresh);
620626 const sent = filesOfTurns(app.db, user.id, fresh.filter((t) => t.role === "person").map((t) => t.id));
627 const named = repoOf(fresh);
628 if (named !== undefined) cited = named;
629 const refs = refTarget(app.db, user, cited);
621630 for (const turn of fresh) {
622 emit("turn", { id: turn.id, role: turn.role, html: turnHtml(turn, waiting, undefined, undefined, works.get(turn.id), sent.get(turn.id), expired, undone).text }, turn.id);
631 emit("turn", { id: turn.id, role: turn.role, html: turnHtml(turn, waiting, undefined, undefined, works.get(turn.id), sent.get(turn.id), expired, undone, refs).text }, turn.id);
623632 cursor = turn.id;
624633 }
625634 }
test/no-polling.test.ts +19 −5
@@ -36,10 +36,15 @@ const NO_TIMER_PAGES = ["/system", "/flow"];
3636 * that only the owner's own submit changes; a pushed patch would move a handle under a drag. */
3737 const STREAM_PAGES = ["/system"];
3838
39 /** A page as the browser gets it: its markup, and every script it runs (fetched files and inline bodies), apart. */
39 /**
40 * A page as the browser gets it: its markup, and every script it runs (fetched files and inline
41 * bodies), apart.
42 */
4043 export interface RenderedPage { html: string; scripts: string[] }
4144
42 /** A stream a script opens. `data-live` alone, never `data-live-every`, the beat this guard forbids. */
45 /**
46 * A stream a script opens. `data-live` alone, never `data-live-every`, the beat this guard forbids.
47 */
4348 const STREAM = /EventSource\s*\(|data-live(?![-\w])/;
4449
4550 /** Script types that hold data, not code. */
@@ -230,7 +235,10 @@ describe("no rendered page polls", () => {
230235 * reads each page's markup and the scripts it loads.
231236 */
232237
233 /** The text of the balanced `(…)` or `{…}` whose opener is at `open`. Strings and comments are not understood: a bracket inside one skews it. */
238 /**
239 * The text of the balanced `(…)` or `{…}` whose opener is at `open`. Strings and comments are not
240 * understood: a bracket inside one skews it.
241 */
234242 function balanced(src: string, open: number): string {
235243 const pairs: Record<string, string> = { "(": ")", "{": "}" };
236244 const o = src[open]!, c = pairs[o]!;
@@ -242,7 +250,10 @@ function balanced(src: string, open: number): string {
242250 return src.slice(open + 1);
243251 }
244252
245 /** The body of a function a script names: `function name(…) {…}` or `name = (…) => {…}` / `name = function (…) {…}`. */
253 /**
254 * The body of a function a script names: `function name(…) {…}` or `name = (…) => {…}` /
255 * `name = function (…) {…}`.
256 */
246257 function bodyOf(src: string, name: string): string | undefined {
247258 const m = new RegExp(`(?:function\\s+${name}\\s*\\(|\\b${name}\\s*=\\s*(?:async\\s*)?(?:function\\s*\\(|\\([^)]*\\)\\s*=>|\\w+\\s*=>))`).exec(src);
248259 if (!m) return undefined;
@@ -413,7 +424,10 @@ describe("every page the router lists", () => {
413424 });
414425 });
415426
416 /** Fewest HTML pages the admin walk reaches; observed when written. A page lost from the walk drops under it. */
427 /**
428 * Fewest HTML pages the admin walk reaches; observed when written. A page lost from the walk drops
429 * under it.
430 */
417431 const WALKED_FLOOR = 130;
418432 /** The same, signed out (observed 44). */
419433 const ANON_FLOOR = 40;
test/tui-talk-chats.test.ts +17
@@ -9,6 +9,7 @@ import { tmpdir } from "node:os";
99 import { join } from "node:path";
1010 import { createApp, type App } from "../src/app.ts";
1111 import { appendTurn, archiveConversation, CONVERSATIONS_MAX, createConversation, listConversations, listTurns, renameConversation } from "../src/core/conversations.ts";
12 import { createIssue } from "../src/core/issues.ts";
1213 import { createUser, type User } from "../src/core/users.ts";
1314 import { createRepo } from "../src/actions/repos.ts";
1415 import { STARTER_PROMPTS } from "../src/actions/talk.ts";
@@ -101,6 +102,22 @@ describe("the terminal's conversations screen", () => {
101102 expect(turns.ok && turns.value.length).toBe(2);
102103 });
103104
105 test("an answer's cited number prints its path when readable and nothing when not (#13405)", async () => {
106 for (const [name, visibility, shows] of [["pubtalk", "public", true], ["privtalk", "private", false]] as const) {
107 const repo = await createRepo(app, alice, { name, visibility });
108 if (!repo.ok) throw new Error(String(repo.error));
109 const issue = createIssue(app.db, { repoId: repo.value.id, authorId: alice.id, title: "t" });
110 if (!issue.ok) throw new Error(issue.error);
111 const made = createConversation(app.db, bob.id);
112 if (!made.ok) throw new Error(made.error);
113 appendTurn(app.db, bob.id, made.value.id, { role: "tool", text: `mcp__forge__read_file {"repo":"alice/${name}","path":"a.ts"}` });
114 appendTurn(app.db, bob.id, made.value.id, { role: "agent", text: `it is tracked in #${issue.value.number}` });
115 const text = await drive(bob, [...open, "\r"]);
116 expect(text).toContain(`tracked in #${issue.value.number}`);
117 expect(text.includes(`/alice/${name}/issues/${issue.value.number}`)).toBe(shows);
118 }
119 });
120
104121 test("an empty conversation numbers the starter prompts, and a number sends that one through talk()", async () => {
105122 const carol = await createUser(app.db, { origin: "seed", trusted: true, username: "carol", email: "[email protected]", password: "a-good-passphrase" });
106123 if (!carol.ok) throw new Error(carol.error);

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs