GeezerVison is showing github.com — refactor: rename workspace adapters (#25272) · githubhjs/opencode@8c79c58
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: packages/opencode/specs/effect/http-api.md +2-2Lines changed: 2 additions & 2 deletions - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
@@ -198,7 +198,7 @@ Use raw Effect HTTP routes where `HttpApi` does not fit. The goal is deleting Ho | 198 | 198 | | `project` | `bridged` | list, current, git init, update | | 199 | 199 | | `file` | `bridged` partial | find text/file/symbol, list/content/status | | 200 | 200 | | `mcp` | `bridged` | status, add, OAuth, connect/disconnect | | 201 | | -| `workspace` | `bridged` | adaptor/list/status/create/remove/session-restore | | | 201 | +| `workspace` | `bridged` | adapter/list/status/create/remove/session-restore | | 202 | 202 | | top-level instance routes | `bridged` | path, vcs, command, agent, skill, lsp, formatter, dispose | | 203 | 203 | | experimental JSON routes | `bridged` | console, tool, worktree list/mutations, global session list, resource list | | 204 | 204 | | `session` | `bridged` | read, lifecycle, prompt, message/part mutations, revert, permission reply | | @@ -290,7 +290,7 @@ This checklist tracks bridge parity only. Checked routes are available through t | 290 | 290 |
| 291 | 291 | ### Workspace Routes | 292 | 292 |
| 293 | | -- [x] `GET /experimental/workspace/adaptor` - list workspace adaptors. | | 293 | +- [x] `GET /experimental/workspace/adapter` - list workspace adapters. | 294 | 294 | - [x] `POST /experimental/workspace` - create workspace. | 295 | 295 | - [x] `GET /experimental/workspace` - list workspaces. | 296 | 296 | - [x] `GET /experimental/workspace/status` - workspace status. | |
Collapse file Copy file name to clipboardExpand all lines: packages/opencode/specs/effect/schema.md +1-1Lines changed: 1 addition & 1 deletion - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
@@ -353,7 +353,7 @@ piecewise. | 353 | 353 | - [ ] `src/cli/cmd/tui/event.ts` | 354 | 354 | - [ ] `src/cli/ui.ts` | 355 | 355 | - [ ] `src/command/index.ts` | 356 | | -- [x] `src/control-plane/adaptors/worktree.ts` | | 356 | +- [x] `src/control-plane/adapters/worktree.ts` | 357 | 357 | - [x] `src/control-plane/types.ts` | 358 | 358 | - [x] `src/control-plane/workspace.ts` | 359 | 359 | - [ ] `src/file/index.ts` | |
Collapse file Copy file name to clipboardExpand all lines: packages/opencode/src/cli/cmd/tui/component/dialog-workspace-create.tsx +8-8Lines changed: 8 additions & 8 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -10,7 +10,7 @@ import { errorMessage } from "@/util/error" | 10 | 10 | import { useSDK } from "../context/sdk" | 11 | 11 | import { useToast } from "../ui/toast" | 12 | 12 |
| 13 | | -type Adaptor = { | | 13 | +type Adapter = { | 14 | 14 | type: string | 15 | 15 | name: string | 16 | 16 | description: string | @@ -108,26 +108,26 @@ export function DialogWorkspaceCreate(props: { onSelect: (workspaceID: string) = | 108 | 108 | const sdk = useSDK() | 109 | 109 | const toast = useToast() | 110 | 110 | const [creating, setCreating] = createSignal<string>() | 111 | | - const [adaptors, setAdaptors] = createSignal<Adaptor[]>() | | 111 | + const [adapters, setAdapters] = createSignal<Adapter[]>() | 112 | 112 |
| 113 | 113 | onMount(() => { | 114 | 114 | dialog.setSize("medium") | 115 | 115 | void (async () => { | 116 | 116 | const dir = sync.path.directory || sdk.directory | 117 | | - const url = new URL("/experimental/workspace/adaptor", sdk.url) | | 117 | + const url = new URL("/experimental/workspace/adapter", sdk.url) | 118 | 118 | if (dir) url.searchParams.set("directory", dir) | 119 | 119 | const res = await sdk | 120 | 120 | .fetch(url) | 121 | | - .then((x) => x.json() as Promise<Adaptor[]>) | | 121 | + .then((x) => x.json() as Promise<Adapter[]>) | 122 | 122 | .catch(() => undefined) | 123 | 123 | if (!res) { | 124 | 124 | toast.show({ | 125 | | - message: "Failed to load workspace adaptors", | | 125 | + message: "Failed to load workspace adapters", | 126 | 126 | variant: "error", | 127 | 127 | }) | 128 | 128 | return | 129 | 129 | } | 130 | | - setAdaptors(res) | | 130 | + setAdapters(res) | 131 | 131 | })() | 132 | 132 | }) | 133 | 133 |
| @@ -142,13 +142,13 @@ export function DialogWorkspaceCreate(props: { onSelect: (workspaceID: string) = | 142 | 142 | }, | 143 | 143 | ] | 144 | 144 | } | 145 | | - const list = adaptors() | | 145 | + const list = adapters() | 146 | 146 | if (!list) { | 147 | 147 | return [ | 148 | 148 | { | 149 | 149 | title: "Loading workspaces...", | 150 | 150 | value: "loading" as const, | 151 | | - description: "Fetching available workspace adaptors", | | 151 | + description: "Fetching available workspace adapters", | 152 | 152 | }, | 153 | 153 | ] | 154 | 154 | } | |
Collapse file Copy file name to clipboard +45Lines changed: 45 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +import type { ProjectID } from "@/project/schema" | | 2 | +import type { WorkspaceAdapter, WorkspaceAdapterEntry } from "../types" | | 3 | +import { WorktreeAdapter } from "./worktree" | | 4 | + | | 5 | +const BUILTIN: Record<string, WorkspaceAdapter> = { | | 6 | + worktree: WorktreeAdapter, | | 7 | +} | | 8 | + | | 9 | +const state = new Map<ProjectID, Map<string, WorkspaceAdapter>>() | | 10 | + | | 11 | +export function getAdapter(projectID: ProjectID, type: string): WorkspaceAdapter { | | 12 | + const custom = state.get(projectID)?.get(type) | | 13 | + if (custom) return custom | | 14 | + | | 15 | + const builtin = BUILTIN[type] | | 16 | + if (builtin) return builtin | | 17 | + | | 18 | + throw new Error(`Unknown workspace adapter: ${type}`) | | 19 | +} | | 20 | + | | 21 | +export async function listAdapters(projectID: ProjectID): Promise<WorkspaceAdapterEntry[]> { | | 22 | + const builtin = await Promise.all( | | 23 | + Object.entries(BUILTIN).map(async ([type, adapter]) => { | | 24 | + return { | | 25 | + type, | | 26 | + name: adapter.name, | | 27 | + description: adapter.description, | | 28 | + } | | 29 | + }), | | 30 | + ) | | 31 | + const custom = [...(state.get(projectID)?.entries() ?? [])].map(([type, adapter]) => ({ | | 32 | + type, | | 33 | + name: adapter.name, | | 34 | + description: adapter.description, | | 35 | + })) | | 36 | + return [...builtin, ...custom] | | 37 | +} | | 38 | + | | 39 | +// Plugins can be loaded per-project so we need to scope them. If you | | 40 | +// want to install a global one pass `ProjectID.global` | | 41 | +export function registerAdapter(projectID: ProjectID, type: string, adapter: WorkspaceAdapter) { | | 42 | + const adapters = state.get(projectID) ?? new Map<string, WorkspaceAdapter>() | | 43 | + adapters.set(type, adapter) | | 44 | + state.set(projectID, adapters) | | 45 | +} |
Collapse file Copy file name to clipboardExpand all lines: packages/opencode/src/control-plane/adapters/worktree.ts +2-2Lines changed: 2 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 1 | 1 | import { Schema } from "effect" | 2 | | -import { type WorkspaceAdaptor, WorkspaceInfo } from "../types" | | 2 | +import { type WorkspaceAdapter, WorkspaceInfo } from "../types" | 3 | 3 |
| 4 | 4 | const WorktreeConfig = Schema.Struct({ | 5 | 5 | name: WorkspaceInfo.fields.name, | @@ -13,7 +13,7 @@ async function loadWorktree() { | 13 | 13 | return { AppRuntime, Worktree } | 14 | 14 | } | 15 | 15 |
| 16 | | -export const WorktreeAdaptor: WorkspaceAdaptor = { | | 16 | +export const WorktreeAdapter: WorkspaceAdapter = { | 17 | 17 | name: "Worktree", | 18 | 18 | description: "Create a git worktree", | 19 | 19 | async configure(info) { | |
Collapse file Copy file name to clipboardExpand all lines: packages/opencode/src/control-plane/adaptors/index.ts -45Lines changed: 0 additions & 45 deletions Collapse file Copy file name to clipboardExpand all lines: packages/opencode/src/control-plane/types.ts +3-3Lines changed: 3 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -17,12 +17,12 @@ export const WorkspaceInfo = Schema.Struct({ | 17 | 17 | .pipe(withStatics((s) => ({ zod: zod(s) }))) | 18 | 18 | export type WorkspaceInfo = DeepMutable<Schema.Schema.Type<typeof WorkspaceInfo>> | 19 | 19 |
| 20 | | -export const WorkspaceAdaptorEntry = Schema.Struct({ | | 20 | +export const WorkspaceAdapterEntry = Schema.Struct({ | 21 | 21 | type: Schema.String, | 22 | 22 | name: Schema.String, | 23 | 23 | description: Schema.String, | 24 | 24 | }).pipe(withStatics((s) => ({ zod: zod(s) }))) | 25 | | -export type WorkspaceAdaptorEntry = Schema.Schema.Type<typeof WorkspaceAdaptorEntry> | | 25 | +export type WorkspaceAdapterEntry = Schema.Schema.Type<typeof WorkspaceAdapterEntry> | 26 | 26 |
| 27 | 27 | export type Target = | 28 | 28 | | { | @@ -35,7 +35,7 @@ export type Target = | 35 | 35 | headers?: HeadersInit | 36 | 36 | } | 37 | 37 |
| 38 | | -export type WorkspaceAdaptor = { | | 38 | +export type WorkspaceAdapter = { | 39 | 39 | name: string | 40 | 40 | description: string | 41 | 41 | configure(info: WorkspaceInfo): WorkspaceInfo | Promise<WorkspaceInfo> | |
Collapse file Copy file name to clipboardExpand all lines: packages/opencode/src/control-plane/workspace.ts +13-13Lines changed: 13 additions & 13 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -16,7 +16,7 @@ import { Filesystem } from "@/util/filesystem" | 16 | 16 | import { ProjectID } from "@/project/schema" | 17 | 17 | import { Slug } from "@opencode-ai/core/util/slug" | 18 | 18 | import { WorkspaceTable } from "./workspace.sql" | 19 | | -import { getAdaptor } from "./adaptors" | | 19 | +import { getAdapter } from "./adapters" | 20 | 20 | import { type WorkspaceInfo, WorkspaceInfo as WorkspaceInfoSchema } from "./types" | 21 | 21 | import { WorkspaceID } from "./schema" | 22 | 22 | import { Session } from "@/session/session" | @@ -335,8 +335,8 @@ export const layer = Layer.effect( | 335 | 335 | }) | 336 | 336 |
| 337 | 337 | const syncWorkspaceLoop = Effect.fn("Workspace.syncWorkspaceLoop")(function* (space: Info) { | 338 | | - const adaptor = getAdaptor(space.projectID, space.type) | 339 | | - const target = yield* Effect.promise(() => Promise.resolve(adaptor.target(space))) | | 338 | + const adapter = getAdapter(space.projectID, space.type) | | 339 | + const target = yield* Effect.promise(() => Promise.resolve(adapter.target(space))) | 340 | 340 |
| 341 | 341 | if (target.type === "local") return | 342 | 342 |
| @@ -419,8 +419,8 @@ export const layer = Layer.effect( | 419 | 419 | const startSync = Effect.fn("Workspace.startSync")(function* (space: Info) { | 420 | 420 | if (!Flag.OPENCODE_EXPERIMENTAL_WORKSPACES) return | 421 | 421 |
| 422 | | - const adaptor = getAdaptor(space.projectID, space.type) | 423 | | - const target = yield* Effect.promise(() => Promise.resolve(adaptor.target(space))) | | 422 | + const adapter = getAdapter(space.projectID, space.type) | | 423 | + const target = yield* Effect.promise(() => Promise.resolve(adapter.target(space))) | 424 | 424 |
| 425 | 425 | if (target.type === "local") { | 426 | 426 | setStatus(space.id, (yield* Effect.promise(() => Filesystem.exists(target.directory))) ? "connected" : "error") | @@ -458,9 +458,9 @@ export const layer = Layer.effect( | 458 | 458 |
| 459 | 459 | const create = Effect.fn("Workspace.create")(function* (input: CreateInput) { | 460 | 460 | const id = WorkspaceID.ascending(input.id) | 461 | | - const adaptor = getAdaptor(input.projectID, input.type) | | 461 | + const adapter = getAdapter(input.projectID, input.type) | 462 | 462 | const config = yield* Effect.promise(() => | 463 | | - Promise.resolve(adaptor.configure({ ...input, id, name: Slug.create(), directory: null })), | | 463 | + Promise.resolve(adapter.configure({ ...input, id, name: Slug.create(), directory: null })), | 464 | 464 | ) | 465 | 465 |
| 466 | 466 | const info: Info = { | @@ -496,7 +496,7 @@ export const layer = Layer.effect( | 496 | 496 | OTEL_RESOURCE_ATTRIBUTES: process.env.OTEL_RESOURCE_ATTRIBUTES, | 497 | 497 | } | 498 | 498 |
| 499 | | - yield* Effect.promise(() => adaptor.create(config, env)) | | 499 | + yield* Effect.promise(() => adapter.create(config, env)) | 500 | 500 | yield* Effect.all( | 501 | 501 | [ | 502 | 502 | waitEvent({ | @@ -531,8 +531,8 @@ export const layer = Layer.effect( | 531 | 531 | workspaceID: input.workspaceID, | 532 | 532 | }) | 533 | 533 |
| 534 | | - const adaptor = getAdaptor(space.projectID, space.type) | 535 | | - const target = yield* Effect.promise(() => Promise.resolve(adaptor.target(space))) | | 534 | + const adapter = getAdapter(space.projectID, space.type) | | 535 | + const target = yield* Effect.promise(() => Promise.resolve(adapter.target(space))) | 536 | 536 |
| 537 | 537 | yield* sync.run(Session.Event.Updated, { | 538 | 538 | sessionID: input.sessionID, | @@ -726,12 +726,12 @@ export const layer = Layer.effect( | 726 | 726 | const info = fromRow(row) | 727 | 727 | yield* Effect.catch( | 728 | 728 | Effect.gen(function* () { | 729 | | - const adaptor = getAdaptor(info.projectID, row.type) | 730 | | - yield* Effect.tryPromise(() => Promise.resolve(adaptor.remove(info))) | | 729 | + const adapter = getAdapter(info.projectID, row.type) | | 730 | + yield* Effect.tryPromise(() => Promise.resolve(adapter.remove(info))) | 731 | 731 | }), | 732 | 732 | () => | 733 | 733 | Effect.sync(() => { | 734 | | - log.error("adaptor not available when removing workspace", { type: row.type }) | | 734 | + log.error("adapter not available when removing workspace", { type: row.type }) | 735 | 735 | }), | 736 | 736 | ) | 737 | 737 |
| |
Collapse file Copy file name to clipboardExpand all lines: packages/opencode/src/plugin/index.ts +5-5Lines changed: 5 additions & 5 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -3,7 +3,7 @@ import type { | 3 | 3 | PluginInput, | 4 | 4 | Plugin as PluginInstance, | 5 | 5 | PluginModule, | 6 | | - WorkspaceAdaptor as PluginWorkspaceAdaptor, | | 6 | + WorkspaceAdapter as PluginWorkspaceAdapter, | 7 | 7 | } from "@opencode-ai/plugin" | 8 | 8 | import { Config } from "@/config/config" | 9 | 9 | import { Bus } from "../bus" | @@ -24,8 +24,8 @@ import { InstanceState } from "@/effect/instance-state" | 24 | 24 | import { errorMessage } from "@/util/error" | 25 | 25 | import { PluginLoader } from "./loader" | 26 | 26 | import { parsePluginSpecifier, readPluginId, readV1Plugin, resolvePluginId } from "./shared" | 27 | | -import { registerAdaptor } from "@/control-plane/adaptors" | 28 | | -import type { WorkspaceAdaptor } from "@/control-plane/types" | | 27 | +import { registerAdapter } from "@/control-plane/adapters" | | 28 | +import type { WorkspaceAdapter } from "@/control-plane/types" | 29 | 29 |
| 30 | 30 | const log = Log.create({ service: "plugin" }) | 31 | 31 |
| @@ -138,8 +138,8 @@ export const layer = Layer.effect( | 138 | 138 | worktree: ctx.worktree, | 139 | 139 | directory: ctx.directory, | 140 | 140 | experimental_workspace: { | 141 | | - register(type: string, adaptor: PluginWorkspaceAdaptor) { | 142 | | - registerAdaptor(ctx.project.id, type, adaptor as WorkspaceAdaptor) | | 141 | + register(type: string, adapter: PluginWorkspaceAdapter) { | | 142 | + registerAdapter(ctx.project.id, type, adapter as WorkspaceAdapter) | 143 | 143 | }, | 144 | 144 | }, | 145 | 145 | get serverUrl(): URL { | |
Collapse file Copy file name to clipboardExpand all lines: packages/opencode/src/server/routes/control/workspace.ts +9-9Lines changed: 9 additions & 9 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -2,10 +2,10 @@ import { Hono } from "hono" | 2 | 2 | import { describeRoute, resolver, validator } from "hono-openapi" | 3 | 3 | import z from "zod" | 4 | 4 | import { Effect } from "effect" | 5 | | -import { listAdaptors } from "@/control-plane/adaptors" | | 5 | +import { listAdapters } from "@/control-plane/adapters" | 6 | 6 | import { Workspace } from "@/control-plane/workspace" | 7 | 7 | import { AppRuntime } from "@/effect/app-runtime" | 8 | | -import { WorkspaceAdaptorEntry } from "@/control-plane/types" | | 8 | +import { WorkspaceAdapterEntry } from "@/control-plane/types" | 9 | 9 | import { zodObject } from "@/util/effect-zod" | 10 | 10 | import { Instance } from "@/project/instance" | 11 | 11 | import { errors } from "../../error" | @@ -18,24 +18,24 @@ const log = Log.create({ service: "server.workspace" }) | 18 | 18 | export const WorkspaceRoutes = lazy(() => | 19 | 19 | new Hono() | 20 | 20 | .get( | 21 | | - "/adaptor", | | 21 | + "/adapter", | 22 | 22 | describeRoute({ | 23 | | - summary: "List workspace adaptors", | 24 | | - description: "List all available workspace adaptors for the current project.", | 25 | | - operationId: "experimental.workspace.adaptor.list", | | 23 | + summary: "List workspace adapters", | | 24 | + description: "List all available workspace adapters for the current project.", | | 25 | + operationId: "experimental.workspace.adapter.list", | 26 | 26 | responses: { | 27 | 27 | 200: { | 28 | | - description: "Workspace adaptors", | | 28 | + description: "Workspace adapters", | 29 | 29 | content: { | 30 | 30 | "application/json": { | 31 | | - schema: resolver(z.array(zodObject(WorkspaceAdaptorEntry))), | | 31 | + schema: resolver(z.array(zodObject(WorkspaceAdapterEntry))), | 32 | 32 | }, | 33 | 33 | }, | 34 | 34 | }, | 35 | 35 | }, | 36 | 36 | }), | 37 | 37 | async (c) => { | 38 | | - return c.json(await listAdaptors(Instance.project.id)) | | 38 | + return c.json(await listAdapters(Instance.project.id)) | 39 | 39 | }, | 40 | 40 | ) | 41 | 41 | .post( | |
|