Solution for long term memory for agent coding CLIs and to facilitate handoff between different agent vendors
Rust
fix(importer): explain why a long document page cannot be verified
João Matheusdff600a2a7d9
diff --git a/companions/ai-memory-importer/src/document.rs b/companions/ai-memory-importer/src/document.rsindex 6ab42aa9..2ea7df61 100644--- a/companions/ai-memory-importer/src/document.rs+++ b/companions/ai-memory-importer/src/document.rs@@ -303,6 +303,10 @@ pub(crate) async fn run(args: DocumentArgs) -> Result<()> {.with_context(|| {format!("reading {} after a refused write", plan.destination_path)})?;+ if let Some(error) = current.unverifiable(&plan.destination_path) {+ manifest.fail(manifest_path, &error)?;+ return Err(error);+ }if current.body != plan.body {let error = anyhow!("{} already holds a page this document import did not write; refusing to replace it",diff --git a/companions/ai-memory-importer/src/mcp.rs b/companions/ai-memory-importer/src/mcp.rsindex 55f068df..ab035f4b 100644--- a/companions/ai-memory-importer/src/mcp.rs+++ b/companions/ai-memory-importer/src/mcp.rs@@ -76,6 +76,29 @@ pub(crate) struct McpWrite<'a> {pub(crate) struct ReadPage {pub(crate) page_id: Option<String>,pub(crate) body: String,+ /// The server cut `body` short, so it is not the stored page.+ pub(crate) truncated: bool,+ /// The stored body's full length in characters, when the server says.+ pub(crate) total_chars: Option<u64>,+}++impl ReadPage {+ /// Why a rerun cannot compare this page with a planned body, if the+ /// server cut it. A page longer than [`READ_PAGE_MAX_CHARS`] never comes+ /// back whole, so it can be told apart neither from the planned body nor+ /// from someone else's edit.+ pub(crate) fn unverifiable(&self, path: &str) -> Option<anyhow::Error> {+ self.truncated.then(|| {+ let length = self.total_chars.map_or_else(+ || "longer".to_owned(),+ |total| format!("{total} characters long, longer"),+ );+ anyhow!(+ "{path} is {length} than memory_read_page returns, so the import cannot \+ compare it with the planned body; nothing was written to it"+ )+ })+ }}impl ImportClient {@@ -168,6 +191,11 @@ impl ImportClient {.and_then(Value::as_str).unwrap_or_default().to_owned(),+ truncated: page+ .get("truncated")+ .and_then(Value::as_bool)+ .unwrap_or(false),+ total_chars: page.get("total_chars").and_then(Value::as_u64),})}