|
| 1 | +--- |
| 2 | +name: vz |
| 3 | +description: > |
| 4 | + Run commands in instant Linux VMs on macOS via vz. Use when the user needs |
| 5 | + to: (1) compile or test code for Linux (cross-compile, Linux-only deps), |
| 6 | + (2) run Linux-specific tools (apt-get, systemd, docker-in-VM), |
| 7 | + (3) execute commands in an isolated Linux environment, |
| 8 | + (4) work on a project that has a vz.json file. |
| 9 | + TRIGGER when: project contains vz.json, user says "run in Linux", |
| 10 | + "test on Linux", "compile for Linux", "vz run", or needs Linux-only behavior. |
| 11 | + DO NOT TRIGGER when: commands work fine on macOS natively. |
| 12 | +--- |
| 13 | + |
| 14 | +# vz — Linux VM execution |
| 15 | + |
| 16 | +Run commands inside a lightweight Linux VM on macOS via Apple's Virtualization.framework. |
| 17 | +The VM boots in ~3s, mounts the project directory via VirtioFS, and persists across runs. |
| 18 | + |
| 19 | +## Detection |
| 20 | + |
| 21 | +Check if the project has a `vz.json` in the working directory or parents. If it does, |
| 22 | +Linux commands should go through `vz run` instead of running locally. |
| 23 | + |
| 24 | +## Commands |
| 25 | + |
| 26 | +### Run a command |
| 27 | + |
| 28 | +```bash |
| 29 | +vz run <command...> |
| 30 | +``` |
| 31 | + |
| 32 | +Output streams in real-time. Exit code propagates. Environment variables from |
| 33 | +`vz.json` are injected automatically (PATH, HOME, CARGO_TARGET_DIR, etc.). |
| 34 | + |
| 35 | +Examples: |
| 36 | +```bash |
| 37 | +vz run cargo build |
| 38 | +vz run cargo test |
| 39 | +vz run make -j4 |
| 40 | +vz run apt-get install -y libssl-dev # only works during setup, not ad-hoc |
| 41 | +vz run python3 script.py |
| 42 | +``` |
| 43 | + |
| 44 | +### Interactive shell |
| 45 | + |
| 46 | +```bash |
| 47 | +vz run -i bash |
| 48 | +``` |
| 49 | + |
| 50 | +Opens a PTY-backed interactive session. Use for debugging, exploring the |
| 51 | +VM filesystem, or running interactive tools. |
| 52 | + |
| 53 | +### Project setup |
| 54 | + |
| 55 | +```bash |
| 56 | +vz init # generate vz.json (auto-detects Rust/Node/Python/Go) |
| 57 | +vz init --template rust # force a specific template |
| 58 | +vz init --image debian:12 # override base image |
| 59 | +``` |
| 60 | + |
| 61 | +### Lifecycle |
| 62 | + |
| 63 | +```bash |
| 64 | +vz status # show daemon/VM state, project, mounts |
| 65 | +vz stop # stop the VM (persists disk, next run reboots) |
| 66 | +vz run --fresh # destroy VM + re-run setup from scratch |
| 67 | +vz logs # show daemon logs |
| 68 | +vz logs -f # follow daemon logs |
| 69 | +``` |
| 70 | + |
| 71 | +## When to use vz run vs local execution |
| 72 | + |
| 73 | +Use `vz run` when: |
| 74 | +- The command needs Linux (cargo build for linux targets, apt-get, Linux syscalls) |
| 75 | +- The project has a `vz.json` |
| 76 | +- The user explicitly asks to run in Linux or in a VM |
| 77 | + |
| 78 | +Use local execution when: |
| 79 | +- The command works on macOS natively (git, formatting, linting) |
| 80 | +- No `vz.json` exists and user hasn't asked for Linux |
| 81 | + |
| 82 | +## Setup commands vs runtime commands |
| 83 | + |
| 84 | +`vz.json` has a `setup` array — these run once on first boot and are cached by hash. |
| 85 | +Do NOT put one-off commands in setup. Instead: |
| 86 | +- **Setup**: package installs, toolchain setup (apt-get, rustup, npm install -g) |
| 87 | +- **Runtime**: build, test, run commands (cargo build, npm test) |
| 88 | + |
| 89 | +If the user needs a new package installed, suggest adding it to the `setup` array |
| 90 | +in `vz.json` and running `vz run --fresh` to re-provision. |
| 91 | + |
| 92 | +## Error patterns |
| 93 | + |
| 94 | +- **"no vz.json found"** — suggest `vz init` |
| 95 | +- **"getcwd() failed"** — harmless kernel warning, ignore it |
| 96 | +- **Setup reruns every time** — setup command may be failing silently; check with `vz run --fresh` and watch output |
| 97 | +- **"daemon startup timed out"** — stale lock file; `vz stop` then retry |
| 98 | +- **Command not found in VM** — tool not in setup commands; add to `vz.json` setup array |
0 commit comments