Revert: all refactor commits migrating from Bun.file() to Filesystem module

This commit is contained in:
Dax Raad
2026-02-18 19:41:14 -05:00
parent 3a07dd8d96
commit 568eccb4c6
25 changed files with 216 additions and 294 deletions

View File

@@ -85,7 +85,7 @@ export namespace InstructionPrompt {
}
for (const file of globalFiles()) {
if (await Filesystem.exists(file)) {
if (await Bun.file(file).exists()) {
paths.add(path.resolve(file))
break
}
@@ -120,7 +120,9 @@ export namespace InstructionPrompt {
const paths = await systemPaths()
const files = Array.from(paths).map(async (p) => {
const content = await Filesystem.readText(p).catch(() => "")
const content = await Bun.file(p)
.text()
.catch(() => "")
return content ? "Instructions from: " + p + "\n" + content : ""
})
@@ -162,7 +164,7 @@ export namespace InstructionPrompt {
export async function find(dir: string) {
for (const file of FILES) {
const filepath = path.resolve(path.join(dir, file))
if (await Filesystem.exists(filepath)) return filepath
if (await Bun.file(filepath).exists()) return filepath
}
}
@@ -180,7 +182,9 @@ export namespace InstructionPrompt {
if (found && found !== target && !system.has(found) && !already.has(found) && !isClaimed(messageID, found)) {
claim(messageID, found)
const content = await Filesystem.readText(found).catch(() => undefined)
const content = await Bun.file(found)
.text()
.catch(() => undefined)
if (content) {
results.push({ filepath: found, content: "Instructions from: " + found + "\n" + content })
}

View File

@@ -2,7 +2,6 @@ import path from "path"
import os from "os"
import fs from "fs/promises"
import z from "zod"
import { Filesystem } from "../util/filesystem"
import { Identifier } from "../id/id"
import { MessageV2 } from "./message-v2"
import { Log } from "../util/log"
@@ -1083,9 +1082,11 @@ export namespace SessionPrompt {
// have to normalize, symbol search returns absolute paths
// Decode the pathname since URL constructor doesn't automatically decode it
const filepath = fileURLToPath(part.url)
const s = Filesystem.stat(filepath)
const stat = await Bun.file(filepath)
.stat()
.catch(() => undefined)
if (s?.isDirectory()) {
if (stat?.isDirectory()) {
part.mime = "application/x-directory"
}
@@ -1232,13 +1233,14 @@ export namespace SessionPrompt {
]
}
const file = Bun.file(filepath)
FileTime.read(input.sessionID, filepath)
return [
{
messageID: info.id,
sessionID: input.sessionID,
type: "text",
text: `Called the Read tool with the following input: {"filePath":"${filepath}"}`,
text: `Called the Read tool with the following input: {\"filePath\":\"${filepath}\"}`,
synthetic: true,
},
{
@@ -1246,7 +1248,7 @@ export namespace SessionPrompt {
messageID: info.id,
sessionID: input.sessionID,
type: "file",
url: `data:${part.mime};base64,` + (await Filesystem.readBytes(filepath)).toString("base64"),
url: `data:${part.mime};base64,` + Buffer.from(await file.bytes()).toString("base64"),
mime: part.mime,
filename: part.filename!,
source: part.source,
@@ -1352,7 +1354,7 @@ export namespace SessionPrompt {
// Switching from plan mode to build mode
if (input.agent.name !== "plan" && assistantMessage?.info.agent === "plan") {
const plan = Session.plan(input.session)
const exists = await Filesystem.exists(plan)
const exists = await Bun.file(plan).exists()
if (exists) {
const part = await Session.updatePart({
id: Identifier.ascending("part"),
@@ -1371,7 +1373,7 @@ export namespace SessionPrompt {
// Entering plan mode
if (input.agent.name === "plan" && assistantMessage?.info.agent !== "plan") {
const plan = Session.plan(input.session)
const exists = await Filesystem.exists(plan)
const exists = await Bun.file(plan).exists()
if (!exists) await fs.mkdir(path.dirname(plan), { recursive: true })
const part = await Session.updatePart({
id: Identifier.ascending("part"),