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

Talk's agent points the pane: an app at a path, with one line of what to try there #16351

Merged opened this

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

Merged

talk/pane-steer → main 0 commits 2 threads · 2 unresolved

  • Merged. talk/pane-steer was merged into main as d05b12e.

Review

Sign in to review this change.
15 files changed +439 −18
docs/design/areas/talk.md +1
@@ -109,6 +109,7 @@ Prior art: Claude and ChatGPT (one centred column, the person's words in a quiet
109109 - `.talk-pane-bar`: the pane's bar: Preview, Code and Diff as a `.seg`, the address, Reload and Open on its own.
110110 - `.talk-addr`: the address of what runs, a muted pill: which environment (Production, Pull #N) and its host; hidden under 30rem.
111111 - `.talk-reload`: Reload the preview, an icon button drawn `js-only`.
112 - `.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.
112113 - `.talk-stage`: the frame's surface, on the card colour with a hairline; `data-busy` dims the frame while it loads again.
113114 - `.talk-stage-note`: the one line over the stage: "Updating the preview…", "Starting the preview…", "Making the first version…"; it shimmers (plain under reduced motion).
114115 - `.talk-stage-wait`: the stage with no frame yet, beside a build: the note alone, as tall as the frame will be.
docs/features/talk.md +13
@@ -236,3 +236,16 @@ A private preview signs the person in inside the frame through their own grant.
236236 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`.
237237
238238 What runs is framed from the start: a new app's starter answers seconds after it is made, so the pane frames production (until a pull's own preview answers) and the crew's block sits under the frame, which gives it room. The block says who works ("cheffry-james is working.", with the same shine Talk's own agent uses while it answers) and lists its newest eight lines: its own words (`plainThought`: the short text between its calls, trimmed to about two lines) and its steps. The block is a live region of its own, so the frame is never redrawn for the crew; a deploy that turns running reloads the frame in place, and a pull's preview that comes up while production is framed draws the page once (its origin joins `frame-src`).
239
240 ## The agent points the pane
241
242 Talk's agent opens the pane on the screen to try: `pane { repo, path?, version?, try? }` (`src/http/mcp/tools/pane.ts`). It frames that app (`version`: `preview`, the newest open pull's, else production; or `live`, production) at `path`, with one line above the frame, "Try: <try>", in plain muted text. The brief tells the agent to call it once a change it asked the crew for has deployed, at the changed screen, and when the person asks where to test.
243
244 - **The path stays on the app's own address** (`panePath`, `src/actions/talk_workspace.ts`): it starts with one `/`, and holds no `//`, scheme, `\`, `@`, control character or `..` segment, checked again once percent-decoded (`%2e%2e` too), at most 300 characters. The tool refuses another in one sentence; a stored call read back with one frames the app's root. The path goes through the app's own grant (`openEnvUrl`), so a private app opens signed in at that screen.
245 - **Only apps the person may read**: someone who may not read the repository gets `not_found`, and no pane.
246 - **The Try line is text**, escaped, never a link, at most 300 characters.
247 - **The tool answers the plain address** it frames and the Try words, never the signed address the frame enters by.
248 - **Live**: a new `pane` call in the stream draws the pane again through its Preview tab, or opens it; a frame on another origin than the page's `frame-src` draws the page once.
249 - **The terminal**: the conversation's pane (`p`) prints the same address as `Preview: <url>` and the line as `Try: <try>`.
250
251 Proof: `test/talk-pane-steer.test.ts`.
src/actions/talk_workspace.ts +54 −8
@@ -16,13 +16,14 @@ import { appPreviews, openEnvUrl } from "./apps.ts";
1616 /** What the workspace needs from the apps module: the newest open preview's pull, and an environment's address. */
1717 export interface Apps {
1818 readonly newestPull: (repo: Repo) => number | undefined;
19 readonly urlOf: (repo: Repo, env: string) => string | undefined;
19 /** `path` is one `panePath` let through: the grant a signed-in person enters by lands there. */
20 readonly urlOf: (repo: Repo, env: string, path?: string) => string | undefined;
2021 }
2122
2223 export const realApps = (app: App, user: User): Apps => ({
2324 newestPull: (repo) => appPreviews(app, user, repo)?.[0]?.number,
24 urlOf: (repo, env) => {
25 const opened = openEnvUrl(app, user, repo, env);
25 urlOf: (repo, env, path = "/") => {
26 const opened = openEnvUrl(app, user, repo, env, path);
2627 return opened.ok ? opened.value : undefined;
2728 },
2829 });
@@ -43,18 +44,63 @@ const ORIGIN = /^https?:\/\/[a-z0-9.-]+(?::\d{1,5})?(?=\/|$)/i;
4344
4445 export const originOf = (url: string): string | undefined => ORIGIN.exec(url)?.[0];
4546
46 /** The workspace `name` stands for, or undefined when it is no repository this person can read. */
47 export function workspaceOf(app: App, user: User, name: string, apps: Apps = realApps(app, user)): Workspace | undefined {
47 /**
48 * The workspace `name` stands for, or undefined when it is no repository this person can read.
49 * Pointed (`pane`): `live` frames production even while a pull's preview is open, and the address
50 * is at `path` when `panePath` lets it through, else at the app's root.
51 */
52 export function workspaceOf(app: App, user: User, name: string, apps: Apps = realApps(app, user), at: { readonly version?: PaneVersion; readonly path?: string } = {}): Workspace | undefined {
4853 const [owner, repoName, extra] = name.split("/");
4954 if (owner === undefined || repoName === undefined || extra !== undefined) return undefined;
5055 const repo = getRepo(app.db, owner, repoName);
5156 if (repo === undefined || !requireReader(app, user, repo).ok) return undefined;
5257 const pull = apps.newestPull(repo);
58 const path = at.path === undefined ? "/" : (panePath(at.path) ?? "/");
5359 // The newest pull's preview, else production: a pull the crew has just opened shows the app as it
54 // runs until its own preview answers, never an empty stage.
55 const ahead = pull === undefined ? undefined : apps.urlOf(repo, previewEnv(pull));
60 // runs until its own preview answers, never an empty stage. Pointed at `live`, production.
61 const ahead = pull === undefined || at.version === "live" ? undefined : apps.urlOf(repo, previewEnv(pull), path);
5662 const shows = ahead === undefined ? undefined : pull;
57 const found = ahead ?? apps.urlOf(repo, "production");
63 const found = ahead ?? apps.urlOf(repo, "production", path);
5864 const origin = found === undefined ? undefined : originOf(found);
5965 return { name, repo, pull, shows, url: origin === undefined ? undefined : found, origin };
6066 }
67
68 /** Which of an app's versions the pane frames: the newest open pull's preview, or production. */
69 export type PaneVersion = "preview" | "live";
70
71 /**
72 * Where the agent pointed the pane (the `pane` tool): a path on the app's own address, and what to
73 * try there.
74 */
75 export interface PaneSteer {
76 readonly repo: string;
77 readonly path: string;
78 readonly version: PaneVersion;
79 readonly try: string;
80 }
81
82 export const PANE_PATH_REFUSAL =
83 "A path in the pane is a path on the app's own address: it starts with one /, and holds no .., \\, @, // or scheme.";
84
85 /** At most this many characters of "Try: …" above the frame. */
86 export const TRY_MAX = 300;

Add the how-to for the pane tool and its path rules in docs/features/talk.md (not README), including the terminal's Try line.

87
88 /**
89 * `raw` as a path on the app's own address, or undefined when it could leave it: one leading `/`,
90 * none of `\`, `@`, control characters or a `..` segment, read again once percent-decoded.
91 */
92 export function panePath(raw: string): string | undefined {
93 if (raw.length > 300 || !raw.startsWith("/") || /\s/.test(raw)) return undefined;
94 let decoded: string;
95 try {
96 decoded = decodeURIComponent(raw);
97 } catch {
98 return undefined;
99 }
100 for (const s of [raw, decoded]) {
101 if (s.startsWith("//") || /[\\@\u0000-\u001f\u007f]/.test(s)) return undefined;
102 // The address parser reads `%2e%2e` as `..` too, so a twice-encoded one is caught here.
103 if (s.split(/[/?#]/).some((part) => part.toLowerCase().replaceAll("%2e", ".") === "..")) return undefined;
104 }
105 return raw;
106 }
src/core/talk_steps.ts +20
@@ -90,6 +90,7 @@ export function stepWords(tool: string, args: Record<string, unknown>): StepWord
9090 return path === "" ? both(`Edited a file${added}`, "Editing a file", "edit a file") : both(`Edited ${path}${added}`, `Editing ${path}`, `edit ${path}`);
9191 }
9292 const repo = cut(str(args["repo"]));
93 if (tool === "pane") return both(`Opened the preview at ${path === "" ? "/" : path}`, "Opening the preview", "open the preview");
9394 // Done names what it changed, the repository with it; running never says an argument back.
9495 if (tool === "archive" && repo !== "")
9596 return args["archived"] === false ? both(`Woke ${repo}`, "Waking a repository", `wake ${repo}`) : both(`Archived ${repo}`, "Archiving a repository", `archive ${repo}`);
@@ -171,6 +172,25 @@ export function repoOf(turns: readonly Said[]): string | undefined {
171172 return undefined;
172173 }
173174
175 /**
176 * Where the last `pane` call pointed the pane (`http/mcp/tools/pane.ts`): its repository, path,
177 * version and "Try" words, as it said them. The pane follows it only while that repository is the
178 * one the conversation works on, and checks the path again before it frames it.
179 */
180 export function steerOf(turns: readonly Said[]): { repo: string; path: string; version: "preview" | "live"; try: string } | undefined {
181 for (let i = turns.length - 1; i >= 0; i -= 1) {
182 const t = turns[i]!;
183 if (t.role !== "tool") continue;
184 const call = parseCall(t.text);
185 if (call?.tool !== "pane") continue;
186 const repo = str(call.args["repo"]);
187 if (!REPO.test(repo)) return undefined;
188 const said = str(call.args["try"]).replace(/\s+/g, " ").trim();
189 return { repo, path: str(call.args["path"]) || "/", version: call.args["version"] === "live" ? "live" : "preview", try: said.slice(0, 300) };
190 }
191 return undefined;
192 }
193
174194 /** A receipt turn's page, or undefined when the turn is not one. */
175195 const receiptHref = (text: string): string | undefined => {
176196 if (!text.startsWith("{")) return undefined;
src/crew/conversation_brief.ts +1
@@ -19,6 +19,7 @@ export const VOICE: readonly string[] = [
1919 "Be brief and direct: say the thing, then stop; no preamble, no recap of what they said, no closing summary. Be the same every time: the same ask gets the same kind of answer, in the same order (what you did or found, what it means, what is next), and the same words for the same things, so they can rely on you without rereading. Spend invention where the work needs it (a name, a design, a way round a problem) and say that you chose, never on the form of the answer.",
2020 "Show the forge's results, do not retell them: a tool answer that ends with a line naming a shown result (`Shown result c7`) can be drawn for the person as the forge returned it by writing a line that is exactly `::show c7`, at the margin, outside any code fence. Say in a sentence what it shows and what to look at; never copy its rows into prose, and say an empty result in a clause instead of showing it.",
2121 "When the person asks for a graph or a chart, or how the server, compute, usage, shipping or throughput is doing, call `show` with the widget that draws it (`compute` for the machine's CPU, memory or load; `shipping` for pulls merged per day; `checks` for checks; `show` with no widget lists them) and place its result; never describe a series in prose or say you cannot draw it before you have called `show`.",
22 "The pane beside the chat shows the app you work on; `pane` points it: once a change you asked the crew for has deployed, call `pane` with the app, the path of the changed screen and one short sentence of what to try there (\"Press Start, then lose a life\"), and do the same when they ask where to test or to see a page. Never point it at an app they did not ask about.",
2223 "When a choice is small and can be undone, pick the sensible default and do it, then say in one line what you picked and how to change it; ask only when the choices lead to work that is costly to redo or cannot be undone.",
2324 "A short message after a change is a correction to the last thing you changed (\"nah, rounder buttons\"): apply it there and keep everything else as it is.",
2425 "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.",
src/http/mcp/catalog.ts +1 −1
@@ -45,7 +45,7 @@ export const DEFAULT_TOOLS: readonly string[] = [
4545 export const TALK_TOOLS: readonly string[] = [
4646 ...DEFAULT_TOOLS,
4747 "issue", "issues", "pull", "pulls", "commits", "threads", "search", "read_file", "repo", "run_log",
48 "preview", "assigned", "health", "releases", "person", "whoami_can", "show",
48 "preview", "assigned", "health", "releases", "person", "whoami_can", "show", "pane",
4949 "close", "assign", "labels", "edit", "review", "merge", "keep_plan", "steer", "stop",
5050 "write_file", "branches", "open_pull", "new_app",
5151 ];
src/http/mcp/tools/index.ts +1
@@ -124,6 +124,7 @@ export { tool as orgs } from "./orgs.ts";
124124 export { tool as origin_apps } from "./origin_apps.ts";
125125 export { tool as origins } from "./origins.ts";
126126 export { tool as outsiders } from "./outsiders.ts";
127 export { tool as pane } from "./pane.ts";
127128 export { tool as parent_unlink } from "./parent_unlink.ts";
128129 export { tool as person } from "./person.ts";
129130 export { tool as pinned_forge } from "./pinned_forge.ts";
src/http/mcp/tools/pane.ts added +42
@@ -0,0 +1,42 @@
1 import { PANE_PATH_REFUSAL, panePath, TRY_MAX, workspaceOf } from "../../../actions/talk_workspace.ts";
2 import { bad, good, str, type Tool } from "../shared.ts";
3
4 export const tool: Tool = {
5 name: "pane",
6 doc: "`{ repo, path?, version?: \"preview\" | \"live\", try? }`: in Talk, open the pane beside the chat on that app at `path` (on its own address), with \"Try: <try>\" above it; answers the address it frames",
7 description: "Open Talk's preview pane on an app at a path, with what to try there.",
8 inputSchema: {
9 type: "object",
10 properties: {
11 repo: { type: "string" },
12 path: { type: "string" },
13 version: { type: "string", enum: ["preview", "live"] },
14 try: { type: "string" },
15 },
16 required: ["repo"],
17 },
18 writes: false,
19 run(ctx, user, args) {
20 const asked = args["version"];
21 if (asked !== undefined && asked !== "preview" && asked !== "live") return bad("invalid", "`version` is preview or live");
22 const raw = args["path"] === undefined ? "/" : str(args["path"]);
23 const path = panePath(raw);
24 if (path === undefined) return bad("invalid", PANE_PATH_REFUSAL);
25 const said = str(args["try"]).replace(/\s+/g, " ").trim();
26 if (said.length > TRY_MAX) return bad("invalid", `\`try\` is at most ${String(TRY_MAX)} characters`);
27 const ws = workspaceOf(ctx.app, user, str(args["repo"]), undefined, { version: asked === "live" ? "live" : "preview", path });
28 if (ws === undefined) return bad("not_found", "no such app or repository you may read (owner/name)");
29 // The plain address, never the signed one the pane enters by: an answer is kept in the
30 // conversation.
31 const url = ws.url === undefined || ws.origin === undefined ? undefined : `${ws.origin}${path}`;
32 const where = ws.shows === undefined ? "production" : `pull #${String(ws.shows)}'s preview`;
33 return good({
34 repo: ws.name,
35 version: ws.shows === undefined ? "live" : "preview",
36 ...(ws.shows === undefined ? {} : { pull: ws.shows }),
37 url: url ?? null,
38 try: said,
39 says: url === undefined ? `Nothing of ${ws.name} runs yet: the pane shows the crew until it does.` : `The pane shows ${where} at ${url}.${said === "" ? "" : ` Try: ${said}`}`,
40 });
41 },
42 };
src/tui/screens/talk_chats.ts +7 −3
@@ -28,7 +28,7 @@ import {
2828 } from "../../core/conversations.ts";
2929 import { conversationMarkdown } from "../../core/conversation_markdown.ts";
3030 import { publicOrigin } from "../../core/public_origin.ts";
31 import { filesOf, repoOf, stepOf } from "../../core/talk_steps.ts";
31 import { filesOf, repoOf, steerOf, stepOf } from "../../core/talk_steps.ts";
3232 import { cardsPlaced, holdsCard, plainVoice } from "../../core/talk_voice.ts";
3333 import { setTalkDisplay, talkDisplay } from "../../core/settings.ts";
3434 import { talkDisplayScreen } from "./talk_display.ts";
@@ -181,13 +181,17 @@ function chatScreen(f: Session, ctx: Ctx, chat: Conversation, hit?: string): Scr
181181 };
182182 const paneLines = (): string[] => {
183183 if (repo === undefined || f.user === undefined) return ["No repository yet."];
184 const ws = workspaceOf(f.app, f.user, repo);
184 // Where the agent pointed the pane, as the page frames it (`pane`).
185 const steer = ((s) => (s?.repo === repo ? s : undefined))(steerOf(recent));
186 const ws = workspaceOf(f.app, f.user, repo, undefined, steer ?? {});
185187 if (ws === undefined) return ["Not a repository you can see."];
186188 const files = filesOf(recent, repo);
189 const url = ws.url;
187190 return [
188191 `${repo} · ${ws.shows === undefined ? "Production" : `Pull #${String(ws.shows)}`}`,
189192 "",
190 ws.url === undefined ? "Nothing running yet." : `Preview: ${ws.url}`,
193 url === undefined ? "Nothing running yet." : `Preview: ${url}`,
194 ...(url === undefined || steer === undefined || steer.try === "" ? [] : [`Try: ${steer.try}`]),
191195 ...(ws.url === undefined ? crewLines(ws.repo.id) : []),
192196 ws.pull === undefined ? "No open pull yet." : `Diff: /${repo}/pulls/${String(ws.pull)}/files`,
193197 "",
src/web/pages/talk.ts +5 −1
@@ -79,7 +79,7 @@ import { workspaceOf } from "../../actions/talk_workspace.ts";
7979 import { buildCss, chosenTemplate, panelFor, templateChips } from "../talk_build.ts";
8080 import type { User } from "../../core/users.ts";
8181 import { chatBuildOf } from "../../core/chat_build.ts";
82 import { runningStep, stepOf, repoOf, type Step } from "../../core/talk_steps.ts";
82 import { runningStep, stepOf, repoOf, steerOf, type Step } from "../../core/talk_steps.ts";
8383 import { paneCss, VIEWS, talkPane, type View } from "./talk_preview.ts";
8484 import { TALK_KEYS, talkCss, talkJs } from "./talk_client.ts";
8585 import { liveRegionsJs } from "../client.ts";
@@ -581,6 +581,7 @@ async function talkPage(ctx: Ctx, conversation: Conversation, before0: string |
581581 // Below 900 px (56.25rem) the list and the thread take turns; ?chats=1 asks for the list.
582582 const listing = ctx.url.searchParams.get("chats") === "1";
583583 const cited = repoOf(turns);
584 const steer = steerOf(turns);
584585 const refs = refTarget(ctx.app.db, user, cited);
585586 const voice = voiceOf(ctx.app.db, user.id, conversation.id, turns, ctx.url.origin);
586587 // The forge paths the replies name, each read once for the page however often they repeat.
@@ -597,6 +598,7 @@ async function talkPage(ctx: Ctx, conversation: Conversation, before0: string |
597598 ...(wait === undefined ? {} : { wait }),
598599 ...(idle === undefined ? {} : { idle }),
599600 busy: pending || running,
601 ...(steer === undefined ? {} : { steer }),
600602 });
601603 // A tab asks for the pane alone, so it swaps in place without the page.
602604 if (ctx.url.searchParams.get("fragment") === "pane") return fragment(pane.html, { request: ctx.request });
@@ -950,6 +952,8 @@ export function talkStream(ctx: Ctx): Response {
950952 const sent = filesOfTurns(app.db, user.id, fresh.filter((t) => t.role === "person").map((t) => t.id));
951953 const named = repoOf(fresh);
952954 if (named !== undefined) cited = named;
955 // The agent pointed the pane: every tab draws it again where it was pointed.
956 if (steerOf(fresh) !== undefined) emit("pane", {});
953957 const refs = refTarget(app.db, user, cited);
954958 const voice = voiceOf(app.db, user.id, conversation.id, fresh, ctx.url.origin);
955959 const look = talkLook(app.db, user, fresh.filter((t) => t.role === "agent").map((t) => t.text), appLook(app, user));
src/web/pages/talk_client.ts +3 −1
@@ -701,6 +701,8 @@ if (root) {
701701 for (const q of JSON.parse(e.data).items) log.insertAdjacentHTML("beforeend", q.html);
702702 });
703703 source.addEventListener("running", () => { dropActs(); mode(true); log.setAttribute("aria-busy", "true"); say("The forge is answering…"); });
704 // The agent pointed the pane: its Preview tab draws it again where it points, or it opens.
705 source.addEventListener("pane", () => { const a = document.querySelector("[data-split] .talk-pane nav.seg a"); if (a) a.click(); else openPane(); });
704706 source.addEventListener("done", (e) => {
705707 log.removeAttribute("aria-busy");
706708 mode(false); dropActs(true); if (hush) hush = false; else say("The forge replied."); source.close(); source = null;
@@ -1082,7 +1084,7 @@ ${dictateJs}
10821084 const t = document.createElement("template");
10831085 t.innerHTML = await (await fetch(href + "&fragment=pane")).text();
10841086 const p = t.content.querySelector(".talk-pane");
1085 if (p) { shell.querySelector(".talk-pane").replaceWith(p); codePane(); p.querySelectorAll("[data-frame]").forEach(watchFrame); }
1087 if (p) { shell.querySelector(".talk-pane").replaceWith(p); codePane(); p.querySelectorAll("[data-frame]").forEach(watchFrame); p.dispatchEvent(new Event("forge:swapped", { bubbles: true })); }
10861088 } catch (_) { say("Could not load that; no connection."); }
10871089 });
10881090 // Code: a file opens in the pane from the blob page's own fragment; a folder fills itself in
src/web/pages/talk_preview.ts +7 −3
@@ -11,7 +11,7 @@
1111 * streaming beside it carries on.
1212 */
1313
14 import { workspaceOf, type Apps } from "../../actions/talk_workspace.ts";
14 import { workspaceOf, type Apps, type PaneSteer } from "../../actions/talk_workspace.ts";
1515 import { previewEnv } from "../../apps/data.ts";
1616 import type { User } from "../../core/users.ts";
1717 import { paneCrew, type PaneCrew, type Work } from "../../core/talk_work.ts";
@@ -52,6 +52,8 @@ export interface PaneAsk {
5252 readonly idle?: string;
5353 /** Something is under way (a preview starting, a first version being made): its words shimmer. */
5454 readonly busy?: boolean;
55 /** Where the agent pointed the pane (`pane`), followed while it names this repository. */
56 readonly steer?: PaneSteer;
5557 }
5658
5759 export async function talkPane(ctx: Ctx, user: User, name: string | undefined, works: ReadonlyMap<string, Work>, view: View = "preview", apps?: Apps, ask: PaneAsk = {}): Promise<Pane> {
@@ -62,7 +64,8 @@ export async function talkPane(ctx: Ctx, user: User, name: string | undefined, w
6264 html: html`<aside class="talk-pane" aria-label="Preview">${words}</aside>`,
6365 });
6466 if (name === undefined) return empty(emptyLine("talkRepos"));
65 const ws = workspaceOf(ctx.app, user, name, apps);
67 const steer = ask.steer?.repo === name ? ask.steer : undefined;
68 const ws = workspaceOf(ctx.app, user, name, apps, steer ?? {});
6669 if (ws === undefined) return empty(emptyLine("talkHidden"));
6770 const { pull, url } = ws;
6871 const tab = (id: View, label: string): Html => html`<a href="?pane=${id}"${view === id ? raw(' aria-current="page"') : null}>${label}</a>`;
@@ -78,7 +81,7 @@ export async function talkPane(ctx: Ctx, user: User, name: string | undefined, w
7881 ? await diffView(ctx.app, work, ask.version)
7982 : url === undefined || ask.wait !== undefined
8083 ? 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)}</div>${ask.build === undefined ? null : html`<h2 class="talk-stage-files small muted">The files it starts from</h2>${await codeView(ctx.app, work)}`}`
81 : html`<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)}`;
84 : 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)}`;
8285 // The address bar of what runs: which environment, where it lives, reload and open on its own.
8386 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>`;
8487 // Waiting, the pane is a live region on the repository's runs: a deploy that turns running swaps
@@ -149,6 +152,7 @@ export const paneCss = /* css */ `
149152 .talk-stage-files { margin: 16px 0 8px; font-size: 12.5px; font-weight: 600; }
150153 .talk-stage-note[hidden] { display: none; }
151154 .talk-crew-now:empty { display: none; }
155 .talk-try { margin: 0 0 8px; color: var(--muted-fg); overflow-wrap: anywhere; }
outdated

Principle 4/6: a filled --muted box with padding is a box around a line. Use plain color: var(--muted-fg) text, no background or padding.

152156 .talk-crew-now { display: grid; gap: 8px; justify-items: start; margin-top: 12px; }
153157 .talk-crew-now p { margin: 0; }
154158 .talk-crew-steps { display: grid; gap: 2px; overflow-wrap: anywhere; }
test/mcp-forge-protocol.test.ts +1
@@ -178,6 +178,7 @@ describe("the forge over MCP: protocol", () => {
178178 "model_ceiling",
179179 "account_verify",
180180 "outsiders",
181 "pane",
181182 "origins",
182183 "decisions_by",
183184 "archive",
test/talk-page.test.ts +1 −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(49_100);
457 expect(Buffer.byteLength(talkJs)).toBeLessThan(49_400);
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);
test/talk-pane-steer.test.ts added +282
@@ -0,0 +1,282 @@
1 /**
2 * The agent points Talk's pane (the owner, 2026-11-24: "bring the user right to where they need to
3 * test"): `pane { repo, path?, version?, try? }` opens the pane on that app at a path on its own
4 * address, with "Try: …" above the frame. The path never leaves the app's origin, someone who may
5 * not read the repository gets `not_found` and no pane, and the Try line is only ever text.
6 */
7 import { afterAll, beforeAll, describe, 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 {
12 PANE_PATH_REFUSAL,
13 panePath,
14 type Apps,
15 } from "../src/actions/talk_workspace.ts";
16 import { createRepo } from "../src/actions/repos.ts";
17 import { createApp, type App } from "../src/app.ts";
18 import type { Repo } from "../src/core/repos.ts";
19 import { steerOf, stepOf } from "../src/core/talk_steps.ts";
20 import { createToken } from "../src/core/tokens.ts";
21 import { createUser, type User } from "../src/core/users.ts";
22 import type { Ctx } from "../src/http/context.ts";
23 import { serve, type Servers } from "../src/http/server.ts";
24 import { talkPane } from "../src/web/pages/talk_preview.ts";
25 import { promote } from "./helpers/members.ts";
26
27 /** Every way out of the app's own address the pane is offered, each refused in one sentence. */
28 const HOSTILE = [
29 "//evil.com",
30 "//evil.com/x",
31 "https://evil.com",
32 "javascript:alert(1)",
33 "/../",
34 "/a/../../b",
35 "%2e%2e/",
36 "/%2e%2e/",
37 "/%2E%2E/admin",
38 "/%252e%252e/",
39 "\\evil",
40 "/\\evil.com",
41 "/%5c%5cevil.com",
42 "/[email protected]",
43 "/x%40evil.com",
44 "/a\nb",
45 "",
46 "game",
47 ];
48
49 const call = (text: string) => ({ role: "tool", text });
50
51 describe("the agent points the pane", () => {
52 let dir: string;
53 let app: App;
54 let servers: Servers;
55 let alice: User;
56 let bob: User;
57 let repo: Repo;
58 let name: string;
59 let ctx: Ctx;
60 let id = 1;
61 /**
62 * A running app: a pull's preview and production, each on its own origin; the path is where it
63 * lands.
64 */
65 const asked: { env: string; path: string | undefined }[] = [];
66 const apps: Apps = {
67 newestPull: () => 3,
68 urlOf: (_repo, env, path) => {
69 asked.push({ env, path });
70 return `https://${env}.arena.apps.test${path ?? "/"}`;
71 },
72 };
73
74 const mcp = async (
75 token: string,
76 args: Record<string, unknown>,
77 ): Promise<{ error?: string; value?: Record<string, unknown> }> => {
78 const res = await fetch(`${servers.url}/mcp`, {
79 method: "POST",
80 headers: {
81 "content-type": "application/json",
82 accept: "application/json, text/event-stream",
83 authorization: `Bearer ${token}`,
84 },
85 body: JSON.stringify({
86 jsonrpc: "2.0",
87 id: id++,
88 method: "tools/call",
89 params: { name: "pane", arguments: args },
90 }),
91 });
92 const body = (await res.json()) as {
93 result: { isError?: boolean; content: { text: string }[] };
94 };
95 const text = body.result.content[0]!.text;
96 return body.result.isError === true
97 ? { error: text }
98 : { value: JSON.parse(text) as Record<string, unknown> };
99 };
100
101 beforeAll(async () => {
102 dir = await mkdtemp(join(tmpdir(), "forge-talk-pane-steer-"));
103 app = createApp({ dataDir: dir, port: 0 });
104 servers = await serve(app);
105 const made = await createUser(app.db, {
106 origin: "seed",
107 trusted: true,
108 username: "alice",
109 email: "[email protected]",
110 password: "a-good-passphrase",
111 adminIfFirst: true,
112 });
113 if (!made.ok) throw new Error(made.error);
114 promote(app.db, made.value);
115 alice = made.value;
116 const other = await createUser(app.db, {
117 origin: "seed",
118 trusted: true,
119 username: "bob",
120 email: "[email protected]",
121 password: "a-good-passphrase",
122 });
123 if (!other.ok) throw new Error(other.error);
124 promote(app.db, other.value);
125 bob = other.value;
126 const created = await createRepo(app, alice, {
127 name: "arena",
128 visibility: "private",
129 });
130 if (!created.ok) throw new Error(String(created.error));
131 repo = created.value;
132 name = `alice/${repo.name}`;
133 ctx = { app } as Ctx;
134 });
135 afterAll(async () => {
136 servers.stop();
137 app.close();
138 await rm(dir, { recursive: true, force: true });
139 });
140
141 test("a path that could leave the app's own address is refused, each in the one sentence, through /mcp", async () => {
142 const token = createToken(app.db, alice.id, "t", "rw").token;
143 for (const path of HOSTILE) {
144 expect([path, panePath(path)]).toEqual([path, undefined]);
145 const said = await mcp(token, { repo: name, path });
146 expect([path, said.error ?? "answered"]).toEqual([
147 path,
148 expect.stringContaining(PANE_PATH_REFUSAL),
149 ]);
150 }
151 for (const path of [
152 "/",
153 "/play",
154 "/play/level-2?lives=3#start",
155 "/files/a%20b.txt",
156 ])
157 expect(panePath(path)).toBe(path);
158 });
159
160 test("someone who may not read the repository gets not_found through /mcp, and no pane", async () => {
161 const said = await mcp(createToken(app.db, bob.id, "t", "rw").token, {
162 repo: name,
163 path: "/play",
164 try: "Press Start",
165 });
166 expect(said.error).toContain("not_found");
167 const p = await talkPane(ctx, bob, name, new Map(), "preview", apps, {
168 steer: {
169 repo: name,
170 path: "/play",
171 version: "preview",
172 try: "Press Start",
173 },
174 });
175 expect([p.frame, p.live]).toEqual([undefined, false]);
176 expect(p.html.text).not.toContain("Press Start");
177 expect(p.html.text).not.toContain("<iframe");
178 });
179
180 test("a reader is answered the plain address it frames, and what to try", async () => {
181 const said = await mcp(createToken(app.db, alice.id, "t", "rw").token, {
182 repo: name,
183 path: "/play",
184 try: "Press Start",
185 });
186 // No app runs here: it says so, and points nowhere else.
187 expect(said.value).toMatchObject({
188 repo: name,
189 url: null,
190 try: "Press Start",
191 });
192 const long = await mcp(createToken(app.db, alice.id, "t", "rw").token, {
193 repo: name,
194 try: "x".repeat(301),
195 });
196 expect(long.error).toContain("at most 300 characters");
197 });
198
199 test("the pane frames the app at that path, preview or live, with the Try line as text only and never a link", async () => {
200 asked.length = 0;
201 const hostile =
202 'Press <a href="https://evil.com">Start</a> <img src=x onerror=alert(1)>';
203 const p = await talkPane(ctx, alice, name, new Map(), "preview", apps, {
204 steer: {
205 repo: name,
206 path: "/play/level-2",
207 version: "preview",
208 try: hostile,
209 },
210 });
211 expect(asked).toEqual([{ env: "pull-3", path: "/play/level-2" }]);
212 expect(p.frame).toBe("https://pull-3.arena.apps.test");
213 const text = p.html.text;
214 expect(text).toContain('src="https://pull-3.arena.apps.test/play/level-2"');
215 const line =
216 /<p class="talk-try small" data-pane-try>([\s\S]*?)<\/p>/.exec(
217 text,
218 )?.[1] ?? "";
219 expect(line).toBe(
220 "Try: Press &lt;a href=&quot;https://evil.com&quot;&gt;Start&lt;/a&gt; &lt;img src=x onerror=alert(1)&gt;",
221 );
222 expect(line).not.toContain("<a");
223 // The Try line sits above the frame.
224 expect(text.indexOf("data-pane-try")).toBeLessThan(text.indexOf("<iframe"));
225 asked.length = 0;
226 const live = await talkPane(ctx, alice, name, new Map(), "preview", apps, {
227 steer: { repo: name, path: "/", version: "live", try: "" },
228 });
229 expect(asked).toEqual([{ env: "production", path: "/" }]);
230 expect(live.html.text).toContain("Production");
231 expect(live.html.text).not.toContain("data-pane-try");
232 });
233
234 test("a path the page reads back that would leave the origin frames the app's root instead", async () => {
235 asked.length = 0;
236 await talkPane(ctx, alice, name, new Map(), "preview", apps, {
237 steer: { repo: name, path: "//evil.com", version: "preview", try: "x" },
238 });
239 expect(asked).toEqual([{ env: "pull-3", path: "/" }]);
240 });
241
242 test("the pane follows the newest pane call only while it names the repository the pane is on", async () => {
243 const steer = steerOf([
244 call(`pane ${JSON.stringify({ repo: "alice/old", path: "/a" })}`),
245 call(`read_file ${JSON.stringify({ repo: name, path: "x" })}`),
246 call(
247 `mcp__forge__pane ${JSON.stringify({ repo: name, path: "/play", version: "live", try: "Lose a\nlife" })}`,
248 ),
249 ]);
250 expect(steer).toEqual({
251 repo: name,
252 path: "/play",
253 version: "live",
254 try: "Lose a life",
255 });
256 expect(
257 steerOf([call(`read_file ${JSON.stringify({ repo: name, path: "x" })}`)]),
258 ).toBeUndefined();
259 asked.length = 0;
260 const elsewhere = await talkPane(
261 ctx,
262 alice,
263 name,
264 new Map(),
265 "preview",
266 apps,
267 {
268 steer: {
269 repo: "alice/other",
270 path: "/admin",
271 version: "live",
272 try: "Look",
273 },
274 },
275 );
276 expect(asked).toEqual([{ env: "pull-3", path: "/" }]);
277 expect(elsewhere.html.text).not.toContain("data-pane-try");
278 expect(
279 stepOf(`pane ${JSON.stringify({ repo: name, path: "/play" })}`)?.label,
280 ).toBe("Opened the preview at /play");
281 });
282 });

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs