dsh-config-manager 0.7.0 → 0.8.1
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/mcp.d.ts +6 -1
- package/lib/adapters/mcp.js +22 -4
- 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 +683 -647
- 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 +7 -0
- package/lib/core/messages.js +14 -0
- package/lib/core/model-tools.js +2 -0
- package/lib/core/patch-document.d.ts +65 -0
- package/lib/core/patch-document.js +161 -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 +8 -1
- package/lib/index.js +51 -68
- 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/mcp.test.ts +23 -3
- package/src/adapters/mcp.ts +24 -4
- 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 +14 -0
- package/src/core/model-tools.ts +2 -0
- package/src/core/patch-document.test.ts +107 -0
- package/src/core/patch-document.ts +194 -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.facade.test.ts +83 -1
- package/src/index.ts +57 -67
- 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
- package/src/utils/patch-yaml.test.ts +1 -1
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',
|
|
@@ -204,6 +209,8 @@ export const zh = {
|
|
|
204
209
|
'host.patchUnsupported': 'dsh-config-manager 仅支持管理 {user} 与 profile 的 {profile}(收到 {file})',
|
|
205
210
|
'host.patchUnreadable': 'patch 层 {file} 读不出来({reason}):该层的 patch 行不会被导出/同步,也不会被改写',
|
|
206
211
|
'host.patchRefuseClobber': 'patch 层 {file} 解析失败({reason}):已拒绝覆盖写入,否则会把这层里读不出来的行整体删掉',
|
|
212
|
+
'host.patchRefusePromote': 'patch 层 {file} 的写入会把 {ids} 从 insert(新增)改成顶层行(覆盖):已拒绝写入,文件未改动(顶层行按 id 覆盖,查不到就整条丢弃)',
|
|
213
|
+
'host.patchSemanticDrift': 'patch 层 {file} 写回后结构自检不通过({detail}):已拒绝写入,文件未改动',
|
|
207
214
|
'host.fsPathEscape': '路径越界: {path}',
|
|
208
215
|
'host.activationRowFailed': '插件 {pkg} 已安装,但激活行写入 profile 补丁失败:{reason}(重启后该插件可能未激活;修复后重试安装即可幂等补行)',
|
|
209
216
|
'host.syncTokenWriteFailed': 'token 写入 DSH credentials 失败:{reason}(请在 DSH 凭据管理里配置 {ref} 后重试)',
|
|
@@ -691,6 +698,11 @@ export const en: Record<keyof typeof zh, string> = {
|
|
|
691
698
|
'restore.uninstallFailedExit': 'dsh plugin remove {name} failed (exit {code}): {tail}',
|
|
692
699
|
'restore.noOutput': 'no output',
|
|
693
700
|
'restore.pluginRemoveFailed': 'Uninstall failed',
|
|
701
|
+
'restore.pluginInstall': 'Reinstall plugin {name}@{version} (removed earlier to follow the remote)',
|
|
702
|
+
'restore.pluginInstallAlreadyPresent': 'Plugin {name} is already installed here; nothing to reinstall',
|
|
703
|
+
'restore.pluginInstallFailed': 'Reinstall failed',
|
|
704
|
+
'restore.installFailedCode': 'dsh plugin add {name} failed ({code}): {message}',
|
|
705
|
+
'restore.installFailedExit': 'dsh plugin add {name} failed (exit {code}): {tail}',
|
|
694
706
|
'restore.unknownAction': 'Unknown action {kind}: {description}',
|
|
695
707
|
'restore.missingTargetBlob': 'Restore action is missing target/blobPath',
|
|
696
708
|
'restore.missingTarget': 'Restore action is missing target',
|
|
@@ -725,6 +737,8 @@ export const en: Record<keyof typeof zh, string> = {
|
|
|
725
737
|
'host.patchUnsupported': 'dsh-config-manager only manages {user} and the profile {profile} (received {file})',
|
|
726
738
|
'host.patchUnreadable': 'Cannot read patch layer {file} ({reason}): its patch rows are not exported or synced, and the file is left untouched',
|
|
727
739
|
'host.patchRefuseClobber': 'Refusing to rewrite patch layer {file}: it cannot be parsed ({reason}), and rewriting would delete every row that could not be read',
|
|
740
|
+
'host.patchRefusePromote': 'Refusing to write patch layer {file}: it would turn {ids} from insert (add) into top-level rows (override); the file is untouched (top-level rows override by id and are dropped entirely when not found)',
|
|
741
|
+
'host.patchSemanticDrift': 'Structure self-check failed after serializing patch layer {file} ({detail}): the write was refused and the file is untouched',
|
|
728
742
|
'host.fsPathEscape': 'Path outside home directory: {path}',
|
|
729
743
|
'host.activationRowFailed': 'Plugin {pkg} is installed, but writing the activation row into the profile patch failed: {reason} (the plugin may be inactive until restart; retrying the install after fixing is idempotent)',
|
|
730
744
|
'host.syncTokenWriteFailed': 'Failed to write the token into DSH credentials: {reason} (configure {ref} in DSH credential management, then retry)',
|
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,
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* patch 文档结构重建(issue #133):顶层行 ≠ `- insert:` 块成员。
|
|
3
|
+
*
|
|
4
|
+
* 宿主合并循环里,顶层 `- id: X` 按 id **覆盖**(查不到就 `patch: entry "X" not found` 丢弃),
|
|
5
|
+
* 只有 insert 块成员是**新增**。旧实现把所有行统一输出成顶层行 —— 一条 update 就把只能靠
|
|
6
|
+
* insert 新增的条目(MCP server 最典型)在重启后整段作废。本文件钉住三条不变量:
|
|
7
|
+
* ① 既有 insert 成员更新后**归属不变**;② 新增(action:'insert')落进 insert 块;
|
|
8
|
+
* ③ 任一 id 不得同时具备两种身份。
|
|
9
|
+
*/
|
|
10
|
+
import test from 'node:test';
|
|
11
|
+
import assert from 'node:assert/strict';
|
|
12
|
+
|
|
13
|
+
import {
|
|
14
|
+
describePatchDocument, describePatchLayoutDrift, PatchPromoteRefusedError, planPatchDocument,
|
|
15
|
+
} from './patch-document.ts';
|
|
16
|
+
|
|
17
|
+
const DOC = [
|
|
18
|
+
{ id: 'top-a', name: '@deepseek-ai/dsh-top', disabled: false },
|
|
19
|
+
{ insert: [
|
|
20
|
+
{ id: 'mcp-a', name: 'dsh-mcp-client', config: { transport: 'stdio', command: 'npx' } },
|
|
21
|
+
{ id: 'mcp-b', name: 'dsh-mcp-client', config: { transport: 'streamable-http', url: 'http://127.0.0.1:1/mcp' } },
|
|
22
|
+
] },
|
|
23
|
+
{ id: 'top-b', name: '@deepseek-ai/dsh-other' },
|
|
24
|
+
];
|
|
25
|
+
|
|
26
|
+
test('#133 insert 块保真:更新一条 insert 成员后仍留在块里,成员集合不变', () => {
|
|
27
|
+
const plan = planPatchDocument(DOC, [
|
|
28
|
+
{ lineId: 'mcp-a', raw: { id: 'mcp-a', name: 'dsh-mcp-client', config: { transport: 'stdio', command: 'uvx' } }, action: 'update' },
|
|
29
|
+
]);
|
|
30
|
+
assert.deepEqual(plan.insertIds, ['mcp-a', 'mcp-b']);
|
|
31
|
+
assert.deepEqual(plan.topLevelIds, ['top-a', 'top-b']);
|
|
32
|
+
const block = plan.items.find((item) => Array.isArray((item as Record<string, unknown>)['insert'])) as { insert: { id: string; config: { command: string } }[] };
|
|
33
|
+
assert.ok(block !== undefined, 'insert 块必须仍然存在(旧实现会把它摊平成两条顶层行)');
|
|
34
|
+
assert.deepEqual(block.insert.map((e) => e.id), ['mcp-a', 'mcp-b']);
|
|
35
|
+
assert.equal(block.insert[0]?.config.command, 'uvx', '更新后的值写进块成员');
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
test('#133 顶层行更新不改归属(也不会掉进 insert 块)', () => {
|
|
39
|
+
const plan = planPatchDocument(DOC, [
|
|
40
|
+
{ lineId: 'top-a', raw: { id: 'top-a', name: '@deepseek-ai/dsh-top', disabled: true }, action: 'update' },
|
|
41
|
+
]);
|
|
42
|
+
assert.deepEqual(plan.topLevelIds, ['top-a', 'top-b']);
|
|
43
|
+
assert.deepEqual(plan.insertIds, ['mcp-a', 'mcp-b']);
|
|
44
|
+
assert.equal((plan.items[0] as { disabled: boolean }).disabled, true, '顶层行保持原位');
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
test('#133 新增条目走 insert 动作时落进 insert 块(新增语义,而不是覆盖)', () => {
|
|
48
|
+
const plan = planPatchDocument(DOC, [
|
|
49
|
+
{ lineId: 'mcp-new', raw: { id: 'mcp-new', name: 'dsh-mcp-client', config: { transport: 'stdio', command: 'node' } }, action: 'insert' },
|
|
50
|
+
]);
|
|
51
|
+
assert.deepEqual(plan.insertIds, ['mcp-a', 'mcp-b', 'mcp-new']);
|
|
52
|
+
assert.deepEqual(plan.topLevelIds, ['top-a', 'top-b'], '新增绝不能出现在顶层行里');
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
test('#133 update 动作写新 id 时保持旧的 upsert 语义(顶层行,不改既有契约)', () => {
|
|
56
|
+
const plan = planPatchDocument(DOC, [
|
|
57
|
+
{ lineId: 'plain', raw: { id: 'plain', disabled: true }, action: 'update' },
|
|
58
|
+
]);
|
|
59
|
+
assert.deepEqual(plan.topLevelIds, ['top-a', 'top-b', 'plain']);
|
|
60
|
+
assert.deepEqual(plan.insertIds, ['mcp-a', 'mcp-b']);
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
test('#133 remove 删掉 insert 成员后块仍保留其余成员', () => {
|
|
64
|
+
const plan = planPatchDocument(DOC, [{ lineId: 'mcp-a', raw: null, action: 'remove' }]);
|
|
65
|
+
assert.deepEqual(plan.insertIds, ['mcp-b']);
|
|
66
|
+
const blocks = plan.items.filter((item) => Array.isArray((item as Record<string, unknown>)['insert']));
|
|
67
|
+
assert.equal(blocks.length, 1);
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
test('#133 remove 删光 insert 成员后不留空块(空块会被宿主当空 insert)', () => {
|
|
71
|
+
const plan = planPatchDocument(DOC, [
|
|
72
|
+
{ lineId: 'mcp-a', raw: null, action: 'remove' },
|
|
73
|
+
{ lineId: 'mcp-b', raw: null, action: 'remove' },
|
|
74
|
+
]);
|
|
75
|
+
assert.deepEqual(plan.insertIds, []);
|
|
76
|
+
assert.equal(plan.items.some((item) => Array.isArray((item as Record<string, unknown>)['insert'])), false);
|
|
77
|
+
assert.deepEqual(plan.topLevelIds, ['top-a', 'top-b']);
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
test('#133 空文档 + insert 动作:落成 insert 块(MCP 从零新建的路径)', () => {
|
|
81
|
+
const plan = planPatchDocument(undefined, [
|
|
82
|
+
{ lineId: 'first', raw: { id: 'first', name: 'dsh-mcp-client', config: { transport: 'stdio', command: 'npx' } }, action: 'insert' },
|
|
83
|
+
]);
|
|
84
|
+
assert.deepEqual(plan.insertIds, ['first']);
|
|
85
|
+
assert.deepEqual(plan.topLevelIds, []);
|
|
86
|
+
assert.equal(plan.items.length, 1);
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
test('#133 同一 id 不得同时具备两种身份(防御性不变量)', () => {
|
|
90
|
+
// 文档里同一 id 既在块里又在顶层:以首次出现为准,绝不产生「两种身份并存」的输出
|
|
91
|
+
const plan = planPatchDocument([
|
|
92
|
+
{ insert: [{ id: 'dup', name: 'a' }] },
|
|
93
|
+
{ id: 'dup', name: 'b' },
|
|
94
|
+
], []);
|
|
95
|
+
assert.deepEqual(plan.insertIds, ['dup']);
|
|
96
|
+
assert.deepEqual(plan.topLevelIds, []);
|
|
97
|
+
assert.equal(new PatchPromoteRefusedError(['x']).ids[0], 'x');
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
test('#133 写后自检:布局不一致时给出可读差异(一致返回 null)', () => {
|
|
101
|
+
const planned = describePatchDocument(DOC);
|
|
102
|
+
assert.equal(describePatchLayoutDrift(planned, describePatchDocument(DOC)), null);
|
|
103
|
+
const drift = describePatchLayoutDrift(planned, { insertIds: [], topLevelIds: ['top-a', 'mcp-a', 'mcp-b', 'top-b'] });
|
|
104
|
+
assert.ok(drift !== null);
|
|
105
|
+
assert.match(String(drift), /insert=\[mcp-a, mcp-b\]/);
|
|
106
|
+
assert.match(String(drift), /got insert=\[\]/);
|
|
107
|
+
});
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* patch 文档的**结构重建**(issue #133)。
|
|
3
|
+
*
|
|
4
|
+
* 为什么需要独立一层:`cordis.patch.yml` 的两种形态语义**不等价**(宿主 dsh-app-boot 的
|
|
5
|
+
* readProfilePatches 合并循环):
|
|
6
|
+
* - 顶层 `- id: X` → 按 id **覆盖**已存在的条目;id 查不到时打 `patch: entry "X" not found` 丢弃;
|
|
7
|
+
* - `- insert:` 块成员 → **新增**条目(`data.push(...clone)`,唯一的新增路径)。
|
|
8
|
+
* 此前重建时把所有行(含 insert 成员)统一输出成顶层行,于是「只能靠 insert 新增」的条目
|
|
9
|
+
* (典型是 MCP server)在 DSH 侧全部失效 —— 一条 update 就够触发。
|
|
10
|
+
*
|
|
11
|
+
* 本模块只做**结构**:不读文件、不碰 YAML(core 层零依赖),输入是已解析的文档 + 变更清单,
|
|
12
|
+
* 输出是重建后的条目数组与两套 id。序列化与自检在宿主门面(DshPatchFileFacade)里做。
|
|
13
|
+
*
|
|
14
|
+
* 三条不变量:
|
|
15
|
+
* ① 原本是 insert 成员的 id,重建后仍在 insert 块里(update 不改变归属);
|
|
16
|
+
* ② 新增条目(`action:'insert'` 且文档里没有)落进 insert 块,而不是顶层行;
|
|
17
|
+
* ③ 任一 id 不得同时出现在顶层与 insert 两处 —— 计划阶段就抛错(防御性,正常路径不可达)。
|
|
18
|
+
*/
|
|
19
|
+
export interface PatchLineChange {
|
|
20
|
+
lineId: string;
|
|
21
|
+
raw: unknown;
|
|
22
|
+
action: 'insert' | 'update' | 'remove';
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export interface PatchDocumentPlan {
|
|
26
|
+
/** 重建后的文档条目(顺序尽量贴原文档:顶层行原位、insert 块原位、新增项追加在尾部) */
|
|
27
|
+
items: unknown[];
|
|
28
|
+
/** 落在 insert 块里的 id(按输出顺序) */
|
|
29
|
+
insertIds: string[];
|
|
30
|
+
/** 落在顶层行里的 id(按输出顺序) */
|
|
31
|
+
topLevelIds: string[];
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** 计划会把 insert 成员提升成顶层行:调用方必须放弃这次写入(零写入)。 */
|
|
35
|
+
export class PatchPromoteRefusedError extends Error {
|
|
36
|
+
readonly ids: string[];
|
|
37
|
+
constructor(ids: string[]) {
|
|
38
|
+
super('patch rebuild would promote insert members to top-level rows: ' + ids.join(', '));
|
|
39
|
+
this.name = 'PatchPromoteRefusedError';
|
|
40
|
+
this.ids = ids;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
interface SlotState {
|
|
45
|
+
raw: unknown;
|
|
46
|
+
inInsert: boolean;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
type Slot = { kind: 'row'; id: string } | { kind: 'block'; ids: string[] };
|
|
50
|
+
|
|
51
|
+
function entryId(value: unknown): string | null {
|
|
52
|
+
if (value === null || typeof value !== 'object') return null;
|
|
53
|
+
const id = (value as Record<string, unknown>)['id'];
|
|
54
|
+
return typeof id === 'string' && id !== '' ? id : null;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function blockMembers(value: unknown): Record<string, unknown>[] | null {
|
|
58
|
+
if (value === null || typeof value !== 'object') return null;
|
|
59
|
+
const insert = (value as Record<string, unknown>)['insert'];
|
|
60
|
+
if (!Array.isArray(insert)) return null;
|
|
61
|
+
return insert.filter((entry): entry is Record<string, unknown> => entry !== null && typeof entry === 'object');
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/** 读出文档里的 insert 成员 id 与顶层行 id(自检与测试共用;不判重、保持文档顺序)。 */
|
|
65
|
+
export function describePatchDocument(doc: unknown): { insertIds: string[]; topLevelIds: string[] } {
|
|
66
|
+
const insertIds: string[] = [];
|
|
67
|
+
const topLevelIds: string[] = [];
|
|
68
|
+
if (!Array.isArray(doc)) return { insertIds, topLevelIds };
|
|
69
|
+
for (const item of doc) {
|
|
70
|
+
const members = blockMembers(item);
|
|
71
|
+
if (members !== null) {
|
|
72
|
+
for (const member of members) {
|
|
73
|
+
const id = entryId(member);
|
|
74
|
+
if (id !== null) insertIds.push(id);
|
|
75
|
+
}
|
|
76
|
+
continue;
|
|
77
|
+
}
|
|
78
|
+
const id = entryId(item);
|
|
79
|
+
if (id !== null) topLevelIds.push(id);
|
|
80
|
+
}
|
|
81
|
+
return { insertIds, topLevelIds };
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* 重建成 patch 文档条目。
|
|
86
|
+
*
|
|
87
|
+
* `doc` 是已解析的原文档(非数组视为空文档);顺序按原布局保留,新增项追加在尾部。
|
|
88
|
+
*/
|
|
89
|
+
export function planPatchDocument(doc: unknown, changes: readonly PatchLineChange[]): PatchDocumentPlan {
|
|
90
|
+
const state = new Map<string, SlotState>();
|
|
91
|
+
const layout: Slot[] = [];
|
|
92
|
+
|
|
93
|
+
if (Array.isArray(doc)) {
|
|
94
|
+
for (const item of doc) {
|
|
95
|
+
const members = blockMembers(item);
|
|
96
|
+
if (members !== null) {
|
|
97
|
+
const ids: string[] = [];
|
|
98
|
+
for (const member of members) {
|
|
99
|
+
const id = entryId(member);
|
|
100
|
+
if (id === null) continue;
|
|
101
|
+
ids.push(id);
|
|
102
|
+
if (!state.has(id)) state.set(id, { raw: member, inInsert: true });
|
|
103
|
+
}
|
|
104
|
+
if (ids.length > 0) layout.push({ kind: 'block', ids });
|
|
105
|
+
continue;
|
|
106
|
+
}
|
|
107
|
+
const id = entryId(item);
|
|
108
|
+
if (id === null) continue;
|
|
109
|
+
layout.push({ kind: 'row', id });
|
|
110
|
+
if (!state.has(id)) state.set(id, { raw: item, inInsert: false });
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
for (const change of changes) {
|
|
115
|
+
if (change.action === 'remove') {
|
|
116
|
+
state.delete(change.lineId);
|
|
117
|
+
continue;
|
|
118
|
+
}
|
|
119
|
+
const previous = state.get(change.lineId);
|
|
120
|
+
// 归属只由**原文档**决定:更新一条既有 insert 成员不会把它搬到顶层;新增才按动作分流
|
|
121
|
+
const inInsert = previous !== undefined ? previous.inInsert : change.action === 'insert';
|
|
122
|
+
state.set(change.lineId, { raw: change.raw, inInsert });
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
const items: unknown[] = [];
|
|
126
|
+
const insertIds: string[] = [];
|
|
127
|
+
const topLevelIds: string[] = [];
|
|
128
|
+
const emitted = new Set<string>();
|
|
129
|
+
|
|
130
|
+
const emitRow = (id: string): void => {
|
|
131
|
+
const slot = state.get(id);
|
|
132
|
+
if (slot === undefined || emitted.has(id)) return;
|
|
133
|
+
emitted.add(id);
|
|
134
|
+
items.push(slot.raw);
|
|
135
|
+
topLevelIds.push(id);
|
|
136
|
+
};
|
|
137
|
+
const emitBlock = (ids: string[]): void => {
|
|
138
|
+
const members = ids.filter((id) => {
|
|
139
|
+
const slot = state.get(id);
|
|
140
|
+
return slot !== undefined && slot.inInsert && !emitted.has(id);
|
|
141
|
+
});
|
|
142
|
+
if (members.length === 0) return;
|
|
143
|
+
for (const id of members) emitted.add(id);
|
|
144
|
+
items.push({ insert: members.map((id) => state.get(id)!.raw) });
|
|
145
|
+
insertIds.push(...members);
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
for (const slot of layout) {
|
|
149
|
+
if (slot.kind === 'row') emitRow(slot.id);
|
|
150
|
+
else emitBlock(slot.ids);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
// 新写入、且原文档布局里没有的 id:insert 动作进块,update 动作保持旧的 upsert 语义(顶层行)
|
|
154
|
+
for (const [id, slot] of state) {
|
|
155
|
+
if (emitted.has(id)) continue;
|
|
156
|
+
if (slot.inInsert) continue;
|
|
157
|
+
emitRow(id);
|
|
158
|
+
}
|
|
159
|
+
emitBlock([...state.keys()].filter((id) => !emitted.has(id)));
|
|
160
|
+
|
|
161
|
+
// 不变量③:同一 id 不得两种身份并存(正常路径不可达;坏了就拒写,别写出一份语义分裂的文件)
|
|
162
|
+
const promoted = insertIds.filter((id) => topLevelIds.includes(id));
|
|
163
|
+
if (promoted.length > 0) throw new PatchPromoteRefusedError(promoted);
|
|
164
|
+
|
|
165
|
+
return { items, insertIds, topLevelIds };
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* 计划布局与观察到的布局是否一致(写后自检用,issue #133)。
|
|
169
|
+
* 一致返回 `null`;不一致返回一句可直接进错误文案的差异说明(只含 id,不含值)。
|
|
170
|
+
*/
|
|
171
|
+
export function describePatchLayoutDrift(
|
|
172
|
+
planned: { insertIds: readonly string[]; topLevelIds: readonly string[] },
|
|
173
|
+
observed: { insertIds: readonly string[]; topLevelIds: readonly string[] },
|
|
174
|
+
): string | null {
|
|
175
|
+
const same = planned.insertIds.length === observed.insertIds.length
|
|
176
|
+
&& planned.topLevelIds.length === observed.topLevelIds.length
|
|
177
|
+
&& planned.insertIds.every((id, i) => id === observed.insertIds[i])
|
|
178
|
+
&& planned.topLevelIds.every((id, i) => id === observed.topLevelIds[i]);
|
|
179
|
+
if (same) return null;
|
|
180
|
+
const fmt = (label: string, ids: readonly string[]): string => label + '=[' + ids.join(', ') + ']';
|
|
181
|
+
return 'planned ' + fmt('insert', planned.insertIds) + ' ' + fmt('top-level', planned.topLevelIds)
|
|
182
|
+
+ '; got ' + fmt('insert', observed.insertIds) + ' ' + fmt('top-level', observed.topLevelIds);
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* 跨层提升检查(issue #133):`topLevelIds` 里哪些是**另一层文档**的 `- insert:` 成员。
|
|
186
|
+
*
|
|
187
|
+
* 命中就意味着「把新增改写成覆盖」——目标作用域里那条通常不存在,宿主会 `not found` 丢弃。
|
|
188
|
+
* `otherDoc` 读不到或解析不了时调用方传 `undefined`,本函数返回空(守卫只做加强)。
|
|
189
|
+
*/
|
|
190
|
+
export function promotedTopLevelIds(otherDoc: unknown, topLevelIds: readonly string[]): string[] {
|
|
191
|
+
if (topLevelIds.length === 0) return [];
|
|
192
|
+
const insertMembers = new Set(describePatchDocument(otherDoc).insertIds);
|
|
193
|
+
return topLevelIds.filter((id) => insertMembers.has(id));
|
|
194
|
+
}
|
|
@@ -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)) {
|