Stream child agent events into view SSE without jumpy drip.

Forward quiet file-subtask EventBus frames while wait blocks, coalesce
DOM updates per rAF, and keep one SSE write per event so Stream stays
live during child work instead of freezing or dumping bursts.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
cflmyandCursor committed 2026-08-11 09:45:08 +08:00
1 parent ff84c43c10
commit f240bdf156
10 files changed
+323 -55

No files matched your search

+27 -5
View File
@@ -1,7 +1,11 @@
//! Process-wide stream event bus for `marqdo view` SSE (S3).
//! Publishers: LLM SSE parse, optional `host_stream_publish`.
//! Subscribers: view `GET /api/events`.
//! Subscribers: view `GET /api/events` / `POST /api/run`.
//!
//! File subtasks set `MARQDO_EVENT_FORWARD=<ndjson path>`; the child appends each
//! published event so the parent can fan them onto its own bus while `wait` blocks.
use std::io::Write;
use std::sync::mpsc::{self, Receiver, Sender};
use std::sync::{Mutex, OnceLock};
@@ -35,10 +39,11 @@ impl EventBus {
}
pub fn publish_json(&self, json_line: &str) {
let Ok(mut g) = self.subs.lock() else {
return;
};
g.retain(|tx| tx.send(json_line.to_string()).is_ok());
if let Ok(mut g) = self.subs.lock() {
g.retain(|tx| tx.send(json_line.to_string()).is_ok());
}
// Child → parent bridge (no-op unless spawn set the env).
forward_to_parent_file(json_line);
}
pub fn publish_value(&self, v: &Value) {
@@ -48,6 +53,23 @@ impl EventBus {
}
}
fn forward_to_parent_file(json_line: &str) {
let Ok(path) = std::env::var("MARQDO_EVENT_FORWARD") else {
return;
};
if path.is_empty() {
return;
}
if let Ok(mut f) = std::fs::OpenOptions::new()
.create(true)
.append(true)
.open(&path)
{
let _ = writeln!(f, "{json_line}");
let _ = f.flush();
}
}
/// Publish a Marqdo map (or any value) onto the global bus.
pub fn publish(v: &Value) {
EventBus::global().publish_value(v);