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

opened this

Merged 17h 39m ago, live in production

talk-pane-own → main 0 commits 2 threads · 2 unresolved

  • Merged. talk-pane-own was merged into main as 18aeb4d.

Review

Sign in to review this change.
5 files changed +58 −20
src/core/empty_words.ts +1 −1
@@ -50,7 +50,7 @@ const TABLE = {
5050 refused: { sentence: "No first ask has been refused." },
5151 databases: { sentence: "No database yet.", reason: "An app's SQLite files appear here once it has written one under its data directory." },
5252 rows: { sentence: "No rows." },
53 talkRepos: { sentence: "No repository yet." },
53 talkRepos: { sentence: "No app in this conversation yet." },
5454 talkFiles: { sentence: "No files touched yet." },
5555 talkPulls: { sentence: "No open pull yet." },
5656 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 {
156156 return `${cut(running ?? `Working: ${call.tool.replaceAll("_", " ")}`).replace(/…$/, "")}…`;
157157 }
158158
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 {
161165 for (let i = turns.length - 1; i >= 0; i -= 1) {
162166 const t = turns[i]!;
163167 if (t.role !== "tool") continue;
164 const repo = parseCall(t.text)?.args["repo"];
168 const repo = calls ? parseCall(t.text)?.args["repo"] : undefined;
165169 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.
168170 const href = receiptHref(t.text);
169171 const named = href === undefined ? undefined : /^\/([^/]+\/[^/]+)(?:\/|$)/.exec(href)?.[1];
170172 if (named !== undefined && REPO.test(named)) return named;
@@ -172,6 +174,17 @@ export function repoOf(turns: readonly Said[]): string | undefined {
172174 return undefined;
173175 }
174176
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
175188 /**
176189 * Where the last `pane` call pointed the pane (`http/mcp/tools/pane.ts`): its repository, path,
177190 * 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
8686 import { buildCss, chosenTemplate, panelFor, templateChips } from "../talk_build.ts";
8787 import type { User } from "../../core/users.ts";
8888 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";
9090 import { paneCss, VIEWS, talkPane, type View } from "./talk_preview.ts";
9191 import { TALK_KEYS, talkCss, talkJs } from "./talk_client.ts";
9292 import { modelForm, modelPicker } from "../talk_model.ts";
@@ -639,7 +639,10 @@ async function talkPage(ctx: Ctx, conversation: Conversation, before0: string |
639639 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.";
640640 // The address bar's choice (`?repo=&show=&path=`): a repository it offers this person, else the
641641 // conversation's own; the page names in `frame-src` exactly the origins it offers.
outdated

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.

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}`;
643646 const offer = paneOffer(ctx.app, user, worksOn);
644647 const at = paneChoice(ctx.app.db, offer, paneAtOf(ctx.url.searchParams), worksOn);
645648 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";
2828 import { createIssue } from "../src/core/issues.ts";
2929 import { addTeamMember, createOrg, createTeam } from "../src/core/orgs.ts";
3030 import { getRepo, type Repo } from "../src/core/repos.ts";
31 import { startChatBuild } from "../src/core/chat_build.ts";
3132 import { createRun } from "../src/core/runs.ts";
3233 import { createSession } from "../src/core/sessions.ts";
3334 import { conversationPulls, paneInfo } from "../src/core/talk_work.ts";
@@ -139,6 +140,8 @@ const talkOn = (who: User, repo: string, receipt?: number): string => {
139140 }),
140141 });
141142 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);
142145 createRun(app.db, {
143146 repoId: getRepo(app.db, repo.split("/")[0]!, repo.split("/")[1]!)!.id,
144147 kind: "agent",
@@ -166,6 +169,23 @@ const page = async (
166169 };
167170 };
168171
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;
outdated

The comment says a receipt naming the app also makes the pane that app's, but only the pane-call path is asserted. Add the receipt-only and ?about=-only cases, or the receipt branch of ownAppOf can be deleted with the suite staying green.

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
169189 describe("the pane's dev server button (#17140)", () => {
170190 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 () => {
171191 const mine = (await page(alice, talkOn(alice, "alice/two"))).html;
@@ -392,15 +412,13 @@ describe("Diff", () => {
392412 const diff = (await page(alice, filed, "?pane=diff&fragment=pane")).html;
393413 expect(diff).toContain(`#${String(closes.value.number)}</a> Footer, again`);
394414 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.");
404422 expect(about).not.toContain("A footer");
405423 });
406424
test/talk-preview-frame.test.ts +7 −3
@@ -18,7 +18,8 @@ import { AppsRuntime } from "../src/apps/runtime.ts";
1818 import { getAppByRepo } from "../src/core/apps.ts";
1919 import { getRepo } from "../src/core/repos.ts";
2020 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";
2223 import { createSession } from "../src/core/sessions.ts";
2324 import { createUser, type User } from "../src/core/users.ts";
2425 import { findChromium } from "../src/looks/capture.ts";
@@ -48,9 +49,12 @@ let bob: User;
4849 const cookies: Record<string, string> = {};
4950
5051 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);
5257 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" })}` });
5458 appendTurn(app.db, userId, chat.id, { role: "agent", text: "Here it is." });
5559 };
5660

Search
↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs