A modern terminal with a built-in multiplexer: close it and your sessions keep running. Run shells and tons of AI agents across your machines, then pick them up from desktop, browser, TUI and more. Written in Rust with no UI framework: interface drawn straight on the GPU. No Electron, GPUI or webview.
Rust agentagent-orchestrationaiai-agentsclaude-codecodexcoding-agentlinuxmacosmultiplayermultiplexerrustterminalterminal-emulatorterminal-multiplexertmuxtuiweztermwindows
use config::{ConfigHandle, SshMultiplexing};
use mux::domain::{Domain, LocalDomain};
use mux::ssh::RemoteSshDomain;
use mux::Mux;
use std::sync::Arc;
use wezterm_client::domain::{ClientDomain, ClientDomainConfig};
pub mod connections;
pub mod dispatch;
pub mod foreign_panes;
#[cfg(any(unix, windows))]
pub mod handoff;
#[cfg(target_os = "macos")]
pub mod hold;
pub mod session_import;
pub mod local;
pub mod pki;
mod plugin_relay;
pub mod privacy;
mod private_file;
mod sent_images;
pub mod sessionhandler;
pub mod share;
pub mod thinkterm_access;
pub mod thinkterm_layout;
pub mod thinkterm_session;
pub mod thinkterm_tree;
pub mod web_auth;
pub mod web_control;
pub mod web_http;
pub mod web_relay;
pub mod web_stream;
pub mod web_tls;
fn client_domains(config: &config::ConfigHandle) -> Vec<ClientDomainConfig> {
let mut domains = vec![];
for unix_dom in &config.unix_domains {
domains.push(ClientDomainConfig::Unix(unix_dom.clone()));
}
for ssh_dom in config.ssh_domains().into_iter() {
if ssh_dom.multiplexing == SshMultiplexing::WezTerm {
domains.push(ClientDomainConfig::Ssh(ssh_dom.clone()));
}
}
for tls_client in &config.tls_clients {
domains.push(ClientDomainConfig::Tls(tls_client.clone()));
}
domains
}
/// Keeps the plugin host up for as long as this server runs while a plugin
/// runs always, as the desktop does: those run while ThinkTerm runs on the
/// machine, and on a host with no desktop this server is ThinkTerm.
pub fn keep_plugin_host_up() {
thinkterm_plugin_channel::client::keep_host_up();
}
pub fn update_mux_domains(config: &ConfigHandle) -> anyhow::Result<()> {
update_mux_domains_impl(config, false)
}
pub fn update_mux_domains_for_server(config: &ConfigHandle) -> anyhow::Result<()> {
update_mux_domains_impl(config, true)
}
fn update_mux_domains_impl(config: &ConfigHandle, is_standalone_mux: bool) -> anyhow::Result<()> {
let mux = Mux::get();
thinkterm_access::initialize_mux(&mux);
thinkterm_layout::initialize_mux(&mux);
for client_config in client_domains(&config) {
if mux.get_domain_by_name(client_config.name()).is_some() {
continue;
}
let domain: Arc<dyn Domain> = Arc::new(ClientDomain::new(client_config));
mux.add_domain(&domain);
}
for ssh_dom in config.ssh_domains().into_iter() {
if ssh_dom.multiplexing != SshMultiplexing::None {
continue;
}
if mux.get_domain_by_name(&ssh_dom.name).is_some() {
continue;
}
let domain: Arc<dyn Domain> = Arc::new(RemoteSshDomain::with_ssh_domain(&ssh_dom)?);
mux.add_domain(&domain);
}
for wsl_dom in config.wsl_domains() {
if mux.get_domain_by_name(&wsl_dom.name).is_some() {
continue;
}
let domain: Arc<dyn Domain> = Arc::new(LocalDomain::new_wsl(wsl_dom.clone())?);
mux.add_domain(&domain);
}
for exec_dom in &config.exec_domains {
if mux.get_domain_by_name(&exec_dom.name).is_some() {
continue;
}
let domain: Arc<dyn Domain> = Arc::new(LocalDomain::new_exec_domain(exec_dom.clone())?);
mux.add_domain(&domain);
}
for serial in &config.serial_ports {
if mux.get_domain_by_name(&serial.name).is_some() {
continue;
}
let domain: Arc<dyn Domain> = Arc::new(LocalDomain::new_serial_domain(serial.clone())?);
mux.add_domain(&domain);
}
if is_standalone_mux {
if let Some(name) = &config.default_mux_server_domain {
if let Some(dom) = mux.get_domain_by_name(name) {
if dom.is::<ClientDomain>() {
anyhow::bail!("default_mux_server_domain cannot be set to a client domain!");
}
mux.set_default_domain(&dom);
}
}
} else {
if let Some(name) = &config.default_domain {
if let Some(dom) = mux.get_domain_by_name(name) {
mux.set_default_domain(&dom);
}
}
}
Ok(())
}
lazy_static::lazy_static! {
pub static ref PKI: pki::Pki = pki::Pki::init().expect("failed to initialize PKI");
}