Skip to main content

Module upgrade_macos

Module upgrade_macos 

Source
Expand description

The macOS side of “Upgrade & restart” (docs/specs/SPEC_UPGRADE_FOR_USERS_AND_AGENTS_2026_10_15.md §4.2, phase 3c), for upgrade_restart: checking the .dmg srv downloaded and verified, asking the user with a native dialog (osascript), and the script that replaces AgentMux.app once this launcher has exited.

The app can’t replace itself while it runs (its own launcher is inside it), so the swap is a small /bin/sh script started detached just before the launcher exits (apply_command). It works on a private copy of the .dmg, checks it again against the release’s SHA-256, mounts it read-only, checks the new app’s code signature (and, when this app passes Gatekeeper, that the new one does too, from the same team), copies it into a private folder it creates beside the running one (a folder only this user, root or admin can change, all the way up) and swaps the two, holding a lock on the app so two launchers (two channels can run one .app) never swap it at once. This version goes to the Trash, so it can still be put back. Whatever fails, the script opens an AgentMux again: the new one, or this one, still in place.

The pure parts (paths, checks, the dialog’s answer, the script’s arguments) build and are tested on every platform; only showing the dialog is macOS-only.

Structs§

MacUpgrade
What a confirmed macOS upgrade needs: the verified .dmg, its digest, the app it replaces, the data channel to keep, and where the script logs.

Constants§

APPLY_SCRIPT 🔒
The swap, run by /bin/sh once this launcher ($1) has exited. Every path is an argument, never part of the script, so nothing in one is parsed. Arguments: launcher pid, .dmg, SHA-256, version, the app to replace, the channel to record beside it (may be empty), the log, the file to leave when the upgrade failed (crate::updating_window::failed_marker).
YES 🔒
The label of the dialog’s Yes.

Functions§

app_of
The .app this launcher (in AgentMux.app/Contents/MacOS/) belongs to, by the bundle layout (runtime_mode::app_bundle_of).
apply_command
The detached /bin/sh that swaps the app once launcher launcher_pid is gone. upgrade_restart::relaunch adds the environment and process group.
can_write_in 🔒
Whether this user can create and remove entries in dir, asked without writing anything there (access(2), which also says no on a read-only volume): a probe file at a predictable name could follow a link someone else planted.
check_dmg
Check what srv names for a macOS upgrade to version: that version’s .dmg, in this version’s own updates/<v>/, whole by the release’s sha256, and an app here that can be replaced. own_dir is the launcher’s folder (AgentMux.app/Contents/MacOS), channel_dir this channel’s data folder, whose name is the channel the new version keeps.
dmg_name
The release file a macOS install upgrades with, as .github/workflows/build-macos.yml names it (srv’s update::install).
not_replaceable
Why app can’t be replaced where it is, or None when it can: macOS runs a quarantined app from a read-only copy (App Translocation), an app opened straight from its mounted .dmg is on a read-only volume, and the folder that holds it must be one this user can write.
question
The dialog’s question.
said_yes
Whether osascript’s output for the dialog is an explicit Yes: the button, and not given up (the dialog closes itself, as No, when its time is up).