@ai-ecoverse/slicc-kernel 1.93.3 → 1.94.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.
package/dist/node.js CHANGED
@@ -4591,6 +4591,7 @@ var OpfsFs = class {
4591
4591
  this.touch(now, parent.path, made2);
4592
4592
  }
4593
4593
  async mkdirExcl(path, owner) {
4594
+ if (normalizePath(path) === "/") throw fsError("EEXIST", path);
4594
4595
  const parent = await this.locate(parentOf4(path), true);
4595
4596
  if (parent.handle?.kind !== "directory") throw fsError("ENOTDIR", path);
4596
4597
  const dir = parent.handle;
@@ -6158,10 +6159,15 @@ async function binCommandsOf(physical, pkg, manifest, taken) {
6158
6159
  }
6159
6160
  return out;
6160
6161
  }
6161
- async function scanCommands(fs, modules, binsFrom = Number.POSITIVE_INFINITY) {
6162
- const found = /* @__PURE__ */ new Map();
6163
- const physical = physicalResolver(fs);
6164
- for (const [index, root] of (typeof modules === "string" ? [modules] : modules).entries()) {
6162
+ var PACKAGE_NAME = /^(@[a-z0-9-~][a-z0-9-._~]*\/)?[a-z0-9-~][a-z0-9-._~]*$/;
6163
+ function replacesOf(manifest) {
6164
+ const replaces = manifest.slicc?.replaces;
6165
+ if (!Array.isArray(replaces)) return [];
6166
+ return replaces.every((name2) => typeof name2 === "string" && PACKAGE_NAME.test(name2)) ? replaces : [];
6167
+ }
6168
+ async function tierPackages(fs, physical, roots, bins) {
6169
+ const out = [];
6170
+ for (const root of roots) {
6165
6171
  for (const pkg of await packages(fs, root)) {
6166
6172
  let manifest;
6167
6173
  try {
@@ -6171,11 +6177,47 @@ async function scanCommands(fs, modules, binsFrom = Number.POSITIVE_INFINITY) {
6171
6177
  }
6172
6178
  const own = commandsOf(pkg, manifest);
6173
6179
  const named = new Set(own.map((command) => command.name));
6174
- const bins = index >= binsFrom ? await binCommandsOf(physical, pkg, manifest, named) : [];
6175
- for (const command of [...own, ...bins]) {
6176
- if (!found.has(command.name))
6177
- found.set(command.name, await withPackagePaths(fs, pkg, command));
6178
- }
6180
+ const extra = bins ? await binCommandsOf(physical, pkg, manifest, named) : [];
6181
+ out.push({
6182
+ name: pkg.slice(root.length + 1),
6183
+ pkg,
6184
+ replaces: replacesOf(manifest),
6185
+ commands: [...own, ...extra]
6186
+ });
6187
+ }
6188
+ }
6189
+ return out;
6190
+ }
6191
+ function winners(tier) {
6192
+ const providers = /* @__PURE__ */ new Map();
6193
+ for (const entry of tier) {
6194
+ for (const command of entry.commands) {
6195
+ const list = providers.get(command.name) ?? [];
6196
+ if (!list.includes(entry)) list.push(entry);
6197
+ providers.set(command.name, list);
6198
+ }
6199
+ }
6200
+ const out = /* @__PURE__ */ new Map();
6201
+ for (const [name2, list] of providers) {
6202
+ const kept = list.filter(
6203
+ (entry2) => !list.some((other) => other !== entry2 && other.replaces.includes(entry2.name))
6204
+ );
6205
+ const entry = kept[0] ?? list[0];
6206
+ const command = entry.commands.find((c) => c.name === name2);
6207
+ out.set(name2, { pkg: entry.pkg, command });
6208
+ }
6209
+ return out;
6210
+ }
6211
+ async function scanCommands(fs, modules, binsFrom = Number.POSITIVE_INFINITY) {
6212
+ const found = /* @__PURE__ */ new Map();
6213
+ const physical = physicalResolver(fs);
6214
+ const tiers = (typeof modules === "string" ? [modules] : modules).map(
6215
+ (tier) => typeof tier === "string" ? [tier] : tier
6216
+ );
6217
+ for (const [index, roots] of tiers.entries()) {
6218
+ const tier = await tierPackages(fs, physical, roots, index >= binsFrom);
6219
+ for (const [name2, { pkg, command }] of winners(tier)) {
6220
+ if (!found.has(name2)) found.set(name2, await withPackagePaths(fs, pkg, command));
6179
6221
  }
6180
6222
  }
6181
6223
  if (!found.has("sh") && found.has("bash")) {
@@ -10109,14 +10151,6 @@ function attachSyncSabResponder(port, sab, token, opts) {
10109
10151
  }
10110
10152
 
10111
10153
  // src/kernel/cpu-clock.ts
10112
- var IDLE_OPS = /* @__PURE__ */ new Set([
10113
- "fd-select",
10114
- "proc-wait",
10115
- "proc-exec",
10116
- "sig-pause",
10117
- "sock-accept",
10118
- "sock-connect"
10119
- ]);
10120
10154
  var SYS_CAP_US = 2e4;
10121
10155
  var LOCAL = SAB_CLOCK_OFFSET;
10122
10156
  var BLOCKED = 0;
@@ -10148,9 +10182,16 @@ var CpuClock = class {
10148
10182
  this.now = now;
10149
10183
  this.start = now();
10150
10184
  }
10151
- enter(op) {
10185
+ enter() {
10152
10186
  this.since = this.now();
10153
- this.kind = this.stopped || IDLE_OPS.has(op) ? "idle" : "sys";
10187
+ this.kind = this.stopped ? "idle" : "sys";
10188
+ }
10189
+ block() {
10190
+ if (this.since === 0 || this.kind === "idle" || this.frozen !== void 0) return;
10191
+ const now = this.now();
10192
+ this.add(now - this.since);
10193
+ this.since = now;
10194
+ this.kind = "idle";
10154
10195
  }
10155
10196
  leave() {
10156
10197
  if (this.since === 0) return;
@@ -10240,9 +10281,10 @@ var ProcessClocks = class {
10240
10281
  }
10241
10282
  timed(clock, dispatch2) {
10242
10283
  const c = clock ?? this.main;
10284
+ const block = () => c.block();
10243
10285
  return (req) => {
10244
- c.enter(req.op);
10245
- return dispatch2(req).finally(() => c.leave());
10286
+ c.enter();
10287
+ return dispatch2(req, block).finally(() => c.leave());
10246
10288
  };
10247
10289
  }
10248
10290
  all() {
@@ -10501,7 +10543,7 @@ function mountTable(mounts = []) {
10501
10543
  }
10502
10544
 
10503
10545
  // src/version.ts
10504
- var KERNEL_VERSION = true ? "1.93.3" : "0.0.0-dev";
10546
+ var KERNEL_VERSION = true ? "1.94.1" : "0.0.0-dev";
10505
10547
  var OS_RELEASE = "6.0.0-slicc";
10506
10548
  function procVersion() {
10507
10549
  return `Linux version ${OS_RELEASE} (slicc-kernel ${KERNEL_VERSION}) #1 SMP PREEMPT_DYNAMIC
@@ -14193,7 +14235,8 @@ var WasmProcess = class {
14193
14235
  this.wake?.();
14194
14236
  for (const listener of this.stateListeners) listener("continued", SIG.CONT);
14195
14237
  }
14196
- async syscall(req, cancelled) {
14238
+ blocks = /* @__PURE__ */ new WeakMap();
14239
+ async syscall(req, cancelled, block) {
14197
14240
  this.options.onSyscall?.(req);
14198
14241
  for (; ; ) {
14199
14242
  await this.resumed;
@@ -14203,6 +14246,7 @@ var WasmProcess = class {
14203
14246
  const forward = () => scope.abort();
14204
14247
  if (cancelled?.aborted) scope.abort();
14205
14248
  cancelled?.addEventListener("abort", forward, { once: true });
14249
+ if (block) this.blocks.set(scope.signal, block);
14206
14250
  const result = await this.dispatch(req, scope.signal).finally(() => {
14207
14251
  cancelled?.removeEventListener("abort", forward);
14208
14252
  this.waiting.delete(scope.signal);
@@ -14285,6 +14329,7 @@ var WasmProcess = class {
14285
14329
  }
14286
14330
  if (this.options.hasPending?.() || cancelled.aborted) throw new KernelError("EINTR");
14287
14331
  if (owing) this.waiting.add(cancelled);
14332
+ if (owing) this.blocks.get(cancelled)?.();
14288
14333
  return this.cancelSignal(cancelled);
14289
14334
  }
14290
14335
  cancelSignal(cancelled) {
@@ -14926,6 +14971,7 @@ var WasmProcess = class {
14926
14971
  case "proc-identity":
14927
14972
  return { ok: true, kind: "json", json: await this.options.identity?.() ?? null };
14928
14973
  case "proc-exec": {
14974
+ this.blocks.get(cancelled)?.();
14929
14975
  this.adoptExec(req.pid);
14930
14976
  this.options.jobs?.exec(this.pid, req.pid);
14931
14977
  await this.fds.closeAll();
@@ -15256,6 +15302,9 @@ function killThread(thread, caught, sig) {
15256
15302
  function unblocked(header4) {
15257
15303
  return Atomics.load(header4, SAB_I_SIGNALS) & ~Atomics.load(header4, SAB_I_BLOCKED);
15258
15304
  }
15305
+ function threadCall(process2, req, cancelled, block) {
15306
+ return isWasmSyscall(req) ? process2.syscall(req, cancelled, block) : dispatchSyncFs(req);
15307
+ }
15259
15308
  function threadSignalsOf(sab) {
15260
15309
  return { header: new Int32Array(sab, 0, SAB_HEADER_I32), interrupt: new AbortController() };
15261
15310
  }
@@ -15459,7 +15508,9 @@ function spawnWasmProcess(opts) {
15459
15508
  process2.keptHandle = (handle2) => holds.keptFor(handle2)?.hidden;
15460
15509
  const worker = opts.createWorker();
15461
15510
  const dying = new Dying();
15462
- const dispatch2 = (req) => dying.serving(() => isWasmSyscall(req) ? process2.syscall(req) : dispatchSyncFs(req));
15511
+ const dispatch2 = (req, block) => dying.serving(
15512
+ () => isWasmSyscall(req) ? process2.syscall(req, void 0, block) : dispatchSyncFs(req)
15513
+ );
15463
15514
  const clocks = new ProcessClocks(sab, opts.program.abi !== "js", process2);
15464
15515
  const responder = attachSyncSabResponder(worker, sab, token, {
15465
15516
  dispatch: clocks.timed(void 0, dispatch2)
@@ -15529,9 +15580,7 @@ function spawnWasmProcess(opts) {
15529
15580
  const tsignals = threadSignalsOf(tsab);
15530
15581
  if (thread.blocked) storeBlocked(tsignals.header, thread.blocked);
15531
15582
  threadSignals.set(thread.tid, tsignals);
15532
- const tdispatch = (req) => dying.serving(
15533
- () => isWasmSyscall(req) ? process2.syscall(req, threadCancel(tsignals)) : dispatchSyncFs(req)
15534
- );
15583
+ const tdispatch = (req, block) => dying.serving(() => threadCall(process2, req, threadCancel(tsignals), block));
15535
15584
  const tresponder = attachSyncSabResponder(tw, tsab, token, {
15536
15585
  dispatch: clocks.timed(clocks.thread(thread.tid, tsab), tdispatch)
15537
15586
  });
@@ -19256,8 +19305,8 @@ var Launcher = class {
19256
19305
  let found = this.catalogs.get(scope);
19257
19306
  if (!found) {
19258
19307
  found = this.trustedAppended().then(async (appended) => {
19259
- const roots = await this.roots(scope, appended);
19260
- return scanCommands(this.scanned, roots, roots.length - appended.length);
19308
+ const tiers = await this.tiers(scope, appended);
19309
+ return scanCommands(this.scanned, tiers, tiers.length - appended.length);
19261
19310
  }).then((commands) => commands.set(SUDO_COMMAND.name, SUDO_COMMAND));
19262
19311
  this.catalogs.set(scope, found);
19263
19312
  }
@@ -19285,13 +19334,16 @@ var Launcher = class {
19285
19334
  }
19286
19335
  return found;
19287
19336
  }
19288
- async roots(scope = "", appended) {
19337
+ async tiers(scope = "", appended) {
19289
19338
  const system = [
19290
- this.modulesDir,
19291
- ...await pnpmGlobalRoots(this.base, this.pnpmHome),
19292
- ...appended ?? await this.trustedAppended()
19339
+ [this.modulesDir],
19340
+ await pnpmGlobalRoots(this.base, this.pnpmHome),
19341
+ ...(appended ?? await this.trustedAppended()).map((root) => [root])
19293
19342
  ];
19294
- return scope ? [...await pnpmGlobalRoots(this.base, scope), ...system] : system;
19343
+ return scope ? [await pnpmGlobalRoots(this.base, scope), ...system] : system;
19344
+ }
19345
+ async roots(scope = "") {
19346
+ return (await this.tiers(scope)).flat();
19295
19347
  }
19296
19348
  async rootOnlyPath(root) {
19297
19349
  for (const at of chain(root)) {
@@ -20903,6 +20955,17 @@ function proxyAddresses() {
20903
20955
  }
20904
20956
  return out;
20905
20957
  }
20958
+ var proxied = /* @__PURE__ */ new Set();
20959
+ function tupleOf(socket) {
20960
+ if (!socket.localPort || !socket.remotePort) return void 0;
20961
+ return `${socket.localAddress}:${socket.localPort} ${socket.remoteAddress}:${socket.remotePort}`;
20962
+ }
20963
+ function toProxy(connectParams) {
20964
+ const proxies = proxyAddresses();
20965
+ if (proxies.size === 0 || !connectParams.hostname) return false;
20966
+ const port = connectParams.port || (connectParams.protocol === "https:" ? "443" : "80");
20967
+ return proxies.has(`${connectParams.hostname}:${port}`);
20968
+ }
20906
20969
  function ensureSubscribed() {
20907
20970
  if (subscribed) return;
20908
20971
  subscribed = true;
@@ -20917,10 +20980,14 @@ function ensureSubscribed() {
20917
20980
  socket.destroy(err2);
20918
20981
  return;
20919
20982
  }
20920
- const proxies = proxyAddresses();
20921
- if (proxies.size > 0 && connectParams.hostname) {
20922
- const cpPort = connectParams.port || (connectParams.protocol === "https:" ? "443" : "80");
20923
- if (proxies.has(`${connectParams.hostname}:${cpPort}`)) return;
20983
+ const tuple = tupleOf(socket);
20984
+ if (tuple && proxied.has(tuple)) return;
20985
+ if (toProxy(connectParams)) {
20986
+ if (tuple) {
20987
+ proxied.add(tuple);
20988
+ socket.once("close", () => proxied.delete(tuple));
20989
+ }
20990
+ return;
20924
20991
  }
20925
20992
  const place = placeOf(address);
20926
20993
  if (!place) return;