@round2ai/r2-cli 1.0.11 → 1.0.12-beta.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.
@@ -0,0 +1,94 @@
1
+ ---
2
+ name: r2-shared
3
+ version: 1.0.0
4
+ description: "R2-CLI 共享基础技能。安装、统一错误格式、命令概览。r2-auth 和 r2-goods 的前置依赖。触发词:r2-cli、安装、install、错误格式。"
5
+ metadata:
6
+ requires:
7
+ bins: ["r2-cli"]
8
+ cliHelp: "r2-cli --help"
9
+ related:
10
+ - "r2-auth"
11
+ - "r2-goods"
12
+ ---
13
+
14
+ # R2-Shared (v1)
15
+
16
+ > **Tip**: 始终使用 `--json` 获取结构化输出。所有 `--json` 命令统一错误格式 `{ success: false, error: "..." }`,检查 `success` 判断成败。
17
+ > **Tip**: Agent 获取数据后展示给用户选择,不要让用户自己提供 ID。
18
+
19
+ 二手潮奢交易命令行工具,由 Round2AI 团队维护。覆盖商品上架、认证登录等核心业务域。
20
+
21
+ ## CRITICAL
22
+
23
+ 本 skill 是 r2-auth 和 r2-goods 的共享基础。认证登录详情见 **r2-auth** skill,商品管理详情见 **r2-goods** skill。
24
+
25
+ ## 安装
26
+
27
+ ```bash
28
+ npm install -g @round2ai/r2-cli@latest
29
+ ```
30
+
31
+ ## 前置条件
32
+
33
+ - 先登录:`r2-cli auth login`(支持第二回合 APP / 微信 / 支付宝扫码)
34
+ - 检查状态:`r2-cli auth status`
35
+
36
+ ## 认证命令(详见 r2-auth skill)
37
+
38
+ | 命令 | 说明 |
39
+ |------|------|
40
+ | `r2-cli auth login --json` | 扫码登录(Agent 推荐,一步完成) |
41
+ | `r2-cli auth xianyu --json` | 闲鱼店铺授权(Agent 推荐,一步完成) |
42
+ | `r2-cli auth status` | 查看登录状态 |
43
+ | `r2-cli auth logout` | 退出登录 |
44
+
45
+ ## 商品管理命令(详见 r2-goods skill)
46
+
47
+ | 分类 | 命令 | 说明 |
48
+ |------|------|------|
49
+ | 查询 | `r2-cli goods shops [--json]` | 查看已授权店铺 |
50
+ | | `r2-cli goods stocks [--json]` | 查看仓库 |
51
+ | | `r2-cli goods list [--stock-id <id>] [--json]` | 查看选品商品 |
52
+ | | `r2-cli goods listing [--json]` | 查询上架列表 |
53
+ | 上架 | `r2-cli goods up --stock-goods-id <> --shop-id <> --price <> --json` | 普通上架(选品商品) |
54
+ | | `r2-cli goods down --id <id> [--json]` | 下架商品 |
55
+ | | `r2-cli goods price --id <id> --price <amount> [--json]` | 修改价格 |
56
+ | 挂售 | `r2-cli goods hang-up categories [--json]` | 获取闲鱼类目 |
57
+ | | `r2-cli goods hang-up props --channel-cat-id <id> [--json]` | 获取属性列表 |
58
+ | | `r2-cli goods hang-up brands --channel-cat-id <> --prop-id <> --key <> [--json]` | 品牌搜索 |
59
+ | | `r2-cli goods hang-up upload-images --shop-id <> --files <> --json` | 上传图片 |
60
+ | | `r2-cli goods hang-up submit --shop-id <> --title <> ... --json` | 提交挂售上架 |
61
+
62
+ ## Agent 上架路由(概要)
63
+
64
+ 用户说"上架商品"时需要选择正确的方式:
65
+ - **商品在选品库** → `goods up`(店铺 → 仓库 → 选品商品 → 提交价格)
66
+ - **用户提供了图片** → `goods hang-up`(上传图片 → AI 读图识别 → 类目/属性 → 提交)
67
+ - **不确定** → 问用户
68
+
69
+ > 详细决策规则见 **r2-goods** skill「上架路由决策」章节。
70
+
71
+ ## Agent 上架 4 步流程(概要)
72
+
73
+ 1. `r2-cli goods shops --json` → 展示店铺 → 用户选择
74
+ 2. `r2-cli goods stocks --json` → 展示仓库 → 用户选择
75
+ 3. `r2-cli goods list --stock-id <id> --json` → 展示商品 → 用户选择
76
+ 4. `r2-cli goods up --stock-goods-id <id> --shop-id <id> --price <amount> --json` → 提交上架
77
+
78
+ > 完整参数说明、挂售流程、错误处理见 **r2-goods** skill。
79
+
80
+ ## 统一错误格式
81
+
82
+ 所有 `--json` 命令统一错误格式:
83
+
84
+ ```json
85
+ { "success": false, "error": "错误信息" }
86
+ ```
87
+
88
+ 常见错误:
89
+
90
+ | 错误信息 | 原因 | 解决方法 |
91
+ |----------|------|----------|
92
+ | `请先运行 r2-cli auth login 登录` | 未登录或 Token 过期 | 执行 `r2-cli auth login --json` |
93
+ | `二维码已过期` / `授权链接已过期` | 扫码超时(5 分钟) | 重新执行命令 |
94
+ | `轮询超时` | 上架结果查询超时 | 稍后用 `r2-cli goods listing` 查看 |
package/dist/package.json DELETED
@@ -1,61 +0,0 @@
1
- {
2
- "name": "@round2ai/r2-cli",
3
- "version": "1.0.10",
4
- "description": "R2-CLI,向 AI 开放二手潮奢交易全链路能力",
5
- "main": "dist/r2-cli.js",
6
- "type": "module",
7
- "bin": {
8
- "r2-cli": "./dist/r2-cli.js"
9
- },
10
- "scripts": {
11
- "postinstall": "node scripts/install-skills.js",
12
- "build": "cross-env NODE_ENV=development node scripts/build.js",
13
- "build:prod": "cross-env NODE_ENV=production node scripts/build.js",
14
- "dev": "node scripts/dev.js"
15
- },
16
- "keywords": [
17
- "round2ai",
18
- "r2",
19
- "r2-cli",
20
- "cli",
21
- "ai",
22
- "fashion",
23
- "luxury",
24
- "second-hand"
25
- ],
26
- "files": [
27
- "dist",
28
- "scripts",
29
- "skills",
30
- "package.json",
31
- "README.md"
32
- ],
33
- "author": "Round2AI - PURESNAKE Team",
34
- "license": "MIT",
35
- "engines": {
36
- "node": ">=18.0.0"
37
- },
38
- "repository": {
39
- "type": "git",
40
- "url": "https://github.com/Round2AI/r2-cli"
41
- },
42
- "dependencies": {
43
- "@inquirer/prompts": "^8.4.2",
44
- "chalk": "^5.3.0",
45
- "commander": "^14.0.3",
46
- "figlet": "^1.11.0",
47
- "ink": "^7.0.0",
48
- "ora": "^9.3.0",
49
- "qrcode": "^1.5.4",
50
- "react": "^19.2.5"
51
- },
52
- "devDependencies": {
53
- "@types/node": "^25.5.2",
54
- "@types/qrcode": "^1.5.6",
55
- "@types/react": "^19.2.14",
56
- "cross-env": "^10.1.0",
57
- "dotenv": "^17.4.2",
58
- "esbuild": "^0.28.0",
59
- "typescript": "^6.0.2"
60
- }
61
- }
package/scripts/build.js DELETED
@@ -1,176 +0,0 @@
1
- #!/usr/bin/env node
2
- /**
3
- * 构建脚本 - 使用 esbuild 打包
4
- */
5
-
6
- import esbuild from "esbuild";
7
- import fs from "node:fs/promises";
8
- import path from "path";
9
- import { fileURLToPath } from "url";
10
- import * as dotenv from "dotenv";
11
-
12
- const __filename = fileURLToPath(import.meta.url);
13
- const __dirname = path.dirname(__filename);
14
- const rootDir = path.dirname(__dirname);
15
-
16
- const nodeEnv = process.env.NODE_ENV || "development";
17
- const isProd = nodeEnv === "production";
18
- const envFile = isProd ? ".env.production" : ".env";
19
- dotenv.config({ path: path.join(rootDir, envFile) });
20
- const serverBaseUrl = process.env.SERVER_BASEURL || "https://api.qiuxietang.com";
21
-
22
- // 入口点配置
23
- const entryPoints = {
24
- "r2-cli": "src/entrypoints/r2-cli.tsx",
25
- };
26
-
27
- // esbuild 配置
28
- const esbuildConfig = {
29
- bundle: true,
30
- platform: "node",
31
- format: "esm",
32
- sourcemap: false,
33
- minify: isProd,
34
- external: [
35
- "commander",
36
- "chalk",
37
- "figlet",
38
- "@inquirer/prompts",
39
- "@inquirer/core",
40
- "@inquirer/input",
41
- "@inquirer/select",
42
- "@inquirer/confirm",
43
- "@inquirer/checkbox",
44
- "mute-stream",
45
- "qrcode",
46
- "ora",
47
- "react",
48
- "ink",
49
- "react-dom",
50
- "react-devtools-core",
51
- "uuid",
52
- ],
53
- banner: {
54
- js: '"use strict";',
55
- },
56
- define: {
57
- "process.env.NODE_ENV": JSON.stringify(nodeEnv),
58
- "process.env.SERVER_BASEURL": JSON.stringify(serverBaseUrl),
59
- },
60
- treeShaking: true,
61
- splitting: false,
62
- };
63
-
64
- /**
65
- * 清理输出目录
66
- */
67
- async function cleanDist() {
68
- const distDir = path.join(rootDir, "dist");
69
- try {
70
- await fs.rm(distDir, { recursive: true, force: true });
71
- } catch (e) {
72
- if (e.code === "EBUSY" || e.code === "EPERM") {
73
- const files = await fs.readdir(distDir);
74
- for (const file of files) {
75
- await fs.rm(path.join(distDir, file), { recursive: true, force: true });
76
- }
77
- } else {
78
- throw e;
79
- }
80
- }
81
- await fs.mkdir(distDir, { recursive: true });
82
- console.log("🧹 清理输出目录完成");
83
- }
84
-
85
- /**
86
- * 构建单个入口点
87
- */
88
- async function buildEntryPoint(name, entry) {
89
- const outputDir = path.join(rootDir, "dist");
90
- console.log(`🔨 构建 ${name} -> ${path.relative(rootDir, outputDir)}`);
91
-
92
- const config = { ...esbuildConfig };
93
- if (name === "r2-cli") {
94
- config.banner = {
95
- js: "#!/usr/bin/env node\n",
96
- };
97
- }
98
-
99
- try {
100
- await esbuild.build({
101
- ...config,
102
- entryPoints: [path.join(rootDir, entry)],
103
- outdir: outputDir,
104
- // 保持原始文件名,不加 outdir 的 hash 前缀
105
- // outdir 会自动生成文件名,不需要 outfile
106
- });
107
- console.log(`✅ ${name} 构建成功`);
108
- } catch (error) {
109
- console.error(`❌ ${name} 构建失败:`, error.message);
110
- throw error;
111
- }
112
- }
113
-
114
- /**
115
- * 复制必要文件
116
- */
117
- async function copyFiles() {
118
- const filesToCopy = ["package.json", "README.md"];
119
-
120
- for (const file of filesToCopy) {
121
- const src = path.join(rootDir, file);
122
- const dest = path.join(rootDir, "dist", file);
123
-
124
- try {
125
- await fs.copyFile(src, dest);
126
- console.log(`📄 已复制 ${file}`);
127
- } catch {
128
- // file doesn't exist, skip
129
- }
130
- }
131
-
132
- // 复制 QR 页面 HTML 文件到 dist/pages/
133
- const pagesDir = path.join(rootDir, "dist", "pages");
134
- await fs.mkdir(pagesDir, { recursive: true });
135
- const htmlSrcDir = path.join(rootDir, "src", "qr-server", "pages");
136
- const htmlFiles = await fs.readdir(htmlSrcDir);
137
- for (const file of htmlFiles) {
138
- if (file.endsWith(".html")) {
139
- await fs.copyFile(path.join(htmlSrcDir, file), path.join(pagesDir, file));
140
- console.log(`📄 已复制 pages/${file}`);
141
- }
142
- }
143
- }
144
-
145
- /**
146
- * 构建项目
147
- */
148
- async function build() {
149
- console.log("🚀 开始构建 R2-CLI...\n");
150
-
151
- try {
152
- // 1. 清理输出目录
153
- await cleanDist();
154
-
155
- // 2. 构建所有入口点
156
- console.log("🔨 开始构建入口点...\n");
157
- for (const [name, entry] of Object.entries(entryPoints)) {
158
- await buildEntryPoint(name, entry);
159
- }
160
-
161
- // 3. 复制必要文件
162
- await copyFiles();
163
-
164
- console.log("\n✅ 构建完成!");
165
- console.log("\n📦 输出文件:");
166
- Object.keys(entryPoints).forEach((name) => {
167
- console.log(` • dist/${name}.js`);
168
- });
169
- } catch (error) {
170
- console.error("❌ 构建失败:", error);
171
- process.exit(1);
172
- }
173
- }
174
-
175
- // 运行构建
176
- build();
package/scripts/dev.js DELETED
@@ -1,22 +0,0 @@
1
- #!/usr/bin/env node
2
- /**
3
- * 开发模式 - 直接运行源码
4
- */
5
-
6
- import { spawn } from 'child_process';
7
- import path from 'path';
8
- import { fileURLToPath } from 'url';
9
-
10
- const __filename = fileURLToPath(import.meta.url);
11
- const __dirname = path.dirname(__filename);
12
- const rootDir = path.dirname(__dirname);
13
-
14
- const child = spawn('npx', ['tsx', 'src/entrypoints/r2-cli.tsx', ...process.argv.slice(2)], {
15
- cwd: rootDir,
16
- stdio: 'inherit',
17
- shell: true,
18
- });
19
-
20
- child.on('exit', (code) => {
21
- process.exit(code ?? 1);
22
- });
@@ -1,70 +0,0 @@
1
- ---
2
- name: r2-cli
3
- description: R2-CLI 二手潮奢交易 CLI 工具。用于认证登录、商品上架/下架/改价、查看店铺/仓库/选品商品/上架列表。Agent 获取数据后展示给用户选择,完成 4 步上架流程。触发词:r2-cli、登录、上架、下架、改价、商品、goods、auth、shops、stocks、listing。
4
- ---
5
-
6
- # R2-CLI Skill
7
-
8
- 二手潮奢交易命令行工具,由 Round2AI 团队维护。覆盖商品上架、认证登录等核心业务域。
9
-
10
- ## 安装
11
-
12
- ```bash
13
- npm install -g @round2ai/r2-cli@latest
14
- ```
15
-
16
- ## 命令前缀自动检测
17
-
18
- 首次使用时检测一次,后续所有命令使用检测到的前缀:
19
-
20
- 1. 项目目录有 `package.json`(name 含 r2-cli)→ `npm run dev --`
21
- 2. 存在 `dist/r2-cli.js` → `node dist/r2-cli.js`
22
- 3. `r2-cli --version` 成功 → `r2-cli`
23
-
24
- > 部分平台 npm 会拦截 `--help` 等 flag,改用 `npx tsx src/entrypoints/r2-cli.tsx --help`。
25
-
26
- ## 前置条件
27
-
28
- - 先登录:`r2-cli auth login`(支持第二回合 APP / 微信 / 支付宝扫码)
29
- - 检查状态:`r2-cli auth status`
30
-
31
- 所有 `--json` 命令输出 `{ success: false, error: "..." }` 格式错误,检查 `success` 判断成败。
32
-
33
- ## 认证命令
34
-
35
- | 命令 | 说明 |
36
- |------|------|
37
- | `r2-cli auth login` | 扫码登录(自动打开浏览器,人类使用) |
38
- | `r2-cli auth login --json` | 扫码登录(自动打开浏览器 + JSON 输出,Agent 推荐) |
39
- | `r2-cli auth login poll --token <>` | 手动轮询登录状态(备选方案,不推荐) |
40
- | `r2-cli auth xianyu` | 闲鱼店铺授权(自动打开浏览器,人类使用) |
41
- | `r2-cli auth xianyu --json` | 闲鱼店铺授权(自动打开浏览器 + JSON 输出,Agent 推荐) |
42
- | `r2-cli auth xianyu poll --state <>` | 手动轮询授权状态(备选方案,不推荐) |
43
- | `r2-cli auth status` | 查看登录状态 |
44
- | `r2-cli auth logout` | 退出登录 |
45
-
46
- > 认证登录的详细 Agent 操作流程见 **r2-auth** skill。
47
-
48
- ## 商品管理命令
49
-
50
- | 命令 | 说明 |
51
- |------|------|
52
- | `r2-cli goods shops [--json]` | 查看所有已授权店铺(跨平台) |
53
- | `r2-cli goods stocks [--json]` | 查看所有仓库 |
54
- | `r2-cli goods list [--stock-id <id>] [--stock-goods-id <id>] [--json]` | 查看选品商品(两个过滤参数均为可选,支持 `--page` 和 `--size`) |
55
- | `r2-cli goods listing [--json]` | 查询上架列表(支持 `--id` / `--shop-id` / `--stock-goods-id` / `--stock-id` / `--status` / `--platform` 过滤) |
56
- | `r2-cli goods up` | 交互式上架(自动轮询上架结果) |
57
- | `r2-cli goods up --stock-goods-id <id> --shop-id <id> --price <amount> --json` | Agent 直接上架(自动轮询上架结果) |
58
- | `r2-cli goods down --id <id> [--json]` | 下架商品(也可用 `--stock-goods-id <id> --shop-id <id>`) |
59
- | `r2-cli goods price --id <id> --price <amount> [--json]` | 修改上架价格(也可用 `--stock-goods-id <id> --shop-id <id>`) |
60
-
61
- ## Agent 上架 4 步流程
62
-
63
- **核心原则:Agent 获取数据后展示给用户选择,不要让用户自己提供 ID。**
64
-
65
- 1. `r2-cli goods shops --json` → 展示店铺(`shopId`、`shopName`、`platform`)→ 用户选择
66
- 2. `r2-cli goods stocks --json` → 展示仓库(`stockId`、`stockName`)→ 用户选择
67
- 3. `r2-cli goods list --stock-id <id> --json` → 展示商品(`stockGoodsId`、`goodsName`、`brand`、`size`、`salePrice`)→ 用户选择(也可用 `--stock-goods-id <id>` 查询单个商品)
68
- 4. `r2-cli goods up --stock-goods-id <id> --shop-id <id> --price <amount> --json` → 提交上架(自动轮询结果)
69
-
70
- > 完整流程、参数说明和注意事项见 **r2-goods** skill。
File without changes