Skip to main content

Module base

Module base 

Source
Expand description

AgentMux base utilities: directory management, lock files, environment, platform detection. Port of Go’s pkg/base/.

Structs§

MuxLock
File-based lock for single-instance enforcement.

Constants§

CONFIG_DIR
DOMAIN_SOCKET_BASE_NAME
MUX_APP_PATH_ENV
MUX_CONFIG_HOME_ENV
MUX_DATA_HOME_ENV
MUX_DB_DIR
MUX_DEV_ENV
MUX_DEV_VITE_ENV
MUX_JWT_TOKEN_ENV
MUX_LOCK_FILE
MUX_SWAP_TOKEN_ENV
REMOTE_DOMAIN_SOCKET_BASE_NAME
REMOTE_FULL_DOMAIN_SOCKET_PATH
REMOTE_MUX_HOME_DIR_NAME
SRV_DATA_LOCK_FILE
File srv locks in the directory holding its databases.

Statics§

BUILD_TIME 🔒
DATA_DIR_LOCKS 🔒
Data-dir locks this process holds, kept for its lifetime.
MUX_VERSION 🔒

Functions§

acquire_data_dir_lock
Take srv’s exclusive lock on data_dir (<data_dir>/srv.lock): one srv per set of databases, however each was started — launcher, host or --headless (SPEC_SRV_HEADLESS_MODE §3.2; Codex P1 on #3893). Idempotent within a process, so headless setup can take it early and bootstrap again later. Advisory flock on Unix; not exclusive elsewhere (see MuxLock).
client_arch
Get the client architecture string (“os/arch”).
copy_dir_all 🔒
Recursively copy a directory tree.
determine_lang
Determine the system language.
ensure_dir
Ensure a directory exists with the given permissions.
ensure_mux_config_dir
Ensure the AgentMux config directory exists.
ensure_mux_data_dir
Ensure the AgentMux data directory exists.
ensure_mux_db_dir
Ensure the AgentMux DB directory exists.
ensure_mux_presets_dir
Ensure the AgentMux presets directory exists.
expand_home_dir
Expand ~ at the start of a path to the home directory. Rejects ~user/ and paths containing .. components (path traversal).
expand_home_dir_safe
Safe version of expand_home_dir that returns the original on error.
get_build_time
Get the build time.
get_domain_socket_name
Get the domain socket path.
get_home_dir
Get the user’s home directory.
get_mux_app_bin_path
Get the AgentMux app bin path.
get_mux_app_path
Get the AgentMux app path from env.
get_mux_config_dir
Get the AgentMux config directory. Uses AGENTMUX_CONFIG_HOME env var, or defaults to ~/.agentmux/config.
get_mux_data_dir
Get the AgentMux root directory (~/.agentmux).
get_mux_db_dir
Get the AgentMux DB directory (~/.agentmux/db).
get_mux_lock_file
Get the AgentMux lock file path.
get_system_summary
Get a system summary string.
get_version
Get the application version.
has_drive_letter_prefix 🔒
True if s starts with <ASCII letter>: — a Windows drive-letter prefix. Both rooted (C:\foo) and drive-relative (C:foo) forms match. Used by safe_join_within_base to reject paths that would rebase off the working directory under Windows path semantics.
is_dev_mode
Check if AgentMux is in dev mode.
migrate_legacy_data_dir
Migrate data from ~/.waveterm to ~/.agentmux if needed. Called once at startup. No-op if ~/.agentmux already exists.
msys_to_windows_path
Convert an MSYS / Git-Bash POSIX drive path to a native Windows path.
normalize_working_dir
Normalize a user/agent-supplied working directory for use with Command::current_dir: first convert MSYS/Git-Bash POSIX drive paths to native Windows form (see msys_to_windows_path), then expand a leading ~. Returns None for an empty/whitespace input.
replace_home_dir
Replace the home directory prefix with ~.
safe_join_within_base
Lexically join relative onto base while guaranteeing the result stays inside base. No filesystem access — does not require either path to exist, which matters on Windows where Path::canonicalize adds the \\?\ UNC prefix and breaks naive starts_with checks against not-yet-created files.
set_build_time
Set the build time (called once at startup).
set_version
Set the application version (called once at startup).
verify_no_symlink_escape
After a lexical join, verify that no symlinked ancestor of the candidate path escapes base_canonical. The lexical helper alone can’t catch this: if <base>/.claude is a symlink to /tmp/outside and the caller writes <base>/.claude/commands/startup.md, the final write follows the symlink and lands outside the working dir.