@ai-ecoverse/slicc-kernel 1.159.1 → 1.159.2

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
@@ -3669,7 +3669,7 @@ function satisfies(version, range2) {
3669
3669
  }
3670
3670
 
3671
3671
  // src/version.ts
3672
- var KERNEL_VERSION = true ? "1.159.1" : "0.0.0-dev";
3672
+ var KERNEL_VERSION = true ? "1.159.2" : "0.0.0-dev";
3673
3673
  var OS_RELEASE = "6.0.0-slicc";
3674
3674
  function procVersion() {
3675
3675
  return `Linux version ${OS_RELEASE} (slicc-kernel ${KERNEL_VERSION}) #1 SMP PREEMPT_DYNAMIC
@@ -6637,9 +6637,9 @@ function withEtcFiles(fs, files) {
6637
6637
  } : {},
6638
6638
  readFile: (path) => fs.readFile(path).catch(fallback(path, (b) => new TextDecoder().decode(b))),
6639
6639
  ...fs.append ? {
6640
- append: async (path, bytes) => {
6640
+ append: async (path, bytes, options) => {
6641
6641
  if (files.has(path)) await materialize(path);
6642
- return fs.append.call(fs, path, bytes);
6642
+ return fs.append.call(fs, path, bytes, options);
6643
6643
  }
6644
6644
  } : {},
6645
6645
  readFileBuffer: (path) => fs.readFileBuffer(path).catch(fallback(path, (b) => b)),
@@ -6756,9 +6756,9 @@ var FreshModules = class {
6756
6756
  };
6757
6757
  const { append } = fs;
6758
6758
  if (append) {
6759
- overrides.append = async (path, bytes) => {
6759
+ overrides.append = async (path, bytes, options) => {
6760
6760
  const fresh3 = this.fresh.has(normalizePath(path));
6761
- const end = await append.call(fs, path, bytes);
6761
+ const end = await append.call(fs, path, bytes, options);
6762
6762
  if (fresh3 && end - bytes.length < MAGIC.length) await decide(path);
6763
6763
  return end;
6764
6764
  };
@@ -6962,9 +6962,9 @@ var ProtectedFs = class {
6962
6962
  }
6963
6963
  } : {},
6964
6964
  ...fs.append ? {
6965
- async append(path, bytes) {
6965
+ async append(path, bytes, options) {
6966
6966
  await check(path, true);
6967
- return fs.append.call(fs, path, bytes);
6967
+ return fs.append.call(fs, path, bytes, options);
6968
6968
  }
6969
6969
  } : {},
6970
6970
  ...fs.truncate ? {
@@ -7550,11 +7550,11 @@ var FsWatchers = class {
7550
7550
  };
7551
7551
  const { append } = fs;
7552
7552
  if (append) {
7553
- overrides.append = async (path, bytes) => {
7553
+ overrides.append = async (path, bytes, options) => {
7554
7554
  let end = 0;
7555
7555
  await content(
7556
7556
  async (_path) => {
7557
- end = await append.call(fs, path, bytes);
7557
+ end = await append.call(fs, path, bytes, options);
7558
7558
  },
7559
7559
  () => ["change"]
7560
7560
  )(path);
@@ -9782,15 +9782,15 @@ var MountFs = class _MountFs {
9782
9782
  );
9783
9783
  }
9784
9784
  }
9785
- async append(path, bytes, redirects = 0) {
9785
+ async append(path, bytes, options, redirects = 0) {
9786
9786
  const real = await this.follow(path, 0, true);
9787
9787
  const { append } = this.base;
9788
9788
  if (!this.at(real) && append) {
9789
9789
  return this.based(
9790
9790
  [real],
9791
9791
  redirects,
9792
- () => append.call(this.base, real, bytes),
9793
- ([to], n) => this.append(to, bytes, n)
9792
+ () => append.call(this.base, real, bytes, options),
9793
+ ([to], n) => this.append(to, bytes, options, n)
9794
9794
  );
9795
9795
  }
9796
9796
  throw errnoError("ENOTSUP", `${real}: appended by position on a mount`);
@@ -20419,7 +20419,7 @@ function heldIo(fs, nodes, changed) {
20419
20419
  path,
20420
20420
  (held) => held.append(bytes),
20421
20421
  async () => {
20422
- const end = await fs.append?.(path, bytes).catch((err) => {
20422
+ const end = await fs.append?.(path, bytes, { alone: true }).catch((err) => {
20423
20423
  if (!positional(err)) throw err;
20424
20424
  return void 0;
20425
20425
  });
@@ -23380,6 +23380,7 @@ var RemoteWatch = class {
23380
23380
  pruned = 0;
23381
23381
  joined;
23382
23382
  met;
23383
+ flushes = /* @__PURE__ */ new Map();
23383
23384
  settled = false;
23384
23385
  quiet;
23385
23386
  crowd;
@@ -23430,9 +23431,24 @@ var RemoteWatch = class {
23430
23431
  resolve2();
23431
23432
  };
23432
23433
  });
23434
+ await Promise.all([...this.flushes.values()].map((flush) => flush.promise));
23435
+ }
23436
+ flushingAt(peer) {
23437
+ if (this.locks && !this.flushes.has(peer)) {
23438
+ this.flushes.set(peer, Promise.withResolvers());
23439
+ void this.mourn(peer);
23440
+ }
23441
+ this.met?.();
23442
+ }
23443
+ flushedAt(peer) {
23444
+ this.flushes.get(peer)?.resolve();
23445
+ this.flushes.delete(peer);
23433
23446
  }
23434
23447
  async peered() {
23435
23448
  await this.joined;
23449
+ while (this.flushes.size > 0) {
23450
+ await Promise.all([...this.flushes.values()].map((flush) => flush.promise));
23451
+ }
23436
23452
  return this.peers.size > 0;
23437
23453
  }
23438
23454
  async joinedAll(cap) {
@@ -23464,7 +23480,9 @@ var RemoteWatch = class {
23464
23480
  if (data.hello !== void 0) this.greeted(data.hello);
23465
23481
  if (data.renaming !== void 0 && data.tab !== void 0) this.heard(data);
23466
23482
  if (data.renamed !== void 0) this.renamed?.(data.renamed);
23483
+ if (data.flushing !== void 0 && data.to === this.tab) this.flushingAt(data.flushing);
23467
23484
  if (data.here !== void 0 && data.to === this.tab) {
23485
+ this.flushedAt(data.here);
23468
23486
  this.arrived(data.here);
23469
23487
  this.met?.();
23470
23488
  }
@@ -23486,9 +23504,10 @@ var RemoteWatch = class {
23486
23504
  const { held = [], pending = [] } = await this.locks.query();
23487
23505
  if (![...held, ...pending].some((lock) => lock.name === name2)) {
23488
23506
  this.mourned.delete(peer);
23489
- if (tries > 1 && this.peers.has(peer)) {
23507
+ const live = this.peers.has(peer) || this.flushes.has(peer);
23508
+ if (tries > 1 && live) {
23490
23509
  setTimeout(() => void this.mourn(peer, tries - 1), MOURN_RETRY_MS);
23491
- }
23510
+ } else this.flushedAt(peer);
23492
23511
  return;
23493
23512
  }
23494
23513
  void this.locks.request(name2, async () => {
@@ -23496,6 +23515,7 @@ var RemoteWatch = class {
23496
23515
  this.others.delete(peer);
23497
23516
  this.peers.delete(peer);
23498
23517
  this.ackers.delete(peer);
23518
+ this.flushedAt(peer);
23499
23519
  this.rebuild();
23500
23520
  this.recount();
23501
23521
  this.gone?.();
@@ -23510,8 +23530,12 @@ var RemoteWatch = class {
23510
23530
  this.channel.postMessage({ here: this.tab, to: peer, renames: true });
23511
23531
  if (this.mine.length > 0) void this.announce(this.mine);
23512
23532
  };
23513
- if (this.quiet) void this.quiet().then(answer2, answer2);
23514
- else answer2();
23533
+ if (!this.quiet) {
23534
+ answer2();
23535
+ return;
23536
+ }
23537
+ this.channel.postMessage({ flushing: this.tab, to: peer });
23538
+ void this.quiet().then(answer2, answer2);
23515
23539
  }
23516
23540
  heard({ tab, renaming, seq: seq2 }) {
23517
23541
  const ack = () => this.channel.postMessage({ ack: seq2, from: this.tab, to: tab });
@@ -25210,7 +25234,10 @@ var OpfsFs = class {
25210
25234
  this.channel = channel === void 0 ? void 0 : new BroadcastChannel(channel);
25211
25235
  this.remote = channel === void 0 ? void 0 : new RemoteWatch(`${channel}:watch`, { locks: this.locks ?? null });
25212
25236
  if (this.remote) {
25213
- this.remote.quiet = () => this.quiet().then(() => this.settle?.());
25237
+ this.remote.quiet = () => {
25238
+ const pending = [...this.inFlight];
25239
+ return this.quiet().then(() => Promise.all(pending)).then(() => this.settle?.());
25240
+ };
25214
25241
  this.remote.gone = () => {
25215
25242
  void this.orphans();
25216
25243
  for (const move of [...this.peerMoves.values()]) void this.peerMoved(move);
@@ -25994,7 +26021,7 @@ var OpfsFs = class {
25994
26021
  async pwrite(path, offset, bytes, _transfer, options) {
25995
26022
  const at = normalizePath(path);
25996
26023
  const movedAway = this.renamesInFlight() ? await this.writeWaits(at) : false;
25997
- this.fileWrites.set(at, (this.fileWrites.get(at) ?? 0) + 1);
26024
+ const ended = this.writeStarted(at);
25998
26025
  try {
25999
26026
  const [kept, target, existed] = await this.keptFor(path);
26000
26027
  if (kept) {
@@ -26012,7 +26039,7 @@ var OpfsFs = class {
26012
26039
  );
26013
26040
  await this.writeAt(handle, target, path, offset, bytes);
26014
26041
  } finally {
26015
- this.writeEnded(at);
26042
+ ended();
26016
26043
  }
26017
26044
  }
26018
26045
  async keptFor(path) {
@@ -26066,6 +26093,17 @@ var OpfsFs = class {
26066
26093
  }
26067
26094
  return away;
26068
26095
  }
26096
+ inFlight = /* @__PURE__ */ new Set();
26097
+ writeStarted(at) {
26098
+ this.fileWrites.set(at, (this.fileWrites.get(at) ?? 0) + 1);
26099
+ const { promise, resolve: resolve2 } = Promise.withResolvers();
26100
+ this.inFlight.add(promise);
26101
+ return () => {
26102
+ this.inFlight.delete(promise);
26103
+ resolve2();
26104
+ this.writeEnded(at);
26105
+ };
26106
+ }
26069
26107
  writeEnded(at) {
26070
26108
  const left = (this.fileWrites.get(at) ?? 1) - 1;
26071
26109
  if (left > 0) this.fileWrites.set(at, left);
@@ -26096,20 +26134,22 @@ var OpfsFs = class {
26096
26134
  async truncate(path, size) {
26097
26135
  const at = normalizePath(path);
26098
26136
  if (this.renamesInFlight()) await this.writeWaits(at);
26099
- this.fileWrites.set(at, (this.fileWrites.get(at) ?? 0) + 1);
26137
+ const ended = this.writeStarted(at);
26100
26138
  try {
26101
26139
  await this.ending(path, () => this.truncated(path, size));
26102
26140
  } finally {
26103
- this.writeEnded(at);
26141
+ ended();
26104
26142
  }
26105
26143
  }
26106
- async append(path, bytes) {
26107
- if (!this.locks || !this.remote || !this.shared()) {
26144
+ async append(path, bytes, options) {
26145
+ const crowded = this.locks !== void 0 && this.remote !== void 0 && this.shared();
26146
+ if (!crowded && options?.alone !== true) {
26108
26147
  throw fsError("ENOTSUP", `${path}: appended by position while no other tab shares the root`);
26109
26148
  }
26149
+ if (crowded) await this.remote?.peered();
26110
26150
  const at = normalizePath(path);
26111
26151
  if (this.renamesInFlight()) await this.writeWaits(at);
26112
- this.fileWrites.set(at, (this.fileWrites.get(at) ?? 0) + 1);
26152
+ const ended = this.writeStarted(at);
26113
26153
  try {
26114
26154
  const found = await this.locate(path, true);
26115
26155
  if (found.handle?.kind !== "file") throw fsError(found.handle ? "EISDIR" : "ENOENT", path);
@@ -26123,7 +26163,7 @@ var OpfsFs = class {
26123
26163
  return end + bytes.length;
26124
26164
  });
26125
26165
  } finally {
26126
- this.writeEnded(at);
26166
+ ended();
26127
26167
  }
26128
26168
  }
26129
26169
  async ending(path, op) {