2025-10-22 00:53:09 +00:00
|
|
|
import { EOL } from "os"
|
2026-05-02 23:22:51 +00:00
|
|
|
import { Effect } from "effect"
|
2025-07-01 16:06:38 +00:00
|
|
|
import { File } from "../../../file"
|
2026-04-16 01:22:18 +00:00
|
|
|
import { Ripgrep } from "@/file/ripgrep"
|
2026-05-02 23:22:51 +00:00
|
|
|
import { effectCmd } from "../../effect-cmd"
|
2025-07-01 16:06:38 +00:00
|
|
|
import { cmd } from "../cmd"
|
2026-05-02 23:22:51 +00:00
|
|
|
import { InstanceRef } from "@/effect/instance-ref"
|
|
|
|
|
import { InstanceStore } from "@/project/instance-store"
|
2025-07-01 16:06:38 +00:00
|
|
|
|
2026-05-02 23:22:51 +00:00
|
|
|
const FileSearchCommand = effectCmd({
|
2025-10-01 07:37:01 +00:00
|
|
|
command: "search <query>",
|
2026-01-08 15:42:12 +00:00
|
|
|
describe: "search files by query",
|
2025-10-01 07:37:01 +00:00
|
|
|
builder: (yargs) =>
|
|
|
|
|
yargs.positional("query", {
|
|
|
|
|
type: "string",
|
|
|
|
|
demandOption: true,
|
|
|
|
|
description: "Search query",
|
|
|
|
|
}),
|
2026-05-02 23:22:51 +00:00
|
|
|
handler: Effect.fn("Cli.debug.file.search")(function* (args) {
|
|
|
|
|
const ctx = yield* InstanceRef
|
|
|
|
|
if (!ctx) return
|
|
|
|
|
const store = yield* InstanceStore.Service
|
|
|
|
|
return yield* Effect.gen(function* () {
|
|
|
|
|
const results = yield* File.Service.use((svc) => svc.search({ query: args.query }))
|
2025-10-28 20:38:08 +00:00
|
|
|
process.stdout.write(results.join(EOL) + EOL)
|
2026-05-02 23:22:51 +00:00
|
|
|
}).pipe(Effect.ensuring(store.dispose(ctx)))
|
|
|
|
|
}),
|
2025-10-01 07:37:01 +00:00
|
|
|
})
|
|
|
|
|
|
2026-05-02 23:22:51 +00:00
|
|
|
const FileReadCommand = effectCmd({
|
2025-07-01 16:06:38 +00:00
|
|
|
command: "read <path>",
|
2026-01-08 15:42:12 +00:00
|
|
|
describe: "read file contents as JSON",
|
2025-07-01 16:06:38 +00:00
|
|
|
builder: (yargs) =>
|
|
|
|
|
yargs.positional("path", {
|
|
|
|
|
type: "string",
|
|
|
|
|
demandOption: true,
|
|
|
|
|
description: "File path to read",
|
|
|
|
|
}),
|
2026-05-02 23:22:51 +00:00
|
|
|
handler: Effect.fn("Cli.debug.file.read")(function* (args) {
|
|
|
|
|
const ctx = yield* InstanceRef
|
|
|
|
|
if (!ctx) return
|
|
|
|
|
const store = yield* InstanceStore.Service
|
|
|
|
|
return yield* Effect.gen(function* () {
|
|
|
|
|
const content = yield* File.Service.use((svc) => svc.read(args.path))
|
2025-10-28 20:38:08 +00:00
|
|
|
process.stdout.write(JSON.stringify(content, null, 2) + EOL)
|
2026-05-02 23:22:51 +00:00
|
|
|
}).pipe(Effect.ensuring(store.dispose(ctx)))
|
|
|
|
|
}),
|
2025-07-01 16:06:38 +00:00
|
|
|
})
|
2025-07-02 00:39:43 +00:00
|
|
|
|
2026-05-02 23:22:51 +00:00
|
|
|
const FileStatusCommand = effectCmd({
|
2025-07-02 00:39:43 +00:00
|
|
|
command: "status",
|
2026-01-08 15:42:12 +00:00
|
|
|
describe: "show file status information",
|
2025-07-02 00:39:43 +00:00
|
|
|
builder: (yargs) => yargs,
|
2026-05-02 23:22:51 +00:00
|
|
|
handler: Effect.fn("Cli.debug.file.status")(function* () {
|
|
|
|
|
const ctx = yield* InstanceRef
|
|
|
|
|
if (!ctx) return
|
|
|
|
|
const store = yield* InstanceStore.Service
|
|
|
|
|
return yield* Effect.gen(function* () {
|
|
|
|
|
const status = yield* File.Service.use((svc) => svc.status())
|
2025-10-28 20:38:08 +00:00
|
|
|
process.stdout.write(JSON.stringify(status, null, 2) + EOL)
|
2026-05-02 23:22:51 +00:00
|
|
|
}).pipe(Effect.ensuring(store.dispose(ctx)))
|
|
|
|
|
}),
|
2025-07-02 00:39:43 +00:00
|
|
|
})
|
|
|
|
|
|
2026-05-02 23:22:51 +00:00
|
|
|
const FileListCommand = effectCmd({
|
2025-08-27 20:27:49 +00:00
|
|
|
command: "list <path>",
|
2026-01-08 15:42:12 +00:00
|
|
|
describe: "list files in a directory",
|
2025-08-27 20:27:49 +00:00
|
|
|
builder: (yargs) =>
|
|
|
|
|
yargs.positional("path", {
|
|
|
|
|
type: "string",
|
|
|
|
|
demandOption: true,
|
|
|
|
|
description: "File path to list",
|
|
|
|
|
}),
|
2026-05-02 23:22:51 +00:00
|
|
|
handler: Effect.fn("Cli.debug.file.list")(function* (args) {
|
|
|
|
|
const ctx = yield* InstanceRef
|
|
|
|
|
if (!ctx) return
|
|
|
|
|
const store = yield* InstanceStore.Service
|
|
|
|
|
return yield* Effect.gen(function* () {
|
|
|
|
|
const files = yield* File.Service.use((svc) => svc.list(args.path))
|
2025-10-28 20:38:08 +00:00
|
|
|
process.stdout.write(JSON.stringify(files, null, 2) + EOL)
|
2026-05-02 23:22:51 +00:00
|
|
|
}).pipe(Effect.ensuring(store.dispose(ctx)))
|
|
|
|
|
}),
|
2025-08-27 20:27:49 +00:00
|
|
|
})
|
|
|
|
|
|
2026-05-02 23:22:51 +00:00
|
|
|
const FileTreeCommand = effectCmd({
|
2025-11-17 15:57:18 +00:00
|
|
|
command: "tree [dir]",
|
2026-01-08 15:42:12 +00:00
|
|
|
describe: "show directory tree",
|
2025-11-17 15:57:18 +00:00
|
|
|
builder: (yargs) =>
|
|
|
|
|
yargs.positional("dir", {
|
|
|
|
|
type: "string",
|
|
|
|
|
description: "Directory to tree",
|
|
|
|
|
default: process.cwd(),
|
|
|
|
|
}),
|
2026-05-02 23:22:51 +00:00
|
|
|
handler: Effect.fn("Cli.debug.file.tree")(function* (args) {
|
|
|
|
|
const ctx = yield* InstanceRef
|
|
|
|
|
if (!ctx) return
|
|
|
|
|
const store = yield* InstanceStore.Service
|
|
|
|
|
return yield* Effect.gen(function* () {
|
|
|
|
|
const tree = yield* Effect.orDie(Ripgrep.Service.use((svc) => svc.tree({ cwd: args.dir, limit: 200 })))
|
2026-04-16 01:22:18 +00:00
|
|
|
console.log(JSON.stringify(tree, null, 2))
|
2026-05-02 23:22:51 +00:00
|
|
|
}).pipe(Effect.ensuring(store.dispose(ctx)))
|
|
|
|
|
}),
|
2025-11-17 15:57:18 +00:00
|
|
|
})
|
|
|
|
|
|
2025-07-02 00:39:43 +00:00
|
|
|
export const FileCommand = cmd({
|
|
|
|
|
command: "file",
|
2026-01-08 15:42:12 +00:00
|
|
|
describe: "file system debugging utilities",
|
2025-08-27 20:27:49 +00:00
|
|
|
builder: (yargs) =>
|
2025-10-01 07:37:01 +00:00
|
|
|
yargs
|
|
|
|
|
.command(FileReadCommand)
|
|
|
|
|
.command(FileStatusCommand)
|
|
|
|
|
.command(FileListCommand)
|
|
|
|
|
.command(FileSearchCommand)
|
2025-11-17 15:57:18 +00:00
|
|
|
.command(FileTreeCommand)
|
2025-10-01 07:37:01 +00:00
|
|
|
.demandCommand(),
|
2025-07-02 00:39:43 +00:00
|
|
|
async handler() {},
|
|
|
|
|
})
|