@joshuaswarren/openclaw-engram 9.0.53 → 9.0.55

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.
package/dist/index.js CHANGED
@@ -6765,7 +6765,9 @@ function serializeFrontmatter(fm) {
6765
6765
  lines.push(`importanceScore: ${fm.importance.score}`);
6766
6766
  lines.push(`importanceLevel: ${fm.importance.level}`);
6767
6767
  if (fm.importance.reasons.length > 0) {
6768
- lines.push(`importanceReasons: [${fm.importance.reasons.map((r) => `"${r.replace(/"/g, '\\"')}"`).join(", ")}]`);
6768
+ lines.push(
6769
+ `importanceReasons: [${fm.importance.reasons.map((r) => `"${r.replace(/\\/g, "\\\\").replace(/"/g, '\\"')}"`).join(", ")}]`
6770
+ );
6769
6771
  }
6770
6772
  if (fm.importance.keywords.length > 0) {
6771
6773
  lines.push(`importanceKeywords: [${fm.importance.keywords.map((k) => `"${k}"`).join(", ")}]`);
@@ -6780,7 +6782,7 @@ function serializeFrontmatter(fm) {
6780
6782
  lines.push(` - targetId: ${link.targetId}`);
6781
6783
  lines.push(` linkType: ${link.linkType}`);
6782
6784
  lines.push(` strength: ${link.strength}`);
6783
- if (link.reason) lines.push(` reason: "${link.reason.replace(/"/g, '\\"')}"`);
6785
+ if (link.reason) lines.push(` reason: ${JSON.stringify(link.reason)}`);
6784
6786
  }
6785
6787
  }
6786
6788
  if (fm.intentGoal) lines.push(`intentGoal: ${fm.intentGoal}`);
@@ -6795,6 +6797,18 @@ function serializeFrontmatter(fm) {
6795
6797
  lines.push("---");
6796
6798
  return lines.join("\n");
6797
6799
  }
6800
+ function parseLinkReasonValue(rawValue) {
6801
+ const legacyValue = rawValue.replace(/\\"/g, '"');
6802
+ const looksLikeLegacyPath = !rawValue.includes("\\\\") && (/[A-Za-z]:\\[A-Za-z0-9._ -]+(?:\\[A-Za-z0-9._ -]+)*/.test(rawValue) || /\\[A-Za-z0-9._ -]+\\[A-Za-z0-9._ -]+/.test(rawValue));
6803
+ if (looksLikeLegacyPath) {
6804
+ return legacyValue;
6805
+ }
6806
+ try {
6807
+ return JSON.parse(`"${rawValue}"`);
6808
+ } catch {
6809
+ return legacyValue;
6810
+ }
6811
+ }
6798
6812
  function parseFrontmatter3(raw) {
6799
6813
  const match = raw.match(/^---\n([\s\S]*?)\n---\n?([\s\S]*)$/);
6800
6814
  if (!match) return null;
@@ -6836,9 +6850,14 @@ function parseFrontmatter3(raw) {
6836
6850
  const level = fm.importanceLevel || "normal";
6837
6851
  let reasons = [];
6838
6852
  const reasonsStr = fm.importanceReasons ?? "";
6839
- const reasonsMatch = reasonsStr.match(/\[(.*)]/);
6840
- if (reasonsMatch) {
6841
- reasons = reasonsMatch[1].split(/",\s*"/).map((r) => r.replace(/^"|"$/g, "").replace(/\\"/g, '"')).filter(Boolean);
6853
+ if (reasonsStr.trim().startsWith("[") && reasonsStr.trim().endsWith("]")) {
6854
+ const reasonMatches = reasonsStr.matchAll(/"((?:\\.|[^"\\])*)"/g);
6855
+ for (const match2 of reasonMatches) {
6856
+ const reason = parseLinkReasonValue(match2[1]);
6857
+ if (reason.length > 0) {
6858
+ reasons.push(reason);
6859
+ }
6860
+ }
6842
6861
  }
6843
6862
  let keywords = [];
6844
6863
  const keywordsStr = fm.importanceKeywords ?? "";
@@ -6897,14 +6916,14 @@ function parseFrontmatter3(raw) {
6897
6916
  if (fmBlock.includes("links:")) {
6898
6917
  const links = [];
6899
6918
  const linkMatches = fmBlock.matchAll(
6900
- /- targetId: (\S+)\s+linkType: (\S+)\s+strength: ([\d.]+)(?:\s+reason: "([^"]*)")?/g
6919
+ /- targetId: (\S+)\s+linkType: (\S+)\s+strength: ([\d.]+)(?:\s+reason: "((?:\\.|[^"\\])*)")?/g
6901
6920
  );
6902
6921
  for (const match2 of linkMatches) {
6903
6922
  links.push({
6904
6923
  targetId: match2[1],
6905
6924
  linkType: match2[2],
6906
6925
  strength: parseFloat(match2[3]),
6907
- reason: match2[4] || void 0
6926
+ reason: match2[4] ? parseLinkReasonValue(match2[4]) : void 0
6908
6927
  });
6909
6928
  }
6910
6929
  if (links.length > 0) {