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

opened this

Merged 8h 28m ago, live in production

contributors-walk → main 0 commits

  • Merged. contributors-walk was merged into main as 791b76f.

Review

Sign in to review this change.
1 file changed +16 −3
test/invite-contributors.test.ts +16 −3
@@ -50,6 +50,8 @@ import { queueAgentRun } from "../src/crew/dispatch.ts";
5050 import { getAgentByName } from "../src/core/agents.ts";
5151 import { forgetWeek } from "../src/crew/week_read.ts";
5252 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";
5355 import { readRunLog } from "../src/runs/log.ts";
5456 import {
5557 startStandInCrew,
@@ -92,11 +94,12 @@ const mcp = async (
9294 who: User,
9395 name: string,
9496 args: Record<string, unknown>,
97 token: string = createToken(standIn.app.db, who.id, "t", "rw").token,
9598 ): Promise<{ text: string; error: boolean }> => {
9699 const res = await fetch(`${url}/mcp`, {
97100 method: "POST",
98101 headers: {
99 authorization: `Bearer ${createToken(standIn.app.db, who.id, "t", "rw").token}`,
102 authorization: `Bearer ${token}`,
100103 "content-type": "application/json",
101104 accept: "application/json, text/event-stream",
102105 },
@@ -257,12 +260,22 @@ describe("a contributor: reads, enters, directs; nothing outside the repository"
257260 { user: "alice" },
258261 { username: "alice" },
259262 ];
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 };
260272 // The markers each walk finds, as `tool args: marker`.
261273 const walk = async (who: User): Promise<string[]> => {
262274 const found: string[] = [];
275 const { token } = createToken(standIn.app.db, who.id, "walk", "rw");
263276 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);
266279 for (const marker of [VAULT, SUB]) if (got.text.includes(marker)) found.push(`${tool} ${JSON.stringify(args)}: ${marker}`);
267280 }
268281 return found;

Search
↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs