c64a4b7557
Co-authored-by: Brendan Allan <14191578+Brendonovich@users.noreply.github.com> Co-authored-by: opencode-agent[bot] <opencode-agent[bot]@users.noreply.github.com> Co-authored-by: Affan Ali <93028901+affanali2k3@users.noreply.github.com> Co-authored-by: affanali2k3 <affanalikhanxx@gmail.com> Co-authored-by: Frank <frank@anoma.ly> Co-authored-by: opencode-agent[bot] <219766164+opencode-agent[bot]@users.noreply.github.com> Co-authored-by: James Long <longster@gmail.com> Co-authored-by: Aiden Cline <63023139+rekram1-node@users.noreply.github.com> Co-authored-by: Jay V <air@live.ca> Co-authored-by: Dax Raad <d@ironbay.co> Co-authored-by: Aarav Sareen <96787824+arvsrn@users.noreply.github.com> Co-authored-by: OpeOginni <107570612+OpeOginni@users.noreply.github.com> Co-authored-by: Luke Parker <10430890+Hona@users.noreply.github.com> Co-authored-by: Ben Guthrie <benjee.012@gmail.com> Co-authored-by: Dax <mail@thdxr.com> Co-authored-by: Filip <34747899+neriousy@users.noreply.github.com>
74 lines
2.5 KiB
TypeScript
74 lines
2.5 KiB
TypeScript
import { EOL } from "os"
|
|
import { Effect } from "effect"
|
|
import { FileSystem } from "@opencode-ai/core/filesystem"
|
|
import { LocationServiceMap, locationServiceMapLayer } from "@opencode-ai/core/location-services"
|
|
import { Location } from "@opencode-ai/core/location"
|
|
import { AbsolutePath, RelativePath } from "@opencode-ai/core/schema"
|
|
import { effectCmd } from "../../effect-cmd"
|
|
import { cmd } from "../cmd"
|
|
|
|
const filesystem = <A, E, R>(effect: Effect.Effect<A, E, R>) =>
|
|
effect.pipe(
|
|
Effect.provide(LocationServiceMap.Service.get(Location.Ref.make({ directory: AbsolutePath.make(process.cwd()) }))),
|
|
Effect.provide(locationServiceMapLayer),
|
|
)
|
|
|
|
const FileSearchCommand = effectCmd({
|
|
command: "search <query>",
|
|
describe: "search files by query",
|
|
builder: (yargs) =>
|
|
yargs.positional("query", {
|
|
type: "string",
|
|
demandOption: true,
|
|
description: "Search query",
|
|
}),
|
|
handler: Effect.fn("Cli.debug.file.search")(function* (args) {
|
|
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)
|
|
}),
|
|
})
|
|
|
|
const FileReadCommand = effectCmd({
|
|
command: "read <path>",
|
|
describe: "read file contents as JSON",
|
|
builder: (yargs) =>
|
|
yargs.positional("path", {
|
|
type: "string",
|
|
demandOption: true,
|
|
description: "File path to read",
|
|
}),
|
|
handler: Effect.fn("Cli.debug.file.read")(function* (args) {
|
|
const file = yield* filesystem(FileSystem.Service.use((svc) => svc.read({ path: RelativePath.make(args.path) })))
|
|
process.stdout.write(
|
|
JSON.stringify(
|
|
{ content: Buffer.from(file.content).toString("base64"), encoding: "base64", mime: file.mime },
|
|
null,
|
|
2,
|
|
) + EOL,
|
|
)
|
|
}),
|
|
})
|
|
|
|
const FileListCommand = effectCmd({
|
|
command: "list <path>",
|
|
describe: "list files in a directory",
|
|
builder: (yargs) =>
|
|
yargs.positional("path", {
|
|
type: "string",
|
|
demandOption: true,
|
|
description: "File path to list",
|
|
}),
|
|
handler: Effect.fn("Cli.debug.file.list")(function* (args) {
|
|
const files = yield* filesystem(FileSystem.Service.use((svc) => svc.list({ path: RelativePath.make(args.path) })))
|
|
process.stdout.write(JSON.stringify(files, null, 2) + EOL)
|
|
}),
|
|
})
|
|
|
|
export const FileCommand = cmd({
|
|
command: "file",
|
|
describe: "file system debugging utilities",
|
|
builder: (yargs) =>
|
|
yargs.command(FileReadCommand).command(FileListCommand).command(FileSearchCommand).demandCommand(),
|
|
async handler() {},
|
|
})
|