@ai-ecoverse/slicc-kernel 1.162.1 → 1.163.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.
package/README.md CHANGED
@@ -422,6 +422,11 @@ The module's default export (or its `main` export) is called with a context and
422
422
  - `asyncContext` (the Node entry only; absent in a browser, so a runtime feature-detects it; #1350, slicc-jsh#375) is `{ run(store, fn, ...args), getStore(), enterWith(store) }`, backed by one host `AsyncLocalStorage` the process worker makes for each program, since a program can't import `node:async_hooks` and the realm has no promise hooks of its own. A store follows the program's native `await` continuations and promise jobs, as an `AsyncLocalStorage` does in Node, so Next.js, OpenTelemetry and request-context loggers keep their context. Each process and each thread has its own. Only these three frozen functions on a frozen null-prototype object reach the program: they hold the host storage in a closure, `run` calls the program's function with its own arguments, and nothing they return or expose is a host object.
423
423
  - `sync.runScript(source, { filename })` (#1541, slicc-jsh#977) runs `source` as a classic script in the program's own global scope, synchronously, as Node's `vm.runInThisContext` does: `let`, `const` and `class` land in the global lexical scope, `var` (in strict code too) on the global object, and stack frames are named `filename` (default `[eval]`). On the Node entry it returns `{ value, completion: true }` with the completion value, and an error the script throws is thrown as it is. In a browser, where process workers are module workers with no synchronous classic-script path, it returns `undefined`, so a runtime feature-detects it with `ctx.sync.runScript('1') !== undefined`. A non-string `source` or `filename` is a `TypeError` everywhere. The script sees exactly the globals the program sees, `import()` inside it is refused, and a `var`, function or `let` declaration can't replace a global the program can't assign: a non-configurable one stays as it is, and the only configurable, non-assignable ones (`crypto`, `navigator`) are ones the program can already redefine with `Object.defineProperty`.
424
424
  - `sync.promiseState(promise)` (#1531, slicc-jsh#974) tells a native promise's state synchronously, as Node's `util.inspect` does: `{ state: 'pending' | 'fulfilled' | 'rejected', value }`. `value` is the very fulfillment value or rejection reason (`undefined` while pending), and probing doesn't handle a rejection. On the Node entry it reads the promise through an inspector session the process worker opens on first use, one per process and per thread; the probe runs no program code. Anything that isn't a native promise (a thenable, a proxy) is a `TypeError`. It answers `undefined` in a browser, where a worker has no inspector, on a Node built without one, once a program has changed `Object.prototype` or put a `toJSON` on a built-in prototype, and when the global object can't take a new property (`Object.preventExtensions(globalThis)`, or a frozen global).
425
+ - `sync.setStackFormatter(fn | null)` (#1612, slicc-jsh#1091) is Node only, so check it with `typeof ctx.sync.setStackFormatter === 'function'`. It returns the previous formatter, and `null` removes it.
426
+ - **When `fn` runs:** it formats an error's `.stack` the way V8's prepare-stack-trace callback does, as `fn(error, callSites)` returning the string. It runs only when no own `Error.prepareStackTrace` function is set, as in Node, so `Error.prepareStackTrace` stays an ordinary property: after `delete` it's `undefined`, `Object.getPrototypeOf(Error)` stays `Function.prototype`, and an assignment to a frozen subclass throws in strict mode.
427
+ - **What `fn` gets:** a fresh array of V8 CallSites holding only the program's own frames (its modules, `data:` imports, `sync.runScript` scripts and code they `eval`), `node:` frames and native frames. Kernel frames are dropped by script identity, so a script named like a kernel file doesn't let them through, and so are host files. A program's strict frames give `getFunction()` and `getThis()` as `undefined`.
428
+ - **Fallback:** if `fn` throws or returns a non-string, or an error is formatted while `fn` runs, the default stack is used.
429
+ - **How it works:** process workers start with `--expose-internals`, so the worker can install the formatter before the lockdown. Host flags a worker refuses are dropped. If the worker still can't start with the flag, the method is absent. Every `internal/*` and `node:internal/*` module stays refused to programs, as do `node:module` and `node:worker_threads`.
425
430
  - **Kernel frames in a program's stacks** (#1583): on the Node entry, the process worker's bundle names itself `slicc-kernel:/node-process-worker.js` (a `sourceURL`), so the kernel's own frames in an error a program sees (its own errors, a failed `ctx` call, `runScript`) show that name and not the host directory the kernel is installed in. The same holds in `CallSite.toString()` and `getScriptNameOrSourceURL()`, which a program's own `Error.prepareStackTrace` gets; `getFileName()` still returns the bundle's file URL. Line and column numbers are unchanged, so they still point into `dist/node-process-worker.js`. Don't run an embedder with `--enable-source-maps` if program-visible paths matter: Node then maps the kernel's frames back to the absolute paths of its sources. In a browser the frames keep the bundle's URL, because Chrome ignores `sourceURL` in a module worker loaded by URL.
426
431
  - `module` (#1598, slicc-jsh#566) is a frozen `{ path }` with the command module's own path in the kernel's file system (e.g. `/usr/lib/node_modules/jsh/dist/jsh.mjs`), so a program can read its package's other files through `ctx.fs` on first use. It's the path the kernel found the package under, with symlinks left as they are (a pnpm-style `node_modules/<name>` link stays in it), and reads the same files through `ctx.fs`. It's a kernel path, never a host one, and a thread gets the same. It's absent for the kernel's built-in programs (`sudo`, `crontab`) and for a program run from inline source with no file.
427
432
  - `memory()`, synchronous and without a kernel call, measures the calling isolate: each `thread` answers for its own (#1240, slicc-jsh#397). It returns a fresh plain object of numbers in bytes, each field only where it's measured: `heapUsed`, `heapTotal`, `heapLimit` (V8's heap size limit), `external`, `arrayBuffers` and `rss`. On the Node entry they come from V8's heap statistics and Node's memory usage, through functions the worker captured before its lockdown, so nothing reachable from the program leads back to `process` or `v8`. `rss` is the host process's resident set size, as a Node worker thread reports it in `process.memoryUsage().rss`: it isn't per process, but shared by every process and thread of the kernel, and by any other kernel in that host process (#1563, slicc-jsh#539). In a browser `memory()` answers `{}` for now, with no `rss`.
@@ -8437,7 +8437,7 @@ function satisfies(version, range2) {
8437
8437
  }
8438
8438
 
8439
8439
  // src/version.ts
8440
- var KERNEL_VERSION = true ? "1.162.1" : "0.0.0-dev";
8440
+ var KERNEL_VERSION = true ? "1.163.1" : "0.0.0-dev";
8441
8441
  var OS_RELEASE = "6.0.0-slicc";
8442
8442
  function procVersion() {
8443
8443
  return `Linux version ${OS_RELEASE} (slicc-kernel ${KERNEL_VERSION}) #1 SMP PREEMPT_DYNAMIC
@@ -13230,6 +13230,11 @@ var HeldSet = class extends Set {
13230
13230
  async bindIds(id2) {
13231
13231
  for (const holds2 of [...this]) await holds2.bindIds(id2);
13232
13232
  }
13233
+ heldIds() {
13234
+ const out = /* @__PURE__ */ new Map();
13235
+ for (const holds2 of this) for (const [path, fid] of holds2.heldIds()) out.set(path, fid);
13236
+ return [...out];
13237
+ }
13233
13238
  delete(holds2) {
13234
13239
  const removed = super.delete(holds2);
13235
13240
  for (const path of /* @__PURE__ */ new Set([...holds2.keys(), ...holds2.opens.keys()])) this.idle(path);
@@ -13296,6 +13301,14 @@ var HeldPaths = class extends Map {
13296
13301
  this.bound.set(handle, { ...bound3, fid });
13297
13302
  }
13298
13303
  }
13304
+ heldIds() {
13305
+ const out = [];
13306
+ for (const [handle, key] of this.handles) {
13307
+ if (this.keptHandles.has(handle)) continue;
13308
+ out.push([key, this.bound.get(handle)?.fid]);
13309
+ }
13310
+ return out;
13311
+ }
13299
13312
  trust(handle, doubt) {
13300
13313
  if (this.doubted.get(handle) === doubt) this.doubted.delete(handle);
13301
13314
  }
@@ -33504,6 +33517,10 @@ var Launcher = class {
33504
33517
  for (const [holds2, ids] of keeping) holds2.keepBound(ids, path, file);
33505
33518
  void this.rootFs.announceHolds?.([], [path, hidden], false);
33506
33519
  }
33520
+ announceHeld() {
33521
+ const held = this.held.heldIds().filter(([path]) => this.mounts.locate(path) === void 0);
33522
+ return held.length === 0 ? void 0 : this.rootFs.announceHolds?.(held, [], false);
33523
+ }
33507
33524
  rootFileId(path) {
33508
33525
  return this.mounts.locate(path) === void 0 ? this.rootFs.bindId?.(path) : void 0;
33509
33526
  }
@@ -33514,7 +33531,7 @@ var Launcher = class {
33514
33531
  this.changes.flush();
33515
33532
  this.changes.foreign(crowded);
33516
33533
  if (crowded) {
33517
- void this.held?.bindIds((path) => this.rootFileId(path));
33534
+ void this.held?.bindIds((path) => this.rootFileId(path)).then(() => this.announceHeld());
33518
33535
  for (const nodes of this.openFiles) nodes.shared();
33519
33536
  }
33520
33537
  });