diff options
Diffstat (limited to 'crates/daemon/src/aclient/history/mod.rs')
| -rw-r--r-- | crates/daemon/src/aclient/history/mod.rs | 42 |
1 files changed, 25 insertions, 17 deletions
diff --git a/crates/daemon/src/aclient/history/mod.rs b/crates/daemon/src/aclient/history/mod.rs index 09d24169..d61c95c5 100644 --- a/crates/daemon/src/aclient/history/mod.rs +++ b/crates/daemon/src/aclient/history/mod.rs @@ -1,4 +1,5 @@ use core::fmt::Formatter; +use regex::RegexSet; use rmp::decode::DecodeStringError; use rmp::decode::ValueReadError; use rmp::{Marker, decode::Bytes}; @@ -28,7 +29,7 @@ const HISTORY_AUTHOR_ENV: &str = "ATUIN_HISTORY_AUTHOR"; const HISTORY_INTENT_ENV: &str = "ATUIN_HISTORY_INTENT"; #[derive(Clone, Debug, Eq, PartialEq, Hash)] -pub struct HistoryId(pub(crate) String); +pub struct HistoryId(pub String); impl Display for HistoryId { fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { @@ -60,37 +61,37 @@ pub struct History { /// A client-generated ID, used to identify the entry when syncing. /// /// Stored as `client_id` in the database. - pub(crate) id: HistoryId, + pub id: HistoryId, /// When the command was run. - pub(crate) timestamp: OffsetDateTime, + pub timestamp: OffsetDateTime, /// How long the command took to run. - pub(crate) duration: i64, + pub duration: i64, /// The exit code of the command. - pub(crate) exit: i64, + pub exit: i64, /// The command that was run. - pub(crate) command: String, + pub command: String, /// The current working directory when the command was run. - pub(crate) cwd: String, + pub cwd: String, /// The session ID, associated with a terminal session. - pub(crate) session: String, + pub session: String, /// The hostname of the machine the command was run on. - pub(crate) hostname: String, + pub hostname: String, /// Who wrote this command (human user or automation/agent identity). - pub(crate) author: String, + pub author: String, /// Optional rationale for why the command was executed. - pub(crate) intent: Option<String>, + pub intent: Option<String>, /// Timestamp, which is set when the entry is deleted, allowing a soft delete. - pub(crate) deleted_at: Option<OffsetDateTime>, + pub deleted_at: Option<OffsetDateTime>, } #[derive(Debug, Clone, PartialEq, Eq, sqlx::FromRow)] @@ -397,7 +398,7 @@ impl History { /// .build() /// .into(); /// ``` - pub(crate) fn capture() -> builder::HistoryCapturedBuilder { + pub fn capture() -> builder::HistoryCapturedBuilder { builder::HistoryCaptured::builder() } @@ -473,14 +474,21 @@ impl History { self.exit == 0 || self.duration == -1 } - pub(crate) fn should_save(&self, settings: &Settings) -> bool { + pub fn should_save(&self, filter: SettingsFilter<'_>) -> bool { !(self.command.is_empty() - || settings.history_filter.is_match(&self.command) - || settings.cwd_filter.is_match(&self.cwd) - || (settings.secrets_filter && SECRET_PATTERNS_RE.is_match(&self.command))) + || filter.history.is_match(&self.command) + || filter.cwd.is_match(&self.cwd) + || (filter.secrets && SECRET_PATTERNS_RE.is_match(&self.command))) } } +#[derive(Debug, Copy, Clone)] +pub struct SettingsFilter<'a> { + pub history: &'a RegexSet, + pub cwd: &'a RegexSet, + pub secrets: bool, +} + #[cfg(test)] mod tests { use regex::RegexSet; |
