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()
}
/// 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 {
let command = command.trim();
command
@@ -1656,6 +1684,31 @@ mod tests {
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]
fn the_baked_list_matches_the_shipped_agents_json() {
// include_str! means the baked copy IS src/launcher/agents.json; this