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
package/lib/index.js CHANGED
@@ -80,7 +80,9 @@ import { ImportUserSkippedError } from './core/types.js';
80
80
  import { PLUGIN_NPM_PACKAGE } from './core/update-check.js';
81
81
  import { planSelfUpdate, runSelfUpdate } from './core/self-update.js';
82
82
  import { createAdapters } from './adapters/index.js';
83
- import { describePatchDocument, describePatchLayoutDrift, planPatchDocument, promotedTopLevelIds } from './core/patch-document.js';
83
+ import { describePatchDocument, describePatchLayoutDrift, planPatchDocument, unprovidedTopLevelIds } from './core/patch-document.js';
84
+ import { alignOverrideNames, patchChainIndex } from './core/patch-chain.js';
85
+ import { PatchChainCache, downgradeProvidedInserts, readExistingPatchDocument, readPatchChainFromProfile, } from './utils/patch-chain-read.js';
84
86
  import { isPatchLayerRel, profilePatchRel, readEffectivePatchLines, USER_PATCH_FILE } from './core/patch-layers.js';
85
87
  import { createLocalPluginPackHook } from './core/local-plugin-host.js';
86
88
  import { ENCRYPTED_CONTAINER_CODE, createEncryptionProvider, readContainerKind, encryptArchive } from './security/index.js';
@@ -149,7 +151,7 @@ export const name = 'config-manager';
149
151
  /** Services required before the engine can mount (present in every profile). */
150
152
  export const inject = ['settings', 'credentials'];
151
153
  /** Plugin version, kept in sync with package.json ("version"). */
152
- export const PLUGIN_VERSION = '0.8.2';
154
+ export const PLUGIN_VERSION = '0.10.0';
153
155
  /** Plugin own package name — excluded from its own exported plugins list. */
154
156
  const PLUGIN_NAME = 'dsh-config-manager';
155
157
  /**
@@ -1389,6 +1391,8 @@ export class DshSessionStoreFacade {
1389
1391
  }
1390
1392
  }
1391
1393
  }
1394
+ /** 生效链缓存时长(#144):一次导入逐行写 patch,逐行重读 30+ 个 bundle 纯属浪费;写盘即 invalidate。 */
1395
+ const PATCH_CHAIN_CACHE_MS = 2000;
1392
1396
  /**
1393
1397
  * Patch-file facade:patch 的**两层**都在 home 根内 ——
1394
1398
  * - 用户(home)层:`$DSH_HOME/cordis.patch.yml`
@@ -1488,65 +1492,56 @@ export class DshPatchFileFacade {
1488
1492
  }
1489
1493
  async applyPatchChanges(file, changes) {
1490
1494
  const p = this.patchPath(file);
1491
- // 1. Load the current document (the ordered table itself is built by planPatchDocument).
1492
- //
1493
- // 读不出来的既有内容**绝不能当作空文档**(issue #75 的数据丢失点):重建后的文件只包含
1494
- // 本次写入的行,等于把用户手写的其余行整段删掉。三种情况分开处理:
1495
- // - 真不存在(ENOENT)→ 空文档(首次创建,既有语义);
1496
- // - 存在但读不到(EACCES/EBUSY/…)→ 抛错,不改写;
1497
- // - 存在但解析不了(含未知方言 / YAML 本身有错)→ 抛错,不改写。
1498
- let existing = null;
1495
+ // 0. 生效链兜底(#144):id 已被别层(bundle 最典型)提供时再写 insert = 两条「新增」抢同一 id
1496
+ // ⇒ 插件保存配置必报 overridden。统一降级成顶层覆盖行(含 mcp/prompts/激活行)。
1497
+ const chain = await this.readPatchChainQuietly();
1498
+ const { effective, downgraded } = downgradeProvidedInserts(chain, file, changes);
1499
+ // 1. 读既有文档:只有真不存在才算空文档;读不到 / 解析不了一律抛错(#75:当空文档 = 删行)。
1500
+ let doc;
1499
1501
  try {
1500
- existing = await fs.readFile(p, 'utf8');
1502
+ doc = await readExistingPatchDocument(p);
1501
1503
  }
1502
1504
  catch (err) {
1503
- if (!isENOENT(err)) {
1504
- throw new Error(this.msg('host.patchRefuseClobber', { file, reason: describePatchYamlError(err) }), { cause: err });
1505
- }
1506
- }
1507
- let doc;
1508
- if (existing !== null && existing.trim() !== '') {
1509
- try {
1510
- doc = loadPatchDocument(existing);
1511
- }
1512
- catch (err) {
1513
- throw new Error(this.msg('host.patchRefuseClobber', { file, reason: describePatchYamlError(err) }), { cause: err });
1514
- }
1505
+ throw new Error(this.msg('host.patchRefuseClobber', { file, reason: describePatchYamlError(err) }), { cause: err });
1515
1506
  }
1516
- // 2. Rebuild through core/patch-document.ts (issue #133): the two shapes are **not**
1517
- // equivalent on the host side. A top-level `- id: X` row *overrides* entry X and is
1518
- // dropped with `patch: entry "X" not found` when X does not exist; only an
1519
- // `- insert:` block member *adds* entries. Emitting every row top-level therefore
1520
- // turned one update into "every insert-only entry (MCP servers, most notably) is
1521
- // gone after restart".
1522
- const plan = planPatchDocument(doc, changes);
1507
+ // 2. 经 core/patch-document.ts 重建(#133):顶层行只覆盖、查不到 id 就整行丢弃,只有 insert 成员才新增。
1508
+ const plan = planPatchDocument(doc, effective);
1509
+ // 2b. 顶层行的 name 必须与既有条目逐字一致(#144):不一致宿主 `patch: name mismatch … skipping` 整行丢弃。
1510
+ const items = chain === null ? plan.items : alignOverrideNames(plan.items, patchChainIndex(chain));
1523
1511
  const text = '# rewritten by dsh-config-manager import (original comments not preserved)\n'
1524
- + dumpPatchDocument(plan.items);
1525
- // 3. Post-write structure self-check, before anything touches the disk: re-parse the
1526
- // text we just serialized and require both id sets to match the plan item by item.
1527
- // A serializer or dialect change that flattens or swallows insert blocks stops here
1528
- // (zero write) instead of silently degrading every patch row to an override.
1512
+ + dumpPatchDocument(items);
1513
+ // 3. 写盘前结构自检:重新解析刚序列化的文本,两组 id 必须与计划逐项一致(序列化退化即零写入)。
1529
1514
  const drift = describePatchLayoutDrift(plan, describePatchDocument(loadPatchDocument(text)));
1530
1515
  if (drift !== null) {
1531
1516
  throw new Error(this.msg('host.patchSemanticDrift', { file, detail: drift }));
1532
1517
  }
1533
- // 4. 跨层提升守卫(issue #133):待写的顶层 id 若是**另一层**的 insert 成员,写下去就从
1534
- // 「新增」变成「覆盖」(宿主查不到则丢弃)。对侧读不出来/解析不了只跳过守卫 —— 读护栏
1535
- // 已在各自层报错,损坏的兄弟文件不该永久阻塞本层写入。
1536
- const other = file === USER_PATCH_FILE ? profilePatchRel(this.profile) : USER_PATCH_FILE;
1537
- const promoted = promotedTopLevelIds(await this.readPatchDocQuietly(other), plan.topLevelIds);
1538
- if (promoted.length > 0) {
1539
- throw new Error(this.msg('host.patchRefusePromote', { file, ids: promoted.join(', ') }));
1518
+ // 4. 覆盖行孤儿守卫(#133 起、#144 改判到整条链):只拒绝「任何一层都没提供这个 id」的顶层行;
1519
+ // 且只在**整链可信**(零失败层)时拒绝 —— 缺口层可能恰好提供该 id,拒绝 = 用户永久卡死。
1520
+ const chainTrusted = chain !== null && chain.failures.length === 0;
1521
+ if (chainTrusted) {
1522
+ const orphans = unprovidedTopLevelIds([...chain.sources.map((source) => source.doc), doc], plan.topLevelIds);
1523
+ if (orphans.length > 0) {
1524
+ throw new Error(this.msg('host.patchRefuseUnknownId', { file, ids: orphans.join(', ') }));
1525
+ }
1540
1526
  }
1541
1527
  await atomicWriteFile(p, text);
1542
- }
1543
- /** 读另一层并解析;读不到/解析不了 → undefined(跨层守卫 fail-open,见 promotedTopLevelIds)。 */
1544
- async readPatchDocQuietly(file) {
1528
+ // 盘面变了:销毁链缓存,否则同一批次里「刚写下的行」对后续判定不可见
1529
+ this.chainCache.invalidate();
1530
+ return { downgraded };
1531
+ }
1532
+ /** 生效链缓存(见 `utils/patch-chain-read.ts`):一次导入逐行写 patch,不必逐行重读 30+ 个 bundle。 */
1533
+ chainCache = new PatchChainCache(PATCH_CHAIN_CACHE_MS);
1534
+ /** 读整条生效 patch 链(issue #144):bundle 层 → profile 层 → home 层,宿主合并序。 */
1535
+ async readPatchChain() {
1536
+ return this.chainCache.get(() => readPatchChainFromProfile(this.homeDir, this.profile));
1537
+ }
1538
+ /** 读链失败(profile 清单整体不可读等)→ `null`:判定退化为两层,绝不阻断写入。 */
1539
+ async readPatchChainQuietly() {
1545
1540
  try {
1546
- return loadPatchDocument(await fs.readFile(resolve(this.homeDir, file), 'utf8'));
1541
+ return await this.readPatchChain();
1547
1542
  }
1548
1543
  catch {
1549
- return undefined;
1544
+ return null;
1550
1545
  }
1551
1546
  }
1552
1547
  }
@@ -6,3 +6,23 @@
6
6
  export declare function readTextSafe(path: string): string | null;
7
7
  /** 文件名片段清洗(profile 名已过校验;这里只是防意外字符)。 */
8
8
  export declare function sanitizeFilePart(name: string): string;
9
+ /**
10
+ * 运行心跳文件名(**唯一实现**)—— 可读前缀 + 名字哈希。
11
+ *
12
+ * 为什么必须带哈希(审计 P11-2 P1,2026-11-13 实测):心跳文件此前叫
13
+ * `<sanitizeFilePart(name)>.json`,而清洗是**多对一**的 —— `web` 与 `web!` 都落到
14
+ * `web.json`,于是两个实例共享同一个心跳文件:后写的覆盖先写的,`listActive()` 只看得到
15
+ * 一个,`stopExternal` 可能停错人,`withdraw()` 也会删掉别人的心跳(对方从此「不可见」,
16
+ * 界面上又能被重复启动 —— 正是这套机制要防的事)。
17
+ *
18
+ * 判据:清洗只用于可读性(截断到 48 字符、去掉结尾的点/空格,Windows 会吃掉结尾点),
19
+ * **唯一性由 sha256(原名) 的前 12 hex 保证**;\0 之类不可达字符也天然被哈希区隔。
20
+ */
21
+ export declare function runtimeFileName(name: string): string;
22
+ /**
23
+ * 旧版心跳文件名(升级清理专用):`<sanitizeFilePart(name)>.json`。
24
+ *
25
+ * 只用于「自报/自撤时顺手删掉自己那份旧文件」—— 否则升级后同一个 profile 会留下两份心跳,
26
+ * `listActive` 对同名记录会看到两条。绝不用于读别人的记录。
27
+ */
28
+ export declare function legacyRuntimeFileName(name: string): string;
@@ -11,6 +11,7 @@
11
11
  * `sanitizeFilePart`(同一正则)。
12
12
  */
13
13
  import { readFileSync } from 'node:fs';
14
+ import { createHash } from 'node:crypto';
14
15
  /**
15
16
  * 读文本文件;不可读返回 **null** —— 语义差异由调用方显式表达(**不得把 null 统一成 ''**):
16
17
  * - 档案管理器用 null 参与「该档案没有清单 → 视为非 DSH profile」的判定;
@@ -28,4 +29,30 @@ export function readTextSafe(path) {
28
29
  export function sanitizeFilePart(name) {
29
30
  return name.replace(/[^A-Za-z0-9._-]/g, '_');
30
31
  }
32
+ /**
33
+ * 运行心跳文件名(**唯一实现**)—— 可读前缀 + 名字哈希。
34
+ *
35
+ * 为什么必须带哈希(审计 P11-2 P1,2026-11-13 实测):心跳文件此前叫
36
+ * `<sanitizeFilePart(name)>.json`,而清洗是**多对一**的 —— `web` 与 `web!` 都落到
37
+ * `web.json`,于是两个实例共享同一个心跳文件:后写的覆盖先写的,`listActive()` 只看得到
38
+ * 一个,`stopExternal` 可能停错人,`withdraw()` 也会删掉别人的心跳(对方从此「不可见」,
39
+ * 界面上又能被重复启动 —— 正是这套机制要防的事)。
40
+ *
41
+ * 判据:清洗只用于可读性(截断到 48 字符、去掉结尾的点/空格,Windows 会吃掉结尾点),
42
+ * **唯一性由 sha256(原名) 的前 12 hex 保证**;\0 之类不可达字符也天然被哈希区隔。
43
+ */
44
+ export function runtimeFileName(name) {
45
+ const readable = sanitizeFilePart(name).replace(/[. ]+$/, '').slice(0, 48);
46
+ const digest = createHash('sha256').update(name, 'utf8').digest('hex').slice(0, 12);
47
+ return readable === '' ? `${digest}.json` : `${readable}-${digest}.json`;
48
+ }
49
+ /**
50
+ * 旧版心跳文件名(升级清理专用):`<sanitizeFilePart(name)>.json`。
51
+ *
52
+ * 只用于「自报/自撤时顺手删掉自己那份旧文件」—— 否则升级后同一个 profile 会留下两份心跳,
53
+ * `listActive` 对同名记录会看到两条。绝不用于读别人的记录。
54
+ */
55
+ export function legacyRuntimeFileName(name) {
56
+ return `${sanitizeFilePart(name)}.json`;
57
+ }
31
58
  //# sourceMappingURL=dsh-profile-io.js.map
@@ -1,3 +1,4 @@
1
+ import { type AtomicIoSync } from '../utils/atomic-write.ts';
1
2
  import { type DshProfileCopyMarker, type DshProfileCopyWarning, type DshProfileDetail, type DshProfileErrorCode, type DshProfileIncompleteCopy, type DshProfileMeta } from './dsh-profile-shared.ts';
2
3
  /** DSH home 下的 profile 根目录名(与 dsh-app-boot 的 PROFILES_DIR 一致)。 */
3
4
  export declare const PROFILES_DIR = "profiles";
@@ -13,6 +14,13 @@ export interface DshProfileManagerOptions {
13
14
  /** 插件 dataDir(保留给调用方复用;本引擎不再落任何状态) */
14
15
  /** 当前运行中的 profile 名(惰性读取,宿主注入) */
15
16
  currentProfile?: () => string;
17
+ /**
18
+ * 「复制进行中标记」那一次写盘用的可注入同步 io(缺省 undefined = 真实 fs)。
19
+ *
20
+ * 只给单测用:Windows 上造不出「目录建好、标记写不出来」的真实故障(写完立刻腾空间就失败了),
21
+ * 而这条窄缝恰恰会留下既不在 list() 里、remove() 又报 notFound 的空目录。
22
+ */
23
+ markerIo?: AtomicIoSync;
16
24
  }
17
25
  /**
18
26
  * t89:残留枚举结果 —— `unreadable` 让「枚举失败」与「确实没有残留」可区分;
@@ -51,6 +59,8 @@ export declare function rollbackCopiedProfileDir(destDir: string, marker: DshPro
51
59
  export declare class DshProfileManager {
52
60
  private readonly homeDir;
53
61
  private readonly currentProfile;
62
+ /** 见 DshProfileManagerOptions.markerIo:只作用于「复制进行中标记」的写入 */
63
+ private readonly markerIo;
54
64
  constructor(options: DshProfileManagerOptions);
55
65
  /** profiles 根目录(`$DSH_HOME/profiles`) */
56
66
  profilesRoot(): string;
@@ -121,11 +131,28 @@ export declare class DshProfileManager {
121
131
  remove(name: string, opts?: {
122
132
  allowCurrent?: boolean;
123
133
  }): void;
134
+ /**
135
+ * remove() 的异步版本:语义、护栏、错误码完全一致,只是不阻塞事件循环(审计 P11-9)。
136
+ *
137
+ * 为什么需要两份:档案目录是整仓里最大的一棵树(含 node_modules,真机 2 万文件)。实测
138
+ * removeTreeSync 删 2 万文件耗 15.5 s,期间宿主 20 ms 定时器 0/776 次触发 —— 心跳、实例
139
+ * 存活探测、同步定时器全停摆,面板表现成「后端卡死」。HTTP 删除走这里;只有确实同步
140
+ * 上下文(脚本、收尾清理)才用 remove(),且必须是自己知道很小的树。
141
+ */
142
+ removeAsync(name: string, opts?: {
143
+ allowCurrent?: boolean;
144
+ }): Promise<void>;
124
145
  /**
125
146
  * cross-F3:目标目录 = **正常 profile(有 package.json)** 或 **中断的复制残留(有进行中标记)**;
126
147
  * 两者都没有 → notFound。残余标记的目录必须能被定位与删除,否则就是孤儿。
127
148
  */
128
149
  private requireManagedDir;
150
+ /**
151
+ * 落「复制进行中标记」(cross-F3 的唯一凭据)。
152
+ *
153
+ * 单独抽出来只为把注入点收窄到这一处写入:调用方(copy)据此保证「标记写失败 ⇒ 目录一起回滚」。
154
+ */
155
+ private writeCopyMarker;
129
156
  /** 复制进行中标记的路径。 */
130
157
  private copyMarkerPath;
131
158
  /**
@@ -153,9 +153,12 @@ export async function rollbackCopiedProfileDir(destDir, marker, remove = default
153
153
  export class DshProfileManager {
154
154
  homeDir;
155
155
  currentProfile;
156
+ /** 见 DshProfileManagerOptions.markerIo:只作用于「复制进行中标记」的写入 */
157
+ markerIo;
156
158
  constructor(options) {
157
159
  this.homeDir = options.homeDir;
158
160
  this.currentProfile = options.currentProfile ?? (() => 'web');
161
+ this.markerIo = options.markerIo;
159
162
  }
160
163
  /** profiles 根目录(`$DSH_HOME/profiles`) */
161
164
  profilesRoot() {
@@ -271,9 +274,6 @@ export class DshProfileManager {
271
274
  throw new DshProfileError('exists');
272
275
  const includeNodeModules = opts.includeNodeModules !== false;
273
276
  const startedAt = Date.now();
274
- await mkdir(destDir, { recursive: true });
275
- // cross-F3:**先落标记再拷文件**。进程被强杀时标记留在目标目录里,使这个半截副本可被
276
- // 档案列表 / 恢复面板辨识并物理删除;不留标记的话它既不在列表里、删除又报 notFound。
277
277
  const marker = {
278
278
  sourceName: name,
279
279
  newName,
@@ -281,8 +281,13 @@ export class DshProfileManager {
281
281
  includeNodeModules,
282
282
  pid: process.pid,
283
283
  };
284
- atomicWriteFileSync(this.copyMarkerPath(destDir), `${JSON.stringify(marker, null, 2)}\n`, { mode: 0o644 });
284
+ // 建目录与落标记同属一个回滚范围:标记写不出来时这个目录还没有任何可辨认身份,
285
+ // 留在盘上就是「list() 看不到、remove() 报 notFound」的空壳 —— 必须在 catch 里一并清掉。
285
286
  try {
287
+ await mkdir(destDir, { recursive: true });
288
+ // cross-F3:**先落标记再拷文件**。进程被强杀时标记留在目标目录里,使这个半截副本可被
289
+ // 档案列表 / 恢复面板辨识并物理删除;不留标记的话它既不在列表里、删除又报 notFound。
290
+ this.writeCopyMarker(destDir, marker);
286
291
  const entries = await readdir(srcDir, { withFileTypes: true });
287
292
  for (const entry of entries) {
288
293
  // node_modules 与 DSH 投影出来的 .dsh-module-fallback 同进同出(后者的链接都指向前者)
@@ -435,6 +440,31 @@ export class DshProfileManager {
435
440
  throw new DshProfileError('deleteFailed', `profile directory still exists after removal: ${dir}`);
436
441
  }
437
442
  }
443
+ /**
444
+ * remove() 的异步版本:语义、护栏、错误码完全一致,只是不阻塞事件循环(审计 P11-9)。
445
+ *
446
+ * 为什么需要两份:档案目录是整仓里最大的一棵树(含 node_modules,真机 2 万文件)。实测
447
+ * removeTreeSync 删 2 万文件耗 15.5 s,期间宿主 20 ms 定时器 0/776 次触发 —— 心跳、实例
448
+ * 存活探测、同步定时器全停摆,面板表现成「后端卡死」。HTTP 删除走这里;只有确实同步
449
+ * 上下文(脚本、收尾清理)才用 remove(),且必须是自己知道很小的树。
450
+ */
451
+ async removeAsync(name, opts = {}) {
452
+ if (isManagedProfileName(name))
453
+ throw new DshProfileError('managedProfile');
454
+ const dir = this.requireManagedDir(name);
455
+ if (name === this.currentProfile() && opts.allowCurrent !== true) {
456
+ throw new DshProfileError('currentProfile');
457
+ }
458
+ try {
459
+ await removeTree(dir);
460
+ }
461
+ catch (error) {
462
+ throw new DshProfileError('deleteFailed', error instanceof Error ? error.message : String(error));
463
+ }
464
+ if (existsSync(dir)) {
465
+ throw new DshProfileError('deleteFailed', `profile directory still exists after removal: ${dir}`);
466
+ }
467
+ }
438
468
  /**
439
469
  * cross-F3:目标目录 = **正常 profile(有 package.json)** 或 **中断的复制残留(有进行中标记)**;
440
470
  * 两者都没有 → notFound。残余标记的目录必须能被定位与删除,否则就是孤儿。
@@ -453,6 +483,17 @@ export class DshProfileManager {
453
483
  return dir;
454
484
  throw new DshProfileError('notFound');
455
485
  }
486
+ /**
487
+ * 落「复制进行中标记」(cross-F3 的唯一凭据)。
488
+ *
489
+ * 单独抽出来只为把注入点收窄到这一处写入:调用方(copy)据此保证「标记写失败 ⇒ 目录一起回滚」。
490
+ */
491
+ writeCopyMarker(dir, marker) {
492
+ atomicWriteFileSync(this.copyMarkerPath(dir), `${JSON.stringify(marker, null, 2)}\n`, {
493
+ mode: 0o644,
494
+ ...(this.markerIo === undefined ? {} : { syncIo: this.markerIo }),
495
+ });
496
+ }
456
497
  /** 复制进行中标记的路径。 */
457
498
  copyMarkerPath(dir) {
458
499
  return join(dir, PROFILE_COPY_MARKER_FILENAME);
@@ -59,8 +59,12 @@ export declare class DshProfileRuntimeRegistry {
59
59
  constructor(options: DshProfileRuntimeOptions);
60
60
  /** 心跳目录(`<dataDir>/running`) */
61
61
  dir(): string;
62
- /** 某个 profile 的心跳文件绝对路径 */
62
+ /** 某个 profile 的心跳文件绝对路径(名字哈希保证唯一,见 runtimeFileName) */
63
63
  fileFor(name: string): string;
64
+ /** 旧版心跳文件(升级清理用:名字清洗多对一,旧文件可能已被别的 profile 覆盖过) */
65
+ private legacyFileFor;
66
+ /** 删掉自己那份旧版心跳(升级后不留双份;不碰别人的文件) */
67
+ private dropLegacyHeartbeat;
64
68
  /** 自报/刷新心跳(幂等;apply 时写一次,之后由 startHeartbeat 定期刷)。 */
65
69
  announce(): DshProfileRuntimeRecord;
66
70
  /** 撤回自己的心跳(dispose 时;正常退出的实例不留垃圾文件)。 */
@@ -19,7 +19,7 @@
19
19
  import { existsSync, mkdirSync, readdirSync, rmSync } from 'node:fs';
20
20
  import { join } from 'node:path';
21
21
  import { atomicWriteFileSync } from '../utils/atomic-write.js';
22
- import { readTextSafe, sanitizeFilePart } from './dsh-profile-io.js';
22
+ import { legacyRuntimeFileName, readTextSafe, runtimeFileName } from './dsh-profile-io.js';
23
23
  import { DshProfileError } from './dsh-profile-manager.js';
24
24
  import { profilesMsg } from './messages.js';
25
25
  import { resolveProcessControl, stopPid } from './process-control.js';
@@ -97,9 +97,20 @@ export class DshProfileRuntimeRegistry {
97
97
  dir() {
98
98
  return join(this.dataDir, RUNTIME_DIR_NAME);
99
99
  }
100
- /** 某个 profile 的心跳文件绝对路径 */
100
+ /** 某个 profile 的心跳文件绝对路径(名字哈希保证唯一,见 runtimeFileName) */
101
101
  fileFor(name) {
102
- return join(this.dir(), `${sanitizeFilePart(name)}.json`);
102
+ return join(this.dir(), runtimeFileName(name));
103
+ }
104
+ /** 旧版心跳文件(升级清理用:名字清洗多对一,旧文件可能已被别的 profile 覆盖过) */
105
+ legacyFileFor(name) {
106
+ return join(this.dir(), legacyRuntimeFileName(name));
107
+ }
108
+ /** 删掉自己那份旧版心跳(升级后不留双份;不碰别人的文件) */
109
+ dropLegacyHeartbeat(name) {
110
+ const legacy = this.legacyFileFor(name);
111
+ if (legacy === this.fileFor(name))
112
+ return;
113
+ rmSync(legacy, { force: true });
103
114
  }
104
115
  /** 自报/刷新心跳(幂等;apply 时写一次,之后由 startHeartbeat 定期刷)。 */
105
116
  announce() {
@@ -113,11 +124,13 @@ export class DshProfileRuntimeRegistry {
113
124
  };
114
125
  mkdirSync(this.dir(), { recursive: true });
115
126
  atomicWriteFileSync(this.fileFor(this.name), `${JSON.stringify(record, null, 2)}\n`, { mode: 0o644 });
127
+ this.dropLegacyHeartbeat(this.name);
116
128
  return record;
117
129
  }
118
130
  /** 撤回自己的心跳(dispose 时;正常退出的实例不留垃圾文件)。 */
119
131
  withdraw() {
120
132
  rmSync(this.fileFor(this.name), { force: true });
133
+ this.dropLegacyHeartbeat(this.name);
121
134
  }
122
135
  /**
123
136
  * 定时刷新(返回停止函数;调用方必须用 ctx.effect 绑定生命周期)。
@@ -2,6 +2,17 @@
2
2
  export declare const PROFILE_STOP_GRACE_MS = 6000;
3
3
  /** Windows 的优雅期(更短,原因见文件头)。 */
4
4
  export declare const PROFILE_STOP_GRACE_MS_WINDOWS = 1500;
5
+ /**
6
+ * 强杀后的**有限等待**(ms):`taskkill /F` 返回 ≠ 进程已消失。
7
+ *
8
+ * Windows 上 TerminateProcess 只是投递终止请求,进程表项与句柄回收是异步的(真机上有几十毫秒窗口);
9
+ * 强杀后立刻回查会把「刚被杀、正在消失」判成 failed,调用方(launcher / runtime)据此抛 stopFailed
10
+ * 并保留心跳 —— 而进程其实已经没了(审计 P11-3)。POSIX 的 SIGKILL 也有同样的(更短的)窗口。
11
+ * 所以强杀后与优雅阶段同构地轮询:窗口内消失即 killed,窗口耗尽才 failed。
12
+ */
13
+ export declare const PROFILE_FORCE_EXIT_WAIT_MS = 1000;
14
+ /** 强杀后的回查间隔(ms):强杀预期立即生效,轮询比优雅期(200ms)更密。 */
15
+ export declare const PROFILE_FORCE_EXIT_POLL_MS = 50;
5
16
  /** 一次停止的终态;failed = 强杀后仍活着(调用方必须如实报错,不许说成已停止)。 */
6
17
  export type StopPidOutcome = 'graceful' | 'killed' | 'already-stopped' | 'failed';
7
18
  /** 可注入的进程控制副作用(测试用;缺省即真实实现)。 */
@@ -14,6 +25,8 @@ export interface ProcessControlDeps {
14
25
  now?: () => number;
15
26
  /** 优雅期(缺省按平台:POSIX 6s / Windows 1.5s) */
16
27
  graceMs?: number;
28
+ /** 强杀后等待进程消失的上限(缺省 PROFILE_FORCE_EXIT_WAIT_MS) */
29
+ forceWaitMs?: number;
17
30
  }
18
31
  /** 解析后的进程控制依赖(构造器注入一次,后续只读)。 */
19
32
  export interface ResolvedProcessControl {
@@ -22,13 +35,17 @@ export interface ResolvedProcessControl {
22
35
  sleep: (ms: number) => Promise<void>;
23
36
  now: () => number;
24
37
  graceMs: number;
38
+ forceWaitMs: number;
25
39
  }
26
40
  /** 缺省优雅期(按平台)。 */
27
41
  export declare function defaultStopGraceMs(): number;
28
42
  export declare function resolveProcessControl(deps?: ProcessControlDeps): ResolvedProcessControl;
29
43
  /**
30
- * 停一个 pid:先优雅 → 等 graceMs → 仍活着则强杀 → 仍活着返回 'failed'。
44
+ * 停一个 pid:先优雅 → 等 graceMs → 仍活着则强杀 → 强杀后再等 forceWaitMs → 仍活着才返回 'failed'。
31
45
  * 只做进程动作,不碰任何台账/心跳文件(那是调用方的事)。
46
+ *
47
+ * 强杀阶段为什么不能「杀完立刻查一次」:见 PROFILE_FORCE_EXIT_WAIT_MS(审计 P11-3:
48
+ * 立刻回查会把「正在消失」误判成 failed,调用方保留心跳、UI 报「停不掉」,而进程其实已死)。
32
49
  */
33
50
  export declare function stopPid(pid: number, deps: ResolvedProcessControl): Promise<StopPidOutcome>;
34
51
  /** 真实存活判定:kill(pid, 0);EPERM 说明进程存在但没权限 → 仍视为存活。 */
@@ -16,6 +16,17 @@ import { setTimeout as delay } from 'node:timers/promises';
16
16
  export const PROFILE_STOP_GRACE_MS = 6_000;
17
17
  /** Windows 的优雅期(更短,原因见文件头)。 */
18
18
  export const PROFILE_STOP_GRACE_MS_WINDOWS = 1_500;
19
+ /**
20
+ * 强杀后的**有限等待**(ms):`taskkill /F` 返回 ≠ 进程已消失。
21
+ *
22
+ * Windows 上 TerminateProcess 只是投递终止请求,进程表项与句柄回收是异步的(真机上有几十毫秒窗口);
23
+ * 强杀后立刻回查会把「刚被杀、正在消失」判成 failed,调用方(launcher / runtime)据此抛 stopFailed
24
+ * 并保留心跳 —— 而进程其实已经没了(审计 P11-3)。POSIX 的 SIGKILL 也有同样的(更短的)窗口。
25
+ * 所以强杀后与优雅阶段同构地轮询:窗口内消失即 killed,窗口耗尽才 failed。
26
+ */
27
+ export const PROFILE_FORCE_EXIT_WAIT_MS = 1_000;
28
+ /** 强杀后的回查间隔(ms):强杀预期立即生效,轮询比优雅期(200ms)更密。 */
29
+ export const PROFILE_FORCE_EXIT_POLL_MS = 50;
19
30
  /** 缺省优雅期(按平台)。 */
20
31
  export function defaultStopGraceMs() {
21
32
  return process.platform === 'win32' ? PROFILE_STOP_GRACE_MS_WINDOWS : PROFILE_STOP_GRACE_MS;
@@ -27,11 +38,15 @@ export function resolveProcessControl(deps = {}) {
27
38
  sleep: deps.sleep ?? ((ms) => delay(ms)),
28
39
  now: deps.now ?? (() => Date.now()),
29
40
  graceMs: deps.graceMs ?? defaultStopGraceMs(),
41
+ forceWaitMs: deps.forceWaitMs ?? PROFILE_FORCE_EXIT_WAIT_MS,
30
42
  };
31
43
  }
32
44
  /**
33
- * 停一个 pid:先优雅 → 等 graceMs → 仍活着则强杀 → 仍活着返回 'failed'。
45
+ * 停一个 pid:先优雅 → 等 graceMs → 仍活着则强杀 → 强杀后再等 forceWaitMs → 仍活着才返回 'failed'。
34
46
  * 只做进程动作,不碰任何台账/心跳文件(那是调用方的事)。
47
+ *
48
+ * 强杀阶段为什么不能「杀完立刻查一次」:见 PROFILE_FORCE_EXIT_WAIT_MS(审计 P11-3:
49
+ * 立刻回查会把「正在消失」误判成 failed,调用方保留心跳、UI 报「停不掉」,而进程其实已死)。
35
50
  */
36
51
  export async function stopPid(pid, deps) {
37
52
  if (!deps.isAlivePid(pid))
@@ -46,6 +61,15 @@ export async function stopPid(pid, deps) {
46
61
  if (!deps.isAlivePid(pid))
47
62
  return 'graceful';
48
63
  deps.killPid(pid, 'force');
64
+ // 与优雅阶段同构:强杀生效是异步的,窗口内消失即 killed,窗口耗尽才 failed。
65
+ // 缺省兜底:直接调 stopPid 且只给了部分 deps 的调用方(脚本/复现)也不该退化成「杀完立刻查一次」。
66
+ const forceWaitMs = deps.forceWaitMs ?? PROFILE_FORCE_EXIT_WAIT_MS;
67
+ const forceDeadline = deps.now() + forceWaitMs;
68
+ while (deps.now() < forceDeadline) {
69
+ if (!deps.isAlivePid(pid))
70
+ return 'killed';
71
+ await deps.sleep(PROFILE_FORCE_EXIT_POLL_MS);
72
+ }
49
73
  return deps.isAlivePid(pid) ? 'failed' : 'killed';
50
74
  }
51
75
  /** 真实存活判定:kill(pid, 0);EPERM 说明进程存在但没权限 → 仍视为存活。 */
@@ -207,7 +207,8 @@ export function profileRoutes(env) {
207
207
  try {
208
208
  if (runningView().some((r) => r.name === name))
209
209
  throw new DshProfileError('instanceRunning');
210
- profiles.remove(name, { allowCurrent });
210
+ // 档案目录是整仓最大的树:异步删除,别让事件循环停摆十几秒(审计 P11-9)。
211
+ await profiles.removeAsync(name, { allowCurrent });
211
212
  const historyError = await tryAppendHistory({
212
213
  kind: 'profile-delete',
213
214
  result: 'success',
@@ -230,6 +230,14 @@ export function syncRoutes(env) {
230
230
  autosync: await buildAutosyncStatus(syncDir, transport),
231
231
  // 全部通道的自动同步状态(git/webdav 各自独立;UI 按当前 tab 取对应通道)
232
232
  autosyncByChannel: await buildAutosyncStatusByChannel(syncDir),
233
+ // 待裁决分区(P2,2026-11-14 真机事故):远端有比基线新的快照、且自动同步撞上冲突时,
234
+ // sync-state.pendingMerge 会记录「哪些分区等人裁决」与「从什么时候开始挂着的」。
235
+ // 首页「待裁决」徽章据此从纯颜色变成可点击入口(跳同步页打开裁决视图)。
236
+ // **绝不回 remoteSnapshotId**:与 hasBaseline 同一纪律 —— 界面只需要知不知道该裁决,
237
+ // 不需要(也不该拿到)远端快照坐标。
238
+ ...(state.pendingMerge === undefined
239
+ ? {}
240
+ : { pendingMerge: { sections: [...state.pendingMerge.sections], since: state.pendingMerge.since } }),
233
241
  // 工作副本事实(仅 git 且配置了地址时返回;'facts' = 自检成功,'error' = 自检读不出来)
234
242
  ...(workDir === null ? {} : { workDir }),
235
243
  };
@@ -425,6 +433,9 @@ export function syncRoutes(env) {
425
433
  const sessionsOpt = sections !== undefined && sections.includes('sessions') && sessions !== undefined
426
434
  ? { sessions }
427
435
  : {};
436
+ // issue #140:强制推送(GUI 等价入口,agent 侧早已有 force)。缺省 false = 内容与远端
437
+ // 最新快照一致时不新建快照(引擎返回 skipped:'unchanged');true 时即使一致也新建。
438
+ const force = body['force'] === true;
428
439
  // P0-②:push 前只读预览(body.preview === true → 不写远端,只返回「将推送什么」)
429
440
  const preview = body['preview'] === true;
430
441
  // 分支调用以保证 withTimeout 的泛型结果类型正确(SyncPushReport | SyncPushPreview)
@@ -433,12 +444,19 @@ export function syncRoutes(env) {
433
444
  ...(sections === undefined ? {} : { sections }),
434
445
  ...sessionsOpt,
435
446
  ...(encrypt || includeSecrets ? { encrypt: true, includeSecrets } : {}),
447
+ // 空数组 = 连磁盘上的历史待裁决一起扣下(issue #146:预览与实推必须同口径,
448
+ // 否则「没得推」的预览会漏掉「其实还挂着冲突」这一事实)。
449
+ skipSections: [],
436
450
  }), ROUTE_TIMEOUT_MS, msg('host.syncPushTimeout'))
437
451
  : await withTimeout(engine.push({
438
452
  ...(snapshotId === undefined ? {} : { snapshotId }),
439
453
  ...(sections === undefined ? {} : { sections }),
440
454
  ...sessionsOpt,
441
455
  ...(encrypt || includeSecrets ? { encrypt: true, includeSecrets, password: effectiveEncryptPassword ?? '' } : {}),
456
+ ...(force ? { force: true } : {}),
457
+ // 手动推送同样扣下仍在等裁决的分区(issue #146):本机没合完就整分区上行,
458
+ // 正是「远端 30 个插件被压回 26 个」的成因。force 时引擎自己短路,不受影响。
459
+ skipSections: [],
442
460
  }), ROUTE_TIMEOUT_MS, msg('host.syncPushTimeout'));
443
461
  await writeSyncConfig(syncDir, syncCfg, cloudSecrets);
444
462
  writeJson(res, 200, report);
@@ -963,7 +981,7 @@ export function syncRoutes(env) {
963
981
  ...item,
964
982
  kind: 'Update',
965
983
  severity: 'info',
966
- conflict: { itemId: c?.itemId ?? item.id, resolution: 'useImported' },
984
+ conflict: { itemId: c?.itemId ?? item.id, resolution: 'useImported', decidedBy: 'item' },
967
985
  }];
968
986
  }
969
987
  return [item];
@@ -179,6 +179,17 @@ export interface PatchLine {
179
179
  file: string;
180
180
  lineId: string;
181
181
  raw: unknown;
182
+ /**
183
+ * 本行 `raw` 里**被脱敏剥空**的叶子路径(行内相对,如 `raw.mcp.args.token`),issue #136 C。
184
+ *
185
+ * 语义:这些路径上的值**不是**用户在源机写空,而是导出侧 SecretScanner 剥掉的(占位符 = 空串),
186
+ * 目标机不得据此覆盖本机同叶子的非空值。写回侧据此精确保护(见
187
+ * `src/core/patch-secret-guard.ts`)。
188
+ *
189
+ * 兼容:字段只增不改。**缺省 = 未知**(老快照没有这个信息)→ 写回侧走保守分支
190
+ * (导入空 + 本机非空即保留本机),绝不假定「空值一定来自用户主动清空」。
191
+ */
192
+ redactedPaths?: string[];
182
193
  }
183
194
  /**
184
195
  * 本地源插件的打包产物(T1)。