Repository navigation
Conversation
`codeman tui` sets `window-size latest` for an attach, but a browser tab
that opens or resizes the same session mid-attach makes Codeman run
`resize-window`, which puts the window back on `manual` at the browser's
size. The terminal then showed a phone-sized pane, and typing or pasting
changed nothing until a detach and a fresh attach.
The attach now sets a per-session `client-active[91]` hook on every
session it dresses. It runs `set-window-option window-size latest` only
for the TUI's own client (`#{client_tty}`), so typing, pasting or
resizing the terminal hands the window back to it, the way plain tmux
follows whoever used it last. `restore()` removes the hooks before the
window sizes are put back, and only while they still name this tty.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A terminal that dies while attached (closed window, dropped SSH) never reaches restore(), so its client-active[91] hooks stayed on the sessions. TUI startup now removes ours whose tty has no live tmux client, next to the leaked-banner sweep. The TUI's own tty is never swept: the sweep is fire-and-forget, and an early Enter can arm that hook before the attach client exists. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…zes included A browser that opens a session sends a forced resize at its current size. Its pty does not change, so tmux keeps the TUI's client as the latest one and `client-active` never fires again, while Codeman's `resize-window` still pins the window to `manual` at the browser's size. Typing in the terminal then did nothing, which is the bug this branch fixes. An `after-resize-window[91]` hook now puts `latest` back after Codeman's resize, so tmux keeps deciding by the client used last; `client-active[91]` stays for Codeman's own attach (`setManualWindowSize()`), which sets `manual` without a resize. The owner's tty moves into the session option `@codeman-tui-follow`, and both hook commands are constants that read it, so no tty is interpolated into a hook and hooks whose owner is gone do nothing. restore() and the startup sweep drop the owner first, then our hooks. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
armFollowTyping() set the owner option, then a hook. On tmux before 3.3 there is no client-active hook, so the first set-hook failed and the arm answered false with the owner still set; restore() disarms only what armed, so it stayed on the session. A failed arm now drops the owner and any of our hooks it already set. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Thanks for this, kkalisz. The PR lets an attached
Smaller points:
With 1 to 3 fixed, this is mergeable. |
…hole hook array Review follow-up on the follow-typing attach. - Redraw (and every forced resize at an unchanged size) handed the window back to the terminal: an unchanged pty sends tmux no SIGWINCH, so the terminal stayed the latest client and the after-resize-window hook undid the resize-window. Session.resize() now nudges the pty one row first (FORCED_RESIZE_NUDGE_MS), then applies the size, so tmux counts the tab as the client used last; the second move bumps the guarded geometry revision too. Under manual with no attach the agent sees no change. - With the nudge, client-active[91] alone covers every case, so the after-resize-window hook is gone. It kept latest through every browser resize and cost the agent three height changes per resize; now the first resize after the terminal was used costs two and later ones one. The cost is stated next to the hook. - The leak sweep matched owners by tty, and Linux hands the next terminal the pty that just closed, so the common leak was never swept. The arm now records the TUI's pid (@codeman-tui-follow-pid), and the sweep keeps only sessions this process armed (a Set filled before the first write) or whose pid is another live process. One list-sessions call reads every owner. It also runs before each attach dresses its sessions, so `codeman tui <n>` gets it and a leaked hook cannot undo presizeWindow(). - `set-hook -u` on our index left an empty session-level array, which hides the user's global hook on that event. Disarm unsets the whole event when ours is its only entry, and arm refuses while the user has a global client-active hook. - Arm and disarm are one tmux call to read and one to write (`;` lists). - Docs: the "forced resize when a browser opens a session" wording was wrong (selectSession sends no force; only Redraw, a closing pop-out and the split pane do), fixed in tui-client.ts, docs/tui.md and the invariants, whose paragraph now stands on its own. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Thanks for the review. Pushed 70ee131 with all three blockers and the smaller points:
Smaller points:
12 of the new tests fail with the previous 🤖 Generated with Claude Code |
|
Thanks for the quick turnaround, kkalisz. This PR lets an attached I re-ran everything here. Typecheck, lint, format and the frontend checks pass. The four touched test files pass (194 tests, with the real-tmux file on tmux 3.4), and 16 of the new tests fail with master's Two things are left:
Optional: store the 60 ms nudge timer ( No need to push again: 1 and 2 go on top at merge time. If you would rather push them yourself first, that works too. |
Problem
Attach to a session with
codeman tui, then open the same session on a phone. The terminal is stuck at the phone's size: typing or resizing does not help until you detach and attach again.The cause is that a browser resize goes through
Session.resize(), which ends inresize-window, and that switches the window towindow-size manual. Codeman's own attach also setsmanual. After either one, the TUI'slatestsetting is lost for the rest of the attach.Fix
While a TUI attach is up, every session it can reach gets one hook and two session options:
client-active[91], which putslatestback when the TUI's client is used again (typing, pasting, resizing).@codeman-tui-follow, the attach's tty, which the hook reads.@codeman-tui-follow-pid, the TUI process, which the leak sweep reads.A browser resize makes the tab's client the latest one, because Codeman resizes that client's pty first. A forced resize at an unchanged size (Redraw, a closing pop-out window, the split pane) does not change the pty, so
Session.resize()now nudges the pty one row first. The user's Redraw then wins, and the terminal's next key takes the window back. Without an attach the window ismanualand ignores the client's pty, so the agent sees no change.Rules:
set-hook -t), never globally. Its command is a constant string with no-t, which reads the tty from the option.client-activehook, because a session array would hide it.client-active.codeman tui <n>is covered too.Cost: the first browser resize after the terminal was used changes the agent's height twice, where master changes it once. Later resizes from the same tab cost one.
Known limits:
switch-clientpath, used when the TUI runs inside Codeman's tmux, gets no hook.Changes
src/tui/tui-client.ts:armFollowTyping,disarmFollowTypingandclearLeakedFollowTyping, plus the hook and option constants.src/tui/tui-app.ts:beginAttachHandoffsweeps, arms the hook and disarms it inrestore(). The dashboard also sweeps at startup.src/session.ts: the one-row nudge for a forced resize at an unchanged size (FORCED_RESIZE_NUDGE_MS).test/tui/tui-follow-typing.test.ts(new) runs against real tmux with two pty clients. It is skipped below tmux 3.3.test/tui/tui-client.test.ts,test/tui/tui-app.test.tsandtest/session-resize-arbitration.test.tsare extended.docs/tui.md,docs/architecture-invariants.mdand a patch changeset.Verification
src.codeman tuiattach and the phone's resize sent through the/resizeroute:master🤖 Generated with Claude Code