多 IDE/Agent 环境下的 Skill 管理方案

背景

在同一个工程项目中,团队成员可能使用不同的 IDE/Agent(例如 Codex、Cursor、GitHub Copilot 等)。尤其是在 token 消耗较快的情况下,单个开发者也可能需要在多个 IDE 之间切换。如果每个工具都维护一份独立的 skills,会带来以下问题:

  • 不同 IDE 的 skill 存储路径不同,导致 skill 内容重复且难以同步
  • 如果将每个 IDE 的 skill 存储文件都同步到项目仓库,会污染版本管理,增加心智负担

设计目标

  1. 单一事实源:技能定义只维护一份
  2. 一键分发:可同步到多个 Agent/IDE
  3. 本地隔离:IDE 运行目录不污染仓库版本管理
  4. 可重复执行:多次执行结果稳定

实现方案

虽然可以设计一个独立的 skill Git 仓库单独维护,但 skill 本身是项目的有机组成部分,新建仓库会增加维护成本,必要性不大。

因此采用以下方案:

  • 在项目中新增 agent-skills/ 目录作为共享 skill 的统一源
  • 通过 npx skills add 完成安装分发
  • 通过 .git/info/exclude 忽略本地产物,避免污染 .gitignore

配置脚本

1. 同步到所有已安装的 Agent(自动识别)

json 复制代码
"skills:sync": "npx skills add ./agent-skills --skill '*' -y"
  • ./agent-skills:指定项目目录为 skills 源
  • --skill '*':一次性安装全部技能,避免逐个声明
  • -y:非交互执行,便于脚本化和自动化

2. 同步到指定 Agent

json 复制代码
"skills:sync:target": "node scripts/skills-sync-target.mjs"
ini 复制代码
#!/usr/bin/env node

import { spawnSync } from "child_process";

const TARGET_AGENTS = ["codex", "github-copilot", "antigravity", "cursor"];
const SKILLS_SOURCE = "./agent-skills";
const SKILL_SELECTOR = "*";

if (!TARGET_AGENTS.length) {
  console.error("[skills:sync:target] No target agent configured.");
  process.exit(1);
}

const successAgents = [];

for (const agent of TARGET_AGENTS) {
  const args = [
    "skills",
    "add",
    SKILLS_SOURCE,
    "--skill",
    SKILL_SELECTOR,
    "--agent",
    agent,
    "-y",
  ];
  const result = spawnSync("npx", args, {
    stdio: "ignore",
    shell: false,
  });

  if (!result.error && result.status === 0) {
    successAgents.push(agent);
  }
}

if (successAgents.length > 0) {
  console.log(`Installed agents: ${successAgents.join(", ")}`);
  process.exit(0);
}

console.error("Installed agents: none");
process.exit(1);

用于只向特定的 Agent 分发 skills。

3. 本地忽略 IDE 目录

json 复制代码
"skills:exclude": "node scripts/sync-exclude.mjs"
javascript 复制代码
#!/usr/bin/env node

import fs from "fs";
import path from "path";

const EXCLUDE_FILE = path.join(".git", "info", "exclude");

// 需要忽略的目录或文件
const PATTERNS = [
  ".agent/",
  ".agents/",
  "openspec/",
  ".trae/",
  ".windsurf/",
  ".claude/",
  ".cursor/",
  ".codex/",
  ".github/",
];

function addExclude(pattern) {
  const content = fs.existsSync(EXCLUDE_FILE)
    ? fs.readFileSync(EXCLUDE_FILE, "utf-8")
    : "";
  const lines = content.split("\n");
  if (lines.some((line) => line === pattern)) {
    console.log(`  skip (already exists): ${pattern}`);
  } else {
    fs.appendFileSync(EXCLUDE_FILE, `${pattern}\n`, "utf-8");
    console.log(`  added: ${pattern}`);
  }
}

console.log(`Syncing local exclude rules to ${EXCLUDE_FILE} ...`);
PATTERNS.forEach(addExclude);
console.log("Done.");

该脚本将 .agent/.agents/.cursor/.codex/ 等目录写入 .git/info/exclude

为什么不直接写入 .gitignore? 实测发现如果在 .gitignore 中忽略 skill 和 command 所在目录,会导致部分 Agent 无法快捷唤醒相关功能。

4. 忽略 skills-lock.json

skills-lock.json 添加到 .gitignore 中,避免版本管理冲突。

使用流程

  1. agent-skills/ 中定义和维护 skills
  2. 执行 pnpm skills:sync 分发到所有 Agent
  3. 执行 pnpm skills:exclude 配置本地文件排除规则
  4. 私有的 skill 以及 command 等在对应的忽略目录中进行维护

该方案实现了单一事实源、一键分发和本地隔离的目标,有效解决了多 IDE/Agent 环境下的 skill 管理问题。

相关推荐
Mintopia1 小时前
密集信息展示:表格与布局的取舍与实践指南
前端
牛奶1 小时前
从一行字到改变世界:HTTP这三十年都经历了什么?
前端·http·http3
进击的尘埃1 小时前
Playwright Component Testing 深度拆解:组件挂载到底干了啥,视觉快照又怎么塞进 CI
javascript
OpenTiny社区2 小时前
以界面重构文字,GenUI 正式发布!
前端·vue.js·ai编程
yuki_uix2 小时前
深入理解 JavaScript 的 this:从困惑到掌握的完整指南
前端·javascript
小贤哥2 小时前
死磕这几道js手写题
前端·程序员
Lee川2 小时前
🌐 深入 Chrome 浏览器:从单线程到多进程架构的进化之路
前端·架构·前端框架
学以智用2 小时前
Vue 3 项目核心配置文件详解
前端·vue.js
工边页字2 小时前
AI 开发必懂:Context Window(上下文窗口)到底是什么?
前端·人工智能·后端