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)

View file

@ -252,11 +252,17 @@ pub fn scan_pid_files(state_dir: &std::path::Path, timeout_secs: u64) -> Vec<(St
/// Spawn an agent asynchronously. Writes the pid file before returning
/// so the caller immediately sees the agent as running.
/// Spawn result: pid and path to the agent's log file.
pub struct SpawnResult {
pub pid: u32,
pub log_path: PathBuf,
}
pub fn spawn_agent(
agent_name: &str,
state_dir: &std::path::Path,
session_id: &str,
) -> Option<u32> {
) -> Option<SpawnResult> {
let def = super::defs::get_def(agent_name)?;
let first_phase = def.steps.first()
.map(|s| s.phase.as_str())
@ -265,8 +271,8 @@ pub fn spawn_agent(
let log_dir = dirs::home_dir().unwrap_or_default()
.join(format!(".consciousness/logs/{}", agent_name));
fs::create_dir_all(&log_dir).ok();
let agent_log = fs::File::create(
log_dir.join(format!("{}.log", store::compact_timestamp())))
let log_path = log_dir.join(format!("{}.log", store::compact_timestamp()));
let agent_log = fs::File::create(&log_path)
.unwrap_or_else(|_| fs::File::create("/dev/null").unwrap());
let child = std::process::Command::new("poc-memory")
@ -281,7 +287,7 @@ pub fn spawn_agent(
let pid = child.id();
let pid_path = state_dir.join(format!("pid-{}", pid));
fs::write(&pid_path, first_phase).ok();
Some(pid)
Some(SpawnResult { pid, log_path })
}
fn run_one_agent_inner(