Skip to main content

ralph_workflow/agents/ccs_env/
io.rs

1// agents/ccs_env/io.rs — boundary module for CCS environment variable loading.
2// File stem is `io` — recognized as boundary module by forbid_io_effects lint.
3
4pub struct RealCcsEnvironment;
5
6impl CcsEnvironment for RealCcsEnvironment {
7    fn get_var(&self, name: &str) -> Option<String> {
8        std::env::var(name).ok()
9    }
10
11    fn home_dir(&self) -> Option<std::path::PathBuf> {
12        dirs::home_dir()
13    }
14}
15
16pub struct RealCcsFilesystem;
17
18impl CcsFilesystem for RealCcsFilesystem {
19    fn exists(&self, path: &std::path::Path) -> bool {
20        path.exists()
21    }
22
23    fn read_to_string(&self, path: &std::path::Path) -> Result<String, std::io::Error> {
24        std::fs::read_to_string(path)
25    }
26
27    fn read_dir(&self, path: &std::path::Path) -> Result<Vec<CcsDirEntry>, std::io::Error> {
28        let entries = std::fs::read_dir(path)?;
29        entries
30            .map(|entry| {
31                let entry = entry?;
32                let ft = entry.file_type()?;
33                Ok(CcsDirEntry {
34                    path: entry.path(),
35                    file_name: entry.file_name().to_string_lossy().into_owned(),
36                    is_file: ft.is_file(),
37                })
38            })
39            .collect()
40    }
41}