From 76b964998bd14f449356c54a9756d3c9b4c31f6e Mon Sep 17 00:00:00 2001 From: Fam Zheng Date: Mon, 6 Apr 2026 20:24:37 +0100 Subject: [PATCH] feat: real-time file sync on write_file (upload immediately, not just at end) --- src/agent.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/agent.rs b/src/agent.rs index aa3481d..00f93bf 100644 --- a/src/agent.rs +++ b/src/agent.rs @@ -893,6 +893,22 @@ pub async fn run_step_loop( let result = execute_tool(&tc.function.name, &tc.function.arguments, workdir, exec).await; let status = if result.starts_with("Error:") { "failed" } else { "done" }; send_execution(update_tx, workflow_id, step_order, &tc.function.name, &tc.function.arguments, &result, status).await; + + // Real-time file sync: upload written file to server immediately + if tc.function.name == "write_file" && status == "done" { + if let Some(rel_path) = args.get("path").and_then(|v| v.as_str()) { + let full = std::path::Path::new(workdir).join(rel_path); + if let Ok(bytes) = tokio::fs::read(&full).await { + use base64::Engine; + let _ = update_tx.send(AgentUpdate::FileSync { + project_id: project_id.to_string(), + path: rel_path.to_string(), + data_b64: base64::engine::general_purpose::STANDARD.encode(&bytes), + }).await; + } + } + } + step_chat_history.push(ChatMessage::tool_result(&tc.id, &result)); } }