@ai-ecoverse/slicc-kernel 1.130.1 → 1.131.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.
@@ -6479,7 +6479,7 @@ var KERNEL_VERSION, OS_RELEASE;
6479
6479
  var init_version = __esm({
6480
6480
  "src/version.ts"() {
6481
6481
  "use strict";
6482
- KERNEL_VERSION = true ? "1.130.1" : "0.0.0-dev";
6482
+ KERNEL_VERSION = true ? "1.131.0" : "0.0.0-dev";
6483
6483
  OS_RELEASE = "6.0.0-slicc";
6484
6484
  }
6485
6485
  });
package/dist/node.js CHANGED
@@ -7394,7 +7394,7 @@ function satisfies(version, range2) {
7394
7394
  }
7395
7395
 
7396
7396
  // src/version.ts
7397
- var KERNEL_VERSION = true ? "1.130.1" : "0.0.0-dev";
7397
+ var KERNEL_VERSION = true ? "1.131.0" : "0.0.0-dev";
7398
7398
  var OS_RELEASE = "6.0.0-slicc";
7399
7399
  function procVersion() {
7400
7400
  return `Linux version ${OS_RELEASE} (slicc-kernel ${KERNEL_VERSION}) #1 SMP PREEMPT_DYNAMIC
@@ -17601,7 +17601,7 @@ var TOKEN5 = "[!#$%&'*+.^_`|~0-9a-z-]+";
17601
17601
  var HEADER = new RegExp(`^header:${TOKEN5}$`);
17602
17602
  var METHOD = /^[!#$%&'*+.^_`|~0-9A-Za-z-]+$/;
17603
17603
  var TARGET = /^[\x21-\x7e]+$/;
17604
- var SESSION_EXIT = /^(tailscale|device:[A-Za-z0-9._-]+)$/;
17604
+ var SESSION_EXIT = /^(tailscale|device:[A-Za-z0-9._:-]+)$/;
17605
17605
  var HOST = /^[a-z0-9.:-]+$/;
17606
17606
  var UNSAFE = /[\r\n\0]/;
17607
17607
  var POSITIONS = {
@@ -18350,6 +18350,90 @@ async function substituteHead(head, ask) {
18350
18350
  `, values };
18351
18351
  }
18352
18352
 
18353
+ // src/kernel/net/sealed-pg.ts
18354
+ var PG_MESSAGE_MAX = 16 * 1024;
18355
+ var PROTOCOL_3 = 196608;
18356
+ var CLEARTEXT = 3;
18357
+ function int32(bytes, at) {
18358
+ return bytes[at] << 24 | bytes[at + 1] << 16 | bytes[at + 2] << 8 | bytes[at + 3];
18359
+ }
18360
+ function sniffPg(start2) {
18361
+ const bytes = Uint8Array.from(start2, (c) => c.charCodeAt(0));
18362
+ if (bytes.length === 0 || bytes[0] !== 0) return bytes.length === 0 ? "more" : "no";
18363
+ if (bytes.length < 8) return "more";
18364
+ const length2 = int32(bytes, 0);
18365
+ return length2 >= 8 && length2 <= PG_MESSAGE_MAX && int32(bytes, 4) === PROTOCOL_3 ? "yes" : "no";
18366
+ }
18367
+ var PgServer = class {
18368
+ buffer = new Uint8Array(0);
18369
+ skip = 0;
18370
+ lost = false;
18371
+ cleartext = false;
18372
+ feed(bytes) {
18373
+ if (this.lost) return;
18374
+ const data = new Uint8Array(this.buffer.length + bytes.length);
18375
+ data.set(this.buffer);
18376
+ data.set(bytes, this.buffer.length);
18377
+ let at = 0;
18378
+ for (; ; ) {
18379
+ const left = data.length - at;
18380
+ if (this.skip > 0) {
18381
+ const n = Math.min(this.skip, left);
18382
+ this.skip -= n;
18383
+ at += n;
18384
+ if (this.skip > 0) break;
18385
+ continue;
18386
+ }
18387
+ if (left < 5) break;
18388
+ const type = data[at];
18389
+ const whole = 1 + int32(data, at + 1);
18390
+ if (whole < 5 || type === 82 && whole > PG_MESSAGE_MAX) {
18391
+ this.lost = true;
18392
+ this.cleartext = false;
18393
+ this.buffer = new Uint8Array(0);
18394
+ return;
18395
+ }
18396
+ if (type !== 82) {
18397
+ this.skip = whole;
18398
+ continue;
18399
+ }
18400
+ if (left < whole) break;
18401
+ this.cleartext = whole === 9 && int32(data, at + 5) === CLEARTEXT;
18402
+ at += whole;
18403
+ }
18404
+ this.buffer = data.slice(at);
18405
+ }
18406
+ };
18407
+ function frame3(type, body) {
18408
+ const out = new Uint8Array(5 + body.length);
18409
+ out[0] = type;
18410
+ const length2 = 4 + body.length;
18411
+ out.set([length2 >>> 24 & 255, length2 >>> 16 & 255, length2 >>> 8 & 255, length2 & 255], 1);
18412
+ for (let i = 0; i < body.length; i++) out[5 + i] = body.charCodeAt(i);
18413
+ return out;
18414
+ }
18415
+ function pgLength(bytes, started) {
18416
+ const header4 = started ? 5 : 4;
18417
+ if (bytes.length < header4) return void 0;
18418
+ const length2 = int32(bytes, started ? 1 : 0);
18419
+ return started ? 1 + length2 : length2;
18420
+ }
18421
+ async function pgPassword(message3, server, ask) {
18422
+ if (message3[0] !== 112 || !server.cleartext) return { bytes: message3, done: true };
18423
+ server.cleartext = false;
18424
+ let body = "";
18425
+ for (const b of message3.subarray(5)) body += String.fromCharCode(b);
18426
+ if (!body.endsWith("\0") || body.indexOf("\0") !== body.length - 1)
18427
+ return { bytes: message3, done: true };
18428
+ const password = body.slice(0, -1);
18429
+ const placeholders = placeholdersIn(password);
18430
+ if (placeholders.length === 0 || placeholders.length > SESSION_PLACEHOLDERS)
18431
+ return { bytes: message3, done: true };
18432
+ const values = usable(await ask(placeholders));
18433
+ if (Object.keys(values).length === 0) return { bytes: message3, done: true };
18434
+ return { bytes: frame3(112, `${replaced(password, values)}\0`), values, done: true };
18435
+ }
18436
+
18353
18437
  // src/kernel/net/sealed-smtp.ts
18354
18438
  var SMTP_LINE_MAX = 4096;
18355
18439
  var GREETING = ["EHLO ", "HELO "];
@@ -18471,11 +18555,14 @@ function headEnd2(bytes) {
18471
18555
  return -1;
18472
18556
  }
18473
18557
  function modeOf(start2) {
18474
- const http = sniffHttp1(start2);
18475
- const smtp = sniffSmtp(start2);
18476
- if (http === "yes") return "http1";
18477
- if (smtp === "yes") return "smtp";
18478
- return http === "no" && smtp === "no" ? "pass" : void 0;
18558
+ const sniffs = [
18559
+ ["http1", sniffHttp1(start2)],
18560
+ ["smtp", sniffSmtp(start2)],
18561
+ ["pg", sniffPg(start2)]
18562
+ ];
18563
+ const hit = sniffs.find(([, v]) => v === "yes");
18564
+ if (hit) return hit[0];
18565
+ return sniffs.every(([, v]) => v === "no") ? "pass" : void 0;
18479
18566
  }
18480
18567
  function crlf(bytes) {
18481
18568
  for (let i = 0; i + 1 < bytes.length; i++) if (bytes[i] === 13 && bytes[i + 1] === 10) return i;
@@ -18489,12 +18576,15 @@ var SessionWriter = class {
18489
18576
  failed;
18490
18577
  session = sessionId();
18491
18578
  smtp;
18579
+ pgStarted = false;
18492
18580
  conn;
18493
18581
  s;
18582
+ pg;
18494
18583
  scope;
18495
- constructor(conn, s, scope) {
18584
+ constructor(conn, s, pg, scope) {
18496
18585
  this.conn = conn;
18497
18586
  this.s = s;
18587
+ this.pg = pg;
18498
18588
  this.scope = scope;
18499
18589
  this.smtp = new SmtpClient(
18500
18590
  (position, placeholders) => this.ask("smtp", position, placeholders)
@@ -18543,6 +18633,7 @@ var SessionWriter = class {
18543
18633
  if (this.mode === "pass") await this.release();
18544
18634
  else if (this.mode === "http1") await this.http1();
18545
18635
  else if (this.mode === "smtp") await this.lines();
18636
+ else if (this.mode === "pg") await this.messages();
18546
18637
  if (this.mode !== "pass" && this.buffer.length > 0)
18547
18638
  this.timer = setTimeout(() => this.idle(), HEAD_IDLE_MS);
18548
18639
  return bytes.length;
@@ -18573,6 +18664,33 @@ var SessionWriter = class {
18573
18664
  }
18574
18665
  if (this.buffer.length > SMTP_LINE_MAX) await this.release();
18575
18666
  }
18667
+ async messages() {
18668
+ for (; ; ) {
18669
+ const whole = pgLength(this.buffer, this.pgStarted);
18670
+ if (whole === void 0 || whole < 4 || whole > PG_MESSAGE_MAX) {
18671
+ if (whole !== void 0) await this.release();
18672
+ return;
18673
+ }
18674
+ if (this.buffer.length < whole) return;
18675
+ const message3 = this.buffer.slice(0, whole);
18676
+ this.buffer = this.buffer.slice(whole);
18677
+ const started = this.pgStarted;
18678
+ this.pgStarted = true;
18679
+ const out = started ? await pgPassword(
18680
+ message3,
18681
+ this.pg,
18682
+ (placeholders) => this.ask("pg", "password-cleartext", placeholders)
18683
+ ).catch(() => ({ bytes: message3, done: true })) : { bytes: message3, done: false };
18684
+ if ("values" in out && out.values) this.remember(out.values);
18685
+ try {
18686
+ await writeAll4(this.conn, out.bytes);
18687
+ } finally {
18688
+ out.bytes.fill(0);
18689
+ message3.fill(0);
18690
+ }
18691
+ if (out.done) return this.release();
18692
+ }
18693
+ }
18576
18694
  idle() {
18577
18695
  this.chain = this.chain.then(() => this.release()).catch((err) => {
18578
18696
  this.failed ??= err;
@@ -18686,9 +18804,18 @@ function idle() {
18686
18804
  return new Promise((resolve2) => setTimeout(() => resolve2(IDLE2), SCRUB_IDLE_MS));
18687
18805
  }
18688
18806
  function sealedConn(conn, s) {
18807
+ const pg = new PgServer();
18689
18808
  const scope = s.broker.sessions.scope(s.pid, s.host);
18690
- const writer = substitutes(s) ? new SessionWriter(conn, s, scope) : void 0;
18691
- const reader = new ScrubReader(conn, scope);
18809
+ const writer = substitutes(s) ? new SessionWriter(conn, s, pg, scope) : void 0;
18810
+ const observed = {
18811
+ ...conn,
18812
+ read: async () => {
18813
+ const bytes = await conn.read();
18814
+ if (bytes) pg.feed(bytes);
18815
+ return bytes;
18816
+ }
18817
+ };
18818
+ const reader = new ScrubReader(writer ? observed : conn, scope);
18692
18819
  return {
18693
18820
  localAddr: conn.localAddr,
18694
18821
  remoteAddr: conn.remoteAddr,
@@ -23946,6 +24073,7 @@ var SETUP_OPS = /* @__PURE__ */ new Set([
23946
24073
  "proc-identity",
23947
24074
  "fd-info",
23948
24075
  "sig-mask",
24076
+ "sig-inherited",
23949
24077
  "proc-setpgid",
23950
24078
  "tty-pgrp-set",
23951
24079
  "proc-exec",