Skip to content
Source
Sign inSign up
pingdotgg/t3code

feat: add opencode provider support #1758

Mergednexxeln(GitHub profile, opens in a new tab)merged 23 commits intomain fromrefs/pull/1758/headmerged by juliusmarminge View on GitHub

summary

  • add OpenCode as a first-class provider across contracts, server runtime wiring, and the web model picker/settings flow
  • implement the OpenCode adapter with SDK-based session streaming, approvals, question handling, and assistant/tool event projection fixes
  • add OpenCode-backed git text generation for thread titles, branch names, commit messages, and PR content

testing

  • bun fmt
  • bun lint
  • PATH="/Users/nxl/.local/state/fnm_multishells/11922_1773576539803/bin:$PATH" bun run typecheck

Note

Medium Risk Introduces a new provider end-to-end (process spawning, network auth, streaming event translation, and persistence/cache integration), which increases integration and lifecycle edge-case risk. Changes also alter event logging behavior by writing canonical logs per threadId.

Overview Adds OpenCode as a first-class provider across the server and web app, including provider discovery/health probing, session orchestration support, and UI selection.

On the server, this introduces an OpenCodeAdapter (SDK-based session streaming with approvals/questions, rollback, and native event logging), an OpenCodeProvider (CLI/server probing with friendlier error messages), and an OpenCodeTextGeneration implementation wired into RoutingTextGeneration with shared local server reuse + 30s idle TTL (or direct use of a configured serverUrl/serverPassword). Provider registries, persistence decoding, and provider status caching are updated to include opencode, and canonical event logging now keys logs by threadId.

On the web, OpenCode becomes selectable in the model picker (icon/theme tweaks), settings gains OpenCode serverUrl/serverPassword fields, and the composer traits UI adds OpenCode-specific Variant + Agent controls while hiding the interaction-mode toggle for OpenCode sessions. Extensive tests are added/updated to cover the new provider wiring and behavior.

Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit e2d5c2f491fa60e06d6626bf76c3f564e3d53008. Bugbot is set up for automated code reviews on this repo. Configure [here](https://www.cursor.com/dashboard/bugbot).

Note

Add OpenCode as a supported provider across server and web

  • Adds full OpenCode provider support end-to-end: contracts, settings schemas, server-side provider/adapter layers, text generation routing, and web UI settings panel.
  • Introduces OpenCodeTextGeneration with a shared server lifecycle: the server process is reused across requests and auto-closed after a 30-second idle TTL, with serialized access via a semaphore.
  • Adds OpenCodeAdapter and OpenCodeProvider server layers, integrates them into ProviderAdapterRegistry and ProviderRegistry, and routes requests with provider: 'opencode' through the new text generation layer.
  • Extends the composer UI to support OpenCode-specific Variant and Agent trait selectors, hides the Build/Plan interaction mode toggle for OpenCode, and surfaces server URL and password fields in the settings panel.
  • Adds createModelSelection and related normalizer helpers in packages/shared to reduce manual model selection object construction across the codebase.
  • Behavioral Change: ProviderService canonical event logs now pass canonicalEvent.threadId instead of null, attributing logs to the correct thread segment.
Macroscope summarized e2d5c2f.
    1. coderabbitai[bot](GitHub profile, opens in a new tab)commented

      Important

      Review skipped

      Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

      ⚙️ Run configuration

      Configuration used: Repository UI

      Review profile: CHILL

      Plan: Pro

      Run ID: 1ec0c310-9345-4921-824e-81225575434b

      You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

      Use the checkbox below for a quick retry:

      • 🔍 Trigger review
      ✨ Finishing Touches
      🧪 Generate unit tests (beta)
      • Create PR with unit tests

      Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

      ❤️ Share
      Comment `@coderabbitai help` to get the list of available commands and usage tips.
    2. github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched

    3. macroscopeapp[bot](GitHub profile, opens in a new tab)commented

      Approvability

      Verdict: Needs human review

      1 blocking correctness issue found. This PR introduces a complete new provider integration (OpenCode) with ~4700 lines of new code spanning process management, SDK integration, credential handling, and UI changes. Unresolved review comments include a high-severity concern about plaintext password storage and medium-severity issues with error handling and default fallback behavior. New features of this scope with security implications require human review.

      You can customize Macroscope's approvability policy. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).
    4. apps/server/src/git/Layers/OpenCodeTextGeneration.ts line 120OutdatedResolvedby juliusmarminge
    5. is it going to be implemented?

    6. apps/server/src/provider/Layers/OpenCodeAdapter.ts line 59OutdatedResolvedby juliusmarminge
    7. @@ -50,7 +56,21 @@
      56+ sendTurn: vi.fn(),
      57+ interruptTurn: vi.fn(),
      58+ respondToRequest: vi.fn(),
      59+ respondToUserInput: vi.fn(),
      60+ stopSession: vi.fn(),
      61+ listSessions: vi.fn(),
      62+ hasSession: vi.fn(),
      63+ readThread: vi.fn(),
      64+ rollbackThread: vi.fn(),
      65+ stopAll: vi.fn(),
      66+ streamEvents: Stream.empty,
      67+};
      68+
      5069 const layer = it.layer(
      5170 Layer.mergeAll(
      5271 Layer.provide(
      5372 ProviderAdapterRegistryLive,
      5473 Layer.mergeAll(
      5574 Layer.succeed(CodexAdapter, fakeCodexAdapter),
      5675 Layer.succeed(ClaudeAdapter, fakeClaudeAdapter),
      76+ Layer.succeed(OpenCodeAdapter, fakeOpenCodeAdapter),

      Inconsistent indentation in ProviderAdapterRegistry and ProviderRegistry

      Low Severity

      Several new lines in ProviderAdapterRegistry.test.ts use inconsistent indentation relative to the surrounding code. For example, the Layer.succeed(OpenCodeAdapter, ...) line at 76 is indented 8 spaces while the adjacent CodexAdapter and ClaudeAdapter lines use 10 spaces. Similarly, const openCode and its assertion at lines 89/92 break alignment with the existing codex/claude lines.

      Additional Locations (1)
      Fix in Cursor Fix in Web
      Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit 570f8192d5bf99d7aa0e362c35426a9f480302a4. Configure [here](https://www.cursor.com/dashboard/bugbot).
    8. @@ -0,0 +192,21 @@
      192+ item: unknown,
      193+): void {
      194+ if (!turnId) {
      195+ return;
      196+ }
      197+ resolveTurnSnapshot(context, turnId).items.push(item);
      198+}
      199+
      200+function ensureSessionContext(
      201+ sessions: ReadonlyMap<ThreadId, OpenCodeSessionContext>,
      202+ threadId: ThreadId,
      203+): OpenCodeSessionContext {
      204+ const session = sessions.get(threadId);
      205+ if (!session) {
      206+ throw new ProviderAdapterSessionNotFoundError({ provider: PROVIDER, threadId });
      207+ }
      208+ if (session.stopped) {
      209+ throw new ProviderAdapterSessionClosedError({ provider: PROVIDER, threadId });
      210+ }
      211+ return session;
      212+}
      macroscopeapp[bot](GitHub profile, opens in a new tab)commented

      🟡 Medium Layers/OpenCodeAdapter.ts:200

      ensureSessionContext throws plain exceptions at lines 207 and 209, but it's called inside Effect.fn generators. When a function throws synchronously inside a generator, Effect catches it as a defect (Die) rather than a typed failure (Fail), so these errors escape the typed error channel and can't be caught with catchTag or catchAll. Return an Effect that fails with these errors instead, and have callers yield* it.

      +function ensureSessionContext(
      +  sessions: ReadonlyMap<ThreadId, OpenCodeSessionContext>,
      +  threadId: ThreadId,
      +): Effect.Effect<OpenCodeSessionContext, ProviderAdapterSessionNotFoundError | ProviderAdapterSessionClosedError> {
      +  const session = sessions.get(threadId);
      +  if (!session) {
      +    return Effect.fail(new ProviderAdapterSessionNotFoundError({ provider: PROVIDER, threadId }));
      +  }
      +  if (session.stopped) {
      +    return Effect.fail(new ProviderAdapterSessionClosedError({ provider: PROVIDER, threadId }));
      +  }
      +  return Effect.succeed(session);
      +}
      🤖 Copy this AI Prompt to have your agent fix this:
      In file apps/server/src/provider/Layers/OpenCodeAdapter.ts around lines 200-212:
      
      `ensureSessionContext` throws plain exceptions at lines 207 and 209, but it's called inside `Effect.fn` generators. When a function throws synchronously inside a generator, Effect catches it as a defect (`Die`) rather than a typed failure (`Fail`), so these errors escape the typed error channel and can't be caught with `catchTag` or `catchAll`. Return an `Effect` that fails with these errors instead, and have callers `yield*` it.
      
      Evidence trail:
      apps/server/src/provider/Layers/OpenCodeAdapter.ts:201-211 (ensureSessionContext throws at lines 206 and 209), apps/server/src/provider/Layers/OpenCodeAdapter.ts:984-985 (called in Effect.fn generator), apps/server/src/provider/Layers/OpenCodeAdapter.ts:1107-1108, apps/server/src/provider/Layers/ClaudeAdapter.ts:2451-2455 (correctly uses Effect.fail), apps/server/src/provider/Layers/CursorAdapter.ts:340-348 (correctly uses Effect.fail), apps/server/src/provider/Layers/GeminiAdapter.ts:874-878 (correctly uses yield*), apps/server/src/provider/Errors.ts:25-35 (ProviderAdapterSessionNotFoundError is Schema.TaggedErrorClass)
      @@ -0,0 +291,21 @@
      291+ await new Promise<void>((resolve, reject) => {
      292+ server.once("error", reject);
      293+ server.listen(0, DEFAULT_HOSTNAME, () => resolve());
      294+ });
      295+ const address = server.address() as AddressInfo;
      296+ const port = address.port;
      297+ await new Promise<void>((resolve, reject) => {
      298+ server.close((error) => (error ? reject(error) : resolve()));
      299+ });
      300+ return port;
      301+}
      302+
      303+export function resolveOpenCodeBinaryPath(binaryPath: string): string {
      304+ if (Path.isAbsolute(binaryPath)) {
      305+ return binaryPath;
      306+ }
      307+ return execFileSync("which", [binaryPath], {
      308+ encoding: "utf8",
      309+ timeout: 3_000,
      310+ }).trim();
      311+}
      macroscopeapp[bot](GitHub profile, opens in a new tab)commented

      🟢 Low provider/opencodeRuntime.ts:303

      resolveOpenCodeBinaryPath calls execFileSync("which", ...) unconditionally, which throws ENOENT on Windows since which does not exist there (the Windows equivalent is where). Since the function is exported without any platform guard, any Windows caller will crash. Consider adding a platform check to use where on Windows, or document that this function is Unix-only and add a runtime guard that throws a clear error on unsupported platforms.

      +import { platform } from "node:os";
      +
       export function resolveOpenCodeBinaryPath(binaryPath: string): string {
         if (Path.isAbsolute(binaryPath)) {
           return binaryPath;
         }
      +  if (platform() === "win32") {
      +    throw new Error("resolveOpenCodeBinaryPath is not supported on Windows");
      +  }
         return execFileSync("which", [binaryPath], {
           encoding: "utf8",
           timeout: 3_000,
         }).trim();
       }
      🤖 Copy this AI Prompt to have your agent fix this:
      In file apps/server/src/provider/opencodeRuntime.ts around lines 303-311:
      
      `resolveOpenCodeBinaryPath` calls `execFileSync("which", ...)` unconditionally, which throws `ENOENT` on Windows since `which` does not exist there (the Windows equivalent is `where`). Since the function is exported without any platform guard, any Windows caller will crash. Consider adding a platform check to use `where` on Windows, or document that this function is Unix-only and add a runtime guard that throws a clear error on unsupported platforms.
      
      Evidence trail:
      apps/server/src/provider/opencodeRuntime.ts lines 303-311 - shows `resolveOpenCodeBinaryPath` using `execFileSync("which", ...)` without platform check. Line 421-423 shows the internal caller `detectMacosSigkillHint` is guarded by `process.platform === "darwin"`. The function is exported at line 303 but has no platform guard itself.
    9. Cursor Bugbot has reviewed your changes and found 2 potential issues.

      There are 3 total unresolved issues (including 1 from previous review).

      Fix All in Cursor ❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the [Cursor dashboard](https://www.cursor.com/dashboard/bugbot). Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit e2d5c2f491fa60e06d6626bf76c3f564e3d53008. Configure [here](https://www.cursor.com/dashboard/bugbot).
      packages/contracts/src/settings.ts line 97Resolvedby juliusmarminge
      @@ -105,4 +105,4 @@
      105105
      106106 const ServerSettingsJson = fromLenientJson(ServerSettings);
      107107
      108-const PROVIDER_ORDER: readonly ProviderKind[] = ["codex", "claudeAgent"];
      108+const PROVIDER_ORDER: readonly ProviderKind[] = ["codex", "claudeAgent", "opencode"];

      OpenCode enabled by default changes text generation fallback

      Medium Severity

      Adding "opencode" to PROVIDER_ORDER while OpenCodeSettings.enabled defaults to true means resolveTextGenerationProvider will now silently fall back to the OpenCode provider when both Codex and Claude are disabled. Since most users won't have the opencode binary installed, this turns a previously graceful "no provider" pass-through into confusing binary-not-found errors for text generation (commit messages, branch names, etc.).

      Additional Locations (1)
      Fix in Cursor Fix in Web
      Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit e2d5c2f491fa60e06d6626bf76c3f564e3d53008. Configure [here](https://www.cursor.com/dashboard/bugbot).
    10. juliusmarminge merged thisce94fee

    11. juliusmarminge closed this

Sign in to join this conversation.