# Tasks: High-Performance Web Terminal

## Task 1: Rewrite TerminalSession with asyncio-native I/O
**Status:** pending
**Files:** `apps/api/src/services/terminal_session.py` (full rewrite)
**Description:**
- Replace `select.select()` with `asyncio.add_reader()` for event-driven PTY reading
- Add output batching (2ms window)
- Add flow control (pause/resume based on client ack)
- Keep docker exec subprocess (optimized)
- Remove circular buffer (not needed with event-driven architecture)

## Task 2: Update TerminalManager for new session class
**Status:** pending
**Files:** `apps/api/src/services/terminal_manager.py`
**Description:**
- Update imports to use rewritten TerminalSession
- Verify session lifecycle methods still work
- Update DB persistence calls

## Task 3: Update WebSocket endpoint for binary frames + flow control
**Status:** pending
**Files:** `apps/api/src/api/terminal.py`
**Description:**
- Accept binary output frames from TerminalSession
- Handle `ack` flow control messages from client
- Send `ping` heartbeat
- Maintain existing auth and session management

## Task 4: Update frontend for binary WebSocket + WebGL
**Status:** pending
**Files:** `apps/web/src/components/terminal.tsx`, `apps/web/package.json`
**Description:**
- Set `ws.binaryType = "arraybuffer"`
- Send flow control `ack` messages
- Add xterm-addon-webgl with DOM fallback
- Optimize resize handling

## Task 5: Add performance benchmarks
**Status:** pending
**Files:** `apps/api/tests/benchmark_terminal.py`
**Description:**
- Input latency benchmark
- Output throughput benchmark
- Resize latency benchmark
- Reconnection time benchmark

## Task 6: Update/fix unit tests
**Status:** pending
**Files:** `apps/api/tests/unit/test_tool_instances_legacy.py`, new tests
**Description:**
- Fix any tests broken by terminal changes
- Add tests for new TerminalSession features

## Task 7: Run full test suite
**Status:** pending
**Description:**
- Run all API tests
- Verify no regressions
- Report quality gate results
