Use nested paths for host mounts

This commit is contained in:
Chris Wanstrath 2026-02-24 08:49:33 -08:00
parent 3d41e3de29
commit 3b21a2afd1

View File

@ -16,10 +16,10 @@ export function containerPath(hostPath: string): string {
return "/sandlot" + hostPath.slice(`${home}/.sandlot`.length) return "/sandlot" + hostPath.slice(`${home}/.sandlot`.length)
} }
if (hostPath.startsWith(`${home}/dev`)) { if (hostPath.startsWith(`${home}/dev`)) {
return "/host" + hostPath.slice(`${home}/dev`.length) return "/host/dev" + hostPath.slice(`${home}/dev`.length)
} }
if (hostPath.startsWith(`${home}/Code`)) { if (hostPath.startsWith(`${home}/Code`)) {
return "/host-code" + hostPath.slice(`${home}/Code`.length) return "/host/Code" + hostPath.slice(`${home}/Code`.length)
} }
return hostPath return hostPath
} }
@ -57,8 +57,8 @@ async function hostMounts(home: string): Promise<{ dev: boolean; code: boolean }
async function createContainer(home: string): Promise<void> { async function createContainer(home: string): Promise<void> {
const mounts = await hostMounts(home) const mounts = await hostMounts(home)
const args = ["container", "run", "-d", "--name", CONTAINER_NAME, "-m", "4G"] 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.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.code) args.push("--mount", `type=bind,source=${home}/Code,target=/host/Code,readonly`)
args.push("-v", `${home}/.sandlot:/sandlot`, "ubuntu:24.04", "sleep", "infinity") args.push("-v", `${home}/.sandlot:/sandlot`, "ubuntu:24.04", "sleep", "infinity")
const result = await $`${args}`.nothrow().quiet() const result = await $`${args}`.nothrow().quiet()
if (result.exitCode !== 0) { if (result.exitCode !== 0) {
@ -82,8 +82,8 @@ async function installPackages(cached: boolean): Promise<void> {
async function createHostSymlinks(home: string): Promise<void> { async function createHostSymlinks(home: string): Promise<void> {
const mounts = await hostMounts(home) const mounts = await hostMounts(home)
const cmds = [`mkdir -p '${home}'`, `ln -s /sandlot '${home}/.sandlot'`] const cmds = [`mkdir -p '${home}'`, `ln -s /sandlot '${home}/.sandlot'`]
if (mounts.dev) cmds.push(`ln -s /host '${home}/dev'`) if (mounts.dev) cmds.push(`ln -s /host/dev '${home}/dev'`)
if (mounts.code) cmds.push(`ln -s /host-code '${home}/Code'`) if (mounts.code) cmds.push(`ln -s /host/Code '${home}/Code'`)
await run( await run(
$`container exec ${CONTAINER_NAME} bash -c ${cmds.join(" && ")}`, $`container exec ${CONTAINER_NAME} bash -c ${cmds.join(" && ")}`,
"Symlink creation") "Symlink creation")
@ -269,8 +269,8 @@ export async function claude(workdir: string, opts?: { prompt?: string; print?:
"You are running inside a sandlot container (Apple Container, ubuntu:24.04).", "You are running inside a sandlot container (Apple Container, ubuntu:24.04).",
`Your working directory is ${cwd}, a git worktree managed by sandlot.`, `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.") 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.code) systemPromptLines.push("The host's ~/Code is mounted read-only at /host/Code.")
systemPromptLines.push( systemPromptLines.push(
"The host's ~/.sandlot is mounted at /sandlot.", "The host's ~/.sandlot is mounted at /sandlot.",
"Bun is installed at ~/.local/bin/bun. Use bun instead of node/npm.", "Bun is installed at ~/.local/bin/bun. Use bun instead of node/npm.",