engine7 7.1.137 → 7.1.140
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -1
- package/dist/bg-worker.mjs +133 -127
- package/dist/cli.mjs +4418 -3209
- package/dist/cpu-router-worker.mjs +604 -8
- package/dist/device-connectors/reader +0 -0
- package/dist/engine-startup.mjs +10270 -5968
- package/dist/main.mjs +10262 -5939
- package/dist/optional-deps.json +78 -0
- package/dist/recall-worker.mjs +57 -53
- package/dist/sqlite-maintenance-worker.mjs +16 -18
- package/dist/topics-worker.mjs +56 -52
- package/dist/travel-authority.mjs +71 -25
- package/dist/travel-console.mjs +301 -110
- package/dist/travel-controller.mjs +321 -56
- package/dist/travel-data.mjs +655 -351
- package/dist/travel-gateway.mjs +34863 -2643
- package/dist/travel-host.mjs +43421 -0
- package/dist/travel-node-data.mjs +609 -281
- package/dist/travel-node.mjs +1424 -621
- package/dist/travel-pairing.mjs +35915 -0
- package/dist/travel-resource.mjs +131 -0
- package/dist/travel-retire.mjs +136 -60
- package/dist/web-console.mjs +2095 -290
- package/package.json +17 -8
- package/scripts/verify-cpu-router-package.mjs +14 -1
- package/templates/config.template.json +14 -0
package/dist/bg-worker.mjs
CHANGED
|
@@ -1075,14 +1075,9 @@ import {
|
|
|
1075
1075
|
fstatSync as fstatSync3,
|
|
1076
1076
|
fsyncSync as fsyncSync3,
|
|
1077
1077
|
readSync,
|
|
1078
|
-
writeSync as writeSync2,
|
|
1079
1078
|
lstatSync as lstatSync4,
|
|
1080
1079
|
realpathSync as realpathSync2,
|
|
1081
|
-
mkdirSync as mkdirSync4
|
|
1082
|
-
readFileSync as readFileSync4,
|
|
1083
|
-
writeFileSync as writeFileSync2,
|
|
1084
|
-
linkSync,
|
|
1085
|
-
unlinkSync as unlinkSync2
|
|
1080
|
+
mkdirSync as mkdirSync4
|
|
1086
1081
|
} from "node:fs";
|
|
1087
1082
|
import { join as join3, dirname as dirname2, resolve as resolve2 } from "node:path";
|
|
1088
1083
|
function assertPrivateDirectory2(path10) {
|
|
@@ -1124,18 +1119,19 @@ function preparePrivateDirectory(path10) {
|
|
|
1124
1119
|
}
|
|
1125
1120
|
assertPrivateDirectory2(path10);
|
|
1126
1121
|
}
|
|
1127
|
-
var PUBLICATION_CHUNK_BYTES, MAGIC, noFollow;
|
|
1122
|
+
var PUBLICATION_CHUNK_BYTES, MAGIC, INLINE_BYTES, noFollow;
|
|
1128
1123
|
var init_publication_objects = __esm({
|
|
1129
1124
|
"src/continuity/publication-objects.ts"() {
|
|
1130
1125
|
"use strict";
|
|
1131
1126
|
PUBLICATION_CHUNK_BYTES = 1024 * 1024;
|
|
1132
1127
|
MAGIC = Buffer.from("E7P1");
|
|
1128
|
+
INLINE_BYTES = 64 * 1024;
|
|
1133
1129
|
noFollow = constants4.O_NOFOLLOW ?? 0;
|
|
1134
1130
|
}
|
|
1135
1131
|
});
|
|
1136
1132
|
|
|
1137
1133
|
// src/continuity/mem7-replication.ts
|
|
1138
|
-
import { closeSync as closeSync5, fsyncSync as fsyncSync4, lstatSync as lstatSync5, openSync as openSync5, writeFileSync as
|
|
1134
|
+
import { closeSync as closeSync5, fsyncSync as fsyncSync4, lstatSync as lstatSync5, openSync as openSync5, writeFileSync as writeFileSync2 } from "node:fs";
|
|
1139
1135
|
import { dirname as dirname3, join as join4 } from "node:path";
|
|
1140
1136
|
function normalize2(value) {
|
|
1141
1137
|
if (!value || !/^[a-f0-9]{64}$/.test(value.schemaHash)) throw new Error("REPLICATION_REGISTRATION_INVALID");
|
|
@@ -1168,7 +1164,7 @@ function ensureMem7ReplicationRegistration(stateDir2, input) {
|
|
|
1168
1164
|
const file = location(stateDir2);
|
|
1169
1165
|
preparePrivateDirectory(dirname3(file));
|
|
1170
1166
|
try {
|
|
1171
|
-
|
|
1167
|
+
writeFileSync2(file, JSON.stringify(registration), { mode: 384, flag: "wx", flush: true });
|
|
1172
1168
|
} catch (error) {
|
|
1173
1169
|
if (error.code !== "EEXIST") throw error;
|
|
1174
1170
|
if (JSON.stringify(readMem7ReplicationRegistration(stateDir2)) !== JSON.stringify(registration)) throw new Error("REPLICATION_REGISTRATION_MISMATCH");
|
|
@@ -3971,7 +3967,7 @@ Follow these principles when generating episodic memories:
|
|
|
3971
3967
|
|
|
3972
3968
|
// src/mem7/core/change-feed.ts
|
|
3973
3969
|
import { createHash as createHash6, randomUUID as randomUUID3 } from "node:crypto";
|
|
3974
|
-
import { existsSync as existsSync3, readFileSync as
|
|
3970
|
+
import { existsSync as existsSync3, readFileSync as readFileSync4, renameSync as renameSync2, unlinkSync as unlinkSync2, writeFileSync as writeFileSync3 } from "node:fs";
|
|
3975
3971
|
function isBusyError(error) {
|
|
3976
3972
|
if (!error || typeof error !== "object") return false;
|
|
3977
3973
|
if (error.errcode === 5) return true;
|
|
@@ -4137,7 +4133,7 @@ CREATE INDEX idx_memory_dependency_slot ON memory_dependencies(scope_id,slot_id)
|
|
|
4137
4133
|
let ledger = {};
|
|
4138
4134
|
if (ledgerPath) {
|
|
4139
4135
|
try {
|
|
4140
|
-
ledger = JSON.parse(
|
|
4136
|
+
ledger = JSON.parse(readFileSync4(ledgerPath, "utf8"))?.heals ?? {};
|
|
4141
4137
|
} catch {
|
|
4142
4138
|
}
|
|
4143
4139
|
if (Number.isFinite(ledger[key4])) {
|
|
@@ -4162,11 +4158,11 @@ CREATE INDEX idx_memory_dependency_slot ON memory_dependencies(scope_id,slot_id)
|
|
|
4162
4158
|
retained[key4] = now2;
|
|
4163
4159
|
const temp = `${ledgerPath}.${randomUUID3()}.tmp`;
|
|
4164
4160
|
try {
|
|
4165
|
-
|
|
4161
|
+
writeFileSync3(temp, JSON.stringify({ version: 1, heals: retained }));
|
|
4166
4162
|
renameSync2(temp, ledgerPath);
|
|
4167
4163
|
} catch (error) {
|
|
4168
4164
|
try {
|
|
4169
|
-
if (existsSync3(temp))
|
|
4165
|
+
if (existsSync3(temp)) unlinkSync2(temp);
|
|
4170
4166
|
} catch {
|
|
4171
4167
|
}
|
|
4172
4168
|
console.warn(`[mem7] \u7F3A\u53E3\u81EA\u6108\u8D26\u672C\u5199\u5165\u5931\u8D25\uFF08\u672C\u8FDB\u7A0B\u5185\u4ECD\u53BB\u91CD\uFF0C\u91CD\u542F\u540E\u53EF\u80FD\u591A\u6CBB\u4E00\u6B21\uFF0C\u5E42\u7B49\u65E0\u5BB3\uFF09\uFF1A${error.message}`);
|
|
@@ -5286,12 +5282,20 @@ CREATE TABLE memory_tombstones (
|
|
|
5286
5282
|
has(scope, kind, id) {
|
|
5287
5283
|
return Boolean(this.db.prepare("SELECT 1 FROM memory_tombstones WHERE scope_id=? AND target_kind=? AND target_id=?").get(scopeId(scope), kind, id));
|
|
5288
5284
|
}
|
|
5285
|
+
/** 1117:deep-recall 的引用只存 scopeId 字符串(无 scope 对象),同判定按 id 直查。 */
|
|
5286
|
+
hasByScopeId(scopeIdValue, kind, id) {
|
|
5287
|
+
return Boolean(this.db.prepare("SELECT 1 FROM memory_tombstones WHERE scope_id=? AND target_kind=? AND target_id=?").get(scopeIdValue, kind, id));
|
|
5288
|
+
}
|
|
5289
5289
|
any(scope) {
|
|
5290
5290
|
return Boolean(this.db.prepare("SELECT 1 FROM memory_tombstones WHERE scope_id=? LIMIT 1").get(scopeId(scope)));
|
|
5291
5291
|
}
|
|
5292
5292
|
anyForOwner(ownerId) {
|
|
5293
5293
|
return Boolean(this.db.prepare("SELECT 1 FROM memory_tombstones t JOIN memory_scopes s ON s.scope_id=t.scope_id WHERE s.owner_id=? LIMIT 1").get(ownerId));
|
|
5294
5294
|
}
|
|
5295
|
+
/** 1117:撤回校验的快速门——墓碑可挂在任意 scope(如旧 default 池)下,不看 owner。 */
|
|
5296
|
+
exists() {
|
|
5297
|
+
return Boolean(this.db.prepare("SELECT 1 FROM memory_tombstones LIMIT 1").get());
|
|
5298
|
+
}
|
|
5295
5299
|
deleteSource(scope, sourceId, expectedVersion, requestKey, reason) {
|
|
5296
5300
|
if (!requestKey || !reason.trim()) throw new Error("INVALID_DELETE_REQUEST");
|
|
5297
5301
|
this.transaction(() => {
|
|
@@ -6026,7 +6030,7 @@ var init_ingest = __esm({
|
|
|
6026
6030
|
|
|
6027
6031
|
// src/mem7/core/legacy-recovery.ts
|
|
6028
6032
|
import { createHash as createHash12 } from "node:crypto";
|
|
6029
|
-
import { readFileSync as
|
|
6033
|
+
import { readFileSync as readFileSync5, realpathSync as realpathSync3, statSync } from "node:fs";
|
|
6030
6034
|
import { isAbsolute, join as join6, relative, resolve as resolve3, sep } from "node:path";
|
|
6031
6035
|
function sessionCandidates(files, mapping) {
|
|
6032
6036
|
const candidates = /* @__PURE__ */ new Map();
|
|
@@ -6036,7 +6040,7 @@ function sessionCandidates(files, mapping) {
|
|
|
6036
6040
|
rejected++;
|
|
6037
6041
|
continue;
|
|
6038
6042
|
}
|
|
6039
|
-
const bytes2 =
|
|
6043
|
+
const bytes2 = readFileSync5(file);
|
|
6040
6044
|
const records = [];
|
|
6041
6045
|
let header;
|
|
6042
6046
|
let invalid = false;
|
|
@@ -6282,7 +6286,7 @@ function recoverLegacyProjections(db, store, input, apply = false) {
|
|
|
6282
6286
|
gap("projection_kind_or_owner_unverified");
|
|
6283
6287
|
continue;
|
|
6284
6288
|
}
|
|
6285
|
-
const bytes2 =
|
|
6289
|
+
const bytes2 = readFileSync5(canonical3);
|
|
6286
6290
|
const text2 = bytes2.toString("utf8").replace(/\r\n/g, "\n");
|
|
6287
6291
|
const fileHash = hash3(bytes2);
|
|
6288
6292
|
const entries = [...text2.matchAll(/<!-- entry:([^\s<>]+) -->([\s\S]*?)<!-- \/entry:\1 -->/g)];
|
|
@@ -6352,7 +6356,7 @@ function recoverLegacyProjections(db, store, input, apply = false) {
|
|
|
6352
6356
|
if (!apply || !candidates.length) return report;
|
|
6353
6357
|
for (const file of new Set(candidates.map((candidate) => candidate.file))) {
|
|
6354
6358
|
const candidate = candidates.find((candidate2) => candidate2.file === file);
|
|
6355
|
-
if (hash3(
|
|
6359
|
+
if (hash3(readFileSync5(file)) !== candidate.fileHash) throw new Error("LEGACY_PROJECTION_CHANGED_DURING_RECOVERY");
|
|
6356
6360
|
if (realpathSync3(store.mem7RootPath()) !== root) throw new Error("LEGACY_PROJECTION_COPY_REQUIRED");
|
|
6357
6361
|
}
|
|
6358
6362
|
store.transaction(() => {
|
|
@@ -7778,7 +7782,7 @@ var init_job_runner = __esm({
|
|
|
7778
7782
|
});
|
|
7779
7783
|
|
|
7780
7784
|
// src/mem7/core/episode.ts
|
|
7781
|
-
import { readFileSync as
|
|
7785
|
+
import { readFileSync as readFileSync6 } from "node:fs";
|
|
7782
7786
|
import { join as join7, dirname as dirname4 } from "node:path";
|
|
7783
7787
|
import { fileURLToPath } from "node:url";
|
|
7784
7788
|
function renderConversation(cell) {
|
|
@@ -7864,7 +7868,7 @@ var init_episode = __esm({
|
|
|
7864
7868
|
init_prompt_render();
|
|
7865
7869
|
init_job_runner();
|
|
7866
7870
|
RETRIES = 2;
|
|
7867
|
-
PROMPT =
|
|
7871
|
+
PROMPT = readFileSync6(join7(dirname4(fileURLToPath(import.meta.url)), "prompts", "episode.md"), "utf8");
|
|
7868
7872
|
}
|
|
7869
7873
|
});
|
|
7870
7874
|
|
|
@@ -8718,7 +8722,7 @@ var init_types = __esm({
|
|
|
8718
8722
|
|
|
8719
8723
|
// src/memory/topics-cleaning/materials.ts
|
|
8720
8724
|
import { createHash as createHash15, randomUUID as randomUUID5 } from "node:crypto";
|
|
8721
|
-
import { existsSync as existsSync4, lstatSync as lstatSync6, mkdirSync as mkdirSync6, readFileSync as
|
|
8725
|
+
import { existsSync as existsSync4, lstatSync as lstatSync6, mkdirSync as mkdirSync6, readFileSync as readFileSync7, renameSync as renameSync3, writeFileSync as writeFileSync4 } from "node:fs";
|
|
8722
8726
|
import { basename as basename2, dirname as dirname5, isAbsolute as isAbsolute2, join as join8, relative as relative2, resolve as resolve4, sep as sep2 } from "node:path";
|
|
8723
8727
|
function canonical(value) {
|
|
8724
8728
|
if (Array.isArray(value)) return `[${value.map(canonical).join(",")}]`;
|
|
@@ -8755,11 +8759,11 @@ function disjoint(...paths) {
|
|
|
8755
8759
|
if (contains(p[i], p[j]) || contains(p[j], p[i])) throw new Error("PATH_OVERLAP");
|
|
8756
8760
|
}
|
|
8757
8761
|
function readJson(path10) {
|
|
8758
|
-
return JSON.parse(
|
|
8762
|
+
return JSON.parse(readFileSync7(unlinked(path10), "utf8").replace(/^\uFEFF/, ""));
|
|
8759
8763
|
}
|
|
8760
8764
|
function rawBytes(snapshot, record) {
|
|
8761
8765
|
if (!/^[a-f0-9]{64}$/.test(record.sha256)) throw new Error("INVALID_OBJECT_REFERENCE");
|
|
8762
|
-
const bytes2 =
|
|
8766
|
+
const bytes2 = readFileSync7(unlinked(join8(snapshot.bundle, "objects", record.sha256)));
|
|
8763
8767
|
if (bytes2.length !== record.bytes || digest3(bytes2) !== record.sha256) throw new Error("OBJECT_HASH_MISMATCH");
|
|
8764
8768
|
return bytes2;
|
|
8765
8769
|
}
|
|
@@ -8902,7 +8906,7 @@ function verifyCleaned(bundle, output) {
|
|
|
8902
8906
|
if (canonical(expected) !== canonical(manifest.items)) throw new Error("CLEANED_SELECTION_MISMATCH");
|
|
8903
8907
|
let fragments = 0;
|
|
8904
8908
|
for (const item of manifest.items) for (const f of item.fragments) {
|
|
8905
|
-
const bytes2 =
|
|
8909
|
+
const bytes2 = readFileSync7(unlinked(join8(output, f.file)));
|
|
8906
8910
|
if (digest3(bytes2) !== f.digest || !bytes2.equals(Buffer.from(materials.get(item.originalHash).text.slice(f.start, f.end)))) throw new Error("CLEANED_FRAGMENT_MISMATCH");
|
|
8907
8911
|
fragments++;
|
|
8908
8912
|
}
|
|
@@ -9138,7 +9142,7 @@ var init_historical_recall = __esm({
|
|
|
9138
9142
|
|
|
9139
9143
|
// src/memory/topics-history/cutoff.ts
|
|
9140
9144
|
import { DatabaseSync as DatabaseSync4 } from "node:sqlite";
|
|
9141
|
-
import { existsSync as existsSync5, readFileSync as
|
|
9145
|
+
import { existsSync as existsSync5, readFileSync as readFileSync8, readdirSync } from "node:fs";
|
|
9142
9146
|
import { join as join9 } from "node:path";
|
|
9143
9147
|
function mem7StartDate(b) {
|
|
9144
9148
|
if (!b.stateDir) return null;
|
|
@@ -9169,7 +9173,7 @@ function mem7StartDate(b) {
|
|
|
9169
9173
|
const files = existsSync5(dir) ? readdirSync(dir).filter((name) => /^episode-\d{4}-\d{2}-\d{2}\.md$/.test(name)).sort() : [];
|
|
9170
9174
|
for (const name of files) {
|
|
9171
9175
|
let found = false;
|
|
9172
|
-
const text2 =
|
|
9176
|
+
const text2 = readFileSync8(unlinked(join9(dir, name)), "utf8");
|
|
9173
9177
|
for (const entry of text2.matchAll(/<!-- entry:([^\s<>]+) -->([\s\S]*?)<!-- \/entry:\1 -->/g)) {
|
|
9174
9178
|
const owner = /^\*\*owner_id\*\*:\s*(\S+)/m.exec(entry[2])?.[1];
|
|
9175
9179
|
if (owner !== b.userId) continue;
|
|
@@ -9229,7 +9233,7 @@ var init_cutoff = __esm({
|
|
|
9229
9233
|
});
|
|
9230
9234
|
|
|
9231
9235
|
// src/continuity/runtime-replication.ts
|
|
9232
|
-
import { constants as constants5, lstatSync as lstatSync7, realpathSync as realpathSync4, mkdirSync as mkdirSync7, openSync as openSync6, closeSync as closeSync6, fstatSync as fstatSync4, readFileSync as
|
|
9236
|
+
import { constants as constants5, lstatSync as lstatSync7, realpathSync as realpathSync4, mkdirSync as mkdirSync7, openSync as openSync6, closeSync as closeSync6, fstatSync as fstatSync4, readFileSync as readFileSync9, writeFileSync as writeFileSync5, fsyncSync as fsyncSync5 } from "node:fs";
|
|
9233
9237
|
import { basename as basename3, dirname as dirname6, join as join10, resolve as resolve5 } from "node:path";
|
|
9234
9238
|
function isReplicationFailure(error) {
|
|
9235
9239
|
return error instanceof Error && /^(?:REPLICATION_|TRAVEL_|CHECKPOINT_BUSY)/.test(error.message);
|
|
@@ -9288,7 +9292,7 @@ function readRuntimeReplicationRegistration(stateDir2, component, key4) {
|
|
|
9288
9292
|
try {
|
|
9289
9293
|
const info = fstatSync4(fd);
|
|
9290
9294
|
if (!info.isFile() || info.size > 4096 || realpathSync4(file) !== resolve5(file) || process.platform !== "win32" && (info.mode & 63 || info.uid !== process.getuid())) throw new Error();
|
|
9291
|
-
return normalize3(JSON.parse(
|
|
9295
|
+
return normalize3(JSON.parse(readFileSync9(fd, "utf8")));
|
|
9292
9296
|
} catch (error) {
|
|
9293
9297
|
throw new Error("REPLICATION_REGISTRATION_INVALID", { cause: error });
|
|
9294
9298
|
} finally {
|
|
@@ -9344,7 +9348,7 @@ function enrollRuntimeReplication(db, stateDir2, component, binding, key4) {
|
|
|
9344
9348
|
mkdirSync7(dirname6(file), { mode: 448, recursive: true });
|
|
9345
9349
|
directory(dirname6(file));
|
|
9346
9350
|
try {
|
|
9347
|
-
|
|
9351
|
+
writeFileSync5(file, JSON.stringify(input), { mode: 384, flag: "wx", flush: true });
|
|
9348
9352
|
} catch (error) {
|
|
9349
9353
|
if (error.code !== "EEXIST") throw error;
|
|
9350
9354
|
if (JSON.stringify(readRuntimeReplicationRegistration(stateDir2, component, key4)) !== JSON.stringify(input)) throw new Error("REPLICATION_REGISTRATION_MISMATCH");
|
|
@@ -9935,7 +9939,7 @@ __export(topics_history_exports, {
|
|
|
9935
9939
|
topicsScope: () => topicsScope
|
|
9936
9940
|
});
|
|
9937
9941
|
import { DatabaseSync as DatabaseSync7 } from "node:sqlite";
|
|
9938
|
-
import { existsSync as existsSync6, mkdirSync as mkdirSync8, readFileSync as
|
|
9942
|
+
import { existsSync as existsSync6, mkdirSync as mkdirSync8, readFileSync as readFileSync10, renameSync as renameSync4, writeFileSync as writeFileSync6, promises as fs2 } from "node:fs";
|
|
9939
9943
|
import { join as join13, resolve as resolve7 } from "node:path";
|
|
9940
9944
|
import { randomUUID as randomUUID6 } from "node:crypto";
|
|
9941
9945
|
function topicQueryYear(query, options = {}) {
|
|
@@ -10064,7 +10068,7 @@ ${body}` };
|
|
|
10064
10068
|
function readSource(b, ref) {
|
|
10065
10069
|
validateRef(b, ref);
|
|
10066
10070
|
if (forgotten(b, ref.sourcePath)) throw new Error("HISTORY_REFERENCE_UNAVAILABLE");
|
|
10067
|
-
const bytes2 =
|
|
10071
|
+
const bytes2 = readFileSync10(unlinked(join13(resolve7(b.topicsDir), ref.sourcePath)));
|
|
10068
10072
|
if (digest3(bytes2) !== ref.originalHash) throw new Error("HISTORY_REFERENCE_UNAVAILABLE");
|
|
10069
10073
|
const text2 = new TextDecoder("utf-8", { fatal: true, ignoreBOM: true }).decode(bytes2);
|
|
10070
10074
|
if (ref.end > text2.length) throw new Error("INVALID_HISTORY_REFERENCE");
|
|
@@ -10113,7 +10117,7 @@ function forgetTopicHistory(b, ref) {
|
|
|
10113
10117
|
getTopicHistory(b, ref);
|
|
10114
10118
|
const dir = join13(topicsHistoryRoot(b), "forgotten");
|
|
10115
10119
|
mkdirSync8(unlinked(dir), { recursive: true });
|
|
10116
|
-
|
|
10120
|
+
writeFileSync6(unlinked(join13(dir, `${digest3(ref.sourcePath)}.json`)), JSON.stringify({ sourcePath: ref.sourcePath, originalHash: ref.originalHash, forgottenAt: (/* @__PURE__ */ new Date()).toISOString() }));
|
|
10117
10121
|
}
|
|
10118
10122
|
function safeParagraphs(text2) {
|
|
10119
10123
|
const out = [];
|
|
@@ -10129,7 +10133,7 @@ function safeParagraphs(text2) {
|
|
|
10129
10133
|
}
|
|
10130
10134
|
function fallbackTopicHits(b, sourcePath) {
|
|
10131
10135
|
if (!safeRelative(sourcePath) || forgotten(b, sourcePath)) return [];
|
|
10132
|
-
const bytes2 =
|
|
10136
|
+
const bytes2 = readFileSync10(unlinked(join13(resolve7(b.topicsDir), sourcePath))), text2 = new TextDecoder("utf-8", { fatal: true, ignoreBOM: true }).decode(bytes2);
|
|
10133
10137
|
const out = [];
|
|
10134
10138
|
const before = mem7StartDate(b);
|
|
10135
10139
|
for (const paragraph of safeParagraphs(text2)) {
|
|
@@ -10214,12 +10218,12 @@ ${aliases.join(" ")}`);
|
|
|
10214
10218
|
db.exec("COMMIT");
|
|
10215
10219
|
if (db.prepare("PRAGMA integrity_check").get().integrity_check !== "ok") throw new Error("HISTORY_INDEX_INVALID");
|
|
10216
10220
|
const count = db.prepare("SELECT count(*) AS n FROM entries").get().n;
|
|
10217
|
-
|
|
10221
|
+
writeFileSync6(join13(dir, "manifest.json"), JSON.stringify(seal({ version, snapshotDigest: snapshot.manifest.digest, cleaningDigest: manifest.digest, entries: count, createdAt: Date.now() })));
|
|
10218
10222
|
} finally {
|
|
10219
10223
|
db.close();
|
|
10220
10224
|
}
|
|
10221
10225
|
const pointer = join13(root, `.current-${version}.json`);
|
|
10222
|
-
|
|
10226
|
+
writeFileSync6(pointer, JSON.stringify({ version }));
|
|
10223
10227
|
renameSync4(pointer, join13(root, "current.json"));
|
|
10224
10228
|
return version;
|
|
10225
10229
|
}
|
|
@@ -13028,7 +13032,7 @@ __export(store_exports, {
|
|
|
13028
13032
|
mem7Root: () => mem7Root
|
|
13029
13033
|
});
|
|
13030
13034
|
import { DatabaseSync as DatabaseSync8 } from "node:sqlite";
|
|
13031
|
-
import { mkdirSync as mkdirSync9, readFileSync as
|
|
13035
|
+
import { mkdirSync as mkdirSync9, readFileSync as readFileSync11, writeFileSync as writeFileSync7, renameSync as renameSync5, existsSync as existsSync7, readdirSync as readdirSync3, lstatSync as lstatSync8, unlinkSync as unlinkSync3 } from "node:fs";
|
|
13032
13036
|
import { join as join14, relative as relative3 } from "node:path";
|
|
13033
13037
|
import { createHash as createHash20, randomUUID as randomUUID9 } from "node:crypto";
|
|
13034
13038
|
function contentHash(text2) {
|
|
@@ -13521,7 +13525,7 @@ CREATE TABLE IF NOT EXISTS cluster_members (
|
|
|
13521
13525
|
let existingBlocks = "";
|
|
13522
13526
|
let count;
|
|
13523
13527
|
if (existsSync7(file)) {
|
|
13524
|
-
const text2 =
|
|
13528
|
+
const text2 = readFileSync11(file, "utf8");
|
|
13525
13529
|
const fmEnd = text2.indexOf("\n---", 3);
|
|
13526
13530
|
const split = fmEnd >= 0 ? fmEnd + 4 : text2.length;
|
|
13527
13531
|
head = text2.slice(0, split);
|
|
@@ -13578,7 +13582,7 @@ CREATE TABLE IF NOT EXISTS cluster_members (
|
|
|
13578
13582
|
let existingBlocks = "";
|
|
13579
13583
|
let count;
|
|
13580
13584
|
if (existsSync7(file)) {
|
|
13581
|
-
const text2 =
|
|
13585
|
+
const text2 = readFileSync11(file, "utf8");
|
|
13582
13586
|
const fmEnd = text2.indexOf("\n---", 3);
|
|
13583
13587
|
const split = fmEnd >= 0 ? fmEnd + 4 : text2.length;
|
|
13584
13588
|
head = text2.slice(0, split);
|
|
@@ -13626,11 +13630,11 @@ CREATE TABLE IF NOT EXISTS cluster_members (
|
|
|
13626
13630
|
assertRuntimeAuthority(this.stateDir, "WRITE");
|
|
13627
13631
|
const temporary = `${file}.${randomUUID9()}.tmp`;
|
|
13628
13632
|
try {
|
|
13629
|
-
|
|
13633
|
+
writeFileSync7(temporary, content, "utf8");
|
|
13630
13634
|
assertRuntimeAuthority(this.stateDir, "WRITE");
|
|
13631
13635
|
renameSync5(temporary, file);
|
|
13632
13636
|
} finally {
|
|
13633
|
-
if (existsSync7(temporary))
|
|
13637
|
+
if (existsSync7(temporary)) unlinkSync3(temporary);
|
|
13634
13638
|
}
|
|
13635
13639
|
}
|
|
13636
13640
|
recordProjection(scope, kind, id, file, content, body, expectedVersion) {
|
|
@@ -13673,7 +13677,7 @@ CREATE TABLE IF NOT EXISTS cluster_members (
|
|
|
13673
13677
|
let max = 0;
|
|
13674
13678
|
if (existsSync7(file)) {
|
|
13675
13679
|
const re = new RegExp(`${prefix}_${dateStr.replace(/-/g, "")}_(\\d+)`, "g");
|
|
13676
|
-
for (const m of
|
|
13680
|
+
for (const m of readFileSync11(file, "utf8").matchAll(re)) max = Math.max(max, Number(m[1]));
|
|
13677
13681
|
}
|
|
13678
13682
|
return max;
|
|
13679
13683
|
}
|
|
@@ -13896,7 +13900,7 @@ ${e.outcome}
|
|
|
13896
13900
|
for (const f of files) {
|
|
13897
13901
|
let text2;
|
|
13898
13902
|
try {
|
|
13899
|
-
text2 =
|
|
13903
|
+
text2 = readFileSync11(join14(dir, f), "utf8");
|
|
13900
13904
|
} catch {
|
|
13901
13905
|
continue;
|
|
13902
13906
|
}
|
|
@@ -13930,7 +13934,7 @@ ${e.outcome}
|
|
|
13930
13934
|
for (const d of dirs) {
|
|
13931
13935
|
let text2;
|
|
13932
13936
|
try {
|
|
13933
|
-
text2 =
|
|
13937
|
+
text2 = readFileSync11(join14(base, d, "SKILL.md"), "utf8");
|
|
13934
13938
|
} catch {
|
|
13935
13939
|
continue;
|
|
13936
13940
|
}
|
|
@@ -13995,7 +13999,7 @@ ${e.outcome}
|
|
|
13995
13999
|
let text2;
|
|
13996
14000
|
const file = join14(this.root, this.ownerProjectionPath("users", ownerId, scope), "user.md");
|
|
13997
14001
|
try {
|
|
13998
|
-
text2 =
|
|
14002
|
+
text2 = readFileSync11(file, "utf8");
|
|
13999
14003
|
} catch {
|
|
14000
14004
|
return null;
|
|
14001
14005
|
}
|
|
@@ -14567,7 +14571,7 @@ ${e.outcome}
|
|
|
14567
14571
|
if (!/^foresight-\d{4}-\d{2}-\d{2}\.md$/.test(f)) continue;
|
|
14568
14572
|
let content;
|
|
14569
14573
|
try {
|
|
14570
|
-
content =
|
|
14574
|
+
content = readFileSync11(join14(dir, f), "utf8");
|
|
14571
14575
|
} catch {
|
|
14572
14576
|
continue;
|
|
14573
14577
|
}
|
|
@@ -14605,7 +14609,7 @@ ${e.outcome}
|
|
|
14605
14609
|
// src/mem7/boot-recovery.ts
|
|
14606
14610
|
import { DatabaseSync as DatabaseSync9 } from "node:sqlite";
|
|
14607
14611
|
import { copyFileSync, existsSync as existsSync8, mkdirSync as mkdirSync10, readdirSync as readdirSync4, renameSync as renameSync6, rmSync, statSync as statSync2 } from "node:fs";
|
|
14608
|
-
import { readFileSync as
|
|
14612
|
+
import { readFileSync as readFileSync12, unlinkSync as unlinkSync4, writeFileSync as writeFileSync8 } from "node:fs";
|
|
14609
14613
|
import { join as join15 } from "node:path";
|
|
14610
14614
|
import { randomUUID as randomUUID10 } from "node:crypto";
|
|
14611
14615
|
function alive(pid) {
|
|
@@ -14619,30 +14623,30 @@ function alive(pid) {
|
|
|
14619
14623
|
function claimBootRecovery(index) {
|
|
14620
14624
|
const sentinel = join15(index, ".mem7-boot-recovery"), body = JSON.stringify({ pid: process.pid, startedAt: Date.now() });
|
|
14621
14625
|
try {
|
|
14622
|
-
|
|
14626
|
+
writeFileSync8(sentinel, body, { flag: "wx" });
|
|
14623
14627
|
return;
|
|
14624
14628
|
} catch (error) {
|
|
14625
14629
|
if (error.code !== "EEXIST") throw error;
|
|
14626
14630
|
}
|
|
14627
14631
|
let holder;
|
|
14628
14632
|
try {
|
|
14629
|
-
holder = JSON.parse(
|
|
14633
|
+
holder = JSON.parse(readFileSync12(sentinel, "utf8"));
|
|
14630
14634
|
} catch {
|
|
14631
14635
|
holder = {};
|
|
14632
14636
|
}
|
|
14633
14637
|
const fresh = Number.isFinite(Number(holder.startedAt)) && Date.now() - Number(holder.startedAt) < 3e5 && (!Number.isSafeInteger(Number(holder.pid)) || Number(holder.pid) <= 0 || alive(Number(holder.pid)));
|
|
14634
14638
|
if (fresh) throw new Error("MEM7_RECOVERY_IN_PROGRESS");
|
|
14635
14639
|
try {
|
|
14636
|
-
|
|
14640
|
+
unlinkSync4(sentinel);
|
|
14637
14641
|
} catch (error) {
|
|
14638
14642
|
if (error.code !== "ENOENT") throw error;
|
|
14639
14643
|
}
|
|
14640
|
-
|
|
14644
|
+
writeFileSync8(sentinel, body, { flag: "wx" });
|
|
14641
14645
|
}
|
|
14642
14646
|
function releaseBootRecovery(index) {
|
|
14643
14647
|
const sentinel = join15(index, ".mem7-boot-recovery");
|
|
14644
14648
|
try {
|
|
14645
|
-
if (JSON.parse(
|
|
14649
|
+
if (JSON.parse(readFileSync12(sentinel, "utf8")).pid === process.pid) unlinkSync4(sentinel);
|
|
14646
14650
|
} catch {
|
|
14647
14651
|
}
|
|
14648
14652
|
}
|
|
@@ -14669,7 +14673,7 @@ function healthyDatabase(path10) {
|
|
|
14669
14673
|
function backupCandidates(stateDir2) {
|
|
14670
14674
|
const root = mem7Root(stateDir2), roots = /* @__PURE__ */ new Set([root]);
|
|
14671
14675
|
try {
|
|
14672
|
-
const registry2 = JSON.parse(
|
|
14676
|
+
const registry2 = JSON.parse(readFileSync12(join15(root, ".topics-backup-roots.json"), "utf8"));
|
|
14673
14677
|
if (Array.isArray(registry2?.roots)) {
|
|
14674
14678
|
for (const entry of registry2.roots)
|
|
14675
14679
|
if (typeof entry === "string" && entry.startsWith("/")) roots.add(entry);
|
|
@@ -14903,7 +14907,7 @@ var init_ids = __esm({
|
|
|
14903
14907
|
});
|
|
14904
14908
|
|
|
14905
14909
|
// src/mem7/core/boundary.ts
|
|
14906
|
-
import { readFileSync as
|
|
14910
|
+
import { readFileSync as readFileSync13 } from "node:fs";
|
|
14907
14911
|
import { join as join16, dirname as dirname7 } from "node:path";
|
|
14908
14912
|
import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
14909
14913
|
function renderBoundaryInput(messages) {
|
|
@@ -15018,12 +15022,12 @@ var init_boundary = __esm({
|
|
|
15018
15022
|
HARD_TOKEN_LIMIT = 8192;
|
|
15019
15023
|
HARD_MSG_LIMIT = 50;
|
|
15020
15024
|
RETRIES2 = 3;
|
|
15021
|
-
PROMPT2 =
|
|
15025
|
+
PROMPT2 = readFileSync13(join16(dirname7(fileURLToPath2(import.meta.url)), "prompts", "boundary.md"), "utf8");
|
|
15022
15026
|
}
|
|
15023
15027
|
});
|
|
15024
15028
|
|
|
15025
15029
|
// src/mem7/core/atomic-facts.ts
|
|
15026
|
-
import { readFileSync as
|
|
15030
|
+
import { readFileSync as readFileSync14 } from "node:fs";
|
|
15027
15031
|
import { join as join17, dirname as dirname8 } from "node:path";
|
|
15028
15032
|
import { fileURLToPath as fileURLToPath3 } from "node:url";
|
|
15029
15033
|
async function extractAtomicFacts(cell, provider, model, strict = false) {
|
|
@@ -15066,18 +15070,18 @@ var init_atomic_facts = __esm({
|
|
|
15066
15070
|
init_episode();
|
|
15067
15071
|
init_prompt_render();
|
|
15068
15072
|
RETRIES3 = 5;
|
|
15069
|
-
PROMPT3 =
|
|
15073
|
+
PROMPT3 = readFileSync14(join17(dirname8(fileURLToPath3(import.meta.url)), "prompts", "atomic-facts-memcell.md"), "utf8");
|
|
15070
15074
|
}
|
|
15071
15075
|
});
|
|
15072
15076
|
|
|
15073
15077
|
// src/mem7/core/status-doc.ts
|
|
15074
|
-
import { existsSync as existsSync9, readFileSync as
|
|
15078
|
+
import { existsSync as existsSync9, readFileSync as readFileSync15, writeFileSync as writeFileSync9, mkdirSync as mkdirSync11, renameSync as renameSync7 } from "node:fs";
|
|
15075
15079
|
import { join as join18, dirname as dirname9 } from "node:path";
|
|
15076
15080
|
function readStatusDoc(root, sid) {
|
|
15077
15081
|
const path10 = docPath(root, sid);
|
|
15078
15082
|
if (!existsSync9(path10)) return null;
|
|
15079
15083
|
try {
|
|
15080
|
-
const parsed = JSON.parse(
|
|
15084
|
+
const parsed = JSON.parse(readFileSync15(path10, "utf-8"));
|
|
15081
15085
|
if (!parsed || parsed.doc !== null && !validDoc(parsed.doc) || parsed.sourceSeq !== null && (!Number.isSafeInteger(parsed.sourceSeq) || parsed.sourceSeq < 0) || typeof parsed.updatedAt !== "string" || !Number.isFinite(Date.parse(parsed.updatedAt)) || parsed.failedAt !== void 0 && !Number.isFinite(Date.parse(parsed.failedAt))) return null;
|
|
15082
15086
|
return parsed;
|
|
15083
15087
|
} catch {
|
|
@@ -15158,7 +15162,7 @@ function writeDoc(root, sid, file) {
|
|
|
15158
15162
|
const path10 = docPath(root, sid);
|
|
15159
15163
|
mkdirSync11(dirname9(path10), { recursive: true });
|
|
15160
15164
|
const tmp = path10 + ".tmp";
|
|
15161
|
-
|
|
15165
|
+
writeFileSync9(tmp, JSON.stringify(file), "utf-8");
|
|
15162
15166
|
renameSync7(tmp, path10);
|
|
15163
15167
|
}
|
|
15164
15168
|
var MERGE_MIN_INTERVAL_SEQ, MERGE_FAIL_COOLDOWN_MS, dirPath, docPath, MERGE_SYSTEM;
|
|
@@ -15184,7 +15188,7 @@ Keep the original language of the facts, attribute properly, never invent facts
|
|
|
15184
15188
|
});
|
|
15185
15189
|
|
|
15186
15190
|
// src/mem7/core/foresight.ts
|
|
15187
|
-
import { readFileSync as
|
|
15191
|
+
import { readFileSync as readFileSync16 } from "node:fs";
|
|
15188
15192
|
import { join as join19, dirname as dirname10 } from "node:path";
|
|
15189
15193
|
import { fileURLToPath as fileURLToPath4 } from "node:url";
|
|
15190
15194
|
function cleanDateString(dateStr) {
|
|
@@ -15278,12 +15282,12 @@ var init_foresight = __esm({
|
|
|
15278
15282
|
MAX_COUNT = 10;
|
|
15279
15283
|
MIN_COUNT = 4;
|
|
15280
15284
|
TEMPERATURE = 0.3;
|
|
15281
|
-
PROMPT4 =
|
|
15285
|
+
PROMPT4 = readFileSync16(join19(dirname10(fileURLToPath4(import.meta.url)), "prompts", "foresight.md"), "utf8");
|
|
15282
15286
|
}
|
|
15283
15287
|
});
|
|
15284
15288
|
|
|
15285
15289
|
// src/mem7/core/case.ts
|
|
15286
|
-
import { readFileSync as
|
|
15290
|
+
import { readFileSync as readFileSync17 } from "node:fs";
|
|
15287
15291
|
import { join as join20, dirname as dirname11 } from "node:path";
|
|
15288
15292
|
import { fileURLToPath as fileURLToPath5 } from "node:url";
|
|
15289
15293
|
function estTokens2(text2) {
|
|
@@ -15350,8 +15354,8 @@ var init_case = __esm({
|
|
|
15350
15354
|
"src/mem7/core/case.ts"() {
|
|
15351
15355
|
"use strict";
|
|
15352
15356
|
init_prompt_render();
|
|
15353
|
-
PROMPT_FILTER =
|
|
15354
|
-
PROMPT_COMPRESS =
|
|
15357
|
+
PROMPT_FILTER = readFileSync17(join20(dirname11(fileURLToPath5(import.meta.url)), "prompts", "case-filter.md"), "utf8");
|
|
15358
|
+
PROMPT_COMPRESS = readFileSync17(join20(dirname11(fileURLToPath5(import.meta.url)), "prompts", "case-compress.md"), "utf8");
|
|
15355
15359
|
FILTER_NO_TOOL_MAX_MESSAGES = 4;
|
|
15356
15360
|
FILTER_NO_TOOL_MIN_ASSISTANT_TOKENS = 200;
|
|
15357
15361
|
MAX_TASK_INTENT_TOKENS = 300;
|
|
@@ -15360,7 +15364,7 @@ var init_case = __esm({
|
|
|
15360
15364
|
});
|
|
15361
15365
|
|
|
15362
15366
|
// src/mem7/core/skill.ts
|
|
15363
|
-
import { readFileSync as
|
|
15367
|
+
import { readFileSync as readFileSync18 } from "node:fs";
|
|
15364
15368
|
import { join as join21, dirname as dirname12 } from "node:path";
|
|
15365
15369
|
import { fileURLToPath as fileURLToPath6 } from "node:url";
|
|
15366
15370
|
async function callJson2(provider, model, prompt) {
|
|
@@ -15431,13 +15435,13 @@ var init_skill = __esm({
|
|
|
15431
15435
|
init_prompt_render();
|
|
15432
15436
|
SKILL_SKIP_QUALITY = 0.2;
|
|
15433
15437
|
SKILL_FAILURE_QUALITY = 0.5;
|
|
15434
|
-
PROMPT_SUCCESS =
|
|
15435
|
-
PROMPT_FAILURE =
|
|
15438
|
+
PROMPT_SUCCESS = readFileSync18(join21(dirname12(fileURLToPath6(import.meta.url)), "prompts", "skill-success.md"), "utf8");
|
|
15439
|
+
PROMPT_FAILURE = readFileSync18(join21(dirname12(fileURLToPath6(import.meta.url)), "prompts", "skill-failure.md"), "utf8");
|
|
15436
15440
|
}
|
|
15437
15441
|
});
|
|
15438
15442
|
|
|
15439
15443
|
// src/mem7/core/profile.ts
|
|
15440
|
-
import { readFileSync as
|
|
15444
|
+
import { readFileSync as readFileSync19 } from "node:fs";
|
|
15441
15445
|
import { join as join22, dirname as dirname13 } from "node:path";
|
|
15442
15446
|
import { fileURLToPath as fileURLToPath7 } from "node:url";
|
|
15443
15447
|
function repairLooseJson(raw) {
|
|
@@ -15589,14 +15593,14 @@ var init_profile = __esm({
|
|
|
15589
15593
|
init_prompt_render();
|
|
15590
15594
|
PROFILE_MAX_ITEMS = 30;
|
|
15591
15595
|
PROFILE_COMPACT_THRESHOLD = 45;
|
|
15592
|
-
P_INIT =
|
|
15593
|
-
P_UPDATE =
|
|
15594
|
-
P_COMPACT =
|
|
15596
|
+
P_INIT = readFileSync19(join22(dirname13(fileURLToPath7(import.meta.url)), "prompts", "profile.md"), "utf8");
|
|
15597
|
+
P_UPDATE = readFileSync19(join22(dirname13(fileURLToPath7(import.meta.url)), "prompts", "profile-update.md"), "utf8");
|
|
15598
|
+
P_COMPACT = readFileSync19(join22(dirname13(fileURLToPath7(import.meta.url)), "prompts", "profile-compact.md"), "utf8");
|
|
15595
15599
|
}
|
|
15596
15600
|
});
|
|
15597
15601
|
|
|
15598
15602
|
// src/mem7/core/cluster.ts
|
|
15599
|
-
import { readFileSync as
|
|
15603
|
+
import { readFileSync as readFileSync20 } from "node:fs";
|
|
15600
15604
|
import { join as join23, dirname as dirname14 } from "node:path";
|
|
15601
15605
|
import { fileURLToPath as fileURLToPath8 } from "node:url";
|
|
15602
15606
|
function cosine(a, b) {
|
|
@@ -15674,7 +15678,7 @@ var init_cluster = __esm({
|
|
|
15674
15678
|
GEOMETRY_WINDOW_DAYS = 7;
|
|
15675
15679
|
LLM_SKIP_THRESHOLD = 0.85;
|
|
15676
15680
|
LLM_K_CANDIDATES = 30;
|
|
15677
|
-
CLUSTER_PROMPT =
|
|
15681
|
+
CLUSTER_PROMPT = readFileSync20(join23(dirname14(fileURLToPath8(import.meta.url)), "prompts", "cluster-assign.md"), "utf8");
|
|
15678
15682
|
}
|
|
15679
15683
|
});
|
|
15680
15684
|
|
|
@@ -16129,7 +16133,7 @@ var init_context = __esm({
|
|
|
16129
16133
|
|
|
16130
16134
|
// src/mem7/core/artifact-file-inputs.ts
|
|
16131
16135
|
import { createHash as createHash22 } from "node:crypto";
|
|
16132
|
-
import { readdirSync as readdirSync5, readFileSync as
|
|
16136
|
+
import { readdirSync as readdirSync5, readFileSync as readFileSync21 } from "node:fs";
|
|
16133
16137
|
import { join as join24, relative as relative4 } from "node:path";
|
|
16134
16138
|
function snapshotArtifactFileInput(store, request, entries) {
|
|
16135
16139
|
return {
|
|
@@ -16161,7 +16165,7 @@ function snapshotFiles(store, request) {
|
|
|
16161
16165
|
return files.map((file) => {
|
|
16162
16166
|
let digest6 = null;
|
|
16163
16167
|
try {
|
|
16164
|
-
digest6 = createHash22("sha256").update(
|
|
16168
|
+
digest6 = createHash22("sha256").update(readFileSync21(file)).digest("hex");
|
|
16165
16169
|
} catch {
|
|
16166
16170
|
}
|
|
16167
16171
|
return { path: relative4(root, file).replace(/\\/g, "/"), digest: digest6 };
|
|
@@ -16172,7 +16176,7 @@ function ownFilePublication(store, request, path10, version) {
|
|
|
16172
16176
|
const file = join24(store.mem7RootPath(), path10);
|
|
16173
16177
|
let text2;
|
|
16174
16178
|
try {
|
|
16175
|
-
text2 =
|
|
16179
|
+
text2 = readFileSync21(file, "utf8");
|
|
16176
16180
|
} catch {
|
|
16177
16181
|
return false;
|
|
16178
16182
|
}
|
|
@@ -21397,7 +21401,7 @@ var init_memory_reasoning = __esm({
|
|
|
21397
21401
|
});
|
|
21398
21402
|
|
|
21399
21403
|
// src/memory/proactive/prompts.ts
|
|
21400
|
-
import { readFileSync as
|
|
21404
|
+
import { readFileSync as readFileSync22 } from "node:fs";
|
|
21401
21405
|
import { join as join25 } from "node:path";
|
|
21402
21406
|
function buildSectionRegistry(D) {
|
|
21403
21407
|
const SECTION_CORE_ROLE = `You are a cognitive graph update agent for a proactive memory system that maintains a dynamic knowledge graph representing ${D.domain_description}.
|
|
@@ -22014,7 +22018,7 @@ function loadPersona(workspace) {
|
|
|
22014
22018
|
if (!workspace) return "";
|
|
22015
22019
|
const file = join25(workspace, "prompts", "proactive-persona.md");
|
|
22016
22020
|
try {
|
|
22017
|
-
const text2 =
|
|
22021
|
+
const text2 = readFileSync22(file, "utf8").trim();
|
|
22018
22022
|
if (text2) console.log(`[proactive] persona loaded from ${file} (${text2.length} chars)`);
|
|
22019
22023
|
return text2;
|
|
22020
22024
|
} catch {
|
|
@@ -22025,7 +22029,7 @@ function loadDomain(workspace) {
|
|
|
22025
22029
|
if (!workspace) return DEFAULT_DOMAIN;
|
|
22026
22030
|
const file = join25(workspace, "prompts", "proactive-domain.json");
|
|
22027
22031
|
try {
|
|
22028
|
-
const raw = JSON.parse(
|
|
22032
|
+
const raw = JSON.parse(readFileSync22(file, "utf8"));
|
|
22029
22033
|
if (raw && typeof raw === "object") {
|
|
22030
22034
|
const allowed = new Set(Object.keys(DEFAULT_DOMAIN));
|
|
22031
22035
|
const clean = {};
|
|
@@ -23580,7 +23584,7 @@ var init_intent = __esm({
|
|
|
23580
23584
|
});
|
|
23581
23585
|
|
|
23582
23586
|
// src/memory/proactive/sweep.ts
|
|
23583
|
-
import { readFileSync as
|
|
23587
|
+
import { readFileSync as readFileSync23 } from "node:fs";
|
|
23584
23588
|
function sharesTerm(a, b) {
|
|
23585
23589
|
const x = normalizeTitle(a);
|
|
23586
23590
|
const y = normalizeTitle(b);
|
|
@@ -23877,7 +23881,7 @@ ${JSON.stringify(payload)}
|
|
|
23877
23881
|
const file = this.deps.promptFile;
|
|
23878
23882
|
if (!file) return DEFAULT_PROMPT;
|
|
23879
23883
|
try {
|
|
23880
|
-
const text2 =
|
|
23884
|
+
const text2 = readFileSync23(file, "utf8").trim();
|
|
23881
23885
|
return text2 || DEFAULT_PROMPT;
|
|
23882
23886
|
} catch {
|
|
23883
23887
|
return DEFAULT_PROMPT;
|
|
@@ -23889,7 +23893,7 @@ ${JSON.stringify(payload)}
|
|
|
23889
23893
|
|
|
23890
23894
|
// src/memory/proactive/opportunity.ts
|
|
23891
23895
|
import { setImmediate as yieldToEventLoop2 } from "node:timers/promises";
|
|
23892
|
-
import { readdirSync as readdirSync6, readFileSync as
|
|
23896
|
+
import { readdirSync as readdirSync6, readFileSync as readFileSync24, existsSync as existsSync10, realpathSync as realpathSync5 } from "node:fs";
|
|
23893
23897
|
import { join as join28, relative as relative5 } from "node:path";
|
|
23894
23898
|
import { DatabaseSync as DatabaseSync12 } from "node:sqlite";
|
|
23895
23899
|
import { createHash as createHash31 } from "node:crypto";
|
|
@@ -24079,7 +24083,7 @@ function parseForesightEntries(everosRoot, now2, userId) {
|
|
|
24079
24083
|
let content;
|
|
24080
24084
|
let bytes2;
|
|
24081
24085
|
try {
|
|
24082
|
-
bytes2 =
|
|
24086
|
+
bytes2 = readFileSync24(file);
|
|
24083
24087
|
content = bytes2.toString("utf8");
|
|
24084
24088
|
} catch {
|
|
24085
24089
|
continue;
|
|
@@ -24087,7 +24091,7 @@ function parseForesightEntries(everosRoot, now2, userId) {
|
|
|
24087
24091
|
const fileDigest = createHash31("sha256").update(bytes2).digest("hex");
|
|
24088
24092
|
const assertCurrent = () => {
|
|
24089
24093
|
try {
|
|
24090
|
-
if (relative5(file, realpathSync5(file)) || createHash31("sha256").update(
|
|
24094
|
+
if (relative5(file, realpathSync5(file)) || createHash31("sha256").update(readFileSync24(file)).digest("hex") !== fileDigest) throw new MemoryReadSupersededError();
|
|
24091
24095
|
} catch {
|
|
24092
24096
|
throw new MemoryReadSupersededError();
|
|
24093
24097
|
}
|
|
@@ -27365,7 +27369,7 @@ var init_config3 = __esm({
|
|
|
27365
27369
|
});
|
|
27366
27370
|
|
|
27367
27371
|
// src/memory/proactive/planning-context.ts
|
|
27368
|
-
import { existsSync as existsSync12, readFileSync as
|
|
27372
|
+
import { existsSync as existsSync12, readFileSync as readFileSync26 } from "node:fs";
|
|
27369
27373
|
import { join as join31 } from "node:path";
|
|
27370
27374
|
import { DatabaseSync as DatabaseSync13 } from "node:sqlite";
|
|
27371
27375
|
function buildPlanningContext(calDb, workspace, memory) {
|
|
@@ -27383,7 +27387,7 @@ function buildPlanningContext(calDb, workspace, memory) {
|
|
|
27383
27387
|
}
|
|
27384
27388
|
}
|
|
27385
27389
|
try {
|
|
27386
|
-
const state =
|
|
27390
|
+
const state = readFileSync26(join31(workspace, "SESSION-STATE.md"), "utf8");
|
|
27387
27391
|
const active = state.match(/##\s*(?:🎯\s*)?(?:in_progress|当前任务|进行中)[^\n]*\n([\s\S]*?)(?=\n##\s|$)/i)?.[1]?.trim().slice(0, 4e3);
|
|
27388
27392
|
if (active) {
|
|
27389
27393
|
lines.push("\n[SESSION-STATE active work]", active);
|
|
@@ -27772,7 +27776,7 @@ var init_rerank = __esm({
|
|
|
27772
27776
|
});
|
|
27773
27777
|
|
|
27774
27778
|
// src/mem7/core/rank/arank.ts
|
|
27775
|
-
import { readFileSync as
|
|
27779
|
+
import { readFileSync as readFileSync27 } from "node:fs";
|
|
27776
27780
|
import { join as join32, dirname as dirname16 } from "node:path";
|
|
27777
27781
|
import { fileURLToPath as fileURLToPath10 } from "node:url";
|
|
27778
27782
|
async function arank(input, opts) {
|
|
@@ -27846,9 +27850,9 @@ var init_arank = __esm({
|
|
|
27846
27850
|
init_rerank();
|
|
27847
27851
|
init_read_guard();
|
|
27848
27852
|
PROMPT_DIR = join32(dirname16(fileURLToPath10(import.meta.url)), "prompts");
|
|
27849
|
-
EPISODIC_PROMPT =
|
|
27850
|
-
CASE_PROMPT =
|
|
27851
|
-
SKILL_PROMPT =
|
|
27853
|
+
EPISODIC_PROMPT = readFileSync27(join32(PROMPT_DIR, "episodic-rerank.md"), "utf8");
|
|
27854
|
+
CASE_PROMPT = readFileSync27(join32(PROMPT_DIR, "case-rerank.md"), "utf8");
|
|
27855
|
+
SKILL_PROMPT = readFileSync27(join32(PROMPT_DIR, "skill-rerank.md"), "utf8");
|
|
27852
27856
|
DEFAULT_RANK_CONFIG = { fusionMode: "rrf", rrfK: 60, vaSaturationK: 5, vaAlpha: 0.7 };
|
|
27853
27857
|
REGISTRY = {
|
|
27854
27858
|
case: { modes: ["rrf", "lr", "vector_anchored"], prompt: CASE_PROMPT, itemType: "case" },
|
|
@@ -28450,7 +28454,7 @@ var init_rerank_bridge = __esm({
|
|
|
28450
28454
|
});
|
|
28451
28455
|
|
|
28452
28456
|
// src/mem7/core/rank/agentic.ts
|
|
28453
|
-
import { readFileSync as
|
|
28457
|
+
import { readFileSync as readFileSync28 } from "node:fs";
|
|
28454
28458
|
import { join as join33, dirname as dirname17 } from "node:path";
|
|
28455
28459
|
import { fileURLToPath as fileURLToPath11 } from "node:url";
|
|
28456
28460
|
async function llmJson(provider, model, prompt, temperature, assertCurrent) {
|
|
@@ -28599,9 +28603,9 @@ var init_agentic = __esm({
|
|
|
28599
28603
|
init_read_guard();
|
|
28600
28604
|
init_fusion();
|
|
28601
28605
|
PROMPT_DIR2 = join33(dirname17(fileURLToPath11(import.meta.url)), "prompts");
|
|
28602
|
-
SUFFICIENCY_PROMPT =
|
|
28603
|
-
MULTI_QUERY_PROMPT =
|
|
28604
|
-
REFINED_QUERY_PROMPT =
|
|
28606
|
+
SUFFICIENCY_PROMPT = readFileSync28(join33(PROMPT_DIR2, "sufficiency.md"), "utf8");
|
|
28607
|
+
MULTI_QUERY_PROMPT = readFileSync28(join33(PROMPT_DIR2, "multi-query.md"), "utf8");
|
|
28608
|
+
REFINED_QUERY_PROMPT = readFileSync28(join33(PROMPT_DIR2, "refined-query.md"), "utf8");
|
|
28605
28609
|
}
|
|
28606
28610
|
});
|
|
28607
28611
|
|
|
@@ -32168,7 +32172,7 @@ ${String(input.tool_output ?? "")}`
|
|
|
32168
32172
|
// src/memory/topics-history/import-backups.ts
|
|
32169
32173
|
import { DatabaseSync as DatabaseSync15, backup as backupSqlite } from "node:sqlite";
|
|
32170
32174
|
import { randomUUID as randomUUID15 } from "node:crypto";
|
|
32171
|
-
import { existsSync as existsSync20, mkdirSync as mkdirSync19, readFileSync as
|
|
32175
|
+
import { existsSync as existsSync20, mkdirSync as mkdirSync19, readFileSync as readFileSync34, renameSync as renameSync10, unlinkSync as unlinkSync6, writeFileSync as writeFileSync13 } from "node:fs";
|
|
32172
32176
|
import { cp, readdir, rm } from "node:fs/promises";
|
|
32173
32177
|
import { basename as basename7, dirname as dirname22, join as join41, resolve as resolve14 } from "node:path";
|
|
32174
32178
|
import { fileURLToPath as fileURLToPath12 } from "node:url";
|
|
@@ -32176,10 +32180,10 @@ import { execFile } from "node:child_process";
|
|
|
32176
32180
|
function atomicJson(path10, value) {
|
|
32177
32181
|
const target = unlinked(path10), temp = unlinked(`${target}.${randomUUID15()}.tmp`);
|
|
32178
32182
|
try {
|
|
32179
|
-
|
|
32183
|
+
writeFileSync13(temp, JSON.stringify(seal(value)) + "\n", { flag: "wx" });
|
|
32180
32184
|
renameSync10(temp, target);
|
|
32181
32185
|
} finally {
|
|
32182
|
-
if (existsSync20(temp))
|
|
32186
|
+
if (existsSync20(temp)) unlinkSync6(temp);
|
|
32183
32187
|
}
|
|
32184
32188
|
}
|
|
32185
32189
|
function alive2(pid) {
|
|
@@ -32206,10 +32210,10 @@ async function withTopicsImportLock(historyRoot2, action) {
|
|
|
32206
32210
|
const path10 = unlinked(join41(root, ".topics-import.lock")), token = randomUUID15();
|
|
32207
32211
|
const body = JSON.stringify({ pid: process.pid, token });
|
|
32208
32212
|
try {
|
|
32209
|
-
|
|
32213
|
+
writeFileSync13(path10, body, { flag: "wx" });
|
|
32210
32214
|
} catch (error) {
|
|
32211
32215
|
if (error.code !== "EEXIST") throw error;
|
|
32212
|
-
const original =
|
|
32216
|
+
const original = readFileSync34(path10, "utf8");
|
|
32213
32217
|
let owner;
|
|
32214
32218
|
try {
|
|
32215
32219
|
owner = JSON.parse(original);
|
|
@@ -32217,14 +32221,14 @@ async function withTopicsImportLock(historyRoot2, action) {
|
|
|
32217
32221
|
throw new Error("TOPICS_IMPORT_BUSY: invalid lock");
|
|
32218
32222
|
}
|
|
32219
32223
|
if (alive2(owner.pid)) throw new Error("TOPICS_IMPORT_BUSY");
|
|
32220
|
-
if (
|
|
32221
|
-
|
|
32222
|
-
|
|
32224
|
+
if (readFileSync34(path10, "utf8") !== original) throw new Error("TOPICS_IMPORT_BUSY");
|
|
32225
|
+
unlinkSync6(path10);
|
|
32226
|
+
writeFileSync13(path10, body, { flag: "wx" });
|
|
32223
32227
|
}
|
|
32224
32228
|
try {
|
|
32225
32229
|
return await action();
|
|
32226
32230
|
} finally {
|
|
32227
|
-
if (existsSync20(path10) &&
|
|
32231
|
+
if (existsSync20(path10) && readFileSync34(path10, "utf8") === body) unlinkSync6(path10);
|
|
32228
32232
|
}
|
|
32229
32233
|
}
|
|
32230
32234
|
function registryPath(stateDir2) {
|
|
@@ -32273,7 +32277,7 @@ async function completeTopicsImportBackup(stateDir2, historyRoot2) {
|
|
|
32273
32277
|
const state = unlinked(stateDir2), history = unlinked(historyRoot2), current2 = pending(state, history);
|
|
32274
32278
|
if (!current2) return;
|
|
32275
32279
|
atomicJson(join41(current2.path, receiptName), { ...current2.receipt, status: "complete", completedAt: Date.now() });
|
|
32276
|
-
|
|
32280
|
+
unlinkSync6(unlinked(join41(history, pointerName)));
|
|
32277
32281
|
}
|
|
32278
32282
|
async function removeBackup(state, root, name) {
|
|
32279
32283
|
if (!receiptAt(state, root, name)) return false;
|
|
@@ -33063,7 +33067,7 @@ var init_reader = __esm({
|
|
|
33063
33067
|
|
|
33064
33068
|
// src/memory/topics-history/import-mem7.ts
|
|
33065
33069
|
import { DatabaseSync as DatabaseSync20 } from "node:sqlite";
|
|
33066
|
-
import { existsSync as existsSync23, writeFileSync as
|
|
33070
|
+
import { existsSync as existsSync23, writeFileSync as writeFileSync15 } from "node:fs";
|
|
33067
33071
|
import { join as join48 } from "node:path";
|
|
33068
33072
|
function topicsImported(binding) {
|
|
33069
33073
|
return !!binding.stateDir && existsSync23(join48(topicsHistoryRoot(binding), "topics-import.json"));
|
|
@@ -34197,7 +34201,7 @@ init_planning_context();
|
|
|
34197
34201
|
init_store();
|
|
34198
34202
|
init_intake();
|
|
34199
34203
|
init_pipeline();
|
|
34200
|
-
import { appendFileSync as appendFileSync3, existsSync as existsSync18, readFileSync as
|
|
34204
|
+
import { appendFileSync as appendFileSync3, existsSync as existsSync18, readFileSync as readFileSync31, readSync as readSync4, writeFileSync as writeFileSync11, writeSync as writeSync2, mkdirSync as mkdirSync16, renameSync as renameSync9, unlinkSync as unlinkSync5, openSync as openSync9, closeSync as closeSync9, fstatSync as fstatSync6, statSync as statSync4, statfsSync } from "node:fs";
|
|
34201
34205
|
import { createHash as createHash32 } from "node:crypto";
|
|
34202
34206
|
import { join as join39, dirname as dirname19 } from "node:path";
|
|
34203
34207
|
var spoolPath = (stateDir2) => join39(mem7Root(stateDir2), "spool", "intake.jsonl");
|
|
@@ -34258,7 +34262,7 @@ function intakeDiagnostic(stateDir2, event, details) {
|
|
|
34258
34262
|
try {
|
|
34259
34263
|
const lock = writeLockPath(stateDir2);
|
|
34260
34264
|
if (existsSync18(lock)) {
|
|
34261
|
-
const stat3 = statSync4(lock), pid = stat3.size <= 32 ? Number(
|
|
34265
|
+
const stat3 = statSync4(lock), pid = stat3.size <= 32 ? Number(readFileSync31(lock, "utf8").trim()) : NaN;
|
|
34262
34266
|
sizes.lock = {
|
|
34263
34267
|
bytes: stat3.size,
|
|
34264
34268
|
ageMs: Math.max(0, now2 - stat3.mtimeMs),
|
|
@@ -34300,7 +34304,7 @@ function lockOwnerState(path10) {
|
|
|
34300
34304
|
let pid;
|
|
34301
34305
|
try {
|
|
34302
34306
|
if (fileBytes(path10) > 32) return "alive";
|
|
34303
|
-
pid = Number(
|
|
34307
|
+
pid = Number(readFileSync31(path10, "utf8").trim());
|
|
34304
34308
|
} catch (error) {
|
|
34305
34309
|
if (error?.code === "ENOENT") return "missing";
|
|
34306
34310
|
throw error;
|
|
@@ -34331,7 +34335,7 @@ function withSpoolWriteLock(stateDir2, operation) {
|
|
|
34331
34335
|
throw Error("INTAKE_WRITER_BUSY: \u5199\u9501\u6062\u590D\u4E2D\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5");
|
|
34332
34336
|
}
|
|
34333
34337
|
try {
|
|
34334
|
-
if (lockOwnerState(path10) === "dead")
|
|
34338
|
+
if (lockOwnerState(path10) === "dead") unlinkSync5(path10);
|
|
34335
34339
|
try {
|
|
34336
34340
|
fd = openSync9(path10, "wx");
|
|
34337
34341
|
} catch (error2) {
|
|
@@ -34340,15 +34344,15 @@ function withSpoolWriteLock(stateDir2, operation) {
|
|
|
34340
34344
|
}
|
|
34341
34345
|
} finally {
|
|
34342
34346
|
closeSync9(reaper);
|
|
34343
|
-
|
|
34347
|
+
unlinkSync5(reaperPath);
|
|
34344
34348
|
}
|
|
34345
34349
|
}
|
|
34346
34350
|
try {
|
|
34347
|
-
|
|
34351
|
+
writeSync2(fd, String(process.pid));
|
|
34348
34352
|
return operation();
|
|
34349
34353
|
} finally {
|
|
34350
34354
|
closeSync9(fd);
|
|
34351
|
-
|
|
34355
|
+
unlinkSync5(path10);
|
|
34352
34356
|
}
|
|
34353
34357
|
}
|
|
34354
34358
|
function* spoolLines(fd, offset, maxEntries) {
|
|
@@ -34382,7 +34386,7 @@ function* spoolLines(fd, offset, maxEntries) {
|
|
|
34382
34386
|
function readCursor(stateDir2, path10, identity, size2) {
|
|
34383
34387
|
try {
|
|
34384
34388
|
if (fileBytes(path10) > 4096) throw Error("INTAKE_CURSOR_INVALID_SIZE");
|
|
34385
|
-
const cursor = JSON.parse(
|
|
34389
|
+
const cursor = JSON.parse(readFileSync31(path10, "utf8"));
|
|
34386
34390
|
if (cursor.dev === identity.dev && cursor.ino === identity.ino && cursor.birthtimeNs === identity.birthtimeNs && Number.isSafeInteger(cursor.offset) && cursor.offset >= 0 && cursor.offset <= size2) return cursor.offset;
|
|
34387
34391
|
intakeDiagnostic(stateDir2, "cursor.replay", { reason: cursor.dev !== identity.dev || cursor.ino !== identity.ino || cursor.birthtimeNs !== identity.birthtimeNs ? "identity_mismatch" : "invalid_offset", batchBytes: size2, identity });
|
|
34388
34392
|
} catch (error) {
|
|
@@ -34429,7 +34433,7 @@ function drainIntakeSpool(stateDir2, store, maxEntries = 50) {
|
|
|
34429
34433
|
if (!existsSync18(processing)) {
|
|
34430
34434
|
if (!existsSync18(path10) || statSync4(path10).size === 0) return;
|
|
34431
34435
|
try {
|
|
34432
|
-
|
|
34436
|
+
unlinkSync5(cursorPath);
|
|
34433
34437
|
} catch (error) {
|
|
34434
34438
|
if (error?.code !== "ENOENT") throw error;
|
|
34435
34439
|
}
|
|
@@ -34545,7 +34549,7 @@ function drainIntakeSpool(stateDir2, store, maxEntries = 50) {
|
|
|
34545
34549
|
diagnostic.stage = "cursor_lock";
|
|
34546
34550
|
withSpoolWriteLock(stateDir2, () => {
|
|
34547
34551
|
diagnostic.stage = "cursor_write";
|
|
34548
|
-
|
|
34552
|
+
writeFileSync11(next, JSON.stringify({ ...identity, offset }), "utf8");
|
|
34549
34553
|
diagnostic.stage = "cursor_rename";
|
|
34550
34554
|
renameSync9(next, cursorPath);
|
|
34551
34555
|
diagnostic.acknowledgedOffset = offset;
|
|
@@ -34553,8 +34557,8 @@ function drainIntakeSpool(stateDir2, store, maxEntries = 50) {
|
|
|
34553
34557
|
diagnostic.stage = "processing_delete";
|
|
34554
34558
|
closeSync9(fd);
|
|
34555
34559
|
fd = -1;
|
|
34556
|
-
|
|
34557
|
-
|
|
34560
|
+
unlinkSync5(processing);
|
|
34561
|
+
unlinkSync5(cursorPath);
|
|
34558
34562
|
}
|
|
34559
34563
|
});
|
|
34560
34564
|
}
|
|
@@ -34579,11 +34583,11 @@ init_config3();
|
|
|
34579
34583
|
init_loader();
|
|
34580
34584
|
init_embedding();
|
|
34581
34585
|
init_provider_factory();
|
|
34582
|
-
import { readFileSync as
|
|
34586
|
+
import { readFileSync as readFileSync33 } from "node:fs";
|
|
34583
34587
|
|
|
34584
34588
|
// src/config/secrets-env.ts
|
|
34585
34589
|
import { createHash as createHash33 } from "node:crypto";
|
|
34586
|
-
import { chmodSync, existsSync as existsSync19, mkdirSync as mkdirSync17, readFileSync as
|
|
34590
|
+
import { chmodSync, existsSync as existsSync19, mkdirSync as mkdirSync17, readFileSync as readFileSync32, writeFileSync as writeFileSync12 } from "node:fs";
|
|
34587
34591
|
import { basename as basename5, dirname as dirname20, join as join40, normalize as normalize5, resolve as resolve13 } from "node:path";
|
|
34588
34592
|
function secretsHome() {
|
|
34589
34593
|
return process.env.HOME || process.env.USERPROFILE || ".";
|
|
@@ -34614,7 +34618,7 @@ function readSecretsEntries(stateDir2, configName) {
|
|
|
34614
34618
|
for (const p of secretsCandidates(stateDir2, configName)) {
|
|
34615
34619
|
if (!existsSync19(p)) continue;
|
|
34616
34620
|
const entries = [];
|
|
34617
|
-
for (const line of
|
|
34621
|
+
for (const line of readFileSync32(p, "utf-8").split("\n")) {
|
|
34618
34622
|
const t = line.trim();
|
|
34619
34623
|
if (!t || t.startsWith("#")) continue;
|
|
34620
34624
|
const eq = t.indexOf("=");
|
|
@@ -34747,7 +34751,7 @@ function createWorkerConfigGetter(configPath2, mainModelRef2) {
|
|
|
34747
34751
|
if (!allowed && !providerId2) return void 0;
|
|
34748
34752
|
if (!cached || Date.now() - readAt > 3e4) {
|
|
34749
34753
|
try {
|
|
34750
|
-
cached = JSON.parse(
|
|
34754
|
+
cached = JSON.parse(readFileSync33(configPath2, "utf8"));
|
|
34751
34755
|
readAt = Date.now();
|
|
34752
34756
|
} catch (error) {
|
|
34753
34757
|
console.warn(`[bg-worker] config read failed: ${error?.message ?? error}`);
|
|
@@ -34902,7 +34906,7 @@ init_import_backups();
|
|
|
34902
34906
|
import { fork } from "node:child_process";
|
|
34903
34907
|
import { DatabaseSync as DatabaseSync19 } from "node:sqlite";
|
|
34904
34908
|
import { randomUUID as randomUUID16 } from "node:crypto";
|
|
34905
|
-
import { existsSync as existsSync22, statSync as statSync6, writeFileSync as
|
|
34909
|
+
import { existsSync as existsSync22, statSync as statSync6, writeFileSync as writeFileSync14, readFileSync as readFileSync35, unlinkSync as unlinkSync7 } from "node:fs";
|
|
34906
34910
|
import { join as join46 } from "node:path";
|
|
34907
34911
|
import { fileURLToPath as fileURLToPath13 } from "node:url";
|
|
34908
34912
|
|
|
@@ -34915,7 +34919,7 @@ import { Worker } from "node:worker_threads";
|
|
|
34915
34919
|
|
|
34916
34920
|
// src/continuity/sqlite-physical-maintenance.ts
|
|
34917
34921
|
import { DatabaseSync as DatabaseSync16 } from "node:sqlite";
|
|
34918
|
-
import { lstatSync as
|
|
34922
|
+
import { lstatSync as lstatSync10 } from "node:fs";
|
|
34919
34923
|
import { resolve as resolve17 } from "node:path";
|
|
34920
34924
|
|
|
34921
34925
|
// src/continuity/sqlite-store-location.ts
|
|
@@ -35010,6 +35014,8 @@ init_schema_migrations();
|
|
|
35010
35014
|
// src/continuity/inventory.ts
|
|
35011
35015
|
import { isAbsolute as isAbsolute4, join as join42, relative as relative6, resolve as resolve16, sep as sep4 } from "node:path";
|
|
35012
35016
|
var STATE = new Set(`workspace agents auth configs cron media mem7 memory runtime session-memory steer tasks teams todos tools topics topics-history .everos .calendar calendar proactive skills prompts goals.json goal-events.jsonl SESSION-STATE.md install-identity.json license.json report-failures.jsonl report-state.json service-suggestions.json weixin cc-driver engines.json settings.json onboarding.json onboarding-tips.json remote-watchers.json plans telegram state`.split(" "));
|
|
35017
|
+
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(" "));
|
|
35018
|
+
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(" "));
|
|
35013
35019
|
function isWithin(root, candidate) {
|
|
35014
35020
|
const rel = relative6(resolve16(root), resolve16(candidate));
|
|
35015
35021
|
return !rel || !rel.startsWith(".." + sep4) && rel !== ".." && !isAbsolute4(rel);
|
|
@@ -35023,7 +35029,7 @@ function openPhysicalMaintenanceDatabase(file, stateDir2) {
|
|
|
35023
35029
|
const runtimeRoots = [.../* @__PURE__ */ new Set([...stateDir2 ? [resolve17(stateDir2)] : [], ...place ? [place.stateDir] : []])].sort();
|
|
35024
35030
|
for (const root of runtimeRoots) assertStateDirUsable(root);
|
|
35025
35031
|
try {
|
|
35026
|
-
const info =
|
|
35032
|
+
const info = lstatSync10(absolute);
|
|
35027
35033
|
if (!info.isFile() || info.isSymbolicLink()) throw new Error();
|
|
35028
35034
|
} catch (error) {
|
|
35029
35035
|
throw new Error("REPLICATION_RECOVERY_REQUIRED", { cause: error });
|
|
@@ -35250,7 +35256,7 @@ function createSqliteMaintenance(stateDir2, options = {}) {
|
|
|
35250
35256
|
let lastRequest = Date.now();
|
|
35251
35257
|
const removeMarker = (token) => {
|
|
35252
35258
|
try {
|
|
35253
|
-
if (JSON.parse(
|
|
35259
|
+
if (JSON.parse(readFileSync35(marker, "utf8")).token === token) unlinkSync7(marker);
|
|
35254
35260
|
} catch {
|
|
35255
35261
|
}
|
|
35256
35262
|
};
|
|
@@ -35275,11 +35281,11 @@ function createSqliteMaintenance(stateDir2, options = {}) {
|
|
|
35275
35281
|
if (existsSync22(marker)) {
|
|
35276
35282
|
let previous;
|
|
35277
35283
|
try {
|
|
35278
|
-
previous = JSON.parse(
|
|
35284
|
+
previous = JSON.parse(readFileSync35(marker, "utf8"));
|
|
35279
35285
|
} catch {
|
|
35280
35286
|
}
|
|
35281
35287
|
if (Number.isSafeInteger(previous?.pid) && previous.pid > 0 && live(previous.pid) && Number.isSafeInteger(previous.startedAt) && Date.now() - previous.startedAt < 24e4) return;
|
|
35282
|
-
|
|
35288
|
+
unlinkSync7(marker);
|
|
35283
35289
|
}
|
|
35284
35290
|
const db = new DatabaseSync19(path10, { readOnly: true });
|
|
35285
35291
|
let eligible = false;
|
|
@@ -35334,7 +35340,7 @@ function createSqliteMaintenance(stateDir2, options = {}) {
|
|
|
35334
35340
|
});
|
|
35335
35341
|
});
|
|
35336
35342
|
try {
|
|
35337
|
-
|
|
35343
|
+
writeFileSync14(marker, JSON.stringify({ pid: child.pid, ownerPid: process.pid, token, startedAt: Date.now() }), { flag: "wx" });
|
|
35338
35344
|
} catch (error) {
|
|
35339
35345
|
void interrupt();
|
|
35340
35346
|
throw error;
|