Skip to main content

zeph_config/
defaults.rs

1// SPDX-FileCopyrightText: 2026 Andrei G <bug-ops>
2// SPDX-License-Identifier: MIT OR Apache-2.0
3
4use std::path::PathBuf;
5
6/// Legacy project-relative runtime paths kept for compatibility checks and migration messaging.
7pub const DEFAULT_SQLITE_PATH: &str = ".zeph/data/zeph.db";
8pub const DEFAULT_SKILLS_DIR: &str = ".zeph/skills";
9pub const DEFAULT_DEBUG_DIR: &str = ".zeph/debug";
10pub const DEFAULT_LOG_FILE: &str = ".zeph/logs/zeph.log";
11
12#[cfg(any(target_os = "macos", target_os = "windows"))]
13const PLATFORM_APP_DIR_NAME: &str = "Zeph";
14#[cfg(not(any(target_os = "macos", target_os = "windows")))]
15const PLATFORM_APP_DIR_NAME: &str = "zeph";
16
17/// Platform default writable data root.
18///
19/// Examples:
20/// - Linux: `~/.local/share/zeph`
21/// - macOS: `~/Library/Application Support/Zeph`
22/// - Windows: `%LOCALAPPDATA%\Zeph`
23pub(crate) fn default_runtime_data_root() -> PathBuf {
24    dirs::data_local_dir()
25        .or_else(dirs::data_dir)
26        .or_else(|| dirs::home_dir().map(|home| home.join(".local").join("share")))
27        .unwrap_or_else(|| PathBuf::from("."))
28        .join(PLATFORM_APP_DIR_NAME)
29}
30
31#[must_use]
32pub fn default_sqlite_path() -> String {
33    default_runtime_data_root()
34        .join("data")
35        .join("zeph.db")
36        .to_string_lossy()
37        .into_owned()
38}
39
40/// Returns the default vault/config directory for skills.
41///
42/// Mirrors the logic in zeph-core's `default_vault_dir` but without depending on that crate.
43#[must_use]
44pub fn default_vault_dir() -> PathBuf {
45    if let Ok(xdg) = std::env::var("XDG_CONFIG_HOME") {
46        return PathBuf::from(xdg).join("zeph");
47    }
48    if let Ok(appdata) = std::env::var("APPDATA") {
49        return PathBuf::from(appdata).join("zeph");
50    }
51    let home = std::env::var("HOME").unwrap_or_else(|_| ".".to_owned());
52    PathBuf::from(home).join(".config").join("zeph")
53}
54
55#[must_use]
56pub fn default_skills_dir() -> String {
57    default_vault_dir()
58        .join("skills")
59        .to_string_lossy()
60        .into_owned()
61}
62
63#[must_use]
64pub fn default_debug_dir() -> PathBuf {
65    default_runtime_data_root().join("debug")
66}
67
68#[must_use]
69pub fn default_log_file_path() -> String {
70    default_runtime_data_root()
71        .join("logs")
72        .join("zeph.log")
73        .to_string_lossy()
74        .into_owned()
75}
76
77#[must_use]
78pub fn default_skill_paths() -> Vec<String> {
79    vec![default_skills_dir()]
80}
81
82pub(crate) fn default_log_file() -> String {
83    default_log_file_path()
84}
85
86#[must_use]
87pub fn default_sqlite_path_field() -> String {
88    default_sqlite_path()
89}
90
91pub(crate) fn default_debug_output_dir() -> PathBuf {
92    default_debug_dir()
93}
94
95#[must_use]
96pub fn is_legacy_default_sqlite_path(path: &str) -> bool {
97    path == DEFAULT_SQLITE_PATH
98}
99
100#[must_use]
101pub fn is_legacy_default_skills_path(path: &str) -> bool {
102    path == DEFAULT_SKILLS_DIR
103}
104
105#[must_use]
106pub fn is_legacy_default_debug_dir(path: &std::path::Path) -> bool {
107    path == std::path::Path::new(DEFAULT_DEBUG_DIR)
108}
109
110#[must_use]
111pub fn is_legacy_default_log_file(path: &str) -> bool {
112    path == DEFAULT_LOG_FILE
113}
114
115pub(crate) fn default_true() -> bool {
116    true
117}