Skip to content

feat: session hardening, TUI improvements, and error handling#12

Merged
moukrea merged 10 commits intomainfrom
feat/session-hardening-and-tui
Mar 29, 2026
Merged

feat: session hardening, TUI improvements, and error handling#12
moukrea merged 10 commits intomainfrom
feat/session-hardening-and-tui

Conversation

@moukrea
Copy link
Copy Markdown
Owner

@moukrea moukrea commented Mar 29, 2026

Summary

  • Harden error handling: PTS fallback, shell path validation, socket path safety
  • Session management: prevent self-attach, detect attach loops, force-steal multi-attach
  • TUI: snagged-by relationships display, alternate screen buffer detection, kill notifications
  • Terminal: set TERM/COLORTERM env vars, re-apply terminal size on detach

Commits

  • fix(snag): set TERM and COLORTERM env vars in spawned PTY sessions
  • fix(snag): prevent session from attaching to itself
  • feat(snag): detect alternate screen buffer in TUI preview
  • fix(snag): re-apply terminal size on client detach with remaining viewers
  • feat(snag): show kill notification in attached terminals
  • feat(snag): prevent simultaneous multi-attach with force-steal option
  • feat(snag): detect and prevent attach loops
  • feat(snag): show snagged-by relationships in TUI with hide toggle
  • fix(snag): harden error handling and implement PTS fallback

Test plan

  • cargo test — 13/13 tests pass
  • cargo build clean

moukrea added 10 commits March 29, 2026 14:02
The daemon detaches from the terminal on startup, so spawned shells
inherit an environment without proper TERM. Explicitly set
TERM=xterm-256color and COLORTERM=truecolor before exec to ensure
colors and terminal features work correctly.
Detect self-attach by comparing the client's controlling terminal
(via peer PID from Unix socket credentials and /proc/<pid>/fd/0)
with the target session's PTY path. Returns a clear error message
when a session tries to attach to itself.
Track ESC[?1049h/l and ESC[?47h/l transitions in PTY output to know
when a session is running a full-screen TUI app. When in alternate
screen mode, the preview shows '[TUI running: <app>]' instead of
garbled output. Normal preview resumes when the app exits.
…wers

Track each client's last known terminal dimensions. When a client
detaches and other clients remain attached, apply a remaining client's
terminal size to the session PTY so it matches the active viewer.
When a session is killed, attached terminals now display
'[Session killed by snag]' before disconnecting. For registered
sessions, the original terminal also receives a notification.
Non-read-only attach now fails if another active client is already
attached. Use --force to steal the session — the evicted client
receives '[Session stolen by another client]'. Read-only attaches
can still coexist with one active attach.
Walk the attach chain from target session through attached clients'
origin sessions to detect cycles. Shows the full chain in the error
message (e.g., 'attach would create a loop: A → B → C → A').
Subsumes the previous self-attach check as a special case.
Add snagged_by field to SessionInfo populated by resolving attached
clients' origin sessions via peer PID. TUI shows snagged sessions
in magenta with '← <source>' suffix. Press 'h' to toggle hiding
snagged sessions from the list.
- Implement get_pts_number_for_fd() fallback: scan sibling fds for
  /dev/pts/<N> symlinks when fdinfo lacks tty-index
- Validate SHELL env var before CString conversion to prevent panic
  on null bytes
- Use fallback path for socket_path.parent() instead of unwrap
@moukrea moukrea merged commit 4f3eed8 into main Mar 29, 2026
4 checks passed
@moukrea moukrea deleted the feat/session-hardening-and-tui branch March 29, 2026 12:06
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