@craftsamo/telegram-tools 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cli.js CHANGED
@@ -27,6 +27,21 @@ var PROJECT = {
27
27
  toolsets: ["account", "chats", "sync", "files", "sends", "actions"],
28
28
  /** The toolsets on when a setting names none. */
29
29
  defaultToolsets: ["account", "chats", "sync", "sends"],
30
+ /** The package's own settings, which the tools themselves read: each snake_case name and its type, with bounds when it needs them. */
31
+ options: {
32
+ /** Where every account's state lives. */
33
+ state_dir: "path",
34
+ /** Where received files are saved. */
35
+ download_dir: "path",
36
+ /** The largest received file a call may download, in megabytes. */
37
+ download_max_mb: { type: "number", integer: true, min: 1, max: 2e3 },
38
+ /** The directories files may be sent from, besides the working directory. */
39
+ send_dirs: "paths",
40
+ /** Whether messages that disappear are kept; read by the sync service's commands. */
41
+ keep_disappearing: "boolean",
42
+ /** Whether channels are listed and their messages received; read by the sync service's commands. */
43
+ channels: "boolean"
44
+ },
30
45
  /** The environment variables the tools read besides the settings, which Codex forwards to the server after them. */
31
46
  toolVariables: []
32
47
  };
@@ -5101,7 +5116,7 @@ var recursive = /* @__PURE__ */ new WeakMap();
5101
5116
  var NONE = 0;
5102
5117
  var ASSUMED = 1;
5103
5118
  var PROVEN = 2;
5104
- function isRecursive(inst, stack, resolve8) {
5119
+ function isRecursive(inst, stack, resolve6) {
5105
5120
  const cached2 = recursive.get(inst);
5106
5121
  if (cached2 !== void 0)
5107
5122
  return cached2 ? PROVEN : NONE;
@@ -5111,7 +5126,7 @@ function isRecursive(inst, stack, resolve8) {
5111
5126
  let result = NONE;
5112
5127
  const check2 = (child) => {
5113
5128
  if (result !== PROVEN && child?._zod) {
5114
- const answer = isRecursive(child, stack, resolve8);
5129
+ const answer = isRecursive(child, stack, resolve6);
5115
5130
  if (answer > result)
5116
5131
  result = answer;
5117
5132
  }
@@ -5122,7 +5137,7 @@ function isRecursive(inst, stack, resolve8) {
5122
5137
  const desc = Object.getOwnPropertyDescriptor(sh, key);
5123
5138
  if (spread && !desc.enumerable)
5124
5139
  continue;
5125
- const child = desc.get ? ASSUMED : desc.value?._zod ? isRecursive(desc.value, stack, resolve8) : NONE;
5140
+ const child = desc.get ? ASSUMED : desc.value?._zod ? isRecursive(desc.value, stack, resolve6) : NONE;
5126
5141
  if (child > answer)
5127
5142
  answer = child;
5128
5143
  }
@@ -5186,7 +5201,7 @@ function isRecursive(inst, stack, resolve8) {
5186
5201
  break;
5187
5202
  // `$ZodLazy` caches its inner on the def, so a resolved edge is followed exactly
5188
5203
  case "lazy": {
5189
- const inner = def._cachedInner ?? (resolve8 ? inst._zod.innerType : void 0);
5204
+ const inner = def._cachedInner ?? (resolve6 ? inst._zod.innerType : void 0);
5190
5205
  merge2(inner ? isRecursive(inner, stack, false) : ASSUMED);
5191
5206
  break;
5192
5207
  }
@@ -9384,8 +9399,8 @@ function ko_default() {
9384
9399
  }
9385
9400
 
9386
9401
  // node_modules/.pnpm/zod@4.6.7/node_modules/zod/v4/locales/lt.js
9387
- var capitalizeFirstCharacter = (text) => {
9388
- return text.charAt(0).toUpperCase() + text.slice(1);
9402
+ var capitalizeFirstCharacter = (text2) => {
9403
+ return text2.charAt(0).toUpperCase() + text2.slice(1);
9389
9404
  };
9390
9405
  function getUnitTypeFromNumber(number4) {
9391
9406
  const abs2 = Math.abs(number4);
@@ -19792,8 +19807,8 @@ function quoteBadLabel(value) {
19792
19807
  const truncated = value.length > MAX_BAD_LABEL_PREVIEW ? `${value.slice(0, MAX_BAD_LABEL_PREVIEW)}\u2026` : value;
19793
19808
  return JSON.stringify(truncated);
19794
19809
  }
19795
- function isLabel(text) {
19796
- return typeof text === "string" && LABEL_PATTERN.test(text);
19810
+ function isLabel(text2) {
19811
+ return typeof text2 === "string" && LABEL_PATTERN.test(text2);
19797
19812
  }
19798
19813
  function checkLabel(label) {
19799
19814
  if (!isLabel(label)) {
@@ -20249,10 +20264,10 @@ var MILLISECOND_DIGITS = 3;
20249
20264
  var MIN_YEAR = 1e3;
20250
20265
  var MAX_HOUR = 23;
20251
20266
  var MAX_MINUTE = 59;
20252
- function badTime(text, name) {
20267
+ function badTime(text2, name) {
20253
20268
  return new ToolError(
20254
20269
  "invalid_argument",
20255
- `${name} is not a time: ${JSON.stringify(text)}. Use RFC 3339 with an offset (2026-11-07T14:03:12+09:00), or a date or time without one (2026-11-07, 2026-11-07T14:03), which reads as local time.`
20270
+ `${name} is not a time: ${JSON.stringify(text2)}. Use RFC 3339 with an offset (2026-11-07T14:03:12+09:00), or a date or time without one (2026-11-07, 2026-11-07T14:03), which reads as local time.`
20256
20271
  );
20257
20272
  }
20258
20273
  function isCalendarDay(year, month, day) {
@@ -20260,21 +20275,21 @@ function isCalendarDay(year, month, day) {
20260
20275
  date5.setUTCFullYear(year, month - 1, day);
20261
20276
  return date5.getUTCFullYear() === year && date5.getUTCMonth() === month - 1 && date5.getUTCDate() === day;
20262
20277
  }
20263
- function parseTimeArgument(text, name) {
20264
- const match = TIME_PATTERN.exec(text.trim());
20265
- if (!match) throw badTime(text, name);
20278
+ function parseTimeArgument(text2, name) {
20279
+ const match = TIME_PATTERN.exec(text2.trim());
20280
+ if (!match) throw badTime(text2, name);
20266
20281
  const [, year, month, day, hour = "0", minute = "0", second = "0", fraction = "", zulu, sign, offsetHour, offsetMin] = match;
20267
20282
  const [y, mon, d, h2, mi, s] = [year, month, day, hour, minute, second].map(Number);
20268
20283
  const ms = Number(fraction.padEnd(MILLISECOND_DIGITS, "0").slice(0, MILLISECOND_DIGITS));
20269
20284
  if (y < MIN_YEAR || !isCalendarDay(y, mon, d) || h2 > MAX_HOUR || mi > MAX_MINUTE || s > MAX_MINUTE) {
20270
- throw badTime(text, name);
20285
+ throw badTime(text2, name);
20271
20286
  }
20272
20287
  if (sign === void 0 && zulu === void 0) return new Date(y, mon - 1, d, h2, mi, s, ms).getTime();
20273
20288
  const wall = Date.UTC(y, mon - 1, d, h2, mi, s, ms);
20274
20289
  if (zulu) return wall;
20275
20290
  const offsetH = Number(offsetHour);
20276
20291
  const offsetM = Number(offsetMin);
20277
- if (offsetH > MAX_HOUR || offsetM > MAX_MINUTE) throw badTime(text, name);
20292
+ if (offsetH > MAX_HOUR || offsetM > MAX_MINUTE) throw badTime(text2, name);
20278
20293
  const offset = (offsetH * MINUTES_PER_HOUR + offsetM) * MS_PER_MINUTE;
20279
20294
  return sign === "-" ? wall + offset : wall - offset;
20280
20295
  }
@@ -20623,23 +20638,23 @@ function encodeCursor(value) {
20623
20638
  function notACursor(name) {
20624
20639
  return new ToolError("invalid_argument", `${name} is not a cursor this tool returned.`);
20625
20640
  }
20626
- function decodeCursor(text, name) {
20627
- const bytes2 = Buffer3.from(text, "base64url");
20628
- if (bytes2.toString("base64url") !== text) throw notACursor(name);
20641
+ function decodeCursor(text2, name) {
20642
+ const bytes2 = Buffer3.from(text2, "base64url");
20643
+ if (bytes2.toString("base64url") !== text2) throw notACursor(name);
20629
20644
  try {
20630
20645
  return JSON.parse(bytes2.toString("utf8"));
20631
20646
  } catch {
20632
20647
  throw notACursor(name);
20633
20648
  }
20634
20649
  }
20635
- function readCursor(text, name, schema) {
20636
- const parsed = schema.safeParse(decodeCursor(text, name));
20650
+ function readCursor(text2, name, schema) {
20651
+ const parsed = schema.safeParse(decodeCursor(text2, name));
20637
20652
  if (!parsed.success) throw notACursor(name);
20638
20653
  return parsed.data;
20639
20654
  }
20640
20655
  var HIGH_SURROGATE = /[\uD800-\uDBFF]$/;
20641
- function cutText(text, keep) {
20642
- return text.length <= keep ? text : text.slice(0, keep).replace(HIGH_SURROGATE, "");
20656
+ function cutText(text2, keep) {
20657
+ return text2.length <= keep ? text2 : text2.slice(0, keep).replace(HIGH_SURROGATE, "");
20643
20658
  }
20644
20659
  function jsonLength(value) {
20645
20660
  return JSON.stringify(value).length;
@@ -20789,15 +20804,15 @@ var ERROR_CODES = {
20789
20804
  function isErrorCode(value) {
20790
20805
  return typeof value === "string" && Object.hasOwn(ERROR_CODES, value);
20791
20806
  }
20792
- function maskPhoneNumbers(text) {
20793
- return text.replace(PHONE_NUMBER, "[number]");
20807
+ function maskPhoneNumbers(text2) {
20808
+ return text2.replace(PHONE_NUMBER, "[number]");
20794
20809
  }
20795
20810
  function cut(message2) {
20796
20811
  return maskPhoneNumbers(message2).trim().slice(0, MAX_DETAIL_LENGTH);
20797
20812
  }
20798
20813
  function detail(message2) {
20799
- const text = cut(message2);
20800
- return text ? `: ${text}` : "";
20814
+ const text2 = cut(message2);
20815
+ return text2 ? `: ${text2}` : "";
20801
20816
  }
20802
20817
  function afterWriteError(method, effect, reason) {
20803
20818
  return effect === "write" ? new ToolError("uncertain", `${method} may have taken effect (${reason}). ${UNCERTAIN_ADVICE}`) : new ToolError("upstream_error", `${method} failed (${reason}).`);
@@ -20918,7 +20933,7 @@ function abortError(signal) {
20918
20933
  }
20919
20934
  function exec(argv, options) {
20920
20935
  const { signal } = options;
20921
- return new Promise((resolve8, reject) => {
20936
+ return new Promise((resolve6, reject) => {
20922
20937
  if (signal?.aborted) {
20923
20938
  reject(abortError(signal));
20924
20939
  return;
@@ -20977,7 +20992,7 @@ function exec(argv, options) {
20977
20992
  }
20978
20993
  const finish2 = () => settle3(() => {
20979
20994
  const { code, killedBy } = exitedWith ?? { code: null, killedBy: null };
20980
- resolve8({
20995
+ resolve6({
20981
20996
  code: code ?? -1,
20982
20997
  stdout,
20983
20998
  stderr,
@@ -21071,19 +21086,19 @@ var ServiceConnection = class _ServiceConnection {
21071
21086
  socket.on("error", (error62) => {
21072
21087
  this.endReason ??= `the connection to the service broke${error62.code ? ` (${error62.code})` : ""}`;
21073
21088
  });
21074
- this.closed = new Promise((resolve8) => {
21089
+ this.closed = new Promise((resolve6) => {
21075
21090
  socket.once("close", () => {
21076
21091
  this.endReason ??= "the service closed the connection";
21077
21092
  const lost = { lost: this.endReason };
21078
21093
  for (const settle3 of [...this.pending.values()]) settle3(lost);
21079
- resolve8();
21094
+ resolve6();
21080
21095
  });
21081
21096
  });
21082
21097
  }
21083
21098
  /** Connects to the service's socket; rejects as `upstream_error` when nothing is listening there. */
21084
21099
  static connect(socketPath, options = {}) {
21085
21100
  const { timeoutMs = DEFAULT_CONNECT_TIMEOUT_MS, signal, maxLineLength = DEFAULT_MAX_LINE_LENGTH } = options;
21086
- return new Promise((resolve8, reject) => {
21101
+ return new Promise((resolve6, reject) => {
21087
21102
  if (signal?.aborted) {
21088
21103
  reject(abortError(signal));
21089
21104
  return;
@@ -21105,7 +21120,7 @@ var ServiceConnection = class _ServiceConnection {
21105
21120
  };
21106
21121
  const onConnect = () => {
21107
21122
  detach();
21108
- resolve8(new _ServiceConnection(socket, maxLineLength));
21123
+ resolve6(new _ServiceConnection(socket, maxLineLength));
21109
21124
  };
21110
21125
  const onFailure = () => stop(new ToolError("upstream_error", NOT_RUNNING_MESSAGE));
21111
21126
  const onAbort2 = () => stop(abortError(signal));
@@ -21128,7 +21143,7 @@ var ServiceConnection = class _ServiceConnection {
21128
21143
  */
21129
21144
  call(method, params, options) {
21130
21145
  const { effect, timeoutMs = DEFAULT_CALL_TIMEOUT_MS, signal } = options;
21131
- return new Promise((resolve8, reject) => {
21146
+ return new Promise((resolve6, reject) => {
21132
21147
  if (signal?.aborted) {
21133
21148
  reject(abortError(signal));
21134
21149
  return;
@@ -21157,7 +21172,7 @@ var ServiceConnection = class _ServiceConnection {
21157
21172
  clearTimeout(timer);
21158
21173
  signal?.removeEventListener("abort", onAbort2);
21159
21174
  try {
21160
- resolve8(produce());
21175
+ resolve6(produce());
21161
21176
  } catch (error62) {
21162
21177
  reject(error62);
21163
21178
  }
@@ -21477,10 +21492,10 @@ function replyTo(parsed, related) {
21477
21492
  if (reply.chat !== void 0) entry2.chat = reply.chat;
21478
21493
  if (reply.topic !== void 0) entry2.topic = reply.topic;
21479
21494
  if (reply.quote !== void 0) entry2.quote = reply.quote;
21480
- const text = repliedText(parsed, related)?.text;
21481
- if (text !== void 0) {
21482
- entry2.text = cutText(text, REPLY_TEXT_LENGTH);
21483
- if (entry2.text.length < text.length) entry2.text_cut = true;
21495
+ const text2 = repliedText(parsed, related)?.text;
21496
+ if (text2 !== void 0) {
21497
+ entry2.text = cutText(text2, REPLY_TEXT_LENGTH);
21498
+ if (entry2.text.length < text2.length) entry2.text_cut = true;
21484
21499
  }
21485
21500
  return entry2;
21486
21501
  }
@@ -21549,25 +21564,25 @@ function texts(entry2) {
21549
21564
  ];
21550
21565
  }
21551
21566
  function messageTextLength(entry2) {
21552
- return texts(entry2).reduce((total, text) => total + text.length, 0);
21567
+ return texts(entry2).reduce((total, text2) => total + text2.length, 0);
21553
21568
  }
21554
21569
  function cutMessage(entry2, keep) {
21555
21570
  let room = keep;
21556
21571
  let cut3 = false;
21557
- const take = (text) => {
21558
- const kept = cutText(text, room);
21559
- room = Math.max(0, room - text.length);
21560
- if (kept.length < text.length) cut3 = true;
21572
+ const take = (text2) => {
21573
+ const kept = cutText(text2, room);
21574
+ room = Math.max(0, room - text2.length);
21575
+ if (kept.length < text2.length) cut3 = true;
21561
21576
  return kept;
21562
21577
  };
21563
21578
  const cutEntry = { ...entry2 };
21564
21579
  if (entry2.text !== void 0) cutEntry.text = take(entry2.text);
21565
21580
  if (entry2.reply_to) {
21566
- const { quote, text } = entry2.reply_to;
21581
+ const { quote, text: text2 } = entry2.reply_to;
21567
21582
  cutEntry.reply_to = {
21568
21583
  ...entry2.reply_to,
21569
21584
  ...quote === void 0 ? {} : { quote: take(quote) },
21570
- ...text === void 0 ? {} : { text: take(text) }
21585
+ ...text2 === void 0 ? {} : { text: take(text2) }
21571
21586
  };
21572
21587
  }
21573
21588
  if (entry2.earlier_versions)
@@ -21816,8 +21831,8 @@ function fetchResult(read, stored) {
21816
21831
  }
21817
21832
 
21818
21833
  // src/core/fold.ts
21819
- function foldCase(text) {
21820
- return text.normalize("NFKC").toUpperCase().toLowerCase().replace(/ς/g, "\u03C3");
21834
+ function foldCase(text2) {
21835
+ return text2.normalize("NFKC").toUpperCase().toLowerCase().replace(/ς/g, "\u03C3");
21821
21836
  }
21822
21837
 
21823
21838
  // src/core/chat/filter.ts
@@ -21956,8 +21971,8 @@ function foldedFileName(media) {
21956
21971
  return isRecord(info) && typeof info.name === "string" ? foldCase(info.name) : void 0;
21957
21972
  }
21958
21973
  function matchesAllWords(row, words2) {
21959
- const text = foldCase(row.body ?? "");
21960
- const unmatched = words2.filter((word) => !text.includes(word));
21974
+ const text2 = foldCase(row.body ?? "");
21975
+ const unmatched = words2.filter((word) => !text2.includes(word));
21961
21976
  if (unmatched.length === 0) return true;
21962
21977
  const name = row.media === null ? void 0 : foldedFileName(row.media);
21963
21978
  return name !== void 0 && unmatched.every((word) => name.includes(word));
@@ -22601,11 +22616,11 @@ var ANIMATED_STICKER = "an animated sticker (.tgs), which cannot be inspected";
22601
22616
  function unreadableArchive(label) {
22602
22617
  return `an archive that cannot be inspected (${label})`;
22603
22618
  }
22604
- function words(text) {
22605
- return text.split(/\s+/).filter((word) => word !== "");
22619
+ function words(text2) {
22620
+ return text2.split(/\s+/).filter((word) => word !== "");
22606
22621
  }
22607
- function ascii(text) {
22608
- return Array.from(text, (character) => character.charCodeAt(0));
22622
+ function ascii(text2) {
22623
+ return Array.from(text2, (character) => character.charCodeAt(0));
22609
22624
  }
22610
22625
  function at(offset, bytes2) {
22611
22626
  return { offset, bytes: bytes2 };
@@ -22863,9 +22878,9 @@ function parseHeader(block) {
22863
22878
  }
22864
22879
  return { path, size: parseNumber(block.subarray(SIZE_START, SIZE_END)), type: block[TYPE_OFFSET] };
22865
22880
  }
22866
- function parseDecimal(text) {
22867
- if (!/^[0-9]{1,15}$/.test(text)) return void 0;
22868
- return Number(text);
22881
+ function parseDecimal(text2) {
22882
+ if (!/^[0-9]{1,15}$/.test(text2)) return void 0;
22883
+ return Number(text2);
22869
22884
  }
22870
22885
  function parsePaxRecords(data, maxRecords = Infinity) {
22871
22886
  const records = [];
@@ -23055,8 +23070,8 @@ var EXTENSIONS = {
23055
23070
  };
23056
23071
  var KIND_PATTERN = /^[a-z]{1,16}$/;
23057
23072
  var UNKNOWN_KIND = "file";
23058
- function byteLength(text) {
23059
- return Buffer5.byteLength(text);
23073
+ function byteLength(text2) {
23074
+ return Buffer5.byteLength(text2);
23060
23075
  }
23061
23076
  function extensionOf2(type3) {
23062
23077
  return type3 == null ? "" : EXTENSIONS[type3.split(";")[0].trim().toLowerCase()] ?? "";
@@ -23372,8 +23387,8 @@ function fitListings(result) {
23372
23387
  var MAX_NAME_CHARACTERS = 255;
23373
23388
  var CUT_MARK = "\u2026";
23374
23389
  var HIDDEN_CHARACTERS = /[\u0000-\u001F\u007F-\u009F\u00AD\u034F\u061C\u115F\u1160\u17B4\u17B5\u180B-\u180F\u200B-\u200F\u2028-\u202E\u2060-\u206F\u3164\uFE00-\uFE0D\uFEFF\uFFA0\uFFF9-\uFFFC\u{1D173}-\u{1D17A}\u{E0000}-\u{E007F}]/gu;
23375
- function cleanName(text) {
23376
- const cleaned = text.normalize("NFC").replace(HIDDEN_CHARACTERS, "?");
23390
+ function cleanName(text2) {
23391
+ const cleaned = text2.normalize("NFC").replace(HIDDEN_CHARACTERS, "?");
23377
23392
  const characters = Array.from(cleaned);
23378
23393
  if (characters.length <= MAX_NAME_CHARACTERS) return cleaned;
23379
23394
  return characters.slice(0, MAX_NAME_CHARACTERS - CUT_MARK.length).join("") + CUT_MARK;
@@ -23546,9 +23561,9 @@ function decodeUtf8Lossy(bytes2) {
23546
23561
  return LOSSY_UTF8.decode(bytes2);
23547
23562
  }
23548
23563
  function decodeCp437(bytes2) {
23549
- let text = "";
23550
- for (const byte of bytes2) text += byte < ASCII_END ? String.fromCharCode(byte) : CP437_HIGH[byte - ASCII_END];
23551
- return text;
23564
+ let text2 = "";
23565
+ for (const byte of bytes2) text2 += byte < ASCII_END ? String.fromCharCode(byte) : CP437_HIGH[byte - ASCII_END];
23566
+ return text2;
23552
23567
  }
23553
23568
 
23554
23569
  // src/core/archive/tar.ts
@@ -24607,14 +24622,14 @@ function storedReactions(json2) {
24607
24622
  function ownReaction(reactions) {
24608
24623
  return reactions.find((reaction2) => reaction2.mine)?.emoji;
24609
24624
  }
24610
- function checkEditable({ kind, body, captioned }, text) {
24625
+ function checkEditable({ kind, body, captioned }, text2) {
24611
24626
  if (kind === "service" || body === null && !captioned) {
24612
24627
  throw new ToolError("invalid_argument", "This message has no text or caption to edit; nothing was edited.");
24613
24628
  }
24614
- if (body === text) {
24629
+ if (body === text2) {
24615
24630
  throw new ToolError("invalid_argument", "The text is the same as the message's; nothing to edit.");
24616
24631
  }
24617
- if (captioned && text.length > CAPTION_MAX_UNITS) {
24632
+ if (captioned && text2.length > CAPTION_MAX_UNITS) {
24618
24633
  throw new ToolError(
24619
24634
  "invalid_argument",
24620
24635
  `A caption must be at most ${CAPTION_MAX_UNITS} characters; nothing was edited.`
@@ -24623,8 +24638,8 @@ function checkEditable({ kind, body, captioned }, text) {
24623
24638
  }
24624
24639
 
24625
24640
  // src/core/message/arguments.ts
24626
- function checkedText(text) {
24627
- const trimmed = text.trim();
24641
+ function checkedText(text2) {
24642
+ const trimmed = text2.trim();
24628
24643
  if (trimmed === "") throw new ToolError("invalid_argument", "text is blank; give the text to send.");
24629
24644
  if (trimmed.length > TEXT_MAX_UNITS) {
24630
24645
  throw new ToolError(
@@ -24682,8 +24697,8 @@ var Window = class {
24682
24697
  get tail() {
24683
24698
  return this.#tail;
24684
24699
  }
24685
- sees(text) {
24686
- const all = this.#tail + text;
24700
+ sees(text2) {
24701
+ const all = this.#tail + text2;
24687
24702
  this.#tail = all.slice(-TAIL_LENGTH);
24688
24703
  return MARKER.test(all);
24689
24704
  }
@@ -24693,13 +24708,13 @@ var PrivateKeyScan = class {
24693
24708
  #withoutNuls;
24694
24709
  /** Feeds the next chunk; whether a marker starts anywhere in the bytes so far. */
24695
24710
  sees(chunk) {
24696
- const text = Buffer.from(chunk.buffer, chunk.byteOffset, chunk.byteLength).toString("latin1");
24711
+ const text2 = Buffer.from(chunk.buffer, chunk.byteOffset, chunk.byteLength).toString("latin1");
24697
24712
  const before = this.#plain.tail;
24698
- const plain2 = this.#plain.sees(text);
24699
- if (this.#withoutNuls === void 0 && text.includes(NUL)) {
24713
+ const plain2 = this.#plain.sees(text2);
24714
+ if (this.#withoutNuls === void 0 && text2.includes(NUL)) {
24700
24715
  this.#withoutNuls = new Window(before);
24701
24716
  }
24702
- const stripped = this.#withoutNuls?.sees(text.replaceAll(NUL, "")) ?? false;
24717
+ const stripped = this.#withoutNuls?.sees(text2.replaceAll(NUL, "")) ?? false;
24703
24718
  return plain2 || stripped;
24704
24719
  }
24705
24720
  };
@@ -25325,12 +25340,12 @@ var DUPLICATE_NOTE = "An earlier delivery of this same call had already gone out
25325
25340
  var DUPLICATE_UNKNOWN_ID_NOTE = `${DUPLICATE_NOTE} Its id is not known yet; \`telegram_chat_read\` shows it once the service receives it.`;
25326
25341
 
25327
25342
  // src/core/message/uncertain.ts
25328
- function sentLike(paths, chat, text, startedAt) {
25343
+ function sentLike(paths, chat, text2, startedAt) {
25329
25344
  const rows = readMirror(
25330
25345
  paths,
25331
25346
  (mirror) => mirror.prepare(
25332
25347
  "SELECT id, ts FROM messages WHERE chat = ? AND from_me = 1 AND body = ? AND ts >= ? ORDER BY ts DESC, id DESC LIMIT ?"
25333
- ).all(chat, text, startedAt - SENT_LOOKBACK_MS, MAX_SENT_LIKE)
25348
+ ).all(chat, text2, startedAt - SENT_LOOKBACK_MS, MAX_SENT_LIKE)
25334
25349
  );
25335
25350
  return rows.map(({ id, ts }) => ({ id, time: formatLocalTime(ts) }));
25336
25351
  }
@@ -25350,8 +25365,8 @@ function withFound(error62, find, describe3) {
25350
25365
  details: { ...error62.details, sent_like_this: found }
25351
25366
  });
25352
25367
  }
25353
- function withSentLike(error62, paths, chat, text, startedAt) {
25354
- return withFound(error62, () => sentLike(paths, chat, text, startedAt), sentence);
25368
+ function withSentLike(error62, paths, chat, text2, startedAt) {
25369
+ return withFound(error62, () => sentLike(paths, chat, text2, startedAt), sentence);
25355
25370
  }
25356
25371
 
25357
25372
  // src/core/file/send/uncertain.ts
@@ -25488,17 +25503,17 @@ var MAX_HEADLINE_VALUES = 8;
25488
25503
  var MAX_HEADLINE_VALUE_LENGTH = 80;
25489
25504
  var MAX_PINS = 16;
25490
25505
  var HEADLINE_PLACEHOLDER = /\{([A-Za-z_][A-Za-z0-9_]*)\}/;
25491
- function cut2(text, limit) {
25492
- const points = Array.from(text);
25493
- return points.length > limit ? `${points.slice(0, limit - 1).join("")}\u2026` : text;
25506
+ function cut2(text2, limit) {
25507
+ const points = Array.from(text2);
25508
+ return points.length > limit ? `${points.slice(0, limit - 1).join("")}\u2026` : text2;
25494
25509
  }
25495
- function omittedBy(text, limit) {
25496
- const length = Array.from(text).length;
25510
+ function omittedBy(text2, limit) {
25511
+ const length = Array.from(text2).length;
25497
25512
  return length > limit ? length - (limit - 1) : 0;
25498
25513
  }
25499
- function templatePlaceholders(text) {
25514
+ function templatePlaceholders(text2) {
25500
25515
  const names = /* @__PURE__ */ new Set();
25501
- const parts = text.split(HEADLINE_PLACEHOLDER);
25516
+ const parts = text2.split(HEADLINE_PLACEHOLDER);
25502
25517
  for (const [index, part] of parts.entries()) {
25503
25518
  if (index % 2 === 1) names.add(part);
25504
25519
  else if (/[{}]/.test(part)) return void 0;
@@ -25516,10 +25531,10 @@ function valueEntries(values) {
25516
25531
  const entries = Object.entries(values);
25517
25532
  return entries.length > MAX_HEADLINE_VALUES ? void 0 : entries;
25518
25533
  }
25519
- function isTemplate(text, limit, entries) {
25520
- if (text.trim() === "" || Array.from(text).length > limit) return false;
25534
+ function isTemplate(text2, limit, entries) {
25535
+ if (text2.trim() === "" || Array.from(text2).length > limit) return false;
25521
25536
  const given = new Set(entries.map(([name]) => name));
25522
- const placeholders2 = templatePlaceholders(text);
25537
+ const placeholders2 = templatePlaceholders(text2);
25523
25538
  return placeholders2 !== void 0 && [...placeholders2].every((name) => given.has(name));
25524
25539
  }
25525
25540
  function isTemplateValue(value) {
@@ -25535,15 +25550,15 @@ function isFact(fact) {
25535
25550
  }
25536
25551
  function cutValue(value) {
25537
25552
  if (typeof value === "string") return cut2(value, MAX_VALUE_LENGTH);
25538
- const { text, values } = value;
25539
- if (values === void 0) return { text };
25553
+ const { text: text2, values } = value;
25554
+ if (values === void 0) return { text: text2 };
25540
25555
  const cutValues = Object.entries(values).map(
25541
25556
  ([name, entry2]) => [name, typeof entry2 === "string" ? cut2(entry2, MAX_VALUE_LENGTH) : entry2]
25542
25557
  );
25543
- return { text, values: Object.fromEntries(cutValues) };
25558
+ return { text: text2, values: Object.fromEntries(cutValues) };
25544
25559
  }
25545
- function isText2(text) {
25546
- return isRecord2(text) && typeof text.label === "string" && text.label.trim() !== "" && typeof text.body === "string";
25560
+ function isText2(text2) {
25561
+ return isRecord2(text2) && typeof text2.label === "string" && text2.label.trim() !== "" && typeof text2.body === "string";
25547
25562
  }
25548
25563
  function pinsOf(pins) {
25549
25564
  if (pins === void 0) return {};
@@ -25557,32 +25572,32 @@ function pinsOf(pins) {
25557
25572
  }
25558
25573
  function copyValue(value) {
25559
25574
  if (typeof value === "string") return value;
25560
- const { text, values } = value;
25561
- return values === void 0 ? { text } : { text, values: { ...values } };
25575
+ const { text: text2, values } = value;
25576
+ return values === void 0 ? { text: text2 } : { text: text2, values: { ...values } };
25562
25577
  }
25563
25578
  function headlineOf(headline) {
25564
25579
  if (!isRecord2(headline) || typeof headline.text !== "string") return void 0;
25565
- const { text, values } = headline;
25580
+ const { text: text2, values } = headline;
25566
25581
  const entries = valueEntries(values);
25567
- if (entries === void 0 || !isTemplate(text, MAX_HEADLINE_LENGTH, entries)) return void 0;
25582
+ if (entries === void 0 || !isTemplate(text2, MAX_HEADLINE_LENGTH, entries)) return void 0;
25568
25583
  if (!entries.every((entry2) => typeof entry2[1] === "string")) return void 0;
25569
- return values === void 0 ? { text } : { text, values: Object.fromEntries(entries) };
25584
+ return values === void 0 ? { text: text2 } : { text: text2, values: Object.fromEntries(entries) };
25570
25585
  }
25571
- function cutHeadline({ text, values }) {
25572
- if (values === void 0) return { text };
25586
+ function cutHeadline({ text: text2, values }) {
25587
+ if (values === void 0) return { text: text2 };
25573
25588
  const cutValues = Object.entries(values).map(
25574
25589
  ([name, value]) => [name, cut2(value, MAX_HEADLINE_VALUE_LENGTH)]
25575
25590
  );
25576
- return { text, values: Object.fromEntries(cutValues) };
25591
+ return { text: text2, values: Object.fromEntries(cutValues) };
25577
25592
  }
25578
- function cutDescription({ headline, facts, text, pins }) {
25593
+ function cutDescription({ headline, facts, text: text2, pins }) {
25579
25594
  return {
25580
25595
  ...headline && { headline: cutHeadline(headline) },
25581
25596
  facts: facts.slice(0, MAX_FACTS).map(({ label, value }) => ({
25582
25597
  label: cut2(label, MAX_LABEL_LENGTH),
25583
25598
  value: cutValue(value)
25584
25599
  })),
25585
- ...text && { text: { label: cut2(text.label, MAX_TEXT_LABEL_LENGTH), body: cut2(text.body, MAX_TEXT_LENGTH) } },
25600
+ ...text2 && { text: { label: cut2(text2.label, MAX_TEXT_LABEL_LENGTH), body: cut2(text2.body, MAX_TEXT_LENGTH) } },
25586
25601
  ...pins && { pins }
25587
25602
  };
25588
25603
  }
@@ -25606,9 +25621,9 @@ async function wholeCallDescription(spec, args, ctx) {
25606
25621
  if (kept === void 0) return void 0;
25607
25622
  const facts = entries.map(({ label, value }) => ({ label, value: copyValue(value) }));
25608
25623
  const headline = answer.headline === void 0 ? void 0 : headlineOf(answer.headline);
25609
- const text = answer.text === void 0 || answer.text.body === "" ? void 0 : { label: answer.text.label, body: answer.text.body };
25610
- if (headline === void 0 && facts.length === 0 && text === void 0) return void 0;
25611
- return { ...headline && { headline }, facts, ...text && { text }, ...kept };
25624
+ const text2 = answer.text === void 0 || answer.text.body === "" ? void 0 : { label: answer.text.label, body: answer.text.body };
25625
+ if (headline === void 0 && facts.length === 0 && text2 === void 0) return void 0;
25626
+ return { ...headline && { headline }, facts, ...text2 && { text: text2 }, ...kept };
25612
25627
  }
25613
25628
 
25614
25629
  // src/core/message/action-describe.ts
@@ -25921,10 +25936,10 @@ var telegramMessageDelete = defineTool({
25921
25936
  });
25922
25937
 
25923
25938
  // src/core/message/edit-prepare.ts
25924
- function prepareEdit(mirror, chatId, id, text) {
25939
+ function prepareEdit(mirror, chatId, id, text2) {
25925
25940
  const { chat, message: message2 } = findOwnMessage(mirror, chatId, id, "edit");
25926
25941
  if (!message2) throw deletedMessage();
25927
- checkEditable({ ...message2, captioned: message2.media !== null && takesCaption(message2.media.type) }, text);
25942
+ checkEditable({ ...message2, captioned: message2.media !== null && takesCaption(message2.media.type) }, text2);
25928
25943
  return { chat, message: message2 };
25929
25944
  }
25930
25945
 
@@ -25947,22 +25962,22 @@ var telegramMessageEdit = defineTool({
25947
25962
  input: editInput,
25948
25963
  output: editOutput,
25949
25964
  async describe(args, ctx) {
25950
- const text = checkedText(args.text);
25965
+ const text2 = checkedText(args.text);
25951
25966
  const chat = requireChatId(args.chat, MESSAGE_EDIT_TOOL_ID);
25952
25967
  const paths = await pickPaths(ctx, args.account);
25953
- const target = readMirror(paths, (mirror) => prepareEdit(mirror, chat, args.id, text));
25968
+ const target = readMirror(paths, (mirror) => prepareEdit(mirror, chat, args.id, text2));
25954
25969
  return {
25955
25970
  ...describeAction(EDIT_HEADLINES, target.chat, args.id, target.message),
25956
- text: { label: "New text", body: text }
25971
+ text: { label: "New text", body: text2 }
25957
25972
  };
25958
25973
  },
25959
25974
  targets: (args, ctx) => actionTargets(MESSAGE_EDIT_TOOL_ID, args, ctx),
25960
25975
  async execute(args, ctx) {
25961
25976
  const chat = requireChatId(args.chat, MESSAGE_EDIT_TOOL_ID);
25962
- const text = checkedText(args.text);
25977
+ const text2 = checkedText(args.text);
25963
25978
  const paths = await pickPaths(ctx, args.account);
25964
- readMirror(paths, (mirror) => prepareEdit(mirror, chat, args.id, text));
25965
- const params = { chat, id: args.id, text };
25979
+ readMirror(paths, (mirror) => prepareEdit(mirror, chat, args.id, text2));
25980
+ const params = { chat, id: args.id, text: text2 };
25966
25981
  const edited = await callService(paths.socket, SERVICE_REQUESTS.edit, params, {
25967
25982
  effect: "write",
25968
25983
  signal: ctx.signal,
@@ -26158,7 +26173,7 @@ var telegramMessageSend = defineTool({
26158
26173
  input: input5,
26159
26174
  output: output5,
26160
26175
  async describe(args, ctx) {
26161
- const text = checkedText(args.text);
26176
+ const text2 = checkedText(args.text);
26162
26177
  const chat = requireChatId(args.chat, MESSAGE_SEND_TOOL_ID);
26163
26178
  const paths = await pickPaths(ctx, args.account);
26164
26179
  const { row, title } = readMirror(paths, (mirror) => {
@@ -26170,17 +26185,17 @@ var telegramMessageSend = defineTool({
26170
26185
  headline: { text: "About to send a message to {chat}", values: { chat: row.name } }
26171
26186
  },
26172
26187
  facts: [chatFact(row.kind), ...topicFacts(args.topic, title), ...replyFacts(args.reply_to)],
26173
- text: { label: "Message text", body: text }
26188
+ text: { label: "Message text", body: text2 }
26174
26189
  };
26175
26190
  },
26176
26191
  targets: (args, ctx) => chatTargets(MESSAGE_SEND_TOOL_ID, args, ctx),
26177
26192
  async execute(args, ctx) {
26178
26193
  const chat = requireChatId(args.chat, MESSAGE_SEND_TOOL_ID);
26179
- const text = checkedText(args.text);
26194
+ const text2 = checkedText(args.text);
26180
26195
  const paths = await pickPaths(ctx, args.account);
26181
26196
  const params = {
26182
26197
  chat,
26183
- text,
26198
+ text: text2,
26184
26199
  ...args.topic !== void 0 && { topic: args.topic },
26185
26200
  ...args.reply_to !== void 0 && { reply_to: args.reply_to }
26186
26201
  };
@@ -26193,7 +26208,7 @@ var telegramMessageSend = defineTool({
26193
26208
  });
26194
26209
  return sendResult(chat, sent);
26195
26210
  } catch (error62) {
26196
- throw isToolError(error62) && error62.code === "uncertain" ? withSentLike(error62, paths, chat, text, startedAt) : error62;
26211
+ throw isToolError(error62) && error62.code === "uncertain" ? withSentLike(error62, paths, chat, text2, startedAt) : error62;
26197
26212
  }
26198
26213
  }
26199
26214
  });
@@ -26585,6 +26600,35 @@ var ALL_TRANSLATIONS = mergeTranslations(
26585
26600
  SYNC_TRANSLATIONS
26586
26601
  );
26587
26602
 
26603
+ // src/entry/directory.ts
26604
+ import { homedir as homedir3 } from "node:os";
26605
+ import { isAbsolute as isAbsolute5, resolve as resolve4 } from "node:path";
26606
+ var DOWNLOADS_DIR = "Downloads";
26607
+ var DEFAULT_DOWNLOAD_MAX_MB = 100;
26608
+ function homeDir(env) {
26609
+ const envHome = env.HOME;
26610
+ if (envHome && isAbsolute5(envHome)) return envHome;
26611
+ return homedir3();
26612
+ }
26613
+ function defaultStateDir(name, env, home) {
26614
+ const xdg = env.XDG_STATE_HOME;
26615
+ return xdg && isAbsolute5(xdg) ? resolve4(xdg, name) : resolve4(home, ".local", "state", name);
26616
+ }
26617
+ function text(value) {
26618
+ return typeof value === "string" ? value : void 0;
26619
+ }
26620
+ function resolveDirectorySettings(options, env, profile) {
26621
+ const home = homeDir(env);
26622
+ const maxMb = options.download_max_mb;
26623
+ const sendDirs = options.send_dirs;
26624
+ return {
26625
+ state_dir: text(options.state_dir) ?? defaultStateDir(profile.name, env, home),
26626
+ download_dir: text(options.download_dir) ?? resolve4(home, DOWNLOADS_DIR, profile.name),
26627
+ download_max_mb: typeof maxMb === "number" ? maxMb : DEFAULT_DOWNLOAD_MAX_MB,
26628
+ send_dirs: Array.isArray(sendDirs) ? [...sendDirs] : []
26629
+ };
26630
+ }
26631
+
26588
26632
  // src/entry/errors.ts
26589
26633
  function errorBody(code, message2, details) {
26590
26634
  return { code, message: message2, ...details !== void 0 && { details } };
@@ -26604,9 +26648,9 @@ function mark(character) {
26604
26648
  const hex3 = character.codePointAt(0).toString(16).toUpperCase();
26605
26649
  return `<U+${hex3.padStart(MARK_DIGITS, "0")}>`;
26606
26650
  }
26607
- function visible(text, options = {}) {
26608
- if (options.keepNewlines) return text.replace(/\r\n/g, "\n").replace(HIDDEN_EXCEPT_NEWLINE, mark);
26609
- return text.replace(HIDDEN_ALL, mark);
26651
+ function visible(text2, options = {}) {
26652
+ if (options.keepNewlines) return text2.replace(/\r\n/g, "\n").replace(HIDDEN_EXCEPT_NEWLINE, mark);
26653
+ return text2.replace(HIDDEN_ALL, mark);
26610
26654
  }
26611
26655
 
26612
26656
  // src/entry/words.ts
@@ -26645,12 +26689,12 @@ var omittedOf = (count) => count > 0 ? { omitted: count } : {};
26645
26689
  function quoted(value) {
26646
26690
  return `"${visible(value).replace(/\\/g, "\\\\").replace(/"/g, '\\"')}"`;
26647
26691
  }
26648
- function filled(text, literal2, slot) {
26649
- return text.split(HEADLINE_PLACEHOLDER).map((part, index) => index % 2 === 0 ? literal2(part) : slot(part)).join("");
26692
+ function filled(text2, literal2, slot) {
26693
+ return text2.split(HEADLINE_PLACEHOLDER).map((part, index) => index % 2 === 0 ? literal2(part) : slot(part)).join("");
26650
26694
  }
26651
- function renderedHeadline({ text, values = {} }) {
26695
+ function renderedHeadline({ text: text2, values = {} }) {
26652
26696
  return filled(
26653
- text,
26697
+ text2,
26654
26698
  (part) => visible(part),
26655
26699
  (name) => quoted(values[name] ?? "")
26656
26700
  );
@@ -26664,7 +26708,7 @@ function renderedValue(value, t) {
26664
26708
  return { value: visible(cut2(whole, MAX_VALUE_LENGTH)), ...omittedOf(omittedBy(whole, MAX_VALUE_LENGTH)) };
26665
26709
  }
26666
26710
  function shownDescription(description, t) {
26667
- const { headline, facts, text } = cutDescription(description);
26711
+ const { headline, facts, text: text2 } = cutDescription(description);
26668
26712
  const wholeBody = description.text?.body ?? "";
26669
26713
  const dropped = description.facts.length - facts.length;
26670
26714
  return {
@@ -26674,9 +26718,9 @@ function shownDescription(description, t) {
26674
26718
  ...renderedValue(description.facts[index].value, t)
26675
26719
  })),
26676
26720
  ...dropped > 0 && { dropped },
26677
- ...text && {
26721
+ ...text2 && {
26678
26722
  text: {
26679
- label: visible(t.word(text.label, MAX_TEXT_LABEL_LENGTH)),
26723
+ label: visible(t.word(text2.label, MAX_TEXT_LABEL_LENGTH)),
26680
26724
  body: visible(cut2(wholeBody, MAX_TEXT_LENGTH), { keepNewlines: true }),
26681
26725
  ...omittedOf(omittedBy(wholeBody, MAX_TEXT_LENGTH))
26682
26726
  }
@@ -26690,9 +26734,9 @@ async function timedCallDescription(spec, args, ctx, timeoutMs = DESCRIBE_TIMEOU
26690
26734
  let timer;
26691
26735
  let onAbort2;
26692
26736
  try {
26693
- const timedOut = new Promise((resolve8) => {
26737
+ const timedOut = new Promise((resolve6) => {
26694
26738
  timer = setTimeout(() => {
26695
- resolve8(void 0);
26739
+ resolve6(void 0);
26696
26740
  controller.abort();
26697
26741
  }, timeoutMs);
26698
26742
  });
@@ -26742,81 +26786,44 @@ async function checkPin(spec, args, ctx, pin, timeoutMs = DESCRIBE_TIMEOUT_MS) {
26742
26786
  var PROJECT_PROFILE = {
26743
26787
  name: PROJECT.name,
26744
26788
  envPrefix: PROJECT.envPrefix,
26745
- toolsets: { names: PROJECT.toolsets, defaults: PROJECT.defaultToolsets }
26789
+ toolsets: { names: PROJECT.toolsets, defaults: PROJECT.defaultToolsets },
26790
+ options: PROJECT.options
26746
26791
  };
26747
26792
 
26748
- // src/entry/download-dir.ts
26749
- import { resolve as resolve5 } from "node:path";
26750
-
26751
- // src/entry/directory.ts
26752
- import { homedir as homedir3 } from "node:os";
26753
- import { isAbsolute as isAbsolute5, join as join11, resolve as resolve4, sep as sep4 } from "node:path";
26754
- function homeDir(env) {
26755
- const envHome = env.HOME;
26756
- if (envHome && isAbsolute5(envHome)) return envHome;
26757
- return homedir3();
26758
- }
26759
- function resolveGivenDirectory(given, home) {
26760
- const text = given.text.trim();
26761
- const expanded = text === "~" ? home : text.startsWith("~/") || text.startsWith(`~${sep4}`) ? join11(home, text.slice(2)) : text;
26762
- if (!text || !isAbsolute5(expanded)) {
26763
- throw new ToolError("invalid_argument", `${given.source} must be an absolute path.`);
26764
- }
26765
- return resolve4(expanded);
26766
- }
26767
-
26768
- // src/entry/download-dir.ts
26769
- var DOWNLOADS_DIR = "Downloads";
26770
- function resolveDownloadDir(given, env, profile) {
26771
- const home = homeDir(env);
26772
- return given !== void 0 ? resolveGivenDirectory(given, home) : resolve5(home, DOWNLOADS_DIR, profile.name);
26773
- }
26774
-
26775
- // src/entry/send-dirs.ts
26776
- function resolveSendDirs(given, env) {
26777
- const home = homeDir(env);
26778
- return given.map((directory) => resolveGivenDirectory(directory, home));
26779
- }
26780
-
26781
- // src/entry/state-dir.ts
26782
- import { isAbsolute as isAbsolute6, resolve as resolve6 } from "node:path";
26783
- function resolveStateDir(given, env, profile) {
26784
- const home = homeDir(env);
26785
- if (given !== void 0) return resolveGivenDirectory(given, home);
26786
- const xdg = env.XDG_STATE_HOME;
26787
- if (xdg && isAbsolute6(xdg)) {
26788
- return resolve6(xdg, profile.name);
26789
- }
26790
- return resolve6(home, ".local", "state", profile.name);
26791
- }
26792
-
26793
26793
  // src/entry/settings.ts
26794
+ import { homedir as homedir4 } from "node:os";
26795
+ import { isAbsolute as isAbsolute6, join as join11, resolve as resolvePath, sep as sep4 } from "node:path";
26794
26796
  var CONFIRM_MODES = ["harness", "elicitation"];
26795
26797
  var ALL_TOOLSETS = "all";
26796
26798
  var TRUE_VALUES = ["1", "true"];
26797
26799
  var FALSE_VALUES = ["0", "false"];
26798
- var DEFAULT_DOWNLOAD_MAX_MB = 100;
26799
- var MAX_DOWNLOAD_MB = 2e3;
26800
26800
  var OPTIONS = {
26801
26801
  toolsets: { flag: "--toolsets", envSuffix: "TOOLSETS" },
26802
26802
  read_only: { flag: "--read-only", envSuffix: "READ_ONLY", boolean: true },
26803
26803
  tools: { flag: "--tools", envSuffix: "TOOLS" },
26804
26804
  exclude_tools: { flag: "--exclude-tools", envSuffix: "EXCLUDE_TOOLS" },
26805
- confirm: { flag: "--confirm", envSuffix: "CONFIRM" },
26806
- state_dir: { flag: "--state-dir", envSuffix: "STATE_DIR" },
26807
- download_dir: { flag: "--download-dir", envSuffix: "DOWNLOAD_DIR" },
26808
- download_max_mb: { flag: "--download-max-mb", envSuffix: "DOWNLOAD_MAX_MB" },
26809
- send_dirs: { flag: "--send-dirs", envSuffix: "SEND_DIRS" },
26810
- keep_disappearing: { flag: "--keep-disappearing", envSuffix: "KEEP_DISAPPEARING", boolean: true },
26811
- channels: { flag: "--channels", envSuffix: "CHANNELS", boolean: true }
26812
- };
26813
- var SERVICE_OPTION_NAMES = ["keep_disappearing", "channels"];
26805
+ confirm: { flag: "--confirm", envSuffix: "CONFIRM" }
26806
+ };
26807
+ function profileOptions(profile) {
26808
+ return profile.options ?? {};
26809
+ }
26810
+ function settingOptions(profile) {
26811
+ const toolOptions = Object.entries(profileOptions(profile)).map(([name, spec]) => [
26812
+ name,
26813
+ {
26814
+ flag: `--${name.replace(/_/g, "-")}`,
26815
+ envSuffix: name.toUpperCase(),
26816
+ ...optionType(spec) === "boolean" && { boolean: true }
26817
+ }
26818
+ ]);
26819
+ return { ...OPTIONS, ...Object.fromEntries(toolOptions) };
26820
+ }
26814
26821
  function envName(name, profile) {
26815
- return `${profile.envPrefix}_${OPTIONS[name].envSuffix}`;
26822
+ return `${profile.envPrefix}_${settingOptions(profile)[name].envSuffix}`;
26816
26823
  }
26817
- function readFlags(argv) {
26824
+ function readFlags(argv, profile) {
26818
26825
  const byFlag = new Map(
26819
- Object.keys(OPTIONS).map((name) => [OPTIONS[name].flag, { name, ...OPTIONS[name] }])
26826
+ Object.entries(settingOptions(profile)).map(([name, option]) => [option.flag, { name, ...option }])
26820
26827
  );
26821
26828
  const given = {};
26822
26829
  for (let i = 0; i < argv.length; i++) {
@@ -26851,9 +26858,9 @@ function checkToolsets(names, source, toolsets) {
26851
26858
  return names.length ? names : void 0;
26852
26859
  }
26853
26860
  function parseBoolean(value, source) {
26854
- const text = value.trim().toLowerCase();
26855
- if (TRUE_VALUES.includes(text)) return true;
26856
- if (FALSE_VALUES.includes(text)) return false;
26861
+ const text2 = value.trim().toLowerCase();
26862
+ if (TRUE_VALUES.includes(text2)) return true;
26863
+ if (FALSE_VALUES.includes(text2)) return false;
26857
26864
  throw new ToolError(
26858
26865
  "invalid_argument",
26859
26866
  `Unknown value "${value}" in ${source}; use one of ${[...TRUE_VALUES, ...FALSE_VALUES].join(", ")}.`
@@ -26869,44 +26876,115 @@ function parseConfirm(value, source) {
26869
26876
  }
26870
26877
  return mode;
26871
26878
  }
26872
- function listedDirectories(given) {
26873
- return given === void 0 ? [] : splitList(given.text).map((text) => ({ text, source: given.source }));
26874
- }
26875
- function downloadMaxMb(value, source) {
26876
- if (typeof value !== "number" || !Number.isInteger(value) || value < 1 || value > MAX_DOWNLOAD_MB) {
26877
- throw new ToolError("invalid_argument", `${source} must be an integer from 1 to ${MAX_DOWNLOAD_MB}.`);
26879
+ function parseNumber2(value, source) {
26880
+ const trimmed = value.trim();
26881
+ const parsed = trimmed === "" ? Number.NaN : Number(trimmed);
26882
+ if (!Number.isFinite(parsed)) {
26883
+ throw new ToolError("invalid_argument", `Unknown number "${value}" in ${source}; use a finite number.`);
26878
26884
  }
26879
- return value;
26885
+ return parsed;
26880
26886
  }
26881
- function downloadMaxMbText({ text, source }) {
26882
- const trimmed = text.trim();
26883
- return downloadMaxMb(/^\d+$/.test(trimmed) ? Number(trimmed) : Number.NaN, source);
26887
+ function absolutePath(text2, source, env) {
26888
+ const home = env.HOME !== void 0 && isAbsolute6(env.HOME) ? env.HOME : homedir4();
26889
+ const expanded = text2 === "~" || text2.startsWith("~/") || text2.startsWith(`~${sep4}`) ? join11(home, text2.slice(1)) : text2;
26890
+ if (!isAbsolute6(expanded)) throw new ToolError("invalid_argument", `${source} must be an absolute path.`);
26891
+ return resolvePath(expanded);
26884
26892
  }
26885
- function downloadSettings(given, env, profile) {
26886
- const value = given ?? ((name) => envText(name, env, profile));
26887
- const max3 = value("download_max_mb");
26888
- return {
26889
- download_dir: resolveDownloadDir(value("download_dir"), env, profile),
26890
- download_max_mb: max3 === void 0 ? DEFAULT_DOWNLOAD_MAX_MB : downloadMaxMbText(max3)
26891
- };
26893
+ function absolutePaths(items, source, env) {
26894
+ return items.length > 0 ? items.map((item) => absolutePath(item, source, env)) : void 0;
26892
26895
  }
26893
26896
  function envText(name, env, profile) {
26894
26897
  const variable = envName(name, profile);
26895
- const text = env[variable];
26896
- return text === void 0 || text.trim() === "" ? void 0 : { text, source: variable };
26898
+ const text2 = env[variable];
26899
+ return text2 === void 0 || text2.trim() === "" ? void 0 : { text: text2, source: variable };
26897
26900
  }
26898
26901
  function flagOrEnvText(flags, name, env, profile) {
26899
26902
  const flagged = flags[name];
26900
26903
  return flagged !== void 0 ? { text: flagged, source: OPTIONS[name].flag } : envText(name, env, profile);
26901
26904
  }
26905
+ function optionType(spec) {
26906
+ return typeof spec === "string" ? spec : spec.type;
26907
+ }
26908
+ function itemCount(count) {
26909
+ return count === 1 ? "1 item" : `${count} items`;
26910
+ }
26911
+ function numberBoundsError({ integer: integer2, min: min3, max: max3 }, source) {
26912
+ const range = min3 !== void 0 && max3 !== void 0 ? ` from ${min3} to ${max3}` : min3 !== void 0 ? ` of at least ${min3}` : max3 !== void 0 ? ` of at most ${max3}` : "";
26913
+ return new ToolError("invalid_argument", `${source} must be ${integer2 ? "a whole number" : "a number"}${range}.`);
26914
+ }
26915
+ function countBoundsError({ min: min3, max: max3 }, source) {
26916
+ const range = min3 !== void 0 && max3 !== void 0 ? `from ${min3} to ${max3} items` : min3 !== void 0 ? `at least ${itemCount(min3)}` : `at most ${itemCount(max3)}`;
26917
+ return new ToolError("invalid_argument", `${source} must list ${range}.`);
26918
+ }
26919
+ function withinBounds(spec, value, source) {
26920
+ if (value === void 0 || typeof spec === "string") return value;
26921
+ const bounds = spec;
26922
+ const { integer: integer2, min: min3, max: max3 } = bounds;
26923
+ if (typeof value === "number") {
26924
+ if (integer2 && !Number.isInteger(value) || min3 !== void 0 && value < min3 || max3 !== void 0 && value > max3) {
26925
+ throw numberBoundsError(bounds, source);
26926
+ }
26927
+ } else if (typeof value === "object" && (min3 !== void 0 && value.length < min3 || max3 !== void 0 && value.length > max3)) {
26928
+ throw countBoundsError(bounds, source);
26929
+ }
26930
+ return value;
26931
+ }
26932
+ function parseOptionText(spec, given, env) {
26933
+ return withinBounds(spec, parseTypedText(optionType(spec), given, env), given.source);
26934
+ }
26935
+ function parseTypedText(kind, given, env) {
26936
+ switch (kind) {
26937
+ case "text":
26938
+ return nonBlank(given.text);
26939
+ case "boolean":
26940
+ return parseBoolean(given.text, given.source);
26941
+ case "number":
26942
+ return parseNumber2(given.text, given.source);
26943
+ case "list": {
26944
+ const items = splitList(given.text);
26945
+ return items.length > 0 ? items : void 0;
26946
+ }
26947
+ case "path": {
26948
+ const text2 = nonBlank(given.text);
26949
+ return text2 === void 0 ? void 0 : absolutePath(text2, given.source, env);
26950
+ }
26951
+ case "paths":
26952
+ return absolutePaths(splitList(given.text), given.source, env);
26953
+ }
26954
+ }
26955
+ function optionsFrom(flags, env, profile) {
26956
+ const options = {};
26957
+ for (const [name, spec] of Object.entries(profileOptions(profile))) {
26958
+ if (flags[name] !== void 0) {
26959
+ const parsed = parseOptionText(spec, { text: flags[name], source: settingOptions(profile)[name].flag }, env);
26960
+ if (parsed !== void 0) options[name] = parsed;
26961
+ continue;
26962
+ }
26963
+ const fromEnv = envText(name, env, profile);
26964
+ if (fromEnv !== void 0) {
26965
+ const parsed = parseOptionText(spec, fromEnv, env);
26966
+ if (parsed !== void 0) options[name] = parsed;
26967
+ }
26968
+ }
26969
+ return options;
26970
+ }
26971
+ function parseToolOptions(argv, env, profile = PROJECT_PROFILE) {
26972
+ const flags = readFlags(argv, profile);
26973
+ const known = profileOptions(profile);
26974
+ const other = Object.keys(flags).find((name) => !(name in known));
26975
+ if (other !== void 0) {
26976
+ throw new ToolError("invalid_argument", `Unknown option "${settingOptions(profile)[other].flag}".`);
26977
+ }
26978
+ return optionsFrom(flags, env, profile);
26979
+ }
26902
26980
  function parseSettings(argv, env, profile = PROJECT_PROFILE) {
26903
- const flags = readFlags(argv);
26981
+ const flags = readFlags(argv, profile);
26904
26982
  const value = (name) => flagOrEnvText(flags, name, env, profile);
26983
+ const options = optionsFrom(flags, env, profile);
26905
26984
  const settings = {
26906
26985
  confirm: "harness",
26907
- state_dir: resolveStateDir(value("state_dir"), env, profile),
26908
- ...downloadSettings(value, env, profile),
26909
- send_dirs: resolveSendDirs(listedDirectories(value("send_dirs")), env)
26986
+ options,
26987
+ ...resolveDirectorySettings(options, env, profile)
26910
26988
  };
26911
26989
  const toolsets = value("toolsets");
26912
26990
  if (toolsets) settings.toolsets = checkToolsets(splitList(toolsets.text), toolsets.source, profile.toolsets);
@@ -26918,10 +26996,6 @@ function parseSettings(argv, env, profile = PROJECT_PROFILE) {
26918
26996
  if (excluded) settings.exclude_tools = splitList(excluded.text);
26919
26997
  const confirm = value("confirm");
26920
26998
  if (confirm) settings.confirm = parseConfirm(confirm.text.trim(), confirm.source);
26921
- for (const name of SERVICE_OPTION_NAMES) {
26922
- const given = value(name);
26923
- if (given) settings[name] = parseBoolean(given.text, given.source);
26924
- }
26925
26999
  return settings;
26926
27000
  }
26927
27001
  function parseToolSettings(argv, env, profile = PROJECT_PROFILE) {
@@ -26936,48 +27010,11 @@ function parseToolSettings(argv, env, profile = PROJECT_PROFILE) {
26936
27010
  );
26937
27011
  return settings;
26938
27012
  }
26939
- function parseStateDir(argv, env, profile = PROJECT_PROFILE) {
26940
- const flags = readFlags(argv);
26941
- const other = Object.keys(flags).find((name) => name !== "state_dir");
26942
- if (other !== void 0)
26943
- throw new ToolError("invalid_argument", `Option ${OPTIONS[other].flag} is not available here.`);
26944
- return resolveStateDir(flagOrEnvText(flags, "state_dir", env, profile), env, profile);
26945
- }
26946
- function parseServiceSettings(argv, env, profile = PROJECT_PROFILE) {
26947
- const flags = readFlags(argv);
26948
- const allowed = ["state_dir", ...SERVICE_OPTION_NAMES];
26949
- const other = Object.keys(flags).find((name) => !allowed.includes(name));
26950
- if (other !== void 0)
26951
- throw new ToolError("invalid_argument", `Option ${OPTIONS[other].flag} is not available here.`);
26952
- const value = (name) => flagOrEnvText(flags, name, env, profile);
26953
- const on = (name) => {
26954
- const given = value(name);
26955
- return given !== void 0 && parseBoolean(given.text, given.source);
26956
- };
26957
- return {
26958
- state_dir: resolveStateDir(value("state_dir"), env, profile),
26959
- keep_disappearing: on("keep_disappearing"),
26960
- channels: on("channels")
26961
- };
26962
- }
26963
- var TOOL_OPTION_NAMES = [
26964
- "toolsets",
26965
- "read_only",
26966
- "tools",
26967
- "exclude_tools",
26968
- "state_dir",
26969
- "download_dir",
26970
- "download_max_mb",
26971
- "send_dirs",
26972
- ...SERVICE_OPTION_NAMES
26973
- ];
26974
- var LANGUAGE_OPTION = "language";
26975
- var PLUGIN_OPTION_NAMES = [...TOOL_OPTION_NAMES, LANGUAGE_OPTION];
26976
27013
  function languageVariable(profile = PROJECT_PROFILE) {
26977
27014
  return `${profile.envPrefix}_LANGUAGE`;
26978
27015
  }
26979
- function nonBlank(text) {
26980
- const trimmed = text?.trim();
27016
+ function nonBlank(text2) {
27017
+ const trimmed = text2?.trim();
26981
27018
  return trimmed === "" ? void 0 : trimmed;
26982
27019
  }
26983
27020
  function promptLanguage(flag2, env, harness, profile = PROJECT_PROFILE) {
@@ -27031,20 +27068,20 @@ function checkApiId(apiId) {
27031
27068
  if (!Number.isSafeInteger(apiId) || apiId <= 0) throw new ToolError("invalid_argument", INVALID_API_ID);
27032
27069
  return apiId;
27033
27070
  }
27034
- function parseApiId(text) {
27035
- const trimmed = text.trim();
27071
+ function parseApiId(text2) {
27072
+ const trimmed = text2.trim();
27036
27073
  if (!API_ID_PATTERN.test(trimmed)) throw new ToolError("invalid_argument", INVALID_API_ID);
27037
27074
  return checkApiId(Number(trimmed));
27038
27075
  }
27039
- function parseApiHash(text) {
27040
- const hash2 = text.trim().toLowerCase();
27076
+ function parseApiHash(text2) {
27077
+ const hash2 = text2.trim().toLowerCase();
27041
27078
  if (!API_HASH_PATTERN.test(hash2)) throw new ToolError("invalid_argument", INVALID_API_HASH);
27042
27079
  return hash2;
27043
27080
  }
27044
27081
  function readApp(path) {
27045
- let text;
27082
+ let text2;
27046
27083
  try {
27047
- text = readFileSync3(path, "utf8");
27084
+ text2 = readFileSync3(path, "utf8");
27048
27085
  } catch (error62) {
27049
27086
  if (error62.code === "ENOENT") {
27050
27087
  throw new ToolError("not_found", "This account has no app credentials yet; log in first.");
@@ -27052,7 +27089,7 @@ function readApp(path) {
27052
27089
  throw new ToolError("upstream_error", UNREADABLE_APP);
27053
27090
  }
27054
27091
  try {
27055
- const parsed = JSON.parse(text);
27092
+ const parsed = JSON.parse(text2);
27056
27093
  if (typeof parsed.api_id !== "number" || typeof parsed.api_hash !== "string") throw new Error("malformed");
27057
27094
  return { apiId: checkApiId(parsed.api_id), apiHash: parseApiHash(parsed.api_hash) };
27058
27095
  } catch {
@@ -28840,16 +28877,16 @@ function _isAny2() {
28840
28877
  }
28841
28878
  var LAYER = 232;
28842
28879
  var RpcError = class _RpcError extends Error {
28843
- constructor(code, text) {
28844
- super("Telegram API error " + code + ": " + text);
28880
+ constructor(code, text2) {
28881
+ super("Telegram API error " + code + ": " + text2);
28845
28882
  this.code = code;
28846
- this.text = text;
28883
+ this.text = text2;
28847
28884
  }
28848
- static is(err, text) {
28849
- return err != null && err.constructor === _RpcError && (!text || err.text === text);
28885
+ static is(err, text2) {
28886
+ return err != null && err.constructor === _RpcError && (!text2 || err.text === text2);
28850
28887
  }
28851
- is(text) {
28852
- return this.text === text;
28888
+ is(text2) {
28889
+ return this.text === text2;
28853
28890
  }
28854
28891
  };
28855
28892
  RpcError.fromTl = function(obj) {
@@ -30316,8 +30353,8 @@ var AsyncLock = class {
30316
30353
  this._locked = true;
30317
30354
  return new AsyncLockGuard(this._release);
30318
30355
  }
30319
- return new Promise((resolve8) => {
30320
- this._waiters.pushBack(resolve8);
30356
+ return new Promise((resolve6) => {
30357
+ this._waiters.pushBack(resolve6);
30321
30358
  });
30322
30359
  }
30323
30360
  async with(func) {
@@ -30527,8 +30564,8 @@ var ConditionVariable = class {
30527
30564
  if (this.#promise) {
30528
30565
  return this.#promise;
30529
30566
  }
30530
- return this.#promise = new Promise((resolve8) => {
30531
- this.#notify = resolve8;
30567
+ return this.#promise = new Promise((resolve6) => {
30568
+ this.#notify = resolve6;
30532
30569
  });
30533
30570
  }
30534
30571
  notify() {
@@ -32159,7 +32196,7 @@ function makeInspectable(obj, props, hide2) {
32159
32196
 
32160
32197
  // node_modules/.pnpm/@mtcute+core@0.32.7/node_modules/@mtcute/core/utils/misc-utils.js
32161
32198
  function sleepWithAbort(ms, signal) {
32162
- return new Promise((resolve8, reject) => {
32199
+ return new Promise((resolve6, reject) => {
32163
32200
  let timeout;
32164
32201
  const onAbort2 = () => {
32165
32202
  timers_exports.clearTimeout(timeout);
@@ -32168,7 +32205,7 @@ function sleepWithAbort(ms, signal) {
32168
32205
  signal.addEventListener("abort", onAbort2);
32169
32206
  timeout = timers_exports.setTimeout(() => {
32170
32207
  signal.removeEventListener("abort", onAbort2);
32171
- resolve8();
32208
+ resolve6();
32172
32209
  }, ms);
32173
32210
  });
32174
32211
  }
@@ -34161,19 +34198,19 @@ var User = class _User {
34161
34198
  * msg.replyText(html`Hello, ${msg.sender.mention()`)
34162
34199
  * ```
34163
34200
  */
34164
- mention(text) {
34165
- if (text === void 0 && this.username) {
34201
+ mention(text2) {
34202
+ if (text2 === void 0 && this.username) {
34166
34203
  return `@${this.username}`;
34167
34204
  }
34168
- if (!text) text = this.displayName;
34205
+ if (!text2) text2 = this.displayName;
34169
34206
  return new MessageEntity$2(
34170
34207
  {
34171
34208
  _: "messageEntityMentionName",
34172
34209
  offset: 0,
34173
- length: text.length,
34210
+ length: text2.length,
34174
34211
  userId: this.raw.id
34175
34212
  },
34176
- text
34213
+ text2
34177
34214
  );
34178
34215
  }
34179
34216
  /**
@@ -34213,19 +34250,19 @@ var User = class _User {
34213
34250
  *
34214
34251
  * @param text Mention text
34215
34252
  */
34216
- permanentMention(text) {
34253
+ permanentMention(text2) {
34217
34254
  if (!this.raw.accessHash) {
34218
34255
  throw new MtArgumentError("User's access hash is not available!");
34219
34256
  }
34220
- if (!text) text = this.displayName;
34257
+ if (!text2) text2 = this.displayName;
34221
34258
  return new MessageEntity$2(
34222
34259
  {
34223
34260
  _: "messageEntityTextUrl",
34224
34261
  offset: 0,
34225
- length: text.length,
34262
+ length: text2.length,
34226
34263
  url: `tg://user?id=${this.id}&hash=${this.raw.accessHash.toString(16)}`
34227
34264
  },
34228
- text
34265
+ text2
34229
34266
  );
34230
34267
  }
34231
34268
  };
@@ -34286,10 +34323,10 @@ var GameHighScore$1 = /* @__PURE__ */ memoizeGetters(GameHighScore, ["user"]);
34286
34323
  var GameHighScore$2 = /* @__PURE__ */ makeInspectable(GameHighScore$1);
34287
34324
 
34288
34325
  // node_modules/.pnpm/@mtcute+core@0.32.7/node_modules/@mtcute/core/highlevel/utils/walk-page-blocks.js
34289
- function walkRichText(text, visitor) {
34290
- if (!text) return;
34291
- visitor.richText?.(text);
34292
- switch (text._) {
34326
+ function walkRichText(text2, visitor) {
34327
+ if (!text2) return;
34328
+ visitor.richText?.(text2);
34329
+ switch (text2._) {
34293
34330
  case "textEmpty":
34294
34331
  case "textPlain":
34295
34332
  case "textEmail":
@@ -34321,14 +34358,14 @@ function walkRichText(text, visitor) {
34321
34358
  case "textDate":
34322
34359
  case "textMentionName":
34323
34360
  case "textButton":
34324
- walkRichText(text.text, visitor);
34361
+ walkRichText(text2.text, visitor);
34325
34362
  break;
34326
34363
  case "textConcat":
34327
- for (const child of text.texts) walkRichText(child, visitor);
34364
+ for (const child of text2.texts) walkRichText(child, visitor);
34328
34365
  break;
34329
34366
  case "textDiff":
34330
- walkRichText(text.text, visitor);
34331
- walkRichText(text.oldText, visitor);
34367
+ walkRichText(text2.text, visitor);
34368
+ walkRichText(text2.oldText, visitor);
34332
34369
  break;
34333
34370
  default:
34334
34371
  assertNever2();
@@ -34458,11 +34495,11 @@ function isUploadedFile(obj) {
34458
34495
  }
34459
34496
 
34460
34497
  // node_modules/.pnpm/@mtcute+core@0.32.7/node_modules/@mtcute/core/highlevel/types/misc/entities.js
34461
- function inputTextToTl(text) {
34498
+ function inputTextToTl(text2) {
34462
34499
  return {
34463
34500
  _: "textWithEntities",
34464
- text: typeof text === "string" ? text : text.text,
34465
- entities: typeof text === "string" ? [] : text.entities ?? []
34501
+ text: typeof text2 === "string" ? text2 : text2.text,
34502
+ entities: typeof text2 === "string" ? [] : text2.entities ?? []
34466
34503
  };
34467
34504
  }
34468
34505
 
@@ -34756,8 +34793,8 @@ function batchedQuery(params) {
34756
34793
  arr = [];
34757
34794
  waiters.set(key, arr);
34758
34795
  }
34759
- return new Promise((resolve8, reject) => {
34760
- arr.push([item, resolve8, reject]);
34796
+ return new Promise((resolve6, reject) => {
34797
+ arr.push([item, resolve6, reject]);
34761
34798
  });
34762
34799
  }
34763
34800
  function popWaiters(waiters, key) {
@@ -35179,9 +35216,9 @@ async function _normalizeInputText(client, input8) {
35179
35216
  if (typeof input8 === "string") {
35180
35217
  return [input8, void 0];
35181
35218
  }
35182
- let text = input8.text;
35219
+ let text2 = input8.text;
35183
35220
  const entities = input8.entities;
35184
- if (!entities) return [text, void 0];
35221
+ if (!entities) return [text2, void 0];
35185
35222
  let canTrimStart = true;
35186
35223
  for (const ent of entities) {
35187
35224
  if (ent._ === "messageEntityMentionName") {
@@ -35199,17 +35236,17 @@ async function _normalizeInputText(client, input8) {
35199
35236
  }
35200
35237
  }
35201
35238
  if (canTrimStart) {
35202
- const resultTrimmed = text.trimStart();
35203
- const numCharsTrimmed = text.length - resultTrimmed.length;
35204
- text = resultTrimmed;
35239
+ const resultTrimmed = text2.trimStart();
35240
+ const numCharsTrimmed = text2.length - resultTrimmed.length;
35241
+ text2 = resultTrimmed;
35205
35242
  adjustOffsets(entities, 0, -numCharsTrimmed);
35206
35243
  }
35207
- text = text.trimEnd();
35244
+ text2 = text2.trimEnd();
35208
35245
  for (const ent of entities) {
35209
35246
  const end = ent.offset + ent.length;
35210
- if (end > text.length) ent.length = text.length - ent.offset;
35247
+ if (end > text2.length) ent.length = text2.length - ent.offset;
35211
35248
  }
35212
- return [text, entities];
35249
+ return [text2, entities];
35213
35250
  }
35214
35251
 
35215
35252
  // node_modules/.pnpm/@fuman+io@0.0.23/node_modules/@fuman/io/read/index.js
@@ -37142,8 +37179,8 @@ async function _normalizeInputRichMessage(client, peer, input8, params) {
37142
37179
  const blocks = input8.blocks.map(processBlock);
37143
37180
  const mentionIds = /* @__PURE__ */ new Set();
37144
37181
  walkPageBlocks(blocks, {
37145
- richText: (text) => {
37146
- if (text._ === "textMentionName") mentionIds.add(text.userId);
37182
+ richText: (text2) => {
37183
+ if (text2._ === "textMentionName") mentionIds.add(text2.userId);
37147
37184
  }
37148
37185
  });
37149
37186
  const users = mentionIds.size ? await resolvePeerMany(client, [...mentionIds], toInputUser) : void 0;
@@ -38414,20 +38451,20 @@ var Chat = class {
38414
38451
  * msg.replyText(html`Hello, ${msg.chat.mention()`)
38415
38452
  * ```
38416
38453
  */
38417
- mention(text) {
38418
- if (text === void 0 && this.username) {
38454
+ mention(text2) {
38455
+ if (text2 === void 0 && this.username) {
38419
38456
  return `@${this.username}`;
38420
38457
  }
38421
- if (!text) text = this.displayName;
38422
- if (!this.username) return text;
38458
+ if (!text2) text2 = this.displayName;
38459
+ if (!this.username) return text2;
38423
38460
  return new MessageEntity$2(
38424
38461
  {
38425
38462
  _: "messageEntityTextUrl",
38426
38463
  offset: 0,
38427
- length: text.length,
38464
+ length: text2.length,
38428
38465
  url: `https://t.me/${this.username}`
38429
38466
  },
38430
- text
38467
+ text2
38431
38468
  );
38432
38469
  }
38433
38470
  };
@@ -44082,9 +44119,9 @@ function _inputReplyToToHeader(replyTo2, peer) {
44082
44119
  ];
44083
44120
  }
44084
44121
  }
44085
- async function sendText(client, chatId, text, params) {
44122
+ async function sendText(client, chatId, text2, params) {
44086
44123
  if (!params) params = {};
44087
- const [message2, entities] = await _normalizeInputText(client, text);
44124
+ const [message2, entities] = await _normalizeInputText(client, text2);
44088
44125
  const replyMarkup = _convertToTl(params.replyMarkup);
44089
44126
  const { peer, replyTo: replyTo2, scheduleDate, chainId, quickReplyShortcut } = await _processCommonSendParameters(
44090
44127
  client,
@@ -49568,8 +49605,8 @@ var UPDATES_TOO_LONG = { _: "updatesTooLong" };
49568
49605
  function collectRichMessagePeerIds(richMessage, peers) {
49569
49606
  if (!richMessage) return;
49570
49607
  walkPageBlocks(richMessage.blocks, {
49571
- richText: (text) => {
49572
- if (text._ === "textMentionName") peers.add(text.userId);
49608
+ richText: (text2) => {
49609
+ if (text2._ === "textMentionName") peers.add(text2.userId);
49573
49610
  }
49574
49611
  });
49575
49612
  }
@@ -79980,10 +80017,10 @@ var ConnectionFloodController = class {
79980
80017
  const delay = wakeup - now;
79981
80018
  this._log?.debug("connect throttled (waiting %dms)", Math.round(delay));
79982
80019
  waited = true;
79983
- await new Promise((resolve8, reject) => {
80020
+ await new Promise((resolve6, reject) => {
79984
80021
  const handle = timers_exports.setTimeout(() => {
79985
80022
  signal?.removeEventListener("abort", onAbort2);
79986
- resolve8();
80023
+ resolve6();
79987
80024
  }, delay);
79988
80025
  const onAbort2 = () => {
79989
80026
  timers_exports.clearTimeout(handle);
@@ -83961,8 +83998,8 @@ function rpcTextOf(error62) {
83961
83998
  return inner_tl_exports.RpcError.is(error62) ? String(error62.text) : void 0;
83962
83999
  }
83963
84000
  function isSessionEnded(error62) {
83964
- const text = rpcTextOf(error62);
83965
- return text !== void 0 && SESSION_ENDED_ERRORS.includes(text);
84001
+ const text2 = rpcTextOf(error62);
84002
+ return text2 !== void 0 && SESSION_ENDED_ERRORS.includes(text2);
83966
84003
  }
83967
84004
  function floodWaitSecondsOf(error62) {
83968
84005
  if (!inner_tl_exports.RpcError.is(error62)) return void 0;
@@ -83986,18 +84023,18 @@ var PHONE_REASONS = {
83986
84023
  function loginError(error62) {
83987
84024
  if (error62 instanceof ToolError || isAbortError(error62)) return error62;
83988
84025
  if (!inner_tl_exports.RpcError.is(error62)) return error62;
83989
- const text = String(error62.text);
84026
+ const text2 = String(error62.text);
83990
84027
  const seconds = floodWaitSecondsOf(error62);
83991
84028
  if (seconds !== void 0 || error62.code === inner_tl_exports.RpcError.FLOOD) {
83992
84029
  const wait = seconds === void 0 ? "a while" : `${seconds} seconds`;
83993
84030
  return new ToolError("rate_limited", `Telegram asks to wait ${wait} before logging in again.`);
83994
84031
  }
83995
- if (text === "PHONE_CODE_EXPIRED") {
84032
+ if (text2 === "PHONE_CODE_EXPIRED") {
83996
84033
  return new ToolError("invalid_argument", "The code expired; log in again.");
83997
84034
  }
83998
- const reason = PHONE_REASONS[text];
84035
+ const reason = PHONE_REASONS[text2];
83999
84036
  if (reason) return new ToolError("invalid_argument", reason);
84000
- return new ToolError("upstream_error", `Telegram refused the login (${text}).`);
84037
+ return new ToolError("upstream_error", `Telegram refused the login (${text2}).`);
84001
84038
  }
84002
84039
  async function guarded(run) {
84003
84040
  try {
@@ -84014,8 +84051,8 @@ async function isLoggedIn(client) {
84014
84051
  await client.getMe();
84015
84052
  return true;
84016
84053
  } catch (error62) {
84017
- const text = rpcTextOf(error62);
84018
- if (text === "AUTH_KEY_UNREGISTERED" || text === "SESSION_PASSWORD_NEEDED") return false;
84054
+ const text2 = rpcTextOf(error62);
84055
+ if (text2 === "AUTH_KEY_UNREGISTERED" || text2 === "SESSION_PASSWORD_NEEDED") return false;
84019
84056
  throw loginError(error62);
84020
84057
  }
84021
84058
  }
@@ -84055,9 +84092,9 @@ async function signInWithCode(client, io, phone, phoneCodeHash) {
84055
84092
  try {
84056
84093
  return await client.signIn({ phone, phoneCodeHash, phoneCode, abortSignal: io.signal });
84057
84094
  } catch (error62) {
84058
- const text = rpcTextOf(error62);
84059
- if (text === "SESSION_PASSWORD_NEEDED") return checkTwoStepPassword(client, io);
84060
- if (text !== "PHONE_CODE_INVALID") throw error62;
84095
+ const text2 = rpcTextOf(error62);
84096
+ if (text2 === "SESSION_PASSWORD_NEEDED") return checkTwoStepPassword(client, io);
84097
+ if (text2 !== "PHONE_CODE_INVALID") throw error62;
84061
84098
  io.say("That code is not right.");
84062
84099
  }
84063
84100
  }
@@ -84129,6 +84166,26 @@ async function logoutLabel(options) {
84129
84166
  }
84130
84167
  }
84131
84168
 
84169
+ // src/entry/command-settings.ts
84170
+ var SERVICE_BOOLEANS = ["keep_disappearing", "channels"];
84171
+ var STATE_DIR = "state_dir";
84172
+ function onlyOptions(profile, names) {
84173
+ const declared = Object.entries(profile.options ?? {}).filter(([name]) => names.includes(name));
84174
+ return { ...profile, options: Object.fromEntries(declared) };
84175
+ }
84176
+ function parseStateDir(argv, env, profile = PROJECT_PROFILE) {
84177
+ const options = parseToolOptions(argv, env, onlyOptions(profile, [STATE_DIR]));
84178
+ return resolveDirectorySettings(options, env, profile).state_dir;
84179
+ }
84180
+ function parseServiceSettings(argv, env, profile = PROJECT_PROFILE) {
84181
+ const options = parseToolOptions(argv, env, onlyOptions(profile, [STATE_DIR, ...SERVICE_BOOLEANS]));
84182
+ return {
84183
+ state_dir: resolveDirectorySettings(options, env, profile).state_dir,
84184
+ keep_disappearing: options.keep_disappearing === true,
84185
+ channels: options.channels === true
84186
+ };
84187
+ }
84188
+
84132
84189
  // src/cli/command-args.ts
84133
84190
  function usageError(message2) {
84134
84191
  return new ToolError("invalid_argument", message2);
@@ -84654,35 +84711,35 @@ function makeNumeric(digits) {
84654
84711
  }
84655
84712
  return new QrSegment(MODE_NUMERIC, digits.length, bb);
84656
84713
  }
84657
- function makeAlphanumeric(text) {
84658
- if (!isAlphanumeric(text))
84714
+ function makeAlphanumeric(text2) {
84715
+ if (!isAlphanumeric(text2))
84659
84716
  throw new RangeError("String contains unencodable characters in alphanumeric mode");
84660
84717
  const bb = [];
84661
84718
  let i;
84662
- for (i = 0; i + 2 <= text.length; i += 2) {
84663
- let temp = ALPHANUMERIC_CHARSET.indexOf(text.charAt(i)) * 45;
84664
- temp += ALPHANUMERIC_CHARSET.indexOf(text.charAt(i + 1));
84719
+ for (i = 0; i + 2 <= text2.length; i += 2) {
84720
+ let temp = ALPHANUMERIC_CHARSET.indexOf(text2.charAt(i)) * 45;
84721
+ temp += ALPHANUMERIC_CHARSET.indexOf(text2.charAt(i + 1));
84665
84722
  appendBits(temp, 11, bb);
84666
84723
  }
84667
- if (i < text.length)
84668
- appendBits(ALPHANUMERIC_CHARSET.indexOf(text.charAt(i)), 6, bb);
84669
- return new QrSegment(MODE_ALPHANUMERIC, text.length, bb);
84724
+ if (i < text2.length)
84725
+ appendBits(ALPHANUMERIC_CHARSET.indexOf(text2.charAt(i)), 6, bb);
84726
+ return new QrSegment(MODE_ALPHANUMERIC, text2.length, bb);
84670
84727
  }
84671
- function makeSegments(text) {
84672
- if (text === "")
84728
+ function makeSegments(text2) {
84729
+ if (text2 === "")
84673
84730
  return [];
84674
- else if (isNumeric(text))
84675
- return [makeNumeric(text)];
84676
- else if (isAlphanumeric(text))
84677
- return [makeAlphanumeric(text)];
84731
+ else if (isNumeric(text2))
84732
+ return [makeNumeric(text2)];
84733
+ else if (isAlphanumeric(text2))
84734
+ return [makeAlphanumeric(text2)];
84678
84735
  else
84679
- return [makeBytes(toUtf8ByteArray(text))];
84736
+ return [makeBytes(toUtf8ByteArray(text2))];
84680
84737
  }
84681
- function isNumeric(text) {
84682
- return NUMERIC_REGEX.test(text);
84738
+ function isNumeric(text2) {
84739
+ return NUMERIC_REGEX.test(text2);
84683
84740
  }
84684
- function isAlphanumeric(text) {
84685
- return ALPHANUMERIC_REGEX.test(text);
84741
+ function isAlphanumeric(text2) {
84742
+ return ALPHANUMERIC_REGEX.test(text2);
84686
84743
  }
84687
84744
  function getTotalBits(segs, version3) {
84688
84745
  let result = 0;
@@ -84868,8 +84925,8 @@ function cell(top, bottom) {
84868
84925
  const background = bottom === true ? DARK : LIGHT;
84869
84926
  return `\x1B[38;5;${foreground}m\x1B[48;5;${background}m${HALF_BLOCK}`;
84870
84927
  }
84871
- function drawQr(text) {
84872
- const modules = encode5(text, { border: QR_QUIET_ZONE }).data;
84928
+ function drawQr(text2) {
84929
+ const modules = encode5(text2, { border: QR_QUIET_ZONE }).data;
84873
84930
  const lines = [];
84874
84931
  for (let row = 0; row < modules.length; row += 2) {
84875
84932
  const upper = modules[row] ?? [];
@@ -85755,13 +85812,13 @@ async function answerBotGuestChatQuery(client, queryId, result) {
85755
85812
 
85756
85813
  // node_modules/.pnpm/@mtcute+core@0.32.7/node_modules/@mtcute/core/highlevel/methods/bots/answer-callback-query.js
85757
85814
  async function answerCallbackQuery(client, queryId, params) {
85758
- const { cacheTime = 0, text, alert, url: url2 } = params ?? {};
85815
+ const { cacheTime = 0, text: text2, alert, url: url2 } = params ?? {};
85759
85816
  const r = await client.call({
85760
85817
  _: "messages.setBotCallbackAnswer",
85761
85818
  queryId: long_default.isLong(queryId) ? queryId : queryId.id,
85762
85819
  cacheTime,
85763
85820
  alert,
85764
- message: text,
85821
+ message: text2,
85765
85822
  url: url2
85766
85823
  });
85767
85824
  assertTrue("messages.setBotCallbackAnswer", r);
@@ -88219,11 +88276,11 @@ function _findEphemeralMessageInUpdate(client, res, isEdit = false, noDispatch =
88219
88276
 
88220
88277
  // node_modules/.pnpm/@mtcute+core@0.32.7/node_modules/@mtcute/core/highlevel/methods/ephemeral/edit-ephemeral-message.js
88221
88278
  async function editEphemeralMessage(client, params) {
88222
- const { chatId, receiverId, messageId, text, media, richMessage, replyMarkup, shouldDispatch, uploadCache } = params;
88279
+ const { chatId, receiverId, messageId, text: text2, media, richMessage, replyMarkup, shouldDispatch, uploadCache } = params;
88223
88280
  let message2;
88224
88281
  let entities;
88225
- if (text !== void 0) {
88226
- [message2, entities] = await _normalizeInputText(client, text);
88282
+ if (text2 !== void 0) {
88283
+ [message2, entities] = await _normalizeInputText(client, text2);
88227
88284
  }
88228
88285
  const peer = chatId !== null ? await resolvePeer(client, chatId) : void 0;
88229
88286
  if (richMessage && !peer) {
@@ -88287,9 +88344,9 @@ async function getWelcomeMessages(client, chatId) {
88287
88344
  }
88288
88345
 
88289
88346
  // node_modules/.pnpm/@mtcute+core@0.32.7/node_modules/@mtcute/core/highlevel/methods/ephemeral/send-ephemeral-message.js
88290
- async function sendEphemeralMessage(client, chatId, receiverId, text, params) {
88347
+ async function sendEphemeralMessage(client, chatId, receiverId, text2, params) {
88291
88348
  const { media, richMessage, replyTo: replyTo2, replyToEphemeral, queryId, shouldDispatch, uploadCache } = params ?? {};
88292
- const [message2, entities] = await _normalizeInputText(client, text);
88349
+ const [message2, entities] = await _normalizeInputText(client, text2);
88293
88350
  const peer = chatId !== null ? await resolvePeer(client, chatId) : void 0;
88294
88351
  if (richMessage && !peer) {
88295
88352
  throw new MtArgumentError("richMessage requires chatId to be passed");
@@ -88335,8 +88392,8 @@ var DownloadDelayGate = class {
88335
88392
  const ms = at2 - now;
88336
88393
  if (ms <= 0) return Promise.resolve();
88337
88394
  if (signal) return sleepWithAbort(ms, signal);
88338
- return new Promise((resolve8) => {
88339
- timers_exports.setTimeout(resolve8, ms);
88395
+ return new Promise((resolve6) => {
88396
+ timers_exports.setTimeout(resolve6, ms);
88340
88397
  });
88341
88398
  }
88342
88399
  };
@@ -89788,16 +89845,16 @@ async function createStreamingDraft(client, chatId, params) {
89788
89845
  const peer = await resolvePeer(client, chatId);
89789
89846
  const stopListener = canStop ? _listenForDraftStop(client, randomId) : void 0;
89790
89847
  let previousText;
89791
- const sendDraft = async (text) => {
89848
+ const sendDraft = async (text2) => {
89792
89849
  if (stopListener?.signal.aborted) return;
89793
- if (typeof text === "string") {
89794
- text = { text };
89850
+ if (typeof text2 === "string") {
89851
+ text2 = { text: text2 };
89795
89852
  }
89796
89853
  if (mode === "append" && previousText) {
89797
- text = joinTextWithEntities([previousText, text]);
89854
+ text2 = joinTextWithEntities([previousText, text2]);
89798
89855
  }
89799
- previousText = text;
89800
- const [_text, entities = []] = await _normalizeInputText(client, text);
89856
+ previousText = text2;
89857
+ const [_text, entities = []] = await _normalizeInputText(client, text2);
89801
89858
  if (stopListener?.signal.aborted) return;
89802
89859
  const r = await client.call({
89803
89860
  _: "messages.setTyping",
@@ -90426,8 +90483,8 @@ async function getUnreadPollVotes(client, chatId, params) {
90426
90483
  }
90427
90484
 
90428
90485
  // node_modules/.pnpm/@mtcute+core@0.32.7/node_modules/@mtcute/core/highlevel/methods/messages/get-web-page-preview.js
90429
- async function getWebPagePreview(client, text) {
90430
- const [message2, entities] = await _normalizeInputText(client, text);
90486
+ async function getWebPagePreview(client, text2) {
90487
+ const [message2, entities] = await _normalizeInputText(client, text2);
90431
90488
  const res = await client.call({
90432
90489
  _: "messages.getWebPagePreview",
90433
90490
  message: message2,
@@ -90814,9 +90871,9 @@ function answerText(client, message2, ...params) {
90814
90871
  if (!message2.isTopicMessage || !message2.replyToMessage?.threadId) {
90815
90872
  return sendText(client, message2.chat.inputPeer, ...params);
90816
90873
  }
90817
- const [text, params_ = {}] = params;
90874
+ const [text2, params_ = {}] = params;
90818
90875
  params_.replyTo = message2.replyToMessage.threadId;
90819
- return sendText(client, message2.chat.inputPeer, text, params_);
90876
+ return sendText(client, message2.chat.inputPeer, text2, params_);
90820
90877
  }
90821
90878
  function answerMedia(client, message2, ...params) {
90822
90879
  if (!message2.isTopicMessage || !message2.replyToMessage?.threadId) {
@@ -90837,11 +90894,11 @@ function answerMediaGroup(client, message2, ...params) {
90837
90894
 
90838
90895
  // node_modules/.pnpm/@mtcute+core@0.32.7/node_modules/@mtcute/core/highlevel/methods/messages/send-reply.js
90839
90896
  function replyText(client, message2, ...params) {
90840
- const [text, params_ = {}] = params;
90897
+ const [text2, params_ = {}] = params;
90841
90898
  params_.replyTo = message2.id;
90842
90899
  const threadId = message2.replyToMessage?.threadId;
90843
90900
  if (threadId) params_.threadId = threadId;
90844
- return sendText(client, message2.chat.inputPeer, text, params_);
90901
+ return sendText(client, message2.chat.inputPeer, text2, params_);
90845
90902
  }
90846
90903
  function replyMedia(client, message2, ...params) {
90847
90904
  const [media, params_ = {}] = params;
@@ -90866,9 +90923,9 @@ function commentText(client, message2, ...params) {
90866
90923
  if (!message2.replies || !message2.replies.hasComments) {
90867
90924
  throw new MtArgumentError("This message does not have comments section");
90868
90925
  }
90869
- const [text, params_ = {}] = params;
90926
+ const [text2, params_ = {}] = params;
90870
90927
  params_.commentTo = message2.id;
90871
- return sendText(client, message2.chat.inputPeer, text, params_);
90928
+ return sendText(client, message2.chat.inputPeer, text2, params_);
90872
90929
  }
90873
90930
  function commentMedia(client, message2, ...params) {
90874
90931
  if (message2.chat.type !== "chat" || message2.chat.chatType !== "channel") {
@@ -91008,11 +91065,11 @@ function extractQuote(message2, from, to) {
91008
91065
  const { raw } = message2;
91009
91066
  if (raw._ === "messageService") throw new MtArgumentError("Cannot quote service message");
91010
91067
  if (!raw.message) throw new MtArgumentError("Cannot quote empty message");
91011
- const text = raw.message;
91068
+ const text2 = raw.message;
91012
91069
  if (from < 0) from = 0;
91013
- if (to > text.length) to = text.length;
91070
+ if (to > text2.length) to = text2.length;
91014
91071
  if (from >= to) throw new MtArgumentError("Invalid quote range");
91015
- if (!raw.entities) return { text: text.slice(from, to), entities: void 0 };
91072
+ if (!raw.entities) return { text: text2.slice(from, to), entities: void 0 };
91016
91073
  const entities = [];
91017
91074
  for (const ent of raw.entities) {
91018
91075
  const start3 = ent.offset;
@@ -91023,15 +91080,15 @@ function extractQuote(message2, from, to) {
91023
91080
  const newEnt = { ...ent, offset: newStart, length: newEnd - newStart };
91024
91081
  entities.push(newEnt);
91025
91082
  }
91026
- return { text: text.slice(from, to), entities };
91083
+ return { text: text2.slice(from, to), entities };
91027
91084
  }
91028
91085
  function quoteWithText(client, message2, params) {
91029
- const { toChatId = message2.chat, start: start3, end, text, ...params__ } = params;
91086
+ const { toChatId = message2.chat, start: start3, end, text: text2, ...params__ } = params;
91030
91087
  const params_ = params__;
91031
91088
  params_.replyTo = message2;
91032
91089
  params_.quote = extractQuote(message2, params.start, params.end);
91033
91090
  params_.quoteOffset = params.start;
91034
- return sendText(client, toChatId, text, params_);
91091
+ return sendText(client, toChatId, text2, params_);
91035
91092
  }
91036
91093
  function quoteWithMedia(client, message2, params) {
91037
91094
  const { toChatId = message2.chat, start: start3, end, media, ...params__ } = params;
@@ -91224,8 +91281,8 @@ async function translateMessage(client, params) {
91224
91281
  }
91225
91282
 
91226
91283
  // node_modules/.pnpm/@mtcute+core@0.32.7/node_modules/@mtcute/core/highlevel/methods/messages/translate-text.js
91227
- async function translateText(client, text, toLanguage, params) {
91228
- const [message2, entities] = await _normalizeInputText(client, text);
91284
+ async function translateText(client, text2, toLanguage, params) {
91285
+ const [message2, entities] = await _normalizeInputText(client, text2);
91229
91286
  const res = await client.call({
91230
91287
  _: "messages.translateText",
91231
91288
  text: [
@@ -91479,8 +91536,8 @@ async function canApplyBoost(client) {
91479
91536
  }
91480
91537
 
91481
91538
  // node_modules/.pnpm/@mtcute+core@0.32.7/node_modules/@mtcute/core/highlevel/methods/premium/create-business-chat-link.js
91482
- async function createBusinessChatLink(client, text, params) {
91483
- const [message2, entities] = await _normalizeInputText(client, text);
91539
+ async function createBusinessChatLink(client, text2, params) {
91540
+ const [message2, entities] = await _normalizeInputText(client, text2);
91484
91541
  const res = await client.call({
91485
91542
  _: "account.createBusinessChatLink",
91486
91543
  link: {
@@ -94137,10 +94194,10 @@ var NodeSocketConnection = class {
94137
94194
  }
94138
94195
  async write(bytes2) {
94139
94196
  if (this.#error) throw this.#error;
94140
- return new Promise((resolve8, reject) => {
94197
+ return new Promise((resolve6, reject) => {
94141
94198
  this.socket.write(bytes2, (error62) => {
94142
94199
  if (error62) reject(error62);
94143
- else resolve8();
94200
+ else resolve6();
94144
94201
  });
94145
94202
  });
94146
94203
  }
@@ -94169,14 +94226,14 @@ var TcpConnection = class extends NodeSocketConnection {
94169
94226
  // node_modules/.pnpm/@fuman+node@0.0.23/node_modules/@fuman/node/net/functions.js
94170
94227
  import { Socket as Socket2, Server } from "node:net";
94171
94228
  function awaitConnect(socket, signal) {
94172
- return new Promise((resolve8, reject) => {
94229
+ return new Promise((resolve6, reject) => {
94173
94230
  function onError(error62) {
94174
94231
  cleanup();
94175
94232
  reject(error62);
94176
94233
  }
94177
94234
  function onConnect() {
94178
94235
  cleanup();
94179
- resolve8();
94236
+ resolve6();
94180
94237
  }
94181
94238
  function onAbort2() {
94182
94239
  cleanup();
@@ -94329,7 +94386,7 @@ var NodeCryptoProvider = class extends BaseCryptoProvider {
94329
94386
  }
94330
94387
  pbkdf2(password, salt, iterations, keylen = 64, algo = "sha512") {
94331
94388
  return new Promise(
94332
- (resolve8, reject) => pbkdf2(password, salt, iterations, keylen, algo, (err, buf) => err !== null ? reject(err) : resolve8(buf))
94389
+ (resolve6, reject) => pbkdf2(password, salt, iterations, keylen, algo, (err, buf) => err !== null ? reject(err) : resolve6(buf))
94333
94390
  );
94334
94391
  }
94335
94392
  sha1(data) {
@@ -94579,7 +94636,7 @@ function createTelegramClient(settings) {
94579
94636
  function deviceInfo() {
94580
94637
  return {
94581
94638
  model: `${PROJECT.name} (unofficial)`,
94582
- appVersion: true ? "0.2.0" : DEV_VERSION,
94639
+ appVersion: true ? "0.3.0" : DEV_VERSION,
94583
94640
  systemVersion: `${type2()} ${release()}`
94584
94641
  };
94585
94642
  }
@@ -94639,9 +94696,9 @@ async function appCredentials(paths, io) {
94639
94696
  return app;
94640
94697
  }
94641
94698
  async function telethonSession(io) {
94642
- const text = isTerminal(io) ? await askHidden(io, TELETHON_PROMPT) : await io.readStdin?.() ?? "";
94643
- if (text.trim() === "") throw usageError("No Telethon string session was given.");
94644
- return text;
94699
+ const text2 = isTerminal(io) ? await askHidden(io, TELETHON_PROMPT) : await io.readStdin?.() ?? "";
94700
+ if (text2.trim() === "") throw usageError("No Telethon string session was given.");
94701
+ return text2;
94645
94702
  }
94646
94703
  function qrPrinter(io) {
94647
94704
  const inPlace = io.isTTY ?? Boolean(process.stdout.isTTY);
@@ -94769,7 +94826,7 @@ async function removeLabel(options) {
94769
94826
  if (Date.now() - start3 >= timeoutMs) {
94770
94827
  throw new ToolError("invalid_argument", "The sync service for this label is still running; stop it first.");
94771
94828
  }
94772
- await new Promise((resolve8) => setTimeout(resolve8, Math.min(intervalMs, timeoutMs - (Date.now() - start3))));
94829
+ await new Promise((resolve6) => setTimeout(resolve6, Math.min(intervalMs, timeoutMs - (Date.now() - start3))));
94773
94830
  }
94774
94831
  const finalStat = await lstat8(paths.dir).catch(() => void 0);
94775
94832
  if (!finalStat || finalStat.isSymbolicLink() || !finalStat.isDirectory()) {
@@ -94794,8 +94851,8 @@ import { chmod as chmod3, lstat as lstat9, mkdir as mkdir5, rename as rename3, r
94794
94851
  import { basename as basename3, dirname as dirname6, join as join13 } from "node:path";
94795
94852
  import { setTimeout as setTimeout3 } from "node:timers/promises";
94796
94853
  var LAUNCHER_SCRIPT = '#!/bin/sh\nexec "$@"\n';
94797
- function xmlEscape(text) {
94798
- return text.replaceAll("&", "&amp;").replaceAll("<", "&lt;").replaceAll(">", "&gt;").replaceAll('"', "&quot;").replaceAll("'", "&apos;");
94854
+ function xmlEscape(text2) {
94855
+ return text2.replaceAll("&", "&amp;").replaceAll("<", "&lt;").replaceAll(">", "&gt;").replaceAll('"', "&quot;").replaceAll("'", "&apos;");
94799
94856
  }
94800
94857
  function buildLaunchdPlist(spec, logPath, launcherPath) {
94801
94858
  checkServiceSpecControlChars(spec);
@@ -94851,8 +94908,8 @@ function launcherPaths(id, label, launcher, home) {
94851
94908
  }
94852
94909
  function isLaunchdNotLoaded(result) {
94853
94910
  if (result.code === 0) return true;
94854
- const text = `${result.stderr} ${result.stdout}`.toLowerCase();
94855
- return text.includes("not loaded") || text.includes("no such process") || text.includes("input/output error") || text.includes("could not find") || result.code === 3 || result.code === 5;
94911
+ const text2 = `${result.stderr} ${result.stdout}`.toLowerCase();
94912
+ return text2.includes("not loaded") || text2.includes("no such process") || text2.includes("input/output error") || text2.includes("could not find") || result.code === 3 || result.code === 5;
94856
94913
  }
94857
94914
  var STOP_POLL_INTERVAL_MS = 200;
94858
94915
  var STOP_TIMEOUT_MS = 3e4;
@@ -94995,8 +95052,8 @@ function systemdPaths(id, label, host) {
94995
95052
  }
94996
95053
  function isSystemdNotLoaded(result) {
94997
95054
  if (result.code === 0) return true;
94998
- const text = `${result.stderr} ${result.stdout}`.toLowerCase();
94999
- return text.includes("not loaded") || text.includes("does not exist") || text.includes("not found") || text.includes("no such") || text.includes("not active");
95055
+ const text2 = `${result.stderr} ${result.stdout}`.toLowerCase();
95056
+ return text2.includes("not loaded") || text2.includes("does not exist") || text2.includes("not found") || text2.includes("no such") || text2.includes("not active");
95000
95057
  }
95001
95058
  async function isSystemdActive(unitName, host) {
95002
95059
  const result = await host.run(["systemctl", "--user", "is-active", unitName]);
@@ -95128,7 +95185,7 @@ import { existsSync as existsSync3, realpathSync } from "node:fs";
95128
95185
 
95129
95186
  // src/cli/service-program.ts
95130
95187
  import { access as access2, constants as constants4, realpath as realpath7, stat as stat3 } from "node:fs/promises";
95131
- import { isAbsolute as isAbsolute7, join as join15, resolve as resolve7, sep as sep5 } from "node:path";
95188
+ import { isAbsolute as isAbsolute7, join as join15, resolve as resolve5, sep as sep5 } from "node:path";
95132
95189
  var PROBE_TIMEOUT_MS = 1e4;
95133
95190
  var PROGRAM_NAME = "node";
95134
95191
  var PROBE_ARGS = ["-p", "process.execPath"];
@@ -95161,7 +95218,7 @@ async function resolveRoots(roots) {
95161
95218
  const resolved = /* @__PURE__ */ new Set();
95162
95219
  for (const root of roots) {
95163
95220
  if (root === "" || !isAbsolute7(root)) continue;
95164
- resolved.add(resolve7(root));
95221
+ resolved.add(resolve5(root));
95165
95222
  try {
95166
95223
  resolved.add(await realpath7(root));
95167
95224
  } catch {
@@ -95192,7 +95249,7 @@ async function pickStableProgram(options) {
95192
95249
  if (dir !== "" && isAbsolute7(dir)) candidates.add(join15(dir, PROGRAM_NAME));
95193
95250
  }
95194
95251
  for (const candidate of candidates) {
95195
- if (pathHoldsVersion(candidate, version3) || isUnder(resolve7(candidate), volatileRoots)) continue;
95252
+ if (pathHoldsVersion(candidate, version3) || isUnder(resolve5(candidate), volatileRoots)) continue;
95196
95253
  if (!await isExecutableFile(candidate)) continue;
95197
95254
  let started;
95198
95255
  try {
@@ -95527,12 +95584,12 @@ function parseRequest(message2) {
95527
95584
  return { id: message2.id, method: message2.method, params };
95528
95585
  }
95529
95586
  function probe(socketPath) {
95530
- return new Promise((resolve8) => {
95587
+ return new Promise((resolve6) => {
95531
95588
  const socket = new Socket3();
95532
95589
  const settle3 = (outcome) => {
95533
95590
  clearTimeout(timer);
95534
95591
  socket.destroy();
95535
- resolve8(outcome);
95592
+ resolve6(outcome);
95536
95593
  };
95537
95594
  const timer = setTimeout(() => settle3("unknown"), PROBE_TIMEOUT_MS2);
95538
95595
  socket.once("connect", () => settle3("answering"));
@@ -95553,16 +95610,16 @@ async function claimSocketPath(socketPath) {
95553
95610
  if (outcome === "stale") await rm5(socketPath, { force: true });
95554
95611
  }
95555
95612
  function listen(server, socketPath) {
95556
- return new Promise((resolve8, reject) => {
95613
+ return new Promise((resolve6, reject) => {
95557
95614
  server.once("error", reject);
95558
95615
  server.listen(socketPath, () => {
95559
95616
  server.off("error", reject);
95560
- resolve8();
95617
+ resolve6();
95561
95618
  });
95562
95619
  });
95563
95620
  }
95564
95621
  function closeServer(server) {
95565
- return new Promise((resolve8) => server.close(() => resolve8()));
95622
+ return new Promise((resolve6) => server.close(() => resolve6()));
95566
95623
  }
95567
95624
  function frame(reply) {
95568
95625
  return `${JSON.stringify({ jsonrpc: "2.0", ...reply })}
@@ -95630,14 +95687,14 @@ var Connection = class {
95630
95687
  signal: this.calls.signal,
95631
95688
  afterAnswered: (effect) => answered ? runEffect(effect) : void effects.push(effect)
95632
95689
  };
95633
- let text;
95690
+ let text2;
95634
95691
  try {
95635
95692
  const result = await handler(params, call);
95636
- text = frame({ id, result: result ?? null });
95693
+ text2 = frame({ id, result: result ?? null });
95637
95694
  } catch (error62) {
95638
- text = frame({ id, error: this.failure(error62, method) });
95695
+ text2 = frame({ id, error: this.failure(error62, method) });
95639
95696
  }
95640
- this.write(text, () => {
95697
+ this.write(text2, () => {
95641
95698
  answered = true;
95642
95699
  for (const effect of effects.splice(0)) runEffect(effect);
95643
95700
  });
@@ -95660,13 +95717,13 @@ var Connection = class {
95660
95717
  * way is the client's loss. `onWritten` runs once the line is flushed, or
95661
95718
  * when it cannot be.
95662
95719
  */
95663
- write(text, onWritten) {
95720
+ write(text2, onWritten) {
95664
95721
  if (!this.socket.writable) {
95665
95722
  onWritten?.();
95666
95723
  return;
95667
95724
  }
95668
95725
  try {
95669
- this.socket.write(text, onWritten);
95726
+ this.socket.write(text2, onWritten);
95670
95727
  } catch {
95671
95728
  this.socket.destroy();
95672
95729
  onWritten?.();
@@ -95702,7 +95759,7 @@ async function serveService(socketPath, handlers, options = {}) {
95702
95759
  });
95703
95760
  let closing;
95704
95761
  const shutDown2 = async () => {
95705
- const closed = [...connections].map((socket) => new Promise((resolve8) => socket.once("close", resolve8)));
95762
+ const closed = [...connections].map((socket) => new Promise((resolve6) => socket.once("close", resolve6)));
95706
95763
  for (const socket of connections) socket.destroy();
95707
95764
  await Promise.all(closed);
95708
95765
  await closeServer(server);
@@ -95724,8 +95781,8 @@ var STORAGE_FAILURE_REASON = "the mirror cannot be written; receiving stopped";
95724
95781
  var CONNECTION_LOST_REASON = "the connection to Telegram could not be kept";
95725
95782
  var OTHER_ACCOUNT_REASON = "this mirror belongs to another account";
95726
95783
  function errorLabel(error62) {
95727
- const text = rpcTextOf(error62);
95728
- if (text !== void 0) return text;
95784
+ const text2 = rpcTextOf(error62);
95785
+ if (text2 !== void 0) return text2;
95729
95786
  if (error62 instanceof ToolError) return error62.message;
95730
95787
  return error62 instanceof Error ? error62.name : "unexpected error";
95731
95788
  }
@@ -95801,7 +95858,7 @@ var Ending = class {
95801
95858
  };
95802
95859
  result;
95803
95860
  constructor() {
95804
- this.promise = new Promise((resolve8) => this.resolve = resolve8);
95861
+ this.promise = new Promise((resolve6) => this.resolve = resolve6);
95805
95862
  }
95806
95863
  /** Aborts once the run has ended, so everything waiting on it gives up. */
95807
95864
  get signal() {
@@ -95830,26 +95887,26 @@ function onAbort(signal, fn) {
95830
95887
  signal.addEventListener("abort", fn, { once: true });
95831
95888
  return () => signal.removeEventListener("abort", fn);
95832
95889
  }
95833
- var realPause = (ms, signal) => new Promise((resolve8) => {
95890
+ var realPause = (ms, signal) => new Promise((resolve6) => {
95834
95891
  let stopListening = () => {
95835
95892
  };
95836
95893
  const timer = setTimeout(() => {
95837
95894
  stopListening();
95838
- resolve8();
95895
+ resolve6();
95839
95896
  }, ms);
95840
95897
  stopListening = onAbort(signal, () => {
95841
95898
  clearTimeout(timer);
95842
- resolve8();
95899
+ resolve6();
95843
95900
  });
95844
95901
  });
95845
95902
  function waitThrough(pause, ms, signal) {
95846
95903
  if (signal.aborted) return Promise.resolve();
95847
- return new Promise((resolve8) => {
95848
- const stopListening = onAbort(signal, resolve8);
95904
+ return new Promise((resolve6) => {
95905
+ const stopListening = onAbort(signal, resolve6);
95849
95906
  pause(ms, signal).catch(() => {
95850
95907
  }).finally(() => {
95851
95908
  stopListening();
95852
- resolve8();
95909
+ resolve6();
95853
95910
  });
95854
95911
  });
95855
95912
  }
@@ -95874,9 +95931,9 @@ function cancelled() {
95874
95931
  return new ToolError("upstream_error", "The request was cancelled before Telegram answered.");
95875
95932
  }
95876
95933
  function abortable(promise2, signal) {
95877
- return new Promise((resolve8, reject) => {
95934
+ return new Promise((resolve6, reject) => {
95878
95935
  const stopListening = onAbort(signal, () => reject(cancelled()));
95879
- promise2.then(resolve8, reject).then(stopListening);
95936
+ promise2.then(resolve6, reject).then(stopListening);
95880
95937
  });
95881
95938
  }
95882
95939
  function requestFailure(error62, what, env) {
@@ -96625,8 +96682,8 @@ var ChatListRefresh = class {
96625
96682
  }
96626
96683
  begin() {
96627
96684
  let listener;
96628
- const listed = new Promise((resolve8, reject) => {
96629
- listener = { listed: resolve8, failed: reject };
96685
+ const listed = new Promise((resolve6, reject) => {
96686
+ listener = { listed: resolve6, failed: reject };
96630
96687
  });
96631
96688
  listed.catch(() => {
96632
96689
  });
@@ -97370,7 +97427,7 @@ var RequestQueue = class {
97370
97427
  const ahead = this.tail;
97371
97428
  let done = () => {
97372
97429
  };
97373
- this.tail = new Promise((resolve8) => done = resolve8);
97430
+ this.tail = new Promise((resolve6) => done = resolve6);
97374
97431
  try {
97375
97432
  await abortable(ahead, signal);
97376
97433
  } catch (error62) {
@@ -97517,12 +97574,12 @@ function parseDownloadParams(params) {
97517
97574
  };
97518
97575
  }
97519
97576
  function sendTextAt(fields) {
97520
- const { text } = fields;
97521
- if (typeof text !== "string") throw invalid("text must be a string.");
97522
- if (text.trim() === "") throw invalid("text must not be blank.");
97523
- if (text !== text.trim()) throw invalid("text must not start or end with blank space.");
97524
- if (text.length > TEXT_MAX_UNITS) throw invalid(`text must be at most ${TEXT_MAX_UNITS} characters.`);
97525
- return text;
97577
+ const { text: text2 } = fields;
97578
+ if (typeof text2 !== "string") throw invalid("text must be a string.");
97579
+ if (text2.trim() === "") throw invalid("text must not be blank.");
97580
+ if (text2 !== text2.trim()) throw invalid("text must not start or end with blank space.");
97581
+ if (text2.length > TEXT_MAX_UNITS) throw invalid(`text must be at most ${TEXT_MAX_UNITS} characters.`);
97582
+ return text2;
97526
97583
  }
97527
97584
  function parseSendParams(params) {
97528
97585
  const fields = recordOf(params, SEND_KEYS, "The send parameters");
@@ -97808,9 +97865,9 @@ function refusedSend(code, what, name) {
97808
97865
  return new ToolError(code, `${what} (${name}); nothing was sent.`);
97809
97866
  }
97810
97867
  function rateLimitSecondsOf(error62) {
97811
- const text = String(error62.text);
97812
- if (!RATE_LIMIT_ERRORS.includes(text.replace(/\d+$/, "%d"))) return void 0;
97813
- const digits = /\d+$/.exec(text);
97868
+ const text2 = String(error62.text);
97869
+ if (!RATE_LIMIT_ERRORS.includes(text2.replace(/\d+$/, "%d"))) return void 0;
97870
+ const digits = /\d+$/.exec(text2);
97814
97871
  return floodWaitSecondsOf(error62) ?? (digits ? Number(digits[0]) : void 0);
97815
97872
  }
97816
97873
  function refusalOf(error62) {
@@ -97942,8 +97999,8 @@ function checkSendable(mirror, { chat, topic, reply_to }) {
97942
97999
  throw new ToolError("not_found", `No message ${reply_to} in this chat to reply to; nothing was sent.`);
97943
98000
  }
97944
98001
  }
97945
- function deliveredId(mirror, chat, text, startedAt) {
97946
- const rows = mirror.prepare("SELECT id FROM messages WHERE chat = ? AND from_me = 1 AND body = ? AND ts >= ? LIMIT 2").all(chat, text, startedAt - DUPLICATE_LOOKBACK_MS);
98002
+ function deliveredId(mirror, chat, text2, startedAt) {
98003
+ const rows = mirror.prepare("SELECT id FROM messages WHERE chat = ? AND from_me = 1 AND body = ? AND ts >= ? LIMIT 2").all(chat, text2, startedAt - DUPLICATE_LOOKBACK_MS);
97947
98004
  return rows.length === 1 ? rows[0].id : void 0;
97948
98005
  }
97949
98006
  function deliveredFileIds(mirror, chat, files, startedAt) {
@@ -98017,9 +98074,9 @@ function replyToOf({
98017
98074
  return { _: "inputReplyToMessage", replyToMsgId, ...inTopic2 === void 0 ? {} : { topMsgId: inTopic2 } };
98018
98075
  }
98019
98076
  function untilAborted(promise2, signal) {
98020
- return new Promise((resolve8, reject) => {
98077
+ return new Promise((resolve6, reject) => {
98021
98078
  const stopListening = onAbort(signal, () => reject(signal.reason));
98022
- promise2.then(resolve8, reject).then(stopListening);
98079
+ promise2.then(resolve6, reject).then(stopListening);
98023
98080
  });
98024
98081
  }
98025
98082
  async function callOnce(ctx, signal, what, call, settle3) {
@@ -98271,10 +98328,10 @@ var EDIT_REFUSALS = {
98271
98328
  { names: ["MEDIA_CAPTION_TOO_LONG"], code: "invalid_argument", what: "Telegram refused the caption" }
98272
98329
  ]
98273
98330
  };
98274
- function refuseUneditable({ message: message2 }, text) {
98331
+ function refuseUneditable({ message: message2 }, text2) {
98275
98332
  if (!message2) throw deletedMessage();
98276
98333
  const captioned = message2.media !== null && takesCaption(JSON.parse(message2.media).type);
98277
- checkEditable({ ...message2, captioned }, text);
98334
+ checkEditable({ ...message2, captioned }, text2);
98278
98335
  }
98279
98336
  function editedOf(group, id) {
98280
98337
  for (const update of group.updates) {
@@ -98291,10 +98348,10 @@ function recordEdit(ctx, { chat }, raw, group) {
98291
98348
  recordSent(ctx.mirror, { now: now(), keepDisappearing }, read, channels);
98292
98349
  });
98293
98350
  }
98294
- function alreadyResult(ctx, { chat, id, text }) {
98351
+ function alreadyResult(ctx, { chat, id, text: text2 }) {
98295
98352
  try {
98296
98353
  const stored = storedMessageOf(ctx.mirror, chat, id);
98297
- if (stored?.body === text && stored.edited !== null) return { id, edited: stored.edited, already: true };
98354
+ if (stored?.body === text2 && stored.edited !== null) return { id, edited: stored.edited, already: true };
98298
98355
  } catch (error62) {
98299
98356
  ctx.settings.log(`edit: the mirror could not be read (${errorLabel(error62)})`);
98300
98357
  }
@@ -99193,6 +99250,7 @@ function toolContext(command, io) {
99193
99250
  downloadMaxMb: command.downloadMaxMb,
99194
99251
  sendDirs: command.sendDirs,
99195
99252
  programName: PROJECT.name,
99253
+ options: command.options,
99196
99254
  signal: io.signal
99197
99255
  };
99198
99256
  }
@@ -99234,16 +99292,18 @@ function parseCommand(argv, io) {
99234
99292
  if (cwd === void 0) throw usageError2(`Command ${name} needs ${CWD_FLAG} <dir>.`);
99235
99293
  if (name === "target") {
99236
99294
  const { value: language, rest: afterLanguage } = takeFlag(rest, LANGUAGE_FLAG);
99237
- const { value: harnessLanguage, rest: settingFlags2 } = takeFlag(afterLanguage, HARNESS_LANGUAGE_FLAG);
99238
- const settings2 = parseToolSettings(settingFlags2, io.env, profile);
99295
+ const { value: harnessLanguage, rest: optionFlags } = takeFlag(afterLanguage, HARNESS_LANGUAGE_FLAG);
99296
+ const parsedOptions = parseToolOptions(optionFlags, io.env, profile);
99297
+ const directories = resolveDirectorySettings(parsedOptions, io.env, profile);
99239
99298
  return {
99240
99299
  name,
99241
99300
  toolId,
99242
99301
  cwd,
99243
- stateDir: settings2.state_dir,
99244
- downloadDir: settings2.download_dir,
99245
- downloadMaxMb: settings2.download_max_mb,
99246
- sendDirs: settings2.send_dirs,
99302
+ stateDir: directories.state_dir,
99303
+ downloadDir: directories.download_dir,
99304
+ downloadMaxMb: directories.download_max_mb,
99305
+ sendDirs: directories.send_dirs,
99306
+ options: parsedOptions,
99247
99307
  language: promptLanguage(language, io.env, harnessLanguage, profile)
99248
99308
  };
99249
99309
  }
@@ -99261,7 +99321,8 @@ function parseCommand(argv, io) {
99261
99321
  stateDir: settings.state_dir,
99262
99322
  downloadDir: settings.download_dir,
99263
99323
  downloadMaxMb: settings.download_max_mb,
99264
- sendDirs: settings.send_dirs
99324
+ sendDirs: settings.send_dirs,
99325
+ options: settings.options
99265
99326
  };
99266
99327
  }
99267
99328
  function describeSpec(spec) {
@@ -99286,10 +99347,10 @@ function writeError(io, code, message2, details) {
99286
99347
  return EXIT_FAILED;
99287
99348
  }
99288
99349
  async function readArguments(io) {
99289
- const text = await io.readStdin();
99290
- if (text.trim() === "") return {};
99350
+ const text2 = await io.readStdin();
99351
+ if (text2.trim() === "") return {};
99291
99352
  try {
99292
- return JSON.parse(text);
99353
+ return JSON.parse(text2);
99293
99354
  } catch (error62) {
99294
99355
  throw new ToolError("invalid_argument", "The arguments on standard input are not valid JSON.", { cause: error62 });
99295
99356
  }
@@ -99389,8 +99450,8 @@ async function main() {
99389
99450
  env: process.env,
99390
99451
  ownDir: packageRoot(import.meta.url),
99391
99452
  readStdin,
99392
- stdout: (text) => process.stdout.write(text),
99393
- stderr: (text) => process.stderr.write(text),
99453
+ stdout: (text2) => process.stdout.write(text2),
99454
+ stderr: (text2) => process.stderr.write(text2),
99394
99455
  signal: controller.signal
99395
99456
  });
99396
99457
  if (argv[0] === "target") process.stdout.write("", () => process.stderr.write("", () => process.exit()));