Skip to main content

agentmux_launcher/
main.rs

1// Copyright 2025-2026, AgentMux Corp.
2// SPDX-License-Identifier: Apache-2.0
3
4// AgentMux Launcher — Sets DLL search path then spawns srv + the CEF host.
5//
6// Phase B.1: launcher now spawns srv directly (sibling of host) so srv
7// survives host crashes. Both children are assigned to the launcher's
8// Job Object J0 with KILL_ON_JOB_CLOSE; killing the launcher reaps
9// the entire tree atomically via the OS.
10//
11// This was previously a tiny sync wrapper that just SetDllDirectoryW'd
12// runtime/ then spawned the CEF host. Phase B grew it into the
13// privileged owner per
14// docs/specs/SPEC_WINDOW_PROCESS_STATE_MACHINE_2026_04_27.md.
15//
16// Process tree after B.1:
17//   launcher (J0)
18//     ├── srv     (assigned to J0; survives host crash)
19//     └── host    (assigned to J0; CEF render workers inherit J0)
20
21#![cfg_attr(
22    all(not(debug_assertions), target_os = "windows"),
23    windows_subsystem = "windows"
24)]
25
26mod autostart;
27mod background_config;
28mod binary_resolution;
29mod data_dir;
30mod diag;
31mod event_log;
32mod hash;
33mod host_pipe;
34mod host_quit;
35mod quit_ask;
36mod host_spawn;
37mod incidents;
38mod ipc;
39mod job_object;
40mod lan_firewall;
41mod logging;
42mod mem_supervisor;
43// OS toast presenter (SPEC_OS_NOTIFICATIONS_SYSTEM_2026_09_24). Started by the
44// Windows and Linux supervisors; macOS has no backend yet (§6.2).
45#[cfg_attr(target_os = "macos", allow(dead_code))]
46mod notify;
47#[cfg_attr(not(target_os = "windows"), allow(dead_code))]
48mod old_versions;
49mod start_at_login;
50mod other_instances;
51mod reducer;
52mod saga;
53mod second_instance;
54mod launch_link;
55mod supervisor;
56mod teardown_backstop;
57mod tray;
58mod ui_liveness;
59// Windows-only consumer (supervisor/windows.rs); pure parts are tested everywhere.
60#[cfg_attr(not(target_os = "windows"), allow(dead_code))]
61mod host_hang_dump;
62mod upgrade;
63mod updating_window;
64mod upgrade_restart;
65mod version_flag;
66// Windows's "Upgrade & restart": the AgentMux window the dialog sits over (upgrade_restart.rs).
67#[cfg(target_os = "windows")]
68mod upgrade_window;
69// Linux's "Upgrade & restart": its targets, its dialog (upgrade_restart.rs).
70mod upgrade_linux;
71// Linux's .deb/.rpm upgrade: the password prompt and the install helper (upgrade_restart.rs).
72#[cfg(target_os = "linux")]
73mod upgrade_package;
74// macOS's "Upgrade & restart": the .dmg, its dialog and the swap
75// (upgrade_restart.rs); the pure parts build and are tested everywhere.
76#[cfg_attr(not(target_os = "macos"), allow(dead_code))]
77mod upgrade_macos;
78#[cfg(target_os = "windows")]
79mod splash;
80#[cfg(target_os = "macos")]
81mod splash_mac;
82#[cfg(target_os = "linux")]
83mod splash_linux;
84// Splash footer support. The baked font + software text blitter are only used by
85// the software-buffer backends (Linux, Windows); macOS renders native text.
86#[cfg(any(target_os = "linux", target_os = "windows"))]
87mod splash_font;
88#[cfg(any(target_os = "linux", target_os = "windows"))]
89mod splash_text;
90mod splash_config;
91mod splash_core;
92mod splash_info;
93#[cfg(target_os = "windows")]
94mod store_restart;
95mod startup_events;
96// srv hang-while-alive detection plugs into srv recycle-on-exit
97// (SRV_RESTART_BUDGET, supervisor/mod.rs), which is Windows-only today.
98#[cfg(target_os = "windows")]
99mod srv_liveness;
100mod srv_spawner;
101#[cfg(unix)]
102mod stale_srv;
103mod state;
104mod verify_update;
105mod wrr;
106
107use binary_resolution::find_cef_binary;
108use logging::log;
109
110/// Suppress the Windows "Application Error" / WER crash dialog so an unhandled
111/// fault terminates the process immediately instead of wedging it behind a
112/// modal. No-op off Windows. Spec:
113/// docs/specs/SPEC_SERVICE_SUPERVISION_AND_RECOVERY_2026_05_20.md.
114#[cfg(target_os = "windows")]
115fn suppress_os_crash_dialogs() {
116    use windows_sys::Win32::System::Diagnostics::Debug::{SetErrorMode, SEM_FAILCRITICALERRORS};
117    use windows_sys::Win32::System::ErrorReporting::{WerSetFlags, WER_FAULT_REPORTING_NO_UI};
118    unsafe {
119        // Suppress the WER crash-dialog UI WITHOUT disabling WER itself —
120        // SEM_NOGPFAULTERRORBOX would also kill WER/LocalDumps crash-dump
121        // collection, the postmortem diagnostics this stability work needs.
122        // WER_FAULT_REPORTING_NO_UI is the documented "no UI, keep
123        // reports" path.
124        let _ = WerSetFlags(WER_FAULT_REPORTING_NO_UI);
125        // SEM_FAILCRITICALERRORS suppresses the critical-error handler
126        // (e.g. "no disk in drive" popups) — unrelated to crash reporting.
127        SetErrorMode(SEM_FAILCRITICALERRORS);
128    }
129}
130
131#[cfg(not(target_os = "windows"))]
132fn suppress_os_crash_dialogs() {}
133
134/// Process entry point. `suppress_os_crash_dialogs()` runs FIRST — before the
135/// Tokio runtime is built. The runtime is built explicitly here (rather than
136/// via `#[tokio::main]`, whose generated wrapper would construct it before any
137/// of our code runs) so a fault during runtime construction can't surface the
138/// Windows crash modal either. Spec:
139/// docs/specs/SPEC_SERVICE_SUPERVISION_AND_RECOVERY_2026_05_20.md.
140fn main() {
141    // `--version`/`-V` prints the version; `--verify-update`: the root helper of a .deb/.rpm upgrade
142    // asks for a package to be checked against the signed manifest; `--updating-window`: see `updating_window`. Nothing else starts.
143    if let Some(code) = version_flag::run_if_requested(&launch_link::own_args()).or_else(|| verify_update::run_if_requested(&launch_link::own_args())).or_else(|| lan_firewall::run_if_requested(&launch_link::own_args())).or_else(|| updating_window::early(&launch_link::own_args())) {
144        std::process::exit(code);
145    }
146    agentmux_common::dev_home_guard::refuse_or_continue_current_exe(); // a dev build by hand has no isolated home
147    agentmux_common::test_offscreen::begin("launcher"); // a test build that cannot keep its windows off the screen refuses to start
148    // Before any thread or child exists: an instance key inherited from the shell that
149    // started this launcher goes no further; the launcher mints its own for srv and the host.
150    agentmux_common::secret_env::discard_startup_secrets();
151    suppress_os_crash_dialogs();
152    logging::install_panic_hook();
153
154    // Dev/demo affordance: `--splash-selftest` shows the splash in isolation
155    // (no srv/host), holds it briefly, then exits — for eyeballing the footer +
156    // layout. See SPEC_SPLASH_USERINFO_AND_DISABLE_2026_06_21.md.
157    if launch_link::own_args().iter().any(|a| a == "--splash-selftest") {
158        splash_selftest();
159        return;
160    }
161
162    // Auto-start control verbs (issue #2977 WS2). Handled before any heavy
163    // startup work — they must not spawn srv/host or disturb a running
164    // instance. Gives an uninstaller a callable removal path, which is what
165    // Workstream 4 requires.
166    {
167        // Before anything reads it, and before any child could inherit it.
168        autostart::startup();
169        let args = launch_link::own_args();
170        if autostart::handle_cli(&args) {
171            return;
172        }
173        // Background-service mode + tray: resolve from env / `--background` /
174        // settings and export into OUR env, before any thread or child exists.
175        // Everything below (macOS headless pump, tray, host spawn) reads it.
176        // SPEC_OS_NOTIFICATIONS_SYSTEM_2026_09_24.md §4.1.
177        background_config::apply(&args);
178    }
179
180    // Windows: the launcher keeps the handles CreateProcess gave it for srv and the host, so its
181    // own access list matters as much as theirs. Linux and macOS have no such handle to take.
182    #[cfg(windows)]
183    agentmux_common::process_hardening::deny_memory_access(false);
184
185    // macOS: paint the splash FIRST, on the main thread, before any heavy work
186    // — this is the whole reason the splash lives in the small fast launcher
187    // rather than the slow CEF host. AppKit must own the main thread, so the
188    // srv+host supervisor (`launcher_main`) runs on a worker thread with its
189    // own Tokio runtime; the splash pumps a CoreFoundation runloop on main
190    // until the host signals first paint. See `splash_mac`.
191    #[cfg(target_os = "macos")]
192    {
193        if splash_config::splash_disabled() {
194            if tray::should_enable(tray::tray_opt_in_from_env(), tray::background_service_from_env()) {
195                // Splash disabled BUT the menu-bar item is on (the default, and
196                // always in background-service mode): the main thread must
197                // still pump AppKit, or there is no menu-bar item and no reopen
198                // delegate once every window is closed (design doc §7.5.1).
199                // Same thread layout as the splash path, minus the window.
200                splash_mac::prepare_headless_app();
201                spawn_supervisor_thread(None);
202                splash_mac::pump_forever();
203            }
204            // Splash disabled and no menu-bar item → no AppKit at all; run the
205            // supervisor directly on the main thread (there's no runloop to
206            // pump without a window or a tray).
207            tokio::runtime::Runtime::new()
208                .expect("failed to build Tokio runtime")
209                .block_on(launcher_main(None));
210            return;
211        }
212        // Create the startup-event sink/receiver here (before the splash
213        // window exists) and thread the sink into launcher_main on the
214        // worker thread, the receiver into the splash on the main thread —
215        // mirrors the Linux branch below. Closes the gap where macOS
216        // previously always passed None and the receiver got dropped
217        // unread in run_unix. See SPEC_MACOS_LAUNCH_SPEED_AND_SPLASH_
218        // TELEMETRY_2026_07_02.md §B.3-B.4.
219        let (startup_sink, startup_rx) = startup_events::StartupEventSink::new();
220        let splash = splash_mac::Splash::show(startup_rx);
221        spawn_supervisor_thread(Some(startup_sink));
222        splash.run_until_dismissed(); // pumps the runloop, then parks forever
223        return;
224    }
225
226    #[cfg(not(target_os = "macos"))]
227    {
228        // Linux: paint the splash before any heavy work (mirrors the macOS path,
229        // but on its own thread since neither X11 nor Wayland needs the main
230        // thread). spawn() sets AGENTMUX_SPLASH_READY_FILE so the host — spawned
231        // later inside launcher_main — inherits it and signals first paint.
232        // Windows keeps spawning its splash inside launcher_main (event-name
233        // model). See splash_linux/.
234        #[cfg(target_os = "linux")]
235        let linux_startup_sink = {
236            let (sink, rx) = startup_events::StartupEventSink::new();
237            if !splash_config::splash_disabled() {
238                splash_linux::spawn(rx);
239            } else {
240                drop(rx);
241            }
242            Some(sink)
243        };
244        #[cfg(not(target_os = "linux"))]
245        let linux_startup_sink: Option<startup_events::StartupEventSink> = None;
246
247        tokio::runtime::Runtime::new()
248            .expect("failed to build Tokio runtime")
249            .block_on(launcher_main(linux_startup_sink));
250    }
251}
252
253/// macOS: run the srv+host supervisor (`launcher_main`) on a worker thread with
254/// its own Tokio runtime, leaving the main thread to AppKit. The thread owns
255/// process lifetime: it `exit`s when the supervisor returns, which is what ends
256/// the main thread's pump loop.
257#[cfg(target_os = "macos")]
258fn spawn_supervisor_thread(startup_sink: Option<startup_events::StartupEventSink>) {
259    std::thread::Builder::new()
260        .name("launcher-supervisor".into())
261        .spawn(move || {
262            // Catch panics so a supervisor crash always exits the process
263            // rather than leaving the main-thread AppKit runloop spinning
264            // as an invisible orphan.
265            let result = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| {
266                tokio::runtime::Runtime::new()
267                    .expect("failed to build Tokio runtime")
268                    .block_on(launcher_main(startup_sink));
269            }));
270            if result.is_err() {
271                eprintln!("AgentMux launcher supervisor panicked — exiting");
272                std::process::exit(1);
273            }
274            // Supervisor finished cleanly (host exited / fatal).
275            std::process::exit(0);
276        })
277        .expect("failed to spawn launcher supervisor thread");
278}
279
280/// `--splash-selftest`: show the splash with no srv/host behind it, hold it for a
281/// few seconds (or `AGENTMUX_SPLASH_HOLD_MS`), then exit. A demo/dev affordance
282/// for eyeballing the footer + centering without launching the whole app.
283fn splash_selftest() {
284    let hold = std::env::var("AGENTMUX_SPLASH_HOLD_MS")
285        .ok()
286        .and_then(|s| s.parse::<u64>().ok())
287        .map(|ms| std::time::Duration::from_millis(ms.max(3000)))
288        .unwrap_or_else(|| std::time::Duration::from_secs(6));
289
290    #[cfg(target_os = "linux")]
291    {
292        let (sink, rx) = startup_events::StartupEventSink::new();
293        // Fire fake startup events so the stage list is exercised.
294        std::thread::spawn(move || {
295            play_selftest_stages(&sink);
296        });
297        splash_linux::spawn(rx);
298        std::thread::sleep(hold);
299    }
300    #[cfg(target_os = "macos")]
301    {
302        let (sink, rx) = startup_events::StartupEventSink::new();
303        // Fire fake startup events so the stage panel is exercised: the shared stages, then the host's.
304        std::thread::spawn(move || {
305            play_selftest_stages(&sink);
306            std::thread::sleep(std::time::Duration::from_millis(100));
307            sink.stage_begin("host", "Host startup");
308            std::thread::sleep(std::time::Duration::from_millis(90));
309            sink.stage_end("host", 90, startup_events::StartupStatus::Ok, None);
310        });
311        let splash = splash_mac::Splash::show(rx);
312        if let Ok(p) = std::env::var("AGENTMUX_SPLASH_DUMP_PNG") {
313            splash.dump_png(&p);
314        }
315        let _ = splash; // run_until_dismissed parks; selftest just holds then exits
316        std::thread::sleep(hold);
317    }
318    #[cfg(target_os = "windows")]
319    {
320        let (_sink, rx) = startup_events::StartupEventSink::new();
321        let _ = splash::spawn_splash("selftest", rx, false);
322        std::thread::sleep(hold);
323    }
324}
325
326/// The fake stages `--splash-selftest` plays into the splash (prep, migrations with two sub-rows, backend), on the
327/// calling thread, with the pauses a real start has. The macOS branch adds the host stage after it.
328#[cfg(any(target_os = "linux", target_os = "macos"))]
329fn play_selftest_stages(sink: &startup_events::StartupEventSink) {
330    std::thread::sleep(std::time::Duration::from_millis(300));
331    sink.stage_begin("prep", "Launcher setup");
332    std::thread::sleep(std::time::Duration::from_millis(120));
333    sink.stage_end("prep", 120, startup_events::StartupStatus::Ok, None);
334    std::thread::sleep(std::time::Duration::from_millis(100));
335    sink.stage_begin("migrations", "Migrations");
336    sink.sub_begin("migrations", "0009", "cron_schema");
337    std::thread::sleep(std::time::Duration::from_millis(80));
338    sink.sub_end("migrations", "0009", 80, startup_events::StartupStatus::Ok, None);
339    sink.sub_begin("migrations", "0010", "identity_dedup");
340    std::thread::sleep(std::time::Duration::from_millis(40));
341    sink.sub_end("migrations", "0010", 40, startup_events::StartupStatus::Ok, None);
342    sink.stage_end("migrations", 220, startup_events::StartupStatus::Ok, None);
343    std::thread::sleep(std::time::Duration::from_millis(200));
344    sink.stage_begin("backend", "Backend startup");
345    std::thread::sleep(std::time::Duration::from_millis(1500));
346    sink.stage_end("backend", 1500, startup_events::StartupStatus::Ok, None);
347}
348
349async fn launcher_main(startup_sink: Option<startup_events::StartupEventSink>) {
350    let exe_path = std::env::current_exe().expect("cannot resolve exe path");
351    let exe_dir = exe_path.parent().expect("exe has no parent directory");
352    // Production + Windows dev use a `runtime/` subdir (launcher at root,
353    // host + libs + srv under runtime/). The macOS/Linux `task dev` flat
354    // layout (Phase 1, SPEC_LAUNCHER_MACOS_DEV_INTEGRATION_2026_05_30)
355    // drops the launcher next to the host in dist/cef-dev/ so the host's
356    // `../Frameworks` resolution and asset anchoring are byte-identical to
357    // the legacy direct-invoke path — no `runtime/` to descend into. Fall
358    // back to exe_dir when there's no runtime/ subdir. Windows always has
359    // one, so its behavior is unchanged.
360    let runtime_dir = {
361        let rt = exe_dir.join("runtime");
362        if rt.is_dir() {
363            rt
364        } else {
365            exe_dir.to_path_buf()
366        }
367    };
368
369    log(&format!(
370        "starting — exe={} runtime={}",
371        exe_path.display(),
372        runtime_dir.display()
373    ));
374
375    // Set DLL search path so libcef.dll (in runtime/) is found by the
376    // CEF host's load-time linker. SetDllDirectoryW is process-local
377    // and inherited by child processes — both srv (which doesn't
378    // need libcef but harmless) and host (which absolutely does).
379    #[cfg(target_os = "windows")]
380    {
381        use std::os::windows::ffi::OsStrExt;
382        let wide: Vec<u16> = runtime_dir
383            .as_os_str()
384            .encode_wide()
385            .chain(Some(0))
386            .collect();
387        unsafe {
388            windows_sys::Win32::System::LibraryLoader::SetDllDirectoryW(wide.as_ptr());
389        }
390    }
391    log("SetDllDirectoryW done");
392
393    let args = launch_link::take(std::env::args().skip(1).collect());
394
395    // LSD-3 — `agentmux.exe --diag sagas` is OFFLINE: it reads the
396    // launcher saga SQLite log directly, with no IPC and no running
397    // launcher. So it MUST run BEFORE the CEF runtime existence
398    // check below — the offline-diagnostic value is most needed
399    // exactly when the launcher won't start (e.g. corrupt runtime
400    // folder). (codex P1 + reagent P1 PR #647 round 3.)
401    if matches!(
402        (args.first().map(String::as_str), args.get(1).map(String::as_str)),
403        (Some("--diag"), Some("sagas"))
404    ) {
405        match diag::run_sagas_diag(exe_dir).await {
406            Ok(()) => std::process::exit(0),
407            Err(msg) => {
408                eprintln!("--diag sagas failed: {}", msg);
409                std::process::exit(1);
410            }
411        }
412    }
413
414    let real_exe = find_cef_binary(&runtime_dir);
415    log(&format!("resolved CEF binary: {}", real_exe.display()));
416    // Self-spawn guard: if host resolution ever points back at the
417    // launcher's own binary (the flat dev layout's failure mode —
418    // launcher + host co-located), spawning it would recurse into an
419    // unbounded launcher fork bomb. find_cef_binary excludes
420    // `agentmux-launcher` by name; this is the loud backstop in case a
421    // future binary slips past that filter. Compare canonicalized paths
422    // so symlink/`./` differences don't defeat the check.
423    if let (Ok(a), Ok(b)) = (
424        std::fs::canonicalize(&real_exe),
425        std::fs::canonicalize(&exe_path),
426    ) {
427        if a == b {
428            log(&format!(
429                "FATAL: host resolved to the launcher's own binary ({}) — refusing to self-spawn",
430                a.display()
431            ));
432            eprintln!("AgentMux runtime is misconfigured (host == launcher). Aborting.");
433            std::process::exit(1);
434        }
435    }
436    if !real_exe.exists() {
437        log(&format!(
438            "FATAL: CEF binary not found at {}",
439            real_exe.display()
440        ));
441        eprintln!(
442            "AgentMux runtime not found in: {}\nMake sure the runtime/ folder is intact.",
443            runtime_dir.display()
444        );
445        std::process::exit(1);
446    }
447
448    log(&format!("forwarding {} CLI args to host", args.len()));
449
450    // Phase B.8 — `agentmux.exe --diag wrr` and `--diag srv` Tool
451    // clients. Connect to the running launcher (or srv) over IPC,
452    // capture events for a short window, print summary, exit.
453    // (Note: --diag sagas is handled above, before the CEF runtime
454    // check, since it doesn't need IPC.)
455    if matches!(args.first().map(String::as_str), Some("--diag")) {
456        let topic = args.get(1).map(String::as_str).unwrap_or("");
457        match topic {
458            "wrr" => match diag::run_wrr_diag(exe_dir).await {
459                Ok(()) => std::process::exit(0),
460                Err(msg) => {
461                    eprintln!("--diag wrr failed: {}", msg);
462                    std::process::exit(1);
463                }
464            },
465            // Phase E.7 — operator visibility into the srv reducer's
466            // canonical state (workspaces / tabs / blocks / sagas) +
467            // recent activity. Same `Tool` IPC pattern as `--diag wrr`,
468            // talks to the srv pipe instead of the launcher pipe.
469            "srv" => match diag::run_srv_diag(exe_dir).await {
470                Ok(()) => std::process::exit(0),
471                Err(msg) => {
472                    eprintln!("--diag srv failed: {}", msg);
473                    std::process::exit(1);
474                }
475            },
476            // sagas is handled above, before the runtime check.
477            "sagas" => {
478                // Should never reach here — `sagas` is matched + handled
479                // above the CEF runtime check. Kept for completeness.
480                unreachable!("--diag sagas is handled before runtime check");
481            }
482            "" => {
483                eprintln!("usage: agentmux.exe --diag <topic>\nknown topics: wrr, srv, sagas");
484                std::process::exit(2);
485            }
486            other => {
487                eprintln!("unknown --diag topic: {} (known: wrr, srv, sagas)", other);
488                std::process::exit(2);
489            }
490        }
491    }
492
493    prune_old_versions_soon(exe_dir, &runtime_dir);
494
495    #[cfg(target_os = "windows")]
496    {
497        let _ = startup_sink;
498        supervisor::run_windows(exe_dir, &real_exe, &args).await;
499    }
500
501    #[cfg(not(target_os = "windows"))]
502    {
503        // Phase 1 (SPEC_LAUNCHER_MACOS_DEV_INTEGRATION_2026_05_30):
504        // the launcher now owns srv + host on macOS/Linux too — it
505        // spawns the backend, hands the host its endpoints via env,
506        // and supervises both with the same crash budget Windows uses.
507        // The legacy exec-into-host escape hatch lives in
508        // `task dev:standalone` (host invoked directly, no launcher).
509        supervisor::run_unix(exe_dir, &real_exe, &args, startup_sink).await;
510    }
511}
512
513/// Start the post-upgrade cleanup: the old `runtime\` files and the old per-version data folders,
514/// on its own thread so startup is never held up.
515fn prune_old_versions_soon(exe_dir: &std::path::Path, runtime_dir: &std::path::Path) {
516    let data_dir = crate::data_dir::resolve_paths(exe_dir, agentmux_common::srv_binary::VERSION)
517        .ok()
518        .map(|p| p.data_dir);
519    old_versions::prune_when_healthy(
520        exe_dir.to_path_buf(),
521        runtime_dir.to_path_buf(),
522        agentmux_common::srv_binary::VERSION,
523        data_dir,
524    );
525}
526
527/// Show a modal error dialog before the launcher exits. Used for
528/// genuine bind failures (NOT the "already running" path — that
529/// silently forwards via `forward_open_new_window`). Without this,
530/// the launcher exit is silent (it has the `windows` subsystem in
531/// release, so eprintln! goes nowhere).
532#[cfg(target_os = "windows")]
533pub(crate) fn show_fatal_dialog(title: &str, body: &str) {
534    use std::os::windows::ffi::OsStrExt;
535    use windows_sys::Win32::UI::WindowsAndMessaging::{
536        MessageBoxW, MB_ICONWARNING, MB_OK, MB_SETFOREGROUND, MB_TOPMOST,
537    };
538    let title_w: Vec<u16> = std::ffi::OsStr::new(title)
539        .encode_wide()
540        .chain(Some(0))
541        .collect();
542    let body_w: Vec<u16> = std::ffi::OsStr::new(body)
543        .encode_wide()
544        .chain(Some(0))
545        .collect();
546    unsafe {
547        MessageBoxW(
548            std::ptr::null_mut(),
549            body_w.as_ptr(),
550            title_w.as_ptr(),
551            MB_OK | MB_ICONWARNING | MB_SETFOREGROUND | MB_TOPMOST,
552        );
553    }
554}
555
556#[cfg(not(target_os = "windows"))]
557pub(crate) fn show_fatal_dialog(_title: &str, body: &str) {
558    eprintln!("{}", body);
559}
560
561// This test binary must hold this checkout's code, not another clone's from
562// a shared target directory (`agentmux_common::checkout`).
563#[cfg(test)]
564agentmux_common::checkout_guard!();