Make hostMounts sync, drop readonly mounts
This commit is contained in:
parent
1382f55964
commit
65603df7d2
26
src/vm.ts
26
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,20 +48,19 @@ async function run(cmd: ReturnType<typeof $>, step: string): Promise<void> {
|
|||
// ── 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<void> {
|
||||
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`)
|
||||
if (mounts.dev) args.push("--mount", `type=bind,source=${home}/dev,target=/host/dev`)
|
||||
if (mounts.code) args.push("--mount", `type=bind,source=${home}/code,target=/host/code`)
|
||||
args.push("-v", `${home}/.sandlot:/sandlot`, "ubuntu:24.04", "sleep", "infinity")
|
||||
const prepared = DEBUG ? $`${args}`.nothrow() : $`${args}`.nothrow().quiet()
|
||||
const result = await prepared
|
||||
|
|
@ -83,7 +83,7 @@ async function installPackages(cached: boolean): Promise<void> {
|
|||
|
||||
/** Create symlinks so git worktree absolute paths from the host resolve inside the container. */
|
||||
async function createHostSymlinks(home: string): Promise<void> {
|
||||
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,13 +268,13 @@ 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.`,
|
||||
]
|
||||
if (mounts.dev) systemPromptLines.push("The host's ~/dev is mounted read-only at /host/dev.")
|
||||
if (mounts.code) systemPromptLines.push("The host's ~/code is mounted read-only at /host/code.")
|
||||
if (mounts.dev) systemPromptLines.push("The host's ~/dev is mounted at /host/dev.")
|
||||
if (mounts.code) systemPromptLines.push("The host's ~/code is mounted 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.",
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user