Repository navigation
explicit zmx lead for remote-attached sessions, with a cover on the pane that follows - #635
Merged
Merged
Conversation
setup.sh applies scripts/zmx-patches/*.patch over ZMX_REV and folds their digest into the build stamp and the CI cache key, so editing a patch rebuilds zmx like a pin change does. the patch adds an opt-in for a terminal that manages leadership itself. a client attached with ZMX_MANAGED leads only by claiming at attach, never by typing or resizing, and is told its role through a reserved OSC 777 notification written at a safe point of the output. zmx screen reads the daemon's own terminal and zmx type queues input with an acknowledgement and without taking the lead. clients that do not opt in behave as upstream.
…nother Mac every zmx attach agterm starts is now a managed client. attaching a session from another Mac claims the lead in every pane at once, so its grid applies without a key press, and typed automation on either side no longer moves the lead back. a pane whose client does not lead is covered, since what it drew is laid out for the other grid. its first key press takes the lead back through a fresh attach into a new surface, and the same happens by itself when the leader goes away. while a pane is covered session.text and surface.cursor are answered by the daemon's own terminal and session.type goes through zmx type, so pane-to-pane automation keeps working on the Mac a session runs on. a covered pane attached from another Mac refuses those three instead. the role travels as a title under a reserved prefix. libghostty drops a desktop notification that follows another within a second, app-wide, which lost the report after every re-attach. a static title in the user's ghostty config would drop the reports too, so it is cleared in every config build and its effect, ignoring program titles, is kept by the title callback. tree reports each pane's lead on its surface node.
session.lead takes the lead of a pane for this Mac, the control twin of a key press on the pane's cover. a pane that already leads answers ok, one whose zmx reports no role says so, and surfaces[].lead is the read-back. a closed pane drops its lead state. hosted tests cover the covered-pane read and type paths, the takeover key and the zmx client's screen and type calls. the control-api rule gains a pane lead section replacing the accepted v1 limitations it removes, and the backlog item it resolves is deleted. docs.html, commands.html and the bundled skill describe the new behaviour.
session.type and the layout reads of a local managed pane always go through the daemon. the role the app holds trails the daemon's by a main-queue hop and up to 250 ms, so keying delivery on it answered ok for input the daemon had already started dropping; the realize poll repeats the check too. only the default viewport read stays on a leading pane's own surface. an attach that ends on its exit prompt drops the pane's lead state, so a failed take-over no longer sits under a cover that swallows its keys. the cover moves below a pane's own overlay and is mounted by terminal zoom and the dashboard as well. a re-attach clears a search the old surface owned synchronously and carries a dashboard cell's transient font as the override instead of seeding the new surface from it. the configured static title is kept and applied by agterm rather than discarded. the zmx daemon ignores a session switch while its leader is managed, whose nonce, generation and daemon reads are bound to that session.
routing every managed local pane's session.type through zmx type sent a fixed carriage return for Return, which is wrong for a program that asked for the kitty keyboard protocol, and skipped the pending IME composition the surface path commits first. both reached ordinary live panes, not only shared ones. zmx type now carries typed text: the daemon encodes each CR as a Return press and release and each run as typed text with ghostty's key encoder against its terminal's live keyboard mode, which is what the surface's own key path does. a pending composition is sent ahead of the scripted text on the same acknowledged call and dropped locally only once the daemon took it.
paste, selectall, copy and an opening or navigating search act on the local surface, which on a covered pane holds output laid out for another grid. they now refuse with a message naming session lead; search --to close stays available so a search opened before the demotion can still be dismissed, and the refusal checks the pane the search is pinned to. a takeover key whose release was never seen no longer swallows its next press: a fresh non-repeat press of the same key clears the latch, other keys leave it alone. lead state of a closed primary is forgotten before the survivor's identity replaces it. check.py predicates are booleans and the docs name the no-lead case accurately.
the refusal ran once, before the realization poll, the needle-change pause and the settle wait. A pane demoted during any of them was still searched and answered ok. The owner is now re-checked after realization, after the needle-change pause before anything is mutated, and before the result is returned. close stays exempt.
…ocused one with a search open on a leading pane and split focus on a covered one, the re-check after realization looked at the focused pane and refused a command that drives the other pane.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
a session attached from another Mac has one zmx daemon per pane and two clients on it, and only one of them, the leader, decides the pty size. Stock zmx moves the lead to whichever client last sent bytes it classifies as user input. A freshly attached pane therefore stayed at the origin's size until a key was pressed in it. The lead also kept moving back with nobody touching the origin: its zmx log showed 10 leadership changes in 50 minutes on one pane, each leaving the other side drawn for the wrong grid. From the source, automation typing into the origin pane (
session.type, used by the chat skills) retakes the lead, and the classifier also accepts Kitty keyboard-status replies. The individual changes in that log were not traced to a cause.this makes the lead explicit.
zmx patch.
scripts/zmx-patches/0001-explicit-leadership.patchis applied to the pinned zmx byscripts/setup.sh, and the patch digest is part of the build stamp and the CI cache key. A client started withZMX_MANAGED=<nonce>is managed. Managed input never takes the lead, and a follower's input is dropped. A managed attach claims explicitly or fills a vacant slot. Unmanaged clients keep stock takeover behavior. The daemon tells a client when its role changes, and the client relays it to agterm as a reserved OSC 2 title. It normally waits for a boundary in the output stream, and after 250 ms cancels an unfinished sequence in the follower, whose screen is thrown away anyway. Two commands are added:zmx screenreads the daemon's own grid, andzmx typetypes into it as key events encoded for the terminal's current keyboard mode.agterm. A remote attach claims the lead in every pane at attach time, so all panes take this Mac's size right away. Local panes attach without the claim, so an origin relaunched while another Mac leads comes back covered. A pane that does not lead is covered with a panel saying where it is in use. A keypress without Command on it, or the new
session leadcommand, takes the lead through a fresh attach into a new surface. When the leader goes away the pane re-attaches by itself.surfaces[].leadintreeis the read-back.automation on a covered pane. On the Mac the pane runs on,
session type,session text --lines/--allandsurface cursorare served by the daemon and keep working under the cover, which is what the chat skills need. After the pane's first role report, localsession typeuses the daemon's acknowledged path regardless of its current role. On an attached Mac whose pane is covered, type, text and cursor requests are refused because its daemon is remote. Commands that can only act on the local surface (paste,selectall,copy, opening or navigating a search) refuse on a covered pane and namesession lead;search --to closestill works.a static
titlein the user's ghostty config made libghostty drop every OSC title, including the role relay. The key is now cleared from the built config and agterm applies the configured title itself.the zmx patch is kept upstreamable and has its own tests (107 pass with the patch) plus
scripts/zmx-patches/check.py, an end-to-end check with two managed clients on ptys.two known limits. Before a local pane's first role report
session typekeeps the legacy surface path, which can report success for input that is dropped if another client already leads. Andzmx screenandzmx typerun synchronously on the main actor, like the existingZmxClientcalls.