Agent log screen: show agent output, not hook log

spawn_agent() now returns SpawnResult { pid, log_path } so the
log path is known at spawn time. No more filesystem scanning.
AgentInfo carries log_path, TUI reads it directly.

F2 → Enter shows the actual agent log (stdout/stderr from the
poc-memory agent process), not the hook orchestration log.

Co-Authored-By: Proof of Concept <poc@bcachefs.org>
This commit is contained in:
Kent Overstreet 2026-04-02 01:04:54 -04:00
parent 1c190a3925
commit a90bd4fd47
3 changed files with 65 additions and 79 deletions

View file

@ -140,6 +140,8 @@ pub struct AgentInfo {
pub name: &'static str,
pub pid: Option<u32>,
pub phase: Option<String>,
/// Path to the most recent agent log file.
pub log_path: Option<std::path::PathBuf>,
}
/// Persistent state for the agent orchestration cycle.
@ -164,7 +166,7 @@ impl AgentCycleState {
.create(true).append(true).open(log_path).ok();
let agents = AGENT_CYCLE_NAMES.iter()
.map(|&name| AgentInfo { name, pid: None, phase: None })
.map(|&name| AgentInfo { name, pid: None, phase: None, log_path: None })
.collect();
AgentCycleState {
@ -185,10 +187,14 @@ impl AgentCycleState {
}
}
fn update_agent(&mut self, name: &str, pid: Option<u32>, phase: Option<String>) {
fn update_agent(&mut self, name: &str, pid: Option<u32>, phase: Option<String>,
log_path: Option<std::path::PathBuf>) {
if let Some(agent) = self.agents.iter_mut().find(|a| a.name == name) {
agent.pid = pid;
agent.phase = phase;
if log_path.is_some() {
agent.log_path = log_path;
}
}
}
@ -266,10 +272,10 @@ impl AgentCycleState {
let live = crate::agents::knowledge::scan_pid_files(&state_dir, timeout);
if let Some((phase, pid)) = live.first() {
self.update_agent("surface-observe", Some(*pid), Some(phase.clone()));
self.update_agent("surface-observe", Some(*pid), Some(phase.clone()), None);
self.log(format_args!("alive pid-{}: phase={}\n", pid, phase));
} else {
self.update_agent("surface-observe", None, None);
self.update_agent("surface-observe", None, None, None);
}
// Read surfaced keys
@ -304,11 +310,12 @@ impl AgentCycleState {
if transcript.size > 0 {
fs::write(&offset_path, transcript.size.to_string()).ok();
}
let pid = crate::agents::knowledge::spawn_agent(
let spawned = crate::agents::knowledge::spawn_agent(
"surface-observe", &state_dir, &session.session_id);
self.update_agent("surface-observe",
pid, Some("surface".into()));
self.log(format_args!("spawned agent {:?}\n", pid));
spawned.as_ref().map(|s| s.pid), Some("surface".into()),
spawned.as_ref().map(|s| s.log_path.clone()));
self.log(format_args!("spawned agent {:?}\n", spawned.as_ref().map(|s| s.pid)));
}
// Wait if agent is significantly behind
@ -353,7 +360,7 @@ impl AgentCycleState {
let live = crate::agents::knowledge::scan_pid_files(&state_dir, 300);
if let Some((phase, pid)) = live.first() {
self.update_agent("reflect", Some(*pid), Some(phase.clone()));
self.update_agent("reflect", Some(*pid), Some(phase.clone()), None);
self.log(format_args!("reflect: already running pid {}\n", pid));
return None;
}
@ -373,10 +380,12 @@ impl AgentCycleState {
}
fs::write(&offset_path, transcript.size.to_string()).ok();
let pid = crate::agents::knowledge::spawn_agent(
let spawned = crate::agents::knowledge::spawn_agent(
"reflect", &state_dir, &session.session_id);
self.update_agent("reflect", pid, Some("step-0".into()));
self.log(format_args!("reflect: spawned {:?}\n", pid));
self.update_agent("reflect",
spawned.as_ref().map(|s| s.pid), Some("step-0".into()),
spawned.as_ref().map(|s| s.log_path.clone()));
self.log(format_args!("reflect: spawned {:?}\n", spawned.as_ref().map(|s| s.pid)));
reflection
}
@ -397,16 +406,18 @@ impl AgentCycleState {
let live = crate::agents::knowledge::scan_pid_files(&state_dir, 300);
if let Some((phase, pid)) = live.first() {
self.update_agent("journal", Some(*pid), Some(phase.clone()));
self.update_agent("journal", Some(*pid), Some(phase.clone()), None);
self.log(format_args!("journal: already running pid {}\n", pid));
return;
}
fs::write(&offset_path, transcript.size.to_string()).ok();
let pid = crate::agents::knowledge::spawn_agent(
let spawned = crate::agents::knowledge::spawn_agent(
"journal", &state_dir, &session.session_id);
self.update_agent("journal", pid, Some("step-0".into()));
self.log(format_args!("journal: spawned {:?}\n", pid));
self.update_agent("journal",
spawned.as_ref().map(|s| s.pid), Some("step-0".into()),
spawned.as_ref().map(|s| s.log_path.clone()));
self.log(format_args!("journal: spawned {:?}\n", spawned.as_ref().map(|s| s.pid)));
}
} // end impl AgentCycleState (cycle methods)