Skip to content

Rex backend: show, attach, and create Rex sessions - #73

Merged
jhen0409 merged 14 commits into
mainfrom
rex-backend
Nov 27, 2026
Merged

jhen0409 merged 14 commits into
mainfrom
rex-backend

Conversation

@jhen0409

@jhen0409 jhen0409 commented Nov 16, 2026 •

Copy link
Copy Markdown
Member

Summary

Rex becomes a third backend beside tmux and herdr: its sessions are shown on the deck, attached as tabs, and created from the app. Rex is never a host's default backend, and Multiplex never starts a Rex server. Written against Rex 0.1.0-preview.25 (API revision 24) and first measured against preview.19 (revision 14).

  • Opt-in per host, nothing else gates it. A host shows Rex once its record lists it: the rail's + REX offer, or the box in Host Settings ▸ Backends. A per-device Settings ▸ Experimental switch gated it for a few commits on this branch and is removed again; a record that listed rex while a device had it off is monitored there now.
  • The hello states a range of API revisions and the server picks (RexWire.apiRevision 24, minimumAPIRevision 14). A preview server gains a revision every few days, so what matters is which shapes the client reads: every call and event a tab makes or handles was sent at 14 and at 24 to one preview.25 server, and at 19 to a preview.23 one, and the answers differ only in ids. The probe and mint scripts run unchanged with the preview.25 CLI. A server with no revision in common closes with a reason that names the side to update, which is the tab's ended line; one too old to negotiate fails the attach with a message. What revisions 20 to 24 added (undoable closes, session.transfer_window, a second zoom per window) is recorded with what the client does about each; none is sent.
  • Deck (RexProbe, pure). One exec per probe (rex do -e <lua> --json): one tile per session, windows on the spine, terminal blocks as panes, the fronted block's screen as the miniature.
    • The rail offers + REX when discovery finds sessions; Host Settings ▸ Backends lists REX.
    • Programs that report status through OSC 7501 drive RUNNING / NEEDS YOU; others are read from title and screen like a tmux tile.
    • The probe uses session.attach_all, so it is not listed as a client of any session.
  • Attach (RexSession, RexWire, WebSocketCodec). Rex ships no terminal client, so a Rex tab is a third transport beside the SSH PTY and mosh.
    • It speaks the server's WebSocket protocol through rex __internal dial-stdio on PTY-less SSH channels (SSHConnection.openPipe): one for control and one per pane.
    • The screen, colors, cursor and scrollback are restored on attach, and again when a full-screen program exits.
    • One tab draws one Rex window, panes included (next bullet). Open Terminal in the tile menu opens a tab on a named terminal's window.
    • A link lost to suspension re-attaches on return. A foreground drop parks on RECONNECT, the same rule as a tmux tab.
    • Typing queues and returns; one write call is in flight at a time and whatever is typed meanwhile rides the next one, so a slow link does not turn each keystroke into its own round trip.
    • A Rex tab rides SSH whatever the host prefers (ridesMosh), so on a mosh host it keeps scrollback and FILE and shows no MOSH badge.
    • The Agent Bar speaks for the pane the tab's keyboard is on (TmuxSession.agent(inPane:)), not the one the session is fronting, so it stays when the Rex app shows another window.
    • Only what a person does is written to a Rex terminal. The Rex server answers the terminal's queries itself; the tab's emulator answered them too, which gave the program every reply twice and, since a write is what claims the size, made an idle tab take the terminal back from the Rex app (seen as flicker there). The SwiftTerm fork now routes the terminal's own answers and reports apart from input (TerminalViewDelegate.sendTerminalReport), and a Rex tab drops them; other tabs are unchanged.
    • A terminal another client holds at its own size is drawn at that size, pane by pane. The stream says what size the terminal is and whose; the tab used to keep parsing at its own grid, which filled it with stray characters while the Rex app was the one in use. Now the session holds the stream, waits for the repaint a resize sets off, has the emulator take the grid, and draws the screen again. The pane gives SwiftTerm that grid by giving it the frame: text shrinks until it fits (TerminalGridFit), and the room left over stays empty. The tab only follows; typing in it still takes the size.
    • A full reset now empties the alternate screen too (SwiftTerm fork). Every redraw of a Rex tab is RIS plus a rendering, and upstream's RIS left the alternate buffer's rows in place, so switching the tab from one full-screen program to another drew the second over the first.
    • The hello is sent as client kind other, so a user's rex do automation still finds exactly one app client.
  • Panes, drawn natively (docs/agents/panes.md). A Rex tab draws the whole window it was opened on: one emulator per terminal block in the server's split tree, a frame around the pane the keyboard is on.
    • Tap a pane to type in it; the key rail, message box, Agent Bar, file drops and links follow. Drag the line between two panes to resize them.
    • The REX key's panel splits the focused pane right or down, zooms it, closes it (asked twice), or opens a new Rex tab; below, the session's terminals, where one in another window brings that window into the tab.
    • Nothing above the transport is Rex's: PaneLayout (the app's own pane tree and geometry, pure), PanedTerminalTransport (a backend that hands its panes out one stream each), TerminalScreen (one emulator endpoint; a tab has one, or one per pane) and PaneSplitView (in the single emulator's place, so keyboard avoidance and the rail are shared). tmux, herdr, shell and mosh tabs keep the single-emulator path. The doc says what a second backend (tmux control mode, herdr) would have to do; neither was measured or built.
    • The layout is the server's. The tab asks (session.new_split, resize_pane, block.close, new_window) and hears the answer in the view like another client's change. A pane is laid out before its terminal is opened, because a screen is rendered for the size it is drawn at.
    • The tab's focus and its zoom are its own. focus_block, focus: true on a new split or window, and zoom_block by block all make that window the session's active one, which is the tab the Rex app on the host is showing; none is sent.
    • A drag sends only the newest ratio, and the server's answer to an earlier one does not pull the line back. The line is dragged by a zero-delay press: a pan recognizer lost the first twenty points.
    • Typing claims every pane another client holds. A pane another client just made is drawn at its owner's size until then.
    • When the Rex tab on show closes (its last shell exits, its last pane is closed, another client closes it), the Multiplex tab moves to the window Rex itself shows next: the one after it, or the one before it if it was last. It used to end there with DETACHED and RECONNECT. It ends only when the session has no terminal left.
    • The keyboard moves to the next pane while the pane it is leaving is still in the window. It used to move a turn later, which for a pane that was going meant the keyboard left with it and the new pane was measured without it: opened at 73 rows, back at 51 before its screen was drawn, the top of the screen scrolled away (about three new tabs in five).
  • Create (RexProbe.mintCommand → createRexSession). New Session's "Runs on" bar, a Rex tab's + TAB, and multiplex://…&action=agent&backend=rex create a session in one exec.
    • What the user typed travels as --args JSON, never as script text.
    • The label is settled against the live list (api taken → api-2); a + TAB sibling starts in the source session's directory.
    • The setup script and launch line ride initial_input.
  • Never the default, never autostarted. Every invocation carries REX_AUTOSTART=0. A create with no server running says so and makes nothing. canBeDefault keeps Rex out of every surface that picks a host's default, and the record demotes a Rex primary to a secondary.
  • Two fixes found on the way. An attention alert compared against the host's primary backend, which swallowed alerts for a same-named session on a secondary backend. The delete confirmation named the host's primary backend, not the session's.
  • First commit, separable: a test HostStore mirrored every added host into the simulator's real Keychain, and the app adopted them (100 and 86 hosts on the test simulators). The mirror is now injected (HostRecordMirror); the shipped app is unchanged.
  • Records: docs/agents/backends-and-probe.md (the Rex adaptation), panes.md (native panes), architecture.md, e2e-headless.md, sync-and-widgets.md, docs/store-metadata.md. The TestFlight note is added. Strings are translated (zh-Hant, ja) and reviewed.

Testing

  • Unit tests on the head commit: visionOS 1650 ✅, iPad 1661 ✅ (one skipped on each, an audio test that needs an opt-in). SwiftLint: 0 violations. ruby Tools/check-metadata.rb: OK.
  • New tests: RexProbeTests (probe parsing from a captured fixture, naming, mint command and outcomes), RexWireTests, and RexSessionTests against an in-memory fake Rex server that keeps a real layout tree (attach, input order, panes coming and going, split, close, ratio, new window, link drop, another client's size), PaneLayoutTests (tree and geometry), TerminalPaneSplitUIKitTests (the real controller and surface over a recording transport: arrangement, focus, drag, zoom, a tab moving windows), TerminalGridFitTests, TerminalFullResetTests. Added with the last four commits: revision negotiation against a fake server that negotiates like a real one, a probe fixture and a stream fixture captured off preview.25, where a closed window's tab goes, and the keyboard changing hands before a pane's cell is dropped.
  • RexPanesUITests (XCUITest, real touches, iPad): a tap moves focus to the pane under it, checked by what each Rex terminal received; a 180 pt finger drag moves the line 180 pt and the server's ratio with it. Outside the unit scheme and CI like the Arrange Keys one: it needs a Rex server, and one run is about twelve minutes because XCUITest waits out its idle timeout on every step.
  • Simulators, against a throwaway Rex server behind the dev sshd harness:
    • Vision Pro: tiles with RUNNING and NEEDS YOU; attach, two-way input, vim in and out, program exit, size ownership.
    • Vision Pro: + TAB from a Rex tab api created api-2 in the same directory and opened it as a second live tab.
    • Vision Pro: with no server reachable, an external backend=rex launch showed the no-server message and started nothing.
    • Vision Pro: killing the tab's SSH session in the foreground ended the tab with RECONNECT / CLOSE TAB.
    • iPad: backgrounded, connections killed, returned → the tab re-attached by itself.
    • Vision Pro, with a real claude (2.1.325) in the Rex terminal: the Agent Bar shows; it stays on that tab after another window is fronted in Rex; a tab on a plain terminal shows none and gains it when switched to the agent's terminal.
    • Vision Pro, size contention: a program that asks for the cursor position on every resize, and a stand-in second client that reclaims the terminal whenever it loses it. Before the fix the two traded the terminal 82 times in 0.6 s with nobody typing; after, the only owner change is the stand-in's own, the server logs no write from the idle tab, and the program reads one reply per query. Typing in the tab still takes the size.
    • Vision Pro, switching: two stand-in full-screen programs in two terminals of one session. Before the fork fix the whole first screen stayed under the second; after, only the second shows.
    • iPad and Vision Pro, panes (MULTIPLEX_AUTO_PANE_ACTIONS): split right and down, ratio, focus, zoom and back, close, new tab. Host-side after each: the layout tree, every block owned by the tab, each terminal at its own pane's columns × rows, and the session's active window unmoved. A split made from the host with rex split appeared in the tab; output printed into a pane hidden behind a zoom was there when the zoom ended.
    • iPad, one pane held by a stand-in client at 150x40: that pane alone showed it in smaller text, its siblings kept their grids, and it returned when the stand-in left.
    • iPad, three panes: backgrounded, connections killed, returned → every pane re-attached into the same emulators, the keyboard on the pane it was on.
    • Vision Pro and iPad, another client's size: a stand-in client takes a terminal running a real claude at 170x50 and types into it. Before, the tab (132x44) showed overlapping fragments; after, it shows the same screen as rex capture in smaller text, and returns to its own grid and text size when the stand-in leaves.
  • iPad simulator against Rex 0.1.0-preview.25 (revision 24), on the last four commits. The runs above were on earlier servers and were not repeated.
    • With no Experimental switch and no MULTIPLEX_REX: a fresh install showed the host's Rex sessions as tiles, and a tab attached.
    • Split right and down, ratio, focus, zoom and back, close, new tab; the host's layout tree, owners and active window after each step were as before.
    • A stand-in client closed one of three panes with undoable: the tab drew two. Six seconds later it called client.undo_close: the pane was back with its screen.
    • session.transfer_window on the window a tab drew, with no other window in the session: the tab ended with RECONNECT and its client left the server at once.
    • New Tab then Close Pane: the tab came back to the window it had left, live. exit in the first of three windows: the tab and the session's active window were both on the second. exit in a window the tab was not drawing: no change. exit in the last: ENDED with RECONNECT.
    • New tab, before and after the keyboard change, with temporary logging: the new pane was opened at 73 rows before and at 51 in each of seven runs after. The same loss showed against preview.23, so it is not the server's.
    • RexPanesUITests (real touches) passed on the keyboard change: both taps typed into their own pane, and a 180 pt drag moved the line 180 pt.

Not exercised end to end

  • The third commit (a cleanup pass) ran against the unit suites and the in-memory fake server only, not a real Rex server. It changes two behaviors: queued typing and the mosh-host rule above.

  • Vision Pro against preview.25: the last four commits ran there as unit tests only. That includes the keyboard change, whose claim also activates the scene on visionOS.

  • A real server older than preview.23. Both too-old paths (no revision in common; a welcome below the minimum) were shown by a fake server, and the first also by asking a preview.25 server for revisions 25 to 30.

  • A closed window's tab landing in a window another client owns (it is drawn at that client's size until someone types, by the same rule as a pane another client adds), and a tab that drew a floating layer when that layer closed (unit-tested on the wire).

  • The New Session sheet's REX choice by press (form state is unit-tested), and a setup script or agent launch typed through the app (measured through the CLI only).

  • Open Terminal on a named block in the app, and the Switch Terminal rows by press (New Tab takes the same road and was run).

  • Panes with the real Rex app as the other client, real touches on Vision Pro, the ALL PANES chip by touch, a paned tab moved between windows and a file dropped on a pane (both unit-tested only), more than nine panes (fake server only), and iPhone.

  • Size contention and size following with the real Rex app itself (both measured with a stand-in client; when the Rex app chooses to reclaim a terminal is not known), a tab whose pane is off screen when the size changes hands, and mouse input on a Rex tab after the fork change (unit-tested on the wire only).

  • The plain-text tail for very large scrollback, and file drop on a Rex tab.

  • Rex on Linux, a fish login shell, and whether real agents emit OSC 7501 while working (Claude Code reported no status at its folder-trust prompt; the other tests used a stand-in program).

  • The ja strings were not run through textlint; zh-Hant was linted with zhtw-mcp.

Known limits

  • A tab draws one layer of one Rex window. Floating layers over the layout, moving and swapping panes, and closing or renaming a window are not built, and what the Rex app has zoomed is not followed.
  • Attaching takes the size of every pane of the window from whoever held it, where it used to take one terminal's.
  • Each pane is an SSH channel, so sshd's MaxSessions caps a tab near nine panes. A pane past that says so in its own pane; the rest of the tab is unaffected.
  • No external launch lands inside an existing Rex session; a named Rex target gets a fresh session.
  • A Rex tab rides SSH on a mosh host. mosh needs a Rex terminal client to run in mosh-server's PTY and Rex ships none (rex block stream answers not implemented on preview.21); recorded as a todo waiting on upstream in docs/agents/backends-and-probe.md, with what a prototype PTY client ran into.
  • The attach depends on an undocumented Rex CLI command (rex __internal dial-stdio). If Rex renames it, the tab fails and shows the reason.
  • A Rex tab has no prefix-key list, Copy Mode or HISTORY.
  • After the keyboard changes hands UIKit still reports it hidden and shown again about 270 ms later; the panes are 73 rows for one layout pass, which costs the terminal two more resizes and the screen nothing.
  • Nothing ties a rendering to the grid its emulator has at the moment it is fed. A pane that shrinks between the fetch and the feed gets a rendering made for more rows than it has. The keyboard change removes the one case seen; the complete fix (a feed that is refused when the grids differ) is described in docs/agents/panes.md and not built.

Open for the maintainer

  • Autostart. Whether a create may start a Rex server is undecided and unmeasured (a server started from an SSH login is the one the host's Rex app then adopts). Until then Rex cannot be a default backend, so a host with only Rex still needs tmux or herdr as its default.
  • Store listing. docs/store-metadata.md records the surface; the listing copy under fastlane/metadata/ does not mention Rex.
  • String Catalog. The new keys were inserted by hand in file order. ./Tools/build.sh strings re-sorted the whole file and marked keys stale, so its output was not kept; the catalog was instead compared with both builds' .stringsdata (no key missing, none unused).
  • + TAB. A Rex tab's New Tab lives in the REX panel only, following the recorded rule that remote structure belongs to the shortcut panel (herdr's + TAB row exists for its setup-script rider). Say if it should be in + TAB too.
  • TestFlight note. It is at 3994 of 4000 characters; fitting the pane steps meant shortening the Duo, Pencil and tmux steps' wording.
  • Which window after a close. The tab follows Rex's own rule (the window after the closed one, or the one before if it was last), so it agrees with the Rex app. After New Tab that is the window the tab came from only when the new one was last in the order, which it is when Rex appends it. Say if "back to where this tab was" should win instead.
  • Undo close. Rex revision 20 and later can reopen a pane, window or session its closer closed within about a minute (client.undo_close). Not adopted: only the client that closed can undo, so it needs a row of its own, and the reopened pane's window becomes the session's active one, which every other call here avoids. Say if it is wanted.

A HostStore handed its own directory isolated hosts.json but still
mirrored every added host into the simulator's real synchronizable
Keychain. The app adopted them on its next launch: the test simulators
had accumulated 100 and 86 box / devbox hosts, and a deck screenshot
showed NO SIGNAL tiles instead of the seeded host.

The mirror is now a value, HostRecordMirror. The app's store uses the
Keychain; a store with an injected directory gets a private in-memory
mirror, and a test that reads back what a store mirrored passes its
own. One test still touches the real Keychain, with a payload that
cannot decode as a host, so even a killed run cannot add one.

The shipped app is unchanged. A simulator that already accumulated
hosts is cleared with `xcrun simctl keychain <udid> reset` and one
launch; the recipe is in docs/agents/sync-and-widgets.md.
Rex (superlogical.com/rex) sessions on a host appear on the deck beside
its tmux and herdr ones: one tile per session, its windows on the spine,
its terminal blocks as panes, the fronted block's screen as the
miniature. The rail offers + REX when discovery finds sessions, and Host
Settings lists REX under Backends. Programs that report status through
OSC 7501 drive RUNNING and NEEDS YOU directly.

Rex ships no terminal client, so a Rex tab is a third transport beside
the SSH PTY and mosh. RexSession speaks the server's own WebSocket
protocol (WebSocketCodec, RexWire) through `rex __internal dial-stdio`
on a PTY-less SSH channel: the screen, colors, cursor and scrollback
are restored on attach, and a link lost to suspension re-attaches on
return. One tab is one terminal. The tab's REX key lists the session's
terminals and switches to another; Open Terminal in the tile menu opens
one as its own tab. A window's split layout is not drawn.

New Session's Runs on bar, a Rex tab's + TAB, and an external
`action=agent&backend=rex` create a Rex session in one exec
(`rex do -e <lua> --args <json>`). What the user typed travels as JSON
arguments, never as script text. The label is settled against the live
list, and the setup script and launch line ride `initial_input`.

Multiplex never starts a Rex server: every invocation carries
REX_AUTOSTART=0, and a create with no server running says so and makes
nothing. Because the default backend must answer on an idle host, Rex
is never a host's default (`canBeDefault`); the record demotes it to a
secondary on every path that could set it.

Measured against Rex 0.1.0-preview.19 (API revision 14). The decisions
and the measurements behind them are in
docs/agents/backends-and-probe.md.
…x code

A cleanup pass over the Rex backend. Three things behave differently.

A Rex tab's write now queues and returns; a drain task makes the calls.
The input pump awaits each write, so a write that waited for the
server's answer made every keystroke its own round trip, queued behind
the last, and the batching the code described never happened.

Whether a tab rides mosh is asked in one place (`ridesMosh`). A Rex tab
rides SSH whatever the host prefers, but scrollback, FILE and the bar's
MOSH badge read the host's preference directly: on a mosh host a Rex tab
had no scrollback, no FILE, and a MOSH badge.

Helper chips on a Rex tab follow the wall probe's record. They polled a
focused-pane query that has no Rex answer and never left their first
value.

Duplication removed:
- The Rex run is the SSH run with a different open step, not a copy.
- RexOneShot was OneShotGate; the Rex attention fallback was the tmux
  verdict; the agent-name map was herdr's; base64url had a helper.
- The "nobody named this window" rule lives once, in RexWire, for the
  deck's spine and a tab's Switch Terminal list. Session id vetting
  moved there too, so TerminalRoute no longer calls into a service.
- One factory for attach modes, one sentence for a failed create, one
  spelling of the product's name ("Rex", not "rex", in the offer alert).
- A mint no longer settles its label twice; the script's pass against
  the live list is the one that counts.

Less work on the terminal's path:
- The WebSocket decoder stopped copying the rest of its buffer after
  every frame, and frames are masked in place.
- Stream output with no server message in it passes through uncopied.
- The alternate-screen watch no longer allocates per ESC byte.
- The two screen reads of an attach are asked together.

Also gone: `reportsClientCount` and `shortcutBackend`, which nothing
needed, and a no-op exec the file viewer made for a Rex tab.
The agent bar read the session's fronted pane (`activeAgent`). That is
right for a tmux or herdr tab, which shows the whole session, and wrong
for a Rex tab, which is one terminal: the bar left a tab still showing
Claude Code as soon as the Rex app fronted another window, and never
appeared on a tab opened or switched to a terminal that was not in
front.

A Rex tab now asks for the agent in the terminal it is showing
(`TmuxSession.agent(inPane:)`), and finds its session by id rather than
by a label another session can take. The controller learns the terminal
when the attach settles on one (`rexBlockID`, which replaces the
switch-only override), so a reconnect returns to it as well.

This takes back part of the previous commit. The bar already followed
the wall probe through the window's own observation, with its grace
before hiding; the loop added for backends with no focused-pane query
duplicated that and skipped the grace. Such a backend now runs no loop.

Reproduced and checked on the Vision Pro simulator against a throwaway
Rex server running a real `claude`: with another window fronted in Rex,
a tab on the agent's terminal keeps its bar; a tab on a plain terminal
shows none and gains it when switched to the agent's.
The shortcut key opens a panel whose switch list may hold one row or
ten, and nothing on the key said which. It now lights (primary ink and
the signal border, the UMD chips' `prominent`; not the latch's fill,
which means ON) while the list has somewhere else to go.

`TmuxSession.hasSwitchChoices` states the rule: more than one window
(herdr: workspace), or on Rex more than one terminal, since a Rex tab is
one terminal and a single split window already has a second row. The
window reads it off the wall probe's record (`probedSession(for:)`,
which the agent bar's lookup now shares), so the key trails a new or
closed window by up to one probe tick.

Both rails re-ink the existing control rather than rebuild: the probe
moves this while the key's own panel may be open (New Window is a row
there), and a rebuilt UMD bar would pull the chip from under its
popover. `shortcutHasChoices` therefore stays out of the bar's
presentation key.

Checked on the iPad simulator against the dev-sshd harness: a tab on the
three-window `main` session shows the TMUX key lit. The unlit state, the
in-place change and the Rex rule are covered by unit tests only; the REX
key was not run against a live Rex server.
A Rex terminal open in Multiplex and in the Rex app at once flickered in
the app: the two clients kept trading the terminal's size.

The Rex server keeps the terminal and answers its queries itself. The
tab's SwiftTerm reads the same output and answered too, and that answer
went out as a terminal.write, which is also what claims the size. So a
tab nobody was touching took the terminal back whenever the program
asked something, and a program that asks on every resize made it a loop.
The program also read each reply twice.

SwiftTerm handed the host one send() for what a person did and for what
the terminal said by itself, so the fork now marks the first kind
(Terminal.isSendingUserInput) and the iOS view routes the rest to a new
TerminalViewDelegate.sendTerminalReport, which defaults to send(). A Rex
tab drops those; keys, mouse events and prompt clicks still go and still
claim. Other tabs are unchanged.

Measured against a throwaway server with a stand-in client that reclaims
the block whenever it loses it: 82 owner changes in 0.6 s before, and
after only the stand-in's own take, with no terminal.write from the idle
tab. Typing in the tab still takes the size.
# Conflicts:
#	fastlane/testflight-whats-new.txt
Two ways a Rex tab ended up with stray characters, both reproduced
against a throwaway Rex server.

Switching the tab between two terminals that each run a full-screen
program left the first one's screen under the second. Every redraw of a
Rex tab is RIS plus a rendering, and SwiftTerm's RIS did not empty the
alternate screen: the buffer is emptied only on the way out of it, and
is not blanked on the way back in once it has rows. With two stand-in
full-screen programs the whole first screen stayed. The fork's reset now
clears the alternate buffer too. A shell on either side hid it, which is
why the first switch tests passed.

While another client held a terminal at a different size, the tab went
on parsing its output at the pane's own grid. Since the tab stopped
answering the terminal's queries, nothing claims the size back until
someone types, so this lasted as long as the Mac was the one in use. The
stream says what size the terminal is and whose; a size that is another
client's is now followed. The session holds the stream, waits for the
repaint a resize sets off to go quiet, has the emulator take the grid,
and draws the screen again, without replaying the held bytes the
rendering already contains. The pane gives SwiftTerm the grid by giving
it the frame: text shrinks until the grid fits, and the room left over
comes off the trailing and bottom edges. The grids reported on the way
are never sent on as the tab's own. Typing in the tab still claims the
size, and the pane is its own again.

Redraws now run one at a time; two sharing a hold let the first release
the stream under the second.
Rex speaks a preview server's protocol, which moved from API revision 14
to 18 within a week, so nobody should meet it by accident. Settings gains
an Experimental section with a "Rex sessions" switch, off by default.

The switch is per device and a host's record is not: `secondaryBackends`
keeps `rex` whatever the switch says, because records sync and another
device may have it on. The gate sits where the record is read
(`SessionBackend.isAvailable`, asked by `monitoredBackends`, `monitors`
and `showsBackendIdentity`), so the probe loop, tiles, New Session,
widgets and external actions follow without checks of their own. The
discovery riders and Host Settings' check bar list backends directly and
use `availableCases`; the check bar carries a hidden checked `rex`
through an edit. Nothing observes the switch: the hub re-reads the host
on every refresh.

`MULTIPLEX_REX=1` forces it on; the unit-test scheme sets it so tests
that build Rex hosts do not depend on a simulator's defaults.

Also records why a Rex tab cannot ride mosh yet and what to re-measure:
Rex ships no terminal client (`rex block stream` still answers "not
implemented" on preview.21), and a throwaway PTY client run by a real
mosh-server met four traps that are now written down for whoever builds
it once upstream does.
A Rex tab showed one terminal of its session and reached the others
through a list. It now draws the whole Rex window it was opened on: one
emulator per terminal block, laid out as the server's split tree, with a
frame around the pane the keyboard is on. Dragging the line between two
panes resizes them, and the REX panel's rows split the focused pane right
or down, zoom it, close it, or open a new Rex tab.

Nothing above the transport is Rex's. `PaneLayout` is the app's own pane
tree and its geometry; `PanedTerminalTransport` is what a backend that
hands its panes out one stream each looks like to a tab; `TerminalScreen`
is one emulator endpoint, of which a tab has one, or one per pane; and
`PaneSplitView` sits where the single emulator view sat, so keyboard
avoidance, bottom chrome and the key rail are shared. "The terminal" of a
tab is its active screen's view, so the chrome that read it follows the
focus from pane to pane without a second version. tmux, herdr, shell and
mosh tabs keep the single-emulator path. docs/agents/panes.md records the
seam and what a second backend (tmux control mode, herdr) would have to
do; neither was measured or built.

`RexSession` now holds one control connection and one data connection per
terminal. The layout is the server's: the tab asks (`session.new_split`,
`resize_pane`, `block.close`, `new_window`) and hears the answer in the
view like any other client's change. Measured against a throwaway server
at the pinned API revision:

- A pane is laid out before its terminal is opened, because a screen is
  rendered for the size it will be drawn at.
- The tab's focus is its own. `focus_block`, and `focus: true` on a new
  split or window, also make that window the session's active one, which
  is the tab the Rex app on the host is showing.
- Zoom is the tab's own for the same reason: the server's cannot be
  aimed at the tab's focused pane without moving the session. The hidden
  panes keep their size and their output.
- A drag sends only the newest ratio, and the server's answer to an
  earlier one no longer pulls the line back.
- Typing claims every pane another client holds. A pane another client
  just made is drawn at its owner's size until then.
- The line is dragged by a press with no delay. A pan recognizer lost
  the first twenty points of a drag.

Attaching now takes the size of every pane of the window, not of one
terminal. Each pane is an SSH channel, so sshd's MaxSessions caps a tab
near nine panes; one that cannot be opened says so in its own pane.

Rows of the switch list that would read the same are counted, since a
window split three ways is three shells with one label. A panel row with
no key behind it shows no empty keycap.

Real touches (the tap that moves focus, the finger on a line) are covered
by `RexPanesUITests`, outside the unit scheme and CI: it needs a Rex
server.
Rex is at 0.1.0-preview.25 and API revision 24; the hello still asked
for revision 14, the one the client was first written against. A server
settles on the newest revision both sides speak and translates to it, so
the hello now says the newest this client knows (24) and the oldest it
can use (14), and the welcome's answer is read.

Every call and event a tab makes or handles was sent at 14 and at 24 to
one preview.25 server, and at 19 to a preview.23 one. The answers differ
only in ids, so the parser is unchanged. The probe and mint scripts,
`ls -q`, `kill` and the stdio bridge run unchanged with the preview.25
CLI, which also probes a preview.23 server.

A server with no revision in common closes the connection with a reason
that names the side to update, which is already the tab's ended line
(measured by asking a preview.25 server for 25 to 30). One from before
revisions were negotiated welcomes at its own revision; the attach now
fails there and says to update Rex. Only a fake server has shown a
server that old: nothing before preview.23 is installed any more.

Two fixtures captured off preview.25, the probe's output and the head of
a terminal stream, each get a test beside the preview.19 ones, and the
fake server negotiates the way a real one does.

What revisions 20 to 24 added is recorded with what this client does
about it. Undoable closes and `client.undo_close` are not sent,
`session.transfer_window` ends a tab drawing that window like any closed
window, and a window's second zoom is ignored like the first. A tab's
reaction to another client's undoable close and to a transferred window
was measured on the iPad simulator.

Also brings docs/store-metadata.md's Rex rows up to what a tab has drawn
since panes landed.
The switch was there because a preview server's protocol had moved under
the client twice in a week. The client now states a range of revisions
and was read against the newest, so the gate goes. Settings loses its
Experimental section, and a host shows Rex once its record lists it (the
rail's + REX offer, or the box in Host Settings), as it did before the
switch.

This is the switch's commit reversed. `ExperimentalFeatures`,
`SessionBackend.isAvailable` and `availableCases`, the hidden-backend
carry in Host Settings, the three strings, the tests and the
`MULTIPLEX_REX` override are gone, and the code they touched is back to
what it was. A record that listed `rex` while a device had the switch
off is monitored on that device now. The stored preference is left where
it is; nothing reads it.

The TestFlight notes drop the switch from the Rex entry and its steps.
Opening a new Rex tab from a paned tab lost the top of the new pane's
screen about three times in five: a shell's first line was missing and
the prompt sat a row low. It happened against Rex preview.23 as well as
preview.25.

The pane with the keyboard was removed first and the keyboard claimed
for its successor a turn later. In between, UIKit dismissed the keyboard
with its first responder, and the layout pass the transport is answered
from measured the panes without it. The new pane's terminal was opened,
sized and rendered at 73 rows, and the pane was back at 51 before that
rendering was fed, so its blank rows scrolled the emulator. Closing the
focused pane removes its cell the same way.

`PaneSplitView.apply` now runs a closure once the new cells are in and
before the old ones go, and `syncPanes` moves the keyboard there whenever
the tab had it. Only an attach's first claim still waits a turn. The
coordinator is pointed at the new pane before the claim, because keyboard
avoidance acts only on the terminal it names.

With the handover in place the new pane was opened at 51 rows in each of
seven runs on the iPad simulator. In its final shape, one claim for
every case, it was checked by a screenshot of a new tab and by the
real-touch test (tap to focus, drag a line).

Two things are left as they were and written down in
docs/agents/panes.md. UIKit still reports the keyboard hidden and shown
again about 270 ms later, which costs the terminal two more resizes and
the screen nothing. And nothing yet ties a rendering to the grid its
emulator has when it is fed.
Closing the Rex tab a Multiplex tab was showing ended the Multiplex tab:
DETACHED and RECONNECT, while the session's other tabs were one press
away. Open a new Rex tab, exit its shell, and the tab you came from was
gone from the screen.

A tab whose window is gone now moves to the window Rex itself shows
next. Rex's rule for a closed active window is the one after it, or the
one before it if it was last; the tab walks the same way from the closed
window's place in the tab order it last read, passing windows with no
terminal. A tab and a Rex app that were both on the window land on the
same one. A window that only lost the layer the tab drew keeps the tab.
The tab ends, cleanly as before, only when no window of the session has
a terminal left.

The move is neither an attach nor a choice from the panel, so it claims
only terminals nobody owns and the window's own focused pane takes the
keyboard.

Measured on the iPad simulator against Rex preview.25. New Tab then
Close Pane came back to the window the tab had left. `exit` in the first
of three windows put the tab and the session's active window on the
second. `exit` in a window the tab was not drawing left it alone, and
`exit` in the last one ended it with RECONNECT.
@jhen0409
jhen0409 marked this pull request as ready for review November 27, 2026 07:28
@jhen0409
jhen0409 merged commit d00507a into main Nov 27, 2026
4 checks passed
@jhen0409
jhen0409 deleted the rex-backend branch November 27, 2026 09:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant