@codingfrees/uap-device-control 0.2.6 → 0.2.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/dist/uap-device-control.mjs +33 -11
- package/package.json +1 -1
|
@@ -783,7 +783,7 @@ import WebSocket from "ws";
|
|
|
783
783
|
// package.json
|
|
784
784
|
var package_default = {
|
|
785
785
|
name: "@codingfrees/uap-device-control",
|
|
786
|
-
version: "0.2.
|
|
786
|
+
version: "0.2.8",
|
|
787
787
|
description: "Cross-platform outbound UAP Device Control client",
|
|
788
788
|
type: "module",
|
|
789
789
|
bin: {
|
|
@@ -826,6 +826,7 @@ var DeviceAgentEngine = class {
|
|
|
826
826
|
this.#maxProcesses = bounded(options.maxProcesses ?? 8, 1, 64, "process limit");
|
|
827
827
|
this.#maxSessions = bounded(options.maxSessions ?? 4, 1, 16, "session limit");
|
|
828
828
|
this.#sessionIdleTimeoutMs = bounded(options.sessionIdleTimeoutMs ?? 30 * 6e4, 100, 24 * 60 * 6e4, "session idle timeout");
|
|
829
|
+
this.#unrestricted = options.unrestricted === true || options.allowedExecutables !== void 0 && options.allowedExecutables.includes("*");
|
|
829
830
|
this.#allowed = new Set(options.allowedExecutables ?? defaultExecutables());
|
|
830
831
|
for (const name of options.allowedServices ?? []) {
|
|
831
832
|
const normalized = serviceName(name);
|
|
@@ -884,6 +885,7 @@ var DeviceAgentEngine = class {
|
|
|
884
885
|
#maxProcesses;
|
|
885
886
|
#maxSessions;
|
|
886
887
|
#sessionIdleTimeoutMs;
|
|
888
|
+
#unrestricted;
|
|
887
889
|
#allowed;
|
|
888
890
|
#allowedServices = /* @__PURE__ */ new Set();
|
|
889
891
|
#capabilityAdapters = /* @__PURE__ */ new Map();
|
|
@@ -1309,7 +1311,9 @@ var DeviceAgentEngine = class {
|
|
|
1309
1311
|
}
|
|
1310
1312
|
#spawn(input, terminal, workspaceId) {
|
|
1311
1313
|
const executable = text2(input.executable ?? defaultShell(), 260, "executable");
|
|
1312
|
-
if (![...this.#allowed].some((allowed) => executable === allowed || path3.basename(executable).toLowerCase() === path3.basename(allowed).toLowerCase()))
|
|
1314
|
+
if (!this.#unrestricted && ![...this.#allowed].some((allowed) => executable === allowed || path3.basename(executable).toLowerCase() === path3.basename(allowed).toLowerCase())) {
|
|
1315
|
+
throw new TypeError("executable is not allowed: " + executable);
|
|
1316
|
+
}
|
|
1313
1317
|
const args = Array.isArray(input.args) ? input.args.map((value) => text2(value, 8192, "argument")) : terminal ? [] : [text2(input.command ?? "", 8192, "command")];
|
|
1314
1318
|
if (args.length > 128 || JSON.stringify(args).length > 32768) throw new TypeError("command length limit exceeded");
|
|
1315
1319
|
const cwd = input.cwd === void 0 ? void 0 : this.#cwd(input.cwd);
|
|
@@ -1373,6 +1377,7 @@ var DeviceAgentEngine = class {
|
|
|
1373
1377
|
for (const root2 of this.#roots.values()) {
|
|
1374
1378
|
if (inside(root2.path, candidate)) return candidate;
|
|
1375
1379
|
}
|
|
1380
|
+
if (this.#unrestricted) return candidate;
|
|
1376
1381
|
throw new TypeError("cwd escapes configured roots");
|
|
1377
1382
|
}
|
|
1378
1383
|
#ownedRecord(map, value, workspaceId, label) {
|
|
@@ -1570,8 +1575,8 @@ async function systemProcessInventory() {
|
|
|
1570
1575
|
}
|
|
1571
1576
|
return records.sort((left, right) => (right.memoryKb ?? 0) - (left.memoryKb ?? 0)).slice(0, 200);
|
|
1572
1577
|
}
|
|
1573
|
-
var defaultShell = (
|
|
1574
|
-
var defaultExecutables = (
|
|
1578
|
+
var defaultShell = (platform = process.platform) => platform === "win32" ? "powershell.exe" : platform === "darwin" ? "/bin/zsh" : "/bin/sh";
|
|
1579
|
+
var defaultExecutables = (platform = process.platform) => platform === "win32" ? ["powershell.exe", "cmd.exe", "git.exe"] : platform === "darwin" ? ["/bin/zsh", "/bin/bash", "/bin/sh", "git"] : ["/bin/sh", "/bin/bash", "git"];
|
|
1575
1580
|
|
|
1576
1581
|
// ../device-agent/src/native-desktop.ts
|
|
1577
1582
|
import { execFile as execFile3 } from "node:child_process";
|
|
@@ -1952,6 +1957,7 @@ async function runRemote(options) {
|
|
|
1952
1957
|
name: os3.hostname(),
|
|
1953
1958
|
agentVersion: UAP_DEVICE_CONTROL_AGENT_VERSION,
|
|
1954
1959
|
roots: options.roots,
|
|
1960
|
+
...options.unrestricted ? { unrestricted: true } : {},
|
|
1955
1961
|
...options.allowedExecutables.length ? { allowedExecutables: options.allowedExecutables } : {},
|
|
1956
1962
|
...services ? { services, allowedServices: options.allowedServices } : {},
|
|
1957
1963
|
...browser ? { capabilityAdapters: [browser] } : {},
|
|
@@ -2028,7 +2034,9 @@ async function remoteSession(origin, stateDirectory, engine, fetcher = fetch, si
|
|
|
2028
2034
|
const output = await execute4(command, workspaceId);
|
|
2029
2035
|
outcome = { ok: true, output };
|
|
2030
2036
|
} catch (error) {
|
|
2031
|
-
|
|
2037
|
+
const message = safeError(error);
|
|
2038
|
+
log?.({ event: "remote.command", status: "failed", requestId: command.requestId, capability: command.capability, error: message });
|
|
2039
|
+
outcome = { ok: false, error: message };
|
|
2032
2040
|
}
|
|
2033
2041
|
await sendResult(socket, acknowledgements, { type: "result", requestId: command.requestId, ...outcome, executionMs: elapsed(startedAt) });
|
|
2034
2042
|
};
|
|
@@ -2308,7 +2316,8 @@ function elapsed(startedAt) {
|
|
|
2308
2316
|
return Math.min(864e5, Math.max(0, Math.round(Date.now() - startedAt)));
|
|
2309
2317
|
}
|
|
2310
2318
|
function safeError(error) {
|
|
2311
|
-
|
|
2319
|
+
if (error instanceof Error && error.message) return error.message.slice(0, 256);
|
|
2320
|
+
return "device operation failed";
|
|
2312
2321
|
}
|
|
2313
2322
|
function sleep2(ms, signal) {
|
|
2314
2323
|
return new Promise((resolve) => {
|
|
@@ -2459,6 +2468,7 @@ function parseDeviceControlArguments(args, cwd = process.cwd()) {
|
|
|
2459
2468
|
let browserControl = true;
|
|
2460
2469
|
let browserPort = 18700;
|
|
2461
2470
|
let debug = false;
|
|
2471
|
+
let unrestricted = false;
|
|
2462
2472
|
let json2 = false;
|
|
2463
2473
|
for (let index = command === "help" ? args.length : 1; index < args.length; index++) {
|
|
2464
2474
|
const option = args[index];
|
|
@@ -2475,11 +2485,15 @@ function parseDeviceControlArguments(args, cwd = process.cwd()) {
|
|
|
2475
2485
|
else if (option === "--no-browser-control") browserControl = false;
|
|
2476
2486
|
else if (option === "--browser-port") browserPort = port(value, option), index++;
|
|
2477
2487
|
else if (option === "--debug") debug = true;
|
|
2488
|
+
else if (option === "--unrestricted" || option === "--full-access") unrestricted = true;
|
|
2489
|
+
else if (option === "--access" && (value === "full" || value === "unrestricted")) unrestricted = true, index++;
|
|
2490
|
+
else if (option === "--access") throw new TypeError("--access mode must be 'full' or 'unrestricted'");
|
|
2478
2491
|
else if (option === "--json") json2 = true;
|
|
2479
2492
|
else throw new TypeError("unsupported UAP Device Control option: " + option);
|
|
2480
2493
|
}
|
|
2481
2494
|
const normalizedOrigin = origin === void 0 ? void 0 : canonicalOrigin(origin);
|
|
2482
|
-
if (!roots.length && command === "remote")
|
|
2495
|
+
if (!roots.length && command === "remote")
|
|
2496
|
+
roots.push(...unrestricted ? [{ id: "root", label: "Root filesystem", path: path6.resolve(process.platform === "win32" ? path6.parse(cwd).root : "/"), readOnly: false }] : defaultRemoteRoots(cwd));
|
|
2483
2497
|
return {
|
|
2484
2498
|
command,
|
|
2485
2499
|
...normalizedOrigin ? { origin: normalizedOrigin } : {},
|
|
@@ -2492,6 +2506,7 @@ function parseDeviceControlArguments(args, cwd = process.cwd()) {
|
|
|
2492
2506
|
browserControl,
|
|
2493
2507
|
browserPort,
|
|
2494
2508
|
debug,
|
|
2509
|
+
unrestricted,
|
|
2495
2510
|
json: json2
|
|
2496
2511
|
};
|
|
2497
2512
|
}
|
|
@@ -2556,6 +2571,7 @@ async function runDeviceControlCli(args = process.argv.slice(2)) {
|
|
|
2556
2571
|
const controller = new AbortController();
|
|
2557
2572
|
for (const signal of ["SIGINT", "SIGTERM"]) process.once(signal, () => controller.abort());
|
|
2558
2573
|
output({ status: "connecting", origin: resolvedOrigin, platform: process.platform });
|
|
2574
|
+
if (config.unrestricted) output({ event: "remote.mode", status: "unrestricted" });
|
|
2559
2575
|
await runRemote({
|
|
2560
2576
|
origin: resolvedOrigin,
|
|
2561
2577
|
stateDirectory: config.stateDirectory,
|
|
@@ -2565,6 +2581,7 @@ async function runDeviceControlCli(args = process.argv.slice(2)) {
|
|
|
2565
2581
|
browserControl: config.browserControl,
|
|
2566
2582
|
browserPort: config.browserPort,
|
|
2567
2583
|
debug: config.debug,
|
|
2584
|
+
unrestricted: config.unrestricted,
|
|
2568
2585
|
signal: controller.signal,
|
|
2569
2586
|
log: output
|
|
2570
2587
|
});
|
|
@@ -2585,15 +2602,19 @@ function formatCliEvent(event, json2 = false) {
|
|
|
2585
2602
|
const tool = String(event.tool ?? "tool");
|
|
2586
2603
|
if (event.phase === "invoking") return "\u{1F527} " + tool + " \xB7 running" + (event.deviceId ? " \xB7 " + JSON.stringify(event, ["providerId", "deviceId"]) : "");
|
|
2587
2604
|
if (event.phase === "failed") {
|
|
2588
|
-
const
|
|
2589
|
-
|
|
2605
|
+
const summary3 = event.summary && typeof event.summary === "object" && !Array.isArray(event.summary) ? event.summary : {};
|
|
2606
|
+
const failure = String(summary3.error ?? "");
|
|
2607
|
+
const detail = typeof summary3.detail === "string" && summary3.detail && summary3.detail !== failure ? " (" + summary3.detail + ")" : "";
|
|
2608
|
+
return "\u274C " + tool + " \xB7 failed" + (failure ? " \xB7 " + failure : "") + detail;
|
|
2590
2609
|
}
|
|
2591
2610
|
const summary2 = event.summary && typeof event.summary === "object" ? " \xB7 " + JSON.stringify(event.summary) : "";
|
|
2592
2611
|
return "\u2705 " + tool + " \xB7 completed" + summary2;
|
|
2593
2612
|
}
|
|
2594
|
-
if (event.event === "remote.
|
|
2613
|
+
if (event.event === "remote.mode" && event.status === "unrestricted") return "\u26A0\uFE0F Unrestricted mode active: all system executables and paths permitted";
|
|
2614
|
+
if (event.event === "remote.command") {
|
|
2595
2615
|
const requestId = String(event.requestId ?? "").slice(0, 8);
|
|
2596
|
-
return "\u{1F9ED} Command \xB7 " + String(event.command ?? "") + (event.cwd ? "\n cwd: " + String(event.cwd) : "") + (requestId ? "\n request: " + requestId : "");
|
|
2616
|
+
if (event.status === "executing") return "\u{1F9ED} Command \xB7 " + String(event.command ?? "") + (event.cwd ? "\n cwd: " + String(event.cwd) : "") + (requestId ? "\n request: " + requestId : "");
|
|
2617
|
+
if (event.status === "failed") return "\u274C Command \xB7 failed \xB7 " + String(event.error ?? "failed") + (requestId ? "\n request: " + requestId : "");
|
|
2597
2618
|
}
|
|
2598
2619
|
if (event.event === "browser.bridge") {
|
|
2599
2620
|
if (status === "ready")
|
|
@@ -2688,6 +2709,7 @@ Remote options:
|
|
|
2688
2709
|
--state-dir <path> Override the local state directory
|
|
2689
2710
|
--origin <https-origin> Override the Device Control service origin
|
|
2690
2711
|
--debug Show redacted command and working-directory diagnostics
|
|
2712
|
+
--unrestricted Enable full access (allow all executables and filesystem paths)
|
|
2691
2713
|
--json Emit machine-readable JSON events
|
|
2692
2714
|
-h, --help Show this help
|
|
2693
2715
|
|