funcoding-cli 0.2.0 → 0.3.0

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/dist/setup.js DELETED
@@ -1,49 +0,0 @@
1
- /**
2
- * setup:把随 CLI 发布的 funcoding Skill(skill/funcoding/SKILL.md)装到智能体,让它知道什么时候、怎么用这个 CLI。
3
- * 这个 Skill 不在网站目录里,来源记录标成 builtin,update 时从当前版本的 CLI 重新复制。
4
- */
5
- import { randomBytes } from 'node:crypto';
6
- import { mkdir, readFile, rename, rm, stat, writeFile } from 'node:fs/promises';
7
- import { dirname, join } from 'node:path';
8
- import { AGENTS, skillsRoot } from './agents.js';
9
- import { USER_AGENT } from './api.js';
10
- import { META_FILE, moveAway } from './install.js';
11
- import { cyan, dim, done, fail, green, info } from './ui.js';
12
- export const BUILTIN_ID = 'funcoding';
13
- const SOURCE = new URL('../skill/funcoding/SKILL.md', import.meta.url);
14
- export const builtinContent = () => readFile(SOURCE, 'utf8');
15
- export async function installBuiltin(targets, force) {
16
- const content = await builtinContent();
17
- const dirs = targets.map((t) => ({ ...t, dir: join(skillsRoot(t.agent, t.scope), BUILTIN_ID) }));
18
- const foreign = [];
19
- for (const d of dirs) {
20
- const meta = await readFile(join(d.dir, META_FILE), 'utf8').catch(() => null);
21
- const present = meta !== null || (await stat(d.dir).then(() => true, () => false));
22
- // 之前 setup 装的直接换成新版;同名的其他 Skill 要 --force,并且先备份
23
- if (present && !(meta && JSON.parse(meta).builtin))
24
- foreign.push(d);
25
- }
26
- if (foreign.length > 0 && !force)
27
- fail('exists', `${foreign.map((d) => d.dir).join('、')} 已存在,且不是 funcoding setup 安装的。`, '确认要覆盖就加 --force(会先备份到配置目录)');
28
- for (const d of dirs) {
29
- const tmp = join(dirname(d.dir), `.funcoding-tmp-${randomBytes(4).toString('hex')}`);
30
- await mkdir(tmp, { recursive: true });
31
- await writeFile(join(tmp, 'SKILL.md'), content);
32
- await writeFile(join(tmp, META_FILE), `${JSON.stringify({ id: BUILTIN_ID, name: BUILTIN_ID, builtin: true, installedAt: new Date().toISOString(), cli: USER_AGENT }, null, 2)}\n`);
33
- if (foreign.includes(d))
34
- await moveAway(d.dir, d.agent, BUILTIN_ID);
35
- else
36
- await rm(d.dir, { recursive: true, force: true });
37
- await rename(tmp, d.dir);
38
- }
39
- return dirs;
40
- }
41
- export async function setup(targets, force) {
42
- const dirs = await installBuiltin(targets, force);
43
- done({ installed: dirs.map((d) => ({ id: BUILTIN_ID, agent: d.agent, scope: d.scope, dir: d.dir })) }, () => {
44
- for (const d of dirs)
45
- info(green(`✓ 已把 funcoding Skill 装到 ${d.dir}`));
46
- info(`之后可以直接让 ${dirs.map((d) => AGENTS[d.agent].label).join('、')} 帮你查找和安装 Skill、配置 MCP,例如「找一个处理 PDF 的 Skill 装上」。`);
47
- info(dim(`也可以输入 ${[...new Set(dirs.map((d) => cyan(AGENTS[d.agent].invoke(BUILTIN_ID))))].join(' / ')} 主动调用。新开会话后生效。`));
48
- });
49
- }