@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
|
@@ -18,9 +18,17 @@ 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
|
+
/**
|
|
23
|
+
* Hash a mixed list of wire paths, each group against the root it lives under.
|
|
24
|
+
* Before the store moved, one root covered everything; it no longer does, and hashing
|
|
25
|
+
* `maestro-memory/...` under the DSH home fails with ENOENT on the first memory file.
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
import { localPathForWirePath, resolveStoreRoot } from './store-root.js';
|
|
21
29
|
import { mergeSessionBuffers } from './session-plan.js';
|
|
22
30
|
import { kindForPath } from './snapshot.js';
|
|
23
|
-
import { hashFiles } from './hashing.js';
|
|
31
|
+
import { hashFiles, hashWirePaths } from './hashing.js';
|
|
24
32
|
import { loadIndex, saveIndex, probeIndex, matchesStat, statFingerprint } from './fingerprint.js';
|
|
25
33
|
import type { RemoteManifestEntry } from './remote-manifest.js';
|
|
26
34
|
import { buildPlan, buildPreview, getPreview, getPreviewDirection, deletePreview, storePreview } from './sync-plan.js';
|
|
@@ -66,6 +74,8 @@ export interface StatusResult {
|
|
|
66
74
|
bothFiles: string[];
|
|
67
75
|
connection: ConnectionStatus;
|
|
68
76
|
remoteHost: string;
|
|
77
|
+
/** `legacy` means the local store still sits at an old root, so the counts are short. */
|
|
78
|
+
storeMigration?: 'ok' | 'legacy';
|
|
69
79
|
}
|
|
70
80
|
|
|
71
81
|
/** Cursor-paged status page for bounded RPC payloads (< 64 KiB). */
|
|
@@ -86,6 +96,8 @@ export interface PreviewResult extends SyncPreview {
|
|
|
86
96
|
|
|
87
97
|
export interface SyncServiceOpts {
|
|
88
98
|
localDsh?: string;
|
|
99
|
+
/** Resolved memory store root; defaults to the same rules the plugin uses. */
|
|
100
|
+
storeRoot?: string;
|
|
89
101
|
remote?: string;
|
|
90
102
|
remoteDsh?: string;
|
|
91
103
|
previewDir?: string;
|
|
@@ -101,6 +113,7 @@ function syncFailure(phase: SyncFailure['phase'], code: string, detail: string,
|
|
|
101
113
|
|
|
102
114
|
export class SyncService {
|
|
103
115
|
localDsh: string;
|
|
116
|
+
storeRoot: string;
|
|
104
117
|
remote: string;
|
|
105
118
|
remoteDsh: string;
|
|
106
119
|
previewDir: string;
|
|
@@ -111,6 +124,14 @@ export class SyncService {
|
|
|
111
124
|
|
|
112
125
|
constructor(opts: SyncServiceOpts = {}) {
|
|
113
126
|
this.localDsh = opts.localDsh || process.env.DSH_HOME || path.join(os.homedir(), '.dsh');
|
|
127
|
+
// The store can live outside the DSH home. Wire paths stay `maestro-memory/...`,
|
|
128
|
+
// so every site that touches disk maps through this root, never through localDsh.
|
|
129
|
+
// A caller that pins `localDsh` pins the whole machine state, so the store is
|
|
130
|
+
// resolved against it: a temp home is isolated by construction, and production's
|
|
131
|
+
// own home is not, which is exactly the plugin's rule.
|
|
132
|
+
this.storeRoot =
|
|
133
|
+
opts.storeRoot ??
|
|
134
|
+
resolveStoreRoot({ env: { ...process.env, DSH_HOME: opts.localDsh ?? process.env.DSH_HOME } }).root;
|
|
114
135
|
this.remote = opts.remote || process.env.REMOTE_HOST || process.env.REMOTE || 'kai@ssh.ddtcorex.com';
|
|
115
136
|
this.remoteDsh = opts.remoteDsh || process.env.REMOTE_DSH_PATH || '~/.dsh';
|
|
116
137
|
// Sidecar preview store shared by every CLI process (preview -> separate apply run).
|
|
@@ -171,14 +192,38 @@ export class SyncService {
|
|
|
171
192
|
}
|
|
172
193
|
|
|
173
194
|
/**
|
|
174
|
-
* Local eligible files (
|
|
195
|
+
* Local eligible files (maestro-memory/*.md, maestro-memory/SUGGESTIONS.jsonl,
|
|
175
196
|
* sessions/<cwd-hash>/<id>/session.jsonl.zstd) as relative paths, sorted.
|
|
176
197
|
* Only content that matches the eligible contract is ever read or hashed.
|
|
177
198
|
*/
|
|
199
|
+
/** The two roots a wire path can resolve to. */
|
|
200
|
+
hashRoots(): { storeRoot: string; localDsh: string } {
|
|
201
|
+
return { storeRoot: this.storeRoot, localDsh: this.localDsh };
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
/** Map a wire path to its local file, through the resolved store root. */
|
|
205
|
+
localPathForWirePath(wirePath: string): string {
|
|
206
|
+
return localPathForWirePath(wirePath, { storeRoot: this.storeRoot, localDsh: this.localDsh });
|
|
207
|
+
}
|
|
208
|
+
|
|
178
209
|
listLocalFiles(): string[] {
|
|
179
210
|
const root = this.localDsh;
|
|
211
|
+
// The store may live outside the DSH home, so its files are collected from the
|
|
212
|
+
// resolved root and labelled with the wire prefix. Sessions stay under the DSH
|
|
213
|
+
// home; they are harness data by definition.
|
|
214
|
+
const storeRootDiffers = this.storeRoot !== path.join(this.localDsh, 'maestro-memory');
|
|
180
215
|
const result: string[] = [];
|
|
181
216
|
const fsMod = this.fs;
|
|
217
|
+
/** Walk `dir` and return the wire paths it holds, without touching `result`. */
|
|
218
|
+
const collect = (dir: string, base: string): string[] => {
|
|
219
|
+
const out: Array<{ push: (...items: string[]) => number }> = [];
|
|
220
|
+
void out;
|
|
221
|
+
const sink: string[] = [];
|
|
222
|
+
const previous = result.length;
|
|
223
|
+
walk(dir, base);
|
|
224
|
+
sink.push(...result.splice(previous));
|
|
225
|
+
return sink;
|
|
226
|
+
};
|
|
182
227
|
const walk = (dir: string, base: string) => {
|
|
183
228
|
try {
|
|
184
229
|
if (typeof fsMod.readdirSync !== 'function') return;
|
|
@@ -214,7 +259,20 @@ export class SyncService {
|
|
|
214
259
|
} catch {
|
|
215
260
|
return [];
|
|
216
261
|
}
|
|
217
|
-
|
|
262
|
+
if (!storeRootDiffers) {
|
|
263
|
+
// Store inside the DSH home: one walk covers everything, exactly as before.
|
|
264
|
+
walk(root, '');
|
|
265
|
+
} else {
|
|
266
|
+
// Store elsewhere: walk the DSH home for sessions and harness state, skipping the
|
|
267
|
+
// path the store would occupy, then walk the store itself under its wire prefix.
|
|
268
|
+
const harnessOwned = collect(root, '');
|
|
269
|
+
for (const wire of harnessOwned) {
|
|
270
|
+
const normalised = wire.split(path.sep).join('/');
|
|
271
|
+
if (normalised === 'maestro-memory' || normalised.startsWith('maestro-memory/')) continue;
|
|
272
|
+
result.push(wire);
|
|
273
|
+
}
|
|
274
|
+
result.push(...collect(this.storeRoot, 'maestro-memory'));
|
|
275
|
+
}
|
|
218
276
|
return [...new Set(
|
|
219
277
|
result
|
|
220
278
|
.map((p) => p.split(path.sep).join('/'))
|
|
@@ -242,6 +300,73 @@ export class SyncService {
|
|
|
242
300
|
* re-hashed at write time (see apply), so a stale cache can never publish a
|
|
243
301
|
* wrong mutation target.
|
|
244
302
|
*/
|
|
303
|
+
/**
|
|
304
|
+
* The 4.0 rename moved the store root. A machine still on the old root would
|
|
305
|
+
* inventory zero memory files, which reads exactly like "nothing to sync".
|
|
306
|
+
* Refuse instead: the marker is written by the plugin's boot migration.
|
|
307
|
+
*/
|
|
308
|
+
private assertLocalStoreMigrated(): void {
|
|
309
|
+
const probe = (this.fs as any)?.existsSync;
|
|
310
|
+
if (typeof probe !== 'function') return;
|
|
311
|
+
const current = this.storeRoot;
|
|
312
|
+
const legacy = path.join(this.localDsh, 'dsh-maestro-memory');
|
|
313
|
+
const v4 = path.join(this.localDsh, 'maestro-memory');
|
|
314
|
+
let currentExists = false;
|
|
315
|
+
let legacyExists = false;
|
|
316
|
+
try {
|
|
317
|
+
currentExists = probe.call(this.fs, current);
|
|
318
|
+
legacyExists = probe.call(this.fs, legacy);
|
|
319
|
+
} catch {
|
|
320
|
+
return;
|
|
321
|
+
}
|
|
322
|
+
// Only the half-migrated shape is refused: the old root is still there and
|
|
323
|
+
// the new one is absent. A fresh DSH_HOME has neither, and a migrated one
|
|
324
|
+
// has the new root, so both stay usable.
|
|
325
|
+
// A store still at a legacy root would inventory zero files through the new root,
|
|
326
|
+
// which reads exactly like "nothing to sync". Refuse instead.
|
|
327
|
+
let v4Exists = false;
|
|
328
|
+
try {
|
|
329
|
+
v4Exists = current !== v4 && probe.call(this.fs, v4);
|
|
330
|
+
} catch {}
|
|
331
|
+
if (!currentExists && legacyExists) {
|
|
332
|
+
throw syncFailure(
|
|
333
|
+
'snapshot',
|
|
334
|
+
'STORE_NOT_MIGRATED',
|
|
335
|
+
`local store is still at ${legacy}; run the current build on this machine (its boot migration moves it) before syncing`,
|
|
336
|
+
);
|
|
337
|
+
}
|
|
338
|
+
if (!currentExists && v4Exists) {
|
|
339
|
+
throw syncFailure(
|
|
340
|
+
'snapshot',
|
|
341
|
+
'STORE_NOT_MIGRATED',
|
|
342
|
+
`local store is still at ${v4}; install the current build (its boot migration moves it to ${current}) before syncing`,
|
|
343
|
+
);
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
/**
|
|
348
|
+
* Refuse a peer that still keeps its store inside the DSH home.
|
|
349
|
+
*
|
|
350
|
+
* The wire paths are the same on both sides, so a mixed pair writes into a directory
|
|
351
|
+
* the upgraded machine no longer reads: the transfer succeeds and the memories are
|
|
352
|
+
* invisible. The marker is the only signal available before the transfer starts.
|
|
353
|
+
*/
|
|
354
|
+
assertPeerMoved(remotePaths: string[]): void {
|
|
355
|
+
// Only meaningful once this machine has moved: while our own store still sits inside
|
|
356
|
+
// the DSH home, the peer's layout is the one that matches and there is nothing to
|
|
357
|
+
// protect against.
|
|
358
|
+
if (this.storeRoot === path.join(this.localDsh, 'maestro-memory')) return;
|
|
359
|
+
const hasMemory = remotePaths.some((p) => p.startsWith('maestro-memory/'));
|
|
360
|
+
const hasMarker = remotePaths.includes('maestro-memory/.maestro-memory/migrated-v5.json');
|
|
361
|
+
if (hasMemory && !hasMarker) {
|
|
362
|
+
throw syncFailure(
|
|
363
|
+
'snapshot',
|
|
364
|
+
'PEER_NOT_MOVED',
|
|
365
|
+
`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`,
|
|
366
|
+
);
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
|
|
245
370
|
private async snapshotBoth(opts: { scope?: SyncScope; sessionsCountOnly?: boolean; onProgress?: (p: SyncProgress) => void; shouldStop?: () => boolean } = {}): Promise<{
|
|
246
371
|
target: RemoteTarget;
|
|
247
372
|
localSnapshots: FileSnapshot[];
|
|
@@ -250,6 +375,7 @@ export class SyncService {
|
|
|
250
375
|
remoteContents: Map<string, Buffer>;
|
|
251
376
|
cleanup: () => void;
|
|
252
377
|
}> {
|
|
378
|
+
this.assertLocalStoreMigrated();
|
|
253
379
|
const progress = (phase: SyncProgress['phase'], current: number, total: number, file?: string) => opts.onProgress?.({ phase, current, total, file });
|
|
254
380
|
const stop = () => {
|
|
255
381
|
if (opts.shouldStop?.()) throw syncFailure('snapshot', 'CANCELLED', 'preview cancelled');
|
|
@@ -258,11 +384,12 @@ export class SyncService {
|
|
|
258
384
|
const fsMod = this.fs;
|
|
259
385
|
const target = await this.requireTarget();
|
|
260
386
|
stop();
|
|
261
|
-
// Scope filter: 'memory' covers
|
|
387
|
+
// Scope filter: 'memory' covers maestro-memory only and skips the
|
|
262
388
|
// live session logs; undefined/'all' preserves the legacy full inventory.
|
|
263
389
|
const inScope = (p: string): boolean => opts.scope !== 'memory' || !p.startsWith('sessions/');
|
|
264
390
|
const localPaths = this.listLocalFiles().filter(inScope);
|
|
265
391
|
const remoteManifest = (await this.transport.manifest(target)).filter((e) => inScope(e.path));
|
|
392
|
+
this.assertPeerMoved(remoteManifest.map((e) => e.path));
|
|
266
393
|
stop();
|
|
267
394
|
const remoteSnapshots = remoteManifest.map((e) => ({ path: e.path, sha256: e.sha256, size: e.size, kind: kindForPath(e.path) }));
|
|
268
395
|
const remoteSet = new Set(remoteManifest.map((e) => e.path));
|
|
@@ -275,7 +402,7 @@ export class SyncService {
|
|
|
275
402
|
const entry = probeIndex(p, index);
|
|
276
403
|
let st: any = null;
|
|
277
404
|
try {
|
|
278
|
-
st = typeof fsMod.statSync === 'function' ? fsMod.statSync(
|
|
405
|
+
st = typeof fsMod.statSync === 'function' ? fsMod.statSync(this.localPathForWirePath(p), { bigint: true } as any) : null;
|
|
279
406
|
} catch {
|
|
280
407
|
st = null;
|
|
281
408
|
}
|
|
@@ -286,7 +413,7 @@ export class SyncService {
|
|
|
286
413
|
}
|
|
287
414
|
}
|
|
288
415
|
let hashedCount = 0;
|
|
289
|
-
const staleHashes = await
|
|
416
|
+
const staleHashes = await hashWirePaths(fsMod, this.hashRoots(), stale, {
|
|
290
417
|
onFile: (h) => {
|
|
291
418
|
hashedCount++;
|
|
292
419
|
progress('hashing', hashedCount, stale.length, h.path);
|
|
@@ -296,7 +423,7 @@ export class SyncService {
|
|
|
296
423
|
for (const h of staleHashes) {
|
|
297
424
|
localSnapshots.push({ path: h.path, sha256: h.sha256, size: h.size, kind: kindForPath(h.path) });
|
|
298
425
|
try {
|
|
299
|
-
const st = typeof fsMod.statSync === 'function' ? fsMod.statSync(
|
|
426
|
+
const st = typeof fsMod.statSync === 'function' ? fsMod.statSync(this.localPathForWirePath(h.path), { bigint: true } as any) : null;
|
|
300
427
|
if (st) index.entries[h.path] = { ...statFingerprint(st), sha256: h.sha256 };
|
|
301
428
|
} catch {
|
|
302
429
|
// stat races are tolerable — the entry simply misses next run
|
|
@@ -322,7 +449,7 @@ export class SyncService {
|
|
|
322
449
|
const localBufferOf = (rel: string): Buffer | undefined => {
|
|
323
450
|
if (localContents.has(rel)) return localContents.get(rel);
|
|
324
451
|
try {
|
|
325
|
-
const d = fsMod.readFileSync(
|
|
452
|
+
const d = fsMod.readFileSync(this.localPathForWirePath(rel));
|
|
326
453
|
const buf = Buffer.isBuffer(d) ? Buffer.from(d) : Buffer.from(String(d), 'utf-8');
|
|
327
454
|
localContents.set(rel, buf);
|
|
328
455
|
return buf;
|
|
@@ -612,7 +739,7 @@ export class SyncService {
|
|
|
612
739
|
} else {
|
|
613
740
|
buf = this.mergeBuffer(act, localContents, remoteContents, 'pull');
|
|
614
741
|
}
|
|
615
|
-
await this.atomicWriteWithBackup(
|
|
742
|
+
await this.atomicWriteWithBackup(this.localPathForWirePath(act.path), buf);
|
|
616
743
|
committed.push(act.path);
|
|
617
744
|
} catch (e: any) {
|
|
618
745
|
failures.push(syncFailure('publish', e?.code ?? 'PUBLISH_FAILED', String(e?.message ?? e), act.path) as SyncFailure);
|
|
@@ -728,7 +855,7 @@ export class SyncService {
|
|
|
728
855
|
const entry = probeIndex(p, index);
|
|
729
856
|
let st: any = null;
|
|
730
857
|
try {
|
|
731
|
-
st = typeof fsMod.statSync === 'function' ? fsMod.statSync(
|
|
858
|
+
st = typeof fsMod.statSync === 'function' ? fsMod.statSync(this.localPathForWirePath(p), { bigint: true } as any) : null;
|
|
732
859
|
} catch {
|
|
733
860
|
st = null;
|
|
734
861
|
}
|
|
@@ -737,7 +864,7 @@ export class SyncService {
|
|
|
737
864
|
}
|
|
738
865
|
if (stale.length > 0) {
|
|
739
866
|
let i = 0;
|
|
740
|
-
const hashed = await
|
|
867
|
+
const hashed = await hashWirePaths(fsMod, this.hashRoots(), stale, {
|
|
741
868
|
onFile: (h) => {
|
|
742
869
|
i++;
|
|
743
870
|
onProgress?.(i, stale.length, h.path);
|
|
@@ -746,7 +873,7 @@ export class SyncService {
|
|
|
746
873
|
for (const h of hashed) {
|
|
747
874
|
out.set(h.path, h.sha256);
|
|
748
875
|
try {
|
|
749
|
-
const st = typeof fsMod.statSync === 'function' ? fsMod.statSync(
|
|
876
|
+
const st = typeof fsMod.statSync === 'function' ? fsMod.statSync(this.localPathForWirePath(h.path), { bigint: true } as any) : null;
|
|
750
877
|
if (st) index.entries[h.path] = { ...statFingerprint(st), sha256: h.sha256 };
|
|
751
878
|
} catch {}
|
|
752
879
|
}
|
|
@@ -756,10 +883,18 @@ export class SyncService {
|
|
|
756
883
|
}
|
|
757
884
|
|
|
758
885
|
async status(): Promise<StatusResult> {
|
|
886
|
+
// A legacy store inventories zero memory files, which reads as "nothing to sync".
|
|
887
|
+
// The count stays honest, and the reason travels with it.
|
|
888
|
+
let storeMigration: 'ok' | 'legacy' = 'ok';
|
|
889
|
+
try {
|
|
890
|
+
this.assertLocalStoreMigrated();
|
|
891
|
+
} catch {
|
|
892
|
+
storeMigration = 'legacy';
|
|
893
|
+
}
|
|
759
894
|
const connection = await this.checkConnection();
|
|
760
895
|
const localFiles = this.listLocalFiles();
|
|
761
896
|
if (!connection.ok) {
|
|
762
|
-
return { localOnly: localFiles.length, remoteOnly: 0, both: 0, localOnlyFiles: localFiles, remoteOnlyFiles: [], bothFiles: [], connection, remoteHost: this.remote };
|
|
897
|
+
return { localOnly: localFiles.length, remoteOnly: 0, both: 0, localOnlyFiles: localFiles, remoteOnlyFiles: [], bothFiles: [], connection, remoteHost: this.remote, storeMigration };
|
|
763
898
|
}
|
|
764
899
|
let remoteFiles: string[] = [];
|
|
765
900
|
try {
|
|
@@ -98,5 +98,5 @@ export interface ApplyRequest {
|
|
|
98
98
|
confirm: true;
|
|
99
99
|
}
|
|
100
100
|
|
|
101
|
-
/** Inventory scope: 'memory' covers
|
|
101
|
+
/** Inventory scope: 'memory' covers maestro-memory only, 'all' adds sessions/. */
|
|
102
102
|
export type SyncScope = 'memory' | 'all';
|
|
@@ -2,8 +2,21 @@ import type { RemoteTarget } from './sync-types.js';
|
|
|
2
2
|
|
|
3
3
|
export const HOST_RE = /^(?!-)[A-Za-z0-9._@:-]+$/;
|
|
4
4
|
export const ABSOLUTE_RE = /^\/(?:[A-Za-z0-9._-]+\/)*[A-Za-z0-9._-]+$/;
|
|
5
|
+
// `migrated-v5.json` is the store-move marker: a peer that carries it has moved its
|
|
6
|
+
// store out of the DSH home. Sync needs to see it to refuse a half-upgraded pair instead
|
|
7
|
+
// of publishing into a directory the peer no longer reads.
|
|
5
8
|
export const ELIGIBLE_RE =
|
|
6
|
-
/^(?:
|
|
9
|
+
/^(?: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)$/;
|
|
10
|
+
|
|
11
|
+
/** True when a wire path is eligible, without throwing at the caller. */
|
|
12
|
+
export function isEligiblePath(value: string): boolean {
|
|
13
|
+
try {
|
|
14
|
+
normalizeEligiblePath(value);
|
|
15
|
+
return true;
|
|
16
|
+
} catch {
|
|
17
|
+
return false;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
7
20
|
|
|
8
21
|
// Backwards-compatible aliases required by spec
|
|
9
22
|
export const HOST = HOST_RE;
|
|
@@ -73,7 +86,7 @@ export function normalizeEligiblePath(value: string): string {
|
|
|
73
86
|
throw new Error(`ineligible path: contains control characters: ${JSON.stringify(value)}`);
|
|
74
87
|
}
|
|
75
88
|
if (value.includes('..')) {
|
|
76
|
-
// traversal not allowed at all; eligible paths are strictly under
|
|
89
|
+
// traversal not allowed at all; eligible paths are strictly under maestro-memory/ or sessions/
|
|
77
90
|
// The ELIGIBLE regex would reject it anyway, but be explicit
|
|
78
91
|
throw new Error(`ineligible path: traversal: ${JSON.stringify(value)}`);
|
|
79
92
|
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Mark this plugin's row in the DSH settings navigation so a style block can
|
|
3
|
-
* replace the shell's fallback gear with the maestro glyph.
|
|
4
|
-
*
|
|
5
|
-
* DSH 0.1.x projects only `id`, `order`, and `label` from a `settings.section`
|
|
6
|
-
* registration and picks icons from a closed built-in list, so each external
|
|
7
|
-
* plugin identifies its own localized row by visible text after the dialog
|
|
8
|
-
* mounts. The marker owns no shell structure and is removed on disposal.
|
|
9
|
-
*/
|
|
10
|
-
export declare const SETTINGS_NAV_MARKER = "data-maestro-settings-nav";
|
|
11
|
-
/** Minimal DOM surface used here; tests inject a stub instead of `document`. */
|
|
12
|
-
/** The two DOM iteration shapes this module touches (querySelector results). */
|
|
13
|
-
type NodeSeq = Iterable<Element> & {
|
|
14
|
-
forEach(fn: (el: Element) => void): unknown;
|
|
15
|
-
};
|
|
16
|
-
interface DomScope {
|
|
17
|
-
querySelectorAll(selector: string): NodeSeq;
|
|
18
|
-
}
|
|
19
|
-
export declare function registerSettingsNavIcon(label: () => string, root?: DomScope): () => void;
|
|
20
|
-
export {};
|
|
21
|
-
//# sourceMappingURL=settings-nav-icon.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"settings-nav-icon.d.ts","sourceRoot":"","sources":["../../../../src/client/config/settings-nav-icon.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,eAAO,MAAM,mBAAmB,8BAA8B,CAAA;AAE9D,gFAAgF;AAChF,gFAAgF;AAChF,KAAK,OAAO,GAAG,QAAQ,CAAC,OAAO,CAAC,GAAG;IAAE,OAAO,CAAC,EAAE,EAAE,CAAC,EAAE,EAAE,OAAO,KAAK,IAAI,GAAG,OAAO,CAAA;CAAE,CAAA;AAElF,UAAU,QAAQ;IAChB,gBAAgB,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAA;CAC5C;AAOD,wBAAgB,uBAAuB,CACrC,KAAK,EAAE,MAAM,MAAM,EACnB,IAAI,CAAC,EAAE,QAAQ,GACd,MAAM,IAAI,CAuCZ"}
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Mark this plugin's row in the DSH settings navigation so a style block can
|
|
3
|
-
* replace the shell's fallback gear with the maestro glyph.
|
|
4
|
-
*
|
|
5
|
-
* DSH 0.1.x projects only `id`, `order`, and `label` from a `settings.section`
|
|
6
|
-
* registration and picks icons from a closed built-in list, so each external
|
|
7
|
-
* plugin identifies its own localized row by visible text after the dialog
|
|
8
|
-
* mounts. The marker owns no shell structure and is removed on disposal.
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
export const SETTINGS_NAV_MARKER = 'data-maestro-settings-nav'
|
|
12
|
-
|
|
13
|
-
/** Minimal DOM surface used here; tests inject a stub instead of `document`. */
|
|
14
|
-
/** The two DOM iteration shapes this module touches (querySelector results). */
|
|
15
|
-
type NodeSeq = Iterable<Element> & { forEach(fn: (el: Element) => void): unknown }
|
|
16
|
-
|
|
17
|
-
interface DomScope {
|
|
18
|
-
querySelectorAll(selector: string): NodeSeq
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
type ElementLike = Element & {
|
|
22
|
-
setAttribute(name: string, value: string): void
|
|
23
|
-
removeAttribute(name: string): void
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export function registerSettingsNavIcon(
|
|
27
|
-
label: () => string,
|
|
28
|
-
root?: DomScope,
|
|
29
|
-
): () => void {
|
|
30
|
-
if (typeof document === 'undefined' && root === undefined) {
|
|
31
|
-
// Node-side import safety (tests inject a stub root instead).
|
|
32
|
-
return () => {}
|
|
33
|
-
}
|
|
34
|
-
const scope = (root ?? document) as DomScope
|
|
35
|
-
|
|
36
|
-
let disposed = false
|
|
37
|
-
|
|
38
|
-
const sync = () => {
|
|
39
|
-
if (disposed) return
|
|
40
|
-
const currentLabel = label().trim()
|
|
41
|
-
const buttons = scope.querySelectorAll('[role="dialog"] nav button')
|
|
42
|
-
for (const button of Array.from(buttons)) {
|
|
43
|
-
const el = button as ElementLike
|
|
44
|
-
const matches =
|
|
45
|
-
currentLabel.length > 0 &&
|
|
46
|
-
button.textContent != null &&
|
|
47
|
-
button.textContent.trim() === currentLabel
|
|
48
|
-
if (matches) el.setAttribute(SETTINGS_NAV_MARKER, '')
|
|
49
|
-
else el.removeAttribute(SETTINGS_NAV_MARKER)
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
sync()
|
|
54
|
-
|
|
55
|
-
let observer: MutationObserver | null = null
|
|
56
|
-
if (typeof MutationObserver !== 'undefined') {
|
|
57
|
-
observer = new MutationObserver(sync)
|
|
58
|
-
observer.observe(document.body, { childList: true, subtree: true, characterData: true })
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
return () => {
|
|
62
|
-
disposed = true
|
|
63
|
-
if (observer !== null) observer.disconnect()
|
|
64
|
-
for (const element of Array.from(scope.querySelectorAll(`[${SETTINGS_NAV_MARKER}]`))) {
|
|
65
|
-
;(element as ElementLike).removeAttribute(SETTINGS_NAV_MARKER)
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
}
|