From 2a10e4e89e149b570e73e979922bbc78c0e558a3 Mon Sep 17 00:00:00 2001 From: Kit Langton Date: Mon, 13 Apr 2026 10:32:39 -0400 Subject: [PATCH] refactor(file): decode ripgrep rows with schema --- packages/opencode/src/file/ripgrep.ts | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/packages/opencode/src/file/ripgrep.ts b/packages/opencode/src/file/ripgrep.ts index 1d2d4b56d3..81cd2bf0dc 100644 --- a/packages/opencode/src/file/ripgrep.ts +++ b/packages/opencode/src/file/ripgrep.ts @@ -408,14 +408,6 @@ export namespace Ripgrep { }) { return yield* Effect.scoped( Effect.gen(function* () { - const parse = Effect.fn("Ripgrep.parse")(function* (line: string) { - const row = yield* Effect.try({ - try: () => Result.parse(JSON.parse(line)), - catch: (cause) => new Error(`invalid ripgrep output: ${cause}`), - }) - if (row.type !== "match") return undefined - return row.data - }) const cmd = yield* args({ mode: "search", glob: input.glob, @@ -436,8 +428,11 @@ export namespace Ripgrep { Stream.decodeText(handle.stdout).pipe( Stream.splitLines, Stream.filter((line) => line.length > 0), - Stream.mapEffect(parse), - Stream.filter((item): item is Item => item !== undefined), + Stream.mapEffect((line) => + decode(line).pipe(Effect.mapError((cause) => new Error("invalid ripgrep output", { cause }))), + ), + Stream.filter((row): row is Schema.Schema.Type => row.type === "match"), + Stream.map((row): Item => row.data), Stream.runCollect, Effect.map((chunk) => [...chunk]), ),