summaryrefslogtreecommitdiffhomepage
path: root/packages/plugin
diff options
context:
space:
mode:
authorJames Long <[email protected]>2026-04-13 13:33:13 -0400
committerGitHub <[email protected]>2026-04-13 13:33:13 -0400
commitbf50d1c028e973ccc0beffdf568fca417b62f020 (patch)
treecfbbaf0c18554bd442bb0058246480d4c79fe2e6 /packages/plugin
parentb8801dbd22e561e3ddaf83744726d8d98744f255 (diff)
downloadopencode-bf50d1c028e973ccc0beffdf568fca417b62f020.tar.gz
opencode-bf50d1c028e973ccc0beffdf568fca417b62f020.zip
feat(core): expose workspace adaptors to plugins (#21927)
Diffstat (limited to 'packages/plugin')
-rw-r--r--packages/plugin/src/example-workspace.ts34
-rw-r--r--packages/plugin/src/index.ts33
-rw-r--r--packages/plugin/tsconfig.json1
3 files changed, 68 insertions, 0 deletions
diff --git a/packages/plugin/src/example-workspace.ts b/packages/plugin/src/example-workspace.ts
new file mode 100644
index 000000000..925328450
--- /dev/null
+++ b/packages/plugin/src/example-workspace.ts
@@ -0,0 +1,34 @@
+import type { Plugin } from "@opencode-ai/plugin"
+import { mkdir, rm } from "node:fs/promises"
+
+export const FolderWorkspacePlugin: Plugin = async ({ experimental_workspace }) => {
+ experimental_workspace.register("folder", {
+ name: "Folder",
+ description: "Create a blank folder",
+ configure(config) {
+ const rand = "" + Math.random()
+
+ return {
+ ...config,
+ directory: `/tmp/folder/folder-${rand}`,
+ }
+ },
+ async create(config) {
+ if (!config.directory) return
+ await mkdir(config.directory, { recursive: true })
+ },
+ async remove(config) {
+ await rm(config.directory!, { recursive: true, force: true })
+ },
+ target(config) {
+ return {
+ type: "local",
+ directory: config.directory!,
+ }
+ },
+ })
+
+ return {}
+}
+
+export default FolderWorkspacePlugin
diff --git a/packages/plugin/src/index.ts b/packages/plugin/src/index.ts
index 1afb55daa..49d995c6f 100644
--- a/packages/plugin/src/index.ts
+++ b/packages/plugin/src/index.ts
@@ -24,11 +24,44 @@ export type ProviderContext = {
options: Record<string, any>
}
+export type WorkspaceInfo = {
+ id: string
+ type: string
+ name: string
+ branch: string | null
+ directory: string | null
+ extra: unknown | null
+ projectID: string
+}
+
+export type WorkspaceTarget =
+ | {
+ type: "local"
+ directory: string
+ }
+ | {
+ type: "remote"
+ url: string | URL
+ headers?: HeadersInit
+ }
+
+export type WorkspaceAdaptor = {
+ name: string
+ description: string
+ configure(config: WorkspaceInfo): WorkspaceInfo | Promise<WorkspaceInfo>
+ create(config: WorkspaceInfo, from?: WorkspaceInfo): Promise<void>
+ remove(config: WorkspaceInfo): Promise<void>
+ target(config: WorkspaceInfo): WorkspaceTarget | Promise<WorkspaceTarget>
+}
+
export type PluginInput = {
client: ReturnType<typeof createOpencodeClient>
project: Project
directory: string
worktree: string
+ experimental_workspace: {
+ register(type: string, adaptor: WorkspaceAdaptor): void
+ }
serverUrl: URL
$: BunShell
}
diff --git a/packages/plugin/tsconfig.json b/packages/plugin/tsconfig.json
index 117381878..f8e9370d8 100644
--- a/packages/plugin/tsconfig.json
+++ b/packages/plugin/tsconfig.json
@@ -2,6 +2,7 @@
"$schema": "https://json.schemastore.org/tsconfig.json",
"extends": "@tsconfig/node22/tsconfig.json",
"compilerOptions": {
+ "rootDir": "src",
"outDir": "dist",
"module": "nodenext",
"declaration": true,