Lark drive

From ZyanWan/Skill-Hub · View interactive version

Lark drive is an AI agent skill from the GitHub repository ZyanWan/Skill-Hub. 飞书云空间(云盘/云存储):管理云空间(云盘/云存储)中的文件和文件夹。上传和下载文件、创建文件夹、复制/移动/删除文件、查看文件元数据、管理文档评论、管理文档权限、订阅用户评论变更事件、修改文件标题(docx、sheet、bitable、file、folder、wiki);也负责把本地 Word/Markdown/Excel/CSV/PPTX 以及 Base 快照(.base)导入为飞书在线云文档(docx、sheet、bitable、slides)。当用户需要上传或下载文件、整理云空间(云盘/云存储)目录、查看文件详情、管理评论、管理文档权限、修改文件标题、订阅用户评论变更事件,或要把本地

How to use this skill

Skill file

drive (v1)

CRITICAL — 开始前 MUST 先用 Read 工具读取 CODE0,其中包含认证、权限处理

术语说明: 飞书云空间也常被称为"云盘"或"云存储",三者指的是同一个产品,是飞书官方的云端文件存储与管理中心。

导入分流规则: 如果用户要把本地 Excel / CSV / .base 快照导入成 Base / 多维表格 / bitable,必须优先使用 lark-cli drive +import --type bitable。不要先切到 lark-base;lark-base 只负责导入完成后的表内操作。

快速决策

修改标题

核心概念

文档类型与 Token

飞书开放平台中,不同类型的文档有不同的 URL 格式和 Token 处理方式。在进行文档操作(如添加评论、下载文件等)时,必须先获取正确的 file_token。

文档 URL 格式与 Token 处理

| URL 格式 | 示例 | Token 类型 | 处理方式 |

|----------|---------------------------------------------------------|-----------|----------|

| /docx/ | https://example.larksuite.com/docx/doxcnxxxxxxxxx | file_token | URL 路径中的 token 直接作为 file_token 使用 |

| /doc/ | https://example.larksuite.com/doc/doccnxxxxxxxxx | file_token | URL 路径中的 token 直接作为 file_token 使用 |

| /wiki/ | https://example.larksuite.com/wiki/wikcnxxxxxxxxx | wiki_token | ⚠️ 不能直接使用,需要先查询获取真实的 obj_token |

| /sheets/ | https://example.larksuite.com/sheets/shtcnxxxxxxxxx | file_token | URL 路径中的 token 直接作为 file_token 使用 |

| /drive/folder/ | https://example.larksuite.com/drive/folder/fldcnxxxx | folder_token | URL 路径中的 token 作为文件夹 token 使用 |

Wiki 链接特殊处理(关键!)

知识库链接(/wiki/TOKEN)背后可能是云文档、电子表格、多维表格等不同类型的文档。不能直接假设 URL 中的 token 就是 file_token,必须先查询实际类型和真实 token。

处理流程

推荐方式:使用 drive +inspect 自动解包

lark-cli drive +inspect --url 'https://xxx.feishu.cn/wiki/wikcnXXX'

返回结果包含 type(底层文档类型)、token(真实 file_token)、title、url 等字段,直接用于后续操作。

手动方式:使用 wiki.spaces.get_node 查询节点信息

  1. 使用 wiki.spaces.get_node 查询节点信息

```bash

lark-cli wiki spaces get_node --params '{"token":"wiki_token"}'

```

  1. 从返回结果中提取关键信息
  1. 根据 obj_type 使用对应的 API

| obj_type | 说明 | 使用的 API |

|----------|------|-----------|

| docx | 新版云文档 | drive file.comments.*、docx.* |

| doc | 旧版云文档 | drive file.comments.* |

| sheet | 电子表格 | sheets.* |

| bitable | 多维表格 | bitable.* |

| slides | 幻灯片 | drive.* |

| file | 文件 | drive.* |

| mindnote | 思维导图 | drive.* |

查询示例
# 查询 wiki 节点
lark-cli wiki spaces get_node --params '{"token":"wiki_token"}'

返回结果示例:

{
  "node": {
    "obj_type": "docx",
    "obj_token": "xxxx",
    "title": "标题",
    "node_type": "origin",
    "space_id": "12345678910"
  }
}

资源关系

Wiki Space (知识空间)
└── Wiki Node (知识库节点)
    ├── obj_type: docx (新版文档)
    │   └── obj_token (真实文档 token)
    ├── obj_type: doc (旧版文档)
    │   └── obj_token (真实文档 token)
    ├── obj_type: sheet (电子表格)
    │   └── obj_token (真实文档 token)
    ├── obj_type: bitable (多维表格)
    │   └── obj_token (真实文档 token)
    └── obj_type: file/slides/mindnote
        └── obj_token (真实文档 token)

Drive Folder (云空间/云盘/云存储文件夹)
└── File (文件/文档)
    └── file_token (直接使用)

常见操作 Token 需求

| 操作 | 需要的 Token | 说明 |

|------|-------------|------|

| 读取文档内容 | file_token / 通过 docs +fetch --api-version v2 自动处理 | docs +fetch --api-version v2 支持直接传入 URL |

| 添加局部评论(划词评论) | file_token | 传 --block-id 时,drive +add-comment 会创建局部评论;docx 支持文本定位或 block_id,sheet 使用 <sheetId>!<cell>,slides 使用 <slide-block-type>!<xml-id>,且都支持最终解析到对应类型的 wiki URL;Drive file 不支持局部评论 |

| 添加全文评论 | file_token | 不传 --block-id 时,drive +add-comment 默认创建全文评论;支持 docx、旧版 doc URL、白名单扩展名的 Drive file,以及最终解析为 doc/docx/file 的 wiki URL |

| 下载文件 | file_token | 从文件 URL 中直接提取 |

| 上传文件 | folder_token / wiki_node_token | 目标位置的 token |

| 列出文档评论 | file_token | 同添加评论 |

评论能力边界(关键!)

评论查询与统计口径(关键!)

强制规则:drive file.comments list 默认必须传 is_solved:false,即仅查询未解决评论。即使用户说“所有评论”“全部评论”“把评论都列出来”,只要没有明确提到要包含已解决评论,仍然按默认口径查询未解决评论。仅当用户明确要求包含已解决评论时,才可省略 is_solved 参数。

正确示例:

# 默认查询:仅未解决评论(推荐)
lark-cli drive file.comments list --params '{"file_token": "xxx", "file_type": "docx", "is_solved": false}'

# 查询所有评论(用户未明确要求包含已解决评论)
lark-cli drive file.comments list --params '{"file_token": "xxx", "file_type": "docx", "is_solved": false}'

# 包含已解决评论(需用户明确要求)
lark-cli drive file.comments list --params '{"file_token": "xxx", "file_type": "docx"}'

错误示例:

# 不推荐:用户未明确要求但查询所有评论
lark-cli drive file.comments list --params '{"file_token": "xxx", "file_type": "docx"}'

评论业务特性与引导(关键!)

Review 场景评论落点
评论排序引导
评论回复限制
批量查询与列表查询的选择
Reaction / 表情场景

典型错误与解决方案

| 错误信息 | 原因 | 解决方案 |

|----------|------|----------|

| not exist | 使用了错误的 token | 检查 token 类型,wiki 链接必须先查询获取 obj_token |

| permission denied | 没有相关操作权限 | 引导用户检查当前身份对文档/文件是否有相应操作权限;如果需要,可以授予相应权限 |

| invalid file_type | file_type 参数错误 | 根据 obj_type 传入正确的 file_type(docx/doc/sheet/slides) |

`permission.public.patch` 错误码引导

调用 lark-cli drive permission.public patch 更新文档公开权限失败时,如果返回以下错误码,按表格给用户明确下一步。不要把这些错误简单归类为缺少 scope;它们通常表示租户、对外分享或文档密级策略拦截。

| 错误码 | 含义 | 给用户的引导 |

|--------|------------------------|--------------|

| 91009 | 对外分享被租户安全策略管控,当前用户无法开启 | 提示用户:对外分享能力被租户安全策略统一管控,无法通过 API 或当前用户直接开启;需要联系租户管理员调整组织级对外分享策略。 |

| 91010 | 文档对外分享未打开 | 提示用户:当前文档尚未打开对外分享,请先在文档权限设置中打开对外分享,再重试 permission.public.patch。 |

| 91011 | 对外分享被文档密级管控 | 提示用户:对外分享被密级策略拦截,需要打开目标文档,在文档内发起密级豁免或进行密级降级后再重试;回复中必须给出目标文档 URL。 |

| 91012 | 权限设置被文档密级管控 | 提示用户:该权限设置被密级策略拦截,需要打开目标文档,在文档内发起密级豁免或进行密级降级后再重试;回复中必须给出目标文档 URL。 |

当用户最初提供的是文档 URL,遇到 91011 或 91012 时直接把该 URL 原样返回给用户作为操作入口;如果上下文只有 token,需要先尽量通过已有上下文、搜索结果或元数据恢复目标文档 URL,再给出可点击的文档 URL。

授权当前应用访问文档

当需要将文档权限授予当前应用(bot)自身时,先通过 bot info 接口获取应用的 open_id,再调用权限接口授权:

# 1. 获取当前应用的 open_id
lark-cli api GET /open-apis/bot/v3/info --as bot
# 从返回值中取 bot.open_id

# 2. 授权当前应用访问文档
lark-cli drive permission.members create \
  --params '{"token":"<doc_token>","type":"<resource_type>"}' \
  --data '{"member_type":"openid","member_id":"<bot_open_id>","perm":"view","type":"user"}'

注意:此方式仅适用于需要授权给当前应用的场景。授权给其他用户时,直接使用对方的 open_id 即可,无需调用 bot info 接口。

<resource_type> 可选值:doc、docx、sheet、bitable、file、folder、wiki、slides。

Shortcuts(推荐优先使用)

Shortcut 是对常用操作的高级封装(lark-cli drive +<verb> [flags])。有 Shortcut 的操作优先使用。

| Shortcut | 说明 |

|----------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|

| CODE0 | Search Lark docs, Wiki, and spreadsheet files with flat filter flags. Natural-language-friendly: --edited-since, --mine, --doc-types, etc. |

| CODE0 | Upload a local file to a Drive folder or wiki node |

| CODE0 | Create a Drive folder, optionally under a parent folder, with bot auto-grant support |

| CODE0 | Download a file from Drive to local |

| CODE0 | Compare a local directory with a Drive folder by exact SHA-256 hash by default, or use --quick for a best-effort modified-time diff that skips remote downloads; reports new_local / new_remote / modified / unchanged plus detection=exact or detection=quick. Duplicate remote rel_path conflicts fail fast with error.type=duplicate_remote_path and list every conflicting entry; do not proceed as if one was chosen. --local-dir 必须是 cwd 内的相对路径,越界路径 CLI 会直接拒绝;目标在 cwd 外时引导用户切换 agent 工作目录,不要私自 cd 绕过。 |

| CODE0 | File-level Drive → local mirror. Duplicate remote rel_path conflicts fail by default; for duplicate files, rename downloads all copies with stable hashed suffixes, while newest / oldest pick one. --if-exists supports overwrite / smart / skip (smart is a best-effort modified-time incremental mode for repeat syncs). --delete-local requires --yes, only removes regular files, and is skipped after item failures. --local-dir must stay inside cwd. |

| +sync | Two-way local ↔ Drive sync. Reuses +status diff buckets, pulls new_remote, pushes new_local, and resolves modified via --on-conflict=remote-wins|local-wins|keep-both|ask. --quick enables best-effort modified-time diffing (timestamp mismatches can still trigger real pull/push actions), --on-duplicate-remote supports fail|newest|oldest, and the command is intentionally non-destructive (no delete on either side). |

| CODE0 | Create a shortcut to an existing Drive file in another folder |

| CODE0 | Add a comment to doc/docx/file/sheet/slides, also supports wiki URL resolving to doc/docx/file/sheet/slides; file targets support selected extensions and full comments only |

| CODE0 | Export a doc/docx/sheet/bitable/slides to a local file with limited polling; supports --file-name for local naming |

| CODE0 | Download an exported file by file_token |

| CODE0 | Import a local file to Drive as a cloud document (docx, sheet, bitable, slides) |

| CODE0 | List historical versions of a file with only_tag=true and cursor-based pagination |

| CODE0 | Download a specific historical version of a file |

| CODE0 | Revert a file to a specific historical version |

| CODE0 | Delete a specific historical version of a file |

| CODE0 | Move a file or folder to another location in Drive |

| CODE0 | Delete a Drive file or folder with limited polling for folder deletes |

| CODE0 | File-level local → Drive mirror. Duplicate remote rel_path conflicts fail by default; newest / oldest only apply to duplicate files when you explicitly want to target one remote file. --if-exists supports skip / smart / overwrite (smart skips files whose remote modified_time is already up to date, but falls through to the same overwrite path when the remote is older, so it inherits overwrite's rollout caveat). --delete-remote requires --yes. --local-dir must stay inside cwd. |

| CODE0 | Poll async task result for import, export, move, or delete operations |

| CODE0 | Inspect a Lark document URL to get its type, title, and canonical token; auto-unwraps wiki URLs to the underlying document |

| CODE0 | Apply to the document owner for view/edit access (user-only; 5/day per document) |

| CODE0 | List secure labels available to the current user |

| CODE0 | Update a Drive file/document secure label; downgrade approval errors require opening the document UI |

API Resources

lark-cli schema drive.<resource>.<method>   # 调用 API 前必须先查看参数结构
lark-cli drive <resource> <method> [flags] # 调用 API

重要:使用原生 API 时,必须先运行 schema 查看 --data / --params 参数结构,不要猜测字段格式。

files

file.comments

file.comment.replys

permission.members

metas

user

file.statistics

file.view_records

file.comment.reply.reactions

权限表

| 方法 | 所需 scope |

|------------------------------------------------|-----------------------------------|

| files.copy | docs:document:copy |

| files.create_folder | space:folder:create |

| files.list | space:document:retrieve |

| files.patch | docx:document:write_only |

| file.comments.batch_query | docs:document.comment:read |

| file.comments.create_v2 | docs:document.comment:create |

| file.comments.list | docs:document.comment:read |

| file.comments.patch | docs:document.comment:update |

| file.comment.replys.create | docs:document.comment:create |

| file.comment.replys.delete | docs:document.comment:delete |

| file.comment.replys.list | docs:document.comment:read |

| file.comment.replys.update | docs:document.comment:update |

| permission.members.auth | docs:permission.member:auth |

| permission.members.create | docs:permission.member:create |

| permission.members.transfer_owner | docs:permission.member:transfer |

| permission.public.get | docs:permission.setting:read |

| permission.public.patch | docs:permission.setting:write_only |

| metas.batch_query | drive:drive.metadata:readonly |

| user.remove_subscription | docs:event:subscribe |

| user.subscription | docs:event:subscribe |

| user.subscription_status | docs:event:subscribe |

| file.statistics.get | drive:drive.metadata:readonly |

| file.view_records.list | drive:file:view_record:readonly |

| file.comment.reply.reactions.update_reaction | docs:document.comment:create |

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.