From 6fc10b0508f598e492ac8ecf6d480d8759d5a088 Mon Sep 17 00:00:00 2001 From: Kent Overstreet Date: Sun, 22 Mar 2026 03:49:08 -0400 Subject: [PATCH] poc-hook: search last 8 lines for surface agent result marker The agent output now includes logging (think blocks, tool calls) before the final response. Search the tail instead of checking only the last line. Co-Authored-By: Claude Opus 4.6 (1M context) --- poc-memory/src/bin/poc-hook.rs | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/poc-memory/src/bin/poc-hook.rs b/poc-memory/src/bin/poc-hook.rs index 389db98..ad05d33 100644 --- a/poc-memory/src/bin/poc-hook.rs +++ b/poc-memory/src/bin/poc-hook.rs @@ -265,12 +265,18 @@ fn main() { if agent_done { if let Ok(result) = fs::read_to_string(&result_path) { if !result.trim().is_empty() { - let last_line = result.lines().rev() - .find(|l| !l.trim().is_empty()) - .unwrap_or(""); + // Search the last 8 non-empty lines for the marker + let tail_lines: Vec<&str> = result.lines().rev() + .filter(|l| !l.trim().is_empty()) + .take(8) + .collect(); + let has_new = tail_lines.iter() + .any(|l| l.starts_with("NEW RELEVANT MEMORIES:")); + let has_none = tail_lines.iter() + .any(|l| l.starts_with("NO NEW RELEVANT MEMORIES")); - if last_line.starts_with("NEW RELEVANT MEMORIES:") { - // Parse key list from lines after the marker + if has_new { + // Parse key list from lines after the last marker let after_marker = result.rsplit_once("NEW RELEVANT MEMORIES:") .map(|(_, rest)| rest) .unwrap_or(""); @@ -305,7 +311,7 @@ fn main() { } } } - } else if !last_line.starts_with("NO NEW RELEVANT MEMORIES") { + } else if !has_none { // Unexpected output — log error let log_dir = poc_memory::store::memory_dir().join("logs"); fs::create_dir_all(&log_dir).ok(); @@ -315,8 +321,9 @@ fn main() { { use std::io::Write; let ts = chrono::Local::now().format("%Y-%m-%dT%H:%M:%S"); + let last = tail_lines.first().unwrap_or(&""); let _ = writeln!(f, "[{}] unexpected surface output: {}", - ts, last_line); + ts, last); } } }