Files
buzz/desktop/src-tauri/src/commands/agent_logs.rs
Will Pfleger 654f384906 fix(desktop): read the newest pair-scoped harness log (#3134)
Harnesses became per (agent, relay) pair in #2122 and now write
`agents/logs/{pubkey}__{sha256(relay_url)}.log` via
`managed_agent_runtime_log_path`. `get_managed_agent_log` was never
updated and still read the legacy `agents/logs/{pubkey}.log`, so agent
profile → Runtime → Harness Log froze at each agent's last
single-runtime line while live output accumulated in files the reader
never opened.

The reader now resolves the log through `latest_managed_agent_log_path`,
which picks the most recently modified file belonging to the agent —
pair-scoped `{pubkey}__*.log` or legacy `{pubkey}.log` — and falls back
to the legacy path when the agent has no log on disk at all. Agents that
have not restarted since the update keep working, and the panel follows
whichever harness is currently writing. The response already carried
`log_path`, so the panel header names the file being shown.

Selection is deterministic: equal mtimes break toward the higher
filename, and files belonging to other agents or without a `.log`
extension are never candidates.

`storage.rs`'s inline test module moves to a `#[path]`-included sibling
`storage_tests.rs`, matching the existing pattern in `teams.rs` and
`archive/mod.rs`. This drops both halves under the desktop file-size
limit (1383 → 826 / 701), so the ratchet entries tighten instead of
growing.

Signed-off-by: Will Pfleger <pfleger.will@gmail.com>
Co-authored-by: Duncan <dcfd242e557282d7a1e2cf2e6877522682f1e5c6156dc92ca7d90eaedd3b0f95@buzz.block.builderlab.xyz>
2026-07-27 11:45:03 -04:00

41 lines
1.3 KiB
Rust

use tauri::{AppHandle, Manager};
use crate::{
app_state::AppState,
managed_agents::{
latest_managed_agent_log_path, load_managed_agents, read_log_tail, BackendKind,
ManagedAgentLogResponse,
},
};
#[tauri::command]
pub async fn get_managed_agent_log(
pubkey: String,
line_count: Option<u32>,
app: AppHandle,
) -> Result<ManagedAgentLogResponse, String> {
tokio::task::spawn_blocking(move || {
let state = app.state::<AppState>();
let _store_guard = state
.managed_agents_store_lock
.lock()
.map_err(|error| error.to_string())?;
let records = load_managed_agents(&app)?;
let record = records
.iter()
.find(|record| record.pubkey == pubkey)
.ok_or_else(|| format!("agent {pubkey} not found"))?;
if record.backend != BackendKind::Local {
return Err("logs are not available for remote agents".to_string());
}
let log_path = latest_managed_agent_log_path(&app, &pubkey)?;
Ok(ManagedAgentLogResponse {
content: read_log_tail(&log_path, line_count.unwrap_or(120) as usize)?,
log_path: log_path.display().to_string(),
})
})
.await
.map_err(|e| format!("spawn_blocking failed: {e}"))?
}