@ai-ecoverse/slicc-kernel 1.30.1 → 1.31.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/node.js CHANGED
@@ -4797,6 +4797,21 @@ function toHostLoopback(href) {
4797
4797
  url.hostname = "127.0.0.1";
4798
4798
  return url.href;
4799
4799
  }
4800
+ var DEFAULT_HOSTNAME = "slicc";
4801
+ var HOSTNAME_ADDRESS = "127.0.1.1";
4802
+ var LIBC_HOSTNAMES = ["emscripten", "wasmer.sh"];
4803
+ var LABEL = /^[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?$/i;
4804
+ function reserved(name2) {
4805
+ const lower = name2.toLowerCase();
4806
+ return lower === "localhost" || lower.endsWith(".localhost") || lower === HOST_LOOPBACK || lower === "wasmer.sh" || /^\d+(\.\d+){3}$/.test(lower);
4807
+ }
4808
+ function isHostname(name2) {
4809
+ if (typeof name2 !== "string" || name2.length > 253 || reserved(name2)) return false;
4810
+ return name2.split(".").every((l) => LABEL.test(l));
4811
+ }
4812
+ function ownNames(hostname) {
4813
+ return [.../* @__PURE__ */ new Set([hostname.toLowerCase(), ...LIBC_HOSTNAMES])];
4814
+ }
4800
4815
 
4801
4816
  // src/kernel/net/proxy-service.ts
4802
4817
  var REALM_PROXY_PORT = 3128;
@@ -5760,14 +5775,15 @@ var CA_PATH = "/etc/ssl/certs/slicc-kernel-ca.pem";
5760
5775
  var PROXY_URL = `http://127.0.0.1:${REALM_PROXY_PORT}`;
5761
5776
  var NO_PROXY = "localhost,.localhost,127.0.0.1,127.0.0.0/8";
5762
5777
  var CA_OWNER = "slicc-kernel";
5763
- function networkEnv() {
5778
+ function networkEnv(hostname = DEFAULT_HOSTNAME) {
5779
+ const bypass = [NO_PROXY, ...ownNames(hostname).filter((n) => n !== "wasmer.sh")].join(",");
5764
5780
  return {
5765
5781
  http_proxy: PROXY_URL,
5766
5782
  https_proxy: PROXY_URL,
5767
5783
  HTTP_PROXY: PROXY_URL,
5768
5784
  HTTPS_PROXY: PROXY_URL,
5769
- no_proxy: NO_PROXY,
5770
- NO_PROXY,
5785
+ no_proxy: bypass,
5786
+ NO_PROXY: bypass,
5771
5787
  SSL_CERT_FILE: CA_PATH,
5772
5788
  CURL_CA_BUNDLE: CA_PATH,
5773
5789
  GIT_SSL_CAINFO: CA_PATH,
@@ -6090,7 +6106,11 @@ var RESOLVE_TTL_MAX = 60;
6090
6106
  var RESOLVE_TIMEOUT_MS = 1e4;
6091
6107
  var RESOLVE_CACHE_MAX = 256;
6092
6108
  var LOOPBACK_NAMES2 = /* @__PURE__ */ new Set(["localhost", "localhost.localdomain", "ip6-localhost", "::1"]);
6093
- function hostsEntry(name2) {
6109
+ function loopbackName(name2, own) {
6110
+ return LOOPBACK_NAMES2.has(name2) || name2.endsWith(".localhost") || own.includes(name2);
6111
+ }
6112
+ function hostsEntry(name2, own = ownNames(DEFAULT_HOSTNAME)) {
6113
+ if (own.includes(name2)) return HOSTNAME_ADDRESS;
6094
6114
  if (LOOPBACK_NAMES2.has(name2) || name2.endsWith(".localhost")) return "127.0.0.1";
6095
6115
  if (name2 === HOST_LOOPBACK) return HOST_LOOPBACK_ADDRESS.join(".");
6096
6116
  return ipv4Bytes(name2) ? name2 : void 0;
@@ -6101,6 +6121,7 @@ var Resolver = class {
6101
6121
  now;
6102
6122
  timeoutMs;
6103
6123
  log;
6124
+ own;
6104
6125
  cache = /* @__PURE__ */ new Map();
6105
6126
  pending = /* @__PURE__ */ new Map();
6106
6127
  constructor(options) {
@@ -6109,16 +6130,17 @@ var Resolver = class {
6109
6130
  this.now = options.now ?? Date.now;
6110
6131
  this.timeoutMs = options.timeoutMs ?? RESOLVE_TIMEOUT_MS;
6111
6132
  this.log = options.log ?? ((message2) => console.warn(message2));
6133
+ this.own = ownNames(options.hostname ?? DEFAULT_HOSTNAME);
6112
6134
  }
6113
6135
  async resolve(name2, family, blocking) {
6114
6136
  const key = name2.toLowerCase().replace(/\.$/, "");
6115
- const local = hostsEntry(key);
6137
+ const local = hostsEntry(key, this.own);
6116
6138
  if (ipv6Groups(key)) {
6117
6139
  const v4 = family !== 6 && local ? [local] : [];
6118
6140
  return family === 4 ? v4 : [...v4, key];
6119
6141
  }
6120
6142
  if (local) {
6121
- const six = LOOPBACK_NAMES2.has(key) || key.endsWith(".localhost") ? ["::1"] : [];
6143
+ const six = loopbackName(key, this.own) ? ["::1"] : [];
6122
6144
  return family === 6 ? six : family === 4 ? [local] : [local, ...six];
6123
6145
  }
6124
6146
  if (!this.uplink || key === "") return [];
@@ -9723,6 +9745,7 @@ var Launcher = class {
9723
9745
  uplink;
9724
9746
  routes;
9725
9747
  resolver;
9748
+ hostname;
9726
9749
  watchers = new FsWatchers();
9727
9750
  pnpmHome;
9728
9751
  mounts;
@@ -9761,13 +9784,16 @@ var Launcher = class {
9761
9784
  this.pnpmHome = options.env?.PNPM_HOME ?? PNPM_HOME;
9762
9785
  this.modulesDir = options.modules ?? "/node_modules";
9763
9786
  this.cdp = new CdpHosts(options.cdp);
9764
- this.env = { ...networkEnv(), SLICC_CDP_URL: this.cdp.url, ...options.env };
9787
+ const hostname = options.hostname ?? DEFAULT_HOSTNAME;
9788
+ if (!isHostname(hostname)) throw new Error(`not a host name: ${String(hostname)}`);
9789
+ this.hostname = hostname;
9790
+ this.env = { ...networkEnv(hostname), SLICC_CDP_URL: this.cdp.url, ...options.env };
9765
9791
  this.ca = kernelCa(options.caStore ?? memoryCaStore());
9766
9792
  this.transport = options.transport ?? missingTransport();
9767
9793
  this.uplink = options.uplink;
9768
9794
  this.routes = new Routes(options.uplink?.traits.ipv6 === true);
9769
9795
  if (options.uplink?.routes) this.routes.set(options.uplink.routes);
9770
- this.resolver = new Resolver({ uplink: options.uplink, routes: this.routes });
9796
+ this.resolver = new Resolver({ uplink: options.uplink, routes: this.routes, hostname });
9771
9797
  if (options.uplink) this.net.useUplink({ uplink: options.uplink, routes: this.routes });
9772
9798
  enableNetwork(this.net, {
9773
9799
  transport: this.transport,
@@ -9923,8 +9949,10 @@ var Launcher = class {
9923
9949
  }
9924
9950
  async launch(planned, req) {
9925
9951
  const { target, args } = planned;
9926
- const env = { ...expandDefaults(target.env, { ...req.env, cwd: req.cwd }), ...req.env };
9952
+ const seen = { ...req.env, HOSTNAME: this.hostname, cwd: req.cwd };
9953
+ const env = { ...expandDefaults(target.env, seen), ...req.env };
9927
9954
  for (const key of target.unset ?? []) delete env[key];
9955
+ env.HOSTNAME = this.hostname;
9928
9956
  let program;
9929
9957
  try {
9930
9958
  program = await this.program(target, env);
@@ -11378,7 +11406,8 @@ async function createNodeKernel(options = {}) {
11378
11406
  ...options.processMounts !== void 0 ? { processMounts: options.processMounts } : {},
11379
11407
  ...options.fstabRetries ? { fstabRetries: options.fstabRetries } : {},
11380
11408
  ...options.hostfs ? { hostfs: options.hostfs } : {},
11381
- ...options.cdp ? { cdp: options.cdp } : {}
11409
+ ...options.cdp ? { cdp: options.cdp } : {},
11410
+ ...options.hostname !== void 0 ? { hostname: options.hostname } : {}
11382
11411
  });
11383
11412
  await launcher.prepare();
11384
11413
  const guard = (work) => new Promise((resolve, reject) => {