Skip to content

Commit 6a3957b

Browse files
saphidclaude
andcommitted
fix(opencode): proxy checks key off T3's own state, not OpenCode's plugin flag
Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 6ed782b commit 6a3957b

5 files changed

Lines changed: 22 additions & 7 deletions

File tree

‎packages/provider-opencode/src/server/OpenCodeRuntime.environment.test.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,9 @@ describe("verifyOpenCodeServerVersion", () => {
124124
OpenCodeRuntime.minimumOpenCodeVersionFor(proxied),
125125
).pipe(Effect.flip);
126126
expect(error.detail).toBe("OpenCode v1.14.48 is too old. Upgrade to v1.14.49 or newer.");
127-
expect(OpenCodeRuntime.minimumOpenCodeVersionFor({})).toBe("1.14.19");
127+
expect(
128+
OpenCodeRuntime.minimumOpenCodeVersionFor({ OPENCODE_DISABLE_DEFAULT_PLUGINS: "1" }),
129+
).toBe("1.14.19");
128130
}),
129131
);
130132
});

‎packages/provider-opencode/src/server/OpenCodeRuntime.ts‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,12 @@ export const MINIMUM_OPENCODE_VERSION = "1.14.19";
5353
// login's plugin would send requests around the proxy.
5454
const MINIMUM_PROXIED_OPENCODE_VERSION = "1.14.49";
5555

56-
/** Set only by applyOpenCodeProxyEnvironment. */
57-
export const isOpenCodeProxied = (environment: NodeJS.ProcessEnv | undefined): boolean =>
58-
environment?.OPENCODE_DISABLE_DEFAULT_PLUGINS === "1";
56+
// T3's own marker: OpenCode's flags may already be set by the user without a proxy.
57+
const PROXIED_MARKER = "T3CODE_OPENCODE_PROXIED";
58+
59+
/** True only for an environment built by applyOpenCodeProxyEnvironment. */
60+
const isOpenCodeProxied = (environment: NodeJS.ProcessEnv | undefined): boolean =>
61+
environment?.[PROXIED_MARKER] === "1";
5962

6063
/** The oldest server a spawn may accept, given its environment. */
6164
export const minimumOpenCodeVersionFor = (environment: NodeJS.ProcessEnv | undefined): string =>
@@ -128,6 +131,7 @@ export function applyOpenCodeProxyEnvironment(
128131
...environment,
129132
OPENCODE_CONFIG_CONTENT: content,
130133
OPENCODE_DISABLE_DEFAULT_PLUGINS: "1",
134+
[PROXIED_MARKER]: "1",
131135
OPENCODE_PURE: "1",
132136
};
133137
}

‎packages/provider-opencode/src/server/driver.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,7 @@ export const OpenCodeDriver: ProviderDriver<
289289
serverPassword: effectiveConfig.serverPassword,
290290
directory: host.paths.cwd,
291291
environment: processEnv,
292+
proxied: proxy !== undefined,
292293
}).pipe(
293294
Effect.provideService(OpenCodeRuntime.OpenCodeRuntime, openCodeRuntime),
294295
Effect.provideService(

‎packages/provider-opencode/src/server/v2/OpenCode2Server.test.ts‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ describe("OpenCode2Server error details", () => {
103103
serverPassword: "secret",
104104
directory: "/project",
105105
environment: {},
106+
proxied: false,
106107
});
107108
const error = yield* server.withConnection(() => Effect.void).pipe(Effect.flip);
108109
return error.detail;
@@ -200,7 +201,13 @@ describe("OpenCode2Server spawned server", () => {
200201
serverUrl: "",
201202
serverPassword: "",
202203
directory,
203-
environment: { ...(yield* HostProcess.Environment), OPENCODE_SERVER_PASSWORD: "ambient" },
204+
// OpenCode's own flag may be set without a proxy; only `proxied` refuses OpenCode 2.
205+
environment: {
206+
...(yield* HostProcess.Environment),
207+
OPENCODE_SERVER_PASSWORD: "ambient",
208+
OPENCODE_DISABLE_DEFAULT_PLUGINS: "1",
209+
},
210+
proxied: false,
204211
});
205212
const first = yield* server.withConnection((connection) => Effect.succeed(connection));
206213
const second = yield* server.withConnection((connection) => Effect.succeed(connection));
@@ -217,6 +224,7 @@ describe("OpenCode2Server spawned server", () => {
217224
url: "http://proxy:8317",
218225
apiKey: "sk",
219226
}),
227+
proxied: true,
220228
});
221229
const refused = yield* proxied
222230
.withConnection((connection) => Effect.succeed(connection))

‎packages/provider-opencode/src/server/v2/OpenCode2Server.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ export const make = Effect.fn("OpenCode2Server.make")(function* (input: {
115115
readonly serverPassword: string;
116116
readonly directory: string;
117117
readonly environment: NodeJS.ProcessEnv;
118+
readonly proxied: boolean;
118119
}) {
119120
const opencode = yield* OpenCode2Client.OpenCode2Client;
120121
const connectTo = Effect.fn("OpenCode2Server.connectTo")(function* (
@@ -156,10 +157,9 @@ export const make = Effect.fn("OpenCode2Server.make")(function* (input: {
156157
});
157158
// OpenCode 2 reads provider endpoints from `providers.*.settings`, which the proxy override
158159
// does not write yet; running would send turns around the proxy.
159-
const proxied = OpenCodeRuntime.isOpenCodeProxied(input.environment);
160160
return OpenCode2Server.of({
161161
withConnection: Effect.fn("OpenCode2Server.withConnection")(function (use) {
162-
if (proxied) {
162+
if (input.proxied) {
163163
return Effect.fail(
164164
new OpenCodeRuntime.OpenCodeRuntimeError({
165165
operation: "server.start",

0 commit comments

Comments
 (0)