dsh-config-manager 0.4.3 → 0.6.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 (286) 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 +17 -41
  13. package/lib/client.js +946 -761
  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 +5 -0
  29. package/lib/core/messages.js +14 -0
  30. package/lib/core/migration-history.d.ts +40 -0
  31. package/lib/core/migration-history.js +55 -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-cli.d.ts +5 -0
  38. package/lib/core/plugin-cli.js +11 -3
  39. package/lib/core/plugin-data-registry.d.ts +1 -1
  40. package/lib/core/plugin-data-registry.js +1 -1
  41. package/lib/core/restore-plan-fingerprint.d.ts +2 -0
  42. package/lib/core/restore-plan-fingerprint.js +18 -0
  43. package/lib/core/restore-resume.d.ts +1 -1
  44. package/lib/core/restore-resume.js +1 -1
  45. package/lib/core/restore.d.ts +5 -0
  46. package/lib/core/restore.js +4 -1
  47. package/lib/core/types.d.ts +12 -0
  48. package/lib/foreign/claude-sessions.d.ts +1 -1
  49. package/lib/foreign/claude-sessions.js +1 -1
  50. package/lib/foreign/registry.js +1 -1
  51. package/lib/foreign/types.d.ts +1 -1
  52. package/lib/index.d.ts +19 -15
  53. package/lib/index.js +72 -80
  54. package/lib/market/git-file-writer.js +1 -1
  55. package/lib/market/github-repos.js +1 -1
  56. package/lib/market/market-config.js +1 -1
  57. package/lib/market/messages-market.js +1 -1
  58. package/lib/market/my-repo.js +1 -1
  59. package/lib/market/prepare.js +1 -1
  60. package/lib/market/reader.js +2 -2
  61. package/lib/market/repo-url.d.ts +1 -1
  62. package/lib/market/security.js +2 -2
  63. package/lib/market/star-cache.d.ts +1 -1
  64. package/lib/market/types.d.ts +1 -1
  65. package/lib/market/types.js +1 -1
  66. package/lib/market/url.js +1 -1
  67. package/lib/profiles/dsh-profile-manager.d.ts +1 -1
  68. package/lib/profiles/dsh-profile-manager.js +26 -7
  69. package/lib/profiles/dsh-profile-shared.d.ts +3 -1
  70. package/lib/routes/backup.js +17 -9
  71. package/lib/routes/index.d.ts +1 -1
  72. package/lib/routes/kit.d.ts +2 -2
  73. package/lib/routes/market.d.ts +1 -1
  74. package/lib/routes/market.js +3 -60
  75. package/lib/routes/model-tools-deps.d.ts +41 -0
  76. package/lib/routes/model-tools-deps.js +18 -0
  77. package/lib/routes/recovery.js +5 -3
  78. package/lib/routes/route-support.d.ts +18 -26
  79. package/lib/routes/route-support.js +19 -32
  80. package/lib/routes/snapshots.d.ts +1 -1
  81. package/lib/routes/snapshots.js +4 -40
  82. package/lib/routes/sync.js +40 -28
  83. package/lib/schema/index.d.ts +2 -2
  84. package/lib/schema/index.js +2 -2
  85. package/lib/schema/section-registry.d.ts +5 -3
  86. package/lib/schema/section-registry.js +7 -3
  87. package/lib/security/secret-scanner.js +1 -1
  88. package/lib/sync/apply-bundle.d.ts +50 -0
  89. package/lib/sync/apply-bundle.js +60 -0
  90. package/lib/sync/autosync-scheduler.d.ts +9 -0
  91. package/lib/sync/autosync-scheduler.js +118 -89
  92. package/lib/sync/backup-scheduler.js +5 -4
  93. package/lib/sync/blob-store.d.ts +2 -2
  94. package/lib/sync/git/git-transport.d.ts +12 -0
  95. package/lib/sync/git/git-transport.js +50 -2
  96. package/lib/sync/merge.d.ts +2 -0
  97. package/lib/sync/merge.js +28 -0
  98. package/lib/sync/messages.d.ts +4 -0
  99. package/lib/sync/messages.js +9 -2
  100. package/lib/sync/s3/s3-transport.d.ts +1 -1
  101. package/lib/sync/s3/s3-transport.js +1 -1
  102. package/lib/sync/sync-engine.d.ts +4 -4
  103. package/lib/sync/sync-engine.js +25 -26
  104. package/lib/sync/sync-scope-boot.d.ts +34 -0
  105. package/lib/sync/sync-scope-boot.js +71 -0
  106. package/lib/sync/sync-scope.d.ts +103 -0
  107. package/lib/sync/sync-scope.js +229 -0
  108. package/lib/sync/sync-selection.d.ts +17 -4
  109. package/lib/sync/sync-selection.js +40 -14
  110. package/lib/sync/transport.d.ts +4 -1
  111. package/lib/sync/transport.js +6 -0
  112. package/lib/sync/webdav/webdav-transport.js +1 -1
  113. package/lib/sync/workspace-merge.d.ts +36 -0
  114. package/lib/sync/workspace-merge.js +152 -0
  115. package/lib/ui/backup-schedule.d.ts +13 -2
  116. package/lib/ui/backup-schedule.js +3 -0
  117. package/lib/ui/snapshots-view.d.ts +16 -0
  118. package/lib/ui/snapshots-view.js +21 -0
  119. package/lib/ui/sync-repository-picker.d.ts +21 -0
  120. package/lib/ui/sync-repository-picker.js +18 -0
  121. package/lib/utils/env-lock.d.ts +96 -0
  122. package/lib/utils/env-lock.js +332 -111
  123. package/lib/utils/messages-utils.d.ts +6 -0
  124. package/lib/utils/messages-utils.js +17 -1
  125. package/lib/utils/patch-yaml.js +1 -1
  126. package/lib/utils/remove-tree.d.ts +7 -0
  127. package/lib/utils/remove-tree.js +265 -0
  128. package/lib/utils/zip.js +1 -1
  129. package/package.json +3 -2
  130. package/src/adapters/mcp.test.ts +28 -0
  131. package/src/adapters/mcp.ts +33 -0
  132. package/src/adapters/plugins.test.ts +49 -0
  133. package/src/adapters/plugins.ts +9 -1
  134. package/src/adapters/pnpm-workspace.ts +1 -1
  135. package/src/adapters/self.test.ts +39 -1
  136. package/src/adapters/self.ts +20 -2
  137. package/src/adapters/workspaces.ts +1 -1
  138. package/src/cli/restore-resume.ts +1 -1
  139. package/src/cli/web/page.ts +2 -2
  140. package/src/client/about/AboutPanel.tsx +1 -1
  141. package/src/client/about/about-view.test.ts +1 -1
  142. package/src/client/about/about-view.ts +1 -1
  143. package/src/client/api.ts +1 -6
  144. package/src/client/chat/chat-entry-view.test.ts +1 -1
  145. package/src/client/chat/chat-slots.ts +1 -1
  146. package/src/client/chat/rollback-diff-tab.ts +1 -1
  147. package/src/client/client-types.ts +1 -1
  148. package/src/client/common/routes.ts +1 -5
  149. package/src/client/config-manager.module.css +21 -1
  150. package/src/client/css-scale-guard.test.ts +1 -1
  151. package/src/client/environment/EnvironmentPanel.tsx +2 -2
  152. package/src/client/home/HomePanel.tsx +3 -0
  153. package/src/client/library/ArtifactRow.tsx +14 -2
  154. package/src/client/library/LibraryPanel.tsx +44 -0
  155. package/src/client/locales/overview.ts +10 -2
  156. package/src/client/locales/profiles.ts +2 -0
  157. package/src/client/locales/sessions.ts +3 -0
  158. package/src/client/market/MyConfigsView.tsx +1 -1
  159. package/src/client/market/market-api.ts +2 -14
  160. package/src/client/market/market-locales.ts +1 -1
  161. package/src/client/market/market-view.ts +3 -3
  162. package/src/client/market/my-configs-api.ts +1 -1
  163. package/src/client/market/my-configs-view.ts +1 -1
  164. package/src/client/recovery/recovery-locales.test.ts +1 -1
  165. package/src/client/run-store.ts +1 -1
  166. package/src/client/sync/ChannelConfigDialog.tsx +32 -1
  167. package/src/client/sync/SyncPanel.tsx +11 -30
  168. package/src/client/sync/SyncRepositoryPicker.tsx +34 -13
  169. package/src/client/sync/SyncSectionPickerDialog.tsx +0 -5
  170. package/src/client/sync/SyncSettingsView.test.ts +32 -0
  171. package/src/client/sync/config-save-state.test.ts +99 -0
  172. package/src/client/sync/config-save-state.ts +69 -0
  173. package/src/client/sync/history-model.test.ts +28 -7
  174. package/src/client/sync/history-model.ts +6 -3
  175. package/src/client/sync/sync-locales.ts +14 -4
  176. package/src/client/sync/sync-view.ts +1 -1
  177. package/src/core/analyzer-cache.test.ts +1 -1
  178. package/src/core/backup.test.ts +45 -1
  179. package/src/core/backup.ts +25 -0
  180. package/src/core/disk-usage.test.ts +2 -0
  181. package/src/core/engine-locale.test.ts +4 -0
  182. package/src/core/env-lock-lifecycle.ts +33 -3
  183. package/src/core/external-failure.test.ts +60 -0
  184. package/src/core/external-failure.ts +54 -0
  185. package/src/core/integrity-extra-entries.test.ts +1 -1
  186. package/src/core/local-plugin-host.test.ts +134 -0
  187. package/src/core/local-plugin-host.ts +122 -17
  188. package/src/core/local-plugin-pack.ts +39 -3
  189. package/src/core/mcp-connector-store.ts +26 -1
  190. package/src/core/messages-core.ts +94 -0
  191. package/src/core/messages.ts +14 -0
  192. package/src/core/migration-history.test.ts +65 -0
  193. package/src/core/migration-history.ts +70 -0
  194. package/src/core/model-tool-plans.test.ts +111 -0
  195. package/src/core/model-tool-plans.ts +170 -0
  196. package/src/core/model-tools.test.ts +212 -12
  197. package/src/core/model-tools.ts +710 -38
  198. package/src/core/phase3-host.ts +10 -2
  199. package/src/core/phase3-production-integration.test.ts +43 -0
  200. package/src/core/plugin-cli.fs.test.ts +30 -3
  201. package/src/core/plugin-cli.ts +11 -3
  202. package/src/core/plugin-data-registry.ts +1 -1
  203. package/src/core/restore-plan-fingerprint.ts +19 -0
  204. package/src/core/restore-resume.ts +1 -1
  205. package/src/core/restore.ts +9 -1
  206. package/src/core/types.ts +12 -0
  207. package/src/foreign/claude-sessions.ts +3 -3
  208. package/src/foreign/registry.ts +1 -1
  209. package/src/foreign/types.ts +1 -1
  210. package/src/index.ts +102 -111
  211. package/src/market/git-file-writer.ts +1 -1
  212. package/src/market/github-repos.test.ts +1 -1
  213. package/src/market/github-repos.ts +1 -1
  214. package/src/market/market-config.ts +1 -1
  215. package/src/market/messages-market.ts +1 -1
  216. package/src/market/my-repo.test.ts +1 -1
  217. package/src/market/my-repo.ts +1 -1
  218. package/src/market/prepare.test.ts +1 -1
  219. package/src/market/prepare.ts +1 -1
  220. package/src/market/reader.ts +2 -2
  221. package/src/market/repo-url.ts +1 -1
  222. package/src/market/security.ts +2 -2
  223. package/src/market/star-cache.ts +1 -1
  224. package/src/market/types.ts +1 -1
  225. package/src/market/url.test.ts +1 -1
  226. package/src/market/url.ts +1 -1
  227. package/src/profiles/dsh-profile-copy-rollback.test.ts +1 -1
  228. package/src/profiles/dsh-profile-manager.test.ts +20 -0
  229. package/src/profiles/dsh-profile-manager.ts +25 -7
  230. package/src/profiles/dsh-profile-shared.ts +2 -0
  231. package/src/routes/backup.ts +16 -9
  232. package/src/routes/index.ts +1 -1
  233. package/src/routes/kit.ts +2 -2
  234. package/src/routes/market.ts +2 -59
  235. package/src/routes/model-tools-deps.ts +56 -0
  236. package/src/routes/recovery.ts +5 -3
  237. package/src/routes/route-support.ts +49 -36
  238. package/src/routes/snapshots.ts +4 -40
  239. package/src/routes/sync.ts +39 -27
  240. package/src/schema/index.ts +2 -2
  241. package/src/schema/manifest-schema.test.ts +2 -2
  242. package/src/schema/registry.test.ts +1 -1
  243. package/src/schema/section-registry.ts +9 -4
  244. package/src/security/redaction.test.ts +1 -1
  245. package/src/security/secret-scanner.test.ts +2 -2
  246. package/src/security/secret-scanner.ts +1 -1
  247. package/src/sync/apply-bundle.ts +104 -0
  248. package/src/sync/autosync-scheduler.test.ts +180 -6
  249. package/src/sync/autosync-scheduler.ts +132 -92
  250. package/src/sync/backup-scheduler.test.ts +11 -4
  251. package/src/sync/backup-scheduler.ts +5 -4
  252. package/src/sync/blob-store.ts +2 -2
  253. package/src/sync/git/git-transport.test.ts +62 -0
  254. package/src/sync/git/git-transport.ts +54 -3
  255. package/src/sync/merge.ts +29 -0
  256. package/src/sync/messages.ts +9 -2
  257. package/src/sync/s3/s3-transport.ts +1 -1
  258. package/src/sync/sync-engine.test.ts +238 -2
  259. package/src/sync/sync-engine.ts +25 -26
  260. package/src/sync/sync-preview-push.test.ts +2 -1
  261. package/src/sync/sync-scope-boot.ts +87 -0
  262. package/src/sync/sync-scope.test.ts +154 -0
  263. package/src/sync/sync-scope.ts +256 -0
  264. package/src/sync/sync-selection.test.ts +76 -2
  265. package/src/sync/sync-selection.ts +40 -13
  266. package/src/sync/transport.test.ts +21 -1
  267. package/src/sync/transport.ts +12 -0
  268. package/src/sync/webdav/webdav-delete-index-unreadable.test.ts +2 -2
  269. package/src/sync/webdav/webdav-transport.ts +1 -1
  270. package/src/sync/workspace-merge.test.ts +110 -0
  271. package/src/sync/workspace-merge.ts +180 -0
  272. package/src/ui/backup-schedule.test.ts +5 -0
  273. package/src/ui/backup-schedule.ts +21 -2
  274. package/src/ui/session-issue-labels.ts +1 -1
  275. package/src/ui/snapshots-view.test.ts +32 -0
  276. package/src/ui/snapshots-view.ts +34 -0
  277. package/src/ui/sync-repository-picker.test.ts +34 -1
  278. package/src/ui/sync-repository-picker.ts +24 -0
  279. package/src/utils/env-lock.test.ts +242 -9
  280. package/src/utils/env-lock.ts +247 -13
  281. package/src/utils/messages-utils.ts +17 -1
  282. package/src/utils/patch-yaml.ts +1 -1
  283. package/src/utils/remove-tree.test.ts +120 -0
  284. package/src/utils/remove-tree.ts +239 -0
  285. package/src/utils/zip.ts +1 -1
  286. package/src/client/CLIENT_DEPENDENCIES.md +0 -94
@@ -4,6 +4,7 @@
4
4
  * 约定:只接收「渲染所需的数据 + 回调」;React 状态、副作用与网络调用仍由
5
5
  * SyncPanel 持有(单一状态源);可测纯逻辑在 src/ui/sync-settings-view.ts。
6
6
  */
7
+ import { useEffect, useRef, useState } from 'react'
7
8
  import type { ChangeEvent } from 'react'
8
9
  import type { TranslateNS } from '../client-types.ts'
9
10
  import type { UiT } from '../../ui/i18n.ts'
@@ -24,6 +25,12 @@ import { S3_PROVIDERS } from '../../ui/sync-settings-view.ts'
24
25
  import type { CloudFormIssue, SyncFormSnapshot } from '../../ui/sync-settings-view.ts'
25
26
  import css from '../config-manager.module.css'
26
27
 
28
+ /**
29
+ * 静默自动保存的「已保存」徽章在弹窗里停留多久(ms)。
30
+ * 入场 180ms 淡入(--cm-motion-base),2.4s 是「够看清、又不碍着继续输入」的停留长度。
31
+ */
32
+ const SAVED_TICK_MS = 2400
33
+
27
34
  /** 通道配置弹窗的表单字段补丁(onFormChange 入参:git/webdav + 云端点两组)。 */
28
35
  export type ChannelFormPatch = {
29
36
  repoUrl?: string
@@ -51,7 +58,7 @@ export type ChannelFormPatch = {
51
58
  * 拆出的职责单元只接收「渲染所需数据 + 回调」:`onFormChange` 由父组件实现为
52
59
  * 「patch 表单 + 防抖自动保存」—— 防抖定时器与卸载 flush 仍归父组件(单一状态源)。
53
60
  */
54
- export function ChannelConfigDialog({ open, onClose, api, t, uiT, form, cloudIssues, busy, savingConfig, remoteReady, statusInfo, githubSignedIn, githubView, onFormChange, onGithubStart, onGithubCancel, onSave }: {
61
+ export function ChannelConfigDialog({ open, onClose, api, t, uiT, form, cloudIssues, busy, savingConfig, remoteReady, statusInfo, githubSignedIn, saveTick, githubView, onFormChange, onGithubStart, onGithubCancel, onSave }: {
55
62
  open: boolean
56
63
  onClose: () => void
57
64
  api: SyncApi
@@ -70,6 +77,12 @@ export function ChannelConfigDialog({ open, onClose, api, t, uiT, form, cloudIss
70
77
  remoteReady: boolean
71
78
  statusInfo: SyncStatusResponse | null
72
79
  githubSignedIn: boolean | null
80
+ /**
81
+ * 静默自动保存的成功计数(父组件每次保存成功 +1)。
82
+ * 为什么用计数而不是布尔:连续改字段会连着保存多次,每次都要重新闪一次徽章;
83
+ * 布尔在「已经显示」的状态下无法区分第二次保存。
84
+ */
85
+ saveTick: number
73
86
  githubView: GithubLoginView
74
87
  onFormChange: (patch: ChannelFormPatch) => void
75
88
  onGithubStart: () => void
@@ -84,6 +97,21 @@ export function ChannelConfigDialog({ open, onClose, api, t, uiT, form, cloudIss
84
97
  } = form
85
98
  /** 密钥槽位引用名(与宿主 cloudSecretRef 同构;只用于提示文案,值从不经过前端) */
86
99
  const cloudSecretRef = cloudSecretRefName(channel)
100
+
101
+ /**
102
+ * 静默自动保存的可见回执(四通道共用):每来一个新的 saveTick 就闪一次「已保存」,SAVED_TICK_MS 后隐藏。
103
+ * 用 ref 记住已消费的 tick —— 弹窗关着时到达的 tick 不会在下次打开时误闪,窗口内重复保存只重置计时。
104
+ */
105
+ const [savedVisible, setSavedVisible] = useState(false)
106
+ // 初始值取挂载瞬间的 tick:弹窗关着时到达的保存不会在下次打开时误闪
107
+ const consumedTickRef = useRef(saveTick)
108
+ useEffect(() => {
109
+ if (saveTick <= 0 || saveTick === consumedTickRef.current) return
110
+ consumedTickRef.current = saveTick
111
+ setSavedVisible(true)
112
+ const timer = setTimeout(() => { setSavedVisible(false) }, SAVED_TICK_MS)
113
+ return () => { clearTimeout(timer) }
114
+ }, [saveTick])
87
115
  return (
88
116
  <Modal
89
117
  open={open}
@@ -117,6 +145,7 @@ export function ChannelConfigDialog({ open, onClose, api, t, uiT, form, cloudIss
117
145
  api={api}
118
146
  t={t}
119
147
  repoUrl={repoUrl}
148
+ signedIn={githubSignedIn}
120
149
  busy={busy}
121
150
  onPick={(cloneUrl) => { onFormChange({ repoUrl: cloneUrl }) }}
122
151
  />
@@ -450,6 +479,8 @@ export function ChannelConfigDialog({ open, onClose, api, t, uiT, form, cloudIss
450
479
  >
451
480
  {t('config.save')}
452
481
  </Button>
482
+ {/* 自动保存的可见回执:改动即存这件事此前完全静默,用户改完字段没有任何反馈 */}
483
+ {savedVisible && <span className={css.savedTick}><Badge kind="ok">{t('config.savedTick')}</Badge></span>}
453
484
  <InfoHint text={t('config.saveHint')} label={t('common.infoHint')} />
454
485
  </div>
455
486
  </Modal.Body>
@@ -61,6 +61,7 @@ import type {
61
61
  } from './sync-api.ts'
62
62
  import { resolveSmartSync } from './sync-entry.ts'
63
63
  import { reportPreviewFailure } from './preview-failure.ts'
64
+ import { savedConfigState } from './config-save-state.ts'
64
65
  import {
65
66
  channelMapOf, channelStateMap, computeGithubLoginView, computeSyncButtons, defaultChannelSyncState,
66
67
  githubPollMessage, isClientChannel, pushReportView, readStoredChannel,
@@ -320,6 +321,9 @@ export function SyncPanel({ api, t, cmT }: SyncPanelProps) {
320
321
  const mountedRef = useRef(true)
321
322
  /** 通道配置弹窗开关(瞬态 UI:切 tab/刷新不持久化,弹窗不自动重开;DESIGN.md §8.12 约定) */
322
323
  const [channelOpen, setChannelOpen] = useState(false)
324
+ /** 静默自动保存的成功计数(不进 SyncUiState 契约):>0 时弹窗内闪一次「已保存」徽章 ——
325
+ * 四通道共用的输入防抖自动保存此前成功后完全静默,用户无从判断存没存上。 */
326
+ const [saveTick, setSaveTick] = useState(0)
323
327
  /** 待确认断开的通道(null = 未打开确认弹窗)——用户要求:配置过的通道必须能删掉 */
324
328
  const [clearTarget, setClearTarget] = useState<SyncChannel | null>(null)
325
329
  /**
@@ -647,38 +651,12 @@ export function SyncPanel({ api, t, cmT }: SyncPanelProps) {
647
651
  // 基于 stateRef 计算(同步权威),经 commit 落库:即使保存完成时组件已卸载
648
652
  // (切走 tab),savingConfig 复位与凭据清空仍会镜像进 store,切回后一致
649
653
  const s = stateRef.current
650
- const next: SyncUiState = { ...s, savingConfig: false }
651
- // 只清空「本次已写入的」password/token:若保存期间用户已改输入则保留新值
652
- next.webdavPassword = s.webdavPassword !== '' && s.webdavPassword !== payloadToSave.password
653
- ? s.webdavPassword
654
- : ''
655
- next.token = s.token !== '' && s.token !== payloadToSave.token ? s.token : ''
656
- // 云端点密钥同一口径:只清「本次确实写出去的」那个;保存期间用户又改了输入则保留新值
657
- next.s3Secret = s.s3Secret !== '' && s.s3Secret !== payloadToSave.secret ? s.s3Secret : ''
658
- next.gistToken = s.gistToken !== '' && s.gistToken !== payloadToSave.secret ? s.gistToken : ''
659
- // 凭据徽章合并(响应只含布尔,无 secret 值)
660
- if (s.statusInfo !== null) {
661
- const info: SyncStatusResponse = {
662
- ...s.statusInfo,
663
- configured: true,
664
- credentialConfigured: saved.credentialConfigured,
665
- }
666
- if (saved.webdav !== undefined) {
667
- info.webdav = {
668
- url: s.statusInfo.webdav?.url,
669
- username: s.statusInfo.webdav?.username,
670
- usernameConfigured: saved.webdav.usernameConfigured,
671
- passwordConfigured: saved.webdav.passwordConfigured,
672
- }
673
- }
674
- // 云端点:响应只回非密视图 + secretStored 布尔(值永不回传),直接合并供徽章刷新
675
- if (saved.s3 !== undefined) info.s3 = saved.s3
676
- if (saved.gist !== undefined) info.gist = saved.gist
677
- next.statusInfo = info
678
- }
654
+ // 凭据清空 + 徽章合并的自包含演算下沉到 ./config-save-state.ts(本文件有行数棘轮)
655
+ const next: SyncUiState = { ...s, ...savedConfigState(s, saved, payloadToSave) }
679
656
  commit(next)
680
- // M-17:手动保存成功给出回执(自动保存静默,避免输入防抖刷屏)
657
+ // M-17:手动保存给出 toast 回执;自动保存不弹 toast(防抖会刷屏),改为计数 +1 → 弹窗内的「已保存」徽章
681
658
  if (announce) toast.ok(t('toast.configSaved'))
659
+ else setSaveTick((n) => n + 1)
682
660
  // 手动填入的 git token 保存成功 → 校验有效性(有效则隐藏 GitHub 登录块)。
683
661
  // 只有 git 通道用 SYNC_CREDENTIAL_REF:云端点通道的密钥走各自的槽位,与 GitHub 登录无关。
684
662
  if (payloadToSave.transport === 'git' && saved.credentialConfigured) {
@@ -809,6 +787,8 @@ export function SyncPanel({ api, t, cmT }: SyncPanelProps) {
809
787
  if (poll.status === 'success') {
810
788
  // token 已由宿主写入 DSH credentials:标记已登录(隐藏登录块)+ 刷新状态/凭据徽章
811
789
  patch({ githubSignedIn: true, github: { ...stateRef.current.github, phase: 'success', error: null } })
790
+ // 登录成功必须当场可见(用户反馈:成功后界面无任何提示,只能靠猜);文案复用 githubPollMessage 的 success 分支
791
+ toast.ok(message)
812
792
  void loadStatus()
813
793
  } else {
814
794
  patchGithub({ phase: 'error', error: message })
@@ -1411,6 +1391,7 @@ export function SyncPanel({ api, t, cmT }: SyncPanelProps) {
1411
1391
  remoteReady={remoteReady}
1412
1392
  statusInfo={state.statusInfo}
1413
1393
  githubSignedIn={state.githubSignedIn}
1394
+ saveTick={saveTick}
1414
1395
  githubView={githubView}
1415
1396
  onClose={closeChannelDialog}
1416
1397
  onFormChange={(p) => { patch(p); scheduleConfigSave() }}
@@ -15,7 +15,7 @@
15
15
  * - 失败**绝不静默,也绝不把拒绝抛出去**(调用点在 void 上下文里):错误同时进 toast 与内联红字
16
16
  * (toast 会被后续提示挤掉,内联红字留在原地),宿主下发的文本一律先过 `redact()` 再渲染。
17
17
  */
18
- import { useCallback, useEffect, useState } from 'react'
18
+ import { useCallback, useEffect, useRef, useState } from 'react'
19
19
  import type { ChangeEvent } from 'react'
20
20
 
21
21
  import type { TranslateNS } from '../client-types.ts'
@@ -27,7 +27,7 @@ import { toast } from '../common/toast-store.ts'
27
27
  import type { SyncApi } from './sync-api.ts'
28
28
  import {
29
29
  formatRepoUpdatedAt, repoCreateBody, repoNameError, repoPickerOptions, repoPickerRepos,
30
- repoPickerValueFor, REPO_PICKER_CREATE_VALUE, type RepoNameError, type RepoPickerRepo,
30
+ repoPickerValueFor, shouldAutoLoadRepos, REPO_PICKER_CREATE_VALUE, type RepoNameError, type RepoPickerRepo,
31
31
  } from '../../ui/sync-repository-picker.ts'
32
32
  import css from '../config-manager.module.css'
33
33
 
@@ -39,6 +39,11 @@ export interface SyncRepositoryPickerProps {
39
39
  t: TranslateNS<'config-manager-sync'>
40
40
  /** 表单里当前的仓库地址(用于回显「当前选中的是哪一个」) */
41
41
  repoUrl: string
42
+ /**
43
+ * GitHub 登录态(null = 未知)。登录成功那一刻由父组件变 true ⇒ 本组件**自动**拉列表,
44
+ * 用户不必再点开下拉才知道列表出来了(2026-11-08 用户反馈)。
45
+ */
46
+ signedIn: boolean | null
42
47
  /** 表单繁忙(保存中 / 同步中)时禁用选择与新建 */
43
48
  busy: boolean
44
49
  /** 选中仓库(或新建成功)后把地址交回父组件 */
@@ -46,7 +51,7 @@ export interface SyncRepositoryPickerProps {
46
51
  }
47
52
 
48
53
  /** 打开下拉时才拉列表(Select 的 onOpen)—— 弹窗一打开就请求会白跑一次网络。 */
49
- export function SyncRepositoryPicker({ open, api, t, repoUrl, busy, onPick }: SyncRepositoryPickerProps) {
54
+ export function SyncRepositoryPicker({ open, api, t, repoUrl, signedIn, busy, onPick }: SyncRepositoryPickerProps) {
50
55
  const [repos, setRepos] = useState<RepoPickerRepo[]>([])
51
56
  const [loading, setLoading] = useState(false)
52
57
  const [loaded, setLoaded] = useState(false)
@@ -58,20 +63,26 @@ export function SyncRepositoryPicker({ open, api, t, repoUrl, busy, onPick }: Sy
58
63
  const [nameError, setNameError] = useState<RepoNameError>(null)
59
64
  const [createError, setCreateError] = useState<string | null>(null)
60
65
 
61
- /** 拉取仓库列表。**绝不抛出**(调用点在 void 上下文里,抛出的拒绝会变成 unhandled rejection)。 */
62
- const load = useCallback(async (): Promise<void> => {
66
+ /** 拉取仓库列表。**绝不抛出**(调用点在 void 上下文里,抛出的拒绝会变成 unhandled rejection)。
67
+ * announce:手动点「刷新列表」为 true —— 列表就在眼前,但用户需要知道那一次点击真的跑了;
68
+ * 自动加载(打开弹窗 / 登录成功)保持静默,否则一进弹窗就弹一条没人要求的通知。
69
+ * 失败**始终**进 toast(内联红字会随滚动离开视野,密码/token 相关的 401 尤其要当刻可见)。 */
70
+ const load = useCallback(async (announce = false): Promise<void> => {
63
71
  setLoading(true)
64
72
  setLoadError(null)
65
73
  try {
66
74
  const res = await api.githubListRepositories()
67
75
  setRepos(res.repos)
68
76
  setLoaded(true)
77
+ if (announce) toast.ok(t('repoPicker.refreshed', { count: repoPickerRepos(res.repos).length }))
69
78
  } catch (err) {
70
- setLoadError(err instanceof Error ? err.message : String(err))
79
+ const detail = err instanceof Error ? err.message : String(err)
80
+ setLoadError(detail)
81
+ toast.error(t('repoPicker.loadFailed') + t('common.labelSeparator') + redact(detail))
71
82
  } finally {
72
83
  setLoading(false)
73
84
  }
74
- }, [api])
85
+ }, [api, t])
75
86
 
76
87
  // 关闭时收起新建表单(下次打开从「选择」开始,不留上一次的半截输入)
77
88
  useEffect(() => {
@@ -83,13 +94,23 @@ export function SyncRepositoryPicker({ open, api, t, repoUrl, busy, onPick }: Sy
83
94
  setCreateError(null)
84
95
  }, [open])
85
96
 
86
- // 表单里已经有地址(例如上次选过)→ 进弹窗就把列表拉出来,让用户直接看到「当前选中的是哪一个」;
87
- // 空地址则等 onOpen 惰性加载。失败过就不自动重试(避免每开一次弹窗打一次必然失败的请求)。
97
+ // 自动加载的三个触发(弹窗打开 / 登录成功瞬间 / 表单里已有地址)由 ui 层的 shouldAutoLoadRepos 判定:
98
+ // 父组件在轮询到 success 时把 signedIn 变 true,这里就会**自动**把列表拉出来 —— 用户不再需要
99
+ // 自己去点开下拉(2026-11-08 用户反馈:登录成功后界面没有任何提示,看不出到底成了没有)。
100
+ // 失败过不自动重试(避免每开一次弹窗打一次必然失败的请求),重试走「刷新列表」或登录态复位。
88
101
  useEffect(() => {
89
- if (!open || loaded || loading || loadError !== null) return
90
- if (repoUrl.trim() === '') return
102
+ if (!shouldAutoLoadRepos({ open, signedIn, loaded, loading, failed: loadError !== null, repoUrl })) return
91
103
  void load()
92
- }, [open, loaded, loading, loadError, repoUrl, load])
104
+ }, [open, signedIn, loaded, loading, loadError, repoUrl, load])
105
+
106
+ // 登录状态由「未登录/未知」变「已登录」→ 清掉上一次的失败态(多半是未登录时的 401),让上面那条
107
+ // effect 立刻重试一次;否则用户登录完仍旧只看到「加载失败,可重试」。
108
+ const prevSignedInRef = useRef(signedIn)
109
+ useEffect(() => {
110
+ const prev = prevSignedInRef.current
111
+ prevSignedInRef.current = signedIn
112
+ if (prev !== true && signedIn === true && loadError !== null) setLoadError(null)
113
+ }, [signedIn, loadError])
93
114
 
94
115
  const pick = (value: string): void => {
95
116
  if (value === REPO_PICKER_CREATE_VALUE) {
@@ -159,7 +180,7 @@ export function SyncRepositoryPicker({ open, api, t, repoUrl, busy, onPick }: Sy
159
180
  onOpen={() => { if (!loaded && !loading) void load() }}
160
181
  onChange={pick}
161
182
  />
162
- <Button size="sm" loading={loading} disabled={busy} onClick={() => { void load() }}>
183
+ <Button size="sm" loading={loading} disabled={busy} onClick={() => { void load(true) }}>
163
184
  {t('repoPicker.refresh')}
164
185
  </Button>
165
186
  </div>
@@ -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')} />
@@ -170,3 +170,35 @@ test('t42: 未新增硬编码颜色(DESIGN.md:颜色/阴影走 --dsw-* token
170
170
  assert.doesNotMatch(viewSource, /#[0-9a-fA-F]{3,8}\b/, '不得出现硬编码颜色值')
171
171
  assert.doesNotMatch(viewSource, /rgba?\(/, '不得出现硬编码 rgb/rgba 颜色')
172
172
  })
173
+
174
+ /* ------------------------------- 用户感知:登录回执 / 列表自动加载 / 自动保存回执 */
175
+
176
+ test('GitHub 登录成功必须立刻给出 toast(用户报告:成功后界面没有任何提示,只能靠猜)', () => {
177
+ // 成功分支原本只 patch 状态 + loadStatus:登录块在 githubSignedIn===true 时整块隐藏,
178
+ // 「成功」这件事在界面上完全消失,用户看不出到底成了没有。文案必须复用 githubPollMessage
179
+ // 的 success 分支(同一句话不在字典与 toast 里各写一遍)。
180
+ const start = viewSource.indexOf("if (poll.status === 'success')")
181
+ assert.ok(start > 0, 'success 分支必须存在')
182
+ const branch = viewSource.slice(start, start + 400)
183
+ assert.match(branch, /toast\.ok\(message\)/, '登录成功必须弹 toast(复用 githubPollMessage 的成功文案)')
184
+ })
185
+
186
+ test('仓库列表在登录成功那一刻自动加载,不必用户先点开下拉(2026-11-08 用户反馈)', () => {
187
+ // 判定收在 ui 纯逻辑里(可单测),组件只负责调用 —— 组件里不得再出现「地址为空就 return」这类内联规则。
188
+ const picker = readSource(fileURLToPath(new URL('./SyncRepositoryPicker.tsx', import.meta.url)))
189
+ assert.match(picker, /shouldAutoLoadRepos\(\{ open, signedIn, loaded, loading, failed: loadError !== null, repoUrl \}\)/, '自动加载必须经 ui/sync-repository-picker.ts 的 shouldAutoLoadRepos 判定')
190
+ assert.doesNotMatch(picker, /if \(repoUrl\.trim\(\) === ''\) return/, '旧的「地址为空就不加载」内联规则必须撤掉(登录成功也要能拉列表)')
191
+ assert.match(picker, /signedIn: boolean \| null/, '选择器必须接收登录态')
192
+ const dialog = readSource(fileURLToPath(new URL('./ChannelConfigDialog.tsx', import.meta.url)))
193
+ assert.match(dialog, /signedIn=\{githubSignedIn\}/, '弹窗必须把登录态传给仓库选择器(登录成功后翻 true ⇒ 自动加载)')
194
+ })
195
+
196
+ test('静默自动保存必须有可见回执(四通道共用:输入防抖保存此前成功后完全静默)', () => {
197
+ // 主文件:自动保存成功(announce=false)→ 计数 +1;弹窗据此闪一次「已保存」徽章。
198
+ assert.match(viewSource, /else setSaveTick\(\(n\) => n \+ 1\)/, '自动保存成功后必须递增 saveTick(不进 SyncUiState 契约)')
199
+ assert.match(viewSource, /<ChannelConfigDialog[\s\S]*?saveTick=\{saveTick\}/, 'saveTick 必须传给配置弹窗')
200
+ const dialog = readSource(fileURLToPath(new URL('./ChannelConfigDialog.tsx', import.meta.url)))
201
+ assert.match(dialog, /\{savedVisible && <span className=\{css\.savedTick\}>/, '弹窗必须渲染「已保存」回执')
202
+ assert.match(dialog, /t\('config\.savedTick'\)/, '回执文案必须走字典(i18n 禁硬编码)')
203
+ assert.match(dialog, /SAVED_TICK_MS = 2400/, '回执是瞬时提示(2.4s 后隐藏),不得常驻')
204
+ })
@@ -0,0 +1,99 @@
1
+ /**
2
+ * 「保存通道配置成功」的 state 演进(./config-save-state.ts)。
3
+ *
4
+ * 真机背景:四通道都有输入防抖自动保存,成功后此前完全静默;
5
+ * 而凭据清空与徽章合并原本内联在 SyncPanel,既挤占行数棘轮又不能单测。
6
+ * 这里钉住两条不可放宽的口径:
7
+ * ① 只清「本次确实写出去」的凭据(保存期间用户改过输入 → 保留新值);
8
+ * ② 响应只含布尔/非密视图,绝不把 secret 值写回 state。
9
+ */
10
+ import test from 'node:test';
11
+ import assert from 'node:assert/strict';
12
+
13
+ import { savedConfigState } from './config-save-state.ts';
14
+ import type { SavedConfigState } from './config-save-state.ts';
15
+ import type { SyncConfigSaveResponse, SyncStatusResponse } from './sync-api.ts';
16
+
17
+ const status = {
18
+ ok: true,
19
+ configured: false,
20
+ credentialConfigured: false,
21
+ credentialWritable: true,
22
+ sectionCount: 0,
23
+ } as SyncStatusResponse;
24
+
25
+ const base: SavedConfigState = {
26
+ savingConfig: true,
27
+ webdavPassword: '',
28
+ token: '',
29
+ s3Secret: '',
30
+ gistToken: '',
31
+ statusInfo: null,
32
+ };
33
+
34
+ function state(over: Partial<SavedConfigState> = {}): SavedConfigState {
35
+ return { ...base, ...over };
36
+ }
37
+
38
+ test('savingConfig 复位:无论成功与否,落库的 state 都不再处于保存中', () => {
39
+ const next = savedConfigState(state(), { ok: true, configured: true, transport: 'git', credentialConfigured: true }, {});
40
+ assert.equal(next.savingConfig, false);
41
+ });
42
+
43
+ test('git:token 等于本次发出的值 → 清空(已写入 credentials)', () => {
44
+ const next = savedConfigState(state({ token: 'ghp_sent' }), { ok: true, configured: true, transport: 'git', credentialConfigured: true }, { token: 'ghp_sent' });
45
+ assert.equal(next.token, '');
46
+ });
47
+
48
+ test('git:保存期间用户改了输入(token ≠ 发出的值)→ 保留用户新输入', () => {
49
+ const next = savedConfigState(state({ token: 'ghp_new' }), { ok: true, configured: true, transport: 'git', credentialConfigured: true }, { token: 'ghp_sent' });
50
+ assert.equal(next.token, 'ghp_new');
51
+ });
52
+
53
+ test('webdav:password 走同一口径;未发出的空值不会被当成「清空依据」', () => {
54
+ const cleared = savedConfigState(state({ webdavPassword: 'pw' }), { ok: true, configured: true, transport: 'webdav', credentialConfigured: false }, { password: 'pw' });
55
+ assert.equal(cleared.webdavPassword, '');
56
+ const kept = savedConfigState(state({ webdavPassword: 'pw-other' }), { ok: true, configured: true, transport: 'webdav', credentialConfigured: false }, { password: 'pw' });
57
+ assert.equal(kept.webdavPassword, 'pw-other');
58
+ });
59
+
60
+ test('s3 / gist:secret 槽位共用 → 各自按同一口径清空,互不影响别的通道', () => {
61
+ const next = savedConfigState(state({ s3Secret: 'sk', gistToken: 'gh' }), { ok: true, configured: true, transport: 's3', credentialConfigured: false }, { secret: 'sk' });
62
+ assert.equal(next.s3Secret, '', 's3 密钥已写入 → 清空');
63
+ assert.equal(next.gistToken, 'gh', 'gist token 不等于本次 secret → 保留');
64
+ });
65
+
66
+ test('statusInfo 为 null(还没拉到 /sync/status)→ 不做徽章合并,留待 loadStatus', () => {
67
+ const next = savedConfigState(state(), { ok: true, configured: true, transport: 'git', credentialConfigured: true }, {});
68
+ assert.equal(next.statusInfo, null);
69
+ });
70
+
71
+ test('徽章合并:configured / credentialConfigured 取响应;webdav 保留本机 url 与 username', () => {
72
+ const withWebdav = { ...status, webdav: { url: 'https://dav.example.com', username: 'me', usernameConfigured: true, passwordConfigured: false } } as SyncStatusResponse;
73
+ const saved: SyncConfigSaveResponse = {
74
+ ok: true,
75
+ configured: true,
76
+ transport: 'webdav',
77
+ credentialConfigured: false,
78
+ webdav: { usernameConfigured: true, passwordConfigured: true },
79
+ };
80
+ const next = savedConfigState(state({ statusInfo: withWebdav }), saved, {});
81
+ assert.equal(next.statusInfo?.configured, true);
82
+ assert.deepEqual(next.statusInfo?.webdav, {
83
+ url: 'https://dav.example.com',
84
+ username: 'me',
85
+ usernameConfigured: true,
86
+ passwordConfigured: true,
87
+ });
88
+ });
89
+
90
+ test('徽章合并:s3 / gist 非密视图原样并入(响应里没有就不动旧值)', () => {
91
+ const cloudS3 = { secretStored: true } as unknown as NonNullable<SyncStatusResponse['s3']>;
92
+ const next = savedConfigState(
93
+ state({ statusInfo: status }),
94
+ { ok: true, configured: true, transport: 's3', credentialConfigured: false, s3: cloudS3 },
95
+ {},
96
+ );
97
+ assert.equal(next.statusInfo?.s3, cloudS3);
98
+ assert.equal(next.statusInfo?.gist, undefined, '响应没带 gist 视图 → 不得凭空造出');
99
+ });
@@ -0,0 +1,69 @@
1
+ /**
2
+ * 「保存通道配置」成功后的本机状态合并(纯函数,node 可测)。
3
+ *
4
+ * 抽成独立文件的原因与 ./SyncRepositoryPicker.tsx 相同:SyncPanel 有行数棘轮,
5
+ * 而「清空已入库凭据 + 合并凭据徽章」是一段自包含的状态演算,
6
+ * 留在组件里既挤占行数,也无法脱离 React 单测。
7
+ *
8
+ * 口径(不得放宽):只清空**本次确实写出去**的 password / token / secret ——
9
+ * 保存期间用户又改了输入则保留新值;响应的凭据字段只有布尔,绝无 secret 值。
10
+ */
11
+ import type { SyncConfigSaveResponse, SyncPushPayload, SyncStatusResponse } from './sync-api.ts'
12
+
13
+ /** 参与合并的 state 结构子集(不依赖 SyncUiState 全量定义,避免循环 import)。 */
14
+ export interface SavedConfigState {
15
+ savingConfig: boolean
16
+ webdavPassword: string
17
+ token: string
18
+ s3Secret: string
19
+ gistToken: string
20
+ statusInfo: SyncStatusResponse | null
21
+ }
22
+
23
+ /** 只清「本次已写入的」内存凭据:仍等于刚才发出去的值才清空,否则说明用户改过,保留。 */
24
+ function clearSent(value: string, sent: string | undefined): string {
25
+ return value !== '' && value !== sent ? value : ''
26
+ }
27
+
28
+ /**
29
+ * 保存成功的 state 演进:savingConfig 复位 → 清空已写入的凭据 → 合并凭据徽章事实。
30
+ * @param s 保存发起时刻之后的权威 state(stateRef.current)
31
+ * @param saved POST /sync/config 响应(只含布尔,无 secret 值)
32
+ * @param sent 本次实际发出的请求体(判断「哪些值确实写出去了」)
33
+ */
34
+ export function savedConfigState(
35
+ s: SavedConfigState,
36
+ saved: SyncConfigSaveResponse,
37
+ sent: SyncPushPayload,
38
+ ): SavedConfigState {
39
+ const next: SavedConfigState = {
40
+ ...s,
41
+ savingConfig: false,
42
+ webdavPassword: clearSent(s.webdavPassword, sent.password),
43
+ token: clearSent(s.token, sent.token),
44
+ // 云端点密钥同一口径:s3 与 gist 共用请求体的 secret 槽位
45
+ s3Secret: clearSent(s.s3Secret, sent.secret),
46
+ gistToken: clearSent(s.gistToken, sent.secret),
47
+ }
48
+ // 状态未知(还没拉到 /sync/status)时没有徽章可合并,等下一次 loadStatus 回填
49
+ if (s.statusInfo === null) return next
50
+ const info: SyncStatusResponse = {
51
+ ...s.statusInfo,
52
+ configured: true,
53
+ credentialConfigured: saved.credentialConfigured,
54
+ }
55
+ // webdav 徽章:url / username 是可回显的非敏感事实,用本机已有的回填
56
+ if (saved.webdav !== undefined) {
57
+ info.webdav = {
58
+ url: s.statusInfo.webdav?.url,
59
+ username: s.statusInfo.webdav?.username,
60
+ usernameConfigured: saved.webdav.usernameConfigured,
61
+ passwordConfigured: saved.webdav.passwordConfigured,
62
+ }
63
+ }
64
+ // 云端点:响应只回非密视图 + secretStored 布尔(值永不回传),直接合并供徽章刷新
65
+ if (saved.s3 !== undefined) info.s3 = saved.s3
66
+ if (saved.gist !== undefined) info.gist = saved.gist
67
+ next.statusInfo = info
68
+ return next
69
+ }
@@ -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';
@@ -22,6 +22,7 @@ export const zh = {
22
22
  // 配置保存(自动保存 + 显式保存按钮)
23
23
  'config.save': '立即保存',
24
24
  'config.saveHint': '表单改动会自动保存:密码/token 安全写入 DSH credentials,不会写入同步文件或日志。',
25
+ 'config.savedTick': '已保存',
25
26
  // 通道选择器
26
27
  'channel.title': '同步通道',
27
28
  'channel.git': 'Git 私有仓库',
@@ -102,6 +103,7 @@ export const zh = {
102
103
  'repoPicker.hint': '列出你 GitHub 账号下已有的私有仓库(按最近更新排序),选中即填入下方仓库地址;也可以直接在下方手填地址(ssh / 本地路径 / 不在列表里的仓库)。列表需要先登录 GitHub;新建的仓库一律为私有 —— 公开仓库会公开你的配置内容。',
103
104
  'repoPicker.placeholder': '手动填写地址(或从上方选择)',
104
105
  'repoPicker.refresh': '刷新列表',
106
+ 'repoPicker.refreshed': '已刷新:{count} 个私有仓库',
105
107
  'repoPicker.forkBadge': 'Fork',
106
108
  'repoPicker.empty': '没有可用的私有仓库',
107
109
  'repoPicker.loadFailed': '仓库列表加载失败,可重试或直接手填地址。',
@@ -195,7 +197,6 @@ export const zh = {
195
197
  'mode.sessionsPickTitle': '选择要同步的历史对话',
196
198
  'mode.sessionsPickHint': '点名后只同步勾中的对话(优先于上面的数量上限);一个都不勾 = 回到「最近 N 个」模式。',
197
199
  'mode.sessionsPickReset': '改为「最近 N 个」',
198
- 'mode.sessionsWorkspaceWarn': '已勾选历史对话,但没有勾选「工作区」分区:目标机上这些对话可能归属不到任何工作区而显示不出来。建议一并勾选「工作区」。',
199
200
  'mode.gistSessionsWarn': '当前通道是 GitHub Gist,且勾选了「历史会话」:gist 会一次取回全部文件内容、单文件超限即截断、文件数还有上限,大分区同步可能失败或内容被截断。建议改用 Git / WebDAV / 对象存储通道同步历史会话,或取消勾选该分区。',
200
201
  'mode.persistHint': '分区选择已保存到本机:自动同步和手动推送都会使用此配置(重启后仍生效)。',
201
202
  'mode.choose': '选择',
@@ -275,7 +276,11 @@ export const zh = {
275
276
  'history.autosyncReasonNetwork': '网络问题',
276
277
  // F1 残留补齐(英文界面零中文):这三类此前只有硬编码中文,只住在这里
277
278
  'history.autosyncReasonEncrypted': '远端快照已加密,自动同步跳过(请手动同步)',
278
- 'history.autosyncReasonMutationLocked': '环境锁被占用(另一项任务进行中,或存在需回收的残留锁)',
279
+ 'history.autosyncReasonMutationLocked': '环境锁被另一个任务占用(稍后重试即可)',
280
+ // 宿主分档后(lockSkipToken):残留锁 / 不可用 / SAFE MODE 各有自己的处置方向,不再挤在「被占用」一句话里
281
+ 'history.autosyncReasonLockStale': '存在残留环境锁(上次任务异常退出留下,重试与重启都不会自愈)——请到「事故恢复」回收',
282
+ 'history.autosyncReasonLockUnavailable': '环境锁暂时不可用(锁目录读写失败或状态未知),稍后重试',
283
+ 'history.autosyncReasonSafeMode': '处于 SAFE MODE(外部操作失败后自动阻断写入)——请到「事故恢复」处理后重试',
279
284
  'history.autosyncReasonUnknown': '未知',
280
285
  'history.autosyncReasonConflictKeptLocal': '已按策略保留本机并覆盖远端',
281
286
  'history.autosyncReasonUpToDate': '无变化(本地与远端一致)',
@@ -479,6 +484,7 @@ export const en: Record<keyof typeof zh, string> = {
479
484
  // Config save (auto-save + explicit save button)
480
485
  'config.save': 'Save now',
481
486
  'config.saveHint': 'Form changes are saved automatically: password/token goes securely into DSH credentials, never into sync files or logs.',
487
+ 'config.savedTick': 'Saved',
482
488
  'channel.title': 'Sync Channel',
483
489
  'channel.git': 'Git private repo',
484
490
  'channel.webdav': 'WebDAV server',
@@ -556,6 +562,7 @@ export const en: Record<keyof typeof zh, string> = {
556
562
  'repoPicker.hint': 'Lists the existing private repositories in your GitHub account (most recently updated first); picking one fills the repository URL below. You can still type an address by hand (ssh / local path / repositories not in the list). The list requires GitHub sign-in. Newly created repositories are always private — a public repository would expose your config contents.',
557
563
  'repoPicker.placeholder': 'Type an address (or pick above)',
558
564
  'repoPicker.refresh': 'Refresh list',
565
+ 'repoPicker.refreshed': 'Refreshed: {count} private repositories',
559
566
  'repoPicker.forkBadge': 'Fork',
560
567
  'repoPicker.empty': 'No private repository available',
561
568
  'repoPicker.loadFailed': 'Could not load the repository list — retry, or type the address below.',
@@ -642,7 +649,6 @@ export const en: Record<keyof typeof zh, string> = {
642
649
  'mode.sessionsPickTitle': 'Pick conversations to sync',
643
650
  'mode.sessionsPickHint': 'Only the picked conversations are synced (this wins over the count above). Picking none returns to the "latest N" mode.',
644
651
  '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
652
  '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
653
  'mode.persistHint': 'The section selection is saved locally: both auto sync and manual push use this configuration (persists across restarts).',
648
654
  'mode.choose': 'Choose',
@@ -719,7 +725,11 @@ export const en: Record<keyof typeof zh, string> = {
719
725
  'history.autosyncReasonNotConfigured': 'No repository configured',
720
726
  'history.autosyncReasonNetwork': 'Network issue',
721
727
  '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)',
728
+ 'history.autosyncReasonMutationLocked': 'The environment lock is held by another task — retry shortly',
729
+ // Host-side split (lockSkipToken): stale / unavailable / SAFE MODE each carry their own remedy
730
+ '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',
731
+ 'history.autosyncReasonLockUnavailable': 'The environment lock cannot be used right now (lock directory unreadable/unwritable or unknown state) — retry later',
732
+ 'history.autosyncReasonSafeMode': 'The plugin is in SAFE MODE (writes are blocked after an external operation failed) — clear it in Incident recovery, then retry',
723
733
  'history.autosyncReasonUnknown': 'Unknown',
724
734
  'history.autosyncReasonConflictKeptLocal': 'Kept the local version and overwrote the remote as configured',
725
735
  'history.autosyncReasonUpToDate': 'No changes (local and remote match)',