dsh-config-manager 0.4.0 → 0.4.2

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 (152) hide show
  1. package/lib/cli/actions.js +2 -3
  2. package/lib/cli/import-source.js +2 -6
  3. package/lib/cli/index.js +2 -3
  4. package/lib/client.d.ts +21 -7
  5. package/lib/client.js +26122 -25799
  6. package/lib/core/exporter.js +2 -4
  7. package/lib/core/host-schedulers/cache-cleanup.d.ts +41 -0
  8. package/lib/core/host-schedulers/cache-cleanup.js +45 -0
  9. package/lib/core/host-schedulers/lifecycle-hooks.d.ts +51 -0
  10. package/lib/core/host-schedulers/lifecycle-hooks.js +78 -0
  11. package/lib/core/host-schedulers/market-cache.d.ts +40 -0
  12. package/lib/core/host-schedulers/market-cache.js +92 -0
  13. package/lib/core/messages-core.d.ts +1 -0
  14. package/lib/core/messages-core.js +2 -0
  15. package/lib/core/migration-history.d.ts +18 -2
  16. package/lib/core/migration-history.js +19 -3
  17. package/lib/core/model-tools.js +2 -6
  18. package/lib/core/restore.d.ts +0 -2
  19. package/lib/core/restore.js +16 -18
  20. package/lib/core/verify-recovery.js +4 -7
  21. package/lib/index.d.ts +3 -22
  22. package/lib/index.js +71 -327
  23. package/lib/profiles/dsh-profile-manager.d.ts +23 -1
  24. package/lib/profiles/dsh-profile-manager.js +70 -2
  25. package/lib/routes/kit.d.ts +21 -0
  26. package/lib/routes/kit.js +29 -0
  27. package/lib/routes/prefs.js +6 -6
  28. package/lib/routes/recovery.js +25 -41
  29. package/lib/routes/route-support.d.ts +23 -1
  30. package/lib/routes/route-support.js +185 -0
  31. package/lib/routes/snapshots.js +4 -11
  32. package/lib/routes/sync.js +5 -7
  33. package/lib/security/redaction.d.ts +5 -1
  34. package/lib/security/redaction.js +26 -23
  35. package/lib/sync/autosync-scheduler.js +6 -2
  36. package/lib/sync/backup-scheduler.js +2 -6
  37. package/lib/sync/baseline-heal.d.ts +35 -0
  38. package/lib/sync/baseline-heal.js +39 -0
  39. package/lib/sync/push-precheck.d.ts +35 -0
  40. package/lib/sync/push-precheck.js +58 -0
  41. package/lib/sync/sync-engine.d.ts +9 -12
  42. package/lib/sync/sync-engine.js +24 -43
  43. package/lib/ui/backup-inspect.d.ts +1 -1
  44. package/lib/ui/dsh-profiles-view.d.ts +0 -10
  45. package/lib/ui/dsh-profiles-view.js +3 -7
  46. package/lib/ui/history-model.js +3 -2
  47. package/lib/ui/overview-view.d.ts +3 -3
  48. package/lib/ui/overview-view.js +9 -1
  49. package/lib/ui/snapshots-view.d.ts +0 -14
  50. package/lib/ui/snapshots-view.js +16 -2
  51. package/lib/utils/paths.d.ts +20 -4
  52. package/lib/utils/paths.js +22 -6
  53. package/lib/utils/time.d.ts +31 -0
  54. package/lib/utils/time.js +54 -0
  55. package/package.json +1 -1
  56. package/src/cli/actions.ts +2 -3
  57. package/src/cli/import-source.ts +2 -7
  58. package/src/cli/index.ts +2 -3
  59. package/src/client/about/AboutPanel.tsx +1 -1
  60. package/src/client/about/ReleaseBody.tsx +22 -52
  61. package/src/client/about/ReleaseNotesDialog.tsx +15 -69
  62. package/src/client/about/release-notes-view.ts +4 -11
  63. package/src/client/common/info-hint-guard.test.ts +11 -5
  64. package/src/client/common/ui.tsx +23 -0
  65. package/src/client/config-manager.module.css +201 -32
  66. package/src/client/css-token-guard.test.ts +135 -1
  67. package/src/client/history/history-locales.ts +2 -0
  68. package/src/client/home/HomePanel.tsx +9 -3
  69. package/src/client/import/ConflictList.tsx +3 -3
  70. package/src/client/import/ImportWizardView.tsx +1 -1
  71. package/src/client/library/ArtifactRow.tsx +2 -2
  72. package/src/client/library/RestorePlanView.tsx +21 -9
  73. package/src/client/library/report-dismiss.test.ts +5 -3
  74. package/src/client/locales/about.ts +97 -0
  75. package/src/client/locales/backup.ts +141 -0
  76. package/src/client/locales/common.ts +113 -0
  77. package/src/client/locales/export.ts +184 -0
  78. package/src/client/locales/foreign.ts +184 -0
  79. package/src/client/locales/import-compat.ts +32 -0
  80. package/src/client/locales/import.ts +192 -0
  81. package/src/client/locales/next-steps.ts +25 -0
  82. package/src/client/locales/overview-control.ts +32 -0
  83. package/src/client/locales/overview.ts +145 -0
  84. package/src/client/locales/profiles.ts +263 -0
  85. package/src/client/locales/report.ts +17 -0
  86. package/src/client/locales/restore.ts +132 -0
  87. package/src/client/locales/sessions.ts +257 -0
  88. package/src/client/locales/shell.ts +149 -0
  89. package/src/client/locales.ts +49 -1781
  90. package/src/client/market/MarketImportReview.tsx +2 -2
  91. package/src/client/market/MarketPanel.tsx +1 -1
  92. package/src/client/market/market-view.ts +3 -5
  93. package/src/client/recovery/RecoveryPanel.tsx +62 -1054
  94. package/src/client/recovery/SessionHealthCard.tsx +134 -0
  95. package/src/client/recovery/SessionHealthDialog.tsx +665 -0
  96. package/src/client/recovery/SessionLayoutSection.tsx +284 -0
  97. package/src/client/recovery/recovery-api.ts +10 -1
  98. package/src/client/recovery/recovery-panel-layout.test.ts +20 -5
  99. package/src/client/recovery/session-dialog-mount.test.ts +16 -9
  100. package/src/client/recovery/use-recovery-write.test.ts +90 -0
  101. package/src/client/recovery/use-recovery-write.ts +53 -0
  102. package/src/client/run-store.ts +57 -2
  103. package/src/client/sync/PushPreviewCard.tsx +2 -2
  104. package/src/client/sync/SyncConfirmView.tsx +5 -5
  105. package/src/client/sync/SyncLogList.tsx +2 -2
  106. package/src/client/sync/history-model.ts +7 -5
  107. package/src/client/sync/sync-locales.ts +2 -0
  108. package/src/client/sync/sync-view.ts +3 -4
  109. package/src/core/exporter.ts +2 -4
  110. package/src/core/host-schedulers/cache-cleanup.test.ts +84 -0
  111. package/src/core/host-schedulers/cache-cleanup.ts +74 -0
  112. package/src/core/host-schedulers/lifecycle-hooks.test.ts +111 -0
  113. package/src/core/host-schedulers/lifecycle-hooks.ts +118 -0
  114. package/src/core/host-schedulers/market-cache.test.ts +93 -0
  115. package/src/core/host-schedulers/market-cache.ts +116 -0
  116. package/src/core/messages-core.ts +2 -0
  117. package/src/core/migration-history.test.ts +19 -0
  118. package/src/core/migration-history.ts +28 -5
  119. package/src/core/model-tools.ts +2 -7
  120. package/src/core/restore-failure-state.test.ts +210 -0
  121. package/src/core/restore.ts +16 -18
  122. package/src/core/verify-recovery.ts +4 -7
  123. package/src/index.ts +78 -332
  124. package/src/profiles/dsh-profile-copy-rollback.test.ts +156 -0
  125. package/src/profiles/dsh-profile-manager.ts +71 -3
  126. package/src/routes/kit.ts +37 -0
  127. package/src/routes/prefs.ts +6 -6
  128. package/src/routes/recovery.ts +25 -42
  129. package/src/routes/route-support.ts +208 -1
  130. package/src/routes/snapshots.ts +4 -9
  131. package/src/routes/sync.ts +4 -7
  132. package/src/security/redaction.ts +29 -23
  133. package/src/sync/autosync-scheduler.test.ts +23 -0
  134. package/src/sync/autosync-scheduler.ts +6 -2
  135. package/src/sync/backup-scheduler.ts +3 -6
  136. package/src/sync/baseline-heal.ts +74 -0
  137. package/src/sync/push-precheck.ts +75 -0
  138. package/src/sync/sync-config.test.ts +24 -13
  139. package/src/sync/sync-engine.test.ts +88 -0
  140. package/src/sync/sync-engine.ts +33 -43
  141. package/src/ui/backup-inspect.ts +1 -1
  142. package/src/ui/dsh-profiles-view.ts +3 -5
  143. package/src/ui/history-model.test.ts +2 -1
  144. package/src/ui/history-model.ts +3 -2
  145. package/src/ui/i18n.test.ts +8 -3
  146. package/src/ui/overview-view.test.ts +12 -0
  147. package/src/ui/overview-view.ts +12 -4
  148. package/src/ui/snapshots-view.ts +2 -2
  149. package/src/utils/paths.test.ts +36 -1
  150. package/src/utils/paths.ts +30 -6
  151. package/src/utils/time.test.ts +46 -0
  152. package/src/utils/time.ts +55 -0
@@ -28,6 +28,7 @@ import { readTextSafe } from '../profiles/dsh-profile-io.js';
28
28
  import { AUTO_BACKUP_PREFIX, DEFAULT_BACKUP_RETENTION, listBackupFiles, } from '../sync/backup-files.js';
29
29
  import { EnvironmentLockManager, OWNERSHIP_FILE } from '../utils/env-lock.js';
30
30
  import { scanSessionHealth } from '../utils/session-health-scan.js';
31
+ import { formatDateStamp } from '../utils/time.js';
31
32
  /* ------------------------------------------------------------ 进程/实例事实 */
32
33
  /** 进程是否存活(不发送信号,只探测)。EPERM = 存在但无权限发信号 → 仍算存活。 */
33
34
  export function isProcessAlive(pid) {
@@ -970,9 +971,7 @@ export async function exportOfflineBackup(paths, sections) {
970
971
  if (collection.entries.length === 0) {
971
972
  return { ok: false, code: 'nothing-to-export', message: '没有可打包的内容(该 home 下未找到可离线收集的分区)。' };
972
973
  }
973
- const now = new Date();
974
- const stamp = String(now.getFullYear()) + String(now.getMonth() + 1).padStart(2, '0') + String(now.getDate()).padStart(2, '0')
975
- + '-' + String(now.getHours()).padStart(2, '0') + String(now.getMinutes()).padStart(2, '0') + String(now.getSeconds()).padStart(2, '0');
974
+ const stamp = formatDateStamp();
976
975
  const { randomBytes } = await import('node:crypto');
977
976
  const desired = 'dsh-config-cli-' + stamp + '-' + randomBytes(4).toString('hex') + '.zip';
978
977
  await fsp.mkdir(paths.exportsDir, { recursive: true });
@@ -21,6 +21,7 @@ import { verifyBackupZip } from '../core/backup-verify.js';
21
21
  import { writeForeignBundle } from '../foreign/bundle.js';
22
22
  import { FOREIGN_CONFLICT_POLICY, ForeignSourceError, createBuiltinForeignSourceRegistry, } from '../foreign/registry.js';
23
23
  import { foreignSourceContext } from '../routes/foreign-context.js';
24
+ import { formatDateStamp } from '../utils/time.js';
24
25
  /** 分区摘要的一行:文件类给文件数,JSON 类给该分区的计数键(全部是机器可读的条目数) */
25
26
  function sectionLine(section, result) {
26
27
  if (section.files !== undefined)
@@ -67,7 +68,7 @@ function printImportSummary(sourceId, detection, result, io) {
67
68
  async function resolveOutPath(options, sourceId) {
68
69
  const desired = options.out !== undefined && options.out !== ''
69
70
  ? path.resolve(options.out)
70
- : path.join(options.exportsDir, 'foreign-' + sourceId + '-' + stamp() + '-' + randomHex4() + '.zip');
71
+ : path.join(options.exportsDir, 'foreign-' + sourceId + '-' + formatDateStamp() + '-' + randomHex4() + '.zip');
71
72
  if (!(await pathExists(desired)))
72
73
  return desired;
73
74
  const base = desired.endsWith('.zip') ? desired.slice(0, -4) : desired;
@@ -77,11 +78,6 @@ async function resolveOutPath(options, sourceId) {
77
78
  return candidate;
78
79
  }
79
80
  }
80
- function stamp() {
81
- const now = new Date();
82
- return `${now.getFullYear()}${String(now.getMonth() + 1).padStart(2, '0')}${String(now.getDate()).padStart(2, '0')}`
83
- + `-${String(now.getHours()).padStart(2, '0')}${String(now.getMinutes()).padStart(2, '0')}${String(now.getSeconds()).padStart(2, '0')}`;
84
- }
85
81
  function randomHex4() {
86
82
  // 用全局 crypto(Node ≥ 19);零额外依赖
87
83
  const bytes = new Uint8Array(4);
package/lib/cli/index.js CHANGED
@@ -39,6 +39,7 @@ import { buildChecksums } from '../utils/hashing.js';
39
39
  import { stringifyJsonSafe } from '../utils/json.js';
40
40
  import { buildManifest, CHECKSUMS_FILE, MANIFEST_FILE } from '../schema/manifest.js';
41
41
  import { writeZip } from '../utils/zip.js';
42
+ import { formatDateStamp } from '../utils/time.js';
42
43
  const VALUE_FLAGS = new Map([
43
44
  ['--data-dir', 'dataDir'],
44
45
  ['--data-root', 'dataRoot'],
@@ -1191,9 +1192,7 @@ async function runBackup(options, io, env) {
1191
1192
  }
1192
1193
  else {
1193
1194
  // 注意:此处刻意不 mkdir —— dry-run 必须零写入,目录在真正落盘前才创建
1194
- const now = new Date();
1195
- const stamp = `${now.getFullYear()}${String(now.getMonth() + 1).padStart(2, '0')}${String(now.getDate()).padStart(2, '0')}`
1196
- + `-${String(now.getHours()).padStart(2, '0')}${String(now.getMinutes()).padStart(2, '0')}${String(now.getSeconds()).padStart(2, '0')}`;
1195
+ const stamp = formatDateStamp();
1197
1196
  try {
1198
1197
  const rand = await randomHex4();
1199
1198
  outPath = await resolveNonCollidingName(exportsDir, `dsh-config-cli-${stamp}-${rand}.zip`);
package/lib/client.d.ts CHANGED
@@ -2938,6 +2938,15 @@ interface SyncPushReport {
2938
2938
  * 而不是记成「同步失败」。
2939
2939
  */
2940
2940
  conflict?: boolean;
2941
+ /**
2942
+ * 本次推送前**收养了本机自己推上去的远端最新快照**(0.4.1 自愈):该值 = 被收养的快照 id。
2943
+ *
2944
+ * 触发场景:上次推送在上传成功、写基线之前被打断(进程退出/崩溃/断电),远端已前进而本机
2945
+ * `lastSnapshotId` 仍是上一版 → 前置检测会永久拒绝推送(每次都说「远端被别人推进了」),
2946
+ * 单设备用户因此被自己的快照锁死。判据只看「远端最新快照的 manifest.deviceId == 本机
2947
+ * deviceId」,别的设备推进过就仍然按冲突返回,绝不越过。
2948
+ */
2949
+ adoptedBase?: string;
2941
2950
  }
2942
2951
  /** 差异报告中的单个变更项(PlanItem 摘要,不含敏感细节) */
2943
2952
  interface PullChange {
@@ -4810,8 +4819,16 @@ declare class RecoveryApi implements RecoveryPort, RollbackPointPort {
4810
4819
  declare const MIGRATION_KINDS: readonly ['import', 'restore', 'rollback', 'profile-create', 'profile-select', 'profile-switch', 'profile-delete', 'profile-rename', 'profile-save', 'profile-import', 'sync-apply', 'autosync', 'recovery', 'backup', 'backup-manual', 'snapshot-delete', 'snapshot-prune'];
4811
4820
  /** §5 覆盖的操作 kind(COMPLETE 不变量;常量枚举,天然非敏感)。 */
4812
4821
  type MigrationKind = (typeof MIGRATION_KINDS)[number];
4813
- /** 操作结果。 */
4814
- type MigrationResult = 'success' | 'failed' | 'skipped';
4822
+ /**
4823
+ * 操作结果。
4824
+ *
4825
+ * 'pending'(0.4.1):操作**跑完了但仍有待裁决项**(自动同步上传成功、下行冲突未裁决;
4826
+ * 合并已应用一部分)。它不是 failed —— 网络/凭据/repo 都是好的;也不是 skipped ——
4827
+ * 那一轮确实做了事。旧实现把 partial 直接折成 'failed',用户看到「自动同步 失败」而
4828
+ * 实际只需要在同步页确认一次冲突。读侧(parseEntry / query 解析)必须接受该值,
4829
+ * 否则含 pending 的历史条目会被整条丢弃。
4830
+ */
4831
+ type MigrationResult = 'success' | 'failed' | 'skipped' | 'pending';
4815
4832
  /** 触发来源(常量)。 */
4816
4833
  type MigrationSource = 'api' | 'autosync' | 'backup-scheduler' | 'recovery' | 'cli' | 'internal';
4817
4834
  /** 一条不可变的迁移历史记录(磁盘形态;schemaVersion 内联)。 */
@@ -4997,11 +5014,6 @@ interface ConfigManagerSectionInjected {
4997
5014
  */
4998
5015
  uiT: UiT;
4999
5016
  }
5000
- /**
5001
- * Config Manager 表面文案:zh 为源语言,en 镜像每个键。
5002
- * 字典 namespace 由 client/index.ts 注册(declare module 合并进 LocaleNamespaceMap)。
5003
- * 键集合通过 `ConfigManagerKey` 类型在注册处做编译期校验(缺键/多键即编译错误)。
5004
- */
5005
5017
  declare const zh$4: {
5006
5018
  readonly 'section.label': '备份与迁移';
5007
5019
  readonly 'section.description': '导出 / 导入 / 迁移 DSH 配置(备份不含密钥,加密备份可选)';
@@ -5640,6 +5652,7 @@ declare const zh$4: {
5640
5652
  readonly 'overview.result.success': '成功';
5641
5653
  readonly 'overview.result.failed': '失败';
5642
5654
  readonly 'overview.result.skipped': '跳过';
5655
+ readonly 'overview.result.pending': '待裁决';
5643
5656
  readonly 'overview.activity.copy': '复制';
5644
5657
  readonly 'overview.activity.redacted': '(文件名已脱敏)';
5645
5658
  readonly 'overview.sections.entries': '{count} 项';
@@ -6083,6 +6096,7 @@ declare const zh$3: {
6083
6096
  readonly 'history.autosyncPush': '上传';
6084
6097
  readonly 'history.autosyncBoth': '双向';
6085
6098
  readonly 'history.autosyncReasonConflict': '冲突';
6099
+ readonly 'history.autosyncReasonBaselineAdopted': '基线已自动收养(上次推送在记录基线前被打断)';
6086
6100
  readonly 'history.autosyncReasonNoRemote': '无远端快照';
6087
6101
  readonly 'history.autosyncReasonNotConfigured': '未配置仓库';
6088
6102
  readonly 'history.autosyncReasonNetwork': '网络问题';