@devries-cameron20 / t3code Mirror · read-only / commits / 2123168a55
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 12:15 UTC

fix(opencode): Go-key-only instances keep OpenCode Go usage on OpenCode 2 (#36519)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>

Julius Marminge committed Nov 14, 2026 at 20:48 UTC 2123168a5568cfa79e6741b321e2e042779d7079
2 files changed +83 -1
packages/provider-opencode/src/server/driver.test.ts
+79
@@ -1053,6 +1053,85 @@ it.layer(layer)("OpenCodeDriver runtime selection", (it) => {
1053 assert.strictEqual(serverStarts, starts);
1054 }).pipe(Effect.scoped, Effect.provide(TestClock.layer())),
1055 );
1056 +
1057 + it.effect("reads Go usage from a stored key when the local server has no Console workspace", () =>
1058 + Effect.gen(function* () {
1059 + let goUsageReads = 0;
1060 + const usageStarted = yield* Deferred.make<void>();
1061 + const server = HttpClient.make((request) => {
1062 + if (request.url === "https://opencode.ai/zen/go/v1/usage") {
1063 + goUsageReads += 1;
1064 + assert.strictEqual(request.headers.authorization, "Bearer test-go-key");
1065 + const window = { percent: 10, resetsAt: "2026-11-01T00:00:00.000Z" };
1066 + return Effect.succeed(
1067 + HttpClientResponse.fromWeb(
1068 + request,
1069 + Response.json({ usage: { rolling: window, weekly: window, monthly: window } }),
1070 + ),
1071 + );
1072 + }
1073 + const path = new URL(request.url).pathname;
1074 + if (path === "/api/experimental/usage/limits") {
1075 + const response = HttpClientResponse.fromWeb(
1076 + request,
1077 + Response.json({ location: { directory: "/work" }, data: null }),
1078 + );
1079 + return Deferred.succeed(usageStarted, undefined).pipe(Effect.as(response));
1080 + }
1081 + const body =
1082 + path === "/api/info"
1083 + ? JSON.parse(OPENCODE_2_RESPONSES["/api/info"].body)
1084 + : { location: { directory: "/work" }, data: [] };
1085 + return Effect.succeed(HttpClientResponse.fromWeb(request, Response.json(body)));
1086 + });
1087 + const runtime = {
1088 + ...openCode2Runtime,
1089 + startOpenCodeServerProcess: ({
1090 + verify,
1091 + }: Parameters<
1092 + OpenCodeRuntime.OpenCodeRuntime["Service"]["startOpenCodeServerProcess"]
1093 + >[0]) =>
1094 + Effect.gen(function* () {
1095 + const url = "http://127.0.0.1:4096";
1096 + const version = verify ? yield* verify(url) : "2.0.18";
1097 + return { url, version, isRunning: Effect.succeed(true), exitCode: Effect.never };
1098 + }),
1099 + };
1100 + const instance = yield* OpenCodeDriver.create({
1101 + instanceId: ProviderInstanceId.make("opencode-go-key-only"),
1102 + displayName: undefined,
1103 + environment: [
1104 + {
1105 + name: "OPENCODE_AUTH_CONTENT",
1106 + sensitive: true,
1107 + value: JSON.stringify({ "opencode-go": { type: "api", key: "test-go-key" } }),
1108 + },
1109 + { name: "OPENCODE_API_KEY", sensitive: true, value: "" },
1110 + ],
1111 + enabled: true,
1112 + config: OpenCodeDriver.defaultConfig(),
1113 + }).pipe(
1114 + Effect.provide(TestProviderHost.layer()),
1115 + Effect.provideService(HttpClient.HttpClient, server),
1116 + Effect.provideService(OpenCodeRuntime.OpenCodeRuntime, runtime),
1117 + );
1118 + const initial = yield* instance.snapshot.streamChanges.pipe(
1119 + Stream.filter((entry) => entry.usageLimits !== undefined),
1120 + Stream.take(1),
1121 + Stream.runCollect,
1122 + Effect.forkChild,
1123 + );
1124 + yield* Deferred.await(usageStarted);
1125 + yield* TestClock.adjust("5 seconds");
1126 + const [snapshot] = Array.from(yield* Fiber.join(initial));
1127 + assert.strictEqual(snapshot?.usageLimits?.unavailable, undefined);
1128 + assert.deepStrictEqual(
1129 + snapshot?.usageLimits?.windows.map((window) => window.kind),
1130 + ["session", "weekly", "monthly"],
1131 + );
1132 + assert.strictEqual(goUsageReads, 1);
1133 + }).pipe(Effect.scoped, Effect.provide(TestClock.layer())),
1134 + );
1135 });
1136
1137 // npm links into opencode-ai for 1.x and @opencode/cli for 2.x.
packages/provider-opencode/src/server/driver.ts
+4 -1
@@ -483,7 +483,10 @@ export const OpenCodeDriver: ProviderDriver<
483 connection.usageLimits(host.paths.cwd),
484 );
485 if (limits === undefined) unsupportedUsageVersion = runtime.version;
486 - return limits ?? (yield* legacyUsageLimits);
486 + if (limits !== undefined && limits.unavailable?.reason !== "unsupported") return limits;
487 + // Without a Console workspace the server reports nothing, but a local Go key still has usage.
488 + const legacy = yield* legacyUsageLimits;
489 + return limits !== undefined && legacy.unavailable?.reason === "unsupported" ? limits : legacy;
490 }).pipe(
491 Effect.timeout("10 seconds"),
492 Effect.catch(() =>