Solution for long term memory for agent coding CLIs and to facilitate handoff between different agent vendors
Rust
fix(auto-improve): accept string evidence quotes
AkitaOnRailsf8ffb6e7f027
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex fa763fb3..fc90da26 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -36,6 +36,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0to pick up new proactive retrieval and `memory_auto_improve` guidance.### Fixed+- `auto-improve` now tolerates LLM evidence arrays that contain bare quote+ strings instead of `{ page, quote }` objects. Bare strings are normalized into+ bounded quote evidence before validation, so one model-format slip no longer+ turns a dry-run review into a 502 response.- Admin destructive ops (`/admin/purge-project`, `/admin/move-project`) nowpropagate the authenticated actor (from the auth middleware's`Extension<ActorContext>`) into the admission context, so a `scope-guard`diff --git a/crates/ai-memory-consolidate/src/auto_improve.rs b/crates/ai-memory-consolidate/src/auto_improve.rsindex 8ec9b877..5376c2a0 100644--- a/crates/ai-memory-consolidate/src/auto_improve.rs+++ b/crates/ai-memory-consolidate/src/auto_improve.rs@@ -10,7 +10,7 @@ use ai_memory_core::{Observation, ObservationKind, PagePath, ProjectId, SessionIuse ai_memory_llm::{ChatMessage, ChatRequest, LlmError, LlmProvider, Role, complete_structured};use ai_memory_store::{BriefingPage, ReaderPool, StoredPageBody};use schemars::JsonSchema;-use serde::{Deserialize, Serialize};+use serde::{Deserialize, Serialize, de};use thiserror::Error;const CHARS_PER_TOKEN: usize = 4;@@ -88,7 +88,7 @@ pub enum AutoImproveError {pub type AutoImproveResult<T> = Result<T, AutoImproveError>;/// One evidence quote cited by a proposal.-#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]+#[derive(Debug, Clone, Serialize, JsonSchema)]pub struct AutoImproveEvidence {/// Source page or observation label, such as `sessions/<id>.md`.pub page: String,@@ -96,6 +96,28 @@ pub struct AutoImproveEvidence {pub quote: String,}+impl<'de> Deserialize<'de> for AutoImproveEvidence {+ fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>+ where+ D: de::Deserializer<'de>,+ {+ #[derive(Deserialize)]+ #[serde(untagged)]+ enum EvidenceInput {+ Object { page: String, quote: String },+ Quote(String),+ }++ match EvidenceInput::deserialize(deserializer)? {+ EvidenceInput::Object { page, quote } => Ok(Self { page, quote }),+ EvidenceInput::Quote(quote) => Ok(Self {+ page: "unspecified".into(),+ quote,+ }),+ }+ }+}+/// One proposed wiki edit returned by the LLM and accepted by validation.#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]pub struct AutoImproveProposal {@@ -971,6 +993,38 @@ mod tests {assert!(warnings.is_empty());}+ #[test]+ fn evidence_deserializes_bare_string_quotes() {+ let raw: AutoImproveLlmResponse = serde_json::from_value(serde_json::json!({+ "summary": "ok",+ "proposals": [{+ "operation": "create_or_update",+ "path": "procedures/release.md",+ "title": "Release Procedure",+ "kind": "procedure",+ "confidence": 0.91,+ "rationale": "The session repeated a release workflow with verification.",+ "evidence": ["run the full gate before release"],+ "body_markdown": "# Release Procedure\n\nRun the full gate before release."+ }],+ "rejected_candidates": []+ }))+ .unwrap();++ assert_eq!(raw.proposals[0].evidence.len(), 1);+ assert_eq!(raw.proposals[0].evidence[0].page, "unspecified");+ assert_eq!(+ raw.proposals[0].evidence[0].quote,+ "run the full gate before release"+ );++ let (accepted, rejected, warnings) =+ validate_response(raw, &cfg(), &ExistingPageIndex::default());+ assert_eq!(accepted.len(), 1);+ assert!(rejected.is_empty());+ assert!(warnings.is_empty());+ }+#[test]fn prompt_uses_session_page_and_samples_high_signal_long_sessions() {let session_id = SessionId::new();