ralph/config/mod.rs
1//! Configuration resolution for Ralph, including global and project layers.
2//!
3//! Responsibilities:
4//! - Resolve configuration from multiple layers: global config, project config, and defaults.
5//! - Load and parse config files (JSON with JSONC comment support via `load_layer`).
6//! - Merge configuration layers via `ConfigLayer` and `apply_layer`.
7//! - Validate configuration values (version, paths, numeric ranges, runner binaries).
8//! - Resolve queue/done file paths and ID generation settings (prefix, width).
9//! - Discover repository root via `.ralph/` directory or `.git/`.
10//!
11//! Not handled here:
12//! - CLI argument parsing (see `crate::cli`).
13//! - Queue operations like task CRUD (see `crate::queue`).
14//! - Runner execution or agent invocation (see `crate::runner`).
15//! - Prompt rendering or template processing (see `crate::prompts_internal`).
16//! - Lock management (see `crate::lock`).
17//!
18//! Invariants/assumptions:
19//! - Config version must be 1; unsupported versions are rejected.
20//! - Paths are resolved relative to repo root unless absolute.
21//! - Global config resolves from `~/.config/ralph/config.jsonc` with `.json` fallback.
22//! - Project config resolves from `.ralph/config.jsonc` with `.json` fallback.
23//! - Config layers are applied in this order: defaults, then global, then project (later layers override earlier ones).
24//! - `save_layer` creates parent directories automatically if needed.
25
26use std::path::PathBuf;
27
28mod layer;
29mod resolution;
30mod trust;
31mod validation;
32
33#[cfg(test)]
34mod tests;
35
36// Re-export main types and functions for backward compatibility
37pub use layer::{ConfigLayer, apply_layer, load_layer, save_layer};
38pub use resolution::{
39 find_repo_root, global_config_path, prefer_jsonc_then_json, project_config_path,
40 resolve_done_path, resolve_from_cwd, resolve_from_cwd_for_doctor,
41 resolve_from_cwd_with_profile, resolve_id_prefix, resolve_id_width, resolve_queue_path,
42};
43pub use trust::{RepoTrust, load_repo_trust, project_trust_path};
44pub use validation::{
45 git_ref_invalid_reason, validate_agent_binary_paths, validate_agent_patch, validate_config,
46 validate_project_execution_trust, validate_queue_done_file_override,
47 validate_queue_file_override, validate_queue_id_prefix_override,
48 validate_queue_id_width_override, validate_queue_overrides,
49};
50
51/// Resolved configuration including computed paths.
52#[derive(Debug, Clone)]
53pub struct Resolved {
54 pub config: crate::contracts::Config,
55 pub repo_root: PathBuf,
56 pub queue_path: PathBuf,
57 pub done_path: PathBuf,
58 pub id_prefix: String,
59 pub id_width: usize,
60 pub global_config_path: Option<PathBuf>,
61 pub project_config_path: Option<PathBuf>,
62}