feat(core): add dummy location filesystem layer

This commit is contained in:
Dax Raad 2026-06-02 01:38:56 -04:00
parent 98b7230c2a
commit 4df3c98c6b
2 changed files with 50 additions and 1 deletions

View File

@ -1,6 +1,9 @@
export * as LocationFileSystem from "./location-filesystem"
import { Context, Effect, Schema } from "effect"
import path from "path"
import { pathToFileURL } from "url"
import { Context, Effect, Layer, Schema } from "effect"
import { Location } from "./location"
import { NonNegativeInt, PositiveInt, RelativePath } from "./schema"
export const ReadInput = Schema.Struct({
@ -63,3 +66,47 @@ export interface Interface {
}
export class Service extends Context.Service<Service, Interface>()("@opencode/v2/LocationFileSystem") {}
export const locationLayer = Layer.effect(
Service,
Effect.gen(function* () {
const location = yield* Location.Service
const entries = [
new Entry({
path: RelativePath.make("README.md"),
uri: pathToFileURL(path.join(location.directory, "README.md")).href,
type: "file",
mime: "text/markdown",
}),
new Entry({
path: RelativePath.make("src"),
uri: pathToFileURL(path.join(location.directory, "src")).href,
type: "directory",
mime: "application/x-directory",
}),
]
return Service.of({
read: Effect.fn("LocationFileSystem.read")(function* () {
return new Content({ type: "text", content: "# opencode\n", mime: "text/markdown" })
}),
list: Effect.fn("LocationFileSystem.list")(function* () {
return entries
}),
find: Effect.fn("LocationFileSystem.find")(function* (input) {
return entries.filter((entry) => input.type === undefined || entry.type === input.type).slice(0, input.limit)
}),
grep: Effect.fn("LocationFileSystem.grep")(function* (input) {
return [
new GrepMatch({
path: RelativePath.make("README.md"),
lines: "# opencode",
line: 1,
offset: 0,
submatches: [{ text: input.pattern, start: 0, end: input.pattern.length }],
}),
].slice(0, input.limit)
}),
})
}),
)

View File

@ -17,6 +17,7 @@ import { Database } from "./database/database"
import { PermissionV2 } from "./permission"
import { PermissionSaved } from "./permission/saved"
import { SessionV2 } from "./session"
import { LocationFileSystem } from "./location-filesystem"
export class LocationServiceMap extends LayerMap.Service<LocationServiceMap>()("@opencode/example/LocationServiceMap", {
lookup: (ref: Location.Ref) => {
@ -30,6 +31,7 @@ export class LocationServiceMap extends LayerMap.Service<LocationServiceMap>()("
AgentV2.locationLayer,
PluginBoot.locationLayer,
PermissionV2.locationLayer,
LocationFileSystem.locationLayer,
).pipe(Layer.provideMerge(location), Layer.fresh)
},
idleTimeToLive: "60 minutes",