feishu-user-plugin 1.3.15 → 1.3.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.
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "feishu-user-plugin",
3
- "version": "1.3.15",
3
+ "version": "1.3.16",
4
4
  "description": "All-in-one Feishu MCP server + CLI tool for Claude Code — send messages as yourself, read chats (auto-expanded merge_forward), manage docs / bitable / wiki (full CRUD) / drive / OKR (with progress writes) / calendar (read+write) / Tasks v2 / multi-profile auto-switch / real-time WS events. 85 tools + 9 prompts, 3 auth layers.",
5
5
  "author": {
6
6
  "name": "EthanQC"
@@ -2,7 +2,7 @@
2
2
  "name": "feishu-user-plugin",
3
3
  "displayName": "Feishu MCP for Claude Code & Codex",
4
4
  "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.",
5
- "version": "1.3.15",
5
+ "version": "1.3.16",
6
6
  "author": {
7
7
  "name": "EthanQC"
8
8
  },
@@ -2,7 +2,7 @@
2
2
  "manifest_version": "0.3",
3
3
  "name": "feishu-user-plugin",
4
4
  "display_name": "Feishu MCP for Claude Code & Codex",
5
- "version": "1.3.15",
5
+ "version": "1.3.16",
6
6
  "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.",
7
7
  "long_description": "feishu-user-plugin is a local stdio MCP server (and shell CLI tool) that bridges Feishu / Lark and any MCP client (Claude Code, Codex, Cursor, Windsurf, OpenClaw, Claude Desktop). It exposes 85 tools across three auth layers: cookie + protobuf for sending messages as the real user (a capability not available through the official bot API), Feishu Open Platform app credentials for groups / docs / bitable / wiki / drive / calendar / tasks / OKR, and user OAuth (UAT) for P2P chat reading and user-owned resource creation.",
8
8
  "author": {
package/CHANGELOG.md CHANGED
@@ -4,6 +4,27 @@ All notable changes to this project will be documented in this file.
4
4
 
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/), and this project adheres to [Semantic Versioning](https://semver.org/).
6
6
 
7
+ ## [1.3.16] - 2026-06-06
8
+
9
+ 修掉发现类读路径的身份盲区:上传到个人空间的文件此前找不到、也因此删不掉。`list_files` / `search_docs` / `search_wiki` / `get_wiki_node` 四条读路径改为 UAT 优先(bot fallback 保留)。85 工具数不变,list_files / search_docs / search_wiki 三个 schema 新增分页参数,无 breaking API。
10
+
11
+ ### Added
12
+
13
+ - **list_files 看得见你的个人空间了(用户报障修复)**:此前 `list_files` 走纯 app token,bot 对个人空间("我的空间")文件夹 403,导致 `upload_drive_file` 走 UAT 传上去的文件**不可发现、也不可删除**(`manage_drive_file(action=delete)` 需要的 file_token 拿不到)。现在 UAT 优先、bot fallback:配置 UAT 后空 `folder_token` 列你自己的"我的空间"根目录。新增 `page_size` / `page_token` 入参与 `nextPageToken` 返回;root 空结果且走 bot 路径时附 `scopeHint` 解释 bot root ≠ 我的空间。(`src/clients/official/drive.js`)
14
+ - **search_docs / search_wiki 分页游标**:新增 `page_size` / `offset` 入参,`hasMore` 时返回 `nextOffset` 直接回填即可翻页;此前只有 `hasMore` 没有可用游标,截断的尾部恰好可能藏着要找的个人空间文档。异常的 `has_more:true` 空页不发 cursor,防止翻页死循环。坏参数(NaN / 负数)收敛为非负整数后才发给飞书。
15
+
16
+ ### Changed
17
+
18
+ - **search_docs / search_wiki / get_wiki_node 改 UAT-first**:suite 搜索 API 只索引调用身份可见的内容,app 身份搜不到个人空间文档(报障里上传的 PDF 就是这样消失的)。三条路径与 `list_files` 一并走 `_asUserOrApp`(UAT 优先、bot fallback,被迫走 bot 时返回 ⚠ fallbackWarning),响应统一带 `viaUser` 标明视角归属。`get_wiki_node` 保持裸 node 返回形状(resolver 兼容),additive 附加 `viaUser` / `fallbackWarning`;obj_token 合成正则不受新错误形状影响(953001 与 live 实测 131005 双分支测试钉死)。
19
+ - **依赖升级**:protobufjs 7.5.6 → 8.6.0(cookie protobuf 发送层经真实发送探针 + 读回验证);`@larksuiteoapi/node-sdk` 1.63.1 → 1.66.0(official API 读路径实测)。
20
+ - **MCP Registry namespace** 指向 `io.github.zhuzhen-team`(仓库迁移收尾)。
21
+
22
+ ### Test scenarios
23
+
24
+ - 配置 UAT 后调 `list_files`(空参)应列出你"我的空间"根目录且 `viaUser:true`
25
+ - `upload_drive_file` 上传 → `list_files` 拿 file_token → `manage_drive_file(action=delete)` 删除 → 再 `list_files` 确认消失
26
+ - `search_docs` 搜个人空间上传的 PDF 标题应能命中,`page_size`+`offset` 翻页两页无重叠
27
+
7
28
  ## [1.3.15] - 2026-05-31
8
29
 
9
30
  两条增强:文档建表格不再让 agent 猜 block_type;UAT 频繁重新授权的根因(良性 refresh_token 轮换竞态被误判为撤销)修掉。无 schema 变化、无新工具(仍 85)、无 breaking API。升级后重启 Claude Code / Codex 自动拉 v1.3.15。
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "feishu-user-plugin",
3
- "mcpName": "io.github.EthanQC/feishu-user-plugin",
4
- "version": "1.3.15",
3
+ "mcpName": "io.github.zhuzhen-team/feishu-user-plugin",
4
+ "version": "1.3.16",
5
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": {
@@ -64,7 +64,7 @@
64
64
  "@modelcontextprotocol/sdk": "^1.29.0",
65
65
  "dotenv": "^16.4.7",
66
66
  "feishu-docx": "^0.7.0",
67
- "protobufjs": "^7.5.6"
67
+ "protobufjs": "^8.6.0"
68
68
  },
69
69
  "devDependencies": {
70
70
  "husky": "^9.1.7"
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  name: feishu-user-plugin
3
- version: "1.3.15"
4
- description: "All-in-one Feishu MCP server + CLI tool — send messages as yourself (incl. batch_send), read group/P2P chats (auto-expands merge_forward), manage docs/tables/wiki (full CRUD)/drive, OKR (with progress writes), calendar (read+write), Tasks v2, multi-profile auto-switch, real-time WS events. v1.3.15: manage_doc_block gains a table create mode agents stop guessing the table block_type (tables are 31, not 40); the plugin builds the block_type=31 table, fills each cell by updating its auto-created text block (no stray empty blocks), resolves cells scoped (no whole-doc 500-block cap) and fails loud rather than silently dropping content. UAT refresh now self-heals a benign refresh_token rotation race: on invalid_grant it re-reads disk and adopts a peer's freshly-persisted valid token (snapshotting the sent token pre-await for the in-process hot-reload case) instead of false-flipping to UAT_REVOKED and pushing the user through a needless oauth re-consent."
3
+ version: "1.3.16"
4
+ description: "All-in-one Feishu MCP server + CLI tool — send messages as yourself (incl. batch_send), read group/P2P chats (auto-expands merge_forward), manage docs/tables/wiki (full CRUD)/drive, OKR (with progress writes), calendar (read+write), Tasks v2, multi-profile auto-switch, real-time WS events. v1.3.16: discovery reads go UAT-first list_files / search_docs / search_wiki / get_wiki_node previously ran app-token-only, so the bot 403'd on personal-space (我的空间) folders and user-uploaded files were undiscoverable and thus undeletable (manage_drive_file needs a file_token only list_files can provide); now they try your user identity first with bot fallback (+⚠ fallbackWarning) and every response carries viaUser. list_files gains page_size/page_token (+nextPageToken), both search tools gain page_size/offset (+nextOffset cursor; withheld on an abnormal empty page to prevent paging loops). Deps: protobufjs 8.6, lark-sdk 1.66."
5
5
  allowed-tools: send_to_user, send_to_group, send_as_user, send_image_as_user, send_file_as_user, send_post_as_user, batch_send, send_card_as_user, search_contacts, create_p2p_chat, get_chat_info, get_user_info, get_login_status, list_profiles, switch_profile, manage_profile_hints, read_p2p_messages, list_user_chats, list_chats, read_messages, search_messages, send_message_as_bot, reply_message, forward_message, delete_message, update_message, add_reaction, delete_reaction, pin_message, create_group, update_group, list_members, manage_members, search_docs, read_doc, get_doc_blocks, create_doc, manage_doc_block, read_doc_markdown, manage_bitable_app, manage_bitable_table, manage_bitable_field, manage_bitable_view, manage_bitable_record, upload_bitable_attachment, list_wiki_spaces, search_wiki, list_wiki_nodes, get_wiki_node, create_wiki_node, update_wiki_node, move_wiki_node, copy_wiki_node, delete_wiki_node, list_files, create_folder, upload_drive_file, manage_drive_file, upload_image, upload_file, download_message_resource, download_doc_image, list_user_okrs, get_okrs, list_okr_periods, create_okr_progress_record, list_okr_progress_records, delete_okr_progress_record, list_calendars, list_calendar_events, get_calendar_event, create_calendar_event, update_calendar_event, delete_calendar_event, respond_calendar_event, get_freebusy, list_tasks, get_task, create_task, update_task, complete_task, delete_task, manage_task_members, get_new_events, manage_ws_status
6
6
  user_invocable: true
7
7
  ---
@@ -7,18 +7,24 @@
7
7
 
8
8
  ### 列出文件
9
9
  1. 用 `list_files` 列出文件夹内容
10
- - 不传 folder_token 则列出根目录
10
+ - 不传 folder_token 则列出根目录(配置了 UAT 时是**你的**"我的空间"根目录)
11
11
  - 传入 folder_token 则列出指定文件夹
12
+ - 结果多时用 `page_token`(来自上一页的 `nextPageToken`)翻页
12
13
 
13
14
  ### 创建文件夹
14
15
  1. 用 `create_folder` 创建新文件夹
15
16
  - 传入 name 和可选的 parent_token
16
17
 
18
+ ### 删除 / 移动 / 复制文件
19
+ 1. 用 `list_files` 找到目标的 token
20
+ 2. 用 `manage_drive_file` 操作(action=delete/move/copy,必传 type)
21
+
17
22
  ## 示例
18
23
  - `/drive list` — 列出根目录文件
19
24
  - `/drive list folderXxx` — 列出指定文件夹
20
25
  - `/drive create 项目资料` — 在根目录创建文件夹
26
+ - `/drive 删掉根目录里的 xxx.pdf` — list_files 找 token 后 manage_drive_file 删除
21
27
 
22
28
  ## 注意
23
29
  - 使用 Official API,需要 LARK_APP_ID
24
- - 文件列表受机器人权限范围限制
30
+ - `list_files` UAT-first(v1.3.16+):配置了 UAT 就以你的身份列文件(个人空间可见);否则以 bot 身份,只能看到共享给 bot 的文件夹。返回的 `viaUser` 标明视角归属
@@ -11,14 +11,31 @@ module.exports = {
11
11
  // --- Docs ---
12
12
 
13
13
  async searchDocs(query, { pageSize = 10, pageToken } = {}) {
14
- const res = await this._safeSDKCall(
15
- () => this.client.request({
16
- method: 'POST', url: '/open-apis/suite/docs-api/search/object',
17
- data: { search_key: query, count: pageSize, offset: pageToken ? parseInt(pageToken) : 0, owner_ids: [], chat_ids: [], docs_types: [] },
18
- }),
19
- 'searchDocs'
20
- );
21
- return { items: res.data.docs_entities || [], hasMore: res.data.has_more };
14
+ // UAT-first (v1.3.16): the suite search API only indexes docs the calling
15
+ // identity can see. App identity misses everything in the user's personal
16
+ // space the 2026-06-06 "search_docs 搜不到个人空间 PDF" report.
17
+ // Tool args arrive unvalidated clamp to sane non-negative integers so a
18
+ // bad offset can't reach Feishu as NaN/negative or corrupt nextOffset
19
+ // math (Copilot review, PR #115).
20
+ const offset = Math.max(0, parseInt(pageToken, 10) || 0);
21
+ const size = Math.max(1, parseInt(pageSize, 10) || 10);
22
+ const body = { search_key: query, count: size, offset, owner_ids: [], chat_ids: [], docs_types: [] };
23
+ const res = await this._asUserOrApp({
24
+ uatPath: '/open-apis/suite/docs-api/search/object',
25
+ method: 'POST',
26
+ body,
27
+ sdkFn: () => this.client.request({ method: 'POST', url: '/open-apis/suite/docs-api/search/object', data: body }),
28
+ label: 'searchDocs',
29
+ });
30
+ const out = { items: res.data.docs_entities || [], hasMore: res.data.has_more, viaUser: !!res._viaUser };
31
+ // Offset-based cursor — hasMore alone gave callers no way to actually
32
+ // page forward, and UAT-wide search makes truncation likelier (the hidden
33
+ // tail may hold the very personal-space doc the user is hunting).
34
+ // Guard on items.length: an abnormal has_more:true + empty page would
35
+ // otherwise emit nextOffset === offset and stall a paging loop.
36
+ if (res.data.has_more && out.items.length > 0) out.nextOffset = offset + out.items.length;
37
+ if (res._fallbackWarning) out.fallbackWarning = res._fallbackWarning;
38
+ return out;
22
39
  },
23
40
 
24
41
  async readDoc(documentId) {
@@ -8,10 +8,35 @@ module.exports = {
8
8
  // --- Drive ---
9
9
 
10
10
  async listFiles(folderToken, { pageSize = 50, pageToken } = {}) {
11
- const params = { page_size: pageSize, folder_token: folderToken || '' };
11
+ // UAT-first (v1.3.16): the bot identity 403s on personal-space ("我的空间")
12
+ // folders it was never invited to, which made user-uploaded files (UAT
13
+ // upload path) undiscoverable — and therefore undeletable, because
14
+ // manage_drive_file needs a file_token only list_files can provide.
15
+ // Bot fallback keeps bot-shared folders working. (2026-06-06 user report.)
16
+ const size = Math.max(1, parseInt(pageSize, 10) || 50);
17
+ const params = { page_size: size, folder_token: folderToken || '' };
12
18
  if (pageToken) params.page_token = pageToken;
13
- const res = await this._safeSDKCall(() => this.client.drive.file.list({ params }), 'listFiles');
14
- return { items: res.data.files || [], hasMore: res.data.has_more };
19
+ const query = { page_size: String(size), folder_token: folderToken || '' };
20
+ if (pageToken) query.page_token = pageToken;
21
+ const res = await this._asUserOrApp({
22
+ uatPath: '/open-apis/drive/v1/files',
23
+ query,
24
+ sdkFn: () => this.client.drive.file.list({ params }),
25
+ label: 'listFiles',
26
+ });
27
+ const out = { items: res.data.files || [], hasMore: res.data.has_more, viaUser: !!res._viaUser };
28
+ if (res.data.next_page_token) out.nextPageToken = res.data.next_page_token;
29
+ if (res._fallbackWarning) out.fallbackWarning = res._fallbackWarning;
30
+ // Empty + bot path + ROOT listing only: with an empty folder_token the
31
+ // bot lists its OWN root space (usually empty), not the user's 我的空间 —
32
+ // that mismatch is the blind spot worth explaining. A specific
33
+ // folder_token the bot cannot access throws (403) and never reaches here,
34
+ // and a bot-visible folder that is genuinely empty should stay a bare []
35
+ // (Copilot review, PR #115).
36
+ if (out.items.length === 0 && !res._viaUser && !folderToken) {
37
+ out.scopeHint = 'Empty result via app identity: with an empty folder_token the bot lists its OWN root space, not your 我的空间 — your personal files are invisible to it. Run `npx feishu-user-plugin oauth` so list_files can read your own space via UAT.';
38
+ }
39
+ return out;
15
40
  },
16
41
 
17
42
  async createFolder(name, parentToken) {
@@ -28,12 +28,31 @@ module.exports = {
28
28
  return out;
29
29
  },
30
30
 
31
- async searchWiki(query) {
32
- const res = await this._safeSDKCall(
33
- () => this.client.request({ method: 'POST', url: '/open-apis/suite/docs-api/search/object', data: { search_key: query, count: 20, offset: 0, owner_ids: [], chat_ids: [], docs_types: ['wiki'] } }),
34
- 'searchWiki'
35
- );
36
- return { items: res.data.docs_entities || [] };
31
+ async searchWiki(query, { pageSize = 20, offset = 0 } = {}) {
32
+ // UAT-first (v1.3.16): same blind spot as searchDocs — the suite search
33
+ // API only indexes entities the calling identity can see, so the app
34
+ // identity misses wiki nodes in spaces the bot wasn't invited to.
35
+ // Clamp unvalidated tool args (Copilot review, PR #115).
36
+ const safeOffset = Math.max(0, parseInt(offset, 10) || 0);
37
+ const size = Math.max(1, parseInt(pageSize, 10) || 20);
38
+ const body = { search_key: query, count: size, offset: safeOffset, owner_ids: [], chat_ids: [], docs_types: ['wiki'] };
39
+ const res = await this._asUserOrApp({
40
+ uatPath: '/open-apis/suite/docs-api/search/object',
41
+ method: 'POST',
42
+ body,
43
+ sdkFn: () => this.client.request({ method: 'POST', url: '/open-apis/suite/docs-api/search/object', data: body }),
44
+ label: 'searchWiki',
45
+ });
46
+ const out = { items: res.data.docs_entities || [], hasMore: res.data.has_more, viaUser: !!res._viaUser };
47
+ // The suite search API is offset-based; hand the caller a ready-to-use
48
+ // cursor so paging doesn't require manual offset math (UAT-wide search
49
+ // makes truncation likelier — the hidden tail may hold the very
50
+ // personal-space doc the user is hunting).
51
+ // Guard on items.length: see searchDocs — prevents a stalled cursor on an
52
+ // abnormal has_more:true + empty page.
53
+ if (res.data.has_more && out.items.length > 0) out.nextOffset = safeOffset + out.items.length;
54
+ if (res._fallbackWarning) out.fallbackWarning = res._fallbackWarning;
55
+ return out;
37
56
  },
38
57
 
39
58
  // Resolves a wiki node token to its underlying object (docx / sheet / bitable / ...).
@@ -46,8 +65,27 @@ module.exports = {
46
65
  // and returns a synthesized node-shaped result so callers don't have to know
47
66
  // which ID space they're holding.
48
67
  async getWikiNode(nodeToken, _spaceId) {
49
- const res = await this._safeSDKCall(() => this.client.wiki.space.getNode({ params: { token: nodeToken } }), 'getNode');
50
- return res.data.node;
68
+ // UAT-first (v1.3.16): bot identity hits permission errors on spaces it
69
+ // wasn't invited to (same class as listWikiNodes' 131006). The dual-failure
70
+ // error from _asUserOrApp embeds the Feishu code ("as user: code=953001
71
+ // ..."), so the obj_token detection regex in tools/wiki.js keeps working.
72
+ const res = await this._asUserOrApp({
73
+ uatPath: '/open-apis/wiki/v2/spaces/get_node',
74
+ query: { token: nodeToken },
75
+ sdkFn: () => this.client.wiki.space.getNode({ params: { token: nodeToken } }),
76
+ label: 'getNode',
77
+ });
78
+ const node = res.data.node;
79
+ // Keep the bare-node return shape (resolver.js reads obj_token/obj_type
80
+ // off it), but attach identity metadata additively so the get_wiki_node
81
+ // tool surfaces degradation like its 3 sibling discovery reads — without
82
+ // this, a UAT-revoked → bot fallback would silently swallow the warning
83
+ // (json() hoists `fallbackWarning` only when it is on the returned object).
84
+ if (node && typeof node === 'object') {
85
+ node.viaUser = !!res._viaUser;
86
+ if (res._fallbackWarning) node.fallbackWarning = res._fallbackWarning;
87
+ }
88
+ return node;
51
89
  },
52
90
 
53
91
  async listWikiNodes(spaceId, { parentNodeToken, pageToken } = {}) {
package/src/test-all.js CHANGED
@@ -377,6 +377,10 @@ main().catch(console.error).finally(() => {
377
377
  console.error('search-messages: FAIL', e);
378
378
  process.exitCode = 1;
379
379
  });
380
+ require('./test-uat-read-paths').run().catch(e => {
381
+ console.error('uat-read-paths: FAIL', e);
382
+ process.exitCode = 1;
383
+ });
380
384
  require('./test-cli-tool').run();
381
385
  require('./test-lark-desktop').run();
382
386
  require('./test-display-label'); // standalone — runs on require, exits non-zero on fail
@@ -0,0 +1,313 @@
1
+ // src/test-uat-read-paths.js — verify discovery-read paths are UAT-first.
2
+ //
3
+ // Background (2026-06-06 user report): upload_drive_file goes UAT (file owned
4
+ // by the user), but list_files went app-token-only → bot gets 403 on personal
5
+ // space folders ("我的空间"), so uploaded files were undiscoverable and thus
6
+ // undeletable (manage_drive_file needs a file_token the user can't obtain).
7
+ // search_docs had the same blind spot (personal-space files not indexed for
8
+ // the bot identity). searchWiki / getWikiNode shared the app-only pattern.
9
+ //
10
+ // Fix: route listFiles / searchDocs / searchWiki / getWikiNode through
11
+ // _asUserOrApp (UAT-first, bot fallback + fallbackWarning), matching
12
+ // listWikiSpaces / listWikiNodes which were already UAT-first.
13
+ //
14
+ // Tests stub `this._asUserOrApp` at the mixin level (methods are mixed into
15
+ // LarkOfficialClient.prototype; binding them to a fake `this` is the
16
+ // supported seam — same approach as test-via-user.js's fakeCtx).
17
+
18
+ 'use strict';
19
+
20
+ const assert = require('node:assert/strict');
21
+
22
+ const driveMixin = require('./clients/official/drive');
23
+ const docsMixin = require('./clients/official/docs');
24
+ const wikiMixin = require('./clients/official/wiki');
25
+
26
+ // fake `this` for mixin methods. Records _asUserOrApp / _safeSDKCall calls.
27
+ // uatResult is what _asUserOrApp resolves to (shape: legacy asUserOrApp
28
+ // contract — data object with _viaUser + optional _fallbackWarning).
29
+ function fakeClient({ uatResult, sdkResult }) {
30
+ const calls = { asUserOrApp: [], safeSDKCall: [] };
31
+ return {
32
+ calls,
33
+ async _asUserOrApp(opts) {
34
+ calls.asUserOrApp.push(opts);
35
+ return uatResult;
36
+ },
37
+ async _safeSDKCall(fn, label) {
38
+ calls.safeSDKCall.push(label);
39
+ // Default shape covers all four legacy call sites so pre-fix code fails
40
+ // on the routing assertions (clean RED) instead of a TypeError here.
41
+ return sdkResult || { code: 0, data: { files: [], has_more: false, docs_entities: [], node: {} } };
42
+ },
43
+ // SDK surface — only reached via the sdkFn closures, which these tests
44
+ // never execute (the _asUserOrApp stub doesn't call sdkFn).
45
+ client: {
46
+ drive: { file: { list: async () => { throw new Error('sdkFn should not run in these tests'); } } },
47
+ wiki: { space: { getNode: async () => { throw new Error('sdkFn should not run in these tests'); } } },
48
+ request: async () => { throw new Error('sdkFn should not run in these tests'); },
49
+ },
50
+ };
51
+ }
52
+
53
+ async function run() {
54
+ // --- 1. listFiles is UAT-first via _asUserOrApp ---
55
+ {
56
+ const c = fakeClient({
57
+ uatResult: { code: 0, data: { files: [{ token: 'boxcnX', name: 'a.pdf' }], has_more: false }, _viaUser: true },
58
+ });
59
+ const res = await driveMixin.listFiles.call(c, 'fldcnROOT');
60
+ assert.equal(c.calls.asUserOrApp.length, 1, 'listFiles must route through _asUserOrApp (UAT-first)');
61
+ assert.equal(c.calls.safeSDKCall.length, 0, 'listFiles must not call _safeSDKCall directly (app-only blind spot)');
62
+ const opts = c.calls.asUserOrApp[0];
63
+ assert.equal(opts.uatPath, '/open-apis/drive/v1/files', 'listFiles UAT path');
64
+ assert.equal(opts.query.folder_token, 'fldcnROOT');
65
+ assert.ok(opts.sdkFn, 'bot fallback must be preserved');
66
+ assert.equal(res.viaUser, true, 'viaUser surfaced');
67
+ assert.equal(res.items.length, 1);
68
+ }
69
+
70
+ // --- 2. listFiles surfaces fallbackWarning + scopeHint on bot path ---
71
+ {
72
+ const c = fakeClient({
73
+ uatResult: { code: 0, data: { files: [], has_more: false }, _viaUser: false, _fallbackWarning: '⚠️ test-warning' },
74
+ });
75
+ const res = await driveMixin.listFiles.call(c, '');
76
+ assert.equal(res.viaUser, false);
77
+ assert.equal(res.fallbackWarning, '⚠️ test-warning', 'fallbackWarning must surface so ownership blind spot is visible');
78
+ assert.ok(res.scopeHint && /403|个人|personal|my space|我的空间|scope/i.test(res.scopeHint),
79
+ 'empty bot-path result must carry a scopeHint explaining the personal-space blind spot');
80
+ }
81
+
82
+ // --- 3. listFiles passes pagination through ---
83
+ {
84
+ const c = fakeClient({
85
+ uatResult: { code: 0, data: { files: [], has_more: true, next_page_token: 'NPT' }, _viaUser: true },
86
+ });
87
+ const res = await driveMixin.listFiles.call(c, 'fld', { pageSize: 10, pageToken: 'PT' });
88
+ const opts = c.calls.asUserOrApp[0];
89
+ assert.equal(String(opts.query.page_size), '10');
90
+ assert.equal(opts.query.page_token, 'PT');
91
+ assert.equal(res.nextPageToken, 'NPT', 'next_page_token must surface for pagination');
92
+ }
93
+
94
+ // --- 4. searchDocs is UAT-first ---
95
+ {
96
+ const c = fakeClient({
97
+ uatResult: { code: 0, data: { docs_entities: [{ docs_token: 'boxcnY' }], has_more: false }, _viaUser: true },
98
+ });
99
+ const res = await docsMixin.searchDocs.call(c, 'PDF 报告');
100
+ assert.equal(c.calls.asUserOrApp.length, 1, 'searchDocs must route through _asUserOrApp');
101
+ const opts = c.calls.asUserOrApp[0];
102
+ assert.equal(opts.uatPath, '/open-apis/suite/docs-api/search/object');
103
+ assert.equal(opts.method, 'POST');
104
+ assert.equal(opts.body.search_key, 'PDF 报告');
105
+ assert.deepEqual(opts.body.docs_types, [], 'searchDocs searches all types');
106
+ assert.equal(res.viaUser, true);
107
+ assert.equal(res.items.length, 1);
108
+ }
109
+
110
+ // --- 5. searchWiki is UAT-first, scoped to wiki ---
111
+ {
112
+ const c = fakeClient({
113
+ uatResult: { code: 0, data: { docs_entities: [] }, _viaUser: false, _fallbackWarning: '⚠️ w' },
114
+ });
115
+ const res = await wikiMixin.searchWiki.call(c, 'roadmap');
116
+ assert.equal(c.calls.asUserOrApp.length, 1, 'searchWiki must route through _asUserOrApp');
117
+ const opts = c.calls.asUserOrApp[0];
118
+ assert.equal(opts.uatPath, '/open-apis/suite/docs-api/search/object');
119
+ assert.deepEqual(opts.body.docs_types, ['wiki'], 'searchWiki restricted to wiki entities');
120
+ assert.equal(res.viaUser, false);
121
+ assert.equal(res.fallbackWarning, '⚠️ w');
122
+ }
123
+
124
+ // --- 6. getWikiNode is UAT-first and surfaces viaUser ---
125
+ {
126
+ const c = fakeClient({
127
+ uatResult: { code: 0, data: { node: { node_token: 'wikcnZ', obj_type: 'docx' } }, _viaUser: true },
128
+ });
129
+ const node = await wikiMixin.getWikiNode.call(c, 'wikcnZ');
130
+ assert.equal(c.calls.asUserOrApp.length, 1, 'getWikiNode must route through _asUserOrApp');
131
+ const opts = c.calls.asUserOrApp[0];
132
+ assert.equal(opts.uatPath, '/open-apis/wiki/v2/spaces/get_node');
133
+ assert.equal(opts.query.token, 'wikcnZ');
134
+ assert.equal(node.node_token, 'wikcnZ');
135
+ assert.equal(node.viaUser, true, 'getWikiNode must surface viaUser like its 3 sibling reads');
136
+ }
137
+
138
+ // --- 6b. getWikiNode bot fallback must NOT swallow the fallbackWarning ---
139
+ // The warning lives on the top-level data object from withIdentityFallback,
140
+ // not on data.node — without explicit copying, a UAT-revoked → bot fallback
141
+ // silently drops it (caught by multi-agent review of the original commit).
142
+ {
143
+ const c = fakeClient({
144
+ uatResult: { code: 0, data: { node: { node_token: 'wikcnZ', obj_type: 'docx' } }, _viaUser: false, _fallbackWarning: '⚠️ g' },
145
+ });
146
+ const node = await wikiMixin.getWikiNode.call(c, 'wikcnZ');
147
+ assert.equal(node.viaUser, false);
148
+ assert.equal(node.fallbackWarning, '⚠️ g', 'fallbackWarning must survive onto the node so json() hoists it');
149
+ }
150
+
151
+ // --- 7. get_wiki_node handler still synthesizes for obj_tokens on dual failure ---
152
+ // withIdentityFallback dual-failure error message embeds the Feishu code
153
+ // (e.g. "as user: code=953001 ..."). The handler's /95300\d/ detection must
154
+ // keep matching so search_wiki obj_tokens (docxXXX) still resolve.
155
+ {
156
+ const { handlers } = require('./tools/wiki');
157
+ const err = new Error('getNode failed on both identities. as user: code=953001 msg=node not found. as app: getNode failed (953001): invalid token');
158
+ const ctx = {
159
+ getOfficialClient: () => ({
160
+ getWikiNode: async () => { throw err; },
161
+ }),
162
+ };
163
+ const resp = await handlers.get_wiki_node({ node_token: 'docxabcdef' }, ctx);
164
+ const body = JSON.parse(resp.content[0].text);
165
+ assert.equal(body.obj_type, 'docx', 'obj_token synthesis must survive the dual-identity error shape');
166
+ assert.equal(body.obj_token, 'docxabcdef');
167
+ }
168
+
169
+ // --- 7b. synthesis also survives the LIVE error shape (131005, not 95300x) ---
170
+ // Real Feishu instances return code=131005 "not found" for non-wiki tokens
171
+ // (observed in E2E 2026-06-06); only the `node.*not.*found` regex branch
172
+ // catches it. Pin that branch so a regex edit can't silently regress it.
173
+ {
174
+ const { handlers } = require('./tools/wiki');
175
+ const err = new Error('getNode failed on both identities. as user: code=131005 msg=not found. as app: getNode failed (HTTP 400, code=131005): not found');
176
+ const ctx = {
177
+ getOfficialClient: () => ({
178
+ getWikiNode: async () => { throw err; },
179
+ }),
180
+ };
181
+ const resp = await handlers.get_wiki_node({ node_token: 'bascnabcdef' }, ctx);
182
+ const body = JSON.parse(resp.content[0].text);
183
+ assert.equal(body.obj_type, 'bitable', 'live 131005 error shape must still trigger obj_token synthesis');
184
+ assert.equal(body.obj_token, 'bascnabcdef');
185
+ }
186
+
187
+ // --- 10. search pagination: nextOffset cursor surfaces; params pass through ---
188
+ {
189
+ const c = fakeClient({
190
+ uatResult: { code: 0, data: { docs_entities: [{ t: 1 }, { t: 2 }], has_more: true }, _viaUser: true },
191
+ });
192
+ const res = await docsMixin.searchDocs.call(c, 'q', { pageSize: 2, pageToken: '4' });
193
+ assert.equal(c.calls.asUserOrApp[0].body.offset, 4, 'searchDocs offset passthrough');
194
+ assert.equal(c.calls.asUserOrApp[0].body.count, 2, 'searchDocs page size passthrough');
195
+ assert.equal(res.nextOffset, 6, 'searchDocs nextOffset = offset + items returned');
196
+ }
197
+ {
198
+ const c = fakeClient({
199
+ uatResult: { code: 0, data: { docs_entities: [{ t: 1 }], has_more: true }, _viaUser: true },
200
+ });
201
+ const res = await wikiMixin.searchWiki.call(c, 'q', { pageSize: 1, offset: 3 });
202
+ assert.equal(c.calls.asUserOrApp[0].body.offset, 3, 'searchWiki offset passthrough');
203
+ assert.equal(c.calls.asUserOrApp[0].body.count, 1, 'searchWiki page size passthrough');
204
+ assert.equal(res.nextOffset, 4, 'searchWiki nextOffset cursor');
205
+ assert.equal(res.hasMore, true, 'searchWiki must surface hasMore');
206
+ }
207
+ // schema: pagination params exposed on both search tools
208
+ {
209
+ const sd = require('./tools/docs').schemas.find(s => s.name === 'search_docs');
210
+ const sw = require('./tools/wiki').schemas.find(s => s.name === 'search_wiki');
211
+ assert.ok(sd.inputSchema.properties.page_size && sd.inputSchema.properties.offset, 'search_docs schema pagination');
212
+ assert.ok(sw.inputSchema.properties.page_size && sw.inputSchema.properties.offset, 'search_wiki schema pagination');
213
+ }
214
+
215
+ // --- 11. unvalidated args are clamped, never reach Feishu as NaN/negative ---
216
+ // Tool args have no schema validation layer; a bad offset/page_size must be
217
+ // normalized to sane non-negative integers (Copilot review, PR #115).
218
+ {
219
+ const c = fakeClient({
220
+ uatResult: { code: 0, data: { docs_entities: [{ t: 1 }], has_more: true }, _viaUser: true },
221
+ });
222
+ const res = await docsMixin.searchDocs.call(c, 'q', { pageSize: 'abc', pageToken: '-5' });
223
+ const body = c.calls.asUserOrApp[0].body;
224
+ assert.equal(body.offset, 0, 'searchDocs negative offset clamps to 0');
225
+ assert.equal(body.count, 10, 'searchDocs non-numeric page size falls back to default');
226
+ assert.equal(res.nextOffset, 1, 'nextOffset math stays sane after clamping');
227
+ }
228
+ {
229
+ const c = fakeClient({
230
+ uatResult: { code: 0, data: { docs_entities: [], has_more: false }, _viaUser: true },
231
+ });
232
+ await wikiMixin.searchWiki.call(c, 'q', { pageSize: NaN, offset: 'xyz' });
233
+ const body = c.calls.asUserOrApp[0].body;
234
+ assert.equal(body.offset, 0, 'searchWiki non-numeric offset clamps to 0');
235
+ assert.equal(body.count, 20, 'searchWiki NaN page size falls back to default');
236
+ }
237
+
238
+ // --- 11b. abnormal has_more:true + empty page must NOT emit a stalled cursor ---
239
+ // nextOffset === offset would loop a paging caller forever (final release
240
+ // review, v1.3.16). hasMore stays visible; the unusable cursor is withheld.
241
+ {
242
+ const c = fakeClient({
243
+ uatResult: { code: 0, data: { docs_entities: [], has_more: true }, _viaUser: true },
244
+ });
245
+ const res = await docsMixin.searchDocs.call(c, 'q', { pageToken: '5' });
246
+ assert.equal(res.hasMore, true);
247
+ assert.equal(res.nextOffset, undefined, 'searchDocs empty page must not emit nextOffset === offset');
248
+ }
249
+ {
250
+ const c = fakeClient({
251
+ uatResult: { code: 0, data: { docs_entities: [], has_more: true }, _viaUser: true },
252
+ });
253
+ const res = await wikiMixin.searchWiki.call(c, 'q', { offset: 5 });
254
+ assert.equal(res.nextOffset, undefined, 'searchWiki empty page must not emit nextOffset === offset');
255
+ }
256
+
257
+ // --- 11c. explicit offset:0 is honored by the handlers (not dropped as falsy) ---
258
+ {
259
+ const docsHandlers = require('./tools/docs').handlers;
260
+ let got;
261
+ const ctx = { getOfficialClient: () => ({ searchDocs: async (q, opts) => { got = opts; return { items: [] }; } }) };
262
+ await docsHandlers.search_docs({ query: 'q', offset: 0 }, ctx);
263
+ assert.equal(got.pageToken, '0', 'search_docs handler must pass explicit offset:0 through');
264
+ }
265
+ {
266
+ const wikiHandlers = require('./tools/wiki').handlers;
267
+ let got;
268
+ const ctx = { getOfficialClient: () => ({ searchWiki: async (q, opts) => { got = opts; return { items: [] }; } }) };
269
+ await wikiHandlers.search_wiki({ query: 'q', offset: 0 }, ctx);
270
+ assert.equal(got.offset, 0, 'search_wiki handler must pass explicit offset:0 through');
271
+ }
272
+
273
+ // --- 12. scopeHint fires ONLY for empty root listing via bot ---
274
+ // A bot-visible folder that is genuinely empty must stay a bare [] — the
275
+ // blind-spot hint is about the bot's OWN root vs the user's 我的空间
276
+ // (Copilot review, PR #115). 403-on-personal-folder throws and never gets here.
277
+ {
278
+ const c = fakeClient({
279
+ uatResult: { code: 0, data: { files: [], has_more: false }, _viaUser: false },
280
+ });
281
+ const res = await driveMixin.listFiles.call(c, 'fldcnSharedEmpty');
282
+ assert.equal(res.scopeHint, undefined, 'empty bot-visible folder must NOT carry the root blind-spot hint');
283
+ }
284
+
285
+ // --- 8. list_files tool schema exposes pagination + UAT-first semantics ---
286
+ {
287
+ const { schemas } = require('./tools/drive');
288
+ const lf = schemas.find(s => s.name === 'list_files');
289
+ assert.ok(lf.inputSchema.properties.page_size, 'list_files schema: page_size');
290
+ assert.ok(lf.inputSchema.properties.page_token, 'list_files schema: page_token');
291
+ assert.ok(/UAT/i.test(lf.description), 'list_files description must state UAT-first routing');
292
+ }
293
+
294
+ // --- 9. list_files handler passes pagination args through ---
295
+ {
296
+ const { handlers } = require('./tools/drive');
297
+ let got;
298
+ const ctx = {
299
+ getOfficialClient: () => ({
300
+ listFiles: async (folderToken, opts) => { got = { folderToken, opts }; return { items: [], viaUser: true }; },
301
+ }),
302
+ };
303
+ await handlers.list_files({ folder_token: 'fldX', page_size: 25, page_token: 'PT2' }, ctx);
304
+ assert.equal(got.folderToken, 'fldX');
305
+ assert.equal(got.opts.pageSize, 25);
306
+ assert.equal(got.opts.pageToken, 'PT2');
307
+ }
308
+
309
+ console.log('uat-read-paths.js: PASS');
310
+ }
311
+
312
+ if (require.main === module) run().catch(e => { console.error(e); process.exit(1); });
313
+ module.exports = { run };
package/src/tools/docs.js CHANGED
@@ -9,10 +9,14 @@ const { text, json } = require('./_registry');
9
9
  const schemas = [
10
10
  {
11
11
  name: 'search_docs',
12
- description: '[Official API] Search Feishu documents by keyword.',
12
+ description: '[Official API] Search Feishu documents by keyword. UAT-first with app fallback: with user identity (UAT) the search covers docs visible to YOU, including your personal space; via bot it only covers docs shared with the bot. Response carries viaUser; when hasMore is true, pass the returned nextOffset back as offset to page forward.',
13
13
  inputSchema: {
14
14
  type: 'object',
15
- properties: { query: { type: 'string', description: 'Search keyword' } },
15
+ properties: {
16
+ query: { type: 'string', description: 'Search keyword' },
17
+ page_size: { type: 'number', description: 'Max results per page (default 10)' },
18
+ offset: { type: 'number', description: 'Pagination offset from a previous nextOffset' },
19
+ },
16
20
  required: ['query'],
17
21
  },
18
22
  },
@@ -95,7 +99,10 @@ function need(arg, name, action) {
95
99
 
96
100
  const handlers = {
97
101
  async search_docs(args, ctx) {
98
- return json(await ctx.getOfficialClient().searchDocs(args.query));
102
+ const opts = {};
103
+ if (args.page_size) opts.pageSize = args.page_size;
104
+ if (args.offset !== undefined) opts.pageToken = String(args.offset);
105
+ return json(await ctx.getOfficialClient().searchDocs(args.query, opts));
99
106
  },
100
107
  async read_doc(args, ctx) {
101
108
  return json(await ctx.getOfficialClient().readDoc(await ctx.resolveDocId(args.document_id)));
@@ -9,10 +9,14 @@ const { text, json } = require('./_registry');
9
9
  const schemas = [
10
10
  {
11
11
  name: 'list_files',
12
- description: '[Official API] List files in a Drive folder.',
12
+ description: '[Official API] List files in a Drive folder. UAT-first with app fallback: with user identity (UAT), empty folder_token lists YOUR personal-space ("我的空间") root; via bot it can only see folders shared with the bot (personal-space folders return 403). Response carries viaUser so you know whose view you got. Use the returned file token with manage_drive_file to copy/move/delete.',
13
13
  inputSchema: {
14
14
  type: 'object',
15
- properties: { folder_token: { type: 'string', description: 'Folder token (empty for root)' } },
15
+ properties: {
16
+ folder_token: { type: 'string', description: 'Folder token (empty for root — your 我的空间 root when UAT is configured)' },
17
+ page_size: { type: 'number', description: 'Max files per page (default 50)' },
18
+ page_token: { type: 'string', description: 'Pagination token from a previous nextPageToken' },
19
+ },
16
20
  },
17
21
  },
18
22
  {
@@ -66,7 +70,10 @@ function need(arg, name, action) {
66
70
 
67
71
  const handlers = {
68
72
  async list_files(args, ctx) {
69
- return json(await ctx.getOfficialClient().listFiles(args.folder_token));
73
+ const opts = {};
74
+ if (args.page_size) opts.pageSize = args.page_size;
75
+ if (args.page_token) opts.pageToken = args.page_token;
76
+ return json(await ctx.getOfficialClient().listFiles(args.folder_token, opts));
70
77
  },
71
78
  async create_folder(args, ctx) {
72
79
  const r = await ctx.getOfficialClient().createFolder(args.name, args.parent_token);
package/src/tools/wiki.js CHANGED
@@ -10,10 +10,14 @@ const schemas = [
10
10
  },
11
11
  {
12
12
  name: 'search_wiki',
13
- description: '[Official API] Search Wiki nodes by keyword.',
13
+ description: '[Official API] Search Wiki nodes by keyword. UAT-first with app fallback: with user identity (UAT) the search covers wiki spaces visible to YOU; via bot it only covers spaces the bot was invited to. Response carries viaUser; when hasMore is true, pass the returned nextOffset back as offset to page forward.',
14
14
  inputSchema: {
15
15
  type: 'object',
16
- properties: { query: { type: 'string', description: 'Search keyword' } },
16
+ properties: {
17
+ query: { type: 'string', description: 'Search keyword' },
18
+ page_size: { type: 'number', description: 'Max results per page (default 20)' },
19
+ offset: { type: 'number', description: 'Pagination offset from a previous nextOffset' },
20
+ },
17
21
  required: ['query'],
18
22
  },
19
23
  },
@@ -119,7 +123,10 @@ const handlers = {
119
123
  return json(await ctx.getOfficialClient().listWikiSpaces());
120
124
  },
121
125
  async search_wiki(args, ctx) {
122
- return json(await ctx.getOfficialClient().searchWiki(args.query));
126
+ const opts = {};
127
+ if (args.page_size) opts.pageSize = args.page_size;
128
+ if (args.offset !== undefined) opts.offset = args.offset;
129
+ return json(await ctx.getOfficialClient().searchWiki(args.query, opts));
123
130
  },
124
131
  async list_wiki_nodes(args, ctx) {
125
132
  return json(await ctx.getOfficialClient().listWikiNodes(args.space_id, { parentNodeToken: args.parent_node_token }));