Skip to main content

winx_code_agent/daemon/
mod.rs

1//! Long-lived shell daemon and its JSON-RPC Unix-socket client.
2
3mod client;
4mod control;
5mod protocol;
6mod server;
7
8use std::path::PathBuf;
9
10pub use client::{DaemonClient, DaemonShellRuntime};
11pub use control::ControlServer;
12pub use protocol::{
13    HelloResult, JournalRead, SessionInfo, MAX_FRAME_BYTES, PROTOCOL_MAJOR, PROTOCOL_MINOR,
14};
15pub use server::DaemonServer;
16
17/// Resolve the daemon socket without creating it.
18pub fn default_socket_path() -> PathBuf {
19    if let Some(path) = std::env::var_os("WINX_SOCKET") {
20        return PathBuf::from(path);
21    }
22    if let Some(runtime_dir) = std::env::var_os("XDG_RUNTIME_DIR") {
23        return PathBuf::from(runtime_dir).join("winx/winxd.sock");
24    }
25    // SAFETY: geteuid has no preconditions and reads process credentials only.
26    PathBuf::from(format!("/tmp/winx-{}/winxd.sock", unsafe { libc::geteuid() }))
27}