dsh-cookie-cleaner 0.1.0 → 0.1.1

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/CHANGELOG.md CHANGED
@@ -1,11 +1,36 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.1.1 (2026-11-04)
4
+
5
+ 跨平台支持(macOS / Linux)与 9 语分发。
6
+
7
+ - **失败归因重写**:实测 `node:sqlite` 在 POSIX 权限不足时只报
8
+ `ERR_SQLITE_ERROR: unable to open database file`,**不给 EACCES**——原先按错误码分档
9
+ 的实现永远走不到权限档,会把「读不了」误报成「客户端在跑」。改为主动探测四档:
10
+ `missing`(文件不在)/ `unreadable`(读不了)/ `not-owned`(属别人)/ `busy`(真占用),
11
+ 每档给各自的处置文案,`classifyOpenFailure` 导出且可注入以便测试。
12
+ - **POSIX 平台分叉**:路径推导按目标平台选 `path.win32`/`path.posix`(此前在 Windows 上
13
+ 会把 posix 路径写成反斜杠);macOS 走 `~/Library/Application Support`,Linux 尊重
14
+ `XDG_CONFIG_HOME`/`HOME`;`DSH_COOKIE_DB` 直接当首选候选,不再拆根重组;
15
+ 退出指引按平台出文案(Linux/mac 不再提「托盘」)。
16
+ - **备份带走 WAL**:POSIX 上 Chromium 用 WAL,只拷主文件是个残副本;现在把
17
+ `-wal`/`-shm`/`-journal` 一并复制并在输出里注明。sidecar 拷不上只记为跳过(`-shm`
18
+ 只是可再生的一致性索引),不再让单个 sidecar 被锁导致整单清理失败。
19
+ - **退出码改黑名单**:此前 `missing` 档会退出 0(把失败报成成功);现在只有真读到内容
20
+ 的档位才返回 0。
21
+ - **9 语分发**:`locale/<lang>.json`(en 为锚,宿主市场卡)+ 运行时文案字典
22
+ (zh 为键集真理源,`registerDictionary` 装载时机械核对缺键/多键/占位符);
23
+ 语言优先级 `--lang` > `DSH_COOKIE_LANG`/`DSH_LANG` > `LC_ALL`/`LANG` > 系统 locale > zh,
24
+ `C.UTF-8`/`POSIX` 中性 locale 判为英文。新增 `lang` 设置项。
25
+ - 测试:`gate` 增 `gen-locales --check`;POSIX `chmod 000` 归因用例在 Windows 自动 skip,
26
+ 已在 WSL(node 24)59/59 跑绿;CLI 用例钉死语言,不再随宿主 locale 漂移。
27
+
3
28
  ## 0.1.0 (2026-11-04)
4
29
 
5
30
  - 首版:只读播报 + 包内独立清理脚本。
6
31
  - `src/core.js`:cookie 库定位(win/mac/linux 惯例 + `DSH_USER_DATA` / `DSH_COOKIE_DB` / `--db` 覆盖)、
7
32
  只读统计(条数/过期数/host_key 分布/过期跨度)、`BEGIN IMMEDIATE` 独占写锁闸、
8
- `.bak` 备份 + 事务删除 + VACUUM,表结构自检不过即拒绝写入。
33
+ `.bak` 备份 + 原子事务删除 + VACUUM,表结构自检不过即拒绝写入。
9
34
  - `src/cli.js`(npm bin `dsh-cookie-cleaner`):`--clean` / `--expired-only` / `--dry-run` / `--no-backup` / `--no-vacuum` / `--db`。
10
35
  - `src/index.js`:`/cookie-cleaner` 命令(只读,输出可直接复制的清理命令)+ 三代设置 waist + `volatile` 配置面。
11
36
  - 关键事实入档:客户端运行期该库被 Chromium 独占,宿主插件无法在启动时清理;
package/README.md CHANGED
@@ -1,38 +1,63 @@
1
1
  # dsh-cookie-cleaner
2
2
 
3
3
  清理 DSH(DeepSeek Harness)**桌面客户端** cookie 库里堆积的本地登录凭据 cookie(`dsh-auth-*`),
4
- 并解释清楚「为什么只能在客户端关闭时清理」——不用每次再去问一遍 AI。
4
+ 并把「为什么只能在客户端关闭时清理」讲清楚——不用每次再去问一遍 AI。
5
+
6
+ 输出支持 9 种语言(zh / en / ja / ko / fr / de / it / ru / es),跟随系统 locale。
5
7
 
6
8
  ## 它是什么 / 为什么长这样
7
9
 
8
- 桌面客户端每次启动都会在 Electron 的 cookie 库(`%APPDATA%\@deepseek-ai\dsh-desktop\Network\Cookies`)
9
- 里留下一条 `dsh-auth-<base64url(sha256(host:port))>`。名字按 **host:port** 哈希,端口一变就多一条,
10
+ 桌面客户端每次启动都会在 Electron 的 cookie 库里留下一条
11
+ `dsh-auth-<base64url(sha256(host:port))>`。名字按 **host:port** 哈希,端口一变就多一条,
10
12
  各带 30 天有效期,于是历史记录长期堆积。
11
13
 
12
14
  这些记录**不影响登录**,也**不涉及账号凭据**:
13
15
 
14
- - 主窗口的 HTTP/WS 请求走的是内存态凭据(宿主换发后由桌面层直接注入请求头),不经 cookie jar;
16
+ - 主窗口的 HTTP/WS 请求走内存态凭据(宿主换发后由桌面层直接注入请求头),不经 cookie jar;
15
17
  - 鉴权只按当前 authority 派生的**那一个名字**取值,其余同名前缀条目本就永远读不到;
16
18
  - 每次启动都会用 launch token 重新换发。
17
19
 
18
- **关键约束(实测,非猜测)**:这个库在客户端运行期间被 Chromium 独占。
19
- 宿主插件跑在 Electron 的纯 Node 模式子进程里,既拿不到 `session.cookies`,
20
- 也无法在运行期打开该库(只读打开都会失败)。所以:
20
+ **关键约束(Windows 与 Linux 双端实测)**:这个库在客户端运行期间被 Chromium 独占,
21
+ 而宿主插件跑在 Electron 的纯 Node 模式子进程里,拿不到 `session.cookies`。所以:
21
22
 
22
23
  > 清理动作不可能由「插件在启动时」完成——它只能发生在客户端已完全退出的时间窗里,
23
24
  > 而那个时刻宿主插件本身并不存在。因此本仓库把执行体做成**包内独立脚本**,
24
25
  > 插件半只做只读播报和命令指引,**永不写库**。
25
26
 
27
+ ## 各平台的库位置与退出方式
28
+
29
+ | 平台 | cookie 库默认位置 | 完全退出客户端的方式 |
30
+ |---|---|---|
31
+ | **Windows** | `%APPDATA%\@deepseek-ai\dsh-desktop\Network\Cookies` | 托盘图标 → 退出;确认任务管理器里没有 `DeepSeek Harness` |
32
+ | **macOS** | `~/Library/Application Support/@deepseek-ai/dsh-desktop/Network/Cookies` | `Cmd+Q` 或菜单 → Quit;Dock 图标消失**不等于**已退出,用 `ps aux \| grep -i deepseek` 确认 |
33
+ | **Linux** | `~/.config/@deepseek-ai/dsh-desktop/Network/Cookies`(`XDG_CONFIG_HOME` 优先) | 关闭主窗口后用 `pgrep -af 'DeepSeek Harness\|dsh-desktop'` 确认没有残留 |
34
+
35
+ 更早的 Chromium 布局把库直接放在 `<userData>/Cookies`(不带 `Network/`),工具两种都会试。
36
+ 位置不对时用 `--db=<完整路径>`,或设 `DSH_USER_DATA` / `DSH_COOKIE_DB` 环境变量。
37
+ flatpak / snap 安装的客户端路径在常规位置之外,通常需要 `--db` 手动指。
38
+
26
39
  ## 安装
27
40
 
28
41
  ```shell
29
42
  # 作为 DSH 插件(提供 /cookie-cleaner 只读播报)
30
- dsh plugin add dsh-cookie-cleaner
43
+ dsh --profile desktop plugin add dsh-cookie-cleaner
31
44
 
32
- # 清理工具随包分发,装完即可在终端调用
33
- npm i -g dsh-cookie-cleaner # 之后直接 `dsh-cookie-cleaner`
34
- # 或不安装,用宿主装好的包体直接跑:
35
- node "<包目录>/src/cli.js"
45
+ # 清理工具随包分发;装完即可用 profile 里的别名,或全局安装后直接敲命令
46
+ npm i -g dsh-cookie-cleaner
47
+ ```
48
+
49
+ > desktop profile 由客户端自己管理,命令行 `dsh plugin add` 可能被拒
50
+ > (`profile "desktop" is managed exclusively by the Electron application`)——
51
+ > 那种情况下在客户端的插件管理界面里装;**清理脚本本身是独立的**,
52
+ > 全局 npm 安装或 `node <包目录>/src/cli.js` 都能跑,不依赖宿主装载。
53
+
54
+ 别名路径(装进 profile 后):
55
+
56
+ ```shell
57
+ # Windows
58
+ %USERPROFILE%\.dsh\profiles\desktop\node_modules\.bin\dsh-cookie-cleaner.cmd
59
+ # macOS / Linux
60
+ ~/.dsh/profiles/desktop/node_modules/.bin/dsh-cookie-cleaner
36
61
  ```
37
62
 
38
63
  ## 用法
@@ -43,31 +68,90 @@ dsh-cookie-cleaner --clean 删除回环域(127.0.0.1/localhost/[:
43
68
  dsh-cookie-cleaner --clean --expired-only 保守档:只删已过期的
44
69
  dsh-cookie-cleaner --clean --dry-run 只看会删几条,不写盘
45
70
  dsh-cookie-cleaner --db=<完整路径> 手动指定 cookie 库
71
+ dsh-cookie-cleaner --lang=de 指定输出语言(缺省跟随系统 locale)
72
+ ```
73
+
74
+ 退出码:`0` 成功;`1` 失败(被占用 / 无权限 / 找不到 / 参数非法)。
75
+
76
+ ### Windows
77
+
78
+ ```powershell
79
+ # 1) 先退出客户端(托盘 → 退出),确认没有残留进程
80
+ Get-Process | Where-Object { $_.ProcessName -match 'DeepSeek|dsh' }
81
+
82
+ # 2) 试跑再实删
83
+ dsh-cookie-cleaner --clean --dry-run
84
+ dsh-cookie-cleaner --clean
85
+ ```
86
+
87
+ ### macOS
88
+
89
+ ```shell
90
+ # 1) Cmd+Q 退出后确认
91
+ ps aux | grep -i '[D]eepSeek Harness'
92
+
93
+ # 2) 试跑再实删
94
+ dsh-cookie-cleaner --clean --dry-run
95
+ dsh-cookie-cleaner --clean
96
+
97
+ # 没装全局命令时:
98
+ node ~/.dsh/profiles/desktop/node_modules/dsh-cookie-cleaner/src/cli.js --clean
46
99
  ```
47
100
 
48
- 可选 `--no-backup`(不产出 `.bak` 副本)、`--no-vacuum`(不做 VACUUM 收缩)。
49
- 退出码:`0` 成功;`1` 库被占用 / 没找到 / 参数非法。
101
+ ### Linux
102
+
103
+ ```shell
104
+ # 1) 关闭主窗口后确认
105
+ pgrep -af 'DeepSeek Harness|dsh-desktop'
50
106
 
51
- 安全设计:
107
+ # 2) 试跑再实删
108
+ dsh-cookie-cleaner --clean --dry-run
109
+ dsh-cookie-cleaner --clean
52
110
 
53
- - **独占写锁即闸门**——`BEGIN IMMEDIATE` 拿不到就拒绝执行并给出人话处置,不做任何"也许能写"的尝试;
54
- - 写盘前先 `copyFileSync` 落 `Cookies.bak-<时间戳>`,备份失败即放弃(全有或全无);
111
+ # 只删已过期的:
112
+ dsh-cookie-cleaner --clean --expired-only
113
+ ```
114
+
115
+ ### 成功输出长这样
116
+
117
+ ```
118
+ Deleted 3 dsh-auth-* entries (all)
119
+ Database: ~/.config/@deepseek-ai/dsh-desktop/Network/Cookies 20480 B → 8192 B
120
+ Backup: ~/.config/@deepseek-ai/dsh-desktop/Network/Cookies.bak-20261104-061512 (incl. -wal, -shm)
121
+ Account credentials, sessions and plugin configuration were not touched; the local cookie is re-issued on next start.
122
+ ```
123
+
124
+ ## 安全设计
125
+
126
+ - **独占写锁即闸门**——`BEGIN IMMEDIATE` 拿不到就拒绝执行并给出对应档位的处置文案;
127
+ - **失败归因不猜错误码**:实测 `node:sqlite` 在 POSIX 权限不足时只报
128
+ `unable to open database file`(不给 EACCES),所以工具自己探文件——
129
+ 不存在 / 读不了 / 属于别人 / 被占用,四档各说各话,不会一律让你「去关客户端」;
130
+ - 写盘前先拷 `.bak-<时间戳>`,**主库副本失败即整单放弃**(全有或全无);
131
+ `-wal`/`-shm`/`-journal` sidecar 一并带走(POSIX 用 WAL,只拷主文件是个残副本),
132
+ 但 sidecar 拷不上只记为跳过,不拦停清理;
55
133
  - 删除语句只由 `host_key` 白名单 + 名称前缀构成,两者都过字符校验,时间戳走 BigInt 绑定参数;
56
134
  - 表结构自检:库里没有 `cookies` 表或缺关键列,一律拒绝,绝不对未知库执行写语句。
57
135
 
58
- Node ≥ 22.19(用到 `node:sqlite`,Electron 44 内置的 Node 24 亦可)。
59
- 在 Node 22 上会打印一条 `ExperimentalWarning: SQLite`,可 `node --no-warnings` 消除。
136
+ Node ≥ 22.19(用到 `node:sqlite`;Electron 44 内置的 Node 24 亦可)。
137
+ Node 22 上会有一条 `ExperimentalWarning: SQLite`,可用 `node --no-warnings` 消掉。
138
+
139
+ ## 语言
140
+
141
+ 优先级:`--lang` > `DSH_COOKIE_LANG` / `DSH_LANG` > `LC_ALL` / `LC_MESSAGES` / `LANG` > 系统 locale > `zh`。
142
+ `LANG=C.UTF-8` / `POSIX` 这类中性 locale 判为英文(Linux 上很常见,不该给你看中文)。
143
+ 认不出的语言落 `zh`,不会因此报错。插件侧同一套字典,可用设置项 `lang` 钉住。
60
144
 
61
145
  ## 插件面
62
146
 
63
147
  - 命令 `/cookie-cleaner` `[status|clean]`:**只读**。输出当前统计 + 可直接复制执行的清理命令。
64
- - 设置 `cookie-cleaner`:`userDataRoot`(覆盖 Electron userData 根,多实例/非默认安装用)、
65
- `expiredOnly`(保守档,影响提示措辞)。
66
- - 没有 client 卡片:这是一个运维工具,界面交给终端。
148
+ - 设置 `cookie-cleaner`:`userDataRoot`(覆盖 Electron userData 根)、`expiredOnly`(保守档措辞)、
149
+ `lang`(钉住输出语言,留空=自动探测)。
150
+ - 没有 client 卡片:这是运维工具,界面交给终端;`locale/<lang>.json` 供宿主市场卡显示。
67
151
 
68
152
  ## 想让残留自动消失(不用手动清)
69
153
 
70
- 宿主内置一个寿命闸:把 `@deepseek-ai/dsh-client-connection` 的 `cookieMaxAgeDays`(默认 30,最小 1)
154
+ 宿主内置寿命闸:把 `@deepseek-ai/dsh-client-connection` 的 `cookieMaxAgeDays`(默认 30,最小 1)
71
155
  调到 1,Chromium 便会在启动时自行清掉过期行,历史条目不再堆积。代价是最后一次领取的 cookie
72
156
  只有 1 天有效期,重启即续期。在 profile 的 `cordis.patch.yml` 追加:
73
157
 
@@ -78,11 +162,17 @@ Node ≥ 22.19(用到 `node:sqlite`,Electron 44 内置的 Node 24 亦可)
78
162
  cookieMaxAgeDays: 1
79
163
  ```
80
164
 
81
- ## 兼容性
165
+ ## 开发与发版
166
+
167
+ ```shell
168
+ npm run sync-hosts # 把 scripts/hosts.mjs 的宿主线刷进双清单
169
+ npm run gen-locales # 由 scripts/gen-locales.mjs 的表生成 locale/*.json(9 语)
170
+ npm run gate # 双清单 check + locale check + eslint + 全部测试
171
+ npm run prepack # 发布前自动跑 gate
172
+ ```
82
173
 
83
- 逐 rc 单列于 `scripts/hosts.mjs`(单一真源),`npm run sync-hosts` 同步进
84
- `package.json#engines.dsh`、`package.json#dsh.compatibility.dshReleases`、`dsh.plugin.json#engines.dsh`;
85
- `prepack` 会以 `--check` 拦截不一致。
174
+ 跨平台验证:测试套件同时要求在 Windows 与 Linux(含 `chmod 000` 归因用例,
175
+ 在 Windows 上自动 skip)跑绿;POSIX 语义在 WSL/原生 Linux 实测过。
86
176
 
87
177
  ## License
88
178
 
package/dsh.plugin.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "id": "dsh-external/dsh-cookie-cleaner",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "main": "./src/index.js",
5
5
  "description": "Cookie 清理器:只读播报桌面客户端 cookie 库里残留的本地登录凭据(dsh-auth-*),并随包分发「客户端完全退出后」可执行的清理命令(独占写锁 + .bak 备份,账号凭据/会话/插件配置不受影响)。",
6
6
  "engines": {
package/locale/de.json ADDED
@@ -0,0 +1,6 @@
1
+ {
2
+ "meta": {
3
+ "title": "Cookie-Räumer",
4
+ "description": "Meldet übrig gebliebene dsh-auth-* Einträge im Cookie-Speicher des Desktop-Clients und liefert einen Befehl, der sie nach vollständigem Beenden des Clients räumt."
5
+ }
6
+ }
package/locale/en.json ADDED
@@ -0,0 +1,6 @@
1
+ {
2
+ "meta": {
3
+ "title": "Cookie Cleaner",
4
+ "description": "Reports leftover dsh-auth-* entries in the desktop client's cookie store and ships a command that purges them once the client is fully closed."
5
+ }
6
+ }
package/locale/es.json ADDED
@@ -0,0 +1,6 @@
1
+ {
2
+ "meta": {
3
+ "title": "Limpiador de cookies",
4
+ "description": "Informa de las entradas dsh-auth-* residuales en el almacén de cookies del cliente de escritorio y ofrece un comando que las purga tras cerrar del todo el cliente."
5
+ }
6
+ }
package/locale/fr.json ADDED
@@ -0,0 +1,6 @@
1
+ {
2
+ "meta": {
3
+ "title": "Nettoyeur de cookies",
4
+ "description": "Signale les entrées dsh-auth-* restantes dans la base de cookies du client desktop et fournit une commande qui les purger une fois le client entièrement fermé."
5
+ }
6
+ }
package/locale/it.json ADDED
@@ -0,0 +1,6 @@
1
+ {
2
+ "meta": {
3
+ "title": "Pulitore di cookie",
4
+ "description": "Segnala le voci dsh-auth-* residue nell'archivio cookie del client desktop e fornisce un comando che le elimina dopo aver chiuso completamente il client."
5
+ }
6
+ }
package/locale/ja.json ADDED
@@ -0,0 +1,6 @@
1
+ {
2
+ "meta": {
3
+ "title": "Cookie クリーナー",
4
+ "description": "デスクトップクライアントの cookie ストアに残った dsh-auth-* を読み取り専用で報告し、クライアントを完全終了後に消去するコマンドを同梱します。"
5
+ }
6
+ }
package/locale/ko.json ADDED
@@ -0,0 +1,6 @@
1
+ {
2
+ "meta": {
3
+ "title": "Cookie 정리 도구",
4
+ "description": "데스크톱 클라이언트 cookie 저장소에 남은 dsh-auth-*를 읽기 전용으로 보고하고, 클라이언트를 완전히 종료한 뒤 지우는 명령을 함께 배포합니다."
5
+ }
6
+ }
package/locale/ru.json ADDED
@@ -0,0 +1,6 @@
1
+ {
2
+ "meta": {
3
+ "title": "Очистка cookie",
4
+ "description": "Отчитывается об остатках dsh-auth-* в хранилище cookie десктопного клиента и поставляет команду очистки, применимую только после полного выхода из клиента."
5
+ }
6
+ }
package/locale/zh.json ADDED
@@ -0,0 +1,6 @@
1
+ {
2
+ "meta": {
3
+ "title": "Cookie 清理器",
4
+ "description": "只读播报桌面客户端 cookie 库里残留的 dsh-auth-* 本地登录凭据,并随包分发「客户端完全退出后」可执行的清理命令。"
5
+ }
6
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-cookie-cleaner",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "Cookie cleaner for DeepSeek Harness: reports the local dsh-auth-* entries left in the desktop client's Chromium cookie store and ships a standalone command that purges them once the client is fully closed (backup + atomic transaction, credentials/sessions/plugin config untouched).",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -20,6 +20,7 @@
20
20
  "exports": {
21
21
  ".": "./src/index.js",
22
22
  "./core": "./src/core.js",
23
+ "./locale/*.json": "./locale/*.json",
23
24
  "./package.json": "./package.json"
24
25
  },
25
26
  "dsh": {
@@ -53,9 +54,10 @@
53
54
  },
54
55
  "scripts": {
55
56
  "sync-hosts": "node scripts/sync-hosts.mjs",
57
+ "gen-locales": "node scripts/gen-locales.mjs",
56
58
  "test": "node --test \"tests/*.test.js\"",
57
59
  "lint": "eslint .",
58
- "gate": "node scripts/sync-hosts.mjs --check && npm run lint && npm test",
60
+ "gate": "node scripts/sync-hosts.mjs --check && node scripts/gen-locales.mjs --check && npm run lint && npm test",
59
61
  "prepack": "npm run gate"
60
62
  },
61
63
  "dependencies": {
@@ -72,6 +74,7 @@
72
74
  "files": [
73
75
  "src",
74
76
  "scripts",
77
+ "locale",
75
78
  "cordis.patch.yml",
76
79
  "dsh.plugin.json",
77
80
  "README.md",
@@ -0,0 +1,82 @@
1
+ /**
2
+ * scripts/gen-locales.mjs — 生成 locale/<lang>.json(9 语包元数据)。
3
+ *
4
+ * 单一真源就是本文件的 TABLE;`--check` 模式只校验磁盘与表一致(prepack 门禁挂它),
5
+ * 避免「手改了 json 没同步表」或反之。宿主以 en.json 为锚,缺锚则整个 locale/ 被忽略。
6
+ */
7
+ import fs from 'node:fs'
8
+ import path from 'node:path'
9
+ import { fileURLToPath } from 'node:url'
10
+
11
+ const ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..')
12
+ const OUT = path.join(ROOT, 'locale')
13
+
14
+ const TABLE = {
15
+ zh: {
16
+ title: 'Cookie 清理器',
17
+ description: '只读播报桌面客户端 cookie 库里残留的 dsh-auth-* 本地登录凭据,并随包分发「客户端完全退出后」可执行的清理命令。',
18
+ },
19
+ en: {
20
+ title: 'Cookie Cleaner',
21
+ description: "Reports leftover dsh-auth-* entries in the desktop client's cookie store and ships a command that purges them once the client is fully closed.",
22
+ },
23
+ ja: {
24
+ title: 'Cookie クリーナー',
25
+ description: 'デスクトップクライアントの cookie ストアに残った dsh-auth-* を読み取り専用で報告し、クライアントを完全終了後に消去するコマンドを同梱します。',
26
+ },
27
+ ko: {
28
+ title: 'Cookie 정리 도구',
29
+ description: '데스크톱 클라이언트 cookie 저장소에 남은 dsh-auth-*를 읽기 전용으로 보고하고, 클라이언트를 완전히 종료한 뒤 지우는 명령을 함께 배포합니다.',
30
+ },
31
+ fr: {
32
+ title: 'Nettoyeur de cookies',
33
+ description: "Signale les entrées dsh-auth-* restantes dans la base de cookies du client desktop et fournit une commande qui les purger une fois le client entièrement fermé.",
34
+ },
35
+ de: {
36
+ title: 'Cookie-Räumer',
37
+ description: 'Meldet übrig gebliebene dsh-auth-* Einträge im Cookie-Speicher des Desktop-Clients und liefert einen Befehl, der sie nach vollständigem Beenden des Clients räumt.',
38
+ },
39
+ it: {
40
+ title: 'Pulitore di cookie',
41
+ description: "Segnala le voci dsh-auth-* residue nell'archivio cookie del client desktop e fornisce un comando che le elimina dopo aver chiuso completamente il client.",
42
+ },
43
+ ru: {
44
+ title: 'Очистка cookie',
45
+ description: 'Отчитывается об остатках dsh-auth-* в хранилище cookie десктопного клиента и поставляет команду очистки, применимую только после полного выхода из клиента.',
46
+ },
47
+ es: {
48
+ title: 'Limpiador de cookies',
49
+ description: 'Informa de las entradas dsh-auth-* residuales en el almacén de cookies del cliente de escritorio y ofrece un comando que las purga tras cerrar del todo el cliente.',
50
+ },
51
+ }
52
+
53
+ const langs = Object.keys(TABLE)
54
+ if (langs.length !== 9) throw new Error('locale 必须正好 9 语,当前 ' + langs.length)
55
+ if (!langs.includes('en')) throw new Error('缺 en 锚,宿主会忽略整个 locale/ 目录')
56
+
57
+ const check = process.argv.includes('--check')
58
+ const drift = []
59
+ fs.mkdirSync(OUT, { recursive: true })
60
+
61
+ for (const lang of langs) {
62
+ const expected = JSON.stringify({ meta: TABLE[lang] }, null, 2) + '\n'
63
+ const file = path.join(OUT, `${lang}.json`)
64
+ if (check) {
65
+ const actual = fs.existsSync(file) ? fs.readFileSync(file, 'utf8') : null
66
+ if (actual === null) drift.push(`${lang}.json 缺失`)
67
+ else if (actual !== expected) drift.push(`${lang}.json 与表不一致`)
68
+ } else {
69
+ fs.writeFileSync(file, expected, 'utf8')
70
+ }
71
+ }
72
+
73
+ if (check) {
74
+ if (drift.length > 0) {
75
+ process.stderr.write('locale 漂移:\n - ' + drift.join('\n - ') + '\n运行 `node scripts/gen-locales.mjs` 修复。\n')
76
+ process.exitCode = 1
77
+ } else {
78
+ process.stdout.write(`locale 9 语与表一致(锚 en 在位)\n`)
79
+ }
80
+ } else {
81
+ process.stdout.write(`已生成 ${langs.length} 份 locale/<lang>.json\n`)
82
+ }
@@ -39,10 +39,14 @@ if (check) {
39
39
  process.stdout.write(`双清单一致(${HOSTS.length} 条宿主线)\n`)
40
40
  }
41
41
  } else if (failures.length > 0) {
42
+ // 版本号以 package.json 为源,把同号刷进 dsh.plugin.json(不然改版本必遗漏一处,V1 闸抓不到)
42
43
  pkg.engines = { ...pkg.engines, dsh: range }
43
44
  pkg.dsh = { ...pkg.dsh, compatibility: { ...pkg.dsh?.compatibility, dshReleases: releases } }
44
45
  manifest.engines = { ...manifest.engines, dsh: range }
45
- manifest.version = pkg.version
46
+ if (manifest.version !== pkg.version) {
47
+ manifest.version = pkg.version
48
+ process.stdout.write(`dsh.plugin.json#version 同步为 ${pkg.version}\n`)
49
+ }
46
50
  fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, 2) + '\n', 'utf8')
47
51
  fs.writeFileSync(manifestPath, JSON.stringify(manifest, null, 2) + '\n', 'utf8')
48
52
  process.stdout.write(`已同步 ${HOSTS.length} 条宿主线到 package.json / dsh.plugin.json\n`)
package/src/cli.js CHANGED
@@ -2,31 +2,43 @@
2
2
  /**
3
3
  * dsh-cookie-cleaner — 独立清理脚本(可在 npm 全局/任意 shell 下直接执行)。
4
4
  *
5
- * 为什么独立成脚本:cookie 库在客户端运行期间被 Chromium 独占(实测连只读打开
6
- * 都会失败),所以清理只能发生在「客户端已完全退出」的时刻——那时宿主插件
7
- * 根本不存在,执行体必须是这个包里的脚本。
5
+ * 为什么独立成脚本:cookie 库在客户端运行期间被 Chromium 独占(实测写入必须等退出),
6
+ * 所以清理只能发生在「客户端已完全退出」的时刻——那时宿主插件根本不存在,
7
+ * 执行体必须是这个包里的脚本。
8
8
  *
9
9
  * 包是 ESM(宿主装载与 npm bin 都走 ESM),core 只有一份实现,两边共用。
10
+ * 输出语言:--lang > DSH_COOKIE_LANG/DSH_LANG > LC_ALL/LANG > 系统 locale > zh。
10
11
  */
11
12
  import path from 'node:path'
13
+ import process from 'node:process'
12
14
  import * as core from './core.js'
15
+ import { LANGS, detectLang, normalize, translator } from './i18n.js'
13
16
 
14
- const USAGE = `dsh-cookie-cleaner — 清理 DSH 客户端留在 cookie 库里的本地登录凭据(dsh-auth-*)
17
+ function usage() {
18
+ return `dsh-cookie-cleaner — 清理 DSH 客户端留在 cookie 库里的本地登录凭据(dsh-auth-*)
15
19
 
16
- 用法(务必先完全退出 DSH 客户端:托盘 → 退出,进程列表里不再有 DeepSeek Harness):
17
- dsh-cookie-cleaner 查看现状:库在哪、有多少条 dsh-auth-*、多少已过期
18
- dsh-cookie-cleaner --clean 删除回环域(127.0.0.1/localhost/[::1])下全部 dsh-auth-*
19
- dsh-cookie-cleaner --clean --expired-only 只删已过期的(保守档)
20
- dsh-cookie-cleaner --clean --dry-run 只看会删几条,不写盘
21
- dsh-cookie-cleaner --db=<完整路径> 手动指定 cookie 库
20
+ 用法(务必先${core.exitInstruction()}):
21
+ dsh-cookie-cleaner 查看现状:库在哪、多少条 dsh-auth-*、多少已过期
22
+ dsh-cookie-cleaner --clean 删除回环域(127.0.0.1/localhost/[::1])下全部 dsh-auth-*
23
+ dsh-cookie-cleaner --clean --expired-only 保守档:只删已过期的
24
+ dsh-cookie-cleaner --clean --dry-run 只看会删几条,不写盘
25
+ dsh-cookie-cleaner --db=<完整路径> 手动指定 cookie 库(非默认安装/flatpak/snap 用)
22
26
 
23
- 可选:--no-backup 不产出 .bak 副本;--no-vacuum 不做 VACUUM 收缩
24
- 退出码:0 成功;1 失败(库被占用/没找到/参数非法)
27
+ 库位置默认按平台惯例推导(也可用 DSH_USER_DATA / DSH_COOKIE_DB 覆盖):
28
+ Windows %APPDATA%\\@deepseek-ai\\dsh-desktop\\Network\\Cookies
29
+ macOS ~/Library/Application Support/@deepseek-ai/dsh-desktop/Network/Cookies
30
+ Linux ~/.config/@deepseek-ai/dsh-desktop/Network/Cookies
31
+
32
+ 其它:--no-backup 不产出 .bak 副本;--no-vacuum 不做 VACUUM 收缩;
33
+ --lang <${LANGS.join('|')}> 指定输出语言(缺省跟随系统 locale)
34
+ 退出码:0 成功;1 失败(库被占用/无权限/没找到/参数非法)
25
35
  `
36
+ }
26
37
 
27
38
  function parseArgs(argv) {
28
- const options = { clean: false, expiredOnly: false, dryRun: false, noBackup: false, noVacuum: false, db: '', help: false }
29
- for (const arg of argv) {
39
+ const options = { clean: false, expiredOnly: false, dryRun: false, noBackup: false, noVacuum: false, db: '', lang: '', help: false }
40
+ for (let i = 0; i < argv.length; i++) {
41
+ const arg = argv[i]
30
42
  if (arg === '--clean') options.clean = true
31
43
  else if (arg === '--expired-only') options.expiredOnly = true
32
44
  else if (arg === '--dry-run') options.dryRun = true
@@ -34,8 +46,10 @@ function parseArgs(argv) {
34
46
  else if (arg === '--no-vacuum') options.noVacuum = true
35
47
  else if (arg === '--help' || arg === '-h') options.help = true
36
48
  else if (arg.startsWith('--db=')) options.db = arg.slice('--db='.length)
49
+ else if (arg === '--lang') options.lang = normalize(argv[++i] ?? '')
50
+ else if (arg.startsWith('--lang=')) options.lang = normalize(arg.slice('--lang='.length))
37
51
  else {
38
- process.stderr.write(`未知参数:${arg}\n\n${USAGE}`)
52
+ process.stderr.write(`未知参数:${arg}\n\n${usage()}`)
39
53
  process.exitCode = 1
40
54
  return undefined
41
55
  }
@@ -46,8 +60,10 @@ function parseArgs(argv) {
46
60
  function main() {
47
61
  const options = parseArgs(process.argv.slice(2))
48
62
  if (options === undefined) return
63
+ const lang = options.lang || detectLang(process.env)
64
+ core.setLang(lang)
49
65
  if (options.help) {
50
- process.stdout.write(USAGE)
66
+ process.stdout.write(usage())
51
67
  return
52
68
  }
53
69
  const explicitPath = options.db ? path.resolve(options.db) : ''
@@ -56,12 +72,20 @@ function main() {
56
72
  if (!options.clean) {
57
73
  const stat = core.statCookies({ explicitPath, env })
58
74
  process.stdout.write(core.describeStat(stat) + '\n')
59
- if (stat.verdict === 'warn' && stat.reason !== 'busy') {
60
- process.stdout.write('下一步:完全退出 DSH 客户端后执行 `dsh-cookie-cleaner --clean`(默认会连未过期的一起删,不影响登录,见 README)。\n')
61
- } else if (stat.reason === 'busy') {
62
- process.stdout.write('下一步:完全退出 DSH 客户端后重跑本命令。\n')
75
+ const exit = core.exitInstruction()
76
+ if (stat.reason === 'busy') {
77
+ process.stdout.write(nextLine('nextCliRerun', { exit }) + '\n')
78
+ } else if (stat.reason === 'permission') {
79
+ process.stdout.write(nextLine('nextCliPermission', {}) + '\n')
80
+ } else if (stat.reason === 'missing') {
81
+ // 文件不存在时提“关客户端”是误引导,直接给 --db 形式
82
+ process.stdout.write(msg('nextCliPermission', {}) + '\n')
83
+ } else if (stat.verdict === 'warn') {
84
+ process.stdout.write(nextLine('nextCliClean', { exit }) + '\n')
63
85
  }
64
- process.exitCode = stat.reason === 'busy' || stat.verdict === 'skipped' ? 1 : 0
86
+ // 退出码用黑名单:只有「真读到内容」的档位才是 0。白名单写法会把新档误归成成功。
87
+ const okReason = stat.reason === 'has-stale-entries' || stat.reason === 'nothing-to-clean' || stat.verdict === 'ok'
88
+ process.exitCode = okReason ? 0 : 1
65
89
  return
66
90
  }
67
91
  const result = core.cleanCookies({
@@ -78,20 +102,34 @@ function main() {
78
102
  return
79
103
  }
80
104
  if (result.dryRun) {
81
- process.stdout.write(`[dry-run] 将删除 ${result.wouldDelete} 条:${result.path}\n未写盘。去掉 --dry-run 即可执行。\n`)
105
+ process.stdout.write(msg('dryRun', { count: result.wouldDelete, path: result.path }) + '\n' + msg('dryRunTail', {}) + '\n')
82
106
  return
83
107
  }
84
- process.stdout.write(
85
- `已删除 ${result.deleted} 条 dsh-auth-*(${result.expiredOnly ? '仅已过期' : '全部'})\n` +
86
- ` 库:${result.path} ${result.beforeBytes} B → ${result.afterBytes} B\n` +
87
- (result.backup ? ` 备份:${result.backup}\n` : ' 备份:已按 --no-backup 跳过\n') +
88
- ' 账号凭据、会话、插件配置均未触碰;下次启动会重新换发本地 cookie。\n',
89
- )
108
+ const lines = [
109
+ msg('deleted', { count: result.deleted, scope: result.expiredOnly ? msg('scopeExpired', {}) : msg('scopeAll', {}) }),
110
+ msg('dbSize', { path: result.path, before: result.beforeBytes, after: result.afterBytes }),
111
+ ]
112
+ if (result.backup) {
113
+ lines.push(msg('backup', { backup: result.backup }) + ((result.backupSidecars ?? []).length ? msg('backupWith', { sidecars: result.backupSidecars.join(', ') }) : ''))
114
+ if ((result.skippedSidecars ?? []).length) lines.push(msg('backupWarn', { sidecars: result.skippedSidecars.join(', ') }))
115
+ } else {
116
+ lines.push(msg('backupSkipped', {}))
117
+ }
118
+ lines.push(msg('untouched', {}))
119
+ process.stdout.write(lines.join('\n') + '\n')
90
120
  } catch (e) {
91
- const busy = e && e.code === 'cookie-busy'
92
- process.stderr.write((busy ? '' : '清理失败:') + (e && e.message ? e.message : String(e)) + '\n')
121
+ const busy = e && (e.code === 'cookie-busy' || e.code === 'cookie-permission')
122
+ process.stderr.write((busy ? '' : msg('cleanFailed', {})) + (e && e.message ? e.message : String(e)) + '\n')
93
123
  process.exitCode = 1
94
124
  }
95
125
  }
96
126
 
127
+ /** 取当前语言的词条(core 内部也按同一语言出文案,保持一致)。 */
128
+ function msg(key, vars) {
129
+ return translator(core.activeLang())(key, vars)
130
+ }
131
+ function nextLine(key, vars) {
132
+ return msg(key, vars)
133
+ }
134
+
97
135
  main()