@codingfrees/uap-device-control 0.2.13 → 0.2.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/DISCLOSURE CHANGED
@@ -9,6 +9,9 @@ authenticated device enrollment, origin-bound credentials, capability
9
9
  restrictions, and elevated approval for sensitive operations. It must not
10
10
  be used to access systems without authorization.
11
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.
12
+ Public releases are submitted from a verified immutable source through
13
+ explicitly authorized npm Trusted Publishing (OIDC) in a GitHub-hosted
14
+ workflow. The npm account owner must approve the trusted-publisher setup
15
+ using the account security controls; the release operation requires an
16
+ explicit Product Releases confirmation and the GitHub production environment.
17
+ Successful publication is independently checked against the public registry.
package/README.md CHANGED
@@ -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, 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.
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 at https://www.npmjs.com/settings/codingfrees/staged-packages 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
 
@@ -9,31 +9,23 @@ import { createServer } from "node:http";
9
9
  // ../../packages/web-crypto/src/index.ts
10
10
  var encoder = new TextEncoder();
11
11
  function randomBytes(length) {
12
- if (!Number.isInteger(length) || length < 1 || length > 4096) {
13
- throw new TypeError("random byte length is invalid");
14
- }
12
+ if (!Number.isInteger(length) || length < 1 || length > 4096) throw new TypeError("random byte length is invalid");
15
13
  const bytes = new Uint8Array(length);
16
14
  crypto.getRandomValues(bytes);
17
15
  return bytes;
18
16
  }
19
17
  async function sha256Bytes(value) {
20
18
  const input = typeof value === "string" ? encoder.encode(value) : value;
21
- if (!isUint8Array(input)) {
22
- throw new TypeError("SHA-256 input is invalid");
23
- }
19
+ if (!isUint8Array(input)) throw new TypeError("SHA-256 input is invalid");
24
20
  const digestInput = new Uint8Array(input.byteLength);
25
21
  digestInput.set(input);
26
22
  return new Uint8Array(await crypto.subtle.digest("SHA-256", digestInput.buffer));
27
23
  }
28
24
  function base64EncodeBytes(bytes) {
29
- if (!isUint8Array(bytes)) {
30
- throw new TypeError("base64 input is invalid");
31
- }
25
+ if (!isUint8Array(bytes)) throw new TypeError("base64 input is invalid");
32
26
  let binary = "";
33
27
  const chunkSize = 32768;
34
- for (let offset = 0; offset < bytes.length; offset += chunkSize) {
35
- binary += String.fromCharCode(...bytes.subarray(offset, offset + chunkSize));
36
- }
28
+ for (let offset = 0; offset < bytes.length; offset += chunkSize) binary += String.fromCharCode(...bytes.subarray(offset, offset + chunkSize));
37
29
  return btoa(binary);
38
30
  }
39
31
  function isUint8Array(value) {
@@ -825,7 +817,7 @@ import WebSocket from "ws";
825
817
  // package.json
826
818
  var package_default = {
827
819
  name: "@codingfrees/uap-device-control",
828
- version: "0.2.13",
820
+ version: "0.2.20",
829
821
  description: "Cross-platform outbound UAP Device Control client",
830
822
  contentPolicy: {
831
823
  class: "dual-use"
@@ -861,8 +853,9 @@ var package_default = {
861
853
 
862
854
  // ../device-agent/src/engine.ts
863
855
  import { execFile as execFile2, spawn } from "node:child_process";
856
+ import { once } from "node:events";
864
857
  import { promisify as promisify2 } from "node:util";
865
- import { cp, mkdir as mkdir3, open, readdir, realpath as realpath2, rename as rename2, rm as rm2, stat, writeFile as writeFile3 } from "node:fs/promises";
858
+ import { cp, lstat, mkdir as mkdir3, open, readdir, realpath as realpath2, rename as rename2, rm as rm2, stat, writeFile as writeFile3 } from "node:fs/promises";
866
859
  import { realpathSync } from "node:fs";
867
860
  import os2 from "node:os";
868
861
  import path3 from "node:path";
@@ -1089,8 +1082,13 @@ var DeviceAgentEngine = class {
1089
1082
  return {
1090
1083
  entries: await Promise.all(
1091
1084
  entries.slice(0, 2e3).map(async (entry) => {
1092
- const value = await stat(path3.join(target, entry.name));
1093
- return { name: entry.name, path: path3.posix.join(relative.replaceAll("\\", "/"), entry.name), kind: entry.isDirectory() ? "directory" : "file", size: value.size, modifiedAt: value.mtimeMs };
1085
+ const value = await lstat(path3.join(target, entry.name)).catch(() => null);
1086
+ return {
1087
+ name: entry.name,
1088
+ path: path3.posix.join(relative.replaceAll("\\", "/"), entry.name),
1089
+ kind: entry.isDirectory() ? "directory" : "file",
1090
+ ...value ? { size: value.size, modifiedAt: value.mtimeMs } : { metadataUnavailable: true }
1091
+ };
1094
1092
  })
1095
1093
  )
1096
1094
  };
@@ -1151,7 +1149,7 @@ var DeviceAgentEngine = class {
1151
1149
  }
1152
1150
  async #oneShot(input, workspaceId) {
1153
1151
  const startedAt = Date.now();
1154
- const process2 = this.#spawn(input, false, workspaceId);
1152
+ const process2 = await this.#spawn(input, false, workspaceId);
1155
1153
  process2.capability = "terminal.exec";
1156
1154
  this.#oneShots.set(process2.id, process2);
1157
1155
  const timeoutMs = bounded(Number(input.timeoutMs ?? 3e4), 100, 3e5, "command timeout");
@@ -1182,7 +1180,7 @@ var DeviceAgentEngine = class {
1182
1180
  }
1183
1181
  if (capability === "process.start") {
1184
1182
  if (this.#running(this.#processes) >= this.#maxProcesses) throw new TypeError("process limit reached");
1185
- const value2 = this.#spawn(input, false, workspaceId);
1183
+ const value2 = await this.#spawn(input, false, workspaceId);
1186
1184
  this.#processes.set(value2.id, value2);
1187
1185
  return summary(value2);
1188
1186
  }
@@ -1197,7 +1195,7 @@ var DeviceAgentEngine = class {
1197
1195
  const operation = String(input.operation);
1198
1196
  if (operation === "start") {
1199
1197
  if (this.#running(this.#sessions) >= this.#maxSessions) throw new TypeError("terminal session limit reached");
1200
- const value2 = this.#spawn(input, true, workspaceId);
1198
+ const value2 = await this.#spawn(input, true, workspaceId);
1201
1199
  value2.lastActivityAt = Date.now();
1202
1200
  value2.expiresAt = value2.lastActivityAt + this.#sessionIdleTimeoutMs;
1203
1201
  value2.idleTimer = null;
@@ -1360,16 +1358,12 @@ var DeviceAgentEngine = class {
1360
1358
  this.#screenSessions.delete(sessionId);
1361
1359
  this.#emit("device-agent.screen.expired", "screen.stream", { sessionId, idleTimeoutMs: this.#sessionIdleTimeoutMs }, session.workspaceId);
1362
1360
  }
1363
- #spawn(input, terminal, workspaceId) {
1361
+ async #spawn(input, terminal, workspaceId) {
1364
1362
  const executable = text2(input.executable ?? defaultShell(), 260, "executable");
1365
- if (!this.#unrestricted && ![...this.#allowed].some((allowed) => executable === allowed || path3.basename(executable).toLowerCase() === path3.basename(allowed).toLowerCase())) {
1366
- throw new TypeError("executable is not allowed: " + executable);
1367
- }
1363
+ if (!this.#unrestricted && ![...this.#allowed].some((allowed) => path3.basename(executable).toLowerCase() === path3.basename(allowed).toLowerCase())) throw new TypeError("executable is not allowed: " + executable);
1368
1364
  const args = Array.isArray(input.args) ? input.args.map((value) => text2(value, 8192, "argument")) : terminal ? [] : [text2(input.command ?? "", 8192, "command")];
1369
1365
  if (args.length > 128 || JSON.stringify(args).length > 32768) throw new TypeError("command length limit exceeded");
1370
- const cwd = input.cwd === void 0 ? void 0 : this.#cwd(input.cwd);
1371
- const env = environment(input.environment);
1372
- const child = spawn(executable, args, { cwd, env: { ...process.env, ...env }, shell: false, windowsHide: true });
1366
+ const child = spawn(executable, args, { cwd: input.cwd === void 0 ? void 0 : this.#cwd(input.cwd), env: { ...process.env, ...environment(input.environment) }, shell: false, windowsHide: true });
1373
1367
  const record = {
1374
1368
  id: randomUUID3(),
1375
1369
  capability: terminal ? "terminal.session" : "process.output",
@@ -1385,16 +1379,14 @@ var DeviceAgentEngine = class {
1385
1379
  truncated: false,
1386
1380
  workspaceId
1387
1381
  };
1388
- child.stdout.on("data", (chunk) => this.#append(record, "stdout", chunk));
1389
- child.stderr.on("data", (chunk) => this.#append(record, "stderr", chunk));
1390
- child.once("close", (code) => {
1391
- record.exitCode = code;
1392
- });
1382
+ for (const stream of ["stdout", "stderr"]) child[stream].on("data", (chunk) => this.#append(record, stream, chunk));
1383
+ child.once("close", (code) => record.exitCode = code);
1384
+ await once(child, "spawn");
1393
1385
  return record;
1394
1386
  }
1395
1387
  #append(record, target, chunk) {
1396
- const totalKey = target === "stdout" ? "stdoutBytes" : "stderrBytes";
1397
- const baseKey = target === "stdout" ? "stdoutBaseBytes" : "stderrBaseBytes";
1388
+ const totalKey = `${target}Bytes`;
1389
+ const baseKey = `${target}BaseBytes`;
1398
1390
  record[totalKey] += chunk.byteLength;
1399
1391
  const next = record[target] + chunk.toString("utf8");
1400
1392
  if (record.capability === "terminal.session") {
@@ -1425,9 +1417,7 @@ var DeviceAgentEngine = class {
1425
1417
  } catch {
1426
1418
  throw new TypeError("cwd is unavailable");
1427
1419
  }
1428
- for (const root2 of this.#roots.values()) {
1429
- if (inside(root2.path, candidate)) return candidate;
1430
- }
1420
+ for (const root2 of this.#roots.values()) if (inside(root2.path, candidate)) return candidate;
1431
1421
  if (this.#unrestricted) return candidate;
1432
1422
  throw new TypeError("cwd escapes configured roots");
1433
1423
  }
@@ -1493,7 +1483,10 @@ var retainUtf8Tail = (value, maximumBytes) => {
1493
1483
  while (start < bytes.byteLength && (bytes[start] & 192) === 128) start++;
1494
1484
  return { text: bytes.subarray(start).toString("utf8"), droppedBytes: start };
1495
1485
  };
1496
- var inside = (root2, target) => target === root2 || target.startsWith(root2 + path3.sep);
1486
+ var inside = (root2, target) => {
1487
+ const relative = path3.relative(root2, target);
1488
+ return relative !== ".." && !relative.startsWith(".." + path3.sep) && !path3.isAbsolute(relative);
1489
+ };
1497
1490
  var executionWorkspaceId = (value) => {
1498
1491
  if (value === void 0) return null;
1499
1492
  if (!/^[A-Za-z0-9][A-Za-z0-9._:-]{0,127}$/.test(value)) throw new TypeError("workspace id is invalid");
@@ -1513,9 +1506,7 @@ async function safeExisting(root2, relative) {
1513
1506
  }
1514
1507
  async function safeWritable(root2, relative) {
1515
1508
  const lexical = path3.resolve(root2, relative);
1516
- if (!inside(root2, lexical) || lexical === root2) {
1517
- throw new TypeError("relative path is invalid");
1518
- }
1509
+ if (!inside(root2, lexical) || lexical === root2) throw new TypeError("relative path is invalid");
1519
1510
  const parts = path3.relative(root2, lexical).split(path3.sep);
1520
1511
  const leaf = parts.pop();
1521
1512
  if (!leaf) throw new TypeError("relative path is invalid");
@@ -1549,9 +1540,8 @@ function isMissing(error) {
1549
1540
  }
1550
1541
  function safeRelative(value, empty) {
1551
1542
  const result = String(value ?? "");
1552
- if (!empty && !result || result.length > 1024 || path3.isAbsolute(result) || result.split(/[\\/]/).some((part) => part === "..") || result.includes("\0")) {
1543
+ if (!empty && !result || result.length > 1024 || path3.isAbsolute(result) || path3.win32.parse(result).root !== "" || result.split(/[\\/]/).some((part) => part === "..") || result.includes("\0"))
1553
1544
  throw new TypeError("relative path is invalid");
1554
- }
1555
1545
  return result;
1556
1546
  }
1557
1547
  function decodeBase64(value, limit) {
@@ -1924,9 +1914,7 @@ async function createNativeServiceAdapter(options = {}) {
1924
1914
  async control(name, operation) {
1925
1915
  const normalizedName = serviceName2(name);
1926
1916
  const normalizedOperation = serviceOperation2(operation);
1927
- for (const [program, ...args] of await controlCommands(normalizedName, normalizedOperation)) {
1928
- await invoke(run, [program, ...args], "service control");
1929
- }
1917
+ for (const [program, ...args] of await controlCommands(normalizedName, normalizedOperation)) await invoke(run, [program, ...args], "service control");
1930
1918
  return { name: normalizedName, operation: normalizedOperation, accepted: true };
1931
1919
  }
1932
1920
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codingfrees/uap-device-control",
3
- "version": "0.2.13",
3
+ "version": "0.2.20",
4
4
  "description": "Cross-platform outbound UAP Device Control client",
5
5
  "contentPolicy": {
6
6
  "class": "dual-use"