Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions apps/server/src/provider/ProviderHostLive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import * as PortScanner from "../preview/PortScanner.ts";
import * as ServerLifecycleEvents from "../serverLifecycleEvents.ts";
import * as ServerSettings from "../serverSettings.ts";
import * as DocumentText from "./DocumentText.ts";
import * as ModelManifest from "./ModelManifest.ts";
import * as ProviderCredentialStore from "./ProviderCredentialStore.ts";

export const layer = Layer.effect(
Expand All @@ -31,7 +32,16 @@ export const layer = Layer.effect(
);
// Optional so hosts built without the preview layer still construct.
const portDiscovery = yield* Effect.serviceOption(PortScanner.PortDiscovery);
// Optional like the services above; without it the bundled policy still applies.
const manifest = yield* Effect.serviceOption(ModelManifest.ModelManifest);
const currentManifest = Option.match(manifest, {
onNone: () => Effect.succeed(ModelManifest.BUNDLED_MODEL_MANIFEST),
onSome: (service) => service.current,
});
return ProviderHost.ProviderHost.of({
compatibility: Effect.fn("ProviderHost.compatibility")(function* (driver, version) {
return ModelManifest.providerCompatibility(yield* currentManifest, driver, version);
}),
paths: {
cwd: config.cwd,
baseDir: config.baseDir,
Expand Down
5 changes: 3 additions & 2 deletions apps/server/src/provider/model-manifest.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"version": 1,
"updatedAt": "2026-11-19T23:30:00Z",
"updatedAt": "2026-11-20T00:34:00Z",
"compatibility": [
{
"driver": "codex",
Expand Down Expand Up @@ -65,6 +65,7 @@
{
"driver": "opencode",
"t3CodeRange": ">=0.0.46",
"versionPattern": "^(\\d+\\.\\d+\\.\\d+)(?:-[0-9A-Za-z.-]+)?(?:\\+[0-9A-Za-z.-]+)?$",
"recommendedRange": ">=2.0.18",
"ranges": [
{ "range": ">=2.0.18", "status": "supported" },
Expand Down Expand Up @@ -107,7 +108,7 @@
"recommendedRange": ">=1.0.0",
"ranges": [
{ "range": ">=0.84.3", "status": "supported" },
{ "range": "<0.84.3", "status": "unsupported" }
{ "range": "<0.84.3", "status": "broken" }
]
},
{
Expand Down
16 changes: 16 additions & 0 deletions apps/server/src/provider/providerCompatibility.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,22 @@ describe("provider compatibility", () => {
assert.strictEqual(advisory?.status, expected, `OpenCode ${version} on 0.0.45`);
assert.strictEqual(advisory?.recommendedVersion, "1.14.19");
}
// The current policy rates a prerelease or build by its base version.
for (const [version, expected] of [
["1.13.0-beta.1", "broken"],
["1.13.0+abc123", "broken"],
["2.1.0-rc.1", "supported"],
] as const) {
assert.strictEqual(
resolveProviderCompatibility(
ModelManifest.BUNDLED_MODEL_MANIFEST.compatibility,
opencode,
version,
)?.status,
expected,
`OpenCode ${version}`,
);
}
assert.isUndefined(
resolveProviderCompatibility(
ModelManifest.BUNDLED_MODEL_MANIFEST.compatibility,
Expand Down
13 changes: 5 additions & 8 deletions apps/server/src/provider/providerCompatibility.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
type ServerProvider,
type ServerProviderCompatibilityAdvisory,
} from "@t3tools/contracts";
import { brokenVersionDetail } from "@t3tools/provider-core/server/compatibility";
import { satisfiesSemverRange } from "@t3tools/shared/semver";
import * as Schema from "effect/Schema";
import packageJson from "../../package.json" with { type: "json" };
Expand Down Expand Up @@ -115,14 +116,10 @@ export function brokenRuntimeError(input: {
readonly advisory: ServerProviderCompatibilityAdvisory | undefined;
readonly action?: string;
}): ProviderSetupError | undefined {
if (input.advisory?.status !== "broken") return undefined;
const target =
input.advisory.recommendedVersion ?? input.advisory.recommendedRange ?? "a newer version";
return new ProviderSetupError({
instanceId: input.instanceId,
operation: "runtime",
detail: `${input.name} ${input.version} does not work with this T3 Code release. ${input.action ?? `Update ${input.name}`} to ${target}, then retry.`,
});
const detail = brokenVersionDetail(input);
return detail === undefined
? undefined
: new ProviderSetupError({ instanceId: input.instanceId, operation: "runtime", detail });
}

export function applyProviderCompatibility(
Expand Down
2 changes: 1 addition & 1 deletion docs/internals/adding-a-provider.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ A provider lives in its own `packages/provider-<name>` package, with
the server's replay testkits drive; testkits that need the orchestrator stay in the server.
Settings live in `providerInstances`; new providers are off by default.
- **Package boundaries.** Server code imports only `@t3tools/provider-core/server/*`, contracts,
and shared. It reaches the server through `ProviderHost` (paths, settings, background demand,
and shared. It reaches the server through `ProviderHost` (paths, settings, background demand, version policy,
attachments, stored credentials), never through `apps/server`. Tests use `@t3tools/provider-testing`.
- **Server registration:** the driver's entry in
[`builtInDrivers.ts`](../../apps/server/src/provider/builtInDrivers.ts). The driver carries its
Expand Down
4 changes: 4 additions & 0 deletions packages/provider-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
"types": "./src/server/attachmentPrompt.ts",
"import": "./src/server/attachmentPrompt.ts"
},
"./server/compatibility": {
"types": "./src/server/compatibility.ts",
"import": "./src/server/compatibility.ts"
},
"./server/auth": {
"types": "./src/server/auth.ts",
"import": "./src/server/auth.ts"
Expand Down
3 changes: 3 additions & 0 deletions packages/provider-core/src/server/ProviderHost.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import type * as Option from "effect/Option";
import type * as Scope from "effect/Scope";
import type * as Stream from "effect/Stream";

import type { ProviderCompatibilityLookup } from "./compatibility.ts";
import type { ProviderCredentialError } from "./errors.ts";

export interface ProviderHostPaths {
Expand Down Expand Up @@ -58,5 +59,7 @@ export class ProviderHost extends Context.Service<
namespace: string,
bindingId: string,
) => Effect.Effect<ProviderCredentials>;
/** A driver declares its minimum version in the policy and asks here, not in a constant. */
readonly compatibility: ProviderCompatibilityLookup;
}
>()("@t3tools/provider-core/server/ProviderHost") {}
23 changes: 23 additions & 0 deletions packages/provider-core/src/server/compatibility.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import type { ProviderDriverKind, ServerProviderCompatibilityAdvisory } from "@t3tools/contracts";
import * as Effect from "effect/Effect";

/** Rates a detected provider version against the host's compatibility policy. */
export type ProviderCompatibilityLookup = (
driver: ProviderDriverKind,
version: string,
) => Effect.Effect<ServerProviderCompatibilityAdvisory | undefined>;

export const noCompatibilityPolicy: ProviderCompatibilityLookup = () => Effect.undefined;

/** The one message for a version the policy rates `broken`; `action` names how it is updated. */
export function brokenVersionDetail(input: {
readonly name: string;
readonly version: string;
readonly advisory: ServerProviderCompatibilityAdvisory | undefined;
readonly action?: string;
}): string | undefined {
if (input.advisory?.status !== "broken") return undefined;
const target =
input.advisory.recommendedVersion ?? input.advisory.recommendedRange ?? "a newer version";
return `${input.name} ${input.version} does not work with this T3 Code release. ${input.action ?? `Update ${input.name}`} to ${target}, then retry.`;
}
1 change: 1 addition & 0 deletions packages/provider-core/src/server/managedProvider.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ function layerProviderHost(input: {
return Layer.succeed(
ProviderHost.ProviderHost,
ProviderHost.ProviderHost.of({
compatibility: () => Effect.undefined,
paths: {
cwd: process.cwd(),
baseDir: "/t3",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
import type { OpencodeClient } from "@opencode-ai/sdk/v2";
import { it as effectIt } from "@effect/vitest";
import * as Effect from "effect/Effect";
import { describe, expect, it } from "vite-plus/test";

import * as OpenCodeRuntime from "./OpenCodeRuntime.ts";
Expand Down Expand Up @@ -28,25 +25,3 @@ describe("resolveOpenCodeServerPassword", () => {
).toBeUndefined();
});
});

function makeHealthClient(
result: (options?: { readonly signal?: AbortSignal }) => Promise<unknown>,
): OpencodeClient {
return {
global: {
health: result,
},
} as unknown as OpencodeClient;
}

describe("verifyOpenCodeServerVersion", () => {
effectIt.effect("rejects a server below the supported version", () =>
Effect.gen(function* () {
const error = yield* OpenCodeRuntime.verifyOpenCodeServerVersion(
makeHealthClient(() => Promise.resolve({ data: { healthy: true, version: "1.14.18" } })),
).pipe(Effect.flip);
expect(error).toBeInstanceOf(OpenCodeRuntime.OpenCodeRuntimeError);
expect(error.detail).toContain("v1.14.18 is too old");
}),
);
});
15 changes: 4 additions & 11 deletions packages/provider-opencode/src/server/OpenCodeRuntime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,11 @@ import { collectStreamAsString } from "@t3tools/provider-core/server/snapshotPro
import * as NetService from "@t3tools/shared/Net";
import { AgentScope } from "@t3tools/shared/AgentScope";
import * as HostProcess from "@t3tools/shared/HostProcess";
import { compareSemverVersions, parseSemver } from "@t3tools/shared/semver";
import { parseSemver } from "@t3tools/shared/semver";
import { resolveSpawnCommand } from "@t3tools/shared/shell";
const encodeUnknownJsonStringExit = Schema.encodeUnknownExit(Schema.fromJsonString(Schema.Unknown));
const OPENCODE_EMPTY_CONFIG_CONTENT = "{}";

export const MINIMUM_OPENCODE_VERSION = "1.14.19";
const OPENCODE_HEALTH_TIMEOUT_MS = 5_000;

const OpenCodeHealthSchema = Schema.Struct({
Expand Down Expand Up @@ -162,7 +161,7 @@ export const runOpenCodeSdk = <A>(
new OpenCodeRuntimeError({ operation, detail: openCodeRuntimeErrorDetail(cause), cause }),
}).pipe(Effect.withSpan(`opencode.${operation}`));

export const verifyOpenCodeServerVersion = Effect.fn("verifyOpenCodeServerVersion")(function* (
const verifyOpenCodeServerVersion = Effect.fn("verifyOpenCodeServerVersion")(function* (
client: OpencodeClient,
environment?: NodeJS.ProcessEnv,
) {
Expand All @@ -185,21 +184,15 @@ export const verifyOpenCodeServerVersion = Effect.fn("verifyOpenCodeServerVersio
(cause) =>
new OpenCodeRuntimeError({
operation: "global.health",
detail: `OpenCode server returned an invalid health response. T3 Code requires OpenCode v${MINIMUM_OPENCODE_VERSION} or newer.`,
detail: "OpenCode server returned an invalid health response.",
cause,
}),
),
);
if (parseSemver(health.version) === null) {
return yield* new OpenCodeRuntimeError({
operation: "global.health",
detail: `OpenCode server returned an invalid version. T3 Code requires OpenCode v${MINIMUM_OPENCODE_VERSION} or newer.`,
});
}
if (compareSemverVersions(health.version, MINIMUM_OPENCODE_VERSION) < 0) {
return yield* new OpenCodeRuntimeError({
operation: "global.health",
detail: `OpenCode v${health.version} is too old. Upgrade to v${MINIMUM_OPENCODE_VERSION} or newer.`,
detail: "OpenCode server returned an invalid version.",
});
}
return health.version;
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
Expand Down
32 changes: 32 additions & 0 deletions packages/provider-opencode/src/server/adapter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ const makeOpenCodeRuntimeHarness = Effect.fn("makeOpenCodeRuntimeHarness")(funct
connectToOpenCodeServer: () =>
Effect.succeed({
url: "http://test.invalid",
version: "1.14.19",
external: turnSettings.exitCode === undefined,
exitCode: turnSettings.exitCode ?? null,
}),
Expand All @@ -192,6 +193,7 @@ const makeOpenCodeRuntimeHarness = Effect.fn("makeOpenCodeRuntimeHarness")(funct
Effect.provideService(ProviderHost.ProviderHost, {
paths: { cwd: "/workspace" },
resolveAttachmentPath: () => null,
compatibility: () => Effect.undefined,
...host,
} as unknown as ProviderHost.ProviderHost["Service"]),
);
Expand Down Expand Up @@ -3846,6 +3848,7 @@ describe("OpenCodeAdapterV2", () => {
Effect.provideService(ProviderHost.ProviderHost, {
paths: { cwd: "/workspace" },
resolveAttachmentPath: () => null,
compatibility: () => Effect.undefined,
} as unknown as ProviderHost.ProviderHost["Service"]),
);
const threadId = ThreadId.make("thread-opencode-admission-race");
Expand Down Expand Up @@ -4490,6 +4493,7 @@ describe("OpenCodeAdapterV2", () => {
Effect.provideService(ProviderHost.ProviderHost, {
paths: { cwd: "/workspace" },
resolveAttachmentPath: () => null,
compatibility: () => Effect.undefined,
} as unknown as ProviderHost.ProviderHost["Service"]),
);
const threadId = ThreadId.make("thread-opencode-initial-stop");
Expand Down Expand Up @@ -5364,3 +5368,31 @@ it.live.each([true, false])("opens an authenticated OpenCode session (external=%
]),
),
);

it.effect("refuses a session on a server version the policy rates broken", () =>
Effect.gen(function* () {
const error = yield* makeOpenCodeRuntimeHarness(
"broken-version",
"ses_broken",
{},
{
compatibility: () =>
Effect.succeed({
status: "broken" as const,
message: null,
recommendedVersion: null,
recommendedRange: ">=2.0.18",
}),
},
).pipe(Effect.flip);
assert.include(JSON.stringify(error), "OpenCode 1.14.19 does not work");
}).pipe(
Effect.scoped,
Effect.provide([
NodeServices.layer,
TestProviderHost.layer().pipe(Layer.provide(NodeServices.layer)),
IdAllocator.layer,
McpProviderSessions.layer,
]),
),
);
15 changes: 15 additions & 0 deletions packages/provider-opencode/src/server/adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import {
type OrchestrationV2TurnItem,
type PlanId,
ProviderDriverKind,
ProviderSetupError,
type ProviderInstanceId,
type ProviderRequestKind,
type ProviderSessionId,
Expand All @@ -54,6 +55,7 @@ import * as Semaphore from "effect/Semaphore";
import * as Scope from "effect/Scope";
import * as Stream from "effect/Stream";

import { brokenVersionDetail } from "@t3tools/provider-core/server/compatibility";
import * as ProviderHost from "@t3tools/provider-core/server/ProviderHost";
import { mcpToolPresentation } from "@t3tools/provider-core/server/mcpToolPresentation";
import * as McpProviderSessions from "@t3tools/provider-core/server/McpProviderSessions";
Expand Down Expand Up @@ -1037,6 +1039,7 @@ export const makeOpenCodeAdapterV2 = Effect.fn("makeOpenCodeAdapterV2")(function
return ProviderAdapter.ProviderAdapterV2.of({
instanceId: options.instanceId,
driver: OPENCODE_PROVIDER,
checksVersionAtHandshake: true,
getCapabilities: Effect.fn("OpencodeAdapter.getCapabilities")(function () {
return Effect.succeed(OpenCodeProviderCapabilitiesV2);
}),
Expand All @@ -1056,6 +1059,18 @@ export const makeOpenCodeAdapterV2 = Effect.fn("makeOpenCodeAdapterV2")(function
: {}),
environment: options.environment,
});
const broken = brokenVersionDetail({
name: "OpenCode",
version: connection.version,
advisory: yield* host.compatibility(OPENCODE_PROVIDER, connection.version),
});
if (broken !== undefined) {
return yield* new ProviderSetupError({
instanceId: options.instanceId,
operation: "runtime",
detail: broken,
});
}
const client = runtime.createOpenCodeSdkClient({
baseUrl: connection.url,
directory: cwd,
Expand Down
1 change: 1 addition & 0 deletions packages/provider-opencode/src/server/driver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,7 @@ export const OpenCodeDriver: ProviderDriver<
runtimeProbe.refresh,
loadOpenCode2Models,
processEnv,
host.compatibility,
).pipe(
Effect.annotateLogs({ providerInstanceId: instanceId }),
Effect.annotateSpans({ providerInstanceId: instanceId }),
Expand Down
Loading
Loading