pi-outpost 0.32.2 → 0.32.4

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.
@@ -11177,19 +11177,19 @@ function getRgbColor(color3, defaultColor = new Uint8ClampedArray(3)) {
11177
11177
  if (!Array.isArray(color3)) {
11178
11178
  return defaultColor;
11179
11179
  }
11180
- const rgbColor = defaultColor || new Uint8ClampedArray(3);
11180
+ const rgbColor2 = defaultColor || new Uint8ClampedArray(3);
11181
11181
  switch (color3.length) {
11182
11182
  case 0:
11183
11183
  return null;
11184
11184
  case 1:
11185
- ColorSpaceUtils.gray.getRgbItem(color3, 0, rgbColor, 0);
11186
- return rgbColor;
11185
+ ColorSpaceUtils.gray.getRgbItem(color3, 0, rgbColor2, 0);
11186
+ return rgbColor2;
11187
11187
  case 3:
11188
- ColorSpaceUtils.rgb.getRgbItem(color3, 0, rgbColor, 0);
11189
- return rgbColor;
11188
+ ColorSpaceUtils.rgb.getRgbItem(color3, 0, rgbColor2, 0);
11189
+ return rgbColor2;
11190
11190
  case 4:
11191
- ColorSpaceUtils.cmyk.getRgbItem(color3, 0, rgbColor, 0);
11192
- return rgbColor;
11191
+ ColorSpaceUtils.cmyk.getRgbItem(color3, 0, rgbColor2, 0);
11192
+ return rgbColor2;
11193
11193
  default:
11194
11194
  return defaultColor;
11195
11195
  }
@@ -15076,20 +15076,20 @@ var init_pdf_worker = __esm({
15076
15076
  stringify: function stringify(text7, replacer2, space) {
15077
15077
  var replacerFunction = getReplacerFunction(replacer2);
15078
15078
  var rawStrings = [];
15079
- var json = stringifyWithProperSymbolsConversion(text7, function(key, value) {
15079
+ var json2 = stringifyWithProperSymbolsConversion(text7, function(key, value) {
15080
15080
  var v2 = isCallable(replacerFunction) ? call(replacerFunction, this, $String(key), value) : value;
15081
15081
  return !NATIVE_RAW_JSON && isRawJSON(v2) ? MARK2 + (push2(rawStrings, v2.rawJSON) - 1) : v2;
15082
15082
  }, space);
15083
- if (typeof json != "string") return json;
15084
- if (ILL_FORMED_UNICODE) json = replace2(json, surrogates, fixIllFormedJSON);
15085
- if (NATIVE_RAW_JSON) return json;
15083
+ if (typeof json2 != "string") return json2;
15084
+ if (ILL_FORMED_UNICODE) json2 = replace2(json2, surrogates, fixIllFormedJSON);
15085
+ if (NATIVE_RAW_JSON) return json2;
15086
15086
  var result = "";
15087
- var length = json.length;
15087
+ var length = json2.length;
15088
15088
  for (var i2 = 0; i2 < length; i2++) {
15089
- var chr = charAt(json, i2);
15089
+ var chr = charAt(json2, i2);
15090
15090
  if (chr === '"') {
15091
- var end = parseJSONString(json, ++i2).end - 1;
15092
- var string3 = slice3(json, i2, end);
15091
+ var end = parseJSONString(json2, ++i2).end - 1;
15092
+ var string3 = slice3(json2, i2, end);
15093
15093
  result += slice3(string3, 0, MARK_LENGTH) === MARK2 ? rawStrings[slice3(string3, MARK_LENGTH)] : '"' + string3 + '"';
15094
15094
  i2 = end;
15095
15095
  } else result += chr;
@@ -18174,9 +18174,9 @@ var init_pdf_worker = __esm({
18174
18174
  kind
18175
18175
  } = imgData;
18176
18176
  const rgbaSize = width * height * 4;
18177
- const K3 = Math.ceil(Math.log2(rgbaSize / MAX_INT_32));
18178
- const newWidth = width >> K3;
18179
- const newHeight = height >> K3;
18177
+ const K4 = Math.ceil(Math.log2(rgbaSize / MAX_INT_32));
18178
+ const newWidth = width >> K4;
18179
+ const newHeight = height >> K4;
18180
18180
  let rgbaData;
18181
18181
  let maxHeight = height;
18182
18182
  try {
@@ -18216,10 +18216,10 @@ var init_pdf_worker = __esm({
18216
18216
  inverseDecode: this._isMask,
18217
18217
  srcPos
18218
18218
  }));
18219
- for (let i2 = 0, ii = h >> K3; i2 < ii; i2++) {
18220
- const buf = src32.subarray((i2 << K3) * width);
18219
+ for (let i2 = 0, ii = h >> K4; i2 < ii; i2++) {
18220
+ const buf = src32.subarray((i2 << K4) * width);
18221
18221
  for (let j2 = 0; j2 < newWidth; j2++) {
18222
- dest32[newIndex++] = buf[j2 << K3];
18222
+ dest32[newIndex++] = buf[j2 << K4];
18223
18223
  }
18224
18224
  }
18225
18225
  }
@@ -49488,9 +49488,9 @@ var init_pdf_worker = __esm({
49488
49488
  const flags = outlineDict.get("F") || 0;
49489
49489
  const color3 = outlineDict.getArray("C");
49490
49490
  const count = outlineDict.get("Count");
49491
- let rgbColor = blackColor;
49491
+ let rgbColor2 = blackColor;
49492
49492
  if (isNumberArray(color3, 3) && (color3[0] !== 0 || color3[1] !== 0 || color3[2] !== 0)) {
49493
- rgbColor = ColorSpaceUtils.rgb.getRgb(color3, 0);
49493
+ rgbColor2 = ColorSpaceUtils.rgb.getRgb(color3, 0);
49494
49494
  }
49495
49495
  const outlineItem = {
49496
49496
  action: data.action,
@@ -49502,7 +49502,7 @@ var init_pdf_worker = __esm({
49502
49502
  newWindow: data.newWindow,
49503
49503
  setOCGState: data.setOCGState,
49504
49504
  title: typeof title === "string" ? stringToPDFString(title) : "",
49505
- color: rgbColor,
49505
+ color: rgbColor2,
49506
49506
  count: Number.isInteger(count) ? count : void 0,
49507
49507
  bold: !!(flags & 2),
49508
49508
  italic: !!(flags & 1),
@@ -76124,20 +76124,20 @@ var init_pdf = __esm({
76124
76124
  stringify: function stringify(text7, replacer2, space) {
76125
76125
  var replacerFunction = getReplacerFunction(replacer2);
76126
76126
  var rawStrings = [];
76127
- var json = stringifyWithProperSymbolsConversion(text7, function(key, value) {
76127
+ var json2 = stringifyWithProperSymbolsConversion(text7, function(key, value) {
76128
76128
  var v2 = isCallable(replacerFunction) ? call(replacerFunction, this, $String(key), value) : value;
76129
76129
  return !NATIVE_RAW_JSON && isRawJSON(v2) ? MARK2 + (push2(rawStrings, v2.rawJSON) - 1) : v2;
76130
76130
  }, space);
76131
- if (typeof json != "string") return json;
76132
- if (ILL_FORMED_UNICODE) json = replace2(json, surrogates, fixIllFormedJSON);
76133
- if (NATIVE_RAW_JSON) return json;
76131
+ if (typeof json2 != "string") return json2;
76132
+ if (ILL_FORMED_UNICODE) json2 = replace2(json2, surrogates, fixIllFormedJSON);
76133
+ if (NATIVE_RAW_JSON) return json2;
76134
76134
  var result = "";
76135
- var length = json.length;
76135
+ var length = json2.length;
76136
76136
  for (var i2 = 0; i2 < length; i2++) {
76137
- var chr = charAt(json, i2);
76137
+ var chr = charAt(json2, i2);
76138
76138
  if (chr === '"') {
76139
- var end = parseJSONString(json, ++i2).end - 1;
76140
- var string3 = slice3(json, i2, end);
76139
+ var end = parseJSONString(json2, ++i2).end - 1;
76140
+ var string3 = slice3(json2, i2, end);
76141
76141
  result += slice3(string3, 0, MARK_LENGTH) === MARK2 ? rawStrings[slice3(string3, MARK_LENGTH)] : '"' + string3 + '"';
76142
76142
  i2 = end;
76143
76143
  } else result += chr;
@@ -96787,9 +96787,9 @@ fn fs_main(in : VertexOutput) -> @location(0) vec4<f32> {
96787
96787
  return false;
96788
96788
  }
96789
96789
  const diffD = d - this.#min_dist;
96790
- const K3 = diffD / d;
96791
- const shiftX = K3 * diffX;
96792
- const shiftY = K3 * diffY;
96790
+ const K4 = diffD / d;
96791
+ const shiftX = K4 * diffX;
96792
+ const shiftY = K4 * diffY;
96793
96793
  let x0 = x1;
96794
96794
  let y0 = y1;
96795
96795
  x1 = x22;
@@ -107313,6 +107313,67 @@ var require_javascript = __commonJS({
107313
107313
  }
107314
107314
  });
107315
107315
 
107316
+ // ../node_modules/@earendil-works/pi-coding-agent/node_modules/highlight.js/lib/languages/json.js
107317
+ var require_json = __commonJS({
107318
+ "../node_modules/@earendil-works/pi-coding-agent/node_modules/highlight.js/lib/languages/json.js"(exports, module) {
107319
+ function json2(hljs2) {
107320
+ const LITERALS = {
107321
+ literal: "true false null"
107322
+ };
107323
+ const ALLOWED_COMMENTS = [
107324
+ hljs2.C_LINE_COMMENT_MODE,
107325
+ hljs2.C_BLOCK_COMMENT_MODE
107326
+ ];
107327
+ const TYPES = [
107328
+ hljs2.QUOTE_STRING_MODE,
107329
+ hljs2.C_NUMBER_MODE
107330
+ ];
107331
+ const VALUE_CONTAINER = {
107332
+ end: ",",
107333
+ endsWithParent: true,
107334
+ excludeEnd: true,
107335
+ contains: TYPES,
107336
+ keywords: LITERALS
107337
+ };
107338
+ const OBJECT = {
107339
+ begin: /\{/,
107340
+ end: /\}/,
107341
+ contains: [
107342
+ {
107343
+ className: "attr",
107344
+ begin: /"/,
107345
+ end: /"/,
107346
+ contains: [hljs2.BACKSLASH_ESCAPE],
107347
+ illegal: "\\n"
107348
+ },
107349
+ hljs2.inherit(VALUE_CONTAINER, {
107350
+ begin: /:/
107351
+ })
107352
+ ].concat(ALLOWED_COMMENTS),
107353
+ illegal: "\\S"
107354
+ };
107355
+ const ARRAY = {
107356
+ begin: "\\[",
107357
+ end: "\\]",
107358
+ contains: [hljs2.inherit(VALUE_CONTAINER)],
107359
+ // inherit is a workaround for a bug that makes shared modes with endsWithParent compile only the ending of one of the parents
107360
+ illegal: "\\S"
107361
+ };
107362
+ TYPES.push(OBJECT, ARRAY);
107363
+ ALLOWED_COMMENTS.forEach(function(rule) {
107364
+ TYPES.push(rule);
107365
+ });
107366
+ return {
107367
+ name: "JSON",
107368
+ contains: TYPES,
107369
+ keywords: LITERALS,
107370
+ illegal: "\\S"
107371
+ };
107372
+ }
107373
+ module.exports = json2;
107374
+ }
107375
+ });
107376
+
107316
107377
  // ../node_modules/@earendil-works/pi-coding-agent/node_modules/highlight.js/lib/languages/kotlin.js
107317
107378
  var require_kotlin = __commonJS({
107318
107379
  "../node_modules/@earendil-works/pi-coding-agent/node_modules/highlight.js/lib/languages/kotlin.js"(exports, module) {
@@ -110788,6 +110849,9 @@ import Fastify from "fastify";
110788
110849
  import {
110789
110850
  createAgentSessionFromServices,
110790
110851
  createAgentSessionServices,
110852
+ createCodemodeExtension,
110853
+ createMcpExtension,
110854
+ createToolSearchExtension,
110791
110855
  getAgentDir as getAgentDir2,
110792
110856
  SessionManager
110793
110857
  } from "@earendil-works/pi-coding-agent";
@@ -124467,7 +124531,7 @@ function collectShapes(operators2, ops) {
124467
124531
  const shapes = [];
124468
124532
  let ctm = [1, 0, 0, 1, 0, 0];
124469
124533
  const stack = [];
124470
- const multiply = (m2, n) => [
124534
+ const multiply2 = (m2, n) => [
124471
124535
  m2[0] * n[0] + m2[2] * n[1],
124472
124536
  m2[1] * n[0] + m2[3] * n[1],
124473
124537
  m2[0] * n[2] + m2[2] * n[3],
@@ -124486,7 +124550,7 @@ function collectShapes(operators2, ops) {
124486
124550
  ctm = stack.pop() ?? ctm;
124487
124551
  } else if (op2 === ops.transform) {
124488
124552
  const args = operators2.argsArray[index4];
124489
- if (Array.isArray(args) && args.length >= 6) ctm = multiply(ctm, args);
124553
+ if (Array.isArray(args) && args.length >= 6) ctm = multiply2(ctm, args);
124490
124554
  } else if (op2 === ops.constructPath) {
124491
124555
  const args = operators2.argsArray[index4];
124492
124556
  if (args === void 0) continue;
@@ -124512,7 +124576,7 @@ function collectImages(operators2, ops) {
124512
124576
  const images = [];
124513
124577
  let ctm = [1, 0, 0, 1, 0, 0];
124514
124578
  const stack = [];
124515
- const multiply = (m2, n) => [
124579
+ const multiply2 = (m2, n) => [
124516
124580
  m2[0] * n[0] + m2[2] * n[1],
124517
124581
  m2[1] * n[0] + m2[3] * n[1],
124518
124582
  m2[0] * n[2] + m2[2] * n[3],
@@ -124531,7 +124595,7 @@ function collectImages(operators2, ops) {
124531
124595
  continue;
124532
124596
  }
124533
124597
  if (fn2 === ops.transform) {
124534
- ctm = multiply(ctm, operators2.argsArray[at4]);
124598
+ ctm = multiply2(ctm, operators2.argsArray[at4]);
124535
124599
  continue;
124536
124600
  }
124537
124601
  if (fn2 !== ops.paintImageXObject && fn2 !== ops.paintInlineImageXObject) continue;
@@ -138250,12 +138314,12 @@ var require_xml2json = /* @__PURE__ */ __commonJSMin(((exports, module) => {
138250
138314
  return options;
138251
138315
  }
138252
138316
  module.exports = function(xml, userOptions) {
138253
- var options = validateOptions(userOptions), js = xml2js(xml, options), json, parentKey = "compact" in options && options.compact ? "_parent" : "parent";
138254
- if ("addParent" in options && options.addParent) json = JSON.stringify(js, function(k2, v2) {
138317
+ var options = validateOptions(userOptions), js = xml2js(xml, options), json2, parentKey = "compact" in options && options.compact ? "_parent" : "parent";
138318
+ if ("addParent" in options && options.addParent) json2 = JSON.stringify(js, function(k2, v2) {
138255
138319
  return k2 === parentKey ? "_" : v2;
138256
138320
  }, options.spaces);
138257
- else json = JSON.stringify(js, null, options.spaces);
138258
- return json.replace(/\u2028/g, "\\u2028").replace(/\u2029/g, "\\u2029");
138321
+ else json2 = JSON.stringify(js, null, options.spaces);
138322
+ return json2.replace(/\u2028/g, "\\u2028").replace(/\u2029/g, "\\u2029");
138259
138323
  };
138260
138324
  }));
138261
138325
  var require_js2xml = /* @__PURE__ */ __commonJSMin(((exports, module) => {
@@ -138521,15 +138585,15 @@ var require_js2xml = /* @__PURE__ */ __commonJSMin(((exports, module) => {
138521
138585
  }));
138522
138586
  var require_json2xml = /* @__PURE__ */ __commonJSMin(((exports, module) => {
138523
138587
  var js2xml = require_js2xml();
138524
- module.exports = function(json, options) {
138525
- if (json instanceof Buffer) json = json.toString();
138588
+ module.exports = function(json2, options) {
138589
+ if (json2 instanceof Buffer) json2 = json2.toString();
138526
138590
  var js = null;
138527
- if (typeof json === "string") try {
138528
- js = JSON.parse(json);
138591
+ if (typeof json2 === "string") try {
138592
+ js = JSON.parse(json2);
138529
138593
  } catch (e) {
138530
138594
  throw new Error("The JSON structure is invalid");
138531
138595
  }
138532
- else js = json;
138596
+ else js = json2;
138533
138597
  return js2xml(js, options);
138534
138598
  };
138535
138599
  }));
@@ -140352,7 +140416,7 @@ var require_ripemd = /* @__PURE__ */ __commonJSMin(((exports) => {
140352
140416
  var Dh = D3;
140353
140417
  var Eh = E;
140354
140418
  for (var j2 = 0; j2 < 80; j2++) {
140355
- var T5 = sum32(rotl32(sum32_4(A5, f2(j2, B4, C2, D3), msg[r[j2] + start], K3(j2)), s[j2]), E);
140419
+ var T5 = sum32(rotl32(sum32_4(A5, f2(j2, B4, C2, D3), msg[r[j2] + start], K4(j2)), s[j2]), E);
140356
140420
  A5 = E;
140357
140421
  E = D3;
140358
140422
  D3 = rotl32(C2, 10);
@@ -140383,7 +140447,7 @@ var require_ripemd = /* @__PURE__ */ __commonJSMin(((exports) => {
140383
140447
  else if (j2 <= 63) return x2 & z3 | y2 & ~z3;
140384
140448
  else return x2 ^ (y2 | ~z3);
140385
140449
  }
140386
- function K3(j2) {
140450
+ function K4(j2) {
140387
140451
  if (j2 <= 15) return 0;
140388
140452
  else if (j2 <= 31) return 1518500249;
140389
140453
  else if (j2 <= 47) return 1859775393;
@@ -147716,7 +147780,7 @@ var require_jszip_min = /* @__PURE__ */ __commonJSMin(((exports, module) => {
147716
147780
  var t2;
147717
147781
  return e2 && e2.state ? (e2.total_in = e2.total_out = 0, e2.data_type = i2, (t2 = e2.state).pending = 0, t2.pending_out = 0, t2.wrap < 0 && (t2.wrap = -t2.wrap), t2.status = t2.wrap ? C2 : E, e2.adler = 2 === t2.wrap ? 0 : 1, t2.last_flush = l3, u._tr_init(t2), m2) : R4(e2, _2);
147718
147782
  }
147719
- function K3(e2) {
147783
+ function K4(e2) {
147720
147784
  var t2 = G2(e2);
147721
147785
  return t2 === m2 && (function(e3) {
147722
147786
  e3.window_size = 2 * e3.w_size, D3(e3.head), e3.max_lazy_match = h[e3.level].max_lazy, e3.good_match = h[e3.level].good_length, e3.nice_match = h[e3.level].nice_length, e3.max_chain_length = h[e3.level].max_chain, e3.strstart = 0, e3.block_start = 0, e3.lookahead = 0, e3.insert = 0, e3.match_length = e3.prev_length = x2 - 1, e3.match_available = 0, e3.ins_h = 0;
@@ -147728,7 +147792,7 @@ var require_jszip_min = /* @__PURE__ */ __commonJSMin(((exports, module) => {
147728
147792
  if (t2 === g && (t2 = 6), n2 < 0 ? (a2 = 0, n2 = -n2) : 15 < n2 && (a2 = 2, n2 -= 16), i3 < 1 || y2 < i3 || r2 !== v2 || n2 < 8 || 15 < n2 || t2 < 0 || 9 < t2 || s2 < 0 || b2 < s2) return R4(e2, _2);
147729
147793
  8 === n2 && (n2 = 9);
147730
147794
  var o2 = new H3();
147731
- return (e2.state = o2).strm = e2, o2.wrap = a2, o2.gzhead = null, o2.w_bits = n2, o2.w_size = 1 << o2.w_bits, o2.w_mask = o2.w_size - 1, o2.hash_bits = i3 + 7, o2.hash_size = 1 << o2.hash_bits, o2.hash_mask = o2.hash_size - 1, o2.hash_shift = ~~((o2.hash_bits + x2 - 1) / x2), o2.window = new c2.Buf8(2 * o2.w_size), o2.head = new c2.Buf16(o2.hash_size), o2.prev = new c2.Buf16(o2.w_size), o2.lit_bufsize = 1 << i3 + 6, o2.pending_buf_size = 4 * o2.lit_bufsize, o2.pending_buf = new c2.Buf8(o2.pending_buf_size), o2.d_buf = 1 * o2.lit_bufsize, o2.l_buf = 3 * o2.lit_bufsize, o2.level = t2, o2.strategy = s2, o2.method = r2, K3(e2);
147795
+ return (e2.state = o2).strm = e2, o2.wrap = a2, o2.gzhead = null, o2.w_bits = n2, o2.w_size = 1 << o2.w_bits, o2.w_mask = o2.w_size - 1, o2.hash_bits = i3 + 7, o2.hash_size = 1 << o2.hash_bits, o2.hash_mask = o2.hash_size - 1, o2.hash_shift = ~~((o2.hash_bits + x2 - 1) / x2), o2.window = new c2.Buf8(2 * o2.w_size), o2.head = new c2.Buf16(o2.hash_size), o2.prev = new c2.Buf16(o2.w_size), o2.lit_bufsize = 1 << i3 + 6, o2.pending_buf_size = 4 * o2.lit_bufsize, o2.pending_buf = new c2.Buf8(o2.pending_buf_size), o2.d_buf = 1 * o2.lit_bufsize, o2.l_buf = 3 * o2.lit_bufsize, o2.level = t2, o2.strategy = s2, o2.method = r2, K4(e2);
147732
147796
  }
147733
147797
  h = [
147734
147798
  new M3(0, 0, 0, 0, function(e2, t2) {
@@ -147756,7 +147820,7 @@ var require_jszip_min = /* @__PURE__ */ __commonJSMin(((exports, module) => {
147756
147820
  new M3(32, 258, 258, 4096, W2)
147757
147821
  ], r.deflateInit = function(e2, t2) {
147758
147822
  return Y3(e2, t2, v2, 15, 8, 0);
147759
- }, r.deflateInit2 = Y3, r.deflateReset = K3, r.deflateResetKeep = G2, r.deflateSetHeader = function(e2, t2) {
147823
+ }, r.deflateInit2 = Y3, r.deflateReset = K4, r.deflateResetKeep = G2, r.deflateSetHeader = function(e2, t2) {
147760
147824
  return e2 && e2.state ? 2 !== e2.state.wrap ? _2 : (e2.state.gzhead = t2, m2) : _2;
147761
147825
  }, r.deflate = function(e2, t2) {
147762
147826
  var r2, n2, i3, s2;
@@ -148706,7 +148770,7 @@ var require_jszip_min = /* @__PURE__ */ __commonJSMin(((exports, module) => {
148706
148770
  for (var n2 = e2.heap[r2], i3 = r2 << 1; i3 <= e2.heap_len && (i3 < e2.heap_len && H3(t2, e2.heap[i3 + 1], e2.heap[i3], e2.depth) && i3++, !H3(t2, n2, e2.heap[i3], e2.depth)); ) e2.heap[r2] = e2.heap[i3], r2 = i3, i3 <<= 1;
148707
148771
  e2.heap[r2] = n2;
148708
148772
  }
148709
- function K3(e2, t2, r2) {
148773
+ function K4(e2, t2, r2) {
148710
148774
  var n2, i3, s2, a2, o2 = 0;
148711
148775
  if (0 !== e2.last_lit) for (; n2 = e2.pending_buf[e2.d_buf + 2 * o2] << 8 | e2.pending_buf[e2.d_buf + 2 * o2 + 1], i3 = e2.pending_buf[e2.l_buf + o2], o2++, 0 === n2 ? L2(e2, i3, t2) : (L2(e2, (s2 = A5[i3]) + u + 1, t2), 0 !== (a2 = w[s2]) && P5(e2, i3 -= I3[s2], a2), L2(e2, s2 = N(--n2), r2), 0 !== (a2 = k2[s2]) && P5(e2, n2 -= T5[s2], a2)), o2 < e2.last_lit; ) ;
148712
148776
  L2(e2, m2, t2);
@@ -148775,11 +148839,11 @@ var require_jszip_min = /* @__PURE__ */ __commonJSMin(((exports, module) => {
148775
148839
  var t3;
148776
148840
  for (X3(e3, e3.dyn_ltree, e3.l_desc.max_code), X3(e3, e3.dyn_dtree, e3.d_desc.max_code), Y3(e3, e3.bl_desc), t3 = c2 - 1; 3 <= t3 && 0 === e3.bl_tree[2 * S3[t3] + 1]; t3--) ;
148777
148841
  return e3.opt_len += 3 * (t3 + 1) + 5 + 5 + 4, t3;
148778
- })(e2), i3 = e2.opt_len + 3 + 7 >>> 3, (s2 = e2.static_len + 3 + 7 >>> 3) <= i3 && (i3 = s2)) : i3 = s2 = r2 + 5, r2 + 4 <= i3 && -1 !== t2 ? J3(e2, t2, r2, n2) : 4 === e2.strategy || s2 === i3 ? (P5(e2, 2 + (n2 ? 1 : 0), 3), K3(e2, z3, C2)) : (P5(e2, 4 + (n2 ? 1 : 0), 3), (function(e3, t3, r3, n3) {
148842
+ })(e2), i3 = e2.opt_len + 3 + 7 >>> 3, (s2 = e2.static_len + 3 + 7 >>> 3) <= i3 && (i3 = s2)) : i3 = s2 = r2 + 5, r2 + 4 <= i3 && -1 !== t2 ? J3(e2, t2, r2, n2) : 4 === e2.strategy || s2 === i3 ? (P5(e2, 2 + (n2 ? 1 : 0), 3), K4(e2, z3, C2)) : (P5(e2, 4 + (n2 ? 1 : 0), 3), (function(e3, t3, r3, n3) {
148779
148843
  var i4;
148780
148844
  for (P5(e3, t3 - 257, 5), P5(e3, r3 - 1, 5), P5(e3, n3 - 4, 4), i4 = 0; i4 < n3; i4++) P5(e3, e3.bl_tree[2 * S3[i4] + 1], 3);
148781
148845
  V3(e3, e3.dyn_ltree, t3 - 1), V3(e3, e3.dyn_dtree, r3 - 1);
148782
- })(e2, e2.l_desc.max_code + 1, e2.d_desc.max_code + 1, a2 + 1), K3(e2, e2.dyn_ltree, e2.dyn_dtree)), W2(e2), n2 && M3(e2);
148846
+ })(e2, e2.l_desc.max_code + 1, e2.d_desc.max_code + 1, a2 + 1), K4(e2, e2.dyn_ltree, e2.dyn_dtree)), W2(e2), n2 && M3(e2);
148783
148847
  }, r._tr_tally = function(e2, t2, r2) {
148784
148848
  return e2.pending_buf[e2.d_buf + 2 * e2.last_lit] = t2 >>> 8 & 255, e2.pending_buf[e2.d_buf + 2 * e2.last_lit + 1] = 255 & t2, e2.pending_buf[e2.l_buf + e2.last_lit] = 255 & r2, e2.last_lit++, 0 === t2 ? e2.dyn_ltree[2 * r2]++ : (e2.matches++, t2--, e2.dyn_ltree[2 * (A5[r2] + u + 1)]++, e2.dyn_dtree[2 * N(t2)]++), e2.last_lit === e2.lit_bufsize - 1;
148785
148849
  }, r._tr_align = function(e2) {
@@ -149911,24 +149975,24 @@ var traverse = (node2) => {
149911
149975
  var findLocationOfText = (node2, text7) => traverse(node2).filter((p) => p.text.includes(text7));
149912
149976
  var formatter = new Formatter();
149913
149977
  var SPLIT_TOKEN = "\u0275";
149914
- var replacer = ({ json, patch, patchText, context, keepOriginalStyles = true }) => {
149915
- const renderedParagraphs = findLocationOfText(json, patchText);
149978
+ var replacer = ({ json: json2, patch, patchText, context, keepOriginalStyles = true }) => {
149979
+ const renderedParagraphs = findLocationOfText(json2, patchText);
149916
149980
  if (renderedParagraphs.length === 0) return {
149917
- element: json,
149981
+ element: json2,
149918
149982
  didFindOccurrence: false
149919
149983
  };
149920
149984
  for (const renderedParagraph of renderedParagraphs) {
149921
149985
  const textJson = patch.children.map((c2) => toJson((0, import_xml6.default)(formatter.format(c2, context)))).map((c2) => c2.elements[0]);
149922
149986
  switch (patch.type) {
149923
149987
  case PatchType.DOCUMENT: {
149924
- const parentElement = goToParentElementFromPath(json, renderedParagraph.pathToParagraph);
149988
+ const parentElement = goToParentElementFromPath(json2, renderedParagraph.pathToParagraph);
149925
149989
  const elementIndex = getLastElementIndexFromPath(renderedParagraph.pathToParagraph);
149926
149990
  parentElement.elements.splice(elementIndex, 1, ...textJson);
149927
149991
  break;
149928
149992
  }
149929
149993
  case PatchType.PARAGRAPH:
149930
149994
  default: {
149931
- const paragraphElement = goToElementFromPath(json, renderedParagraph.pathToParagraph);
149995
+ const paragraphElement = goToElementFromPath(json2, renderedParagraph.pathToParagraph);
149932
149996
  replaceTokenInParagraphElement({
149933
149997
  paragraphElement,
149934
149998
  renderedParagraph,
@@ -149954,19 +150018,19 @@ var replacer = ({ json, patch, patchText, context, keepOriginalStyles = true })
149954
150018
  }
149955
150019
  }
149956
150020
  return {
149957
- element: json,
150021
+ element: json2,
149958
150022
  didFindOccurrence: true
149959
150023
  };
149960
150024
  };
149961
- var goToElementFromPath = (json, path37) => {
149962
- let element = json;
150025
+ var goToElementFromPath = (json2, path37) => {
150026
+ let element = json2;
149963
150027
  for (let i2 = 1; i2 < path37.length; i2++) {
149964
150028
  const index4 = path37[i2];
149965
150029
  element = element.elements[index4];
149966
150030
  }
149967
150031
  return element;
149968
150032
  };
149969
- var goToParentElementFromPath = (json, path37) => goToElementFromPath(json, path37.slice(0, path37.length - 1));
150033
+ var goToParentElementFromPath = (json2, path37) => goToElementFromPath(json2, path37.slice(0, path37.length - 1));
149970
150034
  var getLastElementIndexFromPath = (path37) => path37[path37.length - 1];
149971
150035
  var PatchType = {
149972
150036
  /** Replace entire file-level elements (e.g., whole paragraphs) */
@@ -150006,10 +150070,10 @@ var patchDocument = (function() {
150006
150070
  binaryContentMap.set(key, binaryValue);
150007
150071
  continue;
150008
150072
  }
150009
- const json = toJson(yield value.async("text"));
150073
+ const json2 = toJson(yield value.async("text"));
150010
150074
  if (key === "word/document.xml") {
150011
150075
  var _json$elements;
150012
- const document4 = (_json$elements = json.elements) === null || _json$elements === void 0 ? void 0 : _json$elements.find((i2) => i2.name === "w:document");
150076
+ const document4 = (_json$elements = json2.elements) === null || _json$elements === void 0 ? void 0 : _json$elements.find((i2) => i2.name === "w:document");
150013
150077
  if (document4 && document4.attributes) {
150014
150078
  for (const ns of [
150015
150079
  "mc",
@@ -150042,7 +150106,7 @@ var patchDocument = (function() {
150042
150106
  const patchText = `${start}${patchKey}${end}`;
150043
150107
  while (true) {
150044
150108
  const { didFindOccurrence } = replacer({
150045
- json,
150109
+ json: json2,
150046
150110
  patch: _objectSpread2(_objectSpread2({}, patchValue), {}, { children: patchValue.children.map((element) => {
150047
150111
  if (element instanceof ExternalHyperlink) {
150048
150112
  const concreteHyperlink = new ConcreteHyperlink(element.options.children, uniqueId());
@@ -150063,7 +150127,7 @@ var patchDocument = (function() {
150063
150127
  if (!recursive || !didFindOccurrence) break;
150064
150128
  }
150065
150129
  }
150066
- const mediaDatas = imageReplacer.getMediaData(JSON.stringify(json), context.file.Media);
150130
+ const mediaDatas = imageReplacer.getMediaData(JSON.stringify(json2), context.file.Media);
150067
150131
  if (mediaDatas.length > 0) {
150068
150132
  hasMedia = true;
150069
150133
  imageRelationshipAdditions.push({
@@ -150072,7 +150136,7 @@ var patchDocument = (function() {
150072
150136
  });
150073
150137
  }
150074
150138
  }
150075
- map3.set(key, json);
150139
+ map3.set(key, json2);
150076
150140
  }
150077
150141
  for (const { key, mediaDatas } of imageRelationshipAdditions) {
150078
150142
  var _map$get;
@@ -177885,12 +177949,12 @@ var Revisions = class {
177885
177949
  }
177886
177950
  }
177887
177951
  /** Rebuild an element from its open tag, its children as `each` maps them, and its close tag. */
177888
- markInner(element, kind, each) {
177952
+ markInner(element, kind, each2) {
177889
177953
  const openEnd = element.xml.indexOf(">") + 1;
177890
177954
  if (element.xml[openEnd - 2] === "/") return element.xml;
177891
177955
  const closeStart = element.xml.lastIndexOf("</");
177892
177956
  const children = childElements(element.xml, openEnd, closeStart);
177893
- return element.xml.slice(0, openEnd) + children.map(each).join("") + element.xml.slice(closeStart);
177957
+ return element.xml.slice(0, openEnd) + children.map(each2).join("") + element.xml.slice(closeStart);
177894
177958
  }
177895
177959
  markRow(row, kind) {
177896
177960
  const openEnd = row.xml.indexOf(">") + 1;
@@ -185627,6 +185691,7 @@ var EmbeddedRuntime = class {
185627
185691
  });
185628
185692
  }
185629
185693
  for (const extensionPath of this.session.extensionRunner.getExtensionPaths()) {
185694
+ if (/^<inline:[^>]+>$/.test(extensionPath)) continue;
185630
185695
  const name = extensionPath.split(/[\\/]/).filter(Boolean).at(-1)?.replace(/\.[^.]+$/, "") ?? extensionPath;
185631
185696
  resources2.push({ id: `extension:${extensionPath}`, kind: "extension", name, origin: "runtime", path: extensionPath });
185632
185697
  }
@@ -186288,18 +186353,18 @@ async function resolveToolsExtension() {
186288
186353
  }
186289
186354
  function rpcResourceArgs(config2, context) {
186290
186355
  const args = [];
186291
- const each = (flag, values) => {
186356
+ const each2 = (flag, values) => {
186292
186357
  for (const value of values) args.push(flag, value);
186293
186358
  };
186294
186359
  if (config2.noExtensions) args.push("--no-extensions");
186295
- each("--extension", [...allExtensionPaths(config2), ...config2.extensionScripts]);
186360
+ each2("--extension", [...allExtensionPaths(config2), ...config2.extensionScripts]);
186296
186361
  if (config2.noSkills) args.push("--no-skills");
186297
- each("--skill", [...allSkillPaths(config2), ...context.bundledSkills]);
186362
+ each2("--skill", [...allSkillPaths(config2), ...context.bundledSkills]);
186298
186363
  if (config2.noPromptTemplates) args.push("--no-prompt-templates");
186299
- each("--prompt-template", config2.promptPaths);
186364
+ each2("--prompt-template", config2.promptPaths);
186300
186365
  if (config2.tools !== void 0) args.push("--tools", config2.tools.join(","));
186301
186366
  if (config2.systemPrompt !== void 0) args.push("--system-prompt", config2.systemPrompt);
186302
- each("--append-system-prompt", context.appendSystemPrompt);
186367
+ each2("--append-system-prompt", context.appendSystemPrompt);
186303
186368
  if (config2.offline) args.push("--offline");
186304
186369
  return args;
186305
186370
  }
@@ -187246,7 +187311,7 @@ function rulePatterns(profile, rules, sources) {
187246
187311
  nodes.push({ id: `${container}-item`, label: parts.join(" \xB7 "), kind: rule.then === "forbidden" ? PATTERN_KINDS.forbiddenItem : PATTERN_KINDS.selectedItem, container });
187247
187312
  return;
187248
187313
  }
187249
- const declaration = (profile.relationshipKinds ?? []).find((each) => each.kind === rule.relationship);
187314
+ const declaration = (profile.relationshipKinds ?? []).find((each2) => each2.kind === rule.relationship);
187250
187315
  const then = rule.then === "forbidden" ? void 0 : rule.then;
187251
187316
  for (const side of ["from", "to"]) {
187252
187317
  const when = rule.when?.[side];
@@ -189431,8 +189496,8 @@ function inspectShape(root2) {
189431
189496
  }
189432
189497
  function serializedBytes(value) {
189433
189498
  try {
189434
- const json = JSON.stringify(value);
189435
- return json === void 0 ? null : Buffer.byteLength(json);
189499
+ const json2 = JSON.stringify(value);
189500
+ return json2 === void 0 ? null : Buffer.byteLength(json2);
189436
189501
  } catch {
189437
189502
  return null;
189438
189503
  }
@@ -192215,8 +192280,12 @@ function finalizeTruncatedResult(prefix, prefixWidth, ellipsis, ellipsisWidth, m
192215
192280
  return pad3 ? result + " ".repeat(Math.max(0, maxWidth - visibleWidth2)) : result;
192216
192281
  }
192217
192282
  function graphemeWidth(segment4) {
192218
- if (segment4 === " ") {
192219
- return 3;
192283
+ if (segment4.length === 1) {
192284
+ const code3 = segment4.charCodeAt(0);
192285
+ if (code3 >= 32 && code3 <= 126)
192286
+ return 1;
192287
+ if (code3 === 9)
192288
+ return 3;
192220
192289
  }
192221
192290
  if (terminalSpacingMarkRegex.test(segment4)) {
192222
192291
  return [...segment4].length;
@@ -192260,8 +192329,9 @@ function visibleWidth(str2) {
192260
192329
  if (str2.length === 0) {
192261
192330
  return 0;
192262
192331
  }
192263
- if (isPrintableAscii(str2)) {
192264
- return str2.length;
192332
+ const asciiWidth = asciiVisibleWidth(str2);
192333
+ if (asciiWidth !== -1) {
192334
+ return asciiWidth;
192265
192335
  }
192266
192336
  const cached2 = widthCache.get(str2);
192267
192337
  if (cached2 !== void 0) {
@@ -192271,19 +192341,22 @@ function visibleWidth(str2) {
192271
192341
  if (str2.includes(" ")) {
192272
192342
  clean2 = clean2.replace(/\t/g, " ");
192273
192343
  }
192274
- if (clean2.includes("\x1B")) {
192344
+ let escapeIndex = clean2.indexOf("\x1B");
192345
+ if (escapeIndex !== -1) {
192275
192346
  let stripped = "";
192276
- let i2 = 0;
192277
- while (i2 < clean2.length) {
192278
- const ansi = extractAnsiCode(clean2, i2);
192279
- if (ansi) {
192280
- i2 += ansi.length;
192281
- continue;
192347
+ let copyFrom = 0;
192348
+ while (escapeIndex !== -1) {
192349
+ const length = ansiCodeLength(clean2, escapeIndex);
192350
+ if (length > 0) {
192351
+ stripped += clean2.slice(copyFrom, escapeIndex);
192352
+ escapeIndex += length;
192353
+ copyFrom = escapeIndex;
192354
+ } else {
192355
+ escapeIndex++;
192282
192356
  }
192283
- stripped += clean2[i2];
192284
- i2++;
192357
+ escapeIndex = clean2.indexOf("\x1B", escapeIndex);
192285
192358
  }
192286
- clean2 = stripped;
192359
+ clean2 = stripped + clean2.slice(copyFrom);
192287
192360
  }
192288
192361
  let width = 0;
192289
192362
  for (const { segment: segment4 } of graphemeSegmenter.segment(clean2)) {
@@ -192387,40 +192460,54 @@ function normalizeTerminalOutput(str2) {
192387
192460
  return result;
192388
192461
  }
192389
192462
  function extractAnsiCode(str2, pos) {
192390
- if (pos >= str2.length || str2[pos] !== "\x1B")
192391
- return null;
192463
+ const length = ansiCodeLength(str2, pos);
192464
+ return length > 0 ? { code: str2.substring(pos, pos + length), length } : null;
192465
+ }
192466
+ function asciiVisibleWidth(str2) {
192467
+ let width = 0;
192468
+ let i2 = 0;
192469
+ while (i2 < str2.length) {
192470
+ const code3 = str2.charCodeAt(i2);
192471
+ if (code3 >= 32 && code3 <= 126) {
192472
+ width++;
192473
+ i2++;
192474
+ } else if (code3 === 9) {
192475
+ width += 3;
192476
+ i2++;
192477
+ } else if (code3 === 27) {
192478
+ const length = ansiCodeLength(str2, i2);
192479
+ if (length === 0)
192480
+ return -1;
192481
+ i2 += length;
192482
+ } else {
192483
+ return -1;
192484
+ }
192485
+ }
192486
+ return width;
192487
+ }
192488
+ function ansiCodeLength(str2, pos) {
192489
+ if (pos >= str2.length || str2.charCodeAt(pos) !== 27)
192490
+ return 0;
192392
192491
  const next = str2[pos + 1];
192393
192492
  if (next === "[") {
192394
- let j2 = pos + 2;
192395
- while (j2 < str2.length && !/[mGKHJ]/.test(str2[j2]))
192396
- j2++;
192397
- if (j2 < str2.length)
192398
- return { code: str2.substring(pos, j2 + 1), length: j2 + 1 - pos };
192399
- return null;
192400
- }
192401
- if (next === "]") {
192402
- let j2 = pos + 2;
192403
- while (j2 < str2.length) {
192404
- if (str2[j2] === "\x07")
192405
- return { code: str2.substring(pos, j2 + 1), length: j2 + 1 - pos };
192406
- if (str2[j2] === "\x1B" && str2[j2 + 1] === "\\")
192407
- return { code: str2.substring(pos, j2 + 2), length: j2 + 2 - pos };
192408
- j2++;
192493
+ for (let j2 = pos + 2; j2 < str2.length; j2++) {
192494
+ const c2 = str2.charCodeAt(j2);
192495
+ if (c2 === 109 || c2 === 71 || c2 === 75 || c2 === 72 || c2 === 74)
192496
+ return j2 + 1 - pos;
192409
192497
  }
192410
- return null;
192498
+ return 0;
192411
192499
  }
192412
- if (next === "_") {
192413
- let j2 = pos + 2;
192414
- while (j2 < str2.length) {
192415
- if (str2[j2] === "\x07")
192416
- return { code: str2.substring(pos, j2 + 1), length: j2 + 1 - pos };
192417
- if (str2[j2] === "\x1B" && str2[j2 + 1] === "\\")
192418
- return { code: str2.substring(pos, j2 + 2), length: j2 + 2 - pos };
192419
- j2++;
192500
+ if (next === "]" || next === "_") {
192501
+ for (let j2 = pos + 2; j2 < str2.length; j2++) {
192502
+ const c2 = str2.charCodeAt(j2);
192503
+ if (c2 === 7)
192504
+ return j2 + 1 - pos;
192505
+ if (c2 === 27 && str2[j2 + 1] === "\\")
192506
+ return j2 + 2 - pos;
192420
192507
  }
192421
- return null;
192508
+ return 0;
192422
192509
  }
192423
- return null;
192510
+ return 0;
192424
192511
  }
192425
192512
  function parseOsc8Hyperlink(ansiCode) {
192426
192513
  if (!ansiCode.startsWith("\x1B]8;")) {
@@ -192664,15 +192751,16 @@ var AnsiCodeTracker = class {
192664
192751
  }
192665
192752
  };
192666
192753
  function updateTrackerFromText(text7, tracker) {
192667
- let i2 = 0;
192668
- while (i2 < text7.length) {
192669
- const ansiResult = extractAnsiCode(text7, i2);
192670
- if (ansiResult) {
192671
- tracker.process(ansiResult.code);
192672
- i2 += ansiResult.length;
192754
+ let i2 = text7.indexOf("\x1B");
192755
+ while (i2 !== -1) {
192756
+ const length = ansiCodeLength(text7, i2);
192757
+ if (length > 0) {
192758
+ tracker.process(text7.substring(i2, i2 + length));
192759
+ i2 += length;
192673
192760
  } else {
192674
192761
  i2++;
192675
192762
  }
192763
+ i2 = text7.indexOf("\x1B", i2);
192676
192764
  }
192677
192765
  }
192678
192766
  function getActiveBackgroundAnsi(text7) {
@@ -192904,6 +192992,402 @@ function extractSegments(line, beforeEnd, afterStart, afterLen, strictAfter = fa
192904
192992
  // ../node_modules/@earendil-works/pi-coding-agent/node_modules/@earendil-works/pi-tui/dist/autocomplete.js
192905
192993
  var tokenStartRegex = new RegExp(`${autocompleteBoundaryRegex.source}$`, "u");
192906
192994
 
192995
+ // ../node_modules/@earendil-works/pi-coding-agent/node_modules/@earendil-works/pi-tui/dist/oklab.js
192996
+ var multiply = (m2, [x2, y2, z3]) => m2.map((row) => row[0] * x2 + row[1] * y2 + row[2] * z3);
192997
+ var LINEAR_SRGB_TO_LMS = [
192998
+ [0.4122214694707629, 0.5363325372617349, 0.0514459932675022],
192999
+ [0.2119034958178251, 0.6806995506452344, 0.1073969535369405],
193000
+ [0.0883024591900564, 0.2817188391361215, 0.6299787016738222]
193001
+ ];
193002
+ var LMS_TO_LAB = [
193003
+ [0.210454268309314, 0.793617774702305, -0.0040720430116193],
193004
+ [1.9779985324311684, -2.42859224204858, 0.450593709617411],
193005
+ [0.0259040424655478, 0.7827717124575296, -0.8086757549230774]
193006
+ ];
193007
+ var LAB_TO_LMS = [
193008
+ [1, 0.3963377773761749, 0.2158037573099136],
193009
+ [1, -0.1055613458156586, -0.0638541728258133],
193010
+ [1, -0.0894841775298119, -1.2914855480194092]
193011
+ ];
193012
+ var LMS_TO_LINEAR_SRGB = [
193013
+ [4.076741636075958, -3.307711539258063, 0.2309699031821043],
193014
+ [-1.2684379732850315, 2.609757349287688, -0.341319376002657],
193015
+ [-0.0041960761386756, -0.7034186179359362, 1.7076146940746117]
193016
+ ];
193017
+ var SATURATION_FIT = [
193018
+ [
193019
+ [-1.8817031, -0.80936501],
193020
+ [1.19086277, 1.76576728, 0.59662641, 0.75515197, 0.56771245]
193021
+ ],
193022
+ [
193023
+ [1.8144408, -1.19445267],
193024
+ [0.73956515, -0.45954404, 0.08285427, 0.12541073, -0.14503204]
193025
+ ],
193026
+ [
193027
+ [0.13110758, 1.81333971],
193028
+ [1.35733652, -915799e-8, -1.1513021, -0.50559606, 692167e-8]
193029
+ ]
193030
+ ];
193031
+ var K1 = 0.206;
193032
+ var K22 = 0.03;
193033
+ var K3 = (1 + K1) / (1 + K22);
193034
+ var oklabToOkhslLightness = (x2) => 0.5 * (K3 * x2 - K1 + Math.sqrt((K3 * x2 - K1) ** 2 + 4 * K22 * K3 * x2));
193035
+ var okhslToOklabLightness = (x2) => (x2 * x2 + K1 * x2) / (K3 * (x2 + K22));
193036
+ var linearToSrgb = (value) => value > 31308e-7 ? 1.055 * value ** (1 / 2.4) - 0.055 : 12.92 * value;
193037
+ var srgbToLinear = (value) => value <= 0.04045 ? value / 12.92 : ((value + 0.055) / 1.055) ** 2.4;
193038
+ function oklabToLinearSrgb(lab) {
193039
+ return multiply(LMS_TO_LINEAR_SRGB, multiply(LAB_TO_LMS, lab).map((value) => value ** 3));
193040
+ }
193041
+ function linearSrgbToOklab(rgb) {
193042
+ return multiply(LMS_TO_LAB, multiply(LINEAR_SRGB_TO_LMS, rgb).map(Math.cbrt));
193043
+ }
193044
+ function rgbToOklab({ r, g, b: b2 }) {
193045
+ return linearSrgbToOklab([r / 255, g / 255, b2 / 255].map(srgbToLinear));
193046
+ }
193047
+ function linearSrgbToRgb(linear) {
193048
+ const [r, g, b2] = linear.map((value) => Math.round(Math.min(1, Math.max(0, linearToSrgb(value))) * 255));
193049
+ return { r, g, b: b2 };
193050
+ }
193051
+ function lmsSlopes(a, b2) {
193052
+ return [LAB_TO_LMS[0], LAB_TO_LMS[1], LAB_TO_LMS[2]].map((row) => row[1] * a + row[2] * b2);
193053
+ }
193054
+ function maxSaturation(a, b2) {
193055
+ const channel = SATURATION_FIT.findIndex(([[x2, y2]], index4) => index4 === 2 || x2 * a + y2 * b2 > 1);
193056
+ const [k0, k1, k2, k3, k4] = SATURATION_FIT[channel][1];
193057
+ const weights = LMS_TO_LINEAR_SRGB[channel];
193058
+ const saturation = k0 + k1 * a + k2 * b2 + k3 * a * a + k4 * a * b2;
193059
+ const slopes = lmsSlopes(a, b2);
193060
+ const base = slopes.map((k5) => 1 + saturation * k5);
193061
+ const dot = (values) => values.reduce((sum, value, index4) => sum + weights[index4] * value, 0);
193062
+ const f2 = dot(base.map((value) => value ** 3));
193063
+ const f1 = dot(base.map((value, index4) => 3 * slopes[index4] * value ** 2));
193064
+ const f22 = dot(base.map((value, index4) => 6 * slopes[index4] ** 2 * value));
193065
+ return saturation - f2 * f1 / (f1 * f1 - 0.5 * f2 * f22);
193066
+ }
193067
+ function cusp(a, b2) {
193068
+ const saturation = maxSaturation(a, b2);
193069
+ const lightness = Math.cbrt(1 / Math.max(...oklabToLinearSrgb([1, saturation * a, saturation * b2])));
193070
+ return [lightness, lightness * saturation];
193071
+ }
193072
+ function maxChroma(a, b2, lightness, [cuspL, cuspC]) {
193073
+ if (lightness <= cuspL)
193074
+ return cuspC * lightness / cuspL;
193075
+ const t = cuspC * (lightness - 1) / (cuspL - 1);
193076
+ const slopes = lmsSlopes(a, b2);
193077
+ const lms = slopes.map((k2) => lightness + t * k2);
193078
+ const cubes = lms.map((value) => value ** 3);
193079
+ const first = lms.map((value, index4) => 3 * slopes[index4] * value ** 2);
193080
+ const second = lms.map((value, index4) => 6 * slopes[index4] ** 2 * value);
193081
+ const dot = (row, values) => row[0] * values[0] + row[1] * values[1] + row[2] * values[2];
193082
+ const steps = LMS_TO_LINEAR_SRGB.map((row) => {
193083
+ const f2 = dot(row, cubes) - 1;
193084
+ const f1 = dot(row, first);
193085
+ const f22 = dot(row, second);
193086
+ const u = f1 / (f1 * f1 - 0.5 * f2 * f22);
193087
+ return u >= 0 ? -f2 * u : Number.MAX_VALUE;
193088
+ });
193089
+ return t + Math.min(...steps);
193090
+ }
193091
+ function chromaStops(L2, a, b2) {
193092
+ const peak = cusp(a, b2);
193093
+ const cMax = maxChroma(a, b2, L2, peak);
193094
+ const k2 = cMax / Math.min(L2 * (peak[1] / peak[0]), (1 - L2) * (peak[1] / (1 - peak[0])));
193095
+ const midS = 0.11516993 + 1 / (7.4477897 + 4.1590124 * b2 + a * (-2.19557347 + 1.75198401 * b2 + a * (-2.13704948 - 10.02301043 * b2 + a * (-4.24894561 + 5.38770819 * b2 + 4.69891013 * a))));
193096
+ const midT = 0.11239642 + 1 / (1.6132032 - 0.68124379 * b2 + a * (0.40370612 + 0.90148123 * b2 + a * (-0.27087943 + 0.6122399 * b2 + a * (299215e-8 - 0.45399568 * b2 - 0.14661872 * a))));
193097
+ const cMid = 0.9 * k2 * Math.sqrt(Math.sqrt(1 / (1 / (L2 * midS) ** 4 + 1 / ((1 - L2) * midT) ** 4)));
193098
+ const c0 = Math.sqrt(1 / (1 / (L2 * 0.4) ** 2 + 1 / ((1 - L2) * 0.8) ** 2));
193099
+ return [c0, cMid, cMax];
193100
+ }
193101
+ function okhslToRgb(hue, saturation, lightness) {
193102
+ const L2 = okhslToOklabLightness(lightness);
193103
+ let lab = [L2, 0, 0];
193104
+ if (L2 > 0 && L2 < 1 && saturation > 0) {
193105
+ const angle = 2 * Math.PI * ((hue % 360 + 360) % 360) / 360;
193106
+ const a = Math.cos(angle);
193107
+ const b2 = Math.sin(angle);
193108
+ const [c0, cMid, cMax] = chromaStops(L2, a, b2);
193109
+ let chroma;
193110
+ if (saturation < 0.8) {
193111
+ const t = 1.25 * saturation;
193112
+ const k1 = 0.8 * c0;
193113
+ chroma = t * k1 / (1 - (1 - k1 / cMid) * t);
193114
+ } else {
193115
+ const t = 5 * (saturation - 0.8);
193116
+ const k1 = 0.2 * cMid ** 2 * 1.25 ** 2 / c0;
193117
+ chroma = cMid + t * k1 / (1 - (1 - k1 / (cMax - cMid)) * t);
193118
+ }
193119
+ lab = [L2, chroma * a, chroma * b2];
193120
+ }
193121
+ return linearSrgbToRgb(oklabToLinearSrgb(lab));
193122
+ }
193123
+ function rgbToOkhsl(rgb) {
193124
+ const [L2, labA, labB] = rgbToOklab(rgb);
193125
+ const chroma = Math.hypot(labA, labB);
193126
+ const lightness = oklabToOkhslLightness(L2);
193127
+ if (chroma < 1e-9 || lightness <= 0 || lightness >= 1)
193128
+ return { h: 0, s: 0, l: lightness };
193129
+ const hue = (Math.atan2(labB, labA) * 180 / Math.PI + 360) % 360;
193130
+ const [c0, cMid, cMax] = chromaStops(L2, labA / chroma, labB / chroma);
193131
+ let saturation;
193132
+ if (chroma < cMid) {
193133
+ const k1 = 0.8 * c0;
193134
+ saturation = 0.8 * (chroma / (k1 + (1 - k1 / cMid) * chroma));
193135
+ } else {
193136
+ const k1 = 0.2 * cMid ** 2 * 1.25 ** 2 / c0;
193137
+ const offset = chroma - cMid;
193138
+ saturation = 0.8 + 0.2 * (offset / (k1 + (1 - k1 / (cMax - cMid)) * offset));
193139
+ }
193140
+ return { h: hue, s: Math.min(1, Math.max(0, saturation)), l: lightness };
193141
+ }
193142
+
193143
+ // ../node_modules/@earendil-works/pi-coding-agent/node_modules/@earendil-works/pi-tui/dist/colors.js
193144
+ function requireFinite(value, name) {
193145
+ if (!Number.isFinite(value))
193146
+ throw new Error(`${name} must be finite`);
193147
+ }
193148
+ function indexedColor(index4) {
193149
+ if (!Number.isInteger(index4) || index4 < 0 || index4 > 255) {
193150
+ throw new Error(`ANSI color index must be an integer from 0 to 255: ${index4}`);
193151
+ }
193152
+ return Object.freeze({ kind: "indexed", index: index4 });
193153
+ }
193154
+ function rgbColor(r, g, b2) {
193155
+ for (const [name, value] of [
193156
+ ["r", r],
193157
+ ["g", g],
193158
+ ["b", b2]
193159
+ ]) {
193160
+ requireFinite(value, name);
193161
+ if (value < 0 || value > 255)
193162
+ throw new Error(`${name} must be between 0 and 255: ${value}`);
193163
+ }
193164
+ return Object.freeze({ kind: "rgb", r, g, b: b2 });
193165
+ }
193166
+ function oklchColor(l3, c2, h) {
193167
+ requireFinite(l3, "l");
193168
+ requireFinite(c2, "c");
193169
+ requireFinite(h, "h");
193170
+ if (l3 < 0 || l3 > 1)
193171
+ throw new Error(`l must be between 0 and 1: ${l3}`);
193172
+ if (c2 < 0)
193173
+ throw new Error(`c must not be negative: ${c2}`);
193174
+ return Object.freeze({ kind: "oklch", l: l3, c: c2, h: (h % 360 + 360) % 360 });
193175
+ }
193176
+ var NUMBER_PATTERN = String.raw`[+-]?(?:\d+(?:\.\d*)?|\.\d+)(?:e[+-]?\d+)?`;
193177
+ var OKLCH_PATTERN = new RegExp(`^oklch\\(\\s*(${NUMBER_PATTERN})(%)?\\s+(${NUMBER_PATTERN})\\s+(${NUMBER_PATTERN})(?:deg)?\\s*\\)$`, "i");
193178
+ var OKHSL_PATTERN = new RegExp(`^okhsl\\(\\s*(${NUMBER_PATTERN})(?:deg)?\\s+(${NUMBER_PATTERN})(%)?\\s+(${NUMBER_PATTERN})(%)?\\s*\\)$`, "i");
193179
+ function okhslColor(h, s, l3) {
193180
+ requireFinite(h, "h");
193181
+ requireFinite(s, "s");
193182
+ requireFinite(l3, "l");
193183
+ if (s < 0 || s > 1)
193184
+ throw new Error(`s must be between 0 and 1: ${s}`);
193185
+ if (l3 < 0 || l3 > 1)
193186
+ throw new Error(`l must be between 0 and 1: ${l3}`);
193187
+ const { r, g, b: b2 } = okhslToRgb(h, s, l3);
193188
+ return rgbColor(r, g, b2);
193189
+ }
193190
+ function colorToOkhsl(color3) {
193191
+ return rgbToOkhsl(colorToRgb(color3));
193192
+ }
193193
+ function parseColor(value) {
193194
+ if (typeof value === "number")
193195
+ return indexedColor(value);
193196
+ const hex = /^#([\da-f]{3}|[\da-f]{6})$/i.exec(value);
193197
+ if (hex) {
193198
+ const digits = hex[1].length === 3 ? [...hex[1]].map((digit) => digit + digit).join("") : hex[1];
193199
+ return rgbColor(Number.parseInt(digits.slice(0, 2), 16), Number.parseInt(digits.slice(2, 4), 16), Number.parseInt(digits.slice(4, 6), 16));
193200
+ }
193201
+ const oklch = OKLCH_PATTERN.exec(value);
193202
+ if (oklch) {
193203
+ const lightness = Number.parseFloat(oklch[1]) / (oklch[2] ? 100 : 1);
193204
+ return oklchColor(lightness, Number.parseFloat(oklch[3]), Number.parseFloat(oklch[4]));
193205
+ }
193206
+ const okhsl = OKHSL_PATTERN.exec(value);
193207
+ if (okhsl) {
193208
+ const saturation = Number.parseFloat(okhsl[2]) / (okhsl[3] ? 100 : 1);
193209
+ const lightness = Number.parseFloat(okhsl[4]) / (okhsl[5] ? 100 : 1);
193210
+ return okhslColor(Number.parseFloat(okhsl[1]), saturation, lightness);
193211
+ }
193212
+ throw new Error(`Invalid color value: ${value}`);
193213
+ }
193214
+ var BASIC_COLORS = [
193215
+ { r: 0, g: 0, b: 0 },
193216
+ { r: 128, g: 0, b: 0 },
193217
+ { r: 0, g: 128, b: 0 },
193218
+ { r: 128, g: 128, b: 0 },
193219
+ { r: 0, g: 0, b: 128 },
193220
+ { r: 128, g: 0, b: 128 },
193221
+ { r: 0, g: 128, b: 128 },
193222
+ { r: 192, g: 192, b: 192 },
193223
+ { r: 128, g: 128, b: 128 },
193224
+ { r: 255, g: 0, b: 0 },
193225
+ { r: 0, g: 255, b: 0 },
193226
+ { r: 255, g: 255, b: 0 },
193227
+ { r: 0, g: 0, b: 255 },
193228
+ { r: 255, g: 0, b: 255 },
193229
+ { r: 0, g: 255, b: 255 },
193230
+ { r: 255, g: 255, b: 255 }
193231
+ ];
193232
+ var CUBE_VALUES = [0, 95, 135, 175, 215, 255];
193233
+ var GRAY_VALUES = Array.from({ length: 24 }, (_2, index4) => 8 + index4 * 10);
193234
+ function indexedToRgb(index4) {
193235
+ if (index4 < 16)
193236
+ return { ...BASIC_COLORS[index4] };
193237
+ if (index4 < 232) {
193238
+ const cubeIndex = index4 - 16;
193239
+ return {
193240
+ r: CUBE_VALUES[Math.floor(cubeIndex / 36)],
193241
+ g: CUBE_VALUES[Math.floor(cubeIndex % 36 / 6)],
193242
+ b: CUBE_VALUES[cubeIndex % 6]
193243
+ };
193244
+ }
193245
+ const gray = 8 + (index4 - 232) * 10;
193246
+ return { r: gray, g: gray, b: gray };
193247
+ }
193248
+ function isInSrgbGamut(linear) {
193249
+ const epsilon = 1e-7;
193250
+ return linear.every((channel) => channel >= -epsilon && channel <= 1 + epsilon);
193251
+ }
193252
+ function oklchToRgb({ l: l3, c: c2, h }) {
193253
+ const radians = h * Math.PI / 180;
193254
+ const cos = Math.cos(radians);
193255
+ const sin = Math.sin(radians);
193256
+ const atChroma = (chroma) => oklabToLinearSrgb([l3, chroma * cos, chroma * sin]);
193257
+ const direct = atChroma(c2);
193258
+ if (isInSrgbGamut(direct))
193259
+ return linearSrgbToRgb(direct);
193260
+ let linear = atChroma(0);
193261
+ let low = 0;
193262
+ let high = c2;
193263
+ for (let index4 = 0; index4 < 20; index4++) {
193264
+ const chroma = (low + high) / 2;
193265
+ const candidate = atChroma(chroma);
193266
+ if (isInSrgbGamut(candidate)) {
193267
+ low = chroma;
193268
+ linear = candidate;
193269
+ } else {
193270
+ high = chroma;
193271
+ }
193272
+ }
193273
+ return linearSrgbToRgb(linear);
193274
+ }
193275
+ function colorToRgb(color3) {
193276
+ switch (color3.kind) {
193277
+ case "indexed":
193278
+ return indexedToRgb(color3.index);
193279
+ case "rgb":
193280
+ return { r: color3.r, g: color3.g, b: color3.b };
193281
+ case "oklch":
193282
+ return oklchToRgb(color3);
193283
+ }
193284
+ }
193285
+ function colorToOklch(color3) {
193286
+ if (color3.kind === "oklch")
193287
+ return { l: color3.l, c: color3.c, h: color3.h };
193288
+ const [l3, a, b2] = rgbToOklab(colorToRgb(color3));
193289
+ return { l: l3, c: Math.hypot(a, b2), h: (Math.atan2(b2, a) * 180 / Math.PI + 360) % 360 };
193290
+ }
193291
+ function mixColors(first, second, amount, space = "oklch") {
193292
+ requireFinite(amount, "amount");
193293
+ if (amount < 0 || amount > 1)
193294
+ throw new Error(`amount must be between 0 and 1: ${amount}`);
193295
+ if (space === "srgb") {
193296
+ const a2 = colorToRgb(first);
193297
+ const b3 = colorToRgb(second);
193298
+ return rgbColor(a2.r + (b3.r - a2.r) * amount, a2.g + (b3.g - a2.g) * amount, a2.b + (b3.b - a2.b) * amount);
193299
+ }
193300
+ const a = colorToOklch(first);
193301
+ const b2 = colorToOklch(second);
193302
+ const firstHue = a.c < 1e-7 ? b2.h : a.h;
193303
+ const secondHue = b2.c < 1e-7 ? firstHue : b2.h;
193304
+ const hueDelta = (secondHue - firstHue + 540) % 360 - 180;
193305
+ return oklchColor(a.l + (b2.l - a.l) * amount, a.c + (b2.c - a.c) * amount, firstHue + hueDelta * amount);
193306
+ }
193307
+ function findClosest(values, target) {
193308
+ let closestIndex = 0;
193309
+ let closestDistance = Infinity;
193310
+ for (let index4 = 0; index4 < values.length; index4++) {
193311
+ const distance = Math.abs(target - values[index4]);
193312
+ if (distance < closestDistance) {
193313
+ closestIndex = index4;
193314
+ closestDistance = distance;
193315
+ }
193316
+ }
193317
+ return closestIndex;
193318
+ }
193319
+ function colorDistance(first, second) {
193320
+ const dr2 = first.r - second.r;
193321
+ const dg = first.g - second.g;
193322
+ const db = first.b - second.b;
193323
+ return dr2 * dr2 * 0.299 + dg * dg * 0.587 + db * db * 0.114;
193324
+ }
193325
+ function rgbToAnsi256(color3) {
193326
+ const rIndex = findClosest(CUBE_VALUES, color3.r);
193327
+ const gIndex = findClosest(CUBE_VALUES, color3.g);
193328
+ const bIndex = findClosest(CUBE_VALUES, color3.b);
193329
+ const cubeColor = { r: CUBE_VALUES[rIndex], g: CUBE_VALUES[gIndex], b: CUBE_VALUES[bIndex] };
193330
+ const cubeIndex = 16 + 36 * rIndex + 6 * gIndex + bIndex;
193331
+ const gray = Math.round(0.299 * color3.r + 0.587 * color3.g + 0.114 * color3.b);
193332
+ const grayOffset = findClosest(GRAY_VALUES, gray);
193333
+ const grayValue = GRAY_VALUES[grayOffset];
193334
+ const spread = Math.max(color3.r, color3.g, color3.b) - Math.min(color3.r, color3.g, color3.b);
193335
+ if (spread < 10 && colorDistance(color3, { r: grayValue, g: grayValue, b: grayValue }) < colorDistance(color3, cubeColor)) {
193336
+ return 232 + grayOffset;
193337
+ }
193338
+ return cubeIndex;
193339
+ }
193340
+ function colorAnsi(color3, mode, background) {
193341
+ if (color3.kind === "indexed")
193342
+ return `\x1B[${background ? 48 : 38};5;${color3.index}m`;
193343
+ const rgb = colorToRgb(color3);
193344
+ if (mode === "truecolor") {
193345
+ return `\x1B[${background ? 48 : 38};2;${Math.round(rgb.r)};${Math.round(rgb.g)};${Math.round(rgb.b)}m`;
193346
+ }
193347
+ return `\x1B[${background ? 48 : 38};5;${rgbToAnsi256(rgb)}m`;
193348
+ }
193349
+ function foregroundAnsi(color3, mode) {
193350
+ return colorAnsi(color3, mode, false);
193351
+ }
193352
+ function backgroundAnsi(color3, mode) {
193353
+ return colorAnsi(color3, mode, true);
193354
+ }
193355
+ function styleTextWithAnsi(text7, fgAnsi, bgAnsi, options) {
193356
+ let prefix = "";
193357
+ let suffix = "";
193358
+ if (fgAnsi) {
193359
+ prefix += fgAnsi;
193360
+ suffix = "\x1B[39m";
193361
+ }
193362
+ if (bgAnsi) {
193363
+ prefix += bgAnsi;
193364
+ suffix = `\x1B[49m${suffix}`;
193365
+ }
193366
+ if (options.bold)
193367
+ prefix += "\x1B[1m";
193368
+ if (options.dim)
193369
+ prefix += "\x1B[2m";
193370
+ if (options.bold || options.dim)
193371
+ suffix = `\x1B[22m${suffix}`;
193372
+ if (options.italic) {
193373
+ prefix += "\x1B[3m";
193374
+ suffix = `\x1B[23m${suffix}`;
193375
+ }
193376
+ if (options.underline) {
193377
+ prefix += "\x1B[4m";
193378
+ suffix = `\x1B[24m${suffix}`;
193379
+ }
193380
+ if (options.inverse) {
193381
+ prefix += "\x1B[7m";
193382
+ suffix = `\x1B[27m${suffix}`;
193383
+ }
193384
+ if (options.strikethrough) {
193385
+ prefix += "\x1B[9m";
193386
+ suffix = `\x1B[29m${suffix}`;
193387
+ }
193388
+ return `${prefix}${text7}${suffix}`;
193389
+ }
193390
+
192907
193391
  // ../node_modules/@earendil-works/pi-coding-agent/node_modules/@earendil-works/pi-tui/dist/tui.js
192908
193392
  import { performance as performance2 } from "node:perf_hooks";
192909
193393
 
@@ -193528,17 +194012,18 @@ function parseOscHexChannel(channel) {
193528
194012
  }
193529
194013
  return Math.round(parseInt(channel, 16) / max * 255);
193530
194014
  }
193531
- var OSC11_BACKGROUND_COLOR_RESPONSE_PATTERN = /^\x1b\]11;([^\x07\x1b]*)(?:\x07|\x1b\\)$/i;
194015
+ var OSC_COLOR_RESPONSE_PATTERN = /^\x1b\](?:(1[01])|4;(\d{1,3}));([^\x07\x1b]*)(?:\x07|\x1b\\)$/i;
193532
194016
  var COLOR_SCHEME_REPORT_PATTERN = /^(?:\x1b\[\?997;(1|2)n)+$/;
193533
- function isOsc11BackgroundColorResponse(data) {
193534
- return OSC11_BACKGROUND_COLOR_RESPONSE_PATTERN.test(data);
193535
- }
193536
- function parseOsc11BackgroundColor(data) {
193537
- const match = data.match(OSC11_BACKGROUND_COLOR_RESPONSE_PATTERN);
194017
+ function parseOscColorResponse(data) {
194018
+ const match = data.match(OSC_COLOR_RESPONSE_PATTERN);
193538
194019
  if (!match) {
193539
194020
  return void 0;
193540
194021
  }
193541
- const value = match[1].trim();
194022
+ const target = match[1] === "10" ? "foreground" : match[1] === "11" ? "background" : Number.parseInt(match[2], 10);
194023
+ return { target, rgb: parseOscColorValue(match[3]) };
194024
+ }
194025
+ function parseOscColorValue(rawValue) {
194026
+ const value = rawValue.trim();
193542
194027
  if (value.startsWith("#")) {
193543
194028
  const hex = value.slice(1);
193544
194029
  if (/^[0-9a-f]{6}$/i.test(hex)) {
@@ -193595,7 +194080,7 @@ function detectCapabilitiesFromEnvironment(tmuxForwardsHyperlink) {
193595
194080
  const terminalEmulator = process.env.TERMINAL_EMULATOR?.toLowerCase() || "";
193596
194081
  const term = process.env.TERM?.toLowerCase() || "";
193597
194082
  const colorTerm = process.env.COLORTERM?.toLowerCase() || "";
193598
- const hasTrueColorHint = colorTerm === "truecolor" || colorTerm === "24bit";
194083
+ const hasTrueColorHint = colorTerm === "truecolor" || colorTerm === "24bit" || term.endsWith("-direct");
193599
194084
  const isWindowsConsole = process.platform === "win32";
193600
194085
  if (process.env.TMUX || term.startsWith("tmux")) {
193601
194086
  return { images: null, trueColor: hasTrueColorHint, hyperlinks: tmuxForwardsHyperlink() };
@@ -193658,6 +194143,9 @@ function getCapabilities() {
193658
194143
  }
193659
194144
  return cachedCapabilities;
193660
194145
  }
194146
+ function getTerminalColorMode(capabilities = getCapabilities()) {
194147
+ return capabilities.trueColor ? "truecolor" : "256color";
194148
+ }
193661
194149
  function setCapabilities(caps) {
193662
194150
  cachedCapabilities = caps;
193663
194151
  }
@@ -193772,8 +194260,10 @@ function dispatchMouseEvent(component, event) {
193772
194260
  const result = component.handleMouse?.(event);
193773
194261
  if (!result)
193774
194262
  return void 0;
193775
- if ("target" in result)
193776
- return result;
194263
+ if ("target" in result) {
194264
+ const forwarded = result;
194265
+ return forwarded.focus && component.handleInput ? { ...forwarded, focusTarget: component } : forwarded;
194266
+ }
193777
194267
  if (!result.handled && !result.capture && !result.focus)
193778
194268
  return void 0;
193779
194269
  return {
@@ -193798,6 +194288,10 @@ function retargetMouseEvent(event, target) {
193798
194288
  height: target.height
193799
194289
  };
193800
194290
  }
194291
+ var TERMINAL_PALETTE_SIZE = 16;
194292
+ var TERMINAL_COLOR_REPLY_COUNT = 2 + TERMINAL_PALETTE_SIZE;
194293
+ var TERMINAL_COLOR_QUERY = `\x1B]10;?\x07\x1B]11;?\x07${Array.from({ length: TERMINAL_PALETTE_SIZE }, (_2, index4) => `\x1B]4;${index4};?\x07`).join("")}\x1B[c`;
194294
+ var DEVICE_ATTRIBUTES_RESPONSE_PATTERN = /^\x1b\[\?[\d;]*c$/;
193801
194295
  function isFocusable(component) {
193802
194296
  return component !== null && "focused" in component;
193803
194297
  }
@@ -193899,8 +194393,11 @@ var TuiBase = class _TuiBase extends Container {
193899
194393
  clearOnShrink = false;
193900
194394
  fullRedrawCount = 0;
193901
194395
  stopped = false;
193902
- pendingOsc11BackgroundReplies = 0;
193903
- pendingOsc11BackgroundQueries = [];
194396
+ /**
194397
+ * Color queries waiting for their DA1 reply, oldest first. Terminals answer in order, so color
194398
+ * replies belong to the oldest one. Queries stay here after a timeout to collect late replies.
194399
+ */
194400
+ pendingTerminalColorQueries = [];
193904
194401
  terminalColorSchemeListeners = /* @__PURE__ */ new Set();
193905
194402
  terminalColorSchemeNotificationsEnabled = false;
193906
194403
  /** Directory for debug/crash logs. When undefined, debug logging is disabled and crash dumps fall back to the OS temp directory. */
@@ -193942,7 +194439,7 @@ var TuiBase = class _TuiBase extends Container {
193942
194439
  return;
193943
194440
  this.showHardwareCursor = enabled;
193944
194441
  if (!enabled) {
193945
- this.terminal.hideCursor();
194442
+ this.hideTerminalCursor();
193946
194443
  }
193947
194444
  this.requestRender();
193948
194445
  }
@@ -194078,7 +194575,7 @@ var TuiBase = class _TuiBase extends Container {
194078
194575
  if (!options?.nonCapturing && this.isOverlayVisible(entry)) {
194079
194576
  this.setFocus(component);
194080
194577
  }
194081
- this.terminal.hideCursor();
194578
+ this.hideTerminalCursor();
194082
194579
  this.requestRender();
194083
194580
  return {
194084
194581
  hide: () => {
@@ -194092,7 +194589,7 @@ var TuiBase = class _TuiBase extends Container {
194092
194589
  this.setFocus(topVisible?.component ?? entry.preFocus);
194093
194590
  }
194094
194591
  if (this.overlayStack.length === 0)
194095
- this.terminal.hideCursor();
194592
+ this.hideTerminalCursor();
194096
194593
  this.requestRender();
194097
194594
  }
194098
194595
  },
@@ -194171,9 +194668,14 @@ var TuiBase = class _TuiBase extends Container {
194171
194668
  this.setFocus(topVisible?.component ?? overlay.preFocus);
194172
194669
  }
194173
194670
  if (this.overlayStack.length === 0)
194174
- this.terminal.hideCursor();
194671
+ this.hideTerminalCursor();
194175
194672
  this.requestRender();
194176
194673
  }
194674
+ /** Hide the cursor while running. After stop(), the shell owns the cursor and it must stay visible. */
194675
+ hideTerminalCursor() {
194676
+ if (!this.stopped)
194677
+ this.terminal.hideCursor();
194678
+ }
194177
194679
  /** Check if there are any visible overlays */
194178
194680
  hasOverlay() {
194179
194681
  return this.overlayStack.some((o) => this.isOverlayVisible(o));
@@ -194354,7 +194856,7 @@ var TuiBase = class _TuiBase extends Container {
194354
194856
  }, delay);
194355
194857
  }
194356
194858
  handleTerminalInput(data) {
194357
- if (this.consumeOsc11BackgroundResponse(data)) {
194859
+ if (this.consumeTerminalColorResponse(data)) {
194358
194860
  return;
194359
194861
  }
194360
194862
  if (this.consumeTerminalColorSchemeReport(data)) {
@@ -194414,27 +194916,48 @@ var TuiBase = class _TuiBase extends Container {
194414
194916
  this.requestImmediateRender();
194415
194917
  }
194416
194918
  }
194417
- consumeOsc11BackgroundResponse(data) {
194418
- if (this.pendingOsc11BackgroundReplies <= 0) {
194919
+ consumeTerminalColorResponse(data) {
194920
+ const query = this.pendingTerminalColorQueries[0];
194921
+ if (!query) {
194419
194922
  return false;
194420
194923
  }
194421
- if (!isOsc11BackgroundColorResponse(data)) {
194924
+ if (DEVICE_ATTRIBUTES_RESPONSE_PATTERN.test(data)) {
194925
+ this.pendingTerminalColorQueries.shift();
194926
+ this.completeTerminalColorQuery(query);
194927
+ return true;
194928
+ }
194929
+ const response = parseOscColorResponse(data);
194930
+ if (!response) {
194422
194931
  return false;
194423
194932
  }
194424
- const rgb = parseOsc11BackgroundColor(data);
194425
- this.pendingOsc11BackgroundReplies -= 1;
194426
- const query = this.pendingOsc11BackgroundQueries.shift();
194427
- if (query && !query.settled) {
194428
- query.settled = true;
194429
- if (query.timer) {
194430
- clearTimeout(query.timer);
194431
- query.timer = void 0;
194432
- }
194433
- query.resolve?.(rgb);
194434
- query.resolve = void 0;
194933
+ const { target, rgb } = response;
194934
+ const key = String(target);
194935
+ if (!query.deliver || query.replied.has(key)) {
194936
+ return true;
194937
+ }
194938
+ query.replied.add(key);
194939
+ if (target === "foreground") {
194940
+ query.foreground = rgb;
194941
+ } else if (target === "background") {
194942
+ query.background = rgb;
194943
+ } else if (target < TERMINAL_PALETTE_SIZE) {
194944
+ query.palette[target] = rgb;
194945
+ }
194946
+ if (query.replied.size === TERMINAL_COLOR_REPLY_COUNT) {
194947
+ this.completeTerminalColorQuery(query);
194435
194948
  }
194436
194949
  return true;
194437
194950
  }
194951
+ terminalColorQueryResult(query) {
194952
+ const palette = query.palette.every((color3) => color3 !== void 0) ? query.palette : void 0;
194953
+ return { foreground: query.foreground, background: query.background, palette };
194954
+ }
194955
+ completeTerminalColorQuery(query) {
194956
+ const deliver = query.deliver;
194957
+ query.deliver = void 0;
194958
+ clearTimeout(query.timer);
194959
+ deliver?.(this.terminalColorQueryResult(query));
194960
+ }
194438
194961
  consumeTerminalColorSchemeReport(data) {
194439
194962
  const scheme = parseTerminalColorSchemeReport(data);
194440
194963
  if (!scheme) {
@@ -194643,56 +195166,27 @@ var TuiBase = class _TuiBase extends Container {
194643
195166
  return null;
194644
195167
  }
194645
195168
  /**
194646
- * Query the terminal's default background color with OSC 11 (`ESC ] 11 ; ? BEL`).
194647
- * @param timeoutMs Query timeout in milliseconds.
194648
- * @returns Promise containing the parsed RGB color, or undefined if it times out or fails to parse.
195169
+ * Query the terminal's theme colors: the default foreground (OSC 10), the default background
195170
+ * (OSC 11), and ANSI colors 0-15 (OSC 4), followed by a DA1 request that marks the end of the
195171
+ * replies. Resolves when the DA1 reply or all color replies arrive, or when the timeout expires.
195172
+ * Colors the terminal did not report are undefined; the palette is only set when all 16 arrived.
195173
+ * @param timeoutMs Query timeout in milliseconds, for terminals that do not answer DA1 either.
195174
+ * @param onLateReply Receives the replies if the query completes after the timeout, e.g. over slow links.
194649
195175
  */
194650
- queryTerminalBackgroundColor({ timeoutMs }) {
195176
+ queryTerminalColors({ timeoutMs, onLateReply }) {
194651
195177
  return new Promise((resolve2) => {
194652
195178
  const query = {
194653
- settled: false,
194654
- resolve: resolve2,
195179
+ palette: Array.from({ length: TERMINAL_PALETTE_SIZE }, () => void 0),
195180
+ replied: /* @__PURE__ */ new Set(),
195181
+ deliver: resolve2,
194655
195182
  timer: void 0
194656
195183
  };
194657
195184
  query.timer = setTimeout(() => {
194658
- if (query.settled) {
194659
- return;
194660
- }
194661
- query.settled = true;
194662
- query.timer = void 0;
194663
- query.resolve?.(void 0);
194664
- query.resolve = void 0;
195185
+ query.deliver = onLateReply;
195186
+ resolve2(this.terminalColorQueryResult(query));
194665
195187
  }, timeoutMs);
194666
- this.pendingOsc11BackgroundQueries.push(query);
194667
- this.pendingOsc11BackgroundReplies += 1;
194668
- this.terminal.write("\x1B]11;?\x07");
194669
- });
194670
- }
194671
- /**
194672
- * Query the terminal's color-scheme preference with DSR (`CSI ? 996 n`).
194673
- * Terminals that support the color palette notification protocol reply with
194674
- * `CSI ? 997 ; 1 n` for dark or `CSI ? 997 ; 2 n` for light.
194675
- */
194676
- queryTerminalColorScheme({ timeoutMs }) {
194677
- return new Promise((resolve2) => {
194678
- let settled = false;
194679
- let timer;
194680
- let unsubscribe = () => {
194681
- };
194682
- const settle = (scheme) => {
194683
- if (settled)
194684
- return;
194685
- settled = true;
194686
- if (timer) {
194687
- clearTimeout(timer);
194688
- timer = void 0;
194689
- }
194690
- unsubscribe();
194691
- resolve2(scheme);
194692
- };
194693
- unsubscribe = this.onTerminalColorSchemeChange(settle);
194694
- timer = setTimeout(() => settle(void 0), timeoutMs);
194695
- this.terminal.write("\x1B[?996n");
195188
+ this.pendingTerminalColorQueries.push(query);
195189
+ this.terminal.write(TERMINAL_COLOR_QUERY);
194696
195190
  });
194697
195191
  }
194698
195192
  };
@@ -195051,6 +195545,7 @@ function findWordForward(text7, cursor, options) {
195051
195545
  var graphemeSegmenter2 = getGraphemeSegmenter();
195052
195546
  var wordSegmenter3 = getWordSegmenter();
195053
195547
  var unquotedAutocompleteSuffixRegex = new RegExp(`(?:(?!${autocompleteSeparatorRegex.source}).)*`, "u");
195548
+ var autocompleteTokenStartSource = `${autocompleteBoundaryRegex.source}[([{<\`]*`;
195054
195549
 
195055
195550
  // ../node_modules/@earendil-works/pi-coding-agent/node_modules/@earendil-works/pi-tui/dist/layout-node.js
195056
195551
  var LAYOUT_NODE = /* @__PURE__ */ Symbol.for("@earendil-works/pi-tui/layout-node");
@@ -196469,6 +196964,61 @@ function getScrollViewsAt(frame, x2, y2) {
196469
196964
  return result.map((entry) => entry.scrollView);
196470
196965
  }
196471
196966
 
196967
+ // ../node_modules/@earendil-works/pi-coding-agent/node_modules/@earendil-works/pi-tui/dist/wheel-scroll.js
196968
+ var BURST_GAP_MS = 5;
196969
+ var GESTURE_GAP_MS = 200;
196970
+ var REFERENCE_GAP_MS = 100;
196971
+ var MAX_AUTO_LINES = 6;
196972
+ function terminalAcceleratesWheel() {
196973
+ const env2 = process.env;
196974
+ return process.platform === "darwin" && env2.SSH_CONNECTION === void 0 && env2.SSH_CLIENT === void 0 && env2.SSH_TTY === void 0;
196975
+ }
196976
+ var WheelScrollAccelerator = class {
196977
+ lines;
196978
+ accelerate;
196979
+ lastTime = Number.NEGATIVE_INFINITY;
196980
+ lastDirection = 0;
196981
+ averageGap;
196982
+ carry = 0;
196983
+ constructor(lines = "auto", accelerate = !terminalAcceleratesWheel()) {
196984
+ this.lines = lines;
196985
+ this.accelerate = accelerate;
196986
+ }
196987
+ setLines(lines) {
196988
+ this.lines = lines;
196989
+ this.reset();
196990
+ }
196991
+ /** Return the positive line count for a wheel event in `direction` at time `now` (milliseconds). */
196992
+ next(direction, now) {
196993
+ if (this.lines !== "auto")
196994
+ return Number.isFinite(this.lines) ? Math.max(1, Math.floor(this.lines)) : 1;
196995
+ if (!this.accelerate)
196996
+ return 1;
196997
+ const gap = now - this.lastTime;
196998
+ const sameGesture = direction === this.lastDirection && gap <= GESTURE_GAP_MS;
196999
+ this.lastTime = now;
197000
+ this.lastDirection = direction;
197001
+ if (!sameGesture) {
197002
+ this.averageGap = void 0;
197003
+ this.carry = 0;
197004
+ return 1;
197005
+ }
197006
+ if (gap < BURST_GAP_MS)
197007
+ return 1;
197008
+ this.averageGap = this.averageGap === void 0 ? gap : (this.averageGap + gap) / 2;
197009
+ const lines = Math.min(MAX_AUTO_LINES, Math.max(1, REFERENCE_GAP_MS / this.averageGap)) + this.carry;
197010
+ const whole = Math.floor(lines);
197011
+ this.carry = lines - whole;
197012
+ return whole;
197013
+ }
197014
+ reset() {
197015
+ this.lastTime = Number.NEGATIVE_INFINITY;
197016
+ this.lastDirection = 0;
197017
+ this.averageGap = void 0;
197018
+ this.carry = 0;
197019
+ }
197020
+ };
197021
+
196472
197022
  // ../node_modules/@earendil-works/pi-coding-agent/node_modules/@earendil-works/pi-tui/dist/tui-alt-screen.js
196473
197023
  var ENTER_ALT_SCREEN = "\x1B[?1049h";
196474
197024
  var EXIT_ALT_SCREEN = "\x1B[?1049l";
@@ -196528,7 +197078,7 @@ var TuiAltScreen = class extends TuiBase {
196528
197078
  mousePressPoint;
196529
197079
  mousePressMoved = false;
196530
197080
  lastComponentClick;
196531
- wheelScrollLines;
197081
+ wheelScroll;
196532
197082
  mouseEnabled;
196533
197083
  searchMatchStyle;
196534
197084
  searchCurrentMatchStyle;
@@ -196550,7 +197100,7 @@ var TuiAltScreen = class extends TuiBase {
196550
197100
  };
196551
197101
  this.implicitScrollView = new ScrollView(this.implicitDocument, { follow: "end", primary: true });
196552
197102
  this.flashes = new AltScreenFlashContainer(() => this.requestRender());
196553
- this.wheelScrollLines = Math.max(1, Math.floor(options.wheelScrollLines ?? 1));
197103
+ this.wheelScroll = new WheelScrollAccelerator(options.wheelScrollLines ?? 1);
196554
197104
  this.mouseEnabled = options.mouse ?? true;
196555
197105
  this.searchMatchStyle = options.searchMatchStyle ?? ((text7) => `\x1B[4m${text7}\x1B[24m`);
196556
197106
  this.searchCurrentMatchStyle = options.searchCurrentMatchStyle ?? ((text7) => `\x1B[1;7m${text7}\x1B[22;27m`);
@@ -196568,6 +197118,9 @@ var TuiAltScreen = class extends TuiBase {
196568
197118
  get isFollowingOutput() {
196569
197119
  return this.getPrimaryScrollView().isFollowingEnd;
196570
197120
  }
197121
+ setWheelScrollLines(lines) {
197122
+ this.wheelScroll.setLines(lines);
197123
+ }
196571
197124
  getCopyOnSelect() {
196572
197125
  return this.copyOnSelect;
196573
197126
  }
@@ -196927,9 +197480,9 @@ var TuiAltScreen = class extends TuiBase {
196927
197480
  return { consume: true };
196928
197481
  const wheelEvent = this.parseWheelEvent(data);
196929
197482
  if (wheelEvent) {
196930
- const event = this.createMouseEvent("wheel", wheelEvent.button, wheelEvent.x, wheelEvent.y, {
196931
- wheelDelta: wheelEvent.direction * this.getWheelScrollLines(wheelEvent.button)
196932
- });
197483
+ const lines = this.wheelScroll.next(wheelEvent.direction, performance.now());
197484
+ const wheelDelta = wheelEvent.direction * ((wheelEvent.button & 8) !== 0 ? lines * ALT_WHEEL_SCROLL_MULTIPLIER : lines);
197485
+ const event = this.createMouseEvent("wheel", wheelEvent.button, wheelEvent.x, wheelEvent.y, { wheelDelta });
196933
197486
  const overlay = this.dispatchMouseToOverlay(event);
196934
197487
  const result = overlay.result ?? (overlay.hit ? void 0 : this.dispatchMouseToLayout(event));
196935
197488
  if (result) {
@@ -196939,7 +197492,7 @@ var TuiAltScreen = class extends TuiBase {
196939
197492
  }
196940
197493
  if (this.shouldDeferViewportInputToOverlay())
196941
197494
  return void 0;
196942
- this.routeWheel(wheelEvent);
197495
+ this.routeWheel(wheelEvent, wheelDelta);
196943
197496
  return { consume: true };
196944
197497
  }
196945
197498
  const mouseEvent = this.parseSgrMouseEvent(data);
@@ -197202,11 +197755,8 @@ var TuiAltScreen = class extends TuiBase {
197202
197755
  }
197203
197756
  return void 0;
197204
197757
  }
197205
- getWheelScrollLines(button) {
197206
- return (button & 8) !== 0 ? this.wheelScrollLines * ALT_WHEEL_SCROLL_MULTIPLIER : this.wheelScrollLines;
197207
- }
197208
- routeWheel(event) {
197209
- let remaining = event.direction * this.getWheelScrollLines(event.button);
197758
+ routeWheel(event, delta) {
197759
+ let remaining = delta;
197210
197760
  const seen = /* @__PURE__ */ new Set();
197211
197761
  for (const scrollView of this.currentLayout ? getScrollViewsAt(this.currentLayout, event.x, event.y) : []) {
197212
197762
  seen.add(scrollView);
@@ -198572,6 +199122,7 @@ var import_go = __toESM(require_go(), 1);
198572
199122
  var import_groovy = __toESM(require_groovy(), 1);
198573
199123
  var import_java = __toESM(require_java(), 1);
198574
199124
  var import_javascript = __toESM(require_javascript(), 1);
199125
+ var import_json = __toESM(require_json(), 1);
198575
199126
  var import_kotlin = __toESM(require_kotlin(), 1);
198576
199127
  var import_lua = __toESM(require_lua(), 1);
198577
199128
  var import_nix = __toESM(require_nix(), 1);
@@ -198588,6 +199139,7 @@ var eagerLanguages = {
198588
199139
  java: import_java.default,
198589
199140
  go: import_go.default,
198590
199141
  javascript: import_javascript.default,
199142
+ json: import_json.default,
198591
199143
  cpp: import_cpp.default,
198592
199144
  typescript: import_typescript.default,
198593
199145
  php: import_php.default,
@@ -198609,113 +199161,477 @@ for (const [name, language] of Object.entries(eagerLanguages)) {
198609
199161
  import_core.default.registerLanguage(name, language);
198610
199162
  }
198611
199163
 
198612
- // ../node_modules/@earendil-works/pi-coding-agent/dist/modes/interactive/theme/theme.js
198613
- var themeJsonValidator;
198614
- function hexToRgb2(hex) {
198615
- const cleaned = hex.replace("#", "");
198616
- if (cleaned.length !== 6) {
198617
- throw new Error(`Invalid hex color: ${hex}`);
199164
+ // ../node_modules/@earendil-works/pi-coding-agent/dist/modes/interactive/theme/system-theme.js
199165
+ var SYSTEM_THEME_NAME = "system";
199166
+ var FAMILIES = {
199167
+ neutral: { hue: 231.49, saturation: { min: 0.02, max: 0.08 }, slot: 8 },
199168
+ blue: { hue: 231.49, saturation: { min: 0.1, max: 0.68 }, slot: 4 },
199169
+ green: { hue: 158.68, saturation: { min: 0.1, max: 0.76 }, slot: 2 },
199170
+ red: { hue: 20, saturation: { min: 0.1, max: 0.92 }, slot: 1 },
199171
+ yellow: { hue: 82.36, saturation: { min: 0.5, max: 1 }, slot: 3 },
199172
+ orange: { hue: 52, saturation: { min: 0.12, max: 0.85 }, slot: 3 },
199173
+ violet: { hue: 295, saturation: { min: 0.2, max: 0.6 }, slot: 5 },
199174
+ calamine: { hue: 202.43, saturation: { min: 0.1, max: 0.74 }, slot: 6 },
199175
+ thinkingSlate: { hue: 231.49, saturation: { min: 0.08, max: 0.2 }, slot: 4 },
199176
+ thinkingBlue: { hue: 231.49, saturation: { min: 0.2, max: 0.45 }, slot: 4 },
199177
+ thinkingPeriwinkle: { hue: 263.25, saturation: { min: 0.3, max: 0.6 }, slot: 6 },
199178
+ thinkingViolet: { hue: 295, saturation: { min: 0.4, max: 0.75 }, slot: 5 },
199179
+ thinkingMagenta: { hue: 337.5, saturation: { min: 0.5, max: 0.85 }, slot: 13 },
199180
+ thinkingRed: { hue: 20, saturation: { min: 0.95, max: 1 }, slot: 1 }
199181
+ };
199182
+ var TOKEN_FAMILIES = {
199183
+ selectedBg: "blue",
199184
+ searchMatchBg: "orange",
199185
+ userMessageBg: "blue",
199186
+ customMessageBg: "violet",
199187
+ toolPendingBg: "neutral",
199188
+ toolSuccessBg: "green",
199189
+ toolErrorBg: "red",
199190
+ text: "neutral",
199191
+ userMessageText: "neutral",
199192
+ customMessageText: "neutral",
199193
+ toolTitle: "neutral",
199194
+ syntaxOperator: "neutral",
199195
+ syntaxPunctuation: "neutral",
199196
+ muted: "neutral",
199197
+ dim: "neutral",
199198
+ thinkingText: "neutral",
199199
+ toolOutput: "neutral",
199200
+ mdLinkUrl: "neutral",
199201
+ mdQuote: "neutral",
199202
+ mdQuoteBorder: "neutral",
199203
+ mdHr: "neutral",
199204
+ mdCodeBlockBorder: "neutral",
199205
+ toolDiffContext: "neutral",
199206
+ syntaxComment: "neutral",
199207
+ scrollbarTrack: "neutral",
199208
+ scrollbarThumb: "neutral",
199209
+ searchMatchText: "neutral",
199210
+ borderMuted: "neutral",
199211
+ accent: "violet",
199212
+ borderAccent: "violet",
199213
+ customMessageLabel: "violet",
199214
+ mdCode: "violet",
199215
+ mdListBullet: "violet",
199216
+ syntaxType: "violet",
199217
+ border: "blue",
199218
+ mdLink: "blue",
199219
+ syntaxKeyword: "blue",
199220
+ syntaxVariable: "calamine",
199221
+ success: "green",
199222
+ mdCodeBlock: "green",
199223
+ toolDiffAdded: "green",
199224
+ bashMode: "green",
199225
+ syntaxNumber: "green",
199226
+ error: "red",
199227
+ toolDiffRemoved: "red",
199228
+ warning: "yellow",
199229
+ mdHeading: "yellow",
199230
+ syntaxFunction: "yellow",
199231
+ syntaxString: "orange",
199232
+ thinkingOff: "neutral",
199233
+ thinkingMinimal: "thinkingSlate",
199234
+ thinkingLow: "thinkingBlue",
199235
+ thinkingMedium: "thinkingPeriwinkle",
199236
+ thinkingHigh: "thinkingViolet",
199237
+ thinkingXhigh: "thinkingMagenta",
199238
+ thinkingMax: "thinkingRed"
199239
+ };
199240
+ var TOKEN_SLOTS = { syntaxString: 2, syntaxNumber: 5, searchMatchBg: 3 };
199241
+ var LEVELS = {
199242
+ panel: {
199243
+ dark: { coefficients: [0.29131, -0.39746, 2.33185, -0.85524, -1.2076, 0.86276], reachable: [0, 0.979] },
199244
+ light: { coefficients: [-3.74073, 27.94549, -78.44258, 112.6798, -79.60015, 22.11277], reachable: [0.348, 1] }
199245
+ },
199246
+ track: {
199247
+ dark: { coefficients: [0.39028, -0.23015, 0.83573, 2.43829, -4.38292, 2.01582], reachable: [0, 0.946] },
199248
+ light: { coefficients: [-5.24921, 38.37322, -107.28833, 152.10005, -106.17127, 29.18061], reachable: [0.368, 1] }
199249
+ },
199250
+ thinking0: {
199251
+ dark: { coefficients: [0.52988, -0.05809, -0.30924, 4.63567, -6.52933, 2.89108], reachable: [0, 0.873] },
199252
+ light: {
199253
+ coefficients: [-28.27749, 182.85284, -469.62416, 603.15916, -384.59976, 97.35147],
199254
+ reachable: [0.51, 1]
199255
+ }
199256
+ },
199257
+ thinking1: {
199258
+ dark: { coefficients: [0.55278, -0.03667, -0.45659, 4.95347, -6.90265, 3.0706], reachable: [0, 0.858] },
199259
+ light: {
199260
+ coefficients: [-37.10484, 235.86282, -596.62344, 754.3633, -474.00763, 118.3551],
199261
+ reachable: [0.535, 1]
199262
+ }
199263
+ },
199264
+ thinking2: {
199265
+ dark: { coefficients: [0.57486, -0.01765, -0.58987, 5.25227, -7.27175, 3.25532], reachable: [0, 0.842] },
199266
+ light: {
199267
+ coefficients: [-59.89653, 377.05024, -945.07843, 1182.03145, -734.96375, 181.68658],
199268
+ reachable: [0.556, 1]
199269
+ }
199270
+ },
199271
+ thinking3: {
199272
+ dark: { coefficients: [0.59621, -62e-5, -0.71148, 5.53588, -7.6392, 3.44606], reachable: [0, 0.827] },
199273
+ light: {
199274
+ coefficients: [-72.07122, 445.84082, -1099.57352, 1353.88793, -829.53392, 202.26164],
199275
+ reachable: [0.58, 1]
199276
+ }
199277
+ },
199278
+ thinking4: {
199279
+ dark: { coefficients: [0.61691, 0.01462, -0.82288, 5.80651, -8.00641, 3.64333], reachable: [0, 0.811] },
199280
+ light: {
199281
+ coefficients: [-110.14338, 674.21488, -1645.75941, 2004.32367, -1215.15899, 293.3183],
199282
+ reachable: [0.6, 1]
199283
+ }
199284
+ },
199285
+ thinking5: {
199286
+ dark: { coefficients: [0.63702, 0.02826, -0.92498, 6.06465, -8.37246, 3.84651], reachable: [0, 0.795] },
199287
+ light: {
199288
+ coefficients: [-175.47701, 1063.54495, -2570.70594, 3098.80776, -1860.15527, 444.76392],
199289
+ reachable: [0.62, 1]
199290
+ }
199291
+ },
199292
+ thinking6: {
199293
+ dark: { coefficients: [0.65658, 0.04044, -1.01835, 6.30989, -8.73529, 4.05439], reachable: [0, 0.779] },
199294
+ light: {
199295
+ coefficients: [-183.81712, 1094.70055, -2602.68539, 3088.71276, -1826.91131, 430.75931],
199296
+ reachable: [0.643, 1]
199297
+ }
199298
+ },
199299
+ subtle: {
199300
+ dark: { coefficients: [0.56762, -0.02475, -0.5383, 5.12628, -7.10931, 3.17324], reachable: [0, 0.848] },
199301
+ light: {
199302
+ coefficients: [-232.85459, 1376.54473, -3249.11801, 3827.91186, -2248.29472, 526.55751],
199303
+ reachable: [0.657, 1]
199304
+ }
199305
+ },
199306
+ thumb: {
199307
+ dark: { coefficients: [0.60323, 278e-5, -0.73328, 5.57157, -7.68067, 3.46933], reachable: [0, 0.823] },
199308
+ light: {
199309
+ coefficients: [-82.89897, 511.01355, -1255.98095, 1540.76821, -940.68087, 228.58523],
199310
+ reachable: [0.586, 1]
199311
+ }
199312
+ },
199313
+ readable: {
199314
+ dark: { coefficients: [0.66937, 0.04704, -1.06871, 6.43941, -8.9332, 4.17229], reachable: [0, 0.77] },
199315
+ light: {
199316
+ coefficients: [-1554.52576, 8733.56817, -19604.93507, 21977.72696, -12300.99599, 2749.81288],
199317
+ reachable: [0.751, 1]
199318
+ }
199319
+ },
199320
+ emphasis: {
199321
+ dark: { coefficients: [0.7303, 0.07695, -1.31626, 7.1681, -10.14436, 4.92846], reachable: [0, 0.712] },
199322
+ light: {
199323
+ coefficients: [-4948.31942, 26870.91986, -58334.48399, 63280.17197, -34298.01053, 7430.30146],
199324
+ reachable: [0.811, 1]
199325
+ }
199326
+ },
199327
+ textOnPanel: {
199328
+ dark: { coefficients: [0.86713, 0.05232, -0.89428, 4.79014, -5.5432, 1.75023], reachable: [0, 0.542] },
199329
+ light: {
199330
+ coefficients: [-8570.89457, 43954.60805, -90084.00702, 92220.6791, -47152.15802, 9632.27113],
199331
+ reachable: [0.867, 1]
199332
+ }
199333
+ },
199334
+ text: {
199335
+ dark: { coefficients: [0.89242, 0.02311, -0.44862, 2.34417, -0.06084, -2.63844], reachable: [0, 0.5] },
199336
+ light: {
199337
+ coefficients: [-2004.67048, 6664.47299, -6060.70202, -1792.61209, 5133.82359, -1939.85583],
199338
+ reachable: [0.894, 1]
199339
+ }
199340
+ }
199341
+ };
199342
+ var TOOL_PANELS = ["toolPendingBg", "toolSuccessBg", "toolErrorBg"];
199343
+ var MESSAGE_PANELS = ["userMessageBg", "customMessageBg"];
199344
+ var PANELS = [
199345
+ "userMessageBg",
199346
+ "toolPendingBg",
199347
+ "toolSuccessBg",
199348
+ "toolErrorBg",
199349
+ "selectedBg",
199350
+ "searchMatchBg",
199351
+ "customMessageBg"
199352
+ ];
199353
+ var THINKING = [
199354
+ "thinkingOff",
199355
+ "thinkingMinimal",
199356
+ "thinkingLow",
199357
+ "thinkingMedium",
199358
+ "thinkingHigh",
199359
+ "thinkingXhigh",
199360
+ "thinkingMax"
199361
+ ];
199362
+ var THINKING_LEVELS2 = [
199363
+ "thinking0",
199364
+ "thinking1",
199365
+ "thinking2",
199366
+ "thinking3",
199367
+ "thinking4",
199368
+ "thinking5",
199369
+ "thinking6"
199370
+ ];
199371
+ var each = (tokens, on3, level) => tokens.map((token) => ({ token, on: on3, level }));
199372
+ var RULES = [
199373
+ ...each(PANELS, ["background"], "panel"),
199374
+ { token: "text", on: ["background"], level: "text" },
199375
+ { token: "text", on: ["selectedBg"], level: "textOnPanel" },
199376
+ { token: "userMessageText", on: ["userMessageBg"], level: "textOnPanel" },
199377
+ { token: "toolTitle", on: TOOL_PANELS, level: "textOnPanel" },
199378
+ ...each(["accent", "success", "error", "warning"], ["background", "selectedBg", ...TOOL_PANELS], "readable"),
199379
+ { token: "muted", on: ["background", "selectedBg", "customMessageBg", ...TOOL_PANELS], level: "readable" },
199380
+ { token: "dim", on: ["background", "selectedBg", "customMessageBg", ...TOOL_PANELS], level: "subtle" },
199381
+ { token: "thinkingText", on: ["background"], level: "readable" },
199382
+ { token: "customMessageText", on: ["customMessageBg", ...TOOL_PANELS], level: "readable" },
199383
+ {
199384
+ token: "customMessageLabel",
199385
+ on: ["background", "customMessageBg", "selectedBg", ...TOOL_PANELS],
199386
+ level: "readable"
199387
+ },
199388
+ { token: "toolOutput", on: ["background", ...TOOL_PANELS], level: "readable" },
199389
+ ...each(["mdHeading", "mdLink", "mdLinkUrl", "mdCode", "mdQuote", "mdCodeBlockBorder", "mdListBullet"], ["background", ...MESSAGE_PANELS], "readable"),
199390
+ { token: "mdCodeBlock", on: ["background", ...MESSAGE_PANELS, ...TOOL_PANELS], level: "readable" },
199391
+ ...each(["toolDiffAdded", "toolDiffRemoved", "toolDiffContext"], ["background", ...TOOL_PANELS], "readable"),
199392
+ ...each([
199393
+ "syntaxComment",
199394
+ "syntaxKeyword",
199395
+ "syntaxFunction",
199396
+ "syntaxVariable",
199397
+ "syntaxString",
199398
+ "syntaxNumber",
199399
+ "syntaxType",
199400
+ "syntaxOperator",
199401
+ "syntaxPunctuation"
199402
+ ], ["background", ...MESSAGE_PANELS, ...TOOL_PANELS], "readable"),
199403
+ { token: "searchMatchText", on: ["searchMatchBg"], level: "readable" },
199404
+ ...each(["bashMode", "border", "borderAccent"], ["background"], "readable"),
199405
+ { token: "borderMuted", on: ["background"], level: "subtle" },
199406
+ ...each(["mdQuoteBorder", "mdHr"], ["background", ...MESSAGE_PANELS, ...TOOL_PANELS], "readable"),
199407
+ { token: "scrollbarTrack", on: ["background"], level: "track" },
199408
+ { token: "scrollbarThumb", on: ["scrollbarTrack"], level: "thumb" },
199409
+ ...THINKING.map((token, index4) => ({ token, on: ["background"], level: THINKING_LEVELS2[index4] }))
199410
+ ];
199411
+ var READABLE_FLOOR = { dark: "readable", light: "subtle" };
199412
+ var FOREGROUND_LEVEL = "emphasis";
199413
+ var FOREGROUND_TOKENS = ["text", "userMessageText", "toolTitle"];
199414
+ var TEXT_MINIMUM_WCAG_CONTRAST = 4.5;
199415
+ var SOLVE_ORDER = (() => {
199416
+ const order2 = [];
199417
+ const visit2 = (token) => {
199418
+ if (order2.includes(token))
199419
+ return;
199420
+ for (const rule of RULES) {
199421
+ if (rule.token !== token)
199422
+ continue;
199423
+ for (const surface of rule.on)
199424
+ if (surface !== "background")
199425
+ visit2(surface);
199426
+ }
199427
+ order2.push(token);
199428
+ };
199429
+ for (const rule of RULES)
199430
+ visit2(rule.token);
199431
+ return order2;
199432
+ })();
199433
+ function oklabLightness(color3) {
199434
+ return colorToOklch(rgbColor(color3.r, color3.g, color3.b)).l;
199435
+ }
199436
+ function relativeLuminance({ r, g, b: b2 }) {
199437
+ const linear = (channel) => {
199438
+ const value = channel / 255;
199439
+ return value <= 0.04045 ? value / 12.92 : ((value + 0.055) / 1.055) ** 2.4;
199440
+ };
199441
+ return 0.2126 * linear(r) + 0.7152 * linear(g) + 0.0722 * linear(b2);
199442
+ }
199443
+ function wcagContrast(first, second) {
199444
+ const a = relativeLuminance(first);
199445
+ const b2 = relativeLuminance(second);
199446
+ return (Math.max(a, b2) + 0.05) / (Math.min(a, b2) + 0.05);
199447
+ }
199448
+ function terminalAppearance(background, foreground) {
199449
+ const white = { r: 255, g: 255, b: 255 };
199450
+ const black = { r: 0, g: 0, b: 0 };
199451
+ const whiteContrast = wcagContrast(white, background);
199452
+ const blackContrast = wcagContrast(black, background);
199453
+ if (foreground) {
199454
+ const foregroundL = oklabLightness(foreground);
199455
+ const backgroundL = oklabLightness(background);
199456
+ if (Math.abs(foregroundL - backgroundL) > 0.05) {
199457
+ const appearance = foregroundL > backgroundL ? "dark" : "light";
199458
+ const best = appearance === "dark" ? whiteContrast : blackContrast;
199459
+ if (best >= TEXT_MINIMUM_WCAG_CONTRAST)
199460
+ return appearance;
199461
+ }
199462
+ }
199463
+ return whiteContrast >= blackContrast ? "dark" : "light";
199464
+ }
199465
+ var clamp = (value, min, max) => Math.min(max, Math.max(min, value));
199466
+ function hexOf({ r, g, b: b2 }) {
199467
+ return `#${[r, g, b2].map((channel) => Math.round(channel).toString(16).padStart(2, "0")).join("")}`;
199468
+ }
199469
+ function bellWeight(lightness) {
199470
+ const gaussian = (x2) => Math.exp(-((x2 - 0.5) ** 2) / (2 * 0.25 ** 2));
199471
+ return (gaussian(lightness) - gaussian(0)) / (1 - gaussian(0));
199472
+ }
199473
+ function saturationCurve({ saturation: { min, max } }, lightness) {
199474
+ const floor2 = max > 0 ? min / max : 1;
199475
+ return floor2 + (1 - floor2) * bellWeight(lightness);
199476
+ }
199477
+ function levelTarget(level, appearance, surfaceL) {
199478
+ const curve = LEVELS[level][appearance];
199479
+ if (surfaceL < curve.reachable[0] || surfaceL > curve.reachable[1])
199480
+ return void 0;
199481
+ return curve.coefficients.reduce((sum, coefficient, power) => sum + coefficient * surfaceL ** power, 0);
199482
+ }
199483
+ function generateSystemThemeColors(input) {
199484
+ const saturation = clamp(input.saturation ?? 1, 0, 1);
199485
+ const { background, foreground } = input;
199486
+ if (!background)
199487
+ return indexedColors(saturation, input.appearanceHint);
199488
+ const palette = input.palette?.length === 16 ? input.palette.map(okhslOf) : void 0;
199489
+ const appearance = terminalAppearance(background, foreground);
199490
+ const lighter = appearance === "dark";
199491
+ const extreme = lighter ? 1 : 0;
199492
+ const backgroundL = oklabLightness(background);
199493
+ const paint = (token, oklabL) => {
199494
+ const lightness = oklabToOkhslLightness(oklabL);
199495
+ const family = FAMILIES[TOKEN_FAMILIES[token]];
199496
+ if (!palette) {
199497
+ const { min, max } = family.saturation;
199498
+ return okhslColor(family.hue, (min + (max - min) * bellWeight(lightness)) * saturation, lightness);
199499
+ }
199500
+ return anchored(palette[TOKEN_SLOTS[token] ?? family.slot], family, lightness, saturation);
199501
+ };
199502
+ const target = (level, surfaceL, t) => {
199503
+ const reached = levelTarget(level, appearance, surfaceL);
199504
+ if (reached === void 0 && t === 0)
199505
+ return void 0;
199506
+ const distance = (reached ?? extreme) - surfaceL;
199507
+ const floor2 = (levelTarget(READABLE_FLOOR[appearance], appearance, surfaceL) ?? extreme) - surfaceL;
199508
+ const compressed = Math.abs(distance) > Math.abs(floor2) ? distance - (distance - floor2) * Math.min(t, 1) : distance;
199509
+ return surfaceL + compressed * (1 - Math.max(0, t - 1));
199510
+ };
199511
+ const extremeText = lighter ? { r: 255, g: 255, b: 255 } : { r: 0, g: 0, b: 0 };
199512
+ const readable = (color3) => wcagContrast(extremeText, color3) >= TEXT_MINIMUM_WCAG_CONTRAST;
199513
+ const limitPanel = (token, l3) => {
199514
+ const color3 = paint(token, l3);
199515
+ if (readable(color3))
199516
+ return color3;
199517
+ let [low, high] = [backgroundL, l3];
199518
+ for (let index4 = 0; index4 < 20; index4++) {
199519
+ const middle = (low + high) / 2;
199520
+ if (readable(paint(token, middle)))
199521
+ low = middle;
199522
+ else
199523
+ high = middle;
199524
+ }
199525
+ return paint(token, low);
199526
+ };
199527
+ const solve = (t) => {
199528
+ const colors2 = /* @__PURE__ */ new Map([["background", background]]);
199529
+ for (const token of SOLVE_ORDER) {
199530
+ const targets = [];
199531
+ for (const rule of RULES) {
199532
+ if (rule.token !== token)
199533
+ continue;
199534
+ for (const surface of rule.on) {
199535
+ const value = target(rule.level, oklabLightness(colors2.get(surface) ?? background), t);
199536
+ if (value === void 0 || value < 0 || value > 1)
199537
+ return void 0;
199538
+ targets.push(value);
199539
+ }
199540
+ }
199541
+ const l3 = lighter ? Math.max(...targets) : Math.min(...targets);
199542
+ colors2.set(token, PANELS.includes(token) ? limitPanel(token, l3) : paint(token, l3));
199543
+ }
199544
+ return colors2;
199545
+ };
199546
+ let relaxation = 0;
199547
+ let colors = solve(0);
199548
+ if (!colors) {
199549
+ let [low, high] = [0, 2];
199550
+ colors = solve(high);
199551
+ for (let index4 = 0; index4 < 20; index4++) {
199552
+ const middle = (low + high) / 2;
199553
+ const attempt = solve(middle);
199554
+ if (attempt)
199555
+ [high, colors] = [middle, attempt];
199556
+ else
199557
+ low = middle;
199558
+ }
199559
+ relaxation = high;
198618
199560
  }
198619
- const r = parseInt(cleaned.substring(0, 2), 16);
198620
- const g = parseInt(cleaned.substring(2, 4), 16);
198621
- const b2 = parseInt(cleaned.substring(4, 6), 16);
198622
- if (Number.isNaN(r) || Number.isNaN(g) || Number.isNaN(b2)) {
198623
- throw new Error(`Invalid hex color: ${hex}`);
199561
+ const solved = colors ?? /* @__PURE__ */ new Map();
199562
+ const surfacesOf = (token) => RULES.filter((rule) => rule.token === token).flatMap((rule) => rule.on.map((surface) => solved.get(surface) ?? background));
199563
+ const result = {};
199564
+ for (const token of Object.keys(TOKEN_FAMILIES)) {
199565
+ const color3 = solved.get(token);
199566
+ result[token] = color3 ? hexOf(color3) : "";
199567
+ }
199568
+ for (const token of FOREGROUND_TOKENS) {
199569
+ const surfaces = surfacesOf(token);
199570
+ let text7 = solved.get(token);
199571
+ if (foreground) {
199572
+ const targets = surfaces.map((surface) => target(FOREGROUND_LEVEL, oklabLightness(surface), relaxation));
199573
+ if (targets.every((value) => value !== void 0 && value >= 0 && value <= 1)) {
199574
+ const needed = lighter ? Math.max(...targets) : Math.min(...targets);
199575
+ const foregroundL = oklabLightness(foreground);
199576
+ if (lighter ? foregroundL >= needed : foregroundL <= needed) {
199577
+ result[token] = "";
199578
+ continue;
199579
+ }
199580
+ text7 = anchored(okhslOf(foreground), FAMILIES.neutral, oklabToOkhslLightness(needed), saturation);
199581
+ }
199582
+ }
199583
+ if (text7)
199584
+ result[token] = hexOf(withTextContrast(text7, surfaces, lighter));
198624
199585
  }
198625
- return { r, g, b: b2 };
199586
+ return { colors: result, dim: [], appearance };
198626
199587
  }
198627
- var CUBE_VALUES = [0, 95, 135, 175, 215, 255];
198628
- var GRAY_VALUES = Array.from({ length: 24 }, (_2, i2) => 8 + i2 * 10);
198629
- function findClosestCubeIndex(value) {
198630
- let minDist = Infinity;
198631
- let minIdx = 0;
198632
- for (let i2 = 0; i2 < CUBE_VALUES.length; i2++) {
198633
- const dist = Math.abs(value - CUBE_VALUES[i2]);
198634
- if (dist < minDist) {
198635
- minDist = dist;
198636
- minIdx = i2;
198637
- }
198638
- }
198639
- return minIdx;
198640
- }
198641
- function findClosestGrayIndex(gray) {
198642
- let minDist = Infinity;
198643
- let minIdx = 0;
198644
- for (let i2 = 0; i2 < GRAY_VALUES.length; i2++) {
198645
- const dist = Math.abs(gray - GRAY_VALUES[i2]);
198646
- if (dist < minDist) {
198647
- minDist = dist;
198648
- minIdx = i2;
198649
- }
198650
- }
198651
- return minIdx;
198652
- }
198653
- function colorDistance(r1, g1, b1, r2, g2, b2) {
198654
- const dr2 = r1 - r2;
198655
- const dg = g1 - g2;
198656
- const db = b1 - b2;
198657
- return dr2 * dr2 * 0.299 + dg * dg * 0.587 + db * db * 0.114;
199588
+ function okhslOf({ r, g, b: b2 }) {
199589
+ return colorToOkhsl(rgbColor(r, g, b2));
198658
199590
  }
198659
- function rgbTo256(r, g, b2) {
198660
- const rIdx = findClosestCubeIndex(r);
198661
- const gIdx = findClosestCubeIndex(g);
198662
- const bIdx = findClosestCubeIndex(b2);
198663
- const cubeR = CUBE_VALUES[rIdx];
198664
- const cubeG = CUBE_VALUES[gIdx];
198665
- const cubeB = CUBE_VALUES[bIdx];
198666
- const cubeIndex = 16 + 36 * rIdx + 6 * gIdx + bIdx;
198667
- const cubeDist = colorDistance(r, g, b2, cubeR, cubeG, cubeB);
198668
- const gray = Math.round(0.299 * r + 0.587 * g + 0.114 * b2);
198669
- const grayIdx = findClosestGrayIndex(gray);
198670
- const grayValue = GRAY_VALUES[grayIdx];
198671
- const grayIndex = 232 + grayIdx;
198672
- const grayDist = colorDistance(r, g, b2, grayValue, grayValue, grayValue);
198673
- const maxC = Math.max(r, g, b2);
198674
- const minC = Math.min(r, g, b2);
198675
- const spread = maxC - minC;
198676
- if (spread < 10 && grayDist < cubeDist) {
198677
- return grayIndex;
198678
- }
198679
- return cubeIndex;
199591
+ function anchored(source, family, lightness, saturation) {
199592
+ const anchor = saturationCurve(family, source.l);
199593
+ const falloff = anchor > 0 ? Math.min(1, saturationCurve(family, lightness) / anchor) : 1;
199594
+ return okhslColor(source.h, source.s * falloff * saturation, lightness);
198680
199595
  }
198681
- function hexTo256(hex) {
198682
- const { r, g, b: b2 } = hexToRgb2(hex);
198683
- return rgbTo256(r, g, b2);
198684
- }
198685
- function fgAnsi(color3, mode) {
198686
- if (color3 === "")
198687
- return "\x1B[39m";
198688
- if (typeof color3 === "number")
198689
- return `\x1B[38;5;${color3}m`;
198690
- if (color3.startsWith("#")) {
198691
- if (mode === "truecolor") {
198692
- const { r, g, b: b2 } = hexToRgb2(color3);
198693
- return `\x1B[38;2;${r};${g};${b2}m`;
198694
- } else {
198695
- const index4 = hexTo256(color3);
198696
- return `\x1B[38;5;${index4}m`;
198697
- }
199596
+ function withTextContrast(color3, surfaces, lighter) {
199597
+ const meets = (candidate) => surfaces.every((surface) => wcagContrast(candidate, surface) >= TEXT_MINIMUM_WCAG_CONTRAST);
199598
+ if (meets(color3))
199599
+ return color3;
199600
+ const { h, s, l: l3 } = okhslOf(color3);
199601
+ const at4 = (lightness) => okhslColor(h, s, lightness);
199602
+ const extreme = lighter ? 1 : 0;
199603
+ if (!meets(at4(extreme)))
199604
+ return at4(extreme);
199605
+ let [low, high] = [l3, extreme];
199606
+ for (let index4 = 0; index4 < 20; index4++) {
199607
+ const middle = (low + high) / 2;
199608
+ if (meets(at4(middle)))
199609
+ high = middle;
199610
+ else
199611
+ low = middle;
198698
199612
  }
198699
- throw new Error(`Invalid color value: ${color3}`);
199613
+ return at4(high);
198700
199614
  }
198701
- function bgAnsi(color3, mode) {
198702
- if (color3 === "")
198703
- return "\x1B[49m";
198704
- if (typeof color3 === "number")
198705
- return `\x1B[48;5;${color3}m`;
198706
- if (color3.startsWith("#")) {
198707
- if (mode === "truecolor") {
198708
- const { r, g, b: b2 } = hexToRgb2(color3);
198709
- return `\x1B[48;2;${r};${g};${b2}m`;
198710
- } else {
198711
- const index4 = hexTo256(color3);
198712
- return `\x1B[48;5;${index4}m`;
199615
+ function indexedColors(saturation, appearance) {
199616
+ const colors = {};
199617
+ const dim = [];
199618
+ for (const [token, familyName] of Object.entries(TOKEN_FAMILIES)) {
199619
+ if (PANELS.includes(token)) {
199620
+ colors[token] = "";
199621
+ continue;
198713
199622
  }
199623
+ const neutral = familyName === "neutral";
199624
+ colors[token] = !neutral && saturation > 0 ? TOKEN_SLOTS[token] ?? FAMILIES[familyName].slot : "";
199625
+ if (neutral && !FOREGROUND_TOKENS.includes(token))
199626
+ dim.push(token);
198714
199627
  }
198715
- throw new Error(`Invalid color value: ${color3}`);
199628
+ return { colors, dim, appearance };
198716
199629
  }
199630
+
199631
+ // ../node_modules/@earendil-works/pi-coding-agent/dist/modes/interactive/theme/theme.js
199632
+ var themeJsonValidator;
198717
199633
  function resolveVarRefs(value, vars, visited2 = /* @__PURE__ */ new Set()) {
198718
- if (typeof value === "number" || value === "" || value.startsWith("#")) {
199634
+ if (typeof value === "number" || value === "" || value.startsWith("#") || /^ok(lch|hsl)\(/i.test(value)) {
198719
199635
  return value;
198720
199636
  }
198721
199637
  if (visited2.has(value)) {
@@ -198744,50 +199660,135 @@ function withThemeColorFallbacks(colors) {
198744
199660
  searchMatchText: colors.searchMatchText ?? colors.text
198745
199661
  };
198746
199662
  }
199663
+ var terminalColors = {};
199664
+ var terminalColorsPending = false;
199665
+ var terminalColorScheme;
199666
+ var GUESSED_DEFAULT_COLORS = {
199667
+ dark: { foreground: parseColor("#e5e5e7"), background: parseColor("#000000") },
199668
+ light: { foreground: parseColor("#000000"), background: parseColor("#ffffff") }
199669
+ };
199670
+ function averageLightness(colors) {
199671
+ const fixed = colors.filter((color3) => color3.kind !== "indexed" || color3.index >= 16);
199672
+ if (fixed.length === 0)
199673
+ return void 0;
199674
+ return fixed.reduce((sum, color3) => sum + colorToOklch(color3).l, 0) / fixed.length;
199675
+ }
199676
+ function detectAppearance(foregrounds, backgrounds) {
199677
+ const fg = averageLightness(foregrounds);
199678
+ const bg = averageLightness(backgrounds);
199679
+ if (fg !== void 0 && bg !== void 0)
199680
+ return bg < fg ? "dark" : "light";
199681
+ if (bg !== void 0)
199682
+ return bg < 0.5 ? "dark" : "light";
199683
+ if (fg !== void 0)
199684
+ return fg > 0.5 ? "dark" : "light";
199685
+ return void 0;
199686
+ }
198747
199687
  var Theme = class {
198748
199688
  name;
198749
199689
  sourcePath;
198750
199690
  sourceInfo;
198751
- fgColors;
198752
- bgColors;
198753
199691
  mode;
199692
+ // Precomputed escape sequences keep fg()/bg() on the render hot path to a lookup and concat.
199693
+ fgAnsi = /* @__PURE__ */ new Map();
199694
+ bgAnsi = /* @__PURE__ */ new Map();
199695
+ // Tokens set to "" have no color of their own; `colors` fills them from the terminal defaults.
199696
+ concreteColors = {};
199697
+ defaultForegroundTokens = [];
199698
+ defaultBackgroundTokens = [];
199699
+ // Foreground tokens rendered faint (SGR 2) on top of their color.
199700
+ dimTokens;
199701
+ ownAppearance;
199702
+ resolvedColors;
198754
199703
  constructor(fgColors, bgColors, mode, options = {}) {
198755
199704
  this.name = options.name;
198756
199705
  this.sourcePath = options.sourcePath;
198757
199706
  this.sourceInfo = options.sourceInfo;
198758
199707
  this.mode = mode;
198759
- this.fgColors = /* @__PURE__ */ new Map();
198760
- const colors = {
199708
+ this.dimTokens = new Set(options.dim);
199709
+ const foregrounds = {
198761
199710
  ...fgColors,
198762
199711
  scrollbarTrack: fgColors.scrollbarTrack ?? fgColors.muted,
198763
199712
  scrollbarThumb: fgColors.scrollbarThumb ?? fgColors.text,
198764
199713
  thinkingMax: fgColors.thinkingMax ?? fgColors.thinkingXhigh,
198765
199714
  searchMatchText: fgColors.searchMatchText ?? fgColors.text
198766
199715
  };
198767
- for (const [key, value] of Object.entries(colors)) {
198768
- this.fgColors.set(key, fgAnsi(value, mode));
198769
- }
198770
- this.bgColors = /* @__PURE__ */ new Map();
198771
- const backgrounds = {
198772
- ...bgColors,
198773
- searchMatchBg: bgColors.searchMatchBg ?? bgColors.selectedBg
199716
+ const backgrounds = { ...bgColors, searchMatchBg: bgColors.searchMatchBg ?? bgColors.selectedBg };
199717
+ const concreteForegrounds = [];
199718
+ const concreteBackgrounds = [];
199719
+ const addToken = (token, value, isBackground) => {
199720
+ if (value === "") {
199721
+ (isBackground ? this.defaultBackgroundTokens : this.defaultForegroundTokens).push(token);
199722
+ return isBackground ? "\x1B[49m" : "\x1B[39m";
199723
+ }
199724
+ const color3 = parseColor(value);
199725
+ this.concreteColors[token] = color3;
199726
+ (isBackground ? concreteBackgrounds : concreteForegrounds).push(color3);
199727
+ return isBackground ? backgroundAnsi(color3, mode) : foregroundAnsi(color3, mode);
198774
199728
  };
198775
- for (const [key, value] of Object.entries(backgrounds)) {
198776
- this.bgColors.set(key, bgAnsi(value, mode));
199729
+ for (const [token, value] of Object.entries(foregrounds)) {
199730
+ this.fgAnsi.set(token, addToken(token, value, false));
198777
199731
  }
199732
+ for (const [token, value] of Object.entries(backgrounds)) {
199733
+ this.bgAnsi.set(token, addToken(token, value, true));
199734
+ }
199735
+ this.ownAppearance = options.appearance ?? detectAppearance(concreteForegrounds, concreteBackgrounds);
199736
+ }
199737
+ /**
199738
+ * The background the theme is designed for: declared in the theme JSON, detected from its colors,
199739
+ * or, for themes without usable colors, the terminal's appearance.
199740
+ */
199741
+ get appearance() {
199742
+ return this.ownAppearance ?? getTerminalTheme();
199743
+ }
199744
+ /**
199745
+ * Concrete colors for all tokens. Tokens set to "" (terminal default) use the terminal's reported
199746
+ * default colors, or a guess based on `appearance` when the terminal did not report them. Faint
199747
+ * tokens are approximated by mixing their color toward the background.
199748
+ */
199749
+ get colors() {
199750
+ const terminal = terminalColors;
199751
+ if (this.resolvedColors?.terminal !== terminal) {
199752
+ const guess = GUESSED_DEFAULT_COLORS[this.appearance];
199753
+ const toColor = (rgb, fallback) => rgb ? rgbColor(rgb.r, rgb.g, rgb.b) : fallback;
199754
+ const foreground = toColor(terminal.foreground, guess.foreground);
199755
+ const background = toColor(terminal.background, guess.background);
199756
+ const colors = { ...this.concreteColors };
199757
+ for (const token of this.defaultForegroundTokens)
199758
+ colors[token] = foreground;
199759
+ for (const token of this.defaultBackgroundTokens)
199760
+ colors[token] = background;
199761
+ for (const token of this.dimTokens) {
199762
+ const color3 = colors[token];
199763
+ if (color3)
199764
+ colors[token] = mixColors(color3, background, 0.4);
199765
+ }
199766
+ this.resolvedColors = { terminal, colors: Object.freeze(colors) };
199767
+ }
199768
+ return this.resolvedColors.colors;
199769
+ }
199770
+ style(text7, options) {
199771
+ const { fg, bg } = options;
199772
+ if (typeof fg === "string" && this.dimTokens.has(fg))
199773
+ options = { ...options, dim: true };
199774
+ return styleTextWithAnsi(text7, fg === void 0 ? void 0 : typeof fg === "string" ? this.tokenAnsi(this.fgAnsi, fg) : foregroundAnsi(fg, this.mode), bg === void 0 ? void 0 : typeof bg === "string" ? this.tokenAnsi(this.bgAnsi, bg) : backgroundAnsi(bg, this.mode), options);
198778
199775
  }
198779
199776
  fg(color3, text7) {
198780
- const ansi = this.fgColors.get(color3);
198781
- if (!ansi)
198782
- throw new Error(`Unknown theme color: ${color3}`);
199777
+ const ansi = this.tokenAnsi(this.fgAnsi, color3);
199778
+ if (this.dimTokens.has(color3))
199779
+ return `${ansi}\x1B[2m${text7}\x1B[22;39m`;
198783
199780
  return `${ansi}${text7}\x1B[39m`;
198784
199781
  }
198785
199782
  bg(color3, text7) {
198786
- const ansi = this.bgColors.get(color3);
198787
- if (!ansi)
198788
- throw new Error(`Unknown theme background color: ${color3}`);
199783
+ const ansi = this.tokenAnsi(this.bgAnsi, color3);
198789
199784
  return `${ansi}${text7}\x1B[49m`;
198790
199785
  }
199786
+ tokenAnsi(ansi, token) {
199787
+ const value = ansi.get(token);
199788
+ if (value === void 0)
199789
+ throw new Error(`Unknown theme color: ${token}`);
199790
+ return value;
199791
+ }
198791
199792
  bold(text7) {
198792
199793
  return source_default.bold(text7);
198793
199794
  }
@@ -198803,17 +199804,13 @@ var Theme = class {
198803
199804
  strikethrough(text7) {
198804
199805
  return source_default.strikethrough(text7);
198805
199806
  }
199807
+ /** Opening escape sequence for a foreground token. Faint tokens include SGR 2, which `\x1b[22m` closes. */
198806
199808
  getFgAnsi(color3) {
198807
- const ansi = this.fgColors.get(color3);
198808
- if (!ansi)
198809
- throw new Error(`Unknown theme color: ${color3}`);
198810
- return ansi;
199809
+ const ansi = this.tokenAnsi(this.fgAnsi, color3);
199810
+ return this.dimTokens.has(color3) ? `${ansi}\x1B[2m` : ansi;
198811
199811
  }
198812
199812
  getBgAnsi(color3) {
198813
- const ansi = this.bgColors.get(color3);
198814
- if (!ansi)
198815
- throw new Error(`Unknown theme background color: ${color3}`);
198816
- return ansi;
199813
+ return this.tokenAnsi(this.bgAnsi, color3);
198817
199814
  }
198818
199815
  getColorMode() {
198819
199816
  return this.mode;
@@ -198855,22 +199852,22 @@ function getBuiltinThemes() {
198855
199852
  }
198856
199853
  return BUILTIN_THEMES;
198857
199854
  }
198858
- function parseThemeJson(label, json) {
199855
+ function parseThemeJson(label, json2) {
198859
199856
  if (themeJsonValidator)
198860
- return themeJsonValidator(label, json);
198861
- if (typeof json !== "object" || json === null || !("colors" in json)) {
199857
+ return themeJsonValidator(label, json2);
199858
+ if (typeof json2 !== "object" || json2 === null || !("colors" in json2)) {
198862
199859
  throw new Error(`Invalid theme "${label}": expected an object with a "colors" map.`);
198863
199860
  }
198864
- return json;
199861
+ return json2;
198865
199862
  }
198866
199863
  function parseThemeJsonContent(label, content3) {
198867
- let json;
199864
+ let json2;
198868
199865
  try {
198869
- json = JSON.parse(stripBom(content3));
199866
+ json2 = JSON.parse(stripBom(content3));
198870
199867
  } catch (error) {
198871
199868
  throw new Error(`Failed to parse theme ${label}: ${error}`);
198872
199869
  }
198873
- return parseThemeJson(label, json);
199870
+ return parseThemeJson(label, json2);
198874
199871
  }
198875
199872
  function loadThemeJson(name) {
198876
199873
  const builtinThemes = getBuiltinThemes();
@@ -198893,33 +199890,53 @@ function loadThemeJson(name) {
198893
199890
  const content3 = fs28.readFileSync(themePath, "utf-8");
198894
199891
  return parseThemeJsonContent(name, content3);
198895
199892
  }
198896
- function createTheme(themeJson, mode, sourcePath) {
198897
- const colorMode = mode ?? (getCapabilities().trueColor ? "truecolor" : "256color");
198898
- const resolvedColors = resolveThemeColors(withThemeColorFallbacks(themeJson.colors), themeJson.vars);
199893
+ var BACKGROUND_TOKENS = /* @__PURE__ */ new Set([
199894
+ "selectedBg",
199895
+ "searchMatchBg",
199896
+ "userMessageBg",
199897
+ "customMessageBg",
199898
+ "toolPendingBg",
199899
+ "toolSuccessBg",
199900
+ "toolErrorBg"
199901
+ ]);
199902
+ function splitThemeColors(colors) {
198899
199903
  const fgColors = {};
198900
199904
  const bgColors = {};
198901
- const bgColorKeys = /* @__PURE__ */ new Set([
198902
- "selectedBg",
198903
- "searchMatchBg",
198904
- "userMessageBg",
198905
- "customMessageBg",
198906
- "toolPendingBg",
198907
- "toolSuccessBg",
198908
- "toolErrorBg"
198909
- ]);
198910
- for (const [key, value] of Object.entries(resolvedColors)) {
198911
- if (bgColorKeys.has(key)) {
199905
+ for (const [key, value] of Object.entries(colors)) {
199906
+ if (BACKGROUND_TOKENS.has(key)) {
198912
199907
  bgColors[key] = value;
198913
199908
  } else {
198914
199909
  fgColors[key] = value;
198915
199910
  }
198916
199911
  }
199912
+ return { fgColors, bgColors };
199913
+ }
199914
+ function createTheme(themeJson, mode, sourcePath) {
199915
+ const colorMode = mode ?? getTerminalColorMode();
199916
+ const resolvedColors = resolveThemeColors(withThemeColorFallbacks(themeJson.colors), themeJson.vars);
199917
+ const { fgColors, bgColors } = splitThemeColors(resolvedColors);
198917
199918
  return new Theme(fgColors, bgColors, colorMode, {
198918
199919
  name: themeJson.name,
198919
- sourcePath
199920
+ sourcePath,
199921
+ appearance: themeJson.appearance
199922
+ });
199923
+ }
199924
+ function createSystemTheme(mode) {
199925
+ const generated = generateSystemThemeColors({
199926
+ ...terminalColors,
199927
+ saturation: terminalColorsPending ? 0 : 1,
199928
+ appearanceHint: getTerminalTheme()
199929
+ });
199930
+ const { fgColors, bgColors } = splitThemeColors(generated.colors);
199931
+ return new Theme(fgColors, bgColors, mode ?? getTerminalColorMode(), {
199932
+ name: SYSTEM_THEME_NAME,
199933
+ appearance: generated.appearance,
199934
+ dim: generated.dim
198920
199935
  });
198921
199936
  }
198922
199937
  function loadTheme(name, mode) {
199938
+ if (name === SYSTEM_THEME_NAME)
199939
+ return createSystemTheme(mode);
198923
199940
  const registeredTheme = registeredThemes.get(name);
198924
199941
  if (registeredTheme) {
198925
199942
  return registeredTheme;
@@ -198934,6 +199951,24 @@ function getThemeByName(name) {
198934
199951
  return void 0;
198935
199952
  }
198936
199953
  }
199954
+ function detectColorFgBgTheme(env2 = process.env) {
199955
+ const bg = env2.COLORFGBG?.split(";").at(-1)?.trim();
199956
+ if (!bg || !/^\d{1,2}$/.test(bg))
199957
+ return void 0;
199958
+ const index4 = Number(bg);
199959
+ if (index4 > 15)
199960
+ return void 0;
199961
+ return index4 <= 6 || index4 === 8 ? "dark" : "light";
199962
+ }
199963
+ function detectTerminalTheme(colors = {}, reportedScheme, env2 = process.env) {
199964
+ const { background, foreground } = colors;
199965
+ if (background)
199966
+ return terminalAppearance(background, foreground);
199967
+ return reportedScheme ?? detectColorFgBgTheme(env2) ?? "dark";
199968
+ }
199969
+ function getTerminalTheme() {
199970
+ return detectTerminalTheme(terminalColors, terminalColorScheme);
199971
+ }
198937
199972
  var THEME_KEY = /* @__PURE__ */ Symbol.for("@earendil-works/pi-coding-agent:theme");
198938
199973
  var theme = new Proxy({}, {
198939
199974
  get(_target, prop) {
@@ -198955,14 +199990,19 @@ function cssBackground(ansi) {
198955
199990
  function cssColor(ansi) {
198956
199991
  return /style="(?:[^"]*;)?color:([^;"]+)/.exec(ansiLinesToHtml([`${ansi}x`]))?.[1];
198957
199992
  }
199993
+ function foregroundAnsi2(theme2, role) {
199994
+ try {
199995
+ return theme2.getFgAnsi(role);
199996
+ } catch {
199997
+ return void 0;
199998
+ }
199999
+ }
198958
200000
  function lightCounterparts(dark, light) {
198959
200001
  const pairs = /* @__PURE__ */ new Map();
198960
200002
  if (light === void 0) return pairs;
198961
- const darkColors = dark.fgColors;
198962
- const lightColors = light.fgColors;
198963
- for (const [role, ansi] of darkColors) {
198964
- const darkCss = cssColor(ansi);
198965
- const lightAnsi = lightColors.get(role);
200003
+ for (const role of Object.keys(dark.colors)) {
200004
+ const darkCss = cssColor(foregroundAnsi2(dark, role) ?? "");
200005
+ const lightAnsi = foregroundAnsi2(light, role);
198966
200006
  const lightCss = lightAnsi === void 0 ? void 0 : cssColor(lightAnsi);
198967
200007
  if (darkCss === void 0 || lightCss === void 0 || darkCss === lightCss || pairs.has(darkCss)) continue;
198968
200008
  pairs.set(darkCss, lightCss);
@@ -200608,8 +201648,8 @@ function cacheControlFor(url) {
200608
201648
  }
200609
201649
 
200610
201650
  // ../server/src/index.ts
200611
- var VERSION2 = true ? "0.32.2" : "dev";
200612
- var PI_SDK_VERSION = true ? "0.87.1" : readInstalledPiSdkVersion();
201651
+ var VERSION2 = true ? "0.32.4" : "dev";
201652
+ var PI_SDK_VERSION = true ? "0.99.2" : readInstalledPiSdkVersion();
200613
201653
  var LAUNCH_DIR = process.env.INIT_CWD ?? process.cwd();
200614
201654
  function complain(error) {
200615
201655
  const message = error instanceof Error ? error.message : String(error);
@@ -201167,7 +202207,17 @@ var makeCreateRuntime = (sandboxedTools, publishInto) => async ({ cwd, sessionMa
201167
202207
  ...config.promptPaths.length > 0 ? { additionalPromptTemplatePaths: config.promptPaths } : {},
201168
202208
  ...config.systemPrompt !== void 0 ? { systemPrompt: config.systemPrompt } : {},
201169
202209
  ...appendSystemPrompt.length > 0 ? { appendSystemPrompt } : {},
201170
- ...extraFactories.length > 0 ? { extensionFactories: extraFactories } : {}
202210
+ extensionFactories: [
202211
+ ...extraFactories,
202212
+ // The Pi CLI loads these built-ins itself; SDK sessions do not. Keep the
202213
+ // embedded runtime's extension set in step with the CLI, including MCP's
202214
+ // codemode/tool_search activation when configured servers need them.
202215
+ ...!config.noExtensions ? [
202216
+ { name: "codemode", factory: createCodemodeExtension(), replaceable: true },
202217
+ { name: "tool-search", factory: createToolSearchExtension(), replaceable: true },
202218
+ { name: "mcp", factory: createMcpExtension(), replaceable: true }
202219
+ ] : []
202220
+ ]
201171
202221
  }
201172
202222
  });
201173
202223
  const extResult = services.resourceLoader.getExtensions();