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.
- package/README.md +10 -0
- package/README.zh-CN.md +10 -0
- package/lib/adapters/mcp.d.ts +9 -0
- package/lib/adapters/mcp.js +37 -0
- package/lib/adapters/plugins.js +10 -2
- package/lib/adapters/pnpm-workspace.js +1 -1
- package/lib/adapters/self.d.ts +2 -0
- package/lib/adapters/self.js +18 -2
- package/lib/adapters/workspaces.js +1 -1
- package/lib/cli/restore-resume.js +1 -1
- package/lib/cli/web/page.js +2 -2
- package/lib/client.d.ts +17 -41
- package/lib/client.js +946 -761
- package/lib/core/backup.d.ts +11 -0
- package/lib/core/backup.js +27 -0
- package/lib/core/env-lock-lifecycle.d.ts +17 -3
- package/lib/core/env-lock-lifecycle.js +38 -0
- package/lib/core/external-failure.d.ts +9 -0
- package/lib/core/external-failure.js +50 -0
- package/lib/core/local-plugin-host.d.ts +9 -7
- package/lib/core/local-plugin-host.js +109 -15
- package/lib/core/local-plugin-pack.d.ts +20 -0
- package/lib/core/local-plugin-pack.js +18 -3
- package/lib/core/mcp-connector-store.d.ts +13 -0
- package/lib/core/mcp-connector-store.js +16 -1
- package/lib/core/messages-core.d.ts +45 -0
- package/lib/core/messages-core.js +92 -0
- package/lib/core/messages.d.ts +5 -0
- package/lib/core/messages.js +14 -0
- package/lib/core/migration-history.d.ts +40 -0
- package/lib/core/migration-history.js +55 -0
- package/lib/core/model-tool-plans.d.ts +66 -0
- package/lib/core/model-tool-plans.js +128 -0
- package/lib/core/model-tools.d.ts +96 -8
- package/lib/core/model-tools.js +568 -31
- package/lib/core/phase3-host.js +10 -2
- package/lib/core/plugin-cli.d.ts +5 -0
- package/lib/core/plugin-cli.js +11 -3
- package/lib/core/plugin-data-registry.d.ts +1 -1
- package/lib/core/plugin-data-registry.js +1 -1
- package/lib/core/restore-plan-fingerprint.d.ts +2 -0
- package/lib/core/restore-plan-fingerprint.js +18 -0
- package/lib/core/restore-resume.d.ts +1 -1
- package/lib/core/restore-resume.js +1 -1
- package/lib/core/restore.d.ts +5 -0
- package/lib/core/restore.js +4 -1
- package/lib/core/types.d.ts +12 -0
- package/lib/foreign/claude-sessions.d.ts +1 -1
- package/lib/foreign/claude-sessions.js +1 -1
- package/lib/foreign/registry.js +1 -1
- package/lib/foreign/types.d.ts +1 -1
- package/lib/index.d.ts +19 -15
- package/lib/index.js +72 -80
- package/lib/market/git-file-writer.js +1 -1
- package/lib/market/github-repos.js +1 -1
- package/lib/market/market-config.js +1 -1
- package/lib/market/messages-market.js +1 -1
- package/lib/market/my-repo.js +1 -1
- package/lib/market/prepare.js +1 -1
- package/lib/market/reader.js +2 -2
- package/lib/market/repo-url.d.ts +1 -1
- package/lib/market/security.js +2 -2
- package/lib/market/star-cache.d.ts +1 -1
- package/lib/market/types.d.ts +1 -1
- package/lib/market/types.js +1 -1
- package/lib/market/url.js +1 -1
- package/lib/profiles/dsh-profile-manager.d.ts +1 -1
- package/lib/profiles/dsh-profile-manager.js +26 -7
- package/lib/profiles/dsh-profile-shared.d.ts +3 -1
- package/lib/routes/backup.js +17 -9
- package/lib/routes/index.d.ts +1 -1
- package/lib/routes/kit.d.ts +2 -2
- package/lib/routes/market.d.ts +1 -1
- package/lib/routes/market.js +3 -60
- package/lib/routes/model-tools-deps.d.ts +41 -0
- package/lib/routes/model-tools-deps.js +18 -0
- package/lib/routes/recovery.js +5 -3
- package/lib/routes/route-support.d.ts +18 -26
- package/lib/routes/route-support.js +19 -32
- package/lib/routes/snapshots.d.ts +1 -1
- package/lib/routes/snapshots.js +4 -40
- package/lib/routes/sync.js +40 -28
- package/lib/schema/index.d.ts +2 -2
- package/lib/schema/index.js +2 -2
- package/lib/schema/section-registry.d.ts +5 -3
- package/lib/schema/section-registry.js +7 -3
- package/lib/security/secret-scanner.js +1 -1
- package/lib/sync/apply-bundle.d.ts +50 -0
- package/lib/sync/apply-bundle.js +60 -0
- package/lib/sync/autosync-scheduler.d.ts +9 -0
- package/lib/sync/autosync-scheduler.js +118 -89
- package/lib/sync/backup-scheduler.js +5 -4
- package/lib/sync/blob-store.d.ts +2 -2
- package/lib/sync/git/git-transport.d.ts +12 -0
- package/lib/sync/git/git-transport.js +50 -2
- package/lib/sync/merge.d.ts +2 -0
- package/lib/sync/merge.js +28 -0
- package/lib/sync/messages.d.ts +4 -0
- package/lib/sync/messages.js +9 -2
- package/lib/sync/s3/s3-transport.d.ts +1 -1
- package/lib/sync/s3/s3-transport.js +1 -1
- package/lib/sync/sync-engine.d.ts +4 -4
- package/lib/sync/sync-engine.js +25 -26
- package/lib/sync/sync-scope-boot.d.ts +34 -0
- package/lib/sync/sync-scope-boot.js +71 -0
- package/lib/sync/sync-scope.d.ts +103 -0
- package/lib/sync/sync-scope.js +229 -0
- package/lib/sync/sync-selection.d.ts +17 -4
- package/lib/sync/sync-selection.js +40 -14
- package/lib/sync/transport.d.ts +4 -1
- package/lib/sync/transport.js +6 -0
- package/lib/sync/webdav/webdav-transport.js +1 -1
- package/lib/sync/workspace-merge.d.ts +36 -0
- package/lib/sync/workspace-merge.js +152 -0
- package/lib/ui/backup-schedule.d.ts +13 -2
- package/lib/ui/backup-schedule.js +3 -0
- package/lib/ui/snapshots-view.d.ts +16 -0
- package/lib/ui/snapshots-view.js +21 -0
- package/lib/ui/sync-repository-picker.d.ts +21 -0
- package/lib/ui/sync-repository-picker.js +18 -0
- package/lib/utils/env-lock.d.ts +96 -0
- package/lib/utils/env-lock.js +332 -111
- package/lib/utils/messages-utils.d.ts +6 -0
- package/lib/utils/messages-utils.js +17 -1
- package/lib/utils/patch-yaml.js +1 -1
- package/lib/utils/remove-tree.d.ts +7 -0
- package/lib/utils/remove-tree.js +265 -0
- package/lib/utils/zip.js +1 -1
- package/package.json +3 -2
- package/src/adapters/mcp.test.ts +28 -0
- package/src/adapters/mcp.ts +33 -0
- package/src/adapters/plugins.test.ts +49 -0
- package/src/adapters/plugins.ts +9 -1
- package/src/adapters/pnpm-workspace.ts +1 -1
- package/src/adapters/self.test.ts +39 -1
- package/src/adapters/self.ts +20 -2
- package/src/adapters/workspaces.ts +1 -1
- package/src/cli/restore-resume.ts +1 -1
- package/src/cli/web/page.ts +2 -2
- package/src/client/about/AboutPanel.tsx +1 -1
- package/src/client/about/about-view.test.ts +1 -1
- package/src/client/about/about-view.ts +1 -1
- package/src/client/api.ts +1 -6
- package/src/client/chat/chat-entry-view.test.ts +1 -1
- package/src/client/chat/chat-slots.ts +1 -1
- package/src/client/chat/rollback-diff-tab.ts +1 -1
- package/src/client/client-types.ts +1 -1
- package/src/client/common/routes.ts +1 -5
- package/src/client/config-manager.module.css +21 -1
- package/src/client/css-scale-guard.test.ts +1 -1
- package/src/client/environment/EnvironmentPanel.tsx +2 -2
- package/src/client/home/HomePanel.tsx +3 -0
- package/src/client/library/ArtifactRow.tsx +14 -2
- package/src/client/library/LibraryPanel.tsx +44 -0
- package/src/client/locales/overview.ts +10 -2
- package/src/client/locales/profiles.ts +2 -0
- package/src/client/locales/sessions.ts +3 -0
- package/src/client/market/MyConfigsView.tsx +1 -1
- package/src/client/market/market-api.ts +2 -14
- package/src/client/market/market-locales.ts +1 -1
- package/src/client/market/market-view.ts +3 -3
- package/src/client/market/my-configs-api.ts +1 -1
- package/src/client/market/my-configs-view.ts +1 -1
- package/src/client/recovery/recovery-locales.test.ts +1 -1
- package/src/client/run-store.ts +1 -1
- package/src/client/sync/ChannelConfigDialog.tsx +32 -1
- package/src/client/sync/SyncPanel.tsx +11 -30
- package/src/client/sync/SyncRepositoryPicker.tsx +34 -13
- package/src/client/sync/SyncSectionPickerDialog.tsx +0 -5
- package/src/client/sync/SyncSettingsView.test.ts +32 -0
- package/src/client/sync/config-save-state.test.ts +99 -0
- package/src/client/sync/config-save-state.ts +69 -0
- package/src/client/sync/history-model.test.ts +28 -7
- package/src/client/sync/history-model.ts +6 -3
- package/src/client/sync/sync-locales.ts +14 -4
- package/src/client/sync/sync-view.ts +1 -1
- package/src/core/analyzer-cache.test.ts +1 -1
- package/src/core/backup.test.ts +45 -1
- package/src/core/backup.ts +25 -0
- package/src/core/disk-usage.test.ts +2 -0
- package/src/core/engine-locale.test.ts +4 -0
- package/src/core/env-lock-lifecycle.ts +33 -3
- package/src/core/external-failure.test.ts +60 -0
- package/src/core/external-failure.ts +54 -0
- package/src/core/integrity-extra-entries.test.ts +1 -1
- package/src/core/local-plugin-host.test.ts +134 -0
- package/src/core/local-plugin-host.ts +122 -17
- package/src/core/local-plugin-pack.ts +39 -3
- package/src/core/mcp-connector-store.ts +26 -1
- package/src/core/messages-core.ts +94 -0
- package/src/core/messages.ts +14 -0
- package/src/core/migration-history.test.ts +65 -0
- package/src/core/migration-history.ts +70 -0
- package/src/core/model-tool-plans.test.ts +111 -0
- package/src/core/model-tool-plans.ts +170 -0
- package/src/core/model-tools.test.ts +212 -12
- package/src/core/model-tools.ts +710 -38
- package/src/core/phase3-host.ts +10 -2
- package/src/core/phase3-production-integration.test.ts +43 -0
- package/src/core/plugin-cli.fs.test.ts +30 -3
- package/src/core/plugin-cli.ts +11 -3
- package/src/core/plugin-data-registry.ts +1 -1
- package/src/core/restore-plan-fingerprint.ts +19 -0
- package/src/core/restore-resume.ts +1 -1
- package/src/core/restore.ts +9 -1
- package/src/core/types.ts +12 -0
- package/src/foreign/claude-sessions.ts +3 -3
- package/src/foreign/registry.ts +1 -1
- package/src/foreign/types.ts +1 -1
- package/src/index.ts +102 -111
- package/src/market/git-file-writer.ts +1 -1
- package/src/market/github-repos.test.ts +1 -1
- package/src/market/github-repos.ts +1 -1
- package/src/market/market-config.ts +1 -1
- package/src/market/messages-market.ts +1 -1
- package/src/market/my-repo.test.ts +1 -1
- package/src/market/my-repo.ts +1 -1
- package/src/market/prepare.test.ts +1 -1
- package/src/market/prepare.ts +1 -1
- package/src/market/reader.ts +2 -2
- package/src/market/repo-url.ts +1 -1
- package/src/market/security.ts +2 -2
- package/src/market/star-cache.ts +1 -1
- package/src/market/types.ts +1 -1
- package/src/market/url.test.ts +1 -1
- package/src/market/url.ts +1 -1
- package/src/profiles/dsh-profile-copy-rollback.test.ts +1 -1
- package/src/profiles/dsh-profile-manager.test.ts +20 -0
- package/src/profiles/dsh-profile-manager.ts +25 -7
- package/src/profiles/dsh-profile-shared.ts +2 -0
- package/src/routes/backup.ts +16 -9
- package/src/routes/index.ts +1 -1
- package/src/routes/kit.ts +2 -2
- package/src/routes/market.ts +2 -59
- package/src/routes/model-tools-deps.ts +56 -0
- package/src/routes/recovery.ts +5 -3
- package/src/routes/route-support.ts +49 -36
- package/src/routes/snapshots.ts +4 -40
- package/src/routes/sync.ts +39 -27
- package/src/schema/index.ts +2 -2
- package/src/schema/manifest-schema.test.ts +2 -2
- package/src/schema/registry.test.ts +1 -1
- package/src/schema/section-registry.ts +9 -4
- package/src/security/redaction.test.ts +1 -1
- package/src/security/secret-scanner.test.ts +2 -2
- package/src/security/secret-scanner.ts +1 -1
- package/src/sync/apply-bundle.ts +104 -0
- package/src/sync/autosync-scheduler.test.ts +180 -6
- package/src/sync/autosync-scheduler.ts +132 -92
- package/src/sync/backup-scheduler.test.ts +11 -4
- package/src/sync/backup-scheduler.ts +5 -4
- package/src/sync/blob-store.ts +2 -2
- package/src/sync/git/git-transport.test.ts +62 -0
- package/src/sync/git/git-transport.ts +54 -3
- package/src/sync/merge.ts +29 -0
- package/src/sync/messages.ts +9 -2
- package/src/sync/s3/s3-transport.ts +1 -1
- package/src/sync/sync-engine.test.ts +238 -2
- package/src/sync/sync-engine.ts +25 -26
- package/src/sync/sync-preview-push.test.ts +2 -1
- package/src/sync/sync-scope-boot.ts +87 -0
- package/src/sync/sync-scope.test.ts +154 -0
- package/src/sync/sync-scope.ts +256 -0
- package/src/sync/sync-selection.test.ts +76 -2
- package/src/sync/sync-selection.ts +40 -13
- package/src/sync/transport.test.ts +21 -1
- package/src/sync/transport.ts +12 -0
- package/src/sync/webdav/webdav-delete-index-unreadable.test.ts +2 -2
- package/src/sync/webdav/webdav-transport.ts +1 -1
- package/src/sync/workspace-merge.test.ts +110 -0
- package/src/sync/workspace-merge.ts +180 -0
- package/src/ui/backup-schedule.test.ts +5 -0
- package/src/ui/backup-schedule.ts +21 -2
- package/src/ui/session-issue-labels.ts +1 -1
- package/src/ui/snapshots-view.test.ts +32 -0
- package/src/ui/snapshots-view.ts +34 -0
- package/src/ui/sync-repository-picker.test.ts +34 -1
- package/src/ui/sync-repository-picker.ts +24 -0
- package/src/utils/env-lock.test.ts +242 -9
- package/src/utils/env-lock.ts +247 -13
- package/src/utils/messages-utils.ts +17 -1
- package/src/utils/patch-yaml.ts +1 -1
- package/src/utils/remove-tree.test.ts +120 -0
- package/src/utils/remove-tree.ts +239 -0
- package/src/utils/zip.ts +1 -1
- package/src/client/CLIENT_DEPENDENCIES.md +0 -94
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* src/utils/** 的领域消息目录(zh 源语言 / en 镜像)——「英文界面零中文」迁移(t5)。
|
|
3
3
|
*
|
|
4
|
-
* 口径(与 src/core/messages.ts 一致,见 docs/
|
|
4
|
+
* 口径(与 src/core/messages.ts 一致,见 docs/archive/2026-10-08-i18n-en-hardcoding.md):
|
|
5
5
|
* - zh 值 = 迁移前的既有中文文案**逐字不变**(既有测试断言依赖它,只允许新增 en);
|
|
6
6
|
* - en 值类型为 Record<keyof typeof zh, string> —— 缺键/多键即编译错误;
|
|
7
7
|
* - 动态明细一律走 {param} 插值传参,不得丢信息;
|
|
@@ -68,6 +68,7 @@ export const zh = {
|
|
|
68
68
|
'utils.envLock.heartbeatExpiredNoIdentity': 'heartbeat 过期且 pid={pid} 存活,但无法可靠取得 OS process identity,保守拒绝删除',
|
|
69
69
|
'utils.envLock.pidReuse': 'pid reuse:pid={pid} identity 与 recorded 不同',
|
|
70
70
|
'utils.envLock.ownerAliveDegraded': 'owner 进程存活(heartbeat 可能 degraded),非 stale',
|
|
71
|
+
'utils.envLock.ownerAliveHeartbeatStopped': 'owner pid={pid} 进程存活且进程身份一致,但 heartbeat {longExpired} → 判定为残留锁(写方已停摆),可显式回收',
|
|
71
72
|
'utils.envLock.notStaleRefuseRecovery': '非 stale,拒绝 recovery',
|
|
72
73
|
'utils.envLock.ownershipGone': 'ownership 已消失(被他人接管/清除),停止 recovery',
|
|
73
74
|
'utils.envLock.captureRenameFailed': '捕获 rename 失败(可能被他人接管),停止',
|
|
@@ -86,6 +87,9 @@ export const zh = {
|
|
|
86
87
|
'utils.envLock.durationMinutes': '{value} 分钟',
|
|
87
88
|
'utils.envLock.durationSeconds': '{value} 秒',
|
|
88
89
|
'utils.envLock.ioPermissionNotLock': '{what}: 权限/ACL 错误 ({code}),非锁占用',
|
|
90
|
+
'utils.envLock.heartbeatWriteFailed': '环境锁心跳写入失败: {reason}',
|
|
91
|
+
'utils.envLock.releaseFailedQuarantined': '环境锁释放失败,已把 ownership 挪到 recovering 解除阻塞: {reason}',
|
|
92
|
+
'utils.envLock.releaseFailedStuck': '环境锁释放失败,且无法挪走 ownership(后续操作会被判为锁被占用): {reason}',
|
|
89
93
|
// ---------- utils/env-lock.ts:锁被挡时给用户的分类文案(长 / 短两套,同源同分类) ----------
|
|
90
94
|
'utils.envLock.block.locked': '另一个任务正在运行,请稍后重试。',
|
|
91
95
|
'utils.envLock.block.blocked': '配置修改已被保护,请先处理恢复事项后再继续。',
|
|
@@ -93,10 +97,14 @@ export const zh = {
|
|
|
93
97
|
'utils.envLock.block.stale': '检测到上次异常退出残留的配置锁(其持有进程已不存在),操作已被阻止。'
|
|
94
98
|
+ '该锁不会自动清除,重试或重启 DSH 均无效:请在「事故恢复」中点击「回收残留锁」,'
|
|
95
99
|
+ '或运行 dsh-config-manager recover-stale-lock 回收后再重试。',
|
|
100
|
+
'utils.envLock.block.staleDegraded': '检测到残留的配置锁:其记录中的进程仍在运行,但心跳已长期停止,说明上次释放没有完成。'
|
|
101
|
+
+ '操作已被阻止,重试或重启 DSH 都不会自愈:请在「事故恢复」中点击「回收残留锁」,'
|
|
102
|
+
+ '或运行 dsh-config-manager recover-stale-lock 回收后再重试。',
|
|
96
103
|
'utils.envLock.brief.locked': '环境锁被另一项任务占用',
|
|
97
104
|
'utils.envLock.brief.blocked': '配置修改已被保护,需先处理恢复事项',
|
|
98
105
|
'utils.envLock.brief.unavailable': '环境锁暂时不可用',
|
|
99
106
|
'utils.envLock.brief.stale': '残留配置锁(持有进程已不存在),需先回收',
|
|
107
|
+
'utils.envLock.brief.staleDegraded': '残留配置锁(心跳已长期停止),需先回收',
|
|
100
108
|
// ---------- utils/proxy.ts:代理隧道(保留原文的双语形态,zh 逐字不变) ----------
|
|
101
109
|
'utils.proxy.connectTimeout': '代理连接超时 / proxy connect timed out ({ms}ms)',
|
|
102
110
|
'utils.proxy.malformedConnectResponse': '代理 CONNECT 响应异常(头部过长)/ malformed CONNECT response',
|
|
@@ -167,6 +175,7 @@ export const en = {
|
|
|
167
175
|
'utils.envLock.heartbeatExpiredNoIdentity': 'heartbeat expired and pid={pid} is alive, but the OS process identity cannot be obtained reliably — conservatively refusing to delete',
|
|
168
176
|
'utils.envLock.pidReuse': 'pid reuse: pid={pid} identity differs from the recorded one',
|
|
169
177
|
'utils.envLock.ownerAliveDegraded': 'owner process is alive (heartbeat may be degraded), not stale',
|
|
178
|
+
'utils.envLock.ownerAliveHeartbeatStopped': 'owner pid={pid} is alive and its process identity matches, but heartbeat {longExpired} → judged a stale lock (the writer stopped), explicit reclaim allowed',
|
|
170
179
|
'utils.envLock.notStaleRefuseRecovery': 'not stale — refusing recovery',
|
|
171
180
|
'utils.envLock.ownershipGone': 'ownership has disappeared (taken over/cleared by someone else) — stopping recovery',
|
|
172
181
|
'utils.envLock.captureRenameFailed': 'capture rename failed (possibly taken over by someone else) — stopping',
|
|
@@ -185,16 +194,23 @@ export const en = {
|
|
|
185
194
|
'utils.envLock.durationMinutes': '{value} minutes',
|
|
186
195
|
'utils.envLock.durationSeconds': '{value} seconds',
|
|
187
196
|
'utils.envLock.ioPermissionNotLock': '{what}: permission/ACL error ({code}), not lock contention',
|
|
197
|
+
'utils.envLock.heartbeatWriteFailed': 'Environment lock heartbeat write failed: {reason}',
|
|
198
|
+
'utils.envLock.releaseFailedQuarantined': 'Environment lock release failed; the ownership file was moved to recovering so writes are no longer blocked: {reason}',
|
|
199
|
+
'utils.envLock.releaseFailedStuck': 'Environment lock release failed and the ownership file could not be moved aside (later operations will look lock-blocked): {reason}',
|
|
188
200
|
'utils.envLock.block.locked': 'Another task is running, please retry later.',
|
|
189
201
|
'utils.envLock.block.blocked': 'Configuration changes are protected — resolve the recovery items before continuing.',
|
|
190
202
|
'utils.envLock.block.unavailable': 'The operation cannot run right now, please retry later; if it keeps failing, check the logs.',
|
|
191
203
|
'utils.envLock.block.stale': 'A configuration lock left behind by a previous abnormal exit was detected (its owning process no longer exists), so the operation was blocked.'
|
|
192
204
|
+ 'This lock will not clear itself — retrying or restarting DSH will not help: click "Reclaim stale lock" under "Incident recovery",'
|
|
193
205
|
+ 'or run dsh-config-manager recover-stale-lock and then retry.',
|
|
206
|
+
'utils.envLock.block.staleDegraded': 'A leftover configuration lock was detected: its recorded process is still running, but its heartbeat stopped long ago, so the last release never finished.'
|
|
207
|
+
+ 'The operation was blocked, and retrying or restarting DSH will not clear it: click "Reclaim stale lock" under "Incident recovery",'
|
|
208
|
+
+ 'or run dsh-config-manager recover-stale-lock and then retry.',
|
|
194
209
|
'utils.envLock.brief.locked': 'Environment lock held by another task',
|
|
195
210
|
'utils.envLock.brief.blocked': 'Configuration changes are protected; resolve recovery items first',
|
|
196
211
|
'utils.envLock.brief.unavailable': 'Environment lock temporarily unavailable',
|
|
197
212
|
'utils.envLock.brief.stale': 'Stale configuration lock (owning process is gone); reclaim it first',
|
|
213
|
+
'utils.envLock.brief.staleDegraded': 'Stale configuration lock (heartbeat stopped long ago); reclaim it first',
|
|
198
214
|
// ---------- utils/proxy.ts ----------
|
|
199
215
|
'utils.proxy.connectTimeout': 'Proxy connection timed out ({ms}ms)',
|
|
200
216
|
'utils.proxy.malformedConnectResponse': 'Malformed proxy CONNECT response (headers too long)',
|
package/lib/utils/patch-yaml.js
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
* 调用方若把它 catch 成「这一层没有 patch 行」,用户手写的整层配置就会在导出/同步/预览里凭空消失;
|
|
12
12
|
* 导入写回时更会把整份文件重写成「只剩本次导入的行」—— 这正是 issue #75 报告的数据丢失。
|
|
13
13
|
*
|
|
14
|
-
* 两个形状与 DSH 逐字对齐(**改这里等于改对外契约**,见 `docs/
|
|
14
|
+
* 两个形状与 DSH 逐字对齐(**改这里等于改对外契约**,见 `docs/contracts/bundle-format-v1.md`):
|
|
15
15
|
* - 载入:`!!js <源码>` → `{ __jsExpr: <源码> }`
|
|
16
16
|
* - 写回:`{ __jsExpr: <源码> }` → `!!js <源码>`
|
|
17
17
|
* 判据与 cordis 的 `isJsExpr`(`value instanceof Object && '__jsExpr' in value`)一致,于是 bundle 里
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 同步严格删除:目标不存在算成功;链接只删链接本身;删不掉抛底层错误;
|
|
3
|
+
* 结束时目标**仍然存在**也抛错(rm 静默失效的兜底判据)。
|
|
4
|
+
*/
|
|
5
|
+
export declare function removeTreeSync(target: string): void;
|
|
6
|
+
/** 异步版本(大批量目录不阻塞事件循环);语义与 removeTreeSync 完全一致。 */
|
|
7
|
+
export declare function removeTree(target: string): Promise<void>;
|
|
@@ -0,0 +1,265 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 严格递归删除 —— 覆盖 `fs.rm(dir, { recursive: true, force: true })` 的**静默失效**。
|
|
3
|
+
*
|
|
4
|
+
* 实测(Node 24 / Windows,本仓 0.5.0):目录里只要有一个**悬空链接**(junction / 符号链接的
|
|
5
|
+
* 重指向目标已被删掉),`fs.rmSync(dir, { recursive: true, force: true })` 既不抛错、也不删任何东西
|
|
6
|
+
* —— 1 ms 内返回,目录原样留在磁盘上。用户点「删除档案」,插件回「已删除档案 X」,磁盘上一点没动。
|
|
7
|
+
*
|
|
8
|
+
* 悬空链接不是畸形数据,而是 DSH 自己会造出来的形态:档案的 `node_modules/<pkg>` 是指向
|
|
9
|
+
* `.dsh-module-fallback/node_modules/<pkg>` 的 junction,fallback 目录随宿主升级/重建消失后,
|
|
10
|
+
* 这些链接就全部悬空(实测某档案 20 个)。所以删除必须走通这种树,且**删完必须复核**。
|
|
11
|
+
*
|
|
12
|
+
* 本模块的语义:
|
|
13
|
+
* - 不用 rm 的目录遍历:自己 readdir + lstat 逐条走;**链接只删链接本身**,绝不跟随进 pnpm store;
|
|
14
|
+
* - 列表里有、lstat 读不到的条目(并发删除 / 悬空链接在个别平台上的形态)→ 直接尝试 unlink;
|
|
15
|
+
* - 只读文件 / 只读目录 / 被杀软或索引占用的条目 → 改权限 + 有界退避重试;
|
|
16
|
+
* - 结束后**复核目标不存在**,还在就抛错 —— 绝不把「什么都没删」当成成功。
|
|
17
|
+
*/
|
|
18
|
+
import { chmodSync, existsSync, lstatSync, readdirSync, rmdirSync, unlinkSync } from 'node:fs';
|
|
19
|
+
import { chmod, lstat, readdir, rmdir, unlink } from 'node:fs/promises';
|
|
20
|
+
import { join } from 'node:path';
|
|
21
|
+
/** 单个条目的删除重试次数(Windows 上半途的 AV 扫描 / 索引句柄会让 unlink 短暂 EBUSY)。 */
|
|
22
|
+
const MAX_ATTEMPTS = 4;
|
|
23
|
+
/** 首次退避毫秒(之后每次翻倍)。 */
|
|
24
|
+
const BASE_DELAY_MS = 20;
|
|
25
|
+
/** 值得重试的错误码:只读属性 / 被占用 / 目录已被别人删空一半。 */
|
|
26
|
+
const RETRYABLE = new Set(['EBUSY', 'EPERM', 'EACCES', 'ENOTEMPTY', 'EMFILE']);
|
|
27
|
+
function errorCode(error) {
|
|
28
|
+
return error?.code;
|
|
29
|
+
}
|
|
30
|
+
/** 同步退避:用 Atomics.wait 而不是忙等自旋(与 utils/atomic-write.ts 同做法)。 */
|
|
31
|
+
function busyWait(ms) {
|
|
32
|
+
const ia = new Int32Array(new SharedArrayBuffer(4));
|
|
33
|
+
try {
|
|
34
|
+
Atomics.wait(ia, 0, 0, ms);
|
|
35
|
+
}
|
|
36
|
+
catch {
|
|
37
|
+
/* SharedArrayBuffer 不可用:退化为不等待(少见) */
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
function sleep(ms) {
|
|
41
|
+
return new Promise((resolve) => { setTimeout(resolve, ms); });
|
|
42
|
+
}
|
|
43
|
+
/** lstat:ENOENT 返回 null(真的没了),其它错误照抛(读不到 ≠ 不存在)。 */
|
|
44
|
+
function lstatSyncOrNull(path) {
|
|
45
|
+
try {
|
|
46
|
+
return lstatSync(path);
|
|
47
|
+
}
|
|
48
|
+
catch (error) {
|
|
49
|
+
if (errorCode(error) === 'ENOENT')
|
|
50
|
+
return null;
|
|
51
|
+
throw error;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
async function lstatOrNull(path) {
|
|
55
|
+
try {
|
|
56
|
+
return await lstat(path);
|
|
57
|
+
}
|
|
58
|
+
catch (error) {
|
|
59
|
+
if (errorCode(error) === 'ENOENT')
|
|
60
|
+
return null;
|
|
61
|
+
throw error;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
/** 删一个**非目录**条目(文件 / 符号链接 / junction);悬空链接只能走这条路。 */
|
|
65
|
+
function unlinkSyncOrRetry(path) {
|
|
66
|
+
let delay = BASE_DELAY_MS;
|
|
67
|
+
for (let attempt = 0;; attempt++) {
|
|
68
|
+
try {
|
|
69
|
+
unlinkSync(path);
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
catch (error) {
|
|
73
|
+
const code = errorCode(error);
|
|
74
|
+
if (code === 'ENOENT')
|
|
75
|
+
return;
|
|
76
|
+
if (attempt >= MAX_ATTEMPTS || code === undefined || !RETRYABLE.has(code))
|
|
77
|
+
throw error;
|
|
78
|
+
// EPERM 在 Windows 上多为「只读属性」:先摘掉只读再重试
|
|
79
|
+
if (code === 'EPERM' || code === 'EACCES') {
|
|
80
|
+
try {
|
|
81
|
+
chmodSync(path, 0o666);
|
|
82
|
+
}
|
|
83
|
+
catch { /* 目标已消失 / 无权限:交给下一轮重试 */ }
|
|
84
|
+
}
|
|
85
|
+
busyWait(delay);
|
|
86
|
+
delay *= 2;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
async function unlinkOrRetry(path) {
|
|
91
|
+
let delay = BASE_DELAY_MS;
|
|
92
|
+
for (let attempt = 0;; attempt++) {
|
|
93
|
+
try {
|
|
94
|
+
await unlink(path);
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
catch (error) {
|
|
98
|
+
const code = errorCode(error);
|
|
99
|
+
if (code === 'ENOENT')
|
|
100
|
+
return;
|
|
101
|
+
if (attempt >= MAX_ATTEMPTS || code === undefined || !RETRYABLE.has(code))
|
|
102
|
+
throw error;
|
|
103
|
+
if (code === 'EPERM' || code === 'EACCES') {
|
|
104
|
+
try {
|
|
105
|
+
await chmod(path, 0o666);
|
|
106
|
+
}
|
|
107
|
+
catch { /* 同上 */ }
|
|
108
|
+
}
|
|
109
|
+
await sleep(delay);
|
|
110
|
+
delay *= 2;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
/** 删空目录(调用前子项已删净);ENOTEMPTY 说明有人在并发写入 → 有界重试。 */
|
|
115
|
+
function rmdirSyncOrRetry(path) {
|
|
116
|
+
let delay = BASE_DELAY_MS;
|
|
117
|
+
for (let attempt = 0;; attempt++) {
|
|
118
|
+
try {
|
|
119
|
+
rmdirSync(path);
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
catch (error) {
|
|
123
|
+
const code = errorCode(error);
|
|
124
|
+
if (code === 'ENOENT')
|
|
125
|
+
return;
|
|
126
|
+
if (attempt >= MAX_ATTEMPTS || code === undefined || !RETRYABLE.has(code))
|
|
127
|
+
throw error;
|
|
128
|
+
if (code === 'EPERM' || code === 'EACCES') {
|
|
129
|
+
try {
|
|
130
|
+
chmodSync(path, 0o777);
|
|
131
|
+
}
|
|
132
|
+
catch { /* 同上 */ }
|
|
133
|
+
}
|
|
134
|
+
busyWait(delay);
|
|
135
|
+
delay *= 2;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
async function rmdirOrRetry(path) {
|
|
140
|
+
let delay = BASE_DELAY_MS;
|
|
141
|
+
for (let attempt = 0;; attempt++) {
|
|
142
|
+
try {
|
|
143
|
+
await rmdir(path);
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
catch (error) {
|
|
147
|
+
const code = errorCode(error);
|
|
148
|
+
if (code === 'ENOENT')
|
|
149
|
+
return;
|
|
150
|
+
if (attempt >= MAX_ATTEMPTS || code === undefined || !RETRYABLE.has(code))
|
|
151
|
+
throw error;
|
|
152
|
+
if (code === 'EPERM' || code === 'EACCES') {
|
|
153
|
+
try {
|
|
154
|
+
await chmod(path, 0o777);
|
|
155
|
+
}
|
|
156
|
+
catch { /* 同上 */ }
|
|
157
|
+
}
|
|
158
|
+
await sleep(delay);
|
|
159
|
+
delay *= 2;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
/** 目录在遍历途中消失 → 返回空(随后 rmdir 得到 ENOENT 并被吞掉)。 */
|
|
164
|
+
function readdirSafe(dir) {
|
|
165
|
+
try {
|
|
166
|
+
return readdirSync(dir, { withFileTypes: true });
|
|
167
|
+
}
|
|
168
|
+
catch (error) {
|
|
169
|
+
if (errorCode(error) === 'ENOENT')
|
|
170
|
+
return [];
|
|
171
|
+
throw error;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
async function readdirSafeAsync(dir) {
|
|
175
|
+
try {
|
|
176
|
+
return await readdir(dir, { withFileTypes: true });
|
|
177
|
+
}
|
|
178
|
+
catch (error) {
|
|
179
|
+
if (errorCode(error) === 'ENOENT')
|
|
180
|
+
return [];
|
|
181
|
+
throw error;
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
/** 无异常版本的「还在不在」:任何 stat 错误都当作还在,交给最终复核报错。 */
|
|
185
|
+
function stillExists(path) {
|
|
186
|
+
try {
|
|
187
|
+
lstatSync(path);
|
|
188
|
+
return true;
|
|
189
|
+
}
|
|
190
|
+
catch {
|
|
191
|
+
return existsSync(path);
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* 删掉一个节点(文件 / 链接 / 目录,目录连自身一起删)。
|
|
196
|
+
* 判据用 lstat:junction 在 Windows 上 isSymbolicLink()=true → 走 unlink,绝不跟进目标。
|
|
197
|
+
*/
|
|
198
|
+
function removeNodeSync(target) {
|
|
199
|
+
const stat = lstatSyncOrNull(target);
|
|
200
|
+
if (stat === null)
|
|
201
|
+
return;
|
|
202
|
+
if (!stat.isDirectory() || stat.isSymbolicLink()) {
|
|
203
|
+
unlinkSyncOrRetry(target);
|
|
204
|
+
return;
|
|
205
|
+
}
|
|
206
|
+
for (const entry of readdirSafe(target))
|
|
207
|
+
removeChildSync(target, entry);
|
|
208
|
+
rmdirSyncOrRetry(target);
|
|
209
|
+
}
|
|
210
|
+
async function removeNode(target) {
|
|
211
|
+
const stat = await lstatOrNull(target);
|
|
212
|
+
if (stat === null)
|
|
213
|
+
return;
|
|
214
|
+
if (!stat.isDirectory() || stat.isSymbolicLink()) {
|
|
215
|
+
await unlinkOrRetry(target);
|
|
216
|
+
return;
|
|
217
|
+
}
|
|
218
|
+
for (const entry of await readdirSafeAsync(target))
|
|
219
|
+
await removeChild(target, entry);
|
|
220
|
+
await rmdirOrRetry(target);
|
|
221
|
+
}
|
|
222
|
+
function removeChildSync(dir, entry) {
|
|
223
|
+
const child = join(dir, entry.name);
|
|
224
|
+
try {
|
|
225
|
+
// dirent 对悬空链接的 isDirectory() 各平台不一致:类型只认 lstat
|
|
226
|
+
lstatSync(child);
|
|
227
|
+
}
|
|
228
|
+
catch (error) {
|
|
229
|
+
if (errorCode(error) === 'ENOENT')
|
|
230
|
+
return;
|
|
231
|
+
// 读不到类型(锁 / 权限):按「非目录」尝试删;删不掉就把真实错误抛出去
|
|
232
|
+
unlinkSyncOrRetry(child);
|
|
233
|
+
return;
|
|
234
|
+
}
|
|
235
|
+
removeNodeSync(child);
|
|
236
|
+
}
|
|
237
|
+
async function removeChild(dir, entry) {
|
|
238
|
+
const child = join(dir, entry.name);
|
|
239
|
+
try {
|
|
240
|
+
await lstat(child);
|
|
241
|
+
}
|
|
242
|
+
catch (error) {
|
|
243
|
+
if (errorCode(error) === 'ENOENT')
|
|
244
|
+
return;
|
|
245
|
+
await unlinkOrRetry(child);
|
|
246
|
+
return;
|
|
247
|
+
}
|
|
248
|
+
await removeNode(child);
|
|
249
|
+
}
|
|
250
|
+
/**
|
|
251
|
+
* 同步严格删除:目标不存在算成功;链接只删链接本身;删不掉抛底层错误;
|
|
252
|
+
* 结束时目标**仍然存在**也抛错(rm 静默失效的兜底判据)。
|
|
253
|
+
*/
|
|
254
|
+
export function removeTreeSync(target) {
|
|
255
|
+
removeNodeSync(target);
|
|
256
|
+
if (stillExists(target))
|
|
257
|
+
throw new Error(`removeTreeSync: target still exists after removal: ${target}`);
|
|
258
|
+
}
|
|
259
|
+
/** 异步版本(大批量目录不阻塞事件循环);语义与 removeTreeSync 完全一致。 */
|
|
260
|
+
export async function removeTree(target) {
|
|
261
|
+
await removeNode(target);
|
|
262
|
+
if (stillExists(target))
|
|
263
|
+
throw new Error(`removeTree: target still exists after removal: ${target}`);
|
|
264
|
+
}
|
|
265
|
+
//# sourceMappingURL=remove-tree.js.map
|
package/lib/utils/zip.js
CHANGED
|
@@ -84,7 +84,7 @@ export function assertZipEntryCount(count, limits = {}) {
|
|
|
84
84
|
}
|
|
85
85
|
/* ---------------- 写出侧布局片段(zipToBuffer 与 writeZip 共用,避免两份布局漂移) ----------------
|
|
86
86
|
* 三条 helper 的字段写入顺序与取值**必须与历史 zipToBuffer 逐字一致** —— 产物格式是对外契约
|
|
87
|
-
* (docs/
|
|
87
|
+
* (docs/contracts/bundle-format-v1.md),zip.test.ts 有一条「zipToBuffer 与 writeZip 产物等价」的用例钉住。 */
|
|
88
88
|
/** 本地文件头(30 字节;不含紧随其后的文件名与压缩数据)。 */
|
|
89
89
|
function buildLocalHeader(nameLen, crc, compressedSize, size, time, date) {
|
|
90
90
|
const local = Buffer.alloc(30);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-config-manager",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "Backup, restore, export, import, migrate and sync your DeepSeek Harness (DSH) configuration: settings, plugins, MCP servers, skills, agent presets and workspaces. One-click migration to another machine. DSH 配置一键备份、恢复、导出、导入、迁移与同步插件。",
|
|
6
6
|
"icon": "./icon.svg",
|
|
@@ -84,6 +84,7 @@
|
|
|
84
84
|
"test": "node --test \"src/**/*.test.ts\" \"tests/**/*.test.ts\"",
|
|
85
85
|
"smoke": "node --test src/core/smoke.test.ts",
|
|
86
86
|
"oss:check": "node scripts/oss-live-check.mjs",
|
|
87
|
+
"readme:stars": "node scripts/star-history.mjs",
|
|
87
88
|
"typecheck": "tsc --noEmit",
|
|
88
89
|
"typecheck:tests": "tsc -p tsconfig.tests.json --noEmit",
|
|
89
90
|
"build": "tsc -p tsconfig.build.json && tsdown",
|
|
@@ -203,7 +204,7 @@
|
|
|
203
204
|
"react": "^18.3.1",
|
|
204
205
|
"react-dom": "^18.3.1",
|
|
205
206
|
"schemastery": "^3.18.0",
|
|
206
|
-
"tsdown": "0.23.
|
|
207
|
+
"tsdown": "0.23.5",
|
|
207
208
|
"typescript": "^7.0.2"
|
|
208
209
|
}
|
|
209
210
|
}
|
package/src/adapters/mcp.test.ts
CHANGED
|
@@ -89,6 +89,34 @@ test('mcp: export 提取 + analyzeImport Create/Skip/Conflict + applyItem 写 pa
|
|
|
89
89
|
assert.deepEqual((raw['config'] as Record<string, unknown>)['args'], ['-y', 'x'], 'Conflict useImported 应更新目标行');
|
|
90
90
|
});
|
|
91
91
|
|
|
92
|
+
test('同步判定前提:mcp 导出字节必须可复现 —— 载荷里不得含「导出当刻」的时间戳', async () => {
|
|
93
|
+
// 为什么钉这条:SyncEngine.hasLocalChanges 直接 hashSection(export()),基线也取自同一份载荷;
|
|
94
|
+
// 载荷里只要有 now(),hash 每次都不同 ⇒ 每轮轮询都判「有改动」⇒ 真推一次空快照(AGENTS.md 同步节)。
|
|
95
|
+
const ctx = makeContext('win32', 'C:\\Users\\alice');
|
|
96
|
+
ctx.patchFile.lines.set('mcp-fs', {
|
|
97
|
+
lineId: 'mcp-fs',
|
|
98
|
+
raw: { id: 'mcp-fs', name: 'dsh-mcp-client', config: { serverName: 'filesystem', command: 'npx', args: ['-y', 'x'] } },
|
|
99
|
+
});
|
|
100
|
+
await ctx.fs.writeFile('storages/mcp_connector.json', new TextEncoder().encode(JSON.stringify({
|
|
101
|
+
tables: {
|
|
102
|
+
connections: {
|
|
103
|
+
citra: {
|
|
104
|
+
key: 'citra', connectorId: 'citra', kind: 'manual', name: 'Citra',
|
|
105
|
+
serverName: 'citra', transport: 'stdio', command: 'npx', args: ['-y', '@sylphx/citra'], enabled: true,
|
|
106
|
+
},
|
|
107
|
+
},
|
|
108
|
+
},
|
|
109
|
+
})));
|
|
110
|
+
const adapter = new McpAdapter();
|
|
111
|
+
const first = await adapter.export(ctx, { includeSecrets: false });
|
|
112
|
+
await new Promise((resolve) => { setTimeout(resolve, 25); });
|
|
113
|
+
const second = await adapter.export(ctx, { includeSecrets: false });
|
|
114
|
+
assert.deepEqual(
|
|
115
|
+
second.data, first.data,
|
|
116
|
+
'同一份本地状态两次导出必须逐字节一致(否则同步判定恒为「有改动」)',
|
|
117
|
+
);
|
|
118
|
+
});
|
|
119
|
+
|
|
92
120
|
test('issue #71: profile 层 MCP 行也要导出,且写回**原层**(不再凭空消失 / 不搬家)', async () => {
|
|
93
121
|
const src = makeContext('win32', 'C:\\Users\\alice', 'tauri');
|
|
94
122
|
// 真机形态:MCP server 由手写/工具写进 profile 层(home 层只有别的行)
|
package/src/adapters/mcp.ts
CHANGED
|
@@ -83,6 +83,39 @@ export function extractMcpServers(lines: { lineId: string; raw: unknown; file?:
|
|
|
83
83
|
return servers;
|
|
84
84
|
}
|
|
85
85
|
|
|
86
|
+
/**
|
|
87
|
+
* 反向操作:从一行 patch 里剔除 MCP 服务器条目(plugins 分区导出时用,2026-11「C8」)。
|
|
88
|
+
*
|
|
89
|
+
* 为什么需要:`cordis.patch.yml` 是一本**清单**,plugins 分区导出整本带走,于是「没勾 MCP
|
|
90
|
+
* 连接器」也会把 dsh-mcp-client 行(command/args/env + 本机 cwd)推到远端 —— 违反
|
|
91
|
+
* 「未勾选分区的数据不进推送」。判定必须与 extractMcpServers 完全同口径(config.serverName
|
|
92
|
+
* 为非空字符串),否则两边会漂。返回 undefined = 该行只剩 MCP 条目,整行丢弃。
|
|
93
|
+
*/
|
|
94
|
+
export function stripMcpEntries(raw: unknown): unknown | undefined {
|
|
95
|
+
if (raw === null || typeof raw !== 'object') return raw;
|
|
96
|
+
const obj = raw as Record<string, unknown>;
|
|
97
|
+
if (Array.isArray(obj['insert'])) {
|
|
98
|
+
const before = obj['insert'] as unknown[];
|
|
99
|
+
const kept = before.filter((e) => !isMcpEntry(e));
|
|
100
|
+
if (kept.length === before.length) return raw;
|
|
101
|
+
if (kept.length === 0) return undefined;
|
|
102
|
+
return { ...obj, insert: kept };
|
|
103
|
+
}
|
|
104
|
+
// 非 entry 形态(插件配置行 / 禁用行等)原样保留:只有 entriesOf 认得的行才可能是 MCP 行
|
|
105
|
+
const single = entriesOf(raw);
|
|
106
|
+
if (single.length === 0) return raw;
|
|
107
|
+
return isMcpEntry(single[0]) ? undefined : raw;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/** 单个 patch entry 是否是 MCP 服务器行(与 extractMcpServers 的判定同口径) */
|
|
111
|
+
function isMcpEntry(entry: unknown): boolean {
|
|
112
|
+
if (entry === null || typeof entry !== 'object') return false;
|
|
113
|
+
const config = (entry as Record<string, unknown>)['config'];
|
|
114
|
+
if (config === null || typeof config !== 'object') return false;
|
|
115
|
+
const serverName = (config as Record<string, unknown>)['serverName'];
|
|
116
|
+
return typeof serverName === 'string' && serverName !== '';
|
|
117
|
+
}
|
|
118
|
+
|
|
86
119
|
/** patch 行 → 可枚举的 entry 列表(兼容单行与 insert 块) */
|
|
87
120
|
function entriesOf(raw: unknown): { id?: unknown; name?: unknown; config?: unknown }[] {
|
|
88
121
|
if (raw === null || typeof raw !== 'object') return [];
|
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
import test from 'node:test';
|
|
6
6
|
import assert from 'node:assert/strict';
|
|
7
7
|
import { PluginsAdapter } from './plugins.ts';
|
|
8
|
+
import { McpAdapter } from './mcp.ts';
|
|
8
9
|
import { makeContext, makeImportContext } from './test-helpers.ts';
|
|
9
10
|
import { PLUGIN_PROFILE_MANIFEST_REF } from '../core/backup.ts';
|
|
10
11
|
import type { PluginsSection } from '../schema/types.ts';
|
|
@@ -216,6 +217,53 @@ test('issue #71: plugins 导出同时收集两层 patch 行(此前只读 home
|
|
|
216
217
|
assert.equal(dst.patchFile.lines.has('mnemon-strategy-a'), false, '不得搬到 home 层');
|
|
217
218
|
});
|
|
218
219
|
|
|
220
|
+
/**
|
|
221
|
+
* C8(2026-11):`cordis.patch.yml` 是一本清单,plugins 导出曾整本带走 —— 没勾「MCP 连接器」时
|
|
222
|
+
* dsh-mcp-client 行(command/args/env + 本机 cwd)照样上远端。用户选定语义:只带非 MCP 行,
|
|
223
|
+
* MCP 行由 mcp 分区负责(勾了才走)。判定必须与 mcp 适配器同口径,否则两边漂。
|
|
224
|
+
*/
|
|
225
|
+
test('C8: 未勾选 MCP 时 plugins 载荷不带 MCP patch 行;勾了仍由 mcp 分区带走', async () => {
|
|
226
|
+
const src = makeContext('win32', 'C:\\Users\\alice', 'web');
|
|
227
|
+
src.patchFile.lines.set('skill-badge', { lineId: 'skill-badge', raw: { id: 'skill-badge', disabled: true } });
|
|
228
|
+
// 真机形态:MCP 行由 DSH 的 MCP 工具写进 profile 层,config 里带本机 cwd
|
|
229
|
+
src.patchFile.bucket('profiles/web/cordis.patch.yml').set('mcp-citra', {
|
|
230
|
+
lineId: 'mcp-citra',
|
|
231
|
+
raw: {
|
|
232
|
+
id: 'mcp-citra',
|
|
233
|
+
name: 'dsh-mcp-client',
|
|
234
|
+
config: { serverName: 'citra', command: 'npx', args: ['-y', '@sylphx/citra'], cwd: 'C:\\Users\\alice\\proj' },
|
|
235
|
+
},
|
|
236
|
+
});
|
|
237
|
+
// 块形态混排:只剔 MCP 条目,绝不整块丢(否则连带丢掉同块里的用户行)
|
|
238
|
+
src.patchFile.lines.set('mixed', {
|
|
239
|
+
lineId: 'mixed',
|
|
240
|
+
raw: {
|
|
241
|
+
insert: [
|
|
242
|
+
{ id: 'mcp-mixed', name: 'dsh-mcp-client', config: { serverName: 'mixed', command: 'node' } },
|
|
243
|
+
{ id: 'plain-row', name: '@x/y', disabled: true },
|
|
244
|
+
],
|
|
245
|
+
},
|
|
246
|
+
});
|
|
247
|
+
|
|
248
|
+
const pluginsOut = await new PluginsAdapter().export(src, { includeSecrets: false });
|
|
249
|
+
const ids = pluginsOut.data.patch.map((p) => p.lineId);
|
|
250
|
+
assert.ok(!ids.includes('mcp-citra'), 'MCP 行不得进 plugins 载荷: ' + ids.join(','));
|
|
251
|
+
assert.ok(ids.includes('skill-badge'), '非 MCP 行必须保留: ' + ids.join(','));
|
|
252
|
+
const mixed = pluginsOut.data.patch.find((p) => p.lineId === 'mixed');
|
|
253
|
+
const keptInsert = (mixed?.raw as { insert: { id: string }[] }).insert.map((e) => e.id);
|
|
254
|
+
assert.deepEqual(keptInsert, ['plain-row'], '块里只剔 MCP 条目,其余原样保留');
|
|
255
|
+
const payload = JSON.stringify(pluginsOut.data);
|
|
256
|
+
assert.ok(!payload.includes('serverName'), 'MCP 服务器定义不得出现在 plugins 载荷里');
|
|
257
|
+
assert.ok(!payload.includes('alice'), '本机 cwd 不得出现在 plugins 载荷里');
|
|
258
|
+
|
|
259
|
+
// 勾了 mcp:同样的行仍由 mcp 分区带走(剔的是重复来源,不是数据)
|
|
260
|
+
const mcpOut = await new McpAdapter().export(src, { includeSecrets: false });
|
|
261
|
+
assert.deepEqual(
|
|
262
|
+
mcpOut.data.servers.map((s) => s.serverName).sort(), ['citra', 'mixed'],
|
|
263
|
+
'mcp 分区仍完整导出这些服务器: ' + mcpOut.data.servers.map((s) => s.serverName).join(','),
|
|
264
|
+
);
|
|
265
|
+
});
|
|
266
|
+
|
|
219
267
|
test('plugins: 导出携带 pnpm-workspace.yaml;analyze 目标无文件 → Create', async () => {
|
|
220
268
|
const src = makeContext('win32', 'C:\\Users\\alice', 'web');
|
|
221
269
|
await src.fs.writeFile('profiles/web/pnpm-workspace.yaml', new TextEncoder().encode('allowBuilds:\n ssh2: true\n'));
|
|
@@ -422,6 +470,7 @@ test('plugins: preview 不调用打包钩子,但条目/白名单/告警与 exp
|
|
|
422
470
|
}],
|
|
423
471
|
rewritten: { 'local-pkg': packedSpec },
|
|
424
472
|
warnings: [],
|
|
473
|
+
oversize: [],
|
|
425
474
|
};
|
|
426
475
|
});
|
|
427
476
|
|
package/src/adapters/plugins.ts
CHANGED
|
@@ -24,6 +24,7 @@ import { isPathSafe, normalizePath } from '../utils/paths.ts';
|
|
|
24
24
|
import { isENOENT } from '../utils/guards.ts';
|
|
25
25
|
import { PLUGIN_PATCH_REF_PREFIX, PLUGIN_PROFILE_MANIFEST_REF } from '../core/backup.ts';
|
|
26
26
|
import { readEffectivePatchLines, resolveWriteLayer, USER_PATCH_FILE } from '../core/patch-layers.ts';
|
|
27
|
+
import { stripMcpEntries } from './mcp.ts';
|
|
27
28
|
import {
|
|
28
29
|
parsePnpmPatchedDependencies, restorePnpmMachinePaths, sanitizePnpmWorkspacePatches, stripPnpmMachinePaths,
|
|
29
30
|
} from './pnpm-workspace.ts';
|
|
@@ -431,7 +432,14 @@ export class PluginsAdapter implements ConfigAdapter<PluginsSection> {
|
|
|
431
432
|
// issue #71:patch 有两层(home 层 + profile 层),只读 home 层会漏掉 DSH 工具与 marketplace
|
|
432
433
|
// 写入 profile 层的激活行 —— 导出少了它们,导入到新机就少一批插件加载项。
|
|
433
434
|
const patchRead = await readEffectivePatchLines(ctx.patchFile, ctx.profile);
|
|
434
|
-
for (const l of patchRead.lines)
|
|
435
|
+
for (const l of patchRead.lines) {
|
|
436
|
+
// MCP 行不进 plugins 载荷(2026-11「C8」,用户选择「只带非 MCP 行」):它是 mcp 分区的
|
|
437
|
+
// 数据源,随 plugins 整本带走会让「没勾 MCP 连接器」也把服务器定义与本机 cwd 推到远端。
|
|
438
|
+
// 判定与 mcp 适配器同口径(stripMcpEntries);勾了 mcp 时这些行仍由 mcp 分区带走。
|
|
439
|
+
const raw = stripMcpEntries(l.raw);
|
|
440
|
+
if (raw === undefined) continue;
|
|
441
|
+
patch.push({ file: l.file, lineId: l.lineId, raw });
|
|
442
|
+
}
|
|
435
443
|
for (const f of patchRead.failures) {
|
|
436
444
|
warnings.push(msgOf(ctx)('adapter.patchReadFailed', { reason: `${f.file}: ${f.reason}` }));
|
|
437
445
|
}
|
|
@@ -162,7 +162,7 @@ export function sanitizePnpmWorkspacePatches(
|
|
|
162
162
|
* 2. 写回时把**目标机自己原有的**那几行接回去:不搬运来源机的路径,也不清掉本机自己的设置。
|
|
163
163
|
*
|
|
164
164
|
* `.npmrc` 刻意**不进同步面**(见 plugins.ts 的说明):纳入它会改变 bundle 载荷形态
|
|
165
|
-
* (docs/
|
|
165
|
+
* (docs/contracts/bundle-format-v1.md + conformance),而本机 .npmrc 从来就不由本插件写 ——
|
|
166
166
|
* 「不碰 = 本机保留」。
|
|
167
167
|
* ------------------------------------------------------------------ */
|
|
168
168
|
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
import test from 'node:test';
|
|
12
12
|
import assert from 'node:assert/strict';
|
|
13
13
|
import { createAdapters } from './index.ts';
|
|
14
|
-
import { SelfAdapter, SELF_CONFIG_FILES, SELF_IMPORT_BLOCKED_RELS, SELF_IMPORT_BLOCKED_CODE } from './self.ts';
|
|
14
|
+
import { SelfAdapter, SELF_CONFIG_FILES, SELF_IMPORT_BLOCKED_RELS, SELF_IMPORT_BLOCKED_CODE, isSelfImportBlocked } from './self.ts';
|
|
15
15
|
import { hashSection } from '../sync/sync-state.ts';
|
|
16
16
|
import { sha256Hex } from '../utils/hashing.ts';
|
|
17
17
|
import { makeContext, makeImportContext } from './test-helpers.ts';
|
|
@@ -131,6 +131,44 @@ test('SEC-01:包内含 sync-config.json / sync-autosync.json → 报告级 war
|
|
|
131
131
|
assert.equal(await dst.fs.exists('dsh-config-manager/sync/sync-autosync.json'), false, '不得凭空创建同步调度配置');
|
|
132
132
|
});
|
|
133
133
|
|
|
134
|
+
test('SEC-01:分档案作用域 sync-profiles/<p>/ 的同步目标同样拦截(按模式,不按清单)', async () => {
|
|
135
|
+
// 判据:档案名是运行时集合,列举不出来 —— 所以按目录模式判,两种形态必须一致
|
|
136
|
+
for (const rel of [
|
|
137
|
+
'sync-profiles/Test1/sync-config.json',
|
|
138
|
+
'sync-profiles/Test1/sync-autosync.json',
|
|
139
|
+
'sync-profiles/open-design/sync-config.json',
|
|
140
|
+
'sync/sync-config.json',
|
|
141
|
+
'sync/sync-autosync.json',
|
|
142
|
+
]) {
|
|
143
|
+
assert.equal(isSelfImportBlocked(rel), true, '必须拦下: ' + rel);
|
|
144
|
+
}
|
|
145
|
+
// 不误伤:同目录里的选择/偏好/运行态不是「同步目标」,白名单外也不该被本判据报成安全事件
|
|
146
|
+
for (const rel of [
|
|
147
|
+
'sync-profiles/Test1/sync-selection.json',
|
|
148
|
+
'sync-profiles/Test1/ui-prefs.json',
|
|
149
|
+
'sync-profiles/Test1/sync-state.json',
|
|
150
|
+
'sync-profiles/nested/deep/sync-config.json',
|
|
151
|
+
'sync/sync-selection.json',
|
|
152
|
+
]) {
|
|
153
|
+
assert.equal(isSelfImportBlocked(rel), false, '不该拦: ' + rel);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
// 计划阶段:包内带分档案同步目标 → 改判 Warning(去掉 target ⇒ 引擎不写盘、不进快照范围)
|
|
157
|
+
const adapter = new SelfAdapter();
|
|
158
|
+
const evil = '{"schemaVersion":3,"transport":"git","git":{"repoUrl":"https://attacker.example/collect.git"}}';
|
|
159
|
+
const relativePath = 'sync-profiles/Test1/sync-config.json';
|
|
160
|
+
const section = {
|
|
161
|
+
version: 1 as const,
|
|
162
|
+
files: [{ relativePath, data: Buffer.from(evil, 'utf8'), contentHash: sha256Hex(Buffer.from(evil, 'utf8')) }],
|
|
163
|
+
};
|
|
164
|
+
const dst = makeContext('linux', '/home/bob');
|
|
165
|
+
const items = await adapter.analyzeImport(section, makeImportContext(dst, new Map([['self', section]])));
|
|
166
|
+
assert.equal(items.length, 1);
|
|
167
|
+
assert.equal(items[0]?.kind, 'Warning');
|
|
168
|
+
assert.ok(String(items[0]?.detail ?? '').startsWith(SELF_IMPORT_BLOCKED_CODE));
|
|
169
|
+
assert.equal(await dst.fs.exists('dsh-config-manager/' + relativePath), false, '包内地址不得落地');
|
|
170
|
+
});
|
|
171
|
+
|
|
134
172
|
test('createAdapters: selfDir 缺省挂载 dsh-config-manager;空串不挂载', () => {
|
|
135
173
|
const withSelf = createAdapters({ selfDir: undefined });
|
|
136
174
|
assert.ok(withSelf.some((a) => a.id === 'self'), '缺省挂载 self adapter');
|