Public: anyone can read this; the crew can change it.
The fork tree, browsable, and each fork chooses how it follows #1042
scout/forge:scout/608-the-fork-tree-browsable-and-each-fork-ch → main 6 commits fork
20 files
changed +534
−74
.tmp/.dfffbffbfefefd5e-00000000.hm added
No content changes.
.tmp/bunx-1000-typescript@latest/bun.lock added +54
| @@ -0,0 +1,54 @@ | ||
| 1 | { | |
| 2 | "lockfileVersion": 1, | |
| 3 | "configVersion": 1, | |
| 4 | "workspaces": { | |
| 5 | "": { | |
| 6 | "dependencies": { | |
| 7 | "typescript": "^7.0.2", | |
| 8 | }, | |
| 9 | }, | |
| 10 | }, | |
| 11 | "packages": { | |
| 12 | "@typescript/typescript-aix-ppc64": ["@typescript/[email protected]", "", { "os": "aix", "cpu": "ppc64" }, "sha512-MTKKkWB7p/0E9xi1d1tHtZ5PiLkGEMIq88pK2CubZjOsLtYTLqhgIgi6zepFa+9GHZ6h05NMCkQxGKiPXMxXtQ=="], | |
| 13 | ||
| 14 | "@typescript/typescript-darwin-arm64": ["@typescript/[email protected]", "", { "os": "darwin", "cpu": "arm64" }, "sha512-gowzar9MwS/aRWp6f3a4KUqzRjAZjOsmGNCM6LcTgXum+dBfgsBVMN+AgvOCCbguXyick6LJhpBszxMebJ8syA=="], | |
| 15 | ||
| 16 | "@typescript/typescript-darwin-x64": ["@typescript/[email protected]", "", { "os": "darwin", "cpu": "x64" }, "sha512-SZ9xZInqApNlNGc9s0W1VSsktYSOe9cFqNOIqmN1Gs8SmkjKZYFt017G4VwPxASInODuAdbTW7sXiFUf893RgA=="], | |
| 17 | ||
| 18 | "@typescript/typescript-freebsd-arm64": ["@typescript/[email protected]", "", { "os": "freebsd", "cpu": "arm64" }, "sha512-W5NH4y/J0plIIS5b2xvTEkU7JFxyqdMAOgf+Ilhl0vHQXKO5dZoxd+C/jEtq56c4F3wk71RB4BMRQ2XdI+bwYQ=="], | |
| 19 | ||
| 20 | "@typescript/typescript-freebsd-x64": ["@typescript/[email protected]", "", { "os": "freebsd", "cpu": "x64" }, "sha512-UMGDx5sTpzNw3WiPebH7l90IWfJggEd+egHt/q6p7/Cm3zqoV7VxkGXt+3DxPIw8CcmvAB0j3sVVfbhX+M4Tpw=="], | |
| 21 | ||
| 22 | "@typescript/typescript-linux-arm": ["@typescript/[email protected]", "", { "os": "linux", "cpu": "arm" }, "sha512-gffT3xPz9sR7j/YJExkyPntrI0P2EP9XbOyWzth2/Gs0RstK+90RBcO0ncXoXy/beYll1SXw846Nf2zdnEz0QQ=="], | |
| 23 | ||
| 24 | "@typescript/typescript-linux-arm64": ["@typescript/[email protected]", "", { "os": "linux", "cpu": "arm64" }, "sha512-Qh4eU4/y3yDjnfjjyPYihMj5/ODIlmt+Bzu17OI+fiSRDW57QmU5SiN63exPRNJPKUzcc1INa1NXdrJ+MqHjUQ=="], | |
| 25 | ||
| 26 | "@typescript/typescript-linux-loong64": ["@typescript/[email protected]", "", { "os": "linux", "cpu": "none" }, "sha512-uEHck9i8hoAzXPiYRib1O7miOnz23SxIeVl6F4LXox+qov1K35jHcEW6VHKvZI+pyvl7fZEP4MCU5LYvIq1GuQ=="], | |
| 27 | ||
| 28 | "@typescript/typescript-linux-mips64el": ["@typescript/[email protected]", "", { "os": "linux", "cpu": "none" }, "sha512-R4KvAMnE43W5Qeqb0Ly56O3mWMWIAgsMyz36DCaycd5nbg/9kzm0liw3JocfRqyJY0KPmzFjbswozXyW0DnIYA=="], | |
| 29 | ||
| 30 | "@typescript/typescript-linux-ppc64": ["@typescript/[email protected]", "", { "os": "linux", "cpu": "ppc64" }, "sha512-DORx5b3sd/4S7eayxm4FQv+A7CrkUIGRaHiwI8oiHTAI1fAPWhF4J0vAlkC8biAlHSVVwxMQ3tjZ2/DVbnQiiA=="], | |
| 31 | ||
| 32 | "@typescript/typescript-linux-riscv64": ["@typescript/[email protected]", "", { "os": "linux", "cpu": "none" }, "sha512-wf0jqEDOjrPRnKwYRyyJDRo11KMbvMFrU+q4zqKyChODBzvlkbhNQfKvLxQCcwTpdDaXSHZTVuh0JoCrKCUMHQ=="], | |
| 33 | ||
| 34 | "@typescript/typescript-linux-s390x": ["@typescript/[email protected]", "", { "os": "linux", "cpu": "s390x" }, "sha512-IkwJc3L7yhytWd/ewjyxNDfOmswCm9GWMJT/ue/dU4aZNbwZeYAetq42VyLmsmSjvoX7z74X6ZaYCtzAr0EuGw=="], | |
| 35 | ||
| 36 | "@typescript/typescript-linux-x64": ["@typescript/[email protected]", "", { "os": "linux", "cpu": "x64" }, "sha512-EYdf2cNg7rgCWJnxCdJ+F3V39O8ihb37eHAu1LK8oAFizgTQbPOK7zHHXbPt8rX24COqODXeI3sIf0fCXG7H/A=="], | |
| 37 | ||
| 38 | "@typescript/typescript-netbsd-arm64": ["@typescript/[email protected]", "", { "os": "none", "cpu": "arm64" }, "sha512-+polYF4MF04aPpO5FTkHran9yUQDSXqy5GiSDKpsll5jy3l3+g9QLhpf39T+ePtefhXLOGrLl0QIjkQP6VnelA=="], | |
| 39 | ||
| 40 | "@typescript/typescript-netbsd-x64": ["@typescript/[email protected]", "", { "os": "none", "cpu": "x64" }, "sha512-8YIT0EHM/3dq10ZOVF/A7pc/YSMtbcecct4rWtexrnSCHOPcpC2KTLXfTCR6vDpnSiY12heNb1GiN/wu+T/FyA=="], | |
| 41 | ||
| 42 | "@typescript/typescript-openbsd-arm64": ["@typescript/[email protected]", "", { "os": "openbsd", "cpu": "arm64" }, "sha512-APT8+ClYnuYm1u9+kgGXoMj2VzWzcymwh2gNSQVySHfkRDGOTVkoWLjCmOQSaO+PoqQ57B0flRp9SA+7GnnkzQ=="], | |
| 43 | ||
| 44 | "@typescript/typescript-openbsd-x64": ["@typescript/[email protected]", "", { "os": "openbsd", "cpu": "x64" }, "sha512-yX7s+Q0Dln0Dt9tEzZsAjXXR/+ytBM7AlglaqyeMPxQszJ1JhlJdZ6jLA+IzldHtflX81em7lDao1xXu+aRRkg=="], | |
| 45 | ||
| 46 | "@typescript/typescript-sunos-x64": ["@typescript/[email protected]", "", { "os": "sunos", "cpu": "x64" }, "sha512-dLJDGaLZ1D4HPQn62u1n8mBDkJREwMsAkCdkwd4Ieqw+x3TUyTsqY0YiBCtE6H6OzzgGk3iuZ3vFWRS+E8/d1g=="], | |
| 47 | ||
| 48 | "@typescript/typescript-win32-arm64": ["@typescript/[email protected]", "", { "os": "win32", "cpu": "arm64" }, "sha512-Gyl1Vy6OsWesLzmq+EP0Fb7b4Nid5232AvcA2SFcdYreldpNtYFFofPjnt62y9hQy7VTaZp65ICJjuAQRaVcIQ=="], | |
| 49 | ||
| 50 | "@typescript/typescript-win32-x64": ["@typescript/[email protected]", "", { "os": "win32", "cpu": "x64" }, "sha512-0BQ3HkAHHlKLSp1qRvf3SUhGpGsDuhB/jgFw75guyqbxJqEaS0Cw/VFO8i2nHglJUzQCRtMMR/IBAKE3ETMC4g=="], | |
| 51 | ||
| 52 | "typescript": ["[email protected]", "", { "optionalDependencies": { "@typescript/typescript-aix-ppc64": "7.0.2", "@typescript/typescript-darwin-arm64": "7.0.2", "@typescript/typescript-darwin-x64": "7.0.2", "@typescript/typescript-freebsd-arm64": "7.0.2", "@typescript/typescript-freebsd-x64": "7.0.2", "@typescript/typescript-linux-arm": "7.0.2", "@typescript/typescript-linux-arm64": "7.0.2", "@typescript/typescript-linux-loong64": "7.0.2", "@typescript/typescript-linux-mips64el": "7.0.2", "@typescript/typescript-linux-ppc64": "7.0.2", "@typescript/typescript-linux-riscv64": "7.0.2", "@typescript/typescript-linux-s390x": "7.0.2", "@typescript/typescript-linux-x64": "7.0.2", "@typescript/typescript-netbsd-arm64": "7.0.2", "@typescript/typescript-netbsd-x64": "7.0.2", "@typescript/typescript-openbsd-arm64": "7.0.2", "@typescript/typescript-openbsd-x64": "7.0.2", "@typescript/typescript-sunos-x64": "7.0.2", "@typescript/typescript-win32-arm64": "7.0.2", "@typescript/typescript-win32-x64": "7.0.2" }, "bin": { "tsc": "bin/tsc" } }, "sha512-8FYau96o3NKOhbjKi/qNvG/W5jhzxkbdm5sj9AbZ/5T5sWqn3hJgLfGx27sRKZWTvyzCP8dLRBTf5tBTSRVUNA=="], | |
| 53 | } | |
| 54 | } |
.tmp/bunx-1000-typescript@latest/package.json added +5
| @@ -0,0 +1,5 @@ | ||
| 1 | { | |
| 2 | "dependencies": { | |
| 3 | "typescript": "^7.0.2" | |
| 4 | } | |
| 5 | } |
docs/FOLLOWING.md +20 −1
| @@ -126,10 +126,29 @@ without any simply moves. | ||
| 126 | 126 | - The converge run's assignee is set without the assignment event, so the |
| 127 | 127 | run queues under its own reason and not as an ordinary assignment. |
| 128 | 128 | |
| 129 | ## How a fork follows | |
| 130 | ||
| 131 | A fork's writer chooses, on the forks page (`/:owner/:name/forks`) or with the | |
| 132 | MCP `follow {repo, mode}` tool; `following` returns the `mode`. Saved on the | |
| 133 | repository as `follow_mode`: | |
| 134 | ||
| 135 | - `auto` (the default, and what forks always did): a parent that moves is | |
| 136 | followed when git can do it alone — fast-forward, and with autonomy on a | |
| 137 | clean merge or the crew's converge. | |
| 138 | - `tell`: nothing is moved; the fork hears `fork.parent_moved`. | |
| 139 | - `off`: nothing happens. Pressing Take updates or Converge by hand still works. | |
| 140 | ||
| 141 | A conflict is never a stuck state. Taking updates that hit one (the button, | |
| 142 | the API, MCP `take_updates`) is refused with the files and, in the same | |
| 143 | step, told to the crew: the converge issue carries the files in conflict and | |
| 144 | is assigned to a builder when the repository has one. With nobody on the crew | |
| 145 | the issue still stands, unassigned, and the card says so; the next converge, | |
| 146 | once someone joins, takes that same issue. | |
| 147 | ||
| 129 | 148 | ## The way back up |
| 130 | 149 | |
| 131 | 150 | A fork's own work goes upstream in one press. When a fork is ahead of what |
| 132 | it follows, its following card offers **Propose upstream**: one pull opens | |
| 151 | it follows, the forks page offers **Offer this change** (the following card no longer carries a second button for it): one pull opens | |
| 133 | 152 | on the parent from the fork's default branch, its title the one landed |
| 134 | 153 | change's title, or `N changes from owner/fork` when there are several, its |
| 135 | 154 | body one line per change that landed here since the fork last proposed, |
docs/MCP.md +2 −1
| @@ -38,7 +38,8 @@ for a tunnel and a forge that sleeps. | ||
| 38 | 38 | | `audit` | who can do what, per app, read from its contract.json in git: yes, own or no per door, and whether outsiders may direct its crew (`crewOutsiders`) | | |
| 39 | 39 | | `outsiders` | `{ repo, on?, dryRun? }`: whether people who cannot write may direct the crew; with `on`, planned first (`dryRun` is true unless `false`); set only by the app's admin with an admin token, never an agent | yes | |
| 40 | 40 | | `probe` | knock on a running app's doors as nobody, a user and an admin; the ones that disobey its contract | | |
| 41 | | `following` | where a fork stands against what it follows, and what the crew is doing about it | | | |
| 41 | | `following` | where a fork stands against what it follows, its follow `mode`, and what the crew is doing about it | | | |
| 42 | | `follow` | `{ repo, mode }`: `auto`, `tell` or `off`, how a fork follows its parent; a writer's to say | yes | | |
| 42 | 43 | | `spawn` | `{ name, apps?, crew?, dryRun? }`: a child forge, planned first (`dryRun` is true unless `false`); an admin's, and an `ro` token may plan but not make | yes | |
| 43 | 44 | | `claim_link` | `{ name }`: a new claim link for a child you spawned that nobody has claimed; the old one stops working. An admin's | yes | |
| 44 | 45 | | `take_updates` | a fork takes its parent's updates when git can do it alone; a conflict is refused | yes | |
src/actions/forks.ts +24 −1
| @@ -18,6 +18,8 @@ import { | ||
| 18 | 18 | import { |
| 19 | 19 | canRead, |
| 20 | 20 | forkParentFor, |
| 21 | updateRepoSettings, | |
| 22 | type FollowMode, | |
| 21 | 23 | type Repo, |
| 22 | 24 | } from "../core/repos.ts"; |
| 23 | 25 | import { commitIdentity } from "../core/commit_identity.ts"; |
| @@ -25,7 +27,7 @@ import type { User } from "../core/users.ts"; | ||
| 25 | 27 | import { divergence } from "../git/branches.ts"; |
| 26 | 28 | import { resolveOid } from "../git/merge.ts"; |
| 27 | 29 | import { repoDir } from "../git/repos.ts"; |
| 28 | import { err, type Result } from "../kernel/result.ts"; | |
| 30 | import { err, ok, type Result } from "../kernel/result.ts"; | |
| 29 | 31 | import { requireWriter, type AccessError } from "./access.ts"; |
| 30 | 32 | |
| 31 | 33 | export type { ForkRelation, ForkSync, TakeError } from "../core/following.ts"; |
| @@ -65,6 +67,27 @@ export async function relationOf( | ||
| 65 | 67 | return forkRelation(app, fork, parent); |
| 66 | 68 | } |
| 67 | 69 | |
| 70 | /** Choose how a fork follows its parent; a writer's to say, a fork's only. */ | |
| 71 | export function setFollowMode( | |
| 72 | app: App, | |
| 73 | actor: User | undefined, | |
| 74 | fork: Repo, | |
| 75 | mode: FollowMode, | |
| 76 | ): Result<Repo, AccessError | "not_a_fork"> { | |
| 77 | const writer = requireWriter(app, actor, fork); | |
| 78 | if (!writer.ok) return writer; | |
| 79 | if (fork.forkParentId === null) return err("not_a_fork"); | |
| 80 | if (fork.followMode === mode) return ok(fork); | |
| 81 | const saved = updateRepoSettings(app.db, fork, { followMode: mode }); | |
| 82 | app.bus.append({ | |
| 83 | kind: "repo.follow_mode", | |
| 84 | repoId: fork.id, | |
| 85 | actorId: writer.value.id, | |
| 86 | payload: { from: fork.followMode, to: mode }, | |
| 87 | }); | |
| 88 | return ok(saved); | |
| 89 | } | |
| 90 | ||
| 68 | 91 | export type TakeUpdatesError = AccessError | "not_a_fork" | TakeError; |
| 69 | 92 | |
| 70 | 93 | /** |
src/core/event_audience.ts +2 −1
| @@ -42,7 +42,8 @@ export function eventAudience(kind: string): EventAudience { | ||
| 42 | 42 | // theirs to see, never the readers' (`actions/reports.ts`). |
| 43 | 43 | kind.startsWith("report.") || |
| 44 | 44 | kind === "repo.settings_updated" || |
| 45 | kind === "repo.crew_outsiders" | |
| 45 | kind === "repo.crew_outsiders" || | |
| 46 | kind === "repo.follow_mode" | |
| 46 | 47 | ) |
| 47 | 48 | return "admins"; |
| 48 | 49 | // A fleet operation spans repositories; its receipt is its actor's. |
src/core/following.ts +17 −1
| @@ -96,7 +96,22 @@ export function follow(forge: Following): () => void { | ||
| 96 | 96 | }), |
| 97 | 97 | ); |
| 98 | 98 | if (moved.some((m) => m.ref === `refs/heads/${repo.defaultBranch}`)) |
| 99 | for (const fork of listForks(forge.db, repo.id)) | |
| 99 | for (const fork of listForks(forge.db, repo.id)) { | |
| 100 | // The fork's owner chose how it follows: `off` is left alone, `tell` | |
| 101 | // hears that the parent moved and nothing else happens. | |
| 102 | if (fork.followMode === "off") continue; | |
| 103 | if (fork.followMode === "tell") { | |
| 104 | forge.bus.append({ | |
| 105 | kind: "fork.parent_moved", | |
| 106 | repoId: fork.id, | |
| 107 | actorId: actor, | |
| 108 | payload: { | |
| 109 | parent: `${repo.ownerName}/${repo.name}`, | |
| 110 | parentId: repo.id, | |
| 111 | }, | |
| 112 | }); | |
| 113 | continue; | |
| 114 | } | |
| 100 | 115 | fastForwardFork(forge, fork, repo, actor) |
| 101 | 116 | .then((followed) => { |
| 102 | 117 | // A fork with work of its own cannot be moved; it is told the |
| @@ -120,6 +135,7 @@ export function follow(forge: Following): () => void { | ||
| 120 | 135 | error: String(error), |
| 121 | 136 | }), |
| 122 | 137 | ); |
| 138 | } | |
| 123 | 139 | }); |
| 124 | 140 | } |
| 125 | 141 |
src/core/repos.ts +17 −1
| @@ -98,6 +98,8 @@ export interface Repo { | ||
| 98 | 98 | readonly autonomyCeilingUsd: number; |
| 99 | 99 | readonly autonomySlots: number; |
| 100 | 100 | readonly autonomyBy: string | null; |
| 101 | /** How this fork follows its parent; see `FollowMode`. */ | |
| 102 | readonly followMode: FollowMode; | |
| 101 | 103 | /** |
| 102 | 104 | * "Outsiders may trigger the crew": whether someone who cannot write here |
| 103 | 105 | * may still start or steer a run by speaking (`crew/direct.ts`). Off by |
| @@ -124,6 +126,16 @@ export interface Repo { | ||
| 124 | 126 | readonly counts?: RepoCounts; |
| 125 | 127 | } |
| 126 | 128 | |
| 129 | /** | |
| 130 | * How a fork follows its parent: `auto` takes what git can take alone, | |
| 131 | * `tell` only says the parent moved, `off` leaves the fork as it is. | |
| 132 | */ | |
| 133 | export const FOLLOW_MODES = ["auto", "tell", "off"] as const; | |
| 134 | export type FollowMode = (typeof FOLLOW_MODES)[number]; | |
| 135 | export function isFollowMode(v: unknown): v is FollowMode { | |
| 136 | return FOLLOW_MODES.includes(v as FollowMode); | |
| 137 | } | |
| 138 | ||
| 127 | 139 | interface RepoRow { |
| 128 | 140 | id: string; |
| 129 | 141 | owner_id: string; |
| @@ -141,6 +153,7 @@ interface RepoRow { | ||
| 141 | 153 | autonomy_slots: number; |
| 142 | 154 | autonomy_by: string | null; |
| 143 | 155 | crew_outsiders: number; |
| 156 | follow_mode: string; | |
| 144 | 157 | direction_issue_id: string | null; |
| 145 | 158 | fork_parent_id: string | null; |
| 146 | 159 | sealed_for: string | null; |
| @@ -177,6 +190,7 @@ function toRepo(row: RepoRow): Repo { | ||
| 177 | 190 | autonomySlots: row.autonomy_slots, |
| 178 | 191 | autonomyBy: row.autonomy_by, |
| 179 | 192 | crewOutsiders: row.crew_outsiders === 1, |
| 193 | followMode: isFollowMode(row.follow_mode) ? row.follow_mode : "auto", | |
| 180 | 194 | directionIssueId: row.direction_issue_id, |
| 181 | 195 | forkParentId: row.fork_parent_id, |
| 182 | 196 | sealedFor: row.sealed_for, |
| @@ -983,6 +997,7 @@ export interface RepoSettings { | ||
| 983 | 997 | autonomyBy?: string | null; |
| 984 | 998 | /** Whether someone who cannot write here may start or steer a run. */ |
| 985 | 999 | crewOutsiders?: boolean; |
| 1000 | followMode?: FollowMode; | |
| 986 | 1001 | } |
| 987 | 1002 | |
| 988 | 1003 | /** Update the mutable repo fields, leaving unspecified ones untouched. */ |
| @@ -995,7 +1010,7 @@ export function updateRepoSettings( | ||
| 995 | 1010 | `UPDATE repo SET visibility = ?1, description = ?2, protect_default = ?3, |
| 996 | 1011 | default_branch = ?4, require_review = ?5, require_checks = ?7, |
| 997 | 1012 | autonomy = ?8, autonomy_direction = ?9, autonomy_ceiling_usd = ?10, |
| 998 | autonomy_slots = ?11, autonomy_by = ?12, crew_outsiders = ?13 | |
| 1013 | autonomy_slots = ?11, autonomy_by = ?12, crew_outsiders = ?13, follow_mode = ?14 | |
| 999 | 1014 | WHERE id = ?6`, |
| 1000 | 1015 | ).run( |
| 1001 | 1016 | settings.visibility ?? repo.visibility, |
| @@ -1011,6 +1026,7 @@ export function updateRepoSettings( | ||
| 1011 | 1026 | settings.autonomySlots ?? repo.autonomySlots, |
| 1012 | 1027 | settings.autonomyBy === undefined ? repo.autonomyBy : settings.autonomyBy, |
| 1013 | 1028 | (settings.crewOutsiders ?? repo.crewOutsiders) ? 1 : 0, |
| 1029 | settings.followMode ?? repo.followMode, | |
| 1014 | 1030 | ); |
| 1015 | 1031 | return getRepoById(db, repo.id)!; |
| 1016 | 1032 | } |
src/core/schema.ts +6
| @@ -1540,4 +1540,10 @@ export const migrations: readonly string[] = [ | ||
| 1540 | 1540 | SELECT RAISE(ABORT, 'a sealed repository is never public'); |
| 1541 | 1541 | END; |
| 1542 | 1542 | `, |
| 1543 | // 71 — how a fork follows its parent (#608): `auto` takes what git can | |
| 1544 | // take on its own (today's behaviour), `tell` only says the parent moved, | |
| 1545 | // `off` leaves the fork alone. Meaningless on a repository that is no fork. | |
| 1546 | ` | |
| 1547 | ALTER TABLE repo ADD COLUMN follow_mode TEXT NOT NULL DEFAULT 'auto'; | |
| 1548 | `, | |
| 1543 | 1549 | ]; |
src/crew/converge.ts +16 −6
| @@ -31,6 +31,7 @@ import { activeRunFor, listRuns } from "../core/runs.ts"; | ||
| 31 | 31 | import { commitIdentity } from "../core/commit_identity.ts"; |
| 32 | 32 | import { getUserById, type User } from "../core/users.ts"; |
| 33 | 33 | import { createLog } from "../kernel/log.ts"; |
| 34 | import { ok } from "../kernel/result.ts"; | |
| 34 | 35 | import { parkedCount } from "./autonomy.ts"; |
| 35 | 36 | import { PARK_STRIKES } from "./parks.ts"; |
| 36 | 37 | import { queueAgentRun } from "./dispatch.ts"; |
| @@ -50,11 +51,12 @@ export type Converge = | ||
| 50 | 51 | | { kind: "working"; issue: Issue; agent: Agent | undefined } |
| 51 | 52 | /** The crew's proposal is open on the fork. */ |
| 52 | 53 | | { kind: "proposed"; issue: Issue; pull: Pull } |
| 54 | /** The issue carrying the conflicting files is open; nobody on the crew to take it yet. */ | |
| 55 | | { kind: "told"; issue: Issue } | |
| 53 | 56 | /** The crew tried its limit; a person's word is needed. */ |
| 54 | 57 | | { kind: "parked"; issue: Issue } |
| 55 | 58 | /** Not the crew's: in step, behind only, ahead only, or a clean merge. */ |
| 56 | 59 | | { kind: "nothing"; relation: ForkRelation | undefined } |
| 57 | | { kind: "no_crew" } | |
| 58 | 60 | | { kind: "nobody" } |
| 59 | 61 | /** The person asking may not direct the crew here (`direct.ts`). */ |
| 60 | 62 | | { kind: "forbidden" } |
| @@ -103,6 +105,8 @@ export function convergeState( | ||
| 103 | 105 | return { kind: "working", issue, agent }; |
| 104 | 106 | } |
| 105 | 107 | if (parkedCount(app, fork, issue.id) >= PARK_STRIKES) return { kind: "parked", issue }; |
| 108 | // Never taken by a builder: told, and waiting for one. | |
| 109 | if (issue.assigneeId === null) return { kind: "told", issue }; | |
| 106 | 110 | return { kind: "working", issue, agent: undefined }; |
| 107 | 111 | } |
| 108 | 112 | |
| @@ -139,11 +143,11 @@ export async function convergeFork( | ||
| 139 | 143 | if (relation === undefined || relation.state !== "diverged" || relation.clean) |
| 140 | 144 | return { kind: "nothing", relation }; |
| 141 | 145 | const inHand = convergeState(app, fork, parent); |
| 142 | if (inHand !== undefined) return inHand; | |
| 146 | if (inHand !== undefined && inHand.kind !== "told") return inHand; | |
| 143 | 147 | const builders = listCrewRoles(app.db, fork.id) |
| 144 | 148 | .filter((c) => c.role === "builder") |
| 145 | 149 | .map((c) => c.agent); |
| 146 | if (builders.length === 0) return { kind: "no_crew" }; | |
| 150 | if (inHand !== undefined && builders.length === 0) return inHand; | |
| 147 | 151 | const as = opener(app, fork, actor); |
| 148 | 152 | if (as === undefined) return { kind: "nobody" }; |
| 149 | 153 | |
| @@ -155,7 +159,10 @@ export async function convergeFork( | ||
| 155 | 159 | return { kind: "nothing", relation }; |
| 156 | 160 | } |
| 157 | 161 | const files = relation.conflicts; |
| 158 | const opened = openIssue(app, as, fork, { | |
| 162 | const opened = | |
| 163 | inHand !== undefined | |
| 164 | ? ok(inHand.issue) | |
| 165 | : openIssue(app, as, fork, { | |
| 159 | 166 | title: convergeTitle(parent), |
| 160 | 167 | body: [ |
| 161 | 168 | `This repository follows ${parent.ownerName}/${parent.name}. Both have moved since they last agreed: ${relation.behind} change${relation.behind === 1 ? "" : "s"} there, ${relation.ahead} here, and ${files.length === 0 ? "git cannot merge them" : `${files.length === 1 ? "one file" : `${files.length} files`} changed on both sides: ${files.join(", ")}`}.`, |
| @@ -165,13 +172,16 @@ export async function convergeFork( | ||
| 165 | 172 | }); |
| 166 | 173 | if (!opened.ok) return { kind: "nobody" }; |
| 167 | 174 | const issue = opened.value; |
| 175 | // A conflict is a tell for the crew, not a stuck state: with nobody on | |
| 176 | // the crew the issue still stands, carrying the files, for whoever joins. | |
| 177 | if (builders.length === 0) return { kind: "told", issue }; | |
| 168 | 178 | |
| 169 | 179 | const inFlight = new Map<string, number>(); |
| 170 | 180 | for (const r of listRuns(app.db, fork.id, { kind: "agent", limit: 50 })) |
| 171 | 181 | if ((r.state === "running" || r.state === "queued") && r.actorId !== null) |
| 172 | 182 | inFlight.set(r.actorId, (inFlight.get(r.actorId) ?? 0) + 1); |
| 173 | 183 | const agent = pickBuilder(issue, builders, inFlight); |
| 174 | if (agent === undefined) return { kind: "no_crew" }; | |
| 184 | if (agent === undefined) return { kind: "told", issue }; | |
| 175 | 185 | // The assignee is the agent so that what follows — feedback on the |
| 176 | 186 | // proposal, a red check — reaches the same builder. Set without the |
| 177 | 187 | // assignment event: that event starts an ordinary run, and this one is |
| @@ -207,7 +217,7 @@ export function followDivergence(app: App): () => void { | ||
| 207 | 217 | const parent = |
| 208 | 218 | typeof parentId === "string" ? getRepoById(app.db, parentId) : undefined; |
| 209 | 219 | if (fork === undefined || parent === undefined) return; |
| 210 | if (fork.autonomy === "off") return; | |
| 220 | if (fork.autonomy === "off" || fork.followMode !== "auto") return; | |
| 211 | 221 | diverged(app, fork, parent).catch((error) => |
| 212 | 222 | log.error("could not act on a diverged fork", { |
| 213 | 223 | fork: `${fork.ownerName}/${fork.name}`, |
src/design/activity.ts +1
| @@ -111,6 +111,7 @@ const WORDS: Record<string, string> = { | ||
| 111 | 111 | "repo.created": "created a repository", |
| 112 | 112 | "repo.forked": "forked a repository", |
| 113 | 113 | "repo.settings_updated": "changed repository settings", |
| 114 | "repo.follow_mode": "changed how the fork follows its parent", | |
| 114 | 115 | "repo.crew_outsiders": "changed who may trigger the crew", |
| 115 | 116 | "repo.mirrored": "mirrored a repository", |
| 116 | 117 | "repo.imported": "imported issues and pulls", |
src/http/api.ts +14 −3
| @@ -1717,15 +1717,24 @@ export function apiRoutes(router: Router<Handler>): void { | ||
| 1717 | 1717 | return e === "not_a_fork" |
| 1718 | 1718 | ? apiError("not_a_fork", 404, "this repository follows nothing") |
| 1719 | 1719 | : respondAccess(e, 403); |
| 1720 | if (e.kind === "conflict") | |
| 1720 | if (e.kind === "conflict") { | |
| 1721 | const parent = forkParentFor(ctx.app.db, repo, ctx.auth.user); | |
| 1722 | const told = | |
| 1723 | parent === undefined | |
| 1724 | ? undefined | |
| 1725 | : await convergeFork(ctx.app, repo, parent, ctx.auth.user); | |
| 1721 | 1726 | return json( |
| 1722 | 1727 | { |
| 1723 | 1728 | error: "conflict", |
| 1724 | message: "both sides changed these files; the crew can converge", | |
| 1729 | message: | |
| 1730 | "both sides changed these files; they are told to the crew as an issue", | |
| 1725 | 1731 | files: e.files, |
| 1732 | issue: | |
| 1733 | told !== undefined && "issue" in told ? told.issue.number : null, | |
| 1726 | 1734 | }, |
| 1727 | 1735 | 409, |
| 1728 | 1736 | ); |
| 1737 | } | |
| 1729 | 1738 | return apiError( |
| 1730 | 1739 | e.kind, |
| 1731 | 1740 | 409, |
| @@ -1782,7 +1791,9 @@ export function apiRoutes(router: Router<Handler>): void { | ||
| 1782 | 1791 | const status = |
| 1783 | 1792 | outcome.kind === "queued" |
| 1784 | 1793 | ? 202 |
| 1785 | : outcome.kind === "working" || outcome.kind === "proposed" | |
| 1794 | : outcome.kind === "working" || | |
| 1795 | outcome.kind === "proposed" || | |
| 1796 | outcome.kind === "told" | |
| 1786 | 1797 | ? 200 |
| 1787 | 1798 | : outcome.kind === "ceiling" |
| 1788 | 1799 | ? 429 |
src/http/mcp.ts +50 −11
| @@ -19,7 +19,7 @@ | ||
| 19 | 19 | |
| 20 | 20 | import { mayView, mayViewId, sealedScope } from "../core/sealed.ts"; |
| 21 | 21 | import { changeCapacity, listCapacity } from "../actions/capacity.ts"; |
| 22 | import { relationOf, takeUpdates } from "../actions/forks.ts"; | |
| 22 | import { relationOf, setFollowMode, takeUpdates } from "../actions/forks.ts"; | |
| 23 | 23 | import { watchMilestone } from "../actions/watches.ts"; |
| 24 | 24 | import { |
| 25 | 25 | addCommentThrough, |
| @@ -66,6 +66,8 @@ import { | ||
| 66 | 66 | canWrite, |
| 67 | 67 | forkParentFor, |
| 68 | 68 | getRepo, |
| 69 | FOLLOW_MODES, | |
| 70 | isFollowMode, | |
| 69 | 71 | ownerFactRepoIds, |
| 70 | 72 | type Repo, |
| 71 | 73 | } from "../core/repos.ts"; |
| @@ -742,9 +744,40 @@ const TOOLS: readonly Tool[] = [ | ||
| 742 | 744 | clean: relation.clean, |
| 743 | 745 | conflicts: relation.conflicts, |
| 744 | 746 | converge: converge?.kind ?? null, |
| 747 | mode: repo.followMode, | |
| 745 | 748 | }); |
| 746 | 749 | }, |
| 747 | 750 | }, |
| 751 | { | |
| 752 | name: "follow", | |
| 753 | description: | |
| 754 | "Choose how a fork follows the repository it came from: `auto` takes the updates git can take on its own, `tell` only notes that the parent moved, `off` leaves the fork alone. A writer's to say.", | |
| 755 | inputSchema: { | |
| 756 | type: "object", | |
| 757 | properties: { | |
| 758 | repo: REPO_ARG, | |
| 759 | mode: { type: "string", enum: [...FOLLOW_MODES] }, | |
| 760 | }, | |
| 761 | required: ["repo", "mode"], | |
| 762 | }, | |
| 763 | writes: true, | |
| 764 | async run(ctx, user, args) { | |
| 765 | const repo = repoArg(ctx, user, args); | |
| 766 | if (isAnswer(repo)) return repo; | |
| 767 | const mode = str(args["mode"]); | |
| 768 | if (!isFollowMode(mode)) | |
| 769 | return bad("invalid", "mode is auto, tell or off"); | |
| 770 | const set = setFollowMode(ctx.app, user, repo, mode); | |
| 771 | if (!set.ok) | |
| 772 | return bad( | |
| 773 | set.error, | |
| 774 | set.error === "not_a_fork" | |
| 775 | ? "this repository follows nothing" | |
| 776 | : "only a writer chooses how a fork follows", | |
| 777 | ); | |
| 778 | return good({ mode: set.value.followMode }); | |
| 779 | }, | |
| 780 | }, | |
| 748 | 781 | { |
| 749 | 782 | name: "spawn", |
| 750 | 783 | description: |
| @@ -852,7 +885,7 @@ const TOOLS: readonly Tool[] = [ | ||
| 852 | 885 | { |
| 853 | 886 | name: "take_updates", |
| 854 | 887 | description: |
| 855 | "Take the parent's updates into a fork: a fast-forward, or a merge when git merges cleanly. A conflict is refused with its files; use `converge` then.", | |
| 888 | "Take the parent's updates into a fork: a fast-forward, or a merge when git merges cleanly. A conflict is refused with its files and told to the crew as an issue (assigned to a builder when there is one).", | |
| 856 | 889 | inputSchema: { |
| 857 | 890 | type: "object", |
| 858 | 891 | properties: { repo: REPO_ARG }, |
| @@ -880,15 +913,21 @@ const TOOLS: readonly Tool[] = [ | ||
| 880 | 913 | ? "this repository follows nothing" |
| 881 | 914 | : "you need write access to take updates here", |
| 882 | 915 | ); |
| 883 | return e.kind === "conflict" | |
| 884 | ? bad( | |
| 885 | "conflict", | |
| 886 | `both sides changed ${e.files.join(", ")}; converge with the crew`, | |
| 887 | ) | |
| 888 | : bad( | |
| 889 | e.kind, | |
| 890 | e.kind === "moved" ? "something moved; try again" : e.message, | |
| 891 | ); | |
| 916 | if (e.kind === "conflict") { | |
| 917 | const parent = forkParentFor(ctx.app.db, repo, user); | |
| 918 | const told = | |
| 919 | parent === undefined | |
| 920 | ? undefined | |
| 921 | : await convergeFork(ctx.app, repo, parent, user); | |
| 922 | return bad( | |
| 923 | "conflict", | |
| 924 | `both sides changed ${e.files.join(", ")}; told to the crew${told !== undefined && "issue" in told ? ` on issue #${told.issue.number}` : ""}`, | |
| 925 | ); | |
| 926 | } | |
| 927 | return bad( | |
| 928 | e.kind, | |
| 929 | e.kind === "moved" ? "something moved; try again" : e.message, | |
| 930 | ); | |
| 892 | 931 | }, |
| 893 | 932 | }, |
| 894 | 933 | { |
src/web/pages/following.ts +103 −39
| @@ -13,11 +13,15 @@ | ||
| 13 | 13 | import { DIRECTION_NOTE } from "../../crew/direct.ts"; |
| 14 | 14 | import { |
| 15 | 15 | relationOf, |
| 16 | setFollowMode, | |
| 16 | 17 | takeUpdates, |
| 17 | 18 | type ForkRelation, |
| 18 | 19 | } from "../../actions/forks.ts"; |
| 19 | 20 | import { listCrewRoles } from "../../core/agents.ts"; |
| 20 | 21 | import { |
| 22 | FOLLOW_MODES, | |
| 23 | type FollowMode, | |
| 24 | isFollowMode, | |
| 21 | 25 | canRead, |
| 22 | 26 | canWrite, |
| 23 | 27 | forkParentFor, |
| @@ -156,6 +160,67 @@ export function relationSentence(relation: ForkRelation): string { | ||
| 156 | 160 | } |
| 157 | 161 | } |
| 158 | 162 | |
| 163 | const MODE_WORDS: Record<FollowMode, [string, string]> = { | |
| 164 | auto: ["Take green updates", "Updates git can take alone are taken."], | |
| 165 | tell: ["Tell me", "The fork is only told when its parent moves."], | |
| 166 | off: ["Don't follow", "The fork stays as it is."], | |
| 167 | }; | |
| 168 | ||
| 169 | /** | |
| 170 | * How this fork follows, and the one offer it can make: on the forks page, | |
| 171 | * for a writer of a fork. Choosing the mode is the action; a fork ahead of | |
| 172 | * its parent also offers its change up. | |
| 173 | */ | |
| 174 | export async function followPanel( | |
| 175 | ctx: Ctx, | |
| 176 | repo: Repo, | |
| 177 | ): Promise<Html | null> { | |
| 178 | if (repo.forkParentId === null) return null; | |
| 179 | if (!canWrite(ctx.app.db, repo, ctx.auth.user)) return null; | |
| 180 | const following = await followingOf(ctx, repo); | |
| 181 | if (following === undefined) return null; | |
| 182 | const { relation } = following; | |
| 183 | const parent = relation.parent; | |
| 184 | const base = repoBase(repo); | |
| 185 | const proposal = | |
| 186 | relation.ahead > 0 ? openProposal(ctx.app, repo, parent) : undefined; | |
| 187 | return html`<section class="card follow-panel" id="follow"> | |
| 188 | <div class="card-body"> | |
| 189 | <p class="following-sentence">${relationSentence(relation)}</p> | |
| 190 | <form method="post" action="${base}/following" class="following-actions"> | |
| 191 | <input type="hidden" name="do" value="mode" /> | |
| 192 | ${FOLLOW_MODES.map((m) => | |
| 193 | btn(MODE_WORDS[m][0], { | |
| 194 | size: "sm", | |
| 195 | type: "submit", | |
| 196 | name: "mode", | |
| 197 | value: m, | |
| 198 | variant: repo.followMode === m ? "primary" : "secondary", | |
| 199 | }), | |
| 200 | )} | |
| 201 | </form> | |
| 202 | <p class="muted small following-foot">${MODE_WORDS[repo.followMode][1]}</p> | |
| 203 | ${relation.ahead === 0 | |
| 204 | ? null | |
| 205 | : proposal === undefined | |
| 206 | ? html`<form method="post" action="${base}/following" class="following-actions"> | |
| 207 | <input type="hidden" name="do" value="propose" /> | |
| 208 | ${btn("Offer this change", { | |
| 209 | size: "sm", | |
| 210 | type: "submit", | |
| 211 | icon: "merge", | |
| 212 | })} | |
| 213 | </form>` | |
| 214 | : html`<p class="following-actions"> | |
| 215 | ${btn("See the offer", { | |
| 216 | size: "sm", | |
| 217 | href: `/${parent.ownerName}/${parent.name}/pulls/${proposal.number}`, | |
| 218 | })} | |
| 219 | </p>`} | |
| 220 | </div> | |
| 221 | </section>`; | |
| 222 | } | |
| 223 | ||
| 159 | 224 | /** |
| 160 | 225 | * The card on a fork's home. `studio` swaps nothing but the words for the |
| 161 | 226 | * crew's part; the mechanics are one and the same. |
| @@ -192,11 +257,11 @@ export function followingCard( | ||
| 192 | 257 | })} |
| 193 | 258 | </form>`, |
| 194 | 259 | ); |
| 195 | if (writer && conflict && converge === undefined && crew) | |
| 260 | if (writer && conflict && converge === undefined) | |
| 196 | 261 | actions.push( |
| 197 | 262 | html`<form method="post" action="${base}/following"> |
| 198 | 263 | <input type="hidden" name="do" value="converge" /> |
| 199 | ${btn("Converge with the crew", { | |
| 264 | ${btn(crew ? "Converge with the crew" : "Tell the crew", { | |
| 200 | 265 | size: "sm", |
| 201 | 266 | type: "submit", |
| 202 | 267 | variant: "primary", |
| @@ -212,39 +277,17 @@ export function followingCard( | ||
| 212 | 277 | }), |
| 213 | 278 | ); |
| 214 | 279 | |
| 215 | // The fork's own work, offered upstream in one click: the words come | |
| 216 | // from what landed here, so nothing waits on the crew. | |
| 217 | if (writer && relation.ahead > 0) { | |
| 218 | const proposal = openProposal(ctx.app, repo, parent); | |
| 219 | actions.push( | |
| 220 | proposal === undefined | |
| 221 | ? html`<form method="post" action="${base}/following"> | |
| 222 | <input type="hidden" name="do" value="propose" /> | |
| 223 | ${btn("Propose upstream", { | |
| 224 | size: "sm", | |
| 225 | type: "submit", | |
| 226 | icon: "merge", | |
| 227 | })} | |
| 228 | </form>` | |
| 229 | : btn("See the upstream proposal", { | |
| 230 | size: "sm", | |
| 231 | href: `/${parent.ownerName}/${parent.name}/pulls/${proposal.number}`, | |
| 232 | }), | |
| 233 | ); | |
| 234 | } | |
| 235 | ||
| 236 | 280 | const foot: Html | null = |
| 237 | 281 | converge === undefined |
| 238 | ? conflict | |
| 239 | ? crew | |
| 240 | ? writer | |
| 241 | ? null | |
| 242 | : html`A writer can ask the crew to converge it.` | |
| 243 | : html`Nobody is on the crew to converge it: add someone under | |
| 244 | <a href="${base}/settings/crew">Settings → Crew</a>, or merge | |
| 245 | <span class="mono">refs/following/${parent.defaultBranch}</span> | |
| 246 | by hand.` | |
| 282 | ? conflict && !writer | |
| 283 | ? html`A writer can ask the crew to converge it.` | |
| 247 | 284 | : null |
| 285 | : converge.kind === "told" | |
| 286 | ? html`Told to the crew on | |
| 287 | <a href="${base}/issues/${converge.issue.number}" | |
| 288 | >#${converge.issue.number}</a | |
| 289 | >; a builder takes it once someone joins | |
| 290 | <a href="${base}/settings/crew">the crew</a>.` | |
| 248 | 291 | : converge.kind === "working" |
| 249 | 292 | ? html`${converge.agent === undefined |
| 250 | 293 | ? "The crew" |
| @@ -321,6 +364,24 @@ export async function followingSubmit(ctx: Ctx): Promise<Response> { | ||
| 321 | 364 | }); |
| 322 | 365 | const parentName = `${parent.ownerName}/${parent.name}`; |
| 323 | 366 | |
| 367 | if (field(form, "do") === "mode") { | |
| 368 | const mode = field(form, "mode"); | |
| 369 | const to = `${base}/forks`; | |
| 370 | if (!isFollowMode(mode)) | |
| 371 | return flashOrJson(ctx, to, { | |
| 372 | tone: "danger", | |
| 373 | message: "Choose take green updates, tell me, or don't follow.", | |
| 374 | }); | |
| 375 | const set = setFollowMode(ctx.app, ctx.auth.user, repo, mode); | |
| 376 | if (!set.ok) | |
| 377 | return flashOrJson(ctx, to, { | |
| 378 | tone: "danger", | |
| 379 | message: "You need write access to choose how this follows.", | |
| 380 | }); | |
| 381 | return flashOrJson(ctx, to, { | |
| 382 | message: `${MODE_WORDS[mode][0]}: ${MODE_WORDS[mode][1]}`, | |
| 383 | }); | |
| 384 | } | |
| 324 | 385 | if (field(form, "do") === "converge") { |
| 325 | 386 | if (!canWrite(ctx.app.db, repo, ctx.auth.user)) |
| 326 | 387 | return flashOrJson(ctx, base, { |
| @@ -369,12 +430,17 @@ export async function followingSubmit(ctx: Ctx): Promise<Response> { | ||
| 369 | 430 | ? "This repository follows nothing." |
| 370 | 431 | : "You need write access to take updates here.", |
| 371 | 432 | }); |
| 433 | if (e.kind === "conflict") { | |
| 434 | const told = await convergeFork(ctx.app, repo, parent, ctx.auth.user); | |
| 435 | const said = convergeWords(told, parentName); | |
| 436 | return flashOrJson(ctx, base, { | |
| 437 | message: `${e.files.length === 1 ? "One file needs" : `${e.files.length} files need`} a decision (${e.files.join(", ")}). ${said.message}`, | |
| 438 | }); | |
| 439 | } | |
| 372 | 440 | return flashOrJson(ctx, base, { |
| 373 | 441 | tone: "danger", |
| 374 | 442 | message: |
| 375 | e.kind === "conflict" | |
| 376 | ? `${e.files.length === 1 ? "One file needs" : `${e.files.length} files need`} a decision (${e.files.join(", ")}); the crew can converge it.` | |
| 377 | : e.kind === "moved" | |
| 443 | e.kind === "moved" | |
| 378 | 444 | ? "Something moved while this was read; try again." |
| 379 | 445 | : `Git could not take the updates: ${e.message}`, |
| 380 | 446 | }); |
| @@ -417,11 +483,9 @@ function convergeWords( | ||
| 417 | 483 | ? "They merge cleanly; Take updates does it without the crew." |
| 418 | 484 | : "Nothing to converge.", |
| 419 | 485 | }; |
| 420 | case "no_crew": | |
| 486 | case "told": | |
| 421 | 487 | return { |
| 422 | tone: "danger", | |
| 423 | message: | |
| 424 | "Nobody is on the crew here; add someone under Settings → Crew.", | |
| 488 | message: `Issue #${outcome.issue.number} carries the files in conflict; it goes to a builder once someone joins the crew (Settings → Crew).`, | |
| 425 | 489 | }; |
| 426 | 490 | case "nobody": |
| 427 | 491 | return { |
src/web/pages/repo.ts +3 −1
| @@ -12,7 +12,7 @@ import { canRead, listForks, type Repo } from "../../core/repos.ts"; | ||
| 12 | 12 | import { FORKS_PER_DAY, forkRepo } from "../../actions/repos.ts"; |
| 13 | 13 | import { forkDrift, takeUpdates, type ForkDrift } from "../../actions/forks.ts"; |
| 14 | 14 | import { lineageOf } from "../../core/following.ts"; |
| 15 | import { followingCard, followingOf, lineageCard } from "./following.ts"; | |
| 15 | import { followingCard, followingOf, followPanel, lineageCard } from "./following.ts"; | |
| 16 | 16 | import { pinRepo, syncRepoNow, unpinRepo } from "../../actions/origins.ts"; |
| 17 | 17 | import { |
| 18 | 18 | canAdmin, |
| @@ -132,7 +132,9 @@ export async function forksPage(ctx: Ctx): Promise<Response> { | ||
| 132 | 132 | const lineage = await lineageOf(ctx.app, repo, (r) => |
| 133 | 133 | canRead(ctx.app.db, r, ctx.auth.user), |
| 134 | 134 | ); |
| 135 | const panel = await followPanel(ctx, repo); | |
| 135 | 136 | const body = html`${repoHeader(ctx, repo, "forks")} |
| 137 | ${panel} | |
| 136 | 138 | <div class="page-head mt"> |
| 137 | 139 | <h2>${forks.length} fork${forks.length === 1 ? "" : "s"}</h2> |
| 138 | 140 | </div> |
test/capacity.test.ts +5
| @@ -39,6 +39,11 @@ import { EGRESS_REPORTED } from "../src/kernel/vitals.ts"; | ||
| 39 | 39 | import { serve, type Servers } from "../src/http/server.ts"; |
| 40 | 40 | import { readRunLog } from "../src/runs/log.ts"; |
| 41 | 41 | |
| 42 | // The boot default honours the environment by design, and a check runs with | |
| 43 | // FORGE_CHECK_SHARDS set; these tests are about stored values against the | |
| 44 | // built-in defaults, so they start without it. | |
| 45 | delete process.env["FORGE_CHECK_SHARDS"]; | |
| 46 | ||
| 42 | 47 | describe("capacity: only a forge admin reads or changes it", () => { |
| 43 | 48 | let dataDir: string; |
| 44 | 49 | let app: App; |
test/follow_mode.test.ts added +173
| @@ -0,0 +1,173 @@ | ||
| 1 | /** | |
| 2 | * How a fork chooses to follow (#608): saved from the forks page and from | |
| 3 | * MCP, and honoured when the parent moves. | |
| 4 | */ | |
| 5 | import { afterAll, beforeAll, describe, expect, test } from "bun:test"; | |
| 6 | import { mkdtemp, rm } from "node:fs/promises"; | |
| 7 | import { tmpdir } from "node:os"; | |
| 8 | import { join } from "node:path"; | |
| 9 | import { createApp, type App } from "../src/app.ts"; | |
| 10 | import { commitToBranch, createRepo, forkRepo } from "../src/actions/repos.ts"; | |
| 11 | import { listEvents } from "../src/core/events.ts"; | |
| 12 | import { forkRelation } from "../src/core/following.ts"; | |
| 13 | import { getRepoById, type Repo } from "../src/core/repos.ts"; | |
| 14 | import { createToken } from "../src/core/tokens.ts"; | |
| 15 | import { createUser, type User } from "../src/core/users.ts"; | |
| 16 | import { serve, type Servers } from "../src/http/server.ts"; | |
| 17 | ||
| 18 | describe("a fork chooses how it follows", () => { | |
| 19 | let dataDir: string; | |
| 20 | let app: App; | |
| 21 | let servers: Servers; | |
| 22 | let base: string; | |
| 23 | let alice: User; | |
| 24 | let bob: User; | |
| 25 | let eve: User; | |
| 26 | let bobToken: string; | |
| 27 | let eveToken: string; | |
| 28 | let parent: Repo; | |
| 29 | const forks: Record<string, Repo> = {}; | |
| 30 | const tokens: Record<string, string> = {}; | |
| 31 | const fresh = (r: Repo) => getRepoById(app.db, r.id)!; | |
| 32 | const commit = (who: User, repo: Repo, path: string) => | |
| 33 | commitToBranch(app, who, repo, { | |
| 34 | message: path, | |
| 35 | files: [{ path, content: `${path}\n` }], | |
| 36 | }); | |
| 37 | const post = (token: string, repo: string, body: string) => | |
| 38 | fetch(`${base}/${repo}/following`, { | |
| 39 | method: "POST", | |
| 40 | headers: { | |
| 41 | authorization: `Bearer ${token}`, | |
| 42 | "content-type": "application/x-www-form-urlencoded", | |
| 43 | accept: "application/json", | |
| 44 | }, | |
| 45 | body, | |
| 46 | }); | |
| 47 | const mcp = async (token: string, name: string, args: unknown) => { | |
| 48 | const res = await fetch(`${base}/mcp`, { | |
| 49 | method: "POST", | |
| 50 | headers: { | |
| 51 | authorization: `Bearer ${token}`, | |
| 52 | "content-type": "application/json", | |
| 53 | }, | |
| 54 | body: JSON.stringify({ | |
| 55 | jsonrpc: "2.0", | |
| 56 | id: 1, | |
| 57 | method: "tools/call", | |
| 58 | params: { name, arguments: args }, | |
| 59 | }), | |
| 60 | }); | |
| 61 | const r = (await res.json()) as any; | |
| 62 | const text: string = r.result.content[0].text; | |
| 63 | return r.result.isError === true | |
| 64 | ? { error: text } | |
| 65 | : { value: JSON.parse(text) }; | |
| 66 | }; | |
| 67 | ||
| 68 | beforeAll(async () => { | |
| 69 | dataDir = await mkdtemp(join(tmpdir(), "forge-follow-mode-")); | |
| 70 | app = createApp({ dataDir, port: 0 }); | |
| 71 | servers = await serve(app); | |
| 72 | base = servers.url; | |
| 73 | const mk = async (username: string, first = false) => { | |
| 74 | const u = await createUser(app.db, { | |
| 75 | trusted: true, | |
| 76 | username, | |
| 77 | email: `${username}@forge.local`, | |
| 78 | password: "a-good-passphrase", | |
| 79 | adminIfFirst: first, | |
| 80 | }); | |
| 81 | if (!u.ok) throw new Error(u.error); | |
| 82 | tokens[username] = createToken(app.db, u.value.id, "t", "rw").token; | |
| 83 | return u.value; | |
| 84 | }; | |
| 85 | alice = await mk("alice", true); | |
| 86 | bob = await mk("bob"); | |
| 87 | eve = await mk("eve"); | |
| 88 | bobToken = tokens["bob"]!; | |
| 89 | eveToken = tokens["eve"]!; | |
| 90 | const made = await createRepo(app, alice, { name: "game", visibility: "public" }); | |
| 91 | if (!made.ok) throw new Error(String(made.error)); | |
| 92 | parent = made.value; | |
| 93 | await commit(alice, parent, "README.md"); | |
| 94 | for (const name of ["auto", "tell", "off"]) { | |
| 95 | const f = await forkRepo(app, name === "off" ? bob : await mk(`f${name}`), parent); | |
| 96 | if (!f.ok) throw new Error(String(f.error)); | |
| 97 | forks[name] = f.value; | |
| 98 | } | |
| 99 | }, 30_000); | |
| 100 | ||
| 101 | afterAll(async () => { | |
| 102 | servers.stop(); | |
| 103 | app.close(); | |
| 104 | await rm(dataDir, { recursive: true, force: true }); | |
| 105 | }); | |
| 106 | ||
| 107 | test("the owner saves a mode from the forks page; a stranger cannot", async () => { | |
| 108 | expect(fresh(forks["auto"]!).followMode).toBe("auto"); | |
| 109 | const page = await fetch(`${base}/ftell/game/forks`, { | |
| 110 | headers: { authorization: `Bearer ${tokens["ftell"]}`, accept: "text/html" }, | |
| 111 | }).then((r) => r.text()); | |
| 112 | expect(page).toContain("Take green updates"); | |
| 113 | expect(page).toContain("Tell me"); | |
| 114 | expect(page).toContain("Don't follow"); | |
| 115 | expect((await post(tokens["ftell"]!, "ftell/game", "do=mode&mode=tell")).status).toBe(200); | |
| 116 | expect((await post(bobToken, "bob/game", "do=mode&mode=off")).status).toBe(200); | |
| 117 | expect(fresh(forks["tell"]!).followMode).toBe("tell"); | |
| 118 | expect(fresh(forks["off"]!).followMode).toBe("off"); | |
| 119 | ||
| 120 | expect((await post(tokens["fauto"]!, "fauto/game", "do=mode&mode=bogus")).status).toBe(422); | |
| 121 | expect((await post(eveToken, "fauto/game", "do=mode&mode=off")).status).toBe(422); | |
| 122 | expect(fresh(forks["auto"]!).followMode).toBe("auto"); | |
| 123 | ||
| 124 | // A stranger's view of the same page carries no controls. | |
| 125 | const seen = await fetch(`${base}/ftell/game/forks`, { | |
| 126 | headers: { authorization: `Bearer ${eveToken}`, accept: "text/html" }, | |
| 127 | }).then((r) => r.text()); | |
| 128 | expect(seen).not.toContain("Tell me"); | |
| 129 | }); | |
| 130 | ||
| 131 | test("converge honours each mode when the parent moves", async () => { | |
| 132 | await commit(alice, parent, "levels.txt"); | |
| 133 | const tip = async (f: Repo) => | |
| 134 | (await forkRelation(app, fresh(f), fresh(parent)))!; | |
| 135 | const until = async (f: Repo) => { | |
| 136 | for (let i = 0; i < 100; i++) { | |
| 137 | if ((await tip(f)).state === "synced") return true; | |
| 138 | await Bun.sleep(40); | |
| 139 | } | |
| 140 | return false; | |
| 141 | }; | |
| 142 | expect(await until(forks["auto"]!)).toBe(true); | |
| 143 | // Give the others the same time; they must not have moved. | |
| 144 | await Bun.sleep(300); | |
| 145 | expect((await tip(forks["tell"]!)).state).toBe("behind"); | |
| 146 | expect((await tip(forks["off"]!)).state).toBe("behind"); | |
| 147 | ||
| 148 | const told = (f: Repo) => | |
| 149 | listEvents(app.db, { repoId: f.id }).filter((e) => e.kind === "fork.parent_moved"); | |
| 150 | expect(told(forks["tell"]!).length).toBe(1); | |
| 151 | expect(told(forks["off"]!).length).toBe(0); | |
| 152 | expect(told(forks["auto"]!).length).toBe(0); | |
| 153 | }); | |
| 154 | ||
| 155 | test("a fork ahead offers its change up from the forks page", async () => { | |
| 156 | await commit(bob, forks["off"]!, "mine.txt"); | |
| 157 | const page = () => | |
| 158 | fetch(`${base}/bob/game/forks`, { | |
| 159 | headers: { authorization: `Bearer ${bobToken}`, accept: "text/html" }, | |
| 160 | }).then((r) => r.text()); | |
| 161 | expect(await page()).toContain("Offer this change"); | |
| 162 | }); | |
| 163 | ||
| 164 | test("MCP reads and sets the mode", async () => { | |
| 165 | expect((await mcp(bobToken, "following", { repo: "bob/game" })).value.mode).toBe("off"); | |
| 166 | const set = await mcp(bobToken, "follow", { repo: "bob/game", mode: "auto" }); | |
| 167 | expect(set.value.mode).toBe("auto"); | |
| 168 | expect(fresh(forks["off"]!).followMode).toBe("auto"); | |
| 169 | expect((await mcp(bobToken, "follow", { repo: "bob/game", mode: "x" })).error).toBeDefined(); | |
| 170 | expect((await mcp(eveToken, "follow", { repo: "bob/game", mode: "off" })).error).toBeDefined(); | |
| 171 | expect((await mcp(bobToken, "follow", { repo: "alice/game", mode: "off" })).error).toBeDefined(); | |
| 172 | }); | |
| 173 | }); |
test/following.test.ts +20 −7
| @@ -240,7 +240,15 @@ describe("a fork that follows its parent", () => { | ||
| 240 | 240 | headers: { authorization: `Bearer ${bobToken}`, accept: "text/html" }, |
| 241 | 241 | }).then((p) => p.text()); |
| 242 | 242 | expect(page).toContain("one file needs a decision: README.md"); |
| 243 | expect(page).toContain("Nobody is on the crew"); | |
| 243 | // The refused take told the crew: one issue carries the files, unassigned | |
| 244 | // because nobody is on the crew yet. | |
| 245 | expect(page).toContain("Told to the crew on"); | |
| 246 | const told = listIssues(app.db, fork.id, { state: "open" }).filter( | |
| 247 | (i) => i.title === convergeTitle(parent), | |
| 248 | ); | |
| 249 | expect(told.length).toBe(1); | |
| 250 | expect(told[0]!.body).toContain("README.md"); | |
| 251 | expect(told[0]!.assigneeId).toBeNull(); | |
| 244 | 252 | }); |
| 245 | 253 | |
| 246 | 254 | test("the page form refuses a reader who cannot write, and opens nothing", async () => { |
| @@ -259,7 +267,7 @@ describe("a fork that follows its parent", () => { | ||
| 259 | 267 | expect(listIssues(app.db, fork.id, { state: "open" }).length).toBe(before); |
| 260 | 268 | }); |
| 261 | 269 | |
| 262 | test("without a crew, converging is refused honestly", async () => { | |
| 270 | test("without a crew, converging tells the crew and doubles nothing", async () => { | |
| 263 | 271 | const res = await fetch( |
| 264 | 272 | `${base}/api/v1/repos/bob/game/following/converge`, |
| 265 | 273 | { |
| @@ -267,8 +275,13 @@ describe("a fork that follows its parent", () => { | ||
| 267 | 275 | headers: as(bobToken), |
| 268 | 276 | }, |
| 269 | 277 | ); |
| 270 | expect(res.status).toBe(409); | |
| 271 | expect(((await res.json()) as { kind: string }).kind).toBe("no_crew"); | |
| 278 | expect(res.status).toBe(200); | |
| 279 | expect(((await res.json()) as { kind: string }).kind).toBe("told"); | |
| 280 | expect( | |
| 281 | listIssues(app.db, fork.id, { state: "open" }).filter( | |
| 282 | (i) => i.title === convergeTitle(parent), | |
| 283 | ).length, | |
| 284 | ).toBe(1); | |
| 272 | 285 | }); |
| 273 | 286 | |
| 274 | 287 | test("with a crew, converging opens one issue, stages the parent, queues one run", async () => { |
| @@ -606,11 +619,11 @@ describe("a fork that follows its parent", () => { | ||
| 606 | 619 | expect(k.opened).toBe(false); |
| 607 | 620 | expect(k.number).toBe(j.number); |
| 608 | 621 | |
| 609 | // The card offers the way to it now, not another proposal. | |
| 622 | // The forks page offers the way to it now, not another proposal. | |
| 610 | 623 | const page = await ( |
| 611 | await fetch(`${base}/bob/game`, { headers: as(bobToken) }) | |
| 624 | await fetch(`${base}/bob/game/forks`, { headers: as(bobToken) }) | |
| 612 | 625 | ).text(); |
| 613 | expect(page).toContain("See the upstream proposal"); | |
| 626 | expect(page).toContain("See the offer"); | |
| 614 | 627 | expect(page).not.toContain('value="propose"'); |
| 615 | 628 | }); |
| 616 | 629 |
test/mcp.test.ts +2 −1
| @@ -170,6 +170,7 @@ describe("the forge over MCP", () => { | ||
| 170 | 170 | "outsiders", |
| 171 | 171 | "probe", |
| 172 | 172 | "following", |
| 173 | "follow", | |
| 173 | 174 | "spawn", |
| 174 | 175 | "forges", |
| 175 | 176 | "claim_link", |
| @@ -374,7 +375,7 @@ describe("the forge over MCP", () => { | ||
| 374 | 375 | ).toContain("write access"); |
| 375 | 376 | expect( |
| 376 | 377 | (await tool(bobRw, "converge", { repo: "bob/open" })).value.kind, |
| 377 | ).toBe("no_crew"); | |
| 378 | ).toBe("told"); | |
| 378 | 379 | }); |
| 379 | 380 | |
| 380 | 381 | test("probe only reads, yet needs the access the page needs", async () => { |
new above
offline