Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion mesh/crates/mesh-llm-cli/src/parser/logging_help.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ pub fn logging_help() -> &'static str {
" Path precedence logging.application_state_root, then ",
"MESH_LLM_DATA_DIR/logging, then the local default above.\n",
" Retention setting logging.retention_ttl_secs (default: 129600 seconds).\n",
" Terminal lifecycle Pretty/TUI and --log-format json project the same lifecycle facts; fatal output redacts sensitive fragments while retaining context.\n",
" Terminal lifecycle Pretty/TUI and --log-format json project the same lifecycle facts; fatal output redacts credentials and URL-embedded secrets while retaining context. Paths render verbatim on an attached terminal and redact when the event stream is redirected.\n",
" Durable ledger The Logs console and /api/logs/* read the local SQLite ledger.\n",
" Audit file sink --audit-log-path, --audit-log-format, and --audit-log-level control a separate rotating audit file sink.\n",
" TUI event navigation / filter, f follow, PgUp/PgDn page, Home/End jump.\n",
Expand Down
23 changes: 23 additions & 0 deletions mesh/crates/mesh-llm-tui/src/output/console_capture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ pub(in crate::output) use unix::ConsoleCapture;
#[cfg(not(unix))]
pub(in crate::output) use fallback::ConsoleCapture;

#[cfg(unix)]
pub(in crate::output) use unix::capture_installed;

#[cfg(not(unix))]
pub(in crate::output) use fallback::capture_installed;

#[cfg(unix)]
mod unix {
use mesh_llm_events::OutputEvent;
Expand Down Expand Up @@ -185,6 +191,16 @@ mod unix {
active_captures.load(Ordering::Acquire) > 0
}

/// Is a dashboard currently owning the screen with fd 1/2 captured?
///
/// The attachment probe in `logging_projection::privacy` reads fd 2,
/// which is the capture pipe while a capture is installed — capture
/// active means the operator is watching the dashboard on the
/// controlling terminal, i.e. the session is interactive.
pub(in crate::output) fn capture_installed() -> bool {
dashboard_capture_active(&ACTIVE_CAPTURES)
}

fn deliver(text: String, passthrough: &mut File) {
deliver_with(
text,
Expand Down Expand Up @@ -311,6 +327,13 @@ mod fallback {
Ok(())
}
}

/// No descriptor capture exists here, so the attachment probe in
/// `logging_projection::privacy` falls back to the raw stderr check
/// alone (which on these platforms stays the console).
pub(in crate::output) fn capture_installed() -> bool {
false
}
}

#[cfg(all(test, unix))]
Expand Down
11 changes: 11 additions & 0 deletions mesh/crates/mesh-llm-tui/src/output/formatting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1499,6 +1499,17 @@ impl OutputManager {
}
}

pub(super) fn event_stream_is_terminal(mode: LogFormat) -> bool {
use std::io::IsTerminal;

match mode {
LogFormat::Pretty => {
io::stderr().is_terminal() || super::console_capture::capture_installed()
}
LogFormat::Json => io::stdout().is_terminal(),
}
}

pub(super) fn write_rendered_output(mode: LogFormat, rendered: &str) -> io::Result<()> {
let mut stdout = io::stdout().lock();
let mut stderr = io::stderr().lock();
Expand Down
17 changes: 10 additions & 7 deletions mesh/crates/mesh-llm-tui/src/output/logging_projection.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
mod privacy;
pub(super) mod privacy;

use super::OutputEvent;
use super::formatting::OutputEventPresentation;
use super::{LogFormat, OutputEvent};
use mesh_llm_events::logging::{
envelope::CanonicalEnvelope,
events::{LifecycleEvent, TokenUsage},
Expand All @@ -10,16 +10,19 @@ use serde_json::{Map, Value, json};

use self::privacy::{
json_scalar, native_category, safe_native_params, sanitize_map, sanitize_text,
sanitize_text_for_mode,
};

pub(super) fn projected_message(event: &OutputEvent) -> String {
match event {
OutputEvent::CanonicalLog(envelope) => envelope.presentation_message(),
OutputEvent::LlamaNativeLog { message, .. } => sanitize_text(message),
OutputEvent::LlamaNativeLog { message, .. } => {
sanitize_text_for_mode(message, LogFormat::Json)
}
OutputEvent::Info { message, .. }
| OutputEvent::Warning { message, .. }
| OutputEvent::Error { message, .. }
| OutputEvent::Fatal { message, .. } => sanitize_text(message),
| OutputEvent::Fatal { message, .. } => sanitize_text_for_mode(message, LogFormat::Json),
_ => event.message(),
}
}
Expand All @@ -31,7 +34,7 @@ pub(super) fn projected_pretty_text(event: &OutputEvent) -> String {
message, params, ..
} => {
let mut rendered = sanitize_text(message);
for (key, value) in safe_native_params(params) {
for (key, value) in safe_native_params(params, LogFormat::Pretty) {
rendered.push_str("\n ↳ ");
rendered.push_str(&key);
rendered.push('=');
Expand Down Expand Up @@ -67,7 +70,7 @@ pub(super) fn projected_json_fields(event: &OutputEvent) -> Map<String, Value> {
OutputEvent::LlamaNativeLog {
category, params, ..
} => {
let mut fields = safe_native_params(params);
let mut fields = safe_native_params(params, LogFormat::Json);
fields.insert(
"native_category".to_string(),
Value::String(native_category(category).to_string()),
Expand All @@ -77,7 +80,7 @@ pub(super) fn projected_json_fields(event: &OutputEvent) -> Map<String, Value> {
OutputEvent::Info { .. }
| OutputEvent::Warning { .. }
| OutputEvent::Error { .. }
| OutputEvent::Fatal { .. } => sanitize_map(event.json_fields()),
| OutputEvent::Fatal { .. } => sanitize_map(event.json_fields(), LogFormat::Json),
_ => event.json_fields(),
}
}
Expand Down
Loading
Loading