Solution for long term memory for agent coding CLIs and to facilitate handoff between different agent vendors
Rust
feat(cli): load admission_webhooks from config + wire chain into serve
Djalma Júnior8a83634ba330
diff --git a/crates/ai-memory-cli/Cargo.toml b/crates/ai-memory-cli/Cargo.tomlindex 428a7a14..db8cc515 100644--- a/crates/ai-memory-cli/Cargo.toml+++ b/crates/ai-memory-cli/Cargo.toml@@ -41,6 +41,7 @@ tar.workspace = truejiff.workspace = truetokio.workspace = truetokio-util.workspace = true+tower.workspace = truetower-http.workspace = truetracing.workspace = truetracing-appender.workspace = truediff --git a/crates/ai-memory-cli/src/commands/serve.rs b/crates/ai-memory-cli/src/commands/serve.rsindex f13f2512..22c86686 100644--- a/crates/ai-memory-cli/src/commands/serve.rs+++ b/crates/ai-memory-cli/src/commands/serve.rs@@ -93,6 +93,23 @@ pub async fn run(config: &Config, args: ServeArgs) -> Result<()> {let sanitizer = Sanitizer::new(&config.sanitize).context("compiling sanitizer.extra_patterns from config")?;let wiki = Wiki::new(&config.data_dir, store.writer.clone())?.with_sanitizer(sanitizer.clone());+ // Attach the admission webhook chain (operator-configured via+ // `[[admission_webhooks]]` in config.toml or `AI_MEMORY_ADMISSION_WEBHOOKS__N__*`+ // env vars). Empty config = no chain attached, zero overhead. The store+ // reader is forwarded so the chain can resolve workspace_id/project_id+ // into the human names webhooks address pages by.+ let wiki = if config.admission_webhooks.is_empty() {+ wiki+ } else {+ let chain = ai_memory_wiki::AdmissionChain::new(config.admission_webhooks.clone())+ .context("building admission webhook chain")?;+ tracing::info!(+ count = config.admission_webhooks.len(),+ "admission webhook chain attached"+ );+ wiki.with_admission_chain(chain)+ .with_store_reader(store.reader.clone())+ };let provider_health = ProviderHealth::default();let (wiki, embedder) = configure_embedder(config, &store, wiki, &provider_health).await?;@@ -877,6 +894,7 @@ mod tests {tier: Tier::Semantic,pinned: false,title: None,+ admission_ctx: None,}).await.unwrap();diff --git a/crates/ai-memory-cli/src/config.rs b/crates/ai-memory-cli/src/config.rsindex f357da08..804dcfac 100644--- a/crates/ai-memory-cli/src/config.rs+++ b/crates/ai-memory-cli/src/config.rs@@ -115,6 +115,23 @@ pub struct Config {/// `*` is rejected.#[serde(deserialize_with = "deserialize_string_or_vec", default)]pub cors_allow_origins: Vec<String>,+ /// Admission webhook chain — synchronous HTTP hooks invoked in+ /// [`ai_memory_wiki::Wiki::write_page`] just before page persistence.+ /// Each entry is a [`ai_memory_wiki::WebhookConfig`]. Empty by default+ /// (no chain attached → engine runs as before). Configure via TOML:+ /// ```toml+ /// [[admission_webhooks]]+ /// name = "contributors"+ /// url = "http://contributors-webhook.memory.svc.cluster.local/enrich"+ /// timeout_ms = 2000+ /// failure_policy = "ignore"+ /// events = ["write_page", "consolidate"]+ /// ```+ /// Env override: `AI_MEMORY_ADMISSION_WEBHOOKS__0__URL=…`,+ /// `AI_MEMORY_ADMISSION_WEBHOOKS__0__NAME=…`, etc.+ /// See [`ai_memory_wiki::admission`] for the contract.+ #[serde(default)]+ pub admission_webhooks: Vec<ai_memory_wiki::WebhookConfig>,/// Process-only env values that should never be written to config files.#[serde(skip)]pub runtime_env: RuntimeEnv,@@ -244,6 +261,7 @@ impl Default for Config {auth: AuthSettings::default(),allowed_hosts: vec!["localhost".into(), "127.0.0.1".into(), "::1".into()],cors_allow_origins: Vec::new(),+ admission_webhooks: Vec::new(),runtime_env: RuntimeEnv::default(),}}@@ -313,6 +331,22 @@ impl Config {if let Some(server_url) = runtime_env.server_url.clone() {config.server_url = server_url;}+ // Convenience env override for the admission webhook list. Figment+ // can't reliably round-trip `Vec<Struct>` from `AI_MEMORY_X__0__Y`+ // (env split builds a Map, not a Vec), so we accept a single+ // JSON-encoded env var instead — perfect for charts that+ // `toJson` a values.yaml list. Overrides anything figment loaded+ // from file/other env layers.+ if let Ok(raw) = std::env::var("AI_MEMORY_ADMISSION_WEBHOOKS_JSON")+ && !raw.trim().is_empty()+ {+ let parsed: Vec<ai_memory_wiki::WebhookConfig> = serde_json::from_str(&raw)+ .with_context(|| {+ "parsing AI_MEMORY_ADMISSION_WEBHOOKS_JSON (must be a JSON array of \+ {name,url,timeout_ms?,failure_policy?,events})"+ })?;+ config.admission_webhooks = parsed;+ }// CLI override always wins (figment doesn't see it because clap has// already parsed the flag into `cli_data_dir`).