Ask the login shell for PATH first, then its interactive config only if a tool is missing

AI Assisted
This commit is contained in:
Seth committed 2026-12-05 00:10:44 -08:00
1 parent 8c028c1ce0
commit b629f5ef04
3 files changed
+1172 -72

No files matched your search

+53
View File
@@ -1150,6 +1150,34 @@ pub fn custom_agents() -> (Vec<CustomAgent>, Vec<String>) {
.unwrap_or_default() .unwrap_or_default()
} }
/// The command of every built-in and custom agent that the lookup searches
/// PATH for by name, each once, in list order. A command with a folder in it
/// runs from there, whatever PATH holds, so it is left out. The PATH lookup at
/// start (`node_check::login_shell_path`) reads the shell's interactive config
/// when none of these is on the login PATH.
#[cfg(unix)]
pub fn path_agent_commands() -> Vec<String> {
let (custom, _) = custom_agents();
path_commands(
builtin_entries()
.iter()
.map(|entry| entry.command.as_str())
.chain(custom.iter().map(|agent| agent.command.as_str())),
)
}
/// `path_agent_commands` over the given commands.
#[cfg(unix)]
fn path_commands<'a>(commands: impl Iterator<Item = &'a str>) -> Vec<String> {
let mut seen = HashSet::new();
commands
.map(clean_command)
.filter(|command| !command.is_empty() && !has_separator(command, false))
.filter(|command| seen.insert(*command))
.map(str::to_string)
.collect()
}
fn clean_command(command: &str) -> &str { fn clean_command(command: &str) -> &str {
let command = command.trim(); let command = command.trim();
command command
@@ -1656,6 +1684,31 @@ mod tests {
let _ = std::fs::remove_dir_all(&dir); let _ = std::fs::remove_dir_all(&dir);
} }
#[cfg(unix)]
#[test]
fn the_path_agent_commands_are_the_bare_names_each_once() {
// The baked built-ins, then a custom list with a repeat, a quoted
// name, a command with a folder in it and an empty one.
let builtins = parse_agent_list(BAKED_AGENTS).expect("the baked list parses");
let custom = [
"codex",
"\"opencode\"",
"/opt/tools/bin/gemini",
"./agent",
" ",
];
assert_eq!(
path_commands(
builtins
.builtins
.iter()
.map(|entry| entry.command.as_str())
.chain(custom)
),
["claude", "devin", "codex", "opencode"]
);
}
#[test] #[test]
fn the_baked_list_matches_the_shipped_agents_json() { fn the_baked_list_matches_the_shipped_agents_json() {
// include_str! means the baked copy IS src/launcher/agents.json; this // include_str! means the baked copy IS src/launcher/agents.json; this
+25 -4
View File
@@ -162,13 +162,23 @@ fn platform_info() -> serde_json::Value {
// What the launch card offers per agent: whether its CLI is on PATH (else how // What the launch card offers per agent: whether its CLI is on PATH (else how
// to install it), and whether it takes its own reasoning effort; plus the // to install it), and whether it takes its own reasoning effort; plus the
// warnings about agents.json. // warnings about agents.json. A refresh runs the person's login shell, which
// can take seconds with a slow profile, so the work runs on a blocking thread:
// a sync command would run on the main thread and freeze the window meanwhile.
#[tauri::command] #[tauri::command]
fn agent_availability(refresh: Option<bool>) -> serde_json::Value { async fn agent_availability(refresh: Option<bool>) -> Result<serde_json::Value, String> {
let refresh = refresh == Some(true);
tauri::async_runtime::spawn_blocking(move || agent_list(refresh))
.await
.map_err(|e| e.to_string())
}
// The agent list `agent_availability` answers with.
fn agent_list(refresh: bool) -> serde_json::Value {
// "Check again" also works the PATH out again and re-reads the shipped // "Check again" also works the PATH out again and re-reads the shipped
// agent list, so a CLI whose installer added a new folder to PATH, or a // agent list, so a CLI whose installer added a new folder to PATH, or a
// list an update rewrote, is seen without restarting the app. // list an update rewrote, is seen without restarting the app.
if refresh == Some(true) { if refresh {
node_check::refresh_path(); node_check::refresh_path();
agents::refresh_agent_list(); agents::refresh_agent_list();
} }
@@ -2758,7 +2768,7 @@ mod tests {
// Every entry carries the shared lookup's state: found (on PATH), // Every entry carries the shared lookup's state: found (on PATH),
// outside (needing setup, not missing) or missing, with `folder` for // outside (needing setup, not missing) or missing, with `folder` for
// where an outside hit lives. // where an outside hit lives.
let json = agent_availability(None); let json = agent_list(false);
let entries = json["agents"].as_array().unwrap(); let entries = json["agents"].as_array().unwrap();
assert!(!entries.is_empty()); assert!(!entries.is_empty());
let mut builtins = 0; let mut builtins = 0;
@@ -2777,6 +2787,17 @@ mod tests {
assert!(builtins >= 3, "claude, devin and codex are listed"); assert!(builtins >= 3, "claude, devin and codex are listed");
} }
#[test]
fn the_availability_command_is_awaited_not_run_on_the_ui_thread() {
// Check again re-runs the login shell, then the interactive config
// (up to 5 s with slow ones). A sync command runs on the main thread and freezes the
// window that long, so the command is a future that hands the work
// to a blocking thread; awaiting it gives the same list.
let json = tauri::async_runtime::block_on(agent_availability(None))
.expect("the blocking task finished");
assert_eq!(json, agent_list(false));
}
/// A real console, the same way `tests/console_supervisor.rs` sets one /// A real console, the same way `tests/console_supervisor.rs` sets one
/// up (see `console_test_env`). Keep the guard until the test ends: the /// up (see `console_test_env`). Keep the guard until the test ends: the
/// console's variables must not change while its session is in use. /// console's variables must not change while its session is in use.
File diff suppressed because it is too large. Load diff