Skip to content

AI-native knowledge base & Evernote/Obsidian alternative with instant sync & native MCP. Free on Cloudflare or self-hosted via Docker.

fix(desktop): connect to WorkBuddy 5.8+ lite-wb CLI over stdio ACP (#586)

yulei666e85916de7878
diff --git a/apps/desktop/src/main/acp-host.mjs b/apps/desktop/src/main/acp-host.mjs
index 89b1795c..ebd6b68b 100644
--- a/apps/desktop/src/main/acp-host.mjs
+++ b/apps/desktop/src/main/acp-host.mjs
@@ -209,13 +209,14 @@ function resolveWorkBuddy(id, deps) {
const actual = deps.realpath(candidate);
if (!deps.stat(actual).isFile()) continue;
deps.access(actual, fsConstants.R_OK);
+ const liteBundle = isWorkBuddyLiteBundle(actual, deps);
if (deps.platform === "darwin") {
const executable = path.resolve(path.dirname(actual), "../../../../MacOS/Electron");
if (deps.exists(executable)) {
- return { ok: true, command: workBuddyCommand(executable, actual, id, true) };
+ return { ok: true, command: workBuddyCommand(executable, actual, id, true, liteBundle) };
}
}
- return { ok: true, command: workBuddyCommand(deps.executablePath, actual, id) };
+ return { ok: true, command: workBuddyCommand(deps.executablePath, actual, id, false, liteBundle) };
} catch { /* Try another installed WorkBuddy application. */ }
}
const external = findOnPath(deps.platform === "win32" ? ["codebuddy.exe"] : ["codebuddy"], deps);
@@ -224,10 +225,20 @@ function resolveWorkBuddy(id, deps) {
: { ok: false, state: "not_installed" };
}
-function workBuddyCommand(executablePath, bundledCli, id, nativeBootstrap = false) {
+// WorkBuddy 5.8+ ships only dist/codebuddy-lite-wb.mjs. That bundle loads only
+// with CODEBUDDY_FORCE_LITE_WB_BUNDLE, and its bare --acp runs a one-shot print
+// session; stdio ACP is served only alongside --serve, whose gateway stays on loopback.
+function isWorkBuddyLiteBundle(bundledCli, deps) {
+ const dist = path.resolve(path.dirname(bundledCli), "../dist");
+ return deps.exists(path.join(dist, "codebuddy-lite-wb.mjs")) && !deps.exists(path.join(dist, "codebuddy.js"));
+}
+
+function workBuddyCommand(executablePath, bundledCli, id, nativeBootstrap = false, liteBundle = false) {
const edition = id === "workbuddyCn" ? { CODEBUDDY_INTERNET_ENVIRONMENT: "internal" } : {};
+ const acpArgs = liteBundle ? ["--acp", "--serve", "--acp-transport", "stdio", "--host", "127.0.0.1"] : ["--acp"];
+ const bundleEnv = liteBundle ? { CODEBUDDY_FORCE_LITE_WB_BUNDLE: "1", SERVER__HOST: "127.0.0.1" } : {};
return bundledCli
- ? { command: executablePath, args: [...(nativeBootstrap ? [fileURLToPath(new URL("./workbuddy-launch.cjs", import.meta.url))] : []), bundledCli, "--acp"], env: { ...edition, ELECTRON_RUN_AS_NODE: "1" }, ...(id === "workbuddyIntl" ? { unsetEnv: ["CODEBUDDY_INTERNET_ENVIRONMENT"] } : {}) }
+ ? { command: executablePath, args: [...(nativeBootstrap ? [fileURLToPath(new URL("./workbuddy-launch.cjs", import.meta.url))] : []), bundledCli, ...acpArgs], env: { ...edition, ...bundleEnv, ELECTRON_RUN_AS_NODE: "1" }, ...(id === "workbuddyIntl" ? { unsetEnv: ["CODEBUDDY_INTERNET_ENVIRONMENT"] } : {}) }
: { command: executablePath, args: ["--acp"], env: edition, ...(id === "workbuddyIntl" ? { unsetEnv: ["CODEBUDDY_INTERNET_ENVIRONMENT"] } : {}) };
}
diff --git a/apps/desktop/src/main/acp-host.test.mjs b/apps/desktop/src/main/acp-host.test.mjs
index d66297fe..6a3b03e2 100644
--- a/apps/desktop/src/main/acp-host.test.mjs
+++ b/apps/desktop/src/main/acp-host.test.mjs
@@ -23,6 +23,7 @@ import {
sanitizeFailureDetail,
spawnAcpChild,
} from "./acp-host.mjs";
+import { prepareWorkBuddyAuth } from "./workbuddy-auth.mjs";
const require = createRequire(import.meta.url);
const sdkHref = pathToFileURL(require.resolve("@agentclientprotocol/sdk")).href;
@@ -478,6 +479,21 @@ describe("ACP command allow-list", () => {
expect(nativeInternational.command.args.slice(1)).toEqual([realpathSync(bundled), "--acp"]);
expect(nativeInternational.command.env).toEqual({ ELECTRON_RUN_AS_NODE: "1" });
expect(nativeInternational.command.unsetEnv).toEqual(["CODEBUDDY_INTERNET_ENVIRONMENT"]);
+ // WorkBuddy 5.8+ ships only the lite-wb bundle, whose stdio ACP needs --serve.
+ const dist = path.resolve(path.dirname(bundled), "../dist");
+ await mkdir(dist, { recursive: true });
+ await writeFile(path.join(dist, "codebuddy-lite-wb.mjs"), "// fake lite-wb bundle");
+ const liteDomestic = resolveAcpCommand({ id: "workbuddyCn" }, deps);
+ expect(liteDomestic.command.args.slice(1)).toEqual([realpathSync(bundled), "--acp", "--serve", "--acp-transport", "stdio", "--host", "127.0.0.1"]);
+ expect(liteDomestic.command.env).toEqual({ CODEBUDDY_INTERNET_ENVIRONMENT: "internal", CODEBUDDY_FORCE_LITE_WB_BUNDLE: "1", SERVER__HOST: "127.0.0.1", ELECTRON_RUN_AS_NODE: "1" });
+ const liteAuth = await prepareWorkBuddyAuth(liteDomestic.command);
+ for (const flag of ["--serve", "--acp-transport", "--host", "--port"]) {
+ expect(liteAuth.command.args.filter((arg) => arg === flag)).toHaveLength(1);
+ }
+ expect(liteAuth.command.args).toEqual([...liteDomestic.command.args, "--port", new URL(liteAuth.endpoint).port]);
+ // A full bundle beside lite-wb keeps the legacy launch.
+ await writeFile(path.join(dist, "codebuddy.js"), "// fake full bundle");
+ expect(resolveAcpCommand({ id: "workbuddyCn" }, deps).command.args.slice(1)).toEqual([realpathSync(bundled), "--acp"]);
} finally {
await rm(directory, { recursive: true, force: true });
}
diff --git a/apps/desktop/src/main/workbuddy-auth.mjs b/apps/desktop/src/main/workbuddy-auth.mjs
index e8931745..10df495b 100644
--- a/apps/desktop/src/main/workbuddy-auth.mjs
+++ b/apps/desktop/src/main/workbuddy-auth.mjs
@@ -13,7 +13,7 @@ export async function prepareWorkBuddyAuth(command) {
return {
command: {
...command,
- args: [...command.args, "--serve", "--acp-transport", "stdio", "--host", "127.0.0.1", "--port", String(port)],
+ args: [...command.args, ...(command.args.includes("--serve") ? [] : ["--serve", "--acp-transport", "stdio", "--host", "127.0.0.1"]), "--port", String(port)],
env: { ...command.env, SERVER__HOST: "127.0.0.1", SERVER__PORT: String(port), CODEBUDDY_GATEWAY_AUTH: "password", CODEBUDDY_GATEWAY_PASSWORD: password },
},
endpoint: `http://127.0.0.1:${port}`,