@ddtcorex/dsh-maestro-core 0.15.0 → 0.16.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 +7 -7
- package/assets/icon.svg +4 -0
- package/cordis.patch.yml +0 -12
- package/lib/client.js +3 -1744
- package/lib/health-poller.js +1 -1
- package/lib/self-kill-guard.d.ts +25 -8
- package/lib/self-kill-guard.js +81 -27
- package/lib/types/client/config/components/BrandMark.d.ts +3 -3
- package/lib/types/client/index.d.ts.map +1 -1
- package/locale/en.json +6 -0
- package/package.json +9 -5
- package/src/client/config/components/BrandMark.tsx +3 -3
- package/src/client/index.tsx +0 -2
- package/src/host/health-poller.ts +1 -1
- package/src/host/self-kill-guard.ts +84 -26
- package/lib/sync/backup-config.d.ts +0 -55
- package/lib/sync/backup-config.js +0 -119
- package/lib/sync/backup-service.d.ts +0 -123
- package/lib/sync/backup-service.js +0 -486
- package/lib/sync/bidirectional.d.ts +0 -39
- package/lib/sync/bidirectional.js +0 -25
- package/lib/sync/cli.d.ts +0 -38
- package/lib/sync/cli.js +0 -528
- package/lib/sync/config.d.ts +0 -59
- package/lib/sync/config.js +0 -72
- package/lib/sync/fingerprint.d.ts +0 -29
- package/lib/sync/fingerprint.js +0 -65
- package/lib/sync/hashing.d.ts +0 -22
- package/lib/sync/hashing.js +0 -77
- package/lib/sync/index.d.ts +0 -6
- package/lib/sync/index.js +0 -619
- package/lib/sync/machine-id.d.ts +0 -29
- package/lib/sync/machine-id.js +0 -66
- package/lib/sync/merge.d.ts +0 -31
- package/lib/sync/merge.js +0 -86
- package/lib/sync/peer-host.d.ts +0 -22
- package/lib/sync/peer-host.js +0 -62
- package/lib/sync/process-runner.d.ts +0 -31
- package/lib/sync/process-runner.js +0 -161
- package/lib/sync/remote-agent.d.ts +0 -41
- package/lib/sync/remote-agent.js +0 -227
- package/lib/sync/remote-cache.d.ts +0 -18
- package/lib/sync/remote-cache.js +0 -60
- package/lib/sync/remote-manifest.d.ts +0 -33
- package/lib/sync/remote-manifest.js +0 -111
- package/lib/sync/s3-object-store.d.ts +0 -38
- package/lib/sync/s3-object-store.js +0 -126
- package/lib/sync/session-plan.d.ts +0 -29
- package/lib/sync/session-plan.js +0 -213
- package/lib/sync/sigv4.d.ts +0 -20
- package/lib/sync/sigv4.js +0 -57
- package/lib/sync/snapshot.d.ts +0 -16
- package/lib/sync/snapshot.js +0 -143
- package/lib/sync/ssh-mux.d.ts +0 -12
- package/lib/sync/ssh-mux.js +0 -48
- package/lib/sync/store-root.d.ts +0 -44
- package/lib/sync/store-root.js +0 -67
- package/lib/sync/sync-plan.d.ts +0 -24
- package/lib/sync/sync-plan.js +0 -366
- package/lib/sync/sync-service.d.ts +0 -181
- package/lib/sync/sync-service.js +0 -911
- package/lib/sync/sync-types.d.ts +0 -87
- package/lib/sync/sync-types.js +0 -1
- package/lib/sync/transport.d.ts +0 -75
- package/lib/sync/transport.js +0 -196
- package/lib/sync/tunnel-restore.d.ts +0 -77
- package/lib/sync/tunnel-restore.js +0 -142
- package/lib/sync/validation.d.ts +0 -12
- package/lib/sync/validation.js +0 -96
- package/lib/types/client/sync/R2SyncPanel.d.ts +0 -6
- package/lib/types/client/sync/R2SyncPanel.d.ts.map +0 -1
- package/lib/types/client/sync/SyncPanel.d.ts +0 -12
- package/lib/types/client/sync/SyncPanel.d.ts.map +0 -1
- package/lib/types/client/sync/confirm-dialog.d.ts +0 -43
- package/lib/types/client/sync/confirm-dialog.d.ts.map +0 -1
- package/lib/types/client/sync/index.d.ts +0 -10
- package/lib/types/client/sync/index.d.ts.map +0 -1
- package/lib/types/client/sync/ui.d.ts +0 -75
- package/lib/types/client/sync/ui.d.ts.map +0 -1
- package/lib/types/client/sync/use-backup.d.ts +0 -50
- package/lib/types/client/sync/use-backup.d.ts.map +0 -1
- package/lib/types/client/sync/use-sync.d.ts +0 -88
- package/lib/types/client/sync/use-sync.d.ts.map +0 -1
- package/src/client/sync/R2SyncPanel.tsx +0 -260
- package/src/client/sync/SyncPanel.tsx +0 -422
- package/src/client/sync/confirm-dialog.tsx +0 -202
- package/src/client/sync/index.tsx +0 -286
- package/src/client/sync/ui.tsx +0 -297
- package/src/client/sync/use-backup.ts +0 -207
- package/src/client/sync/use-sync.ts +0 -502
- package/src/host/sync/backup-config.ts +0 -158
- package/src/host/sync/backup-service.ts +0 -506
- package/src/host/sync/bidirectional.ts +0 -66
- package/src/host/sync/cli.ts +0 -530
- package/src/host/sync/config.ts +0 -96
- package/src/host/sync/fingerprint.ts +0 -83
- package/src/host/sync/hashing.ts +0 -91
- package/src/host/sync/index.ts +0 -697
- package/src/host/sync/machine-id.ts +0 -81
- package/src/host/sync/merge.ts +0 -99
- package/src/host/sync/peer-host.ts +0 -65
- package/src/host/sync/process-runner.ts +0 -177
- package/src/host/sync/remote-agent.ts +0 -223
- package/src/host/sync/remote-cache.ts +0 -68
- package/src/host/sync/remote-manifest.ts +0 -117
- package/src/host/sync/s3-object-store.ts +0 -144
- package/src/host/sync/session-plan.ts +0 -237
- package/src/host/sync/sigv4.ts +0 -81
- package/src/host/sync/snapshot.ts +0 -132
- package/src/host/sync/ssh-mux.ts +0 -55
- package/src/host/sync/store-root.ts +0 -83
- package/src/host/sync/sync-plan.ts +0 -366
- package/src/host/sync/sync-service.ts +0 -944
- package/src/host/sync/sync-types.ts +0 -102
- package/src/host/sync/transport.ts +0 -256
- package/src/host/sync/tunnel-restore.ts +0 -160
- package/src/host/sync/validation.ts +0 -104
package/lib/sync/sync-plan.js
DELETED
|
@@ -1,366 +0,0 @@
|
|
|
1
|
-
import { createHash, randomBytes } from 'node:crypto';
|
|
2
|
-
import * as path from 'node:path';
|
|
3
|
-
import * as fs from 'node:fs';
|
|
4
|
-
import { mergeDelimited } from './merge.js';
|
|
5
|
-
import { isSameSession, mergeSessionBuffers } from './session-plan.js';
|
|
6
|
-
export const PREVIEW_TTL_MS = 60_000;
|
|
7
|
-
export const MAX_PREVIEWS = 50;
|
|
8
|
-
const previews = new Map();
|
|
9
|
-
const previewDirections = new Map();
|
|
10
|
-
function previewFile(id, dir) {
|
|
11
|
-
return path.join(dir, `${id}.json`);
|
|
12
|
-
}
|
|
13
|
-
/** Read a persisted preview record (null when missing/corrupt). */
|
|
14
|
-
function readPersisted(id, dir) {
|
|
15
|
-
try {
|
|
16
|
-
const parsed = JSON.parse(fs.readFileSync(previewFile(id, dir), 'utf-8'));
|
|
17
|
-
if (!parsed || typeof parsed !== 'object' || typeof parsed.preview?.previewId !== 'string')
|
|
18
|
-
return null;
|
|
19
|
-
return { preview: parsed.preview, direction: parsed.direction };
|
|
20
|
-
}
|
|
21
|
-
catch {
|
|
22
|
-
return null;
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
function pruneExpired() {
|
|
26
|
-
const now = Date.now();
|
|
27
|
-
for (const [id, p] of previews.entries()) {
|
|
28
|
-
if (new Date(p.expiresAt).getTime() <= now) {
|
|
29
|
-
previews.delete(id);
|
|
30
|
-
previewDirections.delete(id);
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
if (previews.size > MAX_PREVIEWS) {
|
|
34
|
-
const entries = [...previews.entries()].sort((a, b) => new Date(a[1].expiresAt).getTime() - new Date(b[1].expiresAt).getTime());
|
|
35
|
-
const toDelete = previews.size - MAX_PREVIEWS;
|
|
36
|
-
for (let i = 0; i < toDelete; i++) {
|
|
37
|
-
const delId = entries[i][0];
|
|
38
|
-
previews.delete(delId);
|
|
39
|
-
previewDirections.delete(delId);
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
/**
|
|
44
|
-
* Persist a preview to disk so a later process (a separate CLI apply) can
|
|
45
|
-
* consume it. The file mirrors the in-memory record; the TTL is enforced on
|
|
46
|
-
* read. Sidecar only — a plain operational folder under DSH_HOME, never part
|
|
47
|
-
* of the eligible sync data.
|
|
48
|
-
*/
|
|
49
|
-
export function persistPreview(preview, direction, dir) {
|
|
50
|
-
if (!dir)
|
|
51
|
-
return '';
|
|
52
|
-
try {
|
|
53
|
-
fs.mkdirSync(dir, { recursive: true, mode: 0o700 });
|
|
54
|
-
const now = Date.now();
|
|
55
|
-
let files = [];
|
|
56
|
-
try {
|
|
57
|
-
files = fs.readdirSync(dir).filter((f) => f.endsWith('.json'));
|
|
58
|
-
}
|
|
59
|
-
catch {
|
|
60
|
-
files = [];
|
|
61
|
-
}
|
|
62
|
-
// purge expired records, then cap at MAX_PREVIEWS (oldest first)
|
|
63
|
-
const keep = [];
|
|
64
|
-
for (const f of files) {
|
|
65
|
-
if (f === `${preview.previewId}.json`)
|
|
66
|
-
continue;
|
|
67
|
-
const record = readPersisted(f.slice(0, -5), dir);
|
|
68
|
-
if (record && new Date(record.preview.expiresAt).getTime() > now)
|
|
69
|
-
keep.push(f);
|
|
70
|
-
else {
|
|
71
|
-
try {
|
|
72
|
-
fs.unlinkSync(path.join(dir, f));
|
|
73
|
-
}
|
|
74
|
-
catch { }
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
keep.sort();
|
|
78
|
-
while (keep.length >= MAX_PREVIEWS) {
|
|
79
|
-
const old = keep.shift();
|
|
80
|
-
try {
|
|
81
|
-
fs.unlinkSync(path.join(dir, old));
|
|
82
|
-
}
|
|
83
|
-
catch { }
|
|
84
|
-
}
|
|
85
|
-
const target = previewFile(preview.previewId, dir);
|
|
86
|
-
const tmp = target + `.tmp.${randomBytes(4).toString('hex')}`;
|
|
87
|
-
fs.writeFileSync(tmp, JSON.stringify({ preview, direction }), 'utf-8');
|
|
88
|
-
fs.renameSync(tmp, target);
|
|
89
|
-
try {
|
|
90
|
-
fs.chmodSync(target, 0o600);
|
|
91
|
-
}
|
|
92
|
-
catch { }
|
|
93
|
-
}
|
|
94
|
-
catch {
|
|
95
|
-
// persistence is best-effort; the in-memory record still works in-process
|
|
96
|
-
}
|
|
97
|
-
return previewFile(preview.previewId, dir);
|
|
98
|
-
}
|
|
99
|
-
/** Delete every persisted preview file under dir (cleanup helper). */
|
|
100
|
-
export function clearPreviewStore(dir) {
|
|
101
|
-
if (!dir)
|
|
102
|
-
return;
|
|
103
|
-
try {
|
|
104
|
-
for (const f of fs.readdirSync(dir)) {
|
|
105
|
-
if (f.endsWith('.json')) {
|
|
106
|
-
try {
|
|
107
|
-
fs.unlinkSync(path.join(dir, f));
|
|
108
|
-
}
|
|
109
|
-
catch { }
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
catch { }
|
|
114
|
-
}
|
|
115
|
-
export function storePreview(preview, direction, dir) {
|
|
116
|
-
pruneExpired();
|
|
117
|
-
if (previews.size >= MAX_PREVIEWS) {
|
|
118
|
-
let oldestId = null;
|
|
119
|
-
let oldestTime = Infinity;
|
|
120
|
-
for (const [id, p] of previews.entries()) {
|
|
121
|
-
const t = new Date(p.expiresAt).getTime();
|
|
122
|
-
if (t < oldestTime) {
|
|
123
|
-
oldestTime = t;
|
|
124
|
-
oldestId = id;
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
if (oldestId) {
|
|
128
|
-
previews.delete(oldestId);
|
|
129
|
-
previewDirections.delete(oldestId);
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
previews.set(preview.previewId, preview);
|
|
133
|
-
if (direction)
|
|
134
|
-
previewDirections.set(preview.previewId, direction);
|
|
135
|
-
if (dir)
|
|
136
|
-
persistPreview(preview, direction, dir);
|
|
137
|
-
const ttl = Math.max(0, new Date(preview.expiresAt).getTime() - Date.now());
|
|
138
|
-
setTimeout(() => {
|
|
139
|
-
previews.delete(preview.previewId);
|
|
140
|
-
previewDirections.delete(preview.previewId);
|
|
141
|
-
}, ttl).unref?.();
|
|
142
|
-
}
|
|
143
|
-
export function getPreview(id, dir) {
|
|
144
|
-
const cached = previews.get(id);
|
|
145
|
-
if (cached) {
|
|
146
|
-
if (new Date(cached.expiresAt).getTime() <= Date.now()) {
|
|
147
|
-
previews.delete(id);
|
|
148
|
-
previewDirections.delete(id);
|
|
149
|
-
return undefined;
|
|
150
|
-
}
|
|
151
|
-
return cached;
|
|
152
|
-
}
|
|
153
|
-
if (!dir)
|
|
154
|
-
return undefined;
|
|
155
|
-
const record = readPersisted(id, dir);
|
|
156
|
-
if (!record)
|
|
157
|
-
return undefined;
|
|
158
|
-
const p = record.preview;
|
|
159
|
-
if (new Date(p.expiresAt).getTime() <= Date.now()) {
|
|
160
|
-
try {
|
|
161
|
-
fs.unlinkSync(previewFile(id, dir));
|
|
162
|
-
}
|
|
163
|
-
catch { }
|
|
164
|
-
return undefined;
|
|
165
|
-
}
|
|
166
|
-
// hydrate into memory for single-process idempotence
|
|
167
|
-
previews.set(p.previewId, p);
|
|
168
|
-
if (record.direction)
|
|
169
|
-
previewDirections.set(p.previewId, record.direction);
|
|
170
|
-
return p;
|
|
171
|
-
}
|
|
172
|
-
export function getPreviewDirection(id) {
|
|
173
|
-
return previewDirections.get(id);
|
|
174
|
-
}
|
|
175
|
-
export function deletePreview(id, dir) {
|
|
176
|
-
previews.delete(id);
|
|
177
|
-
previewDirections.delete(id);
|
|
178
|
-
if (dir) {
|
|
179
|
-
try {
|
|
180
|
-
fs.unlinkSync(previewFile(id, dir));
|
|
181
|
-
}
|
|
182
|
-
catch { }
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
export function clearPreviews() {
|
|
186
|
-
previews.clear();
|
|
187
|
-
previewDirections.clear();
|
|
188
|
-
}
|
|
189
|
-
export function revisionFrom(snapshots, direction) {
|
|
190
|
-
const h = createHash('sha256');
|
|
191
|
-
h.update(direction);
|
|
192
|
-
const sorted = [...snapshots].sort((a, b) => a.path.localeCompare(b.path));
|
|
193
|
-
for (const s of sorted) {
|
|
194
|
-
h.update(s.path + ':' + s.sha256 + ':' + String(s.size) + ':' + s.kind);
|
|
195
|
-
}
|
|
196
|
-
return h.digest('hex').slice(0, 16);
|
|
197
|
-
}
|
|
198
|
-
function unionJsonlAdded(localBuf, remoteBuf) {
|
|
199
|
-
const localLines = localBuf.toString('utf-8').split('\n').filter((l) => l.length > 0);
|
|
200
|
-
const remoteLines = remoteBuf.toString('utf-8').split('\n').filter((l) => l.length > 0);
|
|
201
|
-
const seen = new Set(localLines);
|
|
202
|
-
let added = 0;
|
|
203
|
-
for (const line of remoteLines) {
|
|
204
|
-
if (!seen.has(line)) {
|
|
205
|
-
seen.add(line);
|
|
206
|
-
added++;
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
return added;
|
|
210
|
-
}
|
|
211
|
-
export async function buildPlan(localSnapshots, remoteSnapshots, direction, localContents, remoteContents, opts = {}) {
|
|
212
|
-
const localMap = new Map(localSnapshots.map((s) => [s.path, s]));
|
|
213
|
-
const remoteMap = new Map(remoteSnapshots.map((s) => [s.path, s]));
|
|
214
|
-
const allPaths = new Set([...localMap.keys(), ...remoteMap.keys()]);
|
|
215
|
-
const actions = [];
|
|
216
|
-
let copied = 0;
|
|
217
|
-
let merged = 0;
|
|
218
|
-
let skipped = 0;
|
|
219
|
-
let conflicts = 0;
|
|
220
|
-
let added = 0;
|
|
221
|
-
// Count-only sessions: preview reports added/updated/deleted/identical from
|
|
222
|
-
// path+checksum without staging content. These files never produce action
|
|
223
|
-
// rows — the UI shows the counts instead of per-file rows. Apply is untouched:
|
|
224
|
-
// it re-inventories with full content and builds a real merge plan.
|
|
225
|
-
let sessionCounts = { added: 0, updated: 0, deleted: 0, identical: 0 };
|
|
226
|
-
const isSession = (p) => p.endsWith('.zstd');
|
|
227
|
-
const sortedPaths = [...allPaths].sort((a, b) => a.localeCompare(b));
|
|
228
|
-
for (const p of sortedPaths) {
|
|
229
|
-
const ls = localMap.get(p);
|
|
230
|
-
const rs = remoteMap.get(p);
|
|
231
|
-
const target = direction === 'pull' ? 'local' : 'remote';
|
|
232
|
-
if (opts.countOnlySessions && isSession(p)) {
|
|
233
|
-
if (!ls && rs) {
|
|
234
|
-
if (direction === 'pull')
|
|
235
|
-
sessionCounts.added++;
|
|
236
|
-
else
|
|
237
|
-
sessionCounts.deleted++;
|
|
238
|
-
}
|
|
239
|
-
else if (ls && !rs) {
|
|
240
|
-
if (direction === 'pull')
|
|
241
|
-
sessionCounts.deleted++;
|
|
242
|
-
else
|
|
243
|
-
sessionCounts.added++;
|
|
244
|
-
}
|
|
245
|
-
else if (ls && rs) {
|
|
246
|
-
if (ls.sha256 === rs.sha256)
|
|
247
|
-
sessionCounts.identical++;
|
|
248
|
-
else
|
|
249
|
-
sessionCounts.updated++;
|
|
250
|
-
}
|
|
251
|
-
continue;
|
|
252
|
-
}
|
|
253
|
-
if (ls && !rs) {
|
|
254
|
-
if (direction === 'push') {
|
|
255
|
-
actions.push({ path: p, action: 'copy', target: 'remote', added: 0, reason: 'local only', expectedTargetSha256: undefined });
|
|
256
|
-
copied++;
|
|
257
|
-
}
|
|
258
|
-
else {
|
|
259
|
-
actions.push({ path: p, action: 'skip', target: 'local', added: 0, reason: 'local only, pull skips' });
|
|
260
|
-
skipped++;
|
|
261
|
-
}
|
|
262
|
-
continue;
|
|
263
|
-
}
|
|
264
|
-
if (!ls && rs) {
|
|
265
|
-
if (direction === 'pull') {
|
|
266
|
-
actions.push({ path: p, action: 'copy', target: 'local', added: 0, reason: 'remote only' });
|
|
267
|
-
copied++;
|
|
268
|
-
}
|
|
269
|
-
else {
|
|
270
|
-
actions.push({ path: p, action: 'skip', target: 'remote', added: 0, reason: 'remote only, push skips' });
|
|
271
|
-
skipped++;
|
|
272
|
-
}
|
|
273
|
-
continue;
|
|
274
|
-
}
|
|
275
|
-
if (ls && rs) {
|
|
276
|
-
if (ls.sha256 === rs.sha256) {
|
|
277
|
-
actions.push({ path: p, action: 'skip', target, added: 0, reason: 'identical bytes', expectedTargetSha256: ls.sha256 });
|
|
278
|
-
skipped++;
|
|
279
|
-
continue;
|
|
280
|
-
}
|
|
281
|
-
const localBuf = localContents.get(p);
|
|
282
|
-
const remoteBuf = remoteContents.get(p);
|
|
283
|
-
if (!localBuf || !remoteBuf) {
|
|
284
|
-
actions.push({ path: p, action: 'conflict', target, added: 0, reason: 'missing content for merge', expectedTargetSha256: target === 'local' ? ls.sha256 : rs.sha256 });
|
|
285
|
-
conflicts++;
|
|
286
|
-
continue;
|
|
287
|
-
}
|
|
288
|
-
try {
|
|
289
|
-
if (p.endsWith('.md')) {
|
|
290
|
-
const localStr = localBuf.toString('utf-8');
|
|
291
|
-
const remoteStr = remoteBuf.toString('utf-8');
|
|
292
|
-
const { added: addedCount } = direction === 'pull' ? mergeDelimited(localStr, remoteStr) : mergeDelimited(remoteStr, localStr);
|
|
293
|
-
if (addedCount === 0) {
|
|
294
|
-
// same delimited entries, different bytes/order — nothing to add
|
|
295
|
-
actions.push({ path: p, action: 'skip', target, added: 0, reason: 'content-equal, no new entries', expectedTargetSha256: target === 'local' ? ls.sha256 : rs.sha256 });
|
|
296
|
-
skipped++;
|
|
297
|
-
}
|
|
298
|
-
else {
|
|
299
|
-
actions.push({ path: p, action: 'merge', target, added: addedCount, reason: 'content differs, merge', expectedTargetSha256: target === 'local' ? ls.sha256 : rs.sha256 });
|
|
300
|
-
merged++;
|
|
301
|
-
added += addedCount;
|
|
302
|
-
}
|
|
303
|
-
}
|
|
304
|
-
else if (p.endsWith('.jsonl')) {
|
|
305
|
-
const addedCount = direction === 'pull' ? unionJsonlAdded(localBuf, remoteBuf) : unionJsonlAdded(remoteBuf, localBuf);
|
|
306
|
-
if (addedCount === 0) {
|
|
307
|
-
actions.push({ path: p, action: 'skip', target, added: 0, reason: 'content-equal, no new lines', expectedTargetSha256: target === 'local' ? ls.sha256 : rs.sha256 });
|
|
308
|
-
skipped++;
|
|
309
|
-
}
|
|
310
|
-
else {
|
|
311
|
-
actions.push({ path: p, action: 'merge', target, added: addedCount, reason: 'content differs, merge', expectedTargetSha256: target === 'local' ? ls.sha256 : rs.sha256 });
|
|
312
|
-
merged++;
|
|
313
|
-
added += addedCount;
|
|
314
|
-
}
|
|
315
|
-
}
|
|
316
|
-
else if (p.endsWith('.zstd')) {
|
|
317
|
-
// Session handling is Buffer/path-only and preserves DSH standalone checksummed Zstd header frame.
|
|
318
|
-
// Never convert Zstd bytes to UTF-8 string; use validated Zstd artifact API via session-plan.
|
|
319
|
-
try {
|
|
320
|
-
if (!isSameSession(localBuf, remoteBuf)) {
|
|
321
|
-
actions.push({ path: p, action: 'conflict', target, added: 0, reason: 'session header mismatch', expectedTargetSha256: target === 'local' ? ls.sha256 : rs.sha256 });
|
|
322
|
-
conflicts++;
|
|
323
|
-
}
|
|
324
|
-
else {
|
|
325
|
-
const { added: addedCount } = direction === 'pull' ? mergeSessionBuffers(localBuf, remoteBuf) : mergeSessionBuffers(remoteBuf, localBuf);
|
|
326
|
-
if (addedCount === 0) {
|
|
327
|
-
// identical session lines under a (possibly different) zstd frame layout
|
|
328
|
-
actions.push({ path: p, action: 'skip', target, added: 0, reason: 'content-equal, no new entries', expectedTargetSha256: target === 'local' ? ls.sha256 : rs.sha256 });
|
|
329
|
-
skipped++;
|
|
330
|
-
}
|
|
331
|
-
else {
|
|
332
|
-
actions.push({ path: p, action: 'merge', target, added: addedCount, reason: 'session differs, merge', expectedTargetSha256: target === 'local' ? ls.sha256 : rs.sha256 });
|
|
333
|
-
merged++;
|
|
334
|
-
added += addedCount;
|
|
335
|
-
}
|
|
336
|
-
}
|
|
337
|
-
}
|
|
338
|
-
catch (e) {
|
|
339
|
-
actions.push({ path: p, action: 'conflict', target, added: 0, reason: e?.message ?? 'session merge failed', expectedTargetSha256: target === 'local' ? ls.sha256 : rs.sha256 });
|
|
340
|
-
conflicts++;
|
|
341
|
-
}
|
|
342
|
-
}
|
|
343
|
-
else {
|
|
344
|
-
actions.push({ path: p, action: 'conflict', target, added: 0, reason: 'unknown kind', expectedTargetSha256: target === 'local' ? ls.sha256 : rs.sha256 });
|
|
345
|
-
conflicts++;
|
|
346
|
-
}
|
|
347
|
-
}
|
|
348
|
-
catch (e) {
|
|
349
|
-
actions.push({ path: p, action: 'conflict', target, added: 0, reason: e?.message ?? 'merge failed', expectedTargetSha256: target === 'local' ? ls.sha256 : rs.sha256 });
|
|
350
|
-
conflicts++;
|
|
351
|
-
}
|
|
352
|
-
}
|
|
353
|
-
}
|
|
354
|
-
const revision = revisionFrom([...localSnapshots, ...remoteSnapshots], direction);
|
|
355
|
-
const summary = { copied, merged, skipped, conflicts, added };
|
|
356
|
-
actions.sort((a, b) => a.path.localeCompare(b.path));
|
|
357
|
-
return { revision, actions, summary, sessionCounts: opts.countOnlySessions ? sessionCounts : undefined };
|
|
358
|
-
}
|
|
359
|
-
export async function buildPreview(localSnapshots, remoteSnapshots, direction, localContents, remoteContents, opts = {}) {
|
|
360
|
-
const plan = await buildPlan(localSnapshots, remoteSnapshots, direction, localContents, remoteContents, opts);
|
|
361
|
-
const previewId = randomBytes(16).toString('hex');
|
|
362
|
-
const expiresAt = new Date(Date.now() + PREVIEW_TTL_MS).toISOString();
|
|
363
|
-
const preview = { ...plan, previewId, expiresAt };
|
|
364
|
-
storePreview(preview, direction);
|
|
365
|
-
return preview;
|
|
366
|
-
}
|
|
@@ -1,181 +0,0 @@
|
|
|
1
|
-
import type { RemoteTarget, SyncDirection, SyncPreview, SyncSummary, SyncFailure, SyncProgress, SyncScope } from './sync-types.js';
|
|
2
|
-
import { type ProcessRunner } from './process-runner.js';
|
|
3
|
-
import { type SyncTransport } from './transport.js';
|
|
4
|
-
export interface PreviewRequest {
|
|
5
|
-
direction: SyncDirection;
|
|
6
|
-
scope?: SyncScope;
|
|
7
|
-
}
|
|
8
|
-
export interface ApplyRequest {
|
|
9
|
-
previewId: string;
|
|
10
|
-
direction: SyncDirection;
|
|
11
|
-
confirm: true;
|
|
12
|
-
scope?: SyncScope;
|
|
13
|
-
}
|
|
14
|
-
export interface ApplyResult {
|
|
15
|
-
ok: boolean;
|
|
16
|
-
revision: string;
|
|
17
|
-
summary: SyncSummary;
|
|
18
|
-
committed: string[];
|
|
19
|
-
failures: SyncFailure[];
|
|
20
|
-
}
|
|
21
|
-
export interface ConnectionStatus {
|
|
22
|
-
ok: boolean;
|
|
23
|
-
host: string;
|
|
24
|
-
latencyMs?: number;
|
|
25
|
-
error?: string;
|
|
26
|
-
}
|
|
27
|
-
/** Legacy status shape — counts never imply same path means same content. */
|
|
28
|
-
export interface StatusResult {
|
|
29
|
-
localOnly: number;
|
|
30
|
-
remoteOnly: number;
|
|
31
|
-
both: number;
|
|
32
|
-
localOnlyFiles: string[];
|
|
33
|
-
remoteOnlyFiles: string[];
|
|
34
|
-
bothFiles: string[];
|
|
35
|
-
connection: ConnectionStatus;
|
|
36
|
-
remoteHost: string;
|
|
37
|
-
}
|
|
38
|
-
/** Cursor-paged status page for bounded RPC payloads (< 64 KiB). */
|
|
39
|
-
export interface StatusPage {
|
|
40
|
-
total: number;
|
|
41
|
-
offset: number;
|
|
42
|
-
limit: number;
|
|
43
|
-
files: string[];
|
|
44
|
-
nextCursor: number | null;
|
|
45
|
-
connection: ConnectionStatus;
|
|
46
|
-
remoteHost: string;
|
|
47
|
-
}
|
|
48
|
-
export interface PreviewResult extends SyncPreview {
|
|
49
|
-
connection: ConnectionStatus;
|
|
50
|
-
remoteHost: string;
|
|
51
|
-
}
|
|
52
|
-
export interface SyncServiceOpts {
|
|
53
|
-
localDsh?: string;
|
|
54
|
-
/** Resolved memory store root; defaults to the same rules the plugin uses. */
|
|
55
|
-
storeRoot?: string;
|
|
56
|
-
remote?: string;
|
|
57
|
-
remoteDsh?: string;
|
|
58
|
-
previewDir?: string;
|
|
59
|
-
cacheDir?: string;
|
|
60
|
-
fs?: any;
|
|
61
|
-
runner?: ProcessRunner;
|
|
62
|
-
transport?: SyncTransport;
|
|
63
|
-
}
|
|
64
|
-
export declare class SyncService {
|
|
65
|
-
localDsh: string;
|
|
66
|
-
storeRoot: string;
|
|
67
|
-
remote: string;
|
|
68
|
-
remoteDsh: string;
|
|
69
|
-
previewDir: string;
|
|
70
|
-
cacheDir: string;
|
|
71
|
-
fs: any;
|
|
72
|
-
runner: ProcessRunner;
|
|
73
|
-
transport: SyncTransport;
|
|
74
|
-
constructor(opts?: SyncServiceOpts);
|
|
75
|
-
/**
|
|
76
|
-
* Resolve + validate the remote target. A `~/.dsh` placeholder is resolved by
|
|
77
|
-
* the transport preflight (remote $HOME bytes) — never by local shell ~ expansion.
|
|
78
|
-
*/
|
|
79
|
-
resolveTarget(): Promise<RemoteTarget>;
|
|
80
|
-
private requireTarget;
|
|
81
|
-
checkConnection(): Promise<ConnectionStatus>;
|
|
82
|
-
private requireConnection;
|
|
83
|
-
/**
|
|
84
|
-
* Local eligible files (maestro-memory/*.md, maestro-memory/SUGGESTIONS.jsonl,
|
|
85
|
-
* sessions/<cwd-hash>/<id>/session.jsonl.zstd) as relative paths, sorted.
|
|
86
|
-
* Only content that matches the eligible contract is ever read or hashed.
|
|
87
|
-
*/
|
|
88
|
-
/** The two roots a wire path can resolve to. */
|
|
89
|
-
hashRoots(): {
|
|
90
|
-
storeRoot: string;
|
|
91
|
-
localDsh: string;
|
|
92
|
-
};
|
|
93
|
-
/** Map a wire path to its local file, through the resolved store root. */
|
|
94
|
-
localPathForWirePath(wirePath: string): string;
|
|
95
|
-
listLocalFiles(): string[];
|
|
96
|
-
/**
|
|
97
|
-
* Snapshot both sides with the manifest-first pipeline:
|
|
98
|
-
* - remote: ONE `transport.manifest` pass (path/sha256/size; NUL-framed,
|
|
99
|
-
* validated). No `list`+`rsync -rcn`+`hashes`, and identical sessions are
|
|
100
|
-
* counted from the manifest without byte transfer.
|
|
101
|
-
* - local: the fingerprint cache (dev+ino+size+mtimeNs+ctimeNs) supplies
|
|
102
|
-
* known SHA-256 values without re-reading files; only cache misses are
|
|
103
|
-
* stream-hashed. Content is loaded lazily for exactly the files a plan or
|
|
104
|
-
* merge needs — identical files are never read into memory.
|
|
105
|
-
* The cache is a pure speed hint: every file apply will WRITE is re-read and
|
|
106
|
-
* re-hashed at write time (see apply), so a stale cache can never publish a
|
|
107
|
-
* wrong mutation target.
|
|
108
|
-
*/
|
|
109
|
-
/**
|
|
110
|
-
* The 4.0 rename moved the store root. A machine still on the old root would
|
|
111
|
-
* inventory zero memory files, which reads exactly like "nothing to sync".
|
|
112
|
-
* Refuse instead: the marker is written by the plugin's boot migration.
|
|
113
|
-
*/
|
|
114
|
-
private assertLocalStoreMigrated;
|
|
115
|
-
/**
|
|
116
|
-
* Refuse a peer that still keeps its store inside the DSH home.
|
|
117
|
-
*
|
|
118
|
-
* The wire paths are the same on both sides, so a mixed pair writes into a directory
|
|
119
|
-
* the upgraded machine no longer reads: the transfer succeeds and the memories are
|
|
120
|
-
* invisible. The marker is the only signal available before the transfer starts.
|
|
121
|
-
*/
|
|
122
|
-
assertPeerMoved(remotePaths: string[]): void;
|
|
123
|
-
private snapshotBoth;
|
|
124
|
-
/**
|
|
125
|
-
* Read-only preview: exact plan with copy/merge/skip/conflict and real added
|
|
126
|
-
* counts — except sessions under `sessionsCountOnly`, which are counted by
|
|
127
|
-
* path+checksum (added/updated/deleted/identical) without staging content.
|
|
128
|
-
* `onProgress` receives per-phase ticks (hashing emits one per session file).
|
|
129
|
-
* No preview path may copy, backup, restore or publish.
|
|
130
|
-
*/
|
|
131
|
-
/**
|
|
132
|
-
* Wrap a multi-spawn operation in one SSH ControlMaster link (Task 6 + follow-up).
|
|
133
|
-
* Fail-open: if the master cannot start (MUX_FAILED) or the transport does not
|
|
134
|
-
* support mux (fakes, rehearsal), run unmuxed — a link optimization, never a
|
|
135
|
-
* correctness requirement. Preview stays read-only; the mux teardown runs in
|
|
136
|
-
* finally.
|
|
137
|
-
*/
|
|
138
|
-
private withMux;
|
|
139
|
-
preview(opts: {
|
|
140
|
-
direction: SyncDirection;
|
|
141
|
-
scope?: SyncScope;
|
|
142
|
-
sessionsCountOnly?: boolean;
|
|
143
|
-
onProgress?: (p: SyncProgress) => void;
|
|
144
|
-
shouldStop?: () => boolean;
|
|
145
|
-
}): Promise<PreviewResult>;
|
|
146
|
-
private previewInner;
|
|
147
|
-
private assertApplyRequest;
|
|
148
|
-
/** Merge dispatcher — bytes stay bytes for zstd; md/jsonl use deterministic unions. */
|
|
149
|
-
private mergeBuffer;
|
|
150
|
-
private atomicWriteWithBackup;
|
|
151
|
-
/**
|
|
152
|
-
* Apply a previously generated preview (the only mutation route).
|
|
153
|
-
* Re-inventories both sides and applies the FRESHEST plan — DSH homes change
|
|
154
|
-
* continuously (session logs are appended every turn), so a byte-for-byte
|
|
155
|
-
* inventory comparison would reject nearly every live apply (STALE_PREVIEW).
|
|
156
|
-
* Safety stays fail-closed without it: each file publish carries the
|
|
157
|
-
* expected target sha (CAS) and a preview is single-use, so a concurrent
|
|
158
|
-
* modification during the write is still rejected and nothing is overwritten
|
|
159
|
-
* silently. Pull publishes atomically per local file; push materializes,
|
|
160
|
-
* uploads and commits through the remote CAS helper.
|
|
161
|
-
*/
|
|
162
|
-
apply(req: ApplyRequest): Promise<ApplyResult>;
|
|
163
|
-
private applyInner;
|
|
164
|
-
private manifestMemo;
|
|
165
|
-
private statusManifest;
|
|
166
|
-
/** Local eligible paths with their sha256 (fingerprint cache fast-path; stale files stream-hashed). */
|
|
167
|
-
private localSnapshotsWithHashes;
|
|
168
|
-
status(): Promise<StatusResult>;
|
|
169
|
-
/**
|
|
170
|
-
* Cursor-paged status page — bounded output.
|
|
171
|
-
* Buckets are ACTION-based (like preview): `remoteOnly` lists every file a
|
|
172
|
-
* pull would bring in (remote-only paths + both-side content differences),
|
|
173
|
-
* `localOnly` lists what a push would send (local-only paths + content
|
|
174
|
-
* differences). One manifest + one local stat/hash pass; no rsync compare.
|
|
175
|
-
*/
|
|
176
|
-
statusPage(opts?: {
|
|
177
|
-
bucket?: string;
|
|
178
|
-
cursor?: number;
|
|
179
|
-
limit?: number;
|
|
180
|
-
}): Promise<StatusPage>;
|
|
181
|
-
}
|