@remnic/core 10.0.101 → 10.0.103

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.
Files changed (36) hide show
  1. package/dist/access-admin-ops-surface.js +2 -2
  2. package/dist/access-cli.js +2 -2
  3. package/dist/access-extraction-force-flush.js +2 -2
  4. package/dist/access-http-briefing.js +2 -2
  5. package/dist/access-http-query.js +2 -2
  6. package/dist/access-http.js +2 -2
  7. package/dist/access-identity-continuity-surface.js +2 -2
  8. package/dist/access-lcm-surface.js +2 -2
  9. package/dist/access-mcp.js +2 -2
  10. package/dist/access-observe-write-surface.js +2 -2
  11. package/dist/access-operations-batch.js +2 -2
  12. package/dist/access-operations.js +2 -2
  13. package/dist/access-recall-concurrency.js +2 -2
  14. package/dist/access-recall-response.js +2 -2
  15. package/dist/access-recall-surface.js +2 -2
  16. package/dist/access-service.js +2 -2
  17. package/dist/{chunk-QIPDTAWZ.js → chunk-D77I4MD4.js} +2 -2
  18. package/dist/{chunk-PL36IQPL.js → chunk-KCRHFW3N.js} +69 -20
  19. package/dist/chunk-KCRHFW3N.js.map +1 -0
  20. package/dist/{chunk-MMOXCCHF.js → chunk-T3X4CCHC.js} +2 -2
  21. package/dist/cli.js +2 -2
  22. package/dist/explicit-capture.js +2 -2
  23. package/dist/harmonic-retrieval.d.ts +14 -4
  24. package/dist/harmonic-retrieval.d.ts.map +1 -1
  25. package/dist/harmonic-retrieval.js +5 -3
  26. package/dist/index.js +2 -2
  27. package/dist/orchestration/backlog-scheduler.js +3 -3
  28. package/dist/orchestration/buffer-drain-runner.js +3 -3
  29. package/dist/orchestrator.js +2 -2
  30. package/dist/recall-navigation.js +2 -2
  31. package/package.json +2 -2
  32. package/src/harmonic-graph-cache.test.ts +172 -7
  33. package/src/harmonic-retrieval.ts +125 -27
  34. package/dist/chunk-PL36IQPL.js.map +0 -1
  35. /package/dist/{chunk-QIPDTAWZ.js.map → chunk-D77I4MD4.js.map} +0 -0
  36. /package/dist/{chunk-MMOXCCHF.js.map → chunk-T3X4CCHC.js.map} +0 -0
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  AccessAdminOpsSurface
3
- } from "./chunk-MMOXCCHF.js";
3
+ } from "./chunk-T3X4CCHC.js";
4
4
  import "./chunk-6P7U3HWG.js";
5
5
  import "./chunk-PQM3B54K.js";
6
6
  import "./chunk-B3DR2JBZ.js";
@@ -173,7 +173,7 @@ import "./chunk-MDPT6QFK.js";
173
173
  import "./chunk-UOBPK2OS.js";
174
174
  import "./chunk-2YA5N2BY.js";
175
175
  import "./chunk-3HSRWJTC.js";
176
- import "./chunk-PL36IQPL.js";
176
+ import "./chunk-KCRHFW3N.js";
177
177
  import "./chunk-HUDPXTXW.js";
178
178
  import "./chunk-AZEZSQ5R.js";
179
179
  import "./chunk-YAZNBMNF.js";
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  EngramAccessService,
3
3
  Orchestrator
4
- } from "./chunk-MMOXCCHF.js";
4
+ } from "./chunk-T3X4CCHC.js";
5
5
  import "./chunk-6P7U3HWG.js";
6
6
  import "./chunk-PQM3B54K.js";
7
7
  import "./chunk-B3DR2JBZ.js";
@@ -176,7 +176,7 @@ import "./chunk-MDPT6QFK.js";
176
176
  import "./chunk-UOBPK2OS.js";
177
177
  import "./chunk-2YA5N2BY.js";
178
178
  import "./chunk-3HSRWJTC.js";
179
- import "./chunk-PL36IQPL.js";
179
+ import "./chunk-KCRHFW3N.js";
180
180
  import "./chunk-HUDPXTXW.js";
181
181
  import "./chunk-AZEZSQ5R.js";
182
182
  import "./chunk-YAZNBMNF.js";
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  extractionForceFlush
3
- } from "./chunk-MMOXCCHF.js";
3
+ } from "./chunk-T3X4CCHC.js";
4
4
  import "./chunk-6P7U3HWG.js";
5
5
  import "./chunk-PQM3B54K.js";
6
6
  import "./chunk-B3DR2JBZ.js";
@@ -173,7 +173,7 @@ import "./chunk-MDPT6QFK.js";
173
173
  import "./chunk-UOBPK2OS.js";
174
174
  import "./chunk-2YA5N2BY.js";
175
175
  import "./chunk-3HSRWJTC.js";
176
- import "./chunk-PL36IQPL.js";
176
+ import "./chunk-KCRHFW3N.js";
177
177
  import "./chunk-HUDPXTXW.js";
178
178
  import "./chunk-AZEZSQ5R.js";
179
179
  import "./chunk-YAZNBMNF.js";
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  respondBriefingHttp
3
- } from "./chunk-MMOXCCHF.js";
3
+ } from "./chunk-T3X4CCHC.js";
4
4
  import "./chunk-6P7U3HWG.js";
5
5
  import "./chunk-PQM3B54K.js";
6
6
  import "./chunk-B3DR2JBZ.js";
@@ -173,7 +173,7 @@ import "./chunk-MDPT6QFK.js";
173
173
  import "./chunk-UOBPK2OS.js";
174
174
  import "./chunk-2YA5N2BY.js";
175
175
  import "./chunk-3HSRWJTC.js";
176
- import "./chunk-PL36IQPL.js";
176
+ import "./chunk-KCRHFW3N.js";
177
177
  import "./chunk-HUDPXTXW.js";
178
178
  import "./chunk-AZEZSQ5R.js";
179
179
  import "./chunk-YAZNBMNF.js";
@@ -3,7 +3,7 @@ import {
3
3
  optionalNamespaceKindQueryParam,
4
4
  optionalQueryString,
5
5
  positiveIntQueryParam
6
- } from "./chunk-MMOXCCHF.js";
6
+ } from "./chunk-T3X4CCHC.js";
7
7
  import "./chunk-6P7U3HWG.js";
8
8
  import "./chunk-PQM3B54K.js";
9
9
  import "./chunk-B3DR2JBZ.js";
@@ -176,7 +176,7 @@ import "./chunk-MDPT6QFK.js";
176
176
  import "./chunk-UOBPK2OS.js";
177
177
  import "./chunk-2YA5N2BY.js";
178
178
  import "./chunk-3HSRWJTC.js";
179
- import "./chunk-PL36IQPL.js";
179
+ import "./chunk-KCRHFW3N.js";
180
180
  import "./chunk-HUDPXTXW.js";
181
181
  import "./chunk-AZEZSQ5R.js";
182
182
  import "./chunk-YAZNBMNF.js";
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  EngramAccessHttpServer,
3
3
  resolveDefaultAdminConsolePublicDir
4
- } from "./chunk-MMOXCCHF.js";
4
+ } from "./chunk-T3X4CCHC.js";
5
5
  import "./chunk-6P7U3HWG.js";
6
6
  import "./chunk-PQM3B54K.js";
7
7
  import "./chunk-B3DR2JBZ.js";
@@ -174,7 +174,7 @@ import "./chunk-MDPT6QFK.js";
174
174
  import "./chunk-UOBPK2OS.js";
175
175
  import "./chunk-2YA5N2BY.js";
176
176
  import "./chunk-3HSRWJTC.js";
177
- import "./chunk-PL36IQPL.js";
177
+ import "./chunk-KCRHFW3N.js";
178
178
  import "./chunk-HUDPXTXW.js";
179
179
  import "./chunk-AZEZSQ5R.js";
180
180
  import "./chunk-YAZNBMNF.js";
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  AccessIdentityContinuitySurface
3
- } from "./chunk-MMOXCCHF.js";
3
+ } from "./chunk-T3X4CCHC.js";
4
4
  import "./chunk-6P7U3HWG.js";
5
5
  import "./chunk-PQM3B54K.js";
6
6
  import "./chunk-B3DR2JBZ.js";
@@ -173,7 +173,7 @@ import "./chunk-MDPT6QFK.js";
173
173
  import "./chunk-UOBPK2OS.js";
174
174
  import "./chunk-2YA5N2BY.js";
175
175
  import "./chunk-3HSRWJTC.js";
176
- import "./chunk-PL36IQPL.js";
176
+ import "./chunk-KCRHFW3N.js";
177
177
  import "./chunk-HUDPXTXW.js";
178
178
  import "./chunk-AZEZSQ5R.js";
179
179
  import "./chunk-YAZNBMNF.js";
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  AccessLcmSurface
3
- } from "./chunk-MMOXCCHF.js";
3
+ } from "./chunk-T3X4CCHC.js";
4
4
  import "./chunk-6P7U3HWG.js";
5
5
  import "./chunk-PQM3B54K.js";
6
6
  import "./chunk-B3DR2JBZ.js";
@@ -173,7 +173,7 @@ import "./chunk-MDPT6QFK.js";
173
173
  import "./chunk-UOBPK2OS.js";
174
174
  import "./chunk-2YA5N2BY.js";
175
175
  import "./chunk-3HSRWJTC.js";
176
- import "./chunk-PL36IQPL.js";
176
+ import "./chunk-KCRHFW3N.js";
177
177
  import "./chunk-HUDPXTXW.js";
178
178
  import "./chunk-AZEZSQ5R.js";
179
179
  import "./chunk-YAZNBMNF.js";
@@ -2,7 +2,7 @@ import {
2
2
  EngramMcpServer,
3
3
  MCP_MIGRATED_OPERATIONS,
4
4
  MCP_SUPPORTED_PROTOCOL_VERSIONS
5
- } from "./chunk-MMOXCCHF.js";
5
+ } from "./chunk-T3X4CCHC.js";
6
6
  import "./chunk-6P7U3HWG.js";
7
7
  import "./chunk-PQM3B54K.js";
8
8
  import "./chunk-B3DR2JBZ.js";
@@ -175,7 +175,7 @@ import "./chunk-MDPT6QFK.js";
175
175
  import "./chunk-UOBPK2OS.js";
176
176
  import "./chunk-2YA5N2BY.js";
177
177
  import "./chunk-3HSRWJTC.js";
178
- import "./chunk-PL36IQPL.js";
178
+ import "./chunk-KCRHFW3N.js";
179
179
  import "./chunk-HUDPXTXW.js";
180
180
  import "./chunk-AZEZSQ5R.js";
181
181
  import "./chunk-YAZNBMNF.js";
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  AccessObserveWriteSurface
3
- } from "./chunk-MMOXCCHF.js";
3
+ } from "./chunk-T3X4CCHC.js";
4
4
  import "./chunk-6P7U3HWG.js";
5
5
  import "./chunk-PQM3B54K.js";
6
6
  import "./chunk-B3DR2JBZ.js";
@@ -173,7 +173,7 @@ import "./chunk-MDPT6QFK.js";
173
173
  import "./chunk-UOBPK2OS.js";
174
174
  import "./chunk-2YA5N2BY.js";
175
175
  import "./chunk-3HSRWJTC.js";
176
- import "./chunk-PL36IQPL.js";
176
+ import "./chunk-KCRHFW3N.js";
177
177
  import "./chunk-HUDPXTXW.js";
178
178
  import "./chunk-AZEZSQ5R.js";
179
179
  import "./chunk-YAZNBMNF.js";
@@ -1,4 +1,4 @@
1
- import "./chunk-MMOXCCHF.js";
1
+ import "./chunk-T3X4CCHC.js";
2
2
  import "./chunk-6P7U3HWG.js";
3
3
  import "./chunk-PQM3B54K.js";
4
4
  import "./chunk-B3DR2JBZ.js";
@@ -171,7 +171,7 @@ import "./chunk-MDPT6QFK.js";
171
171
  import "./chunk-UOBPK2OS.js";
172
172
  import "./chunk-2YA5N2BY.js";
173
173
  import "./chunk-3HSRWJTC.js";
174
- import "./chunk-PL36IQPL.js";
174
+ import "./chunk-KCRHFW3N.js";
175
175
  import "./chunk-HUDPXTXW.js";
176
176
  import "./chunk-AZEZSQ5R.js";
177
177
  import "./chunk-YAZNBMNF.js";
@@ -22,7 +22,7 @@ import {
22
22
  memoryGetOperation,
23
23
  memorySearchOperation,
24
24
  memoryStoreOperation
25
- } from "./chunk-MMOXCCHF.js";
25
+ } from "./chunk-T3X4CCHC.js";
26
26
  import "./chunk-6P7U3HWG.js";
27
27
  import "./chunk-PQM3B54K.js";
28
28
  import "./chunk-B3DR2JBZ.js";
@@ -195,7 +195,7 @@ import "./chunk-MDPT6QFK.js";
195
195
  import "./chunk-UOBPK2OS.js";
196
196
  import "./chunk-2YA5N2BY.js";
197
197
  import "./chunk-3HSRWJTC.js";
198
- import "./chunk-PL36IQPL.js";
198
+ import "./chunk-KCRHFW3N.js";
199
199
  import "./chunk-HUDPXTXW.js";
200
200
  import "./chunk-AZEZSQ5R.js";
201
201
  import "./chunk-YAZNBMNF.js";
@@ -4,7 +4,7 @@ import {
4
4
  createAndStartFlight,
5
5
  leadRecallFlight,
6
6
  withRecallConcurrency
7
- } from "./chunk-MMOXCCHF.js";
7
+ } from "./chunk-T3X4CCHC.js";
8
8
  import "./chunk-6P7U3HWG.js";
9
9
  import "./chunk-PQM3B54K.js";
10
10
  import "./chunk-B3DR2JBZ.js";
@@ -177,7 +177,7 @@ import "./chunk-MDPT6QFK.js";
177
177
  import "./chunk-UOBPK2OS.js";
178
178
  import "./chunk-2YA5N2BY.js";
179
179
  import "./chunk-3HSRWJTC.js";
180
- import "./chunk-PL36IQPL.js";
180
+ import "./chunk-KCRHFW3N.js";
181
181
  import "./chunk-HUDPXTXW.js";
182
182
  import "./chunk-AZEZSQ5R.js";
183
183
  import "./chunk-YAZNBMNF.js";
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  assembleRecallResponse
3
- } from "./chunk-MMOXCCHF.js";
3
+ } from "./chunk-T3X4CCHC.js";
4
4
  import "./chunk-6P7U3HWG.js";
5
5
  import "./chunk-PQM3B54K.js";
6
6
  import "./chunk-B3DR2JBZ.js";
@@ -173,7 +173,7 @@ import "./chunk-MDPT6QFK.js";
173
173
  import "./chunk-UOBPK2OS.js";
174
174
  import "./chunk-2YA5N2BY.js";
175
175
  import "./chunk-3HSRWJTC.js";
176
- import "./chunk-PL36IQPL.js";
176
+ import "./chunk-KCRHFW3N.js";
177
177
  import "./chunk-HUDPXTXW.js";
178
178
  import "./chunk-AZEZSQ5R.js";
179
179
  import "./chunk-YAZNBMNF.js";
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  AccessRecallSurface
3
- } from "./chunk-MMOXCCHF.js";
3
+ } from "./chunk-T3X4CCHC.js";
4
4
  import "./chunk-6P7U3HWG.js";
5
5
  import "./chunk-PQM3B54K.js";
6
6
  import "./chunk-B3DR2JBZ.js";
@@ -173,7 +173,7 @@ import "./chunk-MDPT6QFK.js";
173
173
  import "./chunk-UOBPK2OS.js";
174
174
  import "./chunk-2YA5N2BY.js";
175
175
  import "./chunk-3HSRWJTC.js";
176
- import "./chunk-PL36IQPL.js";
176
+ import "./chunk-KCRHFW3N.js";
177
177
  import "./chunk-HUDPXTXW.js";
178
178
  import "./chunk-AZEZSQ5R.js";
179
179
  import "./chunk-YAZNBMNF.js";
@@ -4,7 +4,7 @@ import {
4
4
  buildProjectedGovernanceProposedActions,
5
5
  hasGroupedGovernanceActions,
6
6
  shapeMemorySummary
7
- } from "./chunk-MMOXCCHF.js";
7
+ } from "./chunk-T3X4CCHC.js";
8
8
  import "./chunk-6P7U3HWG.js";
9
9
  import "./chunk-PQM3B54K.js";
10
10
  import "./chunk-B3DR2JBZ.js";
@@ -177,7 +177,7 @@ import "./chunk-MDPT6QFK.js";
177
177
  import "./chunk-UOBPK2OS.js";
178
178
  import "./chunk-2YA5N2BY.js";
179
179
  import "./chunk-3HSRWJTC.js";
180
- import "./chunk-PL36IQPL.js";
180
+ import "./chunk-KCRHFW3N.js";
181
181
  import "./chunk-HUDPXTXW.js";
182
182
  import "./chunk-AZEZSQ5R.js";
183
183
  import "./chunk-YAZNBMNF.js";
@@ -2,7 +2,7 @@ import {
2
2
  ExtractionDrain,
3
3
  TurnIngestionCoordinator,
4
4
  shouldSkipImplicitExtraction
5
- } from "./chunk-MMOXCCHF.js";
5
+ } from "./chunk-T3X4CCHC.js";
6
6
  import {
7
7
  headerConnector,
8
8
  renderExtractionConversation,
@@ -447,4 +447,4 @@ export {
447
447
  ClaimBufferStorage,
448
448
  BufferDrainRunner
449
449
  };
450
- //# sourceMappingURL=chunk-QIPDTAWZ.js.map
450
+ //# sourceMappingURL=chunk-D77I4MD4.js.map
@@ -58,6 +58,9 @@ import {
58
58
  import {
59
59
  RECALL_FALLBACK_DIRS
60
60
  } from "./chunk-VS2IYZRU.js";
61
+ import {
62
+ log
63
+ } from "./chunk-3WCASNQZ.js";
61
64
 
62
65
  // src/harmonic-retrieval.ts
63
66
  import path from "path";
@@ -170,16 +173,15 @@ function parseSourceMemoryInsertedAt(node) {
170
173
  }
171
174
  return insertedAtById;
172
175
  }
176
+ function isEligibleSourceMemory(memory, memoryDir) {
177
+ return !isSupportPassportPrivateMemory(memory) && inferMemoryStatus(memory.frontmatter, toMemoryPathRel(memoryDir, memory.path)) === "active";
178
+ }
173
179
  function projectSourceBackedNode(node, sourceMemories, memoryDir, temporalExpiredInInjection, nowMs) {
174
180
  const sourceMemoryIds = node.sourceMemoryIds ?? [];
175
181
  if (sourceMemoryIds.length === 0) return node;
176
182
  const activeSourceMemoryIds = sourceMemoryIds.filter((memoryId) => {
177
183
  const memory = sourceMemories.get(memoryId);
178
- return memory !== void 0 && // #2332: a private support-passport record leaves the eligible set the
179
- // same way a rejected one does — a node title or anchor attribution
180
- // rebuilt from it would leak governed metadata into the deep-recall
181
- // frontier (and every other graph reader) before any content check runs.
182
- !isSupportPassportPrivateMemory(memory) && inferMemoryStatus(memory.frontmatter, toMemoryPathRel(memoryDir, memory.path)) === "active" && (temporalExpiredInInjection || !isValidityExpiredNow(memory.frontmatter, nowMs));
184
+ return memory !== void 0 && isEligibleSourceMemory(memory, memoryDir) && (temporalExpiredInInjection || !isValidityExpiredNow(memory.frontmatter, nowMs));
183
185
  });
184
186
  if (activeSourceMemoryIds.length === 0) return null;
185
187
  const insertedAtById = parseSourceMemoryInsertedAt(node);
@@ -308,7 +310,20 @@ async function readCueAnchors(options) {
308
310
  }
309
311
  return anchors;
310
312
  }
313
+ function earliestInvalidAtMs(sourceMemories, memoryDir, nowMs) {
314
+ let earliest = Number.POSITIVE_INFINITY;
315
+ for (const memory of sourceMemories.values()) {
316
+ if (!isEligibleSourceMemory(memory, memoryDir)) continue;
317
+ const invalidAtMs = Date.parse(memory.frontmatter.invalid_at?.trim() ?? "");
318
+ if (Number.isFinite(invalidAtMs) && invalidAtMs > nowMs && invalidAtMs < earliest) earliest = invalidAtMs;
319
+ }
320
+ return earliest;
321
+ }
311
322
  async function buildProjectedHarmonicGraph(options) {
323
+ const { nodes, anchors } = await buildExpiringHarmonicGraph(options);
324
+ return { nodes, anchors };
325
+ }
326
+ async function buildExpiringHarmonicGraph(options) {
312
327
  throwIfAborted(options.abortSignal, "harmonic retrieval aborted");
313
328
  const nodes = await readAbstractionNodes(options);
314
329
  const sourceMemoryIds = [...new Set(nodes.flatMap((node) => node.sourceMemoryIds ?? []))];
@@ -319,6 +334,7 @@ async function buildProjectedHarmonicGraph(options) {
319
334
  nowMs: options.nowMs
320
335
  }) : /* @__PURE__ */ new Map();
321
336
  const nowMs = options.nowMs ?? Date.now();
337
+ const validUntilMs = options.temporalExpiredInInjection === true ? Number.POSITIVE_INFINITY : earliestInvalidAtMs(sourceMemories, options.memoryDir, nowMs);
322
338
  const legacyCompatibleNodeRefs = /* @__PURE__ */ new Set();
323
339
  const projectedNodes = nodes.flatMap((node) => {
324
340
  const projected = projectSourceBackedNode(
@@ -333,7 +349,7 @@ async function buildProjectedHarmonicGraph(options) {
333
349
  }
334
350
  return projected ? [projected] : [];
335
351
  });
336
- if (!options.anchorsEnabled) return { nodes: projectedNodes, anchors: [] };
352
+ if (!options.anchorsEnabled) return { nodes: projectedNodes, anchors: [], validUntilMs };
337
353
  throwIfAborted(options.abortSignal, "harmonic retrieval aborted");
338
354
  const nodeIndex = new Map(projectedNodes.map((node) => [node.nodeId, node]));
339
355
  const anchors = (await readCueAnchors(options)).flatMap((anchor) => {
@@ -344,13 +360,36 @@ async function buildProjectedHarmonicGraph(options) {
344
360
  });
345
361
  return nodeRefs.length > 0 ? [{ ...anchor, nodeRefs }] : [];
346
362
  });
347
- return { nodes: projectedNodes, anchors };
363
+ return { nodes: projectedNodes, anchors, validUntilMs };
348
364
  }
349
365
  var GRAPH_CACHE_TTL_MS = 3e4;
366
+ var GRAPH_CACHE_MAX_STALE_MS = 3e5;
350
367
  var GRAPH_CACHE_MAX_ENTRIES = 8;
351
368
  var graphCache = /* @__PURE__ */ new Map();
352
369
  var graphBuilds = /* @__PURE__ */ new Map();
353
- var harmonicGraphCacheStats = { hits: 0, misses: 0, shared: 0 };
370
+ var refreshFailedAtMs = /* @__PURE__ */ new Map();
371
+ function rememberRefreshFailure(key) {
372
+ refreshFailedAtMs.delete(key);
373
+ refreshFailedAtMs.set(key, Date.now());
374
+ while (refreshFailedAtMs.size > GRAPH_CACHE_MAX_ENTRIES) {
375
+ const oldest = refreshFailedAtMs.keys().next().value;
376
+ if (oldest === void 0) break;
377
+ refreshFailedAtMs.delete(oldest);
378
+ }
379
+ }
380
+ async function buildUnexpiredHarmonicGraph(options, abortSignal) {
381
+ for (; ; ) {
382
+ const built = await buildExpiringHarmonicGraph({
383
+ memoryDir: options.memoryDir,
384
+ abstractionNodeStoreDir: options.abstractionNodeStoreDir,
385
+ anchorsEnabled: options.anchorsEnabled,
386
+ temporalExpiredInInjection: options.temporalExpiredInInjection,
387
+ abortSignal
388
+ });
389
+ if (Date.now() < built.validUntilMs) return built;
390
+ }
391
+ }
392
+ var harmonicGraphCacheStats = { hits: 0, misses: 0, stale: 0, shared: 0 };
354
393
  function deepFreeze(value) {
355
394
  if (Object.isFrozen(value)) return value;
356
395
  Object.freeze(value);
@@ -360,22 +399,20 @@ function deepFreeze(value) {
360
399
  function clearHarmonicGraphCache() {
361
400
  graphCache.clear();
362
401
  graphBuilds.clear();
402
+ refreshFailedAtMs.clear();
403
+ }
404
+ async function settleHarmonicGraphBuilds() {
405
+ await Promise.allSettled([...graphBuilds.values()].map((build) => build.promise));
363
406
  }
364
407
  function startGraphBuild(key, stamp, options) {
365
408
  harmonicGraphCacheStats.misses++;
366
- const startedAtMs = Date.now();
367
409
  const controller = new AbortController();
368
- const promise = buildProjectedHarmonicGraph({
369
- memoryDir: options.memoryDir,
370
- abstractionNodeStoreDir: options.abstractionNodeStoreDir,
371
- anchorsEnabled: options.anchorsEnabled,
372
- temporalExpiredInInjection: options.temporalExpiredInInjection,
373
- abortSignal: controller.signal
374
- }).then((built) => {
410
+ const promise = buildUnexpiredHarmonicGraph(options, controller.signal).then((built) => {
375
411
  const graph = { nodes: deepFreeze(built.nodes), anchors: deepFreeze(built.anchors) };
376
412
  if (graphBuilds.get(key)?.promise !== promise) return graph;
413
+ refreshFailedAtMs.delete(key);
377
414
  graphCache.delete(key);
378
- graphCache.set(key, { stamp, startedAtMs, graph });
415
+ graphCache.set(key, { stamp, builtAtMs: Date.now(), validUntilMs: built.validUntilMs, graph });
379
416
  while (graphCache.size > GRAPH_CACHE_MAX_ENTRIES) {
380
417
  const oldest = graphCache.keys().next().value;
381
418
  if (oldest === void 0) break;
@@ -409,12 +446,23 @@ async function readProjectedHarmonicGraph(options) {
409
446
  options.temporalExpiredInInjection === true
410
447
  ]);
411
448
  const stamp = readHarmonicGraphStamp(options.memoryDir, nodeStoreDir);
412
- const startedAtMs = Date.now();
449
+ const nowMs = Date.now();
413
450
  const hit = graphCache.get(key);
414
- if (hit && hit.stamp === stamp && startedAtMs - hit.startedAtMs < GRAPH_CACHE_TTL_MS) {
451
+ if (hit && hit.stamp === stamp && nowMs < hit.validUntilMs && nowMs - hit.builtAtMs < GRAPH_CACHE_TTL_MS + GRAPH_CACHE_MAX_STALE_MS) {
415
452
  harmonicGraphCacheStats.hits++;
416
453
  graphCache.delete(key);
417
454
  graphCache.set(key, hit);
455
+ if (nowMs - hit.builtAtMs >= GRAPH_CACHE_TTL_MS) {
456
+ harmonicGraphCacheStats.stale++;
457
+ const failedAtMs = refreshFailedAtMs.get(key);
458
+ const backingOff = failedAtMs !== void 0 && nowMs - failedAtMs < GRAPH_CACHE_TTL_MS;
459
+ if (graphBuilds.get(key)?.stamp !== stamp && !backingOff) {
460
+ startGraphBuild(key, stamp, options).promise.catch((err) => {
461
+ rememberRefreshFailure(key);
462
+ log.debug(`harmonic graph refresh failed: ${err}`);
463
+ });
464
+ }
465
+ }
418
466
  return hit.graph;
419
467
  }
420
468
  const running = graphBuilds.get(key);
@@ -500,7 +548,8 @@ export {
500
548
  readCueAnchors,
501
549
  harmonicGraphCacheStats,
502
550
  clearHarmonicGraphCache,
551
+ settleHarmonicGraphBuilds,
503
552
  readProjectedHarmonicGraph,
504
553
  searchHarmonicRetrieval
505
554
  };
506
- //# sourceMappingURL=chunk-PL36IQPL.js.map
555
+ //# sourceMappingURL=chunk-KCRHFW3N.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/harmonic-retrieval.ts"],"sourcesContent":["import path from \"node:path\";\nimport { realpath } from \"node:fs/promises\";\nimport { listJsonFilesStrict, readJsonFile } from \"./json-store.js\";\nimport { raceAbort, throwIfAborted } from \"./abort-error.js\";\nimport { log } from \"./logger.js\";\nimport { readHarmonicGraphStamp } from \"./harmonic-graph-version.js\";\nimport { inferMemoryStatus, toMemoryPathRel } from \"./memory-lifecycle-ledger-utils.js\";\n import {\n HARMONIC_SOURCE_MEMORY_INSERTED_AT_KEY,\n resolveAbstractionNodeStoreDir,\n validateAbstractionNode,\n type AbstractionNode,\n } from \"./abstraction-nodes.js\";\nimport { resolveCueAnchorStoreDir, validateCueAnchor, type CueAnchor, type CueAnchorType } from \"./cue-anchors.js\";\nimport { compareDeterministicStrings } from \"./deterministic-order.js\";\nimport { countRecallTokenOverlap, normalizeRecallTokens } from \"./recall-tokenization.js\";\nimport { stripAttributesSuffix } from \"./structured-attributes.js\";\nimport { isValidityExpiredNow } from \"./temporal-validity.js\";\nimport { assertSafePathSegment, isRecord } from \"./store-contract.js\";\nimport { isSupportPassportPrivateMemory } from \"./support-passport/card-projection.js\";\nimport type { MemoryFile } from \"./types.js\";\nimport { readProjectedMemoryStates } from \"./memory-projection-batch.js\";\nimport { SecureStoreLockedError } from \"./secure-store/secure-fs.js\";\nimport { StorageManager } from \"./storage.js\";\nimport { RECALL_FALLBACK_DIRS } from \"./utils/category-dir.js\";\nimport { readHarmonicSourceMemory, readUnresolvedHarmonicSources } from \"./harmonic-source-lookup.js\";\n\n\ntype SourceMemoryMap = Map<string, MemoryFile>;\n\n\n// An index older than this is treated as unusable: the date window needed to\n// cover \"created since the last rebuild\" would stop being cheap.\nconst INDEX_MAX_AGE_MS = 7 * 86_400_000;\nconst DAY_MS = 86_400_000;\n\nfunction utcDaysSince(rebuiltMs: number, nowMs: number): string[] {\n const days: string[] = [];\n for (let day = Math.floor((rebuiltMs - DAY_MS) / DAY_MS) * DAY_MS; day <= nowMs; day += DAY_MS) {\n days.push(new Date(day).toISOString().slice(0, 10));\n }\n return days;\n}\n\n\n// Memories the projection has no row for were written after its last rebuild, so\n// their dated directory is normally one of `days`. Hot and cold tiers are probed\n// by exact path. Only recall-corpus categories are probed: `questions/` is a queue\n// and `artifacts/` is outside the recall surface, so neither can be a source.\nfunction unprojectedCandidatePaths(memoryDir: string, id: string, days: string[]): string[] {\n const paths: string[] = [];\n for (const root of [memoryDir, path.join(memoryDir, \"cold\")]) {\n for (const dir of RECALL_FALLBACK_DIRS) {\n paths.push(path.join(root, dir, `${id}.md`));\n for (const day of days) paths.push(path.join(root, dir, day, `${id}.md`));\n }\n }\n return paths;\n}\n\n/** Resolve indexed sources first, then use the durable unresolved-id path cache. */\nasync function readIndexedSourceMemories(options: {\n memoryDir: string;\n abortSignal?: AbortSignal;\n sourceMemoryIds: string[];\n nowMs: number;\n}): Promise<SourceMemoryMap | null> {\n // The ids go to SQL as bound parameters, so any id the projection holds is safe to look up.\n const batch = readProjectedMemoryStates(options.memoryDir, options.sourceMemoryIds);\n const rebuiltMs = Date.parse(batch?.rebuiltAt ?? \"\");\n if (!batch?.complete || !batch.rebuiltAt || !Number.isFinite(rebuiltMs) || options.nowMs - rebuiltMs > INDEX_MAX_AGE_MS) return null;\n const rootReal = await realpath(options.memoryDir).catch(() => null);\n if (rootReal === null) return null;\n\n const storage = new StorageManager(options.memoryDir);\n const days = utcDaysSince(rebuiltMs, options.nowMs);\n const sourceMemories: SourceMemoryMap = new Map();\n const pending: string[] = [];\n for (const id of options.sourceMemoryIds) {\n const state = batch.states.get(id);\n // An id is only ever joined into a path when it is a single safe segment.\n let safeId = true;\n try {\n assertSafePathSegment(id, \"sourceMemoryId\");\n } catch {\n safeId = false;\n }\n // state.path was containment-checked by the projection reader.\n const candidates = state\n ? [state.path, path.join(options.memoryDir, \"cold\", state.pathRel)]\n : safeId ? unprojectedCandidatePaths(options.memoryDir, id, days) : [];\n let found = false;\n for (const candidate of candidates) {\n const memory = await readHarmonicSourceMemory(storage, rootReal, candidate, options.abortSignal);\n if (memory?.frontmatter.id !== id) continue;\n sourceMemories.set(id, memory);\n found = true;\n break;\n }\n if (!found) pending.push(id);\n }\n if (pending.length === 0) return sourceMemories;\n\n const unresolved = await readUnresolvedHarmonicSources({\n storage, rootReal, rebuiltAt: batch.rebuiltAt, sourceMemoryIds: pending,\n nowMs: options.nowMs, abortSignal: options.abortSignal,\n });\n for (const [id, memory] of unresolved) sourceMemories.set(id, memory);\n return sourceMemories;\n}\n\nasync function readCorpusSourceMemories(options: {\n memoryDir: string;\n abortSignal?: AbortSignal;\n}): Promise<SourceMemoryMap> {\n const sourceMemories: SourceMemoryMap = new Map();\n try {\n const storage = new StorageManager(options.memoryDir);\n const [hotMemories, coldMemories] = await Promise.all([\n storage.readAllMemories({ abortSignal: options.abortSignal }),\n storage.readAllColdMemories({ abortSignal: options.abortSignal }),\n ]);\n for (const memory of [...hotMemories, ...coldMemories]) {\n throwIfAborted(options.abortSignal, \"harmonic retrieval aborted\");\n sourceMemories.set(memory.frontmatter.id, memory);\n }\n } catch (err) {\n throwIfAborted(options.abortSignal, \"harmonic retrieval aborted\");\n if (err instanceof SecureStoreLockedError) return new Map();\n // Source validation fails closed when the authorized memory directory is\n // unreadable. Source-less nodes remain eligible for retrieval.\n sourceMemories.clear();\n }\n return sourceMemories;\n}\n\nasync function readSourceMemories(options: {\n memoryDir: string;\n abortSignal?: AbortSignal;\n sourceMemoryIds: string[];\n nowMs?: number;\n}): Promise<SourceMemoryMap> {\n try {\n const indexed = await readIndexedSourceMemories({\n memoryDir: options.memoryDir,\n abortSignal: options.abortSignal,\n sourceMemoryIds: options.sourceMemoryIds,\n nowMs: options.nowMs ?? Date.now(),\n });\n if (indexed) return indexed;\n } catch (err) {\n throwIfAborted(options.abortSignal, \"harmonic retrieval aborted\");\n if (err instanceof SecureStoreLockedError) return new Map();\n }\n return readCorpusSourceMemories(options);\n}\n\nfunction parseSourceMemoryInsertedAt(node: AbstractionNode): Map<string, string> {\n const insertedAtById = new Map<string, string>();\n const insertedAtRaw = node.metadata?.[HARMONIC_SOURCE_MEMORY_INSERTED_AT_KEY];\n if (!insertedAtRaw) return insertedAtById;\n try {\n const parsed = JSON.parse(insertedAtRaw) as unknown;\n if (!isRecord(parsed)) return insertedAtById;\n for (const [memoryId, value] of Object.entries(parsed)) {\n if (typeof value === \"string\") insertedAtById.set(memoryId, value);\n }\n } catch {\n // Malformed insertion metadata leaves ordering on the recordedAt fallback.\n }\n return insertedAtById;\n}\n\n/**\n * Whether a source memory can back a projected node at all. Shared with `earliestInvalidAtMs`, so the cache\n * deadline only follows a source that the projection would use.\n * #2332: a private support-passport record leaves the eligible set the same way a rejected one does — a node\n * title or anchor attribution rebuilt from it would leak governed metadata into the deep-recall frontier (and\n * every other graph reader) before any content check runs.\n */\nfunction isEligibleSourceMemory(memory: MemoryFile, memoryDir: string): boolean {\n return (\n !isSupportPassportPrivateMemory(memory) &&\n inferMemoryStatus(memory.frontmatter, toMemoryPathRel(memoryDir, memory.path)) === \"active\"\n );\n}\n\nfunction projectSourceBackedNode(\n node: AbstractionNode,\n sourceMemories: SourceMemoryMap,\n memoryDir: string,\n temporalExpiredInInjection: boolean,\n nowMs: number\n): AbstractionNode | null {\n const sourceMemoryIds = node.sourceMemoryIds ?? [];\n if (sourceMemoryIds.length === 0) return node;\n\n const activeSourceMemoryIds = sourceMemoryIds.filter((memoryId) => {\n const memory = sourceMemories.get(memoryId);\n return (\n memory !== undefined &&\n isEligibleSourceMemory(memory, memoryDir) &&\n (temporalExpiredInInjection || !isValidityExpiredNow(memory.frontmatter, nowMs))\n );\n });\n if (activeSourceMemoryIds.length === 0) return null;\n\n // Newest-first source order keeps the projected title and summary on the most\n // recently inserted facts. Equal or missing timestamps fall back to ascending\n // id order, which matches the stored sourceMemoryIds order.\n const insertedAtById = parseSourceMemoryInsertedAt(node);\n const insertedAtMs = (memoryId: string): number => {\n const parsedMs = Date.parse(insertedAtById.get(memoryId) ?? \"\");\n return Number.isFinite(parsedMs) ? parsedMs : Date.parse(node.recordedAt);\n };\n activeSourceMemoryIds.sort(\n (left, right) =>\n insertedAtMs(right) - insertedAtMs(left) || compareDeterministicStrings(left, right)\n );\n\n const activeMemories = activeSourceMemoryIds.flatMap((memoryId) => {\n const memory = sourceMemories.get(memoryId);\n return memory ? [memory] : [];\n });\n const activeContents = activeMemories.map((memory) =>\n memory.frontmatter.structuredAttributes ? stripAttributesSuffix(memory.content) : memory.content\n );\n let metadata: Record<string, string> | undefined;\n const activeInsertedAt = activeSourceMemoryIds.flatMap((memoryId) => {\n const value = insertedAtById.get(memoryId);\n return typeof value === \"string\" ? [[memoryId, value] as const] : [];\n });\n if (activeInsertedAt.length > 0) {\n metadata = {\n [HARMONIC_SOURCE_MEMORY_INSERTED_AT_KEY]: JSON.stringify(Object.fromEntries(activeInsertedAt)),\n };\n }\n\n return {\n ...node,\n sourceMemoryIds: activeSourceMemoryIds,\n title: activeContents[0]?.slice(0, 80) ?? node.title,\n summary: activeContents.slice(0, 3).join(\"; \").slice(0, 400),\n tags: [...new Set(activeMemories.flatMap((memory) => memory.frontmatter.tags))].sort(compareDeterministicStrings),\n entityRefs: [\n ...new Set(\n activeMemories.flatMap((memory) =>\n typeof memory.frontmatter.entityRef === \"string\" ? [memory.frontmatter.entityRef] : []\n )\n ),\n ].sort(compareDeterministicStrings),\n metadata,\n };\n}\n\nfunction anchorMatchesProjectedNode(\n anchor: CueAnchor,\n nodeRef: string,\n node: AbstractionNode,\n allowLegacyAttribution: boolean\n): boolean {\n const activeSourceMemoryIds = node.sourceMemoryIds ?? [];\n if (activeSourceMemoryIds.length === 0) return true;\n if (!anchor.sourceMemoryIdsByNodeRef) return allowLegacyAttribution;\n const anchorSourceMemoryIds = anchor.sourceMemoryIdsByNodeRef[nodeRef] ?? [];\n return anchorSourceMemoryIds.some((sourceMemoryId) => activeSourceMemoryIds.includes(sourceMemoryId));\n}\n\nexport interface HarmonicMatchedAnchor {\n anchorId: string;\n anchorType: CueAnchorType;\n anchorValue: string;\n}\n\nexport interface HarmonicRetrievalResult {\n node: AbstractionNode;\n score: number;\n nodeScore: number;\n anchorScore: number;\n matchedFields: string[];\n matchedAnchors: HarmonicMatchedAnchor[];\n}\n\ninterface HarmonicCandidate {\n node: AbstractionNode;\n nodeScore: number;\n anchorScore: number;\n matchedFields: Set<string>;\n matchedAnchors: Map<string, HarmonicMatchedAnchor>;\n}\n\nfunction scoreNode(node: AbstractionNode, queryTokens: Set<string>): { score: number; matchedFields: string[] } {\n const matchedFields: string[] = [];\n let score = 0;\n\n const titleMatches = countRecallTokenOverlap(queryTokens, node.title);\n if (titleMatches > 0) {\n score += titleMatches * 3;\n matchedFields.push(\"title\");\n }\n\n const summaryMatches = countRecallTokenOverlap(queryTokens, node.summary);\n if (summaryMatches > 0) {\n score += summaryMatches * 3;\n matchedFields.push(\"summary\");\n }\n\n const tagMatches = countRecallTokenOverlap(queryTokens, node.tags?.join(\" \"));\n if (tagMatches > 0) {\n score += tagMatches * 2;\n matchedFields.push(\"tags\");\n }\n\n const entityMatches = countRecallTokenOverlap(queryTokens, node.entityRefs?.join(\" \"));\n if (entityMatches > 0) {\n score += entityMatches * 2;\n matchedFields.push(\"entityRefs\");\n }\n\n const kindMatches = countRecallTokenOverlap(queryTokens, `${node.kind} ${node.abstractionLevel}`);\n if (kindMatches > 0) {\n score += kindMatches;\n matchedFields.push(\"kind\");\n }\n\n return { score, matchedFields };\n}\n\nfunction scoreAnchor(\n anchor: CueAnchor,\n queryTokens: Set<string>,\n eligibleNodeTags: readonly string[]\n): { score: number; matchedFields: string[] } {\n const matchedFields: string[] = [];\n let score = 0;\n\n const valueMatches = countRecallTokenOverlap(queryTokens, anchor.anchorValue);\n const normalizedMatches = countRecallTokenOverlap(queryTokens, anchor.normalizedCue);\n const cueMatches = Math.max(valueMatches, normalizedMatches);\n if (cueMatches > 0) {\n score += cueMatches * 4;\n if (valueMatches > 0) matchedFields.push(\"anchorValue\");\n if (normalizedMatches > 0) matchedFields.push(\"anchor\");\n }\n\n const typeMatches = countRecallTokenOverlap(queryTokens, anchor.anchorType);\n if (typeMatches > 0) {\n score += typeMatches;\n matchedFields.push(\"anchorType\");\n }\n\n const tagMatches = countRecallTokenOverlap(queryTokens, eligibleNodeTags.join(\" \"));\n if (tagMatches > 0) {\n score += tagMatches * 2;\n matchedFields.push(\"anchorTags\");\n }\n\n return { score, matchedFields };\n}\n\nexport async function readAbstractionNodes(options: {\n memoryDir: string;\n abstractionNodeStoreDir?: string;\n}): Promise<AbstractionNode[]> {\n const rootDir = resolveAbstractionNodeStoreDir(options.memoryDir, options.abstractionNodeStoreDir);\n const files = await listJsonFilesStrict(path.join(rootDir, \"nodes\"), { allowMissingDirectory: true });\n const nodes: AbstractionNode[] = [];\n for (const filePath of files) {\n try {\n nodes.push(validateAbstractionNode(await readJsonFile(filePath)));\n } catch {\n // fail-open: invalid artifacts stay visible via status tooling instead of recall\n }\n }\n return nodes;\n}\n\nexport async function readCueAnchors(options: {\n memoryDir: string;\n abstractionNodeStoreDir?: string;\n}): Promise<CueAnchor[]> {\n const abstractionRoot = resolveAbstractionNodeStoreDir(options.memoryDir, options.abstractionNodeStoreDir);\n const rootDir = resolveCueAnchorStoreDir(abstractionRoot);\n const files = await listJsonFilesStrict(rootDir, { allowMissingDirectory: true });\n const anchors: CueAnchor[] = [];\n for (const filePath of files) {\n try {\n anchors.push(validateCueAnchor(await readJsonFile(filePath)));\n } catch {\n // fail-open: invalid artifacts stay visible via status tooling instead of recall\n }\n }\n return anchors;\n}\n\nexport interface ProjectedHarmonicGraph {\n nodes: AbstractionNode[];\n anchors: CueAnchor[];\n}\n\n/**\n * Read nodes + anchors and project BOTH against the namespace's current active\n * memories. This is the single projection every graph reader shares: a raw\n * `readAbstractionNodes` / `readCueAnchors` pair still carries the stored title,\n * summary, tags, and anchor attribution of a memory that was later rejected,\n * quarantined, or otherwise moved out of the active set, so a second reader\n * that skipped the projection could leak governed metadata even when the\n * memory itself is excluded from the final results.\n *\n * - A node whose every source memory left the active set is dropped.\n * - A surviving node's title/summary/tags/entityRefs are rebuilt from its\n * active sources only.\n * - An anchor keeps a node reference only while its attribution runs through\n * one of that node's surviving active sources, and is dropped once no\n * reference survives.\n */\ninterface ExpiringHarmonicGraph extends ProjectedHarmonicGraph {\n /** First instant a source memory's `invalid_at` passes: from then on the graph is wrong without any write. */\n validUntilMs: number;\n}\n\nfunction earliestInvalidAtMs(sourceMemories: SourceMemoryMap, memoryDir: string, nowMs: number): number {\n let earliest = Number.POSITIVE_INFINITY;\n for (const memory of sourceMemories.values()) {\n // An ineligible source drops out of the projection whatever its `invalid_at`, so its deadline changes nothing.\n if (!isEligibleSourceMemory(memory, memoryDir)) continue;\n const invalidAtMs = Date.parse(memory.frontmatter.invalid_at?.trim() ?? \"\");\n if (Number.isFinite(invalidAtMs) && invalidAtMs > nowMs && invalidAtMs < earliest) earliest = invalidAtMs;\n }\n return earliest;\n}\n\nasync function buildProjectedHarmonicGraph(options: {\n memoryDir: string;\n abstractionNodeStoreDir?: string;\n anchorsEnabled: boolean;\n abortSignal?: AbortSignal;\n temporalExpiredInInjection?: boolean;\n nowMs?: number;\n}): Promise<ProjectedHarmonicGraph> {\n const { nodes, anchors } = await buildExpiringHarmonicGraph(options);\n return { nodes, anchors };\n}\n\nasync function buildExpiringHarmonicGraph(options: {\n memoryDir: string;\n abstractionNodeStoreDir?: string;\n anchorsEnabled: boolean;\n abortSignal?: AbortSignal;\n temporalExpiredInInjection?: boolean;\n nowMs?: number;\n}): Promise<ExpiringHarmonicGraph> {\n throwIfAborted(options.abortSignal, \"harmonic retrieval aborted\");\n const nodes = await readAbstractionNodes(options);\n const sourceMemoryIds = [...new Set(nodes.flatMap((node) => node.sourceMemoryIds ?? []))];\n const sourceMemories: SourceMemoryMap = sourceMemoryIds.length > 0\n ? await readSourceMemories({\n memoryDir: options.memoryDir,\n abortSignal: options.abortSignal,\n sourceMemoryIds,\n nowMs: options.nowMs,\n })\n : new Map();\n const nowMs = options.nowMs ?? Date.now();\n // With temporalExpiredInInjection the validity filter is off, so no `invalid_at` can age the graph.\n const validUntilMs = options.temporalExpiredInInjection === true\n ? Number.POSITIVE_INFINITY\n : earliestInvalidAtMs(sourceMemories, options.memoryDir, nowMs);\n // A node whose full stored source set survived projection keeps legacy\n // anchor attribution (an anchor written before per-node source ids existed).\n const legacyCompatibleNodeRefs = new Set<string>();\n const projectedNodes = nodes.flatMap((node) => {\n const projected = projectSourceBackedNode(\n node,\n sourceMemories,\n options.memoryDir,\n options.temporalExpiredInInjection === true,\n nowMs\n );\n if (\n projected &&\n (node.sourceMemoryIds?.length ?? 0) > 0 &&\n projected.sourceMemoryIds?.length === node.sourceMemoryIds?.length\n ) {\n legacyCompatibleNodeRefs.add(node.nodeId);\n }\n return projected ? [projected] : [];\n });\n if (!options.anchorsEnabled) return { nodes: projectedNodes, anchors: [], validUntilMs };\n throwIfAborted(options.abortSignal, \"harmonic retrieval aborted\");\n const nodeIndex = new Map(projectedNodes.map((node) => [node.nodeId, node]));\n const anchors = (await readCueAnchors(options)).flatMap((anchor) => {\n throwIfAborted(options.abortSignal, \"harmonic retrieval aborted\");\n const nodeRefs = anchor.nodeRefs.filter((nodeRef) => {\n const node = nodeIndex.get(nodeRef);\n return (\n node !== undefined &&\n anchorMatchesProjectedNode(anchor, nodeRef, node, legacyCompatibleNodeRefs.has(nodeRef))\n );\n });\n return nodeRefs.length > 0 ? [{ ...anchor, nodeRefs }] : [];\n });\n return { nodes: projectedNodes, anchors, validUntilMs };\n}\n\nconst GRAPH_CACHE_TTL_MS = 30_000;\n/**\n * Past the TTL a graph whose stamp is unchanged is still served while a refresh runs behind it, so no\n * recall waits for a rebuild just because the TTL lapsed. This is how long past the TTL; after it the graph is rebuilt first.\n */\nconst GRAPH_CACHE_MAX_STALE_MS = 300_000;\nconst GRAPH_CACHE_MAX_ENTRIES = 8;\n\ninterface GraphCacheEntry {\n stamp: string;\n /** When the build finished, so the TTL measures how long the graph has been available. */\n builtAtMs: number;\n validUntilMs: number;\n graph: ProjectedHarmonicGraph;\n}\n\ninterface GraphBuild {\n stamp: string;\n promise: Promise<ProjectedHarmonicGraph>;\n /** Cancels the build's source scan; fired when no caller is waiting for it. */\n controller: AbortController;\n /** Callers currently waiting for this build. */\n waiting: number;\n}\n\nconst graphCache = new Map<string, GraphCacheEntry>();\n/** One build per cache key at a time: every recall that lands on a miss waits for the same build. */\nconst graphBuilds = new Map<string, GraphBuild>();\n/** When a background refresh last failed, per key: stale reads retry at most once per TTL. Capped like the cache. */\nconst refreshFailedAtMs = new Map<string, number>();\n\nfunction rememberRefreshFailure(key: string): void {\n refreshFailedAtMs.delete(key);\n refreshFailedAtMs.set(key, Date.now());\n while (refreshFailedAtMs.size > GRAPH_CACHE_MAX_ENTRIES) {\n const oldest = refreshFailedAtMs.keys().next().value;\n if (oldest === undefined) break;\n refreshFailedAtMs.delete(oldest);\n }\n}\n\n/**\n * A source's `invalid_at` can pass while the build is still reading anchors, which would hand every caller\n * that joined this build a graph that is already expired. Rebuild until the graph is unexpired at completion.\n * Each round drops the sources that expired, so the set of future deadlines shrinks and the loop ends.\n */\nasync function buildUnexpiredHarmonicGraph(options: GraphReadOptions, abortSignal: AbortSignal): Promise<ExpiringHarmonicGraph> {\n for (;;) {\n const built = await buildExpiringHarmonicGraph({\n memoryDir: options.memoryDir,\n abstractionNodeStoreDir: options.abstractionNodeStoreDir,\n anchorsEnabled: options.anchorsEnabled,\n temporalExpiredInInjection: options.temporalExpiredInInjection,\n abortSignal,\n });\n if (Date.now() < built.validUntilMs) return built;\n }\n}\n/** Counters for tests and diagnostics. `stale` hits also count as `hits`. */\nexport const harmonicGraphCacheStats = { hits: 0, misses: 0, stale: 0, shared: 0 };\n\n/** Freeze records and their nested arrays/objects so a caller cannot corrupt the shared cache. */\nfunction deepFreeze<T extends object>(value: T): T {\n // isFrozen is true for primitives and null, and a frozen value is not revisited, so this ends on cycles too.\n if (Object.isFrozen(value)) return value;\n Object.freeze(value);\n for (const child of Object.values(value)) deepFreeze(child);\n return value;\n}\n\nexport function clearHarmonicGraphCache(): void {\n graphCache.clear();\n graphBuilds.clear();\n refreshFailedAtMs.clear();\n}\n\n/**\n * Resolves once every build running now has settled, and after the failure bookkeeping of a background\n * refresh (that handler was attached when the refresh started, so it runs first). For tests: a time-based\n * wait races a slow build.\n */\nexport async function settleHarmonicGraphBuilds(): Promise<void> {\n await Promise.allSettled([...graphBuilds.values()].map((build) => build.promise));\n}\n\ntype GraphReadOptions = Parameters<typeof buildProjectedHarmonicGraph>[0];\n\n/**\n * Start the one build for `key`. The build owns an abort controller instead of using one caller's signal,\n * so a caller that leaves does not cancel it for the others; `joinGraphBuild` cancels it when the last caller leaves.\n */\nfunction startGraphBuild(key: string, stamp: string, options: GraphReadOptions): GraphBuild {\n harmonicGraphCacheStats.misses++;\n const controller = new AbortController();\n const promise: Promise<ProjectedHarmonicGraph> = buildUnexpiredHarmonicGraph(options, controller.signal)\n .then((built) => {\n const graph = { nodes: deepFreeze(built.nodes), anchors: deepFreeze(built.anchors) };\n // A cleared cache or a newer build for this key has replaced this one: do not store a stale graph.\n if (graphBuilds.get(key)?.promise !== promise) return graph;\n refreshFailedAtMs.delete(key);\n graphCache.delete(key);\n graphCache.set(key, { stamp, builtAtMs: Date.now(), validUntilMs: built.validUntilMs, graph });\n while (graphCache.size > GRAPH_CACHE_MAX_ENTRIES) {\n const oldest = graphCache.keys().next().value;\n if (oldest === undefined) break;\n graphCache.delete(oldest);\n }\n return graph;\n })\n .finally(() => {\n if (graphBuilds.get(key)?.promise === promise) graphBuilds.delete(key);\n });\n const build: GraphBuild = { stamp, promise, controller, waiting: 0 };\n graphBuilds.set(key, build);\n return build;\n}\n\n/**\n * Wait for `build` on behalf of one caller. The caller's own signal ends only its own wait. When the last\n * waiting caller has left, the build is cancelled and dropped, so abandoned recalls do not leave full scans running\n * (cancelling a build that already finished does nothing).\n */\nfunction joinGraphBuild(key: string, build: GraphBuild, signal: AbortSignal | undefined): Promise<ProjectedHarmonicGraph> {\n build.waiting++;\n return raceAbort(build.promise, signal, \"harmonic retrieval aborted\").finally(() => {\n build.waiting--;\n if (build.waiting > 0) return;\n if (graphBuilds.get(key) === build) graphBuilds.delete(key);\n build.controller.abort();\n });\n}\n\n/**\n * `readProjectedHarmonicGraph` with an opt-in in-memory cache. Every recall used\n * to re-read all nodes, anchors and source memories from disk (about 4.7 s on a\n * 2107 node, 9199 anchor, 4105 source graph). With `useCache` a completed graph is\n * reused while the stamp below is unchanged: the memory corpus, memory status and\n * cold-write version sentinels (bumped by every memory write, in any process) and\n * the graph version sentinel (bumped by node and anchor writes). A stamp read is\n * four stats, not a scan of the memories. The TTL bounds the one input a sentinel\n * cannot see, which is wall-clock validity expiry; past it the stale graph is served\n * while one refresh runs (up to GRAPH_CACHE_MAX_STALE_MS). A changed stamp always\n * waits for a fresh build, because a stale graph could carry governed metadata of a\n * memory that left the active set. Concurrent misses share one build. An explicit\n * `nowMs` bypasses the cache so tests stay deterministic. The cached arrays are\n * frozen: callers must not mutate them.\n */\nexport async function readProjectedHarmonicGraph(options: {\n memoryDir: string;\n abstractionNodeStoreDir?: string;\n anchorsEnabled: boolean;\n abortSignal?: AbortSignal;\n temporalExpiredInInjection?: boolean;\n nowMs?: number;\n useCache?: boolean;\n}): Promise<ProjectedHarmonicGraph> {\n if (options.useCache !== true || options.nowMs !== undefined) return buildProjectedHarmonicGraph(options);\n // Same cancellation contract as the builder: a cache hit must not mask an aborted signal.\n throwIfAborted(options.abortSignal, \"harmonic retrieval aborted\");\n const nodeStoreDir = resolveAbstractionNodeStoreDir(options.memoryDir, options.abstractionNodeStoreDir);\n const key = JSON.stringify([\n options.memoryDir,\n nodeStoreDir,\n options.anchorsEnabled === true,\n options.temporalExpiredInInjection === true,\n ]);\n // The stamp is read BEFORE the build, so a write that lands mid-build leaves the\n // entry stale and the next call rebuilds.\n const stamp = readHarmonicGraphStamp(options.memoryDir, nodeStoreDir);\n const nowMs = Date.now();\n const hit = graphCache.get(key);\n // A source's `invalid_at` passing changes the projection without bumping the stamp, so it ends the entry\n // at the exact instant, however fresh the entry is.\n if (hit && hit.stamp === stamp && nowMs < hit.validUntilMs && nowMs - hit.builtAtMs < GRAPH_CACHE_TTL_MS + GRAPH_CACHE_MAX_STALE_MS) {\n harmonicGraphCacheStats.hits++;\n graphCache.delete(key);\n graphCache.set(key, hit);\n if (nowMs - hit.builtAtMs >= GRAPH_CACHE_TTL_MS) {\n harmonicGraphCacheStats.stale++;\n const failedAtMs = refreshFailedAtMs.get(key);\n const backingOff = failedAtMs !== undefined && nowMs - failedAtMs < GRAPH_CACHE_TTL_MS;\n if (graphBuilds.get(key)?.stamp !== stamp && !backingOff) {\n startGraphBuild(key, stamp, options).promise.catch((err) => {\n rememberRefreshFailure(key);\n log.debug(`harmonic graph refresh failed: ${err}`);\n });\n }\n }\n return hit.graph;\n }\n const running = graphBuilds.get(key);\n if (running?.stamp === stamp) {\n harmonicGraphCacheStats.shared++;\n return joinGraphBuild(key, running, options.abortSignal);\n }\n return joinGraphBuild(key, startGraphBuild(key, stamp, options), options.abortSignal);\n}\n\nexport async function searchHarmonicRetrieval(options: {\n memoryDir: string;\n abstractionNodeStoreDir?: string;\n query: string;\n maxResults: number;\n sessionKey?: string;\n anchorsEnabled: boolean;\n abortSignal?: AbortSignal;\n temporalExpiredInInjection?: boolean;\n /** Share one projected graph between recalls until a write bumps a version sentinel (see readProjectedHarmonicGraph). */\n useGraphCache?: boolean;\n}): Promise<HarmonicRetrievalResult[]> {\n throwIfAborted(options.abortSignal, \"harmonic retrieval aborted\");\n const queryTokens = new Set(normalizeRecallTokens(options.query, [\"what\", \"which\"]));\n if (queryTokens.size === 0 || options.maxResults <= 0) return [];\n\n // One projection for every graph reader: nodes and anchors both arrive\n // already narrowed to the namespace's current active memories.\n const { nodes: eligibleNodes, anchors } = await readProjectedHarmonicGraph({\n ...options,\n useCache: options.useGraphCache === true,\n });\n const candidates = new Map<string, HarmonicCandidate>();\n\n for (const node of eligibleNodes) {\n throwIfAborted(options.abortSignal, \"harmonic retrieval aborted\");\n const { score, matchedFields } = scoreNode(node, queryTokens);\n if (score <= 0) continue;\n candidates.set(node.nodeId, {\n node,\n nodeScore: score,\n anchorScore: 0,\n matchedFields: new Set(matchedFields),\n matchedAnchors: new Map(),\n });\n }\n\n if (options.anchorsEnabled) {\n throwIfAborted(options.abortSignal, \"harmonic retrieval aborted\");\n const nodeIndex = new Map(eligibleNodes.map((node) => [node.nodeId, node]));\n for (const anchor of anchors) {\n throwIfAborted(options.abortSignal, \"harmonic retrieval aborted\");\n // `nodeRefs` are the projection's surviving references already.\n const eligibleNodeRefs = anchor.nodeRefs;\n const eligibleNodeTags = new Set(eligibleNodeRefs.flatMap((nodeRef) => nodeIndex.get(nodeRef)?.tags ?? []));\n const eligibleAnchorTags = anchor.tags?.filter((tag) => eligibleNodeTags.has(tag)) ?? [];\n const { score, matchedFields } = scoreAnchor(anchor, queryTokens, eligibleAnchorTags);\n if (score <= 0) continue;\n for (const nodeRef of eligibleNodeRefs) {\n const node = nodeIndex.get(nodeRef);\n if (!node) continue;\n const existing = candidates.get(nodeRef) ?? {\n node,\n nodeScore: 0,\n anchorScore: 0,\n matchedFields: new Set<string>(),\n matchedAnchors: new Map<string, HarmonicMatchedAnchor>(),\n };\n existing.anchorScore += score;\n existing.matchedFields.add(\"anchor\");\n for (const field of matchedFields) existing.matchedFields.add(field);\n existing.matchedAnchors.set(anchor.anchorId, {\n anchorId: anchor.anchorId,\n anchorType: anchor.anchorType,\n anchorValue: anchor.anchorValue,\n });\n candidates.set(nodeRef, existing);\n }\n }\n }\n\n return [...candidates.values()]\n .map((candidate) => {\n let score = candidate.nodeScore + candidate.anchorScore;\n if (options.sessionKey && candidate.node.sessionKey === options.sessionKey) score += 0.5;\n return {\n node: candidate.node,\n score,\n nodeScore: candidate.nodeScore,\n anchorScore: candidate.anchorScore,\n matchedFields: [...candidate.matchedFields].sort(),\n matchedAnchors: [...candidate.matchedAnchors.values()].sort(\n (left, right) =>\n left.anchorType.localeCompare(right.anchorType) || left.anchorValue.localeCompare(right.anchorValue)\n ),\n };\n })\n .filter((result) => result.nodeScore > 0 || result.anchorScore > 0)\n .sort(\n (left, right) =>\n right.score - left.score ||\n right.anchorScore - left.anchorScore ||\n right.node.recordedAt.localeCompare(left.node.recordedAt)\n )\n .slice(0, options.maxResults);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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AAmC;AAAA,QACzD;AACA,iBAAS,eAAe;AACxB,iBAAS,cAAc,IAAI,QAAQ;AACnC,mBAAW,SAAS,cAAe,UAAS,cAAc,IAAI,KAAK;AACnE,iBAAS,eAAe,IAAI,OAAO,UAAU;AAAA,UAC3C,UAAU,OAAO;AAAA,UACjB,YAAY,OAAO;AAAA,UACnB,aAAa,OAAO;AAAA,QACtB,CAAC;AACD,mBAAW,IAAI,SAAS,QAAQ;AAAA,MAClC;AAAA,IACF;AAAA,EACF;AAEA,SAAO,CAAC,GAAG,WAAW,OAAO,CAAC,EAC3B,IAAI,CAAC,cAAc;AAClB,QAAI,QAAQ,UAAU,YAAY,UAAU;AAC5C,QAAI,QAAQ,cAAc,UAAU,KAAK,eAAe,QAAQ,WAAY,UAAS;AACrF,WAAO;AAAA,MACL,MAAM,UAAU;AAAA,MAChB;AAAA,MACA,WAAW,UAAU;AAAA,MACrB,aAAa,UAAU;AAAA,MACvB,eAAe,CAAC,GAAG,UAAU,aAAa,EAAE,KAAK;AAAA,MACjD,gBAAgB,CAAC,GAAG,UAAU,eAAe,OAAO,CAAC,EAAE;AAAA,QACrD,CAAC,MAAM,UACL,KAAK,WAAW,cAAc,MAAM,UAAU,KAAK,KAAK,YAAY,cAAc,MAAM,WAAW;AAAA,MACvG;AAAA,IACF;AAAA,EACF,CAAC,EACA,OAAO,CAAC,WAAW,OAAO,YAAY,KAAK,OAAO,cAAc,CAAC,EACjE;AAAA,IACC,CAAC,MAAM,UACL,MAAM,QAAQ,KAAK,SACnB,MAAM,cAAc,KAAK,eACzB,MAAM,KAAK,WAAW,cAAc,KAAK,KAAK,UAAU;AAAA,EAC5D,EACC,MAAM,GAAG,QAAQ,UAAU;AAChC;","names":[]}
@@ -544,7 +544,7 @@ import {
544
544
  import {
545
545
  readProjectedHarmonicGraph,
546
546
  searchHarmonicRetrieval
547
- } from "./chunk-PL36IQPL.js";
547
+ } from "./chunk-KCRHFW3N.js";
548
548
  import {
549
549
  classifyMemoryKind
550
550
  } from "./chunk-YAZNBMNF.js";
@@ -67200,4 +67200,4 @@ export {
67200
67200
  EngramAccessService,
67201
67201
  AccessAdminOpsSurface
67202
67202
  };
67203
- //# sourceMappingURL=chunk-MMOXCCHF.js.map
67203
+ //# sourceMappingURL=chunk-T3X4CCHC.js.map
package/dist/cli.js CHANGED
@@ -91,7 +91,7 @@ import {
91
91
  runWorkProductStatusCliCommand,
92
92
  runWorkProjectCliCommand,
93
93
  runWorkTaskCliCommand
94
- } from "./chunk-MMOXCCHF.js";
94
+ } from "./chunk-T3X4CCHC.js";
95
95
  import "./chunk-6P7U3HWG.js";
96
96
  import "./chunk-PQM3B54K.js";
97
97
  import "./chunk-B3DR2JBZ.js";
@@ -264,7 +264,7 @@ import "./chunk-MDPT6QFK.js";
264
264
  import "./chunk-UOBPK2OS.js";
265
265
  import "./chunk-2YA5N2BY.js";
266
266
  import "./chunk-3HSRWJTC.js";
267
- import "./chunk-PL36IQPL.js";
267
+ import "./chunk-KCRHFW3N.js";
268
268
  import "./chunk-HUDPXTXW.js";
269
269
  import "./chunk-AZEZSQ5R.js";
270
270
  import "./chunk-YAZNBMNF.js";
@@ -8,7 +8,7 @@ import {
8
8
  shouldSkipImplicitExtraction,
9
9
  stripInlineExplicitCaptureNotes,
10
10
  validateExplicitCaptureInput
11
- } from "./chunk-MMOXCCHF.js";
11
+ } from "./chunk-T3X4CCHC.js";
12
12
  import "./chunk-6P7U3HWG.js";
13
13
  import "./chunk-PQM3B54K.js";
14
14
  import "./chunk-B3DR2JBZ.js";
@@ -181,7 +181,7 @@ import "./chunk-MDPT6QFK.js";
181
181
  import "./chunk-UOBPK2OS.js";
182
182
  import "./chunk-2YA5N2BY.js";
183
183
  import "./chunk-3HSRWJTC.js";
184
- import "./chunk-PL36IQPL.js";
184
+ import "./chunk-KCRHFW3N.js";
185
185
  import "./chunk-HUDPXTXW.js";
186
186
  import "./chunk-AZEZSQ5R.js";
187
187
  import "./chunk-YAZNBMNF.js";