@ai-ecoverse/slicc-kernel 1.124.2 → 1.124.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
@@ -4112,6 +4112,8 @@ var ProtectedFs = class {
4112
4112
  // src/fs/remote.ts
4113
4113
  var ANNOUNCE_WAIT_MS = 500;
4114
4114
  var PRUNE_EVERY_MS = 3e4;
4115
+ var MOURN_TRIES = 5;
4116
+ var MOURN_RETRY_MS = 100;
4115
4117
  function lockManager() {
4116
4118
  return globalThis.navigator?.locks;
4117
4119
  }
@@ -4120,6 +4122,7 @@ var RemoteWatch = class {
4120
4122
  name;
4121
4123
  tab = crypto.randomUUID();
4122
4124
  peers = /* @__PURE__ */ new Set();
4125
+ mourned = /* @__PURE__ */ new Set();
4123
4126
  others = /* @__PURE__ */ new Map();
4124
4127
  union = /* @__PURE__ */ new Set();
4125
4128
  listeners = /* @__PURE__ */ new Set();
@@ -4188,8 +4191,7 @@ var RemoteWatch = class {
4188
4191
  receive(data) {
4189
4192
  if (data.hello !== void 0) this.greeted(data.hello);
4190
4193
  if (data.here !== void 0 && data.to === this.tab) {
4191
- this.peers.add(data.here);
4192
- this.recount();
4194
+ this.arrived(data.here);
4193
4195
  this.met?.();
4194
4196
  }
4195
4197
  if (data.tab !== void 0 && data.paths !== void 0) this.announced(data);
@@ -4198,9 +4200,36 @@ var RemoteWatch = class {
4198
4200
  }
4199
4201
  if (data.changed !== void 0) this.emit({ paths: data.changed, trees: [] });
4200
4202
  }
4201
- greeted(peer) {
4203
+ arrived(peer) {
4202
4204
  this.peers.add(peer);
4203
4205
  this.recount();
4206
+ void this.mourn(peer);
4207
+ }
4208
+ async mourn(peer, tries = MOURN_TRIES) {
4209
+ if (!this.locks || this.mourned.has(peer)) return;
4210
+ this.mourned.add(peer);
4211
+ const name2 = this.lockOf(peer);
4212
+ const { held = [], pending = [] } = await this.locks.query();
4213
+ if (![...held, ...pending].some((lock) => lock.name === name2)) {
4214
+ this.mourned.delete(peer);
4215
+ if (tries > 1 && this.peers.has(peer)) {
4216
+ setTimeout(() => void this.mourn(peer, tries - 1), MOURN_RETRY_MS);
4217
+ }
4218
+ return;
4219
+ }
4220
+ void this.locks.request(name2, async () => {
4221
+ this.mourned.delete(peer);
4222
+ this.others.delete(peer);
4223
+ this.peers.delete(peer);
4224
+ this.rebuild();
4225
+ this.recount();
4226
+ for (const wait2 of this.waiting.values()) {
4227
+ if (wait2.left.delete(peer) && wait2.left.size === 0) wait2.done();
4228
+ }
4229
+ });
4230
+ }
4231
+ greeted(peer) {
4232
+ this.arrived(peer);
4204
4233
  const answer = () => {
4205
4234
  this.channel.postMessage({ here: this.tab, to: peer });
4206
4235
  if (this.mine.length > 0) void this.announce(this.mine);
@@ -4210,8 +4239,7 @@ var RemoteWatch = class {
4210
4239
  }
4211
4240
  announced({ tab, paths, seq: seq2 }) {
4212
4241
  const from = tab;
4213
- this.peers.add(from);
4214
- this.recount();
4242
+ this.arrived(from);
4215
4243
  if (paths.length > 0) this.others.set(from, paths);
4216
4244
  else this.others.delete(from);
4217
4245
  this.rebuild();
@@ -4819,7 +4847,8 @@ var OpfsFs = class {
4819
4847
  async linkAlong(path) {
4820
4848
  for (const entry of await this.meta.get(prefixes(path))) {
4821
4849
  if (entry?.link === void 0) continue;
4822
- if (!await this.real(entry.path) && await this.real(parentOf4(entry.path))) return entry;
4850
+ if (entry.path !== path && await this.real(entry.path)) continue;
4851
+ if (await this.real(parentOf4(entry.path))) return entry;
4823
4852
  }
4824
4853
  return void 0;
4825
4854
  }
@@ -5796,15 +5825,21 @@ var UnlinkedKeeper = class {
5796
5825
  };
5797
5826
  const unreplaced = async (path, op) => {
5798
5827
  const at = fs.resolvePath("/", path);
5828
+ const pending = async () => {
5829
+ for (let p = at; replacing.size > 0; p = parentOf5(p)) {
5830
+ await replacing.get(p)?.done;
5831
+ if (p === "/") return;
5832
+ }
5833
+ };
5799
5834
  for (let attempt = 1; ; attempt++) {
5800
- await replacing.get(at)?.done;
5835
+ await pending();
5801
5836
  const seen = keeper.replaced;
5802
5837
  try {
5803
5838
  return await op();
5804
5839
  } catch (err) {
5805
5840
  const code = err?.code;
5806
5841
  if (attempt >= 3 || code !== "ENOENT") throw err;
5807
- await replacing.get(at)?.done;
5842
+ await pending();
5808
5843
  if (keeper.replaced === seen) throw err;
5809
5844
  }
5810
5845
  }
@@ -5829,9 +5864,11 @@ var UnlinkedKeeper = class {
5829
5864
  lstat: (path) => unreplaced(path, async () => counted3(await fs.lstat(path))),
5830
5865
  async rm(path, options) {
5831
5866
  const target = fs.resolvePath("/", path);
5832
- const pinned = await keeper.pin(target);
5833
- if (pinned.moved.has(target)) pinned.commit();
5834
- else await keeper.settle(pinned, () => fs.rm(path, options));
5867
+ await replace(target, async (gated) => {
5868
+ const pinned = await keeper.pin(target, gated);
5869
+ if (pinned.moved.has(target)) pinned.commit();
5870
+ else await keeper.settle(pinned, () => fs.rm(path, options));
5871
+ });
5835
5872
  },
5836
5873
  async rename(from, to) {
5837
5874
  const target = fs.resolvePath("/", to);
@@ -5866,9 +5903,22 @@ var UnlinkedKeeper = class {
5866
5903
  return held;
5867
5904
  }
5868
5905
  async pin(target, gated = () => void 0) {
5869
- const paths = [...this.heldWithin(target).keys()].sort();
5906
+ const paths = [];
5870
5907
  const releases = [];
5871
- for (const path of paths) releases.push(await this.gate.acquire(path));
5908
+ for (; ; ) {
5909
+ const fresh2 = [...this.heldWithin(target).keys()].filter((path) => !paths.includes(path));
5910
+ if (fresh2.length === 0) break;
5911
+ fresh2.sort();
5912
+ if (paths.some((path) => path > fresh2[0])) {
5913
+ for (const release of releases.splice(0)) release();
5914
+ fresh2.push(...paths.splice(0));
5915
+ fresh2.sort();
5916
+ }
5917
+ for (const path of fresh2) {
5918
+ paths.push(path);
5919
+ releases.push(await this.gate.acquire(path));
5920
+ }
5921
+ }
5872
5922
  gated();
5873
5923
  const now = this.heldWithin(target);
5874
5924
  const held = new Map(
@@ -6541,7 +6591,7 @@ var CdpFacade = class {
6541
6591
  for (const conn of this.connections) conn.close();
6542
6592
  }
6543
6593
  async acceptLoop() {
6544
- const served = /* @__PURE__ */ new Set();
6594
+ const served2 = /* @__PURE__ */ new Set();
6545
6595
  for (; ; ) {
6546
6596
  let conn;
6547
6597
  try {
@@ -6549,10 +6599,10 @@ var CdpFacade = class {
6549
6599
  } catch {
6550
6600
  break;
6551
6601
  }
6552
- const done4 = this.serve(conn).finally(() => served.delete(done4));
6553
- served.add(done4);
6602
+ const done4 = this.serve(conn).finally(() => served2.delete(done4));
6603
+ served2.add(done4);
6554
6604
  }
6555
- await Promise.allSettled([...served]);
6605
+ await Promise.allSettled([...served2]);
6556
6606
  }
6557
6607
  async serve(conn) {
6558
6608
  this.connections.add(conn);
@@ -6944,7 +6994,7 @@ function satisfies(version, range2) {
6944
6994
  }
6945
6995
 
6946
6996
  // src/version.ts
6947
- var KERNEL_VERSION = true ? "1.124.2" : "0.0.0-dev";
6997
+ var KERNEL_VERSION = true ? "1.124.4" : "0.0.0-dev";
6948
6998
  var OS_RELEASE = "6.0.0-slicc";
6949
6999
  function procVersion() {
6950
7000
  return `Linux version ${OS_RELEASE} (slicc-kernel ${KERNEL_VERSION}) #1 SMP PREEMPT_DYNAMIC
@@ -8359,7 +8409,7 @@ var RealmProxy = class {
8359
8409
  for (const conn of this.connections) conn.close();
8360
8410
  }
8361
8411
  async acceptLoop() {
8362
- const served = /* @__PURE__ */ new Set();
8412
+ const served2 = /* @__PURE__ */ new Set();
8363
8413
  try {
8364
8414
  for (; ; ) {
8365
8415
  await this.slots.acquire(1, this.stop.signal);
@@ -8372,13 +8422,13 @@ var RealmProxy = class {
8372
8422
  }
8373
8423
  const done4 = this.serve(conn).finally(() => {
8374
8424
  this.slots.release(1);
8375
- served.delete(done4);
8425
+ served2.delete(done4);
8376
8426
  });
8377
- served.add(done4);
8427
+ served2.add(done4);
8378
8428
  }
8379
8429
  } catch {
8380
8430
  }
8381
- await Promise.allSettled([...served]);
8431
+ await Promise.allSettled([...served2]);
8382
8432
  }
8383
8433
  async serve(conn) {
8384
8434
  this.connections.add(conn);
@@ -12110,7 +12160,12 @@ var IDENTITY_OPS = /* @__PURE__ */ new Set([
12110
12160
  "chown",
12111
12161
  "lchown"
12112
12162
  ]);
12163
+ var served = 0;
12164
+ function servedFsCalls() {
12165
+ return served;
12166
+ }
12113
12167
  async function dispatchSyncFs(req) {
12168
+ served++;
12114
12169
  const entry = resolveSyncFsToken(req.token);
12115
12170
  if (!entry) return { ok: false, errno: "EACCES", message: "sync-fs: unknown or revoked token" };
12116
12171
  if (!req.identity || !IDENTITY_OPS.has(req.op)) return dispatchOne(entry, req);
@@ -12819,6 +12874,8 @@ var SYS_TREE = {
12819
12874
  slicc_wasm_memories: (listing) => `${listing.wasm?.live ?? 0} ${listing.wasm?.ceiling ?? 0} ${listing.wasm?.source ?? "none"}
12820
12875
  `,
12821
12876
  slicc_shared_root: (listing) => `${listing.peers ?? 0}
12877
+ `,
12878
+ slicc_fs_calls: (listing) => `${listing.fsCalls ?? 0}
12822
12879
  `
12823
12880
  }
12824
12881
  };
@@ -23122,7 +23179,7 @@ async function openHostfs(spec, connect2, timing = {}) {
23122
23179
  ...active?.capabilities.ranges === true ? { ranges: true } : {},
23123
23180
  ...active ? { maxIo: Math.min(active.maxIo, HOSTFS_IO) } : {}
23124
23181
  });
23125
- const served = serveFilesystem(
23182
+ const served2 = serveFilesystem(
23126
23183
  port2,
23127
23184
  { ...slot2.handlers, mount: ranged2 },
23128
23185
  {
@@ -23139,12 +23196,12 @@ async function openHostfs(spec, connect2, timing = {}) {
23139
23196
  up(client) {
23140
23197
  active = timed(client, timing.callMs ?? HOSTFS_CALL_MS);
23141
23198
  slot2.insert(client, handlers);
23142
- served.invalidate(true);
23199
+ served2.invalidate(true);
23143
23200
  },
23144
- event: (event) => served.invalidate(invalidation(event)),
23201
+ event: (event) => served2.invalidate(invalidation(event)),
23145
23202
  down() {
23146
23203
  slot2.eject();
23147
- served.invalidate(true);
23204
+ served2.invalidate(true);
23148
23205
  },
23149
23206
  ...timing
23150
23207
  },
@@ -25322,7 +25379,8 @@ var Launcher = class {
25322
25379
  load: this.loadAverage(),
25323
25380
  cpu: this.cpuTotal(),
25324
25381
  wasm: this.memories.count(),
25325
- peers: Number(this.locks.shared?.() === true)
25382
+ peers: Number(this.locks.shared?.() === true),
25383
+ fsCalls: servedFsCalls()
25326
25384
  }),
25327
25385
  sudo: (call, signal) => this.sudo(pid, call, signal),
25328
25386
  crontab: (call) => this.crontab(pid, call),
@@ -25816,7 +25874,7 @@ var Launcher = class {
25816
25874
  const worker = this.createDriverWorker();
25817
25875
  const driver = new MessageChannel();
25818
25876
  const client = new MessageChannel();
25819
- const served = serveClient(client.port1, {
25877
+ const served2 = serveClient(client.port1, {
25820
25878
  launcher: async () => this,
25821
25879
  scope: "transport"
25822
25880
  });
@@ -25828,7 +25886,7 @@ var Launcher = class {
25828
25886
  port: driver.port1,
25829
25887
  dispose: () => {
25830
25888
  worker.terminate();
25831
- served.detach();
25889
+ served2.detach();
25832
25890
  driver.port1.close();
25833
25891
  },
25834
25892
  onCrash: (listener) => worker.addEventListener("error", (event) => {
@@ -25842,12 +25900,12 @@ var Launcher = class {
25842
25900
  const ask = (handle) => this.onMountPending?.({ target, source, ...handle ? { handle } : {} });
25843
25901
  const { port1, port2 } = new MessageChannel();
25844
25902
  const medium = removableMedium((handle) => {
25845
- served.invalidate(true);
25903
+ served2.invalidate(true);
25846
25904
  ask(handle);
25847
25905
  });
25848
- const served = serveFilesystem(port2, medium.handlers, FSA_CAPABILITIES);
25906
+ const served2 = serveFilesystem(port2, medium.handlers, FSA_CAPABILITIES);
25849
25907
  const id2 = source.slice("fsa:".length);
25850
- this.removable.set(target, { id: id2, medium, served });
25908
+ this.removable.set(target, { id: id2, medium, served: served2 });
25851
25909
  const stored = this.inserted.get(id2) ?? await this.media.get(id2);
25852
25910
  if (stored && await granted(stored)) medium.insert(stored);
25853
25911
  else ask(stored);
@@ -27906,14 +27964,14 @@ async function createNodeKernel(options = {}) {
27906
27964
  throw fsError("ENOENT", `no user ${String(user)}`);
27907
27965
  }
27908
27966
  const { port1, port2 } = new MessageChannel2();
27909
- const served = serveClient(port1, {
27967
+ const served2 = serveClient(port1, {
27910
27968
  launcher: async () => launcher,
27911
27969
  signal: signalNumber,
27912
27970
  ...user !== void 0 ? { user } : {},
27913
27971
  ...tag !== void 0 ? { tag } : {}
27914
27972
  });
27915
- clients.add(served);
27916
- void served.closed.then(() => clients.delete(served));
27973
+ clients.add(served2);
27974
+ void served2.closed.then(() => clients.delete(served2));
27917
27975
  return port2;
27918
27976
  },
27919
27977
  terminate() {