Skip to content

Attach the terminal to tmux runs so Unix matches the Windows experience - #17

Merged
amanjaiman merged 2 commits into
mainfrom
feat/tmux-interactive-attach
Jul 10, 2026
Merged

Attach the terminal to tmux runs so Unix matches the Windows experience#17
amanjaiman merged 2 commits into
mainfrom
feat/tmux-interactive-attach

Conversation

@amanjaiman

Copy link
Copy Markdown
Owner

Why

On Windows (ConPTY backend) sleeperagent run puts you directly in the agent session: you prompt it normally while the watchdog monitors and auto-resumes after a limit reset. On Linux/macOS (tmux backend) the session started detached and invisible — and attaching to prompt the agent kicked the watchdog off via auto-detach. This makes the tmux backend match the Windows experience.

What

  • run from a real terminal now starts attached: after tmux new-session -d, a supervised tmux attach child wires the user terminal into the session while the supervisor keeps polling in the parent. Supervisor logs go to the instance log file (sleeperagent logs --name N) so they never corrupt the agent TUI.
  • Self-attach no longer triggers auto-detach: attachSuppressingPane hides our own client from the ClientAttached check. A manual tmux attach after the self-view exits is still treated as a takeover and auto-detaches as before.
  • View detach (prefix+d) keeps the watchdog running and returns console logging with a "still watching" hint.
  • Shutdown paths only detach tmux clients when the self-view is still active, so stopping the watchdog right after a takeover does not kick the human off the session.
  • --detached flag restores the old console-watch mode (hotkeys d/q/k). Non-TTY runs (scripts, CI) are unchanged, so existing integration tests needed no edits.
  • README + CHANGELOG updated.

Testing

  • go vet + go test ./... green on Windows (includes a new unit test for the suppression wrapper).
  • New real-tmux integration test test/integration_interactive_attach.sh (auto-attach on start, no self-auto-detach, view detach keeps RUNNING, takeover still auto-detaches), wired into run_all.sh.
  • Full integration suite (all 9 scripts) green in WSL (Ubuntu 24.04, tmux 3.4).

🤖 Generated with Claude Code

amanjaiman and others added 2 commits July 10, 2026 18:19
`sleeperagent run` from a real terminal now drops the user straight into
the live tmux session (a supervised `tmux attach` child) while the
watchdog keeps polling in the parent, logging to the instance log file.
The supervisor's own attach client is hidden from the auto-detach check
(attachSuppressingPane); detaching the view (prefix+d) restores console
logging with the watchdog still running, and a subsequent manual attach
still auto-detaches as a real takeover. New --detached flag restores the
console-watch mode; non-TTY runs are unchanged.

Verified with a new real-tmux integration test
(integration_interactive_attach) plus the existing 8, all green in WSL.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
- Takeover detection during the self-view: ClientAttached now counts
  clients while our view is up (via tmux list-clients) instead of
  masking them all, so a second human attaching still auto-detaches.
- Attach failure / view detach falls back to the classic console mode:
  hotkeys d/q/k engage late via a fallback channel, restoring the kill
  and detach affordances; runs from inside tmux ($TMUX set) skip the
  auto-attach entirely since tmux refuses nested attaches.
- Supervisor-initiated detach no longer yanks the user out of the view:
  it flashes a tmux status-line message and waits for them to detach
  (mirrors the pty backend), and the killed/ended paths wait (bounded)
  for the view teardown so final messages land on the console.
- Extracted setupInteractiveAttach and gave attach-existing (the
  crash-recovery path) the same interactive attach + --detached flag;
  deduped the detach message; replaced the 50ms waitCondition poll with
  a viewDone channel; refreshed the stale pty-only wording in logs.go.

Verified: go vet + unit tests green; all 10 integration tests pass in
WSL tmux, including a new second-client takeover test.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@amanjaiman
amanjaiman merged commit 21055db into main Jul 10, 2026
4 checks passed
@amanjaiman
amanjaiman deleted the feat/tmux-interactive-attach branch July 10, 2026 22:46
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