Skip to content

A desktop coding agent with free access to frontier models.

TypeScript

fix: the folder write check runs the current engine

ogsamratdac6fc28da30
diff --git a/apps/server/src/folder-write-check.test.ts b/apps/server/src/folder-write-check.test.ts
index e690647b..222f6b39 100644
--- a/apps/server/src/folder-write-check.test.ts
+++ b/apps/server/src/folder-write-check.test.ts
@@ -14,6 +14,7 @@ import {
probeWithEngine,
readOnlyPrompt,
resetFolderWriteGate,
+ setWriteCheckEngine,
type FolderProbeOutcome,
} from "./folder-write-check.js";
@@ -207,6 +208,17 @@ describe("folderWriteGate", () => {
expect(probes).toBe(4);
});
+ test("the probe runs the 2.x engine, the one chats run on, not the 1.x binary set at start", async () => {
+ setWriteCheckEngine("/app/sidecars/opencode");
+ const ran: string[] = [];
+ const probeEngine = async (_dir: string, bin: string): Promise<FolderProbeOutcome> => { ran.push(bin); return { ok: true }; };
+ expect(await folderWriteGate("ses_v2", "/p", { env: { OMNIRUSH_OPENCODE2_BIN: "/app/sidecars/opencode2" }, probeEngine, platform: "linux" })).toBeNull();
+ // No 2.x engine named (tests, an older dev setup): the one set at start.
+ expect(await folderWriteGate("ses_v1", "/q", { env: {}, probeEngine, platform: "linux" })).toBeNull();
+ expect(ran).toEqual(["/app/sidecars/opencode2", "/app/sidecars/opencode"]);
+ setWriteCheckEngine(null);
+ });
+
test("OMNIRUSH_WRITE_CHECK=off skips it", async () => {
expect(await folderWriteGate("ses_2", "/p", { env: { OMNIRUSH_WRITE_CHECK: "off" }, probeEngine: async () => fail("EACCES"), engineBin: "/x" })).toBeNull();
});
diff --git a/apps/server/src/folder-write-check.ts b/apps/server/src/folder-write-check.ts
index 12d0d1b7..d5e8e6ae 100644
--- a/apps/server/src/folder-write-check.ts
+++ b/apps/server/src/folder-write-check.ts
@@ -402,7 +402,9 @@ export async function folderWriteGate(sessionId: string, dir: string, options: C
}
let pending = inFlight.get(dir);
if (!pending) {
- pending = checkFolderWritable(dir, { engineBin: engineBinary ?? process.env.OMNIRUSH_OPENCODE_BIN ?? null, ...options })
+ // Chats run on the 2.x engine (the 1.x one no longer ships): its binary runs the probe.
+ const env = options.env ?? process.env;
+ pending = checkFolderWritable(dir, { engineBin: env.OMNIRUSH_OPENCODE2_BIN?.trim() || engineBinary || env.OMNIRUSH_OPENCODE_BIN?.trim() || null, ...options })
.finally(() => inFlight.delete(dir));
inFlight.set(dir, pending);
}