Skip to content

Conversation

@kajogo777
Copy link
Member

Summary

Implements persistent shell sessions that maintain state (environment variables, working directory, aliases) across multiple command executions.

Key Features

  • LocalShellSession: PTY-based local shell using portable-pty
  • RemoteShellSession: SSH-based remote shell using russh with PTY allocation
  • ShellSessionManager: Central manager for session lifecycle
  • Marker-based command completion detection
  • ANSI escape code stripping and output cleaning

Implementation Details

  • ShellSession trait for unified local/remote interface
  • Default session auto-creation for seamless persistent behavior
  • Session timeout and max session limits
  • Comprehensive test coverage (36 unit tests)

Files Changed

  • libs/shared/src/shell_session/ - Core session implementation
  • SSH integration tests disabled (require external Docker container)

Testing

# Run shell session unit tests
cargo test -p stakpak-shared --lib -- shell_session

# Run SSH integration tests (requires Docker SSH container)
# docker run -d --name test-ssh -p 2222:22 -e SSH_ENABLE_ROOT=true -e SSH_ENABLE_PASSWORD_AUTH=true -e SSH_ENABLE_ROOT_PASSWORD_AUTH=true -e ROOT_PASSWORD=testpass123 panubo/sshd:latest
# cargo test -p stakpak-shared --test ssh_integration_test -- --ignored

Implements persistent shell sessions that maintain state (environment
variables, working directory, aliases) across multiple command executions.

Key features:
- LocalShellSession: PTY-based local shell using portable-pty
- RemoteShellSession: SSH-based remote shell using russh with PTY allocation
- ShellSessionManager: Central manager for session lifecycle
- Marker-based command completion detection
- ANSI escape code stripping and output cleaning

Implementation details:
- ShellSession trait for unified local/remote interface
- Default session auto-creation for seamless persistent behavior
- Session timeout and max session limits
- Comprehensive test coverage (36 unit tests)

Files:
- libs/shared/src/shell_session/ - Core session implementation
- SSH integration tests disabled (require external container)
@kajogo777 kajogo777 marked this pull request as draft January 15, 2026 14:55
- Add execute_streaming method to ShellSession trait with OutputChunk/OutputReceiver types
- Implement streaming for LocalShellSession and RemoteShellSession
- Add execute_in_session_streaming to ShellSessionManager
- Integrate streaming into MCP execute_in_persistent_session with notify_progress
- Falls back to non-streaming execution on error
- Add 2 streaming tests (basic and multiline)
- Total: 251 tests passing
- Apply clean_shell_output to streaming chunks (not just final output)
- Track last_streamed_len to stream only new cleaned content
- Improve is_prompt_line detection for user@host patterns
- Remove control characters (\r, backspace) in clean_shell_output
- Update streaming tests to verify clean output
- Both local and remote sessions now stream clean output
- Only stream content up to the last newline character
- Prevents partial line updates that cause visual flicker
- Applied to both local and remote session streaming
- Replace custom strip_ansi_codes implementations with console crate
- Remove strip-ansi-escapes dependency, use console (same as TUI)
- Remove redundant wrapper functions and tests
- Use console::strip_ansi_codes() directly in shell session modules
@kajogo777 kajogo777 marked this pull request as ready for review January 20, 2026 15:26
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.

2 participants