@ai-ecoverse/slicc-kernel 1.133.2 → 1.133.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
@@ -4161,6 +4161,7 @@ var RemoteWatch = class {
4161
4161
  settled = false;
4162
4162
  quiet;
4163
4163
  crowd;
4164
+ gone;
4164
4165
  told;
4165
4166
  counted = 0;
4166
4167
  recount() {
@@ -4250,6 +4251,7 @@ var RemoteWatch = class {
4250
4251
  this.peers.delete(peer);
4251
4252
  this.rebuild();
4252
4253
  this.recount();
4254
+ this.gone?.();
4253
4255
  for (const wait2 of this.waiting.values()) {
4254
4256
  if (wait2.left.delete(peer) && wait2.left.size === 0) wait2.done();
4255
4257
  }
@@ -4285,14 +4287,16 @@ var RemoteWatch = class {
4285
4287
  async prune() {
4286
4288
  if (!this.locks) return;
4287
4289
  const held = new Set(((await this.locks.query()).held ?? []).map((lock) => lock.name));
4290
+ let left = false;
4288
4291
  for (const tab of /* @__PURE__ */ new Set([...this.others.keys(), ...this.peers])) {
4289
4292
  if (!held.has(this.lockOf(tab))) {
4293
+ if (this.peers.delete(tab)) left = true;
4290
4294
  this.others.delete(tab);
4291
- this.peers.delete(tab);
4292
4295
  }
4293
4296
  }
4294
4297
  this.rebuild();
4295
4298
  this.recount();
4299
+ if (left) this.gone?.();
4296
4300
  }
4297
4301
  watched() {
4298
4302
  return this.union.size > 0;
@@ -4382,6 +4386,7 @@ var REPLACED_ATTEMPTS = 4;
4382
4386
  var RECONCILE_LISTINGS = 8;
4383
4387
  var EXECUTABLE = /\/node_modules\/(?:@[^/]+\/)?[^/]+\/bin\//;
4384
4388
  var RENAMES = "/.slicc-renames";
4389
+ var RENAME_LOCK = "slicc-rename:";
4385
4390
  function movable(handle) {
4386
4391
  return typeof handle.move === "function";
4387
4392
  }
@@ -4544,8 +4549,11 @@ var OpfsFs = class {
4544
4549
  this.lockPrefix = `slicc-excl:${channel ?? ""}:`;
4545
4550
  this.rootName = channel;
4546
4551
  this.channel = channel === void 0 ? void 0 : new BroadcastChannel(channel);
4547
- this.remote = channel === void 0 ? void 0 : new RemoteWatch(`${channel}:watch`);
4548
- if (this.remote) this.remote.quiet = () => this.quiet().then(() => this.settle?.());
4552
+ this.remote = channel === void 0 ? void 0 : new RemoteWatch(`${channel}:watch`, { locks: this.locks ?? null });
4553
+ if (this.remote) {
4554
+ this.remote.quiet = () => this.quiet().then(() => this.settle?.());
4555
+ this.remote.gone = () => void this.orphans();
4556
+ }
4549
4557
  if (this.channel) {
4550
4558
  const remote = this.remote;
4551
4559
  meta.listen?.((c) => {
@@ -5618,14 +5626,17 @@ var OpfsFs = class {
5618
5626
  const dir = parent.handle;
5619
5627
  const name2 = baseOf(destination);
5620
5628
  const swap = targetStat?.isDirectory === true;
5629
+ let lock;
5621
5630
  const staging = swap ? `.${name2}.${crypto.randomUUID()}` : name2;
5622
5631
  const copying = sourceStat.isDirectory && !movable(source.handle);
5623
5632
  const staged = resolvePath(parent.path, staging);
5624
5633
  const place = async () => {
5625
5634
  this.forget(destination);
5626
5635
  const timed2 = await this.explicitTimes(source.path);
5627
- const first = copying ? await this.intend({ from: source.path, to: staged }) : void 0;
5628
- const second = copying && swap ? await this.intend({ from: staged, to: destination, replace: true }) : void 0;
5636
+ const root = { ino: inodeOf(source.path), ...moving };
5637
+ const owned4 = lock ? { lock } : {};
5638
+ const first = copying ? await this.intend({ from: source.path, to: staged, root, ...owned4 }) : void 0;
5639
+ const second = copying && swap ? await this.intend({ from: staged, to: destination, replace: true, root, ...owned4 }) : void 0;
5629
5640
  const moved2 = await this.replacingTarget(
5630
5641
  targetStat !== null,
5631
5642
  () => this.place(source.handle, dir, staging)
@@ -5634,7 +5645,7 @@ var OpfsFs = class {
5634
5645
  throw err;
5635
5646
  });
5636
5647
  if (swap) await this.rm(destination, { recursive: true });
5637
- if (second) await this.intend({ from: staged, to: destination }, second);
5648
+ if (second) await this.intend({ from: staged, to: destination, root, ...owned4 }, second);
5638
5649
  await this.meta.move(source.path, destination, carry, left);
5639
5650
  this.movePending(source.path, destination);
5640
5651
  if (!moved2) {
@@ -5659,7 +5670,11 @@ var OpfsFs = class {
5659
5670
  const entry = { from: source.path, to: destination, done: promise };
5660
5671
  this.renamingDirs.add(entry);
5661
5672
  try {
5662
- await place();
5673
+ const locks = this.locks;
5674
+ if (locks) {
5675
+ lock = `${RENAME_LOCK}${crypto.randomUUID()}`;
5676
+ await locks.request(lock, place);
5677
+ } else await place();
5663
5678
  } finally {
5664
5679
  this.renamingDirs.delete(entry);
5665
5680
  resolve2();
@@ -5691,12 +5706,40 @@ var OpfsFs = class {
5691
5706
  } catch {
5692
5707
  }
5693
5708
  }
5694
- async finishRenames() {
5695
- const intents = (await this.meta.under(RENAMES)).filter((entry) => entry.rename !== void 0).sort(
5709
+ replaying = Promise.resolve();
5710
+ orphans() {
5711
+ this.replaying = this.replaying.then(() => this.finishRenames(true)).catch(() => 0);
5712
+ return this.replaying;
5713
+ }
5714
+ async finishRenames(orphaned = false) {
5715
+ const locks = this.locks;
5716
+ const held = /* @__PURE__ */ new Set();
5717
+ if (orphaned && locks) {
5718
+ const { held: h = [], pending = [] } = await locks.query();
5719
+ for (const lock of [...h, ...pending]) held.add(lock.name);
5720
+ }
5721
+ const intents = (await this.meta.under(RENAMES)).filter(
5722
+ (entry) => entry.rename !== void 0 && (!orphaned || locks !== void 0 && entry.rename.lock !== void 0 && !held.has(entry.rename.lock))
5723
+ ).sort(
5696
5724
  (a, b) => a.rename.at - b.rename.at
5697
5725
  );
5698
5726
  for (const entry of intents) {
5699
- const { from, to, replace } = entry.rename;
5727
+ const lock = entry.rename.lock;
5728
+ if (!orphaned || !locks || !lock) await this.finishRename(entry);
5729
+ else await locks.request(lock, () => this.finishRename(entry));
5730
+ }
5731
+ return intents.length;
5732
+ }
5733
+ async finishRename(entry) {
5734
+ const [current] = await this.meta.under(entry.path);
5735
+ if (current?.rename === void 0) return;
5736
+ const { from, to, replace, root } = current.rename;
5737
+ const { promise, resolve: resolve2 } = Promise.withResolvers();
5738
+ const barrier = { from, to, done: promise };
5739
+ this.renamingDirs.add(barrier);
5740
+ this.forget(from);
5741
+ this.forget(to);
5742
+ try {
5700
5743
  const left = await this.real(from);
5701
5744
  if (left && replace && await this.real(to)) await this.rm(to, { recursive: true });
5702
5745
  if (left) {
@@ -5713,11 +5756,23 @@ var OpfsFs = class {
5713
5756
  this.forget(to);
5714
5757
  }
5715
5758
  if ((await this.meta.under(from)).length > 0) {
5716
- await this.meta.move(from, to, (moved2) => ({ ...occupied(moved2), path: to }));
5759
+ await this.meta.move(
5760
+ from,
5761
+ to,
5762
+ (moved2) => ({
5763
+ ...occupied(moved2),
5764
+ ...root,
5765
+ ino: occupied(moved2).ino ?? root?.ino ?? inodeOf(from),
5766
+ path: to
5767
+ }),
5768
+ void 0
5769
+ );
5717
5770
  }
5718
5771
  await this.meta.update(entry.path, () => void 0);
5772
+ } finally {
5773
+ this.renamingDirs.delete(barrier);
5774
+ resolve2();
5719
5775
  }
5720
- return intents.length;
5721
5776
  }
5722
5777
  async settledRename(path) {
5723
5778
  if (this.renamingDirs.size === 0 && this.copying.size === 0 || typeof path !== "string")
@@ -6001,7 +6056,10 @@ var OpfsFs = class {
6001
6056
  };
6002
6057
  }
6003
6058
  async reconcile() {
6004
- if (this.remote && await this.remote.peered()) return 0;
6059
+ if (this.remote && await this.remote.peered()) {
6060
+ await this.orphans();
6061
+ return 0;
6062
+ }
6005
6063
  await this.finishRenames();
6006
6064
  let removed = 0;
6007
6065
  const entries = await this.meta.all();
@@ -7403,7 +7461,7 @@ function satisfies(version, range2) {
7403
7461
  }
7404
7462
 
7405
7463
  // src/version.ts
7406
- var KERNEL_VERSION = true ? "1.133.2" : "0.0.0-dev";
7464
+ var KERNEL_VERSION = true ? "1.133.4" : "0.0.0-dev";
7407
7465
  var OS_RELEASE = "6.0.0-slicc";
7408
7466
  function procVersion() {
7409
7467
  return `Linux version ${OS_RELEASE} (slicc-kernel ${KERNEL_VERSION}) #1 SMP PREEMPT_DYNAMIC
@@ -19342,10 +19400,32 @@ var KEY_ERRORS = [
19342
19400
  [-15232, "ERR_OSSL_BAD_DECRYPT"],
19343
19401
  [-15360, "ERR_OSSL_CRYPTO_INTERRUPTED_OR_CANCELLED"]
19344
19402
  ];
19345
- function keyRefused(err) {
19346
- const code = err instanceof TlsError ? err.code : 0;
19403
+ var PBE_OIDS = [
19404
+ [42, 134, 72, 134, 247, 13, 1, 5],
19405
+ [42, 134, 72, 134, 247, 13, 1, 12, 1]
19406
+ ];
19407
+ function hasBytes(hay, needle) {
19408
+ for (let i = 0; i + needle.length <= hay.length; i++) {
19409
+ if (needle.every((b, j) => hay[i + j] === b)) return true;
19410
+ }
19411
+ return false;
19412
+ }
19413
+ function encryptedKey(key) {
19414
+ if (key[0] === 48) return PBE_OIDS.some((oid2) => hasBytes(key, oid2));
19415
+ return new TextDecoder().decode(key).includes("ENCRYPTED");
19416
+ }
19417
+ var KEY_PARSE_RANGES = [
19418
+ [-16383, -14336],
19419
+ [-5375, -4096],
19420
+ [-28671, -24576],
19421
+ [-127, -96]
19422
+ ];
19423
+ var keyParse = (code) => code !== -15360 && KEY_PARSE_RANGES.some(([lo, hi]) => code >= lo && code <= hi);
19424
+ function keyRefused(err, locked) {
19425
+ const raw2 = err instanceof TlsError ? err.code : 0;
19426
+ const code = locked && keyParse(raw2) ? -15232 : raw2;
19347
19427
  const name2 = KEY_ERRORS.find(([n]) => n === code)?.[1] ?? "ERR_OSSL_UNSUPPORTED";
19348
- const text = code === -3 ? "the key does not match the certificate" : err.message;
19428
+ const text = code === -3 ? "the key does not match the certificate" : code === raw2 ? err.message : "bad decrypt";
19349
19429
  return new KernelError("EPROTO", `${name2}: ${text}`);
19350
19430
  }
19351
19431
  function takeCert(req) {
@@ -19376,7 +19456,7 @@ function withCert(session, cert) {
19376
19456
  try {
19377
19457
  session.ownCert(cert.chain, cert.key, cert.pass);
19378
19458
  } catch (err) {
19379
- throw keyRefused(err);
19459
+ throw keyRefused(err, cert.pass.length > 0 && encryptedKey(cert.key));
19380
19460
  }
19381
19461
  }
19382
19462
  function wipe(cert) {