Skip to main content

codex/cli/
debug.rs

1use std::path::PathBuf;
2
3use crate::CliOverridesPatch;
4
5/// Request for `codex debug`.
6#[derive(Clone, Debug, Eq, PartialEq)]
7pub struct DebugCommandRequest {
8    /// Per-call CLI overrides layered on top of the builder.
9    pub overrides: CliOverridesPatch,
10}
11
12impl DebugCommandRequest {
13    pub fn new() -> Self {
14        Self {
15            overrides: CliOverridesPatch::default(),
16        }
17    }
18
19    /// Replaces the default CLI overrides for this request.
20    pub fn with_overrides(mut self, overrides: CliOverridesPatch) -> Self {
21        self.overrides = overrides;
22        self
23    }
24}
25
26impl Default for DebugCommandRequest {
27    fn default() -> Self {
28        Self::new()
29    }
30}
31
32/// Request for `codex debug help [COMMAND]...`.
33#[derive(Clone, Debug, Eq, PartialEq)]
34pub struct DebugHelpRequest {
35    /// Optional command tokens passed after `help` (variadic).
36    pub command: Vec<String>,
37    /// Per-call CLI overrides layered on top of the builder.
38    pub overrides: CliOverridesPatch,
39}
40
41impl DebugHelpRequest {
42    pub fn new() -> Self {
43        Self {
44            command: Vec::new(),
45            overrides: CliOverridesPatch::default(),
46        }
47    }
48
49    /// Sets the optional `COMMAND` tokens.
50    pub fn command(mut self, command: impl IntoIterator<Item = impl Into<String>>) -> Self {
51        self.command = command.into_iter().map(Into::into).collect();
52        self
53    }
54
55    /// Replaces the default CLI overrides for this request.
56    pub fn with_overrides(mut self, overrides: CliOverridesPatch) -> Self {
57        self.overrides = overrides;
58        self
59    }
60}
61
62impl Default for DebugHelpRequest {
63    fn default() -> Self {
64        Self::new()
65    }
66}
67
68/// Request for `codex debug app-server`.
69#[derive(Clone, Debug, Eq, PartialEq)]
70pub struct DebugAppServerRequest {
71    /// Per-call CLI overrides layered on top of the builder.
72    pub overrides: CliOverridesPatch,
73}
74
75impl DebugAppServerRequest {
76    pub fn new() -> Self {
77        Self {
78            overrides: CliOverridesPatch::default(),
79        }
80    }
81
82    /// Replaces the default CLI overrides for this request.
83    pub fn with_overrides(mut self, overrides: CliOverridesPatch) -> Self {
84        self.overrides = overrides;
85        self
86    }
87}
88
89impl Default for DebugAppServerRequest {
90    fn default() -> Self {
91        Self::new()
92    }
93}
94
95/// Request for `codex debug app-server help [COMMAND]...`.
96#[derive(Clone, Debug, Eq, PartialEq)]
97pub struct DebugAppServerHelpRequest {
98    /// Optional command tokens passed after `help` (variadic).
99    pub command: Vec<String>,
100    /// Per-call CLI overrides layered on top of the builder.
101    pub overrides: CliOverridesPatch,
102}
103
104impl DebugAppServerHelpRequest {
105    pub fn new() -> Self {
106        Self {
107            command: Vec::new(),
108            overrides: CliOverridesPatch::default(),
109        }
110    }
111
112    /// Sets the optional `COMMAND` tokens.
113    pub fn command(mut self, command: impl IntoIterator<Item = impl Into<String>>) -> Self {
114        self.command = command.into_iter().map(Into::into).collect();
115        self
116    }
117
118    /// Replaces the default CLI overrides for this request.
119    pub fn with_overrides(mut self, overrides: CliOverridesPatch) -> Self {
120        self.overrides = overrides;
121        self
122    }
123}
124
125impl Default for DebugAppServerHelpRequest {
126    fn default() -> Self {
127        Self::new()
128    }
129}
130
131/// Request for `codex debug app-server send-message-v2 <USER_MESSAGE>`.
132#[derive(Clone, Debug, Eq, PartialEq)]
133pub struct DebugAppServerSendMessageV2Request {
134    /// Message payload sent to the app-server debug shim.
135    pub user_message: String,
136    /// Per-call CLI overrides layered on top of the builder.
137    pub overrides: CliOverridesPatch,
138}
139
140impl DebugAppServerSendMessageV2Request {
141    pub fn new(user_message: impl Into<String>) -> Self {
142        Self {
143            user_message: user_message.into(),
144            overrides: CliOverridesPatch::default(),
145        }
146    }
147
148    /// Replaces the default CLI overrides for this request.
149    pub fn with_overrides(mut self, overrides: CliOverridesPatch) -> Self {
150        self.overrides = overrides;
151        self
152    }
153}
154
155/// Request for `codex debug models`.
156#[derive(Clone, Debug, Eq, PartialEq)]
157pub struct DebugModelsRequest {
158    /// Requests the `--bundled` flag when enabled.
159    pub bundled: bool,
160    /// Per-call CLI overrides layered on top of the builder.
161    pub overrides: CliOverridesPatch,
162}
163
164impl DebugModelsRequest {
165    pub fn new() -> Self {
166        Self {
167            bundled: false,
168            overrides: CliOverridesPatch::default(),
169        }
170    }
171
172    /// Controls whether `--bundled` is passed to the command.
173    pub fn bundled(mut self, enable: bool) -> Self {
174        self.bundled = enable;
175        self
176    }
177
178    /// Replaces the default CLI overrides for this request.
179    pub fn with_overrides(mut self, overrides: CliOverridesPatch) -> Self {
180        self.overrides = overrides;
181        self
182    }
183}
184
185impl Default for DebugModelsRequest {
186    fn default() -> Self {
187        Self::new()
188    }
189}
190
191/// Request for `codex debug prompt-input [PROMPT]`.
192#[derive(Clone, Debug, Eq, PartialEq)]
193pub struct DebugPromptInputRequest {
194    /// Optional prompt payload appended after the debug context.
195    pub prompt: Option<String>,
196    /// Image paths forwarded via repeated `--image <FILE>` flags.
197    pub images: Vec<PathBuf>,
198    /// Per-call CLI overrides layered on top of the builder.
199    pub overrides: CliOverridesPatch,
200}
201
202impl DebugPromptInputRequest {
203    pub fn new() -> Self {
204        Self {
205            prompt: None,
206            images: Vec::new(),
207            overrides: CliOverridesPatch::default(),
208        }
209    }
210
211    /// Sets the optional prompt payload.
212    pub fn prompt(mut self, prompt: impl Into<String>) -> Self {
213        self.prompt = Some(prompt.into());
214        self
215    }
216
217    /// Appends a single `--image <FILE>` argument.
218    pub fn image(mut self, image: impl Into<PathBuf>) -> Self {
219        self.images.push(image.into());
220        self
221    }
222
223    /// Extends the repeated `--image <FILE>` arguments.
224    pub fn images<I, P>(mut self, images: I) -> Self
225    where
226        I: IntoIterator<Item = P>,
227        P: Into<PathBuf>,
228    {
229        self.images.extend(images.into_iter().map(Into::into));
230        self
231    }
232
233    /// Replaces the default CLI overrides for this request.
234    pub fn with_overrides(mut self, overrides: CliOverridesPatch) -> Self {
235        self.overrides = overrides;
236        self
237    }
238}
239
240impl Default for DebugPromptInputRequest {
241    fn default() -> Self {
242        Self::new()
243    }
244}