Skip to content

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

Rust

Report a replaced saved builder in the CLI, MCP and Just ask (#1073)

Alex Joaquim Pereiraa6e868bfab45
diff --git a/apps/craft-anything-cli/src/rebuild_cmd.rs b/apps/craft-anything-cli/src/rebuild_cmd.rs
index d2b495fc..c509e6fc 100644
--- a/apps/craft-anything-cli/src/rebuild_cmd.rs
+++ b/apps/craft-anything-cli/src/rebuild_cmd.rs
@@ -130,6 +130,9 @@ fn run(cli: &Cli, a: &RebuildArgs) -> Result<bool, ToolError> {
}
};
println!("Project: {}", ws.root.display());
+ // The saved builder may be off or gone; say who builds once the run has started, so a failed
+ // start doesn't claim an AI that never ran.
+ let replacement = rebuild::builder_replacement(&hub.config(), &ws, a.backend.as_deref());
// A follow-up shows in the project's feed as the person typed it.
let shown = message.clone();
let good_enough = engine.session().settings.build.good_enough;
@@ -144,6 +147,9 @@ fn run(cli: &Cli, a: &RebuildArgs) -> Result<bool, ToolError> {
..RunOptions::default()
};
let mut run = RebuildRun::start(&hub, ws, opts)?;
+ if let Some(replacement) = replacement {
+ eprintln!("{}", rebuild::replaced_builder_notice(&replacement.saved, &replacement.used));
+ }
let mut ok = false;
let mut line_open = false;
loop {
diff --git a/apps/craft-anything-cli/tests/rebuild_choice.rs b/apps/craft-anything-cli/tests/rebuild_choice.rs
index 644a0637..a194262b 100644
--- a/apps/craft-anything-cli/tests/rebuild_choice.rs
+++ b/apps/craft-anything-cli/tests/rebuild_choice.rs
@@ -35,6 +35,19 @@ fn fake_claude(bin: &Path) -> PathBuf {
program
}
+/// A stand-in builder that answers one turn and exits, so a run that really starts finishes.
+fn fake_builder(bin: &Path) -> PathBuf {
+ use std::os::unix::fs::PermissionsExt;
+ let program = bin.join("claude");
+ std::fs::write(
+ &program,
+ "#!/bin/sh\nif [ \"$1\" = \"--version\" ]; then echo 'fake-claude 1.0'; exit 0; fi\nif [ \"$1\" = \"--help\" ]; then echo '--output-format stream-json'; exit 0; fi\ncat >/dev/null\nprintf '%s\\n' '{\"type\":\"system\",\"subtype\":\"init\",\"session_id\":\"fake\"}'\nprintf '%s\\n' '{\"type\":\"assistant\",\"message\":{\"content\":[{\"type\":\"text\",\"text\":\"Built it.\"}]}}'\nprintf '%s\\n' '{\"type\":\"result\",\"subtype\":\"success\",\"is_error\":false,\"num_turns\":1}'\n",
+ )
+ .unwrap();
+ std::fs::set_permissions(&program, std::fs::Permissions::from_mode(0o700)).unwrap();
+ program
+}
+
fn api_config(config: &Path) {
std::fs::write(
config.join("config.toml"),
@@ -236,3 +249,33 @@ fn a_computer_with_no_ai_still_finds_an_agent() {
let saved = std::fs::read_to_string(config.path().join("config.toml")).unwrap();
assert!(saved.contains("agent_cli"), "the found agent must still be saved:\n{saved}");
}
+
+/// A project whose saved builder was switched off: once the run starts, it names the saved AI
+/// and the one building instead.
+#[test]
+fn a_replaced_saved_builder_is_named_once_the_run_starts() {
+ use craft_anything_engine::workspace::{TargetRef, Workspace};
+ let config = tempfile::tempdir().unwrap();
+ let home = tempfile::tempdir().unwrap();
+ let bin = tempfile::tempdir().unwrap();
+ let parent = tempfile::tempdir().unwrap();
+ let script = fake_builder(bin.path());
+ std::fs::write(
+ config.path().join("config.toml"),
+ format!(
+ "[[ai.backends]]\nname = \"Off\"\nkind = \"anthropic\"\nmodel = \"claude-test\"\nenabled = false\n\n[[ai.backends]]\nname = \"Claude\"\nkind = \"agent_cli\"\nmodel = \"claude-code\"\ncommand = \"{}\"\nenabled = true\n",
+ script.display()
+ ),
+ )
+ .unwrap();
+ let mut ws = Workspace::create(parent.path(), "Notes", "A notes app", TargetRef::None).unwrap();
+ ws.set_person(|m| m.builder = Some("Off".into())).unwrap();
+
+ let args = stopped_run(&ws.root, None);
+ let refs: Vec<&str> = args.iter().map(String::as_str).collect();
+ let out = cli(&refs, config.path(), home.path(), bin.path());
+ let log = out.stderr_text();
+ assert!(!out.success, "the run must stop at the empty app:\n{log}");
+ assert!(log.contains("Off") && log.contains("Claude") && log.contains("instead"), "the saved builder and its replacement must be named:\n{log}");
+ assert!(!log.contains("Using "), "a replacement is not an added agent:\n{log}");
+}
diff --git a/crates/ai/src/rebuild/mod.rs b/crates/ai/src/rebuild/mod.rs
index 942e4760..609f0059 100644
--- a/crates/ai/src/rebuild/mod.rs
+++ b/crates/ai/src/rebuild/mod.rs
@@ -1274,6 +1274,35 @@ pub fn project_builder<'a>(cfg: &crate::AiConfig, ws: &'a Workspace) -> Option<&
ws.manifest.builder.as_deref().filter(|n| cfg.get(n).is_some_and(|b| b.config.enabled))
}
+/// A project's saved builder that is no longer usable, and the AI that builds in its place.
+#[derive(Debug, Clone, PartialEq, Eq)]
+pub struct BuilderReplacement {
+ /// The AI the project saved, which is off or gone.
+ pub saved: String,
+ /// The AI that builds in its place.
+ pub used: String,
+}
+
+/// When a project's saved builder is off or gone, who builds instead. An explicitly named backend
+/// is not a replacement: it is refused if unusable, and nothing falls back.
+pub fn builder_replacement(cfg: &crate::AiConfig, ws: &Workspace, explicit: Option<&str>) -> Option<BuilderReplacement> {
+ if explicit.is_some() {
+ return None;
+ }
+ let saved = ws.manifest.builder.as_deref().map(str::trim).filter(|s| !s.is_empty())?;
+ if project_builder(cfg, ws).is_some() {
+ return None;
+ }
+ let used = builder_backend(cfg, None).ok()?.config.name;
+ (used != saved).then(|| BuilderReplacement { saved: saved.to_string(), used })
+}
+
+/// The words for a saved builder that was turned off or removed and the one building instead.
+/// English for now: the wording needs a native speaker's check before it joins the catalogs.
+pub 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.")
+}
+
/// The backend that builds: the one named while it is set up and on, else the Builder role's,
/// else an agent app, else any enabled AI backend (which builds with our own agent loop and the
/// Build tools).
diff --git a/crates/ai/src/rebuild/question.rs b/crates/ai/src/rebuild/question.rs
index d19e44fe..e4cfad54 100644
--- a/crates/ai/src/rebuild/question.rs
+++ b/crates/ai/src/rebuild/question.rs
@@ -52,6 +52,9 @@ pub struct Answered {
/// The AI that answered.
pub backend: String,
pub cost_usd: Option<f64>,
+ /// The saved builder that was off or gone, when another AI answered in its place.
+ #[serde(skip_serializing_if = "Option::is_none")]
+ pub builder_notice: Option<String>,
}
/// Answer `question` about `ws` (see the module docs), with the person's `settings` (taken from
@@ -71,6 +74,7 @@ pub fn ask(
return Err(ToolError::invalid(format!("A question is 1 to {MAX_QUESTION} characters.")));
}
let cfg = crate::AiConfig::from_settings(settings);
+ let builder_notice = super::builder_replacement(&cfg, ws, None).map(|r| super::replaced_builder_notice(&r.saved, &r.used));
let entry = builder_backend(&cfg, project_builder(&cfg, ws))?;
let deep = settings.deep_mode;
let cli = |resume: Option<String>| -> Box<dyn Conversation> {
@@ -139,7 +143,7 @@ pub fn ask(
// A copy of a session reports the whole session's running cost, not this question's (a
// live run said $22.67 for a few cents of cache reads): say nothing rather than that.
let cost_usd = cost_usd.filter(|_| from != AnsweredFrom::BuildersSession);
- Ok(Answered { answer, from, backend: entry.config.name.clone(), cost_usd })
+ Ok(Answered { answer, from, backend: entry.config.name.clone(), cost_usd, builder_notice })
}
/// The builder's session, kept in the project, put back where its agent looks when this computer
diff --git a/crates/ai/src/rebuild/runs.rs b/crates/ai/src/rebuild/runs.rs
index 0bdf64d6..3df8e698 100644
--- a/crates/ai/src/rebuild/runs.rs
+++ b/crates/ai/src/rebuild/runs.rs
@@ -218,9 +218,10 @@ impl RunSet {
/// Poll `set` every `every` on a background thread while runs wait, so queued runs start as
/// soon as a place comes free: for holders that poll only when called (the rebuild tools, which
-/// an MCP client may not call again for a while). One thread per set at a time; it ends when the
-/// queue is empty or the engine is gone, and never waits on a busy session.
-pub fn keep_queue_moving(set: &Arc<Mutex<RunSet>>, engine: &Arc<Engine>, every: Duration) {
+/// an MCP client may not call again for a while). `settings_path` is the session's config file,
+/// read when the session is busy. One thread per set at a time; it ends when the queue is empty
+/// or the engine is gone, and never waits on a busy session.
+pub fn keep_queue_moving(set: &Arc<Mutex<RunSet>>, engine: &Arc<Engine>, settings_path: PathBuf, every: Duration) {
{
let mut s = set.lock().unwrap_or_else(PoisonError::into_inner);
if s.watched || s.queue.is_empty() {
@@ -242,7 +243,8 @@ pub fn keep_queue_moving(set: &Arc<Mutex<RunSet>>, engine: &Arc<Engine>, every:
s.set_limit(session.settings.build.parallel);
}
// Each run keeps its own project's feed, so the events aren't needed here.
- let _ = s.poll(&AiHub::new(engine));
+ let hub = AiHub::with_stores(engine, settings_path.clone(), crate::KeyStore::system());
+ let _ = s.poll(&hub);
if s.queue.is_empty() {
s.watched = false;
return;
@@ -419,14 +421,15 @@ mod tests {
let b = Workspace::create(d.path(), "B", "A game", TargetRef::None).unwrap();
let fake = StandIns::new();
let hub = hub();
+ let settings_path = hub.engine.session().config_dir().join("config.toml");
let set = Arc::new(Mutex::new(RunSet::new(1).with_starter(fake.starter())));
set.lock().unwrap().start(&hub, a.clone(), RunOptions::default()).unwrap();
// Nothing waits yet, so no thread is started.
- keep_queue_moving(&set, &hub.engine, Duration::from_millis(5));
+ keep_queue_moving(&set, &hub.engine, settings_path.clone(), Duration::from_millis(5));
assert!(!set.lock().unwrap().watched);
set.lock().unwrap().start(&hub, b.clone(), RunOptions::default()).unwrap();
- keep_queue_moving(&set, &hub.engine, Duration::from_millis(5));
- keep_queue_moving(&set, &hub.engine, Duration::from_millis(5));
+ keep_queue_moving(&set, &hub.engine, settings_path.clone(), Duration::from_millis(5));
+ keep_queue_moving(&set, &hub.engine, settings_path, Duration::from_millis(5));
assert!(set.lock().unwrap().watched);
fake.finish(&a.root);
let deadline = std::time::Instant::now() + Duration::from_secs(10);
diff --git a/crates/ai/src/rebuild/tests.rs b/crates/ai/src/rebuild/tests.rs
index e9040bc5..4ab3354f 100644
--- a/crates/ai/src/rebuild/tests.rs
+++ b/crates/ai/src/rebuild/tests.rs
@@ -3048,6 +3048,61 @@ fn a_project_is_built_by_the_ai_it_was_started_with_while_that_one_is_on() {
assert_eq!(builder_backend(&cfg, super::project_builder(&cfg, &ws)).unwrap().config.name, "Claude Code");
}
+/// The headless surfaces (CLI, MCP, a question) use the same replacement report as the app.
+#[test]
+fn a_saved_builder_that_is_off_or_gone_is_named_for_headless_starts() {
+ use crate::{AiConfig, BackendConfig, BackendEntry, BackendKind};
+ let d = tempfile::tempdir().unwrap();
+ let mut ws = Workspace::create(d.path(), "Notes", "A notes app", TargetRef::None).unwrap();
+ ws.manifest.builder = Some("Codex".into());
+ let mut cfg = AiConfig::default();
+ for (name, enabled) in [("Claude Code", true), ("Codex", true)] {
+ let c = BackendConfig { name: name.into(), kind: BackendKind::AgentCli, model: String::new(), base_url: None, ssh_host: None, enabled };
+ cfg.upsert(BackendEntry { config: c, options: Default::default() });
+ }
+ assert_eq!(super::builder_replacement(&cfg, &ws, None), None, "an enabled saved builder is not a replacement");
+ assert_eq!(super::builder_replacement(&cfg, &ws, Some("Codex")), None, "an explicit name is never a replacement");
+
+ cfg.backends.iter_mut().for_each(|b| b.config.enabled = b.config.name != "Codex");
+ let r = super::builder_replacement(&cfg, &ws, None).expect("a turned-off saved builder is replaced");
+ assert_eq!((r.saved.as_str(), r.used.as_str()), ("Codex", "Claude Code"));
+ let notice = super::replaced_builder_notice(&r.saved, &r.used);
+ assert!(notice.contains("Codex") && notice.contains("Claude Code") && notice.contains("instead"), "{notice}");
+
+ ws.manifest.builder = Some("Gone".into());
+ let r = super::builder_replacement(&cfg, &ws, None).expect("a removed saved builder is replaced");
+ assert_eq!((r.saved.as_str(), r.used.as_str()), ("Gone", "Claude Code"));
+}
+
+/// A question answered by the default AI still says which saved builder it replaced.
+#[cfg(unix)]
+#[test]
+fn a_question_names_a_replaced_saved_builder() {
+ use std::os::unix::fs::PermissionsExt;
+ let d = tempfile::tempdir().unwrap();
+ let script = d.path().join("claude");
+ std::fs::write(
+ &script,
+ "#!/bin/sh\ncat >/dev/null\nprintf '%s\\n' '{\"type\":\"assistant\",\"message\":{\"content\":[{\"type\":\"text\",\"text\":\"In app/src.\"}]}}'\nprintf '%s\\n' '{\"type\":\"result\",\"subtype\":\"success\",\"is_error\":false,\"num_turns\":1}'\n",
+ )
+ .unwrap();
+ std::fs::set_permissions(&script, std::fs::Permissions::from_mode(0o755)).unwrap();
+ let engine = std::sync::Arc::new(Engine::new(craft_anything_engine::testing::session()));
+ let hub = crate::AiHub::with_stores(engine, d.path().join("config.toml"), crate::KeyStore::file_only(d.path().join("keys.toml")));
+ let mut settings = craft_anything_engine::testing::session().settings;
+ settings.ai = toml::from_str(&format!(
+ "[[backends]]\nname = \"Off\"\nkind = \"anthropic\"\nmodel = \"claude-test\"\nenabled = false\n\n[[backends]]\nname = \"Claude\"\nkind = \"agent_cli\"\nmodel = \"claude-code\"\ncommand = \"{}\"\nenabled = true\n",
+ script.display()
+ ))
+ .unwrap();
+ let mut ws = Workspace::create(d.path(), "Notes", "A notes app", TargetRef::None).unwrap();
+ ws.set_person(|m| m.builder = Some("Off".into())).unwrap();
+ let answered = super::question::ask(&hub, &settings, None, &ws, "where is it?", &CancelToken::default()).unwrap();
+ assert_eq!(answered.backend, "Claude");
+ let notice = answered.builder_notice.as_deref().unwrap_or_default();
+ assert!(notice.contains("Off") && notice.contains("Claude"), "{notice}");
+}
+
/// A name given on purpose is never ignored: a backend that is off is refused in words that say
/// how to fix it, and a name that matches nothing names the name instead of blaming the setup.
#[test]
diff --git a/crates/ai/src/rebuild/tools.rs b/crates/ai/src/rebuild/tools.rs
index a7b9170a..bfcf8ed4 100644
--- a/crates/ai/src/rebuild/tools.rs
+++ b/crates/ai/src/rebuild/tools.rs
@@ -4,9 +4,9 @@
//! are the project tools' (`project_show`, `project_inbox_answer`, `project_play`…).
use super::*;
+use craft_anything_engine::EngineRef;
use craft_anything_engine::questions::{self, AskedQuestion};
use craft_anything_engine::tool::{Ctx, Effects, Requires, ToolOutput, ToolSpec, Toolset, parse_params, schema_of};
-use craft_anything_engine::{EngineRef, Settings};
use schemars::JsonSchema;
use serde::Deserialize;
@@ -243,7 +243,8 @@ fn engine(ctx: &Ctx<'_>) -> Option<Arc<Engine>> {
fn refresh(ctx: &Ctx<'_>, set: &mut RunSet) {
set.set_limit(ctx.session.settings.build.parallel);
if let Some(engine) = engine(ctx) {
- let _ = set.poll(&AiHub::new(engine));
+ let hub = AiHub::with_stores(engine, ctx.session.config_dir().join("config.toml"), crate::KeyStore::system());
+ let _ = set.poll(&hub);
}
}
@@ -286,6 +287,7 @@ fn rebuild_question_ask(ctx: &mut Ctx<'_>, params: Value) -> Result<ToolOutput,
deep: settings.deep_mode,
..AskedQuestion::new(question.to_string(), answered.answer.clone(), from_session, answered.backend.clone(), answered.cost_usd, after)
};
+ // The replacement notice is for this caller; the saved question keeps the AI that answered.
// An answer that couldn't be kept is still the answer.
let not_kept = questions::add(&ws, asked).err().map(|e| e.message);
Ok(ToolOutput::Value(json!({"project": ws.root, "question": question, "answered": answered, "not_kept": not_kept})))
@@ -303,11 +305,11 @@ fn rebuild_start(ctx: &mut Ctx<'_>, params: Value) -> Result<ToolOutput, ToolErr
ToolError::new(ErrorCode::FeatureMissing, "Building isn't available in this engine.").with_remediation("Use the app or `craft-anything-cli rebuild`.")
})?;
let runs = runs(ctx);
- let settings: &Settings = &ctx.session.settings;
+ let cfg = crate::AiConfig::from_settings(&ctx.session.settings);
// Refuse an unknown or switched-off name before opening or making a project or adding pictures:
// a refused start must not leave anything behind.
if let Some(name) = p.backend.as_deref() {
- builder_backend(&crate::AiConfig::from_settings(settings), Some(name))?;
+ builder_backend(&cfg, Some(name))?;
}
let (ws, message) = match &p.project {
Some(dir) => {
@@ -330,7 +332,7 @@ fn rebuild_start(ctx: &mut Ctx<'_>, params: Value) -> Result<ToolOutput, ToolErr
(None, Some(d)) => project::Place::In(d),
(None, None) => project::Place::Projects,
};
- let ws = project::new_project(settings, target, &p.request, place, p.build_with.as_deref(), p.generate_assets, p.backend.as_deref())?;
+ let ws = project::new_project(&ctx.session.settings, target, &p.request, place, p.build_with.as_deref(), p.generate_assets, p.backend.as_deref())?;
if p.project_folder.is_some() || matches!(place, project::Place::At(..)) {
ctx.session.remember_project(&ws.root)?;
}
@@ -340,6 +342,9 @@ fn rebuild_start(ctx: &mut Ctx<'_>, params: Value) -> Result<ToolOutput, ToolErr
if !p.pictures.is_empty() {
ws.add_references(&p.pictures)?;
}
+ // A headless start can't show the app's toast: say which AI builds when the saved one is gone.
+ let builder_notice =
+ p.project.as_ref().and_then(|_| super::builder_replacement(&cfg, &ws, p.backend.as_deref()).map(|r| super::replaced_builder_notice(&r.saved, &r.used)));
let mut set = runs.0.lock().unwrap_or_else(PoisonError::into_inner);
refresh(ctx, &mut set);
if set.is_busy(&ws.root) {
@@ -356,16 +361,21 @@ fn rebuild_start(ctx: &mut Ctx<'_>, params: Value) -> Result<ToolOutput, ToolErr
beginner: false,
..RunOptions::default()
};
- let hub = AiHub::new(engine);
- let out = match set.start(&hub, ws, opts)? {
+ // A tool runs with the session locked, so the hub reads the saved file: use this session's
+ // config file (the person's own in the app), not the machine's default one.
+ let hub = AiHub::with_stores(engine, ctx.session.config_dir().join("config.toml"), crate::KeyStore::system());
+ let mut out = match set.start(&hub, ws, opts)? {
Started::Running => json!({"project": root.display().to_string(), "started": true}),
Started::Queued { position } => {
// It starts when a place comes free, whether or not another tool is called.
drop(set);
- runs::keep_queue_moving(&runs.0, &hub.engine, QUEUE_TICK);
+ runs::keep_queue_moving(&runs.0, &hub.engine, ctx.session.config_dir().join("config.toml"), QUEUE_TICK);
json!({"project": root.display().to_string(), "started": false, "queued": position})
}
};
+ if let Some(notice) = builder_notice {
+ out["builder_notice"] = json!(notice);
+ }
Ok(ToolOutput::Value(out))
}
@@ -543,6 +553,57 @@ mod tests {
}
}
+ /// A saved builder that is off is named in the start result, so MCP callers see the
+ /// replacement too.
+ #[cfg(unix)]
+ #[test]
+ fn rebuild_start_names_a_replaced_saved_builder() {
+ use std::os::unix::fs::PermissionsExt;
+ let d = tempfile::tempdir().unwrap();
+ let script = d.path().join("claude");
+ std::fs::write(
+ &script,
+ "#!/bin/sh\ncat >/dev/null\nprintf '%s\\n' '{\"type\":\"assistant\",\"message\":{\"content\":[{\"type\":\"text\",\"text\":\"Made it blue.\"}]}}'\nprintf '%s\\n' '{\"type\":\"result\",\"subtype\":\"success\",\"is_error\":false,\"num_turns\":1}'\n",
+ )
+ .unwrap();
+ std::fs::set_permissions(&script, std::fs::Permissions::from_mode(0o755)).unwrap();
+ let mut s = craft_anything_engine::testing::session();
+ let mut ai = crate::AiConfig::default();
+ ai.upsert(crate::BackendEntry {
+ config: crate::BackendConfig {
+ name: "Off".into(),
+ kind: crate::BackendKind::Anthropic,
+ model: "claude-test".into(),
+ base_url: None,
+ ssh_host: None,
+ enabled: false,
+ },
+ options: Default::default(),
+ });
+ ai.upsert(crate::BackendEntry {
+ config: crate::BackendConfig {
+ name: "Claude".into(),
+ kind: crate::BackendKind::AgentCli,
+ model: "claude-code".into(),
+ base_url: None,
+ ssh_host: None,
+ enabled: true,
+ },
+ options: crate::BackendOptions { command: Some(script.display().to_string()), ..Default::default() },
+ });
+ s.settings.ai = ai.to_table().unwrap();
+ // The tool runs with the session locked; save the same settings where its hub reads them.
+ s.settings.save_to(&s.config_dir().join("config.toml")).unwrap();
+ let e = Engine::shared(s, specs());
+ let mut ws = Workspace::create(d.path(), "Notes", "A notes app", TargetRef::None).unwrap();
+ ws.set_person(|m| m.builder = Some("Off".into())).unwrap();
+ let ok = || CallOptions::new(Caller::Cli).with_consent(Consent::Granted);
+ let out = e.call("rebuild_start", json!({"project": ws.root, "request": "make it blue", "rounds": 0}), ok()).unwrap().to_json();
+ let notice = out["result"]["builder_notice"].as_str().unwrap_or_default();
+ assert!(notice.contains("Off") && notice.contains("Claude"), "{out}");
+ let _ = e.call("rebuild_stop", json!({"project": ws.root}), ok());
+ }
+
#[test]
fn the_builder_asks_the_running_build_for_a_check_and_gets_its_report() {
let d = tempfile::tempdir().unwrap();
diff --git a/crates/ui-egui/src/builders.rs b/crates/ui-egui/src/builders.rs
index 5b19b00d..2d593896 100644
--- a/crates/ui-egui/src/builders.rs
+++ b/crates/ui-egui/src/builders.rs
@@ -6,6 +6,7 @@ use crate::i18n::{tr, trf};
use crate::state::Modal;
use crate::theme::{self, Tokens};
use crate::{CraftApp, icons, widgets};
+use craft_anything_ai::rebuild::replaced_builder_notice;
use craft_anything_ai::{BackendConfig, BackendKind};
use egui::{RichText, Ui, Vec2};
@@ -105,12 +106,6 @@ 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> {
diff --git a/crates/ui-egui/src/just_ask.rs b/crates/ui-egui/src/just_ask.rs
index a4f33b8f..818ca4c5 100644
--- a/crates/ui-egui/src/just_ask.rs
+++ b/crates/ui-egui/src/just_ask.rs
@@ -109,6 +109,9 @@ impl CraftApp {
slot.answer = Some(Ok(answer));
slot.reveal = true;
}
+ if let Some(notice) = a["builder_notice"].as_str() {
+ self.toast(notice.to_string(), false);
+ }
if let Some(why) = v["not_kept"].as_str() {
self.toast(format!("{} {why}", tr("This answer won't be there after a restart:")), true);
}
@@ -215,6 +218,23 @@ mod tests {
assert!(out[1].pictures.is_empty());
}
+ #[test]
+ fn a_question_answered_by_a_replacement_says_so() {
+ let mut app = crate::demo::app(crate::demo::engine(craft_anything_engine::Mode::Beginner, true));
+ app.question_done(Ok(serde_json::json!({
+ "project": "/tmp/example",
+ "question": "where?",
+ "answered": {
+ "answer": "In app.",
+ "from": "the_files",
+ "backend": "Claude",
+ "builder_notice": "The AI chosen for this project (Off) is turned off or no longer set up. Claude builds instead."
+ },
+ "not_kept": null
+ })));
+ assert!(app.state.toasts.iter().any(|(t, err)| !*err && t.contains("Off") && t.contains("Claude")), "{:?}", app.state.toasts);
+ }
+
#[test]
fn a_question_is_marked_by_the_switch_or_btw() {
let question = |t: &str, just_ask| question_in(t, just_ask).unwrap();
diff --git a/docs/ROADMAP.md b/docs/ROADMAP.md
index 3bda9cc4..78881f82 100644
--- a/docs/ROADMAP.md
+++ b/docs/ROADMAP.md
@@ -446,9 +446,10 @@ Owner: open · Status: todo
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
+- [x] `rebuild --continue-in`, `rebuild_start` on a project and `rebuild_question_ask` name the
+ saved builder that is off or gone and the AI building instead: the CLI prints it before the
+ run, `rebuild_start` adds `builder_notice`, and an answered question carries it
+ — claimed: AlexJoaquimPereira, branch `bugfix/r5.5-headless-builder-notice`
- [ ] 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 cannot