dsh-config-manager 0.8.2 → 0.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (418) hide show
  1. package/lib/adapters/mcp.js +51 -15
  2. package/lib/adapters/messages.d.ts +1 -0
  3. package/lib/adapters/messages.js +2 -0
  4. package/lib/adapters/patch-key-guard.d.ts +23 -0
  5. package/lib/adapters/patch-key-guard.js +13 -0
  6. package/lib/adapters/plugin-data.d.ts +19 -5
  7. package/lib/adapters/plugin-data.js +76 -22
  8. package/lib/adapters/plugins.d.ts +14 -1
  9. package/lib/adapters/plugins.js +204 -6
  10. package/lib/adapters/prompts.js +15 -4
  11. package/lib/adapters/test-helpers.d.ts +15 -1
  12. package/lib/adapters/test-helpers.js +11 -0
  13. package/lib/cli/actions.d.ts +7 -105
  14. package/lib/cli/actions.js +16 -172
  15. package/lib/cli/control-state.d.ts +54 -0
  16. package/lib/cli/control-state.js +107 -0
  17. package/lib/cli/help.d.ts +1 -1
  18. package/lib/cli/help.js +21 -14
  19. package/lib/cli/index.js +132 -104
  20. package/lib/cli/sessions-repair.js +58 -22
  21. package/lib/cli/web/client-script.d.ts +1 -1
  22. package/lib/cli/web/client-script.js +71 -5
  23. package/lib/cli/web/page.d.ts +9 -19
  24. package/lib/cli/web/page.js +277 -173
  25. package/lib/cli/web/routes.js +85 -25
  26. package/lib/cli/write-gates.d.ts +61 -0
  27. package/lib/cli/write-gates.js +110 -0
  28. package/lib/client.d.ts +196 -75
  29. package/lib/client.js +8139 -7487
  30. package/lib/core/backup.d.ts +0 -4
  31. package/lib/core/backup.js +21 -4
  32. package/lib/core/boot-rescue.d.ts +1 -1
  33. package/lib/core/boot-rescue.js +12 -1
  34. package/lib/core/boot-safety.js +37 -2
  35. package/lib/core/conflict-decisions.js +2 -1
  36. package/lib/core/exporter.js +22 -1
  37. package/lib/core/journal.d.ts +54 -4
  38. package/lib/core/journal.js +158 -35
  39. package/lib/core/local-plugin-host.d.ts +29 -0
  40. package/lib/core/local-plugin-host.js +55 -48
  41. package/lib/core/messages.d.ts +17 -0
  42. package/lib/core/messages.js +34 -0
  43. package/lib/core/migration-history.js +16 -9
  44. package/lib/core/model-tools.d.ts +2 -2
  45. package/lib/core/model-tools.js +20 -2
  46. package/lib/core/patch-chain.d.ts +65 -0
  47. package/lib/core/patch-chain.js +100 -0
  48. package/lib/core/patch-document.d.ts +32 -4
  49. package/lib/core/patch-document.js +48 -17
  50. package/lib/core/patch-secret-guard.d.ts +49 -0
  51. package/lib/core/patch-secret-guard.js +164 -0
  52. package/lib/core/reconcile.d.ts +8 -0
  53. package/lib/core/reconcile.js +18 -3
  54. package/lib/core/reinstall.d.ts +2 -0
  55. package/lib/core/reinstall.js +6 -2
  56. package/lib/core/restore.js +31 -6
  57. package/lib/core/section-sanitize.d.ts +32 -0
  58. package/lib/core/section-sanitize.js +13 -0
  59. package/lib/core/snapshot-diff.d.ts +30 -0
  60. package/lib/core/snapshot-diff.js +56 -20
  61. package/lib/core/startup-barrier.js +8 -2
  62. package/lib/core/types.d.ts +38 -1
  63. package/lib/core/update-check.js +51 -2
  64. package/lib/foreign/kernel.js +9 -2
  65. package/lib/foreign/read-claude-plugins.js +29 -11
  66. package/lib/foreign/read-dsh.js +31 -2
  67. package/lib/foreign/session-ir.js +50 -9
  68. package/lib/foreign/session-read.d.ts +8 -0
  69. package/lib/foreign/session-read.js +26 -0
  70. package/lib/index.d.ts +9 -4
  71. package/lib/index.js +42 -47
  72. package/lib/profiles/dsh-profile-io.d.ts +20 -0
  73. package/lib/profiles/dsh-profile-io.js +27 -0
  74. package/lib/profiles/dsh-profile-manager.d.ts +27 -0
  75. package/lib/profiles/dsh-profile-manager.js +45 -4
  76. package/lib/profiles/dsh-profile-runtime.d.ts +5 -1
  77. package/lib/profiles/dsh-profile-runtime.js +16 -3
  78. package/lib/profiles/process-control.d.ts +18 -1
  79. package/lib/profiles/process-control.js +25 -1
  80. package/lib/routes/profiles.js +2 -1
  81. package/lib/routes/sync.js +19 -1
  82. package/lib/schema/types.d.ts +11 -0
  83. package/lib/security/redaction.js +22 -6
  84. package/lib/sync/autosync-repeat.d.ts +27 -0
  85. package/lib/sync/autosync-repeat.js +23 -0
  86. package/lib/sync/autosync-scheduler.d.ts +47 -2
  87. package/lib/sync/autosync-scheduler.js +217 -53
  88. package/lib/sync/baseline-heal.js +7 -0
  89. package/lib/sync/baseline-record.d.ts +67 -0
  90. package/lib/sync/baseline-record.js +74 -0
  91. package/lib/sync/blob-store.js +13 -0
  92. package/lib/sync/content-diff.d.ts +39 -0
  93. package/lib/sync/content-diff.js +46 -0
  94. package/lib/sync/git/git-transport.d.ts +32 -1
  95. package/lib/sync/git/git-transport.js +146 -26
  96. package/lib/sync/github-auth.d.ts +17 -1
  97. package/lib/sync/github-auth.js +37 -1
  98. package/lib/sync/local-changes.d.ts +15 -0
  99. package/lib/sync/local-changes.js +39 -0
  100. package/lib/sync/merge-apply-plan.d.ts +38 -0
  101. package/lib/sync/merge-apply-plan.js +76 -0
  102. package/lib/sync/merge-keyed.d.ts +68 -0
  103. package/lib/sync/merge-keyed.js +124 -0
  104. package/lib/sync/messages.d.ts +1 -0
  105. package/lib/sync/messages.js +2 -0
  106. package/lib/sync/patch-line-identity.d.ts +19 -0
  107. package/lib/sync/patch-line-identity.js +99 -0
  108. package/lib/sync/pending-merge.d.ts +41 -0
  109. package/lib/sync/pending-merge.js +61 -0
  110. package/lib/sync/plugin-removals.d.ts +15 -15
  111. package/lib/sync/plugin-removals.js +134 -83
  112. package/lib/sync/push-skip.d.ts +55 -0
  113. package/lib/sync/push-skip.js +70 -0
  114. package/lib/sync/s3/s3-transport.d.ts +14 -2
  115. package/lib/sync/s3/s3-transport.js +72 -48
  116. package/lib/sync/sync-engine.d.ts +44 -51
  117. package/lib/sync/sync-engine.js +160 -194
  118. package/lib/sync/sync-history.d.ts +7 -0
  119. package/lib/sync/sync-state.d.ts +28 -0
  120. package/lib/sync/sync-state.js +20 -0
  121. package/lib/sync/transport.d.ts +12 -3
  122. package/lib/sync/transport.js +13 -4
  123. package/lib/sync/webdav/webdav-transport.d.ts +19 -2
  124. package/lib/sync/webdav/webdav-transport.js +81 -40
  125. package/lib/sync/workspace-merge.d.ts +8 -2
  126. package/lib/ui/artifact-view.d.ts +1 -1
  127. package/lib/ui/commands.js +5 -11
  128. package/lib/ui/dsh-profiles-view.d.ts +8 -3
  129. package/lib/ui/dsh-profiles-view.js +9 -5
  130. package/lib/ui/foreign-view.d.ts +14 -0
  131. package/lib/ui/foreign-view.js +34 -0
  132. package/lib/ui/i18n.d.ts +7 -1
  133. package/lib/ui/i18n.js +15 -2
  134. package/lib/ui/menu-placement.js +1 -1
  135. package/lib/ui/migration-consult-view.d.ts +11 -0
  136. package/lib/ui/migration-consult-view.js +15 -0
  137. package/lib/ui/overview-view.d.ts +7 -0
  138. package/lib/ui/overview-view.js +3 -0
  139. package/lib/ui/report.d.ts +9 -0
  140. package/lib/ui/report.js +17 -4
  141. package/lib/ui/selection-model.d.ts +10 -2
  142. package/lib/ui/selection-model.js +23 -3
  143. package/lib/utils/async-once.d.ts +11 -0
  144. package/lib/utils/async-once.js +15 -0
  145. package/lib/utils/patch-chain-read.d.ts +51 -0
  146. package/lib/utils/patch-chain-read.js +240 -0
  147. package/lib/utils/patch-yaml.d.ts +39 -1
  148. package/lib/utils/patch-yaml.js +82 -2
  149. package/lib/utils/paths.d.ts +13 -0
  150. package/lib/utils/paths.js +35 -0
  151. package/lib/utils/workdir-lock.js +18 -3
  152. package/package.json +3 -2
  153. package/src/adapters/mcp.test.ts +29 -0
  154. package/src/adapters/mcp.ts +52 -14
  155. package/src/adapters/messages.ts +2 -0
  156. package/src/adapters/patch-key-guard.ts +29 -0
  157. package/src/adapters/plugin-data.test.ts +126 -0
  158. package/src/adapters/plugin-data.ts +97 -26
  159. package/src/adapters/plugins.test.ts +403 -0
  160. package/src/adapters/plugins.ts +198 -8
  161. package/src/adapters/prompts.ts +15 -4
  162. package/src/adapters/test-helpers.ts +15 -1
  163. package/src/cli/actions.test.ts +74 -1
  164. package/src/cli/actions.ts +27 -246
  165. package/src/cli/control-state.ts +143 -0
  166. package/src/cli/help.ts +21 -14
  167. package/src/cli/index.ts +123 -107
  168. package/src/cli/sessions-repair.ts +55 -22
  169. package/src/cli/web/client-script.ts +71 -5
  170. package/src/cli/web/page.ts +327 -208
  171. package/src/cli/web/routes.ts +85 -25
  172. package/src/cli/web/web.test.ts +65 -0
  173. package/src/cli/write-gates.ts +149 -0
  174. package/src/client/ConfigManagerSection.tsx +8 -4
  175. package/src/client/about/AboutPanel.tsx +9 -12
  176. package/src/client/about/release-notes-view.test.ts +17 -0
  177. package/src/client/about/release-notes-view.ts +49 -24
  178. package/src/client/api.ts +2 -1
  179. package/src/client/chat/ChatEntryView.tsx +2 -2
  180. package/src/client/chat/rollback-entry-view.ts +6 -1
  181. package/src/client/common/CommandPalette.tsx +6 -3
  182. package/src/client/common/ConfirmDialog.tsx +29 -12
  183. package/src/client/common/ContentPicker.tsx +24 -24
  184. package/src/client/common/Modal.tsx +12 -5
  185. package/src/client/common/MoreMenu.tsx +4 -1
  186. package/src/client/common/RunsCenter.tsx +103 -32
  187. package/src/client/common/Select.tsx +2 -2
  188. package/src/client/common/floating-bounds.ts +1 -1
  189. package/src/client/common/floating-units.test.ts +1 -2
  190. package/src/client/common/plan-text-redaction.test.ts +190 -5
  191. package/src/client/common/runs-center-guard.test.ts +60 -0
  192. package/src/client/common/runs-center-view.test.ts +128 -0
  193. package/src/client/common/runs-center-view.ts +96 -0
  194. package/src/client/common/section-title-action.test.ts +66 -0
  195. package/src/client/common/ui.tsx +93 -30
  196. package/src/client/config-manager.module.css +1515 -270
  197. package/src/client/consult/ConsultCard.tsx +7 -6
  198. package/src/client/environment/EnvironmentPanel.tsx +22 -25
  199. package/src/client/environment/maintenance/DiskUsageCard.tsx +69 -96
  200. package/src/client/environment/profiles-incomplete-ui.test.ts +8 -8
  201. package/src/client/export/ExportView.tsx +7 -16
  202. package/src/client/history/HistoryPanel.tsx +88 -28
  203. package/src/client/history/history-locales.ts +3 -3
  204. package/src/client/home/BackupScheduleCard.tsx +77 -69
  205. package/src/client/home/HomePanel.tsx +47 -12
  206. package/src/client/import/ConflictList.tsx +13 -13
  207. package/src/client/import/ForeignImportView.tsx +67 -9
  208. package/src/client/import/ImportWizardView.tsx +4 -4
  209. package/src/client/import/PathMappingForm.tsx +36 -9
  210. package/src/client/import/PathPickerDialog.tsx +2 -1
  211. package/src/client/import/import-wizard-split.test.ts +1 -1
  212. package/src/client/import/import-wizard-steps.tsx +51 -39
  213. package/src/client/import/use-import-wizard-controller.test.ts +129 -0
  214. package/src/client/import/use-import-wizard-controller.ts +116 -22
  215. package/src/client/library/ArtifactRow.tsx +2 -2
  216. package/src/client/library/BackupInspectView.tsx +21 -15
  217. package/src/client/library/LibraryActions.tsx +116 -28
  218. package/src/client/library/LibraryPanel.tsx +14 -15
  219. package/src/client/library/RestorePlanView.tsx +13 -8
  220. package/src/client/locales/about.ts +0 -2
  221. package/src/client/locales/backup.ts +15 -12
  222. package/src/client/locales/common.ts +2 -0
  223. package/src/client/locales/export.ts +5 -12
  224. package/src/client/locales/foreign.ts +4 -2
  225. package/src/client/locales/import.ts +5 -2
  226. package/src/client/locales/overview.ts +4 -0
  227. package/src/client/locales/profiles.ts +32 -4
  228. package/src/client/locales/restore.ts +2 -2
  229. package/src/client/locales/sessions.ts +0 -2
  230. package/src/client/locales/shell.ts +2 -2
  231. package/src/client/market/MarketImportReview.tsx +4 -4
  232. package/src/client/market/MarketPanel.tsx +58 -56
  233. package/src/client/market/MyConfigsList.tsx +34 -32
  234. package/src/client/market/MyConfigsLoginCard.tsx +12 -15
  235. package/src/client/market/MyConfigsView.tsx +8 -15
  236. package/src/client/market/MyConfigsWizard.tsx +7 -12
  237. package/src/client/market/market-locales.ts +0 -6
  238. package/src/client/market/my-configs-split.test.ts +2 -1
  239. package/src/client/nav-menu-clip-guard.test.ts +52 -0
  240. package/src/client/recovery/IncompleteCopiesSection.tsx +1 -3
  241. package/src/client/recovery/RecoveryPanel.tsx +35 -22
  242. package/src/client/recovery/RollbackCard.tsx +132 -75
  243. package/src/client/recovery/RollbackFileChanges.tsx +40 -27
  244. package/src/client/recovery/SessionHealthCard.tsx +2 -2
  245. package/src/client/recovery/SessionHealthDialog.tsx +5 -7
  246. package/src/client/recovery/SessionLayoutSection.tsx +3 -5
  247. package/src/client/recovery/recovery-locales.ts +12 -8
  248. package/src/client/recovery/rollback-enabled.ts +29 -0
  249. package/src/client/recovery/use-recovery-write.ts +5 -0
  250. package/src/client/run-store.test.ts +30 -0
  251. package/src/client/run-store.ts +21 -1
  252. package/src/client/sync/AddChannelCard.tsx +65 -0
  253. package/src/client/sync/AutosyncCard.tsx +184 -108
  254. package/src/client/sync/ChannelClearConfirmDialog.tsx +5 -1
  255. package/src/client/sync/ChannelConfigDialog.tsx +27 -48
  256. package/src/client/sync/MergePreviewView.tsx +5 -7
  257. package/src/client/sync/PushPreviewCard.tsx +2 -1
  258. package/src/client/sync/PushReportSections.tsx +35 -0
  259. package/src/client/sync/SyncChannelEntryCard.tsx +33 -24
  260. package/src/client/sync/SyncConfirmView.tsx +130 -133
  261. package/src/client/sync/SyncLogList.tsx +29 -14
  262. package/src/client/sync/SyncPanel.tsx +188 -185
  263. package/src/client/sync/SyncProbeRow.tsx +5 -7
  264. package/src/client/sync/SyncRepositoryPicker.tsx +17 -4
  265. package/src/client/sync/SyncSecuritySection.tsx +157 -0
  266. package/src/client/sync/SyncSettingsDialog.tsx +293 -0
  267. package/src/client/sync/SyncSettingsView.test.ts +26 -8
  268. package/src/client/sync/WorkDirCard.tsx +2 -4
  269. package/src/client/sync/config-clear-guard.test.ts +94 -0
  270. package/src/client/sync/config-clear-guard.ts +98 -0
  271. package/src/client/sync/config-dirty.test.ts +91 -0
  272. package/src/client/sync/config-dirty.ts +88 -0
  273. package/src/client/sync/history-model.test.ts +2 -0
  274. package/src/client/sync/history-model.ts +5 -0
  275. package/src/client/sync/merge-request.ts +20 -0
  276. package/src/client/sync/sync-api.ts +13 -1
  277. package/src/client/sync/sync-locales.ts +95 -47
  278. package/src/client/sync/sync-panel-clear.test.ts +44 -0
  279. package/src/client/sync/sync-push-preview.test.ts +9 -0
  280. package/src/client/sync/sync-view.test.ts +20 -0
  281. package/src/client/sync/sync-view.ts +76 -4
  282. package/src/core/backup.test.ts +61 -1
  283. package/src/core/backup.ts +21 -4
  284. package/src/core/boot-rescue.test.ts +35 -0
  285. package/src/core/boot-rescue.ts +13 -2
  286. package/src/core/boot-safety.test.ts +25 -0
  287. package/src/core/boot-safety.ts +37 -2
  288. package/src/core/conflict-decisions.ts +2 -1
  289. package/src/core/exporter.ts +21 -1
  290. package/src/core/journal.test.ts +183 -0
  291. package/src/core/journal.ts +163 -25
  292. package/src/core/local-plugin-host.test.ts +68 -2
  293. package/src/core/local-plugin-host.ts +31 -4
  294. package/src/core/messages.ts +34 -0
  295. package/src/core/migration-history.test.ts +27 -0
  296. package/src/core/migration-history.ts +12 -4
  297. package/src/core/model-tools.test.ts +67 -0
  298. package/src/core/model-tools.ts +22 -4
  299. package/src/core/patch-chain.test.ts +83 -0
  300. package/src/core/patch-chain.ts +150 -0
  301. package/src/core/patch-document.test.ts +48 -1
  302. package/src/core/patch-document.ts +66 -15
  303. package/src/core/patch-layers.test.ts +1 -1
  304. package/src/core/patch-secret-guard.test.ts +110 -0
  305. package/src/core/patch-secret-guard.ts +176 -0
  306. package/src/core/reconcile.ts +32 -4
  307. package/src/core/reinstall.ts +8 -2
  308. package/src/core/restore.ts +32 -7
  309. package/src/core/section-sanitize.ts +37 -0
  310. package/src/core/smoke.test.ts +2 -1
  311. package/src/core/snapshot-diff.test.ts +73 -1
  312. package/src/core/snapshot-diff.ts +66 -21
  313. package/src/core/startup-barrier.test.ts +64 -0
  314. package/src/core/startup-barrier.ts +8 -2
  315. package/src/core/types.ts +43 -2
  316. package/src/core/update-check.test.ts +40 -0
  317. package/src/core/update-check.ts +53 -2
  318. package/src/foreign/claude-code.test.ts +5 -0
  319. package/src/foreign/claude-plugins.test.ts +57 -0
  320. package/src/foreign/claude-sessions-bytes.test.ts +7 -1
  321. package/src/foreign/dsh.test.ts +23 -0
  322. package/src/foreign/kernel.ts +9 -2
  323. package/src/foreign/read-claude-plugins.ts +32 -11
  324. package/src/foreign/read-dsh.ts +33 -2
  325. package/src/foreign/session-ir.test.ts +67 -0
  326. package/src/foreign/session-ir.ts +54 -14
  327. package/src/foreign/session-read.ts +23 -0
  328. package/src/index.facade.test.ts +186 -6
  329. package/src/index.ts +53 -47
  330. package/src/profiles/dsh-profile-copy-rollback.test.ts +58 -4
  331. package/src/profiles/dsh-profile-io.ts +29 -0
  332. package/src/profiles/dsh-profile-manager.test.ts +30 -0
  333. package/src/profiles/dsh-profile-manager.ts +53 -5
  334. package/src/profiles/dsh-profile-runtime.test.ts +29 -7
  335. package/src/profiles/dsh-profile-runtime.ts +17 -3
  336. package/src/profiles/process-control.test.ts +97 -0
  337. package/src/profiles/process-control.ts +28 -1
  338. package/src/routes/profiles.ts +2 -1
  339. package/src/routes/sync.ts +19 -1
  340. package/src/schema/types.ts +16 -1
  341. package/src/security/redaction.test.ts +31 -0
  342. package/src/security/redaction.ts +23 -6
  343. package/src/security/security.test.ts +1 -1
  344. package/src/sync/autosync-repeat.test.ts +58 -0
  345. package/src/sync/autosync-repeat.ts +55 -0
  346. package/src/sync/autosync-scheduler.test.ts +515 -0
  347. package/src/sync/autosync-scheduler.ts +225 -51
  348. package/src/sync/baseline-heal.ts +6 -0
  349. package/src/sync/baseline-record.ts +135 -0
  350. package/src/sync/blob-store.test.ts +16 -0
  351. package/src/sync/blob-store.ts +13 -0
  352. package/src/sync/content-diff.test.ts +95 -0
  353. package/src/sync/content-diff.ts +79 -0
  354. package/src/sync/git/git-transport.test.ts +151 -4
  355. package/src/sync/git/git-transport.ts +143 -27
  356. package/src/sync/github-auth.test.ts +26 -1
  357. package/src/sync/github-auth.ts +37 -1
  358. package/src/sync/local-changes.ts +40 -0
  359. package/src/sync/merge-apply-plan.ts +117 -0
  360. package/src/sync/merge-keyed.test.ts +167 -0
  361. package/src/sync/merge-keyed.ts +160 -0
  362. package/src/sync/messages.ts +3 -0
  363. package/src/sync/patch-line-identity.test.ts +73 -0
  364. package/src/sync/patch-line-identity.ts +105 -0
  365. package/src/sync/pending-merge.test.ts +41 -0
  366. package/src/sync/pending-merge.ts +85 -0
  367. package/src/sync/plugin-removals.test.ts +199 -39
  368. package/src/sync/plugin-removals.ts +150 -64
  369. package/src/sync/push-skip.test.ts +326 -0
  370. package/src/sync/push-skip.ts +102 -0
  371. package/src/sync/s3/s3-delete-and-blob-index.test.ts +249 -0
  372. package/src/sync/s3/s3-transport.ts +76 -42
  373. package/src/sync/sync-config.test.ts +39 -12
  374. package/src/sync/sync-device-identity.test.ts +3 -0
  375. package/src/sync/sync-engine.test.ts +465 -12
  376. package/src/sync/sync-engine.ts +189 -193
  377. package/src/sync/sync-history.ts +7 -0
  378. package/src/sync/sync-state.ts +48 -0
  379. package/src/sync/transport.test.ts +13 -1
  380. package/src/sync/transport.ts +12 -4
  381. package/src/sync/webdav/webdav-delete-and-blob-index.test.ts +249 -0
  382. package/src/sync/webdav/webdav-transport.ts +86 -34
  383. package/src/sync/workspace-merge.ts +9 -2
  384. package/src/ui/artifact-view.ts +1 -1
  385. package/src/ui/commands.test.ts +11 -0
  386. package/src/ui/commands.ts +5 -14
  387. package/src/ui/dsh-profiles-view.test.ts +16 -0
  388. package/src/ui/dsh-profiles-view.ts +11 -5
  389. package/src/ui/foreign-view.test.ts +49 -0
  390. package/src/ui/foreign-view.ts +47 -0
  391. package/src/ui/i18n.ts +15 -2
  392. package/src/ui/menu-placement.ts +1 -1
  393. package/src/ui/migration-consult-view.test.ts +20 -1
  394. package/src/ui/migration-consult-view.ts +17 -0
  395. package/src/ui/overview-view.ts +10 -0
  396. package/src/ui/report.test.ts +25 -1
  397. package/src/ui/report.ts +15 -4
  398. package/src/ui/selection-model.test.ts +29 -1
  399. package/src/ui/selection-model.ts +25 -4
  400. package/src/utils/async-once.ts +14 -0
  401. package/src/utils/js-yaml4.d.ts +35 -0
  402. package/src/utils/patch-chain-read.test.ts +171 -0
  403. package/src/utils/patch-chain-read.ts +259 -0
  404. package/src/utils/patch-yaml.test.ts +215 -3
  405. package/src/utils/patch-yaml.ts +98 -2
  406. package/src/utils/paths.test.ts +14 -1
  407. package/src/utils/paths.ts +35 -0
  408. package/src/utils/workdir-lock.test.ts +69 -0
  409. package/src/utils/workdir-lock.ts +17 -3
  410. package/lib/ui/path-mapping.d.ts +0 -38
  411. package/lib/ui/path-mapping.js +0 -75
  412. package/src/client/common/InfoHint.tsx +0 -289
  413. package/src/client/common/info-hint-guard.test.ts +0 -1119
  414. package/src/client/sync/DecryptPasswordCard.tsx +0 -48
  415. package/src/client/sync/SecurityOptionsCard.tsx +0 -97
  416. package/src/client/sync/SyncSectionPickerDialog.tsx +0 -213
  417. package/src/ui/path-mapping.test.ts +0 -67
  418. package/src/ui/path-mapping.ts +0 -103
@@ -20,7 +20,7 @@ import {
20
20
  EXPORTS_RETENTION_DEFAULT_MS, MARKET_RETENTION_DEFAULT_MS, TMP_RETENTION_DEFAULT_MS,
21
21
  } from '../core/cache-cleaner.ts'
22
22
  import { scanDiskUsage, type DiskUsageDirs, type DiskUsageReport } from '../core/disk-usage.ts'
23
- import { readSafeModeMarkerSync, safeModeMarkerPath } from '../core/phase3-host.ts'
23
+ import { readSafeModeMarkerSync } from '../core/phase3-host.ts'
24
24
  import { listSnapshots, type SnapshotMeta } from '../core/restore.ts'
25
25
  import { readInstalledVersion, resolveProfileDir } from '../core/plugin-cli.ts'
26
26
  import { DshProfileError, DshProfileManager } from '../profiles/dsh-profile-manager.ts'
@@ -31,75 +31,20 @@ import { readTextSafe } from '../profiles/dsh-profile-io.ts'
31
31
  import {
32
32
  AUTO_BACKUP_PREFIX, DEFAULT_BACKUP_RETENTION, listBackupFiles, type BackupFileMeta,
33
33
  } from '../sync/backup-files.ts'
34
- import { EnvironmentLockManager, OWNERSHIP_FILE } from '../utils/env-lock.ts'
35
34
  import { scanSessionHealth, type SessionHealthScanResult } from '../utils/session-health-scan.ts'
36
35
  import type { SessionVerifyResult } from '../utils/session-verify.ts'
37
36
  import { formatDateStamp } from '../utils/time.ts'
38
37
 
39
- /* ------------------------------------------------------------ 进程/实例事实 */
40
-
41
- /** 进程是否存活(不发送信号,只探测)。EPERM = 存在但无权限发信号 → 仍算存活。 */
42
- export function isProcessAlive(pid: number): boolean {
43
- try {
44
- process.kill(pid, 0)
45
- return true
46
- } catch (error) {
47
- return (error as NodeJS.ErrnoException).code === 'EPERM'
48
- }
49
- }
50
-
51
- /** 一个在跑的 DSH 实例(来自 `<root>/running/<profile>.json` 心跳)。 */
52
- export interface RunningInstance {
53
- name: string
54
- pid: number
55
- port: number | null
56
- startedAt: string
57
- updatedAt: number
58
- }
59
-
60
- /**
61
- * 读「本机正在跑的 DSH 实例」。
62
- *
63
- * **为什么按候选根扫描**:心跳在 `<插件 dataDir>/running/`,而 CLI 的 `--data-dir` 语义是
64
- * 「快照目录」(缺省 `$DSH_HOME/dsh-config-manager/snapshots`)。旧实现把快照目录当 dataDir 用,
65
- * 于是缺省路径下**永远找不到心跳** —— 那道「DSH 在跑就别写会话字节」的门形同虚设(fail-open)。
66
- * 这里改为复用 `resolveControlRoots` 的候选根:显式 `--data-root` 只认它,否则同时看
67
- * `--data-dir` 本身与它的父目录,再叠加缺省根;多查几处只会更保守。
68
- */
69
- export async function readRunningInstances(controlRoots: readonly string[]): Promise<RunningInstance[]> {
70
- const alive: RunningInstance[] = []
71
- const seen = new Set<string>()
72
- const now = Date.now()
73
- for (const root of controlRoots) {
74
- const dir = path.join(root, 'running')
75
- let names: string[]
76
- try {
77
- names = (await fsp.readdir(dir)).filter((n) => n.endsWith('.json'))
78
- } catch {
79
- continue // 该候选根没有心跳目录:正常情况,不阻断
80
- }
81
- for (const name of names) {
82
- try {
83
- const record = parseRuntimeRecord(await fsp.readFile(path.join(dir, name), 'utf8'))
84
- if (record === null) continue
85
- if (!isProcessAlive(record.pid) || now - record.updatedAt > RUNTIME_STALE_MS) continue
86
- const key = record.name + '#' + String(record.pid)
87
- if (seen.has(key)) continue
88
- seen.add(key)
89
- alive.push({
90
- name: record.name,
91
- pid: record.pid,
92
- port: record.port,
93
- startedAt: record.startedAt,
94
- updatedAt: record.updatedAt,
95
- })
96
- } catch {
97
- // 单条心跳读不出来不阻断(best-effort)
98
- }
99
- }
100
- }
101
- return alive
102
- }
38
+ // 只读事实层与写入门已拆到独立模块(体量棘轮:本文件曾顶格 1574 行),re-export 保持既有调用点不变。
39
+ import {
40
+ isProcessAlive, readLockState, readRunningInstances, readSafeMode,
41
+ type LockReport, type RunningInstance, type SafeModeReport,
42
+ } from './control-state.ts'
43
+ import { checkWriteGates, locksDirFromControlRoots } from './write-gates.ts'
44
+ export { isProcessAlive, readLockState, readRunningInstances, readSafeMode } from './control-state.ts'
45
+ export type { LockReport, RunningInstance, SafeModeReport } from './control-state.ts'
46
+ export { checkWriteGates, SAFE_MODE_REFUSAL_CODE, locksDirFromControlRoots } from './write-gates.ts'
47
+ export type { WriteGateOutcome, WriteGateRefusal, WriteRefusalCode } from './write-gates.ts'
103
48
 
104
49
  /* ------------------------------------------------------------ 备份自检(verify) */
105
50
 
@@ -232,69 +177,6 @@ export async function readSessionsHealth(homeDir: string): Promise<SessionsHealt
232
177
  }
233
178
  }
234
179
 
235
- /* ------------------------------------------------------------ SAFE MODE / 环境锁 */
236
-
237
- export interface SafeModeReport {
238
- /** 候选控制面根 */
239
- root: string
240
- /** 标记文件绝对路径(写进界面,便于人工核对) */
241
- marker: string
242
- /** clear = 明确没有标记;blocked = 有未结案的 transaction;unknown = 读不出来(按阻断处理) */
243
- state: ReturnType<typeof readSafeModeMarkerSync>
244
- /**
245
- * 该候选根下是否已经存在有效的「控制面目录」(dataDir 或 transactions)。
246
- *
247
- * 为什么需要:候选根里绝大多数**本来就不存在**(`--data-dir` 的父目录、缺省根都可能没有),
248
- * 那些根的 'clear' 只是「这里什么都没建」,把它当成「SAFE MODE 未激活」的正面证据是把
249
- * 「没查」说成「没问题」。界面只在**有效根**上给绿灯,其余如实说「未建立 / 未发现标记」。
250
- */
251
- established: boolean
252
- }
253
-
254
- /** 逐个候选根读 SAFE MODE 标记(fail-closed 的判定仍在 CLI/core;这里只报事实)。 */
255
- export function readSafeMode(controlRoots: readonly string[]): SafeModeReport[] {
256
- return controlRoots.map((root) => ({
257
- root,
258
- marker: safeModeMarkerPath(root),
259
- state: readSafeModeMarkerSync(root),
260
- established: fssync.existsSync(root) || fssync.existsSync(path.join(root, 'transactions')),
261
- }))
262
- }
263
-
264
- export interface LockReport {
265
- locksDir: string
266
- /** 锁文件是否存在(不存在 = 没有活动锁) */
267
- present: boolean
268
- /** 没有锁时恒为 'NONE';否则为 inspectLockState 的结论 */
269
- state: string
270
- detail?: string
271
- }
272
-
273
- /**
274
- * 读环境锁状态(只读)。
275
- *
276
- * 复用宿主/CLI 同一套 `inspectLockState`:**绝不**因为「看起来是残留」就自动回收 ——
277
- * 回收只有显式命令一条路(`recover-stale-lock`)。
278
- */
279
- export async function readLockState(locksDir: string): Promise<LockReport> {
280
- const present = await pathExists(path.join(locksDir, OWNERSHIP_FILE))
281
- if (!present) return { locksDir, present: false, state: 'NONE' }
282
- const lock = new EnvironmentLockManager({ locksDir, op: 'rescue-console-inspect', target: locksDir, lockVersion: '0.1.0' })
283
- const inspection = await lock.inspectLockState()
284
- return inspection.detail === undefined
285
- ? { locksDir, present: true, state: inspection.state }
286
- : { locksDir, present: true, state: inspection.state, detail: inspection.detail }
287
- }
288
-
289
- async function pathExists(target: string): Promise<boolean> {
290
- try {
291
- await fsp.stat(target)
292
- return true
293
- } catch {
294
- return false
295
- }
296
- }
297
-
298
180
  /* ------------------------------------------------------------ 首页聚合 */
299
181
 
300
182
  /** 救急台首页所需的路径事实(由 CLI 侧解析后注入,保证与各子命令同一口径)。 */
@@ -389,119 +271,6 @@ function errorText(error: unknown): string {
389
271
  - 回执如实:完成、失败、跳过分别列出,绝不把「没做」说成「做了」。
390
272
  */
391
273
 
392
- export type WriteRefusalCode =
393
- | 'safe-mode'
394
- | 'stale-lock'
395
- | 'dsh-running'
396
- | 'nothing-to-do'
397
- | 'io-error'
398
-
399
- /**
400
- * SAFE MODE 拒因码的**单点常量**:`src/cli/index.ts` 的源码守卫(P0-11-07)禁止
401
- * CLI 自带 `'safe-mode'` 字面量,判据必须复用本常量(否则改一处漏一处)。
402
- */
403
- export const SAFE_MODE_REFUSAL_CODE: WriteRefusalCode = 'safe-mode'
404
-
405
- export interface WriteGateRefusal {
406
- ok: false
407
- code: WriteRefusalCode
408
- /** 用户可读原因(页面直接展示) */
409
- reason: string
410
- /**
411
- * 拒因的结构化明细(页面据此给出「怎么解除」的可操作指引,而不是只丢一句 reason)。
412
- *
413
- * 为什么要有:`dsh-running` 是最常被撞到的一道门,光给「请先关闭 DSH」用户会问
414
- * 「关哪个、怎么确认关掉了」。这里把**是谁在跑**(心跳台账里的 profile/pid/端口)
415
- * 如实带出来 —— 只读事实,不猜、不代关进程。
416
- */
417
- detail?: {
418
- kind: 'dsh-running' | 'stale-lock' | 'safe-mode'
419
- /** 正在运行的实例(心跳合并视图:本插件启动的 + 手动启动的) */
420
- instances?: Array<{ name: string; pid: number; port: number | null }>
421
- /** 环境锁状态(kind = 'stale-lock') */
422
- lock?: { state: string; locksDir: string }
423
- /** SAFE MODE 标记文件(kind = 'safe-mode') */
424
- markers?: string[]
425
- /** 与 CLI 逐字同源的等价命令(可复制去终端跑) */
426
- commands: string[]
427
- }
428
- }
429
-
430
- export type WriteGateOutcome = { ok: true } | WriteGateRefusal
431
-
432
- /**
433
- * 写动作的前置门(与 CLI `sessions repair --fix` 同一判据)。
434
- *
435
- * `needsDshStopped`:**改写/搬动会话字节**的动作(会话布局归位 repairSessions、字节级就地修复
436
- * repairSessionLogInline)与**快照恢复**(runSnapshotRestore 会覆盖/删除 `$DSH_HOME` 下正在使用的文件)
437
- * 都要「DSH 已停」这一条;磁盘清理不需要(只碰可重建缓存)。
438
- */
439
- export async function checkWriteGates(
440
- controlRoots: readonly string[],
441
- options: { needsDshStopped: boolean; locksDir?: string } = { needsDshStopped: true },
442
- ): Promise<WriteGateOutcome> {
443
- for (const report of readSafeMode(controlRoots)) {
444
- if (report.state === 'blocked') {
445
- return {
446
- ok: false,
447
- code: 'safe-mode',
448
- reason: 'SAFE MODE 已激活(存在未结案的配置 transaction):先处理恢复事项再改磁盘。标记:' + report.marker,
449
- }
450
- }
451
- if (report.state === 'unknown') {
452
- return {
453
- ok: false,
454
- code: 'safe-mode',
455
- reason: 'SAFE MODE 标记无法判定(按最保守口径处理):先人工核对标记文件。路径:' + report.marker,
456
- }
457
- }
458
- }
459
- /**
460
- * ② 环境锁:**存在锁就必须先处理**。
461
- *
462
- * 为什么不能跳过:CLI 侧 destructive 入口(restore/reinstall)都要求成功获取 GLOBAL 环境锁,
463
- * 而残留锁(STALE_LOCK_DETECTED)正是「上次异常退出、别的操作也被挡着」的状态;
464
- * 这时改磁盘等于在一个已知不一致的状态上继续写。判据与 `recover-stale-lock` 同源(inspectLockState),
465
- * 所以**不给自动回收**,只如实拒绝并把出口指出来。
466
- */
467
- if (options.locksDir !== undefined) {
468
- const lock = await readLockState(options.locksDir)
469
- if (lock.present) {
470
- const stale = lock.state === 'STALE_LOCK_DETECTED'
471
- return {
472
- ok: false,
473
- code: 'stale-lock',
474
- reason: (stale
475
- ? '检测到残留的环境锁(持有进程已被确证不存在):先回收它再执行写动作。'
476
- : '环境锁被持有或状态无法判定(' + lock.state + '):先确认没有其它操作在跑,再执行写动作。')
477
- + '锁目录:' + lock.locksDir + ';出口:dsh-config-manager recover-stale-lock(本机救急台的「环境锁」页也可回收)。',
478
- }
479
- }
480
- }
481
- if (options.needsDshStopped) {
482
- const running = await readRunningInstances(controlRoots)
483
- if (running.length > 0) {
484
- return {
485
- ok: false,
486
- code: 'dsh-running',
487
- reason: '检测到 DSH 正在运行(' + running.map((i) => i.name + ' pid=' + String(i.pid)).join('、')
488
- + '):请先关闭 DSH 再改写会话字节。',
489
- detail: {
490
- kind: 'dsh-running',
491
- instances: running.map((i) => ({ name: i.name, pid: i.pid, port: i.port })),
492
- commands: [
493
- // 桌面端独占档案不让普通 CLI 停,如实给出「关窗口」这条唯一通道(见 AGENTS.md 的 desktop 条)
494
- ...running.filter((i) => i.name === 'desktop').map(() => '桌面端(desktop):直接关闭 DSH 桌面窗口;它不接受命令行停止'),
495
- ...running.filter((i) => i.name !== 'desktop').map((i) => 'dsh-config-manager stop ' + i.name + ' # 或在「档案与实例」页点「停止 ' + i.name + '」'),
496
- 'dsh-config-manager web # 停完再回本页点「重新检查」',
497
- ],
498
- },
499
- }
500
- }
501
- }
502
- return { ok: true }
503
- }
504
-
505
274
  /** 会话修复步骤的机器可读形态(页面渲染用;CLI 走它自己的文本输出)。 */
506
275
  export interface RepairStep {
507
276
  kind: 'move' | 'rewrite-move' | 'quarantine' | 'skip'
@@ -662,7 +431,12 @@ export function sessionRepairRowMessage(facts: SessionRepairRowFacts): string {
662
431
  * 而 `session-repair-service` 的 CLI 出入口此前只挂在应用内通道上 —— 离线时用户只能敲命令。
663
432
  */
664
433
  export async function repairSessionLogInline(
665
- options: { home: string; dataDir: string; unitIds: readonly string[]; apply: boolean; expects?: Record<string, { size: number; mtimeMs: number }> },
434
+ options: {
435
+ home: string; dataDir: string; unitIds: readonly string[]; apply: boolean
436
+ expects?: Record<string, { size: number; mtimeMs: number }>
437
+ /** 环境锁目录(缺省由 controlRoots 派生;显式给出时优先) */
438
+ locksDir?: string
439
+ },
666
440
  controlRoots: readonly string[],
667
441
  ): Promise<InlineRepairOutcome> {
668
442
  const base: InlineRepairOutcome = {
@@ -675,8 +449,13 @@ export async function repairSessionLogInline(
675
449
  }
676
450
  if (options.unitIds.length === 0) return { ...base, ok: false, error: '没有选中任何会话单元。' }
677
451
  if (options.apply) {
678
- // 与 CLI 写动作共用同一道写入门:改写会话字节必须先停 DSH(+ SAFE MODE + 环境锁)
679
- const gate = await checkWriteGates(controlRoots, { needsDshStopped: true })
452
+ // 与 CLI 写动作共用同一道写入门:改写会话字节必须先停 DSH(+ SAFE MODE + 环境锁)。
453
+ // 环境锁目录由控制面根派生(审计 P11-4:此前不传 locksDir,锁存在时也照样改写字节)。
454
+ const locksDir = options.locksDir ?? locksDirFromControlRoots(controlRoots)
455
+ const gate = await checkWriteGates(controlRoots, {
456
+ needsDshStopped: true,
457
+ ...(locksDir !== undefined ? { locksDir } : {}),
458
+ })
680
459
  if (!gate.ok) return { ...base, ok: false, error: gate.reason }
681
460
  }
682
461
  const svc = await import('../utils/session-repair-service.ts')
@@ -741,9 +520,11 @@ export async function repairSessions(
741
520
  done: [], errors: [], notices: [],
742
521
  }
743
522
  if (options.fix) {
523
+ // 环境锁目录同样由根派生:调用点漏传时不再静默跳过环境锁检查(与 repairSessionLogInline 同一口径)
524
+ const locksDir = options.locksDir ?? locksDirFromControlRoots(controlRoots)
744
525
  const gate = await checkWriteGates(controlRoots, {
745
526
  needsDshStopped: true,
746
- ...(options.locksDir !== undefined ? { locksDir: options.locksDir } : {}),
527
+ ...(locksDir !== undefined ? { locksDir } : {}),
747
528
  })
748
529
  if (!gate.ok) {
749
530
  return { ...base, ok: false, error: gate.reason, errors: [gate.reason] }
@@ -0,0 +1,143 @@
1
+ /**
2
+ * 救急台与 CLI 共用的**只读事实层**:进程存活、心跳实例、SAFE MODE 标记、环境锁状态。
3
+ *
4
+ * 为什么单独成文件:这四件事是「写动作前置门」与首页聚合共同依赖的最小事实集,原先挤在
5
+ * 1600 行的 actions.ts 里(体量棘轮已顶格)。这里**只放读取**,判据仍只由 core/utils 给,
6
+ * 绝不因为「看起来像残留」就自行回收(回收只有显式命令一条路)。
7
+ */
8
+ import fssync from 'node:fs'
9
+ import fsp from 'node:fs/promises'
10
+ import path from 'node:path'
11
+
12
+ import { readSafeModeMarkerSync, safeModeMarkerPath } from '../core/phase3-host.ts'
13
+ import { parseRuntimeRecord, RUNTIME_STALE_MS } from '../profiles/dsh-profile-runtime.ts'
14
+ import { EnvironmentLockManager, OWNERSHIP_FILE } from '../utils/env-lock.ts'
15
+
16
+
17
+ /* ------------------------------------------------------------ 进程/实例事实 */
18
+
19
+ /** 进程是否存活(不发送信号,只探测)。EPERM = 存在但无权限发信号 → 仍算存活。 */
20
+ export function isProcessAlive(pid: number): boolean {
21
+ try {
22
+ process.kill(pid, 0)
23
+ return true
24
+ } catch (error) {
25
+ return (error as NodeJS.ErrnoException).code === 'EPERM'
26
+ }
27
+ }
28
+
29
+ /** 一个在跑的 DSH 实例(来自 `<root>/running/<profile>.json` 心跳)。 */
30
+ export interface RunningInstance {
31
+ name: string
32
+ pid: number
33
+ port: number | null
34
+ startedAt: string
35
+ updatedAt: number
36
+ }
37
+
38
+ /**
39
+ * 读「本机正在跑的 DSH 实例」。
40
+ *
41
+ * **为什么按候选根扫描**:心跳在 `<插件 dataDir>/running/`,而 CLI 的 `--data-dir` 语义是
42
+ * 「快照目录」(缺省 `$DSH_HOME/dsh-config-manager/snapshots`)。旧实现把快照目录当 dataDir 用,
43
+ * 于是缺省路径下**永远找不到心跳** —— 那道「DSH 在跑就别写会话字节」的门形同虚设(fail-open)。
44
+ * 这里改为复用 `resolveControlRoots` 的候选根:显式 `--data-root` 只认它,否则同时看
45
+ * `--data-dir` 本身与它的父目录,再叠加缺省根;多查几处只会更保守。
46
+ */
47
+ export async function readRunningInstances(controlRoots: readonly string[]): Promise<RunningInstance[]> {
48
+ const alive: RunningInstance[] = []
49
+ const seen = new Set<string>()
50
+ const now = Date.now()
51
+ for (const root of controlRoots) {
52
+ const dir = path.join(root, 'running')
53
+ let names: string[]
54
+ try {
55
+ names = (await fsp.readdir(dir)).filter((n) => n.endsWith('.json'))
56
+ } catch {
57
+ continue // 该候选根没有心跳目录:正常情况,不阻断
58
+ }
59
+ for (const name of names) {
60
+ try {
61
+ const record = parseRuntimeRecord(await fsp.readFile(path.join(dir, name), 'utf8'))
62
+ if (record === null) continue
63
+ if (!isProcessAlive(record.pid) || now - record.updatedAt > RUNTIME_STALE_MS) continue
64
+ const key = record.name + '#' + String(record.pid)
65
+ if (seen.has(key)) continue
66
+ seen.add(key)
67
+ alive.push({
68
+ name: record.name,
69
+ pid: record.pid,
70
+ port: record.port,
71
+ startedAt: record.startedAt,
72
+ updatedAt: record.updatedAt,
73
+ })
74
+ } catch {
75
+ // 单条心跳读不出来不阻断(best-effort)
76
+ }
77
+ }
78
+ }
79
+ return alive
80
+ }
81
+
82
+ /* ------------------------------------------------------------ SAFE MODE / 环境锁 */
83
+
84
+ export interface SafeModeReport {
85
+ /** 候选控制面根 */
86
+ root: string
87
+ /** 标记文件绝对路径(写进界面,便于人工核对) */
88
+ marker: string
89
+ /** clear = 明确没有标记;blocked = 有未结案的 transaction;unknown = 读不出来(按阻断处理) */
90
+ state: ReturnType<typeof readSafeModeMarkerSync>
91
+ /**
92
+ * 该候选根下是否已经存在有效的「控制面目录」(dataDir 或 transactions)。
93
+ *
94
+ * 为什么需要:候选根里绝大多数**本来就不存在**(`--data-dir` 的父目录、缺省根都可能没有),
95
+ * 那些根的 'clear' 只是「这里什么都没建」,把它当成「SAFE MODE 未激活」的正面证据是把
96
+ * 「没查」说成「没问题」。界面只在**有效根**上给绿灯,其余如实说「未建立 / 未发现标记」。
97
+ */
98
+ established: boolean
99
+ }
100
+
101
+ /** 逐个候选根读 SAFE MODE 标记(fail-closed 的判定仍在 CLI/core;这里只报事实)。 */
102
+ export function readSafeMode(controlRoots: readonly string[]): SafeModeReport[] {
103
+ return controlRoots.map((root) => ({
104
+ root,
105
+ marker: safeModeMarkerPath(root),
106
+ state: readSafeModeMarkerSync(root),
107
+ established: fssync.existsSync(root) || fssync.existsSync(path.join(root, 'transactions')),
108
+ }))
109
+ }
110
+
111
+ export interface LockReport {
112
+ locksDir: string
113
+ /** 锁文件是否存在(不存在 = 没有活动锁) */
114
+ present: boolean
115
+ /** 没有锁时恒为 'NONE';否则为 inspectLockState 的结论 */
116
+ state: string
117
+ detail?: string
118
+ }
119
+
120
+ /**
121
+ * 读环境锁状态(只读)。
122
+ *
123
+ * 复用宿主/CLI 同一套 `inspectLockState`:**绝不**因为「看起来是残留」就自动回收 ——
124
+ * 回收只有显式命令一条路(`recover-stale-lock`)。
125
+ */
126
+ export async function readLockState(locksDir: string): Promise<LockReport> {
127
+ const present = await pathExists(path.join(locksDir, OWNERSHIP_FILE))
128
+ if (!present) return { locksDir, present: false, state: 'NONE' }
129
+ const lock = new EnvironmentLockManager({ locksDir, op: 'rescue-console-inspect', target: locksDir, lockVersion: '0.1.0' })
130
+ const inspection = await lock.inspectLockState()
131
+ return inspection.detail === undefined
132
+ ? { locksDir, present: true, state: inspection.state }
133
+ : { locksDir, present: true, state: inspection.state, detail: inspection.detail }
134
+ }
135
+
136
+ async function pathExists(target: string): Promise<boolean> {
137
+ try {
138
+ await fsp.stat(target)
139
+ return true
140
+ } catch {
141
+ return false
142
+ }
143
+ }
package/src/cli/help.ts CHANGED
@@ -69,11 +69,10 @@ export interface HelpGroup {
69
69
  readonly rows: readonly HelpRow[];
70
70
  }
71
71
 
72
- /** 通用选项(所有命令共有)——命令专属选项只出现在各自的详情页里 */
72
+ /** 通用选项(所有命令共有)——范围仅限少数命令的参数(如 --home 仅用于 web/sessions)写在各自详情页 */
73
73
  export const GENERAL_OPTIONS: readonly HelpEntry[] = [
74
- { flag: '--data-dir <dir>', desc: '快照 / 导出目录(缺省 $DSH_HOME/dsh-config-manager/snapshots)' },
74
+ { flag: '--data-dir <dir>', desc: '快照 / 导出 / 锁推导目录(缺省 $DSH_HOME/dsh-config-manager/<subdir>)' },
75
75
  { flag: '--data-root <dir>', desc: '插件数据根 dataDir(自定义时必须显式传;缺省 $DSH_HOME/dsh-config-manager)' },
76
- { flag: '--home <dir>', desc: 'DSH home(缺省 $DSH_HOME,即 ~/.dsh)' },
77
76
  { flag: '-h, --help', desc: '显示本页帮助' },
78
77
  ];
79
78
 
@@ -192,7 +191,7 @@ export const COMMAND_HELP: readonly CommandHelp[] = [
192
191
  title: '列出导入前的安全快照',
193
192
  usage: 'snapshots',
194
193
  summary: '列出导入前快照',
195
- usageLines: ['snapshots [--data-dir <dir>]'],
194
+ usageLines: ['snapshots [--data-dir <dir>] [--data-root <dir>]'],
196
195
  description: [
197
196
  '快照是每次导入前自动留下的整机配置副本;本命令只读,按新→旧列出:',
198
197
  'ID / 创建时间 / 来源 ZIP / 状态 / 条目数 / 宿主文件数 / 插件数。',
@@ -204,6 +203,7 @@ export const COMMAND_HELP: readonly CommandHelp[] = [
204
203
  title: '选项',
205
204
  entries: [
206
205
  { flag: '--data-dir <dir>', desc: '快照目录(缺省 $DSH_HOME/dsh-config-manager/snapshots)' },
206
+ { flag: '--data-root <dir>', desc: '插件数据根 dataDir(自定义时必须显式传)' },
207
207
  { flag: '-h, --help', desc: '显示本页' },
208
208
  ],
209
209
  },
@@ -222,7 +222,7 @@ export const COMMAND_HELP: readonly CommandHelp[] = [
222
222
  title: '只读自检备份 ZIP',
223
223
  usage: 'verify [<file|path>]',
224
224
  summary: '只读自检备份 ZIP(无参 = 导出目录全部)',
225
- usageLines: ['verify [<file|path> | --id <file|path>] [--json] [--data-dir <dir>]'],
225
+ usageLines: ['verify [<file|path> | --id <file|path>] [--json] [--data-dir <dir>] [--data-root <dir>]'],
226
226
  description: [
227
227
  '重新读取备份 ZIP,核对结构与 integrity/checksums.json 的逐条 SHA-256;全程零写入。',
228
228
  '无参数时校验导出目录下全部 *.zip;也可以给一个文件名或完整路径。',
@@ -245,6 +245,7 @@ export const COMMAND_HELP: readonly CommandHelp[] = [
245
245
  { flag: '--json', desc: '机器可读输出(退出码仍为 0/1;出错的 JSON 也走 stdout)' },
246
246
  { flag: '--id <file|path>', desc: '待校验目标(文件名或路径);与位置参数同义,同时给出时以 --id 为准' },
247
247
  { flag: '--data-dir <dir>', desc: '导出目录(缺省 $DSH_HOME/dsh-config-manager/exports)' },
248
+ { flag: '--data-root <dir>', desc: '插件数据根 dataDir(自定义时必须显式传)' },
248
249
  { flag: '-h, --help', desc: '显示本页' },
249
250
  ],
250
251
  },
@@ -263,7 +264,7 @@ export const COMMAND_HELP: readonly CommandHelp[] = [
263
264
  title: '离线文件级备份',
264
265
  usage: 'backup',
265
266
  summary: '离线文件级备份(写出后自动自检)',
266
- usageLines: ['backup [--sections <a,b,c>] [--out <path>] [--dry-run] [--data-dir <dir>]'],
267
+ usageLines: ['backup [--sections <a,b,c>] [--out <path>] [--dry-run] [--data-dir <dir>] [--data-root <dir>]'],
267
268
  description: [
268
269
  '把不需要 DSH 运行时就能读的分区打包成 ZIP,结构与 GUI 导出一致:',
269
270
  'manifest.json + integrity/checksums.json + 分区目录;落盘后立刻用 verify 同一引擎自检。',
@@ -279,6 +280,7 @@ export const COMMAND_HELP: readonly CommandHelp[] = [
279
280
  { flag: '--out <path>', desc: '输出 ZIP 路径(缺省导出目录自动命名,绝不覆盖既有文件)' },
280
281
  { flag: '--dry-run', desc: '只打印待打包清单,零写入' },
281
282
  { flag: '--data-dir <dir>', desc: '导出目录(缺省 $DSH_HOME/dsh-config-manager/exports)' },
283
+ { flag: '--data-root <dir>', desc: '插件数据根 dataDir(自定义时必须显式传)' },
282
284
  { flag: '-h, --help', desc: '显示本页' },
283
285
  ],
284
286
  },
@@ -301,7 +303,7 @@ export const COMMAND_HELP: readonly CommandHelp[] = [
301
303
  title: '外部 agent 配置 → 标准 bundle ZIP',
302
304
  usage: 'import --from <source>',
303
305
  summary: '外部 agent 配置 → 标准 bundle ZIP',
304
- usageLines: ['import --from <source> [--dry-run] [--out <path>] [--cwd <dir>] [--data-dir <dir>]'],
306
+ usageLines: ['import --from <source> [--dry-run] [--out <path>] [--cwd <dir>] [--data-dir <dir>] [--data-root <dir>]'],
305
307
  description: IMPORT_DESCRIPTION,
306
308
  sections: [
307
309
  {
@@ -312,6 +314,7 @@ export const COMMAND_HELP: readonly CommandHelp[] = [
312
314
  { flag: '--out <path>', desc: '输出 ZIP 路径(缺省导出目录自动命名,绝不覆盖)' },
313
315
  { flag: '--cwd <dir>', desc: '项目级配置所在目录(缺省 = 进程当前目录)' },
314
316
  { flag: '--data-dir <dir>', desc: '导出目录(缺省 $DSH_HOME/dsh-config-manager/exports)' },
317
+ { flag: '--data-root <dir>', desc: '插件数据根 dataDir(自定义时必须显式传)' },
315
318
  { flag: '-h, --help', desc: '显示本页' },
316
319
  ],
317
320
  },
@@ -373,9 +376,9 @@ export const COMMAND_HELP: readonly CommandHelp[] = [
373
376
  usage: 'sessions list | doctor | repair',
374
377
  summary: '列出本机会话 / 体检并给处置建议',
375
378
  usageLines: [
376
- 'sessions list [--home <dir>] [--json]',
377
- 'sessions doctor [--home <dir>] [--json]',
378
- 'sessions repair [--home <dir>] [--fix] [--keep <dir>] [--map old=new]... [--json]',
379
+ 'sessions list [--home <dir>] [--data-dir <dir>] [--data-root <dir>] [--json]',
380
+ 'sessions doctor [--home <dir>] [--data-dir <dir>] [--data-root <dir>] [--json]',
381
+ 'sessions repair [--home <dir>] [--data-dir <dir>] [--data-root <dir>] [--fix] [--keep <dir>] [--map old=new]... [--json]',
379
382
  ],
380
383
  description: [
381
384
  'DSH 会校验「日志位置 == projectKey(header.cwd)/id」;位置不对就拒绝启动:',
@@ -401,7 +404,9 @@ export const COMMAND_HELP: readonly CommandHelp[] = [
401
404
  title: '选项',
402
405
  entries: [
403
406
  { flag: '--home <dir>', desc: '要修复的 DSH home(缺省 $DSH_HOME,即 ~/.dsh)' },
404
- { flag: '--json', desc: '机器可读输出(list / doctor / repair 预览)' },
407
+ { flag: '--data-dir <dir>', desc: '衍生控制面目录候选(用于 SAFE MODE / 锁门禁)' },
408
+ { flag: '--data-root <dir>', desc: '插件数据根 dataDir(自定义时必须显式传;用于安全门禁)' },
409
+ { flag: '--json', desc: '机器可读输出(stdout 只输出 JSON;人类提示走 stderr,含 --fix)' },
405
410
  { flag: '--fix, --apply', desc: 'repair 真的落盘(缺省只打印计划)' },
406
411
  { flag: '--keep <dir>', desc: '重复 id 时保留哪一份会话目录(其余移入隔离目录)' },
407
412
  { flag: '--map old=new', desc: '路径前缀映射(可重复;命中即改写首帧 cwd)' },
@@ -429,7 +434,7 @@ export const COMMAND_HELP: readonly CommandHelp[] = [
429
434
  title: '回收残留的环境锁',
430
435
  usage: 'recover-stale-lock',
431
436
  summary: '回收残留环境锁(持有者已确证死亡才回收)',
432
- usageLines: ['recover-stale-lock [--data-dir <dir>]'],
437
+ usageLines: ['recover-stale-lock [--data-dir <dir>] [--data-root <dir>]'],
433
438
  description: [
434
439
  '环境锁记录「谁在操作」并带心跳,保证两个操作不会同时写你的配置。',
435
440
  '进程被强制结束(任务管理器 / kill -9)会留下死锁:之后每次操作都被拒,',
@@ -442,6 +447,7 @@ export const COMMAND_HELP: readonly CommandHelp[] = [
442
447
  title: '选项',
443
448
  entries: [
444
449
  { flag: '--data-dir <dir>', desc: '用它派生锁目录所在的插件数据目录' },
450
+ { flag: '--data-root <dir>', desc: '插件数据根 dataDir(自定义时必须显式传;定位 <dataRoot>/locks)' },
445
451
  { flag: '-h, --help', desc: '显示本页' },
446
452
  ],
447
453
  },
@@ -460,7 +466,7 @@ export const COMMAND_HELP: readonly CommandHelp[] = [
460
466
  title: '重装 DSH 程序本体',
461
467
  usage: 'reinstall',
462
468
  summary: '重装 DSH 程序本体(破坏性选择需二次确认)',
463
- usageLines: ['reinstall [--version <v>] [--yes] [--list] [--wipe-config] [--dry-run] [--data-root <dir>]'],
469
+ usageLines: ['reinstall [--version <v>] [--yes] [--list] [--wipe-config] [--dry-run] [--data-dir <dir>] [--data-root <dir>]'],
464
470
  description: [
465
471
  '跨平台重装 @deepseek-ai/dsh 启动器(Windows 用 PowerShell,Unix 用 bash)。',
466
472
  '缺省只重装启动器 + 清全局缓存;数据类清理项(settings / plugins / data)默认不勾,',
@@ -472,10 +478,11 @@ export const COMMAND_HELP: readonly CommandHelp[] = [
472
478
  title: '选项',
473
479
  entries: [
474
480
  { flag: '--list', desc: '只列出可选的清理项,然后退出' },
475
- { flag: '--yes', desc: '非交互:全选并跳过二次确认' },
481
+ { flag: '--yes', desc: '非交互:全选并跳过二次确认(非 TTY 终端执行重装时必须传)' },
476
482
  { flag: '--wipe-config', desc: '等价于勾选全部数据类(settings / plugins / data)' },
477
483
  { flag: '--version <v>', desc: '要安装的 DSH 版本(缺省 latest)' },
478
484
  { flag: '--dry-run', desc: '只打印重装计划,不执行' },
485
+ { flag: '--data-dir <dir>', desc: '衍生控制面目录候选(用于 SAFE MODE / 锁门禁)' },
479
486
  { flag: '--data-root <dir>', desc: '插件数据根 dataDir(自定义时必须显式传)' },
480
487
  { flag: '-h, --help', desc: '显示本页' },
481
488
  ],