global.ts 826 B

123456789101112131415161718192021222324252627
  1. import path from "path"
  2. import { Global } from "@opencode-ai/util/global"
  3. import { Effect, Layer } from "effect"
  4. import { tmpdir } from "./tmpdir"
  5. export const tempGlobalLayer = Layer.unwrap(
  6. Effect.acquireRelease(
  7. Effect.promise(() => tmpdir()),
  8. (tmp) => Effect.promise(() => tmp[Symbol.asyncDispose]()),
  9. ).pipe(
  10. Effect.map((tmp) => {
  11. const data = path.join(tmp.path, "data")
  12. const cache = path.join(tmp.path, "cache")
  13. return Global.layerWith({
  14. home: path.join(tmp.path, "home"),
  15. data,
  16. cache,
  17. config: path.join(tmp.path, "config"),
  18. state: path.join(tmp.path, "state"),
  19. tmp: path.join(tmp.path, "tmp"),
  20. bin: path.join(cache, "bin"),
  21. log: path.join(data, "log"),
  22. repos: path.join(data, "repos"),
  23. })
  24. }),
  25. ),
  26. )