Public: anyone can read this; the crew can change it.
Crew: an adversarial validator pass before merge on risky pulls (box agent, game door, auth, print path) #18262
Merged 5h 50m ago, live in production
scout/forge:scout/18250-crew-an-adversarial-validator-pass-befor → main 0 commits fork 5 threads · 5 unresolved
5 files
changed +119
−6
docs/features/adversarial-review.md added +19
| @@ -0,0 +1,19 @@ | ||
| 1 | --- | |
| 2 | topic: Tell the crew | |
| 3 | row: A risky pull is read by a reviewer told to break it | |
| 4 | --- | |
| 5 | # A risky pull is read by a reviewer told to break it (#18250) | |
| 6 | ||
| 7 | When a pull changes the box agent (`src/games/agent.sh`), the game door | |
| 8 | (`src/games/door.ts`, `src/http/games_*.ts`), sign-in or permissions | |
| 9 | (`src/auth/`, `contract.json`), a release script, or a print path, the | |
| 10 | reviewer's brief gains an adversarial pass: read-only, fresh context, narrow | |
| 11 | brief: break it. Its findings arrive as the review's line comments, a change | |
| 12 | request when one can be shown. The paths are listed in `src/crew/risky.ts`. | |
| 13 | ||
| 14 | There is no screen for it: it is the review that already appears on the pull, | |
| 15 | on the page and over the API alike; it adds no screen or action of its own. | |
| 16 | ||
| 17 | Not built, tracked in #18271 and #18272, linked to #18250: running the game | |
| 18 | agent tests in ubuntu:24.04 before an agent.sh release, and watching the box | |
| 19 | after one. |
src/crew/brief.ts +7
| @@ -17,6 +17,7 @@ import type { Pull } from "../core/pulls.ts"; | ||
| 17 | 17 | import { saysFromApp } from "../actions/app_notes.ts"; |
| 18 | 18 | import { OUTSIDE_LABEL, OUTSIDE_TITLE, saysOutside } from "../core/reports.ts"; |
| 19 | 19 | import type { Repo } from "../core/repos.ts"; |
| 20 | import { adversarialLines } from "./risky.ts"; | |
| 20 | 21 | import { DESIGN_POINTER, DESIGN_PRINCIPLES } from "./design_principles.ts"; |
| 21 | 22 | import { READER } from "./direct.ts"; |
| 22 | 23 | import { deviceLines } from "./devices.ts"; |
| @@ -364,6 +365,11 @@ export interface TaskInput extends BriefInput { | ||
| 364 | 365 | readonly sealedRef?: string | undefined; |
| 365 | 366 | /** For `review`: the change touches `src/web/`, so the review is held to docs/DESIGN.md. */ |
| 366 | 367 | readonly design?: boolean | undefined; |
| 368 | /** | |
| 369 | * For `review`: the risky areas the change touches (`risky.ts`), so the review is the adversarial | |
| 370 | * one. | |
| 371 | */ | |
| 372 | readonly risky?: readonly string[] | undefined; | |
| 367 | 373 | /** For `review`: an earlier review run on this pull ended with no verdict. */ |
| 368 | 374 | readonly retry?: boolean | undefined; |
| 369 | 375 | /** For `review`: pictures of the preview at this head, phone and desktop. */ |
| @@ -693,6 +699,7 @@ function taskBody(input: TaskInput): string { | ||
| 693 | 699 | "- 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.", |
| 694 | 700 | ]), |
| 695 | 701 | ...(isForge(input.repo) ? hostDoorFor(input.reviewDiff) : []), |
| 702 | ...adversarialLines(input.risky ?? []), | |
| 696 | 703 | ...boxLines(input), |
| 697 | 704 | "", |
| 698 | 705 | ...roundLines(input.reviews.filter((r) => r.authorName === me)), |
src/crew/risky.ts added +36
| @@ -0,0 +1,36 @@ | ||
| 1 | /** | |
| 2 | * Which pulls are risky enough for a reviewer who reads to break them (#18250): the box agent, the | |
| 3 | * game door, sign-in and permissions, the release scripts, and a print path. Plain paths in, the | |
| 4 | * named areas out; the brief turns them into the adversarial pass (`brief.ts`). | |
| 5 | */ | |
| 6 | ||
| 7 | const AREAS: readonly { readonly area: string; readonly path: RegExp }[] = [ | |
| 8 | { area: "the box agent", path: /^src\/games\/(agent\.sh|fetch\.sh|agent_sh\.d\.ts)$/ }, | |
| 9 | { area: "the game door", path: /^src\/games\/(door|hold|lend|heal)[^/]*\.ts$|^src\/http\/games_[^/]*\.ts$/ }, | |
| 10 | { area: "sign-in or permissions", path: /^src\/auth\/|^contract\.json$|^src\/contract|^src\/(.*\/)?permit[^/]*\.ts$/ }, | |
| 11 | { area: "a release script", path: /^scripts\/(cut-release|release-[^/]*)\.ts$|^src\/release\// }, | |
| 12 | { area: "a print path", path: /^(src|scripts)\/(?!.*\.md$)(.*[/_.-])?print([/_.-]|$)/i }, | |
|
||
| 13 | ]; | |
| 14 | ||
| 15 | /** | |
| 16 | * A test file is never the risky change itself: every area skips `*.test.ts`, so the rules agree. | |
| 17 | */ | |
| 18 | const isTest = (p: string): boolean => /\.test\.ts$/.test(p); | |
| 19 | ||
| 20 | /** The risky areas these changed paths touch, in a fixed order; none for an ordinary change. */ | |
| 21 | export function riskyAreas(paths: readonly string[]): string[] { | |
| 22 | const source = paths.filter((p) => !isTest(p)); | |
| 23 | return AREAS.filter((a) => source.some((p) => a.path.test(p))).map((a) => a.area); | |
| 24 | } | |
| 25 | ||
| 26 | /** What a reviewer of such a pull is told: break it, read-only, and say what held. */ | |
| 27 | export function adversarialLines(areas: readonly string[]): string[] { | |
| 28 | if (areas.length === 0) return []; | |
| 29 | return [ | |
| 30 | "", | |
| 31 | `This pull touches ${areas.join(", ")}: this review is the adversarial one. Your brief is narrow: break it. You stay read-only — do not write code, push or change anything — and a fresh pair of eyes is the point, so judge the diff itself, not the author's account of it.`, | |
| 32 | "- Ask of every changed line what runs it when nobody is watching: a loop that never sleeps, a retry with no backoff, a restart or a write while people are online, an error that reaches every player or every user instead of one, a statement in a printed or shown text that is not true.", | |
| 33 | "- Try the empty case, the repeated case, the slow case and the hostile case (a name, a path or a number someone chose to hurt it) against the code, and name the input that breaks it.", | |
| 34 | "- Each finding is a line comment that says what breaks, for what input, and what the change should do; one finding you can show is a change request. If you try hard and find nothing, say what you tried in the verdict's words.", | |
| 35 | ]; | |
| 36 | } |
src/crew/run_prompt.ts +10 −6
| @@ -33,6 +33,7 @@ import { parkReasons, parkedTwice } from "./parks.ts"; | ||
| 33 | 33 | import { resolutionBrief } from "./proposal.ts"; |
| 34 | 34 | import { reviewRange } from "./review_range.ts"; |
| 35 | 35 | import { touchesDesign } from "./review.ts"; |
| 36 | import { riskyAreas } from "./risky.ts"; | |
| 36 | 37 | import { SEALED_REMOTE } from "./sealed_head.ts"; |
| 37 | 38 | import { reviewSourceNote } from "./source_held.ts"; |
| 38 | 39 | import { pureRevertOf } from "../checks/revert_lane.ts"; |
| @@ -201,22 +202,24 @@ export async function reviewInputs( | ||
| 201 | 202 | reviewDiff: string; |
| 202 | 203 | looks: string[]; |
| 203 | 204 | design: boolean; |
| 205 | risky: string[]; | |
| 204 | 206 | landedAs?: string; |
| 205 | 207 | }> { |
| 206 | 208 | const range = await reviewRange(bare, pull); |
| 207 | 209 | let reviewDiff = "(no diff available)"; |
| 208 | 210 | let design = false; |
| 211 | let risky: string[] = []; | |
| 209 | 212 | if (range !== undefined) { |
| 210 | 213 | const names = await runGitCapture( |
| 211 | 214 | ["diff", "--name-only", range.from, range.to], |
| 212 | 215 | { cwd: bare, ...(signal === undefined ? {} : { signal }) }, |
| 213 | 216 | ); |
| 214 | design = touchesDesign( | |
| 215 | names.stdout | |
| 216 | .toString() | |
| 217 | .split("\n") | |
| 218 | .filter((n) => n !== ""), | |
| 219 | ); | |
| 217 | const changed = names.stdout | |
| 218 | .toString() | |
| 219 | .split("\n") | |
| 220 | .filter((n) => n !== ""); | |
| 221 | design = touchesDesign(changed); | |
| 222 | risky = riskyAreas(changed); | |
| 220 | 223 | const out = await runGitCapture( |
| 221 | 224 | ["diff", "--stat", "-p", range.from, range.to], |
| 222 | 225 | { cwd: bare, ...(signal === undefined ? {} : { signal }) }, |
| @@ -249,6 +252,7 @@ export async function reviewInputs( | ||
| 249 | 252 | reviewDiff, |
| 250 | 253 | looks, |
| 251 | 254 | design, |
| 255 | risky, | |
| 252 | 256 | ...(range?.landed === true && reviewDiff !== "(no diff available)" |
| 253 | 257 | ? { landedAs: range.to } |
| 254 | 258 | : {}), |
test/crew-risky.test.ts added +47
| @@ -0,0 +1,47 @@ | ||
| 1 | /** A pull on a risky path is read by an adversarial reviewer (#18250). */ | |
| 2 | import { expect, test } from "bun:test"; | |
| 3 | import { taskPrompt, type TaskInput } from "../src/crew/brief.ts"; | |
| 4 | import { adversarialLines, riskyAreas } from "../src/crew/risky.ts"; | |
| 5 | ||
| 6 | test("the risky paths are named, an ordinary change is not", () => { | |
| 7 | expect(riskyAreas(["src/games/agent.sh"])).toEqual(["the box agent"]); | |
| 8 | expect(riskyAreas(["src/games/door.ts", "src/http/games_routes.ts"])).toEqual(["the game door"]); | |
| 9 | expect(riskyAreas(["src/auth/cookies.ts", "contract.json"])).toEqual(["sign-in or permissions"]); | |
| 10 | expect(riskyAreas(["scripts/cut-release.ts"])).toEqual(["a release script"]); | |
| 11 | expect(riskyAreas(["src/web/pages/print.ts"])).toEqual(["a print path"]); | |
| 12 | expect(riskyAreas(["docs/features/print-sheet.md", "test/print-x.test.ts", "src/web/print.md"])).toEqual([]); | |
| 13 | expect(riskyAreas(["src/print.ts"])).toEqual(["a print path"]); | |
| 14 | expect(riskyAreas(["scripts/print.ts"])).toEqual(["a print path"]); | |
| 15 | expect(riskyAreas(["src/auth/permit.ts"])).toEqual(["sign-in or permissions"]); | |
| 16 | expect(riskyAreas(["test/permit-x.test.ts", "docs/permit.ts", "src/auth/permit.test.ts", "src/x/permit.test.ts"])).toEqual([]); | |
| 17 | expect(riskyAreas(["scripts/release-notes.test.ts", "src/release/x.test.ts"])).toEqual([]); | |
| 18 | expect(riskyAreas(["src/contract.test.ts", "test/auth-x.test.ts"])).toEqual([]); | |
| 19 | expect(riskyAreas(["src/web/pages/home.ts", "README.md", "src/games/ask.ts", "src/blueprint.ts"])).toEqual([]); | |
| 20 | }); | |
| 21 | ||
| 22 | test("the adversarial brief is read-only and says to break it; nothing for an ordinary pull", () => { | |
| 23 | expect(adversarialLines([])).toEqual([]); | |
| 24 | const text = adversarialLines(["the box agent"]).join("\n"); | |
| 25 | expect(text).toContain("the box agent"); | |
| 26 | expect(text).toContain("break it"); | |
| 27 | expect(text).toContain("read-only"); | |
| 28 | }); | |
| 29 | ||
| 30 | const input = (over: object): TaskInput => | |
| 31 | ({ | |
| 32 | agent: { user: { username: "bot", displayName: "" }, brief: "" }, | |
| 33 | repo: { ownerName: "alice", name: "forge", defaultBranch: "main", autonomyDirection: "" }, | |
| 34 | issue: { number: 1, title: "t", body: "b", authorName: "alice" }, | |
| 35 | comments: [], | |
| 36 | reviews: [], | |
| 37 | branch: "bot/1", | |
| 38 | forgeUrl: "http://forge.test", | |
| 39 | reason: "review", | |
| 40 | ...over, | |
| 41 | }) as unknown as TaskInput; | |
| 42 | ||
| 43 | test("risky reaches the review task prompt; without it the prompt has no adversarial pass", () => { | |
| 44 | expect(taskPrompt(input({ risky: ["the box agent"] }))).toContain("this review is the adversarial one"); | |
| 45 | expect(taskPrompt(input({}))).not.toContain("adversarial"); | |
| 46 | expect(taskPrompt(input({ risky: [] }))).not.toContain("adversarial"); | |
| 47 | }); |
new above
offline
permit[^/]\.tsmatchessrc/x/permit.test.ts, whilesrc/contractexcludes tests. Make the two agree: exclude.test.tsin both. The same applies torelease-.tson line 11.