Public: anyone can read this; the crew can change it.
One page shows my forge's upstream and downstream flows: what I follow, what I offered, what my forks offered me #17079
Check · Review · Land · Live — Landed; it goes live with the next production release.
scout/forge:scout/17056-one-page-shows-my-forge-s-upstream-and-d → main 0 commits fork 4 threads · 4 unresolved
24 files
changed +641
−162
- docs/design/audit.md
- docs/features/fork-flows.md
- src/contract/openapi/routes/getApiV1ForksFlows.ts
- src/contract/openapi/routes/index.ts
- src/core/empty_words.ts
- src/core/fork_flows.ts
- src/core/reserved.ts
- src/generated/marks.ts
- src/http/api/upstream.ts
- src/http/marks/api-v1-forks.json
- src/http/marks/forks.json
- src/http/mcp/tools/fork_flows.ts
- src/http/mcp/tools/index.ts
- src/http/server.ts
- src/tui/forge.ts
- src/tui/screens/forkflows.ts
- src/web/empty_words.ts
- src/web/pages/family.ts
- src/web/pages/fork-flows.ts
- src/web/pages/repo.ts
- test/fork-flows.test.ts
- test/mcp-forge-protocol.test.ts
- test/palette-roster.test.ts
- test/private-by-default.test.ts
docs/design/audit.md +1
| @@ -105,6 +105,7 @@ Machine routes are not pages and have no entry: `/audit.csv`, | ||
| 105 | 105 | |
| 106 | 106 | ### Forges (the family) |
| 107 | 107 | |
| 108 | - `/forks/flows` — `pages/fork-flows.ts` · what this forge follows, what it offered upstream and what its forks offered it, three lists · `/forges`, `/family` · none seen; reuses the list and muted text. | |
| 108 | 109 | - `/forges` — `pages/forges.ts` · the forges this one sent, as a client list · `/family` · colour 1. |
| 109 | 110 | - `/forges/refused` — `pages/forges-refused.ts` · the last 20 first asks the forge refused, with its words; an admin's only · `/system` · none seen; reuses the list and muted text. |
| 110 | 111 | - `/forges/archive` — `pages/forges.ts` · what archiving does for the forges named, and the one button · `/forges` · colour 1; reuses the list and button. |
docs/features/fork-flows.md added +22
| @@ -0,0 +1,22 @@ | ||
| 1 | --- | |
| 2 | topic: What a forge is | |
| 3 | row: Fork flows: what I follow, what I offered, what my forks offered me | |
| 4 | --- | |
| 5 | # Fork flows | |
| 6 | ||
| 7 | One page for the fork family in both directions (#17056). It reads stored state only, so it answers in milliseconds. | |
| 8 | ||
| 9 | - **What I follow:** each repository you administer that follows a parent: the parent, where it stands (`synced`, `behind N`, `ahead N`, `diverged`, or `unknown` when nothing has counted the two tips since they moved), and when it last took updates. | |
| 10 | - **Upstream:** the offers you sent, each `waiting`, `taken`, `declined` or `withdrawn`, linking its pull. | |
| 11 | - **Downstream:** open offers your forks made into your repositories, linking their pulls. | |
| 12 | ||
| 13 | A fork you may not read is never named. | |
| 14 | ||
| 15 | ## Where | |
| 16 | ||
| 17 | - Web: `/forks/flows` (signed in), linked from `/family` (signed in) and from a repository's forks page; `/forges` has no room for it. Source: `src/web/pages/fork-flows.ts`. | |
| 18 | - API: `GET /api/v1/forks/flows` returns `{ follows, sent, offered }`. | |
| 19 | - MCP: the tool `fork_flows`, with no arguments, returns the same. | |
| 20 | - Terminal: the palette entry "Fork flows" (`src/tui/screens/forkflows.ts`); `g` reads again. | |
| 21 | ||
| 22 | All four read `forkFlows` in `src/core/fork_flows.ts`. |
src/contract/openapi/routes/getApiV1ForksFlows.ts added +13
| @@ -0,0 +1,13 @@ | ||
| 1 | import type { Route } from "../shared.ts"; | |
| 2 | ||
| 3 | export const route: Route = { | |
| 4 | method: "get", | |
| 5 | path: "/api/v1/forks/flows", | |
| 6 | summary: "Your fork family both ways: what you follow, offered, and were offered", | |
| 7 | detail: | |
| 8 | "Your fork family in both directions, from stored state alone: follows (each repository you administer that follows a readable parent: repo, parent, standing as synced, behind N, ahead N, diverged or unknown when nothing has counted the tips, tookAt: when it last took updates, or null), sent (offers you made upstream: repo, parent, number, title, state waiting, taken, declined or withdrawn, createdAt, href) and offered (open offers your forks made into your repositories: repo, fork, number, title, createdAt, href); a fork you may not read is absent; carries a weak ETag", | |
| 9 | alsoStatus: [304], | |
| 10 | auth: true, | |
| 11 | role: "member", | |
| 12 | refuses: [401], | |
| 13 | }; |
src/contract/openapi/routes/index.ts +1
| @@ -120,6 +120,7 @@ export { route as getApiV1ForgesNameSandbox } from "./getApiV1ForgesNameSandbox. | ||
| 120 | 120 | export { route as getApiV1ForgesRecipes } from "./getApiV1ForgesRecipes.ts"; |
| 121 | 121 | export { route as getApiV1ForgesSizes } from "./getApiV1ForgesSizes.ts"; |
| 122 | 122 | export { route as getApiV1ForgesTemplates } from "./getApiV1ForgesTemplates.ts"; |
| 123 | export { route as getApiV1ForksFlows } from "./getApiV1ForksFlows.ts"; | |
| 123 | 124 | export { route as getApiV1Front } from "./getApiV1Front.ts"; |
| 124 | 125 | export { route as getApiV1Health } from "./getApiV1Health.ts"; |
| 125 | 126 | export { route as getApiV1Here } from "./getApiV1Here.ts"; |
src/core/empty_words.ts +1
| @@ -58,6 +58,7 @@ const TABLE = { | ||
| 58 | 58 | releases: { sentence: "No releases yet.", reason: "A pull landed on the forge's own repository is recorded here." }, |
| 59 | 59 | builds: { sentence: "No builds yet.", label: "Pin one from a branch" }, |
| 60 | 60 | forks: { sentence: "No forks yet.", reason: "A fork is a copy under another name that can propose changes back here, and follows this one until it has work of its own." }, |
| 61 | forkFlows: { sentence: "No fork family flows here yet.", reason: "A repository you administer that follows a parent, or that forks have offered changes to, shows up here." }, | |
| 61 | 62 | repos: { sentence: "No repositories yet.", label: "New repository", href: "/new" }, |
| 62 | 63 | commits: { sentence: "No commits yet.", reason: "Push a branch and its history shows up here." }, |
| 63 | 64 | issues: { sentence: "No issues yet." }, |
src/core/fork_flows.ts added +100
| @@ -0,0 +1,100 @@ | ||
| 1 | /** | |
| 2 | * My forge's fork family in both directions, from stored state alone (#17056): what each repository | |
| 3 | * I administer follows (the parent, its kept standing, when it last took updates), what I offered | |
| 4 | * upstream (`sentOffers`), and what my forks offered into my repositories (`forkOffers`). The page, | |
| 5 | * `GET /api/v1/forks/flows`, MCP `fork_flows` and the terminal screen all read this one function. | |
| 6 | * Standing is `keptStanding`, never a git compare: a pair nothing has counted says "unknown". A | |
| 7 | * parent or fork the viewer cannot read is never named (`forkParentFor`, `visibleForks`). | |
| 8 | */ | |
| 9 | ||
| 10 | import type { Database } from "bun:sqlite"; | |
| 11 | import { keptStanding } from "./following.ts"; | |
| 12 | import { forkOffers, sentOffers, type SentOfferState } from "./fork_offers.ts"; | |
| 13 | import { lastTookAt } from "./fork_follow.ts"; | |
| 14 | import { canAdmin, forkParentFor, listReposWritableTo, type Repo } from "./repos.ts"; | |
| 15 | import type { User } from "./users.ts"; | |
| 16 | ||
| 17 | /** Repositories read per call: what one person administers, bounded. */ | |
| 18 | const MAX_FLOW_REPOS = 100; | |
| 19 | ||
| 20 | export interface FollowRow { | |
| 21 | readonly repo: string; | |
| 22 | readonly parent: string; | |
| 23 | /** | |
| 24 | * `synced`, `behind 3`, `ahead 2`, `diverged`, or `unknown` when nothing has counted the tips. | |
| 25 | */ | |
| 26 | readonly standing: string; | |
| 27 | readonly tookAt: string | null; | |
| 28 | } | |
| 29 | ||
| 30 | export interface SentRow { | |
| 31 | readonly repo: string; | |
| 32 | readonly parent: string; | |
| 33 | readonly number: number; | |
| 34 | readonly title: string; | |
| 35 | readonly state: SentOfferState; | |
| 36 | readonly createdAt: string; | |
| 37 | /** The pull, on the parent's page. */ | |
| 38 | readonly href: string; | |
| 39 | } | |
| 40 | ||
| 41 | export interface OfferedRow { | |
| 42 | /** My repository the offer was made into. */ | |
| 43 | readonly repo: string; | |
| 44 | readonly fork: string; | |
| 45 | readonly number: number; | |
| 46 | readonly title: string; | |
| 47 | readonly createdAt: string; | |
| 48 | readonly href: string; | |
| 49 | } | |
| 50 | ||
| 51 | export interface ForkFlows { | |
| 52 | readonly follows: FollowRow[]; | |
| 53 | readonly sent: SentRow[]; | |
| 54 | readonly offered: OfferedRow[]; | |
| 55 | } | |
| 56 | ||
| 57 | /** The kept standing in words; no git is asked. */ | |
| 58 | export function standingWords(standing: readonly [string, number, number, ...unknown[]] | undefined): string { | |
| 59 | if (standing === undefined) return "unknown"; | |
| 60 | const [state, behind, ahead] = standing; | |
| 61 | if (state === "behind") return `behind ${behind}`; | |
| 62 | if (state === "ahead") return `ahead ${ahead}`; | |
| 63 | return state; | |
| 64 | } | |
| 65 | ||
| 66 | /** | |
| 67 | * The repositories the viewer administers, newest first: the filter runs before the bound, paging | |
| 68 | * the read. | |
| 69 | */ | |
| 70 | function administered(db: Database, viewer: User): Repo[] { | |
| 71 | const out: Repo[] = []; | |
| 72 | let cursor: string | undefined; | |
| 73 | while (out.length < MAX_FLOW_REPOS) { | |
| 74 | const page = listReposWritableTo(db, viewer, { limit: 100, ...(cursor === undefined ? {} : { cursor }), withoutArchived: true, withoutCounts: true }); | |
| 75 | for (const r of page) if (out.length < MAX_FLOW_REPOS && canAdmin(db, r, viewer)) out.push(r); | |
| 76 | if (page.length < 100) break; | |
| 77 | cursor = page[page.length - 1]!.id; | |
| 78 | } | |
| 79 | return out; | |
| 80 | } | |
| 81 | ||
| 82 | export function forkFlows(forge: { db: Database; reposRoot: string }, viewer: User | undefined): ForkFlows { | |
| 83 | const out: { follows: FollowRow[]; sent: SentRow[]; offered: OfferedRow[] } = { follows: [], sent: [], offered: [] }; | |
| 84 | if (viewer === undefined) return out; | |
| 85 | const { db } = forge; | |
| 86 | const mine = administered(db, viewer); | |
| 87 | for (const repo of mine) { | |
| 88 | const name = `${repo.ownerName}/${repo.name}`; | |
| 89 | const parent = repo.forkParentId === null ? undefined : forkParentFor(db, repo, viewer); | |
| 90 | if (parent !== undefined) { | |
| 91 | const parentName = `${parent.ownerName}/${parent.name}`; | |
| 92 | out.follows.push({ repo: name, parent: parentName, standing: standingWords(keptStanding(forge, repo, parent)), tookAt: lastTookAt(db, repo.id) }); | |
| 93 | for (const o of sentOffers(db, repo, viewer)) | |
| 94 | out.sent.push({ repo: name, parent: parentName, number: o.number, title: o.title, state: o.state, createdAt: o.createdAt, href: `/${parentName}/pulls/${o.number}` }); | |
| 95 | } | |
| 96 | for (const o of forkOffers(db, repo, viewer)) | |
| 97 | out.offered.push({ repo: name, fork: o.fork, number: o.number, title: o.title, createdAt: o.createdAt, href: `/${name}/pulls/${o.number}` }); | |
| 98 | } | |
| 99 | return out; | |
| 100 | } |
src/core/reserved.ts +1
src/generated/marks.ts +166 −162
| @@ -37,168 +37,170 @@ import k32 from "../http/marks/api-v1-flow.json"; | ||
| 37 | 37 | import k33 from "../http/marks/api-v1-forge-templates.json"; |
| 38 | 38 | import k34 from "../http/marks/api-v1-forge.json"; |
| 39 | 39 | import k35 from "../http/marks/api-v1-forges.json"; |
| 40 | import k36 from "../http/marks/api-v1-front.json"; | |
| 41 | import k37 from "../http/marks/api-v1-games.json"; | |
| 42 | import k38 from "../http/marks/api-v1-health.json"; | |
| 43 | import k39 from "../http/marks/api-v1-heartbeat.json"; | |
| 44 | import k40 from "../http/marks/api-v1-here.json"; | |
| 45 | import k41 from "../http/marks/api-v1-keeper.json"; | |
| 46 | import k42 from "../http/marks/api-v1-maintenance.json"; | |
| 47 | import k43 from "../http/marks/api-v1-map.json"; | |
| 48 | import k44 from "../http/marks/api-v1-migrate.json"; | |
| 49 | import k45 from "../http/marks/api-v1-offers.json"; | |
| 50 | import k46 from "../http/marks/api-v1-openapi.json.json"; | |
| 51 | import k47 from "../http/marks/api-v1-orgs.json"; | |
| 52 | import k48 from "../http/marks/api-v1-packs.json"; | |
| 53 | import k49 from "../http/marks/api-v1-passport.json"; | |
| 54 | import k50 from "../http/marks/api-v1-places.json"; | |
| 55 | import k51 from "../http/marks/api-v1-plans.json"; | |
| 56 | import k52 from "../http/marks/api-v1-proof.json"; | |
| 57 | import k53 from "../http/marks/api-v1-reach.json"; | |
| 58 | import k54 from "../http/marks/api-v1-release.json"; | |
| 59 | import k55 from "../http/marks/api-v1-releases.json"; | |
| 60 | import k56 from "../http/marks/api-v1-repos.json"; | |
| 61 | import k57 from "../http/marks/api-v1-returns.json"; | |
| 62 | import k58 from "../http/marks/api-v1-runner.json"; | |
| 63 | import k59 from "../http/marks/api-v1-search.json"; | |
| 64 | import k60 from "../http/marks/api-v1-secrets.json"; | |
| 65 | import k61 from "../http/marks/api-v1-sessions.json"; | |
| 66 | import k62 from "../http/marks/api-v1-share.json"; | |
| 67 | import k63 from "../http/marks/api-v1-slash.json"; | |
| 68 | import k64 from "../http/marks/api-v1-start.json"; | |
| 69 | import k65 from "../http/marks/api-v1-status.json"; | |
| 70 | import k66 from "../http/marks/api-v1-telemetry.json"; | |
| 71 | import k67 from "../http/marks/api-v1-templates.json"; | |
| 72 | import k68 from "../http/marks/api-v1-thoughts.json"; | |
| 73 | import k69 from "../http/marks/api-v1-timers.json"; | |
| 74 | import k70 from "../http/marks/api-v1-tokens.json"; | |
| 75 | import k71 from "../http/marks/api-v1-usage.json"; | |
| 76 | import k72 from "../http/marks/api-v1-user.json"; | |
| 77 | import k73 from "../http/marks/api-v1-users.json"; | |
| 78 | import k74 from "../http/marks/api-v1-version.json"; | |
| 79 | import k75 from "../http/marks/api-v1.json"; | |
| 80 | import k76 from "../http/marks/api.json"; | |
| 81 | import k77 from "../http/marks/apple-touch-icon-precomposed.png.json"; | |
| 82 | import k78 from "../http/marks/apple-touch-icon.png.json"; | |
| 83 | import k79 from "../http/marks/apps.json"; | |
| 84 | import k80 from "../http/marks/asked.json"; | |
| 85 | import k81 from "../http/marks/asks.json"; | |
| 86 | import k82 from "../http/marks/assets.json"; | |
| 87 | import k83 from "../http/marks/audit.csv.json"; | |
| 88 | import k84 from "../http/marks/audit.json"; | |
| 89 | import k85 from "../http/marks/big.json"; | |
| 90 | import k86 from "../http/marks/board.json"; | |
| 91 | import k87 from "../http/marks/boards.json"; | |
| 92 | import k88 from "../http/marks/bring.json"; | |
| 93 | import k89 from "../http/marks/broker.json"; | |
| 94 | import k90 from "../http/marks/changelog.atom.json"; | |
| 95 | import k91 from "../http/marks/changelog.json"; | |
| 96 | import k92 from "../http/marks/claim.json"; | |
| 97 | import k93 from "../http/marks/cloud.json"; | |
| 98 | import k94 from "../http/marks/cockpit.json"; | |
| 99 | import k95 from "../http/marks/contract.json"; | |
| 100 | import k96 from "../http/marks/contribute.json"; | |
| 101 | import k97 from "../http/marks/csp-report.json"; | |
| 102 | import k98 from "../http/marks/dash.json"; | |
| 103 | import k99 from "../http/marks/data.json"; | |
| 104 | import k100 from "../http/marks/dataset.json"; | |
| 105 | import k101 from "../http/marks/deploy-to.json"; | |
| 106 | import k102 from "../http/marks/design.json"; | |
| 107 | import k103 from "../http/marks/desk.json"; | |
| 108 | import k104 from "../http/marks/displays.json"; | |
| 109 | import k105 from "../http/marks/docs.json"; | |
| 110 | import k106 from "../http/marks/edge.json"; | |
| 111 | import k107 from "../http/marks/edition.json"; | |
| 112 | import k108 from "../http/marks/events.json"; | |
| 113 | import k109 from "../http/marks/explore.atom.json"; | |
| 114 | import k110 from "../http/marks/explore.json"; | |
| 115 | import k111 from "../http/marks/explore.json.json"; | |
| 116 | import k112 from "../http/marks/family.json"; | |
| 117 | import k113 from "../http/marks/favicon.ico.json"; | |
| 118 | import k114 from "../http/marks/feed.json"; | |
| 119 | import k115 from "../http/marks/feed.json.json"; | |
| 120 | import k116 from "../http/marks/first-admin.json"; | |
| 121 | import k117 from "../http/marks/fleet.json"; | |
| 122 | import k118 from "../http/marks/flow.json"; | |
| 123 | import k119 from "../http/marks/forge.json"; | |
| 124 | import k120 from "../http/marks/forges.json"; | |
| 125 | import k121 from "../http/marks/front.json"; | |
| 126 | import k122 from "../http/marks/funnel.json"; | |
| 127 | import k123 from "../http/marks/games.json"; | |
| 128 | import k124 from "../http/marks/go.json"; | |
| 129 | import k125 from "../http/marks/health.json"; | |
| 130 | import k126 from "../http/marks/home.json"; | |
| 131 | import k127 from "../http/marks/hooks.json"; | |
| 132 | import k128 from "../http/marks/icons.json"; | |
| 133 | import k129 from "../http/marks/infra.json"; | |
| 134 | import k130 from "../http/marks/join.json"; | |
| 135 | import k131 from "../http/marks/live.json"; | |
| 136 | import k132 from "../http/marks/llms-full.txt.json"; | |
| 137 | import k133 from "../http/marks/llms.txt.json"; | |
| 138 | import k134 from "../http/marks/login.json"; | |
| 139 | import k135 from "../http/marks/logout.json"; | |
| 140 | import k136 from "../http/marks/maintenance-json.json"; | |
| 141 | import k137 from "../http/marks/maintenance.json"; | |
| 142 | import k138 from "../http/marks/manifest.webmanifest.json"; | |
| 143 | import k139 from "../http/marks/map.json"; | |
| 144 | import k140 from "../http/marks/mcp.json"; | |
| 145 | import k141 from "../http/marks/measure.json"; | |
| 146 | import k142 from "../http/marks/metrics.json"; | |
| 147 | import k143 from "../http/marks/migrate.json"; | |
| 148 | import k144 from "../http/marks/new.json"; | |
| 149 | import k145 from "../http/marks/next.json"; | |
| 150 | import k146 from "../http/marks/notes.json"; | |
| 151 | import k147 from "../http/marks/now.json"; | |
| 152 | import k148 from "../http/marks/oauth.json"; | |
| 153 | import k149 from "../http/marks/oembed.json"; | |
| 154 | import k150 from "../http/marks/offers.json"; | |
| 155 | import k151 from "../http/marks/offline.json"; | |
| 156 | import k152 from "../http/marks/og.json"; | |
| 157 | import k153 from "../http/marks/openapi.json.json"; | |
| 158 | import k154 from "../http/marks/opensearch.xml.json"; | |
| 159 | import k155 from "../http/marks/organizations.json"; | |
| 160 | import k156 from "../http/marks/origins.json"; | |
| 161 | import k157 from "../http/marks/owner.atom.json"; | |
| 162 | import k158 from "../http/marks/owner.json"; | |
| 163 | import k159 from "../http/marks/packs.json"; | |
| 164 | import k160 from "../http/marks/peek.json"; | |
| 165 | import k161 from "../http/marks/pinned.json"; | |
| 166 | import k162 from "../http/marks/pipeline.json"; | |
| 167 | import k163 from "../http/marks/plugins.json"; | |
| 168 | import k164 from "../http/marks/pricing.json"; | |
| 169 | import k165 from "../http/marks/privacy.json"; | |
| 170 | import k166 from "../http/marks/r.json"; | |
| 171 | import k167 from "../http/marks/recover.json"; | |
| 172 | import k168 from "../http/marks/releases.json"; | |
| 173 | import k169 from "../http/marks/releases.json.json"; | |
| 174 | import k170 from "../http/marks/repos.json"; | |
| 175 | import k171 from "../http/marks/resilience.json"; | |
| 176 | import k172 from "../http/marks/review.json"; | |
| 177 | import k173 from "../http/marks/robots.txt.json"; | |
| 178 | import k174 from "../http/marks/root.json"; | |
| 179 | import k175 from "../http/marks/runs.json"; | |
| 180 | import k176 from "../http/marks/script-error.json"; | |
| 181 | import k177 from "../http/marks/search.json"; | |
| 182 | import k178 from "../http/marks/security.json"; | |
| 183 | import k179 from "../http/marks/settings.json"; | |
| 184 | import k180 from "../http/marks/sign-in.json"; | |
| 185 | import k181 from "../http/marks/signin.json"; | |
| 186 | import k182 from "../http/marks/signup.json"; | |
| 187 | import k183 from "../http/marks/sitemap.xml.json"; | |
| 188 | import k184 from "../http/marks/status.json"; | |
| 189 | import k185 from "../http/marks/sw.js.json"; | |
| 190 | import k186 from "../http/marks/system.json"; | |
| 191 | import k187 from "../http/marks/talk.json"; | |
| 192 | import k188 from "../http/marks/tell.json"; | |
| 193 | import k189 from "../http/marks/templates.json"; | |
| 194 | import k190 from "../http/marks/templates.json.json"; | |
| 195 | import k191 from "../http/marks/terms.json"; | |
| 196 | import k192 from "../http/marks/theme.json"; | |
| 197 | import k193 from "../http/marks/toolbar-lab.js.json"; | |
| 198 | import k194 from "../http/marks/toolbar-lab.json"; | |
| 199 | import k195 from "../http/marks/verify.json"; | |
| 200 | import k196 from "../http/marks/welcome.json"; | |
| 201 | import k197 from "../http/marks/well-known.json"; | |
| 40 | import k36 from "../http/marks/api-v1-forks.json"; | |
| 41 | import k37 from "../http/marks/api-v1-front.json"; | |
| 42 | import k38 from "../http/marks/api-v1-games.json"; | |
| 43 | import k39 from "../http/marks/api-v1-health.json"; | |
| 44 | import k40 from "../http/marks/api-v1-heartbeat.json"; | |
| 45 | import k41 from "../http/marks/api-v1-here.json"; | |
| 46 | import k42 from "../http/marks/api-v1-keeper.json"; | |
| 47 | import k43 from "../http/marks/api-v1-maintenance.json"; | |
| 48 | import k44 from "../http/marks/api-v1-map.json"; | |
| 49 | import k45 from "../http/marks/api-v1-migrate.json"; | |
| 50 | import k46 from "../http/marks/api-v1-offers.json"; | |
| 51 | import k47 from "../http/marks/api-v1-openapi.json.json"; | |
| 52 | import k48 from "../http/marks/api-v1-orgs.json"; | |
| 53 | import k49 from "../http/marks/api-v1-packs.json"; | |
| 54 | import k50 from "../http/marks/api-v1-passport.json"; | |
| 55 | import k51 from "../http/marks/api-v1-places.json"; | |
| 56 | import k52 from "../http/marks/api-v1-plans.json"; | |
| 57 | import k53 from "../http/marks/api-v1-proof.json"; | |
| 58 | import k54 from "../http/marks/api-v1-reach.json"; | |
| 59 | import k55 from "../http/marks/api-v1-release.json"; | |
| 60 | import k56 from "../http/marks/api-v1-releases.json"; | |
| 61 | import k57 from "../http/marks/api-v1-repos.json"; | |
| 62 | import k58 from "../http/marks/api-v1-returns.json"; | |
| 63 | import k59 from "../http/marks/api-v1-runner.json"; | |
| 64 | import k60 from "../http/marks/api-v1-search.json"; | |
| 65 | import k61 from "../http/marks/api-v1-secrets.json"; | |
| 66 | import k62 from "../http/marks/api-v1-sessions.json"; | |
| 67 | import k63 from "../http/marks/api-v1-share.json"; | |
| 68 | import k64 from "../http/marks/api-v1-slash.json"; | |
| 69 | import k65 from "../http/marks/api-v1-start.json"; | |
| 70 | import k66 from "../http/marks/api-v1-status.json"; | |
| 71 | import k67 from "../http/marks/api-v1-telemetry.json"; | |
| 72 | import k68 from "../http/marks/api-v1-templates.json"; | |
| 73 | import k69 from "../http/marks/api-v1-thoughts.json"; | |
| 74 | import k70 from "../http/marks/api-v1-timers.json"; | |
| 75 | import k71 from "../http/marks/api-v1-tokens.json"; | |
| 76 | import k72 from "../http/marks/api-v1-usage.json"; | |
| 77 | import k73 from "../http/marks/api-v1-user.json"; | |
| 78 | import k74 from "../http/marks/api-v1-users.json"; | |
| 79 | import k75 from "../http/marks/api-v1-version.json"; | |
| 80 | import k76 from "../http/marks/api-v1.json"; | |
| 81 | import k77 from "../http/marks/api.json"; | |
| 82 | import k78 from "../http/marks/apple-touch-icon-precomposed.png.json"; | |
| 83 | import k79 from "../http/marks/apple-touch-icon.png.json"; | |
| 84 | import k80 from "../http/marks/apps.json"; | |
| 85 | import k81 from "../http/marks/asked.json"; | |
| 86 | import k82 from "../http/marks/asks.json"; | |
| 87 | import k83 from "../http/marks/assets.json"; | |
| 88 | import k84 from "../http/marks/audit.csv.json"; | |
| 89 | import k85 from "../http/marks/audit.json"; | |
| 90 | import k86 from "../http/marks/big.json"; | |
| 91 | import k87 from "../http/marks/board.json"; | |
| 92 | import k88 from "../http/marks/boards.json"; | |
| 93 | import k89 from "../http/marks/bring.json"; | |
| 94 | import k90 from "../http/marks/broker.json"; | |
| 95 | import k91 from "../http/marks/changelog.atom.json"; | |
| 96 | import k92 from "../http/marks/changelog.json"; | |
| 97 | import k93 from "../http/marks/claim.json"; | |
| 98 | import k94 from "../http/marks/cloud.json"; | |
| 99 | import k95 from "../http/marks/cockpit.json"; | |
| 100 | import k96 from "../http/marks/contract.json"; | |
| 101 | import k97 from "../http/marks/contribute.json"; | |
| 102 | import k98 from "../http/marks/csp-report.json"; | |
| 103 | import k99 from "../http/marks/dash.json"; | |
| 104 | import k100 from "../http/marks/data.json"; | |
| 105 | import k101 from "../http/marks/dataset.json"; | |
| 106 | import k102 from "../http/marks/deploy-to.json"; | |
| 107 | import k103 from "../http/marks/design.json"; | |
| 108 | import k104 from "../http/marks/desk.json"; | |
| 109 | import k105 from "../http/marks/displays.json"; | |
| 110 | import k106 from "../http/marks/docs.json"; | |
| 111 | import k107 from "../http/marks/edge.json"; | |
| 112 | import k108 from "../http/marks/edition.json"; | |
| 113 | import k109 from "../http/marks/events.json"; | |
| 114 | import k110 from "../http/marks/explore.atom.json"; | |
| 115 | import k111 from "../http/marks/explore.json"; | |
| 116 | import k112 from "../http/marks/explore.json.json"; | |
| 117 | import k113 from "../http/marks/family.json"; | |
| 118 | import k114 from "../http/marks/favicon.ico.json"; | |
| 119 | import k115 from "../http/marks/feed.json"; | |
| 120 | import k116 from "../http/marks/feed.json.json"; | |
| 121 | import k117 from "../http/marks/first-admin.json"; | |
| 122 | import k118 from "../http/marks/fleet.json"; | |
| 123 | import k119 from "../http/marks/flow.json"; | |
| 124 | import k120 from "../http/marks/forge.json"; | |
| 125 | import k121 from "../http/marks/forges.json"; | |
| 126 | import k122 from "../http/marks/forks.json"; | |
| 127 | import k123 from "../http/marks/front.json"; | |
| 128 | import k124 from "../http/marks/funnel.json"; | |
| 129 | import k125 from "../http/marks/games.json"; | |
| 130 | import k126 from "../http/marks/go.json"; | |
| 131 | import k127 from "../http/marks/health.json"; | |
| 132 | import k128 from "../http/marks/home.json"; | |
| 133 | import k129 from "../http/marks/hooks.json"; | |
| 134 | import k130 from "../http/marks/icons.json"; | |
| 135 | import k131 from "../http/marks/infra.json"; | |
| 136 | import k132 from "../http/marks/join.json"; | |
| 137 | import k133 from "../http/marks/live.json"; | |
| 138 | import k134 from "../http/marks/llms-full.txt.json"; | |
| 139 | import k135 from "../http/marks/llms.txt.json"; | |
| 140 | import k136 from "../http/marks/login.json"; | |
| 141 | import k137 from "../http/marks/logout.json"; | |
| 142 | import k138 from "../http/marks/maintenance-json.json"; | |
| 143 | import k139 from "../http/marks/maintenance.json"; | |
| 144 | import k140 from "../http/marks/manifest.webmanifest.json"; | |
| 145 | import k141 from "../http/marks/map.json"; | |
| 146 | import k142 from "../http/marks/mcp.json"; | |
| 147 | import k143 from "../http/marks/measure.json"; | |
| 148 | import k144 from "../http/marks/metrics.json"; | |
| 149 | import k145 from "../http/marks/migrate.json"; | |
| 150 | import k146 from "../http/marks/new.json"; | |
| 151 | import k147 from "../http/marks/next.json"; | |
| 152 | import k148 from "../http/marks/notes.json"; | |
| 153 | import k149 from "../http/marks/now.json"; | |
| 154 | import k150 from "../http/marks/oauth.json"; | |
| 155 | import k151 from "../http/marks/oembed.json"; | |
| 156 | import k152 from "../http/marks/offers.json"; | |
| 157 | import k153 from "../http/marks/offline.json"; | |
| 158 | import k154 from "../http/marks/og.json"; | |
| 159 | import k155 from "../http/marks/openapi.json.json"; | |
| 160 | import k156 from "../http/marks/opensearch.xml.json"; | |
| 161 | import k157 from "../http/marks/organizations.json"; | |
| 162 | import k158 from "../http/marks/origins.json"; | |
| 163 | import k159 from "../http/marks/owner.atom.json"; | |
| 164 | import k160 from "../http/marks/owner.json"; | |
| 165 | import k161 from "../http/marks/packs.json"; | |
| 166 | import k162 from "../http/marks/peek.json"; | |
| 167 | import k163 from "../http/marks/pinned.json"; | |
| 168 | import k164 from "../http/marks/pipeline.json"; | |
| 169 | import k165 from "../http/marks/plugins.json"; | |
| 170 | import k166 from "../http/marks/pricing.json"; | |
| 171 | import k167 from "../http/marks/privacy.json"; | |
| 172 | import k168 from "../http/marks/r.json"; | |
| 173 | import k169 from "../http/marks/recover.json"; | |
| 174 | import k170 from "../http/marks/releases.json"; | |
| 175 | import k171 from "../http/marks/releases.json.json"; | |
| 176 | import k172 from "../http/marks/repos.json"; | |
| 177 | import k173 from "../http/marks/resilience.json"; | |
| 178 | import k174 from "../http/marks/review.json"; | |
| 179 | import k175 from "../http/marks/robots.txt.json"; | |
| 180 | import k176 from "../http/marks/root.json"; | |
| 181 | import k177 from "../http/marks/runs.json"; | |
| 182 | import k178 from "../http/marks/script-error.json"; | |
| 183 | import k179 from "../http/marks/search.json"; | |
| 184 | import k180 from "../http/marks/security.json"; | |
| 185 | import k181 from "../http/marks/settings.json"; | |
| 186 | import k182 from "../http/marks/sign-in.json"; | |
| 187 | import k183 from "../http/marks/signin.json"; | |
| 188 | import k184 from "../http/marks/signup.json"; | |
| 189 | import k185 from "../http/marks/sitemap.xml.json"; | |
| 190 | import k186 from "../http/marks/status.json"; | |
| 191 | import k187 from "../http/marks/sw.js.json"; | |
| 192 | import k188 from "../http/marks/system.json"; | |
| 193 | import k189 from "../http/marks/talk.json"; | |
| 194 | import k190 from "../http/marks/tell.json"; | |
| 195 | import k191 from "../http/marks/templates.json"; | |
| 196 | import k192 from "../http/marks/templates.json.json"; | |
| 197 | import k193 from "../http/marks/terms.json"; | |
| 198 | import k194 from "../http/marks/theme.json"; | |
| 199 | import k195 from "../http/marks/toolbar-lab.js.json"; | |
| 200 | import k196 from "../http/marks/toolbar-lab.json"; | |
| 201 | import k197 from "../http/marks/verify.json"; | |
| 202 | import k198 from "../http/marks/welcome.json"; | |
| 203 | import k199 from "../http/marks/well-known.json"; | |
| 202 | 204 | |
| 203 | 205 | /** Each file of `http/marks/`, parsed, in name order. */ |
| 204 | 206 | export const MARK_FILES: readonly unknown[] = [ |
| @@ -400,4 +402,6 @@ export const MARK_FILES: readonly unknown[] = [ | ||
| 400 | 402 | k195, |
| 401 | 403 | k196, |
| 402 | 404 | k197, |
| 405 | k198, | |
| 406 | k199, | |
| 403 | 407 | ]; |
src/http/api/upstream.ts +16
| @@ -18,6 +18,7 @@ import { | ||
| 18 | 18 | setFollowUpstream, |
| 19 | 19 | } from "../../actions/upstream_follow.ts"; |
| 20 | 20 | import { ENABLED_WORDS } from "../../core/arg_words.ts"; |
| 21 | import { forkFlows } from "../../core/fork_flows.ts"; | |
| 21 | 22 | import { followWords } from "../../actions/follow.ts"; |
| 22 | 23 | import { driftOfForks, MAX_RANKED_FORKS, type RankedFork } from "../../actions/forks.ts"; |
| 23 | 24 | import { canAdmin, forkParentFor, visibleForks } from "../../core/repos.ts"; |
| @@ -94,6 +95,21 @@ export function upstreamRoutes(router: Router<Handler>): void { | ||
| 94 | 95 | return json(checked.value); |
| 95 | 96 | }); |
| 96 | 97 | |
| 98 | // The fork family in both directions, from stored state (#17056): the page and MCP `fork_flows` | |
| 99 | // say the same. | |
| 100 | router.add("GET", "/api/v1/forks/flows", (ctx) => { | |
| 101 | notePhase(ctx.request, "session", takeSessionTime(ctx.request)); | |
| 102 | const denied = requireScope(ctx, "ro"); | |
| 103 | if (denied) return denied; | |
| 104 | return timePhase(ctx.request, "render", () => { | |
| 105 | const text = JSON.stringify(forkFlows(ctx.app, ctx.auth.user)); | |
| 106 | const etag = weakEtag(text); | |
| 107 | const headers = { etag, "cache-control": "private, no-cache", vary: "authorization, cookie" }; | |
| 108 | if (holds(ctx.request, etag)) return new Response(null, { status: 304, headers }); | |
| 109 | return new Response(text, { headers: { "content-type": "application/json", ...headers } }); | |
| 110 | }); | |
| 111 | }); | |
| 112 | ||
| 97 | 113 | // The nested tree, apart from the flat page above it so that page's contract is untouched. |
| 98 | 114 | router.add("GET", "/api/v1/repos/:owner/:name/forks/tree", async (ctx) => { |
| 99 | 115 | notePhase(ctx.request, "session", takeSessionTime(ctx.request)); |
src/http/marks/api-v1-forks.json added +4
src/http/mcp/tools/fork_flows.ts added +11
| @@ -0,0 +1,11 @@ | ||
| 1 | import { forkFlows } from "../../../core/fork_flows.ts"; | |
| 2 | import { good, type Tool } from "../shared.ts"; | |
| 3 | ||
| 4 | export const tool: Tool = { | |
| 5 | name: "fork_flows", | |
| 6 | doc: "`{}`: your fork family in both directions, as /forks/flows and GET `/api/v1/forks/flows` answer it: `follows` (each repository you administer that follows a parent: `repo`, `parent`, `standing` as `synced`, `behind N`, `ahead N`, `diverged` or `unknown`, `tookAt`), `sent` (offers you made upstream: `repo`, `parent`, `number`, `title`, `state` waiting, taken, declined or withdrawn, `href`) and `offered` (open offers your forks made into your repositories: `repo`, `fork`, `number`, `title`, `href`); stored state only, a fork you may not read is absent; read-only", | |
| 7 | description: "Your forks' upstream and downstream flows: what you follow, offered, and were offered.", | |
| 8 | inputSchema: { type: "object", properties: {} }, | |
| 9 | writes: false, | |
| 10 | run: (ctx, user) => good(forkFlows(ctx.app, user)), | |
| 11 | }; |
src/http/mcp/tools/index.ts +1
| @@ -87,6 +87,7 @@ export { tool as forge_proposals } from "./forge_proposals.ts"; | ||
| 87 | 87 | export { tool as forge_view } from "./forge_view.ts"; |
| 88 | 88 | export { tool as forges } from "./forges.ts"; |
| 89 | 89 | export { tool as fork } from "./fork.ts"; |
| 90 | export { tool as fork_flows } from "./fork_flows.ts"; | |
| 90 | 91 | export { tool as fork_tree } from "./fork_tree.ts"; |
| 91 | 92 | export { tool as forks } from "./forks.ts"; |
| 92 | 93 | export { tool as front_page } from "./front_page.ts"; |
src/http/server.ts +2
| @@ -266,6 +266,7 @@ import { | ||
| 266 | 266 | branchesPage, |
| 267 | 267 | } from "../web/pages/branches.ts"; |
| 268 | 268 | import { sentOffersPage } from "../web/pages/fork-offers.ts"; |
| 269 | import { forkFlowsPage } from "../web/pages/fork-flows.ts"; | |
| 269 | 270 | import { offerCommitPost, offerPullPost, offerWithdrawPost } from "../web/pages/offer-upstream.ts"; |
| 270 | 271 | import { offerReceiptPage } from "../web/pages/offer-receipt.ts"; |
| 271 | 272 | import { iterationsPage, noteSubmit } from "../web/pages/iterations.ts"; |
| @@ -1220,6 +1221,7 @@ export function buildRouter(): Router<Handler> { | ||
| 1220 | 1221 | router.add("POST", "/fleet", fleetAct); |
| 1221 | 1222 | router.add("GET", "/fleet/ops/:id", fleetReceipt); |
| 1222 | 1223 | router.add("POST", "/fleet/ops/:id/undo", fleetUndo); |
| 1224 | router.add("GET", "/forks/flows", forkFlowsPage); | |
| 1223 | 1225 | router.add("GET", "/fleet/graph", fleetGraphPage); |
| 1224 | 1226 | router.add("GET", "/fleet/graph/live", fleetGraphLive); |
| 1225 | 1227 | router.add("GET", "/fleet/graph.csv", fleetGraphCsv); |
src/tui/forge.ts +10
| @@ -78,6 +78,7 @@ import { flagsScreen } from "./screens/flags.ts"; | ||
| 78 | 78 | import { forgeUsageScreen } from "./screens/forge_usage.ts"; |
| 79 | 79 | import { usageScreen } from "./screens/usage.ts"; |
| 80 | 80 | import { canScreen } from "./screens/can.ts"; |
| 81 | import { forkFlowsScreen } from "./screens/forkflows.ts"; | |
| 81 | 82 | import { modelScreen } from "./screens/model.ts"; |
| 82 | 83 | import { notifyScreen } from "./screens/notify.ts"; |
| 83 | 84 | import { talkBuildScreen } from "./screens/talk_build.ts"; |
| @@ -551,6 +552,15 @@ export function forgeCommands(session: Session): (ctx: Ctx) => Command[] { | ||
| 551 | 552 | hint: "list, add and remove the keys that sign in as you", |
| 552 | 553 | run: () => ctx.push(sshKeysScreen(session, ctx)), |
| 553 | 554 | }); |
| 555 | // /forks/flows, GET /api/v1/forks/flows and MCP `fork_flows`: one function, `forkFlows` | |
| 556 | // (#17056). | |
| 557 | if (session.signedIn) | |
| 558 | commands.push({ | |
| 559 | id: "fork-flows", | |
| 560 | title: "Fork flows", | |
| 561 | hint: "what I follow, what I offered, what my forks offered me", | |
| 562 | run: () => ctx.push(forkFlowsScreen(session, ctx)), | |
| 563 | }); | |
| 554 | 564 | // Settings › Passkeys and MCP `whoami_can kind: passkeys`, read only (#8044). |
| 555 | 565 | if (session.signedIn && session.user?.kind !== "agent") |
| 556 | 566 | commands.push({ |
src/tui/screens/forkflows.ts added +52
| @@ -0,0 +1,52 @@ | ||
| 1 | /** | |
| 2 | * My forge's fork family in both directions, in the terminal: what I follow and where it stands, | |
| 3 | * what I offered upstream, what my forks offered me. The rows are `forkFlows`, the one function | |
| 4 | * behind /forks/flows, GET /api/v1/forks/flows and MCP `fork_flows` (#17056); stored state only. | |
| 5 | */ | |
| 6 | ||
| 7 | import { agoWords } from "../../actions/follow_words.ts"; | |
| 8 | import { EMPTY_WORDS } from "../../core/empty_words.ts"; | |
| 9 | import { forkFlows, type ForkFlows } from "../../core/fork_flows.ts"; | |
| 10 | import type { Ctx, Screen } from "../app/app.ts"; | |
| 11 | import { binding } from "../app/keys.ts"; | |
| 12 | import type { Session } from "../session.ts"; | |
| 13 | import { fill, len, split } from "../ui/layout.ts"; | |
| 14 | import { emptyState } from "../ui/widgets.ts"; | |
| 15 | import { ListState, drawList, type ListRow } from "./common.ts"; | |
| 16 | ||
| 17 | /** The rows the screen draws, pure so a test reads them without a terminal. */ | |
| 18 | export function flowRows(f: ForkFlows): ListRow[] { | |
| 19 | return [ | |
| 20 | ...f.follows.map((r) => ({ title: `${r.repo} follows ${r.parent}`, secondary: r.standing, meta: r.tookAt === null ? "never took updates" : `took updates ${agoWords(r.tookAt)}` })), | |
| 21 | ...f.sent.map((r) => ({ title: `Upstream: ${r.repo} → ${r.parent} #${r.number} ${r.title}`, secondary: r.state, meta: agoWords(r.createdAt) })), | |
| 22 | ...f.offered.map((r) => ({ title: `Downstream: ${r.fork} → ${r.repo} #${r.number} ${r.title}`, secondary: "open", meta: agoWords(r.createdAt) })), | |
| 23 | ]; | |
| 24 | } | |
| 25 | ||
| 26 | export function forkFlowsScreen(f: Session, ctx: Ctx): Screen { | |
| 27 | const state = new ListState(); | |
| 28 | const rows = (): ListRow[] => flowRows(forkFlows(f.app, f.user)); | |
| 29 | let shown = rows(); | |
| 30 | const screen: Screen = { | |
| 31 | title: "Fork flows", | |
| 32 | keys: [binding(["j", "k"], "move cursor"), binding(["g"], "read again")], | |
| 33 | render(area, s) { | |
| 34 | const c = ctx.theme.c; | |
| 35 | const [, body] = split(area, "v", [len(1), fill(1)]); | |
| 36 | if (shown.length === 0) { | |
| 37 | emptyState(s, body!, c, { title: EMPTY_WORDS.forkFlows.sentence }); | |
| 38 | return; | |
| 39 | } | |
| 40 | drawList(s, body!, c, state, shown); | |
| 41 | }, | |
| 42 | key(e) { | |
| 43 | if (state.key(e, shown.length)) return true; | |
| 44 | if (e.ctrl || e.alt || e.key !== "g") return false; | |
| 45 | shown = rows(); | |
| 46 | state.clamp(shown.length); | |
| 47 | ctx.invalidate(); | |
| 48 | return true; | |
| 49 | }, | |
| 50 | }; | |
| 51 | return screen; | |
| 52 | } |
src/web/empty_words.ts +1
src/web/pages/family.ts +1
| @@ -163,6 +163,7 @@ export async function familyPage( | ||
| 163 | 163 | </ul> |
| 164 | 164 | ${kids.more > 0 ? html`<p class="muted small">${plural(kids.more, "more forge")} not shown.</p>` : null} |
| 165 | 165 | ${alone ? html`<p class="muted small">No parent, and none sent.</p>` : null} |
| 166 | ${ctx.auth.user === undefined ? null : html`<p class="muted small" data-fork-flows-link><a href="/forks/flows">Fork flows</a></p>`} | |
| 166 | 167 | </div>`, |
| 167 | 168 | }); |
| 168 | 169 | notePhase(ctx.request, "render", performance.now() - rendering); |
src/web/pages/fork-flows.ts added +35
| @@ -0,0 +1,35 @@ | ||
| 1 | /** GET /forks/flows: the fork family's two directions on one page, from stored state (#17056). */ | |
| 2 | ||
| 3 | import { agoWords } from "../../actions/follow_words.ts"; | |
| 4 | import { forkFlows } from "../../core/fork_flows.ts"; | |
| 5 | import { notePhase, takeSessionTime } from "../../core/route_timing.ts"; | |
| 6 | import type { Ctx } from "../../http/context.ts"; | |
| 7 | import { pageHead, signInFirst } from "../chrome.ts"; | |
| 8 | import { emptyList } from "../empty_words.ts"; | |
| 9 | import { html } from "../html.ts"; | |
| 10 | import { page } from "../layout.ts"; | |
| 11 | import { listCard, row, time } from "../ui.ts"; | |
| 12 | ||
| 13 | export function forkFlowsPage(ctx: Ctx): Response { | |
| 14 | notePhase(ctx.request, "session", takeSessionTime(ctx.request)); | |
| 15 | const user = ctx.auth.user; | |
| 16 | if (user === undefined) return signInFirst(ctx); | |
| 17 | const reading = performance.now(); | |
| 18 | const f = forkFlows(ctx.app, user); | |
| 19 | const empty = f.follows.length + f.sent.length + f.offered.length === 0; | |
| 20 | const when = (at: string) => time(at, { text: agoWords(at) }); | |
| 21 | const body = empty | |
| 22 | ? emptyList("forkFlows") | |
| 23 | : html`${f.follows.length === 0 ? null : html`<h2>What I follow</h2>${listCard(f.follows.map((r) => | |
| 24 | row({ href: `/${r.repo}/forks`, nav: true, title: html`${r.repo} follows ${r.parent}`, meta: html`<span data-standing>${r.standing}</span> <span>${r.tookAt === null ? "never took updates" : html`took updates ${when(r.tookAt)}`}</span>` })))}`} | |
| 25 | ${f.sent.length === 0 ? null : html`<h2>Upstream: what I offered</h2>${listCard(f.sent.map((r) => | |
| 26 | row({ href: r.href, nav: true, title: r.title, num: r.number, meta: html`<span>${r.repo} → ${r.parent}</span> <span>${r.state}</span> <span>${when(r.createdAt)}</span>` })))}`} | |
| 27 | ${f.offered.length === 0 ? null : html`<h2>Downstream: what my forks offered</h2>${listCard(f.offered.map((r) => | |
| 28 | row({ href: r.href, nav: true, title: r.title, num: r.number, meta: html`<span>${r.fork} → ${r.repo}</span> <span>${when(r.createdAt)}</span>` })))}`}`; | |
| 29 | notePhase(ctx.request, "render", performance.now() - reading); | |
| 30 | return page({ | |
| 31 | ctx, | |
| 32 | title: "Fork flows", | |
| 33 | body: html`<div class="narrow-wide" data-fork-flows>${pageHead("Fork flows")}${body}</div>`, | |
| 34 | }); | |
| 35 | } |
src/web/pages/repo.ts +1
| @@ -228,6 +228,7 @@ export async function forksPage(ctx: Ctx): Promise<Response> { | ||
| 228 | 228 | <div class="page-head mt"> |
| 229 | 229 | <h2${countAttr(BIND.rest)}>${forks.length} fork${forks.length === 1 ? "" : "s"}</h2> |
| 230 | 230 | </div> |
| 231 | <p class="muted small" data-fork-flows-link><a href="/forks/flows">Fork flows</a></p> | |
| 231 | 232 | ${lineage.size === 1 |
| 232 | 233 | ? emptyList("forks", { noAction: true, bind: BIND.rest }) |
| 233 | 234 | : html`${forkRanking(ranked, new Map(tree.map((n) => [n.repo.id, n])), BIND.rest, forkModes, (fork, parent) => keptBehind(ctx.app, fork, parent), forkFollowed)} |
test/fork-flows.test.ts added +193
| @@ -0,0 +1,193 @@ | ||
| 1 | /** | |
| 2 | * The fork family's two directions on one page, one API route and one MCP tool, from one function | |
| 3 | * (#17056): what I follow, what I offered upstream, what my forks offered me; a fork the viewer | |
| 4 | * may not read is never named. | |
| 5 | */ | |
| 6 | import { afterAll, beforeAll, describe, expect, test } from "bun:test"; | |
| 7 | import { mkdtemp, rm } from "node:fs/promises"; | |
| 8 | import { tmpdir } from "node:os"; | |
| 9 | import { join } from "node:path"; | |
| 10 | import { commitToBranch, createRepo, forkRepo, updateRepoSettings } from "../src/actions/repos.ts"; | |
| 11 | import { mergePull, openPull } from "../src/actions/pulls.ts"; | |
| 12 | import { setIssueState } from "../src/actions/issues.ts"; | |
| 13 | import { getPull } from "../src/core/pulls.ts"; | |
| 14 | import { markForkOfferWithdrawn } from "../src/core/fork_offer.ts"; | |
| 15 | import { theme } from "../src/tui/ui/theme.ts"; | |
| 16 | import type { Ctx } from "../src/tui/app/app.ts"; | |
| 17 | import { Session } from "../src/tui/forge.ts"; | |
| 18 | import { Screen as Surface } from "../src/tui/term/screen.ts"; | |
| 19 | import { createApp, type App } from "../src/app.ts"; | |
| 20 | import { forkFlows, standingWords } from "../src/core/fork_flows.ts"; | |
| 21 | import { createToken } from "../src/core/tokens.ts"; | |
| 22 | import { createUser, type User } from "../src/core/users.ts"; | |
| 23 | import { serve, type Servers } from "../src/http/server.ts"; | |
| 24 | import { forkFlowsScreen, flowRows } from "../src/tui/screens/forkflows.ts"; | |
| 25 | import { promote } from "./helpers/members.ts"; | |
| 26 | import { mcpTool } from "./helpers/mcp.ts"; | |
| 27 | import type { Repo } from "../src/core/repos.ts"; | |
| 28 | ||
| 29 | describe("fork flows", () => { | |
| 30 | let dir: string; | |
| 31 | let app: App; | |
| 32 | let servers: Servers; | |
| 33 | let lib: Repo; | |
| 34 | const users: Record<string, User> = {}; | |
| 35 | const tokens: Record<string, string> = {}; | |
| 36 | ||
| 37 | const offer = async (user: User, fork: Repo, title: string, branch = "feature") => { | |
| 38 | const pushed = await commitToBranch(app, user, fork, { branch, message: title, files: [{ path: `${branch}-${user.username}.txt`, content: "x\n" }] }); | |
| 39 | if (!pushed.ok) throw new Error(JSON.stringify(pushed.error)); | |
| 40 | const pull = await openPull(app, user, lib, { title, baseBranch: "main", headBranch: branch, headRepo: fork }); | |
| 41 | if (!pull.ok) throw new Error(JSON.stringify(pull.error)); | |
| 42 | return pull.value; | |
| 43 | }; | |
| 44 | ||
| 45 | beforeAll(async () => { | |
| 46 | dir = await mkdtemp(join(tmpdir(), "forge-fork-flows-")); | |
| 47 | app = createApp({ dataDir: dir, port: 0 }); | |
| 48 | servers = await serve(app); | |
| 49 | // The first account is the site admin, who reads everything: the people under test are not. | |
| 50 | for (const [name, first] of [["zed", true], ["alice", false], ["bob", false], ["carol", false], ["dave", false], ["erin", false]] as const) { | |
| 51 | const made = await createUser(app.db, { origin: "seed", trusted: true, username: name, email: `${name}@forge.local`, password: "a-good-passphrase", adminIfFirst: first }); | |
| 52 | if (!made.ok) throw new Error(made.error); | |
| 53 | users[name] = made.value; | |
| 54 | tokens[name] = createToken(app.db, made.value.id, "t", "ro").token; | |
| 55 | } | |
| 56 | promote(app.db, users["alice"]!, users["bob"]!, users["carol"]!, users["dave"]!, users["erin"]!); | |
| 57 | const made = await createRepo(app, users["alice"]!, { name: "lib", visibility: "public" }); | |
| 58 | if (!made.ok) throw new Error(String(made.error)); | |
| 59 | lib = made.value; | |
| 60 | const seeded = await commitToBranch(app, users["alice"]!, lib, { message: "Start", files: [{ path: "README.md", content: "# lib\n" }] }); | |
| 61 | if (!seeded.ok) throw new Error(JSON.stringify(seeded.error)); | |
| 62 | for (const who of ["bob", "carol"] as const) { | |
| 63 | const fork = await forkRepo(app, users[who]!, lib, undefined, { visibility: "public" }); | |
| 64 | if (!fork.ok) throw new Error(String(fork.error)); | |
| 65 | if (who === "carol") { | |
| 66 | const closed = await updateRepoSettings(app, users[who]!, fork.value, { visibility: "private" }); | |
| 67 | if (!closed.ok) throw new Error(String(closed.error)); | |
| 68 | } | |
| 69 | await offer(users[who]!, fork.value, `From ${who}`); | |
| 70 | } | |
| 71 | }); | |
| 72 | ||
| 73 | afterAll(async () => { | |
| 74 | servers.stop(); | |
| 75 | await rm(dir, { recursive: true, force: true }); | |
| 76 | }); | |
| 77 | ||
| 78 | test("standing is said from the kept count, unknown when nothing counted it", () => { | |
| 79 | expect(standingWords(["synced", 0, 0, true, []])).toBe("synced"); | |
| 80 | expect(standingWords(["behind", 3, 0, true, []])).toBe("behind 3"); | |
| 81 | expect(standingWords(["ahead", 0, 2, true, []])).toBe("ahead 2"); | |
| 82 | expect(standingWords(["diverged", 1, 1, false, []])).toBe("diverged"); | |
| 83 | expect(standingWords(undefined)).toBe("unknown"); | |
| 84 | }); | |
| 85 | ||
| 86 | test("upstream: a fork's own flows are what it follows and what it offered", () => { | |
| 87 | const f = forkFlows(app, users["bob"]); | |
| 88 | expect(f.follows.map((r) => [r.repo, r.parent, r.standing, r.tookAt])).toEqual([["bob/lib", "alice/lib", "synced", null]]); | |
| 89 | expect(f.sent.map((r) => [r.title, r.state, r.href])).toEqual([["From bob", "waiting", `/alice/lib/pulls/${f.sent[0]!.number}`]]); | |
| 90 | expect(f.offered).toEqual([]); | |
| 91 | }); | |
| 92 | ||
| 93 | test("a moved parent reads unknown, never a fresh git compare", async () => { | |
| 94 | const moved = await commitToBranch(app, users["alice"]!, lib, { message: "Move", files: [{ path: "more.txt", content: "y\n" }] }); | |
| 95 | if (!moved.ok) throw new Error(JSON.stringify(moved.error)); | |
| 96 | expect(forkFlows(app, users["bob"]).follows[0]!.standing).toBe("unknown"); | |
| 97 | }); | |
| 98 | ||
| 99 | test("downstream: the owner sees a visible fork's offer and never a private fork's", () => { | |
| 100 | const f = forkFlows(app, users["alice"]); | |
| 101 | expect(f.follows).toEqual([]); | |
| 102 | expect(f.offered.map((r) => [r.fork, r.title])).toEqual([["bob/lib", "From bob"]]); | |
| 103 | expect(JSON.stringify(f)).not.toContain("carol"); | |
| 104 | expect(JSON.stringify(f)).not.toContain("From carol"); | |
| 105 | }); | |
| 106 | ||
| 107 | test("an empty forge: nothing followed, nothing offered", () => { | |
| 108 | expect(forkFlows(app, users["dave"])).toEqual({ follows: [], sent: [], offered: [] }); | |
| 109 | expect(forkFlows(app, undefined)).toEqual({ follows: [], sent: [], offered: [] }); | |
| 110 | }); | |
| 111 | ||
| 112 | test("the page lists both directions, links the pull, hides the private fork, says the empty word", async () => { | |
| 113 | const as = (who: string) => fetch(`${servers.url}/forks/flows`, { headers: { authorization: `Bearer ${tokens[who]}` } }); | |
| 114 | const alice = await as("alice"); | |
| 115 | expect(alice.status).toBe(200); | |
| 116 | const body = await alice.text(); | |
| 117 | const number = forkFlows(app, users["alice"]).offered[0]!.number; | |
| 118 | expect(body).toContain("Downstream: what my forks offered"); | |
| 119 | expect(body).toContain(`href="/alice/lib/pulls/${number}"`); | |
| 120 | expect(body).toContain("bob/lib"); | |
| 121 | expect(body).not.toContain("carol/lib"); | |
| 122 | expect(body).not.toContain("From carol"); | |
| 123 | expect(alice.headers.get("server-timing")).toContain("render"); | |
| 124 | const bob = await (await as("bob")).text(); | |
| 125 | expect(bob).toContain("bob/lib follows alice/lib"); | |
| 126 | expect(bob).toContain("waiting"); | |
| 127 | expect(await (await as("dave")).text()).toContain("No fork family flows here yet."); | |
| 128 | expect((await fetch(`${servers.url}/forks/flows`, { redirect: "manual" })).status).not.toBe(200); | |
| 129 | }); | |
| 130 | ||
| 131 | test("the API answers the same data, with an etag, and refuses a stranger", async () => { | |
| 132 | const get = (who?: string, extra: Record<string, string> = {}) => | |
| 133 | fetch(`${servers.url}/api/v1/forks/flows`, { headers: { ...(who === undefined ? {} : { authorization: `Bearer ${tokens[who]}` }), ...extra } }); | |
| 134 | const res = await get("alice"); | |
| 135 | expect(res.status).toBe(200); | |
| 136 | expect(await res.json()).toEqual(JSON.parse(JSON.stringify(forkFlows(app, users["alice"])))); | |
| 137 | const etag = res.headers.get("etag")!; | |
| 138 | expect((await get("alice", { "if-none-match": etag })).status).toBe(304); | |
| 139 | expect((await get()).status).toBe(401); | |
| 140 | }); | |
| 141 | ||
| 142 | test("the MCP tool answers the same data", async () => { | |
| 143 | const got = await mcpTool(servers.url, tokens["bob"]!, "fork_flows"); | |
| 144 | expect(got.value).toEqual(JSON.parse(JSON.stringify(forkFlows(app, users["bob"])))); | |
| 145 | const alice = await mcpTool(servers.url, tokens["alice"]!, "fork_flows"); | |
| 146 | expect(JSON.stringify(alice.value)).not.toContain("carol"); | |
| 147 | }); | |
| 148 | ||
| 149 | test("a fork that took updates says when, and its sent offers read taken, declined, withdrawn", async () => { | |
| 150 | const erin = users["erin"]!; | |
| 151 | const fork = await forkRepo(app, erin, lib, undefined, { visibility: "public" }); | |
| 152 | if (!fork.ok) throw new Error(String(fork.error)); | |
| 153 | const taken = await offer(erin, fork.value, "Taken one", "a"); | |
| 154 | const declined = await offer(erin, fork.value, "Declined one", "b"); | |
| 155 | const withdrawn = await offer(erin, fork.value, "Withdrawn one", "c"); | |
| 156 | const merged = await mergePull(app, users["alice"]!, lib, getPull(app.db, lib.id, taken.number)!, "merge"); | |
| 157 | if (!merged.ok) throw new Error(JSON.stringify(merged.error)); | |
| 158 | const closed = setIssueState(app, users["alice"]!, lib, getPull(app.db, lib.id, declined.number)!, "closed"); | |
| 159 | if (!closed.ok) throw new Error(JSON.stringify(closed.error)); | |
| 160 | const pulled = getPull(app.db, lib.id, withdrawn.number)!; | |
| 161 | markForkOfferWithdrawn(app.db, pulled.id, erin.id); | |
| 162 | const setClosed = setIssueState(app, erin, lib, pulled, "closed"); | |
| 163 | if (!setClosed.ok) throw new Error(JSON.stringify(setClosed.error)); | |
| 164 | app.bus.append({ kind: "push", repoId: fork.value.id, actorId: erin.id, payload: { updates: [], followed: "alice/lib" } }); | |
| 165 | const f = forkFlows(app, erin); | |
| 166 | expect(f.follows[0]!.tookAt).not.toBeNull(); | |
| 167 | expect(f.sent.map((r) => [r.title, r.state])).toEqual([["Withdrawn one", "withdrawn"], ["Declined one", "declined"], ["Taken one", "taken"]]); | |
| 168 | expect(await (await fetch(`${servers.url}/forks/flows`, { headers: { authorization: `Bearer ${tokens["erin"]}` } })).text()).toContain("took updates"); | |
| 169 | }); | |
| 170 | ||
| 171 | test("the terminal draws the same rows, and the empty word", async () => { | |
| 172 | const rows = flowRows(forkFlows(app, users["bob"])); | |
| 173 | expect(rows.map((r) => r.title)).toEqual(["bob/lib follows alice/lib", `Upstream: bob/lib → alice/lib #${forkFlows(app, users["bob"]).sent[0]!.number} From bob`]); | |
| 174 | const draw = (who: string) => { | |
| 175 | const ctx = { theme: theme("dark"), invalidate() {}, toast() {}, push() {}, pop() {}, copy() {}, hit() {}, setCursor() {} } as unknown as Ctx; | |
| 176 | const screen = forkFlowsScreen(new Session(app, { sshUsername: who, remoteAddress: "127.0.0.1", fingerprint: "SHA256:test", user: users[who] }), ctx); | |
| 177 | const surface = new Surface(110, 20); | |
| 178 | screen.render({ x: 0, y: 0, w: 110, h: 20 }, surface); | |
| 179 | return surface.toText(); | |
| 180 | }; | |
| 181 | const bob = draw("bob"); | |
| 182 | expect(bob).toContain("bob/lib follows alice/lib"); | |
| 183 | expect(bob).toContain("From bob"); | |
| 184 | expect(draw("dave")).toContain("No fork family flows here yet."); | |
| 185 | }); | |
| 186 | ||
| 187 | test("it is linked from /family and from a repository's forks page", async () => { | |
| 188 | const forks = await (await fetch(`${servers.url}/alice/lib/forks`)).text(); | |
| 189 | expect(forks).toContain('href="/forks/flows"'); | |
| 190 | const family = await (await fetch(`${servers.url}/family`, { headers: { authorization: `Bearer ${tokens["bob"]}` } })).text(); | |
| 191 | expect(family).toContain('href="/forks/flows"'); | |
| 192 | }); | |
| 193 | }); |
test/mcp-forge-protocol.test.ts +1
test/palette-roster.test.ts +3
| @@ -115,6 +115,7 @@ test("a site-admin person is offered the whole roster", () => { | ||
| 115 | 115 | ["build-app", "Build an app", "say what to build; versions, diff, restore and publish. n starts one"], |
| 116 | 116 | ["fetch-page", "Read a web page", "paste an https link; the page as Markdown, as Talk's agent reads it"], |
| 117 | 117 | ["ssh-keys", "Computer keys", "list, add and remove the keys that sign in as you"], |
| 118 | ["fork-flows", "Fork flows", "what I follow, what I offered, what my forks offered me"], | |
| 118 | 119 | ["passkeys", "Passkeys", "the passkeys that sign in as you"], |
| 119 | 120 | ["account", "Account settings", undefined], |
| 120 | 121 | ["signins", "Signed in", "your browsers and tokens; d signs a browser out"], |
| @@ -308,6 +309,7 @@ test("a site-admin agent is offered the roster without the person-only entries", | ||
| 308 | 309 | ["decider", "Decider", "what it closed, deferred and asked you about today"], |
| 309 | 310 | ["fetch-page", "Read a web page", "paste an https link; the page as Markdown, as Talk's agent reads it"], |
| 310 | 311 | ["ssh-keys", "Computer keys", "list, add and remove the keys that sign in as you"], |
| 312 | ["fork-flows", "Fork flows", "what I follow, what I offered, what my forks offered me"], | |
| 311 | 313 | ["account", "Account settings", undefined], |
| 312 | 314 | ["signins", "Signed in", "your browsers and tokens; d signs a browser out"], |
| 313 | 315 | ["sentinel", "Sentinel", "the forge's open faults"], |
| @@ -436,6 +438,7 @@ test("a member person is offered the signed-in roster without the admin entries" | ||
| 436 | 438 | ["build-app", "Build an app", "say what to build; versions, diff, restore and publish. n starts one"], |
| 437 | 439 | ["fetch-page", "Read a web page", "paste an https link; the page as Markdown, as Talk's agent reads it"], |
| 438 | 440 | ["ssh-keys", "Computer keys", "list, add and remove the keys that sign in as you"], |
| 441 | ["fork-flows", "Fork flows", "what I follow, what I offered, what my forks offered me"], | |
| 439 | 442 | ["passkeys", "Passkeys", "the passkeys that sign in as you"], |
| 440 | 443 | ["account", "Account settings", undefined], |
| 441 | 444 | ["signins", "Signed in", "your browsers and tokens; d signs a browser out"], |
test/private-by-default.test.ts +1
| @@ -125,6 +125,7 @@ const DOORS: Readonly<Record<string, Door>> = { | ||
| 125 | 125 | "mcp branches create": { noRepository: "a branch" }, |
| 126 | 126 | "mcp claim_link": { noRepository: "a spawned forge's claim link" }, |
| 127 | 127 | "mcp fork": { walked: FORK }, |
| 128 | "mcp fork_flows": { noRepository: "reads the fork flows" }, | |
| 128 | 129 | "mcp fork_tree": { noRepository: "reads the fork tree" }, |
| 129 | 130 | "mcp forks": { noRepository: "reads the forks" }, |
| 130 | 131 | "mcp games start": { noRepository: "a game service started (power), not a repository" }, |
new above
offline
Says the page is linked from
/forges; the pull removed that link. Fix the claim, and restore the link (box 6 of #17056).