dsh-config-manager 0.4.3 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +10 -0
- package/README.zh-CN.md +10 -0
- package/lib/adapters/mcp.d.ts +9 -0
- package/lib/adapters/mcp.js +37 -0
- package/lib/adapters/plugins.js +10 -2
- package/lib/adapters/pnpm-workspace.js +1 -1
- package/lib/adapters/self.d.ts +2 -0
- package/lib/adapters/self.js +18 -2
- package/lib/adapters/workspaces.js +1 -1
- package/lib/cli/restore-resume.js +1 -1
- package/lib/cli/web/page.js +2 -2
- package/lib/client.d.ts +14 -41
- package/lib/client.js +794 -716
- package/lib/core/backup.d.ts +11 -0
- package/lib/core/backup.js +27 -0
- package/lib/core/env-lock-lifecycle.d.ts +17 -3
- package/lib/core/env-lock-lifecycle.js +38 -0
- package/lib/core/external-failure.d.ts +9 -0
- package/lib/core/external-failure.js +50 -0
- package/lib/core/local-plugin-host.d.ts +9 -7
- package/lib/core/local-plugin-host.js +109 -15
- package/lib/core/local-plugin-pack.d.ts +20 -0
- package/lib/core/local-plugin-pack.js +18 -3
- package/lib/core/mcp-connector-store.d.ts +13 -0
- package/lib/core/mcp-connector-store.js +16 -1
- package/lib/core/messages-core.d.ts +45 -0
- package/lib/core/messages-core.js +92 -0
- package/lib/core/messages.d.ts +1 -0
- package/lib/core/messages.js +6 -0
- package/lib/core/model-tool-plans.d.ts +66 -0
- package/lib/core/model-tool-plans.js +128 -0
- package/lib/core/model-tools.d.ts +96 -8
- package/lib/core/model-tools.js +568 -31
- package/lib/core/phase3-host.js +10 -2
- package/lib/core/plugin-data-registry.d.ts +1 -1
- package/lib/core/plugin-data-registry.js +1 -1
- package/lib/core/restore-plan-fingerprint.d.ts +2 -0
- package/lib/core/restore-plan-fingerprint.js +18 -0
- package/lib/core/restore-resume.d.ts +1 -1
- package/lib/core/restore-resume.js +1 -1
- package/lib/core/restore.d.ts +5 -0
- package/lib/core/restore.js +4 -1
- package/lib/core/types.d.ts +12 -0
- package/lib/foreign/claude-sessions.d.ts +1 -1
- package/lib/foreign/claude-sessions.js +1 -1
- package/lib/foreign/registry.js +1 -1
- package/lib/foreign/types.d.ts +1 -1
- package/lib/index.d.ts +15 -15
- package/lib/index.js +60 -67
- package/lib/market/git-file-writer.js +1 -1
- package/lib/market/github-repos.js +1 -1
- package/lib/market/market-config.js +1 -1
- package/lib/market/messages-market.js +1 -1
- package/lib/market/my-repo.js +1 -1
- package/lib/market/prepare.js +1 -1
- package/lib/market/reader.js +2 -2
- package/lib/market/repo-url.d.ts +1 -1
- package/lib/market/security.js +2 -2
- package/lib/market/star-cache.d.ts +1 -1
- package/lib/market/types.d.ts +1 -1
- package/lib/market/types.js +1 -1
- package/lib/market/url.js +1 -1
- package/lib/routes/backup.js +17 -9
- package/lib/routes/index.d.ts +1 -1
- package/lib/routes/kit.d.ts +2 -2
- package/lib/routes/market.d.ts +1 -1
- package/lib/routes/market.js +3 -60
- package/lib/routes/model-tools-deps.d.ts +41 -0
- package/lib/routes/model-tools-deps.js +18 -0
- package/lib/routes/recovery.js +5 -3
- package/lib/routes/route-support.d.ts +18 -26
- package/lib/routes/route-support.js +19 -32
- package/lib/routes/snapshots.d.ts +1 -1
- package/lib/routes/snapshots.js +4 -40
- package/lib/routes/sync.js +40 -28
- package/lib/schema/index.d.ts +2 -2
- package/lib/schema/index.js +2 -2
- package/lib/schema/section-registry.d.ts +5 -3
- package/lib/schema/section-registry.js +7 -3
- package/lib/security/secret-scanner.js +1 -1
- package/lib/sync/apply-bundle.d.ts +50 -0
- package/lib/sync/apply-bundle.js +60 -0
- package/lib/sync/autosync-scheduler.d.ts +9 -0
- package/lib/sync/autosync-scheduler.js +118 -89
- package/lib/sync/backup-scheduler.js +5 -4
- package/lib/sync/blob-store.d.ts +2 -2
- package/lib/sync/git/git-transport.d.ts +12 -0
- package/lib/sync/git/git-transport.js +50 -2
- package/lib/sync/merge.d.ts +2 -0
- package/lib/sync/merge.js +28 -0
- package/lib/sync/messages.d.ts +4 -0
- package/lib/sync/messages.js +9 -2
- package/lib/sync/s3/s3-transport.d.ts +1 -1
- package/lib/sync/s3/s3-transport.js +1 -1
- package/lib/sync/sync-engine.d.ts +4 -4
- package/lib/sync/sync-engine.js +25 -26
- package/lib/sync/sync-scope-boot.d.ts +34 -0
- package/lib/sync/sync-scope-boot.js +71 -0
- package/lib/sync/sync-scope.d.ts +103 -0
- package/lib/sync/sync-scope.js +229 -0
- package/lib/sync/sync-selection.d.ts +17 -4
- package/lib/sync/sync-selection.js +40 -14
- package/lib/sync/transport.d.ts +4 -1
- package/lib/sync/transport.js +6 -0
- package/lib/sync/webdav/webdav-transport.js +1 -1
- package/lib/sync/workspace-merge.d.ts +36 -0
- package/lib/sync/workspace-merge.js +152 -0
- package/lib/ui/backup-schedule.d.ts +13 -2
- package/lib/ui/backup-schedule.js +3 -0
- package/lib/ui/snapshots-view.d.ts +16 -0
- package/lib/ui/snapshots-view.js +21 -0
- package/lib/utils/env-lock.d.ts +96 -0
- package/lib/utils/env-lock.js +332 -111
- package/lib/utils/messages-utils.d.ts +6 -0
- package/lib/utils/messages-utils.js +17 -1
- package/lib/utils/patch-yaml.js +1 -1
- package/lib/utils/zip.js +1 -1
- package/package.json +3 -2
- package/src/adapters/mcp.test.ts +28 -0
- package/src/adapters/mcp.ts +33 -0
- package/src/adapters/plugins.test.ts +49 -0
- package/src/adapters/plugins.ts +9 -1
- package/src/adapters/pnpm-workspace.ts +1 -1
- package/src/adapters/self.test.ts +39 -1
- package/src/adapters/self.ts +20 -2
- package/src/adapters/workspaces.ts +1 -1
- package/src/cli/restore-resume.ts +1 -1
- package/src/cli/web/page.ts +2 -2
- package/src/client/about/AboutPanel.tsx +1 -1
- package/src/client/about/about-view.test.ts +1 -1
- package/src/client/about/about-view.ts +1 -1
- package/src/client/api.ts +1 -6
- package/src/client/chat/chat-entry-view.test.ts +1 -1
- package/src/client/chat/chat-slots.ts +1 -1
- package/src/client/chat/rollback-diff-tab.ts +1 -1
- package/src/client/client-types.ts +1 -1
- package/src/client/common/routes.ts +1 -5
- package/src/client/css-scale-guard.test.ts +1 -1
- package/src/client/home/HomePanel.tsx +3 -0
- package/src/client/library/ArtifactRow.tsx +14 -2
- package/src/client/library/LibraryPanel.tsx +44 -0
- package/src/client/locales/overview.ts +10 -2
- package/src/client/locales/sessions.ts +3 -0
- package/src/client/market/MyConfigsView.tsx +1 -1
- package/src/client/market/market-api.ts +2 -14
- package/src/client/market/market-locales.ts +1 -1
- package/src/client/market/market-view.ts +3 -3
- package/src/client/market/my-configs-api.ts +1 -1
- package/src/client/market/my-configs-view.ts +1 -1
- package/src/client/recovery/recovery-locales.test.ts +1 -1
- package/src/client/run-store.ts +1 -1
- package/src/client/sync/SyncSectionPickerDialog.tsx +0 -5
- package/src/client/sync/history-model.test.ts +28 -7
- package/src/client/sync/history-model.ts +6 -3
- package/src/client/sync/sync-locales.ts +10 -4
- package/src/client/sync/sync-view.ts +1 -1
- package/src/core/analyzer-cache.test.ts +1 -1
- package/src/core/backup.test.ts +45 -1
- package/src/core/backup.ts +25 -0
- package/src/core/disk-usage.test.ts +2 -0
- package/src/core/env-lock-lifecycle.ts +33 -3
- package/src/core/external-failure.test.ts +60 -0
- package/src/core/external-failure.ts +54 -0
- package/src/core/integrity-extra-entries.test.ts +1 -1
- package/src/core/local-plugin-host.test.ts +134 -0
- package/src/core/local-plugin-host.ts +122 -17
- package/src/core/local-plugin-pack.ts +39 -3
- package/src/core/mcp-connector-store.ts +26 -1
- package/src/core/messages-core.ts +94 -0
- package/src/core/messages.ts +6 -0
- package/src/core/model-tool-plans.test.ts +111 -0
- package/src/core/model-tool-plans.ts +170 -0
- package/src/core/model-tools.test.ts +212 -12
- package/src/core/model-tools.ts +710 -38
- package/src/core/phase3-host.ts +10 -2
- package/src/core/phase3-production-integration.test.ts +43 -0
- package/src/core/plugin-data-registry.ts +1 -1
- package/src/core/restore-plan-fingerprint.ts +19 -0
- package/src/core/restore-resume.ts +1 -1
- package/src/core/restore.ts +9 -1
- package/src/core/types.ts +12 -0
- package/src/foreign/claude-sessions.ts +3 -3
- package/src/foreign/registry.ts +1 -1
- package/src/foreign/types.ts +1 -1
- package/src/index.ts +91 -98
- package/src/market/git-file-writer.ts +1 -1
- package/src/market/github-repos.test.ts +1 -1
- package/src/market/github-repos.ts +1 -1
- package/src/market/market-config.ts +1 -1
- package/src/market/messages-market.ts +1 -1
- package/src/market/my-repo.test.ts +1 -1
- package/src/market/my-repo.ts +1 -1
- package/src/market/prepare.test.ts +1 -1
- package/src/market/prepare.ts +1 -1
- package/src/market/reader.ts +2 -2
- package/src/market/repo-url.ts +1 -1
- package/src/market/security.ts +2 -2
- package/src/market/star-cache.ts +1 -1
- package/src/market/types.ts +1 -1
- package/src/market/url.test.ts +1 -1
- package/src/market/url.ts +1 -1
- package/src/profiles/dsh-profile-copy-rollback.test.ts +1 -1
- package/src/routes/backup.ts +16 -9
- package/src/routes/index.ts +1 -1
- package/src/routes/kit.ts +2 -2
- package/src/routes/market.ts +2 -59
- package/src/routes/model-tools-deps.ts +56 -0
- package/src/routes/recovery.ts +5 -3
- package/src/routes/route-support.ts +49 -36
- package/src/routes/snapshots.ts +4 -40
- package/src/routes/sync.ts +39 -27
- package/src/schema/index.ts +2 -2
- package/src/schema/manifest-schema.test.ts +2 -2
- package/src/schema/registry.test.ts +1 -1
- package/src/schema/section-registry.ts +9 -4
- package/src/security/redaction.test.ts +1 -1
- package/src/security/secret-scanner.test.ts +2 -2
- package/src/security/secret-scanner.ts +1 -1
- package/src/sync/apply-bundle.ts +104 -0
- package/src/sync/autosync-scheduler.test.ts +180 -6
- package/src/sync/autosync-scheduler.ts +132 -92
- package/src/sync/backup-scheduler.test.ts +11 -4
- package/src/sync/backup-scheduler.ts +5 -4
- package/src/sync/blob-store.ts +2 -2
- package/src/sync/git/git-transport.test.ts +62 -0
- package/src/sync/git/git-transport.ts +54 -3
- package/src/sync/merge.ts +29 -0
- package/src/sync/messages.ts +9 -2
- package/src/sync/s3/s3-transport.ts +1 -1
- package/src/sync/sync-engine.test.ts +238 -2
- package/src/sync/sync-engine.ts +25 -26
- package/src/sync/sync-preview-push.test.ts +2 -1
- package/src/sync/sync-scope-boot.ts +87 -0
- package/src/sync/sync-scope.test.ts +154 -0
- package/src/sync/sync-scope.ts +256 -0
- package/src/sync/sync-selection.test.ts +76 -2
- package/src/sync/sync-selection.ts +40 -13
- package/src/sync/transport.test.ts +21 -1
- package/src/sync/transport.ts +12 -0
- package/src/sync/webdav/webdav-delete-index-unreadable.test.ts +2 -2
- package/src/sync/webdav/webdav-transport.ts +1 -1
- package/src/sync/workspace-merge.test.ts +110 -0
- package/src/sync/workspace-merge.ts +180 -0
- package/src/ui/backup-schedule.test.ts +5 -0
- package/src/ui/backup-schedule.ts +21 -2
- package/src/ui/session-issue-labels.ts +1 -1
- package/src/ui/snapshots-view.test.ts +32 -0
- package/src/ui/snapshots-view.ts +34 -0
- package/src/utils/env-lock.test.ts +242 -9
- package/src/utils/env-lock.ts +247 -13
- package/src/utils/messages-utils.ts +17 -1
- package/src/utils/patch-yaml.ts +1 -1
- package/src/utils/zip.ts +1 -1
- package/src/client/CLIENT_DEPENDENCIES.md +0 -94
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
function isWorkspaces(data) {
|
|
2
|
+
if (data === null || typeof data !== 'object')
|
|
3
|
+
return false;
|
|
4
|
+
const obj = data;
|
|
5
|
+
return obj.version === 1 && Array.isArray(obj.workspaces);
|
|
6
|
+
}
|
|
7
|
+
function recordsById(list) {
|
|
8
|
+
const map = new Map();
|
|
9
|
+
for (const rec of list) {
|
|
10
|
+
if (rec !== null && typeof rec === 'object' && typeof rec.id === 'string')
|
|
11
|
+
map.set(rec.id, rec);
|
|
12
|
+
}
|
|
13
|
+
return map;
|
|
14
|
+
}
|
|
15
|
+
/** 深度判等(本分区只有标量与字符串数组,够用;不引入通用深比较的第二份实现)。 */
|
|
16
|
+
function sameValue(a, b) {
|
|
17
|
+
if (a === b)
|
|
18
|
+
return true;
|
|
19
|
+
if (Array.isArray(a) && Array.isArray(b)) {
|
|
20
|
+
if (a.length !== b.length)
|
|
21
|
+
return false;
|
|
22
|
+
for (let i = 0; i < a.length; i++)
|
|
23
|
+
if (!sameValue(a[i], b[i]))
|
|
24
|
+
return false;
|
|
25
|
+
return true;
|
|
26
|
+
}
|
|
27
|
+
if (a === null || b === null || typeof a !== 'object' || typeof b !== 'object')
|
|
28
|
+
return false;
|
|
29
|
+
const ao = a;
|
|
30
|
+
const bo = b;
|
|
31
|
+
const keys = new Set([...Object.keys(ao), ...Object.keys(bo)]);
|
|
32
|
+
for (const k of keys)
|
|
33
|
+
if (!sameValue(ao[k], bo[k]))
|
|
34
|
+
return false;
|
|
35
|
+
return true;
|
|
36
|
+
}
|
|
37
|
+
/** sessionIds 并集:本地在前、远端新增按原序追加,按裸 id 去重。 */
|
|
38
|
+
function unionSessionIds(local, remote) {
|
|
39
|
+
const out = [];
|
|
40
|
+
const seen = new Set();
|
|
41
|
+
for (const id of [...local, ...remote]) {
|
|
42
|
+
if (typeof id !== 'string')
|
|
43
|
+
continue;
|
|
44
|
+
const key = id.toLowerCase();
|
|
45
|
+
if (seen.has(key))
|
|
46
|
+
continue;
|
|
47
|
+
seen.add(key);
|
|
48
|
+
out.push(id);
|
|
49
|
+
}
|
|
50
|
+
return out;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* 单个记录合并:字段级三方取舍 + sessionIds 并集。
|
|
54
|
+
* @returns 合并后的记录与「相对本地改动的字段数」(供 autoMerged 计数)。
|
|
55
|
+
*/
|
|
56
|
+
function mergeRecord(id, local, remote, ancestor, conflicts) {
|
|
57
|
+
const out = {};
|
|
58
|
+
let changedFields = 0;
|
|
59
|
+
const keys = new Set([...Object.keys(local), ...Object.keys(remote)]);
|
|
60
|
+
for (const key of keys) {
|
|
61
|
+
const lv = local[key];
|
|
62
|
+
const rv = remote[key];
|
|
63
|
+
const av = ancestor === undefined ? undefined : ancestor[key];
|
|
64
|
+
let picked;
|
|
65
|
+
if (key === 'id') {
|
|
66
|
+
picked = id;
|
|
67
|
+
}
|
|
68
|
+
else if (key === 'sessionIds') {
|
|
69
|
+
const union = unionSessionIds(Array.isArray(lv) ? lv : [], Array.isArray(rv) ? rv : []);
|
|
70
|
+
if (!sameValue(union, lv))
|
|
71
|
+
changedFields += 1;
|
|
72
|
+
picked = union;
|
|
73
|
+
}
|
|
74
|
+
else if (sameValue(lv, rv)) {
|
|
75
|
+
picked = lv;
|
|
76
|
+
}
|
|
77
|
+
else if (ancestor !== undefined && sameValue(lv, av)) {
|
|
78
|
+
picked = rv; // 仅远端改了
|
|
79
|
+
changedFields += 1;
|
|
80
|
+
}
|
|
81
|
+
else if (ancestor !== undefined && sameValue(rv, av)) {
|
|
82
|
+
picked = lv; // 仅本地改了
|
|
83
|
+
}
|
|
84
|
+
else {
|
|
85
|
+
// 双侧都改(或无祖先,无从判断谁改)→ 冲突,保留本地值供用户对照,绝不静默取舍
|
|
86
|
+
conflicts.push({
|
|
87
|
+
path: 'workspaces.' + id + '.' + key,
|
|
88
|
+
kind: 'key',
|
|
89
|
+
reason: ancestor === undefined ? 'no-ancestor' : 'both-modified',
|
|
90
|
+
autoMergeAttempted: true,
|
|
91
|
+
local: lv,
|
|
92
|
+
remote: rv,
|
|
93
|
+
ancestor: av,
|
|
94
|
+
});
|
|
95
|
+
picked = lv;
|
|
96
|
+
}
|
|
97
|
+
if (picked !== undefined)
|
|
98
|
+
out[key] = picked;
|
|
99
|
+
}
|
|
100
|
+
return { rec: out, changedFields };
|
|
101
|
+
}
|
|
102
|
+
/** workspaces 分区记录级合并(`merge.ts` 的分区钩子)。 */
|
|
103
|
+
export const mergeWorkspacesSection = (local, remote, ancestor) => {
|
|
104
|
+
if (!isWorkspaces(local) || !isWorkspaces(remote))
|
|
105
|
+
return undefined;
|
|
106
|
+
const a = isWorkspaces(ancestor) ? ancestor : undefined;
|
|
107
|
+
const lMap = recordsById(local.workspaces);
|
|
108
|
+
const rMap = recordsById(remote.workspaces);
|
|
109
|
+
const aMap = a === undefined ? new Map() : recordsById(a.workspaces);
|
|
110
|
+
// 记录顺序:本地既有顺序(用户看得见的稳定顺序)→ 远端新增 → 仅祖先有(等删除判定)
|
|
111
|
+
const ids = [...lMap.keys()];
|
|
112
|
+
for (const id of rMap.keys())
|
|
113
|
+
if (!lMap.has(id))
|
|
114
|
+
ids.push(id);
|
|
115
|
+
for (const id of aMap.keys())
|
|
116
|
+
if (!lMap.has(id) && !rMap.has(id))
|
|
117
|
+
ids.push(id);
|
|
118
|
+
const conflicts = [];
|
|
119
|
+
const mergedRecords = [];
|
|
120
|
+
let mergePoints = 0;
|
|
121
|
+
for (const id of ids) {
|
|
122
|
+
const l = lMap.get(id);
|
|
123
|
+
const r = rMap.get(id);
|
|
124
|
+
const anc = aMap.get(id);
|
|
125
|
+
if (l !== undefined && r !== undefined) {
|
|
126
|
+
const { rec, changedFields } = mergeRecord(id, l, r, anc, conflicts);
|
|
127
|
+
mergedRecords.push(rec);
|
|
128
|
+
mergePoints += changedFields;
|
|
129
|
+
continue;
|
|
130
|
+
}
|
|
131
|
+
if (l !== undefined) {
|
|
132
|
+
if (anc !== undefined && sameValue(l, anc))
|
|
133
|
+
continue; // 远端删了、本地未改 → 跟随删除
|
|
134
|
+
if (anc === undefined) {
|
|
135
|
+
mergedRecords.push(l);
|
|
136
|
+
continue;
|
|
137
|
+
}
|
|
138
|
+
conflicts.push({ path: 'workspaces.' + id, kind: 'key', reason: 'modify-delete', autoMergeAttempted: false, local: l, remote: undefined, ancestor: anc });
|
|
139
|
+
mergedRecords.push(l);
|
|
140
|
+
continue;
|
|
141
|
+
}
|
|
142
|
+
if (r !== undefined) {
|
|
143
|
+
if (anc !== undefined && sameValue(r, anc))
|
|
144
|
+
continue; // 本地删了、远端未改 → 跟随删除
|
|
145
|
+
mergedRecords.push(r);
|
|
146
|
+
mergePoints += 1; // 远端新增(或本地已删、远端改过:保留远端记录并记并入)
|
|
147
|
+
continue;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
return { merged: { version: 1, workspaces: mergedRecords }, conflicts, mergePoints };
|
|
151
|
+
};
|
|
152
|
+
//# sourceMappingURL=workspace-merge.js.map
|
|
@@ -86,8 +86,19 @@ export declare function backupRunSummary(run: BackupRunResult): {
|
|
|
86
86
|
skipReason: string | null;
|
|
87
87
|
error: string | null;
|
|
88
88
|
};
|
|
89
|
-
/**
|
|
90
|
-
|
|
89
|
+
/**
|
|
90
|
+
* 宿主 BackupRunResult.skipReason 的结构化投影;未知 token 落 'other'(不静默当成功)。
|
|
91
|
+
*
|
|
92
|
+
* 锁相关四种分开:宿主按 lockSkipToken() 分档发 token(issue:locks 目录为空也说「锁被占用」)。
|
|
93
|
+
* 'locked' 只表示「真被另一项活任务持有」,残留锁与 SAFE MODE 各有自己的处置方向。
|
|
94
|
+
*/
|
|
95
|
+
export type BackupSkipReason = 'disabled' | 'running' | 'conflict' | 'locked'
|
|
96
|
+
/** 残留锁(含心跳降级):重试/重启都不会自愈,必须去事故恢复回收 */
|
|
97
|
+
| 'lock-stale'
|
|
98
|
+
/** 锁不可用(目录 IO/权限/未知状态):稍后重试 */
|
|
99
|
+
| 'lock-unavailable'
|
|
100
|
+
/** SAFE MODE 阻断写入:锁目录通常是空的,处置入口是事故恢复 */
|
|
101
|
+
| 'safe-mode' | 'other';
|
|
91
102
|
/** 立即备份结果 → 客户端提示通道(壳据 kind 选 toast,据 reason 选文案键)。 */
|
|
92
103
|
export type BackupRunOutcome = {
|
|
93
104
|
kind: 'ok';
|
|
@@ -128,6 +128,9 @@ export function backupRunOutcome(run) {
|
|
|
128
128
|
case 'running': return { kind: 'skipped', reason: 'running' };
|
|
129
129
|
case 'conflict': return { kind: 'skipped', reason: 'conflict' };
|
|
130
130
|
case 'mutation-locked': return { kind: 'skipped', reason: 'locked' };
|
|
131
|
+
case 'mutation-lock-stale': return { kind: 'skipped', reason: 'lock-stale' };
|
|
132
|
+
case 'mutation-lock-unavailable': return { kind: 'skipped', reason: 'lock-unavailable' };
|
|
133
|
+
case 'mutation-safe-mode': return { kind: 'skipped', reason: 'safe-mode' };
|
|
131
134
|
default: return { kind: 'skipped', reason: 'other' };
|
|
132
135
|
}
|
|
133
136
|
}
|
|
@@ -100,3 +100,19 @@ export declare function isUnreadableNote(note: string): boolean;
|
|
|
100
100
|
* 即执行按钮的可点判据:`disabled = running || !planHasExecutableActions(plan)`。
|
|
101
101
|
*/
|
|
102
102
|
export declare function planHasExecutableActions(plan: RestorePlan | null): boolean;
|
|
103
|
+
/** 取来源档案名:非空字符串(去首尾空白)才算「能证明的来源」;缺失/空 → undefined(按「未标注」处理)。 */
|
|
104
|
+
export declare function snapshotOriginOf(meta: {
|
|
105
|
+
originProfile?: string;
|
|
106
|
+
}): string | undefined;
|
|
107
|
+
/**
|
|
108
|
+
* 行首来源徽章的呈现状态:
|
|
109
|
+
* - `unlabeled`:没有来源(旧快照)→ **不显示徽章**(绝不拿占位值凑一个「未知档案」);
|
|
110
|
+
* - `local`:与当前档案相同 → 只显示档案名,中性;
|
|
111
|
+
* - `foreign`:与当前档案不同 → 显示档案名 + 强调「来自他人档案」;
|
|
112
|
+
* - `unknownCurrent`:宿主没给当前档案 → 只显示档案名 —— 不知道自己在哪个档案时
|
|
113
|
+
* 声称「来自他人档案」是无法证明的结论。
|
|
114
|
+
*/
|
|
115
|
+
export type SnapshotOriginState = 'unlabeled' | 'local' | 'foreign' | 'unknownCurrent';
|
|
116
|
+
export declare function snapshotOriginState(meta: {
|
|
117
|
+
originProfile?: string;
|
|
118
|
+
}, currentProfile?: string): SnapshotOriginState;
|
package/lib/ui/snapshots-view.js
CHANGED
|
@@ -152,4 +152,25 @@ export function isUnreadableNote(note) {
|
|
|
152
152
|
export function planHasExecutableActions(plan) {
|
|
153
153
|
return plan !== null && plan.actions.some((a) => a.kind !== 'skip');
|
|
154
154
|
}
|
|
155
|
+
/* ------------------------------------------------------------ 来源档案(originProfile) */
|
|
156
|
+
/* 这里只判「怎么显示」:快照库里混着别的档案拍的条目(插件数据目录被所有 DSH profile 共用),
|
|
157
|
+
* 徽章要能指出它是谁的。**不做筛选** —— 顶部来源筛选已按用户要求移除(2026-11-08),
|
|
158
|
+
* 筛掉哪些快照不改变任何决定,只是在同一屏多一个控件。 */
|
|
159
|
+
/** 取来源档案名:非空字符串(去首尾空白)才算「能证明的来源」;缺失/空 → undefined(按「未标注」处理)。 */
|
|
160
|
+
export function snapshotOriginOf(meta) {
|
|
161
|
+
const value = meta.originProfile;
|
|
162
|
+
if (typeof value !== 'string')
|
|
163
|
+
return undefined;
|
|
164
|
+
const trimmed = value.trim();
|
|
165
|
+
return trimmed === '' ? undefined : trimmed;
|
|
166
|
+
}
|
|
167
|
+
export function snapshotOriginState(meta, currentProfile) {
|
|
168
|
+
const profile = snapshotOriginOf(meta);
|
|
169
|
+
if (profile === undefined)
|
|
170
|
+
return 'unlabeled';
|
|
171
|
+
const current = typeof currentProfile === 'string' ? currentProfile.trim() : '';
|
|
172
|
+
if (current === '')
|
|
173
|
+
return 'unknownCurrent';
|
|
174
|
+
return current === profile ? 'local' : 'foreign';
|
|
175
|
+
}
|
|
155
176
|
//# sourceMappingURL=snapshots-view.js.map
|
package/lib/utils/env-lock.d.ts
CHANGED
|
@@ -19,6 +19,9 @@ export declare const DEFAULT_ACQUIRE_TIMEOUT_MS = 0;
|
|
|
19
19
|
* 「心跳过期 + pid 存活」永远停在 UNKNOWN_STATE,用户只能手工删锁文件(issue #36 实测)。
|
|
20
20
|
* 心跳长过期说明写方早已停摆 → 允许**显式**回收判为残留锁;acquire 侧仍绝不自动摘锁。 */
|
|
21
21
|
export declare const DEFAULT_LONG_EXPIRED_AFTER_MS: number;
|
|
22
|
+
/** 长持有告警阈值(缺省 2 分钟):正常 mutation(导出/合并/推送)远短于此,超过即视为可疑,
|
|
23
|
+
* 但**只告警不解锁** —— 活持有者可能真的在跑长任务,强拆会造出双持有(比卡死更难查)。 */
|
|
24
|
+
export declare const DEFAULT_HOLD_WARN_AFTER_MS = 120000;
|
|
22
25
|
/** 进程身份(可注入探测;OS 可验证的 process creation identity 才用于 PID reuse) */
|
|
23
26
|
export interface ProcessIdentity {
|
|
24
27
|
/** OS 可验证的进程创建身份串(Linux /proc/<pid>/stat starttime、macOS ps、Windows Get-Process);null = 无法可靠取得 */
|
|
@@ -113,6 +116,10 @@ export interface AcquireResult {
|
|
|
113
116
|
token: MutationLockToken | null;
|
|
114
117
|
/** 诊断信息(非敏感):占用方 op/hostname、或错误描述 */
|
|
115
118
|
detail?: string;
|
|
119
|
+
/** STALE_LOCK_DETECTED 的细分(只用于给用户的分类文案):
|
|
120
|
+
* owner-gone = 结构可证(进程已死 / PID 复用 / 无 identity 能力但心跳长过期);
|
|
121
|
+
* heartbeat-stopped = 进程仍活、identity 相同,但心跳长期停止(典型:release 失败留痕)。 */
|
|
122
|
+
staleKind?: 'owner-gone' | 'heartbeat-stopped';
|
|
116
123
|
}
|
|
117
124
|
/** operation-scoped lock token:accepted 后只属于当前 mutation 调用链 */
|
|
118
125
|
export interface MutationLockToken {
|
|
@@ -259,8 +266,25 @@ export interface EnvLockManagerOptions {
|
|
|
259
266
|
lockVersion?: string;
|
|
260
267
|
/** heartbeat 续期写失败回调(留痕;不中断 mutation) */
|
|
261
268
|
onHeartbeatWriteFailure?: (err: unknown) => void;
|
|
269
|
+
/** release 无法把 ownership 从盘上摘掉时留痕(unlink 反复失败 → 已 quarantine 解除阻塞;或彻底失败)。
|
|
270
|
+
* 以前这条路径完全静默:调用方 `release().catch(() => {})` 把错误吞掉,锁留在盘上无人知道。 */
|
|
271
|
+
onReleaseFailure?: (b: {
|
|
272
|
+
err: unknown;
|
|
273
|
+
quarantined: boolean;
|
|
274
|
+
}) => void;
|
|
262
275
|
/** heartbeat 定时器(测试可注入手动 tick 的假定时器;缺省用全局定时器) */
|
|
263
276
|
timers?: LockTimerApi;
|
|
277
|
+
/** 单次持有超过该时长只**告警**(缺省 120 s;0 = 关闭看门狗)。
|
|
278
|
+
* 真机 issue:autosync 成功后 ownership 与 heartbeat 都没释放、seq 一直涨,recover-stale-lock
|
|
279
|
+
* 判定「持有者还活着」拒绝回收,用户只能删 locks 目录或重启桌面端 —— 期间**没有任何线索**
|
|
280
|
+
* 说明是哪个 op 卡住了。看门狗只补这一层可观测性,绝不强拆活持有者(那会造出双持有)。 */
|
|
281
|
+
holdWarnAfterMs?: number;
|
|
282
|
+
/** 长持有告警回调(留痕/上报;异常被吞,绝不影响锁状态) */
|
|
283
|
+
onHoldExceeded?: (info: {
|
|
284
|
+
op: string;
|
|
285
|
+
heldMs: number;
|
|
286
|
+
tokenId: string;
|
|
287
|
+
}) => void;
|
|
264
288
|
}
|
|
265
289
|
/** 外部命令执行器(测试注入用):只取 stdout;失败/超时抛错。 */
|
|
266
290
|
export type IdentityCommandRunner = (file: string, args: string[], timeoutMs: number) => Promise<string>;
|
|
@@ -322,6 +346,14 @@ export declare class EnvironmentLockManager {
|
|
|
322
346
|
private readonly acquireTimeoutMs;
|
|
323
347
|
private readonly lockVersion;
|
|
324
348
|
private readonly onHeartbeatWriteFailure;
|
|
349
|
+
private readonly onReleaseFailure;
|
|
350
|
+
/** 长持有看门狗阈值/回调(见 EnvLockManagerOptions.holdWarnAfterMs) */
|
|
351
|
+
private readonly holdWarnAfterMs;
|
|
352
|
+
private readonly onHoldExceeded;
|
|
353
|
+
/** 看门狗定时器句柄(与 heartbeatTimer 分开:一个是续期,一个是「该不该还没释放」) */
|
|
354
|
+
private holdWatchdogTimer;
|
|
355
|
+
private holdStartedAt;
|
|
356
|
+
private holdOp;
|
|
325
357
|
/** 诊断用(acquire 时写 ownership.op/target) */
|
|
326
358
|
private readonly defaultOp;
|
|
327
359
|
private readonly defaultTarget;
|
|
@@ -334,6 +366,10 @@ export declare class EnvironmentLockManager {
|
|
|
334
366
|
/** heartbeat 定时器句柄(注入面返回值,类型未知 → 用 null 判「未启动」) */
|
|
335
367
|
private heartbeatTimer;
|
|
336
368
|
private heartbeatSeq;
|
|
369
|
+
/** 在飞 acquire 计数:reclaimOwnLeftover 只在「本 manager 此刻没有别的 acquire 在飞」时动手。
|
|
370
|
+
* 否则 A 刚 open('wx') 成功、还没写上 activeToken 的那一瞬,并发 B 会把 A 的**新锁**当成自己的
|
|
371
|
+
* 残留挪走 —— §11.1-c23 实测会出现两个 ACQUIRED(双持有),那是比卡死更难查的错。 */
|
|
372
|
+
private acquireInFlight;
|
|
337
373
|
private readonly activeInstanceId;
|
|
338
374
|
/** 串行化的 heartbeat 写链(**最后一次写**的 promise);release 前用于 drain,见 drainHeartbeat */
|
|
339
375
|
private pendingHeartbeat;
|
|
@@ -373,8 +409,48 @@ export declare class EnvironmentLockManager {
|
|
|
373
409
|
* **保留 activeToken**(本调用链仍持有该 inode),允许调用方重试 release,绝不留下"令牌已失效但锁在磁盘上"的卡死态。
|
|
374
410
|
*/
|
|
375
411
|
release(token: MutationLockToken): Promise<void>;
|
|
412
|
+
/**
|
|
413
|
+
* 把正式路径上的 ownership 记录挪到 `environment.recovering.*`(quarantine)。
|
|
414
|
+
* 只用于**确证属于本 manager** 的路径:release 的 unlink 失败、acquire 发现盘上是自己的 instanceId。
|
|
415
|
+
*
|
|
416
|
+
* 为什么用 rename 而不是继续 unlink:unlink 删不掉说明「这个目录项删不动」(Windows 共享冲突 /
|
|
417
|
+
* 杀软句柄),重复同一操作不会变好;rename 只移动目录项、不删 inode,能立刻把正式路径腾空,
|
|
418
|
+
* 让后续 acquire 继续。挪走后二次读校验 captured 的 instanceId 仍是自己的才删副本;
|
|
419
|
+
* 不符(异常:被他人写入)就保留副本可查 —— 阻塞已解除,这是本方法与「直接抛错」的关键区别。
|
|
420
|
+
*/
|
|
421
|
+
private quarantineOwnership;
|
|
422
|
+
/**
|
|
423
|
+
* 回收「本 manager 自己上一次释放留下的残留」。
|
|
424
|
+
*
|
|
425
|
+
* 真机卡死态:release 的 unlink 失败被调用方 `release().catch(() => {})` 静默吞掉 →
|
|
426
|
+
* ownership 留在盘上、心跳已停,而本进程仍活 ⇒ inspectLockState 判 LOCKED(owner alive degraded)
|
|
427
|
+
* ⇒ 永不 STALE、显式回收也拒 ⇒ 所有 destructive 操作永久 423。
|
|
428
|
+
*
|
|
429
|
+
* 判据必须结构可证(否则就成了跨实例误删):盘上 instanceId === 本 manager 的 activeInstanceId
|
|
430
|
+
* (随机 16 字节、只有本 manager 会产生 ⇒ 宿主内不可能是别人的锁),并且本 manager 此刻
|
|
431
|
+
* 没有在途临界区(activeToken === null),或 release 已进入但没走完(heartbeatTimer === null,
|
|
432
|
+
* 即 stopHeartbeat() 已执行)。两者都不成立时一律返回 false。
|
|
433
|
+
*/
|
|
434
|
+
private reclaimOwnLeftover;
|
|
376
435
|
private startHeartbeat;
|
|
377
436
|
private stopHeartbeat;
|
|
437
|
+
/**
|
|
438
|
+
* 长持有看门狗:持有时间超过阈值时**告警一次**,然后自行停掉。
|
|
439
|
+
*
|
|
440
|
+
* 只做观察,不做解锁。真机 issue(Windows 桌面端):「autosync 成功后 ownership 与 heartbeat
|
|
441
|
+
* 都没释放、heartbeat seq 一直在涨,recover-stale-lock 判定持有者还活着拒绝回收,只能手动删
|
|
442
|
+
* locks 目录或重启桌面端」。那种状态下心跳是「活着」的,任何结构性 stale 判据都不会命中 ——
|
|
443
|
+
* 所以最需要的是**一条能定位到 op 的日志**,而不是又一个自动回收器(强拆活持有者会造出双持有)。
|
|
444
|
+
*
|
|
445
|
+
* 定时器沿用注入面(LockTimerApi 只有 setInterval):命中一次即 clearInterval,等价于一次性。
|
|
446
|
+
*/
|
|
447
|
+
private startHoldWatchdog;
|
|
448
|
+
private stopHoldWatchdog;
|
|
449
|
+
/** 当前持有的操作与已持有时长(诊断用;未持有 → null)。持有超过阈值时它给出「是哪个 op」。 */
|
|
450
|
+
get holdInfo(): {
|
|
451
|
+
op: string;
|
|
452
|
+
heldMs: number;
|
|
453
|
+
} | null;
|
|
378
454
|
/**
|
|
379
455
|
* 等待**当前在途**的 heartbeat 写完成(不改变持有状态、不停定时器)。
|
|
380
456
|
* 首写在 startHeartbeat() 中**同步**入链,故 acquire() 之后调用本方法必然等到首写落盘。
|
|
@@ -431,6 +507,8 @@ export declare class EnvironmentLockManager {
|
|
|
431
507
|
detail?: string;
|
|
432
508
|
corruptOwnership?: boolean;
|
|
433
509
|
ownerInstanceId?: string;
|
|
510
|
+
/** STALE_LOCK_DETECTED 的细分(供用户文案分类;见 AcquireResult.staleKind) */
|
|
511
|
+
staleKind?: 'owner-gone' | 'heartbeat-stopped';
|
|
434
512
|
}>;
|
|
435
513
|
/**
|
|
436
514
|
* 显式 stale recovery(独立动作;对应 CLI `--recover-stale-lock`)。
|
|
@@ -503,6 +581,12 @@ export type LockBlockReason =
|
|
|
503
581
|
* 必须显式回收(GUI「事故恢复」/ CLI `recover-stale-lock`)。见 issue #27。
|
|
504
582
|
*/
|
|
505
583
|
| 'stale'
|
|
584
|
+
/**
|
|
585
|
+
* 残留锁的**降级形态**:记录里的进程仍活着、OS 身份也一致,但心跳已长期停止(远超窗口)。
|
|
586
|
+
* 只有一种真实成因:持有者的 release 没能把 ownership 从盘上摘掉(Windows 句柄冲突),
|
|
587
|
+
* 而调用方又把 release 的错误吞了。文案不能谎称「持有进程已不存在」,也不用「稍后重试」骗人。
|
|
588
|
+
*/
|
|
589
|
+
| 'stale-degraded'
|
|
506
590
|
/** 锁不可用/IO/权限/UNKNOWN(→ 「操作暂时无法执行,请稍后重试」) */
|
|
507
591
|
| 'unavailable';
|
|
508
592
|
/** 按分类生成用户可读的友好文案(内部诊断不进入此文案;op/reason 作为字段供日志使用)。
|
|
@@ -512,6 +596,18 @@ export declare const LOCK_BLOCK_MESSAGE: Record<LockBlockReason, string>;
|
|
|
512
596
|
* 与 LOCK_BLOCK_MESSAGE 同源同分类:长文案给「需要完整指引」的场景(423 响应/告警日志),
|
|
513
597
|
* 短文案给「一行放不下长句」的场景。分开定义避免任一处再自造文案(issue #31 的漂移根因)。 */
|
|
514
598
|
export declare const LOCK_BLOCK_BRIEF: Record<LockBlockReason, string>;
|
|
599
|
+
/**
|
|
600
|
+
* 锁分类 → 落进结果对象/历史记录的**机器token**(客户端据此本地化;不许再把所有被挡拍平成一个词)。
|
|
601
|
+
*
|
|
602
|
+
* issue:真机现场 SAFE MODE 被拒时 locks 目录是空的,界面却说「环境锁被占用」——
|
|
603
|
+
* 因为宿主所有被挡路径都写死 'mutation-locked',客户端只能照最坏情况解释,排查方向被带偏。
|
|
604
|
+
* 现在按分类发 token:**只有真被另一项活任务占着(LOCKED)才叫 locked**。
|
|
605
|
+
* - 'mutation-safe-mode':被 SAFE MODE 阻断(锁目录通常为空,处置入口是事故恢复)
|
|
606
|
+
* - 'mutation-lock-stale':残留锁(含心跳降级形态)——重试/重启都不会自愈,必须显式回收
|
|
607
|
+
* - 'mutation-lock-unavailable':锁不可用(目录 IO/权限/未知,或 acquire 直接抛错)
|
|
608
|
+
* 旧 token 'mutation-locked' 仍表示「被活跃任务持有」,客户端必须继续认它。
|
|
609
|
+
*/
|
|
610
|
+
export declare function lockSkipToken(reason: LockBlockReason | undefined): string;
|
|
515
611
|
/** destructive 必须成功获取 Environment Lock;否则抛此错(被另一进程/操作持有,或锁不可用)。
|
|
516
612
|
* 携带 op 与 reason 供内部日志诊断;.message 恒为用户可读的友好文案(不暴露锁/op/路径)。 */
|
|
517
613
|
export declare class EnvironmentLockUnavailableError extends Error {
|