Commit 2af2e4f0
2af2e4f05cb5Merged
Scott Nixon <[email protected]> · 9 months ago · 9 files · +1 added · ~8 modified
Description
Implement Phase 3: Streaming infrastructure for Claude CLI and SSE (attractor-n57)
This commit implements real-time streaming infrastructure for the Attractor web interface, enabling live typing effects during PRD/Spec generation and setting the foundation for Phase 4 pipeline execution with progress streaming.
Core Features
-
PipelineCheckpoint Updates
- Added
session_id: Option<String>field for tracking execution sessions - Backward compatible with existing checkpoints using serde skip_serializing_if
- Added constructor
with_session_id()for creating new checkpoints - All 6 tests passing including 2 new backward compatibility tests
- Added
-
Server-Sent Events (SSE) Endpoint
- Created
/api/stream/{session_id}endpoint in newserver/stream.rsmodule - In-memory broadcast channels using lazy_static for event distribution
- Keep-alive and auto-reconnection support
- Session cleanup for inactive sessions
- Registered in main.rs router
- Created
-
Streaming PRD/Spec Generation
- Upgraded from
--output-format jsontostream-jsonwith--session-id - UUID v4 session ID generation for tracking
- Line-by-line NDJSON parsing from claude CLI stdout
- Real-time event publishing to SSE broadcast channels
- Smart PRD/Spec splitting via markdown headers (## PRD / ## Spec)
- Upgraded from
-
Live Typing Effect in EditorPage
- SSE client using gloo-net EventSource with auto-reconnection
- Real-time text accumulation in reactive signals
- "🔴 Live streaming..." indicator during generation
- Backward compatible with Phase 2 URL query params
- Proper cleanup on component unmount
-
Updated Navigation Flow
- ChatInput navigates with
session_idinstead of encoded content - EditorPage checks session_id first, falls back to query params
- Dual-mode support for backward compatibility
- ChatInput navigates with
Files Changed
Created:
- crates/attractor-web/src/server/stream.rs (~90 lines)
Modified:
- crates/attractor-pipeline/src/checkpoint.rs (+13 lines)
- crates/attractor-web/Cargo.toml (+9 dependencies)
- crates/attractor-web/src/server/generate.rs (+88/-14 lines)
- crates/attractor-web/src/server/mod.rs (+5 lines)
- crates/attractor-web/src/main.rs (+4 lines)
- crates/attractor-web/src/pages/editor.rs (+72/-6 lines)
- crates/attractor-web/src/components/chat_input.rs (+6/-10 lines)
- Cargo.lock (dependency updates)
Dependencies Added
SSR (server):
- tokio-stream, futures, lazy_static
Hydrate (client):
- gloo-net (with eventsource feature)
- uuid (with v4, serde, js features)
Test Results
- ✅ All 6 checkpoint tests passing (0.26s)
- ✅ Clippy clean (0 warnings, all features)
- ✅ Workspace compilation successful (all 8 crates)
- ✅ SSR and hydrate features properly gated
- ✅ Type-safe throughout with comprehensive error handling
Technical Decisions
- UUID v4 for session IDs (no coordination needed)
- SSE over WebSockets (simpler for one-way streaming)
- In-memory broadcast channels (sufficient for Phase 3 scope)
- Markdown header splitting (reliable, explicit PRD/Spec separation)
- Dual-mode navigation (backward compatible with Phase 2)
Known Limitations (Phase 3 Scope)
- CodergenHandler modifications deferred to Phase 4 (pipeline execution)
- In-memory state lost on server restart (documented)
- No scheduled session cleanup yet (cleanup_inactive_sessions exists but unused)
Architecture Flow
User enters prompt
↓
Generate PRD button → Server function
↓
claude -p --output-format stream-json --session-id <uuid>
↓
Read NDJSON stream + publish to SSE broadcast
↓
Navigate to /editor?session_id=<uuid>
↓
EditorPage connects to /api/stream/<uuid>
↓
Live typing effect with incremental updates! 🔴
Next Phase
This implementation unblocks attractor-krz (Phase 4) for:
- Full pipeline execution with streaming
- Real-time node visualization
- Persistent session storage
- CodergenHandler modifications
Task: attractor-n57 Phase: 3/4 Status: COMPLETE ✅
Details
- Commit
- 2af2e4f05cb5
- Parent
- 752b3b2d1721
Cargo.lockmodifiedView file
dependencies = [ "axum", "console_error_panic_hook", "futures", "gloo-net", "lazy_static", "leptos", "leptos_axum", "leptos_config", "serde", "serde_json", "tokio", "tokio-stream", "tower", "tower-http", "tracing", "tracing-subscriber", "urlencoding", "uuid", "wasm-bindgen",] "futures-core", "pin-project-lite", "tokio", "tokio-util",][[package]]dependencies = [ "getrandom 0.3.4", "js-sys", "serde_core", "wasm-bindgen",]crates/attractor-pipeline/src/checkpoint.rsmodifiedView file
Loading diff…
crates/attractor-web/Cargo.tomlmodifiedView file
Loading diff…
crates/attractor-web/src/components/chat_input.rsmodifiedView file
Loading diff…
crates/attractor-web/src/main.rsmodifiedView file
Loading diff…
crates/attractor-web/src/pages/editor.rsmodifiedView file
Loading diff…
crates/attractor-web/src/server/generate.rsmodifiedView file
Loading diff…
crates/attractor-web/src/server/mod.rsmodifiedView file
Loading diff…
crates/attractor-web/src/server/stream.rsaddedView file
Loading diff…