Solution for long term memory for agent coding CLIs and to facilitate handoff between different agent vendors
Rust
fix(importer): cover empty frontmatter fences
AkitaOnRails1220b3ea4918
diff --git a/companions/ai-memory-importer/src/main.rs b/companions/ai-memory-importer/src/main.rsindex 856cd865..65556716 100644--- a/companions/ai-memory-importer/src/main.rs+++ b/companions/ai-memory-importer/src/main.rs@@ -1105,10 +1105,15 @@ fn split_frontmatter(input: &str) -> Result<(Option<YamlMap>, String)> {return Ok((None, input.to_owned()));};// The closing fence may also end the file with no line ending after it.- let split = rest- .find(&close)- .map(|end| (&rest[..end], &rest[end + close.len()..]))- .or_else(|| rest.strip_suffix("\n---").map(|yaml| (yaml, "")));+ let split = if let Some(body) = rest.strip_prefix(&close[1..]) {+ Some(("", body))+ } else if rest == "---" {+ Some(("", ""))+ } else {+ rest.find(&close)+ .map(|end| (&rest[..end], &rest[end + close.len()..]))+ .or_else(|| rest.strip_suffix("\n---").map(|yaml| (yaml, "")))+ };let Some((yaml, body)) = split else {return Ok((None, input.to_owned()));};@@ -1449,10 +1454,6 @@ mod tests {assert!(parse_markdown("---\ntitle: a\ntitle: b\n---\nbody").is_err());}- /// A wiki checked out on Windows with `core.autocrlf=true`, or saved- /// there by an editor, has CRLF line endings; one saved as "UTF-8 with- /// BOM" opens with U+FEFF. Either used to miss the fence, so kind, tier,- /// tags and pin were dropped and the YAML block was imported as body./// A frontmatter-only page whose closing fence ends the file with no/// final newline, which the server's parser has accepted since #1402.#[test]@@ -1469,8 +1470,18 @@ mod tests {let not_a_fence = parse_markdown("---\ntitle: T\n----").unwrap();assert_eq!(not_a_fence.title, None);++ let empty = parse_markdown("---\n---").unwrap();+ assert_eq!(empty.body, "");+ let empty_with_body = parse_markdown("---\n---\n# Body\n").unwrap();+ assert_eq!(empty_with_body.title.as_deref(), Some("Body"));+ assert_eq!(empty_with_body.body, "# Body\n");}+ /// A wiki checked out on Windows with `core.autocrlf=true`, or saved+ /// there by an editor, has CRLF line endings; one saved as "UTF-8 with+ /// BOM" opens with U+FEFF. Either used to miss the fence, so kind, tier,+ /// tags and pin were dropped and the YAML block was imported as body.#[test]fn parses_omc_frontmatter_with_crlf_or_a_bom() {let crlf = "---\r\ntitle: T\r\nkind: rule\r\ntier: procedural\r\ntags: [a, b]\r\npinned: true\r\n---\r\n# Body\r\ntext";