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
|
@@ -138,8 +138,8 @@ import { randomUUID as randomUUID2, verify } from "node:crypto";
|
|
|
138
138
|
import { constants as constants4, closeSync as closeSync4, existsSync as existsSync2, fstatSync as fstatSync3, fsyncSync as fsyncSync4, lstatSync as lstatSync3, mkdirSync as mkdirSync3, openSync as openSync4, readFileSync as readFileSync2, renameSync, writeFileSync as writeFileSync2 } from "node:fs";
|
|
139
139
|
import { basename, dirname as dirname2, join as join4, resolve as resolve4 } from "node:path";
|
|
140
140
|
function assertPrivateDirectory2(path2) {
|
|
141
|
-
const
|
|
142
|
-
if (!
|
|
141
|
+
const stat2 = lstatSync3(path2);
|
|
142
|
+
if (!stat2.isDirectory() || stat2.isSymbolicLink() || process.platform !== "win32" && (stat2.uid !== process.getuid() || stat2.mode & 63)) throw new Error("TRAVEL_PRIVATE_CONTROL_REQUIRED");
|
|
143
143
|
}
|
|
144
144
|
function readPrivateFile2(path2, maximum) {
|
|
145
145
|
const before = lstatSync3(path2);
|
|
@@ -1386,7 +1386,7 @@ var init_timing = __esm({
|
|
|
1386
1386
|
|
|
1387
1387
|
// src/continuity/runtime-generation-data.ts
|
|
1388
1388
|
import { createHash as createHash13 } from "node:crypto";
|
|
1389
|
-
import { join as
|
|
1389
|
+
import { join as join15, resolve as resolve14 } from "node:path";
|
|
1390
1390
|
import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
1391
1391
|
import { existsSync as existsSync7 } from "node:fs";
|
|
1392
1392
|
|
|
@@ -1396,17 +1396,17 @@ import { constants, lstatSync, mkdirSync, openSync, closeSync, readFileSync, wri
|
|
|
1396
1396
|
function validateKeyIdentity(value) {
|
|
1397
1397
|
if (!value || ["tenantId", "companionId", "seatId", "keyId"].some((k) => typeof value[k] !== "string" || !/^[A-Za-z0-9][A-Za-z0-9_.:-]{0,127}$/.test(value[k])) || !Number.isSafeInteger(value.generation) || value.generation < 1) throw new Error("KEY_SERVICE_INVALID_IDENTITY");
|
|
1398
1398
|
}
|
|
1399
|
-
function assertPrivateStat(
|
|
1400
|
-
if ((directory2 ? !
|
|
1399
|
+
function assertPrivateStat(stat2, directory2) {
|
|
1400
|
+
if ((directory2 ? !stat2.isDirectory() : !stat2.isFile()) || process.platform !== "win32" && ((stat2.mode & 63) !== 0 || stat2.uid !== process.getuid?.()))
|
|
1401
1401
|
throw new Error("KEY_SERVICE_PRIVATE_PATH_REQUIRED");
|
|
1402
1402
|
}
|
|
1403
1403
|
function readPrivateFile(path2, maximumBytes = 65536) {
|
|
1404
1404
|
assertPrivateStat(lstatSync(path2), false);
|
|
1405
1405
|
const fd = openSync(path2, constants.O_RDONLY | (constants.O_NOFOLLOW ?? 0));
|
|
1406
1406
|
try {
|
|
1407
|
-
const
|
|
1408
|
-
assertPrivateStat(
|
|
1409
|
-
if (
|
|
1407
|
+
const stat2 = fstatSync(fd);
|
|
1408
|
+
assertPrivateStat(stat2, false);
|
|
1409
|
+
if (stat2.size > maximumBytes) throw new Error("KEY_SERVICE_INVALID_FILE_SIZE");
|
|
1410
1410
|
return readFileSync(fd);
|
|
1411
1411
|
} finally {
|
|
1412
1412
|
closeSync(fd);
|
|
@@ -2035,10 +2035,11 @@ var STATE_EXCLUDED = {
|
|
|
2035
2035
|
var NESTED_EXCLUDED = { ".git": "source control metadata", node_modules: "installed dependencies", __pycache__: "Python bytecode cache" };
|
|
2036
2036
|
var WORKSPACE_DIAGNOSTICS = /* @__PURE__ */ new Set([".system-prompt.txt", ".context-debug.txt"]);
|
|
2037
2037
|
var RUNTIME_CONTROL = /* @__PURE__ */ new Set([".continuity", ".engine.pid", ".bg-worker.pid", ".travel-restored.json", ".travel-enrolled.json", ".travel-active.json"]);
|
|
2038
|
-
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(" "));
|
|
2038
|
+
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(" "));
|
|
2039
2039
|
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(" "));
|
|
2040
2040
|
function coreReason(path2) {
|
|
2041
2041
|
const name = path2.split("/").at(-1);
|
|
2042
|
+
if (path2 === "chan7-files" || path2.startsWith("chan7-files/")) return void 0;
|
|
2042
2043
|
if (CORE_OMITTED.has(name) || /(?:\.lance$|(?:^|[-.])bak(?:[-.]|$))/i.test(name)) return "optional attachments, historical copies or rebuildable indexes; outside core travel";
|
|
2043
2044
|
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" || path2 === "mem7/spool/intake.failed.jsonl") return "attachments, installed binaries or diagnostics; outside core travel";
|
|
2044
2045
|
}
|
|
@@ -2578,6 +2579,8 @@ async function runtimeFileEntries(options) {
|
|
|
2578
2579
|
excludeStateEntries: { ...options.inventory.excludeStateEntries },
|
|
2579
2580
|
excludeWorkspaceEntries: { ...options.inventory.excludeWorkspaceEntries }
|
|
2580
2581
|
};
|
|
2582
|
+
for (const path2 of ["mem7/spool/intake.write.lock", "mem7/spool/intake.write.lock.reap"])
|
|
2583
|
+
inventoryOptions.excludeStateEntries[path2] = "local queue writer ownership; recreated per process";
|
|
2581
2584
|
for (const directory2 of [...options.vectorDirectories, ...options.sessionDirectories].map(resolvePath)) {
|
|
2582
2585
|
const info = lstatSync6(directory2);
|
|
2583
2586
|
if (!info.isDirectory() || info.isSymbolicLink() || realpathSync3(directory2) !== directory2) throw new Error("SYMLINK_REFUSED");
|
|
@@ -2602,16 +2605,17 @@ async function runtimeFileEntries(options) {
|
|
|
2602
2605
|
db.close();
|
|
2603
2606
|
}
|
|
2604
2607
|
}
|
|
2605
|
-
|
|
2606
|
-
for (const entry of inventory.entries) {
|
|
2607
|
-
if (/\.lance(?:\/|$)/i.test(entry.path)) throw new Error("RUNTIME_UNCLASSIFIED_LANCE");
|
|
2608
|
-
if (entry.kind === "sidecar" && immutable.has(entry.source.replace(/-(wal|shm|journal)$/, ""))) throw new Error("RUNTIME_IMMUTABLE_DATABASE_HAS_SIDECAR");
|
|
2609
|
-
}
|
|
2610
|
-
return inventory.entries.filter((entry) => entry.kind === "directory" || entry.kind === "file" || immutable.has(entry.source));
|
|
2608
|
+
return inventory.entries.filter((entry) => entry.kind === "directory" || entry.kind === "file" || immutable.has(entry.source) || entry.kind === "sqlite" && !dynamic.has(entry.source));
|
|
2611
2609
|
};
|
|
2612
2610
|
return await classify();
|
|
2613
2611
|
}
|
|
2614
|
-
var signatures = (entries) => entries.map((entry) => [
|
|
2612
|
+
var signatures = (entries) => entries.map((entry) => [
|
|
2613
|
+
entry.root,
|
|
2614
|
+
entry.path,
|
|
2615
|
+
entry.kind,
|
|
2616
|
+
entry.mode,
|
|
2617
|
+
entry.kind === "directory" ? entry.signature.split(":").slice(0, -3).join(":") : entry.signature
|
|
2618
|
+
]);
|
|
2615
2619
|
async function runtimeFileFingerprint(options) {
|
|
2616
2620
|
return createHash5("sha256").update(JSON.stringify(signatures(await runtimeFileEntries(options)))).digest("hex");
|
|
2617
2621
|
}
|
|
@@ -3701,10 +3705,33 @@ var RuntimePublicationSource = class _RuntimePublicationSource {
|
|
|
3701
3705
|
if (this.control().head !== 0) throw new Error("RUNTIME_PUBLICATION_INITIAL_ALREADY_PREPARED");
|
|
3702
3706
|
return this.prepareCapture(options, () => captureRuntimeH(options), true);
|
|
3703
3707
|
}
|
|
3704
|
-
/** The
|
|
3705
|
-
*
|
|
3708
|
+
/** The final LOCAL original is archived independently of the transport queue.
|
|
3709
|
+
* Read-only stores and writer exclusion remain held through its durable seal. */
|
|
3706
3710
|
async withStoppedPreparation(options, operation) {
|
|
3707
|
-
|
|
3711
|
+
const before = this.control();
|
|
3712
|
+
if (!same2(options.profile, this.profile) || options.objects !== this.objects) throw new Error("RUNTIME_PUBLICATION_PROFILE_MISMATCH");
|
|
3713
|
+
if (options.deletionWatermark < before.watermark) throw new Error("PUBLICATION_DELETION_REGRESSION");
|
|
3714
|
+
return withStoppedRuntimeH(options, async (parts) => {
|
|
3715
|
+
const manifest = normalizePublication({
|
|
3716
|
+
format: "engine7-publication-v1",
|
|
3717
|
+
profile: this.profile,
|
|
3718
|
+
sequence: before.head + 1,
|
|
3719
|
+
parentDigest: before.digest,
|
|
3720
|
+
databases: parts.databases,
|
|
3721
|
+
trees: parts.trees,
|
|
3722
|
+
deletionWatermark: parts.deletionWatermark
|
|
3723
|
+
});
|
|
3724
|
+
const old = before.head ? await this.readManifest(before.head) : null;
|
|
3725
|
+
if (old && manifest.deletionWatermark === old.manifest.deletionWatermark) {
|
|
3726
|
+
const present = new Set(manifest.trees.flatMap((tree) => tree.files.map((file) => tree.id + "/" + file.path)));
|
|
3727
|
+
if (old.manifest.trees.some((tree) => tree.files.some((file) => !present.has(tree.id + "/" + file.path)))) throw new Error("PUBLICATION_REMOVAL_REQUIRES_DELETION");
|
|
3728
|
+
}
|
|
3729
|
+
const current2 = this.control();
|
|
3730
|
+
if (current2.head !== before.head || current2.digest !== before.digest) throw new Error("RUNTIME_PUBLICATION_CONCURRENT_CHANGE");
|
|
3731
|
+
if (manifest.deletionWatermark < current2.watermark) throw new Error("PUBLICATION_DELETION_REGRESSION");
|
|
3732
|
+
if (old && stateHash(old.manifest) === stateHash(manifest)) return operation({ ...old, sequence: before.head, activationAllowed: false });
|
|
3733
|
+
return operation({ sequence: manifest.sequence, digest: publicationDigest(manifest), manifest, activationAllowed: false });
|
|
3734
|
+
});
|
|
3708
3735
|
}
|
|
3709
3736
|
async prepareCapture(options, capture2, initial = false) {
|
|
3710
3737
|
const c = this.control(), pending = this.status();
|
|
@@ -4012,20 +4039,85 @@ async function openRuntimeGenerationSource(options) {
|
|
|
4012
4039
|
}
|
|
4013
4040
|
}
|
|
4014
4041
|
|
|
4015
|
-
// src/continuity/
|
|
4042
|
+
// src/continuity/native-database-snapshot.ts
|
|
4016
4043
|
import { DatabaseSync as DatabaseSync13, backup } from "node:sqlite";
|
|
4044
|
+
import { lstat as lstat2 } from "node:fs/promises";
|
|
4045
|
+
|
|
4046
|
+
// src/continuity/native-file-copy.ts
|
|
4047
|
+
import { constants as constants7 } from "node:fs";
|
|
4048
|
+
import { copyFile, link as link2, rename, rm, stat } from "node:fs/promises";
|
|
4049
|
+
import { execFile } from "node:child_process";
|
|
4050
|
+
import { promisify as promisify2 } from "node:util";
|
|
4051
|
+
import { dirname as dirname9, join as join13 } from "node:path";
|
|
4052
|
+
import { randomUUID as randomUUID6 } from "node:crypto";
|
|
4053
|
+
var exec = promisify2(execFile);
|
|
4054
|
+
async function copyNativeFile(source, destination, flags = constants7.COPYFILE_EXCL | constants7.COPYFILE_FICLONE, bytes) {
|
|
4055
|
+
if (process.platform !== "darwin") {
|
|
4056
|
+
await copyFile(source, destination, flags);
|
|
4057
|
+
return;
|
|
4058
|
+
}
|
|
4059
|
+
if ((bytes ?? (await stat(source)).size) < 1024 * 1024) {
|
|
4060
|
+
await copyFile(source, destination, flags);
|
|
4061
|
+
return;
|
|
4062
|
+
}
|
|
4063
|
+
const temporary = join13(dirname9(destination), ".e7-native-copy-" + randomUUID6());
|
|
4064
|
+
try {
|
|
4065
|
+
await exec("/bin/cp", ["-c", "-p", source, temporary], { maxBuffer: 8192 });
|
|
4066
|
+
if (flags & constants7.COPYFILE_EXCL) await link2(temporary, destination);
|
|
4067
|
+
else await rename(temporary, destination);
|
|
4068
|
+
} finally {
|
|
4069
|
+
await rm(temporary, { force: true });
|
|
4070
|
+
}
|
|
4071
|
+
}
|
|
4072
|
+
|
|
4073
|
+
// src/continuity/native-database-snapshot.ts
|
|
4074
|
+
async function snapshotNativeDatabase(db, destination) {
|
|
4075
|
+
if (process.platform !== "darwin") {
|
|
4076
|
+
await backup(db, destination);
|
|
4077
|
+
return;
|
|
4078
|
+
}
|
|
4079
|
+
const file = String(db.prepare("PRAGMA database_list").all().find((row) => row.name === "main")?.file ?? "");
|
|
4080
|
+
if (!file) {
|
|
4081
|
+
await backup(db, destination);
|
|
4082
|
+
return;
|
|
4083
|
+
}
|
|
4084
|
+
const reader = new DatabaseSync13(file, { readOnly: true, allowExtension: true });
|
|
4085
|
+
try {
|
|
4086
|
+
reader.exec("BEGIN");
|
|
4087
|
+
reader.prepare("SELECT count(*) FROM sqlite_master").get();
|
|
4088
|
+
await copyNativeFile(file, destination);
|
|
4089
|
+
try {
|
|
4090
|
+
await lstat2(file + "-wal");
|
|
4091
|
+
await copyNativeFile(file + "-wal", destination + "-wal");
|
|
4092
|
+
} catch (error) {
|
|
4093
|
+
if (error.code !== "ENOENT") throw error;
|
|
4094
|
+
}
|
|
4095
|
+
reader.exec("ROLLBACK");
|
|
4096
|
+
} finally {
|
|
4097
|
+
reader.close();
|
|
4098
|
+
}
|
|
4099
|
+
const target = new DatabaseSync13(destination);
|
|
4100
|
+
try {
|
|
4101
|
+
if (Number(target.prepare("PRAGMA wal_checkpoint(TRUNCATE)").get()?.busy) !== 0) throw Error("DATABASE_SNAPSHOT_BUSY");
|
|
4102
|
+
} finally {
|
|
4103
|
+
target.close();
|
|
4104
|
+
}
|
|
4105
|
+
}
|
|
4106
|
+
|
|
4107
|
+
// src/continuity/recovery-archive.ts
|
|
4108
|
+
import { DatabaseSync as DatabaseSync14 } from "node:sqlite";
|
|
4017
4109
|
import { existsSync as existsSync6, lstatSync as lstatSync12, mkdtempSync, rmSync, writeFileSync as writeFileSync8, chmodSync as chmodSync2 } from "node:fs";
|
|
4018
|
-
import { join as
|
|
4110
|
+
import { join as join14, resolve as resolve13 } from "node:path";
|
|
4019
4111
|
init_sqlite_replication();
|
|
4020
4112
|
|
|
4021
4113
|
// src/continuity/crypto.ts
|
|
4022
|
-
import { constants as
|
|
4023
|
-
import { open as open3, lstat as
|
|
4114
|
+
import { constants as constants8, createWriteStream, openSync as openSync10 } from "node:fs";
|
|
4115
|
+
import { open as open3, lstat as lstat3, link as link3, unlink as unlink2, writeFile as writeFile2, appendFile } from "node:fs/promises";
|
|
4024
4116
|
var MAGIC2 = Buffer.from("E7OBJ001");
|
|
4025
4117
|
var HEADER_SIZE = MAGIC2.length + 12;
|
|
4026
4118
|
async function syncDirectory(directory2) {
|
|
4027
4119
|
if (process.platform === "win32") return;
|
|
4028
|
-
const handle = await open3(directory2,
|
|
4120
|
+
const handle = await open3(directory2, constants8.O_RDONLY);
|
|
4029
4121
|
try {
|
|
4030
4122
|
await handle.sync();
|
|
4031
4123
|
} finally {
|
|
@@ -4139,8 +4231,8 @@ var RuntimeRecoveryArchive = class _RuntimeRecoveryArchive {
|
|
|
4139
4231
|
constructor(options) {
|
|
4140
4232
|
this.directory = resolve13(options.directory);
|
|
4141
4233
|
this.objects = options.objects;
|
|
4142
|
-
this.file =
|
|
4143
|
-
this.marker =
|
|
4234
|
+
this.file = join14(this.directory, "archives.sqlite");
|
|
4235
|
+
this.marker = join14(this.directory, "archive.json");
|
|
4144
4236
|
if (options.initialize) preparePrivateDirectory(this.directory);
|
|
4145
4237
|
else {
|
|
4146
4238
|
try {
|
|
@@ -4154,7 +4246,7 @@ var RuntimeRecoveryArchive = class _RuntimeRecoveryArchive {
|
|
|
4154
4246
|
if (!fresh) this.checkMarker();
|
|
4155
4247
|
preparePrivateDatabase(this.file);
|
|
4156
4248
|
try {
|
|
4157
|
-
this.db = new
|
|
4249
|
+
this.db = new DatabaseSync14(this.file);
|
|
4158
4250
|
this.db.exec("PRAGMA synchronous=FULL; PRAGMA busy_timeout=1000");
|
|
4159
4251
|
if (fresh) {
|
|
4160
4252
|
this.db.exec(schema3);
|
|
@@ -4248,6 +4340,7 @@ var RuntimeRecoveryArchive = class _RuntimeRecoveryArchive {
|
|
|
4248
4340
|
this.active();
|
|
4249
4341
|
const { id: id2, kind } = options, manifest = normalizePublication(options.manifest), digest3 = publicationDigest(manifest);
|
|
4250
4342
|
if (typeof id2 !== "string" || !ID2.test(id2) || !["COMMON", "LOCAL", "REMOTE"].includes(kind)) throw new Error("RECOVERY_INVALID_ID");
|
|
4343
|
+
if (options.snapshotDatabase && (kind !== "LOCAL" || id2 !== "first-baseline" || manifest.sequence !== 1 || manifest.parentDigest !== "0".repeat(64))) throw new Error("RECOVERY_INVALID_SNAPSHOT");
|
|
4251
4344
|
if (!same4(manifest.profile.identity, this.objects.identity)) throw new Error("RECOVERY_IDENTITY_MISMATCH");
|
|
4252
4345
|
const deletion = async () => {
|
|
4253
4346
|
const value = await options.deletionWatermark();
|
|
@@ -4289,9 +4382,9 @@ var RuntimeRecoveryArchive = class _RuntimeRecoveryArchive {
|
|
|
4289
4382
|
validateRecoveryArchiveEntry(retained, this.objects.identity);
|
|
4290
4383
|
if (!same4(retained.manifest, manifest) || !same4(retained.publication, publication) || retained.databases.some((d) => d.role !== "replica")) throw new Error("RECOVERY_IDEMPOTENCY_CONFLICT");
|
|
4291
4384
|
}
|
|
4292
|
-
const temporary = mkdtempSync(
|
|
4385
|
+
const temporary = mkdtempSync(join14(this.directory, ".capture-"));
|
|
4293
4386
|
try {
|
|
4294
|
-
writeFileSync8(
|
|
4387
|
+
writeFileSync8(join14(temporary, ".travel-restored.json"), JSON.stringify({ activationAllowed: false }), { mode: 384, flush: true });
|
|
4295
4388
|
const databases = [];
|
|
4296
4389
|
if (retained) {
|
|
4297
4390
|
if (options.verifyRetained !== false) for (const database of retained.databases) await verifyContent(this.objects, database.content);
|
|
@@ -4300,10 +4393,11 @@ var RuntimeRecoveryArchive = class _RuntimeRecoveryArchive {
|
|
|
4300
4393
|
for (let offset = 0; !retained && offset < manifest.databases.length; offset += 6) {
|
|
4301
4394
|
const results = await Promise.allSettled(manifest.databases.slice(offset, offset + 6).map(async (d) => {
|
|
4302
4395
|
floor = Math.max(floor, await verify2());
|
|
4303
|
-
const file =
|
|
4304
|
-
await
|
|
4396
|
+
const file = join14(temporary, d.databaseId + ".sqlite");
|
|
4397
|
+
if (options.snapshotDatabase) await options.snapshotDatabase(options.databases[d.databaseId], file, d.databaseId);
|
|
4398
|
+
else await snapshotNativeDatabase(options.databases[d.databaseId], file);
|
|
4305
4399
|
chmodSync2(file, 384);
|
|
4306
|
-
const copy = new
|
|
4400
|
+
const copy = new DatabaseSync14(file, { readOnly: true });
|
|
4307
4401
|
let schemaHash2;
|
|
4308
4402
|
try {
|
|
4309
4403
|
schemaHash2 = validateRecoveryDatabase(copy, manifest, d.databaseId, role, void 0, false);
|
|
@@ -4357,12 +4451,12 @@ var RuntimeRecoveryArchive = class _RuntimeRecoveryArchive {
|
|
|
4357
4451
|
const floor = await checkRecoveryDeletionAsync(value.manifest, deletionWatermark);
|
|
4358
4452
|
const prior = this.db.prepare("SELECT kind,manifest_digest,content FROM archives WHERE id=?").get(value.id);
|
|
4359
4453
|
if (prior && (prior.kind !== value.kind || prior.manifest_digest !== receipt.manifestDigest || JSON.parse(String(prior.content)).sha256 !== receipt.digest)) throw new Error("RECOVERY_IDEMPOTENCY_CONFLICT");
|
|
4360
|
-
const temporary = verifyDatabases ? mkdtempSync(
|
|
4454
|
+
const temporary = verifyDatabases ? mkdtempSync(join14(this.directory, ".import-")) : void 0;
|
|
4361
4455
|
try {
|
|
4362
4456
|
if (temporary) for (const db of value.databases) {
|
|
4363
|
-
const file =
|
|
4457
|
+
const file = join14(temporary, db.databaseId + ".sqlite");
|
|
4364
4458
|
await this.objects.restoreFile(db.content, file);
|
|
4365
|
-
const probe = new
|
|
4459
|
+
const probe = new DatabaseSync14(file, { readOnly: true });
|
|
4366
4460
|
try {
|
|
4367
4461
|
validateRecoveryDatabase(probe, value.manifest, db.databaseId, db.role, db.schemaHash);
|
|
4368
4462
|
} finally {
|
|
@@ -4950,7 +5044,7 @@ var RuntimeSyncScheduler = class {
|
|
|
4950
5044
|
};
|
|
4951
5045
|
|
|
4952
5046
|
// src/continuity/runtime-checkpoints.ts
|
|
4953
|
-
import { DatabaseSync as
|
|
5047
|
+
import { DatabaseSync as DatabaseSync15 } from "node:sqlite";
|
|
4954
5048
|
var zero = "0".repeat(64);
|
|
4955
5049
|
var natural3 = (value) => typeof value === "number" && Number.isSafeInteger(value) && value >= 0;
|
|
4956
5050
|
async function readPublishedRuntimeCheckpoints(options) {
|
|
@@ -4981,8 +5075,8 @@ async function openGenerationData(options) {
|
|
|
4981
5075
|
if (!runtime || !/^[a-f0-9]{64}$/.test(options.keySha256) || typeof options.initialize !== "boolean") throw new Error("TRAVEL_DATA_CONFIG");
|
|
4982
5076
|
const interval = options.intervalMs ?? 5e3;
|
|
4983
5077
|
if (!Number.isSafeInteger(interval) || interval < 250 || interval > 6e4) throw new Error("TRAVEL_DATA_CONFIG");
|
|
4984
|
-
const sourcePresent = ["source.json", "source.sqlite", "sender.sqlite"].some((file) => existsSync7(
|
|
4985
|
-
const archivePresent = ["archive.json", "archives.sqlite"].map((file) => existsSync7(
|
|
5078
|
+
const sourcePresent = ["source.json", "source.sqlite", "sender.sqlite"].some((file) => existsSync7(join15(options.dataDirectory, "runtime-publications", file)));
|
|
5079
|
+
const archivePresent = ["archive.json", "archives.sqlite"].map((file) => existsSync7(join15(options.dataDirectory, "recovery", file)));
|
|
4986
5080
|
if (sourcePresent && !archivePresent.every(Boolean) || !sourcePresent && archivePresent.some(Boolean)) throw new Error("RECOVERY_ARCHIVE_REQUIRED");
|
|
4987
5081
|
let checkedAt = -Infinity, checkedFloor = -1, closed = false, keyCheck;
|
|
4988
5082
|
let objects, opened, archive;
|
|
@@ -5009,6 +5103,7 @@ async function openGenerationData(options) {
|
|
|
5009
5103
|
keyCheck = void 0;
|
|
5010
5104
|
});
|
|
5011
5105
|
const availableAfterWork = async () => {
|
|
5106
|
+
runtime.assert("CONTROL");
|
|
5012
5107
|
if (clock() - checkedAt >= 1e4) await refresh();
|
|
5013
5108
|
assertAvailable();
|
|
5014
5109
|
};
|
|
@@ -5164,7 +5259,7 @@ async function openGenerationData(options) {
|
|
|
5164
5259
|
});
|
|
5165
5260
|
}, 1e4);
|
|
5166
5261
|
opened = await openRuntimeGenerationSource({ stateDir: options.stateDir, dataDirectory: options.dataDirectory, objects, initialize: options.initialize, mode: "LIVE" });
|
|
5167
|
-
archive = await RuntimeRecoveryArchive.open({ directory:
|
|
5262
|
+
archive = await RuntimeRecoveryArchive.open({ directory: join15(options.dataDirectory, "recovery"), objects, initialize: options.initialize });
|
|
5168
5263
|
const id2 = "baseline-" + hash2(JSON.stringify(opened.profile));
|
|
5169
5264
|
try {
|
|
5170
5265
|
baseline = (await archive.read(id2)).receipt;
|
|
@@ -5172,7 +5267,8 @@ async function openGenerationData(options) {
|
|
|
5172
5267
|
if (!(error instanceof Error) || error.message !== "RECOVERY_ARCHIVE_NOT_FOUND") throw error;
|
|
5173
5268
|
}
|
|
5174
5269
|
if (baseline && (baseline.kind !== "LOCAL" || baseline.manifestDigest !== (await opened.source.read(1)).digest)) throw new Error("TRAVEL_DATA_BASELINE_REQUIRED");
|
|
5175
|
-
await
|
|
5270
|
+
if (baseline) await availableAfterWork();
|
|
5271
|
+
else await capture2();
|
|
5176
5272
|
if (options.peer) await connectPeer(options.peer);
|
|
5177
5273
|
return {
|
|
5178
5274
|
capture: capture2,
|
|
@@ -5182,6 +5278,7 @@ async function openGenerationData(options) {
|
|
|
5182
5278
|
close,
|
|
5183
5279
|
isBusy: () => !!active || !!scheduler?.status().inFlight,
|
|
5184
5280
|
assertAvailable,
|
|
5281
|
+
refreshAvailability: availableAfterWork,
|
|
5185
5282
|
checkpoints: (afterSequence) => readPublishedRuntimeCheckpoints({ source: opened.source, afterSequence, assertAvailable }),
|
|
5186
5283
|
status: () => ({ head: opened.source.head(), baseline, sync: scheduler?.status() ?? null })
|
|
5187
5284
|
};
|
|
@@ -5229,15 +5326,21 @@ async function runGenerationDataCli(args) {
|
|
|
5229
5326
|
process.off("disconnect", stop);
|
|
5230
5327
|
void data.close().then(resolveStop, rejectStop);
|
|
5231
5328
|
};
|
|
5329
|
+
let checking, lastFailure;
|
|
5232
5330
|
const guard = setInterval(() => {
|
|
5233
|
-
|
|
5234
|
-
|
|
5235
|
-
|
|
5236
|
-
|
|
5237
|
-
|
|
5331
|
+
if (stopping || checking) return;
|
|
5332
|
+
checking = data.refreshAvailability().then(() => {
|
|
5333
|
+
lastFailure = void 0;
|
|
5334
|
+
}).catch((error) => {
|
|
5335
|
+
const code = error instanceof Error && /^(?:TRAVEL|KEY_SERVICE)_[A-Z_]+$/.test(error.message) ? error.message : "TRAVEL_DATA_UNAVAILABLE";
|
|
5336
|
+
if (code !== lastFailure) process.stderr.write("[travel-data] " + code + "\n");
|
|
5337
|
+
lastFailure = code;
|
|
5338
|
+
if (["TRAVEL_NODE_KEY_UNAVAILABLE", "KEY_SERVICE_TIMEOUT", "KEY_SERVICE_CONNECTION_FAILED"].includes(code)) return;
|
|
5238
5339
|
process.exitCode = 1;
|
|
5239
5340
|
stop();
|
|
5240
|
-
}
|
|
5341
|
+
}).finally(() => {
|
|
5342
|
+
checking = void 0;
|
|
5343
|
+
});
|
|
5241
5344
|
}, 1e3);
|
|
5242
5345
|
process.once("SIGTERM", stop);
|
|
5243
5346
|
process.once("SIGINT", stop);
|