@ddtcorex/dsh-maestro-core 0.13.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.
- package/README.md +3 -3
- package/lib/client.js +4 -125
- package/lib/debug-agent.d.ts +7 -0
- package/lib/debug-agent.js +15 -5
- package/lib/dsh-launch.d.ts +26 -0
- package/lib/dsh-launch.js +27 -0
- package/lib/plugin.d.ts +1 -0
- package/lib/plugin.js +17 -4
- package/lib/restart-tool.d.ts +3 -1
- package/lib/restart-tool.js +8 -4
- package/lib/restart-web.d.ts +3 -0
- package/lib/restart-web.js +7 -3
- 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-agent.js +12 -1
- package/lib/sync/remote-cache.js +1 -1
- package/lib/sync/remote-manifest.d.ts +25 -0
- package/lib/sync/remote-manifest.js +49 -2
- package/lib/sync/store-root.d.ts +44 -0
- package/lib/sync/store-root.js +67 -0
- package/lib/sync/sync-service.d.ts +25 -1
- package/lib/sync/sync-service.js +117 -12
- 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/skills/dsh-safe-restart/SKILL.md +4 -3
- package/skills/dsh-safe-restart/scripts/restart-dsh-web.sh +20 -36
- 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 +17 -8
- package/src/host/dsh-launch.ts +48 -0
- package/src/host/plugin.ts +19 -5
- package/src/host/restart-tool.ts +8 -4
- package/src/host/restart-web.ts +8 -6
- 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-agent.ts +12 -1
- package/src/host/sync/remote-cache.ts +1 -1
- package/src/host/sync/remote-manifest.ts +49 -2
- package/src/host/sync/store-root.ts +83 -0
- package/src/host/sync/sync-service.ts +131 -12
- package/src/host/sync/sync-types.ts +1 -1
- package/src/host/sync/validation.ts +15 -2
- package/systemd/dsh-web-supervisor.service.template +2 -0
- package/systemd/dsh-web.service.template +8 -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
|
@@ -16,6 +16,39 @@ export interface RemoteManifestEntry {
|
|
|
16
16
|
mtimeSec: number;
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
+
/**
|
|
20
|
+
* Raised when the peer has not moved its store to the 4.0 root yet.
|
|
21
|
+
*
|
|
22
|
+
* Before this guard the peer's `find` simply matched nothing, the plan read as
|
|
23
|
+
* "the peer has no memory", and the next push would have looked like the first
|
|
24
|
+
* one. A named refusal is worth more than a silent empty inventory.
|
|
25
|
+
*/
|
|
26
|
+
/**
|
|
27
|
+
* Raised when the peer has moved its store out of the DSH home.
|
|
28
|
+
*
|
|
29
|
+
* Sync still addresses memory as `<dshRoot>/maestro-memory` on the sending side, so a
|
|
30
|
+
* push to a moved peer writes into the directory that peer no longer reads, and the
|
|
31
|
+
* transfer reports success. Until the remote scripts learn a second base path, the only
|
|
32
|
+
* honest thing is to refuse: a named refusal is worth more than memories that vanish.
|
|
33
|
+
*/
|
|
34
|
+
export class PeerStoreMovedError extends Error {
|
|
35
|
+
readonly code = 'PEER_STORE_MOVED'
|
|
36
|
+
constructor(readonly remotePath: string) {
|
|
37
|
+
super(
|
|
38
|
+
`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`,
|
|
39
|
+
)
|
|
40
|
+
this.name = 'PeerStoreMovedError'
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export class StoreNotMigratedError extends Error {
|
|
45
|
+
readonly code = 'STORE_NOT_MIGRATED'
|
|
46
|
+
constructor(readonly remotePath: string) {
|
|
47
|
+
super(`remote store not migrated: ${remotePath} has no migrated-v4 marker; run the new build on that machine first`)
|
|
48
|
+
this.name = 'StoreNotMigratedError'
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
19
52
|
export function buildRemoteManifestScript(dshRoot: string): string {
|
|
20
53
|
// Fixed script; dshRoot is the validated absolute root (same trust rule as transport.list).
|
|
21
54
|
// Cache-aware, READ-ONLY (spec §4.7 clarification, decision C): it consults
|
|
@@ -30,7 +63,14 @@ export function buildRemoteManifestScript(dshRoot: string): string {
|
|
|
30
63
|
// inside a `do...done` one-liner break bash's parser (verified 2026-09-02).
|
|
31
64
|
const cache = remoteCachePath(dshRoot);
|
|
32
65
|
return [
|
|
33
|
-
|
|
66
|
+
// Preflight sentinel: no 4.0 marker means the peer still holds the old
|
|
67
|
+
// root, so an empty inventory must not be mistaken for an empty store.
|
|
68
|
+
`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;`,
|
|
69
|
+
// 5.0 moved the store out of the DSH home on the peer. Its `find` below would match
|
|
70
|
+
// nothing and read as "the peer has no memory", exactly the failure the v4 sentinel
|
|
71
|
+
// above exists to prevent.
|
|
72
|
+
`mem_root=${dshRoot}/maestro-memory; if [ -f "$HOME/.maestro-memory/.maestro-memory/migrated-v5.json" ]; then mem_root="$HOME/.maestro-memory"; fi;`,
|
|
73
|
+
`find "$mem_root" ${dshRoot}/sessions`,
|
|
34
74
|
`\\( -name node_modules -o -name .git -o -name .supervisor -o -name profiles \\) -prune -o -type f -print0`,
|
|
35
75
|
`| xargs -0 stat --printf='%i %s %.Y %.Z\\t%n\\n' 2>/dev/null`,
|
|
36
76
|
`| 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;}'`,
|
|
@@ -41,7 +81,8 @@ export function buildRemoteManifestScript(dshRoot: string): string {
|
|
|
41
81
|
`printf '%s\\t%s\\t%s\\t%s\\0' "$sha" "$size" "$mtime" "$rel";`,
|
|
42
82
|
`else`,
|
|
43
83
|
`rel=\${rest%%$'\\t'*}; st=\${rest#*$'\\t'};`,
|
|
44
|
-
`
|
|
84
|
+
`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;`,
|
|
85
|
+
`sha=$(sha256sum -- "$full" 2>/dev/null | awk '{print $1}');`,
|
|
45
86
|
`set -- $st;`,
|
|
46
87
|
`printf '%s\\t%s\\t%s\\t%s\\0' "$sha" "$2" "$3" "$rel";`,
|
|
47
88
|
`fi;`,
|
|
@@ -54,6 +95,12 @@ export function parseRemoteManifest(buf: Buffer): RemoteManifestEntry[] {
|
|
|
54
95
|
const parts = buf.toString('utf-8').split('\0');
|
|
55
96
|
for (const part of parts) {
|
|
56
97
|
if (!part) continue;
|
|
98
|
+
if (part.startsWith('STORE_NOT_MIGRATED\t')) {
|
|
99
|
+
throw new StoreNotMigratedError(part.split('\t').slice(3).join('\t'));
|
|
100
|
+
}
|
|
101
|
+
if (part.startsWith('PEER_STORE_MOVED\t')) {
|
|
102
|
+
throw new PeerStoreMovedError(part.split('\t').slice(3).join('\t'));
|
|
103
|
+
}
|
|
57
104
|
const [sha, sizeRaw, mtimeRaw, ...rest] = part.split('\t');
|
|
58
105
|
const p = rest.join('\t');
|
|
59
106
|
const size = Number(sizeRaw);
|
|
@@ -0,0 +1,83 @@
|
|
|
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
|
+
|
|
18
|
+
import { realpathSync } from 'node:fs';
|
|
19
|
+
import { homedir } from 'node:os';
|
|
20
|
+
import { join } from 'node:path';
|
|
21
|
+
|
|
22
|
+
export type StoreRootMode = 'configured' | 'env' | 'isolated' | 'default';
|
|
23
|
+
|
|
24
|
+
export interface StoreRoot {
|
|
25
|
+
root: string;
|
|
26
|
+
mode: StoreRootMode;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function realpathOr(value: string): string {
|
|
30
|
+
try {
|
|
31
|
+
return realpathSync.native(value);
|
|
32
|
+
} catch {
|
|
33
|
+
return value;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export function resolveStoreRoot(
|
|
38
|
+
opts: { memoryDir?: string | null; env?: NodeJS.ProcessEnv; home?: string } = {},
|
|
39
|
+
): StoreRoot {
|
|
40
|
+
if (opts.memoryDir) return { root: opts.memoryDir, mode: 'configured' };
|
|
41
|
+
const env = opts.env ?? process.env;
|
|
42
|
+
const envDir = typeof env.MAESTRO_MEMORY_DIR === 'string' ? env.MAESTRO_MEMORY_DIR.trim() : '';
|
|
43
|
+
if (envDir) return { root: envDir, mode: 'env' };
|
|
44
|
+
|
|
45
|
+
const home = realpathOr(opts.home ?? homedir());
|
|
46
|
+
const dshDefault = join(home, '.dsh');
|
|
47
|
+
const rawDsh = typeof env.DSH_HOME === 'string' && env.DSH_HOME.trim() ? env.DSH_HOME.trim() : '';
|
|
48
|
+
if (rawDsh && realpathOr(rawDsh) !== dshDefault) {
|
|
49
|
+
return { root: join(rawDsh, 'maestro-memory'), mode: 'isolated' };
|
|
50
|
+
}
|
|
51
|
+
return { root: join(home, '.maestro-memory'), mode: 'default' };
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** Map a wire path onto the local filesystem. Wire paths never change; roots do. */
|
|
55
|
+
export function localPathForWirePath(
|
|
56
|
+
wirePath: string,
|
|
57
|
+
roots: { storeRoot: string; localDsh: string },
|
|
58
|
+
): string {
|
|
59
|
+
if (wirePath.startsWith('maestro-memory/')) {
|
|
60
|
+
return join(roots.storeRoot, wirePath.slice('maestro-memory/'.length));
|
|
61
|
+
}
|
|
62
|
+
return join(roots.localDsh, wirePath);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Group wire paths by the local root they resolve to, so a caller that hashes or stats
|
|
67
|
+
* many paths at once hashes each group against its own root instead of assuming the
|
|
68
|
+
* DSH home. After the store move, `maestro-memory/...` and `sessions/...` live in two
|
|
69
|
+
* different trees.
|
|
70
|
+
*/
|
|
71
|
+
export function partitionByWireRoot(
|
|
72
|
+
wirePaths: string[],
|
|
73
|
+
roots: { storeRoot: string; localDsh: string },
|
|
74
|
+
): Array<{ root: string; paths: string[] }> {
|
|
75
|
+
const groups = new Map<string, string[]>();
|
|
76
|
+
for (const wire of wirePaths) {
|
|
77
|
+
const root = wire.startsWith('maestro-memory/') ? roots.storeRoot : roots.localDsh;
|
|
78
|
+
const bucket = groups.get(root);
|
|
79
|
+
if (bucket) bucket.push(wire);
|
|
80
|
+
else groups.set(root, [wire]);
|
|
81
|
+
}
|
|
82
|
+
return [...groups.entries()].map(([root, paths]) => ({ root, paths }));
|
|
83
|
+
}
|
|
@@ -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';
|
|
@@ -86,6 +94,8 @@ export interface PreviewResult extends SyncPreview {
|
|
|
86
94
|
|
|
87
95
|
export interface SyncServiceOpts {
|
|
88
96
|
localDsh?: string;
|
|
97
|
+
/** Resolved memory store root; defaults to the same rules the plugin uses. */
|
|
98
|
+
storeRoot?: string;
|
|
89
99
|
remote?: string;
|
|
90
100
|
remoteDsh?: string;
|
|
91
101
|
previewDir?: string;
|
|
@@ -101,6 +111,7 @@ function syncFailure(phase: SyncFailure['phase'], code: string, detail: string,
|
|
|
101
111
|
|
|
102
112
|
export class SyncService {
|
|
103
113
|
localDsh: string;
|
|
114
|
+
storeRoot: string;
|
|
104
115
|
remote: string;
|
|
105
116
|
remoteDsh: string;
|
|
106
117
|
previewDir: string;
|
|
@@ -111,6 +122,14 @@ export class SyncService {
|
|
|
111
122
|
|
|
112
123
|
constructor(opts: SyncServiceOpts = {}) {
|
|
113
124
|
this.localDsh = opts.localDsh || process.env.DSH_HOME || path.join(os.homedir(), '.dsh');
|
|
125
|
+
// The store can live outside the DSH home. Wire paths stay `maestro-memory/...`,
|
|
126
|
+
// so every site that touches disk maps through this root, never through localDsh.
|
|
127
|
+
// A caller that pins `localDsh` pins the whole machine state, so the store is
|
|
128
|
+
// resolved against it: a temp home is isolated by construction, and production's
|
|
129
|
+
// own home is not, which is exactly the plugin's rule.
|
|
130
|
+
this.storeRoot =
|
|
131
|
+
opts.storeRoot ??
|
|
132
|
+
resolveStoreRoot({ env: { ...process.env, DSH_HOME: opts.localDsh ?? process.env.DSH_HOME } }).root;
|
|
114
133
|
this.remote = opts.remote || process.env.REMOTE_HOST || process.env.REMOTE || 'kai@ssh.ddtcorex.com';
|
|
115
134
|
this.remoteDsh = opts.remoteDsh || process.env.REMOTE_DSH_PATH || '~/.dsh';
|
|
116
135
|
// Sidecar preview store shared by every CLI process (preview -> separate apply run).
|
|
@@ -171,12 +190,26 @@ export class SyncService {
|
|
|
171
190
|
}
|
|
172
191
|
|
|
173
192
|
/**
|
|
174
|
-
* Local eligible files (
|
|
193
|
+
* Local eligible files (maestro-memory/*.md, maestro-memory/SUGGESTIONS.jsonl,
|
|
175
194
|
* sessions/<cwd-hash>/<id>/session.jsonl.zstd) as relative paths, sorted.
|
|
176
195
|
* Only content that matches the eligible contract is ever read or hashed.
|
|
177
196
|
*/
|
|
197
|
+
/** The two roots a wire path can resolve to. */
|
|
198
|
+
hashRoots(): { storeRoot: string; localDsh: string } {
|
|
199
|
+
return { storeRoot: this.storeRoot, localDsh: this.localDsh };
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
/** Map a wire path to its local file, through the resolved store root. */
|
|
203
|
+
localPathForWirePath(wirePath: string): string {
|
|
204
|
+
return localPathForWirePath(wirePath, { storeRoot: this.storeRoot, localDsh: this.localDsh });
|
|
205
|
+
}
|
|
206
|
+
|
|
178
207
|
listLocalFiles(): string[] {
|
|
179
208
|
const root = this.localDsh;
|
|
209
|
+
// The store may live outside the DSH home, so its files are collected from the
|
|
210
|
+
// resolved root and labelled with the wire prefix. Sessions stay under the DSH
|
|
211
|
+
// home; they are harness data by definition.
|
|
212
|
+
const storeRootDiffers = this.storeRoot !== path.join(this.localDsh, 'maestro-memory');
|
|
180
213
|
const result: string[] = [];
|
|
181
214
|
const fsMod = this.fs;
|
|
182
215
|
const walk = (dir: string, base: string) => {
|
|
@@ -214,7 +247,24 @@ export class SyncService {
|
|
|
214
247
|
} catch {
|
|
215
248
|
return [];
|
|
216
249
|
}
|
|
217
|
-
|
|
250
|
+
if (!storeRootDiffers) {
|
|
251
|
+
// Store inside the DSH home: one walk covers everything, exactly as before.
|
|
252
|
+
walk(root, '');
|
|
253
|
+
} else {
|
|
254
|
+
// Store elsewhere: walk the DSH home for sessions and harness state, skipping the
|
|
255
|
+
// path the store would occupy, then walk the store itself under its wire prefix.
|
|
256
|
+
const harnessOwned: string[] = [];
|
|
257
|
+
const push = result.push.bind(result);
|
|
258
|
+
result.push = (...items: string[]) => harnessOwned.push(...items) as unknown as number;
|
|
259
|
+
walk(root, '');
|
|
260
|
+
result.push = push;
|
|
261
|
+
for (const wire of harnessOwned) {
|
|
262
|
+
const normalised = wire.split(path.sep).join('/');
|
|
263
|
+
if (normalised === 'maestro-memory' || normalised.startsWith('maestro-memory/')) continue;
|
|
264
|
+
result.push(wire);
|
|
265
|
+
}
|
|
266
|
+
walk(this.storeRoot, 'maestro-memory');
|
|
267
|
+
}
|
|
218
268
|
return [...new Set(
|
|
219
269
|
result
|
|
220
270
|
.map((p) => p.split(path.sep).join('/'))
|
|
@@ -242,6 +292,73 @@ export class SyncService {
|
|
|
242
292
|
* re-hashed at write time (see apply), so a stale cache can never publish a
|
|
243
293
|
* wrong mutation target.
|
|
244
294
|
*/
|
|
295
|
+
/**
|
|
296
|
+
* The 4.0 rename moved the store root. A machine still on the old root would
|
|
297
|
+
* inventory zero memory files, which reads exactly like "nothing to sync".
|
|
298
|
+
* Refuse instead: the marker is written by the plugin's boot migration.
|
|
299
|
+
*/
|
|
300
|
+
private assertLocalStoreMigrated(): void {
|
|
301
|
+
const probe = (this.fs as any)?.existsSync;
|
|
302
|
+
if (typeof probe !== 'function') return;
|
|
303
|
+
const current = this.storeRoot;
|
|
304
|
+
const legacy = path.join(this.localDsh, 'dsh-maestro-memory');
|
|
305
|
+
const v4 = path.join(this.localDsh, 'maestro-memory');
|
|
306
|
+
let currentExists = false;
|
|
307
|
+
let legacyExists = false;
|
|
308
|
+
try {
|
|
309
|
+
currentExists = probe.call(this.fs, current);
|
|
310
|
+
legacyExists = probe.call(this.fs, legacy);
|
|
311
|
+
} catch {
|
|
312
|
+
return;
|
|
313
|
+
}
|
|
314
|
+
// Only the half-migrated shape is refused: the old root is still there and
|
|
315
|
+
// the new one is absent. A fresh DSH_HOME has neither, and a migrated one
|
|
316
|
+
// has the new root, so both stay usable.
|
|
317
|
+
// A store still at a legacy root would inventory zero files through the new root,
|
|
318
|
+
// which reads exactly like "nothing to sync". Refuse instead.
|
|
319
|
+
let v4Exists = false;
|
|
320
|
+
try {
|
|
321
|
+
v4Exists = current !== v4 && probe.call(this.fs, v4);
|
|
322
|
+
} catch {}
|
|
323
|
+
if (!currentExists && legacyExists) {
|
|
324
|
+
throw syncFailure(
|
|
325
|
+
'snapshot',
|
|
326
|
+
'STORE_NOT_MIGRATED',
|
|
327
|
+
`local store is still at ${legacy}; run the current build on this machine (its boot migration moves it) before syncing`,
|
|
328
|
+
);
|
|
329
|
+
}
|
|
330
|
+
if (!currentExists && v4Exists) {
|
|
331
|
+
throw syncFailure(
|
|
332
|
+
'snapshot',
|
|
333
|
+
'STORE_NOT_MIGRATED',
|
|
334
|
+
`local store is still at ${v4}; install the current build (its boot migration moves it to ${current}) before syncing`,
|
|
335
|
+
);
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
/**
|
|
340
|
+
* Refuse a peer that still keeps its store inside the DSH home.
|
|
341
|
+
*
|
|
342
|
+
* The wire paths are the same on both sides, so a mixed pair writes into a directory
|
|
343
|
+
* the upgraded machine no longer reads: the transfer succeeds and the memories are
|
|
344
|
+
* invisible. The marker is the only signal available before the transfer starts.
|
|
345
|
+
*/
|
|
346
|
+
assertPeerMoved(remotePaths: string[]): void {
|
|
347
|
+
// Only meaningful once this machine has moved: while our own store still sits inside
|
|
348
|
+
// the DSH home, the peer's layout is the one that matches and there is nothing to
|
|
349
|
+
// protect against.
|
|
350
|
+
if (this.storeRoot === path.join(this.localDsh, 'maestro-memory')) return;
|
|
351
|
+
const hasMemory = remotePaths.some((p) => p.startsWith('maestro-memory/'));
|
|
352
|
+
const hasMarker = remotePaths.includes('maestro-memory/.maestro-memory/migrated-v5.json');
|
|
353
|
+
if (hasMemory && !hasMarker) {
|
|
354
|
+
throw syncFailure(
|
|
355
|
+
'snapshot',
|
|
356
|
+
'PEER_NOT_MOVED',
|
|
357
|
+
`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`,
|
|
358
|
+
);
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
|
|
245
362
|
private async snapshotBoth(opts: { scope?: SyncScope; sessionsCountOnly?: boolean; onProgress?: (p: SyncProgress) => void; shouldStop?: () => boolean } = {}): Promise<{
|
|
246
363
|
target: RemoteTarget;
|
|
247
364
|
localSnapshots: FileSnapshot[];
|
|
@@ -250,6 +367,7 @@ export class SyncService {
|
|
|
250
367
|
remoteContents: Map<string, Buffer>;
|
|
251
368
|
cleanup: () => void;
|
|
252
369
|
}> {
|
|
370
|
+
this.assertLocalStoreMigrated();
|
|
253
371
|
const progress = (phase: SyncProgress['phase'], current: number, total: number, file?: string) => opts.onProgress?.({ phase, current, total, file });
|
|
254
372
|
const stop = () => {
|
|
255
373
|
if (opts.shouldStop?.()) throw syncFailure('snapshot', 'CANCELLED', 'preview cancelled');
|
|
@@ -258,11 +376,12 @@ export class SyncService {
|
|
|
258
376
|
const fsMod = this.fs;
|
|
259
377
|
const target = await this.requireTarget();
|
|
260
378
|
stop();
|
|
261
|
-
// Scope filter: 'memory' covers
|
|
379
|
+
// Scope filter: 'memory' covers maestro-memory only and skips the
|
|
262
380
|
// live session logs; undefined/'all' preserves the legacy full inventory.
|
|
263
381
|
const inScope = (p: string): boolean => opts.scope !== 'memory' || !p.startsWith('sessions/');
|
|
264
382
|
const localPaths = this.listLocalFiles().filter(inScope);
|
|
265
383
|
const remoteManifest = (await this.transport.manifest(target)).filter((e) => inScope(e.path));
|
|
384
|
+
this.assertPeerMoved(remoteManifest.map((e) => e.path));
|
|
266
385
|
stop();
|
|
267
386
|
const remoteSnapshots = remoteManifest.map((e) => ({ path: e.path, sha256: e.sha256, size: e.size, kind: kindForPath(e.path) }));
|
|
268
387
|
const remoteSet = new Set(remoteManifest.map((e) => e.path));
|
|
@@ -275,7 +394,7 @@ export class SyncService {
|
|
|
275
394
|
const entry = probeIndex(p, index);
|
|
276
395
|
let st: any = null;
|
|
277
396
|
try {
|
|
278
|
-
st = typeof fsMod.statSync === 'function' ? fsMod.statSync(
|
|
397
|
+
st = typeof fsMod.statSync === 'function' ? fsMod.statSync(this.localPathForWirePath(p), { bigint: true } as any) : null;
|
|
279
398
|
} catch {
|
|
280
399
|
st = null;
|
|
281
400
|
}
|
|
@@ -286,7 +405,7 @@ export class SyncService {
|
|
|
286
405
|
}
|
|
287
406
|
}
|
|
288
407
|
let hashedCount = 0;
|
|
289
|
-
const staleHashes = await
|
|
408
|
+
const staleHashes = await hashWirePaths(fsMod, this.hashRoots(), stale, {
|
|
290
409
|
onFile: (h) => {
|
|
291
410
|
hashedCount++;
|
|
292
411
|
progress('hashing', hashedCount, stale.length, h.path);
|
|
@@ -296,7 +415,7 @@ export class SyncService {
|
|
|
296
415
|
for (const h of staleHashes) {
|
|
297
416
|
localSnapshots.push({ path: h.path, sha256: h.sha256, size: h.size, kind: kindForPath(h.path) });
|
|
298
417
|
try {
|
|
299
|
-
const st = typeof fsMod.statSync === 'function' ? fsMod.statSync(
|
|
418
|
+
const st = typeof fsMod.statSync === 'function' ? fsMod.statSync(this.localPathForWirePath(h.path), { bigint: true } as any) : null;
|
|
300
419
|
if (st) index.entries[h.path] = { ...statFingerprint(st), sha256: h.sha256 };
|
|
301
420
|
} catch {
|
|
302
421
|
// stat races are tolerable — the entry simply misses next run
|
|
@@ -322,7 +441,7 @@ export class SyncService {
|
|
|
322
441
|
const localBufferOf = (rel: string): Buffer | undefined => {
|
|
323
442
|
if (localContents.has(rel)) return localContents.get(rel);
|
|
324
443
|
try {
|
|
325
|
-
const d = fsMod.readFileSync(
|
|
444
|
+
const d = fsMod.readFileSync(this.localPathForWirePath(rel));
|
|
326
445
|
const buf = Buffer.isBuffer(d) ? Buffer.from(d) : Buffer.from(String(d), 'utf-8');
|
|
327
446
|
localContents.set(rel, buf);
|
|
328
447
|
return buf;
|
|
@@ -612,7 +731,7 @@ export class SyncService {
|
|
|
612
731
|
} else {
|
|
613
732
|
buf = this.mergeBuffer(act, localContents, remoteContents, 'pull');
|
|
614
733
|
}
|
|
615
|
-
await this.atomicWriteWithBackup(
|
|
734
|
+
await this.atomicWriteWithBackup(this.localPathForWirePath(act.path), buf);
|
|
616
735
|
committed.push(act.path);
|
|
617
736
|
} catch (e: any) {
|
|
618
737
|
failures.push(syncFailure('publish', e?.code ?? 'PUBLISH_FAILED', String(e?.message ?? e), act.path) as SyncFailure);
|
|
@@ -728,7 +847,7 @@ export class SyncService {
|
|
|
728
847
|
const entry = probeIndex(p, index);
|
|
729
848
|
let st: any = null;
|
|
730
849
|
try {
|
|
731
|
-
st = typeof fsMod.statSync === 'function' ? fsMod.statSync(
|
|
850
|
+
st = typeof fsMod.statSync === 'function' ? fsMod.statSync(this.localPathForWirePath(p), { bigint: true } as any) : null;
|
|
732
851
|
} catch {
|
|
733
852
|
st = null;
|
|
734
853
|
}
|
|
@@ -737,7 +856,7 @@ export class SyncService {
|
|
|
737
856
|
}
|
|
738
857
|
if (stale.length > 0) {
|
|
739
858
|
let i = 0;
|
|
740
|
-
const hashed = await
|
|
859
|
+
const hashed = await hashWirePaths(fsMod, this.hashRoots(), stale, {
|
|
741
860
|
onFile: (h) => {
|
|
742
861
|
i++;
|
|
743
862
|
onProgress?.(i, stale.length, h.path);
|
|
@@ -746,7 +865,7 @@ export class SyncService {
|
|
|
746
865
|
for (const h of hashed) {
|
|
747
866
|
out.set(h.path, h.sha256);
|
|
748
867
|
try {
|
|
749
|
-
const st = typeof fsMod.statSync === 'function' ? fsMod.statSync(
|
|
868
|
+
const st = typeof fsMod.statSync === 'function' ? fsMod.statSync(this.localPathForWirePath(h.path), { bigint: true } as any) : null;
|
|
750
869
|
if (st) index.entries[h.path] = { ...statFingerprint(st), sha256: h.sha256 };
|
|
751
870
|
} catch {}
|
|
752
871
|
}
|
|
@@ -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
|
}
|
|
@@ -11,6 +11,8 @@ ExecStart=/bin/bash -c 'export NVM_DIR="$HOME/.nvm"; [ -s "$NVM_DIR/nvm.sh" ] &&
|
|
|
11
11
|
Restart=always
|
|
12
12
|
RestartSec=2
|
|
13
13
|
Environment=DSH_HOME=%h/.dsh
|
|
14
|
+
# The daemon's nohup fallback and debug-agent dry-boot launch dsh through DSH_BIN.
|
|
15
|
+
Environment=DSH_BIN=%h/.local/share/dsh/current/bin/dsh
|
|
14
16
|
# Optional Telegram — loose mode: set these if you want Telegram alerts, otherwise daemon logs only
|
|
15
17
|
# Environment=TELEGRAM_BOT_TOKEN=your_bot_token
|
|
16
18
|
# Environment=TELEGRAM_CHAT_ID=your_chat_id
|
|
@@ -9,11 +9,17 @@ StartLimitBurst=3
|
|
|
9
9
|
|
|
10
10
|
[Service]
|
|
11
11
|
Type=simple
|
|
12
|
-
|
|
12
|
+
# Runs the published @deepseek-ai/dsh package, installed as one npm prefix per
|
|
13
|
+
# version under ~/.local/share/dsh/<version> with `current` linking the active
|
|
14
|
+
# one. DSH_BIN also steers this package's restart gate and dry-boots.
|
|
15
|
+
# The working directory is not neutral: dsh loads <cwd>/.env as the project env
|
|
16
|
+
# layer, so it stays on the install root, which holds no .env.
|
|
17
|
+
WorkingDirectory=%h/.local/share/dsh
|
|
18
|
+
Environment=DSH_BIN=%h/.local/share/dsh/current/bin/dsh
|
|
13
19
|
# Portable: sources nvm directly (bash -lc alone fails — ~/.bashrc exits early for
|
|
14
20
|
# non-interactive shells via `case $- in *i*) ;; *) return;; esac`, so nvm never loads).
|
|
15
21
|
# Falls back to system node for machines without nvm — no hardcoded /v24.19.0 version.
|
|
16
|
-
ExecStart=/bin/bash -c 'export NVM_DIR="$HOME/.nvm"; [ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"; exec node
|
|
22
|
+
ExecStart=/bin/bash -c 'export NVM_DIR="$HOME/.nvm"; [ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"; exec node "$DSH_BIN" web --no-open'
|
|
17
23
|
Restart=always
|
|
18
24
|
RestartSec=5
|
|
19
25
|
# Wait (up to 30 x 5s) for the previous instance to release the raw webserver
|
|
@@ -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
|
-
}
|