@ddtcorex/dsh-maestro-core 0.14.0 → 0.15.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.
Files changed (51) hide show
  1. package/lib/client.js +4 -125
  2. package/lib/debug-agent.js +2 -1
  3. package/lib/plugin.d.ts +1 -0
  4. package/lib/plugin.js +17 -4
  5. package/lib/resume.js +9 -1
  6. package/lib/sync/backup-service.d.ts +13 -0
  7. package/lib/sync/backup-service.js +60 -14
  8. package/lib/sync/hashing.d.ts +13 -0
  9. package/lib/sync/hashing.js +30 -0
  10. package/lib/sync/merge.d.ts +1 -1
  11. package/lib/sync/merge.js +1 -1
  12. package/lib/sync/remote-agent.js +12 -1
  13. package/lib/sync/remote-cache.js +1 -1
  14. package/lib/sync/remote-manifest.d.ts +25 -0
  15. package/lib/sync/remote-manifest.js +49 -2
  16. package/lib/sync/store-root.d.ts +44 -0
  17. package/lib/sync/store-root.js +67 -0
  18. package/lib/sync/sync-service.d.ts +25 -1
  19. package/lib/sync/sync-service.js +117 -12
  20. package/lib/sync/sync-types.d.ts +1 -1
  21. package/lib/sync/validation.d.ts +2 -0
  22. package/lib/sync/validation.js +15 -2
  23. package/lib/types/client/config/components/BrandMark.d.ts +1 -1
  24. package/lib/types/client/config/components/BrandMark.d.ts.map +1 -1
  25. package/lib/types/client/config/index.d.ts +0 -1
  26. package/lib/types/client/config/index.d.ts.map +1 -1
  27. package/lib/types/client/config/maestro-mark.d.ts +6 -16
  28. package/lib/types/client/config/maestro-mark.d.ts.map +1 -1
  29. package/lib/types/client/sync/index.d.ts.map +1 -1
  30. package/package.json +1 -1
  31. package/src/client/config/components/BrandMark.tsx +0 -1
  32. package/src/client/config/index.tsx +5 -44
  33. package/src/client/config/maestro-mark.ts +6 -23
  34. package/src/client/sync/index.tsx +0 -50
  35. package/src/client/sync/ui.tsx +4 -4
  36. package/src/host/debug-agent.ts +2 -1
  37. package/src/host/plugin.ts +19 -5
  38. package/src/host/resume.ts +10 -1
  39. package/src/host/sync/backup-service.ts +67 -14
  40. package/src/host/sync/hashing.ts +34 -1
  41. package/src/host/sync/merge.ts +1 -1
  42. package/src/host/sync/remote-agent.ts +12 -1
  43. package/src/host/sync/remote-cache.ts +1 -1
  44. package/src/host/sync/remote-manifest.ts +49 -2
  45. package/src/host/sync/store-root.ts +83 -0
  46. package/src/host/sync/sync-service.ts +131 -12
  47. package/src/host/sync/sync-types.ts +1 -1
  48. package/src/host/sync/validation.ts +15 -2
  49. package/lib/types/client/config/settings-nav-icon.d.ts +0 -21
  50. package/lib/types/client/config/settings-nav-icon.d.ts.map +0 -1
  51. package/src/client/config/settings-nav-icon.ts +0 -68
@@ -8,6 +8,39 @@
8
8
  // never an equality proof (equality uses sha256+size).
9
9
  import { normalizeEligiblePath } from './validation.js';
10
10
  import { remoteCachePath } from './remote-cache.js';
11
+ /**
12
+ * Raised when the peer has not moved its store to the 4.0 root yet.
13
+ *
14
+ * Before this guard the peer's `find` simply matched nothing, the plan read as
15
+ * "the peer has no memory", and the next push would have looked like the first
16
+ * one. A named refusal is worth more than a silent empty inventory.
17
+ */
18
+ /**
19
+ * Raised when the peer has moved its store out of the DSH home.
20
+ *
21
+ * Sync still addresses memory as `<dshRoot>/maestro-memory` on the sending side, so a
22
+ * push to a moved peer writes into the directory that peer no longer reads, and the
23
+ * transfer reports success. Until the remote scripts learn a second base path, the only
24
+ * honest thing is to refuse: a named refusal is worth more than memories that vanish.
25
+ */
26
+ export class PeerStoreMovedError extends Error {
27
+ remotePath;
28
+ code = 'PEER_STORE_MOVED';
29
+ constructor(remotePath) {
30
+ super(`peer store moved to ${remotePath}: this sync can only write <dshRoot>/maestro-memory, so publishing would be lost. Upgrade this machine's sync before transferring`);
31
+ this.remotePath = remotePath;
32
+ this.name = 'PeerStoreMovedError';
33
+ }
34
+ }
35
+ export class StoreNotMigratedError extends Error {
36
+ remotePath;
37
+ code = 'STORE_NOT_MIGRATED';
38
+ constructor(remotePath) {
39
+ super(`remote store not migrated: ${remotePath} has no migrated-v4 marker; run the new build on that machine first`);
40
+ this.remotePath = remotePath;
41
+ this.name = 'StoreNotMigratedError';
42
+ }
43
+ }
11
44
  export function buildRemoteManifestScript(dshRoot) {
12
45
  // Fixed script; dshRoot is the validated absolute root (same trust rule as transport.list).
13
46
  // Cache-aware, READ-ONLY (spec §4.7 clarification, decision C): it consults
@@ -22,7 +55,14 @@ export function buildRemoteManifestScript(dshRoot) {
22
55
  // inside a `do...done` one-liner break bash's parser (verified 2026-09-02).
23
56
  const cache = remoteCachePath(dshRoot);
24
57
  return [
25
- `find ${dshRoot}/dsh-maestro-memory ${dshRoot}/sessions`,
58
+ // Preflight sentinel: no 4.0 marker means the peer still holds the old
59
+ // root, so an empty inventory must not be mistaken for an empty store.
60
+ `if [ ! -f ${dshRoot}/maestro-memory/.maestro-memory/migrated-v4 ] && [ -d ${dshRoot}/dsh-maestro-memory ]; then printf 'STORE_NOT_MIGRATED\\t0\\t0\\t%s\\0' ${dshRoot}/dsh-maestro-memory; exit 0; fi;`,
61
+ // 5.0 moved the store out of the DSH home on the peer. Its `find` below would match
62
+ // nothing and read as "the peer has no memory", exactly the failure the v4 sentinel
63
+ // above exists to prevent.
64
+ `mem_root=${dshRoot}/maestro-memory; if [ -f "$HOME/.maestro-memory/.maestro-memory/migrated-v5.json" ]; then mem_root="$HOME/.maestro-memory"; fi;`,
65
+ `find "$mem_root" ${dshRoot}/sessions`,
26
66
  `\\( -name node_modules -o -name .git -o -name .supervisor -o -name profiles \\) -prune -o -type f -print0`,
27
67
  `| xargs -0 stat --printf='%i %s %.Y %.Z\\t%n\\n' 2>/dev/null`,
28
68
  `| awk -F '\\t' -v root='${dshRoot}/' -v cachefile='${cache}' 'BEGIN{while((getline line < cachefile) > 0){if(line=="")continue; m=split(line,a,"\\t"); if(m>=6){c[a[1]]=(a[2]" "a[3]" "a[4]" "a[5])"\\t"a[6]"\\t"a[3]"\\t"a[4];}} close(cachefile);} {st=$1; rel=$2; sub(root,"",rel); if(rel in c){split(c[rel],e,"\\t"); if(e[1]==st){print "H\\t"rel"\\t"e[2]"\\t"e[3]"\\t"e[4]; next;}} print "M\\t"rel"\\t"st;}'`,
@@ -33,7 +73,8 @@ export function buildRemoteManifestScript(dshRoot) {
33
73
  `printf '%s\\t%s\\t%s\\t%s\\0' "$sha" "$size" "$mtime" "$rel";`,
34
74
  `else`,
35
75
  `rel=\${rest%%$'\\t'*}; st=\${rest#*$'\\t'};`,
36
- `sha=$(sha256sum -- "${dshRoot}/$rel" 2>/dev/null | awk '{print $1}');`,
76
+ `case "$rel" in maestro-memory/*) if [ "$mem_root" != "${dshRoot}/maestro-memory" ]; then full="$mem_root/\${rel#maestro-memory/}"; else full="${dshRoot}/$rel"; fi;; *) full="${dshRoot}/$rel";; esac;`,
77
+ `sha=$(sha256sum -- "$full" 2>/dev/null | awk '{print $1}');`,
37
78
  `set -- $st;`,
38
79
  `printf '%s\\t%s\\t%s\\t%s\\0' "$sha" "$2" "$3" "$rel";`,
39
80
  `fi;`,
@@ -46,6 +87,12 @@ export function parseRemoteManifest(buf) {
46
87
  for (const part of parts) {
47
88
  if (!part)
48
89
  continue;
90
+ if (part.startsWith('STORE_NOT_MIGRATED\t')) {
91
+ throw new StoreNotMigratedError(part.split('\t').slice(3).join('\t'));
92
+ }
93
+ if (part.startsWith('PEER_STORE_MOVED\t')) {
94
+ throw new PeerStoreMovedError(part.split('\t').slice(3).join('\t'));
95
+ }
49
96
  const [sha, sizeRaw, mtimeRaw, ...rest] = part.split('\t');
50
97
  const p = rest.join('\t');
51
98
  const size = Number(sizeRaw);
@@ -0,0 +1,44 @@
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
+ export type StoreRootMode = 'configured' | 'env' | 'isolated' | 'default';
18
+ export interface StoreRoot {
19
+ root: string;
20
+ mode: StoreRootMode;
21
+ }
22
+ export declare function resolveStoreRoot(opts?: {
23
+ memoryDir?: string | null;
24
+ env?: NodeJS.ProcessEnv;
25
+ home?: string;
26
+ }): StoreRoot;
27
+ /** Map a wire path onto the local filesystem. Wire paths never change; roots do. */
28
+ export declare function localPathForWirePath(wirePath: string, roots: {
29
+ storeRoot: string;
30
+ localDsh: string;
31
+ }): string;
32
+ /**
33
+ * Group wire paths by the local root they resolve to, so a caller that hashes or stats
34
+ * many paths at once hashes each group against its own root instead of assuming the
35
+ * DSH home. After the store move, `maestro-memory/...` and `sessions/...` live in two
36
+ * different trees.
37
+ */
38
+ export declare function partitionByWireRoot(wirePaths: string[], roots: {
39
+ storeRoot: string;
40
+ localDsh: string;
41
+ }): Array<{
42
+ root: string;
43
+ paths: string[];
44
+ }>;
@@ -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
+ }
@@ -51,6 +51,8 @@ export interface PreviewResult extends SyncPreview {
51
51
  }
52
52
  export interface SyncServiceOpts {
53
53
  localDsh?: string;
54
+ /** Resolved memory store root; defaults to the same rules the plugin uses. */
55
+ storeRoot?: string;
54
56
  remote?: string;
55
57
  remoteDsh?: string;
56
58
  previewDir?: string;
@@ -61,6 +63,7 @@ export interface SyncServiceOpts {
61
63
  }
62
64
  export declare class SyncService {
63
65
  localDsh: string;
66
+ storeRoot: string;
64
67
  remote: string;
65
68
  remoteDsh: string;
66
69
  previewDir: string;
@@ -78,10 +81,17 @@ export declare class SyncService {
78
81
  checkConnection(): Promise<ConnectionStatus>;
79
82
  private requireConnection;
80
83
  /**
81
- * Local eligible files (dsh-maestro-memory/*.md, dsh-maestro-memory/SUGGESTIONS.jsonl,
84
+ * Local eligible files (maestro-memory/*.md, maestro-memory/SUGGESTIONS.jsonl,
82
85
  * sessions/<cwd-hash>/<id>/session.jsonl.zstd) as relative paths, sorted.
83
86
  * Only content that matches the eligible contract is ever read or hashed.
84
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;
85
95
  listLocalFiles(): string[];
86
96
  /**
87
97
  * Snapshot both sides with the manifest-first pipeline:
@@ -96,6 +106,20 @@ export declare class SyncService {
96
106
  * re-hashed at write time (see apply), so a stale cache can never publish a
97
107
  * wrong mutation target.
98
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;
99
123
  private snapshotBoth;
100
124
  /**
101
125
  * Read-only preview: exact plan with copy/merge/skip/conflict and real added
@@ -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 { hashFiles } from './hashing.js';
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,12 +114,24 @@ export class SyncService {
99
114
  return connection;
100
115
  }
101
116
  /**
102
- * Local eligible files (dsh-maestro-memory/*.md, dsh-maestro-memory/SUGGESTIONS.jsonl,
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;
110
137
  const walk = (dir, base) => {
@@ -152,7 +179,26 @@ export class SyncService {
152
179
  catch {
153
180
  return [];
154
181
  }
155
- walk(root, '');
182
+ if (!storeRootDiffers) {
183
+ // Store inside the DSH home: one walk covers everything, exactly as before.
184
+ walk(root, '');
185
+ }
186
+ else {
187
+ // Store elsewhere: walk the DSH home for sessions and harness state, skipping the
188
+ // path the store would occupy, then walk the store itself under its wire prefix.
189
+ const harnessOwned = [];
190
+ const push = result.push.bind(result);
191
+ result.push = (...items) => harnessOwned.push(...items);
192
+ walk(root, '');
193
+ result.push = push;
194
+ for (const wire of harnessOwned) {
195
+ const normalised = wire.split(path.sep).join('/');
196
+ if (normalised === 'maestro-memory' || normalised.startsWith('maestro-memory/'))
197
+ continue;
198
+ result.push(wire);
199
+ }
200
+ walk(this.storeRoot, 'maestro-memory');
201
+ }
156
202
  return [...new Set(result
157
203
  .map((p) => p.split(path.sep).join('/'))
158
204
  .filter((p) => {
@@ -178,7 +224,65 @@ export class SyncService {
178
224
  * re-hashed at write time (see apply), so a stale cache can never publish a
179
225
  * wrong mutation target.
180
226
  */
227
+ /**
228
+ * The 4.0 rename moved the store root. A machine still on the old root would
229
+ * inventory zero memory files, which reads exactly like "nothing to sync".
230
+ * Refuse instead: the marker is written by the plugin's boot migration.
231
+ */
232
+ assertLocalStoreMigrated() {
233
+ const probe = this.fs?.existsSync;
234
+ if (typeof probe !== 'function')
235
+ return;
236
+ const current = this.storeRoot;
237
+ const legacy = path.join(this.localDsh, 'dsh-maestro-memory');
238
+ const v4 = path.join(this.localDsh, 'maestro-memory');
239
+ let currentExists = false;
240
+ let legacyExists = false;
241
+ try {
242
+ currentExists = probe.call(this.fs, current);
243
+ legacyExists = probe.call(this.fs, legacy);
244
+ }
245
+ catch {
246
+ return;
247
+ }
248
+ // Only the half-migrated shape is refused: the old root is still there and
249
+ // the new one is absent. A fresh DSH_HOME has neither, and a migrated one
250
+ // has the new root, so both stay usable.
251
+ // A store still at a legacy root would inventory zero files through the new root,
252
+ // which reads exactly like "nothing to sync". Refuse instead.
253
+ let v4Exists = false;
254
+ try {
255
+ v4Exists = current !== v4 && probe.call(this.fs, v4);
256
+ }
257
+ catch { }
258
+ if (!currentExists && legacyExists) {
259
+ 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`);
260
+ }
261
+ if (!currentExists && v4Exists) {
262
+ 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`);
263
+ }
264
+ }
265
+ /**
266
+ * Refuse a peer that still keeps its store inside the DSH home.
267
+ *
268
+ * The wire paths are the same on both sides, so a mixed pair writes into a directory
269
+ * the upgraded machine no longer reads: the transfer succeeds and the memories are
270
+ * invisible. The marker is the only signal available before the transfer starts.
271
+ */
272
+ assertPeerMoved(remotePaths) {
273
+ // Only meaningful once this machine has moved: while our own store still sits inside
274
+ // the DSH home, the peer's layout is the one that matches and there is nothing to
275
+ // protect against.
276
+ if (this.storeRoot === path.join(this.localDsh, 'maestro-memory'))
277
+ return;
278
+ const hasMemory = remotePaths.some((p) => p.startsWith('maestro-memory/'));
279
+ const hasMarker = remotePaths.includes('maestro-memory/.maestro-memory/migrated-v5.json');
280
+ if (hasMemory && !hasMarker) {
281
+ 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`);
282
+ }
283
+ }
181
284
  async snapshotBoth(opts = {}) {
285
+ this.assertLocalStoreMigrated();
182
286
  const progress = (phase, current, total, file) => opts.onProgress?.({ phase, current, total, file });
183
287
  const stop = () => {
184
288
  if (opts.shouldStop?.())
@@ -188,11 +292,12 @@ export class SyncService {
188
292
  const fsMod = this.fs;
189
293
  const target = await this.requireTarget();
190
294
  stop();
191
- // Scope filter: 'memory' covers dsh-maestro-memory only and skips the
295
+ // Scope filter: 'memory' covers maestro-memory only and skips the
192
296
  // live session logs; undefined/'all' preserves the legacy full inventory.
193
297
  const inScope = (p) => opts.scope !== 'memory' || !p.startsWith('sessions/');
194
298
  const localPaths = this.listLocalFiles().filter(inScope);
195
299
  const remoteManifest = (await this.transport.manifest(target)).filter((e) => inScope(e.path));
300
+ this.assertPeerMoved(remoteManifest.map((e) => e.path));
196
301
  stop();
197
302
  const remoteSnapshots = remoteManifest.map((e) => ({ path: e.path, sha256: e.sha256, size: e.size, kind: kindForPath(e.path) }));
198
303
  const remoteSet = new Set(remoteManifest.map((e) => e.path));
@@ -204,7 +309,7 @@ export class SyncService {
204
309
  const entry = probeIndex(p, index);
205
310
  let st = null;
206
311
  try {
207
- st = typeof fsMod.statSync === 'function' ? fsMod.statSync(path.join(this.localDsh, p), { bigint: true }) : null;
312
+ st = typeof fsMod.statSync === 'function' ? fsMod.statSync(this.localPathForWirePath(p), { bigint: true }) : null;
208
313
  }
209
314
  catch {
210
315
  st = null;
@@ -217,7 +322,7 @@ export class SyncService {
217
322
  }
218
323
  }
219
324
  let hashedCount = 0;
220
- const staleHashes = await hashFiles(fsMod, this.localDsh, stale, {
325
+ const staleHashes = await hashWirePaths(fsMod, this.hashRoots(), stale, {
221
326
  onFile: (h) => {
222
327
  hashedCount++;
223
328
  progress('hashing', hashedCount, stale.length, h.path);
@@ -227,7 +332,7 @@ export class SyncService {
227
332
  for (const h of staleHashes) {
228
333
  localSnapshots.push({ path: h.path, sha256: h.sha256, size: h.size, kind: kindForPath(h.path) });
229
334
  try {
230
- const st = typeof fsMod.statSync === 'function' ? fsMod.statSync(path.join(this.localDsh, h.path), { bigint: true }) : null;
335
+ const st = typeof fsMod.statSync === 'function' ? fsMod.statSync(this.localPathForWirePath(h.path), { bigint: true }) : null;
231
336
  if (st)
232
337
  index.entries[h.path] = { ...statFingerprint(st), sha256: h.sha256 };
233
338
  }
@@ -256,7 +361,7 @@ export class SyncService {
256
361
  if (localContents.has(rel))
257
362
  return localContents.get(rel);
258
363
  try {
259
- const d = fsMod.readFileSync(path.join(this.localDsh, rel));
364
+ const d = fsMod.readFileSync(this.localPathForWirePath(rel));
260
365
  const buf = Buffer.isBuffer(d) ? Buffer.from(d) : Buffer.from(String(d), 'utf-8');
261
366
  localContents.set(rel, buf);
262
367
  return buf;
@@ -568,7 +673,7 @@ export class SyncService {
568
673
  else {
569
674
  buf = this.mergeBuffer(act, localContents, remoteContents, 'pull');
570
675
  }
571
- await this.atomicWriteWithBackup(path.join(this.localDsh, act.path), buf);
676
+ await this.atomicWriteWithBackup(this.localPathForWirePath(act.path), buf);
572
677
  committed.push(act.path);
573
678
  }
574
679
  catch (e) {
@@ -702,7 +807,7 @@ export class SyncService {
702
807
  const entry = probeIndex(p, index);
703
808
  let st = null;
704
809
  try {
705
- st = typeof fsMod.statSync === 'function' ? fsMod.statSync(path.join(this.localDsh, p), { bigint: true }) : null;
810
+ st = typeof fsMod.statSync === 'function' ? fsMod.statSync(this.localPathForWirePath(p), { bigint: true }) : null;
706
811
  }
707
812
  catch {
708
813
  st = null;
@@ -714,7 +819,7 @@ export class SyncService {
714
819
  }
715
820
  if (stale.length > 0) {
716
821
  let i = 0;
717
- const hashed = await hashFiles(fsMod, this.localDsh, stale, {
822
+ const hashed = await hashWirePaths(fsMod, this.hashRoots(), stale, {
718
823
  onFile: (h) => {
719
824
  i++;
720
825
  onProgress?.(i, stale.length, h.path);
@@ -723,7 +828,7 @@ export class SyncService {
723
828
  for (const h of hashed) {
724
829
  out.set(h.path, h.sha256);
725
830
  try {
726
- const st = typeof fsMod.statSync === 'function' ? fsMod.statSync(path.join(this.localDsh, h.path), { bigint: true }) : null;
831
+ const st = typeof fsMod.statSync === 'function' ? fsMod.statSync(this.localPathForWirePath(h.path), { bigint: true }) : null;
727
832
  if (st)
728
833
  index.entries[h.path] = { ...statFingerprint(st), sha256: h.sha256 };
729
834
  }
@@ -83,5 +83,5 @@ export interface ApplyRequest {
83
83
  direction: SyncDirection;
84
84
  confirm: true;
85
85
  }
86
- /** Inventory scope: 'memory' covers dsh-maestro-memory only, 'all' adds sessions/. */
86
+ /** Inventory scope: 'memory' covers maestro-memory only, 'all' adds sessions/. */
87
87
  export type SyncScope = 'memory' | 'all';
@@ -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;
@@ -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
- export const ELIGIBLE_RE = /^(?:dsh-maestro-memory\/(?!.*\.bak\.)[A-Za-z0-9._\/-]+\.md|dsh-maestro-memory\/SUGGESTIONS\.jsonl|sessions\/[A-Za-z0-9._-]+\/[A-Za-z0-9._-]+\/session\.jsonl\.zstd|sessions\/[A-Za-z0-9._\/-]+\.jsonl\.zstd)$/;
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 dsh-maestro-memory/ or sessions/
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, maestroMarkMaskUri, } from '../maestro-mark.js';
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,EACpB,kBAAkB,GACnB,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"}
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;AA6CxC,UAAU,SAAS;IACjB,GAAG,CAAC,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAA;IAC3B,MAAM,CAAC,EAAE,EAAE,MAAM,MAAM,IAAI,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,OAAO,CAAA;CACtD;AAED,eAAO,MAAM,MAAM,kCAAmC,CAAA;AAatD,wBAAgB,KAAK,CAAC,GAAG,EAAE,SAAS,GAAG,IAAI,CAkC1C"}
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 and the
5
- * CSS-mask encoding are importable from a test. `BrandMark.tsx` imports react,
6
- * which the client bundler treats as an EXTERNAL with no entry in this
7
- * package's `package.json` — so it cannot be imported from vitest at all, and a
8
- * test that only greps its text would accept a naive `encodeURIComponent` that
9
- * silently changes every rendered mask. This module has no react import, so
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;;;;;;;;;;;;;GAaG;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;AAE3C;;;;;;;GAOG;AACH,wBAAgB,kBAAkB,IAAI,MAAM,CAM3C"}
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;AA0StD,iBAAS,KAAK,CAAC,GAAG,EAAE,GAAG,GAAG,IAAI,CAqB7B;AAED,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,CAAA;;;;;AAE3B,wBAAgC"}
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ddtcorex/dsh-maestro-core",
3
- "version": "0.14.0",
3
+ "version": "0.15.0",
4
4
  "description": "DSH Web supervisor, settings store, tool guard and sync engine",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -45,7 +45,6 @@ export {
45
45
  MAESTRO_MARK_PATH,
46
46
  MAESTRO_MARK_STROKE_WIDTH,
47
47
  MAESTRO_MARK_VIEWBOX,
48
- maestroMarkMaskUri,
49
48
  } from '../maestro-mark.js'
50
49
 
51
50
  /**