跳转到内容

cnb-rs skill remove

cnb-rs skill remove <SKILL>... [options]

# alias
cnb-rs skill rm <SKILL>...

卸载已装的 cnb skill:删 canonical 目录 + 各 agent 目录(symlink / copy 均处理)+ 从 lockfile 移除 entry。

gh skill / vercel-skills 装的 entry(非 sourceType: "cnb")会被拒绝处理并给清晰提示,避免误删它家管理的 skill。

参数

  • <SKILL>...:要卸载的 skill name(至少一个,对应 lockfile 中的 entry key)

选项

  • --scope <SCOPE>:安装 scope(project / user),决定要去哪个 base_dir 找文件;默认 project
  • --dir <PATH>:自定义目标根目录(覆盖 --scope
  • --keep-files仅删 lockfile entry,保留磁盘文件(给 manual 接管场景)

行为:7 步流程

  1. 校验 args:clap 层强制 <SKILL> 至少一个
  2. 加载 lockfile + 提取 sourceType: "cnb" 条目
  3. 对每个 name 选 entry:缺失或非 cnb → fail-fast,列出可选的 cnb skill 名
  4. 解析 scope / base_dir:决定文件实际位置
  5. 如果非 --keep-files
    • 删 canonical universal dir:<base>/.agents/skills/<skill>/
    • 依据 lockfile entry 的 installed_agents 字段,删每个 agent 的 <base>/<agent.skills_dir>/<skill>/
    • best-effort 语义:目录不存在 → [skip] 提示但不 fail(migrated 场景兼容)
    • symlink dir 用 remove_dir,真实 dir 用 remove_dir_all不会沿 symlink 误删 canonical
  6. lockfile remove:抹掉该 entry
  7. lockfile save

关键设计

Agent 列表来自 lockfile 而不是 --agent / detect

remove 时不读 --agent 选项,也不做 detect_installed()。完全依据 lockfile entry 记录的 installed_agents 字段 —— 即「当年装到哪几个 agent,就从哪几个 agent 删」。

这避免一个常见 footgun:用户先装 claude-code,后来又装了 windsurf(但是手动操作),用 cnb-rs skill remove 时 windsurf 目录会残留。我们把责任精准化:只清理 cnb-rs 当年实际写过的位置。

--keep-files 的用途

把 skill 文件交给用户手动管理:

bash
# 装一次 + 把 lockfile 里登记移除,让 git track 这些文件
$ cnb-rs skill install wwvo/myorg/skills my-skill --dir ./.agents
$ cnb-rs skill remove my-skill --keep-files --dir ./.agents
$ git add .agents/skills/my-skill

之后该 skill 不再受 cnb-rs skill update --all 管。

remove_skill_dirsymlink_metadata() 先 stat(不跟 symlink),再分支:

  • symlink dirremove_dir:只删 link 本身,不会跟到 canonical 把真实文件递归删了
  • 真实 dirremove_dir_all:递归删整目录(canonical 用这条)
  • 普通文件remove_file(不该出现,但 best-effort)

输出示例

$ cnb-rs skill remove cnb-rs-api
📂 base:    /home/alice/myproj
📋 targets: 1 skill(s) to remove

── cnb-rs-api ──
  [del] canonical: /home/alice/myproj/.agents/skills/cnb-rs-api
  [del] claude-code: /home/alice/myproj/.claude/skills/cnb-rs-api
  [del] windsurf: /home/alice/myproj/.codeium/windsurf/skills/cnb-rs-api
 removed

🎉 removed 1 skill(s) from lockfile; 3 dirs deleted from disk; 0 missing dirs skipped

多 skill 一次删

$ cnb-rs skill rm cnb-rs cnb-rs-api cnb-rs-issue
📂 base:    /home/alice/myproj
📋 targets: 3 skill(s) to remove

── cnb-rs ──
  [del] canonical: ...
 removed

── cnb-rs-api ──
  [del] canonical: ...
 removed

── cnb-rs-issue ──
  [del] canonical: ...
 removed

🎉 removed 3 skill(s) from lockfile; 6 dirs deleted from disk; 0 missing dirs skipped

--keep-files:仅删 lockfile entry

$ cnb-rs skill remove cnb-rs-api --keep-files
📂 base:    /home/alice/myproj
📋 targets: 1 skill(s) to remove
  --keep-files:仅删 lockfile entry,磁盘文件保留

── cnb-rs-api ──
 removed

🎉 removed 1 skill(s) from lockfile; 0 dirs deleted from disk; 0 missing dirs skipped

错误示例

没传 skill name

$ cnb-rs skill remove
error: the following required arguments were not provided:
  <SKILL>...

Usage: cnb-rs skill remove [OPTIONS] <SKILL>...

For more information, try '--help'.

Skill 不在 lockfile 中

$ cnb-rs skill remove nonexistent
错误: skill 'nonexistent' 不在 lockfile

可选 (cnb): cnb-rs, cnb-rs-api, cnb-rs-issue

Skill 是 gh / vercel 装的(非 cnb sourceType)

$ cnb-rs skill remove react-best-practices
错误: skill 'react-best-practices' sourceType 不是 "cnb"

提示:cnb-rs 只能管自家 sourceType="cnb" entry;其它 (gh/vercel) 请用对应 CLI 卸载

退出码

  • 0:所有 target 删完(含目录缺失但 best-effort 通过的情况)
  • 1:任何一步失败(skill 不存在 / 非 cnb / 删除时遇到不可恢复的 IO 错)

gh skill remove / vercel-skills remove 的差异

特性cnb-rs skill removegh skill removevercel-skills 移除
处理范围sourceType: "cnb"sourceType: "github"仅 vercel 自家
Agent 列表来源lockfile installed_agents 字段detectnpm script
--keep-files⚠ 不一致
对 symlink 的处理✅ 用 symlink_metadata 安全删 link,不沿 link 走✅ 同⚠ 不一致
pass-through 其它 sourceType✅ lockfile 中其它家 entry 完全不动✅ 同✅ 同
退出语义best-effort 删除磁盘 + fail-fast lockfile

示例

bash
# 卸载一个 skill(删文件 + 移 lockfile entry)
$ cnb-rs skill remove cnb-rs-api

# alias
$ cnb-rs skill rm cnb-rs-api

# 一次卸载多个
$ cnb-rs skill remove cnb-rs cnb-rs-api cnb-rs-issue

# 仅删 lockfile 不动磁盘(把 skill 交给手工 / git 管理)
$ cnb-rs skill remove cnb-rs-api --keep-files

# 卸载 user scope 装的
$ cnb-rs skill remove cnb-rs-api --scope user

# 卸载到指定目录的
$ cnb-rs skill remove cnb-rs-api --dir ~/my-other-base

另请参阅

Released under the MIT License.