@worm-print-platform/skills 0.0.0-stage → 1.6.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 +101 -2
- package/dist/chunk-BKRZHVC3.js +156 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +116 -0
- package/dist/index.d.ts +79 -0
- package/dist/index.js +22 -0
- package/package.json +48 -4
package/README.md
CHANGED
|
@@ -1,3 +1,102 @@
|
|
|
1
|
-
|
|
1
|
+
<p align="center">
|
|
2
|
+
<strong>@worm-print-platform/skills</strong><br>
|
|
3
|
+
<em>官方技能安装器(CLI + npm 包)</em>
|
|
4
|
+
</p>
|
|
2
5
|
|
|
3
|
-
|
|
6
|
+
<p align="center">
|
|
7
|
+
<img src="https://img.shields.io/badge/npm-v1.6.1-384BFF" alt="npm">
|
|
8
|
+
<img src="https://img.shields.io/badge/node-%E2%89%A518-4B9B4B" alt="node">
|
|
9
|
+
<img src="https://img.shields.io/badge/license-MIT-9A9A9A" alt="license">
|
|
10
|
+
</p>
|
|
11
|
+
|
|
12
|
+
> monorepo 根:[worm-print-platform](https://github.com/worm-longliu/worm-print-platform) · 仓库内技能源码:[`skills/`](../../skills/)
|
|
13
|
+
|
|
14
|
+
`worm-print-platform` 官方技能安装器。从 GitHub / Gitee 仓库把技能安装到本地项目,让 AI Agent 在开始动手前先读规范、按既定方式接入。
|
|
15
|
+
|
|
16
|
+
**bin 命令**:`worm-print-skills`(npx 调用 `npx @worm-print-platform/skills` 即可)
|
|
17
|
+
|
|
18
|
+
## 安装
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
# 方式一:npx 调用(推荐)
|
|
22
|
+
npx @worm-print-platform/skills <技能名>
|
|
23
|
+
|
|
24
|
+
# 方式二:全局安装(常用)
|
|
25
|
+
npm i -g @worm-print-platform/skills
|
|
26
|
+
worm-print-skills <技能名>
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## 用法
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
npx @worm-print-platform/skills <技能名> [选项]
|
|
33
|
+
|
|
34
|
+
选项:
|
|
35
|
+
--repo <地址> 仓库地址(GitHub / Gitee 均可,缺省时默认双源:
|
|
36
|
+
github.com/worm-longliu/worm-print-platform →
|
|
37
|
+
gitee.com/liulong_oschina/worm-print-platform,
|
|
38
|
+
先 GitHub,失败自动回退 Gitee。支持 owner/repo 简写)
|
|
39
|
+
--dir <目录> 技能根目录,技能装到 <目录>/<技能名>/。默认 .agents/skills
|
|
40
|
+
--force 目标技能目录已存在时覆盖(默认拒绝并报错)
|
|
41
|
+
-h, --help 显示帮助
|
|
42
|
+
-v, --version 显示版本
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
### 示例
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
# 安装宿主集成规范(默认装到 .agents/skills/worm-print-platform-integration/)
|
|
49
|
+
npx @worm-print-platform/skills worm-print-platform-integration
|
|
50
|
+
|
|
51
|
+
# 安装桌面 MCP 工具到 qoder 项目级目录
|
|
52
|
+
npx @worm-print-platform/skills worm-print-platform-mcp --dir .qoder/skills
|
|
53
|
+
|
|
54
|
+
# 指定仓库地址
|
|
55
|
+
npx @worm-print-platform/skills worm-print-platform-integration \
|
|
56
|
+
--repo https://gitee.com/liulong_oschina/worm-print-platform.git
|
|
57
|
+
|
|
58
|
+
# 覆盖已有技能
|
|
59
|
+
npx @worm-print-platform/skills worm-print-platform-integration --force
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
### 退出码(便于脚本与 AI Agent 判定失败类型)
|
|
63
|
+
|
|
64
|
+
| 码 | 含义 |
|
|
65
|
+
| --- | --- |
|
|
66
|
+
| 0 | 成功 |
|
|
67
|
+
| 2 | 参数错误 |
|
|
68
|
+
| 3 | 目标目录已存在(需 `--force`) |
|
|
69
|
+
| 4 | 技能名在仓库中未找到 |
|
|
70
|
+
| 5 | 仓库操作失败(clone / sparse checkout 出错) |
|
|
71
|
+
| 6 | 系统缺少 `git` |
|
|
72
|
+
|
|
73
|
+
## 仓库内已维护的技能
|
|
74
|
+
|
|
75
|
+
| 技能 | 覆盖范围 |
|
|
76
|
+
| --- | --- |
|
|
77
|
+
| `worm-print-platform-integration` | 全形态宿主集成:NPM 宿主的 `canvas/vue3` 门面与 `<print-designer>` 契约、浏览器直挂 / Vue 2 / React / jQuery、三条打印链路、AI 集成提示词、故障排查 |
|
|
78
|
+
| `worm-print-platform-i18n` | 自定义语言包:骨架生成、校验、人工审核对照表、浏览器/render/client 三端接入与排错 |
|
|
79
|
+
| `worm-print-platform-mcp` | 桌面 MCP 工具:模板会话、渲染预览、视觉回读与参考图比对 |
|
|
80
|
+
|
|
81
|
+
技能源码随本仓库分发(`skills/<技能名>/` 目录),安装器会 sparse-checkout 整个目录。
|
|
82
|
+
|
|
83
|
+
## 手动取用(离线回退)
|
|
84
|
+
|
|
85
|
+
无 npm / git 环境时,从 [GitHub](https://github.com/worm-longliu/worm-print-platform) 或 [Gitee](https://gitee.com/liulong_oschina/worm-print-platform) 仓库的 `skills/<技能名>/` 目录手动下载,放到 AI 编程工具的技能目录(`.agents/skills/` / `.qoder/skills/` / `.claude/skills/` 等)并重载。
|
|
86
|
+
|
|
87
|
+
## 开发
|
|
88
|
+
|
|
89
|
+
```bash
|
|
90
|
+
npm run build # tsup → dist/
|
|
91
|
+
npm run typecheck # tsc --noEmit(pretest)
|
|
92
|
+
npm test # vitest
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
## 相关链接
|
|
96
|
+
|
|
97
|
+
- [根 README AI Agent 配套技能章节](https://github.com/worm-longliu/worm-print-platform/blob/main/README.md#ai-agent-配套技能)
|
|
98
|
+
- [docs/README.md 技能安装方法](../../docs/README.md#技能安装方法提示词第-0-步的通用说明)
|
|
99
|
+
|
|
100
|
+
## License
|
|
101
|
+
|
|
102
|
+
[MIT](../../LICENSE)
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
// src/types.ts
|
|
2
|
+
var SkillError = class extends Error {
|
|
3
|
+
constructor(code, message) {
|
|
4
|
+
super(message);
|
|
5
|
+
this.code = code;
|
|
6
|
+
this.name = "SkillError";
|
|
7
|
+
}
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
// src/repo.ts
|
|
11
|
+
var DEFAULT_GITHUB_REPO = "https://github.com/worm-longliu/worm-print-platform.git";
|
|
12
|
+
var DEFAULT_GITEE_REPO = "https://gitee.com/liulong_oschina/worm-print-platform.git";
|
|
13
|
+
function classifyHost(hostName) {
|
|
14
|
+
const host = hostName.toLowerCase();
|
|
15
|
+
if (host.includes("github")) return "github";
|
|
16
|
+
if (host.includes("gitee")) return "gitee";
|
|
17
|
+
return "other";
|
|
18
|
+
}
|
|
19
|
+
function extractHostName(url) {
|
|
20
|
+
const match = url.match(/^(?:[a-z][a-z0-9+.-]*:\/\/)?(?:[^@/]+@)?([^/:]+)[/:]/i);
|
|
21
|
+
return match ? match[1] : null;
|
|
22
|
+
}
|
|
23
|
+
function parseRepoUrl(raw) {
|
|
24
|
+
const trimmed = raw.trim();
|
|
25
|
+
if (!trimmed) throw new SkillError("BAD_REPO", "\u4ED3\u5E93\u5730\u5740\u4E0D\u80FD\u4E3A\u7A7A");
|
|
26
|
+
let url = trimmed;
|
|
27
|
+
if (/^[A-Za-z0-9._-]+\/[A-Za-z0-9._-]+$/.test(url)) {
|
|
28
|
+
url = `https://github.com/${url}.git`;
|
|
29
|
+
}
|
|
30
|
+
if (!/^(https?:\/\/|ssh:\/\/|git:\/\/|git@)/i.test(url)) {
|
|
31
|
+
throw new SkillError(
|
|
32
|
+
"BAD_REPO",
|
|
33
|
+
`\u4E0D\u652F\u6301\u7684\u4ED3\u5E93\u5730\u5740\uFF1A${raw}\u3002\u652F\u6301 https/ssh/git \u5730\u5740\u6216 owner/repo \u7B80\u5199`
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
if (/[\s\r\n]/.test(url)) {
|
|
37
|
+
throw new SkillError("BAD_REPO", `\u4ED3\u5E93\u5730\u5740\u4E0D\u80FD\u5305\u542B\u7A7A\u767D\u5B57\u7B26\uFF1A${raw}`);
|
|
38
|
+
}
|
|
39
|
+
const hostName = extractHostName(url);
|
|
40
|
+
if (!hostName) throw new SkillError("BAD_REPO", `\u65E0\u6CD5\u89E3\u6790\u4ED3\u5E93\u4E3B\u673A\u540D\uFF1A${raw}`);
|
|
41
|
+
return { url, raw: trimmed, host: classifyHost(hostName), hostName };
|
|
42
|
+
}
|
|
43
|
+
function resolveSources(repo) {
|
|
44
|
+
if (repo !== void 0 && repo.trim() !== "") return [parseRepoUrl(repo)];
|
|
45
|
+
return [parseRepoUrl(DEFAULT_GITHUB_REPO), parseRepoUrl(DEFAULT_GITEE_REPO)];
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// src/install.ts
|
|
49
|
+
import { execFile } from "child_process";
|
|
50
|
+
import { cpSync, existsSync, mkdirSync, mkdtempSync, rmSync } from "fs";
|
|
51
|
+
import { tmpdir } from "os";
|
|
52
|
+
import { isAbsolute, join, resolve } from "path";
|
|
53
|
+
import { promisify } from "util";
|
|
54
|
+
var execFileAsync = promisify(execFile);
|
|
55
|
+
var defaultGitExecutor = async (args, cwd) => {
|
|
56
|
+
let result;
|
|
57
|
+
try {
|
|
58
|
+
result = await execFileAsync("git", args, {
|
|
59
|
+
cwd,
|
|
60
|
+
encoding: "utf8",
|
|
61
|
+
windowsHide: true,
|
|
62
|
+
timeout: 12e4,
|
|
63
|
+
maxBuffer: 4 * 1024 * 1024,
|
|
64
|
+
env: { ...process.env, GIT_TERMINAL_PROMPT: "0" }
|
|
65
|
+
});
|
|
66
|
+
} catch (error) {
|
|
67
|
+
const err = error;
|
|
68
|
+
if (err.code === "ENOENT") {
|
|
69
|
+
throw new SkillError("GIT_MISSING", "\u672A\u627E\u5230 git \u547D\u4EE4\uFF0C\u8BF7\u5148\u5B89\u88C5 Git \u5E76\u52A0\u5165 PATH\u3002");
|
|
70
|
+
}
|
|
71
|
+
const detail = (err.stderr || err.message || String(error)).trim();
|
|
72
|
+
throw new SkillError("CLONE_FAILED", `git ${args[0]} \u5931\u8D25\uFF1A${detail}`);
|
|
73
|
+
}
|
|
74
|
+
return { stdout: String(result.stdout), stderr: String(result.stderr) };
|
|
75
|
+
};
|
|
76
|
+
function validateSkillName(input) {
|
|
77
|
+
const name = input.trim();
|
|
78
|
+
if (!name || !/^[A-Za-z0-9][A-Za-z0-9._-]*$/.test(name) || name === ".." || name === ".") {
|
|
79
|
+
throw new SkillError("BAD_SKILL_NAME", `\u975E\u6CD5\u6280\u80FD\u540D\uFF1A${input}\uFF08\u4EC5\u5141\u8BB8\u5B57\u6BCD\u6570\u5B57\u5F00\u5934\uFF0C\u53EF\u542B . _ -\uFF09`);
|
|
80
|
+
}
|
|
81
|
+
return name;
|
|
82
|
+
}
|
|
83
|
+
function resolveSkillTarget(skill, dir, cwd) {
|
|
84
|
+
const root = cwd ? resolve(cwd) : process.cwd();
|
|
85
|
+
const dirInput = dir && dir.trim() ? dir.trim() : ".agents/skills";
|
|
86
|
+
const baseDir = isAbsolute(dirInput) ? resolve(dirInput) : resolve(root, dirInput);
|
|
87
|
+
return { target: join(baseDir, skill), baseDir };
|
|
88
|
+
}
|
|
89
|
+
async function fetchSkillFromRepo(source, skill, executor) {
|
|
90
|
+
const tmpRoot = mkdtempSync(join(tmpdir(), "worm-print-skills-"));
|
|
91
|
+
try {
|
|
92
|
+
await executor(["clone", "--depth", "1", "--filter=blob:none", "--sparse", source.url, tmpRoot]);
|
|
93
|
+
await executor(["sparse-checkout", "set", `skills/${skill}`], tmpRoot);
|
|
94
|
+
const skillDir = join(tmpRoot, "skills", skill);
|
|
95
|
+
if (!existsSync(join(skillDir, "SKILL.md"))) {
|
|
96
|
+
throw new SkillError(
|
|
97
|
+
"NOT_FOUND",
|
|
98
|
+
`\u4ED3\u5E93 ${source.raw} \u4E2D\u4E0D\u5B58\u5728\u6280\u80FD\u300C${skill}\u300D\uFF08\u7F3A\u5C11 skills/${skill}/SKILL.md\uFF09`
|
|
99
|
+
);
|
|
100
|
+
}
|
|
101
|
+
return { skillDir, tmpRoot };
|
|
102
|
+
} catch (error) {
|
|
103
|
+
rmSync(tmpRoot, { recursive: true, force: true });
|
|
104
|
+
throw error;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
async function installSkill(skillInput, options = {}) {
|
|
108
|
+
const skill = validateSkillName(skillInput);
|
|
109
|
+
const executor = options.executor ?? defaultGitExecutor;
|
|
110
|
+
const sources = resolveSources(options.repo);
|
|
111
|
+
const { target, baseDir } = resolveSkillTarget(skill, options.dir, options.cwd);
|
|
112
|
+
if (existsSync(target) && options.force !== true) {
|
|
113
|
+
throw new SkillError(
|
|
114
|
+
"ALREADY_EXISTS",
|
|
115
|
+
`\u6280\u80FD\u76EE\u5F55\u5DF2\u5B58\u5728\uFF1A${target}
|
|
116
|
+
\u5982\u786E\u8BA4\u8986\u76D6\uFF0C\u8BF7\u52A0 --force \u91CD\u8BD5\u3002`
|
|
117
|
+
);
|
|
118
|
+
}
|
|
119
|
+
const created = !existsSync(target);
|
|
120
|
+
const failures = [];
|
|
121
|
+
for (const source of sources) {
|
|
122
|
+
let fetched;
|
|
123
|
+
try {
|
|
124
|
+
fetched = await fetchSkillFromRepo(source, skill, executor);
|
|
125
|
+
mkdirSync(baseDir, { recursive: true });
|
|
126
|
+
if (!created) rmSync(target, { recursive: true, force: true });
|
|
127
|
+
cpSync(fetched.skillDir, target, { recursive: true, errorOnExist: false, force: true });
|
|
128
|
+
return { skill, target, source, created };
|
|
129
|
+
} catch (error) {
|
|
130
|
+
if (error instanceof SkillError && (error.code === "NOT_FOUND" || error.code === "GIT_MISSING")) {
|
|
131
|
+
throw error;
|
|
132
|
+
}
|
|
133
|
+
const detail = error instanceof Error ? error.message : String(error);
|
|
134
|
+
failures.push(`${source.raw}\uFF1A${detail}`);
|
|
135
|
+
} finally {
|
|
136
|
+
if (fetched) rmSync(fetched.tmpRoot, { recursive: true, force: true });
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
throw new SkillError(
|
|
140
|
+
"CLONE_FAILED",
|
|
141
|
+
`\u6280\u80FD\u300C${skill}\u300D\u4ECE\u4EE5\u4E0B\u4ED3\u5E93\u5B89\u88C5\u5747\u5931\u8D25\uFF1A
|
|
142
|
+
- ${failures.join("\n- ")}`
|
|
143
|
+
);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
export {
|
|
147
|
+
SkillError,
|
|
148
|
+
DEFAULT_GITHUB_REPO,
|
|
149
|
+
DEFAULT_GITEE_REPO,
|
|
150
|
+
parseRepoUrl,
|
|
151
|
+
resolveSources,
|
|
152
|
+
defaultGitExecutor,
|
|
153
|
+
validateSkillName,
|
|
154
|
+
resolveSkillTarget,
|
|
155
|
+
installSkill
|
|
156
|
+
};
|
package/dist/cli.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
package/dist/cli.js
ADDED
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import {
|
|
3
|
+
DEFAULT_GITEE_REPO,
|
|
4
|
+
DEFAULT_GITHUB_REPO,
|
|
5
|
+
SkillError,
|
|
6
|
+
installSkill
|
|
7
|
+
} from "./chunk-BKRZHVC3.js";
|
|
8
|
+
|
|
9
|
+
// src/cli.ts
|
|
10
|
+
var USAGE = `\u7528\u6CD5: npx @worm-print-platform/skills <\u6280\u80FD\u540D> [\u9009\u9879]
|
|
11
|
+
|
|
12
|
+
\u4ECE GitHub / Gitee \u4ED3\u5E93\u628A\u5B98\u65B9\u6280\u80FD\u5B89\u88C5\u5230\u5F53\u524D\u9879\u76EE\uFF08\u9ED8\u8BA4 .agents/skills/<\u6280\u80FD\u540D>/\uFF09\u3002
|
|
13
|
+
|
|
14
|
+
\u53C2\u6570:
|
|
15
|
+
<\u6280\u80FD\u540D> \u5FC5\u586B\uFF0C\u5355\u4E2A\u6280\u80FD\u540D\uFF0C\u5982 worm-print-platform-mcp
|
|
16
|
+
|
|
17
|
+
\u9009\u9879:
|
|
18
|
+
--repo <\u5730\u5740> \u4ED3\u5E93\u5730\u5740\uFF08GitHub/Gitee \u5747\u53EF\uFF09\uFF0C\u7F3A\u7701\u65F6\u7528\u9ED8\u8BA4\u53CC\u6E90\uFF1A
|
|
19
|
+
${DEFAULT_GITHUB_REPO}
|
|
20
|
+
${DEFAULT_GITEE_REPO}
|
|
21
|
+
\u5148 GitHub\uFF0C\u5931\u8D25\u81EA\u52A8\u56DE\u9000 Gitee\u3002\u4E5F\u652F\u6301 owner/repo \u7B80\u5199\u3002
|
|
22
|
+
--dir <\u76EE\u5F55> \u6280\u80FD\u6839\u76EE\u5F55\uFF0C\u6280\u80FD\u88C5\u5230 <\u76EE\u5F55>/<\u6280\u80FD\u540D>/\u3002\u9ED8\u8BA4 .agents/skills
|
|
23
|
+
--force \u76EE\u6807\u6280\u80FD\u76EE\u5F55\u5DF2\u5B58\u5728\u65F6\u8986\u76D6\uFF08\u9ED8\u8BA4\u62D2\u7EDD\u8986\u76D6\u5E76\u62A5\u9519\uFF09
|
|
24
|
+
-h, --help \u663E\u793A\u5E2E\u52A9
|
|
25
|
+
-v, --version \u663E\u793A\u7248\u672C
|
|
26
|
+
|
|
27
|
+
\u793A\u4F8B:
|
|
28
|
+
npx @worm-print-platform/skills worm-print-platform-mcp
|
|
29
|
+
npx @worm-print-platform/skills worm-print-platform-integration --dir .qoder/skills
|
|
30
|
+
npx @worm-print-platform/skills worm-print-platform-mcp --repo https://gitee.com/liulong_oschina/worm-print-platform.git
|
|
31
|
+
|
|
32
|
+
\u9000\u51FA\u7801: 0 \u6210\u529F \xB7 2 \u53C2\u6570\u9519\u8BEF \xB7 3 \u76EE\u6807\u5DF2\u5B58\u5728 \xB7 4 \u672A\u627E\u5230\u6280\u80FD \xB7 5 \u4ED3\u5E93\u64CD\u4F5C\u5931\u8D25 \xB7 6 \u7F3A\u5C11 git`;
|
|
33
|
+
var EXIT_CODE = {
|
|
34
|
+
BAD_ARGUMENT: 2,
|
|
35
|
+
BAD_SKILL_NAME: 2,
|
|
36
|
+
BAD_REPO: 2,
|
|
37
|
+
ALREADY_EXISTS: 3,
|
|
38
|
+
NOT_FOUND: 4,
|
|
39
|
+
CLONE_FAILED: 5,
|
|
40
|
+
GIT_MISSING: 6
|
|
41
|
+
};
|
|
42
|
+
function parseArgs(argv) {
|
|
43
|
+
const parsed = {
|
|
44
|
+
skill: void 0,
|
|
45
|
+
repo: void 0,
|
|
46
|
+
dir: void 0,
|
|
47
|
+
force: false,
|
|
48
|
+
help: false,
|
|
49
|
+
version: false
|
|
50
|
+
};
|
|
51
|
+
for (let i = 0; i < argv.length; i++) {
|
|
52
|
+
const arg = argv[i];
|
|
53
|
+
switch (arg) {
|
|
54
|
+
case "-h":
|
|
55
|
+
case "--help":
|
|
56
|
+
parsed.help = true;
|
|
57
|
+
break;
|
|
58
|
+
case "-v":
|
|
59
|
+
case "--version":
|
|
60
|
+
parsed.version = true;
|
|
61
|
+
break;
|
|
62
|
+
case "--force":
|
|
63
|
+
parsed.force = true;
|
|
64
|
+
break;
|
|
65
|
+
case "--repo":
|
|
66
|
+
case "--dir": {
|
|
67
|
+
const value = argv[++i];
|
|
68
|
+
if (value === void 0 || value.startsWith("--")) {
|
|
69
|
+
throw new SkillError("BAD_ARGUMENT", `${arg} \u9700\u8981\u4E00\u4E2A\u503C`);
|
|
70
|
+
}
|
|
71
|
+
if (arg === "--repo") parsed.repo = value;
|
|
72
|
+
else parsed.dir = value;
|
|
73
|
+
break;
|
|
74
|
+
}
|
|
75
|
+
default:
|
|
76
|
+
if (arg.startsWith("-")) {
|
|
77
|
+
throw new SkillError("BAD_ARGUMENT", `\u672A\u77E5\u9009\u9879\uFF1A${arg}`);
|
|
78
|
+
}
|
|
79
|
+
if (parsed.skill !== void 0) {
|
|
80
|
+
throw new SkillError("BAD_ARGUMENT", `\u53EA\u63A5\u53D7\u4E00\u4E2A\u6280\u80FD\u540D\uFF0C\u591A\u4F59\u53C2\u6570\uFF1A${arg}`);
|
|
81
|
+
}
|
|
82
|
+
parsed.skill = arg;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
return parsed;
|
|
86
|
+
}
|
|
87
|
+
var VERSION = "1.5.0";
|
|
88
|
+
async function main() {
|
|
89
|
+
const args = parseArgs(process.argv.slice(2));
|
|
90
|
+
if (args.help) {
|
|
91
|
+
console.log(USAGE);
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
if (args.version) {
|
|
95
|
+
console.log(`@worm-print-platform/skills ${VERSION}`);
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
if (!args.skill) {
|
|
99
|
+
console.error(USAGE);
|
|
100
|
+
throw new SkillError("BAD_ARGUMENT", "\u7F3A\u5C11\u6280\u80FD\u540D");
|
|
101
|
+
}
|
|
102
|
+
const result = await installSkill(args.skill, {
|
|
103
|
+
repo: args.repo,
|
|
104
|
+
dir: args.dir,
|
|
105
|
+
force: args.force
|
|
106
|
+
});
|
|
107
|
+
console.log(`\u5DF2\u5B89\u88C5\u6280\u80FD\u300C${result.skill}\u300D\u2192 ${result.target}`);
|
|
108
|
+
console.log(`\u6765\u6E90\uFF1A${result.source.url}`);
|
|
109
|
+
if (!result.created) console.log("\u63D0\u793A\uFF1A\u5DF2\u8986\u76D6\u539F\u6709\u6280\u80FD\u76EE\u5F55\u3002");
|
|
110
|
+
}
|
|
111
|
+
main().catch((error) => {
|
|
112
|
+
const code = error instanceof SkillError ? EXIT_CODE[error.code] : 1;
|
|
113
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
114
|
+
console.error(`\u5B89\u88C5\u5931\u8D25\uFF1A${message}`);
|
|
115
|
+
process.exitCode = code;
|
|
116
|
+
});
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/** 仓库源所属托管平台,仅用于错误提示与归类,不影响 git 克隆方式。 */
|
|
2
|
+
type HostKind = 'github' | 'gitee' | 'other';
|
|
3
|
+
/** 规范化后的仓库源。 */
|
|
4
|
+
interface RepoSource {
|
|
5
|
+
/** 传给 git clone 的地址。 */
|
|
6
|
+
url: string;
|
|
7
|
+
/** 用户原始输入,用于提示。 */
|
|
8
|
+
raw: string;
|
|
9
|
+
host: HostKind;
|
|
10
|
+
hostName: string;
|
|
11
|
+
}
|
|
12
|
+
/** git 子进程输出。 */
|
|
13
|
+
interface GitResult {
|
|
14
|
+
stdout: string;
|
|
15
|
+
stderr: string;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* git 执行器。抽成可注入接口,使安装流程可在测试中不依赖真实 git 与网络。
|
|
19
|
+
* args 以数组传入 execFile,不经 shell,杜绝命令注入。
|
|
20
|
+
*/
|
|
21
|
+
type GitExecutor = (args: string[], cwd?: string) => Promise<GitResult>;
|
|
22
|
+
interface InstallOptions {
|
|
23
|
+
/** 显式仓库地址;缺省时用默认 GitHub → Gitee 双源。 */
|
|
24
|
+
repo?: string;
|
|
25
|
+
/** 技能根目录,技能装到 <dir>/<skill>/。默认 .agents/skills。 */
|
|
26
|
+
dir?: string;
|
|
27
|
+
/** 目标已存在时是否覆盖。默认 false。 */
|
|
28
|
+
force?: boolean;
|
|
29
|
+
/** 相对 dir 的解析基准,默认 process.cwd()。 */
|
|
30
|
+
cwd?: string;
|
|
31
|
+
/** 自定义 git 执行器,测试用。 */
|
|
32
|
+
executor?: GitExecutor;
|
|
33
|
+
}
|
|
34
|
+
interface InstallResult {
|
|
35
|
+
skill: string;
|
|
36
|
+
/** 技能最终落地目录的绝对路径。 */
|
|
37
|
+
target: string;
|
|
38
|
+
source: RepoSource;
|
|
39
|
+
/** true 表示新建,false 表示覆盖已有目录。 */
|
|
40
|
+
created: boolean;
|
|
41
|
+
}
|
|
42
|
+
type SkillErrorCode = 'BAD_ARGUMENT' | 'BAD_SKILL_NAME' | 'BAD_REPO' | 'NOT_FOUND' | 'ALREADY_EXISTS' | 'CLONE_FAILED' | 'GIT_MISSING';
|
|
43
|
+
/** 带稳定错误码的领域错误,CLI 据此映射退出码。 */
|
|
44
|
+
declare class SkillError extends Error {
|
|
45
|
+
readonly code: SkillErrorCode;
|
|
46
|
+
constructor(code: SkillErrorCode, message: string);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** 真实 git 执行器:参数数组不经 shell,杜绝命令注入。 */
|
|
50
|
+
declare const defaultGitExecutor: GitExecutor;
|
|
51
|
+
/** 技能名白名单:字母/数字开头,仅含字母数字、点、下划线、连字符。防路径穿越。 */
|
|
52
|
+
declare function validateSkillName(input: string): string;
|
|
53
|
+
/** 解析技能落地目录:<dir>/<skill>,dir 相对 cwd。 */
|
|
54
|
+
declare function resolveSkillTarget(skill: string, dir: string | undefined, cwd: string | undefined): {
|
|
55
|
+
target: string;
|
|
56
|
+
baseDir: string;
|
|
57
|
+
};
|
|
58
|
+
/**
|
|
59
|
+
* 安装技能。默认按 GitHub → Gitee 顺序尝试,任一源成功即落地;
|
|
60
|
+
* 全部失败时聚合各源错误抛出。
|
|
61
|
+
*/
|
|
62
|
+
declare function installSkill(skillInput: string, options?: InstallOptions): Promise<InstallResult>;
|
|
63
|
+
|
|
64
|
+
/** 默认主源:GitHub。 */
|
|
65
|
+
declare const DEFAULT_GITHUB_REPO = "https://github.com/worm-longliu/worm-print-platform.git";
|
|
66
|
+
/** 默认备用源:Gitee 镜像。 */
|
|
67
|
+
declare const DEFAULT_GITEE_REPO = "https://gitee.com/liulong_oschina/worm-print-platform.git";
|
|
68
|
+
/**
|
|
69
|
+
* 解析并规范化仓库地址。
|
|
70
|
+
* 支持:https(s)://、ssh://、git://、git@host:path,以及 owner/repo 简写(按 GitHub 处理)。
|
|
71
|
+
* 拒绝以 - 开头或含空白的地址,避免被 git 当作选项或产生歧义。
|
|
72
|
+
*/
|
|
73
|
+
declare function parseRepoUrl(raw: string): RepoSource;
|
|
74
|
+
/**
|
|
75
|
+
* 解析安装源列表。显式 --repo 时只用该源;否则默认 GitHub 优先、失败回退 Gitee。
|
|
76
|
+
*/
|
|
77
|
+
declare function resolveSources(repo?: string): RepoSource[];
|
|
78
|
+
|
|
79
|
+
export { DEFAULT_GITEE_REPO, DEFAULT_GITHUB_REPO, type GitExecutor, type GitResult, type HostKind, type InstallOptions, type InstallResult, type RepoSource, SkillError, type SkillErrorCode, defaultGitExecutor, installSkill, parseRepoUrl, resolveSkillTarget, resolveSources, validateSkillName };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import {
|
|
2
|
+
DEFAULT_GITEE_REPO,
|
|
3
|
+
DEFAULT_GITHUB_REPO,
|
|
4
|
+
SkillError,
|
|
5
|
+
defaultGitExecutor,
|
|
6
|
+
installSkill,
|
|
7
|
+
parseRepoUrl,
|
|
8
|
+
resolveSkillTarget,
|
|
9
|
+
resolveSources,
|
|
10
|
+
validateSkillName
|
|
11
|
+
} from "./chunk-BKRZHVC3.js";
|
|
12
|
+
export {
|
|
13
|
+
DEFAULT_GITEE_REPO,
|
|
14
|
+
DEFAULT_GITHUB_REPO,
|
|
15
|
+
SkillError,
|
|
16
|
+
defaultGitExecutor,
|
|
17
|
+
installSkill,
|
|
18
|
+
parseRepoUrl,
|
|
19
|
+
resolveSkillTarget,
|
|
20
|
+
resolveSources,
|
|
21
|
+
validateSkillName
|
|
22
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,50 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@worm-print-platform/skills",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
"version": "1.6.1",
|
|
4
|
+
"publishConfig": {
|
|
5
|
+
"access": "public",
|
|
6
|
+
"registry": "https://registry.npmjs.org"
|
|
7
|
+
},
|
|
8
|
+
"type": "module",
|
|
9
|
+
"description": "worm-print-platform 官方技能安装器:从 GitHub / Gitee 仓库把技能安装到本地项目的 .agents/skills/ 或指定目录。",
|
|
10
|
+
"license": "MIT",
|
|
11
|
+
"author": "worm <liu_long_qqcom@qq.com>",
|
|
12
|
+
"repository": {
|
|
13
|
+
"type": "git",
|
|
14
|
+
"url": "git+https://github.com/worm-longliu/worm-print-platform.git"
|
|
15
|
+
},
|
|
16
|
+
"keywords": [
|
|
17
|
+
"skills",
|
|
18
|
+
"cli",
|
|
19
|
+
"worm-print-platform"
|
|
20
|
+
],
|
|
21
|
+
"bin": {
|
|
22
|
+
"worm-print-skills": "./dist/cli.js"
|
|
23
|
+
},
|
|
24
|
+
"main": "./dist/index.js",
|
|
25
|
+
"types": "./dist/index.d.ts",
|
|
26
|
+
"exports": {
|
|
27
|
+
".": {
|
|
28
|
+
"types": "./dist/index.d.ts",
|
|
29
|
+
"import": "./dist/index.js"
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
"files": [
|
|
33
|
+
"dist"
|
|
34
|
+
],
|
|
35
|
+
"engines": {
|
|
36
|
+
"node": ">=18"
|
|
37
|
+
},
|
|
38
|
+
"scripts": {
|
|
39
|
+
"build": "tsup",
|
|
40
|
+
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
41
|
+
"pretest": "npm run typecheck",
|
|
42
|
+
"test": "vitest run"
|
|
43
|
+
},
|
|
44
|
+
"devDependencies": {
|
|
45
|
+
"@types/node": "^20.11.0",
|
|
46
|
+
"tsup": "^8.0.0",
|
|
47
|
+
"typescript": "~5.9.3",
|
|
48
|
+
"vitest": "^1.6.0"
|
|
49
|
+
}
|
|
50
|
+
}
|