@sma1lboy/kobe 0.8.200 → 0.9.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.
@@ -401,6 +401,57 @@ function recordPtyExit(info, path = defaultPtyExitsPath()) {
401
401
  import { mkdirSync as mkdirSync2, readFileSync as readFileSync3, readdirSync, renameSync, rmSync, writeFileSync as writeFileSync2 } from "node:fs";
402
402
  import { join as join2 } from "node:path";
403
403
  import { StringDecoder } from "node:string_decoder";
404
+
405
+ // ../kobe-daemon/src/daemon/terminal-colors.ts
406
+ var DEFAULT_TERMINAL_COLORS = {
407
+ foreground: "#eae7df",
408
+ background: "#141413"
409
+ };
410
+ var HEX_COLOR_RE = /^#[0-9a-f]{6}$/i;
411
+ var DEFAULT_COLOR_QUERY_RE = /\x1b\](10|11);\?(?:\x07|\x1b\\)/g;
412
+ var QUERY_PREFIXES = ["\x1B]10;?", "\x1B]11;?"];
413
+ function normalizeColor(value) {
414
+ return typeof value === "string" && HEX_COLOR_RE.test(value) ? value.toLowerCase() : null;
415
+ }
416
+ function parseTerminalDefaultColors(value) {
417
+ if (typeof value !== "object" || value === null || Array.isArray(value))
418
+ return null;
419
+ const raw = value;
420
+ const foreground = normalizeColor(raw.foreground);
421
+ const background = normalizeColor(raw.background);
422
+ return foreground && background ? { foreground, background } : null;
423
+ }
424
+ function oscRgb(color) {
425
+ const hex = color.slice(1);
426
+ return [hex.slice(0, 2), hex.slice(2, 4), hex.slice(4, 6)].map((component) => component.repeat(2)).join("/");
427
+ }
428
+ function formatDefaultColorReply(slot, colors) {
429
+ const color = slot === 10 ? colors.foreground : colors.background;
430
+ return `\x1B]${slot};rgb:${oscRgb(color)}\x1B\\`;
431
+ }
432
+ function trailingQueryPrefix(text) {
433
+ const maxLength = QUERY_PREFIXES[0].length + 1;
434
+ const start = Math.max(0, text.length - maxLength);
435
+ for (let index = start;index < text.length; index++) {
436
+ const suffix = text.slice(index);
437
+ if (QUERY_PREFIXES.some((prefix) => prefix.startsWith(suffix) || suffix === `${prefix}\x1B`))
438
+ return suffix;
439
+ }
440
+ return "";
441
+ }
442
+ function foldDefaultColorQueries(previousCarry, chunkText) {
443
+ const text = previousCarry + chunkText;
444
+ const slots = [];
445
+ let end = 0;
446
+ DEFAULT_COLOR_QUERY_RE.lastIndex = 0;
447
+ for (let match = DEFAULT_COLOR_QUERY_RE.exec(text);match; match = DEFAULT_COLOR_QUERY_RE.exec(text)) {
448
+ slots.push(match[1] === "10" ? 10 : 11);
449
+ end = match.index + match[0].length;
450
+ }
451
+ return { slots, carry: trailingQueryPrefix(text.slice(end)) };
452
+ }
453
+
454
+ // ../kobe-daemon/src/daemon/pty-freeze-store.ts
404
455
  var FREEZE_VERSION = 1;
405
456
  function freezeSession(session, now = new Date) {
406
457
  return {
@@ -445,6 +496,8 @@ function thawSession(record, cap) {
445
496
  title: record.title,
446
497
  titleCarry: "",
447
498
  titleDecoder: new StringDecoder("utf8"),
499
+ colorQueryCarry: "",
500
+ defaultColors: DEFAULT_TERMINAL_COLORS,
448
501
  sinks: new Map,
449
502
  parked: false,
450
503
  parkedScreenBytes: 0,
@@ -605,6 +658,8 @@ function freshSessionState(key, spec, argv) {
605
658
  title: "",
606
659
  titleCarry: "",
607
660
  titleDecoder: new StringDecoder2("utf8"),
661
+ colorQueryCarry: "",
662
+ defaultColors: parseTerminalDefaultColors(spec.defaultColors) ?? DEFAULT_TERMINAL_COLORS,
608
663
  sinks: new Map,
609
664
  parked: false,
610
665
  parkedScreenBytes: 0,
@@ -816,6 +871,13 @@ class PtyChildController {
816
871
  }
817
872
  onData(session, data) {
818
873
  const buf = typeof data === "string" ? Buffer.from(data, "utf8") : Buffer.from(data);
874
+ const colorQueries = foldDefaultColorQueries(session.colorQueryCarry, buf.toString("latin1"));
875
+ session.colorQueryCarry = colorQueries.carry;
876
+ for (const slot of colorQueries.slots) {
877
+ try {
878
+ session.proc?.write(formatDefaultColorReply(slot, session.defaultColors));
879
+ } catch {}
880
+ }
819
881
  scanOscTitle(session, buf);
820
882
  session.chunks.push(buf);
821
883
  session.bytes += buf.byteLength;
@@ -856,6 +918,7 @@ class WarmSpare {
856
918
  return null;
857
919
  this.spare = null;
858
920
  spare.key = key;
921
+ spare.defaultColors = parseTerminalDefaultColors(spec.defaultColors) ?? spare.defaultColors;
859
922
  const cols = spec.cols ?? spare.cols;
860
923
  const rows = spec.rows ?? spare.rows;
861
924
  if (spare.cols !== cols || spare.rows !== rows) {
@@ -962,6 +1025,9 @@ class PtyHost {
962
1025
  } else if (session.alive && spec.cols !== undefined && spec.rows !== undefined && (session.cols !== spec.cols || session.rows !== spec.rows)) {
963
1026
  this.resize(key, spec.cols, spec.rows);
964
1027
  }
1028
+ const defaultColors = parseTerminalDefaultColors(spec.defaultColors);
1029
+ if (defaultColors)
1030
+ session.defaultColors = defaultColors;
965
1031
  session.sinks.set(token, sink);
966
1032
  session.parked = false;
967
1033
  session.parkedScreenBytes = 0;
@@ -1101,6 +1167,7 @@ class PtyHost {
1101
1167
  session.command = [...spec.command];
1102
1168
  session.cols = spec.cols ?? session.cols;
1103
1169
  session.rows = spec.rows ?? session.rows;
1170
+ session.defaultColors = parseTerminalDefaultColors(spec.defaultColors) ?? session.defaultColors;
1104
1171
  this.childController.startChild(session);
1105
1172
  if (!session.alive)
1106
1173
  return;
@@ -1240,7 +1307,8 @@ async function startPtyHostServer(options = {}) {
1240
1307
  command: Array.isArray(payload.command) ? payload.command.filter((c) => typeof c === "string") : undefined,
1241
1308
  shell: typeof payload.shell === "string" ? payload.shell : undefined,
1242
1309
  cols: typeof payload.cols === "number" ? payload.cols : undefined,
1243
- rows: typeof payload.rows === "number" ? payload.rows : undefined
1310
+ rows: typeof payload.rows === "number" ? payload.rows : undefined,
1311
+ defaultColors: parseTerminalDefaultColors(payload.defaultColors) ?? undefined
1244
1312
  }, client, (frame) => writeFrame(client, frame), typeof payload.sinceOffset === "number" ? payload.sinceOffset : undefined, typeof payload.sincePid === "number" ? payload.sincePid : undefined);
1245
1313
  }
1246
1314
  case "pty.write": {