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
@@ -29,18 +29,21 @@ import type { TranslateNS } from '../client-types.ts'
29
29
  import type { ConfigManagerApi, ForeignImportResponse } from '../api.ts'
30
30
  import type { UiT } from '../../ui/i18n.ts'
31
31
  import {
32
+ foreignAgentPrompt,
32
33
  foreignImportFailure,
33
34
  foreignLossyRows,
34
35
  foreignPathsText,
36
+ foreignProducedSkips,
35
37
  foreignSourcesViewModel,
36
38
  type ForeignImportFailure,
37
39
  type ForeignSourceRow,
38
40
  } from '../../ui/foreign-view.ts'
39
41
  import { Badge, Banner, Button, Card, SectionTitle } from '../common/ui.tsx'
42
+ import { CopyButton } from '../common/CopyButton.tsx'
40
43
  import { SkeletonList } from '../common/Skeleton.tsx'
41
- import { InfoHint } from '../common/InfoHint.tsx'
42
44
  import { ErrorBanner } from '../common/ErrorBanner.tsx'
43
45
  import { redact } from '../../security/redaction.ts'
46
+ import { sectionLabeler } from '../common/section-labels.ts'
44
47
  import css from '../config-manager.module.css'
45
48
 
46
49
  export interface ForeignImportViewProps {
@@ -146,6 +149,8 @@ export function ForeignImportView({ api, t, uiT, onReady }: ForeignImportViewPro
146
149
  }, [api, uiT, tick])
147
150
 
148
151
  const rows = vm?.rows ?? []
152
+ const selectedRow = rows.find((r) => r.id === selected) ?? null
153
+ const producedSkips = foreignProducedSkips(produced?.skipped, uiT)
149
154
  /**
150
155
  * 三类已知有损的展示行(F-5):尚未产包时 applicable=null(界面不渲染适用性徽章),
151
156
  * 产包后按包内分区逐条标注是否适用。判定全在 src/ui/foreign-view.ts 的纯函数里。
@@ -211,7 +216,7 @@ export function ForeignImportView({ api, t, uiT, onReady }: ForeignImportViewPro
211
216
 
212
217
  return (
213
218
  <div className={css.viewBody}>
214
- <SectionTitle title={t('foreign.source.title')} info={<InfoHint text={t('foreign.source.hint')} label={t('common.infoHint')} />} />
219
+ <SectionTitle title={t('foreign.source.title')} tooltip={t('foreign.source.hint')} />
215
220
 
216
221
  {loadError !== null && (
217
222
  <ErrorBanner
@@ -255,7 +260,7 @@ export function ForeignImportView({ api, t, uiT, onReady }: ForeignImportViewPro
255
260
  **位置**:来源列表之后、动作行(含「开始导入」)之前 —— 既保证「导入前必读」,
256
261
  又不把六个来源挤出首屏(t10 的 T10-F2 真机体验反馈)。 */}
257
262
  <Card>
258
- <div className={css.groupLabel}>{t('foreign.lossy.title')} <InfoHint text={t('foreign.lossy.hint')} label={t('common.infoHint')} /></div>
263
+ <div className={css.groupLabel} title={t('foreign.lossy.hint')}>{t('foreign.lossy.title')}</div>
259
264
  <ul className={css.skipList}>
260
265
  {lossyRows.map((row) => (
261
266
  <li key={row.kind} className={css.skipRow}>
@@ -264,7 +269,8 @@ export function ForeignImportView({ api, t, uiT, onReady }: ForeignImportViewPro
264
269
  {row.applicable ? t('foreign.lossy.applies') : t('foreign.lossy.notApplies')}
265
270
  </Badge>
266
271
  )}
267
- <span className={css.skipText}>
272
+ {/* detail 在窄画布上会被折行截断(T-03 剩余缺陷):title 兜住完整原文,不加布局、不加 CSS。 */}
273
+ <span className={css.skipText} title={redact(row.detail)}>
268
274
  <strong>{redact(row.title)}</strong>{' '}
269
275
  {redact(row.detail)}
270
276
  </span>
@@ -275,12 +281,20 @@ export function ForeignImportView({ api, t, uiT, onReady }: ForeignImportViewPro
275
281
 
276
282
  {/* 选中来源的未迁移项:**在选它之后**才展开,避免六来源的码堆在一起淹没有效信息 */}
277
283
  {(() => {
278
- const row = rows.find((r) => r.id === selected) ?? null
284
+ const row = selectedRow
279
285
  if (row === null || row.skips.length === 0) return null
280
286
  return (
281
287
  <Card>
282
- <div className={css.groupLabel}>
283
- {t('foreign.skipped', { count: String(row.skips.length) })}
288
+ <div className={css.headRow}>
289
+ <div className={css.groupLabel}>
290
+ {t('foreign.skipped', { count: String(row.skips.length) })}
291
+ </div>
292
+ <span className={css.statusSpacer} />
293
+ <CopyButton
294
+ text={foreignAgentPrompt({ label: row.label, paths: row.paths, skips: row.skips }, uiT)}
295
+ label={t('foreign.copyAgentPrompt')}
296
+ t={t}
297
+ />
284
298
  </div>
285
299
  <ul className={css.skipList}>
286
300
  {row.skips.map((s, i) => (
@@ -303,15 +317,44 @@ export function ForeignImportView({ api, t, uiT, onReady }: ForeignImportViewPro
303
317
  {/* 产包结果(成功后才出现):让用户在进向导前先看到「包里有什么」 */}
304
318
  {produced !== null && (
305
319
  <Card>
306
- <div className={css.groupLabel}>{t('foreign.previewTitle')} <InfoHint text={t('foreign.previewDryRun')} label={t('common.infoHint')} /></div>
320
+ <div className={css.groupLabel}>{t('foreign.previewTitle')} <span className={css.hint}>{t('foreign.previewDryRun')}</span></div>
307
321
  <div className={css.statRow}>
308
322
  <Badge kind="ok">
309
- {t('foreign.previewSections', { sections: produced.sections.join(' · ') })}
323
+ {t('foreign.previewSections', { sections: produced.sections.map(sectionLabeler(t)).join(' · ') })}
310
324
  </Badge>
311
325
  {produced.credentialRefs.length > 0
312
326
  ? <Badge kind="warn">{t('foreign.credentialRefs', { count: String(produced.credentialRefs.length) })}</Badge>
313
327
  : <Badge kind="info">{t('foreign.credentialRefsNone')}</Badge>}
314
328
  </div>
329
+ {producedSkips.length > 0 && (
330
+ <>
331
+ <div className={css.headRow}>
332
+ <div className={css.groupLabel}>
333
+ {t('foreign.skipped', { count: String(producedSkips.length) })}
334
+ </div>
335
+ <span className={css.statusSpacer} />
336
+ <CopyButton
337
+ text={foreignAgentPrompt({
338
+ label: selectedRow?.label ?? redact(produced.source),
339
+ paths: produced.detectedPaths,
340
+ skips: producedSkips,
341
+ }, uiT)}
342
+ label={t('foreign.copyAgentPrompt')}
343
+ t={t}
344
+ />
345
+ </div>
346
+ <ul className={css.skipList}>
347
+ {producedSkips.map((s, i) => (
348
+ <SkipLine
349
+ key={s.code + '-' + String(i)}
350
+ code={s.code}
351
+ text={redact(s.text)}
352
+ meta={s.origin !== undefined ? redact(s.origin) : (s.count !== undefined ? String(s.count) : '')}
353
+ />
354
+ ))}
355
+ </ul>
356
+ </>
357
+ )}
315
358
  </Card>
316
359
  )}
317
360
 
@@ -320,6 +363,21 @@ export function ForeignImportView({ api, t, uiT, onReady }: ForeignImportViewPro
320
363
  {t('foreign.importFailed', { reason: redact(importFailure.text) })}
321
364
  {/* 稳定码保留给排查/上报:文案是人话,码是可搜索的锚点(未知码时它就是唯一信息) */}
322
365
  {importFailure.code !== null && <span className={css.skipCode}>{importFailure.code}</span>}
366
+ {selectedRow !== null && (
367
+ <>
368
+ <span className={css.statusSpacer} />
369
+ <CopyButton
370
+ text={foreignAgentPrompt({
371
+ label: selectedRow.label,
372
+ paths: selectedRow.paths,
373
+ skips: selectedRow.skips,
374
+ failure: importFailure,
375
+ }, uiT)}
376
+ label={t('foreign.copyAgentPrompt')}
377
+ t={t}
378
+ />
379
+ </>
380
+ )}
323
381
  </Banner>
324
382
  )}
325
383
 
@@ -41,6 +41,7 @@ import {
41
41
  } from '../../ui/session-format-disposition.ts'
42
42
  import type { ImportPreviewSummary } from '../../ui/types.ts'
43
43
  import type { ImportAnalysis, ImportPlan, ImportResult } from '../../core/types.ts'
44
+ import type { SectionId } from '../../schema/types.ts'
44
45
  import type { UiT } from '../../ui/i18n.ts'
45
46
  import type { ConfigManagerApi } from '../api.ts'
46
47
  import type { TranslateNS } from '../client-types.ts'
@@ -48,7 +49,6 @@ import { runStore } from '../run-store.ts'
48
49
  import {
49
50
  Badge, Banner, Button, Card, SectionTitle, Stepper,
50
51
  } from '../common/ui.tsx'
51
- import { InfoHint } from '../common/InfoHint.tsx'
52
52
  import { ErrorBanner, ErrorList } from '../common/ErrorBanner.tsx'
53
53
  import { ProgressBar } from '../common/ProgressBar.tsx'
54
54
  import type { RunProgress } from '../common/progress-view.ts'
@@ -105,7 +105,7 @@ function NextStepsCard({ plan, result, t }: {
105
105
  <ul className={`${css.reportList} ${css.nextStepsList}`}>
106
106
  {steps.restartItems.map((item) => (
107
107
  // description 由宿主按计划项拼装(可能含 MCP env/headers 等本地配置片段)→ 渲染前过 redact
108
- <li key={item.id}>{item.adapter}: {redact(item.description)}</li>
108
+ <li key={item.id}>{sectionLabel(item.adapter as SectionId, t)}: {redact(item.description)}</li>
109
109
  ))}
110
110
  </ul>
111
111
  </div>
@@ -150,7 +150,7 @@ function CompatibilityStep(props: {
150
150
  const notes = compatibilityNotes(analysis.compatibilityReasons)
151
151
  return (
152
152
  <div className={css.viewBody}>
153
- <SectionTitle title={t('import.compatibility.title')} />
153
+ <SectionTitle title={t('import.compatibility.title')} tooltip={t('import.compatibility.hint')} />
154
154
  <div className={css.statRow}>
155
155
  <Badge kind={compatibilityBadgeKind(level)}>
156
156
  {t('import.compatibility.score', { score: t(scoreKey) })}
@@ -263,7 +263,7 @@ function ContentSelectStage(props: {
263
263
  } = props
264
264
  return (
265
265
  <div className={css.viewBody}>
266
- <SectionTitle title={t('import.picker.title')} info={<InfoHint text={t('import.picker.hint')} label={t('common.infoHint')} />} />
266
+ <SectionTitle title={t('import.picker.title')} tooltip={t('import.picker.hint')} />
267
267
  <div className={css.statRow}>
268
268
  <Badge kind={summary.willChange > 0 ? 'info' : 'ok'}>{t('import.preview.willChange', { count: String(summary.willChange) })}</Badge>
269
269
  {summary.unchanged > 0 && <Badge kind="ok">{t('import.preview.unchanged', { count: String(summary.unchanged) })}</Badge>}
@@ -1,16 +1,16 @@
1
1
  /**
2
2
  * 路径映射表单(规范 §12,绑 src/ui/types.ts 的 PathMappingDraft 形状)。
3
3
  *
4
- * 注意:src/ui/path-mapping.ts 的 PathMappingEditor 依赖 utils/paths.ts 的
5
- * applyPrefixMappings(node:path)——浏览器 bundle 不可用,故此处做轻量等价实现:
6
- * 输入输出形状与 core 的 PathMapping 完全一致(oldPrefix/newPrefix/appliesTo),
7
- * 实际前缀替换由 Host 侧 core 在 createImportPlan 阶段执行,本组件只负责收集用户输入。
4
+ * 浏览器半不能引 node:path,所以这里只做「收集用户输入」:输入输出形状与 core 的
5
+ * PathMapping 完全一致(oldPrefix/newPrefix/appliesTo),实际前缀替换由 Host 侧 core 在
6
+ * createImportPlan 阶段执行。此前另有一份 src/ui/path-mapping.ts 的同规则实现(依赖
7
+ * utils/paths.ts),生产零引用,已删(审计 P10-6:同一规则只留一处)。
8
8
  */
9
9
  import { useMemo, useState } from 'react'
10
10
  import type { ChangeEvent } from 'react'
11
11
  import type { PathIssue, PathMapping } from '../../core/types.ts'
12
12
  import type { TranslateNS } from '../client-types.ts'
13
- import { Banner, IconButton } from '../common/ui.tsx'
13
+ import { Banner, Button, IconButton } from '../common/ui.tsx'
14
14
  import { FolderOpenIcon } from '../common/Icon.tsx'
15
15
  import { PathPickerDialog } from './PathPickerDialog.tsx'
16
16
  import type { PathBrowsePort } from './PathPickerDialog.tsx'
@@ -53,15 +53,35 @@ export function PathMappingForm({ issues, initial, t, onChange, api }: PathMappi
53
53
  return out
54
54
  })
55
55
 
56
- const setNewPrefix = (oldPrefix: string, value: string): void => {
57
- const next = { ...drafts, [oldPrefix]: value }
56
+ const commitDrafts = (next: Record<string, string>): void => {
58
57
  setDrafts(next)
59
58
  const mappings: PathMapping[] = Object.entries(next)
60
- .filter(([, v]) => v !== '')
61
- .map(([oldPrefix, newPrefix]) => ({ oldPrefix, newPrefix, appliesTo: [] }))
59
+ .filter(([, v]) => v.trim() !== '')
60
+ .map(([oldPrefix, newPrefix]) => ({ oldPrefix, newPrefix: newPrefix.trim(), appliesTo: [] }))
62
61
  onChange(mappings)
63
62
  }
64
63
 
64
+ const setNewPrefix = (oldPrefix: string, value: string): void => {
65
+ commitDrafts({ ...drafts, [oldPrefix]: value })
66
+ }
67
+
68
+ const suggestedIssues = issues.filter(
69
+ (issue) =>
70
+ typeof issue.mappedTo === 'string' &&
71
+ issue.mappedTo.trim() !== '' &&
72
+ (drafts[issue.value] ?? '').trim() === '',
73
+ )
74
+
75
+ const applySuggested = (): void => {
76
+ const next = { ...drafts }
77
+ for (const issue of suggestedIssues) {
78
+ if (typeof issue.mappedTo === 'string' && issue.mappedTo.trim() !== '') {
79
+ next[issue.value] = issue.mappedTo
80
+ }
81
+ }
82
+ commitDrafts(next)
83
+ }
84
+
65
85
  /**
66
86
  * 文件夹按钮的完整动作,三层降级,任一层拿到绝对路径就回填:
67
87
  * ① **DSH 宿主自带**的目录选择器(就是「选择工作区目录」那个原生窗口,跟着宿主主进程走,最稳);
@@ -102,6 +122,13 @@ export function PathMappingForm({ issues, initial, t, onChange, api }: PathMappi
102
122
  {unresolved.length > 0 && (
103
123
  <Banner kind="info">{t('import.paths.unresolved', { count: String(unresolved.length) })}</Banner>
104
124
  )}
125
+ {suggestedIssues.length > 0 && (
126
+ <div className={css.actionRow}>
127
+ <Button size="sm" variant="ghost" onClick={applySuggested}>
128
+ {t('import.paths.applySuggested')}
129
+ </Button>
130
+ </div>
131
+ )}
105
132
  {issues.length === 0 && <div className={css.empty}>{t('import.paths.empty')}</div>}
106
133
  {issues.map((issue) => (
107
134
  <div key={issue.value} className={css.pathRow}>
@@ -22,6 +22,7 @@ import type { BrowseErrorCode, BrowseResult } from '../../core/path-browse.ts'
22
22
  import type { ConfigManagerApi } from '../api.ts'
23
23
  import type { TranslateNS } from '../client-types.ts'
24
24
  import { Modal } from '../common/Modal.tsx'
25
+ import { redact } from '../../security/redaction.ts'
25
26
  import { Banner, Button, Spinner } from '../common/ui.tsx'
26
27
  import { FileIcon, FolderIcon } from '../common/Icon.tsx'
27
28
  import css from '../config-manager.module.css'
@@ -100,7 +101,7 @@ export function PathPickerDialog({ open, api, t, startPath, onPick, onClose }: P
100
101
  },
101
102
  (error: unknown) => {
102
103
  if (!alive) return
103
- setState({ kind: 'failed', detail: error instanceof Error ? error.message : String(error) })
104
+ setState({ kind: 'failed', detail: redact(error instanceof Error ? error.message : String(error)) })
104
105
  },
105
106
  )
106
107
  return () => { alive = false }
@@ -82,7 +82,7 @@ test('t45/t50: 脱敏登记渲染点必须留在主文件(或日志面板模
82
82
  /import \{ redact \} from '\.\.\/\.\.\/security\/redaction\.ts'/,
83
83
  'tests/client/import-wizard-redaction.test.ts 要求主文件 import redact',
84
84
  )
85
- assert.match(view, /\{item\.adapter\}: \{redact\(item\.description\)\}<\/li>/, '收尾清单登记点必须留在主文件')
85
+ assert.match(view, /\{sectionLabel\(item\.adapter as SectionId, t\)\}: \{redact\(item\.description\)\}<\/li>/, '收尾清单登记点必须留在主文件')
86
86
  assert.match(view, /\{analysis\.warnings\.map\(\(w, i\) => <div key=\{i\}>\{redact\(w\)\}<\/div>\)\}/, '分析告警登记点必须留在主文件')
87
87
  // 2026-09:日志改为「合并后的项状态行 + 明细行」,两处脱敏渲染点在日志面板模块内
88
88
  // (同点登记见 src/client/common/plan-text-redaction.test.ts 的 import-log-* 两条)
@@ -17,7 +17,7 @@ import {
17
17
  Badge, Banner, Button, Card, Checkbox, Empty, SectionTitle,
18
18
  } from '../common/ui.tsx'
19
19
  import { Skeleton } from '../common/Skeleton.tsx'
20
- import { InfoHint } from '../common/InfoHint.tsx'
20
+ import { ImportIcon } from '../common/Icon.tsx'
21
21
  import { ErrorBanner, ErrorList } from '../common/ErrorBanner.tsx'
22
22
  import { CopyButton } from '../common/CopyButton.tsx'
23
23
  import {
@@ -101,7 +101,7 @@ export function SelectStep(props: {
101
101
  const { fileInput, selectModel, uploading, error, onCancel, onPickFile, onReset, apiT, t } = props
102
102
  return (
103
103
  <div className={`${css.viewBody} ${css.sparseFill}`}>
104
- <SectionTitle title={t('import.select.title')} info={<InfoHint text={t('import.select.hint')} label={t('common.infoHint')} />} />
104
+ <SectionTitle title={t('import.select.title')} tooltip={t('import.select.hint')} />
105
105
  <input
106
106
  ref={fileInput}
107
107
  type="file"
@@ -113,6 +113,18 @@ export function SelectStep(props: {
113
113
  void onPickFile(file)
114
114
  }}
115
115
  />
116
+ {/* 投放容器(W3 R-1):只承载图标与主按钮,不做拖拽(宿主没有 drop 能力,
117
+ 写「拖拽到此处」就是承诺做不到的事);点击目标仍是那颗唯一的主按钮。 */}
118
+ <div className={css.dropZone}>
119
+ <ImportIcon size={22} className={css.dropZoneIcon} />
120
+ <Button
121
+ variant="primary"
122
+ loading={uploading}
123
+ onClick={() => { fileInput.current?.click() }}
124
+ >
125
+ {t(browseLabelKey(selectModel.selectedName !== null))}
126
+ </Button>
127
+ </div>
116
128
  {selectModel.selectedName !== null && (
117
129
  /* 已选文件是**值**,不是说明:用徽章承载(原先是一句「已选择:xxx」),
118
130
  data-testid 保持不变以便既有守卫继续定位。 */
@@ -120,20 +132,13 @@ export function SelectStep(props: {
120
132
  <Badge kind="info">{t('import.select.file', { name: selectModel.selectedName })}</Badge>
121
133
  </div>
122
134
  )}
123
- <div className={css.actionRow} style={{ marginBottom: 0 }}>
124
- {selectModel.selectedName !== null && (
135
+ {selectModel.selectedName !== null && (
136
+ <div className={css.actionRow} style={{ marginBottom: 0 }}>
125
137
  <Button variant="ghost" onClick={onCancel}>
126
138
  {t('import.select.cancel')}
127
139
  </Button>
128
- )}
129
- <Button
130
- variant="primary"
131
- loading={uploading}
132
- onClick={() => { fileInput.current?.click() }}
133
- >
134
- {t(browseLabelKey(selectModel.selectedName !== null))}
135
- </Button>
136
- </div>
140
+ </div>
141
+ )}
137
142
  {error !== null && <ErrorBanner error={error} onRetry={onReset} t={apiT} />}
138
143
  </div>
139
144
  )
@@ -170,10 +175,10 @@ export function ConsultStage(props: {
170
175
  const { consultLoading, consultReport, error, onNext, onReset, apiT, t } = props
171
176
  return (
172
177
  <div className={css.viewBody}>
173
- <SectionTitle title={t('import.preview.title')} info={<InfoHint text={t('import.consult.hint')} label={t('common.infoHint')} />} />
178
+ <SectionTitle title={t('import.preview.title')} tooltip={t('import.consult.hint')} />
174
179
  {consultLoading && <Skeleton shape="line" count={5} label={apiT('consult.loading')} />}
175
180
  {consultReport !== null && <ConsultCard report={consultReport} t={apiT} />}
176
- {!consultLoading && consultReport === null && (
181
+ {!consultLoading && consultReport === null && error === null && (
177
182
  <Banner kind="info">{t('import.consult.unavailable')}</Banner>
178
183
  )}
179
184
  {error !== null && <ErrorBanner error={error} onRetry={onNext} t={apiT} />}
@@ -201,27 +206,34 @@ export function DecryptArchiveStep(props: {
201
206
  const { password, onPasswordChange, unlockError, unlocking, onUnlock, onReset, apiT, t } = props
202
207
  return (
203
208
  <div className={css.viewBody}>
204
- <SectionTitle title={t('import.decryptArchive.title')} info={<InfoHint text={t('import.decryptArchive.hint')} label={t('common.infoHint')} />} />
205
- <input
206
- type="password"
207
- className={css.input}
208
- autoComplete="off"
209
- placeholder={t('import.decryptArchive.passwordPlaceholder')}
210
- value={password}
211
- onChange={(e: ChangeEvent<HTMLInputElement>) => { onPasswordChange(e.target.value) }}
212
- />
213
- {unlockError !== null && <ErrorBanner error={unlockError} t={apiT} />}
214
- <div className={css.actionRow}>
215
- <Button variant="ghost" onClick={onReset}>{t('import.select.reselect')}</Button>
216
- <Button
217
- variant="primary"
218
- loading={unlocking}
219
- disabled={password === ''}
220
- onClick={onUnlock}
221
- >
222
- {t('import.decryptArchive.unlock')}
223
- </Button>
224
- </div>
209
+ {/* 解锁卡(W3 R-3):徽章 / 标题 / 密码 / 动作收进同一张卡,屏幕上只剩一个黑底主按钮。
210
+ 机制句只进标题 title(DESIGN §7:说明性文案不进正文)。 */}
211
+ <Card className={css.optionsCard}>
212
+ <div className={css.statRow}>
213
+ <Badge kind="error">🔒 {t('import.decrypt.badge')}</Badge>
214
+ </div>
215
+ <SectionTitle title={t('import.decryptArchive.title')} tooltip={t('import.decryptArchive.hint')} />
216
+ <input
217
+ type="password"
218
+ className={css.input}
219
+ autoComplete="off"
220
+ placeholder={t('import.decryptArchive.passwordPlaceholder')}
221
+ value={password}
222
+ onChange={(e: ChangeEvent<HTMLInputElement>) => { onPasswordChange(e.target.value) }}
223
+ />
224
+ {unlockError !== null && <ErrorBanner error={unlockError} t={apiT} />}
225
+ <div className={css.actionRow} style={{ marginBottom: 0 }}>
226
+ <Button variant="ghost" onClick={onReset}>{t('import.select.reselect')}</Button>
227
+ <Button
228
+ variant="primary"
229
+ loading={unlocking}
230
+ disabled={password === ''}
231
+ onClick={onUnlock}
232
+ >
233
+ {t('import.decryptArchive.unlock')}
234
+ </Button>
235
+ </div>
236
+ </Card>
225
237
  </div>
226
238
  )
227
239
  }
@@ -237,7 +249,7 @@ export function ConflictsStage(props: {
237
249
  const { collector, onChanged, onBack, onNext, t } = props
238
250
  return (
239
251
  <div className={css.viewBody}>
240
- <SectionTitle title={t('import.conflicts.title')} info={<InfoHint text={t('import.conflicts.hint')} label={t('common.infoHint')} />} />
252
+ <SectionTitle title={t('import.conflicts.title')} />
241
253
  <ConflictList
242
254
  collector={collector}
243
255
  t={t}
@@ -267,7 +279,7 @@ export function PathMappingStage(props: {
267
279
  const { issues, mappings, onMappingsChange, onBack, onNext, t, api } = props
268
280
  return (
269
281
  <div className={css.viewBody}>
270
- <SectionTitle title={t('import.paths.title')} info={<InfoHint text={t('import.paths.hint')} label={t('common.infoHint')} />} />
282
+ <SectionTitle title={t('import.paths.title')} tooltip={t('import.paths.hint')} />
271
283
  <PathMappingForm issues={issues} initial={mappings} t={t} onChange={onMappingsChange} api={api} />
272
284
  <div className={css.actionRow}>
273
285
  <Button variant="ghost" onClick={onBack}>{t('common.back')}</Button>
@@ -289,7 +301,7 @@ export function SecretsStage(props: {
289
301
  const { missing, value, onValueChange, onBack, onNext, t } = props
290
302
  return (
291
303
  <div className={css.viewBody}>
292
- <SectionTitle title={t('import.secrets.title')} info={<InfoHint text={t('import.secrets.hint')} label={t('common.infoHint')} />} />
304
+ <SectionTitle title={t('import.secrets.title')} tooltip={t('import.secrets.hint')} />
293
305
  <SecretsForm
294
306
  missing={missing}
295
307
  value={value}
@@ -0,0 +1,129 @@
1
+ /**
2
+ * 导入向导控制器的两处事务语义(审计 P9-7 / P9-8)。
3
+ *
4
+ * 为什么测纯函数而不是 hook:仓库没有组件测试环境(AGENTS.md:逻辑提炼到可 node 跑的函数)。
5
+ * 于是把「解锁 → 继续分析」写成注入端口的异步事务、把「咨询失败 → 文案」写成纯函数,
6
+ * 这里直接跑它们;再用一条源码断言锁住 hook 里**确实调用了**这两处(纯函数测绿但没接线 = 白测)。
7
+ */
8
+ import test from 'node:test'
9
+ import assert from 'node:assert/strict'
10
+ import fs from 'node:fs'
11
+ import { fileURLToPath } from 'node:url'
12
+
13
+ import { ConfigManagerApiError } from '../common/http.ts'
14
+ import {
15
+ consultFailureError,
16
+ unlockArchiveThenAnalyze,
17
+ type ArchiveUnlockFlow,
18
+ } from './use-import-wizard-controller.ts'
19
+
20
+ /** 被实测的接线源码(断言 hook 里确实调用了下面两个纯函数) */
21
+ const CONTROLLER = fileURLToPath(new URL('./use-import-wizard-controller.ts', import.meta.url))
22
+
23
+ /* ---------------------------------------------------------------- P9-7 ---- */
24
+
25
+ test('P9-7 consultFailureError:404 = 宿主不支持(null),其余失败 = 可读消息', () => {
26
+ // 404:老宿主没有 /consult 路由 —— 界面继续按「宿主不支持」渲染 info 横幅,不制造错误
27
+ assert.equal(consultFailureError(new ConfigManagerApiError('Not Found', 404)), null)
28
+ assert.equal(
29
+ consultFailureError(new ConfigManagerApiError('404 no route', 404, 'not-found')),
30
+ null,
31
+ '带 code 的 404 同样是「不支持」',
32
+ )
33
+ // 其它状态码:必须变成可见错误(此前 catch 只 setConsultReport(null) ⇒ 用户看到「没有结论」)
34
+ assert.equal(consultFailureError(new ConfigManagerApiError('boom', 500)), 'boom')
35
+ assert.equal(consultFailureError(new ConfigManagerApiError('timeout', 504)), 'timeout')
36
+ // 无 status(网络层 / 解析失败)
37
+ assert.equal(consultFailureError(new Error('fetch failed')), 'fetch failed')
38
+ // 非 Error 值兜底为字符串,不能变成 undefined / [object Object]
39
+ assert.equal(consultFailureError('plain text'), 'plain text')
40
+ assert.equal(consultFailureError(undefined), 'undefined')
41
+ })
42
+
43
+ test('P9-7 接线:consult 失败时把消息写进 import.error(而不是只清空报告)', () => {
44
+ const src = fs.readFileSync(CONTROLLER, 'utf8')
45
+ assert.match(src, /const message = consultFailureError\(err\)/, 'catch 必须经 consultFailureError 分档')
46
+ assert.match(src, /if \(message !== null\) \{\s*runStore\.patch\(\{ import: \{ error: message \} \}\)/, '非 404 失败必须写 import.error 供 ErrorBanner 渲染')
47
+ })
48
+
49
+ /* ---------------------------------------------------------------- P9-8 ---- */
50
+
51
+ interface Trace {
52
+ calls: string[]
53
+ }
54
+
55
+ function flow(
56
+ trace: Trace,
57
+ opts: {
58
+ unlockFails?: boolean
59
+ analyzeFails?: boolean
60
+ /** 第 n 次调用 cancelled() 的返回值(默认恒 false) */
61
+ cancelledAt?: (call: number) => boolean
62
+ } = {},
63
+ ): ArchiveUnlockFlow<string> {
64
+ let cancelledCalls = 0
65
+ return {
66
+ unlock: async () => {
67
+ trace.calls.push('unlock')
68
+ if (opts.unlockFails === true) throw new Error('密码错误')
69
+ return { refs: ['a', 'b'] }
70
+ },
71
+ commitUnlocked: (refs) => { trace.calls.push('commit:' + refs.join(',')) },
72
+ analyze: async () => {
73
+ trace.calls.push('analyze')
74
+ if (opts.analyzeFails === true) throw new Error('ZIP 解析失败')
75
+ return null
76
+ },
77
+ rollbackUnlocked: () => { trace.calls.push('rollback') },
78
+ cancelled: () => {
79
+ cancelledCalls += 1
80
+ return opts.cancelledAt === undefined ? false : opts.cancelledAt(cancelledCalls)
81
+ },
82
+ }
83
+ }
84
+
85
+ test('P9-8 unlockArchiveThenAnalyze:成功路径按 解锁 → 提交 → 分析 顺序进行,不回滚', async () => {
86
+ const trace: Trace = { calls: [] }
87
+ const outcome = await unlockArchiveThenAnalyze(flow(trace))
88
+ assert.deepEqual(outcome, { status: 'ok' })
89
+ assert.deepEqual(trace.calls, ['unlock', 'commit:a,b', 'analyze'])
90
+ })
91
+
92
+ test('P9-8 unlockArchiveThenAnalyze:解锁成功但 selectZip 抛错 ⇒ 回滚已提交的解锁态', async () => {
93
+ const trace: Trace = { calls: [] }
94
+ const outcome = await unlockArchiveThenAnalyze(flow(trace, { analyzeFails: true }))
95
+ // 这就是审计的根因场景:archiveUnlocked 已 true 而 phase 停在 decrypt-archive
96
+ assert.deepEqual(outcome, { status: 'failed', message: 'ZIP 解析失败', unlocked: true })
97
+ assert.deepEqual(trace.calls, ['unlock', 'commit:a,b', 'analyze', 'rollback'], '提交过就必须回滚,且只回滚一次')
98
+ })
99
+
100
+ test('P9-8 unlockArchiveThenAnalyze:解锁本身失败 ⇒ 不提交、不回滚', async () => {
101
+ const trace: Trace = { calls: [] }
102
+ const outcome = await unlockArchiveThenAnalyze(flow(trace, { unlockFails: true }))
103
+ assert.deepEqual(outcome, { status: 'failed', message: '密码错误', unlocked: false })
104
+ assert.deepEqual(trace.calls, ['unlock'], '没提交过的解锁态没有可回滚的东西')
105
+ })
106
+
107
+ test('P9-8 unlockArchiveThenAnalyze:解锁期间向导被重置 ⇒ 丢弃结果,不提交', async () => {
108
+ const trace: Trace = { calls: [] }
109
+ const outcome = await unlockArchiveThenAnalyze(flow(trace, { cancelledAt: (n) => n === 1 }))
110
+ assert.deepEqual(outcome, { status: 'cancelled' })
111
+ assert.deepEqual(trace.calls, ['unlock'], 'reset 已清空状态,再提交会污染新一轮导入')
112
+ })
113
+
114
+ test('P9-8 unlockArchiveThenAnalyze:分析失败时若向导已被重置 ⇒ 不回滚(不覆盖新一轮)', async () => {
115
+ const trace: Trace = { calls: [] }
116
+ // 第 1 次(提交前)false,第 2 次(catch 里)true —— 用户恰在 analyze 期间点了重新选择
117
+ const outcome = await unlockArchiveThenAnalyze(flow(trace, { analyzeFails: true, cancelledAt: (n) => n === 2 }))
118
+ assert.deepEqual(outcome, { status: 'cancelled' })
119
+ assert.deepEqual(trace.calls, ['unlock', 'commit:a,b', 'analyze'], '回滚会把已重置的向导再拽回 decrypt-archive')
120
+ })
121
+
122
+ test('P9-8 接线:onUnlockArchive 使用事务,且回滚同时写 wizard 与 store 两份状态', () => {
123
+ const src = fs.readFileSync(CONTROLLER, 'utf8')
124
+ assert.match(src, /const outcome = await unlockArchiveThenAnalyze\(\{/, 'onUnlockArchive 必须走事务,而不是 try 里直接 patch')
125
+ // 回滚块:wizard 侧(setDecryptPassword('') / setArchiveEncrypted(true, …))+ store 侧四个字段
126
+ assert.match(src, /wizard\.setArchiveEncrypted\(true, encryptedPath\)/, '回滚必须把 wizard 恢复成「加密未解锁」')
127
+ assert.match(src, /archiveUnlocked: false,[\s\S]{0,120}phase: 'decrypt-archive'/, '回滚必须把 phase 退回 decrypt-archive(与 archiveUnlocked 一致)')
128
+ assert.match(src, /if \(outcome\.status === 'failed'\) \{/, '失败必须走可见错误(archiveUnlockError)')
129
+ })