dsh-config-manager 0.1.78 → 0.1.80
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.
- package/lib/adapters/credentials.d.ts +6 -2
- package/lib/adapters/credentials.js +19 -3
- package/lib/adapters/file-collection.js +2 -1
- package/lib/adapters/mcp.d.ts +48 -2
- package/lib/adapters/mcp.js +265 -3
- package/lib/adapters/messages.d.ts +3 -0
- package/lib/adapters/messages.js +7 -0
- package/lib/adapters/plugin-files.js +2 -1
- package/lib/adapters/plugins.js +105 -20
- package/lib/adapters/pnpm-workspace.d.ts +32 -0
- package/lib/adapters/pnpm-workspace.js +113 -2
- package/lib/adapters/prompts.d.ts +6 -2
- package/lib/adapters/prompts.js +17 -2
- package/lib/adapters/providers.d.ts +19 -2
- package/lib/adapters/providers.js +59 -3
- package/lib/adapters/settings.d.ts +6 -2
- package/lib/adapters/settings.js +13 -2
- package/lib/adapters/skills.d.ts +25 -1
- package/lib/adapters/skills.js +60 -0
- package/lib/adapters/ui.d.ts +6 -2
- package/lib/adapters/ui.js +13 -2
- package/lib/adapters/units.d.ts +18 -0
- package/lib/adapters/units.js +39 -0
- package/lib/adapters/workspaces.js +2 -1
- package/lib/client.d.ts +401 -112
- package/lib/client.js +2899 -1525
- package/lib/core/backup.js +20 -0
- package/lib/core/mcp-connector-store.d.ts +159 -0
- package/lib/core/mcp-connector-store.js +445 -0
- package/lib/core/messages-core.d.ts +2 -0
- package/lib/core/messages-core.js +4 -0
- package/lib/core/messages.d.ts +20 -0
- package/lib/core/messages.js +44 -0
- package/lib/core/phase3-host.js +18 -1
- package/lib/core/plugin-cli.d.ts +22 -2
- package/lib/core/plugin-cli.js +22 -3
- package/lib/core/recovery-orchestrator.d.ts +3 -1
- package/lib/core/recovery-orchestrator.js +75 -16
- package/lib/core/rollback-activity.d.ts +89 -0
- package/lib/core/rollback-activity.js +350 -0
- package/lib/core/rollback-ledger.d.ts +0 -9
- package/lib/core/rollback-ledger.js +37 -0
- package/lib/core/rollback-merge.d.ts +22 -2
- package/lib/core/rollback-merge.js +63 -13
- package/lib/core/rollback-point.d.ts +93 -0
- package/lib/core/rollback-point.js +420 -101
- package/lib/core/rollback-undo-journal.d.ts +123 -0
- package/lib/core/rollback-undo-journal.js +517 -0
- package/lib/core/self-update.js +2 -4
- package/lib/core/text-fidelity.d.ts +89 -0
- package/lib/core/text-fidelity.js +176 -0
- package/lib/core/types.d.ts +12 -3
- package/lib/core/update-check.js +2 -4
- package/lib/core/validator.d.ts +9 -0
- package/lib/core/validator.js +12 -0
- package/lib/foreign/bundle.js +42 -3
- package/lib/foreign/claude-code.js +358 -26
- package/lib/foreign/claude-sessions.d.ts +51 -8
- package/lib/foreign/claude-sessions.js +111 -13
- package/lib/foreign/read-claude-code.d.ts +33 -4
- package/lib/foreign/read-claude-code.js +446 -65
- package/lib/foreign/read-claude-plugins.d.ts +36 -0
- package/lib/foreign/read-claude-plugins.js +403 -0
- package/lib/foreign/registry.js +25 -2
- package/lib/foreign/truth-table.js +6 -4
- package/lib/foreign/types.d.ts +170 -2
- package/lib/index.d.ts +14 -5
- package/lib/index.js +60 -16
- package/lib/market/git-file-writer.js +7 -1
- package/lib/profiles/dsh-profile-launcher.d.ts +20 -0
- package/lib/profiles/dsh-profile-launcher.js +58 -1
- package/lib/profiles/dsh-profile-shared.d.ts +8 -2
- package/lib/profiles/dsh-profile-shared.js +8 -2
- package/lib/routes/foreign.js +8 -1
- package/lib/routes/index.d.ts +1 -1
- package/lib/routes/kit.d.ts +2 -2
- package/lib/routes/sync.js +173 -9
- package/lib/schema/manifest.d.ts +6 -1
- package/lib/schema/manifest.js +55 -0
- package/lib/schema/types.d.ts +47 -2
- package/lib/sync/ancestor.d.ts +22 -0
- package/lib/sync/ancestor.js +66 -2
- package/lib/sync/autosync-config.d.ts +73 -0
- package/lib/sync/autosync-config.js +89 -0
- package/lib/sync/autosync-scheduler.d.ts +80 -6
- package/lib/sync/autosync-scheduler.js +263 -40
- package/lib/sync/gist/gist-transport.d.ts +18 -1
- package/lib/sync/gist/gist-transport.js +42 -3
- package/lib/sync/gist/messages.d.ts +2 -0
- package/lib/sync/gist/messages.js +5 -0
- package/lib/sync/git/git-transport.d.ts +42 -3
- package/lib/sync/git/git-transport.js +146 -3
- package/lib/sync/merge.d.ts +47 -14
- package/lib/sync/merge.js +242 -222
- package/lib/sync/messages.d.ts +8 -0
- package/lib/sync/messages.js +19 -0
- package/lib/sync/risk.d.ts +19 -2
- package/lib/sync/risk.js +10 -3
- package/lib/sync/s3/messages.d.ts +6 -0
- package/lib/sync/s3/messages.js +13 -0
- package/lib/sync/s3/s3-transport.d.ts +9 -1
- package/lib/sync/s3/s3-transport.js +78 -6
- package/lib/sync/s3/sigv4.js +11 -2
- package/lib/sync/sync-engine.d.ts +212 -8
- package/lib/sync/sync-engine.js +514 -58
- package/lib/sync/sync-history.d.ts +11 -0
- package/lib/sync/sync-history.js +20 -0
- package/lib/sync/sync-state.d.ts +43 -0
- package/lib/sync/sync-state.js +44 -0
- package/lib/sync/sync-watcher.d.ts +76 -0
- package/lib/sync/sync-watcher.js +202 -0
- package/lib/sync/text-merge.d.ts +85 -0
- package/lib/sync/text-merge.js +513 -0
- package/lib/sync/transport.d.ts +48 -0
- package/lib/sync/transport.js +12 -0
- package/lib/sync/watch-scope.d.ts +38 -0
- package/lib/sync/watch-scope.js +95 -0
- package/lib/sync/webdav/webdav-transport.d.ts +16 -2
- package/lib/sync/webdav/webdav-transport.js +128 -11
- package/lib/ui/foreign-view.js +10 -0
- package/lib/ui/i18n.d.ts +9 -0
- package/lib/ui/i18n.js +22 -0
- package/lib/ui/rollback-view.d.ts +12 -0
- package/lib/ui/rollback-view.js +2 -0
- package/lib/ui/sync-settings-view.d.ts +47 -0
- package/lib/ui/sync-settings-view.js +24 -0
- package/lib/ui/types.d.ts +21 -0
- package/lib/utils/env-lock.d.ts +1 -0
- package/lib/utils/env-lock.js +7 -4
- package/package.json +6 -6
- package/src/adapters/credentials.ts +22 -4
- package/src/adapters/file-collection.ts +2 -1
- package/src/adapters/mcp.test.ts +235 -1
- package/src/adapters/mcp.ts +276 -5
- package/src/adapters/messages.ts +7 -0
- package/src/adapters/plugin-files.ts +2 -1
- package/src/adapters/plugins.test.ts +176 -2
- package/src/adapters/plugins.ts +107 -21
- package/src/adapters/pnpm-workspace.test.ts +89 -1
- package/src/adapters/pnpm-workspace.ts +127 -2
- package/src/adapters/prompts.ts +20 -3
- package/src/adapters/providers.ts +62 -4
- package/src/adapters/settings.ts +16 -3
- package/src/adapters/skills.test.ts +141 -0
- package/src/adapters/skills.ts +58 -2
- package/src/adapters/ui.ts +16 -3
- package/src/adapters/units-entries.test.ts +190 -0
- package/src/adapters/units.ts +50 -0
- package/src/adapters/workspaces.ts +2 -1
- package/src/client/about/PluginUpdateDialog.tsx +4 -2
- package/src/client/about/ReleaseNotesDialog.tsx +4 -2
- package/src/client/chat/RollbackReviewDialog.tsx +3 -2
- package/src/client/common/Skeleton.tsx +32 -0
- package/src/client/common/api-base.test.ts +36 -0
- package/src/client/common/http.test.ts +12 -1
- package/src/client/common/http.ts +8 -2
- package/src/client/common/routes.ts +46 -3
- package/src/client/config-manager.module.css +321 -11
- package/src/client/home/HomePanel.tsx +14 -6
- package/src/client/import/ForeignImportView.tsx +3 -1
- package/src/client/import/import-wizard-steps.tsx +2 -1
- package/src/client/library/ArtifactRow.tsx +12 -2
- package/src/client/library/LibraryActions.tsx +6 -3
- package/src/client/library/LibraryPanel.tsx +21 -3
- package/src/client/library/RestorePlanView.tsx +4 -2
- package/src/client/locales.ts +3 -0
- package/src/client/market/market-api.test.ts +3 -2
- package/src/client/recovery/RecoveryPanel.tsx +54 -7
- package/src/client/recovery/RollbackCard.tsx +7 -2
- package/src/client/recovery/RollbackDiffPane.tsx +3 -2
- package/src/client/recovery/recovery-locales.ts +20 -2
- package/src/client/recovery/recovery-view.test.ts +39 -1
- package/src/client/recovery/recovery-view.ts +23 -1
- package/src/client/run-store.test.ts +1 -1
- package/src/client/run-store.ts +4 -0
- package/src/client/sync/AutosyncCard.tsx +49 -6
- package/src/client/sync/MergeModal.tsx +220 -0
- package/src/client/sync/MergePreviewView.tsx +306 -0
- package/src/client/sync/SyncActivityBar.tsx +31 -0
- package/src/client/sync/SyncConfirmView.tsx +2 -1
- package/src/client/sync/SyncPanel.tsx +130 -87
- package/src/client/sync/SyncProbeRow.tsx +162 -0
- package/src/client/sync/SyncSettingsView.test.ts +27 -2
- package/src/client/sync/WorkDirCard.tsx +44 -6
- package/src/client/sync/history-model.ts +4 -1
- package/src/client/sync/merge-view.test.ts +248 -0
- package/src/client/sync/merge-view.ts +398 -0
- package/src/client/sync/probe-view.test.ts +90 -0
- package/src/client/sync/probe-view.ts +63 -0
- package/src/client/sync/remote-device-view.test.ts +35 -0
- package/src/client/sync/remote-device-view.ts +25 -0
- package/src/client/sync/sync-api.test.ts +5 -3
- package/src/client/sync/sync-api.ts +212 -2
- package/src/client/sync/sync-entry.test.ts +78 -0
- package/src/client/sync/sync-entry.ts +53 -0
- package/src/client/sync/sync-locales.ts +234 -2
- package/src/client/sync/sync-view.test.ts +18 -1
- package/src/client/sync/sync-view.ts +20 -0
- package/src/core/backup.test.ts +41 -0
- package/src/core/backup.ts +20 -0
- package/src/core/mcp-connector-store.test.ts +265 -0
- package/src/core/mcp-connector-store.ts +516 -0
- package/src/core/messages-core.ts +4 -0
- package/src/core/messages.ts +46 -0
- package/src/core/phase3-host.ts +18 -1
- package/src/core/phase3-production-integration.test.ts +4 -0
- package/src/core/plugin-cli.test.ts +26 -0
- package/src/core/plugin-cli.ts +30 -4
- package/src/core/recovery-orchestrator.test.ts +104 -5
- package/src/core/recovery-orchestrator.ts +74 -17
- package/src/core/rollback-activity.test.ts +311 -0
- package/src/core/rollback-activity.ts +367 -0
- package/src/core/rollback-cross-session.test.ts +694 -0
- package/src/core/rollback-interrupted.test.ts +137 -0
- package/src/core/rollback-ledger.ts +32 -0
- package/src/core/rollback-merge.test.ts +130 -0
- package/src/core/rollback-merge.ts +78 -14
- package/src/core/rollback-point.ts +468 -91
- package/src/core/rollback-undo-journal.test.ts +508 -0
- package/src/core/rollback-undo-journal.ts +571 -0
- package/src/core/self-update.ts +2 -5
- package/src/core/text-fidelity.test.ts +189 -0
- package/src/core/text-fidelity.ts +197 -0
- package/src/core/types.ts +11 -3
- package/src/core/update-check.ts +2 -5
- package/src/core/validator.ts +14 -0
- package/src/foreign/bundle-origin.test.ts +265 -0
- package/src/foreign/bundle.ts +45 -5
- package/src/foreign/claude-code.test.ts +268 -0
- package/src/foreign/claude-code.ts +406 -25
- package/src/foreign/claude-plugins.test.ts +234 -0
- package/src/foreign/claude-sessions.test.ts +141 -0
- package/src/foreign/claude-sessions.ts +179 -23
- package/src/foreign/file-budget.test.ts +4 -1
- package/src/foreign/read-claude-code.test.ts +320 -0
- package/src/foreign/read-claude-code.ts +490 -71
- package/src/foreign/read-claude-plugins.ts +465 -0
- package/src/foreign/registry.ts +25 -2
- package/src/foreign/session-ir.test.ts +65 -0
- package/src/foreign/truth-table.test.ts +81 -0
- package/src/foreign/truth-table.ts +6 -3
- package/src/foreign/types.ts +162 -2
- package/src/index.facade.test.ts +26 -4
- package/src/index.ts +76 -19
- package/src/market/git-file-writer.test.ts +4 -0
- package/src/market/git-file-writer.ts +7 -1
- package/src/profiles/dsh-profile-launcher.test.ts +68 -3
- package/src/profiles/dsh-profile-launcher.ts +56 -1
- package/src/profiles/dsh-profile-shared.ts +8 -2
- package/src/routes/foreign.ts +8 -1
- package/src/routes/index.ts +1 -1
- package/src/routes/kit.ts +2 -2
- package/src/routes/sync.ts +176 -9
- package/src/schema/manifest-schema.test.ts +87 -2
- package/src/schema/manifest.ts +57 -1
- package/src/schema/types.ts +45 -2
- package/src/sync/ancestor.ts +76 -2
- package/src/sync/autosync-config.test.ts +73 -1
- package/src/sync/autosync-config.ts +124 -0
- package/src/sync/autosync-risk-tier.test.ts +38 -2
- package/src/sync/autosync-scheduler.test.ts +264 -12
- package/src/sync/autosync-scheduler.ts +296 -44
- package/src/sync/gist/gist-conditional-write.test.ts +203 -0
- package/src/sync/gist/gist-transport.ts +53 -5
- package/src/sync/gist/messages.ts +5 -0
- package/src/sync/git/git-probe.test.ts +80 -0
- package/src/sync/git/git-transport.test.ts +185 -0
- package/src/sync/git/git-transport.ts +178 -5
- package/src/sync/merge.test.ts +188 -55
- package/src/sync/merge.ts +282 -224
- package/src/sync/messages.ts +19 -0
- package/src/sync/risk.ts +29 -5
- package/src/sync/s3/messages.ts +13 -0
- package/src/sync/s3/s3-conditional-write.test.ts +330 -0
- package/src/sync/s3/s3-transport.test.ts +2 -1
- package/src/sync/s3/s3-transport.ts +87 -9
- package/src/sync/s3/sigv4.test.ts +4 -1
- package/src/sync/s3/sigv4.ts +11 -2
- package/src/sync/sync-device-identity.test.ts +267 -0
- package/src/sync/sync-engine.test.ts +410 -19
- package/src/sync/sync-engine.ts +602 -57
- package/src/sync/sync-history.test.ts +16 -1
- package/src/sync/sync-history.ts +26 -0
- package/src/sync/sync-state.test.ts +64 -0
- package/src/sync/sync-state.ts +79 -0
- package/src/sync/sync-watcher.test.ts +197 -0
- package/src/sync/sync-watcher.ts +246 -0
- package/src/sync/text-merge.test.ts +358 -0
- package/src/sync/text-merge.ts +554 -0
- package/src/sync/transport.ts +57 -0
- package/src/sync/watch-scope.test.ts +122 -0
- package/src/sync/watch-scope.ts +120 -0
- package/src/sync/webdav/webdav-conditional-write.test.ts +360 -0
- package/src/sync/webdav/webdav-transport.ts +137 -14
- package/src/ui/foreign-view.test.ts +34 -0
- package/src/ui/foreign-view.ts +10 -0
- package/src/ui/i18n.ts +22 -0
- package/src/ui/rollback-view.ts +14 -0
- package/src/ui/sync-settings-view.test.ts +28 -1
- package/src/ui/sync-settings-view.ts +43 -0
- package/src/ui/types.ts +22 -0
- package/src/utils/env-lock.ts +8 -5
|
@@ -3,8 +3,10 @@
|
|
|
3
3
|
*
|
|
4
4
|
* 为什么需要它:改仓库地址后同步失败时,App 内此前**没有任何自救路径** —— 只能手工
|
|
5
5
|
* `git remote set-url`,或删掉 `<dataDir>/sync/work` 重来。这里给出工作副本的只读事实
|
|
6
|
-
* (路径 / origin /
|
|
6
|
+
* (路径 / origin / 与配置地址是否一致)与三条出口:
|
|
7
7
|
* - 「重指向仓库地址」= host 的 relink(非破坏性:只改 git 配置,不碰工作树与本地提交);
|
|
8
|
+
* - 「采纳远端历史」= host 的 adopt(issue #104:把远端分支合并进本地工作副本 —— 换仓库 / 远端历史
|
|
9
|
+
* 被重写后两条历史不相交,pull --ff-only 永远失败。不改写本地提交,可 revert,冲突自动 abort);
|
|
8
10
|
* - 「重新克隆工作副本」= host 的 reclone(**丢弃未上行的本地提交**)→ danger 二次确认。
|
|
9
11
|
*
|
|
10
12
|
* 约定(与 ChannelClearConfirmDialog 同族):确认弹窗、宿主调用与终局回执都在本文件内自持,
|
|
@@ -19,10 +21,18 @@ import { ConfirmDialog } from '../common/ConfirmDialog.tsx'
|
|
|
19
21
|
import { toast } from '../common/toast-store.ts'
|
|
20
22
|
import { redact } from '../../security/redaction.ts'
|
|
21
23
|
import {
|
|
22
|
-
canRecloneWorkdir, formatSyncUrlPreview, needsWorkdirRelink,
|
|
24
|
+
canAdoptWorkdir, canRecloneWorkdir, formatSyncUrlPreview, needsWorkdirRelink, workdirBacklog, workdirStateBadgeKind,
|
|
25
|
+
workdirStateKey,
|
|
23
26
|
} from '../../ui/sync-settings-view.ts'
|
|
24
27
|
import css from '../config-manager.module.css'
|
|
25
28
|
|
|
29
|
+
/** 三种出口各自的终局回执(zh/en 都在 sync-locales,禁止在这里拼用户可见文案)。 */
|
|
30
|
+
const WORKDIR_TOAST = {
|
|
31
|
+
relink: 'toast.workdirRelinked',
|
|
32
|
+
adopt: 'toast.workdirAdopted',
|
|
33
|
+
reclone: 'toast.workdirRecloned',
|
|
34
|
+
} as const
|
|
35
|
+
|
|
26
36
|
export function WorkDirCard({ t, api, workDir, busy, onChanged }: {
|
|
27
37
|
t: TranslateNS<'config-manager-sync'>
|
|
28
38
|
api: SyncApi
|
|
@@ -34,20 +44,27 @@ export function WorkDirCard({ t, api, workDir, busy, onChanged }: {
|
|
|
34
44
|
}) {
|
|
35
45
|
/** 重新克隆的二次确认(破坏性:丢弃未上行的本地提交) */
|
|
36
46
|
const [recloneOpen, setRecloneOpen] = useState(false)
|
|
37
|
-
/** 本次发起的出口(relink / reclone):请求在途时卡片按钮就地转加载态。
|
|
47
|
+
/** 本次发起的出口(relink / adopt / reclone):请求在途时卡片按钮就地转加载态。
|
|
38
48
|
* 为什么必须有:reclone 要删目录 + 重新 clone(真机可达数十秒),此前点了只有 toast 在**结束**时才响,
|
|
39
49
|
* 用户无从判断是否正在执行,容易重复点击或以为没反应。 */
|
|
40
|
-
const [pending, setPending] = useState<'relink' | 'reclone' | null>(null)
|
|
50
|
+
const [pending, setPending] = useState<'relink' | 'adopt' | 'reclone' | null>(null)
|
|
41
51
|
const stateKey = workdirStateKey(workDir)
|
|
42
52
|
const badgeKind = workdirStateBadgeKind(stateKey)
|
|
43
53
|
const facts = workDir !== undefined && 'facts' in workDir ? workDir.facts : null
|
|
54
|
+
/** issue #104 建议 3:本地攒了提交、远端却一个快照都没有 —— 这一条必须显式喊出来 */
|
|
55
|
+
const backlog = workdirBacklog(workDir)
|
|
56
|
+
const backlogBadge = backlog.kind === 'never-synced'
|
|
57
|
+
? { kind: 'warn' as const, key: 'workdir.backlogNeverSynced' as const }
|
|
58
|
+
: backlog.kind === 'ahead'
|
|
59
|
+
? { kind: 'warn' as const, key: 'workdir.backlogAhead' as const }
|
|
60
|
+
: null
|
|
44
61
|
|
|
45
|
-
const reset = async (mode: 'relink' | 'reclone'): Promise<void> => {
|
|
62
|
+
const reset = async (mode: 'relink' | 'adopt' | 'reclone'): Promise<void> => {
|
|
46
63
|
setRecloneOpen(false)
|
|
47
64
|
setPending(mode)
|
|
48
65
|
try {
|
|
49
66
|
await api.workdirReset(mode === 'reclone' ? { mode, confirm: true } : { mode })
|
|
50
|
-
toast.ok(t(mode
|
|
67
|
+
toast.ok(t(WORKDIR_TOAST[mode]))
|
|
51
68
|
onChanged()
|
|
52
69
|
} catch (err) {
|
|
53
70
|
toast.error(t('toast.workdirResetFailed') + t('common.labelSeparator') + redact(err instanceof Error ? err.message : String(err)))
|
|
@@ -63,6 +80,7 @@ export function WorkDirCard({ t, api, workDir, busy, onChanged }: {
|
|
|
63
80
|
{stateKey !== null && badgeKind !== null && (
|
|
64
81
|
<div className={css.statRow}>
|
|
65
82
|
<Badge kind={badgeKind}>{t(stateKey)}</Badge>
|
|
83
|
+
{backlogBadge !== null && <Badge kind={backlogBadge.kind}>{t(backlogBadge.key)}</Badge>}
|
|
66
84
|
</div>
|
|
67
85
|
)}
|
|
68
86
|
{workDir === undefined ? (
|
|
@@ -83,6 +101,18 @@ export function WorkDirCard({ t, api, workDir, busy, onChanged }: {
|
|
|
83
101
|
</span>
|
|
84
102
|
</span>
|
|
85
103
|
</div>
|
|
104
|
+
{backlog.kind !== 'unknown' && (
|
|
105
|
+
<div className={css.factCell}>
|
|
106
|
+
<span className={css.factLabel}>{t('workdir.ahead')}</span>
|
|
107
|
+
<span className={css.factValue}>{backlog.kind === 'clean' ? 0 : backlog.ahead}</span>
|
|
108
|
+
</div>
|
|
109
|
+
)}
|
|
110
|
+
{(backlog.kind === 'clean' || backlog.kind === 'ahead') && (
|
|
111
|
+
<div className={css.factCell}>
|
|
112
|
+
<span className={css.factLabel}>{t('workdir.remoteSnapshots')}</span>
|
|
113
|
+
<span className={css.factValue}>{backlog.remoteSnapshots}</span>
|
|
114
|
+
</div>
|
|
115
|
+
)}
|
|
86
116
|
</div>
|
|
87
117
|
)}
|
|
88
118
|
<div className={css.actionRowTop}>
|
|
@@ -91,6 +121,14 @@ export function WorkDirCard({ t, api, workDir, busy, onChanged }: {
|
|
|
91
121
|
{t('workdir.relink')}
|
|
92
122
|
</Button>
|
|
93
123
|
)}
|
|
124
|
+
{canAdoptWorkdir(workDir) && (
|
|
125
|
+
<>
|
|
126
|
+
<Button disabled={busy || pending !== null} loading={pending === 'adopt'} onClick={() => { void reset('adopt') }}>
|
|
127
|
+
{t('workdir.adopt')}
|
|
128
|
+
</Button>
|
|
129
|
+
<InfoHint text={t('workdir.adoptHint')} label={t('common.infoHint')} />
|
|
130
|
+
</>
|
|
131
|
+
)}
|
|
94
132
|
{canRecloneWorkdir(workDir) && (
|
|
95
133
|
<Button variant="danger" disabled={busy || pending !== null} loading={pending === 'reclone'} onClick={() => { setRecloneOpen(true) }}>
|
|
96
134
|
{t('workdir.reclone')}
|
|
@@ -87,7 +87,7 @@ export function autosyncStatusLabel(status: AutosyncHistoryEntry['status'], t: S
|
|
|
87
87
|
* 跳过原因 → 可读描述(host 透传语义;未知原因回退原串)。
|
|
88
88
|
*
|
|
89
89
|
* client-F1(本次收口):conflict / no-remote / not-configured / network / encrypted /
|
|
90
|
-
* mutation-locked / 未知
|
|
90
|
+
* mutation-locked / conflict-kept-local / 未知 **八类全部**走 history.autosyncReason* 字典键 —— 此前部分码是
|
|
91
91
|
* 硬编码中文(sync-locales.ts 当时不可写),英文界面下会原样透出。
|
|
92
92
|
*/
|
|
93
93
|
export function skipReasonKey(reason: string | undefined): SyncKey | null {
|
|
@@ -106,6 +106,9 @@ export function skipReasonKey(reason: string | undefined): SyncKey | null {
|
|
|
106
106
|
// 客户端拿不到细分 reason → 文案必须同时覆盖「活锁占用」与「残留锁需回收」两种可能,
|
|
107
107
|
// 并给出可操作方向(否则界面只显示裸 token,用户无从判断要不要处理)。
|
|
108
108
|
case 'mutation-locked': return 'history.autosyncReasonMutationLocked';
|
|
109
|
+
// 真·自动同步(conflictPolicy='local'):冲突已按策略「保留本机并推上去」消解,
|
|
110
|
+
// 远端那一版被覆盖(仍在远端历史快照里,可回滚)—— 必须与「冲突待裁决」分开说。
|
|
111
|
+
case 'conflict-kept-local': return 'history.autosyncReasonConflictKeptLocal';
|
|
109
112
|
// 未知原因:没有字典键(调用方决定回退策略)
|
|
110
113
|
default: return null;
|
|
111
114
|
}
|
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* T-ui-merge:远程合并裁决**纯函数**单测(node:test,零依赖、无 DOM)。
|
|
3
|
+
*
|
|
4
|
+
* 覆盖验收:决策/成因字典映射(禁止裸枚举)、冲突行投影与截断+redact、
|
|
5
|
+
* 保守缺省(空草稿 = 未点名的分区引擎不应用)、批量裁决语义、裁决计数与可应用判据、结果归一化。
|
|
6
|
+
*/
|
|
7
|
+
import test from 'node:test'
|
|
8
|
+
import assert from 'node:assert/strict'
|
|
9
|
+
|
|
10
|
+
import {
|
|
11
|
+
applyBulkResolution, buildMergeResolutions, decideSyncEntry, decisionWillApply, hasApplicableSections, initialResolutionDraft,
|
|
12
|
+
mergeDecisionCounts, mergeDecisionKey, mergeDecisionTone, mergeKindKey, mergeReasonKey,
|
|
13
|
+
mergeResultView, mergeSectionRows, mergeSummaryItems, needsNoAncestorNotice,
|
|
14
|
+
normalizeDecision, setSectionAction, truncatePreview, MERGE_PREVIEW_MAX_CHARS,
|
|
15
|
+
} from './merge-view.ts'
|
|
16
|
+
import type { MergePreviewResponse, MergePreviewSection, MergeSectionDecision } from './sync-api.ts'
|
|
17
|
+
|
|
18
|
+
/** 构造一份预览(分区 id 用真实 SectionId 形态,便于与宿主口径对齐)。 */
|
|
19
|
+
function preview(overrides: Partial<MergePreviewResponse> = {}): MergePreviewResponse {
|
|
20
|
+
return {
|
|
21
|
+
ok: true,
|
|
22
|
+
snapshotId: 'snap-1',
|
|
23
|
+
hasAncestor: true,
|
|
24
|
+
sections: [],
|
|
25
|
+
summary: { auto: 0, review: 0, conflicts: 0, skipped: 0 },
|
|
26
|
+
...overrides,
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
test('merge-view: normalizeDecision —— 未知值 fail-closed 归入「需裁决」,不静默当无变化', () => {
|
|
31
|
+
assert.equal(normalizeDecision('useRemote'), 'useRemote')
|
|
32
|
+
assert.equal(normalizeDecision('conflict'), 'conflict')
|
|
33
|
+
assert.equal(normalizeDecision('brand-new-decision'), 'conflict')
|
|
34
|
+
assert.equal(normalizeDecision(undefined), 'conflict')
|
|
35
|
+
assert.equal(normalizeDecision(42), 'conflict')
|
|
36
|
+
})
|
|
37
|
+
|
|
38
|
+
test('merge-view: 决策/成因/类型一律经字典键映射(界面不出现裸枚举)', () => {
|
|
39
|
+
assert.equal(mergeDecisionKey('merge'), 'merge.decision.merge')
|
|
40
|
+
assert.equal(mergeDecisionKey('nope'), 'merge.decision.conflict')
|
|
41
|
+
assert.equal(mergeDecisionTone('merge'), 'ok')
|
|
42
|
+
assert.equal(mergeDecisionTone('conflict'), 'warn')
|
|
43
|
+
assert.equal(mergeReasonKey('modify-delete'), 'merge.reason.modifyDelete')
|
|
44
|
+
assert.equal(mergeReasonKey('unknown-reason'), 'merge.reason.bothModified')
|
|
45
|
+
assert.equal(mergeReasonKey(undefined), 'merge.reason.bothModified')
|
|
46
|
+
assert.equal(mergeKindKey('file'), 'merge.kind.file')
|
|
47
|
+
assert.equal(mergeKindKey('key'), 'merge.kind.key')
|
|
48
|
+
assert.equal(mergeKindKey(undefined), 'merge.kind.key')
|
|
49
|
+
})
|
|
50
|
+
|
|
51
|
+
test('merge-view: truncatePreview —— 渲染前再过一次 redact,且按上限截断', () => {
|
|
52
|
+
const secret = 'ghp_abcdefghijklmnopqrstuvwxyz012345'
|
|
53
|
+
const masked = truncatePreview('Authorization: ' + secret)
|
|
54
|
+
assert.ok(masked.includes('REDACTED'), '密钥形状必须被掩码,实际:' + masked)
|
|
55
|
+
assert.ok(!masked.includes(secret))
|
|
56
|
+
assert.equal(truncatePreview(undefined), '')
|
|
57
|
+
assert.equal(truncatePreview(null), '')
|
|
58
|
+
assert.equal(truncatePreview(123), '123', '非字符串按 String() 展示,绝不 undefined')
|
|
59
|
+
const long = 'x'.repeat(MERGE_PREVIEW_MAX_CHARS + 40)
|
|
60
|
+
const cut = truncatePreview(long)
|
|
61
|
+
assert.equal(cut.length, MERGE_PREVIEW_MAX_CHARS + 1, '截断到上限 + 一个省略号')
|
|
62
|
+
assert.ok(cut.endsWith('…'))
|
|
63
|
+
})
|
|
64
|
+
|
|
65
|
+
test('merge-view: mergeSectionRows —— conflict 分区需裁决且「自动合并」不可用;merge 分区可用', () => {
|
|
66
|
+
const p = preview({
|
|
67
|
+
sections: [
|
|
68
|
+
{ id: 'settings', decision: 'conflict', conflictCount: 1, conflicts: [{ path: 'foo', kind: 'key', reason: 'both-modified', localPreview: 'l', remotePreview: 'r', ancestorPreview: 'a' }] },
|
|
69
|
+
{ id: 'providers', decision: 'merge', autoMerged: 2, conflictCount: 0, conflicts: [] },
|
|
70
|
+
],
|
|
71
|
+
})
|
|
72
|
+
const rows = mergeSectionRows(p)
|
|
73
|
+
assert.equal(rows.length, 2)
|
|
74
|
+
const conflict = rows[0]!
|
|
75
|
+
assert.equal(conflict.needsDecision, true)
|
|
76
|
+
assert.equal(conflict.canUseMerged, false, 'conflict 分区没有 merged 载荷 → 采用自动合并必须禁用')
|
|
77
|
+
assert.equal(conflict.resolutionId, 'settings', '裁决单 id = 分区 id(无复合 id)')
|
|
78
|
+
assert.deepEqual(conflict.conflicts[0], {
|
|
79
|
+
path: 'foo',
|
|
80
|
+
kindKey: 'merge.kind.key',
|
|
81
|
+
reasonKey: 'merge.reason.bothModified',
|
|
82
|
+
localPreview: 'l',
|
|
83
|
+
remotePreview: 'r',
|
|
84
|
+
ancestorPreview: 'a',
|
|
85
|
+
})
|
|
86
|
+
const merged = rows[1]!
|
|
87
|
+
assert.equal(merged.needsDecision, false)
|
|
88
|
+
assert.equal(merged.canUseMerged, true)
|
|
89
|
+
assert.equal(merged.autoMerged, 2)
|
|
90
|
+
})
|
|
91
|
+
|
|
92
|
+
test('merge-view: mergeSectionRows —— 缺字段时用冲突数组长度兜底,不显示 undefined', () => {
|
|
93
|
+
const p = preview({
|
|
94
|
+
sections: [{ id: 'mcp', decision: 'conflict', conflictCount: undefined as unknown as number, conflicts: [{ path: 'a', kind: 'key', localPreview: '', remotePreview: '', ancestorPreview: '' }] }],
|
|
95
|
+
})
|
|
96
|
+
const rows = mergeSectionRows(p)
|
|
97
|
+
assert.equal(rows[0]!.conflictCount, 1)
|
|
98
|
+
assert.equal(rows[0]!.autoMerged, null)
|
|
99
|
+
})
|
|
100
|
+
|
|
101
|
+
test('merge-view: initialResolutionDraft —— 空草稿(未点名的分区引擎不应用,界面不再预置 skip)', () => {
|
|
102
|
+
const p = preview({
|
|
103
|
+
sections: [
|
|
104
|
+
{ id: 'settings', decision: 'conflict', conflictCount: 2, conflicts: [] },
|
|
105
|
+
{ id: 'providers', decision: 'useRemote', conflictCount: 0, conflicts: [] },
|
|
106
|
+
],
|
|
107
|
+
})
|
|
108
|
+
assert.deepEqual(initialResolutionDraft(p), {}, '空草稿:请求体里不出现任何分区')
|
|
109
|
+
assert.deepEqual(initialResolutionDraft(null), {})
|
|
110
|
+
assert.deepEqual(buildMergeResolutions({}), [], '空草稿 = 空请求体')
|
|
111
|
+
})
|
|
112
|
+
|
|
113
|
+
test('merge-view: 批量裁决 —— 本地/远端覆盖全部分区;自动合并只碰 merge 分区;留到下次 = 清空待裁决', () => {
|
|
114
|
+
const p = preview({
|
|
115
|
+
sections: [
|
|
116
|
+
{ id: 'settings', decision: 'conflict', conflictCount: 1, conflicts: [] },
|
|
117
|
+
{ id: 'mcp', decision: 'conflict', conflictCount: 1, conflicts: [] },
|
|
118
|
+
{ id: 'providers', decision: 'merge', autoMerged: 1, conflictCount: 0, conflicts: [] },
|
|
119
|
+
],
|
|
120
|
+
})
|
|
121
|
+
const base = initialResolutionDraft(p)
|
|
122
|
+
assert.deepEqual(applyBulkResolution(p, base, 'useRemote'), { settings: 'useRemote', mcp: 'useRemote', providers: 'useRemote' })
|
|
123
|
+
assert.deepEqual(applyBulkResolution(p, base, 'keepLocal'), { settings: 'keepLocal', mcp: 'keepLocal', providers: 'keepLocal' })
|
|
124
|
+
assert.deepEqual(
|
|
125
|
+
applyBulkResolution(p, base, 'useMerged'),
|
|
126
|
+
{ providers: 'useMerged' },
|
|
127
|
+
'conflict 分区不因批量操作被静默改成别的动作,只有有 merged 载荷的分区可写 useMerged',
|
|
128
|
+
)
|
|
129
|
+
assert.deepEqual(applyBulkResolution(p, base, 'leavePending'), {}, '冲突留到下次 = 把待裁决分区移出草稿')
|
|
130
|
+
// 已裁决的分区被「留到下次」清掉,未裁决分区本来就不在草稿里
|
|
131
|
+
assert.deepEqual(applyBulkResolution(p, setSectionAction(base, 'settings', 'useRemote'), 'leavePending'), {})
|
|
132
|
+
})
|
|
133
|
+
|
|
134
|
+
test('merge-view: 单分区裁决 + 请求体排序稳定', () => {
|
|
135
|
+
const p = preview({
|
|
136
|
+
sections: [
|
|
137
|
+
{ id: 'settings', decision: 'conflict', conflictCount: 1, conflicts: [] },
|
|
138
|
+
{ id: 'mcp', decision: 'conflict', conflictCount: 1, conflicts: [] },
|
|
139
|
+
],
|
|
140
|
+
})
|
|
141
|
+
const d = setSectionAction(initialResolutionDraft(p), 'mcp', 'useRemote')
|
|
142
|
+
assert.deepEqual(buildMergeResolutions(d), [{ id: 'mcp', action: 'useRemote' }])
|
|
143
|
+
assert.deepEqual(buildMergeResolutions(setSectionAction({}, 'settings', 'keepLocal')), [{ id: 'settings', action: 'keepLocal' }])
|
|
144
|
+
})
|
|
145
|
+
|
|
146
|
+
test('merge-view: hasApplicableSections —— 预览可应用 或 已裁决会写盘(issue #106)', () => {
|
|
147
|
+
const onlySkip = preview({ sections: [{ id: 'settings', decision: 'skip', conflictCount: 0, conflicts: [] }] })
|
|
148
|
+
assert.equal(hasApplicableSections(onlySkip), false, '全部无变化 → 执行合并必须禁用')
|
|
149
|
+
assert.equal(hasApplicableSections(onlySkip, {}), false)
|
|
150
|
+
assert.equal(hasApplicableSections(null), false)
|
|
151
|
+
const withAuto = preview({
|
|
152
|
+
sections: [
|
|
153
|
+
{ id: 'settings', decision: 'conflict', conflictCount: 1, conflicts: [] },
|
|
154
|
+
{ id: 'providers', decision: 'useRemote', conflictCount: 0, conflicts: [] },
|
|
155
|
+
],
|
|
156
|
+
})
|
|
157
|
+
assert.equal(hasApplicableSections(withAuto), true, '只有冲突 + 一个可应用分区 → 可执行(冲突留待下次)')
|
|
158
|
+
const onlyConflict = preview({ sections: [{ id: 'settings', decision: 'conflict', conflictCount: 1, conflicts: [] }] })
|
|
159
|
+
assert.equal(hasApplicableSections(onlyConflict), false, '未裁决的冲突 → 没有可应用内容')
|
|
160
|
+
|
|
161
|
+
// ---- issue #106 回归:0 可自动应用 + 全是冲突时,裁决完必须可为 ----
|
|
162
|
+
assert.equal(hasApplicableSections(onlyConflict, setSectionAction({}, 'settings', 'useRemote')), true, '已裁决 useRemote → 会写盘,必须可用')
|
|
163
|
+
assert.equal(hasApplicableSections(onlyConflict, setSectionAction({}, 'settings', 'keepLocal')), true, '已裁决 keepLocal → 会写盘,必须可用')
|
|
164
|
+
assert.equal(hasApplicableSections(onlyConflict, setSectionAction({}, 'other', 'useRemote')), false, '草稿点的是别的分区 → 仍然禁用')
|
|
165
|
+
assert.equal(hasApplicableSections(onlyConflict, setSectionAction({}, 'settings', 'useMerged')), false, '冲突分区没有 merged 载荷 → 该裁决什么也不写')
|
|
166
|
+
const mergeable = preview({ sections: [{ id: 'settings', decision: 'merge', autoMerged: 2, conflictCount: 0, conflicts: [] }] })
|
|
167
|
+
assert.equal(hasApplicableSections(mergeable, setSectionAction({}, 'settings', 'useMerged')), true, '有 merged 载荷 → useMerged 会写盘')
|
|
168
|
+
// 批量「全部采用本机」会把 skip 分区也写进草稿,此时它同样会落盘
|
|
169
|
+
assert.equal(hasApplicableSections(onlySkip, setSectionAction({}, 'settings', 'keepLocal')), true)
|
|
170
|
+
assert.equal(decisionWillApply(mergeSectionRows(mergeable)[0]!, 'useMerged'), true)
|
|
171
|
+
assert.equal(decisionWillApply(mergeSectionRows(onlyConflict)[0]!, 'useMerged'), false)
|
|
172
|
+
assert.equal(decisionWillApply(mergeSectionRows(onlyConflict)[0]!, undefined), false)
|
|
173
|
+
})
|
|
174
|
+
|
|
175
|
+
test('merge-view: mergeDecisionCounts —— 待裁决覆盖 + 本次可应用分区数分别可数', () => {
|
|
176
|
+
const p = preview({
|
|
177
|
+
sections: [
|
|
178
|
+
{ id: 'settings', decision: 'conflict', conflictCount: 2, conflicts: [] },
|
|
179
|
+
{ id: 'mcp', decision: 'conflict', conflictCount: 1, conflicts: [] },
|
|
180
|
+
{ id: 'providers', decision: 'merge', autoMerged: 1, conflictCount: 0, conflicts: [] },
|
|
181
|
+
{ id: 'skills', decision: 'skip', conflictCount: 0, conflicts: [] },
|
|
182
|
+
],
|
|
183
|
+
})
|
|
184
|
+
const empty = mergeDecisionCounts(p, {})
|
|
185
|
+
assert.deepEqual(empty, { needsDecision: 2, decided: 0, undecided: 2, conflictItems: 3, applicable: 1 })
|
|
186
|
+
assert.deepEqual(
|
|
187
|
+
mergeDecisionCounts(p, setSectionAction({}, 'settings', 'useRemote')),
|
|
188
|
+
{ needsDecision: 2, decided: 1, undecided: 1, conflictItems: 3, applicable: 2 },
|
|
189
|
+
)
|
|
190
|
+
assert.deepEqual(
|
|
191
|
+
mergeDecisionCounts(p, setSectionAction(setSectionAction({}, 'settings', 'useRemote'), 'mcp', 'keepLocal')),
|
|
192
|
+
{ needsDecision: 2, decided: 2, undecided: 0, conflictItems: 3, applicable: 3 },
|
|
193
|
+
)
|
|
194
|
+
})
|
|
195
|
+
|
|
196
|
+
test('merge-view: mergeSummaryItems —— 缺字段按 0,绝不 undefined', () => {
|
|
197
|
+
assert.deepEqual(mergeSummaryItems(null), [
|
|
198
|
+
{ labelKey: 'merge.summary.auto', value: 0, tone: 'ok' },
|
|
199
|
+
{ labelKey: 'merge.summary.review', value: 0, tone: 'warn' },
|
|
200
|
+
{ labelKey: 'merge.summary.conflicts', value: 0, tone: 'warn' },
|
|
201
|
+
{ labelKey: 'merge.summary.skipped', value: 0, tone: 'info' },
|
|
202
|
+
])
|
|
203
|
+
assert.equal(mergeSummaryItems(preview({ summary: { auto: 1, review: 2, conflicts: 3, skipped: 4 } }))[2]!.value, 3)
|
|
204
|
+
})
|
|
205
|
+
|
|
206
|
+
test('merge-view: mergeResultView —— pendingConflicts 必须暴露出来(跳过 ≠ 已解决)', () => {
|
|
207
|
+
assert.equal(mergeResultView(null), null)
|
|
208
|
+
const v = mergeResultView({
|
|
209
|
+
ok: false,
|
|
210
|
+
applied: ['settings'],
|
|
211
|
+
skipped: ['mcp'],
|
|
212
|
+
warnings: ['w'],
|
|
213
|
+
restoreId: '',
|
|
214
|
+
rolledBack: true,
|
|
215
|
+
pendingConflicts: ['mcp'],
|
|
216
|
+
failed: [{ itemId: 'x' }],
|
|
217
|
+
ineffective: [{ itemId: 'y', adapter: 'z' }],
|
|
218
|
+
})!
|
|
219
|
+
assert.equal(v.restoreId, null, '空串 restoreId 不当作可回滚')
|
|
220
|
+
assert.equal(v.rollbackFull, null, '旧宿主缺 rollbackFull 不得当成「完整」')
|
|
221
|
+
assert.equal(v.hasPendingConflicts, true)
|
|
222
|
+
assert.deepEqual(v.pendingConflicts, ['mcp'])
|
|
223
|
+
assert.equal(v.failedCount, 1)
|
|
224
|
+
assert.equal(v.ineffectiveCount, 1)
|
|
225
|
+
assert.equal(v.rolledBack, true)
|
|
226
|
+
})
|
|
227
|
+
|
|
228
|
+
test('merge-view: decideSyncEntry —— 无基准/预览失败一律回退老路径(fail-safe),全 skip 视为已最新', () => {
|
|
229
|
+
const sec = (decision: MergeSectionDecision): MergePreviewSection => ({ id: 'settings', decision, conflictCount: 0, conflicts: [] })
|
|
230
|
+
const ok = (sections: MergePreviewSection[]): Pick<MergePreviewResponse, 'ok' | 'sections'> => ({ ok: true, sections })
|
|
231
|
+
assert.equal(decideSyncEntry(undefined, null), 'fallback', '缺省(旧宿主)= 未知 → 老路径')
|
|
232
|
+
assert.equal(decideSyncEntry(false, null), 'fallback')
|
|
233
|
+
assert.equal(decideSyncEntry('true', null), 'fallback', '非布尔 true 一律回退')
|
|
234
|
+
assert.equal(decideSyncEntry(true, null), 'fallback', '预览缺失 → 老路径')
|
|
235
|
+
assert.equal(decideSyncEntry(true, { ok: false, sections: [] }), 'fallback', '宿主明确未产出 → 老路径')
|
|
236
|
+
assert.equal(decideSyncEntry(true, ok([])), 'upToDate', '无分区 = 无差异')
|
|
237
|
+
assert.equal(decideSyncEntry(true, ok([sec('skip'), sec('skip')])), 'upToDate', '全 skip = 已是最新')
|
|
238
|
+
assert.equal(decideSyncEntry(true, ok([sec('skip'), sec('conflict')])), 'merge')
|
|
239
|
+
assert.equal(decideSyncEntry(true, ok([sec('merge')])), 'merge')
|
|
240
|
+
// 宿主未来版本可能回传新决策值:类型上不可能,运行时必须 fail-closed(用 cast 模拟线上数据)
|
|
241
|
+
assert.equal(decideSyncEntry(true, ok([sec('brand-new' as MergeSectionDecision)])), 'merge', '未知决策 fail-closed 归入需裁决')
|
|
242
|
+
})
|
|
243
|
+
|
|
244
|
+
test('merge-view: needsNoAncestorNotice —— hasAncestor=false 才提示,null 预览不提示', () => {
|
|
245
|
+
assert.equal(needsNoAncestorNotice(null), false)
|
|
246
|
+
assert.equal(needsNoAncestorNotice(preview({ hasAncestor: true })), false)
|
|
247
|
+
assert.equal(needsNoAncestorNotice(preview({ hasAncestor: false })), true)
|
|
248
|
+
})
|