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

Revert "An app's page says in one line who can see it (only you, your members, anyone with the link, the public) and the same words reach the MCP" #15729

opened this

Check · Review · Land · Live — It conflicts with its base. Next: builder, it conflicts with its base.

Conflicts with main

revert-15665 → main 1 commit

Review

Sign in to review this change.
8 files changed +11 −327
docs/features/app-seen-by.md deleted −29
@@ -1,29 +0,0 @@
1 ---
2 topic: Every setting, by topic
3 row: Who can open the app, in the same line
4 ---
5 # Who can open the app, in the same line
6
7 A repository's audience sentence ([Who can see it](visibility-line.md)) speaks
8 for its app as well, and says the app only where the app reaches further than
9 the code: private code behind a public app.
10
11 ```text
12 Private: only you; anyone with the link can open its app.
13 ```
14
15 In every other case the sentence already says it, so nothing is added: public
16 code and a public app ("Public: anyone can read this; …"), public code and a
17 private app ("The code is public; the app answers only to …"), and private code
18 with a private app ("Private: only you.").
19
20 - **Web**: the head of the repository and of its app's page shows it.
21 - **Terminal**: the About card (`I`) prints the same sentence.
22 - **API and MCP**: `GET /api/v1/repos/:owner/:name` and the `repo` tool carry
23 it as `audience.sentence`, and add `audience.appLine` (`null` without an app):
24 who can open the app on its own, for a client that reads only that. A private
25 app lets in whoever can change the repository and the people the app names;
26 the owner reads "you", anyone else the owner's name.
27
28 The words live in `src/apps/visibility_words.ts`. Tried by
29 `test/visibility-words.test.ts`.
src/apps/visibility_words.ts deleted −49
@@ -1,49 +0,0 @@
1 /**
2 * Who can open an app, in one line: the words the MCP and HTTP `repo` read
3 * return as `audience.appLine` (#15632), and the clause the audience sentence
4 * adds when the app reaches further than the code (`LINK_CLAUSE`). Pure: plain
5 * facts in, one of four kinds and a sentence out, so each wording is a test.
6 *
7 * A private app lets in whoever can change the repository (and its crew) and
8 * the people the app names (`canEnterApp` in `core/repos.ts`); the line says
9 * exactly that, naming the owner — "you" only to the owner.
10 *
11 * - `you`: a private app on a person's repository.
12 * - `members`: a private app on an organization's repository.
13 * - `link`: a public app whose code is private — reachable by its URL.
14 * - `public`: a public app on a public repository.
15 */
16
17 export type AppSeenBy = "you" | "members" | "link" | "public";
18
19 export interface AppVisibilityFacts {
20 readonly access: "public" | "private";
21 readonly visibility: "public" | "private";
22 readonly ownerKind: "user" | "org";
23 readonly ownerName: string;
24 /** Whether the person looking owns the repository: "you" is said only to them. */
25 readonly viewerOwns: boolean;
26 }
27
28 /** What the audience sentence of private code adds when its app is public. */
29 export const LINK_CLAUSE = "anyone with the link can open its app";
30
31 export function appSeenBy(facts: Pick<AppVisibilityFacts, "access" | "visibility" | "ownerKind">): AppSeenBy {
32 if (facts.access === "public") return facts.visibility === "public" ? "public" : "link";
33 return facts.ownerKind === "org" ? "members" : "you";
34 }
35
36 const REST = "whoever can change the repository, and the people the app names can open it.";
37
38 export function appVisibilityWords(facts: AppVisibilityFacts): { readonly seenBy: AppSeenBy; readonly line: string } {
39 const seenBy = appSeenBy(facts);
40 const line =
41 seenBy === "public"
42 ? "Anyone can open this app."
43 : seenBy === "link"
44 ? "Anyone with the link can open this app; its code stays private."
45 : seenBy === "members"
46 ? `Only whoever can change ${facts.ownerName}'s repository and the people the app names can open this app.`
47 : `Only ${facts.viewerOwns ? "you" : facts.ownerName}, ${REST}`;
48 return { seenBy, line };
49 }
src/core/audience.ts +1 −38
@@ -13,7 +13,6 @@ import type { Database } from "bun:sqlite";
1313 import type { Repo } from "./repos.ts";
1414 import type { User } from "./users.ts";
1515 import { REPO_VISIBLE, REPO_WRITABLE } from "./visibility.ts";
16 import { LINK_CLAUSE, appVisibilityWords } from "../apps/visibility_words.ts";
1716
1817 export interface AudienceFacts {
1918 readonly visibility: "public" | "private";
@@ -28,8 +27,6 @@ export interface AudienceFacts {
2827 readonly viewerWrites: boolean;
2928 /** Whether any of the crew works here. */
3029 readonly crew: boolean;
31 /** Whether the viewer owns the repository (an app's line says "you" only to them). */
32 readonly viewerOwns?: boolean;
3330 /**
3431 * The app's access, when the repository has an app. People are counted
3532 * once, never the viewer: `writers` may change the repository, `named` are
@@ -116,15 +113,11 @@ export function audienceOf(facts: AudienceFacts): Audience {
116113 }
117114 const alone = parts.length === 1 && you.length === 1;
118115 parts.push(...crew);
119 // A public app on private code reaches further than the code: the one case
120 // the sentence must go on to say who can open the app (#15632). Every other
121 // case it already says, so it is said once.
122 const linked = facts.app?.access === "public" ? `; ${LINK_CLAUSE}` : "";
123116 return {
124117 level: "private",
125118 sentence: `Private: ${alone ? "only " : ""}${
126119 parts.length === 0 ? "nobody" : list(parts)
127 }${linked}.`,
120 }.`,
128121 };
129122 }
130123
@@ -210,7 +203,6 @@ export function audienceFacts(
210203 viewer === undefined ? "signed-out" : viewer.isAdmin ? "admin" : "person",
211204 ownerKind: owner?.kind ?? "user",
212205 ownerName: repo.ownerName,
213 viewerOwns: viewerId !== undefined && viewerId === repo.ownerId,
214206 readers: countPeople(db, repo.id, REPO_VISIBLE, viewerId),
215207 writers: countPeople(db, repo.id, REPO_WRITABLE, undefined),
216208 viewerWrites: writes,
@@ -233,21 +225,6 @@ export function audienceFacts(
233225 };
234226 }
235227
236 /**
237 * Who can open the repository's app, in the one line its page head shows
238 * (`apps/visibility_words.ts`); `null` when the repository has no app.
239 */
240 export function appLineOf(facts: AudienceFacts): string | null {
241 if (facts.app === undefined) return null;
242 return appVisibilityWords({
243 access: facts.app.access,
244 visibility: facts.visibility,
245 ownerKind: facts.ownerKind,
246 ownerName: facts.ownerName,
247 viewerOwns: facts.viewerOwns === true,
248 }).line;
249 }
250
251228 /** The audience of `repo` for `viewer`: the one call the API and the MCP share. */
252229 export function audienceFor(
253230 db: Database,
@@ -257,17 +234,3 @@ export function audienceFor(
257234 const facts = audienceFacts(db, repo, viewer);
258235 return { ...audienceOf(facts), who: whoOf(facts) };
259236 }
260
261 /**
262 * The audience as the repository read returns it (HTTP and MCP `repo`), with
263 * `appLine`: who can open its app. Only that read carries it, so the page
264 * manifest and the other callers stay their size.
265 */
266 export function repoAudienceFor(
267 db: Database,
268 repo: Repo,
269 viewer: User | undefined,
270 ): Audience & { readonly who: Who; readonly appLine: string | null } {
271 const facts = audienceFacts(db, repo, viewer);
272 return { ...audienceOf(facts), who: whoOf(facts), appLine: appLineOf(facts) };
273 }
src/http/api.ts +3 −3
@@ -151,7 +151,7 @@ import {
151151 } from "../actions/users.ts";
152152 import { OFFSET_LIMIT_MAX, offsetPage, offsetQuery } from "./offset_page.ts";
153153 import { EVENTS_LIMIT_MAX, eventsAfter, eventsLimit, eventsPage, validEventsCursor, validEventsKind } from "../core/events_page.ts";
154 import { repoAudienceFor } from "../core/audience.ts";
154 import { audienceFor } from "../core/audience.ts";
155155 import { repoFor, reposFor, writeAccess, type WriteAccess } from "../core/repo_fields.ts";
156156 import { creditFacts } from "../actions/credit_facts.ts";
157157 import {
@@ -1748,7 +1748,7 @@ export function apiRoutes(router: Router<Handler>, isPage: (path: string) => boo
17481748 const repo = timePhase(ctx.request, "repo", () => loadRepo(ctx));
17491749 if (!repo) return notFound();
17501750 const facts = timePhase(ctx.request, "counts", () => repoJson(ctx, repo));
1751 const audience = timePhase(ctx.request, "audience", () => repoAudienceFor(ctx.app.db, repo, ctx.auth.user));
1751 const audience = timePhase(ctx.request, "audience", () => audienceFor(ctx.app.db, repo, ctx.auth.user));
17521752 const credited = performance.now();
17531753 const credit = await creditFacts(ctx.app, repo, ctx.auth.user);
17541754 notePhase(ctx.request, "credit", performance.now() - credited);
@@ -1864,7 +1864,7 @@ export function apiRoutes(router: Router<Handler>, isPage: (path: string) => boo
18641864 // The line about who can see it moves with the setting, in this answer.
18651865 return json({
18661866 ...repoJson(ctx, updated.value),
1867 audience: repoAudienceFor(ctx.app.db, updated.value, ctx.auth.user),
1867 audience: audienceFor(ctx.app.db, updated.value, ctx.auth.user),
18681868 });
18691869 });
18701870
src/http/mcp/tools/repo.ts +3 −3
@@ -1,6 +1,6 @@
11 import { provenanceFacts } from "../../../core/provenance.ts";
22 import { forkParentFor } from "../../../core/repos.ts";
3 import { repoAudienceFor } from "../../../core/audience.ts";
3 import { audienceFor } from "../../../core/audience.ts";
44 import { repoFor } from "../../../core/repo_fields.ts";
55 import { upstreamCounts } from "../../../actions/upstream_counts.ts";
66 import { upstreamFacts } from "../../../actions/upstream_follow.ts";
@@ -14,7 +14,7 @@ import { good, str, bad, type Tool, REPO_ARG, repoArg, isAnswer } from "../share
1414
1515 export const tool: Tool = {
1616 name: "repo",
17 doc: "`{ repo }`: one repository's description, visibility, autonomy (to a writer), `audience { level, who, sentence, appLine }` and `provenance` (where a migrated one came from, `null` when hidden), `credit` (a mirror's upstream, licence, authors; `null` otherwise), the same as `GET /api/v1/repos/:owner/:name`; `action` (`open|add|remove|close` with `chapter`, `number` for add/remove; a person who administers it, `rw` token) says what it would do, and with `confirm: true` does it, as the page; `view: \"chapters\"` lists its chapters with state, and with `chapter` names one's items (`done|building|left`) and `progress` (the page's sentence)",
17 doc: "`{ repo }`: one repository's description, visibility, autonomy (to a writer), `audience { level, who, sentence }` and `provenance` (where a migrated one came from, `null` when hidden), `credit` (a mirror's upstream, licence, authors; `null` otherwise), the same as `GET /api/v1/repos/:owner/:name`; `action` (`open|add|remove|close` with `chapter`, `number` for add/remove; a person who administers it, `rw` token) says what it would do, and with `confirm: true` does it, as the page; `view: \"chapters\"` lists its chapters with state, and with `chapter` names one's items (`done|building|left`) and `progress` (the page's sentence)",
1818 description:
1919 "One repository you can read, as GET /api/v1/repos/:owner/:name.",
2020 inputSchema: {
@@ -74,7 +74,7 @@ export const tool: Tool = {
7474 description: repo.description,
7575 visibility: repo.visibility,
7676 autonomy: repo.autonomy,
77 audience: repoAudienceFor(ctx.app.db, repo, user),
77 audience: audienceFor(ctx.app.db, repo, user),
7878 provenance: provenanceFacts(
7979 ctx.app.db,
8080 repo,
test/audience-surfaces.test.ts +2 −2
@@ -9,7 +9,7 @@ import { tmpdir } from "node:os";
99 import { join } from "node:path";
1010 import { createRepo } from "../src/actions/repos.ts";
1111 import { createApp, type App } from "../src/app.ts";
12 import { repoAudienceFor } from "../src/core/audience.ts";
12 import { audienceFor } from "../src/core/audience.ts";
1313 import { createApp as makeApp } from "../src/core/apps.ts";
1414 import { createToken } from "../src/core/tokens.ts";
1515 import { createUser, type User } from "../src/core/users.ts";
@@ -60,7 +60,7 @@ describe("one sentence on every surface", () => {
6060 const auth = { authorization: `Bearer ${token}` };
6161 const res = await fetch(`${servers.url}/api/v1/repos/olive/garden`, { headers: auth });
6262 const body = (await res.json()) as { audience: { level: string; sentence: string } };
63 expect(body.audience).toEqual(repoAudienceFor(app.db, made.value, olive));
63 expect(body.audience).toEqual(audienceFor(app.db, made.value, olive));
6464 expect(body.audience.sentence).toStartWith("The code is public; the app answers only to");
6565
6666 const mcp = await fetch(`${servers.url}/mcp`, {
test/visibility-line.test.ts +2 −2
@@ -14,7 +14,7 @@ import { AppsRuntime } from "../src/apps/runtime.ts";
1414 import { newApp } from "../src/actions/apps.ts";
1515 import { openPull } from "../src/actions/pulls.ts";
1616 import { commitToBranch, createRepo, forkRepo } from "../src/actions/repos.ts";
17 import { audienceFor, repoAudienceFor, whoOf } from "../src/core/audience.ts";
17 import { audienceFor, whoOf } from "../src/core/audience.ts";
1818 import { createApp as createAppRecord, getAppByRepo } from "../src/core/apps.ts";
1919 import { getRepo } from "../src/core/repos.ts";
2020 import { createUser, getUserByName, type User } from "../src/core/users.ts";
@@ -108,7 +108,7 @@ describe("who can see it, said once, everywhere", () => {
108108 const body: any = await (await api("/repos/alice/notes", aliceRw)).json();
109109 expect(body.audience.who).toBe("owner");
110110 expect(body.audience.level).toBe("private");
111 expect(body.audience).toEqual(repoAudienceFor(app.db, made.value, alice));
111 expect(body.audience).toEqual(audienceFor(app.db, made.value, alice));
112112 });
113113
114114 test("a stranger asking about a private repository gets what a missing one gets", async () => {
test/visibility-words.test.ts deleted −201
@@ -1,201 +0,0 @@
1 /**
2 * Who can open an app (#15632): the four wordings the MCP `repo` read returns,
3 * and the one audience sentence the page head and the terminal's About card
4 * share, which adds the app only where it reaches further than the code.
5 */
6 import { proveAll } from "./helpers/verified.ts";
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 { createRepo } from "../src/actions/repos.ts";
12 import { createApp, type App } from "../src/app.ts";
13 import { appVisibilityWords } from "../src/apps/visibility_words.ts";
14 import { repoAudienceFor } from "../src/core/audience.ts";
15 import { createApp as makeApp } from "../src/core/apps.ts";
16 import { createToken } from "../src/core/tokens.ts";
17 import { createUser, type User } from "../src/core/users.ts";
18 import { createOrg } from "../src/core/orgs.ts";
19 import { getRepoById, type Repo } from "../src/core/repos.ts";
20 import type { Ctx, Screen } from "../src/tui/app/app.ts";
21 import type { Session } from "../src/tui/session.ts";
22 import { aboutScreen } from "../src/tui/screens/about.ts";
23 import { Screen as Surface } from "../src/tui/term/screen.ts";
24 import { theme } from "../src/tui/ui/theme.ts";
25 import { localSource } from "../src/view/local.ts";
26 import { serve, type Servers } from "../src/http/server.ts";
27
28 const base = { ownerKind: "user", ownerName: "olive", viewerOwns: true } as const;
29
30 describe("the words, one per visibility", () => {
31 test("only you: a private app on your own repository, and the owner named to anyone else", () => {
32 expect(appVisibilityWords({ ...base, access: "private", visibility: "private" })).toEqual({
33 seenBy: "you",
34 line: "Only you, whoever can change the repository, and the people the app names can open it.",
35 });
36 expect(
37 appVisibilityWords({ ...base, access: "private", visibility: "public", viewerOwns: false }).line,
38 ).toBe("Only olive, whoever can change the repository, and the people the app names can open it.");
39 });
40
41 test("your members: a private app on an organization's repository says exactly who gets in", () => {
42 expect(
43 appVisibilityWords({ ...base, ownerKind: "org", ownerName: "acme", access: "private", visibility: "private" }),
44 ).toEqual({
45 seenBy: "members",
46 line: "Only whoever can change acme's repository and the people the app names can open this app.",
47 });
48 });
49
50 test("anyone with the link: a public app whose code is private", () => {
51 expect(appVisibilityWords({ ...base, access: "public", visibility: "private" })).toEqual({
52 seenBy: "link",
53 line: "Anyone with the link can open this app; its code stays private.",
54 });
55 });
56
57 test("the public: a public app on a public repository", () => {
58 expect(appVisibilityWords({ ...base, access: "public", visibility: "public" })).toEqual({
59 seenBy: "public",
60 line: "Anyone can open this app.",
61 });
62 });
63 });
64
65 describe("the page head, the terminal and the MCP say it once, the same way", () => {
66 let dataDir: string;
67 let app: App;
68 let servers: Servers;
69 let olive: User;
70 let pia: User;
71
72 const person = async (username: string, isAdmin = false): Promise<User> => {
73 const made = await createUser(app.db, {
74 origin: "seed",
75 username,
76 email: `${username}@f.dev`,
77 password: "a-good-passphrase",
78 isAdmin,
79 });
80 if (!made.ok) throw new Error(made.error);
81 return made.value;
82 };
83 const repoWithApp = async (
84 name: string,
85 visibility: "public" | "private",
86 access: "public" | "private",
87 owner?: string,
88 ): Promise<Repo> => {
89 const made = await createRepo(app, olive, { name, visibility, ...(owner ? { owner } : {}) });
90 if (!made.ok) throw new Error(String(made.error));
91 makeApp(app.db, { repoId: made.value.id, slug: name, access });
92 return made.value;
93 };
94 const auth = (who: User) => ({ authorization: `Bearer ${createToken(app.db, who.id, "t", "ro").token}` });
95 /** The audience paragraph's sentence on a repository's page. */
96 const pageSentence = async (path: string, who: User): Promise<string> => {
97 const page = await (await fetch(`${servers.url}${path}`, { headers: auth(who) })).text();
98 const m = /<p class="muted small"\s*>\s*(?:<span\s+class="badge"[^>]*>Split<\/span\s*>\s*)?(?:<a href="[^"]*"\s*>)?((?:Private|Public|The code is public)[^<]*)/.exec(page);
99 if (m === null) throw new Error(`no audience line on ${path}`);
100 return m[1]!.trim();
101 };
102 /** The terminal's About card, as text. */
103 const aboutText = (repo: Repo, who: User): string => {
104 const ctx = {
105 theme: theme("dark"),
106 invalidate() {},
107 toast() {},
108 push() {},
109 pop() {},
110 copy() {},
111 hit() {},
112 } as unknown as Ctx;
113 const f = { app, db: app.db, user: who } as unknown as Session;
114 const src = localSource(app, getRepoById(app.db, repo.id)!, who);
115 const screen = aboutScreen(f, ctx, { render() {} } as unknown as Screen, src, undefined, "main");
116 const s = new Surface(160, 30);
117 screen.render({ x: 0, y: 0, w: 160, h: 30 }, s);
118 return s.toText();
119 };
120 const mcpAppLine = async (repo: string, who: User): Promise<string> => {
121 const res = await fetch(`${servers.url}/mcp`, {
122 method: "POST",
123 headers: { ...auth(who), "content-type": "application/json", accept: "application/json, text/event-stream" },
124 body: JSON.stringify({
125 jsonrpc: "2.0",
126 id: 1,
127 method: "tools/call",
128 params: { name: "repo", arguments: { repo } },
129 }),
130 });
131 const body = (await res.json()) as { result: { content: { text: string }[] } };
132 return (JSON.parse(body.result.content[0]!.text) as { audience: { appLine: string } }).audience.appLine;
133 };
134
135 beforeAll(async () => {
136 dataDir = await mkdtemp(join(tmpdir(), "forge-app-seen-"));
137 app = createApp({ dataDir, port: 0 });
138 servers = await serve(app);
139 olive = await person("olive", true);
140 pia = await person("pia");
141 const org = createOrg(app.db, "acme", olive.id);
142 if (!org.ok) throw new Error(String(org.error));
143 proveAll(app);
144 });
145 afterAll(async () => {
146 servers.stop();
147 app.close();
148 await rm(dataDir, { recursive: true, force: true });
149 });
150
151 test("anyone with the link: private code, public app — the one sentence goes on to say it", async () => {
152 const repo = await repoWithApp("plot", "private", "public");
153 const sentence = "Private: only you; anyone with the link can open its app.";
154 expect(await pageSentence("/olive/plot", olive)).toBe(sentence);
155 expect(await pageSentence("/olive/plot/app", olive)).toBe(sentence);
156 expect(aboutText(repo, olive)).toContain(sentence);
157 expect(await mcpAppLine("olive/plot", olive)).toBe("Anyone with the link can open this app; its code stays private.");
158 });
159
160 test("only you: private code, private app — the sentence already says it, so nothing is added", async () => {
161 const repo = await repoWithApp("den", "private", "private");
162 expect(await pageSentence("/olive/den", olive)).toBe("Private: only you.");
163 expect(aboutText(repo, olive)).toContain("Private: only you.");
164 expect(aboutText(repo, olive)).not.toContain("open its app");
165 expect(await mcpAppLine("olive/den", olive)).toBe(
166 "Only you, whoever can change the repository, and the people the app names can open it.",
167 );
168 });
169
170 test("your members: an organization's private app — nothing added, and the MCP says who gets in", async () => {
171 await repoWithApp("ops", "private", "private", "acme");
172 expect(await pageSentence("/acme/ops", olive)).not.toContain("open its app");
173 expect(await mcpAppLine("acme/ops", olive)).toBe(
174 "Only whoever can change acme's repository and the people the app names can open this app.",
175 );
176 });
177
178 test("the public: public code, public app — said once, by the repository sentence", async () => {
179 const repo = await repoWithApp("park", "public", "public");
180 const sentence = await pageSentence("/olive/park", pia);
181 expect(sentence).toStartWith("Public: anyone can read this;");
182 expect(sentence).not.toContain("open its app");
183 expect(aboutText(repo, pia)).toContain(sentence);
184 expect(await mcpAppLine("olive/park", pia)).toBe("Anyone can open this app.");
185 });
186
187 test("the owner is told \"you\"; anyone else is told the owner's name", async () => {
188 await repoWithApp("shed", "public", "private");
189 expect(await mcpAppLine("olive/shed", olive)).toStartWith("Only you, ");
190 expect(await mcpAppLine("olive/shed", pia)).toStartWith("Only olive, ");
191 // The page's split sentence speaks for the app already, to each viewer in their words.
192 expect(await pageSentence("/olive/shed", pia)).toStartWith("The code is public; the app answers only to");
193 });
194
195 test("a repository with no app has no app words, and appLine is null", async () => {
196 const made = await createRepo(app, olive, { name: "notes", visibility: "public" });
197 if (!made.ok) throw new Error(String(made.error));
198 expect(repoAudienceFor(app.db, made.value, olive).appLine).toBeNull();
199 expect(await pageSentence("/olive/notes", olive)).not.toContain("open its app");
200 });
201 });

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs