1use std::ffi::OsString;
2
3use crate::{ApplyDiffArtifacts, CodexClient, CodexError, ForkSessionRequest};
4
5impl CodexClient {
6 pub async fn fork_session(
8 &self,
9 request: ForkSessionRequest,
10 ) -> Result<ApplyDiffArtifacts, CodexError> {
11 if matches!(request.prompt.as_deref(), Some(prompt) if prompt.trim().is_empty()) {
12 return Err(CodexError::EmptyPrompt);
13 }
14
15 let mut args = vec![OsString::from("fork")];
16 if request.all {
17 args.push(OsString::from("--all"));
18 }
19 if request.last {
20 args.push(OsString::from("--last"));
21 }
22 if let Some(session_id) = request.session_id {
23 if !session_id.trim().is_empty() {
24 args.push(OsString::from(session_id));
25 }
26 }
27 if let Some(prompt) = request.prompt {
28 if !prompt.trim().is_empty() {
29 args.push(OsString::from(prompt));
30 }
31 }
32
33 self.run_simple_command_with_overrides(args, request.overrides)
34 .await
35 }
36}