Compare commits
4 Commits
be277b7623
...
6face2560e
| Author | SHA1 | Date | |
|---|---|---|---|
| 6face2560e | |||
| 1e89608d11 | |||
| 3b21a2afd1 | |||
| 3d41e3de29 |
42
src/vm.ts
42
src/vm.ts
|
|
@ -16,7 +16,10 @@ export function containerPath(hostPath: string): string {
|
|||
return "/sandlot" + hostPath.slice(`${home}/.sandlot`.length)
|
||||
}
|
||||
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`)) {
|
||||
return "/host/Code" + hostPath.slice(`${home}/Code`.length)
|
||||
}
|
||||
return hostPath
|
||||
}
|
||||
|
|
@ -41,11 +44,28 @@ 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 }
|
||||
}
|
||||
|
||||
/** Pull the image and start the container in detached mode. */
|
||||
async function createContainer(home: string): Promise<void> {
|
||||
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/dev,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<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 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'`)
|
||||
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/dev.")
|
||||
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.")
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user