From 4df3c98c6b26102644be93207a6cf65c84bd4acd Mon Sep 17 00:00:00 2001 From: Dax Raad Date: Tue, 2 Jun 2026 01:38:56 -0400 Subject: [PATCH] feat(core): add dummy location filesystem layer --- packages/core/src/location-filesystem.ts | 49 +++++++++++++++++++++++- packages/core/src/location-layer.ts | 2 + 2 files changed, 50 insertions(+), 1 deletion(-) diff --git a/packages/core/src/location-filesystem.ts b/packages/core/src/location-filesystem.ts index 3869c5308..2acec8e02 100644 --- a/packages/core/src/location-filesystem.ts +++ b/packages/core/src/location-filesystem.ts @@ -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()("@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) + }), + }) + }), +) diff --git a/packages/core/src/location-layer.ts b/packages/core/src/location-layer.ts index 43b05a596..c4d9ea544 100644 --- a/packages/core/src/location-layer.ts +++ b/packages/core/src/location-layer.ts @@ -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()("@opencode/example/LocationServiceMap", { lookup: (ref: Location.Ref) => { @@ -30,6 +31,7 @@ export class LocationServiceMap extends LayerMap.Service()(" AgentV2.locationLayer, PluginBoot.locationLayer, PermissionV2.locationLayer, + LocationFileSystem.locationLayer, ).pipe(Layer.provideMerge(location), Layer.fresh) }, idleTimeToLive: "60 minutes",