Skip to main content

Module headless

Module headless 

Source
Expand description

Headless mode: srv started directly — a container entrypoint, a server, CI — with no launcher or desktop host. docs/specs/SPEC_SRV_HEADLESS_MODE_2026_09_26.md.

Normally the launcher prepares srv’s world before spawning it: the data-path env (DataPaths::to_env_vars), a per-launch auth key, and a stdin pipe and parent process whose end means “shut down”. Headless srv does that itself:

  • resolves and exports the data-path env when it isn’t already set;
  • takes srv’s data-dir lock early (the same lock every srv takes), so no two servers — headless or launcher-started — share a set of databases;
  • takes its auth key from AGENTMUX_AUTH_KEY, --auth-key-file, or generates one and writes it to <data dir>/srv-auth-key (0600) — the key is never printed, only the file’s path;
  • keeps secrets in owner-only files under the shared dir instead of the OS keychain, which a container usually doesn’t have (--secret-store keychain to use the keychain anyway);
  • joins the LAN and the cloud relay as the desktop app does, on the same settings and the same checks: network:lan_discovery (off until the person turns it on) adds the LAN listeners and the mDNS advertisement, and the relay connects once the channel has its own sign-in;
  • is not tied to stdin or a parent process (main skips those watchers); SIGINT/SIGTERM still shut it down.

Its startup listeners are loopback (--web-port / --ws-port fix the ports), and the web UI is served there only. Another AgentMux reaches it over the LAN or the relay the way it reaches a desktop one: through the LAN listeners the supervisor adds on those ports when network:lan_discovery is on, behind the LAN key and the pins. A browser on another machine is a reverse proxy’s job, not srv’s. For a client behind such a proxy, --frontend-dir serves the built frontend and --allowed-origin names the proxy’s origin for CORS and the /ws check.

Structs§

WebOptions 🔒

Enums§

Listener
Which startup listener a bind address is for.

Constants§

ALLOWED_ORIGIN_ENV
The environment variable a launcher that starts srv per run gives its one allowed origin in (a hosted workspace is served at a host of its own), as --allowed-origin would.
AUTH_KEY_FILE_NAME
File name of the generated auth key, beside the databases.
MIN_PROVIDED_KEY_CHARS 🔒
The fewest characters a key srv did not generate may have when srv serves its own UI. The sign-in’s proof (/auth/hello) is a MAC under the key over values anyone can send, so a short key could be guessed offline from it; a generated key is 64 characters.

Statics§

ACTIVE 🔒
Set once prepare_env succeeded: this process is the headless server.
DATA_DIR 🔒
The directory srv keeps its databases in (--wavedata, else the resolved data dir), set once headless started.
KEY_FILE 🔒
The file the key was read from or written to, when it came from a file (not the environment).
PORTS 🔒
--web-port / --ws-port, held in-process (never in the env, so a launcher-spawned srv or an agent can’t inherit them — ReAgent P1 on #3893).
SESSION_BINDING 🔒
What the file of kept browser sessions is bound to: nothing for a key srv generated (new at every start), the key itself for one the person provided.
WEB 🔒
--frontend-dir / --allowed-origin, held in-process like the ports.

Functions§

active
Is this process running headless (after prepare_env)?
bind_addr_with 🔒
bind_exclusive 🔒
Bind a listener for this server’s own use of its address. Windows lets programs share an address when they ask to (SO_REUSEADDR), and a program that did could then receive connections meant for this server, the sign-in among them; with SO_EXCLUSIVEADDRUSE the address is this server’s alone and any other bind of it is refused, whatever it asks for. Elsewhere the system already refuses a second bind.
bind_exclusive_to 🔒
check_env_key 🔒
The key from the environment, when there is one, held to the floor.
check_key_floor 🔒
data_dir
The data directory this headless srv uses (the one its databases and key file are in), when headless.
effective_data_dir 🔒
The directory srv will open its databases in: --wavedata if given (the same precedence Config::from_env_and_args applies), else resolved.
env_key 🔒
AGENTMUX_AUTH_KEY, as the launcher or the operator gave it (stashed at start, or still in the environment).
frontend_dir
The directory --frontend-dir named, when headless and given.
is_extra_allowed_origin
Is origin one --allowed-origin named? Always false for a srv that isn’t headless.
key_file_path
Where this user’s headless srv keeps its generated key: <data dir>/srv-auth-key, with the data dir resolved the way prepare_env does.
local_sign_in
Does this headless srv serve its own UI, so a browser signs in to it? (--frontend-dir.)
normalize_origin 🔒
An origin as browsers send it, via the WHATWG URL parser browsers use: http or https, a host, an optional port — no path, user, query or fragment. Serialized the way Origin is: lowercase, IDNA hosts in punycode, canonical IPv4/IPv6, and no default port, so every spelling of one origin compares equal (Codex P2s on #3900). A trailing / is fine.
normalize_public_origin 🔒
The one origin a loopback sign-in accepts besides srv’s own: http://127.0.0.1:<port>, the other end of a tunnel. Never a real host name, localhost, another address or https: a browser on a non-loopback origin needs a design of its own (SPEC_HEADLESS_SERVER_PACKAGE_AND_LOCAL_WEB_UI §3).
origin_in 🔒
per_run_origin 🔒
The origins to allow once AGENTMUX_ALLOWED_ORIGIN is taken into account. Unset or empty: --allowed-origin as given. Set: exactly that one origin, and nothing else (so a request from any other origin, including one an earlier launch allowed, is refused). It must be one https origin (a host, an optional port, no path, no wildcard, no list), and a --allowed-origin given too must name the same origin: srv refuses to start on a launch whose two forms disagree, rather than pick one.
port_file_path 🔒
The file that holds a headless srv’s web port, beside its key file: <key file>.port. One name per key file, so the port is read for the server that key belongs to.
prepare_env
Prepare the environment the launcher would normally provide. Runs before logging is initialized, so problems are returned for main to print. Returns the path the auth key was written to, when it generated one.
public_origin
--public-origin, when given.
publish_port 🔒
Write the web port beside the key file (owner-only), so agentmux-srv open finds this server without being told the port. Only a headless srv that serves its own UI and whose key came from a file. The file is replaced at every start and removed at a clean exit; after a crash it can name a port nobody listens on, or one another program now holds, which open meets with its proof of the key and refuses.
read_key_file 🔒
Read a key from a file the operator provided; surrounding whitespace is ignored.
read_port_file 🔒
The web port the server that owns key_file wrote beside it.
read_provided_key_file 🔒
A key file the operator provided, held to the floor.
requested
Is this the headless server starting (--headless or AGENTMUX_HEADLESS=1)? Never for a subcommand such as migrate: it needs none of the headless setup, and its lock would refuse a migrate --verify run beside a running headless server (ReAgent P1 on #3893).
requested_from 🔒
session_file 🔒
Where the browser sessions are kept across a restart (the data root’s sessions.bin) and what the file is bound to. Only a headless srv that serves its own UI.
startup_bind_addr
The address a startup listener binds: STARTUP_BIND_ADDR (loopback, OS-chosen port) — or, headless only, the same loopback host with the port --web-port / --ws-port gave. A non-headless srv always gets the default.
web_options 🔒
withdraw_port_file 🔒
Remove the port file at a clean exit.
write_generated_key 🔒
Generate a fresh key and write it to <dir>/srv-auth-key, readable by the owner only. A new key every start, like a launcher-spawned srv.