AI-native knowledge base & Evernote/Obsidian alternative with instant sync & native MCP. Free on Cloudflare or self-hosted via Docker.
HTML ai-agentcloudflarecloudflare-d1cloudflare-r2cloudflare-workersdockerelectronevernoteevernote-alternativeknowledge-basemcpnote-takingobsidian-alternativeoffline-firstpersonal-knowledge-basepwaself-hostedsqlitetiptapweb-clipper
Auto-approve ACP tool permissions during prompts
tianma-ifd48b77fc8c08
diff --git a/apps/desktop/src/main/acp-host.mjs b/apps/desktop/src/main/acp-host.mjsindex c5c2c818..1f8b27dc 100644--- a/apps/desktop/src/main/acp-host.mjs+++ b/apps/desktop/src/main/acp-host.mjs@@ -615,9 +615,17 @@ const publicAuthMethods = (initialized) => (: []);-const createEdgeEverAcpClient = (requestId, emit) => ({- requestPermission() {- return { outcome: { outcome: "cancelled" } };+export function automaticAcpPermissionResponse(params) {+ const options = Array.isArray(params?.options) ? params.options : [];+ const option = options.find((item) => item?.kind === "allow_once" && typeof item.optionId === "string" && item.optionId.length > 0 && item.optionId.length <= 120)+ ?? options.find((item) => item?.kind === "allow_always" && typeof item.optionId === "string" && item.optionId.length > 0 && item.optionId.length <= 120);+ return { outcome: option ? { outcome: "selected", optionId: option.optionId } : { outcome: "cancelled" } };+}++const createEdgeEverAcpClient = (requestId, emit, allowPermissions) => ({+ requestPermission(params) {+ // Probe, install, and sign-in sessions do not originate from a user prompt.+ return allowPermissions ? automaticAcpPermissionResponse(params) : { outcome: { outcome: "cancelled" } };},sessionUpdate(params) {for (const event of eventsFromSessionUpdate(requestId, params)) emit(event);@@ -711,7 +719,7 @@ export function createAcpHostRuntime(options = {}) {return adapt(resolveAcpCommand(input, commandDeps));};- const connect = async (command, requestId, emit, signal, authMethodId, mcpServers = []) => {+ const connect = async (command, requestId, emit, signal, authMethodId, mcpServers = [], allowPermissions = false) => {const cwd = await createAcpWorkspace(mkdtempImpl, options.tmpRoot);let child = null;let authMethods = [];@@ -722,7 +730,7 @@ export function createAcpHostRuntime(options = {}) {child = await spawnAcpChild(spawnImpl, command, cwd);if (signal?.aborted) throw Object.assign(new Error("connection_timeout"), { code: "TIMEOUT" });const stream = acpNdJsonStream(child);- const connection = new ClientSideConnection(() => createEdgeEverAcpClient(requestId, emit), stream);+ const connection = new ClientSideConnection(() => createEdgeEverAcpClient(requestId, emit, allowPermissions), stream);void connection.closed?.catch(() => {});const initialized = await connection.initialize(acpInitializeParams(version));authMethods = publicAuthMethods(initialized);@@ -913,7 +921,7 @@ export function createAcpHostRuntime(options = {}) {}connected = await withHandshakeTimeout((signal) => connect(resolved.command, requestId, notify, signal, undefined,- mcpBridge ? [mcpServerFor(mcpBridge)] : [],+ mcpBridge ? [mcpServerFor(mcpBridge)] : [], true,));} catch (error) {await mcpBridge?.close();diff --git a/apps/desktop/src/main/acp-host.test.mjs b/apps/desktop/src/main/acp-host.test.mjsindex acef62d9..4f891668 100644--- a/apps/desktop/src/main/acp-host.test.mjs+++ b/apps/desktop/src/main/acp-host.test.mjs@@ -9,6 +9,7 @@ import { pathToFileURL } from "node:url";import { RequestError } from "@agentclientprotocol/sdk";import {acpInitializeParams,+ automaticAcpPermissionResponse,buildPromptContent,classifyAcpFailure,createAcpHostRuntime,@@ -36,6 +37,21 @@ test("classifies ACP prompt refusals without exposing vendor error details", ()expect(promptResultFailure({ stopReason: "refusal", _meta: { "codebuddy.ai/errorMessage": JSON.stringify({ data: { category: "auth" }, message: "private detail" }) } })).toBe("needs_login");});+test("ACP tool permissions automatically select a one-time allow option", () => {+ const options = [+ { optionId: "always", kind: "allow_always" },+ { optionId: "once", kind: "allow_once" },+ { optionId: "deny", kind: "reject_once" },+ ];+ expect(automaticAcpPermissionResponse({ options })).toEqual({ outcome: { outcome: "selected", optionId: "once" } });+ expect(automaticAcpPermissionResponse({ options: options.filter((option) => option.kind !== "allow_once") }))+ .toEqual({ outcome: { outcome: "selected", optionId: "always" } });+ expect(automaticAcpPermissionResponse({ options: [{ optionId: "deny", kind: "reject_once" }] }))+ .toEqual({ outcome: { outcome: "cancelled" } });+ expect(automaticAcpPermissionResponse({ options: [{ optionId: "", kind: "allow_once" }] }))+ .toEqual({ outcome: { outcome: "cancelled" } });+});+const collector = () => {const events = [];let waiters = [];@@ -680,6 +696,7 @@ describe("ACP stdio session", () => {const report = await readReport(reportPath);expect(report.newSession.mcpServers).toEqual([]);expect(report.prompt).toEqual([{ type: "text", text: "Hello" }]);+ expect(report.permission?.outcome).toEqual({ outcome: "selected", optionId: "allow" });} finally {await rm(directory, { recursive: true, force: true });}@@ -755,7 +772,7 @@ describe("ACP stdio session", () => {}}, 15_000);- sessionTest("streams updates, cancels permission, and never reads a local file", async () => {+ sessionTest("streams updates, auto-approves tools, and never reads a local file", async () => {const directory = await mkdtemp(path.join(tmpdir(), "edgeever-acp-prompt-"));const reportPath = path.join(directory, "report.json");const secretPath = path.join(directory, "secret.txt");@@ -779,7 +796,7 @@ describe("ACP stdio session", () => {}, events.emit);await events.waitFor((event) => event.type === "done");const report = await readReport(reportPath);- expect(report.permission?.outcome?.outcome).toBe("cancelled");+ expect(report.permission?.outcome).toEqual({ outcome: "selected", optionId: "allow" });expect(report.readResult).toBeNull();expect(JSON.stringify(report)).not.toContain("SENTINEL_SECRET_CONTENT");expect(path.resolve(report.newSession.cwd)).not.toBe(home);