diff --git a/src/vm.ts b/src/vm.ts index 4737c2c..d3dc568 100644 --- a/src/vm.ts +++ b/src/vm.ts @@ -1,4 +1,5 @@ import { $ } from "bun" +import { existsSync } from "fs" import { homedir } from "os" import { dirname, join } from "path" import { getApiKey } from "./env.ts" @@ -47,17 +48,16 @@ async function run(cmd: ReturnType, step: string): Promise { // ── create() helpers (internal) ────────────────────────────────────── /** Check which host source directories exist. */ -async function hostMounts(home: string): Promise<{ dev: boolean; code: boolean }> { - const [dev, code] = await Promise.all([ - Bun.file(`${home}/dev`).exists().catch(() => false), - Bun.file(`${home}/code`).exists().catch(() => false), - ]) - return { dev, code } +function hostMounts(home: string): { dev: boolean; code: boolean } { + return { + dev: existsSync(`${home}/dev`), + code: existsSync(`${home}/code`), + } } /** Pull the image and start the container in detached mode. */ async function createContainer(home: string): Promise { - const mounts = await hostMounts(home) + const mounts = hostMounts(home) const args = ["container", "run", "-d", "--name", CONTAINER_NAME, "-m", "4G"] if (mounts.dev) args.push("--mount", `type=bind,source=${home}/dev,target=/host/dev,readonly`) if (mounts.code) args.push("--mount", `type=bind,source=${home}/code,target=/host/code,readonly`) @@ -83,7 +83,7 @@ async function installPackages(cached: boolean): Promise { /** Create symlinks so git worktree absolute paths from the host resolve inside the container. */ async function createHostSymlinks(home: string): Promise { - const mounts = await hostMounts(home) + const mounts = hostMounts(home) const cmds = [`mkdir -p '${home}'`, `ln -s /sandlot '${home}/.sandlot'`] if (mounts.dev) cmds.push(`ln -s /host/dev '${home}/dev'`) if (mounts.code) cmds.push(`ln -s /host/code '${home}/code'`) @@ -268,7 +268,7 @@ export async function status(): Promise<"running" | "stopped" | "missing"> { /** Launch claude in the container at the given workdir. */ export async function claude(workdir: string, opts?: { prompt?: string; print?: string; continue?: boolean }): Promise<{ exitCode: number; output?: string }> { const cwd = containerPath(workdir) - const mounts = await hostMounts(homedir()) + const mounts = hostMounts(homedir()) const systemPromptLines = [ "You are running inside a sandlot container (Apple Container, ubuntu:24.04).", `Your working directory is ${cwd}, a git worktree managed by sandlot.`,