refactor(core): simplify location filesystem (#31545)

This commit is contained in:
Dax
2026-06-09 14:28:45 -04:00
committed by GitHub
parent 0777cf1ccf
commit 132ef57272
73 changed files with 1054 additions and 1422 deletions

View File

@@ -1,6 +1,6 @@
import { FileSystem } from "@opencode-ai/core/filesystem"
import { Location } from "@opencode-ai/core/location"
import { RelativePath } from "@opencode-ai/core/schema"
import { PositiveInt, RelativePath } from "@opencode-ai/core/schema"
import { Schema } from "effect"
import { HttpApiEndpoint, HttpApiGroup, OpenApi } from "effect/unstable/httpapi"
import { LocationQuery, locationQueryOpenApi, LocationMiddleware } from "./location"
@@ -15,6 +15,13 @@ const ListQuery = Schema.Struct({
path: RelativePath.pipe(Schema.optional),
})
const FindQuery = Schema.Struct({
...LocationQuery.fields,
query: FileSystem.FindInput.fields.query,
type: FileSystem.FindInput.fields.type,
limit: Schema.NumberFromString.pipe(Schema.decodeTo(PositiveInt), Schema.optional),
})
export const FileSystemGroup = HttpApiGroup.make("server.fs")
.add(
HttpApiEndpoint.get("fs.read", "/api/fs/read", {
@@ -44,6 +51,20 @@ export const FileSystemGroup = HttpApiGroup.make("server.fs")
}),
),
)
.add(
HttpApiEndpoint.get("fs.find", "/api/fs/find", {
query: FindQuery,
success: Location.response(Schema.Array(FileSystem.Entry)),
})
.annotateMerge(locationQueryOpenApi)
.annotateMerge(
OpenApi.annotations({
identifier: "v2.fs.find",
summary: "Find files",
description: "Find recursively ranked filesystem entries relative to the requested location.",
}),
),
)
.annotateMerge(
OpenApi.annotations({
title: "filesystem",

View File

@@ -5,9 +5,10 @@ import { Api } from "../api"
import { response } from "../groups/location"
export const FileSystemHandler = HttpApiBuilder.group(Api, "server.fs", (handlers) =>
Effect.gen(function* () {
return handlers
Effect.succeed(
handlers
.handle("fs.read", (ctx) => response(FileSystem.Service.use((fs) => fs.read(ctx.query))))
.handle("fs.list", (ctx) => response(FileSystem.Service.use((fs) => fs.list(ctx.query))))
}),
.handle("fs.find", (ctx) => response(FileSystem.Service.use((fs) => fs.find(ctx.query)))),
),
)