@manturhub/cli 0.4.0 → 0.5.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/bin/cli.js +14 -0
- package/lib/skill-install.js +96 -0
- package/package.json +2 -2
package/bin/cli.js
CHANGED
|
@@ -3,6 +3,7 @@ import { saveConfig, loadConfig } from "../lib/config.js";
|
|
|
3
3
|
import { apiFetch, pollJob } from "../lib/api.js";
|
|
4
4
|
import { runMcpBridge } from "../lib/mcp.js";
|
|
5
5
|
import { runInit, runMcpInstall } from "../lib/setup.js";
|
|
6
|
+
import { skillLs, skillAdd } from "../lib/skill-install.js";
|
|
6
7
|
import { maybeNotifyUpdate } from "../lib/update-check.js";
|
|
7
8
|
import { readFileSync } from "node:fs";
|
|
8
9
|
import { fileURLToPath } from "node:url";
|
|
@@ -43,6 +44,8 @@ const HELP = `manturhub — ManturHub 算子广场 CLI v${VERSION}
|
|
|
43
44
|
manturhub status <poll_url> 查异步任务状态(配合 run --no-wait)
|
|
44
45
|
manturhub balance 查询馒头余额
|
|
45
46
|
manturhub init 装「ManturHub 使用 skill」+ 写 agent 引导(推荐:让 agent 会用算子)
|
|
47
|
+
manturhub skill ls 列出平台 Skill(业务成品流程,如爆款复刻)
|
|
48
|
+
manturhub skill add <slug> 安装 Skill 到 ~/.claude/skills/<slug>/
|
|
46
49
|
manturhub mcp [--scope <域>] 启动 stdio MCP server(可选,给 MCP 原生客户端)
|
|
47
50
|
manturhub mcp-install [--client x] 把 MCP 接进客户端(可选:claude-code/codex/cursor/claude-desktop/all)
|
|
48
51
|
manturhub help | --version
|
|
@@ -258,6 +261,17 @@ async function main() {
|
|
|
258
261
|
break;
|
|
259
262
|
}
|
|
260
263
|
|
|
264
|
+
case "skill": {
|
|
265
|
+
const sub = args[1];
|
|
266
|
+
if (sub === "ls" || sub === "list") await skillLs();
|
|
267
|
+
else if (sub === "add" || sub === "install") await skillAdd(args[2]);
|
|
268
|
+
else {
|
|
269
|
+
console.error("用法: manturhub skill ls | manturhub skill add <slug>");
|
|
270
|
+
process.exit(1);
|
|
271
|
+
}
|
|
272
|
+
break;
|
|
273
|
+
}
|
|
274
|
+
|
|
261
275
|
case "--version":
|
|
262
276
|
case "-v":
|
|
263
277
|
console.log(VERSION);
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { homedir, tmpdir } from "node:os";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import { mkdirSync, writeFileSync, rmSync } from "node:fs";
|
|
4
|
+
import { execFileSync } from "node:child_process";
|
|
5
|
+
import { getKey, getBaseUrl } from "./config.js";
|
|
6
|
+
|
|
7
|
+
// `manturhub skill ls` — 列出平台上线 Skill(公开元数据,无需 key)。
|
|
8
|
+
export async function skillLs() {
|
|
9
|
+
let res;
|
|
10
|
+
try {
|
|
11
|
+
res = await fetch(getBaseUrl() + "/api/v1/skills");
|
|
12
|
+
} catch (e) {
|
|
13
|
+
console.error(`Skill 列表获取失败: ${e.message}`);
|
|
14
|
+
process.exit(1);
|
|
15
|
+
}
|
|
16
|
+
if (!res.ok) {
|
|
17
|
+
console.error(`Skill 列表获取失败(HTTP ${res.status})`);
|
|
18
|
+
process.exit(1);
|
|
19
|
+
}
|
|
20
|
+
const data = await res.json();
|
|
21
|
+
const skills = data.skills || data || [];
|
|
22
|
+
console.log(`ManturHub 上线 Skill(${skills.length} 个):\n`);
|
|
23
|
+
for (const s of skills) {
|
|
24
|
+
const slug = String(s.slug || "").padEnd(22);
|
|
25
|
+
const cat = s.category ? `[${s.category}]` : "";
|
|
26
|
+
const ver = s.version ? `v${s.version}` : "";
|
|
27
|
+
console.log(` ${slug} ${s.name || ""} ${cat} ${ver}`.trimEnd());
|
|
28
|
+
}
|
|
29
|
+
console.log(`\n用 \`manturhub skill add <slug>\` 安装到 ~/.claude/skills/,重启 Claude Code 后 /<slug> 触发。`);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// `manturhub skill add <slug>` — 下载安装包并解压到 ~/.claude/skills/<slug>/。
|
|
33
|
+
export async function skillAdd(slug) {
|
|
34
|
+
if (!slug) {
|
|
35
|
+
console.error("用法: manturhub skill add <slug> (先 `manturhub skill ls` 看可用 Skill)");
|
|
36
|
+
process.exit(1);
|
|
37
|
+
}
|
|
38
|
+
const key = getKey();
|
|
39
|
+
if (!key) {
|
|
40
|
+
console.error("下载 Skill 需 API Key。运行 `manturhub login --key sk-xxx`,或设置环境变量 MANTURHUB_KEY。");
|
|
41
|
+
process.exit(1);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const url = `${getBaseUrl()}/api/v1/skills/${encodeURIComponent(slug)}/download`;
|
|
45
|
+
// 手动处理 302:服务端返回预签名下载地址,跟随时不把 API Key 带去对象存储。
|
|
46
|
+
let res;
|
|
47
|
+
try {
|
|
48
|
+
res = await fetch(url, { headers: { "x-api-key": key }, redirect: "manual" });
|
|
49
|
+
} catch (e) {
|
|
50
|
+
console.error(`下载失败: ${e.message}`);
|
|
51
|
+
process.exit(1);
|
|
52
|
+
}
|
|
53
|
+
if (res.status === 401) {
|
|
54
|
+
console.error("API Key 无效或未授权(401)。");
|
|
55
|
+
process.exit(1);
|
|
56
|
+
}
|
|
57
|
+
if (res.status === 404) {
|
|
58
|
+
console.error(`Skill 不存在: ${slug}(用 \`manturhub skill ls\` 看可用列表)`);
|
|
59
|
+
process.exit(1);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
let zipBuf;
|
|
63
|
+
if (res.status >= 300 && res.status < 400) {
|
|
64
|
+
const loc = res.headers.get("location");
|
|
65
|
+
if (!loc) {
|
|
66
|
+
console.error("下载重定向缺少 Location 头");
|
|
67
|
+
process.exit(1);
|
|
68
|
+
}
|
|
69
|
+
const zres = await fetch(loc);
|
|
70
|
+
if (!zres.ok) {
|
|
71
|
+
console.error(`安装包下载失败(HTTP ${zres.status})`);
|
|
72
|
+
process.exit(1);
|
|
73
|
+
}
|
|
74
|
+
zipBuf = Buffer.from(await zres.arrayBuffer());
|
|
75
|
+
} else if (res.ok) {
|
|
76
|
+
zipBuf = Buffer.from(await res.arrayBuffer());
|
|
77
|
+
} else {
|
|
78
|
+
console.error(`下载失败(HTTP ${res.status})`);
|
|
79
|
+
process.exit(1);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const dest = join(homedir(), ".claude", "skills", slug);
|
|
83
|
+
mkdirSync(dest, { recursive: true });
|
|
84
|
+
const tmp = join(tmpdir(), `manturhub-skill-${slug}-${process.pid}.zip`);
|
|
85
|
+
writeFileSync(tmp, zipBuf);
|
|
86
|
+
try {
|
|
87
|
+
execFileSync("unzip", ["-o", "-q", tmp, "-d", dest], { stdio: ["ignore", "ignore", "inherit"] });
|
|
88
|
+
} catch {
|
|
89
|
+
console.error(`解压失败(需系统 unzip 命令)。安装包已存到: ${tmp}`);
|
|
90
|
+
console.error(`可手动解压: unzip -o "${tmp}" -d "${dest}"`);
|
|
91
|
+
process.exit(1);
|
|
92
|
+
}
|
|
93
|
+
rmSync(tmp, { force: true });
|
|
94
|
+
console.log(`✓ 已安装 Skill「${slug}」→ ${dest}`);
|
|
95
|
+
console.log(` 重启 Claude Code 后,用 /${slug} <描述> 触发。`);
|
|
96
|
+
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@manturhub/cli",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "ManturHub 算子广场 CLI:命令行直调 AI 算子 + 给 Claude Code / Codex / Cursor 等当 stdio MCP server",
|
|
3
|
+
"version": "0.5.0",
|
|
4
|
+
"description": "ManturHub 算子广场 CLI:命令行直调 AI 算子 + 安装平台 Skill + 给 Claude Code / Codex / Cursor 等当 stdio MCP server",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
7
7
|
"manturhub": "./bin/cli.js"
|