@ai-ecoverse/slicc-kernel 1.124.13 → 1.125.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.
@@ -605,7 +605,7 @@ function parseSyncFsStat(json2) {
605
605
  ...typeof s.gid === "number" ? { gid: s.gid } : {}
606
606
  };
607
607
  }
608
- var SYNC_FS_OPS, HOLD_READ, HOLD_WRITE, HOLD_CREATED, SYNC_FS_REQUEST_TIMEOUT_MS;
608
+ var SYNC_FS_OPS, HOLD_READ, HOLD_WRITE, HOLD_CREATED, SYNC_FS_REQUEST_TIMEOUT_MS, SYNC_FS_READ_ONLY;
609
609
  var init_sync_fs_wire = __esm({
610
610
  "src/realm/sync-fs-wire.ts"() {
611
611
  "use strict";
@@ -645,6 +645,19 @@ var init_sync_fs_wire = __esm({
645
645
  HOLD_WRITE = 8;
646
646
  HOLD_CREATED = 16;
647
647
  SYNC_FS_REQUEST_TIMEOUT_MS = 25e3;
648
+ SYNC_FS_READ_ONLY = /* @__PURE__ */ new Set([
649
+ "read",
650
+ "pread",
651
+ "exists",
652
+ "stat",
653
+ "lstat",
654
+ "readdir",
655
+ "readdir-stat",
656
+ "readlink",
657
+ "statfs",
658
+ "kept",
659
+ "access"
660
+ ]);
648
661
  }
649
662
  });
650
663
 
@@ -864,7 +877,7 @@ function cachingBridge(bridge, now = () => performance.now(), shared) {
864
877
  mkdir: (p) => mutating(() => bridge.mkdir(p), ...entry(p)),
865
878
  rm: (p) => mutating(() => bridge.rm(p)),
866
879
  rename: (from, to) => mutating(() => bridge.rename(from, to)),
867
- link: (from, to, follow2) => mutating(() => bridge.link(from, to, follow2)),
880
+ link: (from, to, follow3) => mutating(() => bridge.link(from, to, follow3)),
868
881
  unlink: (p) => mutating(() => bridge.unlink(p)),
869
882
  rmdir: (p) => mutating(() => bridge.rmdir(p)),
870
883
  symlink: (target, link) => mutating(() => bridge.symlink(target, link), ...entry(link)),
@@ -2264,7 +2277,7 @@ function devFdStat(fd) {
2264
2277
  function linkStat(target) {
2265
2278
  return nodeStat(LINK | 511, target.length);
2266
2279
  }
2267
- function* devStat(abs, follow2) {
2280
+ function* devStat(abs, follow3) {
2268
2281
  const node = yield* lookup(abs);
2269
2282
  switch (node.kind) {
2270
2283
  case "dir":
@@ -2277,10 +2290,10 @@ function* devStat(abs, follow2) {
2277
2290
  case "terminal":
2278
2291
  return yield* terminalStat(node.name);
2279
2292
  case "link":
2280
- if (!follow2) return linkStat(node.target);
2293
+ if (!follow3) return linkStat(node.target);
2281
2294
  return node.fd === void 0 ? nodeStat(DIR | 365) : yield* fdStat(node.fd, abs);
2282
2295
  case "fd":
2283
- return follow2 ? yield* fdStat(node.fd, abs) : linkStat(yield* fdTarget(node.fd, abs));
2296
+ return follow3 ? yield* fdStat(node.fd, abs) : linkStat(yield* fdTarget(node.fd, abs));
2284
2297
  }
2285
2298
  }
2286
2299
  function* devExists(abs) {
@@ -3741,7 +3754,7 @@ function writeEvents(mem, ptr, events) {
3741
3754
  v.setUint16(p + 8, ev.error, true);
3742
3755
  v.setUint8(p + 10, ev.type);
3743
3756
  if (ev.type !== EVENTTYPE.CLOCK) {
3744
- v.setBigUint64(p + 16, 1n, true);
3757
+ v.setBigUint64(p + 16, BigInt(ev.nbytes ?? 1), true);
3745
3758
  if (ev.hangup) v.setUint16(p + 24, EVENT_FD_READWRITE_HANGUP, true);
3746
3759
  }
3747
3760
  });
@@ -3760,6 +3773,10 @@ function classify(fds, subs) {
3760
3773
  }
3761
3774
  return { events, read: read2, write: write2 };
3762
3775
  }
3776
+ function nbytesOf(s, ready) {
3777
+ const n = s.type === EVENTTYPE.FD_READ ? ready.nread?.[s.fd] : void 0;
3778
+ return n === void 0 ? {} : { nbytes: n };
3779
+ }
3763
3780
  function readyEvents(subs, ready) {
3764
3781
  return subs.filter(
3765
3782
  (s) => s.type === EVENTTYPE.FD_READ && ready.read.includes(s.fd) || s.type === EVENTTYPE.FD_WRITE && ready.write.includes(s.fd)
@@ -3767,7 +3784,8 @@ function readyEvents(subs, ready) {
3767
3784
  userdata: s.userdata,
3768
3785
  error: E.SUCCESS,
3769
3786
  type: s.type,
3770
- hangup: ready.hangup?.includes(s.fd) === true
3787
+ hangup: ready.hangup?.includes(s.fd) === true,
3788
+ ...nbytesOf(s, ready)
3771
3789
  }));
3772
3790
  }
3773
3791
  function selectOnce(deps, read2, write2, timeoutMs2) {
@@ -4734,10 +4752,10 @@ var init_wasi_host = __esm({
4734
4752
  return path;
4735
4753
  };
4736
4754
  const modeOf2 = (st) => (st.mode ?? 0) & 4095;
4737
- const chown = (path, uid, gid, follow2, handle) => {
4755
+ const chown = (path, uid, gid, follow3, handle) => {
4738
4756
  const { chown: own } = this.o.fs;
4739
4757
  if (!own) throw new WasiError("ENOSYS");
4740
- own.call(this.o.fs, path, idOf(uid), idOf(gid), follow2, handle);
4758
+ own.call(this.o.fs, path, idOf(uid), idOf(gid), follow3, handle);
4741
4759
  };
4742
4760
  const caller = () => {
4743
4761
  const cred = this.creds.get();
@@ -4777,16 +4795,16 @@ var init_wasi_host = __esm({
4777
4795
  return devSync(dev, devFdStat(fd)).mode ?? DEVICE_MODE;
4778
4796
  return modeOf2(this.o.fs.stat(pathOf(fd)));
4779
4797
  };
4780
- const pathOwned = (path, follow2) => {
4798
+ const pathOwned = (path, follow3) => {
4781
4799
  const alias = this.fdAlias(path);
4782
- if (alias && !follow2) return alias.stdio ? ROOT_IDS : void 0;
4800
+ if (alias && !follow3) return alias.stdio ? ROOT_IDS : void 0;
4783
4801
  if (alias) {
4784
4802
  this.openFd(alias.fd);
4785
4803
  return fdOwned(alias.fd);
4786
4804
  }
4787
4805
  if (this.synthetic(path)) return ROOT_IDS;
4788
- if (kernelDev(path)) return devSync(dev, devStat(path, follow2));
4789
- return follow2 ? this.o.fs.stat(path) : this.o.fs.lstat(path);
4806
+ if (kernelDev(path)) return devSync(dev, devStat(path, follow3));
4807
+ return follow3 ? this.o.fs.stat(path) : this.o.fs.lstat(path);
4790
4808
  };
4791
4809
  return wrap({
4792
4810
  fd_chown: (fd, uid, gid) => {
@@ -5182,7 +5200,7 @@ var init_wasi_host = __esm({
5182
5200
  const at = (dirfd, p, l) => fds.resolve(dirfd, mem.string(p, l));
5183
5201
  return {
5184
5202
  path_open: (dirfd, lookup2, p, l, oflags, rights, _inheriting, fdflags, out) => {
5185
- const follow2 = (lookup2 & LOOKUP_SYMLINK_FOLLOW) !== 0;
5203
+ const follow3 = (lookup2 & LOOKUP_SYMLINK_FOLLOW) !== 0;
5186
5204
  try {
5187
5205
  const asked = at(dirfd, p, l);
5188
5206
  const alias = this.fdAlias(asked);
@@ -5196,7 +5214,7 @@ var init_wasi_host = __esm({
5196
5214
  if (err.code !== "ENOENT") throw err;
5197
5215
  const raw = mem.string(p, l);
5198
5216
  const joined2 = raw.startsWith("/") ? raw : `${fds.dir(dirfd).path}/${raw}`;
5199
- const resolved2 = this.resolveForDev(joined2, follow2);
5217
+ const resolved2 = this.resolveForDev(joined2, follow3);
5200
5218
  if (!resolved2) throw err;
5201
5219
  mem.view().setUint32(out, fds.open(resolved2, oflags, rights, fdflags), true);
5202
5220
  }
@@ -5259,11 +5277,11 @@ var init_wasi_host = __esm({
5259
5277
  path_link: (fd, lookup2, p, l, fd2, p2, l2) => {
5260
5278
  const from = at(fd, p, l);
5261
5279
  const to = at(fd2, p2, l2);
5262
- const follow2 = (lookup2 & LOOKUP_SYMLINK_FOLLOW) !== 0;
5263
- const source = follow2 ? physicalPath(o.fs, from) : from;
5280
+ const follow3 = (lookup2 & LOOKUP_SYMLINK_FOLLOW) !== 0;
5281
+ const source = follow3 ? physicalPath(o.fs, from) : from;
5264
5282
  fds.flushPath(from);
5265
5283
  if (source !== from) fds.flushPath(source);
5266
- o.fs.link(from, to, follow2);
5284
+ o.fs.link(from, to, follow3);
5267
5285
  fds.linked(from, to);
5268
5286
  if (source !== from) fds.linked(source, to);
5269
5287
  }
@@ -5576,18 +5594,18 @@ var init_wasi_host = __esm({
5576
5594
  synthetic(path) {
5577
5595
  return deviceOf(path) !== void 0 || path === SEALED_PATH && !!this.o.kernel.sys.openSealed || path === CLIPBOARD_PATH && !!this.o.kernel.sys.openClipboard;
5578
5596
  }
5579
- devChar(path, follow2) {
5597
+ devChar(path, follow3) {
5580
5598
  try {
5581
5599
  const json2 = (req) => this.o.kernel.call(req);
5582
- const st = devSync({ json: json2 }, devStat(path, follow2));
5600
+ const st = devSync({ json: json2 }, devStat(path, follow3));
5583
5601
  return ((st.mode ?? 0) & 61440) === 8192;
5584
5602
  } catch {
5585
5603
  return false;
5586
5604
  }
5587
5605
  }
5588
- resolveForDev(path, follow2 = true) {
5606
+ resolveForDev(path, follow3 = true) {
5589
5607
  try {
5590
- if (!follow2) {
5608
+ if (!follow3) {
5591
5609
  const slash = path.lastIndexOf("/");
5592
5610
  if (slash <= 0) return void 0;
5593
5611
  const parent = physicalPath(this.o.fs, path.slice(0, slash));
@@ -5678,12 +5696,12 @@ var init_wasi_host = __esm({
5678
5696
  });
5679
5697
  }
5680
5698
  this.fds.flushPath(path);
5681
- const follow2 = (lookup2 & LOOKUP_SYMLINK_FOLLOW) !== 0;
5699
+ const follow3 = (lookup2 & LOOKUP_SYMLINK_FOLLOW) !== 0;
5682
5700
  try {
5683
- return filestatOf(path, follow2 ? this.o.fs.stat(path) : this.o.fs.lstat(path));
5701
+ return filestatOf(path, follow3 ? this.o.fs.stat(path) : this.o.fs.lstat(path));
5684
5702
  } catch (err) {
5685
5703
  if (err.code !== "ENOENT") throw err;
5686
- if (kernelDev(path) && this.devChar(path, follow2)) {
5704
+ if (kernelDev(path) && this.devChar(path, follow3)) {
5687
5705
  return this.local({
5688
5706
  filetype: FILETYPE.CHARACTER_DEVICE,
5689
5707
  size: 0n,
@@ -5691,7 +5709,7 @@ var init_wasi_host = __esm({
5691
5709
  mtimeNs: 0n
5692
5710
  });
5693
5711
  }
5694
- const resolved2 = this.resolveForDev(path, follow2);
5712
+ const resolved2 = this.resolveForDev(path, follow3);
5695
5713
  if (!resolved2) throw err;
5696
5714
  return this.local({
5697
5715
  filetype: FILETYPE.CHARACTER_DEVICE,
@@ -5701,18 +5719,18 @@ var init_wasi_host = __esm({
5701
5719
  });
5702
5720
  }
5703
5721
  }
5704
- setTimes(path, atim, mtim, flags, follow2 = true) {
5722
+ setTimes(path, atim, mtim, flags, follow3 = true) {
5705
5723
  const asked = FSTFLAGS.ATIM | FSTFLAGS.ATIM_NOW | FSTFLAGS.MTIM | FSTFLAGS.MTIM_NOW;
5706
5724
  if (this.o.fs.owners && (flags & asked) === 0) return;
5707
5725
  const now = Date.now();
5708
5726
  let current;
5709
- const statOf = follow2 ? this.o.fs.stat.bind(this.o.fs) : this.o.fs.lstat.bind(this.o.fs);
5727
+ const statOf = follow3 ? this.o.fs.stat.bind(this.o.fs) : this.o.fs.lstat.bind(this.o.fs);
5710
5728
  const kept = (field2) => {
5711
5729
  current ??= statOf(path);
5712
5730
  return current[field2] ?? current.mtimeMs ?? now;
5713
5731
  };
5714
5732
  const pick = (set, setNow, value2, field2) => flags & setNow ? now : flags & set ? Number(value2 / NS_PER_MS4) : kept(field2);
5715
- (follow2 ? this.o.fs.utimes : this.o.fs.lutimes).call(
5733
+ (follow3 ? this.o.fs.utimes : this.o.fs.lutimes).call(
5716
5734
  this.o.fs,
5717
5735
  path,
5718
5736
  pick(FSTFLAGS.ATIM, FSTFLAGS.ATIM_NOW, atim, "atimeMs"),
@@ -6253,7 +6271,7 @@ var KERNEL_VERSION, OS_RELEASE;
6253
6271
  var init_version = __esm({
6254
6272
  "src/version.ts"() {
6255
6273
  "use strict";
6256
- KERNEL_VERSION = true ? "1.124.13" : "0.0.0-dev";
6274
+ KERNEL_VERSION = true ? "1.125.1" : "0.0.0-dev";
6257
6275
  OS_RELEASE = "6.0.0-slicc";
6258
6276
  }
6259
6277
  });
@@ -6914,8 +6932,8 @@ function fetchOp(kernel) {
6914
6932
  for (let hops = 0; ; hops++) {
6915
6933
  const head = await send(hop, signal);
6916
6934
  const location = head.headers.find(([name2]) => name2.toLowerCase() === "location")?.[1];
6917
- const follow2 = known.manualRedirects && REDIRECTS.has(head.status) && location !== void 0 && request.redirect !== "manual";
6918
- if (!follow2) {
6935
+ const follow3 = known.manualRedirects && REDIRECTS.has(head.status) && location !== void 0 && request.redirect !== "manual";
6936
+ if (!follow3) {
6919
6937
  const redirected = hops > 0 || head.redirected === true;
6920
6938
  return respond(head, hop.method, redirected, known.encodedBodies, request);
6921
6939
  }
@@ -7533,7 +7551,7 @@ function createSyncFsSabBridge(transport, opts = {}) {
7533
7551
  let last = null;
7534
7552
  function run(req, path, transfer) {
7535
7553
  last = null;
7536
- const silence = READ_ONLY.has(req.op) ? timeoutMs2 : Number.POSITIVE_INFINITY;
7554
+ const silence = SYNC_FS_READ_ONLY.has(req.op) ? timeoutMs2 : Number.POSITIVE_INFINITY;
7537
7555
  const result = transport.call(req, silence, `sync-sab bridge, '${path}'`, transfer);
7538
7556
  if (!result.ok) throw errnoError(result.errno, path);
7539
7557
  return result;
@@ -7622,8 +7640,8 @@ function createSyncFsSabBridge(transport, opts = {}) {
7622
7640
  rename: (from, to) => {
7623
7641
  run({ op: "rename", path: from, arg2: to }, from);
7624
7642
  },
7625
- link: (from, to, follow2) => {
7626
- run({ op: "link", path: from, arg2: to, ...follow2 ? { mode: 1 } : {} }, from);
7643
+ link: (from, to, follow3) => {
7644
+ run({ op: "link", path: from, arg2: to, ...follow3 ? { mode: 1 } : {} }, from);
7627
7645
  },
7628
7646
  unlink: (path) => {
7629
7647
  run({ op: "unlink", path }, path);
@@ -7666,11 +7684,11 @@ function createSyncFsSabBridge(transport, opts = {}) {
7666
7684
  const flags = { ...mode !== void 0 ? { mode } : {}, ...opening2 ? { opening: opening2 } : {} };
7667
7685
  run({ op: "create", path, ...flags }, path);
7668
7686
  },
7669
- chown: (path, uid, gid, follow2, handle) => {
7687
+ chown: (path, uid, gid, follow3, handle) => {
7670
7688
  const ids = { ...uid !== void 0 ? { uid } : {}, ...gid !== void 0 ? { gid } : {} };
7671
7689
  changing(
7672
7690
  {
7673
- op: follow2 ? "chown" : "lchown",
7691
+ op: follow3 ? "chown" : "lchown",
7674
7692
  path,
7675
7693
  ...ids,
7676
7694
  ...handle !== void 0 ? { handle } : {}
@@ -7696,7 +7714,7 @@ function createSyncFsSabBridge(transport, opts = {}) {
7696
7714
  statfs: (path = "/") => parseSyncFsUsage(json2({ op: "statfs", path }, path))
7697
7715
  };
7698
7716
  }
7699
- var PATH_OPS, READ_ONLY, calls, looks, SPIN_MS, SPIN_STRIDE, SPIN_STRIDES, SPIN_CORES, spinning, SPIN_CAP_MS;
7717
+ var PATH_OPS, calls, looks, SPIN_MS, SPIN_STRIDE, SPIN_STRIDES, SPIN_CORES, spinning, SPIN_CAP_MS;
7700
7718
  var init_sync_sab_bridge = __esm({
7701
7719
  "src/realm/sync-sab-bridge.ts"() {
7702
7720
  "use strict";
@@ -7705,19 +7723,6 @@ var init_sync_sab_bridge = __esm({
7705
7723
  init_sync_fs_wire();
7706
7724
  init_sync_sab_wire();
7707
7725
  PATH_OPS = new Set(SYNC_FS_OPS);
7708
- READ_ONLY = /* @__PURE__ */ new Set([
7709
- "read",
7710
- "pread",
7711
- "exists",
7712
- "stat",
7713
- "lstat",
7714
- "readdir",
7715
- "readdir-stat",
7716
- "readlink",
7717
- "statfs",
7718
- "kept",
7719
- "access"
7720
- ]);
7721
7726
  calls = 0;
7722
7727
  looks = 0;
7723
7728
  SPIN_MS = 0.06;
@@ -8701,9 +8706,9 @@ function guardVanished(Fs) {
8701
8706
  const drop = forget;
8702
8707
  const lookupPath = Fs.lookupPath.bind(Fs);
8703
8708
  const ops = Fs;
8704
- const cached = (path, follow2) => {
8709
+ const cached = (path, follow3) => {
8705
8710
  try {
8706
- const node = lookupPath(path, { follow: follow2 }).node;
8711
+ const node = lookupPath(path, { follow: follow3 }).node;
8707
8712
  return node.live && node.live.openCount === 0 && !node.live.dirty ? node : void 0;
8708
8713
  } catch {
8709
8714
  return void 0;
@@ -8810,11 +8815,11 @@ function linkable(bridge, path) {
8810
8815
  return false;
8811
8816
  }
8812
8817
  }
8813
- function linkLive(Fs, from, to, follow2) {
8818
+ function linkLive(Fs, from, to, follow3) {
8814
8819
  const target = to.replace(/\/+$/, "");
8815
8820
  const slash = target.lastIndexOf("/");
8816
8821
  const name2 = target.slice(slash + 1);
8817
- const source = Fs.lookupPath(from, { follow: follow2 }).node;
8822
+ const source = Fs.lookupPath(from, { follow: follow3 }).node;
8818
8823
  const parent = Fs.lookupPath(target.slice(0, slash) || "/", { follow: true }).node;
8819
8824
  if (!source.live || !parent.live) return false;
8820
8825
  flushOne(Fs, source);
@@ -9713,13 +9718,13 @@ function readonlyRefusal(Fs, memory, call2) {
9713
9718
  try {
9714
9719
  const name2 = cString(memory, call2.path);
9715
9720
  const abs = name2.startsWith("/") ? name2 : `${baseOf3(Fs, call2.dirfd)}/${name2}`;
9716
- const follow2 = (call2.flags & AT_SYMLINK_NOFOLLOW2) === 0;
9721
+ const follow3 = (call2.flags & AT_SYMLINK_NOFOLLOW2) === 0;
9717
9722
  const { node } = Fs.lookupPath.call(Fs, abs, {
9718
- follow: follow2
9723
+ follow: follow3
9719
9724
  });
9720
9725
  const bridge = node.live ? node.mount.opts.bridge : void 0;
9721
9726
  const stats = bridge;
9722
- const stat = follow2 ? stats?.stat : stats?.lstat;
9727
+ const stat = follow3 ? stats?.stat : stats?.lstat;
9723
9728
  return stat?.call(stats, liveNodePath(node)).readonly ? -wasiErrno("EROFS") : 0;
9724
9729
  } catch {
9725
9730
  return 0;
@@ -9768,8 +9773,8 @@ function kernelLink(imports, fs, memory, glue) {
9768
9773
  try {
9769
9774
  const from = at(olddirfd, oldpath);
9770
9775
  const to = at(newdirfd, newpath);
9771
- const follow2 = (flags & AT_SYMLINK_FOLLOW) !== 0;
9772
- if (linkLive(Fs, from, to, follow2)) return 0;
9776
+ const follow3 = (flags & AT_SYMLINK_FOLLOW) !== 0;
9777
+ if (linkLive(Fs, from, to, follow3)) return 0;
9773
9778
  } catch (err) {
9774
9779
  return -errnoOf2(err);
9775
9780
  }
@@ -10390,7 +10395,7 @@ var init_procfs = __esm({
10390
10395
  function inProc(path) {
10391
10396
  return path === "/proc" || path.startsWith("/proc/");
10392
10397
  }
10393
- function* procWalk(path, follow2) {
10398
+ function* procWalk(path, follow3) {
10394
10399
  let done = [];
10395
10400
  let todo = path.split("/").filter((part) => part !== "");
10396
10401
  let hops = 0;
@@ -10405,7 +10410,7 @@ function* procWalk(path, follow2) {
10405
10410
  const at = `/${[...done, part].join("/")}`;
10406
10411
  const whole = normalize(`/${[...done, part, ...todo].join("/")}`);
10407
10412
  if (inProc(at) && inProc(whole)) return broken ?? whole;
10408
- if (!follow2 && todo.length === 0) return void 0;
10413
+ if (!follow3 && todo.length === 0) return void 0;
10409
10414
  const target = yield { at, check: todo.find((next2) => next2 !== ".") === ".." };
10410
10415
  if (typeof target === "string") {
10411
10416
  if (++hops > MAX_HOPS2) return void 0;
@@ -10429,8 +10434,8 @@ function throughLink(target, done, todo) {
10429
10434
  const parts = target.split("/").filter((part) => part !== "");
10430
10435
  return [target.startsWith("/") ? [] : done, [...parts, ...todo]];
10431
10436
  }
10432
- function procPath(fs, path, follow2) {
10433
- const walk = procWalk(path, follow2);
10437
+ function procPath(fs, path, follow3) {
10438
+ const walk = procWalk(path, follow3);
10434
10439
  let step = walk.next();
10435
10440
  while (!step.done) {
10436
10441
  const { at, check } = step.value;
@@ -10488,26 +10493,26 @@ function physicalProc(fs) {
10488
10493
  };
10489
10494
  }
10490
10495
  function procfsBridge(fs, tree) {
10491
- const toProc = (path, follow2) => procPath(fs, path, follow2);
10496
+ const toProc = (path, follow3) => procPath(fs, path, follow3);
10492
10497
  const shadowing = physicalProc(fs);
10493
- const via = (p, proc, own, follow2 = true) => {
10498
+ const via = (p, proc, own, follow3 = true) => {
10494
10499
  if (inProc(p)) return proc(p);
10495
10500
  if (shadowing()) {
10496
- const real = toProc(p, follow2);
10501
+ const real = toProc(p, follow3);
10497
10502
  if (real !== void 0) return proc(real);
10498
10503
  }
10499
10504
  try {
10500
10505
  return own();
10501
10506
  } catch (err) {
10502
- const real = toProc(p, follow2);
10507
+ const real = toProc(p, follow3);
10503
10508
  if (real === void 0) throw err;
10504
10509
  return proc(real);
10505
10510
  }
10506
10511
  };
10507
10512
  const readOnly2 = (paths, run) => {
10508
10513
  const physical2 = shadowing();
10509
- for (const [p, follow2] of paths) {
10510
- if (inProc(p) || physical2 && toProc(p, follow2) !== void 0) throw syncError("EROFS", p);
10514
+ for (const [p, follow3] of paths) {
10515
+ if (inProc(p) || physical2 && toProc(p, follow3) !== void 0) throw syncError("EROFS", p);
10511
10516
  }
10512
10517
  return run();
10513
10518
  };
@@ -10592,12 +10597,12 @@ function procfsBridge(fs, tree) {
10592
10597
  () => fs.rename(from, to)
10593
10598
  ),
10594
10599
  symlink: (target, link) => readOnly2([[link, false]], () => fs.symlink(target, link)),
10595
- link: (from, to, follow2) => readOnly2(
10600
+ link: (from, to, follow3) => readOnly2(
10596
10601
  [
10597
- [from, follow2 === true],
10602
+ [from, follow3 === true],
10598
10603
  [to, false]
10599
10604
  ],
10600
- () => fs.link(from, to, follow2)
10605
+ () => fs.link(from, to, follow3)
10601
10606
  ),
10602
10607
  hold: (p, held2, open, handle, want, seen) => {
10603
10608
  if (handle !== void 0 && snapshots.delete(handle)) return void 0;
@@ -10617,14 +10622,14 @@ function procfsBridge(fs, tree) {
10617
10622
  )
10618
10623
  } : {}
10619
10624
  };
10620
- for (const [names, follow2] of [
10625
+ for (const [names, follow3] of [
10621
10626
  [FOLLOWING, true],
10622
10627
  [NOT_FOLLOWING, false]
10623
10628
  ]) {
10624
10629
  for (const name2 of names) {
10625
10630
  const fn = fs[name2];
10626
10631
  if (!fn) continue;
10627
- over[name2] = (p, ...rest2) => readOnly2([[p, follow2]], () => fn.call(fs, p, ...rest2));
10632
+ over[name2] = (p, ...rest2) => readOnly2([[p, follow3]], () => fn.call(fs, p, ...rest2));
10628
10633
  }
10629
10634
  }
10630
10635
  const { chown } = fs;
@@ -10733,18 +10738,18 @@ var init_wasi_procfs = __esm({
10733
10738
  }
10734
10739
  };
10735
10740
  }
10736
- parts(path, follow2) {
10741
+ parts(path, follow3) {
10737
10742
  const parts = path.split("/").filter((p) => p !== "").slice(1);
10738
- if (parts[0] === "self" && (follow2 || parts.length > 1)) parts[0] = String(this.pid);
10743
+ if (parts[0] === "self" && (follow3 || parts.length > 1)) parts[0] = String(this.pid);
10739
10744
  return parts;
10740
10745
  }
10741
- find(path, follow2) {
10742
- const node = this.node(this.parts(path, follow2));
10746
+ find(path, follow3) {
10747
+ const node = this.node(this.parts(path, follow3));
10743
10748
  if (!node) throw syncError("ENOENT", path);
10744
10749
  return node;
10745
10750
  }
10746
- stat(path, follow2 = true) {
10747
- const node = this.find(path, follow2);
10751
+ stat(path, follow3 = true) {
10752
+ const node = this.find(path, follow3);
10748
10753
  const base = {
10749
10754
  isFile: false,
10750
10755
  isDirectory: false,
@@ -11010,10 +11015,22 @@ var init_js_run = __esm({
11010
11015
  });
11011
11016
 
11012
11017
  // src/process/js/js-sync.ts
11013
- function laneOf(lane) {
11018
+ function laneOf(lane, silence = SYNC_FS_REQUEST_TIMEOUT_MS, open = createSyncSabTransport) {
11014
11019
  if (!lane) return noLane;
11015
- const transport = createSyncSabTransport(lane.sab, lane.port);
11016
- return (req) => transport.call(req, Number.POSITIVE_INFINITY, req.op);
11020
+ const transport = open(lane.sab, lane.port);
11021
+ return (req) => {
11022
+ if (!READ_ONLY.has(req.op)) return transport.call(req, Number.POSITIVE_INFINITY, req.op);
11023
+ try {
11024
+ return transport.call(req, silence, req.op);
11025
+ } catch (err) {
11026
+ const errno2 = err?.code;
11027
+ return {
11028
+ ok: false,
11029
+ errno: typeof errno2 === "string" ? errno2 : "EIO",
11030
+ message: err instanceof Error ? err.message : String(err)
11031
+ };
11032
+ }
11033
+ };
11017
11034
  }
11018
11035
  function syncOps(kernel, shared) {
11019
11036
  const { infos, handles, resolve } = shared;
@@ -11280,7 +11297,7 @@ function syncPathOps(kernel, resolve, statOf, open, tryDev) {
11280
11297
  }
11281
11298
  };
11282
11299
  }
11283
- var encoder3, noLane, JsSyncKernel;
11300
+ var encoder3, noLane, READ_ONLY, JsSyncKernel;
11284
11301
  var init_js_sync = __esm({
11285
11302
  "src/process/js/js-sync.ts"() {
11286
11303
  "use strict";
@@ -11294,6 +11311,7 @@ var init_js_sync = __esm({
11294
11311
  init_js_proc();
11295
11312
  encoder3 = new TextEncoder();
11296
11313
  noLane = () => ({ ok: false, errno: "ENOSYS", message: "no sync lane" });
11314
+ READ_ONLY = /* @__PURE__ */ new Set([...SYNC_FS_READ_ONLY, "fd-path-flush"]);
11297
11315
  JsSyncKernel = class {
11298
11316
  lane;
11299
11317
  kernel;
@@ -11424,6 +11442,50 @@ var init_js_tty = __esm({
11424
11442
  }
11425
11443
  });
11426
11444
 
11445
+ // src/process/js/js-watch.ts
11446
+ function watchRequest(path, options) {
11447
+ return { op: "watch-open", path, ...options?.recursive ? { recursive: true } : {} };
11448
+ }
11449
+ function watchArgs(options, listener) {
11450
+ const onNote = typeof options === "function" ? options : listener;
11451
+ if (typeof onNote !== "function") throw new TypeError("watch needs a listener");
11452
+ return [typeof options === "object" && options !== null ? options : {}, onNote];
11453
+ }
11454
+ function follow2(kernel, id, onNote) {
11455
+ const stop = new AbortController();
11456
+ let closed = false;
11457
+ const close = () => {
11458
+ if (closed) return;
11459
+ closed = true;
11460
+ stop.abort();
11461
+ kernel.call({ op: "watch-close", id }).catch(() => void 0);
11462
+ };
11463
+ const pump2 = async () => {
11464
+ while (!closed) {
11465
+ let notes;
11466
+ try {
11467
+ const r = await kernel.blocking({ op: "watch-next", id }, stop.signal);
11468
+ notes = r.ok && r.kind === "json" ? r.json : [];
11469
+ } catch {
11470
+ closed = true;
11471
+ return;
11472
+ }
11473
+ for (const note of notes) {
11474
+ if (closed) return;
11475
+ if ("ended" in note) closed = true;
11476
+ onNote(note);
11477
+ }
11478
+ }
11479
+ };
11480
+ void pump2();
11481
+ return { close };
11482
+ }
11483
+ var init_js_watch = __esm({
11484
+ "src/process/js/js-watch.ts"() {
11485
+ "use strict";
11486
+ }
11487
+ });
11488
+
11427
11489
  // src/process/js/js-websocket.ts
11428
11490
  function failed4(err) {
11429
11491
  return new TypeError("websocket failed", { cause: err });
@@ -11787,6 +11849,15 @@ async function vfsOpen(kernel, abs, options, statOf, io, whole) {
11787
11849
  handles.set(fd, handle.invalidate);
11788
11850
  return handle.file;
11789
11851
  }
11852
+ function watchingSyncOps(kernel, syncKernel, shared) {
11853
+ const ops = syncOps(syncKernel, shared);
11854
+ const watch = (path, options, listener) => {
11855
+ const [given, onNote] = watchArgs(options, listener);
11856
+ const id = syncKernel.json(watchRequest(shared.resolve(path), given));
11857
+ return follow2(kernel, id, onNote);
11858
+ };
11859
+ return { ...ops, fs: { ...ops.fs, watch } };
11860
+ }
11790
11861
  function createContext(o) {
11791
11862
  const { kernel } = o;
11792
11863
  const infos = /* @__PURE__ */ new Map();
@@ -11862,7 +11933,7 @@ function createContext(o) {
11862
11933
  const terminal = ttyOps(kernel);
11863
11934
  const sync = {
11864
11935
  kernel: KERNEL_INFO,
11865
- ...syncOps(syncKernel, { pid: o.pid, resolve, random, infos, handles }),
11936
+ ...watchingSyncOps(kernel, syncKernel, { pid: o.pid, resolve, random, infos, handles }),
11866
11937
  run: (options) => runSync(syncKernel, { env: o.env, cwd: o.cwd, resolve, signal: signalNumber }, options),
11867
11938
  spawn: (options) => spawnSync(options),
11868
11939
  exit: (status2 = 0) => {
@@ -12094,6 +12165,11 @@ function pathOps(kernel, resolve, statOf, open, tryDev) {
12094
12165
  await statOf("stat", abs);
12095
12166
  return statFsOf(await kernel.json({ op: "statfs", path: abs }));
12096
12167
  },
12168
+ async watch(path, options, listener) {
12169
+ const [given, onNote] = watchArgs(options, listener);
12170
+ const id = await kernel.json(watchRequest(resolve(path), given));
12171
+ return follow2(kernel, id, onNote);
12172
+ },
12097
12173
  async readFile(path) {
12098
12174
  const abs = resolve(path);
12099
12175
  if (inDev(abs)) return readWhole(await open(abs));
@@ -12141,6 +12217,7 @@ var init_js_context = __esm({
12141
12217
  init_js_run();
12142
12218
  init_js_sync();
12143
12219
  init_js_tty();
12220
+ init_js_watch();
12144
12221
  init_js_websocket();
12145
12222
  KERNEL_INFO = Object.freeze({ version: KERNEL_VERSION });
12146
12223
  JsExit = class extends Error {
@@ -12378,9 +12455,9 @@ function useKernelFdMetadata(Fs, sys, call2) {
12378
12455
  }
12379
12456
  return void 0;
12380
12457
  };
12381
- const ofPath = (path, follow2) => {
12458
+ const ofPath = (path, follow3) => {
12382
12459
  if (typeof path !== "string") return find((s) => s.node === path);
12383
- const fd = follow2 ? fdOfPath(path, Fs.cwd()) : void 0;
12460
+ const fd = follow3 ? fdOfPath(path, Fs.cwd()) : void 0;
12384
12461
  if (fd !== void 0) return kernelFd(Fs.getStream(fd));
12385
12462
  return find((s) => s.path === path);
12386
12463
  };