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
|
@@ -255,12 +255,33 @@ export interface PackedLocalPlugin {
|
|
|
255
255
|
data: Uint8Array;
|
|
256
256
|
}
|
|
257
257
|
|
|
258
|
+
/**
|
|
259
|
+
* 因体积上限被**丢弃**的本地插件(tarball 大于 maxTarballBytes)。
|
|
260
|
+
*
|
|
261
|
+
* 单独带出来(而不是只留一条 warning)是为了让宿主侧做**超限负缓存**:
|
|
262
|
+
* 真机实测单个 210MB 的本地插件一次 npm pack 44.7s,而结果每次都被上限丢掉 ——
|
|
263
|
+
* 每 60s 一轮的自动同步于是每分钟白烧 45s CPU 与磁盘。宿主拿到这条事实后,
|
|
264
|
+
* 在源没变的前提下可以不再重复打包(见 core/local-plugin-host.ts 的负缓存)。
|
|
265
|
+
*/
|
|
266
|
+
export interface OversizeLocalPlugin {
|
|
267
|
+
packageName: string;
|
|
268
|
+
/** 解析后的源路径(目录,或 file: 直接指向的 .tgz)—— 负缓存以它为键 */
|
|
269
|
+
sourcePath: string;
|
|
270
|
+
/** 超限形态:'archive' = file: 指向的归档本身太大;'dir' = 打包后太大 */
|
|
271
|
+
source: 'archive' | 'dir';
|
|
272
|
+
/** 实测字节数与上限(用于告警文案与缓存命中时复述) */
|
|
273
|
+
size: number;
|
|
274
|
+
maxBytes: number;
|
|
275
|
+
}
|
|
276
|
+
|
|
258
277
|
export interface PackLocalPluginsResult {
|
|
259
278
|
packed: PackedLocalPlugin[];
|
|
260
279
|
/** packageName → 重写后的 spec */
|
|
261
280
|
rewritten: Record<string, string>;
|
|
262
281
|
/** 非致命告警(跳过原因等;调用方并入分区 warnings) */
|
|
263
282
|
warnings: string[];
|
|
283
|
+
/** 被体积上限丢弃的插件(见 OversizeLocalPlugin;调用方做完负缓存后无需再管) */
|
|
284
|
+
oversize: OversizeLocalPlugin[];
|
|
264
285
|
}
|
|
265
286
|
|
|
266
287
|
/**
|
|
@@ -314,17 +335,18 @@ export async function packLocalPlugins(
|
|
|
314
335
|
const packed: PackedLocalPlugin[] = [];
|
|
315
336
|
const rewritten: Record<string, string> = {};
|
|
316
337
|
const warnings: string[] = [];
|
|
338
|
+
const oversize: OversizeLocalPlugin[] = [];
|
|
317
339
|
const maxBytes = opts.maxTarballBytes ?? MAX_LOCAL_TARBALL_BYTES;
|
|
318
340
|
const timeoutMs = opts.timeoutMs ?? 5 * 60 * 1000;
|
|
319
341
|
|
|
320
342
|
const candidates = opts.plugins.filter((p) => isLocalPluginSpec(p.spec));
|
|
321
|
-
if (candidates.length === 0) return { packed, rewritten, warnings };
|
|
343
|
+
if (candidates.length === 0) return { packed, rewritten, warnings, oversize };
|
|
322
344
|
|
|
323
345
|
try {
|
|
324
346
|
await opts.mkdir(opts.packDir);
|
|
325
347
|
} catch (err) {
|
|
326
348
|
warnings.push(engineMsg('core.localPluginPack.dirCreateFailed', { reason: reasonOf(err) }));
|
|
327
|
-
return { packed, rewritten, warnings };
|
|
349
|
+
return { packed, rewritten, warnings, oversize };
|
|
328
350
|
}
|
|
329
351
|
|
|
330
352
|
for (const plugin of candidates) {
|
|
@@ -345,6 +367,13 @@ export async function packLocalPlugins(
|
|
|
345
367
|
warnings.push(
|
|
346
368
|
engineMsg('core.localPluginPack.tarballTooLarge', { name: plugin.name, size: data.byteLength, max: maxBytes }),
|
|
347
369
|
);
|
|
370
|
+
oversize.push({
|
|
371
|
+
packageName: plugin.name,
|
|
372
|
+
sourcePath,
|
|
373
|
+
source: 'archive',
|
|
374
|
+
size: data.byteLength,
|
|
375
|
+
maxBytes,
|
|
376
|
+
});
|
|
348
377
|
continue;
|
|
349
378
|
}
|
|
350
379
|
const relativePath = `${LOCAL_PLUGIN_DIR}/${safeTarballFileNameFor(plugin.name, sourcePath)}`;
|
|
@@ -388,6 +417,13 @@ export async function packLocalPlugins(
|
|
|
388
417
|
warnings.push(
|
|
389
418
|
engineMsg('core.localPluginPack.tarballTooLarge', { name: plugin.name, size: data.byteLength, max: maxBytes }),
|
|
390
419
|
);
|
|
420
|
+
oversize.push({
|
|
421
|
+
packageName: plugin.name,
|
|
422
|
+
sourcePath,
|
|
423
|
+
source: 'dir',
|
|
424
|
+
size: data.byteLength,
|
|
425
|
+
maxBytes,
|
|
426
|
+
});
|
|
391
427
|
continue;
|
|
392
428
|
}
|
|
393
429
|
|
|
@@ -406,7 +442,7 @@ export async function packLocalPlugins(
|
|
|
406
442
|
}
|
|
407
443
|
}
|
|
408
444
|
|
|
409
|
-
return { packed, rewritten, warnings };
|
|
445
|
+
return { packed, rewritten, warnings, oversize };
|
|
410
446
|
}
|
|
411
447
|
|
|
412
448
|
function reasonOf(err: unknown): string {
|
|
@@ -103,6 +103,13 @@ export interface ConnectorOauthRef {
|
|
|
103
103
|
export interface McpConnectorExport {
|
|
104
104
|
format: typeof MCP_CONNECTOR_EXPORT_FORMAT;
|
|
105
105
|
version: typeof MCP_CONNECTOR_EXPORT_VERSION;
|
|
106
|
+
/**
|
|
107
|
+
* 这批连接**状态**的时间戳(内容派生:最晚的 updatedAt/createdAt,无时间戳则固定纪元值)。
|
|
108
|
+
*
|
|
109
|
+
* 为什么不是「导出当刻」:同步的「本地有无改动」直接哈希这份载荷(SyncEngine.hasLocalChanges),
|
|
110
|
+
* 基线也取自同一份载荷;写 now() 会让 hash 每轮都变 ⇒ 每轮轮询都真推一次空快照。
|
|
111
|
+
* 本字段没有任何读取方(导入只认 connections / oauthConnections),因此取内容派生值不丢信息。
|
|
112
|
+
*/
|
|
106
113
|
exportedAt: string;
|
|
107
114
|
connections: ConnectorExportEntry[];
|
|
108
115
|
oauthConnections: ConnectorOauthRef[];
|
|
@@ -276,8 +283,26 @@ export function exportConnectorRecord(record: ConnectorRecord): ConnectorExportE
|
|
|
276
283
|
return entry;
|
|
277
284
|
}
|
|
278
285
|
|
|
286
|
+
/**
|
|
287
|
+
* 导出块的稳定时间戳:这批连接里最晚的一次变更(updatedAt 优先,其次 createdAt);
|
|
288
|
+
* 一条都没有时间戳时退回固定纪元值(1970-01-01T00:00:00.000Z)——**恒定**比「像样但会漂移」重要,
|
|
289
|
+
* 因为它参与同步的「有无改动」哈希(见 McpConnectorExport.exportedAt 的注释)。
|
|
290
|
+
*/
|
|
291
|
+
export function connectorBlockStamp(records: readonly ConnectorRecord[]): string {
|
|
292
|
+
let latest = 0;
|
|
293
|
+
for (const r of records) {
|
|
294
|
+
for (const v of [r.updatedAt, r.createdAt]) {
|
|
295
|
+
if (typeof v === 'number' && Number.isFinite(v) && v > latest) latest = v;
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
return new Date(latest > 0 ? latest : 0).toISOString();
|
|
299
|
+
}
|
|
300
|
+
|
|
279
301
|
/** 全部连接 → 导出块(OAuth 只留引用;按 key 排序,便于 diff 与稳定哈希) */
|
|
280
|
-
export function exportConnectorBlock(
|
|
302
|
+
export function exportConnectorBlock(
|
|
303
|
+
records: readonly ConnectorRecord[],
|
|
304
|
+
exportedAt = connectorBlockStamp(records),
|
|
305
|
+
): McpConnectorExport {
|
|
281
306
|
const sorted = [...records].sort((a, b) => a.key.localeCompare(b.key));
|
|
282
307
|
return {
|
|
283
308
|
format: MCP_CONNECTOR_EXPORT_FORMAT,
|
|
@@ -279,6 +279,53 @@ export const zh = {
|
|
|
279
279
|
'core.modelTools.syncPullPasswordParam': '解密密码(加密快照需要;仅内存)',
|
|
280
280
|
'core.modelTools.syncPullOutputDesc': '差异报告(changes 列表 / needsReview)',
|
|
281
281
|
|
|
282
|
+
// ---------- model tools D2–D6:计划句柄、密码槽、导入 ----------
|
|
283
|
+
'core.modelTools.restorePlanIdParam': '预览返回的 planId;真实执行时必须带上(服务端会按当前磁盘重算计划并比对,变化即拒绝)',
|
|
284
|
+
'core.modelTools.syncPushPasswordDeprecatedParam': '已弃用:加密密码优先从 DSH credentials 的同通道槽位读取;确需临时密码才传(仅内存,不落盘/不回显)',
|
|
285
|
+
'core.modelTools.syncPushForceParam': '远端已被别的设备推进时仍覆盖(缺省 false = 前置检测到冲突即中止;会覆盖远端历史)',
|
|
286
|
+
'core.modelTools.syncPreviewToolDesc': '三方合并预览(只读):下载远端快照 + 对本机/远端/祖先分类,返回每个分区的结论与冲突位置。落地前必须先调它拿 planId。sessions 分区永不参与。',
|
|
287
|
+
'core.modelTools.syncPreviewSnapshotIdParam': '远端快照 id;缺省 = 最新',
|
|
288
|
+
'core.modelTools.syncPreviewPasswordParam': '解密密码;缺省优先取该通道已存的解密密码(仅内存)',
|
|
289
|
+
'core.modelTools.syncPreviewOutputDesc': '预览结果(planId / summary / 每个分区的 decision 与 conflicts)',
|
|
290
|
+
'core.modelTools.syncApplyToolDesc': '落地三方合并:必须带 config_sync_preview 的 planId。锁内重跑预览比对指纹,预览后有变化即拒绝(零写入)。写操作过 GLOBAL 锁并留回滚点。',
|
|
291
|
+
'core.modelTools.syncApplyPlanIdParam': 'config_sync_preview 返回的 planId',
|
|
292
|
+
'core.modelTools.syncApplyResolutionsParam': '逐分区裁决:id = 分区 id(或 分区id::冲突路径),action = keepLocal / useRemote / useMerged / skip',
|
|
293
|
+
'core.modelTools.syncApplyResolutionIdParam': '分区 id 或 分区id::冲突路径',
|
|
294
|
+
'core.modelTools.syncApplyResolutionActionParam': 'keepLocal 本机为准 / useRemote 远端为准 / useMerged 用自动合并结果 / skip 跳过该分区',
|
|
295
|
+
'core.modelTools.syncApplyPasswordParam': '解密密码;缺省优先取该通道已存的解密密码(仅内存)',
|
|
296
|
+
'core.modelTools.syncApplyOutputDesc': '落地报告(applied / restoreId / rolledBack / warnings / pendingConflicts / ignoredResolutions)',
|
|
297
|
+
'core.modelTools.importPlanToolDesc': '生成导入计划(只读):分析 ZIP + 合并冲突决策与路径映射,返回 planId 与计划摘要。加密归档直接拒绝(密码不进 agent 面,改走 GUI)。',
|
|
298
|
+
'core.modelTools.importPlanZipPathParam': '归档路径,必须落在受控目录内(exports 或临时目录)',
|
|
299
|
+
'core.modelTools.importPlanStrategyParam': '全局冲突策略:merge 保留冲突待裁决 / replace 覆盖 / skipExisting 跳过已存在',
|
|
300
|
+
'core.modelTools.importPlanResolutionsParam': '逐项裁决表:{ 计划项 id: keepCurrent | useImported | review }',
|
|
301
|
+
'core.modelTools.importPlanPathMappingsParam': '路径映射:把旧机器前缀换成本机前缀',
|
|
302
|
+
'core.modelTools.importPlanMappingOldParam': '归档里的旧路径前缀',
|
|
303
|
+
'core.modelTools.importPlanMappingNewParam': '本机的新路径前缀',
|
|
304
|
+
'core.modelTools.importPlanMappingAppliesToParam': '该映射作用的分区(workspaces / mcp / pluginConfig / skills)',
|
|
305
|
+
'core.modelTools.importPlanOutputDesc': '计划结果(planId / analysis 摘要 / plan 摘要;计划项最多回 50 条)',
|
|
306
|
+
'core.modelTools.importApplyToolDesc': '执行导入计划:必须带 config_import_plan 的 planId + confirm:true。执行前重算计划比对指纹,归档或盘面有变化即拒绝(零写入)。',
|
|
307
|
+
'core.modelTools.importApplyPlanIdParam': 'config_import_plan 返回的 planId',
|
|
308
|
+
'core.modelTools.importApplyConfirmParam': 'true 才真实执行(写盘 + 卸载/安装插件);缺省拒绝',
|
|
309
|
+
'core.modelTools.importApplyRollbackOnErrorParam': '任一项失败时是否整体回滚;缺省 = 引擎默认',
|
|
310
|
+
'core.modelTools.importApplyOutputDesc': '执行结果(executed / missingSecrets 数量 / warnings / rolledBack / rollbackFull)',
|
|
311
|
+
'core.modelTools.errPlanRequired': '真实执行前必须先预览并带上预览返回的 planId(缺省即拒绝写入,防止预览与执行不是同一份计划)',
|
|
312
|
+
'core.modelTools.errPlanChanged': '计划已变化:预览之后磁盘或远端又被改过。请重新预览并确认新的计划后再执行(本次零写入)',
|
|
313
|
+
'core.modelTools.errPlanExpired': 'planId 不存在或已过期(句柄只在本进程内存里存活 30 分钟)。请重新预览取得新的 planId',
|
|
314
|
+
'core.modelTools.errIncludeSecrets': '不允许 agent 触发 includeSecrets:真实凭据值只经 GUI 导出(本工具恒按 includeSecrets:false 执行)',
|
|
315
|
+
'core.modelTools.errSyncPasswordMissing': '通道 {channel} 需要加密密码,但没有可用密码(既未传入,也没在 DSH credentials 里存过)',
|
|
316
|
+
'core.modelTools.errInvalidResolution': '非法的冲突裁决动作「{action}」(可用:keepLocal / useRemote / useMerged / skip)',
|
|
317
|
+
'core.modelTools.errImportUnavailable': '导入引擎不可用:宿主没有注入导入器(该场景请走 GUI 导入)',
|
|
318
|
+
'core.modelTools.errPathNotControlled': 'ZIP 路径不在受控目录内:{path}(只接受 exports 或临时目录下的归档)',
|
|
319
|
+
'core.modelTools.errEncryptedArchive': '归档已加密:解密需要密码,而密码不进 agent 面。请让用户在 GUI 里执行加密导入',
|
|
320
|
+
'core.modelTools.errConfirmRequired': '执行前必须显式传 confirm:true(这是写盘操作,缺省即拒绝)',
|
|
321
|
+
'core.modelTools.nextRepreview': '重新调用预览工具取得新的 planId,再执行',
|
|
322
|
+
'core.modelTools.nextRetryWithoutSecrets': '去掉 includeSecrets 后重试(凭据值请让用户在 GUI 导出)',
|
|
323
|
+
'core.modelTools.nextSaveSyncPassword': '先在 GUI 的同步设置里保存该通道的加密密码,或由用户提供密码后再重试',
|
|
324
|
+
'core.modelTools.nextFixResolution': '把 action 改成 keepLocal / useRemote / useMerged / skip 之一后重试',
|
|
325
|
+
'core.modelTools.nextUseGuiImport': '该场景改走 GUI 导入(配置页 → 导入)',
|
|
326
|
+
'core.modelTools.nextPickControlledZip': '把归档放到 exports 或临时目录后重试,或让用户在 GUI 里选择文件',
|
|
327
|
+
'core.modelTools.nextPassConfirm': '确认计划无误后带 confirm:true 重试',
|
|
328
|
+
|
|
282
329
|
// ---------- backup ----------
|
|
283
330
|
'core.backup.fileSectionBaseMissing': '分区 {section} 是文件类分区,但 core/backup.ts 的 FILE_BASES 未给基准目录(拒绝静默退回 homeDir 根)',
|
|
284
331
|
'core.backup.secretsSectionNotSnapshotTarget': 'secrets 分区没有 adapter / 无分区载荷,不应作为快照目标(凭据值走独立加密容器,绝不进快照)',
|
|
@@ -594,6 +641,53 @@ export const en: Record<keyof typeof zh, string> = {
|
|
|
594
641
|
'core.modelTools.syncPullPasswordParam': 'Decryption password (required for encrypted snapshots; memory only)',
|
|
595
642
|
'core.modelTools.syncPullOutputDesc': 'Diff report (changes list / needsReview)',
|
|
596
643
|
|
|
644
|
+
// ---------- model tools D2–D6: plan handles, password slot, import ----------
|
|
645
|
+
'core.modelTools.restorePlanIdParam': 'The planId returned by the preview; required to actually execute (the server recomputes the plan from the current disk and refuses on any change)',
|
|
646
|
+
'core.modelTools.syncPushPasswordDeprecatedParam': 'Deprecated: the encryption password is read from the DSH credentials slot for this channel first; pass one only for a one-off password (memory only, never written to disk or echoed back)',
|
|
647
|
+
'core.modelTools.syncPushForceParam': 'Overwrite even when another device has advanced the remote (default false = abort on the preflight conflict check; overwrites remote history)',
|
|
648
|
+
'core.modelTools.syncPreviewToolDesc': 'Three-way merge preview (read-only): download the remote snapshot and classify local/remote/ancestor, returning each section decision and conflict locations. Always call it first to obtain the planId. The sessions section never participates.',
|
|
649
|
+
'core.modelTools.syncPreviewSnapshotIdParam': 'Remote snapshot id; default = newest',
|
|
650
|
+
'core.modelTools.syncPreviewPasswordParam': 'Decryption password; the channel stored decryption password is preferred by default (memory only)',
|
|
651
|
+
'core.modelTools.syncPreviewOutputDesc': 'Preview result (planId / summary / decision and conflicts per section)',
|
|
652
|
+
'core.modelTools.syncApplyToolDesc': 'Apply the three-way merge: requires the planId from config_sync_preview. The preview is re-run inside the lock and the fingerprint compared; any change after the preview is refused (zero writes). Writes go through the GLOBAL lock and leave a rollback point.',
|
|
653
|
+
'core.modelTools.syncApplyPlanIdParam': 'The planId returned by config_sync_preview',
|
|
654
|
+
'core.modelTools.syncApplyResolutionsParam': 'Per-section decisions: id = section id (or sectionId::conflictPath), action = keepLocal / useRemote / useMerged / skip',
|
|
655
|
+
'core.modelTools.syncApplyResolutionIdParam': 'Section id or sectionId::conflictPath',
|
|
656
|
+
'core.modelTools.syncApplyResolutionActionParam': 'keepLocal local wins / useRemote remote wins / useMerged use the auto-merged result / skip skip this section',
|
|
657
|
+
'core.modelTools.syncApplyPasswordParam': 'Decryption password; the channel stored decryption password is preferred by default (memory only)',
|
|
658
|
+
'core.modelTools.syncApplyOutputDesc': 'Apply report (applied / restoreId / rolledBack / warnings / pendingConflicts / ignoredResolutions)',
|
|
659
|
+
'core.modelTools.importPlanToolDesc': 'Build an import plan (read-only): analyze the ZIP plus conflict decisions and path mappings, returning the planId and a plan summary. Encrypted archives are refused outright (passwords never enter the agent surface; use the GUI instead).',
|
|
660
|
+
'core.modelTools.importPlanZipPathParam': 'Archive path; must live inside a controlled directory (exports or a temporary directory)',
|
|
661
|
+
'core.modelTools.importPlanStrategyParam': 'Global conflict strategy: merge keeps conflicts for a decision / replace overwrites / skipExisting skips existing',
|
|
662
|
+
'core.modelTools.importPlanResolutionsParam': 'Per-item decisions: { plan item id: keepCurrent | useImported | review }',
|
|
663
|
+
'core.modelTools.importPlanPathMappingsParam': 'Path mappings: rewrite old-machine prefixes to local prefixes',
|
|
664
|
+
'core.modelTools.importPlanMappingOldParam': 'Old path prefix recorded in the archive',
|
|
665
|
+
'core.modelTools.importPlanMappingNewParam': 'New local path prefix',
|
|
666
|
+
'core.modelTools.importPlanMappingAppliesToParam': 'Sections this mapping applies to (workspaces / mcp / pluginConfig / skills)',
|
|
667
|
+
'core.modelTools.importPlanOutputDesc': 'Plan result (planId / analysis summary / plan summary; at most 50 plan items are returned)',
|
|
668
|
+
'core.modelTools.importApplyToolDesc': 'Execute an import plan: requires the planId from config_import_plan plus confirm:true. The plan is recomputed before execution and the fingerprint compared; a changed archive or disk state is refused (zero writes).',
|
|
669
|
+
'core.modelTools.importApplyPlanIdParam': 'The planId returned by config_import_plan',
|
|
670
|
+
'core.modelTools.importApplyConfirmParam': 'true actually executes (writes to disk and uninstalls/installs plugins); refused by default',
|
|
671
|
+
'core.modelTools.importApplyRollbackOnErrorParam': 'Whether to roll back everything when any item fails; default = the engine default',
|
|
672
|
+
'core.modelTools.importApplyOutputDesc': 'Execution result (executed / missingSecrets count / warnings / rolledBack / rollbackFull)',
|
|
673
|
+
'core.modelTools.errPlanRequired': 'Preview first and pass the planId it returned (writes are refused without it, so the executed plan is provably the previewed one)',
|
|
674
|
+
'core.modelTools.errPlanChanged': 'The plan changed: disk or remote was modified after the preview. Preview again, confirm the new plan, then execute (zero writes)',
|
|
675
|
+
'core.modelTools.errPlanExpired': 'The planId does not exist or has expired (handles live in process memory for 30 minutes only). Preview again for a new planId',
|
|
676
|
+
'core.modelTools.errIncludeSecrets': 'Agents may not trigger includeSecrets: real credential values are exported through the GUI only (this tool always runs with includeSecrets:false)',
|
|
677
|
+
'core.modelTools.errSyncPasswordMissing': 'Channel {channel} needs an encryption password but none is available (not passed and none stored in DSH credentials)',
|
|
678
|
+
'core.modelTools.errInvalidResolution': 'Invalid conflict resolution action "{action}" (allowed: keepLocal / useRemote / useMerged / skip)',
|
|
679
|
+
'core.modelTools.errImportUnavailable': 'The import engine is unavailable: the host injected no importer (use the GUI import instead)',
|
|
680
|
+
'core.modelTools.errPathNotControlled': 'The ZIP path is not inside a controlled directory: {path} (only archives under exports or a temporary directory are accepted)',
|
|
681
|
+
'core.modelTools.errEncryptedArchive': 'The archive is encrypted: decryption needs a password and passwords never enter the agent surface. Let the user run the encrypted import in the GUI',
|
|
682
|
+
'core.modelTools.errConfirmRequired': 'Pass confirm:true explicitly to execute (this writes to disk; the default refuses)',
|
|
683
|
+
'core.modelTools.nextRepreview': 'Call the preview tool again to obtain a new planId, then execute',
|
|
684
|
+
'core.modelTools.nextRetryWithoutSecrets': 'Retry without includeSecrets (let the user export credentials in the GUI)',
|
|
685
|
+
'core.modelTools.nextSaveSyncPassword': 'Save the encryption password for this channel in the GUI sync settings, or have the user provide a password, then retry',
|
|
686
|
+
'core.modelTools.nextFixResolution': 'Set action to one of keepLocal / useRemote / useMerged / skip and retry',
|
|
687
|
+
'core.modelTools.nextUseGuiImport': 'Use the GUI import for this case (configuration page → import)',
|
|
688
|
+
'core.modelTools.nextPickControlledZip': 'Move the archive under exports or a temporary directory and retry, or let the user pick the file in the GUI',
|
|
689
|
+
'core.modelTools.nextPassConfirm': 'Pass confirm:true once the plan looks right',
|
|
690
|
+
|
|
597
691
|
// ---------- backup ----------
|
|
598
692
|
'core.backup.fileSectionBaseMissing': 'Section {section} is a file section, but FILE_BASES in core/backup.ts has no base directory (refusing to silently fall back to the homeDir root)',
|
|
599
693
|
'core.backup.secretsSectionNotSnapshotTarget': 'the secrets section has no adapter / no section payload and must not be a snapshot target (credential values use the separate encrypted container and never enter a snapshot)',
|
package/src/core/messages.ts
CHANGED
|
@@ -215,6 +215,10 @@ export const zh = {
|
|
|
215
215
|
'host.snapshotPruneSummary': '自动保留清理删除 {count} 个旧快照',
|
|
216
216
|
'host.autosyncSummary': '自动同步 {direction}{transportSuffix}',
|
|
217
217
|
'host.autosyncTransportSuffix': '({transport})',
|
|
218
|
+
'host.autosyncDirectionPush': '上传',
|
|
219
|
+
'host.autosyncDirectionPull': '下载',
|
|
220
|
+
'host.autosyncDirectionBoth': '双向',
|
|
221
|
+
'host.autosyncDirectionNone': '检查',
|
|
218
222
|
'host.githubMissingClientId': '未配置 GitHub OAuth client_id:请在插件配置中设置 githubClientId(GitHub → Settings → Developer settings → OAuth Apps 注册应用获取)',
|
|
219
223
|
'host.githubFlowGone': 'GitHub 登录流程不存在或已过期,请重新开始',
|
|
220
224
|
'host.restoreBlobEscape': 'blob 路径越界: {blob}',
|
|
@@ -439,6 +443,9 @@ export const zh = {
|
|
|
439
443
|
'sync.workdirModeInvalidFull': '重建工作副本的模式非法: {mode}(只允许 relink(重指向地址)、adopt(采纳远端历史)或 reclone(重新克隆))',
|
|
440
444
|
|
|
441
445
|
'sync.git.cmdFailed': 'git {args} 失败 (exit {code}): {err}',
|
|
446
|
+
// 本机提交身份缺失(真机 issue:commit exit 128 ⇒ 交易 NEEDS_ATTENTION ⇒ 被误升 SAFE MODE)。
|
|
447
|
+
// 文案必须点名「本机配置」,并把「远端/网络/令牌」这三种常见误判方向明确排除。
|
|
448
|
+
'sync.git.identityMissing': 'git 在这台机器上没有可用的提交身份(user.name / user.email 未配置),本次操作被本机 git 拒绝(exit 128,与网络和远端无关)。插件会为同步工作副本自动补写仓库级身份;若仍失败,请在本机执行 git config --global user.name "<名字>" 与 git config --global user.email "<邮箱>" 后重试。原始错误:{err}',
|
|
442
449
|
// 推送认证(真机:公开仓库拉取可匿名成功、推送必失败,git 原文只说「Invalid username or token」)
|
|
443
450
|
'sync.git.pushTokenRequired': '推送需要访问令牌:远端是 http(s) 仓库,但本机没有可用的令牌(拉取公开仓库可以匿名完成,推送必须认证)。请在「同步 → 通道配置」里登录 GitHub 或填入访问令牌后重试。',
|
|
444
451
|
'sync.git.pushAuthFailed': '推送认证失败:{err}。请确认令牌有效且对该仓库有写权限(账号密码推送已被远端禁用);拉取成功不代表令牌可用 —— 公开仓库匿名即可拉取。可在「同步 → 通道配置」里重新登录或更换令牌。',
|
|
@@ -725,6 +732,10 @@ export const en: Record<keyof typeof zh, string> = {
|
|
|
725
732
|
'host.snapshotPruneSummary': 'Automatic retention cleanup removed {count} old snapshot(s)',
|
|
726
733
|
'host.autosyncSummary': 'Autosync {direction}{transportSuffix}',
|
|
727
734
|
'host.autosyncTransportSuffix': ' ({transport})',
|
|
735
|
+
'host.autosyncDirectionPush': 'upload',
|
|
736
|
+
'host.autosyncDirectionPull': 'download',
|
|
737
|
+
'host.autosyncDirectionBoth': 'two-way',
|
|
738
|
+
'host.autosyncDirectionNone': 'check',
|
|
728
739
|
'host.githubMissingClientId': 'GitHub OAuth client_id is not configured: set githubClientId in the plugin config (GitHub → Settings → Developer settings → OAuth Apps → register an app)',
|
|
729
740
|
'host.githubFlowGone': 'The GitHub sign-in flow does not exist or has expired; please start over',
|
|
730
741
|
'host.restoreBlobEscape': 'Blob path outside snapshot directory: {blob}',
|
|
@@ -948,6 +959,9 @@ export const en: Record<keyof typeof zh, string> = {
|
|
|
948
959
|
'sync.workdirModeInvalidFull': 'Invalid working-copy rebuild mode: {mode} (only relink (re-point the address), adopt (merge the remote history) or reclone (clone again) are allowed).',
|
|
949
960
|
|
|
950
961
|
'sync.git.cmdFailed': 'git {args} failed (exit {code}): {err}',
|
|
962
|
+
// Missing local commit identity (real-world issue: commit exit 128 → NEEDS_ATTENTION → wrongly escalated to SAFE MODE).
|
|
963
|
+
// Name the local config and rule out the three usual suspects (remote, network, token).
|
|
964
|
+
'sync.git.identityMissing': 'git has no usable commit identity on this machine (user.name / user.email is unset), so local git refused the operation (exit 128 — unrelated to the network or the remote). The plugin writes a repository-level identity into the sync working copy automatically; if that still fails, run git config --global user.name "<name>" and git config --global user.email "<email>" on this machine and retry. Original error: {err}',
|
|
951
965
|
'sync.git.pushTokenRequired': 'Push requires an access token, but none is available on this machine (public repositories can be fetched anonymously; pushing always needs authentication). Sign in to GitHub or paste an access token under Sync → Channel configuration, then retry.',
|
|
952
966
|
'sync.git.pushAuthFailed': 'Push authentication failed: {err}. Check that the token is valid and has write access to this repository (password authentication is disabled by the remote); a successful pull does not prove the token works — public repositories can be fetched anonymously. Sign in again or replace the token under Sync → Channel configuration.',
|
|
953
967
|
'sync.git.credentialHelperBlocked': 'git cannot run the credential helper on this machine (it needs a shell, and this platform does not allow executing scripts/binaries from the app directory), and retrying with an HTTP authorization header did not work either. Make sure git is 2.31 or newer (injecting config through environment variables needs it) or switch the repository address to ssh. Original error: {err}',
|
|
@@ -23,6 +23,7 @@ import {
|
|
|
23
23
|
makeHistoryFilename, isHistoryBasename,
|
|
24
24
|
isValidHistoryRetention, resolveHistoryRetention,
|
|
25
25
|
HISTORY_RETENTION_MIN, HISTORY_RETENTION_MAX, DEFAULT_MIGRATION_RETENTION,
|
|
26
|
+
isAutosyncIdleRound, autosyncDirectionMessageKey, autosyncUnifiedHistoryInput,
|
|
26
27
|
type StoredMigrationHistoryEntry, type MigrationIo,
|
|
27
28
|
} from './migration-history.ts';
|
|
28
29
|
|
|
@@ -405,6 +406,70 @@ test('best-effort:read 目录不存在 → 空结果不 throw', async (t) => {
|
|
|
405
406
|
assert.equal(res.corrupted.length, 0);
|
|
406
407
|
});
|
|
407
408
|
|
|
409
|
+
// ---------- 自动同步:空检查轮与方向本地化(2026-11-08 实测) ----------
|
|
410
|
+
|
|
411
|
+
test('AUTOSYNC:60s 远端探测的空检查轮(upToDate)不构成活动,其余轮次照记', () => {
|
|
412
|
+
// 真机证据(desktop 档案):sync-history.json 每 60s 一条 upToDate,同期 git 工作副本只有 4 次真实 add。
|
|
413
|
+
assert.equal(isAutosyncIdleRound({ status: 'success', skipReason: 'upToDate' }), true, '命中 upToDate = 什么都没传,是轮询');
|
|
414
|
+
assert.equal(isAutosyncIdleRound({ status: 'success', skipReason: 'unchanged' }), false, 'unchanged 走了下行比对,仍要留痕');
|
|
415
|
+
assert.equal(isAutosyncIdleRound({ status: 'success' }), false, '无 skipReason 的 success = 真的推/拉了');
|
|
416
|
+
assert.equal(isAutosyncIdleRound({ status: 'skipped', skipReason: 'conflict' }), false, '冲突必须留在历史里等用户处理');
|
|
417
|
+
assert.equal(isAutosyncIdleRound({ status: 'failed' }), false, '失败永不静默');
|
|
418
|
+
assert.equal(isAutosyncIdleRound({ status: 'partial', skipReason: 'conflict-kept-local' }), false, '待裁决同属真实事件');
|
|
419
|
+
});
|
|
420
|
+
|
|
421
|
+
test('AUTOSYNC:方向枚举走字典键(两侧同键),未知方向不猜', () => {
|
|
422
|
+
assert.equal(autosyncDirectionMessageKey('push'), 'host.autosyncDirectionPush');
|
|
423
|
+
assert.equal(autosyncDirectionMessageKey('pull'), 'host.autosyncDirectionPull');
|
|
424
|
+
assert.equal(autosyncDirectionMessageKey('both'), 'host.autosyncDirectionBoth');
|
|
425
|
+
assert.equal(autosyncDirectionMessageKey('none'), 'host.autosyncDirectionNone');
|
|
426
|
+
assert.equal(autosyncDirectionMessageKey('bogus'), null, '未知方向返回 null,由调用方原样回显');
|
|
427
|
+
assert.equal(autosyncDirectionMessageKey(undefined), null);
|
|
428
|
+
|
|
429
|
+
// 字典词条本身(zh 逐字 + en 无 CJK)由 engine-locale.test.ts 的 t2 清单钉住,这里只管映射。
|
|
430
|
+
});
|
|
431
|
+
|
|
432
|
+
test('AUTOSYNC:统一历史载荷 —— 空轮不写、方向走字典、失败带原因', () => {
|
|
433
|
+
// 与宿主同口径的桩翻译器(字典词条本身由 engine-locale.test.ts 钉住)。
|
|
434
|
+
const dict: Record<string, string> = {
|
|
435
|
+
'host.autosyncDirectionPush': '上传',
|
|
436
|
+
'host.autosyncDirectionPull': '下载',
|
|
437
|
+
'host.autosyncDirectionBoth': '双向',
|
|
438
|
+
'host.autosyncDirectionNone': '检查',
|
|
439
|
+
};
|
|
440
|
+
const msg = (key: string, params?: Record<string, string | number>): string => {
|
|
441
|
+
if (key === 'host.autosyncSummary') return `自动同步 ${String(params?.direction ?? '')}${String(params?.transportSuffix ?? '')}`;
|
|
442
|
+
if (key === 'host.autosyncTransportSuffix') return `(${String(params?.transport ?? '')})`;
|
|
443
|
+
return dict[key] ?? key;
|
|
444
|
+
};
|
|
445
|
+
|
|
446
|
+
assert.equal(autosyncUnifiedHistoryInput({ status: 'success', skipReason: 'upToDate', direction: 'both' }, msg), null, '空检查轮不产生历史条目');
|
|
447
|
+
|
|
448
|
+
const push = autosyncUnifiedHistoryInput({ status: 'success', direction: 'push', transport: 'git', appliedSections: ['settings'] }, msg);
|
|
449
|
+
assert.ok(push);
|
|
450
|
+
assert.equal(push.result, 'success');
|
|
451
|
+
assert.equal(push.source, 'autosync');
|
|
452
|
+
assert.deepEqual(push.sections, ['settings']);
|
|
453
|
+
assert.equal(push.summary, '自动同步 上传(git)');
|
|
454
|
+
assert.equal(push.error, undefined);
|
|
455
|
+
|
|
456
|
+
// sections 必须是副本:历史条目不得与调用方共享可变数组。
|
|
457
|
+
const owned = ['ui'];
|
|
458
|
+
const shared = autosyncUnifiedHistoryInput({ status: 'skipped', direction: 'both', appliedSections: owned }, msg);
|
|
459
|
+
assert.ok(shared);
|
|
460
|
+
assert.notEqual(shared.sections, owned);
|
|
461
|
+
|
|
462
|
+
const failed = autosyncUnifiedHistoryInput({ status: 'failed', direction: 'pull', error: '鉴权失败' }, msg);
|
|
463
|
+
assert.equal(failed?.result, 'failed');
|
|
464
|
+
assert.equal(failed?.error, '鉴权失败', 'failed 必须带原因(sync-history 的 error 优先)');
|
|
465
|
+
assert.equal(autosyncUnifiedHistoryInput({ status: 'failed', direction: 'pull', skipReason: 'network' }, msg)?.error, 'network');
|
|
466
|
+
|
|
467
|
+
assert.equal(autosyncUnifiedHistoryInput({ status: 'partial', direction: 'both' }, msg)?.result, 'pending', '待裁决不是失败');
|
|
468
|
+
|
|
469
|
+
// 未知方向原样回显,不猜、不吞。
|
|
470
|
+
assert.equal(autosyncUnifiedHistoryInput({ status: 'success', direction: 'weird' }, msg)?.summary, '自动同步 weird');
|
|
471
|
+
});
|
|
472
|
+
|
|
408
473
|
test('BOUND:sanitizeEntry 保留合法 UUID operationId/snapshotId/runId', () => {
|
|
409
474
|
const uuid = '00000000-0000-4000-8000-000000000000';
|
|
410
475
|
const entry = sanitizeEntry(makeRaw({ operationId: uuid, snapshotId: uuid, runId: uuid }));
|
|
@@ -31,6 +31,7 @@ import { maskHighEntropy, redact } from '../security/redaction.ts';
|
|
|
31
31
|
import { scanAndRedact } from '../security/secret-scanner.ts';
|
|
32
32
|
import { sha256Hex } from '../utils/hashing.ts';
|
|
33
33
|
import { coreText, engineMsg } from './messages-core.ts';
|
|
34
|
+
import type { MsgFunc } from './msg-types.ts';
|
|
34
35
|
|
|
35
36
|
// ---------- 常量 ----------
|
|
36
37
|
|
|
@@ -103,6 +104,75 @@ export function historyResultFromAutosyncStatus(status: 'success' | 'skipped' |
|
|
|
103
104
|
return status === 'partial' ? 'pending' : 'failed';
|
|
104
105
|
}
|
|
105
106
|
|
|
107
|
+
/**
|
|
108
|
+
* 自动同步「空检查轮」判定:这一轮既没上传也没下行、更没应用任何分区(sections 恒空),
|
|
109
|
+
* 它只是 realtime 通道缺省每 60s 一次(remoteCheckMs)的远端探测 —— 是**轮询**,不是活动。
|
|
110
|
+
*
|
|
111
|
+
* 为什么必须挡在统一历史之外(2026-11-08 真机实测,desktop 档案):
|
|
112
|
+
* ① 1 条/分钟把首页「最近活动」刷成与真推**完全同形**的 success 行(用户据此报告
|
|
113
|
+
* 「每隔 1 分钟都在推送」,而同期 git 工作副本只有 4 次真实 add/deletes);
|
|
114
|
+
* ② 统一历史保留额度(缺省 1000 条)被空轮吃满:实测 1009 条里 934 条是 autosync,
|
|
115
|
+
* 其中 688 条正是 upToDate 空轮,真实事件(备份 22 / 档案操作 40)被最旧淘汰;
|
|
116
|
+
* ③ /history 是目录全量扫描(条目越多首页越慢),空轮只会让它线性变慢。
|
|
117
|
+
*
|
|
118
|
+
* 不丢诊断:sync-history.json 仍逐轮记录(含 upToDate),同步页「上次运行 / 跳过原因」照常显示。
|
|
119
|
+
*/
|
|
120
|
+
export function isAutosyncIdleRound(entry: { status: string; skipReason?: string }): boolean {
|
|
121
|
+
return entry.status === 'success' && entry.skipReason === 'upToDate';
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* 自动同步方向 → 字典键(`both`/`push`/`pull`/`none` 是机器 token,不得直接铺到界面上)。
|
|
126
|
+
* 未知方向返回 null,由调用方原样回显(不猜、不吞)。
|
|
127
|
+
*/
|
|
128
|
+
export function autosyncDirectionMessageKey(direction: unknown): string | null {
|
|
129
|
+
switch (direction) {
|
|
130
|
+
case 'push': return 'host.autosyncDirectionPush';
|
|
131
|
+
case 'pull': return 'host.autosyncDirectionPull';
|
|
132
|
+
case 'both': return 'host.autosyncDirectionBoth';
|
|
133
|
+
case 'none': return 'host.autosyncDirectionNone';
|
|
134
|
+
default: return null;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/** 自动同步一轮 → 统一历史条目的载荷(不写则为 null)。 */
|
|
139
|
+
export type AutosyncHistoryInput = Pick<MigrationHistoryEntry, 'result' | 'sections' | 'source' | 'summary' | 'error'>;
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* 自动同步一轮 → 统一历史条目;空检查轮返回 null(调用方直接 return,不写)。
|
|
143
|
+
*
|
|
144
|
+
* 规则落在 core 而不是宿主闭包里:宿主 src/index.ts 有体量棘轮(tests/file-size-ratchet.test.ts),
|
|
145
|
+
* 且这几条判断本身要能单测(空轮不写 / 方向本地化 / failed 带原因)。
|
|
146
|
+
* msg 由调用方注入(宿主传 engineMsg),本模块只管查表不引入新状态。
|
|
147
|
+
*/
|
|
148
|
+
export function autosyncUnifiedHistoryInput(
|
|
149
|
+
entry: {
|
|
150
|
+
status: 'success' | 'skipped' | 'partial' | 'failed';
|
|
151
|
+
direction?: unknown;
|
|
152
|
+
skipReason?: string;
|
|
153
|
+
transport?: string;
|
|
154
|
+
error?: string;
|
|
155
|
+
appliedSections?: string[];
|
|
156
|
+
},
|
|
157
|
+
msg: MsgFunc = engineMsg,
|
|
158
|
+
): AutosyncHistoryInput | null {
|
|
159
|
+
if (isAutosyncIdleRound(entry)) return null;
|
|
160
|
+
const directionKey = autosyncDirectionMessageKey(entry.direction);
|
|
161
|
+
const transport = entry.transport;
|
|
162
|
+
const input: AutosyncHistoryInput = {
|
|
163
|
+
result: historyResultFromAutosyncStatus(entry.status),
|
|
164
|
+
sections: entry.appliedSections === undefined ? [] : [...entry.appliedSections],
|
|
165
|
+
source: 'autosync',
|
|
166
|
+
summary: msg('host.autosyncSummary', {
|
|
167
|
+
direction: directionKey === null ? String(entry.direction ?? '') : msg(directionKey),
|
|
168
|
+
transportSuffix: transport === undefined || transport === '' ? '' : msg('host.autosyncTransportSuffix', { transport }),
|
|
169
|
+
}),
|
|
170
|
+
};
|
|
171
|
+
const error = entry.status === 'failed' ? (entry.error ?? entry.skipReason) : undefined;
|
|
172
|
+
if (error !== undefined) input.error = error;
|
|
173
|
+
return input;
|
|
174
|
+
}
|
|
175
|
+
|
|
106
176
|
/** 触发来源(常量)。 */
|
|
107
177
|
export type MigrationSource = 'api' | 'autosync' | 'backup-scheduler' | 'recovery' | 'cli' | 'internal';
|
|
108
178
|
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 计划句柄与指纹的单测(D2/D5/D6 的判定基元):
|
|
3
|
+
* - ModelPlanStore:TTL 过期、容量驱逐、同指纹幂等覆盖、delete 后不可重放
|
|
4
|
+
* - syncMergeFingerprint:绝不把三侧预览文本算进指纹(否则同一裁决清单会因展示文本抖动而「计划已变」)
|
|
5
|
+
* - importPlanFingerprint:只看会改变执行结果的结构字段,description/detail 抖动不影响
|
|
6
|
+
* - stableStringify:对象键序无关
|
|
7
|
+
* - restorePlanFingerprint:只吃 kind/target/blobPath
|
|
8
|
+
*/
|
|
9
|
+
import test from 'node:test'
|
|
10
|
+
import assert from 'node:assert/strict'
|
|
11
|
+
|
|
12
|
+
import {
|
|
13
|
+
MODEL_PLAN_MAX, MODEL_PLAN_TTL_MS, ModelPlanStore, importPlanFingerprint, stableStringify, syncMergeFingerprint,
|
|
14
|
+
} from './model-tool-plans.ts'
|
|
15
|
+
import { restorePlanFingerprint } from './restore-plan-fingerprint.ts'
|
|
16
|
+
import type { ImportDecisions, ImportPlan } from './types.ts'
|
|
17
|
+
import type { MergePreview } from '../sync/sync-engine.ts'
|
|
18
|
+
|
|
19
|
+
test('ModelPlanStore:同指纹重复登记 → 同一 id(幂等覆盖),不占额外槽位', () => {
|
|
20
|
+
const store = new ModelPlanStore()
|
|
21
|
+
const a = store.set('restore', 'fp-1', { snapshotId: 's1' })
|
|
22
|
+
const b = store.set('restore', 'fp-1', { snapshotId: 's1' })
|
|
23
|
+
assert.equal(a, 'fp-1')
|
|
24
|
+
assert.equal(b, 'fp-1')
|
|
25
|
+
assert.equal(store.size, 1)
|
|
26
|
+
})
|
|
27
|
+
|
|
28
|
+
test('ModelPlanStore:超过上限驱逐最旧;TTL 过期即失效(不可重放)', async () => {
|
|
29
|
+
const store = new ModelPlanStore()
|
|
30
|
+
for (let i = 0; i < MODEL_PLAN_MAX + 2; i += 1) store.set('import', 'fp-' + i, { zipPath: '/z' })
|
|
31
|
+
assert.equal(store.size, MODEL_PLAN_MAX, '容量上限生效')
|
|
32
|
+
assert.equal(store.get('fp-0'), undefined, '最旧的被驱逐')
|
|
33
|
+
assert.notEqual(store.get('fp-' + (MODEL_PLAN_MAX + 1)), undefined, '最新的保留')
|
|
34
|
+
|
|
35
|
+
// 可控时钟:不靠 sleep,直接跨过 TTL。
|
|
36
|
+
const clock = { t: 1_000_000 }
|
|
37
|
+
const shortLived = new ModelPlanStore(() => clock.t)
|
|
38
|
+
shortLived.set('import', 'fp-x', { zipPath: '/z' })
|
|
39
|
+
assert.ok(shortLived.get('fp-x') !== undefined, 'TTL 内可读')
|
|
40
|
+
clock.t += MODEL_PLAN_TTL_MS + 1
|
|
41
|
+
assert.equal(shortLived.get('fp-x'), undefined, '过期记录读不到')
|
|
42
|
+
assert.equal(shortLived.size, 0, '读到过期即清')
|
|
43
|
+
assert.equal(MODEL_PLAN_TTL_MS, 30 * 60 * 1000)
|
|
44
|
+
})
|
|
45
|
+
|
|
46
|
+
test('ModelPlanStore:delete 后同一 id 不可重放', () => {
|
|
47
|
+
const store = new ModelPlanStore()
|
|
48
|
+
store.set('restore', 'fp', { snapshotId: 's1' })
|
|
49
|
+
store.delete('fp')
|
|
50
|
+
assert.equal(store.get('fp'), undefined)
|
|
51
|
+
})
|
|
52
|
+
|
|
53
|
+
test('stableStringify:对象键序不影响结果', () => {
|
|
54
|
+
assert.equal(stableStringify({ b: 1, a: 2 }), stableStringify({ a: 2, b: 1 }))
|
|
55
|
+
assert.notEqual(stableStringify({ a: 1 }), stableStringify({ a: 2 }))
|
|
56
|
+
})
|
|
57
|
+
|
|
58
|
+
test('syncMergeFingerprint:只看裁决清单,三侧预览文本与展示字段不参与', () => {
|
|
59
|
+
const base = {
|
|
60
|
+
ok: true, snapshotId: 'snap', hasAncestor: true,
|
|
61
|
+
sections: [{ id: 'settings', decision: 'review', conflictCount: 1, conflicts: [{ path: 'x', kind: 'key' }] }],
|
|
62
|
+
summary: { auto: 0, review: 1, conflicts: 1, skipped: 0 },
|
|
63
|
+
} as unknown as MergePreview
|
|
64
|
+
const noisy = JSON.parse(JSON.stringify(base)) as MergePreview
|
|
65
|
+
;(noisy.sections[0]!.conflicts[0] as unknown as Record<string, string>).localPreview = '本地文本 A'
|
|
66
|
+
;(noisy.sections[0]!.conflicts[0] as unknown as Record<string, string>).remotePreview = '远端文本 B'
|
|
67
|
+
assert.equal(syncMergeFingerprint(base), syncMergeFingerprint(noisy), '展示文本抖动不该让计划失效')
|
|
68
|
+
|
|
69
|
+
const changed = JSON.parse(JSON.stringify(base)) as MergePreview
|
|
70
|
+
;(changed.sections[0] as unknown as Record<string, string>).decision = 'auto'
|
|
71
|
+
assert.notEqual(syncMergeFingerprint(base), syncMergeFingerprint(changed), '裁决变化必须改变指纹')
|
|
72
|
+
})
|
|
73
|
+
|
|
74
|
+
function makePlan(overrides: Partial<ImportPlan> = {}): ImportPlan {
|
|
75
|
+
return {
|
|
76
|
+
items: [{ id: 'settings:general', kind: 'Skip', adapter: 'settings', description: '描述', severity: 'info' }],
|
|
77
|
+
globalStrategy: 'merge',
|
|
78
|
+
pathMappings: [],
|
|
79
|
+
missingSecrets: [],
|
|
80
|
+
needsRestart: false,
|
|
81
|
+
estimatedActions: {},
|
|
82
|
+
...overrides,
|
|
83
|
+
} as ImportPlan
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
const decisions: ImportDecisions = { strategy: 'merge', resolutions: {}, pathMappings: [] }
|
|
87
|
+
|
|
88
|
+
test('importPlanFingerprint:description/detail 抖动不影响,item kind 或决策变化必须变', () => {
|
|
89
|
+
const plan = makePlan()
|
|
90
|
+
const relabeled = makePlan({
|
|
91
|
+
items: [{ id: 'settings:general', kind: 'Skip', adapter: 'settings', description: '换个说明', severity: 'info' }],
|
|
92
|
+
})
|
|
93
|
+
assert.equal(importPlanFingerprint(plan, decisions), importPlanFingerprint(relabeled, decisions))
|
|
94
|
+
|
|
95
|
+
const retyped = makePlan({
|
|
96
|
+
items: [{ id: 'settings:general', kind: 'Update', adapter: 'settings', description: '描述', severity: 'info' }],
|
|
97
|
+
})
|
|
98
|
+
assert.notEqual(importPlanFingerprint(plan, decisions), importPlanFingerprint(retyped, decisions))
|
|
99
|
+
|
|
100
|
+
const replaceFirst = { ...decisions, strategy: 'replace' as const }
|
|
101
|
+
assert.notEqual(importPlanFingerprint(plan, decisions), importPlanFingerprint(plan, replaceFirst))
|
|
102
|
+
})
|
|
103
|
+
|
|
104
|
+
test('restorePlanFingerprint:只吃 kind/target/blobPath', () => {
|
|
105
|
+
const a = { actions: [{ kind: 'fileRestore', description: '恢复 a', target: '/a' }] }
|
|
106
|
+
const b = { actions: [{ kind: 'fileRestore', description: '换个说法', target: '/a' }] }
|
|
107
|
+
const c = { actions: [{ kind: 'fileRestore', description: '恢复 a', target: '/b' }] }
|
|
108
|
+
assert.equal(restorePlanFingerprint(a as never), restorePlanFingerprint(b as never))
|
|
109
|
+
assert.notEqual(restorePlanFingerprint(a as never), restorePlanFingerprint(c as never))
|
|
110
|
+
})
|
|
111
|
+
|