feat: file logging on client, logs command to fetch last N lines

This commit is contained in:
Helios Agent 2026-03-03 17:09:23 +01:00
parent 23bbb5b603
commit db3fa9f416
No known key found for this signature in database
GPG key ID: C8259547CD8309B5
6 changed files with 130 additions and 9 deletions

View file

@ -13,6 +13,7 @@ use base64::Engine;
use helios_common::{ClientMessage, ServerMessage};
use uuid::Uuid;
mod logger;
mod shell;
mod screenshot;
mod input;
@ -76,21 +77,27 @@ macro_rules! log_status {
}
macro_rules! log_ok {
($($arg:tt)*) => {
println!(" {}\t{}", "", format!($($arg)*));
};
($($arg:tt)*) => {{
let msg = format!($($arg)*);
println!(" {}\t{}", "", msg);
logger::write_line("OK", &msg);
}};
}
macro_rules! log_err {
($($arg:tt)*) => {
println!(" {}\t{}", "", format!($($arg)*));
};
($($arg:tt)*) => {{
let msg = format!($($arg)*);
println!(" {}\t{}", "", msg);
logger::write_line("ERROR", &msg);
}};
}
macro_rules! log_cmd {
($emoji:expr, $($arg:tt)*) => {
println!(" {}\t{}", $emoji, format!($($arg)*));
};
($emoji:expr, $($arg:tt)*) => {{
let msg = format!($($arg)*);
println!(" {}\t{}", $emoji, msg);
logger::write_line("CMD", &msg);
}};
}
// ────────────────────────────────────────────────────────────────────────────
@ -173,6 +180,7 @@ async fn main() {
// Enable ANSI color codes on Windows (required when running as admin)
#[cfg(windows)]
enable_ansi();
logger::init();
// Suppress tracing output by default
if std::env::var("RUST_LOG").is_err() {
@ -558,6 +566,13 @@ async fn handle_message(
}
}
ServerMessage::LogsRequest { request_id, lines } => {
log_cmd!("📜", "logs (last {lines} lines)");
let content = logger::tail(lines);
let log_path = logger::get_log_path();
ClientMessage::LogsResponse { request_id, content, log_path }
}
ServerMessage::UploadRequest { request_id, path, content_base64 } => {
log_cmd!("", "upload → {}", path);
match (|| -> Result<(), String> {