The open source coding agent.
TypeScript
refactor: migrate remaining tool files from Bun.file() to Filesystem/stat modules (#14121)
Daxbd52ce5640f0
diff --git a/packages/opencode/src/tool/glob.ts b/packages/opencode/src/tool/glob.tsindex 9df1eedca44..a2611246c66 100644--- a/packages/opencode/src/tool/glob.ts+++ b/packages/opencode/src/tool/glob.ts@@ -1,6 +1,7 @@import z from "zod"import path from "path"import { Tool } from "./tool"+import { Filesystem } from "../util/filesystem"import DESCRIPTION from "./glob.txt"import { Ripgrep } from "../file/ripgrep"import { Instance } from "../project/instance"@@ -45,10 +46,7 @@ export const GlobTool = Tool.define("glob", {break}const full = path.resolve(search, file)- const stats = await Bun.file(full)- .stat()- .then((x) => x.mtime.getTime())- .catch(() => 0)+ const stats = Filesystem.stat(full)?.mtime.getTime() ?? 0files.push({path: full,mtime: stats,diff --git a/packages/opencode/src/tool/grep.ts b/packages/opencode/src/tool/grep.tsindex 41ed494de92..00497d4e3fd 100644--- a/packages/opencode/src/tool/grep.ts+++ b/packages/opencode/src/tool/grep.ts@@ -1,5 +1,6 @@import z from "zod"import { Tool } from "./tool"+import { Filesystem } from "../util/filesystem"import { Ripgrep } from "../file/ripgrep"import DESCRIPTION from "./grep.txt"@@ -83,8 +84,7 @@ export const GrepTool = Tool.define("grep", {const lineNum = parseInt(lineNumStr, 10)const lineText = lineTextParts.join("|")- const file = Bun.file(filePath)- const stats = await file.stat().catch(() => null)+ const stats = Filesystem.stat(filePath)if (!stats) continuematches.push({diff --git a/packages/opencode/src/tool/lsp.ts b/packages/opencode/src/tool/lsp.tsindex ca352280b2a..52aef0f9e3f 100644--- a/packages/opencode/src/tool/lsp.ts+++ b/packages/opencode/src/tool/lsp.ts@@ -6,6 +6,7 @@ import DESCRIPTION from "./lsp.txt"import { Instance } from "../project/instance"import { pathToFileURL } from "url"import { assertExternalDirectory } from "./external-directory"+import { Filesystem } from "../util/filesystem"const operations = ["goToDefinition",@@ -47,7 +48,7 @@ export const LspTool = Tool.define("lsp", {const relPath = path.relative(Instance.worktree, file)const title = `${args.operation} ${relPath}:${args.line}:${args.character}`- const exists = await Bun.file(file).exists()+ const exists = await Filesystem.exists(file)if (!exists) {throw new Error(`File not found: ${file}`)}diff --git a/packages/opencode/src/tool/truncation.ts b/packages/opencode/src/tool/truncation.tsindex 84e799c1310..4cc524aeee1 100644--- a/packages/opencode/src/tool/truncation.ts+++ b/packages/opencode/src/tool/truncation.ts@@ -5,6 +5,7 @@ import { Identifier } from "../id/id"import { PermissionNext } from "../permission/next"import type { Agent } from "../agent/agent"import { Scheduler } from "../scheduler"+import { Filesystem } from "../util/filesystem"export namespace Truncate {export const MAX_LINES = 2000@@ -91,7 +92,7 @@ export namespace Truncate {const id = Identifier.ascending("tool")const filepath = path.join(DIR, id)- await Bun.write(Bun.file(filepath), text)+ await Filesystem.write(filepath, text)const hint = hasTaskTool(agent)? `The tool call succeeded but the output was truncated. Full output saved to: ${filepath}\nUse the Task tool to have explore agent process this file with Grep and Read (with offset/limit). Do NOT read the full file yourself - delegate to save context.`