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

Every link in a Talk reply clicks, and nothing that reads as a link is dead #16212

Merged opened this

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

Merged

talk/fix-links-click → main 2 commits 3 threads · 3 unresolved

  • Merged. talk/fix-links-click was merged into main as 4d126cc.

Review

Sign in to review this change.
5 files changed +591 −6
docs/features/talk.md +4
@@ -122,6 +122,10 @@ Prior art read: Vercel AI Elements (Apache-2.0 React on shadcn; anatomy and beha
122122
123123 **The terminal** (`ssh <forge> talk <words>`, `forge talk`) sends one line and prints the answer; it has no log, so who/when, copy, tool cards, starters and the jump button do not apply to it. `forge talk` prints a thought as one `thinking:` line, then the reply, the steps line and the links as paths (the API's agent turns carry `work: {steps, links}`). The steps line says "opened" for a read issue or pull and "changed" for a tool that writes one (`CHANGES` in `core/talk_work.ts`, held to the MCP tools' `writes` by a test); numbers carry their repo when a turn touched more than one. A reply first on an older page, or first in a stream batch, reads its calls from the turns before the page (`worksOf`), so it says the same on every door. The conversation's whole history is read through `GET /api/v1/conversation/turns`, where every turn carries its role and time.
124124
125 ## Every link in a reply clicks
126
127 A reply is drawn by the README renderer and then, for Talk alone, by `linkTalk` (`src/text/talk_link_words.ts`): a Markdown link stays a link only if it goes somewhere (an `http(s)` address with no user part, or a path rooted on this forge: one leading slash, never `//` or `/\\`, no encoded control character), and a relative path, which would resolve against the conversation's own address, is set back to its words. A bare `http(s)` address in the words is a link, its trailing punctuation left out. A forge path written as words (`owner/repo`, `owner/repo#12`, `owner/repo/pulls/4`, `owner/repo/src/a.ts`) is a link when you may read that repository and, for a number, when it is there; anything else stays words, so a private repository's existence is never shown. Each repository a page of replies names is read once. An address of one of this forge's apps you may read goes to it while it runs, and to its page on the forge, said "not running yet", while it does not. READMEs keep their rules (no bare-address or path links); both now refuse a `/\\host` link, which a browser reads as `//host`.
128
125129 ## Code, tables and Copy in a reply (#8816)
126130
127131 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.
src/web/markdown.ts +7 −1
@@ -113,7 +113,13 @@ function inline(escaped: string, repo?: MarkdownRepo): string {
113113 // what keeps javascript:, data: and vbscript: out. What is left is a
114114 // relative path (`docs/keeping.md`), a rooted one, or an anchor —
115115 // all of which stay on this origin by construction.
116 if (url.startsWith("//")) return match;
116 // A browser reads "/\\host" and "\\host" as "//host" too.
117 if (
118 url.startsWith("//") ||
119 url.startsWith("/\\") ||
120 url.startsWith("\\")
121 )
122 return match;
117123 if (repo !== undefined) {
118124 const at = resolveRelative(url, repo);
119125 if (at === "inert") return `${bang}${text}`;
src/web/pages/talk.ts +20 −5
@@ -61,6 +61,7 @@ import { readForm } from "../form.ts";
6161 import { html, raw, type Html } from "../html.ts";
6262 import { flashTo, page, redirect } from "../layout.ts";
6363 import { linkRefs, refTarget } from "../../text/talk_links.ts";
64 import { appLook, linkTalk, talkLook, type TalkLook } from "../../text/talk_link_words.ts";
6465 import { liveCrewRows } from "../../actions/crew_now.ts";
6566 import { crewLineHtml } from "../crew_now.ts";
6667 import { renderMarkdown } from "../markdown.ts";
@@ -230,8 +231,19 @@ const totalLine = (usd: number | undefined): Html =>
230231 /** The cost line under a reply. */
231232 const costLine = (spend: Spend): Html => html`<p class="talk-cost small muted">${spendWords(spend)}</p>`;
232233
234 /**
235 * What a reply's drawn Markdown becomes on the page: its cited numbers linked, and every link one
236 * that clicks.
237 */
238 const linkedOf =
239 (refs?: (n: number) => string | undefined, look?: TalkLook) =>
240 (md: Html): Html => {
241 const cited = refs === undefined ? md : linkRefs(md, refs);
242 return look === undefined ? cited : linkTalk(cited, look);
243 };
244
233245 /** One turn as the page and the stream both draw it; `waiting` is the confirms still open. */
234 export function turnHtml(turn: Turn, waiting: ReadonlySet<string>, cost?: Spend, act?: Html, work?: Work, files: readonly ConversationFile[] = [], expired: ReadonlySet<string> = new Set(), undone: ReadonlySet<string> = new Set(), refs?: (n: number) => string | undefined, voice?: Voice): Html {
246 export function turnHtml(turn: Turn, waiting: ReadonlySet<string>, cost?: Spend, act?: Html, work?: Work, files: readonly ConversationFile[] = [], expired: ReadonlySet<string> = new Set(), undone: ReadonlySet<string> = new Set(), refs?: (n: number) => string | undefined, voice?: Voice, look?: TalkLook): Html {
235247 const id = `t-${turn.id}`;
236248 const set = turn.replaced ? " talk-replaced" : "";
237249 const acts = act === undefined ? null : html`<div class="talk-acts">${act}</div>`;
@@ -249,7 +261,7 @@ export function turnHtml(turn: Turn, waiting: ReadonlySet<string>, cost?: Spend,
249261 </li>`;
250262 if (turn.role === "agent")
251263 return html`<li class="talk-turn talk-agent${set}" id="${id}">
252 <div class="talk-body prose">${agentHtml(turn, voice, (md) => (refs === undefined ? md : linkRefs(md, refs)))}</div>
264 <div class="talk-body prose">${agentHtml(turn, voice, linkedOf(refs, look))}</div>
253265 ${work === undefined ? null : workHtml(work)}
254266 ${label("Forge")}
255267 ${cost === undefined ? null : costLine(cost)}${acts}
@@ -437,6 +449,8 @@ async function talkPage(ctx: Ctx, conversation: Conversation, before0: string |
437449 const cited = repoOf(turns);
438450 const refs = refTarget(ctx.app.db, user, cited);
439451 const voice = voiceOf(ctx.app.db, user.id, conversation.id, turns, ctx.url.origin);
452 // The forge paths the replies name, each read once for the page however often they repeat.
453 const look = talkLook(ctx.app.db, user, turns.filter((t) => t.role === "agent").map((t) => t.text), appLook(ctx.app, user));
440454 const pane = talkPane(ctx, user, cited, works, view);
441455 const body = html`<div class="talk-page"><h1 class="sr-only">Talk</h1>
442456 ${box}
@@ -456,7 +470,7 @@ async function talkPage(ctx: Ctx, conversation: Conversation, before0: string |
456470 ${turns.length === 0
457471 ? 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.
458472 <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>`
459 : turns.map((t) => turnHtml(t, waiting, costs.get(t.id), acts.get(t.id), works.get(t.id), sent.get(t.id), expired, undone, refs, voice))}
473 : turns.map((t) => turnHtml(t, waiting, costs.get(t.id), acts.get(t.id), works.get(t.id), sent.get(t.id), expired, undone, refs, voice, look))}
460474 ${!paged && running ? queuedTalk(ctx.app, user, conversation.id).map(queuedHtml) : null}
461475 </ol>
462476 <div id="end"></div>
@@ -718,7 +732,7 @@ export function talkStream(ctx: Ctx): Response {
718732 const block = liveBlock(app.db, conversation.id);
719733 const refs = refTarget(app.db, user, cited);
720734 const frame = {
721 html: block === undefined || block.text === "" ? "" : html`<div class="talk-body prose">${linkRefs(renderMarkdown(block.text), refs)}</div>`.text,
735 html: block === undefined || block.text === "" ? "" : html`<div class="talk-body prose">${linkedOf(refs, talkLook(app.db, user, [block.text], appLook(app, user)))(renderMarkdown(block.text))}</div>`.text,
722736 thinking: block?.thinking === true,
723737 tool: block?.tool === undefined ? "" : runningStep(block.tool),
724738 };
@@ -748,8 +762,9 @@ export function talkStream(ctx: Ctx): Response {
748762 if (named !== undefined) cited = named;
749763 const refs = refTarget(app.db, user, cited);
750764 const voice = voiceOf(app.db, user.id, conversation.id, fresh, ctx.url.origin);
765 const look = talkLook(app.db, user, fresh.filter((t) => t.role === "agent").map((t) => t.text), appLook(app, user));
751766 for (const turn of fresh) {
752 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, voice).text }, turn.id);
767 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, voice, look).text }, turn.id);
753768 cursor = turn.id;
754769 }
755770 // The page is told at once what the block holds after these turns, empty once it is

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs