yuque-cookie-plugin 0.1.0

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.
@@ -0,0 +1,580 @@
1
+ # Yuque Cookie Plugin 中文使用指南
2
+
3
+ ## 1. 项目定位
4
+
5
+ `yuque-cookie-plugin` 是一个本地 CLI 工具,目标是让 AI 通过浏览器同款 Web Session 操作语雀,而不是走语雀 personal token、OpenAPI token、Skill 或 MCP。
6
+
7
+ 核心认证方式:
8
+
9
+ - `_yuque_session`
10
+ - `yuque_ctoken`
11
+
12
+ 这两个值来自你浏览器里已经登录语雀后的 Cookie。工具会把它们保存到本机用户配置目录:
13
+
14
+ ```bash
15
+ ~/.config/yuque-cookie-plugin/config.json
16
+ ```
17
+
18
+ 项目目录不会保存真实 Cookie。
19
+
20
+ ## 2. 安装和准备
21
+
22
+ 进入项目目录:
23
+
24
+ ```bash
25
+ cd /home/mi/文档/yuque-cookie-plugin
26
+ ```
27
+
28
+ 安装依赖:
29
+
30
+ ```bash
31
+ npm install
32
+ ```
33
+
34
+ 检查工具是否可运行:
35
+
36
+ ```bash
37
+ npm run yuque-local -- --help
38
+ ```
39
+
40
+ ## 3. 登录
41
+
42
+ 运行:
43
+
44
+ ```bash
45
+ npm run yuque-local -- auth login
46
+ ```
47
+
48
+ 命令会打开本地网页,地址类似:
49
+
50
+ ```text
51
+ http://127.0.0.1:34567/
52
+ ```
53
+
54
+ 在网页中填写:
55
+
56
+ - 语雀个人/团队主页 URL,例如 `https://www.yuque.com/your-login/`
57
+ - `_yuque_session`
58
+ - `yuque_ctoken`
59
+
60
+ 保存后页面会显示 `Saved`,CLI 会自动退出。
61
+
62
+ 配置文件会记录:
63
+
64
+ - `saved_at`
65
+ - `updated_at`
66
+ - `homeUrl`
67
+ - `last_validated_at`
68
+ - `last_failed_at`
69
+ - `last_validation_error`
70
+
71
+ 验证配置是否可用:
72
+
73
+ ```bash
74
+ npm run yuque-local -- auth status https://www.yuque.com/<your-login>/<your-book> --json
75
+ ```
76
+
77
+ 成功时会输出 `valid: true`,并更新 `last_validated_at`。失败时会输出 `valid: false`,记录失败时间,并提示重新运行登录命令。
78
+
79
+ 也可以只查看本地配置状态:
80
+
81
+ ```bash
82
+ npm run yuque-local -- auth status --json
83
+ ```
84
+
85
+ Docker、SSH、远程服务器等无头环境中,推荐使用手动模式,不依赖端口映射或自动打开浏览器:
86
+
87
+ ```bash
88
+ yuque-local auth login --manual
89
+ ```
90
+
91
+ 正常执行 `inspect`、`snapshot`、`download-book`、`download-doc` 等真实语雀命令成功后,也会刷新 `last_validated_at`。如果检测到 401、403、页面无法解析等登录态问题,CLI 会提示重新登录。
92
+
93
+ ### 额外 Cookie
94
+
95
+ 默认认证仍然是:
96
+
97
+ - `_yuque_session`
98
+ - `yuque_ctoken`
99
+
100
+ 如果遇到企业私有语雀或公开密码访问场景,需要额外 Cookie,例如 `verified_books`,可以在命令中临时传入:
101
+
102
+ ```bash
103
+ npm run yuque-local -- inspect https://www.yuque.com/user/book \
104
+ --cookie-key verified_books \
105
+ --cookie-value '<cookie-value>'
106
+ ```
107
+
108
+ 也可以使用环境变量:
109
+
110
+ ```bash
111
+ export YUQUE_EXTRA_COOKIE_KEY='verified_books'
112
+ export YUQUE_EXTRA_COOKIE_VALUE='<cookie-value>'
113
+ ```
114
+
115
+ 额外 Cookie 不会改变本项目的主链路,只用于兼容特殊访问场景。
116
+
117
+ ## 4. 下载整个知识库
118
+
119
+ 推荐先下载到临时目录验证:
120
+
121
+ ```bash
122
+ npm run yuque-local -- download-book https://www.yuque.com/<your-login>/<your-book> --dist-dir /tmp/yuque-download-test --incremental
123
+ ```
124
+
125
+ 输出会显示逐篇进度:
126
+
127
+ ```text
128
+ Downloading book "工控" (15 docs) -> /tmp/yuque-download-test/工控
129
+ [1/15] 工厂工程师学C#,第一天能干啥?
130
+ saved: 工厂工程师学C#,第一天能干啥?.md
131
+ ```
132
+
133
+ 完成后会输出 JSON 摘要:
134
+
135
+ ```json
136
+ {
137
+ "ok": true,
138
+ "docs": 15,
139
+ "downloaded": 15,
140
+ "skipped": 0,
141
+ "failures": []
142
+ }
143
+ ```
144
+
145
+ 第二次使用 `--incremental` 时,如果文档没有变化,会跳过:
146
+
147
+ ```json
148
+ {
149
+ "downloaded": 0,
150
+ "skipped": 15
151
+ }
152
+ ```
153
+
154
+ 下载产物包括:
155
+
156
+ - Markdown 文档
157
+ - `index.md`
158
+ - `progress.json`
159
+ - `img/`
160
+ - `attachments/`
161
+ - 本地报告 `reports/download-book-*.json`
162
+
163
+ 如果部分文档失败,最终 JSON 和本地报告会包含 `retry`:
164
+
165
+ ```json
166
+ {
167
+ "retry": {
168
+ "command": "download-doc",
169
+ "urls": ["https://www.yuque.com/user/book/failed-doc"],
170
+ "args": ["download-doc", "https://www.yuque.com/user/book/failed-doc", "--dist-dir", "download"]
171
+ }
172
+ }
173
+ ```
174
+
175
+ AI 或脚本可以用 `retry.args` 只重试失败文档。
176
+
177
+ 如果文档下载成功,但图片、附件或音视频资源下载失败,最终 JSON 和报告会包含 `warning_summary`:
178
+
179
+ ```json
180
+ {
181
+ "warning_summary": {
182
+ "total": 1,
183
+ "by_type": {
184
+ "attachment": 1
185
+ },
186
+ "retryable_resources": [
187
+ {
188
+ "type": "attachment",
189
+ "url": "https://www.yuque.com/attachments/error.pdf"
190
+ }
191
+ ]
192
+ }
193
+ }
194
+ ```
195
+
196
+ 这表示主文档已经保存,但资源需要后续人工检查或单独补救。
197
+
198
+ 下载成功后,最终 JSON 和报告还会包含 `resources`,用于让 AI 或脚本确认图片、附件、音视频等资源实际落盘情况:
199
+
200
+ ```json
201
+ {
202
+ "resources": {
203
+ "total": 2,
204
+ "by_type": {
205
+ "image": 1,
206
+ "attachment": 1
207
+ },
208
+ "total_size": 146111,
209
+ "files": [
210
+ {
211
+ "type": "attachment",
212
+ "path": "attachments/123459/test.pdf",
213
+ "size": 46219
214
+ }
215
+ ]
216
+ }
217
+ }
218
+ ```
219
+
220
+ `resources.files` 只记录本地相对路径和大小,不保存 Cookie。
221
+
222
+ ## 4.1 创建知识库和文档
223
+
224
+ 创建私密测试知识库:
225
+
226
+ ```bash
227
+ npm run yuque-local -- create-book \
228
+ --name AI真实测试知识库 \
229
+ --slug ai-real-test-book
230
+ ```
231
+
232
+ 在已有知识库中创建 Markdown 文档:
233
+
234
+ ```bash
235
+ npm run yuque-local -- create-doc https://www.yuque.com/<your-login>/<your-book> \
236
+ --title AI真实测试文档 \
237
+ --markdown-file article.md
238
+ ```
239
+
240
+ 默认行为:
241
+
242
+ - 不传 `--slug`,由语雀自动生成文档 slug。
243
+ - 自动挂载到知识库目录根节点,返回值中 `toc_attached: true`。
244
+ - 输入文件可以是 Markdown。
245
+ - 创建后会立即读取语雀生成的 `body_asl`,再写回为 Lake,确保最终文档进入语雀原生 Lake 格式。
246
+ - 不默认修改标题文本。
247
+ - 返回 JSON 中 `format` 表示语雀创建接口的初始格式;如果默认 Lake 写回成功,会额外返回 `final_format: "lake"`。
248
+
249
+ ## 4.2 上传和插入附件
250
+
251
+ 只上传文件,不写入正文:
252
+
253
+ ```bash
254
+ npm run yuque-local -- upload-attach <doc-or-book-url> --file ./example.pdf
255
+ ```
256
+
257
+ 上传并插入到文档正文:
258
+
259
+ ```bash
260
+ npm run yuque-local -- insert-attachment <doc-url> \
261
+ --file ./example.pdf \
262
+ --after-text 图片位置
263
+ ```
264
+
265
+ PDF 附件的原生写入规则:
266
+
267
+ - 文件先通过语雀 Web Session 上传,返回 `filekey`、`attachment_id` 和附件下载 URL。
268
+ - 正文写入 `file` card。
269
+ - `src` 必须是 `https://www.yuque.com/office/<filekey>?from=<doc-url>`,这是语雀阅读页打开 PDF 预览所需字段。
270
+ - `downloadUrl/download_url` 保留原始附件地址,供 `download-doc` 落盘资源使用。
271
+ - 如果 file card 只有 `url/previewUrl` 但没有 `src`,阅读页点击可能打开 `about:blank`。
272
+
273
+ 如果需要符合“标题带层级编号”的阅读习惯,创建时加 `--number-headings`:
274
+
275
+ ```bash
276
+ npm run yuque-local -- create-doc https://www.yuque.com/<your-login>/<your-book> \
277
+ --title AI真实测试文档 \
278
+ --markdown-file article.md \
279
+ --number-headings
280
+ ```
281
+
282
+ 该参数不会把 `1.` 写进 Markdown 标题文本,而是在语雀生成 Lake 后给标题节点加语雀原生属性:
283
+
284
+ ```html
285
+ <h1 data-lake-index-type="2">一级标题</h1>
286
+ ```
287
+
288
+ 这和在语雀编辑器里手动开启标题编号后的 Lake 结构一致。阅读页面会渲染出 `1.`、`1.1.`、`1.1.1.`,但编号不会混进标题正文。
289
+
290
+ 调试时如果只想停留在语雀 Markdown 导入结果,不做最终 Lake 写回,可以加:
291
+
292
+ ```bash
293
+ --no-native-lake
294
+ ```
295
+
296
+ 只有确实需要固定 URL 时才传 `--slug`:
297
+
298
+ ```bash
299
+ npm run yuque-local -- create-doc https://www.yuque.com/<your-login>/<your-book> \
300
+ --title AI真实测试文档 \
301
+ --slug custom-doc-slug \
302
+ --markdown-file article.md
303
+ ```
304
+
305
+ 如果只想创建可通过 URL 访问、但不加入目录的文档:
306
+
307
+ ```bash
308
+ npm run yuque-local -- create-doc https://www.yuque.com/<your-login>/<your-book> \
309
+ --title AI真实测试文档 \
310
+ --markdown-file article.md \
311
+ --no-toc
312
+ ```
313
+
314
+ 真实验收结论:
315
+
316
+ - `create-book` 已通过真实语雀验证,可以创建私密知识库。
317
+ - `create-doc` 已通过真实语雀验证,可以创建真实文档,默认让语雀生成 slug,并自动加入知识库 TOC。
318
+ - 语雀会把 Markdown 创建结果自动转换成 Lake 文档,工具随后会默认写回 Lake,后续修改应按 Lake 链路处理。
319
+ - 当前原生写入能力矩阵见 `docs/native-lake-capability.md`。图片、附件、思维导图、画板属于下一阶段真实探索项,不能在未验证前手写 card。
320
+
321
+ ## 4.2 上传图片或附件探索
322
+
323
+ 只上传本地文件,不写入正文:
324
+
325
+ ```bash
326
+ npm run yuque-local -- upload-attach https://www.yuque.com/user/book/doc \
327
+ --file /path/to/image.png
328
+ ```
329
+
330
+ 该命令使用 Web Session 调用语雀网页端上传接口:
331
+
332
+ ```text
333
+ POST /api/upload/attach
334
+ ```
335
+
336
+ 当前用途是探索图片/附件的原生返回结构。上传成功后会输出 `upload` 返回体和本地报告路径,但不会自动生成 Lake card,也不会修改线上文档正文。
337
+
338
+ 上传并插入本地图片到语雀文档:
339
+
340
+ ```bash
341
+ npm run yuque-local -- insert-image https://www.yuque.com/user/book/doc \
342
+ --file /path/to/image.png \
343
+ --dry-run
344
+ ```
345
+
346
+ 确认 dry-run 后实际写入:
347
+
348
+ ```bash
349
+ npm run yuque-local -- insert-image https://www.yuque.com/user/book/doc \
350
+ --file /path/to/image.png
351
+ ```
352
+
353
+ 默认追加到文档末尾。如果要插入到包含某段文字的块后面:
354
+
355
+ ```bash
356
+ npm run yuque-local -- insert-image https://www.yuque.com/user/book/doc \
357
+ --file /path/to/image.png \
358
+ --after-text "图片应插入在这里。"
359
+ ```
360
+
361
+ 注意:`insert-image --dry-run` 会真实上传图片以获得语雀 CDN URL,但不会修改文档正文。
362
+
363
+ 上传并插入附件到语雀文档:
364
+
365
+ ```bash
366
+ npm run yuque-local -- insert-attachment https://www.yuque.com/user/book/doc \
367
+ --file /path/to/file.pdf \
368
+ --dry-run
369
+ ```
370
+
371
+ 确认 dry-run 后实际写入:
372
+
373
+ ```bash
374
+ npm run yuque-local -- insert-attachment https://www.yuque.com/user/book/doc \
375
+ --file /path/to/file.pdf
376
+ ```
377
+
378
+ 和图片一样,`insert-attachment --dry-run` 会真实上传附件以获得语雀附件 URL,但不会修改文档正文。
379
+
380
+ ## 5. 下载单篇或多篇文档
381
+
382
+ 下载单篇:
383
+
384
+ ```bash
385
+ npm run yuque-local -- download-doc https://www.yuque.com/user/book/doc --dist-dir /tmp/yuque-doc-test
386
+ ```
387
+
388
+ 下载多篇:
389
+
390
+ ```bash
391
+ npm run yuque-local -- download-doc \
392
+ https://www.yuque.com/user/book/doc1 \
393
+ https://www.yuque.com/user/book/doc2 \
394
+ --dist-dir /tmp/yuque-doc-test
395
+ ```
396
+
397
+ ## 6. 本地预览下载结果
398
+
399
+ 只生成或检查 VitePress 配置,不启动长驻服务:
400
+
401
+ ```bash
402
+ npm run yuque-local -- serve-book /tmp/yuque-download-test/工控 --config-only
403
+ ```
404
+
405
+ 该命令会输出 JSON,包含:
406
+
407
+ - `root`
408
+ - `config`
409
+ - `generated`
410
+
411
+ 下载完成后可以启动 VitePress 预览:
412
+
413
+ ```bash
414
+ npm run yuque-local -- serve-book /tmp/yuque-download-test/工控 --port 5173
415
+ ```
416
+
417
+ 浏览器打开:
418
+
419
+ ```text
420
+ http://localhost:5173/
421
+ ```
422
+
423
+ 如需重新生成 `.vitepress` 配置:
424
+
425
+ ```bash
426
+ npm run yuque-local -- serve-book /tmp/yuque-download-test/工控 --port 5173 --force
427
+ ```
428
+
429
+ ## 7. 快照和差异比较
430
+
431
+ 抓取语雀文档快照:
432
+
433
+ ```bash
434
+ npm run yuque-local -- snapshot https://www.yuque.com/user/book/doc --out /tmp/doc.snapshot.json
435
+ ```
436
+
437
+ 比较两个快照:
438
+
439
+ ```bash
440
+ npm run yuque-local -- diff-lake /tmp/before.json /tmp/after.json
441
+ ```
442
+
443
+ 把快照转成 AI 可读 Markdown:
444
+
445
+ ```bash
446
+ npm run yuque-local -- lake-to-markdown /tmp/doc.snapshot.json --out /tmp/doc.md
447
+ ```
448
+
449
+ ## 8. HTML 转语雀 Lake
450
+
451
+ 把本地 HTML 交给语雀 Lake editor runtime 序列化:
452
+
453
+ ```bash
454
+ npm run yuque-local -- editor-serialize --html-file article.html --out article.lake.html
455
+ ```
456
+
457
+ 如果输出中有:
458
+
459
+ ```json
460
+ "serializer": "official-lake-editor"
461
+ ```
462
+
463
+ 说明使用的是 vendored Lake editor,而不是 fallback。
464
+
465
+ ## 9. 安全写入语雀文档
466
+
467
+ 强烈建议先 dry-run:
468
+
469
+ ```bash
470
+ npm run yuque-local -- apply-lake https://www.yuque.com/user/book/doc --lake-file article.lake.html --dry-run
471
+ ```
472
+
473
+ 确认报告没有异常后再写入:
474
+
475
+ ```bash
476
+ npm run yuque-local -- apply-lake https://www.yuque.com/user/book/doc --lake-file article.lake.html
477
+ ```
478
+
479
+ 真实写入前会自动生成 snapshot 备份:
480
+
481
+ ```text
482
+ backups/
483
+ ```
484
+
485
+ 写入报告会生成在:
486
+
487
+ ```text
488
+ reports/
489
+ ```
490
+
491
+ ## 10. 文章格式化流程
492
+
493
+ 本地 HTML 到语雀文档的完整流程:
494
+
495
+ ```bash
496
+ npm run yuque-local -- format-article https://www.yuque.com/user/book/doc --html-file article.html --dry-run
497
+ ```
498
+
499
+ 确认无误后:
500
+
501
+ ```bash
502
+ npm run yuque-local -- format-article https://www.yuque.com/user/book/doc --html-file article.html
503
+ ```
504
+
505
+ ## 11. 常用选项
506
+
507
+ 忽略图片下载:
508
+
509
+ ```bash
510
+ --ignore-img
511
+ ```
512
+
513
+ 忽略所有附件:
514
+
515
+ ```bash
516
+ --ignore-attachments
517
+ ```
518
+
519
+ 只忽略指定附件后缀:
520
+
521
+ ```bash
522
+ --ignore-attachments mp4,pdf,zip
523
+ ```
524
+
525
+ 为每篇 Markdown 添加 TOC:
526
+
527
+ ```bash
528
+ --toc
529
+ ```
530
+
531
+ 隐藏页脚:
532
+
533
+ ```bash
534
+ --hide-footer
535
+ ```
536
+
537
+ 把 Markdown 中的 mp4/mp3 链接转成 HTML 标签:
538
+
539
+ ```bash
540
+ --convert-markdown-video-links
541
+ ```
542
+
543
+ 关闭下载过程中的逐篇进度,只保留最后 JSON:
544
+
545
+ ```bash
546
+ --quiet
547
+ ```
548
+
549
+ 默认情况下,下载进度会写到 stderr,最终结果 JSON 会写到 stdout。这样人可以看到进度,AI 或脚本也可以稳定解析最后的 JSON。
550
+
551
+ 如果需要严格的 JSON 输出,建议加 `--quiet`。
552
+
553
+ ## 12. 安全规则
554
+
555
+ - 不要把真实 `_yuque_session` 或 `yuque_ctoken` 写入项目文件。
556
+ - 不要提交 `~/.config/yuque-cookie-plugin/config.json`。
557
+ - 线上写入必须先 dry-run。
558
+ - 批量写入前先对单篇文档做实验。
559
+ - 章节编号不要直接改标题文本硬塞编号,必须先做 snapshot before/after diff。
560
+
561
+ ## 13. 当前已验证场景
562
+
563
+ 已真实验证:
564
+
565
+ - 登录保存 Cookie。
566
+ - `inspect` 读取私有知识库。
567
+ - 下载 `https://www.yuque.com/<your-login>/<your-book>`。
568
+ - 15 篇 Markdown 文档下载成功。
569
+ - 第二次增量下载全部跳过。
570
+ - 导出文件名保留正常空格。
571
+
572
+ ## 14. 当前未完全覆盖场景
573
+
574
+ 仍需继续补齐:
575
+
576
+ - yuque-dl 全量测试用例迁移。
577
+ - 复杂 sheet 文档。
578
+ - 复杂音视频卡片。
579
+ - 公开密码访问的 `verified_books` / `verified_docs`。
580
+ - 企业私有语雀自定义 Cookie key。
package/package.json ADDED
@@ -0,0 +1,71 @@
1
+ {
2
+ "name": "yuque-cookie-plugin",
3
+ "version": "0.1.0",
4
+ "type": "module",
5
+ "description": "Cookie-based Yuque CLI for AI agents, without MCP or OpenAPI token limits.",
6
+ "homepage": "https://github.com/c-sunc6/yuque-cookie-plugin#readme",
7
+ "bugs": {
8
+ "url": "https://github.com/c-sunc6/yuque-cookie-plugin/issues"
9
+ },
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "git+https://github.com/c-sunc6/yuque-cookie-plugin.git"
13
+ },
14
+ "license": "UNLICENSED",
15
+ "keywords": [
16
+ "yuque",
17
+ "cli",
18
+ "cookie",
19
+ "lake",
20
+ "markdown",
21
+ "ai-agent"
22
+ ],
23
+ "engines": {
24
+ "node": ">=20"
25
+ },
26
+ "files": [
27
+ "bin/",
28
+ "dist/",
29
+ "docs/docker-quickstart.md",
30
+ "docs/native-lake-capability.md",
31
+ "docs/npm-release.md",
32
+ "docs/real-acceptance.md",
33
+ "docs/usage-zh.md",
34
+ "skills/yuque-cookie-plugin/",
35
+ "vendor/lake-editor/",
36
+ ".env.example"
37
+ ],
38
+ "bin": {
39
+ "yuque-local": "bin/yuque-local.mjs"
40
+ },
41
+ "publishConfig": {
42
+ "access": "public",
43
+ "registry": "https://registry.npmjs.org/"
44
+ },
45
+ "scripts": {
46
+ "build": "tsc -p tsconfig.build.json",
47
+ "prepack": "npm run build",
48
+ "yuque-local": "tsx ./src/cli.ts",
49
+ "real:acceptance": "tsx ./scripts/real-acceptance.ts",
50
+ "release:check": "tsx ./scripts/prepublish-check.ts",
51
+ "typecheck": "tsc --noEmit",
52
+ "test": "npm run typecheck && vitest run && npm run yuque-local -- --help",
53
+ "test:unit": "vitest run",
54
+ "test:watch": "vitest"
55
+ },
56
+ "devDependencies": {
57
+ "@types/node": "^26.0.0",
58
+ "@types/pako": "^2.0.4",
59
+ "msw": "^2.14.6",
60
+ "tsx": "^4.22.4",
61
+ "typescript": "^6.0.3",
62
+ "vitepress": "^1.6.4",
63
+ "vitest": "^4.1.9"
64
+ },
65
+ "dependencies": {
66
+ "markdown-toc": "^1.2.0",
67
+ "node-html-parser": "^8.0.3",
68
+ "pako": "^2.2.0",
69
+ "playwright": "^1.61.1"
70
+ }
71
+ }
@@ -0,0 +1,58 @@
1
+ ---
2
+ name: yuque-cookie-plugin
3
+ description: Use when an AI agent needs to operate Yuque through the local yuque-local CLI with _yuque_session and yuque_ctoken, including login, auth status, inspect, snapshot, download, create, native Lake update, image/PDF insertion, and safe document formatting. This skill is for CLI orchestration, not MCP or Yuque OpenAPI token usage.
4
+ metadata:
5
+ version: "0.1.0"
6
+ author: "c-sunc6"
7
+ ---
8
+
9
+ # Yuque Cookie Plugin
10
+
11
+ Always use the public CLI entry:
12
+
13
+ ```bash
14
+ yuque-local <module> <command> [args...] --json
15
+ ```
16
+
17
+ Legacy flat commands such as `yuque-local snapshot` and `yuque-local download-book` may exist, but prefer grouped commands for new work.
18
+
19
+ ## Hard Rules
20
+
21
+ | ID | Rule |
22
+ | --- | --- |
23
+ | YQ001 | Do not ask for or print raw `_yuque_session` or `yuque_ctoken` in chat. Use `yuque-local auth login` or `yuque-local auth login --manual`. |
24
+ | YQ002 | Do not write credentials into a project directory. The CLI stores them under the user config directory. |
25
+ | YQ003 | Before modifying an existing online document, create a snapshot unless the command already does so internally. |
26
+ | YQ004 | Prefer `--dry-run` before online writes when the user has not explicitly approved the exact write. |
27
+ | YQ005 | Use `--json` for agent calls and parse the JSON envelope instead of scraping prose. |
28
+ | YQ006 | If auth fails, stop and ask the user to refresh cookies with `yuque-local auth login`; do not repeatedly retry. |
29
+ | YQ007 | Do not fake native Lake structures. Use validated CLI operations such as native heading numbering, editor serialization, image insertion, and attachment insertion. |
30
+
31
+ ## Common Commands
32
+
33
+ ```bash
34
+ yuque-local auth login
35
+ yuque-local auth login --manual
36
+ yuque-local auth status <doc-or-book-url> --json
37
+ yuque-local doctor --json
38
+ yuque-local book download <book-url> --dist-dir download --incremental --quiet --json
39
+ yuque-local doc download <doc-url> --dist-dir download --quiet --json
40
+ yuque-local doc create <book-url> --title "Title" --markdown-file article.md --number-headings --json
41
+ yuque-local doc snapshot <doc-url> --out /tmp/doc.snapshot.json --json
42
+ yuque-local doc apply-lake <doc-url> --lake-file body_asl.html --dry-run --json
43
+ yuque-local doc insert-image <doc-url> --file image.png --after-text "位置" --json
44
+ yuque-local doc insert-attachment <doc-url> --file file.pdf --after-text "附件" --json
45
+ ```
46
+
47
+ ## Workflow
48
+
49
+ 1. Run `yuque-local doctor --json` to inspect local installation and credential state.
50
+ 2. If credentials are missing or stale, ask the user to run `yuque-local auth login` or `yuque-local auth login --manual`.
51
+ 3. For reads and downloads, call the relevant `book` or `doc` command with `--json`.
52
+ 4. For writes, snapshot first, prepare the change, run a dry run when available, then apply after user approval.
53
+ 5. Save local reports and paths from the CLI result for later audit.
54
+
55
+ ## References
56
+
57
+ - Command registry: [commands.yaml](commands.yaml)
58
+ - Agent safety details: [reference/agent-spec.md](reference/agent-spec.md)