Solution for long term memory for agent coding CLIs and to facilitate handoff between different agent vendors
Rust
fix(mcp): decide every as_of conflict before the global branch
AkitaOnRailsf3205392890a
diff --git a/crates/ai-memory-mcp/src/server.rs b/crates/ai-memory-mcp/src/server.rsindex e5a6d6f1..63497f6b 100644--- a/crates/ai-memory-mcp/src/server.rs+++ b/crates/ai-memory-mcp/src/server.rs@@ -2862,13 +2862,12 @@ impl AiMemoryServer {let explicit_scoping = !args.scopes.is_empty()|| named_scope_args_present(args.workspace.as_deref(), args.project.as_deref());// A non-blank `as_of` is explicit intent to read one project as of an- // instant. The global branch below returns its own response, so the- // `as_of` conflict check further down never sees a global query: an- // explicit `global` has to be refused here, and an implicit- // `default_global` broadening must yield to `as_of` the way the- // precedence note above says an explicit arg does.+ // instant. The global branch below returns its own response, so an+ // explicit `global` or `scopes` is refused here, before that branch,+ // and an implicit `default_global` broadening yields to `as_of` the+ // way the precedence note above says an explicit arg does.let as_of_present = args.as_of.as_deref().is_some_and(|s| !s.trim().is_empty());- if as_of_present && args.global.unwrap_or(false) {+ if as_of_present && (args.global.unwrap_or(false) || !args.scopes.is_empty()) {return Err(McpError::invalid_params("as_of cannot be combined with global or scopes",None,@@ -2946,12 +2945,6 @@ impl AiMemoryServer {// RRF. Vector, graph, and the raw-observation fallback stay out// of audit mode.if let Some(raw_as_of) = args.as_of.as_deref().filter(|s| !s.trim().is_empty()) {- if args.global.unwrap_or(false) || !args.scopes.is_empty() {- return Err(McpError::invalid_params(- "as_of cannot be combined with global or scopes",- None,- ));- }let instant: jiff::Timestamp = raw_as_of.trim().parse().map_err(|e| {McpError::invalid_params(format!("as_of must be an ISO-8601 instant: {e}"), None)})?;@@ -14716,6 +14709,53 @@ mod tests {!scoped_text.contains("cluster.md"),"explicit scope must NOT broaden to infra: {scoped_text}");++ // `as_of` wins over default_global too: the time-travel lookup reads+ // the current project (infra) instead of being broadened to a global+ // search that would drop the instant and answer with today's rows.+ let historical = server+ .memory_query(+ Parameters(QueryArgs {+ kind: None,+ tier: None,+ path_prefix: None,+ tag: None,+ query: "recall_token".into(),+ limit: Some(10),+ project: None,+ scopes: Vec::new(),+ workspace: None,+ global: None,+ include_expired: None,+ include_superseded: None,+ pin_first: None,+ explain: None,+ as_of: Some(jiff::Timestamp::now().to_string()),+ answer: None,+ reasoning: None,+ }),+ OptionalParts(test_parts_default()),+ )+ .await+ .unwrap();+ let historical_text = historical+ .content+ .first()+ .and_then(|c| c.as_text())+ .map(|t| t.text.clone())+ .unwrap();+ assert!(+ !historical_text.contains("global_hits"),+ "as_of must not be broadened to global: {historical_text}"+ );+ assert!(+ historical_text.contains("cluster.md"),+ "as_of reads the current project: {historical_text}"+ );+ assert!(+ !historical_text.contains("deploy.md"),+ "as_of stays in the current project: {historical_text}"+ );}#[tokio::test]diff --git a/docs/marker-file.md b/docs/marker-file.mdindex 2bc4b3e9..24f25264 100644--- a/docs/marker-file.md+++ b/docs/marker-file.md@@ -294,9 +294,12 @@ falsy (`false` / `0` / `no` / `off`, quoted or bare). A marker that sets only`[profile]` keys is a settings boundary, like one with `[briefing]` keys.`[recall] default_global` applies to an agent's unscoped `memory_query` and-`memory_recent` calls. The `ai-memory search` and `ai-memory recent` terminal-commands do not read it: those commands stay scoped to the current project-and cover every project only when you pass `--global` (see+`memory_recent` calls. A `memory_query` with `as_of` is not broadened: it+reads the current project as it stood at that instant, and an explicit+`global=true` with `as_of` is refused. The `ai-memory search` and+`ai-memory recent` terminal commands do not read it: those commands stay+scoped to the current project and cover every project only when you pass+`--global` (see[usage.md](usage.md#search-from-the-terminal) and[usage.md](usage.md#recent-pages-from-the-terminal)).diff --git a/docs/temporal.md b/docs/temporal.mdindex 9beb5f77..e5aadec3 100644--- a/docs/temporal.md+++ b/docs/temporal.md@@ -126,6 +126,11 @@ graph neighbours (latest-scoped by construction), and theraw-observation fallback. Audit reads take no access bump and norerank. Omit `as_of` and nothing changes.+An `as_of` query reads one project: the current one, or the one named by+`workspace` + `project`. Combining it with `global=true` or `scopes` is+refused as invalid params. A repository's `[recall] default_global`+marker setting does not broaden it to a cross-project search.+One asymmetry to know: the FTS leg hides pages already TTL-expired atT (the usual `not_expired` predicate evaluated at T); the entity legignores TTL, on the grounds that a page valid at T was still what we