Skip to content

Commit 85d6bf8

Browse files
feat(agents): Harnesses Goose install (slice 3/5) (#279)
Signed-off-by: Salman Mohammed <[email protected]> Signed-off-by: klopez4212 <[email protected]> Co-authored-by: klopez4212 <[email protected]>
1 parent 59d9d6f commit 85d6bf8

14 files changed

Lines changed: 1190 additions & 15 deletions

File tree

‎src-tauri/build.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ fn main() {
3737
"agent_control_snapshot",
3838
"agent_control_log_challenge",
3939
"agent_control_read_log",
40+
"goose_install",
4041
"agent_control_save",
4142
"agent_control_start_on_app_launch",
4243
"agent_control_delete",

‎src-tauri/capabilities/default.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
"allow-agent-control-snapshot",
2525
"allow-agent-control-log-challenge",
2626
"allow-agent-control-read-log",
27+
"allow-goose-install",
2728
"allow-agent-control-save",
2829
"allow-agent-control-start-on-app-launch",
2930
"allow-agent-control-delete",

‎src-tauri/src/agents.rs‎

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use std::sync::{Arc, Mutex};
1313
#[serde(rename_all = "camelCase")]
1414
pub(crate) struct Snapshot {
1515
#[serde(flatten)]
16-
data: ControlSnapshot,
16+
pub(crate) data: ControlSnapshot,
1717
import_available: bool,
1818
create_available: bool,
1919
avatar_editing_available: bool,
@@ -45,6 +45,8 @@ struct HarnessOption {
4545
label: &'static str,
4646
available: bool,
4747
status: &'static str,
48+
#[serde(skip_serializing_if = "Option::is_none")]
49+
install_supported: Option<bool>,
4850
default_args: &'static [&'static str],
4951
providers: &'static [ProviderOption],
5052
}
@@ -138,6 +140,7 @@ fn harness_options() -> Vec<HarnessOption> {
138140
label: "Buzz Agent",
139141
available: true,
140142
status: "ready",
143+
install_supported: None,
141144
default_args: &[],
142145
providers: &[ProviderOption {
143146
value: "databricks_v2",
@@ -156,6 +159,7 @@ fn harness_options() -> Vec<HarnessOption> {
156159
} else {
157160
"cli-needed"
158161
},
162+
install_supported: Some(cfg!(any(target_os = "macos", target_os = "linux"))),
159163
default_args: &["acp"],
160164
providers: GOOSE_PROVIDERS,
161165
},
@@ -167,6 +171,7 @@ fn harness_options() -> Vec<HarnessOption> {
167171
label: "Pi",
168172
available: pi_status == "ready",
169173
status: pi_status,
174+
install_supported: None,
170175
default_args: &[],
171176
providers: &[
172177
ProviderOption {
@@ -403,12 +408,25 @@ impl AgentHost {
403408
.with(|host| host.controller.launch_ids())
404409
.unwrap_or_default();
405410
for id in ids {
406-
let _ = start(self.clone(), id, Action::Start, true, None).await;
411+
let _ = start(self.clone(), id, Action::Start, true, None, false).await;
407412
}
408413
}
409414
pub(crate) fn ensure_open(&self) -> Result<(), String> {
410415
self.with(|_| Ok(()))
411416
}
417+
#[cfg(any(target_os = "macos", target_os = "linux", test))]
418+
pub(crate) fn waiting_for_goose(&self) -> Result<Vec<String>, String> {
419+
self.with(|host| {
420+
Ok(host
421+
.controller
422+
.snapshot()?
423+
.agents
424+
.iter()
425+
.filter(|agent| crate::harness_setup::waiting_for_goose(agent))
426+
.map(|agent| agent.id.clone())
427+
.collect())
428+
})
429+
}
412430
pub(crate) fn disconnect(&self, workspace: &str) -> Result<(), String> {
413431
let workspace = buzz_agent_controller::connection::origin(workspace)?;
414432
self.with(|host| {
@@ -557,19 +575,33 @@ pub(crate) async fn agent_control_action(
557575
if matches!(action, Action::Stop) {
558576
return run(owner, move |host| host.action(&id, action)).await;
559577
}
560-
start(owner, id, action, false, replay_floor).await
578+
start(owner, id, action, false, replay_floor, false).await
561579
}
562-
async fn start(
580+
pub(crate) const NOT_WAITING_FOR_GOOSE: &str = "Agent no longer waiting for Goose";
581+
pub(crate) async fn start(
563582
owner: AgentHost,
564583
id: String,
565584
action: Action,
566585
restore: bool,
567586
replay_floor: Option<u64>,
587+
from_goose_install: bool,
568588
) -> Result<Snapshot, String> {
569589
let prepared = owner.with(|host| {
570590
if restore && (host.acted.contains(&id) || !host.controller.launch_ids()?.contains(&id)) {
571591
return Err("Agent disabled before restore".into());
572592
}
593+
// Re-check while holding the controller, not just at install start:
594+
// Stop or Edit may have changed this agent while the download ran.
595+
if from_goose_install
596+
&& !host
597+
.controller
598+
.snapshot()?
599+
.agents
600+
.iter()
601+
.any(|agent| agent.id == id && crate::harness_setup::waiting_for_goose(agent))
602+
{
603+
return Err(NOT_WAITING_FOR_GOOSE.into());
604+
}
573605
host.starts.remove(&id);
574606
if !restore {
575607
host.acted.insert(id.clone());

‎src-tauri/src/agents/tests.rs‎

Lines changed: 86 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ pub(crate) fn fixture_with_models(
6565
)));
6666
let app = mock_builder()
6767
.manage(host.clone())
68+
.manage(crate::harness_setup::HarnessSetup::default())
6869
.manage(model_host)
6970
.invoke_handler(crate::commands())
7071
.build(crate::app_context())
@@ -164,6 +165,10 @@ fn real_ipc_snapshot_save_cas_stop_and_launch_gate() {
164165
)
165166
);
166167
assert_eq!(before["harnessOptions"][1]["label"], "Goose");
168+
assert_eq!(
169+
before["harnessOptions"][1]["installSupported"],
170+
cfg!(any(target_os = "macos", target_os = "linux"))
171+
);
167172
assert_eq!(before["harnessOptions"][1]["defaultArgs"], json!(["acp"]));
168173
assert_eq!(
169174
before["harnessOptions"][1]["status"],
@@ -333,7 +338,7 @@ fn queued_restore_skips_agent_stopped_after_launch() {
333338
.unwrap();
334339
assert_eq!(stopped["agents"][0]["startOnAppLaunch"], true);
335340
let restored =
336-
tauri::async_runtime::block_on(start(host.clone(), id, Action::Start, true, None));
341+
tauri::async_runtime::block_on(start(host.clone(), id, Action::Start, true, None, false));
337342
assert_eq!(
338343
restored.err().as_deref(),
339344
Some("Agent disabled before restore")
@@ -570,6 +575,85 @@ mod overlap {
570575
}
571576
fresh.shutdown().unwrap();
572577
}
578+
579+
// A genuinely eligible agent: its Start failed on the missing Goose CLI.
580+
// Stop during the download must win over the install's late restart.
581+
#[test]
582+
fn goose_install_restart_does_not_reenable_an_agent_stopped_during_download() {
583+
const KEY: &str = "0000000000000000000000000000000000000000000000000000000000000001";
584+
const PUB: &str = "79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798";
585+
struct Stored;
586+
impl Credentials for Stored {
587+
fn delete(&self, _: &str, _: &str) -> Result<(), String> {
588+
panic!("not a deletion")
589+
}
590+
fn read_legacy(&self, _: LegacySource, _: &str) -> Result<Secret, String> {
591+
panic!("not an import")
592+
}
593+
fn add(&self, _: &str, _: &Secret) -> Result<(), String> {
594+
panic!("not a write")
595+
}
596+
fn read(&self, _: &str, pubkey: &str) -> Result<Option<Secret>, String> {
597+
Secret::parse(KEY, pubkey).map(Some)
598+
}
599+
}
600+
let (dir, host, _app, view) = fixture();
601+
let id = seed(dir.path());
602+
let path = dir.path().join("store/agents.json");
603+
let mut saved: Value = serde_json::from_slice(&std::fs::read(&path).unwrap()).unwrap();
604+
let id = id.replacen(&"ab".repeat(32), PUB, 1);
605+
saved["agents"][0]["id"] = json!(id);
606+
saved["agents"][0]["pubkey"] = json!(PUB);
607+
saved["agents"][0]["credentialId"] = json!(id);
608+
saved["agents"][0]["harness"]["command"] = json!(dir.path().join("missing/goose"));
609+
saved["agents"][0]["harness"]["args"] = json!(["acp"]);
610+
std::fs::write(&path, serde_json::to_vec(&saved).unwrap()).unwrap();
611+
let credentials: Arc<dyn Credentials> = Arc::new(Stored);
612+
host.with(|h| {
613+
h.controller = Controller::new(
614+
Store::open(dir.path().join("replacement"))?,
615+
credentials.clone(),
616+
Err("placeholder".into()),
617+
dir.path().join("ownership"),
618+
);
619+
h.controller = Controller::new(
620+
Store::open(dir.path().join("store"))?,
621+
credentials.clone(),
622+
Ok(synthetic_bundle(&dir.path().join("tools"))),
623+
dir.path().join("ownership"),
624+
);
625+
h.credentials = credentials;
626+
h.legacy_check = || Ok(());
627+
Ok(())
628+
})
629+
.unwrap();
630+
let started = tauri::async_runtime::block_on(start(
631+
host.clone(),
632+
id.clone(),
633+
Action::Start,
634+
false,
635+
None,
636+
false,
637+
))
638+
.unwrap();
639+
assert_eq!(
640+
started.data.agents[0].error.as_deref(),
641+
Some("Required runtime executable is missing")
642+
);
643+
assert_eq!(host.waiting_for_goose().unwrap(), vec![id.clone()]);
644+
invoke(
645+
&view,
646+
"agent_control_action",
647+
json!({"id":id,"action":"stop"}),
648+
)
649+
.unwrap();
650+
assert!(host.waiting_for_goose().unwrap().is_empty());
651+
let result =
652+
tauri::async_runtime::block_on(start(host, id, Action::Restart, false, None, true));
653+
assert_eq!(result.err().as_deref(), Some(NOT_WAITING_FOR_GOOSE));
654+
let saved: Value = serde_json::from_slice(&std::fs::read(path).unwrap()).unwrap();
655+
assert_eq!(saved["agents"][0]["enabled"], false);
656+
}
573657
}
574658

575659
#[cfg(unix)]
@@ -782,7 +866,7 @@ async fn native_start_restore_disconnect_stop_and_quit_fence_late_credentials()
782866
owner.restore().await;
783867
Err("restore completed".into())
784868
} else {
785-
start(owner, agent_id, Action::Start, false, None).await
869+
start(owner, agent_id, Action::Start, false, None, false).await
786870
}
787871
});
788872
tokio::task::spawn_blocking({

‎src-tauri/src/browser_permissions_tests.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ fn native_command_permissions_allow_only_main_webview() {
8181
"agent_control_snapshot",
8282
"agent_control_log_challenge",
8383
"agent_control_read_log",
84+
"goose_install",
8485
"agent_control_save",
8586
"agent_control_start_on_app_launch",
8687
"agent_control_delete",

0 commit comments

Comments
 (0)