Public: anyone can read this; the crew can change it.

The forge removes as well as adds: 8,952 files added against 129 deleted since September, and 5% of commits shrink src #14299

opened this in answer to

Check · Review · Land · Live — No review yet. Next: reviewer, no review yet.

Ready to land

mason/forge:mason/14249-the-forge-removes-as-well-as-adds-8-952 → main 1 commit fork

Review

Sign in to review this change.
4 files changed +92 −1
AGENTS.md +2
@@ -63,3 +63,5 @@ An app token's requests go behind people's and repeat reads are 304s (`src/http/
6363 `src/perf/job_alloc.ts`: `counted`, called by `during` around each job's synchronous slice, adds the JS heap's growth to the job's name (at most 128 names); the minute memory line reads and empties it (`memory allocated by jobs:`, #13924), so a timer that allocates with no request running is named. `bench/idle.ts` is the idle budget on a seeded forge (heap under 20 MiB a minute, no stall over 100 ms). Gone on restart.
6464
6565 A pull that changes code under `src/` adds or edits a `test/*.test.ts` too, or says `No test: <why>` in a commit line; `bun scripts/gate.ts` refuses it otherwise ("a behaviour a pull adds has a test that fails without it", #14235).
66
67 A pull that adds a page (`src/web/pages/*.ts`), an MCP tool (`src/http/mcp/tools/*.ts`) or a settings module (`src/settings/*.ts`) has a commit line `Replaces: <what it takes the place of>` or `Replaces: nothing, <why>` (#14249, `src/kernel/replaces.ts`); `bun scripts/gate.ts` says it as a note, never a refusal, and the reviewer holds the pull to that line.
scripts/gate.ts +19 −1
@@ -673,6 +673,24 @@ export async function tryItNote(cwd: string = process.cwd()): Promise<string[]>
673673 return tryItProblems(parseNameStatus(diff.out), log.out.split("\0").map((m) => m.trim()).filter(Boolean));
674674 }
675675
676 /**
677 * A pull that adds a page, an MCP tool or a settings module says what it replaces, or why nothing
678 * does (#14249): a note for the reviewer, never a refusal.
679 */
680 export async function replacesNote(cwd: string = process.cwd()): Promise<string[]> {
681 const { parseNameStatus } = await import("../src/kernel/pin_edits.ts");
682 const { replacesProblems } = await import("../src/kernel/replaces.ts");
683 const base =
684 process.env.FORGE_CHECK_BASE ||
685 git(["merge-base", "origin/main", "HEAD"], cwd).out ||
686 git(["merge-base", "main", "HEAD"], cwd).out;
687 if (!base) return [];
688 const diff = git(["diff", "--name-status", "-M", `${base}..${judgedHead(cwd)}`], cwd);
689 const log = git(["log", "--format=%B%x00", `${base}..${judgedHead(cwd)}`], cwd);
690 if (!diff.ok || !log.ok) return [];
691 return replacesProblems(parseNameStatus(diff.out), log.out.split("\0").map((m) => m.trim()).filter(Boolean));
692 }
693
676694 /** A pull that adds a page adds its terminal screen and how-to too (#10628). */
677695 export async function bothDoorsRefusal(cwd: string = process.cwd()): Promise<string[]> {
678696 const { parseNameStatus } = await import("../src/kernel/pin_edits.ts");
@@ -838,7 +856,7 @@ export async function gateVerdict(cwd: string = process.cwd()): Promise<{ notes:
838856 ...(await readmeCapRefusal(cwd)),
839857 ...billingDeletesRefusal(cwd),
840858 ];
841 return { notes: [...wrapNote(cwd), ...(await lookNote(cwd)), ...(await tryItNote(cwd))], refusal };
859 return { notes: [...wrapNote(cwd), ...(await lookNote(cwd)), ...(await tryItNote(cwd)), ...(await replacesNote(cwd))], refusal };
842860 }
843861
844862 // `bun scripts/gate.ts`: the audit alone, first in `forge.json`'s check, so
src/kernel/replaces.ts added +36
@@ -0,0 +1,36 @@
1 /**
2 * The forge adds far more than it removes (#14249: 8,952 files added against 129 deleted in
3 * ten weeks; 768 surfaces a person sees added, 8 deleted). A pull that adds a page, an MCP tool
4 * or a settings module therefore says in one commit line what it replaces or why nothing does:
5 * `Replaces: <what it takes the place of>` or `Replaces: nothing, <why>`. The reviewer holds the
6 * pull to that line. The gate says it as a note and never fails a check on it (#14247).
7 */
8
9 import type { Change } from "./pin_edits.ts";
10
11 const ADDED = /^src\/(web\/pages|http\/mcp\/tools|settings)\/[^/]+\.ts$/;
12 const LINE = /^Replaces:\s*\S[^\n]{9,}$/i;
13 // An empty answer is no answer: "nothing" must carry its reason after a comma, colon or dash.
14 const BARE = /^Replaces:\s*(?:n\/?a|none|nothing|tbd|todo|no)\s*[.;]?$/i;
15
16 /** The surfaces a pull adds: new files only; an edit or a deletion adds nothing. */
17 export function surfacesAdded(changes: readonly Change[]): string[] {
18 return changes.filter((c) => c.status.startsWith("A") && ADDED.test(c.path)).map((c) => c.path);
19 }
20
21 function hasLine(message: string): boolean {
22 return message
23 .split("\n")
24 .map((l) => l.trim())
25 .some((l) => LINE.test(l) && !BARE.test(l));
26 }
27
28 /** One line per problem: none when no surface is added or a commit says what it replaces. */
29 export function replacesProblems(changes: readonly Change[], messages: readonly string[]): string[] {
30 const added = surfacesAdded(changes);
31 if (added.length === 0 || messages.some(hasLine)) return [];
32 const shown = added.slice(0, 3).join(", ") + (added.length > 3 ? ` and ${added.length - 3} more` : "");
33 return [
34 `rule "say what it replaces": this pull adds ${shown} but no commit message has a "Replaces: <what it takes the place of>" line, or "Replaces: nothing, <why>" (10+ characters)`,
35 ];
36 }
test/replaces.test.ts added +35
@@ -0,0 +1,35 @@
1 import { expect, test } from "bun:test";
2 import { replacesProblems, surfacesAdded } from "../src/kernel/replaces.ts";
3
4 const ch = (status: string, path: string) => ({ status, path });
5
6 test("only an added page, MCP tool or settings module is a surface added", () => {
7 expect(
8 surfacesAdded([
9 ch("A", "src/web/pages/a.ts"),
10 ch("A", "src/http/mcp/tools/b.ts"),
11 ch("A", "src/settings/c.ts"),
12 ch("M", "src/web/pages/d.ts"),
13 ch("D", "src/web/pages/e.ts"),
14 ch("A", "src/core/f.ts"),
15 ]),
16 ).toEqual(["src/web/pages/a.ts", "src/http/mcp/tools/b.ts", "src/settings/c.ts"]);
17 });
18
19 test("an added page with no Replaces line is a problem naming the file", () => {
20 const [p] = replacesProblems([ch("A", "src/web/pages/a.ts")], ["Add a"]);
21 expect(p).toContain("say what it replaces");
22 expect(p).toContain("src/web/pages/a.ts");
23 });
24
25 test("a Replaces line, or nothing with a reason, answers; a bare nothing does not", () => {
26 const changes = [ch("A", "src/web/pages/a.ts")];
27 expect(replacesProblems(changes, ["Add a\n\nReplaces: the /old page and its tab"])).toEqual([]);
28 expect(replacesProblems(changes, ["Add a\n\nReplaces: nothing, no page shows this yet"])).toEqual([]);
29 expect(replacesProblems(changes, ["Add a\n\nReplaces: nothing"])).toHaveLength(1);
30 expect(replacesProblems(changes, ["Add a\n\nReplaces: n/a"])).toHaveLength(1);
31 });
32
33 test("a pull that adds no surface needs no line", () => {
34 expect(replacesProblems([ch("M", "src/web/pages/a.ts")], ["Edit a"])).toEqual([]);
35 });

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs