Skip to content

armgit / Wake

Public Imported from GitHub
0

All your AI agent sessions in one place — browse, search, resume. Rust + GPUI.

Rust

fix(terminal): retry missing CLI probes

Corey Chiubdf50fca9b6c
diff --git a/CHANGELOG.md b/CHANGELOG.md
index c9fceb6..d992424 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -3,6 +3,7 @@
## Unreleased
- Fixed: agent CLI detection now ignores login-shell rc output, including unterminated ANSI title escapes, by parsing only newline-framed Wake probe records
+- Fixed: agent CLIs installed while Wake is running are detected on the next resume attempt; successful lookups remain cached while misses are re-probed
## [0.3.0] — 2026-08-27
diff --git a/crates/wake-core/src/services/terminal/mod.rs b/crates/wake-core/src/services/terminal/mod.rs
index a53a453..eca17d5 100644
--- a/crates/wake-core/src/services/terminal/mod.rs
+++ b/crates/wake-core/src/services/terminal/mod.rs
@@ -59,25 +59,37 @@ pub struct ResumeOutcome {
pub error: Option<String>,
}
-/// GUI 进程 PATH 不全(macOS/Linux 缺 ~/.local/bin 等),批量解析并缓存
-static CLI_CACHE: Mutex<Option<HashMap<String, Option<String>>>> = Mutex::new(None);
+/// GUI 进程 PATH 不全(macOS/Linux 缺 ~/.local/bin 等),批量解析并缓存。
+/// 只缓存命中:miss 常发生在用户看到提示后刚装好 CLI 的时刻,
+/// 下次点击必须重新探测,不能要求重启 Wake。
+static CLI_CACHE: Mutex<Option<HashMap<String, String>>> = Mutex::new(None);
fn resolve_clis(bins: &[&str]) -> HashMap<String, Option<String>> {
let mut cache = CLI_CACHE.lock().unwrap();
let map = cache.get_or_insert_with(HashMap::new);
+ resolve_clis_with(map, bins, probe_clis)
+}
+
+fn resolve_clis_with(
+ cache: &mut HashMap<String, String>,
+ bins: &[&str],
+ probe: impl FnOnce(&[&str]) -> HashMap<String, String>,
+) -> HashMap<String, Option<String>> {
let missing: Vec<&str> = bins
.iter()
- .filter(|b| !map.contains_key(**b))
+ .filter(|b| !cache.contains_key(**b))
.copied()
.collect();
if !missing.is_empty() {
- let found = probe_clis(&missing);
+ let found = probe(&missing);
for b in missing {
- map.insert(b.to_string(), found.get(b).cloned());
+ if let Some(path) = found.get(b) {
+ cache.insert(b.to_string(), path.clone());
+ }
}
}
bins.iter()
- .map(|b| (b.to_string(), map.get(*b).cloned().flatten()))
+ .map(|b| (b.to_string(), cache.get(*b).cloned()))
.collect()
}
@@ -280,3 +292,48 @@ fn spawn_and_reap(mut cmd: Command) -> std::io::Result<()> {
});
Ok(())
}
+
+#[cfg(test)]
+mod tests {
+ use super::resolve_clis_with;
+ use std::cell::Cell;
+ use std::collections::HashMap;
+
+ #[test]
+ fn cli_cache_reprobes_misses() {
+ let mut cache = HashMap::new();
+ let probes = Cell::new(0);
+
+ for _ in 0..2 {
+ let resolved = resolve_clis_with(&mut cache, &["omp"], |_| {
+ probes.set(probes.get() + 1);
+ HashMap::new()
+ });
+ assert_eq!(resolved.get("omp"), Some(&None));
+ }
+
+ assert_eq!(probes.get(), 2);
+ assert!(cache.is_empty());
+ }
+
+ #[test]
+ fn cli_cache_reuses_hits() {
+ let mut cache = HashMap::new();
+ let first = resolve_clis_with(&mut cache, &["omp"], |_| {
+ HashMap::from([("omp".to_string(), "/opt/bin/omp".to_string())])
+ });
+ let probes = Cell::new(0);
+
+ let second = resolve_clis_with(&mut cache, &["omp"], |_| {
+ probes.set(probes.get() + 1);
+ HashMap::new()
+ });
+
+ assert_eq!(
+ first.get("omp").and_then(Option::as_deref),
+ Some("/opt/bin/omp")
+ );
+ assert_eq!(second, first);
+ assert_eq!(probes.get(), 0);
+ }
+}
diff --git a/crates/wake-core/src/services/terminal/windows.rs b/crates/wake-core/src/services/terminal/windows.rs
index d7a82a3..3295d58 100644
--- a/crates/wake-core/src/services/terminal/windows.rs
+++ b/crates/wake-core/src/services/terminal/windows.rs
@@ -260,8 +260,15 @@ pub fn installed_terminals() -> &'static [TerminalApp] {
/// 时它们同样起不来,得跟着藏掉(macOS 用同一个钩子藏 Kooky)。否则用户点
/// 下去只能拿到 "PowerShell not found" 加一条自己没有 shell 去跑的命令
pub fn terminals_for(_agent: AgentId) -> Vec<TerminalApp> {
- let has_ps = powershell_bin().is_ok();
- installed_terminals()
+ // 这里挂在每个会话行的 render 上,不能调 powershell_bin:
+ // CLI miss 不缓存后,没装 pwsh 的机器会每帧重扫 PATH × PATHEXT。
+ // 已安装终端清单本就是启动期快照,用它判断即可;真正点击
+ // 启动时 powershell_bin 仍会活查,新安装的 pwsh 能立即生效。
+ let installed = installed_terminals();
+ let has_ps = installed
+ .iter()
+ .any(|t| matches!(t, TerminalApp::Pwsh | TerminalApp::WindowsPowershell));
+ installed
.iter()
.copied()
.filter(|t| has_ps || !t.needs_powershell())