@codingfrees/uap-device-control 0.2.5 → 0.2.6

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.6",
787
787
  description: "Cross-platform outbound UAP Device Control client",
788
788
  type: "module",
789
789
  bin: {
@@ -1965,7 +1965,7 @@ async function runRemote(options) {
1965
1965
  options.signal?.addEventListener("abort", abort, { once: true });
1966
1966
  refreshSession = abort;
1967
1967
  try {
1968
- await remoteSession(options.origin, options.stateDirectory, engine, fetcher, sessionController.signal, options.log, options.socketFactory);
1968
+ await remoteSession(options.origin, options.stateDirectory, engine, fetcher, sessionController.signal, options.log, options.socketFactory, options.debug);
1969
1969
  delay = 500;
1970
1970
  } catch (error) {
1971
1971
  if (options.signal?.aborted) break;
@@ -2001,7 +2001,7 @@ function optionalBrowserBridgeFailure(error) {
2001
2001
  if (!error || typeof error !== "object" || !("code" in error)) return false;
2002
2002
  return ["EADDRINUSE", "EACCES", "EAFNOSUPPORT", "EPROTONOSUPPORT"].includes(String(error.code));
2003
2003
  }
2004
- async function remoteSession(origin, stateDirectory, engine, fetcher = fetch, signal, log, socketFactory = defaultSocketFactory) {
2004
+ async function remoteSession(origin, stateDirectory, engine, fetcher = fetch, signal, log, socketFactory = defaultSocketFactory, debug = false) {
2005
2005
  const deviceId = engine.options.deviceId;
2006
2006
  const socket = await authorizedSocket(origin, stateDirectory, fetcher, socketFactory, signal, log, deviceId);
2007
2007
  const inFlight = /* @__PURE__ */ new Set();
@@ -2024,6 +2024,7 @@ async function remoteSession(origin, stateDirectory, engine, fetcher = fetch, si
2024
2024
  const startedAt = Date.now();
2025
2025
  let outcome;
2026
2026
  try {
2027
+ if (debug && command.capability === "terminal.exec") log?.({ event: "remote.command", status: "executing", requestId: command.requestId, ...formatDebugCommand(command.parameters) });
2027
2028
  const output = await execute4(command, workspaceId);
2028
2029
  outcome = { ok: true, output };
2029
2030
  } catch (error) {
@@ -2124,6 +2125,23 @@ async function remoteSession(origin, stateDirectory, engine, fetcher = fetch, si
2124
2125
  log?.({ event: "remote.session", status: "disconnected", deviceId, ...closeCode === void 0 ? {} : { closeCode }, ...closeCause ? { closeCause } : {}, uptimeMs: elapsed(sessionStartedAt) });
2125
2126
  }
2126
2127
  }
2128
+ function formatDebugCommand(parameters) {
2129
+ const executable = typeof parameters.executable === "string" && parameters.executable ? parameters.executable : "<default-shell>";
2130
+ const source = Array.isArray(parameters.args) ? parameters.args.map(String) : [];
2131
+ const args = source.map((value, index) => index > 0 && sensitiveCommandFlag(source[index - 1]) ? "<redacted>" : redactCommandArgument(value));
2132
+ const command = [quoteCommandPart(executable), ...args.map(quoteCommandPart)].join(" ");
2133
+ return { command, ...typeof parameters.cwd === "string" && parameters.cwd ? { cwd: parameters.cwd } : {} };
2134
+ }
2135
+ function sensitiveCommandFlag(value) {
2136
+ return /^(?:--?(?:password|passwd|token|secret|api[-_]?key|authorization)|\/p)$/i.test(value);
2137
+ }
2138
+ function redactCommandArgument(value) {
2139
+ if (/^(?:--?(?:password|passwd|token|secret|api[-_]?key|authorization)|\/p)(?:=|:)/i.test(value)) return value.replace(/([=:]).*$/, "$1<redacted>");
2140
+ 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>");
2141
+ }
2142
+ function quoteCommandPart(value) {
2143
+ return /^[A-Za-z0-9_./:\\-]+$/.test(value) ? value : JSON.stringify(value);
2144
+ }
2127
2145
  function defaultSocketFactory(url, token) {
2128
2146
  return new WebSocket(url, { headers: { authorization: "Bearer " + token } });
2129
2147
  }
@@ -2440,6 +2458,7 @@ function parseDeviceControlArguments(args, cwd = process.cwd()) {
2440
2458
  let service = false;
2441
2459
  let browserControl = true;
2442
2460
  let browserPort = 18700;
2461
+ let debug = false;
2443
2462
  let json2 = false;
2444
2463
  for (let index = command === "help" ? args.length : 1; index < args.length; index++) {
2445
2464
  const option = args[index];
@@ -2455,6 +2474,7 @@ function parseDeviceControlArguments(args, cwd = process.cwd()) {
2455
2474
  else if (option === "--service") service = true;
2456
2475
  else if (option === "--no-browser-control") browserControl = false;
2457
2476
  else if (option === "--browser-port") browserPort = port(value, option), index++;
2477
+ else if (option === "--debug") debug = true;
2458
2478
  else if (option === "--json") json2 = true;
2459
2479
  else throw new TypeError("unsupported UAP Device Control option: " + option);
2460
2480
  }
@@ -2471,6 +2491,7 @@ function parseDeviceControlArguments(args, cwd = process.cwd()) {
2471
2491
  service,
2472
2492
  browserControl,
2473
2493
  browserPort,
2494
+ debug,
2474
2495
  json: json2
2475
2496
  };
2476
2497
  }
@@ -2521,6 +2542,7 @@ async function runDeviceControlCli(args = process.argv.slice(2)) {
2521
2542
  }
2522
2543
  const lease = await acquireRemoteProcessLock(config.stateDirectory, true);
2523
2544
  try {
2545
+ if (!config.json && !config.service) process.stdout.write(formatCliBanner() + "\n");
2524
2546
  if (lease.replaced) output({ event: "remote.session", status: "replaced" });
2525
2547
  if (!existingAuth) {
2526
2548
  if (config.service) throw new TypeError("service mode requires login");
@@ -2542,6 +2564,7 @@ async function runDeviceControlCli(args = process.argv.slice(2)) {
2542
2564
  allowedServices: config.allowedServices,
2543
2565
  browserControl: config.browserControl,
2544
2566
  browserPort: config.browserPort,
2567
+ debug: config.debug,
2545
2568
  signal: controller.signal,
2546
2569
  log: output
2547
2570
  });
@@ -2568,6 +2591,10 @@ function formatCliEvent(event, json2 = false) {
2568
2591
  const summary2 = event.summary && typeof event.summary === "object" ? " \xB7 " + JSON.stringify(event.summary) : "";
2569
2592
  return "\u2705 " + tool + " \xB7 completed" + summary2;
2570
2593
  }
2594
+ if (event.event === "remote.command" && event.status === "executing") {
2595
+ 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 : "");
2597
+ }
2571
2598
  if (event.event === "browser.bridge") {
2572
2599
  if (status === "ready")
2573
2600
  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 +2634,19 @@ function formatCliEvent(event, json2 = false) {
2607
2634
  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
2635
  return "\u2139\uFE0F " + JSON.stringify(event);
2609
2636
  }
2637
+ function formatCliBanner() {
2638
+ return [
2639
+ "",
2640
+ " \u2588\u2588\u2557 \u2588\u2588\u2557 \u2588\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2588\u2588\u2588\u2588\u2557 ",
2641
+ " \u2588\u2588\u2551 \u2588\u2588\u2551\u2588\u2588\u2554\u2550\u2550\u2588\u2588\u2557\u2588\u2588\u2554\u2550\u2550\u2588\u2588\u2557",
2642
+ " \u2588\u2588\u2551 \u2588\u2588\u2551\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2551\u2588\u2588\u2588\u2588\u2588\u2588\u2554\u255D",
2643
+ " \u2588\u2588\u2551 \u2588\u2588\u2551\u2588\u2588\u2554\u2550\u2550\u2588\u2588\u2551\u2588\u2588\u2554\u2550\u2550\u2550\u255D ",
2644
+ " \u255A\u2588\u2588\u2588\u2588\u2588\u2588\u2554\u255D\u2588\u2588\u2551 \u2588\u2588\u2551\u2588\u2588\u2551 ",
2645
+ " \u255A\u2550\u2550\u2550\u2550\u2550\u255D \u255A\u2550\u255D \u255A\u2550\u255D\u255A\u2550\u255D ",
2646
+ " Universal Agent Platform \xB7 Device Control",
2647
+ ""
2648
+ ].join("\n");
2649
+ }
2610
2650
  async function checkRemoteStatus(origin, stateDirectory, deviceId, probe = remoteStatus) {
2611
2651
  for (let attempt = 0; attempt < 2; attempt++) {
2612
2652
  try {
@@ -2647,6 +2687,7 @@ Remote options:
2647
2687
  --no-browser-control Run without browser integration
2648
2688
  --state-dir <path> Override the local state directory
2649
2689
  --origin <https-origin> Override the Device Control service origin
2690
+ --debug Show redacted command and working-directory diagnostics
2650
2691
  --json Emit machine-readable JSON events
2651
2692
  -h, --help Show this help
2652
2693
 
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.6",
4
4
  "description": "Cross-platform outbound UAP Device Control client",
5
5
  "type": "module",
6
6
  "bin": {