fix(server): honor auto-accept edits for the OpenCode provider (#7100)

This commit is contained in:
Rishet11 authored and GitHub committed 2026-08-24 03:46:06 -07:00
1 parent 6a2608292d
commit 04df98db4c
2 files changed
+51 -1

No files matched your search

@@ -0,0 +1,44 @@
import * as NodeAssert from "node:assert/strict";
import { describe, it } from "vite-plus/test";
import { buildOpenCodePermissionRules } from "./opencodeRuntime.ts";
function actionFor(
runtimeMode: Parameters<typeof buildOpenCodePermissionRules>[0],
permission: string,
) {
return buildOpenCodePermissionRules(runtimeMode).find((rule) => rule.permission === permission)
?.action;
}
describe("buildOpenCodePermissionRules", () => {
it("pre-approves edits once the user has chosen to auto-accept them", () => {
NodeAssert.equal(actionFor("auto-accept-edits", "edit"), "allow");
});
it("still asks before editing when approval is required", () => {
NodeAssert.equal(actionFor("approval-required", "edit"), "ask");
});
// Documented in docs/user/permission-modes.md: providers without an AI
// reviewer, OpenCode among them, fall back to Supervised for "auto".
it("leaves auto asking, as the docs say it does without a reviewer", () => {
NodeAssert.equal(actionFor("auto", "edit"), "ask");
});
it("keeps asking for everything else in the auto modes", () => {
for (const runtimeMode of ["auto-accept-edits", "auto"] as const) {
NodeAssert.equal(actionFor(runtimeMode, "bash"), "ask");
NodeAssert.equal(actionFor(runtimeMode, "webfetch"), "ask");
NodeAssert.equal(actionFor(runtimeMode, "external_directory"), "ask");
NodeAssert.equal(actionFor(runtimeMode, "*"), "ask");
}
});
it("allows everything only under full access", () => {
NodeAssert.deepEqual(buildOpenCodePermissionRules("full-access"), [
{ permission: "*", pattern: "*", action: "allow" },
]);
});
});
+7 -1
View File
@@ -373,10 +373,16 @@ export function buildOpenCodePermissionRules(runtimeMode: RuntimeMode): Permissi
return [{ permission: "*", pattern: "*", action: "allow" }];
}
// "Auto-accept edits" is documented as "auto-approve edits, ask before other
// actions", so prompting for every edit ignores the mode the user picked.
// "auto" is left asking on purpose: the docs say providers without an AI
// reviewer, OpenCode among them, fall back to Supervised for that mode.
const editAction = runtimeMode === "auto-accept-edits" ? "allow" : "ask";
return [
{ permission: "*", pattern: "*", action: "ask" },
{ permission: "bash", pattern: "*", action: "ask" },
{ permission: "edit", pattern: "*", action: "ask" },
{ permission: "edit", pattern: "*", action: editAction },
{ permission: "webfetch", pattern: "*", action: "ask" },
{ permission: "websearch", pattern: "*", action: "ask" },
{ permission: "codesearch", pattern: "*", action: "ask" },