Skip to content

Commit ac2f17b

Browse files
committed
feat(core): expose workspace adaptors to plugins
1 parent ce26120 commit ac2f17b

17 files changed

Lines changed: 1773 additions & 42 deletions

File tree

.opencode/opencode.jsonc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
},
1212
},
1313
"mcp": {},
14+
"plugin": ["../folderWorkspacePlugin.ts"],
1415
"tools": {
1516
"github-triage": false,
1617
"github-pr-search": false,

folderWorkspacePlugin.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import type { Plugin } from "@opencode-ai/plugin"
2+
import { mkdir, rm } from "node:fs/promises"
3+
4+
export const FolderWorkspacePlugin: Plugin = async ({ experimental_workspace }) => {
5+
experimental_workspace.register("folder", {
6+
name: 'Folder',
7+
description: 'Create a blank folder',
8+
configure(config) {
9+
const rand = "" + Math.random()
10+
11+
return {
12+
...config,
13+
directory: `/tmp/folder/folder-${rand}`,
14+
}
15+
},
16+
async create(config) {
17+
if (!config.directory) return
18+
await mkdir(config.directory, { recursive: true })
19+
},
20+
async remove(config) {
21+
await rm(config.directory!, { recursive: true, force: true })
22+
},
23+
target(config) {
24+
return {
25+
type: "local",
26+
directory: config.directory!,
27+
}
28+
},
29+
})
30+
31+
return {}
32+
}
33+
34+
export default FolderWorkspacePlugin
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
PRAGMA foreign_keys=OFF;--> statement-breakpoint
2+
CREATE TABLE `__new_workspace` (
3+
`id` text PRIMARY KEY,
4+
`type` text NOT NULL,
5+
`name` text DEFAULT '' NOT NULL,
6+
`branch` text,
7+
`directory` text,
8+
`extra` text,
9+
`project_id` text NOT NULL,
10+
CONSTRAINT `fk_workspace_project_id_project_id_fk` FOREIGN KEY (`project_id`) REFERENCES `project`(`id`) ON DELETE CASCADE
11+
);
12+
--> statement-breakpoint
13+
INSERT INTO `__new_workspace`(`id`, `type`, `branch`, `name`, `directory`, `extra`, `project_id`) SELECT `id`, `type`, `branch`, `name`, `directory`, `extra`, `project_id` FROM `workspace`;--> statement-breakpoint
14+
DROP TABLE `workspace`;--> statement-breakpoint
15+
ALTER TABLE `__new_workspace` RENAME TO `workspace`;--> statement-breakpoint
16+
PRAGMA foreign_keys=ON;

0 commit comments

Comments
 (0)