blun-king-cli 9.1.613 → 9.1.614

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/blun.mjs CHANGED
@@ -1,27 +1,28 @@
1
1
  #!/usr/bin/env node
2
- // BLUN_BUILD_INPUT_SHA256:5c7277a864ffcc0a6909494ad5ada6956f900fe23735200c5aca26b1e7d78834
2
+ // BLUN_BUILD_INPUT_SHA256:8cd22e70289533171a13424a0ac5703315b0efc0c63f381d08987a054e6e2f00
3
3
  import { fileURLToPath as __cjsShimFileURLToPath } from 'node:url';
4
4
  import { dirname as __cjsShimDirname } from 'node:path';
5
5
  const __filename = __cjsShimFileURLToPath(import.meta.url);
6
6
  const __dirname = __cjsShimDirname(__filename);
7
7
  import { createRequire } from "node:module";
8
8
  import crypto$1, { createHash, createHmac, randomBytes, randomInt, randomUUID, timingSafeEqual } from "node:crypto";
9
- import * as fs$17 from "node:fs";
9
+ import * as fs$16 from "node:fs";
10
10
  import Kt, { accessSync, appendFileSync, chmodSync, closeSync, constants, copyFileSync, createReadStream, createWriteStream, existsSync, fstatSync, fsyncSync, linkSync, lstatSync, mkdirSync, openSync, opendirSync, promises, readFileSync, readSync, readdirSync, realpathSync, renameSync, rmSync, statSync, unlinkSync, writeFileSync, writeSync } from "node:fs";
11
- import * as path$17 from "node:path";
11
+ import * as path$16 from "node:path";
12
12
  import path, { basename, dirname, extname, isAbsolute, join, normalize, parse, posix, relative, resolve, sep, win32 } from "node:path";
13
13
  import { Blob as Blob$1, Buffer as Buffer$1, File as File$1 } from "node:buffer";
14
- import fs, { access, appendFile, chmod, constants as constants$1, copyFile, cp, link, lstat, mkdir, mkdtemp, open, readFile, readdir, readlink, realpath, rename, rm, rmdir, stat, unlink, writeFile } from "node:fs/promises";
14
+ import ro, { access, appendFile, chmod, constants as constants$1, copyFile, cp, link, lstat, mkdir, mkdtemp, open, readFile, readdir, readlink, realpath, rename, rm, rmdir, stat, unlink, writeFile } from "node:fs/promises";
15
15
  import * as nodeOs from "node:os";
16
16
  import os, { arch, homedir, hostname, networkInterfaces, platform, release, tmpdir, type, userInfo } from "node:os";
17
17
  import { execFile, execFileSync, execSync, spawn, spawnSync } from "node:child_process";
18
18
  import { Worker } from "node:worker_threads";
19
19
  import * as sysPath from "path";
20
- import path$1, { basename as basename$1, dirname as dirname$1, join as join$1, parse as parse$1 } from "path";
20
+ import js, { basename as basename$1, dirname as dirname$1, join as join$1, parse as parse$1 } from "path";
21
21
  import I, { existsSync as existsSync$1, promises as promises$1, readdirSync as readdirSync$1, stat as stat$1, statSync as statSync$1, unwatchFile, watch, watchFile } from "fs";
22
22
  import { Readable } from "stream";
23
23
  import zi from "assert";
24
24
  import Qr, { EventEmitter } from "events";
25
+ import { StringDecoder } from "node:string_decoder";
25
26
  import { lstat as lstat$1, open as open$1, readdir as readdir$1, realpath as realpath$1, stat as stat$2 } from "fs/promises";
26
27
  import Cs, { PassThrough, Readable as Readable$1, Writable, pipeline } from "node:stream";
27
28
  import { homedir as homedir$1, type as type$1 } from "os";
@@ -37,7 +38,6 @@ import * as win32Path from "node:path/win32";
37
38
  import { createServer } from "node:http";
38
39
  import { pipeline as pipeline$1 } from "node:stream/promises";
39
40
  import { EventEmitter as EventEmitter$1 } from "node:events";
40
- import { StringDecoder } from "node:string_decoder";
41
41
  import co from "node:assert";
42
42
  import { fileURLToPath, pathToFileURL } from "node:url";
43
43
  import { QuickJSAsyncWASMModule, RELEASE_ASYNC, newQuickJSAsyncWASMModule, shouldInterruptAfterDeadline } from "quickjs-emscripten";
@@ -2271,11 +2271,11 @@ var init_blun_files = __esmMin((() => {
2271
2271
  async uploadVideo(input, options) {
2272
2272
  let file;
2273
2273
  if (typeof input === "string") {
2274
- if (!fs$17.existsSync(input)) throw new ChatProviderError(`Video file not found: ${input}`);
2275
- const filename = path$17.basename(input);
2274
+ if (!fs$16.existsSync(input)) throw new ChatProviderError(`Video file not found: ${input}`);
2275
+ const filename = path$16.basename(input);
2276
2276
  const mimeType = guessMimeTypeFromExt(filename);
2277
2277
  if (mimeType === void 0 || !mimeType.startsWith("video/")) throw new ChatProviderError(`BlunFiles.uploadVideo: file extension does not indicate a video type: ${filename}`);
2278
- const data = await fs$17.promises.readFile(input);
2278
+ const data = await fs$16.promises.readFile(input);
2279
2279
  file = new File$1([new Blob$1([new Uint8Array(data)], { type: mimeType })], filename, { type: mimeType });
2280
2280
  } else {
2281
2281
  if (!input.mimeType.startsWith("video/")) throw new ChatProviderError(`Expected a video mime type, got ${input.mimeType}`);
@@ -2658,12 +2658,22 @@ function collectBlunVisionAttachments(messages) {
2658
2658
  }
2659
2659
  return attachments;
2660
2660
  }
2661
- function estimateBlunRequestExtraBytes(tools, messages) {
2662
- const attachments = collectBlunVisionAttachments(messages);
2663
- return {
2664
- toolsBytes: tools.length === 0 ? 0 : Buffer.byteLength(JSON.stringify({ tools: tools.map(convertTool) }), "utf8"),
2665
- visionBytes: attachments.length === 0 ? 0 : Buffer.byteLength(JSON.stringify({ visionAttachments: attachments }), "utf8")
2666
- };
2661
+ function estimateBlunSerializedBodyBytes(systemPrompt, tools, history) {
2662
+ const normalizedHistory = normalizeToolCallIdsForProvider([...history], BLUN_TOOL_CALL_ID_POLICY);
2663
+ const messages = systemPrompt ? [{
2664
+ role: "system",
2665
+ content: systemPrompt
2666
+ }] : [];
2667
+ for (const message of normalizedHistory) if (!isEmptyAssistantHistoryMessage(message)) messages.push(convertMessage(message));
2668
+ const attachments = collectBlunVisionAttachments(normalizedHistory);
2669
+ return Buffer.byteLength(JSON.stringify({
2670
+ model: "king",
2671
+ messages,
2672
+ stream: true,
2673
+ ...tools.length > 0 ? { tools: tools.map(convertTool) } : {},
2674
+ ...attachments.length > 0 ? { visionAttachments: attachments } : {},
2675
+ stream_options: { include_usage: true }
2676
+ }), "utf8");
2667
2677
  }
2668
2678
  function convertMessage(message) {
2669
2679
  let reasoningContent = "";
@@ -11949,7 +11959,7 @@ var require_clone$1 = /* @__PURE__ */ __commonJSMin(((exports, module) => {
11949
11959
  //#endregion
11950
11960
  //#region ../../node_modules/.pnpm/graceful-fs@4.2.11/node_modules/graceful-fs/graceful-fs.js
11951
11961
  var require_graceful_fs = /* @__PURE__ */ __commonJSMin(((exports, module) => {
11952
- var fs$16 = __require("fs");
11962
+ var fs$15 = __require("fs");
11953
11963
  var polyfills = require_polyfills();
11954
11964
  var legacy = require_legacy_streams();
11955
11965
  var clone = require_clone$1();
@@ -11978,36 +11988,36 @@ var require_graceful_fs = /* @__PURE__ */ __commonJSMin(((exports, module) => {
11978
11988
  m = "GFS4: " + m.split(/\n/).join("\nGFS4: ");
11979
11989
  console.error(m);
11980
11990
  };
11981
- if (!fs$16[gracefulQueue]) {
11982
- publishQueue(fs$16, global[gracefulQueue] || []);
11983
- fs$16.close = (function(fs$close) {
11991
+ if (!fs$15[gracefulQueue]) {
11992
+ publishQueue(fs$15, global[gracefulQueue] || []);
11993
+ fs$15.close = (function(fs$close) {
11984
11994
  function close(fd, cb) {
11985
- return fs$close.call(fs$16, fd, function(err) {
11995
+ return fs$close.call(fs$15, fd, function(err) {
11986
11996
  if (!err) resetQueue();
11987
11997
  if (typeof cb === "function") cb.apply(this, arguments);
11988
11998
  });
11989
11999
  }
11990
12000
  Object.defineProperty(close, previousSymbol, { value: fs$close });
11991
12001
  return close;
11992
- })(fs$16.close);
11993
- fs$16.closeSync = (function(fs$closeSync) {
12002
+ })(fs$15.close);
12003
+ fs$15.closeSync = (function(fs$closeSync) {
11994
12004
  function closeSync(fd) {
11995
- fs$closeSync.apply(fs$16, arguments);
12005
+ fs$closeSync.apply(fs$15, arguments);
11996
12006
  resetQueue();
11997
12007
  }
11998
12008
  Object.defineProperty(closeSync, previousSymbol, { value: fs$closeSync });
11999
12009
  return closeSync;
12000
- })(fs$16.closeSync);
12010
+ })(fs$15.closeSync);
12001
12011
  if (/\bgfs4\b/i.test(process.env.NODE_DEBUG || "")) process.on("exit", function() {
12002
- debug(fs$16[gracefulQueue]);
12003
- __require("assert").equal(fs$16[gracefulQueue].length, 0);
12012
+ debug(fs$15[gracefulQueue]);
12013
+ __require("assert").equal(fs$15[gracefulQueue].length, 0);
12004
12014
  });
12005
12015
  }
12006
- if (!global[gracefulQueue]) publishQueue(global, fs$16[gracefulQueue]);
12007
- module.exports = patch(clone(fs$16));
12008
- if (process.env.TEST_GRACEFUL_FS_GLOBAL_PATCH && !fs$16.__patched) {
12009
- module.exports = patch(fs$16);
12010
- fs$16.__patched = true;
12016
+ if (!global[gracefulQueue]) publishQueue(global, fs$15[gracefulQueue]);
12017
+ module.exports = patch(clone(fs$15));
12018
+ if (process.env.TEST_GRACEFUL_FS_GLOBAL_PATCH && !fs$15.__patched) {
12019
+ module.exports = patch(fs$15);
12020
+ fs$15.__patched = true;
12011
12021
  }
12012
12022
  function patch(fs) {
12013
12023
  polyfills(fs);
@@ -12262,23 +12272,23 @@ var require_graceful_fs = /* @__PURE__ */ __commonJSMin(((exports, module) => {
12262
12272
  }
12263
12273
  function enqueue(elem) {
12264
12274
  debug("ENQUEUE", elem[0].name, elem[1]);
12265
- fs$16[gracefulQueue].push(elem);
12275
+ fs$15[gracefulQueue].push(elem);
12266
12276
  retry();
12267
12277
  }
12268
12278
  var retryTimer;
12269
12279
  function resetQueue() {
12270
12280
  var now = Date.now();
12271
- for (var i = 0; i < fs$16[gracefulQueue].length; ++i) if (fs$16[gracefulQueue][i].length > 2) {
12272
- fs$16[gracefulQueue][i][3] = now;
12273
- fs$16[gracefulQueue][i][4] = now;
12281
+ for (var i = 0; i < fs$15[gracefulQueue].length; ++i) if (fs$15[gracefulQueue][i].length > 2) {
12282
+ fs$15[gracefulQueue][i][3] = now;
12283
+ fs$15[gracefulQueue][i][4] = now;
12274
12284
  }
12275
12285
  retry();
12276
12286
  }
12277
12287
  function retry() {
12278
12288
  clearTimeout(retryTimer);
12279
12289
  retryTimer = void 0;
12280
- if (fs$16[gracefulQueue].length === 0) return;
12281
- var elem = fs$16[gracefulQueue].shift();
12290
+ if (fs$15[gracefulQueue].length === 0) return;
12291
+ var elem = fs$15[gracefulQueue].shift();
12282
12292
  var fn = elem[0];
12283
12293
  var args = elem[1];
12284
12294
  var err = elem[2];
@@ -12297,7 +12307,7 @@ var require_graceful_fs = /* @__PURE__ */ __commonJSMin(((exports, module) => {
12297
12307
  if (sinceAttempt >= Math.min(sinceStart * 1.2, 100)) {
12298
12308
  debug("RETRY", fn.name, args);
12299
12309
  fn.apply(null, args.concat([startTime]));
12300
- } else fs$16[gracefulQueue].push(elem);
12310
+ } else fs$15[gracefulQueue].push(elem);
12301
12311
  }
12302
12312
  if (retryTimer === void 0) retryTimer = setTimeout(retry, 0);
12303
12313
  }
@@ -12649,7 +12659,7 @@ var require_mtime_precision = /* @__PURE__ */ __commonJSMin(((exports, module) =
12649
12659
  //#endregion
12650
12660
  //#region ../../node_modules/.pnpm/proper-lockfile@4.1.2/node_modules/proper-lockfile/lib/lockfile.js
12651
12661
  var require_lockfile = /* @__PURE__ */ __commonJSMin(((exports, module) => {
12652
- const path$16 = __require("path");
12662
+ const path$15 = __require("path");
12653
12663
  const fs = require_graceful_fs();
12654
12664
  const retry = require_retry$3();
12655
12665
  const onExit = require_signal_exit();
@@ -12659,7 +12669,7 @@ var require_lockfile = /* @__PURE__ */ __commonJSMin(((exports, module) => {
12659
12669
  return options.lockfilePath || `${file}.lock`;
12660
12670
  }
12661
12671
  function resolveCanonicalPath(file, options, callback) {
12662
- if (!options.realpath) return callback(null, path$16.resolve(file));
12672
+ if (!options.realpath) return callback(null, path$15.resolve(file));
12663
12673
  options.fs.realpath(file, callback);
12664
12674
  }
12665
12675
  function acquireLock(file, options, callback) {
@@ -15175,7 +15185,7 @@ async function syncDir(dirPath) {
15175
15185
  */
15176
15186
  function syncFd(fd) {
15177
15187
  return new Promise((resolve, reject) => {
15178
- fs$17.fsync(fd, (err) => {
15188
+ fs$16.fsync(fd, (err) => {
15179
15189
  if (err) {
15180
15190
  reject(err);
15181
15191
  return;
@@ -22286,6 +22296,31 @@ var init_instruction_provenance = __esmMin((() => {
22286
22296
  get content() {
22287
22297
  return this.pieces.map((piece) => piece.text).join("");
22288
22298
  }
22299
+ prefixUtf8(maxBytes) {
22300
+ if (!Number.isSafeInteger(maxBytes) || maxBytes < 0) throw new RangeError("Invalid instruction byte budget");
22301
+ const kept = [];
22302
+ let remaining = maxBytes;
22303
+ let totalBytes = 0;
22304
+ let readBytes = 0;
22305
+ for (const piece of this.pieces) {
22306
+ const encoded = Buffer.from(piece.text, "utf8");
22307
+ totalBytes += encoded.length;
22308
+ if (remaining <= 0) continue;
22309
+ const content = encoded.length <= remaining ? piece.text : new StringDecoder("utf8").write(encoded.subarray(0, remaining));
22310
+ const bytes = Buffer.byteLength(content, "utf8");
22311
+ if (content.length > 0) kept.push({
22312
+ ...piece,
22313
+ text: content
22314
+ });
22315
+ readBytes += bytes;
22316
+ remaining -= bytes;
22317
+ if (bytes < encoded.length) remaining = 0;
22318
+ }
22319
+ return {
22320
+ text: new InstructionText(kept, new Map(this.sources)),
22321
+ omittedBytes: totalBytes - readBytes
22322
+ };
22323
+ }
22289
22324
  replaceFirst(needle, replacement) {
22290
22325
  const start = this.content.indexOf(needle);
22291
22326
  if (start >= 0) this.replaceRange(start, start + needle.length, replacement);
@@ -22339,6 +22374,64 @@ var init_instruction_provenance = __esmMin((() => {
22339
22374
  }));
22340
22375
  //#endregion
22341
22376
  //#region ../../packages/agent-core/src/profile/context.ts
22377
+ function fitAgentsMdContext(context, maxFixedRequestBytes, measureFixedRequestBytes) {
22378
+ if (!Number.isSafeInteger(maxFixedRequestBytes) || maxFixedRequestBytes <= 0) throw new RangeError("Invalid fixed request byte budget");
22379
+ const originalBytes = measureFixedRequestBytes(context);
22380
+ if (originalBytes <= maxFixedRequestBytes) return {
22381
+ context,
22382
+ fixedRequestBytes: originalBytes,
22383
+ omittedBytes: 0,
22384
+ fits: true
22385
+ };
22386
+ const source = context.agentsMdText;
22387
+ if (source === void 0) return {
22388
+ context,
22389
+ fixedRequestBytes: originalBytes,
22390
+ omittedBytes: 0,
22391
+ fits: false
22392
+ };
22393
+ const totalBytes = source.measure().totalBytes;
22394
+ const candidateAt = (maxBytes) => {
22395
+ const { text } = source.prefixUtf8(maxBytes);
22396
+ return {
22397
+ ...context,
22398
+ agentsMd: text.content,
22399
+ agentsMdSources: text.measure(),
22400
+ agentsMdText: text
22401
+ };
22402
+ };
22403
+ let low = 0;
22404
+ let high = totalBytes;
22405
+ let fitted = candidateAt(0);
22406
+ let fittedBytes = measureFixedRequestBytes(fitted);
22407
+ if (fittedBytes > maxFixedRequestBytes) {
22408
+ const omittedBytes = context.agentsMdSources?.files.reduce((sum, file) => sum + file.bytes, 0) ?? totalBytes;
22409
+ return {
22410
+ context: fitted,
22411
+ fixedRequestBytes: fittedBytes,
22412
+ omittedBytes,
22413
+ fits: false
22414
+ };
22415
+ }
22416
+ while (low < high) {
22417
+ const middle = Math.ceil((low + high) / 2);
22418
+ const candidate = candidateAt(middle);
22419
+ const bytes = measureFixedRequestBytes(candidate);
22420
+ if (bytes <= maxFixedRequestBytes) {
22421
+ low = middle;
22422
+ fitted = candidate;
22423
+ fittedBytes = bytes;
22424
+ } else high = middle - 1;
22425
+ }
22426
+ const omittedBytes = context.agentsMdSources?.files.reduce((sum, file) => sum + file.bytes, 0) ?? totalBytes;
22427
+ const retainedBytes = fitted.agentsMdSources?.files.reduce((sum, file) => sum + file.bytes, 0) ?? 0;
22428
+ return {
22429
+ context: fitted,
22430
+ fixedRequestBytes: fittedBytes,
22431
+ omittedBytes: omittedBytes - retainedBytes,
22432
+ fits: true
22433
+ };
22434
+ }
22342
22435
  async function prepareSystemPromptContext(kaos, brandHome, options) {
22343
22436
  const additionalDirs = normalizeAdditionalDirs(options?.additionalDirs ?? []);
22344
22437
  const [cwdListing, agentsMdResult, additionalDirsInfo] = await Promise.all([
@@ -22351,7 +22444,8 @@ async function prepareSystemPromptContext(kaos, brandHome, options) {
22351
22444
  agentsMd: agentsMdResult.content,
22352
22445
  additionalDirsInfo,
22353
22446
  agentsMdWarning: agentsMdResult.warning,
22354
- agentsMdSources: agentsMdResult.sources
22447
+ agentsMdSources: agentsMdResult.sources,
22448
+ agentsMdText: agentsMdResult.text
22355
22449
  };
22356
22450
  }
22357
22451
  async function loadAgentsMd(kaos, brandHome) {
@@ -22405,6 +22499,7 @@ async function loadAgentsMdForRoots(kaos, brandHome, workDirs) {
22405
22499
  return {
22406
22500
  content,
22407
22501
  warning: totalBytes > AGENTS_MD_RECOMMENDED_MAX_BYTES ? `AGENTS.md total ${formatKB(totalBytes)} KB exceeds the recommended ${formatKB(AGENTS_MD_RECOMMENDED_MAX_BYTES)} KB. Large instruction files increase cost and may impact performance; consider trimming.` : void 0,
22502
+ text: rendered,
22408
22503
  sources: {
22409
22504
  ...rendered.measure(),
22410
22505
  ...notLoadedCandidates.size === 0 ? {} : { notLoadedCandidates: [...notLoadedCandidates] }
@@ -26140,7 +26235,7 @@ var require_loader = /* @__PURE__ */ __commonJSMin(((exports, module) => {
26140
26235
  };
26141
26236
  return _setPrototypeOf(o, p);
26142
26237
  }
26143
- var path$15 = __require("path");
26238
+ var path$14 = __require("path");
26144
26239
  module.exports = /* @__PURE__ */ function(_EmitterObj) {
26145
26240
  _inheritsLoose(Loader, _EmitterObj);
26146
26241
  function Loader() {
@@ -26148,7 +26243,7 @@ var require_loader = /* @__PURE__ */ __commonJSMin(((exports, module) => {
26148
26243
  }
26149
26244
  var _proto = Loader.prototype;
26150
26245
  _proto.resolve = function resolve(from, to) {
26151
- return path$15.resolve(path$15.dirname(from), to);
26246
+ return path$14.resolve(path$14.dirname(from), to);
26152
26247
  };
26153
26248
  _proto.isRelative = function isRelative(filename) {
26154
26249
  return filename.indexOf("./") === 0 || filename.indexOf("../") === 0;
@@ -27804,8 +27899,8 @@ var require_node_loaders = /* @__PURE__ */ __commonJSMin(((exports, module) => {
27804
27899
  };
27805
27900
  return _setPrototypeOf(o, p);
27806
27901
  }
27807
- var fs$15 = __require("fs");
27808
- var path$14 = __require("path");
27902
+ var fs$14 = __require("fs");
27903
+ var path$13 = __require("path");
27809
27904
  var Loader = require_loader();
27810
27905
  var PrecompiledLoader = require_precompiled_loader().PrecompiledLoader;
27811
27906
  var chokidar;
@@ -27820,7 +27915,7 @@ var require_node_loaders = /* @__PURE__ */ __commonJSMin(((exports, module) => {
27820
27915
  _this.noCache = !!opts.noCache;
27821
27916
  if (searchPaths) {
27822
27917
  searchPaths = Array.isArray(searchPaths) ? searchPaths : [searchPaths];
27823
- _this.searchPaths = searchPaths.map(path$14.normalize);
27918
+ _this.searchPaths = searchPaths.map(path$13.normalize);
27824
27919
  } else _this.searchPaths = ["."];
27825
27920
  if (opts.watch) {
27826
27921
  try {
@@ -27828,10 +27923,10 @@ var require_node_loaders = /* @__PURE__ */ __commonJSMin(((exports, module) => {
27828
27923
  } catch (e) {
27829
27924
  throw new Error("watch requires chokidar to be installed");
27830
27925
  }
27831
- var paths = _this.searchPaths.filter(fs$15.existsSync);
27926
+ var paths = _this.searchPaths.filter(fs$14.existsSync);
27832
27927
  var watcher = chokidar.watch(paths);
27833
27928
  watcher.on("all", function(event, fullname) {
27834
- fullname = path$14.resolve(fullname);
27929
+ fullname = path$13.resolve(fullname);
27835
27930
  if (event === "change" && fullname in _this.pathsToNames) _this.emit("update", _this.pathsToNames[fullname], fullname);
27836
27931
  });
27837
27932
  watcher.on("error", function(error) {
@@ -27845,9 +27940,9 @@ var require_node_loaders = /* @__PURE__ */ __commonJSMin(((exports, module) => {
27845
27940
  var fullpath = null;
27846
27941
  var paths = this.searchPaths;
27847
27942
  for (var i = 0; i < paths.length; i++) {
27848
- var basePath = path$14.resolve(paths[i]);
27849
- var p = path$14.resolve(paths[i], name);
27850
- if (p.indexOf(basePath) === 0 && fs$15.existsSync(p)) {
27943
+ var basePath = path$13.resolve(paths[i]);
27944
+ var p = path$13.resolve(paths[i], name);
27945
+ if (p.indexOf(basePath) === 0 && fs$14.existsSync(p)) {
27851
27946
  fullpath = p;
27852
27947
  break;
27853
27948
  }
@@ -27855,7 +27950,7 @@ var require_node_loaders = /* @__PURE__ */ __commonJSMin(((exports, module) => {
27855
27950
  if (!fullpath) return null;
27856
27951
  this.pathsToNames[fullpath] = name;
27857
27952
  var source = {
27858
- src: fs$15.readFileSync(fullpath, "utf-8"),
27953
+ src: fs$14.readFileSync(fullpath, "utf-8"),
27859
27954
  path: fullpath,
27860
27955
  noCache: this.noCache
27861
27956
  };
@@ -27903,7 +27998,7 @@ var require_node_loaders = /* @__PURE__ */ __commonJSMin(((exports, module) => {
27903
27998
  }
27904
27999
  this.pathsToNames[fullpath] = name;
27905
28000
  var source = {
27906
- src: fs$15.readFileSync(fullpath, "utf-8"),
28001
+ src: fs$14.readFileSync(fullpath, "utf-8"),
27907
28002
  path: fullpath,
27908
28003
  noCache: this.noCache
27909
28004
  };
@@ -28205,13 +28300,13 @@ var require_globals = /* @__PURE__ */ __commonJSMin(((exports, module) => {
28205
28300
  //#endregion
28206
28301
  //#region ../../node_modules/.pnpm/nunjucks@3.2.4_chokidar@4.0.3/node_modules/nunjucks/src/express-app.js
28207
28302
  var require_express_app = /* @__PURE__ */ __commonJSMin(((exports, module) => {
28208
- var path$13 = __require("path");
28303
+ var path$12 = __require("path");
28209
28304
  module.exports = function express(env, app) {
28210
28305
  function NunjucksView(name, opts) {
28211
28306
  this.name = name;
28212
28307
  this.path = name;
28213
28308
  this.defaultEngine = opts.defaultEngine;
28214
- this.ext = path$13.extname(name);
28309
+ this.ext = path$12.extname(name);
28215
28310
  if (!this.ext && !this.defaultEngine) throw new Error("No default engine was specified and no extension was provided.");
28216
28311
  if (!this.ext) this.name += this.ext = (this.defaultEngine[0] !== "." ? "." : "") + this.defaultEngine;
28217
28312
  }
@@ -28647,8 +28742,8 @@ var require_precompile_global = /* @__PURE__ */ __commonJSMin(((exports, module)
28647
28742
  //#endregion
28648
28743
  //#region ../../node_modules/.pnpm/nunjucks@3.2.4_chokidar@4.0.3/node_modules/nunjucks/src/precompile.js
28649
28744
  var require_precompile = /* @__PURE__ */ __commonJSMin(((exports, module) => {
28650
- var fs$14 = __require("fs");
28651
- var path$12 = __require("path");
28745
+ var fs$13 = __require("fs");
28746
+ var path$11 = __require("path");
28652
28747
  var _prettifyError = require_lib$8()._prettifyError;
28653
28748
  var compiler = require_compiler();
28654
28749
  var Environment = require_environment().Environment;
@@ -28672,27 +28767,27 @@ var require_precompile = /* @__PURE__ */ __commonJSMin(((exports, module) => {
28672
28767
  var env = opts.env || new Environment([]);
28673
28768
  var wrapper = opts.wrapper || precompileGlobal;
28674
28769
  if (opts.isString) return precompileString(input, opts);
28675
- var pathStats = fs$14.existsSync(input) && fs$14.statSync(input);
28770
+ var pathStats = fs$13.existsSync(input) && fs$13.statSync(input);
28676
28771
  var precompiled = [];
28677
28772
  var templates = [];
28678
28773
  function addTemplates(dir) {
28679
- fs$14.readdirSync(dir).forEach(function(file) {
28680
- var filepath = path$12.join(dir, file);
28681
- var subpath = filepath.substr(path$12.join(input, "/").length);
28682
- var stat = fs$14.statSync(filepath);
28774
+ fs$13.readdirSync(dir).forEach(function(file) {
28775
+ var filepath = path$11.join(dir, file);
28776
+ var subpath = filepath.substr(path$11.join(input, "/").length);
28777
+ var stat = fs$13.statSync(filepath);
28683
28778
  if (stat && stat.isDirectory()) {
28684
28779
  subpath += "/";
28685
28780
  if (!match(subpath, opts.exclude)) addTemplates(filepath);
28686
28781
  } else if (match(subpath, opts.include)) templates.push(filepath);
28687
28782
  });
28688
28783
  }
28689
- if (pathStats.isFile()) precompiled.push(_precompile(fs$14.readFileSync(input, "utf-8"), opts.name || input, env));
28784
+ if (pathStats.isFile()) precompiled.push(_precompile(fs$13.readFileSync(input, "utf-8"), opts.name || input, env));
28690
28785
  else if (pathStats.isDirectory()) {
28691
28786
  addTemplates(input);
28692
28787
  for (var i = 0; i < templates.length; i++) {
28693
- var name = templates[i].replace(path$12.join(input, "/"), "");
28788
+ var name = templates[i].replace(path$11.join(input, "/"), "");
28694
28789
  try {
28695
- precompiled.push(_precompile(fs$14.readFileSync(templates[i], "utf-8"), name, env));
28790
+ precompiled.push(_precompile(fs$13.readFileSync(templates[i], "utf-8"), name, env));
28696
28791
  } catch (e) {
28697
28792
  if (opts.force) console.error(e);
28698
28793
  else throw e;
@@ -32733,7 +32828,7 @@ var require_buffer_from = /* @__PURE__ */ __commonJSMin(((exports, module) => {
32733
32828
  //#region ../../node_modules/.pnpm/source-map-support@0.5.21/node_modules/source-map-support/source-map-support.js
32734
32829
  var require_source_map_support = /* @__PURE__ */ __commonJSMin(((exports, module) => {
32735
32830
  var SourceMapConsumer = require_source_map().SourceMapConsumer;
32736
- var path$11 = __require("path");
32831
+ var path$10 = __require("path");
32737
32832
  var fs;
32738
32833
  try {
32739
32834
  fs = __require("fs");
@@ -32810,15 +32905,15 @@ var require_source_map_support = /* @__PURE__ */ __commonJSMin(((exports, module
32810
32905
  });
32811
32906
  function supportRelativeURL(file, url) {
32812
32907
  if (!file) return url;
32813
- var dir = path$11.dirname(file);
32908
+ var dir = path$10.dirname(file);
32814
32909
  var match = /^\w+:\/\/[^\/]*/.exec(dir);
32815
32910
  var protocol = match ? match[0] : "";
32816
32911
  var startPath = dir.slice(protocol.length);
32817
32912
  if (protocol && /^\/\w\:/.test(startPath)) {
32818
32913
  protocol += "/";
32819
- return protocol + path$11.resolve(dir.slice(protocol.length), url).replace(/\\/g, "/");
32914
+ return protocol + path$10.resolve(dir.slice(protocol.length), url).replace(/\\/g, "/");
32820
32915
  }
32821
- return protocol + path$11.resolve(dir.slice(protocol.length), url);
32916
+ return protocol + path$10.resolve(dir.slice(protocol.length), url);
32822
32917
  }
32823
32918
  function retrieveSourceMapURL(source) {
32824
32919
  var fileData;
@@ -192061,7 +192156,7 @@ var require_gifframe = /* @__PURE__ */ __commonJSMin(((exports) => {
192061
192156
  //#region ../../node_modules/.pnpm/gifwrap@0.10.1/node_modules/gifwrap/src/gifutil.js
192062
192157
  var require_gifutil = /* @__PURE__ */ __commonJSMin(((exports) => {
192063
192158
  /** @namespace GifUtil */
192064
- const fs$13 = __require("fs");
192159
+ const fs$12 = __require("fs");
192065
192160
  const ImageQ = require_image_q();
192066
192161
  const BitmapImage = require_bitmapimage();
192067
192162
  const { GifFrame } = require_gifframe();
@@ -192328,7 +192423,7 @@ var require_gifutil = /* @__PURE__ */ __commonJSMin(((exports) => {
192328
192423
  }
192329
192424
  function _readBinary(path) {
192330
192425
  return new Promise((resolve, reject) => {
192331
- fs$13.readFile(path, (err, buffer) => {
192426
+ fs$12.readFile(path, (err, buffer) => {
192332
192427
  if (err) return reject(err);
192333
192428
  return resolve(buffer);
192334
192429
  });
@@ -192336,7 +192431,7 @@ var require_gifutil = /* @__PURE__ */ __commonJSMin(((exports) => {
192336
192431
  }
192337
192432
  function _writeBinary(path, buffer) {
192338
192433
  return new Promise((resolve, reject) => {
192339
- fs$13.writeFile(path, buffer, (err) => {
192434
+ fs$12.writeFile(path, buffer, (err) => {
192340
192435
  if (err) return reject(err);
192341
192436
  return resolve();
192342
192437
  });
@@ -218154,7 +218249,7 @@ var init_file_type = __esmMin((() => {
218154
218249
  }
218155
218250
  async fromFile(path) {
218156
218251
  this.options.signal?.throwIfAborted();
218157
- const fileHandle = await fs.open(path, constants.O_RDONLY | constants.O_NONBLOCK);
218252
+ const fileHandle = await ro.open(path, constants.O_RDONLY | constants.O_NONBLOCK);
218158
218253
  const fileStat = await fileHandle.stat();
218159
218254
  if (!fileStat.isFile()) {
218160
218255
  await fileHandle.close();
@@ -228659,7 +228754,7 @@ async function processBitmapFont(file, font) {
228659
228754
  ...font,
228660
228755
  chars,
228661
228756
  kernings,
228662
- pages: await Promise.all(font.pages.map(async (page) => CharacterJimp.read(path$1.join(path$1.dirname(file), page))))
228757
+ pages: await Promise.all(font.pages.map(async (page) => CharacterJimp.read(js.join(js.dirname(file), page))))
228663
228758
  };
228664
228759
  }
228665
228760
  var import_parse_bmfont_ascii, import_lib$1, import_parse_bmfont_binary, convertXML, isWebWorker, CharacterJimp, HEADER;
@@ -230997,7 +231092,7 @@ var init_full = __esmMin((() => {
230997
231092
  MAX_SESSION_COMPACTION_FAILURES = 2;
230998
231093
  DEFAULT_COMPACTION_MAX_COMPLETION_TOKENS = 128 * 1024;
230999
231094
  COMPACTION_SUMMARY_RESERVE_RATIO = .1;
231000
- BLUN_COMPACTION_REQUEST_BUDGET_BYTES = 75e4;
231095
+ BLUN_COMPACTION_REQUEST_BUDGET_BYTES = 48e4;
231001
231096
  MAX_HIERARCHICAL_COMPACTION_PASSES = 64;
231002
231097
  HIERARCHICAL_COMPACTION_PREFIX = "This is a complete summary of an earlier chronological segment. Preserve it as source material when merging it with the following conversation:";
231003
231098
  CompactionTruncatedError = class extends Error {
@@ -231153,26 +231248,10 @@ var init_full = __esmMin((() => {
231153
231248
  const model = this.agent.activeResponderModel ?? this.agent.config.modelAlias;
231154
231249
  if (model === void 0 || this.agent.config.runtimeModel(model).provider.name !== "blun") return void 0;
231155
231250
  const systemPrompt = context.systemPrompt ?? this.agent.effectiveSystemPrompt;
231156
- const tools = (context.tools ?? this.agent.tools.loopTools).map((tool) => ({
231157
- name: tool.name,
231158
- description: tool.description,
231159
- parameters: tool.parameters
231160
- }));
231161
- let extraBytes;
231162
- try {
231163
- extraBytes = estimateBlunRequestExtraBytes(tools, messages);
231164
- } catch {
231165
- return;
231166
- }
231167
- if (Buffer.byteLength(JSON.stringify({
231168
- systemPrompt,
231169
- messages: []
231170
- }), "utf8") >= BLUN_COMPACTION_REQUEST_BUDGET_BYTES) return void 0;
231251
+ const tools = context.tools ?? this.agent.tools.loopTools;
231252
+ if (estimateBlunSerializedBodyBytes(systemPrompt, [], []) + 4096 >= BLUN_COMPACTION_REQUEST_BUDGET_BYTES) return void 0;
231171
231253
  return {
231172
- usedRequestBytesEstimate: Buffer.byteLength(JSON.stringify({
231173
- systemPrompt,
231174
- messages
231175
- }), "utf8") + extraBytes.toolsBytes + extraBytes.visionBytes,
231254
+ usedRequestBytesEstimate: estimateBlunSerializedBodyBytes(systemPrompt, tools, messages) + 4096,
231176
231255
  thresholdRequestBytes: BLUN_COMPACTION_REQUEST_BUDGET_BYTES
231177
231256
  };
231178
231257
  }
@@ -231527,10 +231606,7 @@ var init_full = __esmMin((() => {
231527
231606
  dropOrphanResults: true
231528
231607
  }), createUserMessage(requestInstruction)], capability));
231529
231608
  };
231530
- const estimateRequestBytes = (messages) => Buffer.byteLength(JSON.stringify({
231531
- systemPrompt: this.agent.effectiveSystemPrompt,
231532
- messages
231533
- }), "utf8");
231609
+ const estimateRequestBytes = (messages) => estimateBlunSerializedBodyBytes(this.agent.effectiveSystemPrompt, compactionTools, messages) + 4096;
231534
231610
  while (true) {
231535
231611
  signal.throwIfAborted();
231536
231612
  if (hierarchicalPassCount >= MAX_HIERARCHICAL_COMPACTION_PASSES) throw new BlunError(ErrorCodes.COMPACTION_FAILED, `Compaction stopped after ${String(MAX_HIERARCHICAL_COMPACTION_PASSES)} staged requests without reaching a final summary. The conversation history was not changed.`, { details: {
@@ -259338,7 +259414,7 @@ function Yn(s, t) {
259338
259414
  function Kn(s, t) {
259339
259415
  s.head = new ue$1(t, void 0, s.head, s), s.tail || (s.tail = s.head), s.length++;
259340
259416
  }
259341
- var zr, Ur, Ds, Wr, Gr, Zr, Q$1, J$1, nt$1, De$1, qt, Ne$1, Ns, Ae$1, As, z$1, Mt, g$1, Qt, Bt, b$1, N$1, _$1, bi, Ie$1, L$1, S, _i, Oi, Is, Ti, Z$1, xi, Ce$1, Jt$1, Rt, C, jt, Yr, Kr, Vr, $r, Fe$1, Li, Xr, qr, A$1, Jr, ht, H$1, te, m$1, Ni, tt$1, Ai, ki, vi, ie$1, ke$1, Ut$1, Ht, Ii, Pt, at, U$1, ot, Y$1, zt, Ci, j$1, ee$1, Fi, ve$1, gt$2, Me, bt, _t, Be$1, et$1, Wt$1, jr, Fs, ks, vs, Ms, Bs, tn, se$1, K$1, sn, M$1, rn, zs, nn, Bi, Tt, Gt, Pi, re, Pe$1, ze$1, Ue, He$1, We$1, Ge$1, Ze$1, Ye$1, Ke$1, Us, hn, an, Hs, ln, cn, Ws, Gs, Hi, ne, dn, Ui, oe$1, Ve$1, un, F$1, mn, xt, Wi, pn, lt, En, wn, Sn, ct, yn, Rn, gn, Gi, bn, Lt, ft, On, Tn, xn, f, $e$1, Dt, Nn, Xi, qi, An, B$1, Nt, it, Zi, Zs, V$1, he$1, dt, Ys, p, st$1, ut, Yi, At, w$1, Xe$1, qe$1, Ki, Ks, Vs, ae$1, Vi, Qe$1, Yt$1, $$1, Je$1, It, je$1, ti, $s, In, le$1, $i, Xs, Cn, rt$1, mt, vn, Qi, Mn, Bn, Ct, Ji, zn, qs, ce$1, ei, ji, Un, Hn, ts, Qs, rr, Wn, tr, er, ir, is$2, sr, fe$1, ii, ss, si, rs, ns, os$6, hs, pt, ri, as, es, q$1, de$1, ni, oi, Gn, hi, ue$1, pi, nr, li, me$1, W$1, pe$2, Et, Ft$1, Ee$1, ai, G, ls, ci, or, ds, us, fi, di, hr, cs, ui, lr, fs$12, wt, kt, Vn, $n, fr, dr, Xn, qn, Er, wr, ur, Sr, yr, Rr, jn, to, eo, mr, ms, ps, Ei, io, Es, so, ws, Se$1, St, no, gr, Ss, br, oo, _r, ys, Or, Vt$1, Tr, ao, lo, yi, Lr, Dr, _s, Nr, Os, P$1, Ts, xs, gi, Ar, Ir, Re, Cr, Fr, Rs, yt, O$1, Ri, kr, $t, gs, bs, Ls, ge$1, be, _e$1, Oe$1, Te$1, uo, mo, po, vr, Xt$1, ye$1, xe$1, Eo, wo, So, yo, Ro, go, bo, _o, vt, To;
259417
+ var zr, Ur, Ds, Wr, Gr, Zr, Q$1, J$1, nt$1, De$1, qt, Ne$1, Ns, Ae$1, As, z$1, Mt, g$1, Qt, Bt, b$1, N$1, _$1, bi, Ie$1, L$1, S, _i, Oi, Is, Ti, Z$1, xi, Ce$1, Jt$1, Rt, C, jt, Yr, Kr, Vr, $r, Fe$1, Li, Xr, qr, A$1, Jr, ht, H$1, te, m$1, Ni, tt$1, Ai, ki, vi, ie$1, ke$1, Ut$1, Ht, Ii, Pt, at, U$1, ot, Y$1, zt, Ci, j$1, ee$1, Fi, ve$1, gt$2, Me, bt, _t, Be$1, et$1, Wt$1, jr, Fs, ks, vs, Ms, Bs, tn, se$1, K$1, sn, M$1, rn, zs, nn, Bi, Tt, Gt, Pi, re, Pe$1, ze$1, Ue, He$1, We$1, Ge$1, Ze$1, Ye$1, Ke$1, Us, hn, an, Hs, ln, cn, Ws, Gs, Hi, ne, dn, Ui, oe$1, Ve$1, un, F$1, mn, xt, Wi, pn, lt, En, wn, Sn, ct, yn, Rn, gn, Gi, bn, Lt, ft, On, Tn, xn, f, $e$1, Dt, Nn, Xi, qi, An, B$1, Nt, it, Zi, Zs, V$1, he$1, dt, Ys, p, st$1, ut, Yi, At, w$1, Xe$1, qe$1, Ki, Ks, Vs, ae$1, Vi, Qe$1, Yt$1, $$1, Je$1, It, je$1, ti, $s, In, le$1, $i, Xs, Cn, rt$1, mt, vn, Qi, Mn, Bn, Ct, Ji, zn, qs, ce$1, ei, ji, Un, Hn, ts, Qs, rr, Wn, tr, er, ir, is$2, sr, fe$1, ii, ss, si, rs, ns, os$6, hs, pt, ri, as, es, q$1, de$1, ni, oi, Gn, hi, ue$1, pi, nr, li, me$1, W$1, pe$2, Et, Ft$1, Ee$1, ai, G, ls, ci, or, ds, us, fi, di, hr, cs, ui, lr, fs$11, wt, kt, Vn, $n, fr, dr, Xn, qn, Er, wr, ur, Sr, yr, Rr, jn, to, eo, mr, ms, ps, Ei, io, Es, so, ws, Se$1, St, no, gr, Ss, br, oo, _r, ys, Or, Vt$1, Tr, ao, lo, yi, Lr, Dr, _s, Nr, Os, P$1, Ts, xs, gi, Ar, Ir, Re, Cr, Fr, Rs, yt, O$1, Ri, kr, $t, gs, bs, Ls, ge$1, be, _e$1, Oe$1, Te$1, uo, mo, po, vr, Xt$1, ye$1, xe$1, Eo, wo, So, yo, Ro, go, bo, _o, vt, To;
259342
259418
  var init_index_min = __esmMin((() => {
259343
259419
  zr = Object.defineProperty;
259344
259420
  Ur = (s, t) => {
@@ -260866,7 +260942,7 @@ while (this[Zs](this[st$1].shift()));
260866
260942
  let [o, h] = ce$1(this.path);
260867
260943
  o && typeof h == "string" && (this.path = h, r = o);
260868
260944
  }
260869
- this.win32 = !!i.win32 || process.platform === "win32", this.win32 && (this.path = Qs(this.path.replaceAll(/\\/g, "/")), t = t.replaceAll(/\\/g, "/")), this.absolute = f(i.absolute || path$1.resolve(this.cwd, t)), this.path === "" && (this.path = "./"), r && this.warn("TAR_ENTRY_INFO", `stripping ${r} from absolute path`, {
260945
+ this.win32 = !!i.win32 || process.platform === "win32", this.win32 && (this.path = Qs(this.path.replaceAll(/\\/g, "/")), t = t.replaceAll(/\\/g, "/")), this.absolute = f(i.absolute || js.resolve(this.cwd, t)), this.path === "" && (this.path = "./"), r && this.warn("TAR_ENTRY_INFO", `stripping ${r} from absolute path`, {
260870
260946
  entry: this,
260871
260947
  path: r + this.path
260872
260948
  });
@@ -260949,7 +261025,7 @@ while (this[Zs](this[st$1].shift()));
260949
261025
  }
260950
261026
  [sr](t) {
260951
261027
  if (!this.stat) throw new Error("cannot create link entry without stat");
260952
- this.type = "Link", this.linkpath = f(path$1.relative(this.cwd, t)), this.stat.size = 0, this[fe$1](), this.end();
261028
+ this.type = "Link", this.linkpath = f(js.relative(this.cwd, t)), this.stat.size = 0, this[fe$1](), this.end();
260953
261029
  }
260954
261030
  [er]() {
260955
261031
  if (!this.stat) throw new Error("cannot create file entry without stat");
@@ -261308,7 +261384,7 @@ while (this[Zs](this[st$1].shift()));
261308
261384
  constructor(t, e) {
261309
261385
  this.path = t || "./", this.absolute = e;
261310
261386
  }
261311
- }, nr = Buffer.alloc(1024), li = Symbol("onStat"), me$1 = Symbol("ended"), W$1 = Symbol("queue"), pe$2 = Symbol("pendingLinks"), Et = Symbol("current"), Ft$1 = Symbol("process"), Ee$1 = Symbol("processing"), ai = Symbol("processJob"), G = Symbol("jobs"), ls = Symbol("jobDone"), ci = Symbol("addFSEntry"), or = Symbol("addTarEntry"), ds = Symbol("stat"), us = Symbol("readdir"), fi = Symbol("onreaddir"), di = Symbol("pipe"), hr = Symbol("entry"), cs = Symbol("entryOpt"), ui = Symbol("writeEntryClass"), lr = Symbol("write"), fs$12 = Symbol("ondrain"), wt = class extends A$1 {
261387
+ }, nr = Buffer.alloc(1024), li = Symbol("onStat"), me$1 = Symbol("ended"), W$1 = Symbol("queue"), pe$2 = Symbol("pendingLinks"), Et = Symbol("current"), Ft$1 = Symbol("process"), Ee$1 = Symbol("processing"), ai = Symbol("processJob"), G = Symbol("jobs"), ls = Symbol("jobDone"), ci = Symbol("addFSEntry"), or = Symbol("addTarEntry"), ds = Symbol("stat"), us = Symbol("readdir"), fi = Symbol("onreaddir"), di = Symbol("pipe"), hr = Symbol("entry"), cs = Symbol("entryOpt"), ui = Symbol("writeEntryClass"), lr = Symbol("write"), fs$11 = Symbol("ondrain"), wt = class extends A$1 {
261312
261388
  sync = !1;
261313
261389
  opt;
261314
261390
  cwd;
@@ -261341,8 +261417,8 @@ while (this[Zs](this[st$1].shift()));
261341
261417
  if ((t.gzip ? 1 : 0) + (t.brotli ? 1 : 0) + (t.zstd ? 1 : 0) > 1) throw new TypeError("gzip, brotli, zstd are mutually exclusive");
261342
261418
  if (t.gzip && (typeof t.gzip != "object" && (t.gzip = {}), this.portable && (t.gzip.portable = !0), this.zip = new ze$1(t.gzip)), t.brotli && (typeof t.brotli != "object" && (t.brotli = {}), this.zip = new We$1(t.brotli)), t.zstd && (typeof t.zstd != "object" && (t.zstd = {}), this.zip = new Ye$1(t.zstd)), !this.zip) throw new Error("impossible");
261343
261419
  let e = this.zip;
261344
- e.on("data", (i) => super.write(i)), e.on("end", () => super.end()), e.on("drain", () => this[fs$12]()), this.on("resume", () => e.resume());
261345
- } else this.on("drain", this[fs$12]);
261420
+ e.on("data", (i) => super.write(i)), e.on("end", () => super.end()), e.on("drain", () => this[fs$11]()), this.on("resume", () => e.resume());
261421
+ } else this.on("drain", this[fs$11]);
261346
261422
  this.noDirRecurse = !!t.noDirRecurse, this.follow = !!t.follow, this.noMtime = !!t.noMtime, t.mtime && (this.mtime = t.mtime), this.filter = typeof t.filter == "function" ? t.filter : () => !0, this[W$1] = new hi(), this[G] = 0, this.jobs = Number(t.jobs) || 4, this[Ee$1] = !1, this[me$1] = !1;
261347
261423
  }
261348
261424
  [lr](t) {
@@ -261359,7 +261435,7 @@ while (this[Zs](this[st$1].shift()));
261359
261435
  return typeof t == "string" ? this[ci](t) : this[or](t), this.flowing;
261360
261436
  }
261361
261437
  [or](t) {
261362
- let e = f(path$1.resolve(this.cwd, t.path));
261438
+ let e = f(js.resolve(this.cwd, t.path));
261363
261439
  if (!this.filter(t.path, t)) t.resume();
261364
261440
  else {
261365
261441
  let i = new pi(t.path, e);
@@ -261368,7 +261444,7 @@ while (this[Zs](this[st$1].shift()));
261368
261444
  this[Ft$1]();
261369
261445
  }
261370
261446
  [ci](t) {
261371
- let e = f(path$1.resolve(this.cwd, t));
261447
+ let e = f(js.resolve(this.cwd, t));
261372
261448
  this[W$1].push(new pi(t, e)), this[Ft$1]();
261373
261449
  }
261374
261450
  [ds](t) {
@@ -261469,7 +261545,7 @@ while (this[Zs](this[st$1].shift()));
261469
261545
  this.emit("error", e);
261470
261546
  }
261471
261547
  }
261472
- [fs$12]() {
261548
+ [fs$11]() {
261473
261549
  this[Et] && this[Et].entry && this[Et].entry.resume();
261474
261550
  }
261475
261551
  [di](t) {
@@ -261635,7 +261711,7 @@ while (this[Zs](this[st$1].shift()));
261635
261711
  E ? e(E) : x && a ? Es(x, o, h, (Le) => y(Le)) : n ? Kt.chmod(s, r, e) : e();
261636
261712
  };
261637
261713
  if (s === d) return no(s, y);
261638
- if (l) return fs.mkdir(s, {
261714
+ if (l) return ro.mkdir(s, {
261639
261715
  mode: r,
261640
261716
  recursive: !0
261641
261717
  }).then((E) => y(null, E ?? void 0), y);
@@ -262394,7 +262470,7 @@ var require_pend = /* @__PURE__ */ __commonJSMin(((exports, module) => {
262394
262470
  //#endregion
262395
262471
  //#region ../../node_modules/.pnpm/yauzl@3.3.0/node_modules/yauzl/fd-slicer.js
262396
262472
  var require_fd_slicer = /* @__PURE__ */ __commonJSMin(((exports) => {
262397
- var fs$11 = __require("fs");
262473
+ var fs$10 = __require("fs");
262398
262474
  var util$6 = __require("util");
262399
262475
  var stream$2 = __require("stream");
262400
262476
  var Readable = stream$2.Readable;
@@ -262419,7 +262495,7 @@ var require_fd_slicer = /* @__PURE__ */ __commonJSMin(((exports) => {
262419
262495
  FdSlicer.prototype.read = function(buffer, offset, length, position, callback) {
262420
262496
  var self = this;
262421
262497
  self.pend.go(function(cb) {
262422
- fs$11.read(self.fd, buffer, offset, length, position, function(err, bytesRead, buffer) {
262498
+ fs$10.read(self.fd, buffer, offset, length, position, function(err, bytesRead, buffer) {
262423
262499
  cb();
262424
262500
  callback(err, bytesRead, buffer);
262425
262501
  });
@@ -262428,7 +262504,7 @@ var require_fd_slicer = /* @__PURE__ */ __commonJSMin(((exports) => {
262428
262504
  FdSlicer.prototype.write = function(buffer, offset, length, position, callback) {
262429
262505
  var self = this;
262430
262506
  self.pend.go(function(cb) {
262431
- fs$11.write(self.fd, buffer, offset, length, position, function(err, written, buffer) {
262507
+ fs$10.write(self.fd, buffer, offset, length, position, function(err, written, buffer) {
262432
262508
  cb();
262433
262509
  callback(err, written, buffer);
262434
262510
  });
@@ -262448,7 +262524,7 @@ var require_fd_slicer = /* @__PURE__ */ __commonJSMin(((exports) => {
262448
262524
  self.refCount -= 1;
262449
262525
  if (self.refCount > 0) return;
262450
262526
  if (self.refCount < 0) throw new Error("invalid unref");
262451
- if (self.autoClose) fs$11.close(self.fd, onCloseDone);
262527
+ if (self.autoClose) fs$10.close(self.fd, onCloseDone);
262452
262528
  function onCloseDone(err) {
262453
262529
  if (err) self.emit("error", err);
262454
262530
  else self.emit("close");
@@ -262479,7 +262555,7 @@ var require_fd_slicer = /* @__PURE__ */ __commonJSMin(((exports) => {
262479
262555
  self.context.pend.go(function(cb) {
262480
262556
  if (self.destroyed) return cb();
262481
262557
  var buffer = Buffer.allocUnsafe(toRead);
262482
- fs$11.read(self.context.fd, buffer, 0, toRead, self.pos, function(err, bytesRead) {
262558
+ fs$10.read(self.context.fd, buffer, 0, toRead, self.pos, function(err, bytesRead) {
262483
262559
  if (err) self.destroy(err);
262484
262560
  else if (bytesRead === 0) {
262485
262561
  self.destroyed = true;
@@ -262525,7 +262601,7 @@ var require_fd_slicer = /* @__PURE__ */ __commonJSMin(((exports) => {
262525
262601
  }
262526
262602
  self.context.pend.go(function(cb) {
262527
262603
  if (self.destroyed) return cb();
262528
- fs$11.write(self.context.fd, buffer, 0, buffer.length, self.pos, function(err, bytes) {
262604
+ fs$10.write(self.context.fd, buffer, 0, buffer.length, self.pos, function(err, bytes) {
262529
262605
  if (err) {
262530
262606
  self.destroy();
262531
262607
  cb();
@@ -266438,14 +266514,14 @@ async function readGitExecPath(deps, gitExe) {
266438
266514
  }
266439
266515
  }
266440
266516
  function gitBashCandidatesFromGitExe(gitExe) {
266441
- const normalizedGitExe = path$17.win32.normalize(normalizeWindowsPath(gitExe));
266442
- const gitDir = path$17.win32.dirname(normalizedGitExe);
266443
- const gitDirName = path$17.win32.basename(gitDir).toLowerCase();
266517
+ const normalizedGitExe = path$16.win32.normalize(normalizeWindowsPath(gitExe));
266518
+ const gitDir = path$16.win32.dirname(normalizedGitExe);
266519
+ const gitDirName = path$16.win32.basename(gitDir).toLowerCase();
266444
266520
  if (gitDirName !== "cmd" && gitDirName !== "bin") return;
266445
- return gitBashCandidatesFromGitRoot(path$17.win32.dirname(gitDir));
266521
+ return gitBashCandidatesFromGitRoot(path$16.win32.dirname(gitDir));
266446
266522
  }
266447
266523
  function gitBashCandidatesFromGitExecPath(execPath) {
266448
- const normalized = path$17.win32.normalize(normalizeWindowsPath(execPath));
266524
+ const normalized = path$16.win32.normalize(normalizeWindowsPath(execPath));
266449
266525
  const parts = normalized.split("\\");
266450
266526
  for (let i = parts.length - 1; i >= 0; i -= 1) {
266451
266527
  const segment = parts[i]?.toLowerCase();
@@ -266454,16 +266530,16 @@ function gitBashCandidatesFromGitExecPath(execPath) {
266454
266530
  if (root.length > 0) return gitBashCandidatesFromGitRoot(root);
266455
266531
  }
266456
266532
  }
266457
- return gitBashCandidatesFromGitRoot(path$17.win32.join(normalized, "..", ".."));
266533
+ return gitBashCandidatesFromGitRoot(path$16.win32.join(normalized, "..", ".."));
266458
266534
  }
266459
266535
  function gitBashCandidatesFromGitRoot(root) {
266460
- return [path$17.win32.normalize(path$17.win32.join(root, "bin", "bash.exe")), path$17.win32.normalize(path$17.win32.join(root, "usr", "bin", "bash.exe"))];
266536
+ return [path$16.win32.normalize(path$16.win32.join(root, "bin", "bash.exe")), path$16.win32.normalize(path$16.win32.join(root, "usr", "bin", "bash.exe"))];
266461
266537
  }
266462
266538
  function normalizeWindowsPath(path) {
266463
266539
  return path.replaceAll("/", "\\");
266464
266540
  }
266465
266541
  function isAbsoluteWindowsPath(path) {
266466
- return path$17.win32.isAbsolute(normalizeWindowsPath(path));
266542
+ return path$16.win32.isAbsolute(normalizeWindowsPath(path));
266467
266543
  }
266468
266544
  function dedupeWindowsPaths(paths) {
266469
266545
  const deduped = [];
@@ -273256,6 +273332,7 @@ var init_agent = __esmMin((() => {
273256
273332
  init_errors$8();
273257
273333
  init_logger$1();
273258
273334
  init_src$4();
273335
+ init_blun();
273259
273336
  init_commands();
273260
273337
  init_flags();
273261
273338
  init_profile();
@@ -273342,6 +273419,9 @@ var init_agent = __esmMin((() => {
273342
273419
  additionalDirs;
273343
273420
  systemPromptStartedAt = /* @__PURE__ */ new Date();
273344
273421
  activeProfile;
273422
+ rawSystemPromptContext;
273423
+ profileSystemPromptText;
273424
+ agentsMdRequestWarningShown = false;
273345
273425
  brandHome;
273346
273426
  _activeResponderModel;
273347
273427
  allowModelFallback = true;
@@ -273496,6 +273576,7 @@ var init_agent = __esmMin((() => {
273496
273576
  tools: requestTools,
273497
273577
  messages: await rebuildMessages()
273498
273578
  };
273579
+ if (this.activeProfile !== void 0 && this.rawSystemPromptContext !== void 0 && this.config.systemPrompt === this.profileSystemPromptText) this.updateSystemPromptFromProfile(this.activeProfile, this.fitProfileInstructions(this.activeProfile, this.rawSystemPromptContext, requestTools, true));
273499
273580
  let systemPrompt = this.effectiveSystemPrompt;
273500
273581
  const preflightStartedAt = performance.now();
273501
273582
  const compacted = await this.fullCompaction.beforeStep(params.signal, {
@@ -273524,6 +273605,13 @@ var init_agent = __esmMin((() => {
273524
273605
  ...params,
273525
273606
  messages: await rebuildMessages()
273526
273607
  };
273608
+ if (this.config.runtimeModel(_candidate.alias).provider.name === "blun") {
273609
+ const requestBytes = estimateBlunSerializedBodyBytes(systemPrompt, tools, params.messages) + 4096;
273610
+ if (requestBytes >= 5e5) throw new BlunError(ErrorCodes.CONTEXT_OVERFLOW, "The BLUN request is too large after compaction. Shorten fixed instructions or tools.", { details: {
273611
+ estimatedRequestBytes: requestBytes,
273612
+ requestBudgetBytes: 5e5
273613
+ } });
273614
+ }
273527
273615
  return {
273528
273616
  params: {
273529
273617
  ...params,
@@ -273602,8 +273690,14 @@ var init_agent = __esmMin((() => {
273602
273690
  }
273603
273691
  useProfile(profile, context, brandHome) {
273604
273692
  this.setActiveProfile(profile, brandHome);
273605
- this.updateSystemPromptFromProfile(profile, context);
273693
+ this.rawSystemPromptContext = context;
273694
+ if (context?.agentsMdText === void 0) {
273695
+ this.updateSystemPromptFromProfile(profile, context);
273696
+ this.tools.setActiveTools(profile.tools);
273697
+ return;
273698
+ }
273606
273699
  this.tools.setActiveTools(profile.tools);
273700
+ this.updateSystemPromptFromProfile(profile, this.fitProfileInstructions(profile, context));
273607
273701
  }
273608
273702
  setActiveProfile(profile, brandHome) {
273609
273703
  this.activeProfile = profile;
@@ -273618,7 +273712,46 @@ var init_agent = __esmMin((() => {
273618
273712
  async refreshSystemPrompt() {
273619
273713
  if (this.activeProfile === void 0) return;
273620
273714
  const context = this.systemPromptContextProvider === void 0 ? await prepareSystemPromptContext(this.kaos, this.brandHome, { additionalDirs: this.additionalDirs }) : await this.systemPromptContextProvider();
273621
- this.updateSystemPromptFromProfile(this.activeProfile, context);
273715
+ this.rawSystemPromptContext = context;
273716
+ this.updateSystemPromptFromProfile(this.activeProfile, this.fitProfileInstructions(this.activeProfile, context));
273717
+ }
273718
+ fitProfileInstructions(profile, context, tools = this.tools.loopTools, notify = false) {
273719
+ if (context?.agentsMdText === void 0 || this.config.modelAlias === void 0) return context;
273720
+ if (this.config.runtimeModel(this.config.modelAlias).provider.name !== "blun") return context;
273721
+ const fitted = fitAgentsMdContext(context, 4e5, (candidate) => {
273722
+ const rendered = profile.systemPrompt({
273723
+ osEnv: this.kaos.osEnv,
273724
+ now: this.systemPromptStartedAt,
273725
+ cwd: this.config.cwd,
273726
+ skills: this.skills?.registry,
273727
+ cwdListing: candidate.cwdListing,
273728
+ agentsMd: candidate.agentsMd,
273729
+ additionalDirsInfo: candidate.additionalDirsInfo
273730
+ });
273731
+ const compact = this.skills?.registry === void 0 ? rendered : compactLegacyModelSkillListing(rendered, this.skills.registry);
273732
+ return estimateBlunSerializedBodyBytes(this.runtimeSystemPromptAppend.length === 0 ? compact : compact.length === 0 ? this.runtimeSystemPromptAppend : `${compact}\n\n${this.runtimeSystemPromptAppend}`, tools, []) + 4096;
273733
+ });
273734
+ if (!fitted.fits) this.log.warn("fixed BLUN request exceeds 400000 bytes without AGENTS.md", { fixedRequestBytes: fitted.fixedRequestBytes });
273735
+ else if (fitted.omittedBytes > 0) {
273736
+ this.log.warn("AGENTS.md content shortened for BLUN request budget", {
273737
+ omittedBytes: fitted.omittedBytes,
273738
+ fixedRequestBytes: fitted.fixedRequestBytes
273739
+ });
273740
+ if (notify && !this.agentsMdRequestWarningShown) {
273741
+ this.agentsMdRequestWarningShown = true;
273742
+ const retained = new Map(fitted.context.agentsMdSources?.files.map((file) => [file.path, file.bytes]));
273743
+ const files = context.agentsMdSources?.files.flatMap((file) => {
273744
+ const read = retained.get(file.path) ?? 0;
273745
+ return read < file.bytes ? [`${file.path}: ${file.bytes} bytes, ${read} read, ${file.bytes - read} omitted`] : [];
273746
+ }) ?? [];
273747
+ this.emitEvent({
273748
+ type: "warning",
273749
+ code: "agents-md-request-truncated",
273750
+ message: `Instructions shortened for the request size limit: ${files.join("; ")}.`
273751
+ });
273752
+ }
273753
+ }
273754
+ return fitted.context;
273622
273755
  }
273623
273756
  updateSystemPromptFromProfile(profile, context) {
273624
273757
  let contributions;
@@ -273639,6 +273772,7 @@ var init_agent = __esmMin((() => {
273639
273772
  profileName: profile.name,
273640
273773
  systemPrompt
273641
273774
  });
273775
+ this.profileSystemPromptText = systemPrompt;
273642
273776
  this.renderedPromptContributions = contributions === void 0 ? void 0 : {
273643
273777
  text: systemPrompt,
273644
273778
  value: structuredClone(contributions)
@@ -303542,7 +303676,7 @@ var init_proxy = __esmMin((() => {
303542
303676
  var require_windows = /* @__PURE__ */ __commonJSMin(((exports, module) => {
303543
303677
  module.exports = isexe;
303544
303678
  isexe.sync = sync;
303545
- var fs$9 = __require("fs");
303679
+ var fs$8 = __require("fs");
303546
303680
  function checkPathExt(path, options) {
303547
303681
  var pathext = options.pathExt !== void 0 ? options.pathExt : process.env.PATHEXT;
303548
303682
  if (!pathext) return true;
@@ -303559,12 +303693,12 @@ var require_windows = /* @__PURE__ */ __commonJSMin(((exports, module) => {
303559
303693
  return checkPathExt(path, options);
303560
303694
  }
303561
303695
  function isexe(path, options, cb) {
303562
- fs$9.stat(path, function(er, stat) {
303696
+ fs$8.stat(path, function(er, stat) {
303563
303697
  cb(er, er ? false : checkStat(stat, path, options));
303564
303698
  });
303565
303699
  }
303566
303700
  function sync(path, options) {
303567
- return checkStat(fs$9.statSync(path), path, options);
303701
+ return checkStat(fs$8.statSync(path), path, options);
303568
303702
  }
303569
303703
  }));
303570
303704
  //#endregion
@@ -303572,14 +303706,14 @@ var require_windows = /* @__PURE__ */ __commonJSMin(((exports, module) => {
303572
303706
  var require_mode = /* @__PURE__ */ __commonJSMin(((exports, module) => {
303573
303707
  module.exports = isexe;
303574
303708
  isexe.sync = sync;
303575
- var fs$8 = __require("fs");
303709
+ var fs$7 = __require("fs");
303576
303710
  function isexe(path, options, cb) {
303577
- fs$8.stat(path, function(er, stat) {
303711
+ fs$7.stat(path, function(er, stat) {
303578
303712
  cb(er, er ? false : checkStat(stat, options));
303579
303713
  });
303580
303714
  }
303581
303715
  function sync(path, options) {
303582
- return checkStat(fs$8.statSync(path), options);
303716
+ return checkStat(fs$7.statSync(path), options);
303583
303717
  }
303584
303718
  function checkStat(stat, options) {
303585
303719
  return stat.isFile() && checkMode(stat, options);
@@ -303643,7 +303777,7 @@ var require_isexe = /* @__PURE__ */ __commonJSMin(((exports, module) => {
303643
303777
  //#region ../../node_modules/.pnpm/which@2.0.2/node_modules/which/which.js
303644
303778
  var require_which = /* @__PURE__ */ __commonJSMin(((exports, module) => {
303645
303779
  const isWindows = process.platform === "win32" || process.env.OSTYPE === "cygwin" || process.env.OSTYPE === "msys";
303646
- const path$10 = __require("path");
303780
+ const path$9 = __require("path");
303647
303781
  const COLON = isWindows ? ";" : ":";
303648
303782
  const isexe = require_isexe();
303649
303783
  const getNotFoundError = (cmd) => Object.assign(/* @__PURE__ */ new Error(`not found: ${cmd}`), { code: "ENOENT" });
@@ -303673,7 +303807,7 @@ var require_which = /* @__PURE__ */ __commonJSMin(((exports, module) => {
303673
303807
  if (i === pathEnv.length) return opt.all && found.length ? resolve(found) : reject(getNotFoundError(cmd));
303674
303808
  const ppRaw = pathEnv[i];
303675
303809
  const pathPart = /^".*"$/.test(ppRaw) ? ppRaw.slice(1, -1) : ppRaw;
303676
- const pCmd = path$10.join(pathPart, cmd);
303810
+ const pCmd = path$9.join(pathPart, cmd);
303677
303811
  resolve(subStep(!pathPart && /^\.[\\\/]/.test(cmd) ? cmd.slice(0, 2) + pCmd : pCmd, i, 0));
303678
303812
  });
303679
303813
  const subStep = (p, i, ii) => new Promise((resolve, reject) => {
@@ -303694,7 +303828,7 @@ var require_which = /* @__PURE__ */ __commonJSMin(((exports, module) => {
303694
303828
  for (let i = 0; i < pathEnv.length; i++) {
303695
303829
  const ppRaw = pathEnv[i];
303696
303830
  const pathPart = /^".*"$/.test(ppRaw) ? ppRaw.slice(1, -1) : ppRaw;
303697
- const pCmd = path$10.join(pathPart, cmd);
303831
+ const pCmd = path$9.join(pathPart, cmd);
303698
303832
  const p = !pathPart && /^\.[\\\/]/.test(cmd) ? cmd.slice(0, 2) + pCmd : pCmd;
303699
303833
  for (let j = 0; j < pathExt.length; j++) {
303700
303834
  const cur = p + pathExt[j];
@@ -303725,7 +303859,7 @@ var require_path_key = /* @__PURE__ */ __commonJSMin(((exports, module) => {
303725
303859
  //#endregion
303726
303860
  //#region ../../node_modules/.pnpm/cross-spawn@7.0.6/node_modules/cross-spawn/lib/util/resolveCommand.js
303727
303861
  var require_resolveCommand = /* @__PURE__ */ __commonJSMin(((exports, module) => {
303728
- const path$9 = __require("path");
303862
+ const path$8 = __require("path");
303729
303863
  const which = require_which();
303730
303864
  const getPathKey = require_path_key();
303731
303865
  function resolveCommandAttempt(parsed, withoutPathExt) {
@@ -303740,12 +303874,12 @@ var require_resolveCommand = /* @__PURE__ */ __commonJSMin(((exports, module) =>
303740
303874
  try {
303741
303875
  resolved = which.sync(parsed.command, {
303742
303876
  path: env[getPathKey({ env })],
303743
- pathExt: withoutPathExt ? path$9.delimiter : void 0
303877
+ pathExt: withoutPathExt ? path$8.delimiter : void 0
303744
303878
  });
303745
303879
  } catch (e) {} finally {
303746
303880
  if (shouldSwitchCwd) process.chdir(cwd);
303747
303881
  }
303748
- if (resolved) resolved = path$9.resolve(hasCustomCwd ? parsed.options.cwd : "", resolved);
303882
+ if (resolved) resolved = path$8.resolve(hasCustomCwd ? parsed.options.cwd : "", resolved);
303749
303883
  return resolved;
303750
303884
  }
303751
303885
  function resolveCommand(parsed) {
@@ -303794,16 +303928,16 @@ var require_shebang_command = /* @__PURE__ */ __commonJSMin(((exports, module) =
303794
303928
  //#endregion
303795
303929
  //#region ../../node_modules/.pnpm/cross-spawn@7.0.6/node_modules/cross-spawn/lib/util/readShebang.js
303796
303930
  var require_readShebang = /* @__PURE__ */ __commonJSMin(((exports, module) => {
303797
- const fs$7 = __require("fs");
303931
+ const fs$6 = __require("fs");
303798
303932
  const shebangCommand = require_shebang_command();
303799
303933
  function readShebang(command) {
303800
303934
  const size = 150;
303801
303935
  const buffer = Buffer.alloc(size);
303802
303936
  let fd;
303803
303937
  try {
303804
- fd = fs$7.openSync(command, "r");
303805
- fs$7.readSync(fd, buffer, 0, size, 0);
303806
- fs$7.closeSync(fd);
303938
+ fd = fs$6.openSync(command, "r");
303939
+ fs$6.readSync(fd, buffer, 0, size, 0);
303940
+ fs$6.closeSync(fd);
303807
303941
  } catch (e) {}
303808
303942
  return shebangCommand(buffer.toString());
303809
303943
  }
@@ -303812,7 +303946,7 @@ var require_readShebang = /* @__PURE__ */ __commonJSMin(((exports, module) => {
303812
303946
  //#endregion
303813
303947
  //#region ../../node_modules/.pnpm/cross-spawn@7.0.6/node_modules/cross-spawn/lib/parse.js
303814
303948
  var require_parse$5 = /* @__PURE__ */ __commonJSMin(((exports, module) => {
303815
- const path$8 = __require("path");
303949
+ const path$7 = __require("path");
303816
303950
  const resolveCommand = require_resolveCommand();
303817
303951
  const escape = require_escape();
303818
303952
  const readShebang = require_readShebang();
@@ -303835,7 +303969,7 @@ var require_parse$5 = /* @__PURE__ */ __commonJSMin(((exports, module) => {
303835
303969
  const needsShell = !isExecutableRegExp.test(commandFile);
303836
303970
  if (parsed.options.forceShell || needsShell) {
303837
303971
  const needsDoubleEscapeMetaChars = isCmdShimRegExp.test(commandFile);
303838
- parsed.command = path$8.normalize(parsed.command);
303972
+ parsed.command = path$7.normalize(parsed.command);
303839
303973
  parsed.command = escape.command(parsed.command);
303840
303974
  parsed.args = parsed.args.map((arg) => escape.argument(arg, needsDoubleEscapeMetaChars));
303841
303975
  parsed.args = [
@@ -337965,7 +338099,7 @@ var require_dist$5 = /* @__PURE__ */ __commonJSMin(((exports, module) => {
337965
338099
  //#endregion
337966
338100
  //#region ../../node_modules/.pnpm/yazl@3.3.1/node_modules/yazl/index.js
337967
338101
  var require_yazl = /* @__PURE__ */ __commonJSMin(((exports) => {
337968
- var fs$6 = __require("fs");
338102
+ var fs$5 = __require("fs");
337969
338103
  var Transform$2 = __require("stream").Transform;
337970
338104
  var PassThrough$2 = __require("stream").PassThrough;
337971
338105
  var zlib$1 = __require("zlib");
@@ -337994,14 +338128,14 @@ var require_yazl = /* @__PURE__ */ __commonJSMin(((exports) => {
337994
338128
  if (shouldIgnoreAdding(self)) return;
337995
338129
  var entry = new Entry(metadataPath, false, options);
337996
338130
  self.entries.push(entry);
337997
- fs$6.stat(realPath, function(err, stats) {
338131
+ fs$5.stat(realPath, function(err, stats) {
337998
338132
  if (err) return self.emit("error", err);
337999
338133
  if (!stats.isFile()) return self.emit("error", /* @__PURE__ */ new Error("not a file: " + realPath));
338000
338134
  entry.uncompressedSize = stats.size;
338001
338135
  if (options.mtime == null) entry.setLastModDate(stats.mtime);
338002
338136
  if (options.mode == null) entry.setFileAttributesMode(stats.mode);
338003
338137
  entry.setFileDataPumpFunction(function() {
338004
- var readStream = fs$6.createReadStream(realPath);
338138
+ var readStream = fs$5.createReadStream(realPath);
338005
338139
  entry.state = Entry.FILE_DATA_IN_PROGRESS;
338006
338140
  readStream.on("error", function(err) {
338007
338141
  self.emit("error", err);
@@ -353902,8 +354036,8 @@ var require_suggestSimilar = /* @__PURE__ */ __commonJSMin(((exports) => {
353902
354036
  var require_command = /* @__PURE__ */ __commonJSMin(((exports) => {
353903
354037
  const EventEmitter$12 = __require("node:events").EventEmitter;
353904
354038
  const childProcess = __require("node:child_process");
353905
- const path$7 = __require("node:path");
353906
- const fs$5 = __require("node:fs");
354039
+ const path$6 = __require("node:path");
354040
+ const fs$4 = __require("node:fs");
353907
354041
  const process$2 = __require("node:process");
353908
354042
  const { Argument, humanReadableArgName } = require_argument();
353909
354043
  const { CommanderError } = require_error$2();
@@ -354786,7 +354920,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
354786
354920
  * @param {string} subcommandName
354787
354921
  */
354788
354922
  _checkForMissingExecutable(executableFile, executableDir, subcommandName) {
354789
- if (fs$5.existsSync(executableFile)) return;
354923
+ if (fs$4.existsSync(executableFile)) return;
354790
354924
  const executableMissing = `'${executableFile}' does not exist
354791
354925
  - if '${subcommandName}' is not meant to be an executable command, remove description parameter from '.command()' and use '.description()' instead
354792
354926
  - if the default executable name is not suitable, use the executableFile option to supply a custom name or path
@@ -354809,10 +354943,10 @@ Expecting one of '${allowedValues.join("', '")}'`);
354809
354943
  ".cjs"
354810
354944
  ];
354811
354945
  function findFile(baseDir, baseName) {
354812
- const localBin = path$7.resolve(baseDir, baseName);
354813
- if (fs$5.existsSync(localBin)) return localBin;
354814
- if (sourceExt.includes(path$7.extname(baseName))) return void 0;
354815
- const foundExt = sourceExt.find((ext) => fs$5.existsSync(`${localBin}${ext}`));
354946
+ const localBin = path$6.resolve(baseDir, baseName);
354947
+ if (fs$4.existsSync(localBin)) return localBin;
354948
+ if (sourceExt.includes(path$6.extname(baseName))) return void 0;
354949
+ const foundExt = sourceExt.find((ext) => fs$4.existsSync(`${localBin}${ext}`));
354816
354950
  if (foundExt) return `${localBin}${foundExt}`;
354817
354951
  }
354818
354952
  this._checkForMissingMandatoryOptions();
@@ -354822,21 +354956,21 @@ Expecting one of '${allowedValues.join("', '")}'`);
354822
354956
  if (this._scriptPath) {
354823
354957
  let resolvedScriptPath;
354824
354958
  try {
354825
- resolvedScriptPath = fs$5.realpathSync(this._scriptPath);
354959
+ resolvedScriptPath = fs$4.realpathSync(this._scriptPath);
354826
354960
  } catch {
354827
354961
  resolvedScriptPath = this._scriptPath;
354828
354962
  }
354829
- executableDir = path$7.resolve(path$7.dirname(resolvedScriptPath), executableDir);
354963
+ executableDir = path$6.resolve(path$6.dirname(resolvedScriptPath), executableDir);
354830
354964
  }
354831
354965
  if (executableDir) {
354832
354966
  let localFile = findFile(executableDir, executableFile);
354833
354967
  if (!localFile && !subcommand._executableFile && this._scriptPath) {
354834
- const legacyName = path$7.basename(this._scriptPath, path$7.extname(this._scriptPath));
354968
+ const legacyName = path$6.basename(this._scriptPath, path$6.extname(this._scriptPath));
354835
354969
  if (legacyName !== this._name) localFile = findFile(executableDir, `${legacyName}-${subcommand._name}`);
354836
354970
  }
354837
354971
  executableFile = localFile || executableFile;
354838
354972
  }
354839
- launchWithNode = sourceExt.includes(path$7.extname(executableFile));
354973
+ launchWithNode = sourceExt.includes(path$6.extname(executableFile));
354840
354974
  let proc;
354841
354975
  if (process$2.platform !== "win32") if (launchWithNode) {
354842
354976
  args.unshift(executableFile);
@@ -355540,7 +355674,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
355540
355674
  * @return {Command}
355541
355675
  */
355542
355676
  nameFromFilename(filename) {
355543
- this._name = path$7.basename(filename, path$7.extname(filename));
355677
+ this._name = path$6.basename(filename, path$6.extname(filename));
355544
355678
  return this;
355545
355679
  }
355546
355680
  /**
@@ -361756,6 +361890,25 @@ var AcpSession = class {
361756
361890
  });
361757
361891
  return;
361758
361892
  }
361893
+ if (event.type === "warning" && event.code === "agents-md-request-truncated") {
361894
+ if (!isFromMainAgent(event)) return;
361895
+ conn.sessionUpdate({
361896
+ sessionId,
361897
+ update: {
361898
+ sessionUpdate: "agent_message_chunk",
361899
+ content: {
361900
+ type: "text",
361901
+ text: `${event.message}\n`
361902
+ }
361903
+ }
361904
+ }).catch((err) => {
361905
+ log.warn("acp: failed to push instruction warning", {
361906
+ sessionId,
361907
+ error: err instanceof Error ? err.message : String(err)
361908
+ });
361909
+ });
361910
+ return;
361911
+ }
361759
361912
  if (event.type === "assistant.delta") {
361760
361913
  if (!isFromMainAgent(event)) return;
361761
361914
  conn.sessionUpdate(assistantDeltaToSessionUpdate(sessionId, event)).catch((err) => {
@@ -373383,10 +373536,10 @@ var require_atomic_sleep = /* @__PURE__ */ __commonJSMin(((exports, module) => {
373383
373536
  //#endregion
373384
373537
  //#region ../../node_modules/.pnpm/sonic-boom@4.2.1/node_modules/sonic-boom/index.js
373385
373538
  var require_sonic_boom = /* @__PURE__ */ __commonJSMin(((exports, module) => {
373386
- const fs$4 = __require("fs");
373539
+ const fs$3 = __require("fs");
373387
373540
  const EventEmitter$10 = __require("events");
373388
373541
  const inherits$6 = __require("util").inherits;
373389
- const path$6 = __require("path");
373542
+ const path$5 = __require("path");
373390
373543
  const sleep = require_atomic_sleep();
373391
373544
  const assert$8 = __require("assert");
373392
373545
  const BUSY_WRITE_TIMEOUT = 100;
@@ -373426,17 +373579,17 @@ var require_sonic_boom = /* @__PURE__ */ __commonJSMin(((exports, module) => {
373426
373579
  const flags = sonic.append ? "a" : "w";
373427
373580
  const mode = sonic.mode;
373428
373581
  if (sonic.sync) try {
373429
- if (sonic.mkdir) fs$4.mkdirSync(path$6.dirname(file), { recursive: true });
373430
- fileOpened(null, fs$4.openSync(file, flags, mode));
373582
+ if (sonic.mkdir) fs$3.mkdirSync(path$5.dirname(file), { recursive: true });
373583
+ fileOpened(null, fs$3.openSync(file, flags, mode));
373431
373584
  } catch (err) {
373432
373585
  fileOpened(err);
373433
373586
  throw err;
373434
373587
  }
373435
- else if (sonic.mkdir) fs$4.mkdir(path$6.dirname(file), { recursive: true }, (err) => {
373588
+ else if (sonic.mkdir) fs$3.mkdir(path$5.dirname(file), { recursive: true }, (err) => {
373436
373589
  if (err) return fileOpened(err);
373437
- fs$4.open(file, flags, mode, fileOpened);
373590
+ fs$3.open(file, flags, mode, fileOpened);
373438
373591
  });
373439
- else fs$4.open(file, flags, mode, fileOpened);
373592
+ else fs$3.open(file, flags, mode, fileOpened);
373440
373593
  }
373441
373594
  function SonicBoom(opts) {
373442
373595
  if (!(this instanceof SonicBoom)) return new SonicBoom(opts);
@@ -373474,8 +373627,8 @@ var require_sonic_boom = /* @__PURE__ */ __commonJSMin(((exports, module) => {
373474
373627
  this.flush = flushBuffer;
373475
373628
  this.flushSync = flushBufferSync;
373476
373629
  this._actualWrite = actualWriteBuffer;
373477
- fsWriteSync = () => fs$4.writeSync(this.fd, this._writingBuf);
373478
- fsWrite = () => fs$4.write(this.fd, this._writingBuf, this.release);
373630
+ fsWriteSync = () => fs$3.writeSync(this.fd, this._writingBuf);
373631
+ fsWrite = () => fs$3.write(this.fd, this._writingBuf, this.release);
373479
373632
  } else if (contentMode === void 0 || contentMode === kContentModeUtf8) {
373480
373633
  this._writingBuf = "";
373481
373634
  this.write = write;
@@ -373483,12 +373636,12 @@ var require_sonic_boom = /* @__PURE__ */ __commonJSMin(((exports, module) => {
373483
373636
  this.flushSync = flushSync;
373484
373637
  this._actualWrite = actualWrite;
373485
373638
  fsWriteSync = () => {
373486
- if (Buffer.isBuffer(this._writingBuf)) return fs$4.writeSync(this.fd, this._writingBuf);
373487
- return fs$4.writeSync(this.fd, this._writingBuf, "utf8");
373639
+ if (Buffer.isBuffer(this._writingBuf)) return fs$3.writeSync(this.fd, this._writingBuf);
373640
+ return fs$3.writeSync(this.fd, this._writingBuf, "utf8");
373488
373641
  };
373489
373642
  fsWrite = () => {
373490
- if (Buffer.isBuffer(this._writingBuf)) return fs$4.write(this.fd, this._writingBuf, this.release);
373491
- return fs$4.write(this.fd, this._writingBuf, "utf8", this.release);
373643
+ if (Buffer.isBuffer(this._writingBuf)) return fs$3.write(this.fd, this._writingBuf, this.release);
373644
+ return fs$3.write(this.fd, this._writingBuf, "utf8", this.release);
373492
373645
  };
373493
373646
  } else throw new Error(`SonicBoom supports "${kContentModeUtf8}" and "${kContentModeBuffer}", but passed ${contentMode}`);
373494
373647
  if (typeof fd === "number") {
@@ -373533,7 +373686,7 @@ var require_sonic_boom = /* @__PURE__ */ __commonJSMin(((exports, module) => {
373533
373686
  return;
373534
373687
  }
373535
373688
  }
373536
- if (this._fsync) fs$4.fsyncSync(this.fd);
373689
+ if (this._fsync) fs$3.fsyncSync(this.fd);
373537
373690
  const len = this._len;
373538
373691
  if (this._reopening) {
373539
373692
  this._writing = false;
@@ -373630,7 +373783,7 @@ var require_sonic_boom = /* @__PURE__ */ __commonJSMin(((exports, module) => {
373630
373783
  this._flushPending = true;
373631
373784
  const onDrain = () => {
373632
373785
  if (!this._fsync) try {
373633
- fs$4.fsync(this.fd, (err) => {
373786
+ fs$3.fsync(this.fd, (err) => {
373634
373787
  this._flushPending = false;
373635
373788
  cb(err);
373636
373789
  });
@@ -373707,7 +373860,7 @@ var require_sonic_boom = /* @__PURE__ */ __commonJSMin(((exports, module) => {
373707
373860
  if (this._writing) return;
373708
373861
  const fd = this.fd;
373709
373862
  this.once("ready", () => {
373710
- if (fd !== this.fd) fs$4.close(fd, (err) => {
373863
+ if (fd !== this.fd) fs$3.close(fd, (err) => {
373711
373864
  if (err) return this.emit("error", err);
373712
373865
  });
373713
373866
  });
@@ -373738,7 +373891,7 @@ var require_sonic_boom = /* @__PURE__ */ __commonJSMin(((exports, module) => {
373738
373891
  while (this._bufs.length || buf.length) {
373739
373892
  if (buf.length <= 0) buf = this._bufs[0];
373740
373893
  try {
373741
- const n = Buffer.isBuffer(buf) ? fs$4.writeSync(this.fd, buf) : fs$4.writeSync(this.fd, buf, "utf8");
373894
+ const n = Buffer.isBuffer(buf) ? fs$3.writeSync(this.fd, buf) : fs$3.writeSync(this.fd, buf, "utf8");
373742
373895
  const releasedBufObj = releaseWritingBuf(buf, this._len, n);
373743
373896
  buf = releasedBufObj.writingBuf;
373744
373897
  this._len = releasedBufObj.len;
@@ -373749,7 +373902,7 @@ var require_sonic_boom = /* @__PURE__ */ __commonJSMin(((exports, module) => {
373749
373902
  }
373750
373903
  }
373751
373904
  try {
373752
- fs$4.fsyncSync(this.fd);
373905
+ fs$3.fsyncSync(this.fd);
373753
373906
  } catch {}
373754
373907
  }
373755
373908
  function flushBufferSync() {
@@ -373763,7 +373916,7 @@ var require_sonic_boom = /* @__PURE__ */ __commonJSMin(((exports, module) => {
373763
373916
  while (this._bufs.length || buf.length) {
373764
373917
  if (buf.length <= 0) buf = mergeBuf(this._bufs[0], this._lens[0]);
373765
373918
  try {
373766
- const n = fs$4.writeSync(this.fd, buf);
373919
+ const n = fs$3.writeSync(this.fd, buf);
373767
373920
  buf = buf.subarray(n);
373768
373921
  this._len = Math.max(this._len - n, 0);
373769
373922
  if (buf.length <= 0) {
@@ -373785,24 +373938,24 @@ var require_sonic_boom = /* @__PURE__ */ __commonJSMin(((exports, module) => {
373785
373938
  this._writing = true;
373786
373939
  this._writingBuf = this._writingBuf.length ? this._writingBuf : this._bufs.shift() || "";
373787
373940
  if (this.sync) try {
373788
- release(null, Buffer.isBuffer(this._writingBuf) ? fs$4.writeSync(this.fd, this._writingBuf) : fs$4.writeSync(this.fd, this._writingBuf, "utf8"));
373941
+ release(null, Buffer.isBuffer(this._writingBuf) ? fs$3.writeSync(this.fd, this._writingBuf) : fs$3.writeSync(this.fd, this._writingBuf, "utf8"));
373789
373942
  } catch (err) {
373790
373943
  release(err);
373791
373944
  }
373792
- else fs$4.write(this.fd, this._writingBuf, release);
373945
+ else fs$3.write(this.fd, this._writingBuf, release);
373793
373946
  }
373794
373947
  function actualWriteBuffer() {
373795
373948
  const release = this.release;
373796
373949
  this._writing = true;
373797
373950
  this._writingBuf = this._writingBuf.length ? this._writingBuf : mergeBuf(this._bufs.shift(), this._lens.shift());
373798
373951
  if (this.sync) try {
373799
- release(null, fs$4.writeSync(this.fd, this._writingBuf));
373952
+ release(null, fs$3.writeSync(this.fd, this._writingBuf));
373800
373953
  } catch (err) {
373801
373954
  release(err);
373802
373955
  }
373803
373956
  else {
373804
373957
  if (kCopyBuffer) this._writingBuf = Buffer.from(this._writingBuf);
373805
- fs$4.write(this.fd, this._writingBuf, release);
373958
+ fs$3.write(this.fd, this._writingBuf, release);
373806
373959
  }
373807
373960
  }
373808
373961
  function actualClose(sonic) {
@@ -373816,10 +373969,10 @@ var require_sonic_boom = /* @__PURE__ */ __commonJSMin(((exports, module) => {
373816
373969
  sonic._lens = [];
373817
373970
  assert$8(typeof sonic.fd === "number", `sonic.fd must be a number, got ${typeof sonic.fd}`);
373818
373971
  try {
373819
- fs$4.fsync(sonic.fd, closeWrapped);
373972
+ fs$3.fsync(sonic.fd, closeWrapped);
373820
373973
  } catch {}
373821
373974
  function closeWrapped() {
373822
- if (sonic.fd !== 1 && sonic.fd !== 2) fs$4.close(sonic.fd, done);
373975
+ if (sonic.fd !== 1 && sonic.fd !== 2) fs$3.close(sonic.fd, done);
373823
373976
  else done();
373824
373977
  }
373825
373978
  function done(err) {
@@ -403459,7 +403612,7 @@ var import_multipart = /* @__PURE__ */ __toESM((/* @__PURE__ */ __commonJSMin(((
403459
403612
  const fp = require_plugin();
403460
403613
  const { createWriteStream: createWriteStream$1 } = __require("node:fs");
403461
403614
  const { unlink: unlink$1 } = __require("node:fs/promises");
403462
- const path$5 = __require("node:path");
403615
+ const path$4 = __require("node:path");
403463
403616
  const { generateId } = require_generateId();
403464
403617
  const createError = require_error$1();
403465
403618
  const streamToNull = require_stream_consumer();
@@ -403754,7 +403907,7 @@ var import_multipart = /* @__PURE__ */ __toESM((/* @__PURE__ */ __commonJSMin(((
403754
403907
  for await (const part of parts) {
403755
403908
  values = part.fields;
403756
403909
  if (!part.file) continue;
403757
- const filepath = path$5.join(tmpdir, generateId() + path$5.extname(part.filename || "file" + i++));
403910
+ const filepath = path$4.join(tmpdir, generateId() + path$4.extname(part.filename || "file" + i++));
403758
403911
  const target = createWriteStream$1(filepath);
403759
403912
  try {
403760
403913
  this.tmpUploads.push(filepath);
@@ -416495,8 +416648,8 @@ var require_dist$1 = /* @__PURE__ */ __commonJSMin(((exports) => {
416495
416648
  //#endregion
416496
416649
  //#region ../../node_modules/.pnpm/@fastify+swagger@9.7.0/node_modules/@fastify/swagger/lib/mode/static.js
416497
416650
  var require_static = /* @__PURE__ */ __commonJSMin(((exports, module) => {
416498
- const path$4 = __require("node:path");
416499
- const fs$3 = __require("node:fs");
416651
+ const path$3 = __require("node:path");
416652
+ const fs$2 = __require("node:fs");
416500
416653
  const yaml = require_dist$1();
416501
416654
  module.exports = function(fastify, opts, done) {
416502
416655
  if (!opts.specification) return done(/* @__PURE__ */ new Error("specification is missing in the module options"));
@@ -416505,14 +416658,14 @@ var require_static = /* @__PURE__ */ __commonJSMin(((exports, module) => {
416505
416658
  if (!opts.specification.path && !opts.specification.document) return done(/* @__PURE__ */ new Error("both specification.path and specification.document are missing, should be path to the file or swagger document spec"));
416506
416659
  else if (opts.specification.path) {
416507
416660
  if (typeof opts.specification.path !== "string") return done(/* @__PURE__ */ new Error("specification.path is not a string"));
416508
- if (!fs$3.existsSync(path$4.resolve(opts.specification.path))) return done(/* @__PURE__ */ new Error(`${opts.specification.path} does not exist`));
416509
- const extName = path$4.extname(opts.specification.path).toLowerCase();
416661
+ if (!fs$2.existsSync(path$3.resolve(opts.specification.path))) return done(/* @__PURE__ */ new Error(`${opts.specification.path} does not exist`));
416662
+ const extName = path$3.extname(opts.specification.path).toLowerCase();
416510
416663
  if ([".yaml", ".json"].indexOf(extName) === -1) return done(/* @__PURE__ */ new Error("specification.path extension name is not supported, should be one from ['.yaml', '.json']"));
416511
416664
  if (opts.specification.postProcessor && typeof opts.specification.postProcessor !== "function") return done(/* @__PURE__ */ new Error("specification.postProcessor should be a function"));
416512
416665
  if (opts.specification.baseDir && typeof opts.specification.baseDir !== "string") return done(/* @__PURE__ */ new Error("specification.baseDir should be string"));
416513
- if (!opts.specification.baseDir) opts.specification.baseDir = path$4.resolve(path$4.dirname(opts.specification.path));
416666
+ if (!opts.specification.baseDir) opts.specification.baseDir = path$3.resolve(path$3.dirname(opts.specification.path));
416514
416667
  else while (opts.specification.baseDir.endsWith("/")) opts.specification.baseDir = opts.specification.baseDir.slice(0, -1);
416515
- const source = fs$3.readFileSync(path$4.resolve(opts.specification.path), "utf8");
416668
+ const source = fs$2.readFileSync(path$3.resolve(opts.specification.path), "utf8");
416516
416669
  switch (extName) {
416517
416670
  case ".yaml":
416518
416671
  swaggerObject = yaml.parse(source);
@@ -416779,11 +416932,11 @@ var require_should_route_hide = /* @__PURE__ */ __commonJSMin(((exports, module)
416779
416932
  //#endregion
416780
416933
  //#region ../../node_modules/.pnpm/@fastify+swagger@9.7.0/node_modules/@fastify/swagger/lib/util/read-package-json.js
416781
416934
  var require_read_package_json = /* @__PURE__ */ __commonJSMin(((exports, module) => {
416782
- const fs$2 = __require("node:fs");
416783
- const path$3 = __require("node:path");
416935
+ const fs$1 = __require("node:fs");
416936
+ const path$2 = __require("node:path");
416784
416937
  function readPackageJson() {
416785
416938
  try {
416786
- return JSON.parse(fs$2.readFileSync(path$3.join(__dirname, "..", "..", "package.json")));
416939
+ return JSON.parse(fs$1.readFileSync(path$2.join(__dirname, "..", "..", "package.json")));
416787
416940
  } catch {
416788
416941
  return {};
416789
416942
  }
@@ -433766,9 +433919,9 @@ var TUI = class TUI extends Container {
433766
433919
  const debugRedraw = process.env["PI_DEBUG_REDRAW"] === "1";
433767
433920
  const logRedraw = (reason) => {
433768
433921
  if (!debugRedraw) return;
433769
- const logPath = path$17.join(nodeOs.homedir(), ".pi", "agent", "pi-debug.log");
433922
+ const logPath = path$16.join(nodeOs.homedir(), ".pi", "agent", "pi-debug.log");
433770
433923
  const msg = `[${(/* @__PURE__ */ new Date()).toISOString()}] fullRender: ${reason} (prev=${this.previousLines.length}, new=${newLines.length}, height=${height})\n`;
433771
- fs$17.appendFileSync(logPath, msg);
433924
+ fs$16.appendFileSync(logPath, msg);
433772
433925
  };
433773
433926
  if (this.previousLines.length === 0 && !widthChanged && !heightChanged) {
433774
433927
  logRedraw("first render");
@@ -433915,8 +434068,8 @@ var TUI = class TUI extends Container {
433915
434068
  buffer += "\x1B[?2026l";
433916
434069
  if (process.env["PI_TUI_DEBUG"] === "1") {
433917
434070
  const debugDir = "/tmp/tui";
433918
- fs$17.mkdirSync(debugDir, { recursive: true });
433919
- const debugPath = path$17.join(debugDir, `render-${Date.now()}-${Math.random().toString(36).slice(2)}.log`);
434071
+ fs$16.mkdirSync(debugDir, { recursive: true });
434072
+ const debugPath = path$16.join(debugDir, `render-${Date.now()}-${Math.random().toString(36).slice(2)}.log`);
433920
434073
  const debugData = [
433921
434074
  `firstChanged: ${firstChanged}`,
433922
434075
  `viewportTop: ${viewportTop}`,
@@ -433939,7 +434092,7 @@ var TUI = class TUI extends Container {
433939
434092
  "=== buffer ===",
433940
434093
  JSON.stringify(buffer)
433941
434094
  ].join("\n");
433942
- fs$17.writeFileSync(debugPath, debugData);
434095
+ fs$16.writeFileSync(debugPath, debugData);
433943
434096
  }
433944
434097
  this.terminal.write(buffer);
433945
434098
  this.cursorRow = Math.max(0, newLines.length - 1);
@@ -438525,12 +438678,12 @@ function loadNativeModifiersHelper() {
438525
438678
  if (process.platform !== "darwin") return void 0;
438526
438679
  const arch = process.arch;
438527
438680
  if (arch !== "x64" && arch !== "arm64") return void 0;
438528
- const moduleDir = path$17.dirname(fileURLToPath(import.meta.url));
438529
- const nativePath = path$17.join("native", "darwin", "prebuilds", `darwin-${arch}`, "darwin-modifiers.node");
438681
+ const moduleDir = path$16.dirname(fileURLToPath(import.meta.url));
438682
+ const nativePath = path$16.join("native", "darwin", "prebuilds", `darwin-${arch}`, "darwin-modifiers.node");
438530
438683
  const candidates = [
438531
- path$17.join(moduleDir, "..", nativePath),
438532
- path$17.join(moduleDir, nativePath),
438533
- path$17.join(path$17.dirname(process.execPath), nativePath)
438684
+ path$16.join(moduleDir, "..", nativePath),
438685
+ path$16.join(moduleDir, nativePath),
438686
+ path$16.join(path$16.dirname(process.execPath), nativePath)
438534
438687
  ];
438535
438688
  for (const modulePath of candidates) try {
438536
438689
  const helper = cjsRequire$1(modulePath);
@@ -438603,10 +438756,10 @@ var ProcessTerminal = class {
438603
438756
  const env = process.env["PI_TUI_WRITE_LOG"] || "";
438604
438757
  if (!env) return "";
438605
438758
  try {
438606
- if (fs$17.statSync(env).isDirectory()) {
438759
+ if (fs$16.statSync(env).isDirectory()) {
438607
438760
  const now = /* @__PURE__ */ new Date();
438608
438761
  const ts = `${now.getFullYear()}-${String(now.getMonth() + 1).padStart(2, "0")}-${String(now.getDate()).padStart(2, "0")}_${String(now.getHours()).padStart(2, "0")}-${String(now.getMinutes()).padStart(2, "0")}-${String(now.getSeconds()).padStart(2, "0")}`;
438609
- return path$17.join(env, `tui-${ts}-${process.pid}.log`);
438762
+ return path$16.join(env, `tui-${ts}-${process.pid}.log`);
438610
438763
  }
438611
438764
  } catch {}
438612
438765
  return env;
@@ -438809,12 +438962,12 @@ var ProcessTerminal = class {
438809
438962
  try {
438810
438963
  const arch = process.arch;
438811
438964
  if (arch !== "x64" && arch !== "arm64") return;
438812
- const moduleDir = path$17.dirname(fileURLToPath(import.meta.url));
438813
- const nativePath = path$17.join("native", "win32", "prebuilds", `win32-${arch}`, "win32-console-mode.node");
438965
+ const moduleDir = path$16.dirname(fileURLToPath(import.meta.url));
438966
+ const nativePath = path$16.join("native", "win32", "prebuilds", `win32-${arch}`, "win32-console-mode.node");
438814
438967
  const candidates = [
438815
- path$17.join(moduleDir, "..", nativePath),
438816
- path$17.join(moduleDir, nativePath),
438817
- path$17.join(path$17.dirname(process.execPath), nativePath)
438968
+ path$16.join(moduleDir, "..", nativePath),
438969
+ path$16.join(moduleDir, nativePath),
438970
+ path$16.join(path$16.dirname(process.execPath), nativePath)
438818
438971
  ];
438819
438972
  for (const modulePath of candidates) try {
438820
438973
  cjsRequire(modulePath).enableVirtualTerminalInput?.();
@@ -438886,7 +439039,7 @@ var ProcessTerminal = class {
438886
439039
  write(data) {
438887
439040
  process.stdout.write(data);
438888
439041
  if (this.writeLogPath) try {
438889
- fs$17.appendFileSync(this.writeLogPath, data, { encoding: "utf8" });
439042
+ fs$16.appendFileSync(this.writeLogPath, data, { encoding: "utf8" });
438890
439043
  } catch {}
438891
439044
  }
438892
439045
  get columns() {
@@ -547550,13 +547703,13 @@ var BlunTUI = class {
547550
547703
  //#endregion
547551
547704
  //#region src/constant/update.ts
547552
547705
  var import_runtime_exit_ledger = (/* @__PURE__ */ __commonJSMin(((exports, module) => {
547553
- const fs$1 = __require("node:fs");
547706
+ const fs = __require("node:fs");
547554
547707
  const os$1 = __require("node:os");
547555
- const path$2 = __require("node:path");
547708
+ const path$1 = __require("node:path");
547556
547709
  const DEFAULT_MAX_BYTES = 1024 * 1024;
547557
547710
  const DEFAULT_RETAIN_BYTES = 512 * 1024;
547558
547711
  function runtimeExitLedgerPath(homeDir) {
547559
- return path$2.join(homeDir, "diagnostics", "runtime-exits.jsonl");
547712
+ return path$1.join(homeDir, "diagnostics", "runtime-exits.jsonl");
547560
547713
  }
547561
547714
  function sanitizeExitText(input, maxChars = 2048) {
547562
547715
  let value = String(input ?? "");
@@ -547565,7 +547718,7 @@ var import_runtime_exit_ledger = (/* @__PURE__ */ __commonJSMin(((exports, modul
547565
547718
  process.env.USERPROFILE,
547566
547719
  process.env.HOME
547567
547720
  ].filter((entry) => typeof entry === "string" && entry.length > 2));
547568
- for (const home of homes) for (const variant of [path$2.normalize(home), home.replaceAll("\\", "/")]) {
547721
+ for (const home of homes) for (const variant of [path$1.normalize(home), home.replaceAll("\\", "/")]) {
547569
547722
  const escaped = variant.replace(/[.*+?^${}()|[\]\\]/gu, "\\$&");
547570
547723
  value = value.replace(new RegExp(escaped, process.platform === "win32" ? "giu" : "gu"), "$HOME");
547571
547724
  }
@@ -547604,7 +547757,7 @@ var import_runtime_exit_ledger = (/* @__PURE__ */ __commonJSMin(((exports, modul
547604
547757
  return record;
547605
547758
  }
547606
547759
  function directoryIdentity(directory) {
547607
- const stat = fs$1.lstatSync(directory, { bigint: true });
547760
+ const stat = fs.lstatSync(directory, { bigint: true });
547608
547761
  if (!stat.isDirectory() || stat.isSymbolicLink()) throw new Error("Unsafe exit directory");
547609
547762
  return stat;
547610
547763
  }
@@ -547616,46 +547769,46 @@ var import_runtime_exit_ledger = (/* @__PURE__ */ __commonJSMin(((exports, modul
547616
547769
  return stat;
547617
547770
  }
547618
547771
  function trimLedger(descriptor, maxBytes, retainBytes, incomingBytes) {
547619
- const size = Number(regularLedger(fs$1.fstatSync(descriptor, { bigint: true })).size);
547772
+ const size = Number(regularLedger(fs.fstatSync(descriptor, { bigint: true })).size);
547620
547773
  if (!Number.isSafeInteger(size)) throw new Error("Invalid exit ledger size");
547621
547774
  if (size + incomingBytes <= maxBytes) return;
547622
547775
  const keepBytes = Math.max(0, Math.min(size, retainBytes, maxBytes - incomingBytes));
547623
547776
  const contents = Buffer.alloc(keepBytes);
547624
- const read = fs$1.readSync(descriptor, contents, 0, keepBytes, size - keepBytes);
547777
+ const read = fs.readSync(descriptor, contents, 0, keepBytes, size - keepBytes);
547625
547778
  const tail = contents.subarray(0, read);
547626
547779
  const lineStart = size > keepBytes ? tail.indexOf(10) + 1 : 0;
547627
- fs$1.ftruncateSync(descriptor, 0);
547628
- fs$1.writeFileSync(descriptor, lineStart > 0 || size === keepBytes ? tail.subarray(lineStart) : "");
547780
+ fs.ftruncateSync(descriptor, 0);
547781
+ fs.writeFileSync(descriptor, lineStart > 0 || size === keepBytes ? tail.subarray(lineStart) : "");
547629
547782
  }
547630
547783
  function recordRuntimeExit(input = {}) {
547631
547784
  let descriptor;
547632
547785
  let appendDescriptor;
547633
547786
  try {
547634
547787
  const homeDir = typeof input.homeDir === "string" ? input.homeDir.trim() : "";
547635
- if (!homeDir || !path$2.isAbsolute(homeDir)) return false;
547636
- fs$1.mkdirSync(homeDir, {
547788
+ if (!homeDir || !path$1.isAbsolute(homeDir)) return false;
547789
+ fs.mkdirSync(homeDir, {
547637
547790
  recursive: true,
547638
547791
  mode: 448
547639
547792
  });
547640
547793
  const homeIdentity = directoryIdentity(homeDir);
547641
547794
  const file = runtimeExitLedgerPath(homeDir);
547642
- const directory = path$2.dirname(file);
547795
+ const directory = path$1.dirname(file);
547643
547796
  try {
547644
- fs$1.mkdirSync(directory, { mode: 448 });
547797
+ fs.mkdirSync(directory, { mode: 448 });
547645
547798
  } catch (error) {
547646
547799
  if (error.code !== "EEXIST") throw error;
547647
547800
  }
547648
547801
  const directoryStat = directoryIdentity(directory);
547649
547802
  let before;
547650
547803
  try {
547651
- before = regularLedger(fs$1.lstatSync(file, { bigint: true }));
547804
+ before = regularLedger(fs.lstatSync(file, { bigint: true }));
547652
547805
  } catch (error) {
547653
547806
  if (error.code !== "ENOENT") throw error;
547654
547807
  }
547655
- const flags = fs$1.constants.O_RDWR | (fs$1.constants.O_NOFOLLOW ?? 0) | (fs$1.constants.O_NONBLOCK ?? 0) | (before ? 0 : fs$1.constants.O_CREAT | fs$1.constants.O_EXCL);
547656
- descriptor = fs$1.openSync(file, flags, 384);
547657
- const opened = regularLedger(fs$1.fstatSync(descriptor, { bigint: true }));
547658
- if (before && !sameIdentity(before, opened) || !sameIdentity(opened, regularLedger(fs$1.lstatSync(file, { bigint: true }))) || !sameIdentity(homeIdentity, directoryIdentity(homeDir)) || !sameIdentity(directoryStat, directoryIdentity(directory))) throw new Error("Exit ledger changed");
547808
+ const flags = fs.constants.O_RDWR | (fs.constants.O_NOFOLLOW ?? 0) | (fs.constants.O_NONBLOCK ?? 0) | (before ? 0 : fs.constants.O_CREAT | fs.constants.O_EXCL);
547809
+ descriptor = fs.openSync(file, flags, 384);
547810
+ const opened = regularLedger(fs.fstatSync(descriptor, { bigint: true }));
547811
+ if (before && !sameIdentity(before, opened) || !sameIdentity(opened, regularLedger(fs.lstatSync(file, { bigint: true }))) || !sameIdentity(homeIdentity, directoryIdentity(homeDir)) || !sameIdentity(directoryStat, directoryIdentity(directory))) throw new Error("Exit ledger changed");
547659
547812
  const maxBytes = Math.max(1024, Number.isInteger(input.maxBytes) ? input.maxBytes : DEFAULT_MAX_BYTES);
547660
547813
  const retainBytes = Math.max(0, Number.isInteger(input.retainBytes) ? input.retainBytes : DEFAULT_RETAIN_BYTES);
547661
547814
  const record = buildRuntimeExitRecord(input);
@@ -547678,21 +547831,21 @@ var import_runtime_exit_ledger = (/* @__PURE__ */ __commonJSMin(((exports, modul
547678
547831
  line = `${JSON.stringify(record)}\n`;
547679
547832
  }
547680
547833
  trimLedger(descriptor, maxBytes, retainBytes, Buffer.byteLength(line));
547681
- appendDescriptor = fs$1.openSync(file, fs$1.constants.O_WRONLY | fs$1.constants.O_APPEND | (fs$1.constants.O_NOFOLLOW ?? 0) | (fs$1.constants.O_NONBLOCK ?? 0));
547682
- if (!sameIdentity(opened, regularLedger(fs$1.fstatSync(appendDescriptor, { bigint: true }))) || !sameIdentity(opened, regularLedger(fs$1.lstatSync(file, { bigint: true }))) || !sameIdentity(homeIdentity, directoryIdentity(homeDir)) || !sameIdentity(directoryStat, directoryIdentity(directory))) throw new Error("Exit ledger changed");
547683
- fs$1.appendFileSync(appendDescriptor, line, { encoding: "utf8" });
547834
+ appendDescriptor = fs.openSync(file, fs.constants.O_WRONLY | fs.constants.O_APPEND | (fs.constants.O_NOFOLLOW ?? 0) | (fs.constants.O_NONBLOCK ?? 0));
547835
+ if (!sameIdentity(opened, regularLedger(fs.fstatSync(appendDescriptor, { bigint: true }))) || !sameIdentity(opened, regularLedger(fs.lstatSync(file, { bigint: true }))) || !sameIdentity(homeIdentity, directoryIdentity(homeDir)) || !sameIdentity(directoryStat, directoryIdentity(directory))) throw new Error("Exit ledger changed");
547836
+ fs.appendFileSync(appendDescriptor, line, { encoding: "utf8" });
547684
547837
  try {
547685
- fs$1.fchmodSync(descriptor, 384);
547838
+ fs.fchmodSync(descriptor, 384);
547686
547839
  } catch {}
547687
547840
  return true;
547688
547841
  } catch {
547689
547842
  return false;
547690
547843
  } finally {
547691
547844
  if (appendDescriptor !== void 0) try {
547692
- fs$1.closeSync(appendDescriptor);
547845
+ fs.closeSync(appendDescriptor);
547693
547846
  } catch {}
547694
547847
  if (descriptor !== void 0) try {
547695
- fs$1.closeSync(descriptor);
547848
+ fs.closeSync(descriptor);
547696
547849
  } catch {}
547697
547850
  }
547698
547851
  }