Code graph and memory for your coding agents, in one Rust program. For Claude Code, Codex, Cursor and any MCP client.
Rust agent-memoryai-agentsclaude-codecode-analysiscode-graphcode-intelligencecode-searchcodexcoding-agentscontext-engineeringcursordeveloper-toolsgraphragknowledge-graphlocal-firstmcpmcp-servermodel-context-protocolrusttree-sitter
fix: cut a long conversation opening on a character boundary
Rudy Celeklic0230b4109e1
diff --git a/crates/graphicle-memory/src/standing.rs b/crates/graphicle-memory/src/standing.rsindex 35a4eec..6b8bfbd 100644--- a/crates/graphicle-memory/src/standing.rs+++ b/crates/graphicle-memory/src/standing.rs@@ -151,10 +151,13 @@ pub fn openings(text: &str) -> Vec<(usize, usize)> {}let mut b = b;if b - a > 300 {- b = a + text[a..a + 300].rfind(' ').unwrap_or(300);- while !text.is_char_boundary(b) {- b -= 1;+ // The first 300 bytes, back to a character boundary: byte 300+ // can fall inside a multi-byte character.+ let mut cut = a + 300;+ while !text.is_char_boundary(cut) {+ cut -= 1;}+ b = text[a..cut].rfind(' ').map_or(cut, |space| a + space);}found.push((a, b));}@@ -387,6 +390,23 @@ mod tests {);}+ #[test]+ fn a_long_opening_ends_on_a_character_boundary() {+ // Byte 300 of the opening falls inside an "é" (two bytes).+ let text = format!("User: I need help with {}\n", "\u{e9}".repeat(200));+ let spans = openings(&text);+ assert_eq!(spans.len(), 1, "{spans:?}");+ let (a, b) = spans[0];+ assert_eq!(&text[a..b], "I need help with");+ // Without a space in the first 300 bytes the cut is at the last+ // whole character.+ let text = format!("User: x{} b c d\n", "\u{4f60}".repeat(120));+ let spans = openings(&text);+ assert_eq!(spans.len(), 1, "{spans:?}");+ let (a, b) = spans[0];+ assert_eq!(text[a..b], format!("x{}", "\u{4f60}".repeat(99)));+ }+#[test]fn conflicts_pair_a_denial_with_the_users_own_statements_on_its_subject() {let early = "Conversation date: 2024/03/10 (Sun) 00:00\n\n\