library: Skills > New skill makes a skill of the user's own (josephBenchap on X)
josephBenchap asked to create a skill in the Library; it could only
install or bring one in. Skills now has a New skill button beside Find
skills. A dialog takes a name, a description and the agents (the app's
chips, no select); Create writes skills/<name>/SKILL.md in the library's
folder with name and description front matter (YAML-marshalled, one line,
at most 1024 characters), lists it with no source, gives it to the agents
picked like any imported skill, and opens it in the reader, whose path
link opens the file in the user's editor. The name is checkName's, and
refused when the library or an agent already has one by that name
(compared without case) or a folder is in the way. The follow-the-server
note already sits above the Skills tab, so it covers this too. en, zh,
zh-TW, ja, de. docs/subsystems/library.md says so.
Run on mote at this head:
- gofmt -l clean; go vet ./internal/library ./internal/gui on darwin,
GOOS=linux -tags nogui and GOOS=windows: ok.
- go test ./internal/library ./internal/gui: ok. TestCreateSkill is new.
- GUI node --test in chromium and webkit: library-new-skill (new; en and
zh, 1100 and 420px: refusal stays in the dialog, agent untick posted,
reader opens, no select, no sideways scroll), library-items,
library-follow-server, library-all, library-discover-jump,
library-groups, library-intro-width, library-linked-set,
library-pick-remove, library-row-open-scroll, library-ime-scroll,
library-desktop-skills, library-gone-agents, library-bar-more,
library-chip-fan, i18n-keys, i18n-en-no-cjk, gui-de, gui-ja, gui-zh-tw:
all pass.
- library-loading is red (2 of 6) on this tree and on origin/main
e6fe481b3 alike: the tab list gained Claude plugins. Already #5997.
Broken by hand: the agents' own-skill name check removed:
TestCreateSkill red ("theirs" was taken).
Not tried: the real app; Windows run of the tests (vet only); the full
suite starts after the tag.
This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -6680,6 +6680,53 @@ magpie.plugin("library", (ctx) => {
|
||||
};
|
||||
}
|
||||
|
||||
// A skill of the user's own: a name and a description make its SKILL.md
|
||||
// in the library's folder (josephBenchap on X); it opens in the reader,
|
||||
// whose path opens it in their editor.
|
||||
function newSkill() {
|
||||
const all = skillAgents();
|
||||
const d = { name: "", description: "", agents: all.map((a) => a.id) };
|
||||
const ed = el("div", "editor lib-editor lib-newskill");
|
||||
const head = el("div", "ehead");
|
||||
head.append(glyph(GLYPH.skill), el("b", "", t("New skill")));
|
||||
ed.append(head);
|
||||
const err = el("div", "editor-error");
|
||||
const name = field2("", t("e.g. my-skill"), (v) => { d.name = v.trim(); });
|
||||
name.classList.add("mono");
|
||||
ed.append(...field(t("Name"), name, t("Letters, digits, - and _ — what the agents call it")));
|
||||
const desc = el("textarea", "lib-text small lib-newskilldesc");
|
||||
desc.placeholder = t("e.g. Writes release notes. Use when asked for a changelog.");
|
||||
desc.spellcheck = false;
|
||||
desc.rows = 2;
|
||||
desc.maxLength = 1024;
|
||||
desc.oninput = () => { d.description = desc.value; };
|
||||
desc.onkeydown = (e) => { e.stopPropagation(); if (e.isComposing || e.keyCode === 229) return; if (e.key === "Escape") closeLibModal(); else if (e.key === "Enter") { e.preventDefault(); modal?.save?.(); } };
|
||||
ed.append(...field(t("Description"), desc, t("What it does and when to use it: the agent reads this to decide when to load it")));
|
||||
const agentsBox = el("div");
|
||||
ed.append(...field(t("Agents"), agentsBox));
|
||||
ed.append(err);
|
||||
const drawAgents = () => agentsBox.replaceChildren(agentChips(all, d.agents, (next) => { d.agents = next; drawAgents(); }, { names: true, all: true }));
|
||||
drawAgents();
|
||||
const bar = el("div", "bar");
|
||||
bar.append(el("span", "grow"), button(t("Cancel"), "", closeLibModal));
|
||||
const save = async () => {
|
||||
err.textContent = "";
|
||||
try {
|
||||
take(await api("library/skills/create", { name: d.name, description: d.description, agents: d.agents }));
|
||||
report(lib.result, t("{name} is in the library now", { name: d.name }));
|
||||
render();
|
||||
const made = lib.skills.find((x) => x.name === d.name);
|
||||
if (made) viewSkill(made); else closeLibModal(true);
|
||||
} catch (e) { err.textContent = e.message; }
|
||||
};
|
||||
bar.append(button(t("Create"), "primary", save));
|
||||
ed.append(bar);
|
||||
const original = JSON.stringify(d);
|
||||
modal = { save, dirty: () => JSON.stringify(d) !== original };
|
||||
openLib(ed);
|
||||
requestAnimationFrame(() => name.focus());
|
||||
}
|
||||
|
||||
function installCard() {
|
||||
const card = el("div", "list lib-card lib-install");
|
||||
const line = el("div", "lib-find");
|
||||
@@ -6695,7 +6742,9 @@ magpie.plugin("library", (ctx) => {
|
||||
if (probing) go.classList.add("busy");
|
||||
inp.onkeydown = (e) => { e.stopPropagation(); if (e.key === "Enter") find(); else if (e.key === "Escape" && probe) { probe = null; render(); } };
|
||||
const g = glyph(GLYPH.search, "lib-mini");
|
||||
line.append(g, inp, go);
|
||||
const mk = button(t("New skill"), "", () => newSkill());
|
||||
mk.dataset.lib = "new-skill";
|
||||
line.append(g, inp, go, mk);
|
||||
card.append(line);
|
||||
async function find() {
|
||||
const src = inp.value.trim();
|
||||
|
||||
@@ -2,6 +2,10 @@
|
||||
// kernel adds them to i18n.js's (magpie.strings).
|
||||
magpie.strings({
|
||||
zh: {
|
||||
"New skill": "新建技能",
|
||||
"e.g. my-skill": "例如 my-skill",
|
||||
"e.g. Writes release notes. Use when asked for a changelog.": "例如:撰写发布说明。需要更新日志时使用。",
|
||||
"What it does and when to use it: the agent reads this to decide when to load it": "它做什么、何时使用:Agent 据此决定何时加载它",
|
||||
"This computer follows the server: what you change here is replaced by the next sync.": "这台电脑跟随服务器:你在这里的改动会被下一次同步替换。",
|
||||
"Sync settings": "同步设置",
|
||||
"Stop picking memories": "不再选择记忆",
|
||||
@@ -975,6 +979,10 @@ magpie.strings({
|
||||
"{name} read again from its source": "已重新从来源读取 {name}",
|
||||
},
|
||||
"zh-TW": {
|
||||
"New skill": "新增技能",
|
||||
"e.g. my-skill": "例如 my-skill",
|
||||
"e.g. Writes release notes. Use when asked for a changelog.": "例如:撰寫發佈說明。需要更新日誌時使用。",
|
||||
"What it does and when to use it: the agent reads this to decide when to load it": "它做什麼、何時使用:Agent 據此決定何時載入它",
|
||||
"This computer follows the server: what you change here is replaced by the next sync.": "這台電腦跟隨伺服器:你在這裡的變更會被下一次同步取代。",
|
||||
"Sync settings": "同步設定",
|
||||
"Stop picking memories": "不再選擇記憶",
|
||||
@@ -1948,6 +1956,10 @@ magpie.strings({
|
||||
"{name} read again from its source": "已重新從來源讀取 {name}",
|
||||
},
|
||||
ja: {
|
||||
"New skill": "新しいスキル",
|
||||
"e.g. my-skill": "例: my-skill",
|
||||
"e.g. Writes release notes. Use when asked for a changelog.": "例: リリースノートを書く。変更履歴を求められたときに使う。",
|
||||
"What it does and when to use it: the agent reads this to decide when to load it": "何をするか、いつ使うか。エージェントはこれを読んで読み込むかを決めます",
|
||||
"This computer follows the server: what you change here is replaced by the next sync.": "このコンピュータはサーバーに従います。ここでの変更は次の同期で置き換えられます。",
|
||||
"Sync settings": "同期の設定",
|
||||
"Stop picking memories": "メモリの選択を終える",
|
||||
@@ -2921,6 +2933,10 @@ magpie.strings({
|
||||
"{name} read again from its source": "{name} をソースから読み直しました",
|
||||
},
|
||||
de: {
|
||||
"New skill": "Neuer Skill",
|
||||
"e.g. my-skill": "z. B. my-skill",
|
||||
"e.g. Writes release notes. Use when asked for a changelog.": "z. B. Schreibt Release Notes. Zu verwenden, wenn ein Changelog verlangt wird.",
|
||||
"What it does and when to use it: the agent reads this to decide when to load it": "Was er tut und wann er gebraucht wird: Der Agent entscheidet danach, ob er ihn lädt",
|
||||
"This computer follows the server: what you change here is replaced by the next sync.": "Dieser Computer folgt dem Server: Änderungen hier werden bei der nächsten Synchronisierung ersetzt.",
|
||||
"Sync settings": "Sync-Einstellungen",
|
||||
"Stop picking memories": "Keine Erinnerungen mehr auswählen",
|
||||
|
||||
@@ -604,11 +604,13 @@ func libraryRoutes(mux *http.ServeMux, w Windows) {
|
||||
// Agents is named as the page sends it, so that it is this
|
||||
// and not the instructions' own Agents that "agents" fills
|
||||
Agents []string `json:"agents"`
|
||||
Source string
|
||||
Paths []string
|
||||
Names []string // the skills to update, of those a check found changed; to bring in, of those found in the agents
|
||||
Server library.Server
|
||||
Hook library.Hook // a hook saved (#1790)
|
||||
// Description is a new skill's (skills/create)
|
||||
Description string `json:"description"`
|
||||
Source string
|
||||
Paths []string
|
||||
Names []string // the skills to update, of those a check found changed; to bring in, of those found in the agents
|
||||
Server library.Server
|
||||
Hook library.Hook // a hook saved (#1790)
|
||||
// a subagent saved (#2283)
|
||||
Subagent library.Subagent
|
||||
Agent string // the agent whose own skill is in the library's way
|
||||
@@ -715,6 +717,8 @@ func libraryRoutes(mux *http.ServeMux, w Windows) {
|
||||
res, err = library.RemoveSubagents([]string{in.Name})
|
||||
case "skills/install":
|
||||
res, err = library.InstallSkills(in.Source, in.Paths, in.Agents)
|
||||
case "skills/create":
|
||||
res, err = library.CreateSkill(in.Name, in.Description, in.Agents)
|
||||
case "skills/update":
|
||||
res, err = library.UpdateSkill(in.Name, in.Replace)
|
||||
var gone *library.GoneError
|
||||
|
||||
@@ -0,0 +1,93 @@
|
||||
// Run with Node's test runner and Playwright on the module path; see README.md.
|
||||
// A skill made in the Library (josephBenchap on X): Skills > New skill takes
|
||||
// a name and a description and the agents, posts library/skills/create, and
|
||||
// opens the new skill in the reader. A refusal is said in the dialog and the
|
||||
// dialog stays. No native select, no sideways scroll. English and Chinese,
|
||||
// Chromium and WebKit, 1100 and 420px. The API is faked.
|
||||
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 HOME = "/Users/emo";
|
||||
const agent = (id, name) => ({ id, name, icon: "", skills: `${HOME}/.${id}/skills`, mcp: `${HOME}/.${id}/mcp.json` });
|
||||
const lib = (skills) => ({
|
||||
dir: `${HOME}/.magpie/library`, backups: `${HOME}/.magpie/backups`, home: HOME,
|
||||
agents: [agent("codex", "Codex"), agent("claude", "Claude Code")],
|
||||
instructions: { agents: [], sets: [] }, foundServers: [], projects: [], foundSkills: [], skills, servers: [],
|
||||
});
|
||||
|
||||
function server(lang, posts, state) {
|
||||
return async (route) => {
|
||||
const req = route.request(), url = new URL(req.url());
|
||||
if (url.pathname === "/boot.js") return route.fulfill({ contentType: "text/javascript", body: `window.bootPrefs = {lang:"${lang}",theme:"light",web:true};` });
|
||||
if (url.pathname === "/wails/runtime.js") return route.fulfill({ contentType: "text/javascript", body: "export const Window = {};" });
|
||||
if (url.pathname === "/api/state") return route.fulfill({ json: { agents: [], profiles: [], settings: { lang, theme: "light" } } });
|
||||
if (url.pathname === "/api/plugins") return route.fulfill({ json: { plugins: [] } });
|
||||
if (url.pathname === "/api/library") return route.fulfill({ json: lib(state.skills) });
|
||||
if (url.pathname === "/api/library/skills/create") {
|
||||
const b = req.postDataJSON();
|
||||
posts.push(b);
|
||||
if (b.name === "taken") return route.fulfill({ status: 400, body: "there is a skill called taken already" });
|
||||
state.skills = [{ name: b.name, description: b.description, agents: b.agents }];
|
||||
return route.fulfill({ json: { ...lib(state.skills), result: { changed: b.agents, problems: [] } } });
|
||||
}
|
||||
if (url.pathname === "/api/library/skill") return route.fulfill({ json: { text: `---\nname: ${url.searchParams.get("name")}\n---\n`, path: `${HOME}/.magpie/library/skills/${url.searchParams.get("name")}/SKILL.md` } });
|
||||
if (url.pathname === "/api/library/rtk") return route.fulfill({ json: {} });
|
||||
if (url.pathname === "/api/davsync") return route.fulfill({ json: { on: false } });
|
||||
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 } } });
|
||||
if (url.pathname.startsWith("/api/")) return route.fulfill({ 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)];
|
||||
await route.fulfill({ body: await fs.readFile(file), contentType });
|
||||
};
|
||||
}
|
||||
|
||||
for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
|
||||
test(engine + ": Library makes a skill of the user's own", async (t) => {
|
||||
const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" }));
|
||||
const errors = [];
|
||||
t.after(async () => { if (errors.length) console.log(errors); await browser.close(); });
|
||||
for (const lang of ["en", "zh"]) {
|
||||
for (const width of [1100, 420]) {
|
||||
await t.test(`${lang} ${width}`, async () => {
|
||||
const ctx = await browser.newContext({ viewport: { width, height: 800 } });
|
||||
await ctx.addInitScript(() => { try { localStorage.setItem("magpie.libTab", "skills"); } catch {} });
|
||||
const page = await ctx.newPage();
|
||||
page.setDefaultTimeout(5000);
|
||||
page.setDefaultNavigationTimeout(60000);
|
||||
page.on("pageerror", (e) => errors.push(e.message));
|
||||
const posts = [], state = { skills: [] };
|
||||
await page.route("**/*", server(lang, posts, state));
|
||||
await page.goto("http://magpie.test/");
|
||||
await page.locator('button[data-view="library"]').click();
|
||||
const v = page.locator("#view-library");
|
||||
await v.locator("[data-lib=new-skill]").click();
|
||||
const dlg = page.locator(".lib-newskill");
|
||||
await dlg.waitFor();
|
||||
assert.equal(await dlg.locator("select").count(), 0, "native select");
|
||||
const sideways = await page.evaluate(() => document.documentElement.scrollWidth - document.documentElement.clientWidth);
|
||||
assert(sideways <= 0, `page scrolls sideways by ${sideways}px`);
|
||||
// a refusal stays in the dialog
|
||||
await dlg.locator("input").first().fill("taken");
|
||||
await dlg.locator("textarea").fill("Does a thing");
|
||||
await dlg.locator("button.primary").click();
|
||||
await dlg.locator(".editor-error").filter({ hasText: "taken" }).waitFor();
|
||||
assert.equal(posts.length, 1);
|
||||
// one agent unticked, then created
|
||||
await dlg.locator("input").first().fill("my-skill");
|
||||
await dlg.locator(".lib-ag[data-agent=claude]").click();
|
||||
await dlg.locator("button.primary").click();
|
||||
await page.locator(".lib-reader").waitFor();
|
||||
assert.deepEqual(posts[1], { name: "my-skill", description: "Does a thing", agents: ["codex"] });
|
||||
await page.locator(".lib-reader .lib-md").filter({ hasText: "my-skill" }).waitFor();
|
||||
await ctx.close();
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
package library
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
// A skill made in the Library (josephBenchap on X): SKILL.md with valid
|
||||
// front matter in the library's folder, given to the agents picked, and a
|
||||
// name that clashes or isn't folder-safe is refused.
|
||||
func TestCreateSkill(t *testing.T) {
|
||||
h := sandbox(t)
|
||||
ok(t)(CreateSkill("my-skill", "Does: a thing\nacross lines", []string{"claude", "codex"}))
|
||||
b, err := os.ReadFile(filepath.Join(skillDir("my-skill"), "SKILL.md"))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
m := parseMeta(b)
|
||||
if m.Name != "my-skill" || m.Description != "Does: a thing across lines" {
|
||||
t.Errorf("front matter: %+v\\n%s", m, b)
|
||||
}
|
||||
for _, d := range []string{".claude/skills/my-skill", ".codex/skills/my-skill"} {
|
||||
if _, err := os.Stat(filepath.Join(h, d, "SKILL.md")); err != nil {
|
||||
t.Errorf("not given to %s: %v", d, err)
|
||||
}
|
||||
}
|
||||
v, _ := Read(nil)
|
||||
if len(v.Skills) != 1 || v.Skills[0].Name != "my-skill" {
|
||||
t.Errorf("listed: %+v", v.Skills)
|
||||
}
|
||||
skill(t, filepath.Join(h, ".claude/skills/theirs"), "theirs", "An agent's own")
|
||||
for _, c := range [][2]string{
|
||||
{"My-Skill", "d"}, {"theirs", "d"}, {"../x", "d"}, {"a/b", "d"}, {"", "d"}, {"fine", " "}, {"fine", strings.Repeat("x", 1025)},
|
||||
} {
|
||||
if _, err := CreateSkill(c[0], c[1], nil); err == nil {
|
||||
t.Errorf("%q / %.10q was taken", c[0], c[1])
|
||||
}
|
||||
}
|
||||
if _, err := os.Lstat(skillDir("fine")); err == nil {
|
||||
t.Error("a refused skill left a folder")
|
||||
}
|
||||
}
|
||||
@@ -1731,6 +1731,53 @@ func (l *Library) offered(p *Probe, path string, shown bool) {
|
||||
}
|
||||
}
|
||||
|
||||
// CreateSkill makes a skill of the user's own in the library's folder: a
|
||||
// SKILL.md with a name and description in its front matter, listed with no
|
||||
// source and given to the agents like any other. The name can't be one the
|
||||
// library has, one an agent has of its own, or a folder in the way.
|
||||
func CreateSkill(name, description string, agents []string) (*Result, error) {
|
||||
name = strings.TrimSpace(name)
|
||||
if err := checkName("skill", name); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
description = strings.Join(strings.Fields(description), " ")
|
||||
if description == "" {
|
||||
return nil, errors.New("a skill needs a description: it is how an agent knows when to load it")
|
||||
}
|
||||
if len([]rune(description)) > 1024 {
|
||||
return nil, errors.New("the description is over 1024 characters")
|
||||
}
|
||||
return change(func(l *Library) error {
|
||||
same := func(n string) bool { return strings.EqualFold(n, name) }
|
||||
if slices.ContainsFunc(l.Skills, func(s *Skill) bool { return same(s.Name) }) ||
|
||||
slices.ContainsFunc(foundSkills(l), func(f FoundSkill) bool { return same(f.Name) }) {
|
||||
return fmt.Errorf("there is a skill called %s already", name)
|
||||
}
|
||||
dir := skillDir(name)
|
||||
if _, err := os.Lstat(dir); err == nil {
|
||||
return fmt.Errorf("the library's folder already has a %s in it (%s)", name, dir)
|
||||
} else if !errors.Is(err, fs.ErrNotExist) {
|
||||
return err
|
||||
}
|
||||
head, err := yaml.Marshal(meta{Name: name, Description: description})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
text := "---\n" + string(head) + "---\n\n# " + name + "\n\nWrite what the agent should do when this skill is used.\n"
|
||||
if err := os.MkdirAll(dir, 0o755); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := os.WriteFile(filepath.Join(dir, "SKILL.md"), []byte(text), 0o644); err != nil {
|
||||
os.RemoveAll(dir)
|
||||
return err
|
||||
}
|
||||
ag := slices.Clone(agents)
|
||||
slices.Sort(ag)
|
||||
l.Skills = append(l.Skills, &Skill{Name: name, Agents: slices.Compact(ag)})
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
// UpdateSkill fetches a skill from GitHub again, in place: the agents'
|
||||
// links go on pointing at it. One changed here since it was fetched is
|
||||
// an *EditedError unless replace is set, and then the changed version is
|
||||
|
||||
Reference in New Issue
Block a user