From 3d41e3de2907b2df868e9e9b8ff59ef6e0802560 Mon Sep 17 00:00:00 2001 From: Chris Wanstrath Date: Tue, 24 Feb 2026 08:47:57 -0800 Subject: [PATCH] Support optional ~/Code mount alongside ~/dev --- src/vm.ts | 40 ++++++++++++++++++++++++++++++++++------ 1 file changed, 34 insertions(+), 6 deletions(-) diff --git a/src/vm.ts b/src/vm.ts index 6425491..260f12b 100644 --- a/src/vm.ts +++ b/src/vm.ts @@ -18,6 +18,9 @@ export function containerPath(hostPath: string): string { if (hostPath.startsWith(`${home}/dev`)) { return "/host" + hostPath.slice(`${home}/dev`.length) } + if (hostPath.startsWith(`${home}/Code`)) { + return "/host-code" + hostPath.slice(`${home}/Code`.length) + } return hostPath } @@ -41,11 +44,28 @@ 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 } +} + /** Pull the image and start the container in detached mode. */ async function createContainer(home: string): Promise { - await run( - $`container run -d --name ${CONTAINER_NAME} -m 4G --mount type=bind,source=${home}/dev,target=/host,readonly -v ${home}/.sandlot:/sandlot ubuntu:24.04 sleep infinity`, - "Container creation") + const mounts = await 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,readonly`) + if (mounts.code) args.push("--mount", `type=bind,source=${home}/Code,target=/host-code,readonly`) + args.push("-v", `${home}/.sandlot:/sandlot`, "ubuntu:24.04", "sleep", "infinity") + const result = await $`${args}`.nothrow().quiet() + if (result.exitCode !== 0) { + const stderr = result.stderr.toString().trim() + const stdout = result.stdout.toString().trim() + throw new Error(`Container creation failed (exit ${result.exitCode}):\n${stderr || stdout || "(no output)"}`) + } } /** Install base system packages (as root). */ @@ -60,8 +80,12 @@ 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 cmds = [`mkdir -p '${home}'`, `ln -s /sandlot '${home}/.sandlot'`] + if (mounts.dev) cmds.push(`ln -s /host '${home}/dev'`) + if (mounts.code) cmds.push(`ln -s /host-code '${home}/Code'`) await run( - $`container exec ${CONTAINER_NAME} bash -c ${`mkdir -p '${home}' && ln -s /host '${home}/dev' && ln -s /sandlot '${home}/.sandlot'`}`, + $`container exec ${CONTAINER_NAME} bash -c ${cmds.join(" && ")}`, "Symlink creation") } @@ -240,13 +264,17 @@ 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 systemPromptLines = [ "You are running inside a sandlot container (Apple Container, ubuntu:24.04).", `Your working directory is ${cwd}, a git worktree managed by sandlot.`, - "The host's ~/dev is mounted read-only at /host.", + ] + if (mounts.dev) systemPromptLines.push("The host's ~/dev is mounted read-only at /host.") + if (mounts.code) systemPromptLines.push("The host's ~/Code is mounted read-only at /host-code.") + systemPromptLines.push( "The host's ~/.sandlot is mounted at /sandlot.", "Bun is installed at ~/.local/bin/bun. Use bun instead of node/npm.", - ] + ) if (opts?.print) { systemPromptLines.push("IMPORTANT: Do not use plan mode. Do not call the EnterPlanMode tool. Proceed directly with the task.") }