@codingfrees/uap-device-control 0.1.18 → 0.1.20

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
@@ -30,7 +30,9 @@ npx @codingfrees/uap-device-control@latest remote
30
30
 
31
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.
32
32
 
33
- By default the Remote process also starts the loopback-only semantic browser bridge on port `8800`. 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>`.
33
+ 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
+
35
+ Existing extensions paired on the former port `8800` retain that port in browser storage. After updating npm Remote and Browser Extension, open **Device Control · Browser** in extension Settings and use **Reconnect browser bridge** with port `18700` (or the CLI-reported port). This moves the existing pairing after an explicit user action, rather than silently sending the saved bearer to a new local port or resetting device credentials. Use `browser-reset` only if pairing authority was lost or the extension was replaced.
34
36
 
35
37
  If a browser extension was replaced or lost its local token, stop `remote`, run `npx @codingfrees/uap-device-control@latest browser-reset`, then start `remote` again. This resets only the browser pairing and preserves the device identity and login.
36
38
 
@@ -99,3 +101,7 @@ Validate the exact release without publishing with `pnpm publish:public -- --dry
99
101
  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
102
 
101
103
  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.
104
+
105
+ ## UAP Downloads release candidates
106
+
107
+ The `UAP downloadable product candidates` workflow also builds the Node 26 portable `uap-device-control-remote-<version>.mjs`, its SHA-256 and sanitized provenance from the exact candidate source SHA. This executable JavaScript file **requires Node.js 26**; it is not a signed Windows/macOS native installer and is separate from the existing npm release channel. The private CI artifact is not a public UAP Downloads release. Each approved public release must embed Windows/Linux/macOS download, checksum, login, scoped-root, browser pairing and update/removal instructions in its description; live OS/browser certification and separate publication approval are required.
@@ -181,7 +181,7 @@ function exists(error) {
181
181
  // src/auth.ts
182
182
  var scopes = "device-control:device offline_access";
183
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");
184
+ if (options.pairingCode !== void 0 && !/^[A-Za-z0-9_-]{32}$/.test(options.pairingCode)) throw new TypeError("invalid single-use pairing code");
185
185
  const fetcher = options.fetcher ?? fetch;
186
186
  const issuer = canonicalOrigin(origin);
187
187
  const metadata = await json(fetcher(new URL("/.well-known/oauth-authorization-server", issuer), { redirect: "error", cache: "no-store" }));
@@ -208,7 +208,7 @@ async function loginDeviceControl(origin, stateDirectory, options = {}) {
208
208
  authorize2.searchParams.set("state", pkce.state);
209
209
  authorize2.searchParams.set("code_challenge", pkce.challenge);
210
210
  authorize2.searchParams.set("code_challenge_method", "S256");
211
- const result = await automaticPairing(fetcher, issuer, authorize2, options.pairingCode, pkce.state);
211
+ const result = options.pairingCode ? await automaticPairing(fetcher, issuer, authorize2, options.pairingCode, pkce.state) : await browserAuthorization(authorize2, callback.result, options.onAuthorizationUrl);
212
212
  if (result.state !== pkce.state || !result.code) throw new TypeError("OAuth callback is invalid");
213
213
  const token = await json(
214
214
  fetcher(tokenEndpoint, {
@@ -265,6 +265,10 @@ async function logoutDeviceControl(stateDirectory, fetcher = fetch) {
265
265
  await clearRemoteAuth(stateDirectory);
266
266
  return true;
267
267
  }
268
+ async function browserAuthorization(authorize2, result, onAuthorizationUrl) {
269
+ await onAuthorizationUrl?.(authorize2.href);
270
+ return result;
271
+ }
268
272
  async function automaticPairing(fetcher, issuer, authorize2, pairingCode, expectedState) {
269
273
  const started = await json(
270
274
  fetcher(new URL("/pairing/start", issuer), { method: "POST", headers: { "content-type": "application/json" }, body: JSON.stringify({ authorizeUrl: authorize2.href }), redirect: "error", cache: "no-store" })
@@ -299,6 +303,11 @@ async function callbackServer(timeoutMs) {
299
303
  return;
300
304
  }
301
305
  response.writeHead(200, { "content-type": "text/plain; charset=utf-8", "cache-control": "no-store" });
306
+ if (url.searchParams.has("error")) {
307
+ response.end("UAP Device Control authorization declined. You can close this window.");
308
+ reject(new TypeError("OAuth browser authorization was declined"));
309
+ return;
310
+ }
302
311
  response.end("UAP Device Control login completed. You can close this window.");
303
312
  settle({ code: url.searchParams.get("code") ?? void 0, state: url.searchParams.get("state") ?? void 0 });
304
313
  });
@@ -377,7 +386,7 @@ async function resetBrowserBridgePairing(stateDirectory) {
377
386
  await mkdir2(stateDirectory, { recursive: true, mode: 448 });
378
387
  await writeFile2(path2.join(stateDirectory, "browser-bridge.json"), JSON.stringify({ version: 1 }) + "\n", { mode: 384 });
379
388
  }
380
- async function createBrowserBridge(stateDirectory, requestedPort = 8800, log) {
389
+ async function createBrowserBridge(stateDirectory, requestedPort = 18700, log) {
381
390
  if (!Number.isInteger(requestedPort) || requestedPort !== 0 && (requestedPort < 1024 || requestedPort > 65535)) throw new TypeError("browser bridge port is invalid");
382
391
  await mkdir2(stateDirectory, { recursive: true, mode: 448 });
383
392
  const statePath = path2.join(stateDirectory, "browser-bridge.json");
@@ -615,7 +624,7 @@ import path4 from "node:path";
615
624
  // package.json
616
625
  var package_default = {
617
626
  name: "@codingfrees/uap-device-control",
618
- version: "0.1.18",
627
+ version: "0.1.20",
619
628
  description: "Cross-platform outbound UAP Device Control client",
620
629
  type: "module",
621
630
  bin: {
@@ -1714,9 +1723,10 @@ async function runRemote(options) {
1714
1723
  options.log?.(event);
1715
1724
  if (event.event === "browser.bridge" && ["paired", "unpaired", "connected", "permissions-granted", "permissions-required"].includes(String(event.status))) refreshSession();
1716
1725
  };
1717
- const browser = options.browserControl === false ? void 0 : await createBrowserBridge(options.stateDirectory, options.browserPort ?? 8800, browserLog).catch((error) => {
1726
+ const browserPort = options.browserPort ?? 18700;
1727
+ const browser = options.browserControl === false ? void 0 : await createBrowserBridge(options.stateDirectory, browserPort, browserLog).catch((error) => {
1718
1728
  if (!optionalBrowserBridgeFailure(error)) throw error;
1719
- options.log?.({ event: "browser.bridge", status: "unavailable" });
1729
+ options.log?.({ event: "browser.bridge", status: "unavailable", port: browserPort, errorCode: String(error.code) });
1720
1730
  return void 0;
1721
1731
  });
1722
1732
  if (browser) {
@@ -1789,15 +1799,22 @@ async function remoteSession(origin, stateDirectory, engine, fetcher = fetch, si
1789
1799
  if (next.command === null || next.command === void 0) continue;
1790
1800
  const command = commandValue(next.command);
1791
1801
  const startedAt = Date.now();
1802
+ let outcome;
1792
1803
  try {
1793
1804
  const output = await engine.execute(command.capability, command.parameters, { workspaceId: bounded2(next.workspaceId, "workspace id") });
1794
- await invoke2("/device-control/remote/result", { sessionId, deviceId, requestId: command.requestId, ok: true, output, executionMs: elapsed(startedAt) });
1805
+ outcome = { ok: true, output };
1795
1806
  } catch (error) {
1796
- await invoke2("/device-control/remote/result", { sessionId, deviceId, requestId: command.requestId, ok: false, error: safeError(error), executionMs: elapsed(startedAt) });
1807
+ outcome = { ok: false, error: safeError(error) };
1808
+ }
1809
+ try {
1810
+ await invoke2("/device-control/remote/result", { sessionId, deviceId, requestId: command.requestId, ...outcome, executionMs: elapsed(startedAt) });
1811
+ } catch (error) {
1812
+ if (!(error instanceof RemoteResultExpiredError)) throw error;
1813
+ log?.({ event: "remote.result", status: "expired", deviceId, requestId: command.requestId });
1797
1814
  }
1798
1815
  }
1799
1816
  } finally {
1800
- await invoke2("/device-control/remote/disconnect", { sessionId, deviceId }, void 0, 5e3, void 0).catch(() => void 0);
1817
+ await authorizedRequest(fetcher, origin, stateDirectory, "/device-control/remote/disconnect", { sessionId, deviceId }, void 0, 5e3).catch(() => void 0);
1801
1818
  log?.({ event: "remote.session", status: "disconnected", deviceId });
1802
1819
  }
1803
1820
  }
@@ -1832,9 +1849,12 @@ async function request(fetcher, origin, pathname, token, body, signal, timeoutMs
1832
1849
  throw new RemoteUnavailableError(void 0, pathname, controller.signal.aborted ? "timeout" : "transport");
1833
1850
  }
1834
1851
  if (response.status === 401 || response.status === 403) throw new RemoteAuthorizationError(response.status, pathname);
1835
- if (response.status === 409 && pathname === "/device-control/remote/poll") {
1852
+ if (response.status === 409 && (pathname === "/device-control/remote/poll" || pathname === "/device-control/remote/result")) {
1836
1853
  const body2 = await response.json().catch(() => void 0);
1837
- if (body2 && typeof body2 === "object" && !Array.isArray(body2) && "error" in body2 && body2.error === "session_expired") throw new RemoteSessionExpiredError(pathname);
1854
+ if (body2 && typeof body2 === "object" && !Array.isArray(body2) && "error" in body2) {
1855
+ if (body2.error === "session_expired") throw new RemoteSessionExpiredError(pathname);
1856
+ if (pathname.endsWith("/result") && body2.error === "request_not_pending") throw new RemoteResultExpiredError(pathname);
1857
+ }
1838
1858
  }
1839
1859
  if (!response.ok) throw new RemoteUnavailableError(response.status, pathname);
1840
1860
  const raw = await response.json();
@@ -1862,6 +1882,13 @@ var RemoteSessionExpiredError = class extends Error {
1862
1882
  }
1863
1883
  pathname;
1864
1884
  };
1885
+ var RemoteResultExpiredError = class extends Error {
1886
+ constructor(pathname) {
1887
+ super("remote command waiter expired before result acceptance");
1888
+ this.pathname = pathname;
1889
+ }
1890
+ pathname;
1891
+ };
1865
1892
  var RemoteUnavailableError = class extends Error {
1866
1893
  constructor(httpStatus, pathname, reason) {
1867
1894
  super("remote endpoint is unavailable");
@@ -1972,22 +1999,22 @@ async function installRemoteService(origin, stateDirectory) {
1972
1999
  }
1973
2000
  async function runnerV2Installed(platform = process.platform, run = execute3, exists2 = existsSync) {
1974
2001
  if (platform === "linux") {
1975
- if (exists2("/opt/uap-local-node-runner-v2/current")) return true;
2002
+ if (exists2("/opt/uap-local-runner/current")) return true;
1976
2003
  for (const args of [
1977
- ["list-unit-files", "uap-local-node-runner-v2.service", "--no-legend"],
1978
- ["--user", "list-unit-files", "uap-local-node-runner-v2.service", "--no-legend"]
2004
+ ["list-unit-files", "uap-local-runner.service", "--no-legend"],
2005
+ ["--user", "list-unit-files", "uap-local-runner.service", "--no-legend"]
1979
2006
  ]) {
1980
2007
  try {
1981
2008
  const result = await run("systemctl", args);
1982
- if (/^uap-local-node-runner-v2\.service\s/m.test(result.stdout)) return true;
2009
+ if (/^uap-local-runner\.service\s/m.test(result.stdout)) return true;
1983
2010
  } catch {
1984
2011
  }
1985
2012
  }
1986
2013
  }
1987
2014
  if (platform === "win32") {
1988
2015
  for (const [command, args] of [
1989
- ["sc.exe", ["query", "UAPLocalNodeRunnerV2"]],
1990
- ["schtasks.exe", ["/Query", "/TN", "UAPLocalNodeRunnerV2"]]
2016
+ ["sc.exe", ["query", "UAPLocalRunner"]],
2017
+ ["schtasks.exe", ["/Query", "/TN", "UAPLocalRunner"]]
1991
2018
  ]) {
1992
2019
  try {
1993
2020
  await run(command, [...args]);
@@ -2068,7 +2095,7 @@ function parseDeviceControlArguments(args, cwd = process.cwd()) {
2068
2095
  const allowedServices = [];
2069
2096
  let service = false;
2070
2097
  let browserControl = true;
2071
- let browserPort = 8800;
2098
+ let browserPort = 18700;
2072
2099
  let json2 = false;
2073
2100
  for (let index = command === "help" ? args.length : 1; index < args.length; index++) {
2074
2101
  const option = args[index];
@@ -2113,7 +2140,12 @@ async function runDeviceControlCli(args = process.argv.slice(2)) {
2113
2140
  const resolvedOrigin = resolveConfiguredOrigin(config.origin, existingAuth?.origin);
2114
2141
  const output = (event) => process.stdout.write(formatCliEvent(event, config.json) + "\n");
2115
2142
  if (config.command === "login") {
2116
- const auth = await loginDeviceControl(resolvedOrigin, config.stateDirectory, { pairingCode: config.pairingCode });
2143
+ const auth = await loginDeviceControl(resolvedOrigin, config.stateDirectory, {
2144
+ pairingCode: config.pairingCode,
2145
+ onAuthorizationUrl: (url) => {
2146
+ output({ event: "oauth.browser", status: "authorization-required", url });
2147
+ }
2148
+ });
2117
2149
  output({ status: "authenticated", origin: auth.origin });
2118
2150
  return;
2119
2151
  }
@@ -2147,7 +2179,12 @@ async function runDeviceControlCli(args = process.argv.slice(2)) {
2147
2179
  try {
2148
2180
  if (!existingAuth) {
2149
2181
  if (config.service) throw new TypeError("service mode requires login");
2150
- await loginDeviceControl(resolvedOrigin, config.stateDirectory, { pairingCode: config.pairingCode });
2182
+ await loginDeviceControl(resolvedOrigin, config.stateDirectory, {
2183
+ pairingCode: config.pairingCode,
2184
+ onAuthorizationUrl: (url) => {
2185
+ output({ event: "oauth.browser", status: "authorization-required", url });
2186
+ }
2187
+ });
2151
2188
  }
2152
2189
  const controller = new AbortController();
2153
2190
  for (const signal of ["SIGINT", "SIGTERM"]) process.once(signal, () => controller.abort());
@@ -2184,7 +2221,13 @@ function formatCliEvent(event, json2 = false) {
2184
2221
  if (status === "ready")
2185
2222
  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");
2186
2223
  if (status === "pairing-required") return "\u26A0\uFE0F Browser extension not connected; remote control continues without browser tools \xB7 pairing code " + String(event.pairingCode) + " \xB7 port " + String(event.port);
2187
- if (status === "unavailable") return "\u26A0\uFE0F Browser control unavailable; remote control continues with files, terminal and processes";
2224
+ if (status === "unavailable") {
2225
+ const code = ["EADDRINUSE", "EACCES", "EAFNOSUPPORT", "EPROTONOSUPPORT"].includes(String(event.errorCode)) ? String(event.errorCode) : "UNKNOWN";
2226
+ const port2 = Number.isInteger(event.port) && Number(event.port) >= 1024 && Number(event.port) <= 65535 ? Number(event.port) : 18700;
2227
+ const alternate = port2 === 65535 ? 8801 : port2 + 1;
2228
+ const help = code === "EADDRINUSE" ? "port already in use; inspect the listener or retry remote --browser-port " + alternate : code === "EACCES" ? "local port access denied; check reserved ports or retry remote --browser-port " + alternate : code === "EAFNOSUPPORT" || code === "EPROTONOSUPPORT" ? "local TCP/IPv4 networking unavailable; check OS networking" : "local bridge could not start";
2229
+ return "\u26A0\uFE0F Browser control unavailable \xB7 port " + port2 + " \xB7 " + code + " \xB7 " + help + "; files, terminal and processes remain available";
2230
+ }
2188
2231
  if (status === "paired") return "\u2705 UAP Browser Extension paired";
2189
2232
  if (status === "connected") return "\u{1F310} UAP Browser Extension connected";
2190
2233
  if (status === "unpaired") return "\u{1F50C} UAP Browser Extension unpaired";
@@ -2195,6 +2238,8 @@ function formatCliEvent(event, json2 = false) {
2195
2238
  if (status === "reconnecting") return "\u26A0\uFE0F Connection interrupted" + httpDetail(event) + " \xB7 retrying in " + String(event.retryMs) + " ms";
2196
2239
  if (status === "reauthorizing") return "\u{1F510} Refreshing Device Control authorization" + httpDetail(event);
2197
2240
  }
2241
+ if (event.event === "oauth.browser" && status === "authorization-required")
2242
+ return "Open this URL in a browser and explicitly approve this computer:\n" + String(event.url) + "\nIf using WSL2, open the link in Windows and keep this terminal running for the localhost callback.\nAlternatively, run login --pairing-code <code>.";
2198
2243
  if (status === "connecting") return "\u{1F310} Connecting to " + String(event.origin) + " \xB7 " + String(event.platform);
2199
2244
  if (status === "authenticated") return "\u2705 Authenticated \xB7 " + String(event.origin);
2200
2245
  if (status === "logged-out") return "\u2705 Logged out";
@@ -2228,7 +2273,7 @@ Usage:
2228
2273
  Commands:
2229
2274
  remote Connect this computer to Device Control
2230
2275
  status Show authentication, device and connection status
2231
- login Pair this computer using a temporary admin-issued code
2276
+ login Sign in through browser OAuth/PKCE or an admin-issued pairing code
2232
2277
  logout Remove the saved authorization
2233
2278
  browser-reset Reset only the saved browser-extension pairing
2234
2279
  install-service Install the authenticated Remote as a system service
@@ -2240,7 +2285,7 @@ Remote options:
2240
2285
  --read-only-root <id=path> Add a read-only filesystem root
2241
2286
  --allow-executable <path> Allow an executable for terminal commands
2242
2287
  --allow-service <name> Allow a native service
2243
- --browser-port <port> Browser extension bridge port (default: 8800)
2288
+ --browser-port <port> Browser extension bridge port (default: 18700)
2244
2289
  --no-browser-control Run without browser integration
2245
2290
  --state-dir <path> Override the local state directory
2246
2291
  --origin <https-origin> Override the Device Control service origin
@@ -2249,6 +2294,7 @@ Remote options:
2249
2294
 
2250
2295
  Examples:
2251
2296
  npx @codingfrees/uap-device-control@latest
2297
+ npx @codingfrees/uap-device-control@latest login
2252
2298
  npx @codingfrees/uap-device-control@latest login --pairing-code <code>
2253
2299
  npx @codingfrees/uap-device-control@latest browser-reset
2254
2300
  npx @codingfrees/uap-device-control@latest remote
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codingfrees/uap-device-control",
3
- "version": "0.1.18",
3
+ "version": "0.1.20",
4
4
  "description": "Cross-platform outbound UAP Device Control client",
5
5
  "type": "module",
6
6
  "bin": {