@ai-ecoverse/slicc-kernel 1.159.1 → 1.159.3

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