coding_agent_search/daemon/mod.rs
1//! Semantic model daemon for warm embedding and reranking.
2//!
3//! This module provides a daemon server that keeps ML models resident in memory
4//! for fast inference. The daemon:
5//! - Listens on a Unix Domain Socket for requests
6//! - Shares the socket with xf (wire-compatible protocol)
7//! - First-come spawns, others connect
8//! - Supports graceful fallback to direct inference
9//!
10//! ## Architecture
11//!
12//! ```text
13//! ┌─────────────────────────────────────────────────────────────────┐
14//! │ WIRE-COMPATIBLE DAEMONS │
15//! ├─────────────────────────────────────────────────────────────────┤
16//! │ xf (standalone) cass (standalone) │
17//! │ ┌──────────────┐ ┌──────────────┐ │
18//! │ │ xf binary │ │ cass binary │ │
19//! │ │ └─ daemon │ │ └─ daemon │ │
20//! │ └──────────────┘ └──────────────┘ │
21//! │ │ Same socket path: /tmp/semantic-daemon-$USER.sock │
22//! │ ▼ ▼ │
23//! │ ┌────────────────────────────────────────┐ │
24//! │ │ Shared UDS Socket (first-come wins) │ │
25//! │ └────────────────────────────────────────┘ │
26//! └─────────────────────────────────────────────────────────────────┘
27//! ```
28//!
29//! ## Usage
30//!
31//! ```ignore
32//! use cass::daemon::{client::UdsDaemonClient, core::ModelDaemon};
33//!
34//! // Client usage (auto-spawns daemon if not running)
35//! let client = UdsDaemonClient::with_defaults();
36//! client.connect()?;
37//! let embeddings = client.embed(&["hello world"])?;
38//!
39//! // Server usage (for daemon subprocess)
40//! let daemon = ModelDaemon::with_defaults(&data_dir);
41//! daemon.run()?;
42//! ```
43
44pub mod client;
45pub mod core;
46pub mod models;
47pub mod protocol;
48pub mod resource;
49pub mod worker;
50
51use std::path::{Path, PathBuf};
52
53// Used by daemon client/server paths in some target combinations, but not all
54// library-only builds that we verify during placeholder cleanup.
55#[allow(dead_code)]
56pub(crate) fn daemon_run_lock_path(socket_path: &Path) -> PathBuf {
57 socket_path.with_extension("spawnlock")
58}
59
60pub(crate) fn daemon_spawn_guard_lock_path(socket_path: &Path) -> PathBuf {
61 socket_path.with_extension("spawn-guard.lock")
62}
63
64// Re-export key types for convenience
65pub use client::{DaemonClientConfig, UdsDaemonClient};
66pub use core::{DaemonConfig, ModelDaemon};
67pub use models::ModelManager;
68pub use protocol::{PROTOCOL_VERSION, Request, Response, default_socket_path};
69pub use resource::ResourceMonitor;
70pub use worker::{EmbeddingJobConfig, EmbeddingWorkerHandle};