Skip to content

Craft Anything: understand how any software works, and craft your own.

Rust

Offer a switched-off agent in the setup card, and turn it on (#784)

Fábio Soares0e4a1cfb9893
diff --git a/crates/ai/src/lib.rs b/crates/ai/src/lib.rs
index d4a6b231..7342f500 100644
--- a/crates/ai/src/lib.rs
+++ b/crates/ai/src/lib.rs
@@ -194,6 +194,17 @@ pub fn default_builder<'a>(backends: &'a [BackendConfig], chosen: Option<&str>)
.or_else(|| on().find(|b| b.kind != BackendKind::AgentCli))
}
+/// Whether `name` is a saved AI that is switched on. One saved but switched off is not set up:
+/// it's offered again when found, so it can be turned on (#423).
+pub fn is_on(backends: &[BackendConfig], name: &str) -> bool {
+ backends.iter().any(|b| b.enabled && b.name == name)
+}
+
+/// The found AIs that aren't already set up and on.
+pub fn leave_out_set_up(found: Vec<Detected>, backends: &[BackendConfig]) -> Vec<Detected> {
+ found.into_iter().filter(|d| !is_on(backends, &d.suggestion.name)).collect()
+}
+
/// What a backend does in a crew.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
@@ -408,8 +419,7 @@ impl AiHub {
/// Look for keys, local servers and agent CLIs (runs quickly; network probes are bounded).
/// Things already configured (by name) are left out.
pub fn detect(&self) -> Vec<Detected> {
- let have: Vec<String> = self.backends().into_iter().map(|b| b.name).collect();
- detect::detect_all().into_iter().filter(|d| !have.contains(&d.suggestion.name)).collect()
+ leave_out_set_up(detect::detect_all(), &self.backends())
}
/// Host aliases from `~/.ssh/config`, for the "run on another machine" picker.
diff --git a/crates/ai/src/tests.rs b/crates/ai/src/tests.rs
index 466e7e1e..d79ef1ed 100644
--- a/crates/ai/src/tests.rs
+++ b/crates/ai/src/tests.rs
@@ -304,6 +304,22 @@ fn an_agent_apps_program_is_set_and_cleared() {
assert_eq!(program(&h), None, "blank finds it by its usual name again");
}
+/// #423: a saved AI that is switched off isn't set up, so a copy found on the computer is offered
+/// again (to be turned on); one that is on is left out.
+#[test]
+fn a_switched_off_agent_is_found_again() {
+ let (h, _d) = hub();
+ add(&h, "Claude Code", BackendKind::AgentCli, "http://127.0.0.1:9", None);
+ let saved = h.backends().into_iter().next().unwrap();
+ let found = |name: &str| Detected { suggestion: BackendConfig { name: name.into(), ..saved.clone() }, reason: "Found".into(), needs_key: false };
+ let offered =
+ |h: &AiHub| leave_out_set_up(vec![found("Claude Code"), found("Codex")], &h.backends()).into_iter().map(|d| d.suggestion.name).collect::<Vec<_>>();
+ assert_eq!(offered(&h), ["Codex"], "on: Claude Code is set up, so it isn't offered");
+ h.set_enabled("Claude Code", false).unwrap();
+ assert_eq!(offered(&h), ["Claude Code", "Codex"], "off: it's found again, to be turned on");
+ assert!(!is_on(&h.backends(), "Claude Code") && !is_on(&h.backends(), "Codex"));
+}
+
/// Claude Code's folder (`CLAUDE_CONFIG_DIR`) is chosen per AI, so two can be two accounts; only
/// a full path, and only for an agent app that keeps one.
#[test]
diff --git a/crates/ui-egui/src/builders.rs b/crates/ui-egui/src/builders.rs
index ce322253..1b51f73a 100644
--- a/crates/ui-egui/src/builders.rs
+++ b/crates/ui-egui/src/builders.rs
@@ -113,7 +113,7 @@ impl CraftApp {
.flatten()
.filter(|d| d.suggestion.kind == BackendKind::AgentCli && !d.needs_key)
.map(|d| &d.suggestion)
- .filter(|s| !self.backends.iter().any(|b| b.name == s.name))
+ .filter(|s| !craft_anything_ai::is_on(&self.backends, &s.name))
}
/// Every AI that can build: the ones set up and on, then agent apps found here.
@@ -140,9 +140,16 @@ impl CraftApp {
let choices = self.builder_choices();
let name = wanted.filter(|w| choices.iter().any(|c| c.name == *w)).map(str::to_string).or_else(|| self.default_builder())?;
let Some(found) = self.found_agents().find(|b| b.name == name).cloned() else { return Some(name) };
- match self.hub.add_backend(found.clone(), None) {
+ // Saved but switched off (#423): turn it on, keeping its program and folder, rather than
+ // saving a second copy over it.
+ let saved = self.backends.iter().any(|b| b.name == found.name);
+ let done = if saved { self.hub.set_enabled(&found.name, true).map(|_| ()) } else { self.hub.add_backend(found.clone(), None) };
+ match done {
Ok(()) => {
- self.backends.push(found);
+ match self.backends.iter_mut().find(|b| b.name == found.name) {
+ Some(b) => b.enabled = true,
+ None => self.backends.push(found),
+ }
Some(name)
}
Err(e) => {
diff --git a/docs/ROADMAP.md b/docs/ROADMAP.md
index 5937ef01..2fe3cde2 100644
--- a/docs/ROADMAP.md
+++ b/docs/ROADMAP.md
@@ -565,6 +565,12 @@ Owner: open · Status: in progress
- [ ] #105, #135, #259, #385 and #423 predate 0.3.0, which looks in more places, and came through
the ticket relay, so nobody can ask them for `doctor` output. Close them pointing at 0.3.0,
and add search paths only for a new report that has that output
+- [x] #423: an agent that is set up but switched off is never offered again, so "No coding agent was
+ found" stays on screen with Claude installed: the setup card and "Look again" leave out every saved
+ AI by name, on or off. Offer a switched-off agent as found and turn it on, keeping its options.
+ Cause is not confirmed on the reporter's machine (needs their config.toml); the fix covers the
+ switched-off case that the code leaves out (`is_on`, `leave_out_set_up`, `builder_backend`). — claimed: fabox-os,
+ branch bugfix/423-disabled-agent-not-offered
- [ ] Say plainly when what's found is the Claude desktop app rather than the `claude` program
(#259, a guess at its cause)
- [ ] macOS: `/Applications/Antigravity.app` ended up as the agent's command (#467); find what