dsh-connect-workbuddy 5.15.2 → 5.17.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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,286 @@
1
1
  # Changelog
2
2
 
3
+ ## 5.17.0 (2026-11-01)
4
+
5
+ ### 修复
6
+
7
+ - **暗色主题下「虚拟值 / 真实值」的选中项是一格空白**:选中态原来用
8
+ `background: 品牌色 + color: #fff`,而暗色主题里 `--dsw-alias-brand-primary` 本身就是浅色,
9
+ 白字落上去等于同色叠同色。现在改成「前景色做底、底色做字」这一对(`label-primary` /
10
+ `bg-base`),亮色是深底浅字、暗色是浅底深字,按定义互为反色,不再依赖某个具体色值。
11
+ 悬停样式同时排除选中项——它的选择器权重更高,不排除会把选中态冲掉。
12
+ - **弹窗里「真实设备 Token」几乎看不见**:标题从 `label-dimmed` 改为 `label-primary` + 600,
13
+ 说明文字从 tertiary 提到 secondary。虚线边框已经表达了"占位",不需要再靠文字颜色降级。
14
+ - **留空时的派生值现在显示出来**:设备参数弹窗在两个空输入框下面各自列出**真正会发出去的**
15
+ `X-Machine-ID` / `X-Session-ID`(等宽、可整段选中)。派生输入是 uid(与构头同一份),
16
+ 因此同一台机器上不同账号必然不同、同一账号跨重启必然相同。算不出来时分开两种原因:
17
+ 本机没有设备盐、与这个账号没有 uid——用户能做的事不一样。
18
+ - **`lib/` 不再可能"声明了但不存在"**:`pnpm install` 现在通过 `prepare` 构建一次;`build`
19
+ 结束时会核对 `main` / `types` / `bin` / `exports` / `dsh.bundle.patch` 声明的每个文件是否
20
+ 真的生成,并新增 `pnpm run verify:entries`(可对任意已安装目录运行)。
21
+ - 触发这次修复的现象:从源码检出 `link:` 安装后,DSH 报「声明的入口产物缺失(源码检出或
22
+ 构建被拦),下次启动会失败」。`lib/` 是 gitignore 的构建产物,而 `link:` 安装**不执行**
23
+ 包的 `prepare`,此前仓库里也只有 `prepack`(只在打包时跑),所以 `pnpm install` 之后
24
+ 源码目录里依然没有入口文件。DSH 的判定本身是对的,缺的是构建这一步。
25
+
26
+ ### 变更
27
+
28
+ - **SDK token 改为后台自动获取**:插件启动即取一次,此后在 10 分钟 TTL 到期前 15 秒
29
+ 自动换新;取数失败 60 秒后重试,本机没有 SDK 则 5 分钟复查一次。此前只有请求路径
30
+ 会取 token,于是一个空闲进程的「SDK」分区永远停在"已加载、没取过"——那与"SDK 坏了"
31
+ 在界面上长得一模一样,也是重启后看不到 token 的原因。
32
+ - 预热是单链定时器(间隔按当时的时间重算,不是固定 `setInterval`),插件卸载时
33
+ `stopAutoRefresh()` 清掉,不会留下一个永远关不掉的子进程工厂。
34
+ - 失败仍走请求路径的 30 秒退避:一轮对话十几条并发请求不会变成十几个子进程。
35
+ - **「SDK」分区可以直接填 SDK 目录**(评审意见 #1,@susulqx)。
36
+ - 之前只有环境变量 `WORKBUDDY_TURING_SDK_DIR` 一条旁路:自动发现链不命中时
37
+ (装在非默认盘、或另一份副本),用户能做的只有改环境变量再重启。
38
+ - 现在卡片 `GET`/`POST /device-profiles`(`kind: 'sdk'`)保存
39
+ `sdkDir` 与 `sdkFallbackToVirtual`,落在
40
+ `$DSH_HOME/.workbuddy-device-profiles.json`。**留空 = 回到自动发现**,不是
41
+ "路径为空";填错时状态行会答 `missing`/`error` 并带上那个路径,而不是静默
42
+ 回退成自动发现的结果(后者会让人以为保存失败,然后反复保存)。
43
+ - **保存后立刻生效,不用重启**:`createTuringSdk` 的目录从构造期常量改成
44
+ 每次 `probe` 现问一次(`dirSource`),probe 缓存也按**解析结果**判有效——
45
+ 否则填了新目录要等 10 秒的缓存过期,而那 10 秒里用户看到的还是旧目录。
46
+ - 优先级:显式 `dir`(测试)→ `WORKBUDDY_TURING_SDK_DIR` → 卡片手填 →
47
+ 自动发现。环境变量压过卡片,因为它是排障旁路(`doctor` 只能读环境变量),
48
+ 反过来会让一个排障时设的变量在下一次点保存后静默失效。
49
+ - 路径只去首尾空白,**不**规范化分隔符与大小写:那是用户从资源管理器复制来的
50
+ 路径,改了之后"我填的和看到的不一样"会让人怀疑没存上。
51
+
52
+ - **取不到真实设备时退回虚拟值,默认开**(评审意见 #2,@susulqx)。
53
+ - 之前「真实值」档在 SDK 不可用时**一个设备头都不发**(P3 的取舍:静默退回会
54
+ 让界面写着"真实值"、线上跑着虚拟值)。这个取舍有道理,但风控严的时候
55
+ "有总比没有好"也是合理的诉求,所以改成**用户可选,默认开**。
56
+ - 退回时档位**降成 `virtual`**,不是保留 `real` 再补一对派生 id:`deviceTier`
57
+ 既决定发哪些头,也决定界面与 `doctor` 怎么称呼"现在发的是什么"。保留 `real`
58
+ 会让报告与出站字节相反,而报告正是用户判断"到底退没退"的唯一依据。
59
+ - 退回**不读**逐账号覆盖值:这一跳是"真实值档塌回虚拟值",不是"用户切到了虚拟
60
+ 值档"。把齿轮里那对覆盖值混进来,等于让一次降级顺手改变这台机器对外声称的
61
+ 身份,而用户并没有要求这件事。
62
+ - `doctor` 的 `--json` 因此增 `deviceIdentity.tierSent` 与
63
+ `deviceIdentity.fallbackToVirtual`(schemaVersion 9 → 10),**只在分岔时
64
+ 出现**——`tierSent === tier` 是常态,多一个恒等字段只会让人以为两者永远可能
65
+ 不同。人类可读那一行读作
66
+ `real requested, virtual values (fell back: no real device token)`,并照常印出
67
+ 派生设备与文件源那一行(退回时它们真的被用上了)。
68
+
69
+ ### 测试
70
+
71
+ - 新增 **17** 例(2879 总例,较本套改动前净增 17):
72
+ - `tests/device-profile.spec.ts` +9:留空 = 自动发现、`undefined` 不动这一项、
73
+ 两个控件互不覆盖、坏路径保留不静默回退、缺字段 = 回退开(5.16.0 的文件升级
74
+ 即生效)、只有显式 `false` 才关、保存目录不动档位与覆盖值、lookup 暴露两项。
75
+ - `tests/turing-sdk.spec.ts` +4:新填的目录**下一次 `info()` 就命中**、probe
76
+ 缓存不跨目录复用、`WORKBUDDY_TURING_SDK_DIR` 压过卡片、显式 `dir` 压过两者。
77
+ - `tests/wire-profile.spec.ts` +3:开关开时发派生对、**不复用**逐账号覆盖值、
78
+ 有真 token 时照旧发真 token(开关无关)。
79
+ - `tests/device-state.spec.ts` +4:退回时 `tier` 保留 `real` 而 `tierSent` 是
80
+ `virtual` 且 `onWire` 是派生对、开关关时零设备头、有 token 时退回不发生、
81
+ 虚拟值档里这条分支不可达。
82
+ - **Windows 11 真机端到端**:把 `mode: real` + 一个不存在的 `sdkDir` 写进设置文件,
83
+ `doctor` 输出 `Device SDK: missing (... — Z:\nope\turing-sdk)` 且首行为
84
+ `real requested, virtual values (fell back: no real device token)`;把
85
+ `sdkFallbackToVirtual` 改回 `false`,首行变回 `real values: X-Device-Token`
86
+ (P3 原行为)。两条都在真机上跑过,不是纸面推演。
87
+ - **全仓** 2879 例中 2878 通过(171 文件),类型检查通过,build 通过。
88
+ `tests/issue12-region-hiding.spec.ts` 那条轮询 flake 依旧失败——已在未修改的
89
+ `d5183b2` 上同样复现,与本套改动无关(详见 5.16.0 那一条记录)。
90
+
91
+ - **设备身份取证面(P0)**:新增 `src/device-id.ts`(36 位十六进制 id,
92
+ `sha256(namespace + salt + purpose + uid)`,命名空间与用途进哈希、不进线上)、
93
+ `src/device-salt.ts`(本机盐,`$DSH_HOME/.workbuddy-device.json`,首建后只读——
94
+ 文件缺失与不可读分开处理,**不可读永不重键**:重键等于给同一台机器换身份)、
95
+ `src/device-state.ts`(`onWire` 为算出的实际发出头)。`doctor` 增 `deviceIdentity`
96
+ 块(schemaVersion 6 → 7)。
97
+ - **出站身份统一到 `WorkBuddy`(P1)**:chat 的 `X-Product: SaaS`、`X-IDE-Type: CLI`
98
+ 与 billing 的裸 HTTP 形态统一为 `X-Product` / `X-IDE-Type` / `X-Agent-Purpose:
99
+ conversation` + billing 补齐 `User-Agent: WorkBuddy/<ver>` / `Origin` / `Referer` /
100
+ `X-Requested-With` / `X-CodeBuddy-Request`,`Accept-Language` 按区 `zh-CN` /
101
+ `en-US`,并加 `X-Root-Request-ID`(与 `X-Conversation-Request-ID` 同值)。
102
+ 元数据读(`/v3/config`、`/v2/chat/busy`)与 refresh 一跳**字节不动**。
103
+ 配置项 `wireProfile: conservative` 逐字节还原 5.16.0(含 `X-Product: SaaS`),
104
+ 默认 `balanced`(schemaVersion 7,字段级见 `doctor`)。
105
+ - **外部 deviceToken 文件源(P2)**:`WORKBUDDY_DEVICE_TOKEN_FILE` 指向别的工具
106
+ (A / B 面板)维护的 token 文件,5 分钟重读、4 KB 上限,裸值与 `{"token":…}`
107
+ 信封都吃;token 字节绝不进日志与 `doctor`(schemaVersion 7 → 8,
108
+ `deviceIdentity.token`)。
109
+ - **设备头档位 UI(P2.5)**:卡片设备头档位「虚拟值 / 真实值」切换与逐账号齿轮
110
+ (覆盖 `X-Machine-ID` / `X-Session-ID`),落盘
111
+ `$DSH_HOME/.workbuddy-device-profiles.json`(`0600`、锁内合并写)。路由
112
+ `GET`/`POST /plugins/dsh-connect-workbuddy/device-profile`(loopback-only)。
113
+ - **真实设备参数(P3)**:新增「真实值」档,卡片新增「SDK」分区。
114
+ - **档位互斥落在档位上**:`虚拟值` 发派生的 `X-Machine-ID` / `X-Session-ID`(可逐账号
115
+ 覆盖),`真实值` **只发** `X-Device-Token`,派生对整条路径不存在。此前的过渡形态
116
+ (真 token + 派生对同时发)不再是可达的组合——真 token 内含设备信息,旁边挂一对
117
+ 按 uid 算出来的 id 等于自证不一致。
118
+ - **真实值档下所有账号共用这台机器的真实设备**,因此每行的齿轮关闭,点击时说明原因。
119
+ 取不到 token 时**一个设备头都不发**,不退回派生对:界面写着「真实值」而线上跑着
120
+ 虚拟值,正是分档要消灭的那种不一致。
121
+ - **SDK 用本机已安装的桌面端,不随包分发**:插件包**不再**包含 Turing Shield
122
+ 的二进制(`.node` 里的 pdb 路径证明它是桌面端仓库的构建产物;重新分发闭源
123
+ 厂商二进制需要回答"从哪来、什么版本、依不依得着 EULA",这些答案属于桌面端
124
+ 发行方,不属于我们)。目录解析:`WORKBUDDY_TURING_SDK_DIR` 显式指定优先,
125
+ 否则按桌面端安装形状自动发现(Windows 默认布局 + 卸载注册表,macOS
126
+ `/Applications` 与 `~/Applications` 的 bundle;见
127
+ `native/turing-sdk/README.md`)。**子进程**调用(`worker.cjs`):原生模块的
128
+ 加载失败与不可取消的死等只该是"这一条命令失败",不该是插件进程失败。
129
+ 子进程只拿白名单环境变量,不整份继承。
130
+ - **macOS 现状如实记录**:probe 能过(真机验证),token 取不到——SDK 向
131
+ dispatch 主队列 `dispatch_sync`,纯 libuv 进程永不排空它(`sample` 栈实测,
132
+ 见 `native/turing-sdk/README.md`)。mac 上表现为 `ready` 但 token 不可用,
133
+ 真实值档按上面的规则降级。修它需要排空主队列的伴生原生模块,不在本次范围。
134
+ - token 10 分钟重取、失败时 24 h 内旧值可用并标 `stale`、**不落盘**;完整值只在用户
135
+ 点「显示 / 复制」时经 `POST ?action=reveal` 给一次,其余输出只有掩码与长度。
136
+ - 卡片新增「SDK」分区(与「模型 / 能力 / 诊断」同一行):连接状态、SDK 目录与运行时、
137
+ 最近取到时间与当前档位、`X-Device-Token` 的掩码 + 长度,附「显示 / 复制 / 重新获取」。
138
+ 路由 `GET`/`POST /plugins/dsh-connect-workbuddy/device-sdk`(loopback-only)。
139
+ - `doctor` 增 `deviceIdentity.tier` 与 `deviceIdentity.sdk`(schemaVersion 8 → 9;
140
+ 相对 5.16.0 的 schemaVersion 6,本套变更合起来是 **6 → 9**)。
141
+
142
+ ### 测试
143
+
144
+ - **修掉 `refreshes itself when the token expires` 的竞态**(在作者的 `26be06e`
145
+ 上 4/4 复现,不是本套改动引入的)。
146
+ - 症状:该用例间歇性红,报
147
+ `AssertionError: expected 1793477227956 to be greater than 1793477227956`。
148
+ - 根因:假 worker 在**启动时**就把 `calls` 加一,而 `cached.fetchedAtMs` 要等
149
+ 子进程**退出**、父进程收下答案才更新——两者之间有几十毫秒的窗口。旧写法先
150
+ `waitFor` 到 `calls` 变大、再**立刻**比较时间戳,正好落在这个窗口里,于是
151
+ 约一半的跑法拿到的是上一个值。
152
+ - 改法:`waitFor` 的条件换成"时间戳确实前进了",断言的仍然是同一件事,只是不再
153
+ 假设两个计数器同步;跑完再确认 `calls` 也变大了(证明不是把时间戳改了个名字)。
154
+ - 变异验证:把断言换回旧写法,连跑 4 次红 3 次;换成新写法连跑 6 次全绿。
155
+
156
+ - **`hasTuringSdkBinding` 的兜底不再随宿主平台分岔**(Windows 腿上发现的真分岔)。
157
+ - 症状:`tests/turing-sdk.spec.ts` 的 "exposes the binding gate as a
158
+ platform-aware helper" 在 **Windows 腿确定性失败**、在 macOS 腿上绿。macOS 上
159
+ 跑过整套的评审看不到它,所以它一路绿到了这里。
160
+ - 根因在被测代码,不在测试:兜底拼法取的是**宿主**的 `join`
161
+ (`process.platform === 'win32' ? win32.join : posix.join`),而
162
+ `process.platform === 'win32'` 时它恰好等于数据的 `win32.join`,于是
163
+ `hostPath !== dataPath` **恒为假**,兜底分支被整个短路。同一个调用
164
+ `(dir, exists, 'win32')` 因此在 Windows 上只试一种拼法、在 macOS 上试两种。
165
+ - 改法:兜底显式取**另一种**拼法(`platform === 'win32' ? posix.join :
166
+ win32.join`),答案只由参数决定。测试侧补一条反向用例(数据 POSIX、喂 win32
167
+ 形状的目录)——两个方向一起断言,这个分岔在**任意宿主**上都会红。
168
+ - 变异验证:把兜底改回宿主 `join`,正向断言当场打红(1 failed / 28 passed);
169
+ 恢复后 29 passed。
170
+ - **Windows 11 真机全量**(Node 24.22.1):`typecheck` 通过、`build` 通过、
171
+ **2829 例中 2828 通过**。唯一失败是 `tests/issue12-region-hiding.spec.ts` 的
172
+ 轮询 flake,已在**未修改的 `d5183b2` 上同样复现**(2690/2691),与本 PR 无关。
173
+ - **Windows 上真实 SDK 链路跑通**:发现链命中
174
+ `%LOCALAPPDATA%\Programs\WorkBuddy\resources\app.asar.unpacked\native\turing-sdk`,
175
+ `probe` 返回 `ready`(`win32-x64`,napi 10),`tokens.refresh()` 取回 `v3:` 前缀
176
+ token、长度 1210、耗时 **418 ms**。macOS 上那条 `dispatch_sync` 主队列死锁在
177
+ Windows 上不复现——Windows 的原生 binding 不走 dispatch 主队列。
178
+
179
+ ## 5.16.0 (2026-10-31)
180
+
181
+ > **Windows 上凭据库的明文 token 之前对同机低权限进程可读。** issue #183。
182
+ > `mode: 0o600` 在 Windows 上不生效,而插件一直把它当成已经做了权限限制。
183
+
184
+ ### 变更
185
+
186
+ - **凭据库在 Windows 上显式加固文件夹权限**(issue #183)。
187
+ - **问题**:`~/.dsh/workbuddy-vault/<region>/<accountId>.json` 存着解密后的
188
+ `accessToken` / `refreshToken` 明文,写入时传 `mode: 0o600`。Node 的
189
+ `fs.writeFile` / `fs.rename` 在 Windows 上**忽略** `mode`——权限完全由继承的
190
+ DACL 决定。报告者用 `Get-Acl` 实测:该文件对
191
+ `<机器>\CodexSandboxUsers`(DSH 自己沙箱进程的账户)可写可读,也就是本机
192
+ 任何沙箱进程 / 插件 / 脚本都能取到一枚可用 JWT。
193
+ - **改法**:新增 `src/windows-acl.ts`。`writeVaultEntry()` 在写入**之前**加固
194
+ vault **根目录**(`dirname(dir)`——它才是承载 `~/.dsh` 那个
195
+ `Everyone: FullControl` 的一层),**一次 `icacls` 调用**,不遍历子目录:
196
+ 实测 Windows 会把新的可继承 ACE 沿树重新传播,父目录加固后,子目录与其中的
197
+ 既有文件都变成恰好那三条 ACE(`weak=0`)。ACE 只保留
198
+ `OWNER RIGHTS`(S-1-3-4) / `SYSTEM`(S-1-5-18) / `Administrators`(S-1-5-32-544),
199
+ 全部用 SID 而非账户名,因此在任意语言的 Windows 上行为一致。
200
+ - **为什么必须加固在写入之前**:`writeFileAtomic` 是「写临时 inode → rename
201
+ 覆盖」,替换产生的是**新 inode**。写在之后加固,既留下 pre-rename 窗口,也
202
+ 会被下一次替换抹掉。加固目录在前,替换出来的 inode 一出生就继承受限 ACE。
203
+ - **为什么不用 `icacls /T`**:实测 `/T` 配合 `(OI)(CI)` 会让它走过的**每个
204
+ 文件得到空 DACL**(`ACEcount=0`),谁都读不了。正确形态是目录用
205
+ `(OI)(CI)`、文件用裸 `(F)`;本实现的写入路径只加固目录,靠传播覆盖文件。
206
+ - **成本与并发**:`icacls` 是子进程,实测静止态 19–52 ms、**并行负载下最高
207
+ 1242 ms**。因此除了「一个目录一次调用」,同一路径**正在进行的**加固会被
208
+ join 而不是重复发起,突发写入只排一个子进程。这个数字是实测得来的:
209
+ 最初「每次写入再加固一次文件」的版本把
210
+ `tests/issue12-region-hiding.spec.ts` 的 1 s 轮询预算顶穿,才改成现在的形态。
211
+ - **失败不致命**:加固是纵深防御,不是写入前置条件。`icacls` 失败时凭据照常
212
+ 落盘,`doctor` 会把失败情况报出来。
213
+ - **POSIX 不付任何代价**:非 Windows 直接返回 `not-windows`,不 spawn 任何子
214
+ 进程——那里的 `mode 0600` 本来就是这个意思。
215
+ - **没有实现的**:issue 的建议 1(DPAPI / `safeStorage` 加密落盘)。落盘内容
216
+ 仍是明文,只是权限收紧了;管理员、SYSTEM 服务,或已取得该用户令牌的攻击者
217
+ 仍可读取。要做到那一步需要改 vault 的磁盘格式并做迁移,属独立改动。
218
+
219
+ - **`doctor` 新增 `credentialAcl` 块**(`--json` schema 5 → 6)。逐 region 报告
220
+ vault 目录的权限状态,并在报告前**先尝试修复**——所以这个命令对已经被旧版本
221
+ 暴露过的机器是有用的,而不只是描述问题。取值:
222
+ - `protected`:只有 OWNER RIGHTS / SYSTEM / Administrators
223
+ - `exposed`:还有别的持有者,并在 `unexpected` 里点名 SID
224
+ - `unverified`:读不回来(PowerShell 缺失 / 超时)。**故意不折进 `exposed`**
225
+ ——「没测到」和「测到是脏的」需要用户做不同的事,谎报暴露本身就是一种误导
226
+ - `not-windows`:POSIX,`mode 0600` 已表达同样意图,因此不产生任何提示
227
+
228
+ - **人类可读输出新增一行** `Credential vault ACL (<region>): <state> — <detail>`,
229
+ 且在 `exposed` 时给出可直接粘贴的 `icacls` 修复命令。
230
+
231
+ ### 文档
232
+
233
+ - 新增 `docs/CACHE-HIT-70-RESEARCH.md` + `docs/ISSUE-184-REPLY.md`(issue #184
234
+ 「缓存命中太低,一直在 70 左右徘徊」的取证报告与可直接粘贴的 issue 回复)。
235
+ **只是记录,不含任何产品代码改动**——`src/upstream.ts` / `src/shim.ts` /
236
+ `src/index.ts` / `src/adapter.ts` / `src/account-pool.ts` / `src/body-report.ts`
237
+ 与 `tests/upstream.spec.ts` 均未修改,`keepPromptLast` 保持原样。
238
+ - **本机复现不出 70%**:全机 workbuddy 加权命中率 97.5%,主力模型
239
+ `deepseek-v4.1-flash` 97.9%(13,282 请求 / 3,157,473,803 prompt token)。
240
+ - **量级足够解释 70% 的机制**:会话混用模型,其中 `minimax-m3.1-flash`
241
+ 完全不复用缓存(44.6%);反推混入 52.3% 的 prompt 量即可落到 70%,
242
+ 本机 61 个混用会话实测落在 55–75%。
243
+ - **缓存按账号隔离**(A 97.4% / B 0.0% / A 复测 97.3%,同分钟同字节),
244
+ 但账号池换号要每 3.8 请求一次才能造成 70%,实测远低。
245
+ - **`keepPromptLast` 确实是 bug**(开启后每轮边界必断,断点在 message[1]
246
+ 这类极早期位置),但真实代价只有 **−1.74 个点**——真实宿主并不每个 step
247
+ 注入(两个真实会话分别 386 step/12 条、682 step/34 条)。
248
+ - **追加取证(§8)**:`billion-context` 确实在请求链路上(`127.0.0.1:18787`),
249
+ 但以代理 `startedAt` 为界做**同会话**前后对照只掉 0.31 个点;真正的最大
250
+ 单一成因是**工具注册表在会话中途增删工具**——单会话 7 个 `system/message`
251
+ 版本两两不同,每次变更整段前缀失效,turn 12 之后不再变化时命中率立刻回到
252
+ 96% 以上。次因是 `trae` 通道上游不报缓存(34 个请求 `read=0`,占该会话
253
+ 未命中的 33.7%)。
254
+ - 报告里同时记录了我自己的两次判断修正:用「`read` 冻结不动」当断裂信号是
255
+ **错的**(短 step 也会满足),改用「相对上一请求缩水 >20%」;以及用
256
+ **安装时间**而非**代理启动时间**做分界会把跨越期错算进「生效后」。
257
+
258
+ ### 测试
259
+
260
+ - 新增 **12** 例(`tests/issue183-credential-acl.spec.ts`):
261
+ - 写入路径对 vault 根目录发起**恰好一次** `icacls`(既是「加固了」,也是
262
+ 「没有退化成逐目录遍历」——后者是实测 1242 ms 的来源)
263
+ - `icacls` 失败时凭据**照样落盘**(纵深防御不能变成故障)
264
+ - POSIX 上**一个子进程都不 spawn**
265
+ - 传的是 SID 不是账户名(zh-CN 主机上账户名会被本地化)
266
+ - 目录授权必须带 `(OI)(CI)`、文件授权必须**不带**
267
+ - `/T` 永不出现
268
+ - `doctor` 的四个状态各有一条
269
+ - 记忆化只在**成功**时生效(失败必须让下次写入重试)
270
+ - **变异验证**:9 个变异体,8 个被当场打红。第 9 个(把文件授权改成
271
+ `*:(OI)(CI)(F)`)**首轮 12/12 全绿**——因为测试当时用
272
+ `filter(arg => arg.startsWith('*S-1-'))` 取授权,而变异体产生的畸形串根本
273
+ 进不了那个过滤器。已把取法改成「取 `/grant:r` 后面的那个值」并断言**恰好 3
274
+ 条**,重跑后该变异体转红。这条留在注释里,免得下一个人再写出同样取不到的断言。
275
+ - **全仓结果**:2691 例通过(160 文件),类型检查通过。
276
+ - 需要说明的是,`tests/issue12-region-hiding.spec.ts` 的
277
+ 「does not report the in-use model as withdrawn after a directoryless
278
+ save」在本机**改动前**就不稳定:未修改的 HEAD 连跑 5 次,4 次失败、1 次
279
+ 通过;本改动落地后连跑 5 次,3 次失败、2 次通过。两者属同一量级,且该用例
280
+ 断言的是上游目录内容而非文件权限,因此判定为**既有 flake**,不是本改动的
281
+ 回归。本改动与它的唯一交集是 icacls 的调用耗时,现已压到「一目录一次、
282
+ 并发合并」,不再让该用例的 1 s 轮询预算受此影响。
283
+
3
284
  ## 5.15.2 (2026-10-30)
4
285
 
5
286
  > **英文界面下的「最近刷新」不再显示成中文式的时间。** 同步自
package/README.en.md CHANGED
@@ -303,13 +303,15 @@ All three platforms are supported targets; the differences below are **implement
303
303
  | Process-heartbeat timestamp source | PowerShell `Get-Process` `StartTime` (POSIX has no `ps -lstart` equivalent) | `ps -o lstart=` | `ps -o lstart=` |
304
304
  | Child-process window | **`windowsHide` is required**: the host itself has no console (it is a GUI process), so without it every probe flashes a visible black window on screen | Not applicable (the option only takes effect on Windows) | Not applicable |
305
305
  | Transient settings-file contention | **Does hit it**: an antivirus scanner / OneDrive / an editor locking the profile's `cordis.patch.yml` briefly makes the rename replace fail, and `@deepseek-ai/dsh-atomic-write`'s retries are enabled **only on `win32`** | Does not: POSIX rename replaces outright, so the same code never enters the retry branch | Same as macOS |
306
+ | Credential vault file permissions | **`mode: 0o600` has no effect**, because permissions come from the inherited DACL → the plugin hardens the directory and file with `icacls` around each write (owner / SYSTEM / Administrators only). `doctor` reads it back and reports `protected` / `exposed` / `unverified` | Enforced by `mode 0600` | Enforced by `mode 0600` |
306
307
  | CI coverage | `windows-latest`, full suite | The developer's own Mac | `ubuntu-latest`, full suite |
307
308
 
308
- **Three Windows-specific things worth knowing**:
309
+ **Four Windows-specific things worth knowing**:
309
310
 
310
311
  1. **An account change may fail to save** (the profile's `cordis.patch.yml` held open). The plugin **reads the value back after writing**: it reports "cleared" only once the write is confirmed on disk, and otherwise reports the failure and keeps your previous choice. Close whatever holds the file and retry. See [Known limitations](#known-limitations).
311
312
  2. **Credential paths are partly verified on real Windows hardware.** The candidate list is derived from platform conventions and pinned by unit tests (including both the unset and the blank-string fallback for `LOCALAPPDATA` / `APPDATA`). On a real Windows 11 machine, `%LOCALAPPDATA%\CodeBuddyExtension\Data\Public\auth` and `%LOCALAPPDATA%\Programs\WorkBuddy\WorkBuddy.exe` **did resolve**, and the encrypted credential's `keyId` matched the registered vector verbatim. **The remaining candidates are still not verified per-item** — if your credential or app lives elsewhere, point `WORKBUDDY_AUTH_FILE` / `WORKBUDDY_APP_EXECUTABLE` at it and please report what you see.
312
313
  3. **Encrypted credentials (from 5.6.0) require the desktop app to be present**, on Windows exactly as on macOS; if the app lives in a custom directory (e.g. `E:\WorkBuddy\WorkBuddy.exe`), point `WORKBUDDY_APP_EXECUTABLE` at it.
314
+ 4. **The credential vault stores PLAINTEXT tokens** (issue #183). The plugin's vault directory `<DSH home>/workbuddy-vault/<region>/<accountId>.json` holds the decrypted `accessToken` / `refreshToken`, **unencrypted**. From 5.16.0 on Windows, each write hardens that directory with `icacls` so only the owner / SYSTEM / Administrators can read it, and `doctor` prints a `Credential vault ACL` line that reads the result back. But **restricted permissions are not encryption** — an administrator, a SYSTEM service, or an attacker who already has your user token can still read it. For encryption at rest, keep the DSH home on a BitLocker / FileVault volume. POSIX platforms rely on `mode 0600`.
313
315
 
314
316
  ### Using it on a server: carry the credential over
315
317
 
@@ -461,6 +463,20 @@ dsh plugin --profile <web|desktop|dsh-tui> exec dsh-connect-workbuddy logout #
461
463
 
462
464
  `status` and `doctor` accept `--json` for machine-readable output.
463
465
 
466
+ ### Device-identity environment variables
467
+
468
+ The outbound identity profile (`wireProfile`) and the device-header tier (`deviceTier`) are **card settings**, not environment variables. The variables below are the escape hatches for cases a card setting cannot reach:
469
+
470
+ | Variable | Default | Notes |
471
+ |---|---|---|
472
+ | `WORKBUDDY_DEVICE_TOKEN_FILE` | unset | File source for an external `X-Device-Token` in the *virtual* tier: points at a token file another tool maintains (bare value or `{"token":…}` envelope), re-read every 5 min, 4 KB cap; token bytes never reach logs or `doctor`. Same meaning as the card setting `deviceToken.file`, used when that is empty |
473
+ | `WORKBUDDY_HEADER_TRACE` | unset | Set to `1` and `doctor` prints one more section: the header **name** list each request path would send (names only — never values). For answering "what does this tier actually send" |
474
+ | `WORKBUDDY_TURING_SDK_DIR` | unset | Turing Shield SDK directory for the *real* tier. When unset the plugin **auto-discovers** the desktop app's install layouts (`/Applications`, `%LOCALAPPDATA%`, the uninstall registry hive, …); set it when the desktop app is installed yet `doctor` still reports "not found". The card's **SDK** section accepts the same directory (no env var, applies on save) and this variable takes precedence. What happens when no real device can be obtained is the next-but-one row |
475
+ | `WORKBUDDY_TURING_CHANNEL_ID` | `109144` | SDK channel id, matching the desktop app's `product.json` |
476
+ | `WORKBUDDY_TURING_PRODUCT_NAME` | `WorkBuddy` | Product name the SDK initialises with |
477
+ | `WORKBUDDY_TURING_PRODUCT_VERSION` | plugin version | Product version the SDK initialises with |
478
+ | `WORKBUDDY_TURING_KEYCHAIN_STORAGE` | unset (= off) | Set to `1` to let the SDK enable its own device-cache storage; off by default — the plugin does not write device state into the user's keychain |
479
+
464
480
  > **Why these three commands work on a machine with nothing installed (issue #47)**
465
481
  >
466
482
  > The plugin declares `@deepseek-ai/dsh-atomic-write`, `@deepseek-ai/dsh-home-paths`, and the rest of the DSH packages as **peers**: the host supplies them and the plugin ships no copy. That works inside a **booted DSH process** (the host's runtime interception layer resolves those names against the installation), but `dsh plugin … exec` is not that — it runs one `pnpm exec` in the profile directory, and that child uses **stock Node resolution**. The profile is created with `autoInstallPeers: false`, so the peers are never installed there and the two packages cannot be found.
@@ -493,6 +509,38 @@ Local dev via a `link:` install to the desktop profile (restart DSH Desktop afte
493
509
  dsh plugin --profile desktop add /Users/dmh2002/DshProject/dsh-connect-workbuddy
494
510
  ```
495
511
 
512
+ #### A `link:` install must be built first, or DSH refuses to load it
513
+
514
+ `lib/` is a build product and is gitignored, while a `link:` install runs **no lifecycle scripts**
515
+ (`prepare` never fires). Install from a source checkout that was never built and the files named by
516
+ `package.json`'s `main` / `exports` simply are not there, so DSH's plugin market answers:
517
+
518
+ ```
519
+ 声明的入口产物缺失(源码检出或构建被拦),下次启动会失败
520
+ the declared entry artifact is missing (source-only checkout or blocked build) — the next boot would fail
521
+ ```
522
+
523
+ That verdict comes from `dshmarket`'s `entryArtifactExists()`: it reads `main` and `exports` in the
524
+ installed directory and that is the whole evidence. So:
525
+
526
+ ```sh
527
+ pnpm install # `prepare` builds once (lib/ appears)
528
+ # or just build
529
+ pnpm run build
530
+ ```
531
+
532
+ Re-run a build after editing source (or `pnpm install` again), then restart DSH Desktop. If the warning
533
+ survives that, run the check — it prints every declared artifact, and separates "never built" from
534
+ "manifest and build disagree":
535
+
536
+ ```sh
537
+ pnpm run verify:entries # this checkout
538
+ node scripts/verify-entry-artifacts.mjs <installed dir> # a specific installed copy
539
+ ```
540
+
541
+ > Installing from npm (`dsh plugin add dsh-connect-workbuddy`) needs none of this: the published
542
+ > tarball already contains `lib/`, and `prepack` only regenerates it.
543
+
496
544
  ### Calling `chatStream()` from a script: it returns an **envelope**, not a stream
497
545
 
498
546
  ```ts
package/README.md CHANGED
@@ -315,13 +315,15 @@ dsh plugin --profile desktop exec dsh-connect-workbuddy doctor # 第一行就
315
315
  | 进程心跳的时间戳来源 | PowerShell `Get-Process` 的 `StartTime`(POSIX 无 `ps -lstart` 等价物) | `ps -o lstart=` | `ps -o lstart=` |
316
316
  | 子进程的窗口 | **必须 `windowsHide`**:宿主本身没有控制台(GUI 进程),漏设会让每次探测都在屏幕上闪一个可见的黑框 | 不适用(该选项仅 Windows 生效) | 不适用 |
317
317
  | 设置写入的瞬时占用 | **会踩到**:profile 的配置文件 `cordis.patch.yml` 被杀毒软件 / OneDrive / 编辑器短暂锁定会拒绝 rename 覆盖,`@deepseek-ai/dsh-atomic-write` 的重试**只在 `win32` 生效** | 不踩:POSIX 的 rename 直接替换,同一段代码不进重试分支 | 同 macOS |
318
+ | 凭据库(vault)的文件权限 | **`mode: 0o600` 不生效**,权限由继承的 DACL 决定 → 写入前后用 `icacls` 显式加固(只允许 所有者 / SYSTEM / Administrators)。`doctor` 会回读并报告 `protected` / `exposed` / `unverified` | 由 `mode 0600` 生效 | 由 `mode 0600` 生效 |
318
319
  | CI 覆盖 | `windows-latest` 跑完整套件 | 开发者本机(macOS) | `ubuntu-latest` 跑完整套件 |
319
320
 
320
- **Windows 上需要知道的三个具体点**:
321
+ **Windows 上需要知道的四个具体点**:
321
322
 
322
323
  1. **账号改动可能保存失败**(profile 的配置文件 `cordis.patch.yml` 被占用)。插件会在写入后**回读校验**:确认落盘才显示「已清除」,失败则明确报错并保留原选择。遇到提示时关闭占用该文件的程序后重试。详见[已知限制](#已知限制)。
323
324
  2. **凭据路径已部分经真机验证**。候选列表按平台约定推导并有单元测试钉住(含 `LOCALAPPDATA` / `APPDATA` 缺省与空白串两种回落)。已在真实 Windows 11 上确认:`%LOCALAPPDATA%\CodeBuddyExtension\Data\Public\auth` 与 `%LOCALAPPDATA%\Programs\WorkBuddy\WorkBuddy.exe` **命中**,加密凭据的 `keyId` 与登记向量逐字一致。**其余候选仍未经真机逐项验证**——若你的凭据或 App 不在默认位置,用 `WORKBUDDY_AUTH_FILE` / `WORKBUDDY_APP_EXECUTABLE` 指定,并欢迎回报现场。
324
325
  3. **加密凭据(5.6.0 起)需要桌面 App 在场**,Windows 与 macOS 同样如此;App 装在自定义目录(如 `E:\WorkBuddy\WorkBuddy.exe`)时用 `WORKBUDDY_APP_EXECUTABLE` 指定。
326
+ 4. **凭据库里存的是明文 token**(issue #183)。插件的 vault 目录 `<DSH home>/workbuddy-vault/<region>/<accountId>.json` 保存解密后的 `accessToken` / `refreshToken`,**未加密**。Windows 上从 5.16.0 起会在写入前后用 `icacls` 把该目录限制为所有者 / SYSTEM / Administrators 可读,并用 `doctor` 的 `Credential vault ACL` 一行回读确认;但**权限收紧不等于加密**——管理员、SYSTEM 服务,或已取得你用户令牌的攻击者仍可读取。若你需要磁盘加密,请把 DSH home 放在 BitLocker / FileVault 卷上。POSIX 平台依靠 `mode 0600`。
325
327
 
326
328
  ### 在服务器上使用:搬运已登录的凭据
327
329
 
@@ -476,6 +478,20 @@ dsh plugin --profile <web|desktop|dsh-tui> exec dsh-connect-workbuddy logout #
476
478
 
477
479
  `status` 与 `doctor` 支持 `--json` 输出机器可读格式。
478
480
 
481
+ ### 设备身份相关的环境变量
482
+
483
+ 出站身份档位(`wireProfile`)与设备头档位(`deviceTier`)都是**卡片配置项**,不是环境变量。下面这些是给"配置项够不着的场景"留的旁路:
484
+
485
+ | 变量 | 默认 | 说明 |
486
+ |---|---|---|
487
+ | `WORKBUDDY_DEVICE_TOKEN_FILE` | 未设 | 「虚拟值」档外部 `X-Device-Token` 的文件源:指向别的工具维护的 token 文件(裸值或 `{"token":…}` 信封都吃),5 分钟重读、4 KB 上限;token 字节不进日志与 `doctor`。与卡片配置 `deviceToken.file` 同义,配置为空时读它 |
488
+ | `WORKBUDDY_HEADER_TRACE` | 未设 | 设 `1` 后 `doctor` 多打一节:每条请求路径**将要发出的头名清单**(只有名字,永远没有值)——排查"这一档到底发了什么"用 |
489
+ | `WORKBUDDY_TURING_SDK_DIR` | 未设 | 「真实值」档的 Turing Shield SDK 目录。不设置时插件按桌面端安装形状**自动发现**(`/Applications`、`%LOCALAPPDATA%`、卸载注册表等);装了桌面端却仍报「未找到」时,用它显式指路。**卡片「SDK」分区也能直接填**(不用改环境变量、保存即生效),本变量优先级更高。取不到真实设备时的行为见下一行 |
490
+ | `WORKBUDDY_TURING_CHANNEL_ID` | `109144` | SDK 的渠道号,与桌面端 `product.json` 一致 |
491
+ | `WORKBUDDY_TURING_PRODUCT_NAME` | `WorkBuddy` | SDK 初始化自称的产品名 |
492
+ | `WORKBUDDY_TURING_PRODUCT_VERSION` | 插件版本 | SDK 初始化自称的产品版本 |
493
+ | `WORKBUDDY_TURING_KEYCHAIN_STORAGE` | 未设(=关) | 设 `1` 允许 SDK 启用其自身的设备缓存存储;默认关闭——插件不把自己的设备状态写进用户机器的钥匙串 |
494
+
479
495
  > **为什么这三条命令能在「什么都没装」的机器上跑(issue #47)**
480
496
  >
481
497
  > 该插件把 `@deepseek-ai/dsh-atomic-write`、`@deepseek-ai/dsh-home-paths` 等一整套 DSH 包声明为 **peer**:由宿主提供,插件不自己带一份。这在**已启动的 DSH 进程内**工作正常(宿主有运行期拦截层负责按宿主安装位置解析这些名字),但 `dsh plugin … exec` 不是那种环境——它就是在 profile 目录里跑一次 `pnpm exec`,子进程用**普通 Node 解析规则**,而 profile 是按 `autoInstallPeers: false` 建的,peer 根本不会装进去。于是这两个包解析不到。
@@ -508,6 +524,37 @@ pnpm run check # typecheck + test + build
508
524
  dsh plugin --profile desktop add /Users/dmh2002/DshProject/dsh-connect-workbuddy
509
525
  ```
510
526
 
527
+ #### `link:` 安装必须先构建,否则 DSH 会拒绝加载
528
+
529
+ `lib/` 是构建产物且被 gitignore,而 `link:` 安装**不执行包的生命周期脚本**(`prepare` 不会跑)。
530
+ 于是从一份没构建过的源码检出安装时,`package.json` 里声明的 `main` / `exports` 指向的文件并不存在,
531
+ DSH 的插件市场据此判定:
532
+
533
+ ```
534
+ 声明的入口产物缺失(源码检出或构建被拦),下次启动会失败
535
+ ```
536
+
537
+ 这个判定来自 `dshmarket` 的 `entryArtifactExists()`——它只读安装目录里的 `main` 与 `exports`,
538
+ 文件在不在就是全部依据。所以:
539
+
540
+ ```sh
541
+ pnpm install # prepare 会构建一次(lib/ 出现)
542
+ # 或只构建
543
+ pnpm run build
544
+ ```
545
+
546
+ 改完源码也要再 `pnpm run build` 一次(或重跑 `pnpm install`),然后重启 DSH Desktop。
547
+ `pnpm install` 之后仍报同样的话,先跑这一条自查——它打印每个被声明的产物在不在,
548
+ 并区分「从没构建过」和「manifest 与构建不一致」两种原因:
549
+
550
+ ```sh
551
+ pnpm run verify:entries # 当前仓库
552
+ node scripts/verify-entry-artifacts.mjs <已安装的目录> # 具体某个安装副本
553
+ ```
554
+
555
+ > 从 npm 安装(`dsh plugin add dsh-connect-workbuddy`)不需要这一步:发布包里 `lib/` 已经在,
556
+ > `prepack` 也只负责把它重新生成一遍。
557
+
511
558
  ### 写脚本调用 `chatStream()` 时注意:它返回的是**信封**,不是可迭代流
512
559
 
513
560
  ```ts
package/docs/WINDOWS.md CHANGED
@@ -14,9 +14,9 @@ Windows 在本项目里不是「顺带能跑」的平台,而是**有专属分
14
14
  >
15
15
  > 因此**「在 Mac 上试过了,没问题」不足以判定 Windows 行为**。这类结论必须来自:CI 的 windows-latest、Windows 用户回报的现场、或真机取证的向量。
16
16
 
17
- ## 1. 五个 Windows 专属分支
17
+ ## 1. 七个 Windows 专属分支
18
18
 
19
- 改动这五处中的任何一处,都要考虑 Windows。
19
+ 改动这七处中的任何一处,都要考虑 Windows。
20
20
 
21
21
  | # | 位置 | Windows 行为 | 若改错会怎样 |
22
22
  | --- | --- | --- | --- |
@@ -26,6 +26,20 @@ Windows 在本项目里不是「顺带能跑」的平台,而是**有专属分
26
26
  | 4 | 设置写入回读校验(`src/client/account-selection.ts`) | 写入后**回读校验**:profile 的 `cordis.patch.yml` 被占用会让 rename 覆盖失败,而 `set()` 的 promise 仍 resolve | 用户看到假确认(显示「已清除」但没落盘)→ issue #11 |
27
27
  | 5 | 子进程启动选项:`src/host-heartbeat.ts` `PROCESS_PROBE_OPTIONS` 与 `src/at-rest.ts` `fetchAtRestKeyPayload()` | 一律带 `windowsHide: true`(POSIX 忽略该选项) | **宿主本身没有控制台**(Electron GUI 进程,实测 `MainWindowHandle = 0`),Windows 会给子进程**新建一个可见的控制台窗口** → 每次进程存活判定都在屏幕上闪一次黑框 |
28
28
  | 6 | `src/at-rest.ts` `readAtRestKey()` → `findWorkbuddyAppExecutableWithSource()` | 字段密钥**不带参数**调用时才走注册表回退(`reg query` × 3 个卸载 hive);这个探测曾被**只按成功结果**缓存 | 桌面端不在候选目录、凭据又是加密的机器上,`scanAll()` 会**逐文件**重跑整套探测。issue #77 实测:19.1 s 的请求里 15.3 s 花在 `spawnSync`,约 **135 个 `reg query` 子进程**(`findWorkbuddyAppExecutable()` 被调用 45 次)→ 打开页面白等 60 s。POSIX 上这一支根本不跑,**在 macOS 开发机上永远看不到** |
29
+ | 7 | `src/windows-acl.ts` `protectCredentialDirectory()`(issue #183) | 凭据库的访问权限**不能靠 `mode: 0o600`**:Windows 上 `fs.writeFile` / `fs.rename` 的 `mode` 被接受但不生效,权限完全由继承的 DACL 决定。改为在**写入之前**对 vault 根目录发一次 `icacls`(`/inheritance:r` + `*S-1-3-4`、`*S-1-5-18`、`*S-1-5-32-544`,含 `(OI)(CI)`),靠 Windows 的继承传播覆盖整棵子树 | vault 里是**明文** `accessToken` / `refreshToken`。未加固时实测该文件被 `<机器>\CodexSandboxUsers`(DSH 自己沙箱账户)以 `Modify` 读取,且本机 `~/.dsh` 还额外带着 `Everyone: FullControl` → 本机任何低权限进程都能取到可用 JWT |
30
+
31
+ **第 7 条为什么单列**:它是本项目里**第一个「静默失效的防御」**——`mode: 0o600` 看起来像已做了权限限制,代码注释、目录名(`vault`)和既有文档都暗示这一点,而 Windows 上它**什么都不做**。这类缺陷的危险不在于写错,而在于**看起来已经写对了**:没有报错、没有日志、`doctor` 也一切正常。真机取证(2026-10-27,Windows 11)用 `Get-Acl` 读到的事实与代码意图相反,这才把它暴露出来。
32
+
33
+ **加固的四条实测结论**(A 档,真机 `icacls` / `Get-Acl`):
34
+
35
+ 1. **`/T` 必须禁用**。`icacls <dir> /T /inheritance:r /grant:r "*S-1-3-4:(OI)(CI)(F)"` 会让它走过的**每个文件得到空 DACL**(实测 `ACEcount=0`)——比原来更糟,因为谁都读不了,包括插件自己。正确形态是目录用 `(OI)(CI)`、文件用裸 `(F)`;本实现的写入路径只加固目录,靠传播覆盖文件。
36
+ 2. **一次 `icacls` 覆盖整棵树,不需要遍历**。实测:对一个同时含 `cn/`、`global/` 子目录与文件、且全部带 `Everyone`/`CodexSandboxUsers` 的根目录只跑一次 `icacls`,事后根、两个子目录、子目录里的文件全部变成恰好三条 ACE(`weak=0`)。因此实现里没有按目录遍历,也没有按文件逐个加固。
37
+ 3. **加固必须在写入之前**。`writeFileAtomic` 是「写临时 inode → rename 覆盖」,替换出来的是**新 inode**;写在之后加固既留下 pre-rename 窗口,也会被下一次替换抹掉。
38
+ 4. **要加固 vault 根目录,不只是 region 目录**。`Everyone: FullControl` 是从 `~/.dsh` 继承到 `…/workbuddy-vault` 上的;只加固 `<vault>/<region>` 时根目录仍可写,任何进程都能替换掉 region 目录本身。`writeVaultEntry()` 传的是 `dirname(dir)`。
39
+
40
+ **成本是这里的一等约束**(A 档实测):`icacls` 是子进程,静止态 19–52 ms,**并行负载下最高 1242 ms**。因此实现遵守两条:一个目录**一次**调用;同一路径**正在进行的**加固被 join 而不重复发起。这不是提前优化——最初「每次写入后再加固一次文件」的版本把 `tests/issue12-region-hiding.spec.ts` 的 1 s 轮询预算顶穿,才定位到成本形态并改成现在这样。**改动这里的调用次数或等待策略时,请以该用例为成本哨兵。**
41
+
42
+ **没有做的事**(诚实登记):issue #183 的建议 1(DPAPI / `safeStorage` 加密落盘)**未实现**。当前落盘的仍是明文,只是权限收紧了;管理员、SYSTEM 服务,或已经拿到该用户令牌的攻击者仍可读取。要做到那一步需要改变 vault 的**磁盘格式**并做迁移,属独立改动。README 明写「此文件含明文 token」。
29
43
 
30
44
  **第 6 条为什么单列**:这是**第 5 条之外的第二个**「只在 Windows 才付费」形态——不是正确性错误,而是**成本随文件数 × 读取次数放大**的性能缺陷,且两个乘数都在 Windows 特有的分支里。`tests/issue77-at-rest-key-cache.spec.ts` 用 `process.platform` 影子 + `execFileSync` 打桩,在**任何宿主**上都能数出这三件事(失败结果被记住、一次探测 3 次 `reg`、5 个加密文件的一轮读取仍是 3 次)。
31
45