openclaw-cascade-plugin 1.0.5 → 1.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/wsl.ts ADDED
@@ -0,0 +1,53 @@
1
+ import * as os from 'os';
2
+ import { exec } from 'child_process';
3
+ import { promisify } from 'util';
4
+
5
+ const execAsync = promisify(exec);
6
+
7
+ /**
8
+ * Detect if OpenClaw is running inside Windows Subsystem for Linux (WSL)
9
+ */
10
+ export function isWsl(): boolean {
11
+ if (process.platform !== 'linux') {
12
+ return false;
13
+ }
14
+ try {
15
+ const release = os.release().toLowerCase();
16
+ return release.includes('microsoft') || release.includes('wsl');
17
+ } catch {
18
+ return false;
19
+ }
20
+ }
21
+
22
+ /**
23
+ * Automatically fetch the Windows host IP address when running inside WSL.
24
+ * This is crucial because `localhost` inside WSL refers to the Linux VM,
25
+ * not the Windows host where the C# Body or Windows Python is running.
26
+ */
27
+ export async function getWslHostIp(): Promise<string | null> {
28
+ if (!isWsl()) return null;
29
+
30
+ try {
31
+ // Strategy 1: Read /etc/resolv.conf which points to the WSL virtual switch gateway
32
+ const { stdout } = await execAsync("cat /etc/resolv.conf | grep nameserver | awk '{print $2}'");
33
+ const ip = stdout.trim();
34
+ if (ip && /^\d+\.\d+\.\d+\.\d+$/.test(ip)) {
35
+ return ip;
36
+ }
37
+ } catch (e) {
38
+ // Ignore and try strategy 2
39
+ }
40
+
41
+ try {
42
+ // Strategy 2: Check the default IP route
43
+ const { stdout } = await execAsync("ip route show default | awk '{print $3}'");
44
+ const ip = stdout.trim();
45
+ if (ip && /^\d+\.\d+\.\d+\.\d+$/.test(ip)) {
46
+ return ip;
47
+ }
48
+ } catch (e) {
49
+ console.debug('Cascade auto-discovery failed to resolve WSL host IP:', e);
50
+ }
51
+
52
+ return null;
53
+ }