> _**CLI skill · `terminal` namespace** · ~9,820 tokens · hoody-sdk v1.0.0-beta.17_ # `terminal` — Persistent multiplayer PTY sessions over HTTP and WebSocket ## Purpose Real PTY per container, numeric `terminal_id` (1–65535). REST + WebSocket. Multiplayer; sessions persist. ## When to use - **Interactive TUIs** that paint the screen (Claude Code, Codex, vim, htop, less, fzf, ssh, etc.) — these need a real PTY; only `terminal` provides one. - **Durable / long-lived programs that you may need to interact with later** (the agent you spawned, a coding assistant, a chat REPL) — pin a stable `terminal_id` (1–39999) and reattach over WS or REST. When it must be supervised (restarted on exit, started at boot), run it as a `daemon` program with `terminal_id` instead: its terminal is attached the same way (see "Daemon program terminals" below). - Sequenced commands sharing shell state, keystroke automation, screen capture, regex-search the rendered buffer. - SSH / SOCKS5 sessions (`ssh_*` / `socks5_*`). - Host introspection (`hoody terminal system *`). **Pin a unique `terminal_id` per program.** Re-using the same `terminal_id` for multiple programs writes both into the same PTY (output interleaves, prompts collide). Pick a distinct id per concurrent process. A session made by `hoody terminal sessions create` renders on a display only when given `display: N` (the id never sets it); a session first created by `hoody terminal commands run` takes its display from the request URL instead (see Quirks). Keeping ids distinct keeps each terminal-to-display pairing one-to-one. **Never start a durable program with `ephemeral=true`** — ephemeral terminals auto-allocate from `40000–65535`, and once one sits inactive with no attached WebSocket client it is removed and its process force-killed: after 60 s when it holds no results, otherwise after `ephemeral-result-timeout` (300 s default). Your Claude Code / Codex session would die at that point. ## When NOT to use - Headless background process you don't need to interact with → `daemon` (supervised, log-captured, auto-restart). - A script that should be callable over HTTP → `exec`. (A one-off shell command fits `terminal` itself: ephemeral, workflow 2. When its logs must outlive the response, use `hoody daemon ephemeral programs start`.) - File I/O → `files`. GUI rendering → `display`. Schedule → `cron`. ## Prerequisites - Container with `terminal` kit running; capability URL. - SSH needs reachable `ssh_host:ssh_port`; automation needs existing `terminal_id`. ## Capability URL → See `SKILL-CLI.md § Proxy URLs`. **Reaching a service you host on a container port** (any port, any namespace): - `https://{projectId}-{containerId}-http-.{node}.containers.hoody.com` — proxy speaks HTTP to `localhost:`. - `https://{projectId}-{containerId}-https-.{node}.containers.hoody.com` — proxy speaks HTTPS to `localhost:` (target needs TLS). Edge is always `https://`. No alias, firewall edit, or proxy registration needed; capability-token gates still apply. ## Common workflows ### 1. Persistent interactive session `hoody terminal sessions create` (pin `terminal_id` or `ephemeral=true`) → `hoody terminal commands run` (body `wait` defaults to `true` and asks for a synchronous result, but SSH sessions, `defer_pid` commands and a server at its concurrent-wait cap answer asynchronously — check `status` and poll `hoody terminal commands get` by `command_id`; send body `wait: false` for an async `command_id`; shares shell state) → `hoody terminal commands get` → `hoody terminal sessions read`/`hoody terminal sessions screenshots capture` → `hoody terminal sessions delete`. Use `hoody --container "$C" terminal commands run --terminal-id --command '' --no-wait -o json` to start asynchronously and keep the returned `command_id`. ### 2. Ephemeral one-off execute `hoody terminal commands run` `ephemeral=true`, `wait=true` — auto ID 40000–65535, runs `command`, cleans up. Through the proxy, send it to the `terminal-0` hostname: any other `terminal-N` host pins the request to terminal N, so the command runs inside that terminal and every later execute on that host waits behind it for up to 600 s if it hangs. Later: `hoody terminal commands get` before the session goes: an ephemeral session holding results is removed after `ephemeral-result-timeout` (300 s default) of inactivity with no attached client. ### 3. Automate a TUI `hoody terminal sessions create` (or `hoody terminal commands run` to launch) → `hoody terminal sessions press` (`Down`/`Enter`/`F2`; `hoody terminal keys list`) → `hoody terminal sessions paste` (`bracketed=true`) → `hoody terminal sessions wait` (`mode`: `stable`, `regex` with a `pattern`, or `either`) → `hoody terminal sessions snapshot get`/`hoody terminal sessions search`. ### 4. Live stream — WebSocket `hoody terminal sessions connect` at `/api/v1/terminal/ws?terminal_id=…` on the session's `terminal-N` host. After the socket opens, the client must send the initial JSON dimensions message (`{"columns":…,"rows":…}`) before the server sends output. Multiple WS clients attach simultaneously; writes broadcast to PTY. The CLI has no streaming WebSocket reader: `hoody shell --terminal-id N` attaches an interactive PTY instead. Inject from REST via `hoody terminal sessions write` or `hoody terminal sessions press`. `hoody terminal commands cancel` interrupts by `command_id`. ### 5. Container introspection `hoody terminal processes list`, `hoody terminal processes get`, `hoody terminal processes signal`, `hoody terminal system ports list`, `hoody terminal system stats`, `hoody terminal system displays list`, `hoody terminal system daemon programs list`, `hoody terminal system reboot`/`hoody terminal system shutdown`. `hoody terminal processes list` and `hoody terminal system ports list` answer in a single response with no pages (`hoody terminal processes list` takes `limit`, `sort` and `filter`). Add `-o json` to get the full response bodies. ### 6. Spawn a durable agent CLI (Claude Code, Codex, …) and reattach later For interactive coding agents and other long-lived TUIs the user may detach from and come back to: 1. Pick an unused `terminal_id` (1–39999, **never** the ephemeral range 40000–65535, **never** re-use one another program is on). 2. `hoody terminal sessions create` with that pinned id, `ephemeral: false`, `shell: '/bin/bash'`, `cwd: '/home/user'` (or wherever). 3. `hoody terminal commands run` with body `command: 'claude'` (or `codex`, `aider`, `gemini …`) and body `wait: false` so the agent stays alive in the PTY rather than being treated as a sync request. In the CLI: `hoody --container "$C" terminal commands run --terminal-id --command claude --no-wait -o json`. 4. Reattach any time: `hoody --container "$C" shell --terminal-id ` for an interactive attach (multiplayer — multiple viewers / scripts can attach to the same PTY simultaneously), or drive it with `hoody terminal sessions press` / `paste`. 5. Tear down only when really done: `hoody terminal sessions delete `. The session persists until explicitly deleted or hit by `terminal-idle-timeout` (300 s default with zero attached clients and no running process). Sessions are in-memory only — a container reboot kills the PTY and drops the session; re-create after a reboot. Two concurrent agents → two distinct `terminal_id`s (e.g. Claude Code on `1`, Codex on `2`). If a session needs a display, pass `display: N` explicitly on `hoody terminal sessions create`; distinct ids keep that pairing one-to-one. ### 7. Launch a GUI app + control it via the display kit Spin up a terminal, launch any X11 program, then drive it from the paired `display-` kit. **You must explicitly pair the IDs** — the kit injects `DISPLAY` from the JSON `display` field on `hoody terminal sessions create`; there is no automatic `terminal_id ⇒ DISPLAY=:N` mapping. 1. `hoody terminal sessions create` with a pinned `terminal_id` (e.g. `1`) AND a matching `display: "1"` field (string in the SDK type), so the kit exports `DISPLAY=:1` into the PTY. 2. From that session: `hoody terminal commands run` `command: 'xeyes &'` (or `firefox &`, `gimp &`, `chromium-browser &`, `code &`, `xterm &`, …). The `&` returns the PTY immediately so the shell stays interactive; the GUI continues under `display-1`. 3. Open the matching display kit URL — `https://{projectId}-{containerId}-display-1.{node}.containers.hoody.com` (read `projectId`, `containerId`, and `server_name` from `hoody containers get`). 4. Drive the GUI via the `display` namespace: - `hoody display screenshots capture` — see what's on screen (turn `base64` on for vision agents). - `hoody display input click --x --y --button