aboutsummaryrefslogtreecommitdiffstats
path: root/crates/atuin-daemon/src/client.rs
diff options
context:
space:
mode:
authorBenedikt Peetz <benedikt.peetz@b-peetz.de>2026-06-11 00:54:30 +0200
committerBenedikt Peetz <benedikt.peetz@b-peetz.de>2026-06-11 00:54:30 +0200
commit5c39e7cf284a1f6e9a1657f2deb44e359fc47eb8 (patch)
treec64baa8d5866c8e339eaf660dd3f94f30a3f7d8a /crates/atuin-daemon/src/client.rs
parentchore: Somewhat simplify sync code (diff)
downloadatuin-5c39e7cf284a1f6e9a1657f2deb44e359fc47eb8.zip
chore: Move everything into one big crate
That helps remove duplicated code and rustc/cargo will now also show dead code correctly.
Diffstat (limited to '')
-rw-r--r--crates/turtle/src/atuin_daemon/client.rs (renamed from crates/atuin-daemon/src/client.rs)126
1 files changed, 13 insertions, 113 deletions
diff --git a/crates/atuin-daemon/src/client.rs b/crates/turtle/src/atuin_daemon/client.rs
index c18e0e46..45ef19e9 100644
--- a/crates/atuin-daemon/src/client.rs
+++ b/crates/turtle/src/atuin_daemon/client.rs
@@ -1,8 +1,6 @@
-use atuin_client::database::Context;
-use atuin_client::settings::{FilterMode, Settings};
+use crate::atuin_client::database::Context;
+use crate::atuin_client::settings::{FilterMode, Settings};
use eyre::{Context as EyreContext, Result};
-#[cfg(windows)]
-use tokio::net::TcpStream;
use tonic::Code;
use tonic::transport::{Channel, Endpoint, Uri};
use tower::service_fn;
@@ -12,25 +10,25 @@ use hyper_util::rt::TokioIo;
#[cfg(unix)]
use tokio::net::UnixStream;
-use atuin_client::history::History;
+use crate::atuin_client::history::History;
use tracing::{Level, instrument, span};
-use crate::control::HistoryRebuiltEvent;
-use crate::control::{
+use crate::atuin_daemon::control::HistoryRebuiltEvent;
+use crate::atuin_daemon::control::{
ForceSyncEvent, HistoryDeletedEvent, HistoryPrunedEvent, SendEventRequest,
SettingsReloadedEvent, ShutdownEvent, control_client::ControlClient as ControlServiceClient,
};
-use crate::events::DaemonEvent;
-use crate::history::{
+use crate::atuin_daemon::events::DaemonEvent;
+use crate::atuin_daemon::history::{
EndHistoryReply, EndHistoryRequest, ShutdownRequest, StartHistoryReply, StartHistoryRequest,
StatusReply, StatusRequest, TailHistoryReply, TailHistoryRequest,
history_client::HistoryClient as HistoryServiceClient,
};
-use crate::search::{
+use crate::atuin_daemon::search::{
FilterMode as RpcFilterMode, SearchContext as RpcSearchContext, SearchRequest, SearchResponse,
search_client::SearchClient as SearchServiceClient,
};
-use crate::semantic::{
+use crate::atuin_daemon::semantic::{
CommandCapture, CommandOutputReply, CommandOutputRequest, OutputRange, RecordCommandsReply,
semantic_client::SemanticClient as SemanticServiceClient,
};
@@ -94,28 +92,6 @@ impl HistoryClient {
Ok(HistoryClient { client })
}
- #[cfg(not(unix))]
- pub async fn new(port: u64) -> Result<Self> {
- let channel = Endpoint::try_from("http://atuin_local_daemon:0")?
- .connect_with_connector(service_fn(move |_: Uri| {
- let url = format!("127.0.0.1:{port}");
-
- async move {
- Ok::<_, std::io::Error>(TokioIo::new(TcpStream::connect(url.clone()).await?))
- }
- }))
- .await
- .wrap_err_with(|| {
- format!(
- "failed to connect to local atuin daemon at 127.0.0.1:{port}. Is it running?"
- )
- })?;
-
- let client = HistoryServiceClient::new(channel);
-
- Ok(HistoryClient { client })
- }
-
pub async fn start_history(&mut self, h: History) -> Result<StartHistoryReply> {
let req = StartHistoryRequest {
command: h.command,
@@ -188,28 +164,6 @@ impl SearchClient {
Ok(SearchClient { client })
}
- #[cfg(not(unix))]
- pub async fn new(port: u64) -> Result<Self> {
- let channel = Endpoint::try_from("http://atuin_local_daemon:0")?
- .connect_with_connector(service_fn(move |_: Uri| {
- let url = format!("127.0.0.1:{port}");
-
- async move {
- Ok::<_, std::io::Error>(TokioIo::new(TcpStream::connect(url.clone()).await?))
- }
- }))
- .await
- .wrap_err_with(|| {
- format!(
- "failed to connect to local atuin daemon at 127.0.0.1:{port}. Is it running?"
- )
- })?;
-
- let client = SearchServiceClient::new(channel);
-
- Ok(SearchClient { client })
- }
-
#[instrument(skip_all, level = Level::TRACE, name = "daemon_client_search", fields(query = %query, query_id = query_id))]
pub async fn search(
&mut self,
@@ -289,38 +243,11 @@ impl SemanticClient {
Ok(SemanticClient { client })
}
- #[cfg(not(unix))]
- pub async fn new(port: u64) -> Result<Self> {
- let channel = Endpoint::try_from("http://atuin_local_daemon:0")?
- .connect_with_connector(service_fn(move |_: Uri| {
- let url = format!("127.0.0.1:{port}");
-
- async move {
- Ok::<_, std::io::Error>(TokioIo::new(TcpStream::connect(url.clone()).await?))
- }
- }))
- .await
- .wrap_err_with(|| {
- format!(
- "failed to connect to local atuin daemon at 127.0.0.1:{port}. Is it running?"
- )
- })?;
-
- let client = SemanticServiceClient::new(channel);
-
- Ok(SemanticClient { client })
- }
-
#[cfg(unix)]
pub async fn from_settings(settings: &Settings) -> Result<Self> {
Self::new(settings.daemon.socket_path.clone()).await
}
- #[cfg(not(unix))]
- pub async fn from_settings(settings: &Settings) -> Result<Self> {
- Self::new(settings.daemon.tcp_port).await
- }
-
pub async fn record_commands(
&mut self,
captures: Vec<CommandCapture>,
@@ -383,41 +310,12 @@ impl ControlClient {
Ok(ControlClient { client })
}
- /// Connect to the daemon's control service.
- #[cfg(not(unix))]
- pub async fn new(port: u64) -> Result<Self> {
- let channel = Endpoint::try_from("http://atuin_local_daemon:0")?
- .connect_with_connector(service_fn(move |_: Uri| {
- let url = format!("127.0.0.1:{port}");
-
- async move {
- Ok::<_, std::io::Error>(TokioIo::new(TcpStream::connect(url.clone()).await?))
- }
- }))
- .await
- .wrap_err_with(|| {
- format!(
- "failed to connect to local atuin daemon at 127.0.0.1:{port}. Is it running?"
- )
- })?;
-
- let client = ControlServiceClient::new(channel);
-
- Ok(ControlClient { client })
- }
-
/// Connect using settings.
#[cfg(unix)]
pub async fn from_settings(settings: &Settings) -> Result<Self> {
Self::new(settings.daemon.socket_path.clone()).await
}
- /// Connect using settings.
- #[cfg(not(unix))]
- pub async fn from_settings(settings: &Settings) -> Result<Self> {
- Self::new(settings.daemon.tcp_port).await
- }
-
/// Send an event to the daemon.
pub async fn send_event(&mut self, event: DaemonEvent) -> Result<()> {
let proto_event = daemon_event_to_proto(event);
@@ -430,8 +328,10 @@ impl ControlClient {
}
/// Convert a daemon event to its proto representation.
-fn daemon_event_to_proto(event: DaemonEvent) -> crate::control::send_event_request::Event {
- use crate::control::send_event_request::Event;
+fn daemon_event_to_proto(
+ event: DaemonEvent,
+) -> crate::atuin_daemon::control::send_event_request::Event {
+ use crate::atuin_daemon::control::send_event_request::Event;
match event {
DaemonEvent::HistoryPruned => Event::HistoryPruned(HistoryPrunedEvent {}),