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
@@ -20,7 +20,10 @@ export interface ConsultDimensionView {
20
20
  label: string;
21
21
  score: number;
22
22
  verdict: HealthVerdict;
23
+ /** 维度名徽章的 kind(按 verdict,历史上用于整枚徽章着色) */
23
24
  badgeKind: ConsultBadgeKind;
25
+ /** 分数徽章的 kind(按分数档位派生 —— 稿上分数用绿/橙分色,与文字 verdict 无关) */
26
+ scoreKind: ConsultBadgeKind;
24
27
  issues: {
25
28
  severity: 'info' | 'warning' | 'error';
26
29
  message: string;
@@ -88,6 +91,14 @@ export declare function consultVerdictBadgeKind(v: HealthVerdict): ConsultBadgeK
88
91
  export declare function consultRecommendationBadgeKind(r: Recommendation): ConsultBadgeKind;
89
92
  /** 维度 label(i18n key 后缀) */
90
93
  export declare function consultDimensionLabel(id: ConsultDimensionId, t: UiT): string;
94
+ /**
95
+ * 维度分数 → 徽章 kind(稿 D-03:161-200 的分色口径,纯函数):
96
+ * ≥90 ok(绿)/ ≥70 warn(橙)/ 其余 error(红)。
97
+ *
98
+ * 为什么分数不再借用 verdict 的 kind:同一维度可能 verdict=warning 而分数 92(绿),
99
+ * 稿上颜色跟的是**分数**,把 verdict 色套到分数上会出现「92 分却标橙」的自相矛盾。
100
+ */
101
+ export declare function consultScoreBadgeKind(score: number): ConsultBadgeKind;
91
102
  /** 把 ConsultReport 转成视图数据(纯函数) */
92
103
  export declare function consultView(report: ConsultReport, t: UiT): ConsultView;
93
104
  /** recommendation 的可读标签 */
@@ -75,6 +75,20 @@ export function consultDimensionLabel(id, t) {
75
75
  case 'migratability': return t('consult.dim.migratability');
76
76
  }
77
77
  }
78
+ /**
79
+ * 维度分数 → 徽章 kind(稿 D-03:161-200 的分色口径,纯函数):
80
+ * ≥90 ok(绿)/ ≥70 warn(橙)/ 其余 error(红)。
81
+ *
82
+ * 为什么分数不再借用 verdict 的 kind:同一维度可能 verdict=warning 而分数 92(绿),
83
+ * 稿上颜色跟的是**分数**,把 verdict 色套到分数上会出现「92 分却标橙」的自相矛盾。
84
+ */
85
+ export function consultScoreBadgeKind(score) {
86
+ if (score >= 90)
87
+ return 'ok';
88
+ if (score >= 70)
89
+ return 'warn';
90
+ return 'error';
91
+ }
78
92
  /** 把 ConsultReport 转成视图数据(纯函数) */
79
93
  export function consultView(report, t) {
80
94
  const dimensions = report.dimensions.map((d) => ({
@@ -83,6 +97,7 @@ export function consultView(report, t) {
83
97
  score: d.score,
84
98
  verdict: d.verdict,
85
99
  badgeKind: consultVerdictBadgeKind(d.verdict),
100
+ scoreKind: consultScoreBadgeKind(d.score),
86
101
  issues: d.issues.map((i) => ({ severity: i.severity, message: i.message })),
87
102
  }));
88
103
  return {
@@ -130,6 +130,13 @@ export interface OverviewActivityItem {
130
130
  kindKey: string;
131
131
  /** 原始摘要(上层渲染前 redact())。 */
132
132
  summary: string;
133
+ /**
134
+ * P2(2026-11-14 真机事故):这一行点得动 —— 给它一个去处。
135
+ * 目前只有「待裁决」的自动同步轮次:冲突分区已经落进 sync-state.pendingMerge,
136
+ * 真正的裁决动作在同步页(那里有合并裁决视图),首页只负责把用户送过去。
137
+ * 无此字段 = 纯信息行(保持原样,不伪造交互)。
138
+ */
139
+ jumpTo?: 'sync';
133
140
  }
134
141
  /** 最近活动列表:按时间倒序取前 limit 条(kindKey 归一 + 徽章语义映射)。 */
135
142
  export declare function overviewActivity(history: OverviewHistoryLite[] | null, limit?: number): OverviewActivityItem[];
@@ -210,6 +210,9 @@ export function overviewActivity(history, limit = 5) {
210
210
  : 'warn',
211
211
  kindKey: overviewKindKey(e.kind),
212
212
  summary: e.summary,
213
+ // 待裁决 = 有具体分区等用户确认(宿主侧 pendingMerge)。首页不能只挂个颜色:
214
+ // 有去处才给入口,其余徽章保持不可点。
215
+ ...(e.kind === 'autosync' && e.result === 'pending' ? { jumpTo: 'sync' } : {}),
213
216
  }));
214
217
  }
215
218
  /** 空态判定:备份与快照均已加载且都为空 → 显示「开始保护你的配置」引导。 */
@@ -51,4 +51,13 @@ export declare function renderImportReport(result: ImportResult, t: UiT): string
51
51
  export declare function suggestedActions(_result: ImportResult): ImportResultAction[];
52
52
  /** 回滚报告渲染(full / partial + 人工恢复清单) */
53
53
  export declare function renderRollbackReport(rr: RollbackReport, t: UiT): string;
54
+ /**
55
+ * 字节 → 人类可读体积(B / KB / MB / GiB)。
56
+ *
57
+ * 口径与 `session-inventory-view.ts` 的 `formatSessionBytes` 对齐,但后缀沿用报告既有的
58
+ * KB/MB 写法(报告文本曾被测试与文档引用):
59
+ * - 非有限值(NaN/Infinity)或负数 → 空串:此前 `NaN` 会渲染成「NaN MB」,把缺数据
60
+ * 伪装成 0 体积之外的另一条假信息(审计 P10-2);
61
+ * - ≥1 GiB 单独一档:`2048.0 MB` 让用户自己换算,且 3 位数 MB 在报告行里最容易读错。
62
+ */
54
63
  export declare function formatBytes(n: number): string;
package/lib/ui/report.js CHANGED
@@ -41,9 +41,9 @@ export function renderExportReport(report, t) {
41
41
  const lines = [t('report.backupCreated'), ''];
42
42
  lines.push(t('report.included'));
43
43
  for (const { section, counts } of report.included) {
44
- const detail = Object.entries(counts)
45
- .map(([k, v]) => `${v} ${k}`)
46
- .join(', ');
44
+ // 计数文案与导出确认页同一份组装(`exportCountsText`):此前这里直接拼适配器词汇,
45
+ // 中文界面出现「settings (18 namespaces, 3 files)」这种半英文行(审计 P10-3)。
46
+ const detail = exportCountsText(counts, t);
47
47
  lines.push(` ✓ ${section}${detail !== '' ? ` (${detail})` : ''}`);
48
48
  }
49
49
  lines.push('');
@@ -217,11 +217,24 @@ export function renderRollbackReport(rr, t) {
217
217
  return lines.join('\n');
218
218
  }
219
219
  /* ---------------- 工具 ---------------- */
220
+ /**
221
+ * 字节 → 人类可读体积(B / KB / MB / GiB)。
222
+ *
223
+ * 口径与 `session-inventory-view.ts` 的 `formatSessionBytes` 对齐,但后缀沿用报告既有的
224
+ * KB/MB 写法(报告文本曾被测试与文档引用):
225
+ * - 非有限值(NaN/Infinity)或负数 → 空串:此前 `NaN` 会渲染成「NaN MB」,把缺数据
226
+ * 伪装成 0 体积之外的另一条假信息(审计 P10-2);
227
+ * - ≥1 GiB 单独一档:`2048.0 MB` 让用户自己换算,且 3 位数 MB 在报告行里最容易读错。
228
+ */
220
229
  export function formatBytes(n) {
230
+ if (!Number.isFinite(n) || n < 0)
231
+ return '';
221
232
  if (n < 1024)
222
233
  return `${n} B`;
223
234
  if (n < 1024 * 1024)
224
235
  return `${(n / 1024).toFixed(1)} KB`;
225
- return `${(n / (1024 * 1024)).toFixed(1)} MB`;
236
+ if (n < 1024 * 1024 * 1024)
237
+ return `${(n / (1024 * 1024)).toFixed(1)} MB`;
238
+ return `${(n / (1024 * 1024 * 1024)).toFixed(2)} GiB`;
226
239
  }
227
240
  //# sourceMappingURL=report.js.map
@@ -134,8 +134,8 @@ export interface VisibleUnits {
134
134
  /** 被折叠的单元数(0 = 已全部渲染) */
135
135
  hidden: number;
136
136
  }
137
- /** 单元列表渐进披露:默认只给前 limit 条,`showAll` 为 true 时全量。 */
138
- export declare function visibleUnits(units: readonly SelectionUnit[], showAll: boolean, limit?: number): VisibleUnits;
137
+ /** 单元列表渐进披露:默认只给前 limit 条;传页数按 pages * limit 分页,传 true 全量。 */
138
+ export declare function visibleUnits(units: readonly SelectionUnit[], showAll: boolean | number, limit?: number): VisibleUnits;
139
139
  /**
140
140
  * 中段省略(UI-16):用 `…` 收掉字符串**中段**,保留尾部 —— 会话名 / 路径 / 文件名
141
141
  * 的区分信息通常在尾部(时间戳、版本、扩展名),尾部截断会让两条记录看起来一模一样
@@ -519,5 +519,13 @@ export declare function applyPluginPendingChecks(sel: Selection, nodes: Selectio
519
519
  selection: Selection;
520
520
  remaining: PluginPendingCheck[];
521
521
  };
522
+ /**
523
+ * 两条待补勾队列是否等价(同序、同 key、同 kind)。
524
+ *
525
+ * 为什么必须有它:`applyPluginPendingChecks` 每轮都返回**新数组**(内容可完全不变)。
526
+ * 调用方若无条件写回 state,effect 依赖 [pendingChecks, …] 就会自激成无界重渲染
527
+ * (清单读不到时队列永不出队 → 页面卡死,审计 P9-1)。
528
+ */
529
+ export declare function samePendingChecks(a: readonly PluginPendingCheck[], b: readonly PluginPendingCheck[]): boolean;
522
530
  /** 勾上该插件前还需要读取哪些分区的清单(展开/点击时触发惰性读取)。 */
523
531
  export declare function pluginEntryUnreadSections(entry: PluginTreeEntry): SectionId[];
@@ -14,11 +14,15 @@ import { projectKeyOf, sessionIdKey } from '../core/session-select.js';
14
14
  * 真到上万条再谈虚拟化。
15
15
  */
16
16
  export const UNIT_RENDER_LIMIT = 1000;
17
- /** 单元列表渐进披露:默认只给前 limit 条,`showAll` 为 true 时全量。 */
17
+ /** 单元列表渐进披露:默认只给前 limit 条;传页数按 pages * limit 分页,传 true 全量。 */
18
18
  export function visibleUnits(units, showAll, limit = UNIT_RENDER_LIMIT) {
19
- if (showAll || units.length <= limit)
19
+ if (showAll === true)
20
20
  return { shown: [...units], hidden: 0 };
21
- return { shown: units.slice(0, limit), hidden: units.length - limit };
21
+ const pages = typeof showAll === 'number' ? Math.max(1, Math.floor(showAll)) : 1;
22
+ const cap = pages * limit;
23
+ if (units.length <= cap)
24
+ return { shown: [...units], hidden: 0 };
25
+ return { shown: units.slice(0, cap), hidden: units.length - cap };
22
26
  }
23
27
  /**
24
28
  * 中段省略(UI-16):用 `…` 收掉字符串**中段**,保留尾部 —— 会话名 / 路径 / 文件名
@@ -1008,6 +1012,22 @@ export function applyPluginPendingChecks(sel, nodes, tree, pending) {
1008
1012
  }
1009
1013
  return { selection: out, remaining };
1010
1014
  }
1015
+ /**
1016
+ * 两条待补勾队列是否等价(同序、同 key、同 kind)。
1017
+ *
1018
+ * 为什么必须有它:`applyPluginPendingChecks` 每轮都返回**新数组**(内容可完全不变)。
1019
+ * 调用方若无条件写回 state,effect 依赖 [pendingChecks, …] 就会自激成无界重渲染
1020
+ * (清单读不到时队列永不出队 → 页面卡死,审计 P9-1)。
1021
+ */
1022
+ export function samePendingChecks(a, b) {
1023
+ if (a.length !== b.length)
1024
+ return false;
1025
+ for (let i = 0; i < a.length; i += 1) {
1026
+ if (a[i].key !== b[i].key || a[i].kind !== b[i].kind)
1027
+ return false;
1028
+ }
1029
+ return true;
1030
+ }
1011
1031
  /** 勾上该插件前还需要读取哪些分区的清单(展开/点击时触发惰性读取)。 */
1012
1032
  export function pluginEntryUnreadSections(entry) {
1013
1033
  const out = [];
@@ -0,0 +1,11 @@
1
+ /**
2
+ * 记忆化一次异步读取:同一轮里多处要同一份状态时只读一次(issue #146 的扣下判定 + 推送后待裁决)。
3
+ *
4
+ * 为什么不是通用 memo:只服务「同一轮内必须看到**同一份**状态」这一个场景 —— 两处各读一次,
5
+ * 中间被别的进程改写就会出现「扣下的」与「剔除的」不是同一批(真机后果:待裁决记错分区)。
6
+ *
7
+ * 语义(务必看清):**reject 也被记忆化**。第一次失败后后续调用拿到同一个 rejected promise,
8
+ * 不会重试 —— 这正是「同一份状态」的本意,重试反而会看到两份。调用方一律在 catch 侧兜底
9
+ * (读不到就退化成安全的那一支),不要指望它替你重试。
10
+ */
11
+ export declare function memoAsync<T>(fn: () => Promise<T>): () => Promise<T>;
@@ -0,0 +1,15 @@
1
+ /**
2
+ * 记忆化一次异步读取:同一轮里多处要同一份状态时只读一次(issue #146 的扣下判定 + 推送后待裁决)。
3
+ *
4
+ * 为什么不是通用 memo:只服务「同一轮内必须看到**同一份**状态」这一个场景 —— 两处各读一次,
5
+ * 中间被别的进程改写就会出现「扣下的」与「剔除的」不是同一批(真机后果:待裁决记错分区)。
6
+ *
7
+ * 语义(务必看清):**reject 也被记忆化**。第一次失败后后续调用拿到同一个 rejected promise,
8
+ * 不会重试 —— 这正是「同一份状态」的本意,重试反而会看到两份。调用方一律在 catch 侧兜底
9
+ * (读不到就退化成安全的那一支),不要指望它替你重试。
10
+ */
11
+ export function memoAsync(fn) {
12
+ let pending;
13
+ return () => (pending ??= fn());
14
+ }
15
+ //# sourceMappingURL=async-once.js.map
@@ -0,0 +1,51 @@
1
+ import { type PatchChainRead } from '../core/patch-chain.ts';
2
+ /**
3
+ * patch 行改动的最小形状(`PatchFileFacade.applyPatchChanges` 的入参元素)。
4
+ *
5
+ * `forceTopLevel` = 「这一行必须落在**顶层**」:本层若还留着同名 insert 成员(0.9.0 写坏的存量),
6
+ * 光把 action 改成 update 不够 —— planPatchDocument 按**原文档归属**决定身份,insert 成员会
7
+ * 原地留着,于是同 id 仍是两条新增。置位后强制搬到顶层覆盖行。
8
+ */
9
+ export type PatchChangeLike = {
10
+ lineId: string;
11
+ raw: unknown;
12
+ action: 'insert' | 'update' | 'remove';
13
+ forceTopLevel?: boolean;
14
+ };
15
+ /**
16
+ * 生效链读取结果的短时缓存:一次导入会逐行写 patch,逐行重读 30+ 个 bundle patch 没有意义。
17
+ *
18
+ * 只按 TTL 命中还不够 —— 写盘之后必须 `invalidate()`,否则同一批次里「我刚写下的行」对后续
19
+ * 判定不可见(本层最终会同时出现在 insert 与顶层两种身份里)。
20
+ */
21
+ export declare class PatchChainCache {
22
+ private at;
23
+ private read;
24
+ private pending;
25
+ private readonly ttlMs;
26
+ constructor(ttlMs: number);
27
+ /** 丢弃缓存(写盘成功后调用)。 */
28
+ invalidate(): void;
29
+ get(load: () => Promise<PatchChainRead>, now?: number): Promise<PatchChainRead>;
30
+ }
31
+ /**
32
+ * 把「已被**别的层**提供」的 insert 改动降级成覆盖行。
33
+ *
34
+ * 顶层 `- id: X` 行只做覆盖:宿主 `entryMap` 查得到 X 就覆盖它的 config,查不到就整行丢弃;
35
+ * 只有 `- insert:` 块成员才新增条目。所以「X 已在链上」时必须写覆盖行,再写一份 insert 就
36
+ * 变成两条「新增」抢同一个 id —— 宿主 compose 后该条目取到没有 config 的那份,插件保存配置
37
+ * 时必然报 `Configuration for "X" is overridden by a home patch or command-line overlay`。
38
+ */
39
+ export declare function downgradeProvidedInserts<T extends PatchChangeLike>(chain: PatchChainRead | null, file: string, changes: readonly T[]): {
40
+ effective: T[];
41
+ downgraded: string[];
42
+ };
43
+ /** 读整条生效链:bundle 层按声明顺序在前,其后 profile 层、home 层(与宿主合并序一致)。 */
44
+ export declare function readPatchChainFromProfile(homeDir: string, profile: string): Promise<PatchChainRead>;
45
+ /**
46
+ * 读既有 patch 文件并解析:真不存在(ENOENT)或内容为空 → `undefined`。
47
+ *
48
+ * 读不出来 / 解析不了**必须抛错**(issue #75 的数据丢失点):调用方把失败当成空文档重建,
49
+ * 就等于删掉用户手写的其余行。
50
+ */
51
+ export declare function readExistingPatchDocument(path: string): Promise<unknown>;
@@ -0,0 +1,240 @@
1
+ /**
2
+ * 生效 patch 链的读取与写前判据(issue #144)—— 宿主合并序:bundle 层 → profile 层 → home 层。
3
+ *
4
+ * 为什么判据要看 bundle 层:DSH 启动时把每层 patch 依次 overlay 到同一份 plugin 树上,
5
+ * 「这个 id 已存在吗」是全链事实 —— 只看两个 patch 文件会把 bundle 已提供的 id 当成
6
+ * 「本机没有」,于是导入写出第二条 insert(issue #144 报错的成因)。
7
+ *
8
+ * 本模块是宿主侧 IO 壳:纯判据在 `core/patch-chain.ts`,这里只负责把三层读成文档,
9
+ * 并给写入路径提供「已存在则降级成覆盖行」的兜底。读不出来的层一律 fail-open(进 `failures`),
10
+ * 绝不因为一个装坏的 bundle 拒绝写入 —— 但**必须登记**,否则判据缺口会静默变成「确知没有」。
11
+ */
12
+ import fs from 'node:fs/promises';
13
+ import { resolve } from 'node:path';
14
+ import { patchChainIndex, providedByOtherLayers, } from '../core/patch-chain.js';
15
+ import { USER_PATCH_FILE, profilePatchRel } from '../core/patch-layers.js';
16
+ import { isENOENT } from './guards.js';
17
+ import { isSameOrChild } from './paths.js';
18
+ import { describePatchYamlError, loadPatchDocument } from './patch-yaml.js';
19
+ /**
20
+ * 生效链读取结果的短时缓存:一次导入会逐行写 patch,逐行重读 30+ 个 bundle patch 没有意义。
21
+ *
22
+ * 只按 TTL 命中还不够 —— 写盘之后必须 `invalidate()`,否则同一批次里「我刚写下的行」对后续
23
+ * 判定不可见(本层最终会同时出现在 insert 与顶层两种身份里)。
24
+ */
25
+ export class PatchChainCache {
26
+ at = 0;
27
+ read = null;
28
+ pending = null;
29
+ ttlMs;
30
+ constructor(ttlMs) {
31
+ this.ttlMs = ttlMs;
32
+ }
33
+ /** 丢弃缓存(写盘成功后调用)。 */
34
+ invalidate() {
35
+ this.at = 0;
36
+ this.read = null;
37
+ }
38
+ async get(load, now = Date.now()) {
39
+ if (this.read !== null && now - this.at < this.ttlMs)
40
+ return this.read;
41
+ // 并发首读只读一遍:同一次导入里多个分区同时问「这个 id 在吗」很常见
42
+ if (this.pending === null) {
43
+ this.pending = load().then((read) => {
44
+ this.at = now;
45
+ this.read = read;
46
+ this.pending = null;
47
+ return read;
48
+ }, (err) => {
49
+ this.pending = null;
50
+ throw err;
51
+ });
52
+ }
53
+ return this.pending;
54
+ }
55
+ }
56
+ /**
57
+ * 把「已被**别的层**提供」的 insert 改动降级成覆盖行。
58
+ *
59
+ * 顶层 `- id: X` 行只做覆盖:宿主 `entryMap` 查得到 X 就覆盖它的 config,查不到就整行丢弃;
60
+ * 只有 `- insert:` 块成员才新增条目。所以「X 已在链上」时必须写覆盖行,再写一份 insert 就
61
+ * 变成两条「新增」抢同一个 id —— 宿主 compose 后该条目取到没有 config 的那份,插件保存配置
62
+ * 时必然报 `Configuration for "X" is overridden by a home patch or command-line overlay`。
63
+ */
64
+ export function downgradeProvidedInserts(chain, file, changes) {
65
+ const effective = [...changes];
66
+ const downgraded = [];
67
+ if (chain === null)
68
+ return { effective, downgraded };
69
+ const byOther = providedByOtherLayers(patchChainIndex(chain), file);
70
+ if (byOther.size === 0)
71
+ return { effective, downgraded };
72
+ const out = effective.map((change) => {
73
+ if (change.action === 'remove')
74
+ return change;
75
+ const other = byOther.get(change.lineId);
76
+ // 只有「别的层以 insert(新增)提供」才会撞车:别的层若只是覆盖行,新增来源仍只有我们这一份
77
+ if (other === undefined || other.insertLayers.length === 0)
78
+ return change;
79
+ // 本层可能已经是 insert 成员(0.9.0 写坏的存量):只改 action 留不住位置,必须强制搬到顶层
80
+ if (change.action === 'insert')
81
+ downgraded.push(change.lineId);
82
+ return { ...change, action: 'update', forceTopLevel: true };
83
+ });
84
+ return { effective: out, downgraded };
85
+ }
86
+ /** 读整条生效链:bundle 层按声明顺序在前,其后 profile 层、home 层(与宿主合并序一致)。 */
87
+ export async function readPatchChainFromProfile(homeDir, profile) {
88
+ const sources = [];
89
+ const failures = [];
90
+ sources.push(...await readBundleLayerSources(homeDir, profile, failures));
91
+ for (const file of [profilePatchRel(profile), USER_PATCH_FILE]) {
92
+ try {
93
+ sources.push({ file, doc: loadPatchDocument(await fs.readFile(resolve(homeDir, file), 'utf8')) });
94
+ }
95
+ catch (err) {
96
+ // 真不存在 = 该层本来就没有(空文档);其余一律登记失败,绝不静默当空层
97
+ if (isENOENT(err)) {
98
+ sources.push({ file, doc: [] });
99
+ continue;
100
+ }
101
+ failures.push({ file, reason: describePatchYamlError(err) });
102
+ }
103
+ }
104
+ return { sources, failures };
105
+ }
106
+ /**
107
+ * 读 bundle 层的 patch 文档:`profiles/<p>/package.json` 的 `dsh.profile.bundles` →
108
+ * 每个包的 `dsh.bundle.patch`(字符串或有序字符串数组)→ 已解析文档。
109
+ *
110
+ * 声明顺序即合并顺序(宿主 bundlePatchFiles / bundlePatchPaths 同口径)。
111
+ */
112
+ async function readBundleLayerSources(homeDir, profile, failures) {
113
+ const sources = [];
114
+ const manifestRel = `profiles/${profile}/package.json`;
115
+ let manifest;
116
+ try {
117
+ manifest = JSON.parse(await fs.readFile(resolve(homeDir, manifestRel), 'utf8'));
118
+ }
119
+ catch (err) {
120
+ if (!isENOENT(err))
121
+ failures.push({ file: manifestRel, reason: describePatchYamlError(err) });
122
+ return sources;
123
+ }
124
+ const declared = manifest?.dsh?.profile?.bundles;
125
+ if (!Array.isArray(declared))
126
+ return sources;
127
+ for (const name of declared) {
128
+ if (typeof name !== 'string' || name === '')
129
+ continue;
130
+ // 清单来自远端快照:名字必须是合法的 npm 包名,否则 `resolve(node_modules, '../../..')` 会
131
+ // 把读取面带出 $DSH_HOME(链判据读的是文件内容,不该成为任意路径的探针)。
132
+ if (!isBundleName(name)) {
133
+ failures.push({ file: `bundles:${name}`, reason: 'illegal bundle name in profile manifest' });
134
+ continue;
135
+ }
136
+ const patches = await readBundlePatches(homeDir, profile, name, failures);
137
+ if (patches === null) {
138
+ failures.push({ file: `bundles:${name}`, reason: 'package not installed in this profile' });
139
+ continue;
140
+ }
141
+ sources.push(...patches);
142
+ }
143
+ return sources;
144
+ }
145
+ /** 合法 bundle 名:`name` 或 `@scope/name`,分段不得为空、`.`、`..`,不得含分隔符/盘符/NUL。 */
146
+ function isBundleName(name) {
147
+ if (name.includes('\0') || name.includes('\\') || name.startsWith('/') || /^[a-zA-Z]:/.test(name))
148
+ return false;
149
+ const parts = name.split('/');
150
+ if (parts.length === 0 || parts.length > 2)
151
+ return false;
152
+ if (parts.length === 2 && parts[0]?.startsWith('@') !== true)
153
+ return false;
154
+ return parts.every((part) => part !== '' && part !== '.' && part !== '..' && /^@?[A-Za-z0-9._-]+$/.test(part));
155
+ }
156
+ /**
157
+ * 一个 bundle 声明的全部 patch 文档;包不在本机任何已知 node_modules → `null`。
158
+ *
159
+ * 三个候选位置都是**真实布局**(漏掉就不会命中,而漏掉在 fail-open 下等于「这个 bundle 不存在」):
160
+ * 1. `profiles/<p>/node_modules` —— profile 私有安装;
161
+ * 2. `profiles/node_modules` —— pnpm hoisted 树(`nodeLinker: hoisted`,`@deepseek-ai/*` 在这);
162
+ * 3. `$DSH_HOME/node_modules` —— 早期 / 手工安装。
163
+ *
164
+ * 桌面端的 inbox bundle 只有 `app.asar` 内一份(磁盘上不存在),解析不到时如实进 `failures`。
165
+ */
166
+ async function readBundlePatches(homeDir, profile, name, failures) {
167
+ const candidates = [
168
+ resolve(homeDir, 'profiles', profile, 'node_modules', name),
169
+ resolve(homeDir, 'profiles', 'node_modules', name),
170
+ resolve(homeDir, 'node_modules', name),
171
+ ];
172
+ let pkgDir = null;
173
+ let manifest = null;
174
+ for (const dir of candidates) {
175
+ if (!isSameOrChild(dir, homeDir))
176
+ continue;
177
+ try {
178
+ manifest = JSON.parse(await fs.readFile(resolve(dir, 'package.json'), 'utf8'));
179
+ pkgDir = dir;
180
+ break;
181
+ }
182
+ catch (err) {
183
+ // 不存在 → 试下一个候选;存在但读不出/解析不了 → 登记后**不再 fallback**
184
+ // (换用另一个副本会拿错版本的 patch 清单,判据悄悄变味)
185
+ if (isENOENT(err))
186
+ continue;
187
+ failures.push({ file: `bundles:${name}/package.json`, reason: describePatchYamlError(err) });
188
+ return null;
189
+ }
190
+ }
191
+ if (pkgDir === null)
192
+ return null;
193
+ const patch = manifest?.dsh?.bundle?.patch;
194
+ const files = typeof patch === 'string' ? [patch] : patch;
195
+ if (patch !== undefined && (typeof patch !== 'string' && !Array.isArray(patch) || Array.isArray(patch) && !patch.every((file) => typeof file === 'string'))) {
196
+ failures.push({ file: `bundles:${name}`, reason: 'dsh.bundle.patch must be a string or string[]' });
197
+ return [];
198
+ }
199
+ if (!Array.isArray(files))
200
+ return [];
201
+ const sources = [];
202
+ for (const rel of files) {
203
+ const file = 'bundles:' + name + '/' + rel.replace(/\\/g, '/');
204
+ const abs = resolve(pkgDir, rel);
205
+ // 声明里的路径越界(../..)→ 直接忽略该文件:链判据不该读包外的东西
206
+ if (!isSameOrChild(abs, pkgDir)) {
207
+ failures.push({ file, reason: 'patch path escapes the bundle directory' });
208
+ continue;
209
+ }
210
+ try {
211
+ sources.push({ file, doc: loadPatchDocument(await fs.readFile(abs, 'utf8')) });
212
+ }
213
+ catch (err) {
214
+ // 单个 patch 文件读不出来 = 该 bundle 在这条链上不提供 id,但判据缺口必须可见
215
+ failures.push({ file, reason: describePatchYamlError(err) });
216
+ }
217
+ }
218
+ return sources;
219
+ }
220
+ /**
221
+ * 读既有 patch 文件并解析:真不存在(ENOENT)或内容为空 → `undefined`。
222
+ *
223
+ * 读不出来 / 解析不了**必须抛错**(issue #75 的数据丢失点):调用方把失败当成空文档重建,
224
+ * 就等于删掉用户手写的其余行。
225
+ */
226
+ export async function readExistingPatchDocument(path) {
227
+ let text;
228
+ try {
229
+ text = await fs.readFile(path, 'utf8');
230
+ }
231
+ catch (err) {
232
+ if (isENOENT(err))
233
+ return undefined;
234
+ throw err;
235
+ }
236
+ if (text.trim() === '')
237
+ return undefined;
238
+ return loadPatchDocument(text);
239
+ }
240
+ //# sourceMappingURL=patch-chain-read.js.map
@@ -13,8 +13,46 @@ export declare const PATCH_YAML_SCHEMA: import("js-yaml").Schema;
13
13
  * 「当作空文档、把用户的整层配置抹掉」。
14
14
  */
15
15
  export declare function loadPatchDocument(text: string): unknown;
16
- /** 写回 patch 文档:`{__jsExpr}` 还原成 `!!js`,其余按 DSH 的 schema 打印。 */
16
+ /**
17
+ * 写回 patch 文档:`{__jsExpr}` 还原成 `!!js`,字符串一律带引号(issue #135)。
18
+ *
19
+ * `forceQuotes` 不是风格偏好,而是**跨大版本读回的前提**:本插件装在 js-yaml 5.x 上打印,
20
+ * DSH 本体用 4.x 读回(桌面版随包 4.3.2)。5.x 的渲染器只按自己的解析规则决定要不要加引号,
21
+ * 于是 `""` `Null` `~` `True` `007` `0x10` `.inf` 这类**字符串**被写成裸标量,
22
+ * 4.x 按 YAML 1.1 隐式解析成 `null` / `true` / `7` / `16` / `Infinity` —— 两边读到不同的值,
23
+ * 把该字段声明为必填 string 的插件启动时直接 ZodError。
24
+ *
25
+ * 代价(已知且接受):字符串值普遍带引号;普通多行字符串从 `|` 块退化为双引号 + `\n`
26
+ * (`!!js` 的块标量带标签,不受影响)。只影响写出去的字节,读侧语义不变:
27
+ * 已经写成空标量的历史文件仍由 `loadPatchDocument` 读成 `""`,该层下次被写回时自动复原。
28
+ */
17
29
  export declare function dumpPatchDocument(value: unknown): string;
30
+ /**
31
+ * 键名在 DSH 读端(js-yaml 4.x)的**改判**形态。
32
+ *
33
+ * 为什么需要单独一层检查:`forceQuotes`(issue #135)只保**值**,键名是 js-yaml 自己决定加不加
34
+ * 引号的 —— 5.x 只给「YAML 1.2 会改判」的键加引号,1.1-only 的形态(`007`、`True`、`.5`、`~`)
35
+ * 一律裸写,于是 4.x 把键读成 `7` / `true` / `0.5` / `null`:配置静默改名,插件读不到自己的键。
36
+ * 空键名更糟 —— `: 'v'` 会让 4.x **整份文件解析失败**(该层所有行一起失效)。
37
+ */
38
+ export type PatchKeyHazardEffect = 'parse-fail' | 'rename';
39
+ /** 一处键名风险。 */
40
+ export interface PatchKeyHazard {
41
+ /** 键所在容器的路径(`''` = 顶层;数组元素记作 `items[3]`) */
42
+ path: string;
43
+ /** 出问题的键名原文(空串 = 空键名) */
44
+ key: string;
45
+ /** `parse-fail` = 4.x 整份文件解析失败;`rename` = 键被改判成数字 / 布尔 / null */
46
+ effect: PatchKeyHazardEffect;
47
+ }
48
+ /**
49
+ * 找出一个 patch 行里**会跨大版本读坏**的键名(issue #137)。
50
+ *
51
+ * 只扫键、不扫值(值由 `dumpPatchDocument` 的 `forceQuotes` 兜住);`{__jsExpr}` 是本模块的
52
+ * 内存形态不是用户键名,整棵子树跳过;YAML 锚点可以造环,同一对象只走一次。
53
+ * 返回空数组 = 这一行写出去 4.x / 5.x 读到的键名一致。
54
+ */
55
+ export declare function findPatchKeyHazards(value: unknown): PatchKeyHazard[];
18
56
  /**
19
57
  * 解析报错的**安全摘要**:只取首行。
20
58
  *