@ai-ecoverse/slicc-kernel 1.143.2 → 1.143.4

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
@@ -7982,7 +7982,7 @@ function satisfies(version, range2) {
7982
7982
  }
7983
7983
 
7984
7984
  // src/version.ts
7985
- var KERNEL_VERSION = true ? "1.143.2" : "0.0.0-dev";
7985
+ var KERNEL_VERSION = true ? "1.143.4" : "0.0.0-dev";
7986
7986
  var OS_RELEASE = "6.0.0-slicc";
7987
7987
  function procVersion() {
7988
7988
  return `Linux version ${OS_RELEASE} (slicc-kernel ${KERNEL_VERSION}) #1 SMP PREEMPT_DYNAMIC
@@ -10506,22 +10506,22 @@ function noted(watch, note) {
10506
10506
  if (watch.overflowed) return;
10507
10507
  if (watch.notes.length >= WATCH_NOTES_LIMIT) {
10508
10508
  watch.overflowed = true;
10509
- watch.notes.push({ overflow: true });
10509
+ watch.notes.push({ overflow: true, seq: note.seq });
10510
10510
  } else watch.notes.push(note);
10511
10511
  watch.wake?.();
10512
10512
  }
10513
- function route(watch, type, path) {
10514
- for (const root of watch.roots) if (routed(watch, root, type, path)) return;
10513
+ function route(watch, type, path, seq2) {
10514
+ for (const root of watch.roots) if (routed(watch, root, type, path, seq2)) return;
10515
10515
  }
10516
- function routed(watch, root, type, path) {
10516
+ function routed(watch, root, type, path, seq2) {
10517
10517
  if (path === root || type === "rename" && root !== "/" && under3(root, path)) {
10518
- noted(watch, { type, filename: watch.names.get(root) ?? baseOf3(root) });
10519
- if (type === "rename") noted(watch, { ended: true });
10518
+ noted(watch, { type, filename: watch.names.get(root) ?? baseOf3(root), seq: seq2 });
10519
+ if (type === "rename") noted(watch, { ended: true, seq: seq2 });
10520
10520
  return true;
10521
10521
  }
10522
- if (parentOf7(path) === root) noted(watch, { type, filename: baseOf3(path) });
10522
+ if (parentOf7(path) === root) noted(watch, { type, filename: baseOf3(path), seq: seq2 });
10523
10523
  else if (watch.recursive && under3(path, root)) {
10524
- noted(watch, { type, filename: path.slice(root === "/" ? 1 : root.length + 1) });
10524
+ noted(watch, { type, filename: path.slice(root === "/" ? 1 : root.length + 1), seq: seq2 });
10525
10525
  } else return false;
10526
10526
  return true;
10527
10527
  }
@@ -10535,6 +10535,7 @@ var FsWatchers = class {
10535
10535
  typed = /* @__PURE__ */ new Set();
10536
10536
  taps = [];
10537
10537
  reals = /* @__PURE__ */ new Map();
10538
+ seq = 0;
10538
10539
  reshapes = [];
10539
10540
  onReshape(listener) {
10540
10541
  this.reshapes.push(listener);
@@ -10594,7 +10595,7 @@ var FsWatchers = class {
10594
10595
  const notes = watch.notes.splice(0);
10595
10596
  watch.overflowed = false;
10596
10597
  if (watch.ended) this.typed.delete(watch);
10597
- return notes.length === 0 && watch.ended ? [{ ended: true }] : notes;
10598
+ return notes.length === 0 && watch.ended ? [{ ended: true, seq: this.seq }] : notes;
10598
10599
  }
10599
10600
  };
10600
10601
  }
@@ -10611,10 +10612,11 @@ var FsWatchers = class {
10611
10612
  if (this.typed.size === 0) return;
10612
10613
  for (const path of paths) {
10613
10614
  const at = normalizePath(path);
10614
- for (const watch of [...this.typed]) route(watch, type, at);
10615
+ const seq2 = ++this.seq;
10616
+ for (const watch of [...this.typed]) route(watch, type, at, seq2);
10615
10617
  }
10616
10618
  }
10617
- moved(from, to) {
10619
+ moved(from, to, seq2 = ++this.seq) {
10618
10620
  const source = normalizePath(from);
10619
10621
  const target = normalizePath(to);
10620
10622
  const followed2 = /* @__PURE__ */ new Set();
@@ -10630,17 +10632,25 @@ var FsWatchers = class {
10630
10632
  watch.names = names2;
10631
10633
  watch.roots = [...new Set(roots)];
10632
10634
  if (main === source) {
10633
- noted(watch, { type: "rename", filename: names2.get(target), moved: true });
10635
+ noted(watch, {
10636
+ type: "rename",
10637
+ filename: names2.get(target),
10638
+ moved: true,
10639
+ seq: seq2
10640
+ });
10634
10641
  }
10635
10642
  }
10636
10643
  return followed2;
10637
10644
  }
10638
10645
  renamed(from, to) {
10639
- const followed2 = this.moved(from, to);
10646
+ const first = ++this.seq;
10647
+ const followed2 = this.moved(from, to, first);
10640
10648
  if (this.typed.size === 0) return;
10641
- for (const path of [from, to]) {
10649
+ for (const [i, path] of [from, to].entries()) {
10642
10650
  const at = normalizePath(path);
10643
- for (const watch of [...this.typed]) if (!followed2.has(watch)) route(watch, "rename", at);
10651
+ const seq2 = i === 0 ? first : ++this.seq;
10652
+ for (const watch of [...this.typed])
10653
+ if (!followed2.has(watch)) route(watch, "rename", at, seq2);
10644
10654
  }
10645
10655
  }
10646
10656
  changed(...paths) {
@@ -10705,10 +10715,11 @@ var FsWatchers = class {
10705
10715
  const real = await realOf(at);
10706
10716
  const paths = real === at ? [at] : [at, real];
10707
10717
  this.report(paths);
10708
- if (done4) for (const type of types(fresh2)) this.emit(type, paths);
10718
+ if (done4) for (const type of types(fresh2, args)) this.emit(type, paths);
10709
10719
  }
10710
10720
  };
10711
10721
  const written2 = (fresh2) => fresh2 ? ["rename", "change"] : ["change"];
10722
+ const overwritten = (fresh2, args) => fresh2 || args[1].length === 0 ? written2(fresh2) : ["change", "change"];
10712
10723
  const reshaping = (run2) => async (...args) => {
10713
10724
  this.reshaped();
10714
10725
  try {
@@ -10718,7 +10729,7 @@ var FsWatchers = class {
10718
10729
  }
10719
10730
  };
10720
10731
  const overrides = {
10721
- writeFile: content(fs.writeFile.bind(fs), written2),
10732
+ writeFile: content(fs.writeFile.bind(fs), overwritten),
10722
10733
  ...fs.createExclusive ? { createExclusive: content(fs.createExclusive.bind(fs), () => ["rename"]) } : {},
10723
10734
  ...fs.copyFile ? {
10724
10735
  copyFile: (from, to, options) => content(
@@ -17271,7 +17282,8 @@ var Resolver = class {
17271
17282
  const abort = new AbortController();
17272
17283
  lookup4 = { work: this.lookup(key, asked, id2, abort.signal), abort, waiters: 0 };
17273
17284
  this.pending.set(id2, lookup4);
17274
- void lookup4.work.then(() => this.pending.delete(id2));
17285
+ const done4 = () => this.pending.delete(id2);
17286
+ void lookup4.work.then(done4, done4);
17275
17287
  }
17276
17288
  return waitFor(lookup4, signal);
17277
17289
  }
@@ -17289,7 +17301,7 @@ var Resolver = class {
17289
17301
  ])
17290
17302
  );
17291
17303
  } catch {
17292
- return [];
17304
+ throw new KernelError("ETIMEDOUT", `resolve ${name2}: the uplink gave no answer`);
17293
17305
  }
17294
17306
  const addresses = answer2.addresses.filter((a) => this.usable(name2, a, family));
17295
17307
  if (addresses.length > 0) this.remember(id2, addresses, answer2.ttl);
@@ -17322,12 +17334,16 @@ function waitFor(lookup4, signal) {
17322
17334
  reject(new KernelError("EINTR"));
17323
17335
  };
17324
17336
  signal?.addEventListener("abort", abort, { once: true });
17325
- void lookup4.work.then((value2) => {
17337
+ const settle = (finish) => {
17326
17338
  if (signal?.aborted) return;
17327
17339
  lookup4.waiters--;
17328
17340
  signal?.removeEventListener("abort", abort);
17329
- resolve2(value2);
17330
- });
17341
+ finish();
17342
+ };
17343
+ void lookup4.work.then(
17344
+ (value2) => settle(() => resolve2(value2)),
17345
+ (err) => settle(() => reject(err))
17346
+ );
17331
17347
  });
17332
17348
  }
17333
17349
 
@@ -32158,42 +32174,47 @@ function nodeTransport(options = {}) {
32158
32174
  var TERMINATED = "the kernel is terminated";
32159
32175
  var EXIT_GRACE_MS = 50;
32160
32176
  var WARM_IDLE_MS = 3e4;
32161
- function warmPool(make, live, idleMs = WARM_IDLE_MS) {
32162
- let spare;
32177
+ var MAX_WARM_WORKERS = 64;
32178
+ function warmPool(make, live, idleMs = WARM_IDLE_MS, size = 1) {
32179
+ const spares = [];
32163
32180
  let idle2;
32164
32181
  let closed = false;
32165
32182
  const drop = (worker) => {
32166
- if (spare !== worker) return;
32167
- spare = void 0;
32183
+ const at = spares.indexOf(worker);
32184
+ if (at < 0) return;
32185
+ spares.splice(at, 1);
32186
+ if (spares.length > 0) return;
32168
32187
  clearTimeout(idle2);
32169
32188
  live.delete(kill);
32170
32189
  };
32171
32190
  const kill = () => {
32172
- const worker = spare;
32173
- if (!worker) return;
32174
- drop(worker);
32175
- void worker.terminate();
32191
+ for (const worker of [...spares]) {
32192
+ drop(worker);
32193
+ void worker.terminate();
32194
+ }
32176
32195
  };
32177
32196
  const fill2 = () => {
32178
- if (closed || spare) return;
32179
- let worker;
32180
- try {
32181
- worker = make();
32182
- } catch {
32183
- closed = true;
32184
- return;
32197
+ while (!closed && spares.length < size) {
32198
+ let worker;
32199
+ try {
32200
+ worker = make();
32201
+ } catch {
32202
+ closed = true;
32203
+ return;
32204
+ }
32205
+ worker.unref();
32206
+ worker.once("error", () => drop(worker));
32207
+ worker.once("exit", () => drop(worker));
32208
+ spares.push(worker);
32209
+ live.add(kill);
32185
32210
  }
32186
- worker.unref();
32187
- worker.once("error", () => drop(worker));
32188
- worker.once("exit", () => drop(worker));
32189
- spare = worker;
32190
- live.add(kill);
32211
+ clearTimeout(idle2);
32191
32212
  idle2 = setTimeout(kill, idleMs);
32192
32213
  idle2.unref?.();
32193
32214
  };
32194
32215
  return {
32195
32216
  take() {
32196
- const worker = spare;
32217
+ const worker = spares[0];
32197
32218
  if (worker) {
32198
32219
  drop(worker);
32199
32220
  worker.removeAllListeners("error");
@@ -32209,12 +32230,23 @@ function warmPool(make, live, idleMs = WARM_IDLE_MS) {
32209
32230
  }
32210
32231
  };
32211
32232
  }
32233
+ function sparesOf(options) {
32234
+ if (options.warmWorker === false) return 0;
32235
+ const n = options.warmWorkers ?? 1;
32236
+ if (typeof n !== "number" || !Number.isInteger(n) || n < 0 || n > MAX_WARM_WORKERS) {
32237
+ throw new TypeError(
32238
+ `createNodeKernel: warmWorkers must be an integer from 0 to ${MAX_WARM_WORKERS}`
32239
+ );
32240
+ }
32241
+ return n;
32242
+ }
32212
32243
  function processWorker(file, workerData) {
32213
32244
  return new Worker(file, { env: workerEnv(), ...workerData ? { workerData } : {} });
32214
32245
  }
32215
32246
  function warmPoolOf(options, file, workerData, live) {
32216
- if (options.warmWorker === false) return void 0;
32217
- return warmPool(() => processWorker(file, workerData), live);
32247
+ const size = sparesOf(options);
32248
+ if (size === 0) return void 0;
32249
+ return warmPool(() => processWorker(file, workerData), live, WARM_IDLE_MS, size);
32218
32250
  }
32219
32251
  function nodeWorker(file, live, closed, workerData, take) {
32220
32252
  const errors = /* @__PURE__ */ new Set();
@@ -32449,6 +32481,7 @@ async function createNodeKernel(options = {}) {
32449
32481
  export {
32450
32482
  KernelCallError,
32451
32483
  KernelGoneError,
32484
+ MAX_WARM_WORKERS,
32452
32485
  WARM_IDLE_MS,
32453
32486
  attachKernel,
32454
32487
  createNodeKernel,
@@ -32456,6 +32489,7 @@ export {
32456
32489
  memoryRoot,
32457
32490
  nodeTransport,
32458
32491
  serveHostfsPort,
32492
+ sparesOf,
32459
32493
  warmPool
32460
32494
  };
32461
32495
  //# sourceMappingURL=node.js.map