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
Check · Review · Land · Live done — Landed and live in production.
torque/forge:torque/15767-a-fork-s-follow-mode-follow-upstream-or → main 0 commits fork 3 threads · 3 unresolved
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 | ||
| 14 | 14 | |
| 15 | 15 | ## Where the line is |
| 16 | 16 | |
| 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`). | |
| 18 | 18 | |
| 19 | 19 | ## On the web |
| 20 | 20 |
docs/features/fork-tree.md +3 −3
| @@ -18,10 +18,10 @@ A repository you may not read answers "not found", as everywhere else. | ||
| 18 | 18 | |
| 19 | 19 | ## A fork's header |
| 20 | 20 | |
| 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 | |
| 23 | 23 | (`/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, | |
| 25 | 25 | 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 |
| 26 | 26 | the one the fork's relation last read at these two tips (the code page, the Following card, the terminal and the MCP all |
| 27 | 27 | 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"; | ||
| 14 | 14 | import { err, ok, type Result } from "../kernel/result.ts"; |
| 15 | 15 | import { chainOfRepo, forgeLinkOf, FOLLOW_MODES, isFollowMode, setChainMode, severChain } from "../spawn/chain.ts"; |
| 16 | 16 | 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"; | |
| 18 | 18 | import { FORK_FOLLOW_MODES, forkFollowMode, lastTookAt, isForkFollowMode, setForkFollowMode, type ForkFollowMode } from "../core/fork_follow.ts"; |
| 19 | 19 | import { lastFollow } from "../core/last_follow.ts"; |
| 20 | 20 | import { listEvents } from "../core/events.ts"; |
| @@ -163,8 +163,10 @@ export async function followModeOf(app: App, repo: Repo): Promise<ForkFollowMode | ||
| 163 | 163 | * The one plain sentence on how a fork follows its upstream (#14706), read from the same mode the |
| 164 | 164 | * tree rows word; null for a repository that is no fork. |
| 165 | 165 | */ |
| 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}`); | |
| 168 | 170 | } |
| 169 | 171 | |
| 170 | 172 | /** |
src/actions/follow_words.ts +7 −7
| @@ -109,14 +109,14 @@ export function agoWords(iso: string, now: number = Date.now()): string { | ||
| 109 | 109 | } |
| 110 | 110 | |
| 111 | 111 | /** |
| 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. | |
| 114 | 114 | */ |
| 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 |
||
| 116 | if (mode === "take-updates") return `Follows ${upstream} automatically`; | |
| 117 | if (mode === "dont-follow") return "Severed"; | |
| 118 | return "Proposes changes only"; | |
| 119 | } | |
| 120 | 120 | |
| 121 | 121 | /** The words that name a fork's choice, by mode, before the upstream. */ |
| 122 | 122 | 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) | ||
| 78 | 78 | Promise.all(chain.map((r, i) => rowOf(app, r, chain[i + 1]))), |
| 79 | 79 | Promise.all(shown.map((f) => rowOf(app, f, repo))), |
| 80 | 80 | ]); |
| 81 | const line = await followLine(app, repo); | |
| 81 | const line = await followLine(app, repo, user); | |
| 82 | 82 | return { line, app: self, upstream, forks, truncated: all.length > shown.length }; |
| 83 | 83 | } |
src/http/mcp/tools/repo.ts +3 −1
| @@ -2,6 +2,7 @@ import { provenanceFacts } from "../../../core/provenance.ts"; | ||
| 2 | 2 | import { forkParentFor } from "../../../core/repos.ts"; |
| 3 | 3 | import { repoAudienceFor } from "../../../core/audience.ts"; |
| 4 | 4 | import { repoFor } from "../../../core/repo_fields.ts"; |
| 5 | import { followLine } from "../../../actions/follow.ts"; | |
| 5 | 6 | import { upstreamCounts } from "../../../actions/upstream_counts.ts"; |
| 6 | 7 | import { upstreamFacts } from "../../../actions/upstream_follow.ts"; |
| 7 | 8 | import { creditFacts } from "../../../actions/credit_facts.ts"; |
| @@ -14,7 +15,7 @@ import { good, str, bad, type Tool, REPO_ARG, repoArg, isAnswer } from "../share | ||
| 14 | 15 | |
| 15 | 16 | export const tool: Tool = { |
| 16 | 17 | 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)", | |
| 18 | 19 | description: |
| 19 | 20 | "One repository you can read, as GET /api/v1/repos/:owner/:name.", |
| 20 | 21 | inputSchema: { |
| @@ -93,6 +94,7 @@ export const tool: Tool = { | ||
| 93 | 94 | upstreamCounts: (await upstreamCounts(ctx.app, repo, user)) ?? null, |
| 94 | 95 | credit: await creditFacts(ctx.app, repo, user), |
| 95 | 96 | }), |
| 97 | follows: await followLine(ctx.app, repo, user), | |
| 96 | 98 | }); |
| 97 | 99 | }, |
| 98 | 100 | }; |
src/web/chrome.ts +6 −6
| @@ -24,7 +24,7 @@ import { parentUrl, shownTrail, sourceLabel } from "../core/provenance.ts"; | ||
| 24 | 24 | import type { App } from "../app.ts"; |
| 25 | 25 | import type { Ctx } from "../http/context.ts"; |
| 26 | 26 | import { apiError, prefersJson } from "../http/respond.ts"; |
| 27 | import { FOLLOW_LINE } from "../actions/follow_words.ts"; | |
| 27 | import { followLineWords } from "../actions/follow_words.ts"; | |
| 28 | 28 | import { forkFollowMode } from "../core/fork_follow.ts"; |
| 29 | 29 | import { keptBehind, MINE_ANCHOR, ownsInTree } from "../core/following.ts"; |
| 30 | 30 | import { html, raw, when, type Html } from "./html.ts"; |
| @@ -416,14 +416,14 @@ export function lineageLine( | ||
| 416 | 416 | } |
| 417 | 417 | |
| 418 | 418 | /** |
| 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. | |
| 423 | 423 | */ |
| 424 | 424 | function followWord(app: Pick<App, "db" | "reposRoot">, repo: Repo, parent: Repo, href?: string): Html { |
| 425 | 425 | 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}`); | |
| 427 | 427 | return html`${ |
| 428 | 428 | href === undefined |
| 429 | 429 | ? html`<span data-follow-word>${said}</span>` |
test/fork-follow-line.test.ts +29 −8
| @@ -9,7 +9,8 @@ import { join } from "node:path"; | ||
| 9 | 9 | import { commitToBranch, createRepo, forkRepo } from "../src/actions/repos.ts"; |
| 10 | 10 | import { forkTreeRows } from "../src/actions/fork_tree_rows.ts"; |
| 11 | 11 | 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"; | |
| 13 | 14 | import { getRepo } from "../src/core/repos.ts"; |
| 14 | 15 | import { createUser } from "../src/core/users.ts"; |
| 15 | 16 | import { createForgeApp } from "../src/tui/forge.ts"; |
| @@ -61,17 +62,17 @@ afterAll(async () => { | ||
| 61 | 62 | test("both modes are worded plainly, and the owner's line links to the setting", async () => { |
| 62 | 63 | setForkFollowMode(app.db, forkId, "take-updates"); |
| 63 | 64 | const auto = line(await page("/bea/lib", "bea")); |
| 64 | expect(auto).toContain("Follows upstream automatically"); | |
| 65 | expect(auto).toContain("Follows ann/lib automatically"); | |
| 65 | 66 | expect(auto).toContain('href="/bea/lib/settings#follow-choice"'); |
| 66 | 67 | 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"); | |
| 68 | 69 | }); |
| 69 | 70 | |
| 70 | 71 | test("a non-owner and a stranger see the line without the link", async () => { |
| 71 | 72 | setForkFollowMode(app.db, forkId, "tell-me"); |
| 72 | 73 | for (const who of ["cal", undefined]) { |
| 73 | 74 | 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"); | |
| 75 | 76 | expect(said).not.toContain("<a"); |
| 76 | 77 | } |
| 77 | 78 | }); |
| @@ -83,9 +84,9 @@ test("an unrelated repository shows no line", async () => { | ||
| 83 | 84 | test("the MCP tree read says the same sentence, and nothing for a non-fork", async () => { |
| 84 | 85 | setForkFollowMode(app.db, forkId, "take-updates"); |
| 85 | 86 | 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"); | |
| 87 | 88 | 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"); | |
| 89 | 90 | expect((await forkTreeRows(app, getRepo(app.db, "ann", "lib")!, undefined)).line).toBeNull(); |
| 90 | 91 | }); |
| 91 | 92 | |
| @@ -112,10 +113,30 @@ const treeText = async (owner: string): Promise<string> => { | ||
| 112 | 113 | |
| 113 | 114 | test("the terminal's fork tree opens with the sentence for a fork, and not for a non-fork", async () => { |
| 114 | 115 | 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"); | |
| 116 | 117 | 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"); | |
| 118 | 119 | const root = await treeText("ann"); |
| 119 | 120 | expect(root).not.toContain("upstream automatically"); |
| 120 | 121 | expect(root).not.toContain("Proposes upstream"); |
| 121 | 122 | }); |
| 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 |
||
| 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 | ||
| 70 | 70 | test("each mode is one plain sentence in the lineage line, on the code tab and on the others", async () => { |
| 71 | 71 | const fork = getRepo(app.db, "bob", "lib")!; |
| 72 | 72 | 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"], | |
| 76 | 76 | ]; |
| 77 | 77 | for (const [mode, word] of want) { |
| 78 | 78 | setForkFollowMode(app.db, fork.id, mode); |
test/provenance.test.ts +1 −1
| @@ -175,7 +175,7 @@ describe("the record and the line", () => { | ||
| 175 | 175 | }); |
| 176 | 176 | const fork = { ...source, id: "not-recorded", ownerName: "someone" }; |
| 177 | 177 | 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/); | |
| 179 | 179 | expect(line).toContain( |
| 180 | 180 | 'migrated from <a href="https://github.com/Trevato/SO-ARM100" rel="noopener noreferrer">github.com/Trevato/SO-ARM100</a>', |
| 181 | 181 | ); |
test/repo-fields.test.ts +3 −1
| @@ -123,7 +123,9 @@ describe("an anonymous reader and a non-writer", () => { | ||
| 123 | 123 | const ctx: Ctx = { app, request: new Request(url.href), url, params: {}, auth: { user: bob, scope: "ro", via: "token" }, theme: undefined }; |
| 124 | 124 | const read = await repoTool.run(ctx, bob, { repo: "alice/r" }); |
| 125 | 125 | 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; | |
| 127 | 129 | expect(offList(shape)).toEqual([]); |
| 128 | 130 | expect(shape["visibility"]).toBe("public"); |
| 129 | 131 | }); |
new above
offline
The example in this paragraph still reads
forked from alice/lib · Follows upstream automatically · 3 behind. Change it toFollows alice/lib automatically(or use the 'Proposes changes only' example), so the how-to shows the words the page now says.