blun-king-cli 9.1.608 → 9.1.610

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.608",
3
+ "version": "9.1.610",
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": {
@@ -17,6 +17,7 @@
17
17
  },
18
18
  "os": [
19
19
  "darwin",
20
+ "linux",
20
21
  "win32"
21
22
  ],
22
23
  "cpu": [
@@ -59412,6 +59412,9 @@ function isGermanGroupBroadcast(text) {
59412
59412
  }
59413
59413
  return false;
59414
59414
  }
59415
+ function hasAllMention(text) {
59416
+ return /(?:^|[^\p{L}\p{N}_@])@all(?=$|[^\p{L}\p{N}_])/iu.test(text);
59417
+ }
59415
59418
  /**
59416
59419
  * Bot-to-bot loop guard (Telegram's own safety requirement for Bot API 10.0
59417
59420
  * bot-to-bot mode): once King can receive other bots' messages, an unthrottled
@@ -59479,9 +59482,10 @@ function gate(ctx, botUsername) {
59479
59482
  if (groupAllowFrom.length > 0 && !groupAllowFrom.includes(senderId)) return { action: "drop" };
59480
59483
  const addressesAnother = matchesAny(ctx.text, access.ignorePatterns);
59481
59484
  const mentioned = !addressesAnother && isMentioned(ctx, botUsername, access.mentionPatterns);
59482
- if (policy.requireMention === true && !mentioned) return { action: "drop" };
59485
+ const broadcastMention = from.isBot !== true && hasAllMention(ctx.text);
59486
+ if (policy.requireMention && !mentioned && !broadcastMention) return { action: "drop" };
59483
59487
  const mentionBypass = from.isBot !== true && (policy.alwaysAllowFrom ?? []).includes(senderId);
59484
- const addressed = !addressesAnother && (mentionBypass || mentioned || isGermanGroupBroadcast(ctx.text));
59488
+ const addressed = broadcastMention || !addressesAnother && (mentionBypass || mentioned || isGermanGroupBroadcast(ctx.text));
59485
59489
  const inferAddressing = !addressesAnother && !addressed && from.isBot !== true;
59486
59490
  if (!addressed && from.isBot === true && !botLoopGuardAllows(senderId)) return { action: "drop" };
59487
59491
  return {
@@ -60193,7 +60197,7 @@ var BoundedChannelContextBuffer = class {
60193
60197
  function buildChannelTag(content, meta, addressed = true, inferAddressing = false) {
60194
60198
  const pairs = [["source", "telegram"]];
60195
60199
  for (const [key, value] of Object.entries(meta)) if (value !== void 0) pairs.push([key, String(value)]);
60196
- 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.]"}`;
60200
+ return `<channel ${pairs.map(([key, value]) => `${key}="${escapeAttr(value)}"`).join(" ")}>\n${content}\n</channel>\n${addressed && meta.chat_id.startsWith("-") ? `[GRUPPENANTWORT: Eine bloße Information oder eine Nachricht, die ausdrücklich keine Bestätigung verlangt, macht keine Antwort erforderlich. Beende den Turn dann ohne Ausgabe und ohne Bestätigung deiner Stille. Einen konkreten Auftrag an dich nimm kurz an und beginne die Arbeit; melde danach das Ergebnis oder einen echten Blocker. Eine Frage beantworte, wenn du etwas beitragen kannst. Sende eine nötige Antwort mit dem telegram reply-Tool an chat_id=${meta.chat_id}, ohne dieselbe Annahme zu wiederholen.]` : 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.]"}`;
60197
60201
  }
60198
60202
  /**
60199
60203
  * Sent once as the head of the first prompt of every bridged session —
@@ -60211,6 +60215,8 @@ function buildPreamble() {
60211
60215
  "useful contribution: a relevant finding, error, or improvement. Otherwise finish",
60212
60216
  "with no reply tool call and no assistant text. Do not narrate that decision, cite",
60213
60217
  "a silence rule, acknowledge inactivity, or report that you ended without output.",
60218
+ "If your host requires assistant text to finish a silent turn, output exactly",
60219
+ "[[BLUN_TELEGRAM_SILENT]] and nothing else. Never send this marker with reply.",
60214
60220
  "When you do have something useful to contribute, send it once without repeating it.",
60215
60221
  "",
60216
60222
  "Messages arrive wrapped as <channel source=\"telegram\" chat_id=\"...\" message_id=\"...\"",
@@ -67887,6 +67893,10 @@ function assertTelegramLanguageReleased(text, releaseToken, now) {
67887
67893
  function isGroupChat(chatId) {
67888
67894
  return chatId.startsWith("-");
67889
67895
  }
67896
+ const SILENT_TURN_MARKER = "[[BLUN_TELEGRAM_SILENT]]";
67897
+ function isSilentTurnMarker(text) {
67898
+ return text.trim() === SILENT_TURN_MARKER;
67899
+ }
67890
67900
  function normalize(s) {
67891
67901
  return s.toLowerCase().replace(/ä/g, "a").replace(/ö/g, "o").replace(/ü/g, "u").replace(/ß/g, "ss").replace(/[‐-―]/g, " ").replace(/[^\p{L}\p{N}\s]/gu, " ").replace(/\s+/g, " ").trim();
67892
67902
  }
@@ -67896,6 +67906,7 @@ const EMPTY_CLAUSES = [
67896
67906
  /^(keine (gruppen ?)?antwort|gar keine antwort|keine reaktion|kein wort|no ?action|no (response|reply|answer|comment))( (notig|erforderlich|needed|required))?$/,
67897
67907
  /^(ich )?(halte mich raus|(bin|bleibe) (jetzt )?still|schweige|habe nichts zu melden)$/,
67898
67908
  /^(stille|still|silence|nichts (zu tun|zu melden|fur mich|fuer mich)|nicht meine lane)$/,
67909
+ /^(kein handlungsbedarf|es gibt keinen handlungsbedarf|hier besteht kein handlungsbedarf)( (fur|fuer) mich)?$/,
67899
67910
  /^(i (am |will be )?)?(staying (silent|out|quiet)|keeping (quiet|out)|holding back)$/,
67900
67911
  /^(i have )?nothing (to (add|do|report)|for me)$/,
67901
67912
  /^no need to (respond|reply)$/,
@@ -67909,11 +67920,16 @@ const EMPTY_CLAUSES = [
67909
67920
  /^(nach|gemaess) der leerlauf regel( \d+)? gibt es nichts zu melden$/
67910
67921
  ];
67911
67922
  const NOTIFICATION_CONTEXT = /^die(se)? nachricht ist eine (konfigurations )?information( [\p{L}\p{N} _-]{1,64} wird ab jetzt nur noch bei erwahnung benachrichtigt)?( an die gruppe gerichtet)?$/u;
67923
+ function isNarratedSilentTurn(text) {
67924
+ const words = normalize(text);
67925
+ return /^(kein neuer auftrag|kein handlungsbedarf|keine neue anweisung keine frage an mich nichts zu berichten)\b/u.test(words) && /\b(nichts weiter zu tun|stille|stille ohne jede ausgabe)$/u.test(words);
67926
+ }
67912
67927
  /**
67913
67928
  * True only when all clauses are acknowledgements or silence commentary.
67914
67929
  * One substantive or unrecognised clause preserves the entire message.
67915
67930
  */
67916
67931
  function isGroupNoiseReply(text) {
67932
+ if (isNarratedSilentTurn(text)) return true;
67917
67933
  return text.split(/[.!?;,\r\n]+|\s+[-\u2013\u2014]\s+/u).map(normalize).filter(Boolean).every((clause) => EMPTY_CLAUSES.some((pattern) => pattern.test(clause)) || NOTIFICATION_CONTEXT.test(clause));
67918
67934
  }
67919
67935
  //#endregion
@@ -68037,6 +68053,7 @@ function scrubSecrets(text) {
68037
68053
  * log it to outbox.jsonl as kind "reply-fallback". Returns true on success.
68038
68054
  */
68039
68055
  async function sendReplyFallback(chatId, rawText, threadId) {
68056
+ if (rawText.trim().length === 0 || isSilentTurnMarker(rawText)) return true;
68040
68057
  let topic;
68041
68058
  try {
68042
68059
  topic = threadId === void 0 ? {} : { message_thread_id: telegramThreadId(threadId) };
@@ -73470,6 +73470,7 @@ const EMPTY_CLAUSES = [
73470
73470
  /^(keine (gruppen ?)?antwort|gar keine antwort|keine reaktion|kein wort|no ?action|no (response|reply|answer|comment))( (notig|erforderlich|needed|required))?$/,
73471
73471
  /^(ich )?(halte mich raus|(bin|bleibe) (jetzt )?still|schweige|habe nichts zu melden)$/,
73472
73472
  /^(stille|still|silence|nichts (zu tun|zu melden|fur mich|fuer mich)|nicht meine lane)$/,
73473
+ /^(kein handlungsbedarf|es gibt keinen handlungsbedarf|hier besteht kein handlungsbedarf)( (fur|fuer) mich)?$/,
73473
73474
  /^(i (am |will be )?)?(staying (silent|out|quiet)|keeping (quiet|out)|holding back)$/,
73474
73475
  /^(i have )?nothing (to (add|do|report)|for me)$/,
73475
73476
  /^no need to (respond|reply)$/,
@@ -73483,11 +73484,16 @@ const EMPTY_CLAUSES = [
73483
73484
  /^(nach|gemaess) der leerlauf regel( \d+)? gibt es nichts zu melden$/
73484
73485
  ];
73485
73486
  const NOTIFICATION_CONTEXT = /^die(se)? nachricht ist eine (konfigurations )?information( [\p{L}\p{N} _-]{1,64} wird ab jetzt nur noch bei erwahnung benachrichtigt)?( an die gruppe gerichtet)?$/u;
73487
+ function isNarratedSilentTurn(text) {
73488
+ const words = normalize(text);
73489
+ return /^(kein neuer auftrag|kein handlungsbedarf|keine neue anweisung keine frage an mich nichts zu berichten)\b/u.test(words) && /\b(nichts weiter zu tun|stille|stille ohne jede ausgabe)$/u.test(words);
73490
+ }
73486
73491
  /**
73487
73492
  * True only when all clauses are acknowledgements or silence commentary.
73488
73493
  * One substantive or unrecognised clause preserves the entire message.
73489
73494
  */
73490
73495
  function isGroupNoiseReply(text) {
73496
+ if (isNarratedSilentTurn(text)) return true;
73491
73497
  return text.split(/[.!?;,\r\n]+|\s+[-\u2013\u2014]\s+/u).map(normalize).filter(Boolean).every((clause) => EMPTY_CLAUSES.some((pattern) => pattern.test(clause)) || NOTIFICATION_CONTEXT.test(clause));
73492
73498
  }
73493
73499
  //#endregion
@@ -9,6 +9,10 @@
9
9
  function isGroupChat(chatId) {
10
10
  return chatId.startsWith("-");
11
11
  }
12
+ const SILENT_TURN_MARKER = "[[BLUN_TELEGRAM_SILENT]]";
13
+ function isSilentTurnMarker(text) {
14
+ return text.trim() === SILENT_TURN_MARKER;
15
+ }
12
16
  function normalize(s) {
13
17
  return s.toLowerCase().replace(/ä/g, "a").replace(/ö/g, "o").replace(/ü/g, "u").replace(/ß/g, "ss").replace(/[‐-―]/g, " ").replace(/[^\p{L}\p{N}\s]/gu, " ").replace(/\s+/g, " ").trim();
14
18
  }
@@ -18,6 +22,7 @@ const EMPTY_CLAUSES = [
18
22
  /^(keine (gruppen ?)?antwort|gar keine antwort|keine reaktion|kein wort|no ?action|no (response|reply|answer|comment))( (notig|erforderlich|needed|required))?$/,
19
23
  /^(ich )?(halte mich raus|(bin|bleibe) (jetzt )?still|schweige|habe nichts zu melden)$/,
20
24
  /^(stille|still|silence|nichts (zu tun|zu melden|fur mich|fuer mich)|nicht meine lane)$/,
25
+ /^(kein handlungsbedarf|es gibt keinen handlungsbedarf|hier besteht kein handlungsbedarf)( (fur|fuer) mich)?$/,
21
26
  /^(i (am |will be )?)?(staying (silent|out|quiet)|keeping (quiet|out)|holding back)$/,
22
27
  /^(i have )?nothing (to (add|do|report)|for me)$/,
23
28
  /^no need to (respond|reply)$/,
@@ -31,12 +36,17 @@ const EMPTY_CLAUSES = [
31
36
  /^(nach|gemaess) der leerlauf regel( \d+)? gibt es nichts zu melden$/
32
37
  ];
33
38
  const NOTIFICATION_CONTEXT = /^die(se)? nachricht ist eine (konfigurations )?information( [\p{L}\p{N} _-]{1,64} wird ab jetzt nur noch bei erwahnung benachrichtigt)?( an die gruppe gerichtet)?$/u;
39
+ function isNarratedSilentTurn(text) {
40
+ const words = normalize(text);
41
+ return /^(kein neuer auftrag|kein handlungsbedarf|keine neue anweisung keine frage an mich nichts zu berichten)\b/u.test(words) && /\b(nichts weiter zu tun|stille|stille ohne jede ausgabe)$/u.test(words);
42
+ }
34
43
  /**
35
44
  * True only when all clauses are acknowledgements or silence commentary.
36
45
  * One substantive or unrecognised clause preserves the entire message.
37
46
  */
38
47
  function isGroupNoiseReply(text) {
48
+ if (isNarratedSilentTurn(text)) return true;
39
49
  return text.split(/[.!?;,\r\n]+|\s+[-\u2013\u2014]\s+/u).map(normalize).filter(Boolean).every((clause) => EMPTY_CLAUSES.some((pattern) => pattern.test(clause)) || NOTIFICATION_CONTEXT.test(clause));
40
50
  }
41
51
  //#endregion
42
- export { isGroupChat, isGroupNoiseReply };
52
+ export { SILENT_TURN_MARKER, isGroupChat, isGroupNoiseReply, isSilentTurnMarker };
package/worker-host.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- // BLUN_BUILD_INPUT_SHA256:47510c4534e220288a7d413e8081ba7b69d9557c15c1b1e47eb83e2417b79e59
2
+ // BLUN_BUILD_INPUT_SHA256:8c6e16ea727bc28d31e8a784ec7ab7cc656e35f70f996bb1e64df97776875360
3
3
  import { fileURLToPath as __cjsShimFileURLToPath } from 'node:url';
4
4
  import { dirname as __cjsShimDirname } from 'node:path';
5
5
  const __filename = __cjsShimFileURLToPath(import.meta.url);
@@ -347625,6 +347625,7 @@ var BlunAuthTransitionError = class extends Error {
347625
347625
  this.warnings = warnings;
347626
347626
  }
347627
347627
  };
347628
+ const LEGACY_PROFILE_MODEL = "blun/king";
347628
347629
  var BlunAuthFacade = class {
347629
347630
  options;
347630
347631
  toolkit;
@@ -347651,6 +347652,57 @@ var BlunAuthFacade = class {
347651
347652
  }
347652
347653
  });
347653
347654
  }
347655
+ async restoreMissingProfileModel() {
347656
+ const needsRepair = (config) => config.defaultModel === LEGACY_PROFILE_MODEL && config.models?.[LEGACY_PROFILE_MODEL] === void 0 && config.providers["managed:blun"] === void 0;
347657
+ if (!needsRepair(readConfigFileForUpdate(this.options.configPath))) return false;
347658
+ const runtime = this.resolveRuntimeManagedAuth(BLUN_PROVIDER_NAME$1);
347659
+ if (!(await this.toolkit.status("managed:blun", runtime.oauthRef)).providers.some((provider) => provider.hasToken)) return false;
347660
+ let accessToken;
347661
+ try {
347662
+ accessToken = await this.toolkit.ensureFresh(BLUN_PROVIDER_NAME$1, { oauthRef: runtime.oauthRef });
347663
+ } catch (error) {
347664
+ if (error instanceof OAuthError$1) return false;
347665
+ throw error;
347666
+ }
347667
+ let models;
347668
+ try {
347669
+ models = requireManagedBlunKingCatalog(await fetchManagedBlunCodeModels({
347670
+ accessToken,
347671
+ baseUrl: runtime.baseUrl,
347672
+ headers: this.options.identity === void 0 ? void 0 : createBlunDefaultHeaders({
347673
+ homeDir: this.options.homeDir,
347674
+ ...this.options.identity
347675
+ })
347676
+ }));
347677
+ } catch (error) {
347678
+ if (error instanceof ManagedBlunCodeModelsAuthError) return false;
347679
+ throw error;
347680
+ }
347681
+ const repaired = await mutateConfigFile(this.options.configPath, (config) => {
347682
+ if (!needsRepair(config)) return {
347683
+ config,
347684
+ result: false
347685
+ };
347686
+ const existingServices = config.services;
347687
+ applyManagedBlunCodeConfig(config, {
347688
+ models,
347689
+ baseUrl: runtime.baseUrl,
347690
+ oauthKey: runtime.oauthRef.key,
347691
+ oauthHost: runtime.oauthRef.oauthHost,
347692
+ preserveDefaultModel: true
347693
+ });
347694
+ config.services = {
347695
+ ...config.services,
347696
+ ...existingServices
347697
+ };
347698
+ return {
347699
+ config,
347700
+ result: true
347701
+ };
347702
+ });
347703
+ if (repaired) this.options.onConfigUpdated?.(readConfigFile(this.options.configPath));
347704
+ return repaired;
347705
+ }
347654
347706
  async status(providerName) {
347655
347707
  const auth = this.resolveManagedAuth(providerName);
347656
347708
  const apiKey = nonEmpty(auth.apiKey);
@@ -348683,6 +348735,15 @@ function errorMessage(error) {
348683
348735
  }
348684
348736
  //#endregion
348685
348737
  //#region ../../packages/node-sdk/src/sdk-rpc-client.ts
348738
+ function authHomeForProfile(homeDir) {
348739
+ const sharedHome = process.env["BLUN_SHARED_HOME"]?.trim();
348740
+ const profile = process.env["BLUN_PROFILE"]?.trim();
348741
+ if (!sharedHome || !profile || !/^[a-z0-9][a-z0-9_-]{0,31}$/u.test(profile)) return homeDir;
348742
+ const expected = resolve(join(sharedHome, "profile", profile));
348743
+ const actual = resolve(homeDir);
348744
+ if ((process.platform === "win32" ? expected.toLowerCase() : expected) !== (process.platform === "win32" ? actual.toLowerCase() : actual)) return homeDir;
348745
+ return resolve(sharedHome);
348746
+ }
348686
348747
  var SDKRpcClient = class extends SDKRpcClientBase {
348687
348748
  homeDir;
348688
348749
  configPath;
@@ -348691,6 +348752,7 @@ var SDKRpcClient = class extends SDKRpcClientBase {
348691
348752
  auth;
348692
348753
  core;
348693
348754
  ready;
348755
+ usesDefaultConfigPath;
348694
348756
  constructor(options = {}) {
348695
348757
  super();
348696
348758
  this.identity = options.identity === void 0 ? void 0 : assertBlunHostIdentity(options.identity);
@@ -348699,9 +348761,10 @@ var SDKRpcClient = class extends SDKRpcClientBase {
348699
348761
  homeDir: this.homeDir,
348700
348762
  configPath: options.configPath
348701
348763
  });
348764
+ this.usesDefaultConfigPath = options.configPath === void 0;
348702
348765
  this.telemetry = options.telemetry ?? noopTelemetryClient;
348703
348766
  this.auth = new BlunAuthFacade({
348704
- homeDir: this.homeDir,
348767
+ homeDir: authHomeForProfile(this.homeDir),
348705
348768
  configPath: this.configPath,
348706
348769
  identity: this.identity,
348707
348770
  onRefresh: options.onOAuthRefresh
@@ -348721,6 +348784,7 @@ var SDKRpcClient = class extends SDKRpcClientBase {
348721
348784
  }
348722
348785
  async ensureConfigFile() {
348723
348786
  await ensureConfigFile(this.configPath);
348787
+ if (this.usesDefaultConfigPath && authHomeForProfile(this.homeDir) !== this.homeDir) await this.auth.restoreMissingProfileModel();
348724
348788
  }
348725
348789
  async close() {
348726
348790
  try {