@remnic/plugin-openclaw 1.0.35 → 1.0.37

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 (87) hide show
  1. package/README.md +38 -4
  2. package/dist/{calibration-Z5WWNV7U.js → calibration-RKL2LRW4.js} +4 -4
  3. package/dist/{capsule-cli-GBM3WPAM.js → capsule-cli-EHZPMXBC.js} +2 -2
  4. package/dist/{capsule-crypto-K3IRTKRH.js → capsule-crypto-JS67OSWM.js} +3 -3
  5. package/dist/capsule-export-DX53CPIT.js +17 -0
  6. package/dist/capsule-import-4OXCPHOT.js +16 -0
  7. package/dist/{capsule-merge-IWOQ34KL.js → capsule-merge-25AUN33Q.js} +7 -7
  8. package/dist/{causal-chain-WYN5QOPS.js → causal-chain-BVTOWZKC.js} +4 -4
  9. package/dist/{causal-consolidation-C64NNE4T.js → causal-consolidation-DRPM2KOE.js} +13 -10
  10. package/dist/{causal-retrieval-NZHQOZOE.js → causal-retrieval-XAP6QKHZ.js} +4 -5
  11. package/dist/{causal-trajectory-graph-VBPE2WPM.js → causal-trajectory-graph-ZWQWZ7N5.js} +2 -2
  12. package/dist/{chunk-5LE4HTVL.js → chunk-25J4PXDH.js} +0 -18
  13. package/dist/{chunk-6UFI73TJ.js → chunk-3IKMUNW5.js} +53 -46
  14. package/dist/{chunk-EXDYWXMB.js → chunk-4XDQ3KEC.js} +1 -2
  15. package/dist/{chunk-JGIUTWZS.js → chunk-6O3H3DPL.js} +2 -2
  16. package/dist/{chunk-UTDLHBBV.js → chunk-BLC3RQNV.js} +5 -555
  17. package/dist/{chunk-4G2XCSD2.js → chunk-BZ4EYURA.js} +0 -5
  18. package/dist/{chunk-L6I4MQKO.js → chunk-CEL5ZLKP.js} +6 -6
  19. package/dist/{chunk-TDRJVMUP.js → chunk-EH4AXGRO.js} +0 -12
  20. package/dist/{chunk-EYCLXMIV.js → chunk-G3CZA4SD.js} +9 -427
  21. package/dist/chunk-I2KLQ2HA.js +22 -0
  22. package/dist/chunk-IO5WWY6A.js +156 -0
  23. package/dist/{contradiction-scan-A5NOTZPN.js → chunk-JC3FCKYL.js} +189 -86
  24. package/dist/{chunk-SVSQAG6M.js → chunk-KC7KSQR4.js} +47 -28
  25. package/dist/chunk-LZCGPRHS.js +228 -0
  26. package/dist/{chunk-CXM7EBAO.js → chunk-MXFJXUHC.js} +1 -1
  27. package/dist/{chunk-VRGUUHBV.js → chunk-NUWDSTP7.js} +1 -1
  28. package/dist/{chunk-4LYQ4ONL.js → chunk-QCCP4RU5.js} +8 -3
  29. package/dist/{chunk-6OJAU466.js → chunk-QMUQV5NP.js} +0 -1
  30. package/dist/{chunk-LLUROTZJ.js → chunk-QQXJODFL.js} +9 -9
  31. package/dist/{chunk-6F6EKSVP.js → chunk-QXXEF7VI.js} +1 -1
  32. package/dist/{chunk-CMKR6NDQ.js → chunk-SEGEX7W4.js} +73 -241
  33. package/dist/{chunk-VFULKFKI.js → chunk-SWOYEQN2.js} +42 -17
  34. package/dist/chunk-TH5FF5SC.js +16 -0
  35. package/dist/{chunk-FGTYFLL5.js → chunk-TXOEHSVP.js} +29 -32
  36. package/dist/chunk-UZJ7EERS.js +272 -0
  37. package/dist/chunk-YJYZMLD5.js +360 -0
  38. package/dist/{chunk-NKVIN6RD.js → chunk-YKV4EFUI.js} +84 -2
  39. package/dist/{chunk-SSFTU6LP.js → chunk-ZS6VABML.js} +4 -4
  40. package/dist/{cipher-VHAFCG7Z.js → cipher-E23BHBSO.js} +1 -1
  41. package/dist/{consolidation-undo-5ZSX4MWO.js → consolidation-undo-FKJZCJHS.js} +2 -2
  42. package/dist/contradiction-review-WJRWNQ5N.js +29 -0
  43. package/dist/contradiction-scan-5X423QGT.js +12 -0
  44. package/dist/{dreams-ledger-3I52ISYR.js → dreams-ledger-KDX44I7R.js} +1 -1
  45. package/dist/{engine-47AKKYJ4.js → engine-5P774HTZ.js} +6 -6
  46. package/dist/{extraction-judge-telemetry-GHOTVYMP.js → extraction-judge-telemetry-O4ZVGLTU.js} +1 -1
  47. package/dist/{fallback-llm-45A755XP.js → fallback-llm-43UMEXNJ.js} +3 -3
  48. package/dist/{first-start-migration-I24M2JEE.js → first-start-migration-H2SAXAGR.js} +4 -4
  49. package/dist/{forget-NI4RBDPB.js → forget-ZECIDNL5.js} +1 -1
  50. package/dist/{fs-utils-PZRI2HDZ.js → fs-utils-OYXSZSVV.js} +12 -2
  51. package/dist/{graph-edge-decay-5CVKWBYH.js → graph-edge-decay-24ZKD5QL.js} +5 -5
  52. package/dist/index.js +7098 -84293
  53. package/dist/{kdf-H5B23ZM2.js → kdf-RXKIWHRU.js} +1 -1
  54. package/dist/legacy-hook-compat-QHHKF4GK.js +2 -0
  55. package/dist/{logger-TNOKCH7X.js → logger-XG7JKLPS.js} +1 -1
  56. package/dist/{memory-governance-QS7Z425Y.js → memory-governance-6K4M4YXD.js} +5 -5
  57. package/dist/{metadata-JAGIWHEA.js → metadata-WK2TRPYZ.js} +1 -1
  58. package/dist/{migrate-from-identity-anchor-7MMSPEUM.js → migrate-from-identity-anchor-SNDNKHZD.js} +1 -1
  59. package/dist/path-ZKO74XXC.js +7 -0
  60. package/dist/{peers-KRFXWRQ6.js → peers-W53WSDXG.js} +1 -1
  61. package/dist/{purge-XN2VSPZ2.js → purge-IKJISXEQ.js} +1 -1
  62. package/dist/resolution-BN35OXDS.js +11 -0
  63. package/dist/{secure-store-A4NGCNXV.js → secure-store-F75I54O5.js} +3 -3
  64. package/dist/{state-PVISYXRH.js → state-4ITLYMAU.js} +1 -1
  65. package/dist/{state-store-N6TFBFSP.js → state-store-ET3ADVY5.js} +3 -3
  66. package/dist/{storage-DDYQGLXA.js → storage-5EY6T7ON.js} +3 -3
  67. package/dist/{tier-stats-IZNW66NC.js → tier-stats-ZRQBV6G2.js} +4 -4
  68. package/dist/{trace-NJESSGH7.js → trace-IL2Y34EH.js} +1 -1
  69. package/dist/{tui-MGK2LYJY.js → tui-7KRDCMYK.js} +1 -1
  70. package/dist/{types-R4DO7AKM.js → types-MBUINTB2.js} +3 -3
  71. package/openclaw.plugin.json +164 -8
  72. package/package.json +9 -6
  73. package/scripts/faiss_index.py +816 -0
  74. package/scripts/faiss_requirements.txt +3 -0
  75. package/dist/capsule-export-IXVERCQG.js +0 -17
  76. package/dist/capsule-import-IA6VIOPQ.js +0 -16
  77. package/dist/chunk-3GUF7RQI.js +0 -559
  78. package/dist/chunk-7OQEPGQF.js +0 -533
  79. package/dist/chunk-DIZW6H5J.js +0 -136
  80. package/dist/chunk-FQRSVYY4.js +0 -110
  81. package/dist/chunk-GUSMRW4H.js +0 -12
  82. package/dist/chunk-MLKGABMK.js +0 -9
  83. package/dist/chunk-WPINX4MF.js +0 -380
  84. package/dist/contradiction-review-SVGBS3V5.js +0 -21
  85. package/dist/legacy-hook-compat-XQ7FP6FV.js +0 -35
  86. package/dist/path-JIEGNWFL.js +0 -7
  87. package/dist/resolution-YITUVUTH.js +0 -100
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  createVersion
3
- } from "./chunk-6OJAU466.js";
3
+ } from "./chunk-QMUQV5NP.js";
4
4
  import {
5
5
  SecureStoreLockedError,
6
6
  isEncryptedFile,
@@ -25,6 +25,11 @@ import { appendFileSync, mkdirSync, statSync } from "fs";
25
25
  import { createHash } from "crypto";
26
26
  import path4 from "path";
27
27
 
28
+ // ../remnic-core/src/utils/errno.ts
29
+ function isErrnoCode(error, code) {
30
+ return typeof error === "object" && error !== null && "code" in error && error.code === code;
31
+ }
32
+
28
33
  // ../remnic-core/src/memory-cache.ts
29
34
  var entityCacheByDir = /* @__PURE__ */ new Map();
30
35
  function buildEntityCacheKey(baseDir, schemaKey = "") {
@@ -49,63 +54,6 @@ function invalidateCachedEntities(baseDir) {
49
54
  if (key.startsWith(prefix)) entityCacheByDir.delete(key);
50
55
  }
51
56
  }
52
- var episodeMapByDir = /* @__PURE__ */ new Map();
53
- var ruleMemoriesByDir = /* @__PURE__ */ new Map();
54
- function getCachedEpisodeMap(baseDir, currentVersion) {
55
- if (currentVersion === 0) return null;
56
- const entry = episodeMapByDir.get(baseDir);
57
- if (!entry || entry.sourceVersion !== currentVersion) return null;
58
- return entry.data;
59
- }
60
- function setCachedEpisodeMap(baseDir, memories, version) {
61
- const map = /* @__PURE__ */ new Map();
62
- for (const m of memories) {
63
- if (m.frontmatter.status === "archived" || m.frontmatter.status === "forgotten") continue;
64
- if (m.frontmatter.memoryKind !== "episode") continue;
65
- map.set(m.frontmatter.id, m);
66
- }
67
- episodeMapByDir.set(baseDir, { data: map, sourceVersion: version });
68
- return map;
69
- }
70
- function getCachedRuleMemories(baseDir, currentVersion) {
71
- if (currentVersion === 0) return null;
72
- const entry = ruleMemoriesByDir.get(baseDir);
73
- if (!entry || entry.sourceVersion !== currentVersion) return null;
74
- return entry.data;
75
- }
76
- function setCachedRuleMemories(baseDir, memories, version) {
77
- const byId = /* @__PURE__ */ new Map();
78
- const all = [];
79
- for (const m of memories) {
80
- byId.set(m.frontmatter.id, m);
81
- if (m.frontmatter.category === "rule" && m.frontmatter.status !== "archived" && m.frontmatter.status !== "forgotten") {
82
- all.push(m);
83
- }
84
- }
85
- const result = { all, byId };
86
- ruleMemoriesByDir.set(baseDir, { data: result, sourceVersion: version });
87
- return result;
88
- }
89
- var QMD_CACHE_TTL_MS = 6e4;
90
- var qmdSearchCache = /* @__PURE__ */ new Map();
91
- function getCachedQmdSearch(cacheKey) {
92
- const entry = qmdSearchCache.get(cacheKey);
93
- if (!entry) return null;
94
- if (Date.now() - entry.cachedAt > QMD_CACHE_TTL_MS) {
95
- qmdSearchCache.delete(cacheKey);
96
- return null;
97
- }
98
- return entry.results;
99
- }
100
- function setCachedQmdSearch(cacheKey, results) {
101
- qmdSearchCache.set(cacheKey, { results, cachedAt: Date.now() });
102
- if (qmdSearchCache.size > 200) {
103
- const now = Date.now();
104
- for (const [key, entry] of qmdSearchCache) {
105
- if (now - entry.cachedAt > QMD_CACHE_TTL_MS) qmdSearchCache.delete(key);
106
- }
107
- }
108
- }
109
57
 
110
58
  // ../remnic-core/src/hygiene.ts
111
59
  import * as fsReadModule1 from "fs/promises";
@@ -117,29 +65,6 @@ import path from "path";
117
65
  function toSafeTimestamp(ts) {
118
66
  return ts.toISOString().replace(/[:.]/g, "");
119
67
  }
120
- async function lintWorkspaceFiles(opts) {
121
- const warnings = [];
122
- const warnAtBytes = Math.floor(opts.budgetBytes * opts.warnRatio);
123
- for (const p of opts.paths) {
124
- const abs = path.isAbsolute(p) ? p : path.join(opts.workspaceDir, p);
125
- try {
126
- const st = await stat(abs);
127
- if (!st.isFile()) continue;
128
- const bytes = st.size;
129
- if (bytes >= warnAtBytes) {
130
- warnings.push({
131
- path: p,
132
- bytes,
133
- budgetBytes: opts.budgetBytes,
134
- warnAtBytes,
135
- message: `Bootstrap file '${p}' is approaching its budget (${bytes} bytes >= ${warnAtBytes} bytes). Consider splitting/archiving it to avoid silent truncation.`
136
- });
137
- }
138
- } catch {
139
- }
140
- }
141
- return warnings;
142
- }
143
68
  async function rotateMarkdownFileToArchive(opts) {
144
69
  const existing = await fileReader(opts.filePath, "utf-8");
145
70
  const ts = toSafeTimestamp(/* @__PURE__ */ new Date());
@@ -242,14 +167,6 @@ function isValidDerivedFromEntry(entry) {
242
167
  function isConsolidationOperator(value) {
243
168
  return typeof value === "string" && CONSOLIDATION_OPERATORS.includes(value);
244
169
  }
245
- var SEMANTIC_CONSOLIDATION_LLM_OPERATORS = [
246
- "split",
247
- "merge",
248
- "update"
249
- ];
250
- function isSemanticConsolidationLlmOperator(value) {
251
- return typeof value === "string" && SEMANTIC_CONSOLIDATION_LLM_OPERATORS.includes(value);
252
- }
253
170
 
254
171
  // ../remnic-core/src/entity-schema.ts
255
172
  var DEFAULT_ENTITY_SCHEMAS = {
@@ -298,34 +215,6 @@ function toSnakeCase(value) {
298
215
  function titleFromKey(key) {
299
216
  return key.split("_").filter(Boolean).map((token) => token.charAt(0).toUpperCase() + token.slice(1)).join(" ");
300
217
  }
301
- function tokenizeNormalized(value) {
302
- return normalizeEntityText(value).split(/\s+/).filter(Boolean);
303
- }
304
- function normalizeSectionDefinition(raw) {
305
- if (!raw || typeof raw !== "object" || Array.isArray(raw)) return null;
306
- const value = raw;
307
- const keySource = typeof value.key === "string" ? value.key : typeof value.title === "string" ? value.title : "";
308
- const titleSource = typeof value.title === "string" ? value.title : typeof value.key === "string" ? value.key : "";
309
- const key = toSnakeCase(keySource);
310
- const title = titleSource.trim() || titleFromKey(key);
311
- if (!key || !title) return null;
312
- const description = typeof value.description === "string" ? value.description : "";
313
- const aliases = Array.isArray(value.aliases) ? value.aliases.filter((alias) => typeof alias === "string").map((alias) => alias.trim()).filter((alias) => alias.length > 0) : [];
314
- return aliases.length > 0 ? { key, title, description, aliases } : { key, title, description };
315
- }
316
- function normalizeEntitySchemas(raw) {
317
- if (!raw || typeof raw !== "object" || Array.isArray(raw)) return void 0;
318
- const result = {};
319
- for (const [entityType, schema] of Object.entries(raw)) {
320
- if (!schema || typeof schema !== "object" || Array.isArray(schema)) continue;
321
- const rawSections = schema.sections;
322
- if (!Array.isArray(rawSections)) continue;
323
- const sections = rawSections.map((section) => normalizeSectionDefinition(section)).filter((section) => section !== null);
324
- if (sections.length === 0) continue;
325
- result[toSnakeCase(entityType)] = { sections };
326
- }
327
- return Object.keys(result).length > 0 ? result : void 0;
328
- }
329
218
  function mergeEntitySchemaDefinitions(defaults, overrides) {
330
219
  const overrideByKey = new Map(overrides.sections.map((section) => [section.key, section]));
331
220
  const mergedSections = [];
@@ -383,39 +272,6 @@ function normalizeEntityStructuredSection(entityType, section, entitySchemas) {
383
272
  title: section.title.trim() || titleFromKey(key)
384
273
  };
385
274
  }
386
- function queryMentionsAlias(query, alias) {
387
- const queryTokens = tokenizeNormalized(query);
388
- const aliasTokens = tokenizeNormalized(alias);
389
- if (queryTokens.length === 0 || aliasTokens.length === 0) return false;
390
- if (aliasTokens.length > queryTokens.length) return false;
391
- for (let index = 0; index <= queryTokens.length - aliasTokens.length; index += 1) {
392
- let matched = true;
393
- for (let offset = 0; offset < aliasTokens.length; offset += 1) {
394
- if (queryTokens[index + offset] !== aliasTokens[offset]) {
395
- matched = false;
396
- break;
397
- }
398
- }
399
- if (matched) return true;
400
- }
401
- return false;
402
- }
403
- function resolveRequestedEntitySectionKeys(query, entityType, availableSections, entitySchemas) {
404
- if (availableSections.length === 0) return [];
405
- const availableKeys = new Set(availableSections.map((section) => toSnakeCase(section.key)));
406
- const schema = getEntitySchema(entityType, entitySchemas);
407
- if (!schema) return [];
408
- const matches = [];
409
- for (const section of schema.sections) {
410
- const key = toSnakeCase(section.key);
411
- if (!availableKeys.has(key)) continue;
412
- const aliases = [section.title, section.key, ...section.aliases ?? []];
413
- if (aliases.some((alias) => queryMentionsAlias(query, alias))) {
414
- matches.push(key);
415
- }
416
- }
417
- return matches;
418
- }
419
275
  function sortStructuredSectionsBySchema(entityType, sections, entitySchemas) {
420
276
  const schema = getEntitySchema(entityType, entitySchemas);
421
277
  if (!schema || sections.length <= 1) return sections;
@@ -430,36 +286,9 @@ function sortStructuredSectionsBySchema(entityType, sections, entitySchemas) {
430
286
 
431
287
  // ../remnic-core/src/source-attribution.ts
432
288
  var DEFAULT_CITATION_FORMAT = "[Source: agent={agent}, session={sessionId}, ts={ts}]";
433
- var CITATION_UNKNOWN = "unknown";
434
289
  function defaultCitationMatcher() {
435
290
  return /\[Source:\s*([^\]\n]+?)\]/gi;
436
291
  }
437
- function deriveSessionId(session) {
438
- if (!session) return void 0;
439
- const trimmed = session.trim();
440
- if (trimmed.length === 0) return void 0;
441
- const parts = trimmed.split(":").filter((p) => p.length > 0);
442
- if (parts.length === 0) return trimmed;
443
- return parts[parts.length - 1];
444
- }
445
- function formatCitation(ctx, template = DEFAULT_CITATION_FORMAT) {
446
- const session = ctx.session ?? "";
447
- const sessionId = ctx.sessionId ?? deriveSessionId(session) ?? CITATION_UNKNOWN;
448
- const ts = ctx.ts ?? CITATION_UNKNOWN;
449
- const agent = ctx.agent && ctx.agent.trim().length > 0 ? ctx.agent : CITATION_UNKNOWN;
450
- const date = ts && ts !== CITATION_UNKNOWN ? ts.slice(0, 10) : CITATION_UNKNOWN;
451
- const sessionForTemplate = session.trim().length > 0 ? session : CITATION_UNKNOWN;
452
- const values = {
453
- agent,
454
- session: sessionForTemplate,
455
- sessionId,
456
- ts,
457
- date
458
- };
459
- return template.replace(/\{([a-zA-Z_][\w]*)\}/g, (match, name) => {
460
- return Object.prototype.hasOwnProperty.call(values, name) ? values[name] : match;
461
- });
462
- }
463
292
  function hasCitation(text) {
464
293
  if (typeof text !== "string" || text.length === 0) return false;
465
294
  return defaultCitationMatcher().test(text);
@@ -538,15 +367,6 @@ function hasCitationForTemplate(text, template) {
538
367
  }
539
368
  return matcher.test(text);
540
369
  }
541
- function attachCitation(text, ctx, template = DEFAULT_CITATION_FORMAT) {
542
- if (typeof text !== "string") return text;
543
- if (hasCitationForTemplate(text, template)) return text;
544
- const trimmedEnd = text.replace(/\s+$/u, "");
545
- if (trimmedEnd.length === 0) return text;
546
- const citation = formatCitation(ctx, template);
547
- const trailing = text.slice(trimmedEnd.length);
548
- return `${trimmedEnd} ${citation}${trailing}`;
549
- }
550
370
  function stripCitation(text) {
551
371
  if (typeof text !== "string" || text.length === 0) return text;
552
372
  if (!hasCitation(text)) return text;
@@ -596,15 +416,6 @@ function stripCitationForTemplate(text, template) {
596
416
  }
597
417
 
598
418
  // ../remnic-core/src/types.ts
599
- var RECALL_DISCLOSURE_LEVELS = [
600
- "chunk",
601
- "section",
602
- "raw"
603
- ];
604
- var DEFAULT_RECALL_DISCLOSURE = "chunk";
605
- function isRecallDisclosure(value) {
606
- return typeof value === "string" && RECALL_DISCLOSURE_LEVELS.includes(value);
607
- }
608
419
  function confidenceTier(score) {
609
420
  if (score >= 0.95) return "explicit";
610
421
  if (score >= 0.7) return "implied";
@@ -1119,84 +930,6 @@ function readProjectedMemoryBrowse(memoryDir, options) {
1119
930
  };
1120
931
  });
1121
932
  }
1122
- function readProjectedEntityMentions(memoryDir, memoryIds) {
1123
- const db = openProjectionReadonly(memoryDir);
1124
- if (!db) return null;
1125
- try {
1126
- const rows = db.prepare(`
1127
- SELECT
1128
- memory_id,
1129
- entity_ref,
1130
- mention_source,
1131
- created_at,
1132
- updated_at
1133
- FROM memory_entity_mentions
1134
- ORDER BY entity_ref ASC, updated_at DESC, memory_id ASC
1135
- `).all();
1136
- return rows.filter(
1137
- (row) => typeof row.memory_id === "string" && typeof row.entity_ref === "string" && typeof row.mention_source === "string" && typeof row.created_at === "string" && typeof row.updated_at === "string" && (!memoryIds || memoryIds.has(row.memory_id))
1138
- ).map((row) => ({
1139
- memoryId: row.memory_id,
1140
- entityRef: row.entity_ref,
1141
- mentionSource: row.mention_source,
1142
- created: row.created_at,
1143
- updated: row.updated_at
1144
- }));
1145
- } catch {
1146
- return null;
1147
- } finally {
1148
- db.close();
1149
- }
1150
- }
1151
- function readProjectedNativeKnowledgeChunks(memoryDir) {
1152
- const db = openProjectionReadonly(memoryDir);
1153
- if (!db) return null;
1154
- try {
1155
- const rows = db.prepare(`
1156
- SELECT
1157
- chunk_id,
1158
- source_path,
1159
- title,
1160
- source_kind,
1161
- start_line,
1162
- end_line,
1163
- derived_date,
1164
- session_key,
1165
- workflow_key,
1166
- author,
1167
- agent,
1168
- namespace,
1169
- privacy_class,
1170
- source_hash,
1171
- preview_text
1172
- FROM native_knowledge_chunks
1173
- ORDER BY source_kind ASC, source_path ASC, start_line ASC
1174
- `).all();
1175
- return rows.filter(
1176
- (row) => typeof row.chunk_id === "string" && typeof row.source_path === "string" && typeof row.title === "string" && typeof row.source_kind === "string" && typeof row.start_line === "number" && typeof row.end_line === "number" && typeof row.preview_text === "string"
1177
- ).map((row) => ({
1178
- chunkId: row.chunk_id,
1179
- sourcePath: row.source_path,
1180
- title: row.title,
1181
- sourceKind: row.source_kind,
1182
- startLine: row.start_line,
1183
- endLine: row.end_line,
1184
- derivedDate: typeof row.derived_date === "string" ? row.derived_date : void 0,
1185
- sessionKey: typeof row.session_key === "string" ? row.session_key : void 0,
1186
- workflowKey: typeof row.workflow_key === "string" ? row.workflow_key : void 0,
1187
- author: typeof row.author === "string" ? row.author : void 0,
1188
- agent: typeof row.agent === "string" ? row.agent : void 0,
1189
- namespace: typeof row.namespace === "string" ? row.namespace : void 0,
1190
- privacyClass: typeof row.privacy_class === "string" ? row.privacy_class : void 0,
1191
- sourceHash: typeof row.source_hash === "string" ? row.source_hash : void 0,
1192
- preview: row.preview_text
1193
- }));
1194
- } catch {
1195
- return null;
1196
- } finally {
1197
- db.close();
1198
- }
1199
- }
1200
933
  function readProjectedLatestReviewQueue(memoryDir) {
1201
934
  const db = openProjectionReadonly(memoryDir);
1202
935
  if (!db) return null;
@@ -1324,7 +1057,6 @@ function readProjectedGovernanceRecord(memoryDir) {
1324
1057
 
1325
1058
  // ../remnic-core/src/memory-lifecycle-ledger-utils.ts
1326
1059
  import path3 from "path";
1327
- var MEMORY_LIFECYCLE_RULE_VERSION = "memory-lifecycle-ledger.v1";
1328
1060
  var MEMORY_LIFECYCLE_EVENT_SORT_ORDER = {
1329
1061
  created: 0,
1330
1062
  updated: 1,
@@ -1352,52 +1084,6 @@ function inferMemoryStatus(frontmatter, pathRel, fallbackStatus = "active") {
1352
1084
  if (frontmatter.status) return frontmatter.status;
1353
1085
  return fallbackStatus;
1354
1086
  }
1355
- function isActiveMemoryStatus(status) {
1356
- return status === void 0 || status === "active";
1357
- }
1358
- function summarizeMemoryLifecycleState(memory) {
1359
- return {
1360
- category: memory.frontmatter.category,
1361
- path: memory.path,
1362
- status: memory.frontmatter.status ?? "active",
1363
- lifecycleState: memory.frontmatter.lifecycleState
1364
- };
1365
- }
1366
- function makeRebuiltMemoryLifecycleEvent(memory, eventType, timestamp) {
1367
- return {
1368
- eventId: `rebuild-${memory.frontmatter.id}-${eventType}-${timestamp}`,
1369
- memoryId: memory.frontmatter.id,
1370
- eventType,
1371
- timestamp,
1372
- actor: "maintenance.rebuildMemoryLifecycleLedger",
1373
- ruleVersion: MEMORY_LIFECYCLE_RULE_VERSION,
1374
- after: summarizeMemoryLifecycleState(memory),
1375
- relatedMemoryIds: [
1376
- ...memory.frontmatter.supersededBy ? [memory.frontmatter.supersededBy] : [],
1377
- ...memory.frontmatter.supersedes ? [memory.frontmatter.supersedes] : [],
1378
- ...(memory.frontmatter.lineage ?? []).filter(Boolean)
1379
- ]
1380
- };
1381
- }
1382
- function buildLifecycleEventsForMemory(memory) {
1383
- const events = [];
1384
- const created = memory.frontmatter.created;
1385
- const updated = memory.frontmatter.updated;
1386
- const archivedAt = memory.frontmatter.archivedAt;
1387
- const supersededAt = memory.frontmatter.supersededAt;
1388
- const effectiveArchivedAt = archivedAt ?? (memory.frontmatter.status === "archived" && updated ? updated : void 0);
1389
- events.push(makeRebuiltMemoryLifecycleEvent(memory, "created", created));
1390
- if (updated && updated !== created && updated !== effectiveArchivedAt && updated !== supersededAt) {
1391
- events.push(makeRebuiltMemoryLifecycleEvent(memory, "updated", updated));
1392
- }
1393
- if (supersededAt) {
1394
- events.push(makeRebuiltMemoryLifecycleEvent(memory, "superseded", supersededAt));
1395
- }
1396
- if (effectiveArchivedAt) {
1397
- events.push(makeRebuiltMemoryLifecycleEvent(memory, "archived", effectiveArchivedAt));
1398
- }
1399
- return events;
1400
- }
1401
1087
  function sortMemoryLifecycleEvents(events) {
1402
1088
  return [...events].sort((a, b) => {
1403
1089
  if (a.memoryId !== b.memoryId) return a.memoryId.localeCompare(b.memoryId);
@@ -1675,73 +1361,11 @@ function applyContinuityLoopReview(existing, input, nowIso) {
1675
1361
  }
1676
1362
 
1677
1363
  // ../remnic-core/src/utils/iso-timestamp.ts
1678
- var ISO_UTC_TIMESTAMP_RE = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d{3})?Z$/;
1679
- var ISO_OFFSET_TIMESTAMP_RE = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d+)?(?:Z|[+-]\d{2}:\d{2})$/;
1680
1364
  var FLEXIBLE_ISO_TIMESTAMP_RE = /^(\d{4})-(\d{2})-(\d{2})(?:[Tt](\d{2}):(\d{2})(?::(\d{2})(?:\.\d{1,9})?)?(?:[Zz]|([+-])(\d{2}):(\d{2}))?)?$/;
1681
1365
  function isoDaysInMonth(year, month) {
1682
1366
  const leap = year % 4 === 0 && (year % 100 !== 0 || year % 400 === 0);
1683
1367
  return [31, leap ? 29 : 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31][month - 1] ?? 0;
1684
1368
  }
1685
- function validateDateComponents(isoString) {
1686
- const match = isoString.match(
1687
- /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})/
1688
- );
1689
- if (!match) return false;
1690
- const [, yStr, mStr, dStr, hStr, minStr, sStr] = match;
1691
- const y = Number(yStr);
1692
- const m = Number(mStr);
1693
- const d = Number(dStr);
1694
- const h = Number(hStr);
1695
- const min = Number(minStr);
1696
- const s = Number(sStr);
1697
- if (m < 1 || m > 12) return false;
1698
- if (d < 1 || d > 31) return false;
1699
- if (h > 23 || min > 59 || s > 59) return false;
1700
- if (d > isoDaysInMonth(y, m)) return false;
1701
- return true;
1702
- }
1703
- function validateOffset(isoString) {
1704
- const offsetMatch = isoString.match(/([+-])(\d{2}):(\d{2})$/);
1705
- if (!offsetMatch) return true;
1706
- const oh = Number(offsetMatch[2]);
1707
- const om = Number(offsetMatch[3]);
1708
- if (oh > 14 || om > 59) return false;
1709
- if (oh === 14 && om > 0) return false;
1710
- return true;
1711
- }
1712
- function normalizeUtcForComparison(value) {
1713
- const fracMatch = value.match(/\.(\d+)Z$/);
1714
- if (fracMatch) {
1715
- const ms = (fracMatch[1] + "000").slice(0, 3);
1716
- return value.replace(/\.\d+Z$/, `.${ms}Z`);
1717
- }
1718
- return value.replace(/Z$/, ".000Z");
1719
- }
1720
- function parseIsoUtcTimestamp(value) {
1721
- if (typeof value !== "string" || !ISO_UTC_TIMESTAMP_RE.test(value)) {
1722
- return null;
1723
- }
1724
- const ts = Date.parse(value);
1725
- if (!Number.isFinite(ts)) return null;
1726
- if (!validateDateComponents(value)) return null;
1727
- const roundTrip = new Date(ts).toISOString();
1728
- if (roundTrip !== normalizeUtcForComparison(value)) return null;
1729
- return ts;
1730
- }
1731
- function parseIsoOffsetTimestamp(value) {
1732
- if (typeof value !== "string" || !ISO_OFFSET_TIMESTAMP_RE.test(value)) {
1733
- return null;
1734
- }
1735
- const ts = Date.parse(value);
1736
- if (!Number.isFinite(ts)) return null;
1737
- if (!validateDateComponents(value)) return null;
1738
- if (!validateOffset(value)) return null;
1739
- if (value.endsWith("Z")) {
1740
- const roundTrip = new Date(ts).toISOString();
1741
- if (roundTrip !== normalizeUtcForComparison(value)) return null;
1742
- }
1743
- return ts;
1744
- }
1745
1369
  function parseFlexibleIsoTimestamp(value) {
1746
1370
  const match = typeof value === "string" ? value.match(FLEXIBLE_ISO_TIMESTAMP_RE) : null;
1747
1371
  if (!match) {
@@ -1827,9 +1451,6 @@ function normalizeMemoryWriteTimestamp(field, value) {
1827
1451
  }
1828
1452
  return new Date(parsed).toISOString();
1829
1453
  }
1830
- function isErrnoCode(error, code) {
1831
- return typeof error === "object" && error !== null && "code" in error && error.code === code;
1832
- }
1833
1454
  function trimTrailingSpacesAndTabs(value) {
1834
1455
  let end = value.length;
1835
1456
  while (end > 0 && (value[end - 1] === " " || value[end - 1] === " ")) {
@@ -5179,6 +4800,9 @@ ${memory.content}
5179
4800
  } catch {
5180
4801
  }
5181
4802
  }
4803
+ events.sort(
4804
+ (left, right) => Date.parse(left.timestamp) - Date.parse(right.timestamp)
4805
+ );
5182
4806
  if (effectiveLimit === null) return events;
5183
4807
  return events.slice(-effectiveLimit);
5184
4808
  }
@@ -6800,50 +6424,8 @@ ${memory.content}
6800
6424
  };
6801
6425
 
6802
6426
  export {
6803
- normalizeEntityText,
6804
- normalizeEntitySchemas,
6805
- resolveRequestedEntitySectionKeys,
6806
6427
  sanitizeMemoryContent,
6807
- MEMORY_LIFECYCLE_EVENT_SORT_ORDER,
6808
- toMemoryPathRel,
6809
- inferMemoryStatus,
6810
- isActiveMemoryStatus,
6811
- buildLifecycleEventsForMemory,
6812
- sortMemoryLifecycleEvents,
6813
- hasCitationForTemplate,
6814
- attachCitation,
6815
- stripCitationForTemplate,
6816
- getCachedEpisodeMap,
6817
- setCachedEpisodeMap,
6818
- getCachedRuleMemories,
6819
- setCachedRuleMemories,
6820
- getCachedQmdSearch,
6821
- setCachedQmdSearch,
6822
- lintWorkspaceFiles,
6823
- rotateMarkdownFileToArchive,
6824
- DERIVED_FROM_MEMORY_ID_RE,
6825
- isConsolidationOperator,
6826
- isSemanticConsolidationLlmOperator,
6827
- RECALL_DISCLOSURE_LEVELS,
6828
- DEFAULT_RECALL_DISCLOSURE,
6829
- isRecallDisclosure,
6830
- confidenceTier,
6831
- openBetterSqlite3,
6832
- MEMORY_PROJECTION_SCHEMA_VERSION,
6833
- getMemoryProjectionPath,
6834
- memoryCurrentSelectExpressions,
6835
- initializeMemoryProjectionDb,
6836
- parseCurrentRow,
6837
- parseTimelineRows,
6838
- readProjectedEntityMentions,
6839
- readProjectedNativeKnowledgeChunks,
6840
- readProjectedGovernanceRecord,
6841
- normalizeProjectionPreview,
6842
- normalizeProjectionTags,
6843
6428
  parseContinuityImprovementLoops,
6844
- parseIsoUtcTimestamp,
6845
- parseIsoOffsetTimestamp,
6846
- parseFlexibleIsoTimestamp,
6847
6429
  normalizeEntityName,
6848
6430
  ContentHashIndex,
6849
6431
  normalizeAttributePairs,
@@ -0,0 +1,22 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
18
+
19
+ export {
20
+ __export,
21
+ __reExport
22
+ };