blun-king-cli 9.1.165 → 9.1.166

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.
@@ -0,0 +1,92 @@
1
+ 'use strict';
2
+
3
+ const RECURRING_CRON_CONTEXT_MAX_MESSAGES = 24;
4
+ const RECURRING_CRON_CONTEXT_MAX_CHARS = 48_000;
5
+
6
+ function recurringCronJobId(message) {
7
+ if (message?.role !== 'user') return null;
8
+ if (message.origin?.kind !== 'cron_job' || message.origin.recurring !== true) return null;
9
+ const jobId = String(message.origin.jobId || '').trim();
10
+ return jobId || null;
11
+ }
12
+
13
+ function messageTextChars(message) {
14
+ if (!Array.isArray(message?.content)) return 0;
15
+ return message.content.reduce((total, part) => (
16
+ total + (part?.type === 'text' && typeof part.text === 'string' ? part.text.length : 0)
17
+ ), 0);
18
+ }
19
+
20
+ function splitIntoUserSegments(messages) {
21
+ const segments = [];
22
+ let current = [];
23
+ for (const message of messages) {
24
+ if (message?.role === 'user' && current.length > 0) {
25
+ segments.push(current);
26
+ current = [];
27
+ }
28
+ current.push(message);
29
+ }
30
+ if (current.length > 0) segments.push(current);
31
+ return segments;
32
+ }
33
+
34
+ function segmentTextChars(segment) {
35
+ return segment.reduce((total, message) => total + messageTextChars(message), 0);
36
+ }
37
+
38
+ function isCompactionSummarySegment(segment) {
39
+ return segment[0]?.role === 'user' && segment[0]?.origin?.kind === 'compaction_summary';
40
+ }
41
+
42
+ function isRecurringCronSegment(segment) {
43
+ return recurringCronJobId(segment[0]) !== null;
44
+ }
45
+
46
+ function projectRecurringCronHistory(history, jobId) {
47
+ if (!Array.isArray(history) || history.length === 0) return history;
48
+ const normalizedJobId = String(jobId || '').trim();
49
+ if (!normalizedJobId) return history;
50
+
51
+ let wakeupIndex = -1;
52
+ for (let index = history.length - 1; index >= 0; index -= 1) {
53
+ if (recurringCronJobId(history[index]) === normalizedJobId) {
54
+ wakeupIndex = index;
55
+ break;
56
+ }
57
+ }
58
+ if (wakeupIndex < 0) return history;
59
+
60
+ const currentSegment = history.slice(wakeupIndex);
61
+ const priorSegments = splitIntoUserSegments(history.slice(0, wakeupIndex));
62
+ const summaryIndex = priorSegments.findLastIndex(isCompactionSummarySegment);
63
+ const summary = summaryIndex >= 0 ? priorSegments[summaryIndex] : [];
64
+ const candidates = priorSegments.filter((segment, index) => (
65
+ index !== summaryIndex && !isRecurringCronSegment(segment)
66
+ ));
67
+
68
+ const selected = [];
69
+ let selectedMessages = summary.length + currentSegment.length;
70
+ let selectedChars = segmentTextChars(summary) + segmentTextChars(currentSegment);
71
+ for (let index = candidates.length - 1; index >= 0; index -= 1) {
72
+ const segment = candidates[index];
73
+ const nextMessages = selectedMessages + segment.length;
74
+ const nextChars = selectedChars + segmentTextChars(segment);
75
+ if (
76
+ nextMessages > RECURRING_CRON_CONTEXT_MAX_MESSAGES
77
+ || nextChars > RECURRING_CRON_CONTEXT_MAX_CHARS
78
+ ) continue;
79
+ selected.unshift(segment);
80
+ selectedMessages = nextMessages;
81
+ selectedChars = nextChars;
82
+ }
83
+
84
+ return [...summary, ...selected.flat(), ...currentSegment];
85
+ }
86
+
87
+ module.exports = {
88
+ RECURRING_CRON_CONTEXT_MAX_CHARS,
89
+ RECURRING_CRON_CONTEXT_MAX_MESSAGES,
90
+ projectRecurringCronHistory,
91
+ recurringCronJobId,
92
+ };
package/blun.mjs CHANGED
@@ -261180,7 +261180,7 @@ function toolResultText(result) {
261180
261180
  function abandonedToolResultOutput(ended) {
261181
261181
  return `Tool call did not complete: ${ended.reason === "cancelled" ? "the turn was cancelled" : ended.reason === "failed" ? `the turn failed${ended.error !== void 0 ? ` (${ended.error.message})` : ""}` : "the turn ended"} before its result was recorded. Do not assume the tool completed successfully.`;
261182
261182
  }
261183
- var BLUN_CORE_TOOL_NAMES, BLUN_LEAN_TOOL_NAMES, BLUN_ATTACHMENT_MARKER_RE, BLUN_TELEGRAM_OUTBOUND_TOOL_RE, BLUN_TELEGRAM_CHANNEL_RE, BLUN_TOOL_BUDGET_RATIO, createDeferredToolLoader, toolSchemaBudgetTokens, LLM_NOT_SET_MESSAGE, GOAL_CONTINUATION_ORIGIN, GOAL_COMPLETION_REMINDER_NAME, GOAL_BLOCKED_REMINDER_NAME, GOAL_RATE_LIMIT_PAUSE_REASON, GOAL_PROVIDER_CONNECTION_PAUSE_PREFIX, GOAL_PROVIDER_AUTH_PAUSE_PREFIX, GOAL_PROVIDER_API_PAUSE_PREFIX, GOAL_MODEL_CONFIG_PAUSE_PREFIX, GOAL_RUNTIME_PAUSE_PREFIX, GOAL_PROVIDER_FILTERED_PAUSE_REASON, GOAL_CONTINUATION_PROMPT, TurnFlow;
261183
+ var BLUN_CORE_TOOL_NAMES, BLUN_LEAN_TOOL_NAMES, BLUN_ATTACHMENT_MARKER_RE, BLUN_TELEGRAM_OUTBOUND_TOOL_RE, BLUN_TELEGRAM_CHANNEL_RE, BLUN_TOOL_BUDGET_RATIO, createDeferredToolLoader, toolSchemaBudgetTokens, projectRecurringCronHistory, LLM_NOT_SET_MESSAGE, GOAL_CONTINUATION_ORIGIN, GOAL_COMPLETION_REMINDER_NAME, GOAL_BLOCKED_REMINDER_NAME, GOAL_RATE_LIMIT_PAUSE_REASON, GOAL_PROVIDER_CONNECTION_PAUSE_PREFIX, GOAL_PROVIDER_AUTH_PAUSE_PREFIX, GOAL_PROVIDER_API_PAUSE_PREFIX, GOAL_MODEL_CONFIG_PAUSE_PREFIX, GOAL_RUNTIME_PAUSE_PREFIX, GOAL_PROVIDER_FILTERED_PAUSE_REASON, GOAL_CONTINUATION_PROMPT, TurnFlow;
261184
261184
  var init_turn = __esmMin((() => {
261185
261185
  init_dist$4();
261186
261186
  init_src$4();
@@ -261198,6 +261198,7 @@ var init_turn = __esmMin((() => {
261198
261198
  init_user_message_offload();
261199
261199
  init_assistant_message_offload();
261200
261200
  ({ CORE_TOOL_NAMES: BLUN_CORE_TOOL_NAMES, createDeferredToolLoader, toolSchemaBudgetTokens } = createRequire(import.meta.url)("./bin/turn-tool-performance-policy.cjs"));
261201
+ ({ projectRecurringCronHistory } = createRequire(import.meta.url)("./bin/recurring-cron-history-policy.cjs"));
261201
261202
  BLUN_LEAN_TOOL_NAMES = new Set(BLUN_CORE_TOOL_NAMES);
261202
261203
  BLUN_ATTACHMENT_MARKER_RE = /\b(?:attachment_file_id|telegram-anhang|telegram attachment)\b/i;
261203
261204
  BLUN_TELEGRAM_OUTBOUND_TOOL_RE = /^mcp__[^\s]*telegram[^\s]*__(?:reply|react|edit_message)$/i;
@@ -261807,8 +261808,8 @@ var init_turn = __esmMin((() => {
261807
261808
  turnId: String(turnId),
261808
261809
  signal,
261809
261810
  llm: turnLLM,
261810
- buildMessages: () => this.agent.context.project(fastConversation ? turnThinkingEffort === "off" ? blunStandaloneConversationHistory(this.agent.context.history) : blunFastConversationHistory(this.agent.context.history) : personalMemoryRecall === void 0 ? this.agent.context.history : [...this.agent.context.history, personalMemoryRecall], { dropOrphanResults: true }),
261811
- buildMessagesStrict: () => this.agent.context.project(fastConversation ? turnThinkingEffort === "off" ? blunStandaloneConversationHistory(this.agent.context.history) : blunFastConversationHistory(this.agent.context.history) : personalMemoryRecall === void 0 ? this.agent.context.history : [...this.agent.context.history, personalMemoryRecall], {
261811
+ buildMessages: () => this.agent.context.project(fastConversation ? turnThinkingEffort === "off" ? blunStandaloneConversationHistory(this.agent.context.history) : blunFastConversationHistory(this.agent.context.history) : origin.kind === "cron_job" && origin.recurring === true ? projectRecurringCronHistory(this.agent.context.history, origin.jobId) : personalMemoryRecall === void 0 ? this.agent.context.history : [...this.agent.context.history, personalMemoryRecall], { dropOrphanResults: true }),
261812
+ buildMessagesStrict: () => this.agent.context.project(fastConversation ? turnThinkingEffort === "off" ? blunStandaloneConversationHistory(this.agent.context.history) : blunFastConversationHistory(this.agent.context.history) : origin.kind === "cron_job" && origin.recurring === true ? projectRecurringCronHistory(this.agent.context.history, origin.jobId) : personalMemoryRecall === void 0 ? this.agent.context.history : [...this.agent.context.history, personalMemoryRecall], {
261812
261813
  synthesizeMissing: true,
261813
261814
  dropOrphanResults: true,
261814
261815
  dedupeDuplicateToolCalls: true,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "blun-king-cli",
3
- "version": "9.1.165",
3
+ "version": "9.1.166",
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": {