Detection goes by an agent's folder, and an uninstall leaves the folder
behind. Before this commit, Hermes with only its 37-byte
~/.hermes/config.yaml (custom_providers: [], mcp_servers: {}) was listed as
installed in `magpie ls`, the GUI and the TUI, with model and effort pickers
that no program reads. CLIMissing (#843) covered only agents that have an
install command and their own folder. Hermes and the agents whose folder
something else keeps too (claude, codex, cline, opencode, goose) were never
gone.
What changes:
- internal/agent/gone.go adds cliHeld, which asks whether anything here still
reads the folder:
- the CLI on PATH or in proc.FindTool's folders (for goose, a binary that
isn't pressly's Go goose);
- its desktop app (HasApp) or sign;
- the vendor installer's own place: ~/.claude/local, ~/.opencode/bin,
~/.codex/packages/standalone, Hermes' <home>/hermes-agent checkout;
- for the shared folders, an editor extension under
~/.<editor>/extensions (anthropic.claude-code, openai.chatgpt,
saoudrizwan.claude-dev), Claude.app or Claude Desktop, OpenCode.app or
Goose.app on a Mac, a JetBrains IDE's settings (its agents bring their
own program) or Zed's external_agents.
When magpie can't tell, the agent is never gone. That covers OpenCode and
Goose off a Mac, Gemini (its folder is Antigravity's and Code Assist's
too), agents with their own detect, and WSL and plugin agents. It also
covers Bin agents with no install command, except Hermes (cliOnly), since
their installers' paths aren't verified.
- GUI: a gone row shows "CLI not found" and none of its settings, and the
tag's tip says why. It offers no Apply again. While it is still wired it
keeps its switch and Disconnect. Once it isn't wired it folds under Not
set up, and Get started doesn't offer it (connectKind is "no"; the sandbox
run showed Hermes offered there before). The panel shows the words only.
The new tip is translated into zh, zh-TW, ja and de.
- The TUI leaves the agent out. `magpie ls` says "CLI not found" beside its
path.
- docs/subsystems/agent-wiring.md describes all of the above.
- aside-native.test.cjs drops cliMissing from an Aside fixture. That state
can't happen (Aside has no install command and isn't in cliOnly), and
that test is about runtime_unavailable.
What was run:
- Sandbox HOME holding only the reporter's ~/.hermes/config.yaml (37 bytes)
and a bare ~/.codex, with env -i and PATH=/usr/bin:/bin:
- `magpie ls` at base 331c27703 lists "Hermes Agent — · effort —".
- The fix lists "Hermes Agent CLI not found ~/.hermes/config.yaml".
- Codex stays listed, because this Mac has ChatGPT.app's Codex (HasApp),
so a really installed agent is kept.
- `magpie web` from the same sandbox, screenshot in Chromium: the Hermes row
shows "CLI not found" and no pickers. That run found Get started still
offering Hermes, which this commit fixes.
- go test ./internal/agent (2255s under load ~250 on 14 cores) and
./internal/cli and ./internal/tui pass. ./internal/gui fails only
TestMainWindowCorners/macOS_26_SDK, killed at its 40s deadline under the
same load. That is #1936; it has nothing from this change in its path, and
it passed on base once and failed on it twice.
- GUI in Chromium and WebKit:
- agent-cli-missing.test.cjs covers 5 languages, widths 1100 and 420, and
the panel.
- getting-started.test.cjs adds a gone Hermes to the fixture; the chips
stay codex, claude and opencode.
- Also run: i18n-keys, aside-native, agent-*, panel-* and click-scroll.
- gofmt -l is clean. go vet passes on darwin, linux (-tags nogui) and
windows for the touched packages.
Broken by hand, and the tests went red each time:
- Dropping the openai.chatgpt check made TestCLIMissingSharedFolders' codex
case red.
- Dropping the hermes-agent case made TestCLIMissingHermes red.
- Dropping the GUI gone branch, or the agentUsed change ("the one not
connected stayed up"), made agent-cli-missing red.
- Dropping connectKind's cliMissing line made getting-started red
(30 of 60 failed: chips gained hermes).
Not covered:
- library.Targets (Skills/MCP) still lists a gone agent as a place to give
skills to.
221 lines
13 KiB
JavaScript
221 lines
13 KiB
JavaScript
// Run with Node's test runner and Playwright on the module path; see README.md.
|
|
// wangye1644294 on X: magpie isn't friendly to a first-time user; a guide,
|
|
// routing set up in a click and the agents found here, please. A new user's
|
|
// Agents page (the window's first page, and the panel's first tab) has a Get
|
|
// started card: add a model source, connect an agent (those found here, each
|
|
// connected in a click), and, optionally, a routing group made of their own
|
|
// models in a click. Each step is ticked from the state the server gives,
|
|
// never from having been seen; the card goes once the first two are done,
|
|
// and put away it stays away, kept in the settings, not the page's storage.
|
|
// Both engines, a wide and a narrow window and the panel, every language.
|
|
// No backend, the API is faked here.
|
|
const assert = require("node:assert/strict");
|
|
const fs = require("node:fs/promises");
|
|
const path = require("node:path");
|
|
const { test } = require("node:test");
|
|
const { chromium, webkit } = require("playwright");
|
|
|
|
const assets = path.resolve(__dirname, "../assets");
|
|
const shots = process.env.ARTIFACT_DIR;
|
|
|
|
// world is what the fake server knows, changed by the page's writes
|
|
function newWorld() {
|
|
return { served: 0, wired: false, hidden: false, groups: [] };
|
|
}
|
|
|
|
function agents(w) {
|
|
// with no model served, the agents' pickers have none of magpie's
|
|
const mine = w.served ? [{ value: "relay/m1", label: "m1", ref: "relay/m1", note: "Relay · via magpie" }] : [];
|
|
const field = (value, own) => [{ key: "model", label: "model", value, options: [...own, ...mine] }];
|
|
return [
|
|
{ id: "codex", name: "Codex", icon: "generic", path: "/fixture/codex", wired: w.wired, fields: field(w.wired ? "relay/m1" : "", [{ value: "gpt-5.4", label: "GPT-5.4" }]) },
|
|
{ id: "claude", name: "Claude Code", icon: "generic", path: "/fixture/claude", fields: field("", [{ value: "sonnet", label: "Sonnet" }]) },
|
|
{ id: "opencode", name: "OpenCode", icon: "generic", path: "/fixture/opencode", fields: field("", []) },
|
|
// never connectable: not offered on the card
|
|
{ id: "cursor", name: "Cursor", icon: "generic", path: "/fixture/cursor", fields: [] },
|
|
// its folder left behind with the CLI uninstalled (#2173): not offered
|
|
{ id: "hermes", name: "Hermes Agent", icon: "generic", path: "/fixture/hermes", cliMissing: true, fields: field("", [{ value: "hermes-own", label: "Own" }]) },
|
|
];
|
|
}
|
|
|
|
const templates = [
|
|
{ kind: "smart", group: { id: "smart-split", name: "Hard to strong, easy to cheap", members: ["relay/m1", "other/m2"] } },
|
|
{ kind: "thrifty", need: "cheap", of: "m1", group: { id: "cheap-first", name: "Cheap first", members: [] } },
|
|
{ kind: "steady", group: { id: "never-stuck", name: "Never stuck", members: ["relay/m1", "other/m2"] } },
|
|
];
|
|
|
|
function server(lang, w, posts) {
|
|
const settings = () => ({ lang, theme: "light", guideHidden: w.hidden || undefined });
|
|
const state = () => ({ agents: agents(w), profiles: [], served: w.served, settings: settings() });
|
|
const groups = () => ({ groups: w.groups, models: [], pools: [], deciders: [], templates });
|
|
return async (route) => {
|
|
const req = route.request(), url = new URL(req.url());
|
|
const json = (data, status = 200) => route.fulfill({ status, json: data });
|
|
if (url.pathname === "/boot.js") return route.fulfill({ contentType: "text/javascript", body: `window.bootPrefs = {lang:"${lang}",theme:"light",web:false};` });
|
|
if (url.pathname === "/wails/runtime.js") return route.fulfill({ contentType: "text/javascript", body: "export const Window = {};" });
|
|
if (req.method() === "POST") posts.push(url.pathname + url.search);
|
|
if (url.pathname === "/api/state") return json(state());
|
|
if (url.pathname === "/api/settings/guide") {
|
|
w.hidden = !!req.postDataJSON().hidden;
|
|
return json(settings());
|
|
}
|
|
if (url.pathname === "/api/agents/connect/codex") {
|
|
w.wired = true;
|
|
return json(state());
|
|
}
|
|
if (url.pathname === "/api/groups/template") {
|
|
const { kind, name } = req.postDataJSON();
|
|
const tp = templates.find((x) => x.kind === kind);
|
|
w.groups.push({ ...tp.group, name });
|
|
return json(groups());
|
|
}
|
|
if (url.pathname === "/api/groups") return json(groups());
|
|
if (url.pathname === "/api/usage/quotas") return json([]);
|
|
if (url.pathname === "/api/plugins") return json({ plugins: [] });
|
|
if (url.pathname === "/api/agents/cli") return json({ agents: {}, pending: false });
|
|
if (url.pathname === "/api/providers") return json({ providers: [], presets: [], excluded: [], gateway: { running: true, window: true } });
|
|
if (url.pathname.startsWith("/api/")) return json({});
|
|
const file = path.join(assets, url.pathname === "/" ? "index.html" : url.pathname);
|
|
const contentType = { ".html": "text/html", ".js": "text/javascript", ".css": "text/css", ".svg": "image/svg+xml", ".png": "image/png" }[path.extname(file)];
|
|
try { await route.fulfill({ body: await fs.readFile(file), contentType }); } catch { await route.fulfill({ status: 404, body: "" }); }
|
|
};
|
|
}
|
|
|
|
const LAYOUTS = [
|
|
{ name: "window", url: "/?view=agents", viewport: { width: 1100, height: 760 } },
|
|
{ name: "narrow", url: "/?view=agents", viewport: { width: 420, height: 760 } },
|
|
{ name: "panel", url: "/?mode=panel", viewport: { width: 400, height: 640 } },
|
|
];
|
|
const LANGS = ["en", "zh", "zh-TW", "ja", "de"];
|
|
const STRINGS = ["Get started", "Add a model source", "Connect an agent", "Set up routing (optional)", "Hide Get started",
|
|
"A subscription you already pay for, a provider, or an API key", "magpie found these on this computer. Click one to connect it:",
|
|
"A routing group sends each request to the right model, and to the next one when a model fails", "+{n} more below", "{n} of {m} done", "{n} models ready to use", "Add “{name}”"];
|
|
|
|
async function open(browser, layout, lang, w, posts) {
|
|
const context = await browser.newContext({ viewport: layout.viewport, reducedMotion: "reduce" });
|
|
await context.addInitScript(() => { try { localStorage.setItem("magpie.panelTab", "agents"); } catch {} });
|
|
const page = await context.newPage();
|
|
page.setDefaultTimeout(5000);
|
|
page.errors = [];
|
|
page.on("pageerror", (e) => page.errors.push(e.message));
|
|
await page.route("**/*", server(lang, w, posts));
|
|
await page.goto("http://magpie.test" + layout.url);
|
|
await page.locator(".row.agent").first().waitFor();
|
|
return { context, page };
|
|
}
|
|
|
|
const stepDone = (page, step) => page.locator(`.guide-step[data-step="${step}"]`).evaluate((e) => e.classList.contains("done"));
|
|
const tops = (page) => page.evaluate(() => [document.scrollingElement.scrollTop, document.querySelector("#view-agents")?.scrollTop]);
|
|
const sideways = (page) => page.evaluate(() => {
|
|
const v = document.querySelector("#view-agents"), g = document.querySelector(".guide");
|
|
return v.scrollWidth > v.clientWidth + 1 || document.scrollingElement.scrollWidth > innerWidth
|
|
|| (g && [...g.querySelectorAll("*")].some((e) => e.getBoundingClientRect().right > g.getBoundingClientRect().right + 1));
|
|
});
|
|
|
|
for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
|
|
for (const lang of LANGS) {
|
|
for (const layout of LAYOUTS) {
|
|
test(`${engine} ${lang} ${layout.name}: Get started ticks from state, connects in a click and goes once done`, async (t) => {
|
|
const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" }));
|
|
t.after(() => browser.close());
|
|
const w = newWorld(), posts = [];
|
|
const { page } = await open(browser, layout, lang, w, posts);
|
|
const tr = (s, v) => page.evaluate(([s, v]) => t(s, v), [s, v]);
|
|
if (lang !== "en") {
|
|
for (const s of STRINGS) assert.notEqual(await tr(s), s, `${lang} has "${s}"`);
|
|
}
|
|
|
|
// a new user: nothing served, nothing wired
|
|
const card = page.locator("#agentsLead .guide");
|
|
await card.waitFor();
|
|
assert.equal((await page.locator(".guide-h").textContent()), await tr("Get started"));
|
|
assert.equal(await stepDone(page, "source"), false);
|
|
assert.equal(await stepDone(page, "agent"), false);
|
|
assert.equal(await page.locator(".guide-n").textContent(), await tr("{n} of {m} done", { n: 0, m: 2 }));
|
|
// the agents found here are named, Cursor (never connectable) not;
|
|
// with no models yet they can't be connected
|
|
assert.deepEqual(await page.locator(".guide-agent").evaluateAll((bs) => bs.map((b) => b.dataset.id)), ["codex", "claude", "opencode"]);
|
|
assert.ok(await page.locator(".guide-agent").evaluateAll((bs) => bs.every((b) => b.disabled)));
|
|
// routing waits for a model source: no button yet
|
|
assert.equal(await page.locator(".guide-tpl").count(), 0);
|
|
assert.equal(await sideways(page), false, "nothing runs off sideways");
|
|
if (shots && (lang === "en" || lang === "zh")) await page.screenshot({ path: path.join(shots, `getting-started-${engine}-${lang}-${layout.name}-new.png`) });
|
|
|
|
// the first step's button: the window opens the add sheet, the
|
|
// panel the window on Providers
|
|
const top = await tops(page);
|
|
await page.locator('.guide-step[data-step="source"] .guide-go').click();
|
|
if (layout.name === "panel") {
|
|
for (let i = 0; i < 50 && !posts.includes("/api/window/main?view=providers"); i++) await page.waitForTimeout(20);
|
|
assert.ok(posts.includes("/api/window/main?view=providers"), posts.join(" "));
|
|
} else {
|
|
await page.locator("#view-providers").waitFor({ state: "visible" });
|
|
await page.locator("#addSheet").waitFor({ state: "visible" });
|
|
}
|
|
|
|
// a provider added: the step is ticked from the state, the agents can
|
|
// be connected, and a routing group is a click away
|
|
w.served = 12;
|
|
await page.goto("http://magpie.test" + layout.url);
|
|
await card.waitFor();
|
|
assert.equal(await stepDone(page, "source"), true);
|
|
assert.match(await page.locator('.guide-step[data-step="source"] .guide-say').textContent(), /12/);
|
|
assert.equal(await page.locator(".guide-n").textContent(), await tr("{n} of {m} done", { n: 1, m: 2 }));
|
|
const codex = page.locator('.guide-agent[data-id="codex"]');
|
|
assert.equal(await codex.isDisabled(), false);
|
|
const tpl = page.locator(".guide-tpl");
|
|
await tpl.waitFor();
|
|
assert.equal(await tpl.getAttribute("data-kind"), "steady", "the harmless template first; the one that can't be made isn't offered");
|
|
const name = await tr("Never stuck");
|
|
assert.equal(await tpl.textContent(), await tr("Add “{name}”", { name }));
|
|
if (shots && (lang === "en" || lang === "zh")) await page.screenshot({ path: path.join(shots, `getting-started-${engine}-${lang}-${layout.name}-source.png`) });
|
|
|
|
const before = await tops(page);
|
|
await tpl.click();
|
|
await page.locator('.guide-step[data-step="routing"].done').waitFor();
|
|
assert.ok(posts.includes("/api/groups/template"));
|
|
assert.equal(w.groups[0].name, name, "saved under the name shown");
|
|
assert.match(await page.locator('.guide-step[data-step="routing"] .guide-say').textContent(), new RegExp(name.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")));
|
|
|
|
// one click connects Codex, and with both steps done the card goes
|
|
await codex.click();
|
|
await card.waitFor({ state: "detached" });
|
|
assert.ok(posts.includes("/api/agents/connect/codex"));
|
|
assert.deepEqual(await tops(page), before, "no click moved the page");
|
|
assert.equal(top[0], before[0]);
|
|
|
|
// done stays done: a reload brings no card back
|
|
await page.goto("http://magpie.test" + layout.url);
|
|
await page.locator(".row.agent").first().waitFor();
|
|
assert.equal(await page.locator(".guide").count(), 0);
|
|
assert.deepEqual(page.errors, []);
|
|
});
|
|
|
|
test(`${engine} ${lang} ${layout.name}: Get started put away stays away, in the settings`, async (t) => {
|
|
const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" }));
|
|
t.after(() => browser.close());
|
|
const w = newWorld(), posts = [];
|
|
const first = await open(browser, layout, lang, w, posts);
|
|
const page = first.page;
|
|
await page.locator("#agentsLead .guide").waitFor();
|
|
const top = await tops(page);
|
|
await page.locator(".guide-x").click();
|
|
await page.locator(".guide").waitFor({ state: "detached" });
|
|
assert.ok(posts.includes("/api/settings/guide"));
|
|
assert.equal(w.hidden, true);
|
|
assert.deepEqual(await tops(page), top, "no click moved the page");
|
|
assert.deepEqual(page.errors, []);
|
|
await first.context.close();
|
|
|
|
// a fresh browser storage (the other window, a reinstall's webview):
|
|
// still away, though no step is done
|
|
const again = await open(browser, layout, lang, w, posts);
|
|
await again.page.waitForTimeout(150);
|
|
assert.equal(await again.page.locator(".guide").count(), 0);
|
|
assert.equal(await again.page.evaluate(() => { try { return Object.keys(localStorage).filter((k) => /guide/i.test(k)).length; } catch { return 0; } }), 0, "nothing kept in localStorage");
|
|
assert.deepEqual(again.page.errors, []);
|
|
});
|
|
}
|
|
}
|
|
}
|