Skip to content

Commit 3b9b342

Browse files
committed
fix(bcode-browser): detect compiled mode on Windows; pre-flight harnessDir
The bunfs root is /$bunfs/ on POSIX but B:\~BUN\ on Windows (native separators), so `__dirname.startsWith("B:/~BUN/")` was always false in Windows compiled binaries. Result: isCompiled=false, resolveHarnessDir returned the dev path which doesn't exist on installs, the harness was never extracted, and every spawn failed with cwd=ENOENT. Bun's spawn attributes that ENOENT to path="uv", so isUvMissing matched and the agent reported a misleading 'uv not on PATH' error -- even though uv was installed and on PATH. Two fixes: 1. harness.ts: normalize __dirname to forward slashes before the bunfs prefix check, so the same comparison works on Windows and POSIX. 2. browser-execute.ts: fs.access(harnessDir) before spawn. If the directory is missing, fail with a clear message instead of falling into the spawn-ENOENT path that gets misclassified as uv-missing. Reproduced on Windows 11 with v0.0.5 binary (and a locally-built one). Pre-fix: ~/.cache/bcode/harness was never created; agent reported uv missing despite uv being installed and on PATH. Post-fix: harness extracts on first run, agent attaches to Chrome, end-to-end browser_execute works.
1 parent 46afdba commit 3b9b342

2 files changed

Lines changed: 16 additions & 1 deletion

File tree

packages/bcode-browser/src/browser-execute.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,13 @@ export const make = Effect.fn("BrowserExecute.make")(function* () {
9292
const execute = (args: Parameters, ctx: ExecuteContext) =>
9393
Effect.gen(function* () {
9494
const harnessDir = yield* Effect.promise(() => resolveHarnessDir())
95+
// Pre-flight check on harnessDir: spawn ENOENT on a missing cwd surfaces
96+
// with `path: "uv"` on Bun/Windows, which is indistinguishable from a
97+
// truly-missing uv. Catch it here so the user gets the real cause
98+
// instead of a misleading "uv not on PATH" hint.
99+
if (!(yield* Effect.promise(() => fs.access(harnessDir).then(() => true, () => false)))) {
100+
return yield* Effect.fail(new Error(`harness directory not found at ${harnessDir} — bcode build is broken; please reinstall`))
101+
}
95102
yield* Effect.promise(() => fs.mkdir(ctx.bhTmpDir, { recursive: true }))
96103
const uv = yield* locate
97104
const proc = ChildProcess.make(

packages/bcode-browser/src/harness.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,15 @@ import path from "path"
3737
import { fileURLToPath } from "url"
3838

3939
const __dirname = path.dirname(fileURLToPath(import.meta.url))
40-
const isCompiled = __dirname.startsWith("/$bunfs/") || __dirname.startsWith("B:/~BUN/")
40+
// Bun's bunfs root is `/$bunfs/` on POSIX and `B:\~BUN\` on Windows (native
41+
// separators). Normalize before comparing so the compiled-mode check works on
42+
// both platforms — without this, the Windows compiled binary falls through to
43+
// DEV_HARNESS_DIR (which doesn't exist on the user's machine) and every
44+
// subsequent spawn fails with a misleading uv-missing error.
45+
const isCompiled = (() => {
46+
const d = __dirname.replaceAll("\\", "/")
47+
return d.startsWith("/$bunfs/") || d.startsWith("B:/~BUN/")
48+
})()
4149
const DEV_HARNESS_DIR = path.resolve(__dirname, "..", "harness")
4250
const cachedHarnessDir = path.join(os.homedir(), ".cache", "bcode", "harness")
4351

0 commit comments

Comments
 (0)