Skip to content

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

Rust

Try the next renderer after a Windows start that can't draw, and close the gaps in the Claude desktop hint (#1001)

BFlat827fdb793d11
diff --git a/apps/craft-anything/src/main.rs b/apps/craft-anything/src/main.rs
index a9c1b937..af88bfcb 100644
--- a/apps/craft-anything/src/main.rs
+++ b/apps/craft-anything/src/main.rs
@@ -8,10 +8,13 @@ use craft_anything_ui_egui::CraftApp;
use std::path::PathBuf;
use std::sync::Arc;
+#[cfg(any(windows, test))]
+mod renderer;
mod start_guard;
-/// Set when the last start never opened its window (see [`start_guard`]): the software renderer
-/// (WARP) is asked for, as with `CRAFT_ANYTHING_RENDERER=software`, for this start only.
+/// Set when this start draws with the software renderer (WARP), as with
+/// `CRAFT_ANYTHING_RENDERER=software`: the renderer chain chose it (see [`renderer`]), or the
+/// environment picks the backend and the last start never opened its window.
#[cfg(windows)]
static RETRY_IN_SOFTWARE: std::sync::atomic::AtomicBool = std::sync::atomic::AtomicBool::new(false);
@@ -33,13 +36,15 @@ fn main() -> eframe::Result {
log_to_file();
log::info!("starting {} (pid {})", env!("CARGO_PKG_VERSION"), std::process::id());
// A driver that crashes natively leaves nothing behind but this mark (#74): the start after it
- // draws without the graphics card, and the one after that is back to normal.
+ // draws another way (on Windows, the next renderer, which is kept once it works).
let config = craft_anything_engine::settings::config_dir();
- if start_guard::last_start_failed(&config) {
- log::warn!("the last start never opened its window; drawing without the graphics card this time");
- #[cfg(windows)]
- RETRY_IN_SOFTWARE.store(true, std::sync::atomic::Ordering::Relaxed);
+ let last_failed = start_guard::last_start_failed(&config);
+ if last_failed {
+ log::warn!("the last start never opened its window");
}
+ // Windows: the way to draw this time, the next one when the last start failed (#794).
+ #[cfg(windows)]
+ let renderer = pick_renderer(&config, last_failed);
start_guard::begin(&config);
let settings = Settings::load();
@@ -85,7 +90,7 @@ fn main() -> eframe::Result {
// Intel drivers crash in it (ig9icd64.dll, #196), so the window never opens. Similarly,
// starting Vulkan loads Intel's Vulkan driver (igvk64.dll, #394) and crashes before any
// window. DX12 (with WARP) covers all Windows systems; `WGPU_BACKEND` still asks for others.
- setup.instance_descriptor.backends = windows_backends(eframe::wgpu::Backends::from_env());
+ setup.instance_descriptor.backends = windows_backends(eframe::wgpu::Backends::from_env(), renderer);
setup.instance_descriptor.backend_options.dx12.shader_compiler = dx12_compiler(eframe::wgpu::Dx12Compiler::from_env());
setup.native_adapter_selector = Some(Arc::new(pick_adapter));
}
@@ -124,13 +129,31 @@ fn main() -> eframe::Result {
Ok(()) => log::info!("closed"),
Err(e) => {
log::error!("the window couldn't start: {e}");
+ // A wgpu error before the window was shown, with another renderer still to try: start
+ // again with it at once rather than ask the person to (#794). The chain ends, so this
+ // can't loop.
+ #[cfg(windows)]
+ if !shown.load(std::sync::atomic::Ordering::Relaxed)
+ && let Some(next) = renderer.and_then(|r| renderer::relaunch_with(r, &e.to_string()))
+ && {
+ start_guard::release();
+ relaunch(&args)
+ }
+ {
+ log::warn!("starting again with {}", next.title());
+ return run;
+ }
// Without a window the app would just vanish (#166): say why, and where the log is.
let log = craft_anything_engine::settings::config_dir().join("desktop.log");
+ #[cfg(windows)]
+ let retry = renderer.map(|r| format!(" The next start will draw with {}.", renderer::choose(Some(r), true).title())).unwrap_or_default();
+ #[cfg(not(windows))]
+ let retry = String::new();
let _ = rfd::MessageDialog::new()
.set_level(rfd::MessageLevel::Error)
.set_title("Craft Anything couldn't open its window")
.set_description(format!(
- "{e}\n\n{} What happened is written to {}; please attach it if you report this.",
+ "{e}\n\n{}{retry} What happened is written to {}; please attach it if you report this.",
graphics_advice(&e.to_string()),
log.display()
))
@@ -220,9 +243,50 @@ fn pick_adapter(adapters: &[eframe::wgpu::Adapter], surface: Option<&eframe::wgp
/// only (#196, #394). Vulkan and GL load third-party driver DLLs (igvk64.dll, ig9icd64.dll) before
/// an adapter is chosen, which crash on some Intel systems. DX12 (with WARP) covers all Windows
/// installations; `WGPU_BACKEND=vulkan` or `gl` still asks for them explicitly.
+/// After a start that failed, the renderer chain may have moved on to Vulkan or GL (#794): it is
+/// only reached once DX12 has failed.
+#[cfg(windows)]
+fn windows_backends(from_env: Option<eframe::wgpu::Backends>, renderer: Option<renderer::Renderer>) -> eframe::wgpu::Backends {
+ from_env.or(renderer.map(renderer::Renderer::backends)).unwrap_or(eframe::wgpu::Backends::DX12)
+}
+
+/// Windows: the renderer for this start (see [`renderer`]), remembered before the window is asked
+/// for, so a start that dies makes the next one try the next renderer. `None` when
+/// `WGPU_BACKEND` or `CRAFT_ANYTHING_RENDERER` decides; then a failed start only brings WARP, as
+/// before.
#[cfg(windows)]
-fn windows_backends(from_env: Option<eframe::wgpu::Backends>) -> eframe::wgpu::Backends {
- from_env.unwrap_or(eframe::wgpu::Backends::DX12)
+fn pick_renderer(config: &std::path::Path, last_failed: bool) -> Option<renderer::Renderer> {
+ use std::sync::atomic::Ordering;
+ let set = |name: &str| std::env::var_os(name).is_some_and(|v| !v.is_empty());
+ if set("WGPU_BACKEND") || set("CRAFT_ANYTHING_RENDERER") {
+ if last_failed {
+ log::warn!("drawing without the graphics card this time");
+ RETRY_IN_SOFTWARE.store(true, Ordering::Relaxed);
+ }
+ return None;
+ }
+ let version = env!("CARGO_PKG_VERSION");
+ let chosen = renderer::choose(renderer::remembered(config, version), last_failed);
+ renderer::remember(config, version, chosen);
+ RETRY_IN_SOFTWARE.store(chosen.software(), Ordering::Relaxed);
+ if last_failed {
+ log::warn!("drawing with {} ({}), after a start that never opened its window", chosen.title(), chosen.name());
+ } else if chosen != renderer::Renderer::Dx12 {
+ log::info!("drawing with {} ({}), which opened the window last time", chosen.title(), chosen.name());
+ }
+ Some(chosen)
+}
+
+/// Starts the app again with the same arguments; whether it started.
+#[cfg(windows)]
+fn relaunch(args: &[String]) -> bool {
+ let started = std::env::current_exe()
+ .map_err(|e| e.to_string())
+ .and_then(|exe| craft_anything_platform::process::Launch::new(&exe).args(args).label("Craft Anything").start().map_err(|e| e.to_string()));
+ if let Err(e) = &started {
+ log::warn!("couldn't start again: {e}");
+ }
+ started.is_ok()
}
/// Lower is better: GL last, fastest device first, DX12 before Vulkan only between same-class devices
@@ -271,10 +335,16 @@ mod tests {
#[test]
fn gl_and_vulkan_are_only_started_when_asked_for() {
use eframe::wgpu::Backends;
- let started = windows_backends(None);
- assert_eq!(started, Backends::DX12);
- assert_eq!(windows_backends(Some(Backends::GL)), Backends::GL, "WGPU_BACKEND=gl still works");
- assert_eq!(windows_backends(Some(Backends::VULKAN)), Backends::VULKAN, "WGPU_BACKEND=vulkan still works");
+ use renderer::Renderer;
+ assert_eq!(windows_backends(None, None), Backends::DX12);
+ assert_eq!(windows_backends(None, Some(Renderer::Dx12)), Backends::DX12);
+ assert_eq!(windows_backends(None, Some(Renderer::Warp)), Backends::DX12, "WARP is a DX12 adapter");
+ assert_eq!(windows_backends(Some(Backends::GL), None), Backends::GL, "WGPU_BACKEND=gl still works");
+ assert_eq!(windows_backends(Some(Backends::VULKAN), None), Backends::VULKAN, "WGPU_BACKEND=vulkan still works");
+ // #794: once DX12 and WARP failed, the chain reaches them without the variable.
+ assert_eq!(windows_backends(None, Some(Renderer::Vulkan)), Backends::VULKAN);
+ assert_eq!(windows_backends(None, Some(Renderer::Gl)), Backends::GL);
+ assert_eq!(windows_backends(Some(Backends::DX12), Some(Renderer::Gl)), Backends::DX12, "the variable wins");
}
}
diff --git a/apps/craft-anything/src/renderer.rs b/apps/craft-anything/src/renderer.rs
new file mode 100644
index 00000000..4048e45f
--- /dev/null
+++ b/apps/craft-anything/src/renderer.rs
@@ -0,0 +1,194 @@
+//! Windows: which way the window draws, and the next one to try after a start that failed (#794).
+//!
+//! DX12 on the graphics card is the usual way. Some systems refuse it in a way no driver update
+//! fixes: there `CreatePipelineState` rejects egui's own pipeline (`egui_pipeline`, "The parameter
+//! is incorrect", 0x80070057) on AMD, Intel and NVIDIA cards alike, and on WARP too, while Vulkan or
+//! OpenGL draw fine. Software (WARP) alone was the only retry, so such a start failed every time.
+//!
+//! So the renderers form a chain, DX12 → WARP → Vulkan → OpenGL. Each start writes the renderer it
+//! uses here before the window is asked for; a start that never opened its window (see
+//! [`crate::start_guard`]) makes the next one take the next renderer, and a renderer that worked is
+//! kept. That covers a driver that crashes the process natively as well as a wgpu error the app
+//! catches. Vulkan and OpenGL come last because loading their drivers is what crashed some Intel
+//! systems before any window (#196, #394): they are reached only once DX12 has failed.
+//!
+//! The choice is kept for this app version only: an update starts from DX12 again, so a system that
+//! was fixed meanwhile is back on the fast way. `WGPU_BACKEND` and `CRAFT_ANYTHING_RENDERER` still
+//! decide when set, and then nothing here is used.
+
+use std::path::{Path, PathBuf};
+
+/// Beside the settings, with `desktop.log` and the start mark.
+const FILE: &str = "renderer";
+/// The file's own format, so a later one can read it or start afresh.
+const FORMAT: u32 = 1;
+
+/// A way to draw the window.
+#[derive(Debug, Clone, Copy, PartialEq, Eq)]
+pub enum Renderer {
+ /// DX12 on the graphics card.
+ Dx12,
+ /// DX12 with Windows' software renderer.
+ Warp,
+ Vulkan,
+ Gl,
+}
+
+/// The order they are tried in.
+const CHAIN: [Renderer; 4] = [Renderer::Dx12, Renderer::Warp, Renderer::Vulkan, Renderer::Gl];
+
+impl Renderer {
+ pub fn name(self) -> &'static str {
+ match self {
+ Renderer::Dx12 => "dx12",
+ Renderer::Warp => "warp",
+ Renderer::Vulkan => "vulkan",
+ Renderer::Gl => "gl",
+ }
+ }
+
+ /// What people read in the start-failure dialog.
+ #[cfg_attr(not(windows), expect(dead_code, reason = "only Windows picks its renderer"))]
+ pub fn title(self) -> &'static str {
+ match self {
+ Renderer::Dx12 => "DirectX 12",
+ Renderer::Warp => "Windows' software renderer",
+ Renderer::Vulkan => "Vulkan",
+ Renderer::Gl => "OpenGL",
+ }
+ }
+
+ fn from_name(name: &str) -> Option<Self> {
+ CHAIN.into_iter().find(|r| r.name() == name)
+ }
+
+ /// The one to try after this one failed; `None` after the last.
+ pub fn next(self) -> Option<Self> {
+ CHAIN.iter().position(|r| *r == self).and_then(|i| CHAIN.get(i.saturating_add(1))).copied()
+ }
+
+ /// Whether this one draws with WARP.
+ #[cfg_attr(not(windows), expect(dead_code, reason = "only Windows picks its renderer"))]
+ pub fn software(self) -> bool {
+ self == Renderer::Warp
+ }
+
+ #[cfg(windows)]
+ pub fn backends(self) -> eframe::wgpu::Backends {
+ use eframe::wgpu::Backends;
+ match self {
+ Renderer::Dx12 | Renderer::Warp => Backends::DX12,
+ Renderer::Vulkan => Backends::VULKAN,
+ Renderer::Gl => Backends::GL,
+ }
+ }
+}
+
+/// The renderer for this start: the remembered one, or the next after it when the last start never
+/// opened its window. After the last there's nothing new to try, so it starts over from DX12 (the
+/// driver may have been updated meanwhile) rather than staying on one that failed.
+pub fn choose(remembered: Option<Renderer>, last_start_failed: bool) -> Renderer {
+ let current = remembered.unwrap_or(Renderer::Dx12);
+ if last_start_failed { current.next().unwrap_or(Renderer::Dx12) } else { current }
+}
+
+/// Whether a start that failed before its window should start again at once with the next
+/// renderer, and which: only when wgpu said what went wrong (any other early bug isn't the
+/// renderer's fault, and the next start moves on anyway), and only while there is a next one, so
+/// it never loops.
+pub fn relaunch_with(current: Renderer, error: &str) -> Option<Renderer> {
+ if error.contains("wgpu") { current.next() } else { None }
+}
+
+fn file(dir: &Path) -> PathBuf {
+ dir.join(FILE)
+}
+
+/// The renderer remembered for this app version, if any. A file from another version, another
+/// format or one that can't be read means none.
+pub fn remembered(dir: &Path, app_version: &str) -> Option<Renderer> {
+ let text = std::fs::read_to_string(file(dir)).ok()?;
+ let mut format = None;
+ let mut version = None;
+ let mut renderer = None;
+ for line in text.lines() {
+ match line.split_once('=') {
+ Some(("format", v)) => format = v.trim().parse::<u32>().ok(),
+ Some(("app", v)) => version = Some(v.trim()),
+ Some(("renderer", v)) => renderer = Renderer::from_name(v.trim()),
+ _ => {}
+ }
+ }
+ (format == Some(FORMAT) && version == Some(app_version)).then_some(renderer).flatten()
+}
+
+/// Remembers the renderer this start uses, before the window is asked for. Best effort: a folder
+/// that can't be written to only means no fallback.
+pub fn remember(dir: &Path, app_version: &str, renderer: Renderer) {
+ let text = format!("format={FORMAT}\napp={app_version}\nrenderer={}\n", renderer.name());
+ if std::fs::create_dir_all(dir).is_ok()
+ && let Err(e) = craft_anything_platform::fs::write_atomic(&file(dir), text.as_bytes())
+ {
+ log::warn!("couldn't remember the renderer: {e}");
+ }
+}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+
+ /// #794: DX12 and WARP both refused egui's pipeline, Vulkan drew. Each failed start moves on one
+ /// step, a start that opened its window stays where it is, and after OpenGL it starts over.
+ #[test]
+ fn each_failed_start_tries_the_next_renderer_and_a_working_one_is_kept() {
+ assert_eq!(choose(None, false), Renderer::Dx12, "a first start draws the usual way");
+ assert_eq!(choose(None, true), Renderer::Warp, "the old fallback is still the first retry");
+ assert_eq!(choose(Some(Renderer::Warp), true), Renderer::Vulkan);
+ assert_eq!(choose(Some(Renderer::Vulkan), true), Renderer::Gl);
+ assert_eq!(choose(Some(Renderer::Gl), true), Renderer::Dx12, "after the last, start over");
+ assert_eq!(choose(Some(Renderer::Vulkan), false), Renderer::Vulkan, "one that worked is kept");
+ }
+
+ #[test]
+ fn only_a_graphics_error_starts_again_and_never_past_the_last() {
+ let text = "internal error before the window was shown: wgpu error: Validation Error\n\nCaused by:\n In Device::create_render_pipeline, label = 'egui_pipeline'";
+ assert_eq!(relaunch_with(Renderer::Dx12, text), Some(Renderer::Warp));
+ assert_eq!(relaunch_with(Renderer::Warp, text), Some(Renderer::Vulkan));
+ assert_eq!(relaunch_with(Renderer::Gl, text), None, "nothing left: the dialog says why");
+ assert_eq!(relaunch_with(Renderer::Dx12, "internal error before the window was shown: settings"), None);
+ }
+
+ #[test]
+ fn the_choice_is_kept_for_this_version_only() {
+ let d = tempfile::tempdir().unwrap();
+ let dir = d.path().join("config");
+ assert_eq!(remembered(&dir, "0.4.0"), None, "nothing yet");
+ remember(&dir, "0.4.0", Renderer::Vulkan);
+ assert_eq!(remembered(&dir, "0.4.0"), Some(Renderer::Vulkan));
+ assert_eq!(remembered(&dir, "0.4.1"), None, "an update starts from DX12 again");
+ remember(&dir, "0.4.0", Renderer::Gl);
+ assert_eq!(remembered(&dir, "0.4.0"), Some(Renderer::Gl), "the latest is kept");
+ }
+
+ #[test]
+ fn a_file_we_cannot_read_means_none_and_no_crash() {
+ let d = tempfile::tempdir().unwrap();
+ for text in ["", "renderer=vulkan", "format=2\napp=0.4.0\nrenderer=vulkan", "format=1\napp=0.4.0\nrenderer=metal", "\u{0}\u{ff}garbage"] {
+ std::fs::write(file(d.path()), text).unwrap();
+ assert_eq!(remembered(d.path(), "0.4.0"), None, "{text:?}");
+ }
+ // A folder that is a file: nothing written, nothing remembered.
+ let not_a_folder = d.path().join("not-a-folder");
+ std::fs::write(&not_a_folder, "").unwrap();
+ remember(&not_a_folder, "0.4.0", Renderer::Gl);
+ assert_eq!(remembered(&not_a_folder, "0.4.0"), None);
+ }
+
+ #[test]
+ fn names_round_trip() {
+ for r in CHAIN {
+ assert_eq!(Renderer::from_name(r.name()), Some(r));
+ }
+ assert_eq!(Renderer::Gl.next(), None);
+ }
+}
diff --git a/apps/craft-anything/src/start_guard.rs b/apps/craft-anything/src/start_guard.rs
index 514ae977..388e1dd0 100644
--- a/apps/craft-anything/src/start_guard.rs
+++ b/apps/craft-anything/src/start_guard.rs
@@ -5,32 +5,53 @@
//! just vanishes. What can be done is to leave a mark before trying and remove it once the window
//! is open and has shown its first frames (the driver may crash while presenting them, after
//! eframe's setup callback has run); a mark found at the next start means the last one never got
-//! there, and the app draws without the graphics card that time (see `main`). A start that does
-//! open the window clears the mark, so the next one is back to normal.
+//! there, and the app draws another way (see `main` and `renderer`). A start that does open the
+//! window clears the mark.
+//!
+//! A start holds a lock on its mark, which the system lets go of when the process dies. A mark
+//! still locked is a start under way (the icon double-clicked), not one that failed: on Windows
+//! that would move the app to another renderer for good.
+use craft_anything_platform::sync::Mutex;
+use std::fs::{File, OpenOptions, TryLockError};
use std::path::{Path, PathBuf};
+use std::sync::PoisonError;
/// Beside the settings, with `desktop.log`.
const MARKER: &str = "starting";
+/// This start's mark, kept open to keep its lock.
+static HELD: Mutex<Option<File>> = Mutex::new(None);
+
fn marker(dir: &Path) -> PathBuf {
dir.join(MARKER)
}
/// Whether the last start ended before its window opened.
pub fn last_start_failed(dir: &Path) -> bool {
- marker(dir).exists()
+ File::open(marker(dir)).is_ok_and(|mark| !matches!(mark.try_lock(), Err(TryLockError::WouldBlock)))
}
/// Called right before the window is asked for. Best effort: a folder that can't be written to
/// only means no fallback.
pub fn begin(dir: &Path) {
let _ = std::fs::create_dir_all(dir);
- let _ = std::fs::write(marker(dir), std::process::id().to_string());
+ // Not truncated: the mark may be locked by a start that is still going.
+ let Ok(mark) = OpenOptions::new().write(true).create(true).truncate(false).open(marker(dir)) else { return };
+ if mark.try_lock().is_ok() {
+ *HELD.lock().unwrap_or_else(PoisonError::into_inner) = Some(mark);
+ }
+}
+
+/// Lets go of the mark but leaves it, as dying would: for a start that hands over to another.
+#[cfg(any(windows, test))]
+pub fn release() {
+ HELD.lock().unwrap_or_else(PoisonError::into_inner).take();
}
/// Called once the window is open.
pub fn opened(dir: &Path) {
+ HELD.lock().unwrap_or_else(PoisonError::into_inner).take();
let _ = std::fs::remove_file(marker(dir));
}
@@ -45,8 +66,11 @@ mod tests {
let dir = d.path().join("config");
assert!(!last_start_failed(&dir), "a first start has nothing to retry");
begin(&dir);
+ assert!(!last_start_failed(&dir), "a second launch while this one opens is no failure");
+ release();
assert!(last_start_failed(&dir), "the process died before opened()");
begin(&dir);
+ release();
assert!(last_start_failed(&dir), "a second start in a row still sees it");
opened(&dir);
assert!(!last_start_failed(&dir), "a window that opened clears it");
diff --git a/crates/ai/src/cli_agents/mod.rs b/crates/ai/src/cli_agents/mod.rs
index 47e65da4..b3ec8bec 100644
--- a/crates/ai/src/cli_agents/mod.rs
+++ b/crates/ai/src/cli_agents/mod.rs
@@ -62,12 +62,14 @@ pub fn program_for(agent: &str) -> String {
/// computer (ssh) the chosen command is used as it is.
pub fn program_of(config: &BackendConfig, options: &BackendOptions) -> String {
let usual = program_for(&config.model);
- let Some(chosen) = options.command.as_deref().map(str::trim).filter(|c| !c.is_empty()) else { return usual };
let local = config.ssh_host.as_deref().is_none_or(|h| h.trim().is_empty());
+ let Some(chosen) = options.command.as_deref().map(str::trim).filter(|c| !c.is_empty()) else {
+ return if local { usual_program(usual) } else { usual };
+ };
// A folder or app bundle saved before set_command refused it (#467) can't be started: the usual
// program is used, as when none is chosen.
if local && Path::new(chosen).is_dir() {
- return usual;
+ return usual_program(usual);
}
let path = Path::new(chosen);
if !local || path.parent().is_none_or(|p| p.as_os_str().is_empty()) || path.exists() {
@@ -76,6 +78,38 @@ pub fn program_of(config: &BackendConfig, options: &BackendOptions) -> String {
moved_program(path).or_else(|| craft_anything_platform::which(&usual).map(|_| usual)).unwrap_or_else(|| chosen.to_string())
}
+/// The usual name, or the real program's path when the name alone would start something else that
+/// comes first on the search path (the Claude desktop app's `claude.exe`).
+fn usual_program(usual: String) -> String {
+ match (craft_anything_platform::which(&usual), find_program(&usual)) {
+ (Some(first), Some(real)) if first != real => real.display().to_string(),
+ _ => usual,
+ }
+}
+
+/// Where an agent's program is on this computer: the first match on the search path that is
+/// really it. Detection, the desktop app hint and starting a run all look through this, so what's
+/// offered is what runs.
+pub fn find_program(program: &str) -> Option<PathBuf> {
+ find_program_in(program, craft_anything_platform::which::search_path())
+}
+
+fn find_program_in(program: &str, path: Option<std::ffi::OsString>) -> Option<PathBuf> {
+ craft_anything_platform::which::which_in(program, path).into_iter().find(|p| program != "claude" || !is_claude_desktop(p))
+}
+
+/// A file inside the Claude desktop app, which can't build: its older installer names the app
+/// `claude.exe` (`AnthropicClaude\claude.exe`, `AnthropicClaude\app-<version>\claude.exe`), the
+/// Store package keeps it under `WindowsApps\Claude_<version>_<arch>__<publisher>`, and on macOS
+/// it's in `Claude.app`. Only names are compared; nothing is read.
+pub(crate) fn is_claude_desktop(path: &Path) -> bool {
+ path.ancestors().skip(1).take(4).any(|dir| {
+ let name = dir.file_name().map(|n| n.to_string_lossy().to_ascii_lowercase()).unwrap_or_default();
+ let in_store = dir.parent().and_then(Path::file_name).is_some_and(|p| p.eq_ignore_ascii_case("WindowsApps"));
+ name == "anthropicclaude" || name == "claude.app" || (in_store && name.starts_with("claude_"))
+ })
+}
+
/// The same file in the most recently changed sibling of its missing folder, if there is one.
fn moved_program(missing: &Path) -> Option<String> {
let file = missing.file_name()?;
@@ -1142,6 +1176,46 @@ mod tests {
assert_eq!(program_of(&config(None), &bare), "my-codex", "a bare name is left to PATH");
}
+ /// The Claude desktop app's older installer names its app `claude.exe`; with its folder on
+ /// PATH, it was offered as Claude Code (review of #781).
+ #[test]
+ fn the_claude_desktop_app_is_never_taken_for_claude_code() {
+ for app in [
+ r"C:\Users\x\AppData\Local\AnthropicClaude\claude.exe",
+ r"C:\Users\x\AppData\Local\AnthropicClaude\app-0.10.0\claude.exe",
+ r"C:\Program Files\WindowsApps\Claude_4.4212.0.0_x64__pzs8sxrjxfjjc\app\Claude.exe",
+ "/Applications/Claude.app/Contents/MacOS/Claude",
+ ] {
+ let app = PathBuf::from(app.replace('\\', std::path::MAIN_SEPARATOR_STR));
+ assert!(is_claude_desktop(&app), "{}", app.display());
+ }
+ for cli in [r"C:\Users\x\.local\bin\claude.exe", r"C:\Users\x\AppData\Roaming\npm\claude.cmd", "/Users/x/.claude/local/claude"] {
+ let cli = PathBuf::from(cli.replace('\\', std::path::MAIN_SEPARATOR_STR));
+ assert!(!is_claude_desktop(&cli), "{}", cli.display());
+ }
+
+ let d = tempfile::tempdir().unwrap();
+ let file = if cfg!(windows) { "claude.exe" } else { "claude" };
+ let app = d.path().join("AnthropicClaude").join(file);
+ let cli = d.path().join("bin").join(file);
+ for p in [&app, &cli] {
+ std::fs::create_dir_all(p.parent().unwrap()).unwrap();
+ std::fs::write(p, b"").unwrap();
+ #[cfg(unix)]
+ std::fs::set_permissions(p, std::os::unix::fs::PermissionsExt::from_mode(0o755)).unwrap();
+ }
+ let path = |dirs: &[&Path]| std::env::join_paths(dirs).ok();
+ let (app_dir, cli_dir) = (app.parent().unwrap(), cli.parent().unwrap());
+ assert_eq!(find_program_in("claude", path(&[app_dir, cli_dir])), Some(cli.clone()), "the desktop app is passed over");
+ assert_eq!(find_program_in("claude", path(&[app_dir])), None, "only the desktop app: no Claude Code");
+ // Another agent's program in such a folder is only filtered for Claude.
+ let other = app_dir.join(if cfg!(windows) { "codex.exe" } else { "codex" });
+ std::fs::write(&other, b"").unwrap();
+ #[cfg(unix)]
+ std::fs::set_permissions(&other, std::os::unix::fs::PermissionsExt::from_mode(0o755)).unwrap();
+ assert_eq!(find_program_in("codex", path(&[app_dir])), Some(other));
+ }
+
#[test]
fn failed_craft_tool_server_is_reported_from_its_init_status() {
let mut p = StreamParser::new(adapter_for("claude-code"));
diff --git a/crates/ai/src/detect.rs b/crates/ai/src/detect.rs
index c5e4ae8b..42641f68 100644
--- a/crates/ai/src/detect.rs
+++ b/crates/ai/src/detect.rs
@@ -148,7 +148,7 @@ pub fn agent_clis() -> Vec<Detected> {
crate::cli_agents::KNOWN
.iter()
.filter_map(|(id, prog, display)| {
- craft_anything_platform::which(prog).map(|p| Detected {
+ crate::cli_agents::find_program(prog).map(|p| Detected {
suggestion: cfg(display, BackendKind::AgentCli, id),
reason: format!("Found {display} at {}", p.display()),
needs_key: false,
@@ -184,7 +184,7 @@ impl DetectHint {
/// Hints for what [`agent_clis`] can't offer.
pub fn hints() -> Vec<DetectHint> {
- if craft_anything_platform::which("claude").is_some() {
+ if crate::cli_agents::find_program("claude").is_some() {
return Vec::new();
}
let home = std::env::var_os(if cfg!(windows) { "USERPROFILE" } else { "HOME" }).map(PathBuf::from);
@@ -192,15 +192,26 @@ pub fn hints() -> Vec<DetectHint> {
claude_desktop_app(home.as_deref(), local_data.as_deref()).map(|app| DetectHint::ClaudeDesktopWithoutCli { app }).into_iter().collect()
}
+/// The Claude desktop app's Store package family (name and publisher id), whose folder Windows
+/// makes under `%LOCALAPPDATA%\Packages` for each person it's installed for.
+const CLAUDE_STORE_PACKAGE: &str = "Claude_pzs8sxrjxfjjc";
+
/// Where the Claude desktop app is, if it's installed. On Windows the Store package leaves a
-/// `claude-desktop` app alias (a link that only `symlink_metadata` can read) and the older
-/// installer an `AnthropicClaude` folder; on macOS it's `Claude.app`. There's no Linux app.
+/// `claude-desktop` app alias (a link that only `symlink_metadata` can read), or, with its app
+/// aliases turned off, only its package folder; the older installer leaves an `AnthropicClaude`
+/// folder. On macOS it's `Claude.app`. There's no Linux app.
fn claude_desktop_app(home: Option<&std::path::Path>, local_data: Option<&std::path::Path>) -> Option<PathBuf> {
let places: Vec<PathBuf> = if cfg!(windows) {
let local_data = local_data.map(PathBuf::from).or_else(|| home.map(|h| h.join("AppData").join("Local")));
local_data
.into_iter()
- .flat_map(|d| [d.join("Microsoft").join("WindowsApps").join("claude-desktop.exe"), d.join("AnthropicClaude").join("claude.exe")])
+ .flat_map(|d| {
+ [
+ d.join("Microsoft").join("WindowsApps").join("claude-desktop.exe"),
+ d.join("AnthropicClaude").join("claude.exe"),
+ d.join("Packages").join(CLAUDE_STORE_PACKAGE),
+ ]
+ })
.collect()
} else if cfg!(target_os = "macos") {
std::iter::once(PathBuf::from("/Applications/Claude.app")).chain(home.map(|h| h.join("Applications").join("Claude.app"))).collect()
@@ -396,6 +407,11 @@ mod tests {
std::fs::create_dir_all(alias.parent().unwrap()).unwrap();
std::fs::write(&alias, b"").unwrap();
assert_eq!(claude_desktop_app(None, Some(dir.path())), Some(alias));
+ // A Store install whose app aliases are turned off leaves only its package folder.
+ let store = tempfile::tempdir().unwrap();
+ let package = store.path().join("Packages").join(CLAUDE_STORE_PACKAGE);
+ std::fs::create_dir_all(&package).unwrap();
+ assert_eq!(claude_desktop_app(None, Some(store.path())), Some(package));
} else if cfg!(target_os = "linux") {
assert_eq!(found, None, "there's no Claude desktop app for Linux");
}
diff --git a/crates/ui-egui/src/builders.rs b/crates/ui-egui/src/builders.rs
index c904ac9c..292e7234 100644
--- a/crates/ui-egui/src/builders.rs
+++ b/crates/ui-egui/src/builders.rs
@@ -402,9 +402,14 @@ pub fn need_builder_modal(app: &mut CraftApp, ui: &mut Ui, start: bool, close: &
ui.add(crate::widgets::Spinner::new().color(t.accent));
ui.label(RichText::new(tr("Looking on this computer…")).color(t.text_dim));
});
- } else if found.is_empty() {
- ui.label(RichText::new(tr("No coding agent was found on this computer yet.")).color(t.text_dim));
- for hint in &app.detect_hints {
+ } else {
+ if found.is_empty() {
+ ui.label(RichText::new(tr("No coding agent was found on this computer yet.")).color(t.text_dim));
+ }
+ // Agents on other computers (from `~/.ssh/config`) are offered without checking them, so
+ // they don't make the hints about this one any less true.
+ let hints = if found.iter().all(|b| b.ssh_host.as_deref().is_some_and(|h| !h.trim().is_empty())) { &app.detect_hints[..] } else { &[] };
+ for hint in hints {
match hint {
craft_anything_ai::detect::DetectHint::ClaudeDesktopWithoutCli { .. } => ui.add(
egui::Label::new(
diff --git a/crates/ui-egui/tests/smoke.rs b/crates/ui-egui/tests/smoke.rs
index f8bc2ae3..ccd14b68 100644
--- a/crates/ui-egui/tests/smoke.rs
+++ b/crates/ui-egui/tests/smoke.rs
@@ -2524,6 +2524,31 @@ fn only_the_claude_desktop_app_is_named_when_nothing_can_build() {
h.run_steps(2);
h.get_by_label("No coding agent was found on this computer yet.");
h.get_by_label("The Claude desktop app is installed, but building needs Claude Code, its separate command-line tool. Install Claude Code, sign in to it once in a terminal, then look again.");
+
+ // Agents suggested from `~/.ssh/config` aren't checked, so the hint stays (review of #781).
+ use craft_anything_ai::{BackendConfig, Detected};
+ let remote = |name: &str| Detected {
+ suggestion: BackendConfig {
+ name: name.into(),
+ kind: craft_anything_ai::BackendKind::AgentCli,
+ model: "claude-code".into(),
+ base_url: None,
+ ssh_host: Some("box".into()),
+ enabled: true,
+ },
+ reason: "From ~/.ssh/config".into(),
+ needs_key: false,
+ };
+ h.state_mut().detected = Some(vec![remote("Claude Code on box")]);
+ h.run_steps(2);
+ h.get_by_label("The Claude desktop app is installed, but building needs Claude Code, its separate command-line tool. Install Claude Code, sign in to it once in a terminal, then look again.");
+ // An agent found on this computer can build, so the hint goes.
+ let mut local = remote("Codex");
+ local.suggestion.ssh_host = None;
+ local.suggestion.model = "codex".into();
+ h.state_mut().detected = Some(vec![remote("Claude Code on box"), local]);
+ h.run_steps(2);
+ assert!(h.query_by_label("The Claude desktop app is installed, but building needs Claude Code, its separate command-line tool. Install Claude Code, sign in to it once in a terminal, then look again.").is_none());
}
#[test]
diff --git a/docs/ROADMAP.md b/docs/ROADMAP.md
index 416c8f6e..e35df549 100644
--- a/docs/ROADMAP.md
+++ b/docs/ROADMAP.md
@@ -144,6 +144,17 @@ cheapest help we can give anyone, so nothing below should hold it up for long.
skip hardware adapters; needs a different route (another renderer, or a helper that starts
the app with only WARP visible)
- [x] Add to `docs/releasing.md`: before publishing, a Deep build through Claude Code from the
+- [x] #794: on some systems DX12 refuses egui's own pipeline (`egui_pipeline`, 0x80070057 from
+ `CreatePipelineState`) on AMD, Intel and NVIDIA cards and on WARP too (lightcraft#812,
+ pdfcraft#1046, wgpu#10771), so the software retry failed the same way every start, and the
+ dialog only said to update the driver. Each failed start now moves on to the next renderer
+ (DX12 → WARP → Vulkan → GL, `apps/craft-anything/src/renderer.rs`), keeps the one that worked
+ for this app version, and starts again by itself after a wgpu error. Checked with a build
+ that failed every DX12 start; the real failure wasn't reproduced (STATUS.md)
+ — claimed: 00xJS, branch bugfix/r5.1-renderer-fallback
+- [ ] Live-check #794's fallback on a machine where DX12 refuses `egui_pipeline` (the reporter's
+ 780M, or lightcraft#812's)
+- [ ] Add to `docs/releasing.md`: before publishing, a Deep build through Claude Code from the
finished package, on a Mac and on Windows. Starting the CLI from the package (#91) doesn't
show whether Claude Code accepts its tools — PR #982; claimed: doubektomas,
branch docs/r5.1-packaged-deep-build-check. The checklist is documented; live package runs
@@ -680,6 +691,10 @@ Owner: open · Status: in progress
- [x] Say plainly when what's found is the Claude desktop app rather than the `claude` program
(#259, a guess at its cause)
- [ ] macOS: check that `Claude.app` is where the desktop app is found (#259's hint is untried there)
+- [x] #259's hint, the gaps left in review of #781: it's hidden when only `~/.ssh/config` suggestions are
+ found, a Store install without its `claude-desktop` alias isn't seen, and a desktop app's
+ `claude.exe` on PATH is taken for Claude Code (#824) — claimed: FuryNocturn, branch
+ bugfix/r2.2-claude-desktop-hint-gaps
- [x] macOS: `/Applications/Antigravity.app` ended up as the agent's command (#467). Found: the "Where is
the program?" picker (`pick_file`) returns the bundle, and `set_command` saved any path. Refuse a
folder or app bundle when it's saved (`set_command`), and don't run one that was saved before
diff --git a/docs/STATUS.md b/docs/STATUS.md
index a3c811e1..e48688b4 100644
--- a/docs/STATUS.md
+++ b/docs/STATUS.md
@@ -49,6 +49,8 @@ workspace clippy, layers, fmt and the secret scan of all history were clean. Chi
| OpenCode models and thinking | OpenCode V2 locally and over SSH; Settings → AI lists only that instance's enabled chat models and supported Low/Medium/High/Xhigh/Max variants. Selection is validated and saved through UI, CLI and `ai_models_list` / `ai_model_set`. Explicit selections run natively with the Craft Anything MCP server (local runs; none over SSH yet). See [OpenCode](opencode.md). | Stand-in catalogue/process, persistence, remote-command and UI tests; local live catalogue checks (34 models, all five depths represented). Regression checks route explicit selections natively and parse V2 tool events. Live (2026-11-04, Windows, OpenCode 2.2.5, opencode-go/deepseek-v4.1-flash): a `--standalone` run connected the server (38 tools) and called `core_session_show`. No live SSH host or paid generation used |
| Gemini tool calls | A tool call's `extra_content` (Gemini's thought signature) goes back with it unchanged, so Gemini 3 builders get past their first tool call; errors Gemini wraps in an array show their message (#978) | Unit-tested; not run against the live API |
| Claude desktop app without Claude Code | When the `claude` command isn't found but the Claude desktop app is (Windows: the Store package's `claude-desktop` app alias or the older installer's `AnthropicClaude` folder; macOS: `Claude.app`), the builder dialog under "No coding agent was found" and `ai detect` (on stderr) say the desktop app is installed but building needs Claude Code, installed apart (#259). Typed as `DetectHint` from `AiHub::detect_hints` | A regression finds the app in temp folders laid out as each Windows installer leaves it, and nothing on Linux; a UI test shows the hint in the dialog. On Windows 10 the real Store package's alias was found. Not checked: macOS, the older installer, and a computer with no `claude` installed |
+| OpenCode models and thinking | OpenCode V2 locally and over SSH; Settings → AI lists only that instance's enabled chat models and supported Low/Medium/High/Xhigh/Max variants. Selection is validated and saved through UI, CLI and `ai_models_list` / `ai_model_set`. Explicit-selection execution is refused until native MCP integration exists; local ACP runs require clearing the selection. See [OpenCode](opencode.md). | Stand-in catalogue/process, persistence, remote-command and UI tests; local live catalogue checks (34 models, all five depths represented). Regression checks reject native chat/builds before process I/O with ACP on/off, local/SSH and model-only/depth-only/combined selections. No live SSH host or paid generation used |
+| Claude desktop app without Claude Code | When the `claude` command isn't found but the Claude desktop app is (Windows: the Store package's `claude-desktop` app alias, else its package folder, or the older installer's `AnthropicClaude` folder; macOS: `Claude.app`), the builder dialog under "No coding agent was found" and `ai detect` (on stderr) say the desktop app is installed but building needs Claude Code, installed apart (#259). The hint stays when the only suggestions are unchecked agents from `~/.ssh/config`. A `claude` program inside the desktop app (on PATH) is never offered or started as Claude Code: detection, the hint and a run's program look through one `cli_agents::find_program`. Typed as `DetectHint` from `AiHub::detect_hints` | A regression finds the app in temp folders laid out as each Windows installer leaves it, and nothing on Linux; a UI test shows the hint in the dialog, with only SSH suggestions too, and not once an agent here is found; a test passes over the desktop app's `claude.exe` on a search path. On Windows 10 the real Store package's alias was found. Not checked: macOS, the older installer, and a computer with no `claude` installed |
| Missing program paths | A program started by its path (a saved agent program, for one) that has no file there is reported with that path, as possibly moved by an update, with reason `path_missing`, instead of "isn't installed or isn't on your PATH"; a bare name still speaks of PATH. A relative path is looked up where the program starts (on Unix, its working folder), so a script there whose interpreter is missing isn't called a path with no file. It stays a missing program (`EngineMissing`), so builder turns aren't retried (#721). `ai test` names the agent program it ran and the saved one it replaced (`program`, `saved_program_replaced`), and `doctor` says a saved path has no program there | `a_saved_program_that_is_gone_is_named_by_test_and_doctor` runs both with a removed path. A regression starts a program at a path with no file on Windows 10 and checks the message, remediation and reason, with a bare-name control; on Linux (Docker), a relative script with a missing interpreter started in its folder, through `Process` and `Launch`. Not checked: a real Codex desktop update, or the app's Settings screen with a stale path |
| npm agents without Node on Windows | Programs are also looked for in nvm for Windows' version folders (`NVM_HOME`, else `%APPDATA%\nvm`, newest first, after `PATH`), so an npm shim such as `claude.cmd` finds Node when no `nvm use` link exists. When a shim's interpreter is still missing, starting it fails with `EngineMissing`, reason `interpreter_missing`, naming `node` and `nvm use`, instead of Rust's "batch file arguments are invalid" | On Windows 10 (Rust 1.99.1): unit tests for version-folder listing with nvm's own files beside the versions, the missing-interpreter check (no Node, Node on the search path, Node beside the shim) and the error's fields; the existing shim tests, including a real multi-line prompt through Node, and the platform crate's 70 tests pass. The failure was seen with Craft Anything 0.4.0 (Claude Code 1.0.96 npm shim, nvm with no version in use). Not checked: the fixed desktop app or CLI on that machine, and a build through a shim found only in nvm's folders |
| Mach-O Objective-C pointers | Chained offsets mapped only into file-empty `__PAGEZERO` reach the image-base fallback; pointer candidates must be backed by file bytes | Synthetic thin and fat Mach-O regression, plain-pointer and authenticated-rebase controls, null and unmapped-pointer checks. Real binaries were not checked for this correction |
@@ -268,6 +270,20 @@ desktop no longer lags; `WGPU_POWER_PREF=high`, `WGPU_ADAPTER_NAME=nvidia` and `
`WGPU_POWER_PREF=none` still draw on NVIDIA. Desktops with monitors on one or two GPUs and Intel
laptops are covered by unit tests on fake `/sys/class/drm` folders only.
+### Windows renderer fallback
+
+On Windows the window draws with DX12 on the graphics card. A start that never opens its window
+(a driver that crashes the process, or a wgpu error such as DX12 refusing egui's pipeline, #794)
+makes the next start take the next renderer: WARP, then Vulkan, then OpenGL, then DX12 again. After a
+wgpu error the app starts again by itself with the next one; after a native crash the person starts it.
+The renderer that opened the window is kept in `renderer` beside `desktop.log` for this app version,
+so an update tries DX12 first again. `WGPU_BACKEND` and `CRAFT_ANYTHING_RENDERER` still decide when set.
+
+Checked live on an RX 6900 XT (Windows 11): a build that turned every DX12 start
+into #794's wgpu error went DX12 → WARP → Vulkan by itself in about 2 s, opened on Vulkan, kept it at the
+next start, and went back to DX12 for another app version. The real #794 failure wasn't reproduced:
+DX12 and WARP both draw on that machine.
+
## Known limits
- Locks: every mutex but the browser viewer's goes through `platform::sync`. A deadlock on one thread or across