Solution for long term memory for agent coding CLIs and to facilitate handoff between different agent vendors
Rust
fix(wiki): preserve anchor and query fragments in local wikilinks
Vinícius DS Andradeb9344d1265cd
diff --git a/crates/ai-memory-wiki/src/markdown.rs b/crates/ai-memory-wiki/src/markdown.rsindex 4dd617a7..3e1cb835 100644--- a/crates/ai-memory-wiki/src/markdown.rs+++ b/crates/ai-memory-wiki/src/markdown.rs@@ -551,14 +551,20 @@ fn resolve_local_wikilink(// source page — `page_path` is unused on this branch of// `normalize_link_target`/`resolve_relative`), `.md` appended,// traversal collapsed.- let target = normalize_link_target(&path_part, page_path, true)?;+ // Split off a trailing #anchor/?query so it survives the rewrite.+ let (clean_path, suffix) = match path_part.find(['#', '?']) {+ Some(i) => (&path_part[..i], &path_part[i..]),+ None => (path_part.as_str(), ""),+ };+ let target = normalize_link_target(clean_path, page_path, true)?;let page_dir: Vec<&str> = page_path.as_str().rsplit_once('/').map_or_else(Vec::new, |(dir, _)| {dir.split('/').filter(|s| !s.is_empty()).collect()});- let href = relative_href(&page_dir, &target);+ let mut href = relative_href(&page_dir, &target);+ href.push_str(suffix);let display = label.map_or(target_part, str::trim).to_string();Some((href, display))}@@ -1286,6 +1292,27 @@ mod tests {);}+ #[test]+ fn rewrite_local_wikilinks_preserves_anchor_and_query_fragments() {+ let path = PagePath::new("concepts/a.md").unwrap();+ assert_eq!(+ rewrite_local_wikilinks("See [[decisions/b.md#context]].", &path, "proj"),+ "See [decisions/b.md#context](../decisions/b.md#context)."+ );+ assert_eq!(+ rewrite_local_wikilinks("[[decisions/b#context|the decision]]", &path, "proj"),+ "[the decision](../decisions/b.md#context)"+ );+ assert_eq!(+ rewrite_local_wikilinks("[[decisions/b.md?v=1#part-2]]", &path, "proj"),+ "[decisions/b.md?v=1#part-2](../decisions/b.md?v=1#part-2)"+ );+ assert_eq!(+ rewrite_local_wikilinks("[[decisions/b#my section|My Section]]", &path, "proj"),+ "[My Section](<../decisions/b.md#my section>)"+ );+ }+#[test]fn rewrite_local_wikilinks_leaves_cross_project_untouched() {let path = PagePath::new("concepts/a.md").unwrap();