example-workspace.ts 849 B

12345678910111213141516171819202122232425262728293031323334
  1. import type { Plugin } from "@opencode-ai/plugin"
  2. import { mkdir, rm } from "node:fs/promises"
  3. export const FolderWorkspacePlugin: Plugin = async ({ experimental_workspace }) => {
  4. experimental_workspace.register("folder", {
  5. name: "Folder",
  6. description: "Create a blank folder",
  7. configure(config) {
  8. const rand = "" + Math.random()
  9. return {
  10. ...config,
  11. directory: `/tmp/folder/folder-${rand}`,
  12. }
  13. },
  14. async create(config) {
  15. if (!config.directory) return
  16. await mkdir(config.directory, { recursive: true })
  17. },
  18. async remove(config) {
  19. await rm(config.directory!, { recursive: true, force: true })
  20. },
  21. target(config) {
  22. return {
  23. type: "local",
  24. directory: config.directory!,
  25. }
  26. },
  27. })
  28. return {}
  29. }
  30. export default FolderWorkspacePlugin