aboutsummaryrefslogtreecommitdiffstats
path: root/crates/daemon/src/aclient
diff options
context:
space:
mode:
authorBenedikt Peetz <benedikt.peetz@b-peetz.de>2026-07-24 17:56:36 +0200
committerBenedikt Peetz <benedikt.peetz@b-peetz.de>2026-07-24 17:56:36 +0200
commit9cdc575666faad4c162f4b4cf519bfdd1fd528dc (patch)
tree9287963ad11e237ca74edbd54161c03f3309927b /crates/daemon/src/aclient
parentchore: Last big refactoring (diff)
downloadatuin-9cdc575666faad4c162f4b4cf519bfdd1fd528dc.zip
feat: Finalize design for fish-shell integration
Diffstat (limited to '')
-rw-r--r--crates/daemon/src/aclient/database/mod.rs14
-rw-r--r--crates/daemon/src/aclient/history/mod.rs31
-rw-r--r--crates/daemon/src/aclient/history/store.rs8
-rw-r--r--crates/daemon/src/aclient/settings/mod.rs11
4 files changed, 36 insertions, 28 deletions
diff --git a/crates/daemon/src/aclient/database/mod.rs b/crates/daemon/src/aclient/database/mod.rs
index b112b076..f24eb777 100644
--- a/crates/daemon/src/aclient/database/mod.rs
+++ b/crates/daemon/src/aclient/database/mod.rs
@@ -1,4 +1,4 @@
-use std::{path::Path, str::FromStr};
+use std::{path::Path, str::FromStr, time::Duration};
use fs_err::{self as fs};
use sql_builder::{SqlBuilder, SqlName};
@@ -8,7 +8,7 @@ use sqlx::{
};
use time::OffsetDateTime;
use tracing::debug;
-use turtle::history::{History, HistoryId};
+use turtle_api::history::{History, HistoryId};
use turtle_common::utils;
use crate::aclient::utils::setup_db;
@@ -59,9 +59,9 @@ impl ClientSqlite {
"insert or ignore into history(id, timestamp, duration, exit, command, cwd, session, hostname, author, intent, deleted_at)
values(?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8, ?9, ?10, ?11)",
)
- .bind(h.id.0.as_str())
+ .bind(h.id.to_string().as_str())
.bind(h.timestamp.unix_timestamp_nanos() as i64)
- .bind(h.duration)
+ .bind(h.duration.as_nanos() as i64)
.bind(h.exit)
.bind(h.command.as_str())
.bind(h.cwd.as_str())
@@ -81,7 +81,7 @@ impl ClientSqlite {
id: HistoryId,
) -> Result<()> {
sqlx::query("delete from history where id = ?1")
- .bind(id.0.as_str())
+ .bind(id.to_string().as_str())
.execute(&mut **tx)
.await?;
@@ -107,7 +107,9 @@ impl ClientSqlite {
))
.unwrap(),
)
- .duration(row.get("duration"))
+ .duration(Duration::from_nanos(
+ u64::try_from(row.get::<i64, _>("duration")).expect("to be small enough"),
+ ))
.exit(row.get("exit"))
.command(row.get("command"))
.cwd(row.get("cwd"))
diff --git a/crates/daemon/src/aclient/history/mod.rs b/crates/daemon/src/aclient/history/mod.rs
index ae7654a6..35abc89d 100644
--- a/crates/daemon/src/aclient/history/mod.rs
+++ b/crates/daemon/src/aclient/history/mod.rs
@@ -1,7 +1,9 @@
+use std::time::Duration;
+
use rmp::decode::DecodeStringError;
use rmp::decode::ValueReadError;
use rmp::{Marker, decode::Bytes};
-use turtle::history::History;
+use turtle_api::history::History;
use turtle_common::record::DecryptedData;
@@ -40,9 +42,12 @@ impl HistoryExt for History {
let include_intent = self.intent.is_some();
encode::write_array_len(&mut output, 10 + u32::from(include_intent))?;
- encode::write_str(&mut output, &self.id.0)?;
+ encode::write_str(&mut output, &self.id.to_string())?;
encode::write_u64(&mut output, self.timestamp.unix_timestamp_nanos() as u64)?;
- encode::write_sint(&mut output, self.duration)?;
+ encode::write_sint(
+ &mut output,
+ i64::try_from(self.duration.as_nanos()).expect("should be small enough"),
+ )?;
encode::write_sint(&mut output, self.exit)?;
encode::write_str(&mut output, &self.command)?;
encode::write_str(&mut output, &self.cwd)?;
@@ -107,7 +112,11 @@ impl HistoryExt for History {
let mut bytes = Bytes::new(bytes);
let timestamp = decode::read_u64(&mut bytes).map_err(error_report)?;
- let duration = decode::read_int(&mut bytes).map_err(error_report)?;
+ let duration = decode::read_int(&mut bytes)
+ .map(|int: i64| {
+ Duration::from_nanos(u64::try_from(int).expect("should be small enough"))
+ })
+ .map_err(error_report)?;
let exit = decode::read_int(&mut bytes).map_err(error_report)?;
let bytes = bytes.remaining_slice();
@@ -171,7 +180,9 @@ impl HistoryExt for History {
let mut bytes = Bytes::new(bytes);
let timestamp = decode::read_u64(&mut bytes).map_err(error_report)?;
- let duration = decode::read_int(&mut bytes).map_err(error_report)?;
+ let duration = decode::read_int(&mut bytes)
+ .map(|int: i64| Duration::from_nanos(u64::try_from(int).expect("to be small enough")))
+ .map_err(error_report)?;
let exit = decode::read_int(&mut bytes).map_err(error_report)?;
let bytes = bytes.remaining_slice();
@@ -228,6 +239,8 @@ impl HistoryExt for History {
#[cfg(test)]
mod tests {
+ use std::time::Duration;
+
use time::macros::datetime;
use crate::aclient::history::{HISTORY_VERSION, HistoryExt};
@@ -239,7 +252,7 @@ mod tests {
let history = History {
id: "66d16cbee7cd47538e5c5b8b44e9006e".to_owned().into(),
timestamp: datetime!(2023-05-28 18:35:40.633872 +00:00),
- duration: 49_206_000,
+ duration: Duration::from_nanos(49_206_000),
exit: 0,
command: "git status".to_owned(),
cwd: "/Users/conrad.ludgate/Documents/code/atuin".to_owned(),
@@ -267,7 +280,7 @@ mod tests {
let history = History {
id: "66d16cbee7cd47538e5c5b8b44e9006e".to_owned().into(),
timestamp: datetime!(2023-05-28 18:35:40.633872 +00:00),
- duration: 49_206_000,
+ duration: Duration::from_nanos(49_206_000),
exit: 0,
command: "git status".to_owned(),
cwd: "/Users/conrad.ludgate/Documents/code/atuin".to_owned(),
@@ -291,7 +304,7 @@ mod tests {
let history = History {
id: "66d16cbee7cd47538e5c5b8b44e9006e".to_owned().into(),
timestamp: datetime!(2023-05-28 18:35:40.633872 +00:00),
- duration: 49_206_000,
+ duration: Duration::from_nanos(49_206_000),
exit: 0,
command: "git status".to_owned(),
cwd: "/Users/conrad.ludgate/Documents/code/atuin".to_owned(),
@@ -333,7 +346,7 @@ mod tests {
let current = History {
id: "66d16cbee7cd47538e5c5b8b44e9006e".to_owned().into(),
timestamp: datetime!(2023-05-28 18:35:40.633872 +00:00),
- duration: 49_206_000,
+ duration: Duration::from_nanos(49_206_000),
exit: 0,
command: "git status".to_owned(),
cwd: "/Users/conrad.ludgate/Documents/code/atuin".to_owned(),
diff --git a/crates/daemon/src/aclient/history/store.rs b/crates/daemon/src/aclient/history/store.rs
index 952f2070..a6d6a627 100644
--- a/crates/daemon/src/aclient/history/store.rs
+++ b/crates/daemon/src/aclient/history/store.rs
@@ -1,6 +1,6 @@
use eyre::{Result, bail, eyre};
use rmp::decode::Bytes;
-use turtle::history::{History, HistoryId};
+use turtle_api::history::{History, HistoryId};
use crate::aclient::{
database::ClientSqlite,
@@ -56,7 +56,7 @@ impl HistoryRecord {
Self::Delete(id) => {
// 1 -> a history delete
encode::write_u8(&mut output, 1)?;
- encode::write_str(&mut output, id.0.as_str())?;
+ encode::write_str(&mut output, id.to_string().as_str())?;
}
}
@@ -221,6 +221,8 @@ impl HistoryStore {
#[cfg(test)]
mod tests {
+ use std::time::Duration;
+
use time::macros::datetime;
use turtle_common::record::DecryptedData;
@@ -244,7 +246,7 @@ mod tests {
let history = History {
id: "018cd4fe81757cd2aee65cd7861f9c81".to_owned().into(),
timestamp: datetime!(2024-01-04 00:00:00.000000 +00:00),
- duration: 100,
+ duration: Duration::from_nanos(100),
exit: 0,
command: "ls".to_owned(),
cwd: "/Users/ellie/src/github.com/atuinsh/atuin".to_owned(),
diff --git a/crates/daemon/src/aclient/settings/mod.rs b/crates/daemon/src/aclient/settings/mod.rs
index ef3f1dd0..379ee563 100644
--- a/crates/daemon/src/aclient/settings/mod.rs
+++ b/crates/daemon/src/aclient/settings/mod.rs
@@ -252,9 +252,8 @@ impl Settings {
let kv_path = data_dir.join("kv.db");
let scripts_path = data_dir.join("scripts.db");
let ai_sessions_path = data_dir.join("ai_sessions.db");
- let socket_path = utils::runtime_dir().join("atuin.sock");
+ let socket_path = utils::daemon_socket_path();
let pidfile_path = data_dir.join("atuin-daemon.pid");
- let logs_dir = utils::logs_dir();
let key_path = data_dir.join("key");
let meta_path = data_dir.join("meta.db");
@@ -320,7 +319,6 @@ impl Settings {
.set_default("daemon.systemd_socket", false)?
.set_default("daemon.tcp_port", 8889)?
.set_default("logs.enabled", true)?
- .set_default("logs.dir", logs_dir.to_str())?
.set_default("logs.level", "info")?
.set_default("logs.search.file", "search.log")?
.set_default("logs.daemon.file", "daemon.log")?
@@ -583,13 +581,6 @@ mod tests {
);
assert_eq!(meta_db_path, custom_dir.join("meta.db").to_str().unwrap());
assert_eq!(
- daemon_socket_path,
- turtle_common::utils::runtime_dir()
- .join("atuin.sock")
- .to_str()
- .unwrap()
- );
- assert_eq!(
daemon_pidfile_path,
custom_dir.join("atuin-daemon.pid").to_str().unwrap()
);