feat: per-instance terminal sessions for multi-instance switching#24
Merged
feat: per-instance terminal sessions for multi-instance switching#24
Conversation
- Refactor frontend terminal from single shared instance to per-instance sessions, each owning its own xterm.js instance, transport state, timers, and reconnect logic. - Switching between running instances now hides inactive terminal containers instead of tearing down their PTY attachment, preventing disruption of long-lived TUI programs like Copilot CLI. - Add session lifecycle management: createTerminalSession, destroyTerminalSession, maybeDestroyInactiveStoppedSession, reconcileTerminalSessions, reconnectRunningTerminalSessions. - Add reportSessionError for unified per-session error handling. - Update docs/API.md, docs/ARCHITECTURE.md, and docs/PRD.md to document the new frontend session model and instance switch protocol. - Add comprehensive tests covering multi-instance switching, session lifecycle, reconcile logic, and per-session connection management. Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
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.
Overview
Refactor the frontend terminal from a single shared xterm.js instance to a per-instance terminal session model. Each running instance now owns its own terminal, transport state, timers, and reconnect logic.
Key Changes
Frontend Architecture
terminalSessions = {}stores independent session state for each instanceNew Functions
createTerminalSession(id)- Create new session with dedicated xterm instancedestroyTerminalSession(id)- Complete cleanup including termDataDisposablemaybeDestroyInactiveStoppedSession(id)- Cleanup stopped non-active sessionsreconcileTerminalSessions()- Sync sessions with instance state on refreshreconnectRunningTerminalSessions()- Auto-reconnect running sessions after network recoveryrenderTerminalSessions()- Show/hide session containers based on active selectionreportSessionError(session, prefix, err)- Unified per-session error handlingDocumentation Updates
Tests
TestIndexHTMLCoversMultiInstanceSwitching- Verify switching hooksTestIndexHTMLCoversSessionLifecycle- Verify create/destroy hooksTestIndexHTMLCoversReconcileLogic- Verify sync logicTestIndexHTMLCoversPerSessionConnectionManagement- Verify WebSocket managementBenefits
Testing
Checklist