Skip to content

Commit 1a873b5

Browse files
committed
feat(server): support OpenCode 2 alongside OpenCode 1
1 parent 5d76653 commit 1a873b5

22 files changed

Lines changed: 4806 additions & 87 deletions

‎apps/server/package.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
"@effect/platform-node-shared": "catalog:",
2929
"@effect/sql-sqlite-bun": "catalog:",
3030
"@ff-labs/fff-node": "0.9.4",
31+
"@opencode-ai/client": "0.0.0-beta-18155",
3132
"@opencode-ai/sdk": "^1.3.15",
3233
"@pierre/diffs": "catalog:",
3334
"effect": "catalog:",

‎apps/server/src/orchestration/Layers/ProviderRuntimeIngestion.approval.test.ts‎

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,38 @@ describe("runtimeEventToActivities approval details", () => {
3131
expect((activity?.payload as Record<string, unknown> | undefined)?.detail).toBe(detail);
3232
});
3333

34+
it("keeps OpenCode v2 project-wide approval choices available to every client", () => {
35+
const options = [
36+
{ decision: "decline", label: "Decline" },
37+
{ decision: "acceptAlways", label: "Always allow this project" },
38+
{ decision: "accept", label: "Allow once" },
39+
] as const;
40+
const event = {
41+
type: "request.opened",
42+
eventId: EventId.make("evt-opencode-approval"),
43+
provider: ProviderDriverKind.make("opencode"),
44+
createdAt: "2026-08-25T00:00:00.000Z",
45+
threadId: ThreadId.make("thread-opencode"),
46+
requestId: RuntimeRequestId.make("approval-opencode"),
47+
payload: {
48+
requestType: "command_execution_approval",
49+
detail: "git status",
50+
options,
51+
},
52+
} satisfies ProviderRuntimeEvent;
53+
54+
const [activity] = runtimeEventToActivities(event);
55+
56+
expect(activity).toMatchObject({
57+
kind: "approval.requested",
58+
payload: {
59+
requestId: "approval-opencode",
60+
requestKind: "command",
61+
options,
62+
},
63+
});
64+
});
65+
3466
it("keeps app details and approval options available to remote clients", () => {
3567
const options = [
3668
{ decision: "decline", label: "Decline" },

‎apps/server/src/provider/Drivers/OpenCodeDriver.ts‎

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ import type { ServerProviderDraft } from "../providerSnapshot.ts";
4343
import { mergeProviderInstanceEnvironment } from "../ProviderInstanceEnvironment.ts";
4444
import {
4545
enrichProviderSnapshotWithVersionAdvisory,
46+
makeManualOnlyProviderMaintenanceCapabilities,
4647
makePackageManagedProviderMaintenanceResolver,
4748
normalizeCommandPath,
4849
resolveProviderMaintenanceCapabilitiesEffect,
@@ -64,7 +65,7 @@ function isOpenCodeNativeCommandPath(commandPath: string): boolean {
6465
);
6566
}
6667

67-
const UPDATE = makePackageManagedProviderMaintenanceResolver({
68+
const LEGACY_UPDATE = makePackageManagedProviderMaintenanceResolver({
6869
provider: DRIVER_KIND,
6970
npmPackageName: "opencode-ai",
7071
homebrewFormula: "anomalyco/tap/opencode",
@@ -76,6 +77,25 @@ const UPDATE = makePackageManagedProviderMaintenanceResolver({
7677
},
7778
});
7879

80+
const UPDATE = {
81+
resolve(options?: Parameters<typeof LEGACY_UPDATE.resolve>[0]) {
82+
const paths = [options?.binaryPath, options?.resolvedCommandPath, options?.realCommandPath];
83+
const isOpenCodeV2 = paths.some(
84+
(commandPath) =>
85+
typeof commandPath === "string" &&
86+
/(?:^|\/)opencode2(?:\.(?:cmd|bat|exe))?$/.test(normalizeCommandPath(commandPath)),
87+
);
88+
const isUnresolvedDefault =
89+
options?.binaryPath === "opencode" &&
90+
!options.resolvedCommandPath &&
91+
!options.realCommandPath;
92+
93+
return isOpenCodeV2 || isUnresolvedDefault
94+
? makeManualOnlyProviderMaintenanceCapabilities({ provider: DRIVER_KIND, packageName: null })
95+
: LEGACY_UPDATE.resolve(options);
96+
},
97+
};
98+
7999
export type OpenCodeDriverEnv =
80100
| BackgroundPolicy.BackgroundPolicy
81101
| ChildProcessSpawner.ChildProcessSpawner

0 commit comments

Comments
 (0)