@ddtcorex/dsh-maestro-core 0.15.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/sync/remote-agent.js +1 -12
- package/lib/sync/remote-manifest.d.ts +0 -13
- package/lib/sync/remote-manifest.js +2 -27
- package/lib/sync/sync-service.d.ts +2 -0
- package/lib/sync/sync-service.js +22 -7
- package/package.json +1 -1
- package/src/host/sync/remote-agent.ts +1 -12
- package/src/host/sync/remote-manifest.ts +2 -28
- package/src/host/sync/sync-service.ts +23 -7
package/lib/sync/remote-agent.js
CHANGED
|
@@ -146,18 +146,7 @@ while IFS= read -r line; do
|
|
|
146
146
|
esac
|
|
147
147
|
staged="$stage_dir/$rel"
|
|
148
148
|
[ -f "$staged" ] || { echo "maestro-sync-commit: missing staged artifact: $rel" >&2; fail=1; continue; }
|
|
149
|
-
|
|
150
|
-
# whichever store root that peer actually reads; everything else stays under the DSH
|
|
151
|
-
# home. Resolved once per commit from the peer's own marker, never assumed.
|
|
152
|
-
case "$rel" in
|
|
153
|
-
maestro-memory/*)
|
|
154
|
-
if [ -f "$HOME/.maestro-memory/.maestro-memory/migrated-v5.json" ]; then
|
|
155
|
-
target="$HOME/.maestro-memory/\${rel#maestro-memory/}"
|
|
156
|
-
else
|
|
157
|
-
target="$dsh_root/$rel"
|
|
158
|
-
fi ;;
|
|
159
|
-
*) target="$dsh_root/$rel" ;;
|
|
160
|
-
esac
|
|
149
|
+
target="$dsh_root/$rel"
|
|
161
150
|
if [ "$expected" = "absent" ]; then
|
|
162
151
|
if [ -e "$target" ]; then
|
|
163
152
|
echo "CONCURRENT_MODIFICATION: $rel (target exists, expected absent)" >&2
|
|
@@ -11,19 +11,6 @@ export interface RemoteManifestEntry {
|
|
|
11
11
|
* "the peer has no memory", and the next push would have looked like the first
|
|
12
12
|
* one. A named refusal is worth more than a silent empty inventory.
|
|
13
13
|
*/
|
|
14
|
-
/**
|
|
15
|
-
* Raised when the peer has moved its store out of the DSH home.
|
|
16
|
-
*
|
|
17
|
-
* Sync still addresses memory as `<dshRoot>/maestro-memory` on the sending side, so a
|
|
18
|
-
* push to a moved peer writes into the directory that peer no longer reads, and the
|
|
19
|
-
* transfer reports success. Until the remote scripts learn a second base path, the only
|
|
20
|
-
* honest thing is to refuse: a named refusal is worth more than memories that vanish.
|
|
21
|
-
*/
|
|
22
|
-
export declare class PeerStoreMovedError extends Error {
|
|
23
|
-
readonly remotePath: string;
|
|
24
|
-
readonly code = "PEER_STORE_MOVED";
|
|
25
|
-
constructor(remotePath: string);
|
|
26
|
-
}
|
|
27
14
|
export declare class StoreNotMigratedError extends Error {
|
|
28
15
|
readonly remotePath: string;
|
|
29
16
|
readonly code = "STORE_NOT_MIGRATED";
|
|
@@ -15,23 +15,6 @@ import { remoteCachePath } from './remote-cache.js';
|
|
|
15
15
|
* "the peer has no memory", and the next push would have looked like the first
|
|
16
16
|
* one. A named refusal is worth more than a silent empty inventory.
|
|
17
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
18
|
export class StoreNotMigratedError extends Error {
|
|
36
19
|
remotePath;
|
|
37
20
|
code = 'STORE_NOT_MIGRATED';
|
|
@@ -58,11 +41,7 @@ export function buildRemoteManifestScript(dshRoot) {
|
|
|
58
41
|
// Preflight sentinel: no 4.0 marker means the peer still holds the old
|
|
59
42
|
// root, so an empty inventory must not be mistaken for an empty store.
|
|
60
43
|
`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
|
-
|
|
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`,
|
|
44
|
+
`find ${dshRoot}/maestro-memory ${dshRoot}/sessions`,
|
|
66
45
|
`\\( -name node_modules -o -name .git -o -name .supervisor -o -name profiles \\) -prune -o -type f -print0`,
|
|
67
46
|
`| xargs -0 stat --printf='%i %s %.Y %.Z\\t%n\\n' 2>/dev/null`,
|
|
68
47
|
`| 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;}'`,
|
|
@@ -73,8 +52,7 @@ export function buildRemoteManifestScript(dshRoot) {
|
|
|
73
52
|
`printf '%s\\t%s\\t%s\\t%s\\0' "$sha" "$size" "$mtime" "$rel";`,
|
|
74
53
|
`else`,
|
|
75
54
|
`rel=\${rest%%$'\\t'*}; st=\${rest#*$'\\t'};`,
|
|
76
|
-
`
|
|
77
|
-
`sha=$(sha256sum -- "$full" 2>/dev/null | awk '{print $1}');`,
|
|
55
|
+
`sha=$(sha256sum -- "${dshRoot}/$rel" 2>/dev/null | awk '{print $1}');`,
|
|
78
56
|
`set -- $st;`,
|
|
79
57
|
`printf '%s\\t%s\\t%s\\t%s\\0' "$sha" "$2" "$3" "$rel";`,
|
|
80
58
|
`fi;`,
|
|
@@ -90,9 +68,6 @@ export function parseRemoteManifest(buf) {
|
|
|
90
68
|
if (part.startsWith('STORE_NOT_MIGRATED\t')) {
|
|
91
69
|
throw new StoreNotMigratedError(part.split('\t').slice(3).join('\t'));
|
|
92
70
|
}
|
|
93
|
-
if (part.startsWith('PEER_STORE_MOVED\t')) {
|
|
94
|
-
throw new PeerStoreMovedError(part.split('\t').slice(3).join('\t'));
|
|
95
|
-
}
|
|
96
71
|
const [sha, sizeRaw, mtimeRaw, ...rest] = part.split('\t');
|
|
97
72
|
const p = rest.join('\t');
|
|
98
73
|
const size = Number(sizeRaw);
|
|
@@ -34,6 +34,8 @@ export interface StatusResult {
|
|
|
34
34
|
bothFiles: string[];
|
|
35
35
|
connection: ConnectionStatus;
|
|
36
36
|
remoteHost: string;
|
|
37
|
+
/** `legacy` means the local store still sits at an old root, so the counts are short. */
|
|
38
|
+
storeMigration?: 'ok' | 'legacy';
|
|
37
39
|
}
|
|
38
40
|
/** Cursor-paged status page for bounded RPC payloads (< 64 KiB). */
|
|
39
41
|
export interface StatusPage {
|
package/lib/sync/sync-service.js
CHANGED
|
@@ -134,6 +134,16 @@ export class SyncService {
|
|
|
134
134
|
const storeRootDiffers = this.storeRoot !== path.join(this.localDsh, 'maestro-memory');
|
|
135
135
|
const result = [];
|
|
136
136
|
const fsMod = this.fs;
|
|
137
|
+
/** Walk `dir` and return the wire paths it holds, without touching `result`. */
|
|
138
|
+
const collect = (dir, base) => {
|
|
139
|
+
const out = [];
|
|
140
|
+
void out;
|
|
141
|
+
const sink = [];
|
|
142
|
+
const previous = result.length;
|
|
143
|
+
walk(dir, base);
|
|
144
|
+
sink.push(...result.splice(previous));
|
|
145
|
+
return sink;
|
|
146
|
+
};
|
|
137
147
|
const walk = (dir, base) => {
|
|
138
148
|
try {
|
|
139
149
|
if (typeof fsMod.readdirSync !== 'function')
|
|
@@ -186,18 +196,14 @@ export class SyncService {
|
|
|
186
196
|
else {
|
|
187
197
|
// Store elsewhere: walk the DSH home for sessions and harness state, skipping the
|
|
188
198
|
// 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;
|
|
199
|
+
const harnessOwned = collect(root, '');
|
|
194
200
|
for (const wire of harnessOwned) {
|
|
195
201
|
const normalised = wire.split(path.sep).join('/');
|
|
196
202
|
if (normalised === 'maestro-memory' || normalised.startsWith('maestro-memory/'))
|
|
197
203
|
continue;
|
|
198
204
|
result.push(wire);
|
|
199
205
|
}
|
|
200
|
-
|
|
206
|
+
result.push(...collect(this.storeRoot, 'maestro-memory'));
|
|
201
207
|
}
|
|
202
208
|
return [...new Set(result
|
|
203
209
|
.map((p) => p.split(path.sep).join('/'))
|
|
@@ -840,10 +846,19 @@ export class SyncService {
|
|
|
840
846
|
return out;
|
|
841
847
|
}
|
|
842
848
|
async status() {
|
|
849
|
+
// A legacy store inventories zero memory files, which reads as "nothing to sync".
|
|
850
|
+
// The count stays honest, and the reason travels with it.
|
|
851
|
+
let storeMigration = 'ok';
|
|
852
|
+
try {
|
|
853
|
+
this.assertLocalStoreMigrated();
|
|
854
|
+
}
|
|
855
|
+
catch {
|
|
856
|
+
storeMigration = 'legacy';
|
|
857
|
+
}
|
|
843
858
|
const connection = await this.checkConnection();
|
|
844
859
|
const localFiles = this.listLocalFiles();
|
|
845
860
|
if (!connection.ok) {
|
|
846
|
-
return { localOnly: localFiles.length, remoteOnly: 0, both: 0, localOnlyFiles: localFiles, remoteOnlyFiles: [], bothFiles: [], connection, remoteHost: this.remote };
|
|
861
|
+
return { localOnly: localFiles.length, remoteOnly: 0, both: 0, localOnlyFiles: localFiles, remoteOnlyFiles: [], bothFiles: [], connection, remoteHost: this.remote, storeMigration };
|
|
847
862
|
}
|
|
848
863
|
let remoteFiles = [];
|
|
849
864
|
try {
|
package/package.json
CHANGED
|
@@ -147,18 +147,7 @@ while IFS= read -r line; do
|
|
|
147
147
|
esac
|
|
148
148
|
staged="$stage_dir/$rel"
|
|
149
149
|
[ -f "$staged" ] || { echo "maestro-sync-commit: missing staged artifact: $rel" >&2; fail=1; continue; }
|
|
150
|
-
|
|
151
|
-
# whichever store root that peer actually reads; everything else stays under the DSH
|
|
152
|
-
# home. Resolved once per commit from the peer's own marker, never assumed.
|
|
153
|
-
case "$rel" in
|
|
154
|
-
maestro-memory/*)
|
|
155
|
-
if [ -f "$HOME/.maestro-memory/.maestro-memory/migrated-v5.json" ]; then
|
|
156
|
-
target="$HOME/.maestro-memory/\${rel#maestro-memory/}"
|
|
157
|
-
else
|
|
158
|
-
target="$dsh_root/$rel"
|
|
159
|
-
fi ;;
|
|
160
|
-
*) target="$dsh_root/$rel" ;;
|
|
161
|
-
esac
|
|
150
|
+
target="$dsh_root/$rel"
|
|
162
151
|
if [ "$expected" = "absent" ]; then
|
|
163
152
|
if [ -e "$target" ]; then
|
|
164
153
|
echo "CONCURRENT_MODIFICATION: $rel (target exists, expected absent)" >&2
|
|
@@ -23,24 +23,6 @@ export interface RemoteManifestEntry {
|
|
|
23
23
|
* "the peer has no memory", and the next push would have looked like the first
|
|
24
24
|
* one. A named refusal is worth more than a silent empty inventory.
|
|
25
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
26
|
export class StoreNotMigratedError extends Error {
|
|
45
27
|
readonly code = 'STORE_NOT_MIGRATED'
|
|
46
28
|
constructor(readonly remotePath: string) {
|
|
@@ -66,11 +48,7 @@ export function buildRemoteManifestScript(dshRoot: string): string {
|
|
|
66
48
|
// Preflight sentinel: no 4.0 marker means the peer still holds the old
|
|
67
49
|
// root, so an empty inventory must not be mistaken for an empty store.
|
|
68
50
|
`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
|
-
|
|
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`,
|
|
51
|
+
`find ${dshRoot}/maestro-memory ${dshRoot}/sessions`,
|
|
74
52
|
`\\( -name node_modules -o -name .git -o -name .supervisor -o -name profiles \\) -prune -o -type f -print0`,
|
|
75
53
|
`| xargs -0 stat --printf='%i %s %.Y %.Z\\t%n\\n' 2>/dev/null`,
|
|
76
54
|
`| 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;}'`,
|
|
@@ -81,8 +59,7 @@ export function buildRemoteManifestScript(dshRoot: string): string {
|
|
|
81
59
|
`printf '%s\\t%s\\t%s\\t%s\\0' "$sha" "$size" "$mtime" "$rel";`,
|
|
82
60
|
`else`,
|
|
83
61
|
`rel=\${rest%%$'\\t'*}; st=\${rest#*$'\\t'};`,
|
|
84
|
-
`
|
|
85
|
-
`sha=$(sha256sum -- "$full" 2>/dev/null | awk '{print $1}');`,
|
|
62
|
+
`sha=$(sha256sum -- "${dshRoot}/$rel" 2>/dev/null | awk '{print $1}');`,
|
|
86
63
|
`set -- $st;`,
|
|
87
64
|
`printf '%s\\t%s\\t%s\\t%s\\0' "$sha" "$2" "$3" "$rel";`,
|
|
88
65
|
`fi;`,
|
|
@@ -98,9 +75,6 @@ export function parseRemoteManifest(buf: Buffer): RemoteManifestEntry[] {
|
|
|
98
75
|
if (part.startsWith('STORE_NOT_MIGRATED\t')) {
|
|
99
76
|
throw new StoreNotMigratedError(part.split('\t').slice(3).join('\t'));
|
|
100
77
|
}
|
|
101
|
-
if (part.startsWith('PEER_STORE_MOVED\t')) {
|
|
102
|
-
throw new PeerStoreMovedError(part.split('\t').slice(3).join('\t'));
|
|
103
|
-
}
|
|
104
78
|
const [sha, sizeRaw, mtimeRaw, ...rest] = part.split('\t');
|
|
105
79
|
const p = rest.join('\t');
|
|
106
80
|
const size = Number(sizeRaw);
|
|
@@ -74,6 +74,8 @@ export interface StatusResult {
|
|
|
74
74
|
bothFiles: string[];
|
|
75
75
|
connection: ConnectionStatus;
|
|
76
76
|
remoteHost: string;
|
|
77
|
+
/** `legacy` means the local store still sits at an old root, so the counts are short. */
|
|
78
|
+
storeMigration?: 'ok' | 'legacy';
|
|
77
79
|
}
|
|
78
80
|
|
|
79
81
|
/** Cursor-paged status page for bounded RPC payloads (< 64 KiB). */
|
|
@@ -212,6 +214,16 @@ export class SyncService {
|
|
|
212
214
|
const storeRootDiffers = this.storeRoot !== path.join(this.localDsh, 'maestro-memory');
|
|
213
215
|
const result: string[] = [];
|
|
214
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
|
+
};
|
|
215
227
|
const walk = (dir: string, base: string) => {
|
|
216
228
|
try {
|
|
217
229
|
if (typeof fsMod.readdirSync !== 'function') return;
|
|
@@ -253,17 +265,13 @@ export class SyncService {
|
|
|
253
265
|
} else {
|
|
254
266
|
// Store elsewhere: walk the DSH home for sessions and harness state, skipping the
|
|
255
267
|
// path the store would occupy, then walk the store itself under its wire prefix.
|
|
256
|
-
const harnessOwned
|
|
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;
|
|
268
|
+
const harnessOwned = collect(root, '');
|
|
261
269
|
for (const wire of harnessOwned) {
|
|
262
270
|
const normalised = wire.split(path.sep).join('/');
|
|
263
271
|
if (normalised === 'maestro-memory' || normalised.startsWith('maestro-memory/')) continue;
|
|
264
272
|
result.push(wire);
|
|
265
273
|
}
|
|
266
|
-
|
|
274
|
+
result.push(...collect(this.storeRoot, 'maestro-memory'));
|
|
267
275
|
}
|
|
268
276
|
return [...new Set(
|
|
269
277
|
result
|
|
@@ -875,10 +883,18 @@ export class SyncService {
|
|
|
875
883
|
}
|
|
876
884
|
|
|
877
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
|
+
}
|
|
878
894
|
const connection = await this.checkConnection();
|
|
879
895
|
const localFiles = this.listLocalFiles();
|
|
880
896
|
if (!connection.ok) {
|
|
881
|
-
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 };
|
|
882
898
|
}
|
|
883
899
|
let remoteFiles: string[] = [];
|
|
884
900
|
try {
|