Public: anyone can read this; the crew can change it.
Talk: the Preview pane shows the conversation's own work, or nothing yet, never a repository it only read #17517
Merged 17h 39m ago, live in production
talk-pane-own → main 0 commits 2 threads · 2 unresolved
5 files
changed +58
−20
src/core/empty_words.ts +1 −1
| @@ -50,7 +50,7 @@ const TABLE = { | ||
| 50 | 50 | refused: { sentence: "No first ask has been refused." }, |
| 51 | 51 | databases: { sentence: "No database yet.", reason: "An app's SQLite files appear here once it has written one under its data directory." }, |
| 52 | 52 | rows: { sentence: "No rows." }, |
| 53 | talkRepos: { sentence: "No repository yet." }, | |
| 53 | talkRepos: { sentence: "No app in this conversation yet." }, | |
| 54 | 54 | talkFiles: { sentence: "No files touched yet." }, |
| 55 | 55 | talkPulls: { sentence: "No open pull yet." }, |
| 56 | 56 | talkHidden: { sentence: "Not a repository you can see." }, |
src/core/talk_steps.ts +18 −5
| @@ -156,15 +156,17 @@ export function runningStep(text: string): string { | ||
| 156 | 156 | return `${cut(running ?? `Working: ${call.tool.replaceAll("_", " ")}`).replace(/…$/, "")}…`; |
| 157 | 157 | } |
| 158 | 158 | |
| 159 | /** The repository the last call that named a good one worked on. */ | |
| 160 | export function repoOf(turns: readonly Said[]): string | undefined { | |
| 159 | /** | |
| 160 | * The newest repository the turns name: by a receipt's page (`/owner/name`, or an issue of it), | |
| 161 | * and, with `calls`, by a call's `repo` too. A new app has no call that names it, only the receipt | |
| 162 | * of the call that made it. | |
| 163 | */ | |
| 164 | function lastRepo(turns: readonly Said[], calls: boolean): string | undefined { | |
| 161 | 165 | for (let i = turns.length - 1; i >= 0; i -= 1) { |
| 162 | 166 | const t = turns[i]!; |
| 163 | 167 | if (t.role !== "tool") continue; |
| 164 | const repo = parseCall(t.text)?.args["repo"]; | |
| 168 | const repo = calls ? parseCall(t.text)?.args["repo"] : undefined; | |
| 165 | 169 | if (typeof repo === "string" && REPO.test(repo)) return repo; |
| 166 | // A receipt names its repository by its page (`/owner/name`, or an issue of it): a new app has no | |
| 167 | // call that names it, only the receipt of the call that made it. | |
| 168 | 170 | const href = receiptHref(t.text); |
| 169 | 171 | const named = href === undefined ? undefined : /^\/([^/]+\/[^/]+)(?:\/|$)/.exec(href)?.[1]; |
| 170 | 172 | if (named !== undefined && REPO.test(named)) return named; |
| @@ -172,6 +174,17 @@ export function repoOf(turns: readonly Said[]): string | undefined { | ||
| 172 | 174 | return undefined; |
| 173 | 175 | } |
| 174 | 176 | |
| 177 | /** The repository the last call that named a good one worked on. */ | |
| 178 | export const repoOf = (turns: readonly Said[]): string | undefined => lastRepo(turns, true); | |
| 179 | ||
| 180 | /** | |
| 181 | * The repository this conversation's own work is on, newest first: the app it created (its | |
| 182 | * `new_app` receipt) or one it filed work on for the crew (that receipt's issue). Naming or reading | |
| 183 | * a repository in a call does not make it the conversation's; a talk branch does, and that is the | |
| 184 | * build (`core/chat_build.ts`), read beside this. | |
| 185 | */ | |
| 186 | export const ownAppOf = (turns: readonly Said[]): string | undefined => lastRepo(turns, false); | |
| 187 | ||
| 175 | 188 | /** |
| 176 | 189 | * Where the last `pane` call pointed the pane (`http/mcp/tools/pane.ts`): its repository, path, |
| 177 | 190 | * version and "Try" words, as it said them. The pane follows it only while that repository is the |
src/web/pages/talk.ts +5 −2
| @@ -86,7 +86,7 @@ import { paneAtOf, paneChoice, paneOffer, paneQuery, workspaceOf } from "../../a | ||
| 86 | 86 | import { buildCss, chosenTemplate, panelFor, templateChips } from "../talk_build.ts"; |
| 87 | 87 | import type { User } from "../../core/users.ts"; |
| 88 | 88 | import { chatBuildOf } from "../../core/chat_build.ts"; |
| 89 | import { receiptIssues, runningStep, stepOf, repoOf, steerOf, type Step } from "../../core/talk_steps.ts"; | |
| 89 | import { ownAppOf, receiptIssues, runningStep, stepOf, repoOf, steerOf, type Step } from "../../core/talk_steps.ts"; | |
| 90 | 90 | import { paneCss, VIEWS, talkPane, type View } from "./talk_preview.ts"; |
| 91 | 91 | import { TALK_KEYS, talkCss, talkJs } from "./talk_client.ts"; |
| 92 | 92 | import { modelForm, modelPicker } from "../talk_model.ts"; |
| @@ -639,7 +639,10 @@ async function talkPage(ctx: Ctx, conversation: Conversation, before0: string | | ||
| 639 | 639 | const idle = panel === null ? undefined : running ? "Making the first version. The preview shows here once it is built, and each version after it reloads in place." : "Your app shows here once its first version is made: say what to change and the crew makes it. Below are the files it starts from."; |
| 640 | 640 | // The address bar's choice (`?repo=&show=&path=`): a repository it offers this person, else the |
| 641 | 641 | // conversation's own; the page names in `frame-src` exactly the origins it offers. |
| 642 | const worksOn = builtRepo === undefined ? cited : `${builtRepo.ownerName}/${builtRepo.name}`; | |
| 642 | // Only the conversation's own app: the one it has a talk branch on (its build), created, or filed | |
| 643 | // work on, or the app an invitee's first open names (`?about=`); never one it only named, read or | |
| 644 | // pointed the pane at, such as the forge's own repository. Else there is no app in it yet. | |
| 645 | const worksOn = builtRepo === undefined ? (ownAppOf(turns) ?? aboutRepo(ctx.url.searchParams.get("about"))) : `${builtRepo.ownerName}/${builtRepo.name}`; | |
| 643 | 646 | const offer = paneOffer(ctx.app, user, worksOn); |
| 644 | 647 | const at = paneChoice(ctx.app.db, offer, paneAtOf(ctx.url.searchParams), worksOn); |
| 645 | 648 | const paneRepo = at.repo ?? worksOn; |
test/talk-pane-bar.test.ts +27 −9
| @@ -28,6 +28,7 @@ import { appendTurn, createConversation } from "../src/core/conversations.ts"; | ||
| 28 | 28 | import { createIssue } from "../src/core/issues.ts"; |
| 29 | 29 | import { addTeamMember, createOrg, createTeam } from "../src/core/orgs.ts"; |
| 30 | 30 | import { getRepo, type Repo } from "../src/core/repos.ts"; |
| 31 | import { startChatBuild } from "../src/core/chat_build.ts"; | |
| 31 | 32 | import { createRun } from "../src/core/runs.ts"; |
| 32 | 33 | import { createSession } from "../src/core/sessions.ts"; |
| 33 | 34 | import { conversationPulls, paneInfo } from "../src/core/talk_work.ts"; |
| @@ -139,6 +140,8 @@ const talkOn = (who: User, repo: string, receipt?: number): string => { | ||
| 139 | 140 | }), |
| 140 | 141 | }); |
| 141 | 142 | appendTurn(app.db, who.id, chat.value.id, { role: "agent", text: "On it." }); |
| 143 | // Its app: the work it filed there, or else the talk branch it builds on. | |
| 144 | if (receipt === undefined) startChatBuild(app.db, chat.value.id, getRepo(app.db, repo.split("/")[0]!, repo.split("/")[1]!)!.id); | |
| 142 | 145 | createRun(app.db, { |
| 143 | 146 | repoId: getRepo(app.db, repo.split("/")[0]!, repo.split("/")[1]!)!.id, |
| 144 | 147 | kind: "agent", |
| @@ -166,6 +169,23 @@ const page = async ( | ||
| 166 | 169 | }; |
| 167 | 170 | }; |
| 168 | 171 | |
| 172 | describe("whose app the pane shows", () => { | |
| 173 | test("a repository the conversation only read is not its app: a new conversation's pane shows nothing yet, never that repository's crew run", async () => { | |
| 174 | const chat = createConversation(app.db, alice.id); | |
| 175 | if (!chat.ok) throw new Error(chat.error); | |
| 176 | appendTurn(app.db, alice.id, chat.value.id, { role: "person", text: "build me a tiny page that says hello" }); | |
| 177 | appendTurn(app.db, alice.id, chat.value.id, { role: "tool", text: `mcp__forge__read_file ${JSON.stringify({ repo: "alice/two", path: "README.md" })}` }); | |
| 178 | appendTurn(app.db, alice.id, chat.value.id, { role: "agent", text: "Making a new app waits on your yes." }); | |
| 179 | // Pointing the pane at it is naming it too: still not its app. | |
| 180 | appendTurn(app.db, alice.id, chat.value.id, { role: "tool", text: `mcp__forge__pane ${JSON.stringify({ repo: "alice/two" })}` }); | |
| 181 | const html = (await page(alice, chat.value.id, "?pane=preview")).html; | |
| 182 | expect(html).not.toContain('data-pane-of="alice/two"'); | |
| 183 | expect(html).not.toContain("Start dev server"); | |
| 184 | // Once it has a talk branch there, or filed work on it, the pane is that app's. | |
| 185 | expect((await page(alice, talkOn(alice, "alice/two"), "?pane=preview")).html).toContain('data-pane-of="alice/two"'); | |
| 186 | }); | |
| 187 | }); | |
| 188 | ||
| 169 | 189 | describe("the pane's dev server button (#17140)", () => { |
| 170 | 190 | test("a writer of an app is offered Start dev server, a reader is not; while a cell is live the frame is sandboxed without same-origin and the page says what it cannot do", async () => { |
| 171 | 191 | const mine = (await page(alice, talkOn(alice, "alice/two"))).html; |
| @@ -392,15 +412,13 @@ describe("Diff", () => { | ||
| 392 | 412 | const diff = (await page(alice, filed, "?pane=diff&fragment=pane")).html; |
| 393 | 413 | expect(diff).toContain(`#${String(closes.value.number)}</a> Footer, again`); |
| 394 | 414 | expect(diff).toContain(`#${String(pr.value.number)}</a> A footer`); |
| 395 | // Captain-style: a conversation about the repository that filed nothing on it. | |
| 396 | const about = ( | |
| 397 | await page( | |
| 398 | alice, | |
| 399 | talkOn(alice, "team/shared"), | |
| 400 | "?pane=diff&fragment=pane", | |
| 401 | ) | |
| 402 | ).html; | |
| 403 | expect(about).toContain("Pick a pull above to see its change."); | |
| 415 | // Captain-style: a conversation that only read the repository and filed nothing on it has no | |
| 416 | // app, so no pane of that repository's work. | |
| 417 | const chat = createConversation(app.db, alice.id); | |
| 418 | if (!chat.ok) throw new Error(chat.error); | |
| 419 | appendTurn(app.db, alice.id, chat.value.id, { role: "tool", text: `mcp__forge__read_file ${JSON.stringify({ repo: "team/shared", path: "README.md" })}` }); | |
| 420 | const about = (await page(alice, chat.value.id, "?pane=diff&fragment=pane")).html; | |
| 421 | expect(about).toContain("No app in this conversation yet."); | |
| 404 | 422 | expect(about).not.toContain("A footer"); |
| 405 | 423 | }); |
| 406 | 424 |
test/talk-preview-frame.test.ts +7 −3
| @@ -18,7 +18,8 @@ import { AppsRuntime } from "../src/apps/runtime.ts"; | ||
| 18 | 18 | import { getAppByRepo } from "../src/core/apps.ts"; |
| 19 | 19 | import { getRepo } from "../src/core/repos.ts"; |
| 20 | 20 | import { createApp, type App } from "../src/app.ts"; |
| 21 | import { appendTurn, openConversation } from "../src/core/conversations.ts"; | |
| 21 | import { appendTurn, createConversation } from "../src/core/conversations.ts"; | |
| 22 | import { startChatBuild } from "../src/core/chat_build.ts"; | |
| 22 | 23 | import { createSession } from "../src/core/sessions.ts"; |
| 23 | 24 | import { createUser, type User } from "../src/core/users.ts"; |
| 24 | 25 | import { findChromium } from "../src/looks/capture.ts"; |
| @@ -48,9 +49,12 @@ let bob: User; | ||
| 48 | 49 | const cookies: Record<string, string> = {}; |
| 49 | 50 | |
| 50 | 51 | const talkFor = (userId: string, repo: string): void => { |
| 51 | const chat = openConversation(app.db, userId); | |
| 52 | const made = createConversation(app.db, userId); | |
| 53 | if (!made.ok) throw new Error(made.error); | |
| 54 | const chat = made.value; | |
| 55 | const [owner = "", name = ""] = repo.split("/"); | |
| 56 | startChatBuild(app.db, chat.id, getRepo(app.db, owner, name)!.id); | |
| 52 | 57 | appendTurn(app.db, userId, chat.id, { role: "person", text: "show me the app" }); |
| 53 | appendTurn(app.db, userId, chat.id, { role: "tool", text: `read_file ${JSON.stringify({ repo, path: "README.md" })}` }); | |
| 54 | 58 | appendTurn(app.db, userId, chat.id, { role: "agent", text: "Here it is." }); |
| 55 | 59 | }; |
| 56 | 60 |
new above
offline
Two comments now stack for one line and say the same thing. Keep the new one, which is the more exact, and drop the older line above it.