@ai-ecoverse/slicc-kernel 1.41.0 → 1.41.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
@@ -800,8 +800,8 @@ var KernelSocket = class _KernelSocket {
800
800
  async accept(signal, nonblock = false) {
801
801
  for (; ; ) {
802
802
  if (this.state !== "listening") throw new KernelError("EINVAL");
803
- const next = this.queue.shift();
804
- if (next) return next;
803
+ const next2 = this.queue.shift();
804
+ if (next2) return next2;
805
805
  if (nonblock) throw new KernelError("EAGAIN");
806
806
  await this.changes.wait(signal);
807
807
  }
@@ -982,8 +982,8 @@ var LoopbackNet = class {
982
982
  if (reserve) this.internal.add(port);
983
983
  return this.internal.has(port);
984
984
  }
985
- activate(addr, start) {
986
- this.activators.set(keyOf(addr), start);
985
+ activate(addr, start2) {
986
+ this.activators.set(keyOf(addr), start2);
987
987
  }
988
988
  socket(domain) {
989
989
  return new KernelSocket(this, domain);
@@ -1242,12 +1242,12 @@ var MessageQueue = class {
1242
1242
  }
1243
1243
  async *[Symbol.asyncIterator]() {
1244
1244
  for (; ; ) {
1245
- const next = this.items.shift();
1246
- if (next !== void 0) {
1247
- const n = payloadSize(next);
1245
+ const next2 = this.items.shift();
1246
+ if (next2 !== void 0) {
1247
+ const n = payloadSize(next2);
1248
1248
  this.size -= n;
1249
1249
  this.taken?.(n);
1250
- yield next;
1250
+ yield next2;
1251
1251
  continue;
1252
1252
  }
1253
1253
  if (this.ended) return;
@@ -1352,8 +1352,8 @@ async function* chunks(body, idleMs) {
1352
1352
  if (!body) return;
1353
1353
  const reader = body.getReader();
1354
1354
  try {
1355
- for (let next = await readWithin(reader, idleMs); !next.done; next = await readWithin(reader, idleMs)) {
1356
- if (next.value.byteLength > 0) yield next.value;
1355
+ for (let next2 = await readWithin(reader, idleMs); !next2.done; next2 = await readWithin(reader, idleMs)) {
1356
+ if (next2.value.byteLength > 0) yield next2.value;
1357
1357
  }
1358
1358
  } finally {
1359
1359
  await reader.cancel().catch(() => void 0);
@@ -1424,7 +1424,7 @@ function serveTransport(peer, transport, { closeWaitMs = CLOSE_WAIT_MS } = {}) {
1424
1424
  ...typeof code === "string" ? { code } : {}
1425
1425
  });
1426
1426
  };
1427
- const start = async (call) => {
1427
+ const start2 = async (call) => {
1428
1428
  const abort = new AbortController();
1429
1429
  const entry = { abort };
1430
1430
  open.set(call.nid, entry);
@@ -1503,9 +1503,9 @@ function serveTransport(peer, transport, { closeWaitMs = CLOSE_WAIT_MS } = {}) {
1503
1503
  try {
1504
1504
  const messages = socket.messages[Symbol.asyncIterator]();
1505
1505
  for (; ; ) {
1506
- const next = await Promise.race([messages.next(), unanswered]);
1507
- if (next === "late" || next.done) break;
1508
- const data = next.value;
1506
+ const next2 = await Promise.race([messages.next(), unanswered]);
1507
+ if (next2 === "late" || next2.done) break;
1508
+ const data = next2.value;
1509
1509
  if (flow.closing) continue;
1510
1510
  if (payloadSize(data) > MESSAGE_LIMIT) {
1511
1511
  oversize = true;
@@ -1546,12 +1546,12 @@ function serveTransport(peer, transport, { closeWaitMs = CLOSE_WAIT_MS } = {}) {
1546
1546
  const body = open.get(nid)?.body;
1547
1547
  if (!body) return;
1548
1548
  try {
1549
- const next = await body.next();
1550
- if (next.done) {
1549
+ const next2 = await body.next();
1550
+ if (next2.done) {
1551
1551
  open.delete(nid);
1552
1552
  peer.postMessage({ net: "end", nid });
1553
1553
  } else {
1554
- const bytes = next.value.slice();
1554
+ const bytes = next2.value.slice();
1555
1555
  peer.postMessage({ net: "chunk", nid, bytes }, [bytes.buffer]);
1556
1556
  }
1557
1557
  } catch (e) {
@@ -1568,7 +1568,7 @@ function serveTransport(peer, transport, { closeWaitMs = CLOSE_WAIT_MS } = {}) {
1568
1568
  };
1569
1569
  return {
1570
1570
  answer(call) {
1571
- if (call.net === "fetch") void start(call);
1571
+ if (call.net === "fetch") void start2(call);
1572
1572
  else if (call.net === "read") void read(call.nid);
1573
1573
  else if (call.net === "ws-open") void openSocket(call);
1574
1574
  else if (call.net === "ws-send") void sendOn(call);
@@ -1623,17 +1623,17 @@ async function realpath(fs, path) {
1623
1623
  let parts = fs.resolvePath("/", path).split("/").filter(Boolean);
1624
1624
  let resolved = "";
1625
1625
  for (let hops = 0; parts.length > 0; ) {
1626
- const [name2, ...rest] = parts;
1627
- const next = `${resolved}/${name2}`;
1628
- if (!(await fs.lstat(next)).isSymbolicLink) {
1629
- resolved = next;
1630
- parts = rest;
1626
+ const [name2, ...rest2] = parts;
1627
+ const next2 = `${resolved}/${name2}`;
1628
+ if (!(await fs.lstat(next2)).isSymbolicLink) {
1629
+ resolved = next2;
1630
+ parts = rest2;
1631
1631
  continue;
1632
1632
  }
1633
1633
  if (++hops > MAX_LINKS) throw fsError("ELOOP", path);
1634
- const target = await fs.readlink(next);
1634
+ const target = await fs.readlink(next2);
1635
1635
  const base = target.startsWith("/") ? "/" : resolved || "/";
1636
- parts = [...fs.resolvePath(base, target).split("/").filter(Boolean), ...rest];
1636
+ parts = [...fs.resolvePath(base, target).split("/").filter(Boolean), ...rest2];
1637
1637
  resolved = "";
1638
1638
  }
1639
1639
  return resolved || "/";
@@ -2079,8 +2079,8 @@ var OpfsFs = class {
2079
2079
  resolvePath(base, path) {
2080
2080
  return resolvePath(base, path);
2081
2081
  }
2082
- async walk(parts, from, start) {
2083
- let dir = start;
2082
+ async walk(parts, from, start2) {
2083
+ let dir = start2;
2084
2084
  for (let at = from; at < parts.length; at++) {
2085
2085
  dir = await dir.getDirectoryHandle(parts[at]);
2086
2086
  this.dirs.set(`/${parts.slice(0, at + 1).join("/")}`, dir);
@@ -2166,7 +2166,7 @@ var OpfsFs = class {
2166
2166
  }
2167
2167
  return void 0;
2168
2168
  }
2169
- async locate(path, follow) {
2169
+ async locate(path, follow2) {
2170
2170
  let current = path;
2171
2171
  for (let hops = 0; hops <= MAX_LINKS2; hops++) {
2172
2172
  try {
@@ -2175,9 +2175,9 @@ var OpfsFs = class {
2175
2175
  if (!missing(err)) throw err;
2176
2176
  const link2 = await this.linkAlong(current);
2177
2177
  if (!link2) throw err;
2178
- if (link2.path === current && !follow) return { path: current, link: link2 };
2179
- const rest = current.slice(link2.path.length);
2180
- current = resolvePath(parentOf2(link2.path), `${link2.link}${rest}`);
2178
+ if (link2.path === current && !follow2) return { path: current, link: link2 };
2179
+ const rest2 = current.slice(link2.path.length);
2180
+ current = resolvePath(parentOf2(link2.path), `${link2.link}${rest2}`);
2181
2181
  }
2182
2182
  }
2183
2183
  throw fsError("ELOOP", path);
@@ -2493,9 +2493,9 @@ var OpfsFs = class {
2493
2493
  return timed;
2494
2494
  }
2495
2495
  async restamp(path, timed) {
2496
- for (const rest of timed) {
2497
- const mtimeFor = await this.modified(path + rest);
2498
- await this.meta.update(path + rest, (entry) => entry && { ...entry, mtimeFor });
2496
+ for (const rest2 of timed) {
2497
+ const mtimeFor = await this.modified(path + rest2);
2498
+ await this.meta.update(path + rest2, (entry) => entry && { ...entry, mtimeFor });
2499
2499
  }
2500
2500
  }
2501
2501
  async place(handle, dir, name2) {
@@ -2543,8 +2543,8 @@ var OpfsFs = class {
2543
2543
  }));
2544
2544
  this.touch(parent.path);
2545
2545
  }
2546
- async realpath(path, follow) {
2547
- return (await this.locate(path, follow)).path;
2546
+ async realpath(path, follow2) {
2547
+ return (await this.locate(path, follow2)).path;
2548
2548
  }
2549
2549
  async readlink(path) {
2550
2550
  const found = await this.locate(path, false);
@@ -2674,9 +2674,9 @@ var UnlinkedKeeper = class {
2674
2674
  void locks?.request(lockName(this.instance), () => new Promise(() => void 0));
2675
2675
  }
2676
2676
  serial(op) {
2677
- const next = this.queue.then(op);
2678
- this.queue = next.catch(() => void 0);
2679
- return next;
2677
+ const next2 = this.queue.then(op);
2678
+ this.queue = next2.catch(() => void 0);
2679
+ return next2;
2680
2680
  }
2681
2681
  wrap(fs = this.fs) {
2682
2682
  const keeper = this;
@@ -2858,10 +2858,10 @@ var Incoming = class {
2858
2858
  this.eof = true;
2859
2859
  return false;
2860
2860
  }
2861
- const next = new Uint8Array(this.buf.length + chunk2.length);
2862
- next.set(this.buf);
2863
- next.set(chunk2, this.buf.length);
2864
- this.buf = next;
2861
+ const next2 = new Uint8Array(this.buf.length + chunk2.length);
2862
+ next2.set(this.buf);
2863
+ next2.set(chunk2, this.buf.length);
2864
+ this.buf = next2;
2865
2865
  return true;
2866
2866
  }
2867
2867
  take(n) {
@@ -3889,6 +3889,53 @@ function withCommandDirs(fs, names) {
3889
3889
  };
3890
3890
  }
3891
3891
 
3892
+ // src/fs/physical-path.ts
3893
+ var MAX_HOPS = 40;
3894
+ function start(path) {
3895
+ return { done: [], todo: path.split("/").filter((p) => p !== ""), hops: 0 };
3896
+ }
3897
+ function next(walk) {
3898
+ while (walk.todo.length > 0) {
3899
+ const part = walk.todo.shift();
3900
+ if (part === ".") continue;
3901
+ if (part === "..") {
3902
+ walk.done.pop();
3903
+ continue;
3904
+ }
3905
+ return part;
3906
+ }
3907
+ return void 0;
3908
+ }
3909
+ function lexical(path) {
3910
+ const walk = start(path);
3911
+ for (let part = next(walk); part !== void 0; part = next(walk)) walk.done.push(part);
3912
+ return `/${walk.done.join("/")}`;
3913
+ }
3914
+ function rest(walk, part) {
3915
+ return lexical(`/${[...walk.done, part, ...walk.todo].join("/")}`);
3916
+ }
3917
+ function follow(walk, target) {
3918
+ if (++walk.hops > MAX_HOPS) return false;
3919
+ if (target.startsWith("/")) walk.done.length = 0;
3920
+ walk.todo = [...target.split("/").filter((p) => p !== ""), ...walk.todo];
3921
+ return true;
3922
+ }
3923
+ async function physicalPathAsync(fs, path) {
3924
+ const walk = start(path);
3925
+ for (let part = next(walk); part !== void 0; part = next(walk)) {
3926
+ const at = `/${[...walk.done, part].join("/")}`;
3927
+ let target;
3928
+ try {
3929
+ target = (await fs.lstat(at)).isSymbolicLink ? await fs.readlink(at) : void 0;
3930
+ } catch {
3931
+ return rest(walk, part);
3932
+ }
3933
+ if (target === void 0) walk.done.push(part);
3934
+ else if (!follow(walk, target)) return lexical(path);
3935
+ }
3936
+ return `/${walk.done.join("/")}`;
3937
+ }
3938
+
3892
3939
  // src/fs/watch.ts
3893
3940
  var WATCH_BATCH_LIMIT = 1e3;
3894
3941
  var under2 = (path, dir) => dir === "/" || path.startsWith(`${dir}/`);
@@ -4052,10 +4099,10 @@ var ChildTable = class {
4052
4099
  }
4053
4100
  return this.track(req, fds, captured, this.spawner);
4054
4101
  }
4055
- async track(req, fds, captured, start) {
4102
+ async track(req, fds, captured, start2) {
4056
4103
  let handle;
4057
4104
  try {
4058
- handle = await start(req, fds);
4105
+ handle = await start2(req, fds);
4059
4106
  } catch (e) {
4060
4107
  await fds.closeAll();
4061
4108
  throw e;
@@ -4292,8 +4339,7 @@ var HeldSet = class extends Set {
4292
4339
  delete(holds) {
4293
4340
  const removed = super.delete(holds);
4294
4341
  for (const path of /* @__PURE__ */ new Set([...holds.keys(), ...holds.opens.keys()])) this.idle(path);
4295
- for (const kept of holds.unlinked.values()) kept.release();
4296
- holds.unlinked.clear();
4342
+ holds.releaseAll();
4297
4343
  return removed;
4298
4344
  }
4299
4345
  };
@@ -4306,6 +4352,10 @@ var HeldPaths = class extends Map {
4306
4352
  opens = /* @__PURE__ */ new Map();
4307
4353
  unlinked = /* @__PURE__ */ new Map();
4308
4354
  aliases = /* @__PURE__ */ new Map();
4355
+ handles = /* @__PURE__ */ new Map();
4356
+ keptHandles = /* @__PURE__ */ new Map();
4357
+ uses = /* @__PURE__ */ new Map();
4358
+ lastHandle = 0;
4309
4359
  owning;
4310
4360
  onIdle;
4311
4361
  keyOf(path) {
@@ -4321,29 +4371,70 @@ var HeldPaths = class extends Map {
4321
4371
  return this.opens.keys();
4322
4372
  }
4323
4373
  isKept(path) {
4324
- return this.unlinked.has(path);
4374
+ const ids = this.handlesAt(path);
4375
+ return ids.length === 0 ? this.unlinked.has(path) : ids.every((id) => this.keptHandles.has(id));
4376
+ }
4377
+ handlesAt(path) {
4378
+ return [...this.handles].filter(([, key]) => key === path).map(([id]) => id);
4379
+ }
4380
+ keptFor(handle) {
4381
+ return this.keptHandles.get(handle);
4325
4382
  }
4326
4383
  keep(path, file) {
4384
+ const fresh = this.handlesAt(path).filter((id) => !this.keptHandles.has(id));
4385
+ for (const id of fresh) this.keptHandles.set(id, file);
4386
+ this.uses.set(file, Math.max(fresh.length, 1));
4327
4387
  this.unlinked.set(path, file);
4328
4388
  }
4329
- unkeep(path) {
4330
- this.unlinked.delete(path);
4331
- }
4332
- hold(path, on, open = false, real) {
4333
- if (open) {
4334
- const key = real ?? this.keyOf(path);
4335
- if (key !== path) this.aliases.set(path, key);
4336
- const count2 = (this.opens.get(key) ?? 0) + (on ? 1 : -1);
4337
- if (count2 > 0) this.opens.set(key, count2);
4338
- else {
4339
- this.opens.delete(key);
4340
- this.unlinked.get(key)?.release();
4341
- this.unlinked.delete(key);
4342
- for (const [alias, target] of this.aliases) if (target === key) this.aliases.delete(alias);
4343
- this.onIdle?.(key);
4344
- }
4389
+ unkeep(path, file) {
4390
+ for (const [id, kept] of this.keptHandles) if (kept === file) this.keptHandles.delete(id);
4391
+ this.uses.delete(file);
4392
+ if (this.unlinked.get(path) === file) this.unlinked.delete(path);
4393
+ }
4394
+ letGo(file, all = false) {
4395
+ const left = all ? 0 : (this.uses.get(file) ?? 0) - 1;
4396
+ if (left > 0) {
4397
+ this.uses.set(file, left);
4345
4398
  return;
4346
4399
  }
4400
+ if (!this.uses.delete(file)) return;
4401
+ file.release();
4402
+ for (const [path, kept] of this.unlinked) if (kept === file) this.unlinked.delete(path);
4403
+ }
4404
+ releaseAll() {
4405
+ for (const file of [...this.uses.keys()]) this.letGo(file, true);
4406
+ this.keptHandles.clear();
4407
+ }
4408
+ hold(path, on, open = false, real, handle) {
4409
+ if (open) return this.holdOpen(path, on, real, handle);
4410
+ this.holdWrite(path, on);
4411
+ return void 0;
4412
+ }
4413
+ holdOpen(path, on, real, handle) {
4414
+ const known = handle === void 0 ? void 0 : this.handles.get(handle);
4415
+ const key = known ?? real ?? this.keyOf(path);
4416
+ if (key !== path) this.aliases.set(path, key);
4417
+ if (handle !== void 0) {
4418
+ const kept = this.keptHandles.get(handle);
4419
+ this.handles.delete(handle);
4420
+ this.keptHandles.delete(handle);
4421
+ if (kept) this.letGo(kept);
4422
+ }
4423
+ const count = (this.opens.get(key) ?? 0) + (on ? 1 : -1);
4424
+ if (count > 0) this.opens.set(key, count);
4425
+ else {
4426
+ this.opens.delete(key);
4427
+ for (const id of this.handlesAt(key)) this.handles.delete(id);
4428
+ const kept = this.unlinked.get(key);
4429
+ if (kept) this.letGo(kept, true);
4430
+ for (const [alias, target] of this.aliases) if (target === key) this.aliases.delete(alias);
4431
+ this.onIdle?.(key);
4432
+ }
4433
+ if (!on) return void 0;
4434
+ this.handles.set(++this.lastHandle, key);
4435
+ return this.lastHandle;
4436
+ }
4437
+ holdWrite(path, on) {
4347
4438
  const count = (this.get(path) ?? 0) + (on ? 1 : -1);
4348
4439
  if (count > 0) this.set(path, count);
4349
4440
  else {
@@ -4380,6 +4471,9 @@ var HeldPaths = class extends Map {
4380
4471
  this.opens.delete(path);
4381
4472
  this.opens.set(moved2, (this.opens.get(moved2) ?? 0) + count);
4382
4473
  }
4474
+ for (const [id, key] of this.handles) {
4475
+ if (within3(key, from)) this.handles.set(id, to + key.slice(from.length));
4476
+ }
4383
4477
  }
4384
4478
  isRevoked(path) {
4385
4479
  return this.revoked.has(path);
@@ -5054,9 +5148,9 @@ var MountFs = class {
5054
5148
  this.table.forget(found.mount, normalizePath(path));
5055
5149
  await found.mount.conn.call({ op: "symlink", target, path: found.rel });
5056
5150
  }
5057
- async realpath(path, follow) {
5151
+ async realpath(path, follow2) {
5058
5152
  if (this.at(path) || !this.base.realpath) throw errnoError("ENOSYS", path);
5059
- const real = await this.base.realpath(path, follow);
5153
+ const real = await this.base.realpath(path, follow2);
5060
5154
  if (this.at(real)) throw errnoError("ENOSYS", path);
5061
5155
  return real;
5062
5156
  }
@@ -5243,25 +5337,31 @@ async function ranged(fs, path, req) {
5243
5337
  }
5244
5338
  var UNLINKED_OPS = /* @__PURE__ */ new Set(["read", "pread", "pwrite", "truncate"]);
5245
5339
  var OWN_OPS = /* @__PURE__ */ new Set(["rm", "unlink", "rmdir", "rename"]);
5340
+ async function keptOr(entry, path, handle) {
5341
+ if (handle !== void 0) return entry.keptFor?.(handle)?.hidden ?? path;
5342
+ const kept = entry.unlinked?.(path);
5343
+ return kept && !await entry.fs.exists(path) ? kept.hidden : path;
5344
+ }
5246
5345
  async function dispatchSyncFs(req) {
5247
5346
  const entry = resolveSyncFsToken(req.token);
5248
5347
  if (!entry) return { ok: false, errno: "EACCES", message: "sync-fs: unknown or revoked token" };
5249
5348
  const { fs, cwd } = entry;
5250
5349
  try {
5251
5350
  const path = fs.resolvePath(cwd, req.path);
5351
+ if (req.op === "kept") return json2(entry.keptFor?.(req.handle ?? -1) !== void 0);
5252
5352
  if (req.op === "statfs") return json2(await entry.statfs?.(path) ?? await storageUsage());
5253
5353
  if (req.op === "hold") {
5254
5354
  const [on, open] = [((req.mode ?? 0) & 1) === 1, ((req.mode ?? 0) & 2) === 2];
5255
- const real = on && open ? await fs.realpath?.(path, true).catch(() => path) : void 0;
5256
- entry.hold?.(path, on, open, real);
5355
+ if (on && open) {
5356
+ const real = await fs.realpath?.(path, true).catch(() => path);
5357
+ return json2(entry.hold?.(path, on, open, real) ?? null);
5358
+ }
5359
+ entry.hold?.(path, on, open, void 0, req.handle);
5257
5360
  return done;
5258
5361
  }
5259
5362
  if (entry.revoked?.(path)) return { ok: false, errno: "EIO", message: `${path} was unmounted` };
5260
5363
  if (req.op === "write" && req.mode === 1 || UNLINKED_OPS.has(req.op)) {
5261
- const serve = async () => {
5262
- const kept = entry.unlinked?.(path);
5263
- return run(entry, kept && !await fs.exists(path) ? kept.hidden : path, req);
5264
- };
5364
+ const serve = async () => run(entry, await keptOr(entry, path, req.handle), req);
5265
5365
  return await (entry.gate ? entry.gate(path, serve) : serve());
5266
5366
  }
5267
5367
  if (!entry.own || !OWN_OPS.has(req.op)) return await run(entry, path, req);
@@ -6204,15 +6304,15 @@ var octets = (bytes) => tlv(4, bytes);
6204
6304
  var bits = (bytes, unused = 0) => tlv(3, Uint8Array.of(unused), bytes);
6205
6305
  var TRUE = tlv(1, Uint8Array.of(255));
6206
6306
  function integer(magnitude) {
6207
- let start = 0;
6208
- while (start < magnitude.length - 1 && magnitude[start] === 0) start++;
6209
- const trimmed = magnitude.subarray(start);
6307
+ let start2 = 0;
6308
+ while (start2 < magnitude.length - 1 && magnitude[start2] === 0) start2++;
6309
+ const trimmed = magnitude.subarray(start2);
6210
6310
  return tlv(2, trimmed[0] & 128 ? concat4([Uint8Array.of(0), trimmed]) : trimmed);
6211
6311
  }
6212
6312
  function oid(dotted) {
6213
- const [a, b, ...rest] = dotted.split(".").map(Number);
6313
+ const [a, b, ...rest2] = dotted.split(".").map(Number);
6214
6314
  const out = [40 * a + b];
6215
- for (const arc of rest) {
6315
+ for (const arc of rest2) {
6216
6316
  const groups = [];
6217
6317
  for (let v = arc; ; v = Math.floor(v / 128)) {
6218
6318
  groups.unshift(v & 127);
@@ -6252,19 +6352,19 @@ function children(der) {
6252
6352
  function header(der, at) {
6253
6353
  const tag = der[at];
6254
6354
  let len = der[at + 1];
6255
- let start = at + 2;
6355
+ let start2 = at + 2;
6256
6356
  if (len & 128) {
6257
6357
  const count = len & 127;
6258
6358
  len = 0;
6259
- for (let i = 0; i < count; i++) len = len * 256 + der[start + i];
6260
- start += count;
6359
+ for (let i = 0; i < count; i++) len = len * 256 + der[start2 + i];
6360
+ start2 += count;
6261
6361
  }
6262
- if (start + len > der.length) throw new Error("truncated DER");
6263
- return [tag, start, start + len];
6362
+ if (start2 + len > der.length) throw new Error("truncated DER");
6363
+ return [tag, start2, start2 + len];
6264
6364
  }
6265
6365
  function contents(element) {
6266
- const [, start, end] = header(element, 0);
6267
- return element.subarray(start, end);
6366
+ const [, start2, end] = header(element, 0);
6367
+ return element.subarray(start2, end);
6268
6368
  }
6269
6369
  function publicKeyBits(spki) {
6270
6370
  const key = children(spki)[1];
@@ -6865,9 +6965,9 @@ var HttpHandles = class {
6865
6965
  return this.close(req.handle);
6866
6966
  }
6867
6967
  traits() {
6868
- const { unavailable, crossOrigin = "any", ...rest } = this.transport.traits;
6968
+ const { unavailable, crossOrigin = "any", ...rest2 } = this.transport.traits;
6869
6969
  if (unavailable) return { ok: false, errno: "ENETUNREACH", message: NO_TRANSPORT };
6870
- return { ok: true, kind: "json", json: { ...rest, crossOrigin } };
6970
+ return { ok: true, kind: "json", json: { ...rest2, crossOrigin } };
6871
6971
  }
6872
6972
  add(abort, body, cancel) {
6873
6973
  const handle = ++this.nextHandle;
@@ -6929,9 +7029,9 @@ var HttpHandles = class {
6929
7029
  async take(entry, max) {
6930
7030
  if (entry.left.length === 0 && !entry.done) {
6931
7031
  try {
6932
- const next = await entry.body.next();
6933
- if (next.done) entry.done = true;
6934
- else entry.left = next.value;
7032
+ const next2 = await entry.body.next();
7033
+ if (next2.done) entry.done = true;
7034
+ else entry.left = next2.value;
6935
7035
  } catch (e) {
6936
7036
  entry.done = true;
6937
7037
  const timedOut = e?.code === "ETIMEDOUT";
@@ -7393,12 +7493,12 @@ var KernelTty = class {
7393
7493
  const chunks2 = [];
7394
7494
  let n = 0;
7395
7495
  while (this.readable.length > 0 && n < max) {
7396
- const next = this.readable[0];
7397
- if (next === null || next === void 0) break;
7398
- const take = next.subarray(0, max - n);
7496
+ const next2 = this.readable[0];
7497
+ if (next2 === null || next2 === void 0) break;
7498
+ const take = next2.subarray(0, max - n);
7399
7499
  chunks2.push(take);
7400
7500
  n += take.length;
7401
- if (take.length < next.length) this.readable[0] = next.subarray(take.length);
7501
+ if (take.length < next2.length) this.readable[0] = next2.subarray(take.length);
7402
7502
  else this.readable.shift();
7403
7503
  if (this.canonical) break;
7404
7504
  }
@@ -7495,11 +7595,11 @@ var PtyPair = class {
7495
7595
  const chunks2 = [];
7496
7596
  let n = 0;
7497
7597
  while (this.queue.length > 0 && n < max - status) {
7498
- const next = this.queue[0];
7499
- const take = next.subarray(0, max - status - n);
7598
+ const next2 = this.queue[0];
7599
+ const take = next2.subarray(0, max - status - n);
7500
7600
  chunks2.push(take);
7501
7601
  n += take.length;
7502
- if (take.length < next.length) this.queue[0] = next.subarray(take.length);
7602
+ if (take.length < next2.length) this.queue[0] = next2.subarray(take.length);
7503
7603
  else this.queue.shift();
7504
7604
  }
7505
7605
  const out = new Uint8Array(status + n);
@@ -7805,7 +7905,7 @@ var Pages = class {
7805
7905
  }
7806
7906
  const last = runs[runs.length - 1];
7807
7907
  if (last) last[1] = Math.max(last[1], Math.min(READAHEAD, this.stored - last[0]));
7808
- return runs.map(([start, n]) => [start, Math.min(n, this.stored - start)]);
7908
+ return runs.map(([start2, n]) => [start2, Math.min(n, this.stored - start2)]);
7809
7909
  }
7810
7910
  partial(at, length2) {
7811
7911
  if (length2 === 0) return [];
@@ -7813,16 +7913,16 @@ var Pages = class {
7813
7913
  const edges = /* @__PURE__ */ new Set([Math.floor(at / PAGE), Math.floor((at + length2 - 1) / PAGE)]);
7814
7914
  const runs = [];
7815
7915
  for (const page of edges) {
7816
- const start = page * PAGE;
7817
- const covered = at <= start && at + length2 >= start + PAGE;
7818
- if (covered || this.pages.has(page) || start >= this.stored) continue;
7819
- runs.push([start, Math.min(PAGE, this.stored - start)]);
7916
+ const start2 = page * PAGE;
7917
+ const covered = at <= start2 && at + length2 >= start2 + PAGE;
7918
+ if (covered || this.pages.has(page) || start2 >= this.stored) continue;
7919
+ runs.push([start2, Math.min(PAGE, this.stored - start2)]);
7820
7920
  }
7821
7921
  return runs;
7822
7922
  }
7823
- fill(start, bytes) {
7923
+ fill(start2, bytes) {
7824
7924
  for (let at = 0; at < bytes.length; at += PAGE) {
7825
- const page = (start + at) / PAGE;
7925
+ const page = (start2 + at) / PAGE;
7826
7926
  if (this.pages.has(page)) continue;
7827
7927
  const part = bytes.subarray(at, Math.min(at + PAGE, bytes.length));
7828
7928
  const fresh = this.take(part.length);
@@ -7888,14 +7988,14 @@ var Pages = class {
7888
7988
  while (j < sorted.length && sorted[j] === first + (j - i) && sorted[j] * PAGE % RUN !== 0) {
7889
7989
  j++;
7890
7990
  }
7891
- const start = first * PAGE;
7991
+ const start2 = first * PAGE;
7892
7992
  const end = Math.min(this.length, (first + (j - i)) * PAGE);
7893
- const bytes = new Uint8Array(end - start);
7993
+ const bytes = new Uint8Array(end - start2);
7894
7994
  for (let k = i; k < j; k++) {
7895
7995
  const page = this.pages.get(sorted[k]);
7896
- bytes.set(page.subarray(0, Math.min(PAGE, end - (k - i) * PAGE - start)), (k - i) * PAGE);
7996
+ bytes.set(page.subarray(0, Math.min(PAGE, end - (k - i) * PAGE - start2)), (k - i) * PAGE);
7897
7997
  }
7898
- runs.push({ offset: start, bytes });
7998
+ runs.push({ offset: start2, bytes });
7899
7999
  i = j;
7900
8000
  }
7901
8001
  const written2 = Math.max(this.stored, ...runs.map((r) => r.offset + r.bytes.length));
@@ -7962,8 +8062,8 @@ var AsyncRangedFile = class {
7962
8062
  return this.pages.length;
7963
8063
  }
7964
8064
  async fetch(runs) {
7965
- for (const [start, n] of runs) {
7966
- this.pages.fill(start, await this.io.pread(this.path, start, n, this.version));
8065
+ for (const [start2, n] of runs) {
8066
+ this.pages.fill(start2, await this.io.pread(this.path, start2, n, this.version));
7967
8067
  }
7968
8068
  }
7969
8069
  async read(at, length2) {
@@ -8038,9 +8138,9 @@ var VfsNode = class {
8038
8138
  if (dirty && contents2 !== void 0) this.markDirty();
8039
8139
  }
8040
8140
  serial(op) {
8041
- const next = this.queue.then(op);
8042
- this.queue = next.catch(() => void 0);
8043
- return next;
8141
+ const next2 = this.queue.then(op);
8142
+ this.queue = next2.catch(() => void 0);
8143
+ return next2;
8044
8144
  }
8045
8145
  revoke() {
8046
8146
  this.revoked = true;
@@ -8222,10 +8322,10 @@ var VfsNodes = class {
8222
8322
  targetKey(path) {
8223
8323
  return this.real(path, true, () => realTarget(this.fs, path));
8224
8324
  }
8225
- async real(path, follow, walk) {
8325
+ async real(path, follow2, walk) {
8226
8326
  if (this.fs.realpath) {
8227
8327
  try {
8228
- return await this.fs.realpath(path, follow);
8328
+ return await this.fs.realpath(path, follow2);
8229
8329
  } catch (err) {
8230
8330
  if (errCode(err) === "ELOOP") throw err;
8231
8331
  }
@@ -8353,8 +8453,8 @@ var VfsNodes = class {
8353
8453
  }
8354
8454
  }
8355
8455
  };
8356
- async function present(fs, path, follow = false) {
8357
- const look = (follow ? void 0 : fs.lstat) ?? fs.stat;
8456
+ async function present(fs, path, follow2 = false) {
8457
+ const look = (follow2 ? void 0 : fs.lstat) ?? fs.stat;
8358
8458
  try {
8359
8459
  await (look ? look.call(fs, path) : fs.readFileBuffer(path));
8360
8460
  return true;
@@ -8380,10 +8480,10 @@ async function realDir(fs, dir, budget = { hops: 0 }) {
8380
8480
  at = parentOf6(at);
8381
8481
  continue;
8382
8482
  }
8383
- const next = at === "/" ? `/${part}` : `${at}/${part}`;
8384
- const link2 = await linkOf(fs, next);
8483
+ const next2 = at === "/" ? `/${part}` : `${at}/${part}`;
8484
+ const link2 = await linkOf(fs, next2);
8385
8485
  if (link2 === void 0) {
8386
- at = next;
8486
+ at = next2;
8387
8487
  continue;
8388
8488
  }
8389
8489
  if (budget.hops >= MAX_LINKS5) throw fsError("ELOOP", dir);
@@ -9378,7 +9478,8 @@ function holdingToken(opts, holds) {
9378
9478
  fs: opts.fs,
9379
9479
  cwd: opts.cwd,
9380
9480
  ...opts.statfs ? { statfs: opts.statfs } : {},
9381
- hold: (path, on, open, real) => holds.hold(path, on, open, real),
9481
+ hold: (path, on, open, real, handle) => holds.hold(path, on, open, real, handle),
9482
+ keptFor: (handle) => holds.keptFor(handle),
9382
9483
  unlinked: (path) => holds.keptAt(path),
9383
9484
  gate: (path, op) => opts.unlinkGate && holds.holding(path) ? opts.unlinkGate.run(holds.keyOf(path), op) : op(),
9384
9485
  own: (path, op) => holds.own(path, op),
@@ -10644,9 +10745,9 @@ function tmpfs() {
10644
10745
  let node = root;
10645
10746
  for (const name2 of parts(path)) {
10646
10747
  if (node.kind !== "directory") throw fsError2("ENOTDIR", path);
10647
- const next = node.children.get(name2);
10648
- if (!next) throw fsError2("ENOENT", path);
10649
- node = next;
10748
+ const next2 = node.children.get(name2);
10749
+ if (!next2) throw fsError2("ENOENT", path);
10750
+ node = next2;
10650
10751
  }
10651
10752
  return node;
10652
10753
  }
@@ -11210,8 +11311,8 @@ var Launcher = class {
11210
11311
  const words = shebang(head) ?? (binfmt ? [binfmt] : void 0);
11211
11312
  if (!words) return void 0;
11212
11313
  if (baseName(words[0]) === "env") words.shift();
11213
- const [interp, ...rest] = words;
11214
- const arg = rest.join(" ");
11314
+ const [interp, ...rest2] = words;
11315
+ const arg = rest2.join(" ");
11215
11316
  const passed = [...arg ? [arg] : [], command ? script : file, ...argv.slice(1)];
11216
11317
  const found = interp ? await this.resolve(interp, interp, cwd) : void 0;
11217
11318
  if (!found) {
@@ -11292,7 +11393,8 @@ var Launcher = class {
11292
11393
  }
11293
11394
  async launch(planned, req) {
11294
11395
  const { target, args } = planned;
11295
- const seen = { ...req.env, HOSTNAME: this.hostname, cwd: req.cwd };
11396
+ const cwd = await physicalPathAsync(this.base, req.cwd);
11397
+ const seen = { ...req.env, HOSTNAME: this.hostname, cwd };
11296
11398
  const env = { ...expandDefaults(target.env, seen), ...req.env };
11297
11399
  for (const key of target.unset ?? []) delete env[key];
11298
11400
  env.HOSTNAME = this.hostname;
@@ -11303,7 +11405,7 @@ var Launcher = class {
11303
11405
  await req.fds.closeAll();
11304
11406
  throw err;
11305
11407
  }
11306
- return this.start({ ...req, program, argv0: target.argv0, args, env });
11408
+ return this.start({ ...req, cwd, program, argv0: target.argv0, args, env });
11307
11409
  }
11308
11410
  groupSession(pgid) {
11309
11411
  return this.jobs.sessionOf(pgid);
@@ -11710,7 +11812,8 @@ var Launcher = class {
11710
11812
  async starting(argv, dir) {
11711
11813
  this.catalog = void 0;
11712
11814
  this.binfmts = void 0;
11713
- const cwd = this.fs.resolvePath("/", dir ?? "/");
11815
+ const start2 = dir ?? "/";
11816
+ const cwd = await physicalPathAsync(this.base, start2.startsWith("/") ? start2 : `/${start2}`);
11714
11817
  const [file = ""] = argv;
11715
11818
  await this.base.mkdir(cwd, { recursive: true });
11716
11819
  return { cwd, file, planned: await this.plan(file, argv, cwd) };
@@ -11869,26 +11972,26 @@ var MemoryFile = class {
11869
11972
  return new File(this.data.blobs, this.name, { lastModified: this.lastModified });
11870
11973
  }
11871
11974
  async createWritable({ keepExistingData = false } = {}) {
11872
- const next = keepExistingData ? new Chunks([...this.data.blobs], this.data.size) : new Chunks();
11975
+ const next2 = keepExistingData ? new Chunks([...this.data.blobs], this.data.size) : new Chunks();
11873
11976
  let position = 0;
11874
11977
  const put = async (data) => {
11875
11978
  const bytes = await bytesOf(data);
11876
- await next.write(position, bytes);
11979
+ await next2.write(position, bytes);
11877
11980
  position += bytes.length;
11878
11981
  };
11879
11982
  return {
11880
11983
  write: async (data) => {
11881
11984
  if (!isParams(data)) return put(data);
11882
- if (data.type === "truncate") return next.truncate(data.size ?? 0);
11985
+ if (data.type === "truncate") return next2.truncate(data.size ?? 0);
11883
11986
  position = data.position ?? position;
11884
11987
  if (data.type === "write") await put(data.data);
11885
11988
  },
11886
11989
  seek: async (at) => {
11887
11990
  position = at;
11888
11991
  },
11889
- truncate: async (size) => next.truncate(size),
11992
+ truncate: async (size) => next2.truncate(size),
11890
11993
  close: async () => {
11891
- this.data = next;
11994
+ this.data = next2;
11892
11995
  this.lastModified = Date.now();
11893
11996
  },
11894
11997
  abort: async () => {
@@ -12339,11 +12442,11 @@ function stream(chunks2, socket, signal) {
12339
12442
  },
12340
12443
  async pull(controller) {
12341
12444
  try {
12342
- const next = await chunks2.next();
12343
- if (next.done) {
12445
+ const next2 = await chunks2.next();
12446
+ if (next2.done) {
12344
12447
  controller.close();
12345
12448
  socket.close();
12346
- } else controller.enqueue(next.value);
12449
+ } else controller.enqueue(next2.value);
12347
12450
  } catch (err) {
12348
12451
  controller.error(err);
12349
12452
  socket.close();
@@ -12571,12 +12674,12 @@ async function dialOn(channel, { port, host }) {
12571
12674
  return dialStream(await since(channel, 4, "dial", () => channel.call(req)));
12572
12675
  }
12573
12676
  async function spawnOn(channel, argv, opts) {
12574
- const { onStdout, onStderr, stdin, group: _, ...rest } = opts;
12677
+ const { onStdout, onStderr, stdin, group: _, ...rest2 } = opts;
12575
12678
  if (opts.pgid !== void 0)
12576
12679
  await since(channel, 3, "spawn into a process group", async () => {
12577
12680
  });
12578
12681
  const started = Promise.withResolvers();
12579
- const options = { ...rest, ...stdin !== void 0 ? { stdin: bytesOf2(stdin) } : {} };
12682
+ const options = { ...rest2, ...stdin !== void 0 ? { stdin: bytesOf2(stdin) } : {} };
12580
12683
  const { done: done4 } = channel.request(
12581
12684
  { op: "spawn", argv, options },
12582
12685
  {
@@ -12595,7 +12698,7 @@ async function spawnOn(channel, argv, opts) {
12595
12698
  };
12596
12699
  }
12597
12700
  async function runOn(channel, argv, opts) {
12598
- const { onStdout, onStderr, ...rest } = opts;
12701
+ const { onStdout, onStderr, ...rest2 } = opts;
12599
12702
  const chunks2 = { 1: [], 2: [] };
12600
12703
  const live = { 1: new TextDecoder(), 2: new TextDecoder() };
12601
12704
  const tee = (fd, on) => (bytes) => {
@@ -12603,7 +12706,7 @@ async function runOn(channel, argv, opts) {
12603
12706
  on?.(live[fd].decode(bytes, { stream: true }));
12604
12707
  };
12605
12708
  const child = await spawnOn(channel, argv, {
12606
- ...rest,
12709
+ ...rest2,
12607
12710
  onStdout: tee(1, onStdout),
12608
12711
  onStderr: tee(2, onStderr)
12609
12712
  });
@@ -12632,9 +12735,9 @@ async function terminalOn(channel, argv, opts) {
12632
12735
  get onData() {
12633
12736
  return listener;
12634
12737
  },
12635
- set onData(next) {
12636
- listener = next;
12637
- if (next) for (const bytes of backlog.splice(0)) next(bytes);
12738
+ set onData(next2) {
12739
+ listener = next2;
12740
+ if (next2) for (const bytes of backlog.splice(0)) next2(bytes);
12638
12741
  },
12639
12742
  write: (data) => send({ action: "write", bytes: bytesOf2(data) }),
12640
12743
  resize: (cols, rows) => send({ action: "resize", cols, rows }),
@@ -12745,8 +12848,8 @@ async function attachKernel(port, options = {}) {
12745
12848
  mounts: () => since(channel, 2, "mounts", () => channel.call({ op: "mounts" })),
12746
12849
  kill: async (pid, signal = "SIGTERM") => void await channel.call({ op: "kill", pid, signal }),
12747
12850
  fetch: (req) => {
12748
- const { signal, ...rest } = req;
12749
- return transport.fetch({ ...rest, signal: signal ?? new AbortController().signal });
12851
+ const { signal, ...rest2 } = req;
12852
+ return transport.fetch({ ...rest2, signal: signal ?? new AbortController().signal });
12750
12853
  },
12751
12854
  dial: (options2) => dialOn(channel, options2),
12752
12855
  loopbackFetch: (input, options2) => loopbackFetch((o) => dialOn(channel, o), input, options2),
@@ -12863,12 +12966,12 @@ async function createNodeKernel(options = {}) {
12863
12966
  return {
12864
12967
  root,
12865
12968
  async run(argv, opts = {}) {
12866
- const { stdin, onStdout, onStderr, ...rest } = opts;
12969
+ const { stdin, onStdout, onStderr, ...rest2 } = opts;
12867
12970
  const onOut = textOf(onStdout);
12868
12971
  const onErr = textOf(onStderr);
12869
12972
  const result = await guard(
12870
12973
  () => launcher.run(argv, {
12871
- ...rest,
12974
+ ...rest2,
12872
12975
  ...stdin !== void 0 ? { stdin: typeof stdin === "string" ? new TextEncoder().encode(stdin) : stdin } : {},
12873
12976
  ...onOut ? { onStdout: onOut } : {},
12874
12977
  ...onErr ? { onStderr: onErr } : {}
@@ -12881,12 +12984,12 @@ async function createNodeKernel(options = {}) {
12881
12984
  };
12882
12985
  },
12883
12986
  async openTerminal(argv, opts = {}) {
12884
- const { onData, ...rest } = opts;
12987
+ const { onData, ...rest2 } = opts;
12885
12988
  let listener = onData ?? null;
12886
12989
  const backlog = [];
12887
12990
  const session = await guard(
12888
12991
  () => launcher.openTerminal(argv, {
12889
- ...rest,
12992
+ ...rest2,
12890
12993
  onData: (bytes) => listener ? listener(bytes) : backlog.push(bytes)
12891
12994
  })
12892
12995
  );
@@ -12896,9 +12999,9 @@ async function createNodeKernel(options = {}) {
12896
12999
  get onData() {
12897
13000
  return listener;
12898
13001
  },
12899
- set onData(next) {
12900
- listener = next;
12901
- if (next) for (const bytes of backlog.splice(0)) next(bytes);
13002
+ set onData(next2) {
13003
+ listener = next2;
13004
+ if (next2) for (const bytes of backlog.splice(0)) next2(bytes);
12902
13005
  },
12903
13006
  write: (data) => session.write(typeof data === "string" ? new TextEncoder().encode(data) : data),
12904
13007
  resize: (cols, rows) => session.resize(cols, rows),