Skip to content

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

Rust

refactor(lint): group run_lint switches into LintOptions

AkitaOnRails6630a43777d1
diff --git a/crates/ai-memory-cli/src/commands/serve.rs b/crates/ai-memory-cli/src/commands/serve.rs
index c1bf70b6..949d0fec 100644
--- a/crates/ai-memory-cli/src/commands/serve.rs
+++ b/crates/ai-memory-cli/src/commands/serve.rs
@@ -1264,9 +1264,11 @@ async fn run_scheduled_lint_tick(
llm,
scope.workspace_id,
scope.project_id,
- false,
- false,
- decay_lambda,
+ ai_memory_consolidate::LintOptions {
+ dry_run: false,
+ use_llm: false,
+ decay_lambda,
+ },
)
.await
{
diff --git a/crates/ai-memory-consolidate/src/lib.rs b/crates/ai-memory-consolidate/src/lib.rs
index 76fa5d06..8345b3cd 100644
--- a/crates/ai-memory-consolidate/src/lib.rs
+++ b/crates/ai-memory-consolidate/src/lib.rs
@@ -63,7 +63,7 @@ pub use curator::{
pub use embed::{
EmbedBackfillCounts, EmbedBackfillError, EmbedBackfillOptions, run_embedding_backfill,
};
-pub use lint::{LintError, LintFinding, LintReport, run_lint};
+pub use lint::{LintError, LintFinding, LintOptions, LintReport, run_lint, stale_days_for};
pub use sweep::{EvictedPage, SweepError, SweepReport, run_sweep, run_sweep_with_breadth};
pub use types::{
ConsolidatedBatch, ConsolidatedPage, ConsolidatedPageUpdate, ConsolidationOutcome, PageKind,
diff --git a/crates/ai-memory-consolidate/src/lint.rs b/crates/ai-memory-consolidate/src/lint.rs
index df88dc48..94e0634d 100644
--- a/crates/ai-memory-consolidate/src/lint.rs
+++ b/crates/ai-memory-consolidate/src/lint.rs
@@ -122,6 +122,33 @@ pub fn stale_days_for(lambda: f64) -> f64 {
}
}
+/// Options for [`run_lint`].
+///
+/// A struct rather than three positional parameters: `false, false` at a
+/// call site said nothing about which switch was which, and the threshold
+/// input has to travel alongside them.
+#[derive(Debug, Clone, Copy)]
+pub struct LintOptions {
+ /// When `true`, no `_lint/<date>.md` page is written.
+ pub dry_run: bool,
+ /// When `false`, the LLM contradiction pass is skipped even if a
+ /// provider was supplied.
+ pub use_llm: bool,
+ /// The operator's `[decay] lambda`. The stale threshold is derived from
+ /// it — see [`stale_days_for`].
+ pub decay_lambda: f64,
+}
+
+impl Default for LintOptions {
+ fn default() -> Self {
+ Self {
+ dry_run: false,
+ use_llm: true,
+ decay_lambda: 0.02,
+ }
+ }
+}
+
/// Run the lint pass.
///
/// * `llm` — when `Some`, the contradiction pass runs; otherwise the
@@ -141,10 +168,13 @@ pub async fn run_lint(
llm: Option<&std::sync::Arc<dyn LlmProvider>>,
workspace_id: WorkspaceId,
project_id: ProjectId,
- dry_run: bool,
- use_llm: bool,
- decay_lambda: f64,
+ options: LintOptions,
) -> Result<LintReport, LintError> {
+ let LintOptions {
+ dry_run,
+ use_llm,
+ decay_lambda,
+ } = options;
let candidates = reader.decay_candidates(workspace_id, project_id).await?;
let mut findings = rule_based_findings(&candidates, stale_days_for(decay_lambda));
@@ -509,7 +539,8 @@ mod tests {
salience: None,
};
- let default_lambda = rule_based_findings(&[candidate.clone()], stale_days_for(0.02));
+ let default_lambda =
+ rule_based_findings(std::slice::from_ref(&candidate), stale_days_for(0.02));
assert!(
default_lambda.iter().any(|f| f.kind == "stale"),
"60d page must be stale at the default lambda"
diff --git a/crates/ai-memory-consolidate/tests/lifecycle.rs b/crates/ai-memory-consolidate/tests/lifecycle.rs
index 805e716e..8d88ea35 100644
--- a/crates/ai-memory-consolidate/tests/lifecycle.rs
+++ b/crates/ai-memory-consolidate/tests/lifecycle.rs
@@ -424,9 +424,11 @@ async fn m8_retention_lifecycle_end_to_end() {
None,
ws,
proj,
- /* dry_run */ true,
- /* use_llm */ true,
- /* decay_lambda */ ai_memory_store::DecayParams::default().lambda,
+ ai_memory_consolidate::LintOptions {
+ dry_run: true,
+ use_llm: true,
+ decay_lambda: ai_memory_store::DecayParams::default().lambda,
+ },
)
.await
.expect("lint dry-run");
diff --git a/crates/ai-memory-mcp/src/admin.rs b/crates/ai-memory-mcp/src/admin.rs
index c024d53d..2365bc90 100644
--- a/crates/ai-memory-mcp/src/admin.rs
+++ b/crates/ai-memory-mcp/src/admin.rs
@@ -2714,9 +2714,11 @@ async fn handle_lint(
state.llm.as_ref(),
ws,
proj,
- req.dry_run,
- !req.no_llm,
- state.decay_params.lambda,
+ ai_memory_consolidate::LintOptions {
+ dry_run: req.dry_run,
+ use_llm: !req.no_llm,
+ decay_lambda: state.decay_params.lambda,
+ },
)
.await
.map(|report| {
diff --git a/crates/ai-memory-mcp/src/server.rs b/crates/ai-memory-mcp/src/server.rs
index addc1616..8797f876 100644
--- a/crates/ai-memory-mcp/src/server.rs
+++ b/crates/ai-memory-mcp/src/server.rs
@@ -2422,9 +2422,11 @@ impl AiMemoryServer {
self.llm.as_ref(),
ws,
proj,
- args.dry_run.unwrap_or(false),
- !args.no_llm.unwrap_or(false),
- self.decay_params.lambda,
+ ai_memory_consolidate::LintOptions {
+ dry_run: args.dry_run.unwrap_or(false),
+ use_llm: !args.no_llm.unwrap_or(false),
+ decay_lambda: self.decay_params.lambda,
+ },
)
.await
.map_err(|e| McpError::internal_error(e.to_string(), None))?;