dsh-config-manager 0.8.2 → 0.9.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 (345) hide show
  1. package/lib/adapters/mcp.js +42 -13
  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 +147 -4
  10. package/lib/cli/actions.d.ts +7 -105
  11. package/lib/cli/actions.js +16 -172
  12. package/lib/cli/control-state.d.ts +54 -0
  13. package/lib/cli/control-state.js +107 -0
  14. package/lib/cli/index.js +14 -0
  15. package/lib/cli/write-gates.d.ts +61 -0
  16. package/lib/cli/write-gates.js +110 -0
  17. package/lib/client.d.ts +104 -49
  18. package/lib/client.js +12536 -12006
  19. package/lib/core/backup.d.ts +0 -4
  20. package/lib/core/backup.js +21 -4
  21. package/lib/core/boot-rescue.d.ts +1 -1
  22. package/lib/core/boot-rescue.js +12 -1
  23. package/lib/core/boot-safety.js +37 -2
  24. package/lib/core/conflict-decisions.js +2 -1
  25. package/lib/core/exporter.js +22 -1
  26. package/lib/core/journal.d.ts +54 -4
  27. package/lib/core/journal.js +158 -35
  28. package/lib/core/local-plugin-host.d.ts +29 -0
  29. package/lib/core/local-plugin-host.js +55 -48
  30. package/lib/core/messages.d.ts +7 -0
  31. package/lib/core/messages.js +14 -0
  32. package/lib/core/migration-history.js +16 -9
  33. package/lib/core/model-tools.d.ts +2 -2
  34. package/lib/core/model-tools.js +14 -2
  35. package/lib/core/patch-secret-guard.d.ts +49 -0
  36. package/lib/core/patch-secret-guard.js +164 -0
  37. package/lib/core/reconcile.d.ts +8 -0
  38. package/lib/core/reconcile.js +18 -3
  39. package/lib/core/reinstall.d.ts +2 -0
  40. package/lib/core/reinstall.js +6 -2
  41. package/lib/core/restore.js +31 -6
  42. package/lib/core/section-sanitize.d.ts +32 -0
  43. package/lib/core/section-sanitize.js +13 -0
  44. package/lib/core/snapshot-diff.d.ts +30 -0
  45. package/lib/core/snapshot-diff.js +56 -20
  46. package/lib/core/startup-barrier.js +8 -2
  47. package/lib/core/types.d.ts +22 -0
  48. package/lib/core/update-check.js +51 -2
  49. package/lib/foreign/kernel.js +9 -2
  50. package/lib/foreign/read-claude-plugins.js +29 -11
  51. package/lib/foreign/read-dsh.js +31 -2
  52. package/lib/foreign/session-ir.js +50 -9
  53. package/lib/foreign/session-read.d.ts +8 -0
  54. package/lib/foreign/session-read.js +26 -0
  55. package/lib/index.d.ts +1 -1
  56. package/lib/index.js +1 -1
  57. package/lib/profiles/dsh-profile-io.d.ts +20 -0
  58. package/lib/profiles/dsh-profile-io.js +27 -0
  59. package/lib/profiles/dsh-profile-manager.d.ts +27 -0
  60. package/lib/profiles/dsh-profile-manager.js +45 -4
  61. package/lib/profiles/dsh-profile-runtime.d.ts +5 -1
  62. package/lib/profiles/dsh-profile-runtime.js +16 -3
  63. package/lib/profiles/process-control.d.ts +18 -1
  64. package/lib/profiles/process-control.js +25 -1
  65. package/lib/routes/profiles.js +2 -1
  66. package/lib/routes/sync.js +13 -1
  67. package/lib/schema/types.d.ts +11 -0
  68. package/lib/security/redaction.js +22 -6
  69. package/lib/sync/autosync-repeat.d.ts +27 -0
  70. package/lib/sync/autosync-repeat.js +23 -0
  71. package/lib/sync/autosync-scheduler.d.ts +34 -1
  72. package/lib/sync/autosync-scheduler.js +151 -43
  73. package/lib/sync/baseline-heal.js +7 -0
  74. package/lib/sync/baseline-record.d.ts +67 -0
  75. package/lib/sync/baseline-record.js +74 -0
  76. package/lib/sync/blob-store.js +13 -0
  77. package/lib/sync/content-diff.d.ts +39 -0
  78. package/lib/sync/content-diff.js +46 -0
  79. package/lib/sync/git/git-transport.d.ts +32 -1
  80. package/lib/sync/git/git-transport.js +146 -26
  81. package/lib/sync/github-auth.d.ts +17 -1
  82. package/lib/sync/github-auth.js +37 -1
  83. package/lib/sync/merge-apply-plan.d.ts +38 -0
  84. package/lib/sync/merge-apply-plan.js +76 -0
  85. package/lib/sync/messages.d.ts +1 -0
  86. package/lib/sync/messages.js +2 -0
  87. package/lib/sync/pending-merge.d.ts +34 -0
  88. package/lib/sync/pending-merge.js +53 -0
  89. package/lib/sync/s3/s3-transport.d.ts +14 -2
  90. package/lib/sync/s3/s3-transport.js +72 -48
  91. package/lib/sync/sync-engine.d.ts +23 -40
  92. package/lib/sync/sync-engine.js +115 -132
  93. package/lib/sync/sync-history.d.ts +7 -0
  94. package/lib/sync/sync-state.d.ts +28 -0
  95. package/lib/sync/sync-state.js +20 -0
  96. package/lib/sync/transport.d.ts +12 -3
  97. package/lib/sync/transport.js +13 -4
  98. package/lib/sync/webdav/webdav-transport.d.ts +19 -2
  99. package/lib/sync/webdav/webdav-transport.js +81 -40
  100. package/lib/ui/commands.js +5 -11
  101. package/lib/ui/dsh-profiles-view.d.ts +8 -3
  102. package/lib/ui/dsh-profiles-view.js +9 -5
  103. package/lib/ui/i18n.d.ts +2 -1
  104. package/lib/ui/i18n.js +4 -2
  105. package/lib/ui/menu-placement.js +1 -1
  106. package/lib/ui/migration-consult-view.d.ts +11 -0
  107. package/lib/ui/migration-consult-view.js +15 -0
  108. package/lib/ui/overview-view.d.ts +7 -0
  109. package/lib/ui/overview-view.js +3 -0
  110. package/lib/ui/report.d.ts +9 -0
  111. package/lib/ui/report.js +17 -4
  112. package/lib/ui/selection-model.d.ts +8 -0
  113. package/lib/ui/selection-model.js +16 -0
  114. package/lib/utils/patch-yaml.d.ts +39 -1
  115. package/lib/utils/patch-yaml.js +82 -2
  116. package/lib/utils/paths.d.ts +13 -0
  117. package/lib/utils/paths.js +35 -0
  118. package/lib/utils/workdir-lock.js +18 -3
  119. package/package.json +2 -1
  120. package/src/adapters/mcp.test.ts +29 -0
  121. package/src/adapters/mcp.ts +43 -12
  122. package/src/adapters/messages.ts +2 -0
  123. package/src/adapters/patch-key-guard.ts +29 -0
  124. package/src/adapters/plugin-data.test.ts +126 -0
  125. package/src/adapters/plugin-data.ts +97 -26
  126. package/src/adapters/plugins.test.ts +288 -0
  127. package/src/adapters/plugins.ts +141 -4
  128. package/src/cli/actions.test.ts +74 -1
  129. package/src/cli/actions.ts +27 -246
  130. package/src/cli/control-state.ts +143 -0
  131. package/src/cli/index.ts +18 -0
  132. package/src/cli/web/web.test.ts +27 -0
  133. package/src/cli/write-gates.ts +149 -0
  134. package/src/client/about/AboutPanel.tsx +7 -6
  135. package/src/client/about/release-notes-view.test.ts +17 -0
  136. package/src/client/about/release-notes-view.ts +49 -24
  137. package/src/client/chat/ChatEntryView.tsx +2 -2
  138. package/src/client/chat/rollback-entry-view.ts +6 -1
  139. package/src/client/common/CommandPalette.tsx +6 -3
  140. package/src/client/common/ConfirmDialog.tsx +29 -12
  141. package/src/client/common/ContentPicker.tsx +13 -12
  142. package/src/client/common/Modal.tsx +12 -5
  143. package/src/client/common/MoreMenu.tsx +4 -1
  144. package/src/client/common/RunsCenter.tsx +103 -32
  145. package/src/client/common/Select.tsx +2 -2
  146. package/src/client/common/floating-bounds.ts +1 -1
  147. package/src/client/common/floating-units.test.ts +1 -2
  148. package/src/client/common/plan-text-redaction.test.ts +188 -3
  149. package/src/client/common/runs-center-guard.test.ts +60 -0
  150. package/src/client/common/runs-center-view.test.ts +128 -0
  151. package/src/client/common/runs-center-view.ts +96 -0
  152. package/src/client/common/section-title-action.test.ts +66 -0
  153. package/src/client/common/ui.tsx +93 -30
  154. package/src/client/config-manager.module.css +1507 -272
  155. package/src/client/consult/ConsultCard.tsx +7 -6
  156. package/src/client/environment/EnvironmentPanel.tsx +20 -21
  157. package/src/client/environment/maintenance/DiskUsageCard.tsx +65 -91
  158. package/src/client/environment/profiles-incomplete-ui.test.ts +8 -8
  159. package/src/client/export/ExportView.tsx +7 -16
  160. package/src/client/history/HistoryPanel.tsx +88 -28
  161. package/src/client/history/history-locales.ts +3 -3
  162. package/src/client/home/BackupScheduleCard.tsx +35 -30
  163. package/src/client/home/HomePanel.tsx +45 -10
  164. package/src/client/import/ConflictList.tsx +13 -13
  165. package/src/client/import/ForeignImportView.tsx +7 -6
  166. package/src/client/import/ImportWizardView.tsx +2 -3
  167. package/src/client/import/PathMappingForm.tsx +4 -4
  168. package/src/client/import/PathPickerDialog.tsx +2 -1
  169. package/src/client/import/import-wizard-steps.tsx +51 -39
  170. package/src/client/import/use-import-wizard-controller.test.ts +129 -0
  171. package/src/client/import/use-import-wizard-controller.ts +116 -22
  172. package/src/client/library/ArtifactRow.tsx +2 -2
  173. package/src/client/library/BackupInspectView.tsx +19 -15
  174. package/src/client/library/LibraryActions.tsx +56 -16
  175. package/src/client/library/LibraryPanel.tsx +7 -7
  176. package/src/client/library/RestorePlanView.tsx +13 -8
  177. package/src/client/locales/about.ts +0 -2
  178. package/src/client/locales/backup.ts +10 -12
  179. package/src/client/locales/common.ts +2 -0
  180. package/src/client/locales/export.ts +5 -12
  181. package/src/client/locales/foreign.ts +2 -2
  182. package/src/client/locales/import.ts +3 -2
  183. package/src/client/locales/overview.ts +4 -0
  184. package/src/client/locales/profiles.ts +32 -4
  185. package/src/client/locales/restore.ts +0 -2
  186. package/src/client/locales/sessions.ts +0 -2
  187. package/src/client/locales/shell.ts +2 -2
  188. package/src/client/market/MarketPanel.tsx +38 -20
  189. package/src/client/market/MyConfigsList.tsx +34 -32
  190. package/src/client/market/MyConfigsLoginCard.tsx +12 -15
  191. package/src/client/market/MyConfigsView.tsx +5 -5
  192. package/src/client/market/MyConfigsWizard.tsx +7 -12
  193. package/src/client/market/market-locales.ts +0 -6
  194. package/src/client/market/my-configs-split.test.ts +2 -1
  195. package/src/client/nav-menu-clip-guard.test.ts +52 -0
  196. package/src/client/recovery/IncompleteCopiesSection.tsx +1 -3
  197. package/src/client/recovery/RecoveryPanel.tsx +31 -16
  198. package/src/client/recovery/RollbackCard.tsx +58 -16
  199. package/src/client/recovery/RollbackFileChanges.tsx +40 -27
  200. package/src/client/recovery/SessionHealthCard.tsx +2 -2
  201. package/src/client/recovery/SessionHealthDialog.tsx +5 -7
  202. package/src/client/recovery/SessionLayoutSection.tsx +3 -5
  203. package/src/client/recovery/recovery-locales.ts +12 -8
  204. package/src/client/run-store.test.ts +30 -0
  205. package/src/client/run-store.ts +21 -1
  206. package/src/client/sync/AddChannelCard.tsx +65 -0
  207. package/src/client/sync/AutosyncCard.tsx +182 -108
  208. package/src/client/sync/ChannelClearConfirmDialog.tsx +5 -1
  209. package/src/client/sync/ChannelConfigDialog.tsx +27 -48
  210. package/src/client/sync/MergePreviewView.tsx +3 -5
  211. package/src/client/sync/PushReportSections.tsx +35 -0
  212. package/src/client/sync/SyncChannelEntryCard.tsx +33 -24
  213. package/src/client/sync/SyncConfirmView.tsx +3 -3
  214. package/src/client/sync/SyncLogList.tsx +16 -5
  215. package/src/client/sync/SyncPanel.tsx +153 -159
  216. package/src/client/sync/SyncProbeRow.tsx +5 -7
  217. package/src/client/sync/SyncRepositoryPicker.tsx +17 -4
  218. package/src/client/sync/SyncSecuritySection.tsx +157 -0
  219. package/src/client/sync/SyncSettingsDialog.tsx +304 -0
  220. package/src/client/sync/SyncSettingsView.test.ts +26 -8
  221. package/src/client/sync/WorkDirCard.tsx +2 -4
  222. package/src/client/sync/config-clear-guard.test.ts +94 -0
  223. package/src/client/sync/config-clear-guard.ts +98 -0
  224. package/src/client/sync/config-dirty.test.ts +91 -0
  225. package/src/client/sync/config-dirty.ts +88 -0
  226. package/src/client/sync/history-model.test.ts +2 -0
  227. package/src/client/sync/history-model.ts +3 -0
  228. package/src/client/sync/merge-request.ts +20 -0
  229. package/src/client/sync/sync-api.ts +12 -0
  230. package/src/client/sync/sync-locales.ts +87 -47
  231. package/src/client/sync/sync-panel-clear.test.ts +44 -0
  232. package/src/client/sync/sync-view.test.ts +20 -0
  233. package/src/client/sync/sync-view.ts +42 -4
  234. package/src/core/backup.test.ts +61 -1
  235. package/src/core/backup.ts +21 -4
  236. package/src/core/boot-rescue.test.ts +35 -0
  237. package/src/core/boot-rescue.ts +13 -2
  238. package/src/core/boot-safety.test.ts +25 -0
  239. package/src/core/boot-safety.ts +37 -2
  240. package/src/core/conflict-decisions.ts +2 -1
  241. package/src/core/exporter.ts +21 -1
  242. package/src/core/journal.test.ts +183 -0
  243. package/src/core/journal.ts +163 -25
  244. package/src/core/local-plugin-host.test.ts +68 -2
  245. package/src/core/local-plugin-host.ts +31 -4
  246. package/src/core/messages.ts +14 -0
  247. package/src/core/migration-history.test.ts +27 -0
  248. package/src/core/migration-history.ts +12 -4
  249. package/src/core/model-tools.test.ts +67 -0
  250. package/src/core/model-tools.ts +16 -4
  251. package/src/core/patch-secret-guard.test.ts +110 -0
  252. package/src/core/patch-secret-guard.ts +176 -0
  253. package/src/core/reconcile.ts +32 -4
  254. package/src/core/reinstall.ts +8 -2
  255. package/src/core/restore.ts +32 -7
  256. package/src/core/section-sanitize.ts +37 -0
  257. package/src/core/snapshot-diff.test.ts +73 -1
  258. package/src/core/snapshot-diff.ts +66 -21
  259. package/src/core/startup-barrier.test.ts +64 -0
  260. package/src/core/startup-barrier.ts +8 -2
  261. package/src/core/types.ts +27 -1
  262. package/src/core/update-check.test.ts +40 -0
  263. package/src/core/update-check.ts +53 -2
  264. package/src/foreign/claude-code.test.ts +5 -0
  265. package/src/foreign/claude-plugins.test.ts +57 -0
  266. package/src/foreign/claude-sessions-bytes.test.ts +7 -1
  267. package/src/foreign/dsh.test.ts +23 -0
  268. package/src/foreign/kernel.ts +9 -2
  269. package/src/foreign/read-claude-plugins.ts +32 -11
  270. package/src/foreign/read-dsh.ts +33 -2
  271. package/src/foreign/session-ir.test.ts +67 -0
  272. package/src/foreign/session-ir.ts +54 -14
  273. package/src/foreign/session-read.ts +23 -0
  274. package/src/index.ts +1 -1
  275. package/src/profiles/dsh-profile-copy-rollback.test.ts +58 -4
  276. package/src/profiles/dsh-profile-io.ts +29 -0
  277. package/src/profiles/dsh-profile-manager.test.ts +30 -0
  278. package/src/profiles/dsh-profile-manager.ts +53 -5
  279. package/src/profiles/dsh-profile-runtime.test.ts +29 -7
  280. package/src/profiles/dsh-profile-runtime.ts +17 -3
  281. package/src/profiles/process-control.test.ts +97 -0
  282. package/src/profiles/process-control.ts +28 -1
  283. package/src/routes/profiles.ts +2 -1
  284. package/src/routes/sync.ts +13 -1
  285. package/src/schema/types.ts +16 -1
  286. package/src/security/redaction.test.ts +31 -0
  287. package/src/security/redaction.ts +23 -6
  288. package/src/sync/autosync-repeat.test.ts +58 -0
  289. package/src/sync/autosync-repeat.ts +55 -0
  290. package/src/sync/autosync-scheduler.test.ts +417 -0
  291. package/src/sync/autosync-scheduler.ts +154 -41
  292. package/src/sync/baseline-heal.ts +6 -0
  293. package/src/sync/baseline-record.ts +135 -0
  294. package/src/sync/blob-store.test.ts +16 -0
  295. package/src/sync/blob-store.ts +13 -0
  296. package/src/sync/content-diff.test.ts +95 -0
  297. package/src/sync/content-diff.ts +79 -0
  298. package/src/sync/git/git-transport.test.ts +151 -4
  299. package/src/sync/git/git-transport.ts +143 -27
  300. package/src/sync/github-auth.test.ts +26 -1
  301. package/src/sync/github-auth.ts +37 -1
  302. package/src/sync/merge-apply-plan.ts +117 -0
  303. package/src/sync/messages.ts +2 -0
  304. package/src/sync/pending-merge.ts +77 -0
  305. package/src/sync/s3/s3-delete-and-blob-index.test.ts +249 -0
  306. package/src/sync/s3/s3-transport.ts +76 -42
  307. package/src/sync/sync-config.test.ts +39 -12
  308. package/src/sync/sync-device-identity.test.ts +3 -0
  309. package/src/sync/sync-engine.test.ts +465 -12
  310. package/src/sync/sync-engine.ts +130 -135
  311. package/src/sync/sync-history.ts +7 -0
  312. package/src/sync/sync-state.ts +48 -0
  313. package/src/sync/transport.test.ts +13 -1
  314. package/src/sync/transport.ts +12 -4
  315. package/src/sync/webdav/webdav-delete-and-blob-index.test.ts +249 -0
  316. package/src/sync/webdav/webdav-transport.ts +86 -34
  317. package/src/ui/commands.test.ts +11 -0
  318. package/src/ui/commands.ts +5 -14
  319. package/src/ui/dsh-profiles-view.test.ts +16 -0
  320. package/src/ui/dsh-profiles-view.ts +11 -5
  321. package/src/ui/i18n.ts +4 -2
  322. package/src/ui/menu-placement.ts +1 -1
  323. package/src/ui/migration-consult-view.test.ts +20 -1
  324. package/src/ui/migration-consult-view.ts +17 -0
  325. package/src/ui/overview-view.ts +10 -0
  326. package/src/ui/report.test.ts +25 -1
  327. package/src/ui/report.ts +15 -4
  328. package/src/ui/selection-model.test.ts +15 -1
  329. package/src/ui/selection-model.ts +18 -0
  330. package/src/utils/js-yaml4.d.ts +35 -0
  331. package/src/utils/patch-yaml.test.ts +207 -1
  332. package/src/utils/patch-yaml.ts +98 -2
  333. package/src/utils/paths.test.ts +14 -1
  334. package/src/utils/paths.ts +35 -0
  335. package/src/utils/workdir-lock.test.ts +69 -0
  336. package/src/utils/workdir-lock.ts +17 -3
  337. package/lib/ui/path-mapping.d.ts +0 -38
  338. package/lib/ui/path-mapping.js +0 -75
  339. package/src/client/common/InfoHint.tsx +0 -289
  340. package/src/client/common/info-hint-guard.test.ts +0 -1119
  341. package/src/client/sync/DecryptPasswordCard.tsx +0 -48
  342. package/src/client/sync/SecurityOptionsCard.tsx +0 -97
  343. package/src/client/sync/SyncSectionPickerDialog.tsx +0 -213
  344. package/src/ui/path-mapping.test.ts +0 -67
  345. package/src/ui/path-mapping.ts +0 -103
@@ -17,8 +17,21 @@ export const REDACTED = '***REDACTED***';
17
17
  const JSON_FIELD_RE = /"([A-Za-z0-9_.\-]+)"\s*:\s*"([^"]*)"/g;
18
18
  /** kv 值到空白/逗号/分号/&(& 截断:避免吞掉 URL query 的后续参数) */
19
19
  const KV_FIELD_RE = /([A-Za-z0-9_.\-]+)\s*=\s*([^\s,;&]+)/g;
20
- /** colon 值允许空格(如 `Authorization: Bearer xyz`),到逗号/分号/右大括号截断 */
21
- const COLON_FIELD_RE = /([A-Za-z0-9_.\-]+)\s*:\s*([^,;}]+)/g;
20
+ /**
21
+ * colon 形态的**带引号值**(`"field": "value"` 之外的非 JSON 文本,如 `password: "x"`)。
22
+ * 单独一条是为了「保留引号」:替换只动引号内的值,输出仍是合法 JSON / 合法带引号文本。
23
+ */
24
+ const QUOTED_COLON_FIELD_RE = /([A-Za-z0-9_.\-]+)\s*:\s*"([^"\n\r]*)"/g;
25
+ /**
26
+ * colon 值允许空格(如 `Authorization: Bearer xyz`),到逗号/分号/右大括号/**换行/引号**截断。
27
+ *
28
+ * 为什么值域必须排除 \n 与 "(审计 P12-2/P12-3,2026-11-13 实测):
29
+ * - 原值域 `[^,;}]` 含换行 ⇒ `note: ok\npassword: s3cr3t` 里首个不敏感字段一路吞到行尾,
30
+ * 整段只匹配一次、字段名是 note,于是 password 明文透传;
31
+ * - 还含 `"` ⇒ `{"error":"Authorization: Bearer abc"}` 会把 JSON 的收尾引号一起替换掉,
32
+ * 脱敏后 `JSON.parse` 直接抛 Unterminated string。
33
+ */
34
+ const COLON_FIELD_RE = /([A-Za-z0-9_.\-]+)[ \t]*:[ \t]*([^\s,;}\n\r"][^,;}\n\r"]{0,199}?)(?=\s+[A-Za-z0-9_.\-]+[ \t]*:|[,;}\n\r"]|$)/g;
22
35
  /* ---------------- 值形状模式(包含式,字段名无关) ---------------- */
23
36
  /**
24
37
  * 显示层**额外**的 PEM 头(**superset**,t78)。
@@ -111,9 +124,11 @@ function replaceSensitiveField(text, re, blacklist) {
111
124
  * 两份代码只在「正则实例从哪来」上不同 —— 任何一步调整都要记得改两处,漏一次就是两条脱敏口径。
112
125
  * 现在只由调用方决定正则实例的生命周期(模块级常量 / 每次预编译),流水线本身不再有副本。
113
126
  */
114
- function redactPipeline(text, blacklist, json, kv, colon) {
115
- // 1. 结构化字段形态(顺序:JSON → kv → colon;JSON 键不会被后续形态二次命中)
127
+ function redactPipeline(text, blacklist, json, quotedColon, kv, colon) {
128
+ // 1. 结构化字段形态(顺序:JSON → 带引号 colon → kv → 裸 colon);
129
+ // JSON 键不会被后续形态二次命中;带引号 colon 先跑,免得裸 colon 吃掉收尾引号。
116
130
  let out = replaceSensitiveField(text, json, blacklist);
131
+ out = replaceSensitiveField(out, quotedColon, blacklist);
117
132
  out = replaceSensitiveField(out, kv, blacklist);
118
133
  out = replaceSensitiveField(out, colon, blacklist);
119
134
  // 2. 值形状模式(字段名无关,包含式)
@@ -129,7 +144,7 @@ function redactPipeline(text, blacklist, json, kv, colon) {
129
144
  * 输出仍保留结构化形态(JSON 行合法)。
130
145
  */
131
146
  export function redact(text, blacklist = []) {
132
- return redactPipeline(text, blacklist, JSON_FIELD_RE, KV_FIELD_RE, COLON_FIELD_RE);
147
+ return redactPipeline(text, blacklist, JSON_FIELD_RE, QUOTED_COLON_FIELD_RE, KV_FIELD_RE, COLON_FIELD_RE);
133
148
  }
134
149
  /** 对象级掩码:字段名命中敏感名单 → 整值替换(返回新对象,不改原对象;结构与类型保留) */
135
150
  export function redactValue(value, blacklist = []) {
@@ -152,9 +167,10 @@ export function redactValue(value, blacklist = []) {
152
167
  */
153
168
  export function createRedactor(blacklist = []) {
154
169
  const json = new RegExp(JSON_FIELD_RE.source, 'g');
170
+ const quotedColon = new RegExp(QUOTED_COLON_FIELD_RE.source, 'g');
155
171
  const kv = new RegExp(KV_FIELD_RE.source, 'g');
156
172
  const colon = new RegExp(COLON_FIELD_RE.source, 'g');
157
- return (text) => redactPipeline(text, blacklist, json, kv, colon);
173
+ return (text) => redactPipeline(text, blacklist, json, quotedColon, kv, colon);
158
174
  }
159
175
  /** 默认名单(文档用;redact 的默认附加名单为空,内置判定已含 DEFAULT_SECRET_FIELD_NAMES) */
160
176
  export { DEFAULT_SECRET_FIELD_NAMES };
@@ -0,0 +1,27 @@
1
+ /**
2
+ * 自动同步「同一状态连续轮询」的历史去重签名(P1,2026-11-14 真机事故)。
3
+ *
4
+ * 事故现场:远端出现一份比本地基线新的快照后,60s 远端轮询每轮都得出同一结论
5
+ * (skipReason='conflict' + 同样的 conflictedSections + 同样的「远端已推进」原文),
6
+ * 于是 sync-history 被同一条结论刷满(200 条上限里 196 条完全一样,间隔精确 60s),
7
+ * 首页「最近活动」同步变成每 1 分钟一条的噪音,而真正的冲突分区没有任何新信息。
8
+ *
9
+ * 去重口径(只压「同一件事的重复播报」,不压状态变化):
10
+ * - status 'success' / 'failed' 一律**不去重**:upToDate 逐轮记一条是文档化的既有行为
11
+ * (见 core/migration-history.ts 的 isAutosyncIdleRound 注释),失败必须逐条可见;
12
+ * - 带 pushedSnapshotId / pulledSnapshotId 的轮次**不去重**:真的推进了远端或本地 = 进度,
13
+ * 每一轮都是不同的事件;
14
+ * - 其余(skipped / partial)按 channel + status + direction + skipReason + 排序后的
15
+ * conflictedSections/appliedSections + error 取签名:签名相同 = 同一状态的第 N 轮。
16
+ *
17
+ * 被压掉的轮次仍然会刷新 autosync-config 的 lastRunAt / lastRunStatus / 跳过计数
18
+ * (见 autosync-scheduler.writeFinalConfig),所以界面「上次运行」不会停在旧时间。
19
+ */
20
+ import type { AutosyncHistoryEntry } from './sync-history.ts';
21
+ /** 参与签名的字段子集(AutosyncHistoryEntry 的只读投影)。 */
22
+ export type RepeatSignatureEntry = Pick<AutosyncHistoryEntry, 'status' | 'direction' | 'skipReason' | 'conflictedSections' | 'appliedSections' | 'pushedSnapshotId' | 'pulledSnapshotId' | 'error'>;
23
+ /**
24
+ * 返回本轮历史签名;null = 本轮必须照常记录(见文件头的不去重清单)。
25
+ * 签名只用于进程内比较,永不落盘,故用 \u0000 分隔以避免字段拼接歧义。
26
+ */
27
+ export declare function repeatHistorySignature(channel: string, entry: RepeatSignatureEntry): string | null;
@@ -0,0 +1,23 @@
1
+ function sortedList(ids) {
2
+ return ids === undefined ? '' : [...ids].sort().join(',');
3
+ }
4
+ /**
5
+ * 返回本轮历史签名;null = 本轮必须照常记录(见文件头的不去重清单)。
6
+ * 签名只用于进程内比较,永不落盘,故用 \u0000 分隔以避免字段拼接歧义。
7
+ */
8
+ export function repeatHistorySignature(channel, entry) {
9
+ if (entry.status === 'success' || entry.status === 'failed')
10
+ return null;
11
+ if (entry.pushedSnapshotId !== undefined || entry.pulledSnapshotId !== undefined)
12
+ return null;
13
+ return [
14
+ channel,
15
+ entry.status,
16
+ entry.direction,
17
+ entry.skipReason ?? '',
18
+ sortedList(entry.conflictedSections),
19
+ sortedList(entry.appliedSections),
20
+ entry.error ?? '',
21
+ ].join('\u0000');
22
+ }
23
+ //# sourceMappingURL=autosync-repeat.js.map
@@ -44,6 +44,13 @@ export interface AutosyncRunResult {
44
44
  * 「从来没配」在界面上长得一模一样,用户会反复重填同一个被拒地址。
45
45
  */
46
46
  configIssue?: string;
47
+ /**
48
+ * issue #136:本轮下行**实际产生的告警**(例:patch 行里被脱敏剥空的叶子已保留本机值、
49
+ * 叶级未裁决冲突被扣下)。非空 = 有内容没落地,终态不得再报成「成功且零告警」。
50
+ */
51
+ warnings?: string[];
52
+ /** issue #136:本轮被保留待裁决的叶级冲突所在分区(与 warnings 同源,供界面定位)。 */
53
+ heldSections?: SectionId[];
47
54
  }
48
55
  /**
49
56
  * SYN-05:本轮冲突(下行冲突)该不该 force push —— 唯一判定点。
@@ -206,6 +213,14 @@ export declare class AutoSyncScheduler {
206
213
  private readonly reportedConfigIssues;
207
214
  private stopped;
208
215
  private running;
216
+ /**
217
+ * P1(2026-11-14 真机事故):上一轮真正落盘的历史签名,见 autosync-repeat.ts。
218
+ * 与本轮签名相同 → 这一轮不追加历史(同一结论连续播报把 200 条历史刷满、首页变成
219
+ * 每 1 分钟一条的噪音);但 lastRunAt / lastRunStatus / 跳过计数仍逐轮刷新。
220
+ */
221
+ private repeatSignature;
222
+ /** 本轮历史是否被压掉 —— writeFinalConfig 据此保留上一条真记录的 lastRunHistoryId。 */
223
+ private historyDeduped;
209
224
  constructor(opts: AutoSyncSchedulerOptions);
210
225
  /**
211
226
  * 追加一条自动同步历史(自动带上触发通道;0x 安全:绝不覆盖调用方显式 transport)。
@@ -236,8 +251,15 @@ export declare class AutoSyncScheduler {
236
251
  * - 距上次开始不足 minTriggerGapMs → 合并成一次(连续保存只跑一轮,每通道至多一个定时器)。
237
252
  */
238
253
  trigger(channel: SyncTransportType, reason?: string): void;
239
- /** 兜底间隔定时器:每个 enabled 通道按各自 interval 排一次性定时器,触发后只重排自己。 */
254
+ /**
255
+ * 兜底间隔定时器:每个 enabled 通道按各自 interval 排一次性定时器,触发后**只重排自己**。
256
+ *
257
+ * 早期实现是「清掉全部通道再统一重排」:webdav 5m 每跑一轮就把 git 30m 的定时器清掉重排,
258
+ * 30m 永远等不到 → 纯定时器模式下慢通道永久饥饿(审计 P5-1,虚拟时钟 180min 实测 git 只跑 1 次)。
259
+ */
240
260
  private scheduleIntervalTimers;
261
+ /** 单个通道的一次性 interval 排期(触发后只重排这一个通道)。 */
262
+ private scheduleChannelTimer;
241
263
  /**
242
264
  * realtime 通道的远端轮询:按 remoteCheckMs(缺省 60s)排一次性定时器。
243
265
  * 轮询只是「叫醒一轮 runOnce」—— 是否真的下载仍由 detectRemoteNew 判定,
@@ -277,6 +299,17 @@ export declare class AutoSyncScheduler {
277
299
  * 结论**不具权威性**:调用方取到锁之后必须重跑一次(见 runOnceInternal 的 Phase 2)。
278
300
  */
279
301
  private detectPhase;
302
+ /**
303
+ * P2(2026-11-14 真机事故):把「本轮被冲突挡下的分区」写进 sync-state.pendingMerge。
304
+ *
305
+ * 过去自动同步只在历史里留一句「冲突」,sync-state 里没有可挂入口的持久对象 ——
306
+ * 首页「待裁决」徽章于是只有颜色没有去处,用户点不动、也不知道该去哪裁决。
307
+ * 这里由引擎按**本轮实际合并过的远端快照 id** 落 pendingMerge(同远端快照连续冲突保留首次 since),
308
+ * 界面据 /sync/status 的 pendingMerge 显示待裁决分区,首页那一行据此跳到同步页。
309
+ *
310
+ * 尽力而为:写待裁决失败绝不能把「远端有冲突」这一事实变成 failed(那会累加连续失败计数)。
311
+ */
312
+ private recordPendingMerge;
280
313
  private writeFinalConfig;
281
314
  /**
282
315
  * 连续失败 ≥ 3 → 通知(host.log.warn)。
@@ -50,6 +50,7 @@ import { engineMsg } from './messages.js';
50
50
  import { readAutosyncConfig, writeAutosyncConfig, clampRemoteCheckMs, DEFAULT_AUTOSYNC_REALTIME, DEFAULT_AUTOSYNC_REMOTE_CHECK_MS, DEFAULT_AUTOSYNC_AUTO_APPLY_TIER, DEFAULT_AUTOSYNC_CONFLICT_POLICY, } from './autosync-config.js';
51
51
  import { readSyncConfigFor, isGitConfig, isWebDavConfig, isS3Config, isGistConfig, SYNC_CHANNELS } from './sync-config.js';
52
52
  import { readSyncHistory, appendAutosyncEntry, markAutosyncNotified } from './sync-history.js';
53
+ import { repeatHistorySignature } from './autosync-repeat.js';
53
54
  import { classifyMergePlan } from './risk.js';
54
55
  import { SyncWatcher } from './sync-watcher.js';
55
56
  import { buildWatchTargets } from './watch-scope.js';
@@ -143,6 +144,14 @@ export class AutoSyncScheduler {
143
144
  reportedConfigIssues = new Set();
144
145
  stopped = false;
145
146
  running = false;
147
+ /**
148
+ * P1(2026-11-14 真机事故):上一轮真正落盘的历史签名,见 autosync-repeat.ts。
149
+ * 与本轮签名相同 → 这一轮不追加历史(同一结论连续播报把 200 条历史刷满、首页变成
150
+ * 每 1 分钟一条的噪音);但 lastRunAt / lastRunStatus / 跳过计数仍逐轮刷新。
151
+ */
152
+ repeatSignature = null;
153
+ /** 本轮历史是否被压掉 —— writeFinalConfig 据此保留上一条真记录的 lastRunHistoryId。 */
154
+ historyDeduped = false;
146
155
  constructor(opts) {
147
156
  this.syncDir = opts.syncDir;
148
157
  this.host = opts.host;
@@ -174,6 +183,16 @@ export class AutoSyncScheduler {
174
183
  * 原样透传(readSyncHistory 逐条 cast),所以运行时可稳定往返;界面按「字段有无」渲染。
175
184
  */
176
185
  async appendHistory(channel, entry) {
186
+ const signature = repeatHistorySignature(channel, entry);
187
+ if (signature !== null && signature === this.repeatSignature) {
188
+ // 同一状态的第 N 轮(典型:远端快照一直比基线新,60s 轮询每轮都撞同一份冲突)。
189
+ // 不写 sync-history、也不写首页统一历史;但这一轮仍要刷新「上次运行」,
190
+ // 否则界面会停在几十分钟前的 lastRunAt,用户以为自动同步停了。
191
+ this.historyDeduped = true;
192
+ return;
193
+ }
194
+ this.repeatSignature = signature;
195
+ this.historyDeduped = false;
177
196
  await this.appendHistoryFn({ ...entry, transport: channel });
178
197
  }
179
198
  /**
@@ -252,36 +271,47 @@ export class AutoSyncScheduler {
252
271
  this.host.log.error(`自动同步触发失败(${channel}/${reason})`, { error: err instanceof Error ? err.message : String(err) });
253
272
  });
254
273
  }
255
- /** 兜底间隔定时器:每个 enabled 通道按各自 interval 排一次性定时器,触发后只重排自己。 */
274
+ /**
275
+ * 兜底间隔定时器:每个 enabled 通道按各自 interval 排一次性定时器,触发后**只重排自己**。
276
+ *
277
+ * 早期实现是「清掉全部通道再统一重排」:webdav 5m 每跑一轮就把 git 30m 的定时器清掉重排,
278
+ * 30m 永远等不到 → 纯定时器模式下慢通道永久饥饿(审计 P5-1,虚拟时钟 180min 实测 git 只跑 1 次)。
279
+ */
256
280
  scheduleIntervalTimers() {
257
281
  for (const timer of this.timers.values())
258
282
  this.clearTimer(timer);
259
283
  this.timers.clear();
260
284
  // 通道清单唯一来源 = SYNC_CHANNELS(此前同一数组在本文件写了两遍:漏改一处即某通道永不排期)
261
- const channels = SYNC_CHANNELS;
262
- for (const channel of channels) {
263
- void this.readConfig(channel).then((cfg) => {
264
- if (this.stopped || !cfg.enabled)
285
+ for (const channel of SYNC_CHANNELS)
286
+ this.scheduleChannelTimer(channel);
287
+ }
288
+ /** 单个通道的一次性 interval 排期(触发后只重排这一个通道)。 */
289
+ scheduleChannelTimer(channel) {
290
+ const existing = this.timers.get(channel);
291
+ if (existing !== undefined)
292
+ this.clearTimer(existing);
293
+ this.timers.delete(channel);
294
+ void this.readConfig(channel).then((cfg) => {
295
+ if (this.stopped || !cfg.enabled)
296
+ return;
297
+ const ms = intervalToMs(cfg.interval);
298
+ const timer = this.setTimer(() => {
299
+ // 一次性定时器:触发后立即从表移除,避免 reload() 清理到已失效的句柄
300
+ this.timers.delete(channel);
301
+ if (this.stopped)
265
302
  return;
266
- const ms = intervalToMs(cfg.interval);
267
- const timer = this.setTimer(() => {
268
- // 一次性定时器:触发后立即从表移除,避免 reload() 清理到已失效的句柄
269
- this.timers.delete(channel);
270
- if (this.stopped)
271
- return;
272
- void this.runOnce(channel, { reason: 'interval' })
273
- .catch((err) => {
274
- this.host.log.error(`自动同步定时触发失败(${channel})`, { error: err instanceof Error ? err.message : String(err) });
275
- })
276
- .then(() => {
277
- // 只重排 interval 定时器(远端轮询有自己的节奏,绝不互相重置)
278
- if (!this.stopped)
279
- this.scheduleIntervalTimers();
280
- });
281
- }, ms);
282
- this.timers.set(channel, timer);
283
- }).catch(() => { });
284
- }
303
+ void this.runOnce(channel, { reason: 'interval' })
304
+ .catch((err) => {
305
+ this.host.log.error(`自动同步定时触发失败(${channel})`, { error: err instanceof Error ? err.message : String(err) });
306
+ })
307
+ .then(() => {
308
+ // 只重排自己的 interval 定时器(远端轮询有自己的节奏,别的通道也不得被本通道重置)
309
+ if (!this.stopped)
310
+ this.scheduleChannelTimer(channel);
311
+ });
312
+ }, ms);
313
+ this.timers.set(channel, timer);
314
+ }).catch(() => { });
285
315
  }
286
316
  /**
287
317
  * realtime 通道的远端轮询:按 remoteCheckMs(缺省 60s)排一次性定时器。
@@ -514,7 +544,12 @@ export class AutoSyncScheduler {
514
544
  try {
515
545
  // 锁内重跑一次检测:预检到写入之间可能被别的进程推进(远端新快照 / 本机配置改动),
516
546
  // 拿过期结论去写等于覆盖别人的成果。无锁环境(测试)直接用预检结果 —— 同一份数据,没有竞态。
517
- const phase = releaseLock === null ? preflight : await this.detectPhase(channel, cfg, nowIso, historyId);
547
+ // P0(2026-11-14 真机事故):锁内重跑必须与预检同口径传 localCheck。
548
+ // 此前这里漏传 → 60s 远端轮询在锁内又跑了一遍全量本地导出(plugins 的 npm pack,
549
+ // 实测单插件 44.7s/轮),预检省下的开销全被这一步还回去。
550
+ const phase = releaseLock === null
551
+ ? preflight
552
+ : await this.detectPhase(channel, cfg, nowIso, historyId, { localCheck: opts.reason !== 'remote-poll' });
518
553
  if (phase.kind === 'skip')
519
554
  return phase.result;
520
555
  const { engine, remoteNew, localDirty, firstRun } = phase;
@@ -528,6 +563,12 @@ export class AutoSyncScheduler {
528
563
  * 真机现场「推本机配置当备份」这条链路被远端冲突连续阻塞,用户却只看到 skipped/conflict。
529
564
  */
530
565
  let conflictedSections = [];
566
+ //
567
+ // issue #136:Phase B 的「成功但没全写进去」必须能被看见 —— 旧实现只看 applyReport.ok,
568
+ // ok 时把 warnings / 待裁决项整包丢掉,于是「patch 行被剥空→守卫保留本机」与
569
+ // 「叶级冲突被扣下」都表现为一轮干净的成功。
570
+ let downlinkWarnings = [];
571
+ let heldLeafSections = [];
531
572
  // Phase A: pull 合并(下载)—— 仅当远端有新快照才拉取(§3.2)。
532
573
  if (remoteNew) {
533
574
  let mergePlan;
@@ -585,6 +626,8 @@ export class AutoSyncScheduler {
585
626
  })).result
586
627
  : await rawApply();
587
628
  appliedSections = applyReport.applied;
629
+ downlinkWarnings = applyReport.warnings;
630
+ heldLeafSections = [...new Set(applyReport.review.map((r) => r.sectionId))];
588
631
  if (!applyReport.ok) {
589
632
  const error = applyReport.warnings.join('; ') || engineMsg('sync.autosyncApplyMergeFailed');
590
633
  const result = {
@@ -636,12 +679,18 @@ export class AutoSyncScheduler {
636
679
  // 绝不记 failed(那会累加连续失败计数并对用户发通知,把「需要用『检查远程合并』处理」
637
680
  // 谎报成「同步坏了」);错误摘要保留引擎给出的说明(用户能看见到底为什么没推上去)。
638
681
  const message = pushReport.message ?? engineMsg('sync.autosyncPushFailed');
682
+ // issue #136:下行自身的告警/待裁决与「推送被冲突挡下」合并进同一条记录,
683
+ // 不因上行受阻就把下行的事实抹掉。
684
+ const blockedConflicted = [...new Set([...conflictedSections, ...heldLeafSections])];
685
+ const blockedDegraded = downlinkWarnings.length > 0 || heldLeafSections.length > 0;
639
686
  const conflictResult = {
640
- status: conflictedSections.length > 0 ? 'partial' : 'skipped',
687
+ status: blockedConflicted.length > 0 || blockedDegraded ? 'partial' : 'skipped',
641
688
  direction: appliedSections.length ? 'both' : 'push',
642
689
  skipReason: 'conflict', error: message, historyId,
643
690
  appliedSections,
644
- ...(conflictedSections.length > 0 ? { conflictedSections } : {}),
691
+ ...(blockedConflicted.length > 0 ? { conflictedSections: blockedConflicted } : {}),
692
+ ...(downlinkWarnings.length > 0 ? { warnings: downlinkWarnings } : {}),
693
+ ...(heldLeafSections.length > 0 ? { heldSections: heldLeafSections } : {}),
645
694
  consecutiveFailures: 0,
646
695
  ...forcedMark,
647
696
  };
@@ -649,10 +698,14 @@ export class AutoSyncScheduler {
649
698
  direction: appliedSections.length ? 'both' : 'push', status: conflictResult.status,
650
699
  skipReason: 'conflict', error: message,
651
700
  appliedSections,
652
- ...(conflictedSections.length > 0 ? { conflictedSections } : {}),
701
+ ...(blockedConflicted.length > 0 ? { conflictedSections: blockedConflicted } : {}),
702
+ ...(downlinkWarnings.length > 0 ? { warnings: downlinkWarnings } : {}),
703
+ ...(heldLeafSections.length > 0 ? { heldSections: heldLeafSections } : {}),
653
704
  createdAt: nowIso, failureCountAtRun: 0,
654
705
  ...forcedMark,
655
706
  });
707
+ // 冲突分区落成待裁决(P2):首页与同步页据此给出裁决入口。
708
+ await this.recordPendingMerge(engine, conflictedSections);
656
709
  await this.writeFinalConfig(cfg, conflictResult, nowIso, historyId, channel);
657
710
  return conflictResult;
658
711
  }
@@ -692,21 +745,38 @@ export class AutoSyncScheduler {
692
745
  // 如实记一条 skipReason,让历史与首页能说清「这次推上去之前先修好了基线」,
693
746
  // 而不是让用户以为又发生了一次莫名冲突。冲突原因优先(真有冲突时更该被看见)。
694
747
  const adoptedReason = pushReport.adoptedBase !== undefined ? 'baseline-adopted' : undefined;
748
+ // issue #136:下行有告警 / 有待裁决叶级项 → 终态只能是 partial。
749
+ // 「推送成功」不能替下行的未完成背书:用户会从 success 得出「两端一样了」,而实际上
750
+ // 有些叶子被有意扣下(保留本机 / 等待裁决)。
751
+ // 两类降级必须分开说:只有「叶级冲突被扣下」才是冲突待裁决;
752
+ // 纯告警(插件没装上、undo 有残留等)与冲突无关,套上 'conflict' 会让
753
+ // 界面上出现「跳过原因:冲突」「另有 N 个分区待确认」,而 conflictedSections 是空的。
754
+ const heldDegraded = heldLeafSections.length > 0;
755
+ const degraded = downlinkWarnings.length > 0 || heldDegraded;
756
+ const finalPartial = partial || degraded;
757
+ const finalSkipReason = skipReason
758
+ ?? (heldDegraded ? 'conflict' : degraded ? 'warning' : undefined);
759
+ // 扣下的叶级冲突所在分区也要出现在「待处理分区」里(与分区级冲突合并去重)
760
+ const finalConflicted = [...new Set([...reportedConflicted, ...heldLeafSections])];
695
761
  const result = {
696
- status: partial ? 'partial' : 'success',
762
+ status: finalPartial ? 'partial' : 'success',
697
763
  direction: appliedSections.length ? 'both' : 'push',
698
764
  appliedSections, pushedSnapshotId: pushReport.snapshotId, historyId,
699
- ...(skipReason !== undefined || adoptedReason !== undefined ? { skipReason: skipReason ?? adoptedReason } : {}),
700
- ...(reportedConflicted.length > 0 ? { conflictedSections: reportedConflicted } : {}),
765
+ ...(finalSkipReason !== undefined || adoptedReason !== undefined ? { skipReason: finalSkipReason ?? adoptedReason } : {}),
766
+ ...(finalConflicted.length > 0 ? { conflictedSections: finalConflicted } : {}),
767
+ ...(downlinkWarnings.length > 0 ? { warnings: downlinkWarnings } : {}),
768
+ ...(heldLeafSections.length > 0 ? { heldSections: heldLeafSections } : {}),
701
769
  consecutiveFailures: 0,
702
770
  ...forcedMark,
703
771
  };
704
772
  await this.appendHistory(channel, {
705
773
  direction: appliedSections.length ? 'both' : 'push',
706
- status: partial ? 'partial' : 'success',
774
+ status: finalPartial ? 'partial' : 'success',
707
775
  appliedSections, pushedSnapshotId: pushReport.snapshotId,
708
- ...(skipReason !== undefined || adoptedReason !== undefined ? { skipReason: skipReason ?? adoptedReason } : {}),
709
- ...(reportedConflicted.length > 0 ? { conflictedSections: reportedConflicted } : {}),
776
+ ...(finalSkipReason !== undefined || adoptedReason !== undefined ? { skipReason: finalSkipReason ?? adoptedReason } : {}),
777
+ ...(finalConflicted.length > 0 ? { conflictedSections: finalConflicted } : {}),
778
+ ...(downlinkWarnings.length > 0 ? { warnings: downlinkWarnings } : {}),
779
+ ...(heldLeafSections.length > 0 ? { heldSections: heldLeafSections } : {}),
710
780
  createdAt: nowIso, failureCountAtRun: 0,
711
781
  ...forcedMark,
712
782
  });
@@ -732,28 +802,45 @@ export class AutoSyncScheduler {
732
802
  }
733
803
  // 本轮下行被冲突挡下、且没有可上行内容(startup 变体 / 本地无改动)→ 如实 skipped/conflict。
734
804
  if (conflictedSections.length > 0) {
805
+ // issue #136:被扣下的叶级冲突也算「待处理分区」(与分区级冲突同列)。
806
+ const skipConflicted = [...new Set([...conflictedSections, ...heldLeafSections])];
735
807
  const conflictResult = {
736
808
  status: 'skipped', direction: 'pull', skipReason: 'conflict',
737
- conflictedSections, historyId, consecutiveFailures: 0,
809
+ conflictedSections: skipConflicted, historyId, consecutiveFailures: 0,
810
+ ...(downlinkWarnings.length > 0 ? { warnings: downlinkWarnings } : {}),
811
+ ...(heldLeafSections.length > 0 ? { heldSections: heldLeafSections } : {}),
738
812
  };
739
813
  await this.appendHistory(channel, {
740
814
  direction: 'pull', status: 'skipped', skipReason: 'conflict',
741
- conflictedSections, createdAt: nowIso, failureCountAtRun: 0,
815
+ conflictedSections: skipConflicted, createdAt: nowIso, failureCountAtRun: 0,
816
+ ...(downlinkWarnings.length > 0 ? { warnings: downlinkWarnings } : {}),
817
+ ...(heldLeafSections.length > 0 ? { heldSections: heldLeafSections } : {}),
742
818
  });
819
+ await this.recordPendingMerge(engine, conflictedSections);
743
820
  await this.writeFinalConfig(cfg, conflictResult, nowIso, historyId, channel);
744
821
  return conflictResult;
745
822
  }
746
823
  // startup 变体 / 仅远端合并:只做 pull 合并(不上传),或远端无新生且本地无改动(已在上方 upToDate 短路上)。
824
+ // issue #136:纯下行的告警/待裁决同样算「没全做完」—— 终态不得写成 success。
825
+ const degraded = downlinkWarnings.length > 0 || heldLeafSections.length > 0;
826
+ const pulledConflicted = [...new Set([...deferredSections, ...heldLeafSections])];
827
+ const pullSkipReason = !degraded && appliedSections.length === 0
828
+ ? 'unchanged'
829
+ : degraded ? 'conflict' : undefined;
747
830
  const result = {
748
- status: 'success', direction: 'pull', appliedSections,
749
- ...(appliedSections.length === 0 ? { skipReason: 'unchanged' } : {}),
750
- ...(deferredSections.length > 0 ? { conflictedSections: deferredSections } : {}),
831
+ status: degraded ? 'partial' : 'success', direction: 'pull', appliedSections,
832
+ ...(pullSkipReason !== undefined ? { skipReason: pullSkipReason } : {}),
833
+ ...(pulledConflicted.length > 0 ? { conflictedSections: pulledConflicted } : {}),
834
+ ...(downlinkWarnings.length > 0 ? { warnings: downlinkWarnings } : {}),
835
+ ...(heldLeafSections.length > 0 ? { heldSections: heldLeafSections } : {}),
751
836
  historyId, consecutiveFailures: 0,
752
837
  };
753
838
  await this.appendHistory(channel, {
754
- direction: 'pull', status: 'success', appliedSections,
755
- ...(appliedSections.length === 0 ? { skipReason: 'unchanged' } : {}),
756
- ...(deferredSections.length > 0 ? { conflictedSections: deferredSections } : {}),
839
+ direction: 'pull', status: degraded ? 'partial' : 'success', appliedSections,
840
+ ...(pullSkipReason !== undefined ? { skipReason: pullSkipReason } : {}),
841
+ ...(pulledConflicted.length > 0 ? { conflictedSections: pulledConflicted } : {}),
842
+ ...(downlinkWarnings.length > 0 ? { warnings: downlinkWarnings } : {}),
843
+ ...(heldLeafSections.length > 0 ? { heldSections: heldLeafSections } : {}),
757
844
  createdAt: nowIso, failureCountAtRun: 0,
758
845
  });
759
846
  await this.writeFinalConfig(cfg, result, nowIso, historyId, channel);
@@ -893,6 +980,26 @@ export class AutoSyncScheduler {
893
980
  }
894
981
  return { kind: 'work', engine, remoteNew, localDirty, firstRun };
895
982
  }
983
+ /**
984
+ * P2(2026-11-14 真机事故):把「本轮被冲突挡下的分区」写进 sync-state.pendingMerge。
985
+ *
986
+ * 过去自动同步只在历史里留一句「冲突」,sync-state 里没有可挂入口的持久对象 ——
987
+ * 首页「待裁决」徽章于是只有颜色没有去处,用户点不动、也不知道该去哪裁决。
988
+ * 这里由引擎按**本轮实际合并过的远端快照 id** 落 pendingMerge(同远端快照连续冲突保留首次 since),
989
+ * 界面据 /sync/status 的 pendingMerge 显示待裁决分区,首页那一行据此跳到同步页。
990
+ *
991
+ * 尽力而为:写待裁决失败绝不能把「远端有冲突」这一事实变成 failed(那会累加连续失败计数)。
992
+ */
993
+ async recordPendingMerge(engine, sections) {
994
+ if (sections.length === 0)
995
+ return;
996
+ try {
997
+ await engine.recordPendingMerge(sections);
998
+ }
999
+ catch (err) {
1000
+ this.host.log.warn(`自动同步待裁决分区未能落盘:${err instanceof Error ? err.message : String(err)}`);
1001
+ }
1002
+ }
896
1003
  async writeFinalConfig(base, result, nowIso, historyId, channel) {
897
1004
  const skipReason = result.status === 'failed' ? undefined : result.skipReason;
898
1005
  const countsConflicts = skipReason === 'conflict' || skipReason === 'conflict-kept-local';
@@ -904,7 +1011,8 @@ export class AutoSyncScheduler {
904
1011
  lastRunAt: nowIso,
905
1012
  lastRunStatus: result.status,
906
1013
  consecutiveFailures: result.consecutiveFailures,
907
- lastRunHistoryId: historyId,
1014
+ // 历史被压掉的轮次没有新记录 id —— 保留上一条真记录的 id,绝不指向不存在的条目。
1015
+ lastRunHistoryId: this.historyDeduped ? (base.lastRunHistoryId ?? historyId) : historyId,
908
1016
  lastRunMessage: result.error ?? '',
909
1017
  lastRunSkipReason: skipReason,
910
1018
  lastRunSkipCount: skipCount,
@@ -28,6 +28,13 @@ export async function adoptOwnRemoteHead(opts) {
28
28
  continue;
29
29
  state.sections[sid] = { hash, updatedAt: meta.createdAt };
30
30
  }
31
+ // issue #140(G-44):被收养的快照自己就是「远端当前观测」——它的 sections 记进独立字段。
32
+ // 空对象(加密快照)⇒ 删除观测:判定层因此回落 id 比较,绝不拿 state.sections 顶上。
33
+ const remoteHashes = { ...meta.sections };
34
+ if (Object.keys(remoteHashes).length > 0)
35
+ state.lastRemoteSections = remoteHashes;
36
+ else
37
+ delete state.lastRemoteSections;
31
38
  state.transport = opts.transport;
32
39
  await saveSyncState(opts.stateDir, state, opts.fsx);
33
40
  opts.warnings.push(opts.msg(ancestorKnown ? 'sync.pushBaselineAdopted' : 'sync.pushBaselineAdoptedNoAncestor', {
@@ -0,0 +1,67 @@
1
+ /**
2
+ * m-sync-flow:写基线的唯一实现(本地祖先副本 + sync-state)。
3
+ *
4
+ * 为什么单独成模块:这段逻辑是「祖先副本布局 + 远端指针 + 每分区 hash + 裁剪」的完整落盘决策,
5
+ * 不需要引擎的任何其他状态(只吃快照目录、通道身份与时间);留在 SyncEngine 里会顶穿体量棘轮。
6
+ *
7
+ * **两个 id 语义严格分开(P0-7),不要再混用同一个字段**:
8
+ * - `snapshotId`:本次基线的**本地**快照对象 id,同时是本地祖先副本的目录名(写入 `ancestorId`);
9
+ * - `opts.remoteSnapshotId`:该基线在**远端**对应的快照 id(写入 `lastSnapshotId`)。缺省 = snapshotId
10
+ * (push 路径两者天然相同);合并/应用路径**必须显式传**,否则 lastSnapshotId 会退化成「一个远端
11
+ * 并不存在的本地 id」→ hasNewRemoteSnapshot() 恒判「远端有新生」,每轮白跑 list + download + merge。
12
+ * 传入 `''` 表示「远端 id 未知」——宁可留空,也不要把本地 id 冒充成远端 id。
13
+ *
14
+ * **issue #140 / G-44**:`opts.remoteSections` 是**远端观测**(远端快照自己携带的分区哈希),
15
+ * 与传入的 `sections`(本机观测,用来算 hasLocalChanges 的基线)是两个不同来源。
16
+ * 早先的事故正是「一参两用」:拿本机 hash 当远端现状,判定就永远自洽、永远看不出远端真的变了。
17
+ */
18
+ import type { Platform, SectionData, SectionId } from '../schema/types.ts';
19
+ import type { MsgFunc } from '../core/messages.ts';
20
+ import type { SnapshotFs } from './fs.ts';
21
+ import type { PendingMerge, SectionHashes } from './sync-state.ts';
22
+ export interface RecordBaselineOptions {
23
+ writeAncestor?: boolean;
24
+ /** 提供即把祖先副本写成**密文**(密码仅本次内存使用;issue #107) */
25
+ ancestorPassword?: string;
26
+ remoteSnapshotId?: string;
27
+ /** 保留当前祖先副本与 ancestorId(缺省 false = 既有行为逐字不变) */
28
+ preserveAncestor?: boolean;
29
+ /** 待裁决冲突记录:null = 清除;缺省 = 不动该字段 */
30
+ pendingMerge?: PendingMerge | null;
31
+ /** P1-5:本轮**实际带走**的会话单元(提供即覆盖;缺省 = 保留原记录) */
32
+ sessionUnits?: string[];
33
+ /** P1-5:本轮累积的删除墓碑(提供即覆盖;缺省 = 保留原记录) */
34
+ deletedSessions?: string[];
35
+ /**
36
+ * issue #140:本次基线对应的**远端观测**(远端快照实际携带的分区哈希,G-44)。
37
+ *
38
+ * - 提供且非空 ⇒ 原样记录(只允许来自「真的看到了远端 sections」的调用点);
39
+ * - 提供但为空(加密快照)或未提供 ⇒ 指针若发生变化则**删除**既有观测(未知 ⇒ 判定回落 id);
40
+ * - 指针未变(preserveAncestor 的待裁决冲突)⇒ 保留既有观测(远端没动,观测仍成立)。
41
+ * 绝不允许由传入的 `sections`(本机观测)推导。
42
+ */
43
+ remoteSections?: SectionHashes;
44
+ }
45
+ /** 落盘所需的环境(引擎逐字段透传;此处不持有引擎实例)。 */
46
+ export interface RecordBaselineEnv {
47
+ fsx: SnapshotFs;
48
+ stateDir: string;
49
+ localSnapshotsDir?: string;
50
+ dshVersion: string;
51
+ platform: Platform;
52
+ transport: {
53
+ type: string;
54
+ ref: string;
55
+ };
56
+ now: () => Date;
57
+ msg: MsgFunc;
58
+ }
59
+ export interface RecordBaselineInput {
60
+ snapshotId: string;
61
+ /** 基线**恒为明文**(加密快照的基线 hash 也用明文算,供 hasLocalChanges 比较)。 */
62
+ sections: Partial<Record<SectionId, SectionData>>;
63
+ nowIso?: string;
64
+ opts?: RecordBaselineOptions;
65
+ env: RecordBaselineEnv;
66
+ }
67
+ export declare function recordBaseline(input: RecordBaselineInput): Promise<void>;