Module runtime_mode

Module runtime_mode 

Source
Expand description

Runtime mode detection — single source of truth.

The launcher computes RuntimeMode::current once at startup and propagates the result to host + srv via the AGENTMUX_RUNTIME_MODE environment variable. No binary should call [current] more than once per process; downstream binaries read the env var via [from_env] instead.

Replaces the legacy mix of cfg!(debug_assertions), env::var ("AGENTMUX_DEV").is_ok(), and == Ok("1") checks across launcher, host, and sidecar — which were each correct in isolation but desynchronized in combination (see docs/specs/ SPEC_DATA_DIR_UNIFICATION_2026-05-05.md §2.1).

§Detection priority

  1. AGENTMUX_RUNTIME_MODE env override (testing, CI).
  2. Marker-based portable detection: an agentmux-portable.marker file written by scripts/package-portable.sh. Looked for next to the detecting exe, one level down in runtime/ (the packaging puts it there to keep the extract root clean; the launcher is at the root and the host/srv run from runtime/), and two levels up for macOS .app bundles.
  3. Path-based dev detection: exe is under a known dev-build dir (dist/cef-dev/, target/debug/, target/release/).
  4. AGENTMUX_DEV_BRANCH env override (CI override for dev mode).
  5. Default: Installed.

Enums§

RuntimeMode
Where this AgentMux binary is running from. Determines data path layout (see crate::DataPaths).

Functions§

derive_clone_id
Walk up from exe_dir looking for a workspace-root marker, then hash that absolute (canonical) path with FNV-1a and return a 16-char hex string. Used as the per-clone discriminator in ~/.agentmux/dev/<branch>/<clone_id>/. Returns None if no marker is found (extreme edge case — task dev always runs from inside a clone with .git/Cargo.toml/Taskfile.yml).
is_dev_build_exe
True when this binary is running from one of our known dev-build output directories (dist/cef-dev/, target/debug/, target/release/). Walks ancestors to handle nested cases (CEF subprocesses run from a runtime/ subdir even in dev). Path-only — does not read env.
is_dev_self
True iff THIS binary is a source-tree / task dev build, determined from the binary’s path + portable marker via RuntimeMode::current_path_only — NOT from AGENTMUX_RUNTIME_MODE. A running task dev AgentMux exports AGENTMUX_RUNTIME_MODE=dev:<branch> into its environment, which every descendant process inherits; a packaged build launched from a terminal / agent pane inside a dev instance would otherwise mis-identify as Dev (e.g. the “DEV” status-bar badge on a release build). Build identity is a property of the binary on disk, not of whoever launched it.