Skip to main content

codex_rollout/
config.rs

1use std::path::Path;
2use std::path::PathBuf;
3use std::sync::Arc;
4
5pub trait RolloutConfigView {
6    fn codex_home(&self) -> &Path;
7    fn sqlite_home(&self) -> &Path;
8    fn cwd(&self) -> &Path;
9    fn model_provider_id(&self) -> &str;
10    fn generate_memories(&self) -> bool;
11}
12
13#[derive(Clone, Debug, PartialEq, Eq)]
14pub struct RolloutConfig {
15    pub codex_home: PathBuf,
16    pub sqlite_home: PathBuf,
17    pub cwd: PathBuf,
18    pub model_provider_id: String,
19    pub generate_memories: bool,
20}
21
22pub type Config = RolloutConfig;
23
24impl RolloutConfig {
25    pub fn from_view(view: &impl RolloutConfigView) -> Self {
26        Self {
27            codex_home: view.codex_home().to_path_buf(),
28            sqlite_home: view.sqlite_home().to_path_buf(),
29            cwd: view.cwd().to_path_buf(),
30            model_provider_id: view.model_provider_id().to_string(),
31            generate_memories: view.generate_memories(),
32        }
33    }
34}
35
36impl RolloutConfigView for RolloutConfig {
37    fn codex_home(&self) -> &Path {
38        self.codex_home.as_path()
39    }
40
41    fn sqlite_home(&self) -> &Path {
42        self.sqlite_home.as_path()
43    }
44
45    fn cwd(&self) -> &Path {
46        self.cwd.as_path()
47    }
48
49    fn model_provider_id(&self) -> &str {
50        self.model_provider_id.as_str()
51    }
52
53    fn generate_memories(&self) -> bool {
54        self.generate_memories
55    }
56}
57
58impl<T: RolloutConfigView + ?Sized> RolloutConfigView for &T {
59    fn codex_home(&self) -> &Path {
60        (*self).codex_home()
61    }
62
63    fn sqlite_home(&self) -> &Path {
64        (*self).sqlite_home()
65    }
66
67    fn cwd(&self) -> &Path {
68        (*self).cwd()
69    }
70
71    fn model_provider_id(&self) -> &str {
72        (*self).model_provider_id()
73    }
74
75    fn generate_memories(&self) -> bool {
76        (*self).generate_memories()
77    }
78}
79
80impl<T: RolloutConfigView + ?Sized> RolloutConfigView for Arc<T> {
81    fn codex_home(&self) -> &Path {
82        self.as_ref().codex_home()
83    }
84
85    fn sqlite_home(&self) -> &Path {
86        self.as_ref().sqlite_home()
87    }
88
89    fn cwd(&self) -> &Path {
90        self.as_ref().cwd()
91    }
92
93    fn model_provider_id(&self) -> &str {
94        self.as_ref().model_provider_id()
95    }
96
97    fn generate_memories(&self) -> bool {
98        self.as_ref().generate_memories()
99    }
100}