Skip to content

Open-source Grok Bot alternative for named AI teammates. Local-first desktop, web, and mobile clients with per-bot tools, instructions, and memory. Independent fork of T3 Code.

fix(server): respect inherited OPENCODE_CONFIG_CONTENT (#4242)

Jono61b2e744df37
diff --git a/apps/server/src/provider/opencodeRuntime.environment.test.ts b/apps/server/src/provider/opencodeRuntime.environment.test.ts
new file mode 100644
index 000000000..b56921a68
--- /dev/null
+++ b/apps/server/src/provider/opencodeRuntime.environment.test.ts
@@ -0,0 +1,23 @@
+import { describe, expect, it } from "vite-plus/test";
+
+import { resolveOpenCodeConfigContent } from "./opencodeRuntime.ts";
+
+describe("resolveOpenCodeConfigContent", () => {
+ it("prefers the caller environment over the inherited environment", () => {
+ expect(
+ resolveOpenCodeConfigContent(
+ { OPENCODE_CONFIG_CONTENT: '{"source":"caller"}' },
+ { OPENCODE_CONFIG_CONTENT: '{"source":"process"}' },
+ ),
+ ).toBe('{"source":"caller"}');
+ });
+
+ it("falls back to the inherited environment and then an empty config", () => {
+ expect(
+ resolveOpenCodeConfigContent(undefined, {
+ OPENCODE_CONFIG_CONTENT: '{"source":"process"}',
+ }),
+ ).toBe('{"source":"process"}');
+ expect(resolveOpenCodeConfigContent(undefined, {})).toBe("{}");
+ });
+});
diff --git a/apps/server/src/provider/opencodeRuntime.ts b/apps/server/src/provider/opencodeRuntime.ts
index 95a6a0045..399e7d6b3 100644
--- a/apps/server/src/provider/opencodeRuntime.ts
+++ b/apps/server/src/provider/opencodeRuntime.ts
@@ -37,6 +37,17 @@ import { resolveSpawnCommand } from "@t3tools/shared/shell";
const encodeUnknownJsonStringExit = Schema.encodeUnknownExit(Schema.fromJsonString(Schema.Unknown));
const OPENCODE_EMPTY_CONFIG_CONTENT = "{}";
+export function resolveOpenCodeConfigContent(
+ inputEnvironment: Readonly<Record<string, string | undefined>> | undefined,
+ inheritedEnvironment: Readonly<Record<string, string | undefined>> = process.env,
+): string {
+ return (
+ inputEnvironment?.OPENCODE_CONFIG_CONTENT ??
+ inheritedEnvironment.OPENCODE_CONFIG_CONTENT ??
+ OPENCODE_EMPTY_CONFIG_CONTENT
+ );
+}
+
const OPENCODE_SERVER_READY_PREFIX = "opencode server listening";
const DEFAULT_OPENCODE_SERVER_TIMEOUT_MS = 30_000;
const DEFAULT_HOSTNAME = "127.0.0.1";
@@ -467,7 +478,14 @@ const makeOpenCodeRuntime = Effect.gen(function* () {
shell: spawnCommand.shell,
env: {
...input.environment,
- OPENCODE_CONFIG_CONTENT: OPENCODE_EMPTY_CONFIG_CONTENT,
+ // Respect an OPENCODE_CONFIG_CONTENT provided by the caller or
+ // the inherited process environment, only falling back to the
+ // empty config when neither is set. Setting it unconditionally
+ // previously clobbered the user's opencode config, hiding their
+ // providers/models. The value is set explicitly (rather than
+ // relying on inheritance) because `extendEnv` is false whenever
+ // `input.environment` is provided.
+ OPENCODE_CONFIG_CONTENT: resolveOpenCodeConfigContent(input.environment),
},
extendEnv: input.environment === undefined,
}),