Files
headquarter/openspec/changes/persistent-terminal-sessions/tasks.md
T
alex fc873e2d6b docs: add terminal API and user documentation
- Add docs/api/terminal.md with WebSocket protocol and reset endpoint
- Add docs/features/terminal.md with user guide for persistent sessions
- Add docs/features/terminal-troubleshooting.md with diagnostic steps
- Mark tasks 8.1-8.3 complete

Refs: persistent-terminal-sessions tasks 8.x
2026-05-24 12:48:36 +00:00

65 lines
2.8 KiB
Markdown

## 1. Backend - TerminalSession Refactoring
- [x] 1.1 Add circular output buffer to TerminalSession (10KB, stores raw bytes)
- [x] 1.2 Add WebSocket connection tracking (support multiple connections, detach without closing)
- [x] 1.3 Add last_activity timestamp and idle timeout support
- [x] 1.4 Add reset() method to kill process and prepare for restart
- [x] 1.5 Add health check for docker exec process
- [x] 1.6 Modify read_output to also write to circular buffer
## 2. Backend - TerminalManager Refactoring
- [x] 2.1 Change session tracking from session_id to instance_id
- [x] 2.2 Add get_or_create_session() method (reattach if exists, create if not)
- [x] 2.3 Modify create_session to support reconnection (don't always create new)
- [x] 2.4 Add reset_session() method (kill existing, create new)
- [x] 2.5 Add attach_websocket() method (add WebSocket to existing session, replay buffer)
- [x] 2.6 Add detach_websocket() method (remove WebSocket, keep session alive)
- [x] 2.7 Add idle timeout background task (check every minute, cleanup after 30min)
- [x] 2.8 Handle concurrent connections (close old WebSocket when new one connects)
## 3. Backend - Terminal WebSocket Endpoint
- [x] 3.1 Modify endpoint to check for existing session first
- [x] 3.2 Add reconnection logic (attach to existing vs create new)
- [x] 3.3 Handle reset command from WebSocket (JSON message type: "reset")
- [x] 3.4 Add buffer replay on WebSocket attach
- [x] 3.5 Add proper cleanup on WebSocket disconnect (detach, don't kill)
## 4. Backend - API Reset Endpoint
- [x] 4.1 Add POST /api/projects/{project_id}/repositories/{repo_id}/instances/{instance_id}/terminal/reset endpoint
- [x] 4.2 Add authorization checks
- [x] 4.3 Call TerminalManager.reset_session()
- [x] 4.4 Return success/error response
## 5. Frontend - Terminal Component
- [x] 5.1 Add "Reset Terminal" button to terminal UI
- [x] 5.2 Handle WebSocket reconnection gracefully
- [x] 5.3 Display "Reconnecting..." indicator
- [x] 5.4 Handle reset confirmation dialog
- [x] 5.5 Display session status (connected, reconnecting, reset)
## 6. Frontend - Terminal Hook
- [x] 6.1 Add reconnection logic with exponential backoff
- [x] 6.2 Handle buffer replay on reconnect (process incoming bytes)
- [x] 6.3 Add reset function (send WebSocket message or call API)
- [x] 6.4 Add heartbeat/ping to detect disconnections faster
## 7. Testing
- [ ] 7.1 Test terminal session persistence across reconnections
- [ ] 7.2 Test output buffer replay
- [ ] 7.3 Test reset functionality
- [ ] 7.4 Test idle timeout cleanup
- [ ] 7.5 Test concurrent connection handling
- [ ] 7.6 Verify existing functionality still works (create, stop, delete instances)
## 8. Documentation
- [x] 8.1 Update API documentation with new reset endpoint
- [x] 8.2 Update user documentation about persistent terminals
- [x] 8.3 Add troubleshooting guide for terminal issues