aboutsummaryrefslogtreecommitdiffstats
path: root/crates/daemon/src/aclient/history
diff options
context:
space:
mode:
authorBenedikt Peetz <benedikt.peetz@b-peetz.de>2026-07-20 17:54:34 +0200
committerBenedikt Peetz <benedikt.peetz@b-peetz.de>2026-07-20 17:54:34 +0200
commit6bd2b80be51a8623640fbd77afa1da09289e40cc (patch)
tree8fa76fc78e27a4f3d6f57af07805a83e9877f0ad /crates/daemon/src/aclient/history
parentchore: Commit (diff)
downloadatuin-6bd2b80be51a8623640fbd77afa1da09289e40cc.zip
chore: All compiles
Diffstat (limited to 'crates/daemon/src/aclient/history')
-rw-r--r--crates/daemon/src/aclient/history/builder.rs2
-rw-r--r--crates/daemon/src/aclient/history/mod.rs42
-rw-r--r--crates/daemon/src/aclient/history/store.rs90
3 files changed, 72 insertions, 62 deletions
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};