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

The review and build briefs say a preview's /__forge/ and pill come from the host forge, so changes to them are judged by test #16734

Merged opened this

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

Merged

scout/forge:scout/6356-the-review-and-build-briefs-say-a-previe → main 0 commits fork 1 thread · 1 unresolved

  • Merged. scout/6356-the-review-and-build-briefs-say-a-previe was merged into main as 6fc06e8.

Review

Sign in to review this change.
3 files changed +86 −0
docs/CREW.md +2
@@ -19,6 +19,8 @@ off: no autonomy tick, no dispatch, no spend; checks still run and everything
1919 can still be read. The boot log and the studio's crew card say so. Set
2020 `FORGE_CREW_IN_PREVIEW=1` to run it anyway.
2121
22 On a preview, `/__forge/*` and the forge pill come from the host forge, not the branch, so the reviewer and builder briefs say to judge a change to them (src/apps/door.ts, toolbar.ts, feedback.ts, door_pulls.ts, or proxy.ts with `__forge`) by its request-level tests, not by the preview.
23
2224 **Per model, per prompt version.** Every agent run records the model it ran on
2325 and a prompt version: a short hash of the agent's brief, its crew role and the
2426 standing system-prompt text (not the issue or branch, so two runs on one brief
src/crew/brief.ts +36
@@ -481,6 +481,39 @@ function isForge(repo: { readonly name: string }): boolean {
481481 return repo.name === "forge";
482482 }
483483
484 /**
outdated

This doc comment belongs to namesMcp below; the host-door block was inserted between them. Put it back directly above namesMcp and keep the new block above it.

485 * On an app host `/__forge/*` and the injected forge pill are answered by the forge that hosts the
486 * app, so a preview cannot show a change to them (#5988, #6032, #6078).
487 */
488 export const hostDoorRule =
489 "`/__forge/*` and the forge pill on a preview come from the host forge, not from this branch: judge a change to them by the request-level tests that come with it, not by the preview.";
490
491 const DOOR_FILES = ["door", "toolbar", "feedback", "door_pulls"];
492 const DOOR_PATH = new RegExp(`src/apps/(?:${DOOR_FILES.join("|")})\\.ts\\b`);
493
494 /**
495 * Whether a change reaches the host-served door. A diff is read by its `diff --git` headers, so
496 * prose that mentions door.ts does not count; free text (an issue) is matched for the paths.
497 * proxy.ts counts only alongside `__forge`.
498 */
499 export function touchesHostDoor(text: string, isDiff: boolean): boolean {
500 const mentionsDoor = text.includes("__forge");
501 if (!isDiff)
502 return DOOR_PATH.test(text) || (/src\/apps\/proxy\.ts\b/.test(text) && mentionsDoor);
503 const files = [...text.matchAll(/^diff --git a\/(\S+) b\/\S+/gm)].map((m) => m[1] ?? "");
504 return files.some(
505 (f) => DOOR_PATH.test(f) || (f === "src/apps/proxy.ts" && mentionsDoor),
506 );
507 }
508
509 /** The reviewer's line: set when the diff under review touches the host door. */
510 export const hostDoorFor = (diff: string | undefined): string[] =>
511 diff !== undefined && touchesHostDoor(diff, true) ? [`- ${hostDoorRule}`] : [];
512
513 /** The builder's line: set when the issue's text names the host door. */
514 export const builderHostDoor = (title: string, body: string | null | undefined): string[] =>
515 touchesHostDoor(`${title}\n${body ?? ""}`, false) ? ["", hostDoorRule] : [];
516
484517 /** Whether the issue's title or body names a path under src/http/mcp/ or the word MCP. */
485518 function namesMcp(title: string, body: string | null | undefined): boolean {
486519 return /src\/http\/mcp\/|\bMCP\b/.test(`${title}\n${body ?? ""}`);
@@ -564,6 +597,8 @@ function taskBody(input: TaskInput): string {
564597 );
565598 if (input.pull === undefined && isForge(input.repo) && namesMcp(issue.title, issue.body))
566599 out.push("", MCP_SIZE_RULE);
600 if (input.pull === undefined && isForge(input.repo))
601 out.push(...builderHostDoor(issue.title, issue.body));
567602 if (input.pull === undefined && isForge(input.repo)) out.push("", PRIOR_ART_RULE);
568603 if (input.pull === undefined && isForge(input.repo)) out.push("", planRule(input.tools));
569604 if (input.pull === undefined && isForge(input.repo)) out.push("", estimateRule(input.tools));
@@ -625,6 +660,7 @@ function taskBody(input: TaskInput): string {
625660 : [
626661 "- The contract: every action asks `permit` and none compares roles by hand; a new door has its row in `src/contract.test.ts`; and no cell in `contract.json` is loosened unless the issue asked for exactly that — a loosened cell is a wall a person crosses, so a pull that loosens one without being asked is a change request, whatever else it does well.",
627662 ]),
663 ...(isForge(input.repo) ? hostDoorFor(input.reviewDiff) : []),
628664 ...boxLines(input),
629665 "",
630666 ...roundLines(input.reviews.filter((r) => r.authorName === me)),
test/brief-host-door.test.ts added +48
@@ -0,0 +1,48 @@
1 import { describe, expect, test } from "bun:test";
2 import { builderHostDoor, hostDoorFor, hostDoorRule, taskPrompt, touchesHostDoor, type TaskInput } from "../src/crew/brief.ts";
3
4 const diff = (...files: string[]): string =>
5 files.map((f) => `diff --git a/${f} b/${f}\n--- a/${f}\n+++ b/${f}\n@@ -1 +1 @@\n-a\n+b\n`).join("");
6
7 describe("the host door", () => {
8 test("a diff touching door.ts says it; src/web alone does not; docs naming door.ts do not", () => {
9 expect(touchesHostDoor(diff("src/apps/door.ts"), true)).toBe(true);
10 expect(hostDoorFor(diff("src/apps/toolbar.ts"))).toEqual([`- ${hostDoorRule}`]);
11 expect(hostDoorFor(diff("src/web/page.ts"))).toEqual([]);
12 const docs = `${diff("docs/CREW.md")}+ see src/apps/door.ts and /__forge/\n`;
13 expect(touchesHostDoor(docs, true)).toBe(false);
14 expect(hostDoorFor(undefined)).toEqual([]);
15 });
16
17 test("proxy.ts counts only with __forge", () => {
18 expect(touchesHostDoor(diff("src/apps/proxy.ts"), true)).toBe(false);
19 expect(touchesHostDoor(`${diff("src/apps/proxy.ts")}+"/__forge/x"\n`, true)).toBe(true);
20 });
21
22 test("an issue's text is matched as free text", () => {
23 expect(builderHostDoor("Fix src/apps/feedback.ts", "")).toEqual(["", hostDoorRule]);
24 expect(builderHostDoor("Fix the footer", "src/apps/proxy.ts")).toEqual([]);
25 expect(builderHostDoor("Fix", "src/apps/proxy.ts drops /__forge/ headers")).toEqual(["", hostDoorRule]);
26 });
27
28 const input = (over: object): TaskInput =>
29 ({
30 agent: { user: { username: "bot", displayName: "" }, brief: "" },
31 repo: { ownerName: "alice", name: "forge", defaultBranch: "main", autonomyDirection: "" },
32 issue: { number: 1, title: "t", body: "b", authorName: "alice" },
33 comments: [],
34 reviews: [],
35 branch: "bot/1",
36 forgeUrl: "http://forge.test",
37 ...over,
38 }) as unknown as TaskInput;
39
40 test("reviewer and builder briefs carry the line, others do not", () => {
41 const r = taskPrompt(input({ reason: "review", reviewDiff: diff("src/apps/door.ts") }));
42 expect(r).toContain(hostDoorRule);
43 expect(taskPrompt(input({ reason: "review", reviewDiff: diff("src/web/a.ts") }))).not.toContain("host forge");
44 const b = taskPrompt(input({ reason: "assigned", issue: { number: 1, title: "Edit src/apps/door.ts", body: "", authorName: "a" } }));
45 expect(b).toContain(hostDoorRule);
46 expect(taskPrompt(input({ reason: "assigned" }))).not.toContain("host forge");
47 });
48 });

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs