Compare commits

..

2 Commits

Author SHA1 Message Date
Dax
f6ae3e0491 Merge branch 'dev' into migrate-project 2026-02-18 17:53:44 -05:00
Dax Raad
d6d8e85614 refactor: migrate src/project/project.ts from Bun.file() to Filesystem/stat modules
Replace Bun-specific file operations with Filesystem module and fs/promises:

- Add stat import from fs/promises

- Replace Bun.file().text() with Filesystem.readText()

- Replace Bun.file().write() with Filesystem.write()

- Replace Bun.file().arrayBuffer() and .type with Filesystem.readBytes() and mimeType()

- Replace Bun.file().stat() with stat() from fs/promises

All 18 project tests pass.
2026-02-18 10:48:28 -05:00
2 changed files with 12 additions and 16 deletions

View File

@@ -1,6 +1,7 @@
import z from "zod"
import { Filesystem } from "../util/filesystem"
import path from "path"
import { stat } from "fs/promises"
import { Database, eq } from "../storage/db"
import { ProjectTable } from "./project.sql"
import { SessionTable } from "../session/session.sql"
@@ -86,8 +87,7 @@ export namespace Project {
const gitBinary = Bun.which("git")
// cached id calculation
let id = await Bun.file(path.join(dotgit, "opencode"))
.text()
let id = await Filesystem.readText(path.join(dotgit, "opencode"))
.then((x) => x.trim())
.catch(() => undefined)
@@ -125,9 +125,7 @@ export namespace Project {
id = roots[0]
if (id) {
void Bun.file(path.join(dotgit, "opencode"))
.write(id)
.catch(() => undefined)
void Filesystem.write(path.join(dotgit, "opencode"), id).catch(() => undefined)
}
}
@@ -277,10 +275,9 @@ export namespace Project {
)
const shortest = matches.sort((a, b) => a.length - b.length)[0]
if (!shortest) return
const file = Bun.file(shortest)
const buffer = await file.arrayBuffer()
const base64 = Buffer.from(buffer).toString("base64")
const mime = file.type || "image/png"
const buffer = await Filesystem.readBytes(shortest)
const base64 = buffer.toString("base64")
const mime = Filesystem.mimeType(shortest) || "image/png"
const url = `data:${mime};base64,${base64}`
await update({
projectID: input.id,
@@ -381,10 +378,8 @@ export namespace Project {
const data = fromRow(row)
const valid: string[] = []
for (const dir of data.sandboxes) {
const stat = await Bun.file(dir)
.stat()
.catch(() => undefined)
if (stat?.isDirectory()) valid.push(dir)
const s = await stat(dir).catch(() => undefined)
if (s?.isDirectory()) valid.push(dir)
}
return valid
}

View File

@@ -26,8 +26,9 @@ export const WriteTool = Tool.define("write", {
const filepath = path.isAbsolute(params.filePath) ? params.filePath : path.join(Instance.directory, params.filePath)
await assertExternalDirectory(ctx, filepath)
const exists = await Filesystem.exists(filepath)
const contentOld = exists ? await Filesystem.readText(filepath) : ""
const file = Bun.file(filepath)
const exists = await file.exists()
const contentOld = exists ? await file.text() : ""
if (exists) await FileTime.assert(ctx.sessionID, filepath)
const diff = trimDiff(createTwoFilesPatch(filepath, filepath, contentOld, params.content))
@@ -41,7 +42,7 @@ export const WriteTool = Tool.define("write", {
},
})
await Filesystem.write(filepath, params.content)
await Bun.write(filepath, params.content)
await Bus.publish(File.Event.Edited, {
file: filepath,
})