CHENGJIAHEGOXIS on X (v0.1.4178, Windows) couldn't install GoAnyAPI from Plugins: "agency-agents" failed with 从缓存复制到目标目录失败, and it was on no plugin's row, so nothing could remove it. Cause: every bun add/update/remove installs every dependency in plugins/package.json again, and a failed `bun add` writes its package there before exiting 1. agency-agents (a repository with no package.json) was left by such an add; on Windows a file of its copy in node_modules is held open, Bun fails "EBUSY: failed copying files from cache to destination for package agency-agents", and so every later install failed over a package nothing used. Fix (internal/plugin/leftover.go, store.go): - A package Bun says it couldn't install that no plugin is installed as (on the list, on or off, an add in flight, pi's agent) is taken out of package.json and node_modules and the command runs again: install() and runBun, so add, update, check and remove all get it. - A failed install puts back the dependencies and bun.lock it found. - An add whose own package went in while another listed plugin's failed succeeds; that plugin keeps its dependency. - Remove and add's clean-ups drop the dependency by hand when bun remove fails. - What is left from before is listed under Installed as "Not used by any plugin", each with a Remove (/api/plugins leftovers, POST /api/plugins/leftover; pmLeftovers in plugininstalled.js, imported when Plugins first draws), in every language. - plugins.json there and unreadable: nothing is a leftover. - Core script budget +51 for the one call left in plugins.js (reason in core_budget_test.go). Run: - mote-run: go vet ./..., GOOS=linux go vet -tags nogui ./..., GOOS=windows go vet ./...: ok. go test ./internal/plugin (169s) and ./internal/provider (148s): ok. - mica-run go test -count=1 ./internal/gui with the leftovers drawing moved into plugininstalled.js: ok (133s); main since touches none of internal/gui's core scripts, internal/plugin or plugins.go. - win-run go test -run 'Leftover|FailedAdd|AnotherPlugin|RemoveTakes| BunFailed' ./internal/plugin on xiaomi-gpu: ok. - Reproduced the EBUSY with Bun 1.4.2 on xiaomi-gpu (a file in node_modules/agency-agents held open, then bun add another package). - Red on the old store.go: TestLeftoverDoesNotFailAnotherAdd, TestFailedAddLeavesNoDependency, TestAnotherPluginsFailureDoesNotFailAdd, TestRemoveTakesDependencyOutWhenBunFails. - GUI: plugin-leftover.test.cjs 42/42 (chromium + webkit, en zh zh-TW ja de, 980/420px, with and without a plugin); old plugins.js: 21/21 chromium red. - mote-run, rebased onfdf42299e: plugin-leftover + i18n-keys 46/46; every other plugin*.test.cjs, old-webkit and i18n-en-no-cjk: 255 ok, reds only in old-webkit (#6030, #5919), plugin-move-unserved (#4392), plugin-option-placement (#6559) and plugin-page-foreign-error (#6117), each red the same on a clean origin/mainfdf42299echeckout. Not run: the full go test ./... and the whole GUI suite (mote over its cores, mica running another session's full suite; one per machine); a real Windows install through the magpie app.
73 lines
3.7 KiB
JavaScript
73 lines
3.7 KiB
JavaScript
// Installed narrowed as Discover is (WJaunita45604 on X): the same strip of
|
|
// kinds and the same Origin menu, over what is installed. Each plugin is
|
|
// put where Discover puts it: its card's kind and origin (kindOf, srcOf),
|
|
// and for one the market doesn't list, the same read from what it is: its
|
|
// chips' kind, a git one on GitHub, a @magpie-community package the
|
|
// community's, else another author's. plugins.js imports this when its
|
|
// page is first drawn, so it weighs nothing on the core; until then the
|
|
// list is drawn whole. st holds the picks; the strip and the menu show
|
|
// only where there are two or more to pick from.
|
|
window.pmInstalled = function ({ es, st, everything, entryOf, kindOf, srcOf, name, isGit, ORDER, SOURCES, kindStrip, originButton, drawBody }) {
|
|
const card = new Map();
|
|
for (const l of everything(() => true)) { const e = entryOf(l.package); if (e && !card.has(e)) card.set(e, l); }
|
|
const sorted = es.map((e) => {
|
|
const l = card.get(e);
|
|
if (l) return { e, kind: kindOf(l), src: srcOf(l) };
|
|
const kind = e.middleware || e.isMiddleware || e.gateway || e.isGateway ? "mw" : e.agent || e.isAgent ? "ag" : e.tools?.length && !e.providers?.length ? "tl" : e.page && !e.providers?.length ? "pg" : "pv";
|
|
return { e, kind, src: isGit(e.spec) ? "gh" : name(e.spec).startsWith("@magpie-community/") ? "ours" : "third" };
|
|
});
|
|
const kinds = ORDER.filter((k) => sorted.some((x) => x.kind === k));
|
|
const srcs = SOURCES.map(([v]) => v).filter((v) => v && sorted.some((x) => x.src === v));
|
|
if (!kinds.includes(st.kind) || kinds.length < 2) st.kind = "";
|
|
if (!srcs.includes(st.src) || srcs.length < 2) st.src = "";
|
|
const base = sorted.filter((x) => !st.src || x.src === st.src);
|
|
const shown = base.filter((x) => !st.kind || x.kind === st.kind).map((x) => x.e);
|
|
let none = null;
|
|
if (!shown.length) {
|
|
// a pick that leaves nothing says so, with the way back
|
|
none = el("div", "pm-ghnone");
|
|
const every = el("button", "text", t("Show all"));
|
|
every.type = "button";
|
|
every.onclick = () => { st.kind = st.src = ""; drawBody(); };
|
|
none.append(el("span", "", t("No plugin matches")), every);
|
|
}
|
|
return {
|
|
shown, none,
|
|
strip: kinds.length > 1 ? kindStrip(kinds, (k) => base.filter((x) => !k || x.kind === k).length, st.kind, (k) => { st.kind = k; drawBody(); }) : null,
|
|
pop: srcs.length > 1 ? originButton(st.src, null, (v) => { st.src = v; drawBody(); }) : null,
|
|
};
|
|
};
|
|
|
|
// what a failed install left in plugins/ that no plugin is installed as:
|
|
// Bun installs each again with every plugin, and one it can't install
|
|
// failed them all (agency-agents, CHENGJIAHEGOXIS on X). Each can be
|
|
// removed here, below Installed's list, empty or not.
|
|
window.pmLeftovers = function (body, mine, logo, act, busy) {
|
|
const ls = mine?.leftovers || [];
|
|
if (!ls.length) return;
|
|
const box = el("section", "pm-sec pm-leftovers");
|
|
const h = el("div", "pm-sechead");
|
|
h.append(el("h3", "", t("Not used by any plugin")));
|
|
const list = el("div", "list pm-list");
|
|
for (const x of ls) {
|
|
const r = el("div", "row pm-row");
|
|
r.dataset.leftover = x.name;
|
|
const who = el("div", "who");
|
|
const nm = el("div", "name");
|
|
nm.append(el("span", "", x.name));
|
|
if (x.version) nm.append(el("span", "pm-ver", "v" + x.version));
|
|
who.append(nm);
|
|
const val = el("div", "val");
|
|
const key = "leftover:" + x.name;
|
|
const rm = el("button", "text quiet", busy.get(key) === "leftover" ? t("Removing…") : t("Remove"));
|
|
rm.title = x.spec;
|
|
rm.disabled = busy.size > 0;
|
|
rm.onclick = () => act(key, "leftover", { spec: x.name });
|
|
val.append(rm);
|
|
r.append(logo("", false), who, val);
|
|
list.append(r);
|
|
}
|
|
box.append(h, list);
|
|
body.append(box);
|
|
};
|