diff --git a/src/spinner.ts b/src/spinner.ts index 4141f45..2e8b5da 100644 --- a/src/spinner.ts +++ b/src/spinner.ts @@ -1,7 +1,25 @@ const frames = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"] +const DEBUG = !!process.env.DEBUG export function spinner(text: string, prefix?: string) { const tag = prefix ? `\x1b[2m[${prefix}]\x1b[22m ` : "" + + if (DEBUG) { + process.stderr.write(`▸ ${tag}${text}\n`) + return { + set text(t: string) { + process.stderr.write(`▸ ${tag}${t}\n`) + }, + succeed(msg: string) { + process.stderr.write(`✔ ${tag}${msg}\n`) + }, + fail(msg: string) { + process.stderr.write(`✖ ${tag}${msg}\n`) + }, + stop() {}, + } + } + let i = 0 const id = setInterval(() => { process.stderr.write(`\r\x1b[2K${frames[i++ % frames.length]} ${tag}${text}`) diff --git a/src/vm.ts b/src/vm.ts index 3ce4f7c..bf0c569 100644 --- a/src/vm.ts +++ b/src/vm.ts @@ -4,6 +4,7 @@ import { dirname, join } from "path" import { getApiKey } from "./env.ts" import { info } from "./fmt.ts" +const DEBUG = !!process.env.DEBUG const CONTAINER_NAME = "sandlot" const USER = "ubuntu" const CLAUDE_BIN = `/home/${USER}/.local/bin/claude` @@ -33,7 +34,8 @@ function requireContainer(): void { /** Run a shell command, logging stderr on failure. */ async function run(cmd: ReturnType, step: string): Promise { - const result = await cmd.nothrow().quiet() + const prepared = DEBUG ? cmd.nothrow() : cmd.nothrow().quiet() + const result = await prepared if (result.exitCode !== 0) { const stderr = result.stderr.toString().trim() const stdout = result.stdout.toString().trim() @@ -60,7 +62,8 @@ async function createContainer(home: string): Promise { 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() + const prepared = DEBUG ? $`${args}`.nothrow() : $`${args}`.nothrow().quiet() + const result = await prepared if (result.exitCode !== 0) { const stderr = result.stderr.toString().trim() const stdout = result.stdout.toString().trim() @@ -234,7 +237,8 @@ export async function ensure(log?: (msg: string) => void): Promise { requireContainer() // Ensure the container daemon is running - await $`container system start`.nothrow().quiet() + if (DEBUG) await $`container system start`.nothrow() + else await $`container system start`.nothrow().quiet() const s = await status() if (s === "running") return