diff options
| author | Dax <[email protected]> | 2026-02-18 19:29:11 -0500 |
|---|---|---|
| committer | GitHub <[email protected]> | 2026-02-18 19:29:11 -0500 |
| commit | 14c0989411a408c680404b7313382b54dee8ca07 (patch) | |
| tree | ef8d8c2e95db466696318737706ae4463d25b4c8 | |
| parent | 36bc07a5af1c5a98bf1f9e6c1913ee720286ca6d (diff) | |
| download | opencode-14c0989411a408c680404b7313382b54dee8ca07.tar.gz opencode-14c0989411a408c680404b7313382b54dee8ca07.zip | |
refactor: migrate src/tool/read.ts from Bun.file() to Filesystem module (#14118)
| -rw-r--r-- | packages/opencode/src/tool/read.ts | 15 |
1 files changed, 7 insertions, 8 deletions
diff --git a/packages/opencode/src/tool/read.ts b/packages/opencode/src/tool/read.ts index 80ca95900..c981ac16e 100644 --- a/packages/opencode/src/tool/read.ts +++ b/packages/opencode/src/tool/read.ts @@ -10,6 +10,7 @@ import DESCRIPTION from "./read.txt" import { Instance } from "../project/instance" import { assertExternalDirectory } from "./external-directory" import { InstructionPrompt } from "../session/instruction" +import { Filesystem } from "../util/filesystem" const DEFAULT_READ_LIMIT = 2000 const MAX_LINE_LENGTH = 2000 @@ -34,8 +35,7 @@ export const ReadTool = Tool.define("read", { } const title = path.relative(Instance.worktree, filepath) - const file = Bun.file(filepath) - const stat = await file.stat().catch(() => undefined) + const stat = Filesystem.stat(filepath) await assertExternalDirectory(ctx, filepath, { bypass: Boolean(ctx.extra?.["bypassCwdCheck"]), @@ -118,11 +118,10 @@ export const ReadTool = Tool.define("read", { const instructions = await InstructionPrompt.resolve(ctx.messages, filepath, ctx.messageID) // Exclude SVG (XML-based) and vnd.fastbidsheet (.fbs extension, commonly FlatBuffers schema files) - const isImage = - file.type.startsWith("image/") && file.type !== "image/svg+xml" && file.type !== "image/vnd.fastbidsheet" - const isPdf = file.type === "application/pdf" + const mime = Filesystem.mimeType(filepath) + const isImage = mime.startsWith("image/") && mime !== "image/svg+xml" && mime !== "image/vnd.fastbidsheet" + const isPdf = mime === "application/pdf" if (isImage || isPdf) { - const mime = file.type const msg = `${isImage ? "Image" : "PDF"} read successfully` return { title, @@ -136,13 +135,13 @@ export const ReadTool = Tool.define("read", { { type: "file", mime, - url: `data:${mime};base64,${Buffer.from(await file.bytes()).toString("base64")}`, + url: `data:${mime};base64,${Buffer.from(await Filesystem.readBytes(filepath)).toString("base64")}`, }, ], } } - const isBinary = await isBinaryFile(filepath, stat.size) + const isBinary = await isBinaryFile(filepath, Number(stat.size)) if (isBinary) throw new Error(`Cannot read binary file: ${filepath}`) const stream = createReadStream(filepath, { encoding: "utf8" }) |
