Soul-driven AI agent with permission-hardened tools, token budgets, and multi-channel access. Runs 24/7 from CLI, Telegram or More.
fix(desktop): spot Mercury's login service on Linux and Windows too
Salman Qureshi7f17246f4175
diff --git a/apps/desktop/src/shell/updateLocal.test.ts b/apps/desktop/src/shell/updateLocal.test.tsnew file mode 100644index 00000000..191add07--- /dev/null+++ b/apps/desktop/src/shell/updateLocal.test.ts@@ -0,0 +1,21 @@+import { describe, expect, it, vi } from "vitest";++vi.mock("./tauri", () => ({ desktop: {} }));+const { serviceInstalledFrom } = await import("./updateLocal");+const out = (stdout: string, code = 0) => ({ code, stdout, stderr: "" });++describe("is Mercury set to start at login?", () => {+ it("macOS: launchd says so", () => {+ expect(serviceInstalledFrom(out(" Service installed and loaded\n -\t0\tcom.cosmicstack.mercury"))).toBe(true);+ expect(serviceInstalledFrom(out(" Service installed but not loaded"))).toBe(true);+ });+ it("Ubuntu: systemd's own report", () => {+ expect(serviceInstalledFrom(out("● mercury.service - Mercury Agent\n Loaded: loaded (/home/a/.config/systemd/user/mercury.service; enabled)\n Active: active (running)"))).toBe(true);+ });+ it("none set up, unsupported, or no answer", () => {+ expect(serviceInstalledFrom(out(" Mercury service is not installed.\n Run `mercury service install` to set it up."))).toBe(false);+ expect(serviceInstalledFrom(out(" System service is not supported on this platform (freebsd)."))).toBe(false);+ expect(serviceInstalledFrom(out("", 1))).toBe(false);+ expect(serviceInstalledFrom(null)).toBe(false);+ });+});diff --git a/apps/desktop/src/shell/updateLocal.ts b/apps/desktop/src/shell/updateLocal.tsindex 95c1812a..105887c5 100644--- a/apps/desktop/src/shell/updateLocal.ts+++ b/apps/desktop/src/shell/updateLocal.ts@@ -20,8 +20,7 @@ export async function updateLocalRuntime(onStep?: (step: "download" | "restart"/** Stop the running Mercury (whichever copy) and start the installed one. */export async function restartLocalRuntime(onStep?: (step: "restart" | "wait") => void): Promise<void> {onStep?.("restart");- const service = await desktop.runMercury(["service", "status"]).catch(() => null);- if (service && /service installed/i.test(service.stdout) && !/not installed/i.test(service.stdout)) {+ if (await hasLoginService()) {// A login service runs Mercury and would bring the old copy straight// back: install it again from the new copy, which points it there and// restarts it.@@ -48,6 +47,24 @@ export async function restartLocalRuntime(onStep?: (step: "restart" | "wait") =>}}+/**+ * Is Mercury set to start at login? `mercury service status` says "not+ * installed" (or "not supported") when it isn't; otherwise it prints the+ * platform's own report (launchd, systemd, Task Scheduler), so anything+ * else means there is one.+ */+export async function hasLoginService(): Promise<boolean> {+ const out = await desktop.runMercury(["service", "status"]).catch(() => null);+ return serviceInstalledFrom(out);+}++export function serviceInstalledFrom(out: { code: number; stdout: string; stderr: string } | null): boolean {+ if (!out || out.code !== 0) return false;+ const text = `${out.stdout}\n${out.stderr}`;+ if (!text.trim()) return false;+ return !/not installed|not supported|could not get service status/i.test(text);+}+/** Does a running Mercury on this port predate the desktop API? */export async function localIsOutdated(port: number): Promise<boolean> {const health = await desktop.probeLocalHealth(port).catch(() => null);