Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
450 changes: 450 additions & 0 deletions shortcuts/drive/drive_copy.go

Large diffs are not rendered by default.

1,070 changes: 1,070 additions & 0 deletions shortcuts/drive/drive_copy_test.go

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions shortcuts/drive/shortcuts.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ func Shortcuts() []common.Shortcut {
DriveUpload,
DriveCreateFolder,
DriveCreateShortcut,
DriveCopy,
DriveDownload,
DrivePreview,
DriveCover,
Expand Down
1 change: 1 addition & 0 deletions shortcuts/drive/shortcuts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ func TestShortcutsIncludesExpectedCommands(t *testing.T) {
"+upload",
"+create-folder",
"+create-shortcut",
"+copy",
"+download",
"+preview",
"+cover",
Expand Down
7 changes: 4 additions & 3 deletions skills/lark-drive/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ metadata:

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

> **副本分流规则:** 如果用户要复制在线文档、创建文档副本、把文档复制到另一个文件夹,必须使用 `lark-cli drive files copy`。不要用 `drive +export` 下载后再 `drive +import` 上传,也不要用 `docs +fetch` + `docs +create` 重建正文;导出/导入只用于本地文件转换或离线产物。
> **副本分流规则:** 如果用户要复制在线文档、创建文档副本、把文档复制到另一个文件夹,必须使用 `lark-cli drive +copy`。不要用 `drive +export` 下载后再 `drive +import` 上传,也不要用 `docs +fetch` + `docs +create` 重建正文;导出/导入只用于本地文件转换或离线产物。

## 快速决策

- 用户要把**已有 Wiki 节点移出知识库,放到 Drive 文件夹或“我的空间”根目录**:切到 `lark-wiki`,使用 `lark-cli wiki +move-to-drive`;不要把 Wiki token 直接交给 `drive +move`。这是会改变文档归属和权限继承的写操作,执行前确认源节点与目标位置。
- 用户要**复制文档 / 创建副本 / 另存为副本**时,使用 `lark-cli drive files copy`。先用 `lark-cli schema drive.files.copy --format json` 确认参数;如果来源是 wiki URL/token,先用 `lark-cli drive +inspect` 获取底层 `token` 和 `type`,不要把 wiki token 直接当 `file_token`。`params.file_token` 传源文档 token,`data.folder_token` 传目标文件夹 token,`data.name` 传副本名称,`data.type` 传源文件类型(如 `docx` / `sheet` / `bitable` / `slides`)。示例:`lark-cli drive files copy --params '{"file_token":"<DOC_TOKEN>"}' --data '{"folder_token":"<FOLDER_TOKEN>","name":"<COPY_NAME>","type":"docx"}'`。如返回 `confirmation_required`,按 `lark-shared` 高风险审批协议向用户确认后,在原命令末尾追加 `--yes` 重试
- 用户要**复制文档 / 创建副本 到云盘或者文件夹**时,使用 `lark-cli drive +copy`,用法见 [`references/lark-drive-copy.md`](references/lark-drive-copy.md)。如果是要复制文档 / 创建副本到知识库,使用 `wiki +node-copy`(见 [`lark-wiki-node-copy.md`](../lark-wiki/references/lark-wiki-node-copy.md))
- 用户要**识别飞书 / doubao 云空间 URL 的类型和 token**时,可以先按 URL 路径形态做轻量判断;当路径已明确指向 docx / sheet / bitable / slides / file / folder 等资源时,可直接提取对应 token/type。传入 wiki URL、需要识别标题或 canonical URL、URL/token 有歧义,或后续操作依赖底层真实资源时,再使用 `lark-cli drive +inspect --url '<url>'` 进行识别;具体用法、失败处理和边界见 [`references/lark-drive-inspect.md`](references/lark-drive-inspect.md)。
- 高风险写操作(删除、公开权限修改、owner 转移、版本删除/回滚、批量移动/覆盖/同步)必须同时满足三个条件才执行:目标已解析为该操作可直接使用的执行对象,执行细节已明确到可直接调用命令(例如删除的 file-token/type、公开权限修改的共享范围、owner 转移的目标 owner、版本删除/回滚的 version id、移动/覆盖/同步的目标位置和冲突策略),且用户在本轮明确确认执行这些具体目标和执行细节。用户只说“删除没用的文件”“开放/共享给大家”“改成开放”“覆盖/移动这些”只表示目标状态;先只读发现并列出候选、权限档位或执行方案,停止等待用户确认。
- 用户要**检查 / 治理文档权限、公开范围、链接分享、外部访问、复制下载权限、密级标签、owner 转移**,或要”权限风险报告、收紧权限、申请查看 / 编辑权限、转移 / 批量转移 owner”,必须先阅读 [`references/lark-drive-workflow.md`](references/lark-drive-workflow.md),再按其中 `Workflow Registry` 进入 [`permission_governance`](references/lark-drive-workflow-permission-governance.md) workflow。
Expand Down Expand Up @@ -128,6 +128,7 @@ Shortcut 是对常用操作的高级封装(`lark-cli drive +<verb> [flags]`)
| `+sync` | 双向同步本地目录与 Drive 文件夹:拉取 `new_remote`、推送 `new_local`,`modified` 按 `--on-conflict=remote-wins\|local-wins\|keep-both\|ask` 处理;`--quick` 用修改时间近似比较;`--on-duplicate-remote` 支持 `fail` / `newest` / `oldest`;只同步 `type=file`,跳过在线文档和 shortcut,且不会删除两端多余文件。 |
| [`+push`](references/lark-drive-push.md) | 将本地目录推送到 Drive 文件夹,支持 skip / smart / overwrite 与确认后删除远端。 |
| [`+create-shortcut`](references/lark-drive-create-shortcut.md) | 在另一个文件夹里创建现有 Drive 文件的快捷方式。 |
| [`+copy`](references/lark-drive-copy.md) | 复制资源到目标文件夹;如果要复制到知识库,使用 `wiki +node-copy`; |
| [`+add-comment`](references/lark-drive-add-comment.md) | 给 doc/docx/file/sheet/slides/base(bitable) 添加全文/局部评论;不支持妙搭 apps。 |
| [`+list-comments`](references/lark-drive-list-comments.md) | 分页获取评论列表。 |
| [`+batch-query-comments`](references/lark-drive-batch-query-comments.md) | 按评论 ID 批量获取评论。 |
Expand Down Expand Up @@ -171,7 +172,7 @@ lark-cli drive <resource> <method> [flags] # 调用 API

### files

- `copy` — 复制文件;在线文档创建副本的首选能力,完整参数见上方“快速决策”,不要用 `drive +export` / `drive +import` 绕行复制
- `copy` — 复制文件;优先使用 [`drive +copy`](references/lark-drive-copy.md)
- `create_folder` — 新建文件夹
- `list` — 获取文件夹下的清单;使用前阅读 [`references/lark-drive-files-list.md`](references/lark-drive-files-list.md)
- `patch` — 修改文件标题;优先使用 [`drive +update-title`](references/lark-drive-update-title.md) shortcut
Expand Down
87 changes: 87 additions & 0 deletions skills/lark-drive/references/lark-drive-copy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@

# drive +copy

> **前置条件:** 先阅读 [`../lark-shared/SKILL.md`](../../lark-shared/SKILL.md) 了解认证、全局参数和安全规则。

复制一个 Drive 文件(在线文档、表格、多维表格、幻灯片、思维笔记或普通文件)到目标文件夹,生成一个内容相同的新副本。

## 命令

```bash
# 源文档传 URL(自动识别类型和 token)
lark-cli drive +copy --url "https://example.larksuite.com/docx/<DOCX_TOKEN>" --name '副本名称' --folder-token <TARGET_FOLDER_TOKEN>

# Wiki URL(自动解包底层资源后复制到 Drive)
lark-cli drive +copy --url "https://example.larksuite.com/wiki/<WIKI_TOKEN>" --name '副本名称' --folder-token <TARGET_FOLDER_TOKEN>

# Wiki token
lark-cli drive +copy --token <WIKI_TOKEN> --type wiki --name '副本名称' --folder-token my_space
```

## 参数

| 参数 | 必填 | 说明 |
|------|------|------|
| `--url` | 与 `--token` 二选一 | 源文档 URL,支持 `doc` / `docx` / `sheet` / `file` / `mindnote` / `slides` / `base` / `bitable` / `wiki` 路径;wiki 会自动解包底层资源 |
| `--token` | 与 `--url` 二选一 | 源文档 token 或 URL;裸 token 必须配合 `--type` |
| `--type` | 裸 token 时必填 | 源文件类型:`doc`、`docx`、`sheet`、`file`、`mindnote`、`slides`、`bitable`(`base` 为兼容别名)或 `wiki`;传 URL 时可省略,显式传入时必须与 URL 类型一致 |
| `--name` | 是 | 副本名称,最长 256 字节 |
| `--folder-token` | 是 | 目标文件夹 token、文件夹 URL,或常量 `my_space`(复制到当前身份"我的空间"根目录,内部自动解析根 token) |
| `--extra` | 否 | 可重复的 `key=value` 对,原样透传给 API 的 `extra` 自定义复制参数;典型用法 `--extra target_type=docx`(复制旧版 doc 时转换为 docx 副本) |

## 输入规则

- `--url` 与 `--token` 互斥,只传一个
- `--type` 必须与源文件真实类型一致,类型不匹配时服务端会返回失败
- `base` 与 `bitable` 是同一概念,CLI 会把 `base` 归一化为 `bitable` 后发给服务端
- 目标文件夹必须是云空间(云盘/云存储)文件夹 token,不能传 wiki 节点 token

## Wiki 场景

`drive +copy` 接受 wiki URL,也接受 `--token <WIKI_TOKEN> --type wiki`。目标仅支持云盘(Drive)文件夹或 `my_space` 根目录;要把副本留在知识库中,使用 `wiki +node-copy`。

## 行为说明
Comment thread
zzzchao123 marked this conversation as resolved.

- bot 身份复制成功后,CLI 会自动尝试给当前 CLI 用户授予新副本的 `full_access`,结果在输出的 `data.permission_grant` 字段中;授权失败不影响复制本身的成功状态

## 输出
Comment thread
zzzchao123 marked this conversation as resolved.

```json
{
Comment thread
zzzchao123 marked this conversation as resolved.
"ok": true,
"identity": "bot",
"data": {
"copied": true,
"file_token": "<new_file_token>",
"file_type": "docx",
"name": "副本名称",
"url": "https://example.larksuite.com/docx/<new_file_token>",
"source_file_token": "<source_file_token>",
"source_type": "docx",
"source_wiki_token": "<source_wiki_token, only for wiki input>",
"folder_token": "<target_folder_token>",
"permission_grant": {
"status": "granted",
"perm": "full_access",
"member_type": "openid",
"user_open_id": "<current_user_open_id>",
"message": "Granted the current CLI user full_access on the new document."
}
}
}
```

`source_wiki_token` 仅 wiki 输入出现;`permission_grant` 仅 bot 身份出现,user 身份复制时 `data` 下没有该字段。

## 常见错误

| 错误码 | 含义 | 处理 |
|---|---|---|
| `99991672` / `99991679` | 缺失 scope | 按错误里的 `missing_scopes`、`hint` 申请/授权所需 scope 后重试 |
| `99991400` | 命中接口限频 | 等待一段时间后重试;批量复制时保持串行并降低频率 |

## 参考

- [lark-drive](../SKILL.md) -- 云空间(云盘/云存储)全部命令
- [lark-wiki](../../lark-wiki/SKILL.md) -- 知识库节点复制(`wiki +node-copy`)
- [lark-shared](../../lark-shared/SKILL.md) -- 认证和全局参数
Loading
Loading