engine7 7.1.140 → 7.1.142
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/dist/bg-worker.mjs +16 -4
- package/dist/cli.mjs +4003 -1168
- package/dist/engine-startup.mjs +3136 -2143
- package/dist/main.mjs +3142 -2149
- package/dist/recall-worker.mjs +14 -2
- package/dist/sqlite-maintenance-worker.mjs +1 -1
- package/dist/topics-worker.mjs +56 -10
- package/dist/travel-activation-database.mjs +1077 -0
- package/dist/travel-authority.mjs +9 -3
- package/dist/travel-console.mjs +29 -17
- package/dist/travel-controller.mjs +16 -4
- package/dist/travel-data.mjs +364 -266
- package/dist/travel-gateway.mjs +559 -147
- package/dist/travel-host.mjs +1779 -1643
- package/dist/travel-initial-baseline.mjs +5961 -0
- package/dist/travel-node-data.mjs +149 -46
- package/dist/travel-node.mjs +1471 -1246
- package/dist/travel-pairing.mjs +562 -149
- package/dist/web-console.mjs +1065 -1449
- package/dlls/win32/msvcp140.dll +0 -0
- package/dlls/win32/vcruntime140.dll +0 -0
- package/dlls/win32/vcruntime140_1.dll +0 -0
- package/package.json +5 -3
package/dist/travel-data.mjs
CHANGED
|
@@ -188,17 +188,17 @@ var init_legacy_sqlite_indexes = __esm({
|
|
|
188
188
|
});
|
|
189
189
|
|
|
190
190
|
// src/continuity/runtime-authority.ts
|
|
191
|
-
import { randomUUID as
|
|
192
|
-
import { constants as
|
|
193
|
-
import { basename, dirname as
|
|
191
|
+
import { randomUUID as randomUUID3, verify } from "node:crypto";
|
|
192
|
+
import { constants as constants6, closeSync as closeSync4, existsSync, fstatSync as fstatSync3, fsyncSync as fsyncSync4, lstatSync as lstatSync5, mkdirSync as mkdirSync4, openSync as openSync5, readFileSync as readFileSync2, renameSync, writeFileSync as writeFileSync2 } from "node:fs";
|
|
193
|
+
import { basename, dirname as dirname4, join as join6, resolve as resolve5 } from "node:path";
|
|
194
194
|
function assertPrivateDirectory2(path3) {
|
|
195
|
-
const
|
|
196
|
-
if (!
|
|
195
|
+
const stat2 = lstatSync5(path3);
|
|
196
|
+
if (!stat2.isDirectory() || stat2.isSymbolicLink() || process.platform !== "win32" && (stat2.uid !== process.getuid() || stat2.mode & 63)) throw new Error("TRAVEL_PRIVATE_CONTROL_REQUIRED");
|
|
197
197
|
}
|
|
198
198
|
function readPrivateFile2(path3, maximum) {
|
|
199
199
|
const before = lstatSync5(path3);
|
|
200
200
|
if (!before.isFile() || before.isSymbolicLink() || process.platform !== "win32" && (before.uid !== process.getuid() || before.mode & 63)) throw new Error("TRAVEL_PRIVATE_CONTROL_REQUIRED");
|
|
201
|
-
const fd = openSync5(path3,
|
|
201
|
+
const fd = openSync5(path3, constants6.O_RDONLY | (constants6.O_NOFOLLOW ?? 0));
|
|
202
202
|
try {
|
|
203
203
|
if (fstatSync3(fd).size > maximum) throw new Error("TRAVEL_INVALID_CONTROL");
|
|
204
204
|
return readFileSync2(fd);
|
|
@@ -207,11 +207,11 @@ function readPrivateFile2(path3, maximum) {
|
|
|
207
207
|
}
|
|
208
208
|
}
|
|
209
209
|
function writeControl(path3, value2) {
|
|
210
|
-
const temporary = path3 + "." +
|
|
210
|
+
const temporary = path3 + "." + randomUUID3() + ".tmp";
|
|
211
211
|
writeFileSync2(temporary, JSON.stringify(value2), { mode: 384, flag: "wx", flush: true });
|
|
212
212
|
renameSync(temporary, path3);
|
|
213
213
|
if (process.platform !== "win32") {
|
|
214
|
-
const fd = openSync5(
|
|
214
|
+
const fd = openSync5(dirname4(path3), "r");
|
|
215
215
|
try {
|
|
216
216
|
fsyncSync4(fd);
|
|
217
217
|
} finally {
|
|
@@ -223,14 +223,14 @@ function runtimeAuthorityFor(stateDir) {
|
|
|
223
223
|
for (let root = resolve5(stateDir); ; ) {
|
|
224
224
|
const existing = runtimes.get(root);
|
|
225
225
|
if (existing) return existing;
|
|
226
|
-
const file =
|
|
226
|
+
const file = join6(root, ".continuity", "travel-runtime.json");
|
|
227
227
|
if (existsSync(file)) {
|
|
228
228
|
const enrollment = JSON.parse(readPrivateFile2(file, 16384).toString());
|
|
229
229
|
if (enrollment.format !== "engine7-travel-runtime-v1") throw new Error("TRAVEL_RUNTIME_RECOVERY_REQUIRED");
|
|
230
230
|
return new RuntimeAuthority({ stateDir: root, ...enrollment });
|
|
231
231
|
}
|
|
232
|
-
if (existsSync(
|
|
233
|
-
const parent =
|
|
232
|
+
if (existsSync(join6(root, ".travel-active.json")) || existsSync(join6(root, ".travel-enrolled.json"))) throw new Error("TRAVEL_RUNTIME_RECOVERY_REQUIRED");
|
|
233
|
+
const parent = dirname4(root);
|
|
234
234
|
if (parent === root) return null;
|
|
235
235
|
root = parent;
|
|
236
236
|
}
|
|
@@ -242,12 +242,12 @@ function assertRuntimeAuthority(stateDir, operation) {
|
|
|
242
242
|
function databaseRuntimeAuthorityFor(db) {
|
|
243
243
|
const file = String(db.prepare("PRAGMA database_list").all().find((r) => r.name === "main")?.file ?? "");
|
|
244
244
|
if (!file) return null;
|
|
245
|
-
const parent =
|
|
245
|
+
const parent = dirname4(file), name = basename(file);
|
|
246
246
|
let root;
|
|
247
|
-
if (name === "mem7.db" && basename(parent) === "index" && basename(
|
|
248
|
-
else if (name === "calendar.db" && basename(parent) === ".calendar" || name === "proactive.db" && basename(parent) === ".proactive" || name === "session-events.db" && basename(parent) === ".continuity") root =
|
|
249
|
-
else if (name === "memory.db" && basename(parent) === "memory" && basename(
|
|
250
|
-
else if (name === "vectors.db" && basename(
|
|
247
|
+
if (name === "mem7.db" && basename(parent) === "index" && basename(dirname4(parent)) === "mem7") root = dirname4(dirname4(parent));
|
|
248
|
+
else if (name === "calendar.db" && basename(parent) === ".calendar" || name === "proactive.db" && basename(parent) === ".proactive" || name === "session-events.db" && basename(parent) === ".continuity") root = dirname4(parent);
|
|
249
|
+
else if (name === "memory.db" && basename(parent) === "memory" && basename(dirname4(dirname4(parent))) === "agents") root = dirname4(dirname4(dirname4(parent)));
|
|
250
|
+
else if (name === "vectors.db" && basename(dirname4(parent)) === "topics-history") root = dirname4(dirname4(parent));
|
|
251
251
|
return root ? runtimeAuthorityFor(root) : null;
|
|
252
252
|
}
|
|
253
253
|
function assertDatabaseRuntimeAuthority(db, binding) {
|
|
@@ -270,7 +270,7 @@ var init_runtime_authority = __esm({
|
|
|
270
270
|
cachedFloor = 0;
|
|
271
271
|
constructor(options) {
|
|
272
272
|
this.stateDir = resolve5(options.stateDir);
|
|
273
|
-
this.directory =
|
|
273
|
+
this.directory = join6(this.stateDir, ".continuity");
|
|
274
274
|
this.clock = options.monotonicNow ?? now;
|
|
275
275
|
const tools = options.allowedTools ?? [];
|
|
276
276
|
if (!Array.isArray(tools) || tools.length > 1024 || tools.some((t) => typeof t !== "string" || !/^[A-Za-z0-9_.:-]{1,128}$/.test(t))) throw new Error("TRAVEL_INVALID_CAPABILITIES");
|
|
@@ -278,9 +278,9 @@ var init_runtime_authority = __esm({
|
|
|
278
278
|
if (options.initialize) {
|
|
279
279
|
mkdirSync4(this.directory, { mode: 448, recursive: true });
|
|
280
280
|
assertPrivateDirectory2(this.directory);
|
|
281
|
-
const file =
|
|
281
|
+
const file = join6(this.directory, "travel-runtime.json");
|
|
282
282
|
if (!existsSync(file)) writeFileSync2(file, JSON.stringify(this.enrollment), { mode: 384, flag: "wx", flush: true });
|
|
283
|
-
const marker =
|
|
283
|
+
const marker = join6(this.stateDir, ".travel-enrolled.json");
|
|
284
284
|
if (!existsSync(marker)) writeFileSync2(marker, JSON.stringify({ format: this.enrollment.format, identity: options.identity }), { mode: 384, flag: "wx", flush: true });
|
|
285
285
|
}
|
|
286
286
|
this.checkEnrollment();
|
|
@@ -290,7 +290,7 @@ var init_runtime_authority = __esm({
|
|
|
290
290
|
checkEnrollment() {
|
|
291
291
|
try {
|
|
292
292
|
assertPrivateDirectory2(this.directory);
|
|
293
|
-
const existing = JSON.parse(readPrivateFile2(
|
|
293
|
+
const existing = JSON.parse(readPrivateFile2(join6(this.directory, "travel-runtime.json"), 16384).toString());
|
|
294
294
|
if (!equal(existing, this.enrollment)) throw new Error("TRAVEL_RUNTIME_IDENTITY_MISMATCH");
|
|
295
295
|
} catch (error) {
|
|
296
296
|
throw new Error("TRAVEL_RUNTIME_RECOVERY_REQUIRED", { cause: error });
|
|
@@ -298,7 +298,7 @@ var init_runtime_authority = __esm({
|
|
|
298
298
|
}
|
|
299
299
|
grant() {
|
|
300
300
|
this.checkEnrollment();
|
|
301
|
-
const file =
|
|
301
|
+
const file = join6(this.directory, "travel-permit.json");
|
|
302
302
|
if (!existsSync(file)) return null;
|
|
303
303
|
try {
|
|
304
304
|
const grant = JSON.parse(readPrivateFile2(file, 16384).toString());
|
|
@@ -310,7 +310,7 @@ var init_runtime_authority = __esm({
|
|
|
310
310
|
}
|
|
311
311
|
writeGrant(grant) {
|
|
312
312
|
this.checkEnrollment();
|
|
313
|
-
writeControl(
|
|
313
|
+
writeControl(join6(this.directory, "travel-permit.json"), grant);
|
|
314
314
|
this.cachedGrant = grant;
|
|
315
315
|
}
|
|
316
316
|
validatePermit(permit) {
|
|
@@ -354,7 +354,7 @@ var init_runtime_authority = __esm({
|
|
|
354
354
|
return grant.permit;
|
|
355
355
|
}
|
|
356
356
|
deletionFloor() {
|
|
357
|
-
const file =
|
|
357
|
+
const file = join6(this.directory, "travel-deletion-floor.json");
|
|
358
358
|
if (!existsSync(file)) return 0;
|
|
359
359
|
const value2 = JSON.parse(readPrivateFile2(file, 128).toString());
|
|
360
360
|
if (!Number.isSafeInteger(value2) || value2 < 0) throw new Error("TRAVEL_RUNTIME_RECOVERY_REQUIRED");
|
|
@@ -362,7 +362,7 @@ var init_runtime_authority = __esm({
|
|
|
362
362
|
}
|
|
363
363
|
advanceDeletionFloor(floor) {
|
|
364
364
|
if (!Number.isSafeInteger(floor) || floor < this.deletionFloor()) throw new Error("TRAVEL_DELETION_ROLLBACK");
|
|
365
|
-
writeControl(
|
|
365
|
+
writeControl(join6(this.directory, "travel-deletion-floor.json"), floor);
|
|
366
366
|
this.cachedFloor = floor;
|
|
367
367
|
}
|
|
368
368
|
freeze(frozen) {
|
|
@@ -396,7 +396,7 @@ var init_runtime_authority = __esm({
|
|
|
396
396
|
import { createHash as createHash4 } from "node:crypto";
|
|
397
397
|
import { createRequire } from "node:module";
|
|
398
398
|
function sqliteConstants() {
|
|
399
|
-
return
|
|
399
|
+
return constants7 ??= createRequire(import.meta.url)("node:sqlite").constants;
|
|
400
400
|
}
|
|
401
401
|
function bindingText(binding) {
|
|
402
402
|
if (!binding || ["tenantId", "companionId", "seatId", "databaseId", "baselineId"].some((k) => typeof binding[k] !== "string" || !/^[A-Za-z0-9][A-Za-z0-9_.:-]{0,127}$/.test(String(binding[k]))) || !Number.isSafeInteger(binding.epoch) || binding.epoch < 1) throw new Error("REPLICATION_INVALID_BINDING");
|
|
@@ -568,7 +568,7 @@ function sourcePendingBytes(db, after, through) {
|
|
|
568
568
|
if (!Number.isSafeInteger(bytes) || bytes < 0) throw new Error("REPLICATION_CORRUPT_CONTROL");
|
|
569
569
|
return bytes;
|
|
570
570
|
}
|
|
571
|
-
var
|
|
571
|
+
var constants7, metadataTables, metadataColumns, guardPrefix, identifier, hash, digestPattern, SQLiteReplicationSourceReader, SQLiteReplicationSource, SQLiteReplicationReplica;
|
|
572
572
|
var init_sqlite_replication = __esm({
|
|
573
573
|
"src/continuity/sqlite-replication.ts"() {
|
|
574
574
|
"use strict";
|
|
@@ -960,8 +960,8 @@ var init_sqlite_replication = __esm({
|
|
|
960
960
|
});
|
|
961
961
|
|
|
962
962
|
// src/continuity/runtime-replication.ts
|
|
963
|
-
import { constants as
|
|
964
|
-
import { basename as basename2, dirname as
|
|
963
|
+
import { constants as constants8, lstatSync as lstatSync7, realpathSync as realpathSync3, mkdirSync as mkdirSync5, openSync as openSync7, closeSync as closeSync6, fstatSync as fstatSync4, readFileSync as readFileSync3, writeFileSync as writeFileSync4, fsyncSync as fsyncSync6 } from "node:fs";
|
|
964
|
+
import { basename as basename2, dirname as dirname6, join as join8, resolve as resolve6 } from "node:path";
|
|
965
965
|
function checkKey(component, key2) {
|
|
966
966
|
if (component === "topics-vectors" && typeof key2 === "string" && /^[a-f0-9]{64}$/.test(key2)) return;
|
|
967
967
|
if (component === "legacy-memory" && typeof key2 === "string" && /^[A-Za-z0-9][A-Za-z0-9_.-]{0,127}$/.test(key2) && !/[. ]$/.test(key2) && !/^(CON|PRN|AUX|NUL|COM[1-9]|LPT[1-9])(?:\.|$)/i.test(key2)) return;
|
|
@@ -970,17 +970,17 @@ function checkKey(component, key2) {
|
|
|
970
970
|
}
|
|
971
971
|
function location2(stateDir, component, key2) {
|
|
972
972
|
checkKey(component, key2);
|
|
973
|
-
return
|
|
973
|
+
return join8(stateDir, ".continuity", component + (key2 === void 0 ? "" : "-" + key2) + "-replication.json");
|
|
974
974
|
}
|
|
975
975
|
function runtimeReplicationFile(stateDir, component, key2) {
|
|
976
976
|
checkKey(component, key2);
|
|
977
|
-
if (component === "legacy-memory") return
|
|
978
|
-
if (component === "topics-vectors") return
|
|
979
|
-
if (component === "session-events") return
|
|
980
|
-
return
|
|
977
|
+
if (component === "legacy-memory") return join8(stateDir, "agents", key2, "memory", "memory.db");
|
|
978
|
+
if (component === "topics-vectors") return join8(stateDir, "topics-history", key2, "vectors.db");
|
|
979
|
+
if (component === "session-events") return join8(stateDir, ".continuity", "session-events.db");
|
|
980
|
+
return join8(stateDir, "." + component, component + ".db");
|
|
981
981
|
}
|
|
982
982
|
function runtimeReplicationLocation(stateDir, component, file) {
|
|
983
|
-
const key2 = component === "legacy-memory" ? basename2(
|
|
983
|
+
const key2 = component === "legacy-memory" ? basename2(dirname6(dirname6(file))) : component === "topics-vectors" ? basename2(dirname6(file)) : void 0;
|
|
984
984
|
try {
|
|
985
985
|
if (resolve6(file) !== resolve6(runtimeReplicationFile(stateDir, component, key2))) throw new Error();
|
|
986
986
|
} catch (error) {
|
|
@@ -1000,15 +1000,15 @@ function directory(path3) {
|
|
|
1000
1000
|
function readRuntimeReplicationRegistration(stateDir, component, key2) {
|
|
1001
1001
|
const file = location2(stateDir, component, key2);
|
|
1002
1002
|
try {
|
|
1003
|
-
lstatSync7(
|
|
1003
|
+
lstatSync7(dirname6(file));
|
|
1004
1004
|
} catch (error) {
|
|
1005
1005
|
if (error.code === "ENOENT") return null;
|
|
1006
1006
|
throw error;
|
|
1007
1007
|
}
|
|
1008
|
-
directory(
|
|
1008
|
+
directory(dirname6(file));
|
|
1009
1009
|
let fd;
|
|
1010
1010
|
try {
|
|
1011
|
-
fd = openSync7(file,
|
|
1011
|
+
fd = openSync7(file, constants8.O_RDONLY | (constants8.O_NOFOLLOW ?? 0));
|
|
1012
1012
|
} catch (error) {
|
|
1013
1013
|
if (error.code === "ENOENT") return null;
|
|
1014
1014
|
throw new Error("REPLICATION_REGISTRATION_INVALID", { cause: error });
|
|
@@ -1031,7 +1031,7 @@ function checkRuntimeReplicationFile(file, registration, initial = false) {
|
|
|
1031
1031
|
info = lstatSync7(file);
|
|
1032
1032
|
} catch (error) {
|
|
1033
1033
|
if (registration || !initial || error.code !== "ENOENT") throw error;
|
|
1034
|
-
let parent =
|
|
1034
|
+
let parent = dirname6(resolve6(file));
|
|
1035
1035
|
for (; ; ) {
|
|
1036
1036
|
try {
|
|
1037
1037
|
const existing = lstatSync7(parent);
|
|
@@ -1039,7 +1039,7 @@ function checkRuntimeReplicationFile(file, registration, initial = false) {
|
|
|
1039
1039
|
return;
|
|
1040
1040
|
} catch (error2) {
|
|
1041
1041
|
if (error2.code !== "ENOENT") throw error2;
|
|
1042
|
-
parent =
|
|
1042
|
+
parent = dirname6(parent);
|
|
1043
1043
|
}
|
|
1044
1044
|
}
|
|
1045
1045
|
}
|
|
@@ -1069,8 +1069,8 @@ function enrollRuntimeReplication(db, stateDir, component, binding, key2) {
|
|
|
1069
1069
|
const input = normalize2({ binding, schemaHash: sqliteReplicationSchemaHash(db) });
|
|
1070
1070
|
if (old && JSON.stringify(old) !== JSON.stringify(input)) throw new Error("REPLICATION_REGISTRATION_MISMATCH");
|
|
1071
1071
|
if (!old) {
|
|
1072
|
-
mkdirSync5(
|
|
1073
|
-
directory(
|
|
1072
|
+
mkdirSync5(dirname6(file), { mode: 448, recursive: true });
|
|
1073
|
+
directory(dirname6(file));
|
|
1074
1074
|
try {
|
|
1075
1075
|
writeFileSync4(file, JSON.stringify(input), { mode: 384, flag: "wx", flush: true });
|
|
1076
1076
|
} catch (error) {
|
|
@@ -1078,7 +1078,7 @@ function enrollRuntimeReplication(db, stateDir, component, binding, key2) {
|
|
|
1078
1078
|
if (JSON.stringify(readRuntimeReplicationRegistration(stateDir, component, key2)) !== JSON.stringify(input)) throw new Error("REPLICATION_REGISTRATION_MISMATCH");
|
|
1079
1079
|
}
|
|
1080
1080
|
if (process.platform !== "win32") {
|
|
1081
|
-
const fd = openSync7(
|
|
1081
|
+
const fd = openSync7(dirname6(file), "r");
|
|
1082
1082
|
try {
|
|
1083
1083
|
fsyncSync6(fd);
|
|
1084
1084
|
} finally {
|
|
@@ -1097,10 +1097,10 @@ var init_runtime_replication = __esm({
|
|
|
1097
1097
|
});
|
|
1098
1098
|
|
|
1099
1099
|
// src/continuity/runtime-lock.ts
|
|
1100
|
-
import { randomUUID as
|
|
1100
|
+
import { randomUUID as randomUUID4 } from "node:crypto";
|
|
1101
1101
|
import { AsyncLocalStorage } from "node:async_hooks";
|
|
1102
1102
|
import { closeSync as closeSync7, lstatSync as lstatSync8, mkdirSync as mkdirSync6, openSync as openSync8, readFileSync as readFileSync4, realpathSync as realpathSync4 } from "node:fs";
|
|
1103
|
-
import { join as
|
|
1103
|
+
import { join as join9 } from "node:path";
|
|
1104
1104
|
import { createRequire as createRequire4 } from "node:module";
|
|
1105
1105
|
function openSQLite(file, options = {}) {
|
|
1106
1106
|
return new (sqlite ??= createRequire4(import.meta.url)("node:sqlite")).DatabaseSync(file, options);
|
|
@@ -1109,11 +1109,11 @@ function openControl(stateDir, create = true, busyTimeoutMs = 0) {
|
|
|
1109
1109
|
if (create) mkdirSync6(stateDir, { recursive: true });
|
|
1110
1110
|
const state2 = realpathSync4(stateDir);
|
|
1111
1111
|
if (process.platform !== "win32" && lstatSync8(state2).uid !== process.getuid()) throw new Error("CONTROL_OWNER_MISMATCH: run travel as the engine data owner, without sudo");
|
|
1112
|
-
const directory2 =
|
|
1112
|
+
const directory2 = join9(state2, ".continuity");
|
|
1113
1113
|
if (create) mkdirSync6(directory2, { recursive: true, mode: 448 });
|
|
1114
1114
|
if (lstatSync8(directory2).isSymbolicLink()) throw new Error("UNSAFE_CONTROL_DIRECTORY");
|
|
1115
1115
|
assertControlPermissions(directory2);
|
|
1116
|
-
const file =
|
|
1116
|
+
const file = join9(directory2, "runtime.sqlite");
|
|
1117
1117
|
if (create) {
|
|
1118
1118
|
try {
|
|
1119
1119
|
closeSync7(openSync8(file, "wx", 384));
|
|
@@ -1152,7 +1152,7 @@ function assertStateDirUsable(stateDir) {
|
|
|
1152
1152
|
const initial = initialBaselineAdmission.getStore();
|
|
1153
1153
|
if (initial?.active && initial.roots.has(realpathSync4(stateDir))) return;
|
|
1154
1154
|
try {
|
|
1155
|
-
lstatSync8(
|
|
1155
|
+
lstatSync8(join9(stateDir, ".travel-restored.json"));
|
|
1156
1156
|
throw new Error("TRAVEL_ACTIVATION_REQUIRED");
|
|
1157
1157
|
} catch (error) {
|
|
1158
1158
|
if (error.code !== "ENOENT") throw error;
|
|
@@ -1177,7 +1177,7 @@ function registerRuntimeWriter(stateDir, kind) {
|
|
|
1177
1177
|
const recovery = recoveryWriterLocks.getStore();
|
|
1178
1178
|
if (recovery?.active && recovery.roots.has(realpathSync4(stateDir))) return () => {
|
|
1179
1179
|
};
|
|
1180
|
-
const db = openControl(stateDir, true, 1e3), id2 =
|
|
1180
|
+
const db = openControl(stateDir, true, 1e3), id2 = randomUUID4();
|
|
1181
1181
|
try {
|
|
1182
1182
|
db.exec("BEGIN IMMEDIATE");
|
|
1183
1183
|
db.prepare("INSERT INTO writers VALUES (?, ?, ?, ?, ?)").run(id2, process.pid, bootId, kind, (/* @__PURE__ */ new Date()).toISOString());
|
|
@@ -1230,7 +1230,7 @@ async function withCheckpointLock(stateDir, operation) {
|
|
|
1230
1230
|
for (const name of [".engine.pid", ".bg-worker.pid"]) {
|
|
1231
1231
|
let value2;
|
|
1232
1232
|
try {
|
|
1233
|
-
value2 = readFileSync4(
|
|
1233
|
+
value2 = readFileSync4(join9(stateDir, name), "utf8").trim();
|
|
1234
1234
|
} catch (error) {
|
|
1235
1235
|
if (error.code === "ENOENT") continue;
|
|
1236
1236
|
throw new Error("WRITER_STATE_UNKNOWN", { cause: error });
|
|
@@ -1254,7 +1254,7 @@ var init_runtime_lock = __esm({
|
|
|
1254
1254
|
"src/continuity/runtime-lock.ts"() {
|
|
1255
1255
|
"use strict";
|
|
1256
1256
|
init_runtime_authority();
|
|
1257
|
-
bootId =
|
|
1257
|
+
bootId = randomUUID4();
|
|
1258
1258
|
releases = /* @__PURE__ */ new Set();
|
|
1259
1259
|
checkpointHandles = /* @__PURE__ */ new Set();
|
|
1260
1260
|
exitHookInstalled = false;
|
|
@@ -1591,7 +1591,7 @@ var init_historical_recall = __esm({
|
|
|
1591
1591
|
});
|
|
1592
1592
|
|
|
1593
1593
|
// src/memory/topics-history/cutoff.ts
|
|
1594
|
-
import { DatabaseSync as
|
|
1594
|
+
import { DatabaseSync as DatabaseSync8 } from "node:sqlite";
|
|
1595
1595
|
var init_cutoff = __esm({
|
|
1596
1596
|
"src/memory/topics-history/cutoff.ts"() {
|
|
1597
1597
|
"use strict";
|
|
@@ -1604,7 +1604,7 @@ var init_cutoff = __esm({
|
|
|
1604
1604
|
});
|
|
1605
1605
|
|
|
1606
1606
|
// src/memory/topics-history/index.ts
|
|
1607
|
-
import { DatabaseSync as
|
|
1607
|
+
import { DatabaseSync as DatabaseSync9 } from "node:sqlite";
|
|
1608
1608
|
var init_topics_history = __esm({
|
|
1609
1609
|
"src/memory/topics-history/index.ts"() {
|
|
1610
1610
|
"use strict";
|
|
@@ -1628,26 +1628,26 @@ var init_timing = __esm({
|
|
|
1628
1628
|
});
|
|
1629
1629
|
|
|
1630
1630
|
// src/continuity/publication-main.ts
|
|
1631
|
-
import { DatabaseSync as
|
|
1631
|
+
import { DatabaseSync as DatabaseSync20 } from "node:sqlite";
|
|
1632
1632
|
import { readFileSync as readFileSync9, writeFileSync as writeFileSync15, lstatSync as lstatSync19, realpathSync as realpathSync14 } from "node:fs";
|
|
1633
|
-
import { isAbsolute as isAbsolute5, resolve as resolve22, join as
|
|
1633
|
+
import { isAbsolute as isAbsolute5, resolve as resolve22, join as join24, dirname as dirname14 } from "node:path";
|
|
1634
1634
|
import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
1635
1635
|
import { X509Certificate } from "node:crypto";
|
|
1636
1636
|
|
|
1637
1637
|
// src/continuity/key-service-store.ts
|
|
1638
1638
|
import { DatabaseSync } from "node:sqlite";
|
|
1639
1639
|
import { constants, lstatSync, mkdirSync, openSync, closeSync, readFileSync, writeSync, fstatSync, fsyncSync, unlinkSync } from "node:fs";
|
|
1640
|
-
function assertPrivateStat(
|
|
1641
|
-
if ((directory2 ? !
|
|
1640
|
+
function assertPrivateStat(stat2, directory2) {
|
|
1641
|
+
if ((directory2 ? !stat2.isDirectory() : !stat2.isFile()) || process.platform !== "win32" && ((stat2.mode & 63) !== 0 || stat2.uid !== process.getuid?.()))
|
|
1642
1642
|
throw new Error("KEY_SERVICE_PRIVATE_PATH_REQUIRED");
|
|
1643
1643
|
}
|
|
1644
1644
|
function readPrivateFile(path3, maximumBytes = 65536) {
|
|
1645
1645
|
assertPrivateStat(lstatSync(path3), false);
|
|
1646
1646
|
const fd = openSync(path3, constants.O_RDONLY | (constants.O_NOFOLLOW ?? 0));
|
|
1647
1647
|
try {
|
|
1648
|
-
const
|
|
1649
|
-
assertPrivateStat(
|
|
1650
|
-
if (
|
|
1648
|
+
const stat2 = fstatSync(fd);
|
|
1649
|
+
assertPrivateStat(stat2, false);
|
|
1650
|
+
if (stat2.size > maximumBytes) throw new Error("KEY_SERVICE_INVALID_FILE_SIZE");
|
|
1651
1651
|
return readFileSync(fd);
|
|
1652
1652
|
} finally {
|
|
1653
1653
|
closeSync(fd);
|
|
@@ -2201,10 +2201,11 @@ var STATE_EXCLUDED = {
|
|
|
2201
2201
|
var NESTED_EXCLUDED = { ".git": "source control metadata", node_modules: "installed dependencies", __pycache__: "Python bytecode cache" };
|
|
2202
2202
|
var WORKSPACE_DIAGNOSTICS = /* @__PURE__ */ new Set([".system-prompt.txt", ".context-debug.txt"]);
|
|
2203
2203
|
var RUNTIME_CONTROL = /* @__PURE__ */ new Set([".continuity", ".engine.pid", ".bg-worker.pid", ".travel-restored.json", ".travel-enrolled.json", ".travel-active.json"]);
|
|
2204
|
-
var CORE_DIRECTORIES = new Set(`agents auth configs cron mem7 memory runtime session-memory steer tasks teams todos tools .everos .calendar calendar .proactive proactive skills prompts .nudge hooks inner-voice goals plans private scripts state .voice-chat .desktopBuddy body`.split(" "));
|
|
2204
|
+
var CORE_DIRECTORIES = new Set(`agents auth configs cron mem7 memory runtime session-memory steer tasks teams todos tools .everos .calendar calendar .proactive proactive skills prompts topics .nudge hooks inner-voice goals plans private scripts state .voice-chat .desktopBuddy body`.split(" "));
|
|
2205
2205
|
var CORE_OMITTED = new Set(`media images videos audio content content-library docs output outputs dogfood-output backup backups topics-history node_modules .venvs venv .venv asr .cache cache caches tmp temp .playwright-mcp lancedb`.split(" "));
|
|
2206
2206
|
function coreReason(path3) {
|
|
2207
2207
|
const name = path3.split("/").at(-1);
|
|
2208
|
+
if (path3 === "chan7-files" || path3.startsWith("chan7-files/")) return void 0;
|
|
2208
2209
|
if (CORE_OMITTED.has(name) || /(?:\.lance$|(?:^|[-.])bak(?:[-.]|$))/i.test(name)) return "optional attachments, historical copies or rebuildable indexes; outside core travel";
|
|
2209
2210
|
if (/\.(?:mp4|mov|mkv|webm|avi|m4v|mp3|wav|ogg|opus|m4a|aac|flac|png|jpe?g|gif|webp|heic|bmp|tiff?|ico|pdf|docx?|pptx?|xlsx?|zip|gz|tgz|tar|7z|rar|dmg|exe|dll|so|dylib|bin|onnx|safetensors|gguf|vrm|glb|gltf|fbx|ttf|otf|woff2?|pyc|log|out)$/i.test(name) || name === ".DS_Store" || name === "package-lock.json" || name === ".context-debug.txt" || path3 === "mem7/spool/intake.failed.jsonl") return "attachments, installed binaries or diagnostics; outside core travel";
|
|
2210
2211
|
}
|
|
@@ -2536,8 +2537,8 @@ var PublicationReplica = class _PublicationReplica {
|
|
|
2536
2537
|
}
|
|
2537
2538
|
assertJournal() {
|
|
2538
2539
|
try {
|
|
2539
|
-
const
|
|
2540
|
-
if (!
|
|
2540
|
+
const stat2 = lstatSync3(this.journalFile, { bigint: true });
|
|
2541
|
+
if (!stat2.isFile() || stat2.isSymbolicLink() || `${stat2.dev}:${stat2.ino}` !== this.journalIncarnation) throw new Error();
|
|
2541
2542
|
} catch {
|
|
2542
2543
|
throw new Error("PUBLICATION_CORRUPT_CONTROL");
|
|
2543
2544
|
}
|
|
@@ -2741,9 +2742,9 @@ var PublicationReplica = class _PublicationReplica {
|
|
|
2741
2742
|
};
|
|
2742
2743
|
|
|
2743
2744
|
// src/continuity/publication-files.ts
|
|
2744
|
-
import { DatabaseSync as
|
|
2745
|
+
import { DatabaseSync as DatabaseSync5 } from "node:sqlite";
|
|
2745
2746
|
import { lstatSync as lstatSync4, readdirSync, realpathSync as realpathSync2, mkdirSync as mkdirSync3, writeFileSync, chmodSync, openSync as openSync4, closeSync as closeSync3, fsyncSync as fsyncSync3 } from "node:fs";
|
|
2746
|
-
import { join as
|
|
2747
|
+
import { join as join5, resolve as resolve4, dirname as dirname3 } from "node:path";
|
|
2747
2748
|
|
|
2748
2749
|
// src/continuity/crypto.ts
|
|
2749
2750
|
import { constants as constants4, createWriteStream, openSync as openSync3 } from "node:fs";
|
|
@@ -2760,12 +2761,77 @@ async function syncDirectory(directory2) {
|
|
|
2760
2761
|
}
|
|
2761
2762
|
}
|
|
2762
2763
|
|
|
2764
|
+
// src/continuity/native-database-snapshot.ts
|
|
2765
|
+
import { DatabaseSync as DatabaseSync4, backup } from "node:sqlite";
|
|
2766
|
+
import { lstat as lstat3 } from "node:fs/promises";
|
|
2767
|
+
|
|
2768
|
+
// src/continuity/native-file-copy.ts
|
|
2769
|
+
import { constants as constants5 } from "node:fs";
|
|
2770
|
+
import { copyFile, link as link3, rename, rm, stat } from "node:fs/promises";
|
|
2771
|
+
import { execFile } from "node:child_process";
|
|
2772
|
+
import { promisify } from "node:util";
|
|
2773
|
+
import { dirname as dirname2, join as join4 } from "node:path";
|
|
2774
|
+
import { randomUUID as randomUUID2 } from "node:crypto";
|
|
2775
|
+
var exec = promisify(execFile);
|
|
2776
|
+
async function copyNativeFile(source, destination, flags = constants5.COPYFILE_EXCL | constants5.COPYFILE_FICLONE, bytes) {
|
|
2777
|
+
if (process.platform !== "darwin") {
|
|
2778
|
+
await copyFile(source, destination, flags);
|
|
2779
|
+
return;
|
|
2780
|
+
}
|
|
2781
|
+
if ((bytes ?? (await stat(source)).size) < 1024 * 1024) {
|
|
2782
|
+
await copyFile(source, destination, flags);
|
|
2783
|
+
return;
|
|
2784
|
+
}
|
|
2785
|
+
const temporary = join4(dirname2(destination), ".e7-native-copy-" + randomUUID2());
|
|
2786
|
+
try {
|
|
2787
|
+
await exec("/bin/cp", ["-c", "-p", source, temporary], { maxBuffer: 8192 });
|
|
2788
|
+
if (flags & constants5.COPYFILE_EXCL) await link3(temporary, destination);
|
|
2789
|
+
else await rename(temporary, destination);
|
|
2790
|
+
} finally {
|
|
2791
|
+
await rm(temporary, { force: true });
|
|
2792
|
+
}
|
|
2793
|
+
}
|
|
2794
|
+
|
|
2795
|
+
// src/continuity/native-database-snapshot.ts
|
|
2796
|
+
async function snapshotNativeDatabase(db, destination) {
|
|
2797
|
+
if (process.platform !== "darwin") {
|
|
2798
|
+
await backup(db, destination);
|
|
2799
|
+
return;
|
|
2800
|
+
}
|
|
2801
|
+
const file = String(db.prepare("PRAGMA database_list").all().find((row) => row.name === "main")?.file ?? "");
|
|
2802
|
+
if (!file) {
|
|
2803
|
+
await backup(db, destination);
|
|
2804
|
+
return;
|
|
2805
|
+
}
|
|
2806
|
+
const reader = new DatabaseSync4(file, { readOnly: true, allowExtension: true });
|
|
2807
|
+
try {
|
|
2808
|
+
reader.exec("BEGIN");
|
|
2809
|
+
reader.prepare("SELECT count(*) FROM sqlite_master").get();
|
|
2810
|
+
await copyNativeFile(file, destination);
|
|
2811
|
+
try {
|
|
2812
|
+
await lstat3(file + "-wal");
|
|
2813
|
+
await copyNativeFile(file + "-wal", destination + "-wal");
|
|
2814
|
+
} catch (error) {
|
|
2815
|
+
if (error.code !== "ENOENT") throw error;
|
|
2816
|
+
}
|
|
2817
|
+
reader.exec("ROLLBACK");
|
|
2818
|
+
} finally {
|
|
2819
|
+
reader.close();
|
|
2820
|
+
}
|
|
2821
|
+
const target = new DatabaseSync4(destination);
|
|
2822
|
+
try {
|
|
2823
|
+
if (Number(target.prepare("PRAGMA wal_checkpoint(TRUNCATE)").get()?.busy) !== 0) throw Error("DATABASE_SNAPSHOT_BUSY");
|
|
2824
|
+
} finally {
|
|
2825
|
+
target.close();
|
|
2826
|
+
}
|
|
2827
|
+
}
|
|
2828
|
+
|
|
2763
2829
|
// src/continuity/publication-files.ts
|
|
2764
2830
|
function inventory(root) {
|
|
2765
2831
|
if (realpathSync2(root) !== resolve4(root)) throw new Error("SYMLINK_REFUSED");
|
|
2766
2832
|
const entries = [];
|
|
2767
2833
|
const visit = (path3) => {
|
|
2768
|
-
const info = lstatSync4(
|
|
2834
|
+
const info = lstatSync4(join5(root, path3), { bigint: true });
|
|
2769
2835
|
if (info.isSymbolicLink()) throw new Error("SYMLINK_REFUSED");
|
|
2770
2836
|
if (!info.isDirectory() && !info.isFile()) throw new Error("PUBLICATION_NOT_REGULAR_FILE");
|
|
2771
2837
|
if (path3) validatePublicationPath(path3);
|
|
@@ -2776,7 +2842,7 @@ function inventory(root) {
|
|
|
2776
2842
|
mode: info.mode & 0o100n ? 448 : 384,
|
|
2777
2843
|
signature: [info.dev, info.ino, info.size, info.mtimeNs, info.ctimeNs, info.mode].map(String).join(":")
|
|
2778
2844
|
});
|
|
2779
|
-
if (info.isDirectory()) for (const name of readdirSync(
|
|
2845
|
+
if (info.isDirectory()) for (const name of readdirSync(join5(root, path3)).sort()) visit(path3 ? path3 + "/" + name : name);
|
|
2780
2846
|
};
|
|
2781
2847
|
visit("");
|
|
2782
2848
|
if (!entries[0].directory) throw new Error("PUBLICATION_DIRECTORY_REQUIRED");
|
|
@@ -2797,7 +2863,7 @@ async function capturePublication(options) {
|
|
|
2797
2863
|
for (const entry of entries) {
|
|
2798
2864
|
if (!entry.path) continue;
|
|
2799
2865
|
if (entry.directory) tree.directories.push(entry.path);
|
|
2800
|
-
else tree.files.push({ path: entry.path, mode: entry.mode, content: await options.objects.captureFile(
|
|
2866
|
+
else tree.files.push({ path: entry.path, mode: entry.mode, content: await options.objects.captureFile(join5(root.path, entry.path)) });
|
|
2801
2867
|
}
|
|
2802
2868
|
trees.push(tree);
|
|
2803
2869
|
}
|
|
@@ -2818,7 +2884,7 @@ async function restorePublication(options) {
|
|
|
2818
2884
|
const manifest = await receiver.manifest(status.published.sequence);
|
|
2819
2885
|
if (JSON.stringify(Object.keys(options.databases).sort()) !== JSON.stringify(manifest.profile.databaseIds)) throw new Error("PUBLICATION_INCOMPLETE_DATABASES");
|
|
2820
2886
|
const destination = resolve4(options.destination);
|
|
2821
|
-
if (realpathSync2(
|
|
2887
|
+
if (realpathSync2(dirname3(destination)) !== dirname3(destination)) throw new Error("SYMLINK_REFUSED");
|
|
2822
2888
|
if (isWithin(receiver.objects.directory, destination) || isWithin(destination, receiver.objects.directory)) throw new Error("PUBLICATION_OVERLAPPING_PATHS");
|
|
2823
2889
|
try {
|
|
2824
2890
|
mkdirSync3(destination, { mode: 448 });
|
|
@@ -2826,8 +2892,8 @@ async function restorePublication(options) {
|
|
|
2826
2892
|
if (error.code === "EEXIST") throw new Error("CONTINUITY_DESTINATION_EXISTS");
|
|
2827
2893
|
throw error;
|
|
2828
2894
|
}
|
|
2829
|
-
await syncDirectory(
|
|
2830
|
-
writeFileSync(
|
|
2895
|
+
await syncDirectory(dirname3(destination));
|
|
2896
|
+
writeFileSync(join5(destination, ".travel-restored.json"), JSON.stringify({
|
|
2831
2897
|
format: "engine7-publication-restore-v1",
|
|
2832
2898
|
activationAllowed: false,
|
|
2833
2899
|
sequence: manifest.sequence,
|
|
@@ -2837,19 +2903,19 @@ async function restorePublication(options) {
|
|
|
2837
2903
|
const created = /* @__PURE__ */ new Set([destination]);
|
|
2838
2904
|
const directory2 = (path3) => {
|
|
2839
2905
|
const missing = [];
|
|
2840
|
-
for (let current2 = path3; isWithin(destination, current2) && !created.has(current2); current2 =
|
|
2906
|
+
for (let current2 = path3; isWithin(destination, current2) && !created.has(current2); current2 = dirname3(current2)) missing.push(current2);
|
|
2841
2907
|
for (const current2 of missing.reverse()) {
|
|
2842
2908
|
mkdirSync3(current2, { mode: 448 });
|
|
2843
2909
|
created.add(current2);
|
|
2844
2910
|
}
|
|
2845
2911
|
};
|
|
2846
|
-
directory2(
|
|
2847
|
-
directory2(
|
|
2912
|
+
directory2(join5(destination, "databases"));
|
|
2913
|
+
directory2(join5(destination, "trees"));
|
|
2848
2914
|
for (const item of manifest.databases) {
|
|
2849
|
-
const path3 =
|
|
2850
|
-
await
|
|
2915
|
+
const path3 = join5(destination, "databases", item.databaseId + ".sqlite");
|
|
2916
|
+
await snapshotNativeDatabase(options.databases[item.databaseId], path3);
|
|
2851
2917
|
chmodSync(path3, 384);
|
|
2852
|
-
const copy = new
|
|
2918
|
+
const copy = new DatabaseSync5(path3, { readOnly: true });
|
|
2853
2919
|
try {
|
|
2854
2920
|
const row = copy.prepare("SELECT head,digest,binding FROM e7_replication_control WHERE role='replica'").get();
|
|
2855
2921
|
const identity = manifest.profile.identity;
|
|
@@ -2868,12 +2934,12 @@ async function restorePublication(options) {
|
|
|
2868
2934
|
}
|
|
2869
2935
|
const files = [];
|
|
2870
2936
|
for (const tree of manifest.trees) {
|
|
2871
|
-
const root =
|
|
2937
|
+
const root = join5(destination, "trees", tree.id);
|
|
2872
2938
|
directory2(root);
|
|
2873
|
-
for (const path3 of tree.directories) directory2(
|
|
2939
|
+
for (const path3 of tree.directories) directory2(join5(root, path3));
|
|
2874
2940
|
for (const file of tree.files) {
|
|
2875
|
-
const path3 =
|
|
2876
|
-
directory2(
|
|
2941
|
+
const path3 = join5(root, file.path);
|
|
2942
|
+
directory2(dirname3(path3));
|
|
2877
2943
|
files.push({ content: file.content, destination: path3, mode: file.mode });
|
|
2878
2944
|
}
|
|
2879
2945
|
}
|
|
@@ -2886,7 +2952,7 @@ async function restorePublication(options) {
|
|
|
2886
2952
|
const after = await receiver.status(false);
|
|
2887
2953
|
if (!after.dataReady || after.published?.digest !== status.published.digest) throw new Error("PUBLICATION_CONCURRENT_CHANGE");
|
|
2888
2954
|
for (const path3 of [...created].reverse()) await syncDirectory(path3);
|
|
2889
|
-
if (!options.deferReceipt) writeFileSync(
|
|
2955
|
+
if (!options.deferReceipt) writeFileSync(join5(destination, ".publication-receipt.json"), JSON.stringify(status.published), { flag: "wx", mode: 384, flush: true });
|
|
2890
2956
|
await syncDirectory(destination);
|
|
2891
2957
|
return status.published;
|
|
2892
2958
|
}
|
|
@@ -3281,13 +3347,13 @@ async function syncPublication(options) {
|
|
|
3281
3347
|
init_sqlite_replication();
|
|
3282
3348
|
|
|
3283
3349
|
// src/continuity/sqlite-store-location.ts
|
|
3284
|
-
import { basename as basename3, dirname as
|
|
3350
|
+
import { basename as basename3, dirname as dirname7, resolve as resolve7 } from "node:path";
|
|
3285
3351
|
|
|
3286
3352
|
// src/continuity/mem7-replication.ts
|
|
3287
3353
|
import { closeSync as closeSync5, fsyncSync as fsyncSync5, lstatSync as lstatSync6, openSync as openSync6, writeFileSync as writeFileSync3 } from "node:fs";
|
|
3288
|
-
import { dirname as
|
|
3354
|
+
import { dirname as dirname5, join as join7 } from "node:path";
|
|
3289
3355
|
init_sqlite_replication();
|
|
3290
|
-
var location = (stateDir) =>
|
|
3356
|
+
var location = (stateDir) => join7(stateDir, ".continuity", "mem7-replication.json");
|
|
3291
3357
|
function normalize(value2) {
|
|
3292
3358
|
if (!value2 || !/^[a-f0-9]{64}$/.test(value2.schemaHash)) throw new Error("REPLICATION_REGISTRATION_INVALID");
|
|
3293
3359
|
return Object.freeze({ binding: normalizeBinding(value2.binding), schemaHash: value2.schemaHash });
|
|
@@ -3304,7 +3370,7 @@ function hasMem7ReplicationRegistration(stateDir) {
|
|
|
3304
3370
|
function readMem7ReplicationRegistration(stateDir) {
|
|
3305
3371
|
if (!hasMem7ReplicationRegistration(stateDir)) return null;
|
|
3306
3372
|
try {
|
|
3307
|
-
assertPrivateDirectory(
|
|
3373
|
+
assertPrivateDirectory(dirname5(location(stateDir)));
|
|
3308
3374
|
return normalize(JSON.parse(readPrivateFile(location(stateDir), 4096).toString()));
|
|
3309
3375
|
} catch {
|
|
3310
3376
|
throw new Error("REPLICATION_REGISTRATION_INVALID");
|
|
@@ -3314,24 +3380,24 @@ function readMem7ReplicationRegistration(stateDir) {
|
|
|
3314
3380
|
// src/continuity/sqlite-store-location.ts
|
|
3315
3381
|
init_runtime_replication();
|
|
3316
3382
|
function sqliteStoreLocation(file) {
|
|
3317
|
-
const absolute4 = resolve7(file), parent =
|
|
3318
|
-
if (name === "mem7.db" && basename3(parent) === "index" && basename3(
|
|
3319
|
-
return { stateDir:
|
|
3383
|
+
const absolute4 = resolve7(file), parent = dirname7(absolute4), name = basename3(absolute4);
|
|
3384
|
+
if (name === "mem7.db" && basename3(parent) === "index" && basename3(dirname7(parent)) === "mem7")
|
|
3385
|
+
return { stateDir: dirname7(dirname7(parent)), component: "mem7" };
|
|
3320
3386
|
let stateDir, component;
|
|
3321
3387
|
if (name === "calendar.db" && basename3(parent) === ".calendar") {
|
|
3322
|
-
stateDir =
|
|
3388
|
+
stateDir = dirname7(parent);
|
|
3323
3389
|
component = "calendar";
|
|
3324
3390
|
} else if (name === "proactive.db" && basename3(parent) === ".proactive") {
|
|
3325
|
-
stateDir =
|
|
3391
|
+
stateDir = dirname7(parent);
|
|
3326
3392
|
component = "proactive";
|
|
3327
3393
|
} else if (name === "session-events.db" && basename3(parent) === ".continuity") {
|
|
3328
|
-
stateDir =
|
|
3394
|
+
stateDir = dirname7(parent);
|
|
3329
3395
|
component = "session-events";
|
|
3330
|
-
} else if (name === "memory.db" && basename3(parent) === "memory" && basename3(
|
|
3331
|
-
stateDir =
|
|
3396
|
+
} else if (name === "memory.db" && basename3(parent) === "memory" && basename3(dirname7(dirname7(parent))) === "agents") {
|
|
3397
|
+
stateDir = dirname7(dirname7(dirname7(parent)));
|
|
3332
3398
|
component = "legacy-memory";
|
|
3333
|
-
} else if (name === "vectors.db" && basename3(
|
|
3334
|
-
stateDir =
|
|
3399
|
+
} else if (name === "vectors.db" && basename3(dirname7(parent)) === "topics-history") {
|
|
3400
|
+
stateDir = dirname7(dirname7(parent));
|
|
3335
3401
|
component = "topics-vectors";
|
|
3336
3402
|
} else return null;
|
|
3337
3403
|
return { stateDir, ...runtimeReplicationLocation(stateDir, component, absolute4) };
|
|
@@ -3395,15 +3461,15 @@ init_runtime_lock();
|
|
|
3395
3461
|
init_schema_migrations();
|
|
3396
3462
|
|
|
3397
3463
|
// src/continuity/runtime-artifact-cli.ts
|
|
3398
|
-
import { DatabaseSync as
|
|
3399
|
-
import { isAbsolute as isAbsolute2, join as
|
|
3464
|
+
import { DatabaseSync as DatabaseSync12 } from "node:sqlite";
|
|
3465
|
+
import { isAbsolute as isAbsolute2, join as join15, resolve as resolve13 } from "node:path";
|
|
3400
3466
|
import { lstatSync as lstatSync13, realpathSync as realpathSync9 } from "node:fs";
|
|
3401
3467
|
|
|
3402
3468
|
// src/continuity/runtime-tree-source.ts
|
|
3403
|
-
import { DatabaseSync as
|
|
3469
|
+
import { DatabaseSync as DatabaseSync6 } from "node:sqlite";
|
|
3404
3470
|
import { createHash as createHash5 } from "node:crypto";
|
|
3405
3471
|
import { existsSync as existsSync2, writeFileSync as writeFileSync5, openSync as openSync9, closeSync as closeSync8, fsyncSync as fsyncSync7 } from "node:fs";
|
|
3406
|
-
import { join as
|
|
3472
|
+
import { join as join10, resolve as resolve8 } from "node:path";
|
|
3407
3473
|
var ZERO2 = "0".repeat(64);
|
|
3408
3474
|
var HASH3 = /^[a-f0-9]{64}$/;
|
|
3409
3475
|
var schema = [
|
|
@@ -3435,7 +3501,7 @@ var RuntimeTreeSource = class _RuntimeTreeSource {
|
|
|
3435
3501
|
if (JSON.stringify(this.profile.identity) !== JSON.stringify(this.objects.identity)) throw new Error("TREE_SOURCE_PROFILE_MISMATCH");
|
|
3436
3502
|
this.maximumBytes = options.maximumBytes ?? 64 * 1024 * 1024;
|
|
3437
3503
|
if (!Number.isSafeInteger(this.maximumBytes) || this.maximumBytes < 1) throw new Error("TREE_SOURCE_INVALID_LIMIT");
|
|
3438
|
-
const directory2 = resolve8(options.directory), marker =
|
|
3504
|
+
const directory2 = resolve8(options.directory), marker = join10(directory2, "source.json"), file = join10(directory2, "trees.sqlite");
|
|
3439
3505
|
if (options.initialize) preparePrivateDirectory(directory2);
|
|
3440
3506
|
else {
|
|
3441
3507
|
try {
|
|
@@ -3453,7 +3519,7 @@ var RuntimeTreeSource = class _RuntimeTreeSource {
|
|
|
3453
3519
|
}
|
|
3454
3520
|
preparePrivateDatabase(file);
|
|
3455
3521
|
try {
|
|
3456
|
-
this.db = new
|
|
3522
|
+
this.db = new DatabaseSync6(file);
|
|
3457
3523
|
this.db.exec("PRAGMA synchronous=FULL; PRAGMA busy_timeout=5000");
|
|
3458
3524
|
if (fresh) {
|
|
3459
3525
|
this.db.exec("BEGIN IMMEDIATE");
|
|
@@ -3584,7 +3650,7 @@ var RuntimeTreeSource = class _RuntimeTreeSource {
|
|
|
3584
3650
|
// src/continuity/runtime-files.ts
|
|
3585
3651
|
import { lstatSync as lstatSync9, realpathSync as realpathSync5 } from "node:fs";
|
|
3586
3652
|
import { relative as relative2, resolve as resolve9 } from "node:path";
|
|
3587
|
-
import { DatabaseSync as
|
|
3653
|
+
import { DatabaseSync as DatabaseSync7 } from "node:sqlite";
|
|
3588
3654
|
import { createHash as createHash6 } from "node:crypto";
|
|
3589
3655
|
init_runtime_replication();
|
|
3590
3656
|
import { setImmediate as setImmediate2 } from "node:timers/promises";
|
|
@@ -3599,6 +3665,8 @@ async function runtimeFileEntries(options) {
|
|
|
3599
3665
|
excludeStateEntries: { ...options.inventory.excludeStateEntries },
|
|
3600
3666
|
excludeWorkspaceEntries: { ...options.inventory.excludeWorkspaceEntries }
|
|
3601
3667
|
};
|
|
3668
|
+
for (const path3 of ["mem7/spool/intake.write.lock", "mem7/spool/intake.write.lock.reap"])
|
|
3669
|
+
inventoryOptions.excludeStateEntries[path3] = "local queue writer ownership; recreated per process";
|
|
3602
3670
|
for (const directory2 of [...options.vectorDirectories, ...options.sessionDirectories].map(resolvePath)) {
|
|
3603
3671
|
const info = lstatSync9(directory2);
|
|
3604
3672
|
if (!info.isDirectory() || info.isSymbolicLink() || realpathSync5(directory2) !== directory2) throw new Error("SYMLINK_REFUSED");
|
|
@@ -3616,23 +3684,24 @@ async function runtimeFileEntries(options) {
|
|
|
3616
3684
|
const registration = place?.component === "session-events" ? readSQLiteStoreRegistration(place) : null;
|
|
3617
3685
|
if (!place || !registration || !isWithin(state2, place.stateDir) && !isWithin(workspace, place.stateDir)) throw new Error("RUNTIME_REGISTERED_PATH_MISSING");
|
|
3618
3686
|
checkRuntimeReplicationFile(file, registration);
|
|
3619
|
-
const db = new
|
|
3687
|
+
const db = new DatabaseSync7(file, { readOnly: true });
|
|
3620
3688
|
try {
|
|
3621
3689
|
checkRuntimeReplicationDatabase(db, registration, "session-events", 1);
|
|
3622
3690
|
} finally {
|
|
3623
3691
|
db.close();
|
|
3624
3692
|
}
|
|
3625
3693
|
}
|
|
3626
|
-
|
|
3627
|
-
for (const entry of inventory3.entries) {
|
|
3628
|
-
if (/\.lance(?:\/|$)/i.test(entry.path)) throw new Error("RUNTIME_UNCLASSIFIED_LANCE");
|
|
3629
|
-
if (entry.kind === "sidecar" && immutable.has(entry.source.replace(/-(wal|shm|journal)$/, ""))) throw new Error("RUNTIME_IMMUTABLE_DATABASE_HAS_SIDECAR");
|
|
3630
|
-
}
|
|
3631
|
-
return inventory3.entries.filter((entry) => entry.kind === "directory" || entry.kind === "file" || immutable.has(entry.source));
|
|
3694
|
+
return inventory3.entries.filter((entry) => entry.kind === "directory" || entry.kind === "file" || immutable.has(entry.source) || entry.kind === "sqlite" && !dynamic.has(entry.source));
|
|
3632
3695
|
};
|
|
3633
3696
|
return await classify();
|
|
3634
3697
|
}
|
|
3635
|
-
var signatures = (entries) => entries.map((entry) => [
|
|
3698
|
+
var signatures = (entries) => entries.map((entry) => [
|
|
3699
|
+
entry.root,
|
|
3700
|
+
entry.path,
|
|
3701
|
+
entry.kind,
|
|
3702
|
+
entry.mode,
|
|
3703
|
+
entry.kind === "directory" ? entry.signature.split(":").slice(0, -3).join(":") : entry.signature
|
|
3704
|
+
]);
|
|
3636
3705
|
async function runtimeFileFingerprint(options) {
|
|
3637
3706
|
return createHash6("sha256").update(JSON.stringify(signatures(await runtimeFileEntries(options)))).digest("hex");
|
|
3638
3707
|
}
|
|
@@ -3673,17 +3742,17 @@ function resolvePath(path3) {
|
|
|
3673
3742
|
// src/continuity/lance-publication.ts
|
|
3674
3743
|
import { createHash as createHash11 } from "node:crypto";
|
|
3675
3744
|
import { lstatSync as lstatSync10, readdirSync as readdirSync2, realpathSync as realpathSync6, mkdirSync as mkdirSync7, writeFileSync as writeFileSync7, openSync as openSync10, closeSync as closeSync9, fsyncSync as fsyncSync8, chmodSync as chmodSync2 } from "node:fs";
|
|
3676
|
-
import { join as
|
|
3745
|
+
import { join as join12, resolve as resolve10, dirname as dirname9, relative as relative3 } from "node:path";
|
|
3677
3746
|
import { createRequire as createRequire5 } from "node:module";
|
|
3678
3747
|
|
|
3679
3748
|
// src/mem7/core/vector-store.ts
|
|
3680
|
-
import { DatabaseSync as
|
|
3749
|
+
import { DatabaseSync as DatabaseSync11 } from "node:sqlite";
|
|
3681
3750
|
|
|
3682
3751
|
// src/mem7/core/store.ts
|
|
3683
3752
|
init_runtime_lock();
|
|
3684
3753
|
init_runtime_authority();
|
|
3685
3754
|
init_sqlite_replication();
|
|
3686
|
-
import { DatabaseSync as
|
|
3755
|
+
import { DatabaseSync as DatabaseSync10 } from "node:sqlite";
|
|
3687
3756
|
init_sqlite_autocommit();
|
|
3688
3757
|
init_schema_migrations();
|
|
3689
3758
|
|
|
@@ -3700,7 +3769,7 @@ init_schema_migrations();
|
|
|
3700
3769
|
init_scope();
|
|
3701
3770
|
|
|
3702
3771
|
// src/mem7/core/change-feed.ts
|
|
3703
|
-
import { createHash as createHash7, randomUUID as
|
|
3772
|
+
import { createHash as createHash7, randomUUID as randomUUID5 } from "node:crypto";
|
|
3704
3773
|
import { existsSync as existsSync3, readFileSync as readFileSync5, renameSync as renameSync2, unlinkSync as unlinkSync2, writeFileSync as writeFileSync6 } from "node:fs";
|
|
3705
3774
|
|
|
3706
3775
|
// src/mem7/core/state/temporal.ts
|
|
@@ -3931,7 +4000,7 @@ var ChangeFeed = class _ChangeFeed {
|
|
|
3931
4000
|
const cutoff = now2 - _ChangeFeed.GAP_HEAL_RETENTION_MS, retained = {};
|
|
3932
4001
|
for (const [entry, at] of Object.entries(ledger)) if (Number.isFinite(at) && at >= cutoff) retained[entry] = at;
|
|
3933
4002
|
retained[key2] = now2;
|
|
3934
|
-
const temp = `${ledgerPath}.${
|
|
4003
|
+
const temp = `${ledgerPath}.${randomUUID5()}.tmp`;
|
|
3935
4004
|
try {
|
|
3936
4005
|
writeFileSync6(temp, JSON.stringify({ version: 1, heals: retained }));
|
|
3937
4006
|
renameSync2(temp, ledgerPath);
|
|
@@ -4179,8 +4248,8 @@ var RecoveryDeletionGraph = class {
|
|
|
4179
4248
|
|
|
4180
4249
|
// src/mem7/core/host-turns.ts
|
|
4181
4250
|
init_scope();
|
|
4182
|
-
import { randomUUID as
|
|
4183
|
-
var processOwnerId =
|
|
4251
|
+
import { randomUUID as randomUUID6, createHash as createHash10 } from "node:crypto";
|
|
4252
|
+
var processOwnerId = randomUUID6();
|
|
4184
4253
|
var currentSource = `EXISTS (SELECT 1 FROM memory_sources s WHERE s.scope_id=memory_host_turns.scope_id
|
|
4185
4254
|
AND s.source_id=memory_host_turns.source_id AND s.role='user' AND s.origin_class='host_user' AND s.interpretation_status<>'deleted'
|
|
4186
4255
|
AND NOT EXISTS (SELECT 1 FROM memory_sources newer WHERE newer.scope_id=s.scope_id AND newer.origin_key=s.origin_key
|
|
@@ -4213,9 +4282,9 @@ init_scope();
|
|
|
4213
4282
|
|
|
4214
4283
|
// src/mem7/core/episode.ts
|
|
4215
4284
|
import { readFileSync as readFileSync6 } from "node:fs";
|
|
4216
|
-
import { join as
|
|
4285
|
+
import { join as join11, dirname as dirname8 } from "node:path";
|
|
4217
4286
|
import { fileURLToPath } from "node:url";
|
|
4218
|
-
var PROMPT = readFileSync6(
|
|
4287
|
+
var PROMPT = readFileSync6(join11(dirname8(fileURLToPath(import.meta.url)), "prompts", "episode.md"), "utf8");
|
|
4219
4288
|
|
|
4220
4289
|
// src/mem7/core/relationship-cognition.ts
|
|
4221
4290
|
init_scope();
|
|
@@ -4259,8 +4328,8 @@ init_scope();
|
|
|
4259
4328
|
|
|
4260
4329
|
// src/mem7/core/job-retention.ts
|
|
4261
4330
|
import { gzip, gunzipSync } from "node:zlib";
|
|
4262
|
-
import { promisify } from "node:util";
|
|
4263
|
-
var compress =
|
|
4331
|
+
import { promisify as promisify2 } from "node:util";
|
|
4332
|
+
var compress = promisify2(gzip);
|
|
4264
4333
|
var kinds = [
|
|
4265
4334
|
"boundary",
|
|
4266
4335
|
"source.interpret",
|
|
@@ -4443,7 +4512,7 @@ function assertSource(directory2) {
|
|
|
4443
4512
|
if (info.isSymbolicLink()) throw new Error("SYMLINK_REFUSED");
|
|
4444
4513
|
if (!info.isDirectory() && !info.isFile()) throw new Error("LANCE_PUBLICATION_SPECIAL_FILE");
|
|
4445
4514
|
signatures2.push([relative3(directory2, path3), ...[info.dev, info.ino, info.size, info.mode, info.mtimeNs, info.ctimeNs].map(String)]);
|
|
4446
|
-
if (info.isDirectory()) for (const name of readdirSync2(path3).sort()) visit(
|
|
4515
|
+
if (info.isDirectory()) for (const name of readdirSync2(path3).sort()) visit(join12(path3, name), depth + 1);
|
|
4447
4516
|
};
|
|
4448
4517
|
visit(directory2, 0);
|
|
4449
4518
|
return sha3(JSON.stringify(signatures2));
|
|
@@ -4476,7 +4545,7 @@ function durablePrivateTree(directory2) {
|
|
|
4476
4545
|
const visit = (path3) => {
|
|
4477
4546
|
const info = lstatSync10(path3);
|
|
4478
4547
|
if (info.isSymbolicLink() || !info.isDirectory() && !info.isFile()) throw new Error("SYMLINK_REFUSED");
|
|
4479
|
-
if (info.isDirectory()) for (const name of readdirSync2(path3)) visit(
|
|
4548
|
+
if (info.isDirectory()) for (const name of readdirSync2(path3)) visit(join12(path3, name));
|
|
4480
4549
|
chmodSync2(path3, info.isDirectory() ? 448 : 384);
|
|
4481
4550
|
if (process.platform !== "win32" || info.isFile()) {
|
|
4482
4551
|
const fd = openSync10(path3, "r");
|
|
@@ -4588,7 +4657,7 @@ async function readManifest(tree, objects) {
|
|
|
4588
4657
|
}
|
|
4589
4658
|
async function restoreLancePublication(options) {
|
|
4590
4659
|
const destination = resolve10(options.destination);
|
|
4591
|
-
if (realpathSync6(
|
|
4660
|
+
if (realpathSync6(dirname9(destination)) !== dirname9(destination)) throw new Error("SYMLINK_REFUSED");
|
|
4592
4661
|
if (isWithin(destination, options.objects.directory) || isWithin(options.objects.directory, destination)) throw new Error("PUBLICATION_OVERLAPPING_PATHS");
|
|
4593
4662
|
const { manifest, files } = await readManifest(options.tree, options.objects);
|
|
4594
4663
|
const [lance, schemas] = await Promise.all([loadLance(), arrowSchemas()]);
|
|
@@ -4600,7 +4669,7 @@ async function restoreLancePublication(options) {
|
|
|
4600
4669
|
if (error.code === "EEXIST") throw new Error("CONTINUITY_DESTINATION_EXISTS");
|
|
4601
4670
|
throw error;
|
|
4602
4671
|
}
|
|
4603
|
-
writeFileSync7(
|
|
4672
|
+
writeFileSync7(join12(destination, ".travel-restored.json"), JSON.stringify({
|
|
4604
4673
|
format: "engine7-lance-logical-restore-v1",
|
|
4605
4674
|
activationAllowed: false,
|
|
4606
4675
|
identity: options.objects.identity,
|
|
@@ -4641,7 +4710,7 @@ async function restoreLancePublication(options) {
|
|
|
4641
4710
|
}
|
|
4642
4711
|
durablePrivateTree(destination);
|
|
4643
4712
|
writeFileSync7(
|
|
4644
|
-
|
|
4713
|
+
join12(destination, ".lance-receipt.json"),
|
|
4645
4714
|
JSON.stringify({ format: manifest.format, tables: manifest.tables, activationAllowed: false }),
|
|
4646
4715
|
{ flag: "wx", mode: 384, flush: true }
|
|
4647
4716
|
);
|
|
@@ -4656,12 +4725,12 @@ init_runtime_lock();
|
|
|
4656
4725
|
init_runtime_authority();
|
|
4657
4726
|
import { createRequire as createRequire6 } from "node:module";
|
|
4658
4727
|
import { createHash as createHash13 } from "node:crypto";
|
|
4659
|
-
import { constants as
|
|
4660
|
-
import { join as
|
|
4728
|
+
import { constants as constants10, lstatSync as lstatSync12, readdirSync as readdirSync3, realpathSync as realpathSync8, readFileSync as readFileSync7, writeFileSync as writeFileSync8, openSync as openSync12, closeSync as closeSync11, readSync as readSync2, chmodSync as chmodSync3, existsSync as existsSync4 } from "node:fs";
|
|
4729
|
+
import { join as join14, resolve as resolve12, dirname as dirname11 } from "node:path";
|
|
4661
4730
|
|
|
4662
4731
|
// src/continuity/session-event-projection.ts
|
|
4663
4732
|
import {
|
|
4664
|
-
constants as
|
|
4733
|
+
constants as constants9,
|
|
4665
4734
|
lstatSync as lstatSync11,
|
|
4666
4735
|
realpathSync as realpathSync7,
|
|
4667
4736
|
mkdirSync as mkdirSync8,
|
|
@@ -4673,12 +4742,12 @@ import {
|
|
|
4673
4742
|
renameSync as renameSync3,
|
|
4674
4743
|
unlinkSync as unlinkSync3
|
|
4675
4744
|
} from "node:fs";
|
|
4676
|
-
import { basename as basename4, dirname as
|
|
4677
|
-
import { createHash as createHash12, randomUUID as
|
|
4745
|
+
import { basename as basename4, dirname as dirname10, join as join13, relative as relative4, resolve as resolve11 } from "node:path";
|
|
4746
|
+
import { createHash as createHash12, randomUUID as randomUUID7 } from "node:crypto";
|
|
4678
4747
|
function sessionStateDir(fileOrDirectory) {
|
|
4679
4748
|
const absolute4 = resolve11(fileOrDirectory);
|
|
4680
|
-
const directory2 = ["sessions", "sessions-cron"].includes(basename4(absolute4)) ? absolute4 :
|
|
4681
|
-
return ["sessions", "sessions-cron"].includes(basename4(directory2)) && basename4(
|
|
4749
|
+
const directory2 = ["sessions", "sessions-cron"].includes(basename4(absolute4)) ? absolute4 : dirname10(absolute4);
|
|
4750
|
+
return ["sessions", "sessions-cron"].includes(basename4(directory2)) && basename4(dirname10(dirname10(directory2))) === "agents" ? dirname10(dirname10(dirname10(directory2))) : null;
|
|
4682
4751
|
}
|
|
4683
4752
|
function sessionFilePath(stateDir, file) {
|
|
4684
4753
|
const path3 = relative4(stateDir, resolve11(file)).replace(/\\/g, "/");
|
|
@@ -4709,7 +4778,7 @@ function prepareSessionDirectory(directory2) {
|
|
|
4709
4778
|
if (error.code !== "ENOENT") throw error;
|
|
4710
4779
|
}
|
|
4711
4780
|
missing.push(parent);
|
|
4712
|
-
parent =
|
|
4781
|
+
parent = dirname10(parent);
|
|
4713
4782
|
}
|
|
4714
4783
|
if (realpathSync7(parent) !== parent || !lstatSync11(parent).isDirectory()) throw new Error("SESSION_SYMLINK_REFUSED");
|
|
4715
4784
|
for (const path3 of missing.reverse()) {
|
|
@@ -4719,7 +4788,7 @@ function prepareSessionDirectory(directory2) {
|
|
|
4719
4788
|
if (error.code !== "EEXIST") throw error;
|
|
4720
4789
|
}
|
|
4721
4790
|
if (!lstatSync11(path3).isDirectory() || realpathSync7(path3) !== path3) throw new Error("SESSION_SYMLINK_REFUSED");
|
|
4722
|
-
syncSessionDirectory(
|
|
4791
|
+
syncSessionDirectory(dirname10(path3));
|
|
4723
4792
|
}
|
|
4724
4793
|
}
|
|
4725
4794
|
function sessionFileSignature(file) {
|
|
@@ -4738,19 +4807,23 @@ function frameBytes(row) {
|
|
|
4738
4807
|
if (createHash12("sha256").update(bytes).digest("hex") !== row.digest) throw new Error("SESSION_EVENT_CORRUPT");
|
|
4739
4808
|
return bytes;
|
|
4740
4809
|
}
|
|
4741
|
-
function mapSessionIndex(bytes,
|
|
4810
|
+
function mapSessionIndex(bytes, _db, path3, stateDir, sourceRoot, targetRoot) {
|
|
4742
4811
|
if (basename4(path3) !== "session-index.json") return bytes;
|
|
4743
|
-
|
|
4812
|
+
let index;
|
|
4813
|
+
try {
|
|
4814
|
+
index = JSON.parse(bytes.toString("utf8"));
|
|
4815
|
+
} catch {
|
|
4816
|
+
return bytes;
|
|
4817
|
+
}
|
|
4818
|
+
if (!index || typeof index !== "object" || Array.isArray(index)) return bytes;
|
|
4744
4819
|
const prefixes = [sourceRoot, stateDir].map((root) => root.replace(/\\/g, "/").replace(/\/$/, "") + "/");
|
|
4745
|
-
if (!index || typeof index !== "object" || Array.isArray(index)) throw new Error("SESSION_INDEX_INVALID");
|
|
4746
4820
|
for (const entry of Object.values(index)) {
|
|
4747
|
-
if (!entry || typeof entry.file !== "string")
|
|
4821
|
+
if (!entry || typeof entry.file !== "string") continue;
|
|
4748
4822
|
const old = entry.file.replace(/\\/g, "/"), prefix = prefixes.find((value2) => old.startsWith(value2));
|
|
4749
|
-
if (!prefix)
|
|
4823
|
+
if (!prefix) continue;
|
|
4750
4824
|
const local = old.slice(prefix.length);
|
|
4751
|
-
sessionFilePath(stateDir,
|
|
4752
|
-
|
|
4753
|
-
entry.file = join12(targetRoot, local);
|
|
4825
|
+
sessionFilePath(stateDir, join13(stateDir, local));
|
|
4826
|
+
entry.file = join13(targetRoot, local);
|
|
4754
4827
|
}
|
|
4755
4828
|
return Buffer.from(JSON.stringify(index, null, 2));
|
|
4756
4829
|
}
|
|
@@ -4762,15 +4835,15 @@ function portableIndex(bytes, db, path3, sourceRoot, destination) {
|
|
|
4762
4835
|
return mapSessionIndex(bytes, db, path3, destination, sourceRoot, destination);
|
|
4763
4836
|
}
|
|
4764
4837
|
function projectSessionFile(db, cursors, stateDir, path3, sourceRoot) {
|
|
4765
|
-
sessionFilePath(stateDir,
|
|
4838
|
+
sessionFilePath(stateDir, join13(stateDir, path3));
|
|
4766
4839
|
const record = db.prepare("SELECT * FROM session_files WHERE path=?").get(path3);
|
|
4767
4840
|
if (!record) throw new Error("SESSION_FILE_NOT_REGISTERED");
|
|
4768
|
-
const file =
|
|
4769
|
-
prepareSessionDirectory(
|
|
4841
|
+
const file = join13(stateDir, path3), signature = sessionFileSignature(file);
|
|
4842
|
+
prepareSessionDirectory(dirname10(file));
|
|
4770
4843
|
if (record.state === "removed") {
|
|
4771
4844
|
if (signature !== null) {
|
|
4772
4845
|
unlinkSync3(file);
|
|
4773
|
-
syncSessionDirectory(
|
|
4846
|
+
syncSessionDirectory(dirname10(file));
|
|
4774
4847
|
}
|
|
4775
4848
|
cursors.prepare("DELETE FROM cursors WHERE path=?").run(path3);
|
|
4776
4849
|
return;
|
|
@@ -4780,11 +4853,11 @@ function projectSessionFile(db, cursors, stateDir, path3, sourceRoot) {
|
|
|
4780
4853
|
const cursor = cursors.prepare("SELECT * FROM cursors WHERE path=?").get(path3);
|
|
4781
4854
|
const incremental = record.kind === "jsonl" && cursor && cursor.generation === record.generation && cursor.signature === signature && Number(cursor.frames) <= count;
|
|
4782
4855
|
if (incremental && cursor.revision === record.revision && Number(cursor.frames) === count) return;
|
|
4783
|
-
const temp =
|
|
4856
|
+
const temp = join13(dirname10(file), ".session-" + randomUUID7() + ".partial");
|
|
4784
4857
|
const target = incremental ? file : temp, start = incremental ? Number(cursor.frames) : 0;
|
|
4785
4858
|
let fd, complete = false;
|
|
4786
4859
|
try {
|
|
4787
|
-
fd = openSync11(target, (incremental ?
|
|
4860
|
+
fd = openSync11(target, (incremental ? constants9.O_WRONLY | constants9.O_APPEND : constants9.O_WRONLY | constants9.O_CREAT | constants9.O_EXCL) | (constants9.O_NOFOLLOW ?? 0), 384);
|
|
4788
4861
|
let frames2 = start;
|
|
4789
4862
|
const rows = db.prepare(`SELECT f.ordinal,e.body,e.digest FROM session_file_events f JOIN session_events e ON e.sequence=f.event_sequence
|
|
4790
4863
|
WHERE f.path=? AND f.ordinal>? ORDER BY f.ordinal`).iterate(path3, start);
|
|
@@ -4805,7 +4878,7 @@ function projectSessionFile(db, cursors, stateDir, path3, sourceRoot) {
|
|
|
4805
4878
|
if (!incremental) renameSync3(temp, file);
|
|
4806
4879
|
const after = sessionFileSignature(file);
|
|
4807
4880
|
if (after === null || !after.startsWith(`${info.dev}:${info.ino}:${info.size}:`)) throw new Error("SESSION_PROJECTION_CHANGED");
|
|
4808
|
-
syncSessionDirectory(
|
|
4881
|
+
syncSessionDirectory(dirname10(file));
|
|
4809
4882
|
cursors.prepare(`INSERT INTO cursors VALUES(?,?,?,?,?) ON CONFLICT(path) DO UPDATE SET generation=excluded.generation,
|
|
4810
4883
|
revision=excluded.revision,frames=excluded.frames,signature=excluded.signature`).run(path3, record.generation, record.revision, count, after);
|
|
4811
4884
|
complete = true;
|
|
@@ -4844,8 +4917,8 @@ var schema2 = `
|
|
|
4844
4917
|
CREATE TABLE session_file_events(path TEXT NOT NULL,ordinal INTEGER NOT NULL,event_sequence INTEGER NOT NULL,
|
|
4845
4918
|
PRIMARY KEY(path,ordinal),FOREIGN KEY(path) REFERENCES session_files(path),FOREIGN KEY(event_sequence) REFERENCES session_events(sequence));`;
|
|
4846
4919
|
function privateDatabase(file, create) {
|
|
4847
|
-
prepareSessionDirectory(
|
|
4848
|
-
const directory2 = lstatSync12(
|
|
4920
|
+
prepareSessionDirectory(dirname11(file));
|
|
4921
|
+
const directory2 = lstatSync12(dirname11(file));
|
|
4849
4922
|
if (process.platform !== "win32" && (directory2.mode & 63 || directory2.uid !== process.getuid())) throw new Error("SESSION_PRIVATE_CONTROL_REQUIRED");
|
|
4850
4923
|
for (const path3 of [file, file + "-journal", file + "-wal", file + "-shm"]) {
|
|
4851
4924
|
try {
|
|
@@ -4858,7 +4931,7 @@ function privateDatabase(file, create) {
|
|
|
4858
4931
|
if (create) {
|
|
4859
4932
|
try {
|
|
4860
4933
|
closeSync11(openSync12(file, "wx", 384));
|
|
4861
|
-
syncSessionDirectory(
|
|
4934
|
+
syncSessionDirectory(dirname11(file));
|
|
4862
4935
|
} catch (error) {
|
|
4863
4936
|
if (error.code !== "EEXIST") throw error;
|
|
4864
4937
|
}
|
|
@@ -4873,7 +4946,7 @@ function privateDatabase(file, create) {
|
|
|
4873
4946
|
}
|
|
4874
4947
|
}
|
|
4875
4948
|
function projectionDatabase(stateDir, binding) {
|
|
4876
|
-
const db = privateDatabase(
|
|
4949
|
+
const db = privateDatabase(join14(stateDir, ".continuity/session-projection.sqlite"), true);
|
|
4877
4950
|
try {
|
|
4878
4951
|
db.exec(`CREATE TABLE IF NOT EXISTS projection_control(singleton INTEGER PRIMARY KEY CHECK(singleton=1),binding TEXT NOT NULL);
|
|
4879
4952
|
CREATE TABLE IF NOT EXISTS cursors(path TEXT PRIMARY KEY,generation INTEGER NOT NULL,revision INTEGER NOT NULL,frames INTEGER NOT NULL,signature TEXT NOT NULL);`);
|
|
@@ -4934,19 +5007,19 @@ function nextRevision(db) {
|
|
|
4934
5007
|
return revision;
|
|
4935
5008
|
}
|
|
4936
5009
|
function inventory2(stateDir) {
|
|
4937
|
-
const files = [], agents =
|
|
5010
|
+
const files = [], agents = join14(stateDir, "agents");
|
|
4938
5011
|
if (!existsSync4(agents)) return files;
|
|
4939
5012
|
if (realpathSync8(agents) !== agents || !lstatSync12(agents).isDirectory()) throw new Error("SESSION_SYMLINK_REFUSED");
|
|
4940
5013
|
for (const agent of readdirSync3(agents).sort()) {
|
|
4941
|
-
const agentDir =
|
|
5014
|
+
const agentDir = join14(agents, agent);
|
|
4942
5015
|
if (lstatSync12(agentDir).isSymbolicLink()) throw new Error("SESSION_SYMLINK_REFUSED");
|
|
4943
5016
|
if (!lstatSync12(agentDir).isDirectory()) continue;
|
|
4944
5017
|
for (const folder of ["sessions", "sessions-cron"]) {
|
|
4945
|
-
const directory2 =
|
|
5018
|
+
const directory2 = join14(agentDir, folder);
|
|
4946
5019
|
if (!existsSync4(directory2)) continue;
|
|
4947
5020
|
if (!lstatSync12(directory2).isDirectory() || realpathSync8(directory2) !== directory2) throw new Error("SESSION_SYMLINK_REFUSED");
|
|
4948
5021
|
for (const name of readdirSync3(directory2).sort()) {
|
|
4949
|
-
const file =
|
|
5022
|
+
const file = join14(directory2, name);
|
|
4950
5023
|
sessionFilePath(stateDir, file);
|
|
4951
5024
|
const signature = sessionFileSignature(file);
|
|
4952
5025
|
if (signature === null) throw new Error("SESSION_BASELINE_CHANGED");
|
|
@@ -4966,7 +5039,7 @@ function importFile(db, stateDir, file) {
|
|
|
4966
5039
|
add(readFileSync7(file));
|
|
4967
5040
|
return;
|
|
4968
5041
|
}
|
|
4969
|
-
const fd = openSync12(file,
|
|
5042
|
+
const fd = openSync12(file, constants10.O_RDONLY | (constants10.O_NOFOLLOW ?? 0)), chunk = Buffer.alloc(1024 * 1024);
|
|
4970
5043
|
let carry = Buffer.alloc(0);
|
|
4971
5044
|
try {
|
|
4972
5045
|
for (; ; ) {
|
|
@@ -5012,7 +5085,7 @@ async function enrollSessionEvents(stateDir, input, options = {}) {
|
|
|
5012
5085
|
throw error;
|
|
5013
5086
|
}
|
|
5014
5087
|
enrollRuntimeReplication(db, root, "session-events", binding);
|
|
5015
|
-
syncSessionDirectory(
|
|
5088
|
+
syncSessionDirectory(dirname11(file));
|
|
5016
5089
|
} finally {
|
|
5017
5090
|
db.close();
|
|
5018
5091
|
}
|
|
@@ -5029,8 +5102,8 @@ var SessionEventStore = class {
|
|
|
5029
5102
|
const row = db.prepare("SELECT source_root,revision,limits FROM session_control WHERE singleton=1").get();
|
|
5030
5103
|
let approvedSourceRoot = row?.source_root === stateDir;
|
|
5031
5104
|
if (row && !approvedSourceRoot) {
|
|
5032
|
-
const file =
|
|
5033
|
-
if (!
|
|
5105
|
+
const file = join14(stateDir, ".travel-active.json"), stat2 = lstatSync12(file);
|
|
5106
|
+
if (!stat2.isFile() || stat2.isSymbolicLink() || stat2.size > 4 * 1024 * 1024 || process.platform !== "win32" && (stat2.mode & 63 || stat2.uid !== process.getuid())) throw new Error("REPLICATION_RECOVERY_REQUIRED");
|
|
5034
5107
|
const activation = JSON.parse(readFileSync7(file, "utf8")), binding = registration.binding;
|
|
5035
5108
|
approvedSourceRoot = activation.format === "engine7-runtime-activation-v1" && activation.destination === stateDir && activation.originalSessionRoots?.includes(row.source_root) && activation.profile?.baselineId === binding.baselineId && activation.profile?.epoch === binding.epoch && activation.identity?.tenantId === binding.tenantId && activation.identity?.companionId === binding.companionId && activation.identity?.seatId === binding.seatId;
|
|
5036
5109
|
}
|
|
@@ -5280,14 +5353,14 @@ async function restoreSessionEvents(options) {
|
|
|
5280
5353
|
const control2 = options.db.prepare("SELECT binding,head,digest FROM e7_replication_control WHERE role=?").get(role);
|
|
5281
5354
|
const wanted = JSON.stringify([binding.tenantId, binding.companionId, binding.seatId, binding.databaseId, binding.baselineId, binding.epoch]);
|
|
5282
5355
|
if (!control2 || control2.binding !== wanted) throw new Error("REPLICATION_BINDING_MISMATCH");
|
|
5283
|
-
if (realpathSync8(
|
|
5356
|
+
if (realpathSync8(dirname11(destination)) !== dirname11(destination)) throw new Error("SESSION_SYMLINK_REFUSED");
|
|
5284
5357
|
if (existsSync4(destination)) throw new Error("CONTINUITY_DESTINATION_EXISTS");
|
|
5285
5358
|
prepareSessionDirectory(destination);
|
|
5286
|
-
writeFileSync8(
|
|
5359
|
+
writeFileSync8(join14(destination, ".travel-restored.json"), JSON.stringify({ format: "engine7-session-events-restore-v1", activationAllowed: false, binding }), { mode: 384, flag: "wx", flush: true });
|
|
5287
5360
|
syncSessionDirectory(destination);
|
|
5288
|
-
const directory2 =
|
|
5361
|
+
const directory2 = join14(destination, ".continuity");
|
|
5289
5362
|
prepareSessionDirectory(directory2);
|
|
5290
|
-
const file =
|
|
5363
|
+
const file = join14(directory2, "session-events.db");
|
|
5291
5364
|
await require4("node:sqlite").backup(options.db, file);
|
|
5292
5365
|
chmodSync3(file, 384);
|
|
5293
5366
|
const copy = privateDatabase(file, false), cursors = projectionDatabase(destination, binding);
|
|
@@ -5299,7 +5372,7 @@ async function restoreSessionEvents(options) {
|
|
|
5299
5372
|
for (const row of copy.prepare("SELECT path FROM session_files ORDER BY path").all()) projectSessionFile(copy, cursors, destination, String(row.path), root);
|
|
5300
5373
|
cursors.exec("COMMIT");
|
|
5301
5374
|
writeFileSync8(
|
|
5302
|
-
|
|
5375
|
+
join14(destination, ".session-events-receipt.json"),
|
|
5303
5376
|
JSON.stringify({ binding, head: { sequence: control2.head, digest: control2.digest }, activationAllowed: false }),
|
|
5304
5377
|
{ mode: 384, flag: "wx", flush: true }
|
|
5305
5378
|
);
|
|
@@ -5351,7 +5424,7 @@ async function runRuntimeArtifactCli(command, config) {
|
|
|
5351
5424
|
});
|
|
5352
5425
|
try {
|
|
5353
5426
|
return {
|
|
5354
|
-
file:
|
|
5427
|
+
file: join15(stateDir, ".continuity/session-events.db"),
|
|
5355
5428
|
binding: store.replication.binding,
|
|
5356
5429
|
baseline: store.replication.head(),
|
|
5357
5430
|
schemaHash: store.replication.schemaHash,
|
|
@@ -5362,13 +5435,13 @@ async function runRuntimeArtifactCli(command, config) {
|
|
|
5362
5435
|
}
|
|
5363
5436
|
}
|
|
5364
5437
|
if (command === "restore-sessions") {
|
|
5365
|
-
const marker = JSON.parse(readPrivateFile(
|
|
5438
|
+
const marker = JSON.parse(readPrivateFile(join15(stateDir, ".travel-restored.json")).toString());
|
|
5366
5439
|
if (marker.activationAllowed !== false) throw new Error("PUBLICATION_STANDBY_GUARD_REQUIRED");
|
|
5367
5440
|
const file = databaseFile(config.databaseFile), place = sqliteStoreLocation(file), destination = absolute(config.destination);
|
|
5368
5441
|
if (!place || place.component !== "session-events" || place.stateDir !== stateDir) throw new Error("REPLICATION_RUNTIME_PATH_UNSUPPORTED");
|
|
5369
5442
|
if (isWithin(stateDir, destination) || isWithin(destination, stateDir)) throw new Error("PUBLICATION_OVERLAPPING_PATHS");
|
|
5370
5443
|
return await withCheckpointLock(stateDir, async () => {
|
|
5371
|
-
const db = new
|
|
5444
|
+
const db = new DatabaseSync12(file, { readOnly: true });
|
|
5372
5445
|
try {
|
|
5373
5446
|
await restoreSessionEvents({ db, binding: normalizeBinding(config.binding), destination });
|
|
5374
5447
|
return { activationAllowed: false, published: false };
|
|
@@ -5396,7 +5469,7 @@ async function runRuntimeArtifactCli(command, config) {
|
|
|
5396
5469
|
if (!place || !isWithin(stateDir, place.stateDir)) throw new Error("REPLICATION_RUNTIME_PATH_UNSUPPORTED");
|
|
5397
5470
|
assertStateDirUsable(place.stateDir);
|
|
5398
5471
|
runtimeRoots.add(place.stateDir);
|
|
5399
|
-
const registration = readSQLiteStoreRegistration(place), db = new
|
|
5472
|
+
const registration = readSQLiteStoreRegistration(place), db = new DatabaseSync12(file, { readOnly: true });
|
|
5400
5473
|
try {
|
|
5401
5474
|
const actual = readSQLiteReplicationSource(db);
|
|
5402
5475
|
if (!registration || !actual || JSON.stringify(actual) !== JSON.stringify(registration)) throw new Error("REPLICATION_REGISTRATION_MISMATCH");
|
|
@@ -5414,9 +5487,9 @@ async function runRuntimeArtifactCli(command, config) {
|
|
|
5414
5487
|
}
|
|
5415
5488
|
for (const root of [...runtimeRoots].sort()) releases2.push(registerRuntimeWriter(root, "travel-data-runtime-capture"));
|
|
5416
5489
|
} else if (command !== "restore-lance") throw new Error("PUBLICATION_INVALID_COMMAND");
|
|
5417
|
-
objects = await PublicationObjects.open({ directory:
|
|
5490
|
+
objects = await PublicationObjects.open({ directory: join15(dataDir, "objects"), key: key2, identity: profile.identity, maximumBytes: config.maximumBytes });
|
|
5418
5491
|
source = await RuntimeTreeSource.open({
|
|
5419
|
-
directory:
|
|
5492
|
+
directory: join15(dataDir, "runtime-trees"),
|
|
5420
5493
|
profile,
|
|
5421
5494
|
objects,
|
|
5422
5495
|
initialize: command === "capture-runtime" && config.initializeTreeSource === true,
|
|
@@ -5470,19 +5543,19 @@ async function runRuntimeArtifactCli(command, config) {
|
|
|
5470
5543
|
}
|
|
5471
5544
|
|
|
5472
5545
|
// src/continuity/runtime-sync-cli.ts
|
|
5473
|
-
import { DatabaseSync as
|
|
5546
|
+
import { DatabaseSync as DatabaseSync18 } from "node:sqlite";
|
|
5474
5547
|
import { createHash as createHash18 } from "node:crypto";
|
|
5475
5548
|
import { lstatSync as lstatSync17, realpathSync as realpathSync12, readFileSync as readFileSync8 } from "node:fs";
|
|
5476
|
-
import { isAbsolute as isAbsolute4, resolve as resolve19, join as
|
|
5549
|
+
import { isAbsolute as isAbsolute4, resolve as resolve19, join as join21 } from "node:path";
|
|
5477
5550
|
|
|
5478
5551
|
// src/continuity/runtime-publication-source.ts
|
|
5479
|
-
import { DatabaseSync as
|
|
5552
|
+
import { DatabaseSync as DatabaseSync14 } from "node:sqlite";
|
|
5480
5553
|
import { createHash as createHash15 } from "node:crypto";
|
|
5481
5554
|
import { existsSync as existsSync5, lstatSync as lstatSync15, writeFileSync as writeFileSync9, openSync as openSync13, closeSync as closeSync12, fsyncSync as fsyncSync10 } from "node:fs";
|
|
5482
|
-
import { join as
|
|
5555
|
+
import { join as join16, resolve as resolve15 } from "node:path";
|
|
5483
5556
|
|
|
5484
5557
|
// src/continuity/runtime-h-capture.ts
|
|
5485
|
-
import { DatabaseSync as
|
|
5558
|
+
import { DatabaseSync as DatabaseSync13 } from "node:sqlite";
|
|
5486
5559
|
import { createHash as createHash14 } from "node:crypto";
|
|
5487
5560
|
import { lstatSync as lstatSync14, realpathSync as realpathSync10 } from "node:fs";
|
|
5488
5561
|
import { resolve as resolve14, relative as relative5 } from "node:path";
|
|
@@ -5562,7 +5635,7 @@ async function capture(input, assertRoot) {
|
|
|
5562
5635
|
throw new Error("REPLICATION_RUNTIME_PATH_UNSUPPORTED");
|
|
5563
5636
|
if (process.platform !== "win32" && (info.mode & 63 || info.uid !== process.getuid())) throw new Error("PUBLICATION_PRIVATE_FILE_REQUIRED");
|
|
5564
5637
|
assertRoot(place.stateDir);
|
|
5565
|
-
const registration = readSQLiteStoreRegistration(place), probe = new
|
|
5638
|
+
const registration = readSQLiteStoreRegistration(place), probe = new DatabaseSync13(d.file, { readOnly: true });
|
|
5566
5639
|
try {
|
|
5567
5640
|
const enrolled = readSQLiteReplicationSource(probe), b = d.source.binding, v = readSchemaVersion(probe);
|
|
5568
5641
|
if (!registration || !same2(enrolled, registration) || !same2(enrolled, { binding: b, schemaHash: d.source.schemaHash }))
|
|
@@ -5653,9 +5726,9 @@ var RuntimePublicationSource = class _RuntimePublicationSource {
|
|
|
5653
5726
|
if (!HASH4.test(this.layoutDigest) || !natural2(this.maximumPendingCheckpoints) || this.maximumPendingCheckpoints < 1 || this.maximumPendingCheckpoints > 128 || !natural2(this.maximumPendingBytes) || this.maximumPendingBytes < 1 || this.maximumPendingBytes > 1024 * 1024 * 1024)
|
|
5654
5727
|
throw new Error("RUNTIME_PUBLICATION_INVALID_LIMIT");
|
|
5655
5728
|
if (!same3(this.objects.identity, this.profile.identity) || !same3(this.trees.profile, this.profile)) throw new Error("RUNTIME_PUBLICATION_PROFILE_MISMATCH");
|
|
5656
|
-
this.file =
|
|
5657
|
-
this.senderFile =
|
|
5658
|
-
this.marker =
|
|
5729
|
+
this.file = join16(this.directory, "source.sqlite");
|
|
5730
|
+
this.senderFile = join16(this.directory, "sender.sqlite");
|
|
5731
|
+
this.marker = join16(this.directory, "source.json");
|
|
5659
5732
|
if (options.initialize) preparePrivateDirectory(this.directory);
|
|
5660
5733
|
else {
|
|
5661
5734
|
try {
|
|
@@ -5671,9 +5744,9 @@ var RuntimePublicationSource = class _RuntimePublicationSource {
|
|
|
5671
5744
|
preparePrivateDatabase(this.senderFile);
|
|
5672
5745
|
let sender;
|
|
5673
5746
|
try {
|
|
5674
|
-
this.db = new
|
|
5747
|
+
this.db = new DatabaseSync14(this.file);
|
|
5675
5748
|
this.db.exec("PRAGMA synchronous=FULL; PRAGMA busy_timeout=1000");
|
|
5676
|
-
sender = new
|
|
5749
|
+
sender = new DatabaseSync14(this.senderFile);
|
|
5677
5750
|
sender.exec("PRAGMA synchronous=FULL; PRAGMA busy_timeout=0");
|
|
5678
5751
|
if (fresh) {
|
|
5679
5752
|
this.db.exec("BEGIN IMMEDIATE");
|
|
@@ -5802,10 +5875,33 @@ var RuntimePublicationSource = class _RuntimePublicationSource {
|
|
|
5802
5875
|
if (this.control().head !== 0) throw new Error("RUNTIME_PUBLICATION_INITIAL_ALREADY_PREPARED");
|
|
5803
5876
|
return this.prepareCapture(options, () => captureRuntimeH(options), true);
|
|
5804
5877
|
}
|
|
5805
|
-
/** The
|
|
5806
|
-
*
|
|
5878
|
+
/** The final LOCAL original is archived independently of the transport queue.
|
|
5879
|
+
* Read-only stores and writer exclusion remain held through its durable seal. */
|
|
5807
5880
|
async withStoppedPreparation(options, operation) {
|
|
5808
|
-
|
|
5881
|
+
const before = this.control();
|
|
5882
|
+
if (!same3(options.profile, this.profile) || options.objects !== this.objects) throw new Error("RUNTIME_PUBLICATION_PROFILE_MISMATCH");
|
|
5883
|
+
if (options.deletionWatermark < before.watermark) throw new Error("PUBLICATION_DELETION_REGRESSION");
|
|
5884
|
+
return withStoppedRuntimeH(options, async (parts) => {
|
|
5885
|
+
const manifest = normalizePublication({
|
|
5886
|
+
format: "engine7-publication-v1",
|
|
5887
|
+
profile: this.profile,
|
|
5888
|
+
sequence: before.head + 1,
|
|
5889
|
+
parentDigest: before.digest,
|
|
5890
|
+
databases: parts.databases,
|
|
5891
|
+
trees: parts.trees,
|
|
5892
|
+
deletionWatermark: parts.deletionWatermark
|
|
5893
|
+
});
|
|
5894
|
+
const old = before.head ? await this.readManifest(before.head) : null;
|
|
5895
|
+
if (old && manifest.deletionWatermark === old.manifest.deletionWatermark) {
|
|
5896
|
+
const present = new Set(manifest.trees.flatMap((tree) => tree.files.map((file) => tree.id + "/" + file.path)));
|
|
5897
|
+
if (old.manifest.trees.some((tree) => tree.files.some((file) => !present.has(tree.id + "/" + file.path)))) throw new Error("PUBLICATION_REMOVAL_REQUIRES_DELETION");
|
|
5898
|
+
}
|
|
5899
|
+
const current2 = this.control();
|
|
5900
|
+
if (current2.head !== before.head || current2.digest !== before.digest) throw new Error("RUNTIME_PUBLICATION_CONCURRENT_CHANGE");
|
|
5901
|
+
if (manifest.deletionWatermark < current2.watermark) throw new Error("PUBLICATION_DELETION_REGRESSION");
|
|
5902
|
+
if (old && stateHash(old.manifest) === stateHash(manifest)) return operation({ ...old, sequence: before.head, activationAllowed: false });
|
|
5903
|
+
return operation({ sequence: manifest.sequence, digest: publicationDigest(manifest), manifest, activationAllowed: false });
|
|
5904
|
+
});
|
|
5809
5905
|
}
|
|
5810
5906
|
async prepareCapture(options, capture2, initial = false) {
|
|
5811
5907
|
const c = this.control(), pending = this.status();
|
|
@@ -5920,7 +6016,7 @@ var RuntimePublicationSource = class _RuntimePublicationSource {
|
|
|
5920
6016
|
}
|
|
5921
6017
|
async withSending(operation) {
|
|
5922
6018
|
this.control();
|
|
5923
|
-
const db = new
|
|
6019
|
+
const db = new DatabaseSync14(this.senderFile);
|
|
5924
6020
|
try {
|
|
5925
6021
|
db.exec("PRAGMA busy_timeout=0; BEGIN IMMEDIATE");
|
|
5926
6022
|
sendingHandles.add(db);
|
|
@@ -6158,9 +6254,9 @@ init_schema_migrations();
|
|
|
6158
6254
|
init_runtime_lock();
|
|
6159
6255
|
|
|
6160
6256
|
// src/continuity/recovery-archive.ts
|
|
6161
|
-
import { DatabaseSync as
|
|
6257
|
+
import { DatabaseSync as DatabaseSync15 } from "node:sqlite";
|
|
6162
6258
|
import { existsSync as existsSync6, lstatSync as lstatSync16, mkdtempSync, rmSync, writeFileSync as writeFileSync10, chmodSync as chmodSync4 } from "node:fs";
|
|
6163
|
-
import { join as
|
|
6259
|
+
import { join as join17, resolve as resolve16 } from "node:path";
|
|
6164
6260
|
init_sqlite_replication();
|
|
6165
6261
|
import { createHash as createHash16 } from "node:crypto";
|
|
6166
6262
|
|
|
@@ -6267,8 +6363,8 @@ var RuntimeRecoveryArchive = class _RuntimeRecoveryArchive {
|
|
|
6267
6363
|
constructor(options) {
|
|
6268
6364
|
this.directory = resolve16(options.directory);
|
|
6269
6365
|
this.objects = options.objects;
|
|
6270
|
-
this.file =
|
|
6271
|
-
this.marker =
|
|
6366
|
+
this.file = join17(this.directory, "archives.sqlite");
|
|
6367
|
+
this.marker = join17(this.directory, "archive.json");
|
|
6272
6368
|
if (options.initialize) preparePrivateDirectory(this.directory);
|
|
6273
6369
|
else {
|
|
6274
6370
|
try {
|
|
@@ -6282,7 +6378,7 @@ var RuntimeRecoveryArchive = class _RuntimeRecoveryArchive {
|
|
|
6282
6378
|
if (!fresh) this.checkMarker();
|
|
6283
6379
|
preparePrivateDatabase(this.file);
|
|
6284
6380
|
try {
|
|
6285
|
-
this.db = new
|
|
6381
|
+
this.db = new DatabaseSync15(this.file);
|
|
6286
6382
|
this.db.exec("PRAGMA synchronous=FULL; PRAGMA busy_timeout=1000");
|
|
6287
6383
|
if (fresh) {
|
|
6288
6384
|
this.db.exec(schema4);
|
|
@@ -6376,6 +6472,7 @@ var RuntimeRecoveryArchive = class _RuntimeRecoveryArchive {
|
|
|
6376
6472
|
this.active();
|
|
6377
6473
|
const { id: id2, kind } = options, manifest = normalizePublication(options.manifest), digest3 = publicationDigest(manifest);
|
|
6378
6474
|
if (typeof id2 !== "string" || !ID2.test(id2) || !["COMMON", "LOCAL", "REMOTE"].includes(kind)) throw new Error("RECOVERY_INVALID_ID");
|
|
6475
|
+
if (options.snapshotDatabase && (kind !== "LOCAL" || id2 !== "first-baseline" || manifest.sequence !== 1 || manifest.parentDigest !== "0".repeat(64))) throw new Error("RECOVERY_INVALID_SNAPSHOT");
|
|
6379
6476
|
if (!same5(manifest.profile.identity, this.objects.identity)) throw new Error("RECOVERY_IDENTITY_MISMATCH");
|
|
6380
6477
|
const deletion = async () => {
|
|
6381
6478
|
const value2 = await options.deletionWatermark();
|
|
@@ -6417,9 +6514,9 @@ var RuntimeRecoveryArchive = class _RuntimeRecoveryArchive {
|
|
|
6417
6514
|
validateRecoveryArchiveEntry(retained, this.objects.identity);
|
|
6418
6515
|
if (!same5(retained.manifest, manifest) || !same5(retained.publication, publication) || retained.databases.some((d) => d.role !== "replica")) throw new Error("RECOVERY_IDEMPOTENCY_CONFLICT");
|
|
6419
6516
|
}
|
|
6420
|
-
const temporary = mkdtempSync(
|
|
6517
|
+
const temporary = mkdtempSync(join17(this.directory, ".capture-"));
|
|
6421
6518
|
try {
|
|
6422
|
-
writeFileSync10(
|
|
6519
|
+
writeFileSync10(join17(temporary, ".travel-restored.json"), JSON.stringify({ activationAllowed: false }), { mode: 384, flush: true });
|
|
6423
6520
|
const databases = [];
|
|
6424
6521
|
if (retained) {
|
|
6425
6522
|
if (options.verifyRetained !== false) for (const database of retained.databases) await verifyContent(this.objects, database.content);
|
|
@@ -6428,10 +6525,11 @@ var RuntimeRecoveryArchive = class _RuntimeRecoveryArchive {
|
|
|
6428
6525
|
for (let offset = 0; !retained && offset < manifest.databases.length; offset += 6) {
|
|
6429
6526
|
const results = await Promise.allSettled(manifest.databases.slice(offset, offset + 6).map(async (d) => {
|
|
6430
6527
|
floor = Math.max(floor, await verify2());
|
|
6431
|
-
const file =
|
|
6432
|
-
await
|
|
6528
|
+
const file = join17(temporary, d.databaseId + ".sqlite");
|
|
6529
|
+
if (options.snapshotDatabase) await options.snapshotDatabase(options.databases[d.databaseId], file, d.databaseId);
|
|
6530
|
+
else await snapshotNativeDatabase(options.databases[d.databaseId], file);
|
|
6433
6531
|
chmodSync4(file, 384);
|
|
6434
|
-
const copy = new
|
|
6532
|
+
const copy = new DatabaseSync15(file, { readOnly: true });
|
|
6435
6533
|
let schemaHash2;
|
|
6436
6534
|
try {
|
|
6437
6535
|
schemaHash2 = validateRecoveryDatabase(copy, manifest, d.databaseId, role, void 0, false);
|
|
@@ -6485,12 +6583,12 @@ var RuntimeRecoveryArchive = class _RuntimeRecoveryArchive {
|
|
|
6485
6583
|
const floor = await checkRecoveryDeletionAsync(value2.manifest, deletionWatermark);
|
|
6486
6584
|
const prior = this.db.prepare("SELECT kind,manifest_digest,content FROM archives WHERE id=?").get(value2.id);
|
|
6487
6585
|
if (prior && (prior.kind !== value2.kind || prior.manifest_digest !== receipt.manifestDigest || JSON.parse(String(prior.content)).sha256 !== receipt.digest)) throw new Error("RECOVERY_IDEMPOTENCY_CONFLICT");
|
|
6488
|
-
const temporary = verifyDatabases ? mkdtempSync(
|
|
6586
|
+
const temporary = verifyDatabases ? mkdtempSync(join17(this.directory, ".import-")) : void 0;
|
|
6489
6587
|
try {
|
|
6490
6588
|
if (temporary) for (const db of value2.databases) {
|
|
6491
|
-
const file =
|
|
6589
|
+
const file = join17(temporary, db.databaseId + ".sqlite");
|
|
6492
6590
|
await this.objects.restoreFile(db.content, file);
|
|
6493
|
-
const probe = new
|
|
6591
|
+
const probe = new DatabaseSync15(file, { readOnly: true });
|
|
6494
6592
|
try {
|
|
6495
6593
|
validateRecoveryDatabase(probe, value2.manifest, db.databaseId, db.role, db.schemaHash);
|
|
6496
6594
|
} finally {
|
|
@@ -6536,12 +6634,12 @@ async function verifyContent(objects, content) {
|
|
|
6536
6634
|
|
|
6537
6635
|
// src/continuity/recovery-cli.ts
|
|
6538
6636
|
import { existsSync as existsSync7, writeFileSync as writeFileSync13 } from "node:fs";
|
|
6539
|
-
import { dirname as
|
|
6637
|
+
import { dirname as dirname13, isAbsolute as isAbsolute3, join as join20, resolve as resolve18 } from "node:path";
|
|
6540
6638
|
|
|
6541
6639
|
// src/continuity/recovery-archive-restore.ts
|
|
6542
|
-
import { DatabaseSync as
|
|
6640
|
+
import { DatabaseSync as DatabaseSync16 } from "node:sqlite";
|
|
6543
6641
|
import { mkdirSync as mkdirSync9, writeFileSync as writeFileSync11, realpathSync as realpathSync11 } from "node:fs";
|
|
6544
|
-
import { dirname as
|
|
6642
|
+
import { dirname as dirname12, join as join18, resolve as resolve17 } from "node:path";
|
|
6545
6643
|
init_sqlite_replication();
|
|
6546
6644
|
async function restoreRecoveryArchive(options) {
|
|
6547
6645
|
return restoreOriginal(options);
|
|
@@ -6552,7 +6650,7 @@ async function restoreOriginal(options, original, currentHCheck) {
|
|
|
6552
6650
|
const verify2 = async () => currentHCheck ? currentHCheck() : await checkRecoveryDeletionAsync(manifest, options.deletionWatermark, floor);
|
|
6553
6651
|
floor = await verify2();
|
|
6554
6652
|
const destination = resolve17(options.destination);
|
|
6555
|
-
if (realpathSync11(
|
|
6653
|
+
if (realpathSync11(dirname12(destination)) !== dirname12(destination)) throw new Error("SYMLINK_REFUSED");
|
|
6556
6654
|
for (const root of [objects.directory, options.archive.directory]) if (isWithin(root, destination) || isWithin(destination, root)) throw new Error("RECOVERY_OVERLAPPING_PATHS");
|
|
6557
6655
|
try {
|
|
6558
6656
|
mkdirSync9(destination, { mode: 448 });
|
|
@@ -6560,24 +6658,24 @@ async function restoreOriginal(options, original, currentHCheck) {
|
|
|
6560
6658
|
if (error.code === "EEXIST") throw new Error("CONTINUITY_DESTINATION_EXISTS");
|
|
6561
6659
|
throw error;
|
|
6562
6660
|
}
|
|
6563
|
-
writeFileSync11(
|
|
6564
|
-
await syncDirectory(
|
|
6661
|
+
writeFileSync11(join18(destination, ".travel-restored.json"), JSON.stringify({ format: "engine7-recovery-restore-v1", id: entry.id, activationAllowed: false }), { mode: 384, flag: "wx", flush: true });
|
|
6662
|
+
await syncDirectory(dirname12(destination));
|
|
6565
6663
|
await syncDirectory(destination);
|
|
6566
6664
|
const created = /* @__PURE__ */ new Set([destination]);
|
|
6567
6665
|
const directory2 = (path3) => {
|
|
6568
6666
|
const missing = [];
|
|
6569
|
-
for (let current2 = path3; !created.has(current2) && isWithin(destination, current2); current2 =
|
|
6667
|
+
for (let current2 = path3; !created.has(current2) && isWithin(destination, current2); current2 = dirname12(current2)) missing.push(current2);
|
|
6570
6668
|
for (const p of missing.reverse()) {
|
|
6571
6669
|
mkdirSync9(p, { mode: 448 });
|
|
6572
6670
|
created.add(p);
|
|
6573
6671
|
}
|
|
6574
6672
|
};
|
|
6575
|
-
directory2(
|
|
6576
|
-
directory2(
|
|
6577
|
-
await objects.restoreFiles(entry.databases.map((d) => ({ content: d.content, destination:
|
|
6673
|
+
directory2(join18(destination, "databases"));
|
|
6674
|
+
directory2(join18(destination, "trees"));
|
|
6675
|
+
await objects.restoreFiles(entry.databases.map((d) => ({ content: d.content, destination: join18(destination, "databases", d.databaseId + ".sqlite") })));
|
|
6578
6676
|
for (const d of entry.databases) {
|
|
6579
|
-
const path3 =
|
|
6580
|
-
const db = new
|
|
6677
|
+
const path3 = join18(destination, "databases", d.databaseId + ".sqlite");
|
|
6678
|
+
const db = new DatabaseSync16(path3, { readOnly: true });
|
|
6581
6679
|
try {
|
|
6582
6680
|
validateRecoveryDatabase(db, manifest, d.databaseId, d.role, d.schemaHash, options.verifyDatabases !== false);
|
|
6583
6681
|
} finally {
|
|
@@ -6586,30 +6684,30 @@ async function restoreOriginal(options, original, currentHCheck) {
|
|
|
6586
6684
|
}
|
|
6587
6685
|
const files = [];
|
|
6588
6686
|
for (const tree of manifest.trees) {
|
|
6589
|
-
const root =
|
|
6687
|
+
const root = join18(destination, "trees", tree.id);
|
|
6590
6688
|
directory2(root);
|
|
6591
|
-
for (const path3 of tree.directories) directory2(
|
|
6689
|
+
for (const path3 of tree.directories) directory2(join18(root, path3));
|
|
6592
6690
|
for (const file of tree.files) {
|
|
6593
|
-
const path3 =
|
|
6594
|
-
directory2(
|
|
6691
|
+
const path3 = join18(root, file.path);
|
|
6692
|
+
directory2(dirname12(path3));
|
|
6595
6693
|
files.push({ content: file.content, destination: path3, mode: file.mode });
|
|
6596
6694
|
}
|
|
6597
6695
|
}
|
|
6598
6696
|
await objects.restoreFiles(files);
|
|
6599
|
-
directory2(
|
|
6600
|
-
directory2(
|
|
6697
|
+
directory2(join18(destination, "lance"));
|
|
6698
|
+
directory2(join18(destination, "sessions"));
|
|
6601
6699
|
for (const kind of manifest.profile.trees) {
|
|
6602
6700
|
const tree = manifest.trees.find((t) => t.id === kind.id);
|
|
6603
|
-
if (kind.kind === "vector") await restoreLancePublication({ tree, objects, destination:
|
|
6701
|
+
if (kind.kind === "vector") await restoreLancePublication({ tree, objects, destination: join18(destination, "lance", tree.id) });
|
|
6604
6702
|
if (kind.kind === "session") {
|
|
6605
6703
|
if (tree.directories.length || tree.files.length !== 1 || tree.files[0].path !== "manifest.json") throw new Error("RUNTIME_INCOMPLETE_SESSIONS");
|
|
6606
6704
|
const metadata4 = JSON.parse((await objects.readContent(tree.files[0].content, 1024 * 1024)).toString());
|
|
6607
6705
|
const d = entry.databases.find((d2) => d2.databaseId === metadata4.databaseId);
|
|
6608
6706
|
const binding = normalizeBinding({ ...manifest.profile.identity, databaseId: metadata4.databaseId, baselineId: manifest.profile.baselineId, epoch: manifest.profile.epoch });
|
|
6609
6707
|
if (metadata4.format !== "engine7-session-events-publication-v1" || !d || JSON.stringify(metadata4.binding) !== JSON.stringify(binding) || JSON.stringify(metadata4.head) !== JSON.stringify(manifest.databases.find((v) => v.databaseId === d.databaseId).head)) throw new Error("RUNTIME_INCOMPLETE_SESSIONS");
|
|
6610
|
-
const db = new
|
|
6708
|
+
const db = new DatabaseSync16(join18(destination, "databases", d.databaseId + ".sqlite"), { readOnly: true });
|
|
6611
6709
|
try {
|
|
6612
|
-
await restoreSessionEvents({ db, binding, destination:
|
|
6710
|
+
await restoreSessionEvents({ db, binding, destination: join18(destination, "sessions", tree.id), replicationRole: d.role });
|
|
6613
6711
|
} finally {
|
|
6614
6712
|
db.close();
|
|
6615
6713
|
}
|
|
@@ -6617,17 +6715,17 @@ async function restoreOriginal(options, original, currentHCheck) {
|
|
|
6617
6715
|
}
|
|
6618
6716
|
for (const path3 of [...created].reverse()) await syncDirectory(path3);
|
|
6619
6717
|
await verify2();
|
|
6620
|
-
writeFileSync11(
|
|
6718
|
+
writeFileSync11(join18(destination, ".recovery-archive-receipt.json"), JSON.stringify(entry.receipt), { mode: 384, flag: "wx", flush: true });
|
|
6621
6719
|
await syncDirectory(destination);
|
|
6622
6720
|
await verify2();
|
|
6623
6721
|
return entry.receipt;
|
|
6624
6722
|
}
|
|
6625
6723
|
|
|
6626
6724
|
// src/continuity/recovery-diff.ts
|
|
6627
|
-
import { DatabaseSync as
|
|
6725
|
+
import { DatabaseSync as DatabaseSync17 } from "node:sqlite";
|
|
6628
6726
|
import { createHash as createHash17 } from "node:crypto";
|
|
6629
6727
|
import { mkdtempSync as mkdtempSync2, rmSync as rmSync2, writeFileSync as writeFileSync12 } from "node:fs";
|
|
6630
|
-
import { join as
|
|
6728
|
+
import { join as join19 } from "node:path";
|
|
6631
6729
|
init_legacy_sqlite_indexes();
|
|
6632
6730
|
init_schema_migrations();
|
|
6633
6731
|
var same6 = (a, b) => JSON.stringify(a) === JSON.stringify(b);
|
|
@@ -6719,12 +6817,12 @@ async function compareRecoveryArchives(options) {
|
|
|
6719
6817
|
try {
|
|
6720
6818
|
for (let index = 0; index < entries.length; index++) {
|
|
6721
6819
|
const entry = entries[index], ref = references[index], d = entry.databases.find((d2) => d2.databaseId === databaseId);
|
|
6722
|
-
const temporary = mkdtempSync2(
|
|
6820
|
+
const temporary = mkdtempSync2(join19(ref.archive.directory, ".compare-"));
|
|
6723
6821
|
temporaries.push(temporary);
|
|
6724
|
-
writeFileSync12(
|
|
6725
|
-
const file =
|
|
6822
|
+
writeFileSync12(join19(temporary, ".travel-restored.json"), JSON.stringify({ activationAllowed: false }), { mode: 384, flush: true });
|
|
6823
|
+
const file = join19(temporary, databaseId + ".sqlite");
|
|
6726
6824
|
await ref.archive.objects.restoreFile(d.content, file);
|
|
6727
|
-
const db = new
|
|
6825
|
+
const db = new DatabaseSync17(file, { readOnly: true, allowExtension: true });
|
|
6728
6826
|
handles.push(db);
|
|
6729
6827
|
validateRecoveryDatabase(db, entry.manifest, databaseId, d.role, d.schemaHash);
|
|
6730
6828
|
if (readSchemaVersion(db)?.component === "legacy-memory") loadLegacySQLiteVectorExtension(db);
|
|
@@ -6948,13 +7046,13 @@ async function runRecoveryCli(command, config) {
|
|
|
6948
7046
|
const dataDir = absolute2(c.dataDir), keyFile = absolute2(c.dataKeyFile);
|
|
6949
7047
|
if (isWithin(dataDir, keyFile)) throw new Error("RECOVERY_OVERLAPPING_PATHS");
|
|
6950
7048
|
assertPrivateDirectory(dataDir);
|
|
6951
|
-
if (!existsSync7(
|
|
7049
|
+
if (!existsSync7(join20(dataDir, "objects/catalog.sqlite"))) throw new Error("RECOVERY_ARCHIVE_REQUIRED");
|
|
6952
7050
|
const key2 = readPrivateFile(keyFile, 32);
|
|
6953
7051
|
keys.push(key2);
|
|
6954
7052
|
if (key2.length !== 32) throw new Error("PUBLICATION_INVALID_KEY");
|
|
6955
|
-
const objects = await PublicationObjects.open({ directory:
|
|
7053
|
+
const objects = await PublicationObjects.open({ directory: join20(dataDir, "objects"), key: key2, identity: c.identity });
|
|
6956
7054
|
handles.push(objects);
|
|
6957
|
-
const archive = await RuntimeRecoveryArchive.open({ directory:
|
|
7055
|
+
const archive = await RuntimeRecoveryArchive.open({ directory: join20(dataDir, "recovery"), objects });
|
|
6958
7056
|
handles.push(archive);
|
|
6959
7057
|
return { archive, id: c.archiveId };
|
|
6960
7058
|
};
|
|
@@ -6970,7 +7068,7 @@ async function runRecoveryCli(command, config) {
|
|
|
6970
7068
|
const common = await open5(config.common), local = await open5(config.local), remote = await open5(config.remote);
|
|
6971
7069
|
const report = await compareRecoveryArchives({ common, local, remote, deletionWatermark, maximumRows: config.maximumRows, maximumBytes: config.maximumBytes });
|
|
6972
7070
|
const reportFile = absolute2(config.reportFile);
|
|
6973
|
-
assertPrivateDirectory(
|
|
7071
|
+
assertPrivateDirectory(dirname13(reportFile));
|
|
6974
7072
|
for (const c of [config.common, config.local, config.remote]) if (isWithin(absolute2(c.dataDir), reportFile) || reportFile === absolute2(c.dataKeyFile)) throw new Error("RECOVERY_OVERLAPPING_PATHS");
|
|
6975
7073
|
const content = await common.archive.objects.putContent(Buffer.from(JSON.stringify(report)));
|
|
6976
7074
|
for (const ref of [common, local, remote]) checkRecoveryDeletion((await ref.archive.read(ref.id)).manifest, deletionWatermark);
|
|
@@ -6978,7 +7076,7 @@ async function runRecoveryCli(command, config) {
|
|
|
6978
7076
|
if (existsSync7(reportFile)) {
|
|
6979
7077
|
if (JSON.stringify(JSON.parse(readPrivateFile(reportFile, 1024 * 1024).toString())) !== JSON.stringify(pointer)) throw new Error("RECOVERY_IDEMPOTENCY_CONFLICT");
|
|
6980
7078
|
} else writeFileSync13(reportFile, JSON.stringify(pointer), { mode: 384, flag: "wx", flush: true });
|
|
6981
|
-
await syncDirectory(
|
|
7079
|
+
await syncDirectory(dirname13(reportFile));
|
|
6982
7080
|
for (const ref of [common, local, remote]) checkRecoveryDeletion((await ref.archive.read(ref.id)).manifest, deletionWatermark);
|
|
6983
7081
|
return { digest: report.digest, reportFile, counts: report.counts, scannedRecords: report.scannedRecords, admissionAllowed: false, activationAllowed: false };
|
|
6984
7082
|
} finally {
|
|
@@ -7083,7 +7181,7 @@ async function runRuntimeSyncCli(command, config) {
|
|
|
7083
7181
|
releases2.push(registerRuntimeWriter(root, "travel-data-runtime-sync"));
|
|
7084
7182
|
}
|
|
7085
7183
|
for (const d of descriptors) {
|
|
7086
|
-
const place = sqliteStoreLocation(d.file), probe = new
|
|
7184
|
+
const place = sqliteStoreLocation(d.file), probe = new DatabaseSync18(d.file, { readOnly: true });
|
|
7087
7185
|
let component;
|
|
7088
7186
|
try {
|
|
7089
7187
|
component = readSchemaVersion(probe)?.component;
|
|
@@ -7092,7 +7190,7 @@ async function runRuntimeSyncCli(command, config) {
|
|
|
7092
7190
|
}
|
|
7093
7191
|
if (component !== place.component) throw new Error("REPLICATION_RUNTIME_PATH_UNSUPPORTED");
|
|
7094
7192
|
const stopped = command === "preserve-local-runtime";
|
|
7095
|
-
const db = new
|
|
7193
|
+
const db = new DatabaseSync18(d.file, { readOnly: stopped, allowExtension: !stopped && component === "legacy-memory" });
|
|
7096
7194
|
handles.push(db);
|
|
7097
7195
|
databaseHandles[d.id] = db;
|
|
7098
7196
|
if (!stopped && component === "legacy-memory") loadLegacySQLiteVectorExtension(db, d.sqliteVecExtensionFile === void 0 ? void 0 : absolute3(d.sqliteVecExtensionFile));
|
|
@@ -7107,11 +7205,11 @@ async function runRuntimeSyncCli(command, config) {
|
|
|
7107
7205
|
if (stopped) databases[d.id] = { file: d.file, source: new SQLiteReplicationSourceReader(db, binding) };
|
|
7108
7206
|
else databases[d.id] = writableDatabases[d.id] = { file: d.file, source: new SQLiteReplicationSource(db, binding) };
|
|
7109
7207
|
}
|
|
7110
|
-
objects = await PublicationObjects.open({ directory:
|
|
7208
|
+
objects = await PublicationObjects.open({ directory: join21(dataDir, "objects"), key: key2, identity: profile.identity, maximumBytes: config.maximumBytes });
|
|
7111
7209
|
const initialize2 = command === "prepare-runtime";
|
|
7112
|
-
trees = await RuntimeTreeSource.open({ directory:
|
|
7210
|
+
trees = await RuntimeTreeSource.open({ directory: join21(dataDir, "runtime-trees"), profile, objects, initialize: initialize2 && config.initializeTreeSource === true, maximumBytes: config.maximumTreeBytes });
|
|
7113
7211
|
source = await RuntimePublicationSource.open({
|
|
7114
|
-
directory:
|
|
7212
|
+
directory: join21(dataDir, "runtime-publications"),
|
|
7115
7213
|
profile,
|
|
7116
7214
|
objects,
|
|
7117
7215
|
trees,
|
|
@@ -7146,7 +7244,7 @@ async function runRuntimeSyncCli(command, config) {
|
|
|
7146
7244
|
const deletionWatermark = recoveryDeletionReader(config);
|
|
7147
7245
|
if (deletionWatermark() > capture2.deletionWatermark) throw new Error("RECOVERY_DELETION_BARRIER");
|
|
7148
7246
|
return await source.withStoppedPreparation(capture2, async (h) => {
|
|
7149
|
-
const archive = await RuntimeRecoveryArchive.open({ directory:
|
|
7247
|
+
const archive = await RuntimeRecoveryArchive.open({ directory: join21(dataDir, "recovery"), objects, initialize: config.initializeRecoveryArchive === true });
|
|
7150
7248
|
try {
|
|
7151
7249
|
return await archive.preserve({ id: config.archiveId, kind: "LOCAL", manifest: h.manifest, databases: databaseHandles, deletionWatermark });
|
|
7152
7250
|
} finally {
|
|
@@ -7214,15 +7312,15 @@ async function runRuntimeSyncCli(command, config) {
|
|
|
7214
7312
|
}
|
|
7215
7313
|
|
|
7216
7314
|
// src/continuity/runtime-publication-restore.ts
|
|
7217
|
-
import { DatabaseSync as
|
|
7315
|
+
import { DatabaseSync as DatabaseSync19 } from "node:sqlite";
|
|
7218
7316
|
import { mkdirSync as mkdirSync10, writeFileSync as writeFileSync14 } from "node:fs";
|
|
7219
|
-
import { join as
|
|
7317
|
+
import { join as join23, resolve as resolve21 } from "node:path";
|
|
7220
7318
|
init_sqlite_replication();
|
|
7221
7319
|
|
|
7222
7320
|
// src/continuity/generation-integrity.ts
|
|
7223
7321
|
import { createHash as createHash19 } from "node:crypto";
|
|
7224
|
-
import { constants as
|
|
7225
|
-
import { join as
|
|
7322
|
+
import { constants as constants11, closeSync as closeSync13, fstatSync as fstatSync6, lstatSync as lstatSync18, openSync as openSync14, readSync as readSync3, readdirSync as readdirSync4, realpathSync as realpathSync13 } from "node:fs";
|
|
7323
|
+
import { join as join22, resolve as resolve20 } from "node:path";
|
|
7226
7324
|
import { open as open4 } from "node:fs/promises";
|
|
7227
7325
|
var recentSeals = /* @__PURE__ */ new Map();
|
|
7228
7326
|
function rememberSeal(root, integrity, files) {
|
|
@@ -7230,20 +7328,20 @@ function rememberSeal(root, integrity, files) {
|
|
|
7230
7328
|
recentSeals.set(root, { integrity: JSON.stringify(integrity), metadata: fileMetadata(files) });
|
|
7231
7329
|
if (recentSeals.size > 4) recentSeals.delete(recentSeals.keys().next().value);
|
|
7232
7330
|
}
|
|
7233
|
-
var metadata3 = (
|
|
7331
|
+
var metadata3 = (stat2) => [stat2.dev, stat2.ino, stat2.size, stat2.mode, stat2.mtimeNs, stat2.ctimeNs].join(":");
|
|
7234
7332
|
function generationFiles(root) {
|
|
7235
7333
|
const files = [];
|
|
7236
7334
|
if (realpathSync13(root) !== root) throw new Error("TRAVEL_GENERATION_INTEGRITY");
|
|
7237
7335
|
const visit = (path3) => {
|
|
7238
7336
|
if (path3 === ".runtime-publication-receipt.json") return;
|
|
7239
|
-
const file =
|
|
7240
|
-
if (
|
|
7241
|
-
if (
|
|
7337
|
+
const file = join22(root, path3), stat2 = lstatSync18(file, { bigint: true });
|
|
7338
|
+
if (stat2.isSymbolicLink()) throw new Error("TRAVEL_GENERATION_INTEGRITY");
|
|
7339
|
+
if (stat2.isDirectory()) {
|
|
7242
7340
|
for (const name of readdirSync4(file).sort()) visit(path3 ? path3 + "/" + name : name);
|
|
7243
7341
|
return;
|
|
7244
7342
|
}
|
|
7245
|
-
if (!
|
|
7246
|
-
files.push({ path: path3, stat });
|
|
7343
|
+
if (!stat2.isFile() || stat2.size > BigInt(Number.MAX_SAFE_INTEGER) || files.length >= 1e5) throw new Error("TRAVEL_GENERATION_INTEGRITY");
|
|
7344
|
+
files.push({ path: path3, stat: stat2 });
|
|
7247
7345
|
};
|
|
7248
7346
|
visit("");
|
|
7249
7347
|
return files.sort((a, b) => a.path.localeCompare(b.path, "en"));
|
|
@@ -7253,7 +7351,7 @@ async function runtimeGenerationIntegrityAsync(directory2) {
|
|
|
7253
7351
|
const root = resolve20(directory2), result = [], buffer = Buffer.allocUnsafe(1024 * 1024);
|
|
7254
7352
|
const files = generationFiles(root);
|
|
7255
7353
|
for (const { path: path3, stat: before } of files) {
|
|
7256
|
-
const file =
|
|
7354
|
+
const file = join22(root, path3), handle = await open4(file, constants11.O_RDONLY | (constants11.O_NOFOLLOW ?? 0)), hash2 = createHash19("sha256");
|
|
7257
7355
|
let bytes = 0;
|
|
7258
7356
|
try {
|
|
7259
7357
|
while (true) {
|
|
@@ -7297,17 +7395,17 @@ async function restoreRuntimePublication(options) {
|
|
|
7297
7395
|
await restorePublication({ ...options, destination, deferReceipt: true });
|
|
7298
7396
|
const lance = [], sessionStates = [];
|
|
7299
7397
|
for (const directory2 of ["lance", "sessions"]) {
|
|
7300
|
-
mkdirSync10(
|
|
7398
|
+
mkdirSync10(join23(destination, directory2), { mode: 448 });
|
|
7301
7399
|
await syncDirectory(destination);
|
|
7302
7400
|
}
|
|
7303
7401
|
for (const kind of manifest.profile.trees.filter((tree) => tree.kind === "vector")) {
|
|
7304
|
-
const tree = manifest.trees.find((tree2) => tree2.id === kind.id), directory2 =
|
|
7402
|
+
const tree = manifest.trees.find((tree2) => tree2.id === kind.id), directory2 = join23(destination, "lance", tree.id);
|
|
7305
7403
|
await restoreLancePublication({ tree, objects: receiver.objects, destination: directory2 });
|
|
7306
|
-
await syncDirectory(
|
|
7404
|
+
await syncDirectory(join23(destination, "lance"));
|
|
7307
7405
|
lance.push({ treeId: tree.id, directory: `lance/${tree.id}` });
|
|
7308
7406
|
}
|
|
7309
7407
|
for (const session of sessions) {
|
|
7310
|
-
const directory2 =
|
|
7408
|
+
const directory2 = join23(destination, "sessions", session.treeId), db = new DatabaseSync19(join23(destination, "databases", session.databaseId + ".sqlite"), { readOnly: true });
|
|
7311
7409
|
try {
|
|
7312
7410
|
const head = db.prepare("SELECT head,digest FROM e7_replication_control WHERE role='replica'").get();
|
|
7313
7411
|
if (head?.head !== session.head.sequence || head.digest !== session.head.digest) throw new Error("PUBLICATION_DATABASE_SNAPSHOT_MISMATCH");
|
|
@@ -7315,13 +7413,13 @@ async function restoreRuntimePublication(options) {
|
|
|
7315
7413
|
} finally {
|
|
7316
7414
|
db.close();
|
|
7317
7415
|
}
|
|
7318
|
-
await syncDirectory(
|
|
7416
|
+
await syncDirectory(join23(destination, "sessions"));
|
|
7319
7417
|
sessionStates.push({ treeId: session.treeId, databaseId: session.databaseId, directory: `sessions/${session.treeId}` });
|
|
7320
7418
|
}
|
|
7321
7419
|
const after = await receiver.status(false);
|
|
7322
7420
|
if (!after.dataReady || after.published?.sequence !== manifest.sequence || after.published.digest !== status.published.digest) throw new Error("PUBLICATION_CONCURRENT_CHANGE");
|
|
7323
|
-
writeFileSync14(
|
|
7324
|
-
writeFileSync14(
|
|
7421
|
+
writeFileSync14(join23(destination, ".publication-receipt.json"), JSON.stringify(status.published), { flag: "wx", mode: 384, flush: true });
|
|
7422
|
+
writeFileSync14(join23(destination, ".runtime-publication-receipt.json"), JSON.stringify({
|
|
7325
7423
|
format: "engine7-runtime-publication-restore-v1",
|
|
7326
7424
|
profile: manifest.profile,
|
|
7327
7425
|
receipt: status.published,
|
|
@@ -7348,7 +7446,7 @@ function databaseFile2(value2) {
|
|
|
7348
7446
|
}
|
|
7349
7447
|
function requireStandby(stateDir) {
|
|
7350
7448
|
try {
|
|
7351
|
-
const marker = JSON.parse(readPrivateFile(
|
|
7449
|
+
const marker = JSON.parse(readPrivateFile(join24(stateDir, ".travel-restored.json")).toString());
|
|
7352
7450
|
if (marker.activationAllowed !== false) throw new Error();
|
|
7353
7451
|
} catch {
|
|
7354
7452
|
throw new Error("PUBLICATION_STANDBY_GUARD_REQUIRED");
|
|
@@ -7388,20 +7486,20 @@ async function runPublicationCli(args) {
|
|
|
7388
7486
|
}
|
|
7389
7487
|
try {
|
|
7390
7488
|
const operate = async () => {
|
|
7391
|
-
const objects = await PublicationObjects.open({ directory:
|
|
7489
|
+
const objects = await PublicationObjects.open({ directory: join24(dataDir, "objects"), key: key2, identity: profile.identity, maximumBytes: config.maximumBytes });
|
|
7392
7490
|
const databases = /* @__PURE__ */ Object.create(null);
|
|
7393
7491
|
const sources = /* @__PURE__ */ Object.create(null), replicas = /* @__PURE__ */ Object.create(null);
|
|
7394
7492
|
let receiver;
|
|
7395
7493
|
try {
|
|
7396
7494
|
for (let i = 0; i < config.databases.length; i++) {
|
|
7397
|
-
const d = config.databases[i], probe = new
|
|
7495
|
+
const d = config.databases[i], probe = new DatabaseSync20(databasePaths[i], { readOnly: true });
|
|
7398
7496
|
let component;
|
|
7399
7497
|
try {
|
|
7400
7498
|
component = readSchemaVersion(probe)?.component;
|
|
7401
7499
|
} finally {
|
|
7402
7500
|
probe.close();
|
|
7403
7501
|
}
|
|
7404
|
-
const db = new
|
|
7502
|
+
const db = new DatabaseSync20(databasePaths[i], { allowExtension: component === "legacy-memory" });
|
|
7405
7503
|
databases[d.id] = db;
|
|
7406
7504
|
if (component === "legacy-memory") loadLegacySQLiteVectorExtension(db, d.sqliteVecExtensionFile === void 0 ? void 0 : path2(d.sqliteVecExtensionFile));
|
|
7407
7505
|
if (d.writerSchemaVersion !== void 0) {
|
|
@@ -7427,13 +7525,13 @@ async function runPublicationCli(args) {
|
|
|
7427
7525
|
}
|
|
7428
7526
|
if (command === "prepare") {
|
|
7429
7527
|
const manifestFile = path2(config.manifestFile);
|
|
7430
|
-
if (realpathSync14(
|
|
7528
|
+
if (realpathSync14(dirname14(manifestFile)) !== dirname14(manifestFile)) throw new Error("SYMLINK_REFUSED");
|
|
7431
7529
|
if (!Array.isArray(config.roots)) throw new Error("PUBLICATION_INCOMPLETE_TREES");
|
|
7432
7530
|
const roots = config.roots.map((r) => ({ id: r.id, path: path2(r.path) }));
|
|
7433
7531
|
for (const r of roots) if (!isWithin(stateDir, r.path) || isWithin(r.path, manifestFile) || isWithin(r.path, keyFile)) throw new Error("PUBLICATION_OVERLAPPING_PATHS");
|
|
7434
7532
|
const manifest = await capturePublication({ profile, roots, objects, sources, sequence: config.sequence, parentDigest: config.parentDigest, deletionWatermark: config.deletionWatermark });
|
|
7435
7533
|
writeFileSync15(manifestFile, JSON.stringify(manifest), { mode: 384, flag: "wx", flush: true });
|
|
7436
|
-
await syncDirectory(
|
|
7534
|
+
await syncDirectory(dirname14(manifestFile));
|
|
7437
7535
|
return { sequence: manifest.sequence, files: manifest.trees.reduce((n, t) => n + t.files.length, 0), activationAllowed: false };
|
|
7438
7536
|
}
|
|
7439
7537
|
if (command === "sync" || command === "drain") {
|
|
@@ -7459,11 +7557,11 @@ async function runPublicationCli(args) {
|
|
|
7459
7557
|
client.close();
|
|
7460
7558
|
}
|
|
7461
7559
|
}
|
|
7462
|
-
receiver = await PublicationReplica.open({ directory:
|
|
7560
|
+
receiver = await PublicationReplica.open({ directory: join24(dataDir, "publications"), profile, objects, replicas, minimumDeletionWatermark: config.minimumDeletionWatermark });
|
|
7463
7561
|
if (command === "inspect") return await receiver.status();
|
|
7464
7562
|
if (preserveReplicaCommands.includes(command)) {
|
|
7465
7563
|
const deletionWatermark = recoveryDeletionReader(config);
|
|
7466
|
-
const archive = await RuntimeRecoveryArchive.open({ directory:
|
|
7564
|
+
const archive = await RuntimeRecoveryArchive.open({ directory: join24(dataDir, "recovery"), objects, initialize: config.initializeRecoveryArchive === true });
|
|
7467
7565
|
try {
|
|
7468
7566
|
let manifest;
|
|
7469
7567
|
try {
|