Skip to content

Commit 03f8fb5

Browse files
authored
Merge pull request #27 from semantic-developer/feature/sd-29
feature/sd-29
2 parents 0bdee96 + e1a139f commit 03f8fb5

15 files changed

+770
-680
lines changed

SemanticDeveloper/SemanticDeveloper/MainWindow.axaml.cs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@ public MainWindow()
2727
DataContext = this;
2828

2929
_sharedSettings = CloneAppSettings(SettingsService.Load());
30-
var useWsl = OperatingSystem.IsWindows() && _sharedSettings.UseWsl;
31-
Services.CodexConfigService.SetUseWsl(useWsl);
3230
AddSession(applySharedSettings: true);
3331
}
3432

@@ -284,7 +282,6 @@ private async void OnCloseTabClick(object? sender, RoutedEventArgs e)
284282
ShowMcpResultsInLog = source.ShowMcpResultsInLog,
285283
ShowMcpResultsOnlyWhenNoEdits = source.ShowMcpResultsOnlyWhenNoEdits,
286284
SelectedProfile = source.SelectedProfile,
287-
UseWsl = source.UseWsl,
288285
SelectedModelId = source.SelectedModelId,
289286
SelectedReasoningEffort = source.SelectedReasoningEffort
290287
};
@@ -341,9 +338,4 @@ private void OnPropertyChanged([CallerMemberName] string? name = null)
341338
=> PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));
342339
}
343340

344-
internal void RequestProfileCheck()
345-
{
346-
_profileCheckPerformed = false;
347-
Dispatcher.UIThread.Post(async () => await EnsureProfilesConfiguredAsync());
348-
}
349341
}

SemanticDeveloper/SemanticDeveloper/Models/AppSettings.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ public class AppSettings
1111
public bool ShowMcpResultsInLog { get; set; } = true;
1212
public bool ShowMcpResultsOnlyWhenNoEdits { get; set; } = true;
1313
public string SelectedProfile { get; set; } = string.Empty;
14-
public bool UseWsl { get; set; } = false;
1514
public string SelectedModelId { get; set; } = string.Empty;
1615
public string SelectedReasoningEffort { get; set; } = string.Empty;
1716
}

SemanticDeveloper/SemanticDeveloper/Services/CodexAuthService.cs

Lines changed: 4 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,6 @@ public static string GetAuthJsonPath()
1010
{
1111
try
1212
{
13-
if (WslInterop.IsEnabled)
14-
{
15-
var wslPath = WslInterop.TryConvertToWindowsPath("~/.codex/auth.json");
16-
if (!string.IsNullOrWhiteSpace(wslPath))
17-
{
18-
Console.WriteLine($"[CodexAuth] Using WSL auth path {wslPath}.");
19-
return wslPath;
20-
}
21-
}
22-
2313
var home = Environment.GetEnvironmentVariable("CODEX_HOME");
2414
string dir;
2515
if (!string.IsNullOrWhiteSpace(home)) dir = home!;
@@ -38,26 +28,10 @@ public static (bool Exists, bool HasTokens, string? ApiKey) ProbeAuth()
3828
try
3929
{
4030
string? text = null;
41-
if (WslInterop.IsEnabled)
42-
{
43-
text = WslInterop.ReadFile("~/.codex/auth.json");
44-
if (string.IsNullOrWhiteSpace(text))
45-
{
46-
var wslPath = WslInterop.TryConvertToWindowsPath("~/.codex/auth.json");
47-
if (!string.IsNullOrWhiteSpace(wslPath) && File.Exists(wslPath))
48-
{
49-
Console.WriteLine($"[CodexAuth] Using converted WSL auth path {wslPath}.");
50-
text = File.ReadAllText(wslPath);
51-
}
52-
}
53-
}
54-
else
55-
{
56-
var path = GetAuthJsonPath();
57-
if (!File.Exists(path)) return (false, false, null);
58-
Console.WriteLine($"[CodexAuth] Reading auth from {path}.");
59-
text = File.ReadAllText(path);
60-
}
31+
var path = GetAuthJsonPath();
32+
if (!File.Exists(path)) return (false, false, null);
33+
Console.WriteLine($"[CodexAuth] Reading auth from {path}.");
34+
text = File.ReadAllText(path);
6135

6236
if (string.IsNullOrWhiteSpace(text))
6337
return (false, false, null);
@@ -89,4 +63,3 @@ public static (bool Exists, bool HasTokens, string? ApiKey) ProbeAuth()
8963
}
9064
}
9165
}
92-

SemanticDeveloper/SemanticDeveloper/Services/CodexCliService.cs

Lines changed: 3 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -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>();

SemanticDeveloper/SemanticDeveloper/Services/CodexConfigService.cs

Lines changed: 0 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -6,34 +6,13 @@ namespace SemanticDeveloper.Services;
66

77
public static class CodexConfigService
88
{
9-
private static bool _useWsl;
10-
119
public static string? LastProfileSource { get; private set; }
1210
public static string? LastProfileError { get; private set; }
1311

14-
public static void SetUseWsl(bool useWsl)
15-
{
16-
_useWsl = useWsl && OperatingSystem.IsWindows();
17-
WslInterop.SetUseWsl(_useWsl);
18-
}
19-
2012
public static string GetConfigTomlPath()
2113
{
2214
try
2315
{
24-
if (_useWsl && WslInterop.IsEnabled)
25-
{
26-
var wslPath = WslInterop.TryConvertToWindowsPath("~/.codex/config.toml");
27-
if (!string.IsNullOrWhiteSpace(wslPath))
28-
{
29-
Console.WriteLine($"[CodexConfig] Using WSL config path {wslPath}.");
30-
LastProfileSource = $"wslpath:{wslPath}";
31-
return wslPath;
32-
}
33-
34-
Console.WriteLine("[CodexConfig] Could not convert WSL config path; falling back to Windows default.");
35-
}
36-
3716
var home = Environment.GetEnvironmentVariable("CODEX_HOME");
3817
string dir;
3918
if (!string.IsNullOrWhiteSpace(home)) dir = home!;
@@ -51,18 +30,6 @@ public static string GetPromptsDirectory()
5130
{
5231
try
5332
{
54-
if (_useWsl && WslInterop.IsEnabled)
55-
{
56-
var wslPath = WslInterop.TryConvertToWindowsPath("~/.codex/prompts");
57-
if (!string.IsNullOrWhiteSpace(wslPath))
58-
{
59-
Console.WriteLine($"[CodexConfig] Using WSL prompts path {wslPath}.");
60-
return wslPath;
61-
}
62-
63-
Console.WriteLine("[CodexConfig] Could not convert WSL prompts path; falling back to Windows default.");
64-
}
65-
6633
var home = Environment.GetEnvironmentVariable("CODEX_HOME");
6734
string dir;
6835
if (!string.IsNullOrWhiteSpace(home)) dir = home!;
@@ -83,37 +50,6 @@ public static List<string> TryGetProfiles()
8350
LastProfileSource = null;
8451
LastProfileError = null;
8552

86-
if (_useWsl && WslInterop.IsEnabled)
87-
{
88-
var content = WslInterop.ReadFile("~/.codex/config.toml");
89-
if (!string.IsNullOrWhiteSpace(content))
90-
{
91-
Console.WriteLine("[CodexConfig] Loaded profiles from WSL config (~/.codex/config.toml).");
92-
LastProfileSource = "wsl:~/.codex/config.toml";
93-
return ParseProfiles(content);
94-
}
95-
96-
if (string.IsNullOrWhiteSpace(content))
97-
{
98-
var fallbackPath = WslInterop.TryConvertToWindowsPath("~/.codex/config.toml");
99-
if (!string.IsNullOrWhiteSpace(fallbackPath) && File.Exists(fallbackPath))
100-
{
101-
Console.WriteLine($"[CodexConfig] WSL config not directly readable; using converted path {fallbackPath}.");
102-
LastProfileSource = fallbackPath;
103-
content = File.ReadAllText(fallbackPath);
104-
}
105-
}
106-
if (!string.IsNullOrWhiteSpace(content))
107-
{
108-
Console.WriteLine("[CodexConfig] Loaded profiles from converted WSL path.");
109-
LastProfileSource = LastProfileSource ?? "wslpath (converted)";
110-
return ParseProfiles(content);
111-
}
112-
LastProfileError = "WSL ~/.codex/config.toml not found";
113-
Console.WriteLine("[CodexConfig] Failed to load profiles from WSL; config file missing.");
114-
return result;
115-
}
116-
11753
var path = GetConfigTomlPath();
11854
if (!File.Exists(path)) return result;
11955
var text = File.ReadAllText(path);

0 commit comments

Comments
 (0)