@mcesystems/usbmuxd-instance-manager 1.0.75 → 1.0.77
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/dist/cli.js +50 -58
- package/dist/cli.js.map +3 -3
- package/dist/cli.mjs +50 -58
- package/dist/cli.mjs.map +3 -3
- package/dist/index.js +50 -68
- package/dist/index.js.map +3 -3
- package/dist/index.mjs +50 -58
- package/dist/index.mjs.map +3 -3
- package/dist/types/InstanceManager.d.ts +1 -0
- package/dist/types/InstanceManager.d.ts.map +1 -1
- package/dist/types/UsbmuxdService.d.ts +5 -2
- package/dist/types/UsbmuxdService.d.ts.map +1 -1
- package/dist/types/wsl.d.ts.map +1 -1
- package/package.json +2 -3
package/dist/index.js
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
2
|
var __defProp = Object.defineProperty;
|
|
4
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
5
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
6
|
var __export = (target, all) => {
|
|
9
7
|
for (var name in all)
|
|
@@ -17,14 +15,6 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
17
15
|
}
|
|
18
16
|
return to;
|
|
19
17
|
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
-
mod
|
|
27
|
-
));
|
|
28
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
19
|
|
|
30
20
|
// src/index.ts
|
|
@@ -38,7 +28,6 @@ module.exports = __toCommonJS(index_exports);
|
|
|
38
28
|
// src/UsbmuxdService.ts
|
|
39
29
|
var import_node_events2 = require("node:events");
|
|
40
30
|
var import_tool_debug_g44 = require("@mcesystems/tool-debug-g4");
|
|
41
|
-
var import_usb_device_listener = __toESM(require("@mcesystems/usb-device-listener"));
|
|
42
31
|
|
|
43
32
|
// src/InstanceManager.ts
|
|
44
33
|
var import_node_events = require("node:events");
|
|
@@ -269,9 +258,7 @@ var Wsl2 = class {
|
|
|
269
258
|
...usbmuxdArgs
|
|
270
259
|
];
|
|
271
260
|
const process2 = (0, import_node_child_process2.spawn)("wsl", wslArgs, {
|
|
272
|
-
stdio: ["ignore", "pipe", "pipe"]
|
|
273
|
-
detached: true,
|
|
274
|
-
windowsHide: false
|
|
261
|
+
stdio: ["ignore", "pipe", "pipe"]
|
|
275
262
|
});
|
|
276
263
|
process2.stdout?.on("data", (data) => {
|
|
277
264
|
onLog(data.toString().trim());
|
|
@@ -453,7 +440,7 @@ ${stdout}`);
|
|
|
453
440
|
};
|
|
454
441
|
|
|
455
442
|
// src/InstanceManager.ts
|
|
456
|
-
var { logWarning: logWarning3,
|
|
443
|
+
var { logWarning: logWarning3, logDataObject, logTask } = (0, import_tool_debug_g43.createLoggers)("instance-manager");
|
|
457
444
|
var DEFAULT_CONFIG = {
|
|
458
445
|
batchSize: 4,
|
|
459
446
|
basePort: 27015,
|
|
@@ -496,6 +483,9 @@ var InstanceManager = class extends import_node_events.EventEmitter {
|
|
|
496
483
|
if (this.isRunning) {
|
|
497
484
|
throw new Error("Instance manager is already running");
|
|
498
485
|
}
|
|
486
|
+
for (let i = 0; i < this.config.maxInstances; i++) {
|
|
487
|
+
this.createInstance(i + 1);
|
|
488
|
+
}
|
|
499
489
|
this.isRunning = true;
|
|
500
490
|
this.startedAt = /* @__PURE__ */ new Date();
|
|
501
491
|
}
|
|
@@ -582,31 +572,33 @@ var InstanceManager = class extends import_node_events.EventEmitter {
|
|
|
582
572
|
instanceId: instance.id
|
|
583
573
|
});
|
|
584
574
|
}
|
|
575
|
+
async createInstance(id) {
|
|
576
|
+
let onExit = (code, signal) => {
|
|
577
|
+
this.onUsbmuxdInstanceEnd({ instanceId: id, code, signal });
|
|
578
|
+
};
|
|
579
|
+
onExit = onExit.bind(this);
|
|
580
|
+
const { instance, process: process2 } = await this.wsl.createInstance({
|
|
581
|
+
id,
|
|
582
|
+
basePort: this.config.basePort,
|
|
583
|
+
verboseLogging: this.config.verboseLogging,
|
|
584
|
+
usbmuxdPath: this.config.usbmuxdPath,
|
|
585
|
+
onLog: (message) => this.emit("instance-log", {
|
|
586
|
+
instanceId: id,
|
|
587
|
+
level: "info",
|
|
588
|
+
message
|
|
589
|
+
}),
|
|
590
|
+
onExit
|
|
591
|
+
});
|
|
592
|
+
this.onUsbmuxdInstanceStart({ instance, process: process2 });
|
|
593
|
+
return instance;
|
|
594
|
+
}
|
|
585
595
|
async getInstance() {
|
|
586
596
|
let targetInstance = this.findInstanceWithCapacity();
|
|
587
597
|
if (!targetInstance) {
|
|
588
598
|
if (this.instances.size >= this.config.maxInstances) {
|
|
589
599
|
throw new Error(`Maximum number of instances (${this.config.maxInstances}) reached`);
|
|
590
600
|
}
|
|
591
|
-
|
|
592
|
-
let onExit = (code, signal) => {
|
|
593
|
-
this.onUsbmuxdInstanceEnd({ instanceId: newInstanceId, code, signal });
|
|
594
|
-
};
|
|
595
|
-
onExit = onExit.bind(this);
|
|
596
|
-
const { instance, process: process2 } = await this.wsl.createInstance({
|
|
597
|
-
id: newInstanceId,
|
|
598
|
-
basePort: this.config.basePort,
|
|
599
|
-
verboseLogging: this.config.verboseLogging,
|
|
600
|
-
usbmuxdPath: this.config.usbmuxdPath,
|
|
601
|
-
onLog: (message) => this.emit("instance-log", {
|
|
602
|
-
instanceId: newInstanceId,
|
|
603
|
-
level: "info",
|
|
604
|
-
message
|
|
605
|
-
}),
|
|
606
|
-
onExit
|
|
607
|
-
});
|
|
608
|
-
this.onUsbmuxdInstanceStart({ instance, process: process2 });
|
|
609
|
-
targetInstance = instance;
|
|
601
|
+
targetInstance = await this.createInstance(this.nextInstanceId++);
|
|
610
602
|
}
|
|
611
603
|
return targetInstance;
|
|
612
604
|
}
|
|
@@ -677,10 +669,6 @@ var InstanceManager = class extends import_node_events.EventEmitter {
|
|
|
677
669
|
device,
|
|
678
670
|
instance
|
|
679
671
|
});
|
|
680
|
-
if (instance.deviceUdids.length === 0) {
|
|
681
|
-
logDetail2(`Instance ${instance.id} is empty, stopping...`);
|
|
682
|
-
await this.stopInstance(instance.id);
|
|
683
|
-
}
|
|
684
672
|
}
|
|
685
673
|
/**
|
|
686
674
|
* Find an instance with available capacity
|
|
@@ -759,12 +747,10 @@ var InstanceManager = class extends import_node_events.EventEmitter {
|
|
|
759
747
|
var { logInfo: logInfo3, logError, logDataObject: logDataObject2 } = (0, import_tool_debug_g44.createLoggers)("usbmuxd-service");
|
|
760
748
|
var UsbmuxdService = class extends import_node_events2.EventEmitter {
|
|
761
749
|
manager;
|
|
762
|
-
usbListener;
|
|
763
750
|
isListening = false;
|
|
764
751
|
constructor(config = {}) {
|
|
765
752
|
super();
|
|
766
753
|
this.manager = new InstanceManager(config);
|
|
767
|
-
this.usbListener = new import_usb_device_listener.default();
|
|
768
754
|
this.setupEventHandlers();
|
|
769
755
|
}
|
|
770
756
|
/**
|
|
@@ -817,42 +803,39 @@ var UsbmuxdService = class extends import_node_events2.EventEmitter {
|
|
|
817
803
|
throw new Error("Service is already running");
|
|
818
804
|
}
|
|
819
805
|
const config = this.manager.getConfig();
|
|
820
|
-
const appleVid = Number.parseInt(config.appleVendorId, 16);
|
|
821
806
|
logDataObject2("Starting service...", { config });
|
|
822
|
-
this.usbListener.onDeviceAdd(async (device) => {
|
|
823
|
-
if (device.vid !== appleVid) {
|
|
824
|
-
return;
|
|
825
|
-
}
|
|
826
|
-
logInfo3(`Apple device connected: ${device.deviceId} (${device.deviceName || "Unknown"})`);
|
|
827
|
-
try {
|
|
828
|
-
await this.manager.onDeviceConnected(device);
|
|
829
|
-
} catch (error) {
|
|
830
|
-
logError("Error handling device connection:", error);
|
|
831
|
-
}
|
|
832
|
-
});
|
|
833
|
-
this.usbListener.onDeviceRemove(async (device) => {
|
|
834
|
-
if (device.vid !== appleVid) {
|
|
835
|
-
return;
|
|
836
|
-
}
|
|
837
|
-
logInfo3(`Apple device disconnected: ${device.deviceId}`);
|
|
838
|
-
try {
|
|
839
|
-
await this.manager.onDeviceDisconnected(device);
|
|
840
|
-
} catch (error) {
|
|
841
|
-
logError("Error handling device disconnection:", error);
|
|
842
|
-
}
|
|
843
|
-
});
|
|
844
807
|
try {
|
|
845
|
-
this.usbListener.startListening({
|
|
846
|
-
targetDevices: []
|
|
847
|
-
// Monitor all devices, we'll filter by VID
|
|
848
|
-
});
|
|
849
808
|
this.isListening = true;
|
|
850
809
|
this.manager.start();
|
|
851
810
|
logInfo3("Service started successfully");
|
|
852
811
|
logInfo3("Waiting for iOS devices...");
|
|
812
|
+
const onAdd = this.manager.onDeviceConnected.bind(this.manager);
|
|
813
|
+
const onRemove = this.manager.onDeviceDisconnected.bind(this.manager);
|
|
814
|
+
return {
|
|
815
|
+
onAdd,
|
|
816
|
+
onRemove
|
|
817
|
+
};
|
|
853
818
|
} catch (error) {
|
|
854
819
|
logError("Failed to start USB listener:", error);
|
|
855
820
|
throw error;
|
|
821
|
+
} finally {
|
|
822
|
+
process.on("exit", () => {
|
|
823
|
+
this.stop();
|
|
824
|
+
});
|
|
825
|
+
process.on("SIGINT", () => {
|
|
826
|
+
this.stop();
|
|
827
|
+
});
|
|
828
|
+
process.on("SIGTERM", () => {
|
|
829
|
+
this.stop();
|
|
830
|
+
});
|
|
831
|
+
process.on("uncaughtException", (error) => {
|
|
832
|
+
logError("Uncaught exception:", error);
|
|
833
|
+
this.stop();
|
|
834
|
+
});
|
|
835
|
+
process.on("unhandledRejection", (error) => {
|
|
836
|
+
logError("Unhandled rejection:", error);
|
|
837
|
+
this.stop();
|
|
838
|
+
});
|
|
856
839
|
}
|
|
857
840
|
}
|
|
858
841
|
/**
|
|
@@ -864,7 +847,6 @@ var UsbmuxdService = class extends import_node_events2.EventEmitter {
|
|
|
864
847
|
return;
|
|
865
848
|
}
|
|
866
849
|
logInfo3("Stopping service...");
|
|
867
|
-
this.usbListener.stopListening();
|
|
868
850
|
this.isListening = false;
|
|
869
851
|
await this.manager.stop();
|
|
870
852
|
logInfo3("Service stopped");
|
package/dist/index.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/index.ts", "../src/UsbmuxdService.ts", "../src/InstanceManager.ts", "../src/usbipd.ts", "../src/wsl.ts"],
|
|
4
|
-
"sourcesContent": ["export { UsbmuxdService } from \"./UsbmuxdService.js\";\nexport { InstanceManager } from \"./InstanceManager.js\";\nexport type {\n\tInstanceManagerConfig,\n\tUsbmuxdInstance,\n\tDeviceInfo,\n\tDeviceMapping,\n\tManagerStats,\n} from \"./types/index.js\";\n", "import { EventEmitter } from \"node:events\";\nimport { createLoggers } from \"@mcesystems/tool-debug-g4\";\nimport UsbDeviceListener from \"@mcesystems/usb-device-listener\";\nimport type { DeviceInfo } from \"@mcesystems/usb-device-listener\";\nimport { InstanceManager } from \"./InstanceManager.js\";\nimport type { DeviceMapping, InstanceManagerConfig, UsbmuxdInstance } from \"./types/index.js\";\n\nconst { logInfo, logError, logDataObject } = createLoggers(\"usbmuxd-service\");\n\n/**\n * Main service that integrates usb-device-listener with InstanceManager\n * Monitors iOS devices and manages usbmuxd instances automatically.\n * Extends EventEmitter: forwards instance-started, instance-stopped, device-assigned,\n * device-removed, instance-log, instance-exited from the underlying manager.\n */\nexport class UsbmuxdService extends EventEmitter {\n\tprivate manager: InstanceManager;\n\tprivate usbListener: UsbDeviceListener;\n\tprivate isListening = false;\n\n\tconstructor(config: Partial<InstanceManagerConfig> = {}) {\n\t\tsuper();\n\t\tthis.manager = new InstanceManager(config);\n\t\tthis.usbListener = new UsbDeviceListener();\n\t\tthis.setupEventHandlers();\n\t}\n\n\t/**\n\t * Forward manager events to service subscribers (no logging; CLI/examples handle logging).\n\t */\n\tprivate setupEventHandlers(): void {\n\t\tthis.manager.on(\"instance-started\", (instance: UsbmuxdInstance) => {\n\t\t\tthis.emit(\"instance-started\", instance);\n\t\t});\n\n\t\tthis.manager.on(\"instance-stopped\", (instance: UsbmuxdInstance) => {\n\t\t\tthis.emit(\"instance-stopped\", instance);\n\t\t});\n\n\t\tthis.manager.on(\n\t\t\t\"device-assigned\",\n\t\t\t(payload: { device: DeviceInfo; instance: UsbmuxdInstance; mapping: DeviceMapping }) => {\n\t\t\t\tlogInfo(\n\t\t\t\t\t`Device ${payload.device.deviceId} connected to usbmuxd instance at ${payload.mapping.host}:${payload.mapping.port}`\n\t\t\t\t);\n\t\t\t\tthis.emit(\"device-assigned\", payload);\n\t\t\t}\n\t\t);\n\n\t\tthis.manager.on(\n\t\t\t\"device-removed\",\n\t\t\t(payload: { device: DeviceInfo; instance: UsbmuxdInstance }) => {\n\t\t\t\tthis.emit(\"device-removed\", payload);\n\t\t\t}\n\t\t);\n\n\t\tthis.manager.on(\n\t\t\t\"instance-log\",\n\t\t\t(payload: { instanceId: number; level: string; message: string }) => {\n\t\t\t\tthis.emit(\"instance-log\", payload);\n\t\t\t}\n\t\t);\n\n\t\tthis.manager.on(\n\t\t\t\"instance-exited\",\n\t\t\t(payload: { instanceId: number; code: number | null; signal: string | null }) => {\n\t\t\t\tthis.emit(\"instance-exited\", payload);\n\t\t\t}\n\t\t);\n\n\t\tthis.manager.on(\"device-paired\", (payload: { udid: string; mapping: DeviceMapping }) => {\n\t\t\tthis.emit(\"device-paired\", payload);\n\t\t});\n\t}\n\n\t/**\n\t * Start the service\n\t * Begins monitoring for iOS devices\n\t */\n\tpublic start(): void {\n\t\tif (this.isListening) {\n\t\t\tthrow new Error(\"Service is already running\");\n\t\t}\n\n\t\tconst config = this.manager.getConfig();\n\n\t\t// Convert Apple VID from hex to decimal for comparison\n\t\tconst appleVid = Number.parseInt(config.appleVendorId, 16);\n\n\t\tlogDataObject(\"Starting service...\", { config });\n\n\t\t// Set up device listener callbacks\n\t\tthis.usbListener.onDeviceAdd(async (device: DeviceInfo) => {\n\t\t\t// Filter for Apple devices only\n\t\t\tif (device.vid !== appleVid) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tlogInfo(`Apple device connected: ${device.deviceId} (${device.deviceName || \"Unknown\"})`);\n\n\t\t\ttry {\n\t\t\t\tawait this.manager.onDeviceConnected(device);\n\t\t\t} catch (error) {\n\t\t\t\tlogError(\"Error handling device connection:\", error);\n\t\t\t}\n\t\t});\n\n\t\tthis.usbListener.onDeviceRemove(async (device: DeviceInfo) => {\n\t\t\t// Filter for Apple devices only\n\t\t\tif (device.vid !== appleVid) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tlogInfo(`Apple device disconnected: ${device.deviceId}`);\n\n\t\t\ttry {\n\t\t\t\tawait this.manager.onDeviceDisconnected(device);\n\t\t\t} catch (error) {\n\t\t\t\tlogError(\"Error handling device disconnection:\", error);\n\t\t\t}\n\t\t});\n\n\t\t// Start listening for USB events\n\t\ttry {\n\t\t\tthis.usbListener.startListening({\n\t\t\t\ttargetDevices: [], // Monitor all devices, we'll filter by VID\n\t\t\t});\n\n\t\t\tthis.isListening = true;\n\t\t\tthis.manager.start();\n\n\t\t\tlogInfo(\"Service started successfully\");\n\t\t\tlogInfo(\"Waiting for iOS devices...\");\n\t\t} catch (error) {\n\t\t\tlogError(\"Failed to start USB listener:\", error);\n\t\t\tthrow error;\n\t\t}\n\t}\n\n\t/**\n\t * Stop the service\n\t * Stops monitoring and terminates all instances\n\t */\n\tpublic async stop(): Promise<void> {\n\t\tif (!this.isListening) {\n\t\t\treturn;\n\t\t}\n\n\t\tlogInfo(\"Stopping service...\");\n\n\t\t// Stop USB listener\n\t\tthis.usbListener.stopListening();\n\t\tthis.isListening = false;\n\n\t\t// Stop all instances\n\t\tawait this.manager.stop();\n\n\t\tlogInfo(\"Service stopped\");\n\t}\n\n\t/**\n\t * Get device port mapping\n\t */\n\tpublic getDevicePort(udid: string): number | null {\n\t\treturn this.manager.getDevicePort(udid);\n\t}\n\n\t/**\n\t * Get all device mappings\n\t */\n\tpublic getDeviceMappings() {\n\t\treturn this.manager.getDeviceMappings();\n\t}\n\n\t/**\n\t * Get all running instances\n\t */\n\tpublic getInstances() {\n\t\treturn this.manager.getInstances();\n\t}\n\n\t/**\n\t * Get service statistics\n\t */\n\tpublic getStats() {\n\t\treturn this.manager.getStats();\n\t}\n\n\t/**\n\t * Get current configuration\n\t */\n\tpublic getConfig() {\n\t\treturn this.manager.getConfig();\n\t}\n}\n", "import type { ChildProcess } from \"node:child_process\";\nimport { EventEmitter } from \"node:events\";\nimport { createLoggers } from \"@mcesystems/tool-debug-g4\";\nimport type {\n\tDeviceInfo,\n\tDeviceMapping,\n\tInstanceManagerConfig,\n\tManagerStats,\n\tUsbmuxdInstance,\n} from \"./types/index.js\";\nimport { Usbipd } from \"./usbipd.js\";\nimport { Wsl2 } from \"./wsl.js\";\n\nconst { logWarning, logDetail, logDataObject, logTask } = createLoggers(\"instance-manager\");\n\n/**\n * Default configuration for the instance manager\n */\nconst DEFAULT_CONFIG: InstanceManagerConfig = {\n\tbatchSize: 4,\n\tbasePort: 27015,\n\tmaxInstances: 5,\n\tusbmuxdPath: \"usbmuxd\", // Path inside WSL2\n\twslDistribution: \"alpine-usbmuxd-build\", // Alpine WSL2 distribution name\n\tverboseLogging: true,\n\tappleVendorId: \"05AC\",\n};\n\n/**\n * Manages multiple usbmuxd instances with batch device allocation\n *\n * @example\n * const manager = new InstanceManager({\n * batchSize: 4,\n * basePort: 27015,\n * });\n *\n * manager.on('instance-started', (instance) => {\n * logInfo(`Instance ${instance.id} started on port ${instance.port}`);\n * });\n *\n * manager.start();\n */\nexport class InstanceManager extends EventEmitter {\n\t/** Map of usbmuxd instance IDs to instances */\n\tprivate instances: Map<number, UsbmuxdInstance> = new Map();\n\t/** Map of device IDs to device mappings host:port */\n\tprivate deviceMappings: Map<string, DeviceMapping> = new Map();\n\t/** Map of usbmuxd instance IDs to child processes running it on wsl2*/\n\tprivate processes: Map<number, ChildProcess> = new Map();\n\t/** Tracks which devices have been attached to WSL */\n\tprivate attachedDevices: Set<string> = new Set();\n\t/** Device IDs currently in the attach flow\n\t * (ignore disconnect until attach completes) */\n\tprivate pendingAttachDevices: Set<string> = new Set();\n\n\tprivate config: InstanceManagerConfig;\n\tprivate nextInstanceId = 1;\n\tprivate startedAt: Date | null = null;\n\tprivate isRunning = false;\n\n\tprivate wsl: Wsl2;\n\tprivate usbipd: Usbipd;\n\tconstructor(config: Partial<InstanceManagerConfig> = {}) {\n\t\tsuper();\n\t\tthis.config = { ...DEFAULT_CONFIG, ...config };\n\t\tthis.wsl = new Wsl2(this.config.wslDistribution);\n\t\tthis.usbipd = new Usbipd(process.env.USBIPD_PATH ?? \"usbipd\");\n\t}\n\n\t/**\n\t * Start the instance manager\n\t */\n\tpublic start(): void {\n\t\tif (this.isRunning) {\n\t\t\tthrow new Error(\"Instance manager is already running\");\n\t\t}\n\n\t\tthis.isRunning = true;\n\t\tthis.startedAt = new Date();\n\t}\n\n\t/**\n\t * Stop the instance manager and all instances\n\t */\n\tpublic async stop(): Promise<void> {\n\t\tif (!this.isRunning) {\n\t\t\treturn;\n\t\t}\n\n\t\tthis.isRunning = false;\n\n\t\t// Sync lockdown files from Alpine back to native Apple lockdown directory (before clearing mappings)\n\t\tconst udids = Array.from(this.deviceMappings.keys());\n\t\tawait this.wsl.syncFromAlpine(udids);\n\n\t\t// Detach all devices from WSL.\n\t\t// If you only called unbind without detach,\n\t\t// the device might still be attached to the WSL session\n\t\tawait this.usbipd.detachAllDevicesFromWsl();\n\t\tawait this.usbipd.unbindAllDevicesFromWsl();\n\t\tthis.attachedDevices.clear();\n\n\t\t// Stop all instances\n\t\tconst stopPromises = Array.from(this.instances.keys()).map((id) => this.stopInstance(id));\n\n\t\tawait Promise.all(stopPromises);\n\n\t\tthis.instances.clear();\n\t\tthis.deviceMappings.clear();\n\t\tthis.processes.clear();\n\t}\n\n\tprivate async attachToWsl({\n\t\tbusId,\n\t\tdeviceId,\n\t}: { busId: string; deviceId: string }): Promise<void> {\n\t\tif (!this.attachedDevices.has(busId)) {\n\t\t\tthis.pendingAttachDevices.add(deviceId);\n\t\t\tif (!this.config.wslDistribution) {\n\t\t\t\tthrow new Error(\"WSL distribution not configured\");\n\t\t\t}\n\t\t\tconst attached = await this.usbipd.attachDeviceToWsl(\n\t\t\t\tbusId,\n\t\t\t\tthis.wsl,\n\t\t\t\tthis.config.wslDistribution\n\t\t\t);\n\t\t\tif (attached) {\n\t\t\t\tthis.attachedDevices.add(busId);\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate async removeDevice(mapping: DeviceMapping): Promise<UsbmuxdInstance> {\n\t\tconst instance = await this.detachFromWsl({ deviceId: mapping.udid });\n\t\tif (!instance) {\n\t\t\tthrow new Error(`Instance ${mapping.instanceId} not found`);\n\t\t}\n\t\tif (mapping.busId) {\n\t\t\tawait this.usbipd.detachDeviceFromWsl(mapping.busId);\n\t\t\tthis.attachedDevices.delete(mapping.busId);\n\t\t}\n\t\tconst deviceIndex = instance.deviceUdids.indexOf(mapping.udid);\n\t\tif (deviceIndex > -1) {\n\t\t\tinstance.deviceUdids.splice(deviceIndex, 1);\n\t\t}\n\n\t\tthis.deviceMappings.delete(mapping.udid);\n\t\treturn instance;\n\t}\n\n\tprivate async onUsbmuxdInstanceEnd({\n\t\tinstanceId,\n\t\tcode,\n\t\tsignal,\n\t}: { instanceId: number; code: number; signal: string }): Promise<void> {\n\t\tthis.emit(\"instance-exited\", {\n\t\t\tinstanceId,\n\t\t\tcode,\n\t\t\tsignal,\n\t\t});\n\t\tfor (const [_, mapping] of this.deviceMappings.entries()) {\n\t\t\tif (mapping.instanceId === instanceId) {\n\t\t\t\tthis.removeDevice(mapping);\n\t\t\t}\n\t\t}\n\t\tthis.instances.delete(instanceId);\n\t\tthis.processes.get(instanceId)?.kill();\n\t\tthis.processes.delete(instanceId);\n\t}\n\n\tprivate async onUsbmuxdInstanceStart({\n\t\tinstance,\n\t\tprocess,\n\t}: { instance: UsbmuxdInstance; process: ChildProcess }): Promise<void> {\n\t\tthis.instances.set(instance.id, instance);\n\t\tthis.processes.set(instance.id, process);\n\t\tthis.emit(\"instance-started\", {\n\t\t\tinstanceId: instance.id,\n\t\t});\n\t}\n\n\tprivate async getInstance() {\n\t\tlet targetInstance = this.findInstanceWithCapacity();\n\n\t\t// If no instance has capacity, create a new one\n\t\tif (!targetInstance) {\n\t\t\tif (this.instances.size >= this.config.maxInstances) {\n\t\t\t\tthrow new Error(`Maximum number of instances (${this.config.maxInstances}) reached`);\n\t\t\t}\n\n\t\t\tconst newInstanceId = this.nextInstanceId++;\n\n\t\t\tlet onExit = (code: number, signal: string) => {\n\t\t\t\tthis.onUsbmuxdInstanceEnd({ instanceId: newInstanceId, code, signal });\n\t\t\t};\n\n\t\t\tonExit = onExit.bind(this);\n\n\t\t\tconst { instance, process } = await this.wsl.createInstance({\n\t\t\t\tid: newInstanceId,\n\t\t\t\tbasePort: this.config.basePort,\n\t\t\t\tverboseLogging: this.config.verboseLogging,\n\t\t\t\tusbmuxdPath: this.config.usbmuxdPath,\n\t\t\t\tonLog: (message) =>\n\t\t\t\t\tthis.emit(\"instance-log\", {\n\t\t\t\t\t\tinstanceId: newInstanceId,\n\t\t\t\t\t\tlevel: \"info\",\n\t\t\t\t\t\tmessage,\n\t\t\t\t\t}),\n\t\t\t\tonExit,\n\t\t\t});\n\t\t\tthis.onUsbmuxdInstanceStart({ instance, process });\n\t\t\ttargetInstance = instance;\n\t\t}\n\t\treturn targetInstance;\n\t}\n\n\t/**\n\t * Handle device connection only for not attached devices\n\t * Attaches device to WSL, then assigns to an existing instance or creates a new one\n\t */\n\tpublic async onDeviceConnected(device: DeviceInfo): Promise<void> {\n\t\tconst busId = await this.usbipd.findBusIdForDevice(device);\n\n\t\tif (this.attachedDevices.has(busId)) {\n\t\t\tlogTask(`Device ${device.deviceId} is already attached. skipping onDeviceConnected...`);\n\t\t\treturn;\n\t\t}\n\n\t\tlogDataObject(\"Device connected\", { device });\n\t\tawait this.wsl.syncToAlpine(device.deviceId);\n\n\t\tawait this.attachToWsl({ busId, deviceId: device.deviceId });\n\n\t\tconst targetInstance = await this.getInstance();\n\n\t\t// Create mapping (include host and busId for cleanup on disconnect)\n\t\tconst mapping: DeviceMapping = {\n\t\t\tudid: device.deviceId,\n\t\t\tinstanceId: targetInstance.id,\n\t\t\thost: targetInstance.host,\n\t\t\tport: targetInstance.port,\n\t\t\taddedAt: new Date(),\n\t\t\tbusId: busId ?? undefined,\n\t\t};\n\n\t\tthis.deviceMappings.set(device.deviceId, mapping);\n\n\t\t// Add device to instance\n\t\ttargetInstance.deviceUdids.push(device.deviceId);\n\n\t\tthis.emit(\"device-assigned\", {\n\t\t\tdevice,\n\t\t\tinstance: targetInstance,\n\t\t\tmapping,\n\t\t});\n\n\t\tthis.pendingAttachDevices.delete(device.deviceId);\n\t}\n\n\tprivate async detachFromWsl({ deviceId }: { deviceId: string }): Promise<UsbmuxdInstance> {\n\t\tconst mapping = this.deviceMappings.get(deviceId);\n\t\tif (!mapping) {\n\t\t\tthrow new Error(`Device ${deviceId} was not tracked`);\n\t\t}\n\n\t\t// Detach device from WSL if it was attached\n\t\tif (mapping.busId) {\n\t\t\tawait this.usbipd.detachDeviceFromWsl(mapping.busId);\n\t\t\tthis.attachedDevices.delete(mapping.busId);\n\t\t}\n\n\t\tconst instance = this.instances.get(mapping.instanceId);\n\t\tif (!instance) {\n\t\t\tlogWarning(`Instance ${mapping.instanceId} not found`);\n\t\t\tthis.deviceMappings.delete(deviceId);\n\t\t\tthrow new Error(`Instance ${mapping.instanceId} not found`);\n\t\t}\n\n\t\treturn instance;\n\t}\n\n\t/**\n\t * Handle device disconnection only for attached devices\n\t * Detaches from WSL, removes device from instance, and stops instance if empty\n\t */\n\tpublic async onDeviceDisconnected(device: DeviceInfo): Promise<void> {\n\t\t// Ignore disconnect while we're still attaching this device (Windows sees disconnect when device moves to WSL)\n\t\tif (!this.attachedDevices.has(device.deviceId)) {\n\t\t\tlogTask(`Device ${device.deviceId} is not attached. skipping onDeviceDisconnected...`);\n\t\t\treturn;\n\t\t}\n\t\tlogDataObject(\"Device disconnected\", { device });\n\n\t\tconst mapping = this.deviceMappings.get(device.deviceId);\n\t\tif (!mapping) {\n\t\t\tthrow new Error(`Device ${device.deviceId} was not tracked`);\n\t\t}\n\t\t// Remove device from instance\n\t\tconst instance = await this.removeDevice(mapping);\n\n\t\tthis.emit(\"device-removed\", {\n\t\t\tdevice,\n\t\t\tinstance,\n\t\t});\n\n\t\t// If instance is now empty, stop it\n\t\tif (instance.deviceUdids.length === 0) {\n\t\t\tlogDetail(`Instance ${instance.id} is empty, stopping...`);\n\t\t\tawait this.stopInstance(instance.id);\n\t\t}\n\t}\n\n\t/**\n\t * Find an instance with available capacity\n\t */\n\tprivate findInstanceWithCapacity(): UsbmuxdInstance | null {\n\t\tfor (const instance of this.instances.values()) {\n\t\t\tif (instance.deviceUdids.length < this.config.batchSize) {\n\t\t\t\treturn instance;\n\t\t\t}\n\t\t}\n\t\treturn null;\n\t}\n\n\t/**\n\t * Stop a specific instance\n\t */\n\tprivate async stopInstance(instanceId: number): Promise<void> {\n\t\tconst instance = this.instances.get(instanceId);\n\t\tconst childProcess = this.processes.get(instanceId);\n\n\t\tif (!instance || !childProcess) {\n\t\t\treturn;\n\t\t}\n\n\t\tfor (const process of this.processes.values()) {\n\t\t\tprocess.kill(\"SIGKILL\");\n\t\t}\n\n\t\t// Clean up\n\t\tthis.instances.delete(instanceId);\n\t\tthis.processes.delete(instanceId);\n\n\t\t// Remove device mappings\n\t\tfor (const [udid, mapping] of this.deviceMappings.entries()) {\n\t\t\tif (mapping.instanceId === instanceId) {\n\t\t\t\tthis.deviceMappings.delete(udid);\n\t\t\t}\n\t\t}\n\n\t\tthis.emit(\"instance-stopped\", instance);\n\t}\n\n\t/**\n\t * Get device-to-port mapping for a specific UDID\n\t */\n\tpublic getDevicePort(udid: string): number | null {\n\t\tconst mapping = this.deviceMappings.get(udid);\n\t\treturn mapping ? mapping.port : null;\n\t}\n\n\t/**\n\t * Get all device mappings\n\t */\n\tpublic getDeviceMappings(): DeviceMapping[] {\n\t\treturn Array.from(this.deviceMappings.values());\n\t}\n\n\t/**\n\t * Get all running instances\n\t */\n\tpublic getInstances(): UsbmuxdInstance[] {\n\t\treturn Array.from(this.instances.values());\n\t}\n\n\t/**\n\t * Get manager statistics\n\t */\n\tpublic getStats(): ManagerStats {\n\t\tconst now = Date.now();\n\t\tconst startTime = this.startedAt?.getTime() || now;\n\t\tconst uptimeSeconds = Math.floor((now - startTime) / 1000);\n\n\t\treturn {\n\t\t\tinstanceCount: this.instances.size,\n\t\t\tdeviceCount: this.deviceMappings.size,\n\t\t\tuptimeSeconds,\n\t\t\tstartedAt: this.startedAt || new Date(),\n\t\t};\n\t}\n\n\t/**\n\t * Get current configuration\n\t */\n\tpublic getConfig(): InstanceManagerConfig {\n\t\treturn { ...this.config };\n\t}\n}\n", "import { exec } from \"node:child_process\";\nimport { promisify } from \"node:util\";\nimport { createLoggers } from \"@mcesystems/tool-debug-g4\";\nimport type { DeviceInfo } from \"./types\";\nimport type { UsbipdDevice } from \"./types/usbipd.js\";\nimport type { Wsl2 } from \"./wsl.js\";\n\nconst { logInfo, logWarning } = createLoggers(\"usbipd\");\n\nconst execAsync = promisify(exec);\n\nexport class Usbipd {\n\tconstructor(private readonly usbipdPath: string) {}\n\n\tpublic async unbindAllDevicesFromWsl(): Promise<void> {\n\t\ttry {\n\t\t\tawait execAsync(`\"${this.usbipdPath}\" unbind -a`);\n\t\t\tlogInfo(\"All devices unbound from WSL\");\n\t\t} catch (error) {\n\t\t\tlogWarning(`Failed to unbind all devices from WSL: ${error}`);\n\t\t}\n\t}\n\n\tpublic async detachAllDevicesFromWsl(): Promise<void> {\n\t\ttry {\n\t\t\tawait execAsync(`\"${this.usbipdPath}\" detach -a`);\n\t\t\tlogInfo(\"All devices detached from WSL\");\n\t\t} catch (error) {\n\t\t\tlogWarning(`Failed to detach all devices from WSL: ${error}`);\n\t\t}\n\t}\n\n\t/**\n\t * Detach a device from WSL via usbipd\n\t */\n\tpublic async detachDeviceFromWsl(busId: string): Promise<void> {\n\t\ttry {\n\t\t\tawait execAsync(`\"${this.usbipdPath}\" detach --busid=${busId}`);\n\t\t\tlogInfo(`Device ${busId} detached from WSL`);\n\t\t} catch (error) {\n\t\t\tconst message = error instanceof Error ? error.message : String(error);\n\t\t\tif (message.includes(\"no device with busid\") || message.includes(\"There is no device\")) {\n\t\t\t\tlogInfo(`Device ${busId} already detached`);\n\t\t\t} else {\n\t\t\t\tlogWarning(`Failed to detach device ${busId}: ${error}`);\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Attach a device to WSL via usbipd\n\t * Note: This requires administrator privileges\n\t */\n\tpublic async attachDeviceToWsl(busId: string, wsl: Wsl2, distro: string): Promise<boolean> {\n\t\ttry {\n\t\t\t// Ensure WSL is running first\n\t\t\tawait wsl.ensureWslRunning();\n\n\t\t\t// Bind the device (make it shareable)\n\t\t\tlogInfo(`Binding device ${busId}...`);\n\t\t\tawait execAsync(`\"${this.usbipdPath}\" bind --busid ${busId} --force`);\n\n\t\t\t// Attach to WSL (use specific distro if configured, otherwise let usbipd pick)\n\t\t\tif (distro) {\n\t\t\t\tlogInfo(`Attaching device ${busId} to WSL distribution ${distro}...`);\n\t\t\t\tawait execAsync(`\"${this.usbipdPath}\" attach --wsl=${distro} --busid=${busId}`);\n\t\t\t} else {\n\t\t\t\tlogInfo(`Attaching device ${busId} to default WSL...`);\n\t\t\t\tawait execAsync(`\"${this.usbipdPath}\" attach --wsl --busid=${busId}`);\n\t\t\t}\n\n\t\t\tlogInfo(`Device ${busId} attached to WSL successfully`);\n\t\t\treturn true;\n\t\t} catch (error) {\n\t\t\tconst message = error instanceof Error ? error.message : String(error);\n\t\t\t// Device already attached (e.g. from a previous run) \u2014 treat as success so we still start usbmuxd\n\t\t\tif (message.includes(\"already attached to a client\")) {\n\t\t\t\tlogInfo(`Device ${busId} is already attached to WSL, continuing`);\n\t\t\t\treturn true;\n\t\t\t}\n\t\t\tlogWarning(`Failed to attach device ${busId} to WSL: ${error}`);\n\t\t\treturn false;\n\t\t}\n\t}\n\n\t/**\n\t * Parse usbipd list output to extract device information\n\t */\n\tprivate parseUsbipdList(output: string): UsbipdDevice[] {\n\t\tconst devices: UsbipdDevice[] = [];\n\t\t// Handle both \\r\\n and \\n line endings\n\t\tconst lines = output.split(/\\r?\\n/);\n\n\t\tfor (const line of lines) {\n\t\t\t// Format: \"4-5 05ac:12a8 Apple Mobile Device USB Composite Device Shared (forced)\"\n\t\t\t// More flexible regex: busid, vid:pid, then anything else\n\t\t\tconst match = line.match(/^(\\d+-\\d+)\\s+([0-9a-f]{4}):([0-9a-f]{4})\\s+(.+)$/i);\n\t\t\tif (match) {\n\t\t\t\t// Split the rest into description and state (state is the last word(s) after multiple spaces)\n\t\t\t\tconst rest = match[4].trim();\n\t\t\t\tconst stateMatch = rest.match(/^(.+?)\\s{2,}(\\S.*)$/);\n\t\t\t\tconst description = stateMatch ? stateMatch[1].trim() : rest;\n\t\t\t\tconst state = stateMatch ? stateMatch[2].trim() : \"Unknown\";\n\n\t\t\t\tdevices.push({\n\t\t\t\t\tbusId: match[1],\n\t\t\t\t\tvid: match[2].toUpperCase(),\n\t\t\t\t\tpid: match[3].toUpperCase(),\n\t\t\t\t\tdescription,\n\t\t\t\t\tstate,\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\n\t\treturn devices;\n\t}\n\t/**\n\t * Find the usbipd bus ID for a device by matching VID/PID\n\t */\n\tpublic async findBusIdForDevice(device: DeviceInfo): Promise<string> {\n\t\ttry {\n\t\t\tconst { stdout } = await execAsync(`\"${this.usbipdPath}\" list`);\n\t\t\tconst usbipdDevices = this.parseUsbipdList(stdout);\n\n\t\t\t// Convert device VID/PID to hex string for comparison\n\t\t\tconst deviceVid = device.vid.toString(16).toUpperCase().padStart(4, \"0\");\n\t\t\tconst devicePid = device.pid.toString(16).toUpperCase().padStart(4, \"0\");\n\n\t\t\tlogInfo(`Looking for device with VID:PID ${deviceVid}:${devicePid}`);\n\t\t\tlogInfo(`Found ${usbipdDevices.length} devices from usbipd list`);\n\n\t\t\t// Find matching device by VID/PID\n\t\t\tconst match = usbipdDevices.find((d) => d.vid === deviceVid && d.pid === devicePid);\n\n\t\t\tif (match) {\n\t\t\t\tlogInfo(\n\t\t\t\t\t`Found usbipd bus ID ${match.busId} for device ${device.deviceId} (${deviceVid}:${devicePid})`\n\t\t\t\t);\n\t\t\t\treturn match.busId;\n\t\t\t}\n\n\t\t\tthrow new Error(\n\t\t\t\t`Could not find usbipd bus ID for device ${device.deviceId} (${deviceVid}:${devicePid})`\n\t\t\t);\n\t\t} catch (error) {\n\t\t\tthrow new Error(`Failed to run usbipd list: ${error}`);\n\t\t}\n\t}\n}\n", "import { type ChildProcess, exec, spawn } from \"node:child_process\";\nimport { existsSync, mkdirSync } from \"node:fs\";\nimport { join } from \"node:path\";\nimport { promisify } from \"node:util\";\nimport { createLoggers } from \"@mcesystems/tool-debug-g4\";\nimport type { UsbmuxdInstance } from \"./types\";\n\nconst { logInfo, logWarning, logDetail } = createLoggers(\"wsl\");\n\nconst execAsync = promisify(exec);\n\nexport class Wsl2 {\n\tprivate readonly ALPINE_LOCKDOWN_DIR = \"/var/lib/lockdown\";\n\tprivate readonly SYSTEM_CONFIG_PLIST = \"SystemConfiguration.plist\";\n\n\tprivate wslIpAddress: string | null = null;\n\n\tconstructor(private wslDistribution: string | undefined) {}\n\n\t/**\n\t * Detect the WSL2 IP address for the configured distribution\n\t * This IP is needed to connect from Windows to services inside WSL\n\t */\n\tpublic async detectWslIpAddress(): Promise<string> {\n\t\tif (this.wslIpAddress) {\n\t\t\treturn this.wslIpAddress;\n\t\t}\n\n\t\tconst distro = this.wslDistribution || \"alpine-usbmuxd-build\";\n\n\t\ttry {\n\t\t\t// Try to get IP from eth0 interface\n\t\t\tconst { stdout } = await execAsync(`wsl -d ${distro} -- ip -4 addr show eth0`);\n\t\t\tconst match = stdout.match(/inet\\s+(\\d+\\.\\d+\\.\\d+\\.\\d+)/);\n\t\t\tif (match) {\n\t\t\t\tthis.wslIpAddress = match[1];\n\t\t\t\tlogInfo(`Detected WSL IP address: ${this.wslIpAddress}`);\n\t\t\t\treturn this.wslIpAddress;\n\t\t\t}\n\t\t} catch (error) {\n\t\t\tlogWarning(`Failed to detect WSL IP via ip addr: ${error}`);\n\t\t}\n\n\t\t// Fallback: try hostname -I\n\t\ttry {\n\t\t\tconst { stdout } = await execAsync(`wsl -d ${distro} -- hostname -I`);\n\t\t\tconst ip = stdout.trim().split(/\\s+/)[0];\n\t\t\tif (ip && /^\\d+\\.\\d+\\.\\d+\\.\\d+$/.test(ip)) {\n\t\t\t\tthis.wslIpAddress = ip;\n\t\t\t\tlogInfo(`Detected WSL IP address (hostname): ${this.wslIpAddress}`);\n\t\t\t\treturn this.wslIpAddress;\n\t\t\t}\n\t\t} catch (error) {\n\t\t\tlogWarning(`Failed to detect WSL IP via hostname: ${error}`);\n\t\t}\n\n\t\t// Last resort fallback - localhost (may work with WSL2 mirrored networking)\n\t\tlogWarning(\"Could not detect WSL IP, falling back to localhost\");\n\t\tthis.wslIpAddress = \"127.0.0.1\";\n\t\treturn this.wslIpAddress;\n\t}\n\n\t/**\n\t * Ensure the WSL distribution is running\n\t */\n\tpublic async ensureWslRunning(): Promise<boolean> {\n\t\tconst distro = this.wslDistribution;\n\n\t\ttry {\n\t\t\tif (distro) {\n\t\t\t\t// Start specific distribution\n\t\t\t\tlogInfo(`Starting WSL distribution: ${distro}...`);\n\t\t\t\tawait execAsync(`wsl -d ${distro} -- echo \"WSL started\"`);\n\t\t\t} else {\n\t\t\t\t// Start default WSL\n\t\t\t\tlogInfo(\"Starting default WSL distribution...\");\n\t\t\t\tawait execAsync(`wsl -- echo \"WSL started\"`);\n\t\t\t}\n\t\t\treturn true;\n\t\t} catch (error) {\n\t\t\tlogWarning(`Failed to start WSL: ${error}`);\n\t\t\treturn false;\n\t\t}\n\t}\n\n\t/**\n\t * Create a new usbmuxd instance\n\t */\n\tpublic async createInstance({\n\t\tid,\n\t\tbasePort,\n\t\tverboseLogging,\n\t\tusbmuxdPath,\n\t\tonLog,\n\t\tonExit,\n\t}: {\n\t\tid: number;\n\t\tbasePort: number;\n\t\tverboseLogging: boolean;\n\t\tusbmuxdPath: string;\n\t\tonLog: (message: string) => void;\n\t\tonExit: (code: number, signal: string) => void;\n\t}): Promise<{ instance: UsbmuxdInstance; process: ChildProcess }> {\n\t\tconst port = basePort + id - 1;\n\n\t\tlogInfo(`Creating instance ${id} on port ${port}`);\n\n\t\t// Detect WSL IP for connecting from Windows\n\t\tconst host = await this.detectWslIpAddress();\n\n\t\t// Build usbmuxd arguments\n\t\tconst usbmuxdArgs = [\n\t\t\t\"-f\", // Foreground\n\t\t\t\"-v\", // Verbose (if enabled)\n\t\t\t\"-S\",\n\t\t\t`0.0.0.0:${port}`, // Listen on all interfaces (for Windows \u2192 WSL2)\n\t\t\t\"--pidfile\",\n\t\t\t\"NONE\",\n\t\t];\n\n\t\tif (!verboseLogging) {\n\t\t\t// Remove -v if not verbose\n\t\t\tusbmuxdArgs.splice(1, 1);\n\t\t}\n\n\t\t// Build WSL command: wsl -d <distro> usbmuxd <args>\n\t\tconst wslArgs = [\n\t\t\t\"-d\",\n\t\t\tthis.wslDistribution || \"alpine-usbmuxd-build\",\n\t\t\tusbmuxdPath,\n\t\t\t...usbmuxdArgs,\n\t\t];\n\n\t\t// Spawn via WSL\n\t\t// detached: true creates a new process group so the child does NOT receive\n\t\t// the parent's Ctrl+C. Without this, Windows delivers SIGINT to every process\n\t\t// in the console, killing usbmuxd before stop() can sync lockdown files back.\n\t\t// windowsHide: true prevents the detached process from opening a visible console window.\n\t\tconst process = spawn(\"wsl\", wslArgs, {\n\t\t\tstdio: [\"ignore\", \"pipe\", \"pipe\"],\n\t\t\tdetached: true,\n\t\t\twindowsHide: false,\n\t\t});\n\n\t\t// Handle process output\n\t\tprocess.stdout?.on(\"data\", (data) => {\n\t\t\tonLog(data.toString().trim());\n\t\t});\n\n\t\tprocess.stderr?.on(\"data\", (data) => {\n\t\t\tonLog(data.toString().trim());\n\t\t});\n\n\t\t// Handle process exit\n\t\tprocess.on(\"exit\", onExit);\n\n\t\t// Create instance record (pid is set synchronously by Node after spawn)\n\t\tconst pid = process.pid;\n\t\tif (pid === undefined) {\n\t\t\tprocess.kill(\"SIGKILL\");\n\t\t\tthrow new Error(\"Failed to get PID for usbmuxd instance\");\n\t\t}\n\t\tconst instance: UsbmuxdInstance = {\n\t\t\tid,\n\t\t\thost,\n\t\t\tport,\n\t\t\tpid,\n\t\t\tdeviceUdids: [],\n\t\t\tstartedAt: new Date(),\n\t\t};\n\n\t\treturn { instance, process };\n\t}\n\n\t/**\n\t * Convert a Windows path to the equivalent path inside WSL (e.g. C:\\foo\\bar -> /mnt/c/foo/bar).\n\t */\n\tprivate windowsPathToWsl(windowsPath: string): string {\n\t\tconst normalized = windowsPath.replace(/\\\\/g, \"/\").trim();\n\t\tconst driveMatch = normalized.match(/^([a-zA-Z]):\\/?(.*)$/);\n\t\tif (driveMatch) {\n\t\t\tconst drive = driveMatch[1].toLowerCase();\n\t\t\tconst rest = driveMatch[2] || \"\";\n\t\t\treturn `/mnt/${drive}${rest ? `/${rest}` : \"\"}`;\n\t\t}\n\t\treturn normalized;\n\t}\n\n\t/**\n\t * Get the native Apple lockdown directory path for the current platform.\n\t * This is where Apple/iTunes stores pairing records natively.\n\t */\n\tprivate getAppleLockdownPath(): string | null {\n\t\tif (process.platform === \"win32\") {\n\t\t\treturn join(process.env.ProgramData ?? \"C:\\\\ProgramData\", \"Apple\", \"Lockdown\");\n\t\t}\n\t\tif (process.platform === \"darwin\") {\n\t\t\treturn \"/var/db/lockdown\";\n\t\t}\n\t\tif (process.platform === \"linux\") {\n\t\t\treturn \"/var/lib/lockdown\";\n\t\t}\n\t\treturn null;\n\t}\n\n\t/**\n\t * Copy a single device's lockdown plist from the native Apple lockdown directory\n\t * to Alpine so usbmuxd can use it (skip pairing).\n\t *\n\t * Uses the platform-specific Apple/iTunes lockdown directory\n\t * (e.g. C:\\ProgramData\\Apple\\Lockdown on Windows, /var/db/lockdown on macOS).\n\t *\n\t * No-op if the lockdown directory cannot be determined or files don't exist.\n\t */\n\tpublic async syncToAlpine(udid: string): Promise<void> {\n\t\tconst lockdownDir = this.getAppleLockdownPath();\n\t\tif (!lockdownDir) {\n\t\t\tlogWarning(\"Lockdown sync to Alpine: unsupported platform, skipping\");\n\t\t\treturn;\n\t\t}\n\n\t\tlogDetail(`Lockdown sync to Alpine: source dir = ${lockdownDir}, udid = ${udid}`);\n\n\t\tconst distro = this.wslDistribution || \"alpine-usbmuxd-build\";\n\t\tconst wslDestDir = this.ALPINE_LOCKDOWN_DIR;\n\n\t\t// Sync the device-specific plist\n\t\tconst devicePlistFile = `${udid}.plist`;\n\t\tconst devicePlistPath = join(lockdownDir, devicePlistFile);\n\t\tif (existsSync(devicePlistPath)) {\n\t\t\tawait this.copyFileToAlpine(\n\t\t\t\tthis.windowsPathToWsl(devicePlistPath),\n\t\t\t\twslDestDir,\n\t\t\t\tdistro,\n\t\t\t\tdevicePlistFile\n\t\t\t);\n\t\t} else {\n\t\t\tlogDetail(\n\t\t\t\t`Lockdown sync to Alpine: ${devicePlistFile} not found at ${devicePlistPath}, skipping`\n\t\t\t);\n\t\t}\n\n\t\t// Sync SystemConfiguration.plist so Alpine usbmuxd uses the same SystemBUID\n\t\t// that was used during the original pairing on Windows.\n\t\t// Without this, lockdown sessions fail with InvalidHostID.\n\t\tconst systemConfigPath = join(lockdownDir, this.SYSTEM_CONFIG_PLIST);\n\t\tif (existsSync(systemConfigPath)) {\n\t\t\tawait this.copyFileToAlpine(\n\t\t\t\tthis.windowsPathToWsl(systemConfigPath),\n\t\t\t\twslDestDir,\n\t\t\t\tdistro,\n\t\t\t\tthis.SYSTEM_CONFIG_PLIST\n\t\t\t);\n\t\t} else {\n\t\t\tlogDetail(\n\t\t\t\t`Lockdown sync to Alpine: ${this.SYSTEM_CONFIG_PLIST} not found at ${systemConfigPath}, skipping`\n\t\t\t);\n\t\t}\n\t}\n\n\t/**\n\t * Copy a single file into the Alpine lockdown directory.\n\t * Falls back to sudo if the initial copy fails.\n\t */\n\tprivate async copyFileToAlpine(\n\t\twslSource: string,\n\t\twslDestDir: string,\n\t\tdistro: string,\n\t\tfileName: string\n\t): Promise<void> {\n\t\ttry {\n\t\t\tawait execAsync(\n\t\t\t\t`wsl -d ${distro} -- sh -c \"mkdir -p ${wslDestDir} && cp '${wslSource}' '${wslDestDir}/'\"`\n\t\t\t);\n\t\t\tlogInfo(`Lockdown sync: copied ${fileName} to Alpine`);\n\t\t} catch (error) {\n\t\t\ttry {\n\t\t\t\tawait execAsync(\n\t\t\t\t\t`wsl -d ${distro} -- sh -c \"mkdir -p ${wslDestDir} && sudo cp '${wslSource}' '${wslDestDir}/'\"`\n\t\t\t\t);\n\t\t\t\tlogInfo(`Lockdown sync: copied ${fileName} to Alpine (via sudo)`);\n\t\t\t} catch (sudoError) {\n\t\t\t\tlogWarning(\n\t\t\t\t\t`Lockdown sync to Alpine failed for ${fileName}: ${error}. Sudo fallback failed: ${sudoError}. Ensure /var/lib/lockdown is writable or use passwordless sudo.`\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Copy lockdown plists from Alpine back to the native Apple lockdown directory\n\t * (for devices that were assigned this session).\n\t * Also copies SystemConfiguration.plist if present in Alpine.\n\t *\n\t * No-op if the lockdown directory cannot be determined.\n\t */\n\tpublic async syncFromAlpine(udids: string[]): Promise<void> {\n\t\tlogInfo(`Lockdown sync from Alpine: starting (${udids.length} device(s))`);\n\n\t\tconst lockdownDir = this.getAppleLockdownPath();\n\t\tif (!lockdownDir) {\n\t\t\tlogWarning(\"Lockdown sync: unsupported platform, skipping\");\n\t\t\treturn;\n\t\t}\n\n\t\tlogDetail(`Lockdown sync: target dir = ${lockdownDir}`);\n\n\t\ttry {\n\t\t\tmkdirSync(lockdownDir, { recursive: true });\n\t\t} catch (error) {\n\t\t\tlogWarning(`Lockdown sync: could not create lockdown dir ${lockdownDir}: ${error}`);\n\t\t\treturn;\n\t\t}\n\n\t\tconst distro = this.wslDistribution || \"alpine-usbmuxd-build\";\n\t\tconst wslDestDir = this.windowsPathToWsl(lockdownDir);\n\n\t\t// List what Alpine actually has in its lockdown dir for debugging\n\t\ttry {\n\t\t\tconst { stdout } = await execAsync(`wsl -d ${distro} -- ls -la ${this.ALPINE_LOCKDOWN_DIR}/`);\n\t\t\tlogDetail(`Lockdown sync: Alpine ${this.ALPINE_LOCKDOWN_DIR} contents:\\n${stdout}`);\n\t\t} catch (error) {\n\t\t\tlogWarning(`Lockdown sync: could not list Alpine lockdown dir: ${error}`);\n\t\t}\n\n\t\tconst filesToSync = [...udids.map((udid) => `${udid}.plist`), this.SYSTEM_CONFIG_PLIST];\n\n\t\tlogDetail(`Lockdown sync: files to sync = [${filesToSync.join(\", \")}]`);\n\n\t\tfor (const fileName of filesToSync) {\n\t\t\tawait this.copyFileFromAlpine(fileName, wslDestDir, distro, lockdownDir);\n\t\t}\n\n\t\tlogInfo(\"Lockdown sync from Alpine: done\");\n\t}\n\n\t/**\n\t * Copy a single file from the Alpine lockdown directory back to Windows.\n\t * Skips if the file does not exist in Alpine; logs a warning if the copy fails.\n\t */\n\tprivate async copyFileFromAlpine(\n\t\tfileName: string,\n\t\twslDestDir: string,\n\t\tdistro: string,\n\t\tlockdownDir: string\n\t): Promise<void> {\n\t\tconst alpinePath = `${this.ALPINE_LOCKDOWN_DIR}/${fileName}`;\n\n\t\t// Check if the file exists in Alpine first\n\t\ttry {\n\t\t\tawait execAsync(`wsl -d ${distro} -- test -f '${alpinePath}'`);\n\t\t} catch {\n\t\t\tlogDetail(`Lockdown sync: ${fileName} not found in Alpine (${alpinePath}), skipping`);\n\t\t\treturn;\n\t\t}\n\n\t\t// File exists \u2014 copy it to Windows\n\t\tlogDetail(`Lockdown sync: copying ${fileName} \u2192 ${wslDestDir}/`);\n\t\ttry {\n\t\t\tawait execAsync(`wsl -d ${distro} -- cp -f '${alpinePath}' '${wslDestDir}/'`);\n\t\t\tlogInfo(`Lockdown sync: copied ${fileName} from Alpine to ${lockdownDir}`);\n\t\t} catch (error) {\n\t\t\tlogWarning(`Lockdown sync: failed to copy ${fileName} from Alpine to ${lockdownDir}: ${error}`);\n\t\t}\n\t}\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,IAAAA,sBAA6B;AAC7B,IAAAC,wBAA8B;AAC9B,iCAA8B;;;ACD9B,yBAA6B;AAC7B,IAAAC,wBAA8B;;;ACF9B,gCAAqB;AACrB,uBAA0B;AAC1B,2BAA8B;AAK9B,IAAM,EAAE,SAAS,WAAW,QAAI,oCAAc,QAAQ;AAEtD,IAAM,gBAAY,4BAAU,8BAAI;AAEzB,IAAM,SAAN,MAAa;AAAA,EACnB,YAA6B,YAAoB;AAApB;AAAA,EAAqB;AAAA,EAElD,MAAa,0BAAyC;AACrD,QAAI;AACH,YAAM,UAAU,IAAI,KAAK,UAAU,aAAa;AAChD,cAAQ,8BAA8B;AAAA,IACvC,SAAS,OAAO;AACf,iBAAW,0CAA0C,KAAK,EAAE;AAAA,IAC7D;AAAA,EACD;AAAA,EAEA,MAAa,0BAAyC;AACrD,QAAI;AACH,YAAM,UAAU,IAAI,KAAK,UAAU,aAAa;AAChD,cAAQ,+BAA+B;AAAA,IACxC,SAAS,OAAO;A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Q,4BAA4B;AAAA,IACrC,SAAS,OAAO;AACf,eAAS,iCAAiC,KAAK;AAC/C,YAAM;AAAA,IACP;AAAA,EACD;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,MAAa,OAAsB;AAClC,QAAI,CAAC,KAAK,aAAa;AACtB;AAAA,IACD;AAEA,IAAAA,SAAQ,qBAAqB;AAG7B,SAAK,YAAY,cAAc;AAC/B,SAAK,cAAc;AAGnB,UAAM,KAAK,QAAQ,KAAK;AAExB,IAAAA,SAAQ,iBAAiB;AAAA,EAC1B;AAAA;AAAA;AAAA;AAAA,EAKO,cAAc,MAA6B;AACjD,WAAO,KAAK,QAAQ,cAAc,IAAI;AAAA,EACvC;AAAA;AAAA;AAAA;AAAA,EAKO,oBAAoB;AAC1B,WAAO,KAAK,QAAQ,kBAAkB;AAAA,EACvC;AAAA;AAAA;AAAA;AAAA,EAKO,eAAe;AACrB,WAAO,KAAK,QAAQ,aAAa;AAAA,EAClC;AAAA;AAAA;AAAA;AAAA,EAKO,WAAW;AACjB,WAAO,KAAK,QAAQ,SAAS;AAAA,EAC9B;AAAA;AAAA;AAAA;AAAA,EAKO,YAAY;AAClB,WAAO,KAAK,QAAQ,UAAU;AAAA,EAC/B;AACD;",
|
|
6
|
-
"names": ["import_node_events", "import_tool_debug_g4", "import_tool_debug_g4", "import_node_child_process", "import_node_util", "import_tool_debug_g4", "logInfo", "logWarning", "execAsync", "process", "logWarning", "
|
|
4
|
+
"sourcesContent": ["export { UsbmuxdService } from \"./UsbmuxdService.js\";\nexport { InstanceManager } from \"./InstanceManager.js\";\nexport type {\n\tInstanceManagerConfig,\n\tUsbmuxdInstance,\n\tDeviceInfo,\n\tDeviceMapping,\n\tManagerStats,\n} from \"./types/index.js\";\n", "import { EventEmitter } from \"node:events\";\nimport { createLoggers } from \"@mcesystems/tool-debug-g4\";\nimport type { DeviceInfo } from \"@mcesystems/usb-device-listener\";\nimport { InstanceManager } from \"./InstanceManager.js\";\nimport type { DeviceMapping, InstanceManagerConfig, UsbmuxdInstance } from \"./types/index.js\";\n\nconst { logInfo, logError, logDataObject } = createLoggers(\"usbmuxd-service\");\n\n/**\n * Main service that integrates usb-device-listener with InstanceManager\n * Monitors iOS devices and manages usbmuxd instances automatically.\n * Extends EventEmitter: forwards instance-started, instance-stopped, device-assigned,\n * device-removed, instance-log, instance-exited from the underlying manager.\n */\nexport class UsbmuxdService extends EventEmitter {\n\tprivate manager: InstanceManager;\n\tprivate isListening = false;\n\n\tconstructor(config: Partial<InstanceManagerConfig> = {}) {\n\t\tsuper();\n\t\tthis.manager = new InstanceManager(config);\n\t\tthis.setupEventHandlers();\n\t}\n\n\t/**\n\t * Forward manager events to service subscribers (no logging; CLI/examples handle logging).\n\t */\n\tprivate setupEventHandlers(): void {\n\t\tthis.manager.on(\"instance-started\", (instance: UsbmuxdInstance) => {\n\t\t\tthis.emit(\"instance-started\", instance);\n\t\t});\n\n\t\tthis.manager.on(\"instance-stopped\", (instance: UsbmuxdInstance) => {\n\t\t\tthis.emit(\"instance-stopped\", instance);\n\t\t});\n\n\t\tthis.manager.on(\n\t\t\t\"device-assigned\",\n\t\t\t(payload: { device: DeviceInfo; instance: UsbmuxdInstance; mapping: DeviceMapping }) => {\n\t\t\t\tlogInfo(\n\t\t\t\t\t`Device ${payload.device.deviceId} connected to usbmuxd instance at ${payload.mapping.host}:${payload.mapping.port}`\n\t\t\t\t);\n\t\t\t\tthis.emit(\"device-assigned\", payload);\n\t\t\t}\n\t\t);\n\n\t\tthis.manager.on(\n\t\t\t\"device-removed\",\n\t\t\t(payload: { device: DeviceInfo; instance: UsbmuxdInstance }) => {\n\t\t\t\tthis.emit(\"device-removed\", payload);\n\t\t\t}\n\t\t);\n\n\t\tthis.manager.on(\n\t\t\t\"instance-log\",\n\t\t\t(payload: { instanceId: number; level: string; message: string }) => {\n\t\t\t\tthis.emit(\"instance-log\", payload);\n\t\t\t}\n\t\t);\n\n\t\tthis.manager.on(\n\t\t\t\"instance-exited\",\n\t\t\t(payload: { instanceId: number; code: number | null; signal: string | null }) => {\n\t\t\t\tthis.emit(\"instance-exited\", payload);\n\t\t\t}\n\t\t);\n\n\t\tthis.manager.on(\"device-paired\", (payload: { udid: string; mapping: DeviceMapping }) => {\n\t\t\tthis.emit(\"device-paired\", payload);\n\t\t});\n\t}\n\n\t/**\n\t * Start the service\n\t * Begins monitoring for iOS devices\n\t */\n\tpublic start() {\n\t\tif (this.isListening) {\n\t\t\tthrow new Error(\"Service is already running\");\n\t\t}\n\n\t\tconst config = this.manager.getConfig();\n\n\t\tlogDataObject(\"Starting service...\", { config });\n\n\t\t// Start listening for USB events\n\t\ttry {\n\t\t\tthis.isListening = true;\n\t\t\tthis.manager.start();\n\n\t\t\tlogInfo(\"Service started successfully\");\n\t\t\tlogInfo(\"Waiting for iOS devices...\");\n\t\t\tconst onAdd = this.manager.onDeviceConnected.bind(this.manager);\n\t\t\tconst onRemove = this.manager.onDeviceDisconnected.bind(this.manager);\n\t\t\treturn {\n\t\t\t\tonAdd,\n\t\t\t\tonRemove,\n\t\t\t};\n\t\t} catch (error) {\n\t\t\tlogError(\"Failed to start USB listener:\", error);\n\t\t\tthrow error;\n\t\t} finally {\n\t\t\tprocess.on(\"exit\", () => {\n\t\t\t\tthis.stop();\n\t\t\t});\n\t\t\tprocess.on(\"SIGINT\", () => {\n\t\t\t\tthis.stop();\n\t\t\t});\n\t\t\tprocess.on(\"SIGTERM\", () => {\n\t\t\t\tthis.stop();\n\t\t\t});\n\t\t\tprocess.on(\"uncaughtException\", (error) => {\n\t\t\t\tlogError(\"Uncaught exception:\", error);\n\t\t\t\tthis.stop();\n\t\t\t});\n\t\t\tprocess.on(\"unhandledRejection\", (error) => {\n\t\t\t\tlogError(\"Unhandled rejection:\", error);\n\t\t\t\tthis.stop();\n\t\t\t});\n\t\t}\n\t}\n\n\t/**\n\t * Stop the service\n\t * Stops monitoring and terminates all instances\n\t */\n\tpublic async stop(): Promise<void> {\n\t\tif (!this.isListening) {\n\t\t\treturn;\n\t\t}\n\n\t\tlogInfo(\"Stopping service...\");\n\n\t\tthis.isListening = false;\n\n\t\t// Stop all instances\n\t\tawait this.manager.stop();\n\n\t\tlogInfo(\"Service stopped\");\n\t}\n\n\t/**\n\t * Get device port mapping\n\t */\n\tpublic getDevicePort(udid: string): number | null {\n\t\treturn this.manager.getDevicePort(udid);\n\t}\n\n\t/**\n\t * Get all device mappings\n\t */\n\tpublic getDeviceMappings() {\n\t\treturn this.manager.getDeviceMappings();\n\t}\n\n\t/**\n\t * Get all running instances\n\t */\n\tpublic getInstances() {\n\t\treturn this.manager.getInstances();\n\t}\n\n\t/**\n\t * Get service statistics\n\t */\n\tpublic getStats() {\n\t\treturn this.manager.getStats();\n\t}\n\n\t/**\n\t * Get current configuration\n\t */\n\tpublic getConfig() {\n\t\treturn this.manager.getConfig();\n\t}\n}\n", "import type { ChildProcess } from \"node:child_process\";\nimport { EventEmitter } from \"node:events\";\nimport { createLoggers } from \"@mcesystems/tool-debug-g4\";\nimport type {\n\tDeviceInfo,\n\tDeviceMapping,\n\tInstanceManagerConfig,\n\tManagerStats,\n\tUsbmuxdInstance,\n} from \"./types/index.js\";\nimport { Usbipd } from \"./usbipd.js\";\nimport { Wsl2 } from \"./wsl.js\";\n\nconst { logWarning, logDataObject, logTask } = createLoggers(\"instance-manager\");\n\n/**\n * Default configuration for the instance manager\n */\nconst DEFAULT_CONFIG: InstanceManagerConfig = {\n\tbatchSize: 4,\n\tbasePort: 27015,\n\tmaxInstances: 5,\n\tusbmuxdPath: \"usbmuxd\", // Path inside WSL2\n\twslDistribution: \"alpine-usbmuxd-build\", // Alpine WSL2 distribution name\n\tverboseLogging: true,\n\tappleVendorId: \"05AC\",\n};\n\n/**\n * Manages multiple usbmuxd instances with batch device allocation\n *\n * @example\n * const manager = new InstanceManager({\n * batchSize: 4,\n * basePort: 27015,\n * });\n *\n * manager.on('instance-started', (instance) => {\n * logInfo(`Instance ${instance.id} started on port ${instance.port}`);\n * });\n *\n * manager.start();\n */\nexport class InstanceManager extends EventEmitter {\n\t/** Map of usbmuxd instance IDs to instances */\n\tprivate instances: Map<number, UsbmuxdInstance> = new Map();\n\t/** Map of device IDs to device mappings host:port */\n\tprivate deviceMappings: Map<string, DeviceMapping> = new Map();\n\t/** Map of usbmuxd instance IDs to child processes running it on wsl2*/\n\tprivate processes: Map<number, ChildProcess> = new Map();\n\t/** Tracks which devices have been attached to WSL */\n\tprivate attachedDevices: Set<string> = new Set();\n\t/** Device IDs currently in the attach flow\n\t * (ignore disconnect until attach completes) */\n\tprivate pendingAttachDevices: Set<string> = new Set();\n\n\tprivate config: InstanceManagerConfig;\n\tprivate nextInstanceId = 1;\n\tprivate startedAt: Date | null = null;\n\tprivate isRunning = false;\n\n\tprivate wsl: Wsl2;\n\tprivate usbipd: Usbipd;\n\tconstructor(config: Partial<InstanceManagerConfig> = {}) {\n\t\tsuper();\n\t\tthis.config = { ...DEFAULT_CONFIG, ...config };\n\t\tthis.wsl = new Wsl2(this.config.wslDistribution);\n\t\tthis.usbipd = new Usbipd(process.env.USBIPD_PATH ?? \"usbipd\");\n\t}\n\n\t/**\n\t * Start the instance manager\n\t */\n\tpublic start(): void {\n\t\tif (this.isRunning) {\n\t\t\tthrow new Error(\"Instance manager is already running\");\n\t\t}\n\n\t\tfor (let i = 0; i < this.config.maxInstances; i++) {\n\t\t\tthis.createInstance(i + 1);\n\t\t}\n\n\t\tthis.isRunning = true;\n\t\tthis.startedAt = new Date();\n\t}\n\n\t/**\n\t * Stop the instance manager and all instances\n\t */\n\tpublic async stop(): Promise<void> {\n\t\tif (!this.isRunning) {\n\t\t\treturn;\n\t\t}\n\n\t\tthis.isRunning = false;\n\n\t\t// Sync lockdown files from Alpine back to native Apple lockdown directory (before clearing mappings)\n\t\tconst udids = Array.from(this.deviceMappings.keys());\n\t\tawait this.wsl.syncFromAlpine(udids);\n\n\t\t// Detach all devices from WSL.\n\t\t// If you only called unbind without detach,\n\t\t// the device might still be attached to the WSL session\n\t\tawait this.usbipd.detachAllDevicesFromWsl();\n\t\tawait this.usbipd.unbindAllDevicesFromWsl();\n\t\tthis.attachedDevices.clear();\n\n\t\t// Stop all instances\n\t\tconst stopPromises = Array.from(this.instances.keys()).map((id) => this.stopInstance(id));\n\n\t\tawait Promise.all(stopPromises);\n\n\t\tthis.instances.clear();\n\t\tthis.deviceMappings.clear();\n\t\tthis.processes.clear();\n\t}\n\n\tprivate async attachToWsl({\n\t\tbusId,\n\t\tdeviceId,\n\t}: { busId: string; deviceId: string }): Promise<void> {\n\t\tif (!this.attachedDevices.has(busId)) {\n\t\t\tthis.pendingAttachDevices.add(deviceId);\n\t\t\tif (!this.config.wslDistribution) {\n\t\t\t\tthrow new Error(\"WSL distribution not configured\");\n\t\t\t}\n\t\t\tconst attached = await this.usbipd.attachDeviceToWsl(\n\t\t\t\tbusId,\n\t\t\t\tthis.wsl,\n\t\t\t\tthis.config.wslDistribution\n\t\t\t);\n\t\t\tif (attached) {\n\t\t\t\tthis.attachedDevices.add(busId);\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate async removeDevice(mapping: DeviceMapping): Promise<UsbmuxdInstance> {\n\t\tconst instance = await this.detachFromWsl({ deviceId: mapping.udid });\n\t\tif (!instance) {\n\t\t\tthrow new Error(`Instance ${mapping.instanceId} not found`);\n\t\t}\n\t\tif (mapping.busId) {\n\t\t\tawait this.usbipd.detachDeviceFromWsl(mapping.busId);\n\t\t\tthis.attachedDevices.delete(mapping.busId);\n\t\t}\n\t\tconst deviceIndex = instance.deviceUdids.indexOf(mapping.udid);\n\t\tif (deviceIndex > -1) {\n\t\t\tinstance.deviceUdids.splice(deviceIndex, 1);\n\t\t}\n\n\t\tthis.deviceMappings.delete(mapping.udid);\n\t\treturn instance;\n\t}\n\n\tprivate async onUsbmuxdInstanceEnd({\n\t\tinstanceId,\n\t\tcode,\n\t\tsignal,\n\t}: { instanceId: number; code: number; signal: string }): Promise<void> {\n\t\tthis.emit(\"instance-exited\", {\n\t\t\tinstanceId,\n\t\t\tcode,\n\t\t\tsignal,\n\t\t});\n\t\tfor (const [_, mapping] of this.deviceMappings.entries()) {\n\t\t\tif (mapping.instanceId === instanceId) {\n\t\t\t\tthis.removeDevice(mapping);\n\t\t\t}\n\t\t}\n\t\tthis.instances.delete(instanceId);\n\t\tthis.processes.get(instanceId)?.kill();\n\t\tthis.processes.delete(instanceId);\n\t}\n\n\tprivate async onUsbmuxdInstanceStart({\n\t\tinstance,\n\t\tprocess,\n\t}: { instance: UsbmuxdInstance; process: ChildProcess }): Promise<void> {\n\t\tthis.instances.set(instance.id, instance);\n\t\tthis.processes.set(instance.id, process);\n\t\tthis.emit(\"instance-started\", {\n\t\t\tinstanceId: instance.id,\n\t\t});\n\t}\n\n\tprivate async createInstance(id: number) {\n\t\tlet onExit = (code: number, signal: string) => {\n\t\t\tthis.onUsbmuxdInstanceEnd({ instanceId: id, code, signal });\n\t\t};\n\n\t\tonExit = onExit.bind(this);\n\n\t\tconst { instance, process } = await this.wsl.createInstance({\n\t\t\tid,\n\t\t\tbasePort: this.config.basePort,\n\t\t\tverboseLogging: this.config.verboseLogging,\n\t\t\tusbmuxdPath: this.config.usbmuxdPath,\n\t\t\tonLog: (message) =>\n\t\t\t\tthis.emit(\"instance-log\", {\n\t\t\t\t\tinstanceId: id,\n\t\t\t\t\tlevel: \"info\",\n\t\t\t\t\tmessage,\n\t\t\t\t}),\n\t\t\tonExit,\n\t\t});\n\n\t\tthis.onUsbmuxdInstanceStart({ instance, process });\n\t\treturn instance;\n\t}\n\n\tprivate async getInstance() {\n\t\tlet targetInstance = this.findInstanceWithCapacity();\n\n\t\t// If no instance has capacity, create a new one\n\t\tif (!targetInstance) {\n\t\t\tif (this.instances.size >= this.config.maxInstances) {\n\t\t\t\tthrow new Error(`Maximum number of instances (${this.config.maxInstances}) reached`);\n\t\t\t}\n\n\t\t\ttargetInstance = await this.createInstance(this.nextInstanceId++);\n\t\t}\n\t\treturn targetInstance;\n\t}\n\n\t/**\n\t * Handle device connection only for not attached devices\n\t * Attaches device to WSL, then assigns to an existing instance or creates a new one\n\t */\n\tpublic async onDeviceConnected(device: DeviceInfo): Promise<void> {\n\t\tconst busId = await this.usbipd.findBusIdForDevice(device);\n\n\t\tif (this.attachedDevices.has(busId)) {\n\t\t\tlogTask(`Device ${device.deviceId} is already attached. skipping onDeviceConnected...`);\n\t\t\treturn;\n\t\t}\n\n\t\tlogDataObject(\"Device connected\", { device });\n\t\tawait this.wsl.syncToAlpine(device.deviceId);\n\n\t\tawait this.attachToWsl({ busId, deviceId: device.deviceId });\n\n\t\tconst targetInstance = await this.getInstance();\n\n\t\t// Create mapping (include host and busId for cleanup on disconnect)\n\t\tconst mapping: DeviceMapping = {\n\t\t\tudid: device.deviceId,\n\t\t\tinstanceId: targetInstance.id,\n\t\t\thost: targetInstance.host,\n\t\t\tport: targetInstance.port,\n\t\t\taddedAt: new Date(),\n\t\t\tbusId: busId ?? undefined,\n\t\t};\n\n\t\tthis.deviceMappings.set(device.deviceId, mapping);\n\n\t\t// Add device to instance\n\t\ttargetInstance.deviceUdids.push(device.deviceId);\n\n\t\tthis.emit(\"device-assigned\", {\n\t\t\tdevice,\n\t\t\tinstance: targetInstance,\n\t\t\tmapping,\n\t\t});\n\n\t\tthis.pendingAttachDevices.delete(device.deviceId);\n\t}\n\n\tprivate async detachFromWsl({ deviceId }: { deviceId: string }): Promise<UsbmuxdInstance> {\n\t\tconst mapping = this.deviceMappings.get(deviceId);\n\t\tif (!mapping) {\n\t\t\tthrow new Error(`Device ${deviceId} was not tracked`);\n\t\t}\n\n\t\t// Detach device from WSL if it was attached\n\t\tif (mapping.busId) {\n\t\t\tawait this.usbipd.detachDeviceFromWsl(mapping.busId);\n\t\t\tthis.attachedDevices.delete(mapping.busId);\n\t\t}\n\n\t\tconst instance = this.instances.get(mapping.instanceId);\n\t\tif (!instance) {\n\t\t\tlogWarning(`Instance ${mapping.instanceId} not found`);\n\t\t\tthis.deviceMappings.delete(deviceId);\n\t\t\tthrow new Error(`Instance ${mapping.instanceId} not found`);\n\t\t}\n\n\t\treturn instance;\n\t}\n\n\t/**\n\t * Handle device disconnection only for attached devices\n\t * Detaches from WSL, removes device from instance, and stops instance if empty\n\t */\n\tpublic async onDeviceDisconnected(device: DeviceInfo): Promise<void> {\n\t\t// Ignore disconnect while we're still attaching this device (Windows sees disconnect when device moves to WSL)\n\t\tif (!this.attachedDevices.has(device.deviceId)) {\n\t\t\tlogTask(`Device ${device.deviceId} is not attached. skipping onDeviceDisconnected...`);\n\t\t\treturn;\n\t\t}\n\t\tlogDataObject(\"Device disconnected\", { device });\n\n\t\tconst mapping = this.deviceMappings.get(device.deviceId);\n\t\tif (!mapping) {\n\t\t\tthrow new Error(`Device ${device.deviceId} was not tracked`);\n\t\t}\n\t\t// Remove device from instance\n\t\tconst instance = await this.removeDevice(mapping);\n\n\t\tthis.emit(\"device-removed\", {\n\t\t\tdevice,\n\t\t\tinstance,\n\t\t});\n\t}\n\n\t/**\n\t * Find an instance with available capacity\n\t */\n\tprivate findInstanceWithCapacity(): UsbmuxdInstance | null {\n\t\tfor (const instance of this.instances.values()) {\n\t\t\tif (instance.deviceUdids.length < this.config.batchSize) {\n\t\t\t\treturn instance;\n\t\t\t}\n\t\t}\n\t\treturn null;\n\t}\n\n\t/**\n\t * Stop a specific instance\n\t */\n\tprivate async stopInstance(instanceId: number): Promise<void> {\n\t\tconst instance = this.instances.get(instanceId);\n\t\tconst childProcess = this.processes.get(instanceId);\n\n\t\tif (!instance || !childProcess) {\n\t\t\treturn;\n\t\t}\n\n\t\tfor (const process of this.processes.values()) {\n\t\t\tprocess.kill(\"SIGKILL\");\n\t\t}\n\n\t\t// Clean up\n\t\tthis.instances.delete(instanceId);\n\t\tthis.processes.delete(instanceId);\n\n\t\t// Remove device mappings\n\t\tfor (const [udid, mapping] of this.deviceMappings.entries()) {\n\t\t\tif (mapping.instanceId === instanceId) {\n\t\t\t\tthis.deviceMappings.delete(udid);\n\t\t\t}\n\t\t}\n\n\t\tthis.emit(\"instance-stopped\", instance);\n\t}\n\n\t/**\n\t * Get device-to-port mapping for a specific UDID\n\t */\n\tpublic getDevicePort(udid: string): number | null {\n\t\tconst mapping = this.deviceMappings.get(udid);\n\t\treturn mapping ? mapping.port : null;\n\t}\n\n\t/**\n\t * Get all device mappings\n\t */\n\tpublic getDeviceMappings(): DeviceMapping[] {\n\t\treturn Array.from(this.deviceMappings.values());\n\t}\n\n\t/**\n\t * Get all running instances\n\t */\n\tpublic getInstances(): UsbmuxdInstance[] {\n\t\treturn Array.from(this.instances.values());\n\t}\n\n\t/**\n\t * Get manager statistics\n\t */\n\tpublic getStats(): ManagerStats {\n\t\tconst now = Date.now();\n\t\tconst startTime = this.startedAt?.getTime() || now;\n\t\tconst uptimeSeconds = Math.floor((now - startTime) / 1000);\n\n\t\treturn {\n\t\t\tinstanceCount: this.instances.size,\n\t\t\tdeviceCount: this.deviceMappings.size,\n\t\t\tuptimeSeconds,\n\t\t\tstartedAt: this.startedAt || new Date(),\n\t\t};\n\t}\n\n\t/**\n\t * Get current configuration\n\t */\n\tpublic getConfig(): InstanceManagerConfig {\n\t\treturn { ...this.config };\n\t}\n}\n", "import { exec } from \"node:child_process\";\nimport { promisify } from \"node:util\";\nimport { createLoggers } from \"@mcesystems/tool-debug-g4\";\nimport type { DeviceInfo } from \"./types\";\nimport type { UsbipdDevice } from \"./types/usbipd.js\";\nimport type { Wsl2 } from \"./wsl.js\";\n\nconst { logInfo, logWarning } = createLoggers(\"usbipd\");\n\nconst execAsync = promisify(exec);\n\nexport class Usbipd {\n\tconstructor(private readonly usbipdPath: string) {}\n\n\tpublic async unbindAllDevicesFromWsl(): Promise<void> {\n\t\ttry {\n\t\t\tawait execAsync(`\"${this.usbipdPath}\" unbind -a`);\n\t\t\tlogInfo(\"All devices unbound from WSL\");\n\t\t} catch (error) {\n\t\t\tlogWarning(`Failed to unbind all devices from WSL: ${error}`);\n\t\t}\n\t}\n\n\tpublic async detachAllDevicesFromWsl(): Promise<void> {\n\t\ttry {\n\t\t\tawait execAsync(`\"${this.usbipdPath}\" detach -a`);\n\t\t\tlogInfo(\"All devices detached from WSL\");\n\t\t} catch (error) {\n\t\t\tlogWarning(`Failed to detach all devices from WSL: ${error}`);\n\t\t}\n\t}\n\n\t/**\n\t * Detach a device from WSL via usbipd\n\t */\n\tpublic async detachDeviceFromWsl(busId: string): Promise<void> {\n\t\ttry {\n\t\t\tawait execAsync(`\"${this.usbipdPath}\" detach --busid=${busId}`);\n\t\t\tlogInfo(`Device ${busId} detached from WSL`);\n\t\t} catch (error) {\n\t\t\tconst message = error instanceof Error ? error.message : String(error);\n\t\t\tif (message.includes(\"no device with busid\") || message.includes(\"There is no device\")) {\n\t\t\t\tlogInfo(`Device ${busId} already detached`);\n\t\t\t} else {\n\t\t\t\tlogWarning(`Failed to detach device ${busId}: ${error}`);\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Attach a device to WSL via usbipd\n\t * Note: This requires administrator privileges\n\t */\n\tpublic async attachDeviceToWsl(busId: string, wsl: Wsl2, distro: string): Promise<boolean> {\n\t\ttry {\n\t\t\t// Ensure WSL is running first\n\t\t\tawait wsl.ensureWslRunning();\n\n\t\t\t// Bind the device (make it shareable)\n\t\t\tlogInfo(`Binding device ${busId}...`);\n\t\t\tawait execAsync(`\"${this.usbipdPath}\" bind --busid ${busId} --force`);\n\n\t\t\t// Attach to WSL (use specific distro if configured, otherwise let usbipd pick)\n\t\t\tif (distro) {\n\t\t\t\tlogInfo(`Attaching device ${busId} to WSL distribution ${distro}...`);\n\t\t\t\tawait execAsync(`\"${this.usbipdPath}\" attach --wsl=${distro} --busid=${busId}`);\n\t\t\t} else {\n\t\t\t\tlogInfo(`Attaching device ${busId} to default WSL...`);\n\t\t\t\tawait execAsync(`\"${this.usbipdPath}\" attach --wsl --busid=${busId}`);\n\t\t\t}\n\n\t\t\tlogInfo(`Device ${busId} attached to WSL successfully`);\n\t\t\treturn true;\n\t\t} catch (error) {\n\t\t\tconst message = error instanceof Error ? error.message : String(error);\n\t\t\t// Device already attached (e.g. from a previous run) \u2014 treat as success so we still start usbmuxd\n\t\t\tif (message.includes(\"already attached to a client\")) {\n\t\t\t\tlogInfo(`Device ${busId} is already attached to WSL, continuing`);\n\t\t\t\treturn true;\n\t\t\t}\n\t\t\tlogWarning(`Failed to attach device ${busId} to WSL: ${error}`);\n\t\t\treturn false;\n\t\t}\n\t}\n\n\t/**\n\t * Parse usbipd list output to extract device information\n\t */\n\tprivate parseUsbipdList(output: string): UsbipdDevice[] {\n\t\tconst devices: UsbipdDevice[] = [];\n\t\t// Handle both \\r\\n and \\n line endings\n\t\tconst lines = output.split(/\\r?\\n/);\n\n\t\tfor (const line of lines) {\n\t\t\t// Format: \"4-5 05ac:12a8 Apple Mobile Device USB Composite Device Shared (forced)\"\n\t\t\t// More flexible regex: busid, vid:pid, then anything else\n\t\t\tconst match = line.match(/^(\\d+-\\d+)\\s+([0-9a-f]{4}):([0-9a-f]{4})\\s+(.+)$/i);\n\t\t\tif (match) {\n\t\t\t\t// Split the rest into description and state (state is the last word(s) after multiple spaces)\n\t\t\t\tconst rest = match[4].trim();\n\t\t\t\tconst stateMatch = rest.match(/^(.+?)\\s{2,}(\\S.*)$/);\n\t\t\t\tconst description = stateMatch ? stateMatch[1].trim() : rest;\n\t\t\t\tconst state = stateMatch ? stateMatch[2].trim() : \"Unknown\";\n\n\t\t\t\tdevices.push({\n\t\t\t\t\tbusId: match[1],\n\t\t\t\t\tvid: match[2].toUpperCase(),\n\t\t\t\t\tpid: match[3].toUpperCase(),\n\t\t\t\t\tdescription,\n\t\t\t\t\tstate,\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\n\t\treturn devices;\n\t}\n\t/**\n\t * Find the usbipd bus ID for a device by matching VID/PID\n\t */\n\tpublic async findBusIdForDevice(device: DeviceInfo): Promise<string> {\n\t\ttry {\n\t\t\tconst { stdout } = await execAsync(`\"${this.usbipdPath}\" list`);\n\t\t\tconst usbipdDevices = this.parseUsbipdList(stdout);\n\n\t\t\t// Convert device VID/PID to hex string for comparison\n\t\t\tconst deviceVid = device.vid.toString(16).toUpperCase().padStart(4, \"0\");\n\t\t\tconst devicePid = device.pid.toString(16).toUpperCase().padStart(4, \"0\");\n\n\t\t\tlogInfo(`Looking for device with VID:PID ${deviceVid}:${devicePid}`);\n\t\t\tlogInfo(`Found ${usbipdDevices.length} devices from usbipd list`);\n\n\t\t\t// Find matching device by VID/PID\n\t\t\tconst match = usbipdDevices.find((d) => d.vid === deviceVid && d.pid === devicePid);\n\n\t\t\tif (match) {\n\t\t\t\tlogInfo(\n\t\t\t\t\t`Found usbipd bus ID ${match.busId} for device ${device.deviceId} (${deviceVid}:${devicePid})`\n\t\t\t\t);\n\t\t\t\treturn match.busId;\n\t\t\t}\n\n\t\t\tthrow new Error(\n\t\t\t\t`Could not find usbipd bus ID for device ${device.deviceId} (${deviceVid}:${devicePid})`\n\t\t\t);\n\t\t} catch (error) {\n\t\t\tthrow new Error(`Failed to run usbipd list: ${error}`);\n\t\t}\n\t}\n}\n", "import { type ChildProcess, exec, spawn } from \"node:child_process\";\nimport { existsSync, mkdirSync } from \"node:fs\";\nimport { join } from \"node:path\";\nimport { promisify } from \"node:util\";\nimport { createLoggers } from \"@mcesystems/tool-debug-g4\";\nimport type { UsbmuxdInstance } from \"./types\";\n\nconst { logInfo, logWarning, logDetail } = createLoggers(\"wsl\");\n\nconst execAsync = promisify(exec);\n\nexport class Wsl2 {\n\tprivate readonly ALPINE_LOCKDOWN_DIR = \"/var/lib/lockdown\";\n\tprivate readonly SYSTEM_CONFIG_PLIST = \"SystemConfiguration.plist\";\n\n\tprivate wslIpAddress: string | null = null;\n\n\tconstructor(private wslDistribution: string | undefined) {}\n\n\t/**\n\t * Detect the WSL2 IP address for the configured distribution\n\t * This IP is needed to connect from Windows to services inside WSL\n\t */\n\tpublic async detectWslIpAddress(): Promise<string> {\n\t\tif (this.wslIpAddress) {\n\t\t\treturn this.wslIpAddress;\n\t\t}\n\n\t\tconst distro = this.wslDistribution || \"alpine-usbmuxd-build\";\n\n\t\ttry {\n\t\t\t// Try to get IP from eth0 interface\n\t\t\tconst { stdout } = await execAsync(`wsl -d ${distro} -- ip -4 addr show eth0`);\n\t\t\tconst match = stdout.match(/inet\\s+(\\d+\\.\\d+\\.\\d+\\.\\d+)/);\n\t\t\tif (match) {\n\t\t\t\tthis.wslIpAddress = match[1];\n\t\t\t\tlogInfo(`Detected WSL IP address: ${this.wslIpAddress}`);\n\t\t\t\treturn this.wslIpAddress;\n\t\t\t}\n\t\t} catch (error) {\n\t\t\tlogWarning(`Failed to detect WSL IP via ip addr: ${error}`);\n\t\t}\n\n\t\t// Fallback: try hostname -I\n\t\ttry {\n\t\t\tconst { stdout } = await execAsync(`wsl -d ${distro} -- hostname -I`);\n\t\t\tconst ip = stdout.trim().split(/\\s+/)[0];\n\t\t\tif (ip && /^\\d+\\.\\d+\\.\\d+\\.\\d+$/.test(ip)) {\n\t\t\t\tthis.wslIpAddress = ip;\n\t\t\t\tlogInfo(`Detected WSL IP address (hostname): ${this.wslIpAddress}`);\n\t\t\t\treturn this.wslIpAddress;\n\t\t\t}\n\t\t} catch (error) {\n\t\t\tlogWarning(`Failed to detect WSL IP via hostname: ${error}`);\n\t\t}\n\n\t\t// Last resort fallback - localhost (may work with WSL2 mirrored networking)\n\t\tlogWarning(\"Could not detect WSL IP, falling back to localhost\");\n\t\tthis.wslIpAddress = \"127.0.0.1\";\n\t\treturn this.wslIpAddress;\n\t}\n\n\t/**\n\t * Ensure the WSL distribution is running\n\t */\n\tpublic async ensureWslRunning(): Promise<boolean> {\n\t\tconst distro = this.wslDistribution;\n\n\t\ttry {\n\t\t\tif (distro) {\n\t\t\t\t// Start specific distribution\n\t\t\t\tlogInfo(`Starting WSL distribution: ${distro}...`);\n\t\t\t\tawait execAsync(`wsl -d ${distro} -- echo \"WSL started\"`);\n\t\t\t} else {\n\t\t\t\t// Start default WSL\n\t\t\t\tlogInfo(\"Starting default WSL distribution...\");\n\t\t\t\tawait execAsync(`wsl -- echo \"WSL started\"`);\n\t\t\t}\n\t\t\treturn true;\n\t\t} catch (error) {\n\t\t\tlogWarning(`Failed to start WSL: ${error}`);\n\t\t\treturn false;\n\t\t}\n\t}\n\n\t/**\n\t * Create a new usbmuxd instance\n\t */\n\tpublic async createInstance({\n\t\tid,\n\t\tbasePort,\n\t\tverboseLogging,\n\t\tusbmuxdPath,\n\t\tonLog,\n\t\tonExit,\n\t}: {\n\t\tid: number;\n\t\tbasePort: number;\n\t\tverboseLogging: boolean;\n\t\tusbmuxdPath: string;\n\t\tonLog: (message: string) => void;\n\t\tonExit: (code: number, signal: string) => void;\n\t}): Promise<{ instance: UsbmuxdInstance; process: ChildProcess }> {\n\t\tconst port = basePort + id - 1;\n\n\t\tlogInfo(`Creating instance ${id} on port ${port}`);\n\n\t\t// Detect WSL IP for connecting from Windows\n\t\tconst host = await this.detectWslIpAddress();\n\n\t\t// Build usbmuxd arguments\n\t\tconst usbmuxdArgs = [\n\t\t\t\"-f\", // Foreground\n\t\t\t\"-v\", // Verbose (if enabled)\n\t\t\t\"-S\",\n\t\t\t`0.0.0.0:${port}`, // Listen on all interfaces (for Windows \u2192 WSL2)\n\t\t\t\"--pidfile\",\n\t\t\t\"NONE\",\n\t\t];\n\n\t\tif (!verboseLogging) {\n\t\t\t// Remove -v if not verbose\n\t\t\tusbmuxdArgs.splice(1, 1);\n\t\t}\n\n\t\t// Build WSL command: wsl -d <distro> usbmuxd <args>\n\t\tconst wslArgs = [\n\t\t\t\"-d\",\n\t\t\tthis.wslDistribution || \"alpine-usbmuxd-build\",\n\t\t\tusbmuxdPath,\n\t\t\t...usbmuxdArgs,\n\t\t];\n\n\t\t// Spawn via WSL\n\t\tconst process = spawn(\"wsl\", wslArgs, {\n\t\t\tstdio: [\"ignore\", \"pipe\", \"pipe\"],\n\t\t});\n\n\t\t// Handle process output\n\t\tprocess.stdout?.on(\"data\", (data) => {\n\t\t\tonLog(data.toString().trim());\n\t\t});\n\n\t\tprocess.stderr?.on(\"data\", (data) => {\n\t\t\tonLog(data.toString().trim());\n\t\t});\n\n\t\t// Handle process exit\n\t\tprocess.on(\"exit\", onExit);\n\n\t\t// Create instance record (pid is set synchronously by Node after spawn)\n\t\tconst pid = process.pid;\n\t\tif (pid === undefined) {\n\t\t\tprocess.kill(\"SIGKILL\");\n\t\t\tthrow new Error(\"Failed to get PID for usbmuxd instance\");\n\t\t}\n\t\tconst instance: UsbmuxdInstance = {\n\t\t\tid,\n\t\t\thost,\n\t\t\tport,\n\t\t\tpid,\n\t\t\tdeviceUdids: [],\n\t\t\tstartedAt: new Date(),\n\t\t};\n\n\t\treturn { instance, process };\n\t}\n\n\t/**\n\t * Convert a Windows path to the equivalent path inside WSL (e.g. C:\\foo\\bar -> /mnt/c/foo/bar).\n\t */\n\tprivate windowsPathToWsl(windowsPath: string): string {\n\t\tconst normalized = windowsPath.replace(/\\\\/g, \"/\").trim();\n\t\tconst driveMatch = normalized.match(/^([a-zA-Z]):\\/?(.*)$/);\n\t\tif (driveMatch) {\n\t\t\tconst drive = driveMatch[1].toLowerCase();\n\t\t\tconst rest = driveMatch[2] || \"\";\n\t\t\treturn `/mnt/${drive}${rest ? `/${rest}` : \"\"}`;\n\t\t}\n\t\treturn normalized;\n\t}\n\n\t/**\n\t * Get the native Apple lockdown directory path for the current platform.\n\t * This is where Apple/iTunes stores pairing records natively.\n\t */\n\tprivate getAppleLockdownPath(): string | null {\n\t\tif (process.platform === \"win32\") {\n\t\t\treturn join(process.env.ProgramData ?? \"C:\\\\ProgramData\", \"Apple\", \"Lockdown\");\n\t\t}\n\t\tif (process.platform === \"darwin\") {\n\t\t\treturn \"/var/db/lockdown\";\n\t\t}\n\t\tif (process.platform === \"linux\") {\n\t\t\treturn \"/var/lib/lockdown\";\n\t\t}\n\t\treturn null;\n\t}\n\n\t/**\n\t * Copy a single device's lockdown plist from the native Apple lockdown directory\n\t * to Alpine so usbmuxd can use it (skip pairing).\n\t *\n\t * Uses the platform-specific Apple/iTunes lockdown directory\n\t * (e.g. C:\\ProgramData\\Apple\\Lockdown on Windows, /var/db/lockdown on macOS).\n\t *\n\t * No-op if the lockdown directory cannot be determined or files don't exist.\n\t */\n\tpublic async syncToAlpine(udid: string): Promise<void> {\n\t\tconst lockdownDir = this.getAppleLockdownPath();\n\t\tif (!lockdownDir) {\n\t\t\tlogWarning(\"Lockdown sync to Alpine: unsupported platform, skipping\");\n\t\t\treturn;\n\t\t}\n\n\t\tlogDetail(`Lockdown sync to Alpine: source dir = ${lockdownDir}, udid = ${udid}`);\n\n\t\tconst distro = this.wslDistribution || \"alpine-usbmuxd-build\";\n\t\tconst wslDestDir = this.ALPINE_LOCKDOWN_DIR;\n\n\t\t// Sync the device-specific plist\n\t\tconst devicePlistFile = `${udid}.plist`;\n\t\tconst devicePlistPath = join(lockdownDir, devicePlistFile);\n\t\tif (existsSync(devicePlistPath)) {\n\t\t\tawait this.copyFileToAlpine(\n\t\t\t\tthis.windowsPathToWsl(devicePlistPath),\n\t\t\t\twslDestDir,\n\t\t\t\tdistro,\n\t\t\t\tdevicePlistFile\n\t\t\t);\n\t\t} else {\n\t\t\tlogDetail(\n\t\t\t\t`Lockdown sync to Alpine: ${devicePlistFile} not found at ${devicePlistPath}, skipping`\n\t\t\t);\n\t\t}\n\n\t\t// Sync SystemConfiguration.plist so Alpine usbmuxd uses the same SystemBUID\n\t\t// that was used during the original pairing on Windows.\n\t\t// Without this, lockdown sessions fail with InvalidHostID.\n\t\tconst systemConfigPath = join(lockdownDir, this.SYSTEM_CONFIG_PLIST);\n\t\tif (existsSync(systemConfigPath)) {\n\t\t\tawait this.copyFileToAlpine(\n\t\t\t\tthis.windowsPathToWsl(systemConfigPath),\n\t\t\t\twslDestDir,\n\t\t\t\tdistro,\n\t\t\t\tthis.SYSTEM_CONFIG_PLIST\n\t\t\t);\n\t\t} else {\n\t\t\tlogDetail(\n\t\t\t\t`Lockdown sync to Alpine: ${this.SYSTEM_CONFIG_PLIST} not found at ${systemConfigPath}, skipping`\n\t\t\t);\n\t\t}\n\t}\n\n\t/**\n\t * Copy a single file into the Alpine lockdown directory.\n\t * Falls back to sudo if the initial copy fails.\n\t */\n\tprivate async copyFileToAlpine(\n\t\twslSource: string,\n\t\twslDestDir: string,\n\t\tdistro: string,\n\t\tfileName: string\n\t): Promise<void> {\n\t\ttry {\n\t\t\tawait execAsync(\n\t\t\t\t`wsl -d ${distro} -- sh -c \"mkdir -p ${wslDestDir} && cp '${wslSource}' '${wslDestDir}/'\"`\n\t\t\t);\n\t\t\tlogInfo(`Lockdown sync: copied ${fileName} to Alpine`);\n\t\t} catch (error) {\n\t\t\ttry {\n\t\t\t\tawait execAsync(\n\t\t\t\t\t`wsl -d ${distro} -- sh -c \"mkdir -p ${wslDestDir} && sudo cp '${wslSource}' '${wslDestDir}/'\"`\n\t\t\t\t);\n\t\t\t\tlogInfo(`Lockdown sync: copied ${fileName} to Alpine (via sudo)`);\n\t\t\t} catch (sudoError) {\n\t\t\t\tlogWarning(\n\t\t\t\t\t`Lockdown sync to Alpine failed for ${fileName}: ${error}. Sudo fallback failed: ${sudoError}. Ensure /var/lib/lockdown is writable or use passwordless sudo.`\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Copy lockdown plists from Alpine back to the native Apple lockdown directory\n\t * (for devices that were assigned this session).\n\t * Also copies SystemConfiguration.plist if present in Alpine.\n\t *\n\t * No-op if the lockdown directory cannot be determined.\n\t */\n\tpublic async syncFromAlpine(udids: string[]): Promise<void> {\n\t\tlogInfo(`Lockdown sync from Alpine: starting (${udids.length} device(s))`);\n\n\t\tconst lockdownDir = this.getAppleLockdownPath();\n\t\tif (!lockdownDir) {\n\t\t\tlogWarning(\"Lockdown sync: unsupported platform, skipping\");\n\t\t\treturn;\n\t\t}\n\n\t\tlogDetail(`Lockdown sync: target dir = ${lockdownDir}`);\n\n\t\ttry {\n\t\t\tmkdirSync(lockdownDir, { recursive: true });\n\t\t} catch (error) {\n\t\t\tlogWarning(`Lockdown sync: could not create lockdown dir ${lockdownDir}: ${error}`);\n\t\t\treturn;\n\t\t}\n\n\t\tconst distro = this.wslDistribution || \"alpine-usbmuxd-build\";\n\t\tconst wslDestDir = this.windowsPathToWsl(lockdownDir);\n\n\t\t// List what Alpine actually has in its lockdown dir for debugging\n\t\ttry {\n\t\t\tconst { stdout } = await execAsync(`wsl -d ${distro} -- ls -la ${this.ALPINE_LOCKDOWN_DIR}/`);\n\t\t\tlogDetail(`Lockdown sync: Alpine ${this.ALPINE_LOCKDOWN_DIR} contents:\\n${stdout}`);\n\t\t} catch (error) {\n\t\t\tlogWarning(`Lockdown sync: could not list Alpine lockdown dir: ${error}`);\n\t\t}\n\n\t\tconst filesToSync = [...udids.map((udid) => `${udid}.plist`), this.SYSTEM_CONFIG_PLIST];\n\n\t\tlogDetail(`Lockdown sync: files to sync = [${filesToSync.join(\", \")}]`);\n\n\t\tfor (const fileName of filesToSync) {\n\t\t\tawait this.copyFileFromAlpine(fileName, wslDestDir, distro, lockdownDir);\n\t\t}\n\n\t\tlogInfo(\"Lockdown sync from Alpine: done\");\n\t}\n\n\t/**\n\t * Copy a single file from the Alpine lockdown directory back to Windows.\n\t * Skips if the file does not exist in Alpine; logs a warning if the copy fails.\n\t */\n\tprivate async copyFileFromAlpine(\n\t\tfileName: string,\n\t\twslDestDir: string,\n\t\tdistro: string,\n\t\tlockdownDir: string\n\t): Promise<void> {\n\t\tconst alpinePath = `${this.ALPINE_LOCKDOWN_DIR}/${fileName}`;\n\n\t\t// Check if the file exists in Alpine first\n\t\ttry {\n\t\t\tawait execAsync(`wsl -d ${distro} -- test -f '${alpinePath}'`);\n\t\t} catch {\n\t\t\tlogDetail(`Lockdown sync: ${fileName} not found in Alpine (${alpinePath}), skipping`);\n\t\t\treturn;\n\t\t}\n\n\t\t// File exists \u2014 copy it to Windows\n\t\tlogDetail(`Lockdown sync: copying ${fileName} \u2192 ${wslDestDir}/`);\n\t\ttry {\n\t\t\tawait execAsync(`wsl -d ${distro} -- cp -f '${alpinePath}' '${wslDestDir}/'`);\n\t\t\tlogInfo(`Lockdown sync: copied ${fileName} from Alpine to ${lockdownDir}`);\n\t\t} catch (error) {\n\t\t\tlogWarning(`Lockdown sync: failed to copy ${fileName} from Alpine to ${lockdownDir}: ${error}`);\n\t\t}\n\t}\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,IAAAA,sBAA6B;AAC7B,IAAAC,wBAA8B;;;ACA9B,yBAA6B;AAC7B,IAAAC,wBAA8B;;;ACF9B,gCAAqB;AACrB,uBAA0B;AAC1B,2BAA8B;AAK9B,IAAM,EAAE,SAAS,WAAW,QAAI,oCAAc,QAAQ;AAEtD,IAAM,gBAAY,4BAAU,8BAAI;AAEzB,IAAM,SAAN,MAAa;AAAA,EACnB,YAA6B,YAAoB;AAApB;AAAA,EAAqB;AAAA,EAElD,MAAa,0BAAyC;AACrD,QAAI;AACH,YAAM,UAAU,IAAI,KAAK,UAAU,aAAa;AAChD,cAAQ,8BAA8B;AAAA,IACvC,SAAS,OAAO;AACf,iBAAW,0CAA0C,KAAK,EAAE;AAAA,IAC7D;AAAA,EACD;AAAA,EAEA,MAAa,0BAAyC;AACrD,QAAI;AACH,YAAM,UAAU,IAAI,KAAK,UAAU,aAAa;AAChD,cAAQ,+BAA+B;AAAA,IACxC,SAAS,OAAO;AACf,iBAAW,0CAA0C,KAAK,EAAE;AAAA,IAC7D;AAAA,EACD;AAAA;AAAA;AAAA;AAAA,EAKA,MAAa,oBAAoB,OAA8B;AAC9D,QAAI;AACH,YAAM,UAAU,IAAI,KAAK,UAAU,oBAAoB,KAAK,EAAE;AAC9D,cAAQ,UAAU,KAAK,oBAAoB;AAAA,IAC5C,SAAS,OAAO;AACf,YAAM,UAAU,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK;AACrE,UAAI,QAAQ,SAAS,sBAAsB,KAAK,QAAQ,SAAS,oBAAoB,GA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B,WAAO,KAAK,QAAQ,aAAa;AAAA,EAClC;AAAA;AAAA;AAAA;AAAA,EAKO,WAAW;AACjB,WAAO,KAAK,QAAQ,SAAS;AAAA,EAC9B;AAAA;AAAA;AAAA;AAAA,EAKO,YAAY;AAClB,WAAO,KAAK,QAAQ,UAAU;AAAA,EAC/B;AACD;",
|
|
6
|
+
"names": ["import_node_events", "import_tool_debug_g4", "import_tool_debug_g4", "import_node_child_process", "import_node_util", "import_tool_debug_g4", "logInfo", "logWarning", "execAsync", "process", "logWarning", "process", "logInfo", "logDataObject"]
|
|
7
7
|
}
|