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

The MCP `system` tool pauses and resumes the planner, with a preview before the act #13152

Merged opened this

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

Merged

torque/forge:torque/13107-the-mcp-system-tool-pauses-and-resumes-t → main 8 commits fork 4 threads · 4 unresolved

  • Merged. torque/13107-the-mcp-system-tool-pauses-and-resumes-t was merged into main as b7941dc.

Review

Sign in to review this change.
8 files changed +168 −22
docs/MCP.md +1 −1
@@ -224,7 +224,7 @@ bytes in `tools/list`. After changing a tool run `bun scripts/mcp-table.ts`;
224224 | `subscription_wake` | — | Admin: wake a resting subscription | 168 |
225225 | `subscriptions` | — | Claude accounts: scopes, budgets | 158 |
226226 | `sync` | — | Sync a mirror now; `originId` reconnects it | 197 |
227 | `system` | `csp`, `routes`, `footing`, `offsite`, `size`, `maintenance`, `growth` | The forge machine now: CPU, memory, disk, network | 361 |
227 | `system` | `pause`, `resume`, `csp`, `routes`, `footing`, `offsite`, `size`, `maintenance`, `growth` | The forge machine now: CPU, memory, disk, network | 433 |

pause and resume are values of action under kind growth, not kinds. The column lists kinds, so this misleads. Name only growth there and leave the action to the tool doc, or regenerate the table if mcp-table.ts produces this on purpose.

228228 | `take_back` | — | Open the pull that undoes a shipped pull | 219 |
229229 | `take_updates` | — | Take the parent forge's updates into a fork | 176 |
230230 | `teams` | — | Crew teams for person admins: charter, dial (0–100) and member agents | 338 |
docs/features/growth.md +7 −2
@@ -28,5 +28,10 @@ not see them. Today's numbers are in that answer only; the page and terminal sho
2828 Closed-per-day has no index of its own: it walks the repository's rows through the existing `repo_id` index
2929 (one made the retrospective's plan sort). Opened-per-day uses `issue_repo_created`.
3030
31 Not done: the MCP tool for the switch (the API and both doors are the way in for now), the panel on the
32 repository home, one action per aged item, and "until the chapter closes" (the forge has no chapters).
31 **The switch over MCP.** `system` with `{ kind: "growth", repo, action: "pause" | "resume", until? }` answers what
32 it would do and changes nothing; with `confirm: true` it calls `setPlannerSwitch`, as the page's switch does, and the
33 event is `planner.paused` or `planner.resumed`. `until` is a UTC time within a year; pause without it lasts until
34 the planner is switched on. An agent or a non-admin gets the page's sentence, "Only the owner switches the planner."
35
36 Not done: the panel on the repository home, one action per aged item, and "until the chapter closes" (the forge
outdated

The Not-done line is now wrapped raggedly ("the panel on the" then a short line). Rewrap it as one paragraph.

37 has no chapters).
src/actions/planner_switch.ts +25 −5
@@ -19,6 +19,24 @@ export type SwitchInput =
1919
2020 export type SwitchError = "not_found" | "forbidden" | "invalid";
2121
22 /** The page's sentence for each refusal of the switch. */
23 export const SWITCH_REFUSED: Record<SwitchError, string> = {
24 not_found: "No such repository.",
25 forbidden: "Only the owner switches the planner.",
26 invalid: "Pick a time in the future, within a year.",
27 };
28
29 /** A person who administers the repository may switch the planner; an agent never. */
30 export function maySwitch(app: App, actor: User | undefined, repo: Repo): boolean {
31 return actor !== undefined && actor.kind !== "agent" && canAdmin(app.db, repo, actor);
32 }
33
34 /** Whether `at` (UTC) is a time in the future within a year. */
35 export function validUntil(at: string, now = new Date()): boolean {
36 const t = Date.parse(at);
37 return Number.isFinite(t) && t > now.getTime() && t <= now.getTime() + 366 * 86_400_000;
38 }
39
2240 /** Sets the switch; the value is when the pause lifts, or null when the planner is on. */
2341 export function setPlannerSwitch(
2442 app: App,
@@ -28,7 +46,7 @@ export function setPlannerSwitch(
2846 now = new Date(),
2947 ): Result<string | null, SwitchError> {
3048 if (actor === undefined) return err("not_found");
31 if (actor.kind === "agent" || !canAdmin(app.db, repo, actor)) return err("forbidden");
49 if (!maySwitch(app, actor, repo)) return err("forbidden");
3250 if (input.mode === "on") resumePlanner(app.db, repo.id);
3351 else {
3452 let until: string;
@@ -37,9 +55,8 @@ export function setPlannerSwitch(
3755 const reset = weekCapacity(app.db, now)?.resetsAt ?? null;
3856 until = reset !== null && reset > now.toISOString() ? reset : nextWeek(now);
3957 } else {
40 const t = Date.parse(input.at);
41 if (!Number.isFinite(t) || t <= now.getTime() || t > now.getTime() + 366 * 86_400_000) return err("invalid");
42 until = new Date(t).toISOString();
58 if (!validUntil(input.at, now)) return err("invalid");
59 until = new Date(Date.parse(input.at)).toISOString();
4360 }
4461 pausePlanner(app.db, repo.id, until, actor.id);
4562 }
@@ -53,7 +70,10 @@ export function setPlannerSwitch(
5370 return ok(until);
5471 }
5572
56 /** A `datetime-local` value (minutes or seconds, no zone) is UTC, as the page says; anything else goes through as typed. */
73 /**
74 * A `datetime-local` value (minutes or seconds, no zone) is UTC, as the page says; anything else
75 * goes through as typed.
76 */
5777 export function utcAt(at: string): string {
5878 const t = at.trim();
5979 return /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}(:\d{2}(\.\d{1,3})?)?$/.test(t) ? `${t.length === 16 ? `${t}:00` : t}Z` : t;
src/http/mcp/tools/system.ts +28 −4
@@ -15,17 +15,20 @@ import { largestDirs } from "../../../system/largest_dirs.ts";
1515 import { dbSize } from "../../../system/db_size.ts";
1616 import { weekRows } from "../../../maintain/week_line.ts";
1717 import { duties } from "../../../maintain/registry.ts";
18 import { maySwitch, setPlannerSwitch, SWITCH_REFUSED, utcAt, validUntil, type SwitchInput } from "../../../actions/planner_switch.ts";
19 import { pauseSentence, pausedUntil } from "../../../core/planner_pause.ts";
1820 import { growthCounts } from "../../../core/growth.ts";
1921 import { sealedScope } from "../../../core/sealed.ts";
2022 import { good, bad, repoArg, isAnswer, REPO_ARG, type Tool } from "../shared.ts";
2123
2224 export const tool: Tool = {
2325 name: "system",
24 doc: "the machine the forge runs on, now: CPU, load, memory, disk, network, processes, `largestDirs`: the five largest directories under the forge's data as {at, dirs: [{name, bytes}]} (null while first measured; at most once a minute), `stalls`: the last hour's main-thread stalls by route (`<route> (in flight)` when still running at the wake), or `job:<name>`, as {cause, ms, count}, `readings`: the last 20 minutes' worst loop lag as {at, ms, what} beside `barMs` (100) and `over`, and `readers`: who polls the telemetry and how fast, `{ kind: \"routes\" }`: the 10 slowest budgeted routes as {route, p95Ms, budgetMs, n, slowestPhase}, over budget first; a forge admin, or an agent granted `telemetry:read`. `{ kind: \"csp\" }`: the last 24 h of Content-Security-Policy violations browsers reported, `{ directive, n, newest }` per directive (`newest` the blocked host last counted), most first, counted per UTC hour from `since`, and `scriptErrors` `{ page, where, message, n, last }`, as the security page reads them; a forge admin only. `{ kind: \"footing\" }`: what the forge stands on (#11685), as /system's \"What the forge stands on\": `forgeNode`, and per piece `{ id, need, what, machine, seen, risk, ifDies, issues }` read from the live cluster, with `risks`, one line per piece not on the forge's machine; a forge admin only. `{ kind: \"offsite\" }`: the off-site backup lane (#11805), as /system's \"Off-site backup\" and the terminal's: `{ health, says, where, sealed, lastSuccess, newest, error, backupFailure: { cause, bytes, seconds, says } | null, drill: { at, verdict, from, offSite, reason } | null }`; a forge admin only. `{ kind: \"size\" }`: the database's size (#12010), as /system's \"Database size\": `{ fileBytes, walBytes, growth: { perDay, days, readings: [{day, bytes}] }, walk: { at, pageSize, freeBytes, tables: [{name, bytes, rows}], indexes: [{name, table, bytes}] } | null }`, ten of each, largest first, the walk at most an hour old (null while the first runs); a forge admin, or an agent granted `telemetry:read`. `{ kind: \"maintenance\" }`: one row per maintenance worker, 7 days, `{ name, found, acted, last }` (`last` null: not yet run); admin or `telemetry:read`. `{ kind: \"growth\", repo }`: {openIssues, openPulls, openedToday, closedToday, openedWeek, closedWeek}, as /next's line",
26 doc: "the machine the forge runs on, now: CPU, load, memory, disk, network, processes, `largestDirs`: the five largest directories under the forge's data as {at, dirs: [{name, bytes}]} (null while first measured; at most once a minute), `stalls`: the last hour's main-thread stalls by route (`<route> (in flight)` when still running at the wake), or `job:<name>`, as {cause, ms, count}, `readings`: the last 20 minutes' worst loop lag as {at, ms, what} beside `barMs` (100) and `over`, and `readers`: who polls the telemetry and how fast, `{ kind: \"routes\" }`: the 10 slowest budgeted routes as {route, p95Ms, budgetMs, n, slowestPhase}, over budget first; a forge admin, or an agent granted `telemetry:read`. `{ kind: \"csp\" }`: the last 24 h of Content-Security-Policy violations browsers reported, `{ directive, n, newest }` per directive (`newest` the blocked host last counted), most first, counted per UTC hour from `since`, and `scriptErrors` `{ page, where, message, n, last }`, as the security page reads them; a forge admin only. `{ kind: \"footing\" }`: what the forge stands on (#11685), as /system's \"What the forge stands on\": `forgeNode`, and per piece `{ id, need, what, machine, seen, risk, ifDies, issues }` read from the live cluster, with `risks`, one line per piece not on the forge's machine; a forge admin only. `{ kind: \"offsite\" }`: the off-site backup lane (#11805), as /system's \"Off-site backup\" and the terminal's: `{ health, says, where, sealed, lastSuccess, newest, error, backupFailure: { cause, bytes, seconds, says } | null, drill: { at, verdict, from, offSite, reason } | null }`; a forge admin only. `{ kind: \"size\" }`: the database's size (#12010), as /system's \"Database size\": `{ fileBytes, walBytes, growth: { perDay, days, readings: [{day, bytes}] }, walk: { at, pageSize, freeBytes, tables: [{name, bytes, rows}], indexes: [{name, table, bytes}] } | null }`, ten of each, largest first, the walk at most an hour old (null while the first runs); a forge admin, or an agent granted `telemetry:read`. `{ kind: \"maintenance\" }`: one row per maintenance worker, 7 days, `{ name, found, acted, last }` (`last` null: not yet run); admin or `telemetry:read`. `{ kind: \"growth\", repo }`: {openIssues, openPulls, openedToday, closedToday, openedWeek, closedWeek}, as /next's line; with `action` pause (`until`: UTC time within a year, else until switched on) or resume, the planner's switch: a preview, and `confirm:true` does it; the repository's owner, never an agent",
2527 description:
2628 "The forge machine now: CPU, memory, disk, network. Admin or telemetry:read; `kind: csp`: 24 h of CSP violations (admin).",
27 inputSchema: { type: "object", properties: { kind: { type: "string", enum: ["csp", "routes", "footing", "offsite", "size", "maintenance", "growth"] }, repo: REPO_ARG } },
28 writes: false,
29 inputSchema: { type: "object", properties: { kind: { type: "string", enum: ["csp", "routes", "footing", "offsite", "size", "maintenance", "growth"] }, repo: REPO_ARG, action: { type: "string", enum: ["pause", "resume"] }, until: { type: "string" }, confirm: { type: "boolean" } } },
30 writes: true,
31 readsWhen: (args) => args["action"] === undefined || args["confirm"] !== true,
2932 async run(ctx, user, args) {
3033 if (args["kind"] !== undefined) {
3134 if (args["kind"] === "routes") {
@@ -37,6 +40,26 @@ export const tool: Tool = {
3740 if (args["kind"] === "growth") {
3841 const repo = repoArg(ctx, user, args);
3942 if (isAnswer(repo)) return repo;
43 if (args["action"] !== undefined) {
44 const a = args["action"];
45 if (a !== "pause" && a !== "resume") return bad("invalid", "action is pause or resume");
46 if (args["confirm"] !== undefined && typeof args["confirm"] !== "boolean") return bad("invalid", "confirm is true or false");
47 if (args["until"] !== undefined && (typeof args["until"] !== "string" || a === "resume")) return bad("invalid", "until is a UTC time, for pause");
48 if (!maySwitch(ctx.app, user, repo)) return bad("forbidden", SWITCH_REFUSED.forbidden);
49 const input: SwitchInput =

Box 1 (the preview answers what it would do): for resume this returns pauseSentence(null), which is "The planner is on." That reads as the current state, not as the act. When the planner is paused, the preview of a resume still says "on" and then "Nothing changed", which is wrong and confusing. Say it plainly, for example "The planner would be switched on.", and say what is paused now if it is. Add a test that asserts the resume preview's sentence; today it only asserts done:false.

50 a === "resume" ? { mode: "on" } : typeof args["until"] === "string" ? { mode: "until", at: utcAt(args["until"]) } : { mode: "owner" };
51 if (input.mode === "until" && !validUntil(input.at)) return bad("invalid", SWITCH_REFUSED.invalid);
52 if (args["confirm"] !== true) {
53 const now = pausedUntil(ctx.app.db, repo.id, new Date());
54 const was = now === null ? "The planner is on now." : `${pauseSentence(now)} (now)`;
55 const would =
56 input.mode === "on" ? "The planner would be switched on." : input.mode === "owner" ? "The planner would pause until you switch it on." : `The planner would pause until ${input.at}.`;
57 return good({ done: false, says: `${would} ${was} Nothing changed; call again with confirm:true to do it.` });
58 }
59 const done = setPlannerSwitch(ctx.app, user, repo, input);
60 if (!done.ok) return bad(done.error, SWITCH_REFUSED[done.error]);
61 return good({ done: true, until: done.value, says: pauseSentence(done.value) });
62 }
4063 return good(growthCounts(ctx.app.db, repo, new Date(), sealedScope(ctx.app.db, repo, user)));
4164 }
4265 if (args["kind"] === "size") {
@@ -75,7 +98,8 @@ export const tool: Tool = {
7598 const stalls = stallHour(liveOf(ctx.app).loopWatch.tally(performance.now()))
7699 .slice(0, TOP_ROUTES)
77100 .map((r) => ({ cause: r.route, ms: Math.round(r.ms), count: r.count }));
78 // The same 20 minutes /system draws (#11220); `what` is null when no stall past 200 ms was named.
101 // The same 20 minutes /system draws (#11220); `what` is null when no stall past 200 ms was
102 // named.
79103 const rows = liveOf(ctx.app).lagMinutes.readings();
80104 const readings = rows.map((r) => ({ at: new Date(r.at).toISOString(), ms: Math.round(r.ms * 10) / 10, what: r.what }));
81105 // At most 0.8 s on the walk (#11800); the last measurement, or null, when it is slower.
src/web/pages/queue.ts +2 −2
@@ -5,7 +5,7 @@
55 * issues) is left out of every number and title (`core/sealed.ts`).
66 */
77
8 import { setCeiling, setPlannerSwitch, switchInput } from "../../actions/planner_switch.ts";
8 import { setCeiling, setPlannerSwitch, SWITCH_REFUSED, switchInput } from "../../actions/planner_switch.ts";
99 import { growth, oldest, WHO, type Growth } from "../../core/growth.ts";
1010 import { ceilingHold, CEILING_HELD_NOTE, CEILING_REASON, openCeiling, PAUSE_STOPS, pauseSentence, pausedUntil } from "../../core/planner_pause.ts";
1111 import { canAdmin, type Repo } from "../../core/repos.ts";
@@ -125,7 +125,7 @@ export async function queueSwitch(ctx: Ctx): Promise<Response> {
125125 if (input === undefined) return flashTo(ctx, back, { tone: "danger", message: "Choose on, a time, the weekly reset or until you switch it on." });
126126 const done = setPlannerSwitch(ctx.app, ctx.auth.user, repo, input);
127127 if (!done.ok)
128 return flashTo(ctx, back, { tone: "danger", message: done.error === "invalid" ? "Pick a time in the future, within a year." : "Only the owner switches the planner." });
128 return flashTo(ctx, back, { tone: "danger", message: SWITCH_REFUSED[done.error] });
129129 return flashTo(ctx, back, { message: pauseSentence(done.value) });
130130 }
131131
test/conversation-confirm.test.ts +3 −2
@@ -118,14 +118,15 @@ describe("the one list of what asks first", () => {
118118 });
119119
120120 // Writes that do not ask first, on purpose: each reads, plans, or only changes the caller's own
121 // settings and can be put back. A new `writes: true` tool is on neither list until someone decides.
121 // settings and can be put back (`system` previews and does only on its own `confirm:true`). A new
122 // `writes: true` tool is on neither list until someone decides.
122123 const NOT_ASKED = new Set([
123124 "access", "account_requests", "account_verify", "app_members", "app_notes", "asks_act", "asks_decide", "asks_proposal", "asks_undecide", "atlas",
124125 "asks", "assign", "attach_look", "bet", "board_pins", "board_write", "branches", "capacity", "valves", "cloud_accounts", "close", "confirm_wait",
125126 "crew", "decisions_by", "desk", "detach", "economics", "edit", "email_verify", "estimate", "feed_chips", "feed_dismiss", "feed_like", "flag_set", "flag_winner",
126127 "follow_mode", "forge", "fork", "front_page", "hold", "issue_teams", "keep_plan", "knobs", "labels", "lift", "limb", "maintenance", "make_it_yours", "map", "merge", "new_app",
127128 "next_up", "week", "notify", "open_pull", "org_create", "origin_apps", "pins", "plan", "profile", "propose_to_parent_forge", "repo_labels", "reports",
128 "repo", "restore_drill", "review", "say", "signup", "snapshot_now", "spend", "steer", "sync", "take_back", "take_updates",
129 "repo", "restore_drill", "review", "say", "signup", "snapshot_now", "spend", "steer", "sync", "system", "take_back", "take_updates",
129130 "teams", "tell", "threads", "trail", "upstream", "variant", "wait_for", "watch", "whoami_can", "write_file",
130131 ]);
131132
test/growth.test.ts +97 −5
@@ -1,7 +1,8 @@
11 /**
22 * The growth panel and the planner's switch (#11604): the counts match the rows for a fixture with
3 * owner, person, planner, builder and watcher authors; pausing stops the planner's issues, plans and
4 * runs while a builder's queued run still starts; a timed pause lifts itself; the API and the page answer.
3 * owner, person, planner, builder and watcher authors; pausing stops the planner's issues, plans
4 * and runs while a builder's queued run still starts; a timed pause lifts itself; the API and the
5 * page answer.
56 */
67 import { afterAll, beforeAll, describe, expect, test } from "bun:test";
78 import { mkdtemp, rm } from "node:fs/promises";
@@ -102,14 +103,16 @@ describe("growth and the planner switch", () => {
102103 test("the counts match the rows, by day and by author", () => {
103104 app.db.query("DELETE FROM issue WHERE repo_id = ?1").run(repo.id);
104105 const base = 0;
105 // today: 2 planner + 1 owner opened, 1 closed; yesterday: 1 person + 1 builder + 1 watcher opened, 2 closed
106 // today: 2 planner + 1 owner opened, 1 closed; yesterday: 1 person + 1 builder + 1 watcher
107 // opened, 2 closed
106108 insert(planner, "issue", at(0), at(0));
107109 insert(planner, "issue", at(0), null);
108110 insert(owner, "issue", at(0), null);
109111 insert(person, "issue", at(1), null);
110112 insert(builder, "issue", at(1), at(1));
111113 insert(watcher, "issue", at(1), at(1));
112 // an old one is outside the window; pulls: 2 opened a day ago, one landed today, one closed unmerged
114 // an old one is outside the window; pulls: 2 opened a day ago, one landed today, one closed
115 // unmerged
113116 insert(planner, "issue", at(40), null);
114117 insert(builder, "pull", at(1), at(0), true);
115118 insert(builder, "pull", at(1), at(0), false);
@@ -247,7 +250,8 @@ describe("growth and the planner switch", () => {
247250 const plan = original(`EXPLAIN QUERY PLAN ${q}`).all(...Array.from({ length: n }, () => "x")).map((r) => (r as { detail: string }).detail);
248251 expect(plan.filter((d) => /SCAN (i|issue)\b/.test(d) && !/USING/.test(d))).toEqual([]);
249252 }
250 // Opened-per-day walks the new index; closed-per-day walks the repository's own rows by an existing one.
253 // Opened-per-day walks the new index; closed-per-day walks the repository's own rows by an
254 // existing one.
251255 const plans = windowed.map((q) => {
252256 const n = Math.max(...[...q.matchAll(/\?(\d+)/g)].map((m) => Number(m[1])));
253257 return original(`EXPLAIN QUERY PLAN ${q}`).all(...Array.from({ length: n }, () => "x")).map((r) => (r as { detail: string }).detail).join("\n");
@@ -323,4 +327,92 @@ describe("growth and the planner switch", () => {
323327 expect(pauseSentence("9999-12-31T00:00:00.000Z")).toContain("until you switch it on");
324328 expect(pauseSentence("2026-11-20T09:00:00.000Z")).toBe("The planner is paused until 2026-11-20 09:00 UTC.");
325329 });
330
331 describe("over MCP", () => {
332 const mcp = async (user: User, args: Record<string, unknown>) => {
333 const token = createToken(app.db, user.id, "rw", "rw").token;
334 const res = await fetch(`${servers.url}/mcp`, {
335 method: "POST",
336 headers: { "content-type": "application/json", accept: "application/json, text/event-stream", authorization: `Bearer ${token}` },
337 body: JSON.stringify({ jsonrpc: "2.0", id: 1, method: "tools/call", params: { name: "system", arguments: { kind: "growth", repo: "alice/shop", ...args } } }),
338 });
339 const body: any = await res.json();
340 const text: string = body.result.content[0].text;
341 return body.result.isError === true ? { error: text } : { value: JSON.parse(text) };
342 };
343 const events = (kind: string) => (app.db.query("SELECT COUNT(*) AS n FROM event WHERE kind = ?1").get(kind) as { n: number }).n;
344 const soon = () => new Date(Date.now() + 3 * 3_600_000).toISOString();
345
346 test("without confirm nothing changes and the answer says what would happen", async () => {
347 const r: any = await mcp(owner, { action: "pause", until: soon() });
348 expect(r.value.done).toBe(false);
349 expect(r.value.says).toContain("would pause until");
350 expect(pausedUntil(app.db, repo.id, new Date())).toBeNull();
351 const back: any = await mcp(owner, { action: "resume" });
outdated

Missing tests, each for behaviour this pull adds: (a) a non-admin or agent asking for a preview without confirm is refused, so the preview does not leak the switch to them; (b) until together with resume is refused; (c) a non-boolean confirm is refused; (d) an until without a zone goes through utcAt as UTC. Each would fail if its check were removed.

352 expect(back.value.done).toBe(false);
353 expect(back.value.says).toBe("The planner would be switched on. The planner is on now. Nothing changed; call again with confirm:true to do it.");
354 });
355
356 test("the resume preview names what is paused now", async () => {
357 const until = soon();
358 await mcp(owner, { action: "pause", until, confirm: true });
359 const r: any = await mcp(owner, { action: "resume" });
360 expect(r.value.says).toContain("The planner would be switched on. The planner is paused until");
361 expect(pausedUntil(app.db, repo.id, new Date())).toBe(until);
362 await mcp(owner, { action: "resume", confirm: true });
363 });
364
365 test("a preview is refused to an agent and to a non-admin", async () => {
366 for (const u of [planner, person]) {
367 const r: any = await mcp(u, { action: "pause" });
368 expect(r.error).toContain("Only the owner switches the planner.");
369 }
370 });
371
372 test("until with resume, and a confirm that is not a boolean, are refused", async () => {
373 expect(((await mcp(owner, { action: "resume", until: soon() })) as any).error).toContain("until is a UTC time, for pause");
374 expect(((await mcp(owner, { action: "pause", confirm: "yes" })) as any).error).toContain("confirm is true or false");
375 expect(((await mcp(owner, { action: "stop" })) as any).error).toContain("pause or resume");
376 expect(pausedUntil(app.db, repo.id, new Date())).toBeNull();
377 });
378
379 test("an until without a zone is UTC", async () => {
380 const t = new Date(Date.now() + 5 * 3_600_000);
381 const bare = t.toISOString().slice(0, 16);
382 const r: any = await mcp(owner, { action: "pause", until: bare, confirm: true });
383 expect(r.value.until).toBe(`${bare}:00.000Z`);
384 await mcp(owner, { action: "resume", confirm: true });
385 });
386
387 test("an agent is refused with the page's sentence", async () => {
388 const r: any = await mcp(planner, { action: "pause", confirm: true });
389 expect(r.error).toContain("Only the owner switches the planner.");
390 expect(pausedUntil(app.db, repo.id, new Date())).toBeNull();
391 });
392
393 test("a non-admin is refused with the page's sentence", async () => {
394 const r: any = await mcp(person, { action: "pause", confirm: true });
395 expect(r.error).toContain("Only the owner switches the planner.");
396 expect(pausedUntil(app.db, repo.id, new Date())).toBeNull();
397 });
398
399 test("a bad time is refused", async () => {
400 const r: any = await mcp(owner, { action: "pause", until: "2001-01-01T00:00:00Z", confirm: true });
401 expect(r.error).toContain("within a year");
402 });
403
404 test("confirm pauses and resumes, and records both", async () => {
405 const paused0 = events("planner.paused");
406 const resumed0 = events("planner.resumed");
407 const until = soon();
408 const p: any = await mcp(owner, { action: "pause", until, confirm: true });
409 expect(p.value.done).toBe(true);
410 expect(pausedUntil(app.db, repo.id, new Date())).toBe(until);
411 expect(events("planner.paused")).toBe(paused0 + 1);
412 const r: any = await mcp(owner, { action: "resume", confirm: true });
413 expect(r.value.until).toBeNull();
414 expect(pausedUntil(app.db, repo.id, new Date())).toBeNull();
415 expect(events("planner.resumed")).toBe(resumed0 + 1);
416 });
417 });
326418 });
test/mcp-write-scope.test.ts +5 −1
@@ -44,10 +44,14 @@ const ADMIN_ARGS: Record<string, Record<string, unknown>> = {
4444 rollback: { sha: "a".repeat(40), dryRun: false },
4545 };
4646
47 /** Valid arguments for a tool whose write is one call among reads and plans (`readsWhen`): the generic arguments would only read. */
47 /**
48 * Valid arguments for a tool whose write is one call among reads and plans (`readsWhen`): the
49 * generic arguments would only read.
50 */
4851 const WRITE_ARGS: Record<string, Record<string, unknown>> = {
4952 flow: { kind: "drift", action: "update", repo: "alice/game", pull: 1 },
5053 repo: { repo: "alice/game", action: "open", chapter: "v1", confirm: true },
54 system: { kind: "growth", repo: "alice/game", action: "pause", confirm: true },
5155 };
5256
5357 /** What `visible()` answers for a tool the token's scope does not open. */

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs