From 5629c35e225ca20e879c35e0b5e5e7eba80675d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8F=AB=E6=88=91=E5=B0=8F=E6=9D=A8=E5=90=8C=E5=AD=A6?= Date: Mon, 21 Sep 2026 13:30:58 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B5=8B=E8=AF=95=E7=89=88=E6=A0=87?= =?UTF-8?q?=E5=87=BA=20Skill=20=E5=AE=98=E6=96=B9=E8=B0=83=E7=94=A8?= =?UTF-8?q?=E6=96=B9=E5=BC=8F=EF=BC=88/=E5=90=8D=E7=A7=B0=E4=B8=8E?= =?UTF-8?q?=E6=A8=A1=E5=9E=8B=20skill=20=E5=B7=A5=E5=85=B7=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Cursor --- .gitignore | 4 ++++ client.js | 22 ++++++++++++++++++---- lib/index.js | 11 ++++++++++- lib/skills.js | 34 +++++++++++++++++++++++++++++++++- 4 files changed, 65 insertions(+), 6 deletions(-) diff --git a/.gitignore b/.gitignore index f5f5251..ab4b0a1 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,7 @@ +# 外部参考仓库,禁止提交 +choirboy-prompt/ +/choirboy-prompt/ + node_modules/ *.tgz npm-debug.log* diff --git a/client.js b/client.js index b173d36..8c0718b 100644 --- a/client.js +++ b/client.js @@ -238,8 +238,8 @@ window.__ModuleLoader__.load({ id: "dsh-purge", factory: (require) => { "ph.content": "", "btn.saveRule": "保存", "skills.title": "Skill", - "skills.hint": "官方 Skill 目录。可导入压缩包或文件夹。命中和加载由 DSH 负责。", - "skills.hint.desktop": "当前桌面宿主的官方 Skill 目录。可导入压缩包或文件夹。命中和加载由 DSH 负责。", + "skills.hint": "导入到官方目录后,由 DSH 调用:聊天输入 /名称 立即加载;任务对上 description 或 whenToUse 时模型会调 skill 工具。正文写「激活」不会触发。", + "skills.hint.desktop": "当前桌面宿主的官方 Skill 目录。聊天输入 /名称 立即加载;任务对上 description 时模型会调 skill 工具。", "skills.empty": "暂无用户 Skill", "btn.importZip": "导入压缩包", "btn.importFolder": "导入文件夹", @@ -249,6 +249,10 @@ window.__ModuleLoader__.load({ id: "dsh-purge", factory: (require) => { "err.import.folder": "没读到文件夹里的文件,请直接选 Skill 目录(里面要有 SKILL.md)", "skills.pick": "选择 Skill", "skills.invalid": "官方会忽略:格式不对", + "skills.call.slash": "聊天输入 {cmd}", + "skills.call.model": "模型可调", + "skills.call.modelOff": "模型不可调", + "skills.call.userOff": "不可 /名称", "ph.skill.desc": "description(何时用)", "btn.saveSkill": "保存", "need.skill.id": "id 必须是 kebab-case,例如 code-review", @@ -444,8 +448,8 @@ window.__ModuleLoader__.load({ id: "dsh-purge", factory: (require) => { "ph.content": "", "btn.saveRule": "Save", "skills.title": "Skills", - "skills.hint": "Official skill catalog. Import a zip or folder. DSH owns match and load.", - "skills.hint.desktop": "This desktop host’s official skill catalog. Import a zip or folder. DSH owns match and load.", + "skills.hint": "After import, DSH calls it: type /name in chat to load now; the model calls the skill tool when the task matches description or whenToUse. Writing「激活」in the body does nothing.", + "skills.hint.desktop": "This desktop host’s official skill catalog. Type /name in chat to load; the model calls the skill tool when the task matches the description.", "skills.empty": "No user skills", "btn.importZip": "Import zip", "btn.importFolder": "Import folder", @@ -455,6 +459,10 @@ window.__ModuleLoader__.load({ id: "dsh-purge", factory: (require) => { "err.import.folder": "No files were read. Select the skill folder itself (it must contain SKILL.md).", "skills.pick": "Select a skill", "skills.invalid": "Official catalog will ignore this: invalid format", + "skills.call.slash": "Type {cmd} in chat", + "skills.call.model": "Model can load", + "skills.call.modelOff": "Hidden from model", + "skills.call.userOff": "/name disabled", "ph.skill.desc": "description (when to use)", "btn.saveSkill": "Save", "need.skill.id": "id must be kebab-case, e.g. code-review", @@ -1807,6 +1815,12 @@ window.__ModuleLoader__.load({ id: "dsh-purge", factory: (require) => { h("span", { className: "dshp-rule-meta" }, (item.valid ? item.description : t("skills.invalid")) + " · " + formatSize(item.size), ), + item.valid ? h("span", { className: "dshp-rule-meta" }, + [ + item.userInvocable ? t("skills.call.slash", { cmd: "/" + item.id }) : t("skills.call.userOff"), + item.modelInvocable ? t("skills.call.model") : t("skills.call.modelOff"), + ].join(" · "), + ) : null, ), h("div", { className: "dshp-rule-ops" }, h(Btn, { diff --git a/lib/index.js b/lib/index.js index 95ce792..a968114 100644 --- a/lib/index.js +++ b/lib/index.js @@ -518,7 +518,8 @@ function renderSkillsStatus(st) { const out = []; out.push("官方用户 Skill / $DSH_HOME/skills"); out.push(` ${st.skills_dir}`); - out.push(" 命中与加载由官方 skill 工具负责;插件只安装和删除目录。"); + out.push(" 插件只安装目录。调用走官方:任务对上 description/whenToUse 时模型调 skill 工具;聊天输入 /名称 立即加载。"); + out.push(" 正文里写「激活」不会触发。官方认 name、description、whenToUse、disable-model-invocation、user-invocable。"); out.push(""); if (!st.skills.length) { out.push(" (暂无用户 Skill — 用 /skills import <压缩包或文件夹> 或设置页导入)"); @@ -527,7 +528,14 @@ function renderSkillsStatus(st) { for (const item of st.skills) { const mark = item.valid ? "·" : "!"; const desc = item.description || "(无说明)"; + const how = item.valid + ? [ + item.userInvocable ? `/${item.id}` : "不可 /名称", + item.modelInvocable ? "模型可调" : "模型不可调", + ].join(" · ") + : ""; out.push(` ${mark} ${item.id} ${desc} (${skills.formatSize(item.size)})`); + if (how) out.push(` ${how}`); if (!item.valid && item.error) out.push(` ${item.error}`); } return out.join("\n"); @@ -600,6 +608,7 @@ async function handleSkillsCommand(rawInput) { " /skills import <路径> 导入压缩包或文件夹到官方目录\n" + " /skills delete 删除该目录(官方会从目录拿掉)\n" + " 也可自己删 $DSH_HOME/skills/\n" + + " 调用:聊天输入 /,或让模型按 description 调 skill 工具\n" + " 不注入 systemPrompt,不替代提示词", }; } diff --git a/lib/skills.js b/lib/skills.js index b532883..3bbec45 100644 --- a/lib/skills.js +++ b/lib/skills.js @@ -106,6 +106,22 @@ function yamlLineField(head, key) { return value; } +function yamlBoolField(head, key) { + const re = new RegExp(`^${key}:\\s*(.*)$`, "m"); + const match = String(head || "").match(re); + if (!match) return { present: false }; + let value = match[1].trim(); + if ((value.startsWith("\"") && value.endsWith("\"")) || (value.startsWith("'") && value.endsWith("'"))) { + value = value.slice(1, -1).trim(); + } + const comment = value.indexOf(" #"); + if (comment >= 0) value = value.slice(0, comment).trim(); + const norm = value.toLowerCase(); + if (["true", "yes", "on", "1"].includes(norm)) return { present: true, value: true }; + if (["false", "no", "off", "0"].includes(norm)) return { present: true, value: false }; + return { present: true, invalid: true }; +} + export function parseSkillDocument(raw) { const parts = splitFrontmatter(raw); if (!parts) return { ok: false, error: "缺少 YAML frontmatter(须以 --- 包围)" }; @@ -113,7 +129,20 @@ export function parseSkillDocument(raw) { const description = yamlLineField(parts.head, "description"); if (!validSkillName(name)) return { ok: false, error: "frontmatter.name 必须是 kebab-case,例如 code-review" }; if (!description) return { ok: false, error: "frontmatter.description 必填(单行)" }; - return { ok: true, name, description, body: parts.body, head: parts.head }; + const disableModel = yamlBoolField(parts.head, "disable-model-invocation"); + const userInvocable = yamlBoolField(parts.head, "user-invocable"); + if (disableModel.invalid) return { ok: false, error: "disable-model-invocation 必须是布尔值(true/false)" }; + if (userInvocable.invalid) return { ok: false, error: "user-invocable 必须是布尔值(true/false)" }; + return { + ok: true, + name, + description, + whenToUse: yamlLineField(parts.head, "whenToUse"), + modelInvocable: disableModel.value !== true, + userInvocable: userInvocable.value !== false, + body: parts.body, + head: parts.head, + }; } export function renderSkillDocument(id, description, body = "") { @@ -174,6 +203,9 @@ async function skillFromFile(id, fp, kind) { path: fp, content, description: parsed.ok ? parsed.description : "", + whenToUse: parsed.ok ? parsed.whenToUse : "", + modelInvocable: parsed.ok ? parsed.modelInvocable : false, + userInvocable: parsed.ok ? parsed.userInvocable : false, valid: parsed.ok, error: parsed.ok ? null : parsed.error, size: Buffer.byteLength(content, "utf8"),