@ddtcorex/dsh-maestro-core 0.15.1 → 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 -216
- 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 -20
- package/lib/sync/remote-manifest.js +0 -86
- 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 -183
- package/lib/sync/sync-service.js +0 -926
- 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 -212
- package/src/host/sync/remote-cache.ts +0 -68
- package/src/host/sync/remote-manifest.ts +0 -91
- 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 -960
- 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/src/host/sync/config.ts
DELETED
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
import { load } from '../store/index.js';
|
|
2
|
-
import { validateRemoteTarget } from './validation.js';
|
|
3
|
-
import { readPeerHost } from './peer-host.js';
|
|
4
|
-
import type { SyncDirection, SyncRequest } from './sync-types.js';
|
|
5
|
-
|
|
6
|
-
export interface SyncConfig {
|
|
7
|
-
remoteHost: string;
|
|
8
|
-
remoteDshPath: string;
|
|
9
|
-
strategy: string;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
/** The built-in SSH target, reached only when nothing was ever configured. */
|
|
13
|
-
export const DEFAULT_REMOTE_HOST = 'kai@ssh.ddtcorex.com';
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Effective peer host from the four sources, highest first:
|
|
17
|
-
*
|
|
18
|
-
* 1. This machine's own `peer.json` — machine-local truth (see peer-host.ts).
|
|
19
|
-
* 2. The shared settings store `domains.sync.remoteHost` — UI-editable, but it
|
|
20
|
-
* travels between machines, so on the mirrored machine it can name that
|
|
21
|
-
* machine instead of its peer.
|
|
22
|
-
* 3. `REMOTE_HOST` / `REMOTE` env.
|
|
23
|
-
* 4. {@link DEFAULT_REMOTE_HOST}.
|
|
24
|
-
*
|
|
25
|
-
* The machine-local file deliberately outranks the shared store: a machine that
|
|
26
|
-
* inherited the other machine's address must be able to state its own peer
|
|
27
|
-
* without editing a file both machines share. Env stays below the store because
|
|
28
|
-
* callers that need to force a target pass it explicitly (`--remote`), which
|
|
29
|
-
* wins over this whole list.
|
|
30
|
-
*/
|
|
31
|
-
export function resolveRemoteHost(sources: {
|
|
32
|
-
env?: string;
|
|
33
|
-
machineLocal?: string | null;
|
|
34
|
-
stored?: string;
|
|
35
|
-
fallback?: string;
|
|
36
|
-
}): string {
|
|
37
|
-
const first = [sources.machineLocal ?? undefined, sources.stored, sources.env].find(
|
|
38
|
-
(candidate): candidate is string => typeof candidate === 'string' && candidate.trim().length > 0,
|
|
39
|
-
);
|
|
40
|
-
return first ?? sources.fallback ?? DEFAULT_REMOTE_HOST;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* Load sync config via @ddtcorex/dsh-maestro-config-lib load() -> domains.sync
|
|
45
|
-
* Peer host precedence: see {@link resolveRemoteHost}.
|
|
46
|
-
* remoteDshPath = sync.remoteDshPath || REMOTE_DSH_PATH env || '~/.dsh' (unresolved placeholder)
|
|
47
|
-
* strategy = 'merge'
|
|
48
|
-
*
|
|
49
|
-
* NOTE: remoteDshPath may be '~/.dsh' as stored placeholder. It is NOT a validated
|
|
50
|
-
* absolute path. Caller must validate via `validateRemoteTarget` / `buildSyncRequest`
|
|
51
|
-
* before constructing a SyncRequest. The absolute remote home is resolved by the
|
|
52
|
-
* transport preflight (ssh remoteHome), not by shell ~ expansion.
|
|
53
|
-
*
|
|
54
|
-
* @param opts.dshHome DSH home holding this machine's peer file; the caller's
|
|
55
|
-
* own resolved home wins over the ambient default.
|
|
56
|
-
*/
|
|
57
|
-
export async function loadSyncConfig(opts: { dshHome?: string } = {}): Promise<SyncConfig> {
|
|
58
|
-
const doc = await load({ dshHome: opts.dshHome });
|
|
59
|
-
const sync = (doc.domains?.sync as Record<string, unknown> | undefined) ?? {};
|
|
60
|
-
const remoteHost = resolveRemoteHost({
|
|
61
|
-
env: process.env.REMOTE_HOST || process.env.REMOTE,
|
|
62
|
-
machineLocal: readPeerHost(opts.dshHome),
|
|
63
|
-
stored: sync.remoteHost as string | undefined,
|
|
64
|
-
});
|
|
65
|
-
const remoteDshPath = (sync.remoteDshPath as string | undefined) || process.env.REMOTE_DSH_PATH || '~/.dsh';
|
|
66
|
-
const strategy = (sync.strategy as string | undefined) || 'merge';
|
|
67
|
-
return { remoteHost, remoteDshPath, strategy };
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
/**
|
|
71
|
-
* Build a validated SyncRequest. Remote is validated via validateRemoteTarget;
|
|
72
|
-
* localRoot is expected to be an absolute local path (lightly validated as absolute).
|
|
73
|
-
* Throws on invalid host/path.
|
|
74
|
-
*/
|
|
75
|
-
export function buildSyncRequest(params: {
|
|
76
|
-
direction: SyncDirection;
|
|
77
|
-
dryRun: boolean;
|
|
78
|
-
localRoot: string;
|
|
79
|
-
remoteHost: string;
|
|
80
|
-
remoteDshPath: string;
|
|
81
|
-
}): SyncRequest {
|
|
82
|
-
const remote = validateRemoteTarget({ host: params.remoteHost, dshRoot: params.remoteDshPath });
|
|
83
|
-
// localRoot should be absolute; reuse ABSOLUTE notion but allow local home paths
|
|
84
|
-
if (!params.localRoot || typeof params.localRoot !== 'string' || !params.localRoot.startsWith('/')) {
|
|
85
|
-
throw new Error(`invalid localRoot: must be absolute path: ${JSON.stringify(params.localRoot)}`);
|
|
86
|
-
}
|
|
87
|
-
if (params.localRoot.includes('\u0000') || params.localRoot.includes('\n')) {
|
|
88
|
-
throw new Error('invalid localRoot: contains control characters');
|
|
89
|
-
}
|
|
90
|
-
return {
|
|
91
|
-
direction: params.direction,
|
|
92
|
-
dryRun: params.dryRun,
|
|
93
|
-
localRoot: params.localRoot,
|
|
94
|
-
remote,
|
|
95
|
-
};
|
|
96
|
-
}
|
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
// src/host/fingerprint.ts — persistent stat->sha256 index (a pure speed hint).
|
|
2
|
-
//
|
|
3
|
-
// The cache NEVER proves equality on its own: entry.key is trusted only when
|
|
4
|
-
// dev+ino+size+mtimeNs+ctimeNs all match the current stat, and every file a
|
|
5
|
-
// plan will write is freshly read+hashed at write time (see sync-service).
|
|
6
|
-
// mtime+size alone is never an equality proof — a same-size rewrite preserves
|
|
7
|
-
// them; ctimeNs closes that gap (ctime always changes on a write).
|
|
8
|
-
import * as fsMod from 'node:fs';
|
|
9
|
-
import * as path from 'node:path';
|
|
10
|
-
import { randomBytes } from 'node:crypto';
|
|
11
|
-
|
|
12
|
-
export interface FpEntry {
|
|
13
|
-
dev: number;
|
|
14
|
-
ino: number;
|
|
15
|
-
size: number;
|
|
16
|
-
mtimeNs: string;
|
|
17
|
-
ctimeNs: string;
|
|
18
|
-
sha256: string;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export interface FingerprintIndex {
|
|
22
|
-
schema: 1;
|
|
23
|
-
rootKey: string;
|
|
24
|
-
entries: Record<string, FpEntry>;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
const FILE = 'index.json';
|
|
28
|
-
|
|
29
|
-
function toNs(v: unknown, ms: unknown): bigint {
|
|
30
|
-
if (v !== undefined && v !== null) {
|
|
31
|
-
try {
|
|
32
|
-
return BigInt(v as bigint | number | string);
|
|
33
|
-
} catch {
|
|
34
|
-
// fall through to ms-derived approximation
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
return BigInt(Math.trunc((typeof ms === 'number' && Number.isFinite(ms) ? ms : 0) * 1e6));
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* Stable stat fingerprint. Prefer stats from `statSync(p, { bigint: true })`;
|
|
42
|
-
* the mtime/ctime nanoseconds are then exact. Non-bigint stats fall back to an
|
|
43
|
-
* ms-derived approximation, which still changes on any write via ctime.
|
|
44
|
-
*/
|
|
45
|
-
export function statFingerprint(st: any): { dev: number; ino: number; size: number; mtimeNs: string; ctimeNs: string } {
|
|
46
|
-
return {
|
|
47
|
-
dev: Number(st.dev ?? 0),
|
|
48
|
-
ino: Number(st.ino ?? 0),
|
|
49
|
-
size: Number(st.size ?? 0),
|
|
50
|
-
mtimeNs: String(toNs(st.mtimeNs, st.mtimeMs)),
|
|
51
|
-
ctimeNs: String(toNs(st.ctimeNs, st.ctimeMs)),
|
|
52
|
-
};
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
export function matchesStat(entry: FpEntry, st: any): boolean {
|
|
56
|
-
const k = statFingerprint(st);
|
|
57
|
-
return entry.dev === k.dev && entry.ino === k.ino && entry.size === k.size && entry.mtimeNs === k.mtimeNs && entry.ctimeNs === k.ctimeNs;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
export function loadIndex(dir: string): FingerprintIndex {
|
|
61
|
-
try {
|
|
62
|
-
const raw = JSON.parse(fsMod.readFileSync(path.join(dir, FILE), 'utf-8')) as { schema?: number; rootKey?: string; entries?: Record<string, FpEntry> };
|
|
63
|
-
if (raw?.schema !== 1 || !raw.entries || typeof raw.rootKey !== 'string') return { schema: 1, rootKey: '', entries: {} };
|
|
64
|
-
return { schema: 1, rootKey: raw.rootKey, entries: raw.entries };
|
|
65
|
-
} catch {
|
|
66
|
-
return { schema: 1, rootKey: '', entries: {} };
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
export function saveIndex(dir: string, index: FingerprintIndex): void {
|
|
71
|
-
fsMod.mkdirSync(dir, { recursive: true, mode: 0o700 });
|
|
72
|
-
const target = path.join(dir, FILE);
|
|
73
|
-
const tmp = `${target}.tmp.${randomBytes(4).toString('hex')}`;
|
|
74
|
-
fsMod.writeFileSync(tmp, JSON.stringify(index), 'utf-8');
|
|
75
|
-
try {
|
|
76
|
-
fsMod.chmodSync(tmp, 0o600);
|
|
77
|
-
} catch {}
|
|
78
|
-
fsMod.renameSync(tmp, target);
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
export function probeIndex(rel: string, index: FingerprintIndex): FpEntry | null {
|
|
82
|
-
return index.entries[rel] ?? null;
|
|
83
|
-
}
|
package/src/host/sync/hashing.ts
DELETED
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
// src/host/hashing.ts — bounded streaming SHA-256 pool with deterministic order.
|
|
2
|
-
//
|
|
3
|
-
// Reads every file in ≤1 MiB chunks through createReadStream (never whole-file
|
|
4
|
-
// buffers), hashes with a bounded worker pool, and returns outcomes sorted by
|
|
5
|
-
// path so plan/revision output stays deterministic. Concurrency is capped by
|
|
6
|
-
// the caller's default of 4 and backpressure comes from the stream consumers.
|
|
7
|
-
import { createHash } from 'node:crypto';
|
|
8
|
-
import * as path from 'node:path';
|
|
9
|
-
|
|
10
|
-
export interface HashOutcome {
|
|
11
|
-
path: string;
|
|
12
|
-
sha256: string;
|
|
13
|
-
size: number;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
const CHUNK = 1024 * 1024;
|
|
17
|
-
|
|
18
|
-
export async function hashFiles(
|
|
19
|
-
fs: any,
|
|
20
|
-
root: string,
|
|
21
|
-
paths: readonly string[],
|
|
22
|
-
opts: { concurrency?: number; onFile?: (h: HashOutcome) => void } = {},
|
|
23
|
-
): Promise<HashOutcome[]> {
|
|
24
|
-
const concurrency = Math.max(1, opts.concurrency ?? 4);
|
|
25
|
-
const results: HashOutcome[] = [];
|
|
26
|
-
let next = 0;
|
|
27
|
-
const worker = async () => {
|
|
28
|
-
for (;;) {
|
|
29
|
-
const idx = next++;
|
|
30
|
-
if (idx >= paths.length) return;
|
|
31
|
-
const rel = paths[idx]!;
|
|
32
|
-
const full = path.join(root, rel);
|
|
33
|
-
const h = createHash('sha256');
|
|
34
|
-
let size = 0;
|
|
35
|
-
if (typeof fs.createReadStream === 'function') {
|
|
36
|
-
await new Promise<void>((resolve, reject) => {
|
|
37
|
-
const rs = fs.createReadStream(full, { highWaterMark: CHUNK });
|
|
38
|
-
rs.on('data', (chunk: Buffer) => {
|
|
39
|
-
h.update(chunk);
|
|
40
|
-
size += chunk.length;
|
|
41
|
-
});
|
|
42
|
-
rs.on('end', resolve);
|
|
43
|
-
rs.on('error', reject);
|
|
44
|
-
});
|
|
45
|
-
} else {
|
|
46
|
-
const data = fs.readFileSync(full);
|
|
47
|
-
h.update(data);
|
|
48
|
-
size = data.length;
|
|
49
|
-
}
|
|
50
|
-
const outcome: HashOutcome = { path: rel, sha256: h.digest('hex'), size };
|
|
51
|
-
results.push(outcome);
|
|
52
|
-
opts.onFile?.(outcome);
|
|
53
|
-
}
|
|
54
|
-
};
|
|
55
|
-
const workers = Array.from({ length: Math.min(concurrency, paths.length) }, () => worker());
|
|
56
|
-
await Promise.all(workers);
|
|
57
|
-
return results.sort((a, b) => a.path.localeCompare(b.path));
|
|
58
|
-
}
|
|
59
|
-
/**
|
|
60
|
-
* Hash wire paths that live under two different roots.
|
|
61
|
-
*
|
|
62
|
-
* After the store move `maestro-memory/...` is under the store root and `sessions/...`
|
|
63
|
-
* under the DSH home, so one `hashFiles(root, paths)` call cannot cover a mixed list.
|
|
64
|
-
* The wire path is restored on the way out, because every caller reports wire paths.
|
|
65
|
-
*/
|
|
66
|
-
export async function hashWirePaths(
|
|
67
|
-
fs: any,
|
|
68
|
-
roots: { storeRoot: string; localDsh: string },
|
|
69
|
-
wirePaths: string[],
|
|
70
|
-
opts: { onFile?: (h: HashOutcome) => void } = {},
|
|
71
|
-
): Promise<HashOutcome[]> {
|
|
72
|
-
const out: HashOutcome[] = [];
|
|
73
|
-
const groups = new Map<string, string[]>();
|
|
74
|
-
for (const wire of wirePaths) {
|
|
75
|
-
const root = wire.startsWith('maestro-memory/') ? roots.storeRoot : roots.localDsh;
|
|
76
|
-
const bucket = groups.get(root);
|
|
77
|
-
if (bucket) bucket.push(wire);
|
|
78
|
-
else groups.set(root, [wire]);
|
|
79
|
-
}
|
|
80
|
-
for (const [root, wires] of groups) {
|
|
81
|
-
const rel = wires.map((w) => (w.startsWith('maestro-memory/') ? w.slice('maestro-memory/'.length) : w));
|
|
82
|
-
const hashed = await hashFiles(fs, root, rel);
|
|
83
|
-
for (const entry of hashed) {
|
|
84
|
-
const wire = root === roots.storeRoot ? `maestro-memory/${entry.path}` : entry.path;
|
|
85
|
-
const outcome = { ...entry, path: wire };
|
|
86
|
-
opts.onFile?.(outcome as HashOutcome);
|
|
87
|
-
out.push(outcome as HashOutcome);
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
return out;
|
|
91
|
-
}
|