engine7 7.1.140 → 7.1.142

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -19911,7 +19911,7 @@ init_dates();
19911
19911
  init_topics_history();
19912
19912
  init_vectors();
19913
19913
  import { DatabaseSync as DatabaseSync16 } from "node:sqlite";
19914
- import { existsSync as existsSync11, writeFileSync as writeFileSync9 } from "node:fs";
19914
+ import { existsSync as existsSync11, renameSync as renameSync7, writeFileSync as writeFileSync9 } from "node:fs";
19915
19915
  import { join as join22 } from "node:path";
19916
19916
 
19917
19917
  // src/memory/topics-history/import-backups.ts
@@ -19921,7 +19921,19 @@ var TOPICS_BACKUP_RETENTION_MS = 7 * 864e5;
19921
19921
 
19922
19922
  // src/memory/topics-history/import-mem7.ts
19923
19923
  function topicsImported(binding) {
19924
- return !!binding.stateDir && existsSync11(join22(topicsHistoryRoot(binding), "topics-import.json"));
19924
+ if (!binding.stateDir) return false;
19925
+ const marker = join22(topicsHistoryRoot(binding), "topics-import.json");
19926
+ if (!existsSync11(marker)) return false;
19927
+ try {
19928
+ const done = readJson(marker);
19929
+ if ((done.report?.total ?? 0) > 0) return true;
19930
+ const retired = join22(topicsHistoryRoot(binding), `topics-import.degenerate-${(/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "-")}.json`);
19931
+ renameSync7(marker, retired);
19932
+ console.warn(`[topics-import] total=0 \u5B8C\u6210\u6E05\u5355\u4F5C\u5E9F\uFF08\u6E05\u6D17\u9000\u5316\u5047\u5B8C\u6210\uFF0C\u95F8\u95E8\u91CD\u5F00\uFF09\u2192 ${retired}`);
19933
+ } catch {
19934
+ return false;
19935
+ }
19936
+ return false;
19925
19937
  }
19926
19938
 
19927
19939
  // src/memory/memdir/findRelevantMemoriesMem7.ts
@@ -2188,7 +2188,7 @@ init_schema_migrations();
2188
2188
  // src/continuity/inventory.ts
2189
2189
  import { isAbsolute, join as join6, relative, resolve as resolve5, sep } from "node:path";
2190
2190
  var STATE = new Set(`workspace agents auth configs cron media mem7 memory runtime session-memory steer tasks teams todos tools topics topics-history .everos .calendar calendar proactive skills prompts goals.json goal-events.jsonl SESSION-STATE.md install-identity.json license.json report-failures.jsonl report-state.json service-suggestions.json weixin cc-driver engines.json settings.json onboarding.json onboarding-tips.json remote-watchers.json plans telegram state`.split(" "));
2191
- var CORE_DIRECTORIES = new Set(`agents auth configs cron mem7 memory runtime session-memory steer tasks teams todos tools .everos .calendar calendar .proactive proactive skills prompts .nudge hooks inner-voice goals plans private scripts state .voice-chat .desktopBuddy body`.split(" "));
2191
+ var CORE_DIRECTORIES = new Set(`agents auth configs cron mem7 memory runtime session-memory steer tasks teams todos tools .everos .calendar calendar .proactive proactive skills prompts topics .nudge hooks inner-voice goals plans private scripts state .voice-chat .desktopBuddy body`.split(" "));
2192
2192
  var CORE_OMITTED = new Set(`media images videos audio content content-library docs output outputs dogfood-output backup backups topics-history node_modules .venvs venv .venv asr .cache cache caches tmp temp .playwright-mcp lancedb`.split(" "));
2193
2193
  function isWithin(root, candidate) {
2194
2194
  const rel = relative(resolve5(root), resolve5(candidate));
@@ -12921,7 +12921,7 @@ __export(import_mem7_exports, {
12921
12921
  topicsImported: () => topicsImported
12922
12922
  });
12923
12923
  import { DatabaseSync as DatabaseSync10 } from "node:sqlite";
12924
- import { existsSync as existsSync12, writeFileSync as writeFileSync12 } from "node:fs";
12924
+ import { existsSync as existsSync12, renameSync as renameSync8, writeFileSync as writeFileSync12 } from "node:fs";
12925
12925
  import { join as join22 } from "node:path";
12926
12926
  function loadIndexFragments(b) {
12927
12927
  const root = topicsHistoryRoot(b);
@@ -13100,7 +13100,7 @@ ${fragment.body}`;
13100
13100
  }
13101
13101
  }
13102
13102
  await flushEmbeddings();
13103
- if (report.failed === 0) {
13103
+ if (report.failed === 0 && report.total > 0) {
13104
13104
  writeFileSync12(doneMarker, JSON.stringify({ hashes: [.../* @__PURE__ */ new Set([...done, ...completed])], completedAt: (/* @__PURE__ */ new Date()).toISOString(), report }, null, 1));
13105
13105
  try {
13106
13106
  await completeTopicsImportBackup(b.stateDir, root);
@@ -13108,13 +13108,26 @@ ${fragment.body}`;
13108
13108
  } catch (error) {
13109
13109
  console.warn("[topics-import] backup retention deferred:", error instanceof Error ? error.message : String(error));
13110
13110
  }
13111
- } else console.warn(`[topics-import] ${report.failed} \u6761\u672A\u843D\u5E93\u2014\u2014\u5B8C\u6210\u6E05\u5355 withheld\uFF0C\u8F66\u9053\u4FDD\u6301\u5F00\u3001\u4E0B\u8F6E\u81EA\u52A8\u91CD\u8BD5`);
13111
+ } else if (report.failed === 0) console.warn("[topics-import] total=0\uFF08\u7A7A\u7D22\u5F15/\u6E05\u6D17\u9000\u5316\uFF09\u2014\u2014\u5B8C\u6210\u6E05\u5355 withheld\uFF0C\u95F8\u95E8\u4FDD\u6301\u672A\u5BFC\u5165\u6001");
13112
+ else console.warn(`[topics-import] ${report.failed} \u6761\u672A\u843D\u5E93\u2014\u2014\u5B8C\u6210\u6E05\u5355 withheld\uFF0C\u8F66\u9053\u4FDD\u6301\u5F00\u3001\u4E0B\u8F6E\u81EA\u52A8\u91CD\u8BD5`);
13112
13113
  return report;
13113
13114
  } finally {
13114
13115
  }
13115
13116
  }
13116
13117
  function topicsImported(binding2) {
13117
- return !!binding2.stateDir && existsSync12(join22(topicsHistoryRoot(binding2), "topics-import.json"));
13118
+ if (!binding2.stateDir) return false;
13119
+ const marker = join22(topicsHistoryRoot(binding2), "topics-import.json");
13120
+ if (!existsSync12(marker)) return false;
13121
+ try {
13122
+ const done = readJson(marker);
13123
+ if ((done.report?.total ?? 0) > 0) return true;
13124
+ const retired = join22(topicsHistoryRoot(binding2), `topics-import.degenerate-${(/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "-")}.json`);
13125
+ renameSync8(marker, retired);
13126
+ console.warn(`[topics-import] total=0 \u5B8C\u6210\u6E05\u5355\u4F5C\u5E9F\uFF08\u6E05\u6D17\u9000\u5316\u5047\u5B8C\u6210\uFF0C\u95F8\u95E8\u91CD\u5F00\uFF09\u2192 ${retired}`);
13127
+ } catch {
13128
+ return false;
13129
+ }
13130
+ return false;
13118
13131
  }
13119
13132
  function isZeroVector(v) {
13120
13133
  if (v === null || v === void 0) return false;
@@ -13257,7 +13270,7 @@ function loadSecretsEnvForConfig(configPath2, options = {}) {
13257
13270
 
13258
13271
  // src/memory/topics-history/background.ts
13259
13272
  init_materials();
13260
- import { existsSync as existsSync7, mkdirSync as mkdirSync8, writeFileSync as writeFileSync7, renameSync as renameSync4 } from "node:fs";
13273
+ import { existsSync as existsSync7, mkdirSync as mkdirSync8, renameSync as renameSync4, writeFileSync as writeFileSync7 } from "node:fs";
13261
13274
  import { join as join12 } from "node:path";
13262
13275
 
13263
13276
  // src/memory/topics-cleaning/runner.ts
@@ -13569,11 +13582,29 @@ async function runTopicsBackground(options) {
13569
13582
  const root = topicsHistoryRoot(b), batch = join12(root, "batches", fingerprint);
13570
13583
  mkdirSync8(batch, { recursive: true });
13571
13584
  const snapshot = join12(batch, "snapshot"), cleaned = join12(batch, "cleaned"), receipt = join12(batch, "receipt.json");
13585
+ let droppedAudit;
13586
+ const droppedStatus = () => droppedAudit ? { dropped: droppedAudit.dropped, droppedSample: droppedAudit.droppedSample } : {};
13587
+ const degenerate = (detail) => {
13588
+ const counterFile = join12(root, "degenerate-counter.json");
13589
+ const identityKey = digest(canonical([options.identity.model, options.identity.providerIdentity]));
13590
+ let count = 1;
13591
+ try {
13592
+ const prior = readJson(counterFile);
13593
+ if (prior?.identityKey === identityKey) count = (prior.count ?? 0) + 1;
13594
+ } catch {
13595
+ }
13596
+ const temp = join12(root, `.degenerate-${process.pid}.json`);
13597
+ writeFileSync7(temp, JSON.stringify({ identityKey, count, updatedAt: Date.now() }));
13598
+ renameSync4(temp, counterFile);
13599
+ topicsBackgroundStatus(b, { phase: "cleaning_degenerate", sources: records.length, degenerateCount: count, ...detail });
13600
+ console.warn(`[topics-history] cleaning degenerate\uFF08\u7B2C ${count} \u6B21\uFF09: \u4E0D\u53D1\u5E03\u4E0D\u5199 receipt\uFF0C\u9000\u907F\u7B49\u6E05\u6D17\u6A21\u578B\u66F4\u6362`, detail);
13601
+ return { status: "complete", backoff: true };
13602
+ };
13572
13603
  const { augmentTopicsVectors: augmentTopicsVectors2 } = await Promise.resolve().then(() => (init_vectors(), vectors_exports));
13573
13604
  const augmentVectors = async (sources) => {
13574
13605
  try {
13575
13606
  const report = await augmentTopicsVectors2(b, { yieldToOwner: options.waitForIdle });
13576
- topicsBackgroundStatus(b, { phase: "complete", sources, mem7StartDate: before, vectors: report.embedded, vectorTotal: report.total });
13607
+ topicsBackgroundStatus(b, { phase: "complete", sources, mem7StartDate: before, vectors: report.embedded, vectorTotal: report.total, ...droppedStatus() });
13577
13608
  console.log(`[topics-history] vector augment: ${report.embedded} newly embedded / ${report.total} paragraphs`);
13578
13609
  return report.embedded;
13579
13610
  } catch (error) {
@@ -13584,7 +13615,14 @@ async function runTopicsBackground(options) {
13584
13615
  if (existsSync7(receipt) && existsSync7(join12(root, "current.json"))) {
13585
13616
  const previous = readJson(receipt), current2 = readJson(join12(root, "current.json"));
13586
13617
  if (current2.version === previous.version) {
13587
- topicsBackgroundStatus(b, { phase: "complete", sources: records.length, mem7StartDate: before, version: current2.version });
13618
+ if (historicalHashes.size > 0) {
13619
+ try {
13620
+ const published = readJson(join12(root, String(current2.version), "manifest.json"));
13621
+ if ((published.entries ?? 0) === 0) return degenerate({ emptyIndex: current2.version, historical: historicalHashes.size });
13622
+ } catch {
13623
+ }
13624
+ }
13625
+ topicsBackgroundStatus(b, { phase: "complete", sources: records.length, mem7StartDate: before, version: current2.version, ...droppedStatus() });
13588
13626
  const embedded = await augmentVectors(records.length);
13589
13627
  return { status: "complete", version: current2.version, drained: embedded === 0 };
13590
13628
  }
@@ -13649,11 +13687,19 @@ async function runTopicsBackground(options) {
13649
13687
  return { status: "incomplete" };
13650
13688
  }
13651
13689
  }
13690
+ const cleanedManifest = readJson(join12(cleaned, "manifest.json"));
13691
+ const admittedHistorical = (cleanedManifest.items ?? []).reduce((sum, item) => sum + (historicalHashes.has(String(item.originalHash ?? "")) ? item.fragments?.length ?? 0 : 0), 0);
13692
+ if (historicalHashes.size > 0 && admittedHistorical === 0) return degenerate({ admitted: 0, historical: historicalHashes.size });
13693
+ const droppedSuspicious = (cleanedManifest.items ?? []).filter((item) => historicalHashes.has(String(item.originalHash ?? "")) && !(item.fragments?.length ?? 0) && item.omissions?.some((o) => o?.category === "uncertain")).map((item) => String(item.path ?? item.originalHash));
13694
+ if (droppedSuspicious.length) {
13695
+ droppedAudit = { dropped: droppedSuspicious.length, droppedSample: droppedSuspicious.slice(0, 10) };
13696
+ console.warn(`[topics-history] \u843D\u7F51\u6E05\u70B9: ${droppedSuspicious.length} \u7BC7\u5386\u53F2\u6587\u4EF6 0 \u6BB5\u51C6\u5165\u4E14\u542B uncertain \u6392\u9664\uFF08\u524D 10: ${droppedSuspicious.slice(0, 10).join("\u3001")}\uFF09`);
13697
+ }
13652
13698
  await options.waitForIdle();
13653
13699
  topicsBackgroundStatus(b, { phase: "indexing", sources: records.length });
13654
13700
  const version = await publishTopicsIndex(snapshot, cleaned, b);
13655
13701
  writeFileSync7(receipt, JSON.stringify({ fingerprint, version }));
13656
- topicsBackgroundStatus(b, { phase: "complete", sources: records.length, mem7StartDate: before, version });
13702
+ topicsBackgroundStatus(b, { phase: "complete", sources: records.length, mem7StartDate: before, version, ...droppedStatus() });
13657
13703
  await augmentVectors(records.length);
13658
13704
  return { status: "complete", version, drained: false };
13659
13705
  }
@@ -15752,9 +15798,9 @@ for (; ; ) {
15752
15798
  console.warn("[topics-history] vector backfill failed (retry next cycle):", error instanceof Error ? error.message : String(error));
15753
15799
  }
15754
15800
  }
15755
- if (result.drained) {
15801
+ if (result.drained || result.backoff) {
15756
15802
  process.send?.({ type: "drained" });
15757
- console.log("[topics-history] drained: nothing to do, worker exits");
15803
+ console.log(result.backoff ? "[topics-history] degenerate backoff: \u957F\u9000\u907F\u9000\u51FA\uFF08\u6362\u6E05\u6D17\u6A21\u578B\u540E\u81EA\u52A8\u8D70\u51FA\uFF09" : "[topics-history] drained: nothing to do, worker exits");
15758
15804
  break;
15759
15805
  }
15760
15806
  }