summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorDax <[email protected]>2026-02-18 16:20:58 -0500
committerGitHub <[email protected]>2026-02-18 16:20:58 -0500
commite37a9081a673045c7be2de803806e968e5db806c (patch)
tree696051d9a5718eb225030800cb8c4f4b6e617b59
parenta2469d933e1a72db6b3ccdeb29624b56ad1c3547 (diff)
downloadopencode-e37a9081a673045c7be2de803806e968e5db806c.tar.gz
opencode-e37a9081a673045c7be2de803806e968e5db806c.zip
refactor: migrate src/cli/cmd/session.ts from Bun.file() to statSync (#14144)
-rw-r--r--packages/opencode/src/cli/cmd/session.ts7
-rw-r--r--packages/opencode/src/file/time.ts7
-rw-r--r--packages/opencode/src/util/filesystem.ts11
3 files changed, 14 insertions, 11 deletions
diff --git a/packages/opencode/src/cli/cmd/session.ts b/packages/opencode/src/cli/cmd/session.ts
index 8239b0bcb..4aa702359 100644
--- a/packages/opencode/src/cli/cmd/session.ts
+++ b/packages/opencode/src/cli/cmd/session.ts
@@ -5,6 +5,7 @@ import { bootstrap } from "../bootstrap"
import { UI } from "../ui"
import { Locale } from "../../util/locale"
import { Flag } from "../../flag/flag"
+import { Filesystem } from "../../util/filesystem"
import { EOL } from "os"
import path from "path"
@@ -17,18 +18,18 @@ function pagerCmd(): string[] {
// user could have less installed via other options
const lessOnPath = Bun.which("less")
if (lessOnPath) {
- if (Bun.file(lessOnPath).size) return [lessOnPath, ...lessOptions]
+ if (Filesystem.stat(lessOnPath)?.size) return [lessOnPath, ...lessOptions]
}
if (Flag.OPENCODE_GIT_BASH_PATH) {
const less = path.join(Flag.OPENCODE_GIT_BASH_PATH, "..", "..", "usr", "bin", "less.exe")
- if (Bun.file(less).size) return [less, ...lessOptions]
+ if (Filesystem.stat(less)?.size) return [less, ...lessOptions]
}
const git = Bun.which("git")
if (git) {
const less = path.join(git, "..", "..", "usr", "bin", "less.exe")
- if (Bun.file(less).size) return [less, ...lessOptions]
+ if (Filesystem.stat(less)?.size) return [less, ...lessOptions]
}
// Fall back to Windows built-in more (via cmd.exe)
diff --git a/packages/opencode/src/file/time.ts b/packages/opencode/src/file/time.ts
index 35c780fbd..c85781eb4 100644
--- a/packages/opencode/src/file/time.ts
+++ b/packages/opencode/src/file/time.ts
@@ -1,6 +1,7 @@
import { Instance } from "../project/instance"
import { Log } from "../util/log"
import { Flag } from "../flag/flag"
+import { Filesystem } from "../util/filesystem"
export namespace FileTime {
const log = Log.create({ service: "file.time" })
@@ -59,10 +60,10 @@ export namespace FileTime {
const time = get(sessionID, filepath)
if (!time) throw new Error(`You must read file ${filepath} before overwriting it. Use the Read tool first`)
- const stats = await Bun.file(filepath).stat()
- if (stats.mtime.getTime() > time.getTime()) {
+ const mtime = Filesystem.stat(filepath)?.mtime
+ if (mtime && mtime.getTime() > time.getTime()) {
throw new Error(
- `File ${filepath} has been modified since it was last read.\nLast modification: ${stats.mtime.toISOString()}\nLast read: ${time.toISOString()}\n\nPlease read the file again before modifying it.`,
+ `File ${filepath} has been modified since it was last read.\nLast modification: ${mtime.toISOString()}\nLast read: ${time.toISOString()}\n\nPlease read the file again before modifying it.`,
)
}
}
diff --git a/packages/opencode/src/util/filesystem.ts b/packages/opencode/src/util/filesystem.ts
index d2f22be52..7b196eb84 100644
--- a/packages/opencode/src/util/filesystem.ts
+++ b/packages/opencode/src/util/filesystem.ts
@@ -18,12 +18,13 @@ export namespace Filesystem {
}
}
+ export function stat(p: string): ReturnType<typeof statSync> | undefined {
+ return statSync(p, { throwIfNoEntry: false }) ?? undefined
+ }
+
export async function size(p: string): Promise<number> {
- try {
- return statSync(p).size
- } catch {
- return 0
- }
+ const s = stat(p)?.size ?? 0
+ return typeof s === "bigint" ? Number(s) : s
}
export async function readText(p: string): Promise<string> {