From 2e65ac095506b2f2e587ced20d9362a974e8f23c Mon Sep 17 00:00:00 2001 From: Tim Wong <280945586+TimWongUp@users.noreply.github.com> Date: Thu, 3 Dec 2026 20:34:57 +0800 Subject: [PATCH 1/2] =?UTF-8?q?fix(tray):=20=E4=BF=AE=E6=AD=A3=E5=AE=BF?= =?UTF-8?q?=E4=B8=BB=E9=A1=B5=20Skill=20=E7=89=88=E6=9C=AC=E4=B8=8E=20Clau?= =?UTF-8?q?de=20=E5=BE=85=E9=87=8D=E5=BC=80=E7=9A=84=E9=94=99=E8=AF=AF?= =?UTF-8?q?=E7=8A=B6=E6=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 标着比 App 新的 Skill 副本,只在本机服务不低于该版本时保留,否则按过期副本备份后替换;保留时宿主页照实显示版本 - open_tray.sh 在 Claude Code 会话里启动 App 时去掉 CLAUDE_CONFIG_DIR,避免默认 Claude 行与具名账号行指向同一文件、互相改写 AGENTNAVE_HOST_APP 而一直待重开 - 测试覆盖:服务不够新时替换、够新时保留;旧进程已重连时消除待重开、仍有旧中继时保留 --- apps/tray/src/hosts.rs | 13 +++++--- apps/tray/src/hosts/actions.rs | 18 ++++++++--- apps/tray/src/hosts/reload.rs | 4 +-- apps/tray/src/hosts/snapshot.rs | 7 ++++- apps/tray/src/hosts/tests.rs | 56 ++++++++++++++++++++++++++++++--- apps/tray/ui/hosts.js | 1 + scripts/open_tray.sh | 3 ++ 7 files changed, 85 insertions(+), 17 deletions(-) diff --git a/apps/tray/src/hosts.rs b/apps/tray/src/hosts.rs index 579926d9..a30e473d 100644 --- a/apps/tray/src/hosts.rs +++ b/apps/tray/src/hosts.rs @@ -532,13 +532,16 @@ impl Hosts { /// of this App's release, which an older service rejects, so it waits for the upgrade; the /// upgrade refreshes the hosts, and that syncs the rules again. fn service_behind(&self) -> bool { + self.service_version().is_some_and(|installed| { + crate::update::parse(&installed) < crate::update::parse(VERSION) + }) + } + /// The version of the installed local service: the active versioned install, else the + /// shell's uv tool environment. + fn service_version(&self) -> Option { let env = crate::update::active_tools(&self.context.app) .or_else(|| self.tool_dirs().map(|dirs| dirs.tools.join("agentnave"))); - env.as_deref() - .and_then(crate::update::installed_version) - .is_some_and(|installed| { - crate::update::parse(&installed) < crate::update::parse(VERSION) - }) + env.as_deref().and_then(crate::update::installed_version) } /// The rules files the installed apps could read now, kept across a root change so the /// files left behind lose their block too. diff --git a/apps/tray/src/hosts/actions.rs b/apps/tray/src/hosts/actions.rs index 09467b4f..18059311 100644 --- a/apps/tray/src/hosts/actions.rs +++ b/apps/tray/src/hosts/actions.rs @@ -225,11 +225,11 @@ impl Hosts { let state = skill::state(path, &self.context.home, embedded); // Another copy is the App's to replace, like a missing one. let missing = state["state"] == "missing" || state["state"] == "external"; - // Only an older copy is replaced. An App installed over a newer one must not push the - // hosts back to its own Skill while the service stays on the newer version. + // Another release's copy is replaced, unless it is newer and kept by keeps_newer_skill. + let version = state["version"].as_str().unwrap_or_default(); let outdated = state["state"] == "app" - && crate::update::parse(state["version"].as_str().unwrap_or_default()) - < crate::update::parse(VERSION); + && crate::update::parse(version) != crate::update::parse(VERSION) + && !self.keeps_newer_skill(version); if (missing && install_missing) || (outdated && !defer_update) { skill::install( path, @@ -243,6 +243,16 @@ impl Hosts { Ok(false) } } + /// Whether an App copy newer than this App stays: an App installed over a newer one must not + /// push the hosts back to its own Skill while the installed service is at least that new. + /// A marker no installed service reaches is an outdated copy. + pub(super) fn keeps_newer_skill(&self, version: &str) -> bool { + let copy = crate::update::parse(version); + copy > crate::update::parse(VERSION) + && self + .service_version() + .is_some_and(|installed| crate::update::parse(&installed) >= copy) + } pub(super) fn skill_wanted(&self, id: &str, name: &str) -> bool { self.settings[id]["skills"][name] == true } diff --git a/apps/tray/src/hosts/reload.rs b/apps/tray/src/hosts/reload.rs index 623f8b1a..191c05f7 100644 --- a/apps/tray/src/hosts/reload.rs +++ b/apps/tray/src/hosts/reload.rs @@ -244,10 +244,8 @@ impl Hosts { ) } fn install(&self) -> Install { - let env = crate::update::active_tools(&self.context.app) - .or_else(|| self.tool_dirs().map(|dirs| dirs.tools.join("agentnave"))); Install { - version: env.as_deref().and_then(crate::update::installed_version), + version: self.service_version(), } } /// A running host can still hold the configuration from before its first MCP connection. diff --git a/apps/tray/src/hosts/snapshot.rs b/apps/tray/src/hosts/snapshot.rs index 3b8b6357..e8d33b13 100644 --- a/apps/tray/src/hosts/snapshot.rs +++ b/apps/tray/src/hosts/snapshot.rs @@ -252,7 +252,7 @@ impl Hosts { } else { host.skill.clone() }; - let skill = path + let mut skill = path .as_ref() .map(|p| { skill::state( @@ -266,6 +266,11 @@ impl Hosts { ) }) .unwrap_or_else(|| json!({"state":"manual","path":null,"version":null})); + if skill["state"] == "app" + && self.keeps_newer_skill(skill["version"].as_str().unwrap_or_default()) + { + skill["newer"] = json!(true); + } let mut skills = serde_json::Map::new(); for (name, embedded) in skill::OPTIONAL { let mut state = host diff --git a/apps/tray/src/hosts/tests.rs b/apps/tray/src/hosts/tests.rs index ff72bec5..f34cba30 100644 --- a/apps/tray/src/hosts/tests.rs +++ b/apps/tray/src/hosts/tests.rs @@ -735,6 +735,23 @@ fn first_connection_detects_running_hosts_without_mcp_receipts() { hosts.refresh(); assert_eq!(hosts.settings[id]["reload_changed"], changed); assert_eq!(hosts.state(&h)["reload"]["state"], "required"); + // The old process reconnected its MCP after the change, so it runs the new entry; an old + // relay still running beside it, unreconnected, keeps the reload. + let at = changed["at_ms"].as_u64().unwrap(); + let receipt = |started: u64| { + json!({"version":1,"host":id,"started_ms":started,"runtime_version":"0.22.0", + "runtime_tools_hash":"a".repeat(64),"host_tools_hash":"a".repeat(64)}) + .to_string() + }; + let connections = hosts.context.home.join(".agentnave/connections"); + let (new, old) = (connections.join("new.json"), connections.join("old.json")); + save(&new, &receipt(at + 1)); + assert_eq!(hosts.state(&h)["reload"]["state"], "current", "{id}"); + save(&old, &receipt(at)); + assert_eq!(hosts.state(&h)["reload"]["state"], "required", "{id}"); + fs::remove_file(&old).unwrap(); + fs::remove_file(&new).unwrap(); + assert_eq!(hosts.state(&h)["reload"]["reason"], "host_running"); let repeated = hosts.action("connect", &json!({"id":id})).unwrap(); assert!(!repeated["message"].as_str().unwrap().contains("后生效")); hosts.processes = Mutex::new(processes::Probe::fixed(None)); @@ -1771,14 +1788,45 @@ fn skill_ownership_links_and_refresh_replace_other_copies_after_a_backup() { executable_file(&hosts.context.search[0].join("pi"), "#!/bin/sh\nexit 99\n"); hosts.action("connect", &json!({"id":"pi"})).unwrap(); let manifest = path.join(".agentnave-app-manifest.json"); + let mark = |version: &str| { + save(&path.join(".agentnave-app"), version); + let mut value: Value = serde_json::from_slice(&fs::read(&manifest).unwrap()).unwrap(); + value["version"] = json!(version); + save(&manifest, &value.to_string()); + }; + // A copy marked newer than this App stays only while the installed service is that new; + // otherwise it is replaced after a backup like any outdated copy. + let skill_backups = |hosts: &Hosts| hosts.snapshot()["backups"]["skill"].as_u64().unwrap(); + let backed_up = skill_backups(&hosts); + mark("99.0.0"); + hosts.refresh(); + assert_eq!( + skill::state(path, &hosts.context.home, skill::MANAGER)["version"], + VERSION + ); + assert!(skill_backups(&hosts) > backed_up); + let site = hosts + .context + .home + .join(".local/share/uv/tools/agentnave/lib/python3.12/site-packages"); + let (current, newer) = ( + site.join("agentnave-0.22.0.dist-info"), + site.join("agentnave-99.0.0.dist-info"), + ); + fs::rename(¤t, &newer).unwrap(); + mark("99.0.0"); + hosts.refresh(); + let shown = hosts.state(&h)["skill"].clone(); + assert_eq!( + (&shown["version"], &shown["newer"]), + (&json!("99.0.0"), &json!(true)) + ); + fs::rename(&newer, ¤t).unwrap(); for keep_entry in [true, false] { if !keep_entry { fs::remove_file(&h.config).unwrap(); } - save(&path.join(".agentnave-app"), "old"); - let mut value: Value = serde_json::from_slice(&fs::read(&manifest).unwrap()).unwrap(); - value["version"] = json!("old"); - save(&manifest, &value.to_string()); + mark("old"); hosts.refresh(); assert_eq!( skill::state(path, &hosts.context.home, skill::MANAGER)["version"], diff --git a/apps/tray/ui/hosts.js b/apps/tray/ui/hosts.js index 44e533cb..959d3faf 100644 --- a/apps/tray/ui/hosts.js +++ b/apps/tray/ui/hosts.js @@ -488,6 +488,7 @@ function skillNode(host) { return h("span", {}, h("span.warn-text", {}, L("无法安装", "Cannot install")), h("span.sub", {}, L("· 暂未找到 Skill 目录,请在下方「更多信息」里指定根目录", "· Skill folder not found yet; set the root folder in “More info” below"))); if (host.status !== "connected") return h("span.dim", {}, L("接入时安装", "Installed on connect")); if (s.state === "app" && (!S.appVersion || s.version === S.appVersion)) return h("span", {}, `v${s.version}`); + if (s.state === "app" && s.newer) return h("span", {}, `v${s.version}`, h("span.sub", {}, L("· 比 App 新", "· Newer than the App"))); return h("span.warn-text", {}, L("未能安装,点「刷新检测」重试", "Failed to install; click “Refresh detection” to retry")); } diff --git a/scripts/open_tray.sh b/scripts/open_tray.sh index e40d8b95..e85bec15 100644 --- a/scripts/open_tray.sh +++ b/scripts/open_tray.sh @@ -13,6 +13,9 @@ case "${GEMINI_HOME:-}" in "$t3_profiles"*) unset GEMINI_HOME ;; esac if [ "${SSH_CONNECTION:-}" = "127.0.0.1 0 127.0.0.1 0" ]; then unset SSH_CONNECTION; fi case "${BROWSER:-}" in *__T3_ANTIGRAVITY_AUTH_URL__*) unset BROWSER ;; esac unset AGY_ACP_FORCE_FILE_STORAGE +# Inside a Claude Code session CLAUDE_CONFIG_DIR names that session's account. The App would take +# it as the default account's folder (ADR-0118) and its row would share a named account's file. +if [ -n "${CLAUDECODE:-}" ]; then unset CLAUDE_CONFIG_DIR; fi unset TMPDIR TEMP TMP CLAUDECODE ELECTRON_RUN_AS_NODE for var in $(env | awk -F= '/^(ANTIGRAVITY|T3_ACP_MCP|T3CODE)_[A-Za-z0-9_]*=/ && $1 != "T3CODE_HOME" && $1 != "ANTIGRAVITY_CLI_HOME" { print $1 }'); do unset "$var" From 4905d7f9ef1fe10043805188bd1d31510099820e Mon Sep 17 00:00:00 2001 From: Tim Wong <280945586+TimWongUp@users.noreply.github.com> Date: Sat, 5 Dec 2026 15:02:01 +0800 Subject: [PATCH 2/2] =?UTF-8?q?fix(tray):=20=E7=B2=BE=E7=A1=AE=E6=AF=94?= =?UTF-8?q?=E5=AF=B9=20Skill=20=E7=89=88=E6=9C=AC=E5=B9=B6=E5=9C=A8=20shel?= =?UTF-8?q?l=20=E6=8E=A2=E6=B5=8B=E5=A4=B1=E8=B4=A5=E6=97=B6=E4=BF=9D?= =?UTF-8?q?=E7=95=99=E6=96=B0=E7=89=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/tray/src/hosts/actions.rs | 22 ++++++++++++++-------- apps/tray/src/hosts/tests.rs | 24 +++++++++++++++++++++++- 2 files changed, 37 insertions(+), 9 deletions(-) diff --git a/apps/tray/src/hosts/actions.rs b/apps/tray/src/hosts/actions.rs index 87e9987b..8dec1151 100644 --- a/apps/tray/src/hosts/actions.rs +++ b/apps/tray/src/hosts/actions.rs @@ -228,9 +228,8 @@ impl Hosts { let missing = state["state"] == "missing" || state["state"] == "external"; // Another release's copy is replaced, unless it is newer and kept by keeps_newer_skill. let version = state["version"].as_str().unwrap_or_default(); - let outdated = state["state"] == "app" - && crate::update::parse(version) != crate::update::parse(VERSION) - && !self.keeps_newer_skill(version); + let outdated = + state["state"] == "app" && version != VERSION && !self.keeps_newer_skill(version); if (missing && install_missing) || (outdated && !defer_update) { skill::install( path, @@ -246,13 +245,20 @@ impl Hosts { } /// Whether an App copy newer than this App stays: an App installed over a newer one must not /// push the hosts back to its own Skill while the installed service is at least that new. - /// A marker no installed service reaches is an outdated copy. + /// A marker no installed service reaches is an outdated copy, except when a failed shell probe + /// leaves the fallback uv tool directory unknown. pub(super) fn keeps_newer_skill(&self, version: &str) -> bool { let copy = crate::update::parse(version); - copy > crate::update::parse(VERSION) - && self - .service_version() - .is_some_and(|installed| crate::update::parse(&installed) >= copy) + if copy <= crate::update::parse(VERSION) { + return false; + } + match self.service_version() { + Some(installed) => crate::update::parse(&installed) >= copy, + None => { + crate::update::active_tools(&self.context.app).is_none() + && self.shell.as_ref().is_some_and(Result::is_err) + } + } } pub(super) fn skill_wanted(&self, id: &str, name: &str) -> bool { self.settings[id]["skills"][name] == true diff --git a/apps/tray/src/hosts/tests.rs b/apps/tray/src/hosts/tests.rs index 74598f87..3b0c35b9 100644 --- a/apps/tray/src/hosts/tests.rs +++ b/apps/tray/src/hosts/tests.rs @@ -1819,6 +1819,14 @@ fn skill_ownership_links_and_refresh_replace_other_copies_after_a_backup() { VERSION ); assert!(skill_backups(&hosts) > backed_up); + // Same numeric release with a local suffix must also be replaced so the UI never sticks on + // a string mismatch. + mark(&format!("{VERSION}+t42")); + hosts.refresh(); + assert_eq!( + skill::state(path, &hosts.context.home, skill::MANAGER)["version"], + VERSION + ); let site = hosts .context .home @@ -1835,7 +1843,21 @@ fn skill_ownership_links_and_refresh_replace_other_copies_after_a_backup() { (&shown["version"], &shown["newer"]), (&json!("99.0.0"), &json!(true)) ); - fs::rename(&newer, ¤t).unwrap(); + // If the login-shell probe fails and no active versioned install is present, a missing uv tool + // dir cannot prove the service is older; keep the newer copy instead of downgrading it. + let hidden = site.join("agentnave-hidden"); + fs::rename(&newer, &hidden).unwrap(); + hosts.shell = Some(Err("shell probe timed out".into())); + hosts.manual_roots.insert("pi".into()); + hosts.refresh_probed(); + let shown = hosts.state(&h)["skill"].clone(); + assert_eq!( + (&shown["version"], &shown["newer"]), + (&json!("99.0.0"), &json!(true)) + ); + hosts.manual_roots.remove("pi"); + hosts.shell = None; + fs::rename(&hidden, ¤t).unwrap(); for keep_entry in [true, false] { if !keep_entry { fs::remove_file(&h.config).unwrap();