@ease-ops/skill 0.0.0-stage → 2.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +51 -2
- package/SKILL.md +41 -0
- package/bin/ease-ops-skill.mjs +418 -0
- package/lib/clients.mjs +128 -0
- package/lib/gitignore.mjs +31 -0
- package/lib/jsonconf.mjs +86 -0
- package/lib/mcp.mjs +166 -0
- package/lib/skill.mjs +70 -0
- package/package.json +39 -4
- package/references/clients.md +247 -0
- package/references/detect.md +189 -0
- package/references/errors.md +289 -0
- package/references/onboarding.md +102 -0
- package/references/payload.md +686 -0
- package/references/requirements/commit.md +44 -0
- package/references/requirements/delivery.md +87 -0
- package/references/requirements/errors.md +47 -0
- package/references/requirements/external-key.md +29 -0
- package/references/requirements/progress-card.md +96 -0
- package/references/requirements/story-splitting.md +102 -0
- package/references/requirements.md +198 -0
- package/references/verify.md +78 -0
package/README.md
CHANGED
|
@@ -1,3 +1,52 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @ease-ops/skill
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
ease-ops 的唯一 Agent Skill 安装器,同时提供**仓库接入**与**需求研发交付**能力。
|
|
4
|
+
|
|
5
|
+
- Skill:`ease-ops`
|
|
6
|
+
- npm 包:`@ease-ops/skill`
|
|
7
|
+
- CLI:`ease-ops-skill`
|
|
8
|
+
- 源码目录:`skills/ease-ops/`
|
|
9
|
+
- 运行要求:Node.js 18+
|
|
10
|
+
|
|
11
|
+
## 使用
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
# 安装统一 Skill、配置 MCP 并验活
|
|
15
|
+
npx @ease-ops/skill init
|
|
16
|
+
|
|
17
|
+
# 检查 Skill、MCP 配置与连通性
|
|
18
|
+
npx @ease-ops/skill doctor
|
|
19
|
+
|
|
20
|
+
# 卸载统一 Skill 与 ease-ops MCP 配置
|
|
21
|
+
npx @ease-ops/skill remove
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
常用参数:`--client cursor|claude|codebuddy|vscode|codex|generic|all`、`--url`、`--token`、`--root`、`--force`、`--dry-run`、`--no-verify`。Key 优先使用 `EASE_OPS_TOKEN`,避免留在 shell 历史中。
|
|
25
|
+
|
|
26
|
+
## 内容
|
|
27
|
+
|
|
28
|
+
```text
|
|
29
|
+
skills/ease-ops/
|
|
30
|
+
├── SKILL.md
|
|
31
|
+
└── references/
|
|
32
|
+
├── onboarding.md
|
|
33
|
+
├── requirements.md
|
|
34
|
+
├── requirements/
|
|
35
|
+
├── payload.md
|
|
36
|
+
├── detect.md
|
|
37
|
+
├── errors.md
|
|
38
|
+
├── verify.md
|
|
39
|
+
└── clients.md
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
安装结果只有一个 `SKILL.md`。Codex/generic 等无原生 skills 目录的客户端使用 `.ease-ops/ease-ops/`。安装器只修改 MCP 配置中的 `ease-ops` 项,保留其他 server。
|
|
43
|
+
|
|
44
|
+
## 开发与发布
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
npm test
|
|
48
|
+
npm pack --dry-run
|
|
49
|
+
npm publish --access public
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
发布包包含 `SKILL.md`、`bin/`、`lib/` 与完整 `references/`,不依赖仓库中的其他目录。
|
package/SKILL.md
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: ease-ops
|
|
3
|
+
description: >-
|
|
4
|
+
用 ease-ops 平台完成仓库接入、构建部署配置,以及需求→版本→方案→实现→测试交付。
|
|
5
|
+
用于“把这个仓库接入 ease-ops”“加组件进流水线”“只构建不部署”“登记需求”
|
|
6
|
+
“开始开发”“同步设计并入版”等诉求。先判断任务属于接入还是研发交付,再读取对应参考文档。
|
|
7
|
+
version: 2.1.1
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
# ease-ops
|
|
11
|
+
|
|
12
|
+
这是 ease-ops 的唯一 Skill 入口。你负责读仓库、推断与执行流程;平台负责校验、状态与构建;人负责选择、显式确认和填写密钥。
|
|
13
|
+
|
|
14
|
+
## 路由
|
|
15
|
+
|
|
16
|
+
1. 调用 `ease_ops_whoami`,确认身份、权限与版本。若 `min_skill_version` 高于本文版本,停止并提示用户运行 `npx @ease-ops/skill@latest init` 升级。
|
|
17
|
+
2. 读取 `.ease-ops/workspace.json` 与 `.ease-ops/requirements.json` 作为缓存;平台状态始终是真源。
|
|
18
|
+
3. 按用户意图选择一条主流程:
|
|
19
|
+
- **仓库接入、组件、流水线、构建或部署配置**:完整读取 [references/onboarding.md](references/onboarding.md),按其阶段执行。
|
|
20
|
+
- **需求登记、方案、版本、功能实现或测试交付**:完整读取 [references/requirements.md](references/requirements.md),先完成研发门禁再改代码。
|
|
21
|
+
4. 两类工作同时出现时,先完成接入,再进入需求研发;不得跳过任一流程的确认门禁。
|
|
22
|
+
|
|
23
|
+
## 共同安全规则
|
|
24
|
+
|
|
25
|
+
- 密钥不进入文件、命令、日志或回复;只通过平台一次性填写页面补录。
|
|
26
|
+
- 不使用本地路径仓库;接入必须有真实 git 远程地址。
|
|
27
|
+
- 不猜测工具参数。接入字段查 [references/payload.md](references/payload.md),错误处置查 [references/errors.md](references/errors.md)。
|
|
28
|
+
- 不自动重试平台写入失败,不触发生产,不手工把需求标为已发布。
|
|
29
|
+
- 每个阶段结束输出进度卡;用户确认必须明确,“你先做着”不算确认。
|
|
30
|
+
|
|
31
|
+
## 参考文档
|
|
32
|
+
|
|
33
|
+
| 文档 | 用途 |
|
|
34
|
+
|---|---|
|
|
35
|
+
| [references/onboarding.md](references/onboarding.md) | 仓库接入五阶段与硬规则 |
|
|
36
|
+
| [references/detect.md](references/detect.md) | 本地仓库、构建、产物与部署信息识别 |
|
|
37
|
+
| [references/payload.md](references/payload.md) | 接入 payload 字段契约 |
|
|
38
|
+
| [references/verify.md](references/verify.md) | 接入后的构建验证 |
|
|
39
|
+
| [references/requirements.md](references/requirements.md) | 需求研发门禁与测试交付 |
|
|
40
|
+
| [references/requirements/](references/requirements/) | 故事拆分、提交、交付、错误、进度卡与 external_key 规范 |
|
|
41
|
+
| [references/clients.md](references/clients.md) | MCP 客户端配置与排障 |
|
|
@@ -0,0 +1,418 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// ease-ops 统一 Skill 安装器:init / doctor / remove
|
|
3
|
+
// 设计见 ../../docs/design/skill-onboarding.md §5.4,客户端差异见 references/clients.md
|
|
4
|
+
|
|
5
|
+
import fs from 'node:fs';
|
|
6
|
+
import path from 'node:path';
|
|
7
|
+
import process from 'node:process';
|
|
8
|
+
|
|
9
|
+
import { CLIENTS, ENV_NAME, SERVER_NAME, getClient, needsInlineToken, resolveTokenValue } from '../lib/clients.mjs';
|
|
10
|
+
import { readConfig, snippetFor, upsertServer, removeServer, writeConfig } from '../lib/jsonconf.mjs';
|
|
11
|
+
import { ensureIgnored, gitRoot, isGitRepo, isIgnored } from '../lib/gitignore.mjs';
|
|
12
|
+
import { PACKAGE_ROOT, SKILL_NAME, compareVersions, installSkill, readVersion, removeSkill } from '../lib/skill.mjs';
|
|
13
|
+
import { callTool, normalizeUrl } from '../lib/mcp.mjs';
|
|
14
|
+
|
|
15
|
+
const RULES_BODY = `# ease-ops 接入与研发
|
|
16
|
+
|
|
17
|
+
当用户说"接入 ease-ops""加个组件进流水线""登记需求""开始开发"时:
|
|
18
|
+
1. 读 \`.ease-ops/ease-ops/SKILL.md\`,按任务路由到接入或需求研发流程;
|
|
19
|
+
2. 接入 payload 只允许 \`.ease-ops/ease-ops/references/payload.md\` 里的定义;
|
|
20
|
+
3. 需求先完成需求→版本→方案门禁;不要把密钥写进任何文件或对话。
|
|
21
|
+
`;
|
|
22
|
+
|
|
23
|
+
function parseArgs(argv) {
|
|
24
|
+
const out = { _: [] };
|
|
25
|
+
for (let i = 0; i < argv.length; i += 1) {
|
|
26
|
+
const a = argv[i];
|
|
27
|
+
if (!a.startsWith('--')) {
|
|
28
|
+
out._.push(a);
|
|
29
|
+
continue;
|
|
30
|
+
}
|
|
31
|
+
const key = a.slice(2);
|
|
32
|
+
const boolKeys = new Set(['force', 'dry-run', 'no-verify', 'yes', 'help']);
|
|
33
|
+
if (boolKeys.has(key)) {
|
|
34
|
+
out[key] = true;
|
|
35
|
+
} else {
|
|
36
|
+
out[key] = argv[i + 1];
|
|
37
|
+
i += 1;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return out;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const c = {
|
|
44
|
+
dim: (s) => `\x1b[2m${s}\x1b[0m`,
|
|
45
|
+
bold: (s) => `\x1b[1m${s}\x1b[0m`,
|
|
46
|
+
red: (s) => `\x1b[31m${s}\x1b[0m`,
|
|
47
|
+
green: (s) => `\x1b[32m${s}\x1b[0m`,
|
|
48
|
+
yellow: (s) => `\x1b[33m${s}\x1b[0m`,
|
|
49
|
+
};
|
|
50
|
+
const color = process.stdout.isTTY ? c : { dim: (s) => s, bold: (s) => s, red: (s) => s, green: (s) => s, yellow: (s) => s };
|
|
51
|
+
|
|
52
|
+
const mark = {
|
|
53
|
+
ok: () => color.green('[ok] '),
|
|
54
|
+
skip: () => color.dim('[skip]'),
|
|
55
|
+
warn: () => color.yellow('[warn]'),
|
|
56
|
+
fail: () => color.red('[fail]'),
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
function say(kind, label, extra = '') {
|
|
60
|
+
process.stdout.write(`${mark[kind]()} ${label}${extra ? ` ${color.dim(extra)}` : ''}\n`);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const isEmptyObject = (value) => Boolean(value) && typeof value === 'object' && Object.keys(value).length === 0;
|
|
64
|
+
|
|
65
|
+
// 从已写入的客户端配置里找回 MCP 地址:重跑 init / doctor 时不必再记 --url
|
|
66
|
+
function discoverServerUrl(root) {
|
|
67
|
+
for (const client of Object.values(CLIENTS)) {
|
|
68
|
+
if (!client.configPath) continue;
|
|
69
|
+
const conf = readConfig(path.join(root, client.configPath));
|
|
70
|
+
const url = conf.data?.[client.serversKey]?.[SERVER_NAME]?.url;
|
|
71
|
+
if (typeof url === 'string' && url) return url;
|
|
72
|
+
}
|
|
73
|
+
return '';
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function detectClients(root) {
|
|
77
|
+
return Object.values(CLIENTS)
|
|
78
|
+
.filter((client) => client.id !== 'generic')
|
|
79
|
+
.filter((client) => {
|
|
80
|
+
// .vscode/ 太常见(放 settings.json 的仓也在内),只有已存在 mcp.json 才算用了 MCP
|
|
81
|
+
if (client.id === 'vscode') return fs.existsSync(path.join(root, '.vscode', 'mcp.json'));
|
|
82
|
+
return client.probeDirs.some((d) => fs.existsSync(path.join(root, d)));
|
|
83
|
+
})
|
|
84
|
+
.map((client) => client.id);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
async function promptHidden(question) {
|
|
88
|
+
if (!process.stdin.isTTY) {
|
|
89
|
+
const chunks = [];
|
|
90
|
+
for await (const chunk of process.stdin) chunks.push(chunk);
|
|
91
|
+
return Buffer.concat(chunks).toString('utf8').trim();
|
|
92
|
+
}
|
|
93
|
+
return new Promise((resolve) => {
|
|
94
|
+
process.stdout.write(question);
|
|
95
|
+
const stdin = process.stdin;
|
|
96
|
+
stdin.setRawMode(true);
|
|
97
|
+
stdin.resume();
|
|
98
|
+
stdin.setEncoding('utf8');
|
|
99
|
+
let buf = '';
|
|
100
|
+
const done = (value) => {
|
|
101
|
+
stdin.setRawMode(false);
|
|
102
|
+
stdin.pause();
|
|
103
|
+
stdin.removeListener('data', onData);
|
|
104
|
+
process.stdout.write('\n');
|
|
105
|
+
resolve(value);
|
|
106
|
+
};
|
|
107
|
+
const onData = (chunk) => {
|
|
108
|
+
for (const ch of chunk) {
|
|
109
|
+
if (ch === '\r' || ch === '\n' || ch === '\u0004') return done(buf);
|
|
110
|
+
if (ch === '\u0003') {
|
|
111
|
+
stdin.setRawMode(false);
|
|
112
|
+
process.stdout.write('\n');
|
|
113
|
+
process.exit(130);
|
|
114
|
+
}
|
|
115
|
+
if (ch === '\u007f' || ch === '\b') buf = buf.slice(0, -1);
|
|
116
|
+
else buf += ch;
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
stdin.on('data', onData);
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
async function resolveToken(args, clients) {
|
|
124
|
+
const fromArgs = args.token || process.env[ENV_NAME] || '';
|
|
125
|
+
if (fromArgs) return fromArgs;
|
|
126
|
+
// 只有"写入配置文件且不支持变量注入"的客户端才必须拿到 Key;generic 只打印片段
|
|
127
|
+
const needsInline = clients.some((client) => client.configPath && needsInlineToken(client));
|
|
128
|
+
if (needsInline) {
|
|
129
|
+
const typed = await promptHidden(`${ENV_NAME}(输入不回显,可留空改用变量注入): `);
|
|
130
|
+
return typed;
|
|
131
|
+
}
|
|
132
|
+
return '';
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
async function verify(url, token) {
|
|
136
|
+
if (!token) {
|
|
137
|
+
say('skip', '连通性验证', '未提供 Key,跳过(配置已写入)');
|
|
138
|
+
return null;
|
|
139
|
+
}
|
|
140
|
+
const result = await callTool({ url, token, name: 'ease_ops_whoami' });
|
|
141
|
+
if (!result.ok) {
|
|
142
|
+
say('fail', '连通性验证', result.error.message);
|
|
143
|
+
if (result.error.detail) process.stdout.write(`${color.dim(` ${String(result.error.detail).replace(/\s+/g, ' ').slice(0, 200)}`)}\n`);
|
|
144
|
+
process.stdout.write(`${color.dim(' 排障对照:references/clients.md §7')}\n`);
|
|
145
|
+
return null;
|
|
146
|
+
}
|
|
147
|
+
const info = typeof result.data === 'object' ? result.data : { raw: result.data };
|
|
148
|
+
const who = info.user?.name || info.user?.username || info.username || info.name || '已认证';
|
|
149
|
+
const projects = info.projects?.length ?? info.project_count ?? null;
|
|
150
|
+
say('ok', '连通性验证', `${who}${projects !== null ? ` / ${projects} 个项目` : ''}`);
|
|
151
|
+
if (info.min_skill_version) {
|
|
152
|
+
const local = readVersion(PACKAGE_ROOT) || '0.0.0';
|
|
153
|
+
if (compareVersions(info.min_skill_version, local) > 0) {
|
|
154
|
+
say('warn', 'skill 版本偏低', `平台要求 ≥${info.min_skill_version},本地 ${local}`);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
return info;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
async function cmdInit(args) {
|
|
161
|
+
const root = path.resolve(args.root || gitRoot(process.cwd()) || process.cwd());
|
|
162
|
+
const dryRun = Boolean(args['dry-run']);
|
|
163
|
+
|
|
164
|
+
let ids = args.client && args.client !== 'all' ? [args.client] : args.client === 'all' ? Object.keys(CLIENTS) : detectClients(root);
|
|
165
|
+
if (ids.length === 0) ids = ['cursor'];
|
|
166
|
+
const clients = ids.map(getClient);
|
|
167
|
+
|
|
168
|
+
process.stdout.write(`${color.bold('ease-ops skill · init')}\n`);
|
|
169
|
+
say('ok', '项目根', root);
|
|
170
|
+
if (dryRun) say('warn', 'dry-run', '不写任何文件');
|
|
171
|
+
say('ok', '客户端', clients.map((x) => x.label).join(', '));
|
|
172
|
+
|
|
173
|
+
const url = normalizeUrl(args.url || process.env.EASE_OPS_URL || discoverServerUrl(root));
|
|
174
|
+
if (!url) {
|
|
175
|
+
say('fail', 'endpoint', '缺少 --url 或 EASE_OPS_URL(例:https://ops.example.com)');
|
|
176
|
+
return 1;
|
|
177
|
+
}
|
|
178
|
+
if (!url.startsWith('https://') && !/^http:\/\/(127\.0\.0\.1|localhost)(:|\/)/.test(url)) {
|
|
179
|
+
say('warn', 'endpoint', '非 localhost 使用明文 http,Key 会明文过网');
|
|
180
|
+
}
|
|
181
|
+
say('ok', 'endpoint', url);
|
|
182
|
+
|
|
183
|
+
const token = await resolveToken(args, clients);
|
|
184
|
+
let failed = 0;
|
|
185
|
+
|
|
186
|
+
for (const client of clients) {
|
|
187
|
+
if (client.skillRoot) {
|
|
188
|
+
const roots = [client.skillRoot, ...(client.extraSkillRoots || [])];
|
|
189
|
+
for (const skillRoot of roots) {
|
|
190
|
+
const res = installSkill(path.join(root, skillRoot), {
|
|
191
|
+
force: Boolean(args.force),
|
|
192
|
+
dryRun,
|
|
193
|
+
name: SKILL_NAME,
|
|
194
|
+
});
|
|
195
|
+
const where = path.relative(root, res.dest) || res.dest;
|
|
196
|
+
if (res.action === 'skipped') {
|
|
197
|
+
say('warn', `${client.label} skill`, `本地 ${res.destVersion} 高于包内 ${res.srcVersion},加 --force 覆盖(${where})`);
|
|
198
|
+
} else {
|
|
199
|
+
say('ok', `${client.label} skill`, `${res.action} ${res.srcVersion} → ${where}`);
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
} else {
|
|
203
|
+
say('skip', `${client.label} skill`, '该客户端不支持 skills');
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
if (client.rulesPath) {
|
|
207
|
+
const rulesFile = path.join(root, client.rulesPath);
|
|
208
|
+
if (!dryRun) {
|
|
209
|
+
fs.mkdirSync(path.dirname(rulesFile), { recursive: true });
|
|
210
|
+
fs.writeFileSync(rulesFile, RULES_BODY, 'utf8');
|
|
211
|
+
}
|
|
212
|
+
say('ok', `${client.label} rules`, `${client.rulesPath}(引用 .ease-ops/ease-ops/)`);
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
if (!client.configPath) {
|
|
216
|
+
if (client.tomlSnippet) {
|
|
217
|
+
// TOML 类客户端(Codex):打印片段让人手动合并,并给出 skill 路由提示
|
|
218
|
+
process.stdout.write(`\n${color.dim(`${client.label}:把下面这段加进 config.toml:`)}\n${client.tomlSnippet(url, ENV_NAME)}`);
|
|
219
|
+
if (client.routingHint) {
|
|
220
|
+
process.stdout.write(`\n${color.dim(client.routingHint)}\n${RULES_BODY}`);
|
|
221
|
+
}
|
|
222
|
+
continue;
|
|
223
|
+
}
|
|
224
|
+
const entry = client.serverEntry(url, resolveTokenValue(client, token || `<${ENV_NAME}>`));
|
|
225
|
+
process.stdout.write(`\n${color.dim('把下面这段合并进客户端的 MCP 配置:')}\n${snippetFor('mcpServers', SERVER_NAME, entry)}\n`);
|
|
226
|
+
continue;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
const configFile = path.join(root, client.configPath);
|
|
230
|
+
const current = readConfig(configFile);
|
|
231
|
+
if (current.hasComment || current.parseError) {
|
|
232
|
+
const entry = client.serverEntry(url, resolveTokenValue(client, token || `<${ENV_NAME}>`));
|
|
233
|
+
say('warn', `${client.label} 配置`, `${client.configPath} 含注释或无法解析,未写入`);
|
|
234
|
+
process.stdout.write(`${color.dim('请手工合并:')}\n${snippetFor(client.serversKey, SERVER_NAME, entry)}\n`);
|
|
235
|
+
continue;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
const tokenValue = resolveTokenValue(client, token);
|
|
239
|
+
if (needsInlineToken(client) && !tokenValue) {
|
|
240
|
+
say('fail', `${client.label} 配置`, '该客户端不支持变量注入,必须提供 Key');
|
|
241
|
+
failed += 1;
|
|
242
|
+
continue;
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
let next = upsertServer(current.data || {}, client.serversKey, SERVER_NAME, client.serverEntry(url, tokenValue));
|
|
246
|
+
if (client.topLevelExtras) {
|
|
247
|
+
const extras = client.topLevelExtras();
|
|
248
|
+
for (const [k, v] of Object.entries(extras)) {
|
|
249
|
+
const merged = Array.isArray(next[k]) ? next[k] : [];
|
|
250
|
+
const missing = v.filter((item) => !merged.some((m) => m.id === item.id));
|
|
251
|
+
next = { ...next, [k]: [...merged, ...missing] };
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
if (!dryRun) {
|
|
256
|
+
writeConfig(configFile, next, current.indent ?? 2);
|
|
257
|
+
if (needsInlineToken(client)) fs.chmodSync(configFile, 0o600);
|
|
258
|
+
}
|
|
259
|
+
const modeLabel = client.tokenMode === 'env' ? `变量注入 ${ENV_NAME}` : client.tokenMode === 'input' ? '输入框' : '明文 Key';
|
|
260
|
+
say('ok', `${client.label} 配置`, `${client.configPath}(${modeLabel})`);
|
|
261
|
+
|
|
262
|
+
if (needsInlineToken(client)) {
|
|
263
|
+
const ignore = ensureIgnored(root, client.configPath);
|
|
264
|
+
if (ignore.ok) say('ok', 'gitignore', ignore.added ? `已追加 ${client.configPath}` : `${client.configPath} 已被忽略`);
|
|
265
|
+
else if (ignore.reason === 'not_a_git_repo') say('warn', 'gitignore', '当前不是 git 仓库,无法校验');
|
|
266
|
+
else say('warn', 'gitignore', `${client.configPath} 未被忽略,明文 Key 有泄露风险`);
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
const verifyTarget = clients.find((x) => x.tokenMode !== 'input');
|
|
271
|
+
if (dryRun) {
|
|
272
|
+
say('skip', '连通性验证', 'dry-run');
|
|
273
|
+
} else if (!args['no-verify'] && verifyTarget) {
|
|
274
|
+
await verify(url, token);
|
|
275
|
+
} else if (args['no-verify']) {
|
|
276
|
+
say('skip', '连通性验证', '--no-verify');
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
process.stdout.write('\n');
|
|
280
|
+
if (clients.some((x) => x.tokenMode === 'env')) {
|
|
281
|
+
process.stdout.write(`${color.dim(`提醒:变量注入需要先 export ${ENV_NAME}=<key>,且必须对启动客户端的进程可见。`)}\n`);
|
|
282
|
+
}
|
|
283
|
+
if (clients.some((x) => x.configPath && x.tokenMode === 'literal')) {
|
|
284
|
+
process.stdout.write(`${color.dim('提醒:明文 Key 已写入配置文件并设为 0600,不要提交到仓库。')}\n`);
|
|
285
|
+
}
|
|
286
|
+
if (!isGitRepo(root)) process.stdout.write(`${color.dim('提醒:当前目录不是 git 仓库,接入任务仍可运行,但无法校验 gitignore。')}\n`);
|
|
287
|
+
|
|
288
|
+
return failed > 0 ? 1 : 0;
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
async function cmdDoctor(args) {
|
|
292
|
+
const root = path.resolve(args.root || gitRoot(process.cwd()) || process.cwd());
|
|
293
|
+
process.stdout.write(`${color.bold('ease-ops skill · doctor')}\n`);
|
|
294
|
+
say('ok', '项目根', root);
|
|
295
|
+
say('ok', '包版本', readVersion(PACKAGE_ROOT) || 'unknown');
|
|
296
|
+
|
|
297
|
+
for (const client of Object.values(CLIENTS)) {
|
|
298
|
+
const skillDirs = [client.skillRoot, ...(client.extraSkillRoots || [])].filter(Boolean);
|
|
299
|
+
const installed = skillDirs
|
|
300
|
+
.map((d) => ({ dir: d, version: readVersion(path.join(root, d, SKILL_NAME)) }))
|
|
301
|
+
.filter((x) => x.version);
|
|
302
|
+
if (installed.length) {
|
|
303
|
+
say('ok', `${client.label} skill`, installed.map((x) => `${x.dir}/${SKILL_NAME}@${x.version}`).join(' + '));
|
|
304
|
+
} else if (client.skillRoot && client.probeDirs.some((d) => fs.existsSync(path.join(root, d)))) {
|
|
305
|
+
say('warn', `${client.label} skill`, '未安装,重新跑 init 即可');
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
if (client.configPath) {
|
|
309
|
+
const configFile = path.join(root, client.configPath);
|
|
310
|
+
const conf = readConfig(configFile);
|
|
311
|
+
const hasEntry = Boolean(conf.data?.[client.serversKey]?.[SERVER_NAME]);
|
|
312
|
+
if (hasEntry) {
|
|
313
|
+
const mode = client.tokenMode;
|
|
314
|
+
say('ok', `${client.label} 配置`, `${client.configPath}(${mode})`);
|
|
315
|
+
if (needsInlineToken(client)) {
|
|
316
|
+
say(isIgnored(root, client.configPath) ? 'ok' : 'warn', ' gitignore',
|
|
317
|
+
isIgnored(root, client.configPath) ? '已忽略' : '未忽略,明文 Key 有泄露风险');
|
|
318
|
+
}
|
|
319
|
+
} else if (fs.existsSync(configFile)) {
|
|
320
|
+
say('warn', `${client.label} 配置`, `${client.configPath} 存在但没有 ${SERVER_NAME} 项`);
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
const token = args.token || process.env[ENV_NAME] || '';
|
|
326
|
+
const url = normalizeUrl(args.url || process.env.EASE_OPS_URL || discoverServerUrl(root));
|
|
327
|
+
if (url && token) {
|
|
328
|
+
await verify(url, token);
|
|
329
|
+
} else if (url) {
|
|
330
|
+
say('skip', '连通性验证', `缺少 token(--token 或 export ${ENV_NAME})`);
|
|
331
|
+
} else {
|
|
332
|
+
say('skip', '连通性验证', '缺少 --url 或 EASE_OPS_URL');
|
|
333
|
+
}
|
|
334
|
+
return 0;
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
async function cmdRemove(args) {
|
|
338
|
+
const root = path.resolve(args.root || gitRoot(process.cwd()) || process.cwd());
|
|
339
|
+
const dryRun = Boolean(args['dry-run']);
|
|
340
|
+
process.stdout.write(`${color.bold('ease-ops skill · remove')}\n`);
|
|
341
|
+
say('ok', '项目根', root);
|
|
342
|
+
|
|
343
|
+
// 指定 --client 时只动这一家;不带则全量清理
|
|
344
|
+
const targets = args.client && args.client !== 'all' ? [getClient(args.client)] : Object.values(CLIENTS);
|
|
345
|
+
for (const client of targets) {
|
|
346
|
+
for (const skillRoot of [client.skillRoot, ...(client.extraSkillRoots || [])].filter(Boolean)) {
|
|
347
|
+
const res = removeSkill(path.join(root, skillRoot), { dryRun, name: SKILL_NAME });
|
|
348
|
+
if (res.removed) say('ok', `${client.label} skill`, `${dryRun ? '将删除' : '已删除'} ${path.relative(root, res.dest)}`);
|
|
349
|
+
}
|
|
350
|
+
if (client.rulesPath) {
|
|
351
|
+
const rulesFile = path.join(root, client.rulesPath);
|
|
352
|
+
// 只删自己写的那份;用户改过就保留
|
|
353
|
+
if (fs.existsSync(rulesFile) && fs.readFileSync(rulesFile, 'utf8').trim() === RULES_BODY.trim()) {
|
|
354
|
+
if (!dryRun) fs.rmSync(rulesFile);
|
|
355
|
+
say('ok', `${client.label} rules`, `${dryRun ? '将删除' : '已删除'} ${client.rulesPath}`);
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
if (!client.configPath) continue;
|
|
359
|
+
const configFile = path.join(root, client.configPath);
|
|
360
|
+
const conf = readConfig(configFile);
|
|
361
|
+
if (!conf.data) continue;
|
|
362
|
+
const res = removeServer(conf.data, client.serversKey, SERVER_NAME);
|
|
363
|
+
if (res.removed) {
|
|
364
|
+
if (!dryRun) {
|
|
365
|
+
// 移除后只剩空对象(例如 {"mcpServers":{}} 也会被写成 {}):不留空文件
|
|
366
|
+
if (isEmptyObject(res.data)) fs.rmSync(configFile, { force: true });
|
|
367
|
+
else writeConfig(configFile, res.data, conf.indent ?? 2);
|
|
368
|
+
}
|
|
369
|
+
say('ok', `${client.label} 配置`, isEmptyObject(res.data) ? `${dryRun ? '将移除并删除空配置' : '已移除并删除空配置'}` : `${dryRun ? '将移除' : '已移除'} ${SERVER_NAME} 项`);
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
if (fs.existsSync(path.join(root, '.ease-ops'))) {
|
|
373
|
+
say('skip', '.ease-ops/', '保留(含 onboarding.yaml / onboarding.json / requirements.json)');
|
|
374
|
+
}
|
|
375
|
+
return 0;
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
function usage() {
|
|
379
|
+
process.stdout.write(`${color.bold('用法')}
|
|
380
|
+
npx @ease-ops/skill init [options] 安装统一 skill + 配置 MCP + 验活
|
|
381
|
+
npx @ease-ops/skill doctor [options] 检查安装状态与连通性
|
|
382
|
+
npx @ease-ops/skill remove [options] 卸载 skill 与 MCP 配置项
|
|
383
|
+
|
|
384
|
+
${color.bold('选项')}
|
|
385
|
+
--client <id> cursor | claude | codebuddy | vscode | codex | generic | all(默认自动探测)
|
|
386
|
+
--url <url> console 地址,可省略 /mcp;也可用 EASE_OPS_URL
|
|
387
|
+
--token <key> MCP Key;也可用 ${ENV_NAME},缺省时交互输入(不回显)
|
|
388
|
+
--root <dir> 项目根目录(默认取 git 根)
|
|
389
|
+
--force 目标 skill 版本更高时也覆盖
|
|
390
|
+
--dry-run 只打印动作,不写文件
|
|
391
|
+
--no-verify 跳过 whoami 连通性验证
|
|
392
|
+
-h, --help 显示本帮助
|
|
393
|
+
`);
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
async function main() {
|
|
397
|
+
const args = parseArgs(process.argv.slice(2));
|
|
398
|
+
const command = args._[0] || (args.help ? 'help' : '');
|
|
399
|
+
|
|
400
|
+
if (!command || command === 'help' || args.help) {
|
|
401
|
+
usage();
|
|
402
|
+
return 0;
|
|
403
|
+
}
|
|
404
|
+
if (command === 'init') return cmdInit(args);
|
|
405
|
+
if (command === 'doctor') return cmdDoctor(args);
|
|
406
|
+
if (command === 'remove') return cmdRemove(args);
|
|
407
|
+
|
|
408
|
+
say('fail', '未知命令', command);
|
|
409
|
+
usage();
|
|
410
|
+
return 1;
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
main()
|
|
414
|
+
.then((code) => process.exit(code ?? 0))
|
|
415
|
+
.catch((err) => {
|
|
416
|
+
say('fail', '未捕获异常', err?.stack || String(err));
|
|
417
|
+
process.exit(1);
|
|
418
|
+
});
|
package/lib/clients.mjs
ADDED
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
// 客户端差异只体现在三处:skill 落位、MCP 配置落位、Key 注入方式。
|
|
2
|
+
// 依据见 references/clients.md §2;未实测的路径一律标 requiresProbe。
|
|
3
|
+
|
|
4
|
+
const auth = (value) => ({ Authorization: `Bearer ${value}` });
|
|
5
|
+
|
|
6
|
+
export const ENV_NAME = 'EASE_OPS_TOKEN';
|
|
7
|
+
export const SERVER_NAME = 'ease-ops';
|
|
8
|
+
|
|
9
|
+
export const CLIENTS = {
|
|
10
|
+
cursor: {
|
|
11
|
+
id: 'cursor',
|
|
12
|
+
label: 'Cursor',
|
|
13
|
+
probeDirs: ['.cursor'],
|
|
14
|
+
skillRoot: '.cursor/skills',
|
|
15
|
+
configPath: '.cursor/mcp.json',
|
|
16
|
+
globalConfigPath: '~/.cursor/mcp.json',
|
|
17
|
+
serversKey: 'mcpServers',
|
|
18
|
+
tokenMode: 'env',
|
|
19
|
+
tokenExpression: () => `\${env:${ENV_NAME}}`,
|
|
20
|
+
serverEntry: (url, tokenValue) => ({ url, headers: auth(tokenValue) }),
|
|
21
|
+
},
|
|
22
|
+
|
|
23
|
+
claude: {
|
|
24
|
+
id: 'claude',
|
|
25
|
+
label: 'Claude Code',
|
|
26
|
+
probeDirs: ['.claude', '.mcp.json'],
|
|
27
|
+
skillRoot: '.claude/skills',
|
|
28
|
+
configPath: '.mcp.json',
|
|
29
|
+
serversKey: 'mcpServers',
|
|
30
|
+
tokenMode: 'env',
|
|
31
|
+
tokenExpression: () => `\${${ENV_NAME}}`,
|
|
32
|
+
// Claude Code 的 HTTP 传输必须显式声明 type
|
|
33
|
+
serverEntry: (url, tokenValue) => ({ type: 'http', url, headers: auth(tokenValue) }),
|
|
34
|
+
},
|
|
35
|
+
|
|
36
|
+
codebuddy: {
|
|
37
|
+
id: 'codebuddy',
|
|
38
|
+
label: 'CodeBuddy',
|
|
39
|
+
probeDirs: ['.codebuddy'],
|
|
40
|
+
skillRoot: '.codebuddy/skills',
|
|
41
|
+
extraSkillRoots: ['.claude/skills'], // CodeBuddy 兼容 .claude/skills
|
|
42
|
+
configPath: '.codebuddy/mcp.json',
|
|
43
|
+
serversKey: 'mcpServers',
|
|
44
|
+
tokenMode: 'literal',
|
|
45
|
+
serverEntry: (url, tokenValue) => ({ url, headers: auth(tokenValue) }),
|
|
46
|
+
requiresProbe: true, // 配置路径官方未明确,待实测
|
|
47
|
+
},
|
|
48
|
+
|
|
49
|
+
vscode: {
|
|
50
|
+
id: 'vscode',
|
|
51
|
+
label: 'VS Code (Copilot)',
|
|
52
|
+
probeDirs: ['.vscode'],
|
|
53
|
+
skillRoot: null,
|
|
54
|
+
configPath: '.vscode/mcp.json',
|
|
55
|
+
serversKey: 'servers',
|
|
56
|
+
tokenMode: 'input',
|
|
57
|
+
inputId: 'ease-ops-token',
|
|
58
|
+
topLevelExtras: () => ({
|
|
59
|
+
inputs: [
|
|
60
|
+
{
|
|
61
|
+
id: 'ease-ops-token',
|
|
62
|
+
type: 'promptString',
|
|
63
|
+
description: 'ease-ops MCP Key',
|
|
64
|
+
password: true,
|
|
65
|
+
},
|
|
66
|
+
],
|
|
67
|
+
}),
|
|
68
|
+
serverEntry: (url, tokenValue) => ({ type: 'http', url, headers: auth(tokenValue) }),
|
|
69
|
+
},
|
|
70
|
+
|
|
71
|
+
codex: {
|
|
72
|
+
id: 'codex',
|
|
73
|
+
label: 'Codex',
|
|
74
|
+
probeDirs: ['.codex', 'AGENTS.md'], // 项目里有 .codex/ 或 AGENTS.md 视为可能用 Codex
|
|
75
|
+
// Codex 无原生 skills:沿用 .ease-ops/ 落位,靠 AGENTS.md 路由(安装器打印,不覆盖用户 AGENTS.md)
|
|
76
|
+
skillRoot: '.ease-ops',
|
|
77
|
+
configPath: null, // config.toml 是 TOML,安装器不自动合并,只打印片段
|
|
78
|
+
serversKey: 'mcpServers',
|
|
79
|
+
tokenMode: 'env', // 走 bearer_token_env_var,明文不落文件
|
|
80
|
+
// serverEntry 仅占位(不写文件),真实产物见 tomlSnippet
|
|
81
|
+
serverEntry: (url, tokenValue) => ({ url, headers: auth(tokenValue) }),
|
|
82
|
+
tomlSnippet: (url, envName) =>
|
|
83
|
+
[
|
|
84
|
+
`# 追加进 ~/.codex/config.toml,或项目级 .codex/config.toml(项目级仅加载被信任的项目)`,
|
|
85
|
+
`[mcp_servers.${SERVER_NAME}]`,
|
|
86
|
+
`url = "${url}"`,
|
|
87
|
+
`bearer_token_env_var = "${envName}" # 需先 export ${envName}=<key>`,
|
|
88
|
+
`# 无法 export 时退回明文(务必把该文件加进 .gitignore):`,
|
|
89
|
+
`# http_headers = { Authorization = "Bearer eops_xxx" }`,
|
|
90
|
+
].join('\n') + '\n',
|
|
91
|
+
routingHint: '把下面三行加进项目根的 AGENTS.md,Codex 才会加载 skill:',
|
|
92
|
+
},
|
|
93
|
+
|
|
94
|
+
generic: {
|
|
95
|
+
id: 'generic',
|
|
96
|
+
label: '通用(不支持 skills)',
|
|
97
|
+
probeDirs: [],
|
|
98
|
+
skillRoot: '.ease-ops',
|
|
99
|
+
configPath: null,
|
|
100
|
+
serversKey: 'mcpServers',
|
|
101
|
+
tokenMode: 'literal',
|
|
102
|
+
serverEntry: (url, tokenValue) => ({ url, headers: auth(tokenValue) }),
|
|
103
|
+
rulesPath: '.trae/rules/ease-ops.md',
|
|
104
|
+
},
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
export function getClient(id) {
|
|
108
|
+
const c = CLIENTS[id];
|
|
109
|
+
if (!c) {
|
|
110
|
+
throw new Error(`未知客户端 ${id},可选:${Object.keys(CLIENTS).join(' / ')}`);
|
|
111
|
+
}
|
|
112
|
+
return c;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
// tokenMode=env 时写进配置的是变量表达式,而不是真实 Key
|
|
116
|
+
export function resolveTokenValue(client, token) {
|
|
117
|
+
if (client.tokenMode === 'env') return client.tokenExpression();
|
|
118
|
+
if (client.tokenMode === 'input') return `\${input:${client.inputId}}`;
|
|
119
|
+
return token;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
export function needsInlineToken(client) {
|
|
123
|
+
return client.tokenMode === 'literal';
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
export function requiresTokenForVerify(client) {
|
|
127
|
+
return client.tokenMode !== 'input';
|
|
128
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
// MCP 配置文件必须被 git 忽略——本仓两个 .cursor/mcp.json 就是反面教材(未跟踪 + 未忽略 + 明文 Key)。
|
|
2
|
+
|
|
3
|
+
import fs from 'node:fs';
|
|
4
|
+
import path from 'node:path';
|
|
5
|
+
import { spawnSync } from 'node:child_process';
|
|
6
|
+
|
|
7
|
+
export function isGitRepo(cwd) {
|
|
8
|
+
const r = spawnSync('git', ['rev-parse', '--is-inside-work-tree'], { cwd, encoding: 'utf8' });
|
|
9
|
+
return r.status === 0 && r.stdout.trim() === 'true';
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function gitRoot(cwd) {
|
|
13
|
+
const r = spawnSync('git', ['rev-parse', '--show-toplevel'], { cwd, encoding: 'utf8' });
|
|
14
|
+
return r.status === 0 ? r.stdout.trim() : null;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function isIgnored(cwd, relPath) {
|
|
18
|
+
const r = spawnSync('git', ['check-ignore', '-q', relPath], { cwd });
|
|
19
|
+
return r.status === 0;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function ensureIgnored(cwd, relPath) {
|
|
23
|
+
if (!isGitRepo(cwd)) return { ok: false, reason: 'not_a_git_repo', added: false };
|
|
24
|
+
if (isIgnored(cwd, relPath)) return { ok: true, added: false };
|
|
25
|
+
|
|
26
|
+
const file = path.join(cwd, '.gitignore');
|
|
27
|
+
const prev = fs.existsSync(file) ? fs.readFileSync(file, 'utf8') : '';
|
|
28
|
+
const sep = prev === '' || prev.endsWith('\n') ? '' : '\n';
|
|
29
|
+
fs.appendFileSync(file, `${sep}${relPath}\n`);
|
|
30
|
+
return { ok: isIgnored(cwd, relPath), added: true };
|
|
31
|
+
}
|