dsh-config-manager 0.8.2 → 0.10.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 (418) hide show
  1. package/lib/adapters/mcp.js +51 -15
  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 +204 -6
  10. package/lib/adapters/prompts.js +15 -4
  11. package/lib/adapters/test-helpers.d.ts +15 -1
  12. package/lib/adapters/test-helpers.js +11 -0
  13. package/lib/cli/actions.d.ts +7 -105
  14. package/lib/cli/actions.js +16 -172
  15. package/lib/cli/control-state.d.ts +54 -0
  16. package/lib/cli/control-state.js +107 -0
  17. package/lib/cli/help.d.ts +1 -1
  18. package/lib/cli/help.js +21 -14
  19. package/lib/cli/index.js +132 -104
  20. package/lib/cli/sessions-repair.js +58 -22
  21. package/lib/cli/web/client-script.d.ts +1 -1
  22. package/lib/cli/web/client-script.js +71 -5
  23. package/lib/cli/web/page.d.ts +9 -19
  24. package/lib/cli/web/page.js +277 -173
  25. package/lib/cli/web/routes.js +85 -25
  26. package/lib/cli/write-gates.d.ts +61 -0
  27. package/lib/cli/write-gates.js +110 -0
  28. package/lib/client.d.ts +196 -75
  29. package/lib/client.js +8139 -7487
  30. package/lib/core/backup.d.ts +0 -4
  31. package/lib/core/backup.js +21 -4
  32. package/lib/core/boot-rescue.d.ts +1 -1
  33. package/lib/core/boot-rescue.js +12 -1
  34. package/lib/core/boot-safety.js +37 -2
  35. package/lib/core/conflict-decisions.js +2 -1
  36. package/lib/core/exporter.js +22 -1
  37. package/lib/core/journal.d.ts +54 -4
  38. package/lib/core/journal.js +158 -35
  39. package/lib/core/local-plugin-host.d.ts +29 -0
  40. package/lib/core/local-plugin-host.js +55 -48
  41. package/lib/core/messages.d.ts +17 -0
  42. package/lib/core/messages.js +34 -0
  43. package/lib/core/migration-history.js +16 -9
  44. package/lib/core/model-tools.d.ts +2 -2
  45. package/lib/core/model-tools.js +20 -2
  46. package/lib/core/patch-chain.d.ts +65 -0
  47. package/lib/core/patch-chain.js +100 -0
  48. package/lib/core/patch-document.d.ts +32 -4
  49. package/lib/core/patch-document.js +48 -17
  50. package/lib/core/patch-secret-guard.d.ts +49 -0
  51. package/lib/core/patch-secret-guard.js +164 -0
  52. package/lib/core/reconcile.d.ts +8 -0
  53. package/lib/core/reconcile.js +18 -3
  54. package/lib/core/reinstall.d.ts +2 -0
  55. package/lib/core/reinstall.js +6 -2
  56. package/lib/core/restore.js +31 -6
  57. package/lib/core/section-sanitize.d.ts +32 -0
  58. package/lib/core/section-sanitize.js +13 -0
  59. package/lib/core/snapshot-diff.d.ts +30 -0
  60. package/lib/core/snapshot-diff.js +56 -20
  61. package/lib/core/startup-barrier.js +8 -2
  62. package/lib/core/types.d.ts +38 -1
  63. package/lib/core/update-check.js +51 -2
  64. package/lib/foreign/kernel.js +9 -2
  65. package/lib/foreign/read-claude-plugins.js +29 -11
  66. package/lib/foreign/read-dsh.js +31 -2
  67. package/lib/foreign/session-ir.js +50 -9
  68. package/lib/foreign/session-read.d.ts +8 -0
  69. package/lib/foreign/session-read.js +26 -0
  70. package/lib/index.d.ts +9 -4
  71. package/lib/index.js +42 -47
  72. package/lib/profiles/dsh-profile-io.d.ts +20 -0
  73. package/lib/profiles/dsh-profile-io.js +27 -0
  74. package/lib/profiles/dsh-profile-manager.d.ts +27 -0
  75. package/lib/profiles/dsh-profile-manager.js +45 -4
  76. package/lib/profiles/dsh-profile-runtime.d.ts +5 -1
  77. package/lib/profiles/dsh-profile-runtime.js +16 -3
  78. package/lib/profiles/process-control.d.ts +18 -1
  79. package/lib/profiles/process-control.js +25 -1
  80. package/lib/routes/profiles.js +2 -1
  81. package/lib/routes/sync.js +19 -1
  82. package/lib/schema/types.d.ts +11 -0
  83. package/lib/security/redaction.js +22 -6
  84. package/lib/sync/autosync-repeat.d.ts +27 -0
  85. package/lib/sync/autosync-repeat.js +23 -0
  86. package/lib/sync/autosync-scheduler.d.ts +47 -2
  87. package/lib/sync/autosync-scheduler.js +217 -53
  88. package/lib/sync/baseline-heal.js +7 -0
  89. package/lib/sync/baseline-record.d.ts +67 -0
  90. package/lib/sync/baseline-record.js +74 -0
  91. package/lib/sync/blob-store.js +13 -0
  92. package/lib/sync/content-diff.d.ts +39 -0
  93. package/lib/sync/content-diff.js +46 -0
  94. package/lib/sync/git/git-transport.d.ts +32 -1
  95. package/lib/sync/git/git-transport.js +146 -26
  96. package/lib/sync/github-auth.d.ts +17 -1
  97. package/lib/sync/github-auth.js +37 -1
  98. package/lib/sync/local-changes.d.ts +15 -0
  99. package/lib/sync/local-changes.js +39 -0
  100. package/lib/sync/merge-apply-plan.d.ts +38 -0
  101. package/lib/sync/merge-apply-plan.js +76 -0
  102. package/lib/sync/merge-keyed.d.ts +68 -0
  103. package/lib/sync/merge-keyed.js +124 -0
  104. package/lib/sync/messages.d.ts +1 -0
  105. package/lib/sync/messages.js +2 -0
  106. package/lib/sync/patch-line-identity.d.ts +19 -0
  107. package/lib/sync/patch-line-identity.js +99 -0
  108. package/lib/sync/pending-merge.d.ts +41 -0
  109. package/lib/sync/pending-merge.js +61 -0
  110. package/lib/sync/plugin-removals.d.ts +15 -15
  111. package/lib/sync/plugin-removals.js +134 -83
  112. package/lib/sync/push-skip.d.ts +55 -0
  113. package/lib/sync/push-skip.js +70 -0
  114. package/lib/sync/s3/s3-transport.d.ts +14 -2
  115. package/lib/sync/s3/s3-transport.js +72 -48
  116. package/lib/sync/sync-engine.d.ts +44 -51
  117. package/lib/sync/sync-engine.js +160 -194
  118. package/lib/sync/sync-history.d.ts +7 -0
  119. package/lib/sync/sync-state.d.ts +28 -0
  120. package/lib/sync/sync-state.js +20 -0
  121. package/lib/sync/transport.d.ts +12 -3
  122. package/lib/sync/transport.js +13 -4
  123. package/lib/sync/webdav/webdav-transport.d.ts +19 -2
  124. package/lib/sync/webdav/webdav-transport.js +81 -40
  125. package/lib/sync/workspace-merge.d.ts +8 -2
  126. package/lib/ui/artifact-view.d.ts +1 -1
  127. package/lib/ui/commands.js +5 -11
  128. package/lib/ui/dsh-profiles-view.d.ts +8 -3
  129. package/lib/ui/dsh-profiles-view.js +9 -5
  130. package/lib/ui/foreign-view.d.ts +14 -0
  131. package/lib/ui/foreign-view.js +34 -0
  132. package/lib/ui/i18n.d.ts +7 -1
  133. package/lib/ui/i18n.js +15 -2
  134. package/lib/ui/menu-placement.js +1 -1
  135. package/lib/ui/migration-consult-view.d.ts +11 -0
  136. package/lib/ui/migration-consult-view.js +15 -0
  137. package/lib/ui/overview-view.d.ts +7 -0
  138. package/lib/ui/overview-view.js +3 -0
  139. package/lib/ui/report.d.ts +9 -0
  140. package/lib/ui/report.js +17 -4
  141. package/lib/ui/selection-model.d.ts +10 -2
  142. package/lib/ui/selection-model.js +23 -3
  143. package/lib/utils/async-once.d.ts +11 -0
  144. package/lib/utils/async-once.js +15 -0
  145. package/lib/utils/patch-chain-read.d.ts +51 -0
  146. package/lib/utils/patch-chain-read.js +240 -0
  147. package/lib/utils/patch-yaml.d.ts +39 -1
  148. package/lib/utils/patch-yaml.js +82 -2
  149. package/lib/utils/paths.d.ts +13 -0
  150. package/lib/utils/paths.js +35 -0
  151. package/lib/utils/workdir-lock.js +18 -3
  152. package/package.json +3 -2
  153. package/src/adapters/mcp.test.ts +29 -0
  154. package/src/adapters/mcp.ts +52 -14
  155. package/src/adapters/messages.ts +2 -0
  156. package/src/adapters/patch-key-guard.ts +29 -0
  157. package/src/adapters/plugin-data.test.ts +126 -0
  158. package/src/adapters/plugin-data.ts +97 -26
  159. package/src/adapters/plugins.test.ts +403 -0
  160. package/src/adapters/plugins.ts +198 -8
  161. package/src/adapters/prompts.ts +15 -4
  162. package/src/adapters/test-helpers.ts +15 -1
  163. package/src/cli/actions.test.ts +74 -1
  164. package/src/cli/actions.ts +27 -246
  165. package/src/cli/control-state.ts +143 -0
  166. package/src/cli/help.ts +21 -14
  167. package/src/cli/index.ts +123 -107
  168. package/src/cli/sessions-repair.ts +55 -22
  169. package/src/cli/web/client-script.ts +71 -5
  170. package/src/cli/web/page.ts +327 -208
  171. package/src/cli/web/routes.ts +85 -25
  172. package/src/cli/web/web.test.ts +65 -0
  173. package/src/cli/write-gates.ts +149 -0
  174. package/src/client/ConfigManagerSection.tsx +8 -4
  175. package/src/client/about/AboutPanel.tsx +9 -12
  176. package/src/client/about/release-notes-view.test.ts +17 -0
  177. package/src/client/about/release-notes-view.ts +49 -24
  178. package/src/client/api.ts +2 -1
  179. package/src/client/chat/ChatEntryView.tsx +2 -2
  180. package/src/client/chat/rollback-entry-view.ts +6 -1
  181. package/src/client/common/CommandPalette.tsx +6 -3
  182. package/src/client/common/ConfirmDialog.tsx +29 -12
  183. package/src/client/common/ContentPicker.tsx +24 -24
  184. package/src/client/common/Modal.tsx +12 -5
  185. package/src/client/common/MoreMenu.tsx +4 -1
  186. package/src/client/common/RunsCenter.tsx +103 -32
  187. package/src/client/common/Select.tsx +2 -2
  188. package/src/client/common/floating-bounds.ts +1 -1
  189. package/src/client/common/floating-units.test.ts +1 -2
  190. package/src/client/common/plan-text-redaction.test.ts +190 -5
  191. package/src/client/common/runs-center-guard.test.ts +60 -0
  192. package/src/client/common/runs-center-view.test.ts +128 -0
  193. package/src/client/common/runs-center-view.ts +96 -0
  194. package/src/client/common/section-title-action.test.ts +66 -0
  195. package/src/client/common/ui.tsx +93 -30
  196. package/src/client/config-manager.module.css +1515 -270
  197. package/src/client/consult/ConsultCard.tsx +7 -6
  198. package/src/client/environment/EnvironmentPanel.tsx +22 -25
  199. package/src/client/environment/maintenance/DiskUsageCard.tsx +69 -96
  200. package/src/client/environment/profiles-incomplete-ui.test.ts +8 -8
  201. package/src/client/export/ExportView.tsx +7 -16
  202. package/src/client/history/HistoryPanel.tsx +88 -28
  203. package/src/client/history/history-locales.ts +3 -3
  204. package/src/client/home/BackupScheduleCard.tsx +77 -69
  205. package/src/client/home/HomePanel.tsx +47 -12
  206. package/src/client/import/ConflictList.tsx +13 -13
  207. package/src/client/import/ForeignImportView.tsx +67 -9
  208. package/src/client/import/ImportWizardView.tsx +4 -4
  209. package/src/client/import/PathMappingForm.tsx +36 -9
  210. package/src/client/import/PathPickerDialog.tsx +2 -1
  211. package/src/client/import/import-wizard-split.test.ts +1 -1
  212. package/src/client/import/import-wizard-steps.tsx +51 -39
  213. package/src/client/import/use-import-wizard-controller.test.ts +129 -0
  214. package/src/client/import/use-import-wizard-controller.ts +116 -22
  215. package/src/client/library/ArtifactRow.tsx +2 -2
  216. package/src/client/library/BackupInspectView.tsx +21 -15
  217. package/src/client/library/LibraryActions.tsx +116 -28
  218. package/src/client/library/LibraryPanel.tsx +14 -15
  219. package/src/client/library/RestorePlanView.tsx +13 -8
  220. package/src/client/locales/about.ts +0 -2
  221. package/src/client/locales/backup.ts +15 -12
  222. package/src/client/locales/common.ts +2 -0
  223. package/src/client/locales/export.ts +5 -12
  224. package/src/client/locales/foreign.ts +4 -2
  225. package/src/client/locales/import.ts +5 -2
  226. package/src/client/locales/overview.ts +4 -0
  227. package/src/client/locales/profiles.ts +32 -4
  228. package/src/client/locales/restore.ts +2 -2
  229. package/src/client/locales/sessions.ts +0 -2
  230. package/src/client/locales/shell.ts +2 -2
  231. package/src/client/market/MarketImportReview.tsx +4 -4
  232. package/src/client/market/MarketPanel.tsx +58 -56
  233. package/src/client/market/MyConfigsList.tsx +34 -32
  234. package/src/client/market/MyConfigsLoginCard.tsx +12 -15
  235. package/src/client/market/MyConfigsView.tsx +8 -15
  236. package/src/client/market/MyConfigsWizard.tsx +7 -12
  237. package/src/client/market/market-locales.ts +0 -6
  238. package/src/client/market/my-configs-split.test.ts +2 -1
  239. package/src/client/nav-menu-clip-guard.test.ts +52 -0
  240. package/src/client/recovery/IncompleteCopiesSection.tsx +1 -3
  241. package/src/client/recovery/RecoveryPanel.tsx +35 -22
  242. package/src/client/recovery/RollbackCard.tsx +132 -75
  243. package/src/client/recovery/RollbackFileChanges.tsx +40 -27
  244. package/src/client/recovery/SessionHealthCard.tsx +2 -2
  245. package/src/client/recovery/SessionHealthDialog.tsx +5 -7
  246. package/src/client/recovery/SessionLayoutSection.tsx +3 -5
  247. package/src/client/recovery/recovery-locales.ts +12 -8
  248. package/src/client/recovery/rollback-enabled.ts +29 -0
  249. package/src/client/recovery/use-recovery-write.ts +5 -0
  250. package/src/client/run-store.test.ts +30 -0
  251. package/src/client/run-store.ts +21 -1
  252. package/src/client/sync/AddChannelCard.tsx +65 -0
  253. package/src/client/sync/AutosyncCard.tsx +184 -108
  254. package/src/client/sync/ChannelClearConfirmDialog.tsx +5 -1
  255. package/src/client/sync/ChannelConfigDialog.tsx +27 -48
  256. package/src/client/sync/MergePreviewView.tsx +5 -7
  257. package/src/client/sync/PushPreviewCard.tsx +2 -1
  258. package/src/client/sync/PushReportSections.tsx +35 -0
  259. package/src/client/sync/SyncChannelEntryCard.tsx +33 -24
  260. package/src/client/sync/SyncConfirmView.tsx +130 -133
  261. package/src/client/sync/SyncLogList.tsx +29 -14
  262. package/src/client/sync/SyncPanel.tsx +188 -185
  263. package/src/client/sync/SyncProbeRow.tsx +5 -7
  264. package/src/client/sync/SyncRepositoryPicker.tsx +17 -4
  265. package/src/client/sync/SyncSecuritySection.tsx +157 -0
  266. package/src/client/sync/SyncSettingsDialog.tsx +293 -0
  267. package/src/client/sync/SyncSettingsView.test.ts +26 -8
  268. package/src/client/sync/WorkDirCard.tsx +2 -4
  269. package/src/client/sync/config-clear-guard.test.ts +94 -0
  270. package/src/client/sync/config-clear-guard.ts +98 -0
  271. package/src/client/sync/config-dirty.test.ts +91 -0
  272. package/src/client/sync/config-dirty.ts +88 -0
  273. package/src/client/sync/history-model.test.ts +2 -0
  274. package/src/client/sync/history-model.ts +5 -0
  275. package/src/client/sync/merge-request.ts +20 -0
  276. package/src/client/sync/sync-api.ts +13 -1
  277. package/src/client/sync/sync-locales.ts +95 -47
  278. package/src/client/sync/sync-panel-clear.test.ts +44 -0
  279. package/src/client/sync/sync-push-preview.test.ts +9 -0
  280. package/src/client/sync/sync-view.test.ts +20 -0
  281. package/src/client/sync/sync-view.ts +76 -4
  282. package/src/core/backup.test.ts +61 -1
  283. package/src/core/backup.ts +21 -4
  284. package/src/core/boot-rescue.test.ts +35 -0
  285. package/src/core/boot-rescue.ts +13 -2
  286. package/src/core/boot-safety.test.ts +25 -0
  287. package/src/core/boot-safety.ts +37 -2
  288. package/src/core/conflict-decisions.ts +2 -1
  289. package/src/core/exporter.ts +21 -1
  290. package/src/core/journal.test.ts +183 -0
  291. package/src/core/journal.ts +163 -25
  292. package/src/core/local-plugin-host.test.ts +68 -2
  293. package/src/core/local-plugin-host.ts +31 -4
  294. package/src/core/messages.ts +34 -0
  295. package/src/core/migration-history.test.ts +27 -0
  296. package/src/core/migration-history.ts +12 -4
  297. package/src/core/model-tools.test.ts +67 -0
  298. package/src/core/model-tools.ts +22 -4
  299. package/src/core/patch-chain.test.ts +83 -0
  300. package/src/core/patch-chain.ts +150 -0
  301. package/src/core/patch-document.test.ts +48 -1
  302. package/src/core/patch-document.ts +66 -15
  303. package/src/core/patch-layers.test.ts +1 -1
  304. package/src/core/patch-secret-guard.test.ts +110 -0
  305. package/src/core/patch-secret-guard.ts +176 -0
  306. package/src/core/reconcile.ts +32 -4
  307. package/src/core/reinstall.ts +8 -2
  308. package/src/core/restore.ts +32 -7
  309. package/src/core/section-sanitize.ts +37 -0
  310. package/src/core/smoke.test.ts +2 -1
  311. package/src/core/snapshot-diff.test.ts +73 -1
  312. package/src/core/snapshot-diff.ts +66 -21
  313. package/src/core/startup-barrier.test.ts +64 -0
  314. package/src/core/startup-barrier.ts +8 -2
  315. package/src/core/types.ts +43 -2
  316. package/src/core/update-check.test.ts +40 -0
  317. package/src/core/update-check.ts +53 -2
  318. package/src/foreign/claude-code.test.ts +5 -0
  319. package/src/foreign/claude-plugins.test.ts +57 -0
  320. package/src/foreign/claude-sessions-bytes.test.ts +7 -1
  321. package/src/foreign/dsh.test.ts +23 -0
  322. package/src/foreign/kernel.ts +9 -2
  323. package/src/foreign/read-claude-plugins.ts +32 -11
  324. package/src/foreign/read-dsh.ts +33 -2
  325. package/src/foreign/session-ir.test.ts +67 -0
  326. package/src/foreign/session-ir.ts +54 -14
  327. package/src/foreign/session-read.ts +23 -0
  328. package/src/index.facade.test.ts +186 -6
  329. package/src/index.ts +53 -47
  330. package/src/profiles/dsh-profile-copy-rollback.test.ts +58 -4
  331. package/src/profiles/dsh-profile-io.ts +29 -0
  332. package/src/profiles/dsh-profile-manager.test.ts +30 -0
  333. package/src/profiles/dsh-profile-manager.ts +53 -5
  334. package/src/profiles/dsh-profile-runtime.test.ts +29 -7
  335. package/src/profiles/dsh-profile-runtime.ts +17 -3
  336. package/src/profiles/process-control.test.ts +97 -0
  337. package/src/profiles/process-control.ts +28 -1
  338. package/src/routes/profiles.ts +2 -1
  339. package/src/routes/sync.ts +19 -1
  340. package/src/schema/types.ts +16 -1
  341. package/src/security/redaction.test.ts +31 -0
  342. package/src/security/redaction.ts +23 -6
  343. package/src/security/security.test.ts +1 -1
  344. package/src/sync/autosync-repeat.test.ts +58 -0
  345. package/src/sync/autosync-repeat.ts +55 -0
  346. package/src/sync/autosync-scheduler.test.ts +515 -0
  347. package/src/sync/autosync-scheduler.ts +225 -51
  348. package/src/sync/baseline-heal.ts +6 -0
  349. package/src/sync/baseline-record.ts +135 -0
  350. package/src/sync/blob-store.test.ts +16 -0
  351. package/src/sync/blob-store.ts +13 -0
  352. package/src/sync/content-diff.test.ts +95 -0
  353. package/src/sync/content-diff.ts +79 -0
  354. package/src/sync/git/git-transport.test.ts +151 -4
  355. package/src/sync/git/git-transport.ts +143 -27
  356. package/src/sync/github-auth.test.ts +26 -1
  357. package/src/sync/github-auth.ts +37 -1
  358. package/src/sync/local-changes.ts +40 -0
  359. package/src/sync/merge-apply-plan.ts +117 -0
  360. package/src/sync/merge-keyed.test.ts +167 -0
  361. package/src/sync/merge-keyed.ts +160 -0
  362. package/src/sync/messages.ts +3 -0
  363. package/src/sync/patch-line-identity.test.ts +73 -0
  364. package/src/sync/patch-line-identity.ts +105 -0
  365. package/src/sync/pending-merge.test.ts +41 -0
  366. package/src/sync/pending-merge.ts +85 -0
  367. package/src/sync/plugin-removals.test.ts +199 -39
  368. package/src/sync/plugin-removals.ts +150 -64
  369. package/src/sync/push-skip.test.ts +326 -0
  370. package/src/sync/push-skip.ts +102 -0
  371. package/src/sync/s3/s3-delete-and-blob-index.test.ts +249 -0
  372. package/src/sync/s3/s3-transport.ts +76 -42
  373. package/src/sync/sync-config.test.ts +39 -12
  374. package/src/sync/sync-device-identity.test.ts +3 -0
  375. package/src/sync/sync-engine.test.ts +465 -12
  376. package/src/sync/sync-engine.ts +189 -193
  377. package/src/sync/sync-history.ts +7 -0
  378. package/src/sync/sync-state.ts +48 -0
  379. package/src/sync/transport.test.ts +13 -1
  380. package/src/sync/transport.ts +12 -4
  381. package/src/sync/webdav/webdav-delete-and-blob-index.test.ts +249 -0
  382. package/src/sync/webdav/webdav-transport.ts +86 -34
  383. package/src/sync/workspace-merge.ts +9 -2
  384. package/src/ui/artifact-view.ts +1 -1
  385. package/src/ui/commands.test.ts +11 -0
  386. package/src/ui/commands.ts +5 -14
  387. package/src/ui/dsh-profiles-view.test.ts +16 -0
  388. package/src/ui/dsh-profiles-view.ts +11 -5
  389. package/src/ui/foreign-view.test.ts +49 -0
  390. package/src/ui/foreign-view.ts +47 -0
  391. package/src/ui/i18n.ts +15 -2
  392. package/src/ui/menu-placement.ts +1 -1
  393. package/src/ui/migration-consult-view.test.ts +20 -1
  394. package/src/ui/migration-consult-view.ts +17 -0
  395. package/src/ui/overview-view.ts +10 -0
  396. package/src/ui/report.test.ts +25 -1
  397. package/src/ui/report.ts +15 -4
  398. package/src/ui/selection-model.test.ts +29 -1
  399. package/src/ui/selection-model.ts +25 -4
  400. package/src/utils/async-once.ts +14 -0
  401. package/src/utils/js-yaml4.d.ts +35 -0
  402. package/src/utils/patch-chain-read.test.ts +171 -0
  403. package/src/utils/patch-chain-read.ts +259 -0
  404. package/src/utils/patch-yaml.test.ts +215 -3
  405. package/src/utils/patch-yaml.ts +98 -2
  406. package/src/utils/paths.test.ts +14 -1
  407. package/src/utils/paths.ts +35 -0
  408. package/src/utils/workdir-lock.test.ts +69 -0
  409. package/src/utils/workdir-lock.ts +17 -3
  410. package/lib/ui/path-mapping.d.ts +0 -38
  411. package/lib/ui/path-mapping.js +0 -75
  412. package/src/client/common/InfoHint.tsx +0 -289
  413. package/src/client/common/info-hint-guard.test.ts +0 -1119
  414. package/src/client/sync/DecryptPasswordCard.tsx +0 -48
  415. package/src/client/sync/SecurityOptionsCard.tsx +0 -97
  416. package/src/client/sync/SyncSectionPickerDialog.tsx +0 -213
  417. package/src/ui/path-mapping.test.ts +0 -67
  418. package/src/ui/path-mapping.ts +0 -103
@@ -3,6 +3,7 @@
3
3
  */
4
4
  import { test } from 'node:test'
5
5
  import assert from 'node:assert/strict'
6
+ import { readFileSync } from 'node:fs'
6
7
 
7
8
  import {
8
9
  bundleLines, canLaunchProfile, copyWarningKey, dependencyLines, formatBytes, formatProfileTime,
@@ -212,6 +213,21 @@ test('profileInstallCommand / copyWarningKey:副本缺 node_modules 的自救
212
213
  assert.notEqual(profileInstallCommand('a'), restartCommand('a'), '安装命令与启动命令不是同一条')
213
214
  assert.equal(copyWarningKey('depsNotInstalled'), 'profiles.duplicate.warn.depsNotInstalled')
214
215
  })
216
+
217
+ test('copyWarningKey:未映射的告警码暴露为 undefined,不再套用 depsNotInstalled 文案(P10-4)', () => {
218
+ // 修复前 if + 兜底 return 同一字面量:任何入参都返回「缺 node_modules」文案,
219
+ // 于是新增告警码会被静默显示成错误原因。这里用类型逃逸模拟「未来新增的码」。
220
+ assert.equal(copyWarningKey('futureCode' as never), undefined, '未映射的码必须留白,而不是伪造原因')
221
+ // 穷尽性由 Record 的键类型保证(新增 DshProfileCopyWarning 而漏配 ⇒ typecheck 失败),
222
+ // 这里再锁一次机制本身:函数体只能是查表,不能退回手写兜底。
223
+ const src = readFileSync(new URL('./dsh-profiles-view.ts', import.meta.url), 'utf8')
224
+ assert.match(src, /const COPY_WARNING_KEY: Record<DshProfileCopyWarning, /, '映射表必须用 Record<告警码, …> 声明(穷尽性检查的来源)')
225
+ assert.match(
226
+ src,
227
+ /export function copyWarningKey[^}]*\{\s*return COPY_WARNING_KEY\[warning\]\s*\}/,
228
+ 'copyWarningKey 只能是查表:任何 return 字面量兜底都会重新引入「所有码都说缺 node_modules」',
229
+ )
230
+ })
215
231
  test('formatBytes:B / KB / MB 与非法输入', () => {
216
232
  assert.equal(formatBytes(0), '0 B')
217
233
  assert.equal(formatBytes(-5), '0 B')
@@ -176,12 +176,18 @@ export function suggestCopyName(name: string, existingNames: readonly string[],
176
176
  }
177
177
 
178
178
  /**
179
- * 复制告警码 → i18n key。目前只有 `depsNotInstalled` 一类(副本没带 node_modules 却声明了依赖),
180
- * 返回类型写成字面量联合:新增告警码时这里会编译报错,逼着补文案而不是静默吞掉。
179
+ * 复制告警码 → i18n key。目前只有 `depsNotInstalled` 一类(副本没带 node_modules 却声明了依赖)。
180
+ *
181
+ * 为什么是 `Record<告警码, 文案键>` 而不是 if + 兜底:原先 if 与兜底 return 同一字面量,
182
+ * 任何新告警码都会被静默显示成「缺 node_modules」的文案,注释里承诺的「新增码编译报错」
183
+ * 并不存在(审计 P10-4)。Record 的键即告警码全集 —— 码增删而映射不跟上就是编译错误。
181
184
  */
182
- export function copyWarningKey(warning: DshProfileCopyWarning): 'profiles.duplicate.warn.depsNotInstalled' {
183
- if (warning === 'depsNotInstalled') return 'profiles.duplicate.warn.depsNotInstalled'
184
- return 'profiles.duplicate.warn.depsNotInstalled'
185
+ const COPY_WARNING_KEY: Record<DshProfileCopyWarning, 'profiles.duplicate.warn.depsNotInstalled'> = {
186
+ depsNotInstalled: 'profiles.duplicate.warn.depsNotInstalled',
187
+ }
188
+
189
+ export function copyWarningKey(warning: DshProfileCopyWarning): (typeof COPY_WARNING_KEY)[DshProfileCopyWarning] {
190
+ return COPY_WARNING_KEY[warning]
185
191
  }
186
192
 
187
193
  /** 终端启动命令(非 web 形态没有浏览器界面,只能在终端用它拉起)。 */
@@ -14,9 +14,11 @@ import assert from 'node:assert/strict';
14
14
  import {
15
15
  FOREIGN_LOSSY_KINDS,
16
16
  FOREIGN_SKIP_KEY,
17
+ foreignAgentPrompt,
17
18
  foreignImportFailure,
18
19
  foreignLossyRows,
19
20
  foreignPathsText,
21
+ foreignProducedSkips,
20
22
  foreignSkipLine,
21
23
  foreignSourceRow,
22
24
  foreignSourcesViewModel,
@@ -352,3 +354,50 @@ test('foreign-view:导入失败按稳定码翻字典(skip 码 / nothing-to-i
352
354
  assert.equal(weird.code, null);
353
355
  assert.equal(weird.text, 'not an error');
354
356
  });
357
+
358
+ test('foreign-view:产包跳过项映射与 Agent 转换 Prompt 拼装(中英文跟随)', () => {
359
+ assert.deepEqual(foreignProducedSkips(null, zh), []);
360
+ assert.deepEqual(foreignProducedSkips([], zh), []);
361
+ const skips = foreignProducedSkips(
362
+ [
363
+ { code: 'unsupported-hooks', origin: 'settings.json', count: 2 },
364
+ { code: 'skill-missing-file', origin: 'foo-skill' },
365
+ ],
366
+ zh,
367
+ );
368
+ assert.equal(skips.length, 2);
369
+ assert.equal(skips[0]?.code, 'unsupported-hooks');
370
+ assert.equal(skips[0]?.origin, 'settings.json');
371
+ assert.equal(skips[0]?.count, 2);
372
+
373
+ // 无 skip 且无 failure → 空串
374
+ assert.equal(foreignAgentPrompt({ label: 'Claude Code', paths: ['.claude'], skips: [] }, zh), '');
375
+
376
+ const promptZh = foreignAgentPrompt(
377
+ {
378
+ label: 'Claude Code',
379
+ paths: ['.claude/settings.json', '.mcp.json'],
380
+ skips,
381
+ failure: { code: 'nothing-to-import', message: 'raw', text: zh('foreign.importNothing') },
382
+ },
383
+ zh,
384
+ );
385
+ assert.ok(promptZh.includes('Claude Code'));
386
+ assert.ok(promptZh.includes('.claude/settings.json, .mcp.json'));
387
+ assert.ok(promptZh.includes('nothing-to-import'));
388
+ assert.ok(promptZh.includes('[unsupported-hooks] (settings.json) ×2'));
389
+ assert.ok(promptZh.includes('[skill-missing-file] (foo-skill)'));
390
+
391
+ const promptEn = foreignAgentPrompt(
392
+ {
393
+ label: 'Claude Code',
394
+ paths: ['.claude/settings.json'],
395
+ skips: foreignProducedSkips([{ code: 'unsupported-hooks' }], en),
396
+ },
397
+ en,
398
+ );
399
+ assert.ok(promptEn.includes('Please help me convert the following Claude Code'));
400
+ assert.ok(promptEn.includes('Detected paths: .claude/settings.json'));
401
+ assert.ok(promptEn.includes('Items not migrated automatically:'));
402
+ assert.ok(promptEn.includes('[unsupported-hooks]'));
403
+ });
@@ -443,3 +443,50 @@ export function foreignImportFailure(err: unknown, t: UiT): ForeignImportFailure
443
443
  return { code, message, text: mapped === undefined ? message : t(mapped) }
444
444
  }
445
445
 
446
+ /* ------------------------------------------------ 产包跳过 & Agent Prompt */
447
+
448
+ /** 产包阶段的跳过项(POST /foreign-import 的 skipped)→ 可渲染行。 */
449
+ export function foreignProducedSkips(
450
+ skipped: readonly ForeignSkip[] | null | undefined,
451
+ t: UiT,
452
+ ): ForeignSkipLine[] {
453
+ if (!skipped || skipped.length === 0) return []
454
+ return skipped.map((s) => foreignSkipLine(s, t))
455
+ }
456
+
457
+ /** 构造外部转换任务 Prompt 的输入(用于一键复制给 Agent)。 */
458
+ export interface ForeignAgentPromptInput {
459
+ label: string
460
+ paths: readonly string[]
461
+ skips: readonly ForeignSkipLine[]
462
+ failure?: ForeignImportFailure | null
463
+ }
464
+
465
+ /**
466
+ * 把「检测路径 + 未自动迁移项 + 可选失败原因」组织成可直接贴进对话的 Agent 转换 Prompt。
467
+ * 既没有 skip 也没有 failure 时返回空串,避免渲染出一个空提示词复制动作。
468
+ */
469
+ export function foreignAgentPrompt(input: ForeignAgentPromptInput, t: UiT): string {
470
+ if (input.skips.length === 0 && (input.failure === undefined || input.failure === null)) return ''
471
+ const lines: string[] = [t('foreign.prompt.header', { source: input.label })]
472
+ if (input.paths.length > 0) {
473
+ lines.push(t('foreign.prompt.paths', { paths: input.paths.join(', ') }))
474
+ }
475
+ if (input.failure !== undefined && input.failure !== null) {
476
+ const reason = input.failure.code !== null
477
+ ? `${input.failure.code}: ${input.failure.text}`
478
+ : input.failure.text
479
+ lines.push(t('foreign.prompt.failure', { reason }))
480
+ }
481
+ if (input.skips.length > 0) {
482
+ lines.push(t('foreign.prompt.skips'))
483
+ for (const s of input.skips) {
484
+ const origin = s.origin !== undefined && s.origin !== '' ? ` (${s.origin})` : ''
485
+ const count = s.count !== undefined && s.count > 1 ? ` ×${String(s.count)}` : ''
486
+ lines.push(`- [${s.code}]${origin}${count} ${s.text}`)
487
+ }
488
+ }
489
+ return lines.join('\n')
490
+ }
491
+
492
+
package/src/ui/i18n.ts CHANGED
@@ -147,7 +147,6 @@ export const uiZh = {
147
147
  'snapshots.failed': '失败',
148
148
  'snapshots.skipped': '跳过',
149
149
  'snapshots.noActions': '该快照无可恢复动作(或全部跳过)。',
150
- 'snapshots.selectHint': '选择一个快照预览其恢复计划(只读预览,不会改动任何设置):',
151
150
  'snapshots.reportTitle': '恢复报告',
152
151
  // 同步区块(sync-view)
153
152
  'sync.privateRepoHint': '安全要求:同步仓库必须为私有仓库(public 仓库会公开你的配置内容)。认证 token 仅用于仓库访问,绝不写入同步文件、提交内容或日志。',
@@ -177,6 +176,8 @@ export const uiZh = {
177
176
  'sync.neverSyncedShort': '从未同步',
178
177
  'sync.pushFailed': '推送失败',
179
178
  'sync.pushOk': '推送成功(快照 {id})',
179
+ 'sync.pushSkipped': '内容未变化,已跳过(沿用远端快照 {id})',
180
+ 'sync.pushAllConflicted': '未推送任何分区:还有分区待冲突裁决(远端与基线都未改动)',
180
181
  'sync.conflictUnresolved': '冲突项 {id} 必须先选择解决方式(保留当前 / 使用导入)',
181
182
  'sync.pushPreviewHeadline': '将推送 {total} 个分区({changed} 个有变化)',
182
183
  'sync.pushPreviewEncrypted': '加密快照:载荷将整体加密,各分区相对基线的变化不可比对。',
@@ -266,6 +267,7 @@ export const uiZh = {
266
267
  'consult.loading': '正在生成咨询报告…',
267
268
  'diskUsage.title': '磁盘占用',
268
269
  'diskUsage.files': '{count} 个文件',
270
+ 'diskUsage.total': '合计 {size} · {files}',
269
271
  'diskUsage.refresh': '重新体检',
270
272
  'diskUsage.loading': '正在统计磁盘占用…',
271
273
  'diskUsage.unreadable': '未统计',
@@ -479,6 +481,11 @@ export const uiZh = {
479
481
  'foreign.lossy.entry-backslash.detail': 'ZIP 条目名里出现在中段的反斜杠不会被拒绝:同一个包在 Windows 目标上会被当作路径分隔符(落成多级目录),在 POSIX 目标上只是一个普通字符。本实现刻意不改这一格式行为;界面无法逐条检查条目名,跨平台导入后请核对这类文件是否落在预期位置。',
480
482
  'foreign.lossy.prompt-persona-reshape.title': 'prompts 的 systemPrompt 形状变化',
481
483
  'foreign.lossy.prompt-persona-reshape.detail': '源里的 systemPrompt 是字符串,导入落盘时写成带 persona 字段的对象:persona 文本无损,字段形状改变。兼容性评分不会为这一条给出原因 —— 它不改变内容,只改变形态。',
484
+ // 复制外部转换提示词(competitor-ui-review §5.2 #1)
485
+ 'foreign.prompt.header': '请帮我将以下 {source} 配置/会话转换为 DSH 可导入的格式:',
486
+ 'foreign.prompt.paths': '检测路径:{paths}',
487
+ 'foreign.prompt.skips': '未自动迁移项:',
488
+ 'foreign.prompt.failure': '失败原因:{reason}',
482
489
  // ---------- 英文界面零中文(t3):静态目录 / 纯逻辑层的文案 ----------
483
490
  // 导出分类目录的**描述**:静态目录(ui/export-flow.ts)只留键,渲染层用 t() 解析
484
491
  // (见 ExportCategory.descriptionKey)。此前这些中文硬编码在纯逻辑层。
@@ -648,7 +655,6 @@ export const uiEn: Record<UiTextKey, string> = {
648
655
  'snapshots.failed': 'Failed',
649
656
  'snapshots.skipped': 'Skipped',
650
657
  'snapshots.noActions': 'No restorable actions for this snapshot (or all skipped).',
651
- 'snapshots.selectHint': 'Select a snapshot to preview its restore plan (read-only preview, changes nothing):',
652
658
  'snapshots.reportTitle': 'Restore Report',
653
659
  'sync.privateRepoHint': 'Security requirement: the sync repository MUST be private (a public repo would expose your configuration). The auth token is only used for repository access and is never written into sync files, commit content, or logs.',
654
660
  'sync.kind.create': 'Create',
@@ -677,6 +683,8 @@ export const uiEn: Record<UiTextKey, string> = {
677
683
  'sync.neverSyncedShort': 'Never synced',
678
684
  'sync.pushFailed': 'Push failed',
679
685
  'sync.pushOk': 'Push succeeded (snapshot {id})',
686
+ 'sync.pushSkipped': 'No content changes — skipped (reusing remote snapshot {id})',
687
+ 'sync.pushAllConflicted': 'Nothing pushed: some sections still await conflict resolution (remote and baseline untouched)',
680
688
  'sync.conflictUnresolved': 'Conflict item {id} must be resolved first (keep current / use imported)',
681
689
  'sync.pushPreviewHeadline': 'Will push {total} {total, plural, section|sections} ({changed} changed)',
682
690
  'sync.pushPreviewEncrypted': 'Encrypted snapshot: the payload is encrypted as a whole; per-section changes vs the baseline cannot be compared.',
@@ -758,6 +766,7 @@ export const uiEn: Record<UiTextKey, string> = {
758
766
  'consult.loading': 'Generating consultation report…',
759
767
  'diskUsage.title': 'Disk Usage',
760
768
  'diskUsage.files': '{count} {count, plural, file|files}',
769
+ 'diskUsage.total': 'Total {size} · {files}',
761
770
  'diskUsage.refresh': 'Re-scan',
762
771
  'diskUsage.loading': 'Measuring disk usage…',
763
772
  'diskUsage.unreadable': 'not measured',
@@ -964,6 +973,10 @@ export const uiEn: Record<UiTextKey, string> = {
964
973
  'foreign.lossy.entry-backslash.detail': 'A backslash in the middle of a ZIP entry name is not rejected: the same bundle treats it as a path separator on Windows targets (creating extra directory levels) and as an ordinary character on POSIX targets. This format behaviour is left unchanged on purpose; the UI cannot inspect entry names one by one, so check where such files landed after a cross-platform import.',
965
974
  'foreign.lossy.prompt-persona-reshape.title': 'prompts systemPrompt changes shape',
966
975
  'foreign.lossy.prompt-persona-reshape.detail': 'A source systemPrompt is a string and is written back as an object with a persona field: the persona text is lossless, the field shape changes. The compatibility score gives no reason for this one because it changes the form, not the content.',
976
+ 'foreign.prompt.header': 'Please help me convert the following {source} configuration/sessions into a DSH-importable format:',
977
+ 'foreign.prompt.paths': 'Detected paths: {paths}',
978
+ 'foreign.prompt.skips': 'Items not migrated automatically:',
979
+ 'foreign.prompt.failure': 'Failure reason: {reason}',
967
980
  // --- English-UI zero-Chinese (t3): static catalogs / pure logic layer ---
968
981
  'export.category.settings': 'Global DSH settings (namespace sections, redacted)',
969
982
  'export.category.providers': 'LLM providers / models / default model / base URL',
@@ -72,7 +72,7 @@ export function placeMenu(anchor: Rect, bounds: Rect, menu: Size): MenuPlacement
72
72
  if (left + menu.width > bounds.right - MENU_EDGE) left = anchor.right - menu.width
73
73
  left = clampNumber(left, minLeft, maxLeft)
74
74
 
75
- // 垂直:下方优先;下方放不下且上方更宽裕 → 向上翻转(与 InfoHint 气泡同一判据)。
75
+ // 垂直:下方优先;下方放不下且上方更宽裕 → 向上翻转(与 Select 菜单同一判据)。
76
76
  const below = bounds.bottom - anchor.bottom - MENU_GAP - MENU_EDGE
77
77
  const above = anchor.top - bounds.top - MENU_GAP - MENU_EDGE
78
78
  const side: MenuPlacement['side'] = menu.height > below && above > below ? 'top' : 'bottom'
@@ -6,7 +6,7 @@ import assert from 'node:assert/strict';
6
6
  import { makeUiT } from './i18n.ts';
7
7
  import {
8
8
  consultView, consultVerdictBadgeKind, consultRecommendationBadgeKind,
9
- consultDimensionLabel, consultRecommendationLabel,
9
+ consultDimensionLabel, consultRecommendationLabel, consultScoreBadgeKind,
10
10
  dedupeConsultReasons, consultReasonGroups,
11
11
  } from './migration-consult-view.ts';
12
12
  import type { ConsultReport } from '../core/migration-consult.ts';
@@ -84,6 +84,25 @@ test('consult-view: verdict/recommendation badge kind 映射', () => {
84
84
  assert.equal(consultRecommendationLabel('block', t), '建议:阻止执行');
85
85
  });
86
86
 
87
+ test('consult-view: 维度分数配色按分数值派生(不跟 verdict 走)', () => {
88
+ // 稿 D-03:161-200:92/100/95 绿、82/74/60 橙 —— 分数 92 配 needs-attention 的 verdict 时
89
+ // 若沿用 badgeKind 会出现「92 分标橙」,所以按值分档。
90
+ assert.equal(consultScoreBadgeKind(100), 'ok');
91
+ assert.equal(consultScoreBadgeKind(90), 'ok');
92
+ assert.equal(consultScoreBadgeKind(89), 'warn');
93
+ assert.equal(consultScoreBadgeKind(70), 'warn');
94
+ assert.equal(consultScoreBadgeKind(69), 'error');
95
+ assert.equal(consultScoreBadgeKind(0), 'error');
96
+
97
+ const view = consultView(makeReport({
98
+ dimensions: [{ id: 'compatibility', score: 92, verdict: 'needs-attention', issues: [] }],
99
+ }), t);
100
+ const dim = view.dimensions[0];
101
+ assert.ok(dim !== undefined);
102
+ assert.equal(dim.badgeKind, 'warn');
103
+ assert.equal(dim.scoreKind, 'ok');
104
+ });
105
+
87
106
  /* ---------------- 建议依据:去重与分组 ---------------- */
88
107
 
89
108
  test('consult-reasons: dedupeConsultReasons 原文去重 + 保持首现顺序 + 丢弃空串/纯空白', () => {
@@ -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,
@@ -382,6 +382,20 @@ test('visibleUnits:真实规模展开即全量(UI-15 修正后);只有
382
382
  assert.equal(visibleUnits([], false).shown.length, 0)
383
383
  // 恰好等于上限:不折叠(边界)
384
384
  assert.equal(visibleUnits(huge.slice(0, UNIT_RENDER_LIMIT), false).hidden, 0)
385
+
386
+ // 数字分页:每增一页多渲染一个 limit 批,直到全部显示
387
+ const paged = Array.from({ length: 25 }, (_, i) => ({ id: `u:${i}`, label: `u-${i}`, sizeBytes: 1 }))
388
+ const page1 = visibleUnits(paged, 1, 10)
389
+ assert.equal(page1.shown.length, 10)
390
+ assert.equal(page1.hidden, 15)
391
+ const page2 = visibleUnits(paged, 2, 10)
392
+ assert.equal(page2.shown.length, 20)
393
+ assert.equal(page2.hidden, 5)
394
+ const page3 = visibleUnits(paged, 3, 10)
395
+ assert.equal(page3.shown.length, 25)
396
+ assert.equal(page3.hidden, 0)
397
+ // 0 或负数保护:退回第 1 页
398
+ assert.equal(visibleUnits(paged, 0, 10).shown.length, 10)
385
399
  })
386
400
 
387
401
  test('groupUnits:按分组名切块;无分组时退化为单块(其它分区渲染路径不变)', () => {
@@ -1032,6 +1046,20 @@ test('待补勾:清单没到齐时留在队列(绝不假装已勾),到
1032
1046
  assert.equal(pluginEntryPickState(done.selection, alpha), 'all')
1033
1047
  })
1034
1048
 
1049
+ test('samePendingChecks:队列内容等价即视为同一队列(审计 P9-1 回归,防 effect 自激)', () => {
1050
+ const a = [{ key: 'plugin-root', kind: 'root' as const }]
1051
+ // applyPluginPendingChecks 每轮返回新数组:内容相同必须判等,否则 setState → effect 自激
1052
+ assert.equal(samePendingChecks([...a], a), true, '同内容的两个数组必须判等')
1053
+ assert.equal(samePendingChecks(a, [{ key: 'plugin-root', kind: 'root' as const }]), true)
1054
+ assert.equal(samePendingChecks([], []), true)
1055
+ assert.equal(samePendingChecks(a, []), false, '长度不同不等')
1056
+ assert.equal(samePendingChecks(a, [{ key: 'other', kind: 'root' }]), false, 'key 不同不等')
1057
+ assert.equal(samePendingChecks(a, [{ key: 'plugin-root', kind: 'entry' }]), false, 'kind 不同不等')
1058
+ assert.equal(
1059
+ samePendingChecks([...a, ...a], a), false, '重复项也不等(长度不同)',
1060
+ )
1061
+ })
1062
+
1035
1063
  test('「插件」一级区块展开前要读的分区:插件清单自己没读到也要报(否则展开后没有读取入口)', () => {
1036
1064
  const nodes = treeNodes()
1037
1065
  // alpha 声明了一个大文件区域(该分区清单还没读)
@@ -147,14 +147,17 @@ export interface VisibleUnits {
147
147
  hidden: number
148
148
  }
149
149
 
150
- /** 单元列表渐进披露:默认只给前 limit 条,`showAll` 为 true 时全量。 */
150
+ /** 单元列表渐进披露:默认只给前 limit 条;传页数按 pages * limit 分页,传 true 全量。 */
151
151
  export function visibleUnits(
152
152
  units: readonly SelectionUnit[],
153
- showAll: boolean,
153
+ showAll: boolean | number,
154
154
  limit: number = UNIT_RENDER_LIMIT,
155
155
  ): VisibleUnits {
156
- if (showAll || units.length <= limit) return { shown: [...units], hidden: 0 }
157
- return { shown: units.slice(0, limit), hidden: units.length - limit }
156
+ if (showAll === true) return { shown: [...units], hidden: 0 }
157
+ const pages = typeof showAll === 'number' ? Math.max(1, Math.floor(showAll)) : 1
158
+ const cap = pages * limit
159
+ if (units.length <= cap) return { shown: [...units], hidden: 0 }
160
+ return { shown: units.slice(0, cap), hidden: units.length - cap }
158
161
  }
159
162
 
160
163
  /**
@@ -1312,6 +1315,24 @@ export function applyPluginPendingChecks(
1312
1315
  return { selection: out, remaining }
1313
1316
  }
1314
1317
 
1318
+ /**
1319
+ * 两条待补勾队列是否等价(同序、同 key、同 kind)。
1320
+ *
1321
+ * 为什么必须有它:`applyPluginPendingChecks` 每轮都返回**新数组**(内容可完全不变)。
1322
+ * 调用方若无条件写回 state,effect 依赖 [pendingChecks, …] 就会自激成无界重渲染
1323
+ * (清单读不到时队列永不出队 → 页面卡死,审计 P9-1)。
1324
+ */
1325
+ export function samePendingChecks(
1326
+ a: readonly PluginPendingCheck[],
1327
+ b: readonly PluginPendingCheck[],
1328
+ ): boolean {
1329
+ if (a.length !== b.length) return false
1330
+ for (let i = 0; i < a.length; i += 1) {
1331
+ if (a[i]!.key !== b[i]!.key || a[i]!.kind !== b[i]!.kind) return false
1332
+ }
1333
+ return true
1334
+ }
1335
+
1315
1336
  /** 勾上该插件前还需要读取哪些分区的清单(展开/点击时触发惰性读取)。 */
1316
1337
  export function pluginEntryUnreadSections(entry: PluginTreeEntry): SectionId[] {
1317
1338
  const out: SectionId[] = []
@@ -0,0 +1,14 @@
1
+ /**
2
+ * 记忆化一次异步读取:同一轮里多处要同一份状态时只读一次(issue #146 的扣下判定 + 推送后待裁决)。
3
+ *
4
+ * 为什么不是通用 memo:只服务「同一轮内必须看到**同一份**状态」这一个场景 —— 两处各读一次,
5
+ * 中间被别的进程改写就会出现「扣下的」与「剔除的」不是同一批(真机后果:待裁决记错分区)。
6
+ *
7
+ * 语义(务必看清):**reject 也被记忆化**。第一次失败后后续调用拿到同一个 rejected promise,
8
+ * 不会重试 —— 这正是「同一份状态」的本意,重试反而会看到两份。调用方一律在 catch 侧兜底
9
+ * (读不到就退化成安全的那一支),不要指望它替你重试。
10
+ */
11
+ export function memoAsync<T>(fn: () => Promise<T>): () => Promise<T> {
12
+ let pending: Promise<T> | undefined
13
+ return () => (pending ??= fn())
14
+ }
@@ -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
+ }