library: a note on a skill or an MCP server, the library's own (youyo.p_10001)

youyo.p_10001 on Discord: with many skills and MCP servers installed,
you can't tell what each is for or which to use. A skill has the
description its author wrote for models, often in English and about
what it does, not why you installed it. An MCP server has nothing but
its command and its tool list. So each now takes a note in the user's
own words.

- Server.Note and Skill.Note in library.json: one line of at most 200
  characters, whitespace run together (checkNote), as a hook's
  description (#2011). A longer one is turned away, not cut.
- The server editor has a Note field under the name. A skill's reader
  (2a19043af's file reader) has one over its files: Save shows once it
  changes, saves the file being edited with it, and a changed note is
  asked about before the dialog closes. SkillNote, POST skills/note.
- A row shows the note in place of its command or description, so rows
  keep their height; the tooltip gives the note, then that line. The
  skills' filter matches notes.
- No agent is given a note: not in any agent's MCP entry, a project's
  file, the MCP router's list or a skill's copied SKILL.md.
- A sync carries it (CarriedSkill.Note; a server goes whole), and
  clearing it is carried too. An older magpie on another computer
  doesn't know notes: a bundle it writes has none, so a sync from it
  clears them. The TUI's server editor keeps a note as it was.

Run at the pushed head:
Run at the pushed head (on origin/main f168dd278, then
rebased onto 94d0fbfcd, whose two commits change only
migrate_zcode.go and the searcher-pick test):
- mote: go test -timeout 45m internal/library (TestNoteNeverGiven,
  TestNoteCarried, TestNoteTooLong), gui, tui, davsync, backup: ok,
  except internal/gui's TestMainWindowCorners/macOS_26_SDK, mote's SDK
  (#3949). GOOS=windows go vet of library, gui, tui and GOOS=linux of
  library, tui: clean. gofmt -l: clean.
- mote, both engines, every language, narrow and wide: skill-edit (the
  skill reader's note), library-mcp-json (the server's note, its row and
  the filter), mcp-editor-cancel, library-mcp-win-line, market-address,
  market-have, i18n-keys: 108 of 108.
- WSL, the whole GUI suite: no red in a library file that origin/main
  hasn't too (see the command commit; #4120, #4471 for the rest).
- "Note" is in core i18n.js, not the plugin's: agent code says it as a
  word. The rebase had dropped main's title on a server row's command
  line (library-mcp-win-line went red); it is back, and with a note the
  tooltip gives the note, then that line.

Broken by hand, each red, then restored:
- add("note", s.Note) in Claude's MCP format: TestNoteNeverGiven
  (.claude.json held the note).
- the carry of Note left out: TestNoteCarried.
- note left out of the server editor's save: the GUI test, 22 of 22.
- notes left out of the skills' filter text: the GUI test, 22 of 22.
- the note's save left out of the skill reader's Save: skill-edit, 22
  of 22 (Save never goes away).
- the note left out of the reader's unsaved check: skill-edit, 22 of 22
  (closing never asks).

Not tried: a real sync between two computers, a real agent reading its
config (the guard reads every file magpie writes in a sandbox HOME), a
real app window, Linux WebKitGTK.
This commit is contained in:
yetone
2026-11-03 21:43:54 +08:00
parent a80575cc86
commit 50265256ba
13 changed files with 353 additions and 30 deletions
File diff suppressed because one or more lines are too long
+4
View File
@@ -1719,6 +1719,7 @@ const I18N = {
"{agent} is on the routing group {group}, {model} here among its members — click to change": "{agent} 正在使用路由组 {group},{model} 为其成员 — 点击更改",
"e.g. My Relay": "例如 My Relay",
"Name": "名称",
"Note": "备注",
"Form": "表单",
"OpenAI compatible": "OpenAI 兼容",
"Base URL: type the {api} URL, or pick the API the URL you have is for": "Base URL:请填写 {api} 的地址,或改选你已有地址所属的协议",
@@ -6271,6 +6272,7 @@ const I18N = {
"{agent} is on the routing group {group}, {model} here among its members — click to change": "{agent} 正在使用路由組 {group},{model} 為其成員 — 點選更改",
"e.g. My Relay": "例如 My Relay",
"Name": "名稱",
"Note": "備註",
"Form": "表單",
"OpenAI compatible": "OpenAI 相容",
"Base URL: type the {api} URL, or pick the API the URL you have is for": "Base URL:請填寫 {api} 的位址,或改選你已有位址所屬的協議",
@@ -10799,6 +10801,7 @@ const I18N = {
"{agent} is on the routing group {group}, {model} here among its members — click to change": "{agent} はルーティンググループ {group} を使用中で、ここの {model} はそのメンバーです — クリックして変更",
"e.g. My Relay": "例:My Relay",
"Name": "名前",
"Note": "メモ",
"Form": "フォーム",
"OpenAI compatible": "OpenAI 互換",
"Base URL: type the {api} URL, or pick the API the URL you have is for": "Base URL:{api} の URL を入力するか、お持ちの URL が対応する API を選んでください",
@@ -15358,6 +15361,7 @@ const I18N = {
"{agent} is on the routing group {group}, {model} here among its members — click to change": "{agent} nutzt die Weiterleitungsgruppe {group}, zu der {model} gehört — zum Ändern klicken",
"e.g. My Relay": "z. B. Mein Relay",
"Name": "Name",
"Note": "Notiz",
"Form": "Formular",
"OpenAI compatible": "OpenAI-kompatibel",
"Base URL: type the {api} URL, or pick the API the URL you have is for": "Base URL: Gib die {api}-URL ein, oder wähle die API, für die deine URL ist",
+65 -14
View File
@@ -2076,6 +2076,17 @@ magpie.plugin("library", (ctx) => {
openLib(ed);
}
// a row's line under its name: the user's note when there is one, in
// the place of what it would say (a skill's description, a server's
// command), which its tooltip then gives after the note. A row keeps its
// height either way
function noteSub(note, sub, said) {
if (!note) return sub;
const n = el("div", "sub lib-subnote", note);
n.title = said ? note + "\n\n" + said : note;
return n;
}
function serverRow(s, all) {
const row = el("div", "row lib-row click lib-server");
const who = el("div", "who");
@@ -2091,7 +2102,7 @@ magpie.plugin("library", (ctx) => {
who.append(nm, healthEl(s.name));
const sub = el("div", "sub mono", serverLine(s));
sub.title = serverLine(s);
who.append(sub, toolsEl(s.name));
who.append(noteSub(s.note, sub, serverLine(s)), toolsEl(s.name));
row.append(mark(s.icon, s.transport === "stdio" ? GLYPH.cmd : GLYPH.web), who, ...removeAct(() => confirmRemoveServer(s)),
agentChips(withGone(all, s.agents), s.agents, chipsChange("servers/agents", s.name, "servers", (x) => serverRow(x, all)), { problems: s.problems, blocked: sseBlocked(s), all: true }));
if (picking) return pickRow(row, s.name);
@@ -2743,6 +2754,24 @@ magpie.plugin("library", (ctx) => {
return ta;
}
// noteBox is the user's note on a server or a skill (youyo.p on Discord:
// with many, which is which and when to use it). One line of at most 200
// characters, as a hook's description (#2011); the library alone keeps
// it, and no agent is given it.
const NOTE_MAX = 200;
function noteBox(value, placeholder, onInput) {
const ta = el("textarea", "lib-text small lib-notein");
ta.rows = 1;
ta.value = value || "";
ta.placeholder = placeholder;
ta.maxLength = NOTE_MAX;
ta.oninput = () => onInput(ta.value);
ta.onkeydown = (e) => { e.stopPropagation(); if (e.isComposing || e.keyCode === 229) return; if (e.key === "Escape") closeLibModal(); else if (e.key === "Enter" && modal?.save) { e.preventDefault(); modal.save(); } };
autosize(ta, 27);
return ta;
}
const noteHint = () => t("Optional: what it's for and when to use it, in any language. Only the library keeps it; no agent is given it");
// refHint: how a value is read from a variable (#1250)
const refHint = () => t("A value can name a variable, as {ref}: each agent is given it in its own way, so the token stays out of its settings", { ref: "${NAME}" });
@@ -2757,14 +2786,15 @@ magpie.plugin("library", (ctx) => {
if (!d.env) d.env = {};
if (!d.headers) d.headers = {};
d.local = !!d.local;
d.note = d.note || "";
const ed = el("div", "editor lib-editor");
const head = el("div", "ehead lib-serverhead");
head.append(mark(s?.icon, d.transport === "stdio" ? GLYPH.cmd : GLYPH.web), el("b", "", s ? s.name : t("New MCP server")));
if (!s) head.append(el("span", "note", t("or paste its JSON anywhere here")));
// the form, or the server as JSON (hema_17384 on Discord), in Claude
// Code's .mcp.json shape, as Copy config gives it: read whole, edited,
// pasted over. The agents and sync are the library's own and stay in
// the form below it
// pasted over. The note, the agents and sync are the library's own and
// stay in the form below it
let view = "form", jsonBad = "";
const viewBox = el("div", "lib-viewpick");
const viewSegs = () => segs([["form", t("Form")], ["json", "JSON"]], view, (v) => {
@@ -2829,6 +2859,8 @@ magpie.plugin("library", (ctx) => {
const nameF = field(t("Name"), name, t("Letters, digits, - and _ — what the agents call it")), kindF = field(t("Runs as"), kindBox);
const top = el("div", "lib-slot");
ed.append(top);
const note = noteBox(d.note, t("e.g. The shop's database, read only"), (v) => { d.note = v; });
ed.append(...field(t("Note"), note, noteHint()));
const slot = el("div", "lib-slot");
ed.append(slot);
const agentsBox = el("div");
@@ -2960,7 +2992,7 @@ magpie.plugin("library", (ctx) => {
// send saves the form; s is then the server as saved, for a save after
// a sign-in's to be of it
const send = async () => {
const body = { old: s ? s.name : "", server: { name: d.name, transport: d.transport, agents: d.agents, startupTimeout: d.startupTimeout || 0, local: !!d.local, hub: d.hub || "" } };
const body = { old: s ? s.name : "", server: { name: d.name, transport: d.transport, agents: d.agents, startupTimeout: d.startupTimeout || 0, local: !!d.local, hub: d.hub || "", note: d.note || "" } };
if (d.transport === "stdio") Object.assign(body.server, { command: d.command, args: d.args, env: d.env });
else Object.assign(body.server, { url: d.url, headers: d.headers, oauth: d.transport === "http" && d.oauth?.clientId ? d.oauth : null });
take(await api("library/servers/save", body));
@@ -3700,7 +3732,7 @@ magpie.plugin("library", (ctx) => {
if (pick !== "source") {
const skills = [...lib.skills].sort(byName(pick));
const g = { key: "flat", repo: "", skills, parts: null,
text: new Map(skills.map((s) => [s, (s.name + " " + (s.description || "") + " " + skillRepo(s)).toLowerCase()])) };
text: new Map(skills.map((s) => [s, (s.name + " " + (s.note || "") + " " + (s.description || "") + " " + skillRepo(s)).toLowerCase()])) };
grouped = { lib, pick, groups: [g] };
return grouped.groups;
}
@@ -3748,7 +3780,7 @@ magpie.plugin("library", (ctx) => {
...mine.filter((g) => g.skills.length && mineHere(g)), ...down.sort(byRepo), ...(by.has("local") ? [by.get("local")] : [])];
for (const g of groups) {
g.skills.sort((a, b) => a.name.localeCompare(b.name));
g.text = new Map(g.skills.map((s) => [s, (s.name + " " + (s.description || "") + " " + (g.mine || (g.owner ? skillRepo(s) : g.repo))).toLowerCase()]));
g.text = new Map(g.skills.map((s) => [s, (s.name + " " + (s.note || "") + " " + (s.description || "") + " " + (g.mine || (g.owner ? skillRepo(s) : g.repo))).toLowerCase()]));
g.parts = g.mine ? null : partsOf(g);
}
grouped = { lib, pick, groups };
@@ -5441,7 +5473,7 @@ magpie.plugin("library", (ctx) => {
if (hereLine) who.append(hereLine);
const sub = el("div", "sub", s.missing ? t("Its folder is gone from the library") : s.description || "");
sub.title = s.description || "";
who.append(sub);
who.append(s.missing ? sub : noteSub(s.note, sub, s.description || ""));
if (s.source) {
const src = el("div", "lib-src");
if (s.kind === "github") {
@@ -5696,10 +5728,28 @@ magpie.plugin("library", (ctx) => {
head.append(mark(s.icon, GLYPH.skill), el("b", "", s.name), pick, el("span", "grow"));
const body = el("div", "lib-skillbody");
const bar = el("div", "bar");
ed.append(head, body, bar);
// the user's note on it (youyo.p_10001 on Discord), over its files:
// the library's own, never in a file an agent reads. Save shows once
// it's changed, and saves the file being edited with it
let was = s.note || "", note = was;
const noteDirty = () => note.trim() !== was;
const keep = button(t("Save"), "primary", () => save());
keep.hidden = true;
const noteIn = noteBox(was, t("e.g. For the weekly report; the other PDF skill is for forms"), (v) => { note = v; keep.hidden = !!ta || !noteDirty(); });
const noteRow = el("div", "lib-skillnote");
noteRow.append(...field(t("Note"), noteIn, noteHint()));
ed.append(head, noteRow, body, bar);
let cur = null, ta = null;
const lf = (x) => x.replace(/\r\n?/g, "\n");
modal = { dirty: () => !!(ta && cur && ta.value !== lf(cur.text)) };
const fileDirty = () => !!(ta && cur && ta.value !== lf(cur.text));
modal = { save: () => save(), dirty: () => fileDirty() || noteDirty() };
const saveNote = async () => {
if (!noteDirty()) return true;
if (!(await change("skills/note", { name: s.name, note }, t("{name} saved", { name: s.name })))) return false;
was = note = note.trim();
keep.hidden = true;
return true;
};
const read = async (f) => {
body.replaceChildren(el("pre", "lib-md", "…"));
try {
@@ -5711,7 +5761,7 @@ magpie.plugin("library", (ctx) => {
}
};
const swap = async (f) => {
if (f === cur?.file || modal.dirty() && !(await confirmDiscard())) return;
if (f === cur?.file || fileDirty() && !(await confirmDiscard())) return;
ta = null;
read(f);
};
@@ -5726,7 +5776,8 @@ magpie.plugin("library", (ctx) => {
body.replaceChildren(rendered(cur));
const where = el("span", "note");
where.append(pathLink(cur.path));
bar.replaceChildren(where, el("span", "grow"), button(t("Edit"), "", edit), button(t("Close"), "", closeLibModal));
keep.hidden = !noteDirty();
bar.replaceChildren(where, el("span", "grow"), button(t("Edit"), "", edit), button(t("Close"), "", closeLibModal), keep);
};
const edit = () => {
ta = el("textarea", "lib-text lib-skilltext");
@@ -5740,13 +5791,13 @@ magpie.plugin("library", (ctx) => {
};
body.replaceChildren(ta);
const note = el("span", "note lib-reaches", t("Saved in the library: every agent given {name} gets it", { name: s.name }) + " · " + (/^Mac/.test(navigator.platform) ? "⌘S" : "Ctrl+S"));
bar.replaceChildren(note, el("span", "grow"), button(t("Cancel"), "", async () => { if (!modal.dirty() || await confirmDiscard()) show(); }), button(t("Save"), "primary", save));
bar.replaceChildren(note, el("span", "grow"), button(t("Cancel"), "", async () => { if (!fileDirty() || await confirmDiscard()) show(); }), button(t("Save"), "primary", save));
ta.focus({ preventScroll: true });
ta.setSelectionRange(0, 0);
};
const save = async () => {
if (!ta) return;
if (!modal.dirty()) return show();
if (!(await saveNote()) || !ta) return;
if (!fileDirty()) return show();
const f = cur.file;
if (await change("skills/save", { name: s.name, file: f, text: ta.value, was: cur.text }, t("{name} saved", { name: f }))) {
ta = null;
@@ -452,6 +452,9 @@ magpie.strings({
"As Claude Code's .mcp.json has it. A value naming a variable, as {ref}, stays a name here": "与 Claude Code 的 .mcp.json 格式相同。像 {ref} 这样引用变量的值,在这里仍然是变量名",
"This isn't an MCP server's JSON": "这不是 MCP 服务器的 JSON",
"Only one server here; paste several outside this box to add them": "这里只能写一个服务器;要一次添加多个,请粘贴到这个框外面",
"Optional: what it's for and when to use it, in any language. Only the library keeps it; no agent is given it": "可选:用任何语言写下它的用途、什么时候用。只保存在资源库里,不会交给任何 Agent",
"e.g. The shop's database, read only": "例如:店里的数据库,只读",
"e.g. For the weekly report; the other PDF skill is for forms": "例如:写周报用;另一个 PDF 技能是填表用的",
"Copy as an agent's project file": "按 agent 的项目配置文件复制",
"{agent} can't take {names} from a project's file": "{agent} 的项目配置文件放不了 {names}",
"Copied for {agent}, to paste into {file} in your project. Left out, as {agent} can't take them there: {names}": "已按 {agent} 的格式复制,粘贴到项目里的 {file} 即可。{agent} 在那里放不了、没有复制的:{names}",
@@ -1222,6 +1225,9 @@ magpie.strings({
"As Claude Code's .mcp.json has it. A value naming a variable, as {ref}, stays a name here": "與 Claude Code 的 .mcp.json 格式相同。像 {ref} 這樣引用變數的值,在這裡仍然是變數名稱",
"This isn't an MCP server's JSON": "這不是 MCP 伺服器的 JSON",
"Only one server here; paste several outside this box to add them": "這裡只能寫一個伺服器;要一次加入多個,請貼到這個框外面",
"Optional: what it's for and when to use it, in any language. Only the library keeps it; no agent is given it": "選填:用任何語言寫下它的用途、什麼時候用。只儲存在資源庫裡,不會交給任何 Agent",
"e.g. The shop's database, read only": "例如:店裡的資料庫,唯讀",
"e.g. For the weekly report; the other PDF skill is for forms": "例如:寫週報用;另一個 PDF 技能是填表用的",
"Copy as an agent's project file": "按 agent 的專案設定檔複製",
"{agent} can't take {names} from a project's file": "{agent} 的專案設定檔放不了 {names}",
"Copied for {agent}, to paste into {file} in your project. Left out, as {agent} can't take them there: {names}": "已按 {agent} 的格式複製,貼到專案裡的 {file} 即可。{agent} 在那裡放不了、沒有複製的:{names}",
@@ -1987,6 +1993,9 @@ magpie.strings({
"As Claude Code's .mcp.json has it. A value naming a variable, as {ref}, stays a name here": "Claude Code の .mcp.json と同じ形式です。{ref} のように変数を参照する値は、ここでは変数名のままです",
"This isn't an MCP server's JSON": "MCP サーバーの JSON ではありません",
"Only one server here; paste several outside this box to add them": "ここに書けるサーバーは 1 つです。複数をまとめて追加するには、この欄の外に貼り付けてください",
"Optional: what it's for and when to use it, in any language. Only the library keeps it; no agent is given it": "任意:用途やいつ使うかを好きな言語で。ライブラリにだけ保存され、どのエージェントにも渡されません",
"e.g. The shop's database, read only": "例:店のデータベース、読み取り専用",
"e.g. For the weekly report; the other PDF skill is for forms": "例:週報用。もう一つの PDF スキルはフォーム用",
"Copy as an agent's project file": "エージェントのプロジェクト設定ファイルの形でコピー",
"{agent} can't take {names} from a project's file": "{agent} のプロジェクト設定ファイルには {names} を入れられません",
"Copied for {agent}, to paste into {file} in your project. Left out, as {agent} can't take them there: {names}": "{agent} 用にコピーしました。プロジェクトの {file} に貼り付けてください。{agent} がそこで使えないため除いたもの:{names}",
@@ -2755,6 +2764,9 @@ magpie.strings({
"As Claude Code's .mcp.json has it. A value naming a variable, as {ref}, stays a name here": "So, wie es in Claude Codes .mcp.json steht. Ein Wert, der eine Variable nennt, etwa {ref}, bleibt hier ein Name",
"This isn't an MCP server's JSON": "Das ist kein JSON eines MCP-Servers",
"Only one server here; paste several outside this box to add them": "Hier steht nur ein Server; mehrere fügst du hinzu, indem du sie außerhalb dieses Felds einfügst",
"Optional: what it's for and when to use it, in any language. Only the library keeps it; no agent is given it": "Optional: wofür er da ist und wann man ihn nimmt, in jeder Sprache. Nur die Bibliothek speichert sie; kein Agent bekommt sie",
"e.g. The shop's database, read only": "z. B. Die Datenbank des Shops, nur lesend",
"e.g. For the weekly report; the other PDF skill is for forms": "z. B. Für den Wochenbericht; der andere PDF-Skill ist für Formulare",
"Copy as an agent's project file": "Als Projektdatei eines Agenten kopieren",
"{agent} can't take {names} from a project's file": "{agent} kann {names} nicht aus einer Projektdatei lesen",
"Copied for {agent}, to paste into {file} in your project. Left out, as {agent} can't take them there: {names}": "Für {agent} kopiert, zum Einfügen in {file} im Projekt. Weggelassen, da {agent} sie dort nicht lesen kann: {names}",
@@ -821,16 +821,22 @@ body.window .lib-list .lib-row { --lib-indent: 38px; }
.lib-browserask-pick:hover { background: var(--accent-soft); }
.lib-browserask-pick .ic { width: 14px; height: 14px; }
/* an MCP server's command wraps, read whole (hema_17384 on Discord): it
starts as tall as an input beside it */
.lib-editor .lib-cmd { min-height: 0; height: 27px; padding: 4px 9px; border-radius: 7px; line-height: 17px; overflow: hidden; }
/* an MCP server's command wraps, read whole (hema_17384 on Discord), and
a note is a line too: each starts as tall as an input beside it */
.lib-editor :is(.lib-cmd, .lib-notein) { min-height: 0; height: 27px; padding: 4px 9px; border-radius: 7px; line-height: 17px; overflow: hidden; }
.lib-editor .lib-cmd { font-size: 12px; white-space: pre-wrap; overflow-wrap: anywhere; }
.lib-editor .lib-notein { font: inherit; font-size: 12.5px; line-height: 17px; }
/* the server as JSON: wrapped, so a long argument never scrolls sideways */
.lib-editor .lib-json { min-height: 160px; font-size: 12px; line-height: 1.5; white-space: pre-wrap; overflow-wrap: anywhere; }
.lib-editor .lib-json[aria-invalid="true"], .lib-editor .lib-json[aria-invalid="true"]:focus { border-color: var(--red); }
.lib-serverhead { flex-wrap: wrap; row-gap: 6px; }
.lib-serverhead .lib-viewpick { margin-left: auto; flex: none; }
.lib-serverhead .note + .lib-viewpick { margin-left: 0; }
/* a row's note, the user's own words, over the muted line it stands for */
.lib-row .sub.lib-subnote { color: var(--fg-2); }
/* a skill's note, over its SKILL.md */
.lib-skillnote { display: flex; flex-direction: column; gap: 4px; }
.lib-reader .lib-skillnote label { text-align: left; padding-top: 0; }
@media (max-width: 760px), (pointer: coarse) and (max-width: 1024px) {
body.web .lib-editor .lib-cmd { min-height: 44px; font-size: 16px; line-height: 22px; padding: 10px 9px; }
body.web .lib-editor :is(.lib-cmd, .lib-notein) { min-height: 44px; font-size: 16px; line-height: 22px; padding: 10px 9px; }
}
+4 -1
View File
@@ -458,7 +458,7 @@ func libraryRoutes(mux *http.ServeMux, w Windows) {
Subagent library.Subagent
Agent string // the agent whose own skill is in the library's way
App string // the app the MCP hub is added to (servers/hub-open)
Note string // what the MCP router says of itself (servers/hub-note)
Note string // what the MCP router says of itself (servers/hub-note), or a skill's note (skills/note)
ID string // a market server's, or a market skill's in its repository
Values map[string]string // what a market server needs
Dir string // a project's folder
@@ -558,6 +558,9 @@ func libraryRoutes(mux *http.ServeMux, w Windows) {
res, err = library.SaveSkillFile(in.Name, in.File, in.Text, in.Was)
case "skills/here":
res, err = library.SkillHere(in.Name, in.On)
case "skills/note":
// the user's own note on it, which no agent is given
res, err = library.SkillNote(in.Name, in.Note)
case "skills/agents-all":
res, err = library.EverySkillAgents(in.Agents, in.On)
case "skills/agents-some":
+71 -5
View File
@@ -5,8 +5,13 @@
// too, and the editor shows the server as JSON as well, in Claude Code's
// .mcp.json shape, to read whole and edit: an edit there is what is saved,
// and JSON that isn't a server's keeps the dialog from saving or going
// back to the form. Every language, Chromium and WebKit, 1100 and 390
// wide; nothing scrolls sideways. No backend:
// back to the form.
// youyo.p_10001 on Discord: with many skills and servers, which is which.
// Each takes a note, the library's own: saved with the server or by
// itself for a skill, shown in the row in place of its command or
// description (which the tooltip still gives), found by the skills'
// filter, and asked about before it is lost. Every language, Chromium
// and WebKit, 1100 and 390 wide; nothing scrolls sideways. No backend:
// the API is faked here.
const assert = require("node:assert/strict");
const fs = require("node:fs/promises");
@@ -29,7 +34,12 @@ function server(lang, calls) {
agents: [agent("claude", "Claude Code")],
instructions: { agents: [], sets: [] }, foundServers: [], projects: [], foundSkills: [],
servers: [{ name: "db", transport: "stdio", command: "npx", args: ARGS, env: { DB_TOKEN: "${DB_TOKEN}" }, agents: ["claude"] }],
skills: [],
skills: [
{ name: "pdf", description: "Read and fill PDF files", kind: "folder", agents: ["claude"] },
{ name: "weekly", description: "Write a report from the week's commits", kind: "folder", agents: ["claude"] },
// enough of them for the filter, which shows over eight
...["docx", "xlsx", "pptx", "slides", "review", "deploy", "notes"].map((name) => ({ name, description: "Work with " + name, kind: "folder", agents: ["claude"] })),
],
};
return async (route) => {
const req = route.request(), url = new URL(req.url());
@@ -39,6 +49,10 @@ function server(lang, calls) {
if (url.pathname === "/api/plugins") return route.fulfill({ json: { plugins: [] } });
if (url.pathname === "/api/library") return route.fulfill({ json: lib });
if (url.pathname === "/api/library/mcp/check") return route.fulfill({ json: { servers: {} } });
if (url.pathname === "/api/library/skill") {
const name = url.searchParams.get("name");
return route.fulfill({ json: { file: "SKILL.md", files: ["SKILL.md"], text: "---\nname: " + name + "\n---\n\nWrite it up.\n", path: `${HOME}/.magpie/library/skills/${name}` } });
}
if (url.pathname === "/api/library/servers/save") {
const { old, server: s } = req.postDataJSON();
calls.push(["save", s]);
@@ -46,6 +60,13 @@ function server(lang, calls) {
lib.servers[i] = { ...lib.servers[i], ...s };
return route.fulfill({ json: { ...lib, result: { changed: ["claude"] } } });
}
if (url.pathname === "/api/library/skills/note") {
const b = req.postDataJSON();
calls.push(["note", b]);
const s = lib.skills.find((x) => x.name === b.name);
s.note = b.note.trim();
return route.fulfill({ json: { ...lib, result: {} } });
}
if (url.pathname === "/api/usage/quotas") return route.fulfill({ json: [] });
if (url.pathname === "/api/groups") return route.fulfill({ json: { groups: [] } });
if (url.pathname === "/api/providers") return route.fulfill({ json: { providers: [], gateway: { running: true } } });
@@ -57,7 +78,7 @@ function server(lang, calls) {
}
for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
test(engine + ": an MCP server's command read whole, and as JSON", async (t) => {
test(engine + ": an MCP server's command read whole, as JSON, and notes", async (t) => {
assert(["chromium", "webkit"].includes(engine), "BROWSER must be chromium or webkit");
const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: process.env.PLAYWRIGHT_CHANNEL || "chromium" }));
const errors = [];
@@ -71,7 +92,8 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
const w = (s) => tr(lang, s);
const calls = [];
const ctx = await browser.newContext({ viewport: { width, height: 800 } });
await ctx.addInitScript(() => { try { localStorage.setItem("magpie.libTab", "mcp"); } catch {} });
// the MCP tab first; the skills' once the test has picked it
await ctx.addInitScript(() => { try { if (!localStorage.getItem("magpie.libTab")) localStorage.setItem("magpie.libTab", "mcp"); } catch {} });
const page = await ctx.newPage();
page.setDefaultTimeout(5000);
page.setDefaultNavigationTimeout(60000);
@@ -134,6 +156,50 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
assert.deepEqual(calls.at(-1)[1].args, [...ARGS.slice(0, -1), "shop", "--readonly"]);
assert.deepEqual(calls.at(-1)[1].env, { DB_TOKEN: "${DB_TOKEN}", MODE: "ro" });
// a note on the server: saved with it, shown in its row, its command in the tooltip
await open();
const note = ed.locator("textarea.lib-notein");
await note.fill("店里的库存数据库,只读");
await note.press("Enter");
await ed.waitFor({ state: "detached" });
assert.equal(calls.at(-1)[1].note, "店里的库存数据库,只读");
const sub = row.locator(".sub.lib-subnote");
await sub.waitFor();
assert.equal(await sub.textContent(), "店里的库存数据库,只读");
assert((await sub.getAttribute("title")).endsWith(LINE.replace("shop_inventory_reporting", "shop") + " --readonly"));
assert.equal(await row.locator(".sub.mono").count(), 0);
// a skill's note, over its SKILL.md
await page.evaluate(() => { try { localStorage.setItem("magpie.libTab", "skills"); } catch {} });
await page.reload();
await page.locator('button[data-view="library"]').click();
const skill = (name) => page.locator("#view-library .lib-skill", { has: page.locator(".name", { hasText: new RegExp("^" + name + "$") }) });
await skill("weekly").locator(".name").click();
await ed.waitFor();
const keep = ed.locator(":scope > .bar button.primary");
assert.equal(await keep.isVisible(), false, "Save shown with nothing changed");
await ed.locator("textarea.lib-notein").fill("周报用");
await keep.waitFor();
assert.equal(await keep.textContent(), w("Save"));
// asked before it's lost
await page.keyboard.press("Escape");
await page.locator("dialog.action-confirm button:not(.primary)").last().click();
assert.equal(await ed.count(), 1, "a changed note closed without asking");
// saved where it is, the skill's file still open; nothing then to ask about
await ed.locator("textarea.lib-notein").press("Enter");
await keep.waitFor({ state: "hidden" });
assert.deepEqual(calls.at(-1), ["note", { name: "weekly", note: "周报用" }]);
assert.equal(await ed.locator(".lib-skillbody").count(), 1);
await page.keyboard.press("Escape");
await ed.waitFor({ state: "detached" });
const ssub = skill("weekly").locator(".sub.lib-subnote");
await ssub.waitFor();
assert.equal(await ssub.textContent(), "周报用");
assert.equal(await ssub.getAttribute("title"), "周报用\n\nWrite a report from the week's commits");
// the filter finds it by its note
await page.locator("#view-library input.lib-skillq").fill("周报");
await page.waitForFunction(() => document.querySelectorAll("#view-library .lib-skill").length === 1);
assert.equal(await skill("weekly").count(), 1);
assert.equal(await page.evaluate(() => document.documentElement.scrollWidth <= innerWidth), true, "no sideways scroll");
await ctx.close();
});
+4 -2
View File
@@ -45,6 +45,8 @@ type CarriedSkill struct {
Left []string `json:"left,omitempty"` // files too big to carry
// Called is the name its SKILL.md gives, when that isn't Name
Called string `json:"called,omitempty"`
// Note is the user's note on it (Skill.Note)
Note string `json:"note,omitempty"`
}
// A skill's file bigger than maxCarried is left out, and so are the
@@ -104,7 +106,7 @@ func Collect() (*Bundle, error) {
}
for i, c := range readSkills(dirs) {
s := skills[i]
c.Name, c.Source, c.Agents, c.Called = s.Name, s.Source, orNone(slices.Sorted(slices.Values(s.Agents))), s.Called
c.Name, c.Source, c.Agents, c.Called, c.Note = s.Name, s.Source, orNone(slices.Sorted(slices.Values(s.Agents))), s.Called, s.Note
b.Skills = append(b.Skills, c)
}
subs := []*Subagent{}
@@ -416,7 +418,7 @@ func Put(b *Bundle) (*Result, error) {
for _, s := range b.Skills {
// turned off here stays off here: that is this computer's own
off := l.skill(s.Name) != nil && l.skill(s.Name).OffHere
skills = append(skills, &Skill{Name: s.Name, Source: s.Source, Agents: slices.Clone(orNone(s.Agents)), OffHere: off, Called: s.Called})
skills = append(skills, &Skill{Name: s.Name, Source: s.Source, Agents: slices.Clone(orNone(s.Agents)), OffHere: off, Called: s.Called, Note: s.Note})
if keep[s.Name] {
continue
}
+7
View File
@@ -68,6 +68,10 @@ type Server struct {
// off, for a server that reads its project from the folder it is
// started in, or keeps a session's state (#4382, cuipengcx90).
Hub string `json:"hub,omitempty"`
// Note is the user's own word on what the server is for (youyo.p on
// Discord: with many of them, which is which). Only the library keeps
// it, and a sync carries it; no agent is given it (TestNoteNeverGiven).
Note string `json:"note,omitempty"`
// about is the hub entry's description, for an agent that shows a
// server by one before it has connected (Pi, hubServerFor)
@@ -154,6 +158,9 @@ func (s *Server) check() error {
s.OAuth = nil
}
}
if err := checkNote(&s.Note); err != nil {
return fmt.Errorf("%s: %w", s.Name, err)
}
if s.StartupTimeout < 0 || s.StartupTimeout > maxStartupTimeout {
return fmt.Errorf("%s: the startup timeout is between 0 (the agent's own) and %d seconds", s.Name, maxStartupTimeout)
}
+134
View File
@@ -0,0 +1,134 @@
package library
import (
"encoding/json"
"io/fs"
"os"
"path/filepath"
"strings"
"testing"
"github.com/yetone/magpie/internal/settings"
)
// The notes on a server and a skill (youyo.p on Discord: with many of
// them, which is which and when to use it) are the library's alone:
// nothing magpie writes for an agent holds them, whichever format the
// agent reads, through the MCP router or not.
func TestNoteNeverGiven(t *testing.T) {
h := sandbox(t)
const serverNote, skillNote = "备注 the shop's SQL Server, read only", "备注 for the weekly report"
agents := []string{"claude", "codex", "opencode", "gemini"}
ok(t)(SaveServer("", Server{Name: "db", Transport: "stdio", Command: "npx",
Args: []string{"-y", "universal-db-mcp", "--type", "sqlserver"}, Agents: agents, Note: serverNote}))
ok(t)(SaveServer("", Server{Name: "docs", Transport: "http", URL: "https://example.com/mcp", Agents: agents, Note: serverNote}))
skill(t, filepath.Join(h, "src/pdf"), "pdf", "Read PDFs")
ok(t)(InstallSkills(filepath.Join(h, "src"), []string{"pdf"}, agents))
ok(t)(SkillNote("pdf", skillNote))
// given as copies too, whose files are the agents' own
ok(t)(SetSkillHow("claude", "copy"))
// kept, and shown on the page
if s := serverIn(t, "db"); s == nil || s.Note != serverNote {
t.Fatalf("the server's note wasn't kept: %+v", s)
}
if v := offView(t, "pdf"); v.Note != skillNote {
t.Fatalf("the skill's note wasn't kept: %+v", v)
}
given := func(when string) {
t.Helper()
own := filepath.Clean(settings.Dir())
n := 0
filepath.WalkDir(h, func(p string, d fs.DirEntry, err error) error {
if err != nil {
return nil
}
if d.IsDir() && filepath.Clean(p) == own {
return filepath.SkipDir // magpie's own: library.json, its backups
}
if !d.Type().IsRegular() {
return nil
}
b, err := os.ReadFile(p)
if err != nil {
return nil
}
n++
if s := string(b); strings.Contains(s, "备注") {
t.Errorf("%s: %s has a note in it:\n%s", when, p, s)
}
return nil
})
if n == 0 {
t.Fatalf("%s: no agent file was read", when)
}
}
for _, f := range []string{".claude.json", ".codex/config.toml", ".claude/skills/pdf/SKILL.md"} {
if _, err := os.Stat(filepath.Join(h, f)); err != nil {
t.Fatalf("not given to the agents: %v", err)
}
}
given("each agent's own entry")
ok(t)(SetMCPHub(true))
given("through the router")
for _, s := range []string{"db", "docs"} {
b, _ := json.Marshal(hubServerOf(serverIn(t, s)))
if strings.Contains(string(b), "备注") {
t.Fatalf("the router tells an agent of %s with its note: %s", s, b)
}
}
}
// A note is carried to the other computers with the rest of the server
// or the skill, and taking it away is carried too.
func TestNoteCarried(t *testing.T) {
a := sandbox(t)
setUpLibrary(t, a) // the server fs and the skill pdf
s := serverIn(t, "fs")
s.Note = "the project's files"
ok(t)(SaveServer("fs", *s))
ok(t)(SkillNote("pdf", " when a PDF\nis attached "))
if v := offView(t, "pdf"); v.Note != "when a PDF is attached" {
t.Fatalf("a note is one line: %q", v.Note)
}
fromA := carry(t)
b := sandbox(t)
ok(t)(Put(&fromA))
if s := serverIn(t, "fs"); s == nil || s.Note != "the project's files" {
t.Fatalf("the server's note didn't come: %+v", s)
}
if v := offView(t, "pdf"); v.Note != "when a PDF is attached" {
t.Fatalf("the skill's note didn't come: %+v", v)
}
ok(t)(SkillNote("pdf", ""))
fromB := carry(t)
at(t, a)
ok(t)(Put(&fromB))
if v := offView(t, "pdf"); v.Note != "" {
t.Fatalf("a note taken away on B is still on A: %q", v.Note)
}
at(t, b)
}
// A note is a line, not a document: a longer one is turned away whole,
// rather than cut.
func TestNoteTooLong(t *testing.T) {
h := sandbox(t)
skill(t, filepath.Join(h, "src/pdf"), "pdf", "Read PDFs")
ok(t)(InstallSkills(filepath.Join(h, "src"), []string{"pdf"}, []string{"claude"}))
long := strings.Repeat("备", maxNote+1)
if _, err := SkillNote("pdf", long); err == nil {
t.Fatal("a skill's note over the limit was kept")
}
if _, err := SaveServer("", Server{Name: "x", Transport: "stdio", Command: "x", Note: long}); err == nil {
t.Fatal("a server's note over the limit was kept")
}
ok(t)(SkillNote("pdf", strings.Repeat("备", maxNote)))
if _, err := SkillNote("nope", "a"); err == nil {
t.Fatal("a note on no skill")
}
}
+35
View File
@@ -21,6 +21,7 @@ import (
"sync"
"time"
"unicode"
"unicode/utf8"
"github.com/yetone/magpie/internal/agent"
"github.com/yetone/magpie/internal/source"
@@ -59,6 +60,11 @@ type Skill struct {
// under another because a skill from elsewhere had that name first
// (skill_beside.go). Its SKILL.md is named as the library names it.
Called string `json:"called,omitempty"`
// Note is the user's own word on what the skill is for or when to
// use it, beside its SKILL.md's description (youyo.p on Discord).
// Only the library keeps it, and a sync carries it; no agent is
// given it: the skill's folder is the agents', and this isn't in it.
Note string `json:"note,omitempty"`
}
// gives reports whether the agent id gets the skill on this computer: it
@@ -80,6 +86,35 @@ func SkillHere(name string, on bool) (*Result, error) {
})
}
// maxNote is how long a note on a server or a skill can be, in
// characters: a line that says what it is for, as a hook's description.
const maxNote = 200
// checkNote makes a note one line, as the page shows it, and holds it to
// maxNote.
func checkNote(n *string) error {
*n = strings.Join(strings.Fields(*n), " ")
if utf8.RuneCountInString(*n) > maxNote {
return fmt.Errorf("a note is at most %d characters", maxNote)
}
return nil
}
// SkillNote sets the user's note on a skill; "" takes it away.
func SkillNote(name, note string) (*Result, error) {
if err := checkNote(&note); err != nil {
return nil, err
}
return change(func(l *Library) error {
s := l.skill(name)
if s == nil {
return fmt.Errorf("no skill called %s", name)
}
s.Note = note
return nil
})
}
// Source is where a skill came from: a GitHub repository it can be updated
// from, another git repository (fetched with the user's own git), or a
// folder on this machine the library links to, so that editing the folder
+3 -1
View File
@@ -475,6 +475,8 @@ type SkillView struct {
// OffHere is set when it is turned off on this computer alone: Agents
// are still the ones a sync carries to the others
OffHere bool `json:"offHere,omitempty"`
// Note is the user's own note on it (Skill.Note)
Note string `json:"note,omitempty"`
}
// View is the Library page.
@@ -667,7 +669,7 @@ func readView(problems []Problem, glance bool) (*View, error) {
v.Subagents, v.SubagentAgents = l.subagentsView(targets, asleep, of)
tr := &tracer{}
for _, s := range l.Skills {
sv := SkillView{Name: s.Name, Agents: append([]string{}, s.Agents...), Icon: skillIcon(s), Problems: of("skill:" + s.Name), Repo: tr.repoOf(s), OffHere: s.OffHere}
sv := SkillView{Name: s.Name, Agents: append([]string{}, s.Agents...), Icon: skillIcon(s), Problems: of("skill:" + s.Name), Repo: tr.repoOf(s), OffHere: s.OffHere, Note: s.Note}
if s.Source != nil {
sv.Source, sv.Kind = s.Source.String(), s.Source.Kind
}
+3 -2
View File
@@ -424,8 +424,9 @@ func saveServer(old *library.Server, line string) tea.Cmd {
if old != nil {
was, done = old.Name, "saved "+s.Name
// and its OAuth app and startup timeout, which only the GUI edits
// and whether it is kept to this computer, and out of the hub
s.Agents, s.Env, s.Headers, s.OAuth, s.StartupTimeout, s.Local, s.Hub = old.Agents, old.Env, old.Headers, old.OAuth, old.StartupTimeout, old.Local, old.Hub
// and whether it is kept to this computer, and out of the hub,
// and the user's note on it
s.Agents, s.Env, s.Headers, s.OAuth, s.StartupTimeout, s.Local, s.Hub, s.Note = old.Agents, old.Env, old.Headers, old.OAuth, old.StartupTimeout, old.Local, old.Hub, old.Note
}
return libCmd(func() (*library.Result, error) { return library.SaveServer(was, s) }, done)()
}