cladogram 0.2.0 → 0.3.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 +238 -153
- package/bin/clado.js +107 -16
- package/package.json +2 -2
- package/skills/clado/SKILL.md +107 -18
- package/skills/clado/references/diagnostics.md +19 -0
- package/src/core/parse.js +55 -1
- package/src/html/app-css.js +122 -12
- package/src/html/page.js +4 -5
- package/src/html/runtime.js +825 -73
- package/src/skill/install.js +319 -0
- package/src/skill/targets.js +168 -0
|
@@ -0,0 +1,319 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `clado install` —— 把 clado 自己的 skill 装到当前项目里那些「会读 skill」的工具底下。
|
|
3
|
+
*
|
|
4
|
+
* 三件事:
|
|
5
|
+
* ① 扫当前目录,看哪些工具的痕迹在(`.claude/`、`.trae/`、`AGENTS.md` …)
|
|
6
|
+
* ② 让用户勾
|
|
7
|
+
* ③ 装。已经装过的**先整个删掉再拷**,所以升级之后不会留上一个版本的文件。
|
|
8
|
+
*
|
|
9
|
+
* ★ 为什么重装是「删了再拷」而不是「覆盖着拷」:bundle 的文件清单**每个版本都在变**
|
|
10
|
+
* (`references/diagnostics.md` 改过、例子改过名)。只覆盖同名文件的话,上个版本
|
|
11
|
+
* 多出来的那些会永远留在用户项目里,而且没有任何提示 —— 用户看到的是一份两个版本
|
|
12
|
+
* 混在一起的 skill。整个目录换掉是唯一能保证「装上之后 = 这个版本」的做法。
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import { existsSync, statSync, readFileSync, writeFileSync, mkdirSync, rmSync, cpSync, readdirSync } from 'node:fs';
|
|
16
|
+
import { resolve, join, dirname, basename, relative, sep } from 'node:path';
|
|
17
|
+
import { fileURLToPath } from 'node:url';
|
|
18
|
+
|
|
19
|
+
import { c } from '../util/term.js';
|
|
20
|
+
import { TARGETS, SKILL_NAME, BUNDLE_REL, MARK_BEGIN, MARK_END, findTarget, ruleBody } from './targets.js';
|
|
21
|
+
|
|
22
|
+
const HERE = dirname(fileURLToPath(import.meta.url));
|
|
23
|
+
const PKG_ROOT = resolve(HERE, '..', '..');
|
|
24
|
+
const BUNDLE = join(PKG_ROOT, ...BUNDLE_REL.split('/'));
|
|
25
|
+
|
|
26
|
+
/** 用户用错了(跟 build 那边的 UsageError 是一回事,bin 里统一按退出码 2 处理) */
|
|
27
|
+
export class UsageError extends Error {}
|
|
28
|
+
|
|
29
|
+
// ---------------------------------------------------------------- 文件小工具
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* 拷 bundle 时要跳过的目录名。
|
|
33
|
+
* ★ `out` 是 `examples/build.sh` 编出来的产物(三模式 36 个页面、50 多 MB),
|
|
34
|
+
* `.gitignore` 里是有的,但 `cpSync` 不读 `.gitignore` —— 跟着 bundle 一起搬过去
|
|
35
|
+
* 会把用户的项目撑爆。
|
|
36
|
+
*/
|
|
37
|
+
const SKIP = new Set(['out', 'node_modules', '.git', '.DS_Store']);
|
|
38
|
+
|
|
39
|
+
/** 目录下的所有文件,相对路径,正斜杠,排好序 */
|
|
40
|
+
function listFiles(dir) {
|
|
41
|
+
const out = [];
|
|
42
|
+
const walk = (base, rel) => {
|
|
43
|
+
for (const name of readdirSync(base).sort()) {
|
|
44
|
+
if (SKIP.has(name)) continue;
|
|
45
|
+
const abs = join(base, name);
|
|
46
|
+
const r = rel ? `${rel}/${name}` : name;
|
|
47
|
+
if (statSync(abs).isDirectory()) walk(abs, r);
|
|
48
|
+
else out.push(r);
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
walk(dir, '');
|
|
52
|
+
return out;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* 这个目录是不是「我们装的那一份」。
|
|
57
|
+
* 只看有没有 `SKILL.md` 且 frontmatter 里的 `name` 是我们 —— 靠它决定敢不敢 `rm -rf`。
|
|
58
|
+
* 用户自己的 `clado/` 目录(万一有)不能因为重名就被删掉。
|
|
59
|
+
*/
|
|
60
|
+
function looksLikeOurs(dir) {
|
|
61
|
+
const f = join(dir, 'SKILL.md');
|
|
62
|
+
if (!existsSync(f)) return false;
|
|
63
|
+
try {
|
|
64
|
+
const head = readFileSync(f, 'utf8').slice(0, 400);
|
|
65
|
+
return new RegExp(`^name:\\s*${SKILL_NAME}\\s*$`, 'm').test(head);
|
|
66
|
+
} catch {
|
|
67
|
+
return false;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** 在文本里替换 `MARK_BEGIN … MARK_END` 那一段;没有就追加到末尾 */
|
|
72
|
+
function upsertSection(text, body) {
|
|
73
|
+
const block = `${MARK_BEGIN}\n\n${body.trimEnd()}\n\n${MARK_END}\n`;
|
|
74
|
+
const begin = text.indexOf(MARK_BEGIN);
|
|
75
|
+
if (begin < 0) {
|
|
76
|
+
const sep = text.trim() ? (text.endsWith('\n\n') ? '' : text.endsWith('\n') ? '\n' : '\n\n') : '';
|
|
77
|
+
return { text: text + sep + block, replaced: false };
|
|
78
|
+
}
|
|
79
|
+
const end = text.indexOf(MARK_END, begin);
|
|
80
|
+
const after = end < 0 ? '' : text.slice(end + MARK_END.length).replace(/^\n+/, '');
|
|
81
|
+
return { text: text.slice(0, begin) + block + (after ? '\n' + after : ''), replaced: true };
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// ---------------------------------------------------------------- 扫
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* 扫当前目录。
|
|
88
|
+
* @returns {{target: object, detected: boolean, destAbs: string}[]}
|
|
89
|
+
*/
|
|
90
|
+
export function scan(cwd) {
|
|
91
|
+
return TARGETS.map((target) => ({
|
|
92
|
+
target,
|
|
93
|
+
// ★ `root` 没有 marker(它是个逃生口,不是「这个项目在用某个工具」的信号),
|
|
94
|
+
// 所以它永远显示在列表里、但**永远不算「扫到了」** —— 否则 `--list` 给的建议
|
|
95
|
+
// 会变成 `--to root,cursor`,等于劝人白装一份到根目录。
|
|
96
|
+
detected: target.marker ? existsSync(resolve(cwd, target.marker)) : false,
|
|
97
|
+
destAbs: resolve(cwd, target.dest),
|
|
98
|
+
}));
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// ---------------------------------------------------------------- 交互多选
|
|
102
|
+
|
|
103
|
+
const ESC = '\u001b[';
|
|
104
|
+
const ARROWS = [`${ESC}A`, `${ESC}B`, `${ESC}C`, `${ESC}D`];
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* 把一次 `data` 事件切成一串「键」。
|
|
108
|
+
*
|
|
109
|
+
* ★ 一次 `data` 事件不保证只有一个键:终端会把连续输入攒在一起发(用户粘贴、或者敲得快)。
|
|
110
|
+
* 把整块当成一个「键」去比对的话,`jj \r` 这种一起来的输入会整块落进 else 被默默丢掉,
|
|
111
|
+
* 表现就是「敲了没反应,卡在那儿」。方向键是 3 个字符,所以先匹配长的那几个再退回单字符。
|
|
112
|
+
*/
|
|
113
|
+
export function keysOf(chunk) {
|
|
114
|
+
let buf = String(chunk);
|
|
115
|
+
const out = [];
|
|
116
|
+
while (buf.length) {
|
|
117
|
+
let key = null;
|
|
118
|
+
for (const a of ARROWS) if (buf.startsWith(a)) { key = a; break; }
|
|
119
|
+
if (!key) key = buf[0];
|
|
120
|
+
buf = buf.slice(key.length);
|
|
121
|
+
out.push(key);
|
|
122
|
+
}
|
|
123
|
+
return out;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* 上下移动 + 空格勾 + 回车确认。
|
|
128
|
+
* 不是 TTY 就抛错让用户走 `--to` —— 硬要在一个不会回显的终端里读裸键,
|
|
129
|
+
* 只会得到一个「卡住不动」的命令。
|
|
130
|
+
*/
|
|
131
|
+
export function pick(entries) {
|
|
132
|
+
const { stdin, stdout } = process;
|
|
133
|
+
if (!stdin.isTTY || !stdout.isTTY) {
|
|
134
|
+
throw new UsageError('这个终端不能交互。用 `clado install --to claude,dsh` 指定装给谁,`--list` 只看不装。');
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
const state = entries.map((e) => e.detected);
|
|
138
|
+
let cur = 0;
|
|
139
|
+
let drawn = 0;
|
|
140
|
+
|
|
141
|
+
const render = () => {
|
|
142
|
+
const lines = [];
|
|
143
|
+
if (drawn) lines.push(`${ESC}${drawn}A`);
|
|
144
|
+
lines.push(`${ESC}0J`);
|
|
145
|
+
lines.push(` ${c.bold('装给谁?')} ${c.dim('↑↓ 移动 · 空格 勾选 · a 全选 · 回车 开始 · q 取消')}\r\n`);
|
|
146
|
+
lines.push('\r\n');
|
|
147
|
+
entries.forEach((e, i) => {
|
|
148
|
+
const at = i === cur ? c.cyan('❯') : ' ';
|
|
149
|
+
const box = state[i] ? c.green('[×]') : '[ ]';
|
|
150
|
+
const name = state[i] ? c.bold(e.target.name) : e.target.name;
|
|
151
|
+
const where = c.dim(`→ ${e.target.dest}`);
|
|
152
|
+
const tag = e.detected
|
|
153
|
+
? ''
|
|
154
|
+
: c.dim(e.target.marker ? '(这个目录里没看到它的痕迹)' : '(给表里没有的工具:丢一份到根目录,让它自己去搬)');
|
|
155
|
+
lines.push(` ${at} ${box} ${name} ${where}${tag}\r\n`);
|
|
156
|
+
});
|
|
157
|
+
lines.push('\r\n');
|
|
158
|
+
stdout.write(lines.join(''));
|
|
159
|
+
drawn = entries.length + 4;
|
|
160
|
+
};
|
|
161
|
+
|
|
162
|
+
return new Promise((res, rej) => {
|
|
163
|
+
stdin.setRawMode(true);
|
|
164
|
+
stdin.resume();
|
|
165
|
+
stdin.setEncoding('utf8');
|
|
166
|
+
render();
|
|
167
|
+
|
|
168
|
+
const done = (fn, arg) => {
|
|
169
|
+
stdin.setRawMode(false);
|
|
170
|
+
stdin.pause();
|
|
171
|
+
stdin.removeListener('data', onData);
|
|
172
|
+
stdout.write('\r\n');
|
|
173
|
+
fn(arg);
|
|
174
|
+
return 'stop';
|
|
175
|
+
};
|
|
176
|
+
|
|
177
|
+
/** 处理一个键。返回 'stop' 表示完事了,外层就不要再往下切。 */
|
|
178
|
+
const step = (key) => {
|
|
179
|
+
if (key === '\u0003' || key === 'q' || key === '\u001b') {
|
|
180
|
+
return done(rej, new UsageError('取消,什么都没装。'));
|
|
181
|
+
}
|
|
182
|
+
if (key === '\r' || key === '\n') {
|
|
183
|
+
const ids = entries.filter((_, i) => state[i]).map((e) => e.target.id);
|
|
184
|
+
return ids.length ? done(res, ids) : 'skip'; // 一个都没勾,别让回车糊弄过去
|
|
185
|
+
}
|
|
186
|
+
if (key === ' ') state[cur] = !state[cur];
|
|
187
|
+
else if (key === 'a') state.fill(!state.every(Boolean));
|
|
188
|
+
else if (key === `${ESC}A` || key === 'k') cur = (cur - 1 + entries.length) % entries.length;
|
|
189
|
+
else if (key === `${ESC}B` || key === 'j') cur = (cur + 1) % entries.length;
|
|
190
|
+
else return 'skip';
|
|
191
|
+
render();
|
|
192
|
+
return 'ok';
|
|
193
|
+
};
|
|
194
|
+
|
|
195
|
+
const onData = (chunk) => {
|
|
196
|
+
for (const key of keysOf(chunk)) {
|
|
197
|
+
if (step(key) === 'stop') return;
|
|
198
|
+
}
|
|
199
|
+
};
|
|
200
|
+
|
|
201
|
+
stdin.on('data', onData);
|
|
202
|
+
});
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
// ---------------------------------------------------------------- 装
|
|
206
|
+
|
|
207
|
+
/**
|
|
208
|
+
* 装给指定的 id。
|
|
209
|
+
* @param {string} cwd
|
|
210
|
+
* @param {string[]} ids
|
|
211
|
+
* @param {{dryRun?: boolean, force?: boolean}} opts
|
|
212
|
+
*/
|
|
213
|
+
export function installTo(cwd, ids, opts = {}) {
|
|
214
|
+
const { dryRun = false, force = false } = opts;
|
|
215
|
+
|
|
216
|
+
// `--to all` = 全都装。12 个 id 敲一遍太长了。
|
|
217
|
+
if (ids.includes('all')) ids = TARGETS.map((t) => t.id);
|
|
218
|
+
|
|
219
|
+
for (const id of ids) if (!findTarget(id)) throw new UsageError(`不认识这个工具:"${id}"`);
|
|
220
|
+
|
|
221
|
+
if (!existsSync(BUNDLE)) {
|
|
222
|
+
throw new UsageError(`包里找不到 skill 目录:${BUNDLE}\n 装的时候是不是漏了 skills/?`);
|
|
223
|
+
}
|
|
224
|
+
const files = listFiles(BUNDLE);
|
|
225
|
+
|
|
226
|
+
// 规则型的正文要指向一份真实存在的 SKILL.md。
|
|
227
|
+
// 优先指本次已经装好的目录型目标(省一份重复的拷贝),一个都没选才落到 `.clado/`。
|
|
228
|
+
const dirIds = ids.filter((id) => findTarget(id).kind === 'dir');
|
|
229
|
+
const anchor = dirIds.length ? findTarget(dirIds[0]).dest : '.clado/skills/clado';
|
|
230
|
+
const body = ruleBody(anchor);
|
|
231
|
+
const needAnchor = !dirIds.length && ids.some((id) => findTarget(id).kind !== 'dir');
|
|
232
|
+
|
|
233
|
+
const results = [];
|
|
234
|
+
const plan = [...ids.map(findTarget)];
|
|
235
|
+
if (needAnchor) {
|
|
236
|
+
plan.unshift({ id: '_anchor', name: '规则文件要指向的那份 skill', kind: 'dir', dest: anchor, doc: null });
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
for (const t of plan) {
|
|
240
|
+
const destAbs = resolve(cwd, t.dest);
|
|
241
|
+
const rel = relative(cwd, destAbs).split(sep).join('/') || '.';
|
|
242
|
+
|
|
243
|
+
if (t.kind === 'dir') {
|
|
244
|
+
const existed = existsSync(destAbs);
|
|
245
|
+
let oldCount = 0;
|
|
246
|
+
if (existed) {
|
|
247
|
+
if (!statSync(destAbs).isDirectory()) {
|
|
248
|
+
throw new UsageError(`${rel} 是一个文件,不是目录 —— 先自己挪开。`);
|
|
249
|
+
}
|
|
250
|
+
if (!looksLikeOurs(destAbs) && t.id !== '_anchor' && !force) {
|
|
251
|
+
throw new UsageError(
|
|
252
|
+
`${rel} 已经存在,但看起来不是 clado 装的(里面没有 name: ${SKILL_NAME} 的 SKILL.md)。\n` +
|
|
253
|
+
` 确认可以覆盖就加 --force。`,
|
|
254
|
+
);
|
|
255
|
+
}
|
|
256
|
+
oldCount = listFiles(destAbs).length;
|
|
257
|
+
}
|
|
258
|
+
if (!dryRun) {
|
|
259
|
+
rmSync(destAbs, { recursive: true, force: true });
|
|
260
|
+
mkdirSync(dirname(destAbs), { recursive: true });
|
|
261
|
+
// filter 里也要挡一道:listFiles 只是用来数数的,真正搬文件的是 cpSync。
|
|
262
|
+
cpSync(BUNDLE, destAbs, { recursive: true, filter: (src) => !SKIP.has(basename(src)) });
|
|
263
|
+
}
|
|
264
|
+
results.push({
|
|
265
|
+
id: t.id,
|
|
266
|
+
name: t.name,
|
|
267
|
+
dest: rel,
|
|
268
|
+
kind: 'dir',
|
|
269
|
+
action: existed ? (t.id === '_anchor' ? '写了一份' : '换掉了旧的') : '装好了',
|
|
270
|
+
added: files.length,
|
|
271
|
+
removed: existed ? oldCount : 0,
|
|
272
|
+
});
|
|
273
|
+
continue;
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
// 规则型
|
|
277
|
+
if (t.kind === 'own') {
|
|
278
|
+
const existed = existsSync(destAbs);
|
|
279
|
+
if (!dryRun) {
|
|
280
|
+
mkdirSync(dirname(destAbs), { recursive: true });
|
|
281
|
+
writeFileSync(destAbs, ownFileText(body));
|
|
282
|
+
}
|
|
283
|
+
results.push({ id: t.id, name: t.name, dest: rel, kind: 'own', action: existed ? '换掉了旧的' : '装好了', added: 1, removed: existed ? 1 : 0 });
|
|
284
|
+
continue;
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
// append:和别人共用一份规则文件
|
|
288
|
+
const existed = existsSync(destAbs);
|
|
289
|
+
const before = existed ? readFileSync(destAbs, 'utf8') : '';
|
|
290
|
+
const { text, replaced } = upsertSection(before, body);
|
|
291
|
+
if (!dryRun) {
|
|
292
|
+
mkdirSync(dirname(destAbs), { recursive: true });
|
|
293
|
+
writeFileSync(destAbs, text);
|
|
294
|
+
}
|
|
295
|
+
results.push({
|
|
296
|
+
id: t.id,
|
|
297
|
+
name: t.name,
|
|
298
|
+
dest: rel,
|
|
299
|
+
kind: 'append',
|
|
300
|
+
action: replaced ? '换掉了旧的那一段' : existed ? '往里加了一段' : '建好并写了一段',
|
|
301
|
+
added: 1,
|
|
302
|
+
removed: replaced ? 1 : 0,
|
|
303
|
+
});
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
return { results, files: files.length, anchor, dryRun };
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
/**
|
|
310
|
+
* 独占规则文件的正文。
|
|
311
|
+
* ★ Cursor 明确要求 frontmatter 里至少得有 `description` / `globs` / `alwaysApply` 之一,
|
|
312
|
+
* 不然整个文件被忽略 —— 所以这几个键不能省。
|
|
313
|
+
* 其它几家(Cline / Windsurf / CodeBuddy)只要 Markdown 就行,多一个 `description`
|
|
314
|
+
* 是无害的额外键,于是统一都带上,省得一张表里两套写法。
|
|
315
|
+
*/
|
|
316
|
+
function ownFileText(body) {
|
|
317
|
+
const desc = '用 clado 把 Markdown 编译成自包含的网页(文档 / 卡片 / 脑图三种模式)';
|
|
318
|
+
return `---\ndescription: ${desc}\nalwaysApply: false\n---\n\n${body}`;
|
|
319
|
+
}
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `clado install` 认哪些工具、往哪儿装。
|
|
3
|
+
*
|
|
4
|
+
* ★ 这张表里**每一条路径都是从官方文档上抄下来的**,不是猜的。路径错了比没有还糟:
|
|
5
|
+
* 用户以为装上了,工具其实压根不会去读那个目录,而且不会有任何报错。
|
|
6
|
+
* 所以新增一条之前先去翻文档,把链接填进 `doc`。
|
|
7
|
+
*
|
|
8
|
+
* 三种落点:
|
|
9
|
+
* dir 自家的 skills 目录,整个 bundle(15 个文件)拷成 `<dest>/`
|
|
10
|
+
* own 自家独占的规则文件,直接覆写
|
|
11
|
+
* append 和别人共用的规则文件(AGENTS.md 之类),往里写一段**带标记**的内容,
|
|
12
|
+
* 重装时替换那一段而不是再追加一段
|
|
13
|
+
*
|
|
14
|
+
* 探测标记(`marker`)用来看「这个项目是不是在用这个工具」——
|
|
15
|
+
* 只看目录/文件在不在,不去猜用户装没装那个软件。
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
/** skill 的名字。装到别人家目录底下时用的就是它 */
|
|
19
|
+
export const SKILL_NAME = 'clado';
|
|
20
|
+
|
|
21
|
+
/** 打包进 npm 的那份 bundle 在包里的位置(相对包根) */
|
|
22
|
+
export const BUNDLE_REL = `skills/${SKILL_NAME}`;
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* 共用规则文件里那一段的边界标记。
|
|
26
|
+
* 带上它,重装时才能把旧的那段整个换掉 —— 不然升级一次就多一段,越滚越长。
|
|
27
|
+
*/
|
|
28
|
+
export const MARK_BEGIN = `<!-- clado:begin 由 \`clado install\` 生成,重装会整段替换 -->`;
|
|
29
|
+
export const MARK_END = `<!-- clado:end -->`;
|
|
30
|
+
|
|
31
|
+
export const TARGETS = [
|
|
32
|
+
// ---------------------------------------------------------- 目录型
|
|
33
|
+
{
|
|
34
|
+
id: 'claude',
|
|
35
|
+
name: 'Claude Code',
|
|
36
|
+
kind: 'dir',
|
|
37
|
+
dest: '.claude/skills/clado',
|
|
38
|
+
marker: '.claude',
|
|
39
|
+
doc: 'https://docs.claude.com/en/docs/claude-code/skills',
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
id: 'dsh',
|
|
43
|
+
name: 'DSH',
|
|
44
|
+
kind: 'dir',
|
|
45
|
+
dest: '.dsh/skills/clado',
|
|
46
|
+
marker: '.dsh',
|
|
47
|
+
doc: 'https://github.com/GodShelvis/dsh',
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
id: 'trae',
|
|
51
|
+
name: 'Trae(字节)',
|
|
52
|
+
kind: 'dir',
|
|
53
|
+
dest: '.trae/skills/clado',
|
|
54
|
+
marker: '.trae',
|
|
55
|
+
doc: 'https://docs.trae.cn/work_skills?lang=zh',
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
id: 'qoder',
|
|
59
|
+
name: 'Qoder / 通义灵码(阿里)',
|
|
60
|
+
kind: 'dir',
|
|
61
|
+
dest: '.lingma/skills/clado',
|
|
62
|
+
marker: '.lingma',
|
|
63
|
+
doc: 'https://docs.qoder.cn/user-guide/skills',
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
id: 'root',
|
|
67
|
+
name: `项目根目录(丢一个 ${SKILL_NAME}/ 让 AI 自己去搬)`,
|
|
68
|
+
kind: 'dir',
|
|
69
|
+
dest: 'clado',
|
|
70
|
+
// 没有标记 = 永远列出来。这一条是给「表里没有的工具」留的逃生口:
|
|
71
|
+
// 把整个文件夹摆在根目录,任何会读项目的 AI 都能看见并搬到自己认的地方。
|
|
72
|
+
marker: null,
|
|
73
|
+
doc: null,
|
|
74
|
+
},
|
|
75
|
+
|
|
76
|
+
// ---------------------------------------------------------- 规则型
|
|
77
|
+
{
|
|
78
|
+
id: 'agents',
|
|
79
|
+
name: 'AGENTS.md(Codex / OpenCode / Cursor / Trae 都认)',
|
|
80
|
+
kind: 'append',
|
|
81
|
+
dest: 'AGENTS.md',
|
|
82
|
+
marker: 'AGENTS.md',
|
|
83
|
+
doc: 'https://agents.md/',
|
|
84
|
+
},
|
|
85
|
+
{
|
|
86
|
+
id: 'cursor',
|
|
87
|
+
name: 'Cursor',
|
|
88
|
+
kind: 'own',
|
|
89
|
+
dest: '.cursor/rules/clado.mdc',
|
|
90
|
+
marker: '.cursor',
|
|
91
|
+
// ★ Cursor 只认 `.mdc`;同一个目录里放 `.md` 会被**静默忽略**(官方原话:
|
|
92
|
+
// "A plain `.md` file in `.cursor/rules` is ignored")。所以扩展名不能改。
|
|
93
|
+
doc: 'https://cursor.com/docs/rules',
|
|
94
|
+
},
|
|
95
|
+
{
|
|
96
|
+
id: 'copilot',
|
|
97
|
+
name: 'GitHub Copilot',
|
|
98
|
+
kind: 'append',
|
|
99
|
+
dest: '.github/copilot-instructions.md',
|
|
100
|
+
marker: '.github',
|
|
101
|
+
doc: 'https://docs.github.com/en/copilot/how-tos/configure-custom-instructions/add-repository-instructions',
|
|
102
|
+
},
|
|
103
|
+
{
|
|
104
|
+
id: 'gemini',
|
|
105
|
+
name: 'Gemini CLI',
|
|
106
|
+
kind: 'append',
|
|
107
|
+
dest: 'GEMINI.md',
|
|
108
|
+
marker: 'GEMINI.md',
|
|
109
|
+
doc: 'https://github.com/google-gemini/gemini-cli',
|
|
110
|
+
},
|
|
111
|
+
{
|
|
112
|
+
id: 'windsurf',
|
|
113
|
+
name: 'Windsurf',
|
|
114
|
+
kind: 'own',
|
|
115
|
+
dest: '.windsurf/rules/clado.md',
|
|
116
|
+
marker: '.windsurf',
|
|
117
|
+
doc: 'https://docs.windsurf.com/windsurf/cascade/memories',
|
|
118
|
+
},
|
|
119
|
+
{
|
|
120
|
+
id: 'cline',
|
|
121
|
+
name: 'Cline',
|
|
122
|
+
kind: 'own',
|
|
123
|
+
dest: '.clinerules/clado.md',
|
|
124
|
+
marker: '.clinerules',
|
|
125
|
+
doc: 'https://docs.cline.bot/customization/cline-rules',
|
|
126
|
+
},
|
|
127
|
+
{
|
|
128
|
+
id: 'codebuddy',
|
|
129
|
+
name: 'CodeBuddy(腾讯)',
|
|
130
|
+
kind: 'own',
|
|
131
|
+
dest: '.codebuddy/rules/clado.mdc',
|
|
132
|
+
marker: '.codebuddy',
|
|
133
|
+
doc: 'https://cloud.tencent.cn/document/product/1831/137462',
|
|
134
|
+
},
|
|
135
|
+
];
|
|
136
|
+
|
|
137
|
+
/** 按 id 找一条;找不到给 null(调用方负责报错,别在这儿抛) */
|
|
138
|
+
export function findTarget(id) {
|
|
139
|
+
return TARGETS.find((t) => t.id === id) || null;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* 规则文件里的正文。
|
|
144
|
+
*
|
|
145
|
+
* ★ 只写「指针」不抄正文:SKILL.md 有 33 KB,塞进 AGENTS.md 会把每次对话的
|
|
146
|
+
* 上下文都撑爆,而且升级之后两边就对不上了。指过去,让工具按需去读。
|
|
147
|
+
*
|
|
148
|
+
* @param {string} skillPath bundle 在本项目里的相对路径(正斜杠)
|
|
149
|
+
*/
|
|
150
|
+
export function ruleBody(skillPath) {
|
|
151
|
+
return `# clado —— 拿 Markdown 画图
|
|
152
|
+
|
|
153
|
+
这个项目用 [clado](https://www.npmjs.com/package/cladogram) 把一份 Markdown 编译成一个**自包含**的网页:
|
|
154
|
+
同一份 \`.md\` 能长成 **文档 / 卡片 / 脑图** 三种模式,双击就能离线打开。
|
|
155
|
+
|
|
156
|
+
要写或改这类文档之前,**先把这份技能完整读一遍**(它是这个工具的全部用法):
|
|
157
|
+
|
|
158
|
+
${skillPath}/SKILL.md
|
|
159
|
+
|
|
160
|
+
里面写了:标题怎么当卡片、层级怎么嵌套、**边怎么画**(正文里写一个 \`[目标](目标)\` 就够,
|
|
161
|
+
目标对不上就当普通链接、不报错)、表格 / 代码块 / Mermaid 怎么摆、八种诊断码各是什么意思。
|
|
162
|
+
|
|
163
|
+
跑起来:
|
|
164
|
+
|
|
165
|
+
npm install -g cladogram
|
|
166
|
+
clado build 你的文档.md --mode=cards
|
|
167
|
+
`;
|
|
168
|
+
}
|