Skip to main content

crabtalk_core/
paths.rs

1//! Global paths for the crabtalk runtime.
2//!
3//! All crates resolve configuration, socket, and data paths through these
4//! constants so there is a single source of truth.
5
6use std::path::PathBuf;
7use std::sync::LazyLock;
8
9/// Global configuration directory (`~/.crabtalk/`).
10pub static CONFIG_DIR: LazyLock<PathBuf> = LazyLock::new(|| {
11    dirs::home_dir()
12        .expect("no home directory")
13        .join(".crabtalk")
14});
15
16/// Runtime directory (`~/.crabtalk/run/`).
17pub static RUN_DIR: LazyLock<PathBuf> = LazyLock::new(|| CONFIG_DIR.join("run"));
18
19/// Pinned socket path (`~/.crabtalk/run/crabtalk.sock`).
20#[cfg(unix)]
21pub static SOCKET_PATH: LazyLock<PathBuf> = LazyLock::new(|| RUN_DIR.join("crabtalk.sock"));
22
23/// TCP port file (`~/.crabtalk/run/crabtalk.port`). Contains the port number as text.
24pub static TCP_PORT_FILE: LazyLock<PathBuf> = LazyLock::new(|| RUN_DIR.join("crabtalk.port"));
25
26/// Logs directory (`~/.crabtalk/logs/`).
27pub static LOGS_DIR: LazyLock<PathBuf> = LazyLock::new(|| CONFIG_DIR.join("logs"));
28
29/// Configuration file name.
30pub const CONFIG_FILE: &str = "config.toml";
31/// Mutable settings file (daemon-owned, persisted under `local/`).
32pub const SETTINGS_FILE: &str = "local/settings.toml";
33/// Local package directory (user's own skills, agents, MCPs).
34pub const LOCAL_DIR: &str = "local";
35/// Installed plugin manifests directory.
36pub const PLUGINS_DIR: &str = "plugins";
37/// Agents subdirectory (contains *.md files).
38pub const AGENTS_DIR: &str = "local/agents";
39/// Skills subdirectory.
40pub const SKILLS_DIR: &str = "local/skills";
41
42/// OAuth token storage directory (`~/.crabtalk/tokens/`).
43pub static TOKENS_DIR: LazyLock<PathBuf> = LazyLock::new(|| CONFIG_DIR.join("tokens"));
44
45/// Default agent name used when no custom agents are configured.
46pub const DEFAULT_AGENT: &str = "crab";
47
48/// Port file for a named service: `~/.crabtalk/run/{name}.port`
49pub fn service_port_file(name: &str) -> PathBuf {
50    RUN_DIR.join(format!("{name}.port"))
51}
52
53/// Log file for a named service: `~/.crabtalk/logs/{name}.log`
54pub fn service_log_path(name: &str) -> PathBuf {
55    LOGS_DIR.join(format!("{name}.log"))
56}