Public: anyone can read this; the crew can change it.
The MCP changelog answer includes each wave's closing date and pull count, within the size ceilings #14096
Check · Review · Land · Live done — Landed and live in production.
scout/forge:scout/14083-the-mcp-changelog-answer-includes-each-w → main 5 commits fork 2 threads · 2 unresolved
6 files
changed +120
−30
src/http/mcp/tools/releases.ts +1 −1
| @@ -3,7 +3,7 @@ import { bad, good, type Tool } from "../shared.ts"; | ||
| 3 | 3 | |
| 4 | 4 | export const tool: Tool = { |
| 5 | 5 | name: "releases", |
| 6 | doc: "`{shipped: true, repo?}`: what went live, for anyone: `version`, `commit`, `live` (newest first: `repo`, `number`, `title`, `at`) and `onItsWay` (landed, not yet in the running commit), the list /changelog shows (the `ui://forge/releases` card), for `repo` (`all` or `owner/name`; absent is the forge's own, as on the page). `{}`: the forge's kept releases newest first: short sha, version, the pull that landed it, when, and for the live one `live: true` and `since`; for whoever may read /releases, others get its refusal; no rollback, a person does that on the page", | |
| 6 | doc: "`{shipped: true, repo?}`: what went live, for anyone: `version`, `commit`, `live` (newest first: `repo`, `number`, `title`, `at`) `onItsWay` (landed, not yet in the running commit) and `waves` (`repo`, `name`, `closed` date or null, `pulls` landed), the list /changelog shows (the `ui://forge/releases` card), for `repo` (`all` or `owner/name`; absent is the forge's own, as on the page). `{}`: the forge's kept releases newest first: short sha, version, the pull that landed it, when, and for the live one `live: true` and `since`; for whoever may read /releases, others get its refusal; no rollback, a person does that on the page", | |
| 7 | 7 | description: "Kept releases, newest first.", |
| 8 | 8 | inputSchema: { type: "object", properties: { shipped: { type: "boolean" }, repo: { type: "string" } } }, |
| 9 | 9 | writes: false, |
src/release/answer.ts +5 −1
| @@ -10,6 +10,7 @@ import { getRepoById } from "../core/repos.ts"; | ||
| 10 | 10 | import type { User } from "../core/users.ts"; |
| 11 | 11 | import { releaseOf, running, shortOf } from "../kernel/version.ts"; |
| 12 | 12 | import { BOOTED, mayRead } from "./gate.ts"; |
| 13 | import { chapterEntries, groupByChapter, wavesOf } from "./chapter_groups.ts"; | |
| 13 | 14 | import { chosenRepo, readLandings, type Landing, type Landings } from "./landings.ts"; |
| 14 | 15 | import { keeperReleaseOfSha, type Stage } from "../keeper/record.ts"; |
| 15 | 16 | import { listReleases, releaseName } from "./record.ts"; |
| @@ -53,13 +54,16 @@ export async function shippedAnswer(app: App, asked: string | null = null) { | ||
| 53 | 54 | // The versions public apps' production first served (#13707); `owner/name` narrows them, anything |
| 54 | 55 | // else is all. |
| 55 | 56 | const named = asked !== null && /^[^/\s]{1,80}\/[^/\s]{1,80}$/.test(asked) ? asked : undefined; |
| 57 | const live = read.live.filter(keep); | |
| 58 | const waves = wavesOf(groupByChapter(live, chapterEntries(app.db, live, undefined))); | |
| 56 | 59 | return { |
| 57 | 60 | // The release number, or null for a build that is not one: never the word "dev". |
| 58 | 61 | version: releaseOf({ version: read.version, commit: read.commit }), |
| 59 | 62 | commit: read.commit, |
| 60 | 63 | short: read.commit === null ? null : shortOf(read.commit), |
| 61 | 64 | liveSince: BOOTED, |
| 62 | live: read.live.filter(keep), | |
| 65 | live, | |
| 66 | waves, | |
| 63 | 67 | onItsWay: read.onItsWay.filter(keep), |
| 64 | 68 | releases: listPublicReleases(app.db, 50, named), |
| 65 | 69 | }; |
src/release/chapter_groups.ts +34 −1
| @@ -5,7 +5,10 @@ | ||
| 5 | 5 | * from the chapter items (`chapterOfPulls`), handed in as numbers; nothing here reads text or time. |
| 6 | 6 | */ |
| 7 | 7 | |
| 8 | import type { Chapter } from "../core/chapters.ts"; | |
| 8 | import type { Database } from "bun:sqlite"; | |
| 9 | import { chapterOfPulls, listChapters, type Chapter } from "../core/chapters.ts"; | |
| 10 | import { canRead, getRepo } from "../core/repos.ts"; | |
| 11 | import type { User } from "../core/users.ts"; | |
| 9 | 12 | import type { Landing } from "./landings.ts"; |
| 10 | 13 | |
| 11 | 14 | /** |
| @@ -51,3 +54,33 @@ export function groupByChapter(landings: readonly Landing[], entries: readonly C | ||
| 51 | 54 | if (between.length > 0) out.push({ kind: "between", landings: between }); |
| 52 | 55 | return out; |
| 53 | 56 | } |
| 57 | ||
| 58 | /** | |
| 59 | * The chapters (open and closed) of the repositories the live landings came from, each marked with | |
| 60 | * whether `user` may read its repository and which pulls served it. | |
| 61 | */ | |
| 62 | export function chapterEntries(db: Database, live: readonly Landing[], user: User | undefined): ChapterEntry[] { | |
| 63 | const out: ChapterEntry[] = []; | |
| 64 | for (const name of new Set(live.map((l) => l.repo))) { | |
| 65 | const [o = "", n = ""] = name.split("/"); | |
| 66 | const repo = getRepo(db, o, n); | |
| 67 | if (repo === undefined) continue; | |
| 68 | const canSee = canRead(db, repo, user); | |
| 69 | if (!canSee) continue; | |
| 70 | const served = chapterOfPulls(db, repo.id); | |
| 71 | for (const chapter of listChapters(db, repo.id)) { | |
| 72 | if (chapter.state === "draft") continue; | |
| 73 | const pulls = [...served].filter(([, id]) => id === chapter.id).map(([number]) => number); | |
| 74 | out.push({ repo: name, chapter, canSee, pulls }); | |
| 75 | } | |
| 76 | } | |
| 77 | return out; | |
| 78 | } | |
| 79 | ||
| 80 | /** | |
| 81 | * The chapters of a grouping as the answer tells them (waves): repository, name, closing time (null | |
| 82 | * while open) and how many landed pulls it holds, in the page's order. | |
| 83 | */ | |
| 84 | export function wavesOf(groups: readonly Group[]): { repo: string; name: string; closed: string | null; pulls: number }[] { | |
| 85 | return groups.flatMap((g) => (g.kind === "chapter" ? [{ repo: g.repo, name: g.chapter.name, closed: g.chapter.closedAt, pulls: g.landings.length }] : [])); | |
| 86 | } |
src/web/pages/changelog.ts +1 −25
| @@ -12,10 +12,8 @@ import type { Ctx } from "../../http/context.ts"; | ||
| 12 | 12 | import { betNamesOfPulls } from "../../core/bets.ts"; |
| 13 | 13 | import { sourcesOfPulls } from "../../core/trusted_sources.ts"; |
| 14 | 14 | import { canRead, getRepo, type Repo } from "../../core/repos.ts"; |
| 15 | import { chapterOfPulls, listChapters } from "../../core/chapters.ts"; | |
| 16 | import { groupByChapter, type ChapterEntry, type Group } from "../../release/chapter_groups.ts"; | |
| 15 | import { chapterEntries, groupByChapter, type ChapterEntry, type Group } from "../../release/chapter_groups.ts"; | |
| 17 | 16 | import type { Database } from "bun:sqlite"; |
| 18 | import type { User } from "../../core/users.ts"; | |
| 19 | 17 | import { newestLive, secondsWords } from "../../keeper/landed.ts"; |
| 20 | 18 | import { dayHeading, dayOf, daysJs, shippedToday } from "../../release/days.ts"; |
| 21 | 19 | import { hasMerged, mergedRows, readLandings, type Landing, type Landings, type MergedRow } from "../../release/landings.ts"; |
| @@ -103,28 +101,6 @@ export function chapterStamp(db: Database): string { | ||
| 103 | 101 | return `${r?.n ?? 0}|${r?.last ?? ""}|${r?.seen ?? ""}|${r?.items ?? ""}|${Bun.hash(r?.placed ?? "").toString(36)}`; |
| 104 | 102 | } |
| 105 | 103 | |
| 106 | /** | |
| 107 | * The chapters (open and closed) of the repositories the live landings came from, each marked with | |
| 108 | * whether `user` may read its repository and which pulls served it. | |
| 109 | */ | |
| 110 | export function chapterEntries(db: Database, live: readonly Landing[], user: User | undefined): ChapterEntry[] { | |
| 111 | const out: ChapterEntry[] = []; | |
| 112 | for (const name of new Set(live.map((l) => l.repo))) { | |
| 113 | const [o = "", n = ""] = name.split("/"); | |
| 114 | const repo = getRepo(db, o, n); | |
| 115 | if (repo === undefined) continue; | |
| 116 | const canSee = canRead(db, repo, user); | |
| 117 | if (!canSee) continue; | |
| 118 | const served = chapterOfPulls(db, repo.id); | |
| 119 | for (const chapter of listChapters(db, repo.id)) { | |
| 120 | if (chapter.state === "draft") continue; | |
| 121 | const pulls = [...served].filter(([, id]) => id === chapter.id).map(([number]) => number); | |
| 122 | out.push({ repo: name, chapter, canSee, pulls }); | |
| 123 | } | |
| 124 | } | |
| 125 | return out; | |
| 126 | } | |
| 127 | ||
| 128 | 104 | /** |
| 129 | 105 | * A chapter: a nav row (its name linked to its page, its closing day or "open" as the trail), then |
| 130 | 106 | * its landed pulls, one line each; a chapter nothing landed in says so on its row. |
test/changelog-chapters.test.ts +2 −2
| @@ -2,8 +2,8 @@ | ||
| 2 | 2 | import { expect, test } from "bun:test"; |
| 3 | 3 | import type { Chapter } from "../src/core/chapters.ts"; |
| 4 | 4 | import type { Landing, Landings } from "../src/release/landings.ts"; |
| 5 | import { chapterEntries, chapterStamp, shippedRegion } from "../src/web/pages/changelog.ts"; | |
| 6 | import { groupByChapter, type ChapterEntry } from "../src/release/chapter_groups.ts"; | |
| 5 | import { chapterStamp, shippedRegion } from "../src/web/pages/changelog.ts"; | |
| 6 | import { chapterEntries, groupByChapter, type ChapterEntry } from "../src/release/chapter_groups.ts"; | |
| 7 | 7 | import { chapterOfPulls } from "../src/core/chapters.ts"; |
| 8 | 8 | import { createRepo } from "../src/actions/repos.ts"; |
| 9 | 9 | import { getRepo } from "../src/core/repos.ts"; |
test/mcp-changelog-waves.test.ts added +77
| @@ -0,0 +1,77 @@ | ||
| 1 | /** | |
| 2 | * The changelog answer (MCP `releases` with `shipped`) names each wave with its closing date and | |
| 3 | * pull count. | |
| 4 | */ | |
| 5 | import { expect, test } from "bun:test"; | |
| 6 | import { mkdtempSync } from "node:fs"; | |
| 7 | import { tmpdir } from "node:os"; | |
| 8 | import { join } from "node:path"; | |
| 9 | import { createApp } from "../src/app.ts"; | |
| 10 | import { createRepo } from "../src/actions/repos.ts"; | |
| 11 | import { getRepo } from "../src/core/repos.ts"; | |
| 12 | import { createUser } from "../src/core/users.ts"; | |
| 13 | import type { Chapter } from "../src/core/chapters.ts"; | |
| 14 | import { groupByChapter, wavesOf, type ChapterEntry } from "../src/release/chapter_groups.ts"; | |
| 15 | import { shippedAnswer } from "../src/release/answer.ts"; | |
| 16 | import { tool } from "../src/http/mcp/tools/releases.ts"; | |
| 17 | ||
| 18 | const day = (d: number) => `2026-10-${String(d).padStart(2, "0")}T10:00:00Z`; | |
| 19 | const land = (number: number) => ({ repo: "a/b", number, title: `Pull ${number}`, at: day(number), live: true }); | |
| 20 | const chapter = (name: string, closed: string | null, position: number): Chapter => ({ | |
| 21 | id: name, repoId: "r", name, means: "m", state: closed === null ? "open" : "closed", position, patchOf: null, | |
| 22 | createdAt: day(1), openedAt: day(1), closedAt: closed, tagOid: null, notes: "", costUsd: 0, | |
| 23 | }); | |
| 24 | const entry = (c: Chapter, pulls: number[]): ChapterEntry => ({ repo: "a/b", chapter: c, canSee: true, pulls }); | |
| 25 | ||
| 26 | test("each wave carries its closing date and the count of pulls landed in it; open is null; between is no wave", () => { | |
| 27 | const groups = groupByChapter( | |
| 28 | [land(30), land(25), land(20), land(10)], | |
| 29 | [entry(chapter("v1", day(6), 1), [10]), entry(chapter("v2", day(21), 2), [20, 25]), entry(chapter("v3", null, 3), [30])], | |
| 30 | ); | |
| 31 | expect(wavesOf(groups)).toEqual([ | |
| 32 | { repo: "a/b", name: "v3", closed: null, pulls: 1 }, | |
| 33 | { repo: "a/b", name: "v2", closed: day(21), pulls: 2 }, | |
| 34 | { repo: "a/b", name: "v1", closed: day(6), pulls: 1 }, | |
| 35 | ]); | |
| 36 | }); | |
| 37 | ||
outdated
The wiring in answer.ts (chapterEntries with an anonymous user, the keep filter, the call into wavesOf) is only exercised with no chapters, so a broken or dropped wiring still passes. Seed a repo with a closed chapter and landed pulls and assert shippedAnswer(app).waves carries name, closed and pulls; also assert a chapter of a private repo is absent. |
||
| 38 | test("the shipped answer and the MCP tool name the field, empty when no wave is told", async () => { | |
| 39 | const app = createApp({ dataDir: mkdtempSync(join(tmpdir(), "forge-cl-waves-")), port: 0 }); | |
| 40 | try { | |
| 41 | expect((await shippedAnswer(app)).waves).toEqual([]); | |
| 42 | expect(tool.doc).toContain("`waves`"); | |
| 43 | const res: any = await tool.run({ app } as any, undefined as any, { shipped: true }); | |
| 44 | expect(res.value.waves).toEqual([]); | |
| 45 | } finally { | |
| 46 | app.close(); | |
| 47 | } | |
| 48 | }); | |
| 49 | ||
| 50 | test("the shipped answer tells a closed chapter's wave with its closing date and landed pulls; a private repository's chapter is absent", async () => { | |
| 51 | const app = createApp({ dataDir: mkdtempSync(join(tmpdir(), "forge-cl-waves-")), port: 0 }); | |
| 52 | try { | |
| 53 | const u = await createUser(app.db, { origin: "seed", trusted: true, username: "own", email: "[email protected]", password: "a-good-passphrase", adminIfFirst: true }); | |
| 54 | if (!u.ok) throw new Error(u.error); | |
| 55 | const sql = (q: string, ...a: string[]) => app.db.query(q).run(...a); | |
| 56 | const seed = async (name: string, visibility: "public" | "private") => { | |
| 57 | const made = await createRepo(app, u.value, { name, visibility }); | |
| 58 | if (!made.ok) throw new Error(String(made.error)); | |
| 59 | const repo = getRepo(app.db, "own", name)!; | |
| 60 | const chapterId = `c-${name}`; | |
| 61 | sql(`INSERT INTO chapter (id, repo_id, name, means, state, position, created_at, opened_at, closed_at, tag_oid, notes) VALUES (?1, ?2, 'v1', 'm', 'closed', 1, ?3, ?3, ?4, 'abc', 'Done.')`, chapterId, repo.id, day(1), day(9)); | |
| 62 | sql(`INSERT INTO issue (id, repo_id, number, kind, title, body, state, author_id) VALUES (?1, ?2, 1, 'issue', 'Item', '', 'closed', ?3)`, `item-${name}`, repo.id, u.value.id); | |
| 63 | sql("INSERT INTO chapter_item (issue_id, chapter_id) VALUES (?1, ?2)", `item-${name}`, chapterId); | |
| 64 | for (const n of ["2", "3"]) { | |
| 65 | sql(`INSERT INTO issue (id, repo_id, number, kind, title, body, state, author_id) VALUES (?1, ?2, ?3, 'pull', ?4, 'Closes #1', 'closed', ?5)`, `p${n}-${name}`, repo.id, n, `Pull ${n}`, u.value.id); | |
| 66 | sql(`INSERT INTO pull (issue_id, base_branch, head_branch, base_oid, head_oid, merged_at, merged_oid) VALUES (?1, ?2, ?3, 'base', '', ?4, '')`, `p${n}-${name}`, repo.defaultBranch, `h${n}`, day(Number(n))); | |
| 67 | } | |
| 68 | }; | |
| 69 | await seed("open", "public"); | |
| 70 | await seed("secret", "private"); | |
| 71 | const answer = await shippedAnswer(app, "all"); | |
| 72 | expect(answer.live.length).toBeGreaterThan(0); | |
| 73 | expect(answer.waves).toEqual([{ repo: "own/open", name: "v1", closed: day(9), pulls: 2 }]); | |
| 74 | } finally { | |
| 75 | app.close(); | |
| 76 | } | |
| 77 | }); |
new above
offline
A re-export in the middle of the imports is a shim kept only for old importers. Update those importers to import chapterEntries from release/chapter_groups.ts and delete this line.