@@ -15,7 +15,6 @@ public class CodexCliService
1515
1616 public string Command { get ; set ; } = "codex" ; // Assumes codex CLI is on PATH
1717 public string AdditionalArgs { get ; set ; } = string . Empty ; // Extra CLI args if needed
18- public bool UseWsl { get ; set ; } = false ; // Windows: run via wsl.exe when true
1918 public bool IsRunning => _process is { HasExited : false } ;
2019 public bool UseApiKey { get ; set ; } = false ;
2120 public string ? ApiKey { get ; set ; }
@@ -114,7 +113,7 @@ public Task SendAsync(string data)
114113 return p . StandardInput . WriteLineAsync ( data ) ;
115114 }
116115
117- internal async Task < ProcessStartInfo > BuildProcessStartInfoAsync ( string workingDir , IEnumerable < string > commandArgs , bool redirectStdIn , bool redirectStdOut = true , bool redirectStdErr = true )
116+ internal Task < ProcessStartInfo > BuildProcessStartInfoAsync ( string workingDir , IEnumerable < string > commandArgs , bool redirectStdIn , bool redirectStdOut = true , bool redirectStdErr = true )
118117 {
119118 var effectiveDir = string . IsNullOrWhiteSpace ( workingDir ) ? Directory . GetCurrentDirectory ( ) : workingDir ;
120119 var psi = new ProcessStartInfo
@@ -142,31 +141,7 @@ internal async Task<ProcessStartInfo> BuildProcessStartInfoAsync(string workingD
142141 normalizedArgs . Add ( normalized ) ;
143142 }
144143
145- if ( UseWsl && OperatingSystem . IsWindows ( ) )
146- {
147- var wslDir = await TranslatePathToWslAsync ( effectiveDir ) ;
148- var wslExe = WslInterop . GetWslExecutable ( ) ;
149- if ( string . IsNullOrWhiteSpace ( wslExe ) || ! WslInterop . IsEnabled )
150- throw new InvalidOperationException ( "WSL is enabled in settings but wsl.exe could not be located." ) ;
151-
152- psi . FileName = wslExe ;
153- var distribution = WslInterop . SelectedDistribution ;
154- if ( ! string . IsNullOrWhiteSpace ( distribution ) )
155- {
156- psi . ArgumentList . Add ( "-d" ) ;
157- psi . ArgumentList . Add ( distribution ! ) ;
158- }
159- if ( ! string . IsNullOrWhiteSpace ( wslDir ) )
160- {
161- psi . ArgumentList . Add ( "--cd" ) ;
162- psi . ArgumentList . Add ( wslDir ) ;
163- }
164- psi . ArgumentList . Add ( "--" ) ;
165- psi . ArgumentList . Add ( "/bin/bash" ) ;
166- psi . ArgumentList . Add ( "-lc" ) ;
167- psi . ArgumentList . Add ( BuildBashCommand ( normalizedCommand , normalizedArgs ) ) ;
168- }
169- else if ( OperatingSystem . IsWindows ( ) )
144+ if ( OperatingSystem . IsWindows ( ) )
170145 {
171146 var resolved = ResolveWindowsCommand ( normalizedCommand , normalizedArgs ) ;
172147 psi . FileName = resolved . FileName ;
@@ -185,51 +160,7 @@ internal async Task<ProcessStartInfo> BuildProcessStartInfoAsync(string workingD
185160 }
186161 }
187162
188- return psi ;
189- }
190-
191- private async Task < string > TranslatePathToWslAsync ( string path )
192- {
193- if ( string . IsNullOrWhiteSpace ( path ) ) return "/" ;
194- if ( ! UseWsl || ! OperatingSystem . IsWindows ( ) ) return path ;
195-
196- try
197- {
198- var psi = WslInterop . CreateBaseProcessStartInfo ( includeDistribution : true ) ;
199- psi . ArgumentList . Add ( "wslpath" ) ;
200- psi . ArgumentList . Add ( "-a" ) ;
201- psi . ArgumentList . Add ( path ) ;
202-
203- using var proc = Process . Start ( psi ) ;
204- if ( proc != null )
205- {
206- var stdout = await proc . StandardOutput . ReadToEndAsync ( ) ;
207- await proc . WaitForExitAsync ( ) ;
208- if ( proc . ExitCode == 0 )
209- {
210- var converted = stdout . Trim ( ) ;
211- if ( ! string . IsNullOrWhiteSpace ( converted ) )
212- return converted . Replace ( '\\ ' , '/' ) ;
213- }
214- }
215- }
216- catch { }
217-
218- return FallbackWindowsPathToWsl ( path ) ;
219- }
220-
221- private static string FallbackWindowsPathToWsl ( string path )
222- {
223- if ( string . IsNullOrWhiteSpace ( path ) ) return "/" ;
224- var trimmed = path . Trim ( ) ;
225- var normalized = trimmed . Replace ( '\\ ' , '/' ) ;
226- if ( normalized . Length >= 2 && normalized [ 1 ] == ':' && char . IsLetter ( normalized [ 0 ] ) )
227- {
228- var drive = char . ToLowerInvariant ( normalized [ 0 ] ) ;
229- var rest = normalized . Substring ( 2 ) . TrimStart ( '/' ) ;
230- return rest . Length == 0 ? $ "/mnt/{ drive } " : $ "/mnt/{ drive } /{ rest } ";
231- }
232- return normalized . StartsWith ( '/' ) ? normalized : "/" + normalized . TrimStart ( '/' ) ;
163+ return Task . FromResult ( psi ) ;
233164 }
234165
235166 private static string NormalizeToken ( string token )
@@ -255,29 +186,6 @@ private static List<string> BuildArgumentTokens(string? additional)
255186 return tokens ;
256187 }
257188
258- private static string BuildBashCommand ( string command , IReadOnlyList < string > args )
259- {
260- var effectiveCommand = string . IsNullOrWhiteSpace ( command ) ? "codex" : command ;
261- var sb = new StringBuilder ( ) ;
262- sb . Append ( "exec " ) . Append ( QuoteForBash ( effectiveCommand ) ) ;
263- if ( args != null )
264- {
265- foreach ( var arg in args )
266- {
267- if ( string . IsNullOrWhiteSpace ( arg ) ) continue ;
268- sb . Append ( ' ' ) . Append ( QuoteForBash ( arg ) ) ;
269- }
270- }
271- return sb . ToString ( ) ;
272- }
273-
274- private static string QuoteForBash ( string value )
275- {
276- if ( string . IsNullOrEmpty ( value ) )
277- return "''" ;
278- return "'" + value . Replace ( "'" , "'\" '\" '" ) + "'" ;
279- }
280-
281189 private static ( string FileName , List < string > Arguments ) ResolveWindowsCommand ( string command , IReadOnlyList < string > args )
282190 {
283191 var argumentList = new List < string > ( ) ;
0 commit comments