conbridge-agent 0.6.0 → 0.6.1

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 (3) hide show
  1. package/README.md +1 -1
  2. package/conbridge-agent.cjs +1534 -1066
  3. package/package.json +1 -1
@@ -29,17 +29,17 @@ __export(cli_exports, {
29
29
  module.exports = __toCommonJS(cli_exports);
30
30
 
31
31
  // <define:__CONBRIDGE_BUILD__>
32
- var define_CONBRIDGE_BUILD_default = { version: "0.6.0", commit: "69f9aa0c007a", built_at: "2026-11-09T10:50:53.899Z", keychain_helper_sha256: "0a2d65388c0acc75305386ce0d6b7ee2e522ed939f291eb5a50055197674c023", distribution: "npm" };
32
+ var define_CONBRIDGE_BUILD_default = { version: "0.6.1", commit: "f4c4f8b93d73", built_at: "2026-11-09T23:07:16.595Z", keychain_helper_sha256: "0a2d65388c0acc75305386ce0d6b7ee2e522ed939f291eb5a50055197674c023", distribution: "npm" };
33
33
 
34
34
  // dist/cli.js
35
- var import_promises16 = require("node:readline/promises");
35
+ var import_promises17 = require("node:readline/promises");
36
36
 
37
37
  // dist/purge.js
38
- var import_node_child_process3 = require("node:child_process");
38
+ var import_node_child_process4 = require("node:child_process");
39
39
  var import_node_crypto5 = require("node:crypto");
40
- var import_promises6 = require("node:fs/promises");
41
- var import_node_os3 = require("node:os");
42
- var import_node_path7 = require("node:path");
40
+ var import_promises7 = require("node:fs/promises");
41
+ var import_node_os4 = require("node:os");
42
+ var import_node_path8 = require("node:path");
43
43
 
44
44
  // ../../node_modules/.pnpm/zod@4.6.7/node_modules/zod/v4/classic/external.js
45
45
  var external_exports = {};
@@ -5108,7 +5108,7 @@ var recursive = /* @__PURE__ */ new WeakMap();
5108
5108
  var NONE = 0;
5109
5109
  var ASSUMED = 1;
5110
5110
  var PROVEN = 2;
5111
- function isRecursive(inst, stack, resolve9) {
5111
+ function isRecursive(inst, stack, resolve10) {
5112
5112
  const cached2 = recursive.get(inst);
5113
5113
  if (cached2 !== void 0)
5114
5114
  return cached2 ? PROVEN : NONE;
@@ -5118,7 +5118,7 @@ function isRecursive(inst, stack, resolve9) {
5118
5118
  let result2 = NONE;
5119
5119
  const check2 = (child) => {
5120
5120
  if (result2 !== PROVEN && child?._zod) {
5121
- const answer = isRecursive(child, stack, resolve9);
5121
+ const answer = isRecursive(child, stack, resolve10);
5122
5122
  if (answer > result2)
5123
5123
  result2 = answer;
5124
5124
  }
@@ -5129,7 +5129,7 @@ function isRecursive(inst, stack, resolve9) {
5129
5129
  const desc = Object.getOwnPropertyDescriptor(sh, key);
5130
5130
  if (spread && !desc.enumerable)
5131
5131
  continue;
5132
- const child = desc.get ? ASSUMED : desc.value?._zod ? isRecursive(desc.value, stack, resolve9) : NONE;
5132
+ const child = desc.get ? ASSUMED : desc.value?._zod ? isRecursive(desc.value, stack, resolve10) : NONE;
5133
5133
  if (child > answer)
5134
5134
  answer = child;
5135
5135
  }
@@ -5193,7 +5193,7 @@ function isRecursive(inst, stack, resolve9) {
5193
5193
  break;
5194
5194
  // `$ZodLazy` caches its inner on the def, so a resolved edge is followed exactly
5195
5195
  case "lazy": {
5196
- const inner = def._cachedInner ?? (resolve9 ? inst._zod.innerType : void 0);
5196
+ const inner = def._cachedInner ?? (resolve10 ? inst._zod.innerType : void 0);
5197
5197
  merge2(inner ? isRecursive(inner, stack, false) : ASSUMED);
5198
5198
  break;
5199
5199
  }
@@ -19986,7 +19986,7 @@ var inventorySnapshotSchema = external_exports.strictObject({
19986
19986
  image_packages: external_exports.array(inventoryImagePackageSchema).max(INVENTORY_LIMITS.imagePackages).optional(),
19987
19987
  /** TLS endpoints on well-known local ports (agent 0.5.0 and newer). */
19988
19988
  tls_endpoints: external_exports.array(inventoryTlsEndpointSchema).max(INVENTORY_LIMITS.tlsEndpoints).optional(),
19989
- /** Listening sockets and their owners (agent 0.7.0 and newer; CB-194). */
19989
+ /** Listening sockets and their owners (agent 0.6.0 and newer; CB-194). */
19990
19990
  listeners: external_exports.array(inventoryListenerSchema).max(INVENTORY_LIMITS.listeners).optional(),
19991
19991
  pods: external_exports.array(inventoryPodSchema).max(INVENTORY_LIMITS.pods),
19992
19992
  /** Grouped errors of the last 24 hours (agent 0.5.0 and newer). */
@@ -20309,7 +20309,9 @@ var AGENT_FEATURE_MIN_VERSION = Object.freeze({
20309
20309
  * `ssh_hosts` in SOFTWARE_INVENTORY_CONFIG (ADR SECURITY_INTELLIGENCE 11.6). Older agents drop the whole config frame
20310
20310
  * when it carries the field, so the relay sends it only to agents known to have this version.
20311
20311
  */
20312
- ssh_inventory: "0.4.0"
20312
+ ssh_inventory: "0.4.0",
20313
+ /** LIFECYCLE and the passive/timed/ephemeral connection modes (ADR CONNECTION_MODES; HELLO capability `lifecycle.v1`). */
20314
+ lifecycle: "0.6.0"
20313
20315
  });
20314
20316
 
20315
20317
  // ../../packages/protocol/dist/security/types.js
@@ -21807,7 +21809,7 @@ var import_node_fs = require("node:fs");
21807
21809
  var import_node_path = require("node:path");
21808
21810
  var import_node_sea = require("node:sea");
21809
21811
  var import_node_url = require("node:url");
21810
- var SOURCE_VERSION = "0.6.0";
21812
+ var SOURCE_VERSION = "0.6.1";
21811
21813
  var BUILD_INFO = typeof define_CONBRIDGE_BUILD_default === "object" && define_CONBRIDGE_BUILD_default !== null ? define_CONBRIDGE_BUILD_default : null;
21812
21814
  var AGENT_VERSION = BUILD_INFO?.version ?? SOURCE_VERSION;
21813
21815
  function runningAsSea() {
@@ -21894,16 +21896,16 @@ function errorCode2(error63) {
21894
21896
  }
21895
21897
  async function realpathLenient(path) {
21896
21898
  const absolute = (0, import_node_path2.resolve)(path);
21897
- const missing = [];
21899
+ const missing2 = [];
21898
21900
  let current = absolute;
21899
21901
  for (; ; ) {
21900
21902
  try {
21901
- return (0, import_node_path2.join)(await (0, import_promises.realpath)(current), ...missing);
21903
+ return (0, import_node_path2.join)(await (0, import_promises.realpath)(current), ...missing2);
21902
21904
  } catch (error63) {
21903
21905
  const parent = (0, import_node_path2.dirname)(current);
21904
21906
  if (parent === current || errorCode2(error63) !== "ENOENT" && errorCode2(error63) !== "ENOTDIR")
21905
21907
  return absolute;
21906
- missing.unshift((0, import_node_path2.basename)(current));
21908
+ missing2.unshift((0, import_node_path2.basename)(current));
21907
21909
  current = parent;
21908
21910
  }
21909
21911
  }
@@ -21972,8 +21974,8 @@ function launchAgentPath(home = (0, import_node_os.homedir)()) {
21972
21974
  function defaultLogPath(home = (0, import_node_os.homedir)()) {
21973
21975
  return (0, import_node_path3.join)(home, "Library", "Logs", "conbridge-agent.log");
21974
21976
  }
21975
- var systemCommand = (file2, args) => new Promise((resolve9) => {
21976
- (0, import_node_child_process.execFile)(file2, args, { windowsHide: true }, (error63, stdout, stderr) => resolve9({ ok: !error63, output: `${stdout}${stderr}`.trim() }));
21977
+ var systemCommand = (file2, args) => new Promise((resolve10) => {
21978
+ (0, import_node_child_process.execFile)(file2, args, { windowsHide: true }, (error63, stdout, stderr) => resolve10({ ok: !error63, output: `${stdout}${stderr}`.trim() }));
21977
21979
  });
21978
21980
  var systemLaunchctl = (args) => systemCommand("/bin/launchctl", args);
21979
21981
  async function stableNodePath(execPath = process.execPath, candidates = ["/opt/homebrew/bin/node", "/usr/local/bin/node"]) {
@@ -22009,7 +22011,7 @@ async function installLaunchAgent(options, deps = {}) {
22009
22011
  await run2(["enable", `${domain2}/${LAUNCH_AGENT_LABEL}`]);
22010
22012
  let result2 = await run2(["bootstrap", domain2, path]);
22011
22013
  for (let attempt = 1; !result2.ok && attempt <= 4 && /\b5: Input\/output error/.test(result2.output); attempt += 1) {
22012
- await new Promise((resolve9) => setTimeout(resolve9, 750 * attempt));
22014
+ await new Promise((resolve10) => setTimeout(resolve10, 750 * attempt));
22013
22015
  result2 = await run2(["bootstrap", domain2, path]);
22014
22016
  }
22015
22017
  if (!result2.ok)
@@ -22127,8 +22129,8 @@ function withCronLine(current, line) {
22127
22129
  const kept = current.split("\n").filter((entry) => entry.trim() !== "" && !entry.includes(CRON_MARKER));
22128
22130
  return [...kept, ...line ? [line] : []].join("\n") + "\n";
22129
22131
  }
22130
- var systemCrontabWriter = (text6) => new Promise((resolve9) => {
22131
- const child = (0, import_node_child_process.execFile)("crontab", ["-"], (error63, stdout, stderr) => resolve9({ ok: !error63, output: `${stdout}${stderr}`.trim() }));
22132
+ var systemCrontabWriter = (text6) => new Promise((resolve10) => {
22133
+ const child = (0, import_node_child_process.execFile)("crontab", ["-"], (error63, stdout, stderr) => resolve10({ ok: !error63, output: `${stdout}${stderr}`.trim() }));
22132
22134
  child.stdin?.end(text6);
22133
22135
  });
22134
22136
  async function installCronService(options, deps = {}) {
@@ -22220,13 +22222,13 @@ async function installWindowsTask(options, deps = {}) {
22220
22222
  throw new Error("Task Scheduler install is only supported on Windows");
22221
22223
  const run2 = deps.run ?? systemCommand;
22222
22224
  const env = deps.env ?? process.env;
22223
- const launcherPath = windowsLauncherPath(options.stateDir);
22225
+ const launcherPath2 = windowsLauncherPath(options.stateDir);
22224
22226
  await (0, import_promises2.mkdir)((0, import_node_path3.dirname)(options.logPath), { recursive: true });
22225
- await writeFileAtomic(launcherPath, buildWindowsLauncher(options), 384);
22227
+ await writeFileAtomic(launcherPath2, buildWindowsLauncher(options), 384);
22226
22228
  const user = env.USERNAME ?? (0, import_node_os.userInfo)().username;
22227
22229
  const userId = env.USERDOMAIN ? `${env.USERDOMAIN}\\${user}` : user;
22228
22230
  const xmlPath = (0, import_node_path3.join)(options.stateDir, "conbridge-agent-task.xml");
22229
- const xml = buildWindowsTaskXml({ userId, launcherPath, wscriptPath: windowsSystemTool(env, "wscript.exe") });
22231
+ const xml = buildWindowsTaskXml({ userId, launcherPath: launcherPath2, wscriptPath: windowsSystemTool(env, "wscript.exe") });
22230
22232
  await (0, import_promises2.writeFile)(xmlPath, Buffer.concat([Buffer.from([255, 254]), Buffer.from(xml, "utf16le")]), { mode: 384 });
22231
22233
  try {
22232
22234
  const schtasks = windowsSystemTool(env, "schtasks.exe");
@@ -22724,13 +22726,296 @@ async function openKeyStore(paths, descriptor, options = {}) {
22724
22726
  });
22725
22727
  }
22726
22728
 
22729
+ // dist/launcher.js
22730
+ var import_node_child_process3 = require("node:child_process");
22731
+ var import_promises6 = require("node:fs/promises");
22732
+ var import_node_os3 = require("node:os");
22733
+ var import_node_path7 = require("node:path");
22734
+ var LAUNCHER_BIN = "conbridge-agent";
22735
+ var LAUNCHER_BIN_WIN = "conbridge-agent.cmd";
22736
+ var RUNTIME_FILE = "conbridge-agent.cjs";
22737
+ var MARKER_START = "# >>> conbridge >>>";
22738
+ var MARKER_END = "# <<< conbridge <<<";
22739
+ var PATH_LINE = 'export PATH="$HOME/.conbridge/bin:$PATH"';
22740
+ var FISH_PATH_LINE = "fish_add_path -g $HOME/.conbridge/bin";
22741
+ var realFs = {
22742
+ lstat: import_promises6.lstat,
22743
+ stat: import_promises6.stat,
22744
+ mkdir: (path, options) => (0, import_promises6.mkdir)(path, options).then(() => void 0),
22745
+ readFile: (path) => (0, import_promises6.readFile)(path, "utf8"),
22746
+ writeFile: (path, content, options) => (0, import_promises6.writeFile)(path, content, options),
22747
+ appendFile: (path, content) => (0, import_promises6.appendFile)(path, content),
22748
+ realpath: (path) => (0, import_promises6.realpath)(path),
22749
+ rename: import_promises6.rename,
22750
+ chmod: import_promises6.chmod,
22751
+ unlink: import_promises6.unlink
22752
+ };
22753
+ var realPowerShell = (args, env) => new Promise((done) => {
22754
+ (0, import_node_child_process3.execFile)("powershell.exe", args, { windowsHide: true, env: { ...process.env, ...env } }, (error63, stdout, stderr) => {
22755
+ done({ ok: !error63, output: `${stdout}${stderr}`.trim() });
22756
+ });
22757
+ });
22758
+ var PATH_BLOCK = `${MARKER_START}
22759
+ ${PATH_LINE}
22760
+ ${MARKER_END}
22761
+ `;
22762
+ var FISH_BLOCK = `${MARKER_START}
22763
+ ${FISH_PATH_LINE}
22764
+ ${MARKER_END}
22765
+ `;
22766
+ var WINDOWS_PATH_HEADER = [
22767
+ "$dir = $env:CONBRIDGE_BIN_DIR",
22768
+ "$key = [Microsoft.Win32.Registry]::CurrentUser.CreateSubKey('Environment')",
22769
+ "$raw = [string]$key.GetValue('Path', '', [Microsoft.Win32.RegistryValueOptions]::DoNotExpandEnvironmentNames)",
22770
+ "$kind = if ($raw) { $key.GetValueKind('Path') } else { [Microsoft.Win32.RegistryValueKind]::ExpandString }",
22771
+ "$parts = @($raw -split ';' | Where-Object { $_ })",
22772
+ "$target = $dir.TrimEnd('\\')",
22773
+ "$same = { param($entry) [Environment]::ExpandEnvironmentVariables($entry).TrimEnd('\\').Equals($target, [System.StringComparison]::OrdinalIgnoreCase) }"
22774
+ ];
22775
+ var WINDOWS_BROADCAST = "[Environment]::SetEnvironmentVariable('CONBRIDGE_PATH_REFRESH', $null, 'User')";
22776
+ var WINDOWS_APPEND_SCRIPT = [
22777
+ ...WINDOWS_PATH_HEADER,
22778
+ "if (@($parts | Where-Object { & $same $_ }).Count -gt 0) { Write-Output 'present' }",
22779
+ "else { $key.SetValue('Path', (@($parts + $dir) -join ';'), $kind); " + WINDOWS_BROADCAST + "; Write-Output 'added' }",
22780
+ "$key.Close()"
22781
+ ].join("\n");
22782
+ var WINDOWS_REMOVE_SCRIPT = [
22783
+ ...WINDOWS_PATH_HEADER,
22784
+ "$kept = @($parts | Where-Object { -not (& $same $_) })",
22785
+ "if ($kept.Count -eq $parts.Count) { Write-Output 'absent' }",
22786
+ "else { $key.SetValue('Path', ($kept -join ';'), $kind); " + WINDOWS_BROADCAST + "; Write-Output 'removed' }",
22787
+ "$key.Close()"
22788
+ ].join("\n");
22789
+ function windowsBinDir(home) {
22790
+ return import_node_path7.win32.join(home, ".conbridge", "bin");
22791
+ }
22792
+ function launcherPath(home, platform2) {
22793
+ return platform2 === "win32" ? import_node_path7.win32.join(home, ".conbridge", "bin", LAUNCHER_BIN_WIN) : (0, import_node_path7.join)(home, ".conbridge", "bin", LAUNCHER_BIN);
22794
+ }
22795
+ function binDir(home, platform2) {
22796
+ return platform2 === "win32" ? import_node_path7.win32.join(home, ".conbridge", "bin") : (0, import_node_path7.join)(home, ".conbridge", "bin");
22797
+ }
22798
+ function conbridgeRoot(home, platform2) {
22799
+ return platform2 === "win32" ? import_node_path7.win32.join(home, ".conbridge") : (0, import_node_path7.join)(home, ".conbridge");
22800
+ }
22801
+ function normalizeStateDir(stateDir, platform2) {
22802
+ return platform2 === "win32" ? import_node_path7.win32.resolve(stateDir).toLowerCase() : (0, import_node_path7.resolve)(stateDir);
22803
+ }
22804
+ function isDefaultStateDir(stateDir, home, platform2) {
22805
+ const defaultDir = platform2 === "win32" ? import_node_path7.win32.join(home, ".conbridge", "agent") : (0, import_node_path7.join)(home, ".conbridge", "agent");
22806
+ return normalizeStateDir(stateDir, platform2) === normalizeStateDir(defaultDir, platform2);
22807
+ }
22808
+ function shQuote(value) {
22809
+ return "'" + value.replace(/'/g, "'\\''") + "'";
22810
+ }
22811
+ function launcherScript(input2) {
22812
+ const { home, platform: platform2, stateDir, nodePath } = input2;
22813
+ const custom2 = !isDefaultStateDir(stateDir, home, platform2);
22814
+ if (platform2 === "win32") {
22815
+ for (const value of [stateDir, nodePath ?? ""]) {
22816
+ if (/["%\r\n]/.test(value))
22817
+ throw new Error(`Unsupported character in path for the Windows launcher: ${value}`);
22818
+ }
22819
+ const runtime2 = import_node_path7.win32.join(stateDir, "runtime", RUNTIME_FILE);
22820
+ return [
22821
+ "@echo off",
22822
+ 'set "CB_NODE=%~dp0..\\node\\node.exe"',
22823
+ ...nodePath ? [`if not exist "%CB_NODE%" set "CB_NODE=${nodePath}"`] : [],
22824
+ 'if not exist "%CB_NODE%" set "CB_NODE=node"',
22825
+ ...custom2 ? [`set "CONBRIDGE_AGENT_HOME=${stateDir}"`] : [],
22826
+ `"%CB_NODE%" "${runtime2}" %*`,
22827
+ ""
22828
+ ].join("\r\n");
22829
+ }
22830
+ const node2 = (0, import_node_path7.join)(home, ".conbridge", "node", "bin", "node");
22831
+ const runtime = (0, import_node_path7.join)(stateDir, "runtime", RUNTIME_FILE);
22832
+ return [
22833
+ "#!/bin/sh",
22834
+ `node=${shQuote(node2)}`,
22835
+ ...nodePath ? [`[ -x "$node" ] || node=${shQuote(nodePath)}`] : [],
22836
+ '[ -x "$node" ] || node=node',
22837
+ ...custom2 ? [`export CONBRIDGE_AGENT_HOME=${shQuote(stateDir)}`] : [],
22838
+ `exec "$node" ${shQuote(runtime)} "$@"`,
22839
+ ""
22840
+ ].join("\n");
22841
+ }
22842
+ async function installLauncher(input2) {
22843
+ const deps = input2.deps ?? {};
22844
+ const platform2 = deps.platform ?? input2.platform;
22845
+ const home = deps.home ?? input2.home;
22846
+ const fsApi = deps.fs ?? realFs;
22847
+ const target = launcherPath(home, platform2);
22848
+ for (const check2 of [conbridgeRoot(home, platform2), binDir(home, platform2), target]) {
22849
+ const info = await fsApi.lstat(check2).catch((error63) => error63.code === "ENOENT" ? null : (() => {
22850
+ throw error63;
22851
+ })());
22852
+ if (info && info.isSymbolicLink())
22853
+ throw new Error(`Refusing to write the launcher through a symlink: ${check2}`);
22854
+ }
22855
+ const content = launcherScript({ home, platform: platform2, stateDir: input2.stateDir, ...input2.nodePath !== void 0 ? { nodePath: input2.nodePath } : {} });
22856
+ await fsApi.mkdir(binDir(home, platform2), { recursive: true });
22857
+ const temp = `${target}.${randomToken(6)}.tmp`;
22858
+ try {
22859
+ await fsApi.writeFile(temp, content, { mode: 493 });
22860
+ if (platform2 !== "win32")
22861
+ await fsApi.chmod(temp, 493);
22862
+ await fsApi.rename(temp, target);
22863
+ } catch (error63) {
22864
+ await fsApi.unlink(temp).catch(() => void 0);
22865
+ throw error63;
22866
+ }
22867
+ }
22868
+ function shellFiles(home) {
22869
+ return [(0, import_node_path7.join)(home, ".zshrc"), (0, import_node_path7.join)(home, ".bashrc"), (0, import_node_path7.join)(home, ".bash_profile"), (0, import_node_path7.join)(home, ".profile")];
22870
+ }
22871
+ var missing = (error63) => {
22872
+ if (error63.code === "ENOENT")
22873
+ return null;
22874
+ throw error63;
22875
+ };
22876
+ function stripPathBlock(content) {
22877
+ const sep3 = content.includes("\r\n") ? "\r\n" : "\n";
22878
+ const lines4 = content.split(sep3);
22879
+ const out = [];
22880
+ let removed = false;
22881
+ for (let i = 0; i < lines4.length; i += 1) {
22882
+ const line = lines4[i];
22883
+ if (line === MARKER_START) {
22884
+ const end = lines4.indexOf(MARKER_END, i + 1);
22885
+ if (end !== -1) {
22886
+ i = end;
22887
+ removed = true;
22888
+ continue;
22889
+ }
22890
+ }
22891
+ out.push(line);
22892
+ }
22893
+ return { content: out.join(sep3), removed };
22894
+ }
22895
+ async function ensurePathEntry(input2) {
22896
+ const deps = input2.deps ?? {};
22897
+ const platform2 = deps.platform ?? input2.platform;
22898
+ const home = deps.home ?? input2.home;
22899
+ const fsApi = deps.fs ?? realFs;
22900
+ const changed = [];
22901
+ if (input2.env.CONBRIDGE_NO_PATH)
22902
+ return changed;
22903
+ if (platform2 === "win32") {
22904
+ const run2 = deps.runPowerShell ?? realPowerShell;
22905
+ const dir = windowsBinDir(home);
22906
+ const result2 = await run2(["-NoProfile", "-NonInteractive", "-Command", WINDOWS_APPEND_SCRIPT], { ...input2.env, CONBRIDGE_BIN_DIR: dir });
22907
+ if (!result2.ok)
22908
+ throw new Error(`PowerShell could not update the user PATH: ${result2.output}`);
22909
+ if (/\badded\b/.test(result2.output))
22910
+ changed.push(dir);
22911
+ return changed;
22912
+ }
22913
+ for (const file2 of shellFiles(home)) {
22914
+ const link = await fsApi.lstat(file2).catch(missing);
22915
+ const info = link ? await fsApi.stat(file2).catch(missing) : null;
22916
+ if (link) {
22917
+ if (!info || !info.isFile())
22918
+ continue;
22919
+ const content = await fsApi.readFile(file2);
22920
+ if (content.includes(MARKER_START))
22921
+ continue;
22922
+ await fsApi.appendFile(file2, (content !== "" && !content.endsWith("\n") ? "\n" : "") + PATH_BLOCK);
22923
+ changed.push(file2);
22924
+ } else if (platform2 === "darwin" && file2 === (0, import_node_path7.join)(home, ".zshrc") || platform2 === "linux" && file2 === (0, import_node_path7.join)(home, ".profile")) {
22925
+ await fsApi.writeFile(file2, PATH_BLOCK, { mode: 420 });
22926
+ changed.push(file2);
22927
+ }
22928
+ }
22929
+ const fishDir = (0, import_node_path7.join)(home, ".config", "fish");
22930
+ const fishInfo = await fsApi.lstat(fishDir).catch(() => null);
22931
+ if (fishInfo && fishInfo.isDirectory()) {
22932
+ const fishFile = (0, import_node_path7.join)(fishDir, "conf.d", "conbridge.fish");
22933
+ await fsApi.mkdir((0, import_node_path7.join)(fishDir, "conf.d"), { recursive: true });
22934
+ const existing = await fsApi.readFile(fishFile).catch(() => null);
22935
+ if (existing === null || !existing.includes(MARKER_START)) {
22936
+ await fsApi.writeFile(fishFile, FISH_BLOCK, { mode: 420 });
22937
+ changed.push(fishFile);
22938
+ }
22939
+ }
22940
+ return changed;
22941
+ }
22942
+ async function removePathEntry(input2) {
22943
+ const deps = input2.deps ?? {};
22944
+ const platform2 = deps.platform ?? input2.platform;
22945
+ const home = deps.home ?? input2.home;
22946
+ const fsApi = deps.fs ?? realFs;
22947
+ const removed = [];
22948
+ if (platform2 === "win32") {
22949
+ const run2 = deps.runPowerShell ?? realPowerShell;
22950
+ const dir = windowsBinDir(home);
22951
+ const result2 = await run2(["-NoProfile", "-NonInteractive", "-Command", WINDOWS_REMOVE_SCRIPT], { ...input2.env, CONBRIDGE_BIN_DIR: dir });
22952
+ if (!result2.ok)
22953
+ throw new Error(`PowerShell could not update the user PATH: ${result2.output}`);
22954
+ if (/\bremoved\b/.test(result2.output))
22955
+ removed.push(dir);
22956
+ return removed;
22957
+ }
22958
+ for (const file2 of shellFiles(home)) {
22959
+ const link = await fsApi.lstat(file2).catch(missing);
22960
+ const info = link ? await fsApi.stat(file2).catch(missing) : null;
22961
+ if (!info || !info.isFile())
22962
+ continue;
22963
+ const stripped = stripPathBlock(await fsApi.readFile(file2));
22964
+ if (!stripped.removed)
22965
+ continue;
22966
+ const real = await fsApi.realpath(file2);
22967
+ const temp = (0, import_node_path7.join)((0, import_node_path7.dirname)(real), `.${LAUNCHER_BIN}-profile.${randomToken(6)}.tmp`);
22968
+ try {
22969
+ await fsApi.writeFile(temp, stripped.content, { mode: info.mode & 511 });
22970
+ await fsApi.chmod(temp, info.mode & 511);
22971
+ await fsApi.rename(temp, real);
22972
+ } catch (error63) {
22973
+ await fsApi.unlink(temp).catch(() => void 0);
22974
+ throw error63;
22975
+ }
22976
+ removed.push(file2);
22977
+ }
22978
+ const fishFile = (0, import_node_path7.join)(home, ".config", "fish", "conf.d", "conbridge.fish");
22979
+ const fishInfo = await fsApi.lstat(fishFile).catch((error63) => error63.code === "ENOENT" ? null : (() => {
22980
+ throw error63;
22981
+ })());
22982
+ if (fishInfo && fishInfo.isFile()) {
22983
+ await fsApi.unlink(fishFile);
22984
+ removed.push(fishFile);
22985
+ }
22986
+ return removed;
22987
+ }
22988
+ function agentCommandLines(input2) {
22989
+ const path = launcherPath(input2.home, input2.platform);
22990
+ const launcher = input2.platform === "win32" ? `& "${path}"` : /^[A-Za-z0-9_./~-]+$/.test(path) ? path : shQuote(path);
22991
+ return [
22992
+ `conbridge-agent ${input2.command}`,
22993
+ `If this terminal does not find it yet, run: ${launcher} ${input2.command}`,
22994
+ `or: npx --yes conbridge-agent@latest ${input2.command}`
22995
+ ];
22996
+ }
22997
+ function homeFromEnv(env) {
22998
+ return env.HOME ?? env.USERPROFILE ?? (0, import_node_os3.homedir)();
22999
+ }
23000
+
22727
23001
  // dist/purge.js
23002
+ function serviceLogFiles(platform2, home, env) {
23003
+ if (platform2 === "darwin")
23004
+ return [defaultLogPath(home)];
23005
+ if (platform2 === "linux")
23006
+ return [linuxDefaultLogPath(home)];
23007
+ if (platform2 === "win32") {
23008
+ const localAppData = env.LOCALAPPDATA ?? import_node_path8.win32.join(home, "AppData", "Local");
23009
+ return [import_node_path8.win32.join(localAppData, "ConBridge", "conbridge-agent.log")];
23010
+ }
23011
+ return [];
23012
+ }
22728
23013
  var ownRemove = async (path) => {
22729
- await (0, import_promises6.rm)(path, { recursive: true, force: true });
23014
+ await (0, import_promises7.rm)(path, { recursive: true, force: true });
22730
23015
  };
22731
- var exists = async (path) => (0, import_promises6.access)(path).then(() => true, () => false);
23016
+ var exists = async (path) => (0, import_promises7.access)(path).then(() => true, () => false);
22732
23017
  function safeStateDir(stateDir, home, platform2 = process.platform) {
22733
- const pathApi = platform2 === "win32" ? import_node_path7.win32 : { resolve: import_node_path7.resolve, dirname: import_node_path7.dirname, join: import_node_path7.join, sep: "/" };
23018
+ const pathApi = platform2 === "win32" ? import_node_path8.win32 : { resolve: import_node_path8.resolve, dirname: import_node_path8.dirname, join: import_node_path8.join, sep: "/" };
22734
23019
  const dir = pathApi.resolve(stateDir);
22735
23020
  const homeDir = pathApi.resolve(home);
22736
23021
  if (dir === pathApi.dirname(dir) || dir === homeDir || homeDir.startsWith(dir + pathApi.sep) || dir === pathApi.join(homeDir, ".conbridge")) {
@@ -22740,7 +23025,7 @@ function safeStateDir(stateDir, home, platform2 = process.platform) {
22740
23025
  }
22741
23026
  var STATE_ENTRY = /^(?:identity\.json|device-key\.pem|config\.json|journal\.jsonl|hosts\.json|known_hosts|agent\.lock|supervisor\.pid|conbridge-agent-service\.vbs|runtime|ssh|\.(?:identity\.json|device-key\.pem|config\.json|journal\.jsonl|hosts\.json)\.[A-Za-z0-9_-]+\.tmp)$/;
22742
23027
  async function stateEntries(stateDir, dedicated, keepRuntime, pathApi) {
22743
- const names = await (0, import_promises6.readdir)(stateDir).catch((error63) => {
23028
+ const names = await (0, import_promises7.readdir)(stateDir).catch((error63) => {
22744
23029
  if (error63.code === "ENOENT")
22745
23030
  return [];
22746
23031
  throw error63;
@@ -22751,7 +23036,7 @@ function boundedCommand(signal) {
22751
23036
  return (file2, args) => new Promise((done) => {
22752
23037
  if (signal?.aborted)
22753
23038
  return done({ ok: false, output: "purge time limit reached" });
22754
- (0, import_node_child_process3.execFile)(file2, args, { timeout: 1e4, windowsHide: true, ...signal ? { signal } : {} }, (error63, stdout, stderr) => {
23039
+ (0, import_node_child_process4.execFile)(file2, args, { timeout: 1e4, windowsHide: true, ...signal ? { signal } : {} }, (error63, stdout, stderr) => {
22755
23040
  done({ ok: !error63, output: `${stdout}${stderr}`.trim() });
22756
23041
  });
22757
23042
  });
@@ -22760,13 +23045,22 @@ function boundedCronWriter(signal) {
22760
23045
  return (text6) => new Promise((done) => {
22761
23046
  if (signal?.aborted)
22762
23047
  return done({ ok: false, output: "purge time limit reached" });
22763
- const child = (0, import_node_child_process3.execFile)("crontab", ["-"], { timeout: 1e4, ...signal ? { signal } : {} }, (error63, stdout, stderr) => {
23048
+ const child = (0, import_node_child_process4.execFile)("crontab", ["-"], { timeout: 1e4, ...signal ? { signal } : {} }, (error63, stdout, stderr) => {
22764
23049
  done({ ok: !error63, output: `${stdout}${stderr}`.trim() });
22765
23050
  });
22766
23051
  child.stdin?.on("error", () => void 0);
22767
23052
  child.stdin?.end(text6);
22768
23053
  });
22769
23054
  }
23055
+ function purgePowerShell(signal) {
23056
+ return (args, env) => new Promise((done) => {
23057
+ if (signal?.aborted)
23058
+ return done({ ok: false, output: "purge time limit reached" });
23059
+ (0, import_node_child_process4.execFile)("powershell.exe", args, { timeout: 1e4, windowsHide: true, env: { ...process.env, ...env }, ...signal ? { signal } : {} }, (error63, stdout, stderr) => {
23060
+ done({ ok: !error63, output: `${stdout}${stderr}`.trim() });
23061
+ });
23062
+ });
23063
+ }
22770
23064
  async function removeAgentAutostart(stateDir = resolveStateDir(), deps = {}, signal) {
22771
23065
  const platform2 = deps.platform ?? process.platform;
22772
23066
  const run2 = deps.run ?? boundedCommand(signal);
@@ -22794,7 +23088,7 @@ async function removeAgentAutostart(stateDir = resolveStateDir(), deps = {}, sig
22794
23088
  throw new AggregateError(failures, "Some autostart files could not be removed");
22795
23089
  }
22796
23090
  async function removeAgentIdentity(options = {}, deps = {}) {
22797
- const stateDir = safeStateDir(options.stateDir ?? deps.env?.CONBRIDGE_AGENT_HOME ?? (0, import_node_path7.join)(deps.home ?? (0, import_node_os3.homedir)(), ".conbridge", "agent"), deps.home ?? (0, import_node_os3.homedir)(), deps.platform);
23091
+ const stateDir = safeStateDir(options.stateDir ?? deps.env?.CONBRIDGE_AGENT_HOME ?? (0, import_node_path8.join)(deps.home ?? (0, import_node_os4.homedir)(), ".conbridge", "agent"), deps.home ?? (0, import_node_os4.homedir)(), deps.platform);
22798
23092
  const paths = statePaths(stateDir);
22799
23093
  const identity = await (deps.loadIdentity ?? loadIdentity)(paths);
22800
23094
  const failures = [];
@@ -22826,8 +23120,8 @@ function agentLeaveMessage(body) {
22826
23120
  }
22827
23121
  async function purgeAgent(options, deps = {}) {
22828
23122
  const platform2 = deps.platform ?? process.platform;
22829
- const home = deps.home ?? (0, import_node_os3.homedir)();
22830
- const stateDir = safeStateDir(options.stateDir ?? deps.env?.CONBRIDGE_AGENT_HOME ?? (0, import_node_path7.join)(deps.home ?? (0, import_node_os3.homedir)(), ".conbridge", "agent"), home, platform2);
23123
+ const home = deps.home ?? (0, import_node_os4.homedir)();
23124
+ const stateDir = safeStateDir(options.stateDir ?? deps.env?.CONBRIDGE_AGENT_HOME ?? (0, import_node_path8.join)(deps.home ?? (0, import_node_os4.homedir)(), ".conbridge", "agent"), home, platform2);
22831
23125
  const paths = statePaths(stateDir);
22832
23126
  const report = deps.report ?? ((line) => console.log(line));
22833
23127
  const remove = deps.remove ?? ownRemove;
@@ -22897,20 +23191,28 @@ async function purgeAgent(options, deps = {}) {
22897
23191
  await (await storeFor(paths, identity, deps)).remove();
22898
23192
  }
22899
23193
  });
22900
- const pathApi = platform2 === "win32" ? import_node_path7.win32 : import_node_path7.posix;
23194
+ const pathApi = platform2 === "win32" ? import_node_path8.win32 : import_node_path8.posix;
22901
23195
  const dedicated = pathApi.resolve(stateDir) === pathApi.resolve(pathApi.join(home, ".conbridge", "agent"));
22902
23196
  await step("files", async (signal) => {
22903
- const parentInfo = await (0, import_promises6.lstat)(pathApi.join(home, ".conbridge")).catch((error63) => {
23197
+ const failures = [];
23198
+ if (!options.keepRuntime) {
23199
+ try {
23200
+ await removePathEntry({ home, platform: platform2, env: deps.env ?? process.env, deps: { runPowerShell: deps.runPowerShell ?? purgePowerShell(signal) } });
23201
+ } catch (error63) {
23202
+ failures.push(error63);
23203
+ }
23204
+ }
23205
+ const parentInfo = await (0, import_promises7.lstat)(pathApi.join(home, ".conbridge")).catch((error63) => {
22904
23206
  if (error63.code === "ENOENT")
22905
23207
  return null;
22906
23208
  throw error63;
22907
23209
  });
22908
23210
  if (parentInfo?.isSymbolicLink())
22909
23211
  throw new Error("Refusing to traverse a symlink at ~/.conbridge");
22910
- if (options.keepRuntime && (await (0, import_promises6.lstat)(stateDir).catch(() => null))?.isSymbolicLink()) {
23212
+ if (options.keepRuntime && (await (0, import_promises7.lstat)(stateDir).catch(() => null))?.isSymbolicLink()) {
22911
23213
  throw new Error("Refusing to traverse a symlink at the agent state directory");
22912
23214
  }
22913
- if (!dedicated && (await (0, import_promises6.lstat)(stateDir).catch(() => null))?.isSymbolicLink()) {
23215
+ if (!dedicated && (await (0, import_promises7.lstat)(stateDir).catch(() => null))?.isSymbolicLink()) {
22914
23216
  throw new Error("Refusing to traverse a symlink at the agent state directory");
22915
23217
  }
22916
23218
  const targets = options.keepRuntime ? [] : [pathApi.join(home, ".conbridge", "node"), pathApi.join(home, ".conbridge", "bin")];
@@ -22918,30 +23220,31 @@ async function purgeAgent(options, deps = {}) {
22918
23220
  targets.unshift(...await stateEntries(stateDir, dedicated, options.keepRuntime ?? false, pathApi));
22919
23221
  else
22920
23222
  targets.unshift(stateDir);
23223
+ const logs = serviceLogFiles(platform2, home, deps.env ?? process.env);
22921
23224
  const removeEmptyDir = !dedicated && !options.keepRuntime;
22922
23225
  if (platform2 === "win32" && targets.length > 0) {
22923
- if (targets.some((path) => /["%\r\n!&|<>^]/.test(path)))
22924
- throw new Error("Unsupported character in deferred deletion path");
22925
- if (/["%\r\n!&|<>^]/.test(stateDir))
23226
+ if ([...targets, ...logs, stateDir].some((path) => /["%\r\n!&|<>^]/.test(path)))
22926
23227
  throw new Error("Unsupported character in deferred deletion path");
22927
- const command2 = `powershell.exe -NoProfile -NonInteractive -Command "Wait-Process -Id ${process.pid} -ErrorAction SilentlyContinue" >nul 2>nul & ${targets.map((path) => `if exist "${path}" (rmdir /s /q "${path}" 2>nul & del /f /q "${path}" 2>nul)`).join(" & ")}${removeEmptyDir ? ` & rmdir "${stateDir}" 2>nul` : ""}`;
23228
+ const logCommands = logs.map((path) => `del /f /q "${path}" 2>nul & rmdir "${import_node_path8.win32.dirname(path)}" 2>nul`);
23229
+ const command2 = `powershell.exe -NoProfile -NonInteractive -Command "Wait-Process -Id ${process.pid} -ErrorAction SilentlyContinue" >nul 2>nul & ${targets.map((path) => `if exist "${path}" (rmdir /s /q "${path}" 2>nul & del /f /q "${path}" 2>nul)`).join(" & ")}${removeEmptyDir ? ` & rmdir "${stateDir}" 2>nul` : ""}${logCommands.length ? ` & ${logCommands.join(" & ")}` : ""}`;
22928
23230
  if (signal.aborted)
22929
23231
  return;
22930
- const launch = deps.spawnDetached ?? ((file2, args) => new Promise((resolve9, reject) => {
22931
- const child = (0, import_node_child_process3.spawn)(file2, args, { detached: true, stdio: "ignore", windowsHide: true });
23232
+ const launch = deps.spawnDetached ?? ((file2, args, spawnOptions) => new Promise((resolve10, reject) => {
23233
+ const child = (0, import_node_child_process4.spawn)(file2, args, { detached: true, stdio: "ignore", windowsHide: true, ...spawnOptions });
22932
23234
  child.once("error", reject);
22933
23235
  child.once("spawn", () => {
22934
23236
  child.unref();
22935
- resolve9();
23237
+ resolve10();
22936
23238
  });
22937
23239
  }));
22938
- await launch("cmd.exe", ["/d", "/s", "/c", command2]);
23240
+ await launch("cmd.exe", ["/d", "/s", "/c", `"${command2}"`], { windowsVerbatimArguments: true });
22939
23241
  deferred = true;
22940
23242
  report("ConBridge files will be deleted after the agent exits.");
23243
+ if (failures.length)
23244
+ throw new AggregateError(failures, "The PATH entry could not be removed");
22941
23245
  return;
22942
23246
  }
22943
- const failures = [];
22944
- for (const path of targets) {
23247
+ for (const path of [...targets, ...logs]) {
22945
23248
  if (signal.aborted)
22946
23249
  break;
22947
23250
  try {
@@ -22951,7 +23254,7 @@ async function purgeAgent(options, deps = {}) {
22951
23254
  }
22952
23255
  }
22953
23256
  if (removeEmptyDir && !signal.aborted) {
22954
- await (0, import_promises6.rmdir)(stateDir).catch((error63) => {
23257
+ await (0, import_promises7.rmdir)(stateDir).catch((error63) => {
22955
23258
  if (error63.code !== "ENOENT" && error63.code !== "ENOTEMPTY" && error63.code !== "EEXIST")
22956
23259
  failures.push(error63);
22957
23260
  });
@@ -22983,6 +23286,12 @@ async function purgeAgent(options, deps = {}) {
22983
23286
  if (await has(path))
22984
23287
  leftovers.push(platform2 === "win32" ? `rmdir /s /q "${path}"` : `rm -rf -- ${quote(path)}`);
22985
23288
  }
23289
+ for (const path of serviceLogFiles(platform2, home, deps.env ?? process.env)) {
23290
+ if (signal.aborted)
23291
+ break;
23292
+ if (await has(path))
23293
+ leftovers.push(platform2 === "win32" ? `del /f /q "${path}"` : `rm -f -- ${quote(path)}`);
23294
+ }
22986
23295
  }
22987
23296
  for (const command2 of leftovers)
22988
23297
  report(`ConBridge files remain. To remove them, run: ${command2}`);
@@ -22992,18 +23301,18 @@ async function purgeAgent(options, deps = {}) {
22992
23301
  }
22993
23302
 
22994
23303
  // dist/cli.js
22995
- var import_node_child_process11 = require("node:child_process");
23304
+ var import_node_child_process12 = require("node:child_process");
22996
23305
  var import_node_crypto12 = require("node:crypto");
22997
23306
  var import_node_fs4 = require("node:fs");
22998
- var import_promises17 = require("node:fs/promises");
22999
- var import_node_os9 = require("node:os");
23000
- var import_node_path18 = require("node:path");
23307
+ var import_promises18 = require("node:fs/promises");
23308
+ var import_node_os10 = require("node:os");
23309
+ var import_node_path19 = require("node:path");
23001
23310
  var import_node_url3 = require("node:url");
23002
23311
  var import_node_util2 = require("node:util");
23003
23312
 
23004
23313
  // dist/confirm.js
23005
- var import_node_child_process4 = require("node:child_process");
23006
- var import_node_path8 = require("node:path");
23314
+ var import_node_child_process5 = require("node:child_process");
23315
+ var import_node_path9 = require("node:path");
23007
23316
  var CONFIRM_TIMEOUT_MS = 13e4;
23008
23317
  function confirmText(request) {
23009
23318
  const verb = request.created ? "create" : "overwrite";
@@ -23018,11 +23327,11 @@ function buildConfirmScript(request) {
23018
23327
  var macDialogConfirm = (request) => {
23019
23328
  if (process.platform !== "darwin")
23020
23329
  return Promise.resolve(false);
23021
- return new Promise((resolve9) => {
23022
- (0, import_node_child_process4.execFile)("/usr/bin/osascript", ["-e", buildConfirmScript(request)], { timeout: CONFIRM_TIMEOUT_MS }, (error63, stdout) => {
23330
+ return new Promise((resolve10) => {
23331
+ (0, import_node_child_process5.execFile)("/usr/bin/osascript", ["-e", buildConfirmScript(request)], { timeout: CONFIRM_TIMEOUT_MS }, (error63, stdout) => {
23023
23332
  if (error63)
23024
- return resolve9(false);
23025
- resolve9(/button returned:Allow/.test(stdout) && !/gave up:true/.test(stdout));
23333
+ return resolve10(false);
23334
+ resolve10(/button returned:Allow/.test(stdout) && !/gave up:true/.test(stdout));
23026
23335
  });
23027
23336
  });
23028
23337
  };
@@ -23031,20 +23340,20 @@ var WINDOWS_CONFIRM_SCRIPT = [
23031
23340
  '$r = [System.Windows.MessageBox]::Show($env:CONBRIDGE_CONFIRM_TEXT, "ConBridge", "YesNo", "Warning", "No")',
23032
23341
  'if ($r -eq "Yes") { exit 0 } else { exit 1 }'
23033
23342
  ].join("; ");
23034
- var windowsConfirm = (request) => new Promise((resolve9) => {
23035
- const powershell = import_node_path8.win32.join(process.env.SystemRoot ?? "C:\\Windows", "System32", "WindowsPowerShell", "v1.0", "powershell.exe");
23036
- (0, import_node_child_process4.execFile)(powershell, ["-NoProfile", "-NonInteractive", "-ExecutionPolicy", "Bypass", "-Command", WINDOWS_CONFIRM_SCRIPT], { timeout: CONFIRM_TIMEOUT_MS, windowsHide: false, env: { ...process.env, CONBRIDGE_CONFIRM_TEXT: confirmText(request) } }, (error63) => resolve9(!error63));
23343
+ var windowsConfirm = (request) => new Promise((resolve10) => {
23344
+ const powershell = import_node_path9.win32.join(process.env.SystemRoot ?? "C:\\Windows", "System32", "WindowsPowerShell", "v1.0", "powershell.exe");
23345
+ (0, import_node_child_process5.execFile)(powershell, ["-NoProfile", "-NonInteractive", "-ExecutionPolicy", "Bypass", "-Command", WINDOWS_CONFIRM_SCRIPT], { timeout: CONFIRM_TIMEOUT_MS, windowsHide: false, env: { ...process.env, CONBRIDGE_CONFIRM_TEXT: confirmText(request) } }, (error63) => resolve10(!error63));
23037
23346
  });
23038
- var linuxConfirm = (request) => new Promise((resolve9) => {
23347
+ var linuxConfirm = (request) => new Promise((resolve10) => {
23039
23348
  if (!process.env.DISPLAY && !process.env.WAYLAND_DISPLAY)
23040
- return resolve9(false);
23349
+ return resolve10(false);
23041
23350
  const text6 = confirmText(request);
23042
- (0, import_node_child_process4.execFile)("zenity", ["--question", "--title=ConBridge", `--text=${text6}`, "--ok-label=Allow", "--cancel-label=Deny", "--default-cancel", "--timeout=120"], { timeout: CONFIRM_TIMEOUT_MS }, (error63) => {
23351
+ (0, import_node_child_process5.execFile)("zenity", ["--question", "--title=ConBridge", `--text=${text6}`, "--ok-label=Allow", "--cancel-label=Deny", "--default-cancel", "--timeout=120"], { timeout: CONFIRM_TIMEOUT_MS }, (error63) => {
23043
23352
  if (!error63)
23044
- return resolve9(true);
23353
+ return resolve10(true);
23045
23354
  if (error63.code !== "ENOENT")
23046
- return resolve9(false);
23047
- (0, import_node_child_process4.execFile)("kdialog", ["--title", "ConBridge", "--warningyesno", text6, "--yes-label", "Allow", "--no-label", "Deny"], { timeout: CONFIRM_TIMEOUT_MS }, (fallback) => resolve9(!fallback));
23355
+ return resolve10(false);
23356
+ (0, import_node_child_process5.execFile)("kdialog", ["--title", "ConBridge", "--warningyesno", text6, "--yes-label", "Allow", "--no-label", "Deny"], { timeout: CONFIRM_TIMEOUT_MS }, (fallback) => resolve10(!fallback));
23048
23357
  });
23049
23358
  });
23050
23359
  var localConfirm = (request) => {
@@ -23058,8 +23367,8 @@ var localConfirm = (request) => {
23058
23367
  };
23059
23368
 
23060
23369
  // dist/connect.js
23061
- var import_node_child_process5 = require("node:child_process");
23062
- var import_node_path9 = require("node:path");
23370
+ var import_node_child_process6 = require("node:child_process");
23371
+ var import_node_path10 = require("node:path");
23063
23372
 
23064
23373
  // dist/pairing.js
23065
23374
  var PAIRING_CODE = /^[ABCDEFGHJKLMNPQRSTUVWXYZ23456789]{4}-?[ABCDEFGHJKLMNPQRSTUVWXYZ23456789]{4}$/;
@@ -23137,7 +23446,7 @@ async function pairDevice(options) {
23137
23446
  throw new Error("Device name must be 1 to 128 characters");
23138
23447
  const platform2 = options.platform ?? currentPlatform();
23139
23448
  const doFetch = options.fetch ?? ((input2, init) => fetch(input2, init));
23140
- const sleep = options.sleep ?? ((ms) => new Promise((resolve9) => setTimeout(resolve9, ms)));
23449
+ const sleep = options.sleep ?? ((ms) => new Promise((resolve10) => setTimeout(resolve10, ms)));
23141
23450
  const key = await options.keyStore.create();
23142
23451
  const fingerprint = keyFingerprint(key.publicKeyRaw());
23143
23452
  let succeeded = false;
@@ -23244,9 +23553,9 @@ async function runConnect(link, deps, extraHosts = []) {
23244
23553
  const skipped = [];
23245
23554
  for (const folder of folders) {
23246
23555
  try {
23247
- await deps.addFolder(folder, (0, import_node_path9.basename)(folder) || folder, writable);
23556
+ await deps.addFolder(folder, (0, import_node_path10.basename)(folder) || folder, writable);
23248
23557
  } catch (error63) {
23249
- skipped.push(`${(0, import_node_path9.basename)(folder) || folder}: ${friendly(error63)}`);
23558
+ skipped.push(`${(0, import_node_path10.basename)(folder) || folder}: ${friendly(error63)}`);
23250
23559
  }
23251
23560
  }
23252
23561
  if (skipped.length > 0)
@@ -23266,9 +23575,9 @@ function appleScriptString2(value) {
23266
23575
  return '"' + value.replace(/[\\"]/g, "\\$&").replace(/\r?\n/g, '" & linefeed & "') + '"';
23267
23576
  }
23268
23577
  function osascript(script, timeoutMs) {
23269
- return new Promise((resolve9) => {
23270
- (0, import_node_child_process5.execFile)("/usr/bin/osascript", ["-e", "tell current application to activate", "-e", script], { timeout: timeoutMs }, (error63, stdout) => {
23271
- resolve9({ ok: !error63, stdout: stdout ?? "" });
23578
+ return new Promise((resolve10) => {
23579
+ (0, import_node_child_process6.execFile)("/usr/bin/osascript", ["-e", "tell current application to activate", "-e", script], { timeout: timeoutMs }, (error63, stdout) => {
23580
+ resolve10({ ok: !error63, stdout: stdout ?? "" });
23272
23581
  });
23273
23582
  });
23274
23583
  }
@@ -23304,8 +23613,8 @@ Name: ${name3}`;
23304
23613
  };
23305
23614
 
23306
23615
  // dist/journal.js
23307
- var import_promises7 = require("node:fs/promises");
23308
- var import_node_path10 = require("node:path");
23616
+ var import_promises8 = require("node:fs/promises");
23617
+ var import_node_path11 = require("node:path");
23309
23618
  var storedResultSchema = external_exports.strictObject({
23310
23619
  state: external_exports.enum(["SUCCEEDED", "FAILED", "CANCELLED", "EXPIRED"]),
23311
23620
  executed: external_exports.boolean(),
@@ -23380,7 +23689,7 @@ var Journal = class _Journal {
23380
23689
  const journal = new _Journal(path);
23381
23690
  let text6 = "";
23382
23691
  try {
23383
- text6 = await (0, import_promises7.readFile)(path, "utf8");
23692
+ text6 = await (0, import_promises8.readFile)(path, "utf8");
23384
23693
  } catch (error63) {
23385
23694
  if (errorCode2(error63) !== "ENOENT")
23386
23695
  throw error63;
@@ -23438,7 +23747,7 @@ var Journal = class _Journal {
23438
23747
  async #append(entry) {
23439
23748
  const line = JSON.stringify(entrySchema.parse(entry)) + "\n";
23440
23749
  await this.#serialize(async () => {
23441
- const handle = await (0, import_promises7.open)(this.#path, "a", 384);
23750
+ const handle = await (0, import_promises8.open)(this.#path, "a", 384);
23442
23751
  try {
23443
23752
  await handle.appendFile(line, "utf8");
23444
23753
  await handle.sync();
@@ -23488,7 +23797,7 @@ var Journal = class _Journal {
23488
23797
  return this.#serialize(async () => {
23489
23798
  let text6 = "";
23490
23799
  try {
23491
- text6 = await (0, import_promises7.readFile)(this.#path, "utf8");
23800
+ text6 = await (0, import_promises8.readFile)(this.#path, "utf8");
23492
23801
  } catch (error63) {
23493
23802
  if (errorCode2(error63) === "ENOENT")
23494
23803
  return;
@@ -23523,24 +23832,24 @@ var Journal = class _Journal {
23523
23832
  const lines4 = kept.map((entry) => JSON.stringify(entry) + "\n");
23524
23833
  if (watermark !== null)
23525
23834
  lines4.unshift(JSON.stringify(watermarkSchema.parse({ type: "WATERMARK", at_ms: now, watermark_ms: watermark })) + "\n");
23526
- const temp = (0, import_node_path10.join)((0, import_node_path10.dirname)(this.#path), `.${(0, import_node_path10.basename)(this.#path)}.${randomToken(6)}.tmp`);
23527
- const handle = await (0, import_promises7.open)(temp, "wx", 384);
23835
+ const temp = (0, import_node_path11.join)((0, import_node_path11.dirname)(this.#path), `.${(0, import_node_path11.basename)(this.#path)}.${randomToken(6)}.tmp`);
23836
+ const handle = await (0, import_promises8.open)(temp, "wx", 384);
23528
23837
  try {
23529
23838
  await handle.writeFile(lines4.join(""), "utf8");
23530
23839
  await handle.sync();
23531
23840
  } catch (error63) {
23532
23841
  await handle.close().catch(() => void 0);
23533
- await (0, import_promises7.unlink)(temp).catch(() => void 0);
23842
+ await (0, import_promises8.unlink)(temp).catch(() => void 0);
23534
23843
  throw error63;
23535
23844
  }
23536
23845
  await handle.close();
23537
23846
  try {
23538
- await (0, import_promises7.rename)(temp, this.#path);
23847
+ await (0, import_promises8.rename)(temp, this.#path);
23539
23848
  } catch (error63) {
23540
- await (0, import_promises7.unlink)(temp).catch(() => void 0);
23849
+ await (0, import_promises8.unlink)(temp).catch(() => void 0);
23541
23850
  throw error63;
23542
23851
  }
23543
- await fsyncDirectory((0, import_node_path10.dirname)(this.#path));
23852
+ await fsyncDirectory((0, import_node_path11.dirname)(this.#path));
23544
23853
  this.#records.clear();
23545
23854
  this.#nonces.clear();
23546
23855
  for (const entry of kept)
@@ -23552,22 +23861,22 @@ var Journal = class _Journal {
23552
23861
  };
23553
23862
 
23554
23863
  // dist/install.js
23555
- var import_promises8 = require("node:fs/promises");
23556
- var import_node_path11 = require("node:path");
23864
+ var import_promises9 = require("node:fs/promises");
23865
+ var import_node_path12 = require("node:path");
23557
23866
  var import_node_url2 = require("node:url");
23558
23867
  var RUNTIME_ENTRY = "conbridge-agent.cjs";
23559
23868
  function runtimeDir(stateDir) {
23560
- return (0, import_node_path11.join)(stateDir, "runtime");
23869
+ return (0, import_node_path12.join)(stateDir, "runtime");
23561
23870
  }
23562
23871
  function runtimeEntry(stateDir) {
23563
- return (0, import_node_path11.join)(runtimeDir(stateDir), RUNTIME_ENTRY);
23872
+ return (0, import_node_path12.join)(runtimeDir(stateDir), RUNTIME_ENTRY);
23564
23873
  }
23565
23874
  function currentEntry() {
23566
23875
  return (0, import_node_url2.fileURLToPath)(__conbridge_import_meta_url);
23567
23876
  }
23568
23877
  async function sameBytes(a, b) {
23569
23878
  try {
23570
- const [left, right] = await Promise.all([(0, import_promises8.readFile)(a), (0, import_promises8.readFile)(b)]);
23879
+ const [left, right] = await Promise.all([(0, import_promises9.readFile)(a), (0, import_promises9.readFile)(b)]);
23571
23880
  return left.equals(right);
23572
23881
  } catch {
23573
23882
  return false;
@@ -23576,11 +23885,11 @@ async function sameBytes(a, b) {
23576
23885
  async function copyAtomic(from, to, mode) {
23577
23886
  const temp = `${to}.${randomToken(6)}.tmp`;
23578
23887
  try {
23579
- await (0, import_promises8.copyFile)(from, temp);
23580
- await (0, import_promises8.chmod)(temp, mode);
23581
- await (0, import_promises8.rename)(temp, to);
23888
+ await (0, import_promises9.copyFile)(from, temp);
23889
+ await (0, import_promises9.chmod)(temp, mode);
23890
+ await (0, import_promises9.rename)(temp, to);
23582
23891
  } catch (error63) {
23583
- await (0, import_promises8.unlink)(temp).catch(() => void 0);
23892
+ await (0, import_promises9.unlink)(temp).catch(() => void 0);
23584
23893
  throw error63;
23585
23894
  }
23586
23895
  }
@@ -23589,21 +23898,21 @@ async function installRuntime(stateDir, from = {}) {
23589
23898
  const sourceDir = from.codeDir ?? codeDirectory();
23590
23899
  const dir = runtimeDir(stateDir);
23591
23900
  const entry = runtimeEntry(stateDir);
23592
- await (0, import_promises8.mkdir)(dir, { recursive: true, mode: 448 });
23593
- await (0, import_promises8.chmod)(dir, 448);
23901
+ await (0, import_promises9.mkdir)(dir, { recursive: true, mode: 448 });
23902
+ await (0, import_promises9.chmod)(dir, 448);
23594
23903
  let changed = false;
23595
23904
  if (!await sameBytes(source, entry)) {
23596
23905
  await copyAtomic(source, entry, 384);
23597
23906
  changed = true;
23598
23907
  }
23599
- const helper = (0, import_node_path11.join)(sourceDir, KEYCHAIN_HELPER_NAME);
23600
- const helperTarget = (0, import_node_path11.join)(dir, KEYCHAIN_HELPER_NAME);
23601
- const hasHelper = await (0, import_promises8.stat)(helper).then((info) => info.isFile(), () => false);
23908
+ const helper = (0, import_node_path12.join)(sourceDir, KEYCHAIN_HELPER_NAME);
23909
+ const helperTarget = (0, import_node_path12.join)(dir, KEYCHAIN_HELPER_NAME);
23910
+ const hasHelper = await (0, import_promises9.stat)(helper).then((info) => info.isFile(), () => false);
23602
23911
  if (hasHelper && !await sameBytes(helper, helperTarget)) {
23603
23912
  await copyAtomic(helper, helperTarget, 493);
23604
23913
  changed = true;
23605
23914
  } else if (!hasHelper) {
23606
- await (0, import_promises8.unlink)(helperTarget).catch((error63) => {
23915
+ await (0, import_promises9.unlink)(helperTarget).catch((error63) => {
23607
23916
  if (errorCode2(error63) !== "ENOENT")
23608
23917
  throw error63;
23609
23918
  });
@@ -23613,26 +23922,26 @@ async function installRuntime(stateDir, from = {}) {
23613
23922
  async function snapshotRuntime(stateDir) {
23614
23923
  const dir = runtimeDir(stateDir);
23615
23924
  const backup = `${dir}.previous`;
23616
- await (0, import_promises8.rm)(backup, { recursive: true, force: true });
23617
- await (0, import_promises8.mkdir)(backup, { recursive: true, mode: 448 });
23925
+ await (0, import_promises9.rm)(backup, { recursive: true, force: true });
23926
+ await (0, import_promises9.mkdir)(backup, { recursive: true, mode: 448 });
23618
23927
  const saved = /* @__PURE__ */ new Map();
23619
23928
  for (const name3 of [RUNTIME_ENTRY, KEYCHAIN_HELPER_NAME]) {
23620
- const info = await (0, import_promises8.stat)((0, import_node_path11.join)(dir, name3)).catch(() => null);
23929
+ const info = await (0, import_promises9.stat)((0, import_node_path12.join)(dir, name3)).catch(() => null);
23621
23930
  if (!info?.isFile())
23622
23931
  continue;
23623
- await (0, import_promises8.copyFile)((0, import_node_path11.join)(dir, name3), (0, import_node_path11.join)(backup, name3));
23932
+ await (0, import_promises9.copyFile)((0, import_node_path12.join)(dir, name3), (0, import_node_path12.join)(backup, name3));
23624
23933
  saved.set(name3, info.mode & 511);
23625
23934
  }
23626
- const discard = () => (0, import_promises8.rm)(backup, { recursive: true, force: true });
23935
+ const discard = () => (0, import_promises9.rm)(backup, { recursive: true, force: true });
23627
23936
  return {
23628
23937
  async restore() {
23629
- await (0, import_promises8.mkdir)(dir, { recursive: true, mode: 448 });
23938
+ await (0, import_promises9.mkdir)(dir, { recursive: true, mode: 448 });
23630
23939
  for (const name3 of [RUNTIME_ENTRY, KEYCHAIN_HELPER_NAME]) {
23631
23940
  const mode = saved.get(name3);
23632
23941
  if (mode !== void 0)
23633
- await copyAtomic((0, import_node_path11.join)(backup, name3), (0, import_node_path11.join)(dir, name3), mode);
23942
+ await copyAtomic((0, import_node_path12.join)(backup, name3), (0, import_node_path12.join)(dir, name3), mode);
23634
23943
  else
23635
- await (0, import_promises8.unlink)((0, import_node_path11.join)(dir, name3)).catch((error63) => {
23944
+ await (0, import_promises9.unlink)((0, import_node_path12.join)(dir, name3)).catch((error63) => {
23636
23945
  if (errorCode2(error63) !== "ENOENT")
23637
23946
  throw error63;
23638
23947
  });
@@ -23648,7 +23957,7 @@ async function runningFromRuntime(stateDir, entry = currentEntry()) {
23648
23957
  }
23649
23958
 
23650
23959
  // dist/keepawake.js
23651
- var import_node_child_process6 = require("node:child_process");
23960
+ var import_node_child_process7 = require("node:child_process");
23652
23961
  var WINDOWS_SCRIPT = (pid) => [
23653
23962
  "$ErrorActionPreference = 'Stop'",
23654
23963
  `Add-Type -Namespace ConBridge -Name Power -MemberDefinition '[DllImport("kernel32.dll")] public static extern uint SetThreadExecutionState(uint flags);'`,
@@ -23675,7 +23984,7 @@ function keepAwakeCommand(platform2 = process.platform, pid = process.pid, env =
23675
23984
  }
23676
23985
  return null;
23677
23986
  }
23678
- var defaultSpawner = (file2, args) => (0, import_node_child_process6.spawn)(file2, [...args], { stdio: "ignore", windowsHide: true });
23987
+ var defaultSpawner = (file2, args) => (0, import_node_child_process7.spawn)(file2, [...args], { stdio: "ignore", windowsHide: true });
23679
23988
  function startKeepAwake(options = {}) {
23680
23989
  const logger = options.logger ?? silentLogger;
23681
23990
  const command2 = keepAwakeCommand(options.platform);
@@ -23708,7 +24017,7 @@ function startKeepAwake(options = {}) {
23708
24017
  }
23709
24018
 
23710
24019
  // dist/lock.js
23711
- var import_promises9 = require("node:fs/promises");
24020
+ var import_promises10 = require("node:fs/promises");
23712
24021
  function alive(pid) {
23713
24022
  try {
23714
24023
  process.kill(pid, 0);
@@ -23719,7 +24028,7 @@ function alive(pid) {
23719
24028
  }
23720
24029
  async function readLockPid(path) {
23721
24030
  try {
23722
- const pid = Number.parseInt((await (0, import_promises9.readFile)(path, "utf8")).trim(), 10);
24031
+ const pid = Number.parseInt((await (0, import_promises10.readFile)(path, "utf8")).trim(), 10);
23723
24032
  return Number.isInteger(pid) && pid > 0 && alive(pid) ? pid : null;
23724
24033
  } catch {
23725
24034
  return null;
@@ -23728,12 +24037,12 @@ async function readLockPid(path) {
23728
24037
  async function acquireLock(path) {
23729
24038
  for (let attempt = 0; attempt < 2; attempt += 1) {
23730
24039
  try {
23731
- const handle = await (0, import_promises9.open)(path, "wx", 384);
24040
+ const handle = await (0, import_promises10.open)(path, "wx", 384);
23732
24041
  await handle.writeFile(`${process.pid}
23733
24042
  `);
23734
24043
  await handle.close();
23735
24044
  return async () => {
23736
- await (0, import_promises9.unlink)(path).catch(() => void 0);
24045
+ await (0, import_promises10.unlink)(path).catch(() => void 0);
23737
24046
  };
23738
24047
  } catch (error63) {
23739
24048
  if (errorCode2(error63) !== "EEXIST")
@@ -23741,7 +24050,7 @@ async function acquireLock(path) {
23741
24050
  const pid = await readLockPid(path);
23742
24051
  if (pid !== null)
23743
24052
  throw new Error(`Another agent is already running (pid ${pid})`);
23744
- await (0, import_promises9.unlink)(path).catch(() => void 0);
24053
+ await (0, import_promises10.unlink)(path).catch(() => void 0);
23745
24054
  }
23746
24055
  }
23747
24056
  throw new Error("Could not acquire the agent lock");
@@ -23794,16 +24103,16 @@ function excerpt(value) {
23794
24103
  }
23795
24104
 
23796
24105
  // dist/runner.js
23797
- var import_node_os8 = require("node:os");
24106
+ var import_node_os9 = require("node:os");
23798
24107
 
23799
24108
  // dist/dispatcher.js
23800
24109
  var import_node_crypto8 = require("node:crypto");
23801
24110
 
23802
24111
  // dist/fileops.js
23803
24112
  var import_node_fs2 = require("node:fs");
23804
- var import_promises10 = require("node:fs/promises");
24113
+ var import_promises11 = require("node:fs/promises");
23805
24114
  var import_node_crypto7 = require("node:crypto");
23806
- var import_node_path12 = require("node:path");
24115
+ var import_node_path13 = require("node:path");
23807
24116
 
23808
24117
  // dist/glob.js
23809
24118
  function globToRegExp(glob) {
@@ -23980,7 +24289,7 @@ var RootedFs = class {
23980
24289
  return;
23981
24290
  const forms = /* @__PURE__ */ new Set();
23982
24291
  for (const path of this.#protectedInput) {
23983
- forms.add((0, import_node_path12.resolve)(path));
24292
+ forms.add((0, import_node_path13.resolve)(path));
23984
24293
  forms.add(await realpathLenient(path));
23985
24294
  }
23986
24295
  this.#protected = [...forms];
@@ -23990,7 +24299,7 @@ var RootedFs = class {
23990
24299
  #blockedReal(real) {
23991
24300
  if (this.#protected.some((dir) => isSameOrInside(dir, real)))
23992
24301
  return true;
23993
- return this.#hardDeny.denies(real.split(import_node_path12.sep).filter((segment) => segment !== "").join("/"));
24302
+ return this.#hardDeny.denies(real.split(import_node_path13.sep).filter((segment) => segment !== "").join("/"));
23994
24303
  }
23995
24304
  #checkReal(real) {
23996
24305
  if (this.#blockedReal(real))
@@ -23999,8 +24308,8 @@ var RootedFs = class {
23999
24308
  async #rootReal() {
24000
24309
  await this.#loadProtected();
24001
24310
  try {
24002
- const real = await (0, import_promises10.realpath)(this.#root.path);
24003
- if (!(await (0, import_promises10.stat)(real)).isDirectory())
24311
+ const real = await (0, import_promises11.realpath)(this.#root.path);
24312
+ if (!(await (0, import_promises11.stat)(real)).isDirectory())
24004
24313
  throw new FileOpError("NOT_FOUND", "Root is unavailable");
24005
24314
  return real;
24006
24315
  } catch (error63) {
@@ -24010,11 +24319,11 @@ var RootedFs = class {
24010
24319
  }
24011
24320
  }
24012
24321
  #inside(rootReal, real) {
24013
- const prefix = rootReal.endsWith(import_node_path12.sep) ? rootReal : rootReal + import_node_path12.sep;
24322
+ const prefix = rootReal.endsWith(import_node_path13.sep) ? rootReal : rootReal + import_node_path13.sep;
24014
24323
  return real === rootReal || real.startsWith(prefix);
24015
24324
  }
24016
24325
  #relativeOf(rootReal, real) {
24017
- return (0, import_node_path12.relative)(rootReal, real).split(import_node_path12.sep).join("/");
24326
+ return (0, import_node_path13.relative)(rootReal, real).split(import_node_path13.sep).join("/");
24018
24327
  }
24019
24328
  #checkDeny(rel) {
24020
24329
  if (this.#deny.denies(rel))
@@ -24027,7 +24336,7 @@ var RootedFs = class {
24027
24336
  const rootReal = await this.#rootReal();
24028
24337
  let real;
24029
24338
  try {
24030
- real = await (0, import_promises10.realpath)((0, import_node_path12.join)(rootReal, rel));
24339
+ real = await (0, import_promises11.realpath)((0, import_node_path13.join)(rootReal, rel));
24031
24340
  } catch (error63) {
24032
24341
  throw mapFsError(error63, rel);
24033
24342
  }
@@ -24046,10 +24355,10 @@ var RootedFs = class {
24046
24355
  async #openVerified(rootReal, real) {
24047
24356
  let handle;
24048
24357
  try {
24049
- const before = await (0, import_promises10.lstat)(real);
24358
+ const before = await (0, import_promises11.lstat)(real);
24050
24359
  if (!before.isFile())
24051
24360
  throw new FileOpError("NOT_A_FILE", "Path is not a regular file");
24052
- handle = await (0, import_promises10.open)(real, OPEN_READ_FLAGS);
24361
+ handle = await (0, import_promises11.open)(real, OPEN_READ_FLAGS);
24053
24362
  } catch (error63) {
24054
24363
  throw mapFsError(error63, "");
24055
24364
  }
@@ -24057,8 +24366,8 @@ var RootedFs = class {
24057
24366
  const info = await handle.stat();
24058
24367
  if (!info.isFile())
24059
24368
  throw new FileOpError("NOT_A_FILE", "Path is not a regular file");
24060
- const again = await (0, import_promises10.realpath)(real);
24061
- const pathInfo = await (0, import_promises10.stat)(again);
24369
+ const again = await (0, import_promises11.realpath)(real);
24370
+ const pathInfo = await (0, import_promises11.stat)(again);
24062
24371
  if (again !== real || !this.#inside(rootReal, again) || pathInfo.ino !== info.ino || pathInfo.dev !== info.dev) {
24063
24372
  throw new FileOpError("PATH_ESCAPE", "Path changed while it was being opened");
24064
24373
  }
@@ -24110,18 +24419,18 @@ var RootedFs = class {
24110
24419
  async list(input2) {
24111
24420
  const { rel, real } = await this.resolveExisting(input2);
24112
24421
  try {
24113
- if (!(await (0, import_promises10.stat)(real)).isDirectory())
24422
+ if (!(await (0, import_promises11.stat)(real)).isDirectory())
24114
24423
  throw new FileOpError("NOT_A_DIRECTORY", "Path is not a directory", { path: rel });
24115
- const dir = await (0, import_promises10.opendir)(real);
24424
+ const dir = await (0, import_promises11.opendir)(real);
24116
24425
  const names = [];
24117
24426
  for await (const entry of dir) {
24118
24427
  const childRel = rel === "" ? entry.name : `${rel}/${entry.name}`;
24119
24428
  if (this.#deny.denies(childRel))
24120
24429
  continue;
24121
- const childReal = (0, import_node_path12.join)(real, entry.name);
24430
+ const childReal = (0, import_node_path13.join)(real, entry.name);
24122
24431
  if (this.#blockedReal(childReal))
24123
24432
  continue;
24124
- if (entry.isSymbolicLink() && this.#blockedReal(await (0, import_promises10.realpath)(childReal).catch(() => childReal)))
24433
+ if (entry.isSymbolicLink() && this.#blockedReal(await (0, import_promises11.realpath)(childReal).catch(() => childReal)))
24125
24434
  continue;
24126
24435
  const type = entry.isFile() ? "file" : entry.isDirectory() ? "directory" : entry.isSymbolicLink() ? "symlink" : "other";
24127
24436
  names.push({ name: entry.name, type });
@@ -24130,7 +24439,7 @@ var RootedFs = class {
24130
24439
  const entries = [];
24131
24440
  for (const item of names.slice(0, MAX_LIST_ENTRIES)) {
24132
24441
  if (item.type === "file") {
24133
- const size = await (0, import_promises10.lstat)((0, import_node_path12.join)(real, item.name)).then((s) => s.size, () => void 0);
24442
+ const size = await (0, import_promises11.lstat)((0, import_node_path13.join)(real, item.name)).then((s) => s.size, () => void 0);
24134
24443
  entries.push(size === void 0 ? item : { ...item, size });
24135
24444
  } else
24136
24445
  entries.push(item);
@@ -24153,7 +24462,7 @@ var RootedFs = class {
24153
24462
  return;
24154
24463
  let resolved;
24155
24464
  try {
24156
- resolved = await (0, import_promises10.realpath)(fileReal);
24465
+ resolved = await (0, import_promises11.realpath)(fileReal);
24157
24466
  } catch {
24158
24467
  return;
24159
24468
  }
@@ -24161,9 +24470,9 @@ var RootedFs = class {
24161
24470
  return;
24162
24471
  let handle;
24163
24472
  try {
24164
- if (!(await (0, import_promises10.lstat)(resolved)).isFile())
24473
+ if (!(await (0, import_promises11.lstat)(resolved)).isFile())
24165
24474
  return;
24166
- handle = await (0, import_promises10.open)(resolved, OPEN_READ_FLAGS);
24475
+ handle = await (0, import_promises11.open)(resolved, OPEN_READ_FLAGS);
24167
24476
  } catch {
24168
24477
  return;
24169
24478
  }
@@ -24205,7 +24514,7 @@ var RootedFs = class {
24205
24514
  await handle.close().catch(() => void 0);
24206
24515
  }
24207
24516
  };
24208
- const start = await (0, import_promises10.stat)(real).catch((error63) => {
24517
+ const start = await (0, import_promises11.stat)(real).catch((error63) => {
24209
24518
  throw mapFsError(error63, rel);
24210
24519
  });
24211
24520
  if (start.isFile()) {
@@ -24216,7 +24525,7 @@ var RootedFs = class {
24216
24525
  const current = queue.shift();
24217
24526
  let entries;
24218
24527
  try {
24219
- const dir = await (0, import_promises10.opendir)(current.real);
24528
+ const dir = await (0, import_promises11.opendir)(current.real);
24220
24529
  entries = [];
24221
24530
  for await (const entry of dir) {
24222
24531
  entries.push({ name: entry.name, file: entry.isFile(), dir: entry.isDirectory() });
@@ -24231,7 +24540,7 @@ var RootedFs = class {
24231
24540
  const childRel = current.rel === "" ? entry.name : `${current.rel}/${entry.name}`;
24232
24541
  if (this.#deny.denies(childRel))
24233
24542
  continue;
24234
- const childReal = (0, import_node_path12.join)(current.real, entry.name);
24543
+ const childReal = (0, import_node_path13.join)(current.real, entry.name);
24235
24544
  if (this.#blockedReal(childReal))
24236
24545
  continue;
24237
24546
  if (entry.dir)
@@ -24253,7 +24562,7 @@ var RootedFs = class {
24253
24562
  async #currentHash(rootReal, target) {
24254
24563
  let info;
24255
24564
  try {
24256
- info = await (0, import_promises10.lstat)(target);
24565
+ info = await (0, import_promises11.lstat)(target);
24257
24566
  } catch (error63) {
24258
24567
  if (errorCode2(error63) === "ENOENT")
24259
24568
  return { sha256: null, mode: null };
@@ -24285,8 +24594,8 @@ var RootedFs = class {
24285
24594
  const name3 = slash < 0 ? rel : rel.slice(slash + 1);
24286
24595
  let parentReal;
24287
24596
  try {
24288
- parentReal = await (0, import_promises10.realpath)((0, import_node_path12.join)(rootReal, parentRel));
24289
- if (!(await (0, import_promises10.stat)(parentReal)).isDirectory())
24597
+ parentReal = await (0, import_promises11.realpath)((0, import_node_path13.join)(rootReal, parentRel));
24598
+ if (!(await (0, import_promises11.stat)(parentReal)).isDirectory())
24290
24599
  throw new FileOpError("NOT_A_DIRECTORY", "Parent is not a directory");
24291
24600
  } catch (error63) {
24292
24601
  if (errorCode2(error63) === "ENOENT")
@@ -24297,16 +24606,16 @@ var RootedFs = class {
24297
24606
  throw new FileOpError("PATH_ESCAPE", "Path resolves outside the root");
24298
24607
  const parentRealRel = this.#relativeOf(rootReal, parentReal);
24299
24608
  this.#checkDeny(parentRealRel === "" ? name3 : `${parentRealRel}/${name3}`);
24300
- const target = (0, import_node_path12.join)(parentReal, name3);
24609
+ const target = (0, import_node_path13.join)(parentReal, name3);
24301
24610
  this.#checkReal(target);
24302
24611
  return { rel, rootReal, parentReal, name: name3, target };
24303
24612
  }
24304
24613
  /** Temp file in the same directory, fsync, re-check the version, rename over the target. */
24305
24614
  async #replaceAtomic(rel, rootReal, parentReal, name3, target, before, bytes3) {
24306
- const temp = (0, import_node_path12.join)(parentReal, `.${name3}.conbridge-${randomToken(8)}.tmp`);
24615
+ const temp = (0, import_node_path13.join)(parentReal, `.${name3}.conbridge-${randomToken(8)}.tmp`);
24307
24616
  let handle;
24308
24617
  try {
24309
- handle = await (0, import_promises10.open)(temp, import_node_fs2.constants.O_WRONLY | import_node_fs2.constants.O_CREAT | import_node_fs2.constants.O_EXCL | import_node_fs2.constants.O_NOFOLLOW, before.mode ?? 438);
24618
+ handle = await (0, import_promises11.open)(temp, import_node_fs2.constants.O_WRONLY | import_node_fs2.constants.O_CREAT | import_node_fs2.constants.O_EXCL | import_node_fs2.constants.O_NOFOLLOW, before.mode ?? 438);
24310
24619
  } catch (error63) {
24311
24620
  throw mapFsError(error63, rel);
24312
24621
  }
@@ -24320,20 +24629,20 @@ var RootedFs = class {
24320
24629
  } finally {
24321
24630
  await handle.close();
24322
24631
  }
24323
- if (await (0, import_promises10.realpath)(parentReal) !== parentReal)
24632
+ if (await (0, import_promises11.realpath)(parentReal) !== parentReal)
24324
24633
  throw new FileOpError("PATH_ESCAPE", "Directory changed during write");
24325
24634
  const again = await this.#currentHash(rootReal, target);
24326
24635
  if (again.sha256 !== before.sha256) {
24327
24636
  throw new FileOpError("WORKSPACE_VERSION_CONFLICT", "File changed during write", { path: rel, current_sha256: again.sha256 });
24328
24637
  }
24329
- await (0, import_promises10.rename)(temp, target);
24638
+ await (0, import_promises11.rename)(temp, target);
24330
24639
  renamed = true;
24331
24640
  await fsyncDirectory(parentReal);
24332
24641
  } catch (error63) {
24333
24642
  throw mapFsError(error63, rel);
24334
24643
  } finally {
24335
24644
  if (!renamed)
24336
- await (0, import_promises10.unlink)(temp).catch(() => void 0);
24645
+ await (0, import_promises11.unlink)(temp).catch(() => void 0);
24337
24646
  }
24338
24647
  }
24339
24648
  #requireWritable() {
@@ -24361,7 +24670,7 @@ var RootedFs = class {
24361
24670
  const { rel, real, rootReal } = await this.resolveExisting(input2);
24362
24671
  let info;
24363
24672
  try {
24364
- info = await (0, import_promises10.lstat)(real);
24673
+ info = await (0, import_promises11.lstat)(real);
24365
24674
  } catch (error63) {
24366
24675
  throw mapFsError(error63, rel);
24367
24676
  }
@@ -24383,7 +24692,7 @@ var RootedFs = class {
24383
24692
  }
24384
24693
  }
24385
24694
  if (type === "directory") {
24386
- const entries = await (0, import_promises10.readdir)(real).then((names) => names.length, () => void 0);
24695
+ const entries = await (0, import_promises11.readdir)(real).then((names) => names.length, () => void 0);
24387
24696
  return entries === void 0 ? base2 : { ...base2, entries };
24388
24697
  }
24389
24698
  return base2;
@@ -24433,14 +24742,14 @@ var RootedFs = class {
24433
24742
  let created = false;
24434
24743
  for (let index = 1; index <= segments.length; index += 1) {
24435
24744
  const { rootReal, target } = await this.#resolveNew(segments.slice(0, index).join("/"));
24436
- const existing = await (0, import_promises10.lstat)(target).catch(() => null);
24745
+ const existing = await (0, import_promises11.lstat)(target).catch(() => null);
24437
24746
  if (existing) {
24438
24747
  const segment = segments.slice(0, index).join("/");
24439
24748
  if (existing.isSymbolicLink()) {
24440
- const real = await (0, import_promises10.realpath)(target).catch(() => null);
24749
+ const real = await (0, import_promises11.realpath)(target).catch(() => null);
24441
24750
  if (real === null || !this.#inside(rootReal, real))
24442
24751
  throw new FileOpError("PATH_ESCAPE", "Path resolves outside the root", { path: segment });
24443
- if (!(await (0, import_promises10.stat)(real)).isDirectory())
24752
+ if (!(await (0, import_promises11.stat)(real)).isDirectory())
24444
24753
  throw new FileOpError("ALREADY_EXISTS", "A file with that name exists", { path: segment });
24445
24754
  continue;
24446
24755
  }
@@ -24449,12 +24758,12 @@ var RootedFs = class {
24449
24758
  continue;
24450
24759
  }
24451
24760
  try {
24452
- await (0, import_promises10.mkdir)(target, { mode: 511 });
24761
+ await (0, import_promises11.mkdir)(target, { mode: 511 });
24453
24762
  } catch (error63) {
24454
24763
  if (errorCode2(error63) !== "EEXIST")
24455
24764
  throw mapFsError(error63, rel);
24456
24765
  }
24457
- if (!this.#inside(rootReal, await (0, import_promises10.realpath)(target)))
24766
+ if (!this.#inside(rootReal, await (0, import_promises11.realpath)(target)))
24458
24767
  throw new FileOpError("PATH_ESCAPE", "Path resolves outside the root");
24459
24768
  created = true;
24460
24769
  }
@@ -24464,20 +24773,20 @@ var RootedFs = class {
24464
24773
  async move(input2, to) {
24465
24774
  this.#requireWritable();
24466
24775
  const from = await this.#resolveNew(input2);
24467
- const source = await (0, import_promises10.lstat)(from.target).catch(() => null);
24776
+ const source = await (0, import_promises11.lstat)(from.target).catch(() => null);
24468
24777
  if (!source)
24469
24778
  throw new FileOpError("NOT_FOUND", "Path does not exist", { path: from.rel });
24470
- const sourceReal = await (0, import_promises10.realpath)(from.target).catch(() => from.target);
24779
+ const sourceReal = await (0, import_promises11.realpath)(from.target).catch(() => from.target);
24471
24780
  if (this.#protected.some((path) => isSameOrInside(from.target, path) || isSameOrInside(sourceReal, path))) {
24472
24781
  throw new FileOpError("PATH_DENIED", "Path contains files the agent protects", { path: from.rel });
24473
24782
  }
24474
24783
  const dest = await this.#resolveNew(to);
24475
24784
  if (isSameOrInside(from.target, dest.target))
24476
24785
  throw new FileOpError("PATH_INVALID", "Cannot move a folder into itself");
24477
- if (await (0, import_promises10.lstat)(dest.target).then(() => true, () => false))
24786
+ if (await (0, import_promises11.lstat)(dest.target).then(() => true, () => false))
24478
24787
  throw new FileOpError("ALREADY_EXISTS", "The destination already exists", { path: dest.rel });
24479
24788
  try {
24480
- await (0, import_promises10.rename)(from.target, dest.target);
24789
+ await (0, import_promises11.rename)(from.target, dest.target);
24481
24790
  } catch (error63) {
24482
24791
  throw mapFsError(error63, from.rel);
24483
24792
  }
@@ -24488,14 +24797,14 @@ var RootedFs = class {
24488
24797
  async delete(input2, expectedSha256) {
24489
24798
  this.#requireWritable();
24490
24799
  const { rel, rootReal, target, parentReal } = await this.#resolveNew(input2);
24491
- const info = await (0, import_promises10.lstat)(target).catch(() => null);
24800
+ const info = await (0, import_promises11.lstat)(target).catch(() => null);
24492
24801
  if (!info)
24493
24802
  throw new FileOpError("NOT_FOUND", "Path does not exist", { path: rel });
24494
24803
  if (info.isDirectory()) {
24495
24804
  if (expectedSha256 !== null)
24496
24805
  throw new FileOpError("NOT_A_FILE", "Path is a directory; pass expected_sha256 null", { path: rel });
24497
24806
  try {
24498
- await (0, import_promises10.rmdir)(target);
24807
+ await (0, import_promises11.rmdir)(target);
24499
24808
  } catch (error63) {
24500
24809
  if (errorCode2(error63) === "ENOTEMPTY" || errorCode2(error63) === "EEXIST")
24501
24810
  throw new FileOpError("NOT_EMPTY", "Directory is not empty", { path: rel });
@@ -24509,7 +24818,7 @@ var RootedFs = class {
24509
24818
  throw new FileOpError("WORKSPACE_VERSION_CONFLICT", "File changed since it was read", { path: rel, current_sha256: current.sha256 });
24510
24819
  }
24511
24820
  try {
24512
- await (0, import_promises10.unlink)(target);
24821
+ await (0, import_promises11.unlink)(target);
24513
24822
  } catch (error63) {
24514
24823
  throw mapFsError(error63, rel);
24515
24824
  }
@@ -25093,16 +25402,16 @@ var Dispatcher = class {
25093
25402
  };
25094
25403
 
25095
25404
  // dist/monitor.js
25096
- var import_promises11 = require("node:fs/promises");
25097
- var import_node_os4 = require("node:os");
25405
+ var import_promises12 = require("node:fs/promises");
25406
+ var import_node_os5 = require("node:os");
25098
25407
  var defaultMonitorSystem = {
25099
25408
  platform: process.platform,
25100
- cpus: import_node_os4.cpus,
25101
- loadavg: import_node_os4.loadavg,
25102
- totalmem: import_node_os4.totalmem,
25103
- freemem: import_node_os4.freemem,
25104
- uptime: import_node_os4.uptime,
25105
- statfs: (path) => (0, import_promises11.statfs)(path),
25409
+ cpus: import_node_os5.cpus,
25410
+ loadavg: import_node_os5.loadavg,
25411
+ totalmem: import_node_os5.totalmem,
25412
+ freemem: import_node_os5.freemem,
25413
+ uptime: import_node_os5.uptime,
25414
+ statfs: (path) => (0, import_promises12.statfs)(path),
25106
25415
  env: process.env
25107
25416
  };
25108
25417
  var MONITOR_FIRST_SAMPLE_MS = 1e3;
@@ -25235,13 +25544,13 @@ var import_node_crypto10 = require("node:crypto");
25235
25544
  var import_node_zlib = require("node:zlib");
25236
25545
 
25237
25546
  // dist/ssh/exec.js
25238
- var import_node_child_process7 = require("node:child_process");
25239
- var import_node_path14 = require("node:path");
25547
+ var import_node_child_process8 = require("node:child_process");
25548
+ var import_node_path15 = require("node:path");
25240
25549
 
25241
25550
  // dist/ssh/hosts.js
25242
25551
  var import_node_crypto9 = require("node:crypto");
25243
- var import_promises12 = require("node:fs/promises");
25244
- var import_node_path13 = require("node:path");
25552
+ var import_promises13 = require("node:fs/promises");
25553
+ var import_node_path14 = require("node:path");
25245
25554
  var MAX_SSH_HOSTS = 64;
25246
25555
  var SSH_ALIAS = /^[a-z0-9][a-z0-9_-]{0,62}$/;
25247
25556
  var DNS_HOST = /^(?=.{1,253}$)[A-Za-z0-9](?:[A-Za-z0-9-]{0,61}[A-Za-z0-9])?(?:\.[A-Za-z0-9](?:[A-Za-z0-9-]{0,61}[A-Za-z0-9])?)*$/;
@@ -25251,7 +25560,7 @@ function isValidSshHost(value) {
25251
25560
  return DNS_HOST.test(value) || IPV6_HOST.test(value);
25252
25561
  }
25253
25562
  function isValidIdentityPath(value) {
25254
- return (0, import_node_path13.isAbsolute)(value) && value.length <= 1024 && !/[\u0000-\u001f\u007f%"]/.test(value);
25563
+ return (0, import_node_path14.isAbsolute)(value) && value.length <= 1024 && !/[\u0000-\u001f\u007f%"]/.test(value);
25255
25564
  }
25256
25565
  var PINNABLE_KEY_TYPES = Object.freeze([
25257
25566
  "ssh-ed25519",
@@ -25276,11 +25585,11 @@ var sshHostSchema = external_exports.strictObject({
25276
25585
  });
25277
25586
  var hostsFileSchema = external_exports.strictObject({ version: external_exports.literal(1), hosts: external_exports.array(sshHostSchema).max(MAX_SSH_HOSTS) });
25278
25587
  function sshPaths(stateDir) {
25279
- const dir = (0, import_node_path13.join)(stateDir, "ssh");
25280
- return { dir, hosts: (0, import_node_path13.join)(dir, "hosts.json"), knownHostsDir: (0, import_node_path13.join)(dir, "known_hosts") };
25588
+ const dir = (0, import_node_path14.join)(stateDir, "ssh");
25589
+ return { dir, hosts: (0, import_node_path14.join)(dir, "hosts.json"), knownHostsDir: (0, import_node_path14.join)(dir, "known_hosts") };
25281
25590
  }
25282
25591
  function knownHostsPath(paths, resourceId) {
25283
- return (0, import_node_path13.join)(paths.knownHostsDir, external_exports.uuid().parse(resourceId));
25592
+ return (0, import_node_path14.join)(paths.knownHostsDir, external_exports.uuid().parse(resourceId));
25284
25593
  }
25285
25594
  function hostKeyAlias(host) {
25286
25595
  return "conbridge-" + host.resource_id;
@@ -25316,7 +25625,7 @@ function preferredKey(keys) {
25316
25625
  async function loadSshHosts(paths) {
25317
25626
  let text6;
25318
25627
  try {
25319
- text6 = await (0, import_promises12.readFile)(paths.hosts, "utf8");
25628
+ text6 = await (0, import_promises13.readFile)(paths.hosts, "utf8");
25320
25629
  } catch (error63) {
25321
25630
  if (errorCode2(error63) === "ENOENT")
25322
25631
  return [];
@@ -25326,8 +25635,8 @@ async function loadSshHosts(paths) {
25326
25635
  }
25327
25636
  async function ensureSshDirs(paths) {
25328
25637
  for (const dir of [paths.dir, paths.knownHostsDir]) {
25329
- await (0, import_promises12.mkdir)(dir, { recursive: true, mode: 448 });
25330
- await (0, import_promises12.chmod)(dir, 448);
25638
+ await (0, import_promises13.mkdir)(dir, { recursive: true, mode: 448 });
25639
+ await (0, import_promises13.chmod)(dir, 448);
25331
25640
  }
25332
25641
  }
25333
25642
  async function saveSshHosts(paths, hosts) {
@@ -25351,7 +25660,7 @@ async function validateNewHost(input2) {
25351
25660
  if (input2.identity !== void 0) {
25352
25661
  if (!isValidIdentityPath(input2.identity))
25353
25662
  throw new Error("Identity must be an absolute path without quotes, % or control characters");
25354
- const info = await (0, import_promises12.stat)(input2.identity).catch(() => null);
25663
+ const info = await (0, import_promises13.stat)(input2.identity).catch(() => null);
25355
25664
  if (!info?.isFile())
25356
25665
  throw new Error("Identity file not found");
25357
25666
  }
@@ -25408,7 +25717,7 @@ async function removeSshHost(paths, alias) {
25408
25717
  if (!host)
25409
25718
  return false;
25410
25719
  await saveSshHosts(paths, hosts.filter((entry) => entry !== host));
25411
- await (0, import_promises12.unlink)(knownHostsPath(paths, host.resource_id)).catch(() => void 0);
25720
+ await (0, import_promises13.unlink)(knownHostsPath(paths, host.resource_id)).catch(() => void 0);
25412
25721
  return true;
25413
25722
  }
25414
25723
  function hostAddress(host) {
@@ -25423,7 +25732,7 @@ function inventoryResource2(host) {
25423
25732
  // dist/ssh/exec.js
25424
25733
  var DEFAULT_SSH_BINARIES = Object.freeze({ ssh: "/usr/bin/ssh", keyscan: "/usr/bin/ssh-keyscan" });
25425
25734
  function sshBinariesFromEnv(env = process.env) {
25426
- const pick2 = (value, fallback) => value && (0, import_node_path14.isAbsolute)(value) ? value : fallback;
25735
+ const pick2 = (value, fallback) => value && (0, import_node_path15.isAbsolute)(value) ? value : fallback;
25427
25736
  return { ssh: pick2(env.CONBRIDGE_SSH_BIN, DEFAULT_SSH_BINARIES.ssh), keyscan: pick2(env.CONBRIDGE_SSH_KEYSCAN_BIN, DEFAULT_SSH_BINARIES.keyscan) };
25428
25737
  }
25429
25738
  function sshChildEnv(env = process.env) {
@@ -25436,14 +25745,14 @@ function sshChildEnv(env = process.env) {
25436
25745
  }
25437
25746
  function runProcess(file2, args, options) {
25438
25747
  const started = Date.now();
25439
- return new Promise((resolve9) => {
25748
+ return new Promise((resolve10) => {
25440
25749
  const kept = { stdout: [], stderr: [] };
25441
25750
  const totals = { stdout: 0, stderr: 0 };
25442
25751
  let keptBytes = 0;
25443
25752
  let truncated = false;
25444
25753
  let timedOut = false;
25445
25754
  let settled = false;
25446
- const child = (0, import_node_child_process7.spawn)(file2, [...args], { stdio: ["ignore", "pipe", "pipe"], env: options.env, shell: false });
25755
+ const child = (0, import_node_child_process8.spawn)(file2, [...args], { stdio: ["ignore", "pipe", "pipe"], env: options.env, shell: false });
25447
25756
  const collect = (stream) => (chunk2) => {
25448
25757
  totals[stream] += chunk2.length;
25449
25758
  const room = options.maxBytes - keptBytes;
@@ -25472,7 +25781,7 @@ function runProcess(file2, args, options) {
25472
25781
  clearTimeout(timer);
25473
25782
  if (killTimer)
25474
25783
  clearTimeout(killTimer);
25475
- resolve9({
25784
+ resolve10({
25476
25785
  exitCode,
25477
25786
  timedOut,
25478
25787
  truncated,
@@ -25840,198 +26149,805 @@ function parseWindowsPrograms(json2) {
25840
26149
  return result2;
25841
26150
  }
25842
26151
 
25843
- // dist/inventory/parsers/sections.js
25844
- var SECTION_MARKER = "@@conbridge-section";
25845
- var MARKER_PATTERN = /^@@conbridge-section ([a-z0-9-]{1,32})$/;
25846
- function splitSections(output2) {
25847
- const sections = /* @__PURE__ */ new Map();
25848
- if (typeof output2 !== "string")
25849
- return { sections, complete: false };
25850
- const lines4 = output2.split("\n").map((line) => line.endsWith("\r") ? line.slice(0, -1) : line);
25851
- let current;
25852
- let buffer = [];
25853
- let complete = false;
25854
- const flush = () => {
25855
- if (current === void 0)
25856
- return;
25857
- let end = buffer.length;
25858
- while (end > 0 && buffer[end - 1] === "")
25859
- end -= 1;
25860
- const content = buffer.slice(0, end).join("\n");
25861
- if (!sections.has(current))
25862
- sections.set(current, content);
25863
- current = void 0;
25864
- buffer = [];
25865
- };
25866
- for (const line of lines4) {
25867
- const match = MARKER_PATTERN.exec(line);
25868
- if (!match) {
25869
- if (current !== void 0)
25870
- buffer.push(line);
25871
- continue;
25872
- }
25873
- flush();
25874
- const name3 = match[1] ?? "";
25875
- if (name3 === "end") {
25876
- complete = true;
25877
- break;
25878
- }
25879
- current = name3;
25880
- }
25881
- if (!complete)
25882
- flush();
25883
- return { sections, complete };
26152
+ // dist/inventory/parsers/apt-config.js
26153
+ var UPDATE_LISTS_KEY = "APT::Periodic::Update-Package-Lists";
26154
+ var UNATTENDED_KEY = "APT::Periodic::Unattended-Upgrade";
26155
+ function truthy(raw) {
26156
+ if (raw === null)
26157
+ return false;
26158
+ let value = raw.trim();
26159
+ if (value.endsWith(";"))
26160
+ value = value.slice(0, -1).trim();
26161
+ if (value.length >= 2 && value.startsWith('"') && value.endsWith('"'))
26162
+ value = value.slice(1, -1);
26163
+ if (value === "")
26164
+ return false;
26165
+ if (value.toLowerCase() === "always")
26166
+ return true;
26167
+ const number4 = Number(value);
26168
+ return Number.isFinite(number4) && number4 > 0;
25884
26169
  }
25885
-
25886
- // dist/inventory/parsers/system.js
25887
- var RELEASE_KEYS = {
25888
- ID: "id",
25889
- VERSION_ID: "versionId",
25890
- VERSION_CODENAME: "codename",
25891
- PRETTY_NAME: "prettyName",
25892
- NAME: "name",
25893
- VERSION: "version"
25894
- };
25895
- function unquote(raw) {
25896
- const value = raw.trim();
25897
- if (value.length >= 2 && value.startsWith('"')) {
25898
- const end = value.lastIndexOf('"');
25899
- if (end > 0)
25900
- return value.slice(1, end).replace(/\\"/g, '"').trim();
25901
- }
25902
- if (value.length >= 2 && value.startsWith("'")) {
25903
- const end = value.lastIndexOf("'");
25904
- if (end > 0)
25905
- return value.slice(1, end).trim();
26170
+ function parseAptConfig(stdout) {
26171
+ let updateListsValue = null;
26172
+ let unattendedValue = null;
26173
+ if (typeof stdout === "string") {
26174
+ for (const raw of stdout.split(/\r?\n/)) {
26175
+ const line = raw.trim();
26176
+ if (line === "")
26177
+ continue;
26178
+ const space = line.search(/\s/);
26179
+ const key = space < 0 ? line : line.slice(0, space);
26180
+ const value = space < 0 ? "" : line.slice(space + 1).trim();
26181
+ if (key === UPDATE_LISTS_KEY)
26182
+ updateListsValue = value;
26183
+ else if (key === UNATTENDED_KEY)
26184
+ unattendedValue = value;
26185
+ }
25906
26186
  }
25907
- return value;
26187
+ return { update_lists: truthy(updateListsValue), unattended: truthy(unattendedValue) };
25908
26188
  }
25909
- function parseOsRelease(text6) {
25910
- const result2 = {};
25911
- if (typeof text6 !== "string")
25912
- return result2;
25913
- for (const rawLine of text6.split(/\r?\n/)) {
25914
- const line = rawLine.trim();
25915
- if (!line || line.startsWith("#"))
25916
- continue;
25917
- const separator = line.indexOf("=");
25918
- if (separator <= 0)
25919
- continue;
25920
- const key = line.slice(0, separator).trim();
25921
- const field = RELEASE_KEYS[key];
25922
- if (!field)
25923
- continue;
25924
- const value = unquote(line.slice(separator + 1));
25925
- if (!value)
26189
+ function parseAptHold(stdout) {
26190
+ if (typeof stdout !== "string")
26191
+ return [];
26192
+ const held = [];
26193
+ for (const raw of stdout.split(/\r?\n/)) {
26194
+ const name3 = raw.trim();
26195
+ if (!/^[a-z0-9][a-z0-9+.:~-]*$/.test(name3) || name3.length > 200)
25926
26196
  continue;
25927
- result2[field] = value;
26197
+ held.push(name3);
25928
26198
  }
25929
- return result2;
26199
+ return held;
25930
26200
  }
25931
- function parseSwVers(text6) {
25932
- const result2 = {};
25933
- if (typeof text6 !== "string")
25934
- return result2;
25935
- for (const rawLine of text6.split(/\r?\n/)) {
25936
- const line = rawLine.trim();
25937
- if (!line)
25938
- continue;
25939
- const separator = line.indexOf(":");
25940
- if (separator <= 0)
25941
- continue;
25942
- const key = line.slice(0, separator).trim();
25943
- const value = line.slice(separator + 1).trim();
25944
- if (!value)
25945
- continue;
25946
- if (key === "ProductName")
25947
- result2.productName = value;
25948
- else if (key === "ProductVersion")
25949
- result2.productVersion = value;
25950
- else if (key === "BuildVersion")
25951
- result2.buildVersion = value;
25952
- }
25953
- return result2;
25954
- }
25955
- function asRecord2(value) {
25956
- return typeof value === "object" && value !== null && !Array.isArray(value) ? value : void 0;
25957
- }
25958
- function stringField(value) {
25959
- return typeof value === "string" ? value.trim() : "";
26201
+
26202
+ // dist/inventory/parsers/apt-policy.js
26203
+ var MAX_PACKAGES2 = INVENTORY_LIMITS.packages;
26204
+ var NOT_INSTALLED = "(none)";
26205
+ var LOCAL_STATUS = "/var/lib/dpkg/status";
26206
+ var DISTRO_DOMAINS = ["ubuntu.com", "debian.org", "raspbian.org", "raspberrypi.com", "raspberrypi.org"];
26207
+ var ESM_HOST = "esm.ubuntu.com";
26208
+ var THIRD_PARTY_HOSTS = /* @__PURE__ */ new Set([
26209
+ "ppa.launchpadcontent.net",
26210
+ "ppa.launchpad.net",
26211
+ "deb.nodesource.com",
26212
+ "deb.sury.org",
26213
+ "packages.sury.org",
26214
+ "download.docker.com",
26215
+ "nginx.org",
26216
+ "packages.microsoft.com",
26217
+ "apt.postgresql.org",
26218
+ "repo.mysql.com"
26219
+ ]);
26220
+ var MIRROR_PATH_SEGMENTS = /* @__PURE__ */ new Set(["ubuntu", "ubuntu-ports", "debian", "debian-security", "raspbian"]);
26221
+ var DISTRO_COMPONENTS = /* @__PURE__ */ new Set(["main", "restricted", "universe", "multiverse", "contrib", "non-free", "non-free-firmware"]);
26222
+ var ORIGIN_ORDER = ["esm", "distro", "third_party", "local"];
26223
+ function isHostOrSubdomain(host, domain2) {
26224
+ return host === domain2 || host.endsWith(`.${domain2}`);
25960
26225
  }
25961
- function windowsArch(value) {
25962
- const arch3 = value.trim();
25963
- switch (arch3.toLowerCase()) {
25964
- case "64-bit":
25965
- return "x64";
25966
- case "arm 64-bit":
25967
- case "arm64":
25968
- return "arm64";
25969
- case "32-bit":
25970
- return "x86";
25971
- default:
25972
- return arch3;
25973
- }
26226
+ function stripCredentials(location) {
26227
+ return location.replace(/^(https?:\/\/)[^/?#]*@/i, "$1");
25974
26228
  }
25975
- function parseWindowsOs(json2) {
25976
- if (typeof json2 !== "string")
26229
+ function httpUrl3(location) {
26230
+ if (!/^https?:\/\//i.test(location))
25977
26231
  return null;
25978
- let parsed;
25979
26232
  try {
25980
- parsed = JSON.parse(json2);
26233
+ const url2 = new URL(location);
26234
+ if (url2.protocol !== "http:" && url2.protocol !== "https:")
26235
+ return null;
26236
+ return { host: url2.hostname.toLowerCase(), path: url2.pathname };
25981
26237
  } catch {
25982
26238
  return null;
25983
26239
  }
25984
- const info = asRecord2(parsed);
25985
- if (!info)
26240
+ }
26241
+ function firstPathSegment(path) {
26242
+ return path.split("/").find((segment) => segment !== "") ?? "";
26243
+ }
26244
+ function suiteComponent(suite) {
26245
+ if (typeof suite !== "string")
25986
26246
  return null;
25987
- const caption = stringField(info.Caption).replace(/^Microsoft\s+/i, "");
25988
- const version3 = stringField(info.Version);
25989
- if (!caption || !version3)
26247
+ const slash = suite.trim().indexOf("/");
26248
+ if (slash < 0)
25990
26249
  return null;
25991
- const buildNumber = stringField(info.BuildNumber);
25992
- const ubr = info.UBR;
25993
- const build = typeof ubr === "number" ? `${buildNumber}.${ubr}` : buildNumber;
25994
- return { caption, version: version3, build, arch: windowsArch(stringField(info.OSArchitecture)) };
26250
+ const component = suite.trim().slice(slash + 1);
26251
+ return component === "" ? null : component;
25995
26252
  }
25996
- var MODEL_PLACEHOLDERS = /* @__PURE__ */ new Set(["to be filled by o.e.m.", "system product name", "default string"]);
25997
- function cleanModel(text6) {
25998
- if (typeof text6 !== "string")
25999
- return null;
26000
- const cleaned = text6.replace(/\0/g, "").trim().slice(0, 200);
26001
- if (!cleaned)
26253
+ function parseAptPolicy(stdout) {
26254
+ const result2 = /* @__PURE__ */ new Map();
26255
+ if (typeof stdout !== "string")
26256
+ return result2;
26257
+ let name3 = null;
26258
+ let installed = null;
26259
+ let candidate = null;
26260
+ let inInstalledVersion = false;
26261
+ let sources = [];
26262
+ let full = false;
26263
+ const finish = () => {
26264
+ if (name3 !== null && installed !== null)
26265
+ result2.set(name3, { ...originOf(sources), candidate });
26266
+ name3 = null;
26267
+ installed = null;
26268
+ candidate = null;
26269
+ inInstalledVersion = false;
26270
+ sources = [];
26271
+ if (result2.size >= MAX_PACKAGES2)
26272
+ full = true;
26273
+ };
26274
+ for (const line of stdout.split(/\r?\n/)) {
26275
+ if (full)
26276
+ break;
26277
+ if (line.trim() === "")
26278
+ continue;
26279
+ if (/^[NWE]:/.test(line))
26280
+ continue;
26281
+ const first = line.charAt(0);
26282
+ if (first !== " " && first !== " ") {
26283
+ if (!line.endsWith(":") || line.length < 2)
26284
+ continue;
26285
+ finish();
26286
+ if (full)
26287
+ break;
26288
+ name3 = line.slice(0, -1);
26289
+ continue;
26290
+ }
26291
+ const body = line.trimStart();
26292
+ const indent = line.length - body.length;
26293
+ if (indent >= 8) {
26294
+ const source = inInstalledVersion ? sourceOf(body) : null;
26295
+ if (source)
26296
+ sources.push(source);
26297
+ continue;
26298
+ }
26299
+ if (line.startsWith(" *** ")) {
26300
+ inInstalledVersion = true;
26301
+ continue;
26302
+ }
26303
+ if (indent === 2 && body.startsWith("Installed:")) {
26304
+ const value = body.slice("Installed:".length).trim();
26305
+ installed = value === "" || value === NOT_INSTALLED ? null : value;
26306
+ continue;
26307
+ }
26308
+ if (indent === 2 && body.startsWith("Candidate:")) {
26309
+ const value = body.slice("Candidate:".length).trim();
26310
+ candidate = value === "" || value === NOT_INSTALLED ? null : value;
26311
+ continue;
26312
+ }
26313
+ if (inInstalledVersion && indent >= 4)
26314
+ inInstalledVersion = false;
26315
+ }
26316
+ if (!full)
26317
+ finish();
26318
+ return result2;
26319
+ }
26320
+ function sourceOf(body) {
26321
+ const parts = body.split(/\s+/).filter((part) => part !== "");
26322
+ const priority = parts[0];
26323
+ const location = parts[1];
26324
+ if (priority === void 0 || location === void 0)
26002
26325
  return null;
26003
- if (MODEL_PLACEHOLDERS.has(cleaned.toLowerCase()))
26326
+ if (!/^\d+$/.test(priority) || location === "")
26004
26327
  return null;
26005
- return cleaned;
26328
+ return { location, suite: parts[2] ?? null };
26006
26329
  }
26007
- function firstNonEmptyLine(output2) {
26008
- for (const line of output2.split(/\r?\n/)) {
26009
- const trimmed = line.trim();
26010
- if (trimmed)
26011
- return trimmed;
26330
+ function originOf(sources) {
26331
+ const firstByOrigin = /* @__PURE__ */ new Map();
26332
+ for (const source of sources) {
26333
+ const origin = classifyAptSource(source.location, source.suite);
26334
+ if (!firstByOrigin.has(origin))
26335
+ firstByOrigin.set(origin, source.location);
26012
26336
  }
26013
- return "";
26337
+ for (const origin of ORIGIN_ORDER) {
26338
+ const location = firstByOrigin.get(origin);
26339
+ if (location === void 0)
26340
+ continue;
26341
+ return { origin, repository: origin === "local" ? null : stripCredentials(location) };
26342
+ }
26343
+ return { origin: "unknown", repository: null };
26014
26344
  }
26015
- function group2(match) {
26016
- if (!match)
26345
+ function classifyAptSource(location, suite) {
26346
+ if (typeof location !== "string")
26347
+ return "third_party";
26348
+ if (location.trim() === LOCAL_STATUS)
26349
+ return "local";
26350
+ const url2 = httpUrl3(location.trim());
26351
+ if (!url2)
26352
+ return "third_party";
26353
+ if (url2.host === ESM_HOST)
26354
+ return "esm";
26355
+ if (DISTRO_DOMAINS.some((domain2) => isHostOrSubdomain(url2.host, domain2)))
26356
+ return "distro";
26357
+ if (THIRD_PARTY_HOSTS.has(url2.host))
26358
+ return "third_party";
26359
+ const component = suiteComponent(suite);
26360
+ if (MIRROR_PATH_SEGMENTS.has(firstPathSegment(url2.path)) && component !== null && DISTRO_COMPONENTS.has(component)) {
26361
+ return "distro";
26362
+ }
26363
+ return "third_party";
26364
+ }
26365
+
26366
+ // dist/inventory/parsers/apt-sources.js
26367
+ function oneLineHasSecurity(text6) {
26368
+ if (typeof text6 !== "string")
26369
+ return false;
26370
+ for (const raw of text6.split(/\r?\n/)) {
26371
+ const line = raw.trim();
26372
+ if (line === "" || line.startsWith("#"))
26373
+ continue;
26374
+ const suite = oneLineSuite(line);
26375
+ if (suite !== null && suite.endsWith("-security"))
26376
+ return true;
26377
+ }
26378
+ return false;
26379
+ }
26380
+ function oneLineSuite(line) {
26381
+ const tokens = line.split(/\s+/).filter((token) => token !== "");
26382
+ const type = tokens[0];
26383
+ if (type !== "deb" && type !== "deb-src")
26017
26384
  return null;
26018
- const value = match[1];
26019
- if (typeof value !== "string")
26385
+ let index = 1;
26386
+ if (tokens[index]?.startsWith("[")) {
26387
+ while (index < tokens.length && !tokens[index].endsWith("]"))
26388
+ index += 1;
26389
+ index += 1;
26390
+ }
26391
+ const uri = tokens[index];
26392
+ if (!uri)
26020
26393
  return null;
26021
- const trimmed = value.trim();
26022
- return trimmed ? trimmed : null;
26023
- }
26024
- function capture(pattern, value) {
26025
- return group2(pattern.exec(value));
26394
+ return tokens[index + 1] ?? null;
26026
26395
  }
26027
- var GENERIC_VERSION = /^v?(\d+\.\d+(?:\.\d+)?(?:[-+][0-9A-Za-z.-]+)?)\s*$/;
26028
- var VERSION_PARSERS = {
26029
- node: (output2) => capture(/^v?(\d+\.\d+(?:\.\d+)?(?:[-+][0-9A-Za-z.-]+)?)\s*$/, firstNonEmptyLine(output2)),
26030
- python: (output2) => capture(/^Python\s+(\d+\.\d+(?:\.\d+)?(?:[-+][0-9A-Za-z.-]+)?)/, firstNonEmptyLine(output2)),
26031
- php: (output2) => capture(/^PHP\s+(\d+\.\d+(?:\.\d+)?(?:[-+][0-9A-Za-z.-]+)?)/, firstNonEmptyLine(output2)),
26032
- ruby: (output2) => capture(/^ruby\s+(\d+\.\d+(?:\.\d+)?(?:[-+][0-9A-Za-z.-]+)?)/, firstNonEmptyLine(output2)),
26033
- go: (output2) => capture(/^go version go(\S+)/, firstNonEmptyLine(output2)),
26034
- java: (output2) => capture(/^(?:openjdk|java)\s+version\s+"([^"]+)"/, firstNonEmptyLine(output2)),
26396
+ function deb822HasSecurity(text6) {
26397
+ if (typeof text6 !== "string")
26398
+ return false;
26399
+ for (const stanza of text6.split(/\n[ \t]*\n/)) {
26400
+ let enabled = true;
26401
+ const suites = [];
26402
+ let current = null;
26403
+ for (const raw of stanza.split(/\r?\n/)) {
26404
+ const line = raw.replace(/\s+$/, "");
26405
+ if (line === "" || line.startsWith("#"))
26406
+ continue;
26407
+ if (/^[ \t]/.test(line)) {
26408
+ if (current === "Suites")
26409
+ suites.push(...line.trim().split(/\s+/).filter((item) => item !== ""));
26410
+ continue;
26411
+ }
26412
+ const colon = line.indexOf(":");
26413
+ if (colon <= 0)
26414
+ continue;
26415
+ const field = line.slice(0, colon);
26416
+ const value = line.slice(colon + 1).trim();
26417
+ if (field === "Enabled") {
26418
+ enabled = value.toLowerCase() !== "no";
26419
+ current = null;
26420
+ } else if (field === "Suites") {
26421
+ suites.push(...value.split(/\s+/).filter((item) => item !== ""));
26422
+ current = "Suites";
26423
+ } else {
26424
+ current = null;
26425
+ }
26426
+ }
26427
+ if (enabled && suites.some((suite) => suite.endsWith("-security")))
26428
+ return true;
26429
+ }
26430
+ return false;
26431
+ }
26432
+
26433
+ // dist/inventory/parsers/listeners.js
26434
+ var CONTAINER_PLUMBING = /* @__PURE__ */ new Set(["docker-proxy", "containerd-shim", "rootlesskit"]);
26435
+ function classifyIpv4(address) {
26436
+ if (address === "0.0.0.0")
26437
+ return "public";
26438
+ if (address.startsWith("127."))
26439
+ return "loopback";
26440
+ if (address.startsWith("10."))
26441
+ return "private";
26442
+ if (address.startsWith("192.168."))
26443
+ return "private";
26444
+ if (address.startsWith("169.254."))
26445
+ return "private";
26446
+ if (address.startsWith("172.")) {
26447
+ const second = Number(address.split(".")[1]);
26448
+ if (Number.isInteger(second) && second >= 16 && second <= 31)
26449
+ return "private";
26450
+ return "public";
26451
+ }
26452
+ if (address.startsWith("100.")) {
26453
+ const second = Number(address.split(".")[1]);
26454
+ if (Number.isInteger(second) && second >= 64 && second <= 127)
26455
+ return "private";
26456
+ return "public";
26457
+ }
26458
+ return "public";
26459
+ }
26460
+ function classifyBind(address) {
26461
+ if (typeof address !== "string")
26462
+ return "public";
26463
+ const raw = address.trim();
26464
+ if (raw === "" || raw === "*")
26465
+ return "public";
26466
+ const percent = raw.indexOf("%");
26467
+ const addr = percent < 0 ? raw : raw.slice(0, percent);
26468
+ if (addr.includes(":")) {
26469
+ const lower = addr.toLowerCase();
26470
+ if (lower === "::")
26471
+ return "public";
26472
+ if (lower === "::1")
26473
+ return "loopback";
26474
+ const mapped = /^::ffff:(\d+\.\d+\.\d+\.\d+)$/.exec(lower);
26475
+ if (mapped)
26476
+ return classifyIpv4(mapped[1] ?? "");
26477
+ if (/^fe[89ab]/.test(lower))
26478
+ return "private";
26479
+ if (/^f[cd]/.test(lower))
26480
+ return "private";
26481
+ return "public";
26482
+ }
26483
+ return classifyIpv4(addr);
26484
+ }
26485
+ function splitAddrPort(field) {
26486
+ let address;
26487
+ let portText2;
26488
+ if (field.startsWith("[")) {
26489
+ const close = field.indexOf("]");
26490
+ if (close < 0)
26491
+ return void 0;
26492
+ address = field.slice(1, close);
26493
+ const rest = field.slice(close + 1);
26494
+ if (!rest.startsWith(":"))
26495
+ return void 0;
26496
+ portText2 = rest.slice(1);
26497
+ } else {
26498
+ const colon = field.lastIndexOf(":");
26499
+ if (colon < 0)
26500
+ return void 0;
26501
+ address = field.slice(0, colon);
26502
+ portText2 = field.slice(colon + 1);
26503
+ }
26504
+ const port = Number(portText2);
26505
+ if (!Number.isInteger(port) || port < 1 || port > 65535)
26506
+ return void 0;
26507
+ return { address, port };
26508
+ }
26509
+ function parseUsers(users) {
26510
+ if (typeof users !== "string" || users === "")
26511
+ return { pids: [], process: null };
26512
+ const pids = [];
26513
+ const pidRe = /pid=(\d+)/g;
26514
+ let match;
26515
+ while ((match = pidRe.exec(users)) !== null) {
26516
+ const pid = Number(match[1]);
26517
+ if (Number.isInteger(pid) && pid > 0 && !pids.includes(pid))
26518
+ pids.push(pid);
26519
+ }
26520
+ const name3 = /"([^"]*)"/.exec(users);
26521
+ return { pids, process: name3 && name3[1] ? name3[1] : null };
26522
+ }
26523
+ function parseSsLine(line) {
26524
+ const parts = line.split(/\s+/);
26525
+ if (parts.length < 5)
26526
+ return void 0;
26527
+ const proto = parts[0] === "tcp" ? "tcp" : parts[0] === "udp" ? "udp" : void 0;
26528
+ if (!proto)
26529
+ return void 0;
26530
+ const local = splitAddrPort(parts[4] ?? "");
26531
+ if (!local)
26532
+ return void 0;
26533
+ const { pids, process: process2 } = parseUsers(parts.slice(6).join(" "));
26534
+ return { proto, port: local.port, bind: classifyBind(local.address), pids, process: process2 };
26535
+ }
26536
+ function parseSsListeners(stdout) {
26537
+ if (typeof stdout !== "string")
26538
+ return [];
26539
+ const out = [];
26540
+ for (const raw of stdout.split(/\r?\n/)) {
26541
+ const line = raw.trim();
26542
+ if (line === "")
26543
+ continue;
26544
+ const record2 = parseSsLine(line);
26545
+ if (record2)
26546
+ out.push(record2);
26547
+ }
26548
+ return out;
26549
+ }
26550
+ function parseDpkgSearch(stdout) {
26551
+ const map2 = /* @__PURE__ */ new Map();
26552
+ if (typeof stdout !== "string")
26553
+ return map2;
26554
+ for (const raw of stdout.split(/\r?\n/)) {
26555
+ const line = raw.trim();
26556
+ if (line === "")
26557
+ continue;
26558
+ const sep3 = line.indexOf(": ");
26559
+ if (sep3 < 0)
26560
+ continue;
26561
+ const pkg = line.slice(0, sep3);
26562
+ const path = line.slice(sep3 + 2).trim();
26563
+ if (!/^[a-z0-9][a-z0-9+.:~-]*$/.test(pkg) || !path.startsWith("/"))
26564
+ continue;
26565
+ const name3 = pkg.split(":")[0] ?? "";
26566
+ if (name3 === "")
26567
+ continue;
26568
+ if (!map2.has(path))
26569
+ map2.set(path, name3);
26570
+ }
26571
+ return map2;
26572
+ }
26573
+ function publishedHostPorts(ports) {
26574
+ const set2 = /* @__PURE__ */ new Set();
26575
+ if (!Array.isArray(ports))
26576
+ return set2;
26577
+ for (const entry of ports) {
26578
+ const arrow = entry.indexOf("->");
26579
+ const host = arrow < 0 ? entry : entry.slice(0, arrow);
26580
+ const colon = host.lastIndexOf(":");
26581
+ const portText2 = colon < 0 ? "" : host.slice(colon + 1);
26582
+ const port = Number(portText2);
26583
+ if (Number.isInteger(port) && port >= 1 && port <= 65535)
26584
+ set2.add(port);
26585
+ }
26586
+ return set2;
26587
+ }
26588
+ function processNameOf(name3) {
26589
+ if (typeof name3 !== "string")
26590
+ return null;
26591
+ const base2 = name3.split("/").at(-1) ?? name3;
26592
+ const trimmed = base2.trim();
26593
+ if (trimmed === "")
26594
+ return null;
26595
+ return trimmed.length <= 64 ? trimmed : trimmed.slice(0, 64).trimEnd();
26596
+ }
26597
+ function ownerOf(listener, exeByPid, packageByPath, containerByPort) {
26598
+ const name3 = processNameOf(listener.process);
26599
+ if (name3 !== null && CONTAINER_PLUMBING.has(name3)) {
26600
+ const containerId = containerByPort.get(listener.port);
26601
+ if (containerId)
26602
+ return { kind: "container", container_id: containerId };
26603
+ return { kind: "process", name: name3 };
26604
+ }
26605
+ for (const pid of listener.pids) {
26606
+ const exe = exeByPid.get(pid);
26607
+ if (exe === void 0)
26608
+ continue;
26609
+ const pkg = packageByPath.get(exe);
26610
+ if (pkg !== void 0)
26611
+ return { kind: "package", name: pkg };
26612
+ }
26613
+ if (name3 !== null)
26614
+ return { kind: "process", name: name3 };
26615
+ return null;
26616
+ }
26617
+ function resolveListenerOwners(listeners, exeByPid, packageByPath, containers) {
26618
+ if (!Array.isArray(listeners))
26619
+ return [];
26620
+ const containerByPort = /* @__PURE__ */ new Map();
26621
+ if (Array.isArray(containers)) {
26622
+ for (const container of containers) {
26623
+ for (const port of publishedHostPorts(container.ports)) {
26624
+ if (!containerByPort.has(port))
26625
+ containerByPort.set(port, container.id);
26626
+ }
26627
+ }
26628
+ }
26629
+ const out = [];
26630
+ const seen = /* @__PURE__ */ new Set();
26631
+ for (const listener of listeners) {
26632
+ const owner = ownerOf(listener, exeByPid, packageByPath, containerByPort);
26633
+ const item = { proto: listener.proto, port: listener.port, bind: listener.bind, owner };
26634
+ const key = `${item.proto}\0${item.port}\0${item.bind}\0${JSON.stringify(item.owner)}`;
26635
+ if (seen.has(key))
26636
+ continue;
26637
+ seen.add(key);
26638
+ out.push(item);
26639
+ }
26640
+ return out;
26641
+ }
26642
+
26643
+ // dist/inventory/ssh-evidence.js
26644
+ var SSH_EVIDENCE_LIMITS = Object.freeze({
26645
+ /** Bytes of `apt-cache policy` output; a section this long was cut, so its last package entry is dropped. */
26646
+ policyBytes: 4 * 1024 * 1024,
26647
+ /** Package names handed to `apt-cache policy`, and names per call (the local collector's batch). */
26648
+ policyPackages: INVENTORY_LIMITS.packages,
26649
+ policyBatch: 300,
26650
+ /** Bytes of the one-line and of the deb822 source lists (each). */
26651
+ sourcesBytes: 256 * 1024,
26652
+ sourceFileBytes: 64 * 1024,
26653
+ /** `ss` lines, listener pids resolved, executable paths per `dpkg -S`, and `dpkg -S` lines. */
26654
+ ssLines: 1024,
26655
+ pids: 256,
26656
+ paths: 64,
26657
+ ownerLines: 256,
26658
+ /** Seconds the slow commands may take on the host (`timeout`, when installed). */
26659
+ policySeconds: 60,
26660
+ shortSeconds: 10
26661
+ });
26662
+ var cover = (collector, status, count3, durationMs) => ({ collector, status, count: count3, duration_ms: durationMs });
26663
+ function completePolicy(text6) {
26664
+ if (Buffer.byteLength(text6, "utf8") < SSH_EVIDENCE_LIMITS.policyBytes - 2)
26665
+ return { text: text6, truncated: false };
26666
+ const lines4 = text6.split("\n");
26667
+ let last = lines4.length - 1;
26668
+ while (last >= 0) {
26669
+ const line = lines4[last];
26670
+ if (line !== "" && line[0] !== " " && line[0] !== " " && line.endsWith(":"))
26671
+ break;
26672
+ last -= 1;
26673
+ }
26674
+ return { text: last <= 0 ? "" : lines4.slice(0, last).join("\n"), truncated: true };
26675
+ }
26676
+ function applySshAptPolicy(sections, packages, durationMs) {
26677
+ const raw = sections.get("apt-policy");
26678
+ if (raw === void 0)
26679
+ return null;
26680
+ const { text: text6, truncated } = completePolicy(raw);
26681
+ const entries = /* @__PURE__ */ new Map();
26682
+ for (const [name3, entry] of parseAptPolicy(text6))
26683
+ entries.set(name3.split(":")[0], { origin: entry.origin, candidate: entry.candidate });
26684
+ let matched = 0;
26685
+ for (let index = 0; index < packages.length; index += 1) {
26686
+ const item = packages[index];
26687
+ const entry = item.manager === "dpkg" ? entries.get(item.name) : void 0;
26688
+ if (!entry)
26689
+ continue;
26690
+ const next = { ...item, ...entry.origin ? { origin: entry.origin } : {}, candidate: entry.candidate };
26691
+ if (!inventoryPackageSchema.safeParse(next).success)
26692
+ continue;
26693
+ packages[index] = next;
26694
+ matched += 1;
26695
+ }
26696
+ return cover("apt-policy", truncated ? "truncated" : "ok", matched, durationMs);
26697
+ }
26698
+ function listsNewestMs(text6) {
26699
+ const value = (text6 ?? "").trim().split("\n").at(-1)?.trim() ?? "";
26700
+ if (!/^\d{1,12}$/.test(value))
26701
+ return null;
26702
+ const ms = Number(value) * 1e3;
26703
+ return Number.isSafeInteger(ms) && ms > 0 ? ms : null;
26704
+ }
26705
+ function sshAptEvidence(sections) {
26706
+ const config2 = sections.get("apt-config");
26707
+ if (config2 === void 0)
26708
+ return null;
26709
+ const { update_lists, unattended } = parseAptConfig(config2);
26710
+ const held = parseAptHold(sections.get("apt-hold") ?? "").slice(0, INVENTORY_LIMITS.aptHeld);
26711
+ const security_pocket = oneLineHasSecurity(sections.get("sources-list") ?? "") || deb822HasSecurity(sections.get("sources-deb822") ?? "");
26712
+ const apt = { lists_newest_ms: listsNewestMs(sections.get("apt-lists")), update_lists, unattended, security_pocket, held };
26713
+ return inventoryAptSchema.safeParse(apt).success ? apt : null;
26714
+ }
26715
+ function exeByPidOf(text6) {
26716
+ const map2 = /* @__PURE__ */ new Map();
26717
+ for (const line of (text6 ?? "").split("\n")) {
26718
+ const match = /^(\d{1,10}) (\/.*)$/.exec(line);
26719
+ if (!match)
26720
+ continue;
26721
+ const pid = Number(match[1]);
26722
+ const path = match[2];
26723
+ if (pid > 0 && path.length <= 4096 && !/[\u0000-\u001f]/.test(path) && !map2.has(pid))
26724
+ map2.set(pid, path);
26725
+ }
26726
+ return map2;
26727
+ }
26728
+ function sshListeners(sections, durationMs) {
26729
+ if (sections.has("ss-user"))
26730
+ return { listeners: [], coverage: cover("listeners", "not_root", 0, durationMs) };
26731
+ if (sections.has("ss-missing"))
26732
+ return { listeners: [], coverage: cover("listeners", "unavailable", 0, durationMs) };
26733
+ const raw = sections.get("ss-root");
26734
+ if (raw === void 0)
26735
+ return { listeners: [], coverage: null };
26736
+ if ((sections.get("ss-rc") ?? "").trim() !== "0")
26737
+ return { listeners: [], coverage: cover("listeners", "failed", 0, durationMs) };
26738
+ const records = parseSsListeners(raw);
26739
+ const exeByPid = exeByPidOf(sections.get("ss-exe"));
26740
+ const owners = sections.get("ss-owners");
26741
+ const packageByPath = parseDpkgSearch(owners ?? "");
26742
+ const resolved = resolveListenerOwners(records, exeByPid, packageByPath, []);
26743
+ const seen = /* @__PURE__ */ new Set();
26744
+ const listeners = [];
26745
+ for (const item of resolved) {
26746
+ const listener = { proto: item.proto, port: item.port, bind: item.bind, owner: item.owner?.kind === "package" ? item.owner : null };
26747
+ const key = `${listener.proto}\0${listener.port}\0${listener.bind}\0${listener.owner?.kind === "package" ? listener.owner.name : ""}`;
26748
+ if (seen.has(key) || !inventoryListenerSchema.safeParse(listener).success)
26749
+ continue;
26750
+ seen.add(key);
26751
+ listeners.push(listener);
26752
+ }
26753
+ const unresolved = records.length > 0 && (!records.some((record2) => record2.pids.length > 0) || exeByPid.size === 0 || owners !== void 0 && packageByPath.size === 0);
26754
+ const kept = listeners.slice(0, INVENTORY_LIMITS.listeners);
26755
+ const status = unresolved ? "failed" : listeners.length >= INVENTORY_LIMITS.listeners ? "truncated" : "ok";
26756
+ return { listeners: kept, coverage: cover("listeners", status, kept.length, durationMs) };
26757
+ }
26758
+
26759
+ // dist/inventory/parsers/sections.js
26760
+ var SECTION_MARKER = "@@conbridge-section";
26761
+ var MARKER_PATTERN = /^@@conbridge-section ([a-z0-9-]{1,32})$/;
26762
+ function splitSections(output2) {
26763
+ const sections = /* @__PURE__ */ new Map();
26764
+ if (typeof output2 !== "string")
26765
+ return { sections, complete: false };
26766
+ const lines4 = output2.split("\n").map((line) => line.endsWith("\r") ? line.slice(0, -1) : line);
26767
+ let current;
26768
+ let buffer = [];
26769
+ let complete = false;
26770
+ const flush = () => {
26771
+ if (current === void 0)
26772
+ return;
26773
+ let end = buffer.length;
26774
+ while (end > 0 && buffer[end - 1] === "")
26775
+ end -= 1;
26776
+ const content = buffer.slice(0, end).join("\n");
26777
+ if (!sections.has(current))
26778
+ sections.set(current, content);
26779
+ current = void 0;
26780
+ buffer = [];
26781
+ };
26782
+ for (const line of lines4) {
26783
+ const match = MARKER_PATTERN.exec(line);
26784
+ if (!match) {
26785
+ if (current !== void 0)
26786
+ buffer.push(line);
26787
+ continue;
26788
+ }
26789
+ flush();
26790
+ const name3 = match[1] ?? "";
26791
+ if (name3 === "end") {
26792
+ complete = true;
26793
+ break;
26794
+ }
26795
+ current = name3;
26796
+ }
26797
+ if (!complete)
26798
+ flush();
26799
+ return { sections, complete };
26800
+ }
26801
+
26802
+ // dist/inventory/parsers/system.js
26803
+ var RELEASE_KEYS = {
26804
+ ID: "id",
26805
+ VERSION_ID: "versionId",
26806
+ VERSION_CODENAME: "codename",
26807
+ PRETTY_NAME: "prettyName",
26808
+ NAME: "name",
26809
+ VERSION: "version"
26810
+ };
26811
+ function unquote(raw) {
26812
+ const value = raw.trim();
26813
+ if (value.length >= 2 && value.startsWith('"')) {
26814
+ const end = value.lastIndexOf('"');
26815
+ if (end > 0)
26816
+ return value.slice(1, end).replace(/\\"/g, '"').trim();
26817
+ }
26818
+ if (value.length >= 2 && value.startsWith("'")) {
26819
+ const end = value.lastIndexOf("'");
26820
+ if (end > 0)
26821
+ return value.slice(1, end).trim();
26822
+ }
26823
+ return value;
26824
+ }
26825
+ function parseOsRelease(text6) {
26826
+ const result2 = {};
26827
+ if (typeof text6 !== "string")
26828
+ return result2;
26829
+ for (const rawLine of text6.split(/\r?\n/)) {
26830
+ const line = rawLine.trim();
26831
+ if (!line || line.startsWith("#"))
26832
+ continue;
26833
+ const separator = line.indexOf("=");
26834
+ if (separator <= 0)
26835
+ continue;
26836
+ const key = line.slice(0, separator).trim();
26837
+ const field = RELEASE_KEYS[key];
26838
+ if (!field)
26839
+ continue;
26840
+ const value = unquote(line.slice(separator + 1));
26841
+ if (!value)
26842
+ continue;
26843
+ result2[field] = value;
26844
+ }
26845
+ return result2;
26846
+ }
26847
+ function parseSwVers(text6) {
26848
+ const result2 = {};
26849
+ if (typeof text6 !== "string")
26850
+ return result2;
26851
+ for (const rawLine of text6.split(/\r?\n/)) {
26852
+ const line = rawLine.trim();
26853
+ if (!line)
26854
+ continue;
26855
+ const separator = line.indexOf(":");
26856
+ if (separator <= 0)
26857
+ continue;
26858
+ const key = line.slice(0, separator).trim();
26859
+ const value = line.slice(separator + 1).trim();
26860
+ if (!value)
26861
+ continue;
26862
+ if (key === "ProductName")
26863
+ result2.productName = value;
26864
+ else if (key === "ProductVersion")
26865
+ result2.productVersion = value;
26866
+ else if (key === "BuildVersion")
26867
+ result2.buildVersion = value;
26868
+ }
26869
+ return result2;
26870
+ }
26871
+ function asRecord2(value) {
26872
+ return typeof value === "object" && value !== null && !Array.isArray(value) ? value : void 0;
26873
+ }
26874
+ function stringField(value) {
26875
+ return typeof value === "string" ? value.trim() : "";
26876
+ }
26877
+ function windowsArch(value) {
26878
+ const arch3 = value.trim();
26879
+ switch (arch3.toLowerCase()) {
26880
+ case "64-bit":
26881
+ return "x64";
26882
+ case "arm 64-bit":
26883
+ case "arm64":
26884
+ return "arm64";
26885
+ case "32-bit":
26886
+ return "x86";
26887
+ default:
26888
+ return arch3;
26889
+ }
26890
+ }
26891
+ function parseWindowsOs(json2) {
26892
+ if (typeof json2 !== "string")
26893
+ return null;
26894
+ let parsed;
26895
+ try {
26896
+ parsed = JSON.parse(json2);
26897
+ } catch {
26898
+ return null;
26899
+ }
26900
+ const info = asRecord2(parsed);
26901
+ if (!info)
26902
+ return null;
26903
+ const caption = stringField(info.Caption).replace(/^Microsoft\s+/i, "");
26904
+ const version3 = stringField(info.Version);
26905
+ if (!caption || !version3)
26906
+ return null;
26907
+ const buildNumber = stringField(info.BuildNumber);
26908
+ const ubr = info.UBR;
26909
+ const build = typeof ubr === "number" ? `${buildNumber}.${ubr}` : buildNumber;
26910
+ return { caption, version: version3, build, arch: windowsArch(stringField(info.OSArchitecture)) };
26911
+ }
26912
+ var MODEL_PLACEHOLDERS = /* @__PURE__ */ new Set(["to be filled by o.e.m.", "system product name", "default string"]);
26913
+ function cleanModel(text6) {
26914
+ if (typeof text6 !== "string")
26915
+ return null;
26916
+ const cleaned = text6.replace(/\0/g, "").trim().slice(0, 200);
26917
+ if (!cleaned)
26918
+ return null;
26919
+ if (MODEL_PLACEHOLDERS.has(cleaned.toLowerCase()))
26920
+ return null;
26921
+ return cleaned;
26922
+ }
26923
+ function firstNonEmptyLine(output2) {
26924
+ for (const line of output2.split(/\r?\n/)) {
26925
+ const trimmed = line.trim();
26926
+ if (trimmed)
26927
+ return trimmed;
26928
+ }
26929
+ return "";
26930
+ }
26931
+ function group2(match) {
26932
+ if (!match)
26933
+ return null;
26934
+ const value = match[1];
26935
+ if (typeof value !== "string")
26936
+ return null;
26937
+ const trimmed = value.trim();
26938
+ return trimmed ? trimmed : null;
26939
+ }
26940
+ function capture(pattern, value) {
26941
+ return group2(pattern.exec(value));
26942
+ }
26943
+ var GENERIC_VERSION = /^v?(\d+\.\d+(?:\.\d+)?(?:[-+][0-9A-Za-z.-]+)?)\s*$/;
26944
+ var VERSION_PARSERS = {
26945
+ node: (output2) => capture(/^v?(\d+\.\d+(?:\.\d+)?(?:[-+][0-9A-Za-z.-]+)?)\s*$/, firstNonEmptyLine(output2)),
26946
+ python: (output2) => capture(/^Python\s+(\d+\.\d+(?:\.\d+)?(?:[-+][0-9A-Za-z.-]+)?)/, firstNonEmptyLine(output2)),
26947
+ php: (output2) => capture(/^PHP\s+(\d+\.\d+(?:\.\d+)?(?:[-+][0-9A-Za-z.-]+)?)/, firstNonEmptyLine(output2)),
26948
+ ruby: (output2) => capture(/^ruby\s+(\d+\.\d+(?:\.\d+)?(?:[-+][0-9A-Za-z.-]+)?)/, firstNonEmptyLine(output2)),
26949
+ go: (output2) => capture(/^go version go(\S+)/, firstNonEmptyLine(output2)),
26950
+ java: (output2) => capture(/^(?:openjdk|java)\s+version\s+"([^"]+)"/, firstNonEmptyLine(output2)),
26035
26951
  deno: (output2) => capture(/^deno\s+(\S+)/, firstNonEmptyLine(output2)),
26036
26952
  perl: (output2) => capture(/^v?(\d+\.\d+(?:\.\d+)?(?:[-+][0-9A-Za-z.-]+)?)\s*$/, firstNonEmptyLine(output2)) ?? capture(/\(v(\d+\.\d+(?:\.\d+)?)\)/, output2),
26037
26953
  rust: (output2) => capture(/^rustc\s+(\S+)/, firstNonEmptyLine(output2)),
@@ -26071,14 +26987,19 @@ function extractVersion(key, output2) {
26071
26987
  // dist/inventory/ssh.js
26072
26988
  var SSH_INVENTORY_TIMEOUT_S = 120;
26073
26989
  var SSH_INVENTORY_MAX_BYTES = 8 * 1024 * 1024;
26990
+ var TIMEOUTS = `T1=; T2=; if timeout 5 true >/dev/null 2>&1; then T1="timeout ${SSH_EVIDENCE_LIMITS.policySeconds}"; T2="timeout ${SSH_EVIDENCE_LIMITS.shortSeconds}"; fi`;
26991
+ var APT_EVIDENCE = `if command -v apt-cache >/dev/null 2>&1; then export LC_ALL=C.UTF-8; echo "$M apt-policy"; dpkg-query -W -f="\\\${Package}\\n" 2>/dev/null | grep -E "^[a-z0-9][a-z0-9+.-]*$" | sort -u | head -n ${SSH_EVIDENCE_LIMITS.policyPackages} | $T1 xargs -r -n ${SSH_EVIDENCE_LIMITS.policyBatch} apt-cache policy 2>/dev/null | head -c ${SSH_EVIDENCE_LIMITS.policyBytes}; echo; if command -v apt-config >/dev/null 2>&1; then echo "$M apt-config"; $T2 apt-config dump 2>/dev/null | grep -E "^APT::Periodic::(Update-Package-Lists|Unattended-Upgrade) " | head -n 8; fi; echo "$M apt-hold"; $T2 apt-mark showhold 2>/dev/null | head -n ${INVENTORY_LIMITS.aptHeld}; echo "$M apt-lists"; stat -c %Y /var/lib/apt/lists/*_InRelease 2>/dev/null | sort -n | tail -n 1; echo "$M sources-list"; cat /etc/apt/sources.list /etc/apt/sources.list.d/*.list 2>/dev/null | head -c ${SSH_EVIDENCE_LIMITS.sourcesBytes}; echo; echo "$M sources-deb822"; for f in /etc/apt/sources.list.d/*.sources; do [ -r "$f" ] && head -c ${SSH_EVIDENCE_LIMITS.sourceFileBytes} "$f" 2>/dev/null; echo; echo; done | head -c ${SSH_EVIDENCE_LIMITS.sourcesBytes}; echo; export LC_ALL=C; fi; `;
26992
+ var LISTENERS = `if command -v ss >/dev/null 2>&1; then if [ "$(id -u 2>/dev/null)" = 0 ]; then S=$($T2 ss -tulnpH 2>/dev/null); r=$?; echo "$M ss-root"; printf "%s\\n" "$S" | head -n ${SSH_EVIDENCE_LIMITS.ssLines}; echo "$M ss-rc"; echo "$r"; X=$(for p in $(printf "%s\\n" "$S" | grep -o "pid=[0-9]*" | cut -d= -f2 | sort -un | head -n ${SSH_EVIDENCE_LIMITS.pids}); do e=$(readlink /proc/$p/exe 2>/dev/null) && echo "$p $e"; done); echo "$M ss-exe"; printf "%s\\n" "$X"; if command -v dpkg >/dev/null 2>&1; then echo "$M ss-owners"; printf "%s\\n" "$X" | cut -d" " -f2- | grep "^/" | sort -u | head -n ${SSH_EVIDENCE_LIMITS.paths} | $T2 xargs -r dpkg -S 2>/dev/null | head -n ${SSH_EVIDENCE_LIMITS.ownerLines}; fi; else echo "$M ss-user"; fi; else echo "$M ss-missing"; fi`;
26074
26993
  var SCRIPT_BODY = [
26075
26994
  `M="${SECTION_MARKER}"`,
26076
26995
  "export LC_ALL=C",
26996
+ TIMEOUTS,
26077
26997
  'echo "$M os-release"',
26078
26998
  "{ cat /etc/os-release 2>/dev/null || cat /usr/lib/os-release 2>/dev/null; }",
26079
26999
  'echo "$M uname"',
26080
27000
  "uname -srm 2>/dev/null",
26081
- 'if command -v dpkg-query >/dev/null 2>&1; then echo "$M dpkg"; dpkg-query -W -f="\\${Package}\\t\\${Version}\\t\\${Architecture}\\t\\${Installed-Size}\\t\\${db:Status-Abbrev}\\t\\${source:Package}\\t\\${source:Version}\\n" 2>/dev/null; r=$?; echo "$M rc"; echo "$r"; elif command -v rpm >/dev/null 2>&1; then echo "$M rpm"; rpm -qa --qf "%{NAME}\\t%{EPOCH}\\t%{VERSION}\\t%{RELEASE}\\t%{ARCH}\\t%{SIZE}\\n" 2>/dev/null; r=$?; echo "$M rc"; echo "$r"; elif command -v apk >/dev/null 2>&1; then echo "$M apk"; apk list --installed 2>/dev/null; r=$?; echo "$M rc"; echo "$r"; fi',
27001
+ 'if command -v dpkg-query >/dev/null 2>&1; then echo "$M dpkg"; dpkg-query -W -f="\\${Package}\\t\\${Version}\\t\\${Architecture}\\t\\${Installed-Size}\\t\\${db:Status-Abbrev}\\t\\${source:Package}\\t\\${source:Version}\\n" 2>/dev/null; r=$?; echo "$M rc"; echo "$r"; ' + APT_EVIDENCE + 'elif command -v rpm >/dev/null 2>&1; then echo "$M rpm"; rpm -qa --qf "%{NAME}\\t%{EPOCH}\\t%{VERSION}\\t%{RELEASE}\\t%{ARCH}\\t%{SIZE}\\n" 2>/dev/null; r=$?; echo "$M rc"; echo "$r"; elif command -v apk >/dev/null 2>&1; then echo "$M apk"; apk list --installed 2>/dev/null; r=$?; echo "$M rc"; echo "$r"; fi',
27002
+ LISTENERS,
26082
27003
  'echo "$M end"'
26083
27004
  ].join("; ");
26084
27005
  var SSH_INVENTORY_SCRIPT = `/bin/sh -c '${SCRIPT_BODY}'`;
@@ -26133,29 +27054,41 @@ function buildSshSnapshot(output2, now = /* @__PURE__ */ new Date(), durationMs
26133
27054
  const os = osFrom(sections.get("os-release") ?? "", sections.get("uname") ?? "");
26134
27055
  coverage.push({ collector: "os", status: sections.has("os-release") || sections.has("uname") ? "ok" : "failed", count: 0, duration_ms: duration3 });
26135
27056
  let packages = [];
27057
+ let apt = null;
26136
27058
  const found = PACKAGE_SECTIONS.find(([name3]) => sections.has(name3));
26137
27059
  if (found) {
26138
27060
  const [name3, parse3] = found;
26139
27061
  if ((sections.get("rc") ?? "").trim() === "0") {
26140
- packages = parse3(sections.get(name3) ?? "").filter((item) => inventoryPackageSchema.safeParse(item).success);
27062
+ packages = parse3(sections.get(name3) ?? "").filter((item) => inventoryPackageSchema.safeParse(item).success).slice(0, INVENTORY_LIMITS.packages);
26141
27063
  coverage.push({ collector: name3, status: packages.length >= INVENTORY_LIMITS.packages ? "truncated" : "ok", count: packages.length, duration_ms: duration3 });
27064
+ if (name3 === "dpkg") {
27065
+ const policy = applySshAptPolicy(sections, packages, duration3);
27066
+ if (policy)
27067
+ coverage.push(policy);
27068
+ apt = sshAptEvidence(sections);
27069
+ }
26142
27070
  } else {
26143
27071
  coverage.push({ collector: name3, status: "failed", count: 0, duration_ms: duration3 });
26144
27072
  }
26145
27073
  } else {
26146
27074
  coverage.push({ collector: "packages", status: "unavailable", count: 0, duration_ms: duration3 });
26147
27075
  }
27076
+ const listened = sshListeners(sections, duration3);
27077
+ if (listened.coverage)
27078
+ coverage.push(listened.coverage);
26148
27079
  return inventorySnapshotSchema.parse({
26149
27080
  schema: 1,
26150
27081
  collected_at: now.toISOString(),
26151
27082
  agent_version: AGENT_VERSION,
26152
27083
  os,
26153
- packages: packages.slice(0, INVENTORY_LIMITS.packages),
27084
+ packages,
26154
27085
  software: [],
26155
27086
  services: [],
26156
27087
  containers: [],
26157
27088
  images: [],
26158
27089
  pods: [],
27090
+ ...listened.listeners.length > 0 ? { listeners: listened.listeners } : {},
27091
+ ...apt ? { apt } : {},
26159
27092
  coverage: coverage.filter((entry) => inventoryCoverageSchema.safeParse(entry).success)
26160
27093
  });
26161
27094
  }
@@ -26303,8 +27236,8 @@ var InventoryLoop = class {
26303
27236
  const spacing = this.#options.sendSpacingMs ?? SEND_SPACING_MS;
26304
27237
  const wait = this.#lastSendEndMs === null ? 0 : this.#lastSendEndMs + spacing - this.#now();
26305
27238
  if (wait > 0)
26306
- await new Promise((resolve9) => {
26307
- setTimeout(resolve9, wait).unref?.();
27239
+ await new Promise((resolve10) => {
27240
+ setTimeout(resolve10, wait).unref?.();
26308
27241
  });
26309
27242
  return this.#active;
26310
27243
  }
@@ -26382,10 +27315,10 @@ var InventoryLoop = class {
26382
27315
  };
26383
27316
 
26384
27317
  // dist/inventory/collector.js
26385
- var import_node_child_process8 = require("node:child_process");
27318
+ var import_node_child_process9 = require("node:child_process");
26386
27319
  var import_node_fs3 = require("node:fs");
26387
- var import_promises13 = require("node:fs/promises");
26388
- var import_node_os5 = require("node:os");
27320
+ var import_promises14 = require("node:fs/promises");
27321
+ var import_node_os6 = require("node:os");
26389
27322
 
26390
27323
  // dist/inventory/parsers/services.js
26391
27324
  var NAME_MAX2 = 200;
@@ -27024,420 +27957,139 @@ function parseKubectlPods(stdout) {
27024
27957
  if (parts.length < 7)
27025
27958
  continue;
27026
27959
  const namespace = nameOf2(parts[0]);
27027
- const name3 = nameOf2(parts[1]);
27028
- if (!name3)
27029
- continue;
27030
- const readyField = parts[5] ?? "";
27031
- const restartsField = parts[6] ?? "";
27032
- let containers = 0;
27033
- let ready;
27034
- if (readyField !== "<none>") {
27035
- const values = readyField.split(",").map((entry) => entry.trim()).filter((entry) => entry !== "");
27036
- containers = values.length;
27037
- ready = values.filter((entry) => entry.toLowerCase() === "true").length;
27038
- }
27039
- let restarts;
27040
- if (restartsField !== "<none>") {
27041
- const values = restartsField.split(",").map((entry) => entry.trim()).filter((entry) => /^\d+$/.test(entry));
27042
- if (values.length > 0)
27043
- restarts = values.reduce((total, entry) => total + Number(entry), 0);
27044
- }
27045
- const item = {
27046
- name: name3,
27047
- engine: "kubernetes",
27048
- status: text4(parts[2], POD_STATUS_MAX) || "Unknown",
27049
- containers
27050
- };
27051
- if (namespace)
27052
- item.namespace = namespace;
27053
- if (ready !== void 0)
27054
- item.ready = ready;
27055
- if (restarts !== void 0)
27056
- item.restarts = restarts;
27057
- const node2 = nameOf2(parts[3]);
27058
- if (node2 && node2 !== "<none>")
27059
- item.node = node2;
27060
- const created = text4(parts[4], 64);
27061
- if (created && created !== "<none>") {
27062
- const createdAt = isoString(created);
27063
- if (createdAt)
27064
- item.created_at = createdAt;
27065
- }
27066
- push2(result2, item, MAX_PODS);
27067
- }
27068
- return result2;
27069
- }
27070
-
27071
- // dist/inventory/parsers/sbom.js
27072
- var NAME_MAX4 = 200;
27073
- var VERSION_MAX2 = 128;
27074
- var DISTRO_MAX = 40;
27075
- var MAX_PACKAGES2 = INVENTORY_LIMITS.imagePackages;
27076
- var DISTRO_ID = /^[a-z0-9._-]{1,40}$/;
27077
- var MANAGERS = { deb: "dpkg", apk: "apk", npm: "npm" };
27078
- function asRecord5(value) {
27079
- return typeof value === "object" && value !== null && !Array.isArray(value) ? value : void 0;
27080
- }
27081
- function parseJson4(stdout) {
27082
- if (typeof stdout !== "string")
27083
- return void 0;
27084
- try {
27085
- return JSON.parse(stdout);
27086
- } catch {
27087
- return void 0;
27088
- }
27089
- }
27090
- function valueOf(value, max) {
27091
- if (typeof value !== "string")
27092
- return void 0;
27093
- const trimmed = value.trim();
27094
- if (!trimmed || trimmed.length > max)
27095
- return void 0;
27096
- return trimmed;
27097
- }
27098
- function distroId(value) {
27099
- const id = valueOf(value, DISTRO_MAX)?.toLowerCase();
27100
- return id !== void 0 && DISTRO_ID.test(id) ? id : void 0;
27101
- }
27102
- function distroVersion(value) {
27103
- return valueOf(value, DISTRO_MAX);
27104
- }
27105
- function isArtifactType(value) {
27106
- return typeof value === "string" && Object.hasOwn(MANAGERS, value);
27107
- }
27108
- function packageOf(type, artifact) {
27109
- const name3 = valueOf(artifact.name, NAME_MAX4);
27110
- const version3 = valueOf(artifact.version, VERSION_MAX2);
27111
- if (!name3 || !version3)
27112
- return void 0;
27113
- const item = { name: name3, version: version3, manager: MANAGERS[type] };
27114
- const metadata = asRecord5(artifact.metadata);
27115
- if (type === "deb") {
27116
- const source = valueOf(metadata?.source, NAME_MAX4);
27117
- if (source && source !== name3) {
27118
- item.source_name = source;
27119
- item.source_version = valueOf(metadata?.sourceVersion, VERSION_MAX2) ?? version3;
27120
- }
27121
- } else if (type === "apk") {
27122
- const origin = valueOf(metadata?.originPackage, NAME_MAX4);
27123
- if (origin && origin !== name3) {
27124
- item.source_name = origin;
27125
- item.source_version = version3;
27126
- }
27127
- }
27128
- return item;
27129
- }
27130
- function parseSyftJson(stdout) {
27131
- const root = asRecord5(parseJson4(stdout));
27132
- const artifacts = root?.artifacts;
27133
- if (!root || !Array.isArray(artifacts))
27134
- return { packages: [] };
27135
- const result2 = { packages: [] };
27136
- const distro = asRecord5(root.distro);
27137
- const id = distroId(distro?.id);
27138
- if (id)
27139
- result2.distro_id = id;
27140
- const version3 = distroVersion(distro?.versionID) ?? distroVersion(distro?.version);
27141
- if (version3)
27142
- result2.distro_version = version3;
27143
- const seen = /* @__PURE__ */ new Set();
27144
- for (const value of artifacts) {
27145
- const artifact = asRecord5(value);
27146
- if (!artifact || !isArtifactType(artifact.type))
27147
- continue;
27148
- const item = packageOf(artifact.type, artifact);
27149
- if (!item)
27150
- continue;
27151
- const key = `${item.manager}\0${item.name}\0${item.version}\0${item.source_name ?? ""}\0${item.source_version ?? ""}`;
27152
- if (seen.has(key))
27153
- continue;
27154
- seen.add(key);
27155
- result2.packages.push(item);
27156
- if (result2.packages.length >= MAX_PACKAGES2)
27157
- break;
27158
- }
27159
- return result2;
27160
- }
27161
-
27162
- // dist/inventory/parsers/apt-policy.js
27163
- var MAX_PACKAGES3 = INVENTORY_LIMITS.packages;
27164
- var NOT_INSTALLED = "(none)";
27165
- var LOCAL_STATUS = "/var/lib/dpkg/status";
27166
- var DISTRO_DOMAINS = ["ubuntu.com", "debian.org", "raspbian.org", "raspberrypi.com", "raspberrypi.org"];
27167
- var ESM_HOST = "esm.ubuntu.com";
27168
- var THIRD_PARTY_HOSTS = /* @__PURE__ */ new Set([
27169
- "ppa.launchpadcontent.net",
27170
- "ppa.launchpad.net",
27171
- "deb.nodesource.com",
27172
- "deb.sury.org",
27173
- "packages.sury.org",
27174
- "download.docker.com",
27175
- "nginx.org",
27176
- "packages.microsoft.com",
27177
- "apt.postgresql.org",
27178
- "repo.mysql.com"
27179
- ]);
27180
- var MIRROR_PATH_SEGMENTS = /* @__PURE__ */ new Set(["ubuntu", "ubuntu-ports", "debian", "debian-security", "raspbian"]);
27181
- var DISTRO_COMPONENTS = /* @__PURE__ */ new Set(["main", "restricted", "universe", "multiverse", "contrib", "non-free", "non-free-firmware"]);
27182
- var ORIGIN_ORDER = ["esm", "distro", "third_party", "local"];
27183
- function isHostOrSubdomain(host, domain2) {
27184
- return host === domain2 || host.endsWith(`.${domain2}`);
27185
- }
27186
- function stripCredentials(location) {
27187
- return location.replace(/^(https?:\/\/)[^/?#]*@/i, "$1");
27188
- }
27189
- function httpUrl3(location) {
27190
- if (!/^https?:\/\//i.test(location))
27191
- return null;
27192
- try {
27193
- const url2 = new URL(location);
27194
- if (url2.protocol !== "http:" && url2.protocol !== "https:")
27195
- return null;
27196
- return { host: url2.hostname.toLowerCase(), path: url2.pathname };
27197
- } catch {
27198
- return null;
27199
- }
27200
- }
27201
- function firstPathSegment(path) {
27202
- return path.split("/").find((segment) => segment !== "") ?? "";
27203
- }
27204
- function suiteComponent(suite) {
27205
- if (typeof suite !== "string")
27206
- return null;
27207
- const slash = suite.trim().indexOf("/");
27208
- if (slash < 0)
27209
- return null;
27210
- const component = suite.trim().slice(slash + 1);
27211
- return component === "" ? null : component;
27212
- }
27213
- function parseAptPolicy(stdout) {
27214
- const result2 = /* @__PURE__ */ new Map();
27215
- if (typeof stdout !== "string")
27216
- return result2;
27217
- let name3 = null;
27218
- let installed = null;
27219
- let candidate = null;
27220
- let inInstalledVersion = false;
27221
- let sources = [];
27222
- let full = false;
27223
- const finish = () => {
27224
- if (name3 !== null && installed !== null)
27225
- result2.set(name3, { ...originOf(sources), candidate });
27226
- name3 = null;
27227
- installed = null;
27228
- candidate = null;
27229
- inInstalledVersion = false;
27230
- sources = [];
27231
- if (result2.size >= MAX_PACKAGES3)
27232
- full = true;
27233
- };
27234
- for (const line of stdout.split(/\r?\n/)) {
27235
- if (full)
27236
- break;
27237
- if (line.trim() === "")
27238
- continue;
27239
- if (/^[NWE]:/.test(line))
27240
- continue;
27241
- const first = line.charAt(0);
27242
- if (first !== " " && first !== " ") {
27243
- if (!line.endsWith(":") || line.length < 2)
27244
- continue;
27245
- finish();
27246
- if (full)
27247
- break;
27248
- name3 = line.slice(0, -1);
27249
- continue;
27250
- }
27251
- const body = line.trimStart();
27252
- const indent = line.length - body.length;
27253
- if (indent >= 8) {
27254
- const source = inInstalledVersion ? sourceOf(body) : null;
27255
- if (source)
27256
- sources.push(source);
27257
- continue;
27258
- }
27259
- if (line.startsWith(" *** ")) {
27260
- inInstalledVersion = true;
27960
+ const name3 = nameOf2(parts[1]);
27961
+ if (!name3)
27261
27962
  continue;
27963
+ const readyField = parts[5] ?? "";
27964
+ const restartsField = parts[6] ?? "";
27965
+ let containers = 0;
27966
+ let ready;
27967
+ if (readyField !== "<none>") {
27968
+ const values = readyField.split(",").map((entry) => entry.trim()).filter((entry) => entry !== "");
27969
+ containers = values.length;
27970
+ ready = values.filter((entry) => entry.toLowerCase() === "true").length;
27262
27971
  }
27263
- if (indent === 2 && body.startsWith("Installed:")) {
27264
- const value = body.slice("Installed:".length).trim();
27265
- installed = value === "" || value === NOT_INSTALLED ? null : value;
27266
- continue;
27972
+ let restarts;
27973
+ if (restartsField !== "<none>") {
27974
+ const values = restartsField.split(",").map((entry) => entry.trim()).filter((entry) => /^\d+$/.test(entry));
27975
+ if (values.length > 0)
27976
+ restarts = values.reduce((total, entry) => total + Number(entry), 0);
27267
27977
  }
27268
- if (indent === 2 && body.startsWith("Candidate:")) {
27269
- const value = body.slice("Candidate:".length).trim();
27270
- candidate = value === "" || value === NOT_INSTALLED ? null : value;
27271
- continue;
27978
+ const item = {
27979
+ name: name3,
27980
+ engine: "kubernetes",
27981
+ status: text4(parts[2], POD_STATUS_MAX) || "Unknown",
27982
+ containers
27983
+ };
27984
+ if (namespace)
27985
+ item.namespace = namespace;
27986
+ if (ready !== void 0)
27987
+ item.ready = ready;
27988
+ if (restarts !== void 0)
27989
+ item.restarts = restarts;
27990
+ const node2 = nameOf2(parts[3]);
27991
+ if (node2 && node2 !== "<none>")
27992
+ item.node = node2;
27993
+ const created = text4(parts[4], 64);
27994
+ if (created && created !== "<none>") {
27995
+ const createdAt = isoString(created);
27996
+ if (createdAt)
27997
+ item.created_at = createdAt;
27272
27998
  }
27273
- if (inInstalledVersion && indent >= 4)
27274
- inInstalledVersion = false;
27999
+ push2(result2, item, MAX_PODS);
27275
28000
  }
27276
- if (!full)
27277
- finish();
27278
28001
  return result2;
27279
28002
  }
27280
- function sourceOf(body) {
27281
- const parts = body.split(/\s+/).filter((part) => part !== "");
27282
- const priority = parts[0];
27283
- const location = parts[1];
27284
- if (priority === void 0 || location === void 0)
27285
- return null;
27286
- if (!/^\d+$/.test(priority) || location === "")
27287
- return null;
27288
- return { location, suite: parts[2] ?? null };
27289
- }
27290
- function originOf(sources) {
27291
- const firstByOrigin = /* @__PURE__ */ new Map();
27292
- for (const source of sources) {
27293
- const origin = classifyAptSource(source.location, source.suite);
27294
- if (!firstByOrigin.has(origin))
27295
- firstByOrigin.set(origin, source.location);
27296
- }
27297
- for (const origin of ORIGIN_ORDER) {
27298
- const location = firstByOrigin.get(origin);
27299
- if (location === void 0)
27300
- continue;
27301
- return { origin, repository: origin === "local" ? null : stripCredentials(location) };
27302
- }
27303
- return { origin: "unknown", repository: null };
28003
+
28004
+ // dist/inventory/parsers/sbom.js
28005
+ var NAME_MAX4 = 200;
28006
+ var VERSION_MAX2 = 128;
28007
+ var DISTRO_MAX = 40;
28008
+ var MAX_PACKAGES3 = INVENTORY_LIMITS.imagePackages;
28009
+ var DISTRO_ID = /^[a-z0-9._-]{1,40}$/;
28010
+ var MANAGERS = { deb: "dpkg", apk: "apk", npm: "npm" };
28011
+ function asRecord5(value) {
28012
+ return typeof value === "object" && value !== null && !Array.isArray(value) ? value : void 0;
27304
28013
  }
27305
- function classifyAptSource(location, suite) {
27306
- if (typeof location !== "string")
27307
- return "third_party";
27308
- if (location.trim() === LOCAL_STATUS)
27309
- return "local";
27310
- const url2 = httpUrl3(location.trim());
27311
- if (!url2)
27312
- return "third_party";
27313
- if (url2.host === ESM_HOST)
27314
- return "esm";
27315
- if (DISTRO_DOMAINS.some((domain2) => isHostOrSubdomain(url2.host, domain2)))
27316
- return "distro";
27317
- if (THIRD_PARTY_HOSTS.has(url2.host))
27318
- return "third_party";
27319
- const component = suiteComponent(suite);
27320
- if (MIRROR_PATH_SEGMENTS.has(firstPathSegment(url2.path)) && component !== null && DISTRO_COMPONENTS.has(component)) {
27321
- return "distro";
28014
+ function parseJson4(stdout) {
28015
+ if (typeof stdout !== "string")
28016
+ return void 0;
28017
+ try {
28018
+ return JSON.parse(stdout);
28019
+ } catch {
28020
+ return void 0;
27322
28021
  }
27323
- return "third_party";
27324
28022
  }
27325
-
27326
- // dist/inventory/parsers/apt-config.js
27327
- var UPDATE_LISTS_KEY = "APT::Periodic::Update-Package-Lists";
27328
- var UNATTENDED_KEY = "APT::Periodic::Unattended-Upgrade";
27329
- function truthy(raw) {
27330
- if (raw === null)
27331
- return false;
27332
- let value = raw.trim();
27333
- if (value.endsWith(";"))
27334
- value = value.slice(0, -1).trim();
27335
- if (value.length >= 2 && value.startsWith('"') && value.endsWith('"'))
27336
- value = value.slice(1, -1);
27337
- if (value === "")
27338
- return false;
27339
- if (value.toLowerCase() === "always")
27340
- return true;
27341
- const number4 = Number(value);
27342
- return Number.isFinite(number4) && number4 > 0;
28023
+ function valueOf(value, max) {
28024
+ if (typeof value !== "string")
28025
+ return void 0;
28026
+ const trimmed = value.trim();
28027
+ if (!trimmed || trimmed.length > max)
28028
+ return void 0;
28029
+ return trimmed;
27343
28030
  }
27344
- function parseAptConfig(stdout) {
27345
- let updateListsValue = null;
27346
- let unattendedValue = null;
27347
- if (typeof stdout === "string") {
27348
- for (const raw of stdout.split(/\r?\n/)) {
27349
- const line = raw.trim();
27350
- if (line === "")
27351
- continue;
27352
- const space = line.search(/\s/);
27353
- const key = space < 0 ? line : line.slice(0, space);
27354
- const value = space < 0 ? "" : line.slice(space + 1).trim();
27355
- if (key === UPDATE_LISTS_KEY)
27356
- updateListsValue = value;
27357
- else if (key === UNATTENDED_KEY)
27358
- unattendedValue = value;
27359
- }
27360
- }
27361
- return { update_lists: truthy(updateListsValue), unattended: truthy(unattendedValue) };
28031
+ function distroId(value) {
28032
+ const id = valueOf(value, DISTRO_MAX)?.toLowerCase();
28033
+ return id !== void 0 && DISTRO_ID.test(id) ? id : void 0;
27362
28034
  }
27363
- function parseAptHold(stdout) {
27364
- if (typeof stdout !== "string")
27365
- return [];
27366
- const held = [];
27367
- for (const raw of stdout.split(/\r?\n/)) {
27368
- const name3 = raw.trim();
27369
- if (!/^[a-z0-9][a-z0-9+.:~-]*$/.test(name3) || name3.length > 200)
27370
- continue;
27371
- held.push(name3);
27372
- }
27373
- return held;
28035
+ function distroVersion(value) {
28036
+ return valueOf(value, DISTRO_MAX);
27374
28037
  }
27375
-
27376
- // dist/inventory/parsers/apt-sources.js
27377
- function oneLineHasSecurity(text6) {
27378
- if (typeof text6 !== "string")
27379
- return false;
27380
- for (const raw of text6.split(/\r?\n/)) {
27381
- const line = raw.trim();
27382
- if (line === "" || line.startsWith("#"))
27383
- continue;
27384
- const suite = oneLineSuite(line);
27385
- if (suite !== null && suite.endsWith("-security"))
27386
- return true;
27387
- }
27388
- return false;
28038
+ function isArtifactType(value) {
28039
+ return typeof value === "string" && Object.hasOwn(MANAGERS, value);
27389
28040
  }
27390
- function oneLineSuite(line) {
27391
- const tokens = line.split(/\s+/).filter((token) => token !== "");
27392
- const type = tokens[0];
27393
- if (type !== "deb" && type !== "deb-src")
27394
- return null;
27395
- let index = 1;
27396
- if (tokens[index]?.startsWith("[")) {
27397
- while (index < tokens.length && !tokens[index].endsWith("]"))
27398
- index += 1;
27399
- index += 1;
28041
+ function packageOf(type, artifact) {
28042
+ const name3 = valueOf(artifact.name, NAME_MAX4);
28043
+ const version3 = valueOf(artifact.version, VERSION_MAX2);
28044
+ if (!name3 || !version3)
28045
+ return void 0;
28046
+ const item = { name: name3, version: version3, manager: MANAGERS[type] };
28047
+ const metadata = asRecord5(artifact.metadata);
28048
+ if (type === "deb") {
28049
+ const source = valueOf(metadata?.source, NAME_MAX4);
28050
+ if (source && source !== name3) {
28051
+ item.source_name = source;
28052
+ item.source_version = valueOf(metadata?.sourceVersion, VERSION_MAX2) ?? version3;
28053
+ }
28054
+ } else if (type === "apk") {
28055
+ const origin = valueOf(metadata?.originPackage, NAME_MAX4);
28056
+ if (origin && origin !== name3) {
28057
+ item.source_name = origin;
28058
+ item.source_version = version3;
28059
+ }
27400
28060
  }
27401
- const uri = tokens[index];
27402
- if (!uri)
27403
- return null;
27404
- return tokens[index + 1] ?? null;
28061
+ return item;
27405
28062
  }
27406
- function deb822HasSecurity(text6) {
27407
- if (typeof text6 !== "string")
27408
- return false;
27409
- for (const stanza of text6.split(/\n[ \t]*\n/)) {
27410
- let enabled = true;
27411
- const suites = [];
27412
- let current = null;
27413
- for (const raw of stanza.split(/\r?\n/)) {
27414
- const line = raw.replace(/\s+$/, "");
27415
- if (line === "" || line.startsWith("#"))
27416
- continue;
27417
- if (/^[ \t]/.test(line)) {
27418
- if (current === "Suites")
27419
- suites.push(...line.trim().split(/\s+/).filter((item) => item !== ""));
27420
- continue;
27421
- }
27422
- const colon = line.indexOf(":");
27423
- if (colon <= 0)
27424
- continue;
27425
- const field = line.slice(0, colon);
27426
- const value = line.slice(colon + 1).trim();
27427
- if (field === "Enabled") {
27428
- enabled = value.toLowerCase() !== "no";
27429
- current = null;
27430
- } else if (field === "Suites") {
27431
- suites.push(...value.split(/\s+/).filter((item) => item !== ""));
27432
- current = "Suites";
27433
- } else {
27434
- current = null;
27435
- }
27436
- }
27437
- if (enabled && suites.some((suite) => suite.endsWith("-security")))
27438
- return true;
28063
+ function parseSyftJson(stdout) {
28064
+ const root = asRecord5(parseJson4(stdout));
28065
+ const artifacts = root?.artifacts;
28066
+ if (!root || !Array.isArray(artifacts))
28067
+ return { packages: [] };
28068
+ const result2 = { packages: [] };
28069
+ const distro = asRecord5(root.distro);
28070
+ const id = distroId(distro?.id);
28071
+ if (id)
28072
+ result2.distro_id = id;
28073
+ const version3 = distroVersion(distro?.versionID) ?? distroVersion(distro?.version);
28074
+ if (version3)
28075
+ result2.distro_version = version3;
28076
+ const seen = /* @__PURE__ */ new Set();
28077
+ for (const value of artifacts) {
28078
+ const artifact = asRecord5(value);
28079
+ if (!artifact || !isArtifactType(artifact.type))
28080
+ continue;
28081
+ const item = packageOf(artifact.type, artifact);
28082
+ if (!item)
28083
+ continue;
28084
+ const key = `${item.manager}\0${item.name}\0${item.version}\0${item.source_name ?? ""}\0${item.source_version ?? ""}`;
28085
+ if (seen.has(key))
28086
+ continue;
28087
+ seen.add(key);
28088
+ result2.packages.push(item);
28089
+ if (result2.packages.length >= MAX_PACKAGES3)
28090
+ break;
27439
28091
  }
27440
- return false;
28092
+ return result2;
27441
28093
  }
27442
28094
 
27443
28095
  // dist/inventory/parsers/health.js
@@ -28009,12 +28661,12 @@ function endpointOf(port, protocol, cert, hsts) {
28009
28661
  };
28010
28662
  }
28011
28663
  function hstsOf(port) {
28012
- return new Promise((resolve9) => {
28664
+ return new Promise((resolve10) => {
28013
28665
  let settled = false;
28014
28666
  const finish = (value) => {
28015
28667
  if (!settled) {
28016
28668
  settled = true;
28017
- resolve9(value);
28669
+ resolve10(value);
28018
28670
  }
28019
28671
  };
28020
28672
  const req = (0, import_node_https.request)({ host: "127.0.0.1", port, method: "HEAD", path: "/", rejectUnauthorized: false, timeout: TIMEOUT_MS, headers: { host: "localhost", "user-agent": "conbridge-agent/tls-check" } }, (res) => {
@@ -28031,7 +28683,7 @@ function hstsOf(port) {
28031
28683
  });
28032
28684
  }
28033
28685
  function createTlsProbe(webPorts = WEB_PORTS) {
28034
- return (port) => new Promise((resolve9) => {
28686
+ return (port) => new Promise((resolve10) => {
28035
28687
  let settled = false;
28036
28688
  const socket = (0, import_node_tls.connect)({
28037
28689
  host: "127.0.0.1",
@@ -28046,7 +28698,7 @@ function createTlsProbe(webPorts = WEB_PORTS) {
28046
28698
  if (!settled) {
28047
28699
  settled = true;
28048
28700
  socket.destroy();
28049
- resolve9(value);
28701
+ resolve10(value);
28050
28702
  }
28051
28703
  };
28052
28704
  socket.once("secureConnect", () => {
@@ -28078,216 +28730,6 @@ async function collectTlsEndpoints(probe, ports = TLS_PORTS, width = 4) {
28078
28730
  return found.filter((entry) => entry !== null);
28079
28731
  }
28080
28732
 
28081
- // dist/inventory/parsers/listeners.js
28082
- var CONTAINER_PLUMBING = /* @__PURE__ */ new Set(["docker-proxy", "containerd-shim", "rootlesskit"]);
28083
- function classifyIpv4(address) {
28084
- if (address === "0.0.0.0")
28085
- return "public";
28086
- if (address.startsWith("127."))
28087
- return "loopback";
28088
- if (address.startsWith("10."))
28089
- return "private";
28090
- if (address.startsWith("192.168."))
28091
- return "private";
28092
- if (address.startsWith("169.254."))
28093
- return "private";
28094
- if (address.startsWith("172.")) {
28095
- const second = Number(address.split(".")[1]);
28096
- if (Number.isInteger(second) && second >= 16 && second <= 31)
28097
- return "private";
28098
- return "public";
28099
- }
28100
- if (address.startsWith("100.")) {
28101
- const second = Number(address.split(".")[1]);
28102
- if (Number.isInteger(second) && second >= 64 && second <= 127)
28103
- return "private";
28104
- return "public";
28105
- }
28106
- return "public";
28107
- }
28108
- function classifyBind(address) {
28109
- if (typeof address !== "string")
28110
- return "public";
28111
- const raw = address.trim();
28112
- if (raw === "" || raw === "*")
28113
- return "public";
28114
- const percent = raw.indexOf("%");
28115
- const addr = percent < 0 ? raw : raw.slice(0, percent);
28116
- if (addr.includes(":")) {
28117
- const lower = addr.toLowerCase();
28118
- if (lower === "::")
28119
- return "public";
28120
- if (lower === "::1")
28121
- return "loopback";
28122
- const mapped = /^::ffff:(\d+\.\d+\.\d+\.\d+)$/.exec(lower);
28123
- if (mapped)
28124
- return classifyIpv4(mapped[1] ?? "");
28125
- if (/^fe[89ab]/.test(lower))
28126
- return "private";
28127
- if (/^f[cd]/.test(lower))
28128
- return "private";
28129
- return "public";
28130
- }
28131
- return classifyIpv4(addr);
28132
- }
28133
- function splitAddrPort(field) {
28134
- let address;
28135
- let portText2;
28136
- if (field.startsWith("[")) {
28137
- const close = field.indexOf("]");
28138
- if (close < 0)
28139
- return void 0;
28140
- address = field.slice(1, close);
28141
- const rest = field.slice(close + 1);
28142
- if (!rest.startsWith(":"))
28143
- return void 0;
28144
- portText2 = rest.slice(1);
28145
- } else {
28146
- const colon = field.lastIndexOf(":");
28147
- if (colon < 0)
28148
- return void 0;
28149
- address = field.slice(0, colon);
28150
- portText2 = field.slice(colon + 1);
28151
- }
28152
- const port = Number(portText2);
28153
- if (!Number.isInteger(port) || port < 1 || port > 65535)
28154
- return void 0;
28155
- return { address, port };
28156
- }
28157
- function parseUsers(users) {
28158
- if (typeof users !== "string" || users === "")
28159
- return { pids: [], process: null };
28160
- const pids = [];
28161
- const pidRe = /pid=(\d+)/g;
28162
- let match;
28163
- while ((match = pidRe.exec(users)) !== null) {
28164
- const pid = Number(match[1]);
28165
- if (Number.isInteger(pid) && pid > 0 && !pids.includes(pid))
28166
- pids.push(pid);
28167
- }
28168
- const name3 = /"([^"]*)"/.exec(users);
28169
- return { pids, process: name3 && name3[1] ? name3[1] : null };
28170
- }
28171
- function parseSsLine(line) {
28172
- const parts = line.split(/\s+/);
28173
- if (parts.length < 5)
28174
- return void 0;
28175
- const proto = parts[0] === "tcp" ? "tcp" : parts[0] === "udp" ? "udp" : void 0;
28176
- if (!proto)
28177
- return void 0;
28178
- const local = splitAddrPort(parts[4] ?? "");
28179
- if (!local)
28180
- return void 0;
28181
- const { pids, process: process2 } = parseUsers(parts.slice(6).join(" "));
28182
- return { proto, port: local.port, bind: classifyBind(local.address), pids, process: process2 };
28183
- }
28184
- function parseSsListeners(stdout) {
28185
- if (typeof stdout !== "string")
28186
- return [];
28187
- const out = [];
28188
- for (const raw of stdout.split(/\r?\n/)) {
28189
- const line = raw.trim();
28190
- if (line === "")
28191
- continue;
28192
- const record2 = parseSsLine(line);
28193
- if (record2)
28194
- out.push(record2);
28195
- }
28196
- return out;
28197
- }
28198
- function parseDpkgSearch(stdout) {
28199
- const map2 = /* @__PURE__ */ new Map();
28200
- if (typeof stdout !== "string")
28201
- return map2;
28202
- for (const raw of stdout.split(/\r?\n/)) {
28203
- const line = raw.trim();
28204
- if (line === "")
28205
- continue;
28206
- const sep3 = line.indexOf(": ");
28207
- if (sep3 < 0)
28208
- continue;
28209
- const pkg = line.slice(0, sep3);
28210
- const path = line.slice(sep3 + 2).trim();
28211
- if (!/^[a-z0-9][a-z0-9+.:~-]*$/.test(pkg) || !path.startsWith("/"))
28212
- continue;
28213
- const name3 = pkg.split(":")[0] ?? "";
28214
- if (name3 === "")
28215
- continue;
28216
- if (!map2.has(path))
28217
- map2.set(path, name3);
28218
- }
28219
- return map2;
28220
- }
28221
- function publishedHostPorts(ports) {
28222
- const set2 = /* @__PURE__ */ new Set();
28223
- if (!Array.isArray(ports))
28224
- return set2;
28225
- for (const entry of ports) {
28226
- const arrow = entry.indexOf("->");
28227
- const host = arrow < 0 ? entry : entry.slice(0, arrow);
28228
- const colon = host.lastIndexOf(":");
28229
- const portText2 = colon < 0 ? "" : host.slice(colon + 1);
28230
- const port = Number(portText2);
28231
- if (Number.isInteger(port) && port >= 1 && port <= 65535)
28232
- set2.add(port);
28233
- }
28234
- return set2;
28235
- }
28236
- function processNameOf(name3) {
28237
- if (typeof name3 !== "string")
28238
- return null;
28239
- const base2 = name3.split("/").at(-1) ?? name3;
28240
- const trimmed = base2.trim();
28241
- if (trimmed === "")
28242
- return null;
28243
- return trimmed.length <= 64 ? trimmed : trimmed.slice(0, 64).trimEnd();
28244
- }
28245
- function ownerOf(listener, exeByPid, packageByPath, containerByPort) {
28246
- const name3 = processNameOf(listener.process);
28247
- if (name3 !== null && CONTAINER_PLUMBING.has(name3)) {
28248
- const containerId = containerByPort.get(listener.port);
28249
- if (containerId)
28250
- return { kind: "container", container_id: containerId };
28251
- return { kind: "process", name: name3 };
28252
- }
28253
- for (const pid of listener.pids) {
28254
- const exe = exeByPid.get(pid);
28255
- if (exe === void 0)
28256
- continue;
28257
- const pkg = packageByPath.get(exe);
28258
- if (pkg !== void 0)
28259
- return { kind: "package", name: pkg };
28260
- }
28261
- if (name3 !== null)
28262
- return { kind: "process", name: name3 };
28263
- return null;
28264
- }
28265
- function resolveListenerOwners(listeners, exeByPid, packageByPath, containers) {
28266
- if (!Array.isArray(listeners))
28267
- return [];
28268
- const containerByPort = /* @__PURE__ */ new Map();
28269
- if (Array.isArray(containers)) {
28270
- for (const container of containers) {
28271
- for (const port of publishedHostPorts(container.ports)) {
28272
- if (!containerByPort.has(port))
28273
- containerByPort.set(port, container.id);
28274
- }
28275
- }
28276
- }
28277
- const out = [];
28278
- const seen = /* @__PURE__ */ new Set();
28279
- for (const listener of listeners) {
28280
- const owner = ownerOf(listener, exeByPid, packageByPath, containerByPort);
28281
- const item = { proto: listener.proto, port: listener.port, bind: listener.bind, owner };
28282
- const key = `${item.proto}\0${item.port}\0${item.bind}\0${JSON.stringify(item.owner)}`;
28283
- if (seen.has(key))
28284
- continue;
28285
- seen.add(key);
28286
- out.push(item);
28287
- }
28288
- return out;
28289
- }
28290
-
28291
28733
  // dist/inventory/collector.js
28292
28734
  var POSIX_PATH = ["/usr/local/sbin", "/usr/local/bin", "/usr/sbin", "/usr/bin", "/sbin", "/bin", "/opt/homebrew/bin", "/opt/homebrew/sbin", "/snap/bin"];
28293
28735
  var DENIED = /permission denied|EACCES|access is denied|got permission denied while trying to connect/i;
@@ -28298,8 +28740,8 @@ function collectorEnv(env = process.env, platform2 = process.platform) {
28298
28740
  const path = [.../* @__PURE__ */ new Set([...(env.PATH ?? "").split(":").filter(Boolean), ...POSIX_PATH])].join(":");
28299
28741
  return platform2 === "linux" ? { ...base2, PATH: path, LC_ALL: "C.UTF-8", LANGUAGE: "" } : { ...base2, PATH: path };
28300
28742
  }
28301
- var defaultRunner = (file2, args, { timeoutMs, maxBytes }) => new Promise((resolve9) => {
28302
- (0, import_node_child_process8.execFile)(file2, [...args], {
28743
+ var defaultRunner = (file2, args, { timeoutMs, maxBytes }) => new Promise((resolve10) => {
28744
+ (0, import_node_child_process9.execFile)(file2, [...args], {
28303
28745
  timeout: timeoutMs,
28304
28746
  maxBuffer: maxBytes,
28305
28747
  killSignal: "SIGKILL",
@@ -28310,7 +28752,7 @@ var defaultRunner = (file2, args, { timeoutMs, maxBytes }) => new Promise((resol
28310
28752
  const code = error63?.code;
28311
28753
  const killed = error63?.killed === true;
28312
28754
  const out = String(stdout ?? ""), err = String(stderr ?? "");
28313
- resolve9({
28755
+ resolve10({
28314
28756
  stdout: out,
28315
28757
  stderr: err,
28316
28758
  ok: !error63,
@@ -28320,13 +28762,13 @@ var defaultRunner = (file2, args, { timeoutMs, maxBytes }) => new Promise((resol
28320
28762
  });
28321
28763
  });
28322
28764
  });
28323
- var defaultReader = async (path) => (0, import_promises13.readFile)(path, "utf8").catch(() => null);
28765
+ var defaultReader = async (path) => (0, import_promises14.readFile)(path, "utf8").catch(() => null);
28324
28766
  async function findExecutablesOnPath(name3, path = collectorEnv().PATH ?? "") {
28325
28767
  const found = [];
28326
28768
  for (const dir of path.split(":").filter((entry) => entry.startsWith("/"))) {
28327
28769
  try {
28328
- const real = await (0, import_promises13.realpath)(`${dir}/${name3}`);
28329
- await (0, import_promises13.access)(real, import_node_fs3.constants.X_OK);
28770
+ const real = await (0, import_promises14.realpath)(`${dir}/${name3}`);
28771
+ await (0, import_promises14.access)(real, import_node_fs3.constants.X_OK);
28330
28772
  if (!found.includes(real))
28331
28773
  found.push(real);
28332
28774
  } catch {
@@ -28334,7 +28776,7 @@ async function findExecutablesOnPath(name3, path = collectorEnv().PATH ?? "") {
28334
28776
  }
28335
28777
  return found;
28336
28778
  }
28337
- function installOf(real, home = (0, import_node_os5.homedir)()) {
28779
+ function installOf(real, home = (0, import_node_os6.homedir)()) {
28338
28780
  if (/^\/(opt\/homebrew|usr\/local\/Cellar|home\/linuxbrew\/\.linuxbrew)\//.test(real))
28339
28781
  return "homebrew";
28340
28782
  if (/^\/(usr\/(bin|sbin|lib|libexec|share)|bin|sbin|snap)\//.test(real))
@@ -28348,7 +28790,7 @@ function installOf(real, home = (0, import_node_os5.homedir)()) {
28348
28790
  async function readFileTail(path, bytes3) {
28349
28791
  let handle = null;
28350
28792
  try {
28351
- handle = await (0, import_promises13.open)(path, "r");
28793
+ handle = await (0, import_promises14.open)(path, "r");
28352
28794
  const { size } = await handle.stat();
28353
28795
  const length = Math.min(size, bytes3);
28354
28796
  const buffer = Buffer.alloc(length);
@@ -28363,11 +28805,11 @@ async function readFileTail(path, bytes3) {
28363
28805
  }
28364
28806
  async function listDirFiles(path, dirs = false) {
28365
28807
  try {
28366
- const entries = await (0, import_promises13.readdir)(path, { withFileTypes: true });
28808
+ const entries = await (0, import_promises14.readdir)(path, { withFileTypes: true });
28367
28809
  const files = [];
28368
28810
  for (const entry of entries.filter((item) => dirs ? item.isDirectory() : item.isFile()).slice(0, 2e3)) {
28369
28811
  try {
28370
- files.push({ name: entry.name, mtimeMs: (await (0, import_promises13.stat)(`${path}/${entry.name}`)).mtimeMs });
28812
+ files.push({ name: entry.name, mtimeMs: (await (0, import_promises14.stat)(`${path}/${entry.name}`)).mtimeMs });
28371
28813
  } catch {
28372
28814
  }
28373
28815
  }
@@ -28377,9 +28819,9 @@ async function listDirFiles(path, dirs = false) {
28377
28819
  }
28378
28820
  }
28379
28821
  var defaultCollectorSystem = {
28380
- platform: (0, import_node_os5.platform)(),
28381
- arch: (0, import_node_os5.arch)(),
28382
- kernel: (0, import_node_os5.release)(),
28822
+ platform: (0, import_node_os6.platform)(),
28823
+ arch: (0, import_node_os6.arch)(),
28824
+ kernel: (0, import_node_os6.release)(),
28383
28825
  run: defaultRunner,
28384
28826
  readText: defaultReader,
28385
28827
  now: () => /* @__PURE__ */ new Date(),
@@ -28389,12 +28831,12 @@ var defaultCollectorSystem = {
28389
28831
  isRoot: typeof process.getuid === "function" ? process.getuid() === 0 : false,
28390
28832
  resolveExe: async (pid) => {
28391
28833
  try {
28392
- return await (0, import_promises13.realpath)(`/proc/${pid}/exe`);
28834
+ return await (0, import_promises14.realpath)(`/proc/${pid}/exe`);
28393
28835
  } catch {
28394
28836
  return null;
28395
28837
  }
28396
28838
  },
28397
- ...(0, import_node_os5.platform)() === "win32" ? {} : { findExecutables: (name3) => findExecutablesOnPath(name3) }
28839
+ ...(0, import_node_os6.platform)() === "win32" ? {} : { findExecutables: (name3) => findExecutablesOnPath(name3) }
28398
28840
  };
28399
28841
  var SHORT = { timeoutMs: 1e4, maxBytes: 2 * 1024 * 1024 };
28400
28842
  var LIST = { timeoutMs: 45e3, maxBytes: 48 * 1024 * 1024 };
@@ -28908,7 +29350,7 @@ async function collectHealth(c) {
28908
29350
  if (jobs !== null)
28909
29351
  c.health.push(...parseLaunchctlList(jobs));
28910
29352
  if (c.system.listDir) {
28911
- const files = [...await c.system.listDir("/Library/Logs/DiagnosticReports") ?? [], ...await c.system.listDir(`${(0, import_node_os5.homedir)()}/Library/Logs/DiagnosticReports`) ?? []];
29353
+ const files = [...await c.system.listDir("/Library/Logs/DiagnosticReports") ?? [], ...await c.system.listDir(`${(0, import_node_os6.homedir)()}/Library/Logs/DiagnosticReports`) ?? []];
28912
29354
  c.health.push(...crashReportEvents(files, now));
28913
29355
  c.cover("health-crash-reports", "ok", files.length, Date.now() - started);
28914
29356
  }
@@ -29267,10 +29709,10 @@ var SshExecutor = class {
29267
29709
  };
29268
29710
 
29269
29711
  // dist/shell/executor.js
29270
- var import_node_child_process10 = require("node:child_process");
29271
- var import_promises15 = require("node:fs/promises");
29272
- var import_node_os7 = require("node:os");
29273
- var import_node_path16 = require("node:path");
29712
+ var import_node_child_process11 = require("node:child_process");
29713
+ var import_promises16 = require("node:fs/promises");
29714
+ var import_node_os8 = require("node:os");
29715
+ var import_node_path17 = require("node:path");
29274
29716
 
29275
29717
  // dist/shell/output.js
29276
29718
  var OutputBuffer = class {
@@ -29350,18 +29792,18 @@ function trimIncompleteUtf8(bytes3) {
29350
29792
  }
29351
29793
 
29352
29794
  // dist/shell/system.js
29353
- var import_node_child_process9 = require("node:child_process");
29354
- var import_promises14 = require("node:fs/promises");
29355
- var import_node_os6 = require("node:os");
29356
- var import_node_path15 = require("node:path");
29795
+ var import_node_child_process10 = require("node:child_process");
29796
+ var import_promises15 = require("node:fs/promises");
29797
+ var import_node_os7 = require("node:os");
29798
+ var import_node_path16 = require("node:path");
29357
29799
  function windowsTool(env, ...parts) {
29358
- return import_node_path15.win32.join(env.SystemRoot ?? env.windir ?? "C:\\Windows", "System32", ...parts);
29800
+ return import_node_path16.win32.join(env.SystemRoot ?? env.windir ?? "C:\\Windows", "System32", ...parts);
29359
29801
  }
29360
29802
  var POWERSHELL_PREFIX = "[Console]::OutputEncoding = [System.Text.Encoding]::UTF8; $ProgressPreference = 'SilentlyContinue'; ";
29361
29803
  function userShell(env = process.env) {
29362
29804
  let shell = null;
29363
29805
  try {
29364
- shell = (0, import_node_os6.userInfo)().shell;
29806
+ shell = (0, import_node_os7.userInfo)().shell;
29365
29807
  } catch {
29366
29808
  shell = null;
29367
29809
  }
@@ -29397,8 +29839,8 @@ function commandEnv(env = process.env, taskId2) {
29397
29839
  ...taskId2 ? { CONBRIDGE_TASK_ID: taskId2 } : {}
29398
29840
  };
29399
29841
  }
29400
- var run = (file2, args) => new Promise((resolve9) => {
29401
- (0, import_node_child_process9.execFile)(file2, [...args], { windowsHide: true, maxBuffer: 16 * 1024 * 1024, timeout: 2e4 }, (error63, stdout) => resolve9({ ok: !error63, stdout: String(stdout) }));
29842
+ var run = (file2, args) => new Promise((resolve10) => {
29843
+ (0, import_node_child_process10.execFile)(file2, [...args], { windowsHide: true, maxBuffer: 16 * 1024 * 1024, timeout: 2e4 }, (error63, stdout) => resolve10({ ok: !error63, stdout: String(stdout) }));
29402
29844
  });
29403
29845
  function parsePs(text6) {
29404
29846
  const entries = [];
@@ -29473,39 +29915,39 @@ async function listProcesses(options) {
29473
29915
  return { processes: matching.slice(0, options.limit), total: matching.length, truncated: matching.length > options.limit };
29474
29916
  }
29475
29917
  async function systemInfo() {
29476
- const cores = (0, import_node_os6.cpus)();
29918
+ const cores = (0, import_node_os7.cpus)();
29477
29919
  const disk = async (path) => {
29478
29920
  try {
29479
- const info = await (0, import_promises14.statfs)(path);
29921
+ const info = await (0, import_promises15.statfs)(path);
29480
29922
  return { path, total_bytes: info.blocks * info.bsize, free_bytes: info.bavail * info.bsize };
29481
29923
  } catch {
29482
29924
  return null;
29483
29925
  }
29484
29926
  };
29485
- const home = (0, import_node_os6.homedir)();
29486
- const disks = (await Promise.all([disk((0, import_node_os6.platform)() === "win32" ? home.slice(0, 3) || "C:\\" : "/"), disk(home)])).filter((entry) => entry !== null);
29927
+ const home = (0, import_node_os7.homedir)();
29928
+ const disks = (await Promise.all([disk((0, import_node_os7.platform)() === "win32" ? home.slice(0, 3) || "C:\\" : "/"), disk(home)])).filter((entry) => entry !== null);
29487
29929
  let user = null;
29488
29930
  try {
29489
- user = (0, import_node_os6.userInfo)().username;
29931
+ user = (0, import_node_os7.userInfo)().username;
29490
29932
  } catch {
29491
29933
  user = null;
29492
29934
  }
29493
29935
  return {
29494
- hostname: (0, import_node_os6.hostname)(),
29495
- platform: (0, import_node_os6.platform)(),
29496
- os_version: (0, import_node_os6.version)(),
29497
- release: (0, import_node_os6.release)(),
29498
- arch: (0, import_node_os6.arch)(),
29499
- uptime_s: Math.round((0, import_node_os6.uptime)()),
29936
+ hostname: (0, import_node_os7.hostname)(),
29937
+ platform: (0, import_node_os7.platform)(),
29938
+ os_version: (0, import_node_os7.version)(),
29939
+ release: (0, import_node_os7.release)(),
29940
+ arch: (0, import_node_os7.arch)(),
29941
+ uptime_s: Math.round((0, import_node_os7.uptime)()),
29500
29942
  cpu_model: cores[0]?.model ?? null,
29501
29943
  cpu_count: cores.length,
29502
- load_average: (0, import_node_os6.platform)() === "win32" ? null : (0, import_node_os6.loadavg)().map((value) => Math.round(value * 100) / 100),
29503
- memory_total_bytes: (0, import_node_os6.totalmem)(),
29504
- memory_free_bytes: (0, import_node_os6.freemem)(),
29944
+ load_average: (0, import_node_os7.platform)() === "win32" ? null : (0, import_node_os7.loadavg)().map((value) => Math.round(value * 100) / 100),
29945
+ memory_total_bytes: (0, import_node_os7.totalmem)(),
29946
+ memory_free_bytes: (0, import_node_os7.freemem)(),
29505
29947
  disks,
29506
29948
  user,
29507
29949
  home,
29508
- shell: (0, import_node_os6.platform)() === "win32" ? "powershell" : userShell(),
29950
+ shell: (0, import_node_os7.platform)() === "win32" ? "powershell" : userShell(),
29509
29951
  node_version: process.versions.node,
29510
29952
  agent_version: AGENT_VERSION
29511
29953
  };
@@ -29521,12 +29963,12 @@ var KILL_GRACE_MS = 3e3;
29521
29963
  function failure3(code, reason, message, executed = false, extra = {}) {
29522
29964
  return { result: { state: "FAILED", executed, safe_message: message.slice(0, 256), output_excerpt: excerpt({ error: code, reason, message, ...extra }) } };
29523
29965
  }
29524
- function resolveCwd(input2, home = (0, import_node_os7.homedir)()) {
29966
+ function resolveCwd(input2, home = (0, import_node_os8.homedir)()) {
29525
29967
  if (input2 === void 0 || input2 === "~")
29526
29968
  return home;
29527
29969
  if (input2.startsWith("~/") || input2.startsWith("~\\"))
29528
- return (0, import_node_path16.join)(home, input2.slice(2));
29529
- return (0, import_node_path16.isAbsolute)(input2) ? (0, import_node_path16.resolve)(input2) : null;
29970
+ return (0, import_node_path17.join)(home, input2.slice(2));
29971
+ return (0, import_node_path17.isAbsolute)(input2) ? (0, import_node_path17.resolve)(input2) : null;
29530
29972
  }
29531
29973
  var ShellExecutor = class {
29532
29974
  #options;
@@ -29639,7 +30081,7 @@ var ShellExecutor = class {
29639
30081
  const cwd = resolveCwd(payload.cwd);
29640
30082
  if (cwd === null)
29641
30083
  return failure3("INVALID_MESSAGE", "CWD_INVALID", "cwd must be an absolute directory or start with ~");
29642
- const isDirectory = await (0, import_promises15.stat)(cwd).then((info) => info.isDirectory(), () => false);
30084
+ const isDirectory = await (0, import_promises16.stat)(cwd).then((info) => info.isDirectory(), () => false);
29643
30085
  if (!isDirectory)
29644
30086
  return failure3("NOT_FOUND", "CWD_NOT_FOUND", `Directory not found: ${cwd}`);
29645
30087
  if (this.runningCount >= MAX_RUNNING_COMMANDS) {
@@ -29654,7 +30096,7 @@ var ShellExecutor = class {
29654
30096
  const windows = (this.#options.platform ?? process.platform) === "win32";
29655
30097
  let child;
29656
30098
  try {
29657
- child = (0, import_node_child_process10.spawn)(launch.file, [...launch.args], {
30099
+ child = (0, import_node_child_process11.spawn)(launch.file, [...launch.args], {
29658
30100
  cwd,
29659
30101
  env: commandEnv(this.#options.env ?? process.env, context.taskId),
29660
30102
  windowsHide: true,
@@ -29765,7 +30207,7 @@ var ShellExecutor = class {
29765
30207
  const signal = (name3) => {
29766
30208
  try {
29767
30209
  if (windows) {
29768
- (0, import_node_child_process10.spawn)("taskkill", ["/PID", String(child.pid), "/T", "/F"], { windowsHide: true, stdio: "ignore" }).on("error", () => child.kill());
30210
+ (0, import_node_child_process11.spawn)("taskkill", ["/PID", String(child.pid), "/T", "/F"], { windowsHide: true, stdio: "ignore" }).on("error", () => child.kill());
29769
30211
  } else if (child.pid !== void 0) {
29770
30212
  process.kill(-child.pid, name3);
29771
30213
  }
@@ -29810,13 +30252,13 @@ var ShellExecutor = class {
29810
30252
  function shellResource(config2, platform2 = process.platform) {
29811
30253
  if (config2.full_access !== true)
29812
30254
  return null;
29813
- return { resource_id: SHELL_RESOURCE_ID, kind: SHELL_RESOURCE_KIND, label: `Terminal on ${(0, import_node_os8.hostname)().slice(0, 100)}`, attrs: { platform: platform2, arch: (0, import_node_os8.arch)() } };
30255
+ return { resource_id: SHELL_RESOURCE_ID, kind: SHELL_RESOURCE_KIND, label: `Terminal on ${(0, import_node_os9.hostname)().slice(0, 100)}`, attrs: { platform: platform2, arch: (0, import_node_os9.arch)() } };
29814
30256
  }
29815
30257
  var WATCH_INTERVAL_MS = 5e3;
29816
30258
  var RESUME_GAP_MS = 3e4;
29817
30259
  function networkFingerprint() {
29818
30260
  const parts = [];
29819
- for (const [name3, addresses] of Object.entries((0, import_node_os8.networkInterfaces)())) {
30261
+ for (const [name3, addresses] of Object.entries((0, import_node_os9.networkInterfaces)())) {
29820
30262
  for (const address of addresses ?? [])
29821
30263
  if (!address.internal)
29822
30264
  parts.push(`${name3}/${address.address}`);
@@ -30055,11 +30497,11 @@ var AgentRunner = class {
30055
30497
  #wait(ms) {
30056
30498
  const controller = new AbortController();
30057
30499
  this.#sleep = controller;
30058
- return new Promise((resolve9) => {
30059
- const timer = setTimeout(resolve9, ms);
30500
+ return new Promise((resolve10) => {
30501
+ const timer = setTimeout(resolve10, ms);
30060
30502
  controller.signal.addEventListener("abort", () => {
30061
30503
  clearTimeout(timer);
30062
- resolve9();
30504
+ resolve10();
30063
30505
  }, { once: true });
30064
30506
  });
30065
30507
  }
@@ -30068,7 +30510,13 @@ var AgentRunner = class {
30068
30510
  return;
30069
30511
  if (this.#lifecycleTimer)
30070
30512
  clearTimeout(this.#lifecycleTimer);
30071
- Object.assign(this.#options.identity, body);
30513
+ const identity = this.#options.identity;
30514
+ const ends = (mode) => mode === "timed" || mode === "ephemeral";
30515
+ const localEnd = ends(identity.connection_mode) && typeof identity.expires_at_ms === "number" ? identity.expires_at_ms : null;
30516
+ if (localEnd !== null && (!ends(body.connection_mode) || body.expires_at_ms === null || body.expires_at_ms > localEnd)) {
30517
+ Object.assign(identity, { ...body, connection_mode: ends(body.connection_mode) ? body.connection_mode : identity.connection_mode, expires_at_ms: localEnd });
30518
+ } else
30519
+ Object.assign(identity, body);
30072
30520
  if (body.destroy_deadline_ms === null) {
30073
30521
  this.#destroyDispatch = null;
30074
30522
  this.#options.identity.destroy_task_id = null;
@@ -30190,7 +30638,7 @@ var AgentRunner = class {
30190
30638
  onInventoryRequest: (requestId) => inventory2.request(requestId)
30191
30639
  });
30192
30640
  this.#session = session;
30193
- return new Promise((resolve9) => {
30641
+ return new Promise((resolve10) => {
30194
30642
  let settled = false;
30195
30643
  const end = (code) => {
30196
30644
  if (settled)
@@ -30209,7 +30657,7 @@ var AgentRunner = class {
30209
30657
  if (this.#endConnection === end)
30210
30658
  this.#endConnection = null;
30211
30659
  this.#logger.info("relay closed", { code });
30212
- resolve9(ready);
30660
+ resolve10(ready);
30213
30661
  };
30214
30662
  this.#endConnection = end;
30215
30663
  const authTimer = setTimeout(() => {
@@ -30251,7 +30699,7 @@ var AgentRunner = class {
30251
30699
 
30252
30700
  // dist/ssh/cli.js
30253
30701
  var import_node_util = require("node:util");
30254
- var import_node_path17 = require("node:path");
30702
+ var import_node_path18 = require("node:path");
30255
30703
  var SshUsageError = class extends Error {
30256
30704
  };
30257
30705
  var SSH_USAGE = ` conbridge-agent ssh add <alias> --host <host> [--port <n>] [--user <name>] [--identity <path>] [--production] [--confirm-fingerprint <SHA256:...>]
@@ -30308,7 +30756,7 @@ async function cmdSsh(stateDir, args, io) {
30308
30756
  host: values.host,
30309
30757
  port: parsePort(values.port),
30310
30758
  user: values.user,
30311
- identity: values.identity === void 0 ? void 0 : (0, import_node_path17.resolve)(values.identity),
30759
+ identity: values.identity === void 0 ? void 0 : (0, import_node_path18.resolve)(values.identity),
30312
30760
  production: values.production === true
30313
30761
  };
30314
30762
  await validateNewHost(input2);
@@ -30425,10 +30873,22 @@ function cliPath() {
30425
30873
  return (0, import_node_url3.fileURLToPath)(__conbridge_import_meta_url);
30426
30874
  }
30427
30875
  function lockPath(paths) {
30428
- return (0, import_node_path18.join)(paths.dir, "agent.lock");
30876
+ return (0, import_node_path19.join)(paths.dir, "agent.lock");
30877
+ }
30878
+ async function installLauncherAndPath(paths, io) {
30879
+ try {
30880
+ await installLauncher({ home: homeFromEnv(io.env), platform: process.platform, stateDir: paths.dir, nodePath: process.execPath });
30881
+ await ensurePathEntry({ home: homeFromEnv(io.env), platform: process.platform, env: io.env });
30882
+ } catch (error63) {
30883
+ io.err(`Warning: could not put conbridge-agent on PATH (${errorMessage(error63)}). Use: npx --yes conbridge-agent@latest <command>`);
30884
+ }
30885
+ }
30886
+ function printAgentCommand(io, command2) {
30887
+ for (const line of agentCommandLines({ home: homeFromEnv(io.env), platform: process.platform, command: command2 }))
30888
+ io.out(line);
30429
30889
  }
30430
30890
  async function exists2(path) {
30431
- return (0, import_promises17.access)(path).then(() => true, () => false);
30891
+ return (0, import_promises18.access)(path).then(() => true, () => false);
30432
30892
  }
30433
30893
  async function runInstalledCopy(paths, argv, io, keepsIdentity = true) {
30434
30894
  if (!runningFromNpm() || await runningFromRuntime(paths.dir))
@@ -30444,7 +30904,8 @@ async function runInstalledCopy(paths, argv, io, keepsIdentity = true) {
30444
30904
  let status;
30445
30905
  try {
30446
30906
  const { entry } = await installRuntime(paths.dir);
30447
- const child = (0, import_node_child_process11.spawnSync)(process.execPath, [entry, ...argv], { stdio: "inherit", env: io.env });
30907
+ await installLauncherAndPath(paths, io);
30908
+ const child = (0, import_node_child_process12.spawnSync)(process.execPath, [entry, ...argv], { stdio: "inherit", env: io.env });
30448
30909
  if (child.error)
30449
30910
  throw child.error;
30450
30911
  status = child.status ?? 1;
@@ -30488,12 +30949,12 @@ async function newKeyStore(paths, values, env) {
30488
30949
  throw new UsageError("--keychain only applies to the keychain key store");
30489
30950
  return new FileKeyStore(pendingKeyPath(paths));
30490
30951
  }
30491
- if (values.keychain !== void 0 && !(0, import_node_path18.isAbsolute)(values.keychain))
30952
+ if (values.keychain !== void 0 && !(0, import_node_path19.isAbsolute)(values.keychain))
30492
30953
  throw new UsageError("--keychain needs an absolute path");
30493
30954
  return new KeychainKeyStore({
30494
30955
  helperPath: helper,
30495
30956
  keyId: (0, import_node_crypto12.randomUUID)(),
30496
- ...values.keychain !== void 0 ? { keychainPath: (0, import_node_path18.resolve)(values.keychain) } : {}
30957
+ ...values.keychain !== void 0 ? { keychainPath: (0, import_node_path19.resolve)(values.keychain) } : {}
30497
30958
  });
30498
30959
  }
30499
30960
  async function discardOldKey(paths, identity, env) {
@@ -30523,7 +30984,7 @@ async function cmdPair(paths, args, io) {
30523
30984
  if (installed !== null)
30524
30985
  return installed;
30525
30986
  const gateway = values.gateway ?? DEFAULT_GATEWAY_URL;
30526
- const name3 = (values.name ?? (0, import_node_os9.hostname)()).trim().slice(0, 64) || "My computer";
30987
+ const name3 = (values.name ?? (0, import_node_os10.hostname)()).trim().slice(0, 64) || "My computer";
30527
30988
  const keyStore = await newKeyStore(paths, values, io.env);
30528
30989
  const previous = await loadIdentity(paths);
30529
30990
  if (previous && !values.force)
@@ -30542,7 +31003,7 @@ async function cmdPair(paths, args, io) {
30542
31003
  },
30543
31004
  onApproved: async () => {
30544
31005
  if (keyStore.descriptor.type === "file")
30545
- await (0, import_promises17.rename)(pendingKeyPath(paths), paths.key);
31006
+ await (0, import_promises18.rename)(pendingKeyPath(paths), paths.key);
30546
31007
  }
30547
31008
  });
30548
31009
  if (previous && !(keyStore.descriptor.type === "file" && previous.key_store?.type !== "keychain"))
@@ -30554,7 +31015,10 @@ async function cmdPair(paths, args, io) {
30554
31015
  await removeAgentAutostart(paths.dir, lifecycleDeps(io));
30555
31016
  await stopSupervisor(paths);
30556
31017
  await stopAgentProcess(paths);
30557
- return cmdRun(paths, [], io, "foreground");
31018
+ const code = await cmdRun(paths, [], io, "foreground");
31019
+ io.out("On demand session ended. To connect again:");
31020
+ printAgentCommand(io, "start");
31021
+ return code;
30558
31022
  }
30559
31023
  if (values["no-service"]) {
30560
31024
  io.out("Next: conbridge-agent roots add <path> --label <label> [--writable], then conbridge-agent run (or service install)");
@@ -30713,6 +31177,10 @@ async function cmdRun(paths, args, io, session = "service") {
30713
31177
  });
30714
31178
  logger.info("agent starting", { device_uuid: identity.device_uuid, gateway: identity.gateway_url, version: AGENT_VERSION });
30715
31179
  io.out(`ConBridge agent running for device ${identity.device_uuid}. Press Ctrl+C to stop.`);
31180
+ if (session === "foreground") {
31181
+ io.out("To connect again later:");
31182
+ printAgentCommand(io, "start");
31183
+ }
30716
31184
  try {
30717
31185
  await runner.run();
30718
31186
  } finally {
@@ -30877,18 +31345,18 @@ function serviceLogPath(env) {
30877
31345
  return defaultLogPath();
30878
31346
  }
30879
31347
  function supervisorPidPath(paths) {
30880
- return (0, import_node_path18.join)(paths.dir, "supervisor.pid");
31348
+ return (0, import_node_path19.join)(paths.dir, "supervisor.pid");
30881
31349
  }
30882
31350
  function startSupervisorNow(command2, logPath, env) {
30883
31351
  const [file2, ...args] = programArguments(command2);
30884
- void (0, import_promises17.open)(logPath, "a", 384).then((log) => {
30885
- const child = (0, import_node_child_process11.spawn)(file2, [...args.slice(0, -1), "supervise"], { detached: true, stdio: ["ignore", log.fd, log.fd], env });
31352
+ void (0, import_promises18.open)(logPath, "a", 384).then((log) => {
31353
+ const child = (0, import_node_child_process12.spawn)(file2, [...args.slice(0, -1), "supervise"], { detached: true, stdio: ["ignore", log.fd, log.fd], env });
30886
31354
  child.unref();
30887
31355
  void log.close();
30888
31356
  });
30889
31357
  }
30890
31358
  async function stopSupervisor(paths) {
30891
- const pid = Number.parseInt(await (0, import_promises17.readFile)(supervisorPidPath(paths), "utf8").catch(() => ""), 10);
31359
+ const pid = Number.parseInt(await (0, import_promises18.readFile)(supervisorPidPath(paths), "utf8").catch(() => ""), 10);
30892
31360
  if (Number.isInteger(pid) && pid > 1 && pid !== process.pid) {
30893
31361
  try {
30894
31362
  process.kill(pid, "SIGTERM");
@@ -30898,7 +31366,7 @@ async function stopSupervisor(paths) {
30898
31366
  }
30899
31367
  async function cmdSupervise(paths, io) {
30900
31368
  await ensureStateDir(paths.dir);
30901
- await (0, import_promises17.writeFile)(supervisorPidPath(paths), `${process.pid}
31369
+ await (0, import_promises18.writeFile)(supervisorPidPath(paths), `${process.pid}
30902
31370
  `, { mode: 384 });
30903
31371
  const command2 = await agentLaunchCommand({ sea: runningAsSea(), cliPath: cliPath() });
30904
31372
  const [file2, ...args] = programArguments(command2);
@@ -30912,18 +31380,18 @@ async function cmdSupervise(paths, io) {
30912
31380
  process.on("SIGINT", stop);
30913
31381
  try {
30914
31382
  while (!stopping) {
30915
- child = (0, import_node_child_process11.spawn)(file2, args, { stdio: "inherit", env: io.env });
30916
- const code = await new Promise((resolve9) => {
30917
- child.on("exit", (exitCode) => resolve9(exitCode));
30918
- child.on("error", () => resolve9(1));
31383
+ child = (0, import_node_child_process12.spawn)(file2, args, { stdio: "inherit", env: io.env });
31384
+ const code = await new Promise((resolve10) => {
31385
+ child.on("exit", (exitCode) => resolve10(exitCode));
31386
+ child.on("error", () => resolve10(1));
30919
31387
  });
30920
31388
  if (stopping || code === 0)
30921
31389
  break;
30922
31390
  io.err(`${(/* @__PURE__ */ new Date()).toISOString()} supervisor: agent exited with ${String(code)}; restarting in 10 s`);
30923
- await new Promise((resolve9) => setTimeout(resolve9, 1e4));
31391
+ await new Promise((resolve10) => setTimeout(resolve10, 1e4));
30924
31392
  }
30925
31393
  } finally {
30926
- await (0, import_promises17.unlink)(supervisorPidPath(paths)).catch(() => void 0);
31394
+ await (0, import_promises18.unlink)(supervisorPidPath(paths)).catch(() => void 0);
30927
31395
  }
30928
31396
  return 0;
30929
31397
  }
@@ -30945,8 +31413,8 @@ async function cmdAccess(paths, args, io) {
30945
31413
  const { values } = (0, import_node_util2.parseArgs)({ args: rest, allowPositionals: false, options: { "no-home": { type: "boolean" } } });
30946
31414
  await saveConfig(paths, { ...config2, full_access: true });
30947
31415
  if (!values["no-home"]) {
30948
- const home = io.env.HOME ?? (0, import_node_os9.homedir)();
30949
- const real = await (0, import_promises17.realpath)(home).catch(() => null);
31416
+ const home = io.env.HOME ?? (0, import_node_os10.homedir)();
31417
+ const real = await (0, import_promises18.realpath)(home).catch(() => null);
30950
31418
  const covered = config2.roots.some((root) => root.path === real);
30951
31419
  if (real && !covered) {
30952
31420
  const root = await addRoot(paths, { path: real, label: "Home", writable: true, allowBroadRoot: true, home });
@@ -30979,7 +31447,7 @@ async function cmdDoctor(paths, io) {
30979
31447
  const pid = await readLockPid(lockPath(paths));
30980
31448
  checks.push({ ok: pid !== null, label: "Agent running", detail: pid !== null ? `pid ${pid}` : "not running" });
30981
31449
  const config2 = await loadConfig(paths);
30982
- const roots = await Promise.all(config2.roots.map(async (root) => ({ root, ok: await (0, import_promises17.stat)(root.path).then((info) => info.isDirectory(), () => false) })));
31450
+ const roots = await Promise.all(config2.roots.map(async (root) => ({ root, ok: await (0, import_promises18.stat)(root.path).then((info) => info.isDirectory(), () => false) })));
30983
31451
  checks.push({
30984
31452
  ok: roots.every((entry) => entry.ok) ? roots.length > 0 ? true : null : false,
30985
31453
  label: "Shared folders",
@@ -30997,11 +31465,11 @@ async function cmdLogs(paths, args, io) {
30997
31465
  const service = await serviceLocation(paths.dir);
30998
31466
  if (process.platform === "linux" && service?.installed && service.location.endsWith(".service")) {
30999
31467
  const system = service.location.startsWith("/etc/");
31000
- const child = (0, import_node_child_process11.spawnSync)("journalctl", [...system ? [] : ["--user"], "-u", SYSTEMD_UNIT, "-n", String(lines4), ...values.follow ? ["-f"] : [], "--no-pager"], { stdio: "inherit" });
31468
+ const child = (0, import_node_child_process12.spawnSync)("journalctl", [...system ? [] : ["--user"], "-u", SYSTEMD_UNIT, "-n", String(lines4), ...values.follow ? ["-f"] : [], "--no-pager"], { stdio: "inherit" });
31001
31469
  return child.status ?? 1;
31002
31470
  }
31003
31471
  const logPath = serviceLogPath(io.env);
31004
- const text6 = await (0, import_promises17.readFile)(logPath, "utf8").catch(() => null);
31472
+ const text6 = await (0, import_promises18.readFile)(logPath, "utf8").catch(() => null);
31005
31473
  if (text6 === null) {
31006
31474
  io.err(`No log at ${logPath} yet.`);
31007
31475
  return 1;
@@ -31011,14 +31479,14 @@ async function cmdLogs(paths, args, io) {
31011
31479
  io.out(line);
31012
31480
  if (!values.follow)
31013
31481
  return 0;
31014
- let size = (await (0, import_promises17.stat)(logPath)).size;
31482
+ let size = (await (0, import_promises18.stat)(logPath)).size;
31015
31483
  for (; ; ) {
31016
- await new Promise((resolve9) => setTimeout(resolve9, 1e3));
31017
- const now = (await (0, import_promises17.stat)(logPath).catch(() => null))?.size ?? 0;
31484
+ await new Promise((resolve10) => setTimeout(resolve10, 1e3));
31485
+ const now = (await (0, import_promises18.stat)(logPath).catch(() => null))?.size ?? 0;
31018
31486
  if (now < size)
31019
31487
  size = 0;
31020
31488
  if (now > size) {
31021
- const handle = await (0, import_promises17.open)(logPath, "r");
31489
+ const handle = await (0, import_promises18.open)(logPath, "r");
31022
31490
  const buffer = Buffer.alloc(now - size);
31023
31491
  await handle.read(buffer, 0, buffer.length, size);
31024
31492
  await handle.close();
@@ -31034,19 +31502,19 @@ async function cmdUnpair(paths, io) {
31034
31502
  await stopAgentProcess(paths);
31035
31503
  if (identity)
31036
31504
  await discardOldKey(paths, identity, io.env);
31037
- await (0, import_promises17.unlink)(paths.identity).catch(() => void 0);
31505
+ await (0, import_promises18.unlink)(paths.identity).catch(() => void 0);
31038
31506
  io.out(identity ? `Removed the identity of "${identity.display_name}". Remove it in the ConBridge Console (Devices) as well; its key no longer exists here.` : "This computer was not paired.");
31039
31507
  return 0;
31040
31508
  }
31041
31509
  function lifecycleDeps(io) {
31042
- return { env: io.env, home: io.env.HOME ?? io.env.USERPROFILE ?? (0, import_node_os9.homedir)(), ...io.lifecycle?.purgeDeps };
31510
+ return { env: io.env, home: io.env.HOME ?? io.env.USERPROFILE ?? (0, import_node_os10.homedir)(), ...io.lifecycle?.purgeDeps };
31043
31511
  }
31044
31512
  async function cmdKill(paths, args, io) {
31045
31513
  const { values } = (0, import_node_util2.parseArgs)({ args, allowPositionals: false, options: { yes: { type: "boolean" }, "keep-runtime": { type: "boolean" } } });
31046
31514
  if (!values.yes) {
31047
31515
  if (!process.stdin.isTTY)
31048
31516
  throw new UsageError("Removal needs confirmation; use --yes to remove this agent without a prompt.");
31049
- const prompt = (0, import_promises16.createInterface)({ input: process.stdin, output: process.stdout });
31517
+ const prompt = (0, import_promises17.createInterface)({ input: process.stdin, output: process.stdout });
31050
31518
  try {
31051
31519
  if ((await prompt.question("Remove ConBridge and its identity from this computer? [y/N] ")).trim().toLowerCase() !== "y")
31052
31520
  return 0;