blun-king-cli 9.1.647 → 9.1.649

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "blun-king-cli",
3
- "version": "9.1.647",
3
+ "version": "9.1.649",
4
4
  "description": "BLUN CLI - your own AI agent with a Telegram channel. Get it done. With BLUN.",
5
5
  "license": "MIT",
6
6
  "bin": {
@@ -29,7 +29,8 @@
29
29
  "node-pty": "1.2.0-beta.15"
30
30
  },
31
31
  "dependencies": {
32
- "quickjs-emscripten": "0.32.0"
32
+ "quickjs-emscripten": "0.32.0",
33
+ "smol-toml": "1.9.1"
33
34
  },
34
35
  "files": [
35
36
  "CHANGELOG.md",
@@ -49,7 +50,16 @@
49
50
  "versionierung/",
50
51
  "RELEASE-9.1.645.md",
51
52
  "RELEASE-9.1.646.md",
52
- "RELEASE-9.1.647.md"
53
+ "RELEASE-9.1.647.md",
54
+ "RELEASE-9.1.648.md",
55
+ "COMPACTION-STEER.md",
56
+ "GOAL-REPLY-TOOLS.md",
57
+ "ORIGINAL-HISTORY-BINDING.md",
58
+ "ORIGINAL-TOOL-OUTPUT.md",
59
+ "REQUEST-BODY-OBSERVATIONS.md",
60
+ "RETIRED-WORKER-DATA.md",
61
+ "RETIREMENT-COMPATIBILITY.md",
62
+ "RELEASE-9.1.649.md"
53
63
  ],
54
64
  "keywords": [
55
65
  "blun",
@@ -60183,9 +60183,10 @@ var BoundedChannelContextBuffer = class {
60183
60183
  * messages carry a hard silence instruction instead. DMs are always addressed.
60184
60184
  */
60185
60185
  function buildChannelTag(content, meta, addressed = true, inferAddressing = false) {
60186
+ const replyTo = meta.message_id === void 0 ? "" : ` und reply_to=${meta.message_id}`;
60186
60187
  const pairs = [["source", "telegram"]];
60187
60188
  for (const [key, value] of Object.entries(meta)) if (value !== void 0) pairs.push([key, String(value)]);
60188
- return `<channel ${pairs.map(([key, value]) => `${key}="${escapeAttr(value)}"`).join(" ")}>\n${content}\n</channel>\n${addressed ? `[REPLY-PFLICHT: Der Absender liest NUR Telegram. Sende deine Antwort mit dem telegram reply-Tool an chat_id=${meta.chat_id}. Sichtbarer Antworttext kann auch automatisch weitergeleitet werden; er ist kein privater Denkbereich.]` : inferAddressing ? `[SEMANTISCHE ADRESSIERUNG: Diese menschliche Gruppennachricht nennt dich nicht explizit. Entscheide anhand von Inhalt und Gesprächskontext, ob sie an dich gerichtet ist oder Arbeit von dir verlangt. Falls ja, antworte kurz mit dem telegram reply-Tool an chat_id=${meta.chat_id}. Falls nein, beende den Turn ohne Ausgabe; sende keine Bestätigung deiner Stille.]` : "[NUR MITLESEN — diese Nachricht ist NICHT an dich gerichtet (kein @King, keine Antwort an dich, sie spricht jemand anderen oder die Gruppe allgemein an). ANTWORTE NICHT: kein reply-Tool, keine Bestätigung, kein \"verstanden\", kein \"halte mich raus\" — beende den Turn einfach ohne Ausgabe. NUR wenn du ein echtes, konkretes Ergebnis oder einen echten Blocker beitragen kannst, antwortest du kurz. Im Zweifel: schweigen.]"}`;
60189
+ return `<channel ${pairs.map(([key, value]) => `${key}="${escapeAttr(value)}"`).join(" ")}>\n${content}\n</channel>\n${addressed ? `[REPLY-PFLICHT: Der Absender liest NUR Telegram. Sende deine Antwort mit dem telegram reply-Tool an chat_id=${meta.chat_id}${replyTo}. Sichtbarer Antworttext kann auch automatisch weitergeleitet werden; er ist kein privater Denkbereich.]` : inferAddressing ? `[SEMANTISCHE ADRESSIERUNG: Diese menschliche Gruppennachricht nennt dich nicht explizit. Entscheide anhand von Inhalt und Gesprächskontext, ob sie an dich gerichtet ist oder Arbeit von dir verlangt. Falls ja, antworte kurz mit dem telegram reply-Tool an chat_id=${meta.chat_id}${replyTo}. Falls nein, beende den Turn ohne Ausgabe; sende keine Bestätigung deiner Stille.]` : "[NUR MITLESEN — diese Nachricht ist NICHT an dich gerichtet (kein @King, keine Antwort an dich, sie spricht jemand anderen oder die Gruppe allgemein an). ANTWORTE NICHT: kein reply-Tool, keine Bestätigung, kein \"verstanden\", kein \"halte mich raus\" — beende den Turn einfach ohne Ausgabe. NUR wenn du ein echtes, konkretes Ergebnis oder einen echten Blocker beitragen kannst, antwortest du kurz. Im Zweifel: schweigen.]"}`;
60189
60190
  }
60190
60191
  /**
60191
60192
  * Sent once as the head of the first prompt of every bridged session —
@@ -60209,7 +60210,7 @@ function buildPreamble() {
60209
60210
  "user=\"...\" ts=\"...\">. Always pass chat_id back to the reply tool. If the tag has an",
60210
60211
  "image_path attribute, read that file — it is a photo the sender attached. If the tag",
60211
60212
  "has attachment_file_id, call download_attachment with that file_id, then read the",
60212
- "returned path. Use reply_to (a message_id) only when quoting an earlier message.",
60213
+ "returned path. When answering, use the chat_id and set reply_to to the message_id supplied by the bridge when present.",
60213
60214
  "Use edit_message for interim progress updates and finish long tasks with a fresh",
60214
60215
  "reply. Do not add a reaction or acknowledgement just to announce inactivity.",
60215
60216
  "",
@@ -73105,13 +73105,13 @@ function botToken() {
73105
73105
  return token;
73106
73106
  }
73107
73107
  /** Append one history entry (adds ts) to a .jsonl file. Never throws. */
73108
- function appendJsonl(file, entry) {
73108
+ function appendJsonl(file, entry, flush = false) {
73109
73109
  try {
73110
73110
  ensureStateDir();
73111
73111
  appendFileSync(file, `${JSON.stringify({
73112
73112
  ts: (/* @__PURE__ */ new Date()).toISOString(),
73113
73113
  ...entry
73114
- })}\n`);
73114
+ })}\n`, { flush });
73115
73115
  } catch (err) {
73116
73116
  process.stderr.write(`telegram channel: history append failed: ${String(err)}\n`);
73117
73117
  }
@@ -73503,7 +73503,7 @@ function isGroupNoiseReply(text) {
73503
73503
  const TOOL_DEFINITIONS = [
73504
73504
  {
73505
73505
  name: "reply",
73506
- description: "Reply on Telegram. Pass chat_id from the inbound message. Optionally pass reply_to (message_id) for threading, and files (absolute paths) to attach images or documents.",
73506
+ description: "Reply on Telegram. Use the inbound chat_id and pass its message_id as reply_to when present. Supply files as absolute paths to attach images or documents.",
73507
73507
  inputSchema: {
73508
73508
  type: "object",
73509
73509
  properties: {
@@ -73515,7 +73515,7 @@ const TOOL_DEFINITIONS = [
73515
73515
  },
73516
73516
  reply_to: {
73517
73517
  type: "string",
73518
- description: "Message ID to thread under. Use message_id from the inbound <channel> block."
73518
+ description: "Incoming message ID for correlation and, when enabled, Telegram threading."
73519
73519
  },
73520
73520
  files: {
73521
73521
  type: "array",
@@ -73629,7 +73629,7 @@ async function runTool(api, token, name, args) {
73629
73629
  */
73630
73630
  const DUPLICATE_WINDOW_MS = 3e5;
73631
73631
  const OUTBOX_TAIL_BYTES = 32768;
73632
- function isRecentDuplicate(chatId, text) {
73632
+ function isRecentDuplicate(chatId, text, replyTo) {
73633
73633
  try {
73634
73634
  const file = outboxLog();
73635
73635
  const size = statSync(file).size;
@@ -73643,6 +73643,7 @@ function isRecentDuplicate(chatId, text) {
73643
73643
  const entry = JSON.parse(line);
73644
73644
  if (entry.kind !== "reply" && entry.kind !== "reply-fallback") continue;
73645
73645
  if (String(entry.chat_id) !== String(chatId)) continue;
73646
+ if (replyTo !== void 0 && entry.reply_to_message_id !== replyTo) continue;
73646
73647
  if (entry.ts === void 0 || Date.parse(entry.ts) < cutoff) continue;
73647
73648
  if ((entry.text ?? "").trim() === wanted) return true;
73648
73649
  } catch {}
@@ -73654,7 +73655,11 @@ async function runReply(api, args) {
73654
73655
  const chatId = resolveAllowedChatId(args["chat_id"]);
73655
73656
  const text = typeof args["text"] === "string" ? args["text"].split("[[BLUN_TELEGRAM_SILENT]]").join("") : args["text"];
73656
73657
  if (typeof text === "string" && text.trim().length === 0) return "unterdrückt";
73657
- const replyTo = args["reply_to"] !== null && args["reply_to"] !== void 0 ? Number(args["reply_to"]) : void 0;
73658
+ const rawReplyTo = args["reply_to"];
73659
+ if (rawReplyTo != null && (typeof rawReplyTo !== "string" || !/^[1-9][0-9]{0,15}$/u.test(rawReplyTo) || !Number.isSafeInteger(Number(rawReplyTo)))) {
73660
+ throw new Error("invalid Telegram reply_to message ID");
73661
+ }
73662
+ const replyTo = rawReplyTo == null ? void 0 : Number(rawReplyTo);
73658
73663
  const files = args["files"] ?? [];
73659
73664
  const parseMode = args["format"] === "markdownv2" ? "MarkdownV2" : void 0;
73660
73665
  if (files.length === 0 && isGroupChat(chatId) && isGroupNoiseReply(text)) {
@@ -73666,7 +73671,7 @@ async function runReply(api, args) {
73666
73671
  });
73667
73672
  return "suppressed: group meta/acknowledgement noise — not sent (silence means silence)";
73668
73673
  }
73669
- if (files.length === 0 && isRecentDuplicate(chatId, text)) {
73674
+ if (files.length === 0 && isRecentDuplicate(chatId, text, replyTo)) {
73670
73675
  appendJsonl(outboxLog(), {
73671
73676
  direction: "out",
73672
73677
  kind: "reply-duplicate-suppressed",
@@ -73687,36 +73692,32 @@ async function runReply(api, args) {
73687
73692
  const replyMode = access.replyToMode ?? "first";
73688
73693
  const chunks = chunk(text, limit, mode);
73689
73694
  const sentIds = [];
73695
+ const receipt = { direction: "out", chat_id: chatId, reply_to_message_id: replyTo, message_ids: sentIds };
73696
+ const replyParameters = replyTo === void 0 ? void 0 : { message_id: replyTo, allow_sending_without_reply: true };
73690
73697
  try {
73691
73698
  for (let i = 0; i < chunks.length; i++) {
73692
73699
  const shouldReplyTo = replyTo !== void 0 && replyMode !== "off" && (replyMode === "all" || i === 0);
73693
73700
  const chunkText = chunks[i];
73694
73701
  if (chunkText === void 0) continue;
73695
73702
  const sent = await api.sendMessage(chatId, chunkText, {
73696
- ...shouldReplyTo ? { reply_parameters: { message_id: replyTo } } : {},
73703
+ ...shouldReplyTo ? { reply_parameters: replyParameters } : {},
73697
73704
  ...parseMode !== void 0 ? { parse_mode: parseMode } : {}
73698
73705
  });
73699
73706
  sentIds.push(sent.message_id);
73700
73707
  }
73708
+ for (const file of files) {
73709
+ const ext = extname(file).toLowerCase();
73710
+ const input = new import_out.InputFile(file);
73711
+ const opts = replyTo !== void 0 && replyMode !== "off" ? { reply_parameters: replyParameters } : void 0;
73712
+ const sent = PHOTO_EXTS.has(ext) ? await api.sendPhoto(chatId, input, opts) : await api.sendDocument(chatId, input, opts);
73713
+ sentIds.push(sent.message_id);
73714
+ }
73701
73715
  } catch (err) {
73716
+ if (sentIds.length > 0) appendJsonl(outboxLog(), { ...receipt, kind: "reply-partial" }, true);
73702
73717
  const msg = err instanceof Error ? err.message : String(err);
73703
- throw new Error(`reply failed after ${sentIds.length} of ${chunks.length} chunk(s) sent: ${msg}`);
73718
+ throw new Error(`reply failed after ${sentIds.length} of ${chunks.length + files.length} part(s) sent: ${msg}`);
73704
73719
  }
73705
- for (const file of files) {
73706
- const ext = extname(file).toLowerCase();
73707
- const input = new import_out.InputFile(file);
73708
- const opts = replyTo !== void 0 && replyMode !== "off" ? { reply_parameters: { message_id: replyTo } } : void 0;
73709
- const sent = PHOTO_EXTS.has(ext) ? await api.sendPhoto(chatId, input, opts) : await api.sendDocument(chatId, input, opts);
73710
- sentIds.push(sent.message_id);
73711
- }
73712
- appendJsonl(outboxLog(), {
73713
- direction: "out",
73714
- kind: "reply",
73715
- chat_id: chatId,
73716
- message_ids: sentIds,
73717
- text,
73718
- ...files.length > 0 ? { files } : {}
73719
- });
73720
+ appendJsonl(outboxLog(), { ...receipt, kind: "reply", text, ...files.length > 0 ? { files } : {} }, true);
73720
73721
  return sentIds.length === 1 ? `sent (id: ${sentIds[0]})` : `sent ${sentIds.length} parts (ids: ${sentIds.join(", ")})`;
73721
73722
  }
73722
73723
  async function runDownload(api, token, fileId) {