@codingfrees/uap-device-control 0.2.5 → 0.2.7

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/README.md CHANGED
@@ -28,7 +28,9 @@ You can also provide the origin through `UAP_DEVICE_CONTROL_ORIGIN`.
28
28
  npx @codingfrees/uap-device-control@latest remote
29
29
  ```
30
30
 
31
- The interactive CLI uses concise human-readable status lines by default (`✅`, `❌`, `⚠️`, `🔐`, `🌐`, `🔌`, `🔧`). Use `--json` for stable JSONL output in scripts and log collectors. Only one `remote` process may use a state directory at a time; starting a second process with the same device identity fails locally instead of replacing the live broker session. OAuth refresh is serialized across processes, and access-token renewal is retried in the existing broker session rather than forcing a device reconnect.
31
+ The interactive CLI uses concise human-readable status lines by default (`✅`, `❌`, `⚠️`, `🔐`, `🌐`, `🔌`, `🔧`). Use `--json` for stable JSONL output in scripts and log collectors. Only one `remote` process may use a state directory at a time; a new temporary Remote can replace a verified prior temporary instance, while unrelated or service-managed processes fail closed. OAuth refresh is serialized across processes, and access-token renewal is retried in the existing broker session rather than forcing a device reconnect.
32
+
33
+ Interactive `remote` sessions display the UAP Device Control banner at startup; JSON and service modes remain banner-free. Use `--debug` to add local terminal-command diagnostics containing the executable, redacted argument vector, working directory and shortened request ID. Environment values are never logged, and common credential-bearing flags and headers are redacted.
32
34
 
33
35
  By default the Remote process also starts the loopback-only semantic browser bridge on port `18700`. Until the UAP Browser Extension is paired, the CLI prints a short-lived pairing code. Browser control can be disabled with `--no-browser-control` or moved to another loopback port with `--browser-port <port>`.
34
36
 
@@ -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.5",
786
+ version: "0.2.7",
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())) throw new TypeError("executable is not allowed");
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 = () => process.platform === "win32" ? "powershell.exe" : "/bin/sh";
1574
- var defaultExecutables = () => process.platform === "win32" ? ["powershell.exe", "cmd.exe"] : ["/bin/sh", "/bin/bash"];
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] } : {},
@@ -1965,7 +1971,7 @@ async function runRemote(options) {
1965
1971
  options.signal?.addEventListener("abort", abort, { once: true });
1966
1972
  refreshSession = abort;
1967
1973
  try {
1968
- await remoteSession(options.origin, options.stateDirectory, engine, fetcher, sessionController.signal, options.log, options.socketFactory);
1974
+ await remoteSession(options.origin, options.stateDirectory, engine, fetcher, sessionController.signal, options.log, options.socketFactory, options.debug);
1969
1975
  delay = 500;
1970
1976
  } catch (error) {
1971
1977
  if (options.signal?.aborted) break;
@@ -2001,7 +2007,7 @@ function optionalBrowserBridgeFailure(error) {
2001
2007
  if (!error || typeof error !== "object" || !("code" in error)) return false;
2002
2008
  return ["EADDRINUSE", "EACCES", "EAFNOSUPPORT", "EPROTONOSUPPORT"].includes(String(error.code));
2003
2009
  }
2004
- async function remoteSession(origin, stateDirectory, engine, fetcher = fetch, signal, log, socketFactory = defaultSocketFactory) {
2010
+ async function remoteSession(origin, stateDirectory, engine, fetcher = fetch, signal, log, socketFactory = defaultSocketFactory, debug = false) {
2005
2011
  const deviceId = engine.options.deviceId;
2006
2012
  const socket = await authorizedSocket(origin, stateDirectory, fetcher, socketFactory, signal, log, deviceId);
2007
2013
  const inFlight = /* @__PURE__ */ new Set();
@@ -2024,10 +2030,13 @@ async function remoteSession(origin, stateDirectory, engine, fetcher = fetch, si
2024
2030
  const startedAt = Date.now();
2025
2031
  let outcome;
2026
2032
  try {
2033
+ if (debug && command.capability === "terminal.exec") log?.({ event: "remote.command", status: "executing", requestId: command.requestId, ...formatDebugCommand(command.parameters) });
2027
2034
  const output = await execute4(command, workspaceId);
2028
2035
  outcome = { ok: true, output };
2029
2036
  } catch (error) {
2030
- outcome = { ok: false, error: safeError(error) };
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 };
2031
2040
  }
2032
2041
  await sendResult(socket, acknowledgements, { type: "result", requestId: command.requestId, ...outcome, executionMs: elapsed(startedAt) });
2033
2042
  };
@@ -2124,6 +2133,23 @@ async function remoteSession(origin, stateDirectory, engine, fetcher = fetch, si
2124
2133
  log?.({ event: "remote.session", status: "disconnected", deviceId, ...closeCode === void 0 ? {} : { closeCode }, ...closeCause ? { closeCause } : {}, uptimeMs: elapsed(sessionStartedAt) });
2125
2134
  }
2126
2135
  }
2136
+ function formatDebugCommand(parameters) {
2137
+ const executable = typeof parameters.executable === "string" && parameters.executable ? parameters.executable : "<default-shell>";
2138
+ const source = Array.isArray(parameters.args) ? parameters.args.map(String) : [];
2139
+ const args = source.map((value, index) => index > 0 && sensitiveCommandFlag(source[index - 1]) ? "<redacted>" : redactCommandArgument(value));
2140
+ const command = [quoteCommandPart(executable), ...args.map(quoteCommandPart)].join(" ");
2141
+ return { command, ...typeof parameters.cwd === "string" && parameters.cwd ? { cwd: parameters.cwd } : {} };
2142
+ }
2143
+ function sensitiveCommandFlag(value) {
2144
+ return /^(?:--?(?:password|passwd|token|secret|api[-_]?key|authorization)|\/p)$/i.test(value);
2145
+ }
2146
+ function redactCommandArgument(value) {
2147
+ if (/^(?:--?(?:password|passwd|token|secret|api[-_]?key|authorization)|\/p)(?:=|:)/i.test(value)) return value.replace(/([=:]).*$/, "$1<redacted>");
2148
+ return value.replace(/\b(Bearer|Basic)\s+[A-Za-z0-9._~+/-]+=*/gi, "$1 <redacted>").replace(/\b([A-Z][A-Z0-9_]*(?:TOKEN|SECRET|PASSWORD|PASSWD|API_KEY))=([^\s]+)/g, "$1=<redacted>").replace(/(\s--?(?:password|passwd|token|secret|api[-_]?key|authorization)(?:[=:]|\s+))([^\s"']+)/gi, "$1<redacted>");
2149
+ }
2150
+ function quoteCommandPart(value) {
2151
+ return /^[A-Za-z0-9_./:\\-]+$/.test(value) ? value : JSON.stringify(value);
2152
+ }
2127
2153
  function defaultSocketFactory(url, token) {
2128
2154
  return new WebSocket(url, { headers: { authorization: "Bearer " + token } });
2129
2155
  }
@@ -2290,7 +2316,8 @@ function elapsed(startedAt) {
2290
2316
  return Math.min(864e5, Math.max(0, Math.round(Date.now() - startedAt)));
2291
2317
  }
2292
2318
  function safeError(error) {
2293
- return error instanceof TypeError ? error.message.slice(0, 256) : "device operation failed";
2319
+ if (error instanceof Error && error.message) return error.message.slice(0, 256);
2320
+ return "device operation failed";
2294
2321
  }
2295
2322
  function sleep2(ms, signal) {
2296
2323
  return new Promise((resolve) => {
@@ -2440,6 +2467,8 @@ function parseDeviceControlArguments(args, cwd = process.cwd()) {
2440
2467
  let service = false;
2441
2468
  let browserControl = true;
2442
2469
  let browserPort = 18700;
2470
+ let debug = false;
2471
+ let unrestricted = false;
2443
2472
  let json2 = false;
2444
2473
  for (let index = command === "help" ? args.length : 1; index < args.length; index++) {
2445
2474
  const option = args[index];
@@ -2455,11 +2484,16 @@ function parseDeviceControlArguments(args, cwd = process.cwd()) {
2455
2484
  else if (option === "--service") service = true;
2456
2485
  else if (option === "--no-browser-control") browserControl = false;
2457
2486
  else if (option === "--browser-port") browserPort = port(value, option), index++;
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'");
2458
2491
  else if (option === "--json") json2 = true;
2459
2492
  else throw new TypeError("unsupported UAP Device Control option: " + option);
2460
2493
  }
2461
2494
  const normalizedOrigin = origin === void 0 ? void 0 : canonicalOrigin(origin);
2462
- if (!roots.length && command === "remote") roots.push(...defaultRemoteRoots(cwd));
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));
2463
2497
  return {
2464
2498
  command,
2465
2499
  ...normalizedOrigin ? { origin: normalizedOrigin } : {},
@@ -2471,6 +2505,8 @@ function parseDeviceControlArguments(args, cwd = process.cwd()) {
2471
2505
  service,
2472
2506
  browserControl,
2473
2507
  browserPort,
2508
+ debug,
2509
+ unrestricted,
2474
2510
  json: json2
2475
2511
  };
2476
2512
  }
@@ -2521,6 +2557,7 @@ async function runDeviceControlCli(args = process.argv.slice(2)) {
2521
2557
  }
2522
2558
  const lease = await acquireRemoteProcessLock(config.stateDirectory, true);
2523
2559
  try {
2560
+ if (!config.json && !config.service) process.stdout.write(formatCliBanner() + "\n");
2524
2561
  if (lease.replaced) output({ event: "remote.session", status: "replaced" });
2525
2562
  if (!existingAuth) {
2526
2563
  if (config.service) throw new TypeError("service mode requires login");
@@ -2534,6 +2571,7 @@ async function runDeviceControlCli(args = process.argv.slice(2)) {
2534
2571
  const controller = new AbortController();
2535
2572
  for (const signal of ["SIGINT", "SIGTERM"]) process.once(signal, () => controller.abort());
2536
2573
  output({ status: "connecting", origin: resolvedOrigin, platform: process.platform });
2574
+ if (config.unrestricted) output({ event: "remote.mode", status: "unrestricted" });
2537
2575
  await runRemote({
2538
2576
  origin: resolvedOrigin,
2539
2577
  stateDirectory: config.stateDirectory,
@@ -2542,6 +2580,8 @@ async function runDeviceControlCli(args = process.argv.slice(2)) {
2542
2580
  allowedServices: config.allowedServices,
2543
2581
  browserControl: config.browserControl,
2544
2582
  browserPort: config.browserPort,
2583
+ debug: config.debug,
2584
+ unrestricted: config.unrestricted,
2545
2585
  signal: controller.signal,
2546
2586
  log: output
2547
2587
  });
@@ -2562,12 +2602,20 @@ function formatCliEvent(event, json2 = false) {
2562
2602
  const tool = String(event.tool ?? "tool");
2563
2603
  if (event.phase === "invoking") return "\u{1F527} " + tool + " \xB7 running" + (event.deviceId ? " \xB7 " + JSON.stringify(event, ["providerId", "deviceId"]) : "");
2564
2604
  if (event.phase === "failed") {
2565
- const failure = event.summary && typeof event.summary === "object" && !Array.isArray(event.summary) ? String(event.summary.error ?? "") : "";
2566
- return "\u274C " + tool + " \xB7 failed" + (failure ? " \xB7 " + failure : "");
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;
2567
2609
  }
2568
2610
  const summary2 = event.summary && typeof event.summary === "object" ? " \xB7 " + JSON.stringify(event.summary) : "";
2569
2611
  return "\u2705 " + tool + " \xB7 completed" + summary2;
2570
2612
  }
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") {
2615
+ const requestId = String(event.requestId ?? "").slice(0, 8);
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 : "");
2618
+ }
2571
2619
  if (event.event === "browser.bridge") {
2572
2620
  if (status === "ready")
2573
2621
  return "\u{1F310} Browser bridge ready \xB7 127.0.0.1:" + String(event.port) + (event.pairingStored ? " \xB7 pairing saved \xB7 extension offline; new extension? stop Remote, then run: npx @codingfrees/uap-device-control@latest browser-reset" : " \xB7 waiting for pairing");
@@ -2607,6 +2655,19 @@ function formatCliEvent(event, json2 = false) {
2607
2655
  if ("authenticated" in event) return (event.authenticated ? "\u2705" : "\u26A0\uFE0F") + " Device " + String(event.deviceId) + " \xB7 " + String(event.origin) + " \xB7 remote=" + JSON.stringify(event.remote);
2608
2656
  return "\u2139\uFE0F " + JSON.stringify(event);
2609
2657
  }
2658
+ function formatCliBanner() {
2659
+ return [
2660
+ "",
2661
+ " \u2588\u2588\u2557 \u2588\u2588\u2557 \u2588\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2588\u2588\u2588\u2588\u2557 ",
2662
+ " \u2588\u2588\u2551 \u2588\u2588\u2551\u2588\u2588\u2554\u2550\u2550\u2588\u2588\u2557\u2588\u2588\u2554\u2550\u2550\u2588\u2588\u2557",
2663
+ " \u2588\u2588\u2551 \u2588\u2588\u2551\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2551\u2588\u2588\u2588\u2588\u2588\u2588\u2554\u255D",
2664
+ " \u2588\u2588\u2551 \u2588\u2588\u2551\u2588\u2588\u2554\u2550\u2550\u2588\u2588\u2551\u2588\u2588\u2554\u2550\u2550\u2550\u255D ",
2665
+ " \u255A\u2588\u2588\u2588\u2588\u2588\u2588\u2554\u255D\u2588\u2588\u2551 \u2588\u2588\u2551\u2588\u2588\u2551 ",
2666
+ " \u255A\u2550\u2550\u2550\u2550\u2550\u255D \u255A\u2550\u255D \u255A\u2550\u255D\u255A\u2550\u255D ",
2667
+ " Universal Agent Platform \xB7 Device Control",
2668
+ ""
2669
+ ].join("\n");
2670
+ }
2610
2671
  async function checkRemoteStatus(origin, stateDirectory, deviceId, probe = remoteStatus) {
2611
2672
  for (let attempt = 0; attempt < 2; attempt++) {
2612
2673
  try {
@@ -2647,6 +2708,8 @@ Remote options:
2647
2708
  --no-browser-control Run without browser integration
2648
2709
  --state-dir <path> Override the local state directory
2649
2710
  --origin <https-origin> Override the Device Control service origin
2711
+ --debug Show redacted command and working-directory diagnostics
2712
+ --unrestricted Enable full access (allow all executables and filesystem paths)
2650
2713
  --json Emit machine-readable JSON events
2651
2714
  -h, --help Show this help
2652
2715
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codingfrees/uap-device-control",
3
- "version": "0.2.5",
3
+ "version": "0.2.7",
4
4
  "description": "Cross-platform outbound UAP Device Control client",
5
5
  "type": "module",
6
6
  "bin": {