Skip to content

Solution for long term memory for agent coding CLIs and to facilitate handoff between different agent vendors

Rust

fix(consolidate): append .md to sanitized page paths so multi-page consolidation writes portable paths (#885)

AkitaOnRails385e865dd57e
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 39186f2d..b8102312 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -20,6 +20,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
query before falling back. (#873)
### Fixed
+- Multi-page consolidation now stores page paths with a `.md` extension.
+ The LLM returns a bare path for a non-rule page (`decisions/smart-model-luna`),
+ and the shared path sanitizer passed it through verbatim, so the page landed
+ extensionless and read back as a non-portable wiki path. The sanitizer now
+ appends `.md` to the filename component when it is missing (idempotent,
+ case-insensitive), fixing the non-rule consolidation, bootstrap, and
+ auto-improve front doors at once. (#885)
- `ai-memory run`'s auto-wire no longer overwrites an installed session-aware
Claude Code MCP bridge with the static HTTP registration. The auto-wire
sentinel is keyed by client version, so the MCP step re-ran on every upgrade
diff --git a/crates/ai-memory-consolidate/src/consolidator.rs b/crates/ai-memory-consolidate/src/consolidator.rs
index 2727d9d4..b8d35e98 100644
--- a/crates/ai-memory-consolidate/src/consolidator.rs
+++ b/crates/ai-memory-consolidate/src/consolidator.rs
@@ -2123,6 +2123,36 @@ mod tests {
assert_eq!(req.frontmatter["slot_kind"], "state");
}
+ #[test]
+ fn build_update_appends_md_to_bare_non_rule_path() {
+ // #885: the LLM returns a multi-page path with no extension
+ // (`decisions/smart-model-luna`). The non-rule branch routes it
+ // through `slugify_page_path`, which must land it as a portable
+ // `.md` page rather than storing it extensionless.
+ let update = crate::types::ConsolidatedPageUpdate {
+ path: "decisions/smart-model-luna".into(),
+ tier: Tier::Semantic,
+ kind: crate::types::PageKind::Fact,
+ title: "Smart model Luna".into(),
+ body_markdown: "body".into(),
+ summary: None,
+ tags: Vec::new(),
+ slot_kind: SlotKind::State,
+ relations: Relations::default(),
+ entities: Vec::new(),
+ };
+ let (req, _) = build_update(
+ WorkspaceId::new(),
+ ProjectId::new(),
+ &update,
+ true,
+ &ai_memory_core::ActorContext::anonymous(),
+ None,
+ )
+ .unwrap();
+ assert_eq!(req.path.as_str(), "decisions/smart-model-luna.md");
+ }
+
#[test]
fn build_update_stamps_request_actor_and_author() {
let update = crate::types::ConsolidatedPageUpdate {
diff --git a/crates/ai-memory-consolidate/src/path_sanitize.rs b/crates/ai-memory-consolidate/src/path_sanitize.rs
index a994e386..4cb2ce62 100644
--- a/crates/ai-memory-consolidate/src/path_sanitize.rs
+++ b/crates/ai-memory-consolidate/src/path_sanitize.rs
@@ -29,8 +29,18 @@ pub(crate) const PATH_ILLEGAL_CHARS: &[char] = &['<', '>', ':', '"', '|', '?', '
/// Replace every Windows-illegal character and ASCII control byte in each
/// `/`-separated component with `-`, keeping the `dir/subdir/name.md` shape
/// intact so the model's intended layout survives.
+///
+/// The model also omits the `.md` extension on multi-page paths (`decisions/
+/// smart-model-luna` instead of `.../smart-model-luna.md`, #885). The rule
+/// branch in `build_update` always appends `.md` itself, but the non-rule
+/// branch — and bootstrap and auto-improve — route straight through this
+/// helper, so a bare path would be stored extensionless and read back as a
+/// non-portable wiki page. Append `.md` to the final component when it lacks
+/// it (case-insensitive), which is idempotent: a path already ending in `.md`
+/// is left untouched.
pub(crate) fn slugify_page_path(raw: &str) -> String {
- raw.split('/')
+ let mut segments: Vec<String> = raw
+ .split('/')
.map(|segment| {
segment
.chars()
@@ -43,8 +53,16 @@ pub(crate) fn slugify_page_path(raw: &str) -> String {
})
.collect::<String>()
})
- .collect::<Vec<_>>()
- .join("/")
+ .collect();
+ // Append the `.md` extension when the model omitted it on the filename
+ // component (#885). The check is case-insensitive so `NAME.MD` is not
+ // double-extended, keeping the whole operation idempotent.
+ if let Some(last) = segments.last_mut()
+ && !last.to_ascii_lowercase().ends_with(".md")
+ {
+ last.push_str(".md");
+ }
+ segments.join("/")
}
#[cfg(test)]
@@ -67,4 +85,31 @@ mod tests {
"an already-portable path must be left unchanged"
);
}
+
+ #[test]
+ fn slugify_page_path_appends_md_when_the_model_omits_it() {
+ // #885: multi-page consolidation echoes a bare model path with no
+ // extension; the helper must land it as a portable `.md` page.
+ let slug = slugify_page_path("decisions/smart-model-luna");
+ assert!(
+ slug.ends_with("-luna.md"),
+ "bare model path must gain a .md extension, got {slug:?}"
+ );
+ assert_eq!(slug, "decisions/smart-model-luna.md");
+ }
+
+ #[test]
+ fn slugify_page_path_extension_append_is_idempotent() {
+ // A path already ending in `.md` (any casing) keeps its single
+ // extension — the helper never double-extends.
+ assert_eq!(
+ slugify_page_path("decisions/smart-model-luna.md"),
+ "decisions/smart-model-luna.md"
+ );
+ assert_eq!(
+ slugify_page_path("decisions/SHOUTING.MD"),
+ "decisions/SHOUTING.MD",
+ "an existing .MD extension is recognized case-insensitively"
+ );
+ }
}