@ganhaiapp/cli 0.0.1 → 0.2.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/README.md +60 -5
- package/bin/ganhai.js +72 -5
- package/package.json +10 -3
package/README.md
CHANGED
|
@@ -1,9 +1,64 @@
|
|
|
1
1
|
# @ganhaiapp/cli
|
|
2
2
|
|
|
3
|
-
赶海 GanHai 命令行工具 ——
|
|
3
|
+
赶海 GanHai 命令行工具 —— 开放 API 客户端 + MCP 服务(0.2.0)。
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
## 安装
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
```bash
|
|
8
|
+
npm install -g @ganhaiapp/cli # 主通道(自动安装当前平台分包)
|
|
9
|
+
npx @ganhaiapp/cli <命令> # 免安装直接用
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
## MCP 接入(AI 客户端)
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
ganhai mcp install # 自动检测 Claude Desktop / Cursor / VS Code 并写入配置
|
|
16
|
+
ganhai mcp serve # 或手动在客户端配置:{"mcpServers":{"ganhai":{"command":"ganhai","args":["mcp","serve"]}}}
|
|
17
|
+
ganhai mcp status # 查看配置状态
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
tools 按 API Key 的 scope 动态裁剪——无权限的动作模型连名字都看不到。
|
|
21
|
+
新增服务端端点后 MCP tools 自动获得(元数据驱动,客户端零更新)。
|
|
22
|
+
|
|
23
|
+
主包不含二进制;平台二进制(win32/linux × x64/arm64、darwin × x64/arm64)经
|
|
24
|
+
optionalDependencies 平台分包提供,npm 按 os/cpu 自动择包。
|
|
25
|
+
|
|
26
|
+
## 快速开始
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
ganhai auth login --server https://app.example.com
|
|
30
|
+
# → 浏览器打开 /connect?code=XXXX-XXXX 确认授权(Key 不经对话/剪贴板)
|
|
31
|
+
|
|
32
|
+
ganhai shops list # 店铺
|
|
33
|
+
ganhai orders list # 订单
|
|
34
|
+
ganhai orders profit <订单号> # 利润明细
|
|
35
|
+
ganhai inventory list # 库存
|
|
36
|
+
ganhai finance summary # 财务汇总
|
|
37
|
+
ganhai docs # 当前 Key 可见的端点清单
|
|
38
|
+
ganhai schema show GET /api/v1/open/erp/orders # 端点参数/scope 内省
|
|
39
|
+
ganhai whoami # 验证登录(org/scope/可用动作数)
|
|
40
|
+
ganhai skill show agent-setup # Agent 接入手册(教学包)
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## Agent 友好(脚本/智能体场景)
|
|
44
|
+
|
|
45
|
+
- **双渲染**:TTY 输出表格;管道/`--format json`/`GANHAI_FORMAT=json` 输出原样 JSON
|
|
46
|
+
- **stdout 只出数据**,进度/告警走 stderr
|
|
47
|
+
- **退出码**:0 成功 / 2 参数 / 3 认证 / 4 权限 / 5 限流 / 6 服务端 / 7 未订阅
|
|
48
|
+
- **多组织**:`--profile <name>` 或 `GANHAI_PROFILE`(`~/.ganhai/profiles/<name>.json`,0600)
|
|
49
|
+
- 错误消息含 next-command hint(防幻觉:错误后直接给出下一步命令)
|
|
50
|
+
|
|
51
|
+
## 环境变量
|
|
52
|
+
|
|
53
|
+
| 变量 | 说明 |
|
|
54
|
+
|---|---|
|
|
55
|
+
| `GANHAI_SERVER` | auth login 默认服务端地址 |
|
|
56
|
+
| `GANHAI_PROFILE` | 默认 profile 名 |
|
|
57
|
+
| `GANHAI_FORMAT` | `json` 强制 JSON 输出 |
|
|
58
|
+
| `GANHAI_HOME` | 配置根目录(默认 `~/.ganhai`,测试用) |
|
|
59
|
+
| `GANHAI_BIN` | 直接指定二进制路径(bin 垫片调试用) |
|
|
60
|
+
|
|
61
|
+
## 维护者
|
|
62
|
+
|
|
63
|
+
平台分包构建与发布:`cd packages/cli-platforms && node pack.mjs <build|verify|publish>`
|
|
64
|
+
(先发 5 个平台包,再发主包;Go 源码在仓库 `cli/` 目录)。
|
package/bin/ganhai.js
CHANGED
|
@@ -1,6 +1,73 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
//
|
|
3
|
-
//
|
|
4
|
-
//
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
// ganhai — @ganhaiapp/cli 主包 bin 垫片(93-P2,npm 平台分包模式)
|
|
3
|
+
//
|
|
4
|
+
// 主包不含二进制;平台二进制经 optionalDependencies 按平台分包提供:
|
|
5
|
+
// @ganhaiapp/cli-win32-x64 / cli-linux-x64 / cli-darwin-x64 / cli-darwin-arm64
|
|
6
|
+
// npm 安装时按 os/cpu 自动择包(装错平台包会被 os/cpu 字段挡下)。
|
|
7
|
+
//
|
|
8
|
+
// 解析顺序:
|
|
9
|
+
// 1. GANHAI_BIN 环境变量 → 直接用该路径(本地开发/覆盖)
|
|
10
|
+
// 2. require.resolve 平台包内的二进制 → spawn 透传
|
|
11
|
+
// 3. 找不到 → 明确报错(含 npx/安装诊断提示)
|
|
12
|
+
//
|
|
13
|
+
// 纪律:垫片不解析参数、不翻译输出——纯 exec 透传(退出码原样返回)。
|
|
14
|
+
|
|
15
|
+
'use strict'
|
|
16
|
+
|
|
17
|
+
const { spawn } = require('child_process')
|
|
18
|
+
const path = require('path')
|
|
19
|
+
|
|
20
|
+
const PLATFORM_PACKAGES = {
|
|
21
|
+
'win32-x64': '@ganhaiapp/cli-win32-x64',
|
|
22
|
+
'linux-x64': '@ganhaiapp/cli-linux-x64',
|
|
23
|
+
'linux-arm64': '@ganhaiapp/cli-linux-arm64',
|
|
24
|
+
'darwin-x64': '@ganhaiapp/cli-darwin-x64',
|
|
25
|
+
'darwin-arm64': '@ganhaiapp/cli-darwin-arm64',
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function binaryName() {
|
|
29
|
+
return process.platform === 'win32' ? 'ganhai.exe' : 'ganhai'
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function resolveBinary() {
|
|
33
|
+
// 1. 环境变量显式覆盖(开发态:GANHAI_BIN=../../cli/ganhai.exe ganhai ...)。
|
|
34
|
+
if (process.env.GANHAI_BIN) {
|
|
35
|
+
return process.env.GANHAI_BIN
|
|
36
|
+
}
|
|
37
|
+
// 2. 平台分包。
|
|
38
|
+
const pkg = PLATFORM_PACKAGES[`${process.platform}-${process.arch}`]
|
|
39
|
+
if (pkg) {
|
|
40
|
+
try {
|
|
41
|
+
// 平台包 files 只含 bin/,package.json main 指向二进制本身。
|
|
42
|
+
return require.resolve(path.join(pkg, 'bin', binaryName()))
|
|
43
|
+
} catch {
|
|
44
|
+
// optionalDependencies 缺失(npm 老版本/镜像裁剪)→ 落到报错路径。
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return null
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function main() {
|
|
51
|
+
const bin = resolveBinary()
|
|
52
|
+
if (!bin) {
|
|
53
|
+
console.error('未找到当前平台的 ganhai 二进制。')
|
|
54
|
+
console.error(` platform: ${process.platform}-${process.arch}`)
|
|
55
|
+
console.error('请尝试:npm install -g @ganhaiapp/cli(会自动安装对应平台分包)')
|
|
56
|
+
console.error('或用环境变量 GANHAI_BIN 指定二进制路径。')
|
|
57
|
+
process.exit(127)
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const child = spawn(bin, process.argv.slice(2), {
|
|
61
|
+
stdio: 'inherit',
|
|
62
|
+
windowsHide: true,
|
|
63
|
+
})
|
|
64
|
+
child.on('error', (err) => {
|
|
65
|
+
console.error('启动 ganhai 失败:', err.message)
|
|
66
|
+
process.exit(127)
|
|
67
|
+
})
|
|
68
|
+
child.on('close', (code) => {
|
|
69
|
+
process.exit(code === null ? 130 : code)
|
|
70
|
+
})
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
main()
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ganhaiapp/cli",
|
|
3
|
-
"version": "0.0
|
|
4
|
-
"description": "赶海 GanHai CLI
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "赶海 GanHai CLI —— 开放 API 命令行客户端(设备码登录 / 只读命令 / MCP stdio 服务 / skill 教学包)",
|
|
5
5
|
"bin": {
|
|
6
6
|
"ganhai": "bin/ganhai.js"
|
|
7
7
|
},
|
|
@@ -15,5 +15,12 @@
|
|
|
15
15
|
"engines": {
|
|
16
16
|
"node": ">=18"
|
|
17
17
|
},
|
|
18
|
-
"license": "UNLICENSED"
|
|
18
|
+
"license": "UNLICENSED",
|
|
19
|
+
"optionalDependencies": {
|
|
20
|
+
"@ganhaiapp/cli-win32-x64": "0.2.0",
|
|
21
|
+
"@ganhaiapp/cli-linux-x64": "0.2.0",
|
|
22
|
+
"@ganhaiapp/cli-linux-arm64": "0.2.0",
|
|
23
|
+
"@ganhaiapp/cli-darwin-x64": "0.2.0",
|
|
24
|
+
"@ganhaiapp/cli-darwin-arm64": "0.2.0"
|
|
25
|
+
}
|
|
19
26
|
}
|