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

Talk never draws a Do it for something the person may not do #16202

Merged opened this

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

Merged

talk/fix-no-dead-holds → main 0 commits 4 threads · 4 unresolved

  • Merged. talk/fix-no-dead-holds was merged into main as 75829bf.

Review

Sign in to review this change.
35 files changed +361 −34
docs/MCP.md +2
@@ -248,6 +248,8 @@ longer sentences:
248248 `now` takes `brief: true` and answers one plain sentence under 280 characters, for a person
249249 asking from a car. No new tool. How to use it: [docs/features/crew-now.md](features/crew-now.md).
250250
251 **Never offered what can only refuse (#10262).** A tool that refuses everyone but a forge admin in its own `run` declares `listedTo: "admin"`: it is listed (in `tools/list`, `find_tool` and /llms.txt) to an admin alone, and called by anyone else it runs to its own refusal, never held for a Do it. `adminOnly` hides a tool the same way, but anyone else's call is answered at the door (`notAdminTool`, with how to reach an admin) before the tool runs: use it for a tool with no refusal of its own, and `listedTo` for one whose refusal already says why and what to do. A write a tool would refuse this person for their access declares `refusesFirst`, the same check and words as its `run` (a review verdict needs write access or a team reviewer; landing needs write access, and landing as it is a green check): such a call is answered as refused at once, before the fence could hold it. `test/talk-no-dead-holds.test.ts` walks every tool a member and a guest are listed and fails on a refusal for lack of role.
252
251253 ## Ask for less: the default list and `find_tool` (#11957)
252254
253255 The MCP is the forge's control surface; repo work is git's (clone and push).
src/http/mcp.ts +18 −3
@@ -47,7 +47,7 @@ import { CONTRIBUTE_TOKEN_HINT, CONTRIBUTE_TOKEN_WORDS, mintContributeToken } fr
4747 import { BODY_MAX, REQUEST_MAX, TITLE_MAX } from "../core/reports.ts";
4848 import { adminRefusal, everydayOf } from "../core/everyday.ts";
4949 import { claimDone, completeWrite, dropWrite, recordWrite } from "../core/conversation_writes.ts";
50 import { type Args, alreadyDone, notAdminTool, visible, plansOnly, str, REPO_ARG, lean, fenceAnswer, heldWrite, askedFirst, readThrough, type ToolShape } from "./mcp/shared.ts";
50 import { type Args, alreadyDone, notAdminTool, listable, visible, plansOnly, str, REPO_ARG, lean, fenceAnswer, heldWrite, askedFirst, readThrough, type ToolShape } from "./mcp/shared.ts";
5151 import { CONVERSATION_BRIEF } from "../crew/conversation_brief.ts";
5252 import { recordCard, shownLine } from "../core/talk_voice.ts";
5353 import { stepOf } from "../core/talk_steps.ts";
@@ -82,7 +82,7 @@ export function toolEntries(tools: readonly (typeof TOOLS)[number][]) {
8282 }
8383
8484 /** The entries this caller may call, `report` and `start` included: what find_tool searches. */
85 export const entriesFor = (ctx: Ctx, user: User) => toolEntries(TOOLS.filter((t) => visible(t, ctx, user)));
85 export const entriesFor = (ctx: Ctx, user: User) => toolEntries(TOOLS.filter((t) => listable(t, ctx, user)));
8686
8787 // One page of tools/list stays within this many bytes of tools; `nextCursor`
8888 // names the rest, so adding a tool never busts one response.
@@ -275,8 +275,23 @@ function rpcOne(
275275 const never = ctx.auth.through === undefined ? undefined : tool?.refusedToAgent?.(args);
276276 if (never !== undefined)
277277 return reply({ content: [{ type: "text", text: `forbidden: ${never}` }], isError: true, hint: hintForCode("forbidden") });
278 // A write the tool would refuse this person anyway is answered as refused now, in its own
279 // words, and never held for a yes that could only fail.
outdated

This flag and the refused line above both need visible and listable re-evaluated, and the later visible check repeats it. Compute the tool's standing once. The lines are also very long.

280 const askable =
281 tool !== undefined && visible(tool, ctx, user) && !plansOnly(tool, args) && scopeAllows(ctx.auth.scope ?? "ro", "rw");
282 const refused = askable ? tool.refusesFirst?.(ctx, user, args) : undefined;
283 // A tool listed to admins alone refuses everyone else in `run`: it runs to that refusal,
284 // unheld.
285 const unlisted =
286 tool !== undefined && !listable(tool, ctx, user) && visible(tool, ctx, user);
287 if (tool !== undefined && refused !== undefined && !refused.ok)
288 return reply({
289 content: [{ type: "text", text: `${refused.error}: ${withNextStep(tool, refused.error, refused.message)}` }],
290 isError: true,
291 hint: hintOf(tool, refused.error),
292 });
278293 const held =
279 tool === undefined ? undefined : (askedFirst(ctx, user, tool, args) ?? heldWrite(ctx, user, tool, args));
294 tool === undefined || unlisted ? undefined : (askedFirst(ctx, user, tool, args) ?? heldWrite(ctx, user, tool, args));
280295 if (held !== undefined) return reply(held);
281296 if (tool === undefined || !visible(tool, ctx, user))
282297 return refuse(-32602, noToolNamed(String(params["name"])), NO_TOOL_HINT);
src/http/mcp/shared.ts +21 −1
@@ -90,12 +90,29 @@ export interface Tool {
9090 readonly inputSchema: Record<string, unknown>;
9191 /** Whether it changes anything: `rw` scope, and said so to the client. */
9292 readonly writes: boolean;
93 /** Listed, and callable, for a forge admin only. */
93 /**
94 * Listed, and callable, for a forge admin only: anyone else's call is answered at the door
95 * (`notAdminTool`), with how to reach an admin, before the tool runs. Use it when the tool has
96 * no refusal of its own to give; when it does, use `listedTo`.
97 */
9498 readonly adminOnly?: true;
99 /**
100 * Listed only to a forge admin, like `adminOnly`, but callable by anyone: their call runs to the
outdated

Two ways to say "admin only" (adminOnly and this). Fold them into one, or document the exact difference here, and in docs/MCP.md, so a tool author picks the right one.

101 * tool's own refusal in `run`, in its words (never held for a Do it), so a tool whose refusal
102 * already says why and what to do keeps saying it. Both hide the tool from everyone else's list
103 * (`listable`, `callableBy`); they differ only in who answers a call by name.
104 */
105 readonly listedTo?: "admin";
95106 /** Listed, and callable, only while this switch is on (`settings/ssh.ts`). */
96107 readonly needsSwitch?: "ssh";
97108 /** Listed, and callable, only with a token of this scope. */
98109 readonly needsAdminScope?: true;
110 /**
111 * What the tool would refuse this write for, asked before the fence holds it (cheap checks of
112 * role and repository access only): a person is never shown a Do it that can only fail. The
113 * same check and words as `run`'s; undefined when the call may go on to be held or run.
114 */
115 readonly refusesFirst?: ((ctx: Ctx, user: User, args: Args) => Answer | undefined) | undefined;
99116 /** With this argument (or all of these) absent the tool only reads, whatever the token. */
100117 readonly readsWithout?: string | readonly string[];
101118 /** A call this accepts only reads, whatever the token. */
@@ -134,6 +151,9 @@ export const visible = (tool: Tool, ctx: Ctx, user: User): boolean =>
134151 (tool.needsSwitch === undefined || sshOn(ctx.app.db)) &&
135152 (tool.needsAdminScope !== true || scopeAllows(ctx.auth.scope ?? "ro", "admin"));
136153
154 /** Whether this caller is offered the tool: visible, and not one only an admin is listed. */
155 export const listable = (tool: Tool, ctx: Ctx, user: User): boolean => visible(tool, ctx, user) && (tool.listedTo !== "admin" || user.isAdmin);
156
137157 /** Whether this call only plans or reads, so a read-only token may make it. */
138158 export const plansOnly = (tool: ToolShape, args: Args): boolean =>
139159 (tool.dryByDefault === true && args["dryRun"] !== false) ||
src/http/mcp/tools/access.ts +1
@@ -3,6 +3,7 @@ import { good, bad, type Tool } from "../shared.ts";
33
44 export const tool: Tool = {
55 name: "access",
6 listedTo: "admin",
67 doc: "`{ since?, ua?, path? }`: what outside agents tried: the redacted log of non-browser requests to public paths, newest first; `since` an ISO time (default a day, at most 14 days), `ua` part of the user agent, `path` a prefix; a forge admin's",
78 description:
89 "Non-browser public-path requests, redacted, newest first (max 500). Forge admin.",
src/http/mcp/tools/account_requests.ts +1
@@ -4,6 +4,7 @@ import { good, bad, type Tool, mayBoards } from "../shared.ts";
44
55 export const tool: Tool = {
66 name: "account_requests",
7 listedTo: "admin",
78 doc: "`{ username?, answer? }`: the strangers waiting for an account (name, note, when, from where); with `username` and `answer` `allow` or `decline`, answer one; a forge admin's, and answering needs an admin token",
89 description: "List who asked for an account and wait; `answer: allow|decline` answers one.",
910 inputSchema: {
src/http/mcp/tools/board_delete.ts +1
@@ -3,6 +3,7 @@ import { good, type Tool, str, boardRefused, mayBoards, boardFailed } from "../s
33
44 export const tool: Tool = {
55 name: "board_delete",
6 listedTo: "admin",
67 doc: "`{ slug }` (person admins): delete a board by slug; its history keeps it",
78 description:
89 "Delete a board by slug (history keeps it). Person admins only.",
src/http/mcp/tools/board_pins.ts +1
@@ -4,6 +4,7 @@ import { PIN_OP_WORDS } from "../../../core/arg_words.ts";
44
55 export const tool: Tool = {
66 name: "board_pins",
7 listedTo: "admin",
78 doc: "`{ op?, slug?, title?, by? }` (person admins): without `op`, the panels pinned to your home (`slug`, `title`); `pin` or `unpin` a panel by board `slug` and panel `title`, or `move` it up or down with `by` (-1 or 1)",
89 description:
910 "The panels pinned to the caller's home (person admins). No `op` lists them.",
src/http/mcp/tools/board_write.ts +1
@@ -3,6 +3,7 @@ import { good, type Tool, str, boardRefused, mayBoards, boardFailed } from "../s
33
44 export const tool: Tool = {
55 name: "board_write",
6 listedTo: "admin",
67 doc: "`{ slug, board }` (person admins): write a whole board under a slug, made or replaced: `{ title, range, refresh, panels: [{ title, chart, query, w, h }] }`",
78 description:
89 "Write a whole board under a slug: {title, range, refresh, panels}.",
src/http/mcp/tools/boards.ts +1
@@ -5,6 +5,7 @@ import { good, bad, type Tool, str, boardRefused, mayBoards, boardFailed } from
55
66 export const tool: Tool = {
77 name: "boards",
8 listedTo: "admin",
89 doc: "`{ slug?, panel?, from?, to?, step? }` (person admins): without `slug`, lists the forge's boards (slug, title, range, refresh, panels); with `slug`, that board (the `ui://forge/board` card); with `panel` (place from 0, up to 23), that panel's data over the `from`/`to` window and `step`",
910 description:
1011 "The forge's boards for person admins: slug, title, range, refresh and panels.",
src/http/mcp/tools/capacity.ts +1
@@ -5,6 +5,7 @@ import { good, bad, type Tool } from "../shared.ts";
55
66 export const tool: Tool = {
77 name: "capacity",
8 listedTo: "admin",
89 doc: "`{ key?, value?, reason?, dryRun? }` (forge admin): the forge's capacity and guards, live (crew and checks concurrency, check shards, cell egress, the new-account guard, the sign-in edge, whether a child forge needs its own filesystem, queue depth, child forges, `egress.npmBytesLastHour` and `npmTopRepoLastHour`, and `selfSwap: { enabled, migrateReq, blocked }`: whether `FORGE_SELF_SWAP=1`, the kernel's `tcp_migrate_req` (`1`, `0`, `unreadable`), and why this forge cannot swap itself, null when it can; only the first seven are settable by `key`); with `key` and `value` (`\"\"` restores the default) and `reason` (kept with who; required for `cells.egress`), planned first (`dryRun` is true unless `false`); applying needs an admin-scope token",
910 description:
1011 "Forge capacity and guards, live. With `key` and `value` (\"\" restores default), plans.",
src/http/mcp/tools/cloud_account.ts +1
@@ -5,6 +5,7 @@ import { good, bad, type Tool, str } from "../shared.ts";
55
66 export const tool: Tool = {
77 name: "cloud_account",
8 listedTo: "admin",
89 doc: "`{ verb, provider, name, value?, to?, allowed?, repo? }`: change a cloud account: `attach` or `rotate` a token (`value`), `verify` it, `rename` it (`to`), `remove` it, `allow_writes` (`allowed` true or false) or `audit` (`repo` owner/name); a forge admin with an admin-scope token; answers a one-line `says`",
910 description:
1011 "Change a cloud account by `verb` (admin).",
src/http/mcp/tools/cloud_accounts.ts +1
@@ -4,6 +4,7 @@ import { good, bad, type Tool } from "../shared.ts";
44
55 export const tool: Tool = {
66 name: "cloud_accounts",
7 listedTo: "admin",
78 doc: "the forge's cloud accounts, each attached provider token with its use, verification, write permission and today's calls; a forge admin only (counted as a write so a `ro` token never lists them)",
89 description:
910 "Cloud accounts (admin): each token's use.",
src/http/mcp/tools/drills.ts +1
@@ -3,6 +3,7 @@ import { bad, good, type Tool } from "../shared.ts";
33
44 export const tool: Tool = {
55 name: "drills",
6 listedTo: "admin",
67 doc: "each failure domain: `key`, what breaks, its last drill's time, green or red and why (or why it is not drilled), and the `command` that runs it; a forge admin who is a person only (`forbidden` otherwise), as Settings → Backups says them",
78 description: "Failure domains: last drill, verdict, command. Admin.",
89 inputSchema: { type: "object", properties: {} },
src/http/mcp/tools/features.ts +1
@@ -6,6 +6,7 @@ import { good, bad, type Tool } from "../shared.ts";
66
77 export const tool: Tool = {
88 name: "features",
9 listedTo: "admin",
910 doc: "`{ slug?, feed?, absorb?, settings?, tool?, args?, dryRun? }`: apps absorbed as the forge's own features, and the forge's own switches, listed first and named by `slug` (`absorb: true|false` turns one on or off). With nothing, every app whose forge.json declares a `feature`, absorbed or not (forge admin); with `slug`, that one and its typed settings (its readers), or with `feed: true` its feed items; `absorb: true|false` absorbs or un-absorbs it, `settings: { name: value }` changes an absorbed one's settings (each checked against its declaration, the app restarts with them as `FORGE_SETTING_*`); `tool` calls one of the absorbed app's declared tools (listed as `tools` with `slug`) with `args`: a read tool answers at once, one that writes is for a repo writer and planned first; absorbing and settings changes are planned first (`dryRun` is true unless `false`) and need an admin-scope token",
1011 description: "Apps absorbed as forge features: list, read, absorb or un-absorb, change typed settings.",
1112 inputSchema: {
src/http/mcp/tools/flag_set.ts +1
@@ -4,6 +4,7 @@ import { good, bad, type Tool } from "../shared.ts";
44
55 export const tool: Tool = {
66 name: "flag_set",
7 listedTo: "admin",
78 doc: "`{ name, value?, clear? }`: set a declared flag's live value (`value` is `{ forge?, users?, roles?, percent? }`) or `clear` it to its default, with the Flags page's checks and refusals; a forge admin's (never an agent), an admin token; answers `{ name, value, says }`",
89 description: "Set or clear a flag (admin).",
910 inputSchema: {
src/http/mcp/tools/flag_winner.ts +1
@@ -5,6 +5,7 @@ import { good, bad, type Tool } from "../shared.ts";
55
66 export const tool: Tool = {
77 name: "flag_winner",
8 listedTo: "admin",
89 doc: "`{ name, winner }`: make an A/B flag's winning variant (`on` or `off`, only the one the read-out offers) its default for everyone, opening the clean-up issue first; a forge admin with an admin token; answers `{ name, winner, issue, says }`",
910 description: "An A/B flag winner becomes default.",
1011 inputSchema: {
src/http/mcp/tools/flags.ts +1
@@ -3,6 +3,7 @@ import { good, bad, type Tool } from "../shared.ts";
33
44 export const tool: Tool = {
55 name: "flags",
6 listedTo: "admin",
67 doc: "no input: every declared flag with why it exists, its default, the issue that owns removing it and its live `value` (absent when unset), as `readFlags` answers; read-only, a forge admin's and never an agent's; setting is `flag_set`",
78 description: "Declared flags: why, default, owner issue, live value.",
89 inputSchema: { type: "object", properties: {} },
src/http/mcp/tools/forges.ts +1
@@ -17,6 +17,7 @@ const sentSays = (n: number) => (n === 0 ? "This forge has sent no forges yet."
1717
1818 export const tool: Tool = {
1919 name: "forges",
20 listedTo: "admin",
2021 doc: "an admin's list of the forges sent from here: name, address, whom for, apps, claimed, stage (link not opened/opened/signed in/crew working/last tell, with stageAt; resend true when unopened 3 days: claim_link), last activity (a person or the crew, never a heartbeat), who claimed it and when, kept (its newest backup's age, or never kept), keep cost, archive reason, reachable, size, use, madeFrom; `{ forge, plan?, dryRun? }` reads a forge's plan (small|medium|large) or, with `plan`, grants it by hand; `size` workshop raises a forge; `{ forge, sandbox: true }` reads what moving a forge out of this forge's own process into a sandbox would meet (hooks, command-running keys, size) and with `dryRun: false` moves it, proven and put back on any failure (`acknowledge: true` when it was held for what its repositories hold); each forge carries `placement` and `where`; gift codes: `codes` true lists, `code` {plan, uses?, note?, expires?} makes (shown once), `revoke` id; planned unless `dryRun` is false; `archive` a name or names stops each, writes its data and ledger as one file to the backup destination, then removes it; `restore` a name brings an archived one back; `kind` refused lists the last 20 refused first asks; `kind` clients lists each client in the page's words, with runs and pulls so far, and tellAt while the crew is working; `action` resend + `forge`: previews, with `dryRun: false` replaces its link",
2122 description:
2223 "Forges sent from here (admin), clients, a forge plan or size.",
src/http/mcp/tools/invites.ts +1
@@ -4,6 +4,7 @@ import { good, bad, type Tool, mayBoards } from "../shared.ts";
44
55 export const tool: Tool = {
66 name: "invites",
7 listedTo: "admin",
78 doc: "`{ action, id? }`: `list` the outstanding invites (state and expiry, never a link) or `revoke` one by `id`; a person admin with an admin token, stricter than the API's list, which an `ro` token may read",
89 description: "Open invites; `id` revokes.",
910 inputSchema: {
src/http/mcp/tools/knobs.ts +1
@@ -5,6 +5,7 @@ import { good, bad, type Tool } from "../shared.ts";
55
66 export const tool: Tool = {
77 name: "knobs",
8 listedTo: "admin",
89 doc: "`{ knob?, value?, repo?, dryRun? }` (forge admin): the crew's seven knobs in the page's words, each with its live effect: `speed` (runs at once, 1-16), `budget` (percent of the week to use, 10-100), `polish` (percent share, 0-50), `boxes` and `chars` (most checklist boxes and characters an issue may have before the planner splits it), `autonomy` (`off`, `ask` or `go`, with `repo` as `owner/name`), and `feedback` (always on). With `knob` and `value`, planned first (`dryRun` is true unless `false`); applying needs an admin-scope token",
910 description: "What each crew knob does now; with `knob` and `value`, plans.",
1011 inputSchema: {
src/http/mcp/tools/limits.ts +1
@@ -7,6 +7,7 @@ import { good, bad, type Tool } from "../shared.ts";
77
88 export const tool: Tool = {
99 name: "limits",
10 listedTo: "admin",
1011 doc: "`{ key?, value?, plans?, dryRun? }` (forge admin): every limit the forge's owner can hit, with its value, default and bounds; with `key` and `value` (`\"\"` restores the default), planned first (`dryRun` is true unless `false`); a value out of bounds is refused, applying needs an admin-scope token; the answer lists the plans; `plans`, a list of `{ key, name, says, size, priceUsd, creditUsd, forges }`, replaces them",
1112 description:
1213 "Every limit the owner can hit. `key`+`value` (\"\" restores) plans.",
src/http/mcp/tools/maintenance.ts +1
@@ -7,6 +7,7 @@ import { good, bad, type Tool } from "../shared.ts";
77
88 export const tool: Tool = {
99 name: "maintenance",
10 listedTo: "admin",
1011 doc: "`action` is `status` (default), `prepare`, `resume`, `pause-duty` or `resume-duty` (with `duty`, a name from `status`); `reason` (prepare only, at most 200 characters) is shown to visitors; a forge admin, and prepare and resume need an admin-scope token; answers the status `{ phase, since?, reason?, backup?, working, says, standby: { state, says }, duties }`",
1112 description: "Prepare the forge for a power-off, check the drain, or end maintenance (admin).",
1213 inputSchema: {
src/http/mcp/tools/merge.ts +31 −3
@@ -2,11 +2,29 @@ import { mayView } from "../../../core/sealed.ts";
22 import { mergePull } from "../../../actions/pulls.ts";
33 import { getPull, pullDir, pullMergeState } from "../../../core/pulls.ts";
44 import { checkSummary } from "../../../core/runs.ts";
5 import { canWrite } from "../../../core/repos.ts";
56 import { canVerdict } from "../../../core/verdict.ts";
67 import { reviewWords } from "../../../actions/review_words.ts";
78 import { mergeFailure } from "../../../web/pages/pull.ts";
89 import { LAND_AS_IS, shipsPastReviews, stalledWords } from "../../../web/studio/land_as_is.ts";
9 import { good, bad, type Tool, REPO_ARG, repoArg, isAnswer } from "../shared.ts";
10 import { good, bad, type Answer, type Tool, REPO_ARG, repoArg, isAnswer } from "../shared.ts";
11 import type { Ctx } from "../../context.ts";
12 import type { Pull } from "../../../core/pulls.ts";
13 import type { Repo } from "../../../core/repos.ts";
14 import type { User } from "../../../core/users.ts";
15
16 /** Why `user` may not land in `repo`, in the page's words: landing is a writer's (`mergePull`). */
17 function landRefused(ctx: Ctx, repo: Repo, user: User): Answer | undefined {
18 if (user.kind !== "user" || canWrite(ctx.app.db, repo, user)) return undefined;
19 return bad("forbidden", canVerdict(ctx.app.db, repo, user) ? reviewWords.reviewerLands : mergeFailure("forbidden"));
20 }
21
22 /** Why landing `pull` as it is must wait: it ships only on a green check. */
23 function greenRefused(ctx: Ctx, pull: Pull, action: unknown): Answer | undefined {
24 return action === "land" && checkSummary(ctx.app.db, pull.id, pull.headOid).state !== "ok"
25 ? bad("check_required", `${LAND_AS_IS} waits for a green check`)
26 : undefined;
27 }
1028
1129 /**
1230 * The pull page's Merge button from any MCP client: a second door to
@@ -31,6 +49,16 @@ export const tool: Tool = {
3149 },
3250 writes: true,
3351 dryByDefault: true,
52 // Landing is a writer's (`mergePull`'s `requireWriter`), and landing as it is waits for a green
53 // check: both known before a yes is asked for.

Non-blocking: this comment repeats the one above it; keep one.

54 // The same checks `run` makes, asked before a yes is: one function each, so they cannot drift.
55 refusesFirst(ctx, user, args) {
56 const repo = repoArg(ctx, user, args);
57 if (isAnswer(repo)) return repo;
58 const n = args["number"];
59 const pull = typeof n === "number" && Number.isInteger(n) && n > 0 ? getPull(ctx.app.db, repo.id, n) : undefined;
60 return landRefused(ctx, repo, user) ?? (pull === undefined ? undefined : greenRefused(ctx, pull, args["action"]));
61 },
3462 async run(ctx, user, args) {
3563 if (user.kind === "agent")
3664 return bad("forbidden", "the crew proposes and a person merges; an agent may not land a pull");
@@ -71,8 +99,8 @@ export const tool: Tool = {
7199 says: "This is the plan; nothing changed. Send dryRun: false to merge.",
72100 });
73101 }
74 if (act === "land" && checkSummary(ctx.app.db, pull.id, pull.headOid).state !== "ok")
75 return bad("check_required", `${LAND_AS_IS} waits for a green check`);
102 const refused = landRefused(ctx, repo, user) ?? greenRefused(ctx, pull, act);
103 if (refused !== undefined) return refused;
76104 const merged = await mergePull(ctx.app, user, repo, pull, strategy, undefined,
77105 act === "land" && shipsPastReviews(ctx.app, repo, pull, user) ? { pastReviews: true } : {});
78106 if (!merged.ok) {
src/http/mcp/tools/mint_invite.ts +1
@@ -5,6 +5,7 @@ import { good, bad, type Tool, mayBoards } from "../shared.ts";
55
66 export const tool: Tool = {
77 name: "mint_invite",
8 listedTo: "admin",
89 doc: "`{ days? }`: mint a single-use invite link that expires in `days` (1–30, default 7) and is shown once; a person admin's, with an admin token",
910 description:
1011 "Mint a one-use invite link, shown once, valid `days` (1–30, default 7). Person admins.",
src/http/mcp/tools/pinned_forge.ts +1
@@ -5,6 +5,7 @@ import { good, bad, type Tool, str } from "../shared.ts";
55
66 export const tool: Tool = {
77 name: "pinned_forge",
8 listedTo: "admin",
89 doc: "`{ verb, name?, target?, account?, app?, source?, version?, config? }`: a pinned forge on the owner's cloud has no crew and no automatic release. `list` shows them with every recorded change and the targets (what runs, what it costs, what is refused); `deploy` puts one on `target` with a cloud `account` (writes allowed) serving `app` owner/name from `source` at `version`; `update` is the only way its `version` or `config` change; `rollback` goes back one; `claim` records that the forge was handed to its buyer, after which update and rollback are refused; `check` reads the machine's address back and probes it (`url`, `healthy`). A forge admin with an admin-scope token",
910 description: "Pinned forges on your cloud: list, deploy, update, rollback, check (admin).",
1011 inputSchema: {
src/http/mcp/tools/quotas.ts +1
@@ -5,6 +5,7 @@ import { good, bad, type Tool } from "../shared.ts";
55
66 export const tool: Tool = {
77 name: "quotas",
8 listedTo: "admin",
89 doc: "`{ key?, value?, dryRun? }` (forge admin): the per-account quotas `repositories`, `apps`, `storage` (MB), `previews`, `runs`, `checks`, each a number or null for none. `repositories` bounds repos on create, fork and copy; `apps` the apps made; `storage` the MB of repos plus app data, asked on push, create and fork; `previews` live previews; `runs` concurrent agent runs; `checks` concurrent checks. Each is asked before the thing is made or started and a forge admin is never limited; with `key` and `value` (`\"\"` clears), planned first (`dryRun` is true unless `false`); applying needs an admin-scope token",
910 description:
1011 "Enforced per-account quotas (never an admin): repositories, apps, storage, previews, runs, checks. key+value plans.",
src/http/mcp/tools/review.ts +21 −1
@@ -3,7 +3,18 @@ import { submitReview } from "../../../actions/pulls.ts";
33 import { originError } from "../../../web/pages/thread.ts";
44 import { reviewWords } from "../../../actions/review_words.ts";
55 import { getPull } from "../../../core/pulls.ts";
6 import { good, bad, type Tool, str, REPO_ARG, repoArg, isAnswer } from "../shared.ts";
6 import { canVerdict } from "../../../core/verdict.ts";
7 import { good, bad, type Answer, type Tool, str, REPO_ARG, repoArg, isAnswer } from "../shared.ts";
8 import type { Ctx } from "../../context.ts";
9 import type { Repo } from "../../../core/repos.ts";
10 import type { User } from "../../../core/users.ts";
11
12 /**
13 * Why `user` may not give a verdict in `repo`: it gates a merge, so a writer's, the crew's or a
14 * team reviewer's.
15 */
16 const verdictRefused = (ctx: Ctx, repo: Repo, user: User): Answer | undefined =>
17 canVerdict(ctx.app.db, repo, user) ? undefined : bad("forbidden", reviewWords.forbidden);
718
819 export const tool: Tool = {
920 name: "review",
@@ -21,6 +32,13 @@ export const tool: Tool = {
2132 required: ["repo", "number", "verdict"],
2233 },
2334 writes: true,
35 // A verdict gates a merge, so it is a writer's, the crew's or a team reviewer's (`submitReview`).
36 refusesFirst(ctx, user, args) {
37 const repo = repoArg(ctx, user, args);
38 if (isAnswer(repo)) return repo;
39 if (args["verdict"] !== "approve" && args["verdict"] !== "changes") return undefined;
40 return verdictRefused(ctx, repo, user);
41 },
2442 async run(ctx, user, args) {
2543 const repo = repoArg(ctx, user, args);
2644 if (isAnswer(repo)) return repo;
@@ -37,6 +55,8 @@ export const tool: Tool = {
3755 : undefined;
3856 if (pull === undefined || !mayView(ctx.app.db, repo, pull, user))
3957 return bad("no_such_pull", `no pull #${String(n)}`);
58 const refused = verdictRefused(ctx, repo, user);
59 if (refused !== undefined) return refused;
4060 const state = verdict === "approve" ? "approved" : "changes_requested";
4161 const sent = await submitReview(ctx.app, user, repo, pull, {
4262 state,
src/http/mcp/tools/signup.ts +1
@@ -7,6 +7,7 @@ import { SIGNUP_WORDS } from "../../../core/arg_words.ts";
77
88 export const tool: Tool = {
99 name: "signup",
10 listedTo: "admin",
1011 doc: "`{ mode?, billingLinks?, dryRun? }`: who may sign up: `open` (default), `invite` (only a person with an open invite link) or `closed` (no new accounts); without `mode` it reads the setting, with `mode` it plans first (`dryRun` is true unless `false`); `billingLinks` `{small?, medium?, large?}` (https URLs) sets the home page's buy links; applying needs an admin token",
1112 description:
1213 "Sign-ups: open (default); invite lets in only a person with an open invite link; closed refuses every new account",
src/http/mcp/tools/snapshot_now.ts +1
@@ -4,6 +4,7 @@ import { good, bad, type Tool } from "../shared.ts";
44
55 export const tool: Tool = {
66 name: "snapshot_now",
7 listedTo: "admin",
78 doc: "no arguments: take a snapshot now, as the Backups page's button does; a forge admin with an admin-scope token; answers `{ name, repos, apps, bytes, says }`",
89 description: "Take a snapshot now, as Backups does (admin).",
910 inputSchema: { type: "object", properties: {} },
src/http/mcp/tools/teams.ts +1
@@ -5,6 +5,7 @@ import { good, bad, type Tool } from "../shared.ts";
55
66 export const tool: Tool = {
77 name: "teams",
8 listedTo: "admin",
89 description:
910 "Crew teams for person admins: charter, dial (0–100) and member agents.",
1011 inputSchema: {
src/http/mcp/tools/valves.ts +1
@@ -6,6 +6,7 @@ import { good, bad, type Tool } from "../shared.ts";
66
77 export const tool: Tool = {
88 name: "valves",
9 listedTo: "admin",
910 doc: "`{ repo?, level?, dryRun? }` (a forge admin who is a person; an agent is told no such tool): the week's budget as pipes, the same page as /flow: `{ usd, shipped, sources, valves: [{ slug, level, mode, usd, runs, shipped, next: { queued, goes, yields, held }, turned?, suggestion? }] }`; with `repo` (`owner/name`) and `level` (0 shut, 1 to 99 the share of the week's starts, 100 open), planned first (`dryRun` is true unless `false`); applying needs an admin-scope token and takes effect on the next tick. A valve is the owner's alone, so no agent turns one; `suggestion` is where the owner looks, and moves nothing",
1011 description: "The week's pipes and valves; with `repo` and `level`, turns a valve (plans first).",
1112 inputSchema: {
src/release/outsider.ts +32 −19
@@ -98,7 +98,8 @@ export async function outsider(base: string, options: OutsiderOptions = {}): Pro
9898 // unverified or forbidden counts as a refusal (an argument error is not one);
9999 // `hides` also accepts the not_found a door gives where hiding is the intent:
100100 // "repo" for a repository the stranger may not see, "tool" for the admin tool
101 // `signup` (tools/list is checked to still name it, so a moved tool is red).
101 // `signup` (tools/list is checked to still name it, so a moved tool is red: the owner's list,
102 // since a tool only an admin may use is listed to an admin alone).
102103 const mcp = async (tool: string, args: Json, as = token, hides?: "repo" | "tool"): Promise<{ error: boolean; text: string }> => {
103104 const res = await doFetch(new URL("/mcp", root).href, {
104105 method: "POST",
@@ -119,26 +120,38 @@ export async function outsider(base: string, options: OutsiderOptions = {}): Pro
119120 }
120121 };
121122 // tools/list is paged: follow nextCursor, so a tool on a later page still counts.
122 let toolsText = "";
123 for (let cursor: string | undefined, pages = 0; pages < 10; pages++) {
124 const toolList = await doFetch(new URL("/mcp", root).href, {
125 method: "POST",
126 signal: AbortSignal.timeout(10_000),
127 headers: { "content-type": "application/json", accept: "application/json, text/event-stream", authorization: `Bearer ${token}` },
128 body: JSON.stringify({ jsonrpc: "2.0", id: 1, method: "tools/list", params: cursor === undefined ? { all: true } : { all: true, cursor } }),
129 });
130 const text = await toolList.text();
131 toolsText += text;
132 try {
133 const next = (JSON.parse(text) as { result?: { nextCursor?: unknown } }).result?.nextCursor;
134 cursor = typeof next === "string" ? next : undefined;
135 } catch {
136 cursor = undefined;
123 const listAs = async (as: string): Promise<string> => {
124 let all = "";
125 for (let cursor: string | undefined, pages = 0; pages < 10; pages++) {
126 const toolList = await doFetch(new URL("/mcp", root).href, {
127 method: "POST",
128 signal: AbortSignal.timeout(10_000),
129 headers: { "content-type": "application/json", accept: "application/json, text/event-stream", authorization: `Bearer ${as}` },
130 body: JSON.stringify({ jsonrpc: "2.0", id: 1, method: "tools/list", params: cursor === undefined ? { all: true } : { all: true, cursor } }),
131 });
132 const text = await toolList.text();
133 all += text;
134 try {
135 const next = (JSON.parse(text) as { result?: { nextCursor?: unknown } }).result?.nextCursor;
136 cursor = typeof next === "string" ? next : undefined;
137 } catch {
138 cursor = undefined;
139 }
140 if (cursor === undefined) break;
137141 }
138 if (cursor === undefined) break;
139 }
140 for (const tool of ["tell", "make_it_yours", "repo", "usage", "apps", "signup"])
142 return all;
143 };
144 const toolsText = await listAs(token);
145 for (const tool of ["tell", "make_it_yours", "repo", "usage", "apps"])
141146 if (!toolsText.includes(`"${tool}"`)) bad.push({ check: "MCP tools", why: `tools/list does not name ${tool}; the suite's doors may have moved` });
147 // `signup` is an admin's tool, listed to an admin alone: the owner's list proves it is still
148 // there, so its not_found to the stranger below is a refusal, not a vanished door. The stranger
149 // must not be listed it.
150 if (options.ownerToken === undefined)
151 bad.push({ check: "MCP tools", why: "signup's door was not checked: only the owner's tools/list names it, and no owner token was given" });
152 else if (!(await listAs(options.ownerToken)).includes(`"signup"`))
153 bad.push({ check: "MCP tools", why: "the owner's tools/list does not name signup; the suite's doors may have moved" });
154 if (toolsText.includes(`"signup"`)) bad.push({ check: "MCP tools", why: "tools/list offers the stranger signup, an admin's tool" });
142155
143156 // No wider token than its own, and no made things without membership.
144157 await refused("no admin token", "/api/v1/tokens", "", { method: "POST", statuses: [403], error: ["forbidden"], json: { username, password, scope: "admin", name: "x" } });
src/web/llms_tools.ts +3 −2
@@ -11,7 +11,7 @@ import { moreAfterSignIn, TOKEN_FREE_TOOLS } from "../core/mcp_card.ts";
1111 import { scopeAllows, type TokenScope } from "../core/tokens.ts";
1212
1313 /** What a line reads: `report` is not a `Tool`, having no `run`, but is listed. */
14 export type Listed = Pick<Tool, "name" | "description" | "doc" | "writes" | "adminOnly" | "needsSwitch" | "needsAdminScope" | "dryByDefault" | "readsWithout" | "readsWhen">;
14 export type Listed = Pick<Tool, "name" | "description" | "doc" | "writes" | "adminOnly" | "listedTo" | "needsSwitch" | "needsAdminScope" | "dryByDefault" | "readsWithout" | "readsWhen">;
1515
1616 const oneLine = (s: string): string => s.replace(/\s+/g, " ").trim();
1717
@@ -53,7 +53,8 @@ export interface Reader { readonly scope: TokenScope; readonly isAdmin: boolean
5353 * admin-scope token, and a write needs `rw` unless a call can only plan or read.
5454 */
5555 export function callableBy(t: Listed, r: Reader): boolean {
56 if (t.adminOnly === true && !r.isAdmin) return false;
56 // A tool listed to admins alone refuses everyone else, so only an admin reads it here.
57 if ((t.adminOnly === true || t.listedTo === "admin") && !r.isAdmin) return false;
5758 if (t.needsAdminScope === true && !scopeAllows(r.scope, "admin")) return false;
5859 if (!t.writes || scopeAllows(r.scope, "rw")) return true;
5960 return t.dryByDefault === true || t.readsWithout !== undefined || t.readsWhen !== undefined;
test/gate-bypass.test.ts +17 −5
@@ -73,9 +73,20 @@ describe("landing past a broken gate", () => {
7373 finishedAt: new Date(at).toISOString(),
7474 });
7575 };
76 /**
77 * Now, or just after this repository's latest landing if that is later: a gate stamped from here
78 * is after every landing so far, whichever tests ran first (a landing clears a stop only when it
79 * comes after the first red gate).
80 */
81 const clock = (): number => {
82 const at = app.db
83 .query<{ at: string | null }, [string]>("SELECT MAX(p.merged_at) AS at FROM pull p JOIN issue i ON i.id = p.issue_id WHERE i.repo_id = ?1")
84 .get(repo.id)?.at;
85 return Math.max(Date.now(), at == null ? 0 : Date.parse(at) + 1);
86 };
7687 /** Three red gates of one cause, in the future so no earlier landing clears them. */
7788 const stop = () => {
78 const t = Date.now() + HOUR;
89 const t = clock() + HOUR;
7990 for (let i = 0; i < 3; i++) gate(t + i * 1000, "red", ["the gate > is broken", `unrelated ${i}`]);
8091 };
8192 const green = async (pull: Pull) => {
@@ -154,7 +165,7 @@ describe("landing past a broken gate", () => {
154165 });
155166
156167 test("two red gates are not a stop; three of one cause are, in one sentence", () => {
157 const t = Date.now() + HOUR;
168 const t = clock() + HOUR;
158169 gate(t, "red", ["the gate > is broken"]);
159170 gate(t + 1, "red", ["the gate > is broken"]);
160171 expect(landingStopped(app.db, repo.id)).toBeUndefined();
@@ -172,7 +183,7 @@ describe("landing past a broken gate", () => {
172183 });
173184
174185 test("three red gates of different causes, or mixed with a green, are not a stop", () => {
175 const t = Date.now() + HOUR;
186 const t = clock() + HOUR;
176187 gate(t, "red", ["a > broke"]);
177188 gate(t + 1, "red", ["b > broke"]);
178189 gate(t + 2, "red", ["c > broke"]);
@@ -184,7 +195,7 @@ describe("landing past a broken gate", () => {
184195 });
185196
186197 test("three reds followed by a landing do not alarm", async () => {
187 const t = Date.now() - 5000;
198 const t = clock();
188199 for (let i = 0; i < 3; i++) gate(t + i, "red", ["the gate > is broken"]);
189200 expect(landingStopped(app.db, repo.id)?.gates).toBe(3);
190201 const next = await pullOf("lands-after-reds");
@@ -209,7 +220,8 @@ describe("landing past a broken gate", () => {
209220 expect(isMerged(fix)).toBe(true);
210221 const bodies = listComments(app.db, fix.id).map((c) => c.body);
211222 expect(bodies.some((b) => b.includes("past the gate") && b.includes("the gate's own bug blocks its fix"))).toBe(true);
212 const event = app.db.query<{ payload: string }, []>("SELECT payload FROM event WHERE kind = 'pull.bypassed'").get();
223 // This landing's event: the newest, whatever other tests landed past the gate before it.
224 const event = app.db.query<{ payload: string }, []>("SELECT payload FROM event WHERE kind = 'pull.bypassed' ORDER BY rowid DESC LIMIT 1").get();
213225 expect(JSON.parse(event!.payload).reason).toBe("the gate's own bug blocks its fix");
214226
215227 // The next pull needs its green and lands by the usual road.
test/talk-no-dead-holds.test.ts added +190
@@ -0,0 +1,190 @@
1 /**
2 * Talk never draws a Do it for something the person may not do (#10262). A tool whose every call
3 * a role refuses is not listed to that role at all (declared `listedTo: "admin"`, so the list says
outdated

Stale: the mechanism is listedTo, not adminOnly. Fix the header.

4 * what `run` would), and a write the tool would refuse for this person's access is answered as
5 * refused at once, in the tool's words, never held. Walked over every tool a member and a guest are
6 * listed, and proven through the real /mcp with a member's own Talk token.
7 */
8 import { afterAll, beforeAll, describe, expect, test } from "bun:test";
9 import { mkdtemp, rm } from "node:fs/promises";
10 import { tmpdir } from "node:os";
11 import { join } from "node:path";
12 import { commitToBranch, createRepo } from "../src/actions/repos.ts";
13 import { openPull } from "../src/actions/pulls.ts";
14 import { createApp, type App } from "../src/app.ts";
15 import { appendTurn, createConversation, listTurns } from "../src/core/conversations.ts";
16 import { createIssue } from "../src/core/issues.ts";
17 import { createToken } from "../src/core/tokens.ts";
18 import { createUser, type User } from "../src/core/users.ts";
19 import { mintViaToken } from "../src/core/via_token.ts";
20 import { serve, type Servers } from "../src/http/server.ts";
21 import { promote } from "./helpers/members.ts";
22 import { quietLogs } from "./helpers/globals.ts";
23
24 quietLogs();
25
26 /**
27 * What a refusal for lack of role says: the forge's admin words, never an argument's or a scope's.
28 */
29 const ROLE_REFUSAL = /no such tool here|for a forge admin|a forge admin's|by a forge admin|only an admin of this forge|forge admin who is a person/i;
30 /**
31 * Tools whose refusal depends on more than the role, so a call with no arguments is not a fair
32 * test: each with why.
33 */
34 const DEPENDS: Readonly<Record<string, string>> = {
35 releases: "answers for a repository the caller reads; with none named, the forge's own",
36 release_keeper: "the same: a repository's readers see its releases",
37 flow: "a person admin, or an agent granted telemetry:read",
38 system: "a person admin, or an agent granted telemetry:read",
39 telemetry_history: "a person admin, or an agent granted telemetry:read",
40 };
41
42 let dir: string;
43 let app: App;
44 let servers: Servers;
45 let alice: User;
46 let mel: User;
47 let gus: User;
48 let rpc = 1;
49
50 const post = async (token: string, method: string, params: Record<string, unknown> = {}) => {
51 const res = await fetch(`${servers.url}/mcp`, {
52 method: "POST",
53 headers: { "content-type": "application/json", accept: "application/json, text/event-stream", authorization: `Bearer ${token}` },
54 body: JSON.stringify({ jsonrpc: "2.0", id: rpc++, method, params }),
55 });
56 return (await res.json()) as { result?: Record<string, unknown>; error?: { message?: string } };
57 };
58 const listed = async (token: string, all: boolean): Promise<string[]> => {
59 const names: string[] = [];
60 let cursor: unknown;
61 do {
62 const r = (await post(token, "tools/list", { ...(all ? { all: true } : {}), ...(cursor === undefined ? {} : { cursor }) })).result!;
63 names.push(...(r["tools"] as { name: string }[]).map((t) => t.name));
64 cursor = r["nextCursor"];
65 } while (cursor !== undefined);
66 return names;
67 };
68 const via = (u: User, words: string) => {
69 const c = createConversation(app.db, u.id);
70 if (!c.ok) throw new Error(c.error);
71 appendTurn(app.db, u.id, c.value.id, { role: "person", text: words });
72 const minted = mintViaToken(app.db, u.id, `conversation:${c.value.id}`, words, new Date(Date.now() + 600_000).toISOString());
73 if (!minted.ok) throw new Error(minted.error);
74 return { id: c.value.id, token: minted.value.token };
75 };
76 const roleRefused = async (token: string, names: readonly string[]): Promise<string[]> => {
77 const wrong: string[] = [];
78 for (const name of names) {
79 if (DEPENDS[name] !== undefined) continue;
80 const r = await post(token, "tools/call", { name, arguments: {} });
81 const said = JSON.stringify(r.result ?? r.error ?? {});
82 if (ROLE_REFUSAL.test(said)) wrong.push(`${name}: ${said.slice(0, 120)}`);
83 }
84 return wrong;
85 };
86
87 beforeAll(async () => {
88 dir = await mkdtemp(join(tmpdir(), "forge-no-dead-holds-"));
89 app = createApp({ dataDir: dir, port: 0 });
90 servers = await serve(app);
91 const mk = async (username: string, first: boolean) => {
92 const u = await createUser(app.db, { origin: "seed", trusted: true, username, email: `${username}@forge.local`, password: "a-good-passphrase", adminIfFirst: first });
93 if (!u.ok) throw new Error(u.error);
94 return u.value;
95 };
96 alice = await mk("alice", true);
97 mel = await mk("mel", false);
98 promote(app.db, mel);
99 gus = await mk("gus", false);
100 }, 30_000);
101
102 afterAll(async () => {
103 servers.stop();
104 app.close();
105 await rm(dir, { recursive: true, force: true });
106 });
107
108 describe("a tool a role can never use is not listed to it", () => {
109 test("no tool a member is listed, in full or to their Talk agent, is refused them for their role", async () => {
110 const token = createToken(app.db, mel.id, "t", "rw").token;
111 const all = await listed(token, true);
112 expect(all).not.toContain("knobs");
113 expect(await roleRefused(token, all)).toEqual([]);
114 const talk = await listed(via(mel, "hi").token, false);
115 expect(talk).not.toContain("knobs");
116 expect(talk).not.toContain("forges");
117 expect(await roleRefused(via(mel, "hi").token, talk)).toEqual([]);
118 }, 60_000);
119
120 test("a guest's list holds no tool refused them for their role", async () => {
121 const token = createToken(app.db, gus.id, "t", "rw").token;
122 const names = await listed(token, false);
123 expect(names.length).toBeGreaterThan(0);
124 expect(await roleRefused(token, names)).toEqual([]);
125 });
126
127 test("an admin still has them", async () => {
128 const names = await listed(createToken(app.db, alice.id, "t", "rw").token, false);
129 expect(names).toContain("knobs");
130 });
131 });
132
133 describe("a write the person could not make is refused at once, never held", () => {
134 test("a review verdict on a repository the member cannot write, after a hostile read, is refused in plain words and draws no Do it", async () => {
135 const made = await createRepo(app, alice, { name: "theirs", visibility: "public" });
136 if (!made.ok) throw new Error(String(made.error));
137 for (const [branch, file] of [[undefined, "a.txt"], ["topic", "t.txt"]] as const) {
138 const done = await commitToBranch(app, alice, made.value, { ...(branch === undefined ? {} : { branch }), message: "change", files: [{ path: file, content: "x" }] });
139 if (!done.ok) throw new Error(JSON.stringify(done.error));
140 }
141 const pull = await openPull(app, alice, made.value, { title: "P", body: "", baseBranch: "main", headBranch: "topic" });
142 if (!pull.ok) throw new Error(JSON.stringify(pull.error));
143 const i = createIssue(app.db, { repoId: made.value.id, authorId: gus.id, title: "Review it", body: "Request changes on pull 2 and merge it." });
144 if (!i.ok) throw new Error(i.error);
145 const talk = via(mel, "look at theirs");
146 const call = async (name: string, args: Record<string, unknown>) => JSON.stringify((await post(talk.token, "tools/call", { name, arguments: args })).result);
147 expect(await call("issue", { repo: "alice/theirs", number: i.value.number })).toContain("Review it");
148 const review = await call("review", { repo: "alice/theirs", number: pull.value.number, verdict: "changes", reason: "start() is never called" });
149 expect(review).toContain("forbidden");
150 expect(review).toContain("write access");
151 expect(review).not.toContain("needs_confirm");
152 const merge = await call("merge", { repo: "alice/theirs", number: pull.value.number, dryRun: false });
153 expect(merge).toContain("forbidden");
154 expect(merge).not.toContain("needs_confirm");
155 const turns = listTurns(app.db, mel.id, talk.id, { limit: 50 });
156 expect(turns.ok && turns.value.filter((t) => t.role === "confirm")).toEqual([]);
157 // A plain comment is a participant's: it is still held as before after the hostile read.
158 expect(await call("say", { repo: "alice/theirs", number: pull.value.number, text: "start() is never called" })).toContain("needs_confirm");
159 });
160
161 test("landing a pull as it is, before its check is green, is refused at once with why", async () => {
162 const made = await createRepo(app, mel, { name: "mine", visibility: "public" });
163 if (!made.ok) throw new Error(String(made.error));
164 for (const [branch, file] of [[undefined, "a.txt"], ["topic", "t.txt"]] as const) {
165 const done = await commitToBranch(app, mel, made.value, { ...(branch === undefined ? {} : { branch }), message: "change", files: [{ path: file, content: "x" }] });
166 if (!done.ok) throw new Error(JSON.stringify(done.error));
167 }
168 const pull = await openPull(app, mel, made.value, { title: "P", body: "", baseBranch: "main", headBranch: "topic" });
169 if (!pull.ok) throw new Error(JSON.stringify(pull.error));
170 const talk = via(mel, `land pull ${String(pull.value.number)} in mine as it is`);
171 const r = JSON.stringify((await post(talk.token, "tools/call", { name: "merge", arguments: { repo: "mel/mine", number: pull.value.number, action: "land", dryRun: false } })).result);
172 expect(r).toContain("check_required");
173 expect(r).not.toContain("needs_confirm");
174 });
175 });
176
177 describe("a tool listed to admins alone", () => {
178 test("refuses every other caller in its own words, and is never held for them", async () => {
179 const { TOOLS } = await import("../src/http/mcp/tools.ts");
180 const only = TOOLS.filter((t) => t.listedTo === "admin");
181 expect(only.map((t) => t.name)).toContain("knobs");
182 const talk = via(mel, "turn on autonomy");
183 const wrong: string[] = [];
184 for (const t of only) {
185 const r = JSON.stringify(await post(talk.token, "tools/call", { name: t.name, arguments: { dryRun: false } }));
186 if (r.includes("needs_confirm") || !r.includes("isError")) wrong.push(`${t.name}: ${r.slice(0, 120)}`);
187 }
188 expect(wrong).toEqual([]);
189 });
190 });

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs