Make Open Agent update non-destructive and use HOME cargo
This commit is contained in:
@@ -616,6 +616,42 @@ fn stream_open_agent_update() -> impl Stream<Item = Result<Event, std::convert::
|
|||||||
progress: Some(5),
|
progress: Some(5),
|
||||||
}).unwrap()));
|
}).unwrap()));
|
||||||
|
|
||||||
|
let status_result = Command::new("git")
|
||||||
|
.args(["status", "--porcelain"])
|
||||||
|
.current_dir(OPEN_AGENT_REPO_PATH)
|
||||||
|
.output()
|
||||||
|
.await;
|
||||||
|
|
||||||
|
match status_result {
|
||||||
|
Ok(output) if output.status.success() => {
|
||||||
|
if !output.stdout.is_empty() {
|
||||||
|
yield Ok(Event::default().data(serde_json::to_string(&UpdateProgressEvent {
|
||||||
|
event_type: "error".to_string(),
|
||||||
|
message: "Update aborted: repository has local changes. Commit or stash your tweaks first to avoid losing them.".to_string(),
|
||||||
|
progress: None,
|
||||||
|
}).unwrap()));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Ok(output) => {
|
||||||
|
let stderr = String::from_utf8_lossy(&output.stderr);
|
||||||
|
yield Ok(Event::default().data(serde_json::to_string(&UpdateProgressEvent {
|
||||||
|
event_type: "error".to_string(),
|
||||||
|
message: format!("Failed to check repo status: {}", stderr),
|
||||||
|
progress: None,
|
||||||
|
}).unwrap()));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Err(e) => {
|
||||||
|
yield Ok(Event::default().data(serde_json::to_string(&UpdateProgressEvent {
|
||||||
|
event_type: "error".to_string(),
|
||||||
|
message: format!("Failed to run git status: {}", e),
|
||||||
|
progress: None,
|
||||||
|
}).unwrap()));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let fetch_result = Command::new("git")
|
let fetch_result = Command::new("git")
|
||||||
.args(["fetch", "--tags", "origin"])
|
.args(["fetch", "--tags", "origin"])
|
||||||
.current_dir(OPEN_AGENT_REPO_PATH)
|
.current_dir(OPEN_AGENT_REPO_PATH)
|
||||||
@@ -677,20 +713,6 @@ fn stream_open_agent_update() -> impl Stream<Item = Result<Event, std::convert::
|
|||||||
progress: Some(15),
|
progress: Some(15),
|
||||||
}).unwrap()));
|
}).unwrap()));
|
||||||
|
|
||||||
// Reset any local changes before checkout to prevent conflicts
|
|
||||||
let _ = Command::new("git")
|
|
||||||
.args(["reset", "--hard", "HEAD"])
|
|
||||||
.current_dir(OPEN_AGENT_REPO_PATH)
|
|
||||||
.output()
|
|
||||||
.await;
|
|
||||||
|
|
||||||
// Clean untracked files that might interfere
|
|
||||||
let _ = Command::new("git")
|
|
||||||
.args(["clean", "-fd"])
|
|
||||||
.current_dir(OPEN_AGENT_REPO_PATH)
|
|
||||||
.output()
|
|
||||||
.await;
|
|
||||||
|
|
||||||
// Checkout the tag/branch
|
// Checkout the tag/branch
|
||||||
let checkout_result = Command::new("git")
|
let checkout_result = Command::new("git")
|
||||||
.args(["checkout", &latest_tag])
|
.args(["checkout", &latest_tag])
|
||||||
@@ -747,8 +769,18 @@ fn stream_open_agent_update() -> impl Stream<Item = Result<Event, std::convert::
|
|||||||
}).unwrap()));
|
}).unwrap()));
|
||||||
|
|
||||||
// Source cargo env and build
|
// Source cargo env and build
|
||||||
|
let home = std::env::var("HOME").unwrap_or_else(|_| "/root".to_string());
|
||||||
|
let cargo_env = PathBuf::from(&home).join(".cargo/env");
|
||||||
|
let build_cmd = if cargo_env.exists() {
|
||||||
|
format!(
|
||||||
|
"source {} && cargo build --bin open_agent --bin workspace-mcp --bin desktop-mcp",
|
||||||
|
cargo_env.display()
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
"cargo build --bin open_agent --bin workspace-mcp --bin desktop-mcp".to_string()
|
||||||
|
};
|
||||||
let build_result = Command::new("bash")
|
let build_result = Command::new("bash")
|
||||||
.args(["-c", "source /root/.cargo/env && cargo build --bin open_agent --bin workspace-mcp --bin desktop-mcp"])
|
.args(["-c", &build_cmd])
|
||||||
.current_dir(OPEN_AGENT_REPO_PATH)
|
.current_dir(OPEN_AGENT_REPO_PATH)
|
||||||
.output()
|
.output()
|
||||||
.await;
|
.await;
|
||||||
|
|||||||
Reference in New Issue
Block a user