-
Notifications
You must be signed in to change notification settings - Fork 6.6k
feat(server): add OpenCode 2 provider driver #12084
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
f416862
feat(server): add OpenCode 2 provider driver
tarik02 e66787e
fix(server): harden OpenCode 2 session and connection handling
tarik02 56bff28
fix(server): tighten OpenCode 2 recovery, lifecycle, and probe details
tarik02 4f7e4d4
fix(server): catch the OpenCode 2 schema failure with catchTags
tarik02 62ae128
fix(server): settle OpenCode 2 turns and requests after interruptions
tarik02 42fd3eb
fix(server): offer only the variants an OpenCode 2 model declares
tarik02 fcb1d3c
chore(server): bump @opencode/client and @opencode/schema to 2.0.5
tarik02 8e67120
fix(server): port OpenCode 2 adapter to @opencode/client 2.0.5 API
tarik02 9d81032
fix(server): compose the OpenCode 2 platform layer at the server and …
tarik02 a6267df
fix(server): stop labeling OpenCode 2 reads as changed files (#234)
tarik02 549bd58
fix(server): route OpenCode 2 subagents to the agents surface (#235)
tarik02 171217d
Merge remote-tracking branch 'upstream/main' into feat/opencode2
tarik02 92a174d
chore(server): update OpenCode 2 client to 2.0.8
tarik02 eb8644c
fix(server): harden OpenCode 2 reconnect recovery
tarik02 4d644d6
style(server): use opencode2 runtime namespace
tarik02 fa5fc2c
fix(server): isolate opencode2 instance tools
tarik02 5d3ea23
fix(server): recover stale opencode2 services
tarik02 3c80cbc
fix(server): recover stale opencode2 services
tarik02 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,154 @@ | ||
| /** | ||
| * OpenCode2Driver — `ProviderDriver` for the OpenCode 2 background service. | ||
| * | ||
| * Mirrors the OpenCodeDriver's bundle shape (snapshot / adapter / | ||
| * textGeneration closures over the per-instance `OpenCode2Settings`), but | ||
| * there is no process to own: the adapter and probe connect to the machine's | ||
| * background service (or the configured `serverUrl`). Maintenance is | ||
| * manual-only — the v2 binary manages its own updates. | ||
| * | ||
| * @module provider/Drivers/OpenCode2Driver | ||
| */ | ||
| import { OpenCode2Settings, ProviderDriverKind } from "@t3tools/contracts"; | ||
| import * as Crypto from "effect/Crypto"; | ||
| import * as Effect from "effect/Effect"; | ||
| import * as FileSystem from "effect/FileSystem"; | ||
| import * as Path from "effect/Path"; | ||
| import * as Schema from "effect/Schema"; | ||
|
|
||
| import { makeOpenCode2TextGeneration } from "../../textGeneration/OpenCode2TextGeneration.ts"; | ||
| import * as BackgroundPolicy from "../../background/BackgroundPolicy.ts"; | ||
| import { ServerConfig } from "../../config.ts"; | ||
| import { ServerSettingsService } from "../../serverSettings.ts"; | ||
| import { ProviderDriverError } from "../Errors.ts"; | ||
| import { makeOpenCode2Adapter } from "../Layers/OpenCode2Adapter.ts"; | ||
| import { | ||
| checkOpenCode2ProviderStatus, | ||
| makePendingOpenCode2Provider, | ||
| } from "../Layers/OpenCode2Provider.ts"; | ||
| import { makeManagedServerProvider } from "../makeManagedServerProvider.ts"; | ||
| import * as OpenCode2Runtime from "../opencode2Runtime.ts"; | ||
| import { | ||
| defaultProviderContinuationIdentity, | ||
| type ProviderDriver, | ||
| type ProviderInstance, | ||
| } from "../ProviderDriver.ts"; | ||
| import { withInstanceIdentity } from "./instanceIdentity.ts"; | ||
| import { mergeProviderInstanceEnvironment } from "../ProviderInstanceEnvironment.ts"; | ||
| import { makeManualOnlyProviderMaintenanceCapabilities } from "../providerMaintenance.ts"; | ||
| import { | ||
| haveProviderSnapshotSettingsChanged, | ||
| makeProviderSnapshotSettingsSource, | ||
| type ProviderSnapshotSettings, | ||
| } from "../providerUpdateSettings.ts"; | ||
|
|
||
| const decodeOpenCode2Settings = Schema.decodeSync(OpenCode2Settings); | ||
|
|
||
| const DRIVER_KIND = ProviderDriverKind.make("opencode2"); | ||
|
|
||
| // The v2 binary ships its own updater; T3 never manages it. | ||
| const MANUAL_ONLY = makeManualOnlyProviderMaintenanceCapabilities({ | ||
| provider: DRIVER_KIND, | ||
| packageName: null, | ||
| }); | ||
|
|
||
| export type OpenCode2DriverEnv = | ||
| | BackgroundPolicy.BackgroundPolicy | ||
| | Crypto.Crypto | ||
| | FileSystem.FileSystem | ||
| | OpenCode2Runtime.OpenCode2Runtime | ||
| | Path.Path | ||
| | ServerConfig | ||
| | ServerSettingsService; | ||
|
|
||
| export const OpenCode2Driver: ProviderDriver<OpenCode2Settings, OpenCode2DriverEnv> = { | ||
| driverKind: DRIVER_KIND, | ||
| metadata: { | ||
| displayName: "OpenCode 2", | ||
| supportsMultipleInstances: true, | ||
| }, | ||
| configSchema: OpenCode2Settings, | ||
| defaultConfig: (): OpenCode2Settings => decodeOpenCode2Settings({}), | ||
| create: ({ instanceId, displayName, accentColor, environment, enabled, config }) => | ||
| Effect.gen(function* () { | ||
| const serverConfig = yield* ServerConfig; | ||
| const openCode2Runtime = yield* OpenCode2Runtime.OpenCode2Runtime; | ||
| const serverSettings = yield* ServerSettingsService; | ||
| const processEnv = mergeProviderInstanceEnvironment(environment); | ||
| const continuationIdentity = defaultProviderContinuationIdentity({ | ||
| driverKind: DRIVER_KIND, | ||
| instanceId, | ||
| }); | ||
| const stampIdentity = withInstanceIdentity({ | ||
| instanceId, | ||
| driverKind: DRIVER_KIND, | ||
| displayName, | ||
| accentColor, | ||
| continuationGroupKey: continuationIdentity.continuationKey, | ||
| }); | ||
| const effectiveConfig = { ...config, enabled } satisfies OpenCode2Settings; | ||
|
|
||
| const adapter = yield* makeOpenCode2Adapter(effectiveConfig, { | ||
| instanceId, | ||
| environment: processEnv, | ||
| }); | ||
|
|
||
| const textGeneration = yield* makeOpenCode2TextGeneration(effectiveConfig); | ||
|
|
||
| const checkProviderForCwd = (cwd: string) => | ||
| checkOpenCode2ProviderStatus(effectiveConfig, cwd).pipe( | ||
| Effect.map(stampIdentity), | ||
| Effect.provideService(OpenCode2Runtime.OpenCode2Runtime, openCode2Runtime), | ||
| ); | ||
| const checkProvider = checkProviderForCwd(serverConfig.cwd); | ||
|
|
||
| const snapshotSettings = makeProviderSnapshotSettingsSource(effectiveConfig, serverSettings); | ||
| const snapshot = yield* makeManagedServerProvider< | ||
| ProviderSnapshotSettings<OpenCode2Settings> | ||
| >({ | ||
| resolveMaintenance: () => Effect.succeed(MANUAL_ONLY), | ||
| getSettings: snapshotSettings.getSettings, | ||
| streamSettings: snapshotSettings.streamSettings, | ||
| haveSettingsChanged: haveProviderSnapshotSettingsChanged, | ||
| checkProviderOnSettingsChange: () => true, | ||
| refreshOnInterval: false, | ||
| initialSnapshot: (settings) => | ||
| makePendingOpenCode2Provider(settings.provider).pipe(Effect.map(stampIdentity)), | ||
| checkProvider, | ||
| }).pipe( | ||
| Effect.mapError( | ||
| (cause) => | ||
| new ProviderDriverError({ | ||
| driver: DRIVER_KIND, | ||
| instanceId, | ||
| detail: "Failed to build OpenCode 2 snapshot.", | ||
| cause, | ||
| }), | ||
| ), | ||
| ); | ||
|
|
||
| return { | ||
| instanceId, | ||
| driverKind: DRIVER_KIND, | ||
| continuationIdentity, | ||
| displayName, | ||
| accentColor, | ||
| enabled, | ||
| snapshot, | ||
| snapshotForCwd: (cwd) => | ||
| checkProviderForCwd(cwd).pipe( | ||
| Effect.mapError( | ||
| (cause) => | ||
| new ProviderDriverError({ | ||
| driver: DRIVER_KIND, | ||
| instanceId, | ||
| detail: `Failed to probe OpenCode 2 for '${cwd}'`, | ||
| cause, | ||
| }), | ||
| ), | ||
| ), | ||
| adapter, | ||
| textGeneration, | ||
| } satisfies ProviderInstance; | ||
| }), | ||
| }; | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🟠 High
Drivers/OpenCode2Driver.ts:68Running two OpenCode 2 instances causes the newer session to lose its T3 MCP tools: both adapters register the same name for a given
threadId, and the older instance'sstopStaleSessionsForThreadcleanup removes that registration. SetsupportsMultipleInstancestofalseunless the registration name is made instance-specific.🤖 Copy this AI Prompt to have your agent fix this:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in 3c80cbc: OpenCode 2 MCP registration names now include the bound provider instance ID (openCode2McpServerName(..., boundInstanceId)), so separate instances no longer share a per-thread registration or remove each other’s tools. supportsMultipleInstances: true remains intentional and is now safe.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I'm unable to act on this request because you do not have permissions within this repository.