From 98b7230c2a69d150376e431f67ef0b2ceec67b57 Mon Sep 17 00:00:00 2001 From: Dax Raad Date: Tue, 2 Jun 2026 01:37:53 -0400 Subject: [PATCH] feat(core): add location filesystem contract --- packages/core/src/location-filesystem.ts | 65 ++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 packages/core/src/location-filesystem.ts diff --git a/packages/core/src/location-filesystem.ts b/packages/core/src/location-filesystem.ts new file mode 100644 index 000000000..3869c5308 --- /dev/null +++ b/packages/core/src/location-filesystem.ts @@ -0,0 +1,65 @@ +export * as LocationFileSystem from "./location-filesystem" + +import { Context, Effect, Schema } from "effect" +import { NonNegativeInt, PositiveInt, RelativePath } from "./schema" + +export const ReadInput = Schema.Struct({ + path: RelativePath, +}) +export type ReadInput = typeof ReadInput.Type + +export class Content extends Schema.Class("LocationFileSystem.Content")({ + type: Schema.Literals(["text", "binary"]), + content: Schema.String, + encoding: Schema.Literal("base64").pipe(Schema.optional), + mime: Schema.String.pipe(Schema.optional), +}) {} + +export const ListInput = Schema.Struct({ + path: RelativePath.pipe(Schema.optional), +}) +export type ListInput = typeof ListInput.Type + +export class Entry extends Schema.Class("LocationFileSystem.Entry")({ + path: RelativePath, + uri: Schema.String, + type: Schema.Literals(["file", "directory"]), + mime: Schema.String, +}) {} + +export const FindInput = Schema.Struct({ + query: Schema.String, + type: Schema.Literals(["file", "directory"]).pipe(Schema.optional), + limit: PositiveInt.pipe(Schema.optional), +}) +export type FindInput = typeof FindInput.Type + +export const GrepInput = Schema.Struct({ + pattern: Schema.String, + include: Schema.String.pipe(Schema.optional), + limit: PositiveInt.pipe(Schema.optional), +}) +export type GrepInput = typeof GrepInput.Type + +export class GrepMatch extends Schema.Class("LocationFileSystem.GrepMatch")({ + path: RelativePath, + lines: Schema.String, + line: PositiveInt, + offset: NonNegativeInt, + submatches: Schema.Array( + Schema.Struct({ + text: Schema.String, + start: NonNegativeInt, + end: NonNegativeInt, + }), + ), +}) {} + +export interface Interface { + readonly read: (input: ReadInput) => Effect.Effect + readonly list: (input?: ListInput) => Effect.Effect + readonly find: (input: FindInput) => Effect.Effect + readonly grep: (input: GrepInput) => Effect.Effect +} + +export class Service extends Context.Service()("@opencode/v2/LocationFileSystem") {}