From 38a44903c52dafc31bdca28505a0607a3af59290 Mon Sep 17 00:00:00 2001 From: Kit Langton Date: Fri, 1 May 2026 18:13:31 -0400 Subject: [PATCH] refactor: clarify internal workspace adapter type --- .../src/control-plane/adapters/index.ts | 27 ++++++++----------- .../src/control-plane/adapters/worktree.ts | 4 +-- packages/opencode/src/control-plane/types.ts | 2 +- 3 files changed, 14 insertions(+), 19 deletions(-) diff --git a/packages/opencode/src/control-plane/adapters/index.ts b/packages/opencode/src/control-plane/adapters/index.ts index 1f04ffcfbf..8ba58bb190 100644 --- a/packages/opencode/src/control-plane/adapters/index.ts +++ b/packages/opencode/src/control-plane/adapters/index.ts @@ -1,25 +1,25 @@ import type { ProjectID } from "@/project/schema" import { Effect, Schema } from "effect" -import type { WorkspaceAdapter as PluginWorkspaceAdapter } from "@opencode-ai/plugin" +import type { WorkspaceAdapter as PluginWorkspaceAdapter, WorkspaceInfo as PluginWorkspaceInfo } from "@opencode-ai/plugin" import { EffectBridge } from "@/effect/bridge" import { errorMessage } from "@/util/error" -import { type WorkspaceAdapter, WorkspaceAdapterError, type WorkspaceAdapterEntry, WorkspaceInfo } from "../types" +import { type InternalWorkspaceAdapter, WorkspaceAdapterError, type WorkspaceAdapterEntry, WorkspaceInfo } from "../types" import type { Interface as WorktreeService } from "@/worktree" import { WorktreeAdapterEntry, worktreeAdapter } from "./worktree" const BUILTIN: WorkspaceAdapterEntry[] = [{ type: "worktree", ...WorktreeAdapterEntry }] export const makeBuiltinAdapters = (worktree: WorktreeService) => - new Map([["worktree", worktreeAdapter(worktree)]]) + new Map([["worktree", worktreeAdapter(worktree)]]) -const plugins = new Map>() -const emptyBuiltinAdapters = new Map() +const plugins = new Map>() +const emptyBuiltinAdapters = new Map() export function getAdapter( projectID: ProjectID, type: string, - builtin: ReadonlyMap = emptyBuiltinAdapters, -): WorkspaceAdapter { + builtin: ReadonlyMap = emptyBuiltinAdapters, +): InternalWorkspaceAdapter { const custom = plugins.get(projectID)?.get(type) if (custom) return custom @@ -39,13 +39,8 @@ export async function listAdapters(projectID: ProjectID): Promise new WorkspaceAdapterError({ message: errorMessage(cause), cause }) -const decodeWorkspaceInfo = Schema.decodeUnknownSync(WorkspaceInfo) - -const decodeInfo = (value: unknown) => - Effect.try({ - try: () => decodeWorkspaceInfo(value), - catch: adapterError, - }) +const decodeInfo = (value: PluginWorkspaceInfo) => + Schema.decodeEffect(WorkspaceInfo)(value).pipe(Effect.mapError(adapterError)) function runPromiseAdapter(fn: () => A | Promise) { return Effect.gen(function* () { @@ -57,7 +52,7 @@ function runPromiseAdapter(fn: () => A | Promise) { }) } -function fromPromiseAdapter(adapter: PluginWorkspaceAdapter): WorkspaceAdapter { +function fromPromiseAdapter(adapter: PluginWorkspaceAdapter): InternalWorkspaceAdapter { return { name: adapter.name, description: adapter.description, @@ -71,7 +66,7 @@ function fromPromiseAdapter(adapter: PluginWorkspaceAdapter): WorkspaceAdapter { export function registerAdapter(projectID: ProjectID, type: string, adapter: PluginWorkspaceAdapter) { // Plugins can be loaded per-project so we need to scope them. If you // want to install a global one pass `ProjectID.global`. - const adapters = plugins.get(projectID) ?? new Map() + const adapters = plugins.get(projectID) ?? new Map() adapters.set(type, fromPromiseAdapter(adapter)) plugins.set(projectID, adapters) } diff --git a/packages/opencode/src/control-plane/adapters/worktree.ts b/packages/opencode/src/control-plane/adapters/worktree.ts index 59b4d8df40..7b2791e4c0 100644 --- a/packages/opencode/src/control-plane/adapters/worktree.ts +++ b/packages/opencode/src/control-plane/adapters/worktree.ts @@ -1,6 +1,6 @@ import { Cause, Effect, Schema } from "effect" import type { Interface as WorktreeService } from "@/worktree" -import { type WorkspaceAdapter, WorkspaceAdapterError, WorkspaceInfo } from "../types" +import { type InternalWorkspaceAdapter, WorkspaceAdapterError, WorkspaceInfo } from "../types" const WorktreeConfig = Schema.Struct({ name: WorkspaceInfo.fields.name, @@ -29,7 +29,7 @@ const decodeConfig = (info: WorkspaceInfo) => catch: (cause) => adapterError(cause instanceof Error ? cause.message : String(cause), cause), }) -export function worktreeAdapter(worktree: WorktreeService): WorkspaceAdapter { +export function worktreeAdapter(worktree: WorktreeService): InternalWorkspaceAdapter { return { ...WorktreeAdapterEntry, configure(info) { diff --git a/packages/opencode/src/control-plane/types.ts b/packages/opencode/src/control-plane/types.ts index 486357d026..ce2332a2f2 100644 --- a/packages/opencode/src/control-plane/types.ts +++ b/packages/opencode/src/control-plane/types.ts @@ -40,7 +40,7 @@ export class WorkspaceAdapterError extends Schema.TaggedErrorClass