Craft Anything: understand how any software works, and craft your own.
Rust
Say which AI builds when a project's saved AI is turned off (#1066)
Alex Joaquim Pereira27985d1d2bbe
diff --git a/crates/ui-egui/src/builders.rs b/crates/ui-egui/src/builders.rsindex 292e7234..5b19b00d 100644--- a/crates/ui-egui/src/builders.rs+++ b/crates/ui-egui/src/builders.rs@@ -105,6 +105,12 @@ fn detail(b: &BackendConfig) -> String {}}+/// The notice when a project's saved AI was turned off or removed. English for now: the wording+/// needs a native speaker's check before it joins the catalogs.+fn replaced_builder_notice(saved: &str, used: &str) -> String {+ format!("The AI chosen for this project ({saved}) is turned off or no longer set up. {used} builds instead.")+}+impl CraftApp {/// Agent apps found on this computer that aren't set up yet (they need no key).fn found_agents(&self) -> impl Iterator<Item = &BackendConfig> {@@ -138,8 +144,17 @@ impl CraftApp {/// only found is set up now (it needs no key, and the person pressed Start).pub fn builder_backend(&mut self, wanted: Option<&str>) -> Option<String> {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) };+ let kept = wanted.filter(|w| choices.iter().any(|c| c.name == *w));+ let name = kept.map(str::to_string).or_else(|| self.default_builder())?;+ // A saved choice that was turned off or removed is replaced. The notice waits until a+ // builder is committed, so a failed setup doesn't claim one will build.+ let replaced = wanted.filter(|w| !w.is_empty() && kept.is_none() && *w != name.as_str());+ let Some(found) = self.found_agents().find(|b| b.name == name).cloned() else {+ if let Some(saved) = replaced {+ self.toast(replaced_builder_notice(saved, &name), false);+ }+ return Some(name);+ };// 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);@@ -150,6 +165,9 @@ impl CraftApp {Some(b) => b.enabled = true,None => self.backends.push(found),}+ if let Some(saved) = replaced {+ self.toast(replaced_builder_notice(saved, &name), false);+ }Some(name)}Err(e) => {@@ -348,9 +366,12 @@ pub fn built_by(app: &mut CraftApp, ui: &mut Ui) {return;};let choices = app.builder_choices();- // A choice that was removed or turned off meanwhile goes back to automatic.- if app.state.make.ai.as_ref().is_some_and(|a| !choices.iter().any(|c| &c.name == a)) {+ // A choice that was removed or turned off meanwhile goes back to automatic, and the toast+ // says which AI builds instead: switching silently would hide the replacement.+ let replaced = app.state.make.ai.clone().filter(|a| !a.is_empty() && !choices.iter().any(|c| &c.name == a));+ if let Some(saved) = &replaced {app.state.make.ai = None;+ app.toast(replaced_builder_notice(saved, &default), false);}let automatic = trf("Automatic ({name})", &[("name", &default)]);let shown = app.state.make.ai.clone().unwrap_or_else(|| automatic.clone());diff --git a/crates/ui-egui/tests/smoke.rs b/crates/ui-egui/tests/smoke.rsindex c9a63e22..da5b4af7 100644--- a/crates/ui-egui/tests/smoke.rs+++ b/crates/ui-egui/tests/smoke.rs@@ -2584,6 +2584,59 @@ fn make_says_who_builds_and_a_picked_builder_stays_with_the_project() {h.run_steps(2);}+#[test]+fn a_turned_off_make_choice_says_who_builds_instead() {+ let mut h = harness(|| {+ let mut a = demo::app(demo::engine(Mode::Beginner, true));+ a.backends.push(BackendConfig {+ name: "Off".into(),+ kind: BackendKind::Anthropic,+ model: "test-model".into(),+ base_url: None,+ ssh_host: None,+ enabled: false,+ });+ a.state.make.ai = Some("Off".into());+ a+ });+ h.run_steps(3);+ // The stale draft goes back to Automatic, and the toast says who builds instead.+ assert!(h.state().state.make.ai.is_none());+ assert_eq!(h.get_all_by_label("Built by").last().unwrap().value().as_deref(), Some("Automatic (Claude)"));+ assert!(h.state().state.toasts.iter().any(|(t, err)| !*err && t.contains("Off") && t.contains("Claude")), "{:?}", h.state().state.toasts);+}++#[test]+fn a_turned_off_or_removed_saved_builder_says_who_builds_instead() {+ let mut h = harness(|| {+ let mut a = demo::app(demo::engine(Mode::Beginner, true));+ a.backends.push(BackendConfig {+ name: "Off".into(),+ kind: BackendKind::Anthropic,+ model: "test-model".into(),+ base_url: None,+ ssh_host: None,+ enabled: false,+ });+ a+ });+ h.run_steps(2);++ // A turned-off saved builder: the default builds, and the person is told which one.+ assert_eq!(h.state_mut().builder_backend(Some("Off")).as_deref(), Some("Claude"));+ assert!(h.state().state.toasts.iter().any(|(t, err)| !*err && t.contains("Off") && t.contains("Claude")), "{:?}", h.state().state.toasts);++ // A removed one too.+ assert_eq!(h.state_mut().builder_backend(Some("Gone")).as_deref(), Some("Claude"));+ assert!(h.state().state.toasts.iter().any(|(t, err)| !*err && t.contains("Gone") && t.contains("Claude")), "{:?}", h.state().state.toasts);++ // An enabled choice, and Automatic, say nothing.+ let quiet = h.state().state.toasts.len();+ assert_eq!(h.state_mut().builder_backend(Some("Claude")).as_deref(), Some("Claude"));+ assert_eq!(h.state_mut().builder_backend(None).as_deref(), Some("Claude"));+ assert_eq!(h.state().state.toasts.len(), quiet, "no replacement notice when nothing was replaced");+}+#[test]fn with_nothing_to_build_with_start_offers_what_was_found_instead_of_a_dead_end() {use craft_anything_ui_egui::state::Modal;diff --git a/docs/ROADMAP.md b/docs/ROADMAP.mdindex 344d7854..2657164b 100644--- a/docs/ROADMAP.md+++ b/docs/ROADMAP.md@@ -433,9 +433,16 @@ Owner: open · Status: todoturned-off backend is named and must be turned on, and a name that matches nothing is namedinstead of saying to install an agent or add a key— claimed: AlexJoaquimPereira, branch `bugfix/r5.5-disabled-backend-name`; commit a380b3e-- [ ] When a project's saved builder was turned off, Start builds with the default AI without+- [x] When a project's saved builder was turned off, Start builds with the default AI withoutsaying so: the UI picker filters the stale name out (`ui-egui/src/builders.rs`) instead of- reporting that the chosen AI was replaced+ reporting that the chosen AI was replaced. The Make picker says so in a toast, and every+ start (Start, Continue, a note, Try again) names the saved AI and the one building instead+ — claimed: AlexJoaquimPereira, branch `bugfix/r5.5-stale-builder-notice`+- [ ] `rebuild --continue-in`, `rebuild_start` on a project and `rebuild_question_ask` still use+ the default AI when the saved builder is off or gone, and say nothing: report the replacement+ there too+- [ ] The saved-builder replacement notice is English only for now; add it to the catalogs after a+ native speaker checks the wording- [x] Bound accumulated data across all lines of one server-sent event, so short lines cannotgrow a streamed API response without limit— claimed: Afloat16, branch bugfix/r5.5-bounded-sse-events-20261103