@remnic/plugin-openclaw 1.0.34 → 1.0.36

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 +59 -10
  2. package/dist/{calibration-JD4AU7FB.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-YPDWRB3C.js +17 -0
  6. package/dist/capsule-import-SWPOFG6F.js +16 -0
  7. package/dist/{capsule-merge-IWOQ34KL.js → capsule-merge-YXAF7ZJW.js} +7 -7
  8. package/dist/{causal-chain-WYN5QOPS.js → causal-chain-BVTOWZKC.js} +4 -4
  9. package/dist/{causal-consolidation-DSLFN64P.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-FGTYFLL5.js → chunk-3IHGISUN.js} +29 -32
  14. package/dist/{chunk-6UFI73TJ.js → chunk-3IKMUNW5.js} +53 -46
  15. package/dist/{chunk-EXDYWXMB.js → chunk-4XDQ3KEC.js} +1 -2
  16. package/dist/{chunk-4UA6KMRO.js → chunk-6O3H3DPL.js} +2 -2
  17. package/dist/{chunk-7NMHI4IC.js → chunk-BLC3RQNV.js} +5 -555
  18. package/dist/{chunk-4G2XCSD2.js → chunk-BZ4EYURA.js} +0 -5
  19. package/dist/{chunk-4LYQ4ONL.js → chunk-E4RM7637.js} +1 -1
  20. package/dist/{chunk-TDRJVMUP.js → chunk-EH4AXGRO.js} +0 -12
  21. package/dist/{chunk-ZXLYEVOP.js → chunk-G3CZA4SD.js} +60 -362
  22. package/dist/chunk-I2KLQ2HA.js +22 -0
  23. package/dist/chunk-IO5WWY6A.js +156 -0
  24. package/dist/{contradiction-scan-U3QKHWQN.js → chunk-JC3FCKYL.js} +191 -87
  25. package/dist/{chunk-SVSQAG6M.js → chunk-KC7KSQR4.js} +47 -28
  26. package/dist/chunk-LZCGPRHS.js +228 -0
  27. package/dist/{chunk-CXM7EBAO.js → chunk-MXFJXUHC.js} +1 -1
  28. package/dist/{chunk-L6I4MQKO.js → chunk-NNAN63QK.js} +6 -6
  29. package/dist/{chunk-VRGUUHBV.js → chunk-NUWDSTP7.js} +1 -1
  30. package/dist/{chunk-6OJAU466.js → chunk-QMUQV5NP.js} +0 -1
  31. package/dist/{chunk-LLUROTZJ.js → chunk-QQXJODFL.js} +9 -9
  32. package/dist/{chunk-6F6EKSVP.js → chunk-QXXEF7VI.js} +1 -1
  33. package/dist/{chunk-NDZNURDM.js → chunk-SEGEX7W4.js} +73 -241
  34. package/dist/{chunk-7NUFIRM3.js → chunk-SWOYEQN2.js} +97 -21
  35. package/dist/chunk-TH5FF5SC.js +16 -0
  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-57HLTQBN.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-33SPYXQY.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 +7187 -71983
  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-FEQCA35V.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-R3V6ZFQT.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-7L34HYDW.js} +3 -3
  71. package/openclaw.plugin.json +153 -20
  72. package/package.json +18 -9
  73. package/scripts/faiss_index.py +756 -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);
@@ -1674,6 +1360,41 @@ function applyContinuityLoopReview(existing, input, nowIso) {
1674
1360
  };
1675
1361
  }
1676
1362
 
1363
+ // ../remnic-core/src/utils/iso-timestamp.ts
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}))?)?$/;
1365
+ function isoDaysInMonth(year, month) {
1366
+ const leap = year % 4 === 0 && (year % 100 !== 0 || year % 400 === 0);
1367
+ return [31, leap ? 29 : 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31][month - 1] ?? 0;
1368
+ }
1369
+ function parseFlexibleIsoTimestamp(value) {
1370
+ const match = typeof value === "string" ? value.match(FLEXIBLE_ISO_TIMESTAMP_RE) : null;
1371
+ if (!match) {
1372
+ return null;
1373
+ }
1374
+ const year = Number(match[1]);
1375
+ const month = Number(match[2]);
1376
+ const day = Number(match[3]);
1377
+ const hour = match[4] === void 0 ? 0 : Number(match[4]);
1378
+ const minute = match[5] === void 0 ? 0 : Number(match[5]);
1379
+ const second = match[6] === void 0 ? 0 : Number(match[6]);
1380
+ const offsetHour = match[8] === void 0 ? void 0 : Number(match[8]);
1381
+ const offsetMinute = match[9] === void 0 ? void 0 : Number(match[9]);
1382
+ const hasTime = match[4] !== void 0;
1383
+ const hasOffset = offsetHour !== void 0 && offsetMinute !== void 0;
1384
+ const hasTimezone = /(?:[Zz]|[+-]\d{2}:\d{2})$/.test(value);
1385
+ if (month < 1 || month > 12 || day < 1 || day > isoDaysInMonth(year, month) || hasTime && !hasTimezone) {
1386
+ return null;
1387
+ }
1388
+ if (hasTime && (hour > 23 || minute > 59 || second > 59)) {
1389
+ return null;
1390
+ }
1391
+ if (hasOffset && (offsetMinute > 59 || offsetHour > 14 || offsetHour === 14 && offsetMinute > 0)) {
1392
+ return null;
1393
+ }
1394
+ const ts = Date.parse(value);
1395
+ return Number.isFinite(ts) ? ts : null;
1396
+ }
1397
+
1677
1398
  // ../remnic-core/src/storage.ts
1678
1399
  var ARTIFACT_SEARCH_STOPWORDS = /* @__PURE__ */ new Set([
1679
1400
  "a",
@@ -1718,8 +1439,17 @@ function assertMemoryWorthCounter(field, value) {
1718
1439
  throw new Error(`${field} must be >= 0, got ${value}`);
1719
1440
  }
1720
1441
  }
1721
- function isErrnoCode(error, code) {
1722
- return typeof error === "object" && error !== null && "code" in error && error.code === code;
1442
+ function normalizeMemoryWriteTimestamp(field, value) {
1443
+ if (value === void 0) return void 0;
1444
+ if (typeof value !== "string") {
1445
+ throw new Error(`${field} must be an ISO timestamp string, got ${String(value)}`);
1446
+ }
1447
+ const trimmed = value.trim();
1448
+ const parsed = parseFlexibleIsoTimestamp(trimmed);
1449
+ if (parsed === null) {
1450
+ throw new Error(`${field} must be a valid ISO timestamp, got ${JSON.stringify(value)}`);
1451
+ }
1452
+ return new Date(parsed).toISOString();
1723
1453
  }
1724
1454
  function trimTrailingSpacesAndTabs(value) {
1725
1455
  let end = value.length;
@@ -3729,6 +3459,7 @@ var StorageManager = class _StorageManager {
3729
3459
  const id = `${category}-${Date.now()}-${Math.random().toString(36).slice(2, 6)}`;
3730
3460
  const conf = options.confidence ?? 0.8;
3731
3461
  const tier = confidenceTier(conf);
3462
+ const validAt = normalizeMemoryWriteTimestamp("validAt", options.validAt);
3732
3463
  let expiresAt;
3733
3464
  if (typeof options.expiresAt === "string" && options.expiresAt.length > 0) {
3734
3465
  expiresAt = options.expiresAt;
@@ -3758,6 +3489,7 @@ var StorageManager = class _StorageManager {
3758
3489
  sourceMemoryId: options.sourceMemoryId,
3759
3490
  sourceTurnId: options.sourceTurnId,
3760
3491
  memoryKind: options.memoryKind,
3492
+ valid_at: validAt,
3761
3493
  structuredAttributes: options.structuredAttributes
3762
3494
  };
3763
3495
  if (options.status !== void 0) {
@@ -5068,6 +4800,9 @@ ${memory.content}
5068
4800
  } catch {
5069
4801
  }
5070
4802
  }
4803
+ events.sort(
4804
+ (left, right) => Date.parse(left.timestamp) - Date.parse(right.timestamp)
4805
+ );
5071
4806
  if (effectiveLimit === null) return events;
5072
4807
  return events.slice(-effectiveLimit);
5073
4808
  }
@@ -6413,6 +6148,7 @@ ${memory.content}
6413
6148
  const id = `${parentId}-chunk-${chunkIndex}`;
6414
6149
  const conf = options.confidence ?? 0.8;
6415
6150
  const tier = confidenceTier(conf);
6151
+ const validAt = normalizeMemoryWriteTimestamp("validAt", options.validAt);
6416
6152
  const fm = {
6417
6153
  id,
6418
6154
  category,
@@ -6430,7 +6166,8 @@ ${memory.content}
6430
6166
  intentGoal: options.intentGoal,
6431
6167
  intentActionType: options.intentActionType,
6432
6168
  intentEntityTypes: options.intentEntityTypes,
6433
- memoryKind: options.memoryKind
6169
+ memoryKind: options.memoryKind,
6170
+ valid_at: validAt
6434
6171
  };
6435
6172
  const sanitized = sanitizeMemoryContent(content);
6436
6173
  if (!sanitized.clean) {
@@ -6687,46 +6424,7 @@ ${memory.content}
6687
6424
  };
6688
6425
 
6689
6426
  export {
6690
- normalizeEntityText,
6691
- normalizeEntitySchemas,
6692
- resolveRequestedEntitySectionKeys,
6693
6427
  sanitizeMemoryContent,
6694
- MEMORY_LIFECYCLE_EVENT_SORT_ORDER,
6695
- toMemoryPathRel,
6696
- inferMemoryStatus,
6697
- isActiveMemoryStatus,
6698
- buildLifecycleEventsForMemory,
6699
- sortMemoryLifecycleEvents,
6700
- hasCitationForTemplate,
6701
- attachCitation,
6702
- stripCitationForTemplate,
6703
- getCachedEpisodeMap,
6704
- setCachedEpisodeMap,
6705
- getCachedRuleMemories,
6706
- setCachedRuleMemories,
6707
- getCachedQmdSearch,
6708
- setCachedQmdSearch,
6709
- lintWorkspaceFiles,
6710
- rotateMarkdownFileToArchive,
6711
- DERIVED_FROM_MEMORY_ID_RE,
6712
- isConsolidationOperator,
6713
- isSemanticConsolidationLlmOperator,
6714
- RECALL_DISCLOSURE_LEVELS,
6715
- DEFAULT_RECALL_DISCLOSURE,
6716
- isRecallDisclosure,
6717
- confidenceTier,
6718
- openBetterSqlite3,
6719
- MEMORY_PROJECTION_SCHEMA_VERSION,
6720
- getMemoryProjectionPath,
6721
- memoryCurrentSelectExpressions,
6722
- initializeMemoryProjectionDb,
6723
- parseCurrentRow,
6724
- parseTimelineRows,
6725
- readProjectedEntityMentions,
6726
- readProjectedNativeKnowledgeChunks,
6727
- readProjectedGovernanceRecord,
6728
- normalizeProjectionPreview,
6729
- normalizeProjectionTags,
6730
6428
  parseContinuityImprovementLoops,
6731
6429
  normalizeEntityName,
6732
6430
  ContentHashIndex,
@@ -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
+ };