Solution for long term memory for agent coding CLIs and to facilitate handoff between different agent vendors
Rust
fix(store): keep column filters inside parenthesised search groups
Rudy Celekli4d7c2cd6811e
diff --git a/crates/ai-memory-store/src/fts_query.rs b/crates/ai-memory-store/src/fts_query.rsindex f4050184..49ce0c83 100644--- a/crates/ai-memory-store/src/fts_query.rs+++ b/crates/ai-memory-store/src/fts_query.rs@@ -211,6 +211,21 @@ fn fts5_query_parses(query: &str) -> bool {}fn prepare_fts5_token(token: &str) -> Vec<String> {+ // Group parens hug the token (`(title:handoff`, `body:deploy)`), so peel+ // them before the column checks below, which look at the token's start.+ let open = token.len() - token.trim_start_matches('(').len();+ let close = token.len() - token.trim_end_matches(')').len();+ if (open > 0 || close > 0) && open + close < token.len() {+ let mut parts = prepare_fts5_token(&token[open..token.len() - close]);+ if let Some(first) = parts.first_mut() {+ first.insert_str(0, &token[..open]);+ }+ if let Some(last) = parts.last_mut() {+ last.push_str(&token[token.len() - close..]);+ }+ return parts;+ }+if has_unknown_bare_column(token) {return token.replace(':', " ")@@ -578,6 +593,34 @@ mod tests {}}+ /// A column filter inside a group keeps its column: the paren attached+ /// to `title:` must not turn it into an unknown column whose name is+ /// then searched as the literal word "title".+ #[test]+ fn grouped_known_column_filter_keeps_its_column() {+ assert_eq!(prepare_fts5_query("(title:handoff)"), "(title:handoff)");+ assert_eq!(+ prepare_fts5_query("(title:handoff OR body:deploy)"),+ "(title:handoff OR body:deploy)"+ );+ assert_eq!(+ prepare_fts5_query("(title:ai-memory) AND deploy"),+ r#"(title:("ai-memory" OR "ai memory")) AND deploy"#+ );+ for raw in [+ "(title:handoff)",+ "((title:a)",+ "(pick: handoff)",+ "(",+ "(title:)",+ ] {+ let prepared = prepare_fts5_query(raw);+ if !prepared.is_empty() {+ assert_parses(&prepared);+ }+ }+ }+// --- issue #953: configurable stopword list -----------------------/// A custom (Portuguese) list filters the words on that list, but neverdiff --git a/crates/ai-memory-store/src/ops.rs b/crates/ai-memory-store/src/ops.rsindex 5c5d81e5..de12a3be 100644--- a/crates/ai-memory-store/src/ops.rs+++ b/crates/ai-memory-store/src/ops.rs@@ -16562,6 +16562,29 @@ pub(crate) mod tests {assert_eq!(hits, vec!["notes/titled.md".to_string()]);}+ #[test]+ fn grouped_title_filter_searches_only_titles() {+ let (_tmp, mut conn, ws, proj) = fresh_db();+ upsert_page(+ &mut conn,+ &NewPage {+ title: "handoff protocol".into(),+ ..page(ws, proj, "notes/titled.md", "unrelated body")+ },+ )+ .unwrap();+ upsert_page(+ &mut conn,+ &page(ws, proj, "notes/mention.md", "a body about the handoff"),+ )+ .unwrap();++ for raw in ["(title:handoff)", "(title:handoff OR title:deploy)"] {+ let hits = fts_match_paths(&conn, raw).unwrap();+ assert_eq!(hits, vec!["notes/titled.md".to_string()], "{raw}");+ }+ }+/// Regression for the live-found hyphen bug: searching `ui-refresh`/// returned nothing in prod even though/// `follow-ups/ui-refresh-scroll-restoration.md` exists. The first fix