-
Notifications
You must be signed in to change notification settings - Fork 402
Terminal Session Persistence and macOS Shell Optimization #2493
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Terminal Session Persistence and macOS Shell Optimization #2493
Conversation
8dc94d3
to
fc04a88
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @seidnerj thanks for taking the time to make this PR - this all looks really cool!
I've added a few questions/comments but they are really trivial things.
If you are able to clear these comments up then I think the best thing for really testing this would be to merge this into the beta branch so it can be published as a beta version to npm.
I'm really glad also that you have made this an opt-in feature with a configuration option, it means down the line we could hypothetically include this in a latest release much sooner as a 'beta feature'. So thanks for taking the extra time to do this too!
Another note - at some point we will need to copy the text strings into the other language files. There is a script you can run locally to do this (num run lang-sync
) but it might be worth holding off on this for now, in case there any changes to the english file in the meantime. Maybe this was your thinking anyway
Looking forward to seeing this integrated into the UI! 🍾
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR introduces terminal session persistence as a configurable feature, allowing users to maintain their terminal sessions when navigating away from the terminal page. It also enhances shell selection logic to prefer modern shells like zsh on macOS and adds comprehensive navigation protection mechanisms.
- Configurable terminal session persistence with user settings for preservation, warnings, and buffer size
- Enhanced shell selection logic that prefers
/bin/zsh
on macOS with intelligent cross-platform fallbacks - Navigation protection with warning dialogs and browser beforeunload events to prevent accidental session termination
Reviewed Changes
Copilot reviewed 13 out of 13 changed files in this pull request and generated 5 comments.
Show a summary per file
File | Description |
---|---|
ui/src/i18n/en.json | Adds internationalization strings for terminal persistence settings and warning dialogs |
ui/src/app/modules/settings/settings.component.ts | Implements settings UI logic for terminal persistence configuration with confirmation dialogs |
ui/src/app/modules/settings/settings.component.html | Adds HTML form controls for terminal persistence settings with conditional visibility |
ui/src/app/modules/platform-tools/terminal/terminal.component.ts | Implements navigation guards and session management logic for terminal persistence |
ui/src/app/modules/platform-tools/terminal/terminal-routing.module.ts | Adds canDeactivate guard to terminal routing for navigation protection |
ui/src/app/core/terminal.service.ts | Extensive refactoring to support session persistence, reconnection, and proper resource management |
ui/src/app/core/settings.service.ts | Adds terminal persistence settings to the settings service with default values |
ui/src/app/core/settings.interfaces.ts | Extends settings interface to include terminal persistence configuration options |
ui/src/app/core/components/confirm/confirm.component.ts | Adds customizable cancel button label support to confirmation dialogs |
ui/src/app/core/components/confirm/confirm.component.html | Updates template to use customizable cancel button labels |
src/modules/platform-tools/terminal/terminal.service.ts | Backend implementation of persistent terminal sessions using singleton pattern |
src/modules/platform-tools/terminal/terminal.gateway.ts | Adds WebSocket message handler for destroying persistent sessions |
src/core/config/config.service.ts | Integrates terminal persistence settings into the configuration service |
Thank you :) this was a bit difficult to nail down, but I think I got it working properly. This specific thing has been driving me crazy as I would be running certain commands in the terminal only to realize I had navigated out of the page and things would get terminated! I will take a look at all your comments and resolve them. Looking forward to seeing this released soon, it's a real pain :) |
also if you can rebase this onto the |
Implements configurable terminal session persistence with the following features: Backend changes: - Add terminal persistence setting to UI config interface - Implement persistent terminal sessions using static class properties - Add session cleanup endpoint for destroying persistent sessions - Proper buffer management and content restoration - Session termination warning and buffer size controls Frontend changes: - Add terminal persistence toggle in Settings → General - Add warning control and buffer size settings with smart UI logic - Implement navigation guards for both Angular routing and browser navigation - Add confirmation dialogs with customizable button labels - Session cleanup when disabling persistence with user confirmation - Convert diagnostic logging to console.debug for cleaner production output Translation updates: - Add all necessary translation keys for settings and confirmation dialogs - Support for HTML formatting in warning messages
- Add process-exit event handler to reconnectTerminal method - Ensure auto-restart works on first navigation, not just after refresh - Backend now emits process-exit events for persistent terminals - Replace deprecated substr with substring
- Add getPreferredShell() method to select optimal shell per platform - On macOS: prefer /bin/zsh if available, fallback to bash/sh - Other platforms: use existing bash/sh fallback logic - Apply consistent shell selection for both regular and persistent terminals
- Remove all console.debug statements from frontend terminal code - Fix ESLint formatting issues (trailing spaces, empty blocks, etc.) - Maintain functionality while meeting linting standards
- Add terminalBufferSize constant to globalDefaults.ts - Update getPreferredShell() return type to union type for better type safety - Replace hardcoded buffer size values with global constant - Make cancelButtonLabel optional in confirm component - Add conditional display for terminal settings based on terminal access
- Remove empty setTimeout block in terminal service - Reduce verbose logging and change to debug level for performance - Sanitize user input logging to prevent security risks - Update Bootstrap 4 classes (pl-*) to Bootstrap 5 (ps-*)
- Replace persistentTerminal any type with IPty | null - Replace dataDisposable any type with IDisposable | null - Add proper typing for exit code parameter - Import required types from node-pty and xterm packages
- Remove redundant globalThis.terminal.bufferSize fallback since config service already handles default - Update navigation warning message to be more accurate about process termination - Change "any running processes will be stopped" to "all foreground processes will be terminated" - Better reflects the actual behavior where background processes may continue running
- Replace static variables with localStorage for cross-tab communication - Add atomic check-and-set logic to prevent race conditions - Implement "Terminal Already Open" modal when second tab tries to access terminal - Add beforeunload cleanup to handle crashed/closed tabs - Make confirm component buttons conditional to show only when labels provided - Fix onExit callback parameter type to match IPty interface
- Remove debug console.log statements for production compliance - Fix ESLint import ordering and spacing issues - Clean up trailing whitespace and formatting - Ensure all linting rules pass and builds complete successfully
fc04a88
to
fad23c8
Compare
Okay, I fixed all of the above, this now contains:
Let me know if you need anything else! |
Hi @seidnerj this is looking good! please continue to push fixes to this branch. Some things we should work towards:
these are just some comments i have for now, i will continue to comment here if and as i note more things. if there are any that you disagree with or have other ideas for, be sure to let me know! |
eeacd0e
to
1b12292
Compare
Sounds like a bug in xterm.js, have you/anyone else reported this? We could try downgrading to an earlier (but still newer than what we had) version and see when/if this bug gets introduced. |
afb4460
to
61ee610
Compare
cbe5b36
to
059c80d
Compare
Hi @seidnerj |
Nope, I think this is it. Sounds good to me! |
happy for you to merge this into the beta-5.3.1 branch (which it is already based against in this PR)! please use the 'squash and merge' option 😄 |
I have squash merged the PR into the beta-5.3.1 branch, but I cannot push it upstream obviously. |
Took a quick look again, and I see I forgot to get rid of the two following string constants: This was from an earlier iteration when I thought about limiting the the number of active terminals to only one at any given time, but then I realize I might as well just connect to all of them at the same time. |
that’s okay i have taken care of this in another commit 🙂 |
♻️ Current situation
Currently, when users navigate to the terminal page (
/platform-tools/terminal
), a new terminal process is spawned. However, when users navigate away from the terminal page, the terminal process is immediately terminated. This means:Additionally, the shell selection logic was basic and didn't take advantage of modern shells available on different platforms.
💡 Proposed solution
This PR introduces Terminal Session Persistence as a configurable feature with the following enhancements:
1. Configurable Session Persistence
2. Enhanced Navigation Protection
3. Smart Shell Selection
/bin/zsh
(default since macOS Catalina) when available4. Buffer Management
⚙️ Release Notes
New Features
Settings
Three new settings have been added under Settings → General:
User Experience Improvements
➕ Additional Information
Architecture Changes
The implementation uses a singleton pattern for persistent terminals on the backend, with careful event listener management to prevent memory leaks. The frontend maintains WebSocket connections across navigation when persistence is enabled.
Backward Compatibility
All changes are fully backward compatible. The default behavior (persistence OFF) preserves the existing terminal experience. Users must explicitly enable persistence to access the new functionality.
Performance Considerations
Testing
Manual Testing Performed
Edge Cases Covered
Areas for Future Testing
Reviewer Nudging
Good entry points for review:
/ui/src/app/modules/settings/settings.component.ts
to understand the new configuration options/src/modules/platform-tools/terminal/terminal.service.ts
for the singleton pattern and session management/ui/src/app/core/terminal.service.ts
for WebSocket connection management/ui/src/app/modules/platform-tools/terminal/terminal.component.ts
for the protection mechanismsKey areas to focus on: