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

The studio tells a visitor that a person's change was made by "the crew" #243

Closed opened this
Closed without merging

mason/forge:mason/206-the-studio-tells-a-visitor-that-a-person → main 3 commits fork

  • Closed without merging. Nothing was applied to main.

Review

Sign in to review this change.
8 files changed +338 −38
docs/STUDIO.md +11
@@ -127,6 +127,17 @@ coming up — but by "the crew" rather than an agent's own name, and never
127127 with a run's cost, turns or steer box. A private repository is unaffected:
128128 it already answers only to people who can read it at all.
129129
130 **Whose name a row carries** is one rule, in one place — `voiceFor`
131 (`src/web/studio/voice.ts`), which the app's page, a run's own page and the
132 board all sign their rows with. An agent's name is *not* a secret: a
133 change's own page and `/changes` name the agent that opened it to anyone
134 who can read the repository. "The crew" is a voice, not a redaction, and it
135 is chosen by **what the actor is** first: a person is named to every viewer
136 who can see the row at all, so one visitor reads one name for one change on
137 all three pages, avatar included; only an agent's own work — a run, a
138 change it opened, a tell it holds — reads as the crew's for a viewer who
139 cannot see the roster. Nothing here decides whether a row is visible.
140
130141 **The terminal** is the same operator's door, so it sits beside the same
131142 facts: a writer sees the exact `ssh …` command production answers to,
132143 copyable, with the forge's host key fingerprint beside it, or one line
src/web/pages/board.ts +16 −8
@@ -30,6 +30,7 @@ import { boardJs, liveRegionsJs } from "../client.ts";
3030 import { html, when, type Html } from "../html.ts";
3131 import { page } from "../layout.ts";
3232 import { avatar, icon, time } from "../ui.ts";
33 import { voiceFor } from "../studio/voice.ts";
3334 import { lookUrl, thumbLook } from "./looks.ts";
3435
3536 // ---- words ----
@@ -210,13 +211,17 @@ function working(ctx: Ctx, scope: Scope): Html {
210211 );
211212 const rows = runs.map((run) => {
212213 const repo = scope.byId.get(run.repoId)!;
213 // Who is on the crew is an owner's fact — a repo this viewer can only
214 // read reads here as the app's own story, never by the agent's name.
215 const actorName =
216 run.actorId === null
217 ? "crew"
218 : (actors.get(run.actorId)?.username ?? "crew");
219 const who = scope.ownerFacts.has(repo.id) ? actorName : "the crew";
214 // The same rule the app's page signs its rows by, `voiceFor`
215 // (`studio/voice.ts`): the crew's own work reads as the app's own story
216 // for a viewer who cannot see the roster; a person is always named.
217 const actor = run.actorId === null ? undefined : actors.get(run.actorId);
218 const who = voiceFor(
219 {
220 name: actor?.username,
221 isAgent: actor === undefined || actor.kind === "agent",
222 },
223 scope.ownerFacts.has(repo.id),
224 );
220225 const issue = run.issueId === null ? undefined : about.get(run.issueId);
221226 const word = stateWord(run);
222227 return html`<li>
@@ -284,7 +289,10 @@ function landed(ctx: Ctx, scope: Scope): Html {
284289 const rows = pulls.map((pull: Pull) => {
285290 const repo = scope.byId.get(pull.repoId)!;
286291 const picture = pictureOf(repo);
287 const author = scope.ownerFacts.has(repo.id) ? pull.authorName : "the crew";
292 const author = voiceFor(
293 { name: pull.authorName, isAgent: pull.authorIsAgent },
294 scope.ownerFacts.has(repo.id),
295 );
288296 return html`<li>
289297 <a
290298 class="board-card board-landed"
src/web/studio/app.ts +23 −14
@@ -23,6 +23,7 @@ import {
2323 listRuns,
2424 previewLatency,
2525 type PreviewLatency,
26 type Run,
2627 } from "../../core/runs.ts";
2728 import { getUsersByIds } from "../../core/users.ts";
2829 import { autonomyStatus } from "../../crew/autonomy.ts";
@@ -55,6 +56,7 @@ import {
5556 import { LOG_TAIL_CAP, logBox } from "./log.ts";
5657 import { appPanels } from "./previews.ts";
5758 import { stopForm } from "./run.ts";
59 import { voiceFor, type Actor } from "./voice.ts";
5860 import { pullWord, runWord, wordBadge, type WordCtx } from "./words.ts";
5961
6062 /**
@@ -276,10 +278,17 @@ export async function studioApp(
276278 (r, idx, all) => all.findIndex((x) => x.issueId === r.issueId) === idx,
277279 )
278280 .slice(0, 6);
279 // Who is on the crew is an owner's fact same as its roster card — a
280 // viewer who cannot write here reads "Now" as the app's own story, never
281 // by the agent's name.
282 const nameFor = (name: string): string => (ownerFacts ? name : "the crew");
281 // Who signs a "Now" row is the one rule for it, `voiceFor`
282 // (`studio/voice.ts`): a person is named to anyone who can see the row —
283 // the same name `/changes` and the change's own page give — and only the
284 // crew's own work reads as the app's own story for a viewer who cannot
285 // see the roster. The avatar takes the same string, so its initials can
286 // never disagree with the name beside them.
287 const runActor = (r: Run): Actor => ({
288 name: r.actorId === null ? undefined : actors.get(r.actorId)?.username,
289 // A run with nobody on it is the crew's own, never a person's.
290 isAgent: r.actorId === null || actors.get(r.actorId)?.kind === "agent",
291 });
283292
284293 // The one run actually going, if any: its row gets a tail of its own
285294 // log — the last handful of lines, streamed live — beside it. Only one,
@@ -290,11 +299,7 @@ export async function studioApp(
290299 const activeTail = activeRun
291300 ? logBox({
292301 id: "app-run-tail",
293 who: nameFor(
294 activeRun.actorId === null
295 ? "crew"
296 : (actors.get(activeRun.actorId)?.username ?? "crew"),
297 ),
302 who: voiceFor(runActor(activeRun), ownerFacts),
298303 cap: LOG_TAIL_CAP,
299304 lines: readRunLogTail(ctx.app.config.dataDir, activeRun.id, LOG_TAIL_CAP)
300305 .lines,
@@ -306,9 +311,7 @@ export async function studioApp(
306311 const runRows: Html[] = [];
307312 for (const r of rowsNow) {
308313 const { word, note } = await runWord(wordCtx, r);
309 const who = nameFor(
310 r.actorId === null ? "crew" : (actors.get(r.actorId)?.username ?? "crew"),
311 );
314 const who = voiceFor(runActor(r), ownerFacts);
312315 const about = r.issueId === null ? undefined : issues.get(r.issueId);
313316 const stop = stopForm(ctx, repo, r);
314317 runRows.push(
@@ -337,7 +340,10 @@ export async function studioApp(
337340 ...(await Promise.all(
338341 openPulls.map(async (p) => {
339342 const { word, note } = await pullWord(wordCtx, p);
340 const who = nameFor(p.authorName);
343 const who = voiceFor(
344 { name: p.authorName, isAgent: p.authorIsAgent },
345 ownerFacts,
346 );
341347 return row({
342348 href: changeHref(base, p.number),
343349 nav: true,
@@ -350,7 +356,10 @@ export async function studioApp(
350356 )),
351357 ...runRows,
352358 ...waiting.map((i) => {
353 const who = nameFor(i.assigneeName ?? "crew");
359 const who = voiceFor(
360 { name: i.assigneeName ?? undefined, isAgent: i.assigneeIsAgent },
361 ownerFacts,
362 );
354363 return row({
355364 href: tellHref(base, i.number),
356365 nav: true,
src/web/studio/log.ts +8 −7
@@ -9,23 +9,24 @@
99 import type { RunKind } from "../../core/runs.ts";
1010 import { logLine } from "../pages/runs.ts";
1111 import { html, when, type Html } from "../html.ts";
12 import { unnamedRun, voiceFor, type Actor } from "./voice.ts";
1213
1314 /**
1415 * Who speaks a run's own transcript: a deploy or a check speaks for itself
15 * — never "an agent", which is a name for nobody — and only an agent's run
16 * is named for the agent on it, or "the crew" for a reader who cannot see
17 * who that is. The one place this is decided, so a run's own page and the
18 * tail beside a running row (`studio/previews.ts`) never choose two voices
19 * for the same lines.
16 * — never "an agent", which is a name for nobody — and anything else is
17 * named by the one rule for it, `voiceFor` (`studio/voice.ts`), which says
18 * who is named and why. The one place a *run* applies it, so a run's own
19 * page and the tail beside a running row (`studio/previews.ts`) never
20 * choose two voices for the same lines.
2021 */
2122 export function runVoice(
2223 kind: RunKind,
2324 writer: boolean,
24 actorName: string | undefined,
25 actor: Actor,
2526 ): string {
2627 if (kind === "deploy") return "the deploy";
2728 if (kind === "check") return "the check";
28 return writer ? (actorName ?? "an agent") : "the crew";
29 return voiceFor(actor, writer, unnamedRun(writer));
2930 }
3031
3132 /** At most this many of a run's own lines held in a full transcript at
src/web/studio/previews.ts +1 −1
@@ -171,7 +171,7 @@ function deployTail(
171171 if (agentBusy) return undefined;
172172 return logBox({
173173 id: "app-run-tail",
174 who: runVoice("deploy", true, undefined),
174 who: runVoice("deploy", true, { name: undefined, isAgent: true }),
175175 cap: LOG_TAIL_CAP,
176176 lines: readRunLogTail(ctx.app.config.dataDir, production.runId, LOG_TAIL_CAP)
177177 .lines,
src/web/studio/run.ts +12 −8
@@ -30,6 +30,7 @@ import { previewCard } from "../pages/apps.ts";
3030 import { costText, durationText, runTitle } from "../pages/runs.ts";
3131 import { logBox, runVoice, RUN_TRANSCRIPT_CAP } from "./log.ts";
3232 import { changeHref, tellHref } from "./nouns.ts";
33 import { unnamedRun, voiceFor, type Actor } from "./voice.ts";
3334 import { runWord, wordBadge, type WordCtx } from "./words.ts";
3435
3536 /**
@@ -77,14 +78,17 @@ export async function studioRun(
7778 run.issueId === null ? undefined : getIssueById(db, run.issueId);
7879 // A deploy or a check speaks for itself (`runVoice`, shared with the tail
7980 // `studio/previews.ts` opens for the same lines while production comes
80 // up) — only an agent run is named for who is on it, and who is on the
81 // crew is an owner's fact, same as the app's own page: a viewer who
82 // cannot write here reads the transcript as the crew's own work, never by
83 // the agent's name (title, every line, the live stream's `data-who`, the
84 // running pulse). The steer box below is writer-only already, so it only
85 // ever renders with the real name.
86 const who = runVoice(run.kind, writer, actor?.username);
87 const title = runTitle(run, writer ? actor?.username : "the crew", issue);
81 // up); anything else is named by the one rule for it — `voiceFor`
82 // (`studio/voice.ts`) says who is named and why. The title and the
83 // transcript take the same name, so the page never carries two. The
84 // steer box below is writer-only already, so it only ever renders with
85 // the real name.
86 const by: Actor = {
87 name: actor?.username,
88 isAgent: actor?.kind === "agent",
89 };
90 const who = runVoice(run.kind, writer, by);
91 const title = runTitle(run, voiceFor(by, writer, unnamedRun(writer)), issue);
8892 const wordCtx: WordCtx = {
8993 db,
9094 dir: repoDir(ctx.app.reposRoot, repo.ownerName, repo.name),
src/web/studio/voice.ts added +63
@@ -0,0 +1,63 @@
1 /**
2 * Whose name a studio row carries — the one place that decides it, so the
3 * app's page, a run's own page and the front door never sign the same piece
4 * of work to two different people.
5 *
6 * The decision, once: **an agent's name is not a secret.** A change's own
7 * page and `/changes` already name the agent that opened it to anyone who
8 * can read the repository, and nothing here could take that back. What
9 * "the crew" stands in for is narrower — who is on the crew is part of the
10 * roster, the ceiling and the ledger, the owner's own book-keeping
11 * (`docs/STUDIO.md`, _The owner's facts and the public's_) — and it is a
12 * matter of voice, not of secrecy: a visitor reads a *run* of the crew's
13 * as the app's own story rather than as an unfamiliar name's.
14 *
15 * So masking asks two questions and needs both, and the first is about the
16 * actor rather than the viewer:
17 *
18 * 1. Is the actor an agent? A person is named to every viewer that can see
19 * the row at all — their authorship is theirs, and the app page must
20 * say what `/changes` and the change's own page say.
21 * 2. Can this viewer see the owner's facts? A writer reads the real name.
22 *
23 * Nothing here decides *whether* a row is visible: a viewer who cannot see
24 * a change still cannot see it. This only names the one they can already
25 * see.
26 */
27
28 /** The name a run, a change or a tell is signed with when no name is shown. */
29 export const CREW = "the crew";
30
31 /** Who did the thing: a name, and whether that name is a crew member. */
32 export interface Actor {
33 /** The username, or undefined when the row names nobody at all. */
34 readonly name: string | undefined;
35 /** Whether that actor is an agent on the crew rather than a person. */
36 readonly isAgent: boolean;
37 }
38
39 /**
40 * The name to print beside a piece of work, and to draw the avatar from, so
41 * the initials always match the name beside them.
42 *
43 * `unnamed` is what a row that names nobody reads as — "the crew" on the
44 * app's page and the front door, `unnamedRun` on a run's own.
45 */
46 export function voiceFor(
47 actor: Actor,
48 writer: boolean,
49 unnamed: string = CREW,
50 ): string {
51 if (actor.name === undefined) return unnamed;
52 if (!actor.isAgent) return actor.name;
53 return writer ? actor.name : CREW;
54 }
55
56 /**
57 * What a run with no actor on it reads as: "an agent" is a name for nobody,
58 * honest enough for a writer who can see the roster anyway and would
59 * otherwise read the run as the whole crew's, and "the crew" for everyone
60 * else — the voice they read every other run of the crew's in.
61 */
62 export const unnamedRun = (writer: boolean): string =>
63 writer ? "an agent" : CREW;
test/studio.test.ts +204
@@ -6821,3 +6821,207 @@ describe("the front door asks about a person's own change too (#208)", () => {
68216821 expect(setIssueState(app, alice, repo, b, "closed").ok).toBe(true);
68226822 });
68236823 });
6824
6825 /**
6826 * Issue #206: one public app, one open change, one anonymous visitor, three
6827 * studio pages — and they must name the same author. Who signs a row is
6828 * `voiceFor` (`src/web/studio/voice.ts`): a person is named to anyone who
6829 * can see the row at all, and only the crew's own work reads as the app's
6830 * own story for a viewer who cannot see the roster.
6831 */
6832 describe("the studio names a person on the app's page, and the crew only for the crew's own work", () => {
6833 let dataDir: string;
6834 let app: App;
6835 let servers: Servers;
6836 let base: string;
6837 let repo: Repo;
6838 let alice: User;
6839 let ownerCookie: string;
6840 let personPull: Pull;
6841 let agentPull: Pull;
6842 let agentRun: Run;
6843 let waitingTell: Issue;
6844
6845 const signIn = async (username: string): Promise<string> =>
6846 (
6847 (
6848 await fetch(`${base}/signin`, {
6849 method: "POST",
6850 body: new URLSearchParams({
6851 username,
6852 password: "a-good-passphrase",
6853 }),
6854 redirect: "manual",
6855 })
6856 ).headers.get("set-cookie") ?? ""
6857 ).split(";")[0]!;
6858
6859 /** Signed out, in studio mode: the visitor the issue walked as. */
6860 const anon = async (path: string): Promise<string> =>
6861 (
6862 await fetch(`${base}${path}`, {
6863 headers: { cookie: "forge_mode=studio" },
6864 redirect: "manual",
6865 })
6866 ).text();
6867
6868 const owner = async (path: string): Promise<string> =>
6869 (
6870 await fetch(`${base}${path}`, {
6871 headers: { cookie: `${ownerCookie}; forge_mode=studio` },
6872 redirect: "manual",
6873 })
6874 ).text();
6875
6876 /** The one `<li>` a link sits in — one row, not the whole page. */
6877 const rowWith = (page: string, needle: string): string => {
6878 const at = page.indexOf(needle);
6879 expect(at).toBeGreaterThan(-1);
6880 const start = page.lastIndexOf("<li", at);
6881 const end = page.indexOf("</li>", at);
6882 return page.slice(start, end);
6883 };
6884
6885 /** What the avatar beside a name says, so initials can be held to it. */
6886 const initialsIn = (row: string): string =>
6887 row.match(/class="avatar"[\s\S]*?>([^<]*)<\/span/)?.[1]?.trim() ?? "";
6888
6889 const branchAndPull = async (
6890 who: User,
6891 name: string,
6892 title: string,
6893 ): Promise<Pull> => {
6894 const branch = await commitToBranch(app, alice, repo, {
6895 branch: name,
6896 base: "main",
6897 message: title,
6898 files: [{ path: `${name.replace(/\//g, "-")}.md`, content: `${name}\n` }],
6899 });
6900 if (!branch.ok) throw new Error(JSON.stringify(branch.error));
6901 const opened = await openPull(app, who, repo, {
6902 title,
6903 body: "",
6904 baseBranch: "main",
6905 headBranch: name,
6906 });
6907 if (!opened.ok) throw new Error(String(opened.error));
6908 return opened.value;
6909 };
6910
6911 beforeAll(async () => {
6912 dataDir = await mkdtemp(join(tmpdir(), "forge-studio-voice-"));
6913 app = createApp({ dataDir, port: 0 });
6914 servers = await serve(app);
6915 base = servers.url;
6916 const a = await createUser(app.db, {
6917 username: "ivy",
6918 email: "[email protected]",
6919 password: "a-good-passphrase",
6920 adminIfFirst: true,
6921 });
6922 if (!a.ok) throw new Error(a.error);
6923 alice = a.value;
6924 ownerCookie = await signIn("ivy");
6925
6926 const made = await createRepo(app, alice, {
6927 name: "pub",
6928 visibility: "public",
6929 description: "a public house",
6930 });
6931 if (!made.ok) throw new Error(String(made.error));
6932 repo = made.value;
6933 const seeded = await commitToBranch(app, alice, repo, {
6934 message: "Start",
6935 files: [{ path: "README.md", content: "pub\n" }],
6936 });
6937 if (!seeded.ok) throw new Error(JSON.stringify(seeded.error));
6938 const enabled = await enableApp(app, alice, repo, { slug: "pub" });
6939 if (!enabled.ok) throw new Error(String(enabled.error));
6940 const quill = await createAgent(app, alice, { username: "quill" });
6941 if (!quill.ok) throw new Error(String(quill.error));
6942 expect(addToCrew(app, alice, repo, "quill").ok).toBe(true);
6943 const quillUser = getUserByName(app.db, "quill")!;
6944 const quillId = quillUser.id;
6945
6946 // The change ivy opened herself, through the web editor.
6947 personPull = await branchAndPull(alice, "ivy/subtitle", "Add a subtitle");
6948 // One the crew opened, so the masking that was meant has something to
6949 // mask on the very same page.
6950 agentPull = await branchAndPull(quillUser, "quill/lamp", "Hang a lamp");
6951 // A run of the crew's, on a tell of its own so it keeps its own row.
6952 const told = openIssue(app, alice, repo, { title: "Sweep the step" });
6953 if (!told.ok) throw new Error(String(told.error));
6954 agentRun = createRun(app.db, {
6955 repoId: repo.id,
6956 kind: "agent",
6957 issueId: told.value.id,
6958 actorId: quillId,
6959 reason: "assigned",
6960 });
6961 claimRun(app.db, agentRun.id);
6962 agentRun =
6963 finishRun(app.db, agentRun.id, {
6964 state: "ok",
6965 summary: "swept",
6966 costUsd: 3.5,
6967 turns: 2,
6968 }) ?? agentRun;
6969
6970 // And one nobody has picked up yet: a waiting row, the crew's to take.
6971 const waiting = openIssue(app, alice, repo, { title: "Wipe the bar" });
6972 if (!waiting.ok) throw new Error(String(waiting.error));
6973 expect(assignIssue(app, alice, repo, waiting.value, quillUser).ok).toBe(
6974 true,
6975 );
6976 waitingTell = getIssue(app.db, repo.id, waiting.value.number)!;
6977 });
6978
6979 afterAll(async () => {
6980 servers.stop();
6981 app.close();
6982 await rm(dataDir, { recursive: true, force: true });
6983 });
6984
6985 test("an anonymous visitor reads one author for one change on all three pages, avatar included", async () => {
6986 const appPage = await anon("/ivy/pub");
6987 const changes = await anon("/ivy/pub/changes");
6988 const change = await anon(`/ivy/pub/changes/${personPull.number}`);
6989
6990 const onApp = rowWith(appPage, `/changes/${personPull.number}`);
6991 const onList = rowWith(changes, `/changes/${personPull.number}`);
6992 expect(onApp).toContain("ivy");
6993 expect(onApp).not.toContain("the crew");
6994 // The same name the list gives, and the same initials beside it.
6995 expect(initialsIn(onApp)).toBe(initialsIn(onList));
6996 expect(initialsIn(onApp)).toBe("i");
6997 expect(change).toContain("ivy");
6998 });
6999
7000 test("the crew's own change and the crew's own run still read as the crew's to that visitor", async () => {
7001 const appPage = await anon("/ivy/pub");
7002 const onApp = rowWith(appPage, `/changes/${agentPull.number}`);
7003 expect(onApp).toContain("the crew");
7004 expect(onApp).not.toContain("quill");
7005 expect(initialsIn(onApp)).toBe("tc");
7006
7007 const runRow = rowWith(appPage, `/runs/${agentRun.id}`);
7008 expect(runRow).toContain("the crew");
7009 expect(runRow).not.toContain("quill");
7010
7011 const tellRow = rowWith(appPage, `/tells/${waitingTell.number}`);
7012 expect(tellRow).toContain("the crew");
7013 expect(tellRow).not.toContain("quill");
7014
7015 // Nothing the owner keeps to herself came along with the name.
7016 expect(appPage).not.toContain("quill");
7017 expect(appPage).not.toMatch(/\$\d/);
7018 expect(appPage).not.toContain(">Crew<");
7019 });
7020
7021 test("the owner still reads the crew by name, and her own change as her own", async () => {
7022 const appPage = await owner("/ivy/pub");
7023 expect(rowWith(appPage, `/changes/${agentPull.number}`)).toContain("quill");
7024 expect(rowWith(appPage, `/runs/${agentRun.id}`)).toContain("quill");
7025 expect(rowWith(appPage, `/changes/${personPull.number}`)).toContain("ivy");
7026 });
7027 });

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs