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) <noreply@anthropic.com>
This commit is contained in:
Kent Overstreet 2026-03-22 03:49:08 -04:00
parent d2255784dc
commit 6fc10b0508

View file

@ -265,12 +265,18 @@ fn main() {
if agent_done { if agent_done {
if let Ok(result) = fs::read_to_string(&result_path) { if let Ok(result) = fs::read_to_string(&result_path) {
if !result.trim().is_empty() { if !result.trim().is_empty() {
let last_line = result.lines().rev() // Search the last 8 non-empty lines for the marker
.find(|l| !l.trim().is_empty()) let tail_lines: Vec<&str> = result.lines().rev()
.unwrap_or(""); .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:") { if has_new {
// Parse key list from lines after the marker // Parse key list from lines after the last marker
let after_marker = result.rsplit_once("NEW RELEVANT MEMORIES:") let after_marker = result.rsplit_once("NEW RELEVANT MEMORIES:")
.map(|(_, rest)| rest) .map(|(_, rest)| rest)
.unwrap_or(""); .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 // Unexpected output — log error
let log_dir = poc_memory::store::memory_dir().join("logs"); let log_dir = poc_memory::store::memory_dir().join("logs");
fs::create_dir_all(&log_dir).ok(); fs::create_dir_all(&log_dir).ok();
@ -315,8 +321,9 @@ fn main() {
{ {
use std::io::Write; use std::io::Write;
let ts = chrono::Local::now().format("%Y-%m-%dT%H:%M:%S"); 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: {}", let _ = writeln!(f, "[{}] unexpected surface output: {}",
ts, last_line); ts, last);
} }
} }
} }