yuque-cookie-plugin 0.1.1 → 0.1.2

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.
package/README.md CHANGED
@@ -8,7 +8,7 @@
8
8
 
9
9
  ## 当前能力
10
10
 
11
- - Cookie 登录和登录态检测:`auth login`、`auth status`
11
+ - Cookie 登录、清理和登录态检测:`auth login`、`auth logout`、`auth status`
12
12
  - 读取语雀信息:`book inspect`、`doc inspect`
13
13
  - 文档快照和结构对比:`doc snapshot`、`lake diff`
14
14
  - Lake 和 Markdown 辅助转换:`lake to-markdown`、`lake serialize`
@@ -98,6 +98,12 @@ npm run yuque-local -- auth status https://www.yuque.com/<your-login>/<your-book
98
98
  yuque-local auth login --manual
99
99
  ```
100
100
 
101
+ 清理本机保存的 Cookie:
102
+
103
+ ```bash
104
+ yuque-local auth logout
105
+ ```
106
+
101
107
  也可以一次性传入参数,适合本地受控脚本:
102
108
 
103
109
  ```bash
@@ -246,6 +252,7 @@ npm run real:acceptance -- \
246
252
 
247
253
  - 不要把真实 `_yuque_session` 或 `yuque_ctoken` 写入项目文件。
248
254
  - 不要提交 `~/.config/yuque-cookie-plugin/config.json`。
255
+ - 需要清理本机凭据时运行 `yuque-local auth logout`。
249
256
  - `reports/`、`backups/`、`node_modules/` 已被 `.gitignore` 忽略。
250
257
  - 批量写入前先对单篇文档做真实实验。
251
258
  - 不确定 Lake 语义时,先 snapshot,再 diff,再实现。
package/dist/auth.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { createServer } from 'node:http';
2
2
  import { existsSync, readFileSync } from 'node:fs';
3
- import { chmod, mkdir, writeFile } from 'node:fs/promises';
3
+ import { chmod, mkdir, rm, writeFile } from 'node:fs/promises';
4
4
  import { execFile } from 'node:child_process';
5
5
  import { createInterface } from 'node:readline/promises';
6
6
  import os from 'node:os';
@@ -11,6 +11,14 @@ const CONFIG_FILE = path.join(CONFIG_DIR, 'config.json');
11
11
  export function getConfigFilePath() {
12
12
  return CONFIG_FILE;
13
13
  }
14
+ export async function clearSavedCredentials() {
15
+ const existed = existsSync(CONFIG_FILE);
16
+ await rm(CONFIG_FILE, { force: true });
17
+ return {
18
+ config_file: CONFIG_FILE,
19
+ removed: existed
20
+ };
21
+ }
14
22
  export function getCredentials(flags = {}) {
15
23
  const envSession = process.env[String(flags.sessionEnv || 'YUQUE_SESSION')];
16
24
  const envCtoken = process.env[String(flags.ctokenEnv || 'YUQUE_CTOKEN')];
@@ -28,7 +36,7 @@ export function getCredentials(flags = {}) {
28
36
  if (saved?.session && saved?.ctoken) {
29
37
  return { ...saved, extraCookies: { ...(saved.extraCookies || {}), ...extraCookies }, source: CONFIG_FILE };
30
38
  }
31
- throw new Error('Missing Yuque credentials. Run "yuque-local login" to configure them in your browser.');
39
+ throw new Error('Missing Yuque credentials. Run "yuque-local auth login" to configure them in your browser.');
32
40
  }
33
41
  export function getCredentialStatus(flags = {}) {
34
42
  const envSession = process.env[String(flags.sessionEnv || 'YUQUE_SESSION')];
package/dist/cli.js CHANGED
@@ -1,13 +1,13 @@
1
1
  #!/usr/bin/env node
2
2
  import process from 'node:process';
3
3
  import path from 'node:path';
4
- import { cp, mkdir, readFile, writeFile } from 'node:fs/promises';
4
+ import { cp, mkdir, readFile, rm, writeFile } from 'node:fs/promises';
5
5
  import { existsSync } from 'node:fs';
6
6
  import { fileURLToPath } from 'node:url';
7
7
  import { YuqueCookieClient } from "./client-cookie.js";
8
8
  import { diffLakeSnapshots } from "./lake-diff.js";
9
9
  import { writeJson } from "./fs-utils.js";
10
- import { getConfigFilePath, getCredentialStatus, getCredentials, loginWithBrowser, recordCredentialValidation } from "./auth.js";
10
+ import { clearSavedCredentials, getConfigFilePath, getCredentialStatus, getCredentials, loginWithBrowser, recordCredentialValidation } from "./auth.js";
11
11
  import { serializeHtmlToLake } from "./editor-bridge.js";
12
12
  import { snapshotToMarkdown } from "./lake-markdown.js";
13
13
  import { downloadBook, downloadDocs } from "./downloader.js";
@@ -22,9 +22,10 @@ function help() {
22
22
  Usage:
23
23
  yuque-local --version
24
24
  yuque-local auth login [--manual]
25
+ yuque-local auth logout [--json]
25
26
  yuque-local auth status [doc-or-book-url] [--json]
26
27
  yuque-local doctor [--json]
27
- yuque-local skill install|status [--json]
28
+ yuque-local skill install|status|uninstall [--json]
28
29
  yuque-local book create --name <name> --slug <slug> [--description <text>] [--public]
29
30
  yuque-local book download <book-url> [--dist-dir download] [--incremental]
30
31
  yuque-local doc create <book-url> --title <title> --markdown-file <file> [--number-headings]
@@ -131,6 +132,7 @@ function normalizeInvocation(argv) {
131
132
  const grouped = {
132
133
  auth: {
133
134
  login: 'login',
135
+ logout: 'logout',
134
136
  status: 'auth-status'
135
137
  },
136
138
  book: {
@@ -286,9 +288,24 @@ async function commandSkill(action, flags) {
286
288
  console.log(JSON.stringify(data, null, 2));
287
289
  return;
288
290
  }
291
+ const source = path.join(PACKAGE_ROOT, 'skills', 'yuque-cookie-plugin');
292
+ if (action === 'uninstall') {
293
+ const targets = skillTargets();
294
+ const removed = [];
295
+ for (const target of targets) {
296
+ const existed = existsSync(path.join(target, 'SKILL.md'));
297
+ await rm(target, { recursive: true, force: true });
298
+ removed.push({ path: target, removed: existed });
299
+ }
300
+ const data = { removed };
301
+ if (flags.json)
302
+ printJsonResult(jsonResult('success', 'skill uninstalled', data));
303
+ else
304
+ console.log(JSON.stringify(data, null, 2));
305
+ return;
306
+ }
289
307
  if (action !== 'install')
290
308
  throw new Error(`Unknown skill action: ${action}`);
291
- const source = path.join(PACKAGE_ROOT, 'skills', 'yuque-cookie-plugin');
292
309
  if (!existsSync(path.join(source, 'SKILL.md')))
293
310
  throw new Error(`Skill source is missing: ${source}`);
294
311
  const installed = [];
@@ -371,6 +388,17 @@ async function main() {
371
388
  await loginWithBrowser(flags);
372
389
  return;
373
390
  }
391
+ if (command === 'logout') {
392
+ const result = await clearSavedCredentials();
393
+ printCommandResult({
394
+ ok: true,
395
+ ...result,
396
+ note: process.env.YUQUE_SESSION || process.env.YUQUE_CTOKEN
397
+ ? 'Environment credentials are still set in the current shell.'
398
+ : undefined
399
+ }, flags, 'auth credentials cleared');
400
+ return;
401
+ }
374
402
  if (command === 'doctor') {
375
403
  await commandDoctor(flags);
376
404
  return;
package/docs/usage-zh.md CHANGED
@@ -97,6 +97,12 @@ Docker、SSH、远程服务器等无头环境中,推荐使用手动模式,
97
97
  yuque-local auth login --manual
98
98
  ```
99
99
 
100
+ 清理本机保存的 Cookie:
101
+
102
+ ```bash
103
+ yuque-local auth logout
104
+ ```
105
+
100
106
  正常执行 `inspect`、`snapshot`、`download-book`、`download-doc` 等真实语雀命令成功后,也会刷新 `last_validated_at`。如果检测到 401、403、页面无法解析等登录态问题,CLI 会提示重新登录。
101
107
 
102
108
  ### 额外 Cookie
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "yuque-cookie-plugin",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "type": "module",
5
5
  "description": "Cookie-based Yuque CLI for AI agents, without MCP or OpenAPI token limits.",
6
6
  "homepage": "https://github.com/c-sunc6/yuque-cookie-plugin#readme",
@@ -33,6 +33,7 @@ Legacy flat commands such as `yuque-local snapshot` and `yuque-local download-bo
33
33
  ```bash
34
34
  yuque-local auth login
35
35
  yuque-local auth login --manual
36
+ yuque-local auth logout --json
36
37
  yuque-local auth status <doc-or-book-url> --json
37
38
  yuque-local doctor --json
38
39
  yuque-local book download <book-url> --dist-dir download --incremental --quiet --json
@@ -42,6 +43,7 @@ yuque-local doc snapshot <doc-url> --out /tmp/doc.snapshot.json --json
42
43
  yuque-local doc apply-lake <doc-url> --lake-file body_asl.html --dry-run --json
43
44
  yuque-local doc insert-image <doc-url> --file image.png --after-text "位置" --json
44
45
  yuque-local doc insert-attachment <doc-url> --file file.pdf --after-text "附件" --json
46
+ yuque-local skill uninstall --json
45
47
  ```
46
48
 
47
49
  ## Workflow
@@ -14,6 +14,13 @@ auth.status:
14
14
  example: "yuque-local auth status https://www.yuque.com/user/book --json"
15
15
  reference: "reference/agent-spec.md"
16
16
 
17
+ auth.logout:
18
+ cli: "yuque-local auth logout"
19
+ description: "Remove saved local Yuque cookies from the user config file"
20
+ optional: ["--json"]
21
+ example: "yuque-local auth logout --json"
22
+ reference: "reference/agent-spec.md"
23
+
17
24
  doctor:
18
25
  cli: "yuque-local doctor"
19
26
  description: "Inspect CLI version, runtime, auth config path, and skill install status"
@@ -28,6 +35,13 @@ skill.install:
28
35
  example: "yuque-local skill install --json"
29
36
  reference: "reference/agent-spec.md"
30
37
 
38
+ skill.uninstall:
39
+ cli: "yuque-local skill uninstall"
40
+ description: "Remove the installed yuque-cookie-plugin AI skill from local supported agent skill directories"
41
+ optional: ["--json"]
42
+ example: "yuque-local skill uninstall --json"
43
+ reference: "reference/agent-spec.md"
44
+
31
45
  book.download:
32
46
  cli: "yuque-local book download"
33
47
  description: "Download a Yuque knowledge base with resources and reports"
@@ -38,6 +38,12 @@ For Docker, SSH, or headless terminals:
38
38
  yuque-local auth login --manual
39
39
  ```
40
40
 
41
+ To clear saved local cookies:
42
+
43
+ ```bash
44
+ yuque-local auth logout --json
45
+ ```
46
+
41
47
  Never request raw cookie values in the conversation.
42
48
 
43
49
  ## Safe Write Flow