dsh-config-manager 0.4.1 → 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 (122) 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 +0 -5
  5. package/lib/client.js +26116 -25801
  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/model-tools.js +2 -6
  14. package/lib/core/restore.d.ts +0 -2
  15. package/lib/core/restore.js +16 -18
  16. package/lib/core/verify-recovery.js +4 -7
  17. package/lib/index.d.ts +3 -22
  18. package/lib/index.js +69 -325
  19. package/lib/profiles/dsh-profile-manager.d.ts +23 -1
  20. package/lib/profiles/dsh-profile-manager.js +70 -2
  21. package/lib/routes/kit.d.ts +21 -0
  22. package/lib/routes/kit.js +29 -0
  23. package/lib/routes/prefs.js +6 -6
  24. package/lib/routes/recovery.js +25 -41
  25. package/lib/routes/route-support.d.ts +23 -1
  26. package/lib/routes/route-support.js +185 -0
  27. package/lib/routes/snapshots.js +4 -11
  28. package/lib/routes/sync.js +5 -7
  29. package/lib/security/redaction.d.ts +5 -1
  30. package/lib/security/redaction.js +26 -23
  31. package/lib/sync/backup-scheduler.js +2 -6
  32. package/lib/ui/backup-inspect.d.ts +1 -1
  33. package/lib/ui/dsh-profiles-view.d.ts +0 -10
  34. package/lib/ui/dsh-profiles-view.js +3 -7
  35. package/lib/ui/snapshots-view.d.ts +0 -14
  36. package/lib/ui/snapshots-view.js +16 -2
  37. package/lib/utils/paths.d.ts +20 -4
  38. package/lib/utils/paths.js +22 -6
  39. package/lib/utils/time.d.ts +31 -0
  40. package/lib/utils/time.js +54 -0
  41. package/package.json +1 -1
  42. package/src/cli/actions.ts +2 -3
  43. package/src/cli/import-source.ts +2 -7
  44. package/src/cli/index.ts +2 -3
  45. package/src/client/about/AboutPanel.tsx +1 -1
  46. package/src/client/about/ReleaseBody.tsx +22 -52
  47. package/src/client/about/ReleaseNotesDialog.tsx +15 -69
  48. package/src/client/about/release-notes-view.ts +4 -11
  49. package/src/client/common/info-hint-guard.test.ts +11 -5
  50. package/src/client/common/ui.tsx +23 -0
  51. package/src/client/config-manager.module.css +201 -32
  52. package/src/client/css-token-guard.test.ts +135 -1
  53. package/src/client/import/ConflictList.tsx +3 -3
  54. package/src/client/import/ImportWizardView.tsx +1 -1
  55. package/src/client/library/ArtifactRow.tsx +2 -2
  56. package/src/client/library/RestorePlanView.tsx +21 -9
  57. package/src/client/library/report-dismiss.test.ts +5 -3
  58. package/src/client/locales/about.ts +97 -0
  59. package/src/client/locales/backup.ts +141 -0
  60. package/src/client/locales/common.ts +113 -0
  61. package/src/client/locales/export.ts +184 -0
  62. package/src/client/locales/foreign.ts +184 -0
  63. package/src/client/locales/import-compat.ts +32 -0
  64. package/src/client/locales/import.ts +192 -0
  65. package/src/client/locales/next-steps.ts +25 -0
  66. package/src/client/locales/overview-control.ts +32 -0
  67. package/src/client/locales/overview.ts +145 -0
  68. package/src/client/locales/profiles.ts +263 -0
  69. package/src/client/locales/report.ts +17 -0
  70. package/src/client/locales/restore.ts +132 -0
  71. package/src/client/locales/sessions.ts +257 -0
  72. package/src/client/locales/shell.ts +149 -0
  73. package/src/client/locales.ts +49 -1783
  74. package/src/client/market/MarketImportReview.tsx +2 -2
  75. package/src/client/market/MarketPanel.tsx +1 -1
  76. package/src/client/market/market-view.ts +3 -5
  77. package/src/client/recovery/RecoveryPanel.tsx +62 -1054
  78. package/src/client/recovery/SessionHealthCard.tsx +134 -0
  79. package/src/client/recovery/SessionHealthDialog.tsx +665 -0
  80. package/src/client/recovery/SessionLayoutSection.tsx +284 -0
  81. package/src/client/recovery/recovery-api.ts +10 -1
  82. package/src/client/recovery/recovery-panel-layout.test.ts +20 -5
  83. package/src/client/recovery/session-dialog-mount.test.ts +16 -9
  84. package/src/client/recovery/use-recovery-write.test.ts +90 -0
  85. package/src/client/recovery/use-recovery-write.ts +53 -0
  86. package/src/client/run-store.ts +57 -2
  87. package/src/client/sync/PushPreviewCard.tsx +2 -2
  88. package/src/client/sync/SyncConfirmView.tsx +5 -5
  89. package/src/client/sync/SyncLogList.tsx +2 -2
  90. package/src/client/sync/history-model.ts +4 -5
  91. package/src/client/sync/sync-view.ts +3 -4
  92. package/src/core/exporter.ts +2 -4
  93. package/src/core/host-schedulers/cache-cleanup.test.ts +84 -0
  94. package/src/core/host-schedulers/cache-cleanup.ts +74 -0
  95. package/src/core/host-schedulers/lifecycle-hooks.test.ts +111 -0
  96. package/src/core/host-schedulers/lifecycle-hooks.ts +118 -0
  97. package/src/core/host-schedulers/market-cache.test.ts +93 -0
  98. package/src/core/host-schedulers/market-cache.ts +116 -0
  99. package/src/core/model-tools.ts +2 -7
  100. package/src/core/restore-failure-state.test.ts +210 -0
  101. package/src/core/restore.ts +16 -18
  102. package/src/core/verify-recovery.ts +4 -7
  103. package/src/index.ts +76 -330
  104. package/src/profiles/dsh-profile-copy-rollback.test.ts +156 -0
  105. package/src/profiles/dsh-profile-manager.ts +71 -3
  106. package/src/routes/kit.ts +37 -0
  107. package/src/routes/prefs.ts +6 -6
  108. package/src/routes/recovery.ts +25 -42
  109. package/src/routes/route-support.ts +208 -1
  110. package/src/routes/snapshots.ts +4 -9
  111. package/src/routes/sync.ts +4 -7
  112. package/src/security/redaction.ts +29 -23
  113. package/src/sync/backup-scheduler.ts +3 -6
  114. package/src/sync/sync-config.test.ts +24 -13
  115. package/src/ui/backup-inspect.ts +1 -1
  116. package/src/ui/dsh-profiles-view.ts +3 -5
  117. package/src/ui/i18n.test.ts +8 -3
  118. package/src/ui/snapshots-view.ts +2 -2
  119. package/src/utils/paths.test.ts +36 -1
  120. package/src/utils/paths.ts +30 -6
  121. package/src/utils/time.test.ts +46 -0
  122. package/src/utils/time.ts +55 -0
@@ -105,23 +105,31 @@ function replaceSensitiveField(text, re, blacklist) {
105
105
  });
106
106
  }
107
107
  /**
108
- * 文本脱敏(幂等)。blacklist 为**附加**规范化字段名(小写无分隔符,如 'clientsecret')。
109
- * 输出仍保留结构化形态(JSON 行合法)。
108
+ * 脱敏流水线(**唯一实现**,redact 与 createRedactor 共用一套顺序与语义)。
109
+ *
110
+ * 曾经这里与 createRedactor 各写一遍完全相同的 6 步(结构化 3 步 + 值形状 + URL query + userinfo),
111
+ * 两份代码只在「正则实例从哪来」上不同 —— 任何一步调整都要记得改两处,漏一次就是两条脱敏口径。
112
+ * 现在只由调用方决定正则实例的生命周期(模块级常量 / 每次预编译),流水线本身不再有副本。
110
113
  */
111
- export function redact(text, blacklist = []) {
112
- let out = text;
114
+ function redactPipeline(text, blacklist, json, kv, colon) {
113
115
  // 1. 结构化字段形态(顺序:JSON → kv → colon;JSON 键不会被后续形态二次命中)
114
- out = replaceSensitiveField(out, JSON_FIELD_RE, blacklist);
115
- out = replaceSensitiveField(out, KV_FIELD_RE, blacklist);
116
- out = replaceSensitiveField(out, COLON_FIELD_RE, blacklist);
116
+ let out = replaceSensitiveField(text, json, blacklist);
117
+ out = replaceSensitiveField(out, kv, blacklist);
118
+ out = replaceSensitiveField(out, colon, blacklist);
117
119
  // 2. 值形状模式(字段名无关,包含式)
118
120
  for (const { re } of VALUE_PATTERNS) {
119
121
  re.lastIndex = 0;
120
122
  out = out.replace(re, REDACTED);
121
123
  }
122
124
  out = out.replace(URL_QUERY_RE, `$1${REDACTED}`);
123
- out = out.replace(URL_USERINFO_RE, `$1${REDACTED}$3`);
124
- return out;
125
+ return out.replace(URL_USERINFO_RE, `$1${REDACTED}$3`);
126
+ }
127
+ /**
128
+ * 文本脱敏(幂等)。blacklist 为**附加**规范化字段名(小写无分隔符,如 'clientsecret')。
129
+ * 输出仍保留结构化形态(JSON 行合法)。
130
+ */
131
+ export function redact(text, blacklist = []) {
132
+ return redactPipeline(text, blacklist, JSON_FIELD_RE, KV_FIELD_RE, COLON_FIELD_RE);
125
133
  }
126
134
  /** 对象级掩码:字段名命中敏感名单 → 整值替换(返回新对象,不改原对象;结构与类型保留) */
127
135
  export function redactValue(value, blacklist = []) {
@@ -137,21 +145,16 @@ export function redactValue(value, blacklist = []) {
137
145
  }
138
146
  return out;
139
147
  }
140
- /** 预编译脱敏器(多次调用复用;blacklist 为附加规范化字段名) */
148
+ /**
149
+ * 预编译脱敏器(多次调用复用;blacklist 为附加规范化字段名)。
150
+ * 正则实例**在创建时**各复制一份:模块级常量若与本函数共享,多线程无害但会让「谁动了 lastIndex」
151
+ * 不可追溯;复制成本只有一次,换来每个脱敏器实例自持状态。
152
+ */
141
153
  export function createRedactor(blacklist = []) {
142
- const compiled = { json: JSON_FIELD_RE, kv: KV_FIELD_RE, colon: COLON_FIELD_RE };
143
- return (text) => {
144
- let out = replaceSensitiveField(text, new RegExp(compiled.json.source, 'g'), blacklist);
145
- out = replaceSensitiveField(out, new RegExp(compiled.kv.source, 'g'), blacklist);
146
- out = replaceSensitiveField(out, new RegExp(compiled.colon.source, 'g'), blacklist);
147
- for (const { re } of VALUE_PATTERNS) {
148
- re.lastIndex = 0;
149
- out = out.replace(re, REDACTED);
150
- }
151
- out = out.replace(URL_QUERY_RE, `$1${REDACTED}`);
152
- out = out.replace(URL_USERINFO_RE, `$1${REDACTED}$3`);
153
- return out;
154
- };
154
+ const json = new RegExp(JSON_FIELD_RE.source, 'g');
155
+ const kv = new RegExp(KV_FIELD_RE.source, 'g');
156
+ const colon = new RegExp(COLON_FIELD_RE.source, 'g');
157
+ return (text) => redactPipeline(text, blacklist, json, kv, colon);
155
158
  }
156
159
  /** 默认名单(文档用;redact 的默认附加名单为空,内置判定已含 DEFAULT_SECRET_FIELD_NAMES) */
157
160
  export { DEFAULT_SECRET_FIELD_NAMES };
@@ -7,6 +7,7 @@ import { readBackupSchedule, writeBackupSchedule, nextBackupDelayMs } from './ba
7
7
  import { shouldTriggerStartupRun } from './autosync-scheduler.js';
8
8
  import { AUTO_BACKUP_PREFIX, pruneAutoBackupsByPolicy } from './backup-files.js';
9
9
  import { DEFAULT_RETENTION_POLICY } from './retention-policy.js';
10
+ import { formatDateStamp } from '../utils/time.js';
10
11
  export class BackupScheduler {
11
12
  syncDir;
12
13
  exportsDir;
@@ -175,7 +176,7 @@ export class BackupScheduler {
175
176
  });
176
177
  // 显式落 exportsDir(与 host 路由同构;Exporter 缺省 outPath 是相对文件名,不落目录)
177
178
  // auto 前缀 = 定时备份产物标识:列表来源 Badge + cache-cleaner 豁免 + 保留策略清理依据
178
- const outPath = join(this.exportsDir, `${AUTO_BACKUP_PREFIX}${dateStamp(this.now())}-${randomBytes(3).toString('hex')}.zip`);
179
+ const outPath = join(this.exportsDir, `${AUTO_BACKUP_PREFIX}${formatDateStamp(this.now())}-${randomBytes(3).toString('hex')}.zip`);
179
180
  const { report } = await exporter.export({
180
181
  includeSecrets: false, // 恒不含 secret(与自动同步同语义)
181
182
  outPath,
@@ -304,9 +305,4 @@ export class BackupScheduler {
304
305
  }
305
306
  }
306
307
  }
307
- /** 导出文件时间戳(YYYYMMDD-HHmmss),与 host 路由 dateStamp 同构。 */
308
- function dateStamp(d) {
309
- const p = (n) => String(n).padStart(2, '0');
310
- return `${d.getFullYear()}${p(d.getMonth() + 1)}${p(d.getDate())}-${p(d.getHours())}${p(d.getMinutes())}${p(d.getSeconds())}`;
311
- }
312
308
  //# sourceMappingURL=backup-scheduler.js.map
@@ -34,7 +34,7 @@ export declare function inspectSections(analysis: ImportAnalysis, plan: ImportPl
34
34
  export declare function inspectSummary(analysis: ImportAnalysis, plan: ImportPlan): BackupInspectSummary;
35
35
  /** 变更明细分组键(渲染顺序 = 冲突 → 变更 → 路径映射 → 一致跳过 → 其他)。 */
36
36
  export type InspectGroupKey = 'conflicts' | 'changes' | 'paths' | 'skipped' | 'others';
37
- /** 单分组:key(语义)+ kind(Badge/kindTag 颜色语义)+ 组内条目。 */
37
+ /** 单分组:key(语义)+ kind(Badge 四态颜色语义)+ 组内条目。 */
38
38
  export interface InspectChangeGroup {
39
39
  key: InspectGroupKey;
40
40
  /** 颜色语义:error=冲突 / info=变更 / warn=路径映射与其它 / ok=一致跳过 */
@@ -1,13 +1,3 @@
1
- /**
2
- * 「档案」页(DSH profile 管理)—— 框架无关纯函数层(node 可测)。
3
- *
4
- * 职责:名字输入校验、列表排序(当前运行置顶)、列表摘要统计、危险态判定、运行中实例判定、
5
- * 展示格式化(时间/字节)、终端启动命令文本。不产出用户可见散文(文案走 locale 字典 `t()`),
6
- * 不 import node 模块、不 import React。
7
- *
8
- * 依赖方向:只从 `src/profiles/dsh-profile-shared.ts`(零依赖)取类型与纯函数——
9
- * 绝不 import 用 node fs 的引擎(否则 client bundle 会带上 node 内置模块依赖而整插件不加载)。
10
- */
11
1
  import { type DshProfileCopyWarning, type DshProfileIssue, type DshProfileLaunchResult, type DshProfileLaunchWarning, type DshProfileMeta, type DshProfileRunningView, type DshProfileShape, type DshProfileStopOutcome } from '../profiles/dsh-profile-shared.ts';
12
2
  /** 名称输入校验结果(UI 按码映射 i18n;null = 合法)。 */
13
3
  export type ProfileNameIssue = 'required' | 'tooLong' | 'illegal' | 'reserved';
@@ -8,6 +8,7 @@
8
8
  * 依赖方向:只从 `src/profiles/dsh-profile-shared.ts`(零依赖)取类型与纯函数——
9
9
  * 绝不 import 用 node fs 的引擎(否则 client bundle 会带上 node 内置模块依赖而整插件不加载)。
10
10
  */
11
+ import { formatMinuteStamp, parseDateInput } from '../utils/time.js';
11
12
  import { checkProfileName, isLaunchableShape, isManagedProfileName, } from '../profiles/dsh-profile-shared.js';
12
13
  /** 校验输入框里的 profile 名:与 host 侧同规则,但把「空」与「过长」细分以便给出更准的提示。 */
13
14
  export function validateProfileNameInput(name) {
@@ -237,13 +238,8 @@ export function issueLabelKey(issue) {
237
238
  }
238
239
  /** 时间戳(毫秒)→ 本地 `YYYY-MM-DD HH:mm`;null / 非法 = 空串。 */
239
240
  export function formatProfileTime(ms) {
240
- if (ms === null)
241
- return '';
242
- const d = new Date(ms);
243
- if (Number.isNaN(d.getTime()))
244
- return '';
245
- const p = (n) => String(n).padStart(2, '0');
246
- return `${d.getFullYear()}-${p(d.getMonth() + 1)}-${p(d.getDate())} ${p(d.getHours())}:${p(d.getMinutes())}`;
241
+ const d = parseDateInput(ms);
242
+ return d === null ? '' : formatMinuteStamp(d);
247
243
  }
248
244
  /** 字节数 → 人类可读(B / KB / MB,保留一位小数)。 */
249
245
  export function formatBytes(bytes) {
@@ -1,17 +1,3 @@
1
- /**
2
- * 备份页(Backups:快照恢复 / 备份文件 / 定时备份设置)—— 框架无关纯函数层(node 可测)。
3
- *
4
- * t43 从 `src/client/snapshots/SnapshotsPanel.tsx` 下沉(该组件原先把这些逻辑私有在函数体内,
5
- * 违反仓库铁律「逻辑放 src/ui」——node 无法测试)。本层职责:
6
- * - 面板状态切片 ← runStore 快照切片 的投影(切页/刷新恢复的判定);
7
- * - 状态/档位 → **字典键**(本层不产出任何用户可见文案,由 React 壳 t() 渲染,见 backup-schedule.ts 同款约定);
8
- * - 时间与文件名的展示格式化;
9
- * - 备份文件列表的搜索过滤、备注可读性判定;
10
- * - 恢复计划是否含可执行动作(执行按钮的 disabled 判据)。
11
- *
12
- * 约束:不 import node 模块、不 import `../client/*`(架构边界 tests/architecture-boundaries.test.ts)、
13
- * 无 React 依赖;类型仅从 `../core/*` / `../sync/*` 以 type-only 方式取(运行时不加载)。
14
- */
15
1
  import type { RestorePlan, RestoreReport, SnapshotMeta } from '../core/restore.ts';
16
2
  import type { RestoreChangeSummary } from '../core/snapshot-diff.ts';
17
3
  import type { BackupFileMeta } from '../sync/backup-files.ts';
@@ -1,3 +1,18 @@
1
+ /**
2
+ * 备份页(Backups:快照恢复 / 备份文件 / 定时备份设置)—— 框架无关纯函数层(node 可测)。
3
+ *
4
+ * t43 从 `src/client/snapshots/SnapshotsPanel.tsx` 下沉(该组件原先把这些逻辑私有在函数体内,
5
+ * 违反仓库铁律「逻辑放 src/ui」——node 无法测试)。本层职责:
6
+ * - 面板状态切片 ← runStore 快照切片 的投影(切页/刷新恢复的判定);
7
+ * - 状态/档位 → **字典键**(本层不产出任何用户可见文案,由 React 壳 t() 渲染,见 backup-schedule.ts 同款约定);
8
+ * - 时间与文件名的展示格式化;
9
+ * - 备份文件列表的搜索过滤、备注可读性判定;
10
+ * - 恢复计划是否含可执行动作(执行按钮的 disabled 判据)。
11
+ *
12
+ * 约束:不 import node 模块、不 import `../client/*`(架构边界 tests/architecture-boundaries.test.ts)、
13
+ * 无 React 依赖;类型仅从 `../core/*` / `../sync/*` 以 type-only 方式取(运行时不加载)。
14
+ */
15
+ import { formatMinuteStamp } from '../utils/time.js';
1
16
  export const INITIAL_SNAPSHOTS_PANEL_STATE = {
2
17
  status: 'loading',
3
18
  error: null,
@@ -120,8 +135,7 @@ export function formatBackupFileTime(ms) {
120
135
  const d = new Date(ms);
121
136
  if (Number.isNaN(d.getTime()))
122
137
  return '';
123
- const p = (n) => String(n).padStart(2, '0');
124
- return `${d.getFullYear()}-${p(d.getMonth() + 1)}-${p(d.getDate())} ${p(d.getHours())}:${p(d.getMinutes())}`;
138
+ return formatMinuteStamp(d);
125
139
  }
126
140
  /**
127
141
  * 备注是否「编码损坏」(全问号/控制符)→ 调用方改渲染 backupFiles.noteUnreadable 文案;
@@ -8,11 +8,27 @@ export declare function isAbsolutePath(p: string): boolean;
8
8
  /** ZIP 条目名安全检查(Zip Slip / 绝对路径 / 盘符 / NUL,规范 §19.1-2)。
9
9
  * 规则与 node:path 解耦:纯分段校验,跨平台无歧义。 */
10
10
  export declare function isPathSafe(entryName: string): boolean;
11
- /** 候选目录是否位于父目录之内(含等于父目录)。
11
+ /** 越界判定选项。 */
12
+ export interface PathInsideOptions {
13
+ /**
14
+ * 比较前折叠大小写(Windows 文件系统大小写不敏感)。缺省按当前平台。
15
+ * 显式传 false 的场景:拿另一台机器的路径做形状判定(跨平台导入)。
16
+ */
17
+ foldCase?: boolean;
18
+ }
19
+ /** 候选路径是否位于父目录之内(含等于父目录)。
12
20
  *
13
- * 纯字符串语义(不碰文件系统):两侧必须是**同一种拼写**,调用方若混用
14
- * realpath 结果与原路径(Windows 8.3 短名、macOS `/var`→`/private/var`)会误判为越界 ——
15
- * `path.relative` 不会折叠短名,务必先各自 realpath 再调用。 */
21
+ * 全仓**唯一**的越界判定(restore / verify-recovery / zip / recursive-walk / 路由都走这里):
22
+ * 早期四处各写一份,其中三份用 `rel.startsWith('..')` 判越界 —— 名字真的叫 `..foo` 的
23
+ * 兄弟目录会被误判为逃逸(`path.relative('/a/b','/a/b/..foo') === '..foo'`)。
24
+ * 越界只有两种形态:相对结果是 `..` 段本身,或以 `..` + 分隔符开头;绝对结果(跨盘符)同样越界。
25
+ *
26
+ * 纯字符串语义(**不碰文件系统**):两侧各自 `path.resolve` 后比较。调用方若混用
27
+ * realpath 结果与原路径(Windows 8.3 短名、macOS `/var`→`/private/var`)仍会误判为越界 ——
28
+ * `path.resolve` 不折叠短名,真实路径那一层必须两侧都先 realpath 再调用。
29
+ */
30
+ export declare function isPathInside(child: string, parent: string, options?: PathInsideOptions): boolean;
31
+ /** 候选目录是否位于父目录之内(含等于父目录)—— `isPathInside` 的读法友好别名。 */
16
32
  export declare function isSameOrChild(p: string, parent: string): boolean;
17
33
  /**
18
34
  * 归一化并折叠 `.` / `..` 路径段(Reviewer B P0 修复)。
@@ -47,14 +47,30 @@ export function isPathSafe(entryName) {
47
47
  return false; // 目录穿越
48
48
  return true;
49
49
  }
50
- /** 候选目录是否位于父目录之内(含等于父目录)。
50
+ /** 候选路径是否位于父目录之内(含等于父目录)。
51
51
  *
52
- * 纯字符串语义(不碰文件系统):两侧必须是**同一种拼写**,调用方若混用
53
- * realpath 结果与原路径(Windows 8.3 短名、macOS `/var`→`/private/var`)会误判为越界 ——
54
- * `path.relative` 不会折叠短名,务必先各自 realpath 再调用。 */
52
+ * 全仓**唯一**的越界判定(restore / verify-recovery / zip / recursive-walk / 路由都走这里):
53
+ * 早期四处各写一份,其中三份用 `rel.startsWith('..')` 判越界 —— 名字真的叫 `..foo` 的
54
+ * 兄弟目录会被误判为逃逸(`path.relative('/a/b','/a/b/..foo') === '..foo'`)。
55
+ * 越界只有两种形态:相对结果是 `..` 段本身,或以 `..` + 分隔符开头;绝对结果(跨盘符)同样越界。
56
+ *
57
+ * 纯字符串语义(**不碰文件系统**):两侧各自 `path.resolve` 后比较。调用方若混用
58
+ * realpath 结果与原路径(Windows 8.3 短名、macOS `/var`→`/private/var`)仍会误判为越界 ——
59
+ * `path.resolve` 不折叠短名,真实路径那一层必须两侧都先 realpath 再调用。
60
+ */
61
+ export function isPathInside(child, parent, options = {}) {
62
+ const foldCase = options.foldCase ?? process.platform === 'win32';
63
+ const fold = (v) => (foldCase ? v.toLowerCase() : v);
64
+ const rel = path.relative(fold(path.resolve(parent)), fold(path.resolve(child)));
65
+ if (rel === '')
66
+ return true;
67
+ if (path.isAbsolute(rel))
68
+ return false; // 跨盘符(win32 relative 直接回绝对路径)
69
+ return rel !== '..' && !rel.startsWith(`..${path.sep}`);
70
+ }
71
+ /** 候选目录是否位于父目录之内(含等于父目录)—— `isPathInside` 的读法友好别名。 */
55
72
  export function isSameOrChild(p, parent) {
56
- const rel = path.relative(parent, p);
57
- return rel === '' || (!rel.startsWith('..') && !path.isAbsolute(rel));
73
+ return isPathInside(p, parent);
58
74
  }
59
75
  /**
60
76
  * 内部 control-plane namespace(F23 修复):不可信 import(pluginFiles/self/file adapters)
@@ -0,0 +1,31 @@
1
+ /**
2
+ * 时间戳格式化的唯一实现(host 与 client 共用,**零 import**)。
3
+ *
4
+ * 为什么单列一个模块:同一串 `YYYYMMDD-HHmmss` 曾在 5 处各写一遍(model-tools / backup-scheduler /
5
+ * cli·actions / cli·import-source / cli·index),`YYYY-MM-DD` 2 处,展示用的
6
+ * `YYYY-MM-DD HH:mm` 5 处(sync 历史、sync 状态、market、profiles、release notes)——
7
+ * 改一处口径(比如补毫秒、改本地时区)就得记住改十处,漏一处就是两套时间显示。
8
+ *
9
+ * 约束:**不得 import node 模块**(`src/client/**` 直接消费本模块)。
10
+ *
11
+ * 分工:本模块只负责**格式**,不负责「非法输入怎么显示」——那是各处的产品口径
12
+ * (历史表显示 `—`、profiles 显示空串、release notes 原样回显),由调用方决定;
13
+ * 这里只提供 `parseDateInput` 这一个统一的「能不能解析」判定。
14
+ */
15
+ /** 日期戳 `YYYYMMDD-HHmmss`(**本地时区**,用于导出文件名:定宽、仅 ASCII、可排序)。 */
16
+ export declare function formatDateStamp(d?: Date): string;
17
+ /** 日期 `YYYY-MM-DD`(**本地时区**,用于导出文件名 / 只显示日期的场景)。 */
18
+ export declare function formatDateOnly(d: Date): string;
19
+ /** 展示用本地时间 `YYYY-MM-DD HH:mm`(**本地时区**,精确到分钟)。 */
20
+ export declare function formatMinuteStamp(d: Date): string;
21
+ /**
22
+ * 解析时间输入(ISO 字符串或毫秒数)→ Date;不可解析给 null。
23
+ *
24
+ * 与 `new Date(x)` 的差别只有三条**判定**,解析规则本身完全继承:
25
+ * 1. `null` / `undefined` / 空串 / 纯空白 → null(否则 `new Date('')` 给 Invalid Date,
26
+ * 更糟的是 `new Date(null)` 会静默变成 1970-01-01);
27
+ * 2. `number`:`NaN` / `Infinity` / `-Infinity` → null;
28
+ * 3. 解析结果 `getTime()` 非有限 → null。
29
+ * 调用方拿 null 决定回退文案(`—` / 空串 / 原样回显),本模块不替它选。
30
+ */
31
+ export declare function parseDateInput(input: string | number | null | undefined): Date | null;
@@ -0,0 +1,54 @@
1
+ /**
2
+ * 时间戳格式化的唯一实现(host 与 client 共用,**零 import**)。
3
+ *
4
+ * 为什么单列一个模块:同一串 `YYYYMMDD-HHmmss` 曾在 5 处各写一遍(model-tools / backup-scheduler /
5
+ * cli·actions / cli·import-source / cli·index),`YYYY-MM-DD` 2 处,展示用的
6
+ * `YYYY-MM-DD HH:mm` 5 处(sync 历史、sync 状态、market、profiles、release notes)——
7
+ * 改一处口径(比如补毫秒、改本地时区)就得记住改十处,漏一处就是两套时间显示。
8
+ *
9
+ * 约束:**不得 import node 模块**(`src/client/**` 直接消费本模块)。
10
+ *
11
+ * 分工:本模块只负责**格式**,不负责「非法输入怎么显示」——那是各处的产品口径
12
+ * (历史表显示 `—`、profiles 显示空串、release notes 原样回显),由调用方决定;
13
+ * 这里只提供 `parseDateInput` 这一个统一的「能不能解析」判定。
14
+ */
15
+ function pad2(n) {
16
+ return String(n).padStart(2, '0');
17
+ }
18
+ /** 日期戳 `YYYYMMDD-HHmmss`(**本地时区**,用于导出文件名:定宽、仅 ASCII、可排序)。 */
19
+ export function formatDateStamp(d = new Date()) {
20
+ return `${d.getFullYear()}${pad2(d.getMonth() + 1)}${pad2(d.getDate())}`
21
+ + `-${pad2(d.getHours())}${pad2(d.getMinutes())}${pad2(d.getSeconds())}`;
22
+ }
23
+ /** 日期 `YYYY-MM-DD`(**本地时区**,用于导出文件名 / 只显示日期的场景)。 */
24
+ export function formatDateOnly(d) {
25
+ return `${d.getFullYear()}-${pad2(d.getMonth() + 1)}-${pad2(d.getDate())}`;
26
+ }
27
+ /** 展示用本地时间 `YYYY-MM-DD HH:mm`(**本地时区**,精确到分钟)。 */
28
+ export function formatMinuteStamp(d) {
29
+ return `${formatDateOnly(d)} ${pad2(d.getHours())}:${pad2(d.getMinutes())}`;
30
+ }
31
+ /**
32
+ * 解析时间输入(ISO 字符串或毫秒数)→ Date;不可解析给 null。
33
+ *
34
+ * 与 `new Date(x)` 的差别只有三条**判定**,解析规则本身完全继承:
35
+ * 1. `null` / `undefined` / 空串 / 纯空白 → null(否则 `new Date('')` 给 Invalid Date,
36
+ * 更糟的是 `new Date(null)` 会静默变成 1970-01-01);
37
+ * 2. `number`:`NaN` / `Infinity` / `-Infinity` → null;
38
+ * 3. 解析结果 `getTime()` 非有限 → null。
39
+ * 调用方拿 null 决定回退文案(`—` / 空串 / 原样回显),本模块不替它选。
40
+ */
41
+ export function parseDateInput(input) {
42
+ if (input === null || input === undefined)
43
+ return null;
44
+ if (typeof input === 'number') {
45
+ if (!Number.isFinite(input))
46
+ return null;
47
+ return new Date(input);
48
+ }
49
+ if (input.trim() === '')
50
+ return null;
51
+ const d = new Date(input);
52
+ return Number.isFinite(d.getTime()) ? d : null;
53
+ }
54
+ //# sourceMappingURL=time.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-config-manager",
3
- "version": "0.4.1",
3
+ "version": "0.4.2",
4
4
  "license": "MIT",
5
5
  "description": "Backup, restore, export, import, migrate and sync your DeepSeek Harness (DSH) configuration: settings, plugins, MCP servers, skills, agent presets and workspaces. One-click migration to another machine. DSH 配置一键备份、恢复、导出、导入、迁移与同步插件。",
6
6
  "icon": "./icon.svg",
@@ -34,6 +34,7 @@ import {
34
34
  import { EnvironmentLockManager, OWNERSHIP_FILE } from '../utils/env-lock.ts'
35
35
  import { scanSessionHealth, type SessionHealthScanResult } from '../utils/session-health-scan.ts'
36
36
  import type { SessionVerifyResult } from '../utils/session-verify.ts'
37
+ import { formatDateStamp } from '../utils/time.ts'
37
38
 
38
39
  /* ------------------------------------------------------------ 进程/实例事实 */
39
40
 
@@ -1352,9 +1353,7 @@ export async function exportOfflineBackup(
1352
1353
  if (collection.entries.length === 0) {
1353
1354
  return { ok: false, code: 'nothing-to-export', message: '没有可打包的内容(该 home 下未找到可离线收集的分区)。' }
1354
1355
  }
1355
- const now = new Date()
1356
- const stamp = String(now.getFullYear()) + String(now.getMonth() + 1).padStart(2, '0') + String(now.getDate()).padStart(2, '0')
1357
- + '-' + String(now.getHours()).padStart(2, '0') + String(now.getMinutes()).padStart(2, '0') + String(now.getSeconds()).padStart(2, '0')
1356
+ const stamp = formatDateStamp()
1358
1357
  const { randomBytes } = await import('node:crypto')
1359
1358
  const desired = 'dsh-config-cli-' + stamp + '-' + randomBytes(4).toString('hex') + '.zip'
1360
1359
  await fsp.mkdir(paths.exportsDir, { recursive: true })
@@ -29,6 +29,7 @@ import { foreignSourceContext } from '../routes/foreign-context.ts';
29
29
  import type { ForeignSourceContext, ForeignSourceDetection } from '../foreign/registry.ts';
30
30
  import type { ForeignImportResult } from '../foreign/types.ts';
31
31
  import type { Platform } from '../schema/types.ts';
32
+ import { formatDateStamp } from '../utils/time.ts';
32
33
 
33
34
  /** CLI 侧只依赖这个最小 IO 形状(与 src/cli/index.ts 的 CliIo 结构等价,避免循环 import) */
34
35
  export interface ImportIo {
@@ -110,7 +111,7 @@ function printImportSummary(
110
111
  async function resolveOutPath(options: ImportSourceOptions, sourceId: string): Promise<string> {
111
112
  const desired = options.out !== undefined && options.out !== ''
112
113
  ? path.resolve(options.out)
113
- : path.join(options.exportsDir, 'foreign-' + sourceId + '-' + stamp() + '-' + randomHex4() + '.zip');
114
+ : path.join(options.exportsDir, 'foreign-' + sourceId + '-' + formatDateStamp() + '-' + randomHex4() + '.zip');
114
115
  if (!(await pathExists(desired))) return desired;
115
116
  const base = desired.endsWith('.zip') ? desired.slice(0, -4) : desired;
116
117
  for (let i = 1; ; i += 1) {
@@ -119,12 +120,6 @@ async function resolveOutPath(options: ImportSourceOptions, sourceId: string): P
119
120
  }
120
121
  }
121
122
 
122
- function stamp(): string {
123
- const now = new Date();
124
- return `${now.getFullYear()}${String(now.getMonth() + 1).padStart(2, '0')}${String(now.getDate()).padStart(2, '0')}`
125
- + `-${String(now.getHours()).padStart(2, '0')}${String(now.getMinutes()).padStart(2, '0')}${String(now.getSeconds()).padStart(2, '0')}`;
126
- }
127
-
128
123
  function randomHex4(): string {
129
124
  // 用全局 crypto(Node ≥ 19);零额外依赖
130
125
  const bytes = new Uint8Array(4);
package/src/cli/index.ts CHANGED
@@ -54,6 +54,7 @@ import { stringifyJsonSafe } from '../utils/json.ts';
54
54
  import { buildManifest, CHECKSUMS_FILE, MANIFEST_FILE } from '../schema/manifest.ts';
55
55
  import { writeZip } from '../utils/zip.ts';
56
56
  import type { Manifest, SectionId } from '../schema/types.ts';
57
+ import { formatDateStamp } from '../utils/time.ts';
57
58
 
58
59
  /* ------------------------------------------------------------ 参数解析(纯函数) */
59
60
 
@@ -1354,9 +1355,7 @@ async function runBackup(
1354
1355
  }
1355
1356
  } else {
1356
1357
  // 注意:此处刻意不 mkdir —— dry-run 必须零写入,目录在真正落盘前才创建
1357
- const now = new Date();
1358
- const stamp = `${now.getFullYear()}${String(now.getMonth() + 1).padStart(2, '0')}${String(now.getDate()).padStart(2, '0')}`
1359
- + `-${String(now.getHours()).padStart(2, '0')}${String(now.getMinutes()).padStart(2, '0')}${String(now.getSeconds()).padStart(2, '0')}`;
1358
+ const stamp = formatDateStamp();
1360
1359
  try {
1361
1360
  const rand = await randomHex4();
1362
1361
  outPath = await resolveNonCollidingName(exportsDir, `dsh-config-cli-${stamp}-${rand}.zip`);
@@ -133,7 +133,7 @@ export function AboutPanel({ api, t }: AboutPanelProps) {
133
133
  {/* issue #28 诊断位:插件清单实际读的目录 / profile / 识别到的插件数。
134
134
  用于自查「装了插件却没被备份识别到」——此前用户完全无从查看。 */}
135
135
  {state.rows?.diagnostics != null && (
136
- <div className={css.statRow} style={{ flexDirection: 'column', alignItems: 'flex-start', gap: '4px' }}>
136
+ <div className={css.statRow + ' ' + css.statRowStack}>
137
137
  <span className={css.groupLabel}>{t('about.diag.label')} <InfoHint text={t('about.diag.hint')} label={t('common.infoHint')} /></span>
138
138
  <span>{t('about.diag.profileDir', { path: state.rows.diagnostics.profileDir })}</span>
139
139
  <span>{t('about.diag.profile', { profile: state.rows.diagnostics.profile })}</span>
@@ -58,58 +58,39 @@ function renderInlineMarkdown(text: string) {
58
58
  function MarkdownBlockView({ block }: { block: MarkdownBlock }) {
59
59
  switch (block.type) {
60
60
  case 'heading': {
61
- const headingStyle = {
62
- fontWeight: 600,
63
- color: 'var(--dsw-alias-label-primary)',
64
- marginTop: block.level === 1 ? '12px' : '8px',
65
- marginBottom: '4px',
66
- fontSize: block.level === 1 ? '15px' : block.level === 2 ? '14px' : '13px',
67
- }
68
- return <div style={headingStyle}>{block.text}</div>
61
+ /**
62
+ * 只有字号还留在内联:15/14/13px 三级要靠同一规则表达,而 DESIGN.md §4 的字号 scale
63
+ * 只有 4 档(11/12/12.5/13)—— 把 15/14 写进 CSS 会让 scale-01 直接变红。
64
+ * 这是 css-token-guard 豁免表里唯一一条 release 相关例外(见 TSX_STYLE_WHITELIST)。
65
+ */
66
+ return (
67
+ <div
68
+ className={css.releaseHeading}
69
+ data-level={String(block.level)}
70
+ style={{ fontSize: block.level === 1 ? '15px' : block.level === 2 ? '14px' : '13px' }}
71
+ >
72
+ {block.text}
73
+ </div>
74
+ )
69
75
  }
70
76
  case 'list-item': {
71
77
  return (
72
- <div style={{ display: 'flex', gap: '6px', alignItems: 'flex-start', paddingLeft: '4px' }}>
73
- <span style={{ color: 'var(--dsw-alias-label-tertiary)', userSelect: 'none' }}>
78
+ <div className={css.releaseListItem}>
79
+ <span className={css.releaseBullet}>
74
80
  {block.ordered ? (block.index ?? 1) + '.' : '•'}
75
81
  </span>
76
- <div style={{ flex: 1 }}>{renderInlineMarkdown(block.text)}</div>
82
+ <div className={css.releaseItemBody}>{renderInlineMarkdown(block.text)}</div>
77
83
  </div>
78
84
  )
79
85
  }
80
86
  case 'quote': {
81
- return (
82
- <div
83
- style={{
84
- borderLeft: '3px solid var(--dsw-alias-border-l1)',
85
- paddingLeft: '8px',
86
- color: 'var(--dsw-alias-label-secondary)',
87
- fontStyle: 'italic',
88
- }}
89
- >
90
- {renderInlineMarkdown(block.text)}
91
- </div>
92
- )
87
+ return <div className={css.releaseQuote}>{renderInlineMarkdown(block.text)}</div>
93
88
  }
94
89
  case 'code-block': {
95
- return (
96
- <pre
97
- className={css.cliCommand}
98
- style={{ margin: '4px 0', padding: '8px', fontSize: '12px' }}
99
- >
100
- {block.code}
101
- </pre>
102
- )
90
+ return <pre className={css.cliCommand + ' ' + css.releaseCode}>{block.code}</pre>
103
91
  }
104
92
  case 'hr': {
105
- return (
106
- <div
107
- style={{
108
- borderBottom: '1px solid var(--dsw-alias-border-l2)',
109
- margin: '8px 0',
110
- }}
111
- />
112
- )
93
+ return <div className={css.releaseRule} />
113
94
  }
114
95
  case 'paragraph':
115
96
  default: {
@@ -122,22 +103,11 @@ function MarkdownBlockView({ block }: { block: MarkdownBlock }) {
122
103
  export function ReleaseBody({ body, t }: { body: string; t: TranslateNS<'config-manager'> }) {
123
104
  const blocks = parseMarkdownBlocks(body)
124
105
  return (
125
- <div
126
- style={{
127
- display: 'flex',
128
- flexDirection: 'column',
129
- gap: '6px',
130
- fontSize: '13px',
131
- lineHeight: '1.6',
132
- color: 'var(--dsw-alias-label-primary)',
133
- }}
134
- >
106
+ <div className={css.releaseBody}>
135
107
  {blocks.length > 0 ? (
136
108
  blocks.map((block, idx) => <MarkdownBlockView key={idx} block={block} />)
137
109
  ) : (
138
- <div style={{ color: 'var(--dsw-alias-label-tertiary)', fontStyle: 'italic' }}>
139
- {t('about.releaseNotes.noBody')}
140
- </div>
110
+ <div className={css.releaseEmpty}>{t('about.releaseNotes.noBody')}</div>
141
111
  )}
142
112
  </div>
143
113
  )