@newpeak/barista-cli 0.1.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/.eslintrc.json +23 -0
- package/.prettierrc +9 -0
- package/.sisyphus/notepads/liberica-employees/learnings.md +73 -0
- package/AGENTS.md +270 -0
- package/CONTRIBUTING.md +291 -0
- package/README.md +707 -0
- package/bin/barista +6 -0
- package/bin/barista.js +3 -0
- package/docs/ARCHITECTURE.md +184 -0
- package/docs/COMMANDS.md +352 -0
- package/docs/COMMAND_DESIGN_SPEC.md +811 -0
- package/docs/INTEGRATION_NOTES.md +270 -0
- package/docs/commands/REFERENCE.md +297 -0
- package/docs/commands/arabica/auth/index.md +296 -0
- package/docs/commands/liberica/auth/index.md +133 -0
- package/docs/commands/liberica/context/index.md +60 -0
- package/docs/commands/liberica/employees/create.md +185 -0
- package/docs/commands/liberica/employees/disable.md +138 -0
- package/docs/commands/liberica/employees/enable.md +137 -0
- package/docs/commands/liberica/employees/get.md +153 -0
- package/docs/commands/liberica/employees/list.md +168 -0
- package/docs/commands/liberica/employees/update.md +180 -0
- package/docs/commands/liberica/orgs/list.md +62 -0
- package/docs/commands/liberica/positions/list.md +61 -0
- package/docs/commands/liberica/roles/list.md +67 -0
- package/docs/commands/liberica/users/create.md +170 -0
- package/docs/commands/liberica/users/get.md +151 -0
- package/docs/commands/liberica/users/list.md +175 -0
- package/package.json +37 -0
- package/src/commands/arabica/auth/index.ts +277 -0
- package/src/commands/arabica/auth/login.ts +5 -0
- package/src/commands/arabica/auth/logout.ts +5 -0
- package/src/commands/arabica/auth/register.ts +5 -0
- package/src/commands/arabica/auth/status.ts +5 -0
- package/src/commands/arabica/index.ts +23 -0
- package/src/commands/auth.ts +107 -0
- package/src/commands/context.ts +60 -0
- package/src/commands/liberica/auth/index.ts +170 -0
- package/src/commands/liberica/context/index.ts +43 -0
- package/src/commands/liberica/employees/create.ts +275 -0
- package/src/commands/liberica/employees/delete.ts +122 -0
- package/src/commands/liberica/employees/disable.ts +97 -0
- package/src/commands/liberica/employees/enable.ts +97 -0
- package/src/commands/liberica/employees/get.ts +115 -0
- package/src/commands/liberica/employees/index.ts +23 -0
- package/src/commands/liberica/employees/list.ts +131 -0
- package/src/commands/liberica/employees/update.ts +157 -0
- package/src/commands/liberica/index.ts +36 -0
- package/src/commands/liberica/orgs/index.ts +35 -0
- package/src/commands/liberica/positions/index.ts +30 -0
- package/src/commands/liberica/roles/index.ts +59 -0
- package/src/commands/liberica/users/create.ts +132 -0
- package/src/commands/liberica/users/delete.ts +49 -0
- package/src/commands/liberica/users/disable.ts +41 -0
- package/src/commands/liberica/users/enable.ts +30 -0
- package/src/commands/liberica/users/get.ts +46 -0
- package/src/commands/liberica/users/index.ts +27 -0
- package/src/commands/liberica/users/list.ts +68 -0
- package/src/commands/liberica/users/me.ts +42 -0
- package/src/commands/liberica/users/reset-password.ts +42 -0
- package/src/commands/liberica/users/update.ts +48 -0
- package/src/core/api/client.ts +825 -0
- package/src/core/auth/token-manager.ts +183 -0
- package/src/core/config/manager.ts +164 -0
- package/src/index.ts +37 -0
- package/src/types/employee.ts +102 -0
- package/src/types/index.ts +75 -0
- package/src/types/org.ts +25 -0
- package/src/types/position.ts +24 -0
- package/src/types/user.ts +64 -0
- package/tests/unit/commands/arabica/auth.test.ts +230 -0
- package/tests/unit/commands/liberica/auth.test.ts +175 -0
- package/tests/unit/commands/liberica/context.test.ts +98 -0
- package/tests/unit/commands/liberica/employees/create.test.ts +463 -0
- package/tests/unit/commands/liberica/employees/disable.test.ts +82 -0
- package/tests/unit/commands/liberica/employees/enable.test.ts +82 -0
- package/tests/unit/commands/liberica/employees/get.test.ts +111 -0
- package/tests/unit/commands/liberica/employees/list.test.ts +294 -0
- package/tests/unit/commands/liberica/employees/update.test.ts +210 -0
- package/tests/unit/config.test.ts +141 -0
- package/tests/unit/types.test.ts +195 -0
- package/tsconfig.json +20 -0
package/README.md
ADDED
|
@@ -0,0 +1,707 @@
|
|
|
1
|
+
# ☕ Barista CLI
|
|
2
|
+
|
|
3
|
+
<p align="center">
|
|
4
|
+
<img src="https://img.shields.io/badge/AI--Native-CLI-blue?style=flat-square" alt="AI-Native">
|
|
5
|
+
<img src="https://img.shields.io/badge/Liberica-Production%20SaaS-green?style=flat-square" alt="Liberica">
|
|
6
|
+
<img src="https://img.shields.io/badge/Arabica-Sales%20Platform-orange?style=flat-square" alt="Arabica">
|
|
7
|
+
<img src="https://img.shields.io/badge/Node.js-18%2B-brightgreen?style=flat-square" alt="Node.js 18+">
|
|
8
|
+
</p>
|
|
9
|
+
|
|
10
|
+
<p align="center">
|
|
11
|
+
<strong>AI-Native CLI 工具</strong>,无缝桥接 Liberica 生产管理 SaaS 与 Arabica 销售平台
|
|
12
|
+
</p>
|
|
13
|
+
|
|
14
|
+
---
|
|
15
|
+
|
|
16
|
+
## 📋 目录
|
|
17
|
+
|
|
18
|
+
- [项目简介](#项目简介)
|
|
19
|
+
- [快速开始](#快速开始)
|
|
20
|
+
- [架构设计](#架构设计)
|
|
21
|
+
- [命令文档](#命令文档)
|
|
22
|
+
- [高级特性](#高级特性)
|
|
23
|
+
- [配置说明](#配置说明)
|
|
24
|
+
- [AI 集成](#AI-集成)
|
|
25
|
+
- [开发指南](#开发指南)
|
|
26
|
+
- [贡献指南](#贡献指南)
|
|
27
|
+
|
|
28
|
+
---
|
|
29
|
+
|
|
30
|
+
## 项目简介
|
|
31
|
+
|
|
32
|
+
Barista CLI 是专为 Newpeak 生态系统设计的 AI-Native 命令行工具。它提供统一的接口来管理 Liberica 生产管理 SaaS 和 Arabica 销售平台。
|
|
33
|
+
|
|
34
|
+
### 核心特性
|
|
35
|
+
|
|
36
|
+
| 特性 | 说明 |
|
|
37
|
+
|------|------|
|
|
38
|
+
| 🌍 **多环境支持** | dev、test、prod-cn、prod-jp 四环境无缝切换 |
|
|
39
|
+
| 🏢 **多租户架构** | 支持多租户环境配置与隔离 |
|
|
40
|
+
| 🔐 **Token 认证** | 安全存储于系统密钥链,环境隔离 |
|
|
41
|
+
| 🧪 **Dry-Run 模式** | 所有写入操作支持预览,避免误操作 |
|
|
42
|
+
| 🤖 **AI 集成** | 为 Claude Code 优化的 JSON 输出格式 |
|
|
43
|
+
| 🔄 **跨服务操作** | Liberica 与 Arabica 之间的数据同步 |
|
|
44
|
+
|
|
45
|
+
### 适用场景
|
|
46
|
+
|
|
47
|
+
- **生产计划管理**:创建、查询、取消生产订单
|
|
48
|
+
- **产品数据管理**:跨平台搜索、同步产品信息
|
|
49
|
+
- **客户操作**:查询客户信息、生成报价单
|
|
50
|
+
- **AI 自动化**:通过 Claude Code 实现业务流程自动化
|
|
51
|
+
|
|
52
|
+
---
|
|
53
|
+
|
|
54
|
+
## 快速开始
|
|
55
|
+
|
|
56
|
+
### 安装
|
|
57
|
+
|
|
58
|
+
```bash
|
|
59
|
+
# 通过 npm 安装
|
|
60
|
+
npm install -g @newpeak/barista-cli
|
|
61
|
+
|
|
62
|
+
# 或通过 yarn
|
|
63
|
+
yarn global add @newpeak/barista-cli
|
|
64
|
+
|
|
65
|
+
# 验证安装
|
|
66
|
+
barista --version
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
### 初始化配置
|
|
70
|
+
|
|
71
|
+
```bash
|
|
72
|
+
# 1. 初始化配置目录
|
|
73
|
+
barista init
|
|
74
|
+
|
|
75
|
+
# 2. 配置环境(选择默认环境)
|
|
76
|
+
barista context use-env dev
|
|
77
|
+
|
|
78
|
+
# 3. 配置租户
|
|
79
|
+
barista context use-tenant your-tenant
|
|
80
|
+
|
|
81
|
+
# 4. 登录获取 Token
|
|
82
|
+
barista auth login --service liberica --env dev
|
|
83
|
+
|
|
84
|
+
# 5. 验证登录状态
|
|
85
|
+
barista auth status
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
### 基本使用示例
|
|
89
|
+
|
|
90
|
+
```bash
|
|
91
|
+
# 查看当前上下文
|
|
92
|
+
barista context show
|
|
93
|
+
|
|
94
|
+
# 列出所有订单(Liberica)
|
|
95
|
+
barista liberica orders list
|
|
96
|
+
|
|
97
|
+
# 搜索产品(支持模糊查询)
|
|
98
|
+
barista liberica products search --keyword "咖啡机"
|
|
99
|
+
|
|
100
|
+
# 查看 Arabica 产品目录
|
|
101
|
+
barista arabica products public-catalog
|
|
102
|
+
|
|
103
|
+
# 创建生产订单(dry-run 模式预览)
|
|
104
|
+
barista liberica orders create --product-id 123 --quantity 100 --dry-run
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
---
|
|
108
|
+
|
|
109
|
+
## 架构设计
|
|
110
|
+
|
|
111
|
+
### 环境映射
|
|
112
|
+
|
|
113
|
+
#### Liberica(生产管理 SaaS)
|
|
114
|
+
|
|
115
|
+
| 环境 | 域名格式 | 说明 |
|
|
116
|
+
|------|----------|------|
|
|
117
|
+
| dev | `{tenant}-dev.newpeaksh.com` | 开发环境 |
|
|
118
|
+
| test | `{tenant}-test.newpeaksh.com` | 测试环境 |
|
|
119
|
+
| prod-cn | `{tenant}.newpeaksh.com` | 中国生产环境 |
|
|
120
|
+
| prod-jp | `{tenant}.newpeakjp.com` | 日本生产环境 |
|
|
121
|
+
|
|
122
|
+
#### Arabica(销售平台)
|
|
123
|
+
|
|
124
|
+
| 环境 | 域名 | 说明 |
|
|
125
|
+
|------|------|------|
|
|
126
|
+
| dev | `arabica-dev.newpeaksh.com` | 开发环境 |
|
|
127
|
+
| test | `arabica-test.newpeaksh.com` | 测试环境 |
|
|
128
|
+
| prod-cn | `www.newpeaksh.com` | 中国生产环境 |
|
|
129
|
+
| prod-jp | `members.newpeakjp.com` | 日本生产环境 |
|
|
130
|
+
|
|
131
|
+
### 认证机制
|
|
132
|
+
|
|
133
|
+
Barista CLI 采用 Token-based 认证机制:
|
|
134
|
+
|
|
135
|
+
```
|
|
136
|
+
┌─────────────────┐ ┌──────────────────┐ ┌─────────────────┐
|
|
137
|
+
│ Barista CLI │────▶│ Auth Server │────▶│ API Servers │
|
|
138
|
+
│ │ │ │ │ │
|
|
139
|
+
│ • 登录请求 │ │ • 验证凭证 │ │ • 验证 Token │
|
|
140
|
+
│ • 存储 Token │◀────│ • 签发 JWT │◀────│ • 返回数据 │
|
|
141
|
+
│ (系统密钥链) │ │ │ │ │
|
|
142
|
+
└─────────────────┘ └──────────────────┘ └─────────────────┘
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
**安全特性:**
|
|
146
|
+
|
|
147
|
+
- **密钥链存储**:Token 安全存储于系统密钥链(macOS Keychain、Windows Credential、Linux Secret Service)
|
|
148
|
+
- **自动跳过认证**:公开接口(如产品目录查询)无需认证
|
|
149
|
+
- **环境隔离**:每个环境和租户使用独立的 Token,互不影响
|
|
150
|
+
- **Token 刷新**:支持自动刷新即将过期的 Token
|
|
151
|
+
|
|
152
|
+
---
|
|
153
|
+
|
|
154
|
+
## 命令文档
|
|
155
|
+
|
|
156
|
+
> **完整命令清单**: 所有命令的完整参考(包括已实现和待开发状态)请查看 [命令参考](./docs/commands/REFERENCE.md)。
|
|
157
|
+
|
|
158
|
+
### 命令结构
|
|
159
|
+
|
|
160
|
+
```
|
|
161
|
+
barista <service> <resource> <action> [options]
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
**示例:**
|
|
165
|
+
|
|
166
|
+
```bash
|
|
167
|
+
barista liberica orders list --page 1 --size 20
|
|
168
|
+
barista arabica quotes calculate --product-id 123 --quantity 10
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
### 全局选项
|
|
172
|
+
|
|
173
|
+
| 选项 | 说明 | 示例 |
|
|
174
|
+
|------|------|------|
|
|
175
|
+
| `--env` | 指定环境 | `--env prod-cn` |
|
|
176
|
+
| `--tenant` | 指定租户 | `--tenant electionjp` |
|
|
177
|
+
| `--service` | 指定服务 | `--service liberica` |
|
|
178
|
+
| `--dry-run` | 预览模式 | `--dry-run` |
|
|
179
|
+
| `--json` | JSON 输出 | `--json` |
|
|
180
|
+
| `--help` | 显示帮助 | `--help` |
|
|
181
|
+
|
|
182
|
+
### 上下文管理
|
|
183
|
+
|
|
184
|
+
上下文管理用于快速切换工作环境,避免每个命令都指定环境参数。
|
|
185
|
+
|
|
186
|
+
```bash
|
|
187
|
+
# 查看当前上下文
|
|
188
|
+
barista context show
|
|
189
|
+
|
|
190
|
+
# 输出示例:
|
|
191
|
+
# ┌─────────────┬─────────────────┐
|
|
192
|
+
# │ 属性 │ 值 │
|
|
193
|
+
# ├─────────────┼─────────────────┤
|
|
194
|
+
# │ 当前环境 │ dev │
|
|
195
|
+
# │ 当前租户 │ electionjp │
|
|
196
|
+
# │ 当前服务 │ liberica │
|
|
197
|
+
# │ Token 状态 │ 已登录 │
|
|
198
|
+
# │ Token 过期 │ 2024-12-31 │
|
|
199
|
+
# └─────────────┴─────────────────┘
|
|
200
|
+
|
|
201
|
+
# 切换环境
|
|
202
|
+
barista context use-env [dev|test|prod-cn|prod-jp]
|
|
203
|
+
|
|
204
|
+
# 切换租户
|
|
205
|
+
barista context use-tenant <tenant-name>
|
|
206
|
+
|
|
207
|
+
# 切换默认服务
|
|
208
|
+
barista context use-service [liberica|arabica]
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
### 认证管理
|
|
212
|
+
|
|
213
|
+
```bash
|
|
214
|
+
# 登录获取 Token
|
|
215
|
+
barista auth login --service <service> --env <env> [--tenant <tenant>]
|
|
216
|
+
|
|
217
|
+
# 示例:登录 Liberica 开发环境
|
|
218
|
+
barista auth login --service liberica --env dev --tenant electionjp
|
|
219
|
+
|
|
220
|
+
# 检查登录状态
|
|
221
|
+
barista auth status
|
|
222
|
+
|
|
223
|
+
# 输出示例:
|
|
224
|
+
# ✓ Liberica (dev) - 已登录 (过期: 2024-12-31)
|
|
225
|
+
# ✗ Liberica (test) - 未登录
|
|
226
|
+
# ✓ Arabica (prod-cn) - 已登录 (过期: 2024-12-30)
|
|
227
|
+
|
|
228
|
+
# 登出(清除 Token)
|
|
229
|
+
barista auth logout --service <service> --env <env>
|
|
230
|
+
|
|
231
|
+
# 登出所有环境
|
|
232
|
+
barista auth logout --all
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
### Liberica 命令
|
|
236
|
+
|
|
237
|
+
#### 订单管理
|
|
238
|
+
|
|
239
|
+
```bash
|
|
240
|
+
# 列出订单(分页)
|
|
241
|
+
barista liberica orders list [--page <n>] [--size <n>] [--status <status>]
|
|
242
|
+
|
|
243
|
+
# 获取单个订单详情
|
|
244
|
+
barista liberica orders get <order-id>
|
|
245
|
+
|
|
246
|
+
# 创建订单
|
|
247
|
+
barista liberica orders create \
|
|
248
|
+
--product-id <id> \
|
|
249
|
+
--quantity <n> \
|
|
250
|
+
[--delivery-date <date>] \
|
|
251
|
+
[--note <text>]
|
|
252
|
+
|
|
253
|
+
# 取消订单
|
|
254
|
+
barista liberica orders cancel <order-id> [--reason <text>]
|
|
255
|
+
```
|
|
256
|
+
|
|
257
|
+
#### 产品管理
|
|
258
|
+
|
|
259
|
+
```bash
|
|
260
|
+
# 搜索产品
|
|
261
|
+
barista liberica products search --keyword <keyword> [--category <id>]
|
|
262
|
+
|
|
263
|
+
# 获取产品详情
|
|
264
|
+
barista liberica products get <product-id>
|
|
265
|
+
|
|
266
|
+
# 获取公开产品列表(无需认证)
|
|
267
|
+
barista liberica products public-list [--category <id>] [--page <n>]
|
|
268
|
+
```
|
|
269
|
+
|
|
270
|
+
#### 生产计划
|
|
271
|
+
|
|
272
|
+
```bash
|
|
273
|
+
# 查看生产排期
|
|
274
|
+
barista liberica production schedule [--start-date <date>] [--end-date <date>]
|
|
275
|
+
|
|
276
|
+
# 重新排产
|
|
277
|
+
barista liberica production reschedule <order-id> --new-date <date> [--dry-run]
|
|
278
|
+
|
|
279
|
+
# 查询产能
|
|
280
|
+
barista liberica production capacity [--date <date>] [--line <line-id>]
|
|
281
|
+
```
|
|
282
|
+
|
|
283
|
+
### Arabica 命令
|
|
284
|
+
|
|
285
|
+
#### 产品管理
|
|
286
|
+
|
|
287
|
+
```bash
|
|
288
|
+
# 列出产品
|
|
289
|
+
barista arabica products list [--page <n>] [--size <n>] [--category <id>]
|
|
290
|
+
|
|
291
|
+
# 搜索产品
|
|
292
|
+
barista arabica products search --keyword <keyword>
|
|
293
|
+
|
|
294
|
+
# 获取产品目录(公开接口)
|
|
295
|
+
barista arabica products public-catalog [--lang <zh|jp|en>]
|
|
296
|
+
```
|
|
297
|
+
|
|
298
|
+
#### 报价管理
|
|
299
|
+
|
|
300
|
+
```bash
|
|
301
|
+
# 计算报价
|
|
302
|
+
barista arabica quotes calculate \
|
|
303
|
+
--product-id <id> \
|
|
304
|
+
--quantity <n> \
|
|
305
|
+
[--options <json>]
|
|
306
|
+
|
|
307
|
+
# 创建报价单
|
|
308
|
+
barista arabica quotes create \
|
|
309
|
+
--customer-id <id> \
|
|
310
|
+
--items <json> \
|
|
311
|
+
[--valid-days <n>]
|
|
312
|
+
```
|
|
313
|
+
|
|
314
|
+
#### 客户管理
|
|
315
|
+
|
|
316
|
+
```bash
|
|
317
|
+
# 搜索客户
|
|
318
|
+
barista arabica customers search --keyword <keyword> [--type <type>]
|
|
319
|
+
|
|
320
|
+
# 获取客户详情
|
|
321
|
+
barista arabica customers get <customer-id>
|
|
322
|
+
```
|
|
323
|
+
|
|
324
|
+
### 跨服务命令
|
|
325
|
+
|
|
326
|
+
跨服务命令实现 Liberica 与 Arabica 之间的数据同步和业务流程衔接。
|
|
327
|
+
|
|
328
|
+
```bash
|
|
329
|
+
# 从订单生成报价单
|
|
330
|
+
barista cross quote-from-order <order-id> [--target-service arabica]
|
|
331
|
+
|
|
332
|
+
# 输出示例:
|
|
333
|
+
# ✓ 已生成报价单
|
|
334
|
+
# ┌──────────┬────────────┐
|
|
335
|
+
# │ 属性 │ 值 │
|
|
336
|
+
# ├──────────┼────────────┤
|
|
337
|
+
# │ 订单ID │ 12345 │
|
|
338
|
+
# │ 报价单ID │ QT-2024-001│
|
|
339
|
+
# │ 金额 │ ¥50,000 │
|
|
340
|
+
# │ 有效期 │ 30天 │
|
|
341
|
+
# └──────────┴────────────┘
|
|
342
|
+
|
|
343
|
+
# 同步订单状态到 Arabica
|
|
344
|
+
barista cross sync-order <order-id> [--direction liberica-to-arabica]
|
|
345
|
+
```
|
|
346
|
+
|
|
347
|
+
---
|
|
348
|
+
|
|
349
|
+
## 高级特性
|
|
350
|
+
|
|
351
|
+
### Dry-Run 模式
|
|
352
|
+
|
|
353
|
+
Dry-Run 模式允许你在执行写入操作前预览其影响,避免误操作。
|
|
354
|
+
|
|
355
|
+
```bash
|
|
356
|
+
# 所有写入操作都支持 --dry-run 选项
|
|
357
|
+
barista liberica orders create --product-id 123 --quantity 100 --dry-run
|
|
358
|
+
|
|
359
|
+
# 输出示例:
|
|
360
|
+
# 🔍 Dry-Run 模式:操作不会被实际执行
|
|
361
|
+
# ┌─────────────────┬──────────────────────┐
|
|
362
|
+
# │ 操作 │ 创建订单 │
|
|
363
|
+
# ├─────────────────┼──────────────────────┤
|
|
364
|
+
# │ 产品 │ 咖啡机 Pro (ID: 123) │
|
|
365
|
+
# │ 数量 │ 100 │
|
|
366
|
+
# │ 预计金额 │ ¥50,000 │
|
|
367
|
+
# │ 预计交期 │ 2024-12-31 │
|
|
368
|
+
# │ 影响 │ 新增一条订单记录 │
|
|
369
|
+
# └─────────────────┴──────────────────────┘
|
|
370
|
+
#
|
|
371
|
+
# ⚠️ 确认执行?添加 --confirm 选项或移除 --dry-run
|
|
372
|
+
```
|
|
373
|
+
|
|
374
|
+
**默认 Dry-Run 的操作:**
|
|
375
|
+
|
|
376
|
+
以下破坏性操作默认启用 Dry-Run 模式,需显式确认:
|
|
377
|
+
|
|
378
|
+
- 取消订单
|
|
379
|
+
- 删除产品
|
|
380
|
+
- 批量更新
|
|
381
|
+
|
|
382
|
+
### JSON 输出格式
|
|
383
|
+
|
|
384
|
+
Barista CLI 支持 JSON 输出,便于脚本处理和 AI 集成:
|
|
385
|
+
|
|
386
|
+
```bash
|
|
387
|
+
barista liberica orders list --json
|
|
388
|
+
|
|
389
|
+
# 输出示例:
|
|
390
|
+
{
|
|
391
|
+
"success": true,
|
|
392
|
+
"data": {
|
|
393
|
+
"items": [
|
|
394
|
+
{
|
|
395
|
+
"id": "12345",
|
|
396
|
+
"productName": "咖啡机 Pro",
|
|
397
|
+
"quantity": 100,
|
|
398
|
+
"status": "in_production",
|
|
399
|
+
"createdAt": "2024-01-15T10:30:00Z"
|
|
400
|
+
}
|
|
401
|
+
],
|
|
402
|
+
"pagination": {
|
|
403
|
+
"page": 1,
|
|
404
|
+
"size": 20,
|
|
405
|
+
"total": 150
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
```
|
|
410
|
+
|
|
411
|
+
---
|
|
412
|
+
|
|
413
|
+
## 配置说明
|
|
414
|
+
|
|
415
|
+
### 配置文件
|
|
416
|
+
|
|
417
|
+
配置文件位于 `~/.barista/config.yaml`:
|
|
418
|
+
|
|
419
|
+
```yaml
|
|
420
|
+
# Barista CLI 配置文件
|
|
421
|
+
|
|
422
|
+
# 默认上下文设置
|
|
423
|
+
defaults:
|
|
424
|
+
env: dev
|
|
425
|
+
tenant: electionjp
|
|
426
|
+
service: liberica
|
|
427
|
+
|
|
428
|
+
# 环境配置
|
|
429
|
+
environments:
|
|
430
|
+
dev:
|
|
431
|
+
liberica:
|
|
432
|
+
baseUrl: "https://{tenant}-dev.newpeaksh.com"
|
|
433
|
+
timeout: 30000
|
|
434
|
+
arabica:
|
|
435
|
+
baseUrl: "https://arabica-dev.newpeaksh.com"
|
|
436
|
+
timeout: 30000
|
|
437
|
+
|
|
438
|
+
test:
|
|
439
|
+
liberica:
|
|
440
|
+
baseUrl: "https://{tenant}-test.newpeaksh.com"
|
|
441
|
+
timeout: 30000
|
|
442
|
+
arabica:
|
|
443
|
+
baseUrl: "https://arabica-test.newpeaksh.com"
|
|
444
|
+
timeout: 30000
|
|
445
|
+
|
|
446
|
+
prod-cn:
|
|
447
|
+
liberica:
|
|
448
|
+
baseUrl: "https://{tenant}.newpeaksh.com"
|
|
449
|
+
timeout: 60000
|
|
450
|
+
arabica:
|
|
451
|
+
baseUrl: "https://www.newpeaksh.com"
|
|
452
|
+
timeout: 60000
|
|
453
|
+
|
|
454
|
+
prod-jp:
|
|
455
|
+
liberica:
|
|
456
|
+
baseUrl: "https://{tenant}.newpeakjp.com"
|
|
457
|
+
timeout: 60000
|
|
458
|
+
arabica:
|
|
459
|
+
baseUrl: "https://members.newpeakjp.com"
|
|
460
|
+
timeout: 60000
|
|
461
|
+
|
|
462
|
+
# 输出配置
|
|
463
|
+
output:
|
|
464
|
+
format: table # table | json
|
|
465
|
+
color: true
|
|
466
|
+
timestamp: true
|
|
467
|
+
```
|
|
468
|
+
|
|
469
|
+
### 多租户配置
|
|
470
|
+
|
|
471
|
+
支持配置多个租户,快速切换:
|
|
472
|
+
|
|
473
|
+
```bash
|
|
474
|
+
# 添加租户配置
|
|
475
|
+
barista config add-tenant \
|
|
476
|
+
--name customer-a \
|
|
477
|
+
--liberica-id customer-a-id \
|
|
478
|
+
--arabica-id customer-a-arabica-id
|
|
479
|
+
|
|
480
|
+
# 列出已配置租户
|
|
481
|
+
barista config list-tenants
|
|
482
|
+
|
|
483
|
+
# 快速切换租户
|
|
484
|
+
barista context use-tenant customer-a
|
|
485
|
+
```
|
|
486
|
+
|
|
487
|
+
---
|
|
488
|
+
|
|
489
|
+
## AI 集成
|
|
490
|
+
|
|
491
|
+
Barista CLI 专为 AI 编程助手优化,特别是 Claude Code。
|
|
492
|
+
|
|
493
|
+
### Claude Code 使用示例
|
|
494
|
+
|
|
495
|
+
```typescript
|
|
496
|
+
// 在 Claude Code 中使用 Barista CLI
|
|
497
|
+
// 示例:获取订单列表并分析
|
|
498
|
+
|
|
499
|
+
const result = await $`barista liberica orders list --json --page 1 --size 10`;
|
|
500
|
+
const orders = JSON.parse(result.stdout);
|
|
501
|
+
|
|
502
|
+
// 分析订单数据
|
|
503
|
+
const analysis = orders.data.items.map(order => ({
|
|
504
|
+
id: order.id,
|
|
505
|
+
status: order.status,
|
|
506
|
+
amount: order.amount
|
|
507
|
+
}));
|
|
508
|
+
```
|
|
509
|
+
|
|
510
|
+
### Skills 文件
|
|
511
|
+
|
|
512
|
+
Barista CLI 提供 Claude Code Skills 文件,位于:
|
|
513
|
+
|
|
514
|
+
```
|
|
515
|
+
~/.barista/claude/skills/
|
|
516
|
+
├── orders.md # 订单管理技能
|
|
517
|
+
├── products.md # 产品管理技能
|
|
518
|
+
├── quotes.md # 报价管理技能
|
|
519
|
+
└── customers.md # 客户管理技能
|
|
520
|
+
```
|
|
521
|
+
|
|
522
|
+
**示例 Skills 文件:**
|
|
523
|
+
|
|
524
|
+
```markdown
|
|
525
|
+
# 订单管理技能
|
|
526
|
+
|
|
527
|
+
## 列出待处理订单
|
|
528
|
+
|
|
529
|
+
当用户询问待处理订单时:
|
|
530
|
+
|
|
531
|
+
1. 执行命令:barista liberica orders list --status pending --json
|
|
532
|
+
2. 解析返回的 JSON
|
|
533
|
+
3. 总结订单数量和总金额
|
|
534
|
+
4. 列出前 5 个订单的关键信息
|
|
535
|
+
|
|
536
|
+
## 创建新订单
|
|
537
|
+
|
|
538
|
+
当用户需要创建订单时:
|
|
539
|
+
|
|
540
|
+
1. 确认产品 ID 和数量
|
|
541
|
+
2. 使用 dry-run 预览:barista liberica orders create --dry-run ...
|
|
542
|
+
3. 用户确认后执行实际命令
|
|
543
|
+
```
|
|
544
|
+
|
|
545
|
+
### AI 友好的输出
|
|
546
|
+
|
|
547
|
+
所有命令都支持 `--json` 选项,返回结构化的 JSON 数据:
|
|
548
|
+
|
|
549
|
+
```bash
|
|
550
|
+
# 查询带结构化输出
|
|
551
|
+
barista liberica orders get 12345 --json
|
|
552
|
+
|
|
553
|
+
{
|
|
554
|
+
"success": true,
|
|
555
|
+
"data": {
|
|
556
|
+
"id": "12345",
|
|
557
|
+
"status": "in_production",
|
|
558
|
+
"product": {
|
|
559
|
+
"id": "100",
|
|
560
|
+
"name": "咖啡机 Pro"
|
|
561
|
+
},
|
|
562
|
+
"quantity": 100,
|
|
563
|
+
"amount": 50000,
|
|
564
|
+
"timeline": {
|
|
565
|
+
"created": "2024-01-15T10:30:00Z",
|
|
566
|
+
"delivery": "2024-02-15"
|
|
567
|
+
}
|
|
568
|
+
},
|
|
569
|
+
"meta": {
|
|
570
|
+
"requestId": "req-abc123",
|
|
571
|
+
"timestamp": "2024-01-15T10:30:00Z"
|
|
572
|
+
}
|
|
573
|
+
}
|
|
574
|
+
```
|
|
575
|
+
|
|
576
|
+
---
|
|
577
|
+
|
|
578
|
+
## 开发指南
|
|
579
|
+
|
|
580
|
+
### 项目结构
|
|
581
|
+
|
|
582
|
+
```
|
|
583
|
+
coffee-barista-cli/
|
|
584
|
+
├── bin/
|
|
585
|
+
│ └── barista.js # 入口文件
|
|
586
|
+
├── src/
|
|
587
|
+
│ ├── commands/ # 命令实现
|
|
588
|
+
│ │ ├── context/ # 上下文管理命令
|
|
589
|
+
│ │ ├── auth/ # 认证命令
|
|
590
|
+
│ │ ├── liberica/ # Liberica 服务命令
|
|
591
|
+
│ │ │ ├── orders.js
|
|
592
|
+
│ │ │ ├── products.js
|
|
593
|
+
│ │ │ └── production.js
|
|
594
|
+
│ │ ├── arabica/ # Arabica 服务命令
|
|
595
|
+
│ │ │ ├── products.js
|
|
596
|
+
│ │ │ ├── quotes.js
|
|
597
|
+
│ │ │ └── customers.js
|
|
598
|
+
│ │ └── cross/ # 跨服务命令
|
|
599
|
+
│ ├── core/ # 核心模块
|
|
600
|
+
│ │ ├── auth.js # 认证管理
|
|
601
|
+
│ │ ├── config.js # 配置管理
|
|
602
|
+
│ │ ├── context.js # 上下文管理
|
|
603
|
+
│ │ └── api-client.js # API 客户端
|
|
604
|
+
│ ├── utils/ # 工具函数
|
|
605
|
+
│ │ ├── formatter.js # 输出格式化
|
|
606
|
+
│ │ ├── validator.js # 参数验证
|
|
607
|
+
│ │ └── keychain.js # 密钥链操作
|
|
608
|
+
│ └── templates/ # 模板文件
|
|
609
|
+
├── skills/ # Claude Code Skills
|
|
610
|
+
├── tests/ # 测试文件
|
|
611
|
+
├── package.json
|
|
612
|
+
└── README.md
|
|
613
|
+
```
|
|
614
|
+
|
|
615
|
+
### 本地开发
|
|
616
|
+
|
|
617
|
+
```bash
|
|
618
|
+
# 1. 克隆仓库
|
|
619
|
+
git clone https://gitlab.newpeaksh.com/coffee/coffee-barista-cli.git
|
|
620
|
+
cd coffee-barista-cli
|
|
621
|
+
|
|
622
|
+
# 2. 安装依赖
|
|
623
|
+
npm install
|
|
624
|
+
|
|
625
|
+
# 3. 链接到全局(开发模式)
|
|
626
|
+
npm link
|
|
627
|
+
|
|
628
|
+
# 4. 验证链接
|
|
629
|
+
barista --version
|
|
630
|
+
|
|
631
|
+
# 5. 运行测试
|
|
632
|
+
npm test
|
|
633
|
+
|
|
634
|
+
# 6. 代码检查
|
|
635
|
+
npm run lint
|
|
636
|
+
```
|
|
637
|
+
|
|
638
|
+
### 添加新命令
|
|
639
|
+
|
|
640
|
+
**重要**:新增命令必须遵循 [命令设计规范](./docs/COMMAND_DESIGN_SPEC.md),包含设计文档编写、技术评审等完整流程。
|
|
641
|
+
|
|
642
|
+
详细步骤请参考:
|
|
643
|
+
- [完整命令参考](./docs/commands/REFERENCE.md) - 所有命令清单和开发优先级
|
|
644
|
+
- [命令设计规范文档](./docs/COMMAND_DESIGN_SPEC.md#5-命令开发流程规范)
|
|
645
|
+
- [命令开发指南](./docs/COMMANDS.md)
|
|
646
|
+
|
|
647
|
+
---
|
|
648
|
+
|
|
649
|
+
## 贡献指南
|
|
650
|
+
|
|
651
|
+
我们欢迎所有形式的贡献,包括但不限于:
|
|
652
|
+
|
|
653
|
+
- 🐛 报告 Bug
|
|
654
|
+
- 💡 提出新功能建议
|
|
655
|
+
- 📝 改进文档
|
|
656
|
+
- 🔧 提交代码修复
|
|
657
|
+
- ✨ 添加新功能
|
|
658
|
+
|
|
659
|
+
### 提交规范
|
|
660
|
+
|
|
661
|
+
请遵循 [Conventional Commits](https://www.conventionalcommits.org/) 规范:
|
|
662
|
+
|
|
663
|
+
```bash
|
|
664
|
+
# 修复 Bug
|
|
665
|
+
fix: 修复订单列表分页问题
|
|
666
|
+
|
|
667
|
+
# 添加功能
|
|
668
|
+
feat: 添加库存查询命令
|
|
669
|
+
|
|
670
|
+
# 文档更新
|
|
671
|
+
docs: 更新 README 中的环境映射
|
|
672
|
+
|
|
673
|
+
# 代码重构
|
|
674
|
+
refactor: 重构 API 客户端错误处理
|
|
675
|
+
```
|
|
676
|
+
|
|
677
|
+
### 开发流程
|
|
678
|
+
|
|
679
|
+
1. Fork 本仓库
|
|
680
|
+
2. 创建功能分支:`git checkout -b feature/my-feature`
|
|
681
|
+
3. 提交更改:`git commit -m 'feat: add some feature'`
|
|
682
|
+
4. 推送分支:`git push origin feature/my-feature`
|
|
683
|
+
5. 创建 Pull Request
|
|
684
|
+
|
|
685
|
+
---
|
|
686
|
+
|
|
687
|
+
## 相关项目
|
|
688
|
+
|
|
689
|
+
| 项目 | 描述 | 链接 |
|
|
690
|
+
|------|------|------|
|
|
691
|
+
| ☕ Liberica Backend | 生产管理 SaaS 后端 | [coffee-liberica-end](https://gitlab.newpeaksh.com/coffee/coffee-liberica-end) |
|
|
692
|
+
| 🖥️ Liberica Frontend | 生产管理 Web 前端 | [coffee-liberica-front](https://gitlab.newpeaksh.com/coffee/coffee-liberica-front) |
|
|
693
|
+
| 📱 Liberica Mobile | 生产管理移动端 | [coffee-liberica-mobile-front](https://gitlab.newpeaksh.com/coffee/coffee-liberica-mobile-front) |
|
|
694
|
+
| 🛒 Arabica Backend | 销售平台后端 | [coffee-arabica-end](https://gitlab.newpeaksh.com/coffee/coffee-arabica-end) |
|
|
695
|
+
| 🌐 Arabica Frontend | 销售平台前端 | [coffee-arabica-front](https://gitlab.newpeaksh.com/coffee/coffee-arabica-front) |
|
|
696
|
+
|
|
697
|
+
---
|
|
698
|
+
|
|
699
|
+
## 许可证
|
|
700
|
+
|
|
701
|
+
[MIT](LICENSE) © Newpeak Technology
|
|
702
|
+
|
|
703
|
+
---
|
|
704
|
+
|
|
705
|
+
<p align="center">
|
|
706
|
+
用 ☕ 驱动生产力
|
|
707
|
+
</p>
|
package/bin/barista
ADDED
package/bin/barista.js
ADDED