diff options
Diffstat (limited to '')
| -rw-r--r-- | crates/daemon/src/aclient/database/mod.rs | 7 | ||||
| -rw-r--r-- | crates/daemon/src/aclient/history/builder.rs | 2 | ||||
| -rw-r--r-- | crates/daemon/src/aclient/history/mod.rs | 42 | ||||
| -rw-r--r-- | crates/daemon/src/aclient/history/store.rs | 90 |
4 files changed, 75 insertions, 66 deletions
diff --git a/crates/daemon/src/aclient/database/mod.rs b/crates/daemon/src/aclient/database/mod.rs index 36049f80..5e25a0e9 100644 --- a/crates/daemon/src/aclient/database/mod.rs +++ b/crates/daemon/src/aclient/database/mod.rs @@ -51,10 +51,9 @@ pub(crate) struct OptFilters { pub(crate) include_duplicates: bool, } -pub(crate) async fn current_context() -> eyre::Result<Context> { - let session = env::var("ATUIN_SESSION").map_err(|_| { - eyre::eyre!("Failed to find $ATUIN_SESSION in the environment. Check that you have correctly set up your shell.") - })?; +pub(crate) async fn current_context(session: String) -> eyre::Result<Context> { + // TODO(@bpeetz): More of this needs to be moved to the client <2026-07-20> + let hostname = get_host_user(); let cwd = utils::get_current_dir(); let host_id = Settings::host_id().await?; diff --git a/crates/daemon/src/aclient/history/builder.rs b/crates/daemon/src/aclient/history/builder.rs index daa4ef49..ef52637b 100644 --- a/crates/daemon/src/aclient/history/builder.rs +++ b/crates/daemon/src/aclient/history/builder.rs @@ -49,7 +49,7 @@ impl From<HistoryImported> for History { /// so it doesn't have any fields which are known only after /// the command is finished, such as `exit` or `duration`. #[derive(Debug, Clone, TypedBuilder)] -pub(crate) struct HistoryCaptured { +pub struct HistoryCaptured { timestamp: time::OffsetDateTime, #[builder(setter(into))] command: String, 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; diff --git a/crates/daemon/src/aclient/history/store.rs b/crates/daemon/src/aclient/history/store.rs index db692590..a749a1a8 100644 --- a/crates/daemon/src/aclient/history/store.rs +++ b/crates/daemon/src/aclient/history/store.rs @@ -313,50 +313,52 @@ impl HistoryStore { } pub(crate) async fn init_store(&self, db: &ClientSqlite) -> Result<()> { - let pb = ProgressBar::new_spinner(); - pb.set_style( - ProgressStyle::with_template("{spinner:.blue} {msg}") - .unwrap() - .with_key("eta", |state: &ProgressState, w: &mut dyn Write| { - write!(w, "{:.1}s", state.eta().as_secs_f64()).unwrap(); - }) - .progress_chars("#>-"), - ); - pb.enable_steady_tick(Duration::from_millis(500)); + todo!(); - pb.set_message("Fetching history from old database"); - - let context = current_context().await?; - let history = db.list(&[], &context, None, false, true).await?; - - pb.set_message("Fetching history already in store"); - let store_ids = self.history_ids().await?; - - pb.set_message("Converting old history to new store"); - let mut records = Vec::new(); - - for i in history { - debug!("loaded {}", i.id); - - if store_ids.contains(&i.id) { - debug!("skipping {} - already exists", i.id); - continue; - } - - if i.deleted_at.is_some() { - records.push(HistoryRecord::Delete(i.id)); - } else { - records.push(HistoryRecord::Create(i)); - } - } - - pb.set_message("Writing to db"); - - if !records.is_empty() { - self.push_batch(records.into_iter()).await?; - } - - pb.finish_with_message("Import complete"); + // let pb = ProgressBar::new_spinner(); + // pb.set_style( + // ProgressStyle::with_template("{spinner:.blue} {msg}") + // .unwrap() + // .with_key("eta", |state: &ProgressState, w: &mut dyn Write| { + // write!(w, "{:.1}s", state.eta().as_secs_f64()).unwrap(); + // }) + // .progress_chars("#>-"), + // ); + // pb.enable_steady_tick(Duration::from_millis(500)); + // + // pb.set_message("Fetching history from old database"); + // + // let context = current_context().await?; + // let history = db.list(&[], &context, None, false, true).await?; + // + // pb.set_message("Fetching history already in store"); + // let store_ids = self.history_ids().await?; + // + // pb.set_message("Converting old history to new store"); + // let mut records = Vec::new(); + // + // for i in history { + // debug!("loaded {}", i.id); + // + // if store_ids.contains(&i.id) { + // debug!("skipping {} - already exists", i.id); + // continue; + // } + // + // if i.deleted_at.is_some() { + // records.push(HistoryRecord::Delete(i.id)); + // } else { + // records.push(HistoryRecord::Create(i)); + // } + // } + // + // pb.set_message("Writing to db"); + // + // if !records.is_empty() { + // self.push_batch(records.into_iter()).await?; + // } + // + // pb.finish_with_message("Import complete"); Ok(()) } @@ -364,8 +366,8 @@ impl HistoryStore { #[cfg(test)] mod tests { - use turtle_common::record::DecryptedData; use time::macros::datetime; + use turtle_common::record::DecryptedData; use crate::aclient::history::{HISTORY_VERSION, store::HistoryRecord}; |
