From 97f207b771b94c5285faae4810d6eeda1b78926b Mon Sep 17 00:00:00 2001 From: Benedikt Peetz Date: Thu, 11 Jun 2026 16:10:29 +0200 Subject: chore(server): Simplify the database support --- crates/turtle/src/atuin_client/settings.rs | 151 ++--------------------------- 1 file changed, 6 insertions(+), 145 deletions(-) (limited to 'crates/turtle/src/atuin_client/settings.rs') diff --git a/crates/turtle/src/atuin_client/settings.rs b/crates/turtle/src/atuin_client/settings.rs index 046aad1a..5ee7cb77 100644 --- a/crates/turtle/src/atuin_client/settings.rs +++ b/crates/turtle/src/atuin_client/settings.rs @@ -15,8 +15,6 @@ use serde::{Deserialize, Serialize}; use serde_with::DeserializeFromStr; use time::{OffsetDateTime, UtcOffset, format_description::FormatItem, macros::format_description}; -pub(crate) const HISTORY_PAGE_SIZE: i64 = 100; - static DATA_DIR: OnceLock = OnceLock::new(); static META_CONFIG: OnceLock<(String, f64)> = OnceLock::new(); static META_STORE: OnceCell = OnceCell::const_new(); @@ -24,9 +22,6 @@ static META_STORE: OnceCell = OnceCell::co pub(crate) mod meta; pub(crate) mod watcher; -/// Default sync address for Atuin's hosted service -pub(crate) const DEFAULT_SYNC_ADDRESS: &str = "https://api.atuin.sh"; - #[derive(Clone, Debug, Deserialize, Copy, ValueEnum, PartialEq, Serialize)] pub(crate) enum SearchMode { #[serde(rename = "prefix")] @@ -335,23 +330,6 @@ impl Default for Stats { } } -/// Sync protocol type for authentication. -/// -/// This setting is primarily for development/testing. When not explicitly set, -/// the protocol is inferred from the sync_address: -/// - Default sync address (api.atuin.sh) → Hub protocol -/// - Custom sync address → Legacy protocol -/// -/// Set explicitly to "hub" to use Hub authentication with a custom sync_address -/// (useful for local development against a Hub instance). -#[derive(Clone, Copy, Debug, Deserialize, PartialEq, Eq, Serialize, Default)] -#[serde(rename_all = "lowercase")] -pub(crate) enum SyncProtocol { - /// Use legacy CLI authentication (Token from CLI register/login) - #[default] - Legacy, -} - /// Resolved authentication state for sync operations. /// /// Determined at runtime by examining which tokens are available and what @@ -376,13 +354,14 @@ impl SyncAuth { pub(crate) fn into_auth_token(self) -> Result { use crate::atuin_client::api_client::AuthToken; match self { - SyncAuth::Legacy { token } => Ok(AuthToken::Token(token)), + SyncAuth::Legacy { token } => Ok(AuthToken(token)), SyncAuth::NotLoggedIn { reason } => Err(eyre!(reason)), } } } #[derive(Clone, Debug, Deserialize, Default, Serialize)] +#[expect(clippy::struct_excessive_bools)] pub(crate) struct Keys { pub(crate) scroll_exits: bool, pub(crate) exit_past_line_start: bool, @@ -527,18 +506,6 @@ pub(crate) struct Search { pub(crate) frecency_score_multiplier: f64, } -#[derive(Clone, Debug, Deserialize, Serialize)] -pub(crate) struct Tmux { - /// Enable using atuin with tmux popup (tmux >= 3.2) - pub(crate) enabled: bool, - - /// Width of the tmux popup (percentage) - pub(crate) width: String, - - /// Height of the tmux popup (percentage) - pub(crate) height: String, -} - /// Log level for file logging. Maps to tracing's LevelFilter. #[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Deserialize, Serialize)] #[serde(rename_all = "lowercase")] @@ -605,63 +572,6 @@ pub(crate) struct Logs { /// Daemon log settings #[serde(default)] pub(crate) daemon: LogConfig, - - /// AI log settings - #[serde(default)] - pub(crate) ai: LogConfig, -} - -#[derive(Default, Clone, Debug, Deserialize, Serialize)] -pub(crate) struct Ai { - /// Whether or not the AI features are enabled. - pub(crate) enabled: Option, - - /// The address of the Atuin AI endpoint. Used for AI features like command generation. - /// Only necessary for custom AI endpoints. - pub(crate) endpoint: Option, - - /// The API token for the Atuin AI endpoint. Used for AI features like command generation. - /// Only necessary for custom AI endpoints. - pub(crate) api_token: Option, - - /// Path to the AI sessions database. - pub(crate) db_path: String, - - /// The maximum time in minutes that an AI session can be automatically resumed. - pub(crate) session_continue_minutes: i64, - - /// Deprecated: use opening.send_cwd instead. Kept for backwards compatibility. - #[serde(default)] - pub(crate) send_cwd: Option, - - /// Configuration for what context is sent in the opening AI request. - #[serde(default)] - pub(crate) opening: AiOpening, - - /// Tool capability flags. - #[serde(default)] - pub(crate) capabilities: AiCapabilities, -} - -#[derive(Default, Clone, Debug, Deserialize, Serialize)] -pub(crate) struct AiCapabilities { - /// Whether the AI can request to search Atuin history. `None` = unset (defaults to enabled, and the ai will ask for permission). - pub(crate) enable_history_search: Option, - /// Whether the AI can request to view the stored output, if any, for Atuin history entries. `None` = unset (defaults to enabled, and the ai will ask for permission). - pub(crate) enable_history_output: Option, - /// Whether the AI can request to read and write files. `None` = unset (defaults to enabled, and the ai will ask for permission). - pub(crate) enable_file_tools: Option, - /// Whether the AI can request to execute bash commands. `None` = unset (defaults to enabled, and the ai will ask for permission). - pub(crate) enable_command_execution: Option, -} - -#[derive(Default, Clone, Debug, Deserialize, Serialize)] -pub(crate) struct AiOpening { - /// Whether or not to send the current working directory to the AI endpoint. - pub(crate) send_cwd: Option, - - /// Whether or not to send the last command as context in the opening AI request. - pub(crate) send_last_command: Option, } impl Default for Preview { @@ -711,10 +621,6 @@ impl Default for Logs { file: "daemon.log".to_string(), ..Default::default() }, - ai: LogConfig { - file: "ai.log".to_string(), - ..Default::default() - }, } } } @@ -740,12 +646,6 @@ impl Logs { self.daemon.enabled.unwrap_or(self.enabled) } - /// Returns whether AI logging is enabled. - /// Uses AI-specific setting if set, otherwise falls back to global. - pub(crate) fn ai_enabled(&self) -> bool { - self.ai.enabled.unwrap_or(self.enabled) - } - /// Returns the log level for search logging. /// Uses search-specific setting if set, otherwise falls back to global. pub(crate) fn search_level(&self) -> LogLevel { @@ -758,12 +658,6 @@ impl Logs { self.daemon.level.unwrap_or(self.level) } - /// Returns the log level for AI logging. - /// Uses AI-specific setting if set, otherwise falls back to global. - pub(crate) fn ai_level(&self) -> LogLevel { - self.ai.level.unwrap_or(self.level) - } - /// Returns the retention days for search logging. /// Uses search-specific setting if set, otherwise falls back to global. pub(crate) fn search_retention(&self) -> u64 { @@ -776,12 +670,6 @@ impl Logs { self.daemon.retention.unwrap_or(self.retention) } - /// Returns the retention days for AI logging. - /// Uses AI-specific setting if set, otherwise falls back to global. - pub(crate) fn ai_retention(&self) -> u64 { - self.ai.retention.unwrap_or(self.retention) - } - /// Returns the full path for the search log file. pub(crate) fn search_path(&self) -> PathBuf { let path = PathBuf::from(&self.search.file); @@ -793,12 +681,6 @@ impl Logs { let path = PathBuf::from(&self.daemon.file); PathBuf::from(&self.dir).join(path) } - - /// Returns the full path for the AI log file. - pub(crate) fn ai_path(&self) -> PathBuf { - let path = PathBuf::from(&self.ai.file); - PathBuf::from(&self.dir).join(path) - } } impl Default for Search { @@ -820,16 +702,6 @@ impl Default for Search { } } -impl Default for Tmux { - fn default() -> Self { - Self { - enabled: false, - width: "80%".to_string(), - height: "60%".to_string(), - } - } -} - // The preview height strategy also takes max_preview_height into account. #[derive(Clone, Debug, Deserialize, Copy, PartialEq, Eq, ValueEnum, Serialize)] pub(crate) enum PreviewStrategy { @@ -1031,6 +903,7 @@ impl Default for Ui { } #[derive(Clone, Debug, Deserialize, Serialize)] +#[expect(clippy::struct_excessive_bools)] pub(crate) struct Settings { pub(crate) data_dir: Option, pub(crate) dialect: Dialect, @@ -1041,9 +914,6 @@ pub(crate) struct Settings { /// The sync address for atuin. pub(crate) sync_address: String, - #[serde(default)] - pub(crate) sync_protocol: SyncProtocol, - pub(crate) sync_frequency: String, pub(crate) db_path: String, pub(crate) record_store_path: String, @@ -1116,9 +986,6 @@ pub(crate) struct Settings { #[serde(default)] pub(crate) ui: Ui, - #[serde(default)] - pub(crate) tmux: Tmux, - #[serde(default)] pub(crate) logs: Logs, @@ -1170,14 +1037,6 @@ impl Settings { Self::meta_store().await?.save_sync_time().await } - pub(crate) async fn last_version_check() -> Result { - Self::meta_store().await?.last_version_check().await - } - - pub(crate) async fn save_version_check_time() -> Result<()> { - Self::meta_store().await?.save_version_check_time().await - } - pub(crate) async fn should_sync(&self) -> Result { if !self.auto_sync || !Self::meta_store().await?.logged_in().await? { return Ok(false); @@ -1238,7 +1097,9 @@ impl Settings { /// `AuthToken`. Callers that need to distinguish between auth states /// (e.g. to show different UI) should call `resolve_sync_auth` directly. #[cfg(feature = "sync")] - pub(crate) async fn sync_auth_token(&self) -> Result { + pub(crate) async fn sync_auth_token( + &self, + ) -> Result { self.resolve_sync_auth().await.into_auth_token() } -- cgit v1.3.1