In-app agent chat: your own coding agents over ACP, plus OpenAI-compatible endpoints (#1102)

* Agent chat prototype: drive an ACP agent the user already has from a side panel

A desktop-only chat panel (off by default) that starts a coding agent over the
Agent Client Protocol and gives it SolidCraft's MCP server, bridged to the open
window through the token-protected control channel with the default folder
limits. It finds installed agents (Claude Code and Codex adapters, Gemini CLI,
Copilot, Qwen, OpenCode, goose) with version and login state, streams text,
tool calls and plans, shows the agent's permission requests, and when an agent
isn't signed in shows its own login methods without handling any credential.

Design notes and findings: docs/design/in-app-agent-chat.md.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* docs: say only what the end-to-end run showed

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Agent chat: gate, one undo per message, docking, process groups, discovery polish

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Agent chat: Settings → AI, several agents with a switcher, OpenAI-compatible endpoints, permission modes, toolbar button

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Agent chat: translations, tool cards, Add agent dialog fixes, test agent saves on its own

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Agent chat: third-party licences for the keychain crates; clippy

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Agent chat: badge text from the theme tokens

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Agent chat: Auto-allow model edits is the default permission mode

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
bherbruckandClaude Opus 5.5 authored and GitHub committed 2026-10-15 14:22:38 -04:00
1 parent 02fe495d38
commit 2d069ca186
36 files changed
+8078 -303

No files matched your search

+316
View File
@@ -0,0 +1,316 @@
//! Which ACP agents are installed here (desktop only). A desktop app often starts without the
//! shell's PATH, so the usual install folders are searched too. Detection never starts a login
//! or a session: each agent found is asked for `--version` (with a time limit), and whether it
//! looks logged in comes only from whether its own credentials file exists.
use std::path::{Path, PathBuf};
use std::process::{Command, Stdio};
use std::time::{Duration, Instant};
/// An agent SolidCraft knows how to start in ACP mode.
pub struct Known {
pub id: &'static str,
pub name: &'static str,
/// Program names to look for, in order of preference.
pub programs: &'static [&'static str],
/// Arguments that put it in ACP mode.
pub args: &'static [&'static str],
/// Its one-line install hint.
pub install: &'static str,
/// Its own credentials file, relative to the home folder (`None`: can't tell), and the
/// variable that moves its settings folder (`CLAUDE_CONFIG_DIR`, `CODEX_HOME`) with the file's
/// name inside it.
pub credentials: Option<&'static str>,
pub config_dir_var: Option<(&'static str, &'static str)>,
/// Variables holding a key it uses instead of a login.
pub key_vars: &'static [&'static str],
}
/// The agents shown in the picker. The first one found is the default.
pub const KNOWN: &[Known] = &[
Known {
id: "claude",
name: "Claude Code",
programs: &["claude-agent-acp", "claude-code-acp"],
args: &[],
install: "npm install -g @agentclientprotocol/claude-agent-acp",
credentials: Some(".claude/.credentials.json"),
config_dir_var: Some(("CLAUDE_CONFIG_DIR", ".credentials.json")),
key_vars: &["ANTHROPIC_API_KEY"],
},
Known {
id: "codex",
name: "Codex",
programs: &["codex-acp"],
args: &[],
install: "npm install -g @agentclientprotocol/codex-acp",
credentials: Some(".codex/auth.json"),
config_dir_var: Some(("CODEX_HOME", "auth.json")),
key_vars: &["OPENAI_API_KEY", "CODEX_API_KEY"],
},
Known {
id: "gemini",
name: "Gemini CLI",
programs: &["gemini"],
args: &["--acp"],
install: "npm install -g @google/gemini-cli",
credentials: Some(".gemini/oauth_creds.json"),
config_dir_var: None,
key_vars: &["GEMINI_API_KEY", "GOOGLE_API_KEY"],
},
Known {
id: "opencode",
name: "OpenCode",
programs: &["opencode"],
args: &["acp"],
install: "npm install -g opencode-ai",
credentials: Some(".local/share/opencode/auth.json"),
config_dir_var: None,
key_vars: &[],
},
Known {
id: "copilot",
name: "GitHub Copilot CLI",
programs: &["copilot"],
args: &["--acp"],
install: "npm install -g @github/copilot",
credentials: None,
config_dir_var: None,
key_vars: &["GH_TOKEN", "GITHUB_TOKEN"],
},
Known {
id: "qwen",
name: "Qwen Code",
programs: &["qwen"],
args: &["--acp"],
install: "npm install -g @qwen-code/qwen-code",
credentials: Some(".qwen/oauth_creds.json"),
config_dir_var: None,
key_vars: &["DASHSCOPE_API_KEY"],
},
Known {
id: "goose",
name: "goose",
programs: &["goose"],
args: &["acp"],
install: "see block.github.io/goose (installer script or Homebrew)",
credentials: None,
config_dir_var: None,
key_vars: &[],
},
];
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum Login {
/// Its credentials file is there.
LooksLoggedIn,
/// No login file, but one of its key variables is set.
KeyInEnvironment,
/// Its credentials file is missing (it may still use a key from the environment).
NotLoggedIn,
/// It keeps no file we can look at (system keychain, or unknown).
Unknown,
}
impl Login {
pub fn id(self) -> &'static str {
match self {
Login::LooksLoggedIn => "signed_in",
Login::KeyInEnvironment => "key",
Login::NotLoggedIn => "signed_out",
Login::Unknown => "unknown",
}
}
}
/// A known agent that isn't installed, with its one-line install hint.
#[derive(Clone, Debug)]
pub struct Missing {
pub id: &'static str,
pub name: &'static str,
pub install: &'static str,
}
#[derive(Clone, Debug)]
pub struct Found {
pub id: &'static str,
pub name: &'static str,
/// The full command: the program's path and its ACP arguments.
pub argv: Vec<String>,
pub version: Option<String>,
pub login: Login,
}
#[derive(Clone, Debug, Default)]
pub struct Detection {
pub found: Vec<Found>,
/// Known agents not found.
pub missing: Vec<Missing>,
pub took_ms: u64,
}
fn home() -> Option<PathBuf> {
std::env::var_os(if cfg!(windows) { "USERPROFILE" } else { "HOME" }).map(PathBuf::from).filter(|p| p.is_absolute())
}
/// PATH, then the usual places npm, Homebrew, nvm, Volta, bun and pipx put commands.
pub fn search_dirs() -> Vec<PathBuf> {
let mut dirs: Vec<PathBuf> = std::env::var_os("PATH").map(|p| std::env::split_paths(&p).collect()).unwrap_or_default();
if let Some(prefix) = std::env::var_os("NPM_CONFIG_PREFIX").map(PathBuf::from) {
dirs.push(if cfg!(windows) { prefix.clone() } else { prefix.join("bin") });
}
if let Some(h) = home() {
for d in [".local/bin", ".npm-global/bin", ".npm-packages/bin", ".volta/bin", ".bun/bin", ".cargo/bin", "bin"] {
dirs.push(h.join(d));
}
// nvm: every installed Node version's bin.
if let Ok(rd) = std::fs::read_dir(h.join(".nvm/versions/node")) {
let mut v: Vec<PathBuf> = rd.flatten().take(64).map(|e| e.path().join("bin")).collect();
v.sort();
dirs.extend(v.into_iter().rev());
}
}
if cfg!(windows) {
if let Some(a) = std::env::var_os("APPDATA") {
dirs.push(PathBuf::from(a).join("npm"));
}
} else {
for d in ["/opt/homebrew/bin", "/usr/local/bin", "/home/linuxbrew/.linuxbrew/bin", "/usr/bin"] {
dirs.push(PathBuf::from(d));
}
}
let mut seen = std::collections::HashSet::new();
dirs.retain(|d| d.is_absolute() && seen.insert(d.clone()));
dirs
}
/// The first `program` in `dirs` (on Windows also with `.exe`/`.cmd`).
pub fn find_in(program: &str, dirs: &[PathBuf]) -> Option<PathBuf> {
let names: Vec<String> =
if cfg!(windows) { ["", ".exe", ".cmd", ".bat"].iter().map(|e| format!("{program}{e}")).collect() } else { vec![program.to_string()] };
dirs.iter().flat_map(|d| names.iter().map(move |n| d.join(n))).find(|p| p.is_file())
}
/// `program --version`'s first line, or `None` after `limit` (the probe is then stopped).
fn version(program: &Path, limit: Duration) -> Option<String> {
let mut cmd = if cfg!(windows) && program.extension().is_some_and(|e| e.eq_ignore_ascii_case("cmd") || e.eq_ignore_ascii_case("bat")) {
let mut c = Command::new("cmd");
c.arg("/C").arg(program);
c
} else {
Command::new(program)
};
let mut child = cmd.arg("--version").stdin(Stdio::null()).stdout(Stdio::piped()).stderr(Stdio::null()).spawn().ok()?;
let start = Instant::now();
loop {
match child.try_wait() {
Ok(Some(_)) => break,
Ok(None) if start.elapsed() < limit => std::thread::sleep(Duration::from_millis(20)),
_ => {
let _ = child.kill();
let _ = child.wait();
return None;
}
}
}
let mut out = String::new();
std::io::Read::read_to_string(&mut child.stdout.take()?, &mut out).ok()?;
let line = out.lines().map(str::trim).find(|l| !l.is_empty())?;
Some(version_of(line))
}
/// The version number in a `--version` line (`codex-cli 0.162.1`, `2.1.295 (Claude Code)`,
/// `@scope/pkg 2.2.2`), else the line itself, cut short.
fn version_of(line: &str) -> String {
let v = line.split_whitespace().find(|w| w.trim_start_matches('v').starts_with(|c: char| c.is_ascii_digit())).unwrap_or(line);
v.chars().take(40).collect()
}
/// Whether `k` looks signed in, from files and variables only: nothing is started or asked.
fn login_of(k: &Known, home: Option<&Path>) -> Login {
let file = match k.config_dir_var.and_then(|(var, name)| std::env::var_os(var).filter(|v| !v.is_empty()).map(|d| PathBuf::from(d).join(name))) {
Some(p) => Some(p),
None => k.credentials.zip(home).map(|(rel, h)| h.join(rel)),
};
let key = || k.key_vars.iter().any(|v| std::env::var_os(v).is_some_and(|x| !x.is_empty()));
match file {
Some(f) if f.is_file() => Login::LooksLoggedIn,
_ if key() => Login::KeyInEnvironment,
// Claude Code keeps its login in the keychain on macOS: the file says nothing there.
_ if cfg!(target_os = "macos") && k.id == "claude" => Login::Unknown,
Some(_) => Login::NotLoggedIn,
None => Login::Unknown,
}
}
/// Look for every known agent. Blocking (each probe has a time limit): run it off the UI thread.
pub fn detect() -> Detection {
let t0 = Instant::now();
let dirs = search_dirs();
let home = home();
let mut d = Detection::default();
for k in KNOWN {
let Some(path) = k.programs.iter().find_map(|p| find_in(p, &dirs)) else {
d.missing.push(Missing { id: k.id, name: k.name, install: k.install });
continue;
};
let login = login_of(k, home.as_deref());
let mut argv = vec![path.to_string_lossy().into_owned()];
argv.extend(k.args.iter().map(|a| a.to_string()));
d.found.push(Found { id: k.id, name: k.name, version: version(&path, Duration::from_secs(3)), argv, login });
}
d.took_ms = u64::try_from(t0.elapsed().as_millis()).unwrap_or(u64::MAX);
d
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn a_program_is_found_in_the_first_folder_that_has_it() {
let root = std::env::temp_dir().join(format!("sc-agent-find-{}", std::process::id()));
let (a, b) = (root.join("a"), root.join("b"));
std::fs::create_dir_all(&a).unwrap();
std::fs::create_dir_all(&b).unwrap();
std::fs::write(b.join("codex-acp"), "").unwrap();
assert_eq!(find_in("codex-acp", &[a.clone(), b.clone()]), Some(b.join("codex-acp")));
assert_eq!(find_in("gemini", &[a, b]), None);
let _ = std::fs::remove_dir_all(root);
}
#[test]
fn the_version_number_is_picked_out_of_the_line() {
assert_eq!(version_of("@agentclientprotocol/codex-acp 2.2.2"), "2.2.2");
assert_eq!(version_of("2.1.295 (Claude Code)"), "2.1.295");
assert_eq!(version_of("goose v1.9.0"), "v1.9.0");
assert_eq!(version_of("dev build"), "dev build");
}
#[test]
fn signed_in_comes_from_the_agents_own_file_or_a_key_variable() {
let home = std::env::temp_dir().join(format!("sc-agent-login-{}", std::process::id()));
std::fs::create_dir_all(home.join(".gemini")).unwrap();
let gemini = KNOWN.iter().find(|k| k.id == "gemini").unwrap();
let qwen = KNOWN.iter().find(|k| k.id == "qwen").unwrap();
let goose = KNOWN.iter().find(|k| k.id == "goose").unwrap();
if std::env::var_os("GEMINI_API_KEY").is_none() && std::env::var_os("GOOGLE_API_KEY").is_none() {
assert_eq!(login_of(gemini, Some(&home)), Login::NotLoggedIn);
}
std::fs::write(home.join(".gemini/oauth_creds.json"), "{}").unwrap();
assert_eq!(login_of(gemini, Some(&home)), Login::LooksLoggedIn);
if std::env::var_os("DASHSCOPE_API_KEY").is_none() {
assert_eq!(login_of(qwen, Some(&home)), Login::NotLoggedIn);
}
assert_eq!(login_of(goose, Some(&home)), Login::Unknown, "keeps no file we know");
let _ = std::fs::remove_dir_all(home);
}
#[test]
fn every_known_agent_has_a_program_and_an_install_hint() {
for k in KNOWN {
assert!(!k.programs.is_empty() && !k.install.is_empty(), "{}", k.id);
}
assert_eq!(KNOWN.first().map(|k| k.id), Some("claude"), "the Claude Code adapter is the default");
}
}