@joshuaswarren/openclaw-engram 9.1.10 → 9.1.12

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.
@@ -3,10 +3,10 @@ import {
3
3
  EngramAccessService,
4
4
  Orchestrator,
5
5
  parseConfig
6
- } from "./chunk-OQOCVPYG.js";
7
- import "./chunk-UO4TIAAW.js";
6
+ } from "./chunk-BEELVTEN.js";
7
+ import "./chunk-4PXEFPHR.js";
8
8
  import "./chunk-IMMYYNXG.js";
9
- import "./chunk-YKWJUR3I.js";
9
+ import "./chunk-4XBRUH6C.js";
10
10
  import "./chunk-6KX4XLQJ.js";
11
11
  import "./chunk-XCAYYSI7.js";
12
12
  import "./chunk-MKM2BCQH.js";
@@ -4,7 +4,7 @@ import {
4
4
  parseContinuityImprovementLoops,
5
5
  parseContinuityIncident,
6
6
  sanitizeMemoryContent
7
- } from "./chunk-YKWJUR3I.js";
7
+ } from "./chunk-4XBRUH6C.js";
8
8
  import {
9
9
  log
10
10
  } from "./chunk-SSIIJJKA.js";
@@ -1837,4 +1837,4 @@ export {
1837
1837
  defaultTierMigrationCycleBudget,
1838
1838
  CompoundingEngine
1839
1839
  };
1840
- //# sourceMappingURL=chunk-UO4TIAAW.js.map
1840
+ //# sourceMappingURL=chunk-4PXEFPHR.js.map
@@ -9,6 +9,75 @@ import { appendFileSync, mkdirSync, statSync } from "fs";
9
9
  import { createHash } from "crypto";
10
10
  import path4 from "path";
11
11
 
12
+ // src/memory-cache.ts
13
+ var entityCacheByDir = /* @__PURE__ */ new Map();
14
+ function getCachedEntities(baseDir, currentVersion) {
15
+ if (currentVersion === 0) return null;
16
+ const entry = entityCacheByDir.get(baseDir);
17
+ if (!entry || entry.version !== currentVersion) return null;
18
+ return entry.entities;
19
+ }
20
+ function setCachedEntities(baseDir, entities, version) {
21
+ entityCacheByDir.set(baseDir, { entities, version, loadedAt: Date.now() });
22
+ }
23
+ var episodeMapByDir = /* @__PURE__ */ new Map();
24
+ var ruleMemoriesByDir = /* @__PURE__ */ new Map();
25
+ function getCachedEpisodeMap(baseDir, currentVersion) {
26
+ if (currentVersion === 0) return null;
27
+ const entry = episodeMapByDir.get(baseDir);
28
+ if (!entry || entry.sourceVersion !== currentVersion) return null;
29
+ return entry.data;
30
+ }
31
+ function setCachedEpisodeMap(baseDir, memories, version) {
32
+ const map = /* @__PURE__ */ new Map();
33
+ for (const m of memories) {
34
+ if (m.frontmatter.status === "archived") continue;
35
+ if (m.frontmatter.memoryKind !== "episode") continue;
36
+ map.set(m.frontmatter.id, m);
37
+ }
38
+ episodeMapByDir.set(baseDir, { data: map, sourceVersion: version });
39
+ return map;
40
+ }
41
+ function getCachedRuleMemories(baseDir, currentVersion) {
42
+ if (currentVersion === 0) return null;
43
+ const entry = ruleMemoriesByDir.get(baseDir);
44
+ if (!entry || entry.sourceVersion !== currentVersion) return null;
45
+ return entry.data;
46
+ }
47
+ function setCachedRuleMemories(baseDir, memories, version) {
48
+ const byId = /* @__PURE__ */ new Map();
49
+ const all = [];
50
+ for (const m of memories) {
51
+ byId.set(m.frontmatter.id, m);
52
+ if (m.frontmatter.category === "rule" && m.frontmatter.status !== "archived") {
53
+ all.push(m);
54
+ }
55
+ }
56
+ const result = { all, byId };
57
+ ruleMemoriesByDir.set(baseDir, { data: result, sourceVersion: version });
58
+ return result;
59
+ }
60
+ var QMD_CACHE_TTL_MS = 6e4;
61
+ var qmdSearchCache = /* @__PURE__ */ new Map();
62
+ function getCachedQmdSearch(cacheKey) {
63
+ const entry = qmdSearchCache.get(cacheKey);
64
+ if (!entry) return null;
65
+ if (Date.now() - entry.cachedAt > QMD_CACHE_TTL_MS) {
66
+ qmdSearchCache.delete(cacheKey);
67
+ return null;
68
+ }
69
+ return entry.results;
70
+ }
71
+ function setCachedQmdSearch(cacheKey, results) {
72
+ qmdSearchCache.set(cacheKey, { results, cachedAt: Date.now() });
73
+ if (qmdSearchCache.size > 200) {
74
+ const now = Date.now();
75
+ for (const [key, entry] of qmdSearchCache) {
76
+ if (now - entry.cachedAt > QMD_CACHE_TTL_MS) qmdSearchCache.delete(key);
77
+ }
78
+ }
79
+ }
80
+
12
81
  // src/hygiene.ts
13
82
  import { mkdir, readFile, stat, writeFile } from "fs/promises";
14
83
  import path from "path";
@@ -2051,6 +2120,7 @@ ${sanitized.text}
2051
2120
  entity.updated = (/* @__PURE__ */ new Date()).toISOString();
2052
2121
  await writeFile2(filePath, serializeEntityFile(entity), "utf-8");
2053
2122
  this.invalidateKnowledgeIndexCache();
2123
+ this.bumpMemoryStatusVersion();
2054
2124
  log.debug(`wrote entity ${normalized}`);
2055
2125
  return normalized;
2056
2126
  }
@@ -3378,6 +3448,7 @@ ${reflection}
3378
3448
  entity.updated = (/* @__PURE__ */ new Date()).toISOString();
3379
3449
  await writeFile2(filePath, serializeEntityFile(entity), "utf-8");
3380
3450
  this.invalidateKnowledgeIndexCache();
3451
+ this.bumpMemoryStatusVersion();
3381
3452
  }
3382
3453
  // ---------------------------------------------------------------------------
3383
3454
  // Scoring + Knowledge Index (Knowledge Graph v7.0)
@@ -3387,6 +3458,9 @@ ${reflection}
3387
3458
  * Parsing is fast (~50-100ms for ~1,800 files) since entity files are small.
3388
3459
  */
3389
3460
  async readAllEntityFiles() {
3461
+ const currentVersion = this.getMemoryStatusVersion();
3462
+ const cached = getCachedEntities(this.baseDir, currentVersion);
3463
+ if (cached) return cached;
3390
3464
  try {
3391
3465
  const entries = await readdir(this.entitiesDir);
3392
3466
  const mdFiles = entries.filter((e) => e.endsWith(".md"));
@@ -3404,6 +3478,7 @@ ${reflection}
3404
3478
  if (content !== null) entities.push(parseEntityFile(content));
3405
3479
  }
3406
3480
  }
3481
+ setCachedEntities(this.baseDir, entities, currentVersion);
3407
3482
  return entities;
3408
3483
  } catch {
3409
3484
  return [];
@@ -3980,6 +4055,12 @@ ${memory.content}
3980
4055
 
3981
4056
  export {
3982
4057
  sanitizeMemoryContent,
4058
+ getCachedEpisodeMap,
4059
+ setCachedEpisodeMap,
4060
+ getCachedRuleMemories,
4061
+ setCachedRuleMemories,
4062
+ getCachedQmdSearch,
4063
+ setCachedQmdSearch,
3983
4064
  lintWorkspaceFiles,
3984
4065
  rotateMarkdownFileToArchive,
3985
4066
  confidenceTier,
@@ -4007,4 +4088,4 @@ export {
4007
4088
  serializeEntityFile,
4008
4089
  StorageManager
4009
4090
  };
4010
- //# sourceMappingURL=chunk-YKWJUR3I.js.map
4091
+ //# sourceMappingURL=chunk-4XBRUH6C.js.map