- Modified loadChatHistory() to check for active project before fetching all sessions - When active project exists, use project.sessions instead of fetching from API - Added detailed console logging to debug session filtering - This prevents ALL sessions from appearing in every project's sidebar Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
364 lines
9.4 KiB
Markdown
364 lines
9.4 KiB
Markdown
# SSE Refactoring Documentation Index
|
|
|
|
## Quick Start
|
|
|
|
**New to this project?** Start here:
|
|
1. **[SSE_FILE_TREE.txt](SSE_FILE_TREE.txt)** - Overview of all files and architecture
|
|
2. **[SSE_DELIVERABLES.md](SSE_DELIVERABLES.md)** - Summary of what has been created
|
|
|
|
**Ready to implement?**
|
|
1. **[SSE_IMPLEMENTATION_GUIDE.md](SSE_IMPLEMENTATION_GUIDE.md)** - Step-by-step integration
|
|
2. **[SSE_QUICK_REFERENCE.md](SSE_QUICK_REFERENCE.md)** - Code snippets and API reference
|
|
|
|
**Need to understand the design?**
|
|
1. **[SSE_REFACTOR_PLAN.md](SSE_REFACTOR_PLAN.md)** - Complete refactoring plan
|
|
2. **[SSE_ARCHITECTURE_DIAGRAMS.md](SSE_ARCHITECTURE_DIAGRAMS.md)** - Visual diagrams
|
|
|
|
---
|
|
|
|
## Documentation Files
|
|
|
|
### 📘 SSE_REFACTOR_PLAN.md (48KB)
|
|
**Complete refactoring plan and design document**
|
|
|
|
**Sections:**
|
|
- Executive Summary
|
|
- New URL Architecture
|
|
- EventBus Implementation
|
|
- SSE Endpoint Specification
|
|
- Route Implementation
|
|
- Integration with Existing Code
|
|
- Migration Path (4 phases)
|
|
- Risk Assessment & Mitigation
|
|
- Testing Strategy
|
|
- File Structure Summary
|
|
- Dependencies
|
|
- Success Criteria
|
|
- Rollback Plan
|
|
- Documentation Updates
|
|
- Next Steps
|
|
|
|
**Best for:** Understanding the full scope and design decisions
|
|
|
|
---
|
|
|
|
### 📗 SSE_IMPLEMENTATION_GUIDE.md (9.5KB)
|
|
**Step-by-step implementation instructions**
|
|
|
|
**Sections:**
|
|
- Step 1: Integration with server.js
|
|
- Step 2: Modify ClaudeService to emit events
|
|
- Step 3: Test SSE Endpoint
|
|
- Step 4: Browser Testing
|
|
- Step 5: Monitor Metrics
|
|
- Step 6: Test Reconnection
|
|
- Step 7: Load Testing
|
|
- Step 8: nginx Configuration
|
|
- Testing Checklist
|
|
- Troubleshooting
|
|
|
|
**Best for:** Implementing the changes and testing
|
|
|
|
---
|
|
|
|
### 📙 SSE_QUICK_REFERENCE.md (8.8KB)
|
|
**Developer cheat sheet**
|
|
|
|
**Sections:**
|
|
- File Locations
|
|
- Key Code Snippets
|
|
- EventBus Usage
|
|
- SSE Manager Usage
|
|
- Client-Side Usage
|
|
- Validation Middleware
|
|
- API Endpoints
|
|
- Event Types
|
|
- Migration Checklist
|
|
- Monitoring Endpoints
|
|
- Configuration
|
|
- Common Issues
|
|
|
|
**Best for:** Quick lookup while coding
|
|
|
|
---
|
|
|
|
### 📕 SSE_ARCHITECTURE_DIAGRAMS.md (30KB)
|
|
**Visual architecture documentation**
|
|
|
|
**Diagrams:**
|
|
- Overview Diagram
|
|
- Event Flow Diagram
|
|
- Connection Lifecycle Diagram
|
|
- Reconnection Logic Diagram
|
|
- Architecture Comparison (Before/After)
|
|
- Component Relationships
|
|
- Complete Command-to-Output Flow
|
|
- Error Handling Flow
|
|
|
|
**Best for:** Visual understanding of the system
|
|
|
|
---
|
|
|
|
### 📓 SSE_DELIVERABLES.md (7KB)
|
|
**Summary of all deliverables**
|
|
|
|
**Sections:**
|
|
- Overview
|
|
- What Has Been Created
|
|
- Core Implementation Files
|
|
- Key Features
|
|
- Integration Points
|
|
- Testing Strategy
|
|
- Migration Path
|
|
- Risk Mitigation
|
|
- Dependencies
|
|
- File Structure Summary
|
|
- Next Steps
|
|
- Success Criteria
|
|
- Support Resources
|
|
|
|
**Best for:** Executive summary and project overview
|
|
|
|
---
|
|
|
|
### 📄 SSE_FILE_TREE.txt (4KB)
|
|
**File structure and quick reference**
|
|
|
|
**Contents:**
|
|
- Complete file tree
|
|
- Event flow diagram
|
|
- Key improvements comparison
|
|
- Migration timeline
|
|
- Integration effort estimate
|
|
- Next actions
|
|
|
|
**Best for:** Quick overview and navigation
|
|
|
|
---
|
|
|
|
## Implementation Files
|
|
|
|
### 🔧 Services
|
|
|
|
#### **services/event-bus.js** (5.8KB)
|
|
**Central event pub/sub system**
|
|
|
|
**Key Methods:**
|
|
- `subscribe(eventType, sessionId, handler)` - Subscribe to events
|
|
- `emit(eventType, data)` - Emit an event
|
|
- `subscribeToSession(sessionId, handler)` - Subscribe to all session events
|
|
- `getMetrics()` - Get event metrics
|
|
|
|
**Usage:**
|
|
```javascript
|
|
const eventBus = require('./services/event-bus');
|
|
|
|
// Emit event
|
|
eventBus.emit('session-output', {
|
|
sessionId: 'session-123',
|
|
content: 'Hello from terminal'
|
|
});
|
|
|
|
// Subscribe
|
|
const unsubscribe = eventBus.subscribe('session-output', 'session-123', (data) => {
|
|
console.log(data.content);
|
|
});
|
|
```
|
|
|
|
---
|
|
|
|
#### **services/sse-manager.js** (11KB)
|
|
**Manages SSE connections**
|
|
|
|
**Key Methods:**
|
|
- `addConnection(sessionId, res, req)` - Add SSE connection
|
|
- `sendEvent(sessionId, res, data)` - Send event to client
|
|
- `broadcastToSession(sessionId, data)` - Broadcast to all clients
|
|
- `getConnectionCount(sessionId)` - Get connection count
|
|
- `getStats()` - Get connection statistics
|
|
|
|
**Usage:**
|
|
```javascript
|
|
const sseManager = require('./services/sse-manager');
|
|
|
|
// In route handler
|
|
app.get('/api/session/:sessionId/events', (req, res) => {
|
|
sseManager.addConnection(req.params.sessionId, res, req);
|
|
});
|
|
```
|
|
|
|
---
|
|
|
|
### 🛣️ Routes
|
|
|
|
#### **routes/session-routes.js** (13KB)
|
|
**Session API endpoints**
|
|
|
|
**Endpoints:**
|
|
- `POST /api/session/:sessionId/prompt` - Send command
|
|
- `GET /api/session/:sessionId/status` - Get status
|
|
- `GET /api/session/:sessionId/context` - Get context
|
|
- `POST /api/session/:sessionId/operations/preview` - Preview operations
|
|
- `POST /api/session/:sessionId/operations/execute` - Execute operations
|
|
- `DELETE /api/session/:sessionId` - Delete session
|
|
- `POST /api/session/:sessionId/duplicate` - Duplicate session
|
|
- `POST /api/session/:sessionId/fork` - Fork session
|
|
- `POST /api/session/:sessionId/move` - Move to project
|
|
|
|
---
|
|
|
|
#### **routes/sse-routes.js** (3.8KB)
|
|
**SSE streaming endpoints**
|
|
|
|
**Endpoints:**
|
|
- `GET /api/session/:sessionId/events` - SSE event stream
|
|
- `GET /api/session/:sessionId/events/status` - Connection status
|
|
- `GET /api/sse/stats` - Global SSE stats
|
|
- `GET /api/sse/test` - Test endpoint (dev only)
|
|
|
|
---
|
|
|
|
### ✅ Middleware
|
|
|
|
#### **middleware/validation.js** (6.2KB)
|
|
**Request validation middleware**
|
|
|
|
**Middleware:**
|
|
- `validateSessionId` - Validate session ID format
|
|
- `validateTerminalId` - Validate terminal ID format
|
|
- `validateCommand` - Validate command body
|
|
- `validateOperations` - Validate operations array
|
|
- `validateResponse` - Validate response body
|
|
- `errorHandler` - Error handler
|
|
|
|
**Usage:**
|
|
```javascript
|
|
const { validateSessionId, validateCommand } = require('./middleware/validation');
|
|
|
|
router.post('/session/:sessionId/prompt', validateSessionId, validateCommand, (req, res) => {
|
|
// Handler code
|
|
});
|
|
```
|
|
|
|
---
|
|
|
|
### 💻 Client-Side
|
|
|
|
#### **public/js/sse-client.js** (11KB)
|
|
**Browser-side SSE connection manager**
|
|
|
|
**Key Methods:**
|
|
- `new SessionEventStream(sessionId, options)` - Create connection
|
|
- `on(event, handler)` - Register event listener
|
|
- `off(event, handler)` - Remove event listener
|
|
- `disconnect()` - Close connection
|
|
- `getStatus()` - Get connection status
|
|
|
|
**Usage:**
|
|
```html
|
|
<script src="/js/sse-client.js"></script>
|
|
<script>
|
|
const stream = new SessionEventStream('session-123');
|
|
|
|
stream.on('output', (data) => {
|
|
console.log('Output:', data.content);
|
|
});
|
|
|
|
stream.on('error', (data) => {
|
|
console.error('Error:', data.error);
|
|
});
|
|
</script>
|
|
```
|
|
|
|
---
|
|
|
|
## How to Use This Documentation
|
|
|
|
### For Project Managers
|
|
- Start with **SSE_DELIVERABLES.md**
|
|
- Review **SSE_REFACTOR_PLAN.md** (Executive Summary and Migration Path sections)
|
|
- Check **SSE_FILE_TREE.txt** for quick overview
|
|
|
|
### For Backend Developers
|
|
- Read **SSE_REFACTOR_PLAN.md** (complete design)
|
|
- Use **SSE_IMPLEMENTATION_GUIDE.md** for step-by-step integration
|
|
- Reference **SSE_QUICK_REFERENCE.md** while coding
|
|
- Study **services/event-bus.js** and **services/sse-manager.js**
|
|
|
|
### For Frontend Developers
|
|
- Read **SSE_ARCHITECTURE_DIAGRAMS.md** (Event Flow and Connection Lifecycle)
|
|
- Use **public/js/sse-client.js** directly
|
|
- Reference **SSE_QUICK_REFERENCE.md** (Client-Side Usage section)
|
|
- Test with browser examples in **SSE_IMPLEMENTATION_GUIDE.md**
|
|
|
|
### For DevOps Engineers
|
|
- Review **SSE_REFACTOR_PLAN.md** (nginx Configuration section)
|
|
- Check **SSE_IMPLEMENTATION_GUIDE.md** (Step 8: nginx Configuration)
|
|
- Monitor using `/api/debug/metrics` and `/api/sse/stats` endpoints
|
|
|
|
### For QA/Testers
|
|
- Read **SSE_REFACTOR_PLAN.md** (Testing Strategy section)
|
|
- Follow **SSE_IMPLEMENTATION_GUIDE.md** (Testing Checklist)
|
|
- Use test endpoints and examples provided
|
|
|
|
---
|
|
|
|
## Common Tasks
|
|
|
|
### "I want to understand the architecture"
|
|
→ Read **SSE_ARCHITECTURE_DIAGRAMS.md**
|
|
|
|
### "I need to implement this"
|
|
→ Follow **SSE_IMPLEMENTATION_GUIDE.md**
|
|
|
|
### "I'm coding and need quick reference"
|
|
→ Use **SSE_QUICK_REFERENCE.md**
|
|
|
|
### "I need to review the full plan"
|
|
→ Read **SSE_REFACTOR_PLAN.md**
|
|
|
|
### "I want to see what files were created"
|
|
→ Check **SSE_FILE_TREE.txt**
|
|
|
|
### "I need to present this to stakeholders"
|
|
→ Use **SSE_DELIVERABLES.md**
|
|
|
|
---
|
|
|
|
## File Sizes Summary
|
|
|
|
```
|
|
Documentation:
|
|
SSE_REFACTOR_PLAN.md 48KB ████████████
|
|
SSE_ARCHITECTURE_DIAGRAMS.md 30KB ████████
|
|
SSE_IMPLEMENTATION_GUIDE.md 9.5KB ██
|
|
SSE_QUICK_REFERENCE.md 8.8KB ██
|
|
SSE_DELIVERABLES.md 7KB ██
|
|
SSE_FILE_TREE.txt 4KB █
|
|
|
|
Implementation:
|
|
routes/session-routes.js 13KB ███
|
|
services/sse-manager.js 11KB ███
|
|
public/js/sse-client.js 11KB ███
|
|
middleware/validation.js 6.2KB ██
|
|
services/event-bus.js 5.8KB ██
|
|
routes/sse-routes.js 3.8KB █
|
|
|
|
Total: ~168KB of documentation + ~51KB of code
|
|
```
|
|
|
|
---
|
|
|
|
## Support
|
|
|
|
For questions or issues:
|
|
1. Check the relevant documentation file above
|
|
2. Review code comments in implementation files
|
|
3. Test using examples in **SSE_IMPLEMENTATION_GUIDE.md**
|
|
|
|
---
|
|
|
|
**Last Updated:** 2025-01-21
|
|
**Version:** 1.0
|
|
**Status:** Complete and Ready for Implementation
|