Skip to content

Solution for long term memory for agent coding CLIs and to facilitate handoff between different agent vendors

Rust

ci(codeql): model the session-id display helper as a log barrier

AkitaOnRailsb2033d5ac997
diff --git a/.github/codeql/extensions/ai-memory-models/codeql-pack.yml b/.github/codeql/extensions/ai-memory-models/codeql-pack.yml
new file mode 100644
index 00000000..3eb10ae6
--- /dev/null
+++ b/.github/codeql/extensions/ai-memory-models/codeql-pack.yml
@@ -0,0 +1,7 @@
+name: akitaonrails/ai-memory-models
+version: 0.0.1
+library: true
+extensionTargets:
+ codeql/rust-all: '*'
+dataExtensions:
+ - models/**/*.yml
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.yml
new file mode 100644
index 00000000..3ad92b18
--- /dev/null
+++ b/.github/codeql/extensions/ai-memory-models/models/log-barriers.model.yml
@@ -0,0 +1,17 @@
+# CodeQL's sensitive-data heuristic treats any name matching `session.?(id|key)`
+# as account information, so every `eprintln!` of a native session id raised a
+# `rust/cleartext-logging` alert. A session id is a routing identifier shown on
+# the operator's own terminal, not a credential.
+#
+# `display_session_id` is the one helper that renders a session id for
+# terminal output; 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; the CLI test `codeql_model_targets_exist` fails if a
+# modeled function is renamed or moved.
+extensions:
+ - addsTo:
+ pack: codeql/rust-all
+ extensible: barrierModel
+ data:
+ - ["ai_memory_cli::commands::run::display_session_id", "ReturnValue", "log-injection", "manual"]
diff --git a/crates/ai-memory-cli/tests/suite/repo_layout.rs b/crates/ai-memory-cli/tests/suite/repo_layout.rs
index 04d397fa..91a06191 100644
--- a/crates/ai-memory-cli/tests/suite/repo_layout.rs
+++ b/crates/ai-memory-cli/tests/suite/repo_layout.rs
@@ -98,3 +98,47 @@ fn integration_tests_cost_at_most_one_binary_per_crate() {
}
assert!(problems.is_empty(), "{}", problems.join("\n"));
}
+
+/// Every function a CodeQL model under `.github/codeql/extensions` names must
+/// still exist where its path says. A renamed or moved function would leave
+/// the model matching nothing, and the alerts it clears would silently return.
+#[test]
+fn codeql_model_targets_exist() {
+ let repo_root = crates_dir()
+ .parent()
+ .expect("crates/ lives in the repository root")
+ .to_path_buf();
+ let models_dir = repo_root.join(".github/codeql/extensions/ai-memory-models/models");
+ let mut targets = 0;
+ let mut problems = Vec::new();
+ for entry in fs::read_dir(&models_dir)
+ .expect("read the CodeQL model dir")
+ .flatten()
+ {
+ let text = fs::read_to_string(entry.path()).expect("read model file");
+ for target in text
+ .split('"')
+ .filter(|token| token.starts_with("ai_memory_cli::"))
+ {
+ targets += 1;
+ let mut segments: Vec<&str> = target.split("::").skip(1).collect();
+ let function = segments.pop().expect("a path names a function");
+ let file = crates_dir()
+ .join("ai-memory-cli/src")
+ .join(format!("{}.rs", segments.join("/")));
+ let source = fs::read_to_string(&file).unwrap_or_default();
+ if !source.contains(&format!("fn {function}(")) {
+ problems.push(format!(
+ "{target}: no `fn {function}(` in {}",
+ file.display()
+ ));
+ }
+ }
+ }
+ assert!(targets > 0, "the model dir names no ai_memory_cli function");
+ assert!(
+ problems.is_empty(),
+ "stale CodeQL model targets:\n{}",
+ problems.join("\n")
+ );
+}