dsh-config-manager 0.6.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.
Files changed (112) hide show
  1. package/lib/adapters/test-helpers.d.ts +7 -0
  2. package/lib/adapters/test-helpers.js +11 -0
  3. package/lib/cli/actions.js +1 -1
  4. package/lib/client.d.ts +14 -2
  5. package/lib/client.js +722 -647
  6. package/lib/core/backup.d.ts +9 -1
  7. package/lib/core/backup.js +21 -0
  8. package/lib/core/local-plugin-host.d.ts +9 -0
  9. package/lib/core/local-plugin-host.js +174 -1
  10. package/lib/core/messages-core.d.ts +3 -0
  11. package/lib/core/messages-core.js +6 -0
  12. package/lib/core/messages.d.ts +8 -0
  13. package/lib/core/messages.js +18 -0
  14. package/lib/core/model-tools.js +2 -0
  15. package/lib/core/phase4-crash-child.js +1 -1
  16. package/lib/core/plugin-cli.d.ts +11 -0
  17. package/lib/core/plugin-cli.js +30 -0
  18. package/lib/core/restore-wal.d.ts +2 -0
  19. package/lib/core/restore-wal.js +11 -6
  20. package/lib/core/restore.d.ts +15 -2
  21. package/lib/core/restore.js +65 -3
  22. package/lib/core/run-registry.d.ts +10 -0
  23. package/lib/core/run-registry.js +17 -0
  24. package/lib/core/snapshot-diff.js +2 -1
  25. package/lib/core/types.d.ts +32 -0
  26. package/lib/index.d.ts +8 -2
  27. package/lib/index.js +24 -21
  28. package/lib/routes/import.js +6 -1
  29. package/lib/routes/route-support.d.ts +7 -1
  30. package/lib/routes/route-support.js +36 -5
  31. package/lib/routes/sync.js +8 -2
  32. package/lib/sync/autosync-config.d.ts +9 -1
  33. package/lib/sync/autosync-config.js +10 -2
  34. package/lib/sync/autosync-scheduler.js +18 -6
  35. package/lib/sync/git/git-transport.d.ts +31 -1
  36. package/lib/sync/git/git-transport.js +119 -23
  37. package/lib/sync/merge-preview-view.d.ts +78 -0
  38. package/lib/sync/merge-preview-view.js +46 -0
  39. package/lib/sync/merge.d.ts +2 -1
  40. package/lib/sync/merge.js +9 -4
  41. package/lib/sync/plugin-removal-apply.d.ts +95 -0
  42. package/lib/sync/plugin-removal-apply.js +158 -0
  43. package/lib/sync/plugin-removals.d.ts +90 -0
  44. package/lib/sync/plugin-removals.js +167 -0
  45. package/lib/sync/sync-config.d.ts +34 -3
  46. package/lib/sync/sync-config.js +38 -5
  47. package/lib/sync/sync-engine.d.ts +34 -43
  48. package/lib/sync/sync-engine.js +50 -42
  49. package/lib/sync/sync-selection.d.ts +8 -0
  50. package/lib/sync/sync-selection.js +6 -0
  51. package/lib/sync/workspace-merge.d.ts +8 -1
  52. package/lib/ui/restore-plan-view.js +1 -0
  53. package/lib/ui/sync-settings-view.d.ts +14 -0
  54. package/lib/ui/sync-settings-view.js +5 -0
  55. package/package.json +1 -1
  56. package/src/adapters/test-helpers.ts +10 -0
  57. package/src/cli/actions.ts +1 -1
  58. package/src/client/common/info-hint-guard.test.ts +2 -1
  59. package/src/client/run-store.test.ts +8 -6
  60. package/src/client/run-store.ts +9 -5
  61. package/src/client/sync/ChannelConfigDialog.tsx +15 -1
  62. package/src/client/sync/SyncPanel.tsx +16 -0
  63. package/src/client/sync/SyncSectionPickerDialog.tsx +17 -1
  64. package/src/client/sync/sync-api.ts +2 -0
  65. package/src/client/sync/sync-locales.ts +10 -0
  66. package/src/client/sync/sync-view.ts +6 -0
  67. package/src/core/backup.ts +21 -1
  68. package/src/core/local-plugin-host.test.ts +31 -2
  69. package/src/core/local-plugin-host.ts +175 -2
  70. package/src/core/messages-core.ts +6 -0
  71. package/src/core/messages.ts +18 -0
  72. package/src/core/model-tools.ts +2 -0
  73. package/src/core/phase4-crash-child.ts +1 -1
  74. package/src/core/plugin-cli.ts +37 -0
  75. package/src/core/restore-plugin-install.test.ts +116 -0
  76. package/src/core/restore-wal.ts +12 -6
  77. package/src/core/restore.ts +79 -4
  78. package/src/core/run-registry-runs.test.ts +26 -1
  79. package/src/core/run-registry.ts +18 -0
  80. package/src/core/smoke.test.ts +5 -0
  81. package/src/core/snapshot-diff.test.ts +1 -1
  82. package/src/core/snapshot-diff.ts +2 -1
  83. package/src/core/types.ts +31 -0
  84. package/src/index.sync.test.ts +27 -0
  85. package/src/index.ts +30 -28
  86. package/src/routes/import.ts +6 -1
  87. package/src/routes/route-support.ts +34 -5
  88. package/src/routes/sync.ts +8 -2
  89. package/src/security/security.test.ts +1 -0
  90. package/src/sync/autosync-config.ts +10 -2
  91. package/src/sync/autosync-scheduler.test.ts +61 -1
  92. package/src/sync/autosync-scheduler.ts +17 -5
  93. package/src/sync/git/git-transport.test.ts +117 -0
  94. package/src/sync/git/git-transport.ts +131 -23
  95. package/src/sync/merge-preview-view.ts +97 -0
  96. package/src/sync/merge.test.ts +17 -15
  97. package/src/sync/merge.ts +10 -3
  98. package/src/sync/plugin-removal-apply.ts +198 -0
  99. package/src/sync/plugin-removals.test.ts +221 -0
  100. package/src/sync/plugin-removals.ts +208 -0
  101. package/src/sync/sync-config.test.ts +59 -1
  102. package/src/sync/sync-config.ts +51 -5
  103. package/src/sync/sync-engine.test.ts +251 -1
  104. package/src/sync/sync-engine.ts +84 -83
  105. package/src/sync/sync-selection.test.ts +29 -7
  106. package/src/sync/sync-selection.ts +13 -0
  107. package/src/sync/workspace-merge.ts +9 -0
  108. package/src/ui/restore-plan-view.test.ts +1 -1
  109. package/src/ui/restore-plan-view.ts +1 -0
  110. package/src/ui/snapshots-view.test.ts +1 -1
  111. package/src/ui/sync-settings-view.test.ts +21 -0
  112. package/src/ui/sync-settings-view.ts +19 -0
@@ -29,7 +29,7 @@ import { isPatchLayerRel } from './patch-layers.js';
29
29
  import { expectedSessionRefs, sweepGhostSessions } from './ghost-sweep.js';
30
30
  import { zhMsg } from './messages.js';
31
31
  import { classifyDshPluginFailure, readInstalled, readInstalledVersion, resolveProfileDir, runDshPlugin, } from './plugin-cli.js';
32
- import { collectRestoreWalEntries, createRestoreWal, restoreActionStepId, restoreWalHandlesFromSteps, } from './restore-wal.js';
32
+ import { collectRestoreWalEntries, createRestoreWal, isExternalPluginKind, restoreActionStepId, restoreWalHandlesFromSteps, } from './restore-wal.js';
33
33
  import { parseJsonSafe } from '../utils/json.js';
34
34
  import { isPathInside } from '../utils/paths.js';
35
35
  import { atomicCopyFile, atomicWriteFile } from '../utils/atomic-write.js';
@@ -265,6 +265,24 @@ async function defaultPluginUninstaller(name, profileDir, profile, msg) {
265
265
  const tail = output.split('\n').slice(-8).join('\n') || msg('restore.noOutput');
266
266
  return { ok: false, message: msg('restore.uninstallFailedExit', { name, code: String(result.exitCode), tail }) };
267
267
  }
268
+ /**
269
+ * 默认插件重装器(issue #132 undo):官方 dsh plugin add 通道 + 失败分类诊断。
270
+ *
271
+ * 与卸载器同口径:非 0 退出先归类(已知失败码给准确文案),否则回落到退出码 + 输出尾部。
272
+ * 绝不在这里做版本回退/猜测 —— target 就是快照里记下的 `name@version`。
273
+ */
274
+ async function defaultPluginInstaller(name, target, profileDir, profile, msg) {
275
+ const result = await runDshPlugin(profileDir, profile, ['add', target]);
276
+ if (result.exitCode === 0)
277
+ return { ok: true };
278
+ const output = `${result.stderr}\n${result.stdout}`.trim();
279
+ const failure = classifyDshPluginFailure(output);
280
+ if (failure !== null) {
281
+ return { ok: false, message: msg('restore.installFailedCode', { name, code: failure.code, message: failure.message }) };
282
+ }
283
+ const tail = output.split('\n').slice(-8).join('\n') || msg('restore.noOutput');
284
+ return { ok: false, message: msg('restore.installFailedExit', { name, code: String(result.exitCode), tail }) };
285
+ }
268
286
  /** 递归检查快照目录内关键文件非 symlink(F25:拒绝 symlink 化 metadata/blob 写穿)。 */
269
287
  async function assertNoSnapshotSymlink(dir, rel) {
270
288
  const p = path.join(dir, rel);
@@ -496,6 +514,29 @@ export async function planRestore(opts) {
496
514
  });
497
515
  }
498
516
  }
517
+ // 2') 插件重装(issue #132 跟远端删插件的反向):只认快照里**明确记录过**的跟删项。
518
+ // 为什么不按 beforePlugins 反推「缺了就是被删了」:手动卸载/换包也会让基线里的名字消失,
519
+ // 那种情况下重装是替用户改主意。记录过的才装回;现在已存在的直接跳过。
520
+ const recordedRemovals = snapshot.pluginRemovals ?? [];
521
+ if (recordedRemovals.length > 0) {
522
+ const installed = readInstalled(profileDir);
523
+ for (const removal of recordedRemovals) {
524
+ if (Object.hasOwn(installed, removal.name)) {
525
+ actions.push({
526
+ kind: 'skip',
527
+ description: msg('restore.pluginInstallAlreadyPresent', { name: removal.name }),
528
+ });
529
+ continue;
530
+ }
531
+ actions.push({
532
+ kind: 'pluginInstall',
533
+ description: msg('restore.pluginInstall', { name: removal.name, version: removal.version }),
534
+ target: removal.name,
535
+ pluginName: removal.name,
536
+ pluginTarget: removal.target,
537
+ });
538
+ }
539
+ }
499
540
  // 3) file 类条目补偿 + credentials 提示(聚合计数供报告)
500
541
  let namespaceCount = 0;
501
542
  let patchLineCount = 0;
@@ -649,7 +690,7 @@ export async function planRestore(opts) {
649
690
  }
650
691
  function summarizeActions(actions) {
651
692
  const summary = {
652
- hostFileRestores: 0, hostFileRemoves: 0, pluginRemoves: 0,
693
+ hostFileRestores: 0, hostFileRemoves: 0, pluginRemoves: 0, pluginInstalls: 0,
653
694
  fileRestores: 0, fileRemoves: 0, credentialHints: 0, skips: 0,
654
695
  };
655
696
  for (const a of actions) {
@@ -663,6 +704,9 @@ function summarizeActions(actions) {
663
704
  case 'pluginRemove':
664
705
  summary.pluginRemoves += 1;
665
706
  break;
707
+ case 'pluginInstall':
708
+ summary.pluginInstalls += 1;
709
+ break;
666
710
  case 'fileRestore':
667
711
  summary.fileRestores += 1;
668
712
  break;
@@ -693,10 +737,13 @@ export async function restore(opts) {
693
737
  const profileDir = resolveProfileDir(homeDir, profile);
694
738
  const uninstaller = opts.pluginUninstaller
695
739
  ?? ((name, dir, prof) => defaultPluginUninstaller(name, dir, prof, msg));
740
+ const installer = opts.pluginInstaller
741
+ ?? ((name, target, dir, prof) => defaultPluginInstaller(name, target, dir, prof, msg));
696
742
  const report = {
697
743
  snapshotId: plan.snapshotId,
698
744
  restored: [],
699
745
  removedPlugins: [],
746
+ installedPlugins: [],
700
747
  manualHints: [],
701
748
  failed: [],
702
749
  skipped: [],
@@ -737,7 +784,7 @@ export async function restore(opts) {
737
784
  }
738
785
  /** 文件类动作的绝对目标(reconcile 直接拿它读盘算指纹);插件卸载/越界目标 → null(不可指纹)。 */
739
786
  function walAbsOf(action) {
740
- if (action.kind === 'pluginRemove' || action.target === undefined)
787
+ if (isExternalPluginKind(action.kind) || action.target === undefined)
741
788
  return null;
742
789
  try {
743
790
  return homeAbs(homeDir, action.target, msg);
@@ -818,6 +865,21 @@ export async function restore(opts) {
818
865
  }
819
866
  break;
820
867
  }
868
+ case 'pluginInstall': {
869
+ const target = action.pluginTarget ?? action.pluginName;
870
+ const result = await installer(action.pluginName, target, profileDir, profile);
871
+ if (result.ok) {
872
+ report.installedPlugins.push(target);
873
+ }
874
+ else {
875
+ const reason = result.message ?? msg('restore.pluginInstallFailed');
876
+ report.failed.push({ item: `plugin:${action.pluginName}`, reason });
877
+ // 同卸载分支:外部副作用没做成 → attention(绝不记 done)
878
+ settleStatus = 'attention';
879
+ settleMessage = reason;
880
+ }
881
+ break;
882
+ }
821
883
  case 'credentialHint':
822
884
  report.manualHints.push(action.manualHint ?? action.description);
823
885
  break;
@@ -86,6 +86,16 @@ export interface RunRegistryOptions {
86
86
  * 内存 run 注册表。Node 单线程 + 同步 Map 读写,无并发竞争;
87
87
  * 所有公开读方法返回状态副本,防止外部直接篡改内部状态。
88
88
  */
89
+ /**
90
+ * 自动同步「空转」run:60s 一次的远端探测拿到 upToDate —— 本轮既没上传也没下行、没应用任何分区。
91
+ *
92
+ * 为什么要过滤(2026-11-09 真机):realtime 通道每轮都会 register('autosync'),于是运行中心每分钟
93
+ * 多一张「自动同步 · 已完成」卡片,与「迁移历史」同一种噪音(那边已由 isAutosyncIdleRound 挡住)。
94
+ * 轮询不是活动;真干活(push/pull/冲突/失败)的卡片必须留着 —— 它们才解释「刚才发生了什么」。
95
+ *
96
+ * 判定只认 run 自己的 result.idle(由调度器收尾时写入),不在 UI 猜 skipReason。
97
+ */
98
+ export declare function isIdleAutosyncRun(state: Pick<RunState, 'kind' | 'status' | 'result'>): boolean;
89
99
  export declare class RunRegistry {
90
100
  private readonly runs;
91
101
  private readonly retentionMs;
@@ -65,6 +65,23 @@ export const DEFAULT_RUN_STALLED_MS = 6 * 60 * 60 * 1000;
65
65
  * 内存 run 注册表。Node 单线程 + 同步 Map 读写,无并发竞争;
66
66
  * 所有公开读方法返回状态副本,防止外部直接篡改内部状态。
67
67
  */
68
+ /**
69
+ * 自动同步「空转」run:60s 一次的远端探测拿到 upToDate —— 本轮既没上传也没下行、没应用任何分区。
70
+ *
71
+ * 为什么要过滤(2026-11-09 真机):realtime 通道每轮都会 register('autosync'),于是运行中心每分钟
72
+ * 多一张「自动同步 · 已完成」卡片,与「迁移历史」同一种噪音(那边已由 isAutosyncIdleRound 挡住)。
73
+ * 轮询不是活动;真干活(push/pull/冲突/失败)的卡片必须留着 —— 它们才解释「刚才发生了什么」。
74
+ *
75
+ * 判定只认 run 自己的 result.idle(由调度器收尾时写入),不在 UI 猜 skipReason。
76
+ */
77
+ export function isIdleAutosyncRun(state) {
78
+ if (state.kind !== 'autosync' || state.status === 'running')
79
+ return false;
80
+ const result = state.result;
81
+ if (result === null || typeof result !== 'object')
82
+ return false;
83
+ return result.idle === true;
84
+ }
68
85
  export class RunRegistry {
69
86
  runs = new Map();
70
87
  retentionMs;
@@ -83,6 +83,7 @@ function statusOf(kind, beforeExists) {
83
83
  case 'fileRemove':
84
84
  return 'deleted';
85
85
  case 'pluginRemove':
86
+ case 'pluginInstall':
86
87
  return 'plugin';
87
88
  case 'credentialHint':
88
89
  return 'hint';
@@ -225,7 +226,7 @@ export async function summarizeRestoreChanges(opts) {
225
226
  entries.push(entry);
226
227
  continue;
227
228
  }
228
- if (action.kind === 'pluginRemove')
229
+ if (action.kind === 'pluginRemove' || action.kind === 'pluginInstall')
229
230
  entry.status = 'plugin';
230
231
  else if (action.kind === 'credentialHint')
231
232
  entry.status = 'hint';
@@ -267,6 +267,16 @@ export interface PluginsFacade {
267
267
  needsRestart: boolean;
268
268
  installedVersion?: string | null;
269
269
  }>;
270
+ /**
271
+ * 卸载插件(issue #132 跟随远端删除;`dsh plugin remove <pkg>`)。
272
+ *
273
+ * 失败即抛(消息经 `classifyDshPluginFailure` 给出可操作诊断,例如 desktop 保留档案被 CLI 拒绝)。
274
+ * 调用方逐项记录 warning、**不阻断**其余项:一次卸载失败不该让整轮同步回滚。
275
+ * `signal` 中止语义与 install 一致(宿主 kill 子进程)。
276
+ */
277
+ uninstall(pkg: string, signal?: AbortSignal): Promise<{
278
+ needsRestart: boolean;
279
+ }>;
270
280
  }
271
281
  export interface WorkspaceFacade {
272
282
  listRecords(): Promise<WorkspaceRecord[]>;
@@ -1040,6 +1050,20 @@ export interface HostFileBackup {
1040
1050
  */
1041
1051
  unreadable?: boolean;
1042
1052
  }
1053
+ /**
1054
+ * 一轮同步里**跟随远端删除**掉的插件(issue #132)。
1055
+ *
1056
+ * 为什么写进快照:undo 必须能把用户装回去 —— 删插件是不可逆的外部副作用,只有快照记得
1057
+ * 「删的是谁、哪个版本」。有意**不进** computeMetadataHash(它只覆盖 entries/hostFileBackups/
1058
+ * beforePlugins 三样破坏性内容),因此记录它不需要重写 manifest 与 blob。
1059
+ */
1060
+ export interface SnapshotPluginRemoval {
1061
+ name: string;
1062
+ /** 删除时本机已装的版本(快照记的是事实;重装用 target = name@version) */
1063
+ version: string;
1064
+ /** 重装目标(name@version;版本未知时就是裸包名) */
1065
+ target: string;
1066
+ }
1043
1067
  export interface Snapshot {
1044
1068
  id: string;
1045
1069
  createdAt: string;
@@ -1049,6 +1073,8 @@ export interface Snapshot {
1049
1073
  status?: SnapshotStatus;
1050
1074
  /** 导入前已安装插件清单(M2 restore 撤销插件时与当前已装对比)。旧快照缺省 */
1051
1075
  beforePlugins?: PluginInfo[];
1076
+ /** 本轮跟随远端删除的插件(issue #132;restore 计划里对称地重装)。旧快照缺省 */
1077
+ pluginRemovals?: SnapshotPluginRemoval[];
1052
1078
  /** 宿主整文件备份(settings.yaml / settings.json / cordis.patch.yml / profiles/<p>/cordis.patch.yml)。旧快照缺省 */
1053
1079
  hostFileBackups?: HostFileBackup[];
1054
1080
  /**
@@ -1096,6 +1122,12 @@ export interface SnapshotStore {
1096
1122
  readBlob(id: string, blobPath: string): Promise<Uint8Array>;
1097
1123
  /** 标记快照生命周期状态(导入成功→done;失败回滚→rolled-back;持久化由实现负责) */
1098
1124
  updateStatus(id: string, status: SnapshotStatus): Promise<void>;
1125
+ /**
1126
+ * 记录「本轮跟删掉的插件」(issue #132):只重写 snapshot.json 的这一个字段,
1127
+ * 不动 manifest 与 blob(它不在 metadataHash 覆盖面内)。不可用时调用方**跳过记录**并靠
1128
+ * 报告里的重装目标人工兜底,绝不因为记不上就中止同步。
1129
+ */
1130
+ recordPluginRemovals?(id: string, removals: SnapshotPluginRemoval[]): Promise<void>;
1099
1131
  }
1100
1132
  /**
1101
1133
  * Phase 4 生产 journal↔snapshot 绑定 context(由宿主注入引擎,引擎在首 destructive side effect 前调用)。
package/lib/index.d.ts CHANGED
@@ -75,7 +75,7 @@ export declare const name = "config-manager";
75
75
  /** Services required before the engine can mount (present in every profile). */
76
76
  export declare const inject: string[];
77
77
  /** Plugin version, kept in sync with package.json ("version"). */
78
- export declare const PLUGIN_VERSION = "0.6.0";
78
+ export declare const PLUGIN_VERSION = "0.8.0";
79
79
  /**
80
80
  * Star 引导弹窗指向的 GitHub 仓库(用户引导点 Star 的目标)。
81
81
  * 与 package.json 的 repository 字段保持一致;界面不可改(硬编码,参照
@@ -188,6 +188,10 @@ export declare class DshPluginsFacade implements PluginsFacade {
188
188
  needsRestart: boolean;
189
189
  installedVersion?: string | null;
190
190
  }>;
191
+ /** 卸载插件(issue #132):走官方 CLI `dsh plugin remove`,不自己改 package.json、也不补对账。 */
192
+ uninstall(pkg: string, signal?: AbortSignal): Promise<{
193
+ needsRestart: boolean;
194
+ }>;
191
195
  }
192
196
  /**
193
197
  * 宿主 `sessionPersistence` 的 API 形状(**按 API 形状探测,绝不按 DSH 版本号猜**)。
@@ -818,12 +822,13 @@ export type RouteEnvInferred = {
818
822
  syncWorkDir: {
819
823
  inspect: (repoUrl: string, opts?: {
820
824
  detail?: boolean;
825
+ subdir?: string;
821
826
  }) => Promise<{
822
827
  facts: GitWorkDirFacts;
823
828
  } | {
824
829
  error: string;
825
830
  }>;
826
- rebuild: (repoUrl: string, mode: 'relink' | 'adopt' | 'reclone') => Promise<GitWorkDirFacts>;
831
+ rebuild: (repoUrl: string, mode: 'relink' | 'adopt' | 'reclone', subdir?: string) => Promise<GitWorkDirFacts>;
827
832
  };
828
833
  syncSectionCatalog: {
829
834
  id: SectionId;
@@ -872,6 +877,7 @@ type SelectionView = {
872
877
  sessionsInclude: string[];
873
878
  encrypt: boolean;
874
879
  includeSecrets: boolean;
880
+ deletePlugins: boolean;
875
881
  };
876
882
  /**
877
883
  * Mount the config-manager engine: host context, adapters, and the
package/lib/index.js CHANGED
@@ -75,7 +75,7 @@ import { ROLLBACK_ACTIVITY_FILE_NAME, RollbackSessionActivity } from './core/rol
75
75
  import { isRollbackEnabled, onRollbackEnabledChange, setRollbackEnabled } from './core/rollback-gate.js';
76
76
  // t3:宿主斜杠命令 /rollback(与 HTTP 路由同一道写入门;命令服务惰取,未组合时安静跳过)。
77
77
  import { agentSessionFactsOf, registerRollbackCommand } from './core/command-rollback.js';
78
- import { cleanupAbortedInstall, hasDshBundlePatch, installAnchorFromProfileContext, installErrorFor, readInstalledVersion, reconcileBundlesAfterInstall, listInstalledPlugins, profileNameFromProfileContext, resolveProcessProfileName, resolveProfileDir, readProfileManifest, runDshPlugin, validateProfileName } from './core/plugin-cli.js';
78
+ import { cleanupAbortedInstall, hasDshBundlePatch, installAnchorFromProfileContext, installErrorFor, uninstallViaCli, readInstalledVersion, reconcileBundlesAfterInstall, listInstalledPlugins, profileNameFromProfileContext, resolveProcessProfileName, resolveProfileDir, readProfileManifest, runDshPlugin, validateProfileName } from './core/plugin-cli.js';
79
79
  import { ImportUserSkippedError } from './core/types.js';
80
80
  import { PLUGIN_NPM_PACKAGE } from './core/update-check.js';
81
81
  import { planSelfUpdate, runSelfUpdate } from './core/self-update.js';
@@ -148,7 +148,7 @@ export const name = 'config-manager';
148
148
  /** Services required before the engine can mount (present in every profile). */
149
149
  export const inject = ['settings', 'credentials'];
150
150
  /** Plugin version, kept in sync with package.json ("version"). */
151
- export const PLUGIN_VERSION = '0.6.0';
151
+ export const PLUGIN_VERSION = '0.8.0';
152
152
  /** Plugin own package name — excluded from its own exported plugins list. */
153
153
  const PLUGIN_NAME = 'dsh-config-manager';
154
154
  /**
@@ -488,6 +488,10 @@ export class DshPluginsFacade {
488
488
  // 回读实际落盘版本:调用方据此校验升级是否真的生效(issue #101),而不是只看子进程退出码。
489
489
  return { needsRestart: true, installedVersion: readInstalledVersion(profileDir, pkg) };
490
490
  }
491
+ /** 卸载插件(issue #132):走官方 CLI `dsh plugin remove`,不自己改 package.json、也不补对账。 */
492
+ uninstall(pkg, signal) {
493
+ return uninstallViaCli(this.homeDir, this.profile, pkg, this.runner, signal);
494
+ }
491
495
  }
492
496
  /** Workspace facade over the real ctx.workspaceRegistry. */
493
497
  class DshWorkspaceFacade {
@@ -2327,18 +2331,16 @@ function makeRoutes(deps) {
2327
2331
  /** 分区选择视图形状(无 schemaVersion;密码值永不进视图)。 */
2328
2332
  /** 全部通道的分区选择视图(status 路由一次返回;UI 按当前 tab 取对应通道)。 */
2329
2333
  /** 指定通道的分区选择视图。 */
2330
- const selectionView = async (channel) => {
2331
- const sel = await ensureSelectionLoaded(channel);
2332
- return { mode: sel.mode, sections: sel.sections, sessionsLimit: sel.sessionsLimit, sessionsInclude: sel.sessionsInclude, encrypt: sel.encrypt, includeSecrets: sel.includeSecrets };
2333
- };
2334
+ /** SyncSelection → SelectionView(字段白名单;密码值永不进视图)。 */
2335
+ const toSelectionView = (sel) => ({ mode: sel.mode, sections: sel.sections, sessionsLimit: sel.sessionsLimit, sessionsInclude: sel.sessionsInclude, encrypt: sel.encrypt, includeSecrets: sel.includeSecrets, deletePlugins: sel.deletePlugins });
2336
+ const selectionView = async (channel) => toSelectionView(await ensureSelectionLoaded(channel));
2334
2337
  const selectionViewByChannel = async () => {
2335
2338
  const all = await readAllSyncSelections(syncDir);
2336
- const view = (sel) => ({ mode: sel.mode, sections: sel.sections, sessionsLimit: sel.sessionsLimit, sessionsInclude: sel.sessionsInclude, encrypt: sel.encrypt, includeSecrets: sel.includeSecrets });
2337
2339
  // 通道集合来自唯一枚举(SYNC_CHANNELS);不得穷举字面量(漏一处即该通道状态静默缺失)
2338
2340
  const out = {};
2339
2341
  for (const channel of SYNC_CHANNELS) {
2340
2342
  selectionCache[channel] = all[channel];
2341
- out[channel] = view(all[channel]);
2343
+ out[channel] = toSelectionView(all[channel]);
2342
2344
  }
2343
2345
  return out;
2344
2346
  };
@@ -2372,8 +2374,10 @@ function makeRoutes(deps) {
2372
2374
  * 构造 git 通道实例(同步引擎与 issue #79 的工作副本自检/重建共用同一份地址与凭据口径)。
2373
2375
  * token 只经 credentials 端口现取(值永不落盘/日志/回传)。
2374
2376
  */
2375
- const makeGitTransport = (repoUrl) => new GitTransport({
2377
+ const makeGitTransport = (repoUrl, subdir) => new GitTransport({
2376
2378
  repoUrl,
2379
+ // issue #131:子目录前缀与 repoUrl 同源(配置 → 传输层),空串 = 仓库根
2380
+ ...(subdir === undefined ? {} : { subdir }),
2377
2381
  workDir: gitWorkDir,
2378
2382
  credentials: {
2379
2383
  getToken: async () => {
@@ -2438,10 +2442,11 @@ function makeRoutes(deps) {
2438
2442
  });
2439
2443
  }
2440
2444
  else {
2441
- transport = makeGitTransport(cfg.git.repoUrl);
2445
+ transport = makeGitTransport(cfg.git.repoUrl, cfg.git.subdir);
2442
2446
  }
2443
2447
  const channel = channelOf(cfg);
2444
- const sections = effectiveSections(selectionCache[channel] ?? defaultSyncSelection());
2448
+ const selection = selectionCache[channel] ?? defaultSyncSelection();
2449
+ const sections = effectiveSections(selection);
2445
2450
  return new SyncEngine({
2446
2451
  ctx: host,
2447
2452
  transport,
@@ -2452,11 +2457,10 @@ function makeRoutes(deps) {
2452
2457
  zipDir: tmpDir,
2453
2458
  msg,
2454
2459
  ...(sections === undefined ? {} : { sections }),
2455
- ...(engineOpts.optInSections === undefined || engineOpts.optInSections.length === 0
2456
- ? {}
2457
- : { optInSections: engineOpts.optInSections }),
2458
- // m-retention:远端快照裁剪与本地备份产物共用同一份 GFS 保留策略(缺省 = 最近 10 个,
2459
- // 与改造前逐字等价);用户改完策略即时生效(每次 prune 都重读)。
2460
+ // issue #132:开关开 = 授权(手动/自动同判据);self 守卫防同步把自己删掉
2461
+ deletePlugins: selection.deletePlugins, selfPluginName: PLUGIN_NPM_PACKAGE,
2462
+ ...(engineOpts.optInSections?.length ? { optInSections: engineOpts.optInSections } : {}),
2463
+ // m-retention:远端裁剪与本地备份共用 GFS 策略(缺省最近 10 个,每次 prune 重读 ⇒ 改完即时生效)。
2460
2464
  retentionPolicy: () => retentionPolicyProvider(),
2461
2465
  });
2462
2466
  };
@@ -2739,7 +2743,7 @@ function makeRoutes(deps) {
2739
2743
  // issue #104 建议 3:`/sync/status` 要回传「领先远端提交数 / 远端快照数」,
2740
2744
  // 用户看不见积压就会在「以为在备份」的状态下一直失败。detail 那几条是本地只读但各起
2741
2745
  // 一次 git 进程(Windows 约 80 ms)⇒ 缺省完整(WorkDirCard 要),路由可传 false。
2742
- return { facts: await makeGitTransport(repoUrl).inspectWorkDir({ detail: opts.detail !== false }) };
2746
+ return { facts: await makeGitTransport(repoUrl, opts.subdir).inspectWorkDir({ detail: opts.detail !== false }) };
2743
2747
  }
2744
2748
  catch (err) {
2745
2749
  return { error: err instanceof Error ? err.message : String(err) };
@@ -2747,8 +2751,8 @@ function makeRoutes(deps) {
2747
2751
  },
2748
2752
  // 重建:relink 非破坏;adopt 合并远端历史(不改写本地提交,issue #104);
2749
2753
  // reclone 删目录重克隆(调用方必须先取得用户确认)
2750
- rebuild: async (repoUrl, mode) => {
2751
- const transport = makeGitTransport(repoUrl);
2754
+ rebuild: async (repoUrl, mode, subdir) => {
2755
+ const transport = makeGitTransport(repoUrl, subdir);
2752
2756
  await transport.rebuildWorkDir(mode);
2753
2757
  return await transport.inspectWorkDir();
2754
2758
  },
@@ -3503,8 +3507,7 @@ export function apply(ctx, config) {
3503
3507
  namespaces: async () => (await ctx.settings.describe({ redactSecrets: true })).map((d) => String(d.ns)),
3504
3508
  // Sessions 分区默认关(含敏感内容):挂载 adapter 供 Custom Export 显式勾选(§3.3/§15)。
3505
3509
  includeSessions: true,
3506
- // 导出 plugins 分区时不列本插件自身,避免备份中的自引用条目。
3507
- selfPluginName: PLUGIN_NAME,
3510
+ selfPluginName: PLUGIN_NAME, // 导出 plugins 分区时不列本插件自身,避免备份里的自引用条目
3508
3511
  // pluginFiles 扩展:额外白名单文件 + 约定配置目录(都相对 ~/.dsh 根),支持导出更多插件配置。
3509
3512
  pluginFiles: config?.pluginFiles,
3510
3513
  pluginFilesDir: config?.pluginFilesDir,
@@ -5,6 +5,7 @@
5
5
  * path/methods 就是唯一声明处;围栏、方法判定与顶层异常处理由 src/routes/kit.ts 在注册点统一提供。
6
6
  */
7
7
  import { endpoint, requireJsonObject, readJsonBody, writeJson, queryParam } from './kit.js';
8
+ import { isIdleAutosyncRun } from '../core/run-registry.js';
8
9
  import { DEFAULT_ROLLBACK_ON_ERROR } from '../core/import-defaults.js';
9
10
  import { decryptErrorText, isControlledPath, tryDecryptCredentials, writeRequestBodyToFile } from './route-support.js';
10
11
  import { resolveSessionFormatDisposition, sessionFormatAbortResponse } from './session-format.js';
@@ -347,7 +348,11 @@ export function importRoutes(env) {
347
348
  endpoint({ path: '/api/dsh-config-manager/runs', methods: ['GET'] }, async (req, res) => {
348
349
  const url = new URL(req.url ?? '/', 'http://localhost');
349
350
  const scope = queryParam(url, 'scope');
350
- writeJson(res, 200, scope === 'recent' ? runs.listRecent(50) : runs.listActive());
351
+ // 空转的自动同步轮次不进「运行中心」:60s 一次轮询,每轮一张「已完成」卡片与迁移历史同属噪音;
352
+ // running / 真干活的轮次照常列出(判据见 core/run-registry.ts 的 isIdleAutosyncRun)。
353
+ writeJson(res, 200, scope === 'recent'
354
+ ? runs.listRecent(50).filter((run) => !isIdleAutosyncRun(run))
355
+ : runs.listActive());
351
356
  }),
352
357
  // ------------------------------------------------------- runs/cancel
353
358
  // 运行中心「终止」:只在**计划项边界**生效的协作式取消(abort run 级信号)。
@@ -231,6 +231,11 @@ export interface RestoreExecutor {
231
231
  ok: boolean;
232
232
  message?: string;
233
233
  }>;
234
+ /** 装回跟远端删掉的插件(官方通道,issue 132 的反向);失败返回 { ok:false, message } */
235
+ installPlugin(name: string, target: string): Promise<{
236
+ ok: boolean;
237
+ message?: string;
238
+ }>;
234
239
  /**
235
240
  * home 相对路径 → 磁盘绝对路径(逐动作 WAL 用:journal 的 ref 必须是绝对路径,
236
241
  * reconcile 的 verifyStepFingerprint 直接拿它读盘算指纹)。缺省 = 不登记 WAL。
@@ -273,7 +278,8 @@ export interface SyncRefScope {
273
278
  /**
274
279
  * 解析同步请求体,按 transport 分支返回归一化的 SyncConfig(可辨识联合,schemaVersion=2)。
275
280
  * 请求体形状(flat,M4 契约):
276
- * - git: { transport:'git', repoUrl, token? } —— token 非空写 SYNC_CREDENTIAL_REF;
281
+ * - git: { transport:'git', repoUrl, subdir?, token? } —— subdir = 仓库内子目录前缀(issue #131);
282
+ * token 非空写 SYNC_CREDENTIAL_REF;
277
283
  * git 可执行文件固定使用系统 PATH 中的 git(不再接受自定义 gitBin)。
278
284
  * - webdav: { transport:'webdav', url, username?, password? } —— password 非空写 SYNC_WEBDAV_CREDENTIAL_REF。
279
285
  * 返回值不含任何 secret(password/token 只进 credentials,永不回传/落同步文件)。
@@ -24,8 +24,8 @@ import { collectCredentialRefs } from '../security/credentials-yaml.js';
24
24
  import { decryptCredentials, SecurityError } from '../security/index.js';
25
25
  import { engineMsg } from '../core/engine-locale.js';
26
26
  import { createPreRestoreAttemptDir } from '../core/restore.js';
27
- import { collectRestoreWalEntries, createRestoreWal, restoreActionStepId, restoreWalHandlesFromSteps } from '../core/restore-wal.js';
28
- import { GIST_PROVIDER, cloudSecretRef, isS3CompatProvider, isWebDavConfig, parseSyncChannel, validateCloudChannelInput, validateRepoUrl, validateWebDavUrl } from '../sync/sync-config.js';
27
+ import { collectRestoreWalEntries, createRestoreWal, isExternalPluginKind, restoreActionStepId, restoreWalHandlesFromSteps } from '../core/restore-wal.js';
28
+ import { GIST_PROVIDER, cloudSecretRef, isS3CompatProvider, isWebDavConfig, normalizeGitSubdir, parseSyncChannel, validateCloudChannelInput, validateRepoUrl, validateWebDavUrl } from '../sync/sync-config.js';
29
29
  import { DEFAULT_AUTOSYNC_AUTO_APPLY_TIER, DEFAULT_AUTOSYNC_CONFLICT_POLICY, DEFAULT_AUTOSYNC_REALTIME, DEFAULT_AUTOSYNC_REMOTE_CHECK_MS, lastRunFailureMessage, readAllAutosyncConfigs, readAutosyncConfig } from '../sync/autosync-config.js';
30
30
  import { SYNC_CHANNELS } from '../sync/sync-config.js';
31
31
  import { normalizeSessionsInclude } from '../sync/sync-selection.js';
@@ -459,6 +459,7 @@ export async function executeRestorePlan(plan, exec, onAction, journal, resumeHi
459
459
  snapshotId: plan.snapshotId,
460
460
  restored: [],
461
461
  removedPlugins: [],
462
+ installedPlugins: [],
462
463
  manualHints: [],
463
464
  failed: [],
464
465
  skipped: [],
@@ -469,7 +470,7 @@ export async function executeRestorePlan(plan, exec, onAction, journal, resumeHi
469
470
  const wal = createRestoreWal(journal);
470
471
  const walByAction = new Map();
471
472
  const resume = resumeHint;
472
- const absOf = (action) => action.kind === 'pluginRemove' || action.target === undefined || exec.absPath === undefined
473
+ const absOf = (action) => isExternalPluginKind(action.kind) || action.target === undefined || exec.absPath === undefined
473
474
  ? null
474
475
  : exec.absPath(action.target);
475
476
  if (wal !== null && exec.absPath !== undefined) {
@@ -543,6 +544,23 @@ export async function executeRestorePlan(plan, exec, onAction, journal, resumeHi
543
544
  }
544
545
  break;
545
546
  }
547
+ case 'pluginInstall': {
548
+ const name = action.pluginName;
549
+ const target = action.pluginTarget ?? name;
550
+ if (name === undefined || target === undefined)
551
+ throw new Error(engineMsg('restore.missingPluginName'));
552
+ const result = await exec.installPlugin(name, target);
553
+ if (result.ok) {
554
+ report.installedPlugins.push(target);
555
+ }
556
+ else {
557
+ const reason = result.message ?? engineMsg('restore.pluginInstallFailed');
558
+ report.failed.push({ item: `plugin:${name}`, reason });
559
+ settleStatus = 'attention';
560
+ settleMessage = reason;
561
+ }
562
+ break;
563
+ }
546
564
  case 'credentialHint':
547
565
  report.manualHints.push(action.manualHint ?? action.description);
548
566
  break;
@@ -612,12 +630,21 @@ export function makeRestoreExecutor(snapshotDir, host, profile) {
612
630
  const tail = output.split('\n').slice(-8).join('\n') || msgOf(host)('host.restoreNoOutput');
613
631
  return { ok: false, message: msgOf(host)('host.restoreUninstallFailed', { name, code: String(result.exitCode), tail }) };
614
632
  },
633
+ installPlugin: async (name, target) => {
634
+ const result = await runDshPlugin(profileDir, profile, ['add', target]);
635
+ if (result.exitCode === 0)
636
+ return { ok: true };
637
+ const output = `${result.stderr}\n${result.stdout}`.trim();
638
+ const tail = output.split('\n').slice(-8).join('\n') || msgOf(host)('host.restoreNoOutput');
639
+ return { ok: false, message: engineMsg('restore.installFailedExit', { name, code: String(result.exitCode), tail }) };
640
+ },
615
641
  };
616
642
  }
617
643
  /**
618
644
  * 解析同步请求体,按 transport 分支返回归一化的 SyncConfig(可辨识联合,schemaVersion=2)。
619
645
  * 请求体形状(flat,M4 契约):
620
- * - git: { transport:'git', repoUrl, token? } —— token 非空写 SYNC_CREDENTIAL_REF;
646
+ * - git: { transport:'git', repoUrl, subdir?, token? } —— subdir = 仓库内子目录前缀(issue #131);
647
+ * token 非空写 SYNC_CREDENTIAL_REF;
621
648
  * git 可执行文件固定使用系统 PATH 中的 git(不再接受自定义 gitBin)。
622
649
  * - webdav: { transport:'webdav', url, username?, password? } —— password 非空写 SYNC_WEBDAV_CREDENTIAL_REF。
623
650
  * 返回值不含任何 secret(password/token 只进 credentials,永不回传/落同步文件)。
@@ -665,6 +692,10 @@ export async function parseSyncBody(body, deps) {
665
692
  const urlError = validateRepoUrl(repoUrl);
666
693
  if (urlError !== null)
667
694
  throw new SyncRouteError(urlError);
695
+ // issue #131:仓库内子目录前缀(可选;空 = 仓库根)。非法值在这里就拒,绝不先落盘再交给 git。
696
+ const subdirCheck = normalizeGitSubdir(syncStr(body['subdir']));
697
+ if (!subdirCheck.ok)
698
+ throw new SyncRouteError(engineMsg('sync.git.subdirInvalid', { subdir: syncStr(body['subdir']) }));
668
699
  const token = typeof body['token'] === 'string' && body['token'] !== '' ? body['token'] : undefined;
669
700
  if (token !== undefined) {
670
701
  try {
@@ -678,7 +709,7 @@ export async function parseSyncBody(body, deps) {
678
709
  return {
679
710
  schemaVersion: 2,
680
711
  transport: 'git',
681
- git: { repoUrl },
712
+ git: { repoUrl, ...(subdirCheck.value === '' ? {} : { subdir: subdirCheck.value }) },
682
713
  };
683
714
  }
684
715
  /** 请求体字段 → 去空白字符串(非字符串 = 空)。 */
@@ -187,14 +187,17 @@ export function syncRoutes(env) {
187
187
  // 远端快照数」(只读自检;后者是「本地一直没真正备份」的预警依据)。
188
188
  // 读不出来时**如实回传错误**(workDirError),不让状态接口静默少一块信息。
189
189
  const gitRepoUrl = full?.git?.repoUrl ?? '';
190
+ // issue #131:自检必须按配置的子目录前缀读(远端快照数来自 <subdir>/snapshots)
191
+ const gitSubdir = full?.git?.subdir ?? '';
190
192
  let workDir = null;
191
193
  if (gitRepoUrl !== '')
192
- workDir = await syncWorkDir.inspect(gitRepoUrl, { detail: opts.workDirDetail });
194
+ workDir = await syncWorkDir.inspect(gitRepoUrl, { detail: opts.workDirDetail, ...(gitSubdir === '' ? {} : { subdir: gitSubdir }) });
193
195
  return {
194
196
  ok: true,
195
197
  configured: full !== null,
196
198
  transport,
197
199
  repoUrl: full?.git?.repoUrl,
200
+ subdir: full?.git?.subdir,
198
201
  // 被丢弃的通道配置成因(默认空数组:字段恒在,客户端不必判 undefined;
199
202
  // 合法配置不产生幻影告警)。code 是机读 token,message 可直接展示。
200
203
  configIssues,
@@ -283,7 +286,7 @@ export function syncRoutes(env) {
283
286
  });
284
287
  return;
285
288
  }
286
- const rebuilt = await syncWorkDir.rebuild(repoUrl, mode);
289
+ const rebuilt = await syncWorkDir.rebuild(repoUrl, mode, full?.git?.subdir);
287
290
  writeJson(res, 200, { ok: true, mode, workDir: { facts: rebuilt } });
288
291
  }
289
292
  catch (error) {
@@ -1171,6 +1174,9 @@ export function syncRoutes(env) {
1171
1174
  encrypt: body['encrypt'] === true,
1172
1175
  // 安全兜底:includeSecrets 必须同时 encrypt(密钥绝不明文进同步通道)
1173
1176
  includeSecrets: body['includeSecrets'] === true && body['encrypt'] === true,
1177
+ // issue #132:跟随远端删除插件。缺省关;请求体非 true 一律按关处理
1178
+ // (重新保存表单时收起开关 = 明确关掉,不留上一次的 true)
1179
+ deletePlugins: body['deletePlugins'] === true,
1174
1180
  };
1175
1181
  // 加密/解密密码持久化(用户要求:勾选即记住,取消勾选或主动删除才清)。
1176
1182
  // 值只写进 DSH credentials(绝不进 sync-selection.json / 日志 / 响应);
@@ -9,7 +9,15 @@ export declare const DEFAULT_AUTOSYNC_INTERVAL: AutosyncInterval;
9
9
  export declare const DEFAULT_STARTUP_MIN_INTERVAL_MS: number;
10
10
  /** 缺省开启「本地改动即时触发」(真·自动同步;关闭后退回纯定时器) */
11
11
  export declare const DEFAULT_AUTOSYNC_REALTIME = true;
12
- /** 缺省远端轮询间隔(realtime 开启时与本地监听并行:本地改动即时上行,远端改动最迟 1 分钟内下行) */
12
+ /**
13
+ * 缺省远端轮询间隔(realtime 开启时与本地监听并行:本地改动即时上行,远端改动最迟 5 分钟内下行)。
14
+ *
15
+ * 2026-11-09 由 60s 改为 5 分钟(用户拍板):远端探测本身很便宜,但过去每轮还会顺带做一次本地
16
+ * 全量导出判定,plugins 分区要为每个本机源插件跑 npm pack(真机 12 个 ≈12 s、单个 210MB 44.7 s)
17
+ * ⇒ 60 s 一轮等于长期占用一个核。本地改动的即时性由文件监听负责(local-change 触发),
18
+ * 兜底由 interval 负责,远端「有没有新快照」不需要 1 分钟一问。旧配置里已写死的值不在此处迁移
19
+ * (用户显式选过的值优先),需要改的走 POST /sync/autosync 的 remoteCheckMs。
20
+ */
13
21
  export declare const DEFAULT_AUTOSYNC_REMOTE_CHECK_MS: number;
14
22
  /** 远端轮询间隔下限(15 s):再短只是空转 fetch,收益为零 */
15
23
  export declare const MIN_AUTOSYNC_REMOTE_CHECK_MS: number;
@@ -27,8 +27,16 @@ export const DEFAULT_AUTOSYNC_INTERVAL = '30m';
27
27
  export const DEFAULT_STARTUP_MIN_INTERVAL_MS = 5 * 60 * 1000;
28
28
  /** 缺省开启「本地改动即时触发」(真·自动同步;关闭后退回纯定时器) */
29
29
  export const DEFAULT_AUTOSYNC_REALTIME = true;
30
- /** 缺省远端轮询间隔(realtime 开启时与本地监听并行:本地改动即时上行,远端改动最迟 1 分钟内下行) */
31
- export const DEFAULT_AUTOSYNC_REMOTE_CHECK_MS = 60 * 1000;
30
+ /**
31
+ * 缺省远端轮询间隔(realtime 开启时与本地监听并行:本地改动即时上行,远端改动最迟 5 分钟内下行)。
32
+ *
33
+ * 2026-11-09 由 60s 改为 5 分钟(用户拍板):远端探测本身很便宜,但过去每轮还会顺带做一次本地
34
+ * 全量导出判定,plugins 分区要为每个本机源插件跑 npm pack(真机 12 个 ≈12 s、单个 210MB 44.7 s)
35
+ * ⇒ 60 s 一轮等于长期占用一个核。本地改动的即时性由文件监听负责(local-change 触发),
36
+ * 兜底由 interval 负责,远端「有没有新快照」不需要 1 分钟一问。旧配置里已写死的值不在此处迁移
37
+ * (用户显式选过的值优先),需要改的走 POST /sync/autosync 的 remoteCheckMs。
38
+ */
39
+ export const DEFAULT_AUTOSYNC_REMOTE_CHECK_MS = 5 * 60 * 1000;
32
40
  /** 远端轮询间隔下限(15 s):再短只是空转 fetch,收益为零 */
33
41
  export const MIN_AUTOSYNC_REMOTE_CHECK_MS = 15 * 1000;
34
42
  /** 远端轮询间隔上限(60 min):比这更慢就不该叫「实时」了 */