feat(story-93): expose server logs to agents via get_server_logs MCP tool

- Add log_buffer module: bounded 1000-line ring buffer with push/get_recent API
- Add slog! macro: drop-in for eprintln! that also captures to ring buffer
- Replace all eprintln! calls across agents, watcher, search, chat, worktree, claude_code with slog!
- Add get_server_logs MCP tool: accepts count (1-500) and optional filter params
- 5 unit tests for log_buffer covering push/retrieve, eviction, filtering, count limits, empty buffer
- 262 tests passing, clippy clean

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Dave
2026-02-23 20:38:19 +00:00
parent 3d480e7c22
commit 8c6bd4cf74
10 changed files with 243 additions and 66 deletions

View File

@@ -1,3 +1,4 @@
use crate::slog;
use portable_pty::{CommandBuilder, PtySize, native_pty_system};
use std::io::{BufRead, BufReader, Write};
use std::sync::Arc;
@@ -152,7 +153,7 @@ fn run_pty_session(
// Allow nested spawning when the server itself runs inside Claude Code
cmd.env("CLAUDECODE", "");
eprintln!(
slog!(
"[pty-debug] Spawning: claude -p \"{}\" {} --output-format stream-json --verbose",
user_message,
resume_session_id
@@ -165,7 +166,7 @@ fn run_pty_session(
.spawn_command(cmd)
.map_err(|e| format!("Failed to spawn claude: {e}"))?;
eprintln!(
slog!(
"[pty-debug] Process spawned, pid: {:?}",
child.process_id()
);
@@ -187,23 +188,23 @@ fn run_pty_session(
std::thread::spawn(move || {
let buf_reader = BufReader::new(reader);
eprintln!("[pty-debug] Reader thread started");
slog!("[pty-debug] Reader thread started");
for line in buf_reader.lines() {
match line {
Ok(l) => {
eprintln!("[pty-debug] raw line: {}", l);
slog!("[pty-debug] raw line: {}", l);
if line_tx.send(Some(l)).is_err() {
break;
}
}
Err(e) => {
eprintln!("[pty-debug] read error: {e}");
slog!("[pty-debug] read error: {e}");
let _ = line_tx.send(None);
break;
}
}
}
eprintln!("[pty-debug] Reader thread done");
slog!("[pty-debug] Reader thread done");
let _ = line_tx.send(None);
});
@@ -223,7 +224,7 @@ fn run_pty_session(
continue;
}
eprintln!(
slog!(
"[pty-debug] processing: {}...",
&trimmed[..trimmed.len().min(120)]
);