Fully Automated - 100% Backpressure - Pipeline runner 🏃 for AI workflows. 🚀

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

  1. 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
  2. Server-Sent Events (SSE) Endpoint

    • Created /api/stream/{session_id} endpoint in new server/stream.rs module
    • 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
  3. Streaming PRD/Spec Generation

    • Upgraded from --output-format json to stream-json with --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)
  4. 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
  5. Updated Navigation Flow

    • ChatInput navigates with session_id instead of encoded content
    • EditorPage checks session_id first, falls back to query params
    • Dual-mode support for backward compatibility

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

  1. UUID v4 for session IDs (no coordination needed)
  2. SSE over WebSockets (simpler for one-way streaming)
  3. In-memory broadcast channels (sufficient for Phase 3 scope)
  4. Markdown header splitting (reliable, explicit PRD/Spec separation)
  5. 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

@@ -240,6 +240,9 @@
240240 dependencies = [
241241 "axum",
242242 "console_error_panic_hook",
243+ "futures",
244+ "gloo-net",
245+ "lazy_static",
243246 "leptos",
244247 "leptos_axum",
245248 "leptos_config",
@@ -248,11 +251,13 @@
248251 "serde",
249252 "serde_json",
250253 "tokio",
254+ "tokio-stream",
251255 "tower",
252256 "tower-http",
253257 "tracing",
254258 "tracing-subscriber",
255259 "urlencoding",
260+ "uuid",
256261 "wasm-bindgen",
257262 ]
258263
@@ -2660,6 +2665,7 @@
26602665 "futures-core",
26612666 "pin-project-lite",
26622667 "tokio",
2668+ "tokio-util",
26632669 ]
26642670
26652671 [[package]]
@@ -2924,6 +2930,7 @@
29242930 dependencies = [
29252931 "getrandom 0.3.4",
29262932 "js-sys",
2933+ "serde_core",
29272934 "wasm-bindgen",
29282935 ]
29292936