dsh-config-manager 0.4.3 → 0.5.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 (254) hide show
  1. package/README.md +10 -0
  2. package/README.zh-CN.md +10 -0
  3. package/lib/adapters/mcp.d.ts +9 -0
  4. package/lib/adapters/mcp.js +37 -0
  5. package/lib/adapters/plugins.js +10 -2
  6. package/lib/adapters/pnpm-workspace.js +1 -1
  7. package/lib/adapters/self.d.ts +2 -0
  8. package/lib/adapters/self.js +18 -2
  9. package/lib/adapters/workspaces.js +1 -1
  10. package/lib/cli/restore-resume.js +1 -1
  11. package/lib/cli/web/page.js +2 -2
  12. package/lib/client.d.ts +14 -41
  13. package/lib/client.js +794 -716
  14. package/lib/core/backup.d.ts +11 -0
  15. package/lib/core/backup.js +27 -0
  16. package/lib/core/env-lock-lifecycle.d.ts +17 -3
  17. package/lib/core/env-lock-lifecycle.js +38 -0
  18. package/lib/core/external-failure.d.ts +9 -0
  19. package/lib/core/external-failure.js +50 -0
  20. package/lib/core/local-plugin-host.d.ts +9 -7
  21. package/lib/core/local-plugin-host.js +109 -15
  22. package/lib/core/local-plugin-pack.d.ts +20 -0
  23. package/lib/core/local-plugin-pack.js +18 -3
  24. package/lib/core/mcp-connector-store.d.ts +13 -0
  25. package/lib/core/mcp-connector-store.js +16 -1
  26. package/lib/core/messages-core.d.ts +45 -0
  27. package/lib/core/messages-core.js +92 -0
  28. package/lib/core/messages.d.ts +1 -0
  29. package/lib/core/messages.js +6 -0
  30. package/lib/core/model-tool-plans.d.ts +66 -0
  31. package/lib/core/model-tool-plans.js +128 -0
  32. package/lib/core/model-tools.d.ts +96 -8
  33. package/lib/core/model-tools.js +568 -31
  34. package/lib/core/phase3-host.js +10 -2
  35. package/lib/core/plugin-data-registry.d.ts +1 -1
  36. package/lib/core/plugin-data-registry.js +1 -1
  37. package/lib/core/restore-plan-fingerprint.d.ts +2 -0
  38. package/lib/core/restore-plan-fingerprint.js +18 -0
  39. package/lib/core/restore-resume.d.ts +1 -1
  40. package/lib/core/restore-resume.js +1 -1
  41. package/lib/core/restore.d.ts +5 -0
  42. package/lib/core/restore.js +4 -1
  43. package/lib/core/types.d.ts +12 -0
  44. package/lib/foreign/claude-sessions.d.ts +1 -1
  45. package/lib/foreign/claude-sessions.js +1 -1
  46. package/lib/foreign/registry.js +1 -1
  47. package/lib/foreign/types.d.ts +1 -1
  48. package/lib/index.d.ts +15 -15
  49. package/lib/index.js +60 -67
  50. package/lib/market/git-file-writer.js +1 -1
  51. package/lib/market/github-repos.js +1 -1
  52. package/lib/market/market-config.js +1 -1
  53. package/lib/market/messages-market.js +1 -1
  54. package/lib/market/my-repo.js +1 -1
  55. package/lib/market/prepare.js +1 -1
  56. package/lib/market/reader.js +2 -2
  57. package/lib/market/repo-url.d.ts +1 -1
  58. package/lib/market/security.js +2 -2
  59. package/lib/market/star-cache.d.ts +1 -1
  60. package/lib/market/types.d.ts +1 -1
  61. package/lib/market/types.js +1 -1
  62. package/lib/market/url.js +1 -1
  63. package/lib/routes/backup.js +17 -9
  64. package/lib/routes/index.d.ts +1 -1
  65. package/lib/routes/kit.d.ts +2 -2
  66. package/lib/routes/market.d.ts +1 -1
  67. package/lib/routes/market.js +3 -60
  68. package/lib/routes/model-tools-deps.d.ts +41 -0
  69. package/lib/routes/model-tools-deps.js +18 -0
  70. package/lib/routes/recovery.js +5 -3
  71. package/lib/routes/route-support.d.ts +18 -26
  72. package/lib/routes/route-support.js +19 -32
  73. package/lib/routes/snapshots.d.ts +1 -1
  74. package/lib/routes/snapshots.js +4 -40
  75. package/lib/routes/sync.js +40 -28
  76. package/lib/schema/index.d.ts +2 -2
  77. package/lib/schema/index.js +2 -2
  78. package/lib/schema/section-registry.d.ts +5 -3
  79. package/lib/schema/section-registry.js +7 -3
  80. package/lib/security/secret-scanner.js +1 -1
  81. package/lib/sync/apply-bundle.d.ts +50 -0
  82. package/lib/sync/apply-bundle.js +60 -0
  83. package/lib/sync/autosync-scheduler.d.ts +9 -0
  84. package/lib/sync/autosync-scheduler.js +118 -89
  85. package/lib/sync/backup-scheduler.js +5 -4
  86. package/lib/sync/blob-store.d.ts +2 -2
  87. package/lib/sync/git/git-transport.d.ts +12 -0
  88. package/lib/sync/git/git-transport.js +50 -2
  89. package/lib/sync/merge.d.ts +2 -0
  90. package/lib/sync/merge.js +28 -0
  91. package/lib/sync/messages.d.ts +4 -0
  92. package/lib/sync/messages.js +9 -2
  93. package/lib/sync/s3/s3-transport.d.ts +1 -1
  94. package/lib/sync/s3/s3-transport.js +1 -1
  95. package/lib/sync/sync-engine.d.ts +4 -4
  96. package/lib/sync/sync-engine.js +25 -26
  97. package/lib/sync/sync-scope-boot.d.ts +34 -0
  98. package/lib/sync/sync-scope-boot.js +71 -0
  99. package/lib/sync/sync-scope.d.ts +103 -0
  100. package/lib/sync/sync-scope.js +229 -0
  101. package/lib/sync/sync-selection.d.ts +17 -4
  102. package/lib/sync/sync-selection.js +40 -14
  103. package/lib/sync/transport.d.ts +4 -1
  104. package/lib/sync/transport.js +6 -0
  105. package/lib/sync/webdav/webdav-transport.js +1 -1
  106. package/lib/sync/workspace-merge.d.ts +36 -0
  107. package/lib/sync/workspace-merge.js +152 -0
  108. package/lib/ui/backup-schedule.d.ts +13 -2
  109. package/lib/ui/backup-schedule.js +3 -0
  110. package/lib/ui/snapshots-view.d.ts +16 -0
  111. package/lib/ui/snapshots-view.js +21 -0
  112. package/lib/utils/env-lock.d.ts +96 -0
  113. package/lib/utils/env-lock.js +332 -111
  114. package/lib/utils/messages-utils.d.ts +6 -0
  115. package/lib/utils/messages-utils.js +17 -1
  116. package/lib/utils/patch-yaml.js +1 -1
  117. package/lib/utils/zip.js +1 -1
  118. package/package.json +3 -2
  119. package/src/adapters/mcp.test.ts +28 -0
  120. package/src/adapters/mcp.ts +33 -0
  121. package/src/adapters/plugins.test.ts +49 -0
  122. package/src/adapters/plugins.ts +9 -1
  123. package/src/adapters/pnpm-workspace.ts +1 -1
  124. package/src/adapters/self.test.ts +39 -1
  125. package/src/adapters/self.ts +20 -2
  126. package/src/adapters/workspaces.ts +1 -1
  127. package/src/cli/restore-resume.ts +1 -1
  128. package/src/cli/web/page.ts +2 -2
  129. package/src/client/about/AboutPanel.tsx +1 -1
  130. package/src/client/about/about-view.test.ts +1 -1
  131. package/src/client/about/about-view.ts +1 -1
  132. package/src/client/api.ts +1 -6
  133. package/src/client/chat/chat-entry-view.test.ts +1 -1
  134. package/src/client/chat/chat-slots.ts +1 -1
  135. package/src/client/chat/rollback-diff-tab.ts +1 -1
  136. package/src/client/client-types.ts +1 -1
  137. package/src/client/common/routes.ts +1 -5
  138. package/src/client/css-scale-guard.test.ts +1 -1
  139. package/src/client/home/HomePanel.tsx +3 -0
  140. package/src/client/library/ArtifactRow.tsx +14 -2
  141. package/src/client/library/LibraryPanel.tsx +44 -0
  142. package/src/client/locales/overview.ts +10 -2
  143. package/src/client/locales/sessions.ts +3 -0
  144. package/src/client/market/MyConfigsView.tsx +1 -1
  145. package/src/client/market/market-api.ts +2 -14
  146. package/src/client/market/market-locales.ts +1 -1
  147. package/src/client/market/market-view.ts +3 -3
  148. package/src/client/market/my-configs-api.ts +1 -1
  149. package/src/client/market/my-configs-view.ts +1 -1
  150. package/src/client/recovery/recovery-locales.test.ts +1 -1
  151. package/src/client/run-store.ts +1 -1
  152. package/src/client/sync/SyncSectionPickerDialog.tsx +0 -5
  153. package/src/client/sync/history-model.test.ts +28 -7
  154. package/src/client/sync/history-model.ts +6 -3
  155. package/src/client/sync/sync-locales.ts +10 -4
  156. package/src/client/sync/sync-view.ts +1 -1
  157. package/src/core/analyzer-cache.test.ts +1 -1
  158. package/src/core/backup.test.ts +45 -1
  159. package/src/core/backup.ts +25 -0
  160. package/src/core/disk-usage.test.ts +2 -0
  161. package/src/core/env-lock-lifecycle.ts +33 -3
  162. package/src/core/external-failure.test.ts +60 -0
  163. package/src/core/external-failure.ts +54 -0
  164. package/src/core/integrity-extra-entries.test.ts +1 -1
  165. package/src/core/local-plugin-host.test.ts +134 -0
  166. package/src/core/local-plugin-host.ts +122 -17
  167. package/src/core/local-plugin-pack.ts +39 -3
  168. package/src/core/mcp-connector-store.ts +26 -1
  169. package/src/core/messages-core.ts +94 -0
  170. package/src/core/messages.ts +6 -0
  171. package/src/core/model-tool-plans.test.ts +111 -0
  172. package/src/core/model-tool-plans.ts +170 -0
  173. package/src/core/model-tools.test.ts +212 -12
  174. package/src/core/model-tools.ts +710 -38
  175. package/src/core/phase3-host.ts +10 -2
  176. package/src/core/phase3-production-integration.test.ts +43 -0
  177. package/src/core/plugin-data-registry.ts +1 -1
  178. package/src/core/restore-plan-fingerprint.ts +19 -0
  179. package/src/core/restore-resume.ts +1 -1
  180. package/src/core/restore.ts +9 -1
  181. package/src/core/types.ts +12 -0
  182. package/src/foreign/claude-sessions.ts +3 -3
  183. package/src/foreign/registry.ts +1 -1
  184. package/src/foreign/types.ts +1 -1
  185. package/src/index.ts +91 -98
  186. package/src/market/git-file-writer.ts +1 -1
  187. package/src/market/github-repos.test.ts +1 -1
  188. package/src/market/github-repos.ts +1 -1
  189. package/src/market/market-config.ts +1 -1
  190. package/src/market/messages-market.ts +1 -1
  191. package/src/market/my-repo.test.ts +1 -1
  192. package/src/market/my-repo.ts +1 -1
  193. package/src/market/prepare.test.ts +1 -1
  194. package/src/market/prepare.ts +1 -1
  195. package/src/market/reader.ts +2 -2
  196. package/src/market/repo-url.ts +1 -1
  197. package/src/market/security.ts +2 -2
  198. package/src/market/star-cache.ts +1 -1
  199. package/src/market/types.ts +1 -1
  200. package/src/market/url.test.ts +1 -1
  201. package/src/market/url.ts +1 -1
  202. package/src/profiles/dsh-profile-copy-rollback.test.ts +1 -1
  203. package/src/routes/backup.ts +16 -9
  204. package/src/routes/index.ts +1 -1
  205. package/src/routes/kit.ts +2 -2
  206. package/src/routes/market.ts +2 -59
  207. package/src/routes/model-tools-deps.ts +56 -0
  208. package/src/routes/recovery.ts +5 -3
  209. package/src/routes/route-support.ts +49 -36
  210. package/src/routes/snapshots.ts +4 -40
  211. package/src/routes/sync.ts +39 -27
  212. package/src/schema/index.ts +2 -2
  213. package/src/schema/manifest-schema.test.ts +2 -2
  214. package/src/schema/registry.test.ts +1 -1
  215. package/src/schema/section-registry.ts +9 -4
  216. package/src/security/redaction.test.ts +1 -1
  217. package/src/security/secret-scanner.test.ts +2 -2
  218. package/src/security/secret-scanner.ts +1 -1
  219. package/src/sync/apply-bundle.ts +104 -0
  220. package/src/sync/autosync-scheduler.test.ts +180 -6
  221. package/src/sync/autosync-scheduler.ts +132 -92
  222. package/src/sync/backup-scheduler.test.ts +11 -4
  223. package/src/sync/backup-scheduler.ts +5 -4
  224. package/src/sync/blob-store.ts +2 -2
  225. package/src/sync/git/git-transport.test.ts +62 -0
  226. package/src/sync/git/git-transport.ts +54 -3
  227. package/src/sync/merge.ts +29 -0
  228. package/src/sync/messages.ts +9 -2
  229. package/src/sync/s3/s3-transport.ts +1 -1
  230. package/src/sync/sync-engine.test.ts +238 -2
  231. package/src/sync/sync-engine.ts +25 -26
  232. package/src/sync/sync-preview-push.test.ts +2 -1
  233. package/src/sync/sync-scope-boot.ts +87 -0
  234. package/src/sync/sync-scope.test.ts +154 -0
  235. package/src/sync/sync-scope.ts +256 -0
  236. package/src/sync/sync-selection.test.ts +76 -2
  237. package/src/sync/sync-selection.ts +40 -13
  238. package/src/sync/transport.test.ts +21 -1
  239. package/src/sync/transport.ts +12 -0
  240. package/src/sync/webdav/webdav-delete-index-unreadable.test.ts +2 -2
  241. package/src/sync/webdav/webdav-transport.ts +1 -1
  242. package/src/sync/workspace-merge.test.ts +110 -0
  243. package/src/sync/workspace-merge.ts +180 -0
  244. package/src/ui/backup-schedule.test.ts +5 -0
  245. package/src/ui/backup-schedule.ts +21 -2
  246. package/src/ui/session-issue-labels.ts +1 -1
  247. package/src/ui/snapshots-view.test.ts +32 -0
  248. package/src/ui/snapshots-view.ts +34 -0
  249. package/src/utils/env-lock.test.ts +242 -9
  250. package/src/utils/env-lock.ts +247 -13
  251. package/src/utils/messages-utils.ts +17 -1
  252. package/src/utils/patch-yaml.ts +1 -1
  253. package/src/utils/zip.ts +1 -1
  254. package/src/client/CLIENT_DEPENDENCIES.md +0 -94
@@ -24,6 +24,7 @@ import { formatDateTimeFull } from '../sync/history-model.ts'
24
24
  import { deviceLabelsById } from '../sync/remote-device-view.ts'
25
25
  import { runStore, type LibraryStoreSlice } from '../run-store.ts'
26
26
  import { Badge, Button, Card, Empty } from '../common/ui.tsx'
27
+ import { snapshotOriginOf, snapshotOriginState } from '../../ui/snapshots-view.ts'
27
28
  import { SkeletonRows } from '../common/Skeleton.tsx'
28
29
  import { redact } from '../../security/redaction.ts'
29
30
  import { InfoHint } from '../common/InfoHint.tsx'
@@ -84,6 +85,12 @@ export function LibraryPanel({ api, syncApi, marketApi, t, uiT, onAction, onOpen
84
85
  const [remoteChannel, setRemoteChannel] = useState<'git' | 'webdav' | null>(null)
85
86
  /** 面板内部的刷新信号(失败源卡片里的「重试」);外部的走 props.refreshTick */
86
87
  const [localTick, setLocalTick] = useState(0)
88
+ /**
89
+ * 当前档案名(只用于「来源档案」徽章的差异对照):取 `/status` 的诊断位 `profile`。
90
+ * 宿主给不出(老宿主 / 独立 CLI)→ null,此时只显示档案名,**不声称「来自他人档案」**
91
+ * (不知道自己在哪个档案时,那个结论无法证明)。
92
+ */
93
+ const [currentProfile, setCurrentProfile] = useState<string | null>(null)
87
94
 
88
95
  const mounted = useRef(true)
89
96
  useEffect(() => () => { mounted.current = false }, [])
@@ -132,6 +139,14 @@ export function LibraryPanel({ api, syncApi, marketApi, t, uiT, onAction, onOpen
132
139
  })
133
140
  }))
134
141
  put(setMarket, marketApi.browse().then((res) => res.items))
142
+ // 当前档案:与上面四源并行、**失败不影响任何源的状态**(只是少一个对照值)
143
+ api.status().then(
144
+ (status) => {
145
+ if (!mounted.current) return
146
+ setCurrentProfile(typeof status.profile === 'string' && status.profile !== '' ? status.profile : null)
147
+ },
148
+ () => { if (mounted.current) setCurrentProfile(null) },
149
+ )
135
150
  // 通道类型与远端地址都从 /sync/status 取(已并入上面的远端源加载,避免同一接口打两次)
136
151
  }, [api, syncApi, marketApi, localTick, refreshTick])
137
152
 
@@ -177,6 +192,33 @@ export function LibraryPanel({ api, syncApi, marketApi, t, uiT, onAction, onOpen
177
192
  { id: 'market', label: t('library.kind.market'), count: market.status === 'ready' ? counts['market'] : null },
178
193
  ]
179
194
 
195
+
196
+ /**
197
+ * 快照 id → 来源档案(只收**真的带来源**的):徽章只挂在本机快照行上,
198
+ * 其它三个来源没有「档案」语义。
199
+ */
200
+ const originOfSnapshot = useMemo(() => {
201
+ const map = new Map<string, string>()
202
+ for (const meta of snapshots.items) {
203
+ const profile = snapshotOriginOf(meta)
204
+ if (profile !== undefined) map.set(meta.id, profile)
205
+ }
206
+ return map
207
+ }, [snapshots.items])
208
+
209
+ /**
210
+ * 行首来源徽章:档案名恒显示;只有「已知当前档案且不同」时才升到 warn 并带差异说明
211
+ * (宿主没给当前档案时只显示名字 —— 那是无法证明的结论)。
212
+ */
213
+ const originBadgeOf = (row: ArtifactRow): { label: string; hint?: string; kind: 'info' | 'warn' } | undefined => {
214
+ if (row.kind !== 'snapshot') return undefined
215
+ const profile = originOfSnapshot.get(row.ref.snapshotId ?? '')
216
+ if (profile === undefined) return undefined
217
+ return snapshotOriginState({ originProfile: profile }, currentProfile ?? undefined) === 'foreign'
218
+ ? { label: profile, hint: t('library.origin.foreign'), kind: 'warn' }
219
+ : { label: profile, kind: 'info' }
220
+ }
221
+
180
222
  /** 加密项计数:只数**当前筛选后**的行(底部徽章必须与眼前列表一致,见 footer 注释) */
181
223
  const encryptedCount = useMemo(() => filtered.filter((row) => row.badges.includes('encrypted')).length, [filtered])
182
224
 
@@ -209,6 +251,7 @@ export function LibraryPanel({ api, syncApi, marketApi, t, uiT, onAction, onOpen
209
251
  ))}
210
252
  </div>
211
253
 
254
+
212
255
  <input
213
256
  className={css.librarySearch}
214
257
  type="search"
@@ -276,6 +319,7 @@ export function LibraryPanel({ api, syncApi, marketApi, t, uiT, onAction, onOpen
276
319
  // 只把**本行**的进行中动作交给行组件:其余行保持可点(一次只挡同一行)
277
320
  pending={pending !== null && pending.key === row.key ? pending.capability : null}
278
321
  deviceLabel={row.kind === 'remote-snapshot' ? deviceLabelOf.get(row.ref.remoteId ?? '') : undefined}
322
+ originBadge={originBadgeOf(row)}
279
323
  />
280
324
  ))}
281
325
  </ul>
@@ -38,7 +38,11 @@ export const zh = {
38
38
  'overview.quick.backupSkippedDisabled': '已跳过:定时备份未启用(没有生成任何备份文件)',
39
39
  'overview.quick.backupSkippedRunning': '已跳过:上一次备份仍在进行中',
40
40
  'overview.quick.backupSkippedConflict': '已跳过:另一项任务正在执行(防重)',
41
- 'overview.quick.backupSkippedLocked': '已跳过:环境锁被占用(另一项任务进行中,或存在需回收的残留锁)',
41
+ // 分档后这句话只留给「真被另一项活任务持有」;残留锁/SAFE MODE/不可用各有自己的键(issue:locks 为空也说被占用)
42
+ 'overview.quick.backupSkippedLocked': '已跳过:另一个任务正在使用环境锁,稍后重试即可',
43
+ 'overview.quick.backupSkippedLockStale': '已跳过:存在残留环境锁(上次任务异常退出留下,重试与重启都不会自愈)——请到「事故恢复」回收',
44
+ 'overview.quick.backupSkippedLockUnavailable': '已跳过:环境锁暂时不可用(锁目录读写失败或状态未知),请稍后重试并查看宿主日志',
45
+ 'overview.quick.backupSkippedSafeMode': '已跳过:插件处于 SAFE MODE(外部操作失败后自动阻断写入)——请到「事故恢复」处理后重试',
42
46
  'overview.quick.backupSkippedOther': '已跳过:备份服务当前无法执行(详情见宿主日志)',
43
47
  'overview.quick.backupFailed': '备份失败:{message}',
44
48
  'overview.activity.title': '最近活动',
@@ -112,7 +116,11 @@ export const en: Record<keyof typeof zh, string> = {
112
116
  'overview.quick.backupSkippedDisabled': 'Skipped: scheduled backups are disabled (no backup file was created)',
113
117
  'overview.quick.backupSkippedRunning': 'Skipped: a previous backup is still running',
114
118
  'overview.quick.backupSkippedConflict': 'Skipped: another task is running (duplicate guard)',
115
- 'overview.quick.backupSkippedLocked': 'Skipped: the environment lock is held (another task is running, or a stale lock needs recovery)',
119
+ // After the split this wording only covers "held by another live task"; stale/SAFE MODE/unavailable have their own keys
120
+ 'overview.quick.backupSkippedLocked': 'Skipped: another task is using the environment lock — retry shortly',
121
+ 'overview.quick.backupSkippedLockStale': 'Skipped: a stale environment lock is left on disk (an earlier task died; retrying or restarting will not clear it) — reclaim it in Incident recovery',
122
+ 'overview.quick.backupSkippedLockUnavailable': 'Skipped: the environment lock cannot be used right now (lock directory unreadable/unwritable or in an unknown state) — retry later and check the host logs',
123
+ 'overview.quick.backupSkippedSafeMode': 'Skipped: the plugin is in SAFE MODE (writes are blocked after an external operation failed) — clear it in Incident recovery, then retry',
116
124
  'overview.quick.backupSkippedOther': 'Skipped: the backup service cannot run right now (see host logs for details)',
117
125
  'overview.quick.backupFailed': 'Backup failed: {message}',
118
126
  'overview.activity.title': 'Recent activity',
@@ -92,6 +92,8 @@ export const zh = {
92
92
  'library.moreActions': '更多操作',
93
93
  'backupFiles.inspectEncrypted': '这是整包加密的备份,无法直接查看内容:请点「导入」——向导会先让你输入备份密码解锁,解锁后即可看到包含的分区与差异。',
94
94
  'library.source.all': '全部',
95
+ // 来源档案(originProfile):快照行徽章 + 列表筛选。档案名本身不翻译,只有这三条通用文案需要。
96
+ 'library.origin.foreign': '来自他人档案',
95
97
  'library.kind.snapshot': '本机快照',
96
98
  'library.kind.backupFile': '备份文件',
97
99
  'library.kind.remote': '远端快照',
@@ -218,6 +220,7 @@ export const en: Record<keyof typeof zh, string> = {
218
220
  'library.moreActions': 'More actions',
219
221
  'backupFiles.inspectEncrypted': 'This backup is fully encrypted, so its contents cannot be inspected directly. Use Import — the wizard asks for the backup password, unlocks the archive, and then shows its sections and diff.',
220
222
  'library.source.all': 'All',
223
+ 'library.origin.foreign': 'From another profile',
221
224
  'library.kind.snapshot': 'Local snapshot',
222
225
  'library.kind.backupFile': 'Backup file',
223
226
  'library.kind.remote': 'Remote snapshot',
@@ -1,5 +1,5 @@
1
1
  /**
2
- * 「我的配置」视图(设计文档 docs/design/2026-08-20-my-configs-design.md §4.6)。
2
+ * 「我的配置」视图(设计文档 docs/archive/2026-08-20-my-configs-design.md §4.6)。
3
3
  *
4
4
  * 组装「一键上传 / 查看已上传 / 一键更新 / 装回本地」:
5
5
  * - **登录卡**:未登录 → GitHub device flow 登录(复用 SyncApi.githubStart/Poll/Cancel,
@@ -8,7 +8,7 @@
8
8
  * 保证 client 与 Host 请求/响应契约单一来源,避免漂移(与 sync-api.ts 引用 sync-engine.ts 同构)。
9
9
  *
10
10
  * 端点契约(Host 半 src/index.ts 的 makeRoutes 实现;市场设计的上游依据 =
11
- * docs/design/2026-08-19-market-publish-design.md —— 旧的市场设计文档已在 2026-08-19
11
+ * docs/archive/2026-08-19-market-publish-design.md —— 旧的市场设计文档已在 2026-08-19
12
12
  * 大写 Docs/ 清理中删除,该文件自述「为市场设计的新上游依据」,故此处只指向它,
13
13
  * 不再书写已删除文档的路径、也不臆造章节号;内置单市场、只读不可编辑,无 add/remove):
14
14
  * ```
@@ -16,7 +16,6 @@
16
16
  * POST /api/dsh-config-manager/market/refresh → MarketRefreshResponse (拉取最新 index.json)
17
17
  * POST /api/dsh-config-manager/market/browse → MarketBrowseResponse (合并 index + 缓存状态)
18
18
  * POST /api/dsh-config-manager/market/download → MarketDownloadResult ({ itemId } 拉取+校验+dry-run 预览)
19
- * POST /api/dsh-config-manager/market/prepare → MarketPrepareResponse (发布向导:上传 zip + 元数据 → 条目包)
20
19
  * ```
21
20
  * 确认导入(apply)**复用现有** `POST /api/dsh-config-manager/execute`(见 ../api.ts executeImportPlan),
22
21
  * 不新增第二条导入路径 —— 保证安全校验/回滚/凭据补录全部走既有管道。
@@ -30,7 +29,7 @@
30
29
  */
31
30
  import type {
32
31
  MarketBrowseResponse, MarketDownloadResult, MarketItemDetail, MarketListItem,
33
- MarketPreparePayload, MarketPrepareResponse, MarketRefreshResponse, MarketStatusResponse,
32
+ MarketRefreshResponse, MarketStatusResponse,
34
33
  } from '../../market/types.ts';
35
34
  import type { UiT } from '../../ui/i18n.ts';
36
35
  import { getJson, LONG_REQUEST_TIMEOUT_MS, postJson, type RequestOptions } from '../common/http.ts';
@@ -79,15 +78,4 @@ export class MarketApi {
79
78
  async download(itemId: string, repo?: string): Promise<MarketDownloadResult> {
80
79
  return postJson<MarketDownloadResult>(MARKET_API.download, { itemId, ...(repo !== undefined && repo !== '' ? { repo } : {}) }, this.t, MARKET_OPTS);
81
80
  }
82
-
83
- /** 发布向导:由「上传 zip + 用户填写元数据」生成市场条目包(L2 manifest + SHA-256 + sections),
84
- * 供 UI 展示/复制与引导推送。零写入配置(发布目录在受控临时区);不含任何凭据字段。 */
85
- async prepare(payload: MarketPreparePayload): Promise<MarketPrepareResponse> {
86
- return postJson<MarketPrepareResponse>(MARKET_API.prepare, payload, this.t, MARKET_OPTS);
87
- }
88
-
89
- /** 发布包下载 URL(受控临时区 zip;经宿主 /download 端点,无凭据、无写操作) */
90
- downloadPublishUrl(zipPath: string): string {
91
- return `${MARKET_API.fileDownload}?path=${encodeURIComponent(zipPath)}`;
92
- }
93
81
  }
@@ -29,7 +29,7 @@ export const zh = {
29
29
  'list.categoriesAll': '全部类别',
30
30
  'list.sectionsAll': '全部分区',
31
31
  'list.sectionsUnknown': '另有 {count} 个条目未下载,无法按分区匹配',
32
- // 来源筛选 + 排序(2026-08-21 新增,docs/design/2026-08-21-market-star-filter-sort-design.md)
32
+ // 来源筛选 + 排序(2026-08-21 新增,docs/archive/2026-08-21-market-star-filter-sort-design.md)
33
33
  'list.sourceAll': '全部来源',
34
34
  'list.sourceOfficial': '官方配置',
35
35
  'list.sourcePersonal': '个人配置',
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * 配置市场区块的客户端渲染装配层(m-market-ui,node 可测)。
3
3
  *
4
- * 设计纪律(市场设计上游依据 = docs/design/2026-08-19-market-publish-design.md:
4
+ * 设计纪律(市场设计上游依据 = docs/archive/2026-08-19-market-publish-design.md:
5
5
  * 旧的市场设计文档已在 2026-08-19 大写 Docs/ 清理中删除,其章节号在新文档中不存在,
6
6
  * 故只引用该文件、不再引用 § 号):
7
7
  * - **共享渲染模型唯一权威 = Host 侧 `src/market/view.ts`**(marketStatusText /
@@ -34,7 +34,7 @@ import { formatMinuteStamp, parseDateInput } from '../../utils/time.ts';
34
34
  /* ---------------------------------------------------------------- 客户端专属:来源徽章 */
35
35
 
36
36
  /**
37
- * 条目来源徽章 kind(阶段 1:条目级来源仓库,docs/design/2026-08-19-market-publish-design.md §3.3):
37
+ * 条目来源徽章 kind(阶段 1:条目级来源仓库,docs/archive/2026-08-19-market-publish-design.md §3.3):
38
38
  * - `'ok'`(官方):`item.repo` 缺省(条目与市场仓库同仓)或 `item.repo` 为官方默认地址;
39
39
  * - `'warn'`(第三方):`item.repo` 存在且非官方默认地址(条目由作者自托管仓库发布)。
40
40
  * 判定基准复用 `builtin.ts` 的 `isOfficialMarket`(固定官方地址比较):env 覆盖为预览仓库时,
@@ -61,7 +61,7 @@ export function collectCategories(items: readonly MarketListItem[]): string[] {
61
61
  /* ---------------------------------------------------------------- 客户端专属:来源筛选 / 排序 */
62
62
 
63
63
  /**
64
- * 来源筛选值(docs/design/2026-08-21-market-star-filter-sort-design.md §3.3.1):
64
+ * 来源筛选值(docs/archive/2026-08-21-market-star-filter-sort-design.md §3.3.1):
65
65
  * - 'all' 全部来源;
66
66
  * - 'official' 官方配置:条目无 repo(= 官方市场仓库自身)或 repo 为官方地址;
67
67
  * - 'personal' 个人配置:条目带非官方 repo(作者自托管仓库)。
@@ -4,7 +4,7 @@
4
4
  * 端点常量与请求封装都是**单一来源**:路由常量见 `common/routes.ts`,
5
5
  * `readJson` / `getJson` / `postJson`(统一超时 + 取消 + 错误映射)见 `common/http.ts`(W4 收敛)。
6
6
  *
7
- * 端点契约(Host 半 src/index.ts 的 makeRoutes 按 docs/design/2026-08-20-my-configs-design.md §4.2 实现):
7
+ * 端点契约(Host 半 src/index.ts 的 makeRoutes 按 docs/archive/2026-08-20-my-configs-design.md §4.2 实现):
8
8
  * ```
9
9
  * POST /api/dsh-config-manager/me/status → MyMeStatusResponse (登录态 + 目标仓库状态;401 → 未登录)
10
10
  * POST /api/dsh-config-manager/me/upload → MyUploadResult ({ zipPath, form } 一键上传全流程)
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * 「我的配置」区块的客户端纯渲染装配层(m-my-configs-view,node 可测)。
3
3
  *
4
- * 设计纪律(docs/design/2026-08-20-my-configs-design.md §4.5 / §4.6):
4
+ * 设计纪律(docs/archive/2026-08-20-my-configs-design.md §4.5 / §4.6):
5
5
  * - 全部无副作用纯函数,React 壳(MyConfigsView)只装配,不承载业务逻辑;
6
6
  * - 输入数据一律由调用方(组件 / api 层)提供 —— 本文件不发起任何请求,不持有凭据;
7
7
  * - 录入最小化(§1.2):表单仅 name(预填 zip 文件名,可改)/ description(可选)/
@@ -326,7 +326,7 @@ test('T17:留存/救援点文案与引擎四常量逐句对齐,旧的不实
326
326
  test('T18-F1④:createdAfter / result.counts 必须说「留点时并不存在(之后新建)」(2026-10-12 翻面)', () => {
327
327
  // **2026-10-12 翻面**:删除候选的判据从「不在记录里」改成「**能证明**留点时不存在」(方向 A+B:
328
328
  // files ∪ skipped ∪ unreadableFiles ∪ excludedDirs ∪ 路径索引;见 src/core/rollback-point.ts 的
329
- // planCreatedRemovals 与 docs/lessons/recovery-console.md「删除集的可证性」)。
329
+ // planCreatedRemovals 与 docs/evidence/recovery-console.md「删除集的可证性」)。
330
330
  // 于是 createdAfter / leftovers 现在是**证明为留点之后新建**的路径 —— 旧文案「该点未记录」反而
331
331
  // 会把「留点时就被预算挡下、当时确实存在」的既有文件也算进去,那才是不实表述。
332
332
  // `rollback.preview.leftoversTitle` 曾在这里一起被钉;它随「文案克制」下线(清单只渲染「会删的」
@@ -81,7 +81,7 @@ import type { RecoveryPreview, RecoveryStatus, RecoveryVerifyResult } from '../u
81
81
  *
82
82
  * v3 删掉了三个化石值:`import`(导入是流程不是页面)、`market`(市场退出导航、只由 Task 承载),
83
83
  * 并把 v1 的 `overview`/`profiles` 改名为 `home`/`environment`。
84
- * 旧载荷一律由 parsePersistedState 的映射表迁到新值(docs/design/2026-10-05-ui-redesign-v3.md §5.1)。
84
+ * 旧载荷一律由 parsePersistedState 的映射表迁到新值(docs/archive/2026-10-05-ui-redesign-v3.md §5.1)。
85
85
  */
86
86
  export type PanelId = 'home' | 'library' | 'sync' | 'environment'
87
87
 
@@ -78,11 +78,6 @@ export function SyncSectionPickerDialog({ open, t, cmT, uiT, sectionName, catalo
78
78
  trailing={<InfoHint text={t('mode.sessionsPickHint')} label={t('common.infoHint')} />}
79
79
  />
80
80
  <Modal.Body scroll style={{ maxHeight: '66vh' }}>
81
- {/* 会话要在目标机的 DSH 工作区里可见,包内必须有指向它 cwd 的工作区记录。
82
- 同步通道的「工作区」是分区级开关,所以这里只能提示用户一并勾上。 */}
83
- {sections.includes('sessions') && !sections.includes('workspaces') && (
84
- <Banner kind="warn">{t('mode.sessionsWorkspaceWarn')}</Banner>
85
- )}
86
81
  {sessionFailed && <span className={css.hint}>{cmT('picker.unitsUnavailable')}</span>}
87
82
  {!sessionFailed && sessionNodes.length === 0 && sessionPending && (
88
83
  <Skeleton count={4} label={t('common.loading')} />
@@ -96,13 +96,30 @@ test('describeSkipReason:七类已知原因全部走字典(F1 收口:不
96
96
  assert.equal(describeSkipReason('weird', zhT), 'weird');
97
97
  });
98
98
 
99
- // issue #31:宿主统一以 'mutation-locked' 落历史(不细分 LOCKED/STALE)→ 界面不得透出裸 token。
100
- test('describeSkipReason:mutation-locked 必须有可读中文且不再回退原串', () => {
101
- const text = describeSkipReason('mutation-locked', zhT);
102
- assert.notEqual(text, 'mutation-locked', '绝不透出裸机器 token');
103
- assert.match(text, /环境锁/);
104
- assert.match(text, /残留锁/);
105
- assert.match(text, /另一项任务/);
99
+ // issue:锁相关四类分档(宿主 lockSkipToken)—— 此前全部落成 'mutation-locked',
100
+ // 一句文案要同时覆盖「活锁占用」与「残留锁需回收」,真机上 locks 目录为空时把排查方向带偏。
101
+ test('describeSkipReason:锁相关四类各有可读文案,且都不得回退裸 token', () => {
102
+ const tokens = ['mutation-locked', 'mutation-lock-stale', 'mutation-lock-unavailable', 'mutation-safe-mode'];
103
+ for (const token of tokens) {
104
+ assert.notEqual(describeSkipReason(token, zhT), token, '绝不透出裸机器 token: ' + token);
105
+ assert.notEqual(describeSkipReason(token, enT), token, 'en 界面同样不得透出裸 token: ' + token);
106
+ }
107
+ const locked = describeSkipReason('mutation-locked', zhT);
108
+ assert.match(locked, /环境锁/);
109
+ assert.match(locked, /另一个任务/);
110
+ // 分档后 locked 只表示「真被另一项活任务持有」,不得再暗示残留锁(那正是误导的来源)
111
+ assert.doesNotMatch(locked, /残留/);
112
+ // 残留锁:必须点名「重试/重启都不会自愈」并给出显式回收入口
113
+ const stale = describeSkipReason('mutation-lock-stale', zhT);
114
+ assert.match(stale, /残留/);
115
+ assert.match(stale, /事故恢复/);
116
+ // 不可用:既不是「被占」也不是「残留」——只能说暂时无法执行
117
+ const unavailable = describeSkipReason('mutation-lock-unavailable', zhT);
118
+ assert.match(unavailable, /不可用/);
119
+ // SAFE MODE:锁目录通常是空的,处置入口是事故恢复
120
+ const safeMode = describeSkipReason('mutation-safe-mode', zhT);
121
+ assert.match(safeMode, /SAFE MODE/);
122
+ assert.match(safeMode, /事故恢复/);
106
123
  });
107
124
 
108
125
  test('projectAutosyncEntry:摘要行 + 可展开明细(冲突分区 / 应用分区 / 错误)', () => {
@@ -255,6 +272,10 @@ test('issue #79:skipReasonKey —— 新旧码都映射到字典键,未知
255
272
  assert.equal(skipReasonKey('upToDate'), 'history.autosyncReasonUpToDate');
256
273
  assert.equal(skipReasonKey('unchanged'), 'history.autosyncReasonUnchanged');
257
274
  assert.equal(skipReasonKey('mutation-locked'), 'history.autosyncReasonMutationLocked');
275
+ // 锁分档(宿主 lockSkipToken):一类一个键,处置方向各不相同
276
+ assert.equal(skipReasonKey('mutation-lock-stale'), 'history.autosyncReasonLockStale');
277
+ assert.equal(skipReasonKey('mutation-lock-unavailable'), 'history.autosyncReasonLockUnavailable');
278
+ assert.equal(skipReasonKey('mutation-safe-mode'), 'history.autosyncReasonSafeMode');
258
279
  assert.equal(skipReasonKey('future-code-from-newer-host'), null, '未知码不猜');
259
280
  assert.equal(skipReasonKey(undefined), null);
260
281
  });
@@ -101,10 +101,13 @@ export function skipReasonKey(reason: string | undefined): SyncKey | null {
101
101
  // issue #79:状态行新增两类(无变化 / 已是最新)——此前会落到 default 渲染裸码
102
102
  case 'upToDate': return 'history.autosyncReasonUpToDate';
103
103
  case 'unchanged': return 'history.autosyncReasonUnchanged';
104
- // issue #31:宿主侧的分类锁判定(LOCKED/STALE/UNKNOWN)统一以 'mutation-locked' 落历史,
105
- // 客户端拿不到细分 reason → 文案必须同时覆盖「活锁占用」与「残留锁需回收」两种可能,
106
- // 并给出可操作方向(否则界面只显示裸 token,用户无从判断要不要处理)。
104
+ // issue:宿主此前把分类锁判定(LOCKED/STALE/UNKNOWN/SAFE MODE)一律落成 'mutation-locked',
105
+ // 客户端只能写一句「被占用或残留」——真机上 locks 目录是空的,这句把排查方向带偏(用户实测反馈)。
106
+ // 现在宿主按 lockSkipToken() 分档发 token,一类一个文案 + 一个处置方向;旧 token 仍认。
107
107
  case 'mutation-locked': return 'history.autosyncReasonMutationLocked';
108
+ case 'mutation-lock-stale': return 'history.autosyncReasonLockStale';
109
+ case 'mutation-lock-unavailable': return 'history.autosyncReasonLockUnavailable';
110
+ case 'mutation-safe-mode': return 'history.autosyncReasonSafeMode';
108
111
  // 真·自动同步(conflictPolicy='local'):冲突已按策略「保留本机并推上去」消解,
109
112
  // 远端那一版被覆盖(仍在远端历史快照里,可回滚)—— 必须与「冲突待裁决」分开说。
110
113
  case 'conflict-kept-local': return 'history.autosyncReasonConflictKeptLocal';
@@ -195,7 +195,6 @@ export const zh = {
195
195
  'mode.sessionsPickTitle': '选择要同步的历史对话',
196
196
  'mode.sessionsPickHint': '点名后只同步勾中的对话(优先于上面的数量上限);一个都不勾 = 回到「最近 N 个」模式。',
197
197
  'mode.sessionsPickReset': '改为「最近 N 个」',
198
- 'mode.sessionsWorkspaceWarn': '已勾选历史对话,但没有勾选「工作区」分区:目标机上这些对话可能归属不到任何工作区而显示不出来。建议一并勾选「工作区」。',
199
198
  'mode.gistSessionsWarn': '当前通道是 GitHub Gist,且勾选了「历史会话」:gist 会一次取回全部文件内容、单文件超限即截断、文件数还有上限,大分区同步可能失败或内容被截断。建议改用 Git / WebDAV / 对象存储通道同步历史会话,或取消勾选该分区。',
200
199
  'mode.persistHint': '分区选择已保存到本机:自动同步和手动推送都会使用此配置(重启后仍生效)。',
201
200
  'mode.choose': '选择',
@@ -275,7 +274,11 @@ export const zh = {
275
274
  'history.autosyncReasonNetwork': '网络问题',
276
275
  // F1 残留补齐(英文界面零中文):这三类此前只有硬编码中文,只住在这里
277
276
  'history.autosyncReasonEncrypted': '远端快照已加密,自动同步跳过(请手动同步)',
278
- 'history.autosyncReasonMutationLocked': '环境锁被占用(另一项任务进行中,或存在需回收的残留锁)',
277
+ 'history.autosyncReasonMutationLocked': '环境锁被另一个任务占用(稍后重试即可)',
278
+ // 宿主分档后(lockSkipToken):残留锁 / 不可用 / SAFE MODE 各有自己的处置方向,不再挤在「被占用」一句话里
279
+ 'history.autosyncReasonLockStale': '存在残留环境锁(上次任务异常退出留下,重试与重启都不会自愈)——请到「事故恢复」回收',
280
+ 'history.autosyncReasonLockUnavailable': '环境锁暂时不可用(锁目录读写失败或状态未知),稍后重试',
281
+ 'history.autosyncReasonSafeMode': '处于 SAFE MODE(外部操作失败后自动阻断写入)——请到「事故恢复」处理后重试',
279
282
  'history.autosyncReasonUnknown': '未知',
280
283
  'history.autosyncReasonConflictKeptLocal': '已按策略保留本机并覆盖远端',
281
284
  'history.autosyncReasonUpToDate': '无变化(本地与远端一致)',
@@ -642,7 +645,6 @@ export const en: Record<keyof typeof zh, string> = {
642
645
  'mode.sessionsPickTitle': 'Pick conversations to sync',
643
646
  'mode.sessionsPickHint': 'Only the picked conversations are synced (this wins over the count above). Picking none returns to the "latest N" mode.',
644
647
  'mode.sessionsPickReset': 'Use "latest N" instead',
645
- 'mode.sessionsWorkspaceWarn': 'Conversations are selected but the "Workspaces" section is not: on the target machine they may not be attributed to any workspace and stay invisible. Selecting "Workspaces" too is recommended.',
646
648
  'mode.gistSessionsWarn': 'The current channel is GitHub Gist and "Conversations" is selected: a gist returns all file content in one request, truncates any oversized single file, and caps the number of files, so syncing a large section may fail or be truncated. Use a Git / WebDAV / object-storage channel for conversations, or clear that section.',
647
649
  'mode.persistHint': 'The section selection is saved locally: both auto sync and manual push use this configuration (persists across restarts).',
648
650
  'mode.choose': 'Choose',
@@ -719,7 +721,11 @@ export const en: Record<keyof typeof zh, string> = {
719
721
  'history.autosyncReasonNotConfigured': 'No repository configured',
720
722
  'history.autosyncReasonNetwork': 'Network issue',
721
723
  'history.autosyncReasonEncrypted': 'The remote snapshot is encrypted, so auto sync skipped it (sync manually)',
722
- 'history.autosyncReasonMutationLocked': 'The environment lock is held (another task is running, or a stale lock needs reclaiming)',
724
+ 'history.autosyncReasonMutationLocked': 'The environment lock is held by another task — retry shortly',
725
+ // Host-side split (lockSkipToken): stale / unavailable / SAFE MODE each carry their own remedy
726
+ 'history.autosyncReasonLockStale': 'A stale environment lock is left on disk (an earlier task died; retrying or restarting will not clear it) — reclaim it in Incident recovery',
727
+ 'history.autosyncReasonLockUnavailable': 'The environment lock cannot be used right now (lock directory unreadable/unwritable or unknown state) — retry later',
728
+ 'history.autosyncReasonSafeMode': 'The plugin is in SAFE MODE (writes are blocked after an external operation failed) — clear it in Incident recovery, then retry',
723
729
  'history.autosyncReasonUnknown': 'Unknown',
724
730
  'history.autosyncReasonConflictKeptLocal': 'Kept the local version and overwrote the remote as configured',
725
731
  'history.autosyncReasonUpToDate': 'No changes (local and remote match)',
@@ -295,7 +295,7 @@ export function cloudIssueKey(code: string): SyncKey | null {
295
295
  /* ------------------------------------------------ G-34:gist 通道不适合大分区 */
296
296
 
297
297
  /**
298
- * G-34(docs/maintenance/known-gaps.md):gist 通道**刻意不做内容寻址外置** —— 一次 GET 把全部
298
+ * G-34(docs/known-issues/known-gaps.md):gist 通道**刻意不做内容寻址外置** —— 一次 GET 把全部
299
299
  * 文件内容取回、单文件内容超限会被截断、文件数还有上限,因此会话这类大分区不适合走 gist。
300
300
  *
301
301
  * 本常量 = 「gist 表单」常驻提示的字典键(组件按它取 sync 字典文案渲染 hint)。
@@ -159,7 +159,7 @@ test('归档身份变化(大小/mtime)→ 只读缓存立即失效', async (
159
159
  *
160
160
  * 为什么补这条:跨实例的 TOCTOU 已有用例覆盖,但生产里存在同实例调用者
161
161
  * (src/sync/sync-engine.ts:1252 createImportPlan → :1286 executeImportPlan 用的是同一个
162
- * this.importer),且 Importer 是 docs/spec/headless-consumption.md 的门面契约。
162
+ * this.importer),且 Importer 是 docs/contracts/headless-consumption.md 的门面契约。
163
163
  * 修前实测:同实例 execute 吃实例级 bundleCache → 篡改归档不被发现、返回 ok:true。
164
164
  */
165
165
  test('同实例 TOCTOU:plan 之后换包 → 同一 Importer 实例的 execute 也必须重新校验(不得吃实例缓存)', async () => {
@@ -31,7 +31,7 @@ import path from 'node:path';
31
31
 
32
32
  import {
33
33
  FileSnapshotStore, PRE_RESTORE_KEEP_ATTEMPTS, PRE_RESTORE_KEEP_DAYS,
34
- createSnapshot, normalizeDshVersion, resolveFileTarget, verifySnapshot,
34
+ createSnapshot, normalizeDshVersion, normalizeOriginProfile, resolveFileTarget, verifySnapshot,
35
35
  } from './backup.ts';
36
36
  import type { PrunePlan } from './backup.ts';
37
37
  import { existsSync } from 'node:fs';
@@ -599,3 +599,47 @@ test('BK-05/④:反悔副本全部过期后不留空壳目录(快照已不
599
599
  assert.equal(existsSync(path.join(dir, first.id)), false, '快照没了 + 反悔副本也过期 ⇒ 不留空壳');
600
600
  });
601
601
 
602
+ /* ---------------- BK-06:来源档案(originProfile)标注 ----------------
603
+ * 插件数据目录 $DSH_HOME/dsh-config-manager 被**所有** DSH profile 共用,快照库因此混着别的档案拍的条目;
604
+ * 不标注来源用户就分不出哪条来自哪个档案。三条硬边界:必须可选、只在能证明时写、绝不写占位值。 */
605
+
606
+ test('BK-06/①:createSnapshot 记下拍快照的档案名(ctx.profile 有值 ⇒ 写入 originProfile)', async () => {
607
+ const store = new MemSnapshotStore();
608
+
609
+ const ctx = makeContext('win32', 'C:/home/.dsh', 'web');
610
+ await seedHostFiles(ctx);
611
+ const snap = await createSnapshot({ ctx, plan: emptyPlan(), sourceZip: 'unit.zip', store, adapters: [] });
612
+ assert.equal(snap.originProfile, 'web', '档案名要随快照落盘:不标注就分不出来源');
613
+ assert.equal(store.snapshots.get(snap.id)?.originProfile, 'web', 'store 落库的对象也要带该字段(不只是返回值)');
614
+
615
+ // 首尾空白按 trim 归一(宿主偶尔带空格;档案身份本身不含首尾空白)
616
+ const padded = makeContext('win32', 'C:/home/.dsh', ' Test1 ');
617
+ await seedHostFiles(padded);
618
+ const snap2 = await createSnapshot({ ctx: padded, plan: emptyPlan(), sourceZip: 'unit.zip', store, adapters: [] });
619
+ assert.equal(snap2.originProfile, 'Test1');
620
+ });
621
+
622
+ test('BK-06/②:来源档案取不到或不可信 ⇒ 不写 originProfile(绝不写 unknown 占位)', async () => {
623
+ const store = new MemSnapshotStore();
624
+ const profiles: Array<string | undefined> = [undefined, '', ' ', 'unknown', 'web/extra', '..', 'node_modules'];
625
+
626
+ for (const profile of profiles) {
627
+ const ctx = makeContext('win32', 'C:/home/.dsh', profile);
628
+ await seedHostFiles(ctx);
629
+ const snap = await createSnapshot({ ctx, plan: emptyPlan(), sourceZip: 'unit.zip', store, adapters: [] });
630
+ assert.equal(
631
+ 'originProfile' in snap, false,
632
+ `profile=${JSON.stringify(profile)} 时该字段必须**整个缺席**(写 'unknown' 会把「不知道」伪装成「确知」)`,
633
+ );
634
+ }
635
+ });
636
+
637
+ test('BK-06/③:normalizeOriginProfile 只放行真实档案名', () => {
638
+ assert.equal(normalizeOriginProfile('web'), 'web');
639
+ assert.equal(normalizeOriginProfile(' Test1 '), 'Test1');
640
+ assert.equal(normalizeOriginProfile('desktop'), 'desktop');
641
+ for (const bad of [undefined, null, 42, {}, [], '', ' ', 'unknown', 'a/b', 'a\\b', '.', '..', 'node_modules']) {
642
+ assert.equal(normalizeOriginProfile(bad), undefined, `${JSON.stringify(bad)} 不是可证明的档案名`);
643
+ }
644
+ });
645
+
@@ -274,6 +274,25 @@ export function normalizeDshVersion(value: unknown): string | undefined {
274
274
  return trimmed;
275
275
  }
276
276
 
277
+ /**
278
+ * 归一「快照来源档案」(originProfile)。
279
+ *
280
+ * 与 `normalizeDshVersion` 同一口径(非空、非 'unknown' 占位),但判据多一层:档案名要拿去和
281
+ * 当前档案比对、要在界面上按档案分组,所以还得是**合法档案名形态**。形态判据与
282
+ * `core/plugin-cli.ts` 的 `validateProfileName` 同源(拒绝路径分隔符与 '.'/'..'/'node_modules'),
283
+ * 差别只在失败处理:那边是拼 `profiles/<name>` 路径,非法必须抛错;这里只是标注**只过滤不抛错** ——
284
+ * 一个可疑档案名不该让快照落盘失败。
285
+ * 归一不到 → undefined(快照不写该字段,界面按「未标注」处理,绝不写 'unknown' 占位)。
286
+ */
287
+ export function normalizeOriginProfile(value: unknown): string | undefined {
288
+ if (typeof value !== 'string') return undefined;
289
+ const trimmed = value.trim();
290
+ if (trimmed === '' || trimmed === 'unknown') return undefined;
291
+ if (trimmed.includes('/') || trimmed.includes('\\')) return undefined;
292
+ if (trimmed === '.' || trimmed === '..' || trimmed === 'node_modules') return undefined;
293
+ return trimmed;
294
+ }
295
+
277
296
  export interface CreateSnapshotOptions {
278
297
  ctx: HostContext;
279
298
  plan: ImportPlan;
@@ -513,6 +532,10 @@ export async function createSnapshot(opts: CreateSnapshotOptions): Promise<Snaps
513
532
  ctx.log.warn(`快照登记插件清单失败: ${err instanceof Error ? err.message : String(err)}`);
514
533
  }
515
534
 
535
+ // 来源档案(originProfile):$DSH_HOME/dsh-config-manager 被所有 profile 共用,标出来源才分得清;
536
+ // 归一到「能证明的真实档案名」,取不到则不写该字段(绝不写 'unknown' 占位)。
537
+ const originProfile = normalizeOriginProfile(ctx.profile);
538
+
516
539
  const snapshot: Snapshot = {
517
540
  id: crypto.randomUUID(),
518
541
  createdAt: new Date().toISOString(),
@@ -523,6 +546,8 @@ export async function createSnapshot(opts: CreateSnapshotOptions): Promise<Snaps
523
546
  hostFileBackups,
524
547
  // F-4:拍快照时的本机 DSH 版本(归一到「能证明的真实版本」;解析不到则不写该字段)。
525
548
  dshVersion: normalizeDshVersion(ctx.dshVersion),
549
+ // 来源档案(同上:解析不到则不写该字段)。
550
+ ...(originProfile !== undefined ? { originProfile } : {}),
526
551
  // Phase 4:operation-bound binding(journal ↔ snapshot 双向一致)
527
552
  ...(opts.operationId !== undefined ? { operationId: opts.operationId } : {}),
528
553
  ...(opts.operationType !== undefined ? { operationType: opts.operationType } : {}),
@@ -382,6 +382,8 @@ test('GET /disk-usage:HTTP 报告如实包含回滚点库与遗留数据(两
382
382
  tmpDir: f.dirs.tmpDir,
383
383
  marketDir: path.join(f.root, 'market'),
384
384
  syncDir: f.dirs.syncDir,
385
+ // 体检看整棵 sync/(含 sync-profiles/<p>/):本用例的 fixture 两者同根
386
+ syncRootDir: f.dirs.syncDir,
385
387
  // 与生产同语义的「直通」包壳(本组 handler 只用它包裹写路由)
386
388
  withMutationGate: (_op: string, handler: unknown) => handler,
387
389
  };
@@ -5,16 +5,18 @@
5
5
  * ① 启动时回收「结构性可证」的 stale 残留锁(owner 确证死亡 / PID 复用),并把交给 SAFE MODE 判定的
6
6
  * 锁状态按回收结果修正;
7
7
  * ② 启动时清掉孤儿心跳 sidecar(已不是持有者、心跳也早已停更的垃圾);
8
- * ③ 进程退出时**同步**释放本实例持有的锁('exit' 里不能 await,所以必须同步 fs)。
8
+ * ③ 进程退出时**同步**释放本实例持有的锁('exit' 里不能 await,所以必须同步 fs);
9
+ * ④ 装配宿主用的 manager 实例,并把「心跳写失败 / 释放失败」接到日志(以前全静默)。
9
10
  *
10
11
  * 为什么只在分类 NORMAL 时做 ①②:RECOVERY_REQUIRED / NEEDS_ATTENTION 意味着有未决事务,此时删掉
11
12
  * ownership 等于替用户抹掉事故现场(journal↔ownership binding 也会失去对照证据)——那类必须显式恢复。
12
13
  * 为什么不碰 corrupt 残留与「心跳长过期」启发式:`reclaimProvableStaleLock` 只认结构性可证;
13
14
  * 其余留给显式回收(`--recover-stale-lock` / GUI 事故恢复),否则在拿不到 OS identity 的机器上会误删活锁。
14
15
  *
15
- * 真机成因与量化数据 → `docs/lessons/recovery-console.md`;规则 → `AGENTS.md`「备份 / 恢复 / 回滚点」。
16
+ * 真机成因与量化数据 → `docs/evidence/recovery-console.md`;规则 → `AGENTS.md`「备份 / 恢复 / 回滚点」。
16
17
  */
17
- import type { EnvironmentLockManager, LockState } from '../utils/env-lock.ts'
18
+ import { EnvironmentLockManager } from '../utils/env-lock.ts'
19
+ import type { LockState } from '../utils/env-lock.ts'
18
20
  import { mapLockStateForStartup } from './phase3-host.ts'
19
21
  import { utilsMsg } from '../utils/messages-utils.ts'
20
22
 
@@ -62,6 +64,34 @@ export async function reclaimStaleLockAtStartup(input: {
62
64
  return lockState
63
65
  }
64
66
 
67
+ /**
68
+ * 建宿主用的 mutation lock 实例,并给两类**以前全静默**的失败接上日志:
69
+ * 心跳写失败落到 noop、释放失败被调用方 `release().catch(() => {})` 吞掉 ——
70
+ * 真机表现就是「锁留在盘上、没有任何人知道为什么」,直到所有 destructive 操作恒被 423 挡住
71
+ * (2026-11-07 档案删除卡在「另一个任务正在运行」即此形状)。
72
+ * 这里只留痕,不做恢复动作:恢复一律走显式入口(事故恢复 / CLI),与 ①② 同一口径。
73
+ */
74
+ export function createHostMutationLock(input: {
75
+ dataDir: string
76
+ lockVersion: string
77
+ log: Pick<LockLifecycleLog, 'warn'>
78
+ }): EnvironmentLockManager {
79
+ const reason = (error: unknown): string => (error instanceof Error ? error.message : String(error))
80
+ return new EnvironmentLockManager({
81
+ dataDir: input.dataDir,
82
+ op: 'config-manager',
83
+ target: 'global-mutation',
84
+ lockVersion: input.lockVersion,
85
+ onHeartbeatWriteFailure: (err) => input.log.warn(utilsMsg('utils.envLock.heartbeatWriteFailed', { reason: reason(err) })),
86
+ onReleaseFailure: ({ err, quarantined }) =>
87
+ input.log.warn(
88
+ quarantined
89
+ ? utilsMsg('utils.envLock.releaseFailedQuarantined', { reason: reason(err) })
90
+ : utilsMsg('utils.envLock.releaseFailedStuck', { reason: reason(err) }),
91
+ ),
92
+ })
93
+ }
94
+
65
95
  /**
66
96
  * 生成退出释放钩子:只删**本实例 instanceId** 的 ownership 与心跳(与 `release()` 同一不变量),永不抛。
67
97
  * 调用方负责 `process.once('exit', fn)` 与 dispose 时摘钩。