engine7 7.1.121 → 7.1.122
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/cli.mjs +174 -138
- package/dist/engine-startup.mjs +330 -148
- package/dist/main.mjs +330 -148
- package/dist/mem7-worker.mjs +15 -2
- package/package.json +1 -1
- package/templates/config.template.json +1 -1
package/dist/cli.mjs
CHANGED
|
@@ -1047,7 +1047,7 @@ var init_read_budget = __esm({
|
|
|
1047
1047
|
check(depth = 0) {
|
|
1048
1048
|
if (this.failure) throw this.failure;
|
|
1049
1049
|
const elapsed = this.elapsedMs + (this.started === void 0 ? 0 : this.now() - this.started);
|
|
1050
|
-
const reason = depth > (this.limits.maxDepth ?? 256) ? "depth" : ++this.steps > (this.limits.maxSteps ??
|
|
1050
|
+
const reason = depth > (this.limits.maxDepth ?? 256) ? "depth" : ++this.steps > (this.limits.maxSteps ?? 25e4) ? "work" : elapsed >= (this.limits.maxMs ?? 4e3) ? "time" : void 0;
|
|
1051
1051
|
if (reason) {
|
|
1052
1052
|
this.failure = new MemoryReadBudgetExceededError(reason);
|
|
1053
1053
|
throw this.failure;
|
|
@@ -2292,6 +2292,11 @@ CREATE TABLE memory_state_outbox (
|
|
|
2292
2292
|
payload_json TEXT NOT NULL, created_at TEXT NOT NULL,
|
|
2293
2293
|
PRIMARY KEY(scope_id,event_seq), FOREIGN KEY(scope_id) REFERENCES memory_scopes(scope_id)
|
|
2294
2294
|
);
|
|
2295
|
+
-- 1013\uFF1A\u6309 (scope_id,kind) \u53D6 MAX(aggregate_version) \u7684\u805A\u5408\u7248\u672C\u67E5\u8BE2\uFF0C\u9760 PK \u53EA\u80FD\u547D\u4E2D scope_id\uFF0C
|
|
2296
|
+
-- \u4E4B\u540E\u8981\u626B\u8BE5 scope \u4E0B\u5168\u90E8 outbox \u884C\u7B97 MAX\u3002\u8BE5\u67E5\u8BE2\u5728\u5355\u6B21 buildMemoryContext \u91CC\u88AB\u8C03\u7528\u6570\u767E\u6B21
|
|
2297
|
+
-- \uFF08\u59B9\u59B9 2015 \u884C\u5E93 \u2248 140 \u4E07\u884C\u8BBF\u95EE\uFF09\uFF0C\u5B9E\u6D4B\u628A\u5F53\u524D\u4E0A\u4E0B\u6587\u88C5\u914D\u4ECE 719ms \u63A8\u5230 2617ms\uFF0C\u76F4\u63A5\u51FB\u7A7F
|
|
2298
|
+
-- turnReadBudgetMs \u9ED8\u8BA4 1500ms \u2192 \u5168\u8F6E\u964D\u7EA7 \u2192 \u5360\u4F4D\u7B26\u4E8B\u6545\u3002\u8986\u76D6\u7D22\u5F15\u8BA9 MAX \u9000\u5316\u6210\u7D22\u5F15\u672B\u9879\u5B9A\u4F4D\u3002
|
|
2299
|
+
CREATE INDEX IF NOT EXISTS idx_outbox_scope_kind_version ON memory_state_outbox(scope_id,kind,aggregate_version);
|
|
2295
2300
|
`;
|
|
2296
2301
|
}
|
|
2297
2302
|
});
|
|
@@ -10044,6 +10049,14 @@ function migrateMem7(db2, initializeLegacySchema) {
|
|
|
10044
10049
|
version: 29,
|
|
10045
10050
|
name: "idempotent-source-backed-chat-people-updates",
|
|
10046
10051
|
apply: (database) => database.exec(SOCIAL_WRITE_SCHEMA)
|
|
10052
|
+
}, {
|
|
10053
|
+
version: 30,
|
|
10054
|
+
name: "indexed-outbox-aggregate-revisions",
|
|
10055
|
+
// 存量库补索引:聚合版本查询此前要扫该 scope 下全部 outbox 行算 MAX,
|
|
10056
|
+
// 实测妹妹 182MB 库 buildMemoryContext 2617ms → 719ms(读预算默认 1500ms 本来必破)。
|
|
10057
|
+
apply: (database) => database.exec(
|
|
10058
|
+
"CREATE INDEX IF NOT EXISTS idx_outbox_scope_kind_version ON memory_state_outbox(scope_id,kind,aggregate_version)"
|
|
10059
|
+
)
|
|
10047
10060
|
}]);
|
|
10048
10061
|
} finally {
|
|
10049
10062
|
if (foreignKeys) db2.exec("PRAGMA foreign_keys=ON");
|
|
@@ -10069,7 +10082,7 @@ var init_migrations = __esm({
|
|
|
10069
10082
|
init_relationship_cognition();
|
|
10070
10083
|
init_relationship_notices();
|
|
10071
10084
|
init_relationship_history();
|
|
10072
|
-
MEM7_SCHEMA_VERSION =
|
|
10085
|
+
MEM7_SCHEMA_VERSION = 30;
|
|
10073
10086
|
}
|
|
10074
10087
|
});
|
|
10075
10088
|
|
|
@@ -11536,7 +11549,8 @@ var init_registry = __esm({
|
|
|
11536
11549
|
label: "\u6BCF\u8F6E\u8BB0\u5FC6\u8BFB\u53D6\u64CD\u4F5C\u4E0A\u9650",
|
|
11537
11550
|
effect: "hot",
|
|
11538
11551
|
internal: true,
|
|
11539
|
-
|
|
11552
|
+
// 上限必须 ≥ 代码默认值 250_000(1012 抬默认时漏了这里,导致托盘/CLI 拒收代码自己的默认值)
|
|
11553
|
+
validate: (value) => typeof value === "number" && Number.isSafeInteger(value) && value >= 1 && value <= 5e5 ? null : "\u6BCF\u8F6E\u8BB0\u5FC6\u8BFB\u53D6\u64CD\u4F5C\u987B\u4E3A 1\u2013500000 \u6B21"
|
|
11540
11554
|
},
|
|
11541
11555
|
{
|
|
11542
11556
|
path: "mem7.relationships",
|
|
@@ -12006,7 +12020,9 @@ function generateConfig(v) {
|
|
|
12006
12020
|
appSecret: secretRef(envKeyOf("channels.feishu.appSecret"), v.feishuAppSecret),
|
|
12007
12021
|
connectionMode: "websocket",
|
|
12008
12022
|
dmPolicy: "pairing",
|
|
12009
|
-
|
|
12023
|
+
// 1011 翀哥:群默认 mention-only——@才回应(引擎 adapter 同款默认)。此前脚手架写
|
|
12024
|
+
// 'open' = 装机用户的机器人在群里每条都接话;免 @ 的群走 group.openGroups 局部豁免。
|
|
12025
|
+
groupPolicy: "mention-only"
|
|
12010
12026
|
},
|
|
12011
12027
|
...v.wechatEnabled && v.wechatToken ? {
|
|
12012
12028
|
wechat: {
|
|
@@ -16515,6 +16531,130 @@ var init_executor2 = __esm({
|
|
|
16515
16531
|
}
|
|
16516
16532
|
});
|
|
16517
16533
|
|
|
16534
|
+
// src/mem7/assistant-context.ts
|
|
16535
|
+
function emittedWithheldPlaceholder(text) {
|
|
16536
|
+
return typeof text === "string" && text.trim() === withheldSourceBody;
|
|
16537
|
+
}
|
|
16538
|
+
function withholdSource(message) {
|
|
16539
|
+
message.content = withheldSourceBody;
|
|
16540
|
+
delete message.memoryOriginalText;
|
|
16541
|
+
delete message.reasoning_content;
|
|
16542
|
+
delete message.thinking_signature;
|
|
16543
|
+
delete message.responses_reasoning;
|
|
16544
|
+
}
|
|
16545
|
+
function degradeUncheckedMemory(messages) {
|
|
16546
|
+
const safeMessages = [];
|
|
16547
|
+
for (const message of messages) {
|
|
16548
|
+
if (isAttachmentMessage(message)) {
|
|
16549
|
+
if (message.attachment.type !== "relevant_memories") safeMessages.push(message);
|
|
16550
|
+
continue;
|
|
16551
|
+
}
|
|
16552
|
+
safeMessages.push(message);
|
|
16553
|
+
}
|
|
16554
|
+
return safeMessages;
|
|
16555
|
+
}
|
|
16556
|
+
function memoryContextRefs(store, scope, value) {
|
|
16557
|
+
if (!value || typeof value !== "object") return [];
|
|
16558
|
+
const input = value;
|
|
16559
|
+
if (input.scopeId !== void 0 && input.scopeId !== scopeId(scope)) return [];
|
|
16560
|
+
const refs = /* @__PURE__ */ new Map();
|
|
16561
|
+
const add = (candidate) => {
|
|
16562
|
+
checkMemoryReadBudget();
|
|
16563
|
+
if (!candidate || typeof candidate.sourceId !== "string") return;
|
|
16564
|
+
const source = store.sources.get(scope, candidate.sourceId);
|
|
16565
|
+
if (!source || !store.socialSources.retained(scope, source.sourceId)) return;
|
|
16566
|
+
if (candidate.scopeId !== void 0 && candidate.scopeId !== scopeId(scope)) return;
|
|
16567
|
+
if (candidate.sourceVersion !== void 0 && candidate.sourceVersion !== source.sourceVersion) return;
|
|
16568
|
+
const ref = { scopeId: scopeId(scope), sourceId: source.sourceId, sourceVersion: source.sourceVersion };
|
|
16569
|
+
if (candidate.relationshipId !== void 0 || candidate.semanticVersion !== void 0) {
|
|
16570
|
+
if (typeof candidate.relationshipId !== "string" || !Number.isSafeInteger(candidate.semanticVersion) || candidate.semanticVersion < 1) return;
|
|
16571
|
+
ref.relationshipId = candidate.relationshipId;
|
|
16572
|
+
ref.semanticVersion = candidate.semanticVersion;
|
|
16573
|
+
}
|
|
16574
|
+
if (candidate.purpose !== void 0) {
|
|
16575
|
+
if (!["evidence", "context", "historical"].includes(candidate.purpose)) return;
|
|
16576
|
+
ref.purpose = candidate.purpose;
|
|
16577
|
+
}
|
|
16578
|
+
if (store.socialSources.referenceRetained(scope, ref)) refs.set(canonicalJson(ref), ref);
|
|
16579
|
+
};
|
|
16580
|
+
for (const list2 of [input.contextRefs, input.relationships?.contextRefs, input.citations, input.pendingSources]) {
|
|
16581
|
+
if (Array.isArray(list2)) for (const ref of list2) add(ref);
|
|
16582
|
+
}
|
|
16583
|
+
const relationships = Array.isArray(input.relationships) ? input.relationships : input.relationships?.relationships;
|
|
16584
|
+
if (Array.isArray(relationships)) for (const relationship of relationships) {
|
|
16585
|
+
if (!relationship || typeof relationship.relationshipId !== "string" || !Number.isSafeInteger(relationship.semanticVersion)) continue;
|
|
16586
|
+
for (const list2 of [relationship.evidenceSources, relationship.basisSources]) {
|
|
16587
|
+
if (Array.isArray(list2)) for (const source of list2) add({
|
|
16588
|
+
sourceId: source.sourceId,
|
|
16589
|
+
sourceVersion: source.sourceVersion,
|
|
16590
|
+
relationshipId: relationship.relationshipId,
|
|
16591
|
+
semanticVersion: relationship.semanticVersion,
|
|
16592
|
+
purpose: relationship.current === false ? "historical" : "context"
|
|
16593
|
+
});
|
|
16594
|
+
}
|
|
16595
|
+
}
|
|
16596
|
+
for (const list2 of [input.historicalEvidence, input.episodes, input.entries]) {
|
|
16597
|
+
if (Array.isArray(list2)) {
|
|
16598
|
+
for (const item of list2) if (Array.isArray(item.sourceIds)) for (const sourceId of item.sourceIds) add({ sourceId });
|
|
16599
|
+
}
|
|
16600
|
+
}
|
|
16601
|
+
if (typeof input.sourceId === "string" && Number.isSafeInteger(input.sourceVersion)) add(input);
|
|
16602
|
+
return [...refs.values()];
|
|
16603
|
+
}
|
|
16604
|
+
function assistantContextRefs(store, scope, messages) {
|
|
16605
|
+
const refs = /* @__PURE__ */ new Map();
|
|
16606
|
+
const add = (ref) => refs.set(canonicalJson(ref), ref);
|
|
16607
|
+
for (const message of messages) {
|
|
16608
|
+
checkMemoryReadBudget();
|
|
16609
|
+
if (isAttachmentMessage(message)) {
|
|
16610
|
+
if (message.attachment.type !== "relevant_memories") continue;
|
|
16611
|
+
for (const memory of message.attachment.memories) {
|
|
16612
|
+
if (memory.mem7 && scopeId(memory.mem7.scope) === scopeId(scope)) {
|
|
16613
|
+
for (const sourceId of memory.mem7.sourceIds) {
|
|
16614
|
+
const source = store.sources.get(scope, sourceId);
|
|
16615
|
+
if (source && store.socialSources.retained(scope, sourceId)) add({ scopeId: scopeId(scope), sourceId, sourceVersion: source.sourceVersion });
|
|
16616
|
+
}
|
|
16617
|
+
}
|
|
16618
|
+
if (memory.path.startsWith("mem7-context://")) {
|
|
16619
|
+
let value;
|
|
16620
|
+
try {
|
|
16621
|
+
value = JSON.parse(memory.content);
|
|
16622
|
+
} catch (error) {
|
|
16623
|
+
if (!(error instanceof SyntaxError)) throw error;
|
|
16624
|
+
continue;
|
|
16625
|
+
}
|
|
16626
|
+
for (const ref of memoryContextRefs(store, scope, value)) add(ref);
|
|
16627
|
+
}
|
|
16628
|
+
}
|
|
16629
|
+
} else if (message.content !== withheldSourceBody && message.memoryOriginKey && message.memoryScope && scopeId(message.memoryScope) === scopeId(scope)) {
|
|
16630
|
+
const source = store.sources.getByOrigin(scope, message.memoryOriginKey, message.memorySourceVersion ?? 1);
|
|
16631
|
+
if (source && source.role === message.role && store.socialSources.retained(scope, source.sourceId))
|
|
16632
|
+
add({ scopeId: scopeId(scope), sourceId: source.sourceId, sourceVersion: source.sourceVersion });
|
|
16633
|
+
}
|
|
16634
|
+
}
|
|
16635
|
+
return [...refs.values()];
|
|
16636
|
+
}
|
|
16637
|
+
function scrubUnavailableSourceMessages(store, scope, messages) {
|
|
16638
|
+
for (const message of messages) {
|
|
16639
|
+
checkMemoryReadBudget();
|
|
16640
|
+
if (isAttachmentMessage(message) || !message.memoryOriginKey || !message.memoryScope || scopeId(message.memoryScope) !== scopeId(scope) || !store.sources.hasOrigin(scope, message.memoryOriginKey)) continue;
|
|
16641
|
+
const source = store.sources.getByOrigin(scope, message.memoryOriginKey, message.memorySourceVersion ?? 1);
|
|
16642
|
+
if (source && store.socialSources.retained(scope, source.sourceId)) continue;
|
|
16643
|
+
withholdSource(message);
|
|
16644
|
+
}
|
|
16645
|
+
}
|
|
16646
|
+
var withheldSourceBody;
|
|
16647
|
+
var init_assistant_context = __esm({
|
|
16648
|
+
"src/mem7/assistant-context.ts"() {
|
|
16649
|
+
"use strict";
|
|
16650
|
+
init_types();
|
|
16651
|
+
init_scope();
|
|
16652
|
+
init_temporal();
|
|
16653
|
+
init_read_budget();
|
|
16654
|
+
withheldSourceBody = "[\u5BF9\u5E94\u8BB0\u5FC6\u6765\u6E90\u672C\u8F6E\u672A\u901A\u8FC7\u6821\u9A8C\uFF0C\u539F\u6587\u6682\u4E0D\u63D0\u4F9B\u3002]";
|
|
16655
|
+
}
|
|
16656
|
+
});
|
|
16657
|
+
|
|
16518
16658
|
// src/memory/memdir/memoryAge.ts
|
|
16519
16659
|
function memoryAgeDays(mtimeMs) {
|
|
16520
16660
|
return Math.max(0, Math.floor((Date.now() - mtimeMs) / 864e5));
|
|
@@ -19502,6 +19642,7 @@ var init_query = __esm({
|
|
|
19502
19642
|
"use strict";
|
|
19503
19643
|
init_executor2();
|
|
19504
19644
|
init_host_turn();
|
|
19645
|
+
init_assistant_context();
|
|
19505
19646
|
init_external_effect();
|
|
19506
19647
|
init_attachments();
|
|
19507
19648
|
init_context_dump();
|
|
@@ -19952,6 +20093,10 @@ ${perTurnSystemDynamic}` : deferredHint || perTurnSystemDynamic;
|
|
|
19952
20093
|
return;
|
|
19953
20094
|
}
|
|
19954
20095
|
if (toolCalls.length === 0) {
|
|
20096
|
+
if (emittedWithheldPlaceholder(textContent)) {
|
|
20097
|
+
console.warn(`${this.logPrefix} Turn ${turnCount}: \u6A21\u578B\u8F93\u51FA\u7CFB\u7EDF\u5360\u4F4D\u7B26\uFF0C\u6309\u7A7A\u54CD\u5E94\u91CD\u8BD5\uFF08\u4E0D\u5165\u5386\u53F2\u3001\u4E0D\u51FA\u7AD9\uFF09`);
|
|
20098
|
+
textContent = "";
|
|
20099
|
+
}
|
|
19955
20100
|
if (!textContent.trim()) {
|
|
19956
20101
|
const thinkingAteBudget = turnThinking.length > 0;
|
|
19957
20102
|
console.log(`${this.logPrefix} Turn ${turnCount}: API returned empty (no text, no tool_call).${thinkingAteBudget ? ` ${turnThinking.length}ch thinking \u5403\u5149\u8F93\u51FA\u9884\u7B97 \u2192 retry with thinking off` : " Retrying..."} messages=${currentMessages.length}`);
|
|
@@ -30684,133 +30829,6 @@ var init_active_query_engine = __esm({
|
|
|
30684
30829
|
}
|
|
30685
30830
|
});
|
|
30686
30831
|
|
|
30687
|
-
// src/mem7/assistant-context.ts
|
|
30688
|
-
function withholdSource(message) {
|
|
30689
|
-
message.content = withheldSourceBody;
|
|
30690
|
-
delete message.memoryOriginalText;
|
|
30691
|
-
delete message.reasoning_content;
|
|
30692
|
-
delete message.thinking_signature;
|
|
30693
|
-
delete message.responses_reasoning;
|
|
30694
|
-
}
|
|
30695
|
-
function withholdUncheckedMemory(messages, currentMessage) {
|
|
30696
|
-
const safeMessages = [];
|
|
30697
|
-
for (const message of messages) {
|
|
30698
|
-
if (isAttachmentMessage(message)) {
|
|
30699
|
-
if (message.attachment.type !== "relevant_memories") safeMessages.push(message);
|
|
30700
|
-
continue;
|
|
30701
|
-
}
|
|
30702
|
-
if (!message.memoryOriginKey || message === currentMessage) {
|
|
30703
|
-
safeMessages.push(message);
|
|
30704
|
-
continue;
|
|
30705
|
-
}
|
|
30706
|
-
const safe = { ...message };
|
|
30707
|
-
withholdSource(safe);
|
|
30708
|
-
safeMessages.push(safe);
|
|
30709
|
-
}
|
|
30710
|
-
return safeMessages;
|
|
30711
|
-
}
|
|
30712
|
-
function memoryContextRefs(store, scope, value) {
|
|
30713
|
-
if (!value || typeof value !== "object") return [];
|
|
30714
|
-
const input = value;
|
|
30715
|
-
if (input.scopeId !== void 0 && input.scopeId !== scopeId(scope)) return [];
|
|
30716
|
-
const refs = /* @__PURE__ */ new Map();
|
|
30717
|
-
const add = (candidate) => {
|
|
30718
|
-
checkMemoryReadBudget();
|
|
30719
|
-
if (!candidate || typeof candidate.sourceId !== "string") return;
|
|
30720
|
-
const source = store.sources.get(scope, candidate.sourceId);
|
|
30721
|
-
if (!source || !store.socialSources.retained(scope, source.sourceId)) return;
|
|
30722
|
-
if (candidate.scopeId !== void 0 && candidate.scopeId !== scopeId(scope)) return;
|
|
30723
|
-
if (candidate.sourceVersion !== void 0 && candidate.sourceVersion !== source.sourceVersion) return;
|
|
30724
|
-
const ref = { scopeId: scopeId(scope), sourceId: source.sourceId, sourceVersion: source.sourceVersion };
|
|
30725
|
-
if (candidate.relationshipId !== void 0 || candidate.semanticVersion !== void 0) {
|
|
30726
|
-
if (typeof candidate.relationshipId !== "string" || !Number.isSafeInteger(candidate.semanticVersion) || candidate.semanticVersion < 1) return;
|
|
30727
|
-
ref.relationshipId = candidate.relationshipId;
|
|
30728
|
-
ref.semanticVersion = candidate.semanticVersion;
|
|
30729
|
-
}
|
|
30730
|
-
if (candidate.purpose !== void 0) {
|
|
30731
|
-
if (!["evidence", "context", "historical"].includes(candidate.purpose)) return;
|
|
30732
|
-
ref.purpose = candidate.purpose;
|
|
30733
|
-
}
|
|
30734
|
-
if (store.socialSources.referenceRetained(scope, ref)) refs.set(canonicalJson(ref), ref);
|
|
30735
|
-
};
|
|
30736
|
-
for (const list2 of [input.contextRefs, input.relationships?.contextRefs, input.citations, input.pendingSources]) {
|
|
30737
|
-
if (Array.isArray(list2)) for (const ref of list2) add(ref);
|
|
30738
|
-
}
|
|
30739
|
-
const relationships = Array.isArray(input.relationships) ? input.relationships : input.relationships?.relationships;
|
|
30740
|
-
if (Array.isArray(relationships)) for (const relationship of relationships) {
|
|
30741
|
-
if (!relationship || typeof relationship.relationshipId !== "string" || !Number.isSafeInteger(relationship.semanticVersion)) continue;
|
|
30742
|
-
for (const list2 of [relationship.evidenceSources, relationship.basisSources]) {
|
|
30743
|
-
if (Array.isArray(list2)) for (const source of list2) add({
|
|
30744
|
-
sourceId: source.sourceId,
|
|
30745
|
-
sourceVersion: source.sourceVersion,
|
|
30746
|
-
relationshipId: relationship.relationshipId,
|
|
30747
|
-
semanticVersion: relationship.semanticVersion,
|
|
30748
|
-
purpose: relationship.current === false ? "historical" : "context"
|
|
30749
|
-
});
|
|
30750
|
-
}
|
|
30751
|
-
}
|
|
30752
|
-
for (const list2 of [input.historicalEvidence, input.episodes, input.entries]) {
|
|
30753
|
-
if (Array.isArray(list2)) {
|
|
30754
|
-
for (const item of list2) if (Array.isArray(item.sourceIds)) for (const sourceId of item.sourceIds) add({ sourceId });
|
|
30755
|
-
}
|
|
30756
|
-
}
|
|
30757
|
-
if (typeof input.sourceId === "string" && Number.isSafeInteger(input.sourceVersion)) add(input);
|
|
30758
|
-
return [...refs.values()];
|
|
30759
|
-
}
|
|
30760
|
-
function assistantContextRefs(store, scope, messages) {
|
|
30761
|
-
const refs = /* @__PURE__ */ new Map();
|
|
30762
|
-
const add = (ref) => refs.set(canonicalJson(ref), ref);
|
|
30763
|
-
for (const message of messages) {
|
|
30764
|
-
checkMemoryReadBudget();
|
|
30765
|
-
if (isAttachmentMessage(message)) {
|
|
30766
|
-
if (message.attachment.type !== "relevant_memories") continue;
|
|
30767
|
-
for (const memory of message.attachment.memories) {
|
|
30768
|
-
if (memory.mem7 && scopeId(memory.mem7.scope) === scopeId(scope)) {
|
|
30769
|
-
for (const sourceId of memory.mem7.sourceIds) {
|
|
30770
|
-
const source = store.sources.get(scope, sourceId);
|
|
30771
|
-
if (source && store.socialSources.retained(scope, sourceId)) add({ scopeId: scopeId(scope), sourceId, sourceVersion: source.sourceVersion });
|
|
30772
|
-
}
|
|
30773
|
-
}
|
|
30774
|
-
if (memory.path.startsWith("mem7-context://")) {
|
|
30775
|
-
let value;
|
|
30776
|
-
try {
|
|
30777
|
-
value = JSON.parse(memory.content);
|
|
30778
|
-
} catch (error) {
|
|
30779
|
-
if (!(error instanceof SyntaxError)) throw error;
|
|
30780
|
-
continue;
|
|
30781
|
-
}
|
|
30782
|
-
for (const ref of memoryContextRefs(store, scope, value)) add(ref);
|
|
30783
|
-
}
|
|
30784
|
-
}
|
|
30785
|
-
} else if (message.content !== withheldSourceBody && message.memoryOriginKey && message.memoryScope && scopeId(message.memoryScope) === scopeId(scope)) {
|
|
30786
|
-
const source = store.sources.getByOrigin(scope, message.memoryOriginKey, message.memorySourceVersion ?? 1);
|
|
30787
|
-
if (source && source.role === message.role && store.socialSources.retained(scope, source.sourceId))
|
|
30788
|
-
add({ scopeId: scopeId(scope), sourceId: source.sourceId, sourceVersion: source.sourceVersion });
|
|
30789
|
-
}
|
|
30790
|
-
}
|
|
30791
|
-
return [...refs.values()];
|
|
30792
|
-
}
|
|
30793
|
-
function scrubUnavailableSourceMessages(store, scope, messages) {
|
|
30794
|
-
for (const message of messages) {
|
|
30795
|
-
checkMemoryReadBudget();
|
|
30796
|
-
if (isAttachmentMessage(message) || !message.memoryOriginKey || !message.memoryScope || scopeId(message.memoryScope) !== scopeId(scope) || !store.sources.hasOrigin(scope, message.memoryOriginKey)) continue;
|
|
30797
|
-
const source = store.sources.getByOrigin(scope, message.memoryOriginKey, message.memorySourceVersion ?? 1);
|
|
30798
|
-
if (source && store.socialSources.retained(scope, source.sourceId)) continue;
|
|
30799
|
-
withholdSource(message);
|
|
30800
|
-
}
|
|
30801
|
-
}
|
|
30802
|
-
var withheldSourceBody;
|
|
30803
|
-
var init_assistant_context = __esm({
|
|
30804
|
-
"src/mem7/assistant-context.ts"() {
|
|
30805
|
-
"use strict";
|
|
30806
|
-
init_types();
|
|
30807
|
-
init_scope();
|
|
30808
|
-
init_temporal();
|
|
30809
|
-
init_read_budget();
|
|
30810
|
-
withheldSourceBody = "[\u5BF9\u5E94\u8BB0\u5FC6\u6765\u6E90\u672C\u8F6E\u672A\u901A\u8FC7\u6821\u9A8C\uFF0C\u539F\u6587\u6682\u4E0D\u63D0\u4F9B\u3002]";
|
|
30811
|
-
}
|
|
30812
|
-
});
|
|
30813
|
-
|
|
30814
30832
|
// src/memory/memdir/memoryScan.ts
|
|
30815
30833
|
import { readdir, stat as stat2, readFile as readFile3 } from "node:fs/promises";
|
|
30816
30834
|
import { basename as basename6, join as join37, sep as sep6 } from "node:path";
|
|
@@ -39120,8 +39138,21 @@ async function handleQueryInner(text, sessionId, channelName, cb, deps, channelT
|
|
|
39120
39138
|
const memoryContextRefs2 = [];
|
|
39121
39139
|
const memoryStateDir = memoryIntake?.stateDir ?? String(liveConfig.get("stateDir") ?? deps.stateDir ?? "");
|
|
39122
39140
|
const memoryReadBudget = new MemoryReadBudget({
|
|
39123
|
-
|
|
39124
|
-
|
|
39141
|
+
// 1013:时间闸默认 1500ms 同样低于合法工作集——1012 为步数闸写下的原则(「闸只防无进展的
|
|
39142
|
+
// 死循环,不该拦合法工作」)当时没套用到时间闸上,它的 447ms 依据只测了 scrub+strip+refs,
|
|
39143
|
+
// 漏掉最贵的 buildMemoryContext。实测妹妹 182MB 库:三阶段累计 1196–1474ms,1500ms 下余量
|
|
39144
|
+
// 只剩 26–304ms,正常聊天即耗尽(1013 占位符事故,reason=time)。抬到 4000ms(小柯线上
|
|
39145
|
+
// 已跑这个值);闸仍兜 1009 式事件循环冻结,只是不再切合法工作。
|
|
39146
|
+
// 真正的成本在 a75d3804 的 outbox 覆盖索引:当前上下文装配 2617ms → ~1100ms。
|
|
39147
|
+
maxMs: liveConfig.get("mem7.turnReadBudgetMs") ?? 4e3,
|
|
39148
|
+
// 1012:步数闸默认 5 万被证低于合法工作集——忙 scope 单轮两遍冷走(:438 prompt 前 + :1042 query 循环内,
|
|
39149
|
+
// 中间 worker 落盘会失效快照)≈ 5 万步,正常聊天即触发全量扣原文(占位符刷屏事故)。真安全线是时间闸
|
|
39150
|
+
// 1500ms(防 1009 式事件循环冻结),步数闸只防无进展的死循环,抬到 25 万。实测妹妹 151MB 库全轮 447ms。
|
|
39151
|
+
// ⚠️ 1013 更正:上面「真安全线是时间闸 1500ms」已被证伪——那次 447ms 只测了
|
|
39152
|
+
// scrub+strip+refs(见 scripts/_probe-scrub-steps-1012.mts),漏掉最贵的 buildMemoryContext
|
|
39153
|
+
// (同库实测 2617ms),所以 1500ms 当时就已经不可达。步数闸的结论仍然成立(实测
|
|
39154
|
+
// 三阶段 102150 步,25 万合适)。
|
|
39155
|
+
maxSteps: liveConfig.get("mem7.turnReadMaxSteps") ?? 25e4
|
|
39125
39156
|
});
|
|
39126
39157
|
let memoryReadDegraded = false;
|
|
39127
39158
|
let currentPromptMessage;
|
|
@@ -39176,7 +39207,7 @@ async function handleQueryInner(text, sessionId, channelName, cb, deps, channelT
|
|
|
39176
39207
|
Promise.resolve().then(() => (init_historical_recall(), historical_recall_exports))
|
|
39177
39208
|
]);
|
|
39178
39209
|
revalidateRecall = (items) => {
|
|
39179
|
-
if (memoryReadDegraded) return
|
|
39210
|
+
if (memoryReadDegraded) return degradeUncheckedMemory(items);
|
|
39180
39211
|
const invalidPaths = /* @__PURE__ */ new Set();
|
|
39181
39212
|
const checked = items.map((item) => isAttachmentMessage(item) || item === currentPromptMessage ? item : { ...item });
|
|
39182
39213
|
try {
|
|
@@ -39196,7 +39227,7 @@ async function handleQueryInner(text, sessionId, channelName, cb, deps, channelT
|
|
|
39196
39227
|
} catch (error) {
|
|
39197
39228
|
if (!isMemoryReadUnavailable(error)) throw error;
|
|
39198
39229
|
degradeMemoryRead(error);
|
|
39199
|
-
return
|
|
39230
|
+
return degradeUncheckedMemory(items);
|
|
39200
39231
|
}
|
|
39201
39232
|
if (invalidPaths.size) {
|
|
39202
39233
|
stripRecalledMemories(history, (path52) => invalidPaths.has(normalizeMemoryPath(path52)));
|
|
@@ -39721,7 +39752,7 @@ ${evidence}
|
|
|
39721
39752
|
} catch (error) {
|
|
39722
39753
|
if (isMemoryReadUnavailable(error)) {
|
|
39723
39754
|
degradeMemoryRead(error);
|
|
39724
|
-
messages =
|
|
39755
|
+
messages = degradeUncheckedMemory(messages);
|
|
39725
39756
|
}
|
|
39726
39757
|
console.warn(`[handle-query] mem7 current context failed: ${error?.message ?? error}`);
|
|
39727
39758
|
}
|
|
@@ -39745,7 +39776,7 @@ ${evidence}
|
|
|
39745
39776
|
} catch (error) {
|
|
39746
39777
|
if (!isMemoryReadUnavailable(error)) throw error;
|
|
39747
39778
|
degradeMemoryRead(error);
|
|
39748
|
-
messages =
|
|
39779
|
+
messages = degradeUncheckedMemory(messages);
|
|
39749
39780
|
}
|
|
39750
39781
|
}
|
|
39751
39782
|
if (memoryHostSourceId && !memoryContextRefs2.some((ref) => ref.sourceId === memoryHostSourceId)) {
|
|
@@ -39894,7 +39925,12 @@ ${evidence}
|
|
|
39894
39925
|
const rawContent = chunk.content ?? "";
|
|
39895
39926
|
const inputTokens = chunk.inputTokens ?? 0;
|
|
39896
39927
|
const outputTokens = chunk.outputTokens ?? 0;
|
|
39897
|
-
const
|
|
39928
|
+
const placeholderLeak = emittedWithheldPlaceholder(rawContent);
|
|
39929
|
+
if (placeholderLeak) {
|
|
39930
|
+
console.warn("[handle-query] \u26A0\uFE0F \u6A21\u578B\u91CD\u8BD5\u540E\u4ECD\u8F93\u51FA\u7CFB\u7EDF\u5360\u4F4D\u7B26\u2014\u2014\u62D2\u7EDD\u5165\u5386\u53F2\u4E0E\u51FA\u7AD9");
|
|
39931
|
+
}
|
|
39932
|
+
const usableContent = placeholderLeak ? "" : rawContent;
|
|
39933
|
+
const resultContent = usableContent.trim() || fullResponse.trim() || "(\u65E0\u56DE\u590D)";
|
|
39898
39934
|
if (!rawContent.trim()) {
|
|
39899
39935
|
console.log(`[handle-query] \u26A0\uFE0F EMPTY RESULT after ${toolCount} tools, falling back to ${fullResponse.length} chars accumulated`);
|
|
39900
39936
|
}
|