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

A fork's follow mode (follow upstream or only propose) is one line on its page and a field in the fork MCP answer, with the same words #15782

Merged opened this

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

Merged

torque/forge:torque/15767-a-fork-s-follow-mode-follow-upstream-or → main 0 commits fork 3 threads · 3 unresolved

  • Merged. torque/15767-a-fork-s-follow-mode-follow-upstream-or was merged into main as b7b078f.

Review

Sign in to review this change.
11 files changed +62 −35
docs/features/follow-choice.md +1 −1
@@ -14,7 +14,7 @@ A fork says how it follows its upstream with three named choices, each with one
1414
1515 ## Where the line is
1616
17 A fork's header says how it follows in one plain sentence, inside the lineage line (`forked from alice/lib · Follows upstream automatically · 3 behind`): "Follows upstream automatically", "Proposes upstream changes for you to take" or "Does not follow upstream". The fork's admin sees it as a link to `/settings#follow-choice`, where the choice changes; everyone else reads it as text. The MCP `fork_tree` read carries the same sentence as `line` (null for a repository that is no fork), and the terminal's fork tree opens with it. The words live once, in `FOLLOW_LINE` (`src/actions/follow_words.ts`).
17 A fork's header says how it follows in one plain sentence, inside the lineage line (`forked from alice/lib · Follows upstream automatically · 3 behind`): "Follows alice/lib automatically", "Proposes changes only" or "Severed". The fork's admin sees it as a link to `/settings#follow-choice`, where the choice changes; everyone else reads it as text. The MCP `fork_tree` read carries the same sentence as `line` and the MCP `repo` read as `follows` (null for a repository that is no fork), and the terminal's fork tree opens with it. The words live once, in `followLineWords` (`src/actions/follow_words.ts`).

The example in this paragraph still reads forked from alice/lib · Follows upstream automatically · 3 behind. Change it to Follows alice/lib automatically (or use the 'Proposes changes only' example), so the how-to shows the words the page now says.

1818
1919 ## On the web
2020
docs/features/fork-tree.md +3 −3
@@ -18,10 +18,10 @@ A repository you may not read answers "not found", as everywhere else.
1818
1919 ## A fork's header
2020
21 Under the title of a fork the line "forked from alice/lib" ends in one plain sentence (`Follows upstream automatically`,
22 `Proposes upstream changes for you to take` or `Does not follow upstream`), a link to the setting that changes it
21 Under the title of a fork the line "forked from alice/lib" ends in one plain sentence (`Follows alice/lib automatically`,
22 `Proposes changes only` or `Severed`; the words live once, in `followLineWords`, and the MCP `repo` read carries them as `follows`), a link to the setting that changes it
2323 (`/owner/name/settings#follow-choice`) for the fork's admin and plain text for everyone else, then how far behind it is:
24 "forked from alice/lib · Proposes upstream changes for you to take · 2 behind". It is on every tab of the repository,
24 "forked from alice/lib · Proposes changes only · 2 behind". It is on every tab of the repository,
2525 not only the code tab, and a repository with no parent (or one whose parent you may not read) has no word. The count is
2626 the one the fork's relation last read at these two tips (the code page, the Following card, the terminal and the MCP all
2727 read it); when either branch has moved since, the header says no number rather than an old one, and never runs git to
src/actions/follow.ts +5 −3
@@ -14,7 +14,7 @@ import type { User } from "../core/users.ts";
1414 import { err, ok, type Result } from "../kernel/result.ts";
1515 import { chainOfRepo, forgeLinkOf, FOLLOW_MODES, isFollowMode, setChainMode, severChain } from "../spawn/chain.ts";
1616 import { FAMILY_WORDS } from "./family_words.ts";
17 import { FOLLOWS_NOTHING, FOLLOW_LINE, agoWords, driftWords, followModeWords, followStandingLine, lastFollowClause } from "./follow_words.ts";
17 import { FOLLOWS_NOTHING, followLineWords, agoWords, driftWords, followModeWords, followStandingLine, lastFollowClause } from "./follow_words.ts";
1818 import { FORK_FOLLOW_MODES, forkFollowMode, lastTookAt, isForkFollowMode, setForkFollowMode, type ForkFollowMode } from "../core/fork_follow.ts";
1919 import { lastFollow } from "../core/last_follow.ts";
2020 import { listEvents } from "../core/events.ts";
@@ -163,8 +163,10 @@ export async function followModeOf(app: App, repo: Repo): Promise<ForkFollowMode
163163 * The one plain sentence on how a fork follows its upstream (#14706), read from the same mode the
164164 * tree rows word; null for a repository that is no fork.
165165 */
166 export async function followLine(app: App, repo: Repo): Promise<string | null> {
167 return repo.forkParentId === null ? null : FOLLOW_LINE[await followModeOf(app, repo)];
166 export async function followLine(app: App, repo: Repo, user?: User): Promise<string | null> {
167 if (repo.forkParentId === null) return null;
168 const parent = forkParentFor(app.db, repo, user);
169 return followLineWords(await followModeOf(app, repo), parent === undefined ? "upstream" : `${parent.ownerName}/${parent.name}`);
168170 }
169171
170172 /**
src/actions/follow_words.ts +7 −7
@@ -109,14 +109,14 @@ export function agoWords(iso: string, now: number = Date.now()): string {
109109 }
110110
111111 /**
112 * The plain line a fork's header and the MCP tree read say of how it follows (#14706): no names,
113 * so a person and an agent get one sentence.
112 * The one line a fork's page and the MCP repo read say of how it follows (#15767): the same words
113 * for a person and an agent. `upstream` is the parent's name when the reader may see it.
114114 */
115 export const FOLLOW_LINE: Readonly<Record<ForkFollowMode, string>> = {
116 "take-updates": "Follows upstream automatically",
117 "tell-me": "Proposes upstream changes for you to take",
118 "dont-follow": "Does not follow upstream",
119 };
115 export function followLineWords(mode: ForkFollowMode, upstream: string): string {

This renames the exported words, so docs/features/follow-choice.md (line 17) and docs/features/fork-tree.md (lines 21-24) must be updated: they still quote the old three sentences and FOLLOW_LINE. Principle 8: one wording, said once.

116 if (mode === "take-updates") return `Follows ${upstream} automatically`;
117 if (mode === "dont-follow") return "Severed";
118 return "Proposes changes only";
119 }
120120
121121 /** The words that name a fork's choice, by mode, before the upstream. */
122122 const STANDING_LEADS: Record<ForkFollowMode, string> = {
src/actions/fork_tree_rows.ts +1 −1
@@ -78,6 +78,6 @@ export async function forkTreeRows(app: App, repo: Repo, user: User | undefined)
7878 Promise.all(chain.map((r, i) => rowOf(app, r, chain[i + 1]))),
7979 Promise.all(shown.map((f) => rowOf(app, f, repo))),
8080 ]);
81 const line = await followLine(app, repo);
81 const line = await followLine(app, repo, user);
8282 return { line, app: self, upstream, forks, truncated: all.length > shown.length };
8383 }
src/http/mcp/tools/repo.ts +3 −1
@@ -2,6 +2,7 @@ import { provenanceFacts } from "../../../core/provenance.ts";
22 import { forkParentFor } from "../../../core/repos.ts";
33 import { repoAudienceFor } from "../../../core/audience.ts";
44 import { repoFor } from "../../../core/repo_fields.ts";
5 import { followLine } from "../../../actions/follow.ts";
56 import { upstreamCounts } from "../../../actions/upstream_counts.ts";
67 import { upstreamFacts } from "../../../actions/upstream_follow.ts";
78 import { creditFacts } from "../../../actions/credit_facts.ts";
@@ -14,7 +15,7 @@ import { good, str, bad, type Tool, REPO_ARG, repoArg, isAnswer } from "../share
1415
1516 export const tool: Tool = {
1617 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|move|close` with `chapter`, `number` for add/remove/move, `direction: up|down` for move; 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)",
18 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), `follows` (a fork's one line on how it follows upstream, the page's words; `null` for no fork), `credit` (a mirror's upstream, licence, authors; `null` otherwise), the same as `GET /api/v1/repos/:owner/:name`; `action` (`open|add|remove|move|close` with `chapter`, `number` for add/remove/move, `direction: up|down` for move; 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)",
1819 description:
1920 "One repository you can read, as GET /api/v1/repos/:owner/:name.",
2021 inputSchema: {
@@ -93,6 +94,7 @@ export const tool: Tool = {
9394 upstreamCounts: (await upstreamCounts(ctx.app, repo, user)) ?? null,
9495 credit: await creditFacts(ctx.app, repo, user),
9596 }),
97 follows: await followLine(ctx.app, repo, user),
9698 });
9799 },
98100 };
src/web/chrome.ts +6 −6
@@ -24,7 +24,7 @@ import { parentUrl, shownTrail, sourceLabel } from "../core/provenance.ts";
2424 import type { App } from "../app.ts";
2525 import type { Ctx } from "../http/context.ts";
2626 import { apiError, prefersJson } from "../http/respond.ts";
27 import { FOLLOW_LINE } from "../actions/follow_words.ts";
27 import { followLineWords } from "../actions/follow_words.ts";
2828 import { forkFollowMode } from "../core/fork_follow.ts";
2929 import { keptBehind, MINE_ANCHOR, ownsInTree } from "../core/following.ts";
3030 import { html, raw, when, type Html } from "./html.ts";
@@ -416,14 +416,14 @@ export function lineageLine(
416416 }
417417
418418 /**
419 * How a fork follows its parent, in the one plain sentence every door says (`FOLLOW_LINE`, #14706),
420 * linked to the setting for whoever may change it, then how far behind it is when the relation
421 * cache counted it at these tips (#12683). One indexed read and two ref files; no git. Only ever
422 * drawn beside a parent, so a repository that is no fork pays nothing.
419 * How a fork follows its parent, in the one plain sentence every door says (`followLineWords`,
420 * #15767), linked to the setting for whoever may change it, then how far behind it is when the
421 * relation cache counted it at these tips (#12683). One indexed read and two ref files; no git.
422 * Only ever drawn beside a parent, so a repository that is no fork pays nothing.
423423 */
424424 function followWord(app: Pick<App, "db" | "reposRoot">, repo: Repo, parent: Repo, href?: string): Html {
425425 const behind = keptBehind(app, repo, parent);
426 const said = FOLLOW_LINE[forkFollowMode(app.db, repo.id)];
426 const said = followLineWords(forkFollowMode(app.db, repo.id), `${parent.ownerName}/${parent.name}`);
427427 return html`${
428428 href === undefined
429429 ? html`<span data-follow-word>${said}</span>`
test/fork-follow-line.test.ts +29 −8
@@ -9,7 +9,8 @@ import { join } from "node:path";
99 import { commitToBranch, createRepo, forkRepo } from "../src/actions/repos.ts";
1010 import { forkTreeRows } from "../src/actions/fork_tree_rows.ts";
1111 import { createApp, type App } from "../src/app.ts";
12 import { setForkFollowMode } from "../src/core/fork_follow.ts";
12 import type { Ctx } from "../src/http/context.ts";
13 import { setForkFollowMode, type ForkFollowMode } from "../src/core/fork_follow.ts";
1314 import { getRepo } from "../src/core/repos.ts";
1415 import { createUser } from "../src/core/users.ts";
1516 import { createForgeApp } from "../src/tui/forge.ts";
@@ -61,17 +62,17 @@ afterAll(async () => {
6162 test("both modes are worded plainly, and the owner's line links to the setting", async () => {
6263 setForkFollowMode(app.db, forkId, "take-updates");
6364 const auto = line(await page("/bea/lib", "bea"));
64 expect(auto).toContain("Follows upstream automatically");
65 expect(auto).toContain("Follows ann/lib automatically");
6566 expect(auto).toContain('href="/bea/lib/settings#follow-choice"');
6667 setForkFollowMode(app.db, forkId, "tell-me");
67 expect(line(await page("/bea/lib", "bea"))).toContain("Proposes upstream changes for you to take");
68 expect(line(await page("/bea/lib", "bea"))).toContain("Proposes changes only");
6869 });
6970
7071 test("a non-owner and a stranger see the line without the link", async () => {
7172 setForkFollowMode(app.db, forkId, "tell-me");
7273 for (const who of ["cal", undefined]) {
7374 const said = line(await page("/bea/lib", who));
74 expect(said).toContain("Proposes upstream changes for you to take");
75 expect(said).toContain("Proposes changes only");
7576 expect(said).not.toContain("<a");
7677 }
7778 });
@@ -83,9 +84,9 @@ test("an unrelated repository shows no line", async () => {
8384 test("the MCP tree read says the same sentence, and nothing for a non-fork", async () => {
8485 setForkFollowMode(app.db, forkId, "take-updates");
8586 const fork = getRepo(app.db, "bea", "lib")!;
86 expect((await forkTreeRows(app, fork, undefined)).line).toBe("Follows upstream automatically");
87 expect((await forkTreeRows(app, fork, undefined)).line).toBe("Follows ann/lib automatically");
8788 setForkFollowMode(app.db, forkId, "tell-me");
88 expect((await forkTreeRows(app, fork, undefined)).line).toBe("Proposes upstream changes for you to take");
89 expect((await forkTreeRows(app, fork, undefined)).line).toBe("Proposes changes only");
8990 expect((await forkTreeRows(app, getRepo(app.db, "ann", "lib")!, undefined)).line).toBeNull();
9091 });
9192
@@ -112,10 +113,30 @@ const treeText = async (owner: string): Promise<string> => {
112113
113114 test("the terminal's fork tree opens with the sentence for a fork, and not for a non-fork", async () => {
114115 setForkFollowMode(app.db, forkId, "tell-me");
115 expect(await treeText("bea")).toContain("Proposes upstream changes for you to take");
116 expect(await treeText("bea")).toContain("Proposes changes only");
116117 setForkFollowMode(app.db, forkId, "take-updates");
117 expect(await treeText("bea")).toContain("Follows upstream automatically");
118 expect(await treeText("bea")).toContain("Follows ann/lib automatically");
118119 const root = await treeText("ann");
119120 expect(root).not.toContain("upstream automatically");
120121 expect(root).not.toContain("Proposes upstream");
121122 });
123
124 test("the three states read the same on the page and in the MCP repo answer (#15767)", async () => {
125 const { tool } = await import("../src/http/mcp/tools/repo.ts");
126 const said = async (): Promise<string> => {
outdated

Replace { app } as any with a real Ctx (request, url, params, auth, theme), as test/repo-fields.test.ts does, and drop the as any on the mode.

127 const url = new URL("http://forge.test/mcp");
128 const ctx: Ctx = { app, request: new Request(url.href), url, params: {}, auth: { user: users["bea"], scope: "ro", via: "token" }, theme: undefined };
129 const r = await tool.run(ctx, users["bea"], { repo: "bea/lib" });
130 return (r as { value: { follows: string } }).value.follows;
131 };
132 const states: [string, string][] = [
133 ["take-updates", "Follows ann/lib automatically"],
134 ["tell-me", "Proposes changes only"],
135 ["dont-follow", "Severed"],
136 ];
137 for (const [mode, words] of states) {
138 setForkFollowMode(app.db, forkId, mode as ForkFollowMode);
139 expect(line(await page("/bea/lib", "bea"))).toContain(words);
140 expect(await said()).toBe(words);
141 }
142 });
test/fork-follow-word.test.ts +3 −3
@@ -70,9 +70,9 @@ const wordOf = async (path: string): Promise<{ href: string; word: string } | nu
7070 test("each mode is one plain sentence in the lineage line, on the code tab and on the others", async () => {
7171 const fork = getRepo(app.db, "bob", "lib")!;
7272 const want: [Parameters<typeof setForkFollowMode>[2], string][] = [
73 ["tell-me", "Proposes upstream changes for you to take"],
74 ["take-updates", "Follows upstream automatically"],
75 ["dont-follow", "Does not follow upstream"],
73 ["tell-me", "Proposes changes only"],
74 ["take-updates", "Follows alice/lib automatically"],
75 ["dont-follow", "Severed"],
7676 ];
7777 for (const [mode, word] of want) {
7878 setForkFollowMode(app.db, fork.id, mode);
test/provenance.test.ts +1 −1
@@ -175,7 +175,7 @@ describe("the record and the line", () => {
175175 });
176176 const fork = { ...source, id: "not-recorded", ownerName: "someone" };
177177 const line = lineageLine(app, fork, source)!.text.replace(/\s+/g, " ");
178 expect(line).toMatch(/forked from <a href="\/trevato\/arm" ?>trevato\/arm<\/a ?> · <span data-follow-word ?>Proposes upstream changes for you to take<\/span ?> · migrated/);
178 expect(line).toMatch(/forked from <a href="\/trevato\/arm" ?>trevato\/arm<\/a ?> · <span data-follow-word ?>Proposes changes only<\/span ?> · migrated/);
179179 expect(line).toContain(
180180 'migrated from <a href="https://github.com/Trevato/SO-ARM100" rel="noopener noreferrer">github.com/Trevato/SO-ARM100</a>',
181181 );
test/repo-fields.test.ts +3 −1
@@ -123,7 +123,9 @@ describe("an anonymous reader and a non-writer", () => {
123123 const ctx: Ctx = { app, request: new Request(url.href), url, params: {}, auth: { user: bob, scope: "ro", via: "token" }, theme: undefined };
124124 const read = await repoTool.run(ctx, bob, { repo: "alice/r" });
125125 expect(read.ok).toBe(true);
126 const { repo: _name, ...shape } = (read as { value: Record<string, unknown> }).value;
126 // `follows` is the MCP reply's own line (the fork page's words), not a field of the repository
127 // object.
128 const { repo: _name, follows: _follows, ...shape } = (read as { value: Record<string, unknown> }).value;
127129 expect(offList(shape)).toEqual([]);
128130 expect(shape["visibility"]).toBe("public");
129131 });

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs