engine7 7.1.145 → 7.1.146
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/engine-startup.mjs +396 -321
- package/dist/main.mjs +402 -327
- package/package.json +3 -2
package/dist/engine-startup.mjs
CHANGED
|
@@ -453,19 +453,19 @@ import { dirname, join, resolve } from "node:path";
|
|
|
453
453
|
import { createHash as createHash2, randomUUID as randomUUID2 } from "node:crypto";
|
|
454
454
|
function assertPath(root, rel) {
|
|
455
455
|
if (!safeRel(rel)) throw Error("TRAVEL_UNSAFE_PATH");
|
|
456
|
-
let
|
|
456
|
+
let path120 = root;
|
|
457
457
|
for (const part of rel.split("/")) {
|
|
458
|
-
|
|
458
|
+
path120 = join(path120, part);
|
|
459
459
|
try {
|
|
460
|
-
if (lstatSync(
|
|
460
|
+
if (lstatSync(path120).isSymbolicLink()) throw Error("TRAVEL_UNSAFE_PATH");
|
|
461
461
|
} catch (e) {
|
|
462
462
|
if (e.code !== "ENOENT") throw e;
|
|
463
463
|
}
|
|
464
464
|
}
|
|
465
|
-
return
|
|
465
|
+
return path120;
|
|
466
466
|
}
|
|
467
|
-
function atomic(
|
|
468
|
-
const temp =
|
|
467
|
+
function atomic(path120, body2) {
|
|
468
|
+
const temp = path120 + "." + randomUUID2() + ".tmp";
|
|
469
469
|
let fd;
|
|
470
470
|
try {
|
|
471
471
|
fd = openSync2(temp, "wx", 384);
|
|
@@ -473,7 +473,7 @@ function atomic(path119, body2) {
|
|
|
473
473
|
fsyncSync2(fd);
|
|
474
474
|
closeSync2(fd);
|
|
475
475
|
fd = void 0;
|
|
476
|
-
renameSync2(temp,
|
|
476
|
+
renameSync2(temp, path120);
|
|
477
477
|
} finally {
|
|
478
478
|
if (fd !== void 0) closeSync2(fd);
|
|
479
479
|
rmSync(temp, { force: true });
|
|
@@ -485,9 +485,9 @@ function read(root) {
|
|
|
485
485
|
if (value.version !== 1 || value.root !== resolve(root) || !Number.isSafeInteger(value.pid) || value.pid < 1 || !/^[a-f0-9-]{36}$/.test(value.token) || typeof value.committed !== "boolean" || digest8 !== hash(JSON.stringify(body2)) || !Array.isArray(value.entries) || value.entries.some((e) => !safeRel(e.rel) || e.oldSha !== void 0 && !/^[a-f0-9]{64}$/.test(e.oldSha) || e.newSha !== void 0 && !/^[a-f0-9]{64}$/.test(e.newSha))) throw Error("TRAVEL_APPLY_RECOVERY_INVALID");
|
|
486
486
|
return value;
|
|
487
487
|
}
|
|
488
|
-
function matches(
|
|
489
|
-
if (!existsSync2(
|
|
490
|
-
const fd = openSync2(
|
|
488
|
+
function matches(path120, sha3) {
|
|
489
|
+
if (!existsSync2(path120)) return false;
|
|
490
|
+
const fd = openSync2(path120, "r"), digest8 = createHash2("sha256"), buffer = Buffer.alloc(1048576);
|
|
491
491
|
try {
|
|
492
492
|
for (; ; ) {
|
|
493
493
|
const n = readSync(fd, buffer, 0, buffer.length, null);
|
|
@@ -557,14 +557,14 @@ var init_apply_transaction = __esm({
|
|
|
557
557
|
import { randomUUID as randomUUID3, verify } from "node:crypto";
|
|
558
558
|
import { constants, closeSync as closeSync3, existsSync as existsSync3, fstatSync, fsyncSync as fsyncSync3, lstatSync as lstatSync2, mkdirSync as mkdirSync2, openSync as openSync3, readFileSync as readFileSync3, renameSync as renameSync3, writeFileSync as writeFileSync3 } from "node:fs";
|
|
559
559
|
import { basename, dirname as dirname2, join as join2, resolve as resolve2 } from "node:path";
|
|
560
|
-
function assertPrivateDirectory(
|
|
561
|
-
const stat4 = lstatSync2(
|
|
560
|
+
function assertPrivateDirectory(path120) {
|
|
561
|
+
const stat4 = lstatSync2(path120);
|
|
562
562
|
if (!stat4.isDirectory() || stat4.isSymbolicLink() || process.platform !== "win32" && (stat4.uid !== process.getuid() || stat4.mode & 63)) throw new Error("TRAVEL_PRIVATE_CONTROL_REQUIRED");
|
|
563
563
|
}
|
|
564
|
-
function readPrivateFile(
|
|
565
|
-
const before = lstatSync2(
|
|
564
|
+
function readPrivateFile(path120, maximum) {
|
|
565
|
+
const before = lstatSync2(path120);
|
|
566
566
|
if (!before.isFile() || before.isSymbolicLink() || process.platform !== "win32" && (before.uid !== process.getuid() || before.mode & 63)) throw new Error("TRAVEL_PRIVATE_CONTROL_REQUIRED");
|
|
567
|
-
const fd = openSync3(
|
|
567
|
+
const fd = openSync3(path120, constants.O_RDONLY | (constants.O_NOFOLLOW ?? 0));
|
|
568
568
|
try {
|
|
569
569
|
if (fstatSync(fd).size > maximum) throw new Error("TRAVEL_INVALID_CONTROL");
|
|
570
570
|
return readFileSync3(fd);
|
|
@@ -572,12 +572,12 @@ function readPrivateFile(path119, maximum) {
|
|
|
572
572
|
closeSync3(fd);
|
|
573
573
|
}
|
|
574
574
|
}
|
|
575
|
-
function writeControl(
|
|
576
|
-
const temporary =
|
|
575
|
+
function writeControl(path120, value) {
|
|
576
|
+
const temporary = path120 + "." + randomUUID3() + ".tmp";
|
|
577
577
|
writeFileSync3(temporary, JSON.stringify(value), { mode: 384, flag: "wx", flush: true });
|
|
578
|
-
renameSync3(temporary,
|
|
578
|
+
renameSync3(temporary, path120);
|
|
579
579
|
if (process.platform !== "win32") {
|
|
580
|
-
const fd = openSync3(dirname2(
|
|
580
|
+
const fd = openSync3(dirname2(path120), "r");
|
|
581
581
|
try {
|
|
582
582
|
fsyncSync3(fd);
|
|
583
583
|
} finally {
|
|
@@ -1446,9 +1446,9 @@ function normalize(input) {
|
|
|
1446
1446
|
if (!input || !/^[a-f0-9]{64}$/.test(input.schemaHash)) throw new Error("REPLICATION_REGISTRATION_INVALID");
|
|
1447
1447
|
return Object.freeze({ binding: normalizeBinding(input.binding), schemaHash: input.schemaHash });
|
|
1448
1448
|
}
|
|
1449
|
-
function directory(
|
|
1450
|
-
const info = lstatSync3(
|
|
1451
|
-
if (!info.isDirectory() || info.isSymbolicLink() || realpathSync(
|
|
1449
|
+
function directory(path120) {
|
|
1450
|
+
const info = lstatSync3(path120);
|
|
1451
|
+
if (!info.isDirectory() || info.isSymbolicLink() || realpathSync(path120) !== resolve3(path120) || process.platform !== "win32" && (info.mode & 63 || info.uid !== process.getuid()))
|
|
1452
1452
|
throw new Error("REPLICATION_REGISTRATION_INVALID");
|
|
1453
1453
|
}
|
|
1454
1454
|
function readRuntimeReplicationRegistration(stateDir, component, key6) {
|
|
@@ -5027,8 +5027,8 @@ var init_recovery_deletion = __esm({
|
|
|
5027
5027
|
const { owners, parents } = this.links(table, row);
|
|
5028
5028
|
for (const parent of parents) for (const owner of owners) this.edge(parent, owner);
|
|
5029
5029
|
if (table === "memory_artifact_publications") {
|
|
5030
|
-
const medium = text(row, "medium"),
|
|
5031
|
-
const identity3 = medium === "markdown" &&
|
|
5030
|
+
const medium = text(row, "medium"), path120 = text(row, "path"), physicalId = text(row, "physical_id"), kind = text(row, "kind");
|
|
5031
|
+
const identity3 = medium === "markdown" && path120 ? "file:mem7/" + path120 : medium === "vector" && physicalId && kind ? "vector:" + kind + "/rows/" + createHash10("sha256").update(physicalId).digest("hex") + ".arrow" : void 0;
|
|
5032
5032
|
if (identity3) {
|
|
5033
5033
|
const rows = this.artifactPaths.get(identity3) ?? [];
|
|
5034
5034
|
rows.push(row);
|
|
@@ -5036,8 +5036,8 @@ var init_recovery_deletion = __esm({
|
|
|
5036
5036
|
}
|
|
5037
5037
|
}
|
|
5038
5038
|
}
|
|
5039
|
-
blocksArtifactPath(kind,
|
|
5040
|
-
const rows = this.artifactPaths.get(kind + ":" +
|
|
5039
|
+
blocksArtifactPath(kind, path120) {
|
|
5040
|
+
const rows = this.artifactPaths.get(kind + ":" + path120);
|
|
5041
5041
|
return rows?.some((row) => this.blocks("memory_artifact_publications", row));
|
|
5042
5042
|
}
|
|
5043
5043
|
blocks(table, row) {
|
|
@@ -5678,9 +5678,9 @@ function assertPrivateStat(stat4, directory2) {
|
|
|
5678
5678
|
if ((directory2 ? !stat4.isDirectory() : !stat4.isFile()) || process.platform !== "win32" && ((stat4.mode & 63) !== 0 || stat4.uid !== process.getuid?.()))
|
|
5679
5679
|
throw new Error("KEY_SERVICE_PRIVATE_PATH_REQUIRED");
|
|
5680
5680
|
}
|
|
5681
|
-
function readPrivateFile2(
|
|
5682
|
-
assertPrivateStat(lstatSync6(
|
|
5683
|
-
const fd = openSync6(
|
|
5681
|
+
function readPrivateFile2(path120, maximumBytes = 65536) {
|
|
5682
|
+
assertPrivateStat(lstatSync6(path120), false);
|
|
5683
|
+
const fd = openSync6(path120, constants4.O_RDONLY | (constants4.O_NOFOLLOW ?? 0));
|
|
5684
5684
|
try {
|
|
5685
5685
|
const stat4 = fstatSync3(fd);
|
|
5686
5686
|
assertPrivateStat(stat4, false);
|
|
@@ -5710,23 +5710,23 @@ import {
|
|
|
5710
5710
|
mkdirSync as mkdirSync7
|
|
5711
5711
|
} from "node:fs";
|
|
5712
5712
|
import { join as join6, dirname as dirname4, resolve as resolve4 } from "node:path";
|
|
5713
|
-
function assertPrivateDirectory2(
|
|
5714
|
-
const info = lstatSync7(
|
|
5715
|
-
if (!info.isDirectory() || info.isSymbolicLink() || realpathSync3(
|
|
5713
|
+
function assertPrivateDirectory2(path120) {
|
|
5714
|
+
const info = lstatSync7(path120);
|
|
5715
|
+
if (!info.isDirectory() || info.isSymbolicLink() || realpathSync3(path120) !== resolve4(path120) || process.platform !== "win32" && (info.mode & 63 || info.uid !== process.getuid()))
|
|
5716
5716
|
throw new Error("PUBLICATION_PRIVATE_DIRECTORY_REQUIRED");
|
|
5717
5717
|
}
|
|
5718
|
-
function syncDir(
|
|
5718
|
+
function syncDir(path120) {
|
|
5719
5719
|
if (process.platform === "win32") return;
|
|
5720
|
-
const fd = openSync7(
|
|
5720
|
+
const fd = openSync7(path120, constants5.O_RDONLY);
|
|
5721
5721
|
try {
|
|
5722
5722
|
fsyncSync6(fd);
|
|
5723
5723
|
} finally {
|
|
5724
5724
|
closeSync7(fd);
|
|
5725
5725
|
}
|
|
5726
5726
|
}
|
|
5727
|
-
function preparePrivateDirectory(
|
|
5727
|
+
function preparePrivateDirectory(path120) {
|
|
5728
5728
|
const missing = [];
|
|
5729
|
-
let parent = resolve4(
|
|
5729
|
+
let parent = resolve4(path120);
|
|
5730
5730
|
for (; ; ) {
|
|
5731
5731
|
try {
|
|
5732
5732
|
lstatSync7(parent);
|
|
@@ -5747,10 +5747,10 @@ function preparePrivateDirectory(path119) {
|
|
|
5747
5747
|
assertPrivateDirectory2(directory2);
|
|
5748
5748
|
syncDir(dirname4(directory2));
|
|
5749
5749
|
}
|
|
5750
|
-
assertPrivateDirectory2(
|
|
5750
|
+
assertPrivateDirectory2(path120);
|
|
5751
5751
|
}
|
|
5752
|
-
function preparePrivateDatabase(
|
|
5753
|
-
for (const file3 of [
|
|
5752
|
+
function preparePrivateDatabase(path120) {
|
|
5753
|
+
for (const file3 of [path120, path120 + "-journal", path120 + "-wal", path120 + "-shm"]) {
|
|
5754
5754
|
try {
|
|
5755
5755
|
const info2 = lstatSync7(file3);
|
|
5756
5756
|
if (!info2.isFile() || info2.isSymbolicLink() || process.platform !== "win32" && (info2.mode & 63 || info2.uid !== process.getuid()))
|
|
@@ -5760,15 +5760,15 @@ function preparePrivateDatabase(path119) {
|
|
|
5760
5760
|
}
|
|
5761
5761
|
}
|
|
5762
5762
|
try {
|
|
5763
|
-
const fd = openSync7(
|
|
5763
|
+
const fd = openSync7(path120, "wx", 384);
|
|
5764
5764
|
closeSync7(fd);
|
|
5765
5765
|
} catch (error) {
|
|
5766
5766
|
if (error.code !== "EEXIST") throw error;
|
|
5767
5767
|
}
|
|
5768
|
-
const info = lstatSync7(
|
|
5768
|
+
const info = lstatSync7(path120);
|
|
5769
5769
|
if (!info.isFile() || info.isSymbolicLink() || process.platform !== "win32" && (info.mode & 63 || info.uid !== process.getuid()))
|
|
5770
5770
|
throw new Error("PUBLICATION_PRIVATE_FILE_REQUIRED");
|
|
5771
|
-
syncDir(dirname4(
|
|
5771
|
+
syncDir(dirname4(path120));
|
|
5772
5772
|
}
|
|
5773
5773
|
var PUBLICATION_CHUNK_BYTES, MAGIC, INLINE_BYTES, noFollow;
|
|
5774
5774
|
var init_publication_objects = __esm({
|
|
@@ -7929,23 +7929,23 @@ var init_facts = __esm({
|
|
|
7929
7929
|
if ((exception || proposal.changeKind === "exception") && (!exception || schedule.frequency !== "once")) throw new Error("OCCURRENCE_EXCEPTION_REQUIRED");
|
|
7930
7930
|
}
|
|
7931
7931
|
for (const [index, evidence] of proposal.evidence.entries()) {
|
|
7932
|
-
const
|
|
7933
|
-
if (!evidence || typeof evidence !== "object") throw new Error(`INVALID_EVIDENCE_SPAN: ${
|
|
7932
|
+
const path120 = `evidence[${index}]`;
|
|
7933
|
+
if (!evidence || typeof evidence !== "object") throw new Error(`INVALID_EVIDENCE_SPAN: ${path120} \u2014 \u6BCF\u6761\u8BC1\u636E\u987B\u662F\u5BF9\u8C61 {sourceId, quote, relation}`);
|
|
7934
7934
|
const source = this.db.prepare(`SELECT text,role,origin_class,interpretation_status FROM memory_sources s WHERE scope_id=? AND source_id=?
|
|
7935
7935
|
AND NOT EXISTS (SELECT 1 FROM memory_sources newer WHERE newer.scope_id=s.scope_id
|
|
7936
7936
|
AND newer.origin_key=s.origin_key AND newer.source_version>s.source_version)`).get(scopeId(scope), evidence.sourceId ?? null);
|
|
7937
|
-
if (!source || source.interpretation_status === "deleted") throw new Error(`INVALID_EVIDENCE_SPAN: ${
|
|
7938
|
-
if (typeof evidence.quote !== "string" || !evidence.quote) throw new Error(`INVALID_EVIDENCE_SPAN: ${
|
|
7937
|
+
if (!source || source.interpretation_status === "deleted") throw new Error(`INVALID_EVIDENCE_SPAN: ${path120}.sourceId \u2014 \u672C\u6C60\u8BFB\u4E0D\u5230\u8FD9\u6761\u6765\u6E90\uFF08\u4E0D\u5B58\u5728\u3001\u5DF2\u5220\u9664\u6216\u5DF2\u6709\u65B0\u7248\u672C\uFF09\uFF1B\u7528 memory_get({source_id}) \u6838\u5BF9\u5E76\u590D\u5236\u771F\u5B9E\u6765\u6E90 ID`);
|
|
7938
|
+
if (typeof evidence.quote !== "string" || !evidence.quote) throw new Error(`INVALID_EVIDENCE_SPAN: ${path120}.quote \u2014 quote \u5FC5\u586B\uFF0C\u9010\u5B57\u51FA\u81EA\u6765\u6E90\u539F\u6587`);
|
|
7939
7939
|
if (!Number.isSafeInteger(evidence.start) || !Number.isSafeInteger(evidence.end) || evidence.start < 0 || evidence.end <= evidence.start || evidence.end > source.text.length || source.text.slice(evidence.start, evidence.end) !== evidence.quote) {
|
|
7940
7940
|
const count = occurrences(source.text, evidence.quote);
|
|
7941
|
-
throw new Error(count === 0 ? `INVALID_EVIDENCE_SPAN: ${
|
|
7941
|
+
throw new Error(count === 0 ? `INVALID_EVIDENCE_SPAN: ${path120}.quote \u2014 \u5F15\u6587\u5FC5\u987B\u9010\u5B57\u51FA\u81EA\u6765\u6E90\u539F\u6587\uFF08\u539F\u6587\u957F ${source.text.length}\uFF09\uFF1B\u7528 memory_get({source_id}) \u590D\u5236\u539F\u53E5\uFF0C\u4E0D\u8981\u6539\u5199` : `INVALID_EVIDENCE_SPAN: ${path120} \u2014 \u5F15\u6587\u5728\u539F\u6587\u4E2D\u51FA\u73B0 ${count} \u6B21\uFF0C\u8BF7\u7ED9\u51C6\u786E\u7684\u90A3\u4E00\u5904 start/end\uFF08UTF-16 \u4E0B\u6807\uFF0C\u539F\u6587\u957F ${source.text.length}\uFF09`);
|
|
7942
7942
|
}
|
|
7943
|
-
if (!["supports", "refutes"].includes(evidence.relation)) throw new Error(`INVALID_EVIDENCE_SPAN: ${
|
|
7943
|
+
if (!["supports", "refutes"].includes(evidence.relation)) throw new Error(`INVALID_EVIDENCE_SPAN: ${path120}.relation \u2014 \u53EA\u80FD\u662F supports\uFF08\u652F\u6301\uFF09\u6216 refutes\uFF08\u53CD\u9A73\uFF09`);
|
|
7944
7944
|
const relationValue = proposal.value;
|
|
7945
7945
|
if (proposal.predicate === "relation.open" && relationValue?.attribution === "reported" && (proposal.claimKind !== "reported_statement" || !hasReportedAttribution(source.text, relationValue, this.entities.sourceMentions(scope, evidence.sourceId)))) {
|
|
7946
7946
|
throw new Error("EVIDENCE_REPORTED_ATTRIBUTION_UNGROUNDED: attribution=reported \u65F6 claimKind \u987B\u4E3A reported_statement\uFF0C\u4E14 attributionQuote \u5FC5\u987B\u662F\u539F\u8BDD\u91CC\u9010\u5B57\u7684\u8F6C\u8FF0\u53E5\uFF08\u5982\u300C\u67D0\u67D0\u8BF4\uFF1A\u300D\uFF09");
|
|
7947
7947
|
}
|
|
7948
|
-
const roleMismatch = () => new Error(`EVIDENCE_ROLE_MISMATCH: ${
|
|
7948
|
+
const roleMismatch = () => new Error(`EVIDENCE_ROLE_MISMATCH: ${path120} \u7684\u4F5C\u8005/\u89D2\u8272\u4E0E claimKind=${proposal.claimKind} \u4E0D\u7B26\uFF08\u6765\u6E90 role=${source.role}, originClass=${source.origin_class}\uFF09 \u2014 \u7528\u6237\u539F\u8BDD\u914D user_statement\u3001\u5DE5\u5177\u7ED3\u679C\u914D tool_observation\u3001\u8F6C\u8FF0\u4ED6\u4EBA\u914D reported_statement\u3001\u4F60\u81EA\u5DF1\u8BF4\u7684\u8BDD\u914D agent_statement\uFF1B\u6362\u5339\u914D\u7684\u6765\u6E90\u6216\u6539 claimKind`);
|
|
7949
7949
|
if (proposal.claimKind !== "inference") {
|
|
7950
7950
|
if (proposal.claimKind === "user_statement" && (source.role !== "user" || !["host_user", "client_reported_user"].includes(source.origin_class))) throw roleMismatch();
|
|
7951
7951
|
if (proposal.claimKind === "tool_observation" && (source.role !== "tool" || source.origin_class !== "tool_observation")) throw roleMismatch();
|
|
@@ -9800,11 +9800,11 @@ function applySocialInterpretation(store, scope, result2, captured, requestKey,
|
|
|
9800
9800
|
const covers = (evidence, mention) => evidence.sourceId === mention.sourceId && evidence.start <= mention.start && evidence.end >= mention.end;
|
|
9801
9801
|
const entitySnapshot = store.entities.list(scope);
|
|
9802
9802
|
for (const mention of ordered) {
|
|
9803
|
-
const
|
|
9803
|
+
const path120 = mentionPath(mention);
|
|
9804
9804
|
const source = store.sources.get(scope, mention.sourceId);
|
|
9805
9805
|
if (!source || !captured.sourceIds.includes(mention.sourceId) || !Number.isSafeInteger(mention.start) || !Number.isSafeInteger(mention.end) || mention.start < 0 || mention.end <= mention.start || mention.end > source.text.length || source.text.slice(mention.start, mention.end) !== mention.quote || typeof mention.key !== "string" || ids.has(mention.key) || typeof mention.actual !== "boolean") {
|
|
9806
|
-
if (typeof mention.actual !== "boolean") fail2("INVALID_SOCIAL_MENTION", `${
|
|
9807
|
-
fail2("INVALID_SOCIAL_MENTION", `${
|
|
9806
|
+
if (typeof mention.actual !== "boolean") fail2("INVALID_SOCIAL_MENTION", `${path120}.actual`, "\u5FC5\u586B\u5E03\u5C14\u503C\uFF1B\u771F\u5B9E\u4EBA\u7269\u63D0\u53CA\u586B true\uFF0C\u5047\u8BBE\u4EBA\u7269\u586B false\u3002");
|
|
9807
|
+
fail2("INVALID_SOCIAL_MENTION", `${path120}.quote/sourceId/start/end`, "quote \u5FC5\u987B\u9010\u5B57\u51FA\u73B0\u5728 sourceId \u5BF9\u5E94\u7684\u539F\u8BDD\u4E2D\uFF1B\u5148 memory_get({source_id:\u8BE5\u6765\u6E90}) \u6838\u5BF9\u3002mention.quote \u53EA\u622A\u4EBA\u540D/\u79F0\u547C\uFF0C\u5B8C\u6574\u540C\u4EBA\u8BF4\u660E\u653E identity.evidence.quote\uFF1B\u552F\u4E00\u5F15\u6587\u53EF\u7701\u7565 start/end\u3002");
|
|
9808
9808
|
}
|
|
9809
9809
|
if (!mention.actual || isAssistantDraft(source)) {
|
|
9810
9810
|
ids.set(mention.key, null);
|
|
@@ -9814,12 +9814,12 @@ function applySocialInterpretation(store, scope, result2, captured, requestKey,
|
|
|
9814
9814
|
if (!["existing", "new", "unresolved"].includes(mention.disposition)) throw new Error("INVALID_SOCIAL_DISPOSITION");
|
|
9815
9815
|
if (!["name", "description", "reference"].includes(mention.mentionKind)) throw new Error("INVALID_SOCIAL_MENTION_KIND");
|
|
9816
9816
|
let entity = null;
|
|
9817
|
-
const basisRefs = references(mention.basisSourceIds, source.sourceId, `${
|
|
9817
|
+
const basisRefs = references(mention.basisSourceIds, source.sourceId, `${path120}.basisSourceIds`);
|
|
9818
9818
|
let identityEntity = null;
|
|
9819
9819
|
if (mention.identity !== void 0) {
|
|
9820
9820
|
const identity3 = mention.identity;
|
|
9821
9821
|
if (!identity3 || !["same_person", "different_person", "uncertain"].includes(identity3.relation)) throw new Error("INVALID_SOCIAL_IDENTITY");
|
|
9822
|
-
const evidenceSource = literalSpan(identity3.evidence, `${
|
|
9822
|
+
const evidenceSource = literalSpan(identity3.evidence, `${path120}.identity.evidence`);
|
|
9823
9823
|
if (evidenceSource.sourceId !== source.sourceId && !captured.contextRefs?.some((ref) => ref.sourceId === evidenceSource.sourceId)) {
|
|
9824
9824
|
throw new Error("INVALID_SOCIAL_IDENTITY_EVIDENCE");
|
|
9825
9825
|
}
|
|
@@ -9831,7 +9831,7 @@ function applySocialInterpretation(store, scope, result2, captured, requestKey,
|
|
|
9831
9831
|
anchorEntityId = store.entities.speaker(scope, source.sourceId)?.entityId;
|
|
9832
9832
|
} else {
|
|
9833
9833
|
const supplied = mentionsByKey.get(identity3.anchor);
|
|
9834
|
-
if (!supplied || supplied.sourceId !== source.sourceId || supplied.key === mention.key) fail2("INVALID_SOCIAL_IDENTITY_ANCHOR", `${
|
|
9834
|
+
if (!supplied || supplied.sourceId !== source.sourceId || supplied.key === mention.key) fail2("INVALID_SOCIAL_IDENTITY_ANCHOR", `${path120}.identity.anchor`, anchorCorrection);
|
|
9835
9835
|
const anchor = supplied;
|
|
9836
9836
|
if (!covers(identity3.evidence, mention) || mention.mentionKind !== "reference" && !covers(identity3.evidence, anchor)) throw new Error("INVALID_SOCIAL_IDENTITY_EVIDENCE");
|
|
9837
9837
|
anchorEntityId = ids.get(supplied.key);
|
|
@@ -9840,25 +9840,25 @@ function applySocialInterpretation(store, scope, result2, captured, requestKey,
|
|
|
9840
9840
|
} else {
|
|
9841
9841
|
const anchor = identity3.anchor;
|
|
9842
9842
|
const authorAnchor = anchor && "author" in anchor;
|
|
9843
|
-
const anchorSource = authorAnchor ? store.sources.get(scope, anchor.sourceId) : literalSpan(anchor, `${
|
|
9843
|
+
const anchorSource = authorAnchor ? store.sources.get(scope, anchor.sourceId) : literalSpan(anchor, `${path120}.identity.anchor`);
|
|
9844
9844
|
if (!anchorSource || !captured.sourceRefs.some((ref) => ref.sourceId === anchorSource.sourceId && ref.sourceVersion === anchorSource.sourceVersion)) {
|
|
9845
|
-
fail2("INVALID_SOCIAL_IDENTITY_ANCHOR", `${
|
|
9845
|
+
fail2("INVALID_SOCIAL_IDENTITY_ANCHOR", `${path120}.identity.anchor`, anchorCorrection);
|
|
9846
9846
|
}
|
|
9847
9847
|
const supplied = authorAnchor ? void 0 : captured.identityMentions?.find((item) => item.sourceId === anchor.sourceId && item.start === anchor.start && item.end === anchor.end && item.quote === anchor.quote);
|
|
9848
9848
|
const author = ["host_user", "client_reported_user", "assistant"].includes(anchorSource.originClass) ? store.entities.speaker(scope, anchor.sourceId) : null;
|
|
9849
9849
|
const selected = mention.entityId ? store.entities.resolve(scope, mention.entityId) : null;
|
|
9850
9850
|
if (authorAnchor || !supplied && author && selected?.entityId === store.entities.resolve(scope, author.entityId)?.entityId) {
|
|
9851
|
-
if (!author || "author" in anchor && anchor.author !== true) fail2("INVALID_SOCIAL_IDENTITY_ANCHOR", `${
|
|
9851
|
+
if (!author || "author" in anchor && anchor.author !== true) fail2("INVALID_SOCIAL_IDENTITY_ANCHOR", `${path120}.identity.anchor`, anchorCorrection);
|
|
9852
9852
|
if (selected && selected.entityId !== store.entities.resolve(scope, author.entityId)?.entityId) {
|
|
9853
|
-
fail2("SOCIAL_IDENTITY_CONFLICT", `${
|
|
9853
|
+
fail2("SOCIAL_IDENTITY_CONFLICT", `${path120}.identity.anchor`, `\u6765\u6E90\u4F5C\u8005\u4E3A ${author.canonicalName}\uFF0CentityId=${author.entityId}\uFF0C\u4E0E mentions.entityId=${mention.entityId} \u4E0D\u540C\uFF1B\u8BF7\u6838\u5BF9\u76EE\u6807\u4EBA\u7269\uFF0C\u5F15\u7528\u6B63\u786E\u4F5C\u8005\u6216\u6B63\u6587 confirmedMentions\u3002`);
|
|
9854
9854
|
}
|
|
9855
9855
|
if (evidenceSource.sourceId !== source.sourceId || !covers(identity3.evidence, mention)) {
|
|
9856
|
-
fail2("INVALID_SOCIAL_IDENTITY_EVIDENCE", `${
|
|
9856
|
+
fail2("INVALID_SOCIAL_IDENTITY_EVIDENCE", `${path120}.identity.evidence`, "\u5F15\u7528\u6765\u6E90\u4F5C\u8005\u65F6\uFF0Cevidence \u5E94\u5F15\u7528\u5F53\u524D\u539F\u8BDD\u4E2D\u8BF4\u660E\u8BE5\u4EBA\u7269\u7684\u5B8C\u6574\u53E5\u5B50\uFF0C\u5E76\u5305\u542B mention.quote\u3002");
|
|
9857
9857
|
}
|
|
9858
9858
|
anchorEntityId = author.entityId;
|
|
9859
9859
|
anchorBasis = references([anchor.sourceId], source.sourceId);
|
|
9860
9860
|
} else {
|
|
9861
|
-
if (!supplied || authorAnchor || anchor.sourceId === source.sourceId && anchor.start === mention.start && anchor.end === mention.end) fail2("INVALID_SOCIAL_IDENTITY_ANCHOR", `${
|
|
9861
|
+
if (!supplied || authorAnchor || anchor.sourceId === source.sourceId && anchor.start === mention.start && anchor.end === mention.end) fail2("INVALID_SOCIAL_IDENTITY_ANCHOR", `${path120}.identity.anchor`, anchorCorrection);
|
|
9862
9862
|
if (evidenceSource.sourceId === source.sourceId ? !covers(identity3.evidence, mention) : !covers(identity3.evidence, anchor)) {
|
|
9863
9863
|
throw new Error("INVALID_SOCIAL_IDENTITY_EVIDENCE");
|
|
9864
9864
|
}
|
|
@@ -9936,8 +9936,8 @@ function applySocialInterpretation(store, scope, result2, captured, requestKey,
|
|
|
9936
9936
|
if (entity) entityBasis.set(entity.entityId, distinctRefs([...entityBasis.get(entity.entityId) || [], ...grounds]));
|
|
9937
9937
|
}
|
|
9938
9938
|
for (const [ordinal, relation] of result2.relationships.entries()) {
|
|
9939
|
-
const
|
|
9940
|
-
if (typeof relation?.actual !== "boolean") fail2("INVALID_SOCIAL_RELATION", `${
|
|
9939
|
+
const path120 = `relationships[${ordinal}]`;
|
|
9940
|
+
if (typeof relation?.actual !== "boolean") fail2("INVALID_SOCIAL_RELATION", `${path120}.actual`, "\u5FC5\u586B\u5E03\u5C14\u503C\uFF1B\u7528\u6237\u5B9E\u9645\u8BF4\u660E\u7684\u5173\u7CFB\u586B true\u3002label \u662F\u5F00\u653E\u6587\u672C\uFF0C\u201C\u7236\u5B50\u201D\u53EF\u7528\u3002");
|
|
9941
9941
|
if (!relation.actual) {
|
|
9942
9942
|
applied.relationships.push({ index: ordinal, label: relation.label, state: "ignored" });
|
|
9943
9943
|
continue;
|
|
@@ -9946,7 +9946,7 @@ function applySocialInterpretation(store, scope, result2, captured, requestKey,
|
|
|
9946
9946
|
if (!source || !captured.sourceIds.includes(source.sourceId)) {
|
|
9947
9947
|
fail2(
|
|
9948
9948
|
"SOCIAL_SOURCE_NOT_PROVIDED",
|
|
9949
|
-
`${
|
|
9949
|
+
`${path120}.sourceId=${relation.sourceId}`,
|
|
9950
9950
|
`${source ? "\u8BE5\u6765\u6E90\u672A\u5217\u5165\u672C\u6B21 sources\uFF1B\u4EC5\u653E context_sources \u53EA\u4F9B\u53C2\u7167\uFF0C\u4E0D\u7528\u4E8E\u63D0\u53D6\u5173\u7CFB\u3002" : "\u672C\u6C60\u8BFB\u4E0D\u5230\u8BE5\u6765\u6E90\u3002"}\u5148 memory_get \u6838\u5BF9\u5173\u7CFB\u539F\u8BDD\uFF0C\u518D\u628A\u539F\u8BDD\u7684 ID \u548C\u7248\u672C\u5217\u5165 sources\uFF1B\u4E0D\u8981\u66FF\u6362\u4E3A\u4E0D\u542B\u8BE5\u4E8B\u5B9E\u7684\u672C\u8F6E\u56DE\u7B54\u3002`
|
|
9951
9951
|
);
|
|
9952
9952
|
}
|
|
@@ -9956,20 +9956,20 @@ function applySocialInterpretation(store, scope, result2, captured, requestKey,
|
|
|
9956
9956
|
}
|
|
9957
9957
|
for (const field of ["validFrom", "validTo"]) {
|
|
9958
9958
|
const value = relation[field];
|
|
9959
|
-
if (value === void 0) fail2("INVALID_SOCIAL_TIME", `${
|
|
9959
|
+
if (value === void 0) fail2("INVALID_SOCIAL_TIME", `${path120}.${field}`, "\u6B64\u5B57\u6BB5\u5FC5\u586B\uFF1B\u539F\u8BDD\u6CA1\u6709\u8BF4\u660E\u5173\u7CFB\u8D77\u6B62\u65F6\u523B\u65F6\u586B null\uFF0C\u4E0D\u8981\u586B\u8BF4\u8BDD\u65F6\u95F4\u3002");
|
|
9960
9960
|
if (value !== null) {
|
|
9961
9961
|
try {
|
|
9962
9962
|
if (typeof value !== "string") throw new Error("INVALID_TIME");
|
|
9963
9963
|
instant(value);
|
|
9964
9964
|
} catch {
|
|
9965
|
-
fail2("INVALID_SOCIAL_TIME", `${
|
|
9965
|
+
fail2("INVALID_SOCIAL_TIME", `${path120}.${field}`, "\u975E null \u65F6\u95F4\u987B\u4E3A\u5B8C\u6574 ISO \u65F6\u523B\uFF0C\u5E26 Z \u6216 +08:00 \u7B49\u660E\u786E UTC \u504F\u79FB\uFF1B\u672A\u77E5\u65F6\u523B\u586B null\uFF0C\u4E0D\u8981\u731C\u6D4B\u3002");
|
|
9966
9966
|
}
|
|
9967
9967
|
}
|
|
9968
9968
|
}
|
|
9969
9969
|
if (relation.validFrom !== null && relation.validFrom !== void 0) {
|
|
9970
9970
|
const quote2 = relation.validFromQuote;
|
|
9971
9971
|
if (!quote2 || !Number.isSafeInteger(quote2.start) || !Number.isSafeInteger(quote2.end) || quote2.start < 0 || quote2.end <= quote2.start || quote2.end > source.text.length || source.text.slice(quote2.start, quote2.end) !== quote2.quote) {
|
|
9972
|
-
fail2("INVALID_SOCIAL_VALID_FROM", `${
|
|
9972
|
+
fail2("INVALID_SOCIAL_VALID_FROM", `${path120}.validFrom/validFromQuote`, "\u5173\u7CFB\u8D77\u59CB\u65F6\u95F4\u9700\u8981\u539F\u8BDD\u4E2D\u7684\u65F6\u95F4\u4F9D\u636E\uFF1B\u53EA\u77E5\u9053\u4ECA\u5929\u8BF4\u4E86\u8FD9\u4EF6\u4E8B\u65F6\uFF0CvalidFrom \u586B null\uFF0C\u4E0D\u8981\u586B\u8BF4\u8BDD\u65F6\u95F4\u3002");
|
|
9973
9973
|
}
|
|
9974
9974
|
}
|
|
9975
9975
|
const speaker = store.entities.speaker(scope, source.sourceId);
|
|
@@ -9990,7 +9990,7 @@ function applySocialInterpretation(store, scope, result2, captured, requestKey,
|
|
|
9990
9990
|
if (["attitude", "feeling"].includes(relation.contentKind) && relation.direction !== "directed") throw new Error("INVALID_SOCIAL_RECIPROCITY");
|
|
9991
9991
|
if (relation.attribution !== void 0 && !["direct", "reported"].includes(relation.attribution)) throw new Error("INVALID_SOCIAL_ATTRIBUTION");
|
|
9992
9992
|
if (relation.attributionQuote !== void 0 && relation.attribution !== "reported") {
|
|
9993
|
-
fail2("INVALID_SOCIAL_ATTRIBUTION", `${
|
|
9993
|
+
fail2("INVALID_SOCIAL_ATTRIBUTION", `${path120}.attributionQuote`, "attribution=direct\uFF08\u5305\u62EC\u9ED8\u8BA4\u76F4\u63A5\u9648\u8FF0\uFF09\u65F6\u5220\u9664 attributionQuote\uFF1B\u53EA\u6709\u539F\u8BDD\u660E\u786E\u8F6C\u8FF0\u53E6\u4E00\u4EBA\u7269\u89C2\u70B9\u65F6\u624D\u7528 reported\uFF0C\u5E76\u63D0\u4F9B\u8BE5\u4EBA\u7269\u7684 perspective \u548C\u8F6C\u8FF0\u5F15\u6587\u3002\u4E0D\u8981\u4E3A\u901A\u8FC7\u6821\u9A8C\u6539\u6210\u8F6C\u8FF0\u3002");
|
|
9994
9994
|
}
|
|
9995
9995
|
if (relation.realm !== void 0 && !["real", "roleplay", "hypothetical"].includes(relation.realm)) throw new Error("INVALID_SOCIAL_REALM");
|
|
9996
9996
|
if (relation.sensitivity !== void 0 && !["normal", "sensitive"].includes(relation.sensitivity)) throw new Error("INVALID_SOCIAL_SENSITIVITY");
|
|
@@ -10015,7 +10015,7 @@ function applySocialInterpretation(store, scope, result2, captured, requestKey,
|
|
|
10015
10015
|
basisRefs: distinctRefs([
|
|
10016
10016
|
...metadata2?.basisRefs || [],
|
|
10017
10017
|
...store.socialSources.identityRefs(scope, source.sourceId),
|
|
10018
|
-
...references(relation.basisSourceIds, source.sourceId, `${
|
|
10018
|
+
...references(relation.basisSourceIds, source.sourceId, `${path120}.basisSourceIds`),
|
|
10019
10019
|
...[relation.perspective, relation.subject, relation.object].flatMap((ref) => [...mentionBasis.get(ref) || [], ...entityBasis.get(resolve42(ref)) || []])
|
|
10020
10020
|
])
|
|
10021
10021
|
};
|
|
@@ -10393,11 +10393,11 @@ function checkSeal(value) {
|
|
|
10393
10393
|
const { digest: actual, ...body2 } = value ?? {};
|
|
10394
10394
|
if (actual !== digest3(canonical(body2))) throw new Error("MANIFEST_DIGEST_MISMATCH");
|
|
10395
10395
|
}
|
|
10396
|
-
function safeRelative(
|
|
10397
|
-
return typeof
|
|
10396
|
+
function safeRelative(path120) {
|
|
10397
|
+
return typeof path120 === "string" && !!path120 && !isAbsolute(path120) && !/[:\\\x00-\x1f]/.test(path120) && path120.split("/").every((p) => p && p !== "." && p !== "..");
|
|
10398
10398
|
}
|
|
10399
|
-
function unlinked(
|
|
10400
|
-
let cursor2 = resolve5(
|
|
10399
|
+
function unlinked(path120) {
|
|
10400
|
+
let cursor2 = resolve5(path120);
|
|
10401
10401
|
for (; ; ) {
|
|
10402
10402
|
try {
|
|
10403
10403
|
if (lstatSync9(cursor2).isSymbolicLink()) throw new Error("SYMLINK_PATH");
|
|
@@ -10405,7 +10405,7 @@ function unlinked(path119) {
|
|
|
10405
10405
|
if (e.code !== "ENOENT") throw e;
|
|
10406
10406
|
}
|
|
10407
10407
|
const parent = dirname7(cursor2);
|
|
10408
|
-
if (parent === cursor2) return resolve5(
|
|
10408
|
+
if (parent === cursor2) return resolve5(path120);
|
|
10409
10409
|
cursor2 = parent;
|
|
10410
10410
|
}
|
|
10411
10411
|
}
|
|
@@ -10418,8 +10418,8 @@ function disjoint(...paths) {
|
|
|
10418
10418
|
for (let i = 0; i < p.length; i++) for (let j = i + 1; j < p.length; j++)
|
|
10419
10419
|
if (contains(p[i], p[j]) || contains(p[j], p[i])) throw new Error("PATH_OVERLAP");
|
|
10420
10420
|
}
|
|
10421
|
-
function readJson(
|
|
10422
|
-
return JSON.parse(readFileSync9(unlinked(
|
|
10421
|
+
function readJson(path120) {
|
|
10422
|
+
return JSON.parse(readFileSync9(unlinked(path120), "utf8").replace(/^\uFEFF/, ""));
|
|
10423
10423
|
}
|
|
10424
10424
|
function rawBytes(snapshot, record) {
|
|
10425
10425
|
if (!/^[a-f0-9]{64}$/.test(record.sha256)) throw new Error("INVALID_OBJECT_REFERENCE");
|
|
@@ -11410,10 +11410,10 @@ function topicMatchesYear(dates, year) {
|
|
|
11410
11410
|
function topicsHistoryRoot(b) {
|
|
11411
11411
|
return unlinked(join14(b.stateDir, "topics-history", key3(b)));
|
|
11412
11412
|
}
|
|
11413
|
-
function parseTopicHistoryPath(
|
|
11414
|
-
if (!
|
|
11413
|
+
function parseTopicHistoryPath(path120) {
|
|
11414
|
+
if (!path120.startsWith("topics-history://") || path120.length > 1e4) throw new Error("INVALID_HISTORY_REFERENCE");
|
|
11415
11415
|
try {
|
|
11416
|
-
return JSON.parse(Buffer.from(
|
|
11416
|
+
return JSON.parse(Buffer.from(path120.slice(17), "base64url").toString("utf8"));
|
|
11417
11417
|
} catch {
|
|
11418
11418
|
throw new Error("INVALID_HISTORY_REFERENCE");
|
|
11419
11419
|
}
|
|
@@ -11440,19 +11440,19 @@ async function topicHistoryReadRevision(b, refs) {
|
|
|
11440
11440
|
paths.add(join14(resolve7(b.topicsDir), ref.sourcePath));
|
|
11441
11441
|
paths.add(join14(root, "forgotten", `${digest3(ref.sourcePath)}.json`));
|
|
11442
11442
|
}
|
|
11443
|
-
const stats2 = await Promise.all([...paths].sort().map(async (
|
|
11443
|
+
const stats2 = await Promise.all([...paths].sort().map(async (path120) => {
|
|
11444
11444
|
try {
|
|
11445
|
-
const stat4 = await fs4.lstat(
|
|
11446
|
-
return [
|
|
11445
|
+
const stat4 = await fs4.lstat(path120, { bigint: true });
|
|
11446
|
+
return [path120, ...[stat4.dev, stat4.ino, stat4.mode, stat4.size, stat4.mtimeNs, stat4.ctimeNs].map(String)];
|
|
11447
11447
|
} catch (error) {
|
|
11448
|
-
if (error.code === "ENOENT") return [
|
|
11448
|
+
if (error.code === "ENOENT") return [path120, null];
|
|
11449
11449
|
throw error;
|
|
11450
11450
|
}
|
|
11451
11451
|
}));
|
|
11452
11452
|
return JSON.stringify([current2, stats2]);
|
|
11453
11453
|
}
|
|
11454
|
-
function forgotten(b,
|
|
11455
|
-
return existsSync8(unlinked(join14(topicsHistoryRoot(b), "forgotten", `${digest3(
|
|
11454
|
+
function forgotten(b, path120) {
|
|
11455
|
+
return existsSync8(unlinked(join14(topicsHistoryRoot(b), "forgotten", `${digest3(path120)}.json`)));
|
|
11456
11456
|
}
|
|
11457
11457
|
function openIndex(b, version2) {
|
|
11458
11458
|
if (!b.stateDir || !b.topicsDir) return null;
|
|
@@ -11492,16 +11492,16 @@ async function walkTopicsNeedsFallback(b) {
|
|
|
11492
11492
|
const visit = async (rel) => {
|
|
11493
11493
|
const entries2 = await fs4.readdir(unlinked(join14(b.topicsDir, rel)), { withFileTypes: true });
|
|
11494
11494
|
for (const entry of entries2) {
|
|
11495
|
-
const
|
|
11495
|
+
const path120 = rel ? `${rel}/${entry.name}` : entry.name;
|
|
11496
11496
|
if (entry.isSymbolicLink()) continue;
|
|
11497
11497
|
if (entry.isDirectory()) {
|
|
11498
|
-
if (await visit(
|
|
11498
|
+
if (await visit(path120)) return true;
|
|
11499
11499
|
continue;
|
|
11500
11500
|
}
|
|
11501
|
-
if (!entry.isFile() || !/\.md$/i.test(
|
|
11502
|
-
const source = sources.get(
|
|
11501
|
+
if (!entry.isFile() || !/\.md$/i.test(path120) || path120.toUpperCase() === "MEMORY.MD" || forgotten(b, path120)) continue;
|
|
11502
|
+
const source = sources.get(path120);
|
|
11503
11503
|
if (!source) return true;
|
|
11504
|
-
const stat4 = await fs4.stat(unlinked(join14(b.topicsDir,
|
|
11504
|
+
const stat4 = await fs4.stat(unlinked(join14(b.topicsDir, path120)));
|
|
11505
11505
|
if (stat4.size !== source.bytes || stat4.mtimeMs !== source.mtime_ms) return true;
|
|
11506
11506
|
}
|
|
11507
11507
|
return false;
|
|
@@ -12488,7 +12488,7 @@ function readRelationshipContext(store, scope, request3, clock = () => (/* @__PU
|
|
|
12488
12488
|
for (const entity of (request3.graphEntityIds ?? []).flatMap((id3) => resolve42(id3) || []).filter((entity2) => !selected.has(entity2.entityId)).slice(0, 4)) {
|
|
12489
12489
|
if (!context.people.some((person) => person.entityId === entity.entityId)) add("people", entity);
|
|
12490
12490
|
}
|
|
12491
|
-
for (const
|
|
12491
|
+
for (const path120 of (request3.graphPaths ?? []).slice(0, 40)) add("paths", path120, [path120.source, path120.target]);
|
|
12492
12492
|
const linkedIds = store.entities.list(scope, cutoff).filter((entity) => selected.has(resolve42(entity.entityId)?.entityId || entity.entityId)).map((entity) => entity.entityId);
|
|
12493
12493
|
const views = recall.entitySources(linkedIds, maxRecords);
|
|
12494
12494
|
const sourceIds = [.../* @__PURE__ */ new Set([
|
|
@@ -14085,13 +14085,13 @@ CREATE TABLE IF NOT EXISTS cluster_members (
|
|
|
14085
14085
|
const version2 = expectedVersion ?? this.dependencies.version(scope, kind, id3);
|
|
14086
14086
|
this.dependencies.assertCurrent(scope, kind, id3, version2);
|
|
14087
14087
|
const digest8 = createHash21("sha256").update(content.trim()).digest("hex");
|
|
14088
|
-
const
|
|
14088
|
+
const path120 = relative2(this.root, file3).replace(/\\/g, "/");
|
|
14089
14089
|
const previous = this.db.prepare("SELECT version,digest,path FROM memory_projection_entries WHERE scope_id=? AND kind=? AND entry_id=?").get(scopeId(scope), kind, id3);
|
|
14090
|
-
if (previous?.version === version2 && (previous.digest !== digest8 || previous.path !==
|
|
14090
|
+
if (previous?.version === version2 && (previous.digest !== digest8 || previous.path !== path120)) throw new Error("PROJECTION_PUBLICATION_VERSION_CONFLICT");
|
|
14091
14091
|
this.db.prepare(`INSERT INTO memory_projection_entries VALUES (?,?,?,?,?,?)
|
|
14092
14092
|
ON CONFLICT(scope_id,kind,entry_id) DO UPDATE SET path=excluded.path,version=excluded.version,digest=excluded.digest
|
|
14093
|
-
WHERE excluded.version>=memory_projection_entries.version`).run(scopeId(scope), kind, id3,
|
|
14094
|
-
this.artifacts.publish(scope, { ...body2, kind, id: id3, version: version2, medium: "markdown", path:
|
|
14093
|
+
WHERE excluded.version>=memory_projection_entries.version`).run(scopeId(scope), kind, id3, path120, version2, digest8);
|
|
14094
|
+
this.artifacts.publish(scope, { ...body2, kind, id: id3, version: version2, medium: "markdown", path: path120, markdown: content.trim() });
|
|
14095
14095
|
});
|
|
14096
14096
|
}
|
|
14097
14097
|
projectionMatches(scope, kind, id3, file3, content) {
|
|
@@ -14288,8 +14288,8 @@ CREATE TABLE IF NOT EXISTS cluster_members (
|
|
|
14288
14288
|
};
|
|
14289
14289
|
}
|
|
14290
14290
|
unscopedProjectionMatches(ownerId, kind, id3, file3, content) {
|
|
14291
|
-
const
|
|
14292
|
-
const mappings = this.db.prepare("SELECT scope_id FROM memory_projection_entries WHERE kind=? AND entry_id=? AND path=?").all(kind, id3,
|
|
14291
|
+
const path120 = relative2(this.root, file3).replace(/\\/g, "/");
|
|
14292
|
+
const mappings = this.db.prepare("SELECT scope_id FROM memory_projection_entries WHERE kind=? AND entry_id=? AND path=?").all(kind, id3, path120);
|
|
14293
14293
|
if (mappings.length) {
|
|
14294
14294
|
if (mappings.length !== 1) return false;
|
|
14295
14295
|
const scope = this.sources.scope(mappings[0].scope_id);
|
|
@@ -15443,7 +15443,7 @@ function recoverLegacyProjections(db2, store, input, apply = false) {
|
|
|
15443
15443
|
};
|
|
15444
15444
|
const candidates2 = [];
|
|
15445
15445
|
const duplicateIds = /* @__PURE__ */ new Set();
|
|
15446
|
-
const inside3 = (
|
|
15446
|
+
const inside3 = (path120) => path120 && !isAbsolute2(path120) && path120 !== ".." && !path120.startsWith(`..${sep2}`);
|
|
15447
15447
|
for (const relativePath of input.files) {
|
|
15448
15448
|
const logical = resolve8(root, relativePath);
|
|
15449
15449
|
let canonical6;
|
|
@@ -15457,10 +15457,10 @@ function recoverLegacyProjections(db2, store, input, apply = false) {
|
|
|
15457
15457
|
gap("projection_path_unverified");
|
|
15458
15458
|
continue;
|
|
15459
15459
|
}
|
|
15460
|
-
const
|
|
15460
|
+
const path120 = relative3(root, canonical6).replace(/\\/g, "/");
|
|
15461
15461
|
const user = `users/${input.scope.ownerId}/`;
|
|
15462
15462
|
const agent = store.ownerProjectionPath("agents", input.scope.ownerId, input.scope).replace(/\\/g, "/") + "/";
|
|
15463
|
-
const kind =
|
|
15463
|
+
const kind = path120.startsWith(`${user}episodes/`) && /\/episode-\d{4}-\d{2}-\d{2}\.md$/.test(path120) ? "episode" : path120.startsWith(`${user}.atomic_facts/`) && /\/atomic_fact-\d{4}-\d{2}-\d{2}\.md$/.test(path120) ? "atomic_fact" : path120.startsWith(`${user}.foresights/`) && /\/foresight-\d{4}-\d{2}-\d{2}\.md$/.test(path120) ? "foresight" : path120.startsWith(`${agent}.cases/`) && /\/agent_case-\d{4}-\d{2}-\d{2}\.md$/.test(path120) ? "agent_case" : void 0;
|
|
15464
15464
|
if (!kind) {
|
|
15465
15465
|
gap("projection_kind_or_owner_unverified");
|
|
15466
15466
|
continue;
|
|
@@ -15497,9 +15497,9 @@ function recoverLegacyProjections(db2, store, input, apply = false) {
|
|
|
15497
15497
|
continue;
|
|
15498
15498
|
}
|
|
15499
15499
|
const previous = db2.prepare("SELECT * FROM memory_legacy_projection_maps WHERE scope_id=? AND kind=? AND entry_id=?").get(key6, kind, match[1]);
|
|
15500
|
-
const target = join16(store.mem7RootPath(),
|
|
15500
|
+
const target = join16(store.mem7RootPath(), path120);
|
|
15501
15501
|
if (previous) {
|
|
15502
|
-
if (previous.source_file_hash !== fileHash || previous.parent_id !== parent || previous.source_relative_path !==
|
|
15502
|
+
if (previous.source_file_hash !== fileHash || previous.parent_id !== parent || previous.source_relative_path !== path120 || !store.projectionMatches(input.scope, kind, match[1], target, block)) {
|
|
15503
15503
|
gap("projection_mapping_conflict");
|
|
15504
15504
|
continue;
|
|
15505
15505
|
}
|
|
@@ -15515,7 +15515,7 @@ function recoverLegacyProjections(db2, store, input, apply = false) {
|
|
|
15515
15515
|
candidates2.push({
|
|
15516
15516
|
file: canonical6,
|
|
15517
15517
|
fileHash,
|
|
15518
|
-
relativePath:
|
|
15518
|
+
relativePath: path120,
|
|
15519
15519
|
id: match[1],
|
|
15520
15520
|
kind,
|
|
15521
15521
|
parent,
|
|
@@ -19837,8 +19837,8 @@ function notificationStateChange(route, queueStateDir) {
|
|
|
19837
19837
|
function createNotificationStateReader() {
|
|
19838
19838
|
const databases = /* @__PURE__ */ new Map();
|
|
19839
19839
|
const checkers = /* @__PURE__ */ new Map();
|
|
19840
|
-
const open6 = (
|
|
19841
|
-
const key6 = resolve11(
|
|
19840
|
+
const open6 = (path120) => {
|
|
19841
|
+
const key6 = resolve11(path120);
|
|
19842
19842
|
let db2 = databases.get(key6);
|
|
19843
19843
|
if (!db2) {
|
|
19844
19844
|
db2 = new DatabaseSync(key6, { readOnly: true });
|
|
@@ -20055,10 +20055,10 @@ function isCorruption(error) {
|
|
|
20055
20055
|
if (code === 11 || code === 26) return true;
|
|
20056
20056
|
return /database disk image is malformed|file is not a database/i.test(String(error?.message ?? error));
|
|
20057
20057
|
}
|
|
20058
|
-
function healthyDatabase(
|
|
20058
|
+
function healthyDatabase(path120) {
|
|
20059
20059
|
let db2;
|
|
20060
20060
|
try {
|
|
20061
|
-
db2 = new DatabaseSync12(
|
|
20061
|
+
db2 = new DatabaseSync12(path120);
|
|
20062
20062
|
const check = db2.prepare("PRAGMA quick_check").get();
|
|
20063
20063
|
return check?.quick_check === "ok";
|
|
20064
20064
|
} catch {
|
|
@@ -29537,8 +29537,8 @@ import { cp, readdir, rm } from "node:fs/promises";
|
|
|
29537
29537
|
import { basename as basename7, dirname as dirname12, join as join31, resolve as resolve15 } from "node:path";
|
|
29538
29538
|
import { fileURLToPath as fileURLToPath5 } from "node:url";
|
|
29539
29539
|
import { execFile } from "node:child_process";
|
|
29540
|
-
function atomicJson(
|
|
29541
|
-
const target = unlinked(
|
|
29540
|
+
function atomicJson(path120, value) {
|
|
29541
|
+
const target = unlinked(path120), temp = unlinked(`${target}.${randomUUID19()}.tmp`);
|
|
29542
29542
|
try {
|
|
29543
29543
|
writeFileSync14(temp, JSON.stringify(seal(value)) + "\n", { flag: "wx" });
|
|
29544
29544
|
renameSync11(temp, target);
|
|
@@ -29556,10 +29556,10 @@ function alive2(pid) {
|
|
|
29556
29556
|
}
|
|
29557
29557
|
}
|
|
29558
29558
|
function importerActive(historyRoot2) {
|
|
29559
|
-
const
|
|
29560
|
-
if (!existsSync15(
|
|
29559
|
+
const path120 = join31(historyRoot2, ".topics-import.lock");
|
|
29560
|
+
if (!existsSync15(path120)) return false;
|
|
29561
29561
|
try {
|
|
29562
|
-
return alive2(readJson(
|
|
29562
|
+
return alive2(readJson(path120).pid);
|
|
29563
29563
|
} catch {
|
|
29564
29564
|
return true;
|
|
29565
29565
|
}
|
|
@@ -29567,13 +29567,13 @@ function importerActive(historyRoot2) {
|
|
|
29567
29567
|
async function withTopicsImportLock(historyRoot2, action) {
|
|
29568
29568
|
const root = unlinked(historyRoot2);
|
|
29569
29569
|
mkdirSync17(root, { recursive: true });
|
|
29570
|
-
const
|
|
29570
|
+
const path120 = unlinked(join31(root, ".topics-import.lock")), token = randomUUID19();
|
|
29571
29571
|
const body2 = JSON.stringify({ pid: process.pid, token });
|
|
29572
29572
|
try {
|
|
29573
|
-
writeFileSync14(
|
|
29573
|
+
writeFileSync14(path120, body2, { flag: "wx" });
|
|
29574
29574
|
} catch (error) {
|
|
29575
29575
|
if (error.code !== "EEXIST") throw error;
|
|
29576
|
-
const original = readFileSync22(
|
|
29576
|
+
const original = readFileSync22(path120, "utf8");
|
|
29577
29577
|
let owner;
|
|
29578
29578
|
try {
|
|
29579
29579
|
owner = JSON.parse(original);
|
|
@@ -29581,23 +29581,23 @@ async function withTopicsImportLock(historyRoot2, action) {
|
|
|
29581
29581
|
throw new Error("TOPICS_IMPORT_BUSY: invalid lock");
|
|
29582
29582
|
}
|
|
29583
29583
|
if (alive2(owner.pid)) throw new Error("TOPICS_IMPORT_BUSY");
|
|
29584
|
-
if (readFileSync22(
|
|
29585
|
-
unlinkSync7(
|
|
29586
|
-
writeFileSync14(
|
|
29584
|
+
if (readFileSync22(path120, "utf8") !== original) throw new Error("TOPICS_IMPORT_BUSY");
|
|
29585
|
+
unlinkSync7(path120);
|
|
29586
|
+
writeFileSync14(path120, body2, { flag: "wx" });
|
|
29587
29587
|
}
|
|
29588
29588
|
try {
|
|
29589
29589
|
return await action();
|
|
29590
29590
|
} finally {
|
|
29591
|
-
if (existsSync15(
|
|
29591
|
+
if (existsSync15(path120) && readFileSync22(path120, "utf8") === body2) unlinkSync7(path120);
|
|
29592
29592
|
}
|
|
29593
29593
|
}
|
|
29594
29594
|
function registryPath(stateDir) {
|
|
29595
29595
|
return join31(stateDir, "mem7", ".topics-backup-roots.json");
|
|
29596
29596
|
}
|
|
29597
29597
|
function backupRoots(stateDir) {
|
|
29598
|
-
const
|
|
29599
|
-
if (!existsSync15(
|
|
29600
|
-
const value = readJson(
|
|
29598
|
+
const path120 = registryPath(stateDir);
|
|
29599
|
+
if (!existsSync15(path120)) return [join31(stateDir, "mem7")];
|
|
29600
|
+
const value = readJson(path120);
|
|
29601
29601
|
checkSeal(value);
|
|
29602
29602
|
if (value.version !== 1 || value.stateDir !== stateDir || !Array.isArray(value.roots) || value.roots.some((r) => typeof r !== "string" || resolve15(r) !== r)) throw new Error("INVALID_BACKUP_ROOT_REGISTRY");
|
|
29603
29603
|
return [.../* @__PURE__ */ new Set([join31(stateDir, "mem7"), ...value.roots])];
|
|
@@ -29757,8 +29757,8 @@ async function adoptLegacyBackups(state2, root, allowed) {
|
|
|
29757
29757
|
const history = unlinked(join31(histories, entry.name));
|
|
29758
29758
|
if (importerActive(history) || existsSync15(join31(history, pointerName))) continue;
|
|
29759
29759
|
try {
|
|
29760
|
-
const marker = readJson(join31(history, "topics-import.json")),
|
|
29761
|
-
if (marker.report?.failed === 0 && Number.isFinite(Date.parse(marker.completedAt)) && dirname12(
|
|
29760
|
+
const marker = readJson(join31(history, "topics-import.json")), path120 = unlinked(marker.report?.backupPath ?? "");
|
|
29761
|
+
if (marker.report?.failed === 0 && Number.isFinite(Date.parse(marker.completedAt)) && dirname12(path120) === root && backupName.test(basename7(path120)) && existsSync15(path120))
|
|
29762
29762
|
markers.push({ history, marker, hash: digest3(canonical(marker)) });
|
|
29763
29763
|
} catch {
|
|
29764
29764
|
}
|
|
@@ -29810,10 +29810,10 @@ async function legacyCompletionRoots(state2) {
|
|
|
29810
29810
|
try {
|
|
29811
29811
|
const marker = readJson(join31(histories, entry.name, "topics-import.json"));
|
|
29812
29812
|
if (marker.report?.failed !== 0 || !Number.isFinite(Date.parse(marker.completedAt)) || typeof marker.report.backupPath !== "string") continue;
|
|
29813
|
-
const
|
|
29814
|
-
if (!backupName.test(basename7(
|
|
29815
|
-
disjoint(join31(state2, "mem7", "index"), join31(state2, "mem7", "users"),
|
|
29816
|
-
roots.add(dirname12(
|
|
29813
|
+
const path120 = unlinked(marker.report.backupPath);
|
|
29814
|
+
if (!backupName.test(basename7(path120)) || !existsSync15(path120)) continue;
|
|
29815
|
+
disjoint(join31(state2, "mem7", "index"), join31(state2, "mem7", "users"), path120);
|
|
29816
|
+
roots.add(dirname12(path120));
|
|
29817
29817
|
} catch {
|
|
29818
29818
|
}
|
|
29819
29819
|
}
|
|
@@ -33188,8 +33188,8 @@ function modelRefListError(v) {
|
|
|
33188
33188
|
function listFields() {
|
|
33189
33189
|
return FIELDS.slice();
|
|
33190
33190
|
}
|
|
33191
|
-
function getField(
|
|
33192
|
-
return FIELDS.find((f) => f.path ===
|
|
33191
|
+
function getField(path120) {
|
|
33192
|
+
return FIELDS.find((f) => f.path === path120);
|
|
33193
33193
|
}
|
|
33194
33194
|
var VALID_PERSONAS, FIELDS;
|
|
33195
33195
|
var init_registry2 = __esm({
|
|
@@ -35213,7 +35213,7 @@ function needsFreeTierNortFixup(cfg) {
|
|
|
35213
35213
|
if (!provider) return false;
|
|
35214
35214
|
const lanes = free || readPath(cfg, "topics.clean.model") === void 0 ? LANE_MODELS : [FREE_TIER_NORT_MODEL];
|
|
35215
35215
|
if (lanes.some((id3) => !(provider.models || []).some((m) => m?.id === id3))) return true;
|
|
35216
|
-
return free && Object.keys(FIELD_REFS).some((
|
|
35216
|
+
return free && Object.keys(FIELD_REFS).some((path120) => readPath(cfg, path120) === void 0) || legacyDefaultExtract(cfg);
|
|
35217
35217
|
}
|
|
35218
35218
|
function readPath(obj, dotPath) {
|
|
35219
35219
|
return dotPath.split(".").reduce((acc, k) => acc == null ? void 0 : acc[k], obj);
|
|
@@ -35234,8 +35234,8 @@ async function applyFreeTierNortFixup(io) {
|
|
|
35234
35234
|
const pCopy = cfg.providers?.[FREE_TIER_PROVIDER_ID];
|
|
35235
35235
|
if (pCopy && pCopy !== provider) pCopy.models = newModels;
|
|
35236
35236
|
}
|
|
35237
|
-
for (const [
|
|
35238
|
-
if (free && readPath(cfg,
|
|
35237
|
+
for (const [path120, ref] of Object.entries(FIELD_REFS)) {
|
|
35238
|
+
if (free && readPath(cfg, path120) === void 0) writes.push([path120, ref]);
|
|
35239
35239
|
}
|
|
35240
35240
|
if (!free && readPath(cfg, "topics.clean.model") === void 0) {
|
|
35241
35241
|
writes.push(["topics.clean.model", FREE_TIER_FAST_REF]);
|
|
@@ -35247,8 +35247,8 @@ async function applyFreeTierNortFixup(io) {
|
|
|
35247
35247
|
}
|
|
35248
35248
|
if (!writes.length) return false;
|
|
35249
35249
|
let persisted = true;
|
|
35250
|
-
for (const [
|
|
35251
|
-
if (await io.set(
|
|
35250
|
+
for (const [path120, value] of writes) {
|
|
35251
|
+
if (await io.set(path120, value) === false) persisted = false;
|
|
35252
35252
|
}
|
|
35253
35253
|
if (!persisted) {
|
|
35254
35254
|
console.error("[startup] \u540E\u53F0\u6A21\u578B\u8865\u9F50 **\u672A\u5168\u90E8\u843D\u76D8**\uFF08\u672C\u6B21\u8FD0\u884C\u5185\u5B58\u91CC\u5DF2\u751F\u6548\uFF0C\u914D\u7F6E\u6587\u4EF6\u4ECD\u662F\u65E7\u7684\u2014\u2014\u4E0B\u6B21\u542F\u52A8\u4F1A\u91CD\u653E\uFF09\u3002\u4E0A\u9762 [liveConfig] \u90A3\u51E0\u884C\u662F\u539F\u56E0\u3002");
|
|
@@ -42050,9 +42050,9 @@ function buildPlanningContext(calDb, workspace, memory) {
|
|
|
42050
42050
|
function captureScanPlanningContext(workspace, memory, calDb) {
|
|
42051
42051
|
const read3 = () => {
|
|
42052
42052
|
if (calDb !== void 0) return buildPlanningContext(calDb, workspace, memory);
|
|
42053
|
-
const
|
|
42054
|
-
if (!existsSync26(
|
|
42055
|
-
const db2 = new DatabaseSync16(
|
|
42053
|
+
const path120 = join45(workspace, ".calendar", "calendar.db");
|
|
42054
|
+
if (!existsSync26(path120)) return buildPlanningContext(null, workspace, memory);
|
|
42055
|
+
const db2 = new DatabaseSync16(path120, { readOnly: true });
|
|
42056
42056
|
try {
|
|
42057
42057
|
return buildPlanningContext(db2, workspace, memory);
|
|
42058
42058
|
} finally {
|
|
@@ -42493,11 +42493,11 @@ var init_verdict_parse = __esm({
|
|
|
42493
42493
|
// src/memory/proactive/relationship-snapshot.ts
|
|
42494
42494
|
import { existsSync as existsSync28 } from "node:fs";
|
|
42495
42495
|
import { DatabaseSync as DatabaseSync17 } from "node:sqlite";
|
|
42496
|
-
function readRelationshipGraphSnapshot(
|
|
42497
|
-
if (!
|
|
42496
|
+
function readRelationshipGraphSnapshot(path120) {
|
|
42497
|
+
if (!path120 || !existsSync28(path120)) return void 0;
|
|
42498
42498
|
let db2;
|
|
42499
42499
|
try {
|
|
42500
|
-
db2 = new DatabaseSync17(
|
|
42500
|
+
db2 = new DatabaseSync17(path120, { readOnly: true });
|
|
42501
42501
|
db2.exec("BEGIN");
|
|
42502
42502
|
const version2 = readSchemaVersion(db2);
|
|
42503
42503
|
if (version2?.component !== "proactive" || version2.version !== PROACTIVE_SCHEMA_VERSION) return void 0;
|
|
@@ -43315,11 +43315,11 @@ function updatePeople(store, scope, input, _provided) {
|
|
|
43315
43315
|
}
|
|
43316
43316
|
const requestHash = createHash39("sha256").update(canonicalJson(input)).digest("hex");
|
|
43317
43317
|
return store.transaction(() => new MemoryReadBudget().run(() => {
|
|
43318
|
-
const load = (ref,
|
|
43318
|
+
const load = (ref, path120) => {
|
|
43319
43319
|
const source = ref && store.sources.get(scope, ref.source_id);
|
|
43320
|
-
if (!source) throw new Error(`SOCIAL_SOURCE_NOT_CURRENT: ${
|
|
43320
|
+
if (!source) throw new Error(`SOCIAL_SOURCE_NOT_CURRENT: ${path120}.source_id \u2014 \u672C\u6C60\u6682\u65F6\u8BFB\u4E0D\u5230\u6765\u6E90 ${ref?.source_id}\uFF1B\u53EF\u80FD\u5C1A\u5728\u5165\u5E93\u961F\u5217\u6216\u5DF2\u5220\u9664\u3002\u7528 memory_get({source_id:\u8BE5\u6765\u6E90}) \u6838\u5BF9\uFF1B\u4E0D\u8981\u731C source_version\uFF0C\u4E5F\u4E0D\u8981\u6362\u6210\u53E6\u4E00\u6761\u56DE\u7B54\u7684\u6765\u6E90 ID\u3002`);
|
|
43321
43321
|
if (ref.source_version !== void 0 && source.sourceVersion !== ref.source_version || !store.socialSources.readable(scope, source.sourceId)) {
|
|
43322
|
-
throw new Error(`SOCIAL_SOURCE_NOT_CURRENT: ${
|
|
43322
|
+
throw new Error(`SOCIAL_SOURCE_NOT_CURRENT: ${path120}.source_version \u2014 \u8BE5\u6765\u6E90\u8BB0\u5F55 sourceVersion=${source.sourceVersion}, state=${source.state}\uFF1B\u7528 memory_get({source_id:\u8BE5\u6765\u6E90}) \u91CD\u65B0\u8BFB\u53D6\u539F\u8BDD\u548C\u7248\u672C\u3002\u5F53\u524D\u7248\u672C\u6216\u4F9D\u636E\u53EF\u80FD\u5DF2\u5931\u6548\uFF1B\u65E0\u9700\u7B49\u5F85\u666E\u901A\u4E8B\u5B9E\u89E3\u91CA\u5B8C\u6210\u3002`);
|
|
43323
43323
|
}
|
|
43324
43324
|
return source;
|
|
43325
43325
|
};
|
|
@@ -43334,17 +43334,17 @@ function updatePeople(store, scope, input, _provided) {
|
|
|
43334
43334
|
}
|
|
43335
43335
|
const contexts2 = (input.context_sources || []).map((ref, index) => load(ref, `context_sources[${index}]`));
|
|
43336
43336
|
const visible = new Set([...sources, ...contexts2].map((source) => source.sourceId));
|
|
43337
|
-
const addContext = (id3,
|
|
43337
|
+
const addContext = (id3, path120) => {
|
|
43338
43338
|
if (typeof id3 !== "string" || visible.has(id3)) return;
|
|
43339
|
-
contexts2.push(load({ source_id: id3 },
|
|
43339
|
+
contexts2.push(load({ source_id: id3 }, path120));
|
|
43340
43340
|
visible.add(id3);
|
|
43341
43341
|
};
|
|
43342
43342
|
for (const [index, item] of [...input.mentions, ...input.relationships].entries()) {
|
|
43343
|
-
const
|
|
43344
|
-
if (Array.isArray(item?.basisSourceIds)) for (const id3 of item.basisSourceIds) addContext(id3, `${
|
|
43343
|
+
const path120 = index < input.mentions.length ? `mentions[${index}]` : `relationships[${index - input.mentions.length}]`;
|
|
43344
|
+
if (Array.isArray(item?.basisSourceIds)) for (const id3 of item.basisSourceIds) addContext(id3, `${path120}.basisSourceIds`);
|
|
43345
43345
|
if (item && "identity" in item && item.identity) {
|
|
43346
|
-
if (typeof item.identity.anchor === "object") addContext(item.identity.anchor?.sourceId, `${
|
|
43347
|
-
addContext(item.identity.evidence?.sourceId, `${
|
|
43346
|
+
if (typeof item.identity.anchor === "object") addContext(item.identity.anchor?.sourceId, `${path120}.identity.anchor`);
|
|
43347
|
+
addContext(item.identity.evidence?.sourceId, `${path120}.identity.evidence`);
|
|
43348
43348
|
}
|
|
43349
43349
|
}
|
|
43350
43350
|
for (const mention of input.mentions) {
|
|
@@ -43654,10 +43654,10 @@ var init_atomic_facts = __esm({
|
|
|
43654
43654
|
import { existsSync as existsSync30, readFileSync as readFileSync37, writeFileSync as writeFileSync19, mkdirSync as mkdirSync23, renameSync as renameSync14 } from "node:fs";
|
|
43655
43655
|
import { join as join49, dirname as dirname19 } from "node:path";
|
|
43656
43656
|
function readStatusDoc(root, sid) {
|
|
43657
|
-
const
|
|
43658
|
-
if (!existsSync30(
|
|
43657
|
+
const path120 = docPath(root, sid);
|
|
43658
|
+
if (!existsSync30(path120)) return null;
|
|
43659
43659
|
try {
|
|
43660
|
-
const parsed = JSON.parse(readFileSync37(
|
|
43660
|
+
const parsed = JSON.parse(readFileSync37(path120, "utf-8"));
|
|
43661
43661
|
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;
|
|
43662
43662
|
return parsed;
|
|
43663
43663
|
} catch {
|
|
@@ -43735,11 +43735,11 @@ Merge into the status document per the system contract. Return only the JSON obj
|
|
|
43735
43735
|
}
|
|
43736
43736
|
}
|
|
43737
43737
|
function writeDoc(root, sid, file3) {
|
|
43738
|
-
const
|
|
43739
|
-
mkdirSync23(dirname19(
|
|
43740
|
-
const tmp =
|
|
43738
|
+
const path120 = docPath(root, sid);
|
|
43739
|
+
mkdirSync23(dirname19(path120), { recursive: true });
|
|
43740
|
+
const tmp = path120 + ".tmp";
|
|
43741
43741
|
writeFileSync19(tmp, JSON.stringify(file3), "utf-8");
|
|
43742
|
-
renameSync14(tmp,
|
|
43742
|
+
renameSync14(tmp, path120);
|
|
43743
43743
|
}
|
|
43744
43744
|
var MERGE_MIN_INTERVAL_SEQ, MERGE_FAIL_COOLDOWN_MS, dirPath, docPath, MERGE_SYSTEM;
|
|
43745
43745
|
var init_status_doc = __esm({
|
|
@@ -44298,9 +44298,9 @@ function snapshotFiles(store, request3) {
|
|
|
44298
44298
|
return { path: relative6(root, file3).replace(/\\/g, "/"), digest: digest8 };
|
|
44299
44299
|
}).sort((a, b) => a.path.localeCompare(b.path));
|
|
44300
44300
|
}
|
|
44301
|
-
function ownFilePublication(store, request3,
|
|
44301
|
+
function ownFilePublication(store, request3, path120, version2) {
|
|
44302
44302
|
if (request3.kind !== "skills" && request3.kind !== "profile") return false;
|
|
44303
|
-
const file3 = join55(store.mem7RootPath(),
|
|
44303
|
+
const file3 = join55(store.mem7RootPath(), path120);
|
|
44304
44304
|
let text5;
|
|
44305
44305
|
try {
|
|
44306
44306
|
text5 = readFileSync43(file3, "utf8");
|
|
@@ -44330,9 +44330,9 @@ function assertArtifactFileInputs(store, inputs, publicationVersion) {
|
|
|
44330
44330
|
const current2 = currentInput(store, input.request);
|
|
44331
44331
|
const oldFiles = new Map(input.files.map((file3) => [file3.path, file3.digest]));
|
|
44332
44332
|
const newFiles = new Map(current2.files.map((file3) => [file3.path, file3.digest]));
|
|
44333
|
-
for (const
|
|
44334
|
-
if (oldFiles.get(
|
|
44335
|
-
if (publicationVersion !== void 0 && ownFilePublication(store, input.request,
|
|
44333
|
+
for (const path120 of /* @__PURE__ */ new Set([...oldFiles.keys(), ...newFiles.keys()])) {
|
|
44334
|
+
if (oldFiles.get(path120) === newFiles.get(path120)) continue;
|
|
44335
|
+
if (publicationVersion !== void 0 && ownFilePublication(store, input.request, path120, publicationVersion)) continue;
|
|
44336
44336
|
throw new SupersededJobError("ARTIFACT_FILE_INPUT_CHANGED");
|
|
44337
44337
|
}
|
|
44338
44338
|
const expected = new Map(input.entries.map((entry) => [entry.id, entry.digest]));
|
|
@@ -45797,9 +45797,9 @@ var init_pipeline = __esm({
|
|
|
45797
45797
|
import { appendFileSync as appendFileSync4, existsSync as existsSync31, readFileSync as readFileSync44, readSync as readSync5, writeFileSync as writeFileSync20, writeSync as writeSync2, mkdirSync as mkdirSync24, renameSync as renameSync15, unlinkSync as unlinkSync8, openSync as openSync13, closeSync as closeSync13, fstatSync as fstatSync6, statSync as statSync10, statfsSync } from "node:fs";
|
|
45798
45798
|
import { createHash as createHash43 } from "node:crypto";
|
|
45799
45799
|
import { join as join56, dirname as dirname25 } from "node:path";
|
|
45800
|
-
function fileBytes(
|
|
45800
|
+
function fileBytes(path120) {
|
|
45801
45801
|
try {
|
|
45802
|
-
return statSync10(
|
|
45802
|
+
return statSync10(path120).size;
|
|
45803
45803
|
} catch (error) {
|
|
45804
45804
|
if (error?.code !== "ENOENT") throw error;
|
|
45805
45805
|
return 0;
|
|
@@ -45883,11 +45883,11 @@ function warnIntake(stateDir, message) {
|
|
|
45883
45883
|
}
|
|
45884
45884
|
warnings.set(key6, { at: now2, suppressed: 0 });
|
|
45885
45885
|
}
|
|
45886
|
-
function lockOwnerState(
|
|
45886
|
+
function lockOwnerState(path120) {
|
|
45887
45887
|
let pid;
|
|
45888
45888
|
try {
|
|
45889
|
-
if (fileBytes(
|
|
45890
|
-
pid = Number(readFileSync44(
|
|
45889
|
+
if (fileBytes(path120) > 32) return "alive";
|
|
45890
|
+
pid = Number(readFileSync44(path120, "utf8").trim());
|
|
45891
45891
|
} catch (error) {
|
|
45892
45892
|
if (error?.code === "ENOENT") return "missing";
|
|
45893
45893
|
throw error;
|
|
@@ -45901,15 +45901,15 @@ function lockOwnerState(path119) {
|
|
|
45901
45901
|
}
|
|
45902
45902
|
}
|
|
45903
45903
|
function withSpoolWriteLock(stateDir, operation) {
|
|
45904
|
-
const
|
|
45905
|
-
mkdirSync24(dirname25(
|
|
45904
|
+
const path120 = writeLockPath(stateDir);
|
|
45905
|
+
mkdirSync24(dirname25(path120), { recursive: true });
|
|
45906
45906
|
let fd;
|
|
45907
45907
|
try {
|
|
45908
|
-
fd = openSync13(
|
|
45908
|
+
fd = openSync13(path120, "wx");
|
|
45909
45909
|
} catch (error) {
|
|
45910
45910
|
if (error?.code !== "EEXIST") throw error;
|
|
45911
|
-
if (lockOwnerState(
|
|
45912
|
-
const reaperPath =
|
|
45911
|
+
if (lockOwnerState(path120) === "alive") throw Error("INTAKE_WRITER_BUSY: \u5199\u5165\u8005\u6B63\u5728\u64CD\u4F5C\uFF0C\u672A\u5165\u961F\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5");
|
|
45912
|
+
const reaperPath = path120 + ".reap";
|
|
45913
45913
|
let reaper;
|
|
45914
45914
|
try {
|
|
45915
45915
|
reaper = openSync13(reaperPath, "wx");
|
|
@@ -45918,9 +45918,9 @@ function withSpoolWriteLock(stateDir, operation) {
|
|
|
45918
45918
|
throw Error("INTAKE_WRITER_BUSY: \u5199\u9501\u6062\u590D\u4E2D\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5");
|
|
45919
45919
|
}
|
|
45920
45920
|
try {
|
|
45921
|
-
if (lockOwnerState(
|
|
45921
|
+
if (lockOwnerState(path120) === "dead") unlinkSync8(path120);
|
|
45922
45922
|
try {
|
|
45923
|
-
fd = openSync13(
|
|
45923
|
+
fd = openSync13(path120, "wx");
|
|
45924
45924
|
} catch (error2) {
|
|
45925
45925
|
if (error2?.code !== "EEXIST") throw error2;
|
|
45926
45926
|
throw Error("INTAKE_WRITER_BUSY: \u5199\u5165\u8005\u6B63\u5728\u64CD\u4F5C\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5");
|
|
@@ -45935,11 +45935,11 @@ function withSpoolWriteLock(stateDir, operation) {
|
|
|
45935
45935
|
return operation();
|
|
45936
45936
|
} finally {
|
|
45937
45937
|
closeSync13(fd);
|
|
45938
|
-
unlinkSync8(
|
|
45938
|
+
unlinkSync8(path120);
|
|
45939
45939
|
}
|
|
45940
45940
|
}
|
|
45941
45941
|
function enqueueIntake(stateDir, entry) {
|
|
45942
|
-
const
|
|
45942
|
+
const path120 = spoolPath(stateDir);
|
|
45943
45943
|
const operationId = `${process.pid}:${++operationSequence}`, started = performance.now();
|
|
45944
45944
|
const metrics = producerMetrics.get(stateDir) ?? {
|
|
45945
45945
|
callsTotal: 0,
|
|
@@ -45967,7 +45967,7 @@ function enqueueIntake(stateDir, entry) {
|
|
|
45967
45967
|
for (let attempt = 0; attempt < 3; attempt++) {
|
|
45968
45968
|
if (intakeSpoolStatus(stateDir).pendingBytes + bytes3 > INTAKE_MAX_BYTES)
|
|
45969
45969
|
throw Error("INTAKE_SPOOL_FULL: \u5F85\u6D88\u8D39\u961F\u5217\u8FBE\u523064 MiB\u4E0A\u9650\uFF0C\u505C\u6B62\u8FFD\u52A0\uFF0C\u672C\u6761\u539F\u8BDD\u672A\u5165\u961F\uFF1B\u8BF7\u68C0\u67E5worker\u6D88\u8D39\u72B6\u6001");
|
|
45970
|
-
const fd = openSync13(
|
|
45970
|
+
const fd = openSync13(path120, "a");
|
|
45971
45971
|
try {
|
|
45972
45972
|
const opened = fstatSync6(fd, { bigint: true });
|
|
45973
45973
|
appendAttempts++;
|
|
@@ -45977,7 +45977,7 @@ function enqueueIntake(stateDir, entry) {
|
|
|
45977
45977
|
let currentFd;
|
|
45978
45978
|
let currentIdentity = null;
|
|
45979
45979
|
try {
|
|
45980
|
-
currentFd = openSync13(
|
|
45980
|
+
currentFd = openSync13(path120, "r");
|
|
45981
45981
|
const current2 = fstatSync6(currentFd, { bigint: true });
|
|
45982
45982
|
currentIdentity = fileIdentity(current2);
|
|
45983
45983
|
if (current2.dev === opened.dev && current2.ino === opened.ino) return true;
|
|
@@ -46055,10 +46055,10 @@ function* spoolLines(fd, offset, maxEntries) {
|
|
|
46055
46055
|
position += bytes3;
|
|
46056
46056
|
}
|
|
46057
46057
|
}
|
|
46058
|
-
function readCursor(stateDir,
|
|
46058
|
+
function readCursor(stateDir, path120, identity3, size2) {
|
|
46059
46059
|
try {
|
|
46060
|
-
if (fileBytes(
|
|
46061
|
-
const cursor2 = JSON.parse(readFileSync44(
|
|
46060
|
+
if (fileBytes(path120) > 4096) throw Error("INTAKE_CURSOR_INVALID_SIZE");
|
|
46061
|
+
const cursor2 = JSON.parse(readFileSync44(path120, "utf8"));
|
|
46062
46062
|
if (cursor2.dev === identity3.dev && cursor2.ino === identity3.ino && cursor2.birthtimeNs === identity3.birthtimeNs && Number.isSafeInteger(cursor2.offset) && cursor2.offset >= 0 && cursor2.offset <= size2) return cursor2.offset;
|
|
46063
46063
|
intakeDiagnostic(stateDir, "cursor.replay", { reason: cursor2.dev !== identity3.dev || cursor2.ino !== identity3.ino || cursor2.birthtimeNs !== identity3.birthtimeNs ? "identity_mismatch" : "invalid_offset", batchBytes: size2, identity: identity3 });
|
|
46064
46064
|
} catch (error) {
|
|
@@ -46093,21 +46093,21 @@ function drainIntakeSpool(stateDir, store, maxEntries = 50) {
|
|
|
46093
46093
|
} : {},
|
|
46094
46094
|
elapsedMs: Math.round(performance.now() - started)
|
|
46095
46095
|
});
|
|
46096
|
-
const
|
|
46096
|
+
const path120 = spoolPath(stateDir);
|
|
46097
46097
|
const processing = processingPath(stateDir);
|
|
46098
46098
|
const cursorPath = processing + ".cursor";
|
|
46099
46099
|
try {
|
|
46100
46100
|
withSpoolWriteLock(stateDir, () => {
|
|
46101
46101
|
if (!existsSync31(processing)) {
|
|
46102
|
-
if (!existsSync31(
|
|
46102
|
+
if (!existsSync31(path120) || statSync10(path120).size === 0) return;
|
|
46103
46103
|
try {
|
|
46104
46104
|
unlinkSync8(cursorPath);
|
|
46105
46105
|
} catch (error) {
|
|
46106
46106
|
if (error?.code !== "ENOENT") throw error;
|
|
46107
46107
|
}
|
|
46108
|
-
renameSync15(
|
|
46108
|
+
renameSync15(path120, processing);
|
|
46109
46109
|
}
|
|
46110
|
-
appendFileSync4(
|
|
46110
|
+
appendFileSync4(path120, "", "utf8");
|
|
46111
46111
|
});
|
|
46112
46112
|
if (!existsSync31(processing)) return 0;
|
|
46113
46113
|
} catch (error) {
|
|
@@ -51174,11 +51174,11 @@ async function readLastConsolidatedAt(memoryDir) {
|
|
|
51174
51174
|
}
|
|
51175
51175
|
}
|
|
51176
51176
|
async function tryAcquireConsolidationLock(memoryDir) {
|
|
51177
|
-
const
|
|
51177
|
+
const path120 = lockPath(memoryDir);
|
|
51178
51178
|
let mtimeMs;
|
|
51179
51179
|
let holderPid;
|
|
51180
51180
|
try {
|
|
51181
|
-
const [s, raw] = await Promise.all([stat2(
|
|
51181
|
+
const [s, raw] = await Promise.all([stat2(path120), readFile4(path120, "utf8")]);
|
|
51182
51182
|
mtimeMs = s.mtimeMs;
|
|
51183
51183
|
const parsed = parseInt(raw.trim(), 10);
|
|
51184
51184
|
holderPid = Number.isFinite(parsed) ? parsed : void 0;
|
|
@@ -51191,10 +51191,10 @@ async function tryAcquireConsolidationLock(memoryDir) {
|
|
|
51191
51191
|
}
|
|
51192
51192
|
}
|
|
51193
51193
|
await mkdir4(memoryDir, { recursive: true });
|
|
51194
|
-
await writeFile4(
|
|
51194
|
+
await writeFile4(path120, String(process.pid));
|
|
51195
51195
|
let verify4;
|
|
51196
51196
|
try {
|
|
51197
|
-
verify4 = await readFile4(
|
|
51197
|
+
verify4 = await readFile4(path120, "utf8");
|
|
51198
51198
|
} catch {
|
|
51199
51199
|
return null;
|
|
51200
51200
|
}
|
|
@@ -51202,15 +51202,15 @@ async function tryAcquireConsolidationLock(memoryDir) {
|
|
|
51202
51202
|
return mtimeMs ?? 0;
|
|
51203
51203
|
}
|
|
51204
51204
|
async function rollbackConsolidationLock(memoryDir, priorMtime) {
|
|
51205
|
-
const
|
|
51205
|
+
const path120 = lockPath(memoryDir);
|
|
51206
51206
|
try {
|
|
51207
51207
|
if (priorMtime === 0) {
|
|
51208
|
-
await unlink2(
|
|
51208
|
+
await unlink2(path120);
|
|
51209
51209
|
return;
|
|
51210
51210
|
}
|
|
51211
|
-
await writeFile4(
|
|
51211
|
+
await writeFile4(path120, "");
|
|
51212
51212
|
const t = priorMtime / 1e3;
|
|
51213
|
-
await utimes(
|
|
51213
|
+
await utimes(path120, t, t);
|
|
51214
51214
|
} catch (e) {
|
|
51215
51215
|
console.log(`[autoDream] rollback failed: ${e.message} \u2014 next trigger delayed to minHours`);
|
|
51216
51216
|
}
|
|
@@ -51569,7 +51569,7 @@ var require_email_config = __commonJS({
|
|
|
51569
51569
|
"templates/skills/email/scripts/email-config.js"(exports, module) {
|
|
51570
51570
|
"use strict";
|
|
51571
51571
|
var fs111 = __require("node:fs");
|
|
51572
|
-
var
|
|
51572
|
+
var path120 = __require("node:path");
|
|
51573
51573
|
var PROVIDER_MAP = {
|
|
51574
51574
|
"qq.com": { imap: ["imap.qq.com", 993], smtp: ["smtp.qq.com", 465, true] },
|
|
51575
51575
|
"foxmail.com": { imap: ["imap.qq.com", 993], smtp: ["smtp.qq.com", 465, true] },
|
|
@@ -51597,7 +51597,7 @@ var require_email_config = __commonJS({
|
|
|
51597
51597
|
function resolveEmailConfig(opts = {}) {
|
|
51598
51598
|
const stateDir = opts.stateDir || process.env.ENGINE_STATE_DIR || process.env.ENGINE7_STATE_DIR || null;
|
|
51599
51599
|
const configFilePath = opts.configFilePath || process.env.ENGINE7_CONFIG_FILE || process.env.ENGINE_CONFIG;
|
|
51600
|
-
const configFiles = configFilePath ? [
|
|
51600
|
+
const configFiles = configFilePath ? [path120.resolve(configFilePath)] : stateDir ? [path120.join(stateDir, "configs", "main.json")] : [];
|
|
51601
51601
|
if (configFiles.length) {
|
|
51602
51602
|
for (const p of configFiles) {
|
|
51603
51603
|
try {
|
|
@@ -51632,7 +51632,7 @@ var require_email_config = __commonJS({
|
|
|
51632
51632
|
}
|
|
51633
51633
|
}
|
|
51634
51634
|
}
|
|
51635
|
-
const envFile = opts.envFile ||
|
|
51635
|
+
const envFile = opts.envFile || path120.join(__dirname, "..", ".env");
|
|
51636
51636
|
if (fs111.existsSync(envFile)) {
|
|
51637
51637
|
const parsed = {};
|
|
51638
51638
|
for (const line of fs111.readFileSync(envFile, "utf8").split(/\r?\n/)) {
|
|
@@ -56130,9 +56130,9 @@ async function executeAndDeliver(task, now2, deps) {
|
|
|
56130
56130
|
let filePath2 = promptText.slice(1).trim();
|
|
56131
56131
|
try {
|
|
56132
56132
|
const fs111 = await import("fs");
|
|
56133
|
-
const
|
|
56134
|
-
if (!
|
|
56135
|
-
filePath2 =
|
|
56133
|
+
const path120 = await import("path");
|
|
56134
|
+
if (!path120.isAbsolute(filePath2)) {
|
|
56135
|
+
filePath2 = path120.join(deps.sessions["config"].stateDir, filePath2);
|
|
56136
56136
|
}
|
|
56137
56137
|
promptText = fs111.readFileSync(filePath2, "utf-8");
|
|
56138
56138
|
console.log(`[cron] Loaded prompt from ${filePath2} (${promptText.length} chars)`);
|
|
@@ -56195,15 +56195,15 @@ async function executeAndDeliver(task, now2, deps) {
|
|
|
56195
56195
|
let finalResult = result2;
|
|
56196
56196
|
if (task.postProcess) {
|
|
56197
56197
|
try {
|
|
56198
|
-
const
|
|
56198
|
+
const path120 = await import("path");
|
|
56199
56199
|
const fs111 = await import("fs");
|
|
56200
56200
|
let scriptPath = task.postProcess;
|
|
56201
|
-
if (!
|
|
56202
|
-
scriptPath =
|
|
56201
|
+
if (!path120.isAbsolute(scriptPath)) {
|
|
56202
|
+
scriptPath = path120.join(deps.sessions["config"].stateDir, scriptPath);
|
|
56203
56203
|
}
|
|
56204
|
-
const resultsDirTmp =
|
|
56204
|
+
const resultsDirTmp = path120.join(getStorageDir(), "results");
|
|
56205
56205
|
fs111.mkdirSync(resultsDirTmp, { recursive: true });
|
|
56206
|
-
const inputFile =
|
|
56206
|
+
const inputFile = path120.join(resultsDirTmp, `${task.id}.input.txt`);
|
|
56207
56207
|
fs111.writeFileSync(inputFile, result2, "utf-8");
|
|
56208
56208
|
const { execFile: execFile9 } = await import("child_process");
|
|
56209
56209
|
await new Promise((resolve42) => {
|
|
@@ -56232,10 +56232,10 @@ async function executeAndDeliver(task, now2, deps) {
|
|
|
56232
56232
|
}
|
|
56233
56233
|
try {
|
|
56234
56234
|
const fs111 = await import("fs");
|
|
56235
|
-
const
|
|
56236
|
-
const resultsDir =
|
|
56235
|
+
const path120 = await import("path");
|
|
56236
|
+
const resultsDir = path120.join(getStorageDir(), "results");
|
|
56237
56237
|
fs111.mkdirSync(resultsDir, { recursive: true });
|
|
56238
|
-
const resultFile =
|
|
56238
|
+
const resultFile = path120.join(resultsDir, `${task.id}.json`);
|
|
56239
56239
|
fs111.writeFileSync(resultFile, JSON.stringify({
|
|
56240
56240
|
taskId: task.id,
|
|
56241
56241
|
description: task.description,
|
|
@@ -56569,13 +56569,13 @@ TTL: ${task.expiresAt || "\u6C38\u751F"}` };
|
|
|
56569
56569
|
},
|
|
56570
56570
|
handler: async (args) => {
|
|
56571
56571
|
const fs111 = await import("fs");
|
|
56572
|
-
const
|
|
56573
|
-
const resultsDir =
|
|
56572
|
+
const path120 = await import("path");
|
|
56573
|
+
const resultsDir = path120.join(getStorageDir(), "results");
|
|
56574
56574
|
if (!fs111.existsSync(resultsDir)) {
|
|
56575
56575
|
return { content: "\u6682\u65E0cron\u6267\u884C\u7ED3\u679C" };
|
|
56576
56576
|
}
|
|
56577
56577
|
if (args.task_id) {
|
|
56578
|
-
const file3 =
|
|
56578
|
+
const file3 = path120.join(resultsDir, `${args.task_id}.json`);
|
|
56579
56579
|
if (!fs111.existsSync(file3)) {
|
|
56580
56580
|
return { content: `\u4EFB\u52A1 ${args.task_id} \u6682\u65E0\u6267\u884C\u7ED3\u679C`, isError: true };
|
|
56581
56581
|
}
|
|
@@ -56591,7 +56591,7 @@ ${data.result}` };
|
|
|
56591
56591
|
return { content: "\u6682\u65E0cron\u6267\u884C\u7ED3\u679C" };
|
|
56592
56592
|
}
|
|
56593
56593
|
const results = files.map((f) => {
|
|
56594
|
-
const data = JSON.parse(fs111.readFileSync(
|
|
56594
|
+
const data = JSON.parse(fs111.readFileSync(path120.join(resultsDir, f), "utf-8"));
|
|
56595
56595
|
return `### ${data.description} (${data.taskId.slice(0, 8)})
|
|
56596
56596
|
\u6267\u884C: ${data.executedAt} | \u7B2C${data.runCount}\u6B21
|
|
56597
56597
|
${data.result.slice(0, 500)}${data.result.length > 500 ? "..." : ""}`;
|
|
@@ -58411,10 +58411,10 @@ async function validateLegacyTopicsBackup(state2, directory2, history) {
|
|
|
58411
58411
|
}
|
|
58412
58412
|
const readTree = async (root) => {
|
|
58413
58413
|
for (const entry of await readdir2(unlinked(root), { withFileTypes: true })) {
|
|
58414
|
-
const
|
|
58415
|
-
if (entry.isDirectory()) await readTree(
|
|
58414
|
+
const path120 = unlinked(join96(root, entry.name));
|
|
58415
|
+
if (entry.isDirectory()) await readTree(path120);
|
|
58416
58416
|
else if (entry.isFile()) {
|
|
58417
|
-
const file3 = await open2(
|
|
58417
|
+
const file3 = await open2(path120, "r");
|
|
58418
58418
|
try {
|
|
58419
58419
|
const buffer = Buffer.allocUnsafe(64 * 1024);
|
|
58420
58420
|
while ((await file3.read(buffer)).bytesRead > 0) {
|
|
@@ -58483,9 +58483,9 @@ async function validateCompletedTopicsImport(state2, history) {
|
|
|
58483
58483
|
db2.close();
|
|
58484
58484
|
}
|
|
58485
58485
|
const prose = /* @__PURE__ */ new Map(), idsByHash = /* @__PURE__ */ new Map();
|
|
58486
|
-
const scan = async (
|
|
58487
|
-
for (const entry of await readdir3(unlinked(
|
|
58488
|
-
const file3 = unlinked(join97(
|
|
58486
|
+
const scan = async (path121) => {
|
|
58487
|
+
for (const entry of await readdir3(unlinked(path121), { withFileTypes: true })) {
|
|
58488
|
+
const file3 = unlinked(join97(path121, entry.name));
|
|
58489
58489
|
if (entry.isDirectory()) await scan(file3);
|
|
58490
58490
|
else if (entry.isFile() && entry.name.endsWith(".md")) {
|
|
58491
58491
|
const text5 = await readFile5(file3, "utf8");
|
|
@@ -58521,9 +58521,9 @@ async function validateCompletedTopicsImport(state2, history) {
|
|
|
58521
58521
|
}
|
|
58522
58522
|
}
|
|
58523
58523
|
const loaded2 = await import(lanceSpecifierFor(process.platform, process.arch)), lance = loaded2.connect ? loaded2 : loaded2.default;
|
|
58524
|
-
const
|
|
58525
|
-
if (!existsSync56(
|
|
58526
|
-
const connection = await lance.connect(
|
|
58524
|
+
const path120 = unlinked(join97(root, "index", "lancedb"));
|
|
58525
|
+
if (!existsSync56(path120)) throw new Error("TOPICS_IMPORT_LIVE_VECTORS_MISSING");
|
|
58526
|
+
const connection = await lance.connect(path120), vectorIds = /* @__PURE__ */ new Set();
|
|
58527
58527
|
try {
|
|
58528
58528
|
for (const name of await connection.tableNames()) {
|
|
58529
58529
|
const table = await connection.openTable(name);
|
|
@@ -58662,10 +58662,10 @@ function ensureLoaded(workspace, configIds) {
|
|
|
58662
58662
|
if (!state.blockedUserIds.includes(id3)) state.blockedUserIds.push(id3);
|
|
58663
58663
|
}
|
|
58664
58664
|
}
|
|
58665
|
-
const
|
|
58665
|
+
const path120 = join101(workspace, ".reply-blocklist.json");
|
|
58666
58666
|
try {
|
|
58667
|
-
if (existsSync59(
|
|
58668
|
-
const raw = readFileSync76(
|
|
58667
|
+
if (existsSync59(path120)) {
|
|
58668
|
+
const raw = readFileSync76(path120, "utf-8");
|
|
58669
58669
|
const parsed = JSON.parse(raw);
|
|
58670
58670
|
if (parsed.blockedUserIds) {
|
|
58671
58671
|
for (const id3 of parsed.blockedUserIds) {
|
|
@@ -58681,9 +58681,9 @@ function ensureLoaded(workspace, configIds) {
|
|
|
58681
58681
|
loaded = true;
|
|
58682
58682
|
}
|
|
58683
58683
|
function save2(workspace) {
|
|
58684
|
-
const
|
|
58684
|
+
const path120 = join101(workspace, ".reply-blocklist.json");
|
|
58685
58685
|
try {
|
|
58686
|
-
writeFileSync39(
|
|
58686
|
+
writeFileSync39(path120, JSON.stringify(state, null, 2), "utf-8");
|
|
58687
58687
|
} catch (err) {
|
|
58688
58688
|
console.warn(`[reply-blocklist] Failed to save: ${err.message}`);
|
|
58689
58689
|
}
|
|
@@ -63679,6 +63679,78 @@ var init_wx_query = __esm({
|
|
|
63679
63679
|
}
|
|
63680
63680
|
});
|
|
63681
63681
|
|
|
63682
|
+
// src/mcp/bundled-npx.ts
|
|
63683
|
+
import { existsSync as existsSync76, readFileSync as readFileSync92 } from "node:fs";
|
|
63684
|
+
import { createRequire as createRequire12 } from "node:module";
|
|
63685
|
+
import * as path116 from "node:path";
|
|
63686
|
+
function defaultDeps() {
|
|
63687
|
+
const req = createRequire12(import.meta.url);
|
|
63688
|
+
return {
|
|
63689
|
+
execPath: process.execPath,
|
|
63690
|
+
electron: !!process.versions.electron,
|
|
63691
|
+
resolvePackageJson: (name) => {
|
|
63692
|
+
try {
|
|
63693
|
+
return req.resolve(`${name}/package.json`);
|
|
63694
|
+
} catch {
|
|
63695
|
+
return null;
|
|
63696
|
+
}
|
|
63697
|
+
},
|
|
63698
|
+
exists: existsSync76,
|
|
63699
|
+
readFile: (p) => readFileSync92(p, "utf-8")
|
|
63700
|
+
};
|
|
63701
|
+
}
|
|
63702
|
+
function parseNpxArgs(args) {
|
|
63703
|
+
let i = 0;
|
|
63704
|
+
while (i < args.length && args[i].startsWith("-")) {
|
|
63705
|
+
if (!VALUELESS_FLAGS.has(args[i])) return null;
|
|
63706
|
+
i++;
|
|
63707
|
+
}
|
|
63708
|
+
if (i >= args.length) return null;
|
|
63709
|
+
return { spec: args[i], passthrough: args.slice(i + 1) };
|
|
63710
|
+
}
|
|
63711
|
+
function splitSpec(spec) {
|
|
63712
|
+
const at2 = spec.indexOf("@", spec.startsWith("@") ? 1 : 0);
|
|
63713
|
+
return at2 > 0 ? { name: spec.slice(0, at2), version: spec.slice(at2 + 1) } : { name: spec, version: "" };
|
|
63714
|
+
}
|
|
63715
|
+
function resolveStdioSpawn(c, deps = defaultDeps()) {
|
|
63716
|
+
const asConfigured = { command: c.command, args: c.args ?? [], env: c.env, bundled: null };
|
|
63717
|
+
if (c.type && c.type !== "stdio") return asConfigured;
|
|
63718
|
+
if (!NPX.has(path116.basename(c.command).toLowerCase())) return asConfigured;
|
|
63719
|
+
const parsed = parseNpxArgs(c.args ?? []);
|
|
63720
|
+
if (!parsed) return asConfigured;
|
|
63721
|
+
const { name, version: version2 } = splitSpec(parsed.spec);
|
|
63722
|
+
if (!ANY_VERSION.has(version2)) return asConfigured;
|
|
63723
|
+
const pkgJson = deps.resolvePackageJson(name);
|
|
63724
|
+
if (!pkgJson) return asConfigured;
|
|
63725
|
+
let pkg;
|
|
63726
|
+
try {
|
|
63727
|
+
pkg = JSON.parse(deps.readFile(pkgJson));
|
|
63728
|
+
} catch {
|
|
63729
|
+
return asConfigured;
|
|
63730
|
+
}
|
|
63731
|
+
const bins = pkg.bin;
|
|
63732
|
+
const bin = typeof bins === "string" ? bins : bins && typeof bins === "object" && Object.keys(bins).length === 1 ? Object.values(bins)[0] : void 0;
|
|
63733
|
+
if (typeof bin !== "string" || typeof pkg.version !== "string") return asConfigured;
|
|
63734
|
+
const cli = path116.join(path116.dirname(pkgJson), bin);
|
|
63735
|
+
if (!deps.exists(cli)) return asConfigured;
|
|
63736
|
+
const env = { ...deps.electron ? { ELECTRON_RUN_AS_NODE: "1" } : {}, ...c.env ?? {} };
|
|
63737
|
+
return {
|
|
63738
|
+
command: deps.execPath,
|
|
63739
|
+
args: [cli, ...parsed.passthrough],
|
|
63740
|
+
env: Object.keys(env).length ? env : void 0,
|
|
63741
|
+
bundled: `${name}@${pkg.version}`
|
|
63742
|
+
};
|
|
63743
|
+
}
|
|
63744
|
+
var NPX, VALUELESS_FLAGS, ANY_VERSION;
|
|
63745
|
+
var init_bundled_npx = __esm({
|
|
63746
|
+
"src/mcp/bundled-npx.ts"() {
|
|
63747
|
+
"use strict";
|
|
63748
|
+
NPX = /* @__PURE__ */ new Set(["npx", "npx.cmd"]);
|
|
63749
|
+
VALUELESS_FLAGS = /* @__PURE__ */ new Set(["-y", "--yes", "-q", "--quiet", "--no-install"]);
|
|
63750
|
+
ANY_VERSION = /* @__PURE__ */ new Set(["", "latest", "*", "x"]);
|
|
63751
|
+
}
|
|
63752
|
+
});
|
|
63753
|
+
|
|
63682
63754
|
// src/mcp/manager.ts
|
|
63683
63755
|
var manager_exports = {};
|
|
63684
63756
|
__export(manager_exports, {
|
|
@@ -63686,7 +63758,7 @@ __export(manager_exports, {
|
|
|
63686
63758
|
convertInputSchema: () => convertInputSchema
|
|
63687
63759
|
});
|
|
63688
63760
|
import * as fs110 from "node:fs";
|
|
63689
|
-
import * as
|
|
63761
|
+
import * as path117 from "node:path";
|
|
63690
63762
|
import { Client as Client4 } from "@modelcontextprotocol/sdk/client/index.js";
|
|
63691
63763
|
import { StdioClientTransport } from "@modelcontextprotocol/sdk/client/stdio.js";
|
|
63692
63764
|
import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js";
|
|
@@ -63727,9 +63799,9 @@ function convertInputSchema(inputSchema) {
|
|
|
63727
63799
|
}
|
|
63728
63800
|
function persistBinary(base64Data, mimeType, persistId) {
|
|
63729
63801
|
const ext = mimeType?.split("/")[1] || "bin";
|
|
63730
|
-
const dir =
|
|
63802
|
+
const dir = path117.join(process.env.ENGINE_STATE_DIR || ".engine", "mcp-blobs");
|
|
63731
63803
|
fs110.mkdirSync(dir, { recursive: true });
|
|
63732
|
-
const filepath =
|
|
63804
|
+
const filepath = path117.join(dir, `${persistId}.${ext}`);
|
|
63733
63805
|
try {
|
|
63734
63806
|
const buf = Buffer.from(base64Data, "base64");
|
|
63735
63807
|
fs110.writeFileSync(filepath, buf);
|
|
@@ -63781,6 +63853,7 @@ var init_manager2 = __esm({
|
|
|
63781
63853
|
"src/mcp/manager.ts"() {
|
|
63782
63854
|
"use strict";
|
|
63783
63855
|
init_registry();
|
|
63856
|
+
init_bundled_npx();
|
|
63784
63857
|
CONNECT_TIMEOUT_MS = 3e4;
|
|
63785
63858
|
MAX_RESULT_CHARS = 1e5;
|
|
63786
63859
|
McpManager = class {
|
|
@@ -64004,7 +64077,9 @@ var init_manager2 = __esm({
|
|
|
64004
64077
|
return;
|
|
64005
64078
|
} else {
|
|
64006
64079
|
const c = config;
|
|
64007
|
-
|
|
64080
|
+
const spawn9 = resolveStdioSpawn(c);
|
|
64081
|
+
if (spawn9.bundled) console.log(`[mcp] ${serverName}: \u5F15\u64CE\u81EA\u5E26 ${spawn9.bundled}\uFF0C\u7528\u81EA\u5DF1\u7684 node \u76F4\u63A5\u542F\u52A8\uFF08\u4E0D\u8D70 npx\uFF09`);
|
|
64082
|
+
transport = new StdioClientTransport({ command: spawn9.command, args: spawn9.args, env: spawn9.env, stderr: c.stderr ?? "inherit" });
|
|
64008
64083
|
}
|
|
64009
64084
|
const client2 = new Client4({ name: "openclaw-engine", version: "0.1.0" }, { capabilities: {} });
|
|
64010
64085
|
const timeoutMs = config.connectTimeoutMs ?? CONNECT_TIMEOUT_MS;
|
|
@@ -64065,7 +64140,7 @@ __export(resources_exports, {
|
|
|
64065
64140
|
registerMcpResourceTools: () => registerMcpResourceTools,
|
|
64066
64141
|
unregisterMcpResourceTools: () => unregisterMcpResourceTools
|
|
64067
64142
|
});
|
|
64068
|
-
import * as
|
|
64143
|
+
import * as path118 from "node:path";
|
|
64069
64144
|
function registerMcpResourceTools(manager) {
|
|
64070
64145
|
mcpManagerRef = manager;
|
|
64071
64146
|
registry.register(listResourcesTool);
|
|
@@ -64083,7 +64158,7 @@ var init_resources = __esm({
|
|
|
64083
64158
|
"use strict";
|
|
64084
64159
|
init_registry();
|
|
64085
64160
|
MAX_RESULT_CHARS2 = 1e5;
|
|
64086
|
-
MEDIA_DIR = process.env.ENGINE_MEDIA_DIR ||
|
|
64161
|
+
MEDIA_DIR = process.env.ENGINE_MEDIA_DIR || path118.join(process.env.ENGINE_STATE_DIR || ".engine", "media", "inbound");
|
|
64087
64162
|
MCP_LIST_RESOURCES_TOOL = "mcp__list_resources";
|
|
64088
64163
|
MCP_READ_RESOURCE_TOOL = "mcp__read_resource";
|
|
64089
64164
|
mcpManagerRef = null;
|
|
@@ -64298,7 +64373,7 @@ function installTravelEngineControl(options) {
|
|
|
64298
64373
|
}
|
|
64299
64374
|
|
|
64300
64375
|
// src/engine-startup.ts
|
|
64301
|
-
import * as
|
|
64376
|
+
import * as path119 from "node:path";
|
|
64302
64377
|
|
|
64303
64378
|
// src/tools/notification-receipts.ts
|
|
64304
64379
|
init_execution_guard();
|
|
@@ -64607,9 +64682,9 @@ function relationshipNotifications(store, scope, includeQueued = false) {
|
|
|
64607
64682
|
}
|
|
64608
64683
|
async function appendGroupNoticeIntercept(workspace, entry) {
|
|
64609
64684
|
const { appendFile, mkdir: mkdir8 } = await import("node:fs/promises");
|
|
64610
|
-
const
|
|
64611
|
-
const file3 =
|
|
64612
|
-
await mkdir8(
|
|
64685
|
+
const path120 = await import("node:path");
|
|
64686
|
+
const file3 = path120.join(workspace, "memory", "group-routed-notices.md");
|
|
64687
|
+
await mkdir8(path120.dirname(file3), { recursive: true });
|
|
64613
64688
|
await appendFile(file3, `## ${(/* @__PURE__ */ new Date()).toISOString()} ${entry.noticeId}
|
|
64614
64689
|
- \u6765\u6E90\uFF1A${entry.scopeKey}
|
|
64615
64690
|
- \u60F3\u6295\u5F80\uFF1A${entry.channel} \u7FA4 ${entry.target}
|
|
@@ -67022,7 +67097,7 @@ function syncLiveProviderCopy(cfg, change) {
|
|
|
67022
67097
|
cfg.providers[match[1]].baseUrl = change.after;
|
|
67023
67098
|
}
|
|
67024
67099
|
function residualFromEnv(cfg, migrated) {
|
|
67025
|
-
return planRelayEndpointMigration(cfg).map((change) => change.path).filter((
|
|
67100
|
+
return planRelayEndpointMigration(cfg).map((change) => change.path).filter((path120) => !migrated.has(path120) && !/^providers?\./.test(path120));
|
|
67026
67101
|
}
|
|
67027
67102
|
async function applyRelayEndpointMigration(io) {
|
|
67028
67103
|
const cfg = io.all();
|
|
@@ -67312,13 +67387,13 @@ function sessionStateDir(fileOrDirectory) {
|
|
|
67312
67387
|
return ["sessions", "sessions-cron"].includes(basename14(directory2)) && basename14(dirname30(dirname30(directory2))) === "agents" ? dirname30(dirname30(dirname30(directory2))) : null;
|
|
67313
67388
|
}
|
|
67314
67389
|
function sessionFilePath(stateDir, file3) {
|
|
67315
|
-
const
|
|
67316
|
-
const match = /^agents\/([A-Za-z0-9][A-Za-z0-9_.-]{0,127})\/(sessions|sessions-cron)\/([^/]+)$/.exec(
|
|
67317
|
-
if (!match || /[\x00-\x1f<>:"|?*\\]/.test(
|
|
67390
|
+
const path120 = relative8(stateDir, resolve25(file3)).replace(/\\/g, "/");
|
|
67391
|
+
const match = /^agents\/([A-Za-z0-9][A-Za-z0-9_.-]{0,127})\/(sessions|sessions-cron)\/([^/]+)$/.exec(path120);
|
|
67392
|
+
if (!match || /[\x00-\x1f<>:"|?*\\]/.test(path120) || match[3] === "." || match[3] === ".." || path120.split("/").some((part) => /[. ]$/.test(part) || /^(CON|PRN|AUX|NUL|COM[1-9]|LPT[1-9])(?:\.|$)/i.test(part)))
|
|
67318
67393
|
throw new Error("SESSION_PATH_UNSUPPORTED");
|
|
67319
67394
|
const kind = /\.jsonl(?:\.|$)/.test(match[3]) ? "jsonl" : "blob";
|
|
67320
67395
|
const id3 = kind === "jsonl" ? match[3].replace(/\.jsonl(?:\..*)?$/, "") : match[3];
|
|
67321
|
-
return { path:
|
|
67396
|
+
return { path: path120, key: `agents/${match[1]}/${match[2] === "sessions-cron" ? "cron/" : ""}${id3}`, kind };
|
|
67322
67397
|
}
|
|
67323
67398
|
function syncSessionDirectory(directory2) {
|
|
67324
67399
|
if (process.platform === "win32") return;
|
|
@@ -67343,14 +67418,14 @@ function prepareSessionDirectory(directory2) {
|
|
|
67343
67418
|
parent = dirname30(parent);
|
|
67344
67419
|
}
|
|
67345
67420
|
if (realpathSync9(parent) !== parent || !lstatSync12(parent).isDirectory()) throw new Error("SESSION_SYMLINK_REFUSED");
|
|
67346
|
-
for (const
|
|
67421
|
+
for (const path120 of missing.reverse()) {
|
|
67347
67422
|
try {
|
|
67348
|
-
mkdirSync29(
|
|
67423
|
+
mkdirSync29(path120, { mode: 448 });
|
|
67349
67424
|
} catch (error) {
|
|
67350
67425
|
if (error.code !== "EEXIST") throw error;
|
|
67351
67426
|
}
|
|
67352
|
-
if (!lstatSync12(
|
|
67353
|
-
syncSessionDirectory(dirname30(
|
|
67427
|
+
if (!lstatSync12(path120).isDirectory() || realpathSync9(path120) !== path120) throw new Error("SESSION_SYMLINK_REFUSED");
|
|
67428
|
+
syncSessionDirectory(dirname30(path120));
|
|
67354
67429
|
}
|
|
67355
67430
|
}
|
|
67356
67431
|
function sessionFileSignature(file3) {
|
|
@@ -67369,8 +67444,8 @@ function frameBytes(row) {
|
|
|
67369
67444
|
if (createHash46("sha256").update(bytes3).digest("hex") !== row.digest) throw new Error("SESSION_EVENT_CORRUPT");
|
|
67370
67445
|
return bytes3;
|
|
67371
67446
|
}
|
|
67372
|
-
function mapSessionIndex(bytes3, _db,
|
|
67373
|
-
if (basename14(
|
|
67447
|
+
function mapSessionIndex(bytes3, _db, path120, stateDir, sourceRoot, targetRoot) {
|
|
67448
|
+
if (basename14(path120) !== "session-index.json") return bytes3;
|
|
67374
67449
|
let index;
|
|
67375
67450
|
try {
|
|
67376
67451
|
index = JSON.parse(bytes3.toString("utf8"));
|
|
@@ -67389,30 +67464,30 @@ function mapSessionIndex(bytes3, _db, path119, stateDir, sourceRoot, targetRoot)
|
|
|
67389
67464
|
}
|
|
67390
67465
|
return Buffer.from(JSON.stringify(index, null, 2));
|
|
67391
67466
|
}
|
|
67392
|
-
function canonicalSessionIndex(bytes3, db2,
|
|
67393
|
-
return mapSessionIndex(bytes3, db2,
|
|
67467
|
+
function canonicalSessionIndex(bytes3, db2, path120, sourceRoot, stateDir) {
|
|
67468
|
+
return mapSessionIndex(bytes3, db2, path120, stateDir, sourceRoot, sourceRoot);
|
|
67394
67469
|
}
|
|
67395
|
-
function portableIndex(bytes3, db2,
|
|
67470
|
+
function portableIndex(bytes3, db2, path120, sourceRoot, destination) {
|
|
67396
67471
|
if (sourceRoot === destination) return bytes3;
|
|
67397
|
-
return mapSessionIndex(bytes3, db2,
|
|
67472
|
+
return mapSessionIndex(bytes3, db2, path120, destination, sourceRoot, destination);
|
|
67398
67473
|
}
|
|
67399
|
-
function projectSessionFile(db2, cursors, stateDir,
|
|
67400
|
-
sessionFilePath(stateDir, join66(stateDir,
|
|
67401
|
-
const record = db2.prepare("SELECT * FROM session_files WHERE path=?").get(
|
|
67474
|
+
function projectSessionFile(db2, cursors, stateDir, path120, sourceRoot) {
|
|
67475
|
+
sessionFilePath(stateDir, join66(stateDir, path120));
|
|
67476
|
+
const record = db2.prepare("SELECT * FROM session_files WHERE path=?").get(path120);
|
|
67402
67477
|
if (!record) throw new Error("SESSION_FILE_NOT_REGISTERED");
|
|
67403
|
-
const file3 = join66(stateDir,
|
|
67478
|
+
const file3 = join66(stateDir, path120), signature2 = sessionFileSignature(file3);
|
|
67404
67479
|
prepareSessionDirectory(dirname30(file3));
|
|
67405
67480
|
if (record.state === "removed") {
|
|
67406
67481
|
if (signature2 !== null) {
|
|
67407
67482
|
unlinkSync10(file3);
|
|
67408
67483
|
syncSessionDirectory(dirname30(file3));
|
|
67409
67484
|
}
|
|
67410
|
-
cursors.prepare("DELETE FROM cursors WHERE path=?").run(
|
|
67485
|
+
cursors.prepare("DELETE FROM cursors WHERE path=?").run(path120);
|
|
67411
67486
|
return;
|
|
67412
67487
|
}
|
|
67413
67488
|
if (record.state !== "active" || !["jsonl", "blob"].includes(String(record.kind))) throw new Error("SESSION_FILE_CORRUPT");
|
|
67414
|
-
const count = Number(db2.prepare("SELECT count(*) n FROM session_file_events WHERE path=?").get(
|
|
67415
|
-
const cursor2 = cursors.prepare("SELECT * FROM cursors WHERE path=?").get(
|
|
67489
|
+
const count = Number(db2.prepare("SELECT count(*) n FROM session_file_events WHERE path=?").get(path120).n);
|
|
67490
|
+
const cursor2 = cursors.prepare("SELECT * FROM cursors WHERE path=?").get(path120);
|
|
67416
67491
|
const incremental = record.kind === "jsonl" && cursor2 && cursor2.generation === record.generation && cursor2.signature === signature2 && Number(cursor2.frames) <= count;
|
|
67417
67492
|
if (incremental && cursor2.revision === record.revision && Number(cursor2.frames) === count) return;
|
|
67418
67493
|
const temp = join66(dirname30(file3), ".session-" + randomUUID24() + ".partial");
|
|
@@ -67422,13 +67497,13 @@ function projectSessionFile(db2, cursors, stateDir, path119, sourceRoot) {
|
|
|
67422
67497
|
fd = openSync15(target, (incremental ? constants6.O_WRONLY | constants6.O_APPEND : constants6.O_WRONLY | constants6.O_CREAT | constants6.O_EXCL) | (constants6.O_NOFOLLOW ?? 0), 384);
|
|
67423
67498
|
let frames2 = start;
|
|
67424
67499
|
const rows = db2.prepare(`SELECT f.ordinal,e.body,e.digest FROM session_file_events f JOIN session_events e ON e.sequence=f.event_sequence
|
|
67425
|
-
WHERE f.path=? AND f.ordinal>? ORDER BY f.ordinal`).iterate(
|
|
67500
|
+
WHERE f.path=? AND f.ordinal>? ORDER BY f.ordinal`).iterate(path120, start);
|
|
67426
67501
|
for (const row of rows) {
|
|
67427
67502
|
if (Number(row.ordinal) !== ++frames2) throw new Error("SESSION_FILE_EVENT_GAP");
|
|
67428
67503
|
let body2 = frameBytes(row);
|
|
67429
67504
|
if (record.kind === "blob") {
|
|
67430
67505
|
if (count !== 1) throw new Error("SESSION_FILE_CORRUPT");
|
|
67431
|
-
body2 = portableIndex(body2, db2,
|
|
67506
|
+
body2 = portableIndex(body2, db2, path120, sourceRoot, stateDir);
|
|
67432
67507
|
}
|
|
67433
67508
|
appendFileSync5(fd, body2);
|
|
67434
67509
|
}
|
|
@@ -67442,7 +67517,7 @@ function projectSessionFile(db2, cursors, stateDir, path119, sourceRoot) {
|
|
|
67442
67517
|
if (after === null || !after.startsWith(`${info.dev}:${info.ino}:${info.size}:`)) throw new Error("SESSION_PROJECTION_CHANGED");
|
|
67443
67518
|
syncSessionDirectory(dirname30(file3));
|
|
67444
67519
|
cursors.prepare(`INSERT INTO cursors VALUES(?,?,?,?,?) ON CONFLICT(path) DO UPDATE SET generation=excluded.generation,
|
|
67445
|
-
revision=excluded.revision,frames=excluded.frames,signature=excluded.signature`).run(
|
|
67520
|
+
revision=excluded.revision,frames=excluded.frames,signature=excluded.signature`).run(path120, record.generation, record.revision, count, after);
|
|
67446
67521
|
complete = true;
|
|
67447
67522
|
} finally {
|
|
67448
67523
|
if (fd !== void 0) closeSync15(fd);
|
|
@@ -67476,10 +67551,10 @@ function privateDatabase(file3, create) {
|
|
|
67476
67551
|
prepareSessionDirectory(dirname31(file3));
|
|
67477
67552
|
const directory2 = lstatSync13(dirname31(file3));
|
|
67478
67553
|
if (process.platform !== "win32" && (directory2.mode & 63 || directory2.uid !== process.getuid())) throw new Error("SESSION_PRIVATE_CONTROL_REQUIRED");
|
|
67479
|
-
for (const
|
|
67554
|
+
for (const path120 of [file3, file3 + "-journal", file3 + "-wal", file3 + "-shm"]) {
|
|
67480
67555
|
try {
|
|
67481
|
-
const info = lstatSync13(
|
|
67482
|
-
if (!info.isFile() || info.isSymbolicLink() || realpathSync10(
|
|
67556
|
+
const info = lstatSync13(path120);
|
|
67557
|
+
if (!info.isFile() || info.isSymbolicLink() || realpathSync10(path120) !== resolve26(path120) || process.platform !== "win32" && (info.mode & 63 || info.uid !== process.getuid())) throw new Error("SESSION_PRIVATE_CONTROL_REQUIRED");
|
|
67483
67558
|
} catch (error) {
|
|
67484
67559
|
if (error.code !== "ENOENT") throw error;
|
|
67485
67560
|
}
|
|
@@ -67623,8 +67698,8 @@ var SessionEventStore = class {
|
|
|
67623
67698
|
}
|
|
67624
67699
|
return null;
|
|
67625
67700
|
}
|
|
67626
|
-
projectPath(
|
|
67627
|
-
projectSessionFile(this.db, this.cursors, this.stateDir,
|
|
67701
|
+
projectPath(path120) {
|
|
67702
|
+
projectSessionFile(this.db, this.cursors, this.stateDir, path120, this.sourceRoot);
|
|
67628
67703
|
}
|
|
67629
67704
|
project(file3) {
|
|
67630
67705
|
this.locked(() => this.projectPath(sessionFilePath(this.stateDir, file3).path));
|
|
@@ -69688,18 +69763,18 @@ var queryModeWatchers = /* @__PURE__ */ new Map();
|
|
|
69688
69763
|
var backgroundRecalls = /* @__PURE__ */ new Map();
|
|
69689
69764
|
var externalChanRulesCache = null;
|
|
69690
69765
|
function loadExternalChanRules(workspace) {
|
|
69691
|
-
const
|
|
69692
|
-
if (externalChanRulesCache && externalChanRulesCache.path ===
|
|
69766
|
+
const path120 = join80(workspace, "prompts", "external-chan-rules.md");
|
|
69767
|
+
if (externalChanRulesCache && externalChanRulesCache.path === path120) return externalChanRulesCache;
|
|
69693
69768
|
let content = "";
|
|
69694
|
-
if (existsSync48(
|
|
69769
|
+
if (existsSync48(path120)) {
|
|
69695
69770
|
try {
|
|
69696
|
-
content = readFileSync63(
|
|
69771
|
+
content = readFileSync63(path120, "utf-8").trim();
|
|
69697
69772
|
} catch (e) {
|
|
69698
69773
|
console.warn(`[external-chan-rules] Failed to load: ${e}`);
|
|
69699
69774
|
}
|
|
69700
69775
|
}
|
|
69701
|
-
externalChanRulesCache = { path:
|
|
69702
|
-
console.log(`[external-chan-rules] Loaded ${content.length} chars from ${
|
|
69776
|
+
externalChanRulesCache = { path: path120, content };
|
|
69777
|
+
console.log(`[external-chan-rules] Loaded ${content.length} chars from ${path120}`);
|
|
69703
69778
|
return externalChanRulesCache;
|
|
69704
69779
|
}
|
|
69705
69780
|
function getExternalChanRulesBlock(inboundMeta, workspace) {
|
|
@@ -69866,7 +69941,7 @@ async function handleQueryInner(text5, sessionId, channelName, cb, deps, channel
|
|
|
69866
69941
|
);
|
|
69867
69942
|
console.log(`[query-prep] steer inputs restored (${Date.now() - prepT0}ms)`);
|
|
69868
69943
|
const preserveSnapshots = liveConfig.get("mem7.enabled") === true;
|
|
69869
|
-
const removedRecall = stripRecalledMemories(history, (
|
|
69944
|
+
const removedRecall = stripRecalledMemories(history, (path120, memory) => isCurrentMemoryContextPath(path120) && (!preserveSnapshots || !memory.snapshotProof));
|
|
69870
69945
|
if (removedRecall > 0) console.log(`[handle-query] Removed ${removedRecall} cached recall entries before this round`);
|
|
69871
69946
|
for (const p of sessions2.getRestoredRecallPaths(sessionId)) {
|
|
69872
69947
|
if (isCurrentMemoryContextPath(p)) sessions2.getRestoredRecallPaths(sessionId).delete(p);
|
|
@@ -77412,23 +77487,23 @@ function coerceFieldValue(field, value) {
|
|
|
77412
77487
|
async function applyConfigValues(values) {
|
|
77413
77488
|
const applied = [];
|
|
77414
77489
|
const rejected = [];
|
|
77415
|
-
for (const [
|
|
77490
|
+
for (const [path120, value] of Object.entries(values)) {
|
|
77416
77491
|
if (value === null || value === void 0) continue;
|
|
77417
|
-
const field = getField(
|
|
77492
|
+
const field = getField(path120);
|
|
77418
77493
|
if (!field) {
|
|
77419
|
-
rejected.push({ path:
|
|
77494
|
+
rejected.push({ path: path120, error: "\u672A\u6CE8\u518C\u7684\u914D\u7F6E\u9879\uFF08\u53EA\u80FD\u5199 registry \u58F0\u660E\u8FC7\u7684\u5B57\u6BB5\uFF09" });
|
|
77420
77495
|
continue;
|
|
77421
77496
|
}
|
|
77422
77497
|
const c = coerceFieldValue(field, value);
|
|
77423
77498
|
if (c.error) {
|
|
77424
|
-
rejected.push({ path:
|
|
77499
|
+
rejected.push({ path: path120, error: c.error });
|
|
77425
77500
|
continue;
|
|
77426
77501
|
}
|
|
77427
77502
|
try {
|
|
77428
|
-
await liveConfig.set(
|
|
77429
|
-
applied.push({ path:
|
|
77503
|
+
await liveConfig.set(path120, c.value);
|
|
77504
|
+
applied.push({ path: path120, effect: field.effect });
|
|
77430
77505
|
} catch (e) {
|
|
77431
|
-
rejected.push({ path:
|
|
77506
|
+
rejected.push({ path: path120, error: e.message });
|
|
77432
77507
|
}
|
|
77433
77508
|
}
|
|
77434
77509
|
return { applied, rejected };
|
|
@@ -78233,12 +78308,12 @@ async function startHttpApi(ctx) {
|
|
|
78233
78308
|
if (!consoleAllowed(req)) return deny(res);
|
|
78234
78309
|
try {
|
|
78235
78310
|
const fs111 = await import("node:fs");
|
|
78236
|
-
const
|
|
78237
|
-
const logsDir =
|
|
78311
|
+
const path120 = await import("node:path");
|
|
78312
|
+
const logsDir = path120.join(String(config.stateDir ?? ""), "logs");
|
|
78238
78313
|
const files = fs111.existsSync(logsDir) ? fs111.readdirSync(logsDir).filter((f) => /^engine-\d{4}-\d{2}-\d{2}\.log$/.test(f)).sort() : [];
|
|
78239
78314
|
const lines = [];
|
|
78240
78315
|
if (files.length) {
|
|
78241
|
-
const raw = fs111.readFileSync(
|
|
78316
|
+
const raw = fs111.readFileSync(path120.join(logsDir, files[files.length - 1]), "utf-8").split(/\r?\n/).filter((l) => l.length > 0);
|
|
78242
78317
|
lines.push(...raw.slice(-300));
|
|
78243
78318
|
}
|
|
78244
78319
|
res.writeHead(200, { "Content-Type": "application/json" });
|
|
@@ -79940,8 +80015,8 @@ function openPhysicalMaintenanceDatabase(file3, stateDir) {
|
|
|
79940
80015
|
}
|
|
79941
80016
|
|
|
79942
80017
|
// src/mem7/sqlite-maintenance-worker.ts
|
|
79943
|
-
function intakePendingForDatabase(
|
|
79944
|
-
const spool = join98(dirname40(dirname40(
|
|
80018
|
+
function intakePendingForDatabase(path120) {
|
|
80019
|
+
const spool = join98(dirname40(dirname40(path120)), "spool");
|
|
79945
80020
|
return ["intake.jsonl", "intake.processing.jsonl"].some((name) => {
|
|
79946
80021
|
try {
|
|
79947
80022
|
return statSync21(join98(spool, name)).size > 0;
|
|
@@ -79951,22 +80026,22 @@ function intakePendingForDatabase(path119) {
|
|
|
79951
80026
|
}
|
|
79952
80027
|
});
|
|
79953
80028
|
}
|
|
79954
|
-
var bytes = (
|
|
80029
|
+
var bytes = (path120) => {
|
|
79955
80030
|
try {
|
|
79956
|
-
return statSync21(
|
|
80031
|
+
return statSync21(path120).size;
|
|
79957
80032
|
} catch (e) {
|
|
79958
80033
|
if (e.code !== "ENOENT") throw e;
|
|
79959
80034
|
return 0;
|
|
79960
80035
|
}
|
|
79961
80036
|
};
|
|
79962
|
-
async function runSqlitePhysicalMaintenance(
|
|
80037
|
+
async function runSqlitePhysicalMaintenance(path120, options = {}) {
|
|
79963
80038
|
const minimum = options.minFreeBytes ?? 32 * 1024 * 1024, ratio = options.minFreeRatio ?? 0.05;
|
|
79964
80039
|
if (!Number.isFinite(minimum) || minimum < 0 || !Number.isFinite(ratio) || ratio < 0 || ratio > 1) throw new Error("INVALID_SQLITE_RETENTION_THRESHOLD");
|
|
79965
|
-
const before = bytes(
|
|
79966
|
-
const allowed = () => options.shouldRun?.() !== false && !intakePendingForDatabase(
|
|
79967
|
-
const db2 = openPhysicalMaintenanceDatabase(
|
|
80040
|
+
const before = bytes(path120) + bytes(path120 + "-wal"), started = performance.now();
|
|
80041
|
+
const allowed = () => options.shouldRun?.() !== false && !intakePendingForDatabase(path120);
|
|
80042
|
+
const db2 = openPhysicalMaintenanceDatabase(path120, options.stateDir);
|
|
79968
80043
|
let mode = "bootstrap";
|
|
79969
|
-
const report = (state2) => ({ state: state2, mode, reclaimedBytes: Math.max(0, before - bytes(
|
|
80044
|
+
const report = (state2) => ({ state: state2, mode, reclaimedBytes: Math.max(0, before - bytes(path120) - bytes(path120 + "-wal")) });
|
|
79970
80045
|
try {
|
|
79971
80046
|
db2.exec("PRAGMA busy_timeout=0");
|
|
79972
80047
|
mode = Number(db2.prepare("PRAGMA auto_vacuum").get().auto_vacuum) === 2 ? "incremental" : "bootstrap";
|
|
@@ -79976,10 +80051,10 @@ async function runSqlitePhysicalMaintenance(path119, options = {}) {
|
|
|
79976
80051
|
const pageSize = Number(db2.prepare("PRAGMA page_size").get().page_size);
|
|
79977
80052
|
const pages = Number(db2.prepare("PRAGMA page_count").get().page_count);
|
|
79978
80053
|
const free = Number(db2.prepare("PRAGMA freelist_count").get().freelist_count);
|
|
79979
|
-
const oversized = bytes(
|
|
80054
|
+
const oversized = bytes(path120) > pages * pageSize + 1024 * 1024;
|
|
79980
80055
|
if (!oversized && (free * pageSize < minimum || free / Math.max(1, pages) < ratio)) return report("idle");
|
|
79981
80056
|
if (mode === "bootstrap" || oversized) {
|
|
79982
|
-
const disk = statfsSync2(dirname40(
|
|
80057
|
+
const disk = statfsSync2(dirname40(path120));
|
|
79983
80058
|
if (disk.bavail * disk.bsize < (pages - free) * pageSize * 2 + 64 * 1024 * 1024) return report("deferred");
|
|
79984
80059
|
if (!allowed()) return report("deferred");
|
|
79985
80060
|
options.onPhase?.("vacuum");
|
|
@@ -79998,7 +80073,7 @@ async function runSqlitePhysicalMaintenance(path119, options = {}) {
|
|
|
79998
80073
|
}
|
|
79999
80074
|
const finalCheckpoint = db2.prepare("PRAGMA wal_checkpoint(TRUNCATE)").get();
|
|
80000
80075
|
const finalPages = Number(db2.prepare("PRAGMA page_count").get().page_count);
|
|
80001
|
-
if (finalCheckpoint.busy || bytes(
|
|
80076
|
+
if (finalCheckpoint.busy || bytes(path120) > finalPages * pageSize + 1024 * 1024) return report("deferred");
|
|
80002
80077
|
return report("complete");
|
|
80003
80078
|
} catch (error) {
|
|
80004
80079
|
if (/database is locked|SQLITE_BUSY|SQLITE_LOCKED/i.test(String(error))) return report("deferred");
|
|
@@ -80009,9 +80084,9 @@ async function runSqlitePhysicalMaintenance(path119, options = {}) {
|
|
|
80009
80084
|
}
|
|
80010
80085
|
if (process.argv.includes("--sqlite-checkpoint")) {
|
|
80011
80086
|
const flag = process.argv.indexOf("--sqlite-checkpoint");
|
|
80012
|
-
const
|
|
80087
|
+
const path120 = process.argv[flag + 1], stateDir = process.argv[flag + 2];
|
|
80013
80088
|
registerRuntimeWriter(stateDir, "sqlite-checkpoint");
|
|
80014
|
-
const db2 = openPhysicalMaintenanceDatabase(
|
|
80089
|
+
const db2 = openPhysicalMaintenanceDatabase(path120, stateDir);
|
|
80015
80090
|
try {
|
|
80016
80091
|
db2.exec("PRAGMA busy_timeout=15000");
|
|
80017
80092
|
console.log("wal checkpoint " + JSON.stringify(db2.prepare("PRAGMA wal_checkpoint(TRUNCATE)").get()));
|
|
@@ -80023,7 +80098,7 @@ if (process.argv.includes("--sqlite-checkpoint")) {
|
|
|
80023
80098
|
}
|
|
80024
80099
|
}
|
|
80025
80100
|
if (process.argv.includes("--sqlite-maintenance")) {
|
|
80026
|
-
const flag = process.argv.indexOf("--sqlite-maintenance"),
|
|
80101
|
+
const flag = process.argv.indexOf("--sqlite-maintenance"), path120 = resolve36(process.argv[flag + 1] ?? "");
|
|
80027
80102
|
if (!process.argv[flag + 1]) throw new Error("SQLITE_MAINTENANCE_PATH_REQUIRED");
|
|
80028
80103
|
const config = process.argv[flag + 2] ? JSON.parse(process.argv[flag + 2]) : {};
|
|
80029
80104
|
if (!config.stateDir) throw new Error("SQLITE_MAINTENANCE_STATE_DIR_REQUIRED");
|
|
@@ -80043,9 +80118,9 @@ if (process.argv.includes("--sqlite-maintenance")) {
|
|
|
80043
80118
|
}
|
|
80044
80119
|
if (cancel) process.kill(process.pid, 'SIGTERM')
|
|
80045
80120
|
}, 100)
|
|
80046
|
-
`, { eval: true, workerData: { path:
|
|
80121
|
+
`, { eval: true, workerData: { path: path120, ownerPid: process.connected ? process.ppid : null } });
|
|
80047
80122
|
try {
|
|
80048
|
-
console.log(JSON.stringify(await runSqlitePhysicalMaintenance(
|
|
80123
|
+
console.log(JSON.stringify(await runSqlitePhysicalMaintenance(path120, {
|
|
80049
80124
|
...config,
|
|
80050
80125
|
onPhase: (phase) => {
|
|
80051
80126
|
if (process.connected) process.send?.({ type: "sqliteMaintenancePhase", phase });
|
|
@@ -80087,9 +80162,9 @@ if (process.argv.includes("--validate-topics-import-live")) {
|
|
|
80087
80162
|
}
|
|
80088
80163
|
|
|
80089
80164
|
// src/bg/sqlite-maintenance.ts
|
|
80090
|
-
var size = (
|
|
80165
|
+
var size = (path120) => {
|
|
80091
80166
|
try {
|
|
80092
|
-
return statSync22(
|
|
80167
|
+
return statSync22(path120).size;
|
|
80093
80168
|
} catch (error) {
|
|
80094
80169
|
if (error.code !== "ENOENT") throw error;
|
|
80095
80170
|
return 0;
|
|
@@ -80104,7 +80179,7 @@ function live2(pid) {
|
|
|
80104
80179
|
}
|
|
80105
80180
|
}
|
|
80106
80181
|
function createSqliteMaintenance(stateDir, options = {}) {
|
|
80107
|
-
const
|
|
80182
|
+
const path120 = join99(stateDir, "mem7", "index", "mem7.db"), marker = join99(stateDir, "mem7", "index", ".sqlite-maintenance.json");
|
|
80108
80183
|
let child, completion, timer;
|
|
80109
80184
|
let nextCheck = Date.now() + (options.firstRunDelayMs ?? 18e4), stopped = false;
|
|
80110
80185
|
const idle = options.idleMs ?? 6e4;
|
|
@@ -80126,12 +80201,12 @@ function createSqliteMaintenance(stateDir, options = {}) {
|
|
|
80126
80201
|
const poll = () => {
|
|
80127
80202
|
try {
|
|
80128
80203
|
if (child) {
|
|
80129
|
-
if (stopped || intakePendingForDatabase(
|
|
80204
|
+
if (stopped || intakePendingForDatabase(path120) || options.shouldRun?.() === false) void interrupt();
|
|
80130
80205
|
return;
|
|
80131
80206
|
}
|
|
80132
80207
|
if (stopped || Date.now() < nextCheck || options.shouldRun?.() === false) return;
|
|
80133
80208
|
nextCheck = Date.now() + (options.checkIntervalMs ?? 6e4);
|
|
80134
|
-
if (!existsSync57(
|
|
80209
|
+
if (!existsSync57(path120) || intakePendingForDatabase(path120)) return;
|
|
80135
80210
|
if (Date.now() - lastRequest < idle) return;
|
|
80136
80211
|
if (existsSync57(marker)) {
|
|
80137
80212
|
let previous;
|
|
@@ -80142,14 +80217,14 @@ function createSqliteMaintenance(stateDir, options = {}) {
|
|
|
80142
80217
|
if (Number.isSafeInteger(previous?.pid) && previous.pid > 0 && live2(previous.pid) && Number.isSafeInteger(previous.startedAt) && Date.now() - previous.startedAt < 24e4) return;
|
|
80143
80218
|
unlinkSync17(marker);
|
|
80144
80219
|
}
|
|
80145
|
-
const db2 = new DatabaseSync21(
|
|
80220
|
+
const db2 = new DatabaseSync21(path120, { readOnly: true });
|
|
80146
80221
|
let eligible = false;
|
|
80147
80222
|
try {
|
|
80148
80223
|
db2.exec("PRAGMA query_only=ON");
|
|
80149
80224
|
const pageSize = Number(db2.prepare("PRAGMA page_size").get().page_size);
|
|
80150
80225
|
const pages = Number(db2.prepare("PRAGMA page_count").get().page_count);
|
|
80151
80226
|
const free = Number(db2.prepare("PRAGMA freelist_count").get().freelist_count);
|
|
80152
|
-
eligible = free * pageSize >= (options.minFreeBytes ?? 32 * 1024 * 1024) && free / Math.max(1, pages) >= 0.05 || size(
|
|
80227
|
+
eligible = free * pageSize >= (options.minFreeBytes ?? 32 * 1024 * 1024) && free / Math.max(1, pages) >= 0.05 || size(path120) > pages * pageSize + 1024 * 1024 || size(path120 + "-wal") >= 32 * 1024 * 1024;
|
|
80153
80228
|
} finally {
|
|
80154
80229
|
db2.close();
|
|
80155
80230
|
}
|
|
@@ -80162,7 +80237,7 @@ function createSqliteMaintenance(stateDir, options = {}) {
|
|
|
80162
80237
|
windowsHide: true,
|
|
80163
80238
|
execArgv: entry.endsWith(".ts") ? ["--import", "tsx"] : []
|
|
80164
80239
|
};
|
|
80165
|
-
child = fork3(entry, ["--sqlite-maintenance",
|
|
80240
|
+
child = fork3(entry, ["--sqlite-maintenance", path120, JSON.stringify({ stateDir, minFreeBytes: options.minFreeBytes })], launchOptions);
|
|
80166
80241
|
console.log("[bg-worker] SQLite physical reclaim started");
|
|
80167
80242
|
const current2 = child;
|
|
80168
80243
|
let output = "", errors = "";
|
|
@@ -83738,11 +83813,11 @@ var DiscordAdapter = class _DiscordAdapter {
|
|
|
83738
83813
|
/** 发送媒体附件(图片/文件/音频)— discord.js channel.send({ files }) */
|
|
83739
83814
|
async sendFile(target, message, attachment) {
|
|
83740
83815
|
const fs111 = await import("node:fs");
|
|
83741
|
-
const
|
|
83816
|
+
const path120 = await import("node:path");
|
|
83742
83817
|
if (!fs111.existsSync(attachment.path)) {
|
|
83743
83818
|
throw new Error(`File not found: ${attachment.path}`);
|
|
83744
83819
|
}
|
|
83745
|
-
const filename = attachment.filename ||
|
|
83820
|
+
const filename = attachment.filename || path120.basename(attachment.path);
|
|
83746
83821
|
const fileBuffer = fs111.readFileSync(attachment.path);
|
|
83747
83822
|
const filePayload = {
|
|
83748
83823
|
attachment: fileBuffer,
|
|
@@ -84359,11 +84434,11 @@ var FeishuAdapter = class _FeishuAdapter {
|
|
|
84359
84434
|
/** 发送媒体附件(图片/文件) */
|
|
84360
84435
|
async sendFile(target, message, attachment) {
|
|
84361
84436
|
const fs111 = await import("node:fs");
|
|
84362
|
-
const
|
|
84437
|
+
const path120 = await import("node:path");
|
|
84363
84438
|
if (!fs111.existsSync(attachment.path)) {
|
|
84364
84439
|
throw new Error(`File not found: ${attachment.path}`);
|
|
84365
84440
|
}
|
|
84366
|
-
const filename = attachment.filename ||
|
|
84441
|
+
const filename = attachment.filename || path120.basename(attachment.path);
|
|
84367
84442
|
const fileBuffer = fs111.readFileSync(attachment.path);
|
|
84368
84443
|
const safeTarget = target || this.config.defaultTarget || "";
|
|
84369
84444
|
if (!safeTarget) throw new Error("Feishu sendFile: no target (\u4E3B\u52A8\u53D1\u9001\u9700\u914D\u7F6E defaultTarget \u6216\u4F20\u5165 target)");
|
|
@@ -86752,10 +86827,10 @@ var DeskBuddyAdapter = class {
|
|
|
86752
86827
|
if (!this.historyFile) {
|
|
86753
86828
|
const os15 = __require("os");
|
|
86754
86829
|
const fs112 = __require("fs");
|
|
86755
|
-
const
|
|
86756
|
-
const dir =
|
|
86830
|
+
const path120 = __require("path");
|
|
86831
|
+
const dir = path120.join(os15.homedir(), "xiaowen", "workspace", ".desktopBuddy");
|
|
86757
86832
|
fs112.mkdirSync(dir, { recursive: true });
|
|
86758
|
-
this.historyFile =
|
|
86833
|
+
this.historyFile = path120.join(dir, "history.json");
|
|
86759
86834
|
this._fs = fs112;
|
|
86760
86835
|
}
|
|
86761
86836
|
const fs111 = this._fs;
|
|
@@ -94155,8 +94230,8 @@ var SessionManager = class {
|
|
|
94155
94230
|
let fixed = 0;
|
|
94156
94231
|
for (const [key6, entry] of this.index) {
|
|
94157
94232
|
if (fs92.existsSync(entry.file)) continue;
|
|
94158
|
-
const
|
|
94159
|
-
const localPath = path94.join(this.sessionsDir,
|
|
94233
|
+
const basename30 = path94.basename(entry.file);
|
|
94234
|
+
const localPath = path94.join(this.sessionsDir, basename30);
|
|
94160
94235
|
if (fs92.existsSync(localPath)) {
|
|
94161
94236
|
entry.file = localPath;
|
|
94162
94237
|
fixed++;
|
|
@@ -97061,9 +97136,9 @@ function registerPortrait(relPath, name) {
|
|
|
97061
97136
|
const cur = cfg?.tools?.my_selfie?.references || cfg?.my_selfie?.references || [];
|
|
97062
97137
|
const next = Array.isArray(cur) ? cur.filter((r) => r?.name !== name) : [];
|
|
97063
97138
|
next.unshift({ name, path: relPath });
|
|
97064
|
-
const
|
|
97065
|
-
void liveConfig.set(
|
|
97066
|
-
console.log(`[my-selfie] \u5F62\u8C61\u5DF2\u767B\u8BB0\uFF1A${
|
|
97139
|
+
const path120 = cfg?.tools?.my_selfie ? "tools.my_selfie.references" : "my_selfie.references";
|
|
97140
|
+
void liveConfig.set(path120, next);
|
|
97141
|
+
console.log(`[my-selfie] \u5F62\u8C61\u5DF2\u767B\u8BB0\uFF1A${path120}[0] = ${relPath}`);
|
|
97067
97142
|
} catch (e) {
|
|
97068
97143
|
console.warn(`[my-selfie] \u5199\u5165 references \u5931\u8D25\uFF08\u4E0D\u5F71\u54CD\u672C\u6B21\u51FA\u56FE\uFF09: ${e.message}`);
|
|
97069
97144
|
}
|
|
@@ -101517,7 +101592,7 @@ async function startEngine(config, opts) {
|
|
|
101517
101592
|
const { initSessionMemory: initSessionMemory2 } = await Promise.resolve().then(() => (init_sessionMemory(), sessionMemory_exports));
|
|
101518
101593
|
initSessionMemory2({
|
|
101519
101594
|
workspace: config.workspace,
|
|
101520
|
-
stateDir:
|
|
101595
|
+
stateDir: path119.join(config.stateDir, "session-memory"),
|
|
101521
101596
|
provider,
|
|
101522
101597
|
model: config.provider.modelId || config.model || "deepseek-v4-flash",
|
|
101523
101598
|
features: config.profile.features
|
|
@@ -101801,7 +101876,7 @@ async function startEngine(config, opts) {
|
|
|
101801
101876
|
let failed = false;
|
|
101802
101877
|
const finishHostDelivery = (state2, reason) => {
|
|
101803
101878
|
if (!route?.hostDelivery) return;
|
|
101804
|
-
const persist2 = new Persistence(
|
|
101879
|
+
const persist2 = new Persistence(path119.join(route.hostDelivery.workspace, ".proactive", "proactive.db"));
|
|
101805
101880
|
try {
|
|
101806
101881
|
persist2.hostDeliveries.finish(route.hostDelivery.key, state2, reason);
|
|
101807
101882
|
} finally {
|