Overview

The Terminal API provides persistent PTY-based terminals on the Allternit Factory pane engine. Each terminal session is a real shell process owned by the pane engine: it survives API restarts and UI reconnects, replays its scrollback (the last 2 MiB) to every new stream, and reports its exit code. A terminal is a pane like any Factory agent pane: it shows in the agent wall as term-<session_id>, and an agent started in it is detected there.

Base URL

All endpoints require a valid Bearer token in the Authorization header. See Authentication for details. The API reaches the pane engine over its Unix domain socket (on Windows, a named pipe: \\.\pipe\ followed by the path ensure reports). It finds the socket with allternit-factory pane tty ensure, which also starts the pane engine when it isn’t running. To check terminals on Windows against a released Desktop installer, run the windows-terminal-smoke.yml workflow (gh workflow run windows-terminal-smoke.yml -R Allternit/allternit-platform). ALLTERNIT_FACTORY_BIN names the binary (default: allternit-factory next to allternit-api, then on PATH; Allternit Desktop sets it), and ALLTERNIT_FACTORY_PANE_SOCKET names the socket directly. See allternit-mux (folded into the Factory) for the socket methods.

Endpoints

Create terminal

Request body:
All fields are optional. Defaults: command runs that program (with args) instead of the shell, and shell is then ignored. env is added to the terminal’s environment over the fixed TERM=xterm-256color and COLORTERM=truecolor; a key that is empty or contains = or a NUL character returns 400. title is the terminal’s name in the agent wall and in the list. If shell is empty, or is an absolute path that doesn’t exist on that computer (zsh on a Linux cloud computer, for example), the terminal runs that computer’s $SHELL, else bash, else its default shell, instead of failing with ENOENT. On Windows an empty shell or any Unix path runs PowerShell. The app asks for /bin/zsh and, if an older server still answers ENOENT, asks again with an empty shell. Response:

List terminals

Returns every terminal on the pane engine, including terminals that were not created through this API. preview is optional: when set (clamped to 1-40), each terminal also carries the last N rows of its visible screen as plain text (ANSI stripped).
  • pane_id is the pane engine’s id for the terminal’s pane (the id the Factory agent wall shows). Use it to match an agent-wall pane to its terminal. It is null when the engine reports none.
  • title is the title given at create, else the terminal’s own title (set by the program running in it), else the last folder of cwd, else Terminal.
  • cwd is the live working directory from the terminal’s pane, else the one it was created with.
  • command and created_at are known only for terminals created through this API since it started; for others command is [] and created_at is null.
  • preview is left out for a terminal whose pane could not be read in time. That never fails the list.
  • Errors: 503 when the pane engine cannot be reached.

Send input

Request body:
Response:

Resize terminal

Request body:
Response:

Close terminal

The body is optional. With no body (older clients) the pane closes at once, as before.
Response:

Stream output

The response is a text/event-stream. The server first replays the kept scrollback, then streams live output. Ping events are emitted every 15 seconds when no output is available. Example event:
When the shell exits, one exit event follows its last output. The stream then stays open with pings only, so an EventSource doesn’t reconnect and replay the scrollback again. Clients that don’t know the exit type ignore it.
exit_code is null when the pane engine couldn’t read it.

Cloud computers

On a cloud computer (or a Mac running allternit-node with Desktop quit), the same routes reach the computer’s allternit-node daemon through the runtime relay. It serves them in one of two ways:
  • Pane engine (the computer’s allternit-factory pane server answers): the same service and JSON as on Desktop. Terminals survive an allternit-node restart, /terminal/list returns titles, preview rows and pane_id, create takes command/args/env/title, and close takes {"graceful": true}.
  • Fallback (no pane engine on the image, for example Orgo, headless or older images): the node runs the terminals itself. Create takes the same body, and /terminal/list returns them with pane_id: null and no preview. These terminals end when allternit-node restarts, and a graceful close is a plain close.
/terminal/list on a cloud computer also returns a top-level engine field that says which one is serving:
engine is "pane" or "missing". The node never starts the pane engine. While none has answered, it checks again at most every 30 seconds. See cmd/allternit-node/README.md for the socket paths it checks.

Browser computer

The browser computer (see Browser computer) does not use these endpoints. Its Terminal attaches to the pty inside the browser tab, so there is no server websocket and no session on the pane engine. It does not appear in /terminal/list.

Error codes

Input and resize on a terminal whose shell already exited succeed and do nothing, as typing into a closed terminal does. Close always succeeds.