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/shonce 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
.appthis launcher (inAgentMux.app/Contents/MacOS/) belongs to, by the bundle layout (runtime_mode::app_bundle_of). - apply_
command - The detached
/bin/shthat swaps the app once launcherlauncher_pidis gone.upgrade_restart::relaunchadds 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 ownupdates/<v>/, whole by the release’ssha256, and an app here that can be replaced.own_diris the launcher’s folder (AgentMux.app/Contents/MacOS),channel_dirthis 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.ymlnames it (srv’supdate::install). - not_
replaceable - Why
appcan’t be replaced where it is, orNonewhen it can: macOS runs a quarantined app from a read-only copy (App Translocation), an app opened straight from its mounted.dmgis 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).