@codingfrees/uap-device-control 0.1.8 → 0.1.10

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
@@ -72,6 +72,8 @@ npx @codingfrees/uap-device-control@latest install-service
72
72
 
73
73
  The same runtime is persisted using the platform adapter (Windows scheduled startup, Linux systemd user service, macOS launchd).
74
74
 
75
+ The `install-service` command refuses to install a second persistent Remote if an installed Runner V2 is detected on Windows or Linux; temporary `remote` mode remains independent. Service installation stages the runtime atomically and retains a `.previous` copy for rollback if registration fails. This is not a signed automatic update channel; npm publishing and OS-service updating remain separate lifecycles.
76
+
75
77
  ## npm client versus ChatGPT MCP
76
78
 
77
79
  The npm client does **not** use MCP as its device transport. It needs the public UAP origin for OAuth and the outbound Device Control routes under `/device-control/remote/*`.
@@ -92,4 +94,6 @@ pnpm publish:public
92
94
 
93
95
  Validate the exact release without publishing with `pnpm publish:public -- --dry-run`.
94
96
 
97
+ 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.
98
+
95
99
  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.
@@ -407,7 +407,7 @@ import path4 from "node:path";
407
407
  // package.json
408
408
  var package_default = {
409
409
  name: "@codingfrees/uap-device-control",
410
- version: "0.1.8",
410
+ version: "0.1.10",
411
411
  description: "Cross-platform outbound UAP Device Control client",
412
412
  type: "module",
413
413
  bin: {
@@ -1167,7 +1167,18 @@ async function windowsAdapter(run) {
1167
1167
  const monitors = monitorId ? JSON.parse(asText((await invoke2(WINDOWS_MONITORS)).stdout)) : [];
1168
1168
  const monitor = monitorId ? monitors.find((item) => item.id === monitorId) : void 0;
1169
1169
  if (monitorId && !monitor) throw new TypeError("screen monitor is unavailable");
1170
- await invoke2(WINDOWS_POINTER, pointerArguments(monitor ? { ...input, x: integer2(input.x, 0, 1e5, "x") + monitor.x, y: integer2(input.y, 0, 1e5, "y") + monitor.y, toX: integer2(input.toX ?? input.x, 0, 1e5, "toX") + monitor.x, toY: integer2(input.toY ?? input.y, 0, 1e5, "toY") + monitor.y } : input));
1170
+ await invoke2(
1171
+ WINDOWS_POINTER,
1172
+ pointerArguments(
1173
+ monitor ? {
1174
+ ...input,
1175
+ x: integer2(input.x, 0, 1e5, "x") + monitor.x,
1176
+ y: integer2(input.y, 0, 1e5, "y") + monitor.y,
1177
+ toX: integer2(input.toX ?? input.x, 0, 1e5, "toX") + monitor.x,
1178
+ toY: integer2(input.toY ?? input.y, 0, 1e5, "toY") + monitor.y
1179
+ } : input
1180
+ )
1181
+ );
1171
1182
  },
1172
1183
  keyboard: async (input) => {
1173
1184
  await invoke2(WINDOWS_KEYBOARD, [windowsKeyboardSequence(input)]);
@@ -1184,7 +1195,10 @@ async function windowsInteropScreenAdapter(run) {
1184
1195
  const version = await run(executable, ["-NoProfile", "-NonInteractive", "-Command", "$PSVersionTable.PSVersion.ToString()"], { ...commandOptions(), timeout: 2e3 });
1185
1196
  if (!/^\d+(?:\.\d+)+/.test(asText(version.stdout).trim())) continue;
1186
1197
  const invoke2 = (script, args = []) => powershellInvoke(run, executable, script, args);
1187
- return { monitors: async () => JSON.parse(asText((await invoke2(WINDOWS_MONITORS)).stdout)), captureScreen: async (monitorId, options) => JSON.parse(asText((await invoke2(WINDOWS_CAPTURE, [monitorId ?? "0", options?.format ?? "png", String(options?.quality ?? 100)])).stdout)) };
1198
+ return {
1199
+ monitors: async () => JSON.parse(asText((await invoke2(WINDOWS_MONITORS)).stdout)),
1200
+ captureScreen: async (monitorId, options) => JSON.parse(asText((await invoke2(WINDOWS_CAPTURE, [monitorId ?? "0", options?.format ?? "png", String(options?.quality ?? 100)])).stdout))
1201
+ };
1188
1202
  } catch {
1189
1203
  }
1190
1204
  }
@@ -1203,7 +1217,11 @@ async function linuxAdapter(run) {
1203
1217
  const monitors = parseXrandrGeometry(asText((await run("xrandr", ["--query"], commandOptions())).stdout));
1204
1218
  const monitor2 = monitorId ? monitors.find((item) => item.id === monitorId) : monitors.find((item) => item.primary) ?? monitors[0];
1205
1219
  if (!monitor2) throw new TypeError("screen monitor is unavailable");
1206
- const output2 = await run("import", ["-window", "root", "-crop", `${monitor2.width}x${monitor2.height}+${monitor2.x}+${monitor2.y}`, ...options.format === "jpeg" ? ["-quality", String(options.quality)] : [], `${options.format}:-`], binaryOptions());
1220
+ const output2 = await run(
1221
+ "import",
1222
+ ["-window", "root", "-crop", `${monitor2.width}x${monitor2.height}+${monitor2.x}+${monitor2.y}`, ...options.format === "jpeg" ? ["-quality", String(options.quality)] : [], `${options.format}:-`],
1223
+ binaryOptions()
1224
+ );
1207
1225
  const bytes2 = screenImage(asBuffer(output2.stdout), options.format);
1208
1226
  return { contentType: `image/${options.format}`, contentBase64: bytes2.toString("base64"), width: monitor2.width, height: monitor2.height, monitorId: monitor2.id };
1209
1227
  }
@@ -1273,10 +1291,11 @@ function windowsKeyboardSequence(input) {
1273
1291
  }
1274
1292
  const key = text3(input.key, 64, "keyboard key");
1275
1293
  if (/^F(?:[1-9]|1[0-2])$/.test(key)) return "{" + key + "}";
1276
- const token = WINDOWS_KEY_TOKENS[key];
1277
- if (!token) throw new TypeError("keyboard key is invalid");
1278
1294
  const modifiers = modifierList(input.modifiers);
1279
- return (modifiers.includes("Control") ? "^" : "") + (modifiers.includes("Alt") ? "%" : "") + (modifiers.includes("Shift") ? "+" : "") + token;
1295
+ if (modifiers.includes("Meta")) throw new TypeError("Meta keyboard modifier is unavailable on Windows");
1296
+ const token = WINDOWS_KEY_TOKENS[key] ?? (/^[a-zA-Z0-9]$/.test(key) ? key.toLowerCase() : null);
1297
+ if (!token) throw new TypeError("keyboard key is invalid; use a named key, F1-F12, or a single letter/digit");
1298
+ return (modifiers.includes("Control") ? "^" : "") + (modifiers.includes("Alt") ? "%" : "") + (modifiers.includes("Shift") || /^[A-Z]$/.test(key) && modifiers.length === 0 ? "+" : "") + token;
1280
1299
  }
1281
1300
  function linuxKeySequence(key, rawModifiers) {
1282
1301
  const aliases = { Control: "ctrl", Alt: "alt", Shift: "shift", Meta: "super" };
@@ -1717,7 +1736,11 @@ async function runRemote(options) {
1717
1736
  options.log?.(event);
1718
1737
  if (event.event === "browser.bridge" && (event.status === "paired" || event.status === "unpaired")) refreshSession();
1719
1738
  };
1720
- const browser = options.browserControl === false ? void 0 : await createBrowserBridge(options.stateDirectory, options.browserPort ?? 8800, browserLog);
1739
+ const browser = options.browserControl === false ? void 0 : await createBrowserBridge(options.stateDirectory, options.browserPort ?? 8800, browserLog).catch((error) => {
1740
+ if (!optionalBrowserBridgeFailure(error)) throw error;
1741
+ options.log?.({ event: "browser.bridge", status: "unavailable" });
1742
+ return void 0;
1743
+ });
1721
1744
  if (browser) {
1722
1745
  options.log?.({ event: "browser.bridge", status: "ready", port: browser.port, paired: browser.paired });
1723
1746
  if (browser.pairingCode) options.log?.({ event: "browser.bridge", status: "pairing-required", port: browser.port, pairingCode: browser.pairingCode });
@@ -1770,6 +1793,10 @@ async function runRemote(options) {
1770
1793
  engine.close();
1771
1794
  }
1772
1795
  }
1796
+ function optionalBrowserBridgeFailure(error) {
1797
+ if (!error || typeof error !== "object" || !("code" in error)) return false;
1798
+ return ["EADDRINUSE", "EACCES", "EAFNOSUPPORT", "EPROTONOSUPPORT"].includes(String(error.code));
1799
+ }
1773
1800
  async function remoteSession(origin, stateDirectory, engine, fetcher = fetch, signal, log) {
1774
1801
  const deviceId = engine.options.deviceId;
1775
1802
  const invoke2 = (pathname, body, requestSignal = signal, timeoutMs = 15e3, requestLog = log) => authorizedRequest(fetcher, origin, stateDirectory, pathname, body, requestSignal, timeoutMs, requestLog, deviceId);
@@ -1917,23 +1944,66 @@ function sleep2(ms, signal) {
1917
1944
  // src/service.ts
1918
1945
  import os4 from "node:os";
1919
1946
  import path5 from "node:path";
1920
- import { chmod, copyFile, mkdir as mkdir4, writeFile as writeFile4 } from "node:fs/promises";
1947
+ import { chmod, copyFile, mkdir as mkdir4, rename as rename3, rm as rm3, writeFile as writeFile4 } from "node:fs/promises";
1948
+ import { existsSync } from "node:fs";
1921
1949
  import { execFile as execFile4 } from "node:child_process";
1922
1950
  import { promisify as promisify4 } from "node:util";
1923
1951
  var execute4 = promisify4(execFile4);
1924
1952
  async function installRemoteService(origin, stateDirectory) {
1953
+ if (await runnerV2Installed()) throw new TypeError("Runner V2 is installed; use its Device Control provider instead of installing a duplicate Remote service");
1925
1954
  const command = process.execPath;
1926
1955
  const source = process.argv[1];
1927
1956
  if (!source) throw new TypeError("CLI executable path is unavailable");
1928
1957
  await mkdir4(stateDirectory, { recursive: true, mode: 448 });
1929
1958
  const script = path5.join(stateDirectory, "uap-device-control.mjs");
1930
- await copyFile(source, script);
1931
- if (process.platform !== "win32") await chmod(script, 448);
1959
+ const staged = script + ".pending-" + process.pid;
1960
+ const previous = script + ".previous";
1932
1961
  const args = [script, "remote", "--origin", origin, "--state-dir", stateDirectory, "--service"];
1933
- if (process.platform === "linux") return installSystemd(command, args);
1934
- if (process.platform === "darwin") return installLaunchd(command, args);
1935
- if (process.platform === "win32") return installWindowsTask(command, args);
1936
- throw new TypeError("service installation is unsupported on this platform");
1962
+ try {
1963
+ await copyFile(source, staged);
1964
+ if (process.platform !== "win32") await chmod(staged, 448);
1965
+ if (existsSync(script)) await copyFile(script, previous);
1966
+ await rename3(staged, script);
1967
+ try {
1968
+ if (process.platform === "linux") return await installSystemd(command, args);
1969
+ if (process.platform === "darwin") return await installLaunchd(command, args);
1970
+ if (process.platform === "win32") return await installWindowsTask(command, args);
1971
+ throw new TypeError("service installation is unsupported on this platform");
1972
+ } catch (error) {
1973
+ if (existsSync(previous)) await copyFile(previous, script);
1974
+ throw error;
1975
+ }
1976
+ } finally {
1977
+ await rm3(staged, { force: true }).catch(() => void 0);
1978
+ }
1979
+ }
1980
+ async function runnerV2Installed(platform = process.platform, run = execute4, exists2 = existsSync) {
1981
+ if (platform === "linux") {
1982
+ if (exists2("/opt/uap-local-node-runner-v2/current")) return true;
1983
+ for (const args of [
1984
+ ["list-unit-files", "uap-local-node-runner-v2.service", "--no-legend"],
1985
+ ["--user", "list-unit-files", "uap-local-node-runner-v2.service", "--no-legend"]
1986
+ ]) {
1987
+ try {
1988
+ const result = await run("systemctl", args);
1989
+ if (/^uap-local-node-runner-v2\.service\s/m.test(result.stdout)) return true;
1990
+ } catch {
1991
+ }
1992
+ }
1993
+ }
1994
+ if (platform === "win32") {
1995
+ for (const [command, args] of [
1996
+ ["sc.exe", ["query", "UAPLocalNodeRunnerV2"]],
1997
+ ["schtasks.exe", ["/Query", "/TN", "UAPLocalNodeRunnerV2"]]
1998
+ ]) {
1999
+ try {
2000
+ await run(command, [...args]);
2001
+ return true;
2002
+ } catch {
2003
+ }
2004
+ }
2005
+ }
2006
+ return false;
1937
2007
  }
1938
2008
  async function installSystemd(command, args) {
1939
2009
  const directory = path5.join(os4.homedir(), ".config", "systemd", "user");
@@ -1995,8 +2065,8 @@ function xml(value) {
1995
2065
  // src/cli.ts
1996
2066
  var DEFAULT_DEVICE_CONTROL_ORIGIN = "https://device-control.aemdpc.ro";
1997
2067
  function parseDeviceControlArguments(args, cwd = process.cwd()) {
1998
- const command = args[0];
1999
- if (!["remote", "status", "login", "logout", "install-service"].includes(command ?? "")) throw new TypeError("command must be remote, status, login, logout, or install-service");
2068
+ const command = !args.length || args.includes("--help") || args.includes("-h") || args[0] === "help" ? "help" : args[0];
2069
+ if (!["help", "remote", "status", "login", "logout", "install-service"].includes(command ?? "")) throw new TypeError("unknown command; run uap-device-control help");
2000
2070
  let origin = process.env.UAP_DEVICE_CONTROL_ORIGIN;
2001
2071
  let stateDirectory = defaultDeviceControlStateDirectory();
2002
2072
  const roots = [];
@@ -2006,7 +2076,7 @@ function parseDeviceControlArguments(args, cwd = process.cwd()) {
2006
2076
  let browserControl = true;
2007
2077
  let browserPort = 8800;
2008
2078
  let json2 = false;
2009
- for (let index = 1; index < args.length; index++) {
2079
+ for (let index = command === "help" ? args.length : 1; index < args.length; index++) {
2010
2080
  const option = args[index];
2011
2081
  const value = args[index + 1];
2012
2082
  if (option === "--origin") origin = required(value, option), index++;
@@ -2039,6 +2109,10 @@ function parseDeviceControlArguments(args, cwd = process.cwd()) {
2039
2109
  }
2040
2110
  async function runDeviceControlCli(args = process.argv.slice(2)) {
2041
2111
  const config = parseDeviceControlArguments(args);
2112
+ if (config.command === "help") {
2113
+ process.stdout.write(deviceControlHelp());
2114
+ return;
2115
+ }
2042
2116
  const existingAuth = await loadRemoteAuth(config.stateDirectory);
2043
2117
  const resolvedOrigin = resolveConfiguredOrigin(config.origin, existingAuth?.origin);
2044
2118
  const output = (event) => process.stdout.write(formatCliEvent(event, config.json) + "\n");
@@ -2100,7 +2174,8 @@ function formatCliEvent(event, json2 = false) {
2100
2174
  }
2101
2175
  if (event.event === "browser.bridge") {
2102
2176
  if (status === "ready") return "\u{1F310} Browser bridge ready \xB7 127.0.0.1:" + String(event.port) + (event.paired ? " \xB7 paired" : " \xB7 waiting for pairing");
2103
- if (status === "pairing-required") return "\u{1F510} Browser pairing code: " + String(event.pairingCode) + " \xB7 port " + String(event.port);
2177
+ 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);
2178
+ if (status === "unavailable") return "\u26A0\uFE0F Browser control unavailable; remote control continues with files, terminal and processes";
2104
2179
  if (status === "paired") return "\u2705 UAP Browser Extension paired";
2105
2180
  if (status === "connected") return "\u{1F310} UAP Browser Extension connected";
2106
2181
  if (status === "unpaired") return "\u{1F50C} UAP Browser Extension unpaired";
@@ -2119,6 +2194,39 @@ function formatCliEvent(event, json2 = false) {
2119
2194
  if ("authenticated" in event) return (event.authenticated ? "\u2705" : "\u26A0\uFE0F") + " Device " + String(event.deviceId) + " \xB7 " + String(event.origin) + " \xB7 remote=" + JSON.stringify(event.remote);
2120
2195
  return "\u2139\uFE0F " + JSON.stringify(event);
2121
2196
  }
2197
+ function deviceControlHelp() {
2198
+ return `UAP Device Control
2199
+
2200
+ Usage:
2201
+ uap-device-control <command> [options]
2202
+
2203
+ Commands:
2204
+ remote Connect this computer to Device Control
2205
+ status Show authentication, device and connection status
2206
+ login Authorize this computer in your browser
2207
+ logout Remove the saved authorization
2208
+ install-service Install the authenticated Remote as a system service
2209
+ help Show this help
2210
+
2211
+ Remote options:
2212
+ --root <id=path> Add a writable filesystem root
2213
+ --read-only-root <id=path> Add a read-only filesystem root
2214
+ --allow-executable <path> Allow an executable for terminal commands
2215
+ --allow-service <name> Allow a native service
2216
+ --browser-port <port> Browser extension bridge port (default: 8800)
2217
+ --no-browser-control Run without browser integration
2218
+ --state-dir <path> Override the local state directory
2219
+ --origin <https-origin> Override the Device Control service origin
2220
+ --json Emit machine-readable JSON events
2221
+ -h, --help Show this help
2222
+
2223
+ Examples:
2224
+ npx @codingfrees/uap-device-control@latest
2225
+ npx @codingfrees/uap-device-control@latest login
2226
+ npx @codingfrees/uap-device-control@latest remote
2227
+ npx @codingfrees/uap-device-control@latest remote --no-browser-control
2228
+ `;
2229
+ }
2122
2230
  function httpDetail(event) {
2123
2231
  const status = Number(event.httpStatus);
2124
2232
  const pathname = typeof event.pathname === "string" && /^\/[A-Za-z0-9._~!$&'()*+,;=:@%/-]{1,255}$/.test(event.pathname) ? event.pathname : "";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codingfrees/uap-device-control",
3
- "version": "0.1.8",
3
+ "version": "0.1.10",
4
4
  "description": "Cross-platform outbound UAP Device Control client",
5
5
  "type": "module",
6
6
  "bin": {