pub trait ConfigEnvironment: Send + Sync {
// Required methods
fn unified_config_path(&self) -> Option<PathBuf>;
fn file_exists(&self, path: &Path) -> bool;
fn read_file(&self, path: &Path) -> Result<String>;
fn write_file(&self, path: &Path, content: &str) -> Result<()>;
fn create_dir_all(&self, path: &Path) -> Result<()>;
// Provided methods
fn local_config_path(&self) -> Option<PathBuf> { ... }
fn prompt_path(&self) -> PathBuf { ... }
fn worktree_root(&self) -> Option<PathBuf> { ... }
}Expand description
Trait for configuration environment access.
This trait abstracts all external side effects needed for configuration:
- Path resolution (which may depend on environment variables)
- File existence checks
- File reading and writing
- Directory creation
By injecting this trait, configuration code becomes pure and testable.
Required Methods§
Sourcefn unified_config_path(&self) -> Option<PathBuf>
fn unified_config_path(&self) -> Option<PathBuf>
Get the path to the unified config file.
In production, this returns ~/.config/ralph-workflow.toml or
$XDG_CONFIG_HOME/ralph-workflow.toml if the env var is set.
Returns None if the path cannot be determined (e.g., no home directory).
Sourcefn file_exists(&self, path: &Path) -> bool
fn file_exists(&self, path: &Path) -> bool
Check if a file exists at the given path.
Sourcefn write_file(&self, path: &Path, content: &str) -> Result<()>
fn write_file(&self, path: &Path, content: &str) -> Result<()>
Write content to a file, creating parent directories if needed.
Sourcefn create_dir_all(&self, path: &Path) -> Result<()>
fn create_dir_all(&self, path: &Path) -> Result<()>
Create directories recursively.
Provided Methods§
Sourcefn local_config_path(&self) -> Option<PathBuf>
fn local_config_path(&self) -> Option<PathBuf>
Get the path to the local config file.
In production, this returns .agent/ralph-workflow.toml relative to CWD.
Tests may override this to use a different path.
Returns None if local config is not supported or path cannot be determined.
Sourcefn prompt_path(&self) -> PathBuf
fn prompt_path(&self) -> PathBuf
Get the path to the PROMPT.md file.
In production, this returns ./PROMPT.md (relative to current directory).
Tests may override this to use a different path.
Sourcefn worktree_root(&self) -> Option<PathBuf>
fn worktree_root(&self) -> Option<PathBuf>
Get the root of the current git worktree, if running inside one.
Returns None if not in a git repository or in a bare repository.
This is used to resolve local config paths relative to the worktree root
instead of the current working directory.