dsh-config-manager 0.3.1 → 0.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/client.d.ts +54 -3
- package/lib/client.js +1078 -845
- package/lib/core/env-lock-lifecycle.d.ts +45 -0
- package/lib/core/env-lock-lifecycle.js +43 -0
- package/lib/core/history-prune.d.ts +34 -0
- package/lib/core/history-prune.js +43 -0
- package/lib/core/index.d.ts +1 -1
- package/lib/core/index.js +1 -1
- package/lib/core/messages-core.d.ts +1 -0
- package/lib/core/messages-core.js +2 -0
- package/lib/core/migration-history.d.ts +46 -4
- package/lib/core/migration-history.js +60 -7
- package/lib/index.d.ts +2 -2
- package/lib/index.js +26 -8
- package/lib/routes/history.js +70 -5
- package/lib/routes/index.d.ts +1 -1
- package/lib/routes/kit.d.ts +2 -2
- package/lib/routes/messages.d.ts +1 -0
- package/lib/routes/messages.js +3 -0
- package/lib/sync/autosync-scheduler.js +12 -2
- package/lib/sync/backup-scheduler.js +6 -0
- package/lib/sync/baseline-heal.d.ts +35 -0
- package/lib/sync/baseline-heal.js +39 -0
- package/lib/sync/push-precheck.d.ts +35 -0
- package/lib/sync/push-precheck.js +58 -0
- package/lib/sync/sync-engine.d.ts +9 -12
- package/lib/sync/sync-engine.js +24 -43
- package/lib/sync/ui-prefs.d.ts +8 -0
- package/lib/sync/ui-prefs.js +8 -0
- package/lib/ui/history-model.js +3 -2
- package/lib/ui/overview-view.d.ts +3 -3
- package/lib/ui/overview-view.js +9 -1
- package/lib/utils/env-lock.d.ts +55 -1
- package/lib/utils/env-lock.js +131 -2
- package/lib/utils/messages-utils.d.ts +3 -0
- package/lib/utils/messages-utils.js +6 -0
- package/package.json +1 -1
- package/src/client/common/InfoHint.tsx +12 -3
- package/src/client/common/Skeleton.tsx +45 -8
- package/src/client/common/info-hint-guard.test.ts +196 -0
- package/src/client/common/routes.ts +3 -1
- package/src/client/common/skeleton-guard.test.ts +58 -0
- package/src/client/common/ui.tsx +17 -4
- package/src/client/config-manager.module.css +256 -27
- package/src/client/css-motion-guard.test.ts +230 -0
- package/src/client/environment/EnvironmentPanel.tsx +41 -29
- package/src/client/environment/maintenance/DiskUsageCard.tsx +28 -33
- package/src/client/environment/profiles-incomplete-ui.test.ts +9 -5
- package/src/client/export/ExportView.tsx +6 -6
- package/src/client/history/HistoryPanel.tsx +87 -2
- package/src/client/history/history-api.ts +49 -3
- package/src/client/history/history-locales.ts +32 -0
- package/src/client/home/HomePanel.tsx +64 -26
- package/src/client/locales.ts +2 -0
- package/src/client/market/MyConfigsWizard.tsx +12 -3
- package/src/client/recovery/RecoveryPanel.tsx +93 -92
- package/src/client/recovery/RollbackCard.tsx +25 -16
- package/src/client/sync/AutosyncCard.tsx +12 -6
- package/src/client/sync/ChannelConfigDialog.tsx +45 -45
- package/src/client/sync/DecryptPasswordCard.tsx +3 -3
- package/src/client/sync/SecurityOptionsCard.tsx +3 -3
- package/src/client/sync/SyncSectionPickerDialog.tsx +3 -3
- package/src/client/sync/history-model.ts +3 -0
- package/src/client/sync/sync-locales.ts +2 -0
- package/src/core/env-lock-lifecycle.ts +73 -0
- package/src/core/history-prune.test.ts +115 -0
- package/src/core/history-prune.ts +61 -0
- package/src/core/index.ts +2 -0
- package/src/core/messages-core.ts +2 -0
- package/src/core/migration-history.test.ts +97 -0
- package/src/core/migration-history.ts +74 -9
- package/src/index.ts +27 -8
- package/src/routes/history.ts +81 -4
- package/src/routes/index.ts +1 -1
- package/src/routes/kit.ts +2 -2
- package/src/routes/messages.ts +3 -0
- package/src/sync/autosync-scheduler.test.ts +23 -0
- package/src/sync/autosync-scheduler.ts +9 -2
- package/src/sync/backup-scheduler.ts +3 -0
- package/src/sync/baseline-heal.ts +74 -0
- package/src/sync/push-precheck.ts +75 -0
- package/src/sync/sync-engine.test.ts +88 -0
- package/src/sync/sync-engine.ts +33 -43
- package/src/sync/ui-prefs.test.ts +32 -0
- package/src/sync/ui-prefs.ts +16 -0
- package/src/ui/history-model.test.ts +2 -1
- package/src/ui/history-model.ts +3 -2
- package/src/ui/overview-view.test.ts +12 -0
- package/src/ui/overview-view.ts +12 -4
- package/src/utils/env-lock.test.ts +107 -0
- package/src/utils/env-lock.ts +124 -2
- package/src/utils/messages-utils.ts +6 -0
package/lib/routes/history.js
CHANGED
|
@@ -4,22 +4,41 @@
|
|
|
4
4
|
* W1(host-entry#F-02/#F-03):路由只在这里声明一次 —— endpoint({ path, methods }, handler) 的
|
|
5
5
|
* path/methods 就是唯一声明处;围栏、方法判定与顶层异常处理由 src/routes/kit.ts 在注册点统一提供。
|
|
6
6
|
*/
|
|
7
|
-
import { endpoint, writeJson } from './kit.js';
|
|
8
|
-
import { parseHistoryQuery, queryHistory, renderExport, summarizeHistory } from '../core/migration-history.js';
|
|
7
|
+
import { endpoint, requireJsonObject, writeJson } from './kit.js';
|
|
8
|
+
import { DEFAULT_MIGRATION_RETENTION, HISTORY_RETENTION_MAX, HISTORY_RETENTION_MIN, isValidHistoryRetention, parseHistoryQuery, queryHistory, renderExport, resolveHistoryRetention, summarizeHistory, } from '../core/migration-history.js';
|
|
9
|
+
import { readUiPrefs, updateUiPrefs } from '../sync/ui-prefs.js';
|
|
10
|
+
/** 列表接口的 limit 上限:防「?limit=99999999」把只读端点的读放大成拒绝服务面。 */
|
|
11
|
+
const HISTORY_LIST_LIMIT_MAX = 5000;
|
|
12
|
+
/**
|
|
13
|
+
* 解析列表请求的 limit:缺省 / 非法 / 负数 = 0(= 全量,老口径不变);超上限按上限截断。
|
|
14
|
+
* 只接受十进制整数字面量(parseInt 会把 '12abc' 读成 12,故先用正则判形)。
|
|
15
|
+
*/
|
|
16
|
+
function parseListLimit(raw) {
|
|
17
|
+
if (raw === null || !/^\d+$/.test(raw.trim()))
|
|
18
|
+
return 0;
|
|
19
|
+
const n = Number.parseInt(raw.trim(), 10);
|
|
20
|
+
if (!Number.isFinite(n) || n <= 0)
|
|
21
|
+
return 0;
|
|
22
|
+
return Math.min(n, HISTORY_LIST_LIMIT_MAX);
|
|
23
|
+
}
|
|
9
24
|
export function historyRoutes(env) {
|
|
10
|
-
const { history, host, } = env;
|
|
25
|
+
const { history, host, msg, syncDir, withMutationGate, } = env;
|
|
11
26
|
return [
|
|
12
27
|
// ------------------------------------------------------------ history
|
|
13
28
|
// Phase 6:迁移历史审计(统一历史引擎)。只读 GET:列表(过滤)+ 导出。
|
|
14
29
|
// loopback fence(guard)与全仓一致——仅同源 + loopback 可访问。
|
|
30
|
+
// ?limit=N:只读最近 N 条(文件名尾部窗口)。首页只要最近几十条活动,全量读 + 全量回传
|
|
31
|
+
// 会把首屏骨架拖到秒级(真机 2360 条:纯 IO/解析 650 ms,冷启动含回传 9.7 s)。
|
|
32
|
+
// 响应始终带 total(目录合法文件总数)与 scanned(本次实际读取条数),避免 UI 把窗口当全量。
|
|
15
33
|
endpoint({ path: '/api/dsh-config-manager/history', methods: ['GET'] }, async (req, res) => {
|
|
16
34
|
try {
|
|
17
35
|
const url = new URL(req.url ?? '/', 'http://localhost');
|
|
18
36
|
const q = parseHistoryQuery(Object.fromEntries(url.searchParams));
|
|
19
|
-
const
|
|
37
|
+
const limit = parseListLimit(url.searchParams.get('limit'));
|
|
38
|
+
const { entries, corrupted, total } = await history.read({ limit });
|
|
20
39
|
const filtered = queryHistory(entries, q);
|
|
21
40
|
const stats = summarizeHistory(filtered);
|
|
22
|
-
writeJson(res, 200, { ok: true, entries: filtered, stats, corrupted });
|
|
41
|
+
writeJson(res, 200, { ok: true, entries: filtered, stats, corrupted, total: total ?? entries.length, scanned: entries.length, limit });
|
|
23
42
|
}
|
|
24
43
|
catch (error) {
|
|
25
44
|
writeJson(res, 500, { error: error instanceof Error ? error.message : String(error) });
|
|
@@ -48,6 +67,52 @@ export function historyRoutes(env) {
|
|
|
48
67
|
writeJson(res, 500, { error: error instanceof Error ? error.message : String(error) });
|
|
49
68
|
}
|
|
50
69
|
}),
|
|
70
|
+
// ------------------------------------------------------ history/retention
|
|
71
|
+
// 迁移历史自动清理(issue:历史目录只增不减,真机已 2360 条 / 0.67 MB)。
|
|
72
|
+
// 策略存 ui-prefs.json 的 historyRetentionMaxEntries(0 = 不限制,缺省 1000);
|
|
73
|
+
// 宿主在每次写入历史后按该值节流清理最旧条目(调度与取舍 → src/core/history-prune.ts)。
|
|
74
|
+
// GET → 当前策略 + 目录现状;POST → 改策略并立即清理一次(同一道写入门)。
|
|
75
|
+
// 一条 exact 路由 + 方法内部分发:webserver 对重复 (kind, path) 直接抛错。
|
|
76
|
+
endpoint({ path: '/api/dsh-config-manager/history/retention', methods: ['GET', 'POST'] }, async (req, res) => {
|
|
77
|
+
if (req.method === 'GET') {
|
|
78
|
+
try {
|
|
79
|
+
const [prefs, total] = await Promise.all([readUiPrefs(syncDir), history.count()]);
|
|
80
|
+
writeJson(res, 200, {
|
|
81
|
+
ok: true,
|
|
82
|
+
maxEntries: resolveHistoryRetention(prefs.historyRetentionMaxEntries),
|
|
83
|
+
total,
|
|
84
|
+
defaultMaxEntries: DEFAULT_MIGRATION_RETENTION,
|
|
85
|
+
allowedMin: HISTORY_RETENTION_MIN,
|
|
86
|
+
allowedMax: HISTORY_RETENTION_MAX,
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
catch (error) {
|
|
90
|
+
writeJson(res, 500, { error: error instanceof Error ? error.message : String(error) });
|
|
91
|
+
}
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
// 写分支:删历史属破坏性操作,与其它写路径同一道门(不写审计条目 → 见 history-prune 头注释)。
|
|
95
|
+
await withMutationGate('history-retention', async (gatedReq, gatedRes) => {
|
|
96
|
+
const body = await requireJsonObject(gatedReq);
|
|
97
|
+
const next = body['maxEntries'];
|
|
98
|
+
if (!isValidHistoryRetention(next)) {
|
|
99
|
+
writeJson(gatedRes, 400, {
|
|
100
|
+
ok: false,
|
|
101
|
+
code: 'invalid-retention',
|
|
102
|
+
error: msg('route.historyRetentionInvalid', { min: HISTORY_RETENTION_MIN, max: HISTORY_RETENTION_MAX }),
|
|
103
|
+
});
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
// 先落策略再清理:清理失败也要让新策略生效(下一次写入会重试),否则用户改完不生效。
|
|
107
|
+
await updateUiPrefs(syncDir, { historyRetentionMaxEntries: next });
|
|
108
|
+
const removed = next > 0 ? await history.retention(next) : [];
|
|
109
|
+
const total = await history.count();
|
|
110
|
+
if (removed.length > 0) {
|
|
111
|
+
host.log.info('迁移历史自动清理', { maxEntries: next, removed: removed.length, total });
|
|
112
|
+
}
|
|
113
|
+
writeJson(gatedRes, 200, { ok: true, maxEntries: next, removed: removed.length, total });
|
|
114
|
+
}, { journaled: false })(req, res);
|
|
115
|
+
}),
|
|
51
116
|
];
|
|
52
117
|
}
|
|
53
118
|
//# sourceMappingURL=history.js.map
|
package/lib/routes/index.d.ts
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
*
|
|
4
4
|
* 顺序对匹配无影响:DSH webServer 的契约是「命名路由必须互不相同,注册顺序不影响请求」
|
|
5
5
|
* (见 @deepseek-ai/dsh-host-webserver 的 WebServer 文档)。src/index.ts 保留的 7 条被源码级
|
|
6
|
-
* 守卫按文件窗口钉住,其余
|
|
6
|
+
* 守卫按文件窗口钉住,其余 77 条在这里组装(总数 84:含 path-browse)。
|
|
7
7
|
*/
|
|
8
8
|
import type { WebRoute } from './kit.ts';
|
|
9
9
|
import type { RoutesEnv } from './context.ts';
|
package/lib/routes/kit.d.ts
CHANGED
|
@@ -8,8 +8,8 @@
|
|
|
8
8
|
* - 「每条路由首行 guard」这条安全不变量此前**只写在注释里**,零测试覆盖;
|
|
9
9
|
* - 3 条 prefix 路由自造围栏(裸 isLoopbackRequest + 自判方法)。
|
|
10
10
|
*
|
|
11
|
-
* 计数口径(三路一致 =
|
|
12
|
-
* 路由快照
|
|
11
|
+
* 计数口径(三路一致 = 84,勿再照抄旧审计初稿的计数 —— 那是计数口径 overcount):
|
|
12
|
+
* 路由快照 84 条 = 现行 `endpoint()` 声明 84 条 = 运行期 `buildRoutes()` 77 条 + `src/index.ts` 保留的 7 条。
|
|
13
13
|
* 增删路由后必须同步这段计数、`src/routes/index.ts` 的头注释与 parity 快照清单;`tests/route/route-parity.test.ts`
|
|
14
14
|
* 的「路由计数散文」守卫会拿真实声明数逐条对账(写错即红灯)。
|
|
15
15
|
*
|
package/lib/routes/messages.d.ts
CHANGED
|
@@ -6,6 +6,7 @@ export declare const zh: {
|
|
|
6
6
|
readonly 'route.importNoSections': '无分区';
|
|
7
7
|
readonly 'route.importHistorySummary': '导入完成:{sections}(执行 {count} 项)';
|
|
8
8
|
readonly 'route.importIncomplete': '导入未完全成功';
|
|
9
|
+
readonly 'route.historyRetentionInvalid': '保留上限必须是 {min}–{max} 之间的整数(0 = 不限制)';
|
|
9
10
|
readonly 'route.profileLaunchSummary': '启动档案 {name}(独立实例 :{port})';
|
|
10
11
|
readonly 'route.profileCreateSummary': '新建档案 {name}(模板 {template})';
|
|
11
12
|
readonly 'route.profileCopySummary': '复制档案 {from} → {to}{suffix}';
|
package/lib/routes/messages.js
CHANGED
|
@@ -21,6 +21,8 @@ export const zh = {
|
|
|
21
21
|
'route.importNoSections': '无分区',
|
|
22
22
|
'route.importHistorySummary': '导入完成:{sections}(执行 {count} 项)',
|
|
23
23
|
'route.importIncomplete': '导入未完全成功',
|
|
24
|
+
// ---------- 迁移历史自动清理 ----------
|
|
25
|
+
'route.historyRetentionInvalid': '保留上限必须是 {min}–{max} 之间的整数(0 = 不限制)',
|
|
24
26
|
// ---------- 档案 ----------
|
|
25
27
|
'route.profileLaunchSummary': '启动档案 {name}(独立实例 :{port})',
|
|
26
28
|
'route.profileCreateSummary': '新建档案 {name}(模板 {template})',
|
|
@@ -64,6 +66,7 @@ export const en = {
|
|
|
64
66
|
'route.importNoSections': 'no sections',
|
|
65
67
|
'route.importHistorySummary': 'Import finished: {sections} ({count} item(s) executed)',
|
|
66
68
|
'route.importIncomplete': 'Import did not fully succeed',
|
|
69
|
+
'route.historyRetentionInvalid': 'Retention limit must be an integer between {min} and {max} (0 = unlimited)',
|
|
67
70
|
'route.profileLaunchSummary': 'Launched profile {name} (separate instance :{port})',
|
|
68
71
|
'route.profileCreateSummary': 'Created profile {name} (template {template})',
|
|
69
72
|
'route.profileCopySummary': 'Copied profile {from} → {to}{suffix}',
|
|
@@ -440,6 +440,12 @@ export class AutoSyncScheduler {
|
|
|
440
440
|
let releaseLock = null;
|
|
441
441
|
if (this.mutationLock !== undefined) {
|
|
442
442
|
try {
|
|
443
|
+
// 本轮开始前先自愈:上一轮异常退出留下的**可证** stale 残留锁只会让每轮静默 skip,
|
|
444
|
+
// 用户不重启就永远不同步。只删可证的(owner 确证死亡 / PID 复用),其余保持下面既有的 warn 路径。
|
|
445
|
+
try {
|
|
446
|
+
await this.mutationLock.reclaimProvableStaleLock?.();
|
|
447
|
+
}
|
|
448
|
+
catch { /* 预检失败不改变既有路径 */ }
|
|
443
449
|
const lk = await withMutationLock(this.mutationLock, { op: 'autosync', target: channel, isBlocked: this.isBlocked });
|
|
444
450
|
if (lk.context === null) {
|
|
445
451
|
this.running = false;
|
|
@@ -737,11 +743,15 @@ export class AutoSyncScheduler {
|
|
|
737
743
|
: partial
|
|
738
744
|
? conflictedSections
|
|
739
745
|
: deferredSections;
|
|
746
|
+
// 0.4.1:推送前收养了「本机自己推上去的」远端快照(上次推送在写基线前被打断)→
|
|
747
|
+
// 如实记一条 skipReason,让历史与首页能说清「这次推上去之前先修好了基线」,
|
|
748
|
+
// 而不是让用户以为又发生了一次莫名冲突。冲突原因优先(真有冲突时更该被看见)。
|
|
749
|
+
const adoptedReason = pushReport.adoptedBase !== undefined ? 'baseline-adopted' : undefined;
|
|
740
750
|
const result = {
|
|
741
751
|
status: partial ? 'partial' : 'success',
|
|
742
752
|
direction: appliedSections.length ? 'both' : 'push',
|
|
743
753
|
appliedSections, pushedSnapshotId: pushReport.snapshotId, historyId,
|
|
744
|
-
...(skipReason !== undefined ? { skipReason } : {}),
|
|
754
|
+
...(skipReason !== undefined || adoptedReason !== undefined ? { skipReason: skipReason ?? adoptedReason } : {}),
|
|
745
755
|
...(reportedConflicted.length > 0 ? { conflictedSections: reportedConflicted } : {}),
|
|
746
756
|
consecutiveFailures: 0,
|
|
747
757
|
...forcedMark,
|
|
@@ -750,7 +760,7 @@ export class AutoSyncScheduler {
|
|
|
750
760
|
direction: appliedSections.length ? 'both' : 'push',
|
|
751
761
|
status: partial ? 'partial' : 'success',
|
|
752
762
|
appliedSections, pushedSnapshotId: pushReport.snapshotId,
|
|
753
|
-
...(skipReason !== undefined ? { skipReason } : {}),
|
|
763
|
+
...(skipReason !== undefined || adoptedReason !== undefined ? { skipReason: skipReason ?? adoptedReason } : {}),
|
|
754
764
|
...(reportedConflicted.length > 0 ? { conflictedSections: reportedConflicted } : {}),
|
|
755
765
|
createdAt: nowIso, failureCountAtRun: 0,
|
|
756
766
|
...forcedMark,
|
|
@@ -153,6 +153,12 @@ export class BackupScheduler {
|
|
|
153
153
|
return { status: 'skipped', skipReason: 'conflict', consecutiveFailures: cfg.consecutiveFailures };
|
|
154
154
|
}
|
|
155
155
|
try {
|
|
156
|
+
// 本轮开始前先自愈:可证的 stale 残留锁会让每轮备份直接 skipped,用户不重启就永远不备份。
|
|
157
|
+
// 只删可证的(owner 确证死亡 / PID 复用);不可证的仍走下面 runWithMutationLock 的 skipped 分支。
|
|
158
|
+
try {
|
|
159
|
+
await this.mutationLock?.reclaimProvableStaleLock?.();
|
|
160
|
+
}
|
|
161
|
+
catch { /* 预检失败不改变既有路径 */ }
|
|
156
162
|
// Phase 2 锁:定时备份写入 exports 属 GLOBAL mutation(与 Sync push / 手动备份互斥)。
|
|
157
163
|
// 无锁环境(测试)→ 不锁定直接执行;锁被占用 → 返回 failed(destructive 不执行)。
|
|
158
164
|
const result = await runWithMutationLock(this.mutationLock, { op: 'backup-schedule', target: 'exports', isBlocked: this.isBlocked }, async (lockCtx) => {
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { MsgFunc } from '../core/messages.ts';
|
|
2
|
+
import type { SnapshotFs } from './fs.ts';
|
|
3
|
+
import type { SyncSnapshotMeta } from './transport.ts';
|
|
4
|
+
export interface AdoptOwnRemoteHeadOptions {
|
|
5
|
+
/** sync-state.json 所在目录。 */
|
|
6
|
+
stateDir: string;
|
|
7
|
+
fsx: SnapshotFs;
|
|
8
|
+
/** 本地快照副本目录(祖先来源);缺省 = 本机没有副本可指。 */
|
|
9
|
+
localSnapshotsDir?: string;
|
|
10
|
+
/** 远端快照列表(已按 createdAt 升序)。 */
|
|
11
|
+
metas: readonly SyncSnapshotMeta[];
|
|
12
|
+
/** 判定为「比基线新」的那份远端快照 id。 */
|
|
13
|
+
remoteId: string;
|
|
14
|
+
/** 本机当前基线(仅用于告警文案)。 */
|
|
15
|
+
base: string;
|
|
16
|
+
/** 本次通道身份(写回 sync-state.transport)。 */
|
|
17
|
+
transport: {
|
|
18
|
+
type: string;
|
|
19
|
+
ref: string;
|
|
20
|
+
};
|
|
21
|
+
hostname: string;
|
|
22
|
+
msg: MsgFunc;
|
|
23
|
+
/** 出参:收养说明追加到这里(调用方原样带给用户)。 */
|
|
24
|
+
warnings: string[];
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* 把「本机自己推上去、但基线没跟上」的远端最新快照收养为基线。
|
|
28
|
+
*
|
|
29
|
+
* 只写 sync-state:lastSnapshotId / 每分区 hash(取**被收养快照自己**的 sectionHashes,
|
|
30
|
+
* 不是本次导出结果)/ 祖先目录名(本机真有该副本才指过去,没有就保持原祖先 —— 三方合并仍成立,
|
|
31
|
+
* 也不会被写成一个不存在的目录名)。
|
|
32
|
+
*
|
|
33
|
+
* @returns 被收养的快照 id;null = 不满足收养条件(调用方按冲突返回)
|
|
34
|
+
*/
|
|
35
|
+
export declare function adoptOwnRemoteHead(opts: AdoptOwnRemoteHeadOptions): Promise<string | null>;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { joinFs } from './fs.js';
|
|
2
|
+
import { loadSyncState, resolveDeviceIdentity, saveSyncState } from './sync-state.js';
|
|
3
|
+
/**
|
|
4
|
+
* 把「本机自己推上去、但基线没跟上」的远端最新快照收养为基线。
|
|
5
|
+
*
|
|
6
|
+
* 只写 sync-state:lastSnapshotId / 每分区 hash(取**被收养快照自己**的 sectionHashes,
|
|
7
|
+
* 不是本次导出结果)/ 祖先目录名(本机真有该副本才指过去,没有就保持原祖先 —— 三方合并仍成立,
|
|
8
|
+
* 也不会被写成一个不存在的目录名)。
|
|
9
|
+
*
|
|
10
|
+
* @returns 被收养的快照 id;null = 不满足收养条件(调用方按冲突返回)
|
|
11
|
+
*/
|
|
12
|
+
export async function adoptOwnRemoteHead(opts) {
|
|
13
|
+
const meta = opts.metas.find((m) => m.id === opts.remoteId);
|
|
14
|
+
if (meta === undefined)
|
|
15
|
+
return null;
|
|
16
|
+
const device = await resolveDeviceIdentity(opts.stateDir, opts.hostname, opts.fsx, opts.msg);
|
|
17
|
+
const remoteDevice = meta.manifest.deviceId;
|
|
18
|
+
if (typeof remoteDevice !== 'string' || remoteDevice === '' || remoteDevice !== device.id)
|
|
19
|
+
return null;
|
|
20
|
+
const ancestorKnown = opts.localSnapshotsDir !== undefined
|
|
21
|
+
&& await opts.fsx.isDir(joinFs(opts.localSnapshotsDir, opts.remoteId));
|
|
22
|
+
const state = await loadSyncState(opts.stateDir, opts.fsx, opts.msg);
|
|
23
|
+
state.lastSnapshotId = opts.remoteId;
|
|
24
|
+
if (ancestorKnown)
|
|
25
|
+
state.ancestorId = opts.remoteId;
|
|
26
|
+
for (const [sid, hash] of Object.entries(meta.sections)) {
|
|
27
|
+
if (typeof hash !== 'string' || hash === '')
|
|
28
|
+
continue;
|
|
29
|
+
state.sections[sid] = { hash, updatedAt: meta.createdAt };
|
|
30
|
+
}
|
|
31
|
+
state.transport = opts.transport;
|
|
32
|
+
await saveSyncState(opts.stateDir, state, opts.fsx);
|
|
33
|
+
opts.warnings.push(opts.msg(ancestorKnown ? 'sync.pushBaselineAdopted' : 'sync.pushBaselineAdoptedNoAncestor', {
|
|
34
|
+
remote: opts.remoteId,
|
|
35
|
+
base: opts.base,
|
|
36
|
+
}));
|
|
37
|
+
return opts.remoteId;
|
|
38
|
+
}
|
|
39
|
+
//# sourceMappingURL=baseline-heal.js.map
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { SnapshotFs } from './fs.ts';
|
|
2
|
+
import type { RemoteSnapshotIndex } from './session-tombstones.ts';
|
|
3
|
+
import type { SyncTransport } from './transport.ts';
|
|
4
|
+
import type { MsgFunc } from '../core/messages.ts';
|
|
5
|
+
export interface PushBaseOptions {
|
|
6
|
+
stateDir: string;
|
|
7
|
+
fsx: SnapshotFs;
|
|
8
|
+
localSnapshotsDir?: string;
|
|
9
|
+
/** SYN-02:本轮已列过的远端 index(推进检测与墓碑继承共用同一份)。 */
|
|
10
|
+
index: RemoteSnapshotIndex;
|
|
11
|
+
transport: Pick<SyncTransport, 'type'> & {
|
|
12
|
+
ref: string;
|
|
13
|
+
};
|
|
14
|
+
hostname?: string;
|
|
15
|
+
msg: MsgFunc;
|
|
16
|
+
warnings: string[];
|
|
17
|
+
}
|
|
18
|
+
export type PushBaseOutcome = {
|
|
19
|
+
ok: true;
|
|
20
|
+
base: string;
|
|
21
|
+
adopted?: string;
|
|
22
|
+
} | {
|
|
23
|
+
ok: false;
|
|
24
|
+
message: string;
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* 判定本机能否继续推送,返回可用的基线。
|
|
28
|
+
*
|
|
29
|
+
* - 首次同步(没有基线)→ 放行;远端为空 → 放行(没有可比对的快照)。
|
|
30
|
+
* - 读不到远端列表 → **告警放行**(上传本身会再暴露通道问题),绝不把「读不到」当「没变」。
|
|
31
|
+
* - 远端最新快照就是当前基线 → 放行。
|
|
32
|
+
* - 远端最新快照是本机自己推的 → 收养为基线后放行(`adopted` 回传,调用方写进报告)。
|
|
33
|
+
* - 其余(别的设备的改动 / 没有 deviceId 的旧快照)→ 冲突拒绝,给 force 出口。
|
|
34
|
+
*/
|
|
35
|
+
export declare function resolvePushBase(opts: PushBaseOptions): Promise<PushBaseOutcome>;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* push 前置:远端是否已被别的设备推进,以及「是本机自己推的」时收养基线(0.4.1)。
|
|
3
|
+
*
|
|
4
|
+
* 为什么单独成模块:这段判据是「推不推得上去」的唯一闸门,逻辑上只有三条出口
|
|
5
|
+
* (放行 / 告警放行 / 冲突拒绝),却要在 push 里挤掉二十多行 —— 抽出来后
|
|
6
|
+
* `sync-engine.push` 只剩「问一次闸门,拿到基线或冲突文案」。
|
|
7
|
+
*
|
|
8
|
+
* 事故形态(0.3.0 真机):transport.upload 已成功、recordBaseline 未执行 ⇒ 远端最新快照
|
|
9
|
+
* 就是本机自己那份,而基线还停在旧 id ⇒ 之后每轮都被判「远端被别的设备推进」永久拒绝,
|
|
10
|
+
* 每 60 s 一条失败,用户只能手改 sync-state。判据见 baseline-heal.ts:只有 deviceId 对得上
|
|
11
|
+
* 本机才收养,别的设备(或没有 deviceId 的旧快照)一律照旧拒绝。
|
|
12
|
+
*/
|
|
13
|
+
import os from 'node:os';
|
|
14
|
+
import { adoptOwnRemoteHead } from './baseline-heal.js';
|
|
15
|
+
import { loadSyncState } from './sync-state.js';
|
|
16
|
+
/**
|
|
17
|
+
* 判定本机能否继续推送,返回可用的基线。
|
|
18
|
+
*
|
|
19
|
+
* - 首次同步(没有基线)→ 放行;远端为空 → 放行(没有可比对的快照)。
|
|
20
|
+
* - 读不到远端列表 → **告警放行**(上传本身会再暴露通道问题),绝不把「读不到」当「没变」。
|
|
21
|
+
* - 远端最新快照就是当前基线 → 放行。
|
|
22
|
+
* - 远端最新快照是本机自己推的 → 收养为基线后放行(`adopted` 回传,调用方写进报告)。
|
|
23
|
+
* - 其余(别的设备的改动 / 没有 deviceId 的旧快照)→ 冲突拒绝,给 force 出口。
|
|
24
|
+
*/
|
|
25
|
+
export async function resolvePushBase(opts) {
|
|
26
|
+
const state = await loadSyncState(opts.stateDir, opts.fsx, opts.msg);
|
|
27
|
+
const base = state.lastSnapshotId;
|
|
28
|
+
if (base === '')
|
|
29
|
+
return { ok: true, base };
|
|
30
|
+
if (opts.index.reason !== undefined) {
|
|
31
|
+
opts.warnings.push(opts.msg('sync.pushAdvanceCheckFailed', { reason: opts.index.reason }));
|
|
32
|
+
return { ok: true, base };
|
|
33
|
+
}
|
|
34
|
+
const metas = opts.index.metas;
|
|
35
|
+
if (metas.length === 0)
|
|
36
|
+
return { ok: true, base };
|
|
37
|
+
const latest = metas[metas.length - 1].id; // list 按 createdAt 升序 → 最新在末
|
|
38
|
+
if (latest === base)
|
|
39
|
+
return { ok: true, base };
|
|
40
|
+
const adopted = await adoptOwnRemoteHead({
|
|
41
|
+
stateDir: opts.stateDir,
|
|
42
|
+
fsx: opts.fsx,
|
|
43
|
+
localSnapshotsDir: opts.localSnapshotsDir,
|
|
44
|
+
metas,
|
|
45
|
+
remoteId: latest,
|
|
46
|
+
base,
|
|
47
|
+
transport: opts.transport,
|
|
48
|
+
hostname: opts.hostname ?? os.hostname(),
|
|
49
|
+
msg: opts.msg,
|
|
50
|
+
warnings: opts.warnings,
|
|
51
|
+
});
|
|
52
|
+
if (adopted === null) {
|
|
53
|
+
// 无法安全断言「远端没变」时的保守拒绝:不 upload、不记基线、不改 sync-state。
|
|
54
|
+
return { ok: false, message: opts.msg('sync.pushRemoteAdvanced', { remote: latest, base }) };
|
|
55
|
+
}
|
|
56
|
+
return { ok: true, base: adopted, adopted };
|
|
57
|
+
}
|
|
58
|
+
//# sourceMappingURL=push-precheck.js.map
|
|
@@ -138,6 +138,15 @@ export interface SyncPushReport {
|
|
|
138
138
|
* 而不是记成「同步失败」。
|
|
139
139
|
*/
|
|
140
140
|
conflict?: boolean;
|
|
141
|
+
/**
|
|
142
|
+
* 本次推送前**收养了本机自己推上去的远端最新快照**(0.4.1 自愈):该值 = 被收养的快照 id。
|
|
143
|
+
*
|
|
144
|
+
* 触发场景:上次推送在上传成功、写基线之前被打断(进程退出/崩溃/断电),远端已前进而本机
|
|
145
|
+
* `lastSnapshotId` 仍是上一版 → 前置检测会永久拒绝推送(每次都说「远端被别人推进了」),
|
|
146
|
+
* 单设备用户因此被自己的快照锁死。判据只看「远端最新快照的 manifest.deviceId == 本机
|
|
147
|
+
* deviceId」,别的设备推进过就仍然按冲突返回,绝不越过。
|
|
148
|
+
*/
|
|
149
|
+
adoptedBase?: string;
|
|
141
150
|
}
|
|
142
151
|
/** 差异报告中的单个变更项(PlanItem 摘要,不含敏感细节) */
|
|
143
152
|
export interface PullChange {
|
|
@@ -516,18 +525,6 @@ export declare class SyncEngine {
|
|
|
516
525
|
private pruneRemoteSnapshots;
|
|
517
526
|
/** 读取远端保留策略;提供者缺失/抛错 → 缺省策略(保守多留,绝不因读取失败误删)。 */
|
|
518
527
|
private resolveRetentionPolicy;
|
|
519
|
-
/**
|
|
520
|
-
* push 前置:远端是否已被别的设备推进(防「推上去把别人的改动架空」)。
|
|
521
|
-
*
|
|
522
|
-
* 判据与 hasNewRemoteSnapshot() 同源但方向相反:
|
|
523
|
-
* - 首次同步(lastSnapshotId === '')→ **不拦**(本机没有基线可丢,第一次推送就是建立基线);
|
|
524
|
-
* - 远端为空 → 不拦(没有可比对的快照);
|
|
525
|
-
* - 其余:远端最新快照 id !== lastSnapshotId ⇒ 远端被推进(或本机基线已被裁剪)→ 拦。
|
|
526
|
-
* 两种情况都**无法安全断言「远端没变」**,保守拒绝并给出 force 出口。
|
|
527
|
-
* - list() 抛错 → 返回 reason(调用方按原样继续并告警),绝不把「读不到」当成「没变」。
|
|
528
|
-
* - SYN-02:index 可由 push() 传入(同一轮只列一次远端),缺省自己 list(其它调用点行为不变)。
|
|
529
|
-
*/
|
|
530
|
-
private remoteAdvancedCheck;
|
|
531
528
|
/**
|
|
532
529
|
* pull:拉取远端最新(或指定)快照 → 过滤 portable 分区 → 转临时标准 ZIP →
|
|
533
530
|
* 复用 Importer 预览流程(analyzeImport/createImportPlan)产出差异报告。
|
package/lib/sync/sync-engine.js
CHANGED
|
@@ -33,6 +33,7 @@ import { stringifyJsonSafe } from '../utils/json.js';
|
|
|
33
33
|
import { writeZip } from '../utils/zip.js';
|
|
34
34
|
import { createSnapshotFs, joinFs } from './fs.js';
|
|
35
35
|
import { writeSnapshotToDir } from './layout.js';
|
|
36
|
+
import { resolvePushBase } from './push-precheck.js';
|
|
36
37
|
import { credentialsMapFromYaml, decryptCredentialsPayload, decryptSectionsPayload, encryptCredentialsPayload, encryptSectionsPayload, } from './snapshot-crypto.js';
|
|
37
38
|
import { OPT_IN_SYNC_SECTIONS } from './sync-selection.js';
|
|
38
39
|
import { listRemoteSnapshotIndex, planSessionBookkeeping, remoteTombstonesOf, stripTombstonedSessionsInPlace, } from './session-tombstones.js';
|
|
@@ -64,6 +65,8 @@ const zh = {
|
|
|
64
65
|
'sync.applyMergeResolutionsNoImporter': 'applyMergeResolutions: SyncEngine 缺少 importer(需在 options 中注入)',
|
|
65
66
|
'sync.mergePendingConflicts': '仍有 {count} 个分区未裁决({sections}):已裁决的部分已写入本机,但基线不推进,冲突下一轮会重新出现',
|
|
66
67
|
'sync.baselineRexportFailed': '写回成功但重新导出本机分区失败({sections}):无法证明基线与本机一致,本次**不记基线**(远端指针保持原值,下一轮重新合并收敛)',
|
|
68
|
+
'sync.pushBaselineAdopted': '远端最新快照 {remote} 是本机上次推送的(本机基线停在 {base},上次推送在记录基线前被打断):已把它收养为基线并继续本次推送',
|
|
69
|
+
'sync.pushBaselineAdoptedNoAncestor': '远端最新快照 {remote} 是本机上次推送的,但本机没有它的本地祖先副本:已收养基线(下次合并退化为两方合并,结果仍安全)',
|
|
67
70
|
};
|
|
68
71
|
const en = {
|
|
69
72
|
'sync.pushRemoteAdvanced': 'The newest remote snapshot {remote} differs from the local baseline {base}: this push did not run (nothing written remotely, baseline untouched). Sync the remote changes first, or explicitly force the push if this machine should overwrite the remote.',
|
|
@@ -72,6 +75,8 @@ const en = {
|
|
|
72
75
|
'sync.applyMergeResolutionsNoImporter': 'applyMergeResolutions: SyncEngine is missing the importer (must be injected via options)',
|
|
73
76
|
'sync.mergePendingConflicts': '{count} section(s) still have no decision ({sections}): the decided parts were written locally, but the baseline is not advanced, so the conflicts will reappear next round',
|
|
74
77
|
'sync.baselineRexportFailed': 'The write succeeded but re-exporting the local section(s) failed ({sections}): the baseline cannot be proven to match this machine, so no baseline was recorded (the remote pointer keeps its old value and the next merge converges again)',
|
|
78
|
+
'sync.pushBaselineAdopted': 'The newest remote snapshot {remote} was pushed by this device (its baseline stopped at {base}: that push was interrupted before recording the baseline): the baseline has been adopted and this push continues',
|
|
79
|
+
'sync.pushBaselineAdoptedNoAncestor': 'The newest remote snapshot {remote} was pushed by this device, but no local ancestor copy exists for it: the baseline has been adopted (the next merge degrades to a two-way merge, which is still safe)',
|
|
75
80
|
};
|
|
76
81
|
registerMessageCatalog({ id: 'sync-engine-merge', zh, en });
|
|
77
82
|
/** plan 的单个分区结果 → 预览视图(三侧都只回传可读文本,绝不回传原始值)。 */
|
|
@@ -478,6 +483,8 @@ export class SyncEngine {
|
|
|
478
483
|
*/
|
|
479
484
|
async push(opts = {}) {
|
|
480
485
|
const warnings = [];
|
|
486
|
+
/** 0.4.1:本次推送前收养的「本机自己推的」远端快照(非空 ⇒ 上次推送被打断过,已在报告里如实回传) */
|
|
487
|
+
let adopted;
|
|
481
488
|
const includeSecrets = opts.includeSecrets ?? false;
|
|
482
489
|
const encrypt = opts.encrypt ?? false;
|
|
483
490
|
// 安全不变量:导出密钥必须加密;加密必须给密码(密码绝不落盘)
|
|
@@ -490,24 +497,17 @@ export class SyncEngine {
|
|
|
490
497
|
// SYN-02:本轮只列一次远端 index(推进检测 + 继承会话删除墓碑共用;墓碑累积在最新快照里)
|
|
491
498
|
const remoteIndex = await listRemoteSnapshotIndex(this.transport);
|
|
492
499
|
const remoteTombstones = remoteIndex.reason === undefined ? remoteTombstonesOf(remoteIndex.metas) : [];
|
|
493
|
-
//
|
|
494
|
-
//
|
|
500
|
+
// 远端推进检测(判据与 0.4.1 自愈收养全在 push-precheck.ts);冲突时**不抛错**、
|
|
501
|
+
// 不 upload、不记基线、不改 sync-state,只把文案回给调用方走 force 出口。
|
|
495
502
|
if (opts.force !== true) {
|
|
496
|
-
const
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
}
|
|
501
|
-
|
|
502
|
-
return {
|
|
503
|
-
|
|
504
|
-
snapshotId: '',
|
|
505
|
-
sections: [],
|
|
506
|
-
warnings,
|
|
507
|
-
conflict: true,
|
|
508
|
-
message: this.msg('sync.pushRemoteAdvanced', { remote: check.latest, base: check.base }),
|
|
509
|
-
};
|
|
510
|
-
}
|
|
503
|
+
const pre = await resolvePushBase({
|
|
504
|
+
stateDir: this.stateDir, fsx: this.fsx, localSnapshotsDir: this.localSnapshotsDir,
|
|
505
|
+
index: remoteIndex, transport: { type: this.transport.type, ref: this.transportRef },
|
|
506
|
+
msg: this.msg, warnings,
|
|
507
|
+
});
|
|
508
|
+
if (!pre.ok)
|
|
509
|
+
return { ok: false, snapshotId: '', sections: [], warnings, conflict: true, message: pre.message };
|
|
510
|
+
adopted = pre.adopted;
|
|
511
511
|
}
|
|
512
512
|
const plainSections = {};
|
|
513
513
|
const targets = this.pushTargets(opts.sections, warnings);
|
|
@@ -607,7 +607,13 @@ export class SyncEngine {
|
|
|
607
607
|
? { sessionUnits: bookkeeping.sessionUnits, deletedSessions: bookkeeping.tombstones }
|
|
608
608
|
: {}),
|
|
609
609
|
});
|
|
610
|
-
return {
|
|
610
|
+
return {
|
|
611
|
+
ok: true,
|
|
612
|
+
snapshotId: id,
|
|
613
|
+
sections: Object.keys(plainSections),
|
|
614
|
+
warnings,
|
|
615
|
+
...(adopted !== undefined ? { adoptedBase: adopted } : {}),
|
|
616
|
+
};
|
|
611
617
|
}
|
|
612
618
|
/**
|
|
613
619
|
* P0-②:push 前只读预览「将推送什么」—— 零写入、零远端变更:
|
|
@@ -806,31 +812,6 @@ export class SyncEngine {
|
|
|
806
812
|
return DEFAULT_RETENTION_POLICY;
|
|
807
813
|
}
|
|
808
814
|
}
|
|
809
|
-
/**
|
|
810
|
-
* push 前置:远端是否已被别的设备推进(防「推上去把别人的改动架空」)。
|
|
811
|
-
*
|
|
812
|
-
* 判据与 hasNewRemoteSnapshot() 同源但方向相反:
|
|
813
|
-
* - 首次同步(lastSnapshotId === '')→ **不拦**(本机没有基线可丢,第一次推送就是建立基线);
|
|
814
|
-
* - 远端为空 → 不拦(没有可比对的快照);
|
|
815
|
-
* - 其余:远端最新快照 id !== lastSnapshotId ⇒ 远端被推进(或本机基线已被裁剪)→ 拦。
|
|
816
|
-
* 两种情况都**无法安全断言「远端没变」**,保守拒绝并给出 force 出口。
|
|
817
|
-
* - list() 抛错 → 返回 reason(调用方按原样继续并告警),绝不把「读不到」当成「没变」。
|
|
818
|
-
* - SYN-02:index 可由 push() 传入(同一轮只列一次远端),缺省自己 list(其它调用点行为不变)。
|
|
819
|
-
*/
|
|
820
|
-
async remoteAdvancedCheck(index) {
|
|
821
|
-
const state = await loadSyncState(this.stateDir, this.fsx, this.msg);
|
|
822
|
-
const base = state.lastSnapshotId;
|
|
823
|
-
if (base === '')
|
|
824
|
-
return { blocked: false, base, latest: '' };
|
|
825
|
-
const listed = index ?? await listRemoteSnapshotIndex(this.transport);
|
|
826
|
-
if (listed.reason !== undefined)
|
|
827
|
-
return { blocked: false, base, latest: '', reason: listed.reason };
|
|
828
|
-
const metas = listed.metas;
|
|
829
|
-
if (metas.length === 0)
|
|
830
|
-
return { blocked: false, base, latest: '' };
|
|
831
|
-
const latest = metas[metas.length - 1].id; // list 按 createdAt 升序 → 最新在末
|
|
832
|
-
return { blocked: latest !== base, base, latest };
|
|
833
|
-
}
|
|
834
815
|
/**
|
|
835
816
|
* pull:拉取远端最新(或指定)快照 → 过滤 portable 分区 → 转临时标准 ZIP →
|
|
836
817
|
* 复用 Importer 预览流程(analyzeImport/createImportPlan)产出差异报告。
|
package/lib/sync/ui-prefs.d.ts
CHANGED
|
@@ -41,6 +41,14 @@ export interface UiPrefs {
|
|
|
41
41
|
* 台账 / 回退路由本身仍可用:已有回滚点仍能查看、回退、删除、清理 —— 关的是「自动留点」。
|
|
42
42
|
*/
|
|
43
43
|
rollbackEnabled?: boolean;
|
|
44
|
+
/**
|
|
45
|
+
* 迁移历史自动清理的保留上限(条)。
|
|
46
|
+
*
|
|
47
|
+
* 语义:缺省 = 1000(core 的 DEFAULT_MIGRATION_RETENTION);0 = 不限制(只增不减,老行为);
|
|
48
|
+
* 非法值一律回落缺省。宿主每次写入历史后按本值节流清理最旧条目,
|
|
49
|
+
* 用户可在「迁移历史」面板改(GET/POST /history/retention)。
|
|
50
|
+
*/
|
|
51
|
+
historyRetentionMaxEntries?: number;
|
|
44
52
|
}
|
|
45
53
|
/** 缺省配置(首次无文件 / 损坏 / 不支持 schema 时回退) */
|
|
46
54
|
export declare function defaultUiPrefs(): UiPrefs;
|
package/lib/sync/ui-prefs.js
CHANGED
|
@@ -25,6 +25,7 @@ import fsSync from 'node:fs';
|
|
|
25
25
|
import path from 'node:path';
|
|
26
26
|
import { parseJsonSafe, stringifyJsonSafe } from '../utils/json.js';
|
|
27
27
|
import { atomicWriteFile } from '../utils/atomic-write.js';
|
|
28
|
+
import { isValidHistoryRetention } from '../core/migration-history.js';
|
|
28
29
|
import { parseSyncChannel } from './sync-config.js';
|
|
29
30
|
export const UI_PREFS_FILE = 'ui-prefs.json';
|
|
30
31
|
export const UI_PREFS_SCHEMA_VERSION = 1;
|
|
@@ -89,6 +90,10 @@ export async function readUiPrefs(dir) {
|
|
|
89
90
|
if (obj['rollbackEnabled'] === true) {
|
|
90
91
|
prefs.rollbackEnabled = true;
|
|
91
92
|
}
|
|
93
|
+
// 保留上限只认 0..100000 的整数(与路由校验同一口径);字符串/小数/越界一律丢,回落缺省
|
|
94
|
+
if (isValidHistoryRetention(obj['historyRetentionMaxEntries'])) {
|
|
95
|
+
prefs.historyRetentionMaxEntries = obj['historyRetentionMaxEntries'];
|
|
96
|
+
}
|
|
92
97
|
return prefs;
|
|
93
98
|
}
|
|
94
99
|
/**
|
|
@@ -126,6 +131,9 @@ export async function writeUiPrefs(dir, prefs) {
|
|
|
126
131
|
...(prefs.releaseNotesDismissed === true ? { releaseNotesDismissed: true } : {}),
|
|
127
132
|
...(prefs.sessionFormatDisposition !== undefined ? { sessionFormatDisposition: prefs.sessionFormatDisposition } : {}),
|
|
128
133
|
...(prefs.rollbackEnabled === true ? { rollbackEnabled: true } : {}),
|
|
134
|
+
...(isValidHistoryRetention(prefs.historyRetentionMaxEntries)
|
|
135
|
+
? { historyRetentionMaxEntries: prefs.historyRetentionMaxEntries }
|
|
136
|
+
: {}),
|
|
129
137
|
};
|
|
130
138
|
const target = path.join(dir, UI_PREFS_FILE);
|
|
131
139
|
const data = stringifyJsonSafe(payload, { space: 2 });
|
package/lib/ui/history-model.js
CHANGED
|
@@ -4,7 +4,8 @@ export function resultBadgeKind(result) {
|
|
|
4
4
|
return 'ok';
|
|
5
5
|
if (result === 'failed')
|
|
6
6
|
return 'error';
|
|
7
|
-
|
|
7
|
+
// pending(0.4.1)= 跑完了但还有待裁决项:绝不当成失败(红),也不是跳过 —— 用琥珀告警色
|
|
8
|
+
return 'warn'; // skipped / pending
|
|
8
9
|
}
|
|
9
10
|
export function kindLabelKey(kind) {
|
|
10
11
|
return `history.kind.${kind}`;
|
|
@@ -17,7 +18,7 @@ export const HISTORY_KIND_OPTIONS = [
|
|
|
17
18
|
'backup', 'backup-manual', 'snapshot-delete', 'snapshot-prune',
|
|
18
19
|
];
|
|
19
20
|
/** 结果过滤选项。 */
|
|
20
|
-
export const HISTORY_RESULT_OPTIONS = ['success', '
|
|
21
|
+
export const HISTORY_RESULT_OPTIONS = ['success', 'pending', 'skipped', 'failed'];
|
|
21
22
|
/** 把 UI 过滤模型转为后端 query 参数(kind/recent 转 kinds/recent 语义)。 */
|
|
22
23
|
export function filterToQuery(f) {
|
|
23
24
|
const q = {};
|
|
@@ -40,7 +40,7 @@ export interface OverviewSyncLite {
|
|
|
40
40
|
export interface OverviewHistoryLite {
|
|
41
41
|
at: string;
|
|
42
42
|
kind: string;
|
|
43
|
-
result: 'success' | 'failed' | 'skipped';
|
|
43
|
+
result: 'success' | 'failed' | 'skipped' | 'pending';
|
|
44
44
|
summary: string;
|
|
45
45
|
}
|
|
46
46
|
/** Overview 数据输入(null = 未加载/加载失败;组件逐项就绪逐项传入)。 */
|
|
@@ -124,8 +124,8 @@ export declare function overviewHealth(inputs: OverviewInputs): OverviewHealth;
|
|
|
124
124
|
export declare function overviewKindKey(kind: string): string;
|
|
125
125
|
export interface OverviewActivityItem {
|
|
126
126
|
at: string;
|
|
127
|
-
/** 徽章语义(success→ok / failed→error / skipped→warn,与 history-model 同判定)。 */
|
|
128
|
-
badge: 'ok' | 'error' | 'warn';
|
|
127
|
+
/** 徽章语义(success→ok / failed→error / skipped→warn / pending→pending,与 history-model 同判定)。 */
|
|
128
|
+
badge: 'ok' | 'error' | 'warn' | 'pending';
|
|
129
129
|
/** UI 渲染 key(`overview.kind.<kind>`;未知 kind 归一为 other → `overview.kind.other`)。 */
|
|
130
130
|
kindKey: string;
|
|
131
131
|
/** 原始摘要(上层渲染前 redact())。 */
|
package/lib/ui/overview-view.js
CHANGED
|
@@ -199,7 +199,15 @@ export function overviewActivity(history, limit = 5) {
|
|
|
199
199
|
});
|
|
200
200
|
return sorted.slice(0, limit).map((e) => ({
|
|
201
201
|
at: e.at,
|
|
202
|
-
badge: e.result === 'success'
|
|
202
|
+
badge: e.result === 'success'
|
|
203
|
+
? 'ok'
|
|
204
|
+
: e.result === 'failed'
|
|
205
|
+
? 'error'
|
|
206
|
+
// pending:跑完了但仍有待裁决项(自动同步下行冲突未裁决)—— 首页必须说「待裁决」,
|
|
207
|
+
// 既不能红成「失败」,也不该混进「跳过」(那一轮确有上传/应用发生)
|
|
208
|
+
: e.result === 'pending'
|
|
209
|
+
? 'pending'
|
|
210
|
+
: 'warn',
|
|
203
211
|
kindKey: overviewKindKey(e.kind),
|
|
204
212
|
summary: e.summary,
|
|
205
213
|
}));
|