feat(herdr): show an operation's outcome before skillshare answers (#844)

* feat(herdr): enable and disable skills and agents from the panel

The Library lists disabled skills under Off, but the panel had no way
to turn one back on or to turn one off: that meant leaving Herdr for
the CLI or the dashboard.

A skill's or agent's preview now offers Disable, or Enable when it is
disabled. It asks first, then runs skillshare disable / enable with the
entry's own path, the pattern the dashboard writes, so enable removes
exactly what disable added. The next sync applies the change.

Exit 0 only means the entry's own line was written or was not there. A
glob, a folder pattern or a negation in the .local file can still
decide the other way, so the panel reads the list afterwards and
reports an entry that did not change instead of claiming success.

The confirm dialog shares the hook dialog's branch under the role
"able": "toggle" is already the tab-bar button's role, and an overlay
opened with it draws that button.

* feat(herdr): show an operation's outcome before skillshare answers

Every operation waited for the CLI and then for the next full read
before a row moved, so a click looked like nothing happened for
seconds.

The panel now lays its running requests over the rows it has read. A
disable, an enable, an uninstall and a hook change show their outcome
at once, and a finished install lists its skills without waiting for
the read. An update and a sync can be stopped by an audit or a failed
target, so their rows only say "updating…" or "syncing…" rather than
claim a result.

A request that fails is dropped and the rows go back. Otherwise the
first read that starts after the request ended replaces the guess; a
read already in flight when it ended is followed by another, which
also closes the gap where the post-operation refresh was skipped and
the list stayed stale until the next poll.

Git sync, upgrading skillshare and updating the panel are not guessed:
their result depends on the remote.

* refactor(herdr): decide the pending requests' fate in the model

Which optimistic rows survive a read, when an update's rows give way to
the checks, and whether another read is needed were decided inline in
main.js, which the node tests cannot load. herdr/AGENTS.md asks for new
logic in tested modules and main.js kept to views.

shownRows, endedRequests, afterRead and afterChecks now hold those
decisions in model.js; main.js only stores the list. Tests cover a
request ending during a read, a read newer than the request, an update
waiting for the checks, a failed request dropped, and another machine's
request.
This commit is contained in:
Willie
2026-11-11 00:10:34 +08:00
committed by GitHub
parent 709f5ce896
commit 68fd28597f
4 changed files with 151 additions and 12 deletions
+1
View File
@@ -62,6 +62,7 @@ Left to right, everything as in Herdr's `main` layout, plus two blocks:
- Commit and push with a commit message field when files are uncommitted, or Push n commits when only commits are waiting.
- When a pull stops on files both machines changed, the conflict dialog shows each file's two versions with the differing lines marked. You keep one version per file and then apply. `.metadata.json` merges per entry the way skillshare's own pull does, so only real files ask.
- The panel updates itself. `version.js` holds the skillshare release it shipped with. Once an hour while shown it asks, on this computer, where `github.com/runkids/skillshare/releases/latest` lands, and offers "Update panel" when that release is newer. The update clones only `herdr/skillshare/mods/skillshare` at that tag, checks that `mods/skillshare` in Herdr's home holds this panel's version, copies the current files once to the mod folder's `.bak-update-<version>`, and copies the new files in with `main.js` after its modules and `version.js` last. Herdr reloads the panel, and the new build says "Updated the panel to v…". The layout is not touched.
- The list answers a click before skillshare does. `optimistic` (model) lays every request still running, or ended and not yet read back, over the rows: a disable, an enable, an uninstall and a hook change show their outcome at once, and a finished install lists its skills; an update and a sync can be stopped, so their rows only say "updating…" or "syncing…". A request that fails is dropped and the rows go back; otherwise the read that starts after the request ended replaces them (an update's rows wait for the checks). Git sync, upgrading skillshare and updating the panel are not guessed.
- Hook changes (Enable, Disable and Remove), enabling or disabling a skill or agent, Uninstall, the audit hand-off, conflict choices, updating skillshare itself and updating the panel each ask first. Sync applies hook changes through `sync --all`.
## Built from
+22 -11
View File
@@ -11,7 +11,7 @@ import { v_flex, h_flex, InputState, Input, TextView, HoverCard } from "gpui-bas
import { exec, hc, run, spaces, agents, focused, machines, shared, setShared, theme, settings, layout, openOverlay, closeOverlay, nextCommand, readTextFile, knownAgents, props as blockProps } from "herdr";
import {
KINDS, SCOPES, DISCOVER, AUDIT,
parseJSON, lastLine, failure, flag, sourceLine, buildItems, hookArgs, toggleArgs, rowState, previewTargets, eligibleTargets, targetList, waitsForSync, syncScopes, overviewAnswer, remoteLine, waitingNames, mapLanes, needsBothWays, filterItems, groupItems, sourceGroups, counts,
parseJSON, lastLine, failure, flag, sourceLine, buildItems, shownRows, endedRequests, afterRead, afterChecks, hookArgs, toggleArgs, rowState, previewTargets, eligibleTargets, targetList, waitsForSync, syncScopes, overviewAnswer, remoteLine, waitingNames, mapLanes, needsBothWays, filterItems, groupItems, sourceGroups, counts,
cloneUrl, installResult, newerVersion, panelUpdate, updateState, ago, auditMessage, parseDiscover, parseAudit,
} from "./model.js";
import { createRunner } from "./jobs.js";
@@ -260,7 +260,7 @@ export default class Skillshare extends View {
if (this.role !== "panel") return this.initDialog(cx);
this.view = "overview"; this.scope = "all"; this.kind = "skills"; this.query = ""; this.expanded = new Set();
this.ctx = null; this.project = null; this.raw = {}; this.items = []; this.git = null; this.loading = false; this.loadedAt = 0;
this.ctx = null; this.project = null; this.raw = {}; this.items = []; this.pending = []; this.git = null; this.loading = false; this.loadedAt = 0;
this.checks = {}; this.checkedAt = 0; this.nextRequest = channel.listen(); this.shownNotice = null;
this.lastAgent = null; this.machines = {}; this.machinesAt = 0; this.version = null; this.token = 0;
this.latest = null; this.latestAt = 0;
@@ -308,7 +308,7 @@ export default class Skillshare extends View {
const ctx = this.ctx;
if (!ctx || this.loading) return;
this.loading = true;
const token = this.token;
const token = this.token, ended = endedRequests(this.pending);
cx.spawn(async (cx) => {
try {
const { on, folder, spaceFolder } = ctx;
@@ -320,16 +320,22 @@ export default class Skillshare extends View {
const res = await loadResources(io, on, project, network);
if (token !== this.token) return;
this.raw = res.raw; this.git = res.git; this.version = res.version ?? this.version; this.error = res.error;
const { pending, late } = afterRead(this.pending, ended, wantCheck);
this.pending = pending;
this.rebuild(); this.loadedAt = Date.now();
cx.notify();
if (wantCheck) {
this.checkKey = `${on}:${project}`; this.checkedAt = Date.now();
const checks = await loadChecks(io, on, project);
if (token !== this.token) return;
this.checks = checks;
this.checks = checks; this.pending = afterChecks(this.pending, late);
this.rebuild(); cx.notify();
}
} catch (e) { this.error = String(e?.message ?? e); cx.notify(); } finally { if (token === this.token) this.loading = false; }
} catch (e) { this.error = String(e?.message ?? e); this.pending = afterRead(this.pending, ended, false).pending; this.rebuild(); cx.notify(); } finally {
if (token === this.token) this.loading = false;
// A request that ended while this read ran is not in it: read again, or its rows stay a guess.
if (token === this.token && endedRequests(this.pending).length) this.refresh(cx, false);
}
});
}
@@ -343,7 +349,8 @@ export default class Skillshare extends View {
}
rebuild() {
this.items = Object.entries(this.raw).flatMap(([scope, r]) => buildItems(scope, { ...r, ...(this.checks[scope] ?? {}) }));
const read = Object.entries(this.raw).flatMap(([scope, r]) => buildItems(scope, { ...r, ...(this.checks[scope] ?? {}) }));
this.items = shownRows(read, this.pending, this.ctx?.on, this.project);
}
// ---- Work handed over by dialogs, and the panel's own buttons ----
@@ -361,6 +368,8 @@ export default class Skillshare extends View {
}
if (!channel.claim(req.on, "Working…")) { if (req.op !== "refresh") channel.say("warn", "skillshare is busy on that machine; try again when it finishes"); return; }
if (req.op === "panel") setShared(UPDATING, { to: req.to, at: Date.now() });
this.pending.push(req); this.rebuild(); cx.notify();
const drop = () => { this.pending = this.pending.filter((r) => r !== req); this.rebuild(); };
cx.spawn(async (cx) => {
const step = (text) => { channel.step(req.on, text); cx.notify(); };
try {
@@ -371,7 +380,9 @@ export default class Skillshare extends View {
if (res.overlay) openDialog({ width: 620, height: 520, props: { role: "text", ...res.overlay } });
if (res.machines) this.machinesAt = 0;
if (res.kind) channel.say(res.kind, res.text);
} finally {
if (res.kind === "error") drop(); // it did not happen: the rows go back at once
} catch (e) { drop(); throw e; } finally {
req.ended = true;
if (["update", "uninstall", "syncboth", "resolve", "pull", "refresh"].includes(req.op)) this.checkedAt = 0; // their update state changed
channel.release(req.on);
this.refresh(cx, false);
@@ -548,7 +559,7 @@ export default class Skillshare extends View {
if (groups.sync.length) sections.push(this.groupHeader(t, "sync", `NEEDS SYNC · ${groups.sync.length}`, t.blocked, null), ...rows(groups.sync));
if (groups.update.length) {
sections.push(this.groupHeader(t, "update", `UPDATE AVAILABLE · ${groups.update.length}`, t.accent,
groups.update.length > 1 ? secondary("update-all", "Update all", t, () => this.updateAll(groups.update, ctx), { h: 24, px: 9, size: S().label }) : null), ...rows(groups.update));
groups.update.filter((i) => !i.doing).length > 1 ? secondary("update-all", "Update all", t, () => this.updateAll(groups.update, ctx), { h: 24, px: 9, size: S().label }) : null), ...rows(groups.update));
}
const groupable = this.kind === "skills" || this.kind === "agents", bySource = groupable && shared(IN_SYNC_VIEW) !== "list";
if (live.length) sections.push(this.groupHeader(t, "ok", `IN SYNC · ${live.length}`, t.muted, null).when(groupable, (el) => el.child(this.viewSwitch(t, bySource))));
@@ -631,7 +642,7 @@ export default class Skillshare extends View {
// A row is a name and one short state. Everything else, and every action, is in its preview.
row(t, item, showScope, ctx) {
const color = item.notice || item.diagnostic ? t.blocked : { update: t.accent, sync: t.blocked, missing: t.ansi1, ok: t.ansi2, off: t.muted }[item.state] ?? t.muted;
const update = item.state === "update" && (item.kind === "skills" || item.kind === "agents") && !this.busyAt(ctx.on)
const update = item.state === "update" && !item.doing && (item.kind === "skills" || item.kind === "agents") && !this.busyAt(ctx.on)
? secondary(`update-${item.key}`, "Update", t, (_e, cx) => { cx.stop_propagation(); request({ op: "update", on: ctx.on, project: this.project, updates: [{ kind: item.kind, scope: item.scope, name: item.update, label: item.label }] }); }, { h: 24, px: 9, size: S().label })
: null;
return line(t, `row-${item.key}`, dot(color, 8, item.state === "missing" || item.state === "off"), item.notice ? item.reason || item.label : item.label,
@@ -920,7 +931,7 @@ export default class Skillshare extends View {
lead.push(action === "remove" ? textButton(`${role}-remove`, label, t, open, t.ansi1) : dialogButton(`${role}-${action}`, label, t, open));
}
const buttons = [];
if (it.state === "update" && skillish) {
if (it.state === "update" && !it.doing && skillish) {
if (it.kind === "skills") buttons.push(dialogButton("changes", "See changes", t, ask({ op: "text", on: p.on, cwd, busy: `Reading changes in ${it.label}…`, title: `Changes in “${it.label}”`, args: ["check", it.update, "--diff", flag(it.scope)] })));
buttons.push(dialogButton("update", p.busy ? "Working…" : "Update", t, ask({ op: "update", on: p.on, project: p.project, updates: [{ kind: it.kind, scope: it.scope, name: it.update, label: it.label }] }), "primary", !p.busy));
} else {
@@ -1145,7 +1156,7 @@ export default class Skillshare extends View {
else { pr.at = 3; pr.done = result.done; }
this.dropClone(p);
} finally { channel.release(p.on); }
request({ op: "refresh", on: p.on });
request({ op: "refresh", on: p.on, project: p.project, added: (pr.done ?? []).map((name) => ({ name, scope: this.scope, source: this.source })) });
cx.notify();
});
}
+40
View File
@@ -420,10 +420,50 @@ export function toggleArgs(item, action) {
return [action, item.path, ...(item.kind === "agents" ? ["--kind", "agent"] : []), flag(item.scope)];
}
// The rows as they will be once a running request lands, so the list answers the click and not
// the read that follows it. req: what the panel was asked ({ op, item, action, updates, scopes,
// plugins, added, project }); project: the folder the rows are for, since project rows of
// another folder are not these rows. What cannot fail quietly is shown done: a disable, an
// enable, a removal. An update and a sync can be stopped (an audit, a conflict), so their rows
// only say they are running (`doing`). The read after the request replaces all of it; a request
// that fails is simply dropped, and the rows are back as they were.
export function optimistic(items, req, project = req.project) {
const ours = (i) => i.scope !== "project" || (req.project ?? null) === (project ?? null);
const one = (change) => items.flatMap((i) => (i.key === req.item?.key && ours(i) ? change(i) : [i]));
const doing = (text, hit) => items.map((i) => (ours(i) && hit(i) ? { ...i, doing: text } : i));
const able = (i) => [{ ...i, disabled: req.action === "disable", state: req.action === "disable" ? "off" : "ok" }];
if (req.op === "toggle") return one(able);
if (req.op === "hook") return one(req.action === "remove" ? () => [] : able);
if (req.op === "uninstall") return one(() => []);
if (req.op === "update") return doing("updating", (i) => i.state === "update" && (req.updates ?? []).some((u) => u.kind === i.kind && u.scope === i.scope && (u.all || u.name === i.update)));
if (req.op === "sync") return doing("syncing", (i) => !i.notice && waitsForSync(i) && (req.scopes ?? []).includes(i.scope) && (i.kind !== "plugins" || req.plugins));
if (req.op === "refresh" && req.added?.length) {
const fresh = req.added.filter((a) => ours(a) && !items.some((i) => i.kind === "skills" && i.scope === a.scope && i.label === a.name));
return [...items, ...fresh.map((a) => ({ key: `${a.scope}:skills:${a.name}`, kind: "skills", scope: a.scope, name: a.name, label: a.name, rel: a.name, path: a.name, src: shortSource(a.source) || "local", disabled: false, version: null, state: "ok", repo: null }))];
}
return items;
}
// The panel keeps every request from the click until a read newer than its end has landed.
// These four decide what that list holds; main.js only stores it.
// The rows to show on machine `on`: what was read, with that machine's requests laid over it.
export const shownRows = (read, pending, on, project) => pending.filter((r) => (r.on ?? null) === (on ?? null)).reduce((items, r) => optimistic(items, r, project), read);
// The requests a read starting now is newer than. One that ends later is not in that read.
export const endedRequests = (pending) => pending.filter((r) => r.ended);
// After a read's list has landed. ended: endedRequests when it started; checking: the same read
// also runs the update checks. An update shows in the checks, so its request stays (late) until
// afterChecks. Anything still ended in what is left needs one more read.
export function afterRead(pending, ended, checking) {
const late = checking ? ended.filter((r) => r.op === "update") : [];
return { pending: pending.filter((r) => !ended.includes(r) || late.includes(r)), late };
}
export const afterChecks = (pending, late) => pending.filter((r) => !late.includes(r));
// A row's one short state; everything longer is in its preview.
export function rowState(item, showScope) {
const pre = showScope ? `${item.scope} · ` : "";
if (item.notice) return item.scope;
if (item.doing) return `${pre}${item.doing}…`;
const state = { update: "update available", missing: "new", sync: "changed", unknown: "sync status unknown" }[item.state];
if (state) return pre + state;
if (item.state === "off") return `${pre}disabled`;
+88 -1
View File
@@ -4,7 +4,7 @@ import { spawn, spawnSync } from "node:child_process";
import { mkdtempSync, mkdirSync, writeFileSync, readFileSync, readdirSync, existsSync, rmSync, utimesSync } from "node:fs";
import { tmpdir } from "node:os";
import { join } from "node:path";
import { parseGitStatus, sourceLine, driftFrom, targetDrift, buildItems, hookArgs, counts, groupItems, filterItems, sourceGroups, cloneUrl, installResult, newerVersion, parseDiscover, parseAudit, parsePreview, diffSides, mergeMetadata, START, ALIVE, SWEEP, SNAPSHOT, parseSnapshot, rowState, previewTargets, splitFrontmatter, mcpServer, targetList, mapLanes, needsBothWays, READ_SKILL, eligibleTargets, syncScopes, overviewAnswer, remoteLine, waitingNames, releaseTag, panelUpdate, updateState, PANEL_UPDATE, toggleArgs, DISCOVER } from "../skillshare/mods/skillshare/model.js";
import { parseGitStatus, sourceLine, driftFrom, targetDrift, buildItems, hookArgs, counts, groupItems, filterItems, sourceGroups, cloneUrl, installResult, newerVersion, parseDiscover, parseAudit, parsePreview, diffSides, mergeMetadata, START, ALIVE, SWEEP, SNAPSHOT, parseSnapshot, rowState, previewTargets, splitFrontmatter, mcpServer, targetList, mapLanes, needsBothWays, READ_SKILL, eligibleTargets, syncScopes, overviewAnswer, remoteLine, waitingNames, releaseTag, panelUpdate, updateState, PANEL_UPDATE, toggleArgs, optimistic, shownRows, endedRequests, afterRead, afterChecks, DISCOVER } from "../skillshare/mods/skillshare/model.js";
import { VERSION } from "../skillshare/mods/skillshare/version.js";
test("git status reads branch, ahead/behind and files", () => {
@@ -700,3 +700,90 @@ test("a row offers only the change it can take", () => {
const [skill] = buildItems("global", { list: [{ name: "archify", relPath: "archify", kind: "skill" }] });
assert.deepEqual([toggleArgs(skill, "enable"), toggleArgs({ kind: "mcp", name: "m", scope: "global" }, "disable")], [null, null]);
});
// Rows as the panel holds them: two skills, one waiting for an update and one for a sync, per scope.
const held = (scope) => buildItems(scope, {
list: [{ name: "archify", relPath: "archify", kind: "skill" }, { name: "figlens", relPath: "figlens", kind: "skill" }, { name: "draft", relPath: "draft", kind: "skill", disabled: true }],
check: { skills: [{ name: "archify", status: "update_available" }] },
diff: { targets: [{ name: "claude", items: [{ name: "figlens", kind: "skill", action: "modify", is_sync: true }] }] },
});
const states = (items) => items.map((i) => `${i.label}:${i.doing ?? i.state}`);
test("the rows start as the test expects", () => {
assert.deepEqual(states(held("global")), ["archify:update", "figlens:sync", "draft:off"]);
});
test("a disable shows the row off, and an enable shows it on, before skillshare answers", () => {
const items = held("global");
const off = optimistic(items, { op: "toggle", action: "disable", item: items[1] });
const on = optimistic(items, { op: "toggle", action: "enable", item: items[2] });
assert.deepEqual([states(off), states(on)], [["archify:update", "figlens:off", "draft:off"], ["archify:update", "figlens:sync", "draft:ok"]]);
});
test("an uninstall and a hook removal take the row away at once", () => {
const items = [...held("global"), { key: "global:hooks:lint", kind: "hooks", scope: "global", name: "lint", label: "lint", state: "ok" }];
const gone = optimistic(optimistic(items, { op: "uninstall", item: items[0] }), { op: "hook", action: "remove", item: items[3] });
assert.deepEqual(states(gone), ["figlens:sync", "draft:off"]);
});
test("an update and a sync only say they are running: they can still fail", () => {
const items = held("global");
const updating = optimistic(items, { op: "update", updates: [{ kind: "skills", scope: "global", name: "archify" }] });
const syncing = optimistic(items, { op: "sync", scopes: ["global"] });
assert.deepEqual([states(updating), states(syncing)], [["archify:updating", "figlens:sync", "draft:off"], ["archify:update", "figlens:syncing", "draft:off"]]);
});
test("a running row says so in its one short state", () => {
const [row] = optimistic(held("global"), { op: "update", updates: [{ kind: "skills", scope: "global", name: "archify" }] });
assert.equal(rowState(row, true), "global · updating…");
});
test("an installed skill is listed before the next read, once", () => {
const items = held("global");
const req = { op: "refresh", added: [{ name: "pdf", scope: "global", source: "https://github.com/acme/skills" }, { name: "archify", scope: "global", source: "x" }] };
assert.deepEqual(optimistic(items, req).slice(3).map((i) => [i.key, i.state, i.src]), [["global:skills:pdf", "ok", "github.com/acme/skills"]]);
});
test("another project's rows are left alone", () => {
const items = held("project");
const req = { op: "uninstall", project: "/a", item: items[0] };
assert.deepEqual([optimistic(items, req, "/b").length, optimistic(items, req, "/a").length], [3, 2]);
});
test("Update all marks every row of that kind and scope that has an update", () => {
const rows = optimistic(held("global"), { op: "update", updates: [{ kind: "skills", scope: "global", all: true }] });
assert.deepEqual(states(rows), ["archify:updating", "figlens:sync", "draft:off"]);
});
// The panel's requests while one read runs: `ended` is what had ended when the read started.
const uninstall = (items, more = {}) => ({ op: "uninstall", item: items[0], ...more });
test("a request that ends while a read runs outlives that read and asks for another", () => {
const items = held("global"), req = uninstall(items);
const ended = endedRequests([req]); // the read starts while the request still runs
req.ended = true;
const left = afterRead([req], ended, false).pending;
assert.deepEqual([left, endedRequests(left).length, states(shownRows(items, left, null, null))], [[req], 1, ["figlens:sync", "draft:off"]]);
});
test("a read that started after a request ended replaces its rows", () => {
const req = uninstall(held("global"), { ended: true });
assert.deepEqual(afterRead([req], endedRequests([req]), true), { pending: [], late: [] });
});
test("an update's rows wait for the checks that the same read brings", () => {
const items = held("global"), req = { op: "update", ended: true, updates: [{ kind: "skills", scope: "global", name: "archify" }] };
const { pending, late } = afterRead([req], endedRequests([req]), true);
assert.deepEqual([states(shownRows(items, pending, null, null)), afterChecks(pending, late), afterRead([req], [req], false).pending],
[["archify:updating", "figlens:sync", "draft:off"], [], []]);
});
test("a failed request dropped from the list puts its rows back", () => {
const items = held("global"), req = uninstall(items);
assert.deepEqual([states(shownRows(items, [req], null, null)).length, states(shownRows(items, [], null, null)).length], [2, 3]);
});
test("a request on another machine does not touch this machine's rows", () => {
const items = held("global");
assert.equal(shownRows(items, [uninstall(items, { on: "mac-mini" })], null, null).length, 3);
});