dsh-config-manager 0.7.0 → 0.8.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/lib/adapters/test-helpers.d.ts +7 -0
- package/lib/adapters/test-helpers.js +11 -0
- package/lib/cli/actions.js +1 -1
- package/lib/client.d.ts +9 -2
- package/lib/client.js +685 -649
- package/lib/core/backup.d.ts +9 -1
- package/lib/core/backup.js +21 -0
- package/lib/core/messages-core.d.ts +3 -0
- package/lib/core/messages-core.js +6 -0
- package/lib/core/messages.d.ts +5 -0
- package/lib/core/messages.js +10 -0
- package/lib/core/model-tools.js +2 -0
- package/lib/core/phase4-crash-child.js +1 -1
- package/lib/core/plugin-cli.d.ts +11 -0
- package/lib/core/plugin-cli.js +30 -0
- package/lib/core/restore-wal.d.ts +2 -0
- package/lib/core/restore-wal.js +11 -6
- package/lib/core/restore.d.ts +15 -2
- package/lib/core/restore.js +65 -3
- package/lib/core/snapshot-diff.js +2 -1
- package/lib/core/types.d.ts +32 -0
- package/lib/index.d.ts +6 -1
- package/lib/index.js +17 -16
- package/lib/routes/route-support.d.ts +5 -0
- package/lib/routes/route-support.js +28 -2
- package/lib/routes/sync.js +3 -0
- package/lib/sync/merge-preview-view.d.ts +78 -0
- package/lib/sync/merge-preview-view.js +46 -0
- package/lib/sync/merge.d.ts +2 -1
- package/lib/sync/merge.js +9 -4
- package/lib/sync/plugin-removal-apply.d.ts +95 -0
- package/lib/sync/plugin-removal-apply.js +158 -0
- package/lib/sync/plugin-removals.d.ts +90 -0
- package/lib/sync/plugin-removals.js +167 -0
- package/lib/sync/sync-engine.d.ts +34 -43
- package/lib/sync/sync-engine.js +50 -42
- package/lib/sync/sync-selection.d.ts +8 -0
- package/lib/sync/sync-selection.js +6 -0
- package/lib/sync/workspace-merge.d.ts +8 -1
- package/lib/ui/restore-plan-view.js +1 -0
- package/lib/ui/sync-settings-view.d.ts +10 -0
- package/lib/ui/sync-settings-view.js +2 -0
- package/package.json +1 -1
- package/src/adapters/test-helpers.ts +10 -0
- package/src/cli/actions.ts +1 -1
- package/src/client/common/info-hint-guard.test.ts +2 -1
- package/src/client/run-store.test.ts +7 -5
- package/src/client/run-store.ts +4 -5
- package/src/client/sync/SyncPanel.tsx +10 -0
- package/src/client/sync/SyncSectionPickerDialog.tsx +17 -1
- package/src/client/sync/sync-locales.ts +4 -0
- package/src/client/sync/sync-view.ts +6 -0
- package/src/core/backup.ts +21 -1
- package/src/core/messages-core.ts +6 -0
- package/src/core/messages.ts +10 -0
- package/src/core/model-tools.ts +2 -0
- package/src/core/phase4-crash-child.ts +1 -1
- package/src/core/plugin-cli.ts +37 -0
- package/src/core/restore-plugin-install.test.ts +116 -0
- package/src/core/restore-wal.ts +12 -6
- package/src/core/restore.ts +79 -4
- package/src/core/smoke.test.ts +5 -0
- package/src/core/snapshot-diff.test.ts +1 -1
- package/src/core/snapshot-diff.ts +2 -1
- package/src/core/types.ts +31 -0
- package/src/index.ts +21 -21
- package/src/routes/route-support.ts +27 -2
- package/src/routes/sync.ts +3 -0
- package/src/security/security.test.ts +1 -0
- package/src/sync/merge-preview-view.ts +97 -0
- package/src/sync/merge.test.ts +17 -15
- package/src/sync/merge.ts +10 -3
- package/src/sync/plugin-removal-apply.ts +198 -0
- package/src/sync/plugin-removals.test.ts +221 -0
- package/src/sync/plugin-removals.ts +208 -0
- package/src/sync/sync-engine.test.ts +251 -1
- package/src/sync/sync-engine.ts +84 -83
- package/src/sync/sync-selection.test.ts +29 -7
- package/src/sync/sync-selection.ts +13 -0
- package/src/sync/workspace-merge.ts +9 -0
- package/src/ui/restore-plan-view.test.ts +1 -1
- package/src/ui/restore-plan-view.ts +1 -0
- package/src/ui/snapshots-view.test.ts +1 -1
- package/src/ui/sync-settings-view.test.ts +20 -0
- package/src/ui/sync-settings-view.ts +12 -0
|
@@ -1009,13 +1009,14 @@ test('低频面板: 同步/市场/快照切片与当前面板刷新往返恢复
|
|
|
1009
1009
|
createdAt: '2026-01-01T00:00:00Z',
|
|
1010
1010
|
sourceZip: 'x.zip',
|
|
1011
1011
|
actions: [],
|
|
1012
|
-
summary: { hostFileRestores: 0, hostFileRemoves: 0, pluginRemoves: 0, fileRestores: 0, fileRemoves: 0, credentialHints: 0, skips: 1 },
|
|
1012
|
+
summary: { hostFileRestores: 0, hostFileRemoves: 0, pluginRemoves: 0, pluginInstalls: 0, fileRestores: 0, fileRemoves: 0, credentialHints: 0, skips: 1 },
|
|
1013
1013
|
pluginBaselineConfirmed: true,
|
|
1014
1014
|
},
|
|
1015
1015
|
report: {
|
|
1016
1016
|
snapshotId: 'snap-1',
|
|
1017
1017
|
restored: ['settings.yaml'],
|
|
1018
1018
|
removedPlugins: [],
|
|
1019
|
+
installedPlugins: [],
|
|
1019
1020
|
manualHints: [],
|
|
1020
1021
|
failed: [],
|
|
1021
1022
|
skipped: [],
|
|
@@ -1223,6 +1224,7 @@ test('m2-resume: 活跃 restore run 经 /runs 恢复 running 并轮询到完成
|
|
|
1223
1224
|
snapshotId: 'snap-1',
|
|
1224
1225
|
restored: ['settings.yaml'],
|
|
1225
1226
|
removedPlugins: ['@scope/pkg'],
|
|
1227
|
+
installedPlugins: [],
|
|
1226
1228
|
manualHints: [],
|
|
1227
1229
|
failed: [],
|
|
1228
1230
|
skipped: [],
|
|
@@ -1519,7 +1521,7 @@ test('P0-9: 宿主载荷(plan/analysis/result/confirmSession/snapshots.plan/ma
|
|
|
1519
1521
|
detail: `MCP_TOKEN=${P0_9_SECRET}`, manualHint: `Authorization: Bearer ${P0_9_SECRET}`,
|
|
1520
1522
|
}],
|
|
1521
1523
|
summary: {
|
|
1522
|
-
hostFileRestores: 0, hostFileRemoves: 0, pluginRemoves: 0,
|
|
1524
|
+
hostFileRestores: 0, hostFileRemoves: 0, pluginRemoves: 0, pluginInstalls: 0,
|
|
1523
1525
|
fileRestores: 0, fileRemoves: 0, credentialHints: 1, skips: 0,
|
|
1524
1526
|
},
|
|
1525
1527
|
pluginBaselineConfirmed: true,
|
|
@@ -1617,9 +1619,9 @@ test('P0-9: 持久化字段清单显式化(键集合断言 —— 新增字段
|
|
|
1617
1619
|
'loadError', 'pullReport', 'pushPreview', 'pushReport', 'repoUrl', 'webdavUrl', 'webdavUsername',
|
|
1618
1620
|
])
|
|
1619
1621
|
assert.deepEqual(keys(p.sync.byChannel.git), [
|
|
1620
|
-
'autosync', 'autosyncEnabled', 'autosyncInterval', 'autosyncRealtime', '
|
|
1621
|
-
'loadingSnapshots', 'selectedSnapshotId', 'sessionsInclude', 'sessionsLimit',
|
|
1622
|
-
'syncMode', 'syncSections',
|
|
1622
|
+
'autosync', 'autosyncEnabled', 'autosyncInterval', 'autosyncRealtime', 'deletePlugins', 'encrypt',
|
|
1623
|
+
'includeSecrets', 'loadingSnapshots', 'selectedSnapshotId', 'sessionsInclude', 'sessionsLimit',
|
|
1624
|
+
'snapshots', 'syncMode', 'syncSections',
|
|
1623
1625
|
])
|
|
1624
1626
|
assert.deepEqual(keys(p.market), [
|
|
1625
1627
|
'category', 'conflictResolutions', 'detail', 'error', 'importResult', 'items', 'loadError',
|
package/src/client/run-store.ts
CHANGED
|
@@ -1035,16 +1035,14 @@ export function toPersistedState(state: StoreState): PersistedState {
|
|
|
1035
1035
|
syncMode: c.syncMode,
|
|
1036
1036
|
syncSections: [...c.syncSections],
|
|
1037
1037
|
sessionsLimit: c.sessionsLimit,
|
|
1038
|
-
//
|
|
1039
|
-
sessionsInclude: [...c.sessionsInclude],
|
|
1038
|
+
sessionsInclude: [...c.sessionsInclude], // 显式点名清单(非敏感;空 = 「最新 N 个」模式)
|
|
1040
1039
|
encrypt: c.encrypt,
|
|
1041
1040
|
includeSecrets: c.includeSecrets,
|
|
1041
|
+
deletePlugins: c.deletePlugins, // issue 132:用户配置、非敏感,必须落盘
|
|
1042
1042
|
selectedSnapshotId: c.selectedSnapshotId,
|
|
1043
1043
|
// 快照列表按值复制,避免落盘对象与运行时切片共享可变数组
|
|
1044
1044
|
snapshots: [...c.snapshots],
|
|
1045
|
-
// issue #59
|
|
1046
|
-
// (刷新/切 tab 后重新 list 会重新得到,落盘只会在远端恢复后留下陈旧告警)
|
|
1047
|
-
loadingSnapshots: c.loadingSnapshots === true,
|
|
1045
|
+
loadingSnapshots: c.loadingSnapshots === true, // issue #59:远端当下诊断,不落盘(落盘只会留下陈旧告警)
|
|
1048
1046
|
autosync: c.autosync,
|
|
1049
1047
|
autosyncEnabled: c.autosyncEnabled,
|
|
1050
1048
|
autosyncInterval: c.autosyncInterval,
|
|
@@ -1674,6 +1672,7 @@ export class RunStore {
|
|
|
1674
1672
|
sessionsInclude: [],
|
|
1675
1673
|
encrypt: legacySync['encrypt'] === true,
|
|
1676
1674
|
includeSecrets: legacySync['includeSecrets'] === true,
|
|
1675
|
+
deletePlugins: legacySync['deletePlugins'] === true, // 旧载荷无此字段 → 缺省关(破坏性操作必须显式开启)
|
|
1677
1676
|
selectedSnapshotId: typeof legacySync['selectedSnapshotId'] === 'string'
|
|
1678
1677
|
? legacySync['selectedSnapshotId']
|
|
1679
1678
|
: '',
|
|
@@ -132,6 +132,8 @@ interface SelectionPatch {
|
|
|
132
132
|
sessionsInclude?: string[]
|
|
133
133
|
encrypt?: boolean
|
|
134
134
|
includeSecrets?: boolean
|
|
135
|
+
/** 跟随远端删除插件(issue 132;破坏性,缺省关) */
|
|
136
|
+
deletePlugins?: boolean
|
|
135
137
|
/** 非空 = 写入本机凭据库(长期复用) */
|
|
136
138
|
encryptPassword?: string
|
|
137
139
|
decryptPassword?: string
|
|
@@ -969,6 +971,12 @@ export function SyncPanel({ api, t, cmT }: SyncPanelProps) {
|
|
|
969
971
|
void saveSelection(channel, linked.selectionPatch)
|
|
970
972
|
}
|
|
971
973
|
|
|
974
|
+
/** 「跟随远端删除插件」开关(issue 132;勾上 = 显式授权手动与自动都删,执行在宿主 applyMergePlan)。 */
|
|
975
|
+
const setDeletePlugins = (channel: SyncChannel, next: boolean): void => {
|
|
976
|
+
patchChannelOf(channel, { deletePlugins: next })
|
|
977
|
+
void saveSelection(channel, { deletePlugins: next })
|
|
978
|
+
}
|
|
979
|
+
|
|
972
980
|
/** 当前通道导出密钥开关(持久化)。勾选时自动联动选中加密(密钥绝不明文进同步通道)。 */
|
|
973
981
|
const setIncludeSecrets = (channel: SyncChannel, next: boolean): void => {
|
|
974
982
|
// t42:勾「导出密钥」自动打开加密(密钥绝不明文上行)——规则在 ui/sync-settings-view.ts
|
|
@@ -1430,12 +1438,14 @@ export function SyncPanel({ api, t, cmT }: SyncPanelProps) {
|
|
|
1430
1438
|
sections={chState.syncSections}
|
|
1431
1439
|
sessionsLimit={chState.sessionsLimit}
|
|
1432
1440
|
sessionsInclude={chState.sessionsInclude}
|
|
1441
|
+
deletePlugins={chState.deletePlugins}
|
|
1433
1442
|
sessionNode={sessionPickerNode}
|
|
1434
1443
|
sessionPending={sessionInvPending}
|
|
1435
1444
|
sessionFailed={sessionInvFailedRef.current}
|
|
1436
1445
|
onToggleSection={(id, checked) => { toggleSyncSection(state.channel, id, checked) }}
|
|
1437
1446
|
onSessionsLimit={(value) => { setSessionsLimit(state.channel, value) }}
|
|
1438
1447
|
onSessionsInclude={(ids) => { setSessionsInclude(state.channel, ids) }}
|
|
1448
|
+
onToggleDeletePlugins={(next) => { setDeletePlugins(state.channel, next) }}
|
|
1439
1449
|
onClose={() => { setSectionPickerOpen(false) }}
|
|
1440
1450
|
/>
|
|
1441
1451
|
{/* v3:页面级的加密/解密/快照列表卡已移入各自的通道卡(见 renderChannelCard)。 */}
|
|
@@ -32,7 +32,7 @@ import css from '../config-manager.module.css'
|
|
|
32
32
|
* (与导出选择器一致的弹窗语义),因此底部只有「完成」—— 没有「取消」
|
|
33
33
|
* (取消会让用户以为改动被丢弃)。
|
|
34
34
|
*/
|
|
35
|
-
export function SyncSectionPickerDialog({ open, t, cmT, uiT, sectionName, catalog, sections, sessionsLimit, sessionsInclude, sessionNode, sessionPending, sessionFailed, onToggleSection, onSessionsLimit, onSessionsInclude, onClose }: {
|
|
35
|
+
export function SyncSectionPickerDialog({ open, t, cmT, uiT, sectionName, catalog, sections, sessionsLimit, sessionsInclude, deletePlugins, sessionNode, sessionPending, sessionFailed, onToggleSection, onSessionsLimit, onSessionsInclude, onToggleDeletePlugins, onClose }: {
|
|
36
36
|
t: TranslateNS<'config-manager-sync'>
|
|
37
37
|
/** ui 命名空间的翻译器(UiT):分区描述与分组说明的**字典键**由它解析(英文界面零中文) */
|
|
38
38
|
uiT: UiT
|
|
@@ -45,6 +45,8 @@ export function SyncSectionPickerDialog({ open, t, cmT, uiT, sectionName, catalo
|
|
|
45
45
|
sessionsLimit: number
|
|
46
46
|
/** 显式点名的会话单元 id(非空时优先于 sessionsLimit) */
|
|
47
47
|
sessionsInclude: readonly string[]
|
|
48
|
+
/** 跟随远端删除插件(issue 132;只在 plugins 分区被勾选时可操作) */
|
|
49
|
+
deletePlugins: boolean
|
|
48
50
|
/** 会话单元清单(未取到 / 读取失败 → undefined) */
|
|
49
51
|
sessionNode: SelectionSection | undefined
|
|
50
52
|
sessionPending: boolean
|
|
@@ -53,6 +55,7 @@ export function SyncSectionPickerDialog({ open, t, cmT, uiT, sectionName, catalo
|
|
|
53
55
|
onSessionsLimit: (value: number) => void
|
|
54
56
|
/** 点名结果(空数组 = 回到「最新 N 个」模式) */
|
|
55
57
|
onSessionsInclude: (ids: string[]) => void
|
|
58
|
+
onToggleDeletePlugins: (next: boolean) => void
|
|
56
59
|
onClose: () => void
|
|
57
60
|
}) {
|
|
58
61
|
/** 弹窗内的两个视图:分区目录 / 会话逐项勾选(同一 Modal,不嵌套第二个遮罩) */
|
|
@@ -178,6 +181,19 @@ export function SyncSectionPickerDialog({ open, t, cmT, uiT, sectionName, catalo
|
|
|
178
181
|
</div>
|
|
179
182
|
</div>
|
|
180
183
|
)}
|
|
184
|
+
{/* issue 132:插件专属的「跟随远端删除」。放在 Checkbox **之外**(同 sessions
|
|
185
|
+
参数的理由:Checkbox 内部是 label,嵌进去点开关会连带切换分区勾选)。
|
|
186
|
+
只在 plugins 已被勾选时出现 —— 没勾这个分区,这条开关没有任何作用对象。 */}
|
|
187
|
+
{s.id === 'plugins' && sections.includes('plugins') && (
|
|
188
|
+
<div className={css.controlRow}>
|
|
189
|
+
<Checkbox
|
|
190
|
+
checked={deletePlugins}
|
|
191
|
+
onChange={onToggleDeletePlugins}
|
|
192
|
+
label={<span className={css.categoryName}>{t('mode.deletePlugins')}</span>}
|
|
193
|
+
/>
|
|
194
|
+
<InfoHint text={t('mode.deletePluginsHint')} label={t('common.infoHint')} />
|
|
195
|
+
</div>
|
|
196
|
+
)}
|
|
181
197
|
</div>
|
|
182
198
|
))}
|
|
183
199
|
</div>
|
|
@@ -187,6 +187,8 @@ export const zh = {
|
|
|
187
187
|
'mode.hint': '同步范围 = 勾选的分区集合(默认已勾选推荐分区,可随时改)。',
|
|
188
188
|
'mode.selectedCount': '已勾选 {n} / {total}',
|
|
189
189
|
'mode.sectionsHint': '默认可同步的是可移植分区;平台相关分区(MCP 服务器)与设备相关分区(插件文件、凭据状态、历史会话)只有你在这里主动勾选才参与同步。',
|
|
190
|
+
'mode.deletePlugins': '跟随远端删除插件',
|
|
191
|
+
'mode.deletePluginsHint': '远端快照里已经没有、本机也没改过的插件会被卸载(判断依据是共同祖先里还有它 —— 那只可能是别处删掉了)。卸载只发生在插件分区真正被应用的那一轮;失败逐项提示、其余同步照常完成。desktop 保留档案与宿主自己不会被删。',
|
|
190
192
|
'mode.atLeastOne': '请至少勾选一个同步分区',
|
|
191
193
|
'mode.sectionPortable': '可移植',
|
|
192
194
|
'mode.sectionRecommended': '推荐',
|
|
@@ -642,6 +644,8 @@ export const en: Record<keyof typeof zh, string> = {
|
|
|
642
644
|
'mode.hint': 'Sync scope = the ticked set of sections (recommended sections are ticked by default and can be changed any time).',
|
|
643
645
|
'mode.selectedCount': '{n} / {total} selected',
|
|
644
646
|
'mode.sectionsHint': 'Portable sections sync by default; platform-dependent sections (MCP servers) and device-specific sections (plugin files, credentials status, sessions) only participate when you explicitly tick them here.',
|
|
647
|
+
'mode.deletePlugins': 'Delete plugins to follow the remote',
|
|
648
|
+
'mode.deletePluginsHint': 'Plugins that are gone from the remote snapshot and unmodified locally get uninstalled (the evidence is the common ancestor still listing them — only another device could have removed them). Removal runs only in the round where the plugins section is actually applied; failures are reported per item and the rest of the sync still completes. The reserved desktop profile and the host itself are never removed.',
|
|
645
649
|
'mode.atLeastOne': 'Select at least one section to sync',
|
|
646
650
|
'mode.sectionPortable': 'Portable',
|
|
647
651
|
'mode.sectionRecommended': 'Recommended',
|
|
@@ -349,6 +349,11 @@ export interface ChannelSyncState {
|
|
|
349
349
|
encrypt: boolean
|
|
350
350
|
/** 手动推送默认导出真实凭据值(持久化开关;必须同时 encrypt) */
|
|
351
351
|
includeSecrets: boolean
|
|
352
|
+
/**
|
|
353
|
+
* 跟随远端删除插件(issue 132;持久化开关,缺省关)。
|
|
354
|
+
* 勾上即授权手动合并与自动同步都执行 `dsh plugin remove`。
|
|
355
|
+
*/
|
|
356
|
+
deletePlugins: boolean
|
|
352
357
|
/** 加密密码输入框(仅内存;已保存的密码在 DSH 凭据库里,不回显) */
|
|
353
358
|
encryptPassword: string
|
|
354
359
|
/** 加密密码确认(仅内存) */
|
|
@@ -398,6 +403,7 @@ export function defaultChannelSyncState(): ChannelSyncState {
|
|
|
398
403
|
sessionsInclude: [],
|
|
399
404
|
encrypt: false,
|
|
400
405
|
includeSecrets: false,
|
|
406
|
+
deletePlugins: false,
|
|
401
407
|
encryptPassword: '',
|
|
402
408
|
encryptPasswordConfirm: '',
|
|
403
409
|
decryptPassword: '',
|
package/src/core/backup.ts
CHANGED
|
@@ -20,7 +20,7 @@ import { MCP_CONNECTOR_STORE_REL } from './mcp-connector-store.ts';
|
|
|
20
20
|
import type { SectionId } from '../schema/types.ts';
|
|
21
21
|
import type {
|
|
22
22
|
ConfigAdapter, FileSystemFacade, HostContext, HostFileBackup, ImportPlan, PlanItem, Snapshot,
|
|
23
|
-
SnapshotEntry, SnapshotManifest, SnapshotStatus, SnapshotStore, SnapshotTarget,
|
|
23
|
+
SnapshotEntry, SnapshotManifest, SnapshotPluginRemoval, SnapshotStatus, SnapshotStore, SnapshotTarget,
|
|
24
24
|
} from './types.ts';
|
|
25
25
|
|
|
26
26
|
/**
|
|
@@ -960,6 +960,26 @@ export class FileSnapshotStore implements SnapshotStore {
|
|
|
960
960
|
snapshot.status = status;
|
|
961
961
|
await atomicWriteFile(file, JSON.stringify(snapshot, null, 2));
|
|
962
962
|
}
|
|
963
|
+
|
|
964
|
+
/**
|
|
965
|
+
* 记录本轮跟删的插件(issue #132 undo 线索):只重写 snapshot.json 的 pluginRemovals 字段。
|
|
966
|
+
*
|
|
967
|
+
* 为什么不像 save() 那样走 finalizeSnapshot:那条路会重算 manifest.blobHashes(本次没有 blob
|
|
968
|
+
* 可写 → 空 map → 磁盘校验直接判失败)并重跑 verify。这里只补一个**不在 metadataHash 覆盖面内**
|
|
969
|
+
* 的字段,manifest 与 blob 一字不动,快照的 READY/完整性语义不受影响。
|
|
970
|
+
*/
|
|
971
|
+
async recordPluginRemovals(id: string, removals: SnapshotPluginRemoval[]): Promise<void> {
|
|
972
|
+
if (removals.length === 0) return;
|
|
973
|
+
const file = path.join(this.snapshotDir(id), 'snapshot.json');
|
|
974
|
+
const snapshot = parseJsonSafe(await fs.readFile(file, 'utf8')) as Snapshot;
|
|
975
|
+
// 同日多次应用:保留既有记录(append 而不是覆盖),undo 才能把每一轮删的都装回来
|
|
976
|
+
const merged = [...(snapshot.pluginRemovals ?? [])];
|
|
977
|
+
for (const r of removals) {
|
|
978
|
+
if (!merged.some((m) => m.name === r.name)) merged.push(r);
|
|
979
|
+
}
|
|
980
|
+
snapshot.pluginRemovals = merged;
|
|
981
|
+
await atomicWriteFile(file, JSON.stringify(snapshot, null, 2));
|
|
982
|
+
}
|
|
963
983
|
}
|
|
964
984
|
|
|
965
985
|
/* ---------------- Phase 4:manifest / verifySnapshot(F1) ---------------- */
|
|
@@ -363,6 +363,9 @@ export const zh = {
|
|
|
363
363
|
'core.pluginCli.installFailed': '安装 {pkg} 失败({code}):{message}',
|
|
364
364
|
'core.pluginCli.noOutput': '无输出',
|
|
365
365
|
'core.pluginCli.installFailedWithTail': 'dsh plugin 安装 {pkg} 失败(exit {exitCode}):{tail}',
|
|
366
|
+
'core.pluginCli.uninstallTimeout': '卸载 {pkg} 超时(进程已终止):请稍后重试 / remove {pkg} timed out (process killed): retry later',
|
|
367
|
+
'core.pluginCli.uninstallFailed': '卸载 {pkg} 失败({code}):{message}',
|
|
368
|
+
'core.pluginCli.uninstallFailedWithTail': 'dsh plugin remove {pkg} 失败(exit {exitCode}):{tail}',
|
|
366
369
|
|
|
367
370
|
// ---------- migration-consult ----------
|
|
368
371
|
'core.consult.compatNoManifest': '无法评估兼容性:manifest 缺失',
|
|
@@ -725,6 +728,9 @@ export const en: Record<keyof typeof zh, string> = {
|
|
|
725
728
|
'core.pluginCli.installFailed': 'install {pkg} failed ({code}): {message}',
|
|
726
729
|
'core.pluginCli.noOutput': 'no output',
|
|
727
730
|
'core.pluginCli.installFailedWithTail': 'dsh plugin install {pkg} failed (exit {exitCode}): {tail}',
|
|
731
|
+
'core.pluginCli.uninstallTimeout': 'remove {pkg} timed out (process killed): retry later',
|
|
732
|
+
'core.pluginCli.uninstallFailed': 'remove {pkg} failed ({code}): {message}',
|
|
733
|
+
'core.pluginCli.uninstallFailedWithTail': 'dsh plugin remove {pkg} failed (exit {exitCode}): {tail}',
|
|
728
734
|
|
|
729
735
|
// ---------- migration-consult ----------
|
|
730
736
|
'core.consult.compatNoManifest': 'cannot assess compatibility: the manifest is missing',
|
package/src/core/messages.ts
CHANGED
|
@@ -170,6 +170,11 @@ export const zh = {
|
|
|
170
170
|
'restore.uninstallFailedExit': 'dsh plugin remove {name} 失败(exit {code}):{tail}',
|
|
171
171
|
'restore.noOutput': '无输出',
|
|
172
172
|
'restore.pluginRemoveFailed': '卸载失败',
|
|
173
|
+
'restore.pluginInstall': '装回跟远端删除过的插件 {name}@{version}',
|
|
174
|
+
'restore.pluginInstallAlreadyPresent': '插件 {name} 已在本机,无需装回',
|
|
175
|
+
'restore.pluginInstallFailed': '重装失败',
|
|
176
|
+
'restore.installFailedCode': 'dsh plugin add {name} 失败({code}):{message}',
|
|
177
|
+
'restore.installFailedExit': 'dsh plugin add {name} 失败(exit {code}):{tail}',
|
|
173
178
|
'restore.unknownAction': '未知动作 {kind}: {description}',
|
|
174
179
|
'restore.missingTargetBlob': '恢复动作缺少 target/blobPath',
|
|
175
180
|
'restore.missingTarget': '恢复动作缺少 target',
|
|
@@ -691,6 +696,11 @@ export const en: Record<keyof typeof zh, string> = {
|
|
|
691
696
|
'restore.uninstallFailedExit': 'dsh plugin remove {name} failed (exit {code}): {tail}',
|
|
692
697
|
'restore.noOutput': 'no output',
|
|
693
698
|
'restore.pluginRemoveFailed': 'Uninstall failed',
|
|
699
|
+
'restore.pluginInstall': 'Reinstall plugin {name}@{version} (removed earlier to follow the remote)',
|
|
700
|
+
'restore.pluginInstallAlreadyPresent': 'Plugin {name} is already installed here; nothing to reinstall',
|
|
701
|
+
'restore.pluginInstallFailed': 'Reinstall failed',
|
|
702
|
+
'restore.installFailedCode': 'dsh plugin add {name} failed ({code}): {message}',
|
|
703
|
+
'restore.installFailedExit': 'dsh plugin add {name} failed (exit {code}): {tail}',
|
|
694
704
|
'restore.unknownAction': 'Unknown action {kind}: {description}',
|
|
695
705
|
'restore.missingTargetBlob': 'Restore action is missing target/blobPath',
|
|
696
706
|
'restore.missingTarget': 'Restore action is missing target',
|
package/src/core/model-tools.ts
CHANGED
|
@@ -459,6 +459,8 @@ export function createModelTools(deps: ModelToolsDeps) {
|
|
|
459
459
|
hostFileRestores: plan.summary.hostFileRestores,
|
|
460
460
|
hostFileRemoves: plan.summary.hostFileRemoves,
|
|
461
461
|
pluginRemoves: plan.summary.pluginRemoves,
|
|
462
|
+
// issue #132:undo 会反向装回跟删过的插件,计数单独给出(agent 不必自己数 actions)
|
|
463
|
+
pluginInstalls: plan.summary.pluginInstalls,
|
|
462
464
|
fileRestores: plan.summary.fileRestores,
|
|
463
465
|
fileRemoves: plan.summary.fileRemoves,
|
|
464
466
|
credentialHints: plan.summary.credentialHints,
|
|
@@ -53,7 +53,7 @@ async function main(): Promise<void> {
|
|
|
53
53
|
describe: async (ref: string) => ({ value: { theme: 'dark' }, revision: 1, secrets: [] }),
|
|
54
54
|
},
|
|
55
55
|
credentials: { describe: async () => ({ configured: false }) },
|
|
56
|
-
plugins: { listInstalled: async () => [] },
|
|
56
|
+
plugins: { listInstalled: async () => [], uninstall: async () => ({ needsRestart: true }) },
|
|
57
57
|
workspace: { listRecords: async () => [] },
|
|
58
58
|
patchFile: { readPatchLines: async () => [] },
|
|
59
59
|
log: { warn: () => {} },
|
package/src/core/plugin-cli.ts
CHANGED
|
@@ -811,6 +811,43 @@ export function classifyDshPluginFailure(output: string): DshPluginFailure | nul
|
|
|
811
811
|
return null
|
|
812
812
|
}
|
|
813
813
|
|
|
814
|
+
/**
|
|
815
|
+
* 卸载一个插件(issue #132 的唯一写入口):`dsh plugin remove`,不自己改 package.json。
|
|
816
|
+
*
|
|
817
|
+
* 为什么不复用安装后的 reconcileBundlesAfterInstall:对账是「安装成功后补一次」的写操作,
|
|
818
|
+
* 卸载后 bundles 由 CLI 自己收尾;这里再补一次只会在失败语义上制造歧义。
|
|
819
|
+
*/
|
|
820
|
+
export async function uninstallViaCli(
|
|
821
|
+
homeDir: string,
|
|
822
|
+
profile: string,
|
|
823
|
+
pkg: string,
|
|
824
|
+
runner: (profileDir: string, profile: string, argv: readonly string[], input?: undefined, signal?: AbortSignal) => Promise<DshPluginResult>,
|
|
825
|
+
signal?: AbortSignal,
|
|
826
|
+
): Promise<{ needsRestart: boolean }> {
|
|
827
|
+
const result = await runner(resolveProfileDir(homeDir, profile), profile, ['remove', pkg], undefined, signal)
|
|
828
|
+
if (result.exitCode !== 0 || result.timedOut) throw uninstallErrorFor(pkg, result)
|
|
829
|
+
return { needsRestart: true }
|
|
830
|
+
}
|
|
831
|
+
|
|
832
|
+
/** 卸载失败(issue #132)→ 与安装同一套分类口径的双语可读 Error。 */
|
|
833
|
+
export function uninstallErrorFor(pkg: string, result: DshPluginResult): Error {
|
|
834
|
+
if (result.spawnError !== undefined && /ENOENT|EINVAL/.test(result.spawnError)) {
|
|
835
|
+
return new Error(engineMsg('core.pluginCli.dshCliStartFailed', { spawnError: result.spawnError, pkg }))
|
|
836
|
+
}
|
|
837
|
+
if (result.timedOut) {
|
|
838
|
+
return new Error(engineMsg('core.pluginCli.uninstallTimeout', { pkg }))
|
|
839
|
+
}
|
|
840
|
+
const output = `${result.stderr}\n${result.stdout}`
|
|
841
|
+
const failure = classifyDshPluginFailure(output)
|
|
842
|
+
if (failure !== null) {
|
|
843
|
+
return new Error(engineMsg('core.pluginCli.uninstallFailed', { pkg, code: failure.code, message: failure.message }))
|
|
844
|
+
}
|
|
845
|
+
const tail = (result.stderr.trim().split('\n').slice(-8).join('\n')
|
|
846
|
+
|| result.stdout.trim().split('\n').slice(-8).join('\n')
|
|
847
|
+
|| engineMsg('core.pluginCli.noOutput'))
|
|
848
|
+
return new Error(engineMsg('core.pluginCli.uninstallFailedWithTail', { pkg, exitCode: String(result.exitCode), tail }))
|
|
849
|
+
}
|
|
850
|
+
|
|
814
851
|
/** 安装失败 → 分类后的双语可读 Error;未识别则保留 stderr 尾部摘要。 */
|
|
815
852
|
export function installErrorFor(pkg: string, result: DshPluginResult): Error {
|
|
816
853
|
if (result.spawnError !== undefined && /ENOENT|EINVAL/.test(result.spawnError)) {
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* issue #132 undo 面:跟远端删掉插件的**反向补偿** —— 快照里记录过 pluginRemovals 的包,
|
|
3
|
+
* 恢复时若本机已缺就装回(复现被删的那一版),本机已存在则跳过。
|
|
4
|
+
*
|
|
5
|
+
* 为什么只认快照里记录过的名字、不按 beforePlugins 反推「缺了就是被删了」:
|
|
6
|
+
* 手动卸载 / 换包也会让基线里的名字消失,按差集重装等于替用户改主意(判据见 planRestore 的 2') 段)。
|
|
7
|
+
*/
|
|
8
|
+
import test from 'node:test';
|
|
9
|
+
import assert from 'node:assert/strict';
|
|
10
|
+
import fssync from 'node:fs';
|
|
11
|
+
import fs from 'node:fs/promises';
|
|
12
|
+
import os from 'node:os';
|
|
13
|
+
import path from 'node:path';
|
|
14
|
+
|
|
15
|
+
import { planRestore, restore } from './restore.ts';
|
|
16
|
+
import type { Snapshot } from './types.ts';
|
|
17
|
+
|
|
18
|
+
const SNAP_ID = 'snap-132-plugin-install';
|
|
19
|
+
const PKG = '@deepseek-ai/dsh-ssh';
|
|
20
|
+
const VERSION = '1.0.0';
|
|
21
|
+
const TARGET = `${PKG}@${VERSION}`;
|
|
22
|
+
|
|
23
|
+
interface Fixture {
|
|
24
|
+
homeDir: string;
|
|
25
|
+
snapshotDir: string;
|
|
26
|
+
profileDir: string;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function workdir(t: test.TestContext): string {
|
|
30
|
+
const dir = fssync.mkdtempSync(path.join(os.tmpdir(), 'dsh-cm-132-install-'));
|
|
31
|
+
t.after(() => fssync.rmSync(dir, { recursive: true, force: true }));
|
|
32
|
+
return dir;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** 快照目录:无 entries / 无 hostFileBackups、基线为空(→ 不会产出 pluginRemove),只有 pluginRemovals。 */
|
|
36
|
+
async function makeFixture(workDir: string): Promise<Fixture> {
|
|
37
|
+
const homeDir = path.join(workDir, 'home');
|
|
38
|
+
const profileDir = path.join(homeDir, 'profiles', 'web');
|
|
39
|
+
const snapshotDir = path.join(workDir, 'data', 'snapshots', SNAP_ID);
|
|
40
|
+
await fs.mkdir(path.join(snapshotDir, 'blobs', 'host'), { recursive: true });
|
|
41
|
+
await fs.mkdir(profileDir, { recursive: true });
|
|
42
|
+
const snapshot: Snapshot = {
|
|
43
|
+
id: SNAP_ID,
|
|
44
|
+
createdAt: '2026-11-10T00:00:00.000Z',
|
|
45
|
+
sourceZip: 'audit.zip',
|
|
46
|
+
entries: [],
|
|
47
|
+
status: 'done',
|
|
48
|
+
beforePlugins: [],
|
|
49
|
+
hostFileBackups: [],
|
|
50
|
+
pluginRemovals: [{ name: PKG, version: VERSION, target: TARGET }],
|
|
51
|
+
};
|
|
52
|
+
await fs.writeFile(path.join(snapshotDir, 'snapshot.json'), JSON.stringify(snapshot, null, 2), 'utf8');
|
|
53
|
+
return { homeDir, snapshotDir, profileDir };
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
async function writeInstalledProfile(profileDir: string, deps: Record<string, string>): Promise<void> {
|
|
57
|
+
await fs.writeFile(
|
|
58
|
+
path.join(profileDir, 'package.json'),
|
|
59
|
+
`${JSON.stringify({ name: 'dsh-profile-web', dependencies: deps }, null, 2)}\n`,
|
|
60
|
+
'utf8',
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
test('132-R1 记录过跟删的包在本机缺失 → 计划出 pluginInstall(target=name、pluginTarget=name@version)', async (t) => {
|
|
65
|
+
const f = await makeFixture(workdir(t));
|
|
66
|
+
const plan = await planRestore({ snapshotDir: f.snapshotDir, homeDir: f.homeDir, profile: 'web' });
|
|
67
|
+
|
|
68
|
+
const installs = plan.actions.filter((a) => a.kind === 'pluginInstall');
|
|
69
|
+
assert.equal(installs.length, 1, '应恰好规划一条重装动作');
|
|
70
|
+
assert.equal(installs[0]!.target, PKG);
|
|
71
|
+
assert.equal(installs[0]!.pluginName, PKG);
|
|
72
|
+
assert.equal(installs[0]!.pluginTarget, TARGET, '重装目标必须钉住被删时的版本');
|
|
73
|
+
assert.equal(plan.summary.pluginInstalls, 1);
|
|
74
|
+
assert.equal(plan.summary.pluginRemoves, 0, '基线为空且本机无任何已装 ⇒ 不应产出卸载');
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
test('132-R2 本机已装回(profile dependencies 里有该包)→ 计划转成 skip,不重复装', async (t) => {
|
|
78
|
+
const f = await makeFixture(workdir(t));
|
|
79
|
+
await writeInstalledProfile(f.profileDir, { [PKG]: '^1.0.0' });
|
|
80
|
+
|
|
81
|
+
const plan = await planRestore({ snapshotDir: f.snapshotDir, homeDir: f.homeDir, profile: 'web' });
|
|
82
|
+
assert.equal(plan.actions.filter((a) => a.kind === 'pluginInstall').length, 0);
|
|
83
|
+
assert.equal(plan.summary.pluginInstalls, 0);
|
|
84
|
+
assert.ok(
|
|
85
|
+
plan.actions.some((a) => a.kind === 'skip' && a.description.includes(PKG)),
|
|
86
|
+
'已装应留下一条带包名的 skip 说明',
|
|
87
|
+
);
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
test('132-R3 执行面:重装成功进 report.installedPlugins,失败进 report.failed 且不静默', async (t) => {
|
|
91
|
+
const f = await makeFixture(workdir(t));
|
|
92
|
+
const seen: string[] = [];
|
|
93
|
+
const okReport = await restore({
|
|
94
|
+
snapshotDir: f.snapshotDir,
|
|
95
|
+
homeDir: f.homeDir,
|
|
96
|
+
profile: 'web',
|
|
97
|
+
pluginInstaller: async (name, target) => {
|
|
98
|
+
seen.push(`${name}=>${target}`);
|
|
99
|
+
return { ok: true };
|
|
100
|
+
},
|
|
101
|
+
});
|
|
102
|
+
assert.deepEqual(seen, [`${PKG}=>${TARGET}`], '重装器必须收到包名与被删版本组成的 target');
|
|
103
|
+
assert.deepEqual(okReport.installedPlugins, [TARGET]);
|
|
104
|
+
assert.deepEqual(okReport.failed, []);
|
|
105
|
+
|
|
106
|
+
const failReport = await restore({
|
|
107
|
+
snapshotDir: f.snapshotDir,
|
|
108
|
+
homeDir: f.homeDir,
|
|
109
|
+
profile: 'web',
|
|
110
|
+
pluginInstaller: async () => ({ ok: false, message: 'dsh plugin add 失败:registry 不可达' }),
|
|
111
|
+
});
|
|
112
|
+
assert.deepEqual(failReport.installedPlugins, []);
|
|
113
|
+
assert.equal(failReport.failed.length, 1);
|
|
114
|
+
assert.equal(failReport.failed[0]!.item, `plugin:${PKG}`);
|
|
115
|
+
assert.match(failReport.failed[0]!.reason, /registry 不可达/);
|
|
116
|
+
});
|
package/src/core/restore-wal.ts
CHANGED
|
@@ -32,8 +32,14 @@ const WAL_KINDS: ReadonlySet<string> = new Set([
|
|
|
32
32
|
'fileRestore',
|
|
33
33
|
'fileRemove',
|
|
34
34
|
'pluginRemove',
|
|
35
|
+
'pluginInstall',
|
|
35
36
|
]);
|
|
36
37
|
|
|
38
|
+
/** 插件类动作 = 外部副作用(不带文件指纹;reconcile 恒走保守分支)。 */
|
|
39
|
+
export function isExternalPluginKind(kind: string): boolean {
|
|
40
|
+
return kind === 'pluginRemove' || kind === 'pluginInstall';
|
|
41
|
+
}
|
|
42
|
+
|
|
37
43
|
export function isWalActionKind(kind: string): boolean {
|
|
38
44
|
return WAL_KINDS.has(kind);
|
|
39
45
|
}
|
|
@@ -113,8 +119,8 @@ export function createRestoreWal(journal: RestoreJournalPort | undefined): Resto
|
|
|
113
119
|
out.push(undefined);
|
|
114
120
|
continue;
|
|
115
121
|
}
|
|
116
|
-
//
|
|
117
|
-
const external = entry.kind
|
|
122
|
+
// 插件装卸:外部副作用,刻意不带指纹(probeExternal 会得 unknown → 保守)。
|
|
123
|
+
const external = isExternalPluginKind(entry.kind);
|
|
118
124
|
const ref = external ? '' : (entry.abs ?? '');
|
|
119
125
|
const beforeFp = external ? null : await restoreFingerprint(entry.abs);
|
|
120
126
|
const id = stepIdOf(entry, ref);
|
|
@@ -163,7 +169,7 @@ export function restoreStepId(kind: string, subject: string): string {
|
|
|
163
169
|
|
|
164
170
|
/** step id 的 subject 段:插件卸载用包名,其余用绝对路径(拿不到绝对路径时退回流相对 target)。 */
|
|
165
171
|
export function restoreWalSubject(kind: string, pluginName: string | undefined, refOrTarget: string): string {
|
|
166
|
-
return kind
|
|
172
|
+
return isExternalPluginKind(kind) ? (pluginName ?? refOrTarget) : refOrTarget;
|
|
167
173
|
}
|
|
168
174
|
|
|
169
175
|
function stepIdOf(entry: RestoreWalEntry, ref: string): string {
|
|
@@ -175,7 +181,7 @@ export function restoreActionStepId(
|
|
|
175
181
|
action: { kind: string; target?: string; pluginName?: string },
|
|
176
182
|
abs: string | null,
|
|
177
183
|
): string {
|
|
178
|
-
const ref = action.kind
|
|
184
|
+
const ref = isExternalPluginKind(action.kind) ? '' : (abs ?? '');
|
|
179
185
|
return restoreStepId(action.kind, restoreWalSubject(action.kind, action.pluginName, ref || (action.target ?? '')));
|
|
180
186
|
}
|
|
181
187
|
|
|
@@ -196,7 +202,7 @@ export function collectRestoreWalEntries<A extends { kind: string; target?: stri
|
|
|
196
202
|
kind: action.kind,
|
|
197
203
|
...(action.target !== undefined ? { target: action.target } : {}),
|
|
198
204
|
...(action.pluginName !== undefined ? { pluginName: action.pluginName } : {}),
|
|
199
|
-
abs: action.kind
|
|
205
|
+
abs: isExternalPluginKind(action.kind) || action.target === undefined ? null : absOf(action),
|
|
200
206
|
});
|
|
201
207
|
}
|
|
202
208
|
return { mutating, entries };
|
|
@@ -212,7 +218,7 @@ export function restoreWalHandlesFromSteps(
|
|
|
212
218
|
): (RestoreWalHandle | undefined)[] {
|
|
213
219
|
return entries.map((entry) => {
|
|
214
220
|
if (!isWalActionKind(entry.kind)) return undefined;
|
|
215
|
-
const external = entry.kind
|
|
221
|
+
const external = isExternalPluginKind(entry.kind);
|
|
216
222
|
const ref = external ? '' : (entry.abs ?? '');
|
|
217
223
|
const id = restoreStepId(entry.kind, restoreWalSubject(entry.kind, entry.pluginName, ref || (entry.target ?? '')));
|
|
218
224
|
const known = steps[id];
|