Solution for long term memory for agent coding CLIs and to facilitate handoff between different agent vendors
Rust
fix: omit compaction footer from CRLF excerpts
Rudy Celekli7f32bb284ded
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex e3539787..7139b26d 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -28,6 +28,9 @@ version in [`docs/changelog/`](docs/changelog/):keeping unknown migration edits fatal. CI now rejects changes to migrationfiles already present on a PR's base branch.([#1443](https://github.com/akitaonrails/ai-memory/issues/1443))+- Kept the A2 compaction footer out of SessionStart excerpts for pages with+ CRLF line endings, matching the existing LF behavior.+ ([#1264](https://github.com/akitaonrails/ai-memory/pull/1264))- Sent `response_format=json_schema` for structured OpenCode Chat Completionscalls, with the existing tolerant fallback for models that reject it, so`memory_query answer=true` no longer receives unstructured prose by default.diff --git a/crates/ai-memory-core/src/excerpt.rs b/crates/ai-memory-core/src/excerpt.rsindex 0b0c6a80..6b5ec9e8 100644--- a/crates/ai-memory-core/src/excerpt.rs+++ b/crates/ai-memory-core/src/excerpt.rs@@ -77,7 +77,10 @@ pub fn leading_prose(body: &str) -> Option<String> {end -= 1;}let mut prose = String::new();- for block in body[..end].split("\n\n") {+ for block in body[..end]+ .split("\n\n")+ .flat_map(|block| block.split("\n\r\n"))+ {let block = block.trim();if block.starts_with(COMPACTION_FOOTER_PREFIX) {continue;@@ -354,4 +357,16 @@ mod tests {Some("The writer actor owns every SQLite write. - `WriterHandle`"));}+ #[test]+ fn the_a2_footer_is_not_prose_with_crlf() {+ let body = "The writer actor owns every SQLite write.\n\n## Retained facts\n\n- `WriterHandle`\n\n_Extractively compacted from a cold episodic page (A2 tier-down). The full pre-compaction body is retained in git history._\n";+ let expected = "The writer actor owns every SQLite write. - `WriterHandle`";+ let lf = excerpt(json!({"compacted": true}), body);+ assert_eq!(lf.l0.as_deref(), Some(expected));+ assert_eq!(lf.l1.as_deref(), Some(expected));+ for body in [body.replace('\n', "\r\n"), body.replace("\n\n", "\n\r\n")] {+ let crlf = excerpt(json!({"compacted": true}), &body);+ assert_eq!(crlf, lf, "CRLF excerpts must omit the same A2 footer as LF");+ }+ }}diff --git a/crates/ai-memory-hooks/src/router.rs b/crates/ai-memory-hooks/src/router.rsindex 5b007a22..918f1d94 100644--- a/crates/ai-memory-hooks/src/router.rs+++ b/crates/ai-memory-hooks/src/router.rs@@ -17057,6 +17057,35 @@ pub(crate) mod tests {}}+ #[test]+ fn render_session_brief_omits_a2_footer_from_crlf_excerpts() {+ let body = format!(+ "Writes go through one actor.\n\n## Retained facts\n\n- `WriterHandle`\n\n_Extractively compacted from a cold episodic page (A2 tier-down). The full pre-compaction body is retained in git history._\n\n{}",+ "Later material. ".repeat(BRIEF_BUDGET_MAX / 10)+ );+ for body in [+ body.clone(),+ body.replace('\n', "\r\n"),+ body.replace("\n\n", "\n\r\n"),+ ] {+ let core = vec![brief_core_page(+ "_rules/compacted.md",+ &body,+ true,+ serde_json::json!({"compacted": true}),+ )];+ let out = render_session_brief(&core, &[], BRIEF_BUDGET_DEFAULT).unwrap();+ assert!(+ out.contains("`WriterHandle`"),+ "retained facts stay in the excerpt: {out}"+ );+ assert!(+ !out.contains("Extractively compacted"),+ "SessionStart must not spend its excerpt budget on the A2 footer: {out}"+ );+ }+ }+/// #1360: a frontmatter excerpt longer than the body it describes no/// longer stands in for that body. The body costs less, so it shows/// whole, pinned or not. A page with no body keeps its excerpt rather