@manturhub/cli 0.1.0 → 0.1.2

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 CHANGED
@@ -17,7 +17,7 @@ npm install -g @manturhub/cli
17
17
  ## 上手三步
18
18
 
19
19
  ```bash
20
- # 1. 配 Key(去 https://manturhub.leisurecat.cloud/dashboard 拿)
20
+ # 1. 配 Key(去 https://hub.mantur.cn/dashboard 拿)
21
21
  manturhub login --key sk-你的key
22
22
 
23
23
  # 2. 验证(列出全部上线算子)
@@ -65,4 +65,4 @@ args = ["mcp", "--scope", "drama"] # 只暴露剧本域算子
65
65
  `manturhub mcp` 不重新实现 MCP server,而是把客户端的 stdio JSON-RPC 消息转发到 ManturHub 已标准化的 Streamable HTTP MCP 端点(`/api/v1/mcp/<域>/mcp`),再把响应写回 stdout。工具发现、调用、计费全部在服务端完成,CLI 只做可靠的 stdio↔HTTP 桥接 —— 等于一个官方、可控的 mcp-remote。
66
66
 
67
67
  ---
68
- ManturHub 算子广场 · https://manturhub.leisurecat.cloud
68
+ ManturHub 算子广场 · https://hub.mantur.cn
package/bin/cli.js CHANGED
@@ -2,8 +2,14 @@
2
2
  import { saveConfig, loadConfig } from "../lib/config.js";
3
3
  import { apiFetch } from "../lib/api.js";
4
4
  import { runMcpBridge } from "../lib/mcp.js";
5
-
6
- const VERSION = "0.1.0";
5
+ import { runInit, runMcpInstall } from "../lib/setup.js";
6
+ import { readFileSync } from "node:fs";
7
+ import { fileURLToPath } from "node:url";
8
+ import { dirname, join } from "node:path";
9
+
10
+ const VERSION = JSON.parse(
11
+ readFileSync(join(dirname(fileURLToPath(import.meta.url)), "../package.json"), "utf8")
12
+ ).version;
7
13
  const args = process.argv.slice(2);
8
14
  const cmd = args[0];
9
15
 
@@ -21,20 +27,25 @@ const HELP = `manturhub — ManturHub 算子广场 CLI v${VERSION}
21
27
  manturhub ls [--cat <分类>] 列出上线算子(分类: text/image/video/audio/data)
22
28
  manturhub run <算子ID> --json '{}' 调用算子(也可用 --字段 值 形式)
23
29
  manturhub balance 查询馒头余额
30
+ manturhub init 往项目写 agent 引导(CLAUDE.md/AGENTS.md/.cursorrules)
31
+ manturhub mcp-install [--client x] 一键把 MCP 接进客户端(claude-code/codex/cursor/claude-desktop/all)
24
32
  manturhub help | --version
25
33
 
26
34
  环境变量:
27
35
  MANTURHUB_KEY API Key(优先于配置文件)
28
- MANTURHUB_BASE 网关地址(默认 https://manturhub.leisurecat.cloud
36
+ MANTURHUB_BASE 网关地址(默认 https://hub.mantur.cn
37
+
38
+ 让 agent 自动用算子(推荐,无需让 agent 学命令):
39
+ manturhub mcp-install --client all 一键把 MCP 接进 Claude Code / Codex / Cursor / Claude Desktop
40
+ manturhub init 或让 agent 在 shell 里直接用 CLI(写引导到项目)
29
41
 
30
- 把算子接进你的 AI(stdio,所有客户端都稳):
42
+ 手动接 MCP(stdio,所有客户端都稳;Key 由 manturhub login 自动读取):
31
43
  Codex ~/.codex/config.toml:
32
44
  [mcp_servers.manturhub]
33
45
  command = "manturhub"
34
46
  args = ["mcp"]
35
- env = { MANTURHUB_KEY = "sk-xxx" }
36
47
 
37
- Claude Desktop / Cursor:
48
+ Claude Code .mcp.json / Cursor / Claude Desktop:
38
49
  { "mcpServers": { "manturhub": { "command": "manturhub", "args": ["mcp"] } } }
39
50
  `;
40
51
 
@@ -67,6 +78,16 @@ async function main() {
67
78
  break;
68
79
  }
69
80
 
81
+ case "init": {
82
+ runInit();
83
+ break;
84
+ }
85
+
86
+ case "mcp-install": {
87
+ runMcpInstall(getFlag("client"));
88
+ break;
89
+ }
90
+
70
91
  case "ls": {
71
92
  const cat = getFlag("cat");
72
93
  const r = await apiFetch("/api/v1/operators?status=online");
@@ -80,7 +101,7 @@ async function main() {
80
101
  for (const o of ops) {
81
102
  console.log(` ${o.id.padEnd(26)} ${o.name} [${o.cat}]`);
82
103
  }
83
- console.log(`\n用 \`manturhub run <算子ID> --json '{...}'\` 调用,参数见 ${"https://manturhub.leisurecat.cloud"}/marketplace/<算子ID>`);
104
+ console.log(`\n用 \`manturhub run <算子ID> --json '{...}'\` 调用,参数见 ${"https://hub.mantur.cn"}/marketplace/<算子ID>`);
84
105
  break;
85
106
  }
86
107
 
package/lib/config.js CHANGED
@@ -11,7 +11,7 @@ import {
11
11
  // Local config lives at ~/.manturhub/config.json (chmod 600). Env vars win over it.
12
12
  const DIR = join(homedir(), ".manturhub");
13
13
  const FILE = join(DIR, "config.json");
14
- const DEFAULT_BASE = "https://manturhub.leisurecat.cloud";
14
+ const DEFAULT_BASE = "https://hub.mantur.cn";
15
15
 
16
16
  export function loadConfig() {
17
17
  try {
package/lib/setup.js ADDED
@@ -0,0 +1,130 @@
1
+ import { readFileSync, writeFileSync, mkdirSync, existsSync } from "node:fs";
2
+ import { homedir } from "node:os";
3
+ import { join, dirname } from "node:path";
4
+ import { getKey } from "./config.js";
5
+
6
+ const HUB = "https://hub.mantur.cn";
7
+
8
+ // ───────────────────────── manturhub init ─────────────────────────
9
+ // 往项目写一段 agent 引导,让 Claude Code / Codex / Cursor 知道用 manturhub CLI。
10
+ const MARK_START = "<!-- manturhub:start -->";
11
+ const MARK_END = "<!-- manturhub:end -->";
12
+
13
+ function guideBlock() {
14
+ return `${MARK_START}
15
+ ## ManturHub 算子(AI 能力,命令行直调)
16
+
17
+ 本机已安装 \`manturhub\` CLI,可调用 ManturHub 算子广场的 AI 能力(文生图 / 视频生成 / 语音合成 / 视频理解 / 短剧 / 文案等)。**当任务需要这类 AI 能力时,优先用它,不要自己造轮子。**
18
+
19
+ - 列出可用算子:\`manturhub ls\`(按类:\`manturhub ls --cat image|video|audio|text|data\`)
20
+ - 调用算子:\`manturhub run <算子ID> --json '{...入参...}'\`
21
+ - 查余额:\`manturhub balance\`
22
+ - 每个算子的入参字段见 ${HUB}/marketplace/<算子ID>
23
+
24
+ 注意:视频 / 图像等**异步算子**返回 jobId,需按算子文档轮询取结果;这类场景更建议用 MCP(见 \`manturhub mcp-install\`,工具更完整、含任务状态查询)。
25
+ ${MARK_END}`;
26
+ }
27
+
28
+ function escapeRe(s) {
29
+ return s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
30
+ }
31
+
32
+ function upsertGuide(file) {
33
+ const block = guideBlock();
34
+ let content = existsSync(file) ? readFileSync(file, "utf8") : "";
35
+ const re = new RegExp(escapeRe(MARK_START) + "[\\s\\S]*?" + escapeRe(MARK_END));
36
+ if (re.test(content)) {
37
+ content = content.replace(re, block); // 幂等:替换旧块,不重复追加
38
+ } else {
39
+ content = content.trimEnd();
40
+ content = content ? content + "\n\n" + block + "\n" : block + "\n";
41
+ }
42
+ writeFileSync(file, content);
43
+ }
44
+
45
+ export function runInit() {
46
+ const targets = ["AGENTS.md", "CLAUDE.md", ".cursorrules"];
47
+ console.log("写入 agent 引导(幂等,可重复运行):");
48
+ for (const t of targets) {
49
+ upsertGuide(join(process.cwd(), t));
50
+ console.log(` ✓ ${t}`);
51
+ }
52
+ console.log(
53
+ `\nClaude Code 读 CLAUDE.md,Codex 读 AGENTS.md,Cursor 读 .cursorrules。` +
54
+ `\nagent 下次会话即可知道用 manturhub 调算子。`
55
+ );
56
+ if (!getKey()) console.log(`\n⚠ 还没配 Key,先跑:manturhub login --key sk-xxx`);
57
+ }
58
+
59
+ // ──────────────────────── manturhub mcp-install ────────────────────────
60
+ // 把 manturhub MCP server 写进各 AI 客户端配置(自动合并,不覆盖已有其他 server)。
61
+ // Key 由 manturhub login 存的 ~/.manturhub/config.json 自动读取,无需写进各配置。
62
+ const SERVER_DEF = { command: "manturhub", args: ["mcp"] };
63
+
64
+ function writeJsonMcp(file, label) {
65
+ mkdirSync(dirname(file), { recursive: true });
66
+ let cfg = {};
67
+ if (existsSync(file)) {
68
+ try {
69
+ cfg = JSON.parse(readFileSync(file, "utf8"));
70
+ } catch {
71
+ console.log(` ⚠ ${label}: 现有文件不是合法 JSON,跳过 → ${file}`);
72
+ return;
73
+ }
74
+ }
75
+ cfg.mcpServers = cfg.mcpServers || {};
76
+ cfg.mcpServers.manturhub = { ...SERVER_DEF };
77
+ writeFileSync(file, JSON.stringify(cfg, null, 2) + "\n");
78
+ console.log(` ✓ ${label}: ${file}`);
79
+ }
80
+
81
+ function writeTomlCodex(file, label) {
82
+ mkdirSync(dirname(file), { recursive: true });
83
+ let content = existsSync(file) ? readFileSync(file, "utf8") : "";
84
+ if (/\[mcp_servers\.manturhub\]/.test(content)) {
85
+ console.log(` ✓ ${label}: 已存在 manturhub,未改动 → ${file}`);
86
+ return;
87
+ }
88
+ const section = `\n[mcp_servers.manturhub]\ncommand = "manturhub"\nargs = ["mcp"]\n`;
89
+ content = (content.trimEnd() + "\n" + section).replace(/^\n+/, "");
90
+ writeFileSync(file, content);
91
+ console.log(` ✓ ${label}: ${file}`);
92
+ }
93
+
94
+ const CLIENTS = {
95
+ "claude-code": () =>
96
+ writeJsonMcp(join(process.cwd(), ".mcp.json"), "Claude Code (项目 .mcp.json)"),
97
+ "claude-desktop": () =>
98
+ writeJsonMcp(
99
+ join(homedir(), "Library/Application Support/Claude/claude_desktop_config.json"),
100
+ "Claude Desktop"
101
+ ),
102
+ cursor: () => writeJsonMcp(join(homedir(), ".cursor/mcp.json"), "Cursor"),
103
+ codex: () => writeTomlCodex(join(homedir(), ".codex/config.toml"), "Codex"),
104
+ };
105
+
106
+ export function runMcpInstall(client) {
107
+ if (!client) {
108
+ console.log(`把 ManturHub MCP 接进 AI 客户端(agent 自动发现算子工具,无需学命令)。\n`);
109
+ console.log(`一键写入(自动合并,不动你已有的其他 MCP server):`);
110
+ console.log(` manturhub mcp-install --client claude-code # 项目 .mcp.json`);
111
+ console.log(` manturhub mcp-install --client codex # ~/.codex/config.toml`);
112
+ console.log(` manturhub mcp-install --client cursor # ~/.cursor/mcp.json`);
113
+ console.log(` manturhub mcp-install --client claude-desktop # Claude Desktop`);
114
+ console.log(` manturhub mcp-install --client all # 全部`);
115
+ console.log(`\nKey 由 \`manturhub login\` 的配置自动读取,无需写进各客户端配置。`);
116
+ return;
117
+ }
118
+ const names = client === "all" ? Object.keys(CLIENTS) : [client];
119
+ console.log("写入 MCP 配置:");
120
+ for (const n of names) {
121
+ const fn = CLIENTS[n];
122
+ if (!fn) {
123
+ console.log(` 未知客户端: ${n}(可选: ${Object.keys(CLIENTS).join(", ")}, all)`);
124
+ continue;
125
+ }
126
+ fn();
127
+ }
128
+ console.log(`\n完成。重启对应客户端即可看到 manturhub 的算子工具。`);
129
+ if (!getKey()) console.log(`⚠ 还没配 Key,MCP 启动会报错。先跑:manturhub login --key sk-xxx`);
130
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@manturhub/cli",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "description": "ManturHub 算子广场 CLI:命令行直调 AI 算子 + 给 Claude Code / Codex / Cursor 等当 stdio MCP server",
5
5
  "type": "module",
6
6
  "bin": {
@@ -24,5 +24,5 @@
24
24
  "stdio"
25
25
  ],
26
26
  "license": "MIT",
27
- "homepage": "https://manturhub.leisurecat.cloud"
27
+ "homepage": "https://hub.mantur.cn"
28
28
  }