global.ts 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. import path from "path"
  2. import { xdgData, xdgCache, xdgConfig, xdgState } from "xdg-basedir"
  3. import os from "os"
  4. import { Context, Effect, Layer } from "effect"
  5. export namespace Global {
  6. export class Service extends Context.Service<Service, Interface>()("@opencode/Global") {}
  7. export interface Interface {
  8. readonly home: string
  9. readonly data: string
  10. readonly cache: string
  11. readonly config: string
  12. readonly state: string
  13. readonly bin: string
  14. readonly log: string
  15. }
  16. export const layer = Layer.effect(
  17. Service,
  18. Effect.gen(function* () {
  19. const app = "opencode"
  20. const home = process.env.OPENCODE_TEST_HOME ?? os.homedir()
  21. const data = path.join(xdgData!, app)
  22. const cache = path.join(xdgCache!, app)
  23. const cfg = path.join(xdgConfig!, app)
  24. const state = path.join(xdgState!, app)
  25. const bin = path.join(cache, "bin")
  26. const log = path.join(data, "log")
  27. return Service.of({
  28. home,
  29. data,
  30. cache,
  31. config: cfg,
  32. state,
  33. bin,
  34. log,
  35. })
  36. }),
  37. )
  38. }