@ai-ecoverse/slicc-kernel 1.75.1 → 1.77.0

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
@@ -5312,7 +5312,8 @@ function commandOf(pkg, name2, raw, packageAbi, shared) {
5312
5312
  return { name: name2, abi: packageAbi, glue: script, wasm: script, argv0: name2, script, ...withEnv };
5313
5313
  }
5314
5314
  const abi = abiOf(raw.abi, packageAbi);
5315
- const argv0 = typeof raw.argv0 === "string" && raw.argv0 ? raw.argv0 : name2;
5315
+ const fixed = typeof raw.argv0 === "string" && raw.argv0 !== "";
5316
+ const argv0 = fixed ? raw.argv0 : name2;
5316
5317
  const args = argsOf(pkg, raw.args);
5317
5318
  if (abi === "js") {
5318
5319
  const module = inside(pkg, raw.module);
@@ -5323,6 +5324,7 @@ function commandOf(pkg, name2, raw, packageAbi, shared) {
5323
5324
  glue: module,
5324
5325
  wasm: module,
5325
5326
  argv0,
5327
+ ...fixed ? { argv0Fixed: true } : {},
5326
5328
  ...raw.argv0Path === true ? { argv0Path: true } : {},
5327
5329
  ...args ? { args } : {},
5328
5330
  ...withEnv
@@ -5338,6 +5340,7 @@ function commandOf(pkg, name2, raw, packageAbi, shared) {
5338
5340
  glue,
5339
5341
  wasm,
5340
5342
  argv0,
5343
+ ...fixed ? { argv0Fixed: true } : {},
5341
5344
  ...raw.argv0Path === true ? { argv0Path: true } : {},
5342
5345
  ...abi === "wasi" && raw.preopenRoot === true ? { preopenRoot: true } : {},
5343
5346
  ...args ? { args } : {},
@@ -7958,6 +7961,7 @@ var IDLE_OPS = /* @__PURE__ */ new Set([
7958
7961
  ]);
7959
7962
  var SYS_CAP_US = 2e4;
7960
7963
  var LOCAL = SAB_CLOCK_OFFSET;
7964
+ var BLOCKED = 0;
7961
7965
  var IDLE = 1;
7962
7966
  function epochMicros() {
7963
7967
  return Math.floor((performance.timeOrigin + performance.now()) * 1e3);
@@ -8032,6 +8036,7 @@ var CpuClock = class {
8032
8036
  const busy = this.kind === "sys" ? Math.min(spent, SYS_CAP_US) : 0;
8033
8037
  this.sys += busy;
8034
8038
  this.idle += spent - busy;
8039
+ Atomics.store(slots(this.sab), BLOCKED, BigInt(this.idle));
8035
8040
  }
8036
8041
  };
8037
8042
  var ProcessClocks = class {
@@ -8403,8 +8408,8 @@ function pidStat(info, boot) {
8403
8408
  0,
8404
8409
  ticks(info.utime ?? 0),
8405
8410
  ticks(info.stime ?? 0),
8406
- 0,
8407
- 0,
8411
+ ticks(info.cutime ?? 0),
8412
+ ticks(info.cstime ?? 0),
8408
8413
  20,
8409
8414
  0,
8410
8415
  1,
@@ -8428,8 +8433,9 @@ function pidStat(info, boot) {
8428
8433
  `;
8429
8434
  }
8430
8435
  var sigMask = (mask = 0) => (mask >>> 1).toString(16).padStart(16, "0");
8436
+ var STATES = { S: "S (sleeping)", T: "T (stopped)", Z: "Z (zombie)" };
8431
8437
  function pidStatus(info) {
8432
- const state = info.state === "Z" ? "Z (zombie)" : "S (sleeping)";
8438
+ const state = STATES[info.state];
8433
8439
  const c = info.cred ?? ROOT;
8434
8440
  const ids = (r, e, s) => `${r} ${e} ${s} ${e}`;
8435
8441
  return [
@@ -11163,6 +11169,7 @@ async function runChild(req, deps) {
11163
11169
  {
11164
11170
  file: req.file,
11165
11171
  argv: req.argv,
11172
+ ...req.argv0 !== void 0 ? { argv0: req.argv0 } : {},
11166
11173
  env: req.env,
11167
11174
  cwd: req.cwd,
11168
11175
  ...req.pgid !== void 0 ? { pgid: req.pgid } : {},
@@ -12038,6 +12045,16 @@ function words(value) {
12038
12045
  }
12039
12046
  return [...value];
12040
12047
  }
12048
+ var ESCAPES = { " ": "\\t", "\n": "\\n", "\r": "\\r" };
12049
+ function clipboardLine(text) {
12050
+ let out = "";
12051
+ for (const c of text) {
12052
+ const code = c.charCodeAt(0);
12053
+ const control = code < 32 || code === 127;
12054
+ out += control ? ESCAPES[c] ?? `\\x${code.toString(16).padStart(2, "0")}` : c;
12055
+ }
12056
+ return out.length > 200 ? `${out.slice(0, 200)}\u2026` : out;
12057
+ }
12041
12058
  var DYING = { ok: false, errno: "EINTR", message: "the process is being killed" };
12042
12059
  var HOSTS_ONLY = new Resolver({ routes: new Routes() });
12043
12060
  var WasmProcess = class {
@@ -12121,9 +12138,10 @@ var WasmProcess = class {
12121
12138
  return "deliver";
12122
12139
  }
12123
12140
  async spawn(req) {
12124
- const { file, argv, env, cwd, stdio, inherit: inherit2, exec, pgid, session } = req;
12141
+ const { file, argv, argv0, env, cwd, stdio, inherit: inherit2, exec, pgid, session } = req;
12125
12142
  const group = { ...pgid !== void 0 ? { pgid } : {}, ...session ? { session } : {} };
12126
- const spawned = { file, argv, env, cwd, ...group, ...exec ? { exec } : {} };
12143
+ const named = argv0 !== void 0 ? { argv0 } : {};
12144
+ const spawned = { file, argv, ...named, env, cwd, ...group, ...exec ? { exec } : {} };
12127
12145
  const pid = await this.children.spawn(spawned, stdio, inherit2);
12128
12146
  if (!exec) return pid;
12129
12147
  if (this.killed) void Promise.allSettled([this.options.kill?.(pid, SIG.KILL)]);
@@ -12289,7 +12307,22 @@ var WasmProcess = class {
12289
12307
  if (req.max <= 0) return new Uint8Array(0);
12290
12308
  if (channel.unread) channel.stamp = await this.clipboardStamp();
12291
12309
  const signal = channel.settled ? this.interrupt.signal : this.blockingSignal(cancelled);
12292
- return channel.read(Math.min(req.max, MAX_READ), signal);
12310
+ try {
12311
+ return await channel.read(Math.min(req.max, MAX_READ), signal);
12312
+ } catch (err) {
12313
+ await this.clipboardComplaint(err);
12314
+ throw err;
12315
+ }
12316
+ }
12317
+ async clipboardComplaint(err) {
12318
+ const name2 = this.options.clipboardName;
12319
+ if (name2 === void 0 || !(err instanceof KernelError) || err.detail === void 0) return;
12320
+ if (err.code !== "EACCES" && err.code !== "EIO") return;
12321
+ const stderr = this.fds.has(2) ? this.fds.get(2).file : void 0;
12322
+ if (!stderr?.write || stderr.clipboard) return;
12323
+ const line = `${name2}: /dev/clipboard: ${clipboardLine(err.detail)}
12324
+ `;
12325
+ await stderr.write(new TextEncoder().encode(line), AbortSignal.timeout(1e3)).catch(() => 0);
12293
12326
  }
12294
12327
  async write(fd, body, nonblock = false, cancelled) {
12295
12328
  const file = this.fds.get(fd).file;
@@ -12502,7 +12535,10 @@ var WasmProcess = class {
12502
12535
  this.options.locks?.closed(this.pid, req.fd);
12503
12536
  const channel = this.fds.get(req.fd).file.clipboard;
12504
12537
  if (channel) channel.stamp = await this.clipboardStamp();
12505
- await Promise.resolve(this.fds.close(req.fd));
12538
+ await Promise.resolve(this.fds.close(req.fd)).catch(async (err) => {
12539
+ if (channel) await this.clipboardComplaint(err);
12540
+ throw err;
12541
+ });
12506
12542
  return { ok: true, kind: "void" };
12507
12543
  }
12508
12544
  case "fd-pipe": {
@@ -13193,12 +13229,15 @@ function holdingToken(opts, holds, caller) {
13193
13229
  renamed: (from, to) => holds.renamed(from, to)
13194
13230
  });
13195
13231
  }
13232
+ function clipboardName(opts) {
13233
+ return opts.program.abi === "js" ? {} : { clipboardName: opts.argv0 };
13234
+ }
13196
13235
  function processOptions(opts, header4, hooks, created3) {
13197
13236
  return {
13198
13237
  ...inherited(opts),
13199
13238
  ...opts.owners ? { owners: true } : {},
13200
13239
  ...opts.sealed ? { sealed: opts.sealed } : {},
13201
- ...opts.clipboard ? { clipboard: opts.clipboard } : {},
13240
+ ...opts.clipboard ? { clipboard: opts.clipboard, ...clipboardName(opts) } : {},
13202
13241
  ...opts.readonlyAt ? { readonlyAt: opts.readonlyAt } : {},
13203
13242
  ...opts.dac ? { guard: { dac: opts.dac, fs: opts.fs, created: created3 } } : {},
13204
13243
  ...opts.identity ? { identity: opts.identity } : {},
@@ -16054,6 +16093,7 @@ function targetOf(command) {
16054
16093
  glue: command.glue,
16055
16094
  wasm: command.wasm,
16056
16095
  argv0: command.argv0,
16096
+ ...command.argv0Fixed ? { fixed: true } : {},
16057
16097
  ...command.args ? { prefix: command.args } : {},
16058
16098
  ...command.env ? { env: command.env } : {},
16059
16099
  ...command.unset ? { unset: command.unset } : {},
@@ -16089,6 +16129,10 @@ function concat5(chunks2) {
16089
16129
  }
16090
16130
  return out;
16091
16131
  }
16132
+ function addTimes(into, pid, t) {
16133
+ const at = into.get(pid) ?? { utime: 0, stime: 0 };
16134
+ into.set(pid, { utime: at.utime + t.utime, stime: at.stime + t.stime });
16135
+ }
16092
16136
  var Launcher = class {
16093
16137
  fs;
16094
16138
  processFs;
@@ -16416,8 +16460,10 @@ var Launcher = class {
16416
16460
  const target = withScriptEnv(found, command);
16417
16461
  return { target, args: [...target.prefix ?? [], ...passed], via: [interp] };
16418
16462
  }
16419
- async plan(file, argv, cwd, scope) {
16420
- const direct = await this.resolve(file, argv[0] ?? file, cwd, scope);
16463
+ async plan(file, argv, cwd, scope, argv0) {
16464
+ const found = await this.resolve(file, argv[0] ?? file, cwd, scope);
16465
+ const named = typeof argv0 === "string" && found && !found.fixed;
16466
+ const direct = named ? { ...found, argv0 } : found;
16421
16467
  if (direct) return { target: direct, args: [...direct.prefix ?? [], ...argv.slice(1)] };
16422
16468
  const script = await this.interpreted(file, argv, cwd, scope);
16423
16469
  return script && { ...script, script: true };
@@ -16624,7 +16670,7 @@ var Launcher = class {
16624
16670
  http: new HttpHandles(this.transport, pid),
16625
16671
  locks: this.locks,
16626
16672
  resolver: this.resolver,
16627
- onReap: (child) => this.reaped(child),
16673
+ onReap: (child) => this.reaped(child, pid),
16628
16674
  ...req.fork ? { fork: req.fork } : {},
16629
16675
  ...this.shownIds(req)
16630
16676
  });
@@ -16643,9 +16689,14 @@ var Launcher = class {
16643
16689
  tty: terminal?.name ?? null,
16644
16690
  started: Date.now()
16645
16691
  });
16692
+ handle.onState(
16693
+ (state) => state === "stopped" ? this.stopped.add(pid) : this.stopped.delete(pid)
16694
+ );
16646
16695
  void handle.exited.then(() => {
16647
16696
  const spent = handle.times?.();
16648
16697
  if (spent) this.spent.set(pid, spent);
16698
+ if (spent) addTimes(this.imageTimes, this.jobs.shown(pid), spent);
16699
+ this.stopped.delete(pid);
16649
16700
  this.processes.delete(pid);
16650
16701
  if (this.processes.size === 0) {
16651
16702
  clearInterval(this.sampler);
@@ -16673,11 +16724,20 @@ var Launcher = class {
16673
16724
  this.reapedTimes.stime += spent.stime;
16674
16725
  }
16675
16726
  this.spent.delete(pid);
16727
+ this.imageTimes.delete(pid);
16728
+ this.childTimes.delete(pid);
16676
16729
  this.creds.delete(pid);
16677
16730
  this.tags.delete(pid);
16678
16731
  this.granted.delete(pid);
16679
16732
  }
16680
- reaped(pid) {
16733
+ reaped(pid, parent) {
16734
+ const own = this.imageTimes.get(pid);
16735
+ const theirs = this.childTimes.get(pid);
16736
+ const into = this.jobs.shown(parent);
16737
+ if (own) addTimes(this.childTimes, into, own);
16738
+ if (theirs) addTimes(this.childTimes, into, theirs);
16739
+ this.imageTimes.delete(pid);
16740
+ this.childTimes.delete(pid);
16681
16741
  if (this.zombies.delete(pid)) this.forget(pid);
16682
16742
  else this.orphans.add(pid);
16683
16743
  }
@@ -16729,6 +16789,17 @@ var Launcher = class {
16729
16789
  this.sampler.unref?.();
16730
16790
  }
16731
16791
  spent = /* @__PURE__ */ new Map();
16792
+ imageTimes = /* @__PURE__ */ new Map();
16793
+ childTimes = /* @__PURE__ */ new Map();
16794
+ stopped = /* @__PURE__ */ new Set();
16795
+ stateOf(pid) {
16796
+ if (!this.processes.has(pid)) return "Z";
16797
+ return this.stopped.has(pid) ? "T" : "S";
16798
+ }
16799
+ childrenOf(pid) {
16800
+ const t = this.childTimes.get(pid);
16801
+ return t ? { cutime: t.utime, cstime: t.stime } : {};
16802
+ }
16732
16803
  timesAt(pid) {
16733
16804
  return this.processes.get(pid)?.times?.() ?? this.spent.get(pid);
16734
16805
  }
@@ -16774,9 +16845,10 @@ var Launcher = class {
16774
16845
  sid: member.sid,
16775
16846
  ...described2,
16776
16847
  started: (this.described.get(root.pid) ?? described2).started,
16777
- state: this.processes.has(member.pid) ? "S" : "Z",
16848
+ state: this.stateOf(member.pid),
16778
16849
  memory: this.processes.get(member.pid)?.memory() ?? 0,
16779
16850
  ...this.timesOf(member, members),
16851
+ ...this.childrenOf(root.pid),
16780
16852
  umask: this.umaskOf(member.pid),
16781
16853
  cred,
16782
16854
  ...this.signalMasksOf(member.pid)
@@ -16806,7 +16878,7 @@ var Launcher = class {
16806
16878
  }
16807
16879
  const cred = grant ? grant.cred : this.credOf(ppid);
16808
16880
  const scope = grant ? "" : await this.scopeOf(cred.euid);
16809
- const planned = await this.plan(req.file, req.argv, req.cwd, scope);
16881
+ const planned = await this.plan(req.file, req.argv, req.cwd, scope, req.argv0);
16810
16882
  try {
16811
16883
  await this.mayExec(cred, { ...req, pid: ppid }, planned);
16812
16884
  } catch (err) {