feat(daemon): grid feed + output coalescing + snapshot-on-attach (M1)

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-06-09 20:12:55 +07:00
parent b201d0104e
commit 732eef96b5
2 changed files with 100 additions and 15 deletions
+17 -5
View File
@@ -183,7 +183,7 @@ async fn handle_request(
};
match PtyHandle::spawn(spec) {
Ok(pty) => {
let handle = spawn_surface(sid.clone(), workspace_id.clone(), pty, exit_tx.clone());
let handle = spawn_surface(sid.clone(), workspace_id.clone(), pty, cols, rows, exit_tx.clone());
// Bridge the surface's broadcast into the router as Output messages.
spawn_output_bridge(sid.clone(), &handle, router_tx.clone());
reg.insert_surface(handle);
@@ -219,10 +219,22 @@ async fn handle_request(
}
}
Cmd::Attach { surface_id } => {
// M0 attach: register subscription, no snapshot yet (snapshot added in Task 13).
if reg.surface(&surface_id).is_some() {
subs.entry(surface_id.clone()).or_default().push(client);
let _ = out.send(ok(id, serde_json::json!({ "snapshot": "", "cols": 0, "rows": 0 }))).await;
if let Some(s) = reg.surface(&surface_id) {
let (reply_tx, reply_rx) = oneshot::channel();
if s.tx.send(SurfaceMsg::AttachSnapshot { reply: reply_tx }).await.is_ok() {
if let Ok((snap, _sub)) = reply_rx.await {
subs.entry(surface_id.clone()).or_default().push(client);
let _ = out.send(ok(id, serde_json::json!({
"snapshot": snap.ansi,
"cols": snap.cols,
"rows": snap.rows,
"cursor_row": snap.cursor_row,
"cursor_col": snap.cursor_col,
}))).await;
return;
}
}
let _ = out.send(err(id, "INTERNAL", "attach failed")).await;
} else {
let _ = out.send(err(id, "NOT_FOUND", "surface")).await;
}