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

Merged opened this

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

Merged

scout/forge:scout/14083-the-mcp-changelog-answer-includes-each-w → main 5 commits fork 2 threads · 2 unresolved

  • Merged. scout/14083-the-mcp-changelog-answer-includes-each-w was merged into main as e887859.

Review

Sign in to review this change.
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";
33
44 export const tool: Tool = {
55 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",
77 description: "Kept releases, newest first.",
88 inputSchema: { type: "object", properties: { shipped: { type: "boolean" }, repo: { type: "string" } } },
99 writes: false,
src/release/answer.ts +5 −1
@@ -10,6 +10,7 @@ import { getRepoById } from "../core/repos.ts";
1010 import type { User } from "../core/users.ts";
1111 import { releaseOf, running, shortOf } from "../kernel/version.ts";
1212 import { BOOTED, mayRead } from "./gate.ts";
13 import { chapterEntries, groupByChapter, wavesOf } from "./chapter_groups.ts";
1314 import { chosenRepo, readLandings, type Landing, type Landings } from "./landings.ts";
1415 import { keeperReleaseOfSha, type Stage } from "../keeper/record.ts";
1516 import { listReleases, releaseName } from "./record.ts";
@@ -53,13 +54,16 @@ export async function shippedAnswer(app: App, asked: string | null = null) {
5354 // The versions public apps' production first served (#13707); `owner/name` narrows them, anything
5455 // else is all.
5556 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)));
5659 return {
5760 // The release number, or null for a build that is not one: never the word "dev".
5861 version: releaseOf({ version: read.version, commit: read.commit }),
5962 commit: read.commit,
6063 short: read.commit === null ? null : shortOf(read.commit),
6164 liveSince: BOOTED,
62 live: read.live.filter(keep),
65 live,
66 waves,
6367 onItsWay: read.onItsWay.filter(keep),
6468 releases: listPublicReleases(app.db, 50, named),
6569 };
src/release/chapter_groups.ts +34 −1
@@ -5,7 +5,10 @@
55 * from the chapter items (`chapterOfPulls`), handed in as numbers; nothing here reads text or time.
66 */
77
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";
912 import type { Landing } from "./landings.ts";
1013
1114 /**
@@ -51,3 +54,33 @@ export function groupByChapter(landings: readonly Landing[], entries: readonly C
5154 if (between.length > 0) out.push({ kind: "between", landings: between });
5255 return out;
5356 }
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";
1212 import { betNamesOfPulls } from "../../core/bets.ts";
1313 import { sourcesOfPulls } from "../../core/trusted_sources.ts";
1414 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";
1716 import type { Database } from "bun:sqlite";
18 import type { User } from "../../core/users.ts";
1917 import { newestLive, secondsWords } from "../../keeper/landed.ts";
2018 import { dayHeading, dayOf, daysJs, shippedToday } from "../../release/days.ts";
outdated

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.

2119 import { hasMerged, mergedRows, readLandings, type Landing, type Landings, type MergedRow } from "../../release/landings.ts";
@@ -103,28 +101,6 @@ export function chapterStamp(db: Database): string {
103101 return `${r?.n ?? 0}|${r?.last ?? ""}|${r?.seen ?? ""}|${r?.items ?? ""}|${Bun.hash(r?.placed ?? "").toString(36)}`;
104102 }
105103
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
128104 /**
129105 * A chapter: a nav row (its name linked to its page, its closing day or "open" as the trail), then
130106 * 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 @@
22 import { expect, test } from "bun:test";
33 import type { Chapter } from "../src/core/chapters.ts";
44 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";
77 import { chapterOfPulls } from "../src/core/chapters.ts";
88 import { createRepo } from "../src/actions/repos.ts";
99 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 });

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs