From 4f913b60913bab021bd506be8f68420b7641fd51 Mon Sep 17 00:00:00 2001 From: Chris Wanstrath Date: Sat, 21 Feb 2026 08:24:26 -0800 Subject: [PATCH] Add tooling cache and install neofetch, difftastic, and Neovim in containers --- src/vm.ts | 55 ++++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 48 insertions(+), 7 deletions(-) diff --git a/src/vm.ts b/src/vm.ts index df8d144..4cd8886 100644 --- a/src/vm.ts +++ b/src/vm.ts @@ -47,9 +47,12 @@ async function createContainer(home: string): Promise { } /** Install base system packages (as root). */ -async function installPackages(): Promise { +async function installPackages(cached: boolean): Promise { + const packages = cached + ? "curl git fish" + : "curl git fish unzip" await run( - $`container exec ${CONTAINER_NAME} bash -c ${"apt update && apt install -y curl git neofetch fish unzip"}`, + $`container exec ${CONTAINER_NAME} bash -c ${`apt update && apt install -y ${packages}`}`, "Package installation") } @@ -60,8 +63,25 @@ async function createHostSymlinks(home: string): Promise { "Symlink creation") } -/** Install Bun and Claude Code (as ubuntu user). */ -async function installTooling(log?: (msg: string) => void): Promise { +const CACHE_DIR = join(homedir(), '.sandlot', '.cache') + +/** Check whether the package cache is populated. */ +async function hasCachedTooling(): Promise { + const files = ['bun', 'claude', 'neofetch', 'difft', 'nvim.tar.gz'] + const checks = await Promise.all(files.map(f => Bun.file(join(CACHE_DIR, f)).exists())) + return checks.every(Boolean) +} + +/** Install Bun, Claude Code, neofetch, and Neovim, using cached binaries when available. */ +async function installTooling(cached: boolean, log?: (msg: string) => void): Promise { + if (cached) { + log?.("Installing packages (cached)") + await run( + $`container exec --user ${USER} ${CONTAINER_NAME} bash -c ${"mkdir -p ~/.local/bin && cp /sandlot/.cache/bun /sandlot/.cache/claude /sandlot/.cache/neofetch /sandlot/.cache/difft ~/.local/bin/ && chmod +x ~/.local/bin/bun ~/.local/bin/claude ~/.local/bin/neofetch ~/.local/bin/difft && ln -sf bun ~/.local/bin/bunx && tar xzf /sandlot/.cache/nvim.tar.gz -C ~/.local --strip-components=1"}`, + "Install from cache") + return + } + log?.("Installing Bun") await run( $`container exec --user ${USER} ${CONTAINER_NAME} env BUN_INSTALL=/home/${USER}/.local bash -c ${"curl -fsSL https://bun.sh/install | bash"}`, @@ -71,6 +91,25 @@ async function installTooling(log?: (msg: string) => void): Promise { await run( $`container exec --user ${USER} ${CONTAINER_NAME} bash -c ${"curl -fsSL https://claude.ai/install.sh | bash"}`, "Claude Code installation") + + log?.("Installing neofetch") + await run( + $`container exec --user ${USER} ${CONTAINER_NAME} bash -c ${"curl -fsSL https://raw.githubusercontent.com/dylanaraps/neofetch/master/neofetch -o ~/.local/bin/neofetch && chmod +x ~/.local/bin/neofetch"}`, + "neofetch installation") + + log?.("Installing difftastic") + await $`mkdir -p ${CACHE_DIR}`.quiet() + await run( + $`container exec --user ${USER} ${CONTAINER_NAME} bash -c ${"curl -fsSL https://github.com/Wilfred/difftastic/releases/latest/download/difft-aarch64-unknown-linux-gnu.tar.gz | tar xz -C ~/.local/bin"}`, + "difftastic installation") + + log?.("Installing Neovim") + await run( + $`container exec --user ${USER} ${CONTAINER_NAME} bash -c ${"curl -fsSL https://github.com/neovim/neovim/releases/latest/download/nvim-linux-arm64.tar.gz -o /sandlot/.cache/nvim.tar.gz && tar xzf /sandlot/.cache/nvim.tar.gz -C ~/.local --strip-components=1"}`, + "Neovim installation") + + // Cache binaries for next time + await $`container exec --user ${USER} ${CONTAINER_NAME} bash -c ${"cp ~/.local/bin/bun ~/.local/bin/claude ~/.local/bin/neofetch ~/.local/bin/difft /sandlot/.cache/"}`.nothrow().quiet() } /** Configure git identity, API key helper, activity hook, and Claude settings. */ @@ -136,14 +175,16 @@ export async function create(log?: (msg: string) => void): Promise { const home = homedir() + const cached = await hasCachedTooling() + log?.("Pulling image & creating container") await createContainer(home) log?.("Installing packages") - await installPackages() + await installPackages(cached) await createHostSymlinks(home) - await installTooling(log) + await installTooling(cached, log) log?.("Configuring environment") const apiKey = await getApiKey() @@ -235,7 +276,7 @@ export async function shell(workdir?: string): Promise { /** Run neofetch in the container. */ export async function info(): Promise { const proc = Bun.spawn( - ["container", "exec", "--user", USER, CONTAINER_NAME, "neofetch"], + ["container", "exec", "--user", USER, CONTAINER_NAME, "env", `PATH=/home/${USER}/.local/bin:/usr/bin:/bin`, "neofetch"], { stdin: "inherit", stdout: "inherit", stderr: "inherit" }, ) await proc.exited