@newpeak/barista-cli 0.1.15 → 0.1.16

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.
Files changed (44) hide show
  1. package/README.ja.md +209 -620
  2. package/README.md +206 -755
  3. package/README.vi.md +206 -623
  4. package/README.zh.md +340 -0
  5. package/dist/commands/liberica/orgs/batch-delete.d.ts +3 -0
  6. package/dist/commands/liberica/orgs/batch-delete.d.ts.map +1 -0
  7. package/dist/commands/liberica/orgs/batch-delete.js +109 -0
  8. package/dist/commands/liberica/orgs/batch-delete.js.map +1 -0
  9. package/dist/commands/liberica/orgs/create.d.ts +3 -0
  10. package/dist/commands/liberica/orgs/create.d.ts.map +1 -0
  11. package/dist/commands/liberica/orgs/create.js +131 -0
  12. package/dist/commands/liberica/orgs/create.js.map +1 -0
  13. package/dist/commands/liberica/orgs/disable.d.ts +3 -0
  14. package/dist/commands/liberica/orgs/disable.d.ts.map +1 -0
  15. package/dist/commands/liberica/orgs/disable.js +98 -0
  16. package/dist/commands/liberica/orgs/disable.js.map +1 -0
  17. package/dist/commands/liberica/orgs/enable.d.ts +3 -0
  18. package/dist/commands/liberica/orgs/enable.d.ts.map +1 -0
  19. package/dist/commands/liberica/orgs/enable.js +98 -0
  20. package/dist/commands/liberica/orgs/enable.js.map +1 -0
  21. package/dist/commands/liberica/orgs/get.d.ts +3 -0
  22. package/dist/commands/liberica/orgs/get.d.ts.map +1 -0
  23. package/dist/commands/liberica/orgs/get.js +79 -0
  24. package/dist/commands/liberica/orgs/get.js.map +1 -0
  25. package/dist/commands/liberica/orgs/index.d.ts.map +1 -1
  26. package/dist/commands/liberica/orgs/index.js +15 -21
  27. package/dist/commands/liberica/orgs/index.js.map +1 -1
  28. package/dist/commands/liberica/orgs/list.d.ts +3 -0
  29. package/dist/commands/liberica/orgs/list.d.ts.map +1 -0
  30. package/dist/commands/liberica/orgs/list.js +51 -0
  31. package/dist/commands/liberica/orgs/list.js.map +1 -0
  32. package/dist/commands/liberica/orgs/update.d.ts +3 -0
  33. package/dist/commands/liberica/orgs/update.d.ts.map +1 -0
  34. package/dist/commands/liberica/orgs/update.js +136 -0
  35. package/dist/commands/liberica/orgs/update.js.map +1 -0
  36. package/dist/core/api/client.d.ts +7 -1
  37. package/dist/core/api/client.d.ts.map +1 -1
  38. package/dist/core/api/client.js +128 -0
  39. package/dist/core/api/client.js.map +1 -1
  40. package/dist/index.js +1 -1
  41. package/dist/types/org.d.ts +38 -0
  42. package/dist/types/org.d.ts.map +1 -1
  43. package/package.json +1 -1
  44. package/README.en.md +0 -757
package/README.md CHANGED
@@ -1,630 +1,268 @@
1
1
  # ☕ Barista CLI
2
2
 
3
- <p align="center">
4
- <a href="https://gitlab.newpeaksh.com/coffee/coffee-barista-cli/blob/develop/README.md"><img src="https://img.shields.io/badge/-简体中文-green?style=flat-square" alt="简体中文"></a>
5
- <a href="https://gitlab.newpeaksh.com/coffee/coffee-barista-cli/blob/develop/README.en.md"><img src="https://img.shields.io/badge/-English-blue?style=flat-square" alt="English"></a>
6
- <a href="https://gitlab.newpeaksh.com/coffee/coffee-barista-cli/blob/develop/README.ja.md"><img src="https://img.shields.io/badge/-日本語-red?style=flat-square" alt="日本語"></a>
7
- <a href="https://gitlab.newpeaksh.com/coffee/coffee-barista-cli/blob/develop/README.vi.md"><img src="https://img.shields.io/badge/-Tiếng%20Việt-green?style=flat-square" alt="Tiếng Việt"></a>
8
- </p>
9
-
10
- <p align="center">
11
- <img src="https://img.shields.io/badge/AI--Native-CLI-blue?style=flat-square" alt="AI-Native">
12
- <img src="https://img.shields.io/badge/Liberica-Production%20SaaS-green?style=flat-square" alt="Liberica">
13
- <img src="https://img.shields.io/badge/Arabica-在线订阅%20SaaS-orange?style=flat-square" alt="Arabica">
14
- <img src="https://img.shields.io/badge/Node.js-18%2B-brightgreen?style=flat-square" alt="Node.js 18+">
15
- </p>
16
-
17
- <p align="center">
18
- <strong>AI-Native CLI 工具</strong>,无缝桥接 Liberica 生产管理 SaaS 与 Arabica 在线订阅 SaaS 服务
19
- </p>
3
+ > **Let AI assistants control production management systems** — Bridge AI tools (Claude Code, OpenCode, OpenClaw) to enterprise SaaS
20
4
 
21
- ---
22
-
23
- ## 📋 目录
24
-
25
- - [项目简介](#项目简介)
26
- - [快速开始](#快速开始)
27
- - [架构设计](#架构设计)
28
- - [命令文档](#命令文档)
29
- - [高级特性](#高级特性)
30
- - [配置说明](#配置说明)
31
- - [AI 集成](#AI-集成)
32
- - [开发指南](#开发指南)
33
- - [贡献指南](#贡献指南)
5
+ [![npm version](https://img.shields.io/npm/v/@newpeak/barista-cli.svg?style=flat-square)](https://www.npmjs.com/package/@newpeak/barista-cli)
6
+ [![License: MIT](https://img.shields.io/badge/License-MIT-green.svg?style=flat-square)](LICENSE)
7
+ [![Weekly Downloads](https://img.shields.io/npm/dw/@newpeak/barista-cli?style=flat-square)](https://www.npmjs.com/package/@newpeak/barista-cli)
8
+ [![Node.js](https://img.shields.io/badge/Node.js-18%2B-brightgreen?style=flat-square)](https://nodejs.org/)
34
9
 
35
10
  ---
36
11
 
37
- ## 项目简介
38
-
39
- Barista CLI 是专为 Newpeak 生态系统设计的 AI-Native 命令行工具。它提供统一的接口来管理 Liberica 生产管理 SaaS 和 Arabica 在线订阅 SaaS 服务。
12
+ ## ⚡ Quick Start
40
13
 
41
- ### 核心特性
42
-
43
- | 特性 | 说明 |
44
- |------|------|
45
- | 🌍 **多环境支持** | dev、test、prod-cn、prod-jp 四环境无缝切换 |
46
- | 🏢 **多租户架构** | 支持多租户环境配置与隔离 |
47
- | 🔐 **Token 认证** | 安全存储于系统密钥链,环境隔离 |
48
- | 🧪 **Dry-Run 模式** | 所有写入操作支持预览,避免误操作 |
49
- | 🤖 **AI 集成** | 为 Claude Code 优化的 JSON 输出格式 |
50
- | 🔄 **跨服务操作** | Liberica 与 Arabica 之间的数据同步 |
51
-
52
- ### 适用场景
53
-
54
- - **生产计划管理**:创建、查询、取消生产订单
55
- - **产品数据管理**:跨平台搜索、同步产品信息
56
- - **客户操作**:查询客户信息、生成报价单
57
- - **AI 自动化**:通过 Claude Code 实现业务流程自动化
58
-
59
- ---
60
-
61
- ## 快速开始
62
-
63
- ### 安装
14
+ ### 1. Install
64
15
 
65
16
  ```bash
66
- # 通过 npm 安装
67
17
  npm install -g @newpeak/barista-cli
68
-
69
- # 或通过 yarn
70
- yarn global add @newpeak/barista-cli
71
-
72
- # 验证安装
73
- barista --version
74
18
  ```
75
19
 
76
- ### 初始化配置
20
+ ### 2. Authenticate
77
21
 
78
22
  ```bash
79
- # 1. 初始化配置目录
80
- barista init
81
-
82
- # 2. 使用凭证登录(推荐方式,自动设置环境和租户)
83
- barista liberica auth login dev your-tenant your-username your-password
23
+ # AI needs credentials to operate on behalf of user
24
+ barista liberica auth login prod-cn your-tenant your-username your-password
84
25
 
85
- # 或交互式登录(系统会提示输入缺失信息)
26
+ # Interactive login (prompts for missing info)
86
27
  barista liberica auth login
87
-
88
- # 3. 验证登录状态
89
- barista auth status
90
-
91
- # 4. 查看当前上下文(确认环境已自动设置)
92
- barista context show
93
28
  ```
94
29
 
95
- **注意**:使用 `barista liberica auth login` 登录后,系统会自动设置当前环境上下文,后续命令无需指定 `--env` 和 `--tenant` 参数。
96
-
97
- ### 基本使用示例
98
-
99
- ```bash
100
- # 查看当前上下文
101
- barista context show
102
-
103
- # 列出所有订单(Liberica)
104
- barista liberica orders list
105
-
106
- # 搜索产品(支持模糊查询)
107
- barista liberica products search --keyword "咖啡机"
108
-
109
- # 查看 Arabica 产品目录
110
- barista arabica products public-catalog
111
-
112
- # 创建生产订单(dry-run 模式预览)
113
- barista liberica orders create --product-id 123 --quantity 100 --dry-run
114
- ```
115
-
116
- ---
117
-
118
- ## 架构设计
30
+ ### 3. AI Integration
119
31
 
120
- ### 环境映射
121
-
122
- #### Liberica(生产管理 SaaS)
123
-
124
- | 环境 | 域名格式 | 说明 |
125
- |------|----------|------|
126
- | dev | `{tenant}-dev.newpeaksh.com` | 开发环境 |
127
- | test | `{tenant}-test.newpeaksh.com` | 测试环境 |
128
- | prod-cn | `{tenant}.newpeaksh.com` | 中国生产环境 |
129
- | prod-jp | `{tenant}.newpeakjp.com` | 日本生产环境 |
130
-
131
- #### Arabica(在线订阅 SaaS 服务)
132
-
133
- | 环境 | 域名 | 说明 |
134
- |------|------|------|
135
- | dev | `arabica-dev.newpeaksh.com` | 开发环境 |
136
- | test | `arabica-test.newpeaksh.com` | 测试环境 |
137
- | prod-cn | `www.newpeaksh.com` | 中国生产环境 |
138
- | prod-jp | `members.newpeakjp.com` | 日本生产环境 |
139
-
140
- ### 认证机制
141
-
142
- Barista CLI 采用 Token-based 认证机制:
32
+ ```typescript
33
+ // In Claude Code / OpenCode / OpenClaw:
34
+ const orders = await $`barista liberica orders list --env prod-cn --tenant your-tenant --json`
35
+ const { success, data } = JSON.parse(orders.stdout)
143
36
 
37
+ // AI parses and acts on the data
38
+ if (data.items.length > 0) {
39
+ console.log(`Found ${data.pagination.total} orders`)
40
+ }
144
41
  ```
145
- ┌─────────────────┐ ┌──────────────────┐ ┌─────────────────┐
146
- │ Barista CLI │────▶│ Auth Server │────▶│ API Servers │
147
- │ │ │ │ │ │
148
- │ • 登录请求 │ │ • 验证凭证 │ │ • 验证 Token │
149
- │ • 存储 Token │◀────│ • 签发 JWT │◀────│ • 返回数据 │
150
- │ (系统密钥链) │ │ │ │ │
151
- └─────────────────┘ └──────────────────┘ └─────────────────┘
152
- ```
153
-
154
- **安全特性:**
155
42
 
156
- - **密钥链存储**:Token 安全存储于系统密钥链(macOS Keychain、Windows Credential、Linux Secret Service)
157
- - **自动跳过认证**:公开接口(如产品目录查询)无需认证
158
- - **环境隔离**:每个环境和租户使用独立的 Token,互不影响
159
- - **Token 刷新**:支持自动刷新即将过期的 Token
43
+ **[View AI Integration Examples →](#ai-integration)**
160
44
 
161
45
  ---
162
46
 
163
- ## 命令文档
164
-
165
- > **完整命令清单**: 所有命令的完整参考(包括已实现和待开发状态)请查看 [命令参考](./docs/commands/REFERENCE.md)。
166
-
167
- ### 命令结构
168
-
169
- ```
170
- barista <service> <resource> <action> [options]
171
- ```
172
-
173
- **示例:**
174
-
175
- ```bash
176
- barista liberica orders list --page 1 --size 20
177
- barista arabica quotes calculate --product-id 123 --quantity 10
178
- ```
179
-
180
- ### 全局选项
47
+ ## 🤖 AI Integration
181
48
 
182
- | 选项 | 说明 | 示例 |
183
- |------|------|------|
184
- | `--env` | 指定环境 | `--env prod-cn` |
185
- | `--tenant` | 指定租户 | `--tenant electionjp` |
186
- | `--service` | 指定服务 | `--service liberica` |
187
- | `--dry-run` | 预览模式 | `--dry-run` |
188
- | `--json` | JSON 输出 | `--json` |
189
- | `--help` | 显示帮助 | `--help` |
49
+ Barista CLI is designed for AI coding assistants. Every output is structured, every error is actionable.
190
50
 
191
- ### 上下文管理
51
+ ### Supported AI Tools
192
52
 
193
- 上下文管理用于快速切换工作环境,避免每个命令都指定环境参数。
53
+ | AI Tool | Integration Method | Status |
54
+ |---------|-------------------|--------|
55
+ | **Claude Code** | `$` backticks + `--json` | ✅ Verified |
56
+ | **OpenCode** | Shell command + JSON parse | ✅ Verified |
57
+ | **OpenClaw** | Shell command + JSON parse | ✅ Verified |
58
+ | **Cursor** | Terminal integration | ✅ Compatible |
59
+ | **Continue** | CLI subprocess | ✅ Compatible |
194
60
 
195
- ```bash
196
- # 查看当前上下文
197
- barista context show
198
-
199
- # 输出示例:
200
- # ┌─────────────┬─────────────────┐
201
- # │ 属性 │ 值 │
202
- # ├─────────────┼─────────────────┤
203
- # │ 当前环境 │ dev │
204
- # │ 当前租户 │ electionjp │
205
- # │ 当前服务 │ liberica │
206
- # │ Token 状态 │ 已登录 │
207
- # │ Token 过期 │ 2024-12-31 │
208
- # └─────────────┴─────────────────┘
209
-
210
- # 切换环境
211
- barista context use-env [dev|test|prod-cn|prod-jp]
212
-
213
- # 切换租户
214
- barista context use-tenant <tenant-name>
215
-
216
- # 切换默认服务
217
- barista context use-service [liberica|arabica]
218
- ```
219
-
220
- ### 认证管理
221
-
222
- Barista CLI 提供两种登录方式:
223
-
224
- #### 1. 凭证登录(推荐)
225
- 使用用户名和密码进行完整认证流程,自动获取并存储 Token:
226
-
227
- ```bash
228
- # Liberica 凭证登录
229
- barista liberica auth login <env> [tenant] [username] [password]
61
+ ### Integration Pattern
230
62
 
231
- # 示例:登录 Liberica 测试环境
232
- barista liberica auth login test electionjp admin@shanghai.newpeaksh.com 123456
233
-
234
- # 交互式登录(系统会提示输入缺失信息)
235
- barista liberica auth login
236
-
237
- # 登录后会自动设置当前环境上下文,后续命令无需指定 --env
238
- ```
239
-
240
- #### 2. Token 直接存储
241
- 适用于已有 JWT Token 的场景(如从其他渠道获取):
242
-
243
- ```bash
244
- # 直接存储 Token
245
- barista auth login --service <service> --env <env> [--tenant <tenant>]
246
-
247
- # 示例:存储 Liberica 开发环境 Token
248
- barista auth login --service liberica --env dev --tenant electionjp
249
- # 提示: Enter your token: [输入已有 Token]
250
-
251
- # 检查登录状态
252
- barista auth status
253
-
254
- # 输出示例:
255
- # ✓ Liberica (dev) - 已登录 (过期: 2024-12-31)
256
- # ✗ Liberica (test) - 未登录
257
- # ✓ Arabica (prod-cn) - 已登录 (过期: 2024-12-30)
258
-
259
- # 登出(清除 Token)
260
- barista auth logout --service <service> --env <env>
261
-
262
- # 登出所有环境
263
- barista auth logout --all
264
- ```
265
-
266
- **重要**:使用 `barista liberica auth login` 登录后,系统会自动设置当前环境上下文,后续命令无需指定 `--env` 参数。
267
-
268
- ### Liberica 命令
269
-
270
- #### 订单管理
271
-
272
- ```bash
273
- # 列出订单(分页)
274
- barista liberica orders list [--page <n>] [--size <n>] [--status <status>]
275
-
276
- # 获取单个订单详情
277
- barista liberica orders get <order-id>
278
-
279
- # 创建订单
280
- barista liberica orders create \
281
- --product-id <id> \
282
- --quantity <n> \
283
- [--delivery-date <date>] \
284
- [--note <text>]
285
-
286
- # 取消订单
287
- barista liberica orders cancel <order-id> [--reason <text>]
288
- ```
289
-
290
- #### 产品管理
63
+ ```typescript
64
+ // 1. Execute command with JSON output
65
+ const result = await $`barista liberica orders list \
66
+ --env prod-cn \
67
+ --tenant your-tenant \
68
+ --status pending \
69
+ --json \
70
+ --page 1 \
71
+ --size 50`
72
+
73
+ // 2. Parse structured response
74
+ const { success, data, meta } = JSON.parse(result.stdout)
75
+
76
+ if (!success) {
77
+ throw new Error(`API Error: ${meta.code || meta.error?.code} - ${meta.message || meta.error?.message}`)
78
+ }
291
79
 
292
- ```bash
293
- # 搜索产品
294
- barista liberica products search --keyword <keyword> [--category <id>]
80
+ // 3. Work with data
81
+ const pendingOrders = data.items
82
+ console.log(`Found ${data.pagination.total} pending orders`)
295
83
 
296
- # 获取产品详情
297
- barista liberica products get <product-id>
84
+ // 4. Execute operations safely
85
+ for (const order of pendingOrders) {
86
+ // Always dry-run first (AI safety)
87
+ const preview = await $`barista liberica orders cancel ${order.id} --dry-run`
298
88
 
299
- # 获取公开产品列表(无需认证)
300
- barista liberica products public-list [--category <id>] [--page <n>]
89
+ // Parse preview, verify, then execute with --force
90
+ // ...
91
+ }
301
92
  ```
302
93
 
303
- #### 生产计划
304
-
305
- ```bash
306
- # 查看生产排期
307
- barista liberica production schedule [--start-date <date>] [--end-date <date>]
94
+ ### Response Envelope
308
95
 
309
- # 重新排产
310
- barista liberica production reschedule <order-id> --new-date <date> [--dry-run]
96
+ All JSON responses follow this structure:
311
97
 
312
- # 查询产能
313
- barista liberica production capacity [--date <date>] [--line <line-id>]
314
- ```
315
-
316
- #### 仓库管理
317
-
318
- ```bash
319
- # 列出仓库(分页)
320
- barista liberica warehouses list [--page <n>] [--size <n>] [--status <status>] [--name <name>] [--code <code>]
321
-
322
- # 获取仓库详情
323
- barista liberica warehouses get <warehouse-id>
324
-
325
- # 创建仓库
326
- barista liberica warehouses create --code <code> --name <name> \
327
- [--type <type>] [--classes <classes>] [--address <address>] \
328
- [--contact <contact>] [--phone <phone>] [--manager <manager>] \
329
- [--enable-location] [--enable-negative-inventory] [--remark <remark>]
330
-
331
- # 更新仓库
332
- barista liberica warehouses update <warehouse-id> \
333
- [--name <name>] [--type <type>] [--classes <classes>] [--address <address>] \
334
- [--contact <contact>] [--phone <phone>] [--manager <manager>] \
335
- [--enable-location] [--disable-location] \
336
- [--enable-negative-inventory] [--disable-negative-inventory] \
337
- [--remark <remark>]
338
-
339
- # 删除仓库(默认 Dry-Run,需 --force 确认)
340
- barista liberica warehouses delete <warehouse-id> [--force]
341
-
342
- # 启用仓库
343
- barista liberica warehouses enable <warehouse-id> [--force] [--dry-run]
344
-
345
- # 禁用仓库
346
- barista liberica warehouses disable <warehouse-id> [--force] [--dry-run]
98
+ ```json
99
+ {
100
+ "success": true,
101
+ "data": {
102
+ "items": [...],
103
+ "pagination": { "page": 1, "size": 20, "total": 150 }
104
+ },
105
+ "meta": {
106
+ "requestId": "req-abc123",
107
+ "timestamp": "2024-01-15T10:30:00Z",
108
+ "environment": "prod-cn",
109
+ "tenant": "your-tenant"
110
+ }
111
+ }
347
112
  ```
348
113
 
349
- #### 库位管理
350
-
351
- ```bash
352
- # 列出库位(分页)
353
- barista liberica warehouses locations list --warehouse-id <id> \
354
- [--page <n>] [--size <n>] [--status <status>] [--name <name>] [--code <code>]
355
-
356
- # 获取库位详情
357
- barista liberica warehouses locations get <location-id>
114
+ **Error format:**
358
115
 
359
- # 创建库位
360
- barista liberica warehouses locations create --warehouse-id <id> --code <code> --name <name> \
361
- [--type <type>] [--capacity <capacity>] [--remark <remark>] [--status <status>]
362
-
363
- # 更新库位
364
- barista liberica warehouses locations update <location-id> \
365
- [--name <name>] [--type <type>] [--capacity <capacity>] [--remark <remark>] [--status <status>]
366
-
367
- # 删除库位(默认 Dry-Run,需 --force 确认)
368
- barista liberica warehouses locations delete <location-id> [--force]
369
-
370
- # 启用库位
371
- barista liberica warehouses locations enable <location-id> [--force] [--dry-run]
372
-
373
- # 禁用库位
374
- barista liberica warehouses locations disable <location-id> [--force] [--dry-run]
116
+ ```json
117
+ {
118
+ "success": false,
119
+ "error": {
120
+ "code": "A150001",
121
+ "message": "Order not found"
122
+ },
123
+ "meta": {
124
+ "requestId": "req-xyz789",
125
+ "timestamp": "2024-01-15T10:30:00Z"
126
+ }
127
+ }
375
128
  ```
376
129
 
377
- ### Arabica 命令(订阅管理 SaaS)
378
-
379
- > Arabica 命令实现完整的 SaaS 订阅流程管理,包括套餐浏览、订阅管理、订单处理、发票查看等。
380
-
381
- #### 认证管理
382
-
383
- ```bash
384
- # 登录 Arabica
385
- barista arabica auth login <account> <password>
386
-
387
- # 注册新会员
388
- barista arabica auth register --email <email> --account <account> --password <password>
389
-
390
- # 查看登录状态
391
- barista arabica auth status
392
-
393
- # 登出
394
- barista arabica auth logout
395
- ```
130
+ ### Skills for Claude Code
396
131
 
397
- #### 套餐浏览
132
+ Install reusable skill files:
398
133
 
399
134
  ```bash
400
- # 浏览可用套餐
401
- barista arabica plans list
402
-
403
- # 查看套餐详情
404
- barista arabica plans get <plan-id>
405
-
406
- # 对比两个套餐
407
- barista arabica plans compare <plan-a> <plan-b>
135
+ # Skills are located at ~/.barista/claude/skills/
136
+ barista skills install
408
137
  ```
409
138
 
410
- #### 订阅管理
411
-
412
- ```bash
413
- # 查看当前订阅
414
- barista arabica subscription current
139
+ **Available skills:**
140
+ - `orders.md` — Order management workflow
141
+ - `products.md` — Product search and sync
142
+ - `warehouses.md` — Inventory operations
143
+ - `subscriptions.md` — Arabica subscription management
415
144
 
416
- # 升级订阅
417
- barista arabica subscription upgrade <plan-id> [--seats <n>]
418
-
419
- # 降级订阅
420
- barista arabica subscription downgrade <plan-id>
421
-
422
- # 取消订阅
423
- barista arabica subscription cancel [--confirm]
424
- ```
425
-
426
- #### 订单管理
145
+ ---
427
146
 
428
- ```bash
429
- # 查看订单列表
430
- barista arabica orders list [--status pending|paid|cancelled|refunded]
147
+ ## 🚀 Features
431
148
 
432
- # 查看订单详情
433
- barista arabica orders get <order-id>
149
+ ### AI-First Design
434
150
 
435
- # 创建新订单
436
- barista arabica orders create <plan-id> [--seats <n>] [--period year|month]
151
+ | Feature | Description |
152
+ |---------|-------------|
153
+ | 🤖 **JSON-First Output** | All commands support `--json` for AI parsing |
154
+ | 📦 **Structured Responses** | Consistent `{success, data, meta}` envelope |
155
+ | 🔄 **Idempotent Operations** | Safe for AI retry loops |
156
+ | 🛡️ **Dry-Run by Default** | Destructive operations preview before execution |
157
+ | 🔐 **Secure Storage** | Credentials in system keychain, not env vars |
437
158
 
438
- # 取消订单
439
- barista arabica orders cancel <order-id>
440
- ```
159
+ ### Enterprise Connectivity
441
160
 
442
- #### 发票管理
161
+ | Service | Capabilities |
162
+ |---------|-------------|
163
+ | ☕ **Liberica** | Orders, products, inventory, warehouses, production planning |
164
+ | 🛒 **Arabica** | Subscription plans, billing, invoices, enterprise management |
165
+ | 🔗 **Cross-Service** | Quote from order, sync between systems |
443
166
 
444
- ```bash
445
- # 查看发票列表
446
- barista arabica invoices list [--year 2026]
167
+ ### Operational Safety
447
168
 
448
- # 查看发票详情
449
- barista arabica invoices get <invoice-id>
169
+ - 📊 **Audit Trail** — Every operation logged with request ID
170
+ - ⚠️ **Confirmation Guards** — `--dry-run` / `--force` for write operations
171
+ - 🏢 **Multi-Tenant Isolation** — Credentials isolated per tenant
450
172
 
451
- # 下载发票 PDF
452
- barista arabica invoices download <invoice-id> [--output <path>]
453
- ```
173
+ ---
454
174
 
455
- #### 用量查看
175
+ ## 🔧 Command Reference
456
176
 
457
- ```bash
458
- # 查看当前用量
459
- barista arabica usage current
177
+ ### Core Pattern
460
178
 
461
- # 查看用量历史
462
- barista arabica usage history [--period 30d|90d|1y]
463
179
  ```
464
-
465
- #### 企业管理
466
-
467
- ```bash
468
- # 查看企业列表
469
- barista arabica enterprise list
470
-
471
- # 查看席位使用
472
- barista arabica enterprise seats
473
-
474
- # 增加席位
475
- barista arabica enterprise seats add <n>
476
-
477
- # 查看/邀请企业成员
478
- barista arabica enterprise members list
479
- barista arabica enterprise members invite <email>
180
+ barista <service> <resource> <action> [options]
480
181
  ```
481
182
 
482
- #### 访问 Liberica
183
+ ### Global Options
483
184
 
484
- ```bash
485
- # 获取 Liberica 访问地址
486
- barista arabica access url
487
- ```
185
+ | Option | Description | Default |
186
+ |--------|-------------|---------|
187
+ | `--env` | Environment (dev\|test\|prod-cn\|prod-jp) | `dev` |
188
+ | `--tenant` | Tenant name | - |
189
+ | `--json` | JSON output | `false` |
190
+ | `--dry-run` | Preview mode (recommended for AI) | `false` |
191
+ | `--force` | Skip confirmation | `false` |
192
+ | `--page` | Page number | `1` |
193
+ | `--size` | Page size (max items) | `20` |
488
194
 
489
- ### 跨服务命令
195
+ ### Quick Reference
490
196
 
491
- 跨服务命令实现 Liberica Arabica 之间的数据同步和业务流程衔接。
197
+ | Command | Description |
198
+ |---------|-------------|
199
+ | `barista context show` | Show current env/tenant context |
200
+ | `barista context use-env <env>` | Switch environment |
201
+ | `barista liberica orders list --json` | List orders (AI format) |
202
+ | `barista liberica orders get <id> --json` | Get order detail |
203
+ | `barista liberica orders create --dry-run ...` | Preview create |
204
+ | `barista liberica products search --keyword <kw> --json` | Search products |
205
+ | `barista arabica plans list --json` | List subscription plans |
206
+ | `barista arabica invoices list --json` | List invoices |
492
207
 
493
- ```bash
494
- # 从订单生成报价单
495
- barista cross quote-from-order <order-id> [--target-service arabica]
496
-
497
- # 输出示例:
498
- # ✓ 已生成报价单
499
- # ┌──────────┬────────────┐
500
- # │ 属性 │ 值 │
501
- # ├──────────┼────────────┤
502
- # │ 订单ID │ 12345 │
503
- # │ 报价单ID │ QT-2024-001│
504
- # │ 金额 │ ¥50,000 │
505
- # │ 有效期 │ 30天 │
506
- # └──────────┴────────────┘
507
-
508
- # 同步订单状态到 Arabica
509
- barista cross sync-order <order-id> [--direction liberica-to-arabica]
510
- ```
208
+ **[→ Full Command Reference](./docs/commands/REFERENCE.md)**
511
209
 
512
210
  ---
513
211
 
514
- ## 高级特性
212
+ ## 🛡️ AI Safety Guidelines
515
213
 
516
- ### Dry-Run 模式
214
+ ### 1. Always Dry-Run First
517
215
 
518
- Dry-Run 模式允许你在执行写入操作前预览其影响,避免误操作。
216
+ ```typescript
217
+ // ❌ Wrong - executing blindly
218
+ await $`barista liberica orders cancel 12345`
519
219
 
520
- ```bash
521
- # 所有写入操作都支持 --dry-run 选项
522
- barista liberica orders create --product-id 123 --quantity 100 --dry-run
523
-
524
- # 输出示例:
525
- # 🔍 Dry-Run 模式:操作不会被实际执行
526
- # ┌─────────────────┬──────────────────────┐
527
- # │ 操作 │ 创建订单 │
528
- # ├─────────────────┼──────────────────────┤
529
- # │ 产品 │ 咖啡机 Pro (ID: 123) │
530
- # │ 数量 │ 100 │
531
- # │ 预计金额 │ ¥50,000 │
532
- # │ 预计交期 │ 2024-12-31 │
533
- # │ 影响 │ 新增一条订单记录 │
534
- # └─────────────────┴──────────────────────┘
535
- #
536
- # ⚠️ 确认执行?添加 --confirm 选项或移除 --dry-run
220
+ // ✅ Correct - preview first
221
+ const preview = await $`barista liberica orders cancel 12345 --dry-run`
222
+ // Parse preview, verify correctness, then:
223
+ await $`barista liberica orders cancel 12345 --force`
537
224
  ```
538
225
 
539
- **默认 Dry-Run 的操作:**
540
-
541
- 以下破坏性操作默认启用 Dry-Run 模式,需显式确认:
542
-
543
- - 取消订单
544
- - 删除产品
545
- - 批量更新
226
+ ### 2. Check Success Before Proceeding
546
227
 
547
- ### JSON 输出格式
548
-
549
- Barista CLI 支持 JSON 输出,便于脚本处理和 AI 集成:
550
-
551
- ```bash
552
- barista liberica orders list --json
553
-
554
- # 输出示例:
555
- {
556
- "success": true,
557
- "data": {
558
- "items": [
559
- {
560
- "id": "12345",
561
- "productName": "咖啡机 Pro",
562
- "quantity": 100,
563
- "status": "in_production",
564
- "createdAt": "2024-01-15T10:30:00Z"
565
- }
566
- ],
567
- "pagination": {
568
- "page": 1,
569
- "size": 20,
570
- "total": 150
571
- }
572
- }
228
+ ```typescript
229
+ const result = JSON.parse(stdout)
230
+ if (!result.success) {
231
+ // Handle error, don't continue
232
+ throw new Error(result.error?.message || result.meta?.message)
573
233
  }
574
234
  ```
575
235
 
576
- ### CSV 导出格式
577
-
578
- Barista CLI 支持 CSV 格式导出,适用于数据分析及 Excel 处理:
236
+ ### 3. Use Request IDs for Debugging
579
237
 
580
- ```bash
581
- # 导出字典类型数据为 CSV
582
- barista liberica dict-types tenant-items --lang ja --all --csv --output ./dict-data.csv
583
-
584
- # 输出特性:
585
- # • UTF-8 with BOM 编码,确保 Excel 正确识别中文
586
- # • 自动转义特殊字符(逗号、引号、换行符)
587
- # • 支持自定义输出文件路径
588
- # • 可配合 --json 同时输出两种格式
238
+ ```typescript
239
+ const { meta } = JSON.parse(stdout)
240
+ console.log(`Request ID: ${meta.requestId}`)
589
241
  ```
590
242
 
591
- CSV 文件采用 UTF-8 with BOM 编码,确保在 Microsoft Excel 等工具中正确显示中、日、越等 Unicode 字符。
243
+ ### 4. Respect Rate Limits
244
+
245
+ - Add delays between bulk operations
246
+ - Use `--size 100` for bulk fetches
247
+ - Cache responses when appropriate
592
248
 
593
249
  ---
594
250
 
595
- ## 配置说明
251
+ ## ⚙️ Configuration
596
252
 
597
- ### 配置文件
253
+ ### File Location
598
254
 
599
- 配置文件位于 `~/.barista/config.yaml`:
255
+ `~/.barista/config.yaml`
600
256
 
601
- ```yaml
602
- # Barista CLI 配置文件
257
+ ### Quick Config
603
258
 
604
- # 默认上下文设置
259
+ ```yaml
605
260
  defaults:
606
- env: dev
607
- tenant: electionjp
261
+ env: prod-cn
262
+ tenant: your-tenant
608
263
  service: liberica
609
264
 
610
- # 环境配置
611
265
  environments:
612
- dev:
613
- liberica:
614
- baseUrl: "https://{tenant}-dev.newpeaksh.com"
615
- timeout: 30000
616
- arabica:
617
- baseUrl: "https://arabica-dev.newpeaksh.com"
618
- timeout: 30000
619
-
620
- test:
621
- liberica:
622
- baseUrl: "https://{tenant}-test.newpeaksh.com"
623
- timeout: 30000
624
- arabica:
625
- baseUrl: "https://arabica-test.newpeaksh.com"
626
- timeout: 30000
627
-
628
266
  prod-cn:
629
267
  liberica:
630
268
  baseUrl: "https://{tenant}.newpeaksh.com"
@@ -632,258 +270,71 @@ environments:
632
270
  arabica:
633
271
  baseUrl: "https://www.newpeaksh.com"
634
272
  timeout: 60000
635
-
636
- prod-jp:
637
- liberica:
638
- baseUrl: "https://{tenant}.newpeakjp.com"
639
- timeout: 60000
640
- arabica:
641
- baseUrl: "https://members.newpeakjp.com"
642
- timeout: 60000
643
-
644
- # 输出配置
645
- output:
646
- format: table # table | json
647
- color: true
648
- timestamp: true
649
273
  ```
650
274
 
651
- ### 多租户配置
652
-
653
- 支持配置多个租户,快速切换:
275
+ ### Authentication
654
276
 
655
277
  ```bash
656
- # 添加租户配置
657
- barista config add-tenant \
658
- --name customer-a \
659
- --liberica-id customer-a-id \
660
- --arabica-id customer-a-arabica-id
278
+ # Credential login (recommended)
279
+ barista liberica auth login <env> <tenant> <username> <password>
661
280
 
662
- # 列出已配置租户
663
- barista config list-tenants
281
+ # Check auth status
282
+ barista auth status
664
283
 
665
- # 快速切换租户
666
- barista context use-tenant customer-a
284
+ # Logout
285
+ barista auth logout --service liberica --env prod-cn
667
286
  ```
668
287
 
669
288
  ---
670
289
 
671
- ## AI 集成
672
-
673
- Barista CLI 专为 AI 编程助手优化,特别是 Claude Code。
674
-
675
- ### Claude Code 使用示例
676
-
677
- ```typescript
678
- // 在 Claude Code 中使用 Barista CLI
679
- // 示例:获取订单列表并分析
680
-
681
- const result = await $`barista liberica orders list --json --page 1 --size 10`;
682
- const orders = JSON.parse(result.stdout);
683
-
684
- // 分析订单数据
685
- const analysis = orders.data.items.map(order => ({
686
- id: order.id,
687
- status: order.status,
688
- amount: order.amount
689
- }));
690
- ```
691
-
692
- ### Skills 文件
693
-
694
- Barista CLI 提供 Claude Code Skills 文件,位于:
695
-
696
- ```
697
- ~/.barista/claude/skills/
698
- ├── orders.md # 订单管理技能
699
- ├── products.md # 产品管理技能
700
- ├── quotes.md # 报价管理技能
701
- └── customers.md # 客户管理技能
702
- ```
703
-
704
- **示例 Skills 文件:**
705
-
706
- ```markdown
707
- # 订单管理技能
708
-
709
- ## 列出待处理订单
710
-
711
- 当用户询问待处理订单时:
290
+ ## Troubleshooting
712
291
 
713
- 1. 执行命令:barista liberica orders list --status pending --json
714
- 2. 解析返回的 JSON
715
- 3. 总结订单数量和总金额
716
- 4. 列出前 5 个订单的关键信息
717
-
718
- ## 创建新订单
719
-
720
- 当用户需要创建订单时:
721
-
722
- 1. 确认产品 ID 和数量
723
- 2. 使用 dry-run 预览:barista liberica orders create --dry-run ...
724
- 3. 用户确认后执行实际命令
725
- ```
726
-
727
- ### AI 友好的输出
728
-
729
- 所有命令都支持 `--json` 选项,返回结构化的 JSON 数据:
292
+ ### Auth Failures
730
293
 
731
294
  ```bash
732
- # 查询带结构化输出
733
- barista liberica orders get 12345 --json
734
-
735
- {
736
- "success": true,
737
- "data": {
738
- "id": "12345",
739
- "status": "in_production",
740
- "product": {
741
- "id": "100",
742
- "name": "咖啡机 Pro"
743
- },
744
- "quantity": 100,
745
- "amount": 50000,
746
- "timeline": {
747
- "created": "2024-01-15T10:30:00Z",
748
- "delivery": "2024-02-15"
749
- }
750
- },
751
- "meta": {
752
- "requestId": "req-abc123",
753
- "timestamp": "2024-01-15T10:30:00Z"
754
- }
755
- }
756
- ```
757
-
758
- ---
759
-
760
- ## 开发指南
295
+ # Check current status
296
+ barista auth status
761
297
 
762
- ### 项目结构
298
+ # Re-authenticate
299
+ barista liberica auth login prod-cn your-tenant your-username your-password
763
300
 
764
- ```
765
- coffee-barista-cli/
766
- ├── bin/
767
- │ └── barista.js # 入口文件
768
- ├── src/
769
- │ ├── commands/ # 命令实现
770
- │ │ ├── context/ # 上下文管理命令
771
- │ │ ├── auth/ # 认证命令
772
- │ │ ├── liberica/ # Liberica 服务命令
773
- │ │ │ ├── orders.js
774
- │ │ │ ├── products.js
775
- │ │ │ └── production.js
776
- │ │ ├── arabica/ # Arabica 服务命令
777
- │ │ │ ├── products.js
778
- │ │ │ ├── quotes.js
779
- │ │ │ └── customers.js
780
- │ │ └── cross/ # 跨服务命令
781
- │ ├── core/ # 核心模块
782
- │ │ ├── auth.js # 认证管理
783
- │ │ ├── config.js # 配置管理
784
- │ │ ├── context.js # 上下文管理
785
- │ │ └── api-client.js # API 客户端
786
- │ ├── utils/ # 工具函数
787
- │ │ ├── formatter.js # 输出格式化
788
- │ │ ├── validator.js # 参数验证
789
- │ │ └── keychain.js # 密钥链操作
790
- │ └── templates/ # 模板文件
791
- ├── skills/ # Claude Code Skills
792
- ├── tests/ # 测试文件
793
- ├── package.json
794
- └── README.md
301
+ # Check context
302
+ barista context show
795
303
  ```
796
304
 
797
- ### 本地开发
305
+ ### API Errors
798
306
 
799
307
  ```bash
800
- # 1. 克隆仓库
801
- git clone https://gitlab.newpeaksh.com/coffee/coffee-barista-cli.git
802
- cd coffee-barista-cli
803
-
804
- # 2. 安装依赖
805
- npm install
806
-
807
- # 3. 链接到全局(开发模式)
808
- npm link
809
-
810
- # 4. 验证链接
811
- barista --version
812
-
813
- # 5. 运行测试
814
- npm test
308
+ # Always use --json to get error codes
309
+ barista liberica orders list --json
815
310
 
816
- # 6. 代码检查
817
- npm run lint
311
+ # Error response includes requestId for debugging
312
+ # "requestId": "req-abc123"
818
313
  ```
819
314
 
820
- ### 添加新命令
821
-
822
- **重要**:新增命令必须遵循 [命令设计规范](./docs/COMMAND_DESIGN_SPEC.md),包含设计文档编写、技术评审等完整流程。
823
-
824
- 详细步骤请参考:
825
- - [完整命令参考](./docs/commands/REFERENCE.md) - 所有命令清单和开发优先级
826
- - [命令设计规范文档](./docs/COMMAND_DESIGN_SPEC.md#5-命令开发流程规范)
827
- - [命令开发指南](./docs/COMMANDS.md)
828
-
829
- ---
830
-
831
- ## 贡献指南
832
-
833
- 我们欢迎所有形式的贡献,包括但不限于:
834
-
835
- - 🐛 报告 Bug
836
- - 💡 提出新功能建议
837
- - 📝 改进文档
838
- - 🔧 提交代码修复
839
- - ✨ 添加新功能
840
-
841
- ### 提交规范
842
-
843
- 请遵循 [Conventional Commits](https://www.conventionalcommits.org/) 规范:
315
+ ### Timeout Issues
844
316
 
845
317
  ```bash
846
- # 修复 Bug
847
- fix: 修复订单列表分页问题
318
+ # Switch to closer environment
319
+ barista context use-env dev
848
320
 
849
- # 添加功能
850
- feat: 添加库存查询命令
851
-
852
- # 文档更新
853
- docs: 更新 README 中的环境映射
854
-
855
- # 代码重构
856
- refactor: 重构 API 客户端错误处理
321
+ # Or adjust timeout in config.yaml
857
322
  ```
858
323
 
859
- ### 开发流程
860
-
861
- 1. Fork 本仓库
862
- 2. 创建功能分支:`git checkout -b feature/my-feature`
863
- 3. 提交更改:`git commit -m 'feat: add some feature'`
864
- 4. 推送分支:`git push origin feature/my-feature`
865
- 5. 创建 Pull Request
866
-
867
324
  ---
868
325
 
869
- ## 相关项目
326
+ ## 📚 Related Projects
870
327
 
871
- | 项目 | 描述 | 链接 |
872
- |------|------|------|
873
- | ☕ Liberica Backend | 生产管理 SaaS 后端 | [coffee-liberica-end](https://gitlab.newpeaksh.com/coffee/coffee-liberica-end) |
874
- | 🖥️ Liberica Frontend | 生产管理 Web 前端 | [coffee-liberica-front](https://gitlab.newpeaksh.com/coffee/coffee-liberica-front) |
875
- | 📱 Liberica Mobile | 生产管理移动端 | [coffee-liberica-mobile-front](https://gitlab.newpeaksh.com/coffee/coffee-liberica-mobile-front) |
876
- | 🛒 Arabica Backend | 在线订阅 SaaS 服务后端 | [coffee-arabica-end](https://gitlab.newpeaksh.com/coffee/coffee-arabica-end) |
877
- | 🌐 Arabica Frontend | 在线订阅 SaaS 服务前端 | [coffee-arabica-front](https://gitlab.newpeaksh.com/coffee/coffee-arabica-front) |
328
+ | Project | Description |
329
+ |---------|-------------|
330
+ | ☕ Liberica Backend | Production management SaaS backend |
331
+ | 🖥️ Liberica Frontend | Production management web UI |
332
+ | 📱 Liberica Mobile | Production management mobile app |
333
+ | 🛒 Arabica Backend | Online subscription SaaS backend |
334
+ | 🌐 Arabica Frontend | Online subscription web UI |
878
335
 
879
336
  ---
880
337
 
881
- ## 许可证
338
+ ## 📄 License
882
339
 
883
340
  [MIT](LICENSE) © Newpeak Technology
884
-
885
- ---
886
-
887
- <p align="center">
888
- 用 ☕ 驱动生产力
889
- </p>