Public: anyone can read this; the crew can change it.
A read is never held for a Do it, and a held write is said as itself: app_deploy's jobs list read as "Publish … again" #16321
Check · Review · Land · Live done — Landed and live in production.
talk/reads-not-held → main 0 commits
9 files
changed +173
−1
src/crew/conversation_ask.ts +6 −1
| @@ -159,7 +159,12 @@ export const ASKED_AS: Readonly<Record<string, Form>> = { | ||
| 159 | 159 | if (action === "resume_schedule") return `Resume ${own(repo(a))} schedule ${name}`; |
| 160 | 160 | if (action === "cancel_job") return `Cancel ${own(repo(a))} job ${name}`; |
| 161 | 161 | if (action === "retry_job") return `Try ${own(repo(a))} job ${name} again`; |
| 162 | return `Publish ${repo(a)} to ${env} again`; | |
| 162 | if (action === "pull") return `Run ${own(repo(a))} adapter pull now`; | |
| 163 | if (action === "schedules") return `List ${own(repo(a))} schedules`; | |
| 164 | if (action === "jobs") return `List ${own(repo(a))} jobs`; | |
| 165 | if (action === "redeploy") return `Publish ${repo(a)} to ${env} again`; | |
| 166 | // An action this does not know is named as it is, never said as another. | |
| 167 | return `${capital(action.replaceAll("_", " ") || "act")} on ${repo(a)} in ${env}`; | |
| 163 | 168 | }, |
| 164 | 169 | // Release and rollback. |
| 165 | 170 | rollback: (a) => `Roll the forge back to ${val(a, "sha") === "" ? "the last kept release" : `release ${val(a, "sha").slice(0, 12)}`}`, |
src/http/mcp/tools/app_deploy.ts +2
| @@ -21,6 +21,8 @@ export const tool: Tool = { | ||
| 21 | 21 | required: ["repo", "action"], |
| 22 | 22 | }, |
| 23 | 23 | writes: true, |
| 24 | // Its read (listing schedules or jobs) is never held for a Do it: only its writes are. | |
| 25 | heldNotWhen: (args) => args["action"] === "schedules" || args["action"] === "jobs", | |
| 24 | 26 | async run(ctx, user, args) { |
| 25 | 27 | const repo = repoArg(ctx, user, args); |
| 26 | 28 | if (isAnswer(repo)) return repo; |
src/http/mcp/tools/hooks.ts +2
| @@ -38,6 +38,8 @@ export const tool: Tool = { | ||
| 38 | 38 | required: ["repo", "action"], |
| 39 | 39 | }, |
| 40 | 40 | writes: true, |
| 41 | // Its read (listing hooks or their deliveries) is never held for a Do it: only its writes are. | |
| 42 | heldNotWhen: (args) => args["action"] === "list" || args["action"] === "deliveries", | |
| 41 | 43 | tier: "delete", |
| 42 | 44 | deletes: (args) => args["action"] === "remove", |
| 43 | 45 | where: "in the repository's Webhooks settings (/<owner>/<name>/settings/hooks)", |
src/http/mcp/tools/invites.ts +2
| @@ -16,6 +16,8 @@ export const tool: Tool = { | ||
| 16 | 16 | required: ["action"], |
| 17 | 17 | }, |
| 18 | 18 | writes: true, |
| 19 | // Its read (listing invite links) is never held for a Do it: only its writes are. | |
| 20 | heldNotWhen: (args) => args["action"] === "list", | |
| 19 | 21 | run(ctx, user, args) { |
| 20 | 22 | if (!mayBoards(user)) return bad("forbidden", "invites are a forge admin's"); |
| 21 | 23 | if (!scopeAllows(ctx.auth.scope ?? "ro", "admin")) |
src/http/mcp/tools/org_teams.ts +3
| @@ -24,6 +24,9 @@ export const tool: Tool = { | ||
| 24 | 24 | required: ["org", "team"], |
| 25 | 25 | }, |
| 26 | 26 | writes: true, |
| 27 | // Its read (listing a team's members, metrics or waiting pulls) is never held for a Do it: only | |
| 28 | // its writes are. | |
| 29 | heldNotWhen: (args) => args["action"] === "members" || args["action"] === "metrics" || (args["action"] === undefined && args["waiting"] === true), | |
| 27 | 30 | tier: "delete", |
| 28 | 31 | deletes: (args) => args["action"] === "remove", |
| 29 | 32 | where: "on the team's page (/<org>/-/teams/<team>)", |
src/http/mcp/tools/origins.ts +3
| @@ -21,6 +21,9 @@ export const tool: Tool = { | ||
| 21 | 21 | required: ["action"], |
| 22 | 22 | }, |
| 23 | 23 | writes: true, |
| 24 | // Its reads (the origins, what one holds, its inventory, the hosts with none given) are never | |
| 25 | // held for a Do it: only a sync and a hosts change are. | |
| 26 | heldNotWhen: (args) => args["action"] === "list" || args["action"] === "repos" || args["action"] === "inventory" || (args["action"] === "hosts" && args["hosts"] === undefined), | |
| 24 | 27 | readsWithout: ["id", "hosts"], |
| 25 | 28 | async run(ctx, user, args) { |
| 26 | 29 | const action = args["action"]; |
src/http/mcp/tools/pins.ts +2
| @@ -18,6 +18,8 @@ export const tool: Tool = { | ||
| 18 | 18 | }, |
| 19 | 19 | }, |
| 20 | 20 | writes: true, |
| 21 | // Its read (listing pins) is never held for a Do it: only its writes are. | |
| 22 | heldNotWhen: (args) => args["action"] === undefined || args["action"] === "list", | |
| 21 | 23 | readsWithout: "repo", |
| 22 | 24 | run(ctx, user, args) { |
| 23 | 25 | const action = args["action"] ?? "list"; |
src/http/mcp/tools/prompts.ts +2
| @@ -19,6 +19,8 @@ export const tool: Tool = { | ||
| 19 | 19 | required: ["repo", "action"], |
| 20 | 20 | }, |
| 21 | 21 | writes: true, |
| 22 | // Its read (listing prompt sources) is never held for a Do it: only its writes are. | |
| 23 | heldNotWhen: (args) => args["action"] === "list", | |
| 22 | 24 | tier: "delete", |
| 23 | 25 | deletes: (args) => args["action"] === "remove", |
| 24 | 26 | where: "in the repository's Prompts settings (/<owner>/<name>/settings/prompts)", |
test/mixed-actions-held.test.ts added +151
| @@ -0,0 +1,151 @@ | ||
| 1 | /** | |
| 2 | * A tool whose actions mix reads and writes (#16213's morning chat: `app_deploy { action: "jobs" }` | |
| 3 | * was held as "Publish trevato/morning-paper to production again."): a read is never held for a Do | |
| 4 | * it, and the sentence a held write is confirmed with says that write, never another action's. | |
| 5 | * Every write tool with a reading action is in `MIXED`, so a new one is covered or fails here. | |
| 6 | */ | |
| 7 | import { describe, expect, test } from "bun:test"; | |
| 8 | import { confirmSentence, ASKED_AS } from "../src/crew/conversation_ask.ts"; | |
| 9 | import { loadMcp } from "../src/http/mcp/load.ts"; | |
| 10 | import { plansOnly } from "../src/http/mcp/shared.ts"; | |
| 11 | ||
| 12 | /** The arguments a call of each reading action takes, as an agent would send them. */ | |
| 13 | const MIXED: Readonly< | |
| 14 | Record<string, { key: string; reads: readonly Record<string, unknown>[] }> | |
| 15 | > = { | |
| 16 | app_deploy: { | |
| 17 | key: "action", | |
| 18 | reads: [ | |
| 19 | { repo: "o/r", action: "schedules" }, | |
| 20 | { repo: "o/r", action: "jobs" }, | |
| 21 | ], | |
| 22 | }, | |
| 23 | hooks: { | |
| 24 | key: "action", | |
| 25 | reads: [ | |
| 26 | { repo: "o/r", action: "list" }, | |
| 27 | { repo: "o/r", action: "deliveries", id: "h1" }, | |
| 28 | ], | |
| 29 | }, | |
| 30 | invites: { key: "action", reads: [{ action: "list" }] }, | |
| 31 | org_teams: { | |
| 32 | key: "action", | |
| 33 | reads: [ | |
| 34 | { org: "o", team: "t", action: "members" }, | |
| 35 | { org: "o", team: "t", action: "metrics" }, | |
| 36 | { org: "o", team: "t", waiting: true }, | |
| 37 | ], | |
| 38 | }, | |
| 39 | prompts: { key: "action", reads: [{ repo: "o/r", action: "list" }] }, | |
| 40 | pins: { key: "action", reads: [{}, { action: "list" }] }, | |
| 41 | say: { | |
| 42 | key: "action", | |
| 43 | reads: ["list", "find", "download", "build_state", "build_diff"].map( | |
| 44 | (action) => ({ action, text: "x" }), | |
| 45 | ), | |
| 46 | }, | |
| 47 | maintenance: { key: "action", reads: [{ action: "status" }] }, | |
| 48 | restore_drill: { key: "action", reads: [{ action: "status" }] }, | |
| 49 | egress_grants: { key: "op", reads: [{ repo: "o/r", op: "list" }] }, | |
| 50 | pinned_forge: { key: "verb", reads: [{ verb: "list" }] }, | |
| 51 | proposal_tokens: { key: "verb", reads: [{ verb: "list" }] }, | |
| 52 | app_env: { key: "action", reads: [{ repo: "o/r", action: "list" }] }, | |
| 53 | drop: { key: "action", reads: [{ repo: "o/r", action: "list" }] }, | |
| 54 | origins: { | |
| 55 | key: "action", | |
| 56 | reads: ["list", "repos", "inventory"] | |
| 57 | .map((action) => ({ action, id: "o1" })) | |
| 58 | .concat([{ action: "hosts", id: "o1" }]), | |
| 59 | }, | |
| 60 | sessions: { key: "action", reads: [{ action: "list" }] }, | |
| 61 | ssh_keys: { key: "action", reads: [{ action: "list" }] }, | |
| 62 | }; | |
| 63 | ||
| 64 | /** Action words that only read. */ | |
| 65 | const READING = | |
| 66 | /^(list|status|schedules|jobs|members|metrics|deliveries|find|download|build_state|build_diff)$/; | |
| 67 | ||
| 68 | describe("a tool whose actions mix reads and writes", async () => { | |
| 69 | const { TOOLS } = await loadMcp(); | |
| 70 | const byName = new Map(TOOLS.map((t) => [t.name, t])); | |
| 71 | ||
| 72 | test("every write tool with a reading action is in the table", () => { | |
| 73 | const mixed = TOOLS.filter((t) => t.writes).flatMap((t) => | |
| 74 | ["action", "op", "verb"].flatMap((key) => { | |
| 75 | const values = | |
| 76 | ( | |
| 77 | t.inputSchema as { | |
| 78 | properties?: Record<string, { enum?: unknown[] }>; | |
| 79 | } | |
| 80 | ).properties?.[key]?.enum ?? []; | |
| 81 | return values.some((v) => typeof v === "string" && READING.test(v)) | |
| 82 | ? [t.name] | |
| 83 | : []; | |
| 84 | }), | |
| 85 | ); | |
| 86 | for (const name of mixed) | |
| 87 | expect(Object.keys(MIXED), `${name} mixes reads and writes`).toContain( | |
| 88 | name, | |
| 89 | ); | |
| 90 | }); | |
| 91 | ||
| 92 | test("a read is never held: it plans only, or the tool says the agent need not ask", () => { | |
| 93 | for (const [name, { reads }] of Object.entries(MIXED)) { | |
| 94 | const tool = byName.get(name)!; | |
| 95 | expect(tool, name).toBeDefined(); | |
| 96 | for (const args of reads) | |
| 97 | expect( | |
| 98 | plansOnly(tool, args) || tool.heldNotWhen?.(args) === true, | |
| 99 | `${name} ${JSON.stringify(args)}`, | |
| 100 | ).toBe(true); | |
| 101 | } | |
| 102 | }); | |
| 103 | ||
| 104 | test("each write of a tool with its own sentences is said as itself, never as another action", () => { | |
| 105 | for (const [name, { key, reads }] of Object.entries(MIXED)) { | |
| 106 | if (ASKED_AS[name] === undefined) continue; | |
| 107 | const tool = byName.get(name)!; | |
| 108 | // The arguments its reads are called with, as an agent would send its writes too. | |
| 109 | const base = { name: "n", user: "u", id: "h1", ...reads[0] }; | |
| 110 | // The writes, by the tool's own rule: a call it reads (or never holds) has no sentence to | |
| 111 | // give. | |
| 112 | const values = ( | |
| 113 | ( | |
| 114 | tool.inputSchema as { | |
| 115 | properties: Record<string, { enum?: string[] }>; | |
| 116 | } | |
| 117 | ).properties[key]?.enum ?? [] | |
| 118 | ).filter((v) => { | |
| 119 | const args = { ...base, [key]: v }; | |
| 120 | return !plansOnly(tool, args) && tool.heldNotWhen?.(args) !== true; | |
| 121 | }); | |
| 122 | const said = values.map((v) => | |
| 123 | confirmSentence(name, { ...base, [key]: v }, tool.description ?? ""), | |
| 124 | ); | |
| 125 | expect(new Set(said).size, `${name}: ${JSON.stringify(said)}`).toBe( | |
| 126 | said.length, | |
| 127 | ); | |
| 128 | } | |
| 129 | }); | |
| 130 | ||
| 131 | test("app_deploy says each action as itself: a jobs read is no publish, and an adapter pull is a pull", () => { | |
| 132 | const say = (action: string) => | |
| 133 | confirmSentence("app_deploy", { repo: "alice/paper", action }); | |
| 134 | expect(say("redeploy")).toBe("Publish alice/paper to production again."); | |
| 135 | expect(say("jobs")).toBe("List alice/paper's jobs."); | |
| 136 | expect(say("schedules")).toBe("List alice/paper's schedules."); | |
| 137 | expect(say("pull")).toBe("Run alice/paper's adapter pull now."); | |
| 138 | for (const action of [ | |
| 139 | "stop", | |
| 140 | "pull", | |
| 141 | "jobs", | |
| 142 | "schedules", | |
| 143 | "cancel_job", | |
| 144 | "retry_job", | |
| 145 | "run_schedule", | |
| 146 | "pause_schedule", | |
| 147 | "resume_schedule", | |
| 148 | ]) | |
| 149 | expect(say(action), action).not.toContain("Publish"); | |
| 150 | }); | |
| 151 | }); |
new above
offline