@agent-device/proxy 0.21.34-nightly.20261028.102 → 0.21.34

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.
Files changed (2) hide show
  1. package/dist/process.mjs +25 -11
  2. package/package.json +2 -2
package/dist/process.mjs CHANGED
@@ -1,8 +1,8 @@
1
1
  import { i as redactDiagnosticData, n as createRequestCanceledError, t as AppError } from "./errors.mjs";
2
2
  import crypto, { randomUUID } from "node:crypto";
3
3
  import path from "node:path";
4
- import { AsyncLocalStorage } from "node:async_hooks";
5
4
  import fs from "node:fs";
5
+ import { AsyncLocalStorage } from "node:async_hooks";
6
6
  import { spawn, spawnSync } from "node:child_process";
7
7
  import { Readable } from "node:stream";
8
8
  import { pipeline } from "node:stream/promises";
@@ -264,12 +264,12 @@ function runSpawnedCommand(cmd, args, options = {}) {
264
264
  reject(failure);
265
265
  return;
266
266
  }
267
- resolve({
267
+ resolve(execResult(child, {
268
268
  stdout,
269
269
  stderr,
270
270
  exitCode: finalExitCode,
271
271
  stdoutBuffer: stdoutChunks ? Buffer.concat(stdoutChunks) : void 0
272
- });
272
+ }));
273
273
  }
274
274
  const settlement = createCommandKillSettlement({
275
275
  killProcessTree: () => killProcessTree(child, options),
@@ -326,6 +326,13 @@ function runSpawnedCommand(cmd, args, options = {}) {
326
326
  });
327
327
  });
328
328
  }
329
+ /** Returns the result with `signal` added when a signal terminated the process. */
330
+ function execResult(ended, result) {
331
+ return ended.signalCode ? {
332
+ ...result,
333
+ signal: ended.signalCode
334
+ } : result;
335
+ }
329
336
  function runCmdSync(cmd, args, options = {}) {
330
337
  const executable = normalizeExecutableCommand(cmd);
331
338
  const result = spawnSync(executable, args, {
@@ -358,12 +365,12 @@ function runCmdSync(cmd, args, options = {}) {
358
365
  const stderr = typeof result.stderr === "string" ? result.stderr : (result.stderr ?? "").toString();
359
366
  const exitCode = result.status ?? 1;
360
367
  if (exitCode !== 0 && !options.allowFailure) throw createExitError(executable, cmd, args, exitCode, stdout, stderr);
361
- return {
368
+ return execResult({ signalCode: result.signal }, {
362
369
  stdout,
363
370
  stderr,
364
371
  exitCode,
365
372
  stdoutBuffer
366
- };
373
+ });
367
374
  }
368
375
  function normalizeExecutableCommand(cmd) {
369
376
  const candidate = normalizeExecutableLookup(cmd);
@@ -581,7 +588,7 @@ function sleep(ms, signal) {
581
588
  //#endregion
582
589
  //#region ../host-kit/src/internal/host-process.ts
583
590
  const PS_TIMEOUT_MS = 1e3;
584
- const HOST_PS_COMMAND = "/bin/ps";
591
+ const HOST_PS_COMMANDS = ["/bin/ps", "/run/current-system/sw/bin/ps"];
585
592
  const WINDOWS_PS_TIMEOUT_MS = 2e3;
586
593
  const WINDOWS_PROCESS_TOOL = "powershell.exe";
587
594
  /**
@@ -609,6 +616,13 @@ function hostPlatform() {
609
616
  function hostProcessId() {
610
617
  return process.pid;
611
618
  }
619
+ function hostPsCommand() {
620
+ for (const candidate of HOST_PS_COMMANDS) try {
621
+ fs.accessSync(candidate, fs.constants.X_OK);
622
+ return candidate;
623
+ } catch {}
624
+ return HOST_PS_COMMANDS[0];
625
+ }
612
626
  function isProcessAlive(pid) {
613
627
  if (!Number.isInteger(pid) || pid <= 0) return false;
614
628
  try {
@@ -702,7 +716,7 @@ const HOST_PROCESS_IDENTITY_PS_ARGS = (pids) => [
702
716
  function readHostProcessIdentityRowsSync(pids) {
703
717
  if (isWindowsHostPlatform()) return windowsProcessIdentityRows(readWindowsProcessRows(pids, WINDOWS_PS_TIMEOUT_MS));
704
718
  try {
705
- const result = runCmdSync(HOST_PS_COMMAND, HOST_PROCESS_IDENTITY_PS_ARGS(pids), {
719
+ const result = runCmdSync(hostPsCommand(), HOST_PROCESS_IDENTITY_PS_ARGS(pids), {
706
720
  allowFailure: true,
707
721
  timeoutMs: PS_TIMEOUT_MS
708
722
  });
@@ -716,7 +730,7 @@ async function readHostProcessIdentityRowsAsync(pids) {
716
730
  if (selected.length === 0) return [];
717
731
  if (isWindowsHostPlatform()) return windowsProcessIdentityRows(await readWindowsProcessRowsAsync(selected, WINDOWS_PS_TIMEOUT_MS));
718
732
  try {
719
- const result = await runCmd(HOST_PS_COMMAND, HOST_PROCESS_IDENTITY_PS_ARGS(selected), {
733
+ const result = await runCmd(hostPsCommand(), HOST_PROCESS_IDENTITY_PS_ARGS(selected), {
720
734
  allowFailure: true,
721
735
  timeoutMs: PS_TIMEOUT_MS
722
736
  });
@@ -751,7 +765,7 @@ function readProcessField(pid, field) {
751
765
  if (!Number.isInteger(pid) || pid <= 0) return null;
752
766
  if (isWindowsHostPlatform()) return readWindowsProcessField(pid, field);
753
767
  try {
754
- return processFieldValue(runCmdSync(HOST_PS_COMMAND, [
768
+ return processFieldValue(runCmdSync(hostPsCommand(), [
755
769
  "-p",
756
770
  String(pid),
757
771
  "-o",
@@ -767,7 +781,7 @@ function readProcessField(pid, field) {
767
781
  async function readProcessFieldAsync(pid, field, timeoutMs) {
768
782
  if (!Number.isInteger(pid) || pid <= 0) return null;
769
783
  try {
770
- return processFieldValue(await runCmd(HOST_PS_COMMAND, [
784
+ return processFieldValue(await runCmd(hostPsCommand(), [
771
785
  "-p",
772
786
  String(pid),
773
787
  "-o",
@@ -913,7 +927,7 @@ async function listWindowsHostProcesses(options) {
913
927
  }
914
928
  async function listHostProcesses(options) {
915
929
  if (isWindowsHostPlatform()) return await listWindowsHostProcesses(options);
916
- const result = await (options.runCommand ?? runCmd)(options.runCommand ? "ps" : HOST_PS_COMMAND, [
930
+ const result = await (options.runCommand ?? runCmd)(options.runCommand ? "ps" : hostPsCommand(), [
917
931
  "-ax",
918
932
  "-o",
919
933
  "pid=,ppid=,command="
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agent-device/proxy",
3
- "version": "0.21.34-nightly.20261028.102",
3
+ "version": "0.21.34",
4
4
  "type": "module",
5
5
  "description": "Transport-neutral authenticating proxy in front of an agent-device daemon.",
6
6
  "license": "MIT",
@@ -25,8 +25,8 @@
25
25
  "dist"
26
26
  ],
27
27
  "devDependencies": {
28
- "@agent-device/contracts": "0.0.0",
29
28
  "@agent-device/host-kit": "0.0.0",
29
+ "@agent-device/contracts": "0.0.0",
30
30
  "@agent-device/kernel": "0.0.0"
31
31
  },
32
32
  "scripts": {