meegle-cli 0.1.0 → 0.1.1

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 (2) hide show
  1. package/README.md +331 -116
  2. package/package.json +2 -2
package/README.md CHANGED
@@ -1,215 +1,430 @@
1
- # meegle-cli (plugin-only)
1
+ # meegle-cli
2
2
 
3
- 基于 `project-oapi-sdk-typescript` 的命令行工具。
4
- 当前模式:仅支持 `plugin_access_token / virtual_plugin_token`,不支持 `user_access_token`。
3
+ 面向飞书项目(Meegle)的命令行工具。
4
+ 当前版本运行在 `plugin-only` 模式:只支持 `plugin_access_token / virtual_plugin_token`,不支持 `user_access_token`。
5
5
 
6
- ## 安装
6
+ ## 适用对象
7
+
8
+ - 想在终端里查询空间、工作项、视图、评论、子任务
9
+ - 想把 Meegle 调用接到脚本、Agent、CI 里
10
+ - 已经有插件凭证:`pluginId / pluginSecret`
11
+
12
+ 不适用场景:
7
13
 
8
- 对外用户安装:
14
+ - 需要 `user_access_token` 的接口
15
+ - 需要在 CLI 内做浏览器登录换 user token
16
+
17
+ ## 安装
9
18
 
10
19
  ```bash
11
20
  npm install -g meegle-cli
12
21
  meegle --help
13
22
  ```
14
23
 
15
- 仓库内开发安装:
24
+ 如果安装后提示 `meegle: command not found`,先确认 npm 全局 bin 在 PATH 里:
16
25
 
17
26
  ```bash
18
- cd /Users/linmi/conductor/repos/meego-client/meegle-cli
19
- npm install
27
+ npm bin -g
20
28
  ```
21
29
 
22
- ## 构建
30
+ ## 你需要准备什么
23
31
 
24
- ```bash
25
- npm run build
26
- ```
32
+ 最少准备这几项:
33
+
34
+ - `pluginId`
35
+ - `pluginSecret`
36
+ - `userKey`
37
+ - `projectKey`
38
+
39
+ 可选:
27
40
 
28
- ## 发布
41
+ - `baseURL`
42
+ - 默认就是 `https://project.feishu.cn`
29
43
 
30
- 发布说明见 [RELEASE.md](/Users/linmi/conductor/repos/meego-client/meegle-cli/RELEASE.md)。
44
+ ## 3 分钟上手
31
45
 
32
- ## 初始化
46
+ ### 1. 初始化一个 profile
33
47
 
34
48
  ```bash
35
- node dist/index.js auth init \
49
+ meegle auth init \
36
50
  --target-profile default \
37
- --plugin-id MII_xxx \
38
- --plugin-secret xxx \
39
- --base-url https://project.feishu.cn \
40
- --token-type 0 \
41
- --default-user-key 123456
51
+ --plugin-id <PLUGIN_ID> \
52
+ --plugin-secret <PLUGIN_SECRET> \
53
+ --default-user-key <USER_KEY>
42
54
  ```
43
55
 
44
- 也可以先放环境变量,再直接初始化:
56
+ 也可以先放环境变量,再执行初始化:
45
57
 
46
58
  ```bash
47
- export MEEGLE_PLUGIN_ID=MII_xxx
48
- export MEEGLE_PLUGIN_SECRET=xxx
49
- export MEEGLE_USER_KEY=123456
59
+ export MEEGLE_PLUGIN_ID=<PLUGIN_ID>
60
+ export MEEGLE_PLUGIN_SECRET=<PLUGIN_SECRET>
61
+ export MEEGLE_USER_KEY=<USER_KEY>
50
62
 
51
- node dist/index.js auth init --target-profile default
63
+ meegle auth init --target-profile default
52
64
  ```
53
65
 
54
- ## 入参约定
66
+ ### 2. 校验凭证
55
67
 
56
- - 常用查询优先走直接参数,不再强制写 JSON 文件
57
- - 常用写操作也优先走直接参数,例如 `--name`、`--desc`、`--content`
58
- - 复杂请求体仍可使用 `--body <json>` 或 `--body-file <path>`
59
- - 复杂查询参数仍可使用 `--query-file <path>`
60
- - 大多数命令要求 `userKey`:`--user-key` 或 `auth init --default-user-key`
61
- - 如果 profile 里没存 `defaultUserKey`,运行时也会读取 `MEEGLE_USER_KEY`
62
- - 自定义字段统一使用 `--field field_key=value`;对象/数组值直接传 JSON
63
- - 排期参数统一支持 `--start/--end`,可传毫秒时间戳或可解析日期,如 `2025-01-01`
68
+ ```bash
69
+ meegle --profile default auth status --json
70
+ ```
64
71
 
65
- ## 命令总览
72
+ 成功时会返回:
66
73
 
67
- - `auth`: `init`, `status`
68
- - `space`: `list`, `get`, `types`, `team-members`
69
- - `workitem`: `get`, `meta`, `create`, `update`, `remove`, `freeze`, `unfreeze`, `abort`, `restore`, `op-records`, `update-compound`
70
- - `workitem search`: `filter`, `filter-across`, `by-params`, `by-relation`, `compositive`, `universal`
71
- - `workflow`: `query`, `state-change`, `node-operate`, `node-update`, `required-info`, `wbs`
72
- - `comment`: `list`, `add`, `update`, `remove`
73
- - `subtask`: `list`, `search`, `create`, `update`, `remove`, `operate`
74
- - `attachment`: `upload-file`, `upload`, `download`, `delete`
75
- - `workhour`: `list`, `create`, `update`, `delete`
76
- - `view`: `list`, `fix-items`, `panoramic-items`, `create-fix`, `update-fix`, `delete`, `create-condition`, `update-condition`
77
- - `measure`: `charts`, `chart-data`
78
- - `tenant`: `info`, `entitlement`, `spaces`
79
- - `user`: `query`, `search`(会被拒绝)
80
- - `user group`: `create`, `update-members`, `query-members`(会被拒绝)
74
+ - `profile`
75
+ - `baseURL`
76
+ - `tokenType`
77
+ - `tokenPreview`
78
+ - `ok: true`
79
+
80
+ ### 3. 列出你能看到的空间
81
81
 
82
- ## 真实环境 Smoke(可选)
82
+ ```bash
83
+ meegle --profile default space list --json
84
+ ```
83
85
 
84
- 执行:
86
+ ### 4. 查询自己
85
87
 
86
88
  ```bash
87
- npm run test:smoke:real
89
+ meegle --profile default user query --self --json
88
90
  ```
89
91
 
90
- 必填环境变量:
92
+ ## 核心概念
91
93
 
92
- - `MEEGLE_SMOKE_PLUGIN_ID`
93
- - `MEEGLE_SMOKE_PLUGIN_SECRET`
94
- - `MEEGLE_SMOKE_USER_KEY`
95
- - `MEEGLE_SMOKE_PROJECT_KEY`
94
+ ### profile
96
95
 
97
- 可选环境变量:
96
+ 一套 CLI 配置,通常对应一套环境或一组凭证。
98
97
 
99
- - `MEEGLE_SMOKE_BASE_URL`(默认 `https://project.feishu.cn`)
100
- - `MEEGLE_SMOKE_WORK_ITEM_TYPE_KEY`(不填时自动取 `space types` 第一项)
101
- - `MEEGLE_SMOKE_WORK_ITEM_ID`(填了会额外做 `workitem get`)
98
+ 例如:
102
99
 
103
- 测试链路:
100
+ - `default`
101
+ - `test`
102
+ - `prod`
104
103
 
105
- - `auth init -> auth status -> space list -> space get -> user query --self -> space types -> workitem meta`
106
- - 若提供 `MEEGLE_SMOKE_WORK_ITEM_ID`,再执行 `workitem get`
107
- - 最后验证 user-only 接口在 plugin-only 下被拒绝
104
+ 切换方式:
108
105
 
109
- `MEEGLE_SMOKE_USER_KEY` 获取建议:
106
+ ```bash
107
+ meegle --profile prod space list
108
+ ```
110
109
 
111
- - 文档建议可在飞书项目空间双击头像获取 `user_key`
112
- - 如果你在插件前端里调试,JS SDK 文档里有 `window.JSSDK.utils.getAuthCode()`;虽然该方法用于 user token 流程,但同一套文档章节也包含用户身份相关取值指引
110
+ ### userKey
113
111
 
114
- ## plugin-only 拒绝列表(denylist)
112
+ `plugin-only` 模式下,大多数命令都需要 `userKey`。
115
113
 
116
- - `POST /open_api/user/search`
117
- - `POST /open_api/:project_key/user_group`
118
- - `PATCH /open_api/:project_key/user_group/members`
119
- - `POST /open_api/:project_key/user_groups/members/page`
114
+ 来源优先级:
120
115
 
121
- ## 示例
116
+ 1. 命令行 `--user-key`
117
+ 2. profile 里的 `defaultUserKey`
118
+ 3. 环境变量 `MEEGLE_USER_KEY`
122
119
 
123
- ```bash
124
- # 1) 校验凭证
125
- node dist/index.js --profile default auth status --json
120
+ ### projectKey
126
121
 
127
- # 2) 列出空间
128
- node dist/index.js --profile default space list --json
122
+ 空间 ID,通常就是接口里的 `project_key`。
123
+ 很多命令也支持空间域名 `simple_name`,例如 `69zyer`。
129
124
 
130
- # 3) 获取空间详情
131
- node dist/index.js --profile default space get \
132
- --project-key your_project \
125
+ ## 常见任务
126
+
127
+ ### 查空间详情
128
+
129
+ ```bash
130
+ meegle --profile default space get \
131
+ --project-key <PROJECT_KEY> \
133
132
  --json
133
+ ```
134
134
 
135
- # 4) 查询当前 userKey 对应的用户
136
- node dist/index.js --profile default user query \
137
- --self \
135
+ ### 查工作项
136
+
137
+ 查单个工作项:
138
+
139
+ ```bash
140
+ meegle --profile default workitem get \
141
+ --project-key <PROJECT_KEY> \
142
+ --type story \
143
+ --id 6300034462 \
138
144
  --json
145
+ ```
146
+
147
+ 只取部分字段:
139
148
 
140
- # 5) 查询工作项,常见场景直接传 ID
141
- node dist/index.js --profile default workitem get \
142
- --project-key your_project \
149
+ ```bash
150
+ meegle --profile default workitem get \
151
+ --project-key <PROJECT_KEY> \
143
152
  --type story \
144
153
  --id 6300034462 \
154
+ --fields name,priority,owner,description \
145
155
  --json
156
+ ```
157
+
158
+ ### 创建工作项
146
159
 
147
- # 6) 创建工作项,常见字段直接写
148
- node dist/index.js --profile default workitem create \
149
- --project-key your_project \
160
+ ```bash
161
+ meegle --profile default workitem create \
162
+ --project-key <PROJECT_KEY> \
150
163
  --type story \
151
164
  --name "登录优化" \
152
165
  --desc "补齐错误提示" \
153
- --owner your_user_key \
166
+ --owner <USER_KEY> \
154
167
  --priority P2 \
155
168
  --json
169
+ ```
170
+
171
+ ### 更新工作项
156
172
 
157
- # 7) 更新工作项,改单个字段不需要写 update_fields
158
- node dist/index.js --profile default workitem update \
159
- --project-key your_project \
173
+ ```bash
174
+ meegle --profile default workitem update \
175
+ --project-key <PROJECT_KEY> \
160
176
  --type story \
161
177
  --id 6300034462 \
162
178
  --name "登录优化(已排期)" \
163
179
  --json
180
+ ```
164
181
 
165
- # 8) 添加评论,支持直接写文本或从文件读
166
- node dist/index.js --profile default comment add \
167
- --project-key your_project \
182
+ ### 添加评论
183
+
184
+ ```bash
185
+ meegle --profile default comment add \
186
+ --project-key <PROJECT_KEY> \
168
187
  --type story \
169
188
  --id 6300034462 \
170
189
  --content "收到,开始处理" \
171
190
  --json
191
+ ```
192
+
193
+ 如果评论内容很长,改用文件:
172
194
 
173
- # 9) 创建子任务
174
- node dist/index.js --profile default subtask create \
175
- --project-key your_project \
195
+ ```bash
196
+ meegle --profile default comment add \
197
+ --project-key <PROJECT_KEY> \
198
+ --type story \
199
+ --id 6300034462 \
200
+ --content-file ./comment.txt \
201
+ --json
202
+ ```
203
+
204
+ ### 创建子任务
205
+
206
+ ```bash
207
+ meegle --profile default subtask create \
208
+ --project-key <PROJECT_KEY> \
176
209
  --type story \
177
210
  --id 6300034462 \
178
211
  --node-id doing \
179
212
  --name "需求分析" \
180
213
  --note "补齐边界条件" \
181
- --assignee your_user_key \
214
+ --assignee <USER_KEY> \
182
215
  --points 3 \
183
216
  --start 2025-01-01 \
184
217
  --end 2025-01-02 \
185
218
  --json
219
+ ```
186
220
 
187
- # 10) 状态流转
188
- node dist/index.js --profile default workflow state-change \
189
- --project-key your_project \
221
+ ### 状态流转
222
+
223
+ ```bash
224
+ meegle --profile default workflow state-change \
225
+ --project-key <PROJECT_KEY> \
190
226
  --type story \
191
227
  --id 6300034462 \
192
228
  --transition-id 12345 \
193
229
  --field description="流转补充说明" \
194
230
  --json
231
+ ```
195
232
 
196
- # 11) 节点完成/回滚
197
- node dist/index.js --profile default workflow node-operate \
198
- --project-key your_project \
233
+ ### 节点完成 / 回滚
234
+
235
+ ```bash
236
+ meegle --profile default workflow node-operate \
237
+ --project-key <PROJECT_KEY> \
199
238
  --type story \
200
239
  --id 6300034462 \
201
240
  --node-id dev \
202
241
  --action rollback \
203
242
  --rollback-reason "需要返工" \
204
243
  --json
244
+ ```
205
245
 
206
- # 12) 复杂场景再回退到原始请求体
207
- node dist/index.js --profile default workitem get \
208
- --project-key your_project \
209
- --type story \
210
- --body '{"work_item_ids":[6300034462],"fields":["name","priority"]}' \
246
+ ## 视图使用
247
+
248
+ ### 先查视图配置,再决定调哪个接口
249
+
250
+ 固定视图和全景视图不是一个接口。
251
+ 先查 `view_type`,再调后续命令,别从 URL 结构直接猜。
252
+
253
+ 查指定视图:
254
+
255
+ ```bash
256
+ cat > /tmp/view-list.json <<'JSON'
257
+ {
258
+ "work_item_type_key": "story",
259
+ "view_ids": ["sypbi-z60"],
260
+ "is_query_quick_filter": true,
261
+ "page_size": 10,
262
+ "page_num": 1
263
+ }
264
+ JSON
265
+
266
+ meegle --profile default view list \
267
+ --project-key 69zyer \
268
+ --body-file /tmp/view-list.json \
211
269
  --json
270
+ ```
271
+
272
+ 返回中重点看:
212
273
 
213
- # 13) user-only 接口会被直接拒绝
214
- node dist/index.js user search --query test
274
+ - `view_id`
275
+ - `name`
276
+ - `view_type`
277
+ - `1` = 条件视图
278
+ - `2` = 固定视图
279
+
280
+ ### 固定视图
281
+
282
+ 固定视图用:
283
+
284
+ ```bash
285
+ cat > /tmp/fix.json <<'JSON'
286
+ {
287
+ "page_size": 50,
288
+ "page_num": 1
289
+ }
290
+ JSON
291
+
292
+ meegle --profile default view fix-items \
293
+ --project-key 69zyer \
294
+ --view-id sypbi-z60 \
295
+ --query-file /tmp/fix.json \
296
+ --json
215
297
  ```
298
+
299
+ ### 全景视图
300
+
301
+ 全景视图用:
302
+
303
+ ```bash
304
+ cat > /tmp/panoramic.json <<'JSON'
305
+ {
306
+ "page_size": 50,
307
+ "page_num": 1
308
+ }
309
+ JSON
310
+
311
+ meegle --profile default view panoramic-items \
312
+ --project-key 69zyer \
313
+ --view-id <VIEW_ID> \
314
+ --body-file /tmp/panoramic.json \
315
+ --json
316
+ ```
317
+
318
+ ### PMO 视角的正确用法
319
+
320
+ 如果你要做 PMO 基线分析,推荐链路是:
321
+
322
+ 1. `view list` 确认视图类型
323
+ 2. `view fix-items` 或 `view panoramic-items` 拉视图内工作项 ID
324
+ 3. `workitem get --ids ... --fields ...` 拉详情字段
325
+ 4. 再在脚本里统计:
326
+ - 状态分布
327
+ - 负责人分布
328
+ - 优先级分布
329
+ - 到期时间完整度
330
+ - 超期 / 逾期 / 老化
331
+
332
+ 不要直接拿整个空间总池代替“这个视图”的口径。
333
+
334
+ ## 参数约定
335
+
336
+ - 常用查询优先走直接参数,不强制写 JSON 文件
337
+ - 常用写操作优先走直接参数,例如 `--name`、`--desc`、`--content`
338
+ - 复杂请求体可使用 `--body <json>` 或 `--body-file <path>`
339
+ - 复杂查询参数可使用 `--query-file <path>`
340
+ - 自定义字段统一使用 `--field field_key=value`
341
+ - 对象 / 数组值直接传 JSON
342
+ - 排期参数统一支持 `--start/--end`
343
+ - 可传毫秒时间戳
344
+ - 也可传可解析日期,例如 `2025-01-01`
345
+
346
+ ## 当前限制
347
+
348
+ ### plugin-only
349
+
350
+ 当前 CLI 不支持 `user_access_token`。
351
+ 所以这类命令会被直接拒绝:
352
+
353
+ - `user search`
354
+ - `user group create`
355
+ - `user group update-members`
356
+ - `user group query-members`
357
+
358
+ 这是设计行为,不是故障。
359
+
360
+ ## 排错
361
+
362
+ ### 1. `meegle: command not found`
363
+
364
+ 先看 npm 全局 bin:
365
+
366
+ ```bash
367
+ npm bin -g
368
+ ```
369
+
370
+ ### 2. 缺少 `userKey`
371
+
372
+ 报错通常类似:
373
+
374
+ - `缺少 userKey`
375
+ - `命令 ... 需要 userKey`
376
+
377
+ 处理方式:
378
+
379
+ ```bash
380
+ meegle --profile default space list --user-key <USER_KEY>
381
+ ```
382
+
383
+ 或者重新初始化:
384
+
385
+ ```bash
386
+ meegle auth init \
387
+ --target-profile default \
388
+ --plugin-id <PLUGIN_ID> \
389
+ --plugin-secret <PLUGIN_SECRET> \
390
+ --default-user-key <USER_KEY>
391
+ ```
392
+
393
+ ### 3. `user search` 被拒绝
394
+
395
+ 这是正常行为。
396
+ 当前版本是 `plugin-only`,该命令依赖 `user_access_token`。
397
+
398
+ ### 4. 固定视图 / 全景视图调用报错
399
+
400
+ 先回到 `view list` 看 `view_type`。
401
+ 不要只凭页面 URL 去猜视图类型。
402
+
403
+ ## 命令总览
404
+
405
+ - `auth`: `init`, `status`
406
+ - `space`: `list`, `get`, `types`, `team-members`
407
+ - `workitem`: `get`, `meta`, `create`, `update`, `remove`, `freeze`, `unfreeze`, `abort`, `restore`, `op-records`, `update-compound`
408
+ - `workitem search`: `filter`, `filter-across`, `by-params`, `by-relation`, `compositive`, `universal`
409
+ - `workflow`: `query`, `state-change`, `node-operate`, `node-update`, `required-info`, `wbs`
410
+ - `comment`: `list`, `add`, `update`, `remove`
411
+ - `subtask`: `list`, `search`, `create`, `update`, `remove`, `operate`
412
+ - `attachment`: `upload-file`, `upload`, `download`, `delete`
413
+ - `workhour`: `list`, `create`, `update`, `delete`
414
+ - `view`: `list`, `fix-items`, `panoramic-items`, `create-fix`, `update-fix`, `delete`, `create-condition`, `update-condition`
415
+ - `measure`: `charts`, `chart-data`
416
+ - `tenant`: `info`, `entitlement`, `spaces`
417
+ - `user`: `query`, `search`(会被拒绝)
418
+ - `user group`: `create`, `update-members`, `query-members`(会被拒绝)
419
+
420
+ ## 开发与发布
421
+
422
+ 仓库内开发:
423
+
424
+ ```bash
425
+ cd meegle-cli
426
+ npm install
427
+ npm test
428
+ ```
429
+
430
+ 发布说明见 [RELEASE.md](./RELEASE.md)。
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "meegle-cli",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "Plugin-only CLI for Feishu Project (Meegle) based on meeglesdk",
5
5
  "type": "module",
6
6
  "bin": {
7
- "meegle": "./dist/index.js"
7
+ "meegle": "dist/index.js"
8
8
  },
9
9
  "files": [
10
10
  "dist",