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

Merged opened this

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

Merged

talk/reads-not-held → main 0 commits

  • Merged. talk/reads-not-held was merged into main as 0bd0ce7.

Review

Sign in to review this change.
9 files changed +173 −1
src/crew/conversation_ask.ts +6 −1
@@ -159,7 +159,12 @@ export const ASKED_AS: Readonly<Record<string, Form>> = {
159159 if (action === "resume_schedule") return `Resume ${own(repo(a))} schedule ${name}`;
160160 if (action === "cancel_job") return `Cancel ${own(repo(a))} job ${name}`;
161161 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}`;
163168 },
164169 // Release and rollback.
165170 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 = {
2121 required: ["repo", "action"],
2222 },
2323 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",
2426 async run(ctx, user, args) {
2527 const repo = repoArg(ctx, user, args);
2628 if (isAnswer(repo)) return repo;
src/http/mcp/tools/hooks.ts +2
@@ -38,6 +38,8 @@ export const tool: Tool = {
3838 required: ["repo", "action"],
3939 },
4040 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",
4143 tier: "delete",
4244 deletes: (args) => args["action"] === "remove",
4345 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 = {
1616 required: ["action"],
1717 },
1818 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",
1921 run(ctx, user, args) {
2022 if (!mayBoards(user)) return bad("forbidden", "invites are a forge admin's");
2123 if (!scopeAllows(ctx.auth.scope ?? "ro", "admin"))
src/http/mcp/tools/org_teams.ts +3
@@ -24,6 +24,9 @@ export const tool: Tool = {
2424 required: ["org", "team"],
2525 },
2626 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),
2730 tier: "delete",
2831 deletes: (args) => args["action"] === "remove",
2932 where: "on the team's page (/<org>/-/teams/<team>)",
src/http/mcp/tools/origins.ts +3
@@ -21,6 +21,9 @@ export const tool: Tool = {
2121 required: ["action"],
2222 },
2323 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),
2427 readsWithout: ["id", "hosts"],
2528 async run(ctx, user, args) {
2629 const action = args["action"];
src/http/mcp/tools/pins.ts +2
@@ -18,6 +18,8 @@ export const tool: Tool = {
1818 },
1919 },
2020 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",
2123 readsWithout: "repo",
2224 run(ctx, user, args) {
2325 const action = args["action"] ?? "list";
src/http/mcp/tools/prompts.ts +2
@@ -19,6 +19,8 @@ export const tool: Tool = {
1919 required: ["repo", "action"],
2020 },
2121 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",
2224 tier: "delete",
2325 deletes: (args) => args["action"] === "remove",
2426 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 });

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs