diff --git a/packages/experimental/cua-windows/native/entry/CuaWindows.csproj b/packages/experimental/cua-windows/native/entry/CuaWindows.csproj
index 64093d02e4..64233ba671 100644
--- a/packages/experimental/cua-windows/native/entry/CuaWindows.csproj
+++ b/packages/experimental/cua-windows/native/entry/CuaWindows.csproj
@@ -12,8 +12,13 @@
app.manifest
none
false
+ DeepSeek.Cua.Windows
+
+
+
+
diff --git a/packages/experimental/cua-windows/native/entry/Program.cs b/packages/experimental/cua-windows/native/entry/Program.cs
index d46db4479c..6e2910a72d 100644
--- a/packages/experimental/cua-windows/native/entry/Program.cs
+++ b/packages/experimental/cua-windows/native/entry/Program.cs
@@ -1,35 +1,59 @@
// The executable is a private helper launched by the dsh Windows provider.
+using System.CommandLine;
using DeepSeek.Cua.Protocol;
+using DeepSeek.Cua.Windows;
-namespace DeepSeek.Cua.Windows;
-
-internal static class Program
+try
{
- private static int Main(string[] args)
+#if NETFRAMEWORK
+ if (Environment.OSVersion.Version.Build < 19041)
{
- try
- {
- if (!OperatingSystem.IsWindowsVersionAtLeast(10, 0, 19041)) throw new NativeFailure("UNSUPPORTED", "Windows CUA requires Windows 10 build 19041 or later");
- var server = args.Length == 7 && args[0] == "--shared-server";
- var bridge = args.Length == 7 && args[0] == "--bridge";
- var connector = args.Length == 9 && args[0] == "--serve" && args[1] == "--instance-id" && Guid.TryParseExact(args[2], "N", out _);
- var offset = server || bridge ? 1 : 3;
- if ((!server && !connector && !bridge) || args[offset] != "--runtime-key" || args[offset + 2] != "--connect-timeout-ms"
- || args[offset + 4] != "--grace-ms"
- || !int.TryParse(args[offset + 3], out var connectTimeoutMs) || connectTimeoutMs <= 0
- || !int.TryParse(args[offset + 5], out var graceMs) || graceMs <= 0)
- throw new NativeFailure("INVALID_ARGUMENT", "The helper must be launched by the dsh Windows provider");
- var runtime = Applications.Digest(Environment.ProcessPath!);
- if (runtime != args[offset + 1]) throw new NativeFailure("NATIVE_STARTUP", "The helper executable changed before startup");
- if (server) SharedRuntime.Serve(runtime, connectTimeoutMs, graceMs);
- else if (bridge) SharedRuntime.Bridge(runtime, connectTimeoutMs).GetAwaiter().GetResult();
- else SharedRuntime.Connect(args[2], runtime, connectTimeoutMs, graceMs).GetAwaiter().GetResult();
- return 0;
- }
- catch (Exception error)
- {
- Console.Error.WriteLine(error is NativeFailure failure ? $"{failure.Code}: {failure.Message}" : $"NATIVE_STARTUP: {error.Message}");
- return 1;
- }
+ throw new NativeFailure("UNSUPPORTED", "Windows CUA requires Windows 10 build 19041 or later");
}
+#endif
+
+ var serve = new Option("--serve") { Arity = ArgumentArity.Zero };
+ var sharedServer = new Option("--shared-server") { Arity = ArgumentArity.Zero };
+ var bridge = new Option("--bridge") { Arity = ArgumentArity.Zero };
+ var instanceId = new Option("--instance-id");
+ var runtimeKey = new Option("--runtime-key") { Required = true };
+ var connectTimeoutMs = new Option("--connect-timeout-ms") { Required = true };
+ var graceMs = new Option("--grace-ms") ;
+
+ var rootCommand = new RootCommand
+ {
+ Options =
+ {
+ serve,
+ sharedServer,
+ bridge,
+ instanceId,
+ runtimeKey,
+ connectTimeoutMs,
+ graceMs,
+ }
+ };
+
+ var parseResult = rootCommand.Parse(args);
+ if (parseResult.Errors.Count != 0)
+ throw new NativeFailure("INVALID_ARGUMENT", "The helper must be launched by the dsh Windows provider");
+
+ var runtime = Applications.Digest(Environment.ProcessPath!);
+ if (runtime != parseResult.GetValue(runtimeKey)) throw new NativeFailure("NATIVE_STARTUP", "The helper executable changed before startup");
+
+ if (parseResult.GetValue(sharedServer))
+ SharedRuntime.Serve(runtime, parseResult.GetRequiredValue(connectTimeoutMs), parseResult.GetRequiredValue(graceMs));
+ else if (parseResult.GetValue(bridge))
+ await SharedRuntime.Bridge(runtime, parseResult.GetRequiredValue(connectTimeoutMs));
+ else if (parseResult.GetValue(serve))
+ await SharedRuntime.Connect(parseResult.GetRequiredValue(instanceId).ToString("N"), runtime, parseResult.GetRequiredValue(connectTimeoutMs), parseResult.GetRequiredValue(graceMs));
+ else
+ throw new NativeFailure("INVALID_ARGUMENT", "The helper must be launched by the dsh Windows provider");
+
+ return 0;
+}
+catch (Exception error)
+{
+ Console.Error.WriteLine(error is NativeFailure failure ? $"{failure.Code}: {failure.Message}" : $"NATIVE_STARTUP: {error.Message}");
+ return -1;
}
diff --git a/packages/experimental/cua-windows/native/entry/packages.lock.json b/packages/experimental/cua-windows/native/entry/packages.lock.json
index 44acac2f65..32ee8aad59 100644
--- a/packages/experimental/cua-windows/native/entry/packages.lock.json
+++ b/packages/experimental/cua-windows/native/entry/packages.lock.json
@@ -17,6 +17,15 @@
"resolved": "1.15.0",
"contentHash": "FbU0El+EEjdpuIX4iDbeS7ki1uzpJPx8vbqOzEtqnl1GZeAGJfq+jCbxeJL2y0EPnUNk8dRnnqR2xnYXg9Tf+g=="
},
+ "System.CommandLine": {
+ "type": "Direct",
+ "requested": "[2.0.14, )",
+ "resolved": "2.0.14",
+ "contentHash": "15fyVO4aG6poR6IKmhM74zf7PUzaU6FZAGm2d3SQSO9yIyGAeo44e6t9qeKjjaqyMEqYdqcb2G1B0gpLoDU2cA==",
+ "dependencies": {
+ "System.Memory": "4.5.5"
+ }
+ },
"System.Text.Json": {
"type": "Direct",
"requested": "[10.0.14, 10.0.14]",