library: a repository's card counts the skills its sheet lists once the repository is read

bdefdc319's repository card counted the skills skills.sh lists, while
its sheet, once Find skills' probe had read the repository, listed what
the repository holds: mattpocock/skills read 55 on the card and 39 in
the sheet, a number that changed on click.

A repository's read is now kept for the session (repoRead). Once it is
read, the card behind the sheet says the sheet's count at once, keeps
it when drawn again, and takes its Added from the read too; reopened,
the sheet lists the read repository straight away, the skills just
installed greyed, while it is read again. A later read that fails keeps
the one before; one with no SKILL.md drops it.

Run (mote, at origin/main e199eb9c7 + this):
- market-repo.test.cjs: 20 of 20, chromium and WebKit, five languages,
  420px. It now checks the card's count after the read, after the
  install's redraw, and the reopened sheet. With the card counting
  skills.sh's list again by hand, all 5 chromium first cases red.
- Every market-* file and i18n-keys: 132 of 132.
The whole GUI suite runs after the push, with bdefdc319's.
This commit is contained in:
yetone
2026-11-18 18:33:34 +08:00
parent e199eb9c79
commit 8634c4ad08
2 changed files with 54 additions and 13 deletions
+33 -8
View File
@@ -9101,8 +9101,13 @@ magpie.plugin("library", (ctx) => {
// A repository's card: its name, how many of its skills the list has,
// and their names; opened, every skill it holds, to pick from.
// a repository Find skills has read, by its lowercased name: its card
// then counts what the sheet lists, not what skills.sh does
const repoRead = new Map();
const repoCount = (g) => t("{n} skills", { n: repoRead.get(g.repo.toLowerCase())?.candidates.length ?? g.skills.length });
function repoCard(g) {
const fresh = g.skills.filter((x) => !x.have);
const read = repoRead.get(g.repo.toLowerCase());
const fresh = read ? read.candidates.filter((c) => !c.have) : g.skills.filter((x) => !x.have);
const c = el("div", "mk-card click mk-repo" + (fresh.length ? "" : " have"));
c.dataset.id = "repo:" + g.repo;
const top = el("div", "mk-top");
@@ -9112,7 +9117,7 @@ magpie.plugin("library", (ctx) => {
if (g.skills.some((x) => x.official)) { const o = el("span", "mk-official"); o.append(svg(CHECK, 9, 2.2)); o.title = t("Official — from the team that makes it"); nm.append(o); }
who.append(nm);
const meta = el("div", "mk-meta");
meta.append(el("span", "mk-pub mk-count", t("{n} skills", { n: g.skills.length })));
meta.append(el("span", "mk-pub mk-count", repoCount(g)));
who.append(meta);
top.append(logo(g.icon, g.repo), who);
const names = g.skills.map((x) => x.name).join(", ");
@@ -9223,7 +9228,11 @@ magpie.plugin("library", (ctx) => {
go.disabled = true;
go.textContent = t("Installing…");
let ok;
if (r.found) ok = await change("skills/install", { source: r.found.source, paths: [...r.pick], agents: r.agents }, done);
if (r.found) {
const paths = [...r.pick];
ok = await change("skills/install", { source: r.found.source, paths, agents: r.agents }, done);
if (ok) for (const c of r.found.candidates) if (paths.includes(c.path)) c.have = true;
}
else {
// one at a time, as each card's Add does
const picked = g.skills.filter((x) => r.pick.has("m:" + x.skillId));
@@ -9240,17 +9249,33 @@ magpie.plugin("library", (ctx) => {
openLib(ed);
// the whole repository, as Find skills reads it; the list's picks
// carried over by the folder name the market installs by
api("library/skills/probe", { source: g.repo }).then((p) => {
if (!ed.isConnected) return;
// read before: the sheet opens on it, as its card counts it
const adopt = (p) => {
const byId = (id) => p.candidates.find((c) => c.name === id) || p.candidates.find((c) => c.path.split("/").pop() === id);
const pick = new Set();
for (const k of r.pick) { const c = byId(k.slice(2)); if (c && !c.have) pick.add(c.path); }
if (!p.candidates.length) { r.error = t("No SKILL.md found there"); draw(); return; }
for (const k of r.pick) {
if (!k.startsWith("m:")) { if (p.candidates.some((c) => c.path === k && !c.have)) pick.add(k); continue; }
const c = byId(k.slice(2));
if (c && !c.have) pick.add(c.path);
}
Object.assign(r, { found: p, pick });
drawList();
draw();
};
const key = g.repo.toLowerCase();
if (repoRead.has(key)) adopt(repoRead.get(key));
api("library/skills/probe", { source: g.repo }).then((p) => {
if (!p.candidates.length) {
repoRead.delete(key);
if (ed.isConnected) { r.found = null; r.error = t("No SKILL.md found there"); draw(); }
return;
}
repoRead.set(key, p);
// the card behind says the count the sheet lists
for (const n of document.querySelectorAll(".mk-repo .mk-count")) if (n.closest(".mk-repo").dataset.id.toLowerCase() === "repo:" + key) n.textContent = repoCount(g);
if (ed.isConnected) adopt(p);
}, (e) => {
if (!ed.isConnected) return;
if (!ed.isConnected || r.found) return;
r.error = e.message;
draw();
});
+21 -5
View File
@@ -35,11 +35,11 @@ const candidates = [
{ name: "caveman", path: "skills/caveman", description: "Talks less.", have: true },
];
const words = {
en: { skills: "3 skills", choose: "Choose…", install: "Install {n} skills", one: "Install 1 skill" },
zh: { skills: "3 个技能", choose: "选择…", install: "安装 {n} 个技能", one: "安装 1 个技能" },
"zh-TW": { skills: "3 個技能", choose: "選擇…", install: "安裝 {n} 個技能", one: "安裝 1 個技能" },
ja: { skills: "3 件のスキル", choose: "選択…", install: "{n} 個のスキルをインストール", one: "1 個のスキルをインストール" },
de: { skills: "3 Skills", choose: "Auswählen…", install: "{n} Skills installieren", one: "1 Skill installieren" },
en: { skills: "3 skills", five: "5 skills", choose: "Choose…", install: "Install {n} skills", one: "Install 1 skill" },
zh: { skills: "3 个技能", five: "5 个技能", choose: "选择…", install: "安装 {n} 个技能", one: "安装 1 个技能" },
"zh-TW": { skills: "3 個技能", five: "5 個技能", choose: "選擇…", install: "安裝 {n} 個技能", one: "安裝 1 個技能" },
ja: { skills: "3 件のスキル", five: "5 件のスキル", choose: "選択…", install: "{n} 個のスキルをインストール", one: "1 個のスキルをインストール" },
de: { skills: "3 Skills", five: "5 Skills", choose: "Auswählen…", install: "{n} Skills installieren", one: "1 Skill installieren" },
};
function serve(lang, st) {
@@ -139,6 +139,8 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
await page.waitForFunction(() => document.querySelectorAll("#modal .mk-reposheet .lib-pick").length === 5);
assert.deepEqual(st.probed, ["mattpocock/skills"]);
assert.equal(await sheet.locator(".mk-repowait").count(), 0);
// the card behind now counts what the sheet lists, not skills.sh
assert.equal((await repo.locator(".mk-count").textContent()).trim(), w.five);
// the list's still ticked, the rest not, the one had greyed
assert.deepEqual(await rows.evaluateAll((rs) => rs.map((r) => [r.querySelector(".name").textContent, r.querySelector("input").checked, r.querySelector("input").disabled])),
[["tdd", true, false], ["grill-me", true, false], ["write-a-prd", true, false], ["triage", false, false], ["caveman", false, true]]);
@@ -155,6 +157,20 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
await go.click();
await sheet.waitFor({ state: "detached" });
assert.deepEqual(st.installs, [["skills/install", { source: "mattpocock/skills", paths: ["skills/grill-me", "skills/triage"], agents: ["claude"] }]]);
// drawn again, the card keeps the sheet's count
assert.equal((await repo.locator(".mk-count").textContent()).trim(), w.five);
// opened again, the sheet lists the read repository at once, the
// two just installed greyed, while it is read again
const [again, letAgain] = gate();
st.probeGate = again;
await repo.click();
await sheet.waitFor();
assert.equal(await sheet.locator(".mk-repowait").count(), 0);
assert.deepEqual(await rows.evaluateAll((rs) => rs.map((r) => [r.querySelector(".name").textContent, r.querySelector("input").checked, r.querySelector("input").disabled])),
[["tdd", true, false], ["grill-me", false, true], ["write-a-prd", true, false], ["triage", false, true], ["caveman", false, true]]);
letAgain();
await page.waitForFunction(() => document.querySelector("#modal .mk-reposheet") && !document.querySelector(".mk-repowait"));
assert.equal(st.probed.length, 2);
assert.deepEqual(errors, []);
});