refactor(core): unify filesystem search service (#31566)
This commit is contained in:
@@ -2,7 +2,6 @@ import { EOL } from "os"
|
||||
import { Effect } from "effect"
|
||||
import { FileSystem } from "@opencode-ai/core/filesystem"
|
||||
import { LocationServiceMap } from "@opencode-ai/core/location-layer"
|
||||
import { Search } from "@opencode-ai/core/filesystem/search"
|
||||
import { AbsolutePath, RelativePath } from "@opencode-ai/core/schema"
|
||||
import { effectCmd } from "../../effect-cmd"
|
||||
import { cmd } from "../cmd"
|
||||
@@ -23,7 +22,11 @@ const FileSearchCommand = effectCmd({
|
||||
description: "Search query",
|
||||
}),
|
||||
handler: Effect.fn("Cli.debug.file.search")(function* (args) {
|
||||
const results = yield* filesystem(FileSystem.Service.use((svc) => svc.find({ query: args.query })))
|
||||
const results = yield* Effect.orDie(
|
||||
filesystem(
|
||||
FileSystem.Service.use((svc) => svc.find({ query: args.query })),
|
||||
),
|
||||
)
|
||||
process.stdout.write(results.map((item) => item.path).join(EOL) + EOL)
|
||||
}),
|
||||
})
|
||||
@@ -58,21 +61,6 @@ const FileListCommand = effectCmd({
|
||||
}),
|
||||
})
|
||||
|
||||
const FileTreeCommand = effectCmd({
|
||||
command: "tree [dir]",
|
||||
describe: "show directory tree",
|
||||
builder: (yargs) =>
|
||||
yargs.positional("dir", {
|
||||
type: "string",
|
||||
description: "Directory to tree",
|
||||
default: process.cwd(),
|
||||
}),
|
||||
handler: Effect.fn("Cli.debug.file.tree")(function* (args) {
|
||||
const tree = yield* Effect.orDie(Search.Service.use((svc) => svc.tree({ cwd: args.dir, limit: 200 })))
|
||||
console.log(JSON.stringify(tree, null, 2))
|
||||
}),
|
||||
})
|
||||
|
||||
export const FileCommand = cmd({
|
||||
command: "file",
|
||||
describe: "file system debugging utilities",
|
||||
@@ -81,7 +69,6 @@ export const FileCommand = cmd({
|
||||
.command(FileReadCommand)
|
||||
.command(FileListCommand)
|
||||
.command(FileSearchCommand)
|
||||
.command(FileTreeCommand)
|
||||
.demandCommand(),
|
||||
async handler() {},
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user