@ddtcorex/dsh-maestro-core 0.14.0 → 0.15.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.js +4 -125
- package/lib/debug-agent.js +2 -1
- package/lib/plugin.d.ts +1 -0
- package/lib/plugin.js +17 -4
- package/lib/resume.js +9 -1
- package/lib/sync/backup-service.d.ts +13 -0
- package/lib/sync/backup-service.js +60 -14
- package/lib/sync/hashing.d.ts +13 -0
- package/lib/sync/hashing.js +30 -0
- package/lib/sync/merge.d.ts +1 -1
- package/lib/sync/merge.js +1 -1
- package/lib/sync/remote-cache.js +1 -1
- package/lib/sync/remote-manifest.d.ts +12 -0
- package/lib/sync/remote-manifest.js +23 -1
- package/lib/sync/store-root.d.ts +44 -0
- package/lib/sync/store-root.js +67 -0
- package/lib/sync/sync-service.d.ts +27 -1
- package/lib/sync/sync-service.js +133 -13
- package/lib/sync/sync-types.d.ts +1 -1
- package/lib/sync/validation.d.ts +2 -0
- package/lib/sync/validation.js +15 -2
- package/lib/types/client/config/components/BrandMark.d.ts +1 -1
- package/lib/types/client/config/components/BrandMark.d.ts.map +1 -1
- package/lib/types/client/config/index.d.ts +0 -1
- package/lib/types/client/config/index.d.ts.map +1 -1
- package/lib/types/client/config/maestro-mark.d.ts +6 -16
- package/lib/types/client/config/maestro-mark.d.ts.map +1 -1
- package/lib/types/client/sync/index.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/client/config/components/BrandMark.tsx +0 -1
- package/src/client/config/index.tsx +5 -44
- package/src/client/config/maestro-mark.ts +6 -23
- package/src/client/sync/index.tsx +0 -50
- package/src/client/sync/ui.tsx +4 -4
- package/src/host/debug-agent.ts +2 -1
- package/src/host/plugin.ts +19 -5
- package/src/host/resume.ts +10 -1
- package/src/host/sync/backup-service.ts +67 -14
- package/src/host/sync/hashing.ts +34 -1
- package/src/host/sync/merge.ts +1 -1
- package/src/host/sync/remote-cache.ts +1 -1
- package/src/host/sync/remote-manifest.ts +22 -1
- package/src/host/sync/store-root.ts +83 -0
- package/src/host/sync/sync-service.ts +148 -13
- package/src/host/sync/sync-types.ts +1 -1
- package/src/host/sync/validation.ts +15 -2
- package/lib/types/client/config/settings-nav-icon.d.ts +0 -21
- package/lib/types/client/config/settings-nav-icon.d.ts.map +0 -1
- package/src/client/config/settings-nav-icon.ts +0 -68
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* sync/store-root.ts — where the memory store lives, resolved the same way the plugin
|
|
3
|
+
* resolves it.
|
|
4
|
+
*
|
|
5
|
+
* Core cannot import the plugin (separate package, separate release), so this is a
|
|
6
|
+
* deliberate second implementation. `tests/sync/store-root-parity.spec.ts` runs the
|
|
7
|
+
* shared fixture against it, and the plugin runs the same fixture against its own
|
|
8
|
+
* copy, so a rule change on one side fails on that side instead of drifting silently.
|
|
9
|
+
*
|
|
10
|
+
* The rules, in order:
|
|
11
|
+
* 1. `memoryDir` (explicit config) wins.
|
|
12
|
+
* 2. `MAESTRO_MEMORY_DIR` wins next.
|
|
13
|
+
* 3. A `DSH_HOME` that realpaths somewhere other than `<home>/.dsh` is an isolated run
|
|
14
|
+
* (dry-boot, test, second profile): the store stays inside it.
|
|
15
|
+
* 4. Otherwise the neutral root, `<home>/.maestro-memory`.
|
|
16
|
+
*/
|
|
17
|
+
import { realpathSync } from 'node:fs';
|
|
18
|
+
import { homedir } from 'node:os';
|
|
19
|
+
import { join } from 'node:path';
|
|
20
|
+
function realpathOr(value) {
|
|
21
|
+
try {
|
|
22
|
+
return realpathSync.native(value);
|
|
23
|
+
}
|
|
24
|
+
catch {
|
|
25
|
+
return value;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
export function resolveStoreRoot(opts = {}) {
|
|
29
|
+
if (opts.memoryDir)
|
|
30
|
+
return { root: opts.memoryDir, mode: 'configured' };
|
|
31
|
+
const env = opts.env ?? process.env;
|
|
32
|
+
const envDir = typeof env.MAESTRO_MEMORY_DIR === 'string' ? env.MAESTRO_MEMORY_DIR.trim() : '';
|
|
33
|
+
if (envDir)
|
|
34
|
+
return { root: envDir, mode: 'env' };
|
|
35
|
+
const home = realpathOr(opts.home ?? homedir());
|
|
36
|
+
const dshDefault = join(home, '.dsh');
|
|
37
|
+
const rawDsh = typeof env.DSH_HOME === 'string' && env.DSH_HOME.trim() ? env.DSH_HOME.trim() : '';
|
|
38
|
+
if (rawDsh && realpathOr(rawDsh) !== dshDefault) {
|
|
39
|
+
return { root: join(rawDsh, 'maestro-memory'), mode: 'isolated' };
|
|
40
|
+
}
|
|
41
|
+
return { root: join(home, '.maestro-memory'), mode: 'default' };
|
|
42
|
+
}
|
|
43
|
+
/** Map a wire path onto the local filesystem. Wire paths never change; roots do. */
|
|
44
|
+
export function localPathForWirePath(wirePath, roots) {
|
|
45
|
+
if (wirePath.startsWith('maestro-memory/')) {
|
|
46
|
+
return join(roots.storeRoot, wirePath.slice('maestro-memory/'.length));
|
|
47
|
+
}
|
|
48
|
+
return join(roots.localDsh, wirePath);
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Group wire paths by the local root they resolve to, so a caller that hashes or stats
|
|
52
|
+
* many paths at once hashes each group against its own root instead of assuming the
|
|
53
|
+
* DSH home. After the store move, `maestro-memory/...` and `sessions/...` live in two
|
|
54
|
+
* different trees.
|
|
55
|
+
*/
|
|
56
|
+
export function partitionByWireRoot(wirePaths, roots) {
|
|
57
|
+
const groups = new Map();
|
|
58
|
+
for (const wire of wirePaths) {
|
|
59
|
+
const root = wire.startsWith('maestro-memory/') ? roots.storeRoot : roots.localDsh;
|
|
60
|
+
const bucket = groups.get(root);
|
|
61
|
+
if (bucket)
|
|
62
|
+
bucket.push(wire);
|
|
63
|
+
else
|
|
64
|
+
groups.set(root, [wire]);
|
|
65
|
+
}
|
|
66
|
+
return [...groups.entries()].map(([root, paths]) => ({ root, paths }));
|
|
67
|
+
}
|
|
@@ -34,6 +34,8 @@ export interface StatusResult {
|
|
|
34
34
|
bothFiles: string[];
|
|
35
35
|
connection: ConnectionStatus;
|
|
36
36
|
remoteHost: string;
|
|
37
|
+
/** `legacy` means the local store still sits at an old root, so the counts are short. */
|
|
38
|
+
storeMigration?: 'ok' | 'legacy';
|
|
37
39
|
}
|
|
38
40
|
/** Cursor-paged status page for bounded RPC payloads (< 64 KiB). */
|
|
39
41
|
export interface StatusPage {
|
|
@@ -51,6 +53,8 @@ export interface PreviewResult extends SyncPreview {
|
|
|
51
53
|
}
|
|
52
54
|
export interface SyncServiceOpts {
|
|
53
55
|
localDsh?: string;
|
|
56
|
+
/** Resolved memory store root; defaults to the same rules the plugin uses. */
|
|
57
|
+
storeRoot?: string;
|
|
54
58
|
remote?: string;
|
|
55
59
|
remoteDsh?: string;
|
|
56
60
|
previewDir?: string;
|
|
@@ -61,6 +65,7 @@ export interface SyncServiceOpts {
|
|
|
61
65
|
}
|
|
62
66
|
export declare class SyncService {
|
|
63
67
|
localDsh: string;
|
|
68
|
+
storeRoot: string;
|
|
64
69
|
remote: string;
|
|
65
70
|
remoteDsh: string;
|
|
66
71
|
previewDir: string;
|
|
@@ -78,10 +83,17 @@ export declare class SyncService {
|
|
|
78
83
|
checkConnection(): Promise<ConnectionStatus>;
|
|
79
84
|
private requireConnection;
|
|
80
85
|
/**
|
|
81
|
-
* Local eligible files (
|
|
86
|
+
* Local eligible files (maestro-memory/*.md, maestro-memory/SUGGESTIONS.jsonl,
|
|
82
87
|
* sessions/<cwd-hash>/<id>/session.jsonl.zstd) as relative paths, sorted.
|
|
83
88
|
* Only content that matches the eligible contract is ever read or hashed.
|
|
84
89
|
*/
|
|
90
|
+
/** The two roots a wire path can resolve to. */
|
|
91
|
+
hashRoots(): {
|
|
92
|
+
storeRoot: string;
|
|
93
|
+
localDsh: string;
|
|
94
|
+
};
|
|
95
|
+
/** Map a wire path to its local file, through the resolved store root. */
|
|
96
|
+
localPathForWirePath(wirePath: string): string;
|
|
85
97
|
listLocalFiles(): string[];
|
|
86
98
|
/**
|
|
87
99
|
* Snapshot both sides with the manifest-first pipeline:
|
|
@@ -96,6 +108,20 @@ export declare class SyncService {
|
|
|
96
108
|
* re-hashed at write time (see apply), so a stale cache can never publish a
|
|
97
109
|
* wrong mutation target.
|
|
98
110
|
*/
|
|
111
|
+
/**
|
|
112
|
+
* The 4.0 rename moved the store root. A machine still on the old root would
|
|
113
|
+
* inventory zero memory files, which reads exactly like "nothing to sync".
|
|
114
|
+
* Refuse instead: the marker is written by the plugin's boot migration.
|
|
115
|
+
*/
|
|
116
|
+
private assertLocalStoreMigrated;
|
|
117
|
+
/**
|
|
118
|
+
* Refuse a peer that still keeps its store inside the DSH home.
|
|
119
|
+
*
|
|
120
|
+
* The wire paths are the same on both sides, so a mixed pair writes into a directory
|
|
121
|
+
* the upgraded machine no longer reads: the transfer succeeds and the memories are
|
|
122
|
+
* invisible. The marker is the only signal available before the transfer starts.
|
|
123
|
+
*/
|
|
124
|
+
assertPeerMoved(remotePaths: string[]): void;
|
|
99
125
|
private snapshotBoth;
|
|
100
126
|
/**
|
|
101
127
|
* Read-only preview: exact plan with copy/merge/skip/conflict and real added
|
package/lib/sync/sync-service.js
CHANGED
|
@@ -18,9 +18,15 @@ import * as path from 'node:path';
|
|
|
18
18
|
import * as os from 'node:os';
|
|
19
19
|
import { randomBytes } from 'node:crypto';
|
|
20
20
|
import { mergeDelimited } from './merge.js';
|
|
21
|
+
/**
|
|
22
|
+
* Hash a mixed list of wire paths, each group against the root it lives under.
|
|
23
|
+
* Before the store moved, one root covered everything; it no longer does, and hashing
|
|
24
|
+
* `maestro-memory/...` under the DSH home fails with ENOENT on the first memory file.
|
|
25
|
+
*/
|
|
26
|
+
import { localPathForWirePath, resolveStoreRoot } from './store-root.js';
|
|
21
27
|
import { mergeSessionBuffers } from './session-plan.js';
|
|
22
28
|
import { kindForPath } from './snapshot.js';
|
|
23
|
-
import {
|
|
29
|
+
import { hashWirePaths } from './hashing.js';
|
|
24
30
|
import { loadIndex, saveIndex, probeIndex, matchesStat, statFingerprint } from './fingerprint.js';
|
|
25
31
|
import { buildPlan, buildPreview, getPreview, getPreviewDirection, deletePreview, storePreview } from './sync-plan.js';
|
|
26
32
|
import { normalizeEligiblePath, validateRemoteTarget, validateHost } from './validation.js';
|
|
@@ -31,6 +37,7 @@ function syncFailure(phase, code, detail, path) {
|
|
|
31
37
|
}
|
|
32
38
|
export class SyncService {
|
|
33
39
|
localDsh;
|
|
40
|
+
storeRoot;
|
|
34
41
|
remote;
|
|
35
42
|
remoteDsh;
|
|
36
43
|
previewDir;
|
|
@@ -40,6 +47,14 @@ export class SyncService {
|
|
|
40
47
|
transport;
|
|
41
48
|
constructor(opts = {}) {
|
|
42
49
|
this.localDsh = opts.localDsh || process.env.DSH_HOME || path.join(os.homedir(), '.dsh');
|
|
50
|
+
// The store can live outside the DSH home. Wire paths stay `maestro-memory/...`,
|
|
51
|
+
// so every site that touches disk maps through this root, never through localDsh.
|
|
52
|
+
// A caller that pins `localDsh` pins the whole machine state, so the store is
|
|
53
|
+
// resolved against it: a temp home is isolated by construction, and production's
|
|
54
|
+
// own home is not, which is exactly the plugin's rule.
|
|
55
|
+
this.storeRoot =
|
|
56
|
+
opts.storeRoot ??
|
|
57
|
+
resolveStoreRoot({ env: { ...process.env, DSH_HOME: opts.localDsh ?? process.env.DSH_HOME } }).root;
|
|
43
58
|
this.remote = opts.remote || process.env.REMOTE_HOST || process.env.REMOTE || 'kai@ssh.ddtcorex.com';
|
|
44
59
|
this.remoteDsh = opts.remoteDsh || process.env.REMOTE_DSH_PATH || '~/.dsh';
|
|
45
60
|
// Sidecar preview store shared by every CLI process (preview -> separate apply run).
|
|
@@ -99,14 +114,36 @@ export class SyncService {
|
|
|
99
114
|
return connection;
|
|
100
115
|
}
|
|
101
116
|
/**
|
|
102
|
-
* Local eligible files (
|
|
117
|
+
* Local eligible files (maestro-memory/*.md, maestro-memory/SUGGESTIONS.jsonl,
|
|
103
118
|
* sessions/<cwd-hash>/<id>/session.jsonl.zstd) as relative paths, sorted.
|
|
104
119
|
* Only content that matches the eligible contract is ever read or hashed.
|
|
105
120
|
*/
|
|
121
|
+
/** The two roots a wire path can resolve to. */
|
|
122
|
+
hashRoots() {
|
|
123
|
+
return { storeRoot: this.storeRoot, localDsh: this.localDsh };
|
|
124
|
+
}
|
|
125
|
+
/** Map a wire path to its local file, through the resolved store root. */
|
|
126
|
+
localPathForWirePath(wirePath) {
|
|
127
|
+
return localPathForWirePath(wirePath, { storeRoot: this.storeRoot, localDsh: this.localDsh });
|
|
128
|
+
}
|
|
106
129
|
listLocalFiles() {
|
|
107
130
|
const root = this.localDsh;
|
|
131
|
+
// The store may live outside the DSH home, so its files are collected from the
|
|
132
|
+
// resolved root and labelled with the wire prefix. Sessions stay under the DSH
|
|
133
|
+
// home; they are harness data by definition.
|
|
134
|
+
const storeRootDiffers = this.storeRoot !== path.join(this.localDsh, 'maestro-memory');
|
|
108
135
|
const result = [];
|
|
109
136
|
const fsMod = this.fs;
|
|
137
|
+
/** Walk `dir` and return the wire paths it holds, without touching `result`. */
|
|
138
|
+
const collect = (dir, base) => {
|
|
139
|
+
const out = [];
|
|
140
|
+
void out;
|
|
141
|
+
const sink = [];
|
|
142
|
+
const previous = result.length;
|
|
143
|
+
walk(dir, base);
|
|
144
|
+
sink.push(...result.splice(previous));
|
|
145
|
+
return sink;
|
|
146
|
+
};
|
|
110
147
|
const walk = (dir, base) => {
|
|
111
148
|
try {
|
|
112
149
|
if (typeof fsMod.readdirSync !== 'function')
|
|
@@ -152,7 +189,22 @@ export class SyncService {
|
|
|
152
189
|
catch {
|
|
153
190
|
return [];
|
|
154
191
|
}
|
|
155
|
-
|
|
192
|
+
if (!storeRootDiffers) {
|
|
193
|
+
// Store inside the DSH home: one walk covers everything, exactly as before.
|
|
194
|
+
walk(root, '');
|
|
195
|
+
}
|
|
196
|
+
else {
|
|
197
|
+
// Store elsewhere: walk the DSH home for sessions and harness state, skipping the
|
|
198
|
+
// path the store would occupy, then walk the store itself under its wire prefix.
|
|
199
|
+
const harnessOwned = collect(root, '');
|
|
200
|
+
for (const wire of harnessOwned) {
|
|
201
|
+
const normalised = wire.split(path.sep).join('/');
|
|
202
|
+
if (normalised === 'maestro-memory' || normalised.startsWith('maestro-memory/'))
|
|
203
|
+
continue;
|
|
204
|
+
result.push(wire);
|
|
205
|
+
}
|
|
206
|
+
result.push(...collect(this.storeRoot, 'maestro-memory'));
|
|
207
|
+
}
|
|
156
208
|
return [...new Set(result
|
|
157
209
|
.map((p) => p.split(path.sep).join('/'))
|
|
158
210
|
.filter((p) => {
|
|
@@ -178,7 +230,65 @@ export class SyncService {
|
|
|
178
230
|
* re-hashed at write time (see apply), so a stale cache can never publish a
|
|
179
231
|
* wrong mutation target.
|
|
180
232
|
*/
|
|
233
|
+
/**
|
|
234
|
+
* The 4.0 rename moved the store root. A machine still on the old root would
|
|
235
|
+
* inventory zero memory files, which reads exactly like "nothing to sync".
|
|
236
|
+
* Refuse instead: the marker is written by the plugin's boot migration.
|
|
237
|
+
*/
|
|
238
|
+
assertLocalStoreMigrated() {
|
|
239
|
+
const probe = this.fs?.existsSync;
|
|
240
|
+
if (typeof probe !== 'function')
|
|
241
|
+
return;
|
|
242
|
+
const current = this.storeRoot;
|
|
243
|
+
const legacy = path.join(this.localDsh, 'dsh-maestro-memory');
|
|
244
|
+
const v4 = path.join(this.localDsh, 'maestro-memory');
|
|
245
|
+
let currentExists = false;
|
|
246
|
+
let legacyExists = false;
|
|
247
|
+
try {
|
|
248
|
+
currentExists = probe.call(this.fs, current);
|
|
249
|
+
legacyExists = probe.call(this.fs, legacy);
|
|
250
|
+
}
|
|
251
|
+
catch {
|
|
252
|
+
return;
|
|
253
|
+
}
|
|
254
|
+
// Only the half-migrated shape is refused: the old root is still there and
|
|
255
|
+
// the new one is absent. A fresh DSH_HOME has neither, and a migrated one
|
|
256
|
+
// has the new root, so both stay usable.
|
|
257
|
+
// A store still at a legacy root would inventory zero files through the new root,
|
|
258
|
+
// which reads exactly like "nothing to sync". Refuse instead.
|
|
259
|
+
let v4Exists = false;
|
|
260
|
+
try {
|
|
261
|
+
v4Exists = current !== v4 && probe.call(this.fs, v4);
|
|
262
|
+
}
|
|
263
|
+
catch { }
|
|
264
|
+
if (!currentExists && legacyExists) {
|
|
265
|
+
throw syncFailure('snapshot', 'STORE_NOT_MIGRATED', `local store is still at ${legacy}; run the current build on this machine (its boot migration moves it) before syncing`);
|
|
266
|
+
}
|
|
267
|
+
if (!currentExists && v4Exists) {
|
|
268
|
+
throw syncFailure('snapshot', 'STORE_NOT_MIGRATED', `local store is still at ${v4}; install the current build (its boot migration moves it to ${current}) before syncing`);
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
/**
|
|
272
|
+
* Refuse a peer that still keeps its store inside the DSH home.
|
|
273
|
+
*
|
|
274
|
+
* The wire paths are the same on both sides, so a mixed pair writes into a directory
|
|
275
|
+
* the upgraded machine no longer reads: the transfer succeeds and the memories are
|
|
276
|
+
* invisible. The marker is the only signal available before the transfer starts.
|
|
277
|
+
*/
|
|
278
|
+
assertPeerMoved(remotePaths) {
|
|
279
|
+
// Only meaningful once this machine has moved: while our own store still sits inside
|
|
280
|
+
// the DSH home, the peer's layout is the one that matches and there is nothing to
|
|
281
|
+
// protect against.
|
|
282
|
+
if (this.storeRoot === path.join(this.localDsh, 'maestro-memory'))
|
|
283
|
+
return;
|
|
284
|
+
const hasMemory = remotePaths.some((p) => p.startsWith('maestro-memory/'));
|
|
285
|
+
const hasMarker = remotePaths.includes('maestro-memory/.maestro-memory/migrated-v5.json');
|
|
286
|
+
if (hasMemory && !hasMarker) {
|
|
287
|
+
throw syncFailure('snapshot', 'PEER_NOT_MOVED', `the peer ${this.remote ?? 'unknown'} still keeps its store inside its DSH home (memory files present, no migrated-v5.json marker); upgrade maestro-memory on that machine and restart it before syncing`);
|
|
288
|
+
}
|
|
289
|
+
}
|
|
181
290
|
async snapshotBoth(opts = {}) {
|
|
291
|
+
this.assertLocalStoreMigrated();
|
|
182
292
|
const progress = (phase, current, total, file) => opts.onProgress?.({ phase, current, total, file });
|
|
183
293
|
const stop = () => {
|
|
184
294
|
if (opts.shouldStop?.())
|
|
@@ -188,11 +298,12 @@ export class SyncService {
|
|
|
188
298
|
const fsMod = this.fs;
|
|
189
299
|
const target = await this.requireTarget();
|
|
190
300
|
stop();
|
|
191
|
-
// Scope filter: 'memory' covers
|
|
301
|
+
// Scope filter: 'memory' covers maestro-memory only and skips the
|
|
192
302
|
// live session logs; undefined/'all' preserves the legacy full inventory.
|
|
193
303
|
const inScope = (p) => opts.scope !== 'memory' || !p.startsWith('sessions/');
|
|
194
304
|
const localPaths = this.listLocalFiles().filter(inScope);
|
|
195
305
|
const remoteManifest = (await this.transport.manifest(target)).filter((e) => inScope(e.path));
|
|
306
|
+
this.assertPeerMoved(remoteManifest.map((e) => e.path));
|
|
196
307
|
stop();
|
|
197
308
|
const remoteSnapshots = remoteManifest.map((e) => ({ path: e.path, sha256: e.sha256, size: e.size, kind: kindForPath(e.path) }));
|
|
198
309
|
const remoteSet = new Set(remoteManifest.map((e) => e.path));
|
|
@@ -204,7 +315,7 @@ export class SyncService {
|
|
|
204
315
|
const entry = probeIndex(p, index);
|
|
205
316
|
let st = null;
|
|
206
317
|
try {
|
|
207
|
-
st = typeof fsMod.statSync === 'function' ? fsMod.statSync(
|
|
318
|
+
st = typeof fsMod.statSync === 'function' ? fsMod.statSync(this.localPathForWirePath(p), { bigint: true }) : null;
|
|
208
319
|
}
|
|
209
320
|
catch {
|
|
210
321
|
st = null;
|
|
@@ -217,7 +328,7 @@ export class SyncService {
|
|
|
217
328
|
}
|
|
218
329
|
}
|
|
219
330
|
let hashedCount = 0;
|
|
220
|
-
const staleHashes = await
|
|
331
|
+
const staleHashes = await hashWirePaths(fsMod, this.hashRoots(), stale, {
|
|
221
332
|
onFile: (h) => {
|
|
222
333
|
hashedCount++;
|
|
223
334
|
progress('hashing', hashedCount, stale.length, h.path);
|
|
@@ -227,7 +338,7 @@ export class SyncService {
|
|
|
227
338
|
for (const h of staleHashes) {
|
|
228
339
|
localSnapshots.push({ path: h.path, sha256: h.sha256, size: h.size, kind: kindForPath(h.path) });
|
|
229
340
|
try {
|
|
230
|
-
const st = typeof fsMod.statSync === 'function' ? fsMod.statSync(
|
|
341
|
+
const st = typeof fsMod.statSync === 'function' ? fsMod.statSync(this.localPathForWirePath(h.path), { bigint: true }) : null;
|
|
231
342
|
if (st)
|
|
232
343
|
index.entries[h.path] = { ...statFingerprint(st), sha256: h.sha256 };
|
|
233
344
|
}
|
|
@@ -256,7 +367,7 @@ export class SyncService {
|
|
|
256
367
|
if (localContents.has(rel))
|
|
257
368
|
return localContents.get(rel);
|
|
258
369
|
try {
|
|
259
|
-
const d = fsMod.readFileSync(
|
|
370
|
+
const d = fsMod.readFileSync(this.localPathForWirePath(rel));
|
|
260
371
|
const buf = Buffer.isBuffer(d) ? Buffer.from(d) : Buffer.from(String(d), 'utf-8');
|
|
261
372
|
localContents.set(rel, buf);
|
|
262
373
|
return buf;
|
|
@@ -568,7 +679,7 @@ export class SyncService {
|
|
|
568
679
|
else {
|
|
569
680
|
buf = this.mergeBuffer(act, localContents, remoteContents, 'pull');
|
|
570
681
|
}
|
|
571
|
-
await this.atomicWriteWithBackup(
|
|
682
|
+
await this.atomicWriteWithBackup(this.localPathForWirePath(act.path), buf);
|
|
572
683
|
committed.push(act.path);
|
|
573
684
|
}
|
|
574
685
|
catch (e) {
|
|
@@ -702,7 +813,7 @@ export class SyncService {
|
|
|
702
813
|
const entry = probeIndex(p, index);
|
|
703
814
|
let st = null;
|
|
704
815
|
try {
|
|
705
|
-
st = typeof fsMod.statSync === 'function' ? fsMod.statSync(
|
|
816
|
+
st = typeof fsMod.statSync === 'function' ? fsMod.statSync(this.localPathForWirePath(p), { bigint: true }) : null;
|
|
706
817
|
}
|
|
707
818
|
catch {
|
|
708
819
|
st = null;
|
|
@@ -714,7 +825,7 @@ export class SyncService {
|
|
|
714
825
|
}
|
|
715
826
|
if (stale.length > 0) {
|
|
716
827
|
let i = 0;
|
|
717
|
-
const hashed = await
|
|
828
|
+
const hashed = await hashWirePaths(fsMod, this.hashRoots(), stale, {
|
|
718
829
|
onFile: (h) => {
|
|
719
830
|
i++;
|
|
720
831
|
onProgress?.(i, stale.length, h.path);
|
|
@@ -723,7 +834,7 @@ export class SyncService {
|
|
|
723
834
|
for (const h of hashed) {
|
|
724
835
|
out.set(h.path, h.sha256);
|
|
725
836
|
try {
|
|
726
|
-
const st = typeof fsMod.statSync === 'function' ? fsMod.statSync(
|
|
837
|
+
const st = typeof fsMod.statSync === 'function' ? fsMod.statSync(this.localPathForWirePath(h.path), { bigint: true }) : null;
|
|
727
838
|
if (st)
|
|
728
839
|
index.entries[h.path] = { ...statFingerprint(st), sha256: h.sha256 };
|
|
729
840
|
}
|
|
@@ -735,10 +846,19 @@ export class SyncService {
|
|
|
735
846
|
return out;
|
|
736
847
|
}
|
|
737
848
|
async status() {
|
|
849
|
+
// A legacy store inventories zero memory files, which reads as "nothing to sync".
|
|
850
|
+
// The count stays honest, and the reason travels with it.
|
|
851
|
+
let storeMigration = 'ok';
|
|
852
|
+
try {
|
|
853
|
+
this.assertLocalStoreMigrated();
|
|
854
|
+
}
|
|
855
|
+
catch {
|
|
856
|
+
storeMigration = 'legacy';
|
|
857
|
+
}
|
|
738
858
|
const connection = await this.checkConnection();
|
|
739
859
|
const localFiles = this.listLocalFiles();
|
|
740
860
|
if (!connection.ok) {
|
|
741
|
-
return { localOnly: localFiles.length, remoteOnly: 0, both: 0, localOnlyFiles: localFiles, remoteOnlyFiles: [], bothFiles: [], connection, remoteHost: this.remote };
|
|
861
|
+
return { localOnly: localFiles.length, remoteOnly: 0, both: 0, localOnlyFiles: localFiles, remoteOnlyFiles: [], bothFiles: [], connection, remoteHost: this.remote, storeMigration };
|
|
742
862
|
}
|
|
743
863
|
let remoteFiles = [];
|
|
744
864
|
try {
|
package/lib/sync/sync-types.d.ts
CHANGED
|
@@ -83,5 +83,5 @@ export interface ApplyRequest {
|
|
|
83
83
|
direction: SyncDirection;
|
|
84
84
|
confirm: true;
|
|
85
85
|
}
|
|
86
|
-
/** Inventory scope: 'memory' covers
|
|
86
|
+
/** Inventory scope: 'memory' covers maestro-memory only, 'all' adds sessions/. */
|
|
87
87
|
export type SyncScope = 'memory' | 'all';
|
package/lib/sync/validation.d.ts
CHANGED
|
@@ -2,6 +2,8 @@ import type { RemoteTarget } from './sync-types.js';
|
|
|
2
2
|
export declare const HOST_RE: RegExp;
|
|
3
3
|
export declare const ABSOLUTE_RE: RegExp;
|
|
4
4
|
export declare const ELIGIBLE_RE: RegExp;
|
|
5
|
+
/** True when a wire path is eligible, without throwing at the caller. */
|
|
6
|
+
export declare function isEligiblePath(value: string): boolean;
|
|
5
7
|
export declare const HOST: RegExp;
|
|
6
8
|
export declare const ABSOLUTE: RegExp;
|
|
7
9
|
export declare const ELIGIBLE: RegExp;
|
package/lib/sync/validation.js
CHANGED
|
@@ -1,6 +1,19 @@
|
|
|
1
1
|
export const HOST_RE = /^(?!-)[A-Za-z0-9._@:-]+$/;
|
|
2
2
|
export const ABSOLUTE_RE = /^\/(?:[A-Za-z0-9._-]+\/)*[A-Za-z0-9._-]+$/;
|
|
3
|
-
|
|
3
|
+
// `migrated-v5.json` is the store-move marker: a peer that carries it has moved its
|
|
4
|
+
// store out of the DSH home. Sync needs to see it to refuse a half-upgraded pair instead
|
|
5
|
+
// of publishing into a directory the peer no longer reads.
|
|
6
|
+
export const ELIGIBLE_RE = /^(?:maestro-memory\/(?!.*\.bak\.)[A-Za-z0-9._\/-]+\.md|maestro-memory\/SUGGESTIONS\.jsonl|maestro-memory\/\.maestro-memory\/migrated-v5\.json|sessions\/[A-Za-z0-9._-]+\/[A-Za-z0-9._-]+\/session\.jsonl\.zstd|sessions\/[A-Za-z0-9._\/-]+\.jsonl\.zstd)$/;
|
|
7
|
+
/** True when a wire path is eligible, without throwing at the caller. */
|
|
8
|
+
export function isEligiblePath(value) {
|
|
9
|
+
try {
|
|
10
|
+
normalizeEligiblePath(value);
|
|
11
|
+
return true;
|
|
12
|
+
}
|
|
13
|
+
catch {
|
|
14
|
+
return false;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
4
17
|
// Backwards-compatible aliases required by spec
|
|
5
18
|
export const HOST = HOST_RE;
|
|
6
19
|
export const ABSOLUTE = ABSOLUTE_RE;
|
|
@@ -65,7 +78,7 @@ export function normalizeEligiblePath(value) {
|
|
|
65
78
|
throw new Error(`ineligible path: contains control characters: ${JSON.stringify(value)}`);
|
|
66
79
|
}
|
|
67
80
|
if (value.includes('..')) {
|
|
68
|
-
// traversal not allowed at all; eligible paths are strictly under
|
|
81
|
+
// traversal not allowed at all; eligible paths are strictly under maestro-memory/ or sessions/
|
|
69
82
|
// The ELIGIBLE regex would reject it anyway, but be explicit
|
|
70
83
|
throw new Error(`ineligible path: traversal: ${JSON.stringify(value)}`);
|
|
71
84
|
}
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
* (`bg-base #fff`) and dark (`bg-base #121212`) — a token-only
|
|
28
28
|
* background can resolve to near-white on some dark tokens.
|
|
29
29
|
*/
|
|
30
|
-
export { MAESTRO_BRAND_TILE, MAESTRO_MARK_PATH, MAESTRO_MARK_STROKE_WIDTH, MAESTRO_MARK_VIEWBOX,
|
|
30
|
+
export { MAESTRO_BRAND_TILE, MAESTRO_MARK_PATH, MAESTRO_MARK_STROKE_WIDTH, MAESTRO_MARK_VIEWBOX, } from '../maestro-mark.js';
|
|
31
31
|
/**
|
|
32
32
|
* Keys a call site may override on the badge. POSITIONING ONLY — the tile's
|
|
33
33
|
* colour, border, shadow, radius and size are the brand and are not negotiable.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BrandMark.d.ts","sourceRoot":"","sources":["../../../../../src/client/config/components/BrandMark.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AAcH,OAAO,EACL,kBAAkB,EAClB,iBAAiB,EACjB,yBAAyB,EACzB,oBAAoB,
|
|
1
|
+
{"version":3,"file":"BrandMark.d.ts","sourceRoot":"","sources":["../../../../../src/client/config/components/BrandMark.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AAcH,OAAO,EACL,kBAAkB,EAClB,iBAAiB,EACjB,yBAAyB,EACzB,oBAAoB,GACrB,MAAM,oBAAoB,CAAA;AAE3B;;;;;GAKG;AACH,eAAO,MAAM,uBAAuB,4FAE1B,CAAA;AAEV,KAAK,eAAe,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC,OAAO,uBAAuB,CAAC,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC,CAAC,CAAA;AAWzF,wBAAgB,WAAW,CAAC,KAAK,EAAE;IAAE,IAAI,CAAC,EAAE,MAAM,CAAA;CAAE,mCAKnD;AAED;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE;IAAE,IAAI,CAAC,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,eAAe,CAAA;CAAE,8DAa5G"}
|
|
@@ -12,7 +12,6 @@
|
|
|
12
12
|
export declare const MAESTRO_SETTINGS_ORDER = 26;
|
|
13
13
|
interface ClientCtx {
|
|
14
14
|
get?(name: string): unknown;
|
|
15
|
-
effect(fn: () => () => void, label?: string): unknown;
|
|
16
15
|
}
|
|
17
16
|
export declare const inject: readonly ["slots", "connection"];
|
|
18
17
|
export declare function apply(ctx: ClientCtx): void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/client/config/index.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,eAAO,MAAM,sBAAsB,KAAK,CAAA;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/client/config/index.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,eAAO,MAAM,sBAAsB,KAAK,CAAA;AAsBxC,UAAU,SAAS;IACjB,GAAG,CAAC,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAA;CAC5B;AAED,eAAO,MAAM,MAAM,kCAAmC,CAAA;AAEtD,wBAAgB,KAAK,CAAC,GAAG,EAAE,SAAS,GAAG,IAAI,CA8B1C"}
|
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Maestro M logo — the react-free half of the reference implementation.
|
|
3
3
|
*
|
|
4
|
-
* Split out from `components/BrandMark.tsx` so the glyph declaration
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
* `tests/brand-mark.spec.ts` can assert the exact URI bytes.
|
|
4
|
+
* Split out from `components/BrandMark.tsx` so the glyph declaration is
|
|
5
|
+
* importable from a test: `BrandMark.tsx` imports react, which the client
|
|
6
|
+
* bundler treats as an EXTERNAL with no entry in this package's `package.json`,
|
|
7
|
+
* so it cannot be imported from vitest at all. This module has no react import,
|
|
8
|
+
* so `tests/brand-mark.spec.ts` can still read the declarations a caller builds
|
|
9
|
+
* its glyph from.
|
|
11
10
|
*
|
|
12
11
|
* The path itself is duplicated in other Maestro packages and that duplication
|
|
13
12
|
* is structural — see the header in `components/BrandMark.tsx`.
|
|
@@ -17,13 +16,4 @@ export declare const MAESTRO_MARK_VIEWBOX = "0 0 16 16";
|
|
|
17
16
|
export declare const MAESTRO_MARK_STROKE_WIDTH = 1.6;
|
|
18
17
|
/** Badge tile colour — part of the house pattern documented in AGENTS.md. */
|
|
19
18
|
export declare const MAESTRO_BRAND_TILE = "#0A84FF";
|
|
20
|
-
/**
|
|
21
|
-
* The exact data-URI the settings-nav row paints as a `currentColor` mask.
|
|
22
|
-
*
|
|
23
|
-
* Only `<` and `>` are encoded. `encodeURIComponent` would additionally escape
|
|
24
|
-
* quotes, slashes and spaces, producing a different URI than the literal this
|
|
25
|
-
* replaces — and the row renders through `mask`, so a subtly different URI can
|
|
26
|
-
* leave the glyph blank. `tests/brand-mark.spec.ts` pins the bytes.
|
|
27
|
-
*/
|
|
28
|
-
export declare function maestroMarkMaskUri(): string;
|
|
29
19
|
//# sourceMappingURL=maestro-mark.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"maestro-mark.d.ts","sourceRoot":"","sources":["../../../../src/client/config/maestro-mark.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"maestro-mark.d.ts","sourceRoot":"","sources":["../../../../src/client/config/maestro-mark.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,eAAO,MAAM,iBAAiB,iCAAiC,CAAA;AAC/D,eAAO,MAAM,oBAAoB,cAAc,CAAA;AAC/C,eAAO,MAAM,yBAAyB,MAAM,CAAA;AAE5C,6EAA6E;AAC7E,eAAO,MAAM,kBAAkB,YAAY,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/client/sync/index.tsx"],"names":[],"mappings":"AAUA,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAE1C,eAAO,MAAM,MAAM,kCAAmC,CAAA;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/client/sync/index.tsx"],"names":[],"mappings":"AAUA,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAE1C,eAAO,MAAM,MAAM,kCAAmC,CAAA;AA0PtD,iBAAS,KAAK,CAAC,GAAG,EAAE,GAAG,GAAG,IAAI,CAmB7B;AAED,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,CAAA;;;;;AAE3B,wBAAgC"}
|
package/package.json
CHANGED
|
@@ -13,37 +13,14 @@ export const MAESTRO_SETTINGS_ORDER = 26
|
|
|
13
13
|
|
|
14
14
|
// DSH-native redesign — reuses DSH tokens & primitive geometry maximally (see MaestroSettings.tsx).
|
|
15
15
|
import { MaestroSettingsTab } from './MaestroSettings.js'
|
|
16
|
-
import { registerSettingsNavIcon, SETTINGS_NAV_MARKER } from './settings-nav-icon.js'
|
|
17
|
-
import { maestroMarkMaskUri } from './components/BrandMark.js'
|
|
18
16
|
|
|
19
17
|
/**
|
|
20
|
-
* DSH 0.
|
|
21
|
-
*
|
|
22
|
-
* the marker
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
* declared once in components/BrandMark.tsx — the workspace reference
|
|
26
|
-
* implementation.
|
|
18
|
+
* The nav row keeps the shell's default gear. DSH 0.2.x paints a section row
|
|
19
|
+
* through the settings.section.icon slot: the glyph sits inside a wrapping
|
|
20
|
+
* span, so the 0.1.x marker + `::before` mask this plugin used to carry hid
|
|
21
|
+
* nothing and painted a second glyph beside the gear. A custom row icon is a
|
|
22
|
+
* slot registration, not a DOM rewrite, and no Maestro section asks for one.
|
|
27
23
|
*/
|
|
28
|
-
const SETTINGS_NAV_CSS = `
|
|
29
|
-
|
|
30
|
-
/* maestro: replace the settings-nav fallback gear with the Maestro M-logo glyph — same mark as components/BrandMark.tsx */
|
|
31
|
-
[${SETTINGS_NAV_MARKER}] > svg:first-child,
|
|
32
|
-
[${SETTINGS_NAV_MARKER}] > svg.zWKi1a_navIcon {
|
|
33
|
-
display: none !important;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
[${SETTINGS_NAV_MARKER}]::before {
|
|
37
|
-
content: '';
|
|
38
|
-
flex: none;
|
|
39
|
-
width: 16px;
|
|
40
|
-
height: 16px;
|
|
41
|
-
display: inline-block;
|
|
42
|
-
background: currentColor;
|
|
43
|
-
-webkit-mask: url("${maestroMarkMaskUri()}") center / contain no-repeat;
|
|
44
|
-
mask: url("${maestroMarkMaskUri()}") center / contain no-repeat;
|
|
45
|
-
}
|
|
46
|
-
`
|
|
47
24
|
|
|
48
25
|
type SlotsApi = {
|
|
49
26
|
inject(name: string, factory: () => unknown): void
|
|
@@ -56,22 +33,10 @@ type RpcCall = (endpoint: string, payload?: unknown, signal?: AbortSignal) => Pr
|
|
|
56
33
|
|
|
57
34
|
interface ClientCtx {
|
|
58
35
|
get?(name: string): unknown
|
|
59
|
-
effect(fn: () => () => void, label?: string): unknown
|
|
60
36
|
}
|
|
61
37
|
|
|
62
38
|
export const inject = ['slots', 'connection'] as const
|
|
63
39
|
|
|
64
|
-
function installNavIconStyle(): () => void {
|
|
65
|
-
const tag = document.createElement('style')
|
|
66
|
-
tag.dataset.plugin = '@ddtcorex/dsh-maestro-config'
|
|
67
|
-
tag.dataset.pluginCss = 'maestro/settings-nav.css'
|
|
68
|
-
tag.textContent = SETTINGS_NAV_CSS
|
|
69
|
-
document.head.appendChild(tag)
|
|
70
|
-
return () => {
|
|
71
|
-
document.querySelector('style[data-plugin-css="maestro/settings-nav.css"]')?.remove()
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
|
|
75
40
|
export function apply(ctx: ClientCtx): void {
|
|
76
41
|
const slots = ctx.get?.('slots') as SlotsApi | undefined
|
|
77
42
|
if (slots === undefined) return
|
|
@@ -96,10 +61,6 @@ export function apply(ctx: ClientCtx): void {
|
|
|
96
61
|
return connection.rpc.call('/dsh-maestro-supervisor-resume', endpoint, payload, signal)
|
|
97
62
|
}
|
|
98
63
|
|
|
99
|
-
// Reversible effects: nav-row marker observer + owned style tag.
|
|
100
|
-
ctx.effect(() => registerSettingsNavIcon(() => 'Maestro'), 'maestro: settings nav icon')
|
|
101
|
-
ctx.effect(installNavIconStyle, 'maestro: settings nav css')
|
|
102
|
-
|
|
103
64
|
slots.inject('settings.section', () =>
|
|
104
65
|
slots.register(
|
|
105
66
|
{ name: 'settings.section', id: 'maestro', order: MAESTRO_SETTINGS_ORDER, label: () => 'Maestro', inject: () => ({ configRpcCall, supervisorRpcCall }) },
|