Public: anyone can read this; the crew can change it.
The contributor's walk of Talk's tools makes the calls that can run, not a thousand refused ones #17806
Merged 8h 28m ago, live in production
contributors-walk → main 0 commits
1 file
changed +16
−3
test/invite-contributors.test.ts +16 −3
| @@ -50,6 +50,8 @@ import { queueAgentRun } from "../src/crew/dispatch.ts"; | ||
| 50 | 50 | import { getAgentByName } from "../src/core/agents.ts"; |
| 51 | 51 | import { forgetWeek } from "../src/crew/week_read.ts"; |
| 52 | 52 | import { TALK_TOOLS } from "../src/http/mcp/catalog.ts"; |
| 53 | import { badArgument } from "../src/http/mcp/shared.ts"; | |
| 54 | import { TOOLS } from "../src/http/mcp/tools.ts"; | |
| 53 | 55 | import { readRunLog } from "../src/runs/log.ts"; |
| 54 | 56 | import { |
| 55 | 57 | startStandInCrew, |
| @@ -92,11 +94,12 @@ const mcp = async ( | ||
| 92 | 94 | who: User, |
| 93 | 95 | name: string, |
| 94 | 96 | args: Record<string, unknown>, |
| 97 | token: string = createToken(standIn.app.db, who.id, "t", "rw").token, | |
| 95 | 98 | ): Promise<{ text: string; error: boolean }> => { |
| 96 | 99 | const res = await fetch(`${url}/mcp`, { |
| 97 | 100 | method: "POST", |
| 98 | 101 | headers: { |
| 99 | authorization: `Bearer ${createToken(standIn.app.db, who.id, "t", "rw").token}`, | |
| 102 | authorization: `Bearer ${token}`, | |
| 100 | 103 | "content-type": "application/json", |
| 101 | 104 | accept: "application/json, text/event-stream", |
| 102 | 105 | }, |
| @@ -257,12 +260,22 @@ describe("a contributor: reads, enters, directs; nothing outside the repository" | ||
| 257 | 260 | { user: "alice" }, |
| 258 | 261 | { username: "alice" }, |
| 259 | 262 | ]; |
| 263 | // A call that does not fit a tool's schema is refused before the tool runs, in words made of the | |
| 264 | // schema and the call's own arguments: one such call a tool is enough. Every call that fits is | |
| 265 | // made. A tool the list does not hold (`report`, `start`) is called with every shape. | |
| 266 | const calls = (name: string): Record<string, unknown>[] => { | |
| 267 | const tool = TOOLS.find((t) => t.name === name); | |
| 268 | if (tool === undefined) return shapes; | |
| 269 | const fits = (args: Record<string, unknown>) => badArgument(tool.inputSchema, args) === undefined; | |
| 270 | return [...shapes.filter(fits), ...shapes.filter((s) => !fits(s)).slice(0, 1)]; | |
| 271 | }; | |
| 260 | 272 | // The markers each walk finds, as `tool args: marker`. |
| 261 | 273 | const walk = async (who: User): Promise<string[]> => { |
| 262 | 274 | const found: string[] = []; |
| 275 | const { token } = createToken(standIn.app.db, who.id, "walk", "rw"); | |
| 263 | 276 | for (const tool of TALK_TOOLS) |
| 264 | for (const args of shapes) { | |
| 265 | const got = await mcp(who, tool, args); | |
| 277 | for (const args of calls(tool)) { | |
| 278 | const got = await mcp(who, tool, args, token); | |
| 266 | 279 | for (const marker of [VAULT, SUB]) if (got.text.includes(marker)) found.push(`${tool} ${JSON.stringify(args)}: ${marker}`); |
| 267 | 280 | } |
| 268 | 281 | return found; |
new above
offline