@codingfrees/uap-device-control 0.1.15 → 0.1.17

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
@@ -15,10 +15,10 @@ Runner, WSL, `cloudflared`, a separately installed Device Agent and an inbound d
15
15
  The public npm package does not embed a development, staging or production hostname. Select the intended UAP environment explicitly on first login:
16
16
 
17
17
  ```bash
18
- npx @codingfrees/uap-device-control@latest login --origin https://<uap-device-control-origin>
18
+ npx @codingfrees/uap-device-control@latest login --origin https://<uap-device-control-origin> --pairing-code <temporary-admin-code>
19
19
  ```
20
20
 
21
- The browser OAuth flow stores a device-scoped credential for that exact origin. Later commands reuse the stored origin. To change environments, logout first and then login against the other origin.
21
+ Open the UAP Device Control /admin console, select the authorized owner or workspace identity, and generate a one-time pairing code (valid for five minutes). The CLI exchanges this code via OAuth PKCE and stores a revocable device-scoped credential for the exact origin; it does not require GitHub/Google login. Later commands reuse the saved origin and credential. To change environments, logout first and then pair with the other origin.
22
22
 
23
23
  You can also provide the origin through `UAP_DEVICE_CONTROL_ORIGIN`.
24
24
 
@@ -98,4 +98,4 @@ Validate the exact release without publishing with `pnpm publish:public -- --dry
98
98
 
99
99
  For `npm whoami` HTTP 401 in Linux/WSL, renew authentication locally using `npm login --registry=https://registry.npmjs.org/ --auth-type=web`, then confirm `npm whoami`. Do not paste credentials into issue reports or logs. npm versions are immutable: bump the package version and commit a clean tree before publishing.
100
100
 
101
- The script requires a clean repository, refuses an already-published version, builds and dry-runs the package, then calls npm publish and verifies the registry version plus the `latest` dist-tag. npm account 2FA remains mandatory and is handled by npm during the publish step.
101
+ The script requires clean package inputs, refuses an already-published version, builds and dry-runs the package, then calls npm publish and verifies the registry version plus the `latest` dist-tag. The root `pnpm deploy:npm` entrypoint invokes the publisher directly; a separate package-local node_modules directory is unnecessary when workspace dependencies are installed. npm account 2FA remains mandatory and is handled by npm during the publish step.
@@ -5,8 +5,6 @@ import path6 from "node:path";
5
5
 
6
6
  // src/auth.ts
7
7
  import { createServer } from "node:http";
8
- import { execFile } from "node:child_process";
9
- import { promisify } from "node:util";
10
8
 
11
9
  // ../../packages/web-crypto/src/index.ts
12
10
  var encoder = new TextEncoder();
@@ -62,25 +60,6 @@ import os from "node:os";
62
60
  import path from "node:path";
63
61
  import { link, mkdir, readFile, rm, rename, writeFile } from "node:fs/promises";
64
62
  import { randomUUID } from "node:crypto";
65
- function defaultOwnerBootstrapPath(home = os.homedir(), platform = process.platform) {
66
- if (platform === "win32") return path.join(process.env.LOCALAPPDATA || path.join(home, "AppData", "Local"), "UAP", "DeviceControl", "owner-bootstrap.json");
67
- if (platform === "darwin") return path.join(home, "Library", "Application Support", "UAP", "DeviceControl", "owner-bootstrap.json");
68
- return path.join(process.env.XDG_CONFIG_HOME || path.join(home, ".config"), "uap-device-control", "owner-bootstrap.json");
69
- }
70
- async function loadOwnerBootstrapCredential(expectedOrigin, file = defaultOwnerBootstrapPath()) {
71
- try {
72
- const raw = JSON.parse(await readFile(file, "utf8"));
73
- if (!raw || typeof raw !== "object" || Array.isArray(raw)) throw new TypeError("owner bootstrap credential is invalid");
74
- const value = raw;
75
- if (value.origin !== expectedOrigin || typeof value.secret !== "string" || value.secret.length < 24 || value.secret.length > 512 || /[\u0000-\u001f\u007f]/.test(value.secret)) {
76
- throw new TypeError("owner bootstrap credential is invalid");
77
- }
78
- return { origin: expectedOrigin, secret: value.secret };
79
- } catch (error) {
80
- if (missing(error)) return void 0;
81
- throw error;
82
- }
83
- }
84
63
  function defaultDeviceControlStateDirectory(home = os.homedir(), platform = process.platform) {
85
64
  if (platform === "win32") return path.join(process.env.LOCALAPPDATA || path.join(home, "AppData", "Local"), "UAP", "DeviceControl");
86
65
  if (platform === "darwin") return path.join(home, "Library", "Application Support", "UAP", "DeviceControl");
@@ -200,9 +179,9 @@ function exists(error) {
200
179
  }
201
180
 
202
181
  // src/auth.ts
203
- var execute = promisify(execFile);
204
182
  var scopes = "device-control:device offline_access";
205
183
  async function loginDeviceControl(origin, stateDirectory, options = {}) {
184
+ if (!options.pairingCode || !/^[A-Za-z0-9_-]{32}$/.test(options.pairingCode)) throw new TypeError("A single-use pairing code from the admin console is required");
206
185
  const fetcher = options.fetcher ?? fetch;
207
186
  const issuer = canonicalOrigin(origin);
208
187
  const metadata = await json(fetcher(new URL("/.well-known/oauth-authorization-server", issuer), { redirect: "error", cache: "no-store" }));
@@ -229,8 +208,7 @@ async function loginDeviceControl(origin, stateDirectory, options = {}) {
229
208
  authorize2.searchParams.set("state", pkce.state);
230
209
  authorize2.searchParams.set("code_challenge", pkce.challenge);
231
210
  authorize2.searchParams.set("code_challenge_method", "S256");
232
- const configuredBootstrap = options.ownerBootstrapSecret === void 0 ? await loadOwnerBootstrapCredential(issuer).then((value) => value?.secret) : options.ownerBootstrapSecret ?? void 0;
233
- const result = configuredBootstrap ? await automaticPairing(fetcher, issuer, authorize2, configuredBootstrap, pkce.state) : await browserAuthorization(options.open ?? openBrowser, authorize2.href, callback.result);
211
+ const result = await automaticPairing(fetcher, issuer, authorize2, options.pairingCode, pkce.state);
234
212
  if (result.state !== pkce.state || !result.code) throw new TypeError("OAuth callback is invalid");
235
213
  const token = await json(
236
214
  fetcher(tokenEndpoint, {
@@ -261,7 +239,8 @@ async function accessToken(stateDirectory, fetcher = fetch, forceRefresh = false
261
239
  fetcher(tokenEndpoint, {
262
240
  method: "POST",
263
241
  headers: { "content-type": "application/x-www-form-urlencoded" },
264
- body: new URLSearchParams({ grant_type: "refresh_token", client_id: auth.clientId, refresh_token: auth.refreshToken, resource: auth.origin + "/mcp" })
242
+ body: new URLSearchParams({ grant_type: "refresh_token", client_id: auth.clientId, refresh_token: auth.refreshToken, resource: auth.origin + "/mcp" }),
243
+ signal: AbortSignal.timeout(1e4)
265
244
  })
266
245
  );
267
246
  const next = {
@@ -286,7 +265,7 @@ async function logoutDeviceControl(stateDirectory, fetcher = fetch) {
286
265
  await clearRemoteAuth(stateDirectory);
287
266
  return true;
288
267
  }
289
- async function automaticPairing(fetcher, issuer, authorize2, ownerSecret, expectedState) {
268
+ async function automaticPairing(fetcher, issuer, authorize2, pairingCode, expectedState) {
290
269
  const started = await json(
291
270
  fetcher(new URL("/pairing/start", issuer), { method: "POST", headers: { "content-type": "application/json" }, body: JSON.stringify({ authorizeUrl: authorize2.href }), redirect: "error", cache: "no-store" })
292
271
  );
@@ -295,7 +274,7 @@ async function automaticPairing(fetcher, issuer, authorize2, ownerSecret, expect
295
274
  await json(
296
275
  fetcher(new URL("/pairing/approve", issuer), {
297
276
  method: "POST",
298
- headers: { "content-type": "application/json", authorization: "Bearer " + ownerSecret },
277
+ headers: { "content-type": "application/json", "x-uap-pairing-code": pairingCode },
299
278
  body: JSON.stringify({ pairingId }),
300
279
  redirect: "error",
301
280
  cache: "no-store"
@@ -309,10 +288,6 @@ async function automaticPairing(fetcher, issuer, authorize2, ownerSecret, expect
309
288
  if (redirect.searchParams.get("state") !== expectedState) throw new TypeError("pairing callback state is invalid");
310
289
  return { code: redirect.searchParams.get("code") ?? void 0, state: redirect.searchParams.get("state") ?? void 0 };
311
290
  }
312
- async function browserAuthorization(open, authorizeUrl, result) {
313
- await open(authorizeUrl);
314
- return result;
315
- }
316
291
  async function callbackServer(timeoutMs) {
317
292
  let settle;
318
293
  let reject;
@@ -344,15 +319,6 @@ async function callbackServer(timeoutMs) {
344
319
  }
345
320
  };
346
321
  }
347
- function browserOpenCommand(platform, url) {
348
- if (platform === "win32") return { command: "rundll32.exe", args: ["url.dll,FileProtocolHandler", url] };
349
- if (platform === "darwin") return { command: "open", args: [url] };
350
- return { command: "xdg-open", args: [url] };
351
- }
352
- async function openBrowser(url) {
353
- const launch = browserOpenCommand(process.platform, url);
354
- await execute(launch.command, launch.args, { windowsHide: true });
355
- }
356
322
  async function requiredDeviceAuth(stateDirectory) {
357
323
  const auth = await loadRemoteAuth(stateDirectory);
358
324
  if (!auth) throw new TypeError("not logged in");
@@ -415,8 +381,8 @@ async function createBrowserBridge(stateDirectory, requestedPort = 8800, log) {
415
381
  if (!Number.isInteger(requestedPort) || requestedPort !== 0 && (requestedPort < 1024 || requestedPort > 65535)) throw new TypeError("browser bridge port is invalid");
416
382
  await mkdir2(stateDirectory, { recursive: true, mode: 448 });
417
383
  const statePath = path2.join(stateDirectory, "browser-bridge.json");
418
- let pairing = await loadPairing(statePath);
419
- let pairingCode = pairing ? void 0 : createPairingCode();
384
+ let pairing2 = await loadPairing(statePath);
385
+ let pairingCode = pairing2 ? void 0 : createPairingCode();
420
386
  let pairingExpiresAt = pairingCode ? Date.now() + 10 * 6e4 : 0;
421
387
  let lastSeen = 0;
422
388
  let permissionsGranted = false;
@@ -433,7 +399,7 @@ async function createBrowserBridge(stateDirectory, requestedPort = 8800, log) {
433
399
  const body = await jsonBody(request2);
434
400
  const extensionId = extensionIdValue(body.extensionId);
435
401
  if (origin !== "chrome-extension://" + extensionId) throw new TypeError("browser extension origin is invalid");
436
- if (pairing) throw new TypeError("browser bridge is already paired");
402
+ if (pairing2) throw new TypeError("browser bridge is already paired");
437
403
  const candidate = pairingCodeValue(body.pairingCode);
438
404
  if (!pairingCode || Date.now() > pairingExpiresAt) {
439
405
  pairingCode = createPairingCode();
@@ -443,14 +409,14 @@ async function createBrowserBridge(stateDirectory, requestedPort = 8800, log) {
443
409
  }
444
410
  if (!secureEqual(candidate, pairingCode)) throw new TypeError("browser pairing code is invalid");
445
411
  const token = randomBytes2(32).toString("base64url");
446
- pairing = { extensionId, tokenHash: digest(token) };
412
+ pairing2 = { extensionId, tokenHash: digest(token) };
447
413
  pairingCode = void 0;
448
414
  pairingExpiresAt = 0;
449
- await persistPairing(statePath, pairing);
415
+ await persistPairing(statePath, pairing2);
450
416
  log?.({ event: "browser.bridge", status: "paired" });
451
417
  return send(response, 200, { token, port: actualPort(server) }, origin);
452
418
  }
453
- const current = authorize(request2, origin, pairing);
419
+ const current = authorize(request2, origin, pairing2);
454
420
  if (url.pathname === "/browser/status" && request2.method === "POST") {
455
421
  const wasOffline = Date.now() - lastSeen >= 45e3;
456
422
  lastSeen = Date.now();
@@ -458,7 +424,7 @@ async function createBrowserBridge(stateDirectory, requestedPort = 8800, log) {
458
424
  return send(response, 200, { paired: true, online: true, permissionsGranted }, current.origin);
459
425
  }
460
426
  if (url.pathname === "/browser/unpair" && request2.method === "POST") {
461
- pairing = void 0;
427
+ pairing2 = void 0;
462
428
  pairingCode = createPairingCode();
463
429
  pairingExpiresAt = Date.now() + 10 * 6e4;
464
430
  lastSeen = 0;
@@ -521,11 +487,11 @@ async function createBrowserBridge(stateDirectory, requestedPort = 8800, log) {
521
487
  return pairingCode;
522
488
  },
523
489
  available() {
524
- return Boolean(pairing && permissionsGranted && Date.now() - lastSeen < 45e3);
490
+ return Boolean(pairing2 && permissionsGranted && Date.now() - lastSeen < 45e3);
525
491
  },
526
492
  execute(capability, parameters) {
527
493
  if (!BROWSER_CONTROL_CAPABILITIES.includes(capability)) throw new TypeError("browser capability is unavailable");
528
- if (!pairing || !permissionsGranted || Date.now() - lastSeen >= 45e3) return Promise.reject(new TypeError("browser control extension is unavailable or missing permissions"));
494
+ if (!pairing2 || !permissionsGranted || Date.now() - lastSeen >= 45e3) return Promise.reject(new TypeError("browser control extension is unavailable or missing permissions"));
529
495
  const requestId = randomUUID2();
530
496
  const command = { requestId, capability, parameters };
531
497
  const completion = new Promise((resolve, reject) => {
@@ -550,10 +516,10 @@ async function createBrowserBridge(stateDirectory, requestedPort = 8800, log) {
550
516
  }
551
517
  };
552
518
  }
553
- function authorize(request2, origin, pairing) {
554
- if (!pairing || origin !== "chrome-extension://" + pairing.extensionId) throw new TypeError("browser bridge is not paired");
519
+ function authorize(request2, origin, pairing2) {
520
+ if (!pairing2 || origin !== "chrome-extension://" + pairing2.extensionId) throw new TypeError("browser bridge is not paired");
555
521
  const auth = request2.headers.authorization;
556
- if (!auth?.startsWith("Bearer ") || digest(auth.slice(7)) !== pairing.tokenHash) throw new TypeError("browser bridge authorization failed");
522
+ if (!auth?.startsWith("Bearer ") || digest(auth.slice(7)) !== pairing2.tokenHash) throw new TypeError("browser bridge authorization failed");
557
523
  return { origin };
558
524
  }
559
525
  function cors(response, origin, status) {
@@ -599,8 +565,8 @@ async function loadPairing(file) {
599
565
  return void 0;
600
566
  }
601
567
  }
602
- async function persistPairing(file, pairing) {
603
- await writeFile2(file, JSON.stringify({ version: 1, ...pairing }) + "\n", { mode: 384 });
568
+ async function persistPairing(file, pairing2) {
569
+ await writeFile2(file, JSON.stringify({ version: 1, ...pairing2 }) + "\n", { mode: 384 });
604
570
  }
605
571
  function rejectAll(pending, message) {
606
572
  for (const value of pending.values()) {
@@ -649,7 +615,7 @@ import path4 from "node:path";
649
615
  // package.json
650
616
  var package_default = {
651
617
  name: "@codingfrees/uap-device-control",
652
- version: "0.1.15",
618
+ version: "0.1.17",
653
619
  description: "Cross-platform outbound UAP Device Control client",
654
620
  type: "module",
655
621
  bin: {
@@ -1385,10 +1351,10 @@ var defaultShell = () => process.platform === "win32" ? "powershell.exe" : "/bin
1385
1351
  var defaultExecutables = () => process.platform === "win32" ? ["powershell.exe", "cmd.exe"] : ["/bin/sh", "/bin/bash"];
1386
1352
 
1387
1353
  // ../device-agent/src/native-desktop.ts
1388
- import { execFile as execFile2 } from "node:child_process";
1389
- import { promisify as promisify2 } from "node:util";
1390
- var execute2 = promisify2(execFile2);
1391
- async function createNativeDesktopAdapter(platform = process.platform, run = execute2) {
1354
+ import { execFile } from "node:child_process";
1355
+ import { promisify } from "node:util";
1356
+ var execute = promisify(execFile);
1357
+ async function createNativeDesktopAdapter(platform = process.platform, run = execute) {
1392
1358
  if (platform === "win32") return windowsAdapter(run);
1393
1359
  if (platform === "linux") {
1394
1360
  const interop = await windowsInteropScreenAdapter(run);
@@ -1643,15 +1609,15 @@ var WINDOWS_CLIPBOARD_READ = "Add-Type -AssemblyName System.Windows.Forms;[Conso
1643
1609
  var WINDOWS_CLIPBOARD_WRITE = "param($text) Add-Type -AssemblyName System.Windows.Forms;[System.Windows.Forms.Clipboard]::SetText($text)";
1644
1610
 
1645
1611
  // ../device-agent/src/native-services.ts
1646
- import { execFile as execFile3 } from "node:child_process";
1612
+ import { execFile as execFile2 } from "node:child_process";
1647
1613
  import { realpath as realpath2, stat as stat2 } from "node:fs/promises";
1648
1614
  import { win32 } from "node:path";
1649
- import { promisify as promisify3 } from "node:util";
1650
- var execute3 = promisify3(execFile3);
1615
+ import { promisify as promisify2 } from "node:util";
1616
+ var execute2 = promisify2(execFile2);
1651
1617
  async function createNativeServiceAdapter(options = {}) {
1652
1618
  const platform = options.platform ?? process.platform;
1653
1619
  const environment2 = options.environment ?? process.env;
1654
- const run = options.run ?? execute3;
1620
+ const run = options.run ?? execute2;
1655
1621
  const resolveExecutable = options.resolveExecutable ?? firstExecutable;
1656
1622
  let readCommand;
1657
1623
  let controlCommands;
@@ -1972,9 +1938,9 @@ import os4 from "node:os";
1972
1938
  import path5 from "node:path";
1973
1939
  import { chmod, copyFile, mkdir as mkdir4, rename as rename3, rm as rm3, writeFile as writeFile4 } from "node:fs/promises";
1974
1940
  import { existsSync } from "node:fs";
1975
- import { execFile as execFile4 } from "node:child_process";
1976
- import { promisify as promisify4 } from "node:util";
1977
- var execute4 = promisify4(execFile4);
1941
+ import { execFile as execFile3 } from "node:child_process";
1942
+ import { promisify as promisify3 } from "node:util";
1943
+ var execute3 = promisify3(execFile3);
1978
1944
  async function installRemoteService(origin, stateDirectory) {
1979
1945
  if (await runnerV2Installed()) throw new TypeError("Runner V2 is installed; use its Device Control provider instead of installing a duplicate Remote service");
1980
1946
  const command = process.execPath;
@@ -2003,7 +1969,7 @@ async function installRemoteService(origin, stateDirectory) {
2003
1969
  await rm3(staged, { force: true }).catch(() => void 0);
2004
1970
  }
2005
1971
  }
2006
- async function runnerV2Installed(platform = process.platform, run = execute4, exists2 = existsSync) {
1972
+ async function runnerV2Installed(platform = process.platform, run = execute3, exists2 = existsSync) {
2007
1973
  if (platform === "linux") {
2008
1974
  if (exists2("/opt/uap-local-node-runner-v2/current")) return true;
2009
1975
  for (const args of [
@@ -2055,8 +2021,8 @@ async function installSystemd(command, args) {
2055
2021
  ].join("\n"),
2056
2022
  { mode: 384 }
2057
2023
  );
2058
- await execute4("systemctl", ["--user", "daemon-reload"]);
2059
- await execute4("systemctl", ["--user", "enable", "--now", "uap-device-control.service"]);
2024
+ await execute3("systemctl", ["--user", "daemon-reload"]);
2025
+ await execute3("systemctl", ["--user", "enable", "--now", "uap-device-control.service"]);
2060
2026
  return { platform: "linux", location };
2061
2027
  }
2062
2028
  async function installLaunchd(command, args) {
@@ -2067,15 +2033,15 @@ async function installLaunchd(command, args) {
2067
2033
  const plist = '<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"><plist version="1.0"><dict><key>Label</key><string>ro.codingfrees.uap-device-control</string><key>ProgramArguments</key><array>' + escaped + "</array><key>RunAtLoad</key><true/><key>KeepAlive</key><true/></dict></plist>";
2068
2034
  await writeFile4(location, plist, { mode: 384 });
2069
2035
  const domain = "gui/" + process.getuid?.();
2070
- await execute4("launchctl", ["bootout", domain, location]).catch(() => void 0);
2071
- await execute4("launchctl", ["bootstrap", domain, location]);
2036
+ await execute3("launchctl", ["bootout", domain, location]).catch(() => void 0);
2037
+ await execute3("launchctl", ["bootstrap", domain, location]);
2072
2038
  return { platform: "darwin", location };
2073
2039
  }
2074
2040
  async function installWindowsTask(command, args) {
2075
2041
  const location = "UAP Device Control";
2076
2042
  const taskCommand = quoteWindows(command) + " " + args.map(quoteWindows).join(" ");
2077
- await execute4("schtasks.exe", ["/Create", "/F", "/SC", "ONLOGON", "/TN", location, "/TR", taskCommand]);
2078
- await execute4("schtasks.exe", ["/Run", "/TN", location]);
2043
+ await execute3("schtasks.exe", ["/Create", "/F", "/SC", "ONLOGON", "/TN", location, "/TR", taskCommand]);
2044
+ await execute3("schtasks.exe", ["/Run", "/TN", location]);
2079
2045
  return { platform: "win32", location };
2080
2046
  }
2081
2047
  function systemdEscape(command, args) {
@@ -2094,6 +2060,7 @@ function parseDeviceControlArguments(args, cwd = process.cwd()) {
2094
2060
  const command = !args.length || args.includes("--help") || args.includes("-h") || args[0] === "help" ? "help" : args[0];
2095
2061
  if (!["help", "remote", "status", "login", "logout", "browser-reset", "install-service"].includes(command ?? "")) throw new TypeError("unknown command; run uap-device-control help");
2096
2062
  let origin = process.env.UAP_DEVICE_CONTROL_ORIGIN;
2063
+ let pairingCode;
2097
2064
  let stateDirectory = defaultDeviceControlStateDirectory();
2098
2065
  const roots = [];
2099
2066
  const allowedExecutables = [];
@@ -2106,6 +2073,7 @@ function parseDeviceControlArguments(args, cwd = process.cwd()) {
2106
2073
  const option = args[index];
2107
2074
  const value = args[index + 1];
2108
2075
  if (option === "--origin") origin = required(value, option), index++;
2076
+ else if (option === "--pairing-code") pairingCode = pairing(value), index++;
2109
2077
  else if (option === "--state-dir") stateDirectory = absolute(value, option), index++;
2110
2078
  else if (option === "--root" || option === "--read-only-root") {
2111
2079
  roots.push(root(required(value, option), option === "--read-only-root"));
@@ -2123,6 +2091,7 @@ function parseDeviceControlArguments(args, cwd = process.cwd()) {
2123
2091
  return {
2124
2092
  command,
2125
2093
  ...normalizedOrigin ? { origin: normalizedOrigin } : {},
2094
+ ...pairingCode ? { pairingCode } : {},
2126
2095
  stateDirectory,
2127
2096
  roots,
2128
2097
  allowedExecutables,
@@ -2143,7 +2112,7 @@ async function runDeviceControlCli(args = process.argv.slice(2)) {
2143
2112
  const resolvedOrigin = resolveConfiguredOrigin(config.origin, existingAuth?.origin);
2144
2113
  const output = (event) => process.stdout.write(formatCliEvent(event, config.json) + "\n");
2145
2114
  if (config.command === "login") {
2146
- const auth = await loginDeviceControl(resolvedOrigin, config.stateDirectory);
2115
+ const auth = await loginDeviceControl(resolvedOrigin, config.stateDirectory, { pairingCode: config.pairingCode });
2147
2116
  output({ status: "authenticated", origin: auth.origin });
2148
2117
  return;
2149
2118
  }
@@ -2178,7 +2147,7 @@ async function runDeviceControlCli(args = process.argv.slice(2)) {
2178
2147
  try {
2179
2148
  if (!existingAuth) {
2180
2149
  if (config.service) throw new TypeError("service mode requires login");
2181
- await loginDeviceControl(resolvedOrigin, config.stateDirectory);
2150
+ await loginDeviceControl(resolvedOrigin, config.stateDirectory, { pairingCode: config.pairingCode });
2182
2151
  }
2183
2152
  const controller = new AbortController();
2184
2153
  for (const signal of ["SIGINT", "SIGTERM"]) process.once(signal, () => controller.abort());
@@ -2204,7 +2173,10 @@ function formatCliEvent(event, json2 = false) {
2204
2173
  if (event.event === "plugin.tool") {
2205
2174
  const tool = String(event.tool ?? "tool");
2206
2175
  if (event.phase === "invoking") return "\u{1F527} " + tool + " \xB7 running" + (event.deviceId ? " \xB7 " + JSON.stringify(event, ["providerId", "deviceId"]) : "");
2207
- if (event.phase === "failed") return "\u274C " + tool + " \xB7 failed";
2176
+ if (event.phase === "failed") {
2177
+ const failure = event.summary && typeof event.summary === "object" && !Array.isArray(event.summary) ? String(event.summary.error ?? "") : "";
2178
+ return "\u274C " + tool + " \xB7 failed" + (failure ? " \xB7 " + failure : "");
2179
+ }
2208
2180
  const summary2 = event.summary && typeof event.summary === "object" ? " \xB7 " + JSON.stringify(event.summary) : "";
2209
2181
  return "\u2705 " + tool + " \xB7 completed" + summary2;
2210
2182
  }
@@ -2241,13 +2213,14 @@ Usage:
2241
2213
  Commands:
2242
2214
  remote Connect this computer to Device Control
2243
2215
  status Show authentication, device and connection status
2244
- login Authorize this computer in your browser
2216
+ login Pair this computer using a temporary admin-issued code
2245
2217
  logout Remove the saved authorization
2246
2218
  browser-reset Reset only the saved browser-extension pairing
2247
2219
  install-service Install the authenticated Remote as a system service
2248
2220
  help Show this help
2249
2221
 
2250
2222
  Remote options:
2223
+ --pairing-code <code> One-time code generated in the admin console
2251
2224
  --root <id=path> Add a writable filesystem root
2252
2225
  --read-only-root <id=path> Add a read-only filesystem root
2253
2226
  --allow-executable <path> Allow an executable for terminal commands
@@ -2261,7 +2234,7 @@ Remote options:
2261
2234
 
2262
2235
  Examples:
2263
2236
  npx @codingfrees/uap-device-control@latest
2264
- npx @codingfrees/uap-device-control@latest login
2237
+ npx @codingfrees/uap-device-control@latest login --pairing-code <code>
2265
2238
  npx @codingfrees/uap-device-control@latest browser-reset
2266
2239
  npx @codingfrees/uap-device-control@latest remote
2267
2240
  npx @codingfrees/uap-device-control@latest remote --no-browser-control
@@ -2295,6 +2268,10 @@ function port(value, label) {
2295
2268
  if (!Number.isInteger(result) || result < 1024 || result > 65535) throw new TypeError(label + " is invalid");
2296
2269
  return result;
2297
2270
  }
2271
+ function pairing(value) {
2272
+ if (!value || !/^[A-Za-z0-9_-]{32}$/.test(value)) throw new TypeError("pairing code must be a valid 32-character code from the admin console");
2273
+ return value;
2274
+ }
2298
2275
  function identifier2(value, label) {
2299
2276
  const result = required(value, label);
2300
2277
  if (!/^[A-Za-z0-9_.@:-]{1,256}$/.test(result)) throw new TypeError(label + " is invalid");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codingfrees/uap-device-control",
3
- "version": "0.1.15",
3
+ "version": "0.1.17",
4
4
  "description": "Cross-platform outbound UAP Device Control client",
5
5
  "type": "module",
6
6
  "bin": {