Skip to content

Commit e750e32

Browse files
committed
refactor: remove makeRuntime facades from File and Ripgrep
Delete leftover facade exports and makeRuntime from file/index.ts and file/ripgrep.ts. Migrate all callers (debug CLI commands, tests) to use AppRuntime.runPromise with Service.use directly. Also simplifies debug/file.ts handlers to drop unnecessary Effect.gen wrappers, adds missing bootstrap() to FileTreeCommand, and consolidates ripgrep tests into a single describe block using Service.use.
1 parent bddf830 commit e750e32

5 files changed

Lines changed: 130 additions & 213 deletions

File tree

packages/opencode/src/cli/cmd/debug/file.ts

Lines changed: 9 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
import { EOL } from "os"
2-
import { Effect } from "effect"
32
import { AppRuntime } from "@/effect/app-runtime"
43
import { File } from "../../../file"
4+
import { Ripgrep } from "@/file/ripgrep"
55
import { bootstrap } from "../../bootstrap"
66
import { cmd } from "../cmd"
7-
import { Ripgrep } from "@/file/ripgrep"
87

98
const FileSearchCommand = cmd({
109
command: "search <query>",
@@ -17,11 +16,7 @@ const FileSearchCommand = cmd({
1716
}),
1817
async handler(args) {
1918
await bootstrap(process.cwd(), async () => {
20-
const results = await AppRuntime.runPromise(
21-
Effect.gen(function* () {
22-
return yield* File.Service.use((svc) => svc.search({ query: args.query }))
23-
}),
24-
)
19+
const results = await AppRuntime.runPromise(File.Service.use((svc) => svc.search({ query: args.query })))
2520
process.stdout.write(results.join(EOL) + EOL)
2621
})
2722
},
@@ -38,11 +33,7 @@ const FileReadCommand = cmd({
3833
}),
3934
async handler(args) {
4035
await bootstrap(process.cwd(), async () => {
41-
const content = await AppRuntime.runPromise(
42-
Effect.gen(function* () {
43-
return yield* File.Service.use((svc) => svc.read(args.path))
44-
}),
45-
)
36+
const content = await AppRuntime.runPromise(File.Service.use((svc) => svc.read(args.path)))
4637
process.stdout.write(JSON.stringify(content, null, 2) + EOL)
4738
})
4839
},
@@ -54,11 +45,7 @@ const FileStatusCommand = cmd({
5445
builder: (yargs) => yargs,
5546
async handler() {
5647
await bootstrap(process.cwd(), async () => {
57-
const status = await AppRuntime.runPromise(
58-
Effect.gen(function* () {
59-
return yield* File.Service.use((svc) => svc.status())
60-
}),
61-
)
48+
const status = await AppRuntime.runPromise(File.Service.use((svc) => svc.status()))
6249
process.stdout.write(JSON.stringify(status, null, 2) + EOL)
6350
})
6451
},
@@ -75,11 +62,7 @@ const FileListCommand = cmd({
7562
}),
7663
async handler(args) {
7764
await bootstrap(process.cwd(), async () => {
78-
const files = await AppRuntime.runPromise(
79-
Effect.gen(function* () {
80-
return yield* File.Service.use((svc) => svc.list(args.path))
81-
}),
82-
)
65+
const files = await AppRuntime.runPromise(File.Service.use((svc) => svc.list(args.path)))
8366
process.stdout.write(JSON.stringify(files, null, 2) + EOL)
8467
})
8568
},
@@ -95,8 +78,10 @@ const FileTreeCommand = cmd({
9578
default: process.cwd(),
9679
}),
9780
async handler(args) {
98-
const files = await Ripgrep.tree({ cwd: args.dir, limit: 200 })
99-
console.log(JSON.stringify(files, null, 2))
81+
await bootstrap(process.cwd(), async () => {
82+
const tree = await AppRuntime.runPromise(Ripgrep.Service.use((svc) => svc.tree({ cwd: args.dir, limit: 200 })))
83+
console.log(JSON.stringify(tree, null, 2))
84+
})
10085
},
10186
})
10287

packages/opencode/src/cli/cmd/debug/ripgrep.ts

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { EOL } from "os"
2+
import { Effect, Stream } from "effect"
23
import { AppRuntime } from "../../../effect/app-runtime"
34
import { Ripgrep } from "../../../file/ripgrep"
45
import { Instance } from "../../../project/instance"
@@ -21,7 +22,10 @@ const TreeCommand = cmd({
2122
}),
2223
async handler(args) {
2324
await bootstrap(process.cwd(), async () => {
24-
process.stdout.write((await Ripgrep.tree({ cwd: Instance.directory, limit: args.limit })) + EOL)
25+
const tree = await AppRuntime.runPromise(
26+
Ripgrep.Service.use((svc) => svc.tree({ cwd: Instance.directory, limit: args.limit })),
27+
)
28+
process.stdout.write(tree + EOL)
2529
})
2630
},
2731
})
@@ -45,14 +49,21 @@ const FilesCommand = cmd({
4549
}),
4650
async handler(args) {
4751
await bootstrap(process.cwd(), async () => {
48-
const files: string[] = []
49-
for await (const file of await Ripgrep.files({
50-
cwd: Instance.directory,
51-
glob: args.glob ? [args.glob] : undefined,
52-
})) {
53-
files.push(file)
54-
if (args.limit && files.length >= args.limit) break
55-
}
52+
const files = await AppRuntime.runPromise(
53+
Effect.gen(function* () {
54+
const rg = yield* Ripgrep.Service
55+
return yield* rg
56+
.files({
57+
cwd: Instance.directory,
58+
glob: args.glob ? [args.glob] : undefined,
59+
})
60+
.pipe(
61+
Stream.take(args.limit ?? Infinity),
62+
Stream.runCollect,
63+
Effect.map((c) => [...c]),
64+
)
65+
}),
66+
)
5667
process.stdout.write(files.join(EOL) + EOL)
5768
})
5869
},

packages/opencode/src/file/index.ts

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { BusEvent } from "@/bus/bus-event"
22
import { InstanceState } from "@/effect/instance-state"
3-
import { makeRuntime } from "@/effect/run-service"
3+
44
import { AppFileSystem } from "@/filesystem"
55
import { Git } from "@/git"
66
import { Effect, Layer, Context } from "effect"
@@ -653,26 +653,4 @@ export namespace File {
653653
Layer.provide(AppFileSystem.defaultLayer),
654654
Layer.provide(Git.defaultLayer),
655655
)
656-
657-
const { runPromise } = makeRuntime(Service, defaultLayer)
658-
659-
export function init() {
660-
return runPromise((svc) => svc.init())
661-
}
662-
663-
export async function status() {
664-
return runPromise((svc) => svc.status())
665-
}
666-
667-
export async function read(file: string): Promise<Content> {
668-
return runPromise((svc) => svc.read(file))
669-
}
670-
671-
export async function list(dir?: string) {
672-
return runPromise((svc) => svc.list(dir))
673-
}
674-
675-
export async function search(input: { query: string; limit?: number; dirs?: boolean; type?: "file" | "directory" }) {
676-
return runPromise((svc) => svc.search(input))
677-
}
678656
}

packages/opencode/src/file/ripgrep.ts

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { fileURLToPath } from "url"
44
import z from "zod"
55
import { Cause, Context, Effect, Layer, Queue, Stream } from "effect"
66
import { ripgrep } from "ripgrep"
7-
import { makeRuntime } from "@/effect/run-service"
7+
88
import { Filesystem } from "@/util/filesystem"
99
import { Log } from "@/util/log"
1010

@@ -572,18 +572,4 @@ export namespace Ripgrep {
572572
)
573573

574574
export const defaultLayer = layer
575-
576-
const { runPromise } = makeRuntime(Service, defaultLayer)
577-
578-
export function files(input: FilesInput) {
579-
return runPromise((svc) => Stream.toAsyncIterableEffect(svc.files(input)))
580-
}
581-
582-
export function tree(input: TreeInput) {
583-
return runPromise((svc) => svc.tree(input))
584-
}
585-
586-
export function search(input: SearchInput) {
587-
return runPromise((svc) => svc.search(input))
588-
}
589575
}

0 commit comments

Comments
 (0)