通过语雀 OpenAPI 管理知识库文档。支持文档 CRUD、目录查看和智能增量同步。
始终使用用户输入的语言进行回复。 如果用户用英文提问,则全程用英文回复;如果用户用中文,则全程用中文回复。无法判断时默认使用中文。CLI 输出为固定英文格式,转述给用户时需翻译为用户使用的语言(保留 flag 名称、slug、路径等字面值不翻译)。
This skill does NOT own:
requests and python-dotenv installed.
.env file in the project root (created via the setup flow below).
If the user has not configured this skill yet (no .env file, or list returns a config error), follow this flow:
> Please paste your Yuque knowledge base URL, for example: https://xxx.yuque.com/group/book
>
> You can find it by opening your knowledge base in the browser and copying the address bar URL.
> Please paste your Yuque API token.
>
> To create one: open Yuque -> click your avatar (top right) -> "Account Settings" -> "Tokens" -> "Create new token". Grant it read/write access to your target knowledge base.
>
> Token page: https://www.yuque.com/settings/tokens
```bash
python scripts/yuque_cli.py setup --url "
```
.env is written, connection is verified, .gitignore is checked.
--force to overwrite an existing .env.
python scripts/yuque_cli.py list.
.env to git. The setup script checks .gitignore and warns if .env is not excluded.
.env.
python scripts/yuque_cli.py list to confirm token and repo are valid.
scripts/yuque_cli.py with the matching subcommand.
list, get, or toc to confirm the operation succeeded.
| Action | Command | Key flags |
|--------|---------|-----------|
| Setup | python scripts/yuque_cli.py setup --url URL --token TOKEN | --force, --env-path |
| List | python scripts/yuque_cli.py list | --offset, --limit |
| Get | python scripts/yuque_cli.py get | |
| Create | python scripts/yuque_cli.py create -t "Title" -b "Body" | -f FILE, --no-toc, --format, --slug |
| Update | python scripts/yuque_cli.py update | -b, -f FILE, --format |
| Delete | python scripts/yuque_cli.py delete | --confirm required (not optional) |
| TOC | python scripts/yuque_cli.py toc | |
| Sync | python scripts/yuque_cli.py sync | --check, --root, --layout, --on-missing |
| Pull | python scripts/yuque_cli.py pull --slug | --all, --overwrite, --root, --layout |
| Status | python scripts/yuque_cli.py status | --root, --layout |
Global flags available on all commands: --json (machine-readable output), --dry-run (preview without executing).
> Dry-run mode always outputs JSON regardless of the --json flag. Use it to inspect the payload before committing.
Use sync for "push only what actually changed" instead of blind update. The script maintains .yuque-sync.json (auto-added to .gitignore) tracking each doc's local content hash and remote latest_version_id, so unchanged docs are skipped without any GET-detail call.
When the user runs sync/pull/status and no state file exists, the script auto-detects the local layout from .md files under --root (default cwd):
.md files at top level. Slug = file stem.
.md files under subdirectories. Slug = file stem (subdirs are organizational only; they do not create TOC groups).
--- slug: xxx --- frontmatter at the top. Slug = frontmatter value.
.md files yet; suggest pull --all to seed locally.
If layouts are mixed or partially-frontmatter, the script errors and asks the user to pass --layout flat|nested|frontmatter or normalize the directory.
optional_properties=latest_version_id) — no per-doc GET.
latest_version_id to the values stored in .yuque-sync.json.
create for local files with no remote counterpart (auto-adds to TOC).
update for local files whose body changed and remote did not.
sync exits 2 when local files that were previously synced are now missing. This is not an error — it means the script needs an explicit choice from the user. The stdout block describes three options, each with the exact flag to re-run with:
--on-missing delete — delete on Yuque too
--on-missing pull — restore locally from Yuque
--on-missing forget — keep on Yuque, drop from local state
When you see exit code 2, show the printed block to the user (translated to their query language; see Language section), then re-invoke sync --on-missing once they pick.
If a doc was changed both locally and remotely (or remote moved while local stayed), sync lists it under "Conflicts" and skips it. Resolve manually:
pull --slug --overwrite — accept remote version locally.
update -f path/to/file.md — overwrite remote with local version.
After resolution, the next sync run will reconcile the state file.
.env.
setup with the correct URL.
.env is protected.
--title, --body, --body-file, --slug, --format, --public must be given.
--confirm.
sync exit code 2: Not an error. Confirmation required for missing-local files. Show the block to the user, get their choice, re-run with --on-missing .
--layout for them — ask which structure they intend.
Do NOT guess doc IDs or slugs. If unknown, run list, toc, or status first to find the target.
references/yuque-cli.md — 全部命令详细说明,按场景分组
scripts/yuque_cli.py — CLI 工具本体,运行它;除非调试,不要直接阅读源码
scripts/yuque_cli.py --help 和 scripts/yuque_cli.py --help 查看完整 flag 说明
.env 存储凭据(不得提交到版本控制)
append_doc_to_toc. Use --no-toc only if you explicitly want an unlisted document.
id parameter in get/update/delete can be either an integer doc ID or a string slug. Both work, but slugs are more readable.
--body-file instead of --body for any non-trivial content to avoid shell quoting issues.
--format markdown (the default) unless the user specifically needs Lake format.
sync ignores remote drafts (body_draft). Change detection is based on latest_version_id (the last published version). If a teammate is editing in the Yuque web editor without publishing, that draft will be overwritten by sync update. If you suspect this, use pull --slug --overwrite to inspect remote first.
sync will only delete remotely when the user explicitly passes --on-missing delete after seeing the confirmation block. Do not pass delete on the user's behalf without an unambiguous yes.
共 1 个版本