feishu-user-plugin 1.3.11 → 1.3.13

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 (51) hide show
  1. package/.claude-plugin/plugin.json +2 -2
  2. package/.cursor-plugin/plugin.json +2 -2
  3. package/.mcpb/manifest.json +3 -3
  4. package/CHANGELOG.md +159 -8
  5. package/README.en.md +130 -413
  6. package/README.md +69 -259
  7. package/package.json +2 -2
  8. package/scripts/check-description-drift.js +73 -0
  9. package/scripts/check-docs-sync.js +7 -16
  10. package/scripts/check-scopes.js +99 -0
  11. package/scripts/check-tool-count.js +4 -3
  12. package/scripts/sync-claude-md.sh +3 -4
  13. package/scripts/verify-app-name.js +64 -0
  14. package/skills/feishu-user-plugin/SKILL.md +3 -3
  15. package/skills/feishu-user-plugin/references/search.md +3 -3
  16. package/src/auth/credentials-monitor.js +185 -0
  17. package/src/auth/identity-state.js +209 -0
  18. package/src/auth/uat.js +49 -35
  19. package/src/cli.js +87 -0
  20. package/src/clients/official/base.js +170 -14
  21. package/src/clients/official/calendar.js +3 -1
  22. package/src/clients/official/im.js +76 -2
  23. package/src/clients/official/okr.js +2 -1
  24. package/src/error-codes.js +40 -0
  25. package/src/events/lockfile.js +40 -4
  26. package/src/events/owner.js +11 -2
  27. package/src/index.js +1 -1
  28. package/src/logger.js +11 -5
  29. package/src/oauth.js +65 -14
  30. package/src/server.js +76 -37
  31. package/src/test-all.js +41 -0
  32. package/src/test-cli-tool.js +87 -0
  33. package/src/test-credentials-monitor.js +124 -0
  34. package/src/test-display-label.js +88 -0
  35. package/src/test-error-codes.js +85 -0
  36. package/src/test-identity-state.js +177 -0
  37. package/src/test-lark-desktop.js +1 -0
  38. package/src/test-lockfile-pid.js +90 -0
  39. package/src/test-lru-cache.js +145 -0
  40. package/src/test-negative-cache.js +85 -0
  41. package/src/test-populate-sender-names.js +98 -0
  42. package/src/test-search-messages.js +101 -0
  43. package/src/test-send-shape.js +115 -0
  44. package/src/test-via-user.js +94 -0
  45. package/src/test-with-uat-retry.js +135 -0
  46. package/src/tools/_registry.js +24 -1
  47. package/src/tools/calendar.js +5 -5
  48. package/src/tools/im-read.js +52 -4
  49. package/src/tools/messaging-user.js +1 -1
  50. package/src/utils.js +83 -0
  51. package/skills/feishu-user-plugin/references/CLAUDE.md +0 -524
package/README.md CHANGED
@@ -1,41 +1,34 @@
1
- # feishu-user-plugin
1
+ # feishu-user-plugin —— 飞书 MCP 服务器 + CLI 工具
2
2
 
3
3
  [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE)
4
4
  [![Node.js](https://img.shields.io/badge/Node.js-%3E%3D18-green.svg)](https://nodejs.org)
5
5
  [![MCP](https://img.shields.io/badge/MCP-Compatible-purple.svg)](https://modelcontextprotocol.io)
6
- [![Tools](https://img.shields.io/badge/Tools-84-orange.svg)](#工具索引84-个)
6
+ [![Tools](https://img.shields.io/badge/Tools-85-orange.svg)](docs/TOOLS.md)
7
7
  [![npm](https://img.shields.io/npm/v/feishu-user-plugin.svg)](https://www.npmjs.com/package/feishu-user-plugin)
8
8
  [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](CONTRIBUTING.md)
9
9
 
10
10
  **中文** · [English](README.en.md) · [Docs](https://ethanqc.github.io/feishu-user-plugin/) · [CHANGELOG](CHANGELOG.md) · [npm](https://www.npmjs.com/package/feishu-user-plugin)
11
11
 
12
- 飞书 / Lark MCP 服务器,覆盖 IM、文档、多维表格、知识库、云空间、日历、任务 v2、OKR、实时事件。**84 tools · 3 auth layers · 9 MCP prompts · MIT licensed · Node ≥18**。
12
+ 飞书 / Lark MCP 服务器,覆盖 IM、文档、多维表格、知识库、云空间、日历、任务 v2、OKR、实时事件。**85 工具 · 3 层鉴权 · 9 MCP prompts · MIT licensed · Node ≥18**。
13
13
 
14
14
  兼容 Claude Code、Codex、Cursor、Windsurf、VS Code、Claude Desktop、OpenClaw 等 MCP 客户端。
15
15
 
16
- 与其他飞书 MCP 的区别:基于 cookie + protobuf 协议路径,支持以**用户本人身份**发消息——飞书官方开放 API 没有 `send_as_user` 权限点,机器人 token 发出的消息一律标 `sender_type: "app"`。
16
+ 用户身份发消息有两条路径:**飞书官方 OAuth scope `im:message.send_as_user`**(需要创建自建应用 + 管理员审批),或本仓的 **cookie + protobuf 路径**(零应用门槛,cookie 抓出来就跑)。本仓不再是物理性独家,但仍然是"个人开发者 / 没有管理员权限 / 想快速试"场景的简便选项。
17
17
 
18
- ## 三层鉴权
19
-
20
- | 鉴权层 | 凭证 | 覆盖能力 | 工具数 |
21
- |---|---|---|---|
22
- | 用户身份(cookie + protobuf) | `LARK_COOKIE` | 以用户身份发文本 / 图片 / 文件 / 富文本 / @ / 批量 | 8 |
23
- | 官方 API(机器人) | `LARK_APP_ID` + `LARK_APP_SECRET` | 群消息读写、文档、多维表格、知识库、云空间、日历、任务 v2、OKR、联系人、实时事件 WS | 70+ |
24
- | 用户 OAuth UAT | `LARK_USER_ACCESS_TOKEN` + `LARK_USER_REFRESH_TOKEN` | P2P 私聊读取、用户 chat 列表;写入文档 / Bitable / 日历 资源时以用户为 owner | 2 显式 + 全工具 UAT-first |
18
+ ## 与官方对比(飞书 2026 年也发了 MCP + CLI)
25
19
 
26
- 三层独立 —— 配置任意一层,对应工具可用。
20
+ - [`larksuite/lark-openapi-mcp`](https://github.com/larksuite/lark-openapi-mcp) —— 官方 OpenAPI MCP,**⚠ Beta** + 最后更新 2025-08(9 个月前),README 明文不支持文件上传下载、不支持文档编辑;1271 个 endpoint 工具但 preset.default 仅 ~20,其余"未做兼容性测试"
21
+ - [`larksuite/cli`](https://github.com/larksuite/cli) —— 官方 CLI(9.9k stars,活跃),17 业务域 200+ commands + 24 AI Agent Skills,**已支持 `+messages-send --as user`**(走 OAuth scope `im:message.send_as_user`),但 **CLI 形态而不是 MCP**,Codex / Cursor / Windsurf 等用它要 shell out
27
22
 
28
- ## 安装
23
+ **什么时候用本仓**:
29
24
 
30
- ```bash
31
- npx feishu-user-plugin setup --app-id <APP_ID> --app-secret <APP_SECRET>
32
- npx feishu-user-plugin oauth # 拿用户 OAuth UAT
33
- # 重启 Claude Code / Codex
34
- ```
25
+ - 想以用户身份发消息 / 读 P2P 私聊但**不想 / 不能创建飞书自建应用**(个人开发者 / 没管理员权限)—— cookie 路径零门槛
26
+ - MCP 协议(Codex / Cursor / Windsurf / VS Code 等)+ 不需要邮件 / 审批 / HR / 会议纪要等本仓未覆盖的域
27
+ - MCP 客户端共存且需要"实时事件全机精确投递一次"(v1.3.9+ 机器级 WS SSOT)
35
28
 
36
- cookie 获取:跟 Claude Code 说一句"帮我设置飞书 cookie"会自动经 Playwright 扫码登录抓取;手动方式在 feishu.cn DevTools Network 标签从请求头 Cookie 整行复制(不要用 `document.cookie` 或 Application > Cookies 标签—— HttpOnly 的 `session` / `sl_session` 拿不到)。
29
+ **什么时候用官方**:需要邮件 / 审批 / 考勤 / HR / 招聘 / 会议纪要等业务系统域;或已有飞书应用 + 管理员批了 OAuth scope,偏好官方长期稳定路径。
37
30
 
38
- 没有 APP_ID / SECRET 见下面 [创建飞书应用](#创建飞书应用)。
31
+ 完整诚实对比见 [docs/COMPARISON.md](docs/COMPARISON.md)。
39
32
 
40
33
  ## 用法
41
34
 
@@ -49,172 +42,36 @@ Claude:[调用 send_to_user] Sent
49
42
  Claude:[read_messages → 总结 → send_to_group] Sent
50
43
  ```
51
44
 
52
- ## 创建飞书应用
53
-
54
- `LARK_APP_ID` / `LARK_APP_SECRET` 是用 Official API(70+ 工具)的前置条件:
55
-
56
- 1. [飞书开放平台](https://open.feishu.cn/app) 登录 → 创建**自建应用**(不能选商店应用 / 第三方应用,否则 P2P 读取会被锁)
57
- 2. 添加应用能力 → 启用机器人
58
- 3. 权限管理 → 添加 scope:
59
- - 消息:`im:message`、`im:message:readonly`、`im:chat:readonly`
60
- - 文档:`docx:document`、`bitable:record`、`wiki:wiki:readonly`、`drive:drive:readonly`
61
- - 联系人:`contact:user.base:readonly`
62
- - 按需:`okr:okr:readonly`、`calendar:calendar:readonly`、`task:task`、`drive:drive`、`docs:document.media:upload`、`wiki:wiki` 等
63
- 4. 凭证与基础信息 → 复制 App ID(`cli_xxx`)+ App Secret
64
- 5. 创建版本 → 提交审核 → 管理员审批
65
- 6. 把 bot 加到要读消息的群里
66
-
67
- ## 工具索引(84 个)
68
-
69
- 完整工具列表 + 参数 + 跨域注意事项见 [CLAUDE.md](CLAUDE.md)。
70
-
71
- ### 用户身份 —— 消息(cookie protobuf,8 个)
72
-
73
- | 工具 | 说明 |
74
- |---|---|
75
- | `send_to_user` | 按名搜用户 + 发文本,一步完成 |
76
- | `send_to_group` | 按名搜群 + 发文本,一步完成 |
77
- | `send_as_user` | 按 chat ID 发文本,支持回复线程(`root_id` / `parent_id`) |
78
- | `send_image_as_user` | 以用户身份发图(v1.3.9) |
79
- | `send_file_as_user` | 以用户身份发文件(需先 `upload_file`) |
80
- | `send_post_as_user` | 富文本:标题 + 段落 + @ + 超链 |
81
- | `send_card_as_user` | 飞书交互卡片(机器人通道;cookie 通道服务端关闭,仅 bot 路径可用) |
82
- | `batch_send` | 一次发多条到不同 chat(text / image / file / post) |
83
-
84
- ### 用户身份 —— 联系人 / 信息(cookie,5 个)
85
-
86
- | 工具 | 说明 |
87
- |---|---|
88
- | `search_contacts` | 搜用户 / bot / 群 |
89
- | `create_p2p_chat` | 创建或获取 P2P chat |
90
- | `get_chat_info` | 群详情(接受 `oc_xxx` 或 numeric) |
91
- | `get_user_info` | 用户名 / 头像查询 |
92
- | `get_login_status` | 三层鉴权健康检查(实际跑一次 UAT 调用,不只看配置) |
93
-
94
- ### 用户 OAuth UAT —— P2P 读取(2 个)
95
-
96
- | 工具 | 说明 |
97
- |---|---|
98
- | `read_p2p_messages` | 读私聊历史(外部群自动 fallback) |
99
- | `list_user_chats` | 用户加入的所有群(仅群,不含 P2P;P2P 用 `search_contacts` → `create_p2p_chat`) |
100
-
101
- ### 官方 API —— IM(15 个)
102
-
103
- | 工具 | 说明 |
104
- |---|---|
105
- | `list_chats` | 列 bot 加入的所有 chat |
106
- | `read_messages` | 读群消息(接受 chat 名 / `oc_xxx` / numeric;外部群自动 UAT fallback;merge_forward 自动展开) |
107
- | `send_message_as_bot` | 机器人发消息 |
108
- | `reply_message` | 机器人回复 |
109
- | `forward_message` | 转发到其他 chat(自动识别 receive_id_type) |
110
- | `delete_message` | 撤回 / 删除 bot 消息 |
111
- | `update_message` | 编辑已发消息(仅支持 text / interactive) |
112
- | `add_reaction` / `delete_reaction` | 表情回应 |
113
- | `pin_message` | 置顶 |
114
- | `create_group` / `update_group` | 建群 / 改群 |
115
- | `list_members` / `manage_members` | 群成员 list / add / remove(注意 `member_id_type` 与 ID 类型匹配) |
116
- | `download_message_resource` | 下载消息附件(image / file,> 2 MiB 必须 `save_path`) |
117
-
118
- ### 官方 API —— 文档(7 个)
119
-
120
- | 工具 | 说明 |
121
- |---|---|
122
- | `search_docs` | 关键词搜文档 |
123
- | `read_doc` | 结构化 JSON |
124
- | `read_doc_markdown` | v1.3.9 直接返回 markdown,~60% token 节省(适合 RAG / 总结) |
125
- | `get_doc_blocks` | 块树 |
126
- | `create_doc` | 创建文档(可选 `wiki_space_id` 直接落知识库) |
127
- | `manage_doc_block` | 块 create / update / delete(image_path / file_path / image_token / file_token 快捷) |
128
- | `download_doc_image` | 下载文档内嵌图片 |
129
-
130
- ### 官方 API —— 多维表格 Bitable(6 个,v1.3.7 整合)
131
-
132
- | 工具 | actions | 说明 |
133
- |---|---|---|
134
- | `manage_bitable_app` | create / copy / get_meta | 应用级(创建可指定 `wiki_space_id` 直接落 Wiki) |
135
- | `manage_bitable_table` | list / create / update / delete | 数据表 CRUD |
136
- | `manage_bitable_field` | list / create / update / delete | 字段(update 必须传 `type` 即使只改名) |
137
- | `manage_bitable_view` | list / create / delete | 视图(grid / kanban / gallery / form / gantt / calendar) |
138
- | `manage_bitable_record` | search / get / create / update / delete | 记录 CRUD(数组:单条或最多 500) |
139
- | `upload_bitable_attachment` | — | 上传附件,返回 `file_token` |
140
-
141
- ### 官方 API —— 知识库 Wiki(9 个)
142
-
143
- | 工具 | 说明 |
144
- |---|---|
145
- | `list_wiki_spaces` | 列空间(UAT-first) |
146
- | `search_wiki` | 搜知识库 |
147
- | `list_wiki_nodes` | 列节点 |
148
- | `get_wiki_node` | 节点 → obj_token 解析(接受 wiki node token 或 obj_token) |
149
- | `create_wiki_node` | 创建节点(doc / sheet / bitable / mindnote / file / docx / slides) |
150
- | `update_wiki_node` | 改名(内容编辑用 docx / bitable 工具) |
151
- | `move_wiki_node` | 移动 |
152
- | `copy_wiki_node` | 深拷贝 |
153
- | `delete_wiki_node` | 删除 wiki 节点指针(底层 drive 资源用 `manage_drive_file(action=delete)` 删) |
154
-
155
- ### 官方 API —— 云空间 Drive(5 个)
156
-
157
- | 工具 | 说明 |
158
- |---|---|
159
- | `list_files` | 列文件夹内文件 |
160
- | `create_folder` | 建文件夹 |
161
- | `manage_drive_file` | copy / move / delete(必须传 `type`) |
162
- | `upload_image` / `upload_file` | 上传图片 / 文件,返回 key |
163
- | `upload_drive_file` | 上传到 Drive 文件夹(可选 `wiki_space_id` 直接挂 Wiki 节点) |
164
-
165
- ### 官方 API —— OKR(6 个)
166
-
167
- | 工具 | 说明 |
168
- |---|---|
169
- | `list_user_okrs` | 列指定用户的 OKR(必须传 user_id) |
170
- | `get_okrs` | 批量取详情(objectives + key results + progress + alignments) |
171
- | `list_okr_periods` | 列周期(季度 / 年度) |
172
- | `create_okr_progress_record` | 添加进展记录(v1.3.7,需 `okr:okr.content:write`) |
173
- | `list_okr_progress_records` | 列进展记录(从 `get_okrs` 提取 triples) |
174
- | `delete_okr_progress_record` | 删进展记录 |
175
-
176
- ### 官方 API —— 日历(8 个,写入 v1.3.7)
45
+ ## 安装
177
46
 
178
- | 工具 | 说明 |
179
- |---|---|
180
- | `list_calendars` | 列日历(primary + 共享 + 订阅) |
181
- | `list_calendar_events` | 列事件(指定时间窗) |
182
- | `get_calendar_event` | 事件详情(参与人 / 地点 / 会议链接 / 附件) |
183
- | `create_calendar_event` | 建事件(需 `calendar:calendar.event:write`) |
184
- | `update_calendar_event` | 改事件 |
185
- | `delete_calendar_event` | 删事件(可选 `meeting_chat_id` 同时解散关联会议群) |
186
- | `respond_calendar_event` | RSVP(accept / decline / tentative) |
187
- | `get_freebusy` | 多人 freebusy 查询 |
47
+ ```bash
48
+ npx feishu-user-plugin setup --app-id <APP_ID> --app-secret <APP_SECRET>
49
+ npx feishu-user-plugin oauth # 拿用户 OAuth UAT
50
+ # 重启 Claude Code / Codex
51
+ ```
188
52
 
189
- ### 官方 API —— 任务 v2(7 个,v1.3.7 新域)
53
+ cookie 获取(Playwright 自动扫码 / DevTools 手动)、创建飞书应用、各客户端配置详见 [docs/AUTH-SETUP.md](docs/AUTH-SETUP.md)。
190
54
 
191
- 标识符是 `task_guid`(不是 v1 的 numeric `task_id`),需 `task:task` scope。
55
+ ## 三层鉴权
192
56
 
193
- | 工具 | 说明 |
194
- |---|---|
195
- | `list_tasks` | 列当前用户任务 |
196
- | `get_task` | 详情 |
197
- | `create_task` | 建任务(summary 必填) |
198
- | `update_task` | 改任务(必传 `update_fields=[...]`,飞书只 patch 列出字段) |
199
- | `complete_task` | 完成 / 取消完成 |
200
- | `delete_task` | 删 |
201
- | `manage_task_members` | add / remove 成员(assignee / follower) |
57
+ | 鉴权层 | 凭证 | 覆盖能力 | 工具数 |
58
+ |---|---|---|---|
59
+ | 用户身份(cookie + protobuf) | `LARK_COOKIE` | 以用户身份发文本 / 图片 / 文件 / 富文本 / @ / 批量 | 8 |
60
+ | 官方 API(机器人) | `LARK_APP_ID` + `LARK_APP_SECRET` | 群消息读写、文档、多维表格、知识库、云空间、日历、任务 v2、OKR、联系人、实时事件 WS | 70+ |
61
+ | 用户 OAuth UAT | `LARK_USER_ACCESS_TOKEN` + `LARK_USER_REFRESH_TOKEN` | P2P 私聊读取、用户 chat 列表;写入文档 / Bitable / 日历 资源时以用户为 owner | 2 显式 + 全工具 UAT-first |
202
62
 
203
- ### 插件层 —— 诊断与多账号(4 个)
63
+ 三层独立 —— 配置任意一层,对应工具可用。
204
64
 
205
- | 工具 | 说明 |
206
- |---|---|
207
- | `get_login_status` | 三层鉴权健康检查 |
208
- | `list_profiles` | 列可用 profile(默认 + LARK_PROFILES_JSON / credentials.json) |
209
- | `switch_profile` | 切 profile(缓存的 client 实例下次调用重建) |
210
- | `manage_profile_hints` | 查 / 改 / 清 自动切换缓存(list / set / clear) |
65
+ ## 核心能力
211
66
 
212
- ### 插件层 —— 实时事件(2 个,v1.3.9)
67
+ - **以你身份发消息**(8):text / image / file / 富文本 post / 卡片 / 批量;差异化锚点 —— 飞书官方 API 没有 `send_as_user`
68
+ - **读群与 P2P 私聊**(17):群消息 / 私聊 / `merge_forward` 自动展开 / URL + 飞书文档链接自动提取 / 外部群自动 fallback 到 UAT
69
+ - **文档生态**(27):飞书文档(含 `read_doc_markdown` 省 ~60% token)/ 多维表格(500 条批量)/ 知识库(含 write CRUD)/ 云空间
70
+ - **协作工具**(21):日历(读+写)/ 任务 v2(含成员管理)/ OKR(读+进展记录)/ 联系人
71
+ - **实时事件**(2):机器级 SSOT WS,每条事件全机精确投递一次
72
+ - **诊断与多账号**(4):N 个 profile 自动切换,写路径不切(避免错号建资源)
213
73
 
214
- | 工具 | 说明 |
215
- |---|---|
216
- | `get_new_events` | 拉取增量事件(peek=true 不推进 cursor;filter by event_type / chat_id / since_seconds / profile) |
217
- | `manage_ws_status` | info / reconnect / claim / rotate / reconfig(诊断 / 重连 / 抢锁 / 强制 events.jsonl 轮转 / 不重启重新订阅) |
74
+ 完整工具列表 + 跨域 caveat + 用法 patterns 见 [docs/TOOLS.md](docs/TOOLS.md)。
218
75
 
219
76
  ## 9 个 MCP prompts(slash commands)
220
77
 
@@ -232,48 +89,27 @@ Claude:[read_messages → 总结 → send_to_group] Sent
232
89
 
233
90
  ## 客户端配置
234
91
 
235
- 环境变量配置一致,配置文件路径和顶层键不同。
236
-
237
- **统一 env 块**:
238
-
239
- ```json
240
- {
241
- "command": "npx",
242
- "args": ["-y", "feishu-user-plugin"],
243
- "env": {
244
- "LARK_COOKIE": "your-cookie-string",
245
- "LARK_APP_ID": "cli_xxxxxxxxxxxx",
246
- "LARK_APP_SECRET": "your-app-secret",
247
- "LARK_USER_ACCESS_TOKEN": "your-uat",
248
- "LARK_USER_REFRESH_TOKEN": "your-refresh-token"
249
- }
250
- }
251
- ```
252
-
253
- **安放位置**:
92
+ 环境变量统一,配置文件位置和顶层键不同:
254
93
 
255
94
  | 客户端 | 配置文件 | 顶层键 |
256
95
  |---|---|---|
257
- | Claude Code | `~/.claude.json`(推荐全局) / `.mcp.json` | `mcpServers.feishu-user-plugin` |
96
+ | Claude Code | `~/.claude.json`(推荐全局)/ `.mcp.json` | `mcpServers.feishu-user-plugin` |
258
97
  | Claude Desktop | `~/Library/Application Support/Claude/claude_desktop_config.json` (macOS) | `mcpServers.feishu` |
259
- | Codex | `~/.codex/config.toml` | `[mcp_servers.feishu-user-plugin]`(TOML) |
98
+ | Codex | `~/.codex/config.toml` | `[mcp_servers.feishu-user-plugin]` |
260
99
  | Cursor | `.cursor/mcp.json`(项目级) | `mcpServers.feishu` |
261
- | VS Code (Copilot) | `.vscode/mcp.json` | `servers.feishu`(注意是 `servers`,不是 `mcpServers`) |
100
+ | VS Code (Copilot) | `.vscode/mcp.json` | `servers.feishu`(注意 `servers`,非 `mcpServers`) |
262
101
  | OpenClaw | `~/.openclaw/openclaw.json` | `mcp.servers.feishu-user-plugin` |
263
102
  | Windsurf | `~/.codeium/windsurf/mcp_config.json` | `mcpServers.feishu` |
264
103
 
265
- **自动化设置**:
266
-
267
104
  ```bash
268
- npx feishu-user-plugin setup # 默认写 Claude Code (~/.claude.json)
269
- npx feishu-user-plugin setup --client codex # Codex (~/.codex/config.toml)
270
- npx feishu-user-plugin setup --client both # Claude Code + Codex 都写
271
- npx feishu-user-plugin setup --activate # 激活当前 profile
105
+ npx feishu-user-plugin setup # Claude Code
106
+ npx feishu-user-plugin setup --client codex # Codex
107
+ npx feishu-user-plugin setup --client both # 都写
272
108
  ```
273
109
 
274
- 各客户端完整 JSON 模板见 [README.en.md `MCP Client Configuration`](README.en.md#mcp-client-configuration)。
110
+ 各客户端完整 JSON 模板见 [README.en.md `MCP Client Configuration`](README.en.md#mcp-client-configuration);详细安装与凭证流程见 [docs/AUTH-SETUP.md](docs/AUTH-SETUP.md)
275
111
 
276
- ## 多账号(v1.3.8 / v1.3.9)
112
+ ## 多账号
277
113
 
278
114
  `~/.feishu-user-plugin/credentials.json` 支持多 profile(默认 + 任意附加),单台机器一处配置覆盖多个飞书账号 / 多个企业。
279
115
 
@@ -283,73 +119,47 @@ npx feishu-user-plugin switch-profile <name>
283
119
  npx feishu-user-plugin keepalive --all # 跨 profile keepalive
284
120
  ```
285
121
 
286
- 读路径工具(`read_*` / `list_*` / `get_*` / `search_*` / `download_*`)失败码 91403 / 1254301 / 1254000 / 99991672 / HTTP 403 时自动跨 profile retry。写路径不自动切(避免错号创建资源)。
122
+ 读路径工具失败码 `91403` / `1254301` / `1254000` / `99991672` / `HTTP 403` 时自动跨 profile retry。写路径不自动切(避免错号创建资源)。单调用覆盖:传 `via_profile: "<name>"` 钉到指定 profile。
287
123
 
288
- 单调用覆盖:传 `via_profile: "<name>"` 钉到指定 profile,传 `via_profile: "auto"` 给写路径开自动切换。
124
+ 详见 [docs/TOOLS.md " profile auto-switch"](docs/TOOLS.md#多-profile-auto-switchv138)。
289
125
 
290
- 详见 [CLAUDE.md "Multi-profile auto-switch" 段](CLAUDE.md#multi-profile-auto-switch-v138)。
126
+ ## 实时事件
291
127
 
292
- ## 实时事件(v1.3.9 机器级 SSOT)
293
-
294
- 机器上单进程持有 WS owner 锁(`~/.feishu-user-plugin/ws-owner.lock`,`O_CREAT|O_EXCL`,30s stale),所有 MCP 进程共享 `~/.feishu-user-plugin/events.jsonl`(10 MB 软 / 20 MB 硬限自动轮转),`events.cursor.json` 是全机所有 harness 共享的 drain cursor —— 每条事件全机恰好一次。
128
+ 机器上单进程持有 WS owner 锁,所有 MCP 进程共享 `events.jsonl`,每条事件全机恰好一次。
295
129
 
296
130
  ```bash
297
- mcp call manage_ws_status --action info # 谁在持锁、当前订阅、events.jsonl 大小
298
- mcp call manage_ws_status --action claim --force true # 跨进程抢锁
131
+ mcp call manage_ws_status --action info
132
+ mcp call manage_ws_status --action claim --force true
299
133
  ```
300
134
 
301
- 默认订阅 `["im.message.receive_v1"]`。要订阅其他事件(审批 / 日历 / vc / etc),编辑 `credentials.json::profiles[<active>].events`,然后 `manage_ws_status(action=reconfig)` 不重启重新订阅。
135
+ 默认订阅 `["im.message.receive_v1"]`。要订阅审批 / 日历 / vc 等其他事件,编辑 `credentials.json::profiles[<active>].events`,然后 `manage_ws_status(action=reconfig)` 不重启重新订阅。
302
136
 
303
137
  仅支持 feishu.cn —— Lark 国际版(lark.com)的 WSClient 当前不支持。
304
138
 
305
- ## 工程细节
306
-
307
- ### Token 生命周期
308
-
309
- | 鉴权层 | Token | 有效期 | 续期 |
310
- |---|---|---|---|
311
- | Cookie | `sl_session` | 12h max-age | 4h 心跳自动刷新 |
312
- | App | `tenant_access_token` | 2h | SDK 自动管理 |
313
- | User OAuth | `user_access_token` | ~2h | refresh_token 自动刷新,写回 credentials.json |
314
- | Refresh Token | — | 7 天 | `keepalive` cron 防过期 |
315
-
316
- ```bash
317
- crontab -e
318
- # 0 */4 * * * npx feishu-user-plugin keepalive >> /tmp/feishu-keepalive.log 2>&1
319
- ```
320
-
321
- UAT 刷新失败 `invalid_grant` —— refresh token 过期 / 被撤销,重跑 `npx feishu-user-plugin oauth` 然后重启 Claude Code / Codex。
322
-
323
- ### 凭证存储(v1.3.7+)
324
-
325
- 单一可信源 `~/.feishu-user-plugin/credentials.json`(mode 0600),多 harness 共享。schema 见 [docs/CREDENTIALS-FORMAT.md](docs/CREDENTIALS-FORMAT.md)。
326
-
327
- ```bash
328
- npx feishu-user-plugin migrate # dry-run
329
- npx feishu-user-plugin migrate --confirm # 真写
330
- ```
331
-
332
- ### 自动 sync hooks
333
-
334
- | 阶段 | 触发文件 | 作用 |
335
- |---|---|---|
336
- | pre-commit | `CLAUDE.md` staged | 同步到 `AGENTS.md` + skill 引用 |
337
- | pre-commit | `package.json` / `plugin.json` / `SKILL.md` staged | 三角等价检查(version 必须一致) |
338
- | pre-commit | `src/server.js` / `src/tools/*` staged | 工具个数 + README 84 tools 徽章必须一致 |
339
- | pre-commit | `src/*` staged | smoke test |
340
- | post-merge (main) | 任意 | 自动开 team-skills sync PR |
341
-
342
- CI(`.github/workflows/validate.yml`)每个 PR 跑同样的 gate。
343
-
344
139
  ## 已知限制
345
140
 
346
141
  - **Cookie 寿命**:12-24 小时无心跳过期,需重新登录 feishu.cn 拿 cookie
347
142
  - **协议变化**:cookie + protobuf 层依赖飞书 web 客户端的协议,飞书更新可能失效(机器人能力不受影响)
348
143
  - **卡片**:cookie 通道发卡片服务端不可用,机器人通道可发
349
144
  - **Lark 国际版**:实时事件 WS 不支持
350
- - **未实现**:`search_messages`(v1.3.10 计划)、md → wiki 同步(v1.3.10 主线)
351
-
352
- 完整 ROADMAP 见 [ROADMAP.md](ROADMAP.md)。
145
+ - **未实现**:`search_messages`、md → wiki 同步(详见 [ROADMAP.md](ROADMAP.md))
146
+
147
+ ## 文档
148
+
149
+ | 文档 | 角色 |
150
+ |------|------|
151
+ | [docs/TOOLS.md](docs/TOOLS.md) | 工具详细 + 跨域 caveat + 用法 patterns |
152
+ | [docs/AUTH-SETUP.md](docs/AUTH-SETUP.md) | 安装 / 三层鉴权 / Cookie 抓取 / OAuth Scopes |
153
+ | [docs/TROUBLESHOOTING.md](docs/TROUBLESHOOTING.md) | 错误码与诊断 |
154
+ | [docs/RELEASING.md](docs/RELEASING.md) | 发版流程 + team-skills 同步 + 公告规则 |
155
+ | [docs/REFACTOR-NOTES.md](docs/REFACTOR-NOTES.md) | 文件职责矩阵 |
156
+ | [docs/CREDENTIALS-FORMAT.md](docs/CREDENTIALS-FORMAT.md) | 凭证 schema |
157
+ | [docs/TESTING-METHODOLOGY.md](docs/TESTING-METHODOLOGY.md) | 测试方法 |
158
+ | [CONTRIBUTING.md](CONTRIBUTING.md) | 贡献流程(中英双语) |
159
+ | [ROADMAP.md](ROADMAP.md) | 路线图(forward-only) |
160
+ | [CHANGELOG.md](CHANGELOG.md) | 历史变更 |
161
+
162
+ 完整 docs/ 索引:[docs/README.md](docs/README.md)。
353
163
 
354
164
  ## 贡献
355
165
 
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "feishu-user-plugin",
3
3
  "mcpName": "io.github.EthanQC/feishu-user-plugin",
4
- "version": "1.3.11",
5
- "description": "All-in-one Feishu MCP server for Claude Code & Codex — 84 tools across 3 auth layers (cookie / app / OAuth). Send as you, read groups, manage docs / bitable / wiki / drive / calendar / tasks / OKR.",
4
+ "version": "1.3.13",
5
+ "description": "All-in-one Feishu MCP server + CLI tool for Claude Code / Codex / Cursor / scripts 85 tools across 3 auth layers (cookie / app / OAuth). Send as you, read groups, manage docs / bitable / wiki / drive / calendar / tasks / OKR.",
6
6
  "main": "src/index.js",
7
7
  "bin": {
8
8
  "feishu-user-plugin": "src/cli.js"
@@ -0,0 +1,73 @@
1
+ #!/usr/bin/env node
2
+ 'use strict';
3
+ // Verifies every manifest description / long_description references only
4
+ // the current package.json::version (or no version at all).
5
+ //
6
+ // Catches the "plugin.json description stuck at v1.3.8 for 3 releases"
7
+ // class of bug: a CI gate would have flagged it on the v1.3.9 release PR.
8
+ //
9
+ // Rule: every `vX.Y.Z` token inside the listed description fields must
10
+ // equal the current package.json::version. To keep a description across
11
+ // releases without churn, drop the version reference entirely.
12
+
13
+ const fs = require('fs');
14
+ const path = require('path');
15
+
16
+ const ROOT = path.join(__dirname, '..');
17
+ const VERSION = require(path.join(ROOT, 'package.json')).version;
18
+
19
+ // Match `vX.Y.Z` only (must have leading `v`) — avoids false positives on
20
+ // schema versions like "0.3" or random numbers.
21
+ const VERSION_PATTERN = /v(\d+\.\d+\.\d+)/g;
22
+
23
+ const SOURCES = [
24
+ { label: 'package.json::description', file: 'package.json', extract: (raw) => JSON.parse(raw).description },
25
+ { label: '.claude-plugin/plugin.json::description', file: '.claude-plugin/plugin.json', extract: (raw) => JSON.parse(raw).description },
26
+ { label: '.cursor-plugin/plugin.json::description', file: '.cursor-plugin/plugin.json', extract: (raw) => JSON.parse(raw).description },
27
+ { label: 'mcp-registry.json::description', file: 'mcp-registry.json', extract: (raw) => JSON.parse(raw).description },
28
+ { label: '.mcpb/manifest.json::description', file: '.mcpb/manifest.json', extract: (raw) => JSON.parse(raw).description },
29
+ { label: '.mcpb/manifest.json::long_description', file: '.mcpb/manifest.json', extract: (raw) => JSON.parse(raw).long_description },
30
+ { label: 'skills/feishu-user-plugin/SKILL.md description', file: 'skills/feishu-user-plugin/SKILL.md', extract: extractSkillDescription },
31
+ ];
32
+
33
+ function extractSkillDescription(raw) {
34
+ // SKILL.md frontmatter has description: "..." on a single line.
35
+ const m = raw.match(/^description:\s*"((?:[^"\\]|\\.)*)"/m);
36
+ return m ? m[1].replace(/\\"/g, '"') : null;
37
+ }
38
+
39
+ const failures = [];
40
+
41
+ for (const src of SOURCES) {
42
+ const fullPath = path.join(ROOT, src.file);
43
+ if (!fs.existsSync(fullPath)) {
44
+ failures.push(`${src.label}: source file ${src.file} does not exist`);
45
+ continue;
46
+ }
47
+
48
+ let description;
49
+ try {
50
+ description = src.extract(fs.readFileSync(fullPath, 'utf8'));
51
+ } catch (e) {
52
+ failures.push(`${src.label}: parse error — ${e.message}`);
53
+ continue;
54
+ }
55
+
56
+ if (!description) continue; // Field absent — nothing to check.
57
+
58
+ for (const m of description.matchAll(VERSION_PATTERN)) {
59
+ const found = m[1];
60
+ if (found !== VERSION) {
61
+ failures.push(`${src.label}: references v${found}, but package.json is v${VERSION}`);
62
+ }
63
+ }
64
+ }
65
+
66
+ if (failures.length) {
67
+ console.error('description drift detected:');
68
+ for (const f of failures) console.error(` ${f}`);
69
+ console.error(`\nFix: update each description to reference v${VERSION}, or remove the version reference entirely (e.g. drop "v1.3.8: feature X" → "feature X").`);
70
+ process.exit(1);
71
+ }
72
+
73
+ console.log(`OK: all manifest descriptions reference v${VERSION} (or no version reference)`);
@@ -1,14 +1,12 @@
1
1
  #!/usr/bin/env node
2
2
  'use strict';
3
- // Verifies CLAUDE.md is in sync with AGENTS.md (Codex) and
4
- // skills/feishu-user-plugin/references/CLAUDE.md (skill reference copy).
3
+ // Verifies CLAUDE.md is in sync with AGENTS.md (Codex).
5
4
  //
6
- // Pre-commit hook (scripts/sync-claude-md.sh) already auto-regenerates these
5
+ // Pre-commit hook (scripts/sync-claude-md.sh) already auto-regenerates AGENTS.md
7
6
  // from CLAUDE.md, but this script gives prepublishOnly + CI a hard gate.
8
7
  //
9
- // Match logic mirrors validate.yml's diff steps:
10
- // AGENTS.md = "# feishu-user-plugin — Codex Instructions\n" + tail -n +2 CLAUDE.md
11
- // skills/.../CLAUDE.md = identical to CLAUDE.md
8
+ // Match logic mirrors validate.yml's diff step:
9
+ // AGENTS.md = "# feishu-user-plugin — Codex 指令\n" + tail -n +2 CLAUDE.md
12
10
 
13
11
  const fs = require('fs');
14
12
  const path = require('path');
@@ -16,9 +14,9 @@ const path = require('path');
16
14
  const ROOT = path.join(__dirname, '..');
17
15
  const claude = fs.readFileSync(path.join(ROOT, 'CLAUDE.md'), 'utf8');
18
16
 
19
- // AGENTS.md: header replaced with "# feishu-user-plugin — Codex Instructions"
17
+ // AGENTS.md: header replaced with "# feishu-user-plugin — Codex 指令"
20
18
  const claudeBody = claude.split('\n').slice(1).join('\n'); // drop first line
21
- const expectedAgents = '# feishu-user-plugin — Codex Instructions\n' + claudeBody;
19
+ const expectedAgents = '# feishu-user-plugin — Codex 指令\n' + claudeBody;
22
20
  const actualAgents = fs.readFileSync(path.join(ROOT, 'AGENTS.md'), 'utf8');
23
21
 
24
22
  const failures = [];
@@ -27,15 +25,8 @@ if (actualAgents !== expectedAgents) {
27
25
  failures.push('Fix: bash scripts/sync-claude-md.sh (or edit CLAUDE.md and re-stage)');
28
26
  }
29
27
 
30
- const skillRef = path.join(ROOT, 'skills', 'feishu-user-plugin', 'references', 'CLAUDE.md');
31
- const actualSkillRef = fs.readFileSync(skillRef, 'utf8');
32
- if (actualSkillRef !== claude) {
33
- failures.push('skills/feishu-user-plugin/references/CLAUDE.md is out of sync with CLAUDE.md');
34
- failures.push('Fix: bash scripts/sync-claude-md.sh (or edit CLAUDE.md and re-stage)');
35
- }
36
-
37
28
  if (failures.length) {
38
29
  for (const f of failures) console.error(f);
39
30
  process.exit(1);
40
31
  }
41
- console.log('OK: CLAUDE.md / AGENTS.md / skill reference all in sync');
32
+ console.log('OK: CLAUDE.md / AGENTS.md in sync');
@@ -0,0 +1,99 @@
1
+ #!/usr/bin/env node
2
+ 'use strict';
3
+
4
+ // Validates src/oauth.js::SCOPES against:
5
+ // 1) BANLIST — scope names we've confirmed do NOT exist in Feishu's catalog
6
+ // (caused OAuth 422 / runtime 20043). Add new ones here when discovered.
7
+ // 2) docs/AUTH-SETUP.md mentions — every scope in SCOPES must appear at least
8
+ // once in AUTH-SETUP.md, so the doc never drifts behind the code.
9
+ //
10
+ // Why this gate exists: Feishu's OAuth server SILENTLY accepted some malformed
11
+ // scope names pre-2026-05 (they were ignored, UAT just lacked the scope); from
12
+ // May 2026 it started rejecting the whole authorize request with 422 +
13
+ // "scope <name> 有误". A single bad name in SCOPES locks every user out of
14
+ // `npx oauth`. This script catches it in CI before merge.
15
+
16
+ const path = require('path');
17
+ const fs = require('fs');
18
+
19
+ const repoRoot = path.join(__dirname, '..');
20
+
21
+ // --- Step 1: extract SCOPES constant from src/oauth.js ---
22
+ const oauthSrc = fs.readFileSync(path.join(repoRoot, 'src', 'oauth.js'), 'utf8');
23
+ const m = oauthSrc.match(/const\s+SCOPES\s*=\s*'([^']+)'/);
24
+ if (!m) {
25
+ console.error('check-scopes: could not find `const SCOPES = \'...\'` in src/oauth.js');
26
+ process.exit(1);
27
+ }
28
+ const scopes = m[1].split(/\s+/).filter(Boolean);
29
+
30
+ // --- Step 1b: ADDITIONAL_APP_SCOPES — tenant-side scopes that the plugin requires
31
+ // but that don't live in SCOPES (because they can't be granted via OAuth — only
32
+ // in the Feishu app console "应用身份" tab). Validated against AUTH-SETUP.md only.
33
+ const ADDITIONAL_APP_SCOPES = [
34
+ // Used by LarkOfficialClient.getAppName() to resolve self-app display label.
35
+ // Without it, `senderType=app` messages fall back to "[Bot] (cli_xxx)".
36
+ // Feishu marks this scope as 免审权限 (no admin review needed).
37
+ 'application:application:self_manage',
38
+ ];
39
+
40
+ // --- Step 2: BANLIST of known-bad scope names ---
41
+ //
42
+ // Each entry: { bad: '<name>', reason: '<why>', replacement: '<correct names>' }
43
+ // Append-only — never remove an entry (it's a regression guard).
44
+ const BANLIST = [
45
+ {
46
+ bad: 'calendar:calendar.event:write',
47
+ reason: 'Feishu catalog has no such scope. The catalog splits write into 4 verbs.',
48
+ replacement: 'calendar:calendar.event:create + calendar:calendar.event:update + calendar:calendar.event:delete + calendar:calendar.event:reply',
49
+ },
50
+ {
51
+ bad: 'okr:okr.content:write',
52
+ reason: 'Feishu catalog uses :writeonly (one word) not :write.',
53
+ replacement: 'okr:okr.content:writeonly',
54
+ },
55
+ ];
56
+
57
+ // --- Step 3: validate ---
58
+ const failures = [];
59
+
60
+ for (const entry of BANLIST) {
61
+ if (scopes.includes(entry.bad)) {
62
+ failures.push(
63
+ `BANLIST hit: SCOPES contains \`${entry.bad}\`.\n` +
64
+ ` Reason: ${entry.reason}\n` +
65
+ ` Replace with: ${entry.replacement}`
66
+ );
67
+ }
68
+ }
69
+
70
+ // docs/AUTH-SETUP.md must mention every scope. Catches silent additions
71
+ // to SCOPES that never made it into the OAuth setup docs.
72
+ const authSetupPath = path.join(repoRoot, 'docs', 'AUTH-SETUP.md');
73
+ const authSetup = fs.readFileSync(authSetupPath, 'utf8');
74
+ const missingFromDocs = scopes.filter(s => s !== 'offline_access' && !authSetup.includes(s));
75
+ if (missingFromDocs.length) {
76
+ failures.push(
77
+ `${missingFromDocs.length} scope(s) in SCOPES not mentioned in docs/AUTH-SETUP.md:\n` +
78
+ missingFromDocs.map(s => ` - ${s}`).join('\n') +
79
+ `\n Add them to the scope table around line 117 (\`## OAuth Scopes\` section).`
80
+ );
81
+ }
82
+
83
+ // Same enforcement for tenant-only scopes.
84
+ const missingAppScopes = ADDITIONAL_APP_SCOPES.filter(s => !authSetup.includes(s));
85
+ if (missingAppScopes.length) {
86
+ failures.push(
87
+ `${missingAppScopes.length} tenant-side scope(s) not in docs/AUTH-SETUP.md:\n` +
88
+ missingAppScopes.map(s => ` - ${s}`).join('\n') +
89
+ `\n Add them to the "应用身份额外 scope" section.`
90
+ );
91
+ }
92
+
93
+ if (failures.length) {
94
+ console.error('check-scopes: FAIL\n');
95
+ for (const f of failures) console.error(f + '\n');
96
+ process.exit(1);
97
+ }
98
+
99
+ console.log(`check-scopes: OK (${scopes.length} OAuth + ${ADDITIONAL_APP_SCOPES.length} tenant-only scopes, ${BANLIST.length} banned names guarded)`);