@ai-ecoverse/slicc-kernel 1.30.1 → 1.31.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.
@@ -2369,6 +2369,21 @@ function toHostLoopback(href) {
2369
2369
  url.hostname = "127.0.0.1";
2370
2370
  return url.href;
2371
2371
  }
2372
+ var DEFAULT_HOSTNAME = "slicc";
2373
+ var HOSTNAME_ADDRESS = "127.0.1.1";
2374
+ var LIBC_HOSTNAMES = ["emscripten", "wasmer.sh"];
2375
+ var LABEL = /^[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?$/i;
2376
+ function reserved(name2) {
2377
+ const lower = name2.toLowerCase();
2378
+ return lower === "localhost" || lower.endsWith(".localhost") || lower === HOST_LOOPBACK || lower === "wasmer.sh" || /^\d+(\.\d+){3}$/.test(lower);
2379
+ }
2380
+ function isHostname(name2) {
2381
+ if (typeof name2 !== "string" || name2.length > 253 || reserved(name2)) return false;
2382
+ return name2.split(".").every((l) => LABEL.test(l));
2383
+ }
2384
+ function ownNames(hostname) {
2385
+ return [.../* @__PURE__ */ new Set([hostname.toLowerCase(), ...LIBC_HOSTNAMES])];
2386
+ }
2372
2387
 
2373
2388
  // src/kernel/net/http1.ts
2374
2389
  var HttpError = class extends Error {
@@ -3617,14 +3632,15 @@ var PROXY_URL = `http://127.0.0.1:${REALM_PROXY_PORT}`;
3617
3632
  var NO_PROXY = "localhost,.localhost,127.0.0.1,127.0.0.0/8";
3618
3633
  var CA_OWNER = "slicc-kernel";
3619
3634
  var CA_DB = "slicc-kernel-ca";
3620
- function networkEnv() {
3635
+ function networkEnv(hostname = DEFAULT_HOSTNAME) {
3636
+ const bypass = [NO_PROXY, ...ownNames(hostname).filter((n) => n !== "wasmer.sh")].join(",");
3621
3637
  return {
3622
3638
  http_proxy: PROXY_URL,
3623
3639
  https_proxy: PROXY_URL,
3624
3640
  HTTP_PROXY: PROXY_URL,
3625
3641
  HTTPS_PROXY: PROXY_URL,
3626
- no_proxy: NO_PROXY,
3627
- NO_PROXY,
3642
+ no_proxy: bypass,
3643
+ NO_PROXY: bypass,
3628
3644
  SSL_CERT_FILE: CA_PATH,
3629
3645
  CURL_CA_BUNDLE: CA_PATH,
3630
3646
  GIT_SSL_CAINFO: CA_PATH,
@@ -6372,7 +6388,11 @@ var RESOLVE_TTL_MAX = 60;
6372
6388
  var RESOLVE_TIMEOUT_MS = 1e4;
6373
6389
  var RESOLVE_CACHE_MAX = 256;
6374
6390
  var LOOPBACK_NAMES2 = /* @__PURE__ */ new Set(["localhost", "localhost.localdomain", "ip6-localhost", "::1"]);
6375
- function hostsEntry(name2) {
6391
+ function loopbackName(name2, own) {
6392
+ return LOOPBACK_NAMES2.has(name2) || name2.endsWith(".localhost") || own.includes(name2);
6393
+ }
6394
+ function hostsEntry(name2, own = ownNames(DEFAULT_HOSTNAME)) {
6395
+ if (own.includes(name2)) return HOSTNAME_ADDRESS;
6376
6396
  if (LOOPBACK_NAMES2.has(name2) || name2.endsWith(".localhost")) return "127.0.0.1";
6377
6397
  if (name2 === HOST_LOOPBACK) return HOST_LOOPBACK_ADDRESS.join(".");
6378
6398
  return ipv4Bytes(name2) ? name2 : void 0;
@@ -6383,6 +6403,7 @@ var Resolver = class {
6383
6403
  now;
6384
6404
  timeoutMs;
6385
6405
  log;
6406
+ own;
6386
6407
  cache = /* @__PURE__ */ new Map();
6387
6408
  pending = /* @__PURE__ */ new Map();
6388
6409
  constructor(options) {
@@ -6391,16 +6412,17 @@ var Resolver = class {
6391
6412
  this.now = options.now ?? Date.now;
6392
6413
  this.timeoutMs = options.timeoutMs ?? RESOLVE_TIMEOUT_MS;
6393
6414
  this.log = options.log ?? ((message2) => console.warn(message2));
6415
+ this.own = ownNames(options.hostname ?? DEFAULT_HOSTNAME);
6394
6416
  }
6395
6417
  async resolve(name2, family, blocking) {
6396
6418
  const key = name2.toLowerCase().replace(/\.$/, "");
6397
- const local = hostsEntry(key);
6419
+ const local = hostsEntry(key, this.own);
6398
6420
  if (ipv6Groups(key)) {
6399
6421
  const v4 = family !== 6 && local ? [local] : [];
6400
6422
  return family === 4 ? v4 : [...v4, key];
6401
6423
  }
6402
6424
  if (local) {
6403
- const six = LOOPBACK_NAMES2.has(key) || key.endsWith(".localhost") ? ["::1"] : [];
6425
+ const six = loopbackName(key, this.own) ? ["::1"] : [];
6404
6426
  return family === 6 ? six : family === 4 ? [local] : [local, ...six];
6405
6427
  }
6406
6428
  if (!this.uplink || key === "") return [];
@@ -9996,6 +10018,7 @@ var Launcher = class {
9996
10018
  uplink;
9997
10019
  routes;
9998
10020
  resolver;
10021
+ hostname;
9999
10022
  watchers = new FsWatchers();
10000
10023
  pnpmHome;
10001
10024
  mounts;
@@ -10034,13 +10057,16 @@ var Launcher = class {
10034
10057
  this.pnpmHome = options.env?.PNPM_HOME ?? PNPM_HOME;
10035
10058
  this.modulesDir = options.modules ?? "/node_modules";
10036
10059
  this.cdp = new CdpHosts(options.cdp);
10037
- this.env = { ...networkEnv(), SLICC_CDP_URL: this.cdp.url, ...options.env };
10060
+ const hostname = options.hostname ?? DEFAULT_HOSTNAME;
10061
+ if (!isHostname(hostname)) throw new Error(`not a host name: ${String(hostname)}`);
10062
+ this.hostname = hostname;
10063
+ this.env = { ...networkEnv(hostname), SLICC_CDP_URL: this.cdp.url, ...options.env };
10038
10064
  this.ca = kernelCa(options.caStore ?? memoryCaStore());
10039
10065
  this.transport = options.transport ?? missingTransport();
10040
10066
  this.uplink = options.uplink;
10041
10067
  this.routes = new Routes(options.uplink?.traits.ipv6 === true);
10042
10068
  if (options.uplink?.routes) this.routes.set(options.uplink.routes);
10043
- this.resolver = new Resolver({ uplink: options.uplink, routes: this.routes });
10069
+ this.resolver = new Resolver({ uplink: options.uplink, routes: this.routes, hostname });
10044
10070
  if (options.uplink) this.net.useUplink({ uplink: options.uplink, routes: this.routes });
10045
10071
  enableNetwork(this.net, {
10046
10072
  transport: this.transport,
@@ -10196,8 +10222,10 @@ var Launcher = class {
10196
10222
  }
10197
10223
  async launch(planned, req) {
10198
10224
  const { target, args } = planned;
10199
- const env = { ...expandDefaults(target.env, { ...req.env, cwd: req.cwd }), ...req.env };
10225
+ const seen = { ...req.env, HOSTNAME: this.hostname, cwd: req.cwd };
10226
+ const env = { ...expandDefaults(target.env, seen), ...req.env };
10200
10227
  for (const key of target.unset ?? []) delete env[key];
10228
+ env.HOSTNAME = this.hostname;
10201
10229
  let program;
10202
10230
  try {
10203
10231
  program = await this.program(target, env);
@@ -10782,6 +10810,7 @@ function serveKernel(port, deps) {
10782
10810
  ...deps.createDriverWorker ? { createDriverWorker: deps.createDriverWorker } : {},
10783
10811
  ...req.modules ? { modules: req.modules } : {},
10784
10812
  ...req.env ? { env: req.env } : {},
10813
+ ...req.hostname !== void 0 ? { hostname: req.hostname } : {},
10785
10814
  ...net,
10786
10815
  ...media ? { media } : {},
10787
10816
  onMountPending: (medium) => port.postMessage({ medium }),