zeph_commands/traits/debug.rs
1// SPDX-FileCopyrightText: 2026 Andrei G <bug-ops>
2// SPDX-License-Identifier: MIT OR Apache-2.0
3
4//! [`DebugAccess`] trait for command handlers that read or mutate debug/diagnostics state.
5//!
6//! This trait exposes the subset of debug state used by `/log`, `/debug-dump`, and
7//! `/dump-format` handlers. All methods return or accept primitives and `String`s so that
8//! `zeph-commands` does not depend on `zeph-core`'s `DebugState`, `DebugDumper`, or
9//! `DumpFormat` types.
10
11use std::future::Future;
12use std::pin::Pin;
13
14use crate::CommandError;
15
16/// Access to debug/diagnostics state for command handlers.
17///
18/// Implemented by `zeph-core` on a struct that wraps `DebugState`. Methods intentionally return
19/// strings rather than internal types, keeping `zeph-commands` free of `zeph-core` dependencies.
20pub trait DebugAccess: Send {
21 /// Return a formatted human-readable status of the log configuration.
22 ///
23 /// Used by `/log` to display the current log file path, level, rotation, and max files.
24 fn log_status(&self) -> String;
25
26 /// Optionally read and return recent log file tail entries (last `n` lines).
27 ///
28 /// Returns `None` when log file output is disabled. The implementation performs blocking
29 /// I/O via `spawn_blocking`.
30 fn read_log_tail<'a>(
31 &'a self,
32 n: usize,
33 ) -> Pin<Box<dyn Future<Output = Option<String>> + Send + 'a>>;
34
35 /// Scrub credentials from a string before displaying it.
36 ///
37 /// Delegates to `zeph-core`'s `redact::scrub_content`.
38 fn scrub(&self, text: &str) -> String;
39
40 /// Return a description of the current debug dump state.
41 ///
42 /// Returns `Some(path_display)` if debug dump is active, `None` otherwise.
43 fn dump_status(&self) -> Option<String>;
44
45 /// Return the current dump format name (e.g. `"json"`, `"raw"`, `"trace"`).
46 fn dump_format_name(&self) -> String;
47
48 /// Enable debug dump output to the given directory path.
49 ///
50 /// Returns `Ok(path_display)` on success.
51 ///
52 /// # Errors
53 ///
54 /// Returns `Err(CommandError)` when the directory cannot be created or is inaccessible.
55 fn enable_dump(&mut self, dir: &str) -> Result<String, CommandError>;
56
57 /// Switch the dump format to one of `"json"`, `"raw"`, or `"trace"`.
58 ///
59 /// # Errors
60 ///
61 /// Returns `Err(CommandError)` when the format name is unrecognized.
62 fn set_dump_format(&mut self, format_name: &str) -> Result<(), CommandError>;
63}