Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions apps/tray/src/hosts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> {
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.
Expand Down
26 changes: 21 additions & 5 deletions apps/tray/src/hosts/actions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,11 +226,10 @@ 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.
let outdated = state["state"] == "app"
&& crate::update::parse(state["version"].as_str().unwrap_or_default())
< crate::update::parse(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" && version != VERSION && !self.keeps_newer_skill(version);
if (missing && install_missing) || (outdated && !defer_update) {
skill::install(
path,
Expand All @@ -244,6 +243,23 @@ 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, 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);
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
}
Expand Down
4 changes: 1 addition & 3 deletions apps/tray/src/hosts/reload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
7 changes: 6 additions & 1 deletion apps/tray/src/hosts/snapshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ impl Hosts {
} else {
host.skill.clone()
};
let skill = path
let mut skill = path
.as_ref()
.map(|p| {
skill::state(
Expand All @@ -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
Expand Down
78 changes: 74 additions & 4 deletions apps/tray/src/hosts/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -749,6 +749,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));
Expand Down Expand Up @@ -1785,14 +1802,67 @@ 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);
// 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
.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(&current, &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))
);
// 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, &current).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"],
Expand Down
1 change: 1 addition & 0 deletions apps/tray/ui/hosts.js
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,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"));
}

Expand Down
3 changes: 3 additions & 0 deletions scripts/open_tray.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
# A Claude Code session's own markers, as HOST_SESSION_ENV in src/agentnave/adapters/claude.py
# lists them: a tray holding them runs its CLI probes as that session's children, and Claude's
Expand Down
Loading