Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/cli-contract.md
Original file line number Diff line number Diff line change
Expand Up @@ -293,11 +293,11 @@ VM subcommands:
| `vm terminal send <machine> <terminal-id> [text] [--keys <k1,k2,…>] [--json]` (alias `write`) | `vm.terminal_write {id, terminal_id, text?, keys?}`: types `text` into the machine terminal exactly as given (no newline), then presses the named keys (`enter`, `tab`, `escape`, `up`, …; chords join with `+`: `ctrl+c`) — cmux-tui `terminal <id> write --text` / `keys`. Headless: no pane is attached or focused. |
| `vm terminal read <machine> <terminal-id> [--json]` (alias `screen`) | `vm.terminal_read {id, terminal_id}`: the terminal's visible screen (`text`; `--json` adds `rows`, `cols`, `cursor_row`, `cursor_col`, `cursor_visible`) — cmux-tui `terminal <id> screen read`. |
| `vm terminal wait <machine> <terminal-id> --pattern <regex> [--timeout <seconds>] [--json]` | `vm.terminal_wait {id, terminal_id, pattern, timeout_ms?}`: blocks until the screen text matches (default 30 s) — cmux-tui `terminal <id> screen wait`. Prints `OK matched …`; exits 1 with the screen tail on timeout. |
| `vm new`, `vm create` | Create a shell-only VM. No provider ships a desktop image right now, so `--base` is the default and `--desktop` fails closed with an image config error until one lands; `--base`/`--no-desktop` stay accepted. The CLI sends the machine **kind** (`desktop`/`base`) and the backend maps it to the image its deployment supports; `--image <id>` is the explicit override and is the only way an image id leaves the client. Supports `--size <2g|4g|8g|16g|24g|32g>`, `--name <label>` (display label, applied via `vm.rename` after create), `--provider`, `--workspace`, `--detach`, and `-d`. Without `--detach`, opens a plain terminal on the machine through the shared open path (see `vm shell`). The Machines panel's + opens the New Machine sheet (name, kind, size, plan meter) whose Create runs this same command. |
| `vm new`, `vm create` | Create a VM. The default kind is `desktop` (a screen: TigerVNC + openbox + noVNC on 6901); `--base`/`--no-desktop` ask for a shell-only machine. The CLI sends the machine **kind** (`desktop`/`base`) and the backend maps it to the image its deployment supports (today one devbox snapshot serves both kinds); `--image <id>` is the explicit override and is the only way an image id leaves the client. Supports `--size <2g|4g|8g|16g|24g|32g>`, `--name <label>` (display label, applied via `vm.rename` after create), `--provider`, `--workspace`, `--detach`, and `-d`. Without `--detach`, opens a plain terminal on the machine through the shared open path (see `vm shell`). The Machines panel's + opens the New Machine sheet (name, kind, size, plan meter) whose Create runs this same command. |
Comment thread
austinywang marked this conversation as resolved.
Resolved
| `vm base open`, `vm base reset` | Open (creating on first use) or reset the persistent Base machine. `--base` / `--desktop` choose the kind for the create; an existing Base keeps its image. The app's Cloud VM button shows the Set Up Base sheet only when no Base exists yet. |
| `vm shell`, `vm attach` | Open an interactive shell for an existing VM. Every cloud open (`vm shell` / `vm new` / `vm fork` / `vm restore` / `vm base open` / `vm base reset`, the Machines panel, the sidebar cloud button) uses one path and lands a PLAIN terminal on the machine (like an ssh session, not the cmux-tui client): `vm.cmux_remote_info` (availability and protocol check; the local client's `client_capabilities` when one is installed), then `workspace.create` or, for `--workspace`, `workspace.cloud_vm_terminal_ready` (a placeholder pane), then `workspace.cloud_vm_bind`, then `surface.new_terminal {machine, open: true, workspace_id, focus: true, name: "shell"}` — the machine's provider creates a `bash -l` terminal in its cmux-tui session (a catalog resource `<machine>/terminal/<term_…>`) and the catalog projects it into the workspace as a pane running `attach --terminal`; the placeholder is closed with `surface.close`. The `OK` line carries `terminal=<term_…>` and a `Reattach: cmux vm open <m>/<ws>/<term>` hint; `--json` adds `terminal_id`, `remote_workspace_id`, `surface_id`. `cmux vm tui <id>` is the only open that runs the full client. The websocket/SSH transports remain only for deployments whose control plane reports no cmux-tui daemon; a machine that answers `vm_attach_transport_unsupported` is cmux-tui only and never falls back. |
| `vm stats <id>`, `vm top <id>` | Print CPU, memory, and disk for the machine right now; a sleeping machine reports `asleep` and is not woken. |
| `vm desktop <id>`, `vm vnc <id>` | Open the VM's noVNC desktop as a browser pane in the machine's open workspace, else the workspace you are in (or `--workspace <id|ref|index>`); desktop-image machines only, of which there are none today (the verb and its wrapper are kept for Freestyle desktop support). One path with `vm open <id>:desktop`, the split beside `vm shell`, and the sidebar tree: `vm.desktop_open {id, workspace_id?, focus}` (focus defaults to false so the pane never steals typing from the shell). |
| `vm desktop <id>`, `vm vnc <id>` | Open the VM's noVNC desktop as a browser pane in the machine's open workspace, else the workspace you are in (or `--workspace <id|ref|index>`); desktop-kind machines only (`--base` machines have no screen). The pane opens the machine's private address on 6901 over the owner's private network (`POST /api/vm/<id>/open-port`). One path with `vm open <id>:desktop`, the split beside `vm shell`, and the sidebar tree: `vm.desktop_open {id, workspace_id?, focus}` (focus defaults to false so the pane never steals typing from the shell). |
| `vm rename <id> <label>`, `vm rename <id> --clear` | Set or clear a display label; the machine id stays its address. |
| `vm rm`, `vm destroy`, `vm delete` | Destroy a VM. |
| `vm ssh` | Open a cmux-managed SSH workspace for an existing VM. |
Expand Down
2 changes: 1 addition & 1 deletion skills/cmux-cloud-vm/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Everything the Cloud sidebar can do, from the CLI — plus agent-only primitives
| Term | Meaning |
|------|---------|
| **Machine** | A persistent cloud VM (`cmux vm ls`). Sleeps when idle (free while asleep), wakes on connect or exec. `/root` is a 16 GB persistent volume; the rest of the filesystem is disposable compute. |
| **Contents** | Ubuntu (shared devbox image): node, bun, uv, git, gh, ripgrep, fd, jq, tmux, xdotool. **Claude Code, Codex, OpenCode, and Pi are preinstalled**. Machines are shell-only today — no provider ships a desktop image, so there is no VNC screen to open. Provisioning runs in the background on first boot — `cat /tmp/cmux/provision.log` on a brand-new machine if a tool is missing. |
| **Contents** | Ubuntu 24.04 (shared devbox image): node, bun, uv, git, gh, ripgrep, fd, jq, tmux, xdotool, Chrome, `cua-driver`. **Claude Code, Codex, OpenCode, and Pi are preinstalled**. Every machine boots a desktop: TigerVNC on `:1` with an openbox session, a dock (Chrome, Files, Ghostty) and noVNC on 6901 — the **Desktop** row in the sidebar / `vm open <m>:desktop` shows it. Shells on the machine get `DISPLAY=:1` (and the accessibility bus) while the desktop is up, so `agent-browser`, `xdotool` and `cua-driver mcp` act on that screen. |
Comment thread
austinywang marked this conversation as resolved.
Resolved
| **Session** | Every machine runs the **cmux-tui remote daemon**: its own workspaces → terminals, visible in `cmux vm tree`. A terminal you start there keeps running when the Mac disconnects. |
| **Surface** | A terminal, VNC screen or browser — on This Mac or on a machine — with a stable id `<machine>/<kind>/<key>` (`cmux surface ls --json`). Panes *project* surfaces: `cmux surface open <id>` reuses the pane already showing one, or lands it at a pane edge you choose; closing a pane never kills a machine's terminal. |
| **Base** | The one pinned persistent machine (`cmux vm base open`) — use it for the user's ongoing work. |
Expand Down
106 changes: 80 additions & 26 deletions web/scripts/build-devbox-freestyle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,13 @@
* daemon still runs as root until the driver adopts the ubuntu user for
* sessions.
*
* Desktop contract (desktop/start-vnc.sh): RFB 5901 loopback, noVNC 6901,
* run as `ubuntu` by the cmux-desktop systemd unit.
* Desktop contract (web/services/vms/images/desktop.ts, desktop/start-vnc.sh):
* RFB 5901 loopback, noVNC 6901, run as `ubuntu` by the cmux-desktop systemd
* unit, which publishes DISPLAY and the accessibility bus at
* /run/cmux-desktop/env for every other shell (/etc/cmux/desktop-env.sh). The
* desktop packages, files and the Ghostty .deb come from the Dockerfile
* (devbox-image-common.ts reads them), so the container recipe and this bake
* cannot drift.
*/
import { Freestyle } from "freestyle";
import { fileURLToPath } from "node:url";
Expand All @@ -72,18 +77,32 @@ import {
resolveCmuxTuiSource,
} from "../services/vms/drivers/cmuxTuiDaemon";
import {
DEVBOX_GHOSTTY_DEB_URL,
DEVBOX_DESKTOP_INSTALLS,
DEVBOX_INSTANCE_ID_COMMAND,
bakeMetadata,
bakePreflight,
devboxAgentPins,
devboxCuaDriverVersion,
devboxDesktopPackages,
devboxFileBytes,
devboxGhosttyDebUrl,
devboxParkDaemonCommand,
emitBakeResult,
hasFlag,
manifestEntrySkeleton,
} from "./devbox-image-common";
import {
DEVBOX_DESKTOP_DISPLAY,
DEVBOX_DESKTOP_ENV_FILE,
DEVBOX_DESKTOP_HOME,
DEVBOX_DESKTOP_NOVNC_PORT,
DEVBOX_DESKTOP_RFB_PORT,
DEVBOX_DESKTOP_RUNTIME_DIR,
DEVBOX_DESKTOP_START_SCRIPT,
DEVBOX_DESKTOP_SUPERVISOR,
DEVBOX_DESKTOP_UNIT,
DEVBOX_DESKTOP_USER,
} from "../services/vms/images/desktop";

const apiKey = process.env.FREESTYLE_API_KEY;
const stackToken = process.env.FREESTYLE_STACK_ACCESS_TOKEN;
Expand Down Expand Up @@ -122,11 +141,11 @@ const BUILD_ENV = {
LANG: "C.UTF-8",
};

/** The work user: the base's uid-1000 account, the API and SSH default. */
const WORK_USER = "ubuntu";
/** The work user: the base's uid-1000 account, the API and SSH default, and the desktop session's user. */
const WORK_USER = DEVBOX_DESKTOP_USER;

const instanceIdCommand = DEVBOX_INSTANCE_ID_COMMAND;
const WORK_HOME = `/home/${WORK_USER}`;
const WORK_HOME = DEVBOX_DESKTOP_HOME;

const builderSnapshot = process.env.CMUX_FREESTYLE_BUILDER_SNAPSHOT?.trim() || "freestyle/ubuntu-sm";
const { vm, vmId } = await fs.vms.create({
Expand Down Expand Up @@ -284,43 +303,78 @@ try {
);

if (withDesktop) {
// Desktop + media stack (Blaxel cmux-devbox apt list): TigerVNC, openbox,
// tint2, Thunar, feh, noVNC + websockify, and the GL/Vulkan/xkb libraries
// Ghostty and Chrome render with under Xvnc.
// Desktop + media stack (the Dockerfile's CMUX_IMAGE_DESKTOP_PACKAGES):
// TigerVNC, openbox, tint2, Thunar, feh, noVNC + websockify, the
// accessibility bus (at-spi2-core) and D-Bus, and the GL/Vulkan/xkb
// libraries Ghostty and Chrome render with under Xvnc.
await step(
"desktop-apt",
"apt-get update -q && apt-get install -y --no-install-recommends tigervnc-standalone-server tigervnc-tools openbox tint2 thunar feh novnc websockify at-spi2-core dbus-x11 x11-xserver-utils xdg-utils adwaita-icon-theme libgl1-mesa-dri mesa-vulkan-drivers libvulkan1 libxkbcommon0 libxkbcommon-x11-0 netcat-openbsd && rm -rf /var/lib/apt/lists/* && { [ -e /usr/share/novnc/index.html ] || ln -s vnc.html /usr/share/novnc/index.html; } && command -v Xtigervnc && command -v websockify && command -v openbox && command -v tint2",
`apt-get update -q && apt-get install -y --no-install-recommends ${devboxDesktopPackages().join(" ")} && rm -rf /var/lib/apt/lists/* && { [ -e /usr/share/novnc/index.html ] || ln -s vnc.html /usr/share/novnc/index.html; } && command -v Xtigervnc && command -v vncconfig && command -v websockify && command -v openbox && command -v tint2 && command -v dbus-launch && command -v dbus-send && command -v gdbus && command -v feh && command -v thunar && { test -x /usr/libexec/at-spi-bus-launcher || test -x /usr/lib/at-spi2-core/at-spi-bus-launcher; }`,
);

// Ghostty: pinned community .deb for Ubuntu 24.04 (no upstream .deb
// exists). libgl1-mesa-dri above is the software GL its renderer uses.
// Ghostty: the Dockerfile's pinned community .deb for Ubuntu 24.04 (no
// upstream .deb exists). libgl1-mesa-dri above is the software GL its
// renderer uses.
await step(
"ghostty",
`curl -fsSL -o /tmp/ghostty.deb ${DEVBOX_GHOSTTY_DEB_URL} && apt-get update -q && apt-get install -y --no-install-recommends /tmp/ghostty.deb && rm -rf /var/lib/apt/lists/* /tmp/ghostty.deb && ghostty +version | head -1`,
`curl -fsSL -o /tmp/ghostty.deb ${devboxGhosttyDebUrl()} && apt-get update -q && apt-get install -y --no-install-recommends /tmp/ghostty.deb && rm -rf /var/lib/apt/lists/* /tmp/ghostty.deb && ghostty +version | head -1`,
);

// Dock launchers and icons live under /etc/cmux so the dock never depends
// on a distro's /usr/share/applications or icon-theme layout.
// Every desktop file, at the path the Dockerfile COPYs it to
// (DEVBOX_DESKTOP_INSTALLS is the one map). Dock launchers and icons
// live under /etc/cmux so the dock never depends on a distro's
// /usr/share/applications or icon-theme layout.
await step("desktop-dirs", "mkdir -p /etc/cmux/apps /etc/cmux/icons /usr/share/backgrounds/cmux");
await put("desktop/google-chrome-cmux.desktop", "/etc/cmux/apps/google-chrome-cmux.desktop");
await put("desktop/thunar-cmux.desktop", "/etc/cmux/apps/thunar-cmux.desktop");
await put("desktop/ghostty-cmux.desktop", "/etc/cmux/apps/ghostty-cmux.desktop");
await put("desktop/tint2rc", "/etc/cmux/tint2rc");
await put("desktop/wallpaper.jpg", "/usr/share/backgrounds/cmux/wallpaper.jpg");
await put("desktop/start-vnc.sh", "/usr/local/bin/start-vnc.sh", 0o755);
await put("desktop/cmux-desktop-boot", "/usr/local/bin/cmux-desktop-boot", 0o755);
await put("desktop/cmux-desktop.service", "/etc/systemd/system/cmux-desktop.service");
for (const install of DEVBOX_DESKTOP_INSTALLS) {
await put(install.source, install.target, install.mode);
}
await step(
"desktop-icons",
"cp /opt/google/chrome/product_logo_128.png /etc/cmux/icons/google-chrome.png && cp \"$(find /usr/share/icons -name 'org.xfce.thunar.png' -path '*128*' | head -1)\" /etc/cmux/icons/thunar.png && cp \"$(find /usr/share/icons -name 'com.mitchellh.ghostty.png' -path '*128*' | head -1)\" /etc/cmux/icons/ghostty.png && test -s /etc/cmux/icons/thunar.png && test -s /etc/cmux/icons/ghostty.png && test -s /etc/cmux/icons/google-chrome.png",
);

// Bring the desktop up under systemd as the work user and prove the
// contract ports answer. The "First Run" marker pre-accepts Chrome's
// first-run/ToS dialog (cmux-desktop-boot re-asserts it on every boot).
// contract: both ports answer (RFB loopback-only), noVNC serves its
// client, the window manager, dock, clipboard helper and accessibility
// bus run, the wallpaper is on the root window, root can reach the
// display too (cmux sessions run as root), exactly one desktop
// supervisor exists (systemd's; cmux-devbox-boot must not start a second
// one under systemd), login shells of both accounts inherit DISPLAY from
// the published env, the work user's also the accessibility and session
// buses, and cua-driver's doctor sees the display and the accessibility
// bus. The "First Run" marker pre-accepts Chrome's first-run/ToS dialog
// (cmux-desktop-boot re-asserts it on every boot).
const desktopEnvLine = `'[ -f /etc/cmux/desktop-env.sh ] && . /etc/cmux/desktop-env.sh'`;
const loginAs = (user: string, home: string, command: string): string =>
`sudo -n -u ${user} env -i HOME=${home} USER=${user} TERM=xterm PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin bash -lc '${command}'`;
await step(
"desktop-unit",
`bash -n /usr/local/bin/start-vnc.sh && sh -n /usr/local/bin/cmux-desktop-boot && grep -q '^User=${WORK_USER}$' /etc/systemd/system/cmux-desktop.service && mkdir -p ${WORK_HOME}/.config/google-chrome && touch '${WORK_HOME}/.config/google-chrome/First Run' && chown -R ${WORK_USER}:${WORK_USER} ${WORK_HOME}/.config && systemctl daemon-reload && systemctl enable --now cmux-desktop && for i in $(seq 1 60); do ss -tln | grep -q ':6901 ' && ss -tln | grep -q ':5901 ' && break; sleep 1; done && ss -tln | grep -q ':5901 ' && ss -tln | grep -q ':6901 ' && curl -fsS http://127.0.0.1:6901/ | grep -qi novnc && pgrep -u ${WORK_USER} -x openbox >/dev/null && pgrep -u ${WORK_USER} -x tint2 >/dev/null && systemctl is-active cmux-desktop && runuser -u ${WORK_USER} -- env DISPLAY=:1 xdpyinfo | grep dimensions`,
[
`bash -n ${DEVBOX_DESKTOP_START_SCRIPT} && sh -n ${DEVBOX_DESKTOP_SUPERVISOR} && sh -n /etc/cmux/desktop-env.sh`,
`grep -q '^User=${WORK_USER}$' /etc/systemd/system/${DEVBOX_DESKTOP_UNIT}.service`,
`grep -q '^RuntimeDirectory=${DEVBOX_DESKTOP_RUNTIME_DIR.replace("/run/", "")}$' /etc/systemd/system/${DEVBOX_DESKTOP_UNIT}.service`,
`echo ${desktopEnvLine} > /etc/profile.d/cmux-desktop.sh`,
...rcFiles.map((rc) => `echo ${desktopEnvLine} >> ${rc}`),
`mkdir -p ${WORK_HOME}/.config/google-chrome && touch '${WORK_HOME}/.config/google-chrome/First Run' && chown -R ${WORK_USER}:${WORK_USER} ${WORK_HOME}/.config`,
`systemctl daemon-reload && systemctl enable --now ${DEVBOX_DESKTOP_UNIT}`,
`for i in $(seq 1 90); do ss -tln | grep -q ':${DEVBOX_DESKTOP_NOVNC_PORT} ' && ss -tln | grep -q ':${DEVBOX_DESKTOP_RFB_PORT} ' && test -s ${DEVBOX_DESKTOP_ENV_FILE} && grep -q AT_SPI_BUS_ADDRESS ${DEVBOX_DESKTOP_ENV_FILE} && break; sleep 1; done`,
`ss -tln | grep -q ':${DEVBOX_DESKTOP_RFB_PORT} ' && ss -tln | grep -q ':${DEVBOX_DESKTOP_NOVNC_PORT} '`,
`ss -tln | grep ':${DEVBOX_DESKTOP_RFB_PORT} ' | grep -q '127.0.0.1:${DEVBOX_DESKTOP_RFB_PORT}'`,
`curl -fsS http://127.0.0.1:${DEVBOX_DESKTOP_NOVNC_PORT}/ | grep -qi novnc`,
`pgrep -u ${WORK_USER} -x 'Xvnc|Xtigervnc' >/dev/null && pgrep -u ${WORK_USER} -x openbox >/dev/null && pgrep -u ${WORK_USER} -x tint2 >/dev/null && pgrep -u ${WORK_USER} -x vncconfig >/dev/null && pgrep -u ${WORK_USER} -f at-spi-bus-launcher >/dev/null`,
`[ "$(pgrep -u ${WORK_USER} -f ${DEVBOX_DESKTOP_SUPERVISOR} | wc -l)" = 1 ]`,
`systemctl is-active ${DEVBOX_DESKTOP_UNIT}`,
`runuser -u ${WORK_USER} -- env DISPLAY=${DEVBOX_DESKTOP_DISPLAY} xdpyinfo | grep dimensions`,
`env DISPLAY=${DEVBOX_DESKTOP_DISPLAY} xdpyinfo >/dev/null`,
`env DISPLAY=${DEVBOX_DESKTOP_DISPLAY} xprop -root _XROOTPMAP_ID | grep -q 0x`,
`grep -q "^export DISPLAY='${DEVBOX_DESKTOP_DISPLAY}'$" ${DEVBOX_DESKTOP_ENV_FILE} && grep -q '^export AT_SPI_BUS_ADDRESS=' ${DEVBOX_DESKTOP_ENV_FILE} && grep -q '^export AT_SPI_BUS=' ${DEVBOX_DESKTOP_ENV_FILE}`,
`[ "$(env -i HOME=/root PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin bash -lc 'echo "$DISPLAY"')" = "${DEVBOX_DESKTOP_DISPLAY}" ]`,
`[ -z "$(env -i HOME=/root PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin bash -lc 'echo "$DBUS_SESSION_BUS_ADDRESS"')" ]`,
`[ "$(${loginAs(WORK_USER, WORK_HOME, 'echo "$DISPLAY"')})" = "${DEVBOX_DESKTOP_DISPLAY}" ]`,
loginAs(WORK_USER, WORK_HOME, 'test -n "$DBUS_SESSION_BUS_ADDRESS" && test -n "$AT_SPI_BUS_ADDRESS"'),
`${loginAs(WORK_USER, WORK_HOME, "cua-driver doctor")} > /tmp/cua-doctor.txt 2>&1; cat /tmp/cua-doctor.txt; grep -q 'X11 connection: connected' /tmp/cua-doctor.txt && grep -q 'AT-SPI: bus address present' /tmp/cua-doctor.txt && ! grep -q 'accessibility bus not reachable' /tmp/cua-doctor.txt && rm -f /tmp/cua-doctor.txt`,
"echo desktop-ok",
].join(" && "),
);
}

Expand Down
Loading