Compare commits

..

2 Commits

Author SHA1 Message Date
Dax
2986d7e83a Merge branch 'dev' into migrate-session-prompt 2026-02-18 17:53:44 -05:00
Dax Raad
50623c120d refactor: migrate src/session/prompt.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 and Filesystem import

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

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

- Replace Bun.file().bytes() with Filesystem.readBytes()

All 109 session tests pass (4 skipped, 0 fail).
2026-02-18 10:50:22 -05:00
2 changed files with 10 additions and 11 deletions

View File

@@ -1,7 +1,9 @@
import path from "path"
import os from "os"
import fs from "fs/promises"
import { stat } 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"
@@ -1082,11 +1084,9 @@ 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 stat = await Bun.file(filepath)
.stat()
.catch(() => undefined)
const s = await stat(filepath).catch(() => undefined)
if (stat?.isDirectory()) {
if (s?.isDirectory()) {
part.mime = "application/x-directory"
}
@@ -1233,14 +1233,13 @@ 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,
},
{
@@ -1248,7 +1247,8 @@ export namespace SessionPrompt {
messageID: info.id,
sessionID: input.sessionID,
type: "file",
url: `data:${part.mime};base64,` + Buffer.from(await file.bytes()).toString("base64"),
url:
`data:${part.mime};base64,` + Buffer.from(await Filesystem.readBytes(filepath)).toString("base64"),
mime: part.mime,
filename: part.filename!,
source: part.source,
@@ -1354,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 Bun.file(plan).exists()
const exists = await Filesystem.exists(plan)
if (exists) {
const part = await Session.updatePart({
id: Identifier.ascending("part"),
@@ -1373,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 Bun.file(plan).exists()
const exists = await Filesystem.exists(plan)
if (!exists) await fs.mkdir(path.dirname(plan), { recursive: true })
const part = await Session.updatePart({
id: Identifier.ascending("part"),

View File

@@ -1,6 +1,5 @@
import { Flag } from "@/flag/flag"
import { lazy } from "@/util/lazy"
import { Filesystem } from "@/util/filesystem"
import path from "path"
import { spawn, type ChildProcess } from "child_process"
@@ -44,7 +43,7 @@ export namespace Shell {
// git.exe is typically at: C:\Program Files\Git\cmd\git.exe
// bash.exe is at: C:\Program Files\Git\bin\bash.exe
const bash = path.join(git, "..", "..", "bin", "bash.exe")
if (Filesystem.stat(bash)?.size) return bash
if (Bun.file(bash).size) return bash
}
return process.env.COMSPEC || "cmd.exe"
}