Solution for long term memory for agent coding CLIs and to facilitate handoff between different agent vendors
Rust
ci(codeql): move the companions' session-id display helper into ai-memory-client
AkitaOnRails8eec2fc48bb0
diff --git a/.github/codeql/extensions/ai-memory-models/models/log-barriers.model.yml b/.github/codeql/extensions/ai-memory-models/models/log-barriers.model.ymlindex 8d1653d0..e19d4d67 100644--- a/.github/codeql/extensions/ai-memory-models/models/log-barriers.model.yml+++ b/.github/codeql/extensions/ai-memory-models/models/log-barriers.model.yml@@ -4,8 +4,10 @@# the operator's own terminal, not a credential.## `display_session_id` is the one helper that renders a session id for-# terminal output (the CLI's, and the importer's copy, since the importer is-# a separate workspace that cannot call the CLI); declaring its return value+# terminal output (the CLI's, and the companions' copy in the+# `ai-memory-client` library crate, since the companions are a separate+# workspace that cannot call the CLI; a model path in a binary-only crate does+# not resolve); declaring its return value# a log barrier clears those alerts while a real secret (an `api_key`, a# token) logged anywhere else is still reported. Route any new session-id# output through it rather than adding more rows here.@@ -23,4 +25,4 @@ extensions:data:- ["ai_memory_cli::commands::run::display_session_id", "ReturnValue", "log-injection", "manual"]- ["ai_memory_cli::commands::user::display_username", "ReturnValue", "log-injection", "manual"]- - ["ai_memory_importer::agentmemory::display_session_id", "ReturnValue", "log-injection", "manual"]+ - ["ai_memory_client::display_session_id", "ReturnValue", "log-injection", "manual"]diff --git a/companions/ai-memory-client/src/lib.rs b/companions/ai-memory-client/src/lib.rsindex 6304c738..78d0f5b4 100644--- a/companions/ai-memory-client/src/lib.rs+++ b/companions/ai-memory-client/src/lib.rs@@ -6,6 +6,22 @@ use serde_json::Value;mod scrub;pub use scrub::sanitize_external_text;+/// Render a session id for terminal output, bounded so a long id cannot flood+/// a report. CodeQL's sensitive-data heuristic reads any `session_id` name as+/// account information; this is the function its `rust/cleartext-logging`+/// barrier model names for the companions+/// (`.github/codeql/extensions/ai-memory-models/models/log-barriers.model.yml`),+/// so companions print every session id through it. A session id is a routing+/// identifier, not a credential.+pub fn display_session_id(value: &str) -> String {+ const MAX_CHARS: usize = 64;+ let mut output = value.chars().take(MAX_CHARS).collect::<String>();+ if value.chars().count() > MAX_CHARS {+ output.push_str("...");+ }+ output+}+/// Reject credentials and control characters without changing retry identities.pub fn reject_sensitive(value: &Value) -> Result<()> {bounded(value, 0)?;diff --git a/companions/ai-memory-importer/src/agentmemory/mod.rs b/companions/ai-memory-importer/src/agentmemory/mod.rsindex 76cebf8e..425c84f4 100644--- a/companions/ai-memory-importer/src/agentmemory/mod.rs+++ b/companions/ai-memory-importer/src/agentmemory/mod.rs@@ -140,20 +140,7 @@ pub(crate) fn validate_id(id: &str, what: &str) -> Result<()> {Ok(())}-/// Render an agentmemory session id for terminal output, bounded so a long-/// id cannot flood the report. CodeQL's sensitive-data heuristic reads any-/// `session_id` name as account information; this is the one function its-/// `rust/cleartext-logging` barrier model names-/// (`.github/codeql/extensions/ai-memory-models/models/log-barriers.model.yml`),-/// so print every session id through it.-pub(crate) fn display_session_id(value: &str) -> String {- const MAX_CHARS: usize = 64;- let mut output = value.chars().take(MAX_CHARS).collect::<String>();- if value.chars().count() > MAX_CHARS {- output.push_str("...");- }- output-}+pub(crate) use ai_memory_client::display_session_id;/// ai-memory `kind` and `tier` for an agentmemory memory `type`.pub(crate) fn memory_kind_tier(memory_type: &str) -> (&'static str, &'static str) {diff --git a/crates/ai-memory-cli/tests/suite/repo_layout.rs b/crates/ai-memory-cli/tests/suite/repo_layout.rsindex 3ce56a27..7934b16e 100644--- a/crates/ai-memory-cli/tests/suite/repo_layout.rs+++ b/crates/ai-memory-cli/tests/suite/repo_layout.rs@@ -115,6 +115,10 @@ fn codeql_model_targets_exist() {"ai_memory_importer",repo_root.join("companions/ai-memory-importer/src"),),+ (+ "ai_memory_client",+ repo_root.join("companions/ai-memory-client/src"),+ ),];let models_dir = repo_root.join(".github/codeql/extensions/ai-memory-models/models");let mut targets = 0;@@ -136,8 +140,14 @@ fn codeql_model_targets_exist() {segments.remove(0);let function = segments.pop().expect("a path names a function");let module = segments.join("/");- // A module is either `name.rs` or `name/mod.rs`.- let source = [format!("{module}.rs"), format!("{module}/mod.rs")]+ // A crate-root function lives in `lib.rs`; a module is either+ // `name.rs` or `name/mod.rs`.+ let candidates = if module.is_empty() {+ vec!["lib.rs".to_string()]+ } else {+ vec![format!("{module}.rs"), format!("{module}/mod.rs")]+ };+ let source = candidates.iter().find_map(|file| fs::read_to_string(src.join(file)).ok()).unwrap_or_default();