Skip to content

SolidCraft: an open-source parametric 3D CAD application built in pure Rust. Desktop, web, and automation through MCP.

AI Preferences: reflect agent authentication results (#2578) (#4253)

Colin Faulkinghamb55f30959d27
diff --git a/assets/locales/pending/agent-login-status.json b/assets/locales/pending/agent-login-status.json
new file mode 100644
index 0000000000..899784a8ed
--- /dev/null
+++ b/assets/locales/pending/agent-login-status.json
@@ -0,0 +1,11 @@
+{
+ "en": {
+ "ui.agent_chat_login_found": "login found"
+ },
+ "ja": {
+ "ui.agent_chat_login_found": "ログイン情報あり"
+ },
+ "zh": {
+ "ui.agent_chat_login_found": "已找到登录信息"
+ }
+}
diff --git a/crates/ui-egui/src/agent_chat/acp_client.rs b/crates/ui-egui/src/agent_chat/acp_client.rs
index 730c0cf0cc..bf1e37e5f8 100644
--- a/crates/ui-egui/src/agent_chat/acp_client.rs
+++ b/crates/ui-egui/src/agent_chat/acp_client.rs
@@ -7,7 +7,7 @@ use std::collections::HashMap;
use serde_json::{Value, json};
use super::acp::{self, Incoming};
-use super::backend::{ChatBackend, Event, PromptPart, StartContext};
+use super::backend::{ChatBackend, Event, PromptPart, StartContext, TestError};
use super::process::{AgentProcess, FromAgent};
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
@@ -231,10 +231,10 @@ impl ChatBackend for AcpBackend {
/// Test connection: start the agent, say hello, open a session without tools, end it. What it
/// answered (its name and version), or what went wrong (it isn't signed in, it didn't answer).
-pub fn test_agent(argv: &[String], cwd: &std::path::Path) -> Result<String, String> {
- let mut p = AgentProcess::spawn(argv, cwd, ENV_REMOVE, || {})?;
+pub fn test_agent(argv: &[String], cwd: &std::path::Path) -> Result<String, TestError> {
+ let mut p = AgentProcess::spawn(argv, cwd, ENV_REMOVE, || {}).map_err(TestError::Other)?;
let deadline = std::time::Instant::now() + std::time::Duration::from_secs(20);
- let wait_for = |p: &AgentProcess, id: u64| -> Result<Value, String> {
+ let wait_for = |p: &AgentProcess, id: u64| -> Result<Value, TestError> {
loop {
let left = deadline.saturating_duration_since(std::time::Instant::now());
match p.from_agent.recv_timeout(left) {
@@ -244,17 +244,17 @@ pub fn test_agent(argv: &[String], cwd: &std::path::Path) -> Result<String, Stri
{
return result.map_err(|(code, m)| {
if code == acp::AUTH_REQUIRED || m.to_ascii_lowercase().contains("auth") {
- crate::i18n::tr("ui.agent_chat_state_auth").to_string()
+ TestError::AuthRequired
} else {
- m
+ TestError::Other(m)
}
});
}
}
Ok(FromAgent::Exited(tail)) => {
- return Err(tail.last().cloned().unwrap_or_else(|| crate::i18n::tr("ui.agent_chat_exited").to_string()));
+ return Err(TestError::Other(tail.last().cloned().unwrap_or_else(|| crate::i18n::tr("ui.agent_chat_exited").to_string())));
}
- Err(_) => return Err(crate::i18n::tr("ui.ai_no_answer").to_string()),
+ Err(_) => return Err(TestError::Other(crate::i18n::tr("ui.ai_no_answer").to_string())),
}
}
};
diff --git a/crates/ui-egui/src/agent_chat/agents.rs b/crates/ui-egui/src/agent_chat/agents.rs
index 8d989a9084..f0c813d4cf 100644
--- a/crates/ui-egui/src/agent_chat/agents.rs
+++ b/crates/ui-egui/src/agent_chat/agents.rs
@@ -157,7 +157,8 @@ pub struct Entry {
/// ACP: what to start.
pub argv: Vec<String>,
pub version: Option<String>,
- /// `signed_in`, `key`, `signed_out`, `unknown` (found agents), or empty.
+ /// `login_found`, `key`, `signed_out`, `unknown` from discovery, `signed_in` after a
+ /// successful connection, or empty for an untested custom agent.
pub login: &'static str,
/// Found installed (not added by the user).
pub found: bool,
@@ -216,6 +217,13 @@ pub fn entries(app: &crate::SolveApp) -> Vec<Entry> {
}));
}
out.extend(app.preferences.agents.iter().map(Entry::from_config));
+ for entry in &mut out {
+ if entry.kind == Kind::Acp
+ && let Some(signed_in) = app.agent_chat.login_results.get(&entry.id)
+ {
+ entry.login = if *signed_in { "signed_in" } else { "signed_out" };
+ }
+ }
out
}
diff --git a/crates/ui-egui/src/agent_chat/backend.rs b/crates/ui-egui/src/agent_chat/backend.rs
index 7a4b3ac3e2..b74d33cbe3 100644
--- a/crates/ui-egui/src/agent_chat/backend.rs
+++ b/crates/ui-egui/src/agent_chat/backend.rs
@@ -10,6 +10,22 @@ use serde_json::Value;
pub use super::acp::{AuthMethod, PermissionOption, ToolStatus};
+/// A connection test keeps authentication failures distinct from transport or protocol errors.
+#[derive(Clone, Debug, PartialEq, Eq)]
+pub enum TestError {
+ AuthRequired,
+ Other(String),
+}
+
+impl TestError {
+ pub fn message(&self) -> &str {
+ match self {
+ Self::AuthRequired => crate::i18n::tr("ui.agent_chat_state_auth"),
+ Self::Other(message) => message,
+ }
+ }
+}
+
/// One part of a message to the agent.
#[derive(Clone, Debug, PartialEq)]
pub enum PromptPart {
diff --git a/crates/ui-egui/src/agent_chat/discover.rs b/crates/ui-egui/src/agent_chat/discover.rs
index 0fd03560a9..cf9490f1e8 100644
--- a/crates/ui-egui/src/agent_chat/discover.rs
+++ b/crates/ui-egui/src/agent_chat/discover.rs
@@ -162,7 +162,7 @@ pub enum Login {
impl Login {
pub fn id(self) -> &'static str {
match self {
- Login::LooksLoggedIn => "signed_in",
+ Login::LooksLoggedIn => "login_found",
Login::KeyInEnvironment => "key",
Login::NotLoggedIn => "signed_out",
Login::Unknown => "unknown",
diff --git a/crates/ui-egui/src/agent_chat/mod.rs b/crates/ui-egui/src/agent_chat/mod.rs
index 144bb2b5e7..8648874c45 100644
--- a/crates/ui-egui/src/agent_chat/mod.rs
+++ b/crates/ui-egui/src/agent_chat/mod.rs
@@ -405,6 +405,8 @@ pub struct AgentChat {
tools_tx: Option<Sender<ControlRequest>>,
/// Settings → AI: the Add agent dialog and connection tests.
pub settings: settings::State,
+ /// Latest authentication evidence from a connection test or a chat, per agent; never saved.
+ login_results: std::collections::HashMap<String, bool>,
/// Desktop host hook: start the endpoint on demand.
pub control_starter: Option<ControlStarter>,
/// The picker is unfolded (it folds to one line once an agent is connected).
@@ -569,6 +571,18 @@ impl AgentChat {
/// Take in what the backend reported.
fn on_event(&mut self, e: Event) -> Option<Outcome> {
+ let signed_in = match &e {
+ Event::Ready { .. } => Some(true),
+ Event::AuthRequired { .. } => Some(false),
+ _ => None,
+ };
+ if let Some(signed_in) = signed_in
+ && !self.running_id.is_empty()
+ {
+ self.login_results.insert(self.running_id.clone(), signed_in);
+ // A newer chat result supersedes the old test, including one still in flight.
+ self.settings.tests.remove(&self.running_id);
+ }
match e {
Event::Documents(documents) => self.documents = documents,
Event::ToolsAvailable(available) => self.tools_available = Some(available),
@@ -1630,10 +1644,15 @@ pub(crate) fn take_loaded(app: &mut SolveApp, ctx: &egui::Context) {
}
pub fn poll(app: &mut SolveApp, ctx: &egui::Context) {
+ settings::poll_tests(&mut app.agent_chat);
#[cfg(not(target_arch = "wasm32"))]
if let Some(rx) = &app.agent_chat.detecting
&& let Ok(d) = rx.try_recv()
{
+ for found in &d.found {
+ app.agent_chat.login_results.remove(found.id);
+ app.agent_chat.settings.tests.remove(found.id);
+ }
app.agent_chat.detection = Some(d);
app.agent_chat.detecting = None;
}
diff --git a/crates/ui-egui/src/agent_chat/settings.rs b/crates/ui-egui/src/agent_chat/settings.rs
index 12cc04a089..659ba261cd 100644
--- a/crates/ui-egui/src/agent_chat/settings.rs
+++ b/crates/ui-egui/src/agent_chat/settings.rs
@@ -4,6 +4,7 @@
//! endpoint (OpenAI-compatible or Anthropic-compatible, whose key goes to the system keychain).
use super::agents::{self, AgentConfig, Kind, Mode, Protocol};
+use super::backend::TestError;
use super::*;
use crate::ui_kit;
@@ -35,16 +36,31 @@ pub struct AddState {
/// A connection test running or done.
pub enum Test {
- Running(std::sync::mpsc::Receiver<Result<String, String>>),
- Done(Result<String, String>),
+ Running(std::sync::mpsc::Receiver<Result<String, TestError>>),
+ Done(Result<String, TestError>),
}
impl Test {
- fn poll(&mut self) {
+ fn poll(&mut self) -> Option<bool> {
if let Test::Running(rx) = self
&& let Ok(r) = rx.try_recv()
{
+ let login = match &r {
+ Ok(_) => Some(true),
+ Err(TestError::AuthRequired) => Some(false),
+ Err(TestError::Other(_)) => None,
+ };
*self = Test::Done(r);
+ return login;
+ }
+ None
+ }
+}
+
+pub(super) fn poll_tests(chat: &mut AgentChat) {
+ for (id, test) in &mut chat.settings.tests {
+ if let Some(signed_in) = test.poll() {
+ chat.login_results.insert(id.clone(), signed_in);
}
}
}
@@ -180,17 +196,17 @@ fn start_test(app: &SolveApp, e: &agents::Entry, key: Option<String>) -> Test {
});
}
Kind::Api => {
- let Some(http) = app.services.agent_http.clone() else { return Test::Done(Err(tr("ui.ai_no_http").to_string())) };
+ let Some(http) = app.services.agent_http.clone() else { return Test::Done(Err(TestError::Other(tr("ui.ai_no_http").to_string()))) };
let (url, model) = (e.base_url.clone(), e.model.clone());
std::thread::spawn(move || {
- let _ = tx.send(super::api_client::test_endpoint(&http, &url, key.as_deref(), &model));
+ let _ = tx.send(super::api_client::test_endpoint(&http, &url, key.as_deref(), &model).map_err(TestError::Other));
});
}
Kind::Anthropic => {
- let Some(http) = app.services.agent_http.clone() else { return Test::Done(Err(tr("ui.ai_no_http").to_string())) };
+ let Some(http) = app.services.agent_http.clone() else { return Test::Done(Err(TestError::Other(tr("ui.ai_no_http").to_string()))) };
let (url, model) = (e.base_url.clone(), e.model.clone());
std::thread::spawn(move || {
- let _ = tx.send(super::api_client::test_anthropic_endpoint(&http, &url, key.as_deref(), &model));
+ let _ = tx.send(super::api_client::test_anthropic_endpoint(&http, &url, key.as_deref(), &model).map_err(TestError::Other));
});
}
}
@@ -214,7 +230,7 @@ fn test_line(ui: &mut egui::Ui, test: &Option<&Test>) {
ui_kit::text(ui, message, ui_kit::Text::Report("test_ok", false));
}
Some(Test::Done(Err(error))) => {
- ui_kit::text(ui, error, ui_kit::Text::Report("test_error", true));
+ ui_kit::text(ui, error.message(), ui_kit::Text::Report("test_error", true));
}
None => {}
}
@@ -376,9 +392,6 @@ fn pointer_section(app: &mut SolveApp, ui: &mut egui::Ui) {
/// The agents: found and added, with Test, Default, a permission override and Remove.
#[cfg(not(target_arch = "wasm32"))]
fn agents_section(app: &mut SolveApp, ui: &mut egui::Ui) {
- for test in app.agent_chat.settings.tests.values_mut() {
- test.poll();
- }
let all = agents::entries(app);
let d = &app.preferences.agent_default;
let default = if all.iter().any(|e| &e.id == d) { Some(d.clone()) } else { all.first().map(|e| e.id.clone()) };
@@ -427,6 +440,7 @@ fn agents_section(app: &mut SolveApp, ui: &mut egui::Ui) {
remove = Some(entry.id.clone());
}
match entry.login {
+ "login_found" => ui_kit::settings_badge(ui, tr("ui.agent_chat_login_found"), false),
"signed_in" => ui_kit::settings_badge(ui, tr("ui.agent_chat_signed_in"), false),
"key" => ui_kit::settings_badge(ui, tr("ui.agent_chat_key_in_env"), false),
"signed_out" => ui_kit::settings_badge(ui, tr("ui.agent_chat_not_signed_in"), true),
@@ -510,6 +524,8 @@ fn agents_section(app: &mut SolveApp, ui: &mut egui::Ui) {
b.set_request_timeout(secs);
}
if let Some(id) = remove {
+ app.agent_chat.login_results.remove(&id);
+ app.agent_chat.settings.tests.remove(&id);
app.preferences.agents.retain(|a| a.id != id);
app.preferences.agent_permissions.remove(&id);
app.preferences.agent_always_allow.remove(&id);
@@ -545,7 +561,7 @@ pub fn dialog(app: &mut SolveApp, ctx: &egui::Context) {
.show(ctx, true, |ui| {
let Some(s) = app.agent_chat.settings.add.as_mut() else { return };
if let Some(test) = s.test.as_mut() {
- test.poll();
+ let _ = test.poll();
}
let kinds = [(AddKind::Installed, "ui.ai_add_installed"), (AddKind::Custom, "ui.ai_add_custom"), (AddKind::Api, "ui.ai_add_endpoint")];
ui_kit::row(ui, tr("ui.ai_kind"), |ui| {
@@ -688,7 +704,7 @@ pub fn dialog(app: &mut SolveApp, ctx: &egui::Context) {
let key = Some(s.key.trim().to_string()).filter(|k| !k.is_empty());
let result = match url {
Ok(_) => start_test(app, &e, key),
- Err(err) => Test::Done(Err(err)),
+ Err(err) => Test::Done(Err(TestError::Other(err))),
};
if let Some(s) = app.agent_chat.settings.add.as_mut() {
s.test = Some(result);
diff --git a/crates/ui-egui/src/agent_chat/tests.rs b/crates/ui-egui/src/agent_chat/tests.rs
index 6338f6c3d5..3c84e2421f 100644
--- a/crates/ui-egui/src/agent_chat/tests.rs
+++ b/crates/ui-egui/src/agent_chat/tests.rs
@@ -7,6 +7,97 @@ fn chat() -> AgentChat {
c
}
+#[cfg(not(target_arch = "wasm32"))]
+fn app_with_discovered_login() -> SolveApp {
+ let mut app = SolveApp::new(solidcraft_engine::Session::default(), crate::Services::default());
+ app.agent_chat.detection = Some(discover::Detection {
+ found: vec![discover::Found {
+ id: "qwen",
+ name: "Qwen Code",
+ argv: vec!["qwen".into(), "--acp".into()],
+ version: None,
+ login: discover::Login::LooksLoggedIn,
+ }],
+ ..Default::default()
+ });
+ app.agent_chat.running_id = "qwen".into();
+ app
+}
+
+#[cfg(not(target_arch = "wasm32"))]
+#[test]
+fn agent_login_file_does_not_claim_a_verified_sign_in() {
+ let app = app_with_discovered_login();
+ assert_eq!(agents::current(&app).unwrap().login, "login_found");
+}
+
+#[cfg(not(target_arch = "wasm32"))]
+#[test]
+fn agent_login_follows_chat_authentication_results() {
+ let mut app = app_with_discovered_login();
+ app.preferences.agents.push(agents::AgentConfig { id: "other".into(), name: "Other agent".into(), ..Default::default() });
+ app.agent_chat.on_event(Event::AuthRequired { methods: vec![] });
+ assert_eq!(agents::current(&app).unwrap().login, "signed_out");
+ assert_eq!(agents::entries(&app).iter().find(|e| e.id == "other").unwrap().login, "");
+ app.agent_chat.settings.tests.insert("qwen".into(), settings::Test::Done(Err(backend::TestError::AuthRequired)));
+ app.agent_chat.on_event(Event::Ready { agent: "Qwen Code".into(), images: false });
+ assert_eq!(agents::current(&app).unwrap().login, "signed_in");
+ assert!(!app.agent_chat.settings.tests.contains_key("qwen"), "a newer chat clears the stale test error");
+ app.agent_chat.on_event(Event::AuthRequired { methods: vec![] });
+ assert_eq!(agents::current(&app).unwrap().login, "signed_out");
+}
+
+#[cfg(unix)]
+#[test]
+fn agent_login_test_results_override_discovery() {
+ // A real local ACP subprocess: initialize succeeds, session/new rejects the expired login.
+ let script = r#"
+read -r initialize
+printf '%s\n' '{"jsonrpc":"2.0","id":1,"result":{"protocolVersion":1,"agentInfo":{"name":"fake","version":"1"}}}'
+read -r session
+printf '%s\n' '{"jsonrpc":"2.0","id":2,"error":{"code":-32000,"message":"credentials expired"}}'
+while IFS= read -r line; do :; done
+"#;
+ let argv = vec!["sh".into(), "-c".into(), script.into()];
+ let result = acp_client::test_agent(&argv, &std::env::temp_dir());
+ assert_eq!(result, Err(backend::TestError::AuthRequired), "keep the protocol error, not translated text");
+ let mut app = app_with_discovered_login();
+ let complete = |app: &mut SolveApp, result| {
+ let (tx, rx) = channel();
+ app.agent_chat.settings.tests.insert("qwen".into(), settings::Test::Running(rx));
+ tx.send(result).unwrap();
+ frame(app);
+ };
+ complete(&mut app, result);
+ assert_eq!(agents::current(&app).unwrap().login, "signed_out");
+ complete(&mut app, Err(backend::TestError::Other("connection failed".into())));
+ assert_eq!(agents::current(&app).unwrap().login, "signed_out", "transport errors aren't login evidence");
+ let success = script.replace(r#""error":{"code":-32000,"message":"credentials expired"}"#, r#""result":{"sessionId":"test"}"#);
+ let result = acp_client::test_agent(&["sh".into(), "-c".into(), success], &std::env::temp_dir());
+ assert!(result.is_ok(), "{result:?}");
+ complete(&mut app, result);
+ assert_eq!(agents::current(&app).unwrap().login, "signed_in");
+ complete(&mut app, Err(backend::TestError::Other("connection failed".into())));
+ assert_eq!(agents::current(&app).unwrap().login, "signed_in");
+ app.agent_chat.on_event(Event::AuthRequired { methods: vec![] });
+ frame(&mut app);
+ assert_eq!(agents::current(&app).unwrap().login, "signed_out", "an old test cannot overwrite newer chat evidence");
+}
+
+#[cfg(not(target_arch = "wasm32"))]
+#[test]
+fn agent_login_refresh_returns_to_unverified_discovery() {
+ let mut app = app_with_discovered_login();
+ app.agent_chat.on_event(Event::AuthRequired { methods: vec![] });
+ app.agent_chat.settings.tests.insert("qwen".into(), settings::Test::Done(Err(backend::TestError::AuthRequired)));
+ let (tx, rx) = channel();
+ app.agent_chat.detecting = Some(rx);
+ tx.send(app.agent_chat.detection.clone().unwrap()).unwrap();
+ frame(&mut app);
+ assert_eq!(agents::current(&app).unwrap().login, "login_found");
+ assert!(!app.agent_chat.settings.tests.contains_key("qwen"));
+}
+
#[test]
fn streamed_text_joins_and_tool_updates_change_their_call() {
let mut c = chat();
diff --git a/docs/agent-chat.md b/docs/agent-chat.md
index 6cf8b06ebb..de99380ac3 100644
--- a/docs/agent-chat.md
+++ b/docs/agent-chat.md
@@ -144,14 +144,18 @@ conversation starts with), its own permission setting, and **Remove** for the on
SolidCraft looks for agents that speak the [Agent Client Protocol](https://agentclientprotocol.com)
on your `PATH` and in the usual install folders a desktop app's `PATH` often misses (npm's
global folder, nvm, Volta, bun, `~/.local/bin`, `~/.grok/bin`, Homebrew, `%APPDATA%\npm`). For each one it
-shows its **version** (from `--version`, given three seconds) and whether it looks **signed in**.
+shows its **version** (from `--version`, given three seconds) and whether a **login was found**.
Version checks and agent sessions also use those folders on their `PATH`, so adapters can find
runtimes such as Node when SolidCraft is opened from Finder or the Dock. Existing absolute
`PATH` entries keep their order; no shell startup files are run.
SolidCraft only checks whether the agent's own login file (`~/.claude/.credentials.json`,
`~/.codex/auth.json`, `~/.gemini/oauth_creds.json`, …) or one of its key variables exists. It never
reads the file and never starts the agent to find out. On macOS Claude Code keeps its login in
-the keychain, so SolidCraft doesn't guess there.
+the keychain, so SolidCraft doesn't guess there. A found login file may be expired: **Test** or a
+chat connection verifies it. A successful ACP connection shows **signed in**; an authentication
+rejection shows **not signed in**. These results apply to that agent until a newer connection
+result or **Refresh**, which checks the installed agents again. An unrelated connection error
+doesn't change the last known login state.
| Agent | What to install |
|---|---|