dsh-config-manager 0.4.2 → 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 (263) hide show
  1. package/README.md +24 -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 +19 -41
  13. package/lib/client.js +863 -722
  14. package/lib/core/access-mode.d.ts +25 -0
  15. package/lib/core/access-mode.js +28 -0
  16. package/lib/core/backup.d.ts +11 -0
  17. package/lib/core/backup.js +27 -0
  18. package/lib/core/env-lock-lifecycle.d.ts +17 -3
  19. package/lib/core/env-lock-lifecycle.js +38 -0
  20. package/lib/core/external-failure.d.ts +9 -0
  21. package/lib/core/external-failure.js +50 -0
  22. package/lib/core/local-plugin-host.d.ts +9 -7
  23. package/lib/core/local-plugin-host.js +109 -15
  24. package/lib/core/local-plugin-pack.d.ts +20 -0
  25. package/lib/core/local-plugin-pack.js +18 -3
  26. package/lib/core/mcp-connector-store.d.ts +13 -0
  27. package/lib/core/mcp-connector-store.js +16 -1
  28. package/lib/core/messages-core.d.ts +45 -0
  29. package/lib/core/messages-core.js +92 -0
  30. package/lib/core/messages.d.ts +1 -0
  31. package/lib/core/messages.js +6 -0
  32. package/lib/core/model-tool-plans.d.ts +66 -0
  33. package/lib/core/model-tool-plans.js +128 -0
  34. package/lib/core/model-tools.d.ts +96 -8
  35. package/lib/core/model-tools.js +568 -31
  36. package/lib/core/phase3-host.js +10 -2
  37. package/lib/core/plugin-data-registry.d.ts +1 -1
  38. package/lib/core/plugin-data-registry.js +1 -1
  39. package/lib/core/restore-plan-fingerprint.d.ts +2 -0
  40. package/lib/core/restore-plan-fingerprint.js +18 -0
  41. package/lib/core/restore-resume.d.ts +1 -1
  42. package/lib/core/restore-resume.js +1 -1
  43. package/lib/core/restore.d.ts +5 -0
  44. package/lib/core/restore.js +4 -1
  45. package/lib/core/types.d.ts +12 -0
  46. package/lib/foreign/claude-sessions.d.ts +1 -1
  47. package/lib/foreign/claude-sessions.js +1 -1
  48. package/lib/foreign/registry.js +1 -1
  49. package/lib/foreign/types.d.ts +1 -1
  50. package/lib/index.d.ts +15 -15
  51. package/lib/index.js +65 -72
  52. package/lib/market/git-file-writer.js +1 -1
  53. package/lib/market/github-repos.js +1 -1
  54. package/lib/market/market-config.js +1 -1
  55. package/lib/market/messages-market.js +1 -1
  56. package/lib/market/my-repo.js +1 -1
  57. package/lib/market/prepare.js +1 -1
  58. package/lib/market/reader.js +2 -2
  59. package/lib/market/repo-url.d.ts +1 -1
  60. package/lib/market/security.js +2 -2
  61. package/lib/market/star-cache.d.ts +1 -1
  62. package/lib/market/types.d.ts +1 -1
  63. package/lib/market/types.js +1 -1
  64. package/lib/market/url.js +1 -1
  65. package/lib/routes/backup.js +17 -9
  66. package/lib/routes/index.d.ts +1 -1
  67. package/lib/routes/kit.d.ts +42 -3
  68. package/lib/routes/kit.js +43 -3
  69. package/lib/routes/market.d.ts +1 -1
  70. package/lib/routes/market.js +3 -60
  71. package/lib/routes/model-tools-deps.d.ts +41 -0
  72. package/lib/routes/model-tools-deps.js +18 -0
  73. package/lib/routes/recovery.js +5 -3
  74. package/lib/routes/request-trust.d.ts +28 -0
  75. package/lib/routes/request-trust.js +65 -0
  76. package/lib/routes/route-support.d.ts +18 -26
  77. package/lib/routes/route-support.js +19 -32
  78. package/lib/routes/snapshots.d.ts +1 -1
  79. package/lib/routes/snapshots.js +4 -40
  80. package/lib/routes/sync.js +40 -28
  81. package/lib/schema/index.d.ts +2 -2
  82. package/lib/schema/index.js +2 -2
  83. package/lib/schema/section-registry.d.ts +5 -3
  84. package/lib/schema/section-registry.js +7 -3
  85. package/lib/security/secret-scanner.js +1 -1
  86. package/lib/sync/apply-bundle.d.ts +50 -0
  87. package/lib/sync/apply-bundle.js +60 -0
  88. package/lib/sync/autosync-scheduler.d.ts +9 -0
  89. package/lib/sync/autosync-scheduler.js +118 -89
  90. package/lib/sync/backup-scheduler.js +5 -4
  91. package/lib/sync/blob-store.d.ts +2 -2
  92. package/lib/sync/git/git-transport.d.ts +12 -0
  93. package/lib/sync/git/git-transport.js +50 -2
  94. package/lib/sync/merge.d.ts +2 -0
  95. package/lib/sync/merge.js +28 -0
  96. package/lib/sync/messages.d.ts +4 -0
  97. package/lib/sync/messages.js +9 -2
  98. package/lib/sync/s3/s3-transport.d.ts +1 -1
  99. package/lib/sync/s3/s3-transport.js +1 -1
  100. package/lib/sync/sync-engine.d.ts +4 -4
  101. package/lib/sync/sync-engine.js +25 -26
  102. package/lib/sync/sync-scope-boot.d.ts +34 -0
  103. package/lib/sync/sync-scope-boot.js +71 -0
  104. package/lib/sync/sync-scope.d.ts +103 -0
  105. package/lib/sync/sync-scope.js +229 -0
  106. package/lib/sync/sync-selection.d.ts +17 -4
  107. package/lib/sync/sync-selection.js +40 -14
  108. package/lib/sync/transport.d.ts +4 -1
  109. package/lib/sync/transport.js +6 -0
  110. package/lib/sync/webdav/webdav-transport.js +1 -1
  111. package/lib/sync/workspace-merge.d.ts +36 -0
  112. package/lib/sync/workspace-merge.js +152 -0
  113. package/lib/ui/backup-schedule.d.ts +13 -2
  114. package/lib/ui/backup-schedule.js +3 -0
  115. package/lib/ui/snapshots-view.d.ts +16 -0
  116. package/lib/ui/snapshots-view.js +21 -0
  117. package/lib/utils/env-lock.d.ts +96 -0
  118. package/lib/utils/env-lock.js +332 -111
  119. package/lib/utils/messages-utils.d.ts +6 -0
  120. package/lib/utils/messages-utils.js +17 -1
  121. package/lib/utils/patch-yaml.js +1 -1
  122. package/lib/utils/zip.js +1 -1
  123. package/package.json +3 -2
  124. package/src/adapters/mcp.test.ts +28 -0
  125. package/src/adapters/mcp.ts +33 -0
  126. package/src/adapters/plugins.test.ts +49 -0
  127. package/src/adapters/plugins.ts +9 -1
  128. package/src/adapters/pnpm-workspace.ts +1 -1
  129. package/src/adapters/self.test.ts +39 -1
  130. package/src/adapters/self.ts +20 -2
  131. package/src/adapters/workspaces.ts +1 -1
  132. package/src/cli/restore-resume.ts +1 -1
  133. package/src/cli/web/page.ts +2 -2
  134. package/src/client/about/AboutPanel.tsx +8 -1
  135. package/src/client/about/about-view.test.ts +1 -1
  136. package/src/client/about/about-view.ts +1 -1
  137. package/src/client/api.ts +1 -6
  138. package/src/client/chat/chat-entry-view.test.ts +1 -1
  139. package/src/client/chat/chat-slots.ts +1 -1
  140. package/src/client/chat/rollback-diff-tab.ts +1 -1
  141. package/src/client/client-types.ts +1 -1
  142. package/src/client/common/access-mode.ts +21 -0
  143. package/src/client/common/routes.ts +1 -5
  144. package/src/client/css-scale-guard.test.ts +1 -1
  145. package/src/client/home/HomePanel.tsx +34 -6
  146. package/src/client/library/ArtifactRow.tsx +14 -2
  147. package/src/client/library/LibraryPanel.tsx +44 -0
  148. package/src/client/locales/about.ts +6 -0
  149. package/src/client/locales/overview.ts +18 -2
  150. package/src/client/locales/sessions.ts +3 -0
  151. package/src/client/market/MyConfigsView.tsx +1 -1
  152. package/src/client/market/market-api.ts +2 -14
  153. package/src/client/market/market-locales.ts +1 -1
  154. package/src/client/market/market-view.ts +3 -3
  155. package/src/client/market/my-configs-api.ts +1 -1
  156. package/src/client/market/my-configs-view.ts +1 -1
  157. package/src/client/recovery/recovery-locales.test.ts +1 -1
  158. package/src/client/run-store.ts +1 -1
  159. package/src/client/sync/SyncSectionPickerDialog.tsx +0 -5
  160. package/src/client/sync/history-model.test.ts +28 -7
  161. package/src/client/sync/history-model.ts +6 -3
  162. package/src/client/sync/sync-locales.ts +10 -4
  163. package/src/client/sync/sync-view.ts +1 -1
  164. package/src/core/access-mode.ts +37 -0
  165. package/src/core/analyzer-cache.test.ts +1 -1
  166. package/src/core/backup.test.ts +45 -1
  167. package/src/core/backup.ts +25 -0
  168. package/src/core/disk-usage.test.ts +2 -0
  169. package/src/core/env-lock-lifecycle.ts +33 -3
  170. package/src/core/external-failure.test.ts +60 -0
  171. package/src/core/external-failure.ts +54 -0
  172. package/src/core/integrity-extra-entries.test.ts +1 -1
  173. package/src/core/local-plugin-host.test.ts +134 -0
  174. package/src/core/local-plugin-host.ts +122 -17
  175. package/src/core/local-plugin-pack.ts +39 -3
  176. package/src/core/mcp-connector-store.ts +26 -1
  177. package/src/core/messages-core.ts +94 -0
  178. package/src/core/messages.ts +6 -0
  179. package/src/core/model-tool-plans.test.ts +111 -0
  180. package/src/core/model-tool-plans.ts +170 -0
  181. package/src/core/model-tools.test.ts +212 -12
  182. package/src/core/model-tools.ts +710 -38
  183. package/src/core/phase3-host.ts +10 -2
  184. package/src/core/phase3-production-integration.test.ts +43 -0
  185. package/src/core/plugin-data-registry.ts +1 -1
  186. package/src/core/restore-plan-fingerprint.ts +19 -0
  187. package/src/core/restore-resume.ts +1 -1
  188. package/src/core/restore.ts +9 -1
  189. package/src/core/types.ts +12 -0
  190. package/src/foreign/claude-sessions.ts +3 -3
  191. package/src/foreign/registry.ts +1 -1
  192. package/src/foreign/types.ts +1 -1
  193. package/src/index.ts +96 -103
  194. package/src/market/git-file-writer.ts +1 -1
  195. package/src/market/github-repos.test.ts +1 -1
  196. package/src/market/github-repos.ts +1 -1
  197. package/src/market/market-config.ts +1 -1
  198. package/src/market/messages-market.ts +1 -1
  199. package/src/market/my-repo.test.ts +1 -1
  200. package/src/market/my-repo.ts +1 -1
  201. package/src/market/prepare.test.ts +1 -1
  202. package/src/market/prepare.ts +1 -1
  203. package/src/market/reader.ts +2 -2
  204. package/src/market/repo-url.ts +1 -1
  205. package/src/market/security.ts +2 -2
  206. package/src/market/star-cache.ts +1 -1
  207. package/src/market/types.ts +1 -1
  208. package/src/market/url.test.ts +1 -1
  209. package/src/market/url.ts +1 -1
  210. package/src/profiles/dsh-profile-copy-rollback.test.ts +1 -1
  211. package/src/routes/backup.ts +16 -9
  212. package/src/routes/index.ts +1 -1
  213. package/src/routes/kit.ts +71 -5
  214. package/src/routes/market.ts +2 -59
  215. package/src/routes/model-tools-deps.ts +56 -0
  216. package/src/routes/recovery.ts +5 -3
  217. package/src/routes/request-trust.ts +97 -0
  218. package/src/routes/route-support.ts +49 -36
  219. package/src/routes/snapshots.ts +4 -40
  220. package/src/routes/sync.ts +39 -27
  221. package/src/schema/index.ts +2 -2
  222. package/src/schema/manifest-schema.test.ts +2 -2
  223. package/src/schema/registry.test.ts +1 -1
  224. package/src/schema/section-registry.ts +9 -4
  225. package/src/security/redaction.test.ts +1 -1
  226. package/src/security/secret-scanner.test.ts +2 -2
  227. package/src/security/secret-scanner.ts +1 -1
  228. package/src/sync/apply-bundle.ts +104 -0
  229. package/src/sync/autosync-scheduler.test.ts +180 -6
  230. package/src/sync/autosync-scheduler.ts +132 -92
  231. package/src/sync/backup-scheduler.test.ts +11 -4
  232. package/src/sync/backup-scheduler.ts +5 -4
  233. package/src/sync/blob-store.ts +2 -2
  234. package/src/sync/git/git-transport.test.ts +62 -0
  235. package/src/sync/git/git-transport.ts +54 -3
  236. package/src/sync/merge.ts +29 -0
  237. package/src/sync/messages.ts +9 -2
  238. package/src/sync/s3/s3-transport.ts +1 -1
  239. package/src/sync/sync-engine.test.ts +238 -2
  240. package/src/sync/sync-engine.ts +25 -26
  241. package/src/sync/sync-preview-push.test.ts +2 -1
  242. package/src/sync/sync-scope-boot.ts +87 -0
  243. package/src/sync/sync-scope.test.ts +154 -0
  244. package/src/sync/sync-scope.ts +256 -0
  245. package/src/sync/sync-selection.test.ts +76 -2
  246. package/src/sync/sync-selection.ts +40 -13
  247. package/src/sync/transport.test.ts +21 -1
  248. package/src/sync/transport.ts +12 -0
  249. package/src/sync/webdav/webdav-delete-index-unreadable.test.ts +2 -2
  250. package/src/sync/webdav/webdav-transport.ts +1 -1
  251. package/src/sync/workspace-merge.test.ts +110 -0
  252. package/src/sync/workspace-merge.ts +180 -0
  253. package/src/ui/backup-schedule.test.ts +5 -0
  254. package/src/ui/backup-schedule.ts +21 -2
  255. package/src/ui/session-issue-labels.ts +1 -1
  256. package/src/ui/snapshots-view.test.ts +32 -0
  257. package/src/ui/snapshots-view.ts +34 -0
  258. package/src/utils/env-lock.test.ts +242 -9
  259. package/src/utils/env-lock.ts +247 -13
  260. package/src/utils/messages-utils.ts +17 -1
  261. package/src/utils/patch-yaml.ts +1 -1
  262. package/src/utils/zip.ts +1 -1
  263. package/src/client/CLIENT_DEPENDENCIES.md +0 -94
@@ -37,6 +37,7 @@ import { redact } from '../../security/redaction.ts'
37
37
  import { runStore } from '../run-store.ts'
38
38
  import type { ArtifactKind } from '../../ui/artifact-view.ts'
39
39
  import { toast } from '../common/toast-store.ts'
40
+ import { isAccessModeError } from '../common/access-mode.ts'
40
41
  import { toRecoveryView } from '../recovery/recovery-view.ts'
41
42
  import {
42
43
  buildOverviewMetrics,
@@ -61,12 +62,21 @@ const HOME_SYNC_TIMEOUT_MS = 30_000
61
62
  * 服务端按文件名尾部只读最近 N 个文件 —— 不再把 2360 条历史全量读出来返给首屏。 */
62
63
  const HOME_ACTIVITY_LIMIT = 100
63
64
 
65
+ /** 当前页面的来源地址(issue #126):访问方式被拒时必须让用户看到「你是从哪个地址打开的」。
66
+ * 非浏览器环境(SSR / 单测)没有 location,退回 'unknown' 而不是空串 —— 文案是拼句。 */
67
+ function pageOrigin(): string {
68
+ return typeof location === 'undefined' ? 'unknown' : location.origin
69
+ }
70
+
64
71
  /** issue #43:立即备份跳过原因 → 文案键(文案统一走 locale 字典;未知 token 走 other)。 */
65
72
  const BACKUP_SKIP_KEY: Record<BackupSkipReason, ConfigManagerKey> = {
66
73
  disabled: 'overview.quick.backupSkippedDisabled',
67
74
  running: 'overview.quick.backupSkippedRunning',
68
75
  conflict: 'overview.quick.backupSkippedConflict',
69
76
  locked: 'overview.quick.backupSkippedLocked',
77
+ 'lock-stale': 'overview.quick.backupSkippedLockStale',
78
+ 'lock-unavailable': 'overview.quick.backupSkippedLockUnavailable',
79
+ 'safe-mode': 'overview.quick.backupSkippedSafeMode',
70
80
  other: 'overview.quick.backupSkippedOther',
71
81
  }
72
82
 
@@ -161,7 +171,10 @@ export function HomePanel({ api, syncApi, historyApi, t, syncT, openForeignImpor
161
171
  * 为什么必须有它:此前 allSettled 把失败一律吞成 null,而健康判定对 null 不降级 ——
162
172
  * 宿主接口整体不可达时,用户看到的是绿色「配置健康」+「暂无操作记录」,
163
173
  * 读起来像「一切正常只是没操作过」,真实原因与重试入口都不可见。 */
164
- const [loadError, setLoadError] = useState<{ count: number; message: string } | null>(null)
174
+ /** accessMode:这轮失败里**至少一条**是「当前访问方式不受支持」(issue #126)——
175
+ * 围栏对全部路由同一口径,一条被访问面拒绝就说明整页都在围栏外;其余失败(超时/连带 500)
176
+ * 只是连带现象,此时横幅必须换成解释 + 下一步,绝不能再给一个点了也没用的「重试」。 */
177
+ const [loadError, setLoadError] = useState<{ count: number; message: string; accessMode: boolean } | null>(null)
165
178
  const [backupRunning, setBackupRunning] = useState(false)
166
179
  /** 卸载后不再 setState(异步回调竞态防护) */
167
180
  const aliveRef = useRef(true)
@@ -175,6 +188,7 @@ export function HomePanel({ api, syncApi, historyApi, t, syncT, openForeignImpor
175
188
  setLoadError(list.length === 0 ? null : {
176
189
  count: list.length,
177
190
  message: first instanceof Error ? first.message : String(first),
191
+ accessMode: list.some(isAccessModeError),
178
192
  })
179
193
  }, [])
180
194
 
@@ -389,11 +403,25 @@ export function HomePanel({ api, syncApi, historyApi, t, syncT, openForeignImpor
389
403
  {/* 0. 读取失败横幅:必须排在状态条之前 —— 数据没拿到时,绿色健康点是假的。
390
404
  重试复用同一条 load()(不新增刷新路径)。 */}
391
405
  {loadError !== null && (
392
- <Banner kind="error">
393
- {t('overview.loadFailed', { count: String(loadError.count), message: redact(loadError.message) })}
394
- {' '}
395
- <Button size="sm" loading={loading} onClick={() => { void load() }}>{t('common.retry')}</Button>
396
- </Banner>
406
+ loadError.accessMode
407
+ /* issue #126:访问方式问题不是读取失败 —— 说清「为什么」与「怎么改」,且不给重试
408
+ (同一个地址重试必然再被拒;换隧道或换 --host 启动都要整页重开)。 */
409
+ ? (
410
+ <Banner kind="warn">
411
+ {t('overview.accessMode.title')}
412
+ {' '}
413
+ {t('overview.accessMode.origin', { origin: pageOrigin() })}
414
+ {' '}
415
+ {t('overview.accessMode.hint')}
416
+ </Banner>
417
+ )
418
+ : (
419
+ <Banner kind="error">
420
+ {t('overview.loadFailed', { count: String(loadError.count), message: redact(loadError.message) })}
421
+ {' '}
422
+ <Button size="sm" loading={loading} onClick={() => { void load() }}>{t('common.retry')}</Button>
423
+ </Banner>
424
+ )
397
425
  )}
398
426
  {/* 1. 状态条:健康点 + 指标段(可点击,名词在前) */}
399
427
  <div className={css.statStrip} data-tone={health.kind === 'ok' ? undefined : health.kind}>
@@ -67,10 +67,18 @@ export interface ArtifactRowViewProps {
67
67
  * (旧快照没有该字段,绝不显示空串或占位)。
68
68
  */
69
69
  deviceLabel?: string | undefined
70
+ /**
71
+ * 来源档案徽章(本机快照专用):这份快照是哪个 DSH profile 拍的。
72
+ *
73
+ * 只有 `SnapshotMeta.originProfile` 真的存在时调用方才给值 —— 缺省 undefined 表示**不渲染**
74
+ * (旧快照没有来源,绝不显示空档案名或「未标注」徽章)。`hint` 只在「与当前档案不同」时给,
75
+ * 徽章本体只写档案名,差异语不重复表达。
76
+ */
77
+ originBadge?: { label: string; hint?: string; kind: 'info' | 'warn' } | undefined
70
78
  }
71
79
 
72
80
  export function ArtifactRowView({
73
- row, t, uiT, formatTime, expanded, onToggle, onAction, pending = null, deviceLabel,
81
+ row, t, uiT, formatTime, expanded, onToggle, onAction, pending = null, deviceLabel, originBadge,
74
82
  }: ArtifactRowViewProps) {
75
83
  const detailId = useId()
76
84
  const primary = row.capabilities[0]
@@ -122,13 +130,17 @@ export function ArtifactRowView({
122
130
  </div>
123
131
  )}
124
132
  </div>
125
- {row.badges.length > 0 && (
133
+ {(row.badges.length > 0 || originBadge !== undefined) && (
126
134
  <div className={css.artifactBadges}>
127
135
  {row.badges.map((badge) => (
128
136
  <Badge key={badge} kind={BADGE_KIND[badge]} title={badge === 'encrypted' ? encryptedHint : undefined}>
129
137
  {uiT(ARTIFACT_BADGE_LABEL_KEY[badge])}
130
138
  </Badge>
131
139
  ))}
140
+ {/* 来源档案排在状态徽章之后:先读「这行现在是什么状态」,再读「它来自哪个档案」 */}
141
+ {originBadge !== undefined && (
142
+ <Badge kind={originBadge.kind} title={originBadge.hint}>{originBadge.label}</Badge>
143
+ )}
132
144
  </div>
133
145
  )}
134
146
  <div className={css.artifactActions} onClick={(event) => { event.stopPropagation() }}>
@@ -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>
@@ -49,6 +49,9 @@ export const zh = {
49
49
  'about.cli.title': 'CLI 救援工具',
50
50
  'about.cli.hint': 'GUI 运行在 DSH 内部——DSH 无法启动时,独立安装的 CLI(dsh-config-manager)是第一救援手段:列快照 / 离线恢复 / 一键重装 DSH,全程无需 DSH 运行。安装一次即可在任何机器上用:',
51
51
  'about.cli.docs': 'CLI 使用文档',
52
+ // issue #126:内嵌面板的访问边界(宿主 --host 局域网地址 / 反代会被围栏拒绝,不是数据坏了)
53
+ 'about.access.title': '访问范围',
54
+ 'about.access.hint': '本面板只接受两种来源:本机回环地址(127.0.0.1 / localhost),或宿主已信任的地址与已登录的 dsh web 会话。用 dsh web --host <局域网地址> 启动后从别的机器打开时,页面能加载但读不到本机数据——改用 ssh -L 3080:127.0.0.1:3080 隧道从 localhost 打开即可。CLI 与 agent 工具不受此限制。',
52
55
  } as const;
53
56
 
54
57
  export const en: Record<keyof typeof zh, string> = {
@@ -94,4 +97,7 @@ export const en: Record<keyof typeof zh, string> = {
94
97
  'about.cli.title': 'CLI Rescue Tool',
95
98
  'about.cli.hint': 'The GUI lives inside DSH — when DSH cannot start, the separately installed CLI (dsh-config-manager) is your first rescue tool: list snapshots / offline restore / one-click DSH reinstall, no DSH runtime needed. Install once and use it on any machine:',
96
99
  'about.cli.docs': 'CLI documentation',
100
+ // issue #126: the panel's access boundary (host --host LAN address / reverse proxy is fenced)
101
+ 'about.access.title': 'Access scope',
102
+ 'about.access.hint': 'This panel accepts only two sources: loopback on this machine (127.0.0.1 / localhost), or an address and signed-in dsh web session the host already trusts. Started with dsh web --host <LAN address> and opened from another machine, the page loads but cannot read local data — open it through an ssh -L 3080:127.0.0.1:3080 tunnel via localhost instead. The CLI and agent tools are not affected.',
97
103
  };
@@ -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': '最近活动',
@@ -50,6 +54,10 @@ export const zh = {
50
54
  'overview.activity.unavailable': '活动记录读取失败(这不是「没有记录」)',
51
55
  // 首屏 5 个只读请求有失败时如实说清(此前失败被吞成 null,页面仍显示绿色健康 + 空活动)
52
56
  'overview.loadFailed': '有 {count} 项数据读取失败:{message} —— 下面的指标可能不完整',
57
+ // issue #126:访问方式(宿主 --host 局域网地址 / 反代)不满足围栏时,说清原因与下一步,且不给重试
58
+ 'overview.accessMode.title': '当前访问方式不被允许读取本机数据。',
59
+ 'overview.accessMode.origin': '页面地址:{origin}。',
60
+ 'overview.accessMode.hint': '面板只接受本机回环访问,或宿主已信任的地址与已登录会话。改法:用 ssh -L 3080:127.0.0.1:3080 隧道后从 localhost 打开;或以 dsh web --host 127.0.0.1 启动后在本机访问;若本就在可信地址上,重新打开 dsh web 打印的访问链接(会话可能已过期)。',
53
61
  'overview.empty.title': '开始保护你的配置',
54
62
  'overview.empty.step1': '创建第一份备份',
55
63
  'overview.empty.step2': '导出 ZIP 带走',
@@ -108,7 +116,11 @@ export const en: Record<keyof typeof zh, string> = {
108
116
  'overview.quick.backupSkippedDisabled': 'Skipped: scheduled backups are disabled (no backup file was created)',
109
117
  'overview.quick.backupSkippedRunning': 'Skipped: a previous backup is still running',
110
118
  'overview.quick.backupSkippedConflict': 'Skipped: another task is running (duplicate guard)',
111
- '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',
112
124
  'overview.quick.backupSkippedOther': 'Skipped: the backup service cannot run right now (see host logs for details)',
113
125
  'overview.quick.backupFailed': 'Backup failed: {message}',
114
126
  'overview.activity.title': 'Recent activity',
@@ -120,6 +132,10 @@ export const en: Record<keyof typeof zh, string> = {
120
132
  'overview.activity.unavailable': 'The activity log could not be read (this is not \"no activity\")',
121
133
  // Say it plainly when some of the five read-only requests failed (failures used to be swallowed into null)
122
134
  'overview.loadFailed': '{count} data {count, plural, request|requests} failed: {message} — the metrics below may be incomplete',
135
+ // issue #126: the host's --host (LAN) address or a reverse proxy sits outside the fence
136
+ 'overview.accessMode.title': 'This page cannot read local data from its current address.',
137
+ 'overview.accessMode.origin': 'Page address: {origin}.',
138
+ 'overview.accessMode.hint': 'The panel only accepts loopback access, or an address and signed-in session the host already trusts. Fix: open it through an ssh -L 3080:127.0.0.1:3080 tunnel via localhost, or start dsh web --host 127.0.0.1 and open it on this machine; if you are already on a trusted address, reopen the access link dsh web printed (the session may have expired).',
123
139
  'overview.empty.title': 'Start protecting your configuration',
124
140
  'overview.empty.step1': 'Create a backup',
125
141
  'overview.empty.step2': 'Export the ZIP',
@@ -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)。
@@ -0,0 +1,37 @@
1
+ /**
2
+ * 围栏拒绝码(access-mode)—— 宿主路由与浏览器两半的**唯一字面量来源**。
3
+ *
4
+ * 为什么需要独立模块:issue #126 里局域网访问内嵌面板时,每条只读路由都回
5
+ * `{"error":"forbidden: loopback-only"}`,而界面只能把它当普通错误显示成
6
+ * 「有 5 项数据读取失败」+ 一个点了没用的「重试」—— 用户据此会以为数据坏了。
7
+ * 客户端要能认出「这是访问方式问题、不是数据问题」,就必须有一个**机器码**,
8
+ * 且这个码不能各写一份(宿主 kit 写一个、浏览器 api 写一个,早晚分叉)。
9
+ *
10
+ * 三档语义(与 src/routes/kit.ts 的围栏一一对应):
11
+ * - `loopback-only`:只接受本机回环(无宿主信任面可委托时的兜底 / 独立 CLI 救急台);
12
+ * - `untrusted-authority`:宿主拒绝了这次请求的 Host/Origin(不在 trustedHosts);
13
+ * - `browser-session`:地址可信但缺 dsh web 的登录会话 cookie(401)。
14
+ *
15
+ * 本模块零依赖、零 import(宿主与浏览器 bundle 都要能引)。
16
+ */
17
+
18
+ /** 只接受回环(无委托或委托不可用)。 */
19
+ export const LOOPBACK_ONLY_CODE = 'loopback-only' as const
20
+
21
+ /** 宿主不认这个 authority(Host 头不在 trustedHosts)。 */
22
+ export const UNTRUSTED_AUTHORITY_CODE = 'untrusted-authority' as const
23
+
24
+ /** 地址可信,但请求没有有效的 dsh web 登录会话。 */
25
+ export const BROWSER_SESSION_CODE = 'browser-session' as const
26
+
27
+ export type AccessModeCode =
28
+ | typeof LOOPBACK_ONLY_CODE
29
+ | typeof UNTRUSTED_AUTHORITY_CODE
30
+ | typeof BROWSER_SESSION_CODE
31
+
32
+ const ACCESS_MODE_CODES: readonly string[] = [LOOPBACK_ONLY_CODE, UNTRUSTED_AUTHORITY_CODE, BROWSER_SESSION_CODE]
33
+
34
+ /** 该 code 是否属于「访问方式」这一类拒绝(客户端据此换文案,而不是当成读取失败)。 */
35
+ export function isAccessModeCode(value: unknown): value is AccessModeCode {
36
+ return typeof value === 'string' && ACCESS_MODE_CODES.includes(value)
37
+ }
@@ -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 () => {