@codingfrees/uap-device-control 0.2.11 → 0.2.13

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/DISCLOSURE ADDED
@@ -0,0 +1,14 @@
1
+ UAP Device Control is an authorized remote device administration client.
2
+ It can perform terminal, filesystem, process, screen and optional browser
3
+ operations on an enrolled device, making its capabilities security-relevant
4
+ and dual-use.
5
+
6
+ Its intended use is administration of devices controlled by the owner or
7
+ a person who has explicitly authorized that access. The client requires
8
+ authenticated device enrollment, origin-bound credentials, capability
9
+ restrictions, and elevated approval for sensitive operations. It must not
10
+ be used to access systems without authorization.
11
+
12
+ Publication is submitted to npm staging. Public promotion requires a
13
+ maintainer to review the staged package and complete npm two-factor
14
+ authentication; automated OIDC staging does not bypass this requirement.
package/README.md CHANGED
@@ -4,7 +4,7 @@ Cross-platform outbound Device Control client for Universal Agent Platform.
4
4
 
5
5
  ## Requirements
6
6
 
7
- - Node.js 26.x (`>=26.8.1 <27`)
7
+ - Node.js 24.18.1 or later, 25.x, or 26.x (`>=24.18.1 <27`). Prefer supported LTS majors for ongoing installations.
8
8
  - a public UAP Device Control origin for first login
9
9
  - Windows, Linux or macOS
10
10
 
@@ -28,7 +28,7 @@ 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; 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.
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. On relays advertising `transport-ping-v1`, a bounded 30-second application heartbeat receives automatic responses while the Durable Object hibernates; a missing reply causes the CLI to replace the silent half-open transport. Older relays continue using on-demand presence probes until both sides are updated.
32
32
 
33
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.
34
34
 
@@ -110,7 +110,7 @@ The client opens only outbound HTTPS connections plus the optional browser bridg
110
110
 
111
111
  ## Publishing
112
112
 
113
- Publish a verified public release from this package with:
113
+ Stage a verified dual-use release for npm maintainer approval with:
114
114
 
115
115
  ```bash
116
116
  pnpm publish:public
@@ -120,7 +120,7 @@ Validate the exact release without publishing with `pnpm publish:public -- --dry
120
120
 
121
121
  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.
122
122
 
123
- 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.
123
+ The script requires clean package inputs, the persistent `contentPolicy` declaration and bundled `DISCLOSURE`, and an unused version. It builds and checks the package, then calls `npm stage publish`. The root `pnpm deploy:npm` entrypoint uses the same staging script. A maintainer must inspect and explicitly approve the stage on npmjs.com with 2FA before the version becomes publicly available; the script does not bypass npm identity checks or claim a staged version is published.
124
124
 
125
125
  ## UAP Downloads release candidates
126
126
 
@@ -234,19 +234,19 @@ async function loginDeviceControl(origin, stateDirectory, options = {}) {
234
234
  if (options.pairingCode !== void 0 && !/^[A-Za-z0-9_-]{32}$/.test(options.pairingCode)) throw new TypeError("invalid single-use pairing code");
235
235
  const fetcher = options.fetcher ?? fetch;
236
236
  const issuer = canonicalOrigin(origin);
237
- const metadata = await json(fetcher(new URL("/.well-known/oauth-authorization-server", issuer), { redirect: "error", cache: "no-store" }));
237
+ const requestTimeoutMs = options.requestTimeoutMs ?? 15e3;
238
+ const requestJson = (url, init = {}) => timedJson(fetcher, url, init, requestTimeoutMs);
239
+ const metadata = await requestJson(new URL("/.well-known/oauth-authorization-server", issuer), { redirect: "error", cache: "no-store" });
238
240
  const authorizationEndpoint = exactHttps(metadata.authorization_endpoint, issuer);
239
241
  const tokenEndpoint = exactHttps(metadata.token_endpoint, issuer);
240
242
  const registrationEndpoint = exactHttps(metadata.registration_endpoint, issuer);
241
- const callback = await callbackServer(options.timeoutMs ?? 12e4);
243
+ const callback = await callbackServer();
242
244
  try {
243
- const registration = await json(
244
- fetcher(registrationEndpoint, {
245
- method: "POST",
246
- headers: { "content-type": "application/json" },
247
- body: JSON.stringify({ redirect_uris: [callback.redirectUri], token_endpoint_auth_method: "none", grant_types: ["authorization_code", "refresh_token"], response_types: ["code"] })
248
- })
249
- );
245
+ const registration = await requestJson(registrationEndpoint, {
246
+ method: "POST",
247
+ headers: { "content-type": "application/json" },
248
+ body: JSON.stringify({ redirect_uris: [callback.redirectUri], token_endpoint_auth_method: "none", grant_types: ["authorization_code", "refresh_token"], response_types: ["code"] })
249
+ });
250
250
  const clientId = text(registration.client_id, "OAuth client id");
251
251
  const pkce = await createOAuthPkce();
252
252
  const authorize2 = new URL(authorizationEndpoint);
@@ -258,15 +258,13 @@ async function loginDeviceControl(origin, stateDirectory, options = {}) {
258
258
  authorize2.searchParams.set("state", pkce.state);
259
259
  authorize2.searchParams.set("code_challenge", pkce.challenge);
260
260
  authorize2.searchParams.set("code_challenge_method", "S256");
261
- const result = options.pairingCode ? await automaticPairing(fetcher, issuer, authorize2, options.pairingCode, pkce.state) : await browserAuthorization(authorize2, callback.result, options.onAuthorizationUrl);
261
+ const result = options.pairingCode ? await automaticPairing(requestJson, issuer, authorize2, options.pairingCode, pkce.state) : await browserAuthorization(authorize2, callback.result, options.onAuthorizationUrl, options.timeoutMs ?? 8 * 6e4);
262
262
  if (result.state !== pkce.state || !result.code) throw new TypeError("OAuth callback is invalid");
263
- const token = await json(
264
- fetcher(tokenEndpoint, {
265
- method: "POST",
266
- headers: { "content-type": "application/x-www-form-urlencoded" },
267
- body: new URLSearchParams({ grant_type: "authorization_code", client_id: clientId, code: result.code, redirect_uri: callback.redirectUri, code_verifier: pkce.verifier, resource: issuer + "/mcp" })
268
- })
269
- );
263
+ const token = await requestJson(tokenEndpoint, {
264
+ method: "POST",
265
+ headers: { "content-type": "application/x-www-form-urlencoded" },
266
+ body: new URLSearchParams({ grant_type: "authorization_code", client_id: clientId, code: result.code, redirect_uri: callback.redirectUri, code_verifier: pkce.verifier, resource: issuer + "/mcp" })
267
+ });
270
268
  const refreshToken = text(token.refresh_token, "OAuth refresh token");
271
269
  const accessToken2 = text(token.access_token, "OAuth access token");
272
270
  const expiresIn = integer(token.expires_in, "OAuth expiry");
@@ -329,37 +327,65 @@ async function logoutDeviceControl(stateDirectory, fetcher = fetch) {
329
327
  await clearRemoteAuth(stateDirectory);
330
328
  return true;
331
329
  }
332
- async function browserAuthorization(authorize2, result, onAuthorizationUrl) {
330
+ async function browserAuthorization(authorize2, result, onAuthorizationUrl, timeoutMs) {
333
331
  await onAuthorizationUrl?.(authorize2.href);
334
- return result;
332
+ return withTimeout(result, timeoutMs, "OAuth browser authorization timed out; finish Google sign-in and select Authorize this computer in the same browser.");
335
333
  }
336
- async function automaticPairing(fetcher, issuer, authorize2, pairingCode, expectedState) {
337
- const started = await json(
338
- fetcher(new URL("/pairing/start", issuer), { method: "POST", headers: { "content-type": "application/json" }, body: JSON.stringify({ authorizeUrl: authorize2.href }), redirect: "error", cache: "no-store" })
339
- );
334
+ async function automaticPairing(requestJson, issuer, authorize2, pairingCode, expectedState) {
335
+ const started = await requestJson(new URL("/pairing/start", issuer), {
336
+ method: "POST",
337
+ headers: { "content-type": "application/json" },
338
+ body: JSON.stringify({ authorizeUrl: authorize2.href }),
339
+ redirect: "error",
340
+ cache: "no-store"
341
+ });
340
342
  const pairingId = text(started.pairingId, "pairing id");
341
343
  const pollToken = text(started.pollToken, "pairing poll token");
342
- await json(
343
- fetcher(new URL("/pairing/approve", issuer), {
344
- method: "POST",
345
- headers: { "content-type": "application/json", "x-uap-pairing-code": pairingCode },
346
- body: JSON.stringify({ pairingId }),
347
- redirect: "error",
348
- cache: "no-store"
349
- })
350
- );
351
- const status = await json(
352
- fetcher(new URL("/pairing/status", issuer), { method: "POST", headers: { "content-type": "application/json" }, body: JSON.stringify({ pairingId, pollToken }), redirect: "error", cache: "no-store" })
353
- );
344
+ await requestJson(new URL("/pairing/approve", issuer), {
345
+ method: "POST",
346
+ headers: { "content-type": "application/json", "x-uap-pairing-code": pairingCode },
347
+ body: JSON.stringify({ pairingId }),
348
+ redirect: "error",
349
+ cache: "no-store"
350
+ });
351
+ const status = await requestJson(new URL("/pairing/status", issuer), {
352
+ method: "POST",
353
+ headers: { "content-type": "application/json" },
354
+ body: JSON.stringify({ pairingId, pollToken }),
355
+ redirect: "error",
356
+ cache: "no-store"
357
+ });
354
358
  if (status.status !== "approved" || typeof status.redirect !== "string") throw new TypeError("pairing approval failed");
355
359
  const redirect = new URL(status.redirect);
356
360
  if (redirect.searchParams.get("state") !== expectedState) throw new TypeError("pairing callback state is invalid");
357
361
  return { code: redirect.searchParams.get("code") ?? void 0, state: redirect.searchParams.get("state") ?? void 0 };
358
362
  }
359
- async function callbackServer(timeoutMs) {
363
+ async function timedJson(fetcher, url, init, timeoutMs) {
364
+ const controller = new AbortController();
365
+ return withTimeout(json(fetcher(url, { ...init, signal: controller.signal })), timeoutMs, `OAuth request timed out at ${url.pathname}`, () => controller.abort());
366
+ }
367
+ async function withTimeout(pending, timeoutMs, message, onTimeout) {
368
+ if (!Number.isSafeInteger(timeoutMs) || timeoutMs < 1 || timeoutMs > 10 * 6e4) throw new TypeError("OAuth timeout setting is invalid");
369
+ let timer;
370
+ try {
371
+ return await Promise.race([
372
+ pending,
373
+ new Promise((_, reject) => {
374
+ timer = setTimeout(() => {
375
+ reject(new TypeError(message));
376
+ onTimeout?.();
377
+ }, timeoutMs);
378
+ })
379
+ ]);
380
+ } finally {
381
+ clearTimeout(timer);
382
+ }
383
+ }
384
+ async function callbackServer() {
360
385
  let settle;
361
386
  let reject;
362
387
  const result = new Promise((resolve, rejectResult) => (settle = resolve, reject = rejectResult));
388
+ void result.catch(() => void 0);
363
389
  const server = createServer((request, response) => {
364
390
  const url = new URL(request.url ?? "/", "http://127.0.0.1");
365
391
  if (url.pathname !== "/callback") {
@@ -372,7 +398,7 @@ async function callbackServer(timeoutMs) {
372
398
  reject(new TypeError("OAuth browser authorization was declined"));
373
399
  return;
374
400
  }
375
- response.end("UAP Device Control login completed. You can close this window.");
401
+ response.end("UAP Device Control callback received. Return to the terminal to confirm login.");
376
402
  settle({ code: url.searchParams.get("code") ?? void 0, state: url.searchParams.get("state") ?? void 0 });
377
403
  });
378
404
  await new Promise((resolve, rejectListen) => {
@@ -381,13 +407,10 @@ async function callbackServer(timeoutMs) {
381
407
  });
382
408
  const address = server.address();
383
409
  if (!address || typeof address === "string") throw new TypeError("OAuth callback address is unavailable");
384
- const timer = setTimeout(() => reject(new TypeError("OAuth login timed out")), timeoutMs);
385
- timer.unref();
386
410
  return {
387
411
  redirectUri: "http://127.0.0.1:" + address.port + "/callback",
388
412
  result,
389
413
  close: async () => {
390
- clearTimeout(timer);
391
414
  await new Promise((resolve) => server.close(() => resolve()));
392
415
  }
393
416
  };
@@ -802,17 +825,26 @@ import WebSocket from "ws";
802
825
  // package.json
803
826
  var package_default = {
804
827
  name: "@codingfrees/uap-device-control",
805
- version: "0.2.11",
828
+ version: "0.2.13",
806
829
  description: "Cross-platform outbound UAP Device Control client",
830
+ contentPolicy: {
831
+ class: "dual-use"
832
+ },
833
+ repository: {
834
+ type: "git",
835
+ url: "git+https://github.com/CodingFrees/UAP-next.git",
836
+ directory: "apps/uap-device-control"
837
+ },
807
838
  type: "module",
808
839
  bin: {
809
840
  "uap-device-control": "dist/uap-device-control.mjs"
810
841
  },
811
842
  files: [
812
- "dist/"
843
+ "dist/",
844
+ "DISCLOSURE"
813
845
  ],
814
846
  engines: {
815
- node: ">=26.8.1 <27"
847
+ node: ">=24.18.1 <27"
816
848
  },
817
849
  dependencies: {
818
850
  ws: "8.22.0"
@@ -821,7 +853,7 @@ var package_default = {
821
853
  access: "public"
822
854
  },
823
855
  scripts: {
824
- build: 'pnpm exec esbuild src/bin.ts --bundle --packages=external --platform=node --format=esm --target=node26 --outfile=dist/uap-device-control.mjs --banner:js="#!/usr/bin/env node"',
856
+ build: 'pnpm exec esbuild src/bin.ts --bundle --packages=external --platform=node --format=esm --target=node24 --outfile=dist/uap-device-control.mjs --banner:js="#!/usr/bin/env node"',
825
857
  prepack: "pnpm run build",
826
858
  "publish:public": "node scripts/publish.mjs"
827
859
  }
@@ -2024,6 +2056,42 @@ async function runRemote(options) {
2024
2056
  engine.close();
2025
2057
  }
2026
2058
  }
2059
+ function createRemoteHeartbeat(socket, onMissed, intervalMs = 3e4, timeoutMs = 1e4) {
2060
+ let pending;
2061
+ let stopped = false;
2062
+ const stop = () => {
2063
+ stopped = true;
2064
+ clearInterval(interval);
2065
+ if (pending) clearTimeout(pending);
2066
+ pending = void 0;
2067
+ };
2068
+ const fail = () => {
2069
+ if (stopped) return;
2070
+ stop();
2071
+ onMissed();
2072
+ };
2073
+ const interval = setInterval(() => {
2074
+ if (stopped || pending) return;
2075
+ pending = setTimeout(fail, timeoutMs);
2076
+ pending.unref();
2077
+ try {
2078
+ socket.send('{"type":"transport-ping"}', (error) => {
2079
+ if (error) fail();
2080
+ });
2081
+ } catch {
2082
+ fail();
2083
+ }
2084
+ }, intervalMs);
2085
+ interval.unref();
2086
+ return {
2087
+ acknowledge() {
2088
+ if (!pending || stopped) return;
2089
+ clearTimeout(pending);
2090
+ pending = void 0;
2091
+ },
2092
+ stop
2093
+ };
2094
+ }
2027
2095
  function createRefreshScheduler(refresh, delayMs = 100) {
2028
2096
  let timer;
2029
2097
  return {
@@ -2055,6 +2123,7 @@ async function remoteSession(origin, stateDirectory, engine, fetcher = fetch, si
2055
2123
  const sessionStartedAt = Date.now();
2056
2124
  let closeCode;
2057
2125
  let closeCause;
2126
+ let heartbeat;
2058
2127
  const execute4 = (command, workspaceId) => {
2059
2128
  if (!command.capability.startsWith("browser.")) return engine.execute(command.capability, command.parameters, { workspaceId });
2060
2129
  const current = browserExecution.then(() => engine.execute(command.capability, command.parameters, { workspaceId }));
@@ -2111,6 +2180,11 @@ async function remoteSession(origin, stateDirectory, engine, fetcher = fetch, si
2111
2180
  const value = socketMessage(data);
2112
2181
  if (value.type === "connected") {
2113
2182
  connected = true;
2183
+ if (Array.isArray(value.features) && value.features.includes("transport-ping-v1"))
2184
+ heartbeat = createRemoteHeartbeat(socket, () => {
2185
+ closeCause = "presence-timeout";
2186
+ socket.terminate();
2187
+ });
2114
2188
  log?.({
2115
2189
  event: "remote.session",
2116
2190
  status: "connected",
@@ -2122,6 +2196,10 @@ async function remoteSession(origin, stateDirectory, engine, fetcher = fetch, si
2122
2196
  return;
2123
2197
  }
2124
2198
  if (!connected) throw new TypeError("remote socket sent data before connection acknowledgement");
2199
+ if (value.type === "transport-pong" && heartbeat) {
2200
+ heartbeat.acknowledge();
2201
+ return;
2202
+ }
2125
2203
  if (value.type === "presence-probe") {
2126
2204
  const probeId = bounded2(value.id, "presence probe id");
2127
2205
  socket.send(JSON.stringify({ type: "presence-ack", id: probeId }), (error) => {
@@ -2174,9 +2252,10 @@ async function remoteSession(origin, stateDirectory, engine, fetcher = fetch, si
2174
2252
  };
2175
2253
  socket.on("message", onMessage).on("close", onClose).on("error", onError);
2176
2254
  signal?.addEventListener("abort", onAbort, { once: true });
2177
- socket.send(JSON.stringify({ type: "hello", device: engine.info(), features: ["presence-probe-v1"] }));
2255
+ socket.send(JSON.stringify({ type: "hello", device: engine.info(), features: ["presence-probe-v1", "transport-ping-v1"] }));
2178
2256
  });
2179
2257
  } finally {
2258
+ heartbeat?.stop();
2180
2259
  for (const pending of acknowledgements.values()) pending.reject(new RemoteUnavailableError(void 0, "/device-control/remote/socket", "transport"));
2181
2260
  acknowledgements.clear();
2182
2261
  await drain();
package/package.json CHANGED
@@ -1,16 +1,25 @@
1
1
  {
2
2
  "name": "@codingfrees/uap-device-control",
3
- "version": "0.2.11",
3
+ "version": "0.2.13",
4
4
  "description": "Cross-platform outbound UAP Device Control client",
5
+ "contentPolicy": {
6
+ "class": "dual-use"
7
+ },
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "git+https://github.com/CodingFrees/UAP-next.git",
11
+ "directory": "apps/uap-device-control"
12
+ },
5
13
  "type": "module",
6
14
  "bin": {
7
15
  "uap-device-control": "dist/uap-device-control.mjs"
8
16
  },
9
17
  "files": [
10
- "dist/"
18
+ "dist/",
19
+ "DISCLOSURE"
11
20
  ],
12
21
  "engines": {
13
- "node": ">=26.8.1 <27"
22
+ "node": ">=24.18.1 <27"
14
23
  },
15
24
  "dependencies": {
16
25
  "ws": "8.22.0"
@@ -19,7 +28,7 @@
19
28
  "access": "public"
20
29
  },
21
30
  "scripts": {
22
- "build": "pnpm exec esbuild src/bin.ts --bundle --packages=external --platform=node --format=esm --target=node26 --outfile=dist/uap-device-control.mjs --banner:js=\"#!/usr/bin/env node\"",
31
+ "build": "pnpm exec esbuild src/bin.ts --bundle --packages=external --platform=node --format=esm --target=node24 --outfile=dist/uap-device-control.mjs --banner:js=\"#!/usr/bin/env node\"",
23
32
  "prepack": "pnpm run build",
24
33
  "publish:public": "node scripts/publish.mjs"
25
34
  }