From 7bccaae91052f4fb4055055c6ec34769571071af Mon Sep 17 00:00:00 2001 From: yetone Date: Fri, 13 Nov 2026 16:08:37 +0800 Subject: [PATCH] agy-cli 0.1.35: a client tool's ide-tools permission request is allowed once (#1082) Newer agy asks before an MCP call, and the bridge refused every session/request_permission, so each client tool failed with "user denied permission for mcp(ide-tools/exec_command)". A request whose title (or name) is exactly mcp(ide-tools/), mcp "ide-tools/", ide-tools/ or mcp_ide-tools_, with among the tools the client declared, now gets allow_once. Those tools run in the client under its own permissions. agy's own tools (shell, edits, browser) are still denied, as is a title that only contains such a name somewhere (a shell command's text can be in its title), an undeclared tool and another server's tool. rawInput is never read. Run (WSL magpie-desktop, HOME=$(mktemp -d)): bun test in packages/agy-cli, 20 pass; bun scripts/check.mjs agy-cli ok. Broken by hand: with the allow branch off, smoke.mjs has 2 failures, the two #1082 allow checks. Not tried: a real agy that asks for MCP permission. The title agy sends for an MCP call isn't known from its strings, so the forms above come from its rule and error text; the reporter is asked to confirm. Reported-by: Saramanda9988 --- packages/agy-cli/README.en.md | 7 +++++-- packages/agy-cli/README.md | 6 ++++-- packages/agy-cli/index.mjs | 29 +++++++++++++++++++++++++++-- packages/agy-cli/package.json | 2 +- packages/agy-cli/test/smoke.mjs | 18 +++++++++++++++++- 5 files changed, 54 insertions(+), 8 deletions(-) diff --git a/packages/agy-cli/README.en.md b/packages/agy-cli/README.en.md index 2a0f694..0dafee4 100644 --- a/packages/agy-cli/README.en.md +++ b/packages/agy-cli/README.en.md @@ -82,8 +82,11 @@ MCP server. The control port listens on loopback only, with a token per process. and instruction hashes still match. The state file stores session IDs and hashes, never message text. - **Isolation**: your global MCP configuration is never read. Every agy process - runs with a temporary agent, and every permission request agy raises (shell, - file edits, browser) is refused. Real actions happen on the client side. + runs with a temporary agent, and every permission request agy raises for its + own tools (shell, file edits, browser) is refused. A request for one of the + client's tools on the bridge's `ide-tools` server is allowed once, since that + tool runs in the client under the client's own permissions. Real actions + happen on the client side. - **Assistant prefill**: requests that end with a text-only assistant message (SillyTavern presets, "continue"/"impersonate", bot frameworks) are served instead of rejected; the session ledger stays aligned across turns. See diff --git a/packages/agy-cli/README.md b/packages/agy-cli/README.md index f1b1669..d0e5f5a 100644 --- a/packages/agy-cli/README.md +++ b/packages/agy-cli/README.md @@ -59,8 +59,10 @@ agy 连接 `--ide-mcp-port` 时会运行 `nc 127.0.0.1 <端口>`。插件在 agy 占位响应,真正的结果送达后继续同一轮对话,每个调用只在客户端执行一次。 - **会话续接**:每轮结束后记录会话。重启 Magpie 或插件后,只要历史和指令的哈希一致, 就用 `session/resume` 接上上下文。状态文件只存会话 ID 与哈希,不存消息原文。 -- **隔离运行**:不读取你的全局 MCP 配置。每个 agy 进程使用临时 agent。agy 发起的权限 - 请求(shell、写文件、浏览器等)一律拒绝,真正的操作都在客户端侧完成。 +- **隔离运行**:不读取你的全局 MCP 配置。每个 agy 进程使用临时 agent。agy 为它自己的 + 工具发起的权限请求(shell、写文件、浏览器等)一律拒绝;客户端工具经桥接的 `ide-tools` + 调用时发起的请求放行一次,这些工具在客户端里运行,受客户端自己的权限管。真正的操作 + 都在客户端侧完成。 - **助手预填**:以 assistant 结尾的预填请求(SillyTavern 预设、继续写、bot 框架)不再 400 拒绝:预填留在本轮并渲染为续写载体,会话跨轮保持对齐,见下文「助手预填」。 - **额度查看**:在 Magpie 里查看 agy 订阅的用量窗口,仅作展示,额度耗尽时不会自动拦截请求。 diff --git a/packages/agy-cli/index.mjs b/packages/agy-cli/index.mjs index cc049b7..3279330 100644 --- a/packages/agy-cli/index.mjs +++ b/packages/agy-cli/index.mjs @@ -856,6 +856,22 @@ async function sweepWindowsNcDirs(tmp, keep) { } } +// The client tool a permission request names, when it names one on the +// bridge's ide-tools server: agy calls it `mcp(ide-tools/)` in its +// permission rules and `mcp_ide-tools_` as a function. Only agy's own +// words are read (title, name), never rawInput, which the model writes. +const IDE_TOOL_NAMED = /^(?:mcp\(ide-tools\/([^()\s]+)\)|(?:mcp\s+)?"?ide-tools\/([^()\s"]+)"?|mcp_ide-tools_(\S+))$/ +export function ideToolOf(toolCall) { + for (const value of [toolCall?.title, toolCall?.name, toolCall?.toolName]) { + if (typeof value !== "string") continue + // The whole title, never a word in it: a shell command's own text can + // appear in its title. + const m = IDE_TOOL_NAMED.exec(value.trim().replace(/\?$/, "")) + if (m) return m[1] || m[2] || m[3] + } + return "" +} + function agentDefinition() { const lines = [ "---", @@ -1635,8 +1651,17 @@ class Proc { throw Object.assign(new Error("unknown session"), { code: -32602 }) } if (method === "session/request_permission") { - // Client tools arrive through MCP and never ask. Deny anything that would - // run inside agy itself (shell, file edits, questions, browser). + // A client tool reaches agy through the bridge's own ide-tools MCP + // server and runs in the client, under the client's own permissions. + // Newer agy asks before an MCP call too (plugins #1082), so a request + // that names ide-tools and a tool the client declared is allowed once. + // Anything that would run inside agy itself (shell, file edits, + // questions, browser) is denied. + const tool = ideToolOf(params?.toolCall) + if (tool && this.tools.some((t) => t.name === tool)) { + const allow = (params?.options || []).find((option) => option?.kind === "allow_once") + if (allow) return { outcome: { outcome: "selected", optionId: allow.optionId } } + } this.deniedPermissions++ const reject = (params?.options || []).find((option) => option?.kind === "reject_once") || (params?.options || []).find((option) => option?.kind === "reject_always") diff --git a/packages/agy-cli/package.json b/packages/agy-cli/package.json index f7e07f2..65e0015 100644 --- a/packages/agy-cli/package.json +++ b/packages/agy-cli/package.json @@ -1,6 +1,6 @@ { "name": "@magpie-community/opencode-agy-cli-auth", - "version": "0.1.34", + "version": "0.1.35", "description": "Magpie/OpenCode model provider that connects your local agy CLI through the Agent Client Protocol (agy acp), so Antigravity subscription models run through the real CLI", "type": "module", "main": "./opencode.mjs", diff --git a/packages/agy-cli/test/smoke.mjs b/packages/agy-cli/test/smoke.mjs index 2ffd46a..ccef1a5 100644 --- a/packages/agy-cli/test/smoke.mjs +++ b/packages/agy-cli/test/smoke.mjs @@ -297,11 +297,14 @@ async function prompt(params) { return { stopReason: "end_turn" } } if (text.includes("PERMISSION")) { + const titled = /PERMISSION_TITLE\[(.*?)\]/.exec(text) const outcome = await new Promise(resolve => { pendingClient.set("perm", resolve) send({ jsonrpc: "2.0", id: "perm", method: "session/request_permission", params: { sessionId: session.id, - toolCall: { toolCallId: "call_perm", title: "Run run_command?", rawInput: { CommandLine: "printf SHOULD_NOT_RUN" } }, + toolCall: titled + ? { toolCallId: "call_perm", title: titled[1], rawInput: { text: "hi" } } + : { toolCallId: "call_perm", title: "Run run_command?", rawInput: { CommandLine: "printf SHOULD_NOT_RUN" } }, options: [ { optionId: "allow", name: "Allow once", kind: "allow_once" }, { optionId: "always", name: "Allow always", kind: "allow_always" }, @@ -1320,6 +1323,19 @@ for (const change of ["tools", "model"]) { check("a denied built-in tool does not fail the turn", stopOf(events) === "end_turn") } +for (const [title, tools, want, name] of [ + ["mcp(ide-tools/echo)", [echoTool], "allow", "a client tool on ide-tools is allowed once (#1082)"], + ["mcp_ide-tools_echo", [echoTool], "allow", "a client tool named as agy's function is allowed once (#1082)"], + ["mcp(ide-tools/run_shell)", [echoTool], "deny", "an ide-tools tool the client did not declare is denied"], + ["Run command: echo mcp(ide-tools/echo)", [echoTool], "deny", "a title that only contains an ide-tools name is denied"], + ["mcp(other/echo)", [echoTool], "deny", "another MCP server's tool is denied"], +]) { + const response = await callFetch({ model, messages: [{ role: "user", content: `PERMISSION_TITLE[${title}]` }], tools }) + const { events } = await readSSE(response) + const permission = lastOf("permission") + check(name, permission?.outcome?.outcome === "selected" && permission.outcome.optionId === want && stopOf(events) === "end_turn", JSON.stringify(permission)) +} + { const opening = { model, messages: [{ role: "user", content: "before the upstream error" }] } const openingEvents = (await readSSE(await callFetch(opening))).events