diff --git a/poc-memory/src/cli/agent.rs b/poc-memory/src/cli/agent.rs index d5f1d5f..0350830 100644 --- a/poc-memory/src/cli/agent.rs +++ b/poc-memory/src/cli/agent.rs @@ -4,8 +4,12 @@ use crate::store; use crate::agents::llm; pub fn cmd_run_agent(agent: &str, count: usize, target: &[String], query: Option<&str>, dry_run: bool, local: bool) -> Result<(), String> { + // Mark as agent so tool calls (e.g. poc-memory render) don't + // pollute the user's seen set as a side effect + // SAFETY: single-threaded at this point (CLI startup, before any agent work) + unsafe { std::env::set_var("POC_AGENT", "1"); } + if dry_run { - // SAFETY: single-threaded at this point (CLI startup, before any agent work) unsafe { std::env::set_var("POC_MEMORY_DRY_RUN", "1"); } } diff --git a/poc-memory/src/cli/node.rs b/poc-memory/src/cli/node.rs index bb5173a..9a762cf 100644 --- a/poc-memory/src/cli/node.rs +++ b/poc-memory/src/cli/node.rs @@ -249,18 +249,21 @@ pub fn cmd_render(key: &[String]) -> Result<(), String> { .ok_or_else(|| format!("Node not found: {}", bare))?; print!("{}", rendered); - // Mark as seen if we're inside a Claude session - if let Ok(session_id) = std::env::var("POC_SESSION_ID") { - if !session_id.is_empty() { - let state_dir = std::path::PathBuf::from("/tmp/claude-memory-search"); - let seen_path = state_dir.join(format!("seen-{}", session_id)); - if let Ok(mut f) = std::fs::OpenOptions::new() - .create(true).append(true).open(seen_path) - { - use std::io::Write; - let ts = chrono::Local::now().format("%Y-%m-%dT%H:%M:%S"); - let _ = writeln!(f, "{}\t{}", ts, bare); - } + // Mark as seen if we're inside a Claude session (not an agent subprocess — + // agents read the seen set but shouldn't write to it as a side effect of + // tool calls; only surface_agent_cycle should mark keys seen) + if std::env::var("POC_AGENT").is_err() + && let Ok(session_id) = std::env::var("POC_SESSION_ID") + && !session_id.is_empty() + { + let state_dir = std::path::PathBuf::from("/tmp/claude-memory-search"); + let seen_path = state_dir.join(format!("seen-{}", session_id)); + if let Ok(mut f) = std::fs::OpenOptions::new() + .create(true).append(true).open(seen_path) + { + use std::io::Write; + let ts = chrono::Local::now().format("%Y-%m-%dT%H:%M:%S"); + let _ = writeln!(f, "{}\t{}", ts, bare); } }