search: exclude seen set when running in agent session
Make Session::from_env() and Session::seen() the public API for accessing session state. Internal callers converted to use session methods. Search automatically filters already-surfaced nodes when POC_SESSION_ID is set.
This commit is contained in:
parent
5c3baeea80
commit
9d84dde597
3 changed files with 38 additions and 8 deletions
|
|
@ -43,6 +43,24 @@ impl Session {
|
|||
pub fn path(&self, prefix: &str) -> PathBuf {
|
||||
self.state_dir.join(format!("{}-{}", prefix, self.session_id))
|
||||
}
|
||||
|
||||
/// Load from POC_SESSION_ID environment variable
|
||||
pub fn from_env() -> Option<Self> {
|
||||
let session_id = std::env::var("POC_SESSION_ID").ok()?;
|
||||
if session_id.is_empty() { return None; }
|
||||
let state_dir = PathBuf::from("/tmp/claude-memory-search");
|
||||
Some(Session {
|
||||
session_id,
|
||||
transcript_path: String::new(),
|
||||
hook_event: String::new(),
|
||||
state_dir,
|
||||
})
|
||||
}
|
||||
|
||||
/// Get the seen set for this session
|
||||
pub fn seen(&self) -> HashSet<String> {
|
||||
load_seen(&self.state_dir, &self.session_id)
|
||||
}
|
||||
}
|
||||
|
||||
/// Run the hook logic on parsed JSON input. Returns output to inject.
|
||||
|
|
@ -202,7 +220,7 @@ fn surface_agent_cycle(session: &Session, out: &mut String, log_f: &mut File) {
|
|||
let _ = writeln!(log_f, "keys {:?}", keys);
|
||||
|
||||
let Ok(store) = crate::store::Store::load() else { return; };
|
||||
let mut seen = load_seen(&session.state_dir, &session.session_id);
|
||||
let mut seen = session.seen();
|
||||
let seen_path = session.path("seen");
|
||||
for key in &keys {
|
||||
if !seen.insert(key.clone()) {
|
||||
|
|
@ -304,7 +322,7 @@ fn hook(session: &Session) -> String {
|
|||
if output.status.success() {
|
||||
let ctx = String::from_utf8_lossy(&output.stdout).to_string();
|
||||
if !ctx.trim().is_empty() {
|
||||
let mut ctx_seen = load_seen(&session.state_dir, &session.session_id);
|
||||
let mut ctx_seen = session.seen();
|
||||
for line in ctx.lines() {
|
||||
if line.starts_with("--- ") && line.ends_with(" ---") {
|
||||
let inner = &line[4..line.len() - 4];
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue