Skip to content

A desktop coding agent with free access to frontier models.

TypeScript

fix: preview engine skips the global config, key refusal hint

ogsamrat1c4c9642fa20
diff --git a/apps/app/src/react-app/domains/settings/pages/mcp-supported-panel.tsx b/apps/app/src/react-app/domains/settings/pages/mcp-supported-panel.tsx
index 6c62f2a6..bdd40d2c 100644
--- a/apps/app/src/react-app/domains/settings/pages/mcp-supported-panel.tsx
+++ b/apps/app/src/react-app/domains/settings/pages/mcp-supported-panel.tsx
@@ -32,6 +32,7 @@ export const MCP_BLOCKED_HINTS: Record<string, string> = {
runner_missing: "Install Node.js (for npx) or uv (for uvx), then restart the app.",
secret_missing: "Set the key in your environment, then restart the app.",
remote_settings: "Remove the headers and settings: only the plain address is supported.",
+ protected_value: "Take the app's key out of the entry: give the server only its own settings.",
};
export type McpServerState =
diff --git a/apps/app/tests/mcp-supported-panel.test.tsx b/apps/app/tests/mcp-supported-panel.test.tsx
index 93a257e2..1359630d 100644
--- a/apps/app/tests/mcp-supported-panel.test.tsx
+++ b/apps/app/tests/mcp-supported-panel.test.tsx
@@ -171,6 +171,9 @@ describe("Settings > MCP: supported servers", () => {
expect(signed).toContain("https://mcp.figma.com/mcp");
expect(render({ policy: policy({ supported: [remote], decisions: on }), servers: [server("figma", { type: "remote", url: "https://mcp.figma.com/mcp" })] })).not.toContain("mcp-sign-in-figma");
expect(MCP_BLOCKED_HINTS.secret_missing).toContain("environment");
+ // An entry holding one of the app's keys: the refusal says why, the hint what to change.
+ const held = mcpServerState(server("mem"), { name: "mem", status: "blocked", code: "protected_value", reason: "This MCP server entry holds one of the app's own keys (in its command, variables or folder), so it does not start." });
+ expect(held).toEqual({ kind: "blocked", reason: "This MCP server entry holds one of the app's own keys (in its command, variables or folder), so it does not start.", hint: MCP_BLOCKED_HINTS.protected_value });
});
test("a missing MCP filter: one clear warning (no MCP server starts), enabled or not", () => {
diff --git a/apps/server/src/managed-opencode-v2.env.test.ts b/apps/server/src/managed-opencode-v2.env.test.ts
new file mode 100644
index 00000000..ab55881f
--- /dev/null
+++ b/apps/server/src/managed-opencode-v2.env.test.ts
@@ -0,0 +1,28 @@
+import { expect, test } from "bun:test";
+import { chmod, mkdtemp, readFile, rm, writeFile } from "node:fs/promises";
+import { tmpdir } from "node:os";
+import { join } from "node:path";
+
+import { createManagedOpencodeV2Server } from "./managed-opencode-v2.js";
+
+const posix = process.platform === "win32" ? test.skip : test;
+
+posix("the v2 engine gets its own empty config home, not the user's global opencode config", async () => {
+ const dir = await mkdtemp(join(tmpdir(), "v2-env-"));
+ try {
+ const record = join(dir, "env.txt");
+ const bin = join(dir, "fake-v2");
+ await writeFile(bin, `#!/bin/sh\nenv > "${record}"\nexit 3\n`);
+ await chmod(bin, 0o755);
+ const userConfig = join(dir, "user-config");
+ await createManagedOpencodeV2Server({ bin, rootDir: join(dir, "state"), bootTimeoutMs: 5_000, env: { XDG_CONFIG_HOME: userConfig } })
+ .then((server) => server.close(), () => undefined);
+ const env = await readFile(record, "utf8");
+ const configHome = /^XDG_CONFIG_HOME=(.*)$/m.exec(env)?.[1];
+ expect(configHome).toBe(join(dir, "state", "xdg-config"));
+ expect(env).not.toContain(userConfig);
+ expect(env).toMatch(/^OPENCODE_DISABLE_PROJECT_CONFIG=1$/m);
+ } finally {
+ await rm(dir, { recursive: true, force: true });
+ }
+});
diff --git a/apps/server/src/managed-opencode-v2.ts b/apps/server/src/managed-opencode-v2.ts
index c1e3d412..145e40da 100644
--- a/apps/server/src/managed-opencode-v2.ts
+++ b/apps/server/src/managed-opencode-v2.ts
@@ -117,6 +117,11 @@ export async function createManagedOpencodeV2Server(
await chmod(options.rootDir, 0o700);
await mkdir(configDir, { recursive: true, mode: 0o700 });
await chmod(configDir, 0o700);
+ // The user's global opencode config (~/.config/opencode) is not read either: its MCP servers would start with
+ // this environment (the password and the policy token) before the app removes them. Its own empty folder instead.
+ const configHome = join(options.rootDir, "xdg-config");
+ await mkdir(configHome, { recursive: true, mode: 0o700 });
+ await chmod(configHome, 0o700);
// Load enforcement on the first boot, before any session can run.
await writeProviders();
const child = spawn(options.bin, ["serve", "--hostname", hostname, "--port", String(port)], {
@@ -125,6 +130,7 @@ export async function createManagedOpencodeV2Server(
OPENCODE_PASSWORD: password,
OPENCODE_DB: join(options.rootDir, "opencode.db"),
OPENCODE_CONFIG_DIR: configDir,
+ XDG_CONFIG_HOME: configHome,
// No session sharing to an outside share service.
OPENCODE_DISABLE_SHARE: "1",
// A project's own config files are not read: this engine has no MCP filter, and it starts a project's