diff --git a/src/ClaudeMailbox/Cli/ServiceCommands.cs b/src/ClaudeMailbox/Cli/ServiceCommands.cs index 5dcb3f5..b6856cc 100644 --- a/src/ClaudeMailbox/Cli/ServiceCommands.cs +++ b/src/ClaudeMailbox/Cli/ServiceCommands.cs @@ -123,14 +123,67 @@ public static class ServiceCommands var admin = RequireAdmin(); if (admin != 0) return admin; - Console.Error.WriteLine("uninstall-service: not yet implemented."); - return 1; + var purge = Array.IndexOf(args, "--purge") >= 0; + + // Best-effort stop; ignore failure if not running. + RunSc("stop", ServiceName); + + var deleteExit = RunSc("delete", ServiceName); + if (deleteExit != 0) + { + Console.Error.WriteLine($"sc delete failed (exit {deleteExit})."); + return deleteExit; + } + + if (purge) + { + var programData = Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData); + var dataDir = Path.Combine(programData, "ClaudeMailbox"); + if (Directory.Exists(dataDir)) + { + Directory.Delete(dataDir, recursive: true); + Console.WriteLine($"Purged: {dataDir}"); + } + } + + Console.WriteLine($"Service '{ServiceName}' uninstalled."); + return 0; } [SupportedOSPlatform("windows")] private static int Status() { - Console.Error.WriteLine("status: not yet implemented."); + var psi = new ProcessStartInfo("sc.exe") + { + RedirectStandardOutput = true, + RedirectStandardError = true, + UseShellExecute = false, + }; + psi.ArgumentList.Add("query"); + psi.ArgumentList.Add(ServiceName); + + using var proc = Process.Start(psi)!; + var stdout = proc.StandardOutput.ReadToEnd(); + proc.WaitForExit(); + + if (proc.ExitCode != 0) + { + Console.WriteLine("NotInstalled"); + return 2; + } + + var state = stdout.Split('\n') + .Select(l => l.Trim()) + .FirstOrDefault(l => l.StartsWith("STATE", StringComparison.Ordinal)) + ?? ""; + + if (state.Contains("RUNNING", StringComparison.Ordinal)) + { + Console.WriteLine("Running"); + return 0; + } + + Console.WriteLine("Stopped"); return 1; }