dsh-config-manager 0.8.2 → 0.9.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.
Files changed (345) hide show
  1. package/lib/adapters/mcp.js +42 -13
  2. package/lib/adapters/messages.d.ts +1 -0
  3. package/lib/adapters/messages.js +2 -0
  4. package/lib/adapters/patch-key-guard.d.ts +23 -0
  5. package/lib/adapters/patch-key-guard.js +13 -0
  6. package/lib/adapters/plugin-data.d.ts +19 -5
  7. package/lib/adapters/plugin-data.js +76 -22
  8. package/lib/adapters/plugins.d.ts +14 -1
  9. package/lib/adapters/plugins.js +147 -4
  10. package/lib/cli/actions.d.ts +7 -105
  11. package/lib/cli/actions.js +16 -172
  12. package/lib/cli/control-state.d.ts +54 -0
  13. package/lib/cli/control-state.js +107 -0
  14. package/lib/cli/index.js +14 -0
  15. package/lib/cli/write-gates.d.ts +61 -0
  16. package/lib/cli/write-gates.js +110 -0
  17. package/lib/client.d.ts +104 -49
  18. package/lib/client.js +12536 -12006
  19. package/lib/core/backup.d.ts +0 -4
  20. package/lib/core/backup.js +21 -4
  21. package/lib/core/boot-rescue.d.ts +1 -1
  22. package/lib/core/boot-rescue.js +12 -1
  23. package/lib/core/boot-safety.js +37 -2
  24. package/lib/core/conflict-decisions.js +2 -1
  25. package/lib/core/exporter.js +22 -1
  26. package/lib/core/journal.d.ts +54 -4
  27. package/lib/core/journal.js +158 -35
  28. package/lib/core/local-plugin-host.d.ts +29 -0
  29. package/lib/core/local-plugin-host.js +55 -48
  30. package/lib/core/messages.d.ts +7 -0
  31. package/lib/core/messages.js +14 -0
  32. package/lib/core/migration-history.js +16 -9
  33. package/lib/core/model-tools.d.ts +2 -2
  34. package/lib/core/model-tools.js +14 -2
  35. package/lib/core/patch-secret-guard.d.ts +49 -0
  36. package/lib/core/patch-secret-guard.js +164 -0
  37. package/lib/core/reconcile.d.ts +8 -0
  38. package/lib/core/reconcile.js +18 -3
  39. package/lib/core/reinstall.d.ts +2 -0
  40. package/lib/core/reinstall.js +6 -2
  41. package/lib/core/restore.js +31 -6
  42. package/lib/core/section-sanitize.d.ts +32 -0
  43. package/lib/core/section-sanitize.js +13 -0
  44. package/lib/core/snapshot-diff.d.ts +30 -0
  45. package/lib/core/snapshot-diff.js +56 -20
  46. package/lib/core/startup-barrier.js +8 -2
  47. package/lib/core/types.d.ts +22 -0
  48. package/lib/core/update-check.js +51 -2
  49. package/lib/foreign/kernel.js +9 -2
  50. package/lib/foreign/read-claude-plugins.js +29 -11
  51. package/lib/foreign/read-dsh.js +31 -2
  52. package/lib/foreign/session-ir.js +50 -9
  53. package/lib/foreign/session-read.d.ts +8 -0
  54. package/lib/foreign/session-read.js +26 -0
  55. package/lib/index.d.ts +1 -1
  56. package/lib/index.js +1 -1
  57. package/lib/profiles/dsh-profile-io.d.ts +20 -0
  58. package/lib/profiles/dsh-profile-io.js +27 -0
  59. package/lib/profiles/dsh-profile-manager.d.ts +27 -0
  60. package/lib/profiles/dsh-profile-manager.js +45 -4
  61. package/lib/profiles/dsh-profile-runtime.d.ts +5 -1
  62. package/lib/profiles/dsh-profile-runtime.js +16 -3
  63. package/lib/profiles/process-control.d.ts +18 -1
  64. package/lib/profiles/process-control.js +25 -1
  65. package/lib/routes/profiles.js +2 -1
  66. package/lib/routes/sync.js +13 -1
  67. package/lib/schema/types.d.ts +11 -0
  68. package/lib/security/redaction.js +22 -6
  69. package/lib/sync/autosync-repeat.d.ts +27 -0
  70. package/lib/sync/autosync-repeat.js +23 -0
  71. package/lib/sync/autosync-scheduler.d.ts +34 -1
  72. package/lib/sync/autosync-scheduler.js +151 -43
  73. package/lib/sync/baseline-heal.js +7 -0
  74. package/lib/sync/baseline-record.d.ts +67 -0
  75. package/lib/sync/baseline-record.js +74 -0
  76. package/lib/sync/blob-store.js +13 -0
  77. package/lib/sync/content-diff.d.ts +39 -0
  78. package/lib/sync/content-diff.js +46 -0
  79. package/lib/sync/git/git-transport.d.ts +32 -1
  80. package/lib/sync/git/git-transport.js +146 -26
  81. package/lib/sync/github-auth.d.ts +17 -1
  82. package/lib/sync/github-auth.js +37 -1
  83. package/lib/sync/merge-apply-plan.d.ts +38 -0
  84. package/lib/sync/merge-apply-plan.js +76 -0
  85. package/lib/sync/messages.d.ts +1 -0
  86. package/lib/sync/messages.js +2 -0
  87. package/lib/sync/pending-merge.d.ts +34 -0
  88. package/lib/sync/pending-merge.js +53 -0
  89. package/lib/sync/s3/s3-transport.d.ts +14 -2
  90. package/lib/sync/s3/s3-transport.js +72 -48
  91. package/lib/sync/sync-engine.d.ts +23 -40
  92. package/lib/sync/sync-engine.js +115 -132
  93. package/lib/sync/sync-history.d.ts +7 -0
  94. package/lib/sync/sync-state.d.ts +28 -0
  95. package/lib/sync/sync-state.js +20 -0
  96. package/lib/sync/transport.d.ts +12 -3
  97. package/lib/sync/transport.js +13 -4
  98. package/lib/sync/webdav/webdav-transport.d.ts +19 -2
  99. package/lib/sync/webdav/webdav-transport.js +81 -40
  100. package/lib/ui/commands.js +5 -11
  101. package/lib/ui/dsh-profiles-view.d.ts +8 -3
  102. package/lib/ui/dsh-profiles-view.js +9 -5
  103. package/lib/ui/i18n.d.ts +2 -1
  104. package/lib/ui/i18n.js +4 -2
  105. package/lib/ui/menu-placement.js +1 -1
  106. package/lib/ui/migration-consult-view.d.ts +11 -0
  107. package/lib/ui/migration-consult-view.js +15 -0
  108. package/lib/ui/overview-view.d.ts +7 -0
  109. package/lib/ui/overview-view.js +3 -0
  110. package/lib/ui/report.d.ts +9 -0
  111. package/lib/ui/report.js +17 -4
  112. package/lib/ui/selection-model.d.ts +8 -0
  113. package/lib/ui/selection-model.js +16 -0
  114. package/lib/utils/patch-yaml.d.ts +39 -1
  115. package/lib/utils/patch-yaml.js +82 -2
  116. package/lib/utils/paths.d.ts +13 -0
  117. package/lib/utils/paths.js +35 -0
  118. package/lib/utils/workdir-lock.js +18 -3
  119. package/package.json +2 -1
  120. package/src/adapters/mcp.test.ts +29 -0
  121. package/src/adapters/mcp.ts +43 -12
  122. package/src/adapters/messages.ts +2 -0
  123. package/src/adapters/patch-key-guard.ts +29 -0
  124. package/src/adapters/plugin-data.test.ts +126 -0
  125. package/src/adapters/plugin-data.ts +97 -26
  126. package/src/adapters/plugins.test.ts +288 -0
  127. package/src/adapters/plugins.ts +141 -4
  128. package/src/cli/actions.test.ts +74 -1
  129. package/src/cli/actions.ts +27 -246
  130. package/src/cli/control-state.ts +143 -0
  131. package/src/cli/index.ts +18 -0
  132. package/src/cli/web/web.test.ts +27 -0
  133. package/src/cli/write-gates.ts +149 -0
  134. package/src/client/about/AboutPanel.tsx +7 -6
  135. package/src/client/about/release-notes-view.test.ts +17 -0
  136. package/src/client/about/release-notes-view.ts +49 -24
  137. package/src/client/chat/ChatEntryView.tsx +2 -2
  138. package/src/client/chat/rollback-entry-view.ts +6 -1
  139. package/src/client/common/CommandPalette.tsx +6 -3
  140. package/src/client/common/ConfirmDialog.tsx +29 -12
  141. package/src/client/common/ContentPicker.tsx +13 -12
  142. package/src/client/common/Modal.tsx +12 -5
  143. package/src/client/common/MoreMenu.tsx +4 -1
  144. package/src/client/common/RunsCenter.tsx +103 -32
  145. package/src/client/common/Select.tsx +2 -2
  146. package/src/client/common/floating-bounds.ts +1 -1
  147. package/src/client/common/floating-units.test.ts +1 -2
  148. package/src/client/common/plan-text-redaction.test.ts +188 -3
  149. package/src/client/common/runs-center-guard.test.ts +60 -0
  150. package/src/client/common/runs-center-view.test.ts +128 -0
  151. package/src/client/common/runs-center-view.ts +96 -0
  152. package/src/client/common/section-title-action.test.ts +66 -0
  153. package/src/client/common/ui.tsx +93 -30
  154. package/src/client/config-manager.module.css +1507 -272
  155. package/src/client/consult/ConsultCard.tsx +7 -6
  156. package/src/client/environment/EnvironmentPanel.tsx +20 -21
  157. package/src/client/environment/maintenance/DiskUsageCard.tsx +65 -91
  158. package/src/client/environment/profiles-incomplete-ui.test.ts +8 -8
  159. package/src/client/export/ExportView.tsx +7 -16
  160. package/src/client/history/HistoryPanel.tsx +88 -28
  161. package/src/client/history/history-locales.ts +3 -3
  162. package/src/client/home/BackupScheduleCard.tsx +35 -30
  163. package/src/client/home/HomePanel.tsx +45 -10
  164. package/src/client/import/ConflictList.tsx +13 -13
  165. package/src/client/import/ForeignImportView.tsx +7 -6
  166. package/src/client/import/ImportWizardView.tsx +2 -3
  167. package/src/client/import/PathMappingForm.tsx +4 -4
  168. package/src/client/import/PathPickerDialog.tsx +2 -1
  169. package/src/client/import/import-wizard-steps.tsx +51 -39
  170. package/src/client/import/use-import-wizard-controller.test.ts +129 -0
  171. package/src/client/import/use-import-wizard-controller.ts +116 -22
  172. package/src/client/library/ArtifactRow.tsx +2 -2
  173. package/src/client/library/BackupInspectView.tsx +19 -15
  174. package/src/client/library/LibraryActions.tsx +56 -16
  175. package/src/client/library/LibraryPanel.tsx +7 -7
  176. package/src/client/library/RestorePlanView.tsx +13 -8
  177. package/src/client/locales/about.ts +0 -2
  178. package/src/client/locales/backup.ts +10 -12
  179. package/src/client/locales/common.ts +2 -0
  180. package/src/client/locales/export.ts +5 -12
  181. package/src/client/locales/foreign.ts +2 -2
  182. package/src/client/locales/import.ts +3 -2
  183. package/src/client/locales/overview.ts +4 -0
  184. package/src/client/locales/profiles.ts +32 -4
  185. package/src/client/locales/restore.ts +0 -2
  186. package/src/client/locales/sessions.ts +0 -2
  187. package/src/client/locales/shell.ts +2 -2
  188. package/src/client/market/MarketPanel.tsx +38 -20
  189. package/src/client/market/MyConfigsList.tsx +34 -32
  190. package/src/client/market/MyConfigsLoginCard.tsx +12 -15
  191. package/src/client/market/MyConfigsView.tsx +5 -5
  192. package/src/client/market/MyConfigsWizard.tsx +7 -12
  193. package/src/client/market/market-locales.ts +0 -6
  194. package/src/client/market/my-configs-split.test.ts +2 -1
  195. package/src/client/nav-menu-clip-guard.test.ts +52 -0
  196. package/src/client/recovery/IncompleteCopiesSection.tsx +1 -3
  197. package/src/client/recovery/RecoveryPanel.tsx +31 -16
  198. package/src/client/recovery/RollbackCard.tsx +58 -16
  199. package/src/client/recovery/RollbackFileChanges.tsx +40 -27
  200. package/src/client/recovery/SessionHealthCard.tsx +2 -2
  201. package/src/client/recovery/SessionHealthDialog.tsx +5 -7
  202. package/src/client/recovery/SessionLayoutSection.tsx +3 -5
  203. package/src/client/recovery/recovery-locales.ts +12 -8
  204. package/src/client/run-store.test.ts +30 -0
  205. package/src/client/run-store.ts +21 -1
  206. package/src/client/sync/AddChannelCard.tsx +65 -0
  207. package/src/client/sync/AutosyncCard.tsx +182 -108
  208. package/src/client/sync/ChannelClearConfirmDialog.tsx +5 -1
  209. package/src/client/sync/ChannelConfigDialog.tsx +27 -48
  210. package/src/client/sync/MergePreviewView.tsx +3 -5
  211. package/src/client/sync/PushReportSections.tsx +35 -0
  212. package/src/client/sync/SyncChannelEntryCard.tsx +33 -24
  213. package/src/client/sync/SyncConfirmView.tsx +3 -3
  214. package/src/client/sync/SyncLogList.tsx +16 -5
  215. package/src/client/sync/SyncPanel.tsx +153 -159
  216. package/src/client/sync/SyncProbeRow.tsx +5 -7
  217. package/src/client/sync/SyncRepositoryPicker.tsx +17 -4
  218. package/src/client/sync/SyncSecuritySection.tsx +157 -0
  219. package/src/client/sync/SyncSettingsDialog.tsx +304 -0
  220. package/src/client/sync/SyncSettingsView.test.ts +26 -8
  221. package/src/client/sync/WorkDirCard.tsx +2 -4
  222. package/src/client/sync/config-clear-guard.test.ts +94 -0
  223. package/src/client/sync/config-clear-guard.ts +98 -0
  224. package/src/client/sync/config-dirty.test.ts +91 -0
  225. package/src/client/sync/config-dirty.ts +88 -0
  226. package/src/client/sync/history-model.test.ts +2 -0
  227. package/src/client/sync/history-model.ts +3 -0
  228. package/src/client/sync/merge-request.ts +20 -0
  229. package/src/client/sync/sync-api.ts +12 -0
  230. package/src/client/sync/sync-locales.ts +87 -47
  231. package/src/client/sync/sync-panel-clear.test.ts +44 -0
  232. package/src/client/sync/sync-view.test.ts +20 -0
  233. package/src/client/sync/sync-view.ts +42 -4
  234. package/src/core/backup.test.ts +61 -1
  235. package/src/core/backup.ts +21 -4
  236. package/src/core/boot-rescue.test.ts +35 -0
  237. package/src/core/boot-rescue.ts +13 -2
  238. package/src/core/boot-safety.test.ts +25 -0
  239. package/src/core/boot-safety.ts +37 -2
  240. package/src/core/conflict-decisions.ts +2 -1
  241. package/src/core/exporter.ts +21 -1
  242. package/src/core/journal.test.ts +183 -0
  243. package/src/core/journal.ts +163 -25
  244. package/src/core/local-plugin-host.test.ts +68 -2
  245. package/src/core/local-plugin-host.ts +31 -4
  246. package/src/core/messages.ts +14 -0
  247. package/src/core/migration-history.test.ts +27 -0
  248. package/src/core/migration-history.ts +12 -4
  249. package/src/core/model-tools.test.ts +67 -0
  250. package/src/core/model-tools.ts +16 -4
  251. package/src/core/patch-secret-guard.test.ts +110 -0
  252. package/src/core/patch-secret-guard.ts +176 -0
  253. package/src/core/reconcile.ts +32 -4
  254. package/src/core/reinstall.ts +8 -2
  255. package/src/core/restore.ts +32 -7
  256. package/src/core/section-sanitize.ts +37 -0
  257. package/src/core/snapshot-diff.test.ts +73 -1
  258. package/src/core/snapshot-diff.ts +66 -21
  259. package/src/core/startup-barrier.test.ts +64 -0
  260. package/src/core/startup-barrier.ts +8 -2
  261. package/src/core/types.ts +27 -1
  262. package/src/core/update-check.test.ts +40 -0
  263. package/src/core/update-check.ts +53 -2
  264. package/src/foreign/claude-code.test.ts +5 -0
  265. package/src/foreign/claude-plugins.test.ts +57 -0
  266. package/src/foreign/claude-sessions-bytes.test.ts +7 -1
  267. package/src/foreign/dsh.test.ts +23 -0
  268. package/src/foreign/kernel.ts +9 -2
  269. package/src/foreign/read-claude-plugins.ts +32 -11
  270. package/src/foreign/read-dsh.ts +33 -2
  271. package/src/foreign/session-ir.test.ts +67 -0
  272. package/src/foreign/session-ir.ts +54 -14
  273. package/src/foreign/session-read.ts +23 -0
  274. package/src/index.ts +1 -1
  275. package/src/profiles/dsh-profile-copy-rollback.test.ts +58 -4
  276. package/src/profiles/dsh-profile-io.ts +29 -0
  277. package/src/profiles/dsh-profile-manager.test.ts +30 -0
  278. package/src/profiles/dsh-profile-manager.ts +53 -5
  279. package/src/profiles/dsh-profile-runtime.test.ts +29 -7
  280. package/src/profiles/dsh-profile-runtime.ts +17 -3
  281. package/src/profiles/process-control.test.ts +97 -0
  282. package/src/profiles/process-control.ts +28 -1
  283. package/src/routes/profiles.ts +2 -1
  284. package/src/routes/sync.ts +13 -1
  285. package/src/schema/types.ts +16 -1
  286. package/src/security/redaction.test.ts +31 -0
  287. package/src/security/redaction.ts +23 -6
  288. package/src/sync/autosync-repeat.test.ts +58 -0
  289. package/src/sync/autosync-repeat.ts +55 -0
  290. package/src/sync/autosync-scheduler.test.ts +417 -0
  291. package/src/sync/autosync-scheduler.ts +154 -41
  292. package/src/sync/baseline-heal.ts +6 -0
  293. package/src/sync/baseline-record.ts +135 -0
  294. package/src/sync/blob-store.test.ts +16 -0
  295. package/src/sync/blob-store.ts +13 -0
  296. package/src/sync/content-diff.test.ts +95 -0
  297. package/src/sync/content-diff.ts +79 -0
  298. package/src/sync/git/git-transport.test.ts +151 -4
  299. package/src/sync/git/git-transport.ts +143 -27
  300. package/src/sync/github-auth.test.ts +26 -1
  301. package/src/sync/github-auth.ts +37 -1
  302. package/src/sync/merge-apply-plan.ts +117 -0
  303. package/src/sync/messages.ts +2 -0
  304. package/src/sync/pending-merge.ts +77 -0
  305. package/src/sync/s3/s3-delete-and-blob-index.test.ts +249 -0
  306. package/src/sync/s3/s3-transport.ts +76 -42
  307. package/src/sync/sync-config.test.ts +39 -12
  308. package/src/sync/sync-device-identity.test.ts +3 -0
  309. package/src/sync/sync-engine.test.ts +465 -12
  310. package/src/sync/sync-engine.ts +130 -135
  311. package/src/sync/sync-history.ts +7 -0
  312. package/src/sync/sync-state.ts +48 -0
  313. package/src/sync/transport.test.ts +13 -1
  314. package/src/sync/transport.ts +12 -4
  315. package/src/sync/webdav/webdav-delete-and-blob-index.test.ts +249 -0
  316. package/src/sync/webdav/webdav-transport.ts +86 -34
  317. package/src/ui/commands.test.ts +11 -0
  318. package/src/ui/commands.ts +5 -14
  319. package/src/ui/dsh-profiles-view.test.ts +16 -0
  320. package/src/ui/dsh-profiles-view.ts +11 -5
  321. package/src/ui/i18n.ts +4 -2
  322. package/src/ui/menu-placement.ts +1 -1
  323. package/src/ui/migration-consult-view.test.ts +20 -1
  324. package/src/ui/migration-consult-view.ts +17 -0
  325. package/src/ui/overview-view.ts +10 -0
  326. package/src/ui/report.test.ts +25 -1
  327. package/src/ui/report.ts +15 -4
  328. package/src/ui/selection-model.test.ts +15 -1
  329. package/src/ui/selection-model.ts +18 -0
  330. package/src/utils/js-yaml4.d.ts +35 -0
  331. package/src/utils/patch-yaml.test.ts +207 -1
  332. package/src/utils/patch-yaml.ts +98 -2
  333. package/src/utils/paths.test.ts +14 -1
  334. package/src/utils/paths.ts +35 -0
  335. package/src/utils/workdir-lock.test.ts +69 -0
  336. package/src/utils/workdir-lock.ts +17 -3
  337. package/lib/ui/path-mapping.d.ts +0 -38
  338. package/lib/ui/path-mapping.js +0 -75
  339. package/src/client/common/InfoHint.tsx +0 -289
  340. package/src/client/common/info-hint-guard.test.ts +0 -1119
  341. package/src/client/sync/DecryptPasswordCard.tsx +0 -48
  342. package/src/client/sync/SecurityOptionsCard.tsx +0 -97
  343. package/src/client/sync/SyncSectionPickerDialog.tsx +0 -213
  344. package/src/ui/path-mapping.test.ts +0 -67
  345. package/src/ui/path-mapping.ts +0 -103
@@ -24,7 +24,10 @@ export interface ConsultDimensionView {
24
24
  label: string;
25
25
  score: number;
26
26
  verdict: HealthVerdict;
27
+ /** 维度名徽章的 kind(按 verdict,历史上用于整枚徽章着色) */
27
28
  badgeKind: ConsultBadgeKind;
29
+ /** 分数徽章的 kind(按分数档位派生 —— 稿上分数用绿/橙分色,与文字 verdict 无关) */
30
+ scoreKind: ConsultBadgeKind;
28
31
  issues: { severity: 'info' | 'warning' | 'error'; message: string }[];
29
32
  }
30
33
 
@@ -140,6 +143,19 @@ export function consultDimensionLabel(id: ConsultDimensionId, t: UiT): string {
140
143
  }
141
144
  }
142
145
 
146
+ /**
147
+ * 维度分数 → 徽章 kind(稿 D-03:161-200 的分色口径,纯函数):
148
+ * ≥90 ok(绿)/ ≥70 warn(橙)/ 其余 error(红)。
149
+ *
150
+ * 为什么分数不再借用 verdict 的 kind:同一维度可能 verdict=warning 而分数 92(绿),
151
+ * 稿上颜色跟的是**分数**,把 verdict 色套到分数上会出现「92 分却标橙」的自相矛盾。
152
+ */
153
+ export function consultScoreBadgeKind(score: number): ConsultBadgeKind {
154
+ if (score >= 90) return 'ok'
155
+ if (score >= 70) return 'warn'
156
+ return 'error'
157
+ }
158
+
143
159
  /** 把 ConsultReport 转成视图数据(纯函数) */
144
160
  export function consultView(report: ConsultReport, t: UiT): ConsultView {
145
161
  const dimensions: ConsultDimensionView[] = report.dimensions.map((d) => ({
@@ -148,6 +164,7 @@ export function consultView(report: ConsultReport, t: UiT): ConsultView {
148
164
  score: d.score,
149
165
  verdict: d.verdict,
150
166
  badgeKind: consultVerdictBadgeKind(d.verdict),
167
+ scoreKind: consultScoreBadgeKind(d.score),
151
168
  issues: d.issues.map((i) => ({ severity: i.severity, message: i.message })),
152
169
  }));
153
170
 
@@ -296,6 +296,13 @@ export interface OverviewActivityItem {
296
296
  kindKey: string
297
297
  /** 原始摘要(上层渲染前 redact())。 */
298
298
  summary: string
299
+ /**
300
+ * P2(2026-11-14 真机事故):这一行点得动 —— 给它一个去处。
301
+ * 目前只有「待裁决」的自动同步轮次:冲突分区已经落进 sync-state.pendingMerge,
302
+ * 真正的裁决动作在同步页(那里有合并裁决视图),首页只负责把用户送过去。
303
+ * 无此字段 = 纯信息行(保持原样,不伪造交互)。
304
+ */
305
+ jumpTo?: 'sync'
299
306
  }
300
307
 
301
308
  /** 最近活动列表:按时间倒序取前 limit 条(kindKey 归一 + 徽章语义映射)。 */
@@ -322,6 +329,9 @@ export function overviewActivity(
322
329
  : 'warn',
323
330
  kindKey: overviewKindKey(e.kind),
324
331
  summary: e.summary,
332
+ // 待裁决 = 有具体分区等用户确认(宿主侧 pendingMerge)。首页不能只挂个颜色:
333
+ // 有去处才给入口,其余徽章保持不可点。
334
+ ...(e.kind === 'autosync' && e.result === 'pending' ? { jumpTo: 'sync' as const } : {}),
325
335
  }))
326
336
  }
327
337
 
@@ -134,8 +134,32 @@ test('report: importProblems 抽失败/警告项(带分区与原因,保持
134
134
  assert.equal(problems[2]!.message, undefined, '无原因时不留 undefined 字段');
135
135
  });
136
136
 
137
- test('report: formatBytes', () => {
137
+ test('report: formatBytes(含 GiB 档与非法值守卫)', () => {
138
138
  assert.equal(formatBytes(512), '512 B');
139
139
  assert.equal(formatBytes(20480), '20.0 KB');
140
140
  assert.equal(formatBytes(2 * 1024 * 1024), '2.0 MB');
141
+ // P10-2:≥1 GiB 曾经输出「2048.0 MB」——用户得自己换算,且三位数 MB 最容易读错
142
+ assert.equal(formatBytes(1024 * 1024 * 1024), '1.00 GiB');
143
+ assert.equal(formatBytes(2 * 1024 * 1024 * 1024), '2.00 GiB', '2048 MiB 必须是 2.00 GiB,不是 2048.0 MB');
144
+ assert.equal(formatBytes(1.5 * 1024 * 1024 * 1024), '1.50 GiB');
145
+ // P10-2:非法值不得伪装成体积 —— 此前渲染成「NaN MB」/「Infinity MB」
146
+ assert.equal(formatBytes(Number.NaN), '', 'NaN → 空串(报告行由调用方决定怎么显示缺数据)');
147
+ assert.equal(formatBytes(Number.POSITIVE_INFINITY), '');
148
+ assert.equal(formatBytes(-1), '', '负数体积无意义');
149
+ assert.equal(formatBytes(0), '0 B', '0 是有效值,不能当空');
150
+ });
151
+
152
+ test('report: 导出报告的分区计数走同一份文案组装(P10-3:中文界面不出现裸适配器词汇)', () => {
153
+ const report = makeExportReport({
154
+ included: [
155
+ { section: 'settings', counts: { namespaces: 18, files: 3 } },
156
+ { section: 'plugins', counts: { plugins: 8 } },
157
+ ],
158
+ });
159
+ const zhText = renderExportReport(report, zhT);
160
+ assert.ok(zhText.includes('✓ settings (18 个命名空间,3 个文件)'), zhText);
161
+ assert.ok(!zhText.includes('namespaces'), '中文界面不得出现裸适配器键(exportCountsText 已修的口径必须接到这里)');
162
+ assert.ok(!zhText.includes('18 namespaces, 3 files'), '半英文行是本次要修的缺陷形态');
163
+ const enText = renderExportReport(report, enT);
164
+ assert.ok(enText.includes('✓ settings (18 namespaces, 3 files)'), '英文界面用半角逗号 + 单复数');
141
165
  });
package/src/ui/report.ts CHANGED
@@ -56,9 +56,9 @@ export function renderExportReport(report: ExportReport, t: UiT): string {
56
56
  const lines: string[] = [t('report.backupCreated'), ''];
57
57
  lines.push(t('report.included'));
58
58
  for (const { section, counts } of report.included) {
59
- const detail = Object.entries(counts)
60
- .map(([k, v]) => `${v} ${k}`)
61
- .join(', ');
59
+ // 计数文案与导出确认页同一份组装(`exportCountsText`):此前这里直接拼适配器词汇,
60
+ // 中文界面出现「settings (18 namespaces, 3 files)」这种半英文行(审计 P10-3)。
61
+ const detail = exportCountsText(counts, t);
62
62
  lines.push(` ✓ ${section}${detail !== '' ? ` (${detail})` : ''}`);
63
63
  }
64
64
  lines.push('');
@@ -230,8 +230,19 @@ export function renderRollbackReport(rr: RollbackReport, t: UiT): string {
230
230
 
231
231
  /* ---------------- 工具 ---------------- */
232
232
 
233
+ /**
234
+ * 字节 → 人类可读体积(B / KB / MB / GiB)。
235
+ *
236
+ * 口径与 `session-inventory-view.ts` 的 `formatSessionBytes` 对齐,但后缀沿用报告既有的
237
+ * KB/MB 写法(报告文本曾被测试与文档引用):
238
+ * - 非有限值(NaN/Infinity)或负数 → 空串:此前 `NaN` 会渲染成「NaN MB」,把缺数据
239
+ * 伪装成 0 体积之外的另一条假信息(审计 P10-2);
240
+ * - ≥1 GiB 单独一档:`2048.0 MB` 让用户自己换算,且 3 位数 MB 在报告行里最容易读错。
241
+ */
233
242
  export function formatBytes(n: number): string {
243
+ if (!Number.isFinite(n) || n < 0) return '';
234
244
  if (n < 1024) return `${n} B`;
235
245
  if (n < 1024 * 1024) return `${(n / 1024).toFixed(1)} KB`;
236
- return `${(n / (1024 * 1024)).toFixed(1)} MB`;
246
+ if (n < 1024 * 1024 * 1024) return `${(n / (1024 * 1024)).toFixed(1)} MB`;
247
+ return `${(n / (1024 * 1024 * 1024)).toFixed(2)} GiB`;
237
248
  }
@@ -10,7 +10,7 @@ import test from 'node:test'
10
10
  import assert from 'node:assert/strict'
11
11
 
12
12
  import {
13
- applyPluginPendingChecks, buildExportRequest, buildSelectedPlan, defaultSelection,
13
+ applyPluginPendingChecks, buildExportRequest, buildSelectedPlan, defaultSelection, samePendingChecks,
14
14
  defaultSelectionFromPlan, effectiveImportPlan, effectiveImportSelection, filterSections,
15
15
  filterPluginTree, groupPickState, groupSelectedCount, groupUnits, HIGH_RISK_ADAPTERS, isHighRiskAdapter,
16
16
  isPlanItemExcluded, isPluginTreeSection, isUnitSelected, PLUGIN_TREE_SECTIONS,
@@ -1032,6 +1032,20 @@ test('待补勾:清单没到齐时留在队列(绝不假装已勾),到
1032
1032
  assert.equal(pluginEntryPickState(done.selection, alpha), 'all')
1033
1033
  })
1034
1034
 
1035
+ test('samePendingChecks:队列内容等价即视为同一队列(审计 P9-1 回归,防 effect 自激)', () => {
1036
+ const a = [{ key: 'plugin-root', kind: 'root' as const }]
1037
+ // applyPluginPendingChecks 每轮返回新数组:内容相同必须判等,否则 setState → effect 自激
1038
+ assert.equal(samePendingChecks([...a], a), true, '同内容的两个数组必须判等')
1039
+ assert.equal(samePendingChecks(a, [{ key: 'plugin-root', kind: 'root' as const }]), true)
1040
+ assert.equal(samePendingChecks([], []), true)
1041
+ assert.equal(samePendingChecks(a, []), false, '长度不同不等')
1042
+ assert.equal(samePendingChecks(a, [{ key: 'other', kind: 'root' }]), false, 'key 不同不等')
1043
+ assert.equal(samePendingChecks(a, [{ key: 'plugin-root', kind: 'entry' }]), false, 'kind 不同不等')
1044
+ assert.equal(
1045
+ samePendingChecks([...a, ...a], a), false, '重复项也不等(长度不同)',
1046
+ )
1047
+ })
1048
+
1035
1049
  test('「插件」一级区块展开前要读的分区:插件清单自己没读到也要报(否则展开后没有读取入口)', () => {
1036
1050
  const nodes = treeNodes()
1037
1051
  // alpha 声明了一个大文件区域(该分区清单还没读)
@@ -1312,6 +1312,24 @@ export function applyPluginPendingChecks(
1312
1312
  return { selection: out, remaining }
1313
1313
  }
1314
1314
 
1315
+ /**
1316
+ * 两条待补勾队列是否等价(同序、同 key、同 kind)。
1317
+ *
1318
+ * 为什么必须有它:`applyPluginPendingChecks` 每轮都返回**新数组**(内容可完全不变)。
1319
+ * 调用方若无条件写回 state,effect 依赖 [pendingChecks, …] 就会自激成无界重渲染
1320
+ * (清单读不到时队列永不出队 → 页面卡死,审计 P9-1)。
1321
+ */
1322
+ export function samePendingChecks(
1323
+ a: readonly PluginPendingCheck[],
1324
+ b: readonly PluginPendingCheck[],
1325
+ ): boolean {
1326
+ if (a.length !== b.length) return false
1327
+ for (let i = 0; i < a.length; i += 1) {
1328
+ if (a[i]!.key !== b[i]!.key || a[i]!.kind !== b[i]!.kind) return false
1329
+ }
1330
+ return true
1331
+ }
1332
+
1315
1333
  /** 勾上该插件前还需要读取哪些分区的清单(展开/点击时触发惰性读取)。 */
1316
1334
  export function pluginEntryUnreadSections(entry: PluginTreeEntry): SectionId[] {
1317
1335
  const out: SectionId[] = []
@@ -0,0 +1,35 @@
1
+ /**
2
+ * `js-yaml@4.x` 的最小类型面(issue #135)。
3
+ *
4
+ * 为什么要有这个声明:DSH 本体读 `cordis.patch.yml` 用的是随包的 js-yaml 4.x,
5
+ * 而本插件用 5.x 写。要证明「写出去的字节两边读到同一个值」,只能真的把 4.x 装上读一遍;
6
+ * 4.x 以 devDependency 别名 `js-yaml4`(`npm:js-yaml@^4.3.2`)安装,没有随包类型,
7
+ * `@types/js-yaml` 是 5.x 的形状、不能复用。
8
+ *
9
+ * 范围刻意只到「测试需要的最小面」:schema 扩展与 load。运行时依赖仍然只有 `js-yaml`。
10
+ */
11
+ declare module 'js-yaml4' {
12
+ export interface JsYaml4TypeOptions {
13
+ kind: 'scalar' | 'sequence' | 'mapping'
14
+ /** 显式标签(`!!foo`)的构造:4.x 只在标签被显式写出时调用。 */
15
+ construct?: (data: unknown) => unknown
16
+ /** 隐式解析的判据(字符串 → 是否属于本类型)。 */
17
+ resolve?: (data: string) => boolean
18
+ /** 写回时:内存值是否属于本类型。 */
19
+ predicate?: (data: unknown) => boolean
20
+ /** 写回时:把内存值还原成源码文本。 */
21
+ represent?: (data: unknown) => unknown
22
+ }
23
+
24
+ export class Type {
25
+ constructor(tag: string, options: JsYaml4TypeOptions)
26
+ }
27
+
28
+ export interface JsYaml4Schema {
29
+ extend(types: Type[]): JsYaml4Schema
30
+ }
31
+
32
+ export const JSON_SCHEMA: JsYaml4Schema
33
+
34
+ export function load(input: string, options?: { schema?: JsYaml4Schema }): unknown
35
+ }
@@ -13,8 +13,9 @@ import assert from 'node:assert/strict';
13
13
  import fs from 'node:fs';
14
14
  import { fileURLToPath } from 'node:url';
15
15
  import * as yaml from 'js-yaml';
16
+ import * as yaml4 from 'js-yaml4';
16
17
 
17
- import { describePatchYamlError, dumpPatchDocument, isPatchJsExpr, loadPatchDocument } from './patch-yaml.ts';
18
+ import { describePatchYamlError, dumpPatchDocument, findPatchKeyHazards, isPatchJsExpr, loadPatchDocument } from './patch-yaml.ts';
18
19
 
19
20
  /** 真机形态(issue #75 报告的那一行):顶层行 + 行内 JS 表达式 + 嵌套 config。 */
20
21
  const SAMPLE = [
@@ -89,6 +90,131 @@ test('describePatchYamlError:只取首行,源码片段(可能含内联密
89
90
  assert.ok(realSafe.length > 0);
90
91
  });
91
92
 
93
+ /* ------------------------------ 跨大版本读回(issue #135) ------------------------------ */
94
+
95
+ /**
96
+ * DSH 侧的读端:桌面版随包 js-yaml 4.3.2(`app.asar` 内的 `/dsh/node_modules/js-yaml`)。
97
+ * 它装成 devDependency 别名 `js-yaml4`(运行时依赖仍只有 5.x 的 `js-yaml`)。
98
+ *
99
+ * 为什么必须真读 4.x:既有那条「写回保真」是 `load(dump(x))` 自环 —— 5.x 自己读自己恒等,
100
+ * 于是「空标量 / 裸标量关键字」这类跨版本分歧在自环里根本看不见(#135 就是这么漏掉的)。
101
+ * 而 DSH 才是这份文件的真实读者:它是 4.x,按 YAML 1.1 隐式解析。
102
+ */
103
+ const JsExpr4 = new yaml4.Type('tag:yaml.org,2002:js', {
104
+ kind: 'scalar',
105
+ construct: (data) => ({ __jsExpr: String(data) }),
106
+ });
107
+ const DSH_READER_SCHEMA = yaml4.JSON_SCHEMA.extend([JsExpr4]);
108
+
109
+ /** 完全按 DSH 的口径读回一份 patch 文本。 */
110
+ function loadAsDsh(text: string): unknown {
111
+ return yaml4.load(text, { schema: DSH_READER_SCHEMA });
112
+ }
113
+
114
+ /**
115
+ * 会被 4.x 改判类型的字符串:空串 + YAML 1.1 的 null / 布尔 / 进制 / 浮点特例。
116
+ *
117
+ * 这是**回归样本**,不是完备性证明 —— 完备性来自 `forceQuotes` 对每个字符串值都生效
118
+ * (见下一条「输出必须是带引号标量」的结构性断言)。清单实测来源:24 种串 × map/list
119
+ * 共 48 处发散,判据与明细在 `docs/evidence/profiles-and-instances.md`。
120
+ */
121
+ const AMBIGUOUS_STRINGS = [
122
+ '',
123
+ 'Null',
124
+ 'NULL',
125
+ '~',
126
+ 'True',
127
+ 'TRUE',
128
+ 'False',
129
+ 'FALSE',
130
+ '007',
131
+ '-007',
132
+ '+7',
133
+ '012',
134
+ '-012',
135
+ '+1',
136
+ '0x10',
137
+ '0x1F',
138
+ '0o17',
139
+ '0b101',
140
+ '0b1010',
141
+ '.5',
142
+ '-.5',
143
+ '.inf',
144
+ '.Inf',
145
+ '-.inf',
146
+ '.nan',
147
+ '.NaN',
148
+ ];
149
+
150
+ test('#135 写回空字符串是显式空串,4.x 不会读成 null', () => {
151
+ const text = dumpPatchDocument({ config: { constraints: '' } });
152
+ assert.match(text, /constraints: (''|"")/, '空串必须带引号,实际输出:\n' + text);
153
+ assert.deepEqual(loadAsDsh(text), { config: { constraints: '' } });
154
+ });
155
+
156
+ test('#135 每种歧义字符串在 map / list 两个位置都能被 4.x 读回(' + AMBIGUOUS_STRINGS.length * 2 + '/' + AMBIGUOUS_STRINGS.length * 2 + ')', () => {
157
+ const inMap: Record<string, string> = {};
158
+ const inList: Record<string, string[]> = {};
159
+ AMBIGUOUS_STRINGS.forEach((value, index) => {
160
+ inMap['k' + index] = value;
161
+ inList['k' + index] = [value];
162
+ });
163
+ const total = AMBIGUOUS_STRINGS.length;
164
+ assert.deepEqual(loadAsDsh(dumpPatchDocument(inMap)), inMap, `map 位置必须 ${total}/${total}`);
165
+ assert.deepEqual(loadAsDsh(dumpPatchDocument(inList)), inList, `list 位置必须 ${total}/${total}`);
166
+ });
167
+
168
+ /**
169
+ * 完备性断言(不依赖清单):写出去的**每个字符串值**都必须是带引号标量。
170
+ * 带引号的标量在任何 schema 下都是 string,这正是 forceQuotes 能盖住未知怪串的原因;
171
+ * 一旦有人「优化掉引号」,这条先红 —— 与 4.x 清单无关。
172
+ */
173
+ test('#135 输出里的字符串值一律是带引号标量(完备性不靠清单)', () => {
174
+ const samples = [...AMBIGUOUS_STRINGS, 'hello', 'a b', 'x:y', '- z', '#tag', '@deepseek-ai/dsh-mcp-client', ' ', '多行\n第二行'];
175
+ for (const value of samples) {
176
+ const text = dumpPatchDocument({ k: value });
177
+ assert.match(text, /^k: ['"]/, '字符串值必须带引号,实际: ' + JSON.stringify(value) + ' -> ' + JSON.stringify(text));
178
+ }
179
+ });
180
+
181
+ test('#135 两个读端读到同一份值(行为锁定:dump 里不得留 4.x 歧义标量)', () => {
182
+ const doc = {
183
+ constraints: '',
184
+ reserved: null,
185
+ count: 3,
186
+ enabled: true,
187
+ pkg: '@deepseek-ai/dsh-mcp-client',
188
+ spaced: ' ',
189
+ wordIsNull: 'null',
190
+ expr: { __jsExpr: '(function(){ return true })()' },
191
+ };
192
+ const text = dumpPatchDocument(doc);
193
+ assert.deepEqual(loadAsDsh(text), loadPatchDocument(text), 'DSH 读到的值必须与插件读到的相同:\n' + text);
194
+ assert.deepEqual(loadPatchDocument(text), doc, '5.x 侧仍要保真');
195
+ });
196
+
197
+ test('#135 forceQuotes 不改变 !!js:短标签与块标量照旧往返,4.x 侧同样读到 {__jsExpr}', () => {
198
+ const doc = loadPatchDocument(SAMPLE);
199
+ const text = dumpPatchDocument(doc);
200
+ assert.ok(text.includes('!!js '), '短标签保留');
201
+ assert.ok(text.includes('!!js |'), '块标量形态保持(带标签的标量不加引号)');
202
+ assert.deepEqual(loadAsDsh(text), doc, '4.x 必须读到同样的 {__jsExpr}');
203
+ assert.deepEqual(loadPatchDocument(text), doc);
204
+ });
205
+
206
+ /**
207
+ * 已知识别缺口(**记录,不是达标**):js-yaml 5 的 `forceQuotes` 只作用于**值**,键名不在范围内。
208
+ * 于是数值样式的键名在 DSH 的 4.x 侧会被解析成数字/布尔/null 再被 JS 强制回字符串,键名变形。
209
+ * 真机 patch 的键名都是插件名/配置字段名(普通标识符),不受影响;哪天 js-yaml 也给键加引号,
210
+ * 这条会变红 —— 届时删掉它并更新 docs/evidence/profiles-and-instances.md 的相邻缺口一节。
211
+ */
212
+ test('#135 已知缺口:键名不受 forceQuotes 保护(数值样式键名会被 4.x 改名)', () => {
213
+ const text = dumpPatchDocument({ '012': 'v' });
214
+ assert.equal(text, "012: 'v'\n", '当前行为:键名裸写(这是缺口,不是期望)');
215
+ assert.deepEqual(loadAsDsh(text), { '12': 'v' }, '4.x 侧键名变形:012 -> 12');
216
+ });
217
+
92
218
  /* ---------------------------------- 接线守卫(源码级) ---------------------------------- */
93
219
 
94
220
  /**
@@ -110,3 +236,83 @@ test('接线守卫:patch 门面与 boot-safety 的 YAML 解析都必须走本
110
236
  );
111
237
  assert.equal(index.includes('yaml.dump('), false, 'src/index.ts 不得再用裸 yaml.dump 写 patch 文件');
112
238
  });
239
+
240
+ /* ------------------------ 键名跨大版本守卫(issue #137) ------------------------ */
241
+
242
+ test('#137 空键名 → parse-fail(顶层 / 数组元素 / 嵌套 map 都要定位到)', () => {
243
+ assert.deepEqual(findPatchKeyHazards({ '': 'v' }), [{ path: '', key: '', effect: 'parse-fail' }]);
244
+ assert.deepEqual(findPatchKeyHazards({ items: [{ '': 'v' }] }), [{ path: 'items[0]', key: '', effect: 'parse-fail' }]);
245
+ assert.deepEqual(findPatchKeyHazards({ config: { env: { '': 'v' } } }), [{ path: 'config.env', key: '', effect: 'parse-fail' }]);
246
+ });
247
+
248
+ test('#137 4.x 会改判的键名 → rename(全部实测命中)', () => {
249
+ const keys = [
250
+ '~', 'Null', 'NULL', 'True', 'TRUE', 'False', 'FALSE',
251
+ '007', '-007', '+7', '012', '-012', '+1', '00', '000', '0007',
252
+ '0x10', '0x1F', '0o17', '0b101', '0b1010',
253
+ '.5', '.5e2', '00.5', '.inf', '.Inf', '.INF', '-.inf', '.nan', '.NaN', '.NAN',
254
+ ];
255
+ for (const key of keys) {
256
+ assert.deepEqual(findPatchKeyHazards({ [key]: 'v' }), [{ path: '', key, effect: 'rename' }], '键 ' + JSON.stringify(key) + ' 必须命中');
257
+ }
258
+ });
259
+
260
+ test('#137 安全键名一个都不许拦(误伤比漏拦更贵:用户改不动自己的配置)', () => {
261
+ const safe = [
262
+ 'docs', 'a b', 'k:v', 'k#v', 'k #v', '@scope/pkg', '.cjs', 'yes', 'no', 'on', 'off',
263
+ '1_000', '1:20', '12:34:56', '2020-01-01', '2020-01-01T00:00:00Z', '1.2', '1.2.3', '1.0', '0.',
264
+ '0', '-0', '7', '-7', '80', '1e3', '1E3', '1.0e+3', '1.5E-3', 'e3', '1e',
265
+ '0X10', '0O17', '0B101', '+.5', '-.5', '-0.5', 'Infinity', 'NaN', 'inf', 'nan',
266
+ 'null', 'true', 'false', '...', '...x',
267
+ ];
268
+ for (const key of safe) {
269
+ assert.deepEqual(findPatchKeyHazards({ [key]: 'v' }), [], '键 ' + JSON.stringify(key) + ' 不该被拦');
270
+ }
271
+ });
272
+
273
+ /**
274
+ * 语料 = 手写边角 + 生成式数字形态。断言的是「检测器判据 === 真 4.x 判据」:
275
+ * 只有两边完全一致,规则表(AMBIGUOUS_KEYS)才不会悄悄漂移成误伤或漏拦。
276
+ */
277
+ const KEY_CORPUS: string[] = (() => {
278
+ const keys = new Set<string>([
279
+ '~', 'null', 'Null', 'NULL', 'true', 'True', 'TRUE', 'false', 'False', 'FALSE',
280
+ '...', '---', '--- x', '...x', 'docs', 'a b', 'k:v', 'k#v', 'k #v', '@scope/pkg', '.cjs',
281
+ 'yes', 'no', 'on', 'off', '1_000', '1:20', '12:34:56', '2020-01-01', '2020-01-01T00:00:00Z',
282
+ '1.2', '1.2.3', '1.0', '0.', '0', '-0', '7', '-7', '80', '1e3', '1E3', '1.0e+3', '1.5E-3',
283
+ '0X10', '0O17', '0B101', '+.5', '-.5', '-0.5', '+.5e2', 'Infinity', 'NaN', 'inf', 'nan', 'e3', '1e',
284
+ ':', 'x:', ':x', 'x :y', '<x>', '[x]', '{x}', '&x', '*', '|', '1 2', 'a:b:c',
285
+ ]);
286
+ for (const body of ['7', '007', '012', '0x10', '0o17', '0b101', '.5', '00.5', '.5e2', '1.0', '1e3', '.inf', '.NaN']) {
287
+ for (const sign of ['', '-', '+']) keys.add(sign + body);
288
+ }
289
+ // 空键名单独断言:4.x 的报错文案随位置变化,混进语料只会让失败信息更吵
290
+ keys.delete('');
291
+ return [...keys];
292
+ })();
293
+
294
+ test('#137 检测器判据与真 4.x 完全一致(' + KEY_CORPUS.length + ' 项语料,防规则表漂移)', () => {
295
+ const mismatched: { key: string; realRisk: boolean; guarded: boolean }[] = [];
296
+ for (const key of KEY_CORPUS) {
297
+ const text = dumpPatchDocument({ [key]: 'v' });
298
+ let realRisk: boolean;
299
+ try {
300
+ const read = loadAsDsh(text);
301
+ const keys = read !== null && typeof read === 'object' ? Object.keys(read as Record<string, unknown>) : [];
302
+ realRisk = keys.length !== 1 || keys[0] !== key;
303
+ } catch {
304
+ // 4.x 整份读不了:比改判更糟,同样算风险(空键名 / 文档分隔符形态)
305
+ realRisk = true;
306
+ }
307
+ const guarded = findPatchKeyHazards({ [key]: 'v' }).length > 0;
308
+ if (realRisk !== guarded) mismatched.push({ key, realRisk, guarded });
309
+ }
310
+ assert.deepEqual(mismatched, [], '检测器与 4.x 不一致的键:AMBIGUOUS_KEYS 需要更新');
311
+ });
312
+
313
+ test('#137 跳过 {__jsExpr} 子树,且不怕 YAML 锚点造出的环', () => {
314
+ assert.deepEqual(findPatchKeyHazards({ a: [{ __jsExpr: '007' }] }), [], '{__jsExpr} 是我们的内存形态,不是用户键名');
315
+ const cyclic: Record<string, unknown> = { ok: 'v' };
316
+ cyclic['self'] = cyclic;
317
+ assert.deepEqual(findPatchKeyHazards(cyclic), [], '环必须只走一次(否则守卫自己会爆栈)');
318
+ });
@@ -53,9 +53,105 @@ export function loadPatchDocument(text: string): unknown {
53
53
  return load(text, { schema: PATCH_YAML_SCHEMA })
54
54
  }
55
55
 
56
- /** 写回 patch 文档:`{__jsExpr}` 还原成 `!!js`,其余按 DSH 的 schema 打印。 */
56
+ /**
57
+ * 写回 patch 文档:`{__jsExpr}` 还原成 `!!js`,字符串一律带引号(issue #135)。
58
+ *
59
+ * `forceQuotes` 不是风格偏好,而是**跨大版本读回的前提**:本插件装在 js-yaml 5.x 上打印,
60
+ * DSH 本体用 4.x 读回(桌面版随包 4.3.2)。5.x 的渲染器只按自己的解析规则决定要不要加引号,
61
+ * 于是 `""` `Null` `~` `True` `007` `0x10` `.inf` 这类**字符串**被写成裸标量,
62
+ * 4.x 按 YAML 1.1 隐式解析成 `null` / `true` / `7` / `16` / `Infinity` —— 两边读到不同的值,
63
+ * 把该字段声明为必填 string 的插件启动时直接 ZodError。
64
+ *
65
+ * 代价(已知且接受):字符串值普遍带引号;普通多行字符串从 `|` 块退化为双引号 + `\n`
66
+ * (`!!js` 的块标量带标签,不受影响)。只影响写出去的字节,读侧语义不变:
67
+ * 已经写成空标量的历史文件仍由 `loadPatchDocument` 读成 `""`,该层下次被写回时自动复原。
68
+ */
57
69
  export function dumpPatchDocument(value: unknown): string {
58
- return dump(value, { schema: PATCH_YAML_SCHEMA })
70
+ return dump(value, { schema: PATCH_YAML_SCHEMA, forceQuotes: true })
71
+ }
72
+
73
+ /**
74
+ * 键名在 DSH 读端(js-yaml 4.x)的**改判**形态。
75
+ *
76
+ * 为什么需要单独一层检查:`forceQuotes`(issue #135)只保**值**,键名是 js-yaml 自己决定加不加
77
+ * 引号的 —— 5.x 只给「YAML 1.2 会改判」的键加引号,1.1-only 的形态(`007`、`True`、`.5`、`~`)
78
+ * 一律裸写,于是 4.x 把键读成 `7` / `true` / `0.5` / `null`:配置静默改名,插件读不到自己的键。
79
+ * 空键名更糟 —— `: 'v'` 会让 4.x **整份文件解析失败**(该层所有行一起失效)。
80
+ */
81
+ export type PatchKeyHazardEffect = 'parse-fail' | 'rename'
82
+
83
+ /** 一处键名风险。 */
84
+ export interface PatchKeyHazard {
85
+ /** 键所在容器的路径(`''` = 顶层;数组元素记作 `items[3]`) */
86
+ path: string
87
+ /** 出问题的键名原文(空串 = 空键名) */
88
+ key: string
89
+ /** `parse-fail` = 4.x 整份文件解析失败;`rename` = 键被改判成数字 / 布尔 / null */
90
+ effect: PatchKeyHazardEffect
91
+ }
92
+
93
+ /**
94
+ * 4.x(YAML 1.1 隐式解析)会改判的裸键形态 —— **只列实测会改判的**。
95
+ *
96
+ * 实测口径(`.tmp` 之外不留脚本,结论进 docs/evidence):`0X10` / `0B101` / `+.5` / `-.5` /
97
+ * `1_000` / `2020-01-01` / `yes` / `1.2`(5.x 自己会加引号或两端都是字符串)一律**不算**风险。
98
+ */
99
+ const AMBIGUOUS_KEYS: readonly RegExp[] = [
100
+ /^~$/,
101
+ /^(?:null|Null|NULL|true|True|TRUE|false|False|FALSE)$/,
102
+ /^[-+]?0x[0-9a-fA-F]+$/,
103
+ /^[-+]?0b[01]+$/,
104
+ /^[-+]?0o[0-7]+$/,
105
+ /^[-+]?\d+$/,
106
+ /^(?:[-+]?\d+(?:\.\d*)?|\.\d+)(?:[eE][-+]?\d+)?$/,
107
+ /^[-+]?\.(?:inf|Inf|INF)$/,
108
+ /^\.(?:nan|NaN|NAN)$/,
109
+ ]
110
+
111
+ /** 5.x 会把键裸写吗(不加引号)—— 用真 dumper 判,不靠推断引号规则。 */
112
+ function isKeyWrittenBare(key: string): boolean {
113
+ try {
114
+ return dumpPatchDocument({ [key]: 'x' }).startsWith(`${key}:`)
115
+ } catch {
116
+ return false
117
+ }
118
+ }
119
+
120
+ function keyHazardEffect(key: string): PatchKeyHazardEffect | null {
121
+ if (key === '') return 'parse-fail'
122
+ if (!isKeyWrittenBare(key)) return null
123
+ // 文档分隔符写进键位会把整份文件切成两段(`--- x: v` 连 5.x 自己都读不回来)
124
+ if (key === '---' || key.startsWith('--- ')) return 'parse-fail'
125
+ return AMBIGUOUS_KEYS.some((pattern) => pattern.test(key)) ? 'rename' : null
126
+ }
127
+
128
+ /**
129
+ * 找出一个 patch 行里**会跨大版本读坏**的键名(issue #137)。
130
+ *
131
+ * 只扫键、不扫值(值由 `dumpPatchDocument` 的 `forceQuotes` 兜住);`{__jsExpr}` 是本模块的
132
+ * 内存形态不是用户键名,整棵子树跳过;YAML 锚点可以造环,同一对象只走一次。
133
+ * 返回空数组 = 这一行写出去 4.x / 5.x 读到的键名一致。
134
+ */
135
+ export function findPatchKeyHazards(value: unknown): PatchKeyHazard[] {
136
+ const hazards: PatchKeyHazard[] = []
137
+ const seen = new Set<object>()
138
+ const walk = (node: unknown, path: string): void => {
139
+ if (node === null || typeof node !== 'object') return
140
+ if (isPatchJsExpr(node)) return
141
+ if (seen.has(node)) return
142
+ seen.add(node)
143
+ if (Array.isArray(node)) {
144
+ node.forEach((item, index) => walk(item, `${path}[${index}]`))
145
+ return
146
+ }
147
+ for (const [key, child] of Object.entries(node as Record<string, unknown>)) {
148
+ const effect = keyHazardEffect(key)
149
+ if (effect !== null) hazards.push({ path, key, effect })
150
+ walk(child, path === '' ? key : `${path}.${key}`)
151
+ }
152
+ }
153
+ walk(value, '')
154
+ return hazards
59
155
  }
60
156
 
61
157
  /**
@@ -8,7 +8,7 @@
8
8
  import test from 'node:test';
9
9
  import assert from 'node:assert/strict';
10
10
  import path from 'node:path';
11
- import { applyPrefixMappings, isPathInside, isSameOrChild } from './paths.ts';
11
+ import { applyPrefixMappings, isPathInside, isSameOrChild, isSensitiveHomeRel } from './paths.ts';
12
12
  import type { PathMapping } from '../core/types.ts';
13
13
 
14
14
  /** 测试用映射(appliesTo 与语义无关,任选一个合法分区) */
@@ -96,3 +96,16 @@ test('core-E1:越界判定只有一份实现,且 `..foo` 这种合法兄弟
96
96
  // foldCase:false 只在 POSIX 生效:win32 的 path.relative 自己就折大小写(故此处结果仍 true)
97
97
  assert.equal(isPathInside('/a/B', '/a/b', { foldCase: false }), process.platform === 'win32');
98
98
  });
99
+
100
+ test('审计 P2-1:isSensitiveHomeRel 认得出凭据形状(分区出包的单一判据)', () => {
101
+ // 命中:vault 段 / 常见凭据文件名(大小写与分隔符不敏感)
102
+ for (const rel of ['.mnemon/vault/key', '.mnemon/VAULT/key', '.mnemon/credentials.yaml', '.mnemon/CREDENTIALS.json',
103
+ '.mnemon/credentials', '.dsh-x/secrets.yaml', '.dsh-x/auth.json', '.dsh-x/.env', '.dsh-x/.env.local', '.dsh-x/.credentials.yml']) {
104
+ assert.equal(isSensitiveHomeRel(rel), true, `必须判敏感:${rel}`);
105
+ }
106
+ // 不命中:普通配置/资产/包含关键词但不是凭据名的文件
107
+ for (const rel of ['.mnemon/runtime/MEMORY.md', '.dsh-x/config.json', '.dsh-x/uploads/wall.mp4',
108
+ '.dsh-x/credentials-backup.txt', '.dsh-x/my-credentials-notes.md', '.dsh-x/vaulted/config.json']) {
109
+ assert.equal(isSensitiveHomeRel(rel), false, `不得误判:${rel}`);
110
+ }
111
+ });
@@ -89,6 +89,10 @@ const RESERVED_INTERNAL_PREFIXES: readonly string[] = [
89
89
  'dsh-config-manager/environment-fingerprint.token',
90
90
  // Phase 6:迁移历史审计目录(统一历史引擎;防 F23 投毒链——不可信导入不得映射到该目录)。
91
91
  'dsh-config-manager/migration-history/',
92
+ // Phase 6+(审计 P12-5):敏感文件镜像目录(<dataDir>/vault)存的是 .credentials.yaml 等明文镜像,
93
+ // 与上面几项同属「不可信归档不得映射进来」的 control-plane 区;isSensitiveHomeRel 已在**收集/打包**
94
+ // 侧按 vault 段拦这种文件,这里补上**导入目标**侧的同一判据,免得 crafted 归档把条目写进镜像目录。
95
+ 'dsh-config-manager/vault/',
92
96
  // 注意:不得整段保留 dsh-config-manager/sync/ —— self 分区合法持有 sync/*.json 白名单配置
93
97
  //(sync-config / sync-selection / ui-prefs / backup-schedule),会误伤。
94
98
  'dsh-config-manager/sync/snapshots/',
@@ -129,6 +133,37 @@ export function isReservedInternalRel(relPath: string): boolean {
129
133
  return false;
130
134
  }
131
135
 
136
+ /**
137
+ * 凭据文件(home 相对路径)判定 —— **全仓唯一出口**(审计 P2-1 P0 修复,2026-11-13)。
138
+ *
139
+ * 为什么必须有:pluginData / pluginAssets 的分区根是**系统主目录**,来源既可能是内置表,
140
+ * 也可能是插件自己在 package.json 里声明的 `dsh.dataDirs`。声明方只要写 `.dsh`,就会把
141
+ * `~/.dsh/.credentials.yaml` 当普通配置收进**明文 ZIP** —— 而 manifest 仍报「不含密钥」
142
+ * (真机实测:包内出现 plugin-data/.dsh/.credentials.yaml,containsSecrets=false)。
143
+ * 字段级脱敏只处理结构化值,管不到「整文件即秘密」的形态,所以按**文件名形态**判一次,
144
+ * 收集侧(adapter)与打包侧(exporter)共用同一判据 —— 两处都在,缺一即回归。
145
+ *
146
+ * 只认名字、不做内容嗅探:收集期读全部字节既慢又读不完大资产。
147
+ */
148
+ export function isSensitiveHomeRel(relPath: string): boolean {
149
+ const norm = normalizePathCollapsed(relPath).toLowerCase();
150
+ if (norm === '') return false;
151
+ const segments = norm.split('/');
152
+ // vault 目录本身即凭据明文镜像(<dataDir>/vault),任何形态都不得进归档
153
+ if (segments.includes('vault')) return true;
154
+ const base = segments[segments.length - 1] ?? '';
155
+ return SENSITIVE_HOME_BASENAMES.some((re) => re.test(base));
156
+ }
157
+
158
+ /** 凭据文件名形态(小写比较;与 DEFAULT_SENSITIVE_RELS 的「整文件即秘密」同口径) */
159
+ const SENSITIVE_HOME_BASENAMES: readonly RegExp[] = [
160
+ /^\.?credentials(\..*)?$/, // .credentials.yaml / credentials.json / .credentials
161
+ /^credentials\.(ya?ml|json)$/,
162
+ /^secrets\.(ya?ml|json)$/,
163
+ /^auth\.json$/,
164
+ /^\.env(\..*)?$/,
165
+ ];
166
+
132
167
  /**
133
168
  * Windows 语义路径(盘符 "C:/"、"C:\\";UNC 以两个斜杠或两个反斜杠开头)。
134
169
  *