feat: session hardening, TUI improvements, and error handling#12
Merged
feat: session hardening, TUI improvements, and error handling#12
Conversation
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
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.
Summary
Commits
Test plan
cargo test— 13/13 tests passcargo buildclean