Share terminal sizing across Mac, iPhone and Cloud with tmux semantics
Summary
A terminal has one PTY grid, but a Mac, paired iPhones, and on Cloud VMs other people can view it at once. Today local terminals use "smallest viewport wins", Cloud terminals use a single owner that freezes the grid when that owner disconnects, and nobody can see who set the size or where the grid ends.
This adds one sizing model for local and Cloud terminals, with tmux semantics:
- The process that owns the PTY decides: the Mac app for local terminals, the cmux-tui daemon for Cloud terminals. A Mac mirroring a Cloud terminal is a relay. It forwards itself and each iPhone behind it as separate participants.
- One reducer, written twice (
Packages/Shared/CmuxTerminalSizing,cmux-tui-core/src/sizing_policy.rs), both replayingschemas/terminal-sizing/fixtures.json. - Modes
smallest(default, shown as Fit everyone),latest(tmux 3.1+),largest,priority(ordered list of people/devices),fixed. A per-participant "counts toward size" switch (tmuxignore-size). An iPhone does not count while the same user's Mac is attached. When the owner leaves, the next owner takes over at once. - Any viewer can be disconnected (tmux
detach-client), and "Disconnect other clients" isdetach-client -a.detachednow carriesreasonandby;disconnected-bynever reconnects automatically. iOS shows "Detached from " with Reattach and Reattach as viewer. - Bounds are explicit on Mac and iOS: owner-colored border, hatch outside the grid, a chip naming who set the size, an amber crop edge with
+N cols, and a size HUD on change. The bonsplit tab shows who is attached, a ring on the owner, the grid size, and a mismatch glyph. The size panel has the mode control, a size map, per-person rows with counts, priority order and disconnect. - Entrypoints: tab accessory and context menu, size panel, "Size Terminal to My Window" (⌃⌥⌘=, configurable), command palette,
cmux surface size|size-policy|size-to-me|size-counts|participants|disconnect-participant|disconnect-others, mobile RPC, cmux-tui commandsset-size-policy,set-size-counts,get-size-state,note-size-activityand eventsize-statebehind capabilityshared-sizing-v1.
Contract: docs/shared-terminal-sizing.md. Depends on https://github.com/manaflow-ai/bonsplit/pull/259 (merge it first).
Known limits: user_id on Cloud is client-supplied because relay tickets carry no user identity (it affects sizing only, not access). Daemon policies are in memory and reset on daemon restart. Workspace-default scope is not implemented on the Mac side yet. A fixed size is limited to 500 × 200 on every entrypoint.
Testing
- Shared engine:
swift testinPackages/Shared/CmuxTerminalSizingreplays all 18 conformance cases (Swift and Rust shareschemas/terminal-sizing/fixtures.json; the new zero-viewport case was red on Swift, then green). - Theme contrast matrix:
TerminalSizingPaletteTests(iOS chip and bounds) and bonsplit's presence color tests require 4.5:1 text and glyphs, 3:1 borders and rings, and visible fills on light, dark, Solarized light and dark, Dracula, low-contrast dark, mid grey, pure white and pure black, including a light tab bar under a dark system appearance. Both were red before the colors were derived from the surface. Rendered proofs for 7 themes × 2 system appearances were reviewed; the tab avatars now sit side by side with a 2 pt gap (testAccessoryAvatarsDoNotOverlap, red then green) so every initial stays readable. - cmux-tui: fixture replay and mux tests (owner leave without freeze, relay sub-views, kick reason and actor, relay-forwarded phone activity, policy events) pass on a Blacksmith Testbox;
cargo clippy -D warningsandcargo fmt --checkclean. SDK coverage tests now count 117 commands and 50 events in every language. - Mac:
swift testfor CmuxTerminalSharing, CmuxSettings and ControlCommandExecutionPolicy pass. New app-host tests: closing a shared terminal drops its sizing host and store snapshot, andterminal.size_policy.setrejects a 70000-column fixed grid (both red before the fix). - iOS:
swift testfor CmuxMobileShellModel (including the new reconnect ordering tests, red then green), CmuxMobileRPC and CmuxMobileTerminalKit pass. The iOS simulator suites (iPhone and iPad) pass on this head. - E2E simulator runs: recorded on an isolated iOS Simulator paired to a throwaway Mac tag (
sze2e), with video frames and the Mac debug log: default Fit everyone fits the first phone frame with one Mac grid change; phone leave restores the Mac at once; Follow latest renders the whole Mac grid scaled on the phone with no wrapping; a kick shows the Detached card, does not reconnect for 30 s, and Reattach restores it; no bright border frame on connect. Hostedtest-e2e.ymlwithCloudTerminalSharedSizingTests(run) executed and passed 7 tests. - Fleet build of
c3229c7(tagsizing-v1, job2c46fd7bf321dba83bb16f5d) succeeded. An earlier tagged build was driven through the debug socket:size-policy fixed --cols 70 --rows 20resizes the PTY (tputreports 70×20) and draws the border, hatch, chip and tab accessory;size-policy latestandsize-to-merestore the window size. - Cloud VM check: a Freestyle dev VM upgraded to this branch's cmux-tui advertised
shared-sizing-v1, sentsize-state, moved the grid to the next owner within 1.5 s when the owner left, sentdisconnected-bywith the actor on a kick (relay sub-view kicks keep the relay), fit two views with smallest, and the tagged Mac attached as a Cloud participant and showed the Detached card after a kick. - Review fixes on this head: a closed terminal no longer keeps its local sizing host; the phone forgets size states when its Mac connection ends, so a relaunched host's generation 1 is accepted; a font-size change re-reports the Mac pane's grid.
- Unverified: a blank first open (~2 s) seen once on the phone did not reproduce in 5 recorded first opens; phones behind a Mac on a Cloud VM were not run end to end; the font-size re-report has no automated test (it needs a live Ghostty surface).
Merge notes: main's displaced-owner model (the exclusive owner that returned the grid when a phone stopped sizing) is replaced by the shared reducer, which re-elects the next counting participant when an owner leaves. Main's displaced-owner tests were rewritten to assert the same outcomes through the reducer. Generated SDK bindings were regenerated with cmux-tui/bindings/codegen/generate.py, not hand-merged.
Checks on c3229c7 that do not pass, none caused by this change (each rerun once):
macos / CLI product tests: the runner failed during setup (Homebrew directories not writable). Earlier heads failed only wrapper and shell-hook scripts, which fail on main too (main run).macos / app-host unit tests (changed suites): the app host aborts withCannot form weak reference to instance of class NSKVONotifying_NSWindow, the same crash main's app-host shards hit on each of their last three runs (main run); here it lands inSessionPersistenceTests, before either sizing suite runs.MobileHostOrderedInputTests.orderedInputOnAnotherSurfaceIsNotBlockedhits its 300 s limit on main too (main run). The new sizing suites pass.macos / swift-package-tests:CmuxPanesfails to link on the owned runners because the kept SwiftPM scratch holds aSessionLayoutRestoreTestsobject compiled against main's bonsplit (Tab.initwithoutpresence:). Reproduced locally with--build-system native: after the bonsplit pin changes, SwiftPM recompiles Bonsplit but not that test file. A clean scratch passes. This needs a CI scratch fix (for example, keyingowned_spm_scratch.pyon the bonsplit commit); it is not a code defect in this PR.
Changelog
Added: Shared terminals on Mac, iPhone and Cloud VMs show who sets the terminal size and where it ends, and let you choose the sizing mode, give people priority, and disconnect other viewers.
Demo Video
Tagged build screenshots are described in Testing; the prototype of the full design is local to the author.
🤖 Generated with Claude Code